{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) {} else {\n rl.close();\n let hm = {}\n let arr = input.split(\" \").map(x=>parseInt(x))\n let mn1 = 9999999\n let nr = 0\n for(let i=1;i<=100;i++){\n let s=0\n for(let j=0;j {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [min, t] = [Infinity, 1];\n\n for (let i = 1; i <= 1000; i++) {\n const target = i;\n let count = 0;\n for (let j = 0; j < len; j++) {\n const current = arr[j];\n const diff = Math.abs(target - current);\n if (diff > 1) {\n count += diff - 1;\n }\n }\n if (count < min) {\n min = count;\n t = target;\n }\n }\n\n console.log(`${t} ${min}`);\n}\n"}, {"source_code": "function ansa(n,arr){\n\n var ans = []\n ans[0] = Infinity\n for(var i = 1 ; i < 101 ; i++){\n\n ans[i] = 0\n\n for(var j = 0 ; j < n ; j++){\n\n ans[i] += Math.abs(arr[j] - i);\n if(Math.abs(arr[j] - i) !== 0) ans[i]--\n\n }\n }\n var min = Math.min(...ans);\n print(ans.indexOf(min) + \" \" + min)\n}\n\nvar line = readline().split(' ')\nvar arr = readline().split(' ')\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\nansa(parseInt(line[0]),arr)\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [min, t] = [Infinity, 1];\n\n for (let i = 0; i < len; i++) {\n const target = arr[i];\n let count = 0;\n for (let j = 0; j < len; j++) {\n const current = arr[j];\n const diff = Math.abs(target - current);\n if (diff > 1) {\n count += diff - 1;\n }\n }\n if (count < min) {\n min = count;\n t = target;\n }\n }\n\n console.log(`${t} ${min}`);\n}\n"}], "src_uid": "bce9ebad1dc8bd5aae516c4ca9e551c0"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet a;\r\nconst mod = 998244353;\r\nfunction cnk(n, k) {\r\n if (k > n - k)\r\n k = n - k;\r\n return a[n][k];\r\n}\r\n\r\nfunction precalc(n) {\r\n a = new Array(n + 1);\r\n a[0] = new Array(1);\r\n a[0][0] = 1;\r\n for(let i = 1; i <= n; i++) {\r\n a[i] = new Array(Math.floor(i / 2) + 1);\r\n for(let j = 0; j <= Math.floor(i / 2); j++) {\r\n if (j === 0) {\r\n a[i][j] = 1;\r\n } else {\r\n a[i][j] = cnk(i-1,j-1);\r\n if (i > j) {\r\n a[i][j] = (a[i][j] + cnk(i-1,j)) % mod;\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nlet solve = async () => {\r\n const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));\r\n precalc(n);\r\n const nk = cnk(4,2);\r\n const s = await getLine();\r\n let l,r;\r\n if (k===0) {\r\n console.log('1');\r\n return;\r\n }\r\n for(l = 0; l < s.length && s.charAt(l) === '0'; l++);\r\n if (l >= s.length) {\r\n console.log('1');\r\n return;\r\n }\r\n\r\n if (k === 1)\r\n r = l;\r\n else {\r\n let count = k - 1;\r\n for (r = l + 1; r < s.length && count > 0;)\r\n if (s.charAt(r) === '1') {\r\n count--;\r\n if (count > 0) {\r\n r++;\r\n }\r\n } else r++;\r\n if (r >= s.length) {\r\n console.log('1');\r\n return;\r\n }\r\n }\r\n\r\n let res = 1;\r\n while (r < s.length) {\r\n let ll = l;\r\n let rr = r;\r\n while (rr + 1 < s.length && s.charAt(rr + 1) === '0') {\r\n rr++;\r\n }\r\n while (ll - 1 >= 0 && s.charAt(ll - 1) === '0') {\r\n ll--;\r\n res = (res + cnk(rr - ll, k - 1)) % mod;\r\n }\r\n ll = l + 1;\r\n while (rr - ll >= k - 1) {\r\n res = (res + cnk(rr - ll, k - 1)) % mod;\r\n ll++;\r\n }\r\n\r\n if (rr === s.length - 1) {\r\n res = (res + cnk(rr - l,k - 1) + mod - 1) % mod;\r\n }\r\n\r\n r++;\r\n while (r < s.length && s.charAt(r) === '0') r++;\r\n l++;\r\n while (l < s.length && s.charAt(l) === '0') l++;\r\n }\r\n\r\n console.log(res);\r\n\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const s = lines[l++]\n output[i] = solve(n, k, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, s) {\n const ps = []\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '1') ps.push(i)\n }\n if (ps.length < k) return 1\n\n const cache = combo(n)\n let ans = 1\n let j = 0\n for (let i = 0; i < s.length; i++) {\n const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i\n let c\n if (s[i] === '1') {\n c = Math.min(ps.length - j, k)\n } else {\n c = Math.min(ps.length - j - 1, k - 1)\n }\n // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)\n if (d > 0 && c >= 0 && d >= c && j < ps.length) {\n ans = add(ans, cache[d][c])\n }\n // console.log(d, c)\n if (s[i] === '1') {\n j++\n }\n }\n return ans\n}\nconst MOD = 998244353\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction combo(n) {\n const r = []\n for (let i = 1; i <= n; i++) {\n r[i] = []\n for (let j = 0; j <= n; j++) {\n if (i === 1 || !j || i <= j) {\n r[i][j] = 1\n continue\n }\n r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])\n }\n }\n return r\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const s = lines[l++]\n output[i] = solve(n, k, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, s) {\n const ps = []\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '1') ps.push(i)\n }\n if (ps.length < k) return 1\n\n const cache = combo(n)\n let ans = 1\n let j = 0\n for (let i = 0; i < s.length; i++) {\n const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i\n let c\n if (s[i] === '1') {\n c = Math.min(ps.length - j, k)\n } else {\n c = Math.min(ps.length - j - 1, k - 1)\n }\n // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)\n if (d > 0 && c >= 0 && j < ps.length) {\n ans = add(ans, cache[d][c])\n }\n // console.log(d, c)\n if (s[i] === '1') {\n j++\n }\n }\n return ans\n}\nconst MOD = 998244353\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction combo(n) {\n const r = []\n for (let i = 1; i <= n; i++) {\n r[i] = []\n for (let j = 0; j <= n; j++) {\n if (i === 1 || !j || i <= j) {\n r[i][j] = 1\n continue\n }\n r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])\n }\n }\n return r\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const s = lines[l++]\n output[i] = solve(n, k, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, s) {\n const ps = []\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '1') ps.push(i)\n }\n if (ps.length < k) return 1\n\n const cache = combo(n)\n let ans = 1\n let j = 0\n for (let i = 0; i < s.length; i++) {\n const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i\n let c\n if (s[i] === '1') {\n c = Math.min(ps.length - j, k)\n } else {\n c = Math.min(ps.length - j - 1, k - 1)\n }\n // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)\n if (d > 0 && j < ps.length) {\n ans = add(ans, cache[d][c])\n }\n // console.log(d, c)\n if (s[i] === '1') {\n j++\n }\n }\n return ans\n}\nconst MOD = 998244353\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction combo(n) {\n const r = []\n for (let i = 1; i <= n; i++) {\n r[i] = []\n for (let j = 0; j <= n; j++) {\n if (i === 1 || !j || i <= j) {\n r[i][j] = 1\n continue\n }\n r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])\n }\n }\n return r\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet a;\r\nconst mod = 998244353;\r\nfunction cnk(n, k) {\r\n if (k > n - k)\r\n k = n - k;\r\n return a[n][k];\r\n}\r\n\r\nfunction precalc(n) {\r\n a = new Array(n + 1);\r\n a[0] = new Array(1);\r\n a[0][0] = 1;\r\n for(let i = 1; i <= n; i++) {\r\n a[i] = new Array(Math.floor(i / 2) + 1);\r\n for(let j = 0; j <= Math.floor(i / 2); j++) {\r\n if (j === 0) {\r\n a[i][j] = 1;\r\n } else {\r\n a[i][j] = cnk(i-1,j-1);\r\n if (i > j) {\r\n a[i][j] = (a[i][j] + cnk(i-1,j)) % mod;\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nlet solve = async () => {\r\n const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));\r\n precalc(n);\r\n const nk = cnk(4,2);\r\n const s = await getLine();\r\n let l,r;\r\n for(l = 0; l < s.length && s.charAt(l) === '0'; l++);\r\n if (l >= s.length) {\r\n console.log('1');\r\n return;\r\n }\r\n if (k === 1)\r\n r = l;\r\n else {\r\n let count = k - 1;\r\n for (r = l + 1; r < s.length && count > 0;)\r\n if (s.charAt(r) === '1') {\r\n count--;\r\n if (count > 0) {\r\n r++;\r\n }\r\n }\r\n if (r >= s.length) {\r\n console.log('1');\r\n return;\r\n }\r\n }\r\n\r\n let res = 1;\r\n while (r < s.length) {\r\n /* let ll = l;\r\n while (true) {\r\n let rr = r;\r\n while (true) {\r\n res = (res + cnk(rr - ll - 1, k - 2)) % mod;\r\n if (rr === r && ll === l) {\r\n res = (res + mod - 1) % mod;\r\n }\r\n rr++;\r\n if (rr >= s.length || s.charAt(rr) === '1')\r\n break;\r\n }\r\n ll--;\r\n if (ll < 0 || s.charAt(ll) === '1')\r\n break;\r\n } */\r\n let ll = l;\r\n let rr = r;\r\n while (rr + 1 < s.length && s.charAt(rr + 1) === '0') {\r\n rr++;\r\n }\r\n while (ll - 1 >= 0 && s.charAt(ll - 1) === '0') {\r\n ll--;\r\n res = (res + cnk(rr - ll, k - 1)) % mod;\r\n }\r\n ll = l + 1;\r\n while (rr - ll >= k - 1) {\r\n res = (res + cnk(rr - ll, k - 1)) % mod;\r\n ll++;\r\n }\r\n\r\n if (rr === s.length - 1) {\r\n res = (res + cnk(rr - l,k - 1) + mod - 1) % mod;\r\n }\r\n\r\n r++;\r\n while (r < s.length && s.charAt(r) === '0') r++;\r\n l++;\r\n while (l < s.length && s.charAt(l) === '0') l++;\r\n }\r\n\r\n console.log(res);\r\n\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "d666df06a7a7ecbe801c1018b3d482b9"} {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\nplayers.sort(function(a,b){\n return ab?1:0);\n});\n\nprint((players[n-1] == players[n])?'NO':'YES');", "positive_code": [{"source_code": "var length = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\nvar raitings = readline().split(\" \").map(function(x) { return parseInt(x); });\nraitings.sort(function(a,b) { return a - b;});\nvar mid = raitings.length / 2;\nprint(raitings[mid - 1] < raitings[mid] ? \"YES\" : \"NO\")"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){\n return !isNaN(elem);\n});\nplayers.sort(function(a,b){\n return ab?1:0);\n});\n\nprint((players[n-1] == players[n])?'NO':'YES');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ');\nfor(var i in players){\n players[i] = parseInt(players[i]);\n}\nplayers.sort(function(a,b){\n return ab?1:0);\n});\n\nprint((players[n-1] == players[n])?'NO':'YES');"}, {"source_code": "function cmp(a,b)\n{\n return a-b;\n}\n\nvar n = +readline();\nvar s = readline();\n\nvar a = s.split(' ').map(function(v){return +v;});\na.sort(cmp);\nif (a[n-1]===a[n])\n{\n print(\"NO\");\n}\nelse\n{\n print(\"YES\");\n}"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\n\nprint((result1=players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\nplayers.sort(function(a,b){\n return a>=b;\n});\nwrite((players[n]==players[n-1])?'NO':'YES');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\n\nprint((result1players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\n\nprint((result1=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n/*print((players[n-1] == players[n])?'NO':'YES');\n*/\nif((result1 < result2) && (players[n-1] < players[n])){\n print(\"YES\");\n}else{\n print(\"NO\");\n}"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){\n return !isNaN(elem);\n});\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n/*print((players[n-1] == players[n])?'NO':'YES');\n*/\n\n\n\nif((result1 < result2) && (players[n-1] < players[n])){\n print(\"YES\");\n}else{\n print(\"NO\");\n}"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){\n return !isNaN(elem);\n});\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\nprint((result1=b;\n});\n/*var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);*/\n\nprint((players[n-1] == players[n])?'NO':'YES');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\nplayers.sort(function(a,b){\n return a>=b;\n});\nprint((players[n]>players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>b;\n});\n\nwrite((players[n]>players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\nplayers.sort(function(a,b){\n return a>=b;\n});\nprint((players[n]==players[n-1])?'NO':'YES');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\n\nprint((result1players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\nplayers.sort(function(a,b){\n return a>b;\n});\nprint((players[n]>players[n-1])?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar players = readline().split(' ').map(function(term) { return parseInt(term);});\n\nplayers.sort(function(a,b){\n return a>=b;\n});\nvar result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);\nvar result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);\n\nprint((result1 {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i x%2)\n acc++\n const map = {\n 0: [],\n 1: []\n }\n for (let i =0; i 1) {\n const l = map[cursor[0]].length\n if (l <= cursor[1]+1) {\n cursor[0] = 1\n cursor[1] = 0\n }\n console.log(map[cursor[0]][cursor[1]]+1, map[cursor[0]][cursor[1]+1]+1)\n cursor[1] += 2\n n--\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n var arr = readNumArray();\n var lastEven = 0;\n var lastOdd = 0;\n var counter = 0;\n for (var j = 1; j <= 2 * n; j++) {\n if (arr[j - 1] % 2) {\n if (lastOdd) {\n print(lastOdd + \" \" + j);\n lastOdd = 0;\n counter++;\n } else {\n lastOdd = j;\n }\n } else {\n if (lastEven) {\n print(lastEven + \" \" + j);\n lastEven = 0;\n counter++;\n } else {\n lastEven = j;\n }\n }\n if (counter === n - 1) {\n break;\n }\n }\n }\n}\n\nmain();"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let _ = readLine();\n let arr = readLine()\n .split(\" \")\n .map((num) => parseInt(num));\n solve(arr);\n }\n\n function solve(arr) {\n const evenMap = {};\n const oddMap = {};\n\n arr.forEach((num, index) => {\n if (num % 2 === 0) evenMap[index + 1] = num;\n else oddMap[index + 1] = num;\n });\n\n let evenKeys = Object.keys(evenMap);\n let oddKeys = Object.keys(oddMap);\n\n for (let i = 0; i < arr.length / 2 - 1; i++) {\n if (evenKeys.length >= 2) console.log(`${evenKeys.pop()} ${evenKeys.pop()}`);\n else console.log(`${oddKeys.pop()} ${oddKeys.pop()}`);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var tests = parseInt(lines.shift(), 10);\n var _loop_1 = function () {\n var n = parseInt(lines.shift(), 10);\n var arr = lineToNumArray(lines.shift());\n var indices = [[], []];\n arr.forEach(function (element, index) { return indices[element % 2].push(index); });\n if (indices[0].length % 2) {\n indices[0].shift();\n indices[1].shift();\n }\n else {\n var parity = Number(!indices[0].length);\n indices[parity].shift();\n indices[parity].shift();\n }\n indices.forEach(function (parity) {\n while (parity.length) {\n console.log(1 + parity.pop(), 1 + parity.pop());\n }\n });\n };\n while (tests--) {\n _loop_1();\n }\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let _ = readLine();\n let arr = readLine()\n .split(\" \")\n .map((num) => parseInt(num));\n solve(arr);\n }\n\n function solve(arr) {\n const map = { even: [], odd: [] };\n arr.forEach((num) => {\n if (num % 2 === 0) map[\"even\"].push(num);\n else map[\"odd\"].push(num);\n });\n for (let i = 0; i < arr.length / 2 - 1; i++) {\n if (map[\"even\"].length >= 2) console.log(`${map[\"even\"].pop()} ${map[\"even\"].pop()}`);\n else console.log(`${map[\"odd\"].pop()} ${map[\"odd\"].pop()}`);\n }\n }\n}\n"}], "src_uid": "96fac9f9377bf03e144067bf93716d3d"} {"source_code": "var n = +readline();\n\nconst FALL = {\n yes: {},\n maybe: {},\n no: {}\n};\n\nvar fallType = function (fallTree, blockTree) {\n var distance = Math.abs(fallTree.x - blockTree.x);\n\n if (fallTree.h + blockTree.h < distance) {\n return FALL.yes;\n }\n\n if (fallTree.h < distance) {\n return blockTree.h >= distance ? FALL.yes : FALL.maybe;\n }\n\n return FALL.no;\n};\n\nvar Tree = function (data) {\n this.x = +data[0];\n this.h = +data[1];\n};\n\nTree.prototype.calculate = function (leftTree, rightTree) {\n this.left = fallType(this, leftTree);\n this.right = fallType(this, rightTree);\n};\n\nTree.prototype.canFall = function () {\n return this.left === FALL.yes || this.right === FALL.yes;\n};\n\nTree.prototype.cantFall = function () {\n return this.left === FALL.no && this.right === FALL.no;\n};\n\nvar trees = [new Tree([-Infinity, 0])];\nfor (var i = 0; i < n; ++i) {\n trees.push(new Tree(readline().split(' ')));\n}\ntrees.push(new Tree([+Infinity, 0]));\n\nfor (var i = 1; i <= n; ++i) {\n trees[i].calculate(trees[i - 1], trees[i + 1]);\n}\n\nvar result = 0;\nvar state = 0;\n\nfor (var i = 1; i <= n; ++i) {\n switch (state) {\n case 0:\n if (trees[i].canFall()) {\n ++result;\n } else if (trees[i].cantFall()) {\n // nothing do to here\n } else if (trees[i].left === FALL.no) {\n ++result;\n state = 1;\n } else {\n ++result;\n }\n break;\n case 1:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else if (trees[i].cantFall()) {\n state = 0;\n } else if (trees[i].right === FALL.no) {\n state = 0;\n } else {\n ++result;\n }\n\n break;\n }\n}\n\nwrite(result);", "positive_code": [{"source_code": "var n = +readline(),\n x = [],\n h = [],\n count = (n === 1) ? 1 : 2;\n\nfor (var i = 0; i < n; i ++)\n{\n var line = readline().split(' ');\n x[i] = +line[0],\n h[i] = +line[1];\n}\n\nfor (var i = 1; i < n - 1; i ++)\n{\n if (x[i - 1] < x[i] - h[i])\n {\n count ++;\n }\n else if (x[i + 1] > x[i] + h[i])\n {\n x[i] += h[i];\n count ++;\n }\n}\n\nprint(count);\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n \n this.find = function( val , fl ) {\n \tvar lo , hi , mi , res , sz1 , sz2 ;\n \tsz1 = this.brr.length ;\n \tsz2 = this.crr.length ;\n \tlo = 0 ;\n \tif( fl == false ) {\n \t\thi = sz1 - 1 ;\n \t}\n \telse {\n \t\thi = sz2 - 1 ;\n \t}\n \tres = -1 ;\n \twhile( lo <= hi ) {\n \t\tmi = Math.floor( ( lo + hi ) / 2 ) ;\n \t\tif( fl == false ) {\n \t\t\tif( this.brr[ mi ].index < val ) {\n \t\t\t\tlo = mi + 1 ;\n \t\t\t\tres = Math.max( res , mi ) ;\n \t\t\t}\n \t\t\telse {\n \t\t\t\thi = mi - 1 ;\n \t\t\t}\n \t\t}\n \t\telse {\n \t\t\tif( this.crr[ mi ].index + this.crr[ mi ].height < val ) {\n \t\t\t\tlo = mi + 1 ;\n \t\t\t\tres = Math.max( res , mi ) ;\n \t\t\t}\n \t\t\telse {\n \t\t\t\thi = mi - 1 ;\n \t\t\t}\n \t\t}\n \t}\n \tif( res != -1 ) {\n \t\tif( fl == false ) {\n \t\t\tres = this.brr[ res ].arrayIndex ;\n \t\t}\n \t\telse {\n \t\t\tres = this.crr[ res ].arrayIndex ;\n \t\t}\n \t}\n \treturn res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j ;\n res = 0 ;\n this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;\n this.brr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i == 0 ) {\n \t\tthis.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n \telse if( this.arr[ i ].index - this.arr[ i ].height > this.arr[ i - 1 ].index ) {\n \t\tthis.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n }\n this.crr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i == this.n - 1 ) {\n \t\tthis.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n \telse if( this.arr[ i ].index + this.arr[ i ].height < this.arr[ i + 1 ].index ) {\n \t\tthis.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n }\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.memo[ i ][ 0 ] = 1 ;\n \tthis.memo[ i ][ 1 ] = 1 ;\n \tif( i > 0 ) {\n \t\tj = this.find( this.arr[ i ].index - this.arr[ i ].height , false ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 0 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index - this.arr[ i ].height , true ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 1 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index , false ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 0 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index , true ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 1 ] + 1 ) ;\n \t\t}\n\t \tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ i - 1 ][ 0 ] ) ;\n\t \tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ i - 1 ][ 1 ] ) ;\n \t}\n \tres = Math.max( res , this.memo[ i ][ 0 ] ) ;\n\t res = Math.max( res , this.memo[ i ][ 1 ] ) ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i , obj ;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tobj = {} ;\n \tobj.index = irObj.nextInt() ;\n \tobj.height = irObj.nextInt() ;\n this.arr.push( obj ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.brr = [];\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.idx = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.idx.push( new Array() );\n for( j = 0 ; j < 2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.idx[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function toi(x){return parseInt(x);}\nvar n=+readline();\nif(n==1){\n print(\"1\")\n quit();\n} \t \nvar treex=[];\nvar treeh=[];\nfor(var i=0;i= distance ? FALL.yes : FALL.maybe;\n }\n\n return FALL.no;\n};\n\nvar Tree = function (data) {\n this.x = +data[0];\n this.h = +data[1];\n};\n\nTree.prototype.calculate = function (leftTree, rightTree) {\n this.left = fallType(this, leftTree);\n this.right = fallType(this, rightTree);\n};\n\nTree.prototype.canFall = function () {\n return this.left === FALL.yes || this.right === FALL.yes;\n};\n\nTree.prototype.cantFall = function () {\n return this.left === FALL.no && this.right === FALL.no;\n};\n\nvar trees = [new Tree([-Infinity, 0])];\nfor (var i = 0; i < n; ++i) {\n trees.push(new Tree(readline().split(' ')));\n}\ntrees.push(new Tree([+Infinity, 0]));\n\nfor (var i = 1; i <= n; ++i) {\n trees[i].calculate(trees[i - 1], trees[i + 1]);\n}\n\nvar result = 0;\nvar state = 0;\n\nfor (var i = 1; i <= n; ++i) {\n switch (state) {\n case 0:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].left === FALL.no) {\n ++result;\n state = 1;\n } else {\n ++result;\n }\n }\n }\n break;\n case 1:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].right === FALL.no) {\n state = 0;\n } else {\n ++result;\n }\n }\n }\n break;\n }\n}\n\nwrite(result);"}, {"source_code": "var n = +readline();\n\nconst FALL = {\n yes: {},\n maybe: {},\n no: {}\n}\n\nvar fallType = function(fallTree, blockTree) {\n var distance = Math.abs(fallTree.x - blockTree.x);\n \n if (fallTree.h + blockTree.h < distance) {\n return FALL.yes;\n }\n \n if (fallTree.h < distance) {\n if (blockTree.h >= distance) {\n return FALL.yes;\n }\n else {\n return FALL.maybe;\n }\n }\n \n return FALL.no;\n}\n\nvar Tree = function(data) {\n this.x = +data[0];\n this.h = +data[1];\n};\n\nTree.prototype.calculate = function(leftTree, rightTree) {\n this.left = fallType(this, leftTree);\n this.right = fallType(this, rightTree);\n};\n\nTree.prototype.canFall = function() {\n return this.left === FALL.yes || this.right === FALL.yes;\n};\n\nTree.prototype.cantFall = function() {\n return this.left === FALL.no && this.right === FALL.no;\n};\n\nTree.prototype.maybeFall = function() {\n return this.left === FALL.maybe || this.right === FALL.maybe;\n};\n\nvar trees = [new Tree([-Infinity, 0])];\nfor (var i = 0; i < n; ++i) {\n trees.push(new Tree(readline().split(' ')));\n}\ntrees.push(new Tree([+Infinity, 0]));\n\nfor (var i = 1; i <= n; ++i) {\n trees[i].calculate(trees[i-1], trees[i+1]);\n}\n\nvar result = 0;\nvar state = 0;\n\nfor (var i = 1; i <= n; ++i) {\n switch (state) {\n case 0:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].left === FALL.no) {\n ++result;\n state = 1;\n } else {\n ++result;\n }\n }\n }\n break;\n case 1:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].right === FALL.no) {\n state = 0;\n } else {\n ++result;\n }\n }\n }\n break;\n }\n}\n\nwrite(result);"}], "negative_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , a , b , c , d ;\n res = 0 ;\n this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;\n a = -2000000000 ;\n b = -2000000000 ;\n aa = 0 ;\n bb = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tc = this.arr[ i ].index ;\n \td = this.arr[ i ].height ;\n \tif( a < c - d ) {\n \t\ta = c ;\n \t\taa += 1 ;\n \t}\n \telse if( b < c - d ) {\n \t\ta = c ;\n \t\taa += 1 ;\n \t}\n \tif( b < c ) {\n \t\tb = c + d ;\n \t\tbb += 1 ;\n \t}\n \telse if( a < c ) {\n \t\tb = c + d ;\n \t\tbb += 1 ;\n \t}\n \tres = Math.max( res , aa ) ;\n \tres = Math.max( res , bb ) ;\n }\n print( res - 1 );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i , obj ;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tobj = {} ;\n \tobj.index = irObj.nextInt() ;\n \tobj.height = irObj.nextInt() ;\n this.arr.push( obj ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.brr = [];\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n \n this.find = function( val , fl ) {\n \tvar lo , hi , mi , res , sz1 , sz2 ;\n \tsz1 = this.brr.length ;\n \tsz2 = this.crr.length ;\n \tlo = 0 ;\n \tif( fl == false ) {\n \t\thi = sz1 - 1 ;\n \t}\n \telse {\n \t\thi = sz2 - 1 ;\n \t}\n \tres = -1 ;\n \twhile( lo <= hi ) {\n \t\tmi = Math.floor( ( lo + hi ) / 2 ) ;\n \t\tif( fl == false ) {\n \t\t\tif( this.brr[ mi ].index < val ) {\n \t\t\t\tlo = mi + 1 ;\n \t\t\t\tres = Math.max( res , mi ) ;\n \t\t\t}\n \t\t\telse {\n \t\t\t\thi = mi - 1 ;\n \t\t\t}\n \t\t}\n \t\telse {\n \t\t\tif( this.crr[ mi ].index + this.crr[ mi ].height < val ) {\n \t\t\t\tlo = mi + 1 ;\n \t\t\t\tres = Math.max( res , mi ) ;\n \t\t\t}\n \t\t\telse {\n \t\t\t\thi = mi - 1 ;\n \t\t\t}\n \t\t}\n \t}\n \tif( res != -1 ) {\n \t\tif( fl == false ) {\n \t\t\tres = this.brr[ res ].arrayIndex ;\n \t\t}\n \t\telse {\n \t\t\tres = this.crr[ res ].arrayIndex ;\n \t\t}\n \t}\n \treturn res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j ;\n res = 0 ;\n this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;\n this.brr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i == 0 ) {\n \t\tthis.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n \telse if( this.arr[ i ].index - this.arr[ i ].height > this.arr[ i - 1 ].index ) {\n \t\tthis.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n }\n this.crr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i == this.n - 1 ) {\n \t\tthis.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n \telse if( this.arr[ i ].index + this.arr[ i ].height < this.arr[ i + 1 ].index ) {\n \t\tthis.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;\n \t}\n }\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.memo[ i ][ 0 ] = 1 ;\n \tthis.memo[ i ][ 1 ] = 1 ;\n \tif( i > 0 ) {\n \t\tj = this.find( this.arr[ i ].index - this.arr[ i ].height , false ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 0 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index - this.arr[ i ].height , true ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 1 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index , false ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 0 ] + 1 ) ;\n \t\t}\n \t\tj = this.find( this.arr[ i ].index , true ) ;\n \t\tif( j != -1 ) {\n \t\t\tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 1 ] + 1 ) ;\n \t\t}\n\t \tthis.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ i - 1 ][ 0 ] ) ;\n\t \tthis.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ i - 1 ][ 1 ] ) ;\n\t \tres = Math.max( res , this.memo[ i ][ 0 ] ) ;\n\t \tres = Math.max( res , this.memo[ i ][ 1 ] ) ;\n \t}\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i , obj ;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tobj = {} ;\n \tobj.index = irObj.nextInt() ;\n \tobj.height = irObj.nextInt() ;\n this.arr.push( obj ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.brr = [];\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.idx = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.idx.push( new Array() );\n for( j = 0 ; j < 2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.idx[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function toi(x){return parseInt(x);}\nvar n=+readline();\nvar treex=[];\nvar treeh=[];\nfor(var i=0;i= distance) {\n return FALL.yes;\n }\n else {\n return FALL.maybe;\n }\n }\n \n return FALL.no;\n}\n\nvar Tree = function(data) {\n this.x = +data[0];\n this.h = +data[1];\n};\n\nTree.prototype.calculate = function(leftTree, rightTree) {\n this.left = fallType(this, leftTree);\n this.right = fallType(this, rightTree);\n};\n\nTree.prototype.canFall = function() {\n return this.left === FALL.yes || this.right === FALL.yes;\n};\n\nTree.prototype.cantFall = function() {\n return this.left === FALL.no && this.right === FALL.no;\n};\n\nTree.prototype.maybeFall = function() {\n return this.left === FALL.maybe || this.right === FALL.maybe;\n};\n\nvar trees = [new Tree([-Infinity, 0])];\nfor (var i = 0; i < n; ++i) {\n trees.push(new Tree(readline().split(' ')));\n}\ntrees.push(new Tree([+Infinity, 0]));\n\nfor (var i = 1; i <= n; ++i) {\n trees[i].calculate(trees[i-1], trees[i+1]);\n}\n\nvar result = 0;\nvar state = 0;\n\nfor (var i = 1; i <= n; ++i) {\n switch (state) {\n case 0:\n if (trees[i].canFall()) {\n ++result;\n } else {\n if (trees[i].cantFall()) {\n // nothing to do here\n } else {\n if (trees[i].left = FALL.maybe) {\n ++result;\n } else {\n ++result;\n state = 1;\n }\n }\n }\n break;\n case 1:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].right = FALL.no) {\n state = 0;\n } else {\n ++result;\n }\n }\n }\n break;\n }\n}\n\nwrite(result);"}, {"source_code": "var n = +readline();\n\nconst FALL = {\n yes: {},\n maybe: {},\n no: {}\n}\n\nvar fallType = function(fallTree, blockTree) {\n var distance = Math.abs(fallTree.x - blockTree.x);\n \n if (fallTree.h + blockTree.h < distance) {\n return FALL.yes;\n }\n \n if (fallTree.h < distance) {\n if (blockTree.h >= distance) {\n return FALL.yes;\n }\n else {\n return FALL.maybe;\n }\n }\n \n return FALL.no;\n}\n\nvar Tree = function(data) {\n this.x = +data[0];\n this.h = +data[1];\n};\n\nTree.prototype.calculate = function(leftTree, rightTree) {\n this.left = fallType(this, leftTree);\n this.right = fallType(this, rightTree);\n};\n\nTree.prototype.canFall = function() {\n return this.left === FALL.yes || this.right === FALL.yes;\n};\n\nTree.prototype.cantFall = function() {\n return this.left === FALL.no && this.right === FALL.no;\n};\n\nTree.prototype.maybeFall = function() {\n return this.left === FALL.maybe || this.right === FALL.maybe;\n};\n\nvar trees = [new Tree([-Infinity, 0])];\nfor (var i = 0; i < n; ++i) {\n trees.push(new Tree(readline().split(' ')));\n}\ntrees.push([new Tree([+Infinity, 0])]);\n\nfor (var i = 1; i <= n; ++i) {\n trees[i].calculate(trees[i-1], trees[i+1]);\n}\n\nvar result = 0;\nvar state = 0;\n\nfor (var i = 1; i <= n; ++i) {\n switch (state) {\n case 0:\n if (trees[i].canFall()) {\n ++result;\n } else {\n if (trees[i].cantFall()) {\n // nothing to do here\n } else {\n if (trees[i].left = FALL.maybe) {\n ++result;\n } else {\n ++result;\n state = 1;\n }\n }\n }\n break;\n case 1:\n if (trees[i].canFall()) {\n ++result;\n state = 0;\n } else {\n if (trees[i].cantFall()) {\n state = 0;\n } else {\n if (trees[i].right = FALL.no) {\n state = 0;\n } else {\n ++result;\n }\n }\n }\n break;\n }\n}\n\nwrite(result);"}, {"source_code": "var n = +readline(),\n x = [],\n h = [],\n spc = [],\n count = 2;\n\nfor (var i = 0; i < n; i ++)\n{\n var line = readline().split(' ');\n x[i] = +line[0],\n h[i] = +line[1];\n}\n\nfor (var i = 1; i < n - 1; i ++)\n{\n if (x[i - 1] < x[i] - h[i])\n {\n count ++;\n }\n else if (x[i + 1] > x[i] + h[i])\n {\n x[i] += h[i];\n count ++;\n }\n}\n\nprint(count);\n"}], "src_uid": "a850dd88a67a6295823e70e2c5c857c9"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if(n < k)\n console.log(k-n);\n else{\n if((n+k) % 2 === 0){\n console.log(0);\n }else{\n console.log(1);\n }\n }\n }\n}\n\nfunction probB(){\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n a[0] = pi(a[0]);\n a[1] = pi(a[1]);\n a[2] = pi(a[2]);\n\n b[0] = pi(b[0]);\n b[1] = pi(b[1]);\n b[2] = pi(b[2]);\n\n let maxSum = 0;\n if(b[2] - (a[0] + a[2]) > 0){\n b[2] = b[2] - (a[0]+a[2]);\n a[0] = 0;\n a[2] = 0;\n }else if(b[2] - a[0] > 0){\n a[2] = a[2] - (b[2] - a[0]);\n b[2] = 0;\n a[0] = 0;\n }else{\n a[0] -= b[2];\n b[2] = 0;\n }\n\n if(a[2] > b[1])\n console.log((b[1] - b[2]) * 2)\n else\n console.log((a[2]-b[2]) * 2);\n\n }\n}\n\nfunction probC(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = readline().split(' ');\n let x = JSON.parse(JSON.stringify(a));\n\n x.sort((a,b) => pi(a) - pi(b));\n let res = true;\n for(let i = 0; i < n; i++){\n if(x[i] !== a[i]){\n if(pi(a[i]) % pi(x[0]) !== 0){\n res = false;\n break;\n }\n }\n }\n\n if(res)\n console.log('yes');\n else\n console.log('no');\n }\n}", "positive_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\nfunction functions() {\n rl.question('', function (n) {\n var input = n.split(' ')\n var a = parseInt(input[0]);\n var k = parseInt(input[1]);\n var o = 0;\n var output;\n if (k >= a) {\n output = k - a;\n } else {\n if ((a % 2 == 0 && k % 2 == 0) || (a % 2 != 0 && k % 2 != 0)) {\n output = 0\n } else {\n output = 1\n }\n }\n console.log(output)\n functions()\n })\n}\n\n// function functions() {\n// rl.question('', function (input) {\n// var n = input.split(' ');\n// var x = parseInt(n[0]);\n// var y = parseInt(n[1]);\n// var z = parseInt(n[2]);\n// var a, b, c, bool = false;\n// if (x == y && y >= z) {\n// bool = true;\n// a = x;\n// b = z;\n// c = 1;\n// } else if (x == z && z >= y) {\n// bool = true;\n// b = x;\n// a = y;\n// c = 1;\n// } else if (y == z && z >= x) {\n// bool = true;\n// c = y;\n// b = x;\n// a = 1;\n// } else if (x == y && y == z) {\n// bool = true;\n// a = b = c = x;\n// }\n// if (bool) {\n// console.log('yes')\n// console.log(a, b, c)\n// } else {\n// console.log('no')\n// }\n// // console.log(x == y, x > z, z, y > 2)\n// functions();\n// })\n// }\n// function functions() {\n// rl.question(\"\", function (n) {\n// rl.question(\"\", function (num) {\n// var arr = num.split(' ');\n// var l = [];\n// for (var i = 0; i < n * 2; i++) {\n// for (var j = 0; j < arr.length; j++) {\n// var lhas = l.includes(arr[j])\n// if (!lhas) {\n// l.push(arr[j]);\n//\n// }\n// }\n// }\n// console.log(l.join(' '));\n// functions();\n// });\n// })\n// }\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (a <= b) {\n console.log(b - a);\n } else if (a % 2 != b % 2) {\n console.log(1);\n } else {\n console.log(0);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const [n, k] = readLine().split(/\\s/).map(Number)\n console.log(n < k ? k - n : (n - k) % 2)\n }\n}\n\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let [n, k] = $(2)\n if (n <= k) log(k - n);\n else if (n % 2 == k % 2) log(0);\n else log(1);\n }\n}\n"}, {"source_code": "let _input = '';\nlet lineNumberToRead = -1;\nlet outputArray = [];\nfunction readLine() {\n lineNumberToRead += 1;\n return _input[lineNumberToRead];\n}\n\nconst l = readLine;\n\nfunction flush() {\n console.log(outputArray.join(''));\n outputArray = [];\n}\n\nfunction out(s) {\n outputArray.push(s);\n}\nfunction ria() {\n return l().split(' ').map((x) => +x);\n}\nfunction processInput() {\n const t = +l();\n\n for (let i = 1; i <= t; i += 1) {\n solveTestCase(i);\n }\n\n flush();\n}\n\nfunction solveTestCase(testCaseNumber) {\n const [n, k] = ria();\n\n if(n < k) {\n out(k - n + \"\\n\");\n } else {\n out(((n%2 == k%2) ? 0 : 1) + \"\\n\");\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', (data) => { _input += data; });\nprocess.stdin.on('end', () => {\n _input = _input.trim().split('\\n').map((x) => x.trim());\n processInput();\n});\n"}, {"source_code": "var t = +(readline());\nwhile (t--) {\n var inputs = readline().split(' ');\n var n = +inputs[0], k = +inputs[1];\n if (n < k) {\n print(k-n);\n } else if (n%2==k%2) print(0);\n else print(1); \n}\n"}, {"source_code": "var t = parseInt(readline());\n\nwhile(t--){\n a = readline().split(' ');\n n = parseInt(a[0]);\n k = parseInt(a[1]);\n \n if (n < k)\n print(k - n);\n else if (n % 2 == k % 2)\n print(0);\n else \n print(1);\n}"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\nfunction functions() {\n rl.question('', function (n) {\n var input = n.split(' ')\n var a = input[0];\n var k = input[1];\n var o = 0;\n var output;\n if (k >= a) {\n output = k - a;\n } else {\n if ((a % 2 == 0 && k % 2 == 0) || (a % 2 != 0 && k % 2 != 0)) {\n output = 0\n } else {\n output = 1\n }\n }\n console.log(output)\n functions()\n })\n}\n\n// function functions() {\n// rl.question('', function (input) {\n// var n = input.split(' ');\n// var x = parseInt(n[0]);\n// var y = parseInt(n[1]);\n// var z = parseInt(n[2]);\n// var a, b, c, bool = false;\n// if (x == y && y >= z) {\n// bool = true;\n// a = x;\n// b = z;\n// c = 1;\n// } else if (x == z && z >= y) {\n// bool = true;\n// b = x;\n// a = y;\n// c = 1;\n// } else if (y == z && z >= x) {\n// bool = true;\n// c = y;\n// b = x;\n// a = 1;\n// } else if (x == y && y == z) {\n// bool = true;\n// a = b = c = x;\n// }\n// if (bool) {\n// console.log('yes')\n// console.log(a, b, c)\n// } else {\n// console.log('no')\n// }\n// // console.log(x == y, x > z, z, y > 2)\n// functions();\n// })\n// }\n// function functions() {\n// rl.question(\"\", function (n) {\n// rl.question(\"\", function (num) {\n// var arr = num.split(' ');\n// var l = [];\n// for (var i = 0; i < n * 2; i++) {\n// for (var j = 0; j < arr.length; j++) {\n// var lhas = l.includes(arr[j])\n// if (!lhas) {\n// l.push(arr[j]);\n//\n// }\n// }\n// }\n// console.log(l.join(' '));\n// functions();\n// });\n// })\n// }\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let [n, k] = $(2)\n if (n <= k) log(k - n);\n else if (n % 2 == k % 2) log(0);\n else log(1);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if((n+k) % 2 === 0){\n if(n === 0)\n console.log(k);\n else\n console.log(0);\n }\n else\n console.log(Math.abs(n-k));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if(n < k)\n console.log(k-n);\n else{\n if((n+k) % 2 === 0){\n console.log(0);\n }else{\n console.log(n-k);\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if((n+k) % 2 === 0 && n > k){\n console.log(0);\n }else{\n console.log(Math.abs(n-k));\n }\n }\n}"}], "src_uid": "f98d1d426f68241bad437eb221f617f4"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const a = d.split(' ').map(Number);\n\n for (let i = 0; i < a.length; i++) {\n if (a[i] % 2 === 0) {\n a[i] = a[i] - 1;\n }\n }\n\n console.log(a.join(' '));\n\n c++;\n});\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const array = is.nextArray();\n for (let i = 0; i < n; i += 1) {\n array[i] = parseInt(array[i], 10);\n }\n\n let tmp;\n for (let i = 0; i < n; i += 1) {\n tmp = array[i];\n for (let j = 0; j < n; j += 1) {\n if (array[j] === tmp && array[j] % 2 === 0) {\n array[j] = tmp - 1;\n }\n }\n }\n\n console.log(array.join(' '));\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var readline = (()=>{\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n let currentLine = 0;\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n });\t\n \n function readline() {\n return inputString[currentLine++];\n }\n return readline;\n})()\n \n\nfunction main() {\n\treadline();\n\tconsole.log(((str)=>\n\t\tstr.split(\" \").map(item=>item%2===0?item-1:item).join(\" \")\n\t)(readline()));\n}\n"}, {"source_code": "var readline = (()=>{\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n let currentLine = 0;\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n });\t\n \n function readline() {\n return inputString[currentLine++];\n }\n return readline;\n})()\n \n\nfunction main() {\n\treadline();\n\tconsole.log(((str)=>{\n\t\tlet arr=str.split(\" \");\n\t\tarr = arr.reduce((acc,c,i)=>{\n\t\t\tlet n = c%2==0?c-1:c;\n\t\t\tif(acc[n]==null){\n\t\t\t\tacc[n] = [];\n\t\t\t};\n\t\t\tacc[n].push(i);\n\t\t\treturn acc;\n\t\t}, {});\n\t\treturn Object.keys(arr).reduce((acc,e,i)=>{\n\t\t\tlet c = arr[e];\n\t\t\tc.map(t=>acc[t]=e);\n\t\t\treturn acc;\n\t\t},[]).join(\" \")\n\t})(readline()));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n for(var i = 0; i < N; i++){\n list[i] -= (list[i] % 2 == 0) ? 1 : 0;\n }\n myout(myconv(list, 8));\n}\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let n = parseInt(input[0]);\n let num = [];\n input[1].split(' ').forEach(i => num.push(parseInt(i)));\n\n for(let i = 0; i < n; i++){\n for(let j = i; j < n; j++){\n if(num[i] === num[j] && num[j] % 2 === 0)\n num[j]--;\n }\n }\n\n let answer = ''; num.forEach( i => answer+= `${i} `)\n console.log(answer);\n});\n\n"}, {"source_code": "n=readline()\nprint(readline().split(' ').map(function(x){return x-(+x+1)%2}).join(' '))"}, {"source_code": "var n = (+ readline ());\nvar a = readline ();\na = a.trim ().split ( ' ' );\nvar i;\nfor ( i = 0; i < n; i ++ ) a [ i ] = Number ( a [ i ] );\nfor ( i = 0; i < n; i ++ ) {\n if ( a [ i ] % 2 == 0 ) a [ i ] --;\n}\nprint ( a.join ( ' ' ) );\n"}, {"source_code": "var elements = readline();\nelements = readline().split(' ').map(e => e % 2 === 0 ? e - 1 : e).join(' ');\nprint(elements);"}, {"source_code": "//var h = readline()\nvar n = parseInt(readline())\nvar nums = (readline().split(' '))\nvar i = 0\nwhile (n--) {\n var a = nums[i] - 1\n var b = parseInt((a / 2), 10)\n var c = b * 2\n var res = c + 1\n write(res, ' ')\n i++\n}"}, {"source_code": "var n = parseInt(readline())\nvar nums = (readline().split(' '))\nvar i = 0\nwhile (n--) {\n var a = nums[i] - 1\n var b = parseInt((a / 2), 10)\n var c = b * 2\n var res = c + 1\n print(res)\n i++\n}"}, {"source_code": "// var print = require('lol-io').print\n// var readline = require('lol-io').readline\n\nreadline();\n\nvar arr = readline().split(' ');\n\nvar answer = '';\n\narr.forEach(nr => {\n if(!(nr % 2)) {\n answer += nr - 1;\n } else {\n answer += nr;\n }\n answer += ' ';\n});\n\nprint(answer);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(function(el) {\n return parseInt(el, 10);\n});\n\nfor (var i of a) {\n if (i % 2 == 0) {\n write(i - 1,' ');\n }\n else {\n write(i, ' ')\n }\n}\n\n"}], "negative_code": [{"source_code": "var readline = (()=>{\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n let currentLine = 0;\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n });\t\n \n function readline() {\n return inputString[currentLine++];\n }\n return readline;\n})()\n \n\nfunction main() {\n\treadline();\n\tconsole.log(((str)=>{\n\t\tlet arr=str.split(\" \");\n\t\tarr = arr.reduce((acc,c,i)=>{\n\t\t\tlet n = c%2===0?c-1:c;\n\t\t\tif(acc[n]==null){\n\t\t\t\tacc[n] = [];\n\t\t\t}\n\t\t\tacc[n].push(i);\n\t\t\treturn acc;\n\t\t}, {});\n\t\treturn Object.keys(arr).reduce((acc,e,i)=>{\n\t\t\tlet c = arr[e];\n\t\t\tconsole.log(e);\n\t\t\tc.map(t=>acc[t]=e);\n\t\t\treturn acc;\n\t\t},[]).join(\" \")\n\t})(readline()));\n}\n"}], "src_uid": "d00696cb27c679dda6e2e29314a8432b"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solution(n, x){\n return n === 1 ? 1 : Math.floor((n - 3) / x) + 2;\n}\n\nfunction main() {\n const N = parseInt(readline());\n \n for(let i = 0; i < N; i++){\n const line = readline().split(' ').map(item => parseInt(item));\n console.log(solution(line[0], line[1]));\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [target, flats] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (target <= 2) console.log(1);\n else if (target >= 3 && target <= flats) console.log(2);\n else {\n target = target - (2 + flats);\n let result = Math.floor(target / flats);\n if (target % flats !== 0) result += 1;\n console.log(result + 2);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var X = one[1];\n if(N < 3){\n output[i] = 1;\n }else{\n var count = 0;\n while(true){\n if(3 + count * X <= N && N <= (count + 1) * X + 2){\n output[i] = count + 2;\n break;\n }\n count++;\n }\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n\nfunction print(thing) {\n console.log(thing);\n}\nconst getLine = (function() {\n const getLineGen = (async function*() {\n for await (const line of rl) {\n yield line;\n }\n })();\n return async() => ((await getLineGen.next()).value);\n})();\n\nconst main = async() => {\n let t = Number(await getLine());\n for (test = 0; test < t; test++) {\n let raw = (await getLine()).split(\" \");\n n = Number(raw[0]);\n x = Number(raw[1]);\n if (n <= 2) {\n print(1);\n } else {\n print((Math.floor((n - 3) / x)) + 2);\n }\n }\n process.exit(0);\n};\n\nmain();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), x = $()\n log(max(0, Math.ceil((n - 2) / x)) + 1);\n }\n}\n"}, {"source_code": "function main(){\n var ncases = +readline();\n for(var i = 0; i < ncases; ++i){\n var input = readline().split(' ');\n var res = Math.ceil((+input[0] - 2) / +input[1]) +1;\n print(res || 1);\n }\n}\n\nmain();"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n var ln = readline().split(\" \");\n var n = Number(ln[0]),x = Number(ln[1]);\n if(n<=2)print(1);\n else print(parseInt((n-2)/x)+((n-2)%x>0)+1);\n}"}, {"source_code": "var \u0ca0_\u0ca0 = Number(readline());\nwhile(\u0ca0_\u0ca0--){\n var ln = readline().split(\" \");\n var n = Number(ln[0]),x = Number(ln[1]);\n if(n<=2)print(1);\n else print(parseInt((n-2)/x)+((n-2)%x>0)+1);\n}"}, {"source_code": "var t = Number( readline() );\nfor(var i=0; iNumber(a));\n print((r[0]<3)?1:Math.floor((r[0]-3)/r[1]+2));\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var i = 0; i < t; i++) {\n var params = readline();\n var n = parseInt(params.split(\" \")[0]);\n var apts = parseInt(params.split(\" \")[1]);\n var floor = 1;\n if (n > 2) {\n floor = Math.ceil(parseFloat(n - 2) / apts) + 1;\n }\n\n print(floor);\n}\n"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var a = readline().split(' ').map(int)\n\n var n = a[0], x = a[1]\n \n if(n == 1 || n == 2) {\n print(1)\n }else {\n n -= 2;\n print(1 + Math.ceil(n / x))\n }\n \n \n}"}, {"source_code": "var rr=readline()\n\n\n//var i=0;\nfor(var j=0;jpetyaApartment)&&i===0){\nFloorPetya=i+1\nprint(FloorPetya)\n\nbreak;\n\n}\nif(i!==0){\nNewFloor+=otherFloor\n\n}\nif(NewFloor==petyaApartment||NewFloor>petyaApartment){\n\nFloorPetya=i+1\nprint(FloorPetya)\n\nbreak;\n\n}\n \n}\n}\n//print(FloorPetya)\n\n"}, {"source_code": "var tc = parseInt(readline());\n\nwhile(tc--){\n var ar = readline().split(' ').map( x => parseInt(x));\n var n = ar[0];\n var x = ar[1];\n\n if(n < 3){\n print(1);\n }else{\n print(Math.ceil((n+(x-2))/x));\n }\n}"}, {"source_code": "var tc = parseInt(readline());\n\nwhile (tc--) {\n\tvar numbers = readline().split(' '),\n\t\tn = parseInt(numbers[0]),\n\t\tx = parseInt(numbers[1]);\n\n\tvar ans = 1;\n\tn -= 2;\n\twhile (n > 0) {\n\t\tn -= x;\n\t\tans++;\n\t}\n\n\tprint(ans);\n}\n"}, {"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\t// f = 0\n\t// const { EOL } = require('os')\n\t// const lines = input.split(EOL) /*your input text, split by lines*/\n\t// main(input, lines)\n})\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\t// console.log(Math.ceil((n - 3) / x) + 2)\n\t// console.log(n, x)\n\t// return\n\tif (n <= 2) {\n\t\tconsole.log(1)\n\t}\n\telse {\n\t\tconsole.log(Math.floor((n - 3) / x + 2))\n\t}\n\t// console.log(line);\n});\n\n// function main() {\n// \tinput.split('\\n').slice(1).map(l => {\n// \t\t[n, x] = l.split(' ').map(x => +x)\n// \t\tconsole.log(Math.ceil((n + 2) / x))\n// \t})\n// }\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "// https://codeforces.com/problemset/problem/1426/A\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet data = [];\nrl.on('line', (input) => {\n data.push(input);\n});\n\nrl.on('close', () => {\n solve(data);\n});\n\nfunction solve(data) {\n\n for (let i = 1; i < data.length; i++) {\n [n, x] = data[i].split(\" \");\n\n if (n <= 2) {\n\n // first floor\n console.log(1);\n\n } else {\n\n floor = 0;\n while (true) {\n lower = floor*x+3;\n upper = (floor+1)*x+2;\n if (n >= lower && n <= upper) {\n console.log(floor + 2);\n break;\n }\n floor++;\n }\n\n }\n }\n\n}\n"}, {"source_code": "var testcases = readline();\n\nfor(var i = 0 ; i < testcases ; i++) {\n var details = readline().split(' ').map(Number)\n var apartmentNumber = details[0];\n var x = details[1];\n var y = Math.ceil(apartmentNumber/x) + 1\n var temp = 2;\n var floor = 1;\n while(y--){\n if(temp >= apartmentNumber){\n print(floor);\n break;\n }\n else{\n temp = temp + x;\n floor++;\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n let b = parseInt(line[1]);\n let res = parseInt(line[1]);\n if (a == 1 || a== 2)\n {\n console.log(1);\n }\n else{\n a -= 2;\n res = a/b;\n res = Math.floor(res)\n if(a%b===0)\n {\n console.log(res+1);\n }\n else\n {\n console.log(res+2);\n }\n }\n }\n}"}, {"source_code": "var t = +readline();\nvar inp;\n\nfor(var i = 0; i < t; i++) {\n inp = readline().split(\" \").map(Number);\n\n if (inp[0] <= 2) {\n print(1);\n } else {\n print(Math.ceil((inp[0] - 2) / inp[1]) + 1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = readLine();\n var loop = 1010;\n while (T--) {\n var arr = readLine();\n arr = arr.split(\" \").map(Number);\n var n = arr[0];\n var x = arr[1];\n var result = 0;\n for (let i = 1; i < loop; i++) {\n if (n <= 2) {\n result = 1;\n break;\n }\n result = Math.floor((n - 3) / x + 2);\n }\n console.log(result);\n }\n}\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet data = [];\n\nrl.on(\"line\", (line) => {\n data.push(line);\n});\n\nrl.on(\"close\", () => {\n floor(data);\n})\n\nfunction floor(data) {\n for (let i = 1; i < data.length; i++) {\n [n, x] = data[i].split(\" \").map(Number);\n \n let currentFloor = 1;\n\n if (n > 2) {\n currentFloor = Math.ceil((n - 2) / x) + 1;\n }\n\n console.log(currentFloor);\n }\n}"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\t \n\t\n\t//let [a,b] = inputReader.readNumberArray();\n\tlet noOfTestCases = inputReader.readNumber();\n\t\n\t//console.log(noOfTestCases,typeof noOfTestCases);\n\twhile(noOfTestCases--){\n\t let [a,b] = inputReader.readNumberArray();\n\t let count = 1;\n\t if(a<=2){\n\t console.log(1);\n\t continue;\n\t }\n\t let floor;\n\t if((a-2)%b===0)\n\t floor = (a-2)/b +1;\n\t else\n\t floor = Math.ceil((a-2)/b)+1;\n\t console.log(floor);\n\t \n\t}\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumber(){\n\t\treturn Number(_inputLines[_lineNumber++]);\n\t}\n\t\t\n\tfunction readNumberArray(){\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}], "negative_code": [{"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\n// process.stdin.on('end', () => {\n// \tconst { EOL } = require('os')\n// \tconst lines = input.split(EOL) /*your input text, split by lines*/\n// \tmain(input, lines)\n// })\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\tconsole.log(Math.ceil((n + 2) / x))\n\t// console.log(line);\n});\n\nfunction main() {\n\tinput.split('\\n').slice(1).map(l => {\n\t\t[n, x] = l.split(' ').map(x => +x)\n\t\tconsole.log(Math.ceil((n + 2) / x))\n\t})\n}\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\tf = 0\n\t// const { EOL } = require('os')\n\t// const lines = input.split(EOL) /*your input text, split by lines*/\n\t// main(input, lines)\n})\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\t// console.log(Math.ceil((n - 3) / x) + 2)\n\tif (n <= 2) {\n\t\tconsole.log(1)\n\t}\n\telse {\n\t\tconsole.log(Math.ceil((n + 2) / x))\n\t}\n\t// console.log(line);\n});\n\n// function main() {\n// \tinput.split('\\n').slice(1).map(l => {\n// \t\t[n, x] = l.split(' ').map(x => +x)\n// \t\tconsole.log(Math.ceil((n + 2) / x))\n// \t})\n// }\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "let input = ''\nprocess.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\tconst { EOL } = require('os')\n\tconst lines = input.split(EOL) /*your input text, split by lines*/\n\tmain(input, lines)\n})\n\nfunction main(input) {\n\tinput.split('\\n').slice(1).map(l => {\n\t\t[n, x] = l.split(' ').map(x => +x)\n\t\tconsole.log(Math.ceil((n + 2) / x))\n\t})\n}\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n let b = parseInt(line[1]);\n if (a == 1 || a == 2)\n {\n console.log(1);\n }\n else{\n a /= b;\n if(a%b===0)\n {\n console.log(Math.ceil(a));\n }\n else\n {\n console.log(Math.ceil(a+1));\n }\n }\n }\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n let t = readLine();\n t = parseInt(t);\n\n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n let b = parseInt(line[1]);\n if (a == 1 || a == 2)\n {\n console.log(1);\n }\n else{\n a /= b;\n if(a%b===0)\n {\n console.log(a);\n }\n else\n {\n console.log(a+1);\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n let b = parseInt(line[1]);\n if (a == 1 || a == 2)\n {\n console.log(1);\n }\n else{\n a -= 2;\n a /= b;\n if(a%b===0)\n {\n console.log(Math.round(a));\n }\n else\n {\n console.log(Math.round(a+1));\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n \n let b = parseInt(line[1]);\n if (a < 3)\n {\n console.log(1);\n }\n else{\n a -= 2;\n a /= b;\n if(a%b===0)\n {\n console.log(Math.round(a+1));\n }\n else\n {\n console.log(Math.round(a+2));\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n let b = parseInt(line[1]);\n if (a == 1 || a == 2)\n {\n console.log(1);\n }\n else{\n a /= b;\n if(a%b===0)\n {\n console.log(Math.round(a));\n }\n else\n {\n console.log(Math.round(a+1));\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \n \n \nfunction main() {\n let t = readLine();\n t = parseInt(t);\n \n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let a = parseInt(line[0]);\n \n let b = parseInt(line[1]);\n if (a == 1 || a== 2)\n {\n console.log(1);\n }\n else{\n a -= 2;\n a /= b;\n if(a%b===0)\n {\n console.log(Math.round(a+1));\n }\n else\n {\n console.log(Math.round(a+2));\n }\n }\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = readLine();\n var loop = 1010;\n while (T--) {\n var arr = readLine();\n arr = arr.split(\" \").map(Number);\n var n = arr[0];\n var x = arr[1];\n var result = 0;\n for (let i = 1; i < loop; i++) {\n if (n <= 2) {\n result = 1;\n }\n result = (n - 3) / x + 2;\n }\n console.log(Math.floor(result));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = readLine();\n var loop = 1010;\n while (T--) {\n var arr = readLine();\n arr = arr.split(\" \").map(Number);\n var n = arr[0];\n var x = arr[1];\n var result = 0;\n for (let i = 0; i < loop; i++) {\n if (n <= 2) {\n result = 1;\n }\n result = (n - 3) / x + 2;\n }\n console.log(Math.floor(result));\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), x = $()\n log(Math.ceil((n - 2) / x) + 1);\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solution(n, x){\n return Math.floor((n - 3) / x) + 2;\n}\n\nfunction main() {\n const N = parseInt(readline());\n \n for(let i = 0; i < N; i++){\n const line = readline().split(' ').map(item => parseInt(item));\n console.log(solution(line[0], line[1]));\n }\n}"}, {"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\tf = 0\n\t// const { EOL } = require('os')\n\t// const lines = input.split(EOL) /*your input text, split by lines*/\n\t// main(input, lines)\n})\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\t// console.log(Math.ceil((n - 3) / x) + 2)\n\tif (n <= 2) {\n\t\treturn 1\n\t}\n\tconsole.log(Math.ceil((n + 2) / x))\n\t// console.log(line);\n});\n\n// function main() {\n// \tinput.split('\\n').slice(1).map(l => {\n// \t\t[n, x] = l.split(' ').map(x => +x)\n// \t\tconsole.log(Math.ceil((n + 2) / x))\n// \t})\n// }\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\t// f = 0\n\t// const { EOL } = require('os')\n\t// const lines = input.split(EOL) /*your input text, split by lines*/\n\t// main(input, lines)\n})\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\t// console.log(Math.ceil((n - 3) / x) + 2)\n\t// console.log(n, x)\n\t// return\n\tif (n <= 2) {\n\t\tconsole.log(1)\n\t}\n\telse {\n\t\tconsole.log(Math.ceil((n - 3) / x) + 2)\n\t}\n\t// console.log(line);\n});\n\n// function main() {\n// \tinput.split('\\n').slice(1).map(l => {\n// \t\t[n, x] = l.split(' ').map(x => +x)\n// \t\tconsole.log(Math.ceil((n + 2) / x))\n// \t})\n// }\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "// let input = `4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`\n\nlet input = ''\n\n// process.stdin.on('data', str => input += str)\nprocess.stdin.on('end', () => {\n\tsetTimeout(() => f = 0)\n\t// const { EOL } = require('os')\n\t// const lines = input.split(EOL) /*your input text, split by lines*/\n\t// main(input, lines)\n})\n\nconst readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet f = 0\n// multi line input\nreadline.on('line', l => {\n\tif (!f) {\n\t\tf = 1\n\t\treturn\n\t}\n\t[n, x] = l.split(' ').map(x => +x)\n\tconsole.log(Math.ceil((n + 2) / x))\n\t// console.log(line);\n});\n\n// function main() {\n// \tinput.split('\\n').slice(1).map(l => {\n// \t\t[n, x] = l.split(' ').map(x => +x)\n// \t\tconsole.log(Math.ceil((n + 2) / x))\n// \t})\n// }\n\n// process.on('SIGINT', function () {\n// \tmain()\n// \tprocess.exit(0);\n// });\n\n// main(`4\n// 7 3\n// 1 5\n// 22 5\n// 987 13`)"}, {"source_code": "function main(){\n var ncases = +readline();\n for(var i = 0; i < ncases; ++i){\n var input = readline().split(' ');\n print(Math.ceil((+input[0] - 2) / +input[1]) +1);\n }\n}\n\nmain();"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n \n}"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n var ln = readline().split(\" \");\n var n = Number(ln[0]),x = Number(ln[1]);\n}"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n var ln = readline().split(\" \");\n var n = Number(ln[0]),x = Number(ln[1]);\n if(n<=2)print(1);\n else print((n-2)/x+((n-2)%x>0)+1);\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var i = 0; i < t; i++) {\n var params = readline();\n var n = parseInt(params.split(\" \")[0]);\n var apts = parseInt(params.split(\" \")[1]);\n var floor = 1;\n if (n > 2) {\n floor = Math.ceil(parseFloat(n) / apts) + 1;\n }\n\n print(floor);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var i = 0; i < t; i++) {\n var params = readline();\n var n = parseInt(params.split(\" \")[0]);\n var apts = parseInt(params.split(\" \")[1]);\n var floor = 1;\n if (n > 2) {\n floor = Math.ceil(n / apts) + 1;\n }\n\n print(floor);\n}\n"}, {"source_code": "var inp = readline().split(' ');\nvar NewFloor=2;\nvar petyaApartment=parseInt(inp[0]);\nvar FloorPetya;\nconst otherFloor=parseInt(inp[1]);\n\n//var i=0;\n\nfor(var i=0;i<1000;i++){\n \n \nif((NewFloor==petyaApartment||NewFloor>petyaApartment)&&i===0){\nFloorPetya=i+1\n\nbreak;\n\n}\nif(i!==0){\nNewFloor+=otherFloor\n\n}\nif(NewFloor==petyaApartment||NewFloor>petyaApartment){\n\nFloorPetya=i+1\n\nbreak;\n\n}\n \n}\nprint(FloorPetya)\n\n"}, {"source_code": "var t = readline();\nvar test = +t;\n\nwhile(t++ <= 0) {\n var test = readline().split(' ').map(Number);\n if (test[0] <= 2) {\n print(1);\n } else {\n print(Math.ceil((test[0] - 2) / test[1]) + 1)\n }\n}\n"}, {"source_code": "var t = Number(readline());\n\nprint(t);\nwhile(false) {\n var test = readline().split(' ').map(Number);\n\n if (test[0] <= 2) {\n print(1);\n } else {\n print(Math.ceil((test[0] - 2) / test[1]) + 1)\n }\n}\n"}, {"source_code": "var t = +readline();\n\nwhile(t++ <= 0) {\n var test = readline().split(' ').map(Number);\n if (test[0] <= 2) {\n print(1);\n } else {\n print(Math.ceil((test[0] - 2) / test[1]) + 1)\n }\n}\n"}, {"source_code": "var t = Number(readline());\nprint(t);\nwhile(t++ <= 0) {\n var test = readline().split(' ').map(Number);\n\n if (test[0] <= 2) {\n print(1);\n } else {\n print(Math.ceil((test[0] - 2) / test[1]) + 1)\n }\n}\n"}], "src_uid": "8b50a0eb2e1c425455b132683d3e6047"} {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n read();\n var cp = [0, 0];\n read().split(' ').forEach(function(sn) {\n ++cp[Number(sn) % 2];\n });\n read();\n var cq = [0, 0];\n read().split(' ').forEach(function(sn) {\n ++cq[Number(sn) % 2];\n });\n write(cp[0] * cq[0] + cp[1] * cq[1]);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nvar gcd = (a, b) => a ? gcd(b % a, a) : b;\nvar lcm = (a, b) => a * b / gcd(a, b);\n\n\nfunction main(){\n\tlet t = +(readLine());\n\n\twhile(t--){\n\t\tlet n = +(readLine());\n\t\tlet p = readLine().split(\" \").map(Number);\n\t\tlet m = +(readLine());\n\t\tlet q = readLine().split(\" \").map(Number);\n\t\tlet ctr=0;\n\t\tlet odd1 = p.filter(x=> x%2==1).length;\n\t\tlet odd2 = q.filter(x=> x%2==1).length;\n\t\tlet even1 = p.filter(x=> x%2==0).length;\n\t\tlet even2 = q.filter(x=> x%2==0).length;\n\t\tctr = odd1*odd2 + even2*even1;\n\t\tconsole.log(ctr);\n\n\t}\n}\n"}, {"source_code": "var queriesCount = parseInt(readline());\n// var queriesCount = 1;\n\nfor (var i = 0; i < queriesCount; i++) {\n readline(); \n var DSL = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n readline();\n var JSL = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n\n // var DSL = [1,2,3]\n // var JSL = [0,3]\n\n var oddsDSL = 0;\n var evensDSL = 0;\n var oddsJSL = 0;\n var evensJSL = 0;\n \n for (var j = 0; j < DSL.length; j++) {\n if (DSL[j] % 2 === 0) {\n evensDSL++;\n } else {\n oddsDSL++;\n }\n }\n for (var k = 0; k < JSL.length; k++) {\n if (JSL[k] % 2 === 0) {\n evensJSL++;\n } else {\n oddsJSL++;\n }\n }\n\n write(((evensDSL * evensJSL) + (oddsDSL * oddsJSL)) + '\\n')\n}\n// });"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n for(let i = 0; i < t; i++){\n let a = lines[1 + i * 4 + 1].split(\" \");\n let b = lines[1 + i * 4 + 3].split(\" \");\n\n let n1 = 0, m1 = 0, n2 = 0, m2 = 0;\n\n a.map((n)=>{if(n%2 == 0) n1++; else m1++;});\n b.map((n)=>{if(n%2 == 0) n2++; else m2++;});\n\n answer += (\"\" + (n1 * n2 + m1 * m2) + '\\n');\n }\n console.log(answer);\n});"}], "negative_code": [{"source_code": "var queriesCount = parseInt(readline());\n// var queriesCount = 1;\n\nfor (var i = 0; i < queriesCount; i++) {\n readline(); \n var DSL = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n readline();\n var JSL = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n\n // var DSL = [1,2,3]\n // var JSL = [0,3]\n\n var oddsDSL = 0;\n var evensDSL = 0;\n var oddsJSL = 0;\n var evensJSL = 0;\n \n for (var i = 0; i < DSL.length; i++) {\n if (DSL[i] % 2 === 0) {\n evensDSL++;\n } else {\n oddsDSL++;\n }\n }\n for (var i = 0; i < JSL.length; i++) {\n if (JSL[i] % 2 === 0) {\n evensJSL++;\n } else {\n oddsJSL++;\n }\n }\n\n write(((evensDSL * evensJSL) + (oddsDSL * oddsJSL)) + '\\n')\n}\n// });"}], "src_uid": "adf4239de3b0034cc690dad6160cf1d0"} {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr))\n }\n});\n\nfunction solve(n, arr) {\nconst t1 = new Date()\n const d = arr.reduce((s, x) => gcd(s, x), arr[0])\n let same = true\n arr = arr.map(x => {\n if (x !== d) same = false\n return x / d\n })\n if (same) return 0\n\n// console.log('pre', new Date() - t1)\n // let j = 0\n // for (var i = 0; i < 2 * n; i++) {\n // j++\n // }\n const tree = []\n createTree(tree, 0, 0, 2 * n - 1, 0)\n// console.log('tree created', new Date() - t1)\n// return\n initTree(tree, gcd, arr)\n// console.log('tree inited', new Date() - t1)\n\n let max = 0\n for (let i = 0; i < n; i++) {\n const last = binarySearch(i, i + n - 1, x => {\n return i === x || queryTree(tree, 0, i, x, gcd) > 1\n })\n const len = last - i + 1\n max = Math.max(max, len)\n // console.log(i, last, queryTree(tree, 0, i, last, gcd))\n }\n return max\n}\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n\n // const tree = []\n // tree[0] = {\n // left: 0,\n // right: n - 1,\n // val\n // }\n\n // const q = [[0, n - 1, 0]]\n // while (q.length) {\n // const [left, right, p] = q.shift()\n // const mid = Math.floor((left + right) / 2)\n // tree[2 * p + 1] = {\n // left,\n // right: mid,\n // val\n // }\n // if (left !== mid) {\n // q.push([left, mid, 2 * p + 1])\n // }\n\n // tree[2 * p + 2] = {\n // left: mid + 1,\n // right,\n // val\n // }\n // if (mid + 1 !== right) {\n // q.push([mid + 1, right, 2 * p + 2])\n // }\n // console.log('q.length ' + q.length)\n // }\n // return tree\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right } = tree[idx]\n if (l === left && r === right) {\n tree[idx].val = val\n return\n }\n\n const mid = Math.floor((left + right) / 2)\n if (r <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } else if (l > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n } else {\n insertTree(tree, 2 * idx + 1, l, mid, val)\n insertTree(tree, 2 * idx + 2, mid + 1, r, val)\n }\n}\nfunction queryTree(tree, idx, l, r, merge) {\n const { left, right } = tree[idx]\n // if (left === right) return tree[idx].val\n if (l === left && r === right) return tree[idx].val\n\n const mid = Math.floor((left + right) / 2)\n if (r <= mid) {\n return queryTree(tree, 2 * idx + 1, l, r, merge)\n } else if (l > mid) {\n return queryTree(tree, 2 * idx + 2, l, r, merge)\n } else {\n const a = queryTree(tree, 2 * idx + 1, l, mid, merge)\n const b = queryTree(tree, 2 * idx + 2, mid + 1, r, merge)\n return merge(a, b)\n }\n}\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}", "positive_code": [{"source_code": "var sz;\r\nvar gets;\r\n\r\nfunction gcd(a, b) {\r\n return b === 0 ? a : gcd(b, a % b);\r\n}\r\n\r\nfunction ini(n) {\r\n\tsize = 1;\r\n\twhile(size < n)\r\n\t\tsize *= 2;\r\n\tgets = new Array(2 * size).fill(0);\r\n}\r\n \r\nfunction sets(i, v, cur, l, r) {\r\n\tif(r - l == 1) {\r\n\t\tgets[cur] = v;\r\n\t\treturn;\r\n\t}\r\n\tvar m = (l + r) >> 1;\r\n\tif(i= rx || lx >= r)\r\n\t\treturn 0;\r\n\tif(lx >= l && rx <= r)\r\n\t\treturn gets[cur];\r\n\tvar m = (lx + rx) >> 1;\r\n\tvar s1 = gt(l, r, 2 * cur + 1, lx, m);\r\n\tvar s2 = gt(l, r, 2 * cur + 2, m, rx);\r\n\treturn gcd(s1, s2);\r\n}\r\n \r\nfunction ret(l, r) {\r\n\treturn gt(l, r, 0, 0, size);\r\n}\r\n\r\nvar t = parseInt(readline());\r\nfor(var tc = 0; tc < t; tc++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n\tfor(var i = 0; i < n; i++) {\r\n\t a[i] = parseInt(a[i]);\r\n\t}\r\n\tini(n);\r\n\tfor(var i = 0; i < n; i++)\r\n\t\tupd(i, a[i]);\r\n\tvar l = 0, r = n - 1;\r\n\twhile(l <= r) {\r\n\t\tvar mid = (l + r) >> 1;\r\n\t\tvar gc = ret(0, mid + 1);\r\n\t\tvar ok = 1;\r\n\t\tfor(var i = 1; i < n; i++)\r\n\t\t{\r\n\t\t\tvar idx = i + mid;\r\n\t\t\tif(idx < n)\r\n\t\t\t\tok &= ret(i, idx + 1) == gc;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tidx %= n;\r\n\t\t\t\tok &= gcd(ret(i, n), ret(0, idx + 1)) == gc;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok) {\r\n\t\t r = mid - 1;\r\n\t\t}\r\n\t\telse {\r\n\t\t l = mid + 1;\r\n\t\t}\r\n\t}\r\n\tprint(l);\r\n}"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst MAX_A = 1000002;\r\nlet n;\r\nlet arr;\r\nlet primes = [];\r\nlet sieve = new Int32Array(MAX_A).fill(0); // min pf of i\r\nfunction pre() {\r\n sieve[1] = 1;\r\n for (let i = 2; i < MAX_A; i++) {\r\n if (sieve[i] == 0) {\r\n sieve[i] = i;\r\n primes.push(i);\r\n for (let j = i; i * j < MAX_A; j++) {\r\n sieve[i * j] = i;\r\n }\r\n }\r\n }\r\n // for (let i = 1; i < 60; i++) {\r\n // printf(\"sieve[%d] %d\\n\", i, sieve[i]);\r\n // }\r\n}\r\nfunction gcd(a, b) {\r\n while (a > 0) {\r\n let c = a;\r\n a = b % a;\r\n b = c;\r\n }\r\n return b;\r\n}\r\nfunction solve() {\r\n const pf = Array.from({ length: n });\r\n for (let i = 0; i < n; i++) {\r\n pf[i] = new Set();\r\n let t = arr[i];\r\n while (t != 1) {\r\n pf[i].add(sieve[t]);\r\n t /= sieve[t];\r\n }\r\n }\r\n // printf(\"arr %j\\n\", arr);\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let p of pf[i]) {\r\n let cnt = 1;\r\n let j = (n + i - 1) % n;\r\n while (pf[j].has(p)) {\r\n pf[j].delete(p);\r\n cnt++;\r\n j = (n + j - 1) % n;\r\n }\r\n j = (i + 1) % n;\r\n while (pf[j].has(p)) {\r\n pf[j].delete(p);\r\n cnt++;\r\n j = (j + 1) % n;\r\n }\r\n // printf(\"i %d p %d cnt %d\\n\",i, p, cnt);\r\n ans = Math.max(ans, cnt);\r\n }\r\n pf[i].clear();\r\n }\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n pre();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n arr = new Int32Array(n);\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = nextInt();\r\n }\r\n let com = arr[0];\r\n for (let i = 1; i < n; i++) {\r\n com = gcd(com, arr[i]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n arr[i] /= com;\r\n }\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "1dfef6ab673b51e3622be6e8ab949ddc"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let t = 0\n const [n, q] = readInts(input,t++)\n\n let arr = [Array(n).fill(false), Array(n).fill(false)]\n\n let result = false\n\n let blocks = 0\n while(t <= q) {\n let [r, c] = readInts(input,t++)\n r--\n c--\n\n arr[r][c] = !arr[r][c]\n\n if(!arr[r][c] && !result) wr('YES')\n\n else if(arr[r][c]) {\n let r1 = (r + 1) % 2\n if(arr[r1][c - 1] && c > 0) blocks ++\n if(arr[r1][c]) blocks ++ \n if(arr[r1][c + 1] && c < n - 1) blocks ++\n if(blocks == 0) {\n result = false\n wr('YES')\n }\n else {\n result = true\n wr('NO')\n }\n }\n else if(!arr[r][c] && result) {\n let r1 = (r + 1) % 2\n if(arr[r1][c - 1]) blocks--\n if(arr[r1][c]) blocks--\n if(arr[r1][c + 1]) blocks--\n if(blocks == 0) {\n result = false\n wr('YES')\n }\n else wr('NO')\n }\n // wr(arr, blocks)\n }\n}", "positive_code": [{"source_code": "var input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar q = input[1];\n\nvar field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);\nvar blocks = 0;\nwhile(q--)\n{\n input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var r = input[0];\n var c = input[1];\n\n var blocksPrev = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n {\n if (field[i] == 0)\n continue;\n\n var selfstatus = 0;\n if (field[i] == 3)\n selfstatus = field[i] == 3;\n\n var leftstatus = 0;\n if (i - 1 >= 0 && (field[i] | field[i - 1]) == 3)\n {\n leftstatus = 1;\n selfstatus |= 1;\n }\n\n var rightstatus = 0;\n if (i + 1 < n && (field[i] | field[i + 1]) == 3)\n {\n rightstatus = 1;\n selfstatus |= 1;\n } \n \n blocksPrev += rightstatus | leftstatus | selfstatus;\n }\n\n field[c - 1] ^= r;\n \n var blocksAfter = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n {\n if (field[i] == 0)\n continue;\n\n var selfstatus = 0;\n if (field[i] == 3)\n selfstatus = field[i] == 3;\n\n var leftstatus = 0;\n if (i - 1 >= 0 && (field[i] | field[i - 1]) == 3)\n {\n leftstatus = 1;\n selfstatus |= 1;\n }\n\n var rightstatus = 0;\n if (i + 1 < n && (field[i] | field[i + 1]) == 3)\n {\n rightstatus = 1;\n selfstatus |= 1;\n } \n \n blocksAfter += rightstatus | leftstatus | selfstatus;\n }\n\n blocks += blocksAfter - blocksPrev;\n \n /*\n var ans = \"yes\";\n for(var i = 0; i < n - 1; i++)\n {\n if ((field[i] | field[i + 1]) == 3)\n {\n ans = \"no\";\n break;\n }\n }\n */\n if (blocks > 0)\n print(\"no\");\n else\n print(\"yes\");\n}"}], "negative_code": [{"source_code": "var input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar q = input[1];\n\nvar field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);\nvar blocks = 0;\nwhile(q--)\n{\n input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var r = input[0];\n var c = input[1];\n\n var blocksPrev = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n if ((field[i - 1] | field[i] | field[i + 1]) == 3)\n blocksPrev++;\n\n field[c - 1] ^= r;\n \n var blocksAfter = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n if ((field[i - 1] | field[i] | field[i + 1]) == 3)\n blocksAfter++;\n\n blocks += blocksAfter - blocksPrev;\n \n /*\n var ans = \"yes\";\n for(var i = 0; i < n - 1; i++)\n {\n if ((field[i] | field[i + 1]) == 3)\n {\n ans = \"no\";\n break;\n }\n }\n */\n if (blocks > 0)\n print(\"no\");\n else\n print(\"yes\");\n}"}, {"source_code": "var input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar q = input[1];\n\nvar field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);\nvar blocks = 0;\nwhile(q--)\n{\n input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var r = input[0];\n var c = input[1];\n\n var blocksPrev = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)\n {\n var status = field[i];\n if (i - 1 >= 0)\n status |= field[i - 1];\n if (i + 1 < n)\n status |= field[i + 1];\n \n if (status == 3)\n blocksPrev++;\n }\n\n field[c - 1] ^= r;\n \n var blocksAfter = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n {\n var status = field[i];\n if (i - 1 >= 0)\n status |= field[i - 1];\n if (i + 1 < n)\n status |= field[i + 1];\n \n if (status == 3)\n blocksAfter++;\n }\n\n blocks += blocksAfter - blocksPrev;\n \n /*\n var ans = \"yes\";\n for(var i = 0; i < n - 1; i++)\n {\n if ((field[i] | field[i + 1]) == 3)\n {\n ans = \"no\";\n break;\n }\n }\n */\n if (blocks > 0)\n print(\"no\");\n else\n print(\"yes\");\n}"}, {"source_code": "var input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar q = input[1];\n\nvar field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);\nvar blocks = 0;\nwhile(q--)\n{\n input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var r = input[0];\n var c = input[1];\n\n var blocksPrev = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)\n {\n var status = field[i];\n if (i - 1 >= 0)\n status |= field[i - 1];\n if (i + 1 < n)\n status |= field[i + 1];\n \n if (status == 3)\n blocksPrev++;\n }\n\n field[c - 1] ^= r;\n \n var blocksAfter = 0;\n for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++) \n {\n var status = field[i];\n if (i - 1 >= 0)\n status |= field[i - 1];\n if (i + 1 < n)\n status |= field[i + 1];\n \n if (status == 3)\n blocksPrev++;\n }\n\n blocks += blocksAfter - blocksPrev;\n \n /*\n var ans = \"yes\";\n for(var i = 0; i < n - 1; i++)\n {\n if ((field[i] | field[i + 1]) == 3)\n {\n ans = \"no\";\n break;\n }\n }\n */\n if (blocks > 0)\n print(\"no\");\n else\n print(\"yes\");\n}"}], "src_uid": "af036416721694d1843368988ca78e8e"} {"source_code": "function main() {\n var row = readline().split(\" \");\n var n = row[0], k = row[1];\n var alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n var possible = alphabet.slice(0, k);\n var pass = Array(Math.ceil(n/k)+1).join(possible);\n pass = pass.slice(0, n);\n print(pass);\n\n return 0;\n}\n\nmain();", "positive_code": [{"source_code": "//Input\nvar firstLine = \"4 3\";\nvar firstLine = \"6 6\";\nvar firstLine = \"5 2\";\n\nvar firstLine = readline();\n\nretorno = eval(firstLine);\n\n//Solution\nfunction eval(firstLine){\n var tmp = firstLine.split(\" \");\n var n = parseInt(tmp[0]);\n var k = parseInt(tmp[1]);\n\n // console.log(getPassword(n, k));\n write(getPassword(n, k));\n //return \"Hola\";\n};\n\nfunction getPassword(n, k){\n var alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n var newPassword = \"\";\n\n for(var i = 0 ; i < k ; i++){\n newPassword += alphabet[i];\n };\n for(var i = k ; i < n ; i++){\n newPassword += newPassword[i%k];\n };\n\n return newPassword;\n};\n"}, {"source_code": "var s = readline().split(' '),\n exactNum = parseInt(s[0]),\n disNum = parseInt(s[1]),\n characters = 'qwertyuiopasdfghjklzxcvbnm',\n x = ''.split(''),\n i = 0;\n while (x.length < disNum){\n x.push(characters.charAt(i));\n i++;\n }\n i = 0;\n while (x.length < exactNum){\n x.push(characters.charAt(i));\n i++;\n if(i >= disNum)\n i = 0;\n }\n \n x = x.join('');\n\n print(x);"}, {"source_code": "var informations = readline().split(' ').map(Number)\n\n var n = informations[0]\n var k = informations[1]\n var firstIndex = 'a'.charCodeAt(0)\n var lastIndex = 'a'.charCodeAt(0) + k\n\n var password = new Array(n).fill('_')\n\n\n var index = firstIndex\n for (var i = 0; i < n; i++) {\n password[i] = String.fromCharCode(index)\n index += 1\n if (index >= lastIndex) {\n index = firstIndex\n }\n }\n\n print(password.join(''))"}, {"source_code": "var informations = readline().split(' ').map(Number)\n\n var n = informations[0]\n var k = informations[1]\n\n var result = []\n for (var i = 0; i < n; i++) {\n result.push(String.fromCharCode(i % k + 'a'.charCodeAt(0)))\n }\n\n print(result.join(''))"}, {"source_code": "function main() {\n var row = readline().split(\" \");\n var n = row[0], k = row[1];\n var alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n var possible = alphabet.slice(0, k);\n var pass = Array(Math.ceil(n/k)+1).join(possible);\n pass = pass.slice(0, n);\n print(pass);\n\n return 0;\n}\n\nmain();"}, {"source_code": "var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar data = [];\ndata.push(readline());\n\nfunction solve() {\n var _data$0$split$map = data[0].split(' ').map(function (d) {\n return parseInt(d);\n });\n\n var _data$0$split$map2 = _slicedToArray(_data$0$split$map, 2);\n\n var n = _data$0$split$map2[0];\n var k = _data$0$split$map2[1];\n\n var pass = Array(k).fill(0).map(function (_, i) {\n return String.fromCharCode(i + 97);\n }).join('');\n var i = 0;\n while (pass.length < n) {\n pass += pass[i];\n i++;\n }\n print(pass);\n}\n\nsolve();"}, {"source_code": "var l = readline().split(' ');\nvar n = l[0];\nvar k = l[1];\nvar str =\"\";\nfor(var i=0; i= passwordChars.length) pointer = 0;\n\tchar = passwordChars[pointer++];\n\tpassword.push(char);\n}\n\nprint(password.join(\"\"));"}, {"source_code": "var input = readline().trim().split(\" \");\nvar n = +input[0], k = +input[1];\n\nvar s = \"qwertyuiopasdfghjklzxcvbnm\";\nvar ans = \"\";\n\nfor (var i = 0; i < n; i++) {\n\tans += s.charAt(i % k);\n}\n\nprint(ans);\n"}, {"source_code": "var generatePassword = (n,k) => {\n if (n < 2 || n > 100 ||\u00a0k < 2 || k > Math.min(n,26))\n throw new Error('Invalid input');\n \n // create an array of letters from a - z;\n const latinLetters = [...Array(26)].map((v,i) => String.fromCharCode(i + 'a'.charCodeAt()));\n // shuffle the array\n latinLetters.sort(() => Math.random() - 0.5); \n const distinctSymbols = [];\n // add the first k elements to the distinctSymbols Array;\n\n while (distinctSymbols.length < k){\n // .shift() removes the first element and return it\n distinctSymbols.push(latinLetters.shift())\n }\n \n let i = 0;\n let output = distinctSymbols.join('')\n while (output.length < n){\n output += distinctSymbols[i++ % k]\n }\n\n console.log(output)\n}\n\nprocess.stdin.on('data',(chunk) => {\n var n = chunk.toString().split(' ')[0];\n var k = chunk.toString().split(' ')[1];\n\n generatePassword(n,k)\n})"}, {"source_code": "var generatePassword = (n,k) => {\n let output = ''\n for (let i = 0; i < k; i++)\n output += String.fromCharCode(i + 'a'.charCodeAt())\n \n const count = Math.floor(n / k);\n const remainingSpots = n % k;\n output = output.repeat(count) + output.slice(0,remainingSpots);\n console.log(output)\n}\n\nprocess.stdin.on('data',(chunk) => {\n var n = chunk.toString().split(' ')[0];\n var k = chunk.toString().split(' ')[1];\n\n generatePassword(n,k)\n})"}, {"source_code": "var letters = [ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o','p','a',\n's','d','f','g','h','j','k','l','z','x','c','v','b','n','m'];\n\nvar input = readline().split(' ');\nvar n = input[0];\nvar k = input[1];\nvar usedLetters = letters.slice(0, k);\nvar ans = '';\nfor (var i = 0; i < n; i++) {\n\tans += usedLetters[i % usedLetters.length];\n}\nprint(ans);\n"}, {"source_code": "var generatePassword = (n,k) => {\n if (n < 2 || n > 100 ||\u00a0k < 2 || k > Math.min(n,26))\n throw new Error('Invalid input');\n // create an array of letters from a - z;\n const latinLetters = [...Array(26)].map((v,i) => String.fromCharCode(i + 'a'.charCodeAt()));\n // shuffle the array (even if we dont shuffle it the answer will be valid)\n latinLetters.sort(() => Math.random() - 0.5);\n // joining the first k elements\n let output = latinLetters.slice(0,k).join('')\n //\n const count = Math.floor(n / k);\n const remainingSpots = n % k;\n\n output = output.repeat(count) + output.slice(0,remainingSpots);\n\n console.log(output)\n}\n\nprocess.stdin.on('data',(chunk) => {\n var n = chunk.toString().split(' ')[0];\n var k = chunk.toString().split(' ')[1];\n\n generatePassword(n,k)\n})"}, {"source_code": "var line = readline().split(\" \"),\n length = line[0],\n count = line[1],\n letters = \"qwertyuiopasdfghjklzxcvbnm\".split(\"\"),\n \n random = function(a, b) {\n return Math.floor(Math.random() * (b - a + 1)) + a;\n },\n \n sel = [],\n selUse = [],\n password = [];\n \nfor (var i = 0; i < count; ++i) {\n var idx = random(0, letters.length - 1),\n q = letters[idx];\n sel.push(q);\n selUse.push(q);\n letters.splice(idx, 1);\n}\n\nvar last;\nfor (var i = 0; i < length; ++i) {\n var cur, idx, db;\n do {\n db = selUse.length ? selUse : sel;\n cur = db[idx = random(0, db.length - 1)];\n } while (cur == last);\n password.push(cur);\n db === selUse && db.splice(idx, 1);\n last = cur;\n}\n\nprint(password.join(\"\"));"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', (input) => {\n rl.close();\n let line = input.split(' ');\n console.log(solve(parseInt(line[0]), parseInt(line[1])));\n});\n\n\nconst solve = (n, k) => {\n let z = k;\n let password = '';\n let alphIndex = 0;\n let characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',\n 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\n 'w', 'x', 'y', 'z'\n ];\n\n while (k !== 0) {\n password += characters[alphIndex++];\n k--;\n }\n\n return password.repeat(Math.ceil(n / z)).slice(0, n);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const [n, k] = readline().split(' ').map(x => parseInt(x));\n const a = [];\n const c = 'abcdefghijklmnopqrstuvwxyz';\n let i = 0, s = 0;\n while (i++ < n) {\n if (s === k) {\n s = 0;\n }\n a.push(c.charAt(s));\n s++;\n }\n // output\n print(a.join(''));\n}\n\n"}, {"source_code": "var a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];\nvar g = readline().split(\" \");\nvar arr = [];\nvar n = Number(g[0]);\nvar k = Number(g[1]);\nfor(i=0;i {\n const [n, k] = d.split(' ').map(Number);\n const letters = 'abcdefghijklmnopqrstuvwxyz';\n const ans = [];\n\n for (let i = 0; i < k; i++) {\n ans.push(letters[i]);\n }\n\n let inc = 0;\n while (ans.length < n) {\n ans.push(ans[inc]);\n inc++;\n }\n\n console.log(ans.join(''));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const [n, k] = d.split(' ').map(Number);\n const letters = 'abcdefghijklmnopqrstuvwxyz';\n // const ans = [];\n let ans = '';\n\n for (let i = 0; i < n; i++) {\n ans += letters[i % k];\n }\n\n console.log(ans);\n\n // for (let i = 0; i < k; i++) {\n // ans.push(letters[i]);\n // }\n\n // let inc = 0;\n // while (ans.length < n) {\n // ans.push(ans[inc]);\n // inc++;\n // }\n\n // console.log(ans.join(''));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const [n, k] = d.split(' ').map(Number);\n // const letters = 'abcdefghijklmnopqrstuvwxyz';\n // const ans = [];\n let ans = '';\n\n for (let i = 0; i < n; i++) {\n ans += String.fromCharCode(i % k + 97);\n }\n\n console.log(ans);\n\n // for (let i = 0; i < k; i++) {\n // ans.push(letters[i]);\n // }\n\n // let inc = 0;\n // while (ans.length < n) {\n // ans.push(ans[inc]);\n // inc++;\n // }\n\n // console.log(ans.join(''));\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n,k] = readint();\n let ab = n + 2 - k;\n let beg = 97;\n for(let i = 0; i < ab; i++) {\n write(String.fromCharCode(beg));\n if(beg == 97) beg = 98;\n else beg = 97;\n } \n beg = 99;\n for(let i = 0; i < k - 2; i++) {\n write(String.fromCharCode(beg));\n beg++;\n }\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet firstLine = input[0].split(' ');\nconst length = parseInt(firstLine[0], 10);\nconst uniqueAmount = parseInt(firstLine[1], 10);\nlet text = '';\nfor (let i=0; i {\n if (n < 2 || n > 100 ||\u00a0k < 2 || k > Math.min(n,26))\n throw new Error('Invalid input');\n \n // create an array of letters from a - z;\n const latinLetters = [...Array(26)].map((v,i) => String.fromCharCode(i + 'a'.charCodeAt()));\n // shuffle the array\n latinLetters.sort(() => Math.random() - 0.5); \n const distinctSymbols = [];\n // add the first k elements to the distinctSymbols Array;\n\n while (distinctSymbols.length < k){\n // .shift() removes the first element and return it\n distinctSymbols.push(latinLetters.shift())\n }\n \n let i = 0;\n let output = distinctSymbols.join('')\n while (output.length < n){\n output += distinctSymbols[i++ % k]\n }\n\n console.log(output)\n}\n\n\ngeneratePassword(99,26)"}, {"source_code": "var generatePassword = (n,k) => {\n if (n < 2 || n > 100 ||\u00a0k < 2 || k > Math.min(n,26))\n throw new Error('Invalid input');\n \n // create an array of letters from a - z;\n const latinLetters = [...Array(26)].map((v,i) => String.fromCharCode(i + 'a'.charCodeAt()));\n // shuffle the array\n latinLetters.sort(() => Math.random() - 0.5); \n const distinctSymbols = [];\n // add the first k elements to the distinctSymbols Array;\n\n while (distinctSymbols.length < k){\n // .shift() removes the first element and return it\n distinctSymbols.push(latinLetters.shift())\n }\n \n let i = 0;\n let output = distinctSymbols.join('')\n while (output.length < n){\n output += distinctSymbols[i++ % k]\n }\n\n return output\n}\n\n\ngeneratePassword(6,4)"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', (input) => {\n rl.close();\n let line = input.split(' ');\n console.log(solve(parseInt(line[0]), parseInt(line[1])));\n});\n\n\nconst solve = (n, k) => {\n\n let password = '';\n let alphIndex = 0;\n let characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',\n 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\n 'w', 'x', 'y', 'z'\n ];\n\n while (k !== 0) {\n password += characters.shift();\n k--;\n }\n n -= 26 - characters.length;\n while (n !== 0) {\n if (alphIndex === characters.length - 1) alphIndex = 0;\n password += characters[alphIndex++];\n n--;\n }\n return password;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const [n, k] = readline().split(' ').map(x => parseInt(x));\n const a = [];\n const c = 'abcdefghijklmnopqrstuvwxyz';\n let i = 0, s = 0;\n while (i++ < n) {\n if (s < k) {\n a.push(c.charAt(s));\n s++;\n } else {\n s = 0;\n a.push(c.charAt(s));\n }\n }\n // output\n print(a.join(''));\n}\n\n"}, {"source_code": "//Input\n// var firstLine = \"4 3\";\n// var firstLine = \"6 6\";\n// var firstLine = \"5 2\";\n\nvar firstLine = readline();\n\nretorno = eval(firstLine);\n\n//Solution\nfunction eval(firstLine){\n var tmp = firstLine.split(\" \");\n var n = parseInt(tmp[0]);\n var k = parseInt(tmp[1]);\n\n // console.log(getPassword(n, k));\n write(getPassword(n, k));\n //return \"Hola\";\n};\n\nfunction getPassword(n, k){\n var alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n var newPassword = \"\";\n var index = parseInt((Math.random())*26);\n //console.log(\"index: \" + index + \" alphabet[\" + index + \"]: \" + alphabet[index]);\n newPassword += alphabet[index];\n //console.log(\"newPassword: \" + newPassword)\n var nextIndex = index;\n\n for(var i = 1 ; i < n ; i++){\n while(index == nextIndex){\n nextIndex = parseInt((Math.random())*26);\n //console.log(\"index: \" + index + \" nextIndex: \" + nextIndex);\n if(nextIndex != index){\n newPassword += alphabet[nextIndex];\n index = nextIndex;\n break;\n };\n };\n //console.log(\"nextIndex: \" + nextIndex);\n };\n\n\n\n\n return newPassword;\n};\n\n\n\n"}, {"source_code": "var l = readline().split(' ');\nvar n = l[0];\nvar k = l[1];\nvar str =\"\";\nfor(var i=0; i +i);\n\nvar positions = [];\nf.forEach((fi, i) => positions[fi - 1] = i);\n\nvar steps = positions\n .map((pfi, i, p) => Math.abs(pfi - p[i-1] || 0))\n .reduce((sum, diff) => sum + diff);\nprint(steps);\n", "positive_code": [{"source_code": "/* TEST CASE\ninput\n3\n3 1 2\noutput\n3\ninput\n5\n1 3 5 4 2\noutput\n10\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(\" \");\n\tvar fragmentSector = new Array(n + 1);\n\t\n\tvar i;\n\tfor (i = 0; i < n; i++) {\n\t\tfragmentSector[parseInt(splitted[i])] = i;\n\t}\n\n\tvar answer = 0;\n\tfor (i = 2; i <= n; i++) {\n\t\tanswer += Math.abs(fragmentSector[i] - fragmentSector[i - 1]);\n\t}\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "!function(e){function __webpack_require__(_){if(r[_])return r[_].exports;var t=r[_]={exports:{},id:_,loaded:!1};return e[_].call(t.exports,t,t.exports,__webpack_require__),t.loaded=!0,t.exports}var r={};return __webpack_require__.m=e,__webpack_require__.c=r,__webpack_require__.p=\"\",__webpack_require__(0)}([function(e,r,_){e.exports=_(1)},function(e,r){\"use strict\";function solve(e){function calculate(e){for(var r=e.length,_={},t=0;r>t;t++)_[e[t]]=t;for(var a=0,t=1;r>t;t++)a+=Math.abs(_[t+1]-_[t]);return a}print(calculate(e))}var _=(parseInt(readline()),readline().split(\" \").map(function(e){return parseInt(e)}));solve(_)}]);"}, {"source_code": "var n = +readline();\nvar f = readline().split(' ').map(Number);\nvar fm = [];\nvar count = 0;\nfor (var i=0; i a[1] - b[1] );\nfor (var i=0; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, a)=>{\n let count = Infinity;\n for (let i = 0; i < n; i++) {\n let localCount = 0;\n let prev = 0;\n for (let j = i + 1; j < n; j++) {\n if (prev === 0) {\n localCount++;\n prev = a[j];\n } else {\n let match = Math.floor(prev / a[j]);\n let diff = match + 1;\n localCount += diff;\n prev = a[j] * diff;\n }\n }\n prev = 0;\n for (let j = i - 1; j >= 0; j--) {\n if (prev === 0) {\n localCount++;\n prev = a[j];\n } else {\n let match = Math.floor(prev / a[j]);\n let diff = match + 1;\n localCount += diff;\n prev = a[j] * diff;\n }\n }\n count = Math.min(count, localCount);\n }\n\n return count;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n \n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n", "positive_code": [{"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction main() {\r\n let n = nextInt();\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n let ans = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n let t = 0;\r\n let last = 0;\r\n for (let j = i - 1; j >= 0; j--) {\r\n let need = Math.ceil((last + 1) / a[j]);\r\n t += need;\r\n last = need * a[j];\r\n }\r\n last = 0;\r\n for (let j = i + 1; j < n; j++) {\r\n let need = Math.ceil((last + 1) / a[j]);\r\n t += need;\r\n last = need * a[j];\r\n }\r\n ans = Math.min(ans, t);\r\n }\r\n printf(\"%d\\n\", ans);\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n let res = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n const tmp = new Array(n).fill(0),\r\n queue = [[i + 1, 1], [i - 1, -1]];\r\n let count = 0;\r\n for (let [j, dj] of queue) {\r\n if (j < 0 || j >= n) continue;\r\n let num = Math.floor(tmp[j - dj] / (a[j] * dj)) + 1;\r\n tmp[j] = num * a[j] * dj;\r\n count += num;\r\n queue.push([j + dj, dj]);\r\n }\r\n res = Math.min(res, count);\r\n }\r\n console.log(res);\r\n}\r\n\r\nfunction main(inputs) {\r\n const n = Number(inputs[0].trim());\r\n const a = inputs[1].trim().split(' ').map(Number);\r\n solve(n, a);\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n let index = 0;\n\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n}\n\nfunction solution(testCase, index) {\n const { n, a } = testCase;\n\n let result = Infinity;\n\n for (let pivot = 0; pivot < n; pivot++) {\n let moves = 0;\n let ref = 1;\n const b = new Array(n).fill(0);\n // Left\n for (let i = pivot - 1; i >= 0; i--) {\n const nbMovesNeeded = Math.ceil((ref - a[i]) / a[i]) + 1;\n\n ref = nbMovesNeeded * a[i];\n b[i] = -ref;\n ref++;\n moves += nbMovesNeeded;\n }\n\n ref = 1;\n // Right\n for (let i = pivot + 1; i < n; i++) {\n const nbMovesNeeded = Math.ceil((ref - a[i]) / a[i]) + 1;\n\n ref = nbMovesNeeded * a[i];\n b[i] = ref;\n ref++;\n moves += nbMovesNeeded;\n }\n\n if (moves < result) result = moves;\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n s = s.split(\"\\n\");\n\n main();\n});\n\nfunction main() {\n const n = Number(s[0]);\n const a = s[1].split(\" \").map(Number);\n\n solve(n, a);\n}\n\nfunction solve(n, a) {\n let count = Infinity;\n\n for (let i = 0; i < n; i++) {\n let tc = 0;\n // Greater\n let prev = 0;\n for (let j = i + 1; j < n; j++) {\n if (a[j] > prev) {\n tc++;\n prev = a[j];\n } else {\n const newValCount = Math.floor(prev / a[j]) + 1;\n tc += newValCount;\n prev = a[j] * newValCount;\n }\n }\n\n // Lesser\n prev = 0;\n for (let j = i - 1; j >= 0; j--) {\n if (a[j] > prev) {\n tc++;\n prev = a[j];\n } else {\n const newValCount = Math.floor(prev / a[j]) + 1;\n tc += newValCount;\n prev = a[j] * newValCount;\n }\n }\n\n count = Math.min(count, tc);\n }\n\n console.log(count);\n}\n"}, {"source_code": "'use strict';\n\nconst { timeStamp } = require('console');\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst times = (target, using)=>{\n return Math.max(1, Math.ceil(target/using))\n}\n\nconst calc = (n, A)=>{\n let ans = Infinity;\n for (let i=0; i=0; j--){\n let ops = times(target, A[j]);\n cur += ops;\n target = ops*A[j]+1;\n }\n target = 1;\n for (let j=i+1; j parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let cnt = Infinity;\r\n const left = (pos) => {\r\n let op = 0,\r\n prev = 0;\r\n for (let i = pos - 1; i >= 0; i--) {\r\n if (prev === 0) {\r\n prev = -1 * arr[i];\r\n op++;\r\n } else {\r\n let k = Math.floor(Math.abs(prev) / arr[i]) + 1;\r\n prev = k * arr[i] * -1;\r\n op += k;\r\n }\r\n }\r\n return op;\r\n };\r\n const right = (pos) => {\r\n let op = 0,\r\n prev = 0;\r\n for (let i = pos + 1; i < n; i++) {\r\n if (prev === 0) {\r\n op++;\r\n prev = arr[i];\r\n } else {\r\n let k = Math.floor(prev / arr[i]) + 1;\r\n prev = k * arr[i];\r\n op += k;\r\n }\r\n }\r\n return op;\r\n };\r\n for (let i = 0; i < n; i++) cnt = Math.min(cnt, left(i) + right(i));\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction main() {\r\n let n = nextInt();\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n let ans = 1e15;\r\n for (let i = 0; i < n; i++) {\r\n let t = 0;\r\n let last = 0;\r\n for (let j = i - 1; j >= 0; j--) {\r\n let need = Math.ceil((last + 1) / a[j]);\r\n t += need;\r\n last = need * a[j];\r\n }\r\n last = 0;\r\n for (let j = i + 1; j < n; j++) {\r\n let need = Math.ceil((last + 1) / a[j]);\r\n t += need;\r\n last = need * a[j];\r\n }\r\n ans = Math.min(ans, t);\r\n }\r\n printf(\"%d\\n\", ans);\r\n}\r\n"}], "src_uid": "da2fb0ea61808905a133021223f6148d"} {"source_code": "const check = (str,pos,n)=>{\r\n let issub;\r\n if(str[pos]===\"a\"){\r\n if(pos+2>n) issub = false;\r\n else if((str[pos+1]===\"b\")&&(str[pos+2]===\"c\")) issub = true;\r\n else issub = false;\r\n }\r\n else if(str[pos]===\"b\"){\r\n if((pos===1)||(pos+1>n)) issub = false;\r\n else if((str[pos-1]===\"a\")&&(str[pos+1]===\"c\")) issub = true;\r\n else issub = false;\r\n }\r\n else{\r\n if(pos<3) issub = false;\r\n else if((str[pos-1]===\"b\")&&(str[pos-2]===\"a\")) issub = true;\r\n else issub = false;\r\n }\r\n return issub;\r\n}\r\nconst solve = (n,str,q)=>{\r\n let cnt = 0;\r\n for(let i=1;i<=n;i++){\r\n if((str[i]===\"a\")&&((i+2)<=n)){\r\n if((str[i+1]===\"b\")&&(str[i+2]===\"c\")) cnt++;\r\n }\r\n }\r\n for(let i=0;iparseInt(cur));\r\n let str = (\" \"+readline().trim()).split(\"\");\r\n let q = [];\r\n for(let i=0;i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n \r\nfunction main () {\r\n\tlet [n, q] = rna();\r\n\tlet s = rl().split('');\r\n \r\n\tlet cnt = 0;\r\n\tfor (let i = 0; i < s.length - 2; i++) {\r\n\t\tif (s.slice(i, i + 3).join('') == 'abc') {\r\n\t\t\tcnt++;\r\n\t\t}\r\n\t}\r\n \r\n\twhile (q--) {\r\n\t\tlet [i, c] = ra();i--;\r\n\t\tconst olds = s.slice(Math.max(0, i-2), i+3).join('');\r\n\t\ts[i] = c;\r\n\t\tconst news = s.slice(Math.max(0, i-2), i+3).join('');\r\n \r\n\t\tconst dif = news.includes('abc') - olds.includes('abc');\r\n\t\tcnt += dif;\r\n\t\tconsole.log(cnt);\r\n\t}\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, q] = rna();\r\n\tlet s = rl().split('');\r\n\r\n\tlet cnt = 0;\r\n\tfor (let i = 0; i < s.length - 2; i++) {\r\n\t\tif (s.slice(i, i + 3).join('') == 'abc') {\r\n\t\t\tcnt++;\r\n\t\t}\r\n\t}\r\n\r\n\twhile (q--) {\r\n\t\tlet [i, c] = ra();i--;\r\n\t\tconst olds = s.slice(Math.max(0, i-2), i+3).join('');\r\n\t\ts[i] = c;\r\n\t\tconst news = s.slice(Math.max(0, i-2), i+3).join('');\r\n\r\n\t\tconst dif = news.includes('abc') - olds.includes('abc');\r\n\t\tcnt += dif;\r\n\t\tconsole.log(cnt);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "db473ad780a93983667d12b1357c6e2f"} {"source_code": "n=1000000\na=new Array(n)\ncounts=new Array(9)\ncountAts=new Array(9)\nfor(i=0;i<9;i++)\n{\n\tcounts[i]=0\n\tcountAts[i]=new Array(n+1)\n\tcountAts[i][0]=0\n}\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nq=parseInt(readline())\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nq=Number(readline())\nans=new Array(q)\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nq=Number(readline())\nans=new Array(q)\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nq=Number(readline())\nans=Array(q)\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nq=parseInt(readline())\nans=new Array(q)\nfor(i=0;i9)\n\t{\n\t\tif(a[cur-1]!==undefined)\n\t\t{\n\t\t\tcur=a[cur-1]\n\t\t\tbreak\n\t\t}\n\t\tpro=1\n\t\twhile(cur>1)\n\t\t{\n\t\t\tpro*=cur%10>1?cur%10:1\n\t\t\tcur=parseInt(cur/10)\n\t\t}\n\t\tcur=pro\n\t}\n\ta[i]=cur\n\tcounts[cur-1]++\n\tfor(j=0;j<9;j++)\n\t\tcountAts[j][i+1]=counts[j]\n}\n\nfor(i=0;i= 0; i--) {\n var dig = Number(num[i])\n \n if (!hasZeros && dig === 0) {\n hasZeros = true\n }\n \n dig %= 3\n \n sumMod += dig\n sumMod %= 3\n \n if (dig !== 0 && scapeGoats[dig - 1].length < 2) {\n scapeGoats[dig - 1].push(i)\n }\n}\n\nimpossible = false\n\nvar del = []\nvar del2 = []\nif (sumMod !== 0) {\n if (scapeGoats[sumMod - 1].length > 0) {\n del.push(scapeGoats[sumMod - 1][0])\n }\n if (scapeGoats[1 - (sumMod - 1)].length === 2 && num.length > 2) {\n del2 = del2.concat(scapeGoats[1 - (sumMod - 1)])\n }\n}\n\n\nvar ans = num\n\nfor (var i = 0; i < del.length; i++) {\n ans = ans.substring(0, del[i]) + ans.substring(del[i] + 1)\n}\n\nans = ans.replace(/^0*/, '')\n\nif (ans === '' && hasZeros) {\n ans = '0'\n}\n\nvar ans2 = num\n\nfor (var i = 0; i < del2.length; i++) {\n ans2 = ans2.substring(0, del2[i]) + ans2.substring(del2[i] + 1)\n}\n\nans2 = ans2.replace(/^0*/, '')\n\nif (ans2 === '' && hasZeros) {\n ans2 = '0'\n}\n\nif (sumMod !== 0 && del.length === 0) {\n ans = ''\n}\n\nif (sumMod !== 0 && del2.length === 0) {\n ans2 = ''\n}\n\nif (ans === '' && ans2 === '') {\n print('-1')\n} else {\n print(ans.length < ans2.length? ans2 : ans)\n}\n", "positive_code": [{"source_code": " var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false;\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target !== -1 && target !== 0) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n } else if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print(0);\n done = true;\n } else {\n print(-1);\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n if(res.length === 0) {\n print(-1);\n done = true;\n } else {\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length === 0) {\n res = '0';\n }\n print(res);\n done = true;\n }\n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n if(res.length === 0) {\n print(-1);\n done = true;\n } else {\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length === 0) {\n res = '0';\n }\n print(res);\n done = true;\n }\n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }"}], "negative_code": [{"source_code": "// Neither neat nor clear :(\nvar num = readline()\n\nvar scapeGoats = [[], []]\n\nvar hasZeros = false\n\nvar sumMod = 0\n\nfor (var i = num.length - 1; i >= 0; i--) {\n var dig = Number(num[i])\n \n if (!hasZeros && dig === 0) {\n hasZeros = true\n }\n \n dig %= 3\n \n sumMod += dig\n sumMod %= 3\n \n if (dig !== 0 && scapeGoats[dig - 1].length < 2) {\n scapeGoats[dig - 1].push(i)\n }\n}\n\nimpossible = false\n\nvar del = []\n\nif (sumMod !== 0) {\n if (scapeGoats[sumMod - 1].length > 0) {\n del.push(scapeGoats[sumMod - 1][0])\n } else if (scapeGoats[1 - (sumMod - 1)].length === 2 && num.length > 2) {\n del = del.concat(scapeGoats[1 - (sumMod - 1)])\n } else {\n impossible = true\n }\n}\n\nif (impossible) {\n print('-1')\n} else {\n var ans = num\n\n for (var i = 0; i < del.length; i++) {\n ans = ans.substring(0, del[i]) + ans.substring(del[i] + 1)\n }\n \n ans = ans.replace(/^0*/, '')\n \n if (ans === '' && hasZeros) {\n ans = '0'\n }\n \n if (ans === '') {\n print('-1')\n } else {\n print(ans)\n }\n}"}, {"source_code": "// Neither neat nor clear :(\nvar num = readline()\n\nvar scapeGoats = [[], []]\n\nvar hasZeros = false\n\nvar sumMod = 0\n\nfor (var i = num.length - 1; i >= 0; i--) {\n var dig = Number(num[i])\n \n if (!hasZeros && dig === 0) {\n hasZeros = true\n }\n \n dig %= 3\n \n sumMod += dig\n sumMod %= 3\n \n if (dig !== 0 && scapeGoats[dig - 1].length < 2) {\n scapeGoats[dig - 1].push(i)\n }\n}\n\nimpossible = false\n\nvar del = []\nvar del2 = []\nif (sumMod !== 0) {\n if (scapeGoats[sumMod - 1].length > 0) {\n del.push(scapeGoats[sumMod - 1][0])\n }\n if (scapeGoats[1 - (sumMod - 1)].length === 2 && num.length > 2) {\n del2 = del2.concat(scapeGoats[1 - (sumMod - 1)])\n }\n}\n\n\nvar ans = num\n\nfor (var i = 0; i < del.length; i++) {\n ans = ans.substring(0, del[i]) + ans.substring(del[i] + 1)\n}\n\nans = ans.replace(/^0*/, '')\n\nif (ans === '' && hasZeros) {\n ans = '0'\n}\n\nvar ans2 = num\n\nfor (var i = 0; i < del2.length; i++) {\n ans2 = ans2.substring(0, del2[i]) + ans2.substring(del2[i] + 1)\n}\n\nans2 = ans2.replace(/^0*/, '')\n\nif (ans2 === '' && hasZeros) {\n ans2 = '0'\n}\n\nif (del.length === 0) {\n ans = ''\n}\n\nif (del2.length === 0) {\n ans2 = ''\n}\n\nif (ans === '' && ans2 === '') {\n print('-1')\n} else {\n print(ans.length < ans2.length? ans2 : ans)\n}\n"}, {"source_code": "\n var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false;\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target !== -1 && target !== 0) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n } else if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print(0);\n done = true;\n } else {\n print(-1);\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n }\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print('0');\n done = true;\n }\n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }"}, {"source_code": "\n var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false;\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target !== -1 && target !== 0) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n } else if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print(0);\n done = true;\n } else {\n print(-1);\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > zeroes || res.length === 1) {\n res = res.slice(zeroes);\n if(res.length === 0) {\n res = '0';\n }\n print(res);\n done = true;\n }\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n if(res.length > zeroes || res.length === 1) {\n res = res.slice(zeroes);\n if(res.length === 0) {\n res = '0';\n }\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print('0');\n done = true;\n }\n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }\n "}, {"source_code": " var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false;\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target !== -1 && target !== 0) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n } else if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print(0);\n done = true;\n } else {\n print(-1);\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n }\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n if(res.length > zeroes || res.length === 1) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print('0');\n done = true;\n }\n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }"}, {"source_code": " var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n }\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n } \n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }"}, {"source_code": " var d = readline();\n var sum = 0;\n for(var i = 0; i < d.length; i += 1) {\n sum += parseInt(d[i]);\n sum %= 3;\n }\n var done = false\n if(sum === 0) {\n print(d);\n done = true;\n }\n if(!done) {\n var target = -1;\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === sum) {\n target = i;\n break;\n }\n }\n var target2 = [];\n for(var i = d.length - 1; i >= 0; i -= 1) {\n if(parseInt(d[i]) % 3 === 3 - sum) {\n target2.unshift(i);\n if(target2.length === 2) {\n break;\n }\n }\n }\n if(target === 0) {\n var zeroes = 0;\n for(var i = 1; i 0) {\n print(res);\n done = true;\n } else if(d[d.length - 1] === '0') {\n print(0);\n done = true;\n } else {\n print(-1);\n done = true;\n }\n } else {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n }\n }\n }\n } else if(!done && target === -1) {\n if(target2.length === 2) {\n var res = d.slice(0, target2[0]) + d.slice(target2[0] + 1, target2[1]) + d.slice(target2[1] + 1, d.length);\n var zeroes = 0;\n for(var i = 0; i < res.length; i += 1) {\n if(res[i] === '0') {\n zeroes += 1;\n } else {\n break;\n }\n }\n res = res.slice(zeroes);\n if(res.length > 0) {\n print(res);\n done = true;\n } \n } else if(!done) {\n print(d.slice(0, target) + d.slice(target + 1, d.length));\n done = true;\n }\n }\n }\n if(!done) {\n print(-1);\n }\n"}], "src_uid": "df9942d1eb66b1f3b5c6b665b446cd3e"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m, k] = rna();\r\n\r\n\t\tif \t\t(m < n - 1) \t\t\tconsole.log('NO'); // non connected graph\r\n\t\telse if (m > n * (n - 1) / 2)\tconsole.log('NO'); // multiedged graph\r\n\t\telse if (k < 2)\t\t\t\tconsole.log('NO');\r\n\t\telse if (k == 2)\t\t\t\tconsole.log(n == 1 \t\t\t\t ? 'YES' : 'NO');\r\n\t\telse if (k == 3) \t\t\t\tconsole.log(m == n * (n - 1) / 2 ? 'YES' : 'NO');\r\n\t\telse if (k > 3) \t\t\t\tconsole.log('YES');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n let l = ((n) * (n - 1n)) / 2n;\r\n if(l1n) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n continue;\r\n }\r\n if(l===m){\r\n if(k>2n) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n continue;\r\n }\r\n if(k>3n) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n \r\n }\r\n};\r\nsolve();"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let q = 0; q < Q; q++) {\r\n let [N, M, K] = readline().split(\" \").map((a) => parseInt(a));\r\n\r\n let full = N * (N-1) / 2;\r\n\r\n if (M < N - 1 || M > full) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n if (M === full) {\r\n if (N === 1) {\r\n\tconsole.log(K >= 2? \"YES\": \"NO\");\r\n } else {\r\n\tconsole.log(K >= 3? \"YES\": \"NO\");\r\n }\r\n continue;\r\n }\r\n\r\n console.log(K >= 4? \"YES\": \"NO\");\r\n }\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m, k] = rna();\r\n\r\n\t\tfunction put (ans) { console.log(ans); }\r\n\r\n\t\tif (m < n - 1) \t\t\t\tput('NO');\r\n\t\telse if (m > n*(n-1)/2)\t \tput('NO');\r\n\t\telse if (k < 2)\t\t\t\tput('NO');\r\n\t\telse if (k == 2)\t\t\tput(n == 1 ? 'YES' : 'NO');\r\n\t\telse if (k == 3) \t\t\tput(m == n * (n - 1) / 2 ? 'YES' : 'NO');\r\n\t\telse if (k > 3) \t\t\tput('YES');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\nvar stdin_input = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\n\nconst rl = () => dataitr.next().value.trim();\nconst rn = () => Number(rl());\nconst ra = () => rl().split(' ');\nconst rna = () => ra().map(x => Number(x));\n\nfunction main () {\n\tlet t = rn();\n\twhile (t--) {\n\t\tlet [n, m, k] = rna();\n\n\t\tif (k < 2) console.log('NO');\n\t\tif (k == 2) console.log(n == 1 ? 'YES' : 'NO');\n\t\tif (k == 3) console.log(m == n * (n - 1) / 2 ? 'YES' : 'NO');\n\t\tif (k > 3) console.log('YES');\n\t}\n}\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m, k] = rna();\r\n\r\n\t\tif (k < 3) console.log('NO');\r\n\t\tif (k > 3) console.log('YES');\r\n\t\tif (k == 3) console.log(m == n * (n - 1) / 2 ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let l = (BigInt(n) * BigInt(n - 1)) / 2n;\r\n if (m > l) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n if (n === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n if (n > m) {\r\n if (n - m > 1) console.log(\"NO\");\r\n else {\r\n if (m < k - 1) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n } else {\r\n if (k - 1 === 0) console.log(\"NO\");\r\n else if (k - 1 > Math.floor(n / 2)) console.log(\"YES\");\r\n else {\r\n if (BigInt(m) >= l) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let l = (BigInt(n) * BigInt(n - 1)) / 2n;\r\n if (m > l) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n if (n === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n if (n > m) {\r\n if (n - m > 1) console.log(\"NO\");\r\n else {\r\n if (m < k - 1) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n } else {\r\n if (k - 1 === 0) console.log(\"NO\");\r\n else if (k - 1 < Math.floor(n / 2)) console.log(\"YES\");\r\n else {\r\n if (BigInt(m) >= l) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n > m) {\r\n if (n - m > 1) console.log(\"NO\");\r\n else {\r\n if (m < k - 1) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n } else {\r\n if (k - 1 === 0) console.log(\"NO\");\r\n else if (k - 1 > Math.floor(n / 2)) console.log(\"YES\");\r\n else {\r\n let l = (BigInt(n) * BigInt(n - 1)) / 2n;\r\n if (BigInt(m) >= l) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let q = 0; q < Q; q++) {\r\n let [N, M, K] = readline().split(\" \").map((a) => parseInt(a));\r\n\r\n let full = N * (N-1) / 2;\r\n\r\n if (M < N - 1 || M > full) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n if (M === full) {\r\n console.log(K >= 3? \"YES\": \"NO\");\r\n continue;\r\n }\r\n\r\n console.log(K >= 4? \"YES\": \"NO\");\r\n }\r\n}\r\n\r\n"}], "src_uid": "f853a61741518cb884c00c8b760692aa"} {"source_code": "const alphabets = []\n\nconst start = 'a'.charCodeAt(0)\nconst end = 'z'.charCodeAt(0)\nfor (let s = start; s<=end; s++) {\n alphabets.push(String.fromCharCode(s))\n}\n\nconst processData = (lines) => {\n const num = +lines[0]\n for (let i=0; i +x)\n let res = ''\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar input_lines;\nvar currentLine = 0;\nprocess.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', function (_) {\n input_lines = inputString.trim().split('\\n').map(function (str) {\n return str.trim();\n });\n main();\n});\nfunction input() {\n return input_lines[currentLine++];\n}\nfunction EOF() {\n return currentLine >= input_lines.length;\n}\nvar letters = \"qwertyuiopasdfghjklzxcvbnm\";\nfunction main() {\n var t = parseInt(input());\n for (var casen = 0; casen < t; casen++) {\n var _a = input().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], a = _a[1], b = _a[2];\n var answer = [];\n while (answer.length < n) {\n for (var i = 0; i < b - 1; i++) {\n answer.push(letters.charAt(i));\n }\n for (var i = 0; i < a - (b - 1); i++) {\n answer.push(letters.charAt(b - 1));\n }\n }\n answer = answer.splice(0, n);\n console.log(\"\".concat.apply(\"\", answer));\n }\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, a, b] = readInts()\n let ans = ''\n let ax = ''\n for(let i = 0, j = 97; i < b; i++) {\n ax += String.fromCharCode(j)\n j++\n }\n ax = ax.padEnd(a, 'a')\n ans = ans.padEnd(n, ax)\n wr(ans)\n }\n}"}, {"source_code": "\n//DISABLE THIS LINE END ENABLE NEXT\n//const rl = require('readline').createInterface({input: require('fs').createReadStream('input.txt')});\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst write = (...args) => {\n process.stdout.write(args.join(' ') );\n}\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\n\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nfunction repeat(pattern, count) {\n if (count < 1) return '';\n var result = '';\n while (count > 1) {\n if (count & 1) result += pattern;\n count >>= 1, pattern += pattern;\n }\n return result + pattern;\n}\n\nfunction main() {\n\tvar parr = \"abcdefghijklmnopqrstuvwxyz\";//.split();\n\tvar y = +readline()\n\twhile(y > 0) {\n\t\tvar z = readline().split(' ');\n\t\tvar n = +z[0];\n\t\tvar a = +z[1];\n\t\tvar b = +z[2];\n\t\tvar res = \"\";\n\t\t//[0,...., b-1] from parr\n\t\tvar res = \"\";\n\t\tvar p = parr.substring(0,b);\n\t\tvar count = Math.floor(n / p.length);\n\t\tres = repeat(p, count);\n\t\twhile(res.length < n) {\n\t\t\tres += p;\n\t\t}\n\t\tres = res.substring(0, n);\n\t\tif (y > 1) {\n\t\t\twrite(res + '\\n');\n\t\t} else {\n\t\t\twrite(res);\n\t\t}\n\t\ty--;\n\t}\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, a, b] = d.split(' ').map(Number);\n let ans = '';\n\n let i = 0;\n while (ans.length < n) {\n ans += String.fromCharCode((i % 26) % b + 97);\n i++;\n\n if (i === a) {\n i = 0;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n arr = arr.map(el => +el);\n let l = arr[0];\n arr = arr.slice(1);\n const a = 97;\n for (let i = 0; i < l; i++){\n let temp = arr.slice(i*3,i*3+3);\n let str = \"\";\n let max = temp[2] + a;\n let current = a;\n for (let i = 0; i < temp[0]; i++) {\n str += String.fromCharCode(current);\n current++;\n if (current === max) current = a;\n }\n console.log(str);\n }\n}\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar currentLine = 0;\nprocess.stdin.on('data', function (input) { inputString += input; });\nprocess.stdin.on('end', function (_) { inputString = inputString.split('\\n'); main(); });\nvar readline = function () { return inputString[currentLine++]; };\nfunction main() {\n var tests = parseInt(readline());\n var abc = ' abcdefghijklmnopqrstuvwxyz';\n while (tests--) {\n var _a = readline().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], a = _a[1], b = _a[2];\n var copies = Math.floor(n / b) + 1;\n var ans = '';\n while (b) {\n ans += abc[b];\n b--;\n }\n ans = ans.repeat(copies);\n ans = ans.substr(0, n);\n console.log(ans);\n }\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n var a = input1[0]\n var b = input1[1]\n var c = input1[2]\n var str=\"\"\n for(var i=0; i {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst main = () => {\n let t = Number(readline());\n while (t--) {\n let [n, a, b] = readline().split(' ').map(x => parseInt(x));\n let s = '';\n let ci = 0;\n const CHAR_CODE_BASE = 97;\n for (let i = 0; i < n; i++) {\n s += String.fromCharCode(ci + CHAR_CODE_BASE);\n ci++;\n ci %= b;\n }\n print(s);\n }\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, a, b) {\n let res = '';\n let substr = '';\n let alphabet = 'abcdefghijklmnopqrstuvwxyz';\n for (let i = 0; i < b; i++) {\n substr += alphabet[i];\n }\n for (let i = 0; i < n; i++) {\n res += substr[i % substr.length];\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n // let n = parseInt(readLine());\n let [n, a, b] = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, a, b);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let n = parseInt(readline(), 10);\n const Acode = 'a'.charCodeAt(0)\n\n for (var j = 0; j < n; j++) {\n const [n, a ,b] = readline().split(\" \").map(e => parseInt(e));\n let res = '';\n var alaphabet = [];\n for (var i = 0; i < b; i++) {\n alaphabet.push(String.fromCharCode((Acode+i)));\n }\n for (var i = 0; i < n; i++) {\n res += alaphabet[i % alaphabet.length];\n }\n console.log(res);\n }\n \n}\n"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const inp = getInts()\n\n let s = ''\n let init = 'a'.charCodeAt()\n for (let i = 0; i < inp[2]; ++i) {\n s += String.fromCharCode(init ++)\n }\n \n while (s.length < inp[1]) s += 'a'\n while (s.length < inp[0]) s += s\n print(s.slice(0, inp[0]))\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nvar ch = 'a';\nvar acode = ch.charCodeAt(0);\n\n\nfor (var tt = 0; tt < t; tt++) {\n var inp = readline().split(' ').map(Number);\n var n = inp[0];\n var a = inp[1];\n var b = inp[2] - 1;\n var res = '';\n \n for (var i = 0; i < n; i++) {\n var pos = i % a;\n if (pos > b) {\n res += String.fromCharCode(acode+b);\n } else {\n res += String.fromCharCode(acode+pos);\n }\n }\n \n write(res+'\\n');\n}\n"}, {"source_code": "var n = +readline();\nvar string = 'abcdefghijklmnopqrstuvwxyz';\nfor(var i = 0; i < n; i++){\n var s = readline().split(' ').map(Number);\n var x = s[0];\n var a = s[1];\n var b = s[2];\n \n var _ = parseInt(x/a);\n var str = string.slice(0,b).repeat(parseInt(b/a)+1).slice(0,a);\n str = str.repeat(parseInt(x/b) + 1).slice(0,x);\n write(str + '\\n');\n}"}, {"source_code": "var n = +readline();\n\nvar alp = 'abcdefghijklmnopqrstuvwxyz';\nfor (var i = 0; i < n; i ++) {\n var s = readline().split(' ').map(Number);\n \n var x = s[0];\n var a = s[1];\n var b = s[2];\n \n var rp = parseInt(x / a);\n var str = alp.slice(0, b).repeat(parseInt(b / a) + 1).slice(0, a);\n str = str.repeat(parseInt(x / b) + 1).slice(0, x);\n write(str + '\\n');\n}\n\n// abc abcab abcabab"}, {"source_code": "function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(n); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nvar t = readline();\n\nwhile (t--) {\n var _readline$split = readline().split(' '),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n a = _readline$split2[1],\n b = _readline$split2[2]; //1, 2, 3\n\n\n var charCods = [];\n\n for (var i = 97; i < 97 + 26; i++) {\n charCods.push(i);\n }\n\n var str = String.fromCharCode.apply(String, charCods).slice(0, b);\n str = str.repeat(Math.ceil(n / str.length)).slice(0, n);\n print(str);\n}"}, {"source_code": "var n = Number(readline());\nvar inp;\nfor(var i = 0; i < n; i++){\n inp = readline().split(' ').map(cur => Number(cur));\n stringGenerator(...inp);\n}\n\nfunction stringGenerator (l,a,b){\n\nconst arr = [...Array(26)].map((cur,i) => String.fromCharCode(97+i));\n\nvar res = [];\n\nfor(var i = 0; i< l ;i++){\nres.push(arr[i%b]); \n} \n \n print(res.join(''));\n}"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(num) {\n return +num;\n}\n\nvar alph = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];\n\nfor (var i = 0; i < t; i++) {\n var data = readline().split(' ').map(mapper);\n var n = data[0];\n var a = data[1];\n var b = data[2];\n \n var letters = alph.slice(0, b);\n var str = letters.join('');\n var res = '';\n \n for(var j = 0; j < Math.ceil(n / b); j++) {\n res += str;\n }\n\n res = res.slice(0, n);\n print(res);\n}"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n var arrange = []; \n var startString = 97;\n \n for(var j=0;j {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, a, b] = readInts()\n let ans = ''\n let ax = ''\n for(let i = 0, j = 97; i < a; i++) {\n ax += String.fromCharCode(j)\n j++\n if(j - 96 > b) j = 97\n if(j > 121) j = 97\n }\n // wr(ax)\n ans = ans.padEnd(n, ax)\n wr(ans)\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, a, b] = d.split(' ').map(Number);\n let ans = '';\n\n for (let i = 0; i < n; i++) {\n ans += String.fromCharCode( (i % 26) % b + 97 );\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n var a = input1[0]\n var b = input1[1]\n var c = input1[2]\n var str=\"\"\n for(var i=0; i= badges[i+1]) {\n ++numChanges;\n ++badges[i+1];\n }\n }\n return numChanges;\n\n}\n\nprint(main());", "positive_code": [{"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,i){return i?gcd(i,t%i):t},Math.lcm=function(t,i){return t/gcd(t,i)*i},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,i){return(+t>+i)-(+i>+t)},Math.icmp=function(t,i){return(+i>+t)-(+t>+i)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]};\n\nvar cnt = new Array(10000);\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var t;\n for(var i = 0; i < 10000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n t = +cin.next();\n cnt[t]++; \n }\n var ans = 0;\n for(var i = 1; i <= n; ++i)\n {\n while(cnt[i] > 1)\n {\n var j;\n for(j = i + 1; cnt[j]; ++j);\n --cnt[i];\n ++cnt[j];\n ans += j - i;\n }\n }\n cout.print(ans);\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "/**\n * Created by Det on 25.05.2015.\n */\n(function main() {\n var line1 = readline().split(' ');\n var line2 = readline().split(' ');\n var money = 0;\n var sold = [];\n var lish = [];\n\n for (var i=0; i < line2.length; i++){\n if (sold[line2[i]]) {\n lish.push(sold[line2[i]]);\n } else {\n sold[line2[i]] = line2[i];\n }\n }\n for (var i=0; i < lish.length; i++) {\n for (var j=+lish[i]; j < (sold.length + lish.length); j++) {\n if(!sold[j]){\n sold[j] = 1;\n money += j - lish[i];\n break;\n }\n }\n }\n\n print(money);\n})();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp ;\n res = 0 ;\n this.arr = this.arr.sort( function( left , right ) { return left - right ; } ) ;\n prev = -1 ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( this.arr[ i ] <= prev ) {\n \t\tres += prev + 1 - this.arr[ i ] ;\n \t\tprev = prev + 1 ;\n \t}\n \telse {\n \t\tprev = this.arr[ i ] ;\n \t}\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\toutput[+input[i]]++;\n\t}\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar signs = {}, cnt = 0, x = 0;\n\nfor(i = 1; i <= n*2; i++){\n\tsigns[i] = 0;\n}\n\ncountUniqueElements(a,signs);\n\nfor(i = 1; i <= n; i++){\n\tif(signs[i] > 1){\n\t\tfor(j = i; j <= n*2; j++){\n\t\t\tif(signs[j] == 0){\n\t\t\t\tsigns[i]--;\n\t\t\t\tsigns[j]++;\n\t\t\t\tcnt += j - i;\n\t\t\t}\n\t\t\tif(signs[i] == 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nwrite(cnt);"}], "negative_code": [{"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\toutput[+input[i]]++;\n\t}\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar signs = {}, cnt = 0;\n\nfor(i = 1; i <= n; i++){\n\tsigns[i] = 0;\n}\n\ncountUniqueElements(a,signs);\n\nfor(sign in signs){\n\tif(signs[sign] == 0){\n\t\tcnt++;\n\t}\n}\n\nwrite(cnt);"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\toutput[+input[i]]++;\n\t}\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar signs = {}, cnt = 0;\n\nfor(i = 1; i <= n; i++){\n\tsigns[i] = 0;\n}\n\ncountUniqueElements(a,signs);\n\nfor(i = 1; i <= n; i++){\n\tif(signs[i] > 1){\n\t\tfor(j = signs[i]; j <= n; j++){\n\t\t\tif(signs[j] == 0){\n\t\t\t\tsigns[i]--;\n\t\t\t\tsigns[j]++;\n\t\t\t\tcnt += j - i;\n\t\t\t}\n\t\t}\n\t}\n}\n\nwrite(cnt);"}, {"source_code": "function main() {\n var numBadges = parseInt(readline());\n\n var badges = readline().split(\" \");\n badges.map(parseInt);\n\n badges.sort();\n var numChanges = 0;\n for(var i = 0; i < badges.length-1; i++) {\n if(badges[i] == badges[i+1]) {\n ++numChanges;\n ++badges[i+1];\n }\n }\n return numChanges;\n\n}\n\nprint(main());"}, {"source_code": "function main() {\n var numBadges = parseInt(readline());\n\n var badges = readline().split(\" \");\n badges.map(parseInt);\n\n badges.sort(function(a, b) {\n return a - b;\n });\n var numChanges = 0;\n for(var i = 0; i < badges.length-1; i++) {\n if(badges[i] == badges[i+1]) {\n ++numChanges;\n ++badges[i+1];\n }\n }\n return numChanges;\n\n}\n\nprint(main());"}, {"source_code": "function main() {\n var numBadges = parseInt(readline());\n\n var badges = readline().split(\" \");\n badges.map(parseInt);\n\n badges.sort(function(a, b) {\n return a - b;\n });\n //print(badges);\n var numChanges = 0;\n for(var i = 0; i < badges.length-1; i++) {\n while(badges[i] >= badges[i+1]) {\n ++numChanges;\n ++badges[i+1];\n }\n }\n return numChanges;\n\n}\n\nprint(main());"}], "src_uid": "53ae714f04fd29721b8bbf77576b7ccf"} {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n\n function* genMain() {\n let n = yield;\n if (n == 1) {\n console.log('! 1');\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n console.log('?', i, j);\n let mij = yield;\n console.log('?', j, i);\n let mji = yield;\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n console.log('!', a.slice(1).join(' '));\n process.exit();\n }\n let main = genMain();\n main.next();\n process.stdin.on('data', c => main.next(+c));\n\n})();\n\n", "positive_code": [{"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n\n let inputResolve;\n let inputNext = i => new Promise(resolve => inputResolve = resolve);\n process.stdin.on('data', c => inputResolve(+c));\n let n = await inputNext();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n // setTimeout(() => {\n // process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\\n`);\n // process.exit();\n // }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await inputNext()\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await inputNext()\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}, {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n\n let inputResolve;\n let inputNext = i => new Promise(resolve => inputResolve = resolve);\n process.stdin.on('data', c => inputResolve(+c));\n let n = await inputNext();\n if (n == 1) {\n console.log('! 1');\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n // setTimeout(() => {\n // process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\\n`);\n // process.exit();\n // }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n console.log('?', i, j);\n let mij = await inputNext()\n console.log('?', j, i);\n let mji = await inputNext()\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n console.log('!', a.slice(1).join(' '));\n process.exit();\n})();\n\n"}], "negative_code": [{"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));\n let n = await next();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n setTimeout(() => {\n process.stdout.write(`! ${a.filter(v => v).length}\\n`);\n process.exit();\n }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await next();\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await next();\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}, {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));\n let n = await next();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n setTimeout(() => {\n process.stdout.write(`! ${Arr(n, 1, 0, i => i).join(' ')}\\n`);\n process.exit();\n }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await next();\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await next();\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}, {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));\n let n = await next();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n setTimeout(() => {\n process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\\n`);\n process.exit();\n }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await next();\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await next();\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}, {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));\n let n = await next();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n setTimeout(() => {\n process.stdout.write(`! ${a.filter(v => v).length} ${a.slice(1).join(' ')}\\n`);\n process.exit();\n }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await next();\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await next();\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}, {"source_code": "// let input = '';\n// let inputResolve;\n// let inputPromise = new Promise(resolve => inputResolve = resolve);\n// process.stdin.on('data', c => input += c);\n// process.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n // await inputPromise;\n // let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n // out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));\n let n = await next();\n if (n == 1) {\n process.stdout.write(`! 1\\n`);\n process.exit();\n }\n let a = Array(n + 1);\n let i = 1;\n let j = 2;\n setTimeout(() => {\n process.stdout.write(`! ${Arr(n, 1, -1, i => i).join(' ')}\\n`);\n process.exit();\n }, 800);\n while (1) {\n while (i <= n && a[i] || i == j) i++;\n while (j <= n && a[j] || i == j) j++;\n if (i > n || j > n) break;\n process.stdout.write(`? ${i} ${j}\\n`);\n let mij = await next();\n process.stdout.write(`? ${j} ${i}\\n`);\n let mji = await next();\n if (mij > mji) a[i++] = mij;\n else a[j++] = mji;\n }\n For(1, n, 1, i => a[i] ? null : a[i] = n);\n process.stdout.write(`! ${a.slice(1).join(' ')}\\n`);\n process.exit();\n})();\n\n"}], "src_uid": "9bfbd68e61f4d2f3d404fd0413aded35"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m, k, q] = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, m, k, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, k, qs) {\n const rows = {}\n const cols = {}\n let cr = 0\n let cc = 0\n let count = 0\n for (let i = qs.length - 1; i >= 0; i--) {\n let [x, y] = qs[i]\n x--; y--\n //\n let ok = 0\n if (!rows[x] && cc < m) {\n ok = 1\n }\n if (!cols[y] && cr < n) {\n ok = 1\n }\n if (ok) count++\n // if (n > 1 && m > 1) {\n // } else if (n > 1) {\n // if (!rows[x] && cc < m) {\n // count++\n // }\n // // } else if (m > 1) {\n // } else {\n // if (!cols[y] && cr < n) {\n // count++\n // }\n // }\n //\n if (!rows[x]) {\n rows[x] = 1\n cr++\n }\n if (!cols[y]) {\n cols[y] = 1\n cc++\n }\n // console.log(cr, cc)\n }\n return pow(k, count)\n}\n\nconst MOD = 998244353\nconst MOD_CUT = ((1 << 20) * (1 << 20)) % MOD\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction minus(a, b) {\n return add(add(a, -b), MOD)\n}\nfunction mul(a, b) {\n let r = (a >> 20) * (b >> 20) * MOD_CUT\n + (a & 0xfff00000) * (b & 0xfffff)\n + (a & 0xfffff) * b\n return r % MOD\n}\nfunction pow(a, b) {\n let r = 1\n let base = a\n while (b) {\n if (b & 1) {\n r = mul(r, base)\n }\n b >>= 1\n base = mul(base, base)\n }\n return r\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n let [n, m, k, q] = a;\r\n let visr = new Set(),\r\n visc = new Set(),\r\n res = 1,\r\n vx = new Set(),\r\n vy = new Set(),\r\n sx = 0,\r\n sy = 0;\r\n for (let i = q - 1; i >= 0; i--) {\r\n let [x, y] = b[i];\r\n x--, y--;\r\n if (!visr.has(x) && sx < m || !visc.has(y) && sy < n) {\r\n res = mul(res, k);\r\n }\r\n if (sx === m && sy === n) break;\r\n if (!visr.has(x)) visr.add(x);\r\n if (!visc.has(y)) visc.add(y);\r\n if (!vx.has(y)) {\r\n vx.add(y);\r\n sx++;\r\n }\r\n if (!vy.has(x)) {\r\n vy.add(x);\r\n sy++;\r\n }\r\n }\r\n return res;\r\n}\r\nconst MOD = 998244353;\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = a[3];\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n let [n, m, k, q] = a;\r\n let visr = new Set(),\r\n visc = new Set(),\r\n res = 0,\r\n vx = new Set(),\r\n vy = new Set(),\r\n sx = 0,\r\n sy = 0;\r\n for (let i = q - 1; i >= 0; i--) {\r\n let [x, y] = b[i];\r\n x--, y--;\r\n if (!visr.has(x) && sx < m || !visc.has(y) && sy < n) {\r\n res++;\r\n }\r\n if (sx === m && sy === n) break;\r\n if (!visr.has(x)) visr.add(x);\r\n if (!visc.has(y)) visc.add(y);\r\n if (!vx.has(y)) {\r\n vx.add(y);\r\n sx++;\r\n }\r\n if (!vy.has(x)) {\r\n vy.add(x);\r\n sy++;\r\n }\r\n }\r\n return power(k, res);\r\n}\r\nconst MOD = 998244353;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = a[3];\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n let [n, m, k, q] = a;\r\n b = b.map(arr => arr.map(num => num - 1));\r\n let visr = new Array(n),\r\n visc = new Array(n),\r\n res = 1,\r\n v1 = new Array(n),\r\n v2 = new Array(n),\r\n sum1 = 0,\r\n sum2 = 0;\r\n for (let i = q - 1; i >= 0; i--) {\r\n const [x, y] = b[i];\r\n if (!visr[x] && sum1 < n || !visc[y] && sum2 < m) {\r\n res = mul(res, k);\r\n }\r\n visr[x] = 1;\r\n visc[y] = 1;\r\n if (!v1[y]) {\r\n v1[y] = 1;\r\n sum1++;\r\n }\r\n if (!v2[x]) {\r\n v2[x] = 1;\r\n sum2++;\r\n }\r\n }\r\n return res;\r\n}\r\nconst MOD = 998244353;\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = a[3];\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "623a373709e4c4223fbbb9a320f307b1"} {"source_code": "function PrintArray(arr)\r\n{\r\n var str = ''\r\n for(var k=0;k {\r\n input += c;\r\n});\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const cases = parseInt(lines[0]);\r\n \r\n let on = true;\r\n for (let i = 1; i < cases * 3; i++) {\r\n const line = lines[i];\r\n // console.log(line);\r\n if (!line) {\r\n return;\r\n }\r\n if (on) {\r\n } else {\r\n const arr = lines[i].split(' ').map(t => t.trim());\r\n let t;\r\n //console.log(arr);\r\n const index = arr.findIndex((item, index) => {\r\n //console.log('t' + t + item);\r\n if (index === 0 && arr[index + 1] !== item && arr[index + 2] !== item) {\r\n return true;\r\n }\r\n if (t === undefined) {\r\n t = item;\r\n return false;\r\n }\r\n \r\n if (item !== t) {\r\n return true;\r\n }\r\n });\r\n \r\n \r\n console.log((index + 1));\r\n }\r\n \r\n on = !on;\r\n }\r\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var a=readline();\r\nwhile(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n\r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0])+1)\r\n}\r\n}\r\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let arr = readline().split(' ').map( Number )\r\n console.log( solve(arr) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (arr) => { \r\n let min = minOfArray( arr ) \r\n let max = maxOfArray( arr ) \r\n let minArr = arr.filter( a => a === min )\r\n\r\n spy = ( minArr.length === 1 ) ? min : max\r\n\r\n for( a in arr ) {\r\n if( arr[a] === spy ) return parseInt( a ) + 1\r\n }\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n for(j = 0; j < e; j++){\n var l = j - 1;\n var r = j + 1;\n l = l == -1 ? k.length - 1 : l;\n r = r == k.length ? 0 : r;\n if(k[l] != k[j] && k[j] != k[r]){\n console.log(j + 1);\n break;\n }\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0];\n var answer = 0;\n for(var j = 1; j <= n * 2; j += 2){\n var num = lines[j + 1].split(' ');\n for(var k = 0; k < num.length; k++){\n var left = k - 1;\n var right = k + 1;\n if(left == -1){\n left = num.length -1;\n } \n if(right == num.length){ \n right = 0;\n }\n if(num[k] != num[left] && num[k] != num[right]){\n console.log(k + 1);\n }\n }\n \n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\nlet max = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let = i = 0;\n\n let x = readline();\n max = x;\n\n for (let i = 0; i < max * 2; i++) {\n let y = readline();\n if (i % 2 === 1) {\n execute(y.split(\" \"));\n }\n }\n}\n\nfunction execute(x) {\n // without auto '\\n' (newline)\n // process.stdout.write(\"\");\n // with auto '\\n' (newline)\n // console.log(x);\n\n let data = {};\n let spy = null;\n\n if (x.length !== 1) {\n for (let i = 0; i < x.length; i++) {\n if (!data.hasOwnProperty(x[i])) {\n data[`${x[i]}`] = 1;\n } else {\n data[`${x[i]}`] += 1;\n }\n }\n\n for (const el in data) {\n if (data[el] === 1) {\n spy = el;\n }\n }\n\n for (let i = 0; i < x.length; i++) {\n if (x[i] === spy) {\n console.log(i + 1);\n }\n }\n }\n}\n"}, {"source_code": "function processInput(input) {\r\n let opt = {};\r\n let [first, ...second] = [...input.split(\"\\n\")];\r\n opt.n = parseInt(first);\r\n for(var i = 0; i < second.length; i++) {\r\n second[i] = second[i].split(\" \").map(val => parseInt(val));\r\n }\r\n opt.testcases = second;\r\n // console.log(opt);\r\n return opt;\r\n }\r\n \r\n function iterateTC(TC) {\r\n var size = TC.n, arr = TC.testcases, k;\r\n for(var i = 1; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n let guess = arr[0];\n\n if (guess === arr[1]) {\n let inc = 1;\n while (guess === arr[inc]) {\n inc++;\n }\n\n console.log(inc + 1);\n } else {\n if (guess === arr[2]) {\n console.log(2);\n } else {\n console.log(1);\n }\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 2; i < input.length; i+=2) {\r\n let nums = input[i].split(' ');\r\n for (let j = 0; j < nums.length; j++) {\r\n if (nums.indexOf(nums[j]) === nums.lastIndexOf(nums[j])) {\r\n ans.push(j+1);\r\n break;\r\n }\r\n }\r\n }\r\n console.log(ans.join('\\n'))\r\n});"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n \r\n const lines = i.split(EOL)\r\n const NoL = lines[0]*2\r\n \r\n let LoA = false\r\n let crewmate = 0\r\n \r\n let n = 1\r\n while(NoL >= n){\r\n if(!LoA){\r\n LoA = lines[n]\r\n \r\n }else{\r\n let number = lines[n].split(\" \")\r\n \r\n if(number[0] == number[1]){\r\n crewmate = number[0]\r\n \r\n }else if(number[0] == number[2]){\r\n crewmate = number[0]\r\n }else{\r\n crewmate = number[1]\r\n }\r\n \r\n \r\n let a = 0\r\n while(LoA > a){\r\n if(number[a] != crewmate){\r\n console.log(number.indexOf(number[a])+1)\r\n break;\r\n }\r\n a++\r\n }\r\n \r\n LoA = false\r\n }\r\n n++ \r\n }\r\n})\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction solve() {\r\n let n = nextInt();\r\n const cnt = af(101).fill(0);\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n cnt[a[i]]++;\r\n }\r\n for (let i = 1; i <= 100; i++) {\r\n if (cnt[i] == 1) {\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] == i) {\r\n return j + 1;\r\n }\r\n }\r\n }\r\n }\r\n return INIT;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nconst getSpyIndex = (arrNum) => {\r\n let index;\r\n // console.log(\"input string\", arrNum);\r\n\r\n arrNum.forEach((x, i) => {\r\n if (i > 1) {\r\n if (arrNum[0] !== x) {\r\n if (arrNum[1] === x) {\r\n index = 0;\r\n } else {\r\n index = i;\r\n }\r\n } else if (i === 2) {\r\n index = 1;\r\n }\r\n }\r\n });\r\n\r\n console.log(index + 1);\r\n};\r\n\r\nfunction main() {\r\n const numberOfTestCases = 1 * readline();\r\n // console.log(\"number of test cases\", numberOfTestCases);\r\n Array.from({ length: numberOfTestCases }).forEach(() => {\r\n const arrayLength = 1 * readline();\r\n const arrayString = readline();\r\n const arr = arrayString.split(\" \");\r\n const arrNum = arr.map((x) => x * 1);\r\n\r\n getSpyIndex(arrNum);\r\n });\r\n}\r\n"}, {"source_code": "/**\r\n * Bismillahir Rahmanir Rahim\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n */\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n \r\n let inputString = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\tlet s = readLine().split(\" \").map(item=>parseInt(item));\r\n\t\tconsole.log(solve(n,s)+1);\r\n\t\t\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n, s) {\r\n\tfor (let i = 0; i < n-2; i++) {\r\n\t\tif (s[i] == s[i+1] && s[i] == s[i+2]) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (s[i] == s[i+1]) return i+2;\r\n\t\tif (s[i] == s[i+2]) return i+1;\r\n\t\tif (s[i+1] == s[i+2]) return i;\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet s = nl.nums();\n\t\tlet a = s[0];\n\t\tlet b = s[1];\n\t\tlet c = s[2];\n\t\tlet x = 0;\n\t\tif (a == b) {\n\t\t\tx = a;\n\t\t} else if (b == c) {\n\t\t\tx = b;\n\t\t} else {\n\t\t\tx = a;\n\t\t}\n\t\t\n\t\tlet y = 0;\n\t\ts.forEach((e, i) => {\n\t\t\tif (e != x) {\n\t\t\t\ty = i + 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t});\n\t\tans.push(y);\n }\n \n\tconsole.log(ans.join(\"\\n\"));\n \n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "input()\r\n//-------------------\r\n\r\nfunction input () {\r\n let i = ''\r\n process.stdin.on('data', c => i += c)\r\n process.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines);\r\n solve(lines)\r\n })\r\n\r\n}\r\n\r\nfunction solve (arr) {\r\n var d =+arr[0]\r\n for (var i =1 ;i <=d ;i++){\r\n var mas =arr[2*i].split(\" \")\r\n var mno =new Set(mas)\r\n \r\n for (var e of mno){\r\n var k =mas.indexOf(e)\r\n var kk =mas.lastIndexOf(e)\r\n if (k == kk){\r\n console.log(k+1)\r\n break\r\n \r\n }\r\n }\r\n \r\n }\r\n \r\n \r\n\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\n\r\nprocess.stdin.on(\"end\", a => {\r\n\tinputString = inputString.trim().split(\"\\n\").map(str => str.trim());\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\tlet t = parseInt(readLine().split(\" \")[0]);\r\n\t\r\n\twhile(t-->0) {\t\r\n\t\tlet n = parseInt(readLine().split(\" \")[0]);\r\n\t\t\r\n\t\tlet arr = new Array(n);\r\n\t\tlet num = readLine().split(\" \");\r\n\t\tfor(let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = readline();\n while(t--)\n {\n let num_of_elements = readline(); \n let elements = readline();\n elements = elements.split(' ')\n let prev_occ = elements[0];\n for(let i=1;i {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n let n = parseInt(readLine());\r\n let arr = get_ints();\r\n let my_map = new Map();\r\n for(let i = 0 ; i < n ; i++)\r\n my_map.get(arr[i]) ? my_map.set(arr[i], my_map.get(arr[i]) + 1) : my_map.set(arr[i], 1)\r\n let ans;\r\n for([key,value] of my_map){\r\n if(value === 1) ans = key;\r\n }\r\n for(let i = 0; i < n; i++){\r\n if(arr[i] === ans){\r\n console.log(i + 1);\r\n break;\r\n }\r\n }\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\nfunction isEqual(arr){\r\n let flag = true;\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] !== arr[i + 1]){\r\n flag = false;\r\n break;\r\n }\r\n }\r\n return flag;\r\n}\r\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1512/A\n\nprocess.stdin.setEncoding('utf-8')\nconst readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n }\n)\n\nlet count = -1\nlet inputArr = []\n\nrl.on('line', data => {\n if (count === -1) {\n count = +data * 2\n } else if (count !== 0) {\n inputArr.push(data.trim())\n count--;\n }\n\n if (count === 0) {\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\n\n for (let i = 0; i < inputArr.length; i += 2) {\n solution(inputArr[i], inputArr[i + 1])\n }\n\n process.exit(0)\n }\n})\n\n/**\nTEST CASES\n4\n4\n11 13 11 11\n5\n1 4 4 4 4\n10\n3 3 3 3 10 3 3 3 3 3\n3\n20 20 10\n */\nconst solution = (n, arr) => {\n const key0 = arr[0];\n const key1 = arr[1];\n const key2 = arr[2];\n\n if (key0 === key1 && key0 !== key2) {\n console.log(3);\n return;\n } else if (key0 === key2 && key0 !== key1) {\n console.log(2);\n return;\n } else if (key1 === key2 && key0 !== key1) {\n console.log(1);\n return;\n }\n\n let result = 1;\n\n for (let i=1; i {\r\n return parseInt(__lineDB[__lineIdx++], 10);\r\n },\r\n readLine: () => {\r\n return __lineDB[__lineIdx++];\r\n }\r\n};\r\nlet __lineDB = [];\r\nlet __lineIdx = 0;\r\nconst isDebug = process.argv[2] === 'readizDebug';\r\nif (!isDebug) {\r\n global.console = {\r\n log: () => {},\r\n warn: () => {},\r\n info: () => {},\r\n debug: () => {},\r\n error: () => {}\r\n };\r\n const rl = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n __lineDB.push(line);\r\n });\r\n rl.on('close', () => {\r\n process.stdout.write(solution(scanner) + '\\n');\r\n });\r\n} else {\r\n __lineDB = require('fs').readFileSync(process.argv[1].replace('.js', '_input.txt')).toString().split('\\n');\r\n while (__lineIdx < __lineDB.length) {\r\n process.stdout.write('--------------------------------------------\\n');\r\n process.stdout.write('New Start + Log\\n');\r\n process.stdout.write('--------------------------------------------\\n');\r\n const start = __lineIdx;\r\n const answer = solution(scanner);\r\n const end = __lineIdx;\r\n process.stdout.write('----------------------\\n');\r\n process.stdout.write('Input\\n')\r\n process.stdout.write('----------------------\\n');\r\n process.stdout.write(__lineDB.slice(start, end).join('\\n') + '\\n');\r\n process.stdout.write('----------------------\\n');\r\n process.stdout.write('Answer\\n')\r\n process.stdout.write('----------------------\\n');\r\n process.stdout.write(answer + '\\n');\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar map = {};\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(map[list[j]] == null){\r\n\t\t\t\tmap[list[j]] = 0;\r\n\t\t\t}\r\n\t\t\tmap[list[j]]++;\r\n\t\t}\r\n\t\tvar key = Object.keys(map);\r\n\t\tvar min;\r\n\t\tmyerr(map);\r\n\t\tif(map[key[0]] < map[key[1]]){\r\n\t\t\tmin = key[0];\r\n\t\t}else{\r\n\t\t\tmin = key[1];\r\n\t\t}\r\n\t\tmyerr(min);\r\n\t\tmyout(list.indexOf(min) + 1);\r\n\t}\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let m = new Map();\r\n for (const e of a) m.set(e, m.get(e) + 1 || 1);\r\n for (let i = 0; i < n; i++) {\r\n if (m.get(a[i]) == 1) return pr(i + 1);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n const res = arr.filter((el, i, arr) => arr.indexOf(el) === arr.lastIndexOf(el))\r\n console.log(arr.indexOf(res[0]) + 1)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n const n = parseInt(readline());\r\n // var [n, p, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var min = 0\r\n var object = {}\r\n for (let j = 0; j < n; j++) {\r\n if (!object[a[j]]) object[a[j]] = 0\r\n object[a[j]]++\r\n }\r\n for (let j = 0; j < n; j++) {\r\n if (object[a[j]] === 1) return console.log(j + 1)\r\n }\r\n\r\n })\r\n}\r\n"}, {"source_code": "var cases = parseInt(readline());\r\nvar t;\r\nfor(t=0; t parseInt(e));;\r\n var indexSpy = 0;\r\n var occorences = {};\r\n\r\n // count all occorence of two number in the array\r\n array.forEach( (e) => {\r\n occorences[e] = occorences[e] ? (occorences[e] += 1) : 1;\r\n });\r\n\r\n // find number with one occorence\r\n if( occorences[ Object.keys(occorences)[0] ] == 1){\r\n indexSpy = Object.keys(occorences)[0];\r\n } else {\r\n indexSpy = Object.keys(occorences)[1];\r\n }\r\n\r\n // print output\r\n print( array.indexOf( parseInt(indexSpy) ) + 1 );\r\n\r\n}\r\n"}, {"source_code": "// 1512 A - Spy detected!\r\n\r\n// number of test case\r\nvar numTests = parseInt( readline() );\r\n\r\nfor (var numTest = 0; numTest < numTests; numTest++) {\r\n \r\n // input data \r\n var n = parseInt( readline() );\r\n var array = readline().split(' ').map( e => parseInt(e));;\r\n var indexSpy = 0;\r\n var occorences = {};\r\n\r\n array.forEach( (e) => {\r\n occorences[e] = occorences[e] ? (occorences[e] += 1) : 1;\r\n });\r\n \r\n // print(JSON.stringify(occorences));\r\n\r\n if( occorences[ Object.keys(occorences)[0] ] == 1){\r\n indexSpy = Object.keys(occorences)[0];\r\n } else {\r\n indexSpy = Object.keys(occorences)[1];\r\n }\r\n \r\n // print('spy: '+indexSpy);\r\n indexSpy = array.indexOf( parseInt(indexSpy) ) + 1 ;\r\n // print('index: '+indexSpy+'\\n');\r\n \r\n print(indexSpy);\r\n \r\n}"}, {"source_code": "var testCases = readline();\r\nvar count;\r\nvar resultObj;\r\nvar result;\r\nvar length0;\r\nfor (var i = 0; i < testCases; i++) {\r\n resultObj = {};\r\n length0= readline();\r\n var arr = readline().split(' ');\r\n for (var val of arr) { \r\n if(!resultObj[val]) resultObj[val] = 1;\r\n else resultObj[val]++;\r\n }\r\n for (var key in resultObj) {\r\n if(resultObj[key] == 1) result = key;\r\n }\r\n print(arr.indexOf(result) + 1);\r\n}"}, {"source_code": "function solution() {\r\n var t = parseInt(readline());\r\n for (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n var nonSpy = a[0] === a[1] ? a[0] : a[2];\r\n for (var j = 0; j < n; j++) {\r\n if (a[j] !== nonSpy) {\r\n print(j+1);\r\n }\r\n }\r\n }\r\n}\r\n\r\nsolution();"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n a = readline().split(' ');\r\n valuesArray = [...new Set(a)],\r\n unexceptedValue = valuesArray[0] , counter = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n if(parseInt(valuesArray[0]) == parseInt(a[j]) ){\r\n counter++;\r\n if(counter > 1){\r\n unexceptedValue = valuesArray[1];\r\n break;\r\n }\r\n }\r\n }\r\n print(parseInt(a.indexOf(unexceptedValue)) + 1);\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n\r\n if (arr[0] !== arr[1]) {\r\n if (arr[2] === arr[0]) {\r\n print(2);\r\n } else {\r\n print(1);\r\n }\r\n } else {\r\n for (var j = 2; j < n; j++) {\r\n if (arr[j] !== arr[0]) {\r\n print(j + 1);\r\n break;\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "var numberOfTests =+(readline()),counter=0\r\nfor(var i=0;i+node)\r\n for(var j=0;j{\r\n return Math.min(a,b)\r\n })\r\n \r\n print(a.indexOf(min)+1)\r\n}"}, {"source_code": " var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var hash = {};\r\n for (var i = 0; i < n; i++) {\r\n if (hash.hasOwnProperty(inp[i])) {\r\n hash[inp[i]]++;\r\n } else {\r\n hash[inp[i]] = 1;\r\n }\r\n }\r\n\r\n var ind = 0;\r\n for (var i in hash) {\r\n if (hash[i] === 1) {\r\n ind = i;\r\n }\r\n }\r\n return inp.indexOf(+ind) + 1;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var test = parseInt(readline());\r\nvar inte = 0;\r\n\r\nfor(var i = 0; i < test; i++) {\r\n var foo = parseInt(readline());\r\n var bar = readline();\r\n var barSplited = bar.split(\" \");\r\n for(var j = 0; j < barSplited.length; j++) {\r\n var counter = 0\r\n for(var k = 0; k < barSplited.length; k++) {\r\n if(barSplited[j] == barSplited[k] && j != k) {\r\n counter++\r\n }\r\n }\r\n if(counter == 0) {\r\n inte = j + 1;\r\n }\r\n }\r\n print(inte)\r\n}\r\n\r\n"}, {"source_code": "var tests = Number(readline());\r\n\r\n\r\nfor (var i = 0; i < tests; i++) {\r\n var len = Number(readline());\r\n var n = readline().split(\" \");\r\n var index = 0;\r\n var check = 0;\r\n var is_first = false;\r\n \r\n for (var j = 0; j < len; j++) {\r\n var temp = n[j];\r\n \r\n if (j == 0 && n[j] != n[j+1]) {\r\n if (n[j + 1] == n[j + 2])\r\n is_first = true; \r\n }\r\n \r\n if (temp != n[j + 1])\r\n check++;\r\n\r\n if (check == 2) {\r\n index = j;\r\n break;\r\n }\r\n \r\n \r\n }\r\n \r\n \r\n is_first ? print(1) : print(index + 1);\r\n}"}, {"source_code": "var t=Number(readline());\r\nfor (var i=0; i c[x] != -1)])\r\n \r\n}"}, {"source_code": " 'use strict';\r\n\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n\r\n let inputString = '';\r\n let currentLine = 0;\r\n\r\n process.stdin.on('data', inputStdin => {\r\n \tinputString += inputStdin;\r\n });\r\n\r\n process.stdin.on('end', _ => {\r\n \tinputString = inputString.trim().split('\\n').map(string => {\r\n \t\treturn string.trim();\r\n \t});\r\n\r\n \tmain(); \r\n });\r\n\r\n function readline() {\r\n \treturn inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n\t\t///problem specific code start\r\nlet tc = readline();\r\nwhile(tc--)\r\n{\r\n\tlet arraySize = readline();\r\n\tconst array = readline().split(' ');\r\n const obj = {};\r\n for (let value of array)\r\n {\r\n \tif(value in obj)\r\n \t{\r\n obj[value]++;\r\n \t}\r\n \telse \r\n \t\tobj[value]=1;\r\n }\r\n for(let key in obj)\r\n {\r\n \tif(obj[key]==1)\r\n \t\tconsole.log(array.indexOf(key)+1);\r\n }\r\n\r\n\r\n \t\r\n\r\n} //problem specific code end\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": " 'use strict';\r\n\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n\r\n let inputString = '';\r\n let currentLine = 0;\r\n\r\n process.stdin.on('data', inputStdin => {\r\n \tinputString += inputStdin;\r\n });\r\n\r\n process.stdin.on('end', _ => {\r\n \tinputString = inputString.trim().split('\\n').map(string => {\r\n \t\treturn string.trim();\r\n \t});\r\n\r\n \tmain(); \r\n });\r\n\r\n function readline() {\r\n \treturn inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n \t///problem specific code start\r\n /*\r\n \tvar tc=readline();\r\n \twhile(tc--)\r\n \t{\r\n \t\tlet size=readline();\r\n \t\tconst numbers=readline().split(' ');\r\n \t\tfor(let i=0;i {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n function main() {\r\n \r\n var tc=readline();\r\nwhile(tc--)\r\n{\r\n\tlet size=readline();\r\n\tconst numbers=readline().split(' ');\r\n\tfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const useCases = readline();\r\n\r\n for (let i = 0; i < useCases; i++) {\r\n const arrayLength = readline();\r\n const arrayContent = readline().split(' ');\r\n const arrayContentSorted = arrayContent.slice().sort((a,b) => a - b);\r\n let unique = 0;\r\n\r\n if (arrayContentSorted[0] === arrayContentSorted[1]) {\r\n unique = arrayContentSorted[arrayLength - 1];\r\n } else {\r\n unique = arrayContentSorted[0];\r\n }\r\n\r\n const uniqueIndex = arrayContent.indexOf(unique);\r\n\r\n print(uniqueIndex + 1);\r\n }\r\n}\r\n\r\nfunction print(x) {\r\n // process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \n// ********** Code Start **********\n\nfunction main() {\n const t = parseInt(readline())\n const results = []\n const arrayInputs = []\n for(let i =0; i {\n if(arr[0] != arr[1]) {\n if(arr[1] == arr[2]) {\n results.push(1)\n }else {\n results.push(2)\n }\n }else {\n let cont = true\n i=2;\n while(cont && i {\n check(arrayInput)\n })\n\n results.forEach(result => console.log(result))\n}\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nconst getSpyIndex = (arrNum) => {\n // console.log(\"input string\", arrNum);\n\n if (arrNum[0] === arrNum[2] && arrNum[1] !== arrNum[2]) {\n return 1;\n }\n for (let i = 2; i < arrNum.length; i++) {\n if (arrNum[0] !== arrNum[i]) {\n if (arrNum[1] === arrNum[i]) {\n return 0;\n } else {\n return i;\n }\n }\n }\n};\n\nfunction main() {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const arrayLength = 1 * readline();\n const arrayString = readline();\n const arr = arrayString.split(\" \");\n const arrNum = arr.map((x) => +x);\n\n console.log(getSpyIndex(arrNum) + 1);\n });\n}\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nconst getSpyIndex = (arrNum) => {\n let index;\n // console.log(\"input string\", arrNum);\n\n arrNum.forEach((x, i) => {\n if (i > 1) {\n if (arrNum[0] !== x) {\n if (arrNum[1] === x) {\n index = 0;\n } else {\n index = i;\n }\n } else if (i === 2) {\n index = 1;\n }\n }\n });\n\n console.log(index + 1);\n};\n\nfunction main() {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const arrayLength = 1 * readline();\n const arrayString = readline();\n const arr = arrayString.split(\" \");\n const arrNum = arr.map((x) => x * 1);\n\n getSpyIndex(arrNum);\n });\n}\n// const arrString = \"3 3 3 3 10 3 3 3 3 3\";\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline().split(' ');\r\n let key = {};\r\n for (let i = 0; i < len; i++) {\r\n if (key[arr[i]]) key[arr[i]].push(i + 1);\r\n else key[arr[i]] = [i + 1];\r\n }\r\n PrintMin(Object.values(key));\r\n }\r\n}\r\n\r\nfunction PrintMin(arr) {\r\n if (arr[0].length === 1) console.log(...arr[0]);\r\n else console.log(...arr[1]);\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0];\n var answer = 0;\n for(var j = 1; j <= n * 2; j += 2){\n var num = lines[j + 1].split(' ');\n for(var k = 0; k < num.length; k++){\n var left = k - 1;\n var right = k + 1;\n if(left == -1){\n left = num.length -1;\n } \n if(right == num.length){ \n right = 0;\n }\n if(num[k] != num[left] && num[k] != num[right]){\n console.log(k + 1);\n }\n }\n \n }\n});"}], "negative_code": [{"source_code": "var integer = readline();\r\nvar array = readline().split(\" \");\r\nvar i;\r\nvar k;\r\nvar counter=0;\r\nvar item;\r\nfor(i=0; i b?'0':'1'\r\n if(str[current] == '?')\r\n {\r\n if(str[inversed]!='?')\r\n {\r\n str[current] = str[inversed];\r\n if(str[inversed] == '0')\r\n {\r\n a = parseInt(a) - 1 \r\n }\r\n else\r\n {\r\n b = parseInt(b) - 1\r\n }\r\n }\r\n else\r\n {\r\n str[current] = next;\r\n str[inversed] = next;\r\n if(a>b)\r\n {\r\n a = parseInt(a) - 2 \r\n }\r\n else\r\n {\r\n b = parseInt(b) - 2\r\n }\r\n }\r\n }\r\n else if(str[current] == '0')\r\n {\r\n if(str[inversed] == '1')\r\n {\r\n return \"-1\";\r\n }\r\n else if(str[inversed] == '?')\r\n {\r\n str[inversed] = '0';\r\n a = parseInt(a) - 1; \r\n }\r\n }\r\n else if(str[current] == '1')\r\n {\r\n if(str[inversed] == '0')\r\n {\r\n return \"-1\";\r\n }\r\n else if(str[inversed] == '?')\r\n {\r\n str[inversed] = '1';\r\n b = parseInt(b) - 1; \r\n }\r\n }\r\n if(a<0 || b<0)\r\n {\r\n return \"-1\";\r\n }\r\n }\r\n\r\n return str.join(\"\");\r\n}\r\n\r\nvar arr = []\r\nvar t = readline();\r\n\r\nfor(var indT=0;indT {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start **********\r\n \r\n function main() {\r\n \t/*\r\n var a=readline();\r\n while(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n \r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0])+1)\r\n }\r\n */\r\n var tc=readline();\r\nwhile(tc--)\r\n{\r\n\tlet size=readline();\r\n\tconst numbers=readline().split(' ');\r\n\tfor(let i=0;i {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start **********\r\n \r\n function main() {\r\n \t/*\r\n var a=readline();\r\n while(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n \r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0])+1)\r\n }\r\n */\r\n var tc=readline();\r\nwhile(tc--)\r\n{\r\n\tlet size=readline();\r\n\tconst numbers=readline().split(' ');\r\n\tfor(let i=0;i {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start **********\r\n \r\n function main() {\r\n \t/*\r\n var a=readline();\r\n while(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n \r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0])+1)\r\n }\r\n */\r\n var tc=readline();\r\nwhile(tc--)\r\n{\r\n\tlet size=readline();\r\n\tconst numbers=readline().split(' ');\r\n\tfor(let i=0;i {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start **********\r\n \r\n function main() {\r\n \t/*\r\n var a=readline();\r\n while(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n \r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0])+1)\r\n }\r\n */\r\n var tc=readline();\r\nwhile(tc--)\r\n{\r\n\tlet size=readline();\r\n\tconst numbers=readline().split(' ');\r\n\tfor(let i=0;i a - b);\r\n let unique = 0;\r\n\r\n if (arrayContentSorted[0] === arrayContentSorted[1]) {\r\n unique = arrayContentSorted[arrayLength - 1];\r\n } else {\r\n unique = arrayContentSorted[0];\r\n }\r\n\r\n const uniqueIndex = arrayContent.indexOf(unique);\r\n\r\n print(uniqueIndex + 1);\r\n }\r\n}"}, {"source_code": "function main() {\r\n const useCases = readline();\r\n\r\n for (let i = 0; i < useCases; i++) {\r\n const arrayLength = readline();\r\n let unique = 0\r\n const arrayContent = readline().split(' ')\r\n const arrayContentSorted = arrayContent.slice().sort((a,b) => a - b);\r\n if (arrayContentSorted[0] === arrayContentSorted[1]) {\r\n unique = arrayContentSorted[arrayLength - 1]\r\n } else {\r\n unique = arrayContentSorted[0]\r\n }\r\n const uniqueIndex = arrayContent.indexOf(unique)\r\n console.log(uniqueIndex + 1)\r\n }\r\n}"}, {"source_code": "function main() {\r\n const useCases = readline();\r\n\r\n for (let i = 0; i < useCases; i++) {\r\n const arrayLength = readline();\r\n let unique = 0\r\n const arrayContent = readline().split(' ')\r\n const arrayContentSorted = arrayContent.slice().sort((a,b) => a - b);\r\n if (arrayContentSorted[0] === arrayContentSorted[1]) {\r\n unique = arrayContentSorted[arrayLength - 1]\r\n } else {\r\n unique = arrayContentSorted[0]\r\n }\r\n const uniqueIndex = arrayContent.indexOf(unique)\r\n print(uniqueIndex + 1)\r\n }\r\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nconst getSpyIndex = (arrNum) => {\n let index;\n // console.log(\"input string\", arrNum);\n\n for (let i = 2; i < arrNum.length; i++) {\n if (arrNum[0] !== arrNum[i]) {\n if (arrNum[1] === arrNum[i]) {\n index = 0;\n } else {\n index = i;\n }\n break;\n } else if (i === 2) {\n index = 1;\n break;\n }\n }\n\n console.log(index + 1);\n};\n\nfunction main() {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const arrayLength = 1 * readline();\n const arrayString = readline();\n const arr = arrayString.split(\" \");\n const arrNum = arr.map((x) => +x);\n\n getSpyIndex(arrNum);\n });\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline().split(' ').map(Number);\r\n let left = 0;\r\n let right = len - 1;\r\n for (let i = 0; i < len; i++) {\r\n if (arr[left] === arr[right]) {\r\n left++;\r\n right--;\r\n } else {\r\n if (arr[left] === arr[left + 1]) {\r\n console.log(right + 1);\r\n break;\r\n }\r\n console.log(left + 1);\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline().split(' ').map(Number);\r\n let left = 0;\r\n let right = len - 1;\r\n for (let i = 0; i < len; i++) {\r\n if (arr[left] === arr[right]) {\r\n left++;\r\n right--;\r\n } else {\r\n if (arr[left + 1] !== arr[right]) {\r\n console.log(right + 1);\r\n break;\r\n }\r\n console.log(left + 1);\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var number = lines[0].split(' ');\n var boyGirl = lines[1].split('');\n var answer = '';\n while(number[1]--){\n for(j = 1; j < number[0]; j++){\n if(boyGirl[j] == 'G' && boyGirl[j - 1] == 'B'){\n boyGirl[j] = 'B';\n boyGirl[j - 1] = 'G';\n j++;\n }\n }\n }\n answer = boyGirl.toString();\n answer.split(',');\n var a = '';\n for(k = 0; k < Number(number[0]) * 2 - 1;k++){\n if(k % 2 === 0){\n a += answer[k];\n }\n }\n console.log(a);\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(var j = 1; j <= lines[0] * 2; j += 2){\n var a = lines[j].split(' ');\n for(var k = 0; k <= a.length; k++){\n var l = k - 1;\n var r = k + 1;\n if(l == -1){\n l = a.length;\n } \n if(r == a.length){ \n r = 0;\n }\n if(a[k] != a[l] && a[k] != a[r]){\n console.log(k + 1);\n }\n }\n \n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var a=readline();\r\nwhile(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n \r\n var c=[];\r\n var ex;\r\n\r\n for(let i=0;i data != ex);\r\n console.log(s.indexOf(ans[0]))\r\n}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var a=readline();\r\nwhile(a--){\r\n var t=readline();\r\n var s=readline().split(\" \");\r\n var c=[];\r\n var ex;\r\n\r\n for(let i=0;i data != ex);\r\n console.log(ans[0])\r\n}\r\n}\r\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let arr = readline().split(' ').map( Number )\r\n console.log( solve(arr) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (arr) => { \r\n let freq = new Array( 100 ).fill( 0 )\r\n \r\n for( let a of arr ) {\r\n freq[a]++\r\n }\r\n\r\n return ( arr.indexOf( freq.indexOf(1) ) + 1 )\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\nlet maxLine = 8;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n for (let i = 0; i <= maxLine; i++) {\n let x = readline();\n execute(x.split(\" \"));\n }\n}\n\nfunction execute(x) {\n // without auto '\\n' (newline)\n // process.stdout.write(\"\");\n // with auto '\\n' (newline)\n // console.log(x);\n\n let data = {};\n let spy = null;\n\n if (x.length !== 1) {\n for (let i = 0; i < x.length; i++) {\n if (!data.hasOwnProperty(x[i])) {\n data[`${x[i]}`] = 1;\n } else {\n data[`${x[i]}`] += 1;\n }\n }\n\n for (const el in data) {\n if (data[el] === 1) {\n spy = el;\n }\n }\n\n for (let i = 0; i < x.length; i++) {\n if (x[i] === spy) {\n console.log(i + 1);\n }\n }\n }\n}\n"}, {"source_code": "function solve(arr, N) {\r\n const a = arr[0];\r\n const b = arr[1];\r\n const c = arr[2];\r\n if (a == b && b == c) {\r\n for (let i = 4; i < N; i++) {\r\n if (arr[i] != a) {\r\n return i + 1;\r\n }\r\n }\r\n } else if (a == b && b != c) {\r\n return 3;\r\n } else if (b == c && a != b) {\r\n return 1;\r\n } else {\r\n return 2;\r\n }\r\n}\r\n\r\nfunction processData(input) {\r\n //Enter your code here\r\n input = input.split('\\n');\r\n const T = Number(input[0].trim());\r\n let i = 1;\r\n for (let t = 0; t < T; t++) {\r\n const N = Number(input[i++].trim());\r\n const arr = input[i++].trim().split(' ').map(Number);\r\n const ans = solve(arr, N);\r\n console.log(ans);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n"}], "src_uid": "224a0b09547ec1441474efbd8e06353b"} {"source_code": "var input = readline().split(' ').map(Number), t = input[0], k = input[1];\nvar res = [];\nvar sum = [];\nres[0] = 1;\nfor (var i = 1; i <= 100000; i++) {\n res[i] = (i - k >= 0) ? ((res[i-1] + res[i-k]) % 1000000007) : res[i-1];\n}\nvar currentSum = 0;\nsum[0] = 0;\nfor (var i = 1; i <= 100000; i++) {\n currentSum = (currentSum + res[i]) % 1000000007;\n sum[i] = currentSum;\n}\nvar ans = '';\nfor (var i = 0; i < t; i++) {\n input = readline().split(' ').map(Number), a = input[0], b = input[1];\n var diff = sum[b] - sum[a-1];\n if (diff < 0) diff += 1000000007;\n ans += (diff + '\\n');\n}\n\n\nwrite(ans);\n", "positive_code": [{"source_code": "var xx = readline().split(' ');\nvar t = parseInt(xx[0]);\nvar k = parseInt(xx[1]);\nvar MOD = 1000000007;\nvar a = new Array();\nvar b = new Array();\nvar n = 100000;\nfor(var i=1;i= 0) ? ((res[i-1] + res[i-k]) % 1000000007) : res[i-1];\n}\nvar currentSum = 0;\nsum[0] = 0;\nfor (var i = 1; i < 100000; i++) {\n currentSum = (currentSum + res[i]) % 1000000007;\n sum[i] = currentSum;\n}\nvar ans = '';\nfor (var i = 0; i < t; i++) {\n input = readline().split(' ').map(Number), a = input[0], b = input[1];\n var diff = sum[b] - sum[a-1];\n ans += (diff + '\\n');\n}\n\nwrite(ans);\n"}, {"source_code": "var input = readline().split(' ').map(Number), t = input[0], k = input[1];\nvar res = [];\nvar sum = [];\nres[0] = 1;\nfor (var i = 1; i < 100000; i++) {\n res[i] = (i - k >= 0) ? ((res[i-1] + res[i-k]) % 1000000007) : res[i-1];\n}\nvar currentSum = 0;\nsum[0] = 0;\nfor (var i = 1; i < 100000; i++) {\n currentSum = (currentSum + res[i]) % 1000000007;\n sum[i] = currentSum;\n}\nvar ans = '';\nfor (var i = 0; i < t; i++) {\n input = readline().split(' ').map(Number), a = input[0], b = input[1];\n var diff = sum[b] - sum[a-1];\n if (diff < 0) diff += 1000000007;\n ans += (diff + '\\n');\n}\n\n\nwrite(ans);\n"}], "src_uid": "16c016c0735be1815c7b94c5c50516f1"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n b = rns(n);\r\n let x = a.reduce((a, b) => a + b, 0),\r\n y = b.reduce((a, b) => a + b, 0);\r\n let dif = x - y;\r\n let res = Math.abs(dif);\r\n for (let i = 0; i < n && dif; i++) {\r\n if (dif > 0) {\r\n if (a[i] !== b[i] && a[i]) {\r\n a[i] = 0;\r\n dif--;\r\n }\r\n } else if (dif < 0) {\r\n if (a[i] !== b[i] && !a[i]) {\r\n a[i] = 1;\r\n dif++;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) {\r\n res++;\r\n break;\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let a = readline() \r\n let b = readline() \r\n console.log( solve( n, a, b ) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, a, b) => { \r\n if( a === b ) return 0\r\n if( n === 1 && a !== b ) return 1\r\n\r\n a = a.split(' ').map( Number )\r\n b = b.split(' ').map( Number )\r\n \r\n let ones_a = 0\r\n for(let i = 0; i < n; i++) {\r\n if( a[i] == 1 ) ones_a++\r\n }\r\n \r\n let ones_b = 0\r\n for(let i = 0; i < n; i++) {\r\n if( b[i] == 1 ) ones_b++\r\n }\r\n \r\n let diff = Math.abs(ones_a - ones_b)\r\n\r\n let res = 0\r\n for(let i = 0; i < n; i++) {\r\n if(a[i] != b[i]) res++\r\n }\r\n\r\n return Math.min( res, diff + 1 )\r\n}\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}], "negative_code": [], "src_uid": "5ccef7fbfd5e85d7fc7ef92f9ebc4088"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const n = str.length\n let a = Array(n)\n let b = Array(n)\n let c = Array(n)\n const s = 'Yes'\n for (let i = 0; i < n; i++) {\n a[i] = s[i % 3]\n b[i] = s[(i + 1) % 3]\n c[i] = s[(i + 2) % 3]\n }\n a = a.join('')\n b = b.join('')\n c = c.join('')\n // console.log(n, a, b, c)\n return a === str || b === str || c === str\n}\n", "positive_code": [{"source_code": "var n = parseInt(readline());\n\nfor(var i = 0; i < n; i++) {\n var s = readline();\n\n var yes = 'Yes';\n \n var k = 0;\n\n while(k < 3 && yes[k] !== s[0]) k++;\n\n k %= 3;\n\n if(yes[k] !== s[0]) { \n print('NO');\n continue;\n }\n\n var j = 0;\n for(; j < s.length;) {\n if(yes[k] === s[j]) {\n k = (k + 1) % 3;\n j++;\n } else {\n print('NO')\n break;\n }\n }\n \n if(j === s.length) print('YES');\n}\n\n\n"}, {"source_code": "var n = Number(readline());\n\nfor (var i = 0; i < n; i++) {\n var str = readline();\n var b = \"Yes\".repeat(50).indexOf(str) > -1;\n print(b ? \"Yes\" : \"NO\");\n}\n"}, {"source_code": "\"use strict\";\r\nexports.__esModule = true;\r\nvar readline_1 = require(\"readline\");\r\nvar yesMap = {\r\n\tY: \"e\",\r\n\te: \"s\",\r\n\ts: \"Y\",\r\n};\r\nfunction isValidSubString(s) {\r\n\tif (s === \"Y\" || s === \"e\" || s === \"s\") {\r\n\t\treturn true;\r\n\t}\r\n\treturn false;\r\n}\r\nfunction findYesSubString(lines) {\r\n\tvar testCases = Number(lines[0]);\r\n\tvar mainString;\r\n\tvar isPartOfYes;\r\n\tfor (var i = 1; i <= testCases; i++) {\r\n\t\tisPartOfYes = false;\r\n\t\tmainString = lines[i];\r\n\t\tvar char = void 0;\r\n\t\t// mainString = mainString.replace(\"Yes\", \"\");\r\n\t\tfor (var j = 0; j < mainString.length; j++) {\r\n\t\t\tchar = mainString[j];\r\n\t\t\tif (mainString.length === 1 && isValidSubString(char)) {\r\n\t\t\t\tisPartOfYes = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (mainString.length === j + 1) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t// console.log(i, mainString, yesMap[char], mainString[j + 1], char);\r\n\t\t\tif (isValidSubString(char) && yesMap[char] === mainString[j + 1]) {\r\n\t\t\t\tisPartOfYes = true;\r\n\t\t\t} else {\r\n\t\t\t\tisPartOfYes = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (isPartOfYes) {\r\n\t\t\tconsole.log(\"YES\");\r\n\t\t} else {\r\n\t\t\tconsole.log(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\nvar rl = readline_1.createInterface(process.stdin, process.stdout);\r\nvar input = [];\r\nrl.on(\"line\", function (line) {\r\n\treturn input.push(line);\r\n}).on(\"close\", function () {\r\n\treturn findYesSubString(input);\r\n});\r\nvar a = \"s\";\r\n"}, {"source_code": " const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n function alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n }\r\n function Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n }\r\n function max(x,y) {\r\n return x >=y ? x : y;\r\n }\r\n function min(x,y) {\r\n return x <=y ? x : y;\r\n }\r\n function abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n }\r\n var T = readline();\r\n var inf = 1000000000000;\r\n for(var tc=1;tc<=T;tc++) {\r\n \tvar n = readline();\r\n \tvar N = n.length;\r\n \tvar ok = false;\r\n \tvar ref = [\"Y\",\"e\",\"s\"];\r\n \tvar r = ref.indexOf(n[0]);\r\n \tif(r!==-1) {\r\n \t\tvar j = 0;\r\n \t\twhile(j {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = parseInt(readline());\n\n\tfor (let i = 0; i < t; i++) {\n\t\tlet s = readline();\n\t\tlet yes = ['Y', 'e', 's'];\n\t\tlet index = -1;\n\t\tlet i = 0;\n\n\t\t// s es substring de YesYesYes\n\n\t\tlet esSubstring = true;\n\n\t\tif (s[0] != 'Y' && s[0] != 'e' && s[0] != 's') {\n\t\t\tesSubstring = false;\n\t\t}\n\n\t\tif (s[0] == 'Y') {\n\t\t\tindex = 0;\n\t\t} else if (s[0] == 'e') {\n\t\t\tindex = 1;\n\t\t}\n\t\tif (s[0] == 's') {\n\t\t\tindex = 2;\n\t\t}\n\n\t\twhile (esSubstring && i < s.length) {\n\t\t\tif (s[i] != yes[index]) {\n\t\t\t\tesSubstring = false;\n\t\t\t}\n\t\t\tif (index == 2) {\n\t\t\t\tindex = 0;\n\t\t\t} else {\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tif (esSubstring) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n const str = 'Yes'.repeat(50);\r\n for (let i = 0; i < testCases; i++) {\r\n let chunk = readline();\r\n if (findChunk(str, chunk)) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}\r\n\r\nfunction findChunk(str, chunk) {\r\n return str.indexOf(chunk) > -1\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = int(readLine());\r\n while (t--) {\r\n let str = readLine();\r\n let len = str.length\r\n let yes = 'Yes'.repeat(len)\r\n if (yes.includes(str)) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n let s = read();\r\n if (s[0] !== 'Y' && s[0] !== 'e' && s[0] !== 's') return 'NO';\r\n let i = 0,\r\n j = 0;\r\n if (s[0] === 'e') j = 1;else if (s[0] === 's') j = 2;\r\n const s1 = 'Yes';\r\n while (i < s.length) {\r\n if (s[i] !== s1[j]) return 'NO';\r\n j = (j + 1) % 3;\r\n i++;\r\n }\r\n return 'YES';\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar V = \"\";\r\n\tfor(var i = 0; i < 10000; i++){\r\n\t\tV += \"Yes\";\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tif(V.indexOf(s) != -1){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var input = readline();\r\n\r\nfor(var i=0; i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar N = n.length;\r\n\tvar ok = false;\r\n\tvar ref = [\"Y\",\"e\",\"s\"];\r\n\tvar r = ref.indexOf(n[0]);\r\n\tif(r!==-1) {\r\n\t\tvar j = 0;\r\n\t\twhile(j {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x,y] = ti(readline().split(' '));\n \n let min = Math.min(x,y);\n let max = Math.max(x,y);\n if(max === min){\n console.log(max+min);\n }else{\n console.log(2*min+(1+(max-min-1)*2));\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let sum = 0;\n for(let i = 0; i < a.length; i++)\n sum += a[i];\n\n let x = sum-a[0];\n let d = a[n-1]*(n-1)-x;\n\n if(a[0] > d){\n let diff = a[0]-d;\n console.log(diff % (n-1) === 0 ? 0 : ((n-1) - (diff % (n-1))));\n }else{\n console.log(d-a[0]);\n }\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [max, sum] = [-Infinity, 0];\n readLine()\n .split(\" \")\n .forEach((n) => {\n n = parseInt(n);\n sum += n;\n max = Math.max(max, n);\n });\n\n const value = Math.ceil(sum / (len - 1));\n if (max > value) {\n let output = Math.abs((len - 1) * max - sum);\n console.log(output);\n } else {\n let output = Math.abs(sum - (len - 1) * value);\n console.log(output);\n }\n }\n}\n"}, {"source_code": "/*\nYou are asked to watch your nephew who likes to play with toy blocks in a strange way.\n\nHe has n boxes and the i-th box has ai blocks. His game consists of two steps:\n\nhe chooses an arbitrary box i;\nhe tries to move all blocks from the i-th box to other boxes.\nIf he can make the same number of blocks in each of n\u22121 other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.\nYou don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box i he chooses he won't be sad. What is the minimum number of extra blocks you need to put?\n\nInput\nThe first line contains a single integer t (1\u2264t\u22641000) \u2014 the number of test cases.\n\nThe first line of each test case contains the integer n (2\u2264n\u2264105) \u2014 the number of boxes.\n\nThe second line of each test case contains n integers a1,a2,\u2026,an (0\u2264ai\u2264109) \u2014 the number of blocks in each box.\n\nIt's guaranteed that the sum of n over test cases doesn't exceed 105.\n\ninputCopy\n3\n3\n3 2 2 -> 3. 1 -> 2 || 2 (2,3,2) || (2,2,3) 2. 1->\n4\n2 2 3 2\n3\n0 3 0\noutputCopy\n1\n0\n3\n\nIn the first test case, you can, for example, put one extra block into the first box and make a=[4,2,2]. If your nephew chooses the box with 4 blocks, then we will move two blocks to the second box and two blocks to the third box (0,4,4). If he chooses the box with 2 blocks then he will move these two blocks to the other box with 2 blocks. (4,0,4) || (4,4,0)\n\nIn the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.\n\nIn the third test case, you should put 3 extra blocks. For example, you can put 2 blocks in the first box and 1 block in the third box. You'll get array a=[2,3,1].\n*/\n\n'use-strict'\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\ndata += chunk;\n});\n\nprocess.stdin.on('end', () =>{\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const n = parseInt(data.shift());\n\n const arr = get_ints();\n\n const res = b(n,arr);\n\n console.log(res)\n }\n});\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n \nfunction readLine() { \n return data[currentLine++];\n}\n \nfunction b(n, arr)\n{\n arr.sort((a,b) => b - a);\n\n const max = arr[0];\n\n const sum = arr.reduce((a, b) => a + b);\n\n const k = Math.max(Math.ceil(sum/(n - 1)), max)\n\n return (n - 1) * k - sum;\n}\n\nmodule.exports = b;"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x,y] = ti(readline().split(' '));\n \n let min = Math.min(x,y);\n let max = Math.max(x,y);\n if(max === min){\n console.log(max+min);\n }else{\n console.log(2*min+(1+(max-min-1)*2));\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let sum = 0;\n for(let i = 0; i < a.length; i++)\n sum += a[i];\n\n let x = sum-a[0];\n let d = a[n-1]*(n-1)-x;\n\n if(a[0] > d){\n let diff = a[0]-d;\n console.log(diff % (n-1));\n }else{\n console.log(d-a[0]);\n }\n }\n}"}], "src_uid": "e75b88ce4341062c20b6014da1152d29"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n let n = data[i] * 1;\n let arr = [];\n for (let i = n; i > 0; i -= 1) arr.push(i);\n console.log(arr.join(' '));\n i += 1;\n\t}\n}", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = [];\n\t\tfor (let i = n; i > 0; i--) {\n\t\t\tarr.push(i);\n\t\t}\n\n\t\tconsole.log(arr.join(' '));\n\t}\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n3\n1\n3\n7\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r 0; j--) {\n arr.push(j);\n }\n print(arr.join(' '));\n }\n}\n\nmain();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n for(var i=1;i<=cases;i++){\n var line2 = readline();\n var currentNumber = parseInt(line2);\n console.log(getGoodPermutation(currentNumber));\n }\n \n}\nfunction getGoodPermutation(x) {\n var strs = [];\n for(var i=1;i<=x;i++){\n strs.push(i);\n }\n return strs.join(\" \");\n}"}, {"source_code": "var readline=require(\"readline\");\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(parseInt(inp));\n var T=arr[0];\n if(arr.length>1){\n var n=parseInt(arr[arr.length-1]);\n var str=\"1\";\n for(var i=2;i<=n;i++) str+=\" \"+i;\n console.log(str);\n }\n if(arr.length===(T+1)) process.exit(0);\n});"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = [];\n for (let i = 0; i < len; i++) {\n arr.push(i + 1);\n }\n console.log(arr.join(\" \"));\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar N = nextInt();\n \tvar list = [];\n \tfor(var j = N; j > 0; j--){\n \t\tlist.push(j);\n \t}\n \toutput[i] = myconv(list, 8);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n console.log(Array(n).fill(0).map((_, i) => i + 1).join(' '))\n }\n}\n"}], "negative_code": [], "src_uid": "1b3ac752bc9c0b5e20a76f028d4b3c15"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0], m = k[1];\n if(n < m){\n var temp = n;\n n = m;\n m = temp;\n }\n if(m == 1 && n >= 3){\n console.log(-1);\n }else{\n console.log(2 * n - Math.floor((n + m) % 2) - 2);\n }\n }\n});", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var n = nextInt();\r\n\t\tvar m = nextInt();\r\n\r\n let max = Math.max(n, m), min = Math.min(n, m);\r\n\r\n if (min === 1) {\r\n if (max === 1) {\r\n myout(0);\r\n } else if (max === 2) {\r\n myout(1);\r\n } else {\r\n myout(-1);\r\n }\r\n continue\r\n } \r\n \r\n if (max === min + 1 || max === min) {\r\n myout(max + min - 2);\r\n continue;\r\n } \r\n\r\n let diff = max - min;\r\n let res = 0;\r\n if (diff % 2 === 1) {\r\n res += 1\r\n }\r\n\r\n res += min*2 - 2 + Math.floor(diff / 2) * 4;\r\n myout(res)\r\n // output in nodeJs\r\n // console.log(arr)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var n = nextInt();\r\n\t\tvar m = nextInt();\r\n\r\n let max = Math.max(n, m), min = Math.min(n, m);\r\n\r\n if (min === 1) {\r\n if (max === 1) {\r\n myout(0);\r\n } else if (max === 2) {\r\n myout(1);\r\n } else {\r\n myout(-1);\r\n }\r\n continue\r\n } \r\n \r\n if (max === min + 1 || max === min) {\r\n myout(max + min - 2);\r\n continue;\r\n } \r\n\r\n let diff = max - min;\r\n let res = 0;\r\n if (diff % 2 === 1) {\r\n res += 1\r\n }\r\n\r\n res += min*2 - 2 + Math.floor(diff / 2) * 4;\r\n myout(res)\r\n // output in nodeJs\r\n // console.log(arr)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var n = nextInt();\r\n\t\tvar m = nextInt();\r\n\r\n let max = Math.max(n, m), min = Math.min(n, m);\r\n\r\n if (min === 1) {\r\n if (max === 1) {\r\n myout(0);\r\n } else if (max === 2) {\r\n myout(1);\r\n } else {\r\n myout(-1);\r\n }\r\n continue\r\n } \r\n \r\n if (max === min + 1 || max === min) {\r\n myout(max + min - 2);\r\n continue;\r\n } \r\n\r\n let diff = max - min;\r\n let res = 0;\r\n if (diff % 2 === 1) {\r\n res += 1\r\n }\r\n\r\n res += min*2 - 2 + Math.floor(diff / 2) * 4;\r\n myout(res)\r\n // output in nodeJs\r\n // console.log(arr)\r\n\t}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n'); \r\n main(); \r\n});\r\n\r\nfunction readLine(){\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n // input in nodeJs\r\n\tlet test = parseInt(readLine(),10);\r\n\twhile(test--){\r\n\t\tlet [n, m] = readLine().split(\" \").map(ele => parseInt(ele, 10));\r\n \r\n let max = Math.max(n, m), min = Math.min(n, m);\r\n\r\n if (min === 1) {\r\n if (max === 1) {\r\n console.log(0);\r\n } else if (max === 2) {\r\n console.log(1);\r\n } else {\r\n console.log(-1);\r\n }\r\n continue\r\n } \r\n \r\n if (max === min + 1 || max === min) {\r\n console.log(max + min - 2);\r\n continue;\r\n } \r\n\r\n let diff = max - min;\r\n let res = 0;\r\n if (diff % 2 === 1) {\r\n res += 1\r\n }\r\n\r\n res += min*2 - 2 + Math.floor(diff / 2) * 4;\r\n console.log(res)\r\n // output in nodeJs\r\n // console.log(arr)\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n s = s.trim().split(\"\\n\");\n\n main();\n});\n\nfunction main() {\n let t = Number(s[0]);\n\n let i = 1;\n while (t--) {\n const [m, n] = s[i].split(\" \").map(Number);\n solve(m, n);\n i++;\n }\n}\n\nfunction solve(m, n) {\n if (m === 1 || n === 1) {\n if (Math.abs(m - n) === 1) {\n console.log(1);\n return;\n }\n if (m + n > 2) {\n console.log(-1);\n return;\n }\n }\n\n if (m < n) {\n [m, n] = [n, m];\n }\n\n let count = 0;\n const diag = 2 * (n - 1);\n\n count += diag;\n\n const remaining = m - n;\n const twoJumps = Math.floor(remaining / 2);\n count += twoJumps * 4;\n count += remaining % 2;\n\n console.log(count);\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m) {\r\n if (n > m) {\r\n return solve(m, n);\r\n } else {\r\n if (n === 1 && m > 2) console.log(-1);else if ((n & 1) === (m & 1)) console.log(m * 2 - 2);else console.log(m * 2 - 3);\r\n }\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 1; __ <= _; __++) {\r\n const [n, m] = inputs[__].trim().split(' ').map(Number);\r\n\r\n solve(n, m);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let [x,y]=line[i].split(' ').map(x=>{return parseInt(x)});\r\n x--;\r\n y--;\r\n if(x>y) [x,y]=[y,x];\r\n if(x===0)\r\n {\r\n if(y<=1) console.log(y);\r\n else console.log(-1);\r\n }\r\n else\r\n {\r\n let ans=y+x+(y-x-1);\r\n if((y-x-1)&1) ans++;\r\n console.log(ans);\r\n }\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n if (m > n) [m, n] = [n, m];\r\n\r\n if (m === 1 && n > 2) {\r\n output(-1);\r\n continue;\r\n }\r\n\r\n output(2*n-2-(n+m)%2);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nfunction solve(n, m) {\r\n if (n < m) {\r\n [n, m] = [m, n];\r\n }\r\n if (m == 1 && n > 2) {\r\n return INIT;\r\n }\r\n let ans = m + m - 2;\r\n n -= m;\r\n let pairs = n - (n % 2);\r\n ans += pairs * 2;\r\n if ((n % 2) == 1) {\r\n ans++;\r\n }\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let m = nextInt();\r\n printf(\"%d\\n\", solve(n, m));\r\n }\r\n}\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m] = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n m,\n };\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, m } = testCase;\n\n const mini = Math.min(m - 1, n - 1);\n const maxi = Math.max(m - 1, n - 1);\n const diff = Math.abs(m - n);\n\n let result =\n mini == 0 && maxi > 1\n ? -1\n : mini * 2 + Math.floor(diff / 2) * 4 + (diff % 2);\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, m)=>{\n if (n === 1 && m === 1) return 0;\n if (n === 1 && m > 2 || n > 2 && m === 1) return -1;\n if (n === 1 && m === 2 || n === 2 && m === 1) return 1;\n\n let diag = (Math.min(n, m) - 1) * 2;\n // console.log('DEBUG diag', diag);\n if (n === m) return diag;\n\n let diff = Math.abs(n - m);\n\n\n let x1 = Math.floor((diff + 1) / 2);\n let x2 = Math.floor(diff / 2);\n // console.log('DEBUG x1', x1);\n // console.log('DEBUG x2', x2);\n\n let min = Math.min(n, m);\n let divBy2 = min % 2;\n // console.log('DEBUG divBy2', divBy2);\n\n // let ones = divBy2 ? x2 : x1;\n // let threes = divBy2 ? x1 : x2;\n let ones = x1;\n let threes = x2;\n\n // console.log('DEBUG ones', ones);\n // console.log('DEBUG threes', threes);\n\n let res = diag + ones + threes * 3;\n\n return res;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, m] = ra();\n \n console.log(`${calc(n, m)}`);\n }\n}"}, {"source_code": "'use strict';\n\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, m)=>{\n if (n>m)\n return calc(m, n);\n // n1)\n return -1;\n let ans = n*2;\n m -= n;\n if (m==0)\n return ans;\n l({ans, m})\n return ans + Math.floor((m)/2)*4 + m%2;\n if (m%3==2){\n }\n ans++;\n m--;\n ans += m*2\n if (0)\n if (m%2) \n ans++;\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, m] = ra();\n l('ans')\n print(calc(n, m));\n }\n}\n \nE.calc = calc;"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar H = Math.min(N, M);\r\n\t\tvar W = Math.max(N, M);\r\n\t\tif(H == 1 && W >= 3){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = (H - 1) + (W - 1);\r\n\t\tif(W - H >= 2){\r\n\t\t\tvar diff = W - H;\r\n\t\t\toutput += Math.floor(diff / 2) * 2;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n s = s.trim().split(\"\\n\");\n\n main();\n});\n\nfunction main() {\n let t = Number(s[0]);\n\n let i = 1;\n while (t--) {\n const [m, n] = s[i].split(\" \").map(Number);\n solve(m, n);\n i++;\n }\n}\n\nfunction solve(m, n) {\n if (m === 1 || n === 1) {\n if (m - n === 1) {\n console.log(1);\n return;\n }\n if (m + n > 2) {\n console.log(-1);\n return;\n }\n }\n\n if (m < n) {\n [m, n] = [n, m];\n }\n\n let count = 0;\n const diag = 2 * (n - 1);\n\n count += diag;\n\n const remaining = m - n;\n const twoJumps = Math.floor(remaining / 2);\n count += twoJumps * 4;\n count += remaining % 2;\n\n console.log(count);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n s = s.trim().split(\"\\n\");\n\n main();\n});\n\nfunction main() {\n let t = Number(s[0]);\n\n let i = 1;\n while (t--) {\n const [m, n] = s[i].split(\" \").map(Number);\n solve(m, n);\n i++;\n }\n}\n\nfunction solve(m, n) {\n if (m === 1 && n === 1) {\n console.log(0);\n return 0;\n }\n if (m === 1 || n === 1) {\n console.log(-1);\n return;\n }\n\n let sx = 1,\n sy = 1;\n\n let count = 0;\n const defOptions = [\n [1, 0],\n [0, 1],\n ];\n let i = 0;\n while (sx !== m && sy !== n) {\n sx += defOptions[i][0];\n sy += defOptions[i][1];\n i = (i + 1) % 2;\n count++;\n }\n\n const diff = sx === m ? n - sy : m - sx;\n const q = Math.floor(diff / 2);\n const r = diff % 2;\n count += q * 4 + r;\n\n console.log(count);\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m) {\r\n if (m === n) {\r\n console.log(n * (n - 1));\r\n } else if (n > m) {\r\n return solve(m, n);\r\n } else {\r\n if (n === 1 && m > 2) console.log(-1);else if ((n & 1) === (m & 1)) console.log(m * 2 - 2);else console.log(m * 2 - 3);\r\n }\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 1; __ <= _; __++) {\r\n const [n, m] = inputs[__].trim().split(' ').map(Number);\r\n\r\n solve(n, m);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}], "src_uid": "6f0d3a7971ffc2571838ecd8bf14238d"} {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n const arr = lines[i*2+2].split(' ').map(x => +x)\n const ns = new Set()\n for (const num of arr) {\n ns.add(num)\n }\n const s = Array.from(ns)\n if (s.length > k) {\n console.log(-1)\n } else {\n let diff = k - s.length\n while (diff) {\n s.push(s[0])\n diff--\n }\n console.log(n * s.length)\n console.log(arr.reduce((r) => r.concat(s), []).join(' '))\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 2) {\n const [n, k] = splbsi(input[i]);\n const arr = splbsi(input[i + 1]);\n\n const nums = new Set(arr);\n\n if (nums.size > k) {\n console.log(-1);\n continue;\n }\n\n const res = [...nums];\n for (let j = 0; j < k - nums.size; j += 1) {\n res.push(1);\n }\n\n const answer = [];\n for (let i = 0; i < n; i += 1) {\n answer.push(...res);\n }\n\n console.log(answer.length);\n console.log(answer.join(\" \"));\n }\n});\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var unique = new Set(numbers);\n\n if(unique.size > limit) {\n console.log(-1);\n continue;\n }\n\n const output = [];\n for(let i=0;i parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 2) {\n const [n, k] = splbsi(input[i]);\n const arr = splbsi(input[i + 1]);\n\n const nums = new Set(arr);\n\n if (nums.size > k) {\n console.log(-1);\n continue;\n }\n\n const res = [];\n for (let j = 0; j < n; j += 1) {\n res.push(...[...nums, 1]);\n }\n\n console.log(n * k);\n console.log(res.join(\" \"));\n }\n});\n"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 2) {\n const [n, k] = splbsi(input[i]);\n const arr = splbsi(input[i + 1]);\n\n const nums = new Set(arr);\n\n if (nums.size > k) {\n console.log(-1);\n continue;\n }\n\n const res = [];\n for (let j = 0; j < n; j += 1) {\n res.push(...[...nums, 1]);\n }\n\n console.log(res.length);\n console.log(res.join(\" \"));\n }\n});\n"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 2) {\n const [n, k] = splbsi(input[i]);\n const arr = splbsi(input[i + 1]);\n\n const nums = new Set(arr);\n\n if (nums.size > k) {\n console.log(-1);\n continue;\n }\n\n const res = [];\n while (res.length <= n) {\n res.push(...nums);\n }\n\n console.log(res.length);\n console.log(res.join(\" \"));\n }\n});\n"}, {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n const arr = lines[i*2+2].split(' ').map(x => +x)\n const ns = new Set()\n for (const num of arr) {\n ns.add(num)\n }\n const s = Array.from(ns)\n if (s.length > k) {\n console.log(-1)\n } else {\n console.log(n * s.length)\n console.log(arr.reduce((r) => r.concat(s), []).join(' '))\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var oldNumber = [...numbers];\n numbers.sort((a,b) => a-b);\n\n if(numbers.join(\"\") === oldNumber.join(\"\")) {\n console.log(-1);\n } else {\n let max = Math.max.apply(null, oldNumber);\n let output = [];\n\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var unique = new Set(numbers);\n\n if(unique.size === numbers.length) {\n console.log(-1);\n continue;\n }\n\n const output = [];\n console.log(n*limit);\n for(let i=0;i<= n;i++) {\n output.push(...Array.from(unique));\n if(!unique.has(1)) {\n output.push(1);\n }\n }\n console.log(output.join(\" \"));\n\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var oldNumber = [...numbers];\n numbers.sort((a,b) => a-b);\n\n if(numbers.join(\"\") === oldNumber.join(\"\")) {\n console.log(-1);\n } else {\n let max = Math.max.apply(null, oldNumber);\n limit = limit * 2;\n let output = [];\n\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var unique = new Set(numbers);\n\n if(unique.size >= limit) {\n console.log(-1);\n continue;\n }\n\n const output = [];\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var unique = new Set(numbers);\n\n if(unique.size === numbers.length) {\n console.log(-1);\n continue;\n }\n\n const output = [];\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var oldNumber = [...numbers];\n numbers.sort((a,b) => a-b);\n\n if(numbers.join(\"\") === oldNumber.join(\"\")) {\n console.log(-1);\n } else {\n let max = Math.max.apply(null, oldNumber);\n let output = [];\n\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r parseInt(x));\n var numbers = readline().split(\" \").map(x=> parseInt(x));\n var unique = new Set(numbers);\n\n if(unique.size === numbers.length) {\n console.log(-1);\n continue;\n }\n\n const output = [];\n console.log(n*limit);\n for(let i=0;i<= n;i++) {\n output.push(Array.from(unique));\n if(!unique.has(1)) {\n output.push(1);\n }\n }\n console.log(output.join(\" \"));\n\n }\n}"}], "src_uid": "80d4b2d01215b12ebd89b8ee2d1ac6ed"} {"source_code": "function readInts() {\n return readline().split(' ').map(function (v) { return parseInt(v); });\n}\nfunction min(_a, _b) {\n var l1 = _a[0], r1 = _a[1];\n var l2 = _b[0], r2 = _b[1];\n // console.log('min', [l1, r1], [l2, r2]);\n return [l1 < l2 ? l1 : l2, r1 < r2 ? r1 : r2];\n}\nfunction solve(n, m, rooms) {\n var _a, _b, _c;\n var first = true;\n var _d = [0, 0], l = _d[0], r = _d[1];\n var f = 0;\n while (f < n) {\n var room = rooms[f];\n var leftmost = room.indexOf('1');\n if (leftmost < 0) {\n if (!first)\n _a = min([l + 1, r + 1], [r + m + 2, l + m + 2]), l = _a[0], r = _a[1];\n }\n else {\n var rightmost = room.lastIndexOf('1');\n if (first) {\n _b = [rightmost, m - leftmost + 1], l = _b[0], r = _b[1];\n first = false;\n }\n else {\n _c = min([m + 2 + r, m + 2 + l], [rightmost * 2 + 1 + l, (m - leftmost + 1) * 2 + 1 + r]), l = _c[0], r = _c[1];\n }\n }\n // console.log({ f, l, r });\n f++;\n }\n return l;\n}\n// function show(n: number, m: number, rooms: string[]) {\n// console.log({n, m, rooms}, '-->', solve(n, m, rooms))\n// }\n// show(2, 2, [\n// '0010',\n// '0100']);\n// show(3, 4, [\n// '001000',\n// '000010',\n// '000010']);\n// show(4, 3, [\n// '01110',\n// '01110',\n// '01110',\n// '01110'])\nvar _a = readInts(), n = _a[0], m = _a[1];\nvar rooms = [];\nfor (var i = 0; i < n; i++)\n rooms.push(readline());\nprint(solve(n, m, rooms));\n", "positive_code": [{"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar m = parseInt(arr[1]);\nvar v = Array(n);\nvar count = 0;\nvar ef = 0;\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline();\n var line = arr.substr(1,m);\n // var line = Array(m).fill(0);\n // for (var j = 0; j < m; j ++)\n // {\n // line[j] = arr.charAt(j+1)=='1'?1:0;\n // }\n // v.splice(v, 0, line);\n if (line.indexOf('1') != -1)\n {\n v[count++] = line;\n }\n else if (count !== 0)\n {\n ef ++;\n }\n}\nn = count;\n// print(JSON.stringify(v));\n\nif (n === 0)\n{\n print(0);\n}\nvar dp = [Array(n+2).fill(0), Array(n+2).fill(0)];\nfor (var i = 0; i < n; i ++)\n{\n var r = v[n-1-i].lastIndexOf('1');\n var l = v[n-1-i].indexOf('1');\n // print(l, r);\n if (i === 0)\n {\n if (n == 1)\n {\n print(r+1 + ef);\n }\n else\n {\n dp[0][i] = (r+1)*2 + 1;\n dp[1][i] = m + 2;\n }\n }\n else if (i == n-1)\n {\n print(Math.min( dp[0][i-1]+(r+1), dp[1][i-1]+(m-l)) + ef);\n }\n else\n {\n dp[0][i] = Math.min( dp[0][i-1]+(r+1)*2, dp[1][i-1]+(m+1)) + 1;\n dp[1][i] = Math.min( dp[0][i-1]+(m+1), dp[1][i-1]+(m-l)*2) + 1;\n }\n // print(JSON.stringify(dp));\n}\n"}], "negative_code": [{"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar m = parseInt(arr[1]);\nvar v = Array(n);\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline();\n var line = arr.substr(1,m);\n // var line = Array(m).fill(0);\n // for (var j = 0; j < m; j ++)\n // {\n // line[j] = arr.charAt(j+1)=='1'?1:0;\n // }\n // v.splice(v, 0, line);\n v[n-i-1] = line;\n}\n// print(JSON.stringify(v));\n\nvar dp = [Array(n+2).fill(0), Array(n+2).fill(0)];\nfor (var i = 0; i < n; i ++)\n{\n var r = v[i].lastIndexOf('1');\n var l = v[i].indexOf('1');\n // print(l, r);\n if (i === 0)\n {\n dp[0][i] = (r+1)*2 + 1;\n dp[1][i] = m + 2;\n }\n else if (i == n-1)\n {\n print(Math.min( dp[0][i-1]+(r+1), dp[1][i-1]+(m-l)));\n }\n else\n {\n dp[0][i] = Math.min( dp[0][i-1]+(r+1)*2, dp[1][i-1]+(m+1)) + 1;\n dp[1][i] = Math.min( dp[0][i-1]+(m+1), dp[1][i-1]+(m-l)*2) + 1;\n }\n // print(JSON.stringify(dp));\n}"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar m = parseInt(arr[1]);\nvar v = Array(n);\nvar count = 0;\nvar ef = 0;\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline();\n var line = arr.substr(1,m);\n // var line = Array(m).fill(0);\n // for (var j = 0; j < m; j ++)\n // {\n // line[j] = arr.charAt(j+1)=='1'?1:0;\n // }\n // v.splice(v, 0, line);\n if (line.indexOf('1') != -1)\n {\n v[count++] = line;\n }\n else if (count !== 0)\n {\n ef ++;\n }\n}\nn = count;\n// print(JSON.stringify(v));\n\nvar dp = [Array(n+2).fill(0), Array(n+2).fill(0)];\nfor (var i = 0; i < n; i ++)\n{\n var r = v[n-1-i].lastIndexOf('1');\n var l = v[n-1-i].indexOf('1');\n // print(l, r);\n if (i === 0)\n {\n dp[0][i] = (r+1)*2 + 1;\n dp[1][i] = m + 2;\n }\n else if (i == n-1)\n {\n print(Math.min( dp[0][i-1]+(r+1), dp[1][i-1]+(m-l)) + ef);\n }\n else\n {\n dp[0][i] = Math.min( dp[0][i-1]+(r+1)*2, dp[1][i-1]+(m+1)) + 1;\n dp[1][i] = Math.min( dp[0][i-1]+(m+1), dp[1][i-1]+(m-l)*2) + 1;\n }\n // print(JSON.stringify(dp));\n}"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar m = parseInt(arr[1]);\nvar v = Array(n);\nvar count = 0;\nvar ef = 0;\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline();\n var line = arr.substr(1,m);\n // var line = Array(m).fill(0);\n // for (var j = 0; j < m; j ++)\n // {\n // line[j] = arr.charAt(j+1)=='1'?1:0;\n // }\n // v.splice(v, 0, line);\n if (line.indexOf('1') != -1)\n {\n v[count++] = line;\n }\n else if (count !== 0)\n {\n ef ++;\n }\n}\nn = count;\n// print(JSON.stringify(v));\n\nvar dp = [Array(n+2).fill(0), Array(n+2).fill(0)];\nfor (var i = 0; i < n; i ++)\n{\n var r = v[n-1-i].lastIndexOf('1');\n var l = v[n-1-i].indexOf('1');\n // print(l, r);\n if (i === 0)\n {\n if (n == 1)\n {\n print(r+1 + ef);\n }\n else\n {\n dp[0][i] = (r+1)*2 + 1;\n dp[1][i] = m + 2;\n }\n }\n else if (i == n-1)\n {\n print(Math.min( dp[0][i-1]+(r+1), dp[1][i-1]+(m-l)) + ef);\n }\n else\n {\n dp[0][i] = Math.min( dp[0][i-1]+(r+1)*2, dp[1][i-1]+(m+1)) + 1;\n dp[1][i] = Math.min( dp[0][i-1]+(m+1), dp[1][i-1]+(m-l)*2) + 1;\n }\n // print(JSON.stringify(dp));\n}\n"}], "src_uid": "55070f8e5dba8a6ec669a53a169e557d"} {"source_code": "var t = parseInt(readline(), 10),\n ab = [], b = 0;\n \nfor(var i=1; i<=t; i++) {\n ab = readline().split(' ').map(el => parseInt(el, 10));\n var a = ab[0];\n var B = ab[1];\n \n if(B < 9) b = 0;\n else if(B < 99) b = 1;\n else if(B < 999) b = 2;\n else if(B < 9999) b = 3;\n else if(B < 99999) b = 4;\n else if(B < 999999) b = 5;\n else if(B < 9999999) b = 6;\n else if(B < 99999999) b = 7;\n else if(B < 999999999) b = 8;\n else b = 9;\n \n print(a*b);\n}", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const t = readInt(arr)\n\n for(let i = 0; i < t; i++) {\n const [A, B] = readInts(arr, i)\n // wr(arr[i], A, B)\n\n let st = B.toString()\n let len = st.length\n\n if(Math.pow(10, len) - 1 > B) len --\n\n wr(A * len)\n\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var t = parseInt(readline());\n var A, B;\n for (var i = 0; i < t; i++)\n {\n var line = readline().split(' ')\n A = parseInt(line[0]);\n B = parseInt(line[1]);\n console.log(A * (('' + (B + 1)).length - 1));\n }\n\n}"}, {"source_code": "'use strict'\nvar t=Number(readline());\n\nwhile(t--){\n var s=readline().replace(/\\r$/, '').split(' ').map(Number);\n var a=s[0];\n var b=s[1];\n\n var cnt=0,nine=0;\n\n while((nine*10+9)<=b){\n nine*=10;\n nine+=9;\n cnt++;\n }\n var ans=Number(a*cnt);\n print(ans);\n}"}], "negative_code": [{"source_code": "'use strict'\nvar t=Number(readline());\n\nwhile(t--){\n var s=readline().replace(/\\r$/, '').split(' ').map(Number);\n var a=s[0];\n var b=s[1];\n\n var cnt=0,nine=0;\n\n while((nine*10+9)<=b){\n nine*=10;\n nine+=9;\n cnt++;\n print(\"pp\");\n }\n var ans=Number(a*cnt);\n print(ans);\n}"}], "src_uid": "dc67dd2102c70ea476df642b863ae8d3"} {"source_code": "\"use strict\";\n\nvar atLevel = {};\n\nfunction addForLevel (text, level) {\n if (!(level in atLevel)) {\n atLevel[level] = []; \n }\n atLevel[level].push(text);\n}\n\nfunction parseComment (tokens, pos, level) {\n var text = tokens[pos++];\n var kids = parseInt(tokens[pos++]);\n addForLevel (text, level);\n var positions = [kids];\n while (true) {\n while (positions.length > 0 && positions[positions.length - 1] === 0)\n positions.pop();\n if (positions.length === 0)\n break; \n text = tokens[pos++];\n kids = parseInt(tokens[pos++]);\n positions[positions.length - 1]--;\n addForLevel (text, positions.length);\n positions.push(kids)\n }\n return pos;\n}\n\nfunction parseAll (s) {\n var tokens = s.split(',');\n var pos = 0;\n while (pos < tokens.length) \n pos = parseComment(tokens, pos, 0);\n}\n\nvar s = readline();\nparseAll(s);\nvar level = 0;\nwhile (level in atLevel) \n level++;\nprint(level);\nfor (var i = 0; i < level; i++)\n print(atLevel[i].join(' '));\n ", "positive_code": [{"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nreadline = ->\n #'hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0'\n #'a,5,A,0,a,0,A,0,a,0,A,0'\n 'A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0'\n\nprint = console.log\n */\n\n(function() {\n var depthstack, el, i, j, layers, len, line, name, numbers, text;\n\n line = readline().split(',');\n\n text = line.filter(function(x, i) {\n return i % 2 === 0;\n });\n\n numbers = line.filter(function(x, i) {\n return i % 2 === 1;\n }).map(Number);\n\n layers = [];\n\n depthstack = [Infinity];\n\n for (i = j = 0, len = text.length; j < len; i = ++j) {\n el = text[i];\n if (layers[name = depthstack.length - 1] == null) {\n layers[name] = [];\n }\n layers[depthstack.length - 1].push(text[i]);\n depthstack[depthstack.length - 1] -= 1;\n depthstack.push(numbers[i]);\n while (depthstack[depthstack.length - 1] === 0) {\n depthstack.pop();\n }\n }\n\n print(layers.length);\n\n print(layers.map(function(x) {\n return x.join(' ');\n }).join('\\n'));\n\n}).call(this);\n"}], "negative_code": [], "src_uid": "da08dd34ac3c05af58926f70abe5acd0"} {"source_code": "var i, a = [], s = readline();\nfor (i = 0; i < s.length; i++)\n\tif (s[i] === a[a.length - 1]) a.pop();\n\telse a.push(s[i]);\n\nprint(a.join(''));", "positive_code": [{"source_code": "const {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let L = ipt.split(EOL).slice(0, -1)[0]\n let l = []\n for (let i = 0; i < L.length; i++) {\n while (L[i] == l[l.length - 1]) {\n i++\n l.pop()\n }\n l.push(L[i])\n }\n console.log(l.join(''))\n})"}, {"source_code": "readline = require('readline')\nlet stdinInput = '';\n\nfunction IO_IN_FILE(){\n //file\n var fs = require('fs');\n const inputfile = '_in.txt';\n const outputfile = '_out.txt';\n fs.writeFileSync(outputfile, '');\n var myInterface = readline.createInterface({\n input: fs.createReadStream(inputfile),\n });\n myInterface.on('line', function (line) {\n stdinInput += line+'\\n';\n }).on('close', () => {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n // let l = []\n // let len = s.length;\n // for (let i = 0; i < len; i++) {\n // while (s[i] == l[l.length - 1]) {\n // i++\n // l.pop()\n // }\n // l.push(s[i])\n // }\n // console.log(l.join(''))\n\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n a.pop();\n n--;\n }else{\n a.push(s[i]);\n n++;\n }\n }else{\n a.push(s[i]);\n n++;\n }\n }\n // console.log(a.join(''))\n // for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n // let l = []\n // let len = s.length;\n // for (let i = 0; i < len; i++) {\n // while (s[i] == l[l.length - 1]) {\n // i++\n // l.pop()\n // }\n // l.push(s[i])\n // }\n // console.log(l.join(''))\n\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n a.pop();\n n--;\n }else{\n a.push(s[i]);\n n++;\n }\n }else{\n a.push(s[i]);\n n++;\n }\n }\n console.log(a.join(''))\n // for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n let l = []\n let len = s.length;\n for (let i = 0; i < len; i++) {\n while (s[i] == l[l.length - 1]) {\n i++\n l.pop()\n }\n l.push(s[i])\n }\n console.log(l.join(''))\n\n // let len = s.length;\n // let a = [], n;\n // n=0;\n // for(let i=0; i0){\n // if(s[i]==a[n-1]){\n // n--;\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }\n \n // for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n let l = []\n for (let i = 0; i < s.length; i++) {\n while (s[i] == l[l.length - 1]) {\n i++\n l.pop()\n }\n l.push(s[i])\n }\n console.log(l.join(''))\n\n // let len = s.length;\n // let a = [], n;\n // n=0;\n // for(let i=0; i0){\n // if(s[i]==a[n-1]){\n // n--;\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }\n \n // for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n // let l = []\n // let len = s.length;\n // for (let i = 0; i < len; i++) {\n // while (s[i] == l[l.length - 1]) {\n // i++\n // l.pop()\n // }\n // l.push(s[i])\n // }\n // console.log(l.join(''))\n\n\n let len = s.length;\n let a = [], n;\n n=0;\nfor(let i=0; i0){\n if(s[i]==a[n-1]){\n a.pop();\n n--;\n }else{\n a.push(s[i]);\n n++;\n }\n }else{\n a.push(s[i]);\n n++;\n }\n}\n// console.log(a.join(''))\n// for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i ipt += s)\nprocess.stdin.on('end', () => {\n let L = ipt.split(EOL).slice(0, -1)[0]\n let l\n do {\n l = L\n L = L.replace(/(\\w)\\1+/g, '')\n } while (l != L)\n console.log(L)\n})"}, {"source_code": "readline = require('readline')\nlet stdinInput = '';\n\nfunction IO_IN_FILE(){\n //file\n var fs = require('fs');\n const inputfile = '_in.txt';\n const outputfile = '_out.txt';\n fs.writeFileSync(outputfile, '');\n var myInterface = readline.createInterface({\n input: fs.createReadStream(inputfile),\n });\n myInterface.on('line', function (line) {\n stdinInput += line+'\\n';\n }).on('close', () => {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n console.log(a);\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n console.log(this.lines);\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n console.log(s);\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n console.log(a);\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s1, s2;\nfunction main() {\n const is = new Scanner();\n \n while((s1 = is.nextLine())!==false){\n solve(s1);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n// var readline = require('readline');\n\n// const myInterface = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// // var fs = require('fs');\n// // fs.writeFileSync('_out.txt', '');\n// // var myInterface = readline.createInterface({\n// // input: fs.createReadStream('_in.txt'),\n// // });\n\n\n// myInterface.on('line', function (line) {\n// solve(line);\n \n// }).on('close', () => {\n// process.exit(0);\n// })\n\nfunction solve(s){\n // let a = [300000];\n // let n=0;\n let len = s.length;\n // for(let i=0; i0){\n // if(s[i]==a[n-1]){\n // n--;\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }\n // // console.log(n);\n // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s1, s2;\nfunction main() {\n const is = new Scanner();\n \n while((s1 = is.nextLine())!==false){\n solve(s1);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n// var readline = require('readline');\n\n// const myInterface = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// // var fs = require('fs');\n// // fs.writeFileSync('_out.txt', '');\n// // var myInterface = readline.createInterface({\n// // input: fs.createReadStream('_in.txt'),\n// // });\n\n\n// myInterface.on('line', function (line) {\n// solve(line);\n \n// }).on('close', () => {\n// process.exit(0);\n// })\n\nfunction solve(s1){\n // let a = [300000];\n // let n=0;\n let len = s1.length;\n // for(let i=0; i0){\n // if(s[i]==a[n-1]){\n // n--;\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }\n // // console.log(n);\n // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n console.log(a);\n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n // console.log(n);\n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n console.log(a);\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; console.log(input)});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n console.log(this.lines);\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n console.log(s);\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n console.log(a);\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input;});\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n\n // let l = []\n // let len = s.length;\n // for (let i = 0; i < len; i++) {\n // while (s[i] == l[l.length - 1]) {\n // i++\n // l.pop()\n // }\n // l.push(s[i])\n // }\n // console.log(l.join(''))\n\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n // for(let i=0; i0){\n// if(s[i]==a[n-1]){\n// a.pop();\n// n--;\n// }else{\n// a.push(s[i]);\n// n++;\n// }\n// }else{\n// a.push(s[i]);\n// n++;\n// }\n// }\n// // console.log(a.join(''))\n// // for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n console.log(n);\n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s1, s2;\nfunction main() {\n const is = new Scanner();\n \n while((s1 = is.nextLine())!==false){\n solve(s1);\n }\n}\n\n\n\n\n\n\n\n\n// var readline = require('readline');\n\n// const myInterface = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// // var fs = require('fs');\n// // fs.writeFileSync('_out.txt', '');\n// // var myInterface = readline.createInterface({\n// // input: fs.createReadStream('_in.txt'),\n// // });\n\n\n// myInterface.on('line', function (line) {\n// solve(line);\n \n// }).on('close', () => {\n// process.exit(0);\n// })\n\nfunction solve(s){\n // let a = [300000];\n // let n=0;\n let len = s.length;\n // for(let i=0; i0){\n // if(s[i]==a[n-1]){\n // n--;\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }else{\n // a[n] = s[i];\n // n++;\n // }\n // }\n // // console.log(n);\n // for(let i=0; i {\n main(); \n process.exit(0);\n })\n\n process.stdout.write = function(data1){\n fs.appendFileSync(outputfile, data1, 'utf8');\n }\n}\n\nfunction IO_STD(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('readable', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n if(this.index >= this.lines.length-1)\n return false;\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n let checkarr = this.nextLine();\n if(checkarr===false)\n return false;\n const array = checkarr.split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// IO_IN_FILE();\nIO_STD();\n\n\nlet ntest, s;\nfunction main() {\n const is = new Scanner();\n \n while((s = is.nextLine())!==false){\n console.log(s);\n let len = s.length;\n let a = [], n;\n n=0;\n for(let i=0; i0){\n if(s[i]==a[n-1]){\n n--;\n }else{\n a[n] = s[i];\n n++;\n console.log(a);\n }\n }else{\n a[n] = s[i];\n n++;\n }\n }\n \n for(let i=0; i {\n// process.exit(0);\n// })\n\n// function solve(s){\n// // let a = [300000];\n// // let n=0;\n// let len = s.length;\n// // for(let i=0; i0){\n// // if(s[i]==a[n-1]){\n// // n--;\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }else{\n// // a[n] = s[i];\n// // n++;\n// // }\n// // }\n// // // console.log(n);\n// // for(let i=0; i this.arr[ i ] ) {\n \t\t\tcn++ ;\n \t\t}\n \t}\n \tthis.brr.push( cn ) ;\n }\n res = '' ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i > 0 ) {\n \t\tres += ' ' ;\n \t}\n \tres += this.brr[ i ] ;\n }\n print( res ) ;\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function toi(x){return parseInt(x);}\n(function(){\n var n=+readline();\n var a=readline().split(\" \").map(toi);\n var res=a.map(function(x){ return 1+a.filter(function(y){return y>x;}).length});\n print(res.join(\" \"));\n})();\n"}, {"source_code": "var n = parseInt(readline(), 10);\nvar a = readline().split(' ').map(Number);\n\nvar b = [];\n\nfor (var i = 0; i < a.length; i++) {\n\tb.push([a[i], i + 1]);\n}\n\nb.sort(function(x, y) {\n\treturn (x[0] - y[0]);\n});\n\nb.reverse();\n\nvar ans = [];\n\nfor (var i = 0; i < b.length; i++) {\n\tif (i == 0) {\n\t\tans[b[i][1]] = i + 1;\n\t} else {\n\t\tif (b[i][0] === b[i-1][0]) {\n\t\t\tans[b[i][1]] = ans[b[i-1][1]];\n\t\t} else {\n\t\t\tans[b[i][1]] = i + 1;\n\t\t}\n\t}\n}\n\nprint(ans.join(' '));\n"}, {"source_code": "n = readline();\nstr = readline().split(' ').map(Number);\n\nvar arr = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar count = 0;\n\n\tfor (var j = 0; j < n; j++) {\n\t\tif (str[j] > str[i]) {\n\t\t\tcount++;\n\t\t};\n\t};\n\n\tarr.push(count + 1);\n};\n\nprint(arr.join(' '));"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1, a2) => a2 - a1)\n let map = new Map()\n\n for (let i = 0; i < n; i++) {\n if (!map.has(clone[i])) {\n map.set(clone[i], i + 1)\n }\n }\n\n let result = ''\n for (let i = 0; i < n; i++) {\n result += map.get(a[i]) + ' '\n }\n\n console.log(result.substring(0, result.length))\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n const arr = readLine().split(' ').map((item, i, a) => new List(parseInt(item, 10), i));\n\n const result = gukiZAndContest(n, arr);\n printResult(result);\n}\n\nfunction List(value, pos) {\n this.value = value;\n this.pos = pos;\n}\n\nfunction compare(a, b) {\n if (a.value < b.value) return 1;\n if (a.value > b.value) return -1;\n return 0;\n}\n\nconst gukiZAndContest = (n, a) => {\n a.sort(compare);\n\n const result = new Array(n);\n let ranking = 1;\n result[a[0].pos] = ranking;\n for (let i = 0; i < n - 1; i++) {\n if (a[i].value > a[i + 1].value) ranking = i + 2;\n result[a[i + 1].pos] = ranking;\n }\n\n return result.join(' ');\n};"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const ans = [];\n\n for (let i = 0; i < arr.length; i++) {\n let counter = 1;\n for (let j = 0; j < arr.length; j++) {\n if (arr[i] < arr[j]) {\n counter++;\n }\n }\n ans.push(counter);\n }\n\n console.log(ans.join(' '));\n c++;\n});\n"}], "negative_code": [], "src_uid": "a5edbf422616cdac35e95a4f07efc7fd"} {"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(1);\n\tvar List = __webpack_require__(2);\n\tvar _a = List.map(parseInt, readline().split(' ')), n = _a[0], k = _a[1];\n\tvar a = List.map(parseInt, readline().split(' '));\n\tvar count = List.replicate(101, 0);\n\tfor (var i = 0; i < a.length; i++) {\n\t count[a[i]]++;\n\t}\n\tfunction enhance(ten, digit, delta) {\n\t var skills = count[ten + digit];\n\t if (skills == 0 || k < delta)\n\t return;\n\t var points = Math.floor(k / delta);\n\t var chosen = Prelude_1.min(skills, points);\n\t count[ten + digit] -= chosen;\n\t count[ten + 10] += chosen;\n\t k -= chosen * delta;\n\t}\n\tfor (var digit = 9; digit > 0; digit--) {\n\t var delta = 10 - digit;\n\t for (var x = 0; x <= 90 && k >= delta; x += 10) {\n\t enhance(x, digit, delta);\n\t }\n\t}\n\tfor (var x = 0; x <= 90; x += 10) {\n\t enhance(x, 0, 10);\n\t}\n\tvar result = 0;\n\tfor (var x = 0; x <= 100; x++) {\n\t result += count[x] * Math.floor(x / 10);\n\t}\n\tprint(result);\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(1);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction maximum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximum = maximum;\n\tfunction minimum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimum = minimum;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\n\n/***/ }\n/******/ ]);", "positive_code": [{"source_code": "function quickSort(low, high) {\n var i = low; \n var j = high;\n var middle = data_help[ Math.round(( low + high ) / 2) ]; // middle - \u043e\u043f\u043e\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442; \u0432 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043c\u0435\u0436\u0434\u0443 low \u0438 high\n \n do {\n while(data_help[i] > middle)\n {\n ++i; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n } \n while(data_help[j] < middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n\n\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data[i]=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i= (10 - b[i].mod) ) {\n\t\tvar add = Math.min((10 - b[i].mod)%10, k);\n\t\t//write(\"add = \" + add + \"\\n\");\n\t\ta[b[i].i] += add;\n\t\tk -= add;\n\t}\n}\n\na.sort();\nfor (var i = 0; i < n; i++) {\n\tif (a[i] < 100 && k > 0) {\n\t\tvar add = Math.min(100 - a[i],k);\n\t\ta[i] += add;\n\t\tk -= add;\n\t}\n}\n\nanswer = 0;\nfor (var i = 0; i < n; i++) {\n\tanswer += Math.floor(a[i]/10);\n}\n\nwrite(answer);\n\n\n//write(\"b[i].mod = \" + b[i].mod + \"\\n\");\n\n"}], "negative_code": [{"source_code": "function quickSort(low, high) {\n var i = low; \n var j = high;\n var middle = data_help[ Math.round(( low + high ) / 2) ]; // middle - \u043e\u043f\u043e\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442; \u0432 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043c\u0435\u0436\u0434\u0443 low \u0438 high\n \n do {\n while(data_help[i] < middle)\n {\n ++i; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n } \n while(data_help[j] > middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i0){\n for(i=0;i=100){\n sum+=Math.round(data[i]/10);\n data.splice(i,1);\n n--;\n i--;\n continue;\n }\n var help=Math.round((1-data_help[i])*10);\n if(k>=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n k=0;\n break;\n }\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=Math.round(data[i]/10);\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n ++i; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n } \n while(data_help[j] < middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n\n\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\nfor(i=0;i0){\n for(i=0;i=100){\n data.splice(i,1);\n n--;\n i--;\n continue;\n }\n var help=Math.round((1-data_help[i])*10);\n if(k>=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n k=0;\n break;\n }\n }\n}\nvar sum=0;\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\ndata.length=n;\nfor(i=0;i0){\n for(i=0;i=100){\n data.splice(i,1);\n n--;\n i--;\n continue;\n }\n var help=Math.round((1-data_help[i])*10);\n if(k>=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n k=0;\n break;\n }\n }\n}\nvar sum=0;\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\ndata.length=n;\ndata_help.length=n;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else \n break;\n}\nvar sum=0;\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=Math.floor(data[i]/10);\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]==100){\n sum+=Math.round(data[i]/10);\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=100){\n sum+=Math.round(data[i]/10);\n data.splice(i,1);\n n--;\n i--;\n continue;\n }\n var help=Math.round((1-data_help[i])*10);\n if(k>=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=10;\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(i, high);\n } \n }\n//40 108\n//20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66\n\nvar input=readline().split(' ');\n//var input=['40','108'];\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\n//input=['20','100' ,'99' ,'50' ,'8','78' ,'44' ,'67' ,'91', '75', '93', '53', '96' ,'81', '96', '86', '81', '0', '58', '9', '51', '63', '70', '73', '80', '79', '28', '82', '4', '15' ,'60' ,'74', '19', '17', '54', '81' ,'11', '67', '71', '66'];\nvar data=[];\nvar data_help=[];\nvar sum=0;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n data_help[i]=0;\n k=k-help;\n if(data[i]>=100){\n sum+=Math.floor(data[i]/10);\n data.splice(i,1);\n data_help.splice(i,1);\n n--;\n i--;\n }\n }\n else {\n break;\n }\n}\nfor(i=0;i=help){\n data=(data[i]+help);\n k=k-help;\n }\n else {\n data[i]+=k;\n break;\n }\n}\nfor(i=0;i middle)\n {\n --j; // \u0438\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n }\n if(i <= j){ \n // \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n var temp = data_help[i];\n data_help[i] = data_help[j];\n data_help[j] = temp;\n\n var temp2=data[i];\n data[i]=data[j];\n data[j]=temp2;\n // \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\n i++; j--;\n }\n } \n while(i < j);\n \n if(low < j){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort(data_help, low, j);\n } \n\n if(i < high){\n // \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n quickSort( i, high);\n } \n }\nvar input=readline().split(' ');\nvar n=parseInt(input[0]);\nvar k=parseInt(input[1]);\ninput=readline().split(' ');\nvar data=[];\nvar data_help=[];\ndata.length=n;\ndata_help.length=n;\nfor(i=0;i=help){\n data[i]=data[i]+help;\n k=k-help;\n }\n else {\n k=0;\n break;\n }\n}\n}\nvar sum=0;\nfor(i=0;i= (10 - b[i].mod) ) {\n\t\tvar add = Math.min(10-b[i].mod, k);\n\t\ta[b[i].i] += add;\n\t\tk -= add;\n\t}\n}\n\na.sort();\nfor (var i = 0; i < n; i++) {\n\tif (a[i] < 100 && k > 0) {\n\t\tvar add = Math.min(100 - a[i],k);\n\t\ta[i] += add;\n\t\tk -= add;\n\t}\n}\n\nanswer = 0;\nfor (var i = 0; i < n; i++) {\n\tanswer += Math.floor(a[i]/10);\n}\n\nwrite(answer);\n\n\n//write(\"b[i].mod = \" + b[i].mod + \"\\n\");\n\n"}], "src_uid": "b4341e1b0ec0b7341fdbe6edfe81a0d4"} {"source_code": "\r\nconst memo = [];\r\n\r\n\r\nconst trace = (arr, index) => {\r\n\tif (index >= arr.length) {\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tif (memo[index] !== undefined) {\r\n\t\treturn memo[index];\r\n\t}\r\n\r\n\tif (arr[index] === '1') {\r\n\t\tconst res = trace(arr, index*2+1);\r\n\t\tmemo[index] = res;\r\n\t\treturn res;\r\n\t}\r\n\r\n\tif (arr[index] === '0') {\r\n\t\tconst res = trace(arr, index*2+2);\r\n\t\tmemo[index] = res;\r\n\t\treturn res;\r\n\t}\r\n\r\n\tconst res = trace(arr, index*2+1) +\r\n\t\ttrace(arr, index*2+2);\r\n\r\n\tmemo[index] = res;\r\n\treturn res;\r\n}\r\n\r\nconst traceTop = (index) => {\r\n\tif (index < 0)\r\n\t\treturn;\r\n\r\n\tmemo[index] = undefined;\r\n\r\n\tif (index%2 === 0) {\r\n\t\treturn traceTop((index - 2)/2);\r\n\t}\r\n\r\n\treturn traceTop((index-1)/2);\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [, s, qCount, ...queries] = input.trim().split('\\n');\r\n\r\n\tconst line = s.trim().split('').reverse();\r\n\r\n\tfor (let i=0; i x.split(' '))\n console.log(solve(str, updates));\n l += n\n }\n});\n\nlet C2TMAP // ch index -> tree index\nlet T2CMAP\nfunction solve(str, updates) {\n const chs = str.split('')\n const nodes = []\n createTree(nodes, chs)\n return updates.map(([i, ch]) => {\n const idx = +i - 1\n chs[idx] = ch\n updateTree(nodes, chs, idx)\n return nodes[0].v\n }).join('\\n')\n}\n\n// 0123 45 6\n// -> 6 45 0123\nfunction createIndexMap(total) {\n T2CMAP = {}\n C2TMAP = {}\n\n let step = 2\n let chIdx = 0\n while (step <= total) {\n const limit = total / step // count of each level\n let treeIdx = limit - 1\n for (let i = 0; i < limit; i++) {\n T2CMAP[treeIdx] = chIdx\n C2TMAP[chIdx] = treeIdx\n chIdx++\n treeIdx++\n }\n step *= 2\n }\n}\n\nfunction createTree(nodes, chs) {\n const total = chs.length + 1\n createIndexMap(total)\n\n let step = total\n let l, r, limit\n while (step >= 1) {\n l = 0\n limit = total / step\n for (let i = 0; i < limit; i++) {\n r = l + step - 1\n const node = {\n l, \n r,\n v: 1,\n i: nodes.length\n }\n nodes[node.i] = node\n\n l = r + 1\n }\n step /= 2\n }\n\n // init v\n for (let i = 0; i < chs.length; i++) {\n const node = nodes[C2TMAP[i]]\n node.v = getMerge(nodes, chs, node)\n }\n}\n\nfunction updateTree(nodes, chs, idx) {\n let node = nodes[C2TMAP[idx]]\n while (1) {\n node.v = getMerge(nodes, chs, node)\n if (node.i === 0) break\n node = nodes[Math.floor((node.i - 1) / 2)]\n }\n}\n\nfunction getMerge(nodes, chs, node) {\n const ch = chs[T2CMAP[node.i]]\n const left = nodes[node.i * 2 + 1]\n const right = nodes[node.i * 2 + 2]\n if (ch === '0') {\n return left.v\n } else if (ch === '1') {\n return right.v\n } else {\n return left.v + right.v\n }\n}\n"}], "negative_code": [{"source_code": "\r\nconst trace = (arr, index) => {\r\n\tif (index > arr.length) {\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tif (arr[index] === '1') {\r\n\t\treturn trace(arr, index*2+1);\r\n\t}\r\n\r\n\tif (arr[index] === '0') {\r\n\t\treturn trace(arr, index*2+2);\r\n\t}\r\n\r\n\treturn trace(arr, index*2+1) +\r\n\t\ttrace(arr, index*2+2);\r\n}\r\n\r\n\r\nconst solve = (str) => {\r\n\tconst reverse = [...str].reverse();\r\n\r\n\treturn trace(reverse, 0);\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [, s, qCount, ...queries] = input.trim().split('\\n');\r\n\r\n\tconst line = s.trim().split('');\r\n\r\n\tfor (let i=0; i {\r\n\tif (index > arr.length) {\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tif (arr[index] === '1') {\r\n\t\treturn trace(arr, index*2+1);\r\n\t}\r\n\r\n\tif (arr[index] === '0') {\r\n\t\treturn trace(arr, index*2+2);\r\n\t}\r\n\r\n\treturn trace(arr, index*2+1) +\r\n\t\ttrace(arr, index*2+2);\r\n}\r\n\r\n\r\nconst solve = (str) => {\r\n\tconst reverse = [...str].reverse();\r\n\r\n\treturn trace(reverse, 0);\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [k, s, qCount, ...queries] = input.trim().split('\\n');\r\n\r\n\tconst line = s.split('');\r\n\r\n\tfor (let i=0; i x.split(' '))\n console.log(solve(str, updates));\n l += n\n }\n});\n \nfunction solve(str, updates) {\n const chs = str.split('')\n return updates.map(([i, ch]) => {\n chs[+i - 1] = ch\n return cal(chs)\n }).join('\\n')\n}\n\nfunction cal(chs) {\n let base = chs.length + 1\n let count = Array(base).fill(1)\n let next = []\n let pos = 0\n while (base > 1) {\n base /= 2\n for (let i = 0; i < base; i++) {\n const ch = chs[pos++]\n if (ch === '0') {\n next.push(count[i])\n } else if (ch === '1') {\n next.push(count[i + 1])\n } else {\n next.push(count[i] + count[i + 1])\n }\n }\n // console.log(next)\n count = next\n next = []\n }\n return count[0]\n}\n"}], "src_uid": "0eee4b8f074e02311329d5728138c7fe"} {"source_code": "function main()\n{\n var N = parseInt( readline() );\n var numbers = readline().split(' ').map( function(item, index, array){ return parseInt(item); } );\n numbers.sort( function(a, b) { return a - b; } );\n\n if ( N == 1 )\n {\n print(-1);\n }\n else if ( N == 2 )\n {\n if ( numbers[0] == numbers[1] )\n {\n print(1);\n print( numbers[0] );\n }\n else\n {\n var ans = [];\n var diff = numbers[1] - numbers[0];\n ans.push( numbers[0] - diff );\n if ( diff % 2 == 0 ) ans.push( (numbers[0] + numbers[1]) / 2 );\n ans.push( numbers[1] + diff );\n print( ans.length );\n print( ans.join(' ') );\n }\n }\n else\n {\n var gaps = [];\n for (var i = 1; i < N; i++) gaps.push( numbers[i] - numbers[i-1] );\n gaps.sort(function(a, b){ return a - b; });\n gaps = gaps.filter( function(item, index, array){ return (index==0 || item != array[index-1]); } );\n\n var ans = [];\n if ( gaps.length == 1 )\n {\n ans.push( numbers[0] - gaps[0] );\n if ( gaps[0] != 0 ) ans.push( numbers[numbers.length - 1] + gaps[0] )\n }\n else if ( gaps.length == 2 && 2*gaps[0] == gaps[1] )\n {\n var Count = 0;\n for (var i = 1; i < N; i++) if( numbers[i] - numbers[i-1] == gaps[1] )\n {\n ans.push( (numbers[i] + numbers[i-1]) / 2 );\n }\n if ( ans.length > 1 ) ans = [];\n }\n \n print( ans.length );\n print( ans.join(' ') );\n }\n}\n\nmain();\n", "positive_code": [{"source_code": "\nvar n = +readline();\nvar a = readline().split(' ').map(function(v){\n\treturn +v;\n});\n\na.sort(function(a,b){ return a===b?0:a>b?1:-1; });\n\nif(n===1){\n\tprint(-1);\n}else{\n\tvar k = {};\n\tfor(var i=1; ib){\n\t\treturn 1;\n\t}else{\n\t\treturn -1;\n\t}\n});\nif(n==1){\n\tprint(-1);\n}else if(_flg){\n\tprint(0);\n}else{\n\nvar arr = [];\nfor(var i=1;ib?1:-1; });\n\nif(n===1){\n\tprint(-1);\n}else{\n\tvar k = {};\n\tfor(var i=1; ib){\n\t\treturn 1;\n\t}else{\n\t\treturn -1;\n\t}\n});\nif(n==1){\n\tprint(-1);\n}else if(_flg>1){\n\tif(num.length==_flg){\n\t\tprint(1);\n\t\tprint(num[0]);\n\t}else{\n\t\tprint(0);\t\n\t}\n}else{\n\nvar arr = [];\nfor(var i=1;i2 ){\n\tprint(0);\n}else if(k.length===2){\n\tif(k[0]*2==k[1]||k[1]*2==k[0]){\n\t\tvar ret=[];\n\t\tvar g = Math.min(+k[0], +k[1]);\n\t\tfor(var i=0;ib){\n\t\treturn 1;\n\t}else{\n\t\treturn -1;\n\t}\n});\nif(n==1){\n\tprint(-1);\n}else if(_flg){\n\tif(num.length==2){\n\t\tprint(1);\n\t\tprint(num[0]);\n\t}else{\n\t\tprint(0);\t\n\t}\n}else{\n\nvar arr = [];\nfor(var i=1;i2 ){\n\tprint(0);\n}else if(k.length===2){\n\tif(k[0]*2==k[1]||k[1]*2==k[0]){\n\t\tvar ret=[];\n\t\tvar g = Math.min(+k[0], +k[1]);\n\t\tfor(var i=0;ib?1:-1; });\n\nif(n===1){\n\tprint(-1);\n}else{\n\tvar k = {};\n\tfor(var i=1; ib){\n\t\treturn 1;\n\t}else{\n\t\treturn -1;\n\t}\n});\nif(n==1){\n\tprint(-1);\n}else if(_flg){\n\tprint(0);\n}else{\n\nvar arr = [];\nfor(var i=1;ib){\n\t\treturn 1;\n\t}else{\n\t\treturn -1;\n\t}\n});\nif(n==1){\n\tprint(-1);\n}else if(_flg){\n\tprint(0);\n}else{\n\nvar arr = [];\nfor(var i=1;i2 ){\n\tprint(0);\n}else if(k.length===2){\n\tif(k[0]*2==k[1]||k[1]*2==k[0]){\n\t\tvar ret=[];\n\t\tvar g = Math.min(+k[0], +k[1]);\n\t\tfor(var i=0;i 1 ) ans = [];\n }\n \n print( ans.length );\n print( ans.join(' ') );\n }\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar cardNum = integers[0];\n\tvar cards = tokenizeIntegers(readline());\n\tcards.sort(function(a, b) { return a-b; });\n\n\tif (cardNum == 1) {\n\t\tprint(-1);\n\t}\n\telse if (cardNum == 2) {\n\t\tvar a = cards[0], b = cards[1];\n\t\tif (a == b) {\n\t\t\tprint(1);\n\t\t\tprint(a);\n\t\t}\n\t\telse if ((b-a)%2 == 1) {\n\t\t\tprint(2);\n\t\t\tprint(a-(b-a), b+(b-a));\n\t\t}\n\t\telse {\n\t\t\tprint(3);\n\t\t\tprint(a-(b-a), (a+b)/2, b+(b-a));\n\t\t}\n\t}\n\telse {\n\t\tvar gaps = [];\n\t\tfor (var i = 1; i < cardNum; i += 1) {\n\t\t\tgaps.push(cards[i]-cards[i-1]);\n\t\t}\n\n\t\tgaps.sort(function(a, b) { return a-b; });\n\t\tvar small = gaps[0], big = gaps[gaps.length-1];\n\n\t\tif (small == big) {\n\t\t\tif (small == 0) {\n\t\t\t\tprint(1);\n\t\t\t\tprint(cards[0]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tprint(2);\n\t\t\t\tprint(cards[0]-small, cards[cardNum-1]+small);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (gaps[gaps.length-2] != small) {\n\t\t\t\tprint(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (var i = 1; i < cardNum; i += 1) {\n\t\t\t\tif (cards[i]-cards[i-1] == big) {\n\t\t\t\t\tprint(1);\n\t\t\t\t\tprint(cards[i-1]+small);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar cardNum = integers[0];\n\tvar cards = tokenizeIntegers(readline());\n\tcards.sort(function(a, b) { return a-b; });\n\n\tif (cardNum == 1) {\n\t\tprint(-1);\n\t}\n\telse if (cardNum == 2) {\n\t\tvar a = cards[0], b = cards[1];\n\t\tif (a == b) {\n\t\t\tprint(1);\n\t\t\tprint(a);\n\t\t}\n\t\telse if ((b-a)%2 == 1) {\n\t\t\tprint(2);\n\t\t\tprint(a-(b-a), b+(b-a));\n\t\t}\n\t\telse {\n\t\t\tprint(3);\n\t\t\tprint(a-(b-a), (a+b)/2, b+(b-a));\n\t\t}\n\t}\n\telse {\n\t\tvar gaps = [];\n\t\tfor (var i = 1; i < cardNum; i += 1) {\n\t\t\tgaps.push(cards[i]-cards[i-1]);\n\t\t}\n\n\t\tgaps.sort(function(a, b) { return a-b; });\n\t\tvar small = gaps[0], big = gaps[gaps.length-1];\n\n\t\tif (small == big) {\n\t\t\tif (small == 0) {\n\t\t\t\tprint(1);\n\t\t\t\tprint(cards[0]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tprint(2);\n\t\t\t\tprint(cards[0]-small, cards[cardNum-1]+small);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (gaps[gaps.length-2] != small) {\n\t\t\t\tprint(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (2*small != big) {\n\t\t\t\tprint(0);\n\t\t\t}\n\t\t\tfor (var i = 1; i < cardNum; i += 1) {\n\t\t\t\tif (cards[i]-cards[i-1] == big) {\n\t\t\t\t\tprint(1);\n\t\t\t\t\tprint(cards[i-1]+small);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}\n\nmain();\n"}], "src_uid": "e3ca8338beb8852c201be72650e9aabd"} {"source_code": "function main() {\n var n = Number(readline());\n var a = readline()\n .split(' ')\n .map(l => Number(l));\n var sum = [a[0]];\n\n for (var i = 1; i < a.length; i++) {\n sum[i] = sum[i - 1] + a[i];\n }\n\n var equator = sum[sum.length - 1] / 2;\n\n for (var i = 0; i < sum.length; i++) {\n if (sum[i] >= equator) {\n return print(i + 1);\n }\n }\n}\n\nmain();\n", "positive_code": [{"source_code": "n=Number(readline());a=readline().split(' ').map(Number);\ne=a.reduce((r, i) => r + i, 0)/2;i=0;\nwhile (e > 0) e -= a[i++];\nprint(i);\n"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = row[0];\n\nvar a = [];\nvar total = 0;\nrow = readline().split(\" \").map(function(x) { return parseInt(x); });\nfor(var i = 0; i < n; i++) {\n\ta.push(row[i]);\n\ttotal += parseInt(row[i]);\n}\n\nvar current = 0;\nfor(var i = 0; i < n; i++) {\n current += a[i];\n\tif(total / current <= 2) {\n\t write(i + 1);\n\t break;\n\t}\n}"}, {"source_code": "var a = parseInt(readline());\nvar b = readline().split(' ').map(function (i) { return parseInt(i); });\nvar c = b.reduce((a, b) => a + b);\nvar d = c / 2;\nvar e = 0;\nfor (var i = 0; i < b.length; i++) {\n e = e + b[i];\n if (e >= d) break;\n}\nprint(i + 1);"}, {"source_code": "function main() {\n var n = readline();\n var a = readline().split(' ').map(l => Number(l));\n \n var sum = 0;\n for(var i = 0; i < n; i++)\n sum += a[i];\n \n var cnt = 0;\n for(var i = 0; i < n; i++) {\n cnt += a[i];\n \n if(2 * cnt >= sum)\n return print(i + 1), 0;\n }\n \n return 0;\n}\n\nmain();"}], "negative_code": [{"source_code": "var a = readline();\nvar b = readline();\nprint(a);"}, {"source_code": "function main() {\n var n = Number(readline());\n var a = readline()\n .split(' ')\n .map(l => Number(l));\n var sum = [a[0]];\n\n for (var i = 1; i < a.length; i++) {\n sum[i] = sum[i - 1] + a[i];\n }\n\n var equator = sum[sum.length - 1] / 2;\n\n for (var i = 1; i < sum.length; i++) {\n if (sum[i] >= equator) {\n return print(i + 1);\n }\n }\n}\n\nmain();\n"}, {"source_code": "function main() {\n var n = Number(readline());\n var a = readline()\n .split(' ')\n .map(l => Number(l));\n var sum = [a[0]];\n\n for (var i = 1; i < a.length; i++) {\n sum[i] = sum[i - 1] + a[i];\n }\n\n var closest = sum[0];\n var closestIndex = 0;\n\n for (var i = 1; i < sum.length; i++) {\n var iClose = Math.abs(sum[i] - sum[sum.length - 1] / 2);\n if (iClose < closest) {\n closest = iClose;\n closestIndex = i;\n }\n }\n\n print(closestIndex + 1);\n}\n\nmain();\n"}], "src_uid": "241157c465fe5dd96acd514010904321"} {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tc: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[i - 1][0] > AB[i][0] || AB[i - 1][1] > AB[i][1]) {\r\n results.push(\"-1\");\r\n continue tc;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var b = readline().split(' ').map((x) => parseInt(x));\r\n var as = [...a]\r\n var bs = [...b]\r\n as.sort(function(x,y) { return x-y })\r\n bs.sort(function(x,y) { return x-y })\r\n // var rev_a = reverse(as);\r\n // var rev_b = reverse(bs);\r\n // function reverse(arr) {\r\n // var v = [];\r\n // for(var j=arr.length-1;j>=0;j--) v.push(arr[j]);\r\n // return v;\r\n // }\r\n //console.log(a, as, rev_a);\r\n var ans = [];\r\n var flag = true;\r\n for(var i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(sa, sb) {\n const moves = []\n const sorted = sa.map((x, i) => ({ x, i }))\n // .sort((a, b) => a.x - b.x)\n sort(sorted, 0, sorted.length - 1, sa, moves)\n// console.log(sorted)\n //\n let p = {}, pi = -1\n sorted.forEach((x, i) => {\n if (x.x === p.x) {\n //\n } else {\n // [pi, i - 1]\n if (pi >= 0) {\n // console.log(pi, i - 1)\n sort(sorted, pi, i - 1, sb, moves)\n }\n p = x\n pi = i\n }\n })\n// console.log(pi, sa.length - 1)\n sort(sorted, pi, sa.length - 1, sb, moves)\n const after = sorted.map(o => sb[o.i])\n// console.log(after)\n for (let i = 1; i < after.length; i++) {\n if (after[i - 1] > after[i]) return -1\n }\n if (!moves.length) return 0\n return moves.length + '\\n' + moves.join('\\n')\n}\nfunction sort(arr, first, last, old, moves) {\n let swap\n for (let i = first; i <= last; i++) {\n swap = 0\n for (let j = first + 1; j <= last; j++) {\n if (old[arr[j - 1].i] > old[arr[j].i]) {\n [arr[j - 1], arr[j]] = [arr[j], arr[j - 1]]\n moves.push([j - 1 + 1, j + 1].join(' '))\n swap = 1\n }\n }\n if (!swap) break\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a, b) {\r\n let nums = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n nums[i] = [a[i], b[i], i];\r\n }\r\n let flag = true;\r\n nums.sort((a, b) => {\r\n if (a[0] === b[0]) {\r\n return a[1] - b[1];\r\n } else if (a[1] === b[1]) {\r\n return a[0] - b[0];\r\n } else {\r\n const x = a[0] - b[0],\r\n y = a[1] - b[1];\r\n if (x * y < 0) {\r\n flag = false;\r\n }\r\n return a[0] - b[0];\r\n }\r\n });\r\n if (!flag) return -1;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (nums[i][2] !== i) {\r\n add(i, nums[i][2]);\r\n }\r\n }\r\n let res = [],\r\n st = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n if (st[i]) continue;\r\n if (h[i] !== -1) {\r\n const queue = [i];\r\n for (let u of queue) {\r\n st[u] = 1;\r\n for (let k = h[u]; k !== -1; k = ne[k]) {\r\n const v = e[k];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n }\r\n }\r\n let cur = i;\r\n for (let j = 1; j < queue.length; j++) {\r\n res.push([cur, queue[j]]);\r\n cur = queue[j];\r\n }\r\n }\r\n }\r\n if (res.length === 0) return '0';\r\n return `${res.length}\\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\\n')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr1 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr2 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = [];\r\n const sort = (arr, arr1) => {\r\n for (let i = 0; i < n; i++) {\r\n let min = i;\r\n for (let j = i + 1; j < n; j++) {\r\n if (arr[min] > arr[j]) min = j;\r\n }\r\n if (min === i) continue;\r\n res.push(`${min + 1} ${i + 1}`);\r\n [arr[i], arr[min]] = [arr[min], arr[i]];\r\n [arr1[i], arr1[min]] = [arr1[min], arr1[i]];\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr1[i - 1] > arr1[i]) return false;\r\n }\r\n return true;\r\n };\r\n const print = () => {\r\n console.log(res.length);\r\n if (res.length === 0) return;\r\n for (let i = 0; i < res.length; i++) console.log(res[i]);\r\n };\r\n if (sort(arr1, arr2)) {\r\n print();\r\n continue;\r\n }\r\n if (sort(arr2, arr1)) {\r\n print();\r\n continue;\r\n }\r\n console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let P = [];\n for (let i=0; i{\n swaps.push((i+1)+' '+(j+1));\n let tmp = A[i];\n A[i] = A[j];\n A[j] = tmp;\n tmp = B[i];\n B[i] = B[j];\n B[j] = tmp;\n };\n for (let i=0; iB[j+1]){\n swap(j, j+1);\n }\n } else {\n if (A[j]B[j+1])\n return void print(-1);\n } else {\n if (B[j] lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let b = ra();\n\n let moves = [];\n\n for (let i = 0; i < n; i++) {\n let minidx = i;\n let j = i + 1;\n for (; j < n; j++) {\n if (a[j] < a[minidx]) {\n minidx = j;\n }\n }\n if (minidx === i) continue;\n j = minidx;\n moves.push(`${i + 1} ${j + 1}`);\n\n let tmpa = a[i];\n a[i] = a[j];\n a[j] = tmpa;\n\n let tmpb = b[i];\n b[i] = b[j];\n b[j] = tmpb;\n }\n\n for (let l = 0; l < n - 1; l++) {\n let r = l + 1;\n while (r < n && a[l] === a[r]) {\n r++;\n }\n\n for (let i = l; i < r; i++) {\n let minidx = i;\n let j = i + 1\n for (; j < r; j++) {\n if (b[j] < b[minidx]) {\n minidx = j;\n }\n }\n if (minidx === i) continue;\n j = minidx;\n moves.push(`${i + 1} ${j + 1}`);\n\n let tmpb = b[i];\n b[i] = b[j];\n b[j] = tmpb;\n }\n\n }\n\n if (moves.length > 10000) return '-1';\n\n for (let i = 1; i < n; i++) {\n if (b[i] < b[i - 1]) return '-1';\n }\n\n let result = `${moves.length}`;\n if (moves.length > 0) {\n result += '\\n';\n result += moves.join('\\n');\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(\"-1\");\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n // for (let i = 0; i < N; i++) {\r\n // for (let j = i + 1; j < N; j++) {\r\n // if (A[i] > A[j] || B[i] > B[j]) {\r\n // [A[i], A[j]] = [A[j], A[i]];\r\n // [B[i], B[j]] = [B[j], B[i]];\r\n // ops.push([j + 1, i + 1].join(\" \"));\r\n // }\r\n // }\r\n // }\r\n for (let i = 1; i < N; i++) {\r\n for (let j = 1; j < N; j++) {\r\n if (A[j - 1] > A[j] || B[j - 1] > B[j]) {\r\n [A[j - 1], A[j]] = [A[j], A[j - 1]];\r\n [B[j - 1], B[j]] = [B[j], B[j - 1]];\r\n ops.push([j, j + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(\"-1\");\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(\"-1\");\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(\"-1\");\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N - 1; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(-1);\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[1][i - 1] > AB[1][i]) {\r\n results.push(-1);\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[1][i - 1] > AB[1][i]) {\r\n results.push(-1);\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([i + 1, j + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n const history = [];\r\n for (let i = 0; i < N; i++) {\r\n let minA = A[i];\r\n let minB = B[i];\r\n let idxA = null;\r\n let idxB = null;\r\n for (let j = i + 1; j < N; j++) {\r\n if (minA > A[j]) {\r\n minA = A[j];\r\n idxA = j;\r\n }\r\n if (minB > B[j]) {\r\n minB = B[j];\r\n idxB = j;\r\n }\r\n }\r\n const idx = idxA || idxB;\r\n if (idx !== null) {\r\n let tmp = A[i];\r\n A[i] = A[idx];\r\n A[idx] = tmp;\r\n tmp = B[i];\r\n B[i] = B[idx];\r\n B[idx] = tmp;\r\n history.push([i + 1, idx + 1]);\r\n }\r\n }\r\n if (\r\n JSON.stringify(A.slice().sort()) === JSON.stringify(A) &&\r\n JSON.stringify(B.slice().sort()) === JSON.stringify(B)\r\n ) {\r\n results.push(history.length);\r\n history.forEach((v) => results.push(v.join(\" \")));\r\n } else {\r\n results.push(-1);\r\n }\r\n\r\n // console.log(history);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr1 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr2 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = [];\r\n const sort = (arr, arr1) => {\r\n for (let i = 0; i < n; i++) {\r\n let min = i;\r\n for (let j = i + 1; j < n; j++) {\r\n if (arr[min] > arr[j]) min = j;\r\n }\r\n if (min === i) continue;\r\n res.push(`${min + 1} ${i + 1}`);\r\n [arr[i], arr[min]] = [arr[min], arr[i]];\r\n [arr1[i], arr1[min]] = [arr1[min], arr1[i]];\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr1[i - 1] > arr1[i]) return false;\r\n }\r\n return true;\r\n };\r\n const print = () => {\r\n console.log(res.length);\r\n if (res.length === 0) return;\r\n for (let i = 0; i < res.length; i++) console.log(res[i]);\r\n };\r\n if (sort(arr1, arr2)) {\r\n print();\r\n continue;\r\n }\r\n res = [];\r\n if (sort(arr2, arr1)) {\r\n print();\r\n continue;\r\n }\r\n console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr1 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr2 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = [];\r\n const sort = (arr, arr1) => {\r\n for (let i = 0; i < n; i++) {\r\n let min = i;\r\n for (let j = i + 1; j < n; j++) {\r\n if (arr[min] > arr[j]) min = j;\r\n }\r\n if (min === i) continue;\r\n res.push(`${min + 1} ${i + 1}`);\r\n [arr[i], arr[min]] = [arr[min], arr[i]];\r\n [arr1[i], arr1[min]] = [arr1[min], arr1[i]];\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr1[i - 1] > arr1[i]) return false;\r\n }\r\n return true;\r\n };\r\n const print = () => {\r\n console.log(res.length);\r\n if (res.length === 0) return;\r\n for (let i = 0; i < res.length; i++) console.log(res[i]);\r\n };\r\n if (sort([...arr1], [...arr2])) {\r\n print();\r\n continue;\r\n }\r\n res = [];\r\n if (sort([...arr2], [...arr1])) {\r\n print();\r\n continue;\r\n }\r\n console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let P = [];\n for (let i=0; i{\n swaps.push((i+1)+' '+(j+1));\n let tmp = A[i];\n A[i] = A[j];\n A[j] = tmp;\n tmp = B[i];\n B[i] = B[j];\n B[j] = tmp;\n };\n for (let i=0; iB[j+1]){\n swap(j, j+1);\n }\n } else {\n if (A[j]B[j+1])\n print(-1);\n } else {\n if (B[j]1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let P = [];\n for (let i=0; i{\n swaps.push((i+1)+' '+(j+1));\n let tmp = A[i];\n A[i] = A[j];\n A[j] = tmp;\n tmp = B[i];\n B[i] = B[j];\n B[j] = tmp;\n };\n for (let i=0; iB[j+1]){\n swap(j, j+1);\n }\n } else {\n if (A[j]B[j+1])\n return -1;\n } else {\n if (B[j] lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let b = ra();\n\n let moves = [];\n\n for (let i = 0; i < n; i++) {\n let minidx = i;\n let j = i + 1;\n for (; j < n; j++) {\n if (a[j] < a[minidx]) {\n minidx = j;\n }\n }\n if (minidx === i) continue;\n j = minidx;\n moves.push(`${i} ${j}`);\n\n let tmpa = a[i];\n a[i] = a[j];\n a[j] = tmpa;\n\n let tmpb = b[i];\n b[i] = b[j];\n b[j] = tmpb;\n }\n\n for (let l = 0; l < n - 1; l++) {\n let r = l + 1;\n while (r < n && a[l] === a[r]) {\n r++;\n }\n\n for (let i = l; i < r; i++) {\n let minidx = i;\n let j = i + 1\n for (; j < r; j++) {\n if (b[j] < b[minidx]) {\n minidx = j;\n }\n }\n if (minidx === i) continue;\n j = minidx;\n moves.push(`${i} ${j}`);\n\n let tmpb = b[i];\n b[i] = b[j];\n b[j] = tmpb;\n }\n\n }\n\n if (moves.length > 10000) return '-1';\n\n for (let i = 1; i < n; i++) {\n if (b[i] < b[i - 1]) return '-1';\n }\n\n let result = `${moves.length}`;\n if (moves.length > 0) {\n result += '\\n';\n result += moves.join('\\n');\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var b = readline().split(' ').map((x) => parseInt(x));\r\n var as = [...a]\r\n var bs = [...b]\r\n as.sort(function(x,y) { return x-y })\r\n bs.sort(function(x,y) { return x-y })\r\n // var rev_a = reverse(as);\r\n // var rev_b = reverse(bs);\r\n // function reverse(arr) {\r\n // var v = [];\r\n // for(var j=arr.length-1;j>=0;j--) v.push(arr[j]);\r\n // return v;\r\n // }\r\n //console.log(a, as, rev_a);\r\n var ans = [];\r\n var flag = true;\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline();\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(input){\r\n let max = 0;\r\n let min = 21;\r\n for(let i = 0; i<3; i++){\r\n max = input[i] > max ? input[i] : max;\r\n min = input[i] < min ? input[i] : min;\r\n }\r\n console.log(\r\n input.filter(x=>x != max && x != min)[0]\r\n )\r\n}", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [a,b,c]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n if(a>b) [a,b]=[b,a];\r\n if(a>c) [a,c]=[c,a];\r\n if(b>c) [b,c]=[c,b];\r\n console.log(b);\r\n }\r\n})"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline().split(\" \").map(w => parseInt(w));\r\n\tn.sort((x,y) => x-y);\r\n\tconsole.log(n[1])\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n //let mod = 10**9+7\r\n loopwhile:\r\n while(t--)\r\n {\r\n \r\n let a_b_c = readLine().trim().split(\" \").map(x=>parseInt(x));\r\n \r\n //console.log(\"a_b_c \" + a_b_c)\r\n let min = Math.min(...a_b_c);\r\n let max = Math.max(...a_b_c);\r\n \r\n \r\n \r\n /*console.log(\"min \" + min)\r\n console.log(\"max \" + max)*/\r\n \r\n let medium = a_b_c.filter(x=>(x!=min)&&(x!=max))[0]\r\n \r\n //console.log(\"medium \" + medium)\r\n \r\n console.log(medium)\r\n } \r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let arr = readline().split(\" \").map(elem => Number(elem));\r\n console.log(findMedium(arr))\r\n }\r\n}\r\n\r\nfunction findMedium(arr) {\r\n arr.sort((a, b) => a - b)\r\n return arr[1]\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n arr.sort((a, b) => a - b)\n return arr[1]\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar list = nextIntArray(3);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tmyout(list[1]);\r\n\t}\r\n}\r\n"}, {"source_code": "t = +readline()\r\n\r\nwhile(t--) {\r\n abc = readline().split(' ').map(value => +value).sort((a, b) => a - b)\r\n print(abc[1])\r\n}"}, {"source_code": "t = +readline()\r\n \r\nwhile(t--) {\r\n abc = readline().split(' ').map(value => +value).sort((a, b) => a - b)\r\n print(abc[1])\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline().split(' ')\r\n\r\n print(ThreeNum(arr[0],arr[1],arr[2]))\r\n \r\n}\r\n \r\nfunction ThreeNum(a,b,c){\r\n a = +a\r\n b = +b\r\n c = +c\r\n \r\n return [a,b,c].sort((a,b) => a-b)[1]\r\n}\r\n"}, {"source_code": "var t = readline();\r\n\r\nfor(tt=0;tt {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline()\r\n \r\n for(let i = 0; iparseInt(x)))\r\n }\r\n}\r\n\r\n\r\nfunction solve(input){\r\n let max = 0;\r\n let min = 21;\r\n for(let i = 0; i<3; i++){\r\n max = input[1] > max ? input[i] : max;\r\n min = input[i] < min ? input[i] : min;\r\n }\r\n console.log(\r\n input.filter(x=>x != max && x != min)[0]\r\n )\r\n}"}, {"source_code": "t = +readline()\r\n\r\nwhile(t--) {\r\n abc = readline().split(' ').map(value => +value).sort()\r\n print(abc[1])\r\n}"}], "src_uid": "63c2142461c93ae4c962eac1ecb5b192"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = -INF;\r\n\t\tfor (let i = n; i > Math.max(0, n-2*k); i--) {\r\n\t\t\tfor (let j = i-1; j > Math.max(0, n-2*k); j--) {\r\n\t\t\t\tconst cur = i*j - k*(a[i]|a[j]);\r\n\t\t\t\tans = Math.max(ans, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const args = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, args))\n }\n// })()\n})\n\nfunction solve(n, k, arr) {\n let max = -Infinity\n const limit = 2 * k + 1\n for (let i = 0; i < limit; i++) {\n for (let j = 0; j < limit; j++) {\n if (i === j) continue\n\n const a = n - 1 - i\n const b = n - 1 - j\n if (a < 0 || b < 0) continue\n const v = (a + 1) * (b + 1) - k * (arr[a] | arr[b])\n // console.log(i, j, v)\n max = Math.max(max, v)\n }\n }\n return max\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = -INF;\r\n\t\tfor (let i = n; i >= Math.max(1, n-k-5); i--) {\r\n\t\t\tfor (let j = i-1; j >= Math.max(1, n-k-5); j--) {\r\n\t\t\t\tconst cur = i*j - k*(a[i]|a[j]);\r\n\t\t\t\tans = Math.max(ans, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = -INF;\r\n\t\tfor (let i = n; i >= Math.max(1, n-k); i--) {\r\n\t\t\tfor (let j = i-1; j >= Math.max(1, n-k); j--) {\r\n\t\t\t\tconst cur = i*j - k*(a[i]|a[j]);\r\n\t\t\t\tans = Math.max(ans, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = -INF;\r\n\t\tfor (let i = n; i >= Math.max(1, n-k-5); i--) {\r\n\t\t\tfor (let j = i-1; j >- Math.max(1, n-k-5); j--) {\r\n\t\t\t\tconst cur = i*j - k*(a[i]|a[j]);\r\n\t\t\t\tans = Math.max(ans, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = -INF;\r\n\t\tfor (let i = n; i > n-k; i--) {\r\n\t\t\tfor (let j = i-1; j > n-k; j--) {\r\n\t\t\t\tconst cur = i*j - k*(a[i]|a[j]);\r\n\t\t\t\tans = Math.max(ans, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "3a45b6acdcf3800d1cb4ef8ac96ed4cf"} {"source_code": "main.apply(0, readNums());\nfunction main(n, m) {\n var max = 0;\n for (var i = 0; i < n; i++) {\n var v = min(readNums());\n if (v > max)\n max = v;\n }\n print(max);\n}\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}\nfunction min(arr) {\n var v = arr[0];\n for (var i = 1; i < arr.length; i++) {\n if (v > arr[i])\n v = arr[i];\n }\n return v;\n}\n", "positive_code": [{"source_code": "function cmp(a,b){return a-b;}\n\ns=readline().split(' ')\nn=+s[0]\nm=+s[1]\nres=0\nwhile(n--)\n{\n a=readline().split(' ')\n a.sort(cmp)\n if (+a[0]>res)\n {\n res=+a[0]\n }\n}\nprint(res)"}], "negative_code": [], "src_uid": "f2142bc2f44e5d8b77f8561c29038a73"} {"source_code": "(function main(){\r\n \r\n var t = readline();\r\n while(t--){\r\n var num = readline();\r\n var word = [];\r\n var obj = {\r\n\r\n }\r\n for(var i=0;i<3;i++){\r\n word[i] = readline().split(' ');\r\n for(var j=0;j {\r\n var res = 0;\r\n for(var k in ob1){\r\n if(!ob2[k] && !ob3[k]) res += 3;\r\n else if (!ob2[k] || !ob3[k] ) res += 1;\r\n }\r\n \r\n return res;\r\n};\r\n\r\nvar toObj = (r) => {\r\n var obj = {}\r\n for(var i = 0; i < r.length; i++){\r\n obj[r[i]] = true\r\n }\r\n return obj\r\n}\r\n\r\nwhile(t--){\r\n var n = parseInt(readline());\r\n var r1 = readline().split(\" \");\r\n var r2 = readline().split(\" \");\r\n var r3 = readline().split(\" \");\r\n \r\n var ob1 = toObj(r1);\r\n var ob2 = toObj(r2);\r\n var ob3 = toObj(r3);\r\n \r\n \r\n var res1 = calc(ob1, ob2, ob3);\r\n var res2 = calc(ob2, ob1, ob3);\r\n var res3 = calc(ob3, ob2, ob1);\r\n \r\n print(res1 + \" \" + res2 + \" \" + res3);\r\n \r\n \r\n}"}, {"source_code": "var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++) {\r\n var caseLength = parseInt(readline());\r\n var firstArray = readline().split(\" \");\r\n var secondArray = readline().split(\" \");\r\n var thirdArray = readline().split(\" \");\r\n var firstMap = new Map();\r\n var secondMap = new Map();\r\n var thirdMap = new Map();\r\n for (var j = 0; j < caseLength; j++) {\r\n firstMap.set(firstArray[j], 1);\r\n secondMap.set(secondArray[j], 1);\r\n thirdMap.set(thirdArray[j], 1);\r\n }\r\n var firstTotal = 0;\r\n var secondTotal = 0;\r\n var thridTotal = 0;\r\n for (var j = 0; j < caseLength; j++) {\r\n if (!secondMap.has(firstArray[j]) && !thirdMap.has(firstArray[j])) {\r\n firstTotal += 3;\r\n }\r\n else if ((!secondMap.has(firstArray[j]) && thirdMap.has(firstArray[j])) ||\r\n (secondMap.has(firstArray[j]) && !thirdMap.has(firstArray[j]))) {\r\n firstTotal++;\r\n }\r\n if (!firstMap.has(secondArray[j]) && !thirdMap.has(secondArray[j])) {\r\n secondTotal += 3;\r\n }\r\n else if ((!firstMap.has(secondArray[j]) && thirdMap.has(secondArray[j])) ||\r\n (firstMap.has(secondArray[j]) && !thirdMap.has(secondArray[j]))) {\r\n secondTotal++;\r\n }\r\n if (!firstMap.has(thirdArray[j]) && !secondMap.has(thirdArray[j])) {\r\n thridTotal += 3;\r\n }\r\n else if ((firstMap.has(thirdArray[j]) && !secondMap.has(thirdArray[j])) ||\r\n (!firstMap.has(thirdArray[j]) && secondMap.has(thirdArray[j]))) {\r\n thridTotal++;\r\n }\r\n }\r\n print(\"\".concat(firstTotal, \" \").concat(secondTotal, \" \").concat(thridTotal));\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var pl1 = readline().split(' ');\r\n var pl2 = readline().split(' ');\r\n var pl3 = readline().split(' ');\r\n\r\n var ans = [];\r\n\r\n var arr = pl1.concat(pl2).concat(pl3);\r\n var map = new Map();\r\n\r\n for (var i = 0; i < 3 * n; i++) {\r\n var mapEl = map.get(arr[i]);\r\n if (!mapEl) {\r\n map.set(arr[i], 1);\r\n } else {\r\n map.set(arr[i], mapEl + 1);\r\n }\r\n }\r\n\r\n var counter = pl => {\r\n var count = 0; \r\n\r\n for (var i = 0; i < n; i++) {\r\n if (map.get(pl[i]) === 1) {\r\n count += 3;\r\n } else if (map.get(pl[i]) === 2) {\r\n count += 1;\r\n }\r\n }\r\n\r\n return count;\r\n }\r\n\r\n ans.push(counter(pl1));\r\n ans.push(counter(pl2));\r\n ans.push(counter(pl3));\r\n\r\n print(ans.join(' '));\r\n}\r\n"}, {"source_code": "var n, a;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t {\r\n i = 0;\r\n return () => {\r\n return lines[i++]\r\n }\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\nrl.on('close', () => {\r\n const readLine = createReadLine();\r\n let t = parseInt(readLine())\r\n while (t--) {\r\n let words = {}\r\n let n = readLine()\r\n for (let i = 0; i < 3; i++){\r\n let playerWords = readLine().split(' ')\r\n for (const word of playerWords) {\r\n if (words[word]) {\r\n words[word].push(i)\r\n } else {\r\n words[word] = [i]\r\n }\r\n }\r\n }\r\n\r\n let result = {\r\n 0: 0,\r\n 1: 0,\r\n 2: 0,\r\n };\r\n\r\n for (const word in words) {\r\n if (words.hasOwnProperty(word)) {\r\n if (words[word].length === 1) {\r\n result[words[word][0]] += 3\r\n } else if (words[word].length === 2) {\r\n result[words[word][0]] += 1\r\n result[words[word][1]] += 1\r\n }\r\n }\r\n }\r\n\r\n console.log(result['0'], result['1'], result['2'])\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let a = readline().split(' ');\r\n let b = readline().split(' ');\r\n let c = readline().split(' ');\r\n\r\n let arr = [...a, ...b, ...c];\r\n\r\n let freq = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n if (freq[arr[i]]) {\r\n freq[arr[i]]++;\r\n } else {\r\n freq[arr[i]] = 1;\r\n }\r\n }\r\n\r\n const val = word => {\r\n if (freq[word] === 1) {\r\n return 3;\r\n } else if (freq[word] === 2) {\r\n return 1;\r\n } else if (freq[word] === 3) {\r\n return 0;\r\n }\r\n };\r\n\r\n let sa = a.reduce((acc, curr) => acc + val(curr), 0);\r\n let sb = b.reduce((acc, curr) => acc + val(curr), 0);\r\n let sc = c.reduce((acc, curr) => acc + val(curr), 0);\r\n\r\n output(`${sa} ${sb} ${sc}`);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numberOfTest = Number.parseInt(readline());\n for(let i=0; i {\n if(frqncy[word]){\n frqncy[word] = frqncy[word]+1\n } else {\n frqncy[word]= 1;\n }\n });\n s2Words.forEach(word => {\n if(frqncy[word]){\n frqncy[word] = frqncy[word]+1\n } else {\n frqncy[word]= 1;\n }\n });\n s3Words.forEach(word => {\n if(frqncy[word]){\n frqncy[word] = frqncy[word]+1\n } else {\n frqncy[word]= 1;\n }\n });\n const s1Count = s1Words.reduce((acc, curr)=> {\n if(frqncy[curr] == 2){\n acc += 1\n }else if(frqncy[curr] == 1){\n acc += 3\n }\n return acc;\n }, 0);\n const s2Count = s2Words.reduce((acc, curr)=> {\n if(frqncy[curr] == 2){\n acc += 1\n }else if(frqncy[curr] == 1){\n acc += 3\n }\n return acc;\n }, 0);\n\n const s3Count = s3Words.reduce((acc, curr)=> {\n if(frqncy[curr] == 2){\n acc += 1\n }else if(frqncy[curr] == 1){\n acc += 3\n }\n return acc;\n }, 0);\n console.log(`${s1Count} ${s2Count} ${s3Count}`);\n}"}, {"source_code": "let readline = require(\"readline\");\r\nconst { start } = require(\"repl\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 4 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n //console.log(input[1 + 1].split(\" \"));\r\n\r\n for (let i = 1; i < input.length; i += 4) {\r\n let words1 = input[i + 1].split(\" \");\r\n let words2 = input[i + 2].split(\" \");\r\n let words3 = input[i + 3].split(\" \");\r\n\r\n let words1Map = {};\r\n let words2Map = {};\r\n let words3Map = {};\r\n\r\n for (const word of words1) {\r\n words1Map[word] = true;\r\n }\r\n\r\n for (const word of words2) {\r\n words2Map[word] = true;\r\n }\r\n for (const word of words3) {\r\n words3Map[word] = true;\r\n }\r\n\r\n let score1 = 0;\r\n let score2 = 0;\r\n let score3 = 0;\r\n\r\n for (const word of words1) {\r\n if (words2Map[word] && words3Map[word]) continue;\r\n else if (words2Map[word] || words3Map[word]) score1++;\r\n else score1 += 3;\r\n }\r\n\r\n for (const word of words2) {\r\n if (words1Map[word] && words3Map[word]) continue;\r\n else if (words1Map[word] || words3Map[word]) score2++;\r\n else score2 += 3;\r\n }\r\n\r\n for (const word of words3) {\r\n if (words1Map[word] && words2Map[word]) continue;\r\n else if (words1Map[word] || words2Map[word]) score3++;\r\n else score3 += 3;\r\n }\r\n\r\n console.log(`${score1} ${score2} ${score3}`);\r\n }\r\n};\r\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst LowerBound = (arr, val) =>\r\n{\r\n let ng = -1;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] >= val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\nconst ReverseLowerBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] <= val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d val\r\n return ng;\r\n}\r\n\r\n\r\nconst ReverseUpperBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] < val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 val\r\n return ng;\r\n}\r\n\r\nconst UpperBound = (arr, val) =>\r\n{\r\n let ok = arr.length;\r\n let ng = -1;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] > val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let map1 = new Map();\r\n let map2 = new Map();\r\n let map3 = new Map();\r\n\r\n let n = +sc.L();\r\n let l1 = sc.L().split(' ');\r\n let l2 = sc.L().split(' ');\r\n let l3 = sc.L().split(' ');\r\n let map = new Map();\r\n\r\n for (let s of l1)\r\n {\r\n map1.set(s, 1);\r\n\r\n if (map.has(s))\r\n {\r\n map.set(s, map.get(s) + 1);\r\n }\r\n else map.set(s, 1);\r\n }\r\n\r\n for (let s of l2)\r\n {\r\n map2.set(s, 2);\r\n\r\n if (map.has(s))\r\n {\r\n map.set(s, map.get(s) + 1);\r\n }\r\n else map.set(s, 1);\r\n }\r\n\r\n for (let s of l3)\r\n {\r\n map3.set(s, 3);\r\n\r\n if (map.has(s))\r\n {\r\n map.set(s, map.get(s) + 1);\r\n }\r\n else map.set(s, 1);\r\n }\r\n\r\n let one = 0, two = 0, three = 0;\r\n for (let [key, value] of map)\r\n {\r\n let c = 0;\r\n\r\n if (map1.has(key))\r\n {\r\n ++c;\r\n }\r\n\r\n if (map2.has(key)) ++c;\r\n\r\n if (map3.has(key)) ++c;\r\n\r\n if (c === 2)\r\n {\r\n if (map1.has(key)) ++one;\r\n if (map2.has(key)) ++two;\r\n if (map3.has(key)) ++three;\r\n }\r\n else if (c === 1)\r\n {\r\n if (map1.has(key)) one += 3;\r\n if (map2.has(key)) two += 3;\r\n if (map3.has(key)) three += 3;\r\n }\r\n }\r\n\r\n console.log(`${one} ${two} ${three}`);\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = +sc.L();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar map = {};\r\n\t\tvar one = nextStrArray(N);\r\n\t\tvar two = nextStrArray(N);\r\n\t\tvar three = nextStrArray(N);\r\n\t\tvar oneP = 0;\r\n\t\tvar twoP = 0;\r\n\t\tvar threeP = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(map[one[i]] == null){\r\n\t\t\t\tmap[one[i]] = 0;\r\n\t\t\t}\r\n\t\t\tmap[one[i]]++;\r\n\t\t\tif(map[two[i]] == null){\r\n\t\t\t\tmap[two[i]] = 0;\r\n\t\t\t}\r\n\t\t\tmap[two[i]]++;\r\n\t\t\tif(map[three[i]] == null){\r\n\t\t\t\tmap[three[i]] = 0;\r\n\t\t\t}\r\n\t\t\tmap[three[i]]++;\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(map[one[i]] == 1){\r\n\t\t\t\toneP += 3;\r\n\t\t\t}else if(map[one[i]] == 2){\r\n\t\t\t\toneP++;\r\n\t\t\t}\r\n\t\t\tif(map[two[i]] == 1){\r\n\t\t\t\ttwoP += 3;\r\n\t\t\t}else if(map[two[i]] == 2){\r\n\t\t\t\ttwoP++;\r\n\t\t\t}\r\n\t\t\tif(map[three[i]] == 1){\r\n\t\t\t\tthreeP += 3;\r\n\t\t\t}else if(map[three[i]] == 2){\r\n\t\t\t\tthreeP++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(oneP + \" \" + twoP + \" \" + threeP);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + 3).map(str => str.trim().split(' '))\n l += 3\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n const s = arr[i][j]\n map[s] = (map[s] || 0) + 1\n }\n }\n // return [n, arr]\n // console.log(map)\n return arr.map(x => {\n let p = 0\n for (let i = 0; i < x.length; i++) {\n const s = x[i]\n if (map[s] === 1) {\n p += 3\n } else if (map[s] === 2) {\n p += 1\n }\n }\n return p\n }).join(' ')\n}\n"}], "negative_code": [], "src_uid": "f8a89510fefbbc8e5698efe8a0c30927"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n var res = solveMeFirst(b, c);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(n, arr) {\r\n arr = arr.split(\" \");\r\n arr[arr.length - 1] = arr[arr.length - 1].replace(\"\\r\", \"\");\r\n arr.sort((a, b) => +a - +b);\r\n if (arr.length > 1) {\r\n if (\r\n +arr[arr.length - 1] - +arr[arr.length - 2] == 1 ||\r\n +arr[arr.length - 1] - +arr[arr.length - 2] == 0\r\n ) {\r\n return \"YES\";\r\n } else {\r\n return \"NO\";\r\n }\r\n } else {\r\n if (+arr[0] == 1) return \"YES\";\r\n else return \"NO\";\r\n }\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n const t = parseInt(readLine());\r\n const arr = readLine().split(\" \").map(i => parseInt(i)).sort((a, b) => a - b);\r\n let last = arr[arr.length - 1]\r\n if (t == 1 && last > 1) return \"NO\";\r\n if (t == 1 && last == 1) return \"YES\";\r\n if ((last - arr[arr.length - 2]) > 1) return \"NO\"\r\n return \"YES\";\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (arr, n)=>{\n arr.sort((a, b)=>b-a);\n if (n==1)\n return arr[0]==1;\n return arr[0]-arr[1]<2;\n for (let i=0; iarr[i+1]+1)\n return false;\n arr[i+1] = 0;\n }\n return true;\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let a = ra();\n print(calc(a, n) ? 'yes' : 'no')\n }\n}\n\nE.calc = calc;"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n a = readline().split(' ').sort((a,b)=>{return(a - b)}).reverse();\r\n if(n == 1 && a[0] > 1){\r\n print(\"NO\");\r\n }\r\n else if(a[0] - a[1] > 1){\r\n print('NO');\r\n }\r\n else{\r\n print('YES');\r\n }\r\n }\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(' ').map(x=>parseInt(x));\r\n var ans = 'YES';\r\n if (n == 1) {\r\n if (a[0] != 1) {\r\n ans = 'NO'\r\n }\r\n } else {\r\n var max = Math.max(...a);\r\n a.splice(a.indexOf(max), 1);\r\n var second = Math.max(...a);\r\n if (max - second > 1) {\r\n ans = 'NO'\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n var c = readline().split(' ').map(Number);\r\n c.sort((a,b) => b - a);\r\n \r\n if (c[0] - c[1] <= 1 || c[0] === 1) print('YES');\r\n else { \r\n print('NO');\r\n }\r\n}\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});\n if(i % 2 == 1){\n e = k[0]; \n }else{\n console.log(k[0] - k[1] < 2 || e == 1 && k[0] == 1? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n arr.sort((a, b) => b - a);\r\n \r\n if (arr.length === 1 && arr[0] > 1) {\r\n output('NO');\r\n } else if (arr[0] - 1 > arr[1]) {\r\n output('NO');\r\n } else {\r\n output('YES');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar max = list[0];\r\n\t\tif(N == 1){\r\n\t\t\tif(max > 1){\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tvar nx = list[1];\r\n\t\t\tif(max > nx + 1){\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n\tlet t = parseInt(readLine());\n\twhile(t--){\n\t\tlet n = parseInt(readLine());\n\t\tlet ans = true;\n\t\tconst arr = readLine().split(' ');\n\t\tif(n == 1){\n\t\t\tif(parseInt(arr[0]) > 1)console.log(\"NO\");\n\t\t\telse console.log(\"YES\");\n\t\t\tcontinue;\n\t\t}\n\t\tarr.sort(function(a, b){return b - a});\n\t\tif(arr[0] - 1 > arr[1])ans = false;\n\t\tconsole.log((ans? \"YES\" : \"NO\"));\n\t}\n\t\t\n}\n\n"}, {"source_code": "process.stdin.resume();process.stdin.setEncoding('utf-8');let inputString = '';let currentLine = 0;process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(string => { return string.trim(); }); main(); }); function readLine() { return inputString[currentLine++]; }\n\nfunction main() {\n const N = readLine();\n for (let i = 0; i < N; i++) {\n const n = Number(readLine());\n const arr = readLine().split(' ').map(Number);\n arr.sort((x, y) => x - y);\n if (n === 1) {\n console.log(arr[0] === 1 ? 'YES' : 'NO');\n } else {\n console.log(arr[arr.length - 1] - arr[arr.length - 2] >=2 ? 'NO' : 'YES');\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let arr = readLine().split(\" \").map(Number);\n arr.sort((a, b) => a - b);\n\n if (n == 1) {\n if (arr[0] > 1) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n } else {\n if (arr[n - 2] + 1 < arr[n - 1]) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nlet stepeni = [1, 2]\r\nlet stepen = function (n) {\r\n if (stepeni[n]) return stepeni[n];\r\n let l = stepeni.length - 1;\r\n while (l < n) {\r\n stepeni.push(2 * stepeni[l++]);\r\n }\r\n return stepeni[n];\r\n}\r\n\r\nlet parser = e=>parseInt(e);\r\nlet sorter = (a,b)=>a-b;\r\n\r\nfunction main() {\r\n let k = parseInt(readLine());\r\n for(let i = 0; i0){\r\n let br = niz.pop();\r\n if(preth-br>sme){\r\n flag = false;\r\n break;\r\n }\r\n sme+=br;\r\n preth = br;\r\n }\r\n }\r\n console.log(flag?\"YES\":\"NO\");\r\n }\r\n}"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst n = Number(inputs[0])\r\n\r\nmain(n, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n next: for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].trim().split(' ').map(Number)\r\n\r\n data.sort((a, b) => b - a)\r\n if ((data.length === 1 && data[0] > 1) || data[0] > data[1] + 1) {\r\n res.push('NO')\r\n } else {\r\n res.push('YES')\r\n }\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n if (n === 1) return arr[0] <= 1\n\n arr.sort((a, b) => b - a)\n return arr[0] - arr[1] <= 1\n}\n"}], "negative_code": [{"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});\n if(i % 2 == 1){\n e = k[0]; \n }else{\n console.log(k[0] - k[1] < 2 || e == k[0] ? 'YES' : 'NO');\n }\n }\n});"}], "src_uid": "8b926a19f380a56018308668c17c6928"} {"source_code": "function query(l, r, x, lx, rx) {\n if (lx >= r || rx <= l) return 0;\n if (lx >= l && rx <= r) return tree[x];\n var m = (lx + rx) / 2;\n var left = query(l, r, 2 * x + 1, lx, m),\n right = query(l, r, 2 * x + 2, m, rx);\n return Math.max(left, right);\n}\n\nvar l = readline().split(\" \");\nvar m = parseInt(l[0]);\nvar n = parseInt(l[1]);\n\nvar arr = readline().split(\" \");\nfor (var i = 0; i < n; i++) {\n arr[i] = parseInt(arr[i]);\n}\n\nvar N = 1;\nwhile (N < arr.length) N *= 2;\ntree = new Array(N * 2);\nfor (var i = 0; i < arr.length; i++) {\n tree[N - 1 + i] = arr[i];\n}\nfor (var i = N - 2; i >= 0; i--) {\n var left = tree[2 * i + 1],\n right = tree[2 * i + 2];\n tree[i] = Math.max(left, right);\n}\n\nvar q = parseInt(readline(), 10);\nwhile (q--) {\n l = readline().split(\" \");\n for (var i = 0; i < l.length; i++) l[i] = parseInt(l[i]);\n var xs = --l[0],\n ys = --l[1],\n xf = --l[2],\n yf = --l[3],\n k = l[4];\n xs = m - xs - 1;\n xf = m - xf - 1;\n if (ys > yf) {\n var temp = ys;\n ys = yf;\n yf = temp;\n temp = xs;\n xs = xf;\n xf = temp;\n }\n if ((xf - xs) % k !== 0 || (yf - ys) % k !== 0) {\n print(\"NO\");\n } else {\n var x = xs % k;\n if (x < m - query(ys, yf, 0, 0, N)) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}\n", "positive_code": [{"source_code": "function query(l, r, x, lx, rx) {\n if (lx >= r || rx <= l) return 0;\n if (lx >= l && rx <= r) return tree[x];\n var m = (lx + rx) / 2;\n var left = query(l, r, 2 * x + 1, lx, m),\n right = query(l, r, 2 * x + 2, m, rx);\n return Math.max(left, right);\n}\n\nvar l = readline().split(\" \");\nvar m = parseInt(l[0]);\nvar n = parseInt(l[1]);\n\nvar arr = readline().split(\" \");\nfor (var i = 0; i < n; i++) {\n arr[i] = parseInt(arr[i]);\n}\n\nvar N = 1;\nwhile (N < arr.length) N *= 2;\ntree = new Array(N * 2);\nfor (var i = 0; i < arr.length; i++) {\n tree[N - 1 + i] = arr[i];\n}\nfor (var i = N - 2; i >= 0; i--) {\n var left = tree[2 * i + 1],\n right = tree[2 * i + 2];\n tree[i] = Math.max(left, right);\n}\n\nvar q = parseInt(readline(), 10);\nwhile (q--) {\n l = readline().split(\" \");\n for (var i = 0; i < l.length; i++) l[i] = parseInt(l[i]);\n var xs = --l[0],\n ys = --l[1],\n xf = --l[2],\n yf = --l[3],\n k = l[4];\n xs = m - xs - 1;\n xf = m - xf - 1;\n if (ys > yf) {\n var temp = ys;\n ys = yf;\n yf = temp;\n temp = xs;\n xs = xf;\n xf = temp;\n }\n if ((xf - xs) % k !== 0 || (yf - ys) % k !== 0) {\n print(\"NO\\n\");\n } else {\n var x = xs % k;\n if (x < m - query(ys, yf, 0, 0, N)) {\n print(\"YES\\n\");\n } else {\n print(\"NO\\n\");\n }\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, q, a, b) {\r\n const segTree = new SegTree(m);\r\n for (let i = 0; i < m; i++) {\r\n segTree.update(i, a[i]);\r\n }\r\n let res = new Array(q);\r\n for (let i = 0; i < q; i++) {\r\n let [x1, y1, x2, y2, k] = b[i];\r\n if (Math.abs(x2 - x1) % k !== 0 || Math.abs(y2 - y1) % k !== 0) {\r\n res[i] = 'NO';\r\n } else if (y1 === y2) {\r\n res[i] = 'YES';\r\n } else {\r\n let max = 0;\r\n if (y1 > y2) {\r\n max = segTree.query(y2, y1 - 2);\r\n } else {\r\n max = segTree.query(y1, y2 - 2);\r\n }\r\n const cur = Math.floor((n - x1) / k) * k + x1;\r\n if (cur > max) {\r\n res[i] = 'YES';\r\n } else {\r\n res[i] = 'NO';\r\n }\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, z) => {\r\n x = Math.max(x, 0);\r\n x = Math.min(x, n);\r\n this._update(this.root, 0, n, x, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(left = null, right = null) {\r\n return {\r\n max: 0,\r\n left,\r\n right\r\n };\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.max = Math.max(left.max, right.max);\r\n }\r\n _update(node, l, r, x, z) {\r\n if (!node) return;\r\n if (l === r) {\r\n node.max = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (x <= mid) this._update(node.left, l, mid, x, z);else this._update(node.right, mid + 1, r, x, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.max;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.max(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n const k = Number(await read());\r\n let tmp = k;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, k, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [], "src_uid": "19f12c275f2b389ed5a1af66808d1bbd"} {"source_code": "//solve();\n\nfunction solve() {\n var t = Number(readline()), line, p1, p2, s1, res, d, o, z, bs, zs, sign;\n for (;t--;) {\n line = readline().split(' ').map(Number);\n z = '';\n p1 = (line[0] - line[1]);\n if (p1 < 0) {\n z = '-';\n p1 = -p1;\n }\n p2 = (line[2] >> 1);\n s1 = ((line[2] & 1) * line[0]);\n if (!p1 || line[2] === 1) {\n print(s1);\n continue;\n }\n zs = '';\n if (s1 < 0) {\n zs = '-';\n s1 = -s1;\n }\n res = [];\n while (p1) {\n o = p1 % 10;\n res.push(o);\n p1 = (p1 - o) / 10;\n }\n bs = [];\n if (s1) {\n while (s1) {\n o = s1 % 10;\n bs.push(o);\n s1 = (s1 - o) / 10;\n }\n } else {\n bs = [0];\n }\n d = 0;\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] * p2 + d;\n o = res[i] % 10;\n d = (res[i] - o) / 10;\n res[i] = o;\n }\n while (d) {\n o = d % 10;\n res.push(o);\n d = (d - o) / 10;\n }\n if (z === zs) {\n while (res.length < bs.length) {\n res.push(0);\n }\n while (bs.length < res.length) {\n bs.push(0);\n }\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] + bs[i] + d;\n o = res[i] % 10;\n d = (res[i] - o) / 10;\n res[i] = o;\n }\n while (d) {\n o = d % 10;\n res.push(o);\n d = (d - o) / 10;\n }\n } else {\n sign = 0;\n if (res.length < bs.length) {\n sign = -1;\n } else if (res.length > bs.length) {\n sign = 1;\n } else {\n for (i = res.length - 1; i >= 0; --i) {\n if (res[i] < bs[i]) {\n sign = -1;\n break;\n } else if (res[i] > bs[i]) {\n sign = 1;\n break;\n }\n }\n }\n if (!sign) {\n print(0);\n continue\n }\n if (sign === -1) {\n z = zs;\n p1 = res;\n res = bs;\n bs = p1;\n }\n while (bs.length < res.length) {\n bs.push(0);\n }\n for (i = 0; i < res.length; ++i) {\n if (res[i] + d < bs[i]) {\n res[i] = res[i] + d + 10 - bs[i];\n d = -1;\n } else {\n res[i] = res[i] + d - bs[i];\n d = 0;\n }\n }\n while (res[res.length - 1] === 0) {\n res.pop();\n }\n }\n print(z + res.reverse().join(''));\n /*a = line[0];\n b = line[1];\n k = line[2];\n print ('' + a + b + k);\n print((a - b) * (k >> 1) + (k & 1) * a);*/\n }\n}\n\nlet MEMORY = [],\n i = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[i++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n", "positive_code": [{"source_code": "solve();\n\nfunction solve() {\n var t = Number(readline()), line, p1, p2, s1, res, d, o, z, bs, zs, sign;\n for (;t--;) {\n line = readline().split(' ').map(Number);\n z = '';\n p1 = (line[0] - line[1]);\n if (p1 < 0) {\n z = '-';\n p1 = -p1;\n }\n p2 = (line[2] >> 1);\n s1 = ((line[2] & 1) * line[0]);\n if (!p1 || line[2] === 1) {\n print(s1);\n continue;\n }\n zs = '';\n if (s1 < 0) {\n zs = '-';\n s1 = -s1;\n }\n res = [];\n while (p1) {\n o = p1 % 10;\n res.push(o);\n p1 = (p1 - o) / 10;\n }\n bs = [];\n if (s1) {\n while (s1) {\n o = s1 % 10;\n bs.push(o);\n s1 = (s1 - o) / 10;\n }\n } else {\n bs = [0];\n }\n d = 0;\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] * p2 + d;\n o = res[i] % 10;\n d = (res[i] - o) / 10;\n res[i] = o;\n }\n while (d) {\n o = d % 10;\n res.push(o);\n d = (d - o) / 10;\n }\n if (z === zs) {\n while (res.length < bs.length) {\n res.push(0);\n }\n while (bs.length < res.length) {\n bs.push(0);\n }\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] + bs[i] + d;\n o = res[i] % 10;\n d = (res[i] - o) / 10;\n res[i] = o;\n }\n while (d) {\n o = d % 10;\n res.push(o);\n d = (d - o) / 10;\n }\n } else {\n sign = 0;\n if (res.length < bs.length) {\n sign = -1;\n } else if (res.length > bs.length) {\n sign = 1;\n } else {\n for (i = res.length - 1; i >= 0; --i) {\n if (res[i] < bs[i]) {\n sign = -1;\n break;\n } else if (res[i] > bs[i]) {\n sign = 1;\n break;\n }\n }\n }\n if (!sign) {\n print(0);\n continue\n }\n if (sign === -1) {\n z = zs;\n p1 = res;\n res = bs;\n bs = p1;\n }\n while (bs.length < res.length) {\n bs.push(0);\n }\n for (i = 0; i < res.length; ++i) {\n if (res[i] + d < bs[i]) {\n res[i] = res[i] + d + 10 - bs[i];\n d = -1;\n } else {\n res[i] = res[i] + d - bs[i];\n d = 0;\n }\n }\n while (res[res.length - 1] === 0) {\n res.pop();\n }\n }\n print(z + res.reverse().join(''));\n /*a = line[0];\n b = line[1];\n k = line[2];\n print ('' + a + b + k);\n print((a - b) * (k >> 1) + (k & 1) * a);*/\n }\n}"}, {"source_code": "var bigInt = (function (undefined) {\n \"use strict\";\n\n var BASE = 1e7,\n LOG_BASE = 7,\n MAX_INT = 9007199254740992,\n MAX_INT_ARR = smallToArray(MAX_INT),\n LOG_MAX_INT = Math.log(MAX_INT);\n\n function Integer(v, radix) {\n if (typeof v === \"undefined\") return Integer[0];\n if (typeof radix !== \"undefined\") return +radix === 10 ? parseValue(v) : parseBase(v, radix);\n return parseValue(v);\n }\n\n function BigInteger(value, sign) {\n this.value = value;\n this.sign = sign;\n this.isSmall = false;\n }\n BigInteger.prototype = Object.create(Integer.prototype);\n\n function SmallInteger(value) {\n this.value = value;\n this.sign = value < 0;\n this.isSmall = true;\n }\n SmallInteger.prototype = Object.create(Integer.prototype);\n\n function isPrecise(n) {\n return -MAX_INT < n && n < MAX_INT;\n }\n\n function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes\n if (n < 1e7)\n return [n];\n if (n < 1e14)\n return [n % 1e7, Math.floor(n / 1e7)];\n return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];\n }\n\n function arrayToSmall(arr) { // If BASE changes this function may need to change\n trim(arr);\n var length = arr.length;\n if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {\n switch (length) {\n case 0: return 0;\n case 1: return arr[0];\n case 2: return arr[0] + arr[1] * BASE;\n default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;\n }\n }\n return arr;\n }\n\n function trim(v) {\n var i = v.length;\n while (v[--i] === 0);\n v.length = i + 1;\n }\n\n function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger\n var x = new Array(length);\n var i = -1;\n while (++i < length) {\n x[i] = 0;\n }\n return x;\n }\n\n function truncate(n) {\n if (n > 0) return Math.floor(n);\n return Math.ceil(n);\n }\n\n function add(a, b) { // assumes a and b are arrays with a.length >= b.length\n var l_a = a.length,\n l_b = b.length,\n r = new Array(l_a),\n carry = 0,\n base = BASE,\n sum, i;\n for (i = 0; i < l_b; i++) {\n sum = a[i] + b[i] + carry;\n carry = sum >= base ? 1 : 0;\n r[i] = sum - carry * base;\n }\n while (i < l_a) {\n sum = a[i] + carry;\n carry = sum === base ? 1 : 0;\n r[i++] = sum - carry * base;\n }\n if (carry > 0) r.push(carry);\n return r;\n }\n\n function addAny(a, b) {\n if (a.length >= b.length) return add(a, b);\n return add(b, a);\n }\n\n function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT\n var l = a.length,\n r = new Array(l),\n base = BASE,\n sum, i;\n for (i = 0; i < l; i++) {\n sum = a[i] - base + carry;\n carry = Math.floor(sum / base);\n r[i] = sum - carry * base;\n carry += 1;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n BigInteger.prototype.add = function (v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.subtract(n.negate());\n }\n var a = this.value, b = n.value;\n if (n.isSmall) {\n return new BigInteger(addSmall(a, Math.abs(b)), this.sign);\n }\n return new BigInteger(addAny(a, b), this.sign);\n };\n BigInteger.prototype.plus = BigInteger.prototype.add;\n\n SmallInteger.prototype.add = function (v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.subtract(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n if (isPrecise(a + b)) return new SmallInteger(a + b);\n b = smallToArray(Math.abs(b));\n }\n return new BigInteger(addSmall(b, Math.abs(a)), a < 0);\n };\n SmallInteger.prototype.plus = SmallInteger.prototype.add;\n\n function subtract(a, b) { // assumes a and b are arrays with a >= b\n var a_l = a.length,\n b_l = b.length,\n r = new Array(a_l),\n borrow = 0,\n base = BASE,\n i, difference;\n for (i = 0; i < b_l; i++) {\n difference = a[i] - borrow - b[i];\n if (difference < 0) {\n difference += base;\n borrow = 1;\n } else borrow = 0;\n r[i] = difference;\n }\n for (i = b_l; i < a_l; i++) {\n difference = a[i] - borrow;\n if (difference < 0) difference += base;\n else {\n r[i++] = difference;\n break;\n }\n r[i] = difference;\n }\n for (; i < a_l; i++) {\n r[i] = a[i];\n }\n trim(r);\n return r;\n }\n\n function subtractAny(a, b, sign) {\n var value;\n if (compareAbs(a, b) >= 0) {\n value = subtract(a, b);\n } else {\n value = subtract(b, a);\n sign = !sign;\n }\n value = arrayToSmall(value);\n if (typeof value === \"number\") {\n if (sign) value = -value;\n return new SmallInteger(value);\n }\n return new BigInteger(value, sign);\n }\n\n function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT\n var l = a.length,\n r = new Array(l),\n carry = -b,\n base = BASE,\n i, difference;\n for (i = 0; i < l; i++) {\n difference = a[i] + carry;\n carry = Math.floor(difference / base);\n difference %= base;\n r[i] = difference < 0 ? difference + base : difference;\n }\n r = arrayToSmall(r);\n if (typeof r === \"number\") {\n if (sign) r = -r;\n return new SmallInteger(r);\n } return new BigInteger(r, sign);\n }\n\n BigInteger.prototype.subtract = function (v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.add(n.negate());\n }\n var a = this.value, b = n.value;\n if (n.isSmall)\n return subtractSmall(a, Math.abs(b), this.sign);\n return subtractAny(a, b, this.sign);\n };\n BigInteger.prototype.minus = BigInteger.prototype.subtract;\n\n SmallInteger.prototype.subtract = function (v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.add(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n return new SmallInteger(a - b);\n }\n return subtractSmall(b, Math.abs(a), a >= 0);\n };\n SmallInteger.prototype.minus = SmallInteger.prototype.subtract;\n\n BigInteger.prototype.negate = function () {\n return new BigInteger(this.value, !this.sign);\n };\n SmallInteger.prototype.negate = function () {\n var sign = this.sign;\n var small = new SmallInteger(-this.value);\n small.sign = !sign;\n return small;\n };\n\n BigInteger.prototype.abs = function () {\n return new BigInteger(this.value, false);\n };\n SmallInteger.prototype.abs = function () {\n return new SmallInteger(Math.abs(this.value));\n };\n\n function multiplyLong(a, b) {\n var a_l = a.length,\n b_l = b.length,\n l = a_l + b_l,\n r = createArray(l),\n base = BASE,\n product, carry, i, a_i, b_j;\n for (i = 0; i < a_l; ++i) {\n a_i = a[i];\n for (var j = 0; j < b_l; ++j) {\n b_j = b[j];\n product = a_i * b_j + r[i + j];\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n r[i + j + 1] += carry;\n }\n }\n trim(r);\n return r;\n }\n\n function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE\n var l = a.length,\n r = new Array(l),\n base = BASE,\n carry = 0,\n product, i;\n for (i = 0; i < l; i++) {\n product = a[i] * b + carry;\n carry = Math.floor(product / base);\n r[i] = product - carry * base;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n function shiftLeft(x, n) {\n var r = [];\n while (n-- > 0) r.push(0);\n return r.concat(x);\n }\n\n function multiplyKaratsuba(x, y) {\n var n = Math.max(x.length, y.length);\n\n if (n <= 30) return multiplyLong(x, y);\n n = Math.ceil(n / 2);\n\n var b = x.slice(n),\n a = x.slice(0, n),\n d = y.slice(n),\n c = y.slice(0, n);\n\n var ac = multiplyKaratsuba(a, c),\n bd = multiplyKaratsuba(b, d),\n abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));\n\n var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));\n trim(product);\n return product;\n }\n\n // The following function is derived from a surface fit of a graph plotting the performance difference\n // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.\n function useKaratsuba(l1, l2) {\n return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;\n }\n\n BigInteger.prototype.multiply = function (v) {\n var n = parseValue(v),\n a = this.value, b = n.value,\n sign = this.sign !== n.sign,\n abs;\n if (n.isSmall) {\n if (b === 0) return Integer[0];\n if (b === 1) return this;\n if (b === -1) return this.negate();\n abs = Math.abs(b);\n if (abs < BASE) {\n return new BigInteger(multiplySmall(a, abs), sign);\n }\n b = smallToArray(abs);\n }\n if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes\n return new BigInteger(multiplyKaratsuba(a, b), sign);\n return new BigInteger(multiplyLong(a, b), sign);\n };\n\n BigInteger.prototype.times = BigInteger.prototype.multiply;\n\n function multiplySmallAndArray(a, b, sign) { // a >= 0\n if (a < BASE) {\n return new BigInteger(multiplySmall(b, a), sign);\n }\n return new BigInteger(multiplyLong(b, smallToArray(a)), sign);\n }\n SmallInteger.prototype._multiplyBySmall = function (a) {\n if (isPrecise(a.value * this.value)) {\n return new SmallInteger(a.value * this.value);\n }\n return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);\n };\n BigInteger.prototype._multiplyBySmall = function (a) {\n if (a.value === 0) return Integer[0];\n if (a.value === 1) return this;\n if (a.value === -1) return this.negate();\n return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);\n };\n SmallInteger.prototype.multiply = function (v) {\n return parseValue(v)._multiplyBySmall(this);\n };\n SmallInteger.prototype.times = SmallInteger.prototype.multiply;\n\n function square(a) {\n //console.assert(2 * BASE * BASE < MAX_INT);\n var l = a.length,\n r = createArray(l + l),\n base = BASE,\n product, carry, i, a_i, a_j;\n for (i = 0; i < l; i++) {\n a_i = a[i];\n carry = 0 - a_i * a_i;\n for (var j = i; j < l; j++) {\n a_j = a[j];\n product = 2 * (a_i * a_j) + r[i + j] + carry;\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n }\n r[i + l] = carry;\n }\n trim(r);\n return r;\n }\n\n BigInteger.prototype.square = function () {\n return new BigInteger(square(this.value), false);\n };\n\n SmallInteger.prototype.square = function () {\n var value = this.value * this.value;\n if (isPrecise(value)) return new SmallInteger(value);\n return new BigInteger(square(smallToArray(Math.abs(this.value))), false);\n };\n\n function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.\n var a_l = a.length,\n b_l = b.length,\n base = BASE,\n result = createArray(b.length),\n divisorMostSignificantDigit = b[b_l - 1],\n // normalization\n lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),\n remainder = multiplySmall(a, lambda),\n divisor = multiplySmall(b, lambda),\n quotientDigit, shift, carry, borrow, i, l, q;\n if (remainder.length <= a_l) remainder.push(0);\n divisor.push(0);\n divisorMostSignificantDigit = divisor[b_l - 1];\n for (shift = a_l - b_l; shift >= 0; shift--) {\n quotientDigit = base - 1;\n if (remainder[shift + b_l] !== divisorMostSignificantDigit) {\n quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);\n }\n // quotientDigit <= base - 1\n carry = 0;\n borrow = 0;\n l = divisor.length;\n for (i = 0; i < l; i++) {\n carry += quotientDigit * divisor[i];\n q = Math.floor(carry / base);\n borrow += remainder[shift + i] - (carry - q * base);\n carry = q;\n if (borrow < 0) {\n remainder[shift + i] = borrow + base;\n borrow = -1;\n } else {\n remainder[shift + i] = borrow;\n borrow = 0;\n }\n }\n while (borrow !== 0) {\n quotientDigit -= 1;\n carry = 0;\n for (i = 0; i < l; i++) {\n carry += remainder[shift + i] - base + divisor[i];\n if (carry < 0) {\n remainder[shift + i] = carry + base;\n carry = 0;\n } else {\n remainder[shift + i] = carry;\n carry = 1;\n }\n }\n borrow += carry;\n }\n result[shift] = quotientDigit;\n }\n // denormalization\n remainder = divModSmall(remainder, lambda)[0];\n return [arrayToSmall(result), arrayToSmall(remainder)];\n }\n\n function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/\n // Performs faster than divMod1 on larger input sizes.\n var a_l = a.length,\n b_l = b.length,\n result = [],\n part = [],\n base = BASE,\n guess, xlen, highx, highy, check;\n while (a_l) {\n part.unshift(a[--a_l]);\n trim(part);\n if (compareAbs(part, b) < 0) {\n result.push(0);\n continue;\n }\n xlen = part.length;\n highx = part[xlen - 1] * base + part[xlen - 2];\n highy = b[b_l - 1] * base + b[b_l - 2];\n if (xlen > b_l) {\n highx = (highx + 1) * base;\n }\n guess = Math.ceil(highx / highy);\n do {\n check = multiplySmall(b, guess);\n if (compareAbs(check, part) <= 0) break;\n guess--;\n } while (guess);\n result.push(guess);\n part = subtract(part, check);\n }\n result.reverse();\n return [arrayToSmall(result), arrayToSmall(part)];\n }\n\n function divModSmall(value, lambda) {\n var length = value.length,\n quotient = createArray(length),\n base = BASE,\n i, q, remainder, divisor;\n remainder = 0;\n for (i = length - 1; i >= 0; --i) {\n divisor = remainder * base + value[i];\n q = truncate(divisor / lambda);\n remainder = divisor - q * lambda;\n quotient[i] = q | 0;\n }\n return [quotient, remainder | 0];\n }\n\n function divModAny(self, v) {\n var value, n = parseValue(v);\n var a = self.value, b = n.value;\n var quotient;\n if (b === 0) throw new Error(\"Cannot divide by zero\");\n if (self.isSmall) {\n if (n.isSmall) {\n return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];\n }\n return [Integer[0], self];\n }\n if (n.isSmall) {\n if (b === 1) return [self, Integer[0]];\n if (b == -1) return [self.negate(), Integer[0]];\n var abs = Math.abs(b);\n if (abs < BASE) {\n value = divModSmall(a, abs);\n quotient = arrayToSmall(value[0]);\n var remainder = value[1];\n if (self.sign) remainder = -remainder;\n if (typeof quotient === \"number\") {\n if (self.sign !== n.sign) quotient = -quotient;\n return [new SmallInteger(quotient), new SmallInteger(remainder)];\n }\n return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];\n }\n b = smallToArray(abs);\n }\n var comparison = compareAbs(a, b);\n if (comparison === -1) return [Integer[0], self];\n if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];\n\n // divMod1 is faster on smaller input sizes\n if (a.length + b.length <= 200)\n value = divMod1(a, b);\n else value = divMod2(a, b);\n\n quotient = value[0];\n var qSign = self.sign !== n.sign,\n mod = value[1],\n mSign = self.sign;\n if (typeof quotient === \"number\") {\n if (qSign) quotient = -quotient;\n quotient = new SmallInteger(quotient);\n } else quotient = new BigInteger(quotient, qSign);\n if (typeof mod === \"number\") {\n if (mSign) mod = -mod;\n mod = new SmallInteger(mod);\n } else mod = new BigInteger(mod, mSign);\n return [quotient, mod];\n }\n\n BigInteger.prototype.divmod = function (v) {\n var result = divModAny(this, v);\n return {\n quotient: result[0],\n remainder: result[1]\n };\n };\n SmallInteger.prototype.divmod = BigInteger.prototype.divmod;\n\n BigInteger.prototype.divide = function (v) {\n return divModAny(this, v)[0];\n };\n SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;\n\n BigInteger.prototype.mod = function (v) {\n return divModAny(this, v)[1];\n };\n SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;\n\n BigInteger.prototype.pow = function (v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n value, x, y;\n if (b === 0) return Integer[1];\n if (a === 0) return Integer[0];\n if (a === 1) return Integer[1];\n if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.sign) {\n return Integer[0];\n }\n if (!n.isSmall) throw new Error(\"The exponent \" + n.toString() + \" is too large.\");\n if (this.isSmall) {\n if (isPrecise(value = Math.pow(a, b)))\n return new SmallInteger(truncate(value));\n }\n x = this;\n y = Integer[1];\n while (true) {\n if (b & 1 === 1) {\n y = y.times(x);\n --b;\n }\n if (b === 0) break;\n b /= 2;\n x = x.square();\n }\n return y;\n };\n SmallInteger.prototype.pow = BigInteger.prototype.pow;\n\n BigInteger.prototype.modPow = function (exp, mod) {\n exp = parseValue(exp);\n mod = parseValue(mod);\n if (mod.isZero()) throw new Error(\"Cannot take modPow with modulus 0\");\n var r = Integer[1],\n base = this.mod(mod);\n while (exp.isPositive()) {\n if (base.isZero()) return Integer[0];\n if (exp.isOdd()) r = r.multiply(base).mod(mod);\n exp = exp.divide(2);\n base = base.square().mod(mod);\n }\n return r;\n };\n SmallInteger.prototype.modPow = BigInteger.prototype.modPow;\n\n function compareAbs(a, b) {\n if (a.length !== b.length) {\n return a.length > b.length ? 1 : -1;\n }\n for (var i = a.length - 1; i >= 0; i--) {\n if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;\n }\n return 0;\n }\n\n BigInteger.prototype.compareAbs = function (v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) return 1;\n return compareAbs(a, b);\n };\n SmallInteger.prototype.compareAbs = function (v) {\n var n = parseValue(v),\n a = Math.abs(this.value),\n b = n.value;\n if (n.isSmall) {\n b = Math.abs(b);\n return a === b ? 0 : a > b ? 1 : -1;\n }\n return -1;\n };\n\n BigInteger.prototype.compare = function (v) {\n // See discussion about comparison with Infinity:\n // https://github.com/peterolson/BigInteger.js/issues/61\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (this.sign !== n.sign) {\n return n.sign ? 1 : -1;\n }\n if (n.isSmall) {\n return this.sign ? -1 : 1;\n }\n return compareAbs(a, b) * (this.sign ? -1 : 1);\n };\n BigInteger.prototype.compareTo = BigInteger.prototype.compare;\n\n SmallInteger.prototype.compare = function (v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) {\n return a == b ? 0 : a > b ? 1 : -1;\n }\n if (a < 0 !== n.sign) {\n return a < 0 ? -1 : 1;\n }\n return a < 0 ? 1 : -1;\n };\n SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;\n\n BigInteger.prototype.equals = function (v) {\n return this.compare(v) === 0;\n };\n SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;\n\n BigInteger.prototype.notEquals = function (v) {\n return this.compare(v) !== 0;\n };\n SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;\n\n BigInteger.prototype.greater = function (v) {\n return this.compare(v) > 0;\n };\n SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;\n\n BigInteger.prototype.lesser = function (v) {\n return this.compare(v) < 0;\n };\n SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;\n\n BigInteger.prototype.greaterOrEquals = function (v) {\n return this.compare(v) >= 0;\n };\n SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;\n\n BigInteger.prototype.lesserOrEquals = function (v) {\n return this.compare(v) <= 0;\n };\n SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;\n\n BigInteger.prototype.isEven = function () {\n return (this.value[0] & 1) === 0;\n };\n SmallInteger.prototype.isEven = function () {\n return (this.value & 1) === 0;\n };\n\n BigInteger.prototype.isOdd = function () {\n return (this.value[0] & 1) === 1;\n };\n SmallInteger.prototype.isOdd = function () {\n return (this.value & 1) === 1;\n };\n\n BigInteger.prototype.isPositive = function () {\n return !this.sign;\n };\n SmallInteger.prototype.isPositive = function () {\n return this.value > 0;\n };\n\n BigInteger.prototype.isNegative = function () {\n return this.sign;\n };\n SmallInteger.prototype.isNegative = function () {\n return this.value < 0;\n };\n\n BigInteger.prototype.isUnit = function () {\n return false;\n };\n SmallInteger.prototype.isUnit = function () {\n return Math.abs(this.value) === 1;\n };\n\n BigInteger.prototype.isZero = function () {\n return false;\n };\n SmallInteger.prototype.isZero = function () {\n return this.value === 0;\n };\n BigInteger.prototype.isDivisibleBy = function (v) {\n var n = parseValue(v);\n var value = n.value;\n if (value === 0) return false;\n if (value === 1) return true;\n if (value === 2) return this.isEven();\n return this.mod(n).equals(Integer[0]);\n };\n SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;\n\n function isBasicPrime(v) {\n var n = v.abs();\n if (n.isUnit()) return false;\n if (n.equals(2) || n.equals(3) || n.equals(5)) return true;\n if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;\n if (n.lesser(49)) return true;\n // we don't know if it's prime: let the other functions figure it out\n }\n\n function millerRabinTest(n, a) {\n var nPrev = n.prev(),\n b = nPrev,\n r = 0,\n d, t, i, x;\n while (b.isEven()) b = b.divide(2), r++;\n next : for (i = 0; i < a.length; i++) {\n if (n.lesser(a[i])) continue;\n x = bigInt(a[i]).modPow(b, n);\n if (x.equals(Integer[1]) || x.equals(nPrev)) continue;\n for (d = r - 1; d != 0; d--) {\n x = x.square().mod(n);\n if (x.isUnit()) return false;\n if (x.equals(nPrev)) continue next;\n }\n return false;\n }\n return true;\n }\n\n// Set \"strict\" to true to force GRH-supported lower bound of 2*log(N)^2\n BigInteger.prototype.isPrime = function (strict) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var bits = n.bitLength();\n if(bits <= 64)\n return millerRabinTest(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022]);\n var logN = Math.log(2) * bits;\n var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN);\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt(i + 2));\n }\n return millerRabinTest(n, a);\n };\n SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;\n\n BigInteger.prototype.isProbablePrime = function (iterations) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var t = iterations === undefined ? 5 : iterations;\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt.randBetween(2, n.minus(2)));\n }\n return millerRabinTest(n, a);\n };\n SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;\n\n BigInteger.prototype.modInv = function (n) {\n var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;\n while (!newR.equals(bigInt.zero)) {\n q = r.divide(newR);\n lastT = t;\n lastR = r;\n t = newT;\n r = newR;\n newT = lastT.subtract(q.multiply(newT));\n newR = lastR.subtract(q.multiply(newR));\n }\n if (!r.equals(1)) throw new Error(this.toString() + \" and \" + n.toString() + \" are not co-prime\");\n if (t.compare(0) === -1) {\n t = t.add(n);\n }\n if (this.isNegative()) {\n return t.negate();\n }\n return t;\n };\n\n SmallInteger.prototype.modInv = BigInteger.prototype.modInv;\n\n BigInteger.prototype.next = function () {\n var value = this.value;\n if (this.sign) {\n return subtractSmall(value, 1, this.sign);\n }\n return new BigInteger(addSmall(value, 1), this.sign);\n };\n SmallInteger.prototype.next = function () {\n var value = this.value;\n if (value + 1 < MAX_INT) return new SmallInteger(value + 1);\n return new BigInteger(MAX_INT_ARR, false);\n };\n\n BigInteger.prototype.prev = function () {\n var value = this.value;\n if (this.sign) {\n return new BigInteger(addSmall(value, 1), true);\n }\n return subtractSmall(value, 1, this.sign);\n };\n SmallInteger.prototype.prev = function () {\n var value = this.value;\n if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);\n return new BigInteger(MAX_INT_ARR, true);\n };\n\n var powersOfTwo = [1];\n while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);\n var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];\n\n function shift_isSmall(n) {\n return ((typeof n === \"number\" || typeof n === \"string\") && +Math.abs(n) <= BASE) ||\n (n instanceof BigInteger && n.value.length <= 1);\n }\n\n BigInteger.prototype.shiftLeft = function (n) {\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + \" is too large for shifting.\");\n }\n n = +n;\n if (n < 0) return this.shiftRight(-n);\n var result = this;\n if (result.isZero()) return result;\n while (n >= powers2Length) {\n result = result.multiply(highestPower2);\n n -= powers2Length - 1;\n }\n return result.multiply(powersOfTwo[n]);\n };\n SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;\n\n BigInteger.prototype.shiftRight = function (n) {\n var remQuo;\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + \" is too large for shifting.\");\n }\n n = +n;\n if (n < 0) return this.shiftLeft(-n);\n var result = this;\n while (n >= powers2Length) {\n if (result.isZero() || (result.isNegative() && result.isUnit())) return result;\n remQuo = divModAny(result, highestPower2);\n result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n n -= powers2Length - 1;\n }\n remQuo = divModAny(result, powersOfTwo[n]);\n return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n };\n SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;\n\n function bitwise(x, y, fn) {\n y = parseValue(y);\n var xSign = x.isNegative(), ySign = y.isNegative();\n var xRem = xSign ? x.not() : x,\n yRem = ySign ? y.not() : y;\n var xDigit = 0, yDigit = 0;\n var xDivMod = null, yDivMod = null;\n var result = [];\n while (!xRem.isZero() || !yRem.isZero()) {\n xDivMod = divModAny(xRem, highestPower2);\n xDigit = xDivMod[1].toJSNumber();\n if (xSign) {\n xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers\n }\n\n yDivMod = divModAny(yRem, highestPower2);\n yDigit = yDivMod[1].toJSNumber();\n if (ySign) {\n yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers\n }\n\n xRem = xDivMod[0];\n yRem = yDivMod[0];\n result.push(fn(xDigit, yDigit));\n }\n var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);\n for (var i = result.length - 1; i >= 0; i -= 1) {\n sum = sum.multiply(highestPower2).add(bigInt(result[i]));\n }\n return sum;\n }\n\n BigInteger.prototype.not = function () {\n return this.negate().prev();\n };\n SmallInteger.prototype.not = BigInteger.prototype.not;\n\n BigInteger.prototype.and = function (n) {\n return bitwise(this, n, function (a, b) { return a & b; });\n };\n SmallInteger.prototype.and = BigInteger.prototype.and;\n\n BigInteger.prototype.or = function (n) {\n return bitwise(this, n, function (a, b) { return a | b; });\n };\n SmallInteger.prototype.or = BigInteger.prototype.or;\n\n BigInteger.prototype.xor = function (n) {\n return bitwise(this, n, function (a, b) { return a ^ b; });\n };\n SmallInteger.prototype.xor = BigInteger.prototype.xor;\n\n var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;\n function roughLOB(n) { // get lowestOneBit (rough)\n // SmallInteger: return Min(lowestOneBit(n), 1 << 30)\n // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]\n var v = n.value, x = typeof v === \"number\" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI;\n return x & -x;\n }\n\n function integerLogarithm(value, base) {\n if (base.compareTo(value) <= 0) {\n var tmp = integerLogarithm(value, base.square(base));\n var p = tmp.p;\n var e = tmp.e;\n var t = p.multiply(base);\n return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 };\n }\n return { p: bigInt(1), e: 0 };\n }\n\n BigInteger.prototype.bitLength = function () {\n var n = this;\n if (n.compareTo(bigInt(0)) < 0) {\n n = n.negate().subtract(bigInt(1));\n }\n if (n.compareTo(bigInt(0)) === 0) {\n return bigInt(0);\n }\n return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));\n }\n SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;\n\n function max(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.greater(b) ? a : b;\n }\n function min(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.lesser(b) ? a : b;\n }\n function gcd(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n if (a.equals(b)) return a;\n if (a.isZero()) return b;\n if (b.isZero()) return a;\n var c = Integer[1], d, t;\n while (a.isEven() && b.isEven()) {\n d = Math.min(roughLOB(a), roughLOB(b));\n a = a.divide(d);\n b = b.divide(d);\n c = c.multiply(d);\n }\n while (a.isEven()) {\n a = a.divide(roughLOB(a));\n }\n do {\n while (b.isEven()) {\n b = b.divide(roughLOB(b));\n }\n if (a.greater(b)) {\n t = b; b = a; a = t;\n }\n b = b.subtract(a);\n } while (!b.isZero());\n return c.isUnit() ? a : a.multiply(c);\n }\n function lcm(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n return a.divide(gcd(a, b)).multiply(b);\n }\n function randBetween(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n var low = min(a, b), high = max(a, b);\n var range = high.subtract(low).add(1);\n if (range.isSmall) return low.add(Math.floor(Math.random() * range));\n var length = range.value.length - 1;\n var result = [], restricted = true;\n for (var i = length; i >= 0; i--) {\n var top = restricted ? range.value[i] : BASE;\n var digit = truncate(Math.random() * top);\n result.unshift(digit);\n if (digit < top) restricted = false;\n }\n result = arrayToSmall(result);\n return low.add(typeof result === \"number\" ? new SmallInteger(result) : new BigInteger(result, false));\n }\n var parseBase = function (text, base) {\n var length = text.length;\n var i;\n var absBase = Math.abs(base);\n for (var i = 0; i < length; i++) {\n var c = text[i].toLowerCase();\n if (c === \"-\") continue;\n if (/[a-z0-9]/.test(c)) {\n if (/[0-9]/.test(c) && +c >= absBase) {\n if (c === \"1\" && absBase === 1) continue;\n throw new Error(c + \" is not a valid digit in base \" + base + \".\");\n } else if (c.charCodeAt(0) - 87 >= absBase) {\n throw new Error(c + \" is not a valid digit in base \" + base + \".\");\n }\n }\n }\n if (2 <= base && base <= 36) {\n if (length <= LOG_MAX_INT / Math.log(base)) {\n var result = parseInt(text, base);\n if (isNaN(result)) {\n throw new Error(c + \" is not a valid digit in base \" + base + \".\");\n }\n return new SmallInteger(parseInt(text, base));\n }\n }\n base = parseValue(base);\n var digits = [];\n var isNegative = text[0] === \"-\";\n for (i = isNegative ? 1 : 0; i < text.length; i++) {\n var c = text[i].toLowerCase(),\n charCode = c.charCodeAt(0);\n if (48 <= charCode && charCode <= 57) digits.push(parseValue(c));\n else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87));\n else if (c === \"<\") {\n var start = i;\n do { i++; } while (text[i] !== \">\");\n digits.push(parseValue(text.slice(start + 1, i)));\n }\n else throw new Error(c + \" is not a valid character\");\n }\n return parseBaseFromArray(digits, base, isNegative);\n };\n\n function parseBaseFromArray(digits, base, isNegative) {\n var val = Integer[0], pow = Integer[1], i;\n for (i = digits.length - 1; i >= 0; i--) {\n val = val.add(digits[i].times(pow));\n pow = pow.times(base);\n }\n return isNegative ? val.negate() : val;\n }\n\n function stringify(digit) {\n if (digit <= 35) {\n return \"0123456789abcdefghijklmnopqrstuvwxyz\".charAt(digit);\n }\n return \"<\" + digit + \">\";\n }\n\n function toBase(n, base) {\n base = bigInt(base);\n if (base.isZero()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n throw new Error(\"Cannot convert nonzero numbers to base 0.\");\n }\n if (base.equals(-1)) {\n if (n.isZero()) return { value: [0], isNegative: false };\n if (n.isNegative())\n return {\n value: [].concat.apply([], Array.apply(null, Array(-n))\n .map(Array.prototype.valueOf, [1, 0])\n ),\n isNegative: false\n };\n\n var arr = Array.apply(null, Array(+n - 1))\n .map(Array.prototype.valueOf, [0, 1]);\n arr.unshift([1]);\n return {\n value: [].concat.apply([], arr),\n isNegative: false\n };\n }\n\n var neg = false;\n if (n.isNegative() && base.isPositive()) {\n neg = true;\n n = n.abs();\n }\n if (base.equals(1)) {\n if (n.isZero()) return { value: [0], isNegative: false };\n\n return {\n value: Array.apply(null, Array(+n))\n .map(Number.prototype.valueOf, 1),\n isNegative: neg\n };\n }\n var out = [];\n var left = n, divmod;\n while (left.isNegative() || left.compareAbs(base) >= 0) {\n divmod = left.divmod(base);\n left = divmod.quotient;\n var digit = divmod.remainder;\n if (digit.isNegative()) {\n digit = base.minus(digit).abs();\n left = left.next();\n }\n out.push(digit.toJSNumber());\n }\n out.push(left.toJSNumber());\n return { value: out.reverse(), isNegative: neg };\n }\n\n function toBaseString(n, base) {\n var arr = toBase(n, base);\n return (arr.isNegative ? \"-\" : \"\") + arr.value.map(stringify).join('');\n }\n\n BigInteger.prototype.toArray = function (radix) {\n return toBase(this, radix);\n };\n\n SmallInteger.prototype.toArray = function (radix) {\n return toBase(this, radix);\n };\n\n BigInteger.prototype.toString = function (radix) {\n if (radix === undefined) radix = 10;\n if (radix !== 10) return toBaseString(this, radix);\n var v = this.value, l = v.length, str = String(v[--l]), zeros = \"0000000\", digit;\n while (--l >= 0) {\n digit = String(v[l]);\n str += zeros.slice(digit.length) + digit;\n }\n var sign = this.sign ? \"-\" : \"\";\n return sign + str;\n };\n\n SmallInteger.prototype.toString = function (radix) {\n if (radix === undefined) radix = 10;\n if (radix != 10) return toBaseString(this, radix);\n return String(this.value);\n };\n BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); }\n\n BigInteger.prototype.valueOf = function () {\n return parseInt(this.toString(), 10);\n };\n BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;\n\n SmallInteger.prototype.valueOf = function () {\n return this.value;\n };\n SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;\n\n function parseStringValue(v) {\n if (isPrecise(+v)) {\n var x = +v;\n if (x === truncate(x))\n return new SmallInteger(x);\n throw new Error(\"Invalid integer: \" + v);\n }\n var sign = v[0] === \"-\";\n if (sign) v = v.slice(1);\n var split = v.split(/e/i);\n if (split.length > 2) throw new Error(\"Invalid integer: \" + split.join(\"e\"));\n if (split.length === 2) {\n var exp = split[1];\n if (exp[0] === \"+\") exp = exp.slice(1);\n exp = +exp;\n if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error(\"Invalid integer: \" + exp + \" is not a valid exponent.\");\n var text = split[0];\n var decimalPlace = text.indexOf(\".\");\n if (decimalPlace >= 0) {\n exp -= text.length - decimalPlace - 1;\n text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);\n }\n if (exp < 0) throw new Error(\"Cannot include negative exponent part for integers\");\n text += (new Array(exp + 1)).join(\"0\");\n v = text;\n }\n var isValid = /^([0-9][0-9]*)$/.test(v);\n if (!isValid) throw new Error(\"Invalid integer: \" + v);\n var r = [], max = v.length, l = LOG_BASE, min = max - l;\n while (max > 0) {\n r.push(+v.slice(min, max));\n min -= l;\n if (min < 0) min = 0;\n max -= l;\n }\n trim(r);\n return new BigInteger(r, sign);\n }\n\n function parseNumberValue(v) {\n if (isPrecise(v)) {\n if (v !== truncate(v)) throw new Error(v + \" is not an integer.\");\n return new SmallInteger(v);\n }\n return parseStringValue(v.toString());\n }\n\n function parseValue(v) {\n if (typeof v === \"number\") {\n return parseNumberValue(v);\n }\n if (typeof v === \"string\") {\n return parseStringValue(v);\n }\n return v;\n }\n // Pre-define numbers in range [-999,999]\n for (var i = 0; i < 1000; i++) {\n Integer[i] = new SmallInteger(i);\n if (i > 0) Integer[-i] = new SmallInteger(-i);\n }\n // Backwards compatibility\n Integer.one = Integer[1];\n Integer.zero = Integer[0];\n Integer.minusOne = Integer[-1];\n Integer.max = max;\n Integer.min = min;\n Integer.gcd = gcd;\n Integer.lcm = lcm;\n Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };\n Integer.randBetween = randBetween;\n\n Integer.fromArray = function (digits, base, isNegative) {\n return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative);\n };\n\n return Integer;\n})();\n\nif (typeof module !== \"undefined\" && module.hasOwnProperty(\"exports\")) {\n module.exports = bigInt;\n}\nif (typeof define === \"function\" && define.amd) {\n define(\"big-integer\", [], function () {\n return bigInt;\n });\n}\n\nvar cnt = +readline();\nfor(var i = 0; i < cnt; i++) {\n var line = readline().split(' ').map(v=>+v);\n var diff = line[0] - line[1];\n var answer = bigInt(diff).multiply(Math.ceil(line[2] / 2));\n if(line[2] % 2) answer = answer.plus(line[1]);\n print(answer.toString());\n}"}], "negative_code": [{"source_code": "var BigNum = {\n\n plus: function plus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && Math.abs(number1) < BigNum.limit2 &&\n typeof number2 === 'number' && Math.abs(number2) < BigNum.limit2)\n\n return number1 + number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.minus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n return BigNum.minus(ranks2, ranks1, false, false);\n } else {\n result.minus = true;\n }\n\n var maxRank = Math.max(ranks1.length, ranks2.length);\n for (var i = 0; i < maxRank; i++) {\n result[i] = (result[i] || 0)\n + (ranks1[i] || 0)\n + (ranks2[i] || 0);\n\n if (result[i] >= BigNum.limit) {\n result[i + 1] = 1;\n result[i] -= BigNum.limit;\n }\n }\n\n return result;\n },\n\n minus: function minus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 - number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.plus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n result = BigNum.plus(ranks1, ranks2, false, false);\n result.minus = true;\n return result;\n } else {\n return BigNum.minus(ranks2, ranks1, false, false);\n }\n\n var maxRank = Math.max(ranks1.length - 1, ranks2.length - 1);\n for (var i = maxRank; i >= 0; i--) {\n\n result[i] = (ranks1[i] || 0)\n - (ranks2[i] || 0);\n\n if (result[i] < 0) {\n if (result.minus === undefined) {\n result.minus = true;\n result[i] = -result[i];\n\n var swap = ranks1;\n ranks1 = ranks2;\n ranks2 = swap;\n } else {\n var j = i;\n do {\n result[j + 1] -= 1;\n result[j] += BigNum.limit;\n } while (result[++j] < 0);\n }\n } else if (result.minus === undefined && result[i] > 0) {\n result.minus = false;\n }\n }\n\n while(result[result.length - 1] === 0) {\n result.pop();\n }\n if (result.length < 3) {\n return BigNum.toInt(result);\n }\n\n return result;\n },\n\n multiply: function multiply(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit &&\n typeof number2 === 'number' && number2 < BigNum.limit)\n\n return number1 * number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n for (var i = 0; i < ranks1.length; i++) {\n for (var j = 0; j < ranks2.length; j++) {\n var rank = i + j;\n var prod = ranks1[i] * ranks2[j];\n if (prod > BigNum.limit) {\n result[rank] = (result[rank] || 0)\n + prod % BigNum.limit;\n result[rank + 1] = (result[rank + 1] || 0)\n + Math.floor(prod / BigNum.limit);\n } else {\n result[rank] = (result[rank] || 0)\n + prod;\n }\n }\n }\n\n for (i = 0; i < result.length; i++) {\n if (result[i] > BigNum.limit) {\n result[i] -= BigNum.limit;\n result[i + 1] = (result[i + 1] || 0) + 1;\n }\n }\n\n result.minus = (ranks1.minus != ranks2.minus);\n return result;\n },\n\n divide: function divide(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 / number2;\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var result = BigNum.toStr(ranks1) / BigNum.toStr(ranks2);\n return result;\n },\n\n ////////////////////////////////////////////////\n // comparision\n more: function more(number1, number2) {\n return BigNum.compare(number1, number2) > 0;\n },\n\n less: function less(number1, number2) {\n return BigNum.compare(number1, number2) < 0;\n },\n\n equal: function equal(number1, number2) {\n return BigNum.compare(number1, number2) === 0;\n },\n\n max: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.more(number1, number2) ? number1 : number2;\n }\n\n var numberArr = number1;\n var max = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.more(numberArr[i], max)) {\n max = numberArr[i];\n }\n }\n\n return max;\n },\n\n min: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.compare(number1, number2) < 0 ? number1 : number2;\n }\n\n var numberArr = number1;\n var min = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.compare(numberArr[i], min) < 0) {\n min = numberArr[i]\n }\n }\n\n return min;\n },\n\n compare: function compareNumbers(number1, number2) {\n var numberTypes = [typeof number1, typeof number2];\n\n if(numberTypes[0] === numberTypes[1]) {\n if(numberTypes[0] === 'number') {\n return number1 - number2;\n }\n } else {\n if (numberTypes[1] === 'number') {\n if (number1[2]) {\n return 1;\n }\n } else if (numberTypes[0] === 'number') {\n if(number2[2]) {\n return -1;\n }\n }\n }\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var diff;\n\n if(ranks1.minus !== ranks2.minus) {\n return !ranks1.minus > !ranks2.minus ? 1 : -1\n } else if(diff = ranks1.length - ranks2.length) {\n return diff;\n }\n\n for (var i = ranks1.length - 1; i >= 0; i--) {\n if(diff = ranks1[i] - ranks2[i]) {\n return diff;\n }\n }\n\n return 0;\n },\n\n toInt: function (number) {\n if (typeof number === 'object') {\n if(!number.length) return 0;\n else return +BigNum.toStr(number);\n }\n else return +number;\n },\n\n toStr: function (number) {\n\n if (typeof number === 'string') return number;\n else if(typeof number === 'number') return '' + number;\n\n var str = '';\n for (var i = 0; i < number.length - 1; i++) {\n str = ('000000' + number[i]).substr(-7) + str;\n }\n str = number[i] + str;\n return (number.minus ? '-' : '') + str;\n },\n\n getBig: function (number) {\n if (typeof number === 'string') {\n if (number.length < 16) return +number;\n }\n\n return BigNum._getRanks(number);\n },\n\n _getRanks: function (number) {\n\n if (typeof number === 'object') {\n return number;\n } else if (typeof number === 'number') {\n number = '' + number;\n }\n\n var ranks = [];\n if (number[0] === '-') {\n ranks.minus = true;\n number = number.substr(1);\n }\n\n if (number.length > 7) {\n\n number = '' + number;\n for (var i = 7; i <= number.length; i += 7) {\n ranks.push(+number.substr(-i, 7));\n }\n\n var rest = number.length % 7;\n if (rest) {\n ranks.push(+number.substr(0, rest));\n }\n\n } else {\n ranks.push(+number);\n }\n\n if (ranks[ranks.length - 1] < 0) {\n ranks[ranks.length - 1] = -ranks[ranks.length - 1];\n ranks.minus = true;\n }\n\n return ranks;\n },\n\n rand: function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min)) + min;\n },\n\n /*runTests: function tests(count = 10) {\n var correct = 0;\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-999999999999999, 999999999999999);\n var val2 = BigNum.rand(-999999999999999, 999999999999999);\n\n var resBn = BigNum.plus(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = val1 + val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' + ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.minus(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = val1 - val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' - ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.divide(val1, val2);\n resBnInt = Math.round(resBn, 4);\n res = Math.round(val1 / val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' / ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.more(val1, val2);\n res = val1 > val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' > ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.less(val1, val2);\n res = val1 < val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' < ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val2);\n res = val1 === val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val1);\n res = val1 === val1;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val1);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.max(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2);\n\n if(resBnInt !== res) {in\n console.log('!!! min ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var val3 = BigNum.rand(-999999999999999, 999999999999999);\n var resBn = BigNum.max([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! min ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n val1 = BigNum.rand(-99999999, 99999999);\n val2 = BigNum.rand(-9999999, 9999999);\n\n resBn = BigNum.multiply(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = Math.round(val1 * val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' * ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n }\n console.log('correct:' + correct);\n\n\n },*/\n /*runTimeTests: function timeTests(count = 10000, ranks = 15) {\n\n var max = Math.pow(10, ranks);\n\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-max, max);\n var val2 = BigNum.rand(-max, max);\n\n values.push([val1, val2]);\n }\n\n var testF = function (funcs, operation) {\n var results = [];\n for(var f = 0; f < 2; f++) {\n var func = funcs[f];\n var t = performance.now();\n for(var i = 0; i < count; i++) {\n res = func(values[i][0], values[i][1]);\n }\n results[f] = Math.floor(performance.now() - t);\n }\n\n console.log('test ' + operation + ': diff ' + (results[1] - results[0]));\n }\n\n var testsFuncs = {\n plus: [\n (val1, val2) => val1 + val2,\n (val1, val2) => BigNum.plus(val1, val2),\n ],\n\n minus: [\n (val1, val2) => val1 - val2,\n (val1, val2) => BigNum.minus(val1, val2),\n ],\n\n divide: [\n (val1, val2) => val1 / val2,\n (val1, val2) => BigNum.divide(val1, val2),\n ],\n\n miltiply: [\n (val1, val2) => val1 * val2,\n (val1, val2) => BigNum.multiply(val1, val2),\n ],\n };\n\n for(k in testsFuncs) {\n testF(testsFuncs[k], k);\n }\n },*/\n\n limit: 10000000,\n limit2: 100000000000000,\n}\n\n\n\nvar cnt = +readline();\nfor(var i = 0; i < cnt; i++) {\n var line = readline().split(' ').map(v=>+v);\n var diff = line[0] - line[1];\n var answer = BigNum.multiply(diff, Math.ceil(line[2] / 2));\n if(line[2] % 2) answer = BigNum.plus(answer, line[1]);\n print(BigNum.toInt(answer));\n}"}, {"source_code": "var BigNum = {\n\n plus: function plus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && Math.abs(number1) < BigNum.limit2 &&\n typeof number2 === 'number' && Math.abs(number2) < BigNum.limit2)\n\n return number1 + number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.minus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n return BigNum.minus(ranks2, ranks1, false, false);\n } else {\n result.minus = true;\n }\n\n var maxRank = Math.max(ranks1.length, ranks2.length);\n for (var i = 0; i < maxRank; i++) {\n result[i] = (result[i] || 0)\n + (ranks1[i] || 0)\n + (ranks2[i] || 0);\n\n if (result[i] >= BigNum.limit) {\n result[i + 1] = 1;\n result[i] -= BigNum.limit;\n }\n }\n\n return result;\n },\n\n minus: function minus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 - number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.plus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n result = BigNum.plus(ranks1, ranks2, false, false);\n result.minus = true;\n return result;\n } else {\n return BigNum.minus(ranks2, ranks1, false, false);\n }\n\n var maxRank = Math.max(ranks1.length - 1, ranks2.length - 1);\n for (var i = maxRank; i >= 0; i--) {\n\n result[i] = (ranks1[i] || 0)\n - (ranks2[i] || 0);\n\n if (result[i] < 0) {\n if (result.minus === undefined) {\n result.minus = true;\n result[i] = -result[i];\n\n var swap = ranks1;\n ranks1 = ranks2;\n ranks2 = swap;\n } else {\n var j = i;\n do {\n result[j + 1] -= 1;\n result[j] += BigNum.limit;\n } while (result[++j] < 0);\n }\n } else if (result.minus === undefined && result[i] > 0) {\n result.minus = false;\n }\n }\n\n while(result[result.length - 1] === 0) {\n result.pop();\n }\n if (result.length < 3) {\n return BigNum.toInt(result);\n }\n\n return result;\n },\n\n multiply: function multiply(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit &&\n typeof number2 === 'number' && number2 < BigNum.limit)\n\n return number1 * number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n for (var i = 0; i < ranks1.length; i++) {\n for (var j = 0; j < ranks2.length; j++) {\n var rank = i + j;\n var prod = ranks1[i] * ranks2[j];\n if (prod > BigNum.limit) {\n result[rank] = (result[rank] || 0)\n + prod % BigNum.limit;\n result[rank + 1] = (result[rank + 1] || 0)\n + Math.floor(prod / BigNum.limit);\n } else {\n result[rank] = (result[rank] || 0)\n + prod;\n }\n }\n }\n\n for (i = 0; i < result.length; i++) {\n if (result[i] > BigNum.limit) {\n result[i] -= BigNum.limit;\n result[i + 1] = (result[i + 1] || 0) + 1;\n }\n }\n\n result.minus = (ranks1.minus != ranks2.minus);\n return result;\n },\n\n divide: function divide(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 / number2;\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var result = BigNum.toStr(ranks1) / BigNum.toStr(ranks2);\n return result;\n },\n\n ////////////////////////////////////////////////\n // comparision\n more: function more(number1, number2) {\n return BigNum.compare(number1, number2) > 0;\n },\n\n less: function less(number1, number2) {\n return BigNum.compare(number1, number2) < 0;\n },\n\n equal: function equal(number1, number2) {\n return BigNum.compare(number1, number2) === 0;\n },\n\n max: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.more(number1, number2) ? number1 : number2;\n }\n\n var numberArr = number1;\n var max = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.more(numberArr[i], max)) {\n max = numberArr[i];\n }\n }\n\n return max;\n },\n\n min: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.compare(number1, number2) < 0 ? number1 : number2;\n }\n\n var numberArr = number1;\n var min = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.compare(numberArr[i], min) < 0) {\n min = numberArr[i]\n }\n }\n\n return min;\n },\n\n compare: function compareNumbers(number1, number2) {\n var numberTypes = [typeof number1, typeof number2];\n\n if(numberTypes[0] === numberTypes[1]) {\n if(numberTypes[0] === 'number') {\n return number1 - number2;\n }\n } else {\n if (numberTypes[1] === 'number') {\n if (number1[2]) {\n return 1;\n }\n } else if (numberTypes[0] === 'number') {\n if(number2[2]) {\n return -1;\n }\n }\n }\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var diff;\n\n if(ranks1.minus !== ranks2.minus) {\n return !ranks1.minus > !ranks2.minus ? 1 : -1\n } else if(diff = ranks1.length - ranks2.length) {\n return diff;\n }\n\n for (var i = ranks1.length - 1; i >= 0; i--) {\n if(diff = ranks1[i] - ranks2[i]) {\n return diff;\n }\n }\n\n return 0;\n },\n\n toInt: function (number) {\n if (typeof number === 'object') {\n if(!number.length) return 0;\n else return +BigNum.toStr(number);\n }\n else return +number;\n },\n\n toStr: function (number) {\n\n if (typeof number === 'string') return number;\n else if(typeof number === 'number') return '' + number;\n\n var str = '';\n for (var i = 0; i < number.length - 1; i++) {\n str = ('000000' + number[i]).substr(-7) + str;\n }\n str = number[i] + str;\n return (number.minus ? '-' : '') + str;\n },\n\n getBig: function (number) {\n if (typeof number === 'string') {\n if (number.length < 16) return +number;\n }\n\n return BigNum._getRanks(number);\n },\n\n _getRanks: function (number) {\n\n if (typeof number === 'object') {\n return number;\n } else if (typeof number === 'number') {\n number = '' + number;\n }\n\n var ranks = [];\n if (number[0] === '-') {\n ranks.minus = true;\n number = number.substr(1);\n }\n\n if (number.length > 7) {\n\n number = '' + number;\n for (var i = 7; i <= number.length; i += 7) {\n ranks.push(+number.substr(-i, 7));\n }\n\n var rest = number.length % 7;\n if (rest) {\n ranks.push(+number.substr(0, rest));\n }\n\n } else {\n ranks.push(+number);\n }\n\n if (ranks[ranks.length - 1] < 0) {\n ranks[ranks.length - 1] = -ranks[ranks.length - 1];\n ranks.minus = true;\n }\n\n return ranks;\n },\n\n rand: function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min)) + min;\n },\n\n /*runTests: function tests(count = 10) {\n var correct = 0;\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-999999999999999, 999999999999999);\n var val2 = BigNum.rand(-999999999999999, 999999999999999);\n\n var resBn = BigNum.plus(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = val1 + val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' + ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.minus(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = val1 - val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' - ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.divide(val1, val2);\n resBnInt = Math.round(resBn, 4);\n res = Math.round(val1 / val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' / ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.more(val1, val2);\n res = val1 > val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' > ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.less(val1, val2);\n res = val1 < val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' < ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val2);\n res = val1 === val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val1);\n res = val1 === val1;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val1);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.max(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2);\n\n if(resBnInt !== res) {in\n console.log('!!! min ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var val3 = BigNum.rand(-999999999999999, 999999999999999);\n var resBn = BigNum.max([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! min ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n val1 = BigNum.rand(-99999999, 99999999);\n val2 = BigNum.rand(-9999999, 9999999);\n\n resBn = BigNum.multiply(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = Math.round(val1 * val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' * ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n }\n console.log('correct:' + correct);\n\n\n },*/\n /*runTimeTests: function timeTests(count = 10000, ranks = 15) {\n\n var max = Math.pow(10, ranks);\n\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-max, max);\n var val2 = BigNum.rand(-max, max);\n\n values.push([val1, val2]);\n }\n\n var testF = function (funcs, operation) {\n var results = [];\n for(var f = 0; f < 2; f++) {\n var func = funcs[f];\n var t = performance.now();\n for(var i = 0; i < count; i++) {\n res = func(values[i][0], values[i][1]);\n }\n results[f] = Math.floor(performance.now() - t);\n }\n\n console.log('test ' + operation + ': diff ' + (results[1] - results[0]));\n }\n\n var testsFuncs = {\n plus: [\n (val1, val2) => val1 + val2,\n (val1, val2) => BigNum.plus(val1, val2),\n ],\n\n minus: [\n (val1, val2) => val1 - val2,\n (val1, val2) => BigNum.minus(val1, val2),\n ],\n\n divide: [\n (val1, val2) => val1 / val2,\n (val1, val2) => BigNum.divide(val1, val2),\n ],\n\n miltiply: [\n (val1, val2) => val1 * val2,\n (val1, val2) => BigNum.multiply(val1, val2),\n ],\n };\n\n for(k in testsFuncs) {\n testF(testsFuncs[k], k);\n }\n },*/\n\n limit: 10000000,\n limit2: 100000000000000,\n}\n\nvar cnt = +readline();\nfor(var i = 0; i < cnt; i++) {\n var line = readline().split(' ').map(v=>+v);\n var diff = line[0] - line[1];\n var answer = BigNum.multiply(diff, Math.ceil(line[2] / 2));\n if(line[2] % 2) answer = BigNum.plus(answer, line[1]);\n print(BigNum.toInt(answer));\n}"}, {"source_code": "var cnt = +readline();\nfor(var i = 0; i < cnt; i++) {\n var line = readline().split(' ').map(v=>+v);\n var diff = line[0] - line[1];\n var answer = diff * Math.round(line[2] / 2);\n if(line[2] % 2) answer = answer + line[1];\n print(answer);\n}"}, {"source_code": "var BigNum = {\n\n plus: function plus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && Math.abs(number1) < BigNum.limit2 &&\n typeof number2 === 'number' && Math.abs(number2) < BigNum.limit2)\n\n return number1 + number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.minus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n return BigNum.minus(ranks2, ranks1, false, false);\n } else {\n result.minus = true;\n }\n\n var maxRank = Math.max(ranks1.length, ranks2.length);\n for (var i = 0; i < maxRank; i++) {\n result[i] = (result[i] || 0)\n + (ranks1[i] || 0)\n + (ranks2[i] || 0);\n\n if (result[i] >= BigNum.limit) {\n result[i + 1] = 1;\n result[i] -= BigNum.limit;\n }\n }\n\n return result;\n },\n\n minus: function minus(number1, number2, minus1, minus2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 - number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n if (minus1 === undefined) minus1 = ranks1.minus;\n if (minus2 === undefined) minus2 = ranks2.minus;\n\n\n if (!minus1) {\n if (minus2) {\n return BigNum.plus(ranks1, ranks2, false, false);\n }\n } else if (!minus2) {\n result = BigNum.plus(ranks1, ranks2, false, false);\n result.minus = true;\n return result;\n } else {\n return BigNum.minus(ranks2, ranks1, false, false);\n }\n\n var maxRank = Math.max(ranks1.length - 1, ranks2.length - 1);\n for (var i = maxRank; i >= 0; i--) {\n\n result[i] = (ranks1[i] || 0)\n - (ranks2[i] || 0);\n\n if (result[i] < 0) {\n if (result.minus === undefined) {\n result.minus = true;\n result[i] = -result[i];\n\n var swap = ranks1;\n ranks1 = ranks2;\n ranks2 = swap;\n } else {\n var j = i;\n do {\n result[j + 1] -= 1;\n result[j] += BigNum.limit;\n } while (result[++j] < 0);\n }\n } else if (result.minus === undefined && result[i] > 0) {\n result.minus = false;\n }\n }\n\n while(result[result.length - 1] === 0) {\n result.pop();\n }\n if (result.length < 3) {\n return BigNum.toInt(result);\n }\n\n return result;\n },\n\n multiply: function multiply(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit &&\n typeof number2 === 'number' && number2 < BigNum.limit)\n\n return number1 * number2;\n\n var result = [];\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n for (var i = 0; i < ranks1.length; i++) {\n for (var j = 0; j < ranks2.length; j++) {\n var rank = i + j;\n var prod = ranks1[i] * ranks2[j];\n if (prod > BigNum.limit) {\n result[rank] = (result[rank] || 0)\n + prod % BigNum.limit;\n result[rank + 1] = (result[rank + 1] || 0)\n + Math.floor(prod / BigNum.limit);\n } else {\n result[rank] = (result[rank] || 0)\n + prod;\n }\n }\n }\n\n for (i = 0; i < result.length; i++) {\n if (result[i] > BigNum.limit) {\n result[i] -= BigNum.limit;\n result[i + 1] = (result[i + 1] || 0) + 1;\n }\n }\n\n result.minus = (ranks1.minus != ranks2.minus);\n return result;\n },\n\n divide: function divide(number1, number2) {\n\n if (typeof number1 === 'number' && number1 < BigNum.limit2 &&\n typeof number2 === 'number' && number2 < BigNum.limit2)\n\n return number1 / number2;\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var result = BigNum.toStr(ranks1) / BigNum.toStr(ranks2);\n return result;\n },\n\n ////////////////////////////////////////////////\n // comparision\n more: function more(number1, number2) {\n return BigNum.compare(number1, number2) > 0;\n },\n\n less: function less(number1, number2) {\n return BigNum.compare(number1, number2) < 0;\n },\n\n equal: function equal(number1, number2) {\n return BigNum.compare(number1, number2) === 0;\n },\n\n max: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.more(number1, number2) ? number1 : number2;\n }\n\n var numberArr = number1;\n var max = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.more(numberArr[i], max)) {\n max = numberArr[i];\n }\n }\n\n return max;\n },\n\n min: function max(number1, number2) {\n if(number2 !== undefined) {\n return BigNum.compare(number1, number2) < 0 ? number1 : number2;\n }\n\n var numberArr = number1;\n var min = numberArr[0];\n\n for(var i = 1; i < numberArr.length; i++) {\n if(BigNum.compare(numberArr[i], min) < 0) {\n min = numberArr[i]\n }\n }\n\n return min;\n },\n\n compare: function compareNumbers(number1, number2) {\n var numberTypes = [typeof number1, typeof number2];\n\n if(numberTypes[0] === numberTypes[1]) {\n if(numberTypes[0] === 'number') {\n return number1 - number2;\n }\n } else {\n if (numberTypes[1] === 'number') {\n if (number1[2]) {\n return 1;\n }\n } else if (numberTypes[0] === 'number') {\n if(number2[2]) {\n return -1;\n }\n }\n }\n\n var ranks1 = BigNum._getRanks(number1);\n var ranks2 = BigNum._getRanks(number2);\n\n var diff;\n\n if(ranks1.minus !== ranks2.minus) {\n return !ranks1.minus > !ranks2.minus ? 1 : -1\n } else if(diff = ranks1.length - ranks2.length) {\n return diff;\n }\n\n for (var i = ranks1.length - 1; i >= 0; i--) {\n if(diff = ranks1[i] - ranks2[i]) {\n return diff;\n }\n }\n\n return 0;\n },\n\n toInt: function (number) {\n if (typeof number === 'object') {\n if(!number.length) return 0;\n else return +BigNum.toStr(number);\n }\n else return +number;\n },\n\n toStr: function (number) {\n\n if (typeof number === 'string') return number;\n else if(typeof number === 'number') return '' + number;\n\n var str = '';\n while(number.length && !number[number.length - 1]) number.pop();\n\n if(!number.length) return '0';\n\n for (var i = 0; i < number.length - 1; i++) {\n str = ('000000' + number[i]).substr(-7) + str;\n }\n str = number[i] + str;\n return (number.minus ? '-' : '') + str;\n },\n\n getBig: function (number) {\n if (typeof number === 'string') {\n if (number.length < 16) return +number;\n }\n\n return BigNum._getRanks(number);\n },\n\n _getRanks: function (number) {\n\n if (typeof number === 'object') {\n return number;\n } else if (typeof number === 'number') {\n number = '' + number;\n }\n\n var ranks = [];\n if (number[0] === '-') {\n ranks.minus = true;\n number = number.substr(1);\n }\n\n if (number.length > 7) {\n\n number = '' + number;\n for (var i = 7; i <= number.length; i += 7) {\n ranks.push(+number.substr(-i, 7));\n }\n\n var rest = number.length % 7;\n if (rest) {\n ranks.push(+number.substr(0, rest));\n }\n\n } else {\n ranks.push(+number);\n }\n\n if (ranks[ranks.length - 1] < 0) {\n ranks[ranks.length - 1] = -ranks[ranks.length - 1];\n ranks.minus = true;\n }\n\n return ranks;\n },\n\n rand: function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min)) + min;\n },\n\n /*runTests: function tests(count = 10) {\n var correct = 0;\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-999999999999999, 999999999999999);\n var val2 = BigNum.rand(-999999999999999, 999999999999999);\n\n var resBn = BigNum.plus(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = val1 + val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' + ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.minus(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = val1 - val2;\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' - ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.divide(val1, val2);\n resBnInt = Math.round(resBn, 4);\n res = Math.round(val1 / val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' / ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.more(val1, val2);\n res = val1 > val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' > ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.less(val1, val2);\n res = val1 < val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' < ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val2);\n res = val1 === val2;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val2);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n resBn = BigNum.equal(val1, val1);\n res = val1 === val1;\n\n if(resBn !== res) {\n console.log('!!! ' + val1 + ' === ' + val1);\n console.log(' Bn: ' + resBn);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.max(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min(val1, val2);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2);\n\n if(resBnInt !== res) {in\n console.log('!!! min ' + val1 + ', ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var val3 = BigNum.rand(-999999999999999, 999999999999999);\n var resBn = BigNum.max([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.max(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! max ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n var resBn = BigNum.min([val1, val2, val3]);\n var resBnInt = BigNum.toInt(resBn);\n var res = Math.min(val1, val2, val3);\n\n if(resBnInt !== res) {\n console.log('!!! min ' + val1 + ', ' + val2 + ', ' + val3);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n val1 = BigNum.rand(-99999999, 99999999);\n val2 = BigNum.rand(-9999999, 9999999);\n\n resBn = BigNum.multiply(val1, val2);\n resBnInt = BigNum.toInt(resBn);\n res = Math.round(val1 * val2, 4);\n\n if(resBnInt !== res) {\n console.log('!!! ' + val1 + ' * ' + val2);\n console.log(' Bn: ' + resBnInt);\n console.log(' Nm: ' + res);\n } else {\n correct++;\n }\n\n }\n console.log('correct:' + correct);\n\n\n },*/\n /*runTimeTests: function timeTests(count = 10000, ranks = 15) {\n\n var max = Math.pow(10, ranks);\n\n var values = [];\n for(var i = 0; i < count; i++) {\n var val1 = BigNum.rand(-max, max);\n var val2 = BigNum.rand(-max, max);\n\n values.push([val1, val2]);\n }\n\n var testF = function (funcs, operation) {\n var results = [];\n for(var f = 0; f < 2; f++) {\n var func = funcs[f];\n var t = performance.now();\n for(var i = 0; i < count; i++) {\n res = func(values[i][0], values[i][1]);\n }\n results[f] = Math.floor(performance.now() - t);\n }\n\n console.log('test ' + operation + ': diff ' + (results[1] - results[0]));\n }\n\n var testsFuncs = {\n plus: [\n (val1, val2) => val1 + val2,\n (val1, val2) => BigNum.plus(val1, val2),\n ],\n\n minus: [\n (val1, val2) => val1 - val2,\n (val1, val2) => BigNum.minus(val1, val2),\n ],\n\n divide: [\n (val1, val2) => val1 / val2,\n (val1, val2) => BigNum.divide(val1, val2),\n ],\n\n miltiply: [\n (val1, val2) => val1 * val2,\n (val1, val2) => BigNum.multiply(val1, val2),\n ],\n };\n\n for(k in testsFuncs) {\n testF(testsFuncs[k], k);\n }\n },*/\n\n limit: 10000000,\n limit2: 100000000000000,\n}\n\nvar cnt = +readline();\nfor(var i = 0; i < cnt; i++) {\n var line = readline().split(' ').map(v=>+v);\n var diff = line[0] - line[1];\n var answer = BigNum.multiply(diff, Math.ceil(line[2] / 2));\n if(line[2] % 2) answer = BigNum.plus(answer, line[1]);\n print(BigNum.toStr(answer));\n}"}, {"source_code": "solve();\n\nfunction solve() {\n var t = Number(readline()), line, p1, p2, s1, res, d, o, z;\n for (;t--;) {\n line = readline().split(' ').map(Number);\n z = '';\n p1 = (line[0] - line[1]);\n if (p1 < 0) {\n z = '-';\n p1 = -p1;\n }\n p2 = (line[2] >> 1);\n s1 = ((line[2] & 1) * line[0]);\n if (!p1 || line[2] === 1) {\n print(s1);\n continue;\n }\n if (z) {\n s1 = -s1;\n }\n res = [];\n while (p1) {\n o = p1 % 1000;\n res.push(o);\n p1 = (p1 - o) / 1000;\n }\n d = 0;\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] * p2 + d;\n o = res[i] % 1000;\n d = (res[i] - o) / 1000;\n res[i] = o;\n }\n while (d) {\n o = d % 1000;\n res.push(o);\n d = (d - o) / 1000;\n }\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] + s1 + d;\n o = res[i] % 1000;\n d = (res[i] - o) / 1000;\n res[i] = o;\n }\n while (d) {\n o = d % 1000;\n res.push(o);\n d = (d - o) / 1000;\n }\n print(z + res.reverse().join(''));\n /*a = line[0];\n b = line[1];\n k = line[2];\n print ('' + a + b + k);\n print((a - b) * (k >> 1) + (k & 1) * a);*/\n }\n}"}, {"source_code": "solve();\n\nvar D = 10000, DL = 4;\n\nfunction LongNumber(n) {\n this.zero = [''];\n for (var i = 1; i < DL; ++i) {\n this.zero[i] = this.zero[i - 1] + '0';\n }\n this.value = [];\n if (!n) {\n this.value.push(0);\n }\n while (n) {\n this.value.push(n % D);\n n = Math.floor(n / D);\n }\n \n this.toString = function() {\n var value = this.value, i, result = '', sc;\n for (i = value.length - 1; i && !value[i]; --i);\n result += value[i--];\n for(; ~i; --i) {\n sc = String(value[i]);\n result += this.zero[DL - sc.length] + sc;\n }\n return result;\n };\n this.plus = function(n) {\n if (typeof n === 'number') {\n n = new LongNumber(n).value;\n }\n var value = this.value, d = 0, i;\n while(value.length < n.length) {\n value.push(0);\n }\n var l = Math.min(value.length, n.length),\n L = Math.max(value.length, n.length);\n for(i = 0; i < l; ++i) {\n value[i] += n[i] + d;\n d = Math.floor(value[i] / D);\n value[i] %= D;\n }\n for(; i < L && d; ++i) {\n value[i] += d;\n d = Math.floor(value[i] / D);\n value[i] %= D;\n }\n while (d) {\n value.push(d % D);\n d = Math.floor(d / D);\n }\n return this;\n };\n \n return this;\n}\n\nfunction solve() {\n var ln = new LongNumber();\n for (var i = 0; i < 10000; ++i) {\n ln.plus(1000000000);\n }\n print(ln.toString());\n}"}, {"source_code": "solve();\n\nfunction solve() {\n var t = Number(readline()), line, a, b, k;\n for (;t--;) {\n line = readline().split(' ').map(Number);\n a = line[0];\n b = line[1];\n k = line[2];\n print((a - b) * (k >> 1) + (k & 1) * a);\n }\n}"}, {"source_code": "solve();\n\nvar D = 10000, DL = 4;\n\nfunction LongNumber(n) {\n this.zero = [''];\n for (var i = 1; i < DL; ++i) {\n this.zero[i] = this.zero[i - 1] + '0';\n }\n this.value = [];\n if (!n) {\n this.value.push(0);\n }\n while (n) {\n this.value.push(n % D);\n n = Math.floor(n / D);\n }\n \n this.toString = function() {\n var value = this.value, i, result = '', sc;\n for (i = value.length - 1; i && !value[i]; --i);\n result += value[i--];\n for(; ~i; --i) {\n sc = String(value[i]);\n result += this.zero[DL - sc.length] + sc;\n }\n return result;\n };\n this.plus = function(n) {\n if (typeof n === 'number') {\n n = new LongNumber(n).value;\n }\n var value = this.value, d = 0, i;\n while(value.length < n.length) {\n value.push(0);\n }\n var l = Math.min(value.length, n.length),\n L = Math.max(value.length, n.length);\n for(i = 0; i < l; ++i) {\n value[i] += n[i] + d;\n d = Math.floor(value[i] / D);\n value[i] %= D;\n }\n for(; i < L && d; ++i) {\n value[i] += d;\n d = Math.floor(value[i] / D);\n value[i] %= D;\n }\n while (d) {\n value.push(d % D);\n d = Math.floor(d / D);\n }\n return this;\n };\n \n return this;\n}\n\nfunction solve() {\n var ln = new LongNumber();\n for (var i = 0; i < 100; ++i) {\n ln.plus(100000000);\n }\n print(ln.toString());\n}"}, {"source_code": "solve();\n\nfunction solve() {\n var t = Number(readline()), line, p1, p2, s1, res, d, o, z, bs, zs, sign;\n for (;t--;) {\n line = readline().split(' ').map(Number);\n z = '';\n p1 = (line[0] - line[1]);\n if (p1 < 0) {\n z = '-';\n p1 = -p1;\n }\n p2 = (line[2] >> 1);\n s1 = ((line[2] & 1) * line[0]);\n if (!p1 || line[2] === 1) {\n print(s1);\n continue;\n }\n zs = '';\n if (s1 < 0) {\n zs = '-';\n s1 = -s1;\n }\n res = [];\n while (p1) {\n o = p1 % 1000;\n res.push(o);\n p1 = (p1 - o) / 1000;\n }\n bs = [];\n while (s1) {\n o = s1 % 1000;\n bs.push(o);\n s1 = (s1 - o) / 1000;\n }\n d = 0;\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] * p2 + d;\n o = res[i] % 1000;\n d = (res[i] - o) / 1000;\n res[i] = o;\n }\n while (d) {\n o = d % 1000;\n res.push(o);\n d = (d - o) / 1000;\n }\n if (z === zs) {\n while (res.length < bs.length) {\n res.push(0);\n }\n while (bs.length < res.length) {\n bs.push(0);\n }\n for (var i = 0; i < res.length; ++i) {\n res[i] = res[i] + bs[i] + d;\n o = res[i] % 1000;\n d = (res[i] - o) / 1000;\n res[i] = o;\n }\n while (d) {\n o = d % 1000;\n res.push(o);\n d = (d - o) / 1000;\n }\n } else {\n sign = 0;\n if (res.length < bs.length) {\n sign = -1;\n } else if (res.length > bs.length) {\n sign = 1;\n } else {\n for (i = res.length - 1; i >= 0; --i) {\n if (res[i] < bs[i]) {\n sign = -1;\n break;\n } else if (res[i] > bs[i]) {\n sign = 1;\n break;\n }\n }\n }\n if (!sign) {\n print(0);\n continue\n }\n if (sign === -1) {\n z = zs;\n p1 = res;\n res = bs;\n bs = p1;\n }\n for (i = 0; i < res.length; ++i) {\n if (res[i] + d < bs[i]) {\n res[i] = res[i] + d + 1000 - bs[i];\n d = -1;\n } else {\n res[i] = res[i] + d - bs[i];\n d = 0;\n }\n }\n while (res[res.length - 1] === 0) {\n res.pop();\n }\n }\n print(z + res.reverse().join(''));\n /*a = line[0];\n b = line[1];\n k = line[2];\n print ('' + a + b + k);\n print((a - b) * (k >> 1) + (k & 1) * a);*/\n }\n}"}], "src_uid": "1f435ba837f59b007167419896c836ae"} {"source_code": "print(function(k, s) {\n\tvar i, ans = 0,\n\t\tc = 0,\n\t\tl = s.length,\n\t\tdp = [1];\n\n\tfor (i = 1; i <= l; i++)\n\t\tdp.push(0);\n\n\tfor (i = 0; i < l; i++) {\n\t\tif (s[i] === '1') c++;\n\t\tif (c >= k) ans += dp[c - k];\n\t\tdp[c]++;\n\t}\n\n\treturn ans;\n}(+readline(), readline()));", "positive_code": [{"source_code": "\nprint(function(k, s) {\n\n\tvar i, c = 0,\n\t\tans = 0,\n\t\tl = s.length,\n\t\tdp = [1];\n\n\tfor (i = 1; i <= l; i++)\n\t\tdp.push(0);\n\n\n\tfor (i = 0; i < l; i++) {\n\t\tif (s[i] === '1') c++;\n\t\tif (c >= k) ans += dp[c - k];\n\t\tdp[c]++;\n\t}\n\n\n\treturn ans;\n\n}(+readline(), readline()));\n"}, {"source_code": "print(function(k, s) {\n\n\tvar i, c = 0,\n\t\tans = 0,\n\t\tl = s.length,\n\t\tdp = [1];\n\n\tfor (i = 1; i <= l; i++)\n\t\tdp.push(0);\n\n\n\tfor (i = 0; i < l; i++) {\n\t\tif (s[i] === '1') c++;\n\t\tif (c >= k) ans += dp[c - k];\n\t\tdp[c]++;\n\t}\n\n\n\treturn ans;\n\n}(+readline(), readline()));"}, {"source_code": "\n\nvar k = +readline();\nvar s = readline();\nvar aa =[];\naa[0] = 0;\nfor(var i=1; i<=1e6; i++){\n\taa[i]=aa[i-1]+i;\n}\n\nif(k===0){\n\tprint( s.split(/1+/g).map(function(v){\n\t\treturn aa[v.length];\n\t}).reduce(function(a, b){ return a+b;}) );\n\tquit();\n}\n\nvar low = 0;\nvar high = 0;\nvar c = 0;\nvar ans = 0;\n// while(true){\n\tfor(; high= k) ans += dp[c - k];\n\t\tdp[c]++;\n\t}\n\n\n\treturn ans;\n\n}(+readline(), readline()));\n"}, {"source_code": "var k = +readline();\nvar s = readline();\nvar aa =[];\naa[0] = 0;\nfor(var i=1; i<=1e6; i++){\n\taa[i]=aa[i-1]+i;\n}\n\nif(k===0){\n\tprint( s.split(/1+/g).map(function(v){\n\t\treturn aa[v.length];\n\t}).reduce(function(a, b){ return a+b;}) );\n\tquit();\n}\n\nvar low = 0;\nvar high = 0;\nvar c = 0;\nvar ans = 0;\n// while(true){\n\tfor(; high= k) ans += dp[c - k];\n\t\tdp[c]++;\n\t}\n\n\n\treturn ans;\n\n}(+readline(), readline()));"}, {"source_code": "var k = +readline();\nvar s = readline();\nvar aa =[];\naa[0] = 0;\nfor(var i=1; i<1e6; i++){\n\taa[i]=aa[i-1]+i;\n}\n\nif(k===0){\n\tprint( s.split(/1+/g).map(function(v){\n\t\treturn aa[v.length];\n\t}).reduce(function(a, b){ return a+b;}) );\n\tquit();\n}\n\nvar low = 0;\nvar high = 0;\nvar c = 0;\nvar ans = 0;\n// while(true){\n\tfor(; high1){\n\t\t\ta*=v;\n\t\t\tv--;\n\t\t}\n\t\treturn a;\n\t}).reduce(function(a, b){ return a+b;}) );\n\tquit();\n}\n\nvar low = 0;\nvar high = 0;\nvar c = 0;\nvar ans = 0;\n// while(true){\n\tfor(; high a - b);\r\n for(var i = 1; i < nums.length; i++) {\r\n if(nums[i] == nums[i-1]) {\r\n print(\"NO\");\r\n return;\r\n }\r\n }\r\n print(\"YES\");\r\n}\r\n\r\nvar caseNum = parseInt(readline(), 10);\r\nfor (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(x);\r\n}", "positive_code": [{"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction possibleIncrease(cases) {\n for (let i = 0; i < cases.length; i++) {\n const [...elements] = cases[i];\n let dict = {};\n for (let j = 0; j < elements.length; j++) {\n dict = {\n ...dict,\n [elements[j]]: isNaN(dict[[elements[j]]])\n ? 1\n : Number(dict[[elements[j]]]) + 1,\n };\n }\n\n const res = Object.keys(dict).some((element) => {\n if (dict[element] > 1) {\n return true;\n }\n });\n\n const sortElements = cases[i];\n sortElements.sort((a, b) => a - b);\n\n let isSorted = true;\n for (let j = 0; j < elements.length && isSorted; j++) {\n if (elements[j] !== sortElements[j]) {\n isSorted = false;\n }\n }\n console.log(res ? \"NO\" : \"YES\");\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const numbers = readLine().trim().split(\" \");\n if (i % 2 === 1) cases.push(numbers);\n }\n\n possibleIncrease(cases);\n}\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst data = [];\r\nconst input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n const dSize = parseInt(input[0], 10);\r\n for (let i = 1; i < input.length; i += 2) {\r\n const size = parseInt(input[i], 10);\r\n if (\r\n new Set(input[i + 1].split(' ').map(x => parseInt(x, 10))).size === size\r\n ) {\r\n data.push('YES');\r\n } else {\r\n data.push('NO');\r\n }\r\n }\r\n if (data.length === dSize) {\r\n console.log(data.join('\\n'));\r\n process.exit(0);\r\n }\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst data = [];\r\nconst input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n const dSize = parseInt(input[0], 10);\r\n for (let i = 1; i < input.length; i += 2) {\r\n const size = parseInt(input[i], 10);\r\n new Set(input[i + 1].split(' ').map(x => parseInt(x, 10))).size === size\r\n ? data.push('YES')\r\n : data.push('NO');\r\n }\r\n if (data.length === dSize) {\r\n console.log(data.join('\\n'));\r\n process.exit(0);\r\n }\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst data = [];\r\nconst input = [];\r\n\r\nrl.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n const dSize = parseInt(input[0], 10);\r\n for (let i = 1; i < input.length; i += 2) {\r\n new Set(input[i + 1].split(' ').map(x => parseInt(x, 10))).size ===\r\n parseInt(input[i], 10)\r\n ? data.push('YES')\r\n : data.push('NO');\r\n }\r\n if (data.length === dSize) {\r\n console.log(data.join('\\n'));\r\n process.exit(0);\r\n }\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst data = [];\r\nconst input = [];\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nrl.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n const dSize = parseInt(input[0], 10);\r\n for (let i = 1; i < input.length; i += 2) {\r\n const size = parseInt(input[i], 10);\r\n const arr = input[i + 1].split(' ').map(x => parseInt(x, 10));\r\n new Set(arr).size === size ? data.push('YES') : data.push('NO');\r\n }\r\n if (data.length === dSize) {\r\n console.log(data.join('\\n'));\r\n rl.close();\r\n process.exit(0);\r\n }\r\n});\r\n"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nasync function main(read) {\r\n let amount = Number(await read());\r\n let output = \"\"\r\n while (amount > 0) {\r\n let length = Number(await read())\r\n let array = await read().split(' ').map(Number).sort((a, b) => a - b)\r\n let answer = array.every((e, i) => array.lastIndexOf(e) == i)\r\n output += (answer ? \"YES\" : \"NO\") + '\\n'\r\n amount--\r\n }\r\n return output\r\n}\r\n\r\nlet inputs, str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var e = lines[j], a = new Map(), f= false\n }else{\n k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n f = true\n break;\n }else{\n a.set(k[l])\n }\n }\n console.log(f === true ? 'NO' : 'YES')\n }\n \n }\n});"}, {"source_code": " const fs = require('fs');\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n \r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n \r\n let T = readline();\r\n for(let i = 1; i <= T; i++){\r\n let N = readline().split(' ');\r\n let arr = readline().split(' ').map(Number);\r\n console.log(solve(arr, N));\r\n }\r\n \r\n \r\n function solve(arr, N){\r\n let itms = new Set();\r\n for(let i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i], a = new Map(), flag = false;\n }else{\n k = lines[i].split(' ').map(Number);\n for(j = 0; j < n; j++){\n if(a.has(k[j])){\n flag = true;\n break;\n }else{\n a.set(k[j]);\n }\n }\n console.log(flag === true ? 'NO' : 'YES');\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var a = readline().split(' ');\r\n var repeated = a.filter(function (e, i, a) {\r\n return a.indexOf(e) !== i;\r\n })\r\n if (repeated.length == 0) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL} = require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n // console.log(EOL);\r\n for(let z=1;z<=t;z++)\r\n {\r\n let n=parseInt(line[2*z-1]);\r\n let arr=line[2*z].split(' ').map(x=>{return parseInt(x)});\r\n // console.log(arr);\r\n const st=new Set();\r\n for(let i=0;i {\r\n if (currentLineIndex > 0 && currentLineIndex % 2 === 0) {\r\n lines.push(line);\r\n }\r\n currentLineIndex++;\r\n});\r\n\r\nreadlineInterface.on(\"close\", () => {\r\n const tests = lines.map((line) => line.split(\" \").map((e) => +e));\r\n\r\n tests\r\n .map((numbers) => {\r\n return new Set(numbers).size === numbers.length ? \"YES\" : \"NO\";\r\n })\r\n .forEach((e) => console.log(e));\r\n});\r\n"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/B\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nconst solve = (n, a) => {\r\n a.sort((x, y) => x - y);\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] == a[i - 1]) return pr(\"NO\");\r\n }\r\n pr(\"YES\");\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let t = ni();\r\n while (t--) {\r\n let n = ni(), a = nai();\r\n solve(n, a);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nvar tcn = 0\r\nvar isnTurn = true\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on('line', line => {\r\n if (!tcn) return tcn = Number(line)\r\n\r\n if (isnTurn) {\r\n isnTurn = false\r\n }\r\n else {\r\n isnTurn = true\r\n run(line)\r\n if (!--tcn) rl.close()\r\n }\r\n\r\n})\r\n\r\nfunction run(line) {\r\n var vals = line.split(' ').map(val => Number(val)).sort((a, b) => a - b)\r\n for (let index = 0; index < vals.length - 1; index++) {\r\n if (vals[index] == vals[index + 1]) {\r\n console.log('NO')\r\n return\r\n } \r\n }\r\n console.log('YES') \r\n}\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let arr = readline().split(' ').map(Number)\r\n console.log(solve(arr))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (arr) => {\r\n let arr2 = uniqueArray( arr )\r\n \r\n if( arr.length === arr2.length ) return 'YES'\r\n\r\n return 'NO'\r\n}\r\n\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\n\r\n// cmd: cat input.txt | node main.js"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet processIn = '';\r\nlet processCurr = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n processIn += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n processIn = processIn.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n JS();\r\n});\r\n\r\nfunction readLine() {\r\n return processIn[processCurr++];\r\n}\r\nfunction mergeSort(a) {\r\n let r = a.length;\r\n let l = 0;\r\n let m = Math.round((r - l) / 2);\r\n if (r === 1) {\r\n return; // returns recursively\r\n }\r\n let L = []; // left half of current a\r\n let R = []; // right half of current a\r\n for (let i = l; i < m; i++) {\r\n L.push(a[i]);\r\n }\r\n for (let j = m; j < r; j++) {\r\n R.push(a[j]);\r\n }\r\n mergeSort(L);\r\n mergeSort(R);\r\n let i = 0, j = 0, k = 0;\r\n // Merging part\r\n while (i < L.length && j < R.length) {\r\n if (L[i] < R[j]) {\r\n a[k] = L[i];\r\n i++;\r\n } else {\r\n a[k] = R[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n while (i < L.length) {\r\n a[k] = L[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < R.length) {\r\n a[k] = R[j];\r\n j++;\r\n k++;\r\n }\r\n}\r\n\r\nfunction JS() {\r\n /*\r\n\r\n */\r\n let tt = parseInt(readLine());\r\n // let tt = 1;\r\n for(let t=0;t { return parseInt(string.trim()); });\r\n mergeSort(l);\r\n let flag = 1;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readline();\r\n for (let i = 0; i < t; i++) {\r\n let n = readline();\r\n let arr = readline().split(\" \").map(Number);\r\n const set = new Set();\r\n for (let i = 0; i < arr.length; i++) {\r\n if (!set.has(arr[i])) {\r\n set.add(arr[i]);\r\n }\r\n }\r\n if (set.size === arr.length) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n a.sort((a, b) => a - b);\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] >= a[i + 1]) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const m = {}\n for (let x of arr) {\n if (m[x]) return 'NO'\n m[x] = 1\n }\n return 'YES'\n}\n"}, {"source_code": "// run on javascript V8 4.8.0\r\n// https://codeforces.com/contest/1742/problem/A\r\n// You are given an array a of n positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that a1 a[i]) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n var isEqual = function (a) {\r\n for (var i = 1; i < a.length; i++) {\r\n if (a[i-1] == a[i]) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n \r\n if (isDecreasing(a)) {\r\n print('NO');\r\n }\r\n else if (isEqual(a)) {\r\n print('NO');\r\n }\r\n else {\r\n print('YES');\r\n }\r\n}\r\n\r\n\r\nmain();\r\n"}, {"source_code": "const tc = readline();\r\nfor (var t =0 ; tNumber(i));\r\n input = input.sort();\r\n var b = true;\r\n for(var i=1;i {\n if (dict[element] > 1) {\n return true;\n }\n });\n\n // const sortElements = cases[i];\n // sortElements.sort((a, b) => a - b);\n\n // let isSorted = true;\n // for (let j = 0; j < elements.length && isSorted; j++) {\n // if (elements[j] !== sortElements[j]) {\n // isSorted = false;\n // }\n // }\n console.log(res ? \"NO\" : \"YES\");\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const numbers = readLine().split(\" \");\n if (i % 2 === 1) cases.push(numbers);\n }\n\n possibleIncrease(cases);\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction possibleIncrease(cases) {\n for (let i = 0; i < cases.length; i++) {\n const [...elements] = cases[i];\n let dict = {};\n for (let j = 0; j < elements.length; j++) {\n dict = {\n ...dict,\n [elements[j]]: isNaN(dict[[elements[j]]])\n ? 1\n : Number(dict[[elements[j]]]) + 1,\n };\n }\n\n const res = Object.keys(dict).some((element) => {\n if (dict[element] > 1) {\n return true;\n }\n });\n\n console.log(\"ress nya:\", res);\n\n const sortElements = cases[i];\n sortElements.sort((a, b) => a - b);\n\n let isSorted = true;\n for (let j = 0; j < elements.length && isSorted; j++) {\n if (elements[j] !== sortElements[j]) {\n isSorted = false;\n }\n }\n console.log(res ? \"NO\" : \"YES\");\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const numbers = readLine().split(\" \");\n if (i % 2 === 1) cases.push(numbers);\n }\n\n possibleIncrease(cases);\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction possibleIncrease(cases) {\n for (let i = 0; i < cases.length; i++) {\n const [...elements] = cases[i];\n let dict = {};\n for (let j = 0; j < elements.length; j++) {\n dict = {\n ...dict,\n [elements[j]]: isNaN(dict[[elements[j]]])\n ? 1\n : Number(dict[[elements[j]]]) + 1,\n };\n }\n\n const res = Object.keys(dict).some((element) => {\n if (dict[element] > 1) {\n return true;\n }\n });\n\n const sortElements = cases[i];\n sortElements.sort((a, b) => a - b);\n\n let isSorted = true;\n for (let j = 0; j < elements.length && isSorted; j++) {\n if (elements[j] !== sortElements[j]) {\n isSorted = false;\n }\n }\n console.log(res ? \"NO\" : \"YES\");\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const numbers = readLine().split(\" \");\n if (i % 2 === 1) cases.push(numbers);\n }\n\n possibleIncrease(cases);\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction possibleIncrease(cases) {\n for (let i = 0; i < cases.length; i++) {\n const [...elements] = cases[i];\n let dict = {};\n for (let j = 0; j < elements.length; j++) {\n dict = {\n ...dict,\n [elements[j]]: isNaN(dict[[elements[j]]])\n ? 1\n : Number(dict[[elements[j]]]) + 1,\n };\n }\n\n const res = Object.keys(dict).some((element) => {\n if (dict[element] > 1) {\n return true;\n }\n });\n\n const sortElements = cases[i];\n sortElements.sort((a, b) => a - b);\n\n let isSorted = true;\n for (let j = 0; j < elements.length && isSorted; j++) {\n if (elements[j] !== sortElements[j]) {\n isSorted = false;\n }\n }\n console.log(res || (isSorted && elements.length > 1) ? \"NO\" : \"YES\");\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const numbers = readLine().split(\" \");\n if (i % 2 === 1) cases.push(numbers);\n }\n\n possibleIncrease(cases);\n}\n"}, {"source_code": "const readline = require('readline');\r\nconst util = require('util');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst question = util.promisify(rl.question).bind(rl);\r\nconst data = [];\r\n\r\nrl.question('', async testCaseSize => {\r\n const dSize = parseInt(testCaseSize, 10);\r\n for (let i = 0; i < dSize; i++) {\r\n const size = parseInt(await question(''), 10);\r\n const arr = (await question('')).split(' ').map(x => parseInt(x, 10));\r\n new Set(arr).size === size ? data.push('YES') : data.push('NO');\r\n if (data.length === dSize) {\r\n console.log(data.join('\\n'));\r\n rl.close();\r\n }\r\n }\r\n});\r\n\r\nrl.on('close', function () {\r\n process.exit(0);\r\n});\r\n"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nasync function main(read) {\r\n let amount = Number(await read());\r\n let output = \"\"\r\n while (amount > 0) {\r\n try {\r\n let length = Number(await read())\r\n let array = await read().split(' ').map(Number).sort((a, b) => a - b)\r\n while (array.length > 1) {\r\n let c = array.shift()\r\n let n = array.shift()\r\n if (c < n) continue\r\n break\r\n }\r\n output += (array.length == 0 ? \"YES\" : \"NO\") + '\\n'\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n amount--\r\n }\r\n return output\r\n}\r\n\r\nlet inputs, str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nasync function main(read) {\r\n let amount = Number(await read());\r\n let output = \"\"\r\n while (amount > 0) {\r\n try {\r\n let length = Number(await read())\r\n let array = await read().split(' ').map(Number).sort((a, b) => a - b)\r\n while (array.length > 0) {\r\n let c = array.shift()\r\n let n = array.shift()\r\n if (c >= n) break\r\n }\r\n output += (array.length == 0 ? \"YES\" : \"NO\") + '\\n'\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n amount--\r\n }\r\n return output\r\n}\r\n \r\nlet inputs, str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nasync function main(read) {\r\n let amount = Number(await read());\r\n let output = \"\"\r\n while (amount > 0) {\r\n try {\r\n let length = Number(await read())\r\n let array = await read().split(' ').sort((a, b) => a - b)\r\n while (array.length > 0) {\r\n let c = array.shift()\r\n let n = array.shift()\r\n if (c >= n) break\r\n }\r\n output += (array.length == 0 ? \"YES\" : \"NO\") + '\\n'\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n amount--\r\n }\r\n return output\r\n}\r\n\r\nlet inputs, str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var e = lines[j], a = new Map(), f= false\n }else{\n k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n f = true\n break;\n }\n }\n console.log(f === true ? 'NO' : 'YES')\n }\n \n }\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var e = lines[j], a = new Map(), f= false\n }else{\n k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n f = true\n break;\n }\n }\n console.log(f === true ? 'NO' : 'YES')\n break;\n }\n \n }\n});"}, {"source_code": " const fs = require('fs');\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n \r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n \r\n let T = readline();\r\n for(let i = 1; i <= T; i++){\r\n let N = readline().split(' ');\r\n let arr = readline().split(' ').map(Number);\r\n console.log(N, arr);\r\n console.log(solve(arr, N));\r\n }\r\n \r\n \r\n function solve(arr, N){\r\n let itms = new Set();\r\n for(let i=0;i a[i]) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n if (!isDecreasing(a)) {\r\n print('YES');\r\n }\r\n else {\r\n print('NO');\r\n }\r\n}\r\n\r\n\r\nmain();\r\n"}, {"source_code": "// run on javascript V8 4.8.0\r\n// https://codeforces.com/contest/1742/problem/A\r\n// You are given an array a of n positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that a1Number(i));\r\n input = input.sort();\r\n var b = true;\r\n for(var i=1;i {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n if (n) {\n strs.push(d);\n n--;\n return;\n }\n\n points.push(...d.split(' ').map(Number));\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < strs[0].length; i++) {\n const obj = {};\n for (let j = 0; j < strs.length; j++) {\n if (obj[strs[j][i]]) {\n obj[strs[j][i]]++;\n }\n else {\n obj[strs[j][i]] = 1;\n }\n }\n\n const values = Object.values(obj).sort((a, b) => b - a);\n ans += values[0] * points[i];\n }\n\n console.log(ans);\n});\n", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const scores = [];\n for (let i = 1; i < lines.length - 2; i++) {\n scores.push(lines[i]);\n }\n let values = lines[lines.length - 2].split(' ');\n values = values.map(val => parseInt(val, 10));\n getMaxScore(scores, values);\n});\n\nfunction getMaxScore(scores, values) {\n const buckets = [];\n buckets.length = 5;\n buckets.fill(0);\n\n const mapping = {\n A: 0,\n B: 1,\n C: 2,\n D: 3,\n E: 4,\n };\n\n let score = 0;\n for (let i = 0; i < scores[0].length; i++) {\n for (let j = 0; j < scores.length; j++) {\n const answer = scores[j][i];\n buckets[mapping[answer]]++;\n }\n const max = Math.max(...buckets);\n score += (max * values[i]);\n buckets.fill(0);\n }\n console.log(score);\n}\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet [n, k] = line.shift().split(' ').map(v => parseInt(v,10));\n\tlet ans = [];\n\tfor(let i = 0; i < n; i++){\n\t\tans.push(line.shift());\n\t}\n\tlet point = line.shift().split(' ').map(v => parseInt(v, 10));\n\t\n\tlet sum = 0;\n\tlet a = 'A'.charCodeAt(0);\n\tfor(let i = 0; i < k; i++){\n\t\tlet o = [0,0,0,0,0];\n\t\tfor(let j = 0 ; j < n; j++){\n\t\t\to[ans[j].charCodeAt(i) - a]++;\n\t\t}\n\t\t\n\t\tsum += Math.max(...o) * point[i];\n\t}\n\tconsole.log(sum);\n}\n\nprocess.stdin.on('end', solution);"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet [n, k] = line.shift().split(' ').map(v => parseInt(v,10));\n\tlet ans = [];\n\tfor(let i = 0; i < n; i++){\n\t\tans.push(line.shift());\n\t}\n\tlet point = line.shift().split(' ').map(v => parseInt(v, 10));\n\t\n\tlet sum = 0;\n\tfor(let i = 0; i < k; i++){\n\t\tlet o = {A: 0, B: 0, C: 0, D: 0, E: 0};\n\t\tfor(let j = 0 ; j < n; j++){\n\t\t\to[ans[j][i]]++;\n\t\t}\n\t\t\n\t\tlet max = 0;\n\t\tfor(let m in o){\n\t\t\tmax = Math.max(o[m], max);\n\t\t}\n\t\tsum += max * point[i];\n\t}\n\tconsole.log(sum);\n}\n\nprocess.stdin.on('end', solution);"}, {"source_code": "var keys = { A: 0, B: 1, C: 2, D: 3, E: 4 };\n\nvar nm = readline().split(' ').map(item => +item);\n\nvar answers = [];\nfor(var i = 0; i < nm[0]; i++) {\n answers.push(readline());\n}\n\nvar sum = 0, vals = readline().split(' ').map(item => +item), ans = new Array(5);\n\nfor(var i = 0; i < nm[1]; i++) {\n ans.fill(0);\n for(var j = 0; j < nm[0]; j++) {\n ans[keys[answers[j][i]]]++;\n }\n sum += Math.max(...ans) * vals[i];\n}\n\nprint(sum);\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var m = input[1];\n var M = crAr(m);\n for (var i = 0; i < M.length; ++i) {\n M[i] = {};\n M[i]['A'] = 0;\n M[i]['B'] = 0;\n M[i]['C'] = 0;\n M[i]['D'] = 0;\n M[i]['E'] = 0;\n }\n for (var i = 0; i < n; ++i) {\n var s = rdS();\n for (var j = 0; j < s.length; ++j) {\n ++M[j][s[j]];\n }\n }\n //prOb(M);\n var A = rdArN();\n var res = 0;\n for (var i = 0 ; i < m; ++i) {\n var max = -Infinity;\n for (var key in M[i]) {\n max = Math.max(max, M[i][key]);\n }\n res += max*A[i];\n //pr(max*A[i])\n }\n wr(res);\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const scores = [];\n for (let i = 1; i < lines.length - 1; i++) {\n scores.push(lines[i]);\n }\n let values = lines[lines.length - 1].split(' ');\n values = values.map(val => parseInt(val, 10));\n getMaxScore(scores, values);\n});\n\nfunction getMaxScore(scores, values) {\n const buckets = [];\n buckets.length = 5;\n buckets.fill(0);\n\n const mapping = {\n A: 0,\n B: 1,\n C: 2,\n D: 3,\n E: 4,\n };\n\n let score = 0;\n for (let i = 0; i < scores[0].length; i++) {\n for (let j = 0; j < scores.length; j++) {\n const answer = scores[j][i];\n buckets[mapping[answer]]++;\n }\n const max = Math.max(...buckets);\n score += (max * values[i]);\n buckets.fill(0);\n }\n console.log(score);\n}\n"}], "src_uid": "2022f53e5a88d5833e133dc3608a122c"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n if(N == 2){\n output[i] = 2;\n }else{\n output[i] = N % 2;\n }\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet cases, arr = [], toBuy = [];\n\nrl.on('line', n => {\n if (!cases) { cases = n } else {\n arr.push(n);\n cases--;\n if (cases === 0) {\n arr.map(Number).forEach(num => {\n num < 4 ? toBuy.push(4 - num) : num % 2 === 0 ? toBuy.push(0) : toBuy.push(1);\n });\n toBuy.forEach(num => console.log(num));\n rl.close();\n }\n }\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const n = +d;\n\n if (n === 2) {\n console.log(2);\n }\n else if (n % 2 === 0) {\n console.log(0);\n }\n else {\n console.log(1);\n }\n\n c++;\n});\n"}, {"source_code": "let fs=require('fs');\nlet txt=fs.readFileSync(0,\"utf-8\").split(\"\\r\\n\").filter(data=>{return data.length>0});\ntxt.shift()\n\ntxt.forEach(data=>{\n matches(data*1);\n})\n\nfunction matches(num){\n let res=Math.ceil(num/2);\n let other=Math.floor(num/2);\n let add=0\n if(other data += c);\nconst sol = () => {\n let [k, ...nums] = data.trim().split('\\n').map(v => Number(v));\n let ans = [];\n for(let n of nums){\n \tans.push((n < 3)?(4 - n):(n%2));\n }\n console.log(ans.join('\\n'));\n}\nprocess.stdin.on('end', sol);"}, {"source_code": "var s = '';\nvar n = 0;\n\nprocess.stdin.on('data', function (c) {\n s += c;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n main();\n});\n\nfunction readline() {\n return s[n++];\n}\n\nfunction main() {\n var T = parseInt(readline());\n for (var t = 0; t < T; ++t) {\n var n = parseInt(readline());\n if (n === 2) {\n console.log(2);\n } else if (n % 2 == 1) {\n console.log(1);\n } else {\n console.log(0);\n }\n }\n}"}, {"source_code": "//'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet t = Date.now();\n\nlet currentLine = 0;\nlet i = '';\nprocess.stdin.on('data', c => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n i = i.trim()\n .split('\\n')\n .map(string => {\n return string.trim();\n });\n main();\n});\n\nfunction readLine() {\n return i[currentLine++];\n}\n\n\n\n\nfunction main() {\n var x = readLine();\n let j = 0;\n for (j = 0; j < x; j++) {\n var cq = readLine();\n //console.log('current query' + cq);\n if (cq == 2) {\n console.log(2);\n } else {\n var rs = cq - Math.floor(cq / 2); //console.log('rs ' + rs);\n var ls = Math.floor(cq / 2); //console.log('ls ' + ls);\n if (ls === rs)\n console.log('0');\n else {\n console.log(rs - ls);\n }\n }\n }\n}"}, {"source_code": "(function() {\n var q = Number(readline());\n while (q--) {\n var n = parseInt(readline());\n if (n == 2)\n print(2);\n else\n print(n % 2);\n }\n})();\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const n = Number(input[0]);\n const queries = input.slice(1).map(Number);\n queries.forEach(v => {\n if (v === 1) console.log(3);\n else if (v === 2) console.log(2); \n else {\n if (v % 2 === 1) console.log(1);\n else console.log(0); \n }\n })\n});"}, {"source_code": "const readline = require(\"readline\").createInterface(process.stdin, process.stdout);\nvar linesLeft,\n result = '';\nreadline.on(\"line\", line => {\n if (linesLeft === undefined)\n linesLeft = parseInt(line);\n else{\n solution(line);\n if (!(--linesLeft > 0))\n readline.close();\n }\n}).on(\"close\",() => {\n console.log(result)\n process.exit(0);\n});\n\nfunction solution (input){\n result += (input > 2 ? input % 2 : 2) + '\\n';\n return input % 2;\n}\n"}, {"source_code": "'use strict'\n \nlet n; readline();\nwhile(n = parseInt(readline())) { write((n < 5 ? 4 - n : n % 2) + '\\n'); }"}, {"source_code": "'use strict';\n\nmain();\n\nfunction main() {\n let cases = parseInt(readline());\n while ( cases-- > 0 ) {\n print(solve());\n }\n}\n\nfunction solve() {\n let matches = parseInt(readline());\n matches -= 4; // 1 + 1 = 2, basic equation\n\n return ( ( matches < 0 ) ? -1 * matches : matches % 2 );\n}"}, {"source_code": "var q = parseInt(readline());\nvar input = []\nwhile (q != 0) {\n q--;\n input.push(parseInt(readline()));\n}\ninput\n .map(n => n == 2 ? 2 : n % 2)\n .forEach(z => print(z))"}, {"source_code": "var q = parseInt(readline())\nvar mass = []\nmass.length = q\nfor (var i = 0; i < q; i++) mass[i] = parseInt(readline())\nfor (var i = 0; i < q; i++) {\n var n = mass[i]\n if (n == 2) print(2)\n else if (n % 2 == 0)\n print(0)\n else print(1)\n}"}, {"source_code": "n = +readline();\nvar q;\nfor (var i = 0; i < n;i ++){\n q = +readline();\n if (q === 1) { print(2)}\n else if (q === 2) { print(2)}\n else {\n if (q % 2 === 0){\n print(0);\n }\n else { print(1)}\n }\n}"}, {"source_code": "var q = readline();\nvar n;\nfor (var i = 0; i (num % 2) + (num < 4 ? (4 - num) : 0))\n .forEach(z => print(z))"}, {"source_code": "//'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet t = Date.now();\n\nlet currentLine = 0;\nlet i = '';\nprocess.stdin.on('data', c => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n i = i.trim()\n .split('\\n')\n .map(string => {\n return string.trim();\n });\n main();\n});\n\nfunction readLine() {\n return i[currentLine++];\n}\n\n\n\n\nfunction main() {\n var x = readLine();\n console.log(x);\n let j = 0;\n for (j = 0; j < x; j++) {\n var cq = readLine();\n //console.log('current query' + cq);\n if (cq == 2) {\n console.log(2);\n } else {\n var rs = cq - Math.floor(cq / 2); //console.log('rs ' + rs);\n var ls = Math.floor(cq / 2); //console.log('ls ' + ls);\n if (ls === rs)\n console.log('0');\n else {\n console.log(rs - ls);\n }\n }\n }\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const n = Number(input[0]);\n const queries = input.slice(1).map(Number);\n console.log(queries);\n queries.forEach(v => {\n if (v === 1) console.log(3);\n else if (v === 2) console.log(2); \n else {\n if (v % 2 === 1) console.log(1);\n else console.log(0); \n }\n })\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\nconst sol = () => {\n let nums = data.split('\\n').map(v => Number(v));\n nums.shift();\n let ans = [];\n for(let n of nums){\n \tans.push((n < 3)?(4 - n):(n%2));\n }\n console.log(ans.join('\\n'));\n}\nprocess.stdin.on('end', sol);"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\nconst sol = () => {\n let [k, ...nums] = data.split('\\n').map(v => Number(v));\n let ans = [];\n for(let n of nums){\n \tans.push((n < 3)?(4 - n):(n%2));\n }\n console.log(ans.join('\\n'));\n}\nprocess.stdin.on('end', sol);"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\nconst sol = () => {\n let nums = data.split('\\n').map(v => parseInt(v,10));\n nums.shift();\n let ans = [];\n for(let n of nums){\n \tans.push((n < 3)?(4 - n):(n%2));\n }\n console.log(ans.join('\\n'));\n}\nprocess.stdin.on('end', sol);"}], "src_uid": "178876bfe161ba9ccfd80c9310f75cbc"} {"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = Number(input[0])\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + i * 2])\r\n const a = input[1 + i * 2 + 1].split(' ').map((x) => parseInt(x))\r\n\r\n const ans =\r\n a.reduce((prev, current) => prev + current, 0) - Math.min(...a) * n\r\n console.log(ans)\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())", "positive_code": [{"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e= 0, g = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j], g= 0\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b}), a = k[0]\n for(l = 1; l < e; l++){\n g += k[l] - a\n }\n console.log(g)\n }\n }\n \n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = 0;\n var a = k[0];\n for(i = 1; i < e; i++){\n ans += k[i] - a;\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "/*\r\nFile Created: Tuesday, 17 May 2022\r\nAuthor: Lukas Rimkus\r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\n data += chunk;\r\n});\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '').split('\\n').map(str => str.replace(/\\s*$/, ''));\r\n let testCases = parseInt(readLine());\r\n while(testCases--) {\r\n const n = parseInt(readLine());\r\n const arr = get_ints();\r\n console.log(solve([n,arr]));\r\n }\r\n});\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(Number);\r\n}\r\n\r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction solve(input){\r\n let candies = 0;\r\n const min = Math.min(...input[1]);\r\n for (let index = 0; index < input[1].length; index++) {\r\n candies+= input[1][index] - min;\r\n } \r\n return candies;\r\n}\r\n\r\nmodule.exports = solve;"}, {"source_code": "\r\n\r\nconst { createInterface } = require('readline');\r\n/*\r\nconst { createWriteStream, createReadStream } = require('fs');\r\nconst { format } = require('util');\r\nconst log_file = createWriteStream('output.txt', { flags: 'w' }\r\n);\r\nconst log_stdout = process.stdout;\r\nconsole.log = function (d) {\r\n log_file.write(format(d) + '\\n');\r\n log_stdout.write(format(d) + '\\n');\r\n};\r\nconst fileStream = createReadStream('input.txt');\r\n*/\r\nfunction main() {\r\n const readline = createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let lineNb = 0;\r\n let n;\r\n let t = [];\r\n let currentLength = -1;\r\n readline.on('line', line => {\r\n if (!lineNb)\r\n n = parseInt(line) * 2;\r\n else if (!(lineNb % 2)) {\r\n let sum = 0;\r\n let array = line.split(\" \");\r\n let min = parseInt(array[0])\r\n t = (line.split(\" \").map(i => {\r\n let currentNumber = Number(i);\r\n sum += currentNumber\r\n if (min > currentNumber) min = currentNumber\r\n return Number(i);\r\n }));\r\n console.log(sum - min * currentLength)\r\n } else {\r\n currentLength = parseInt(line)\r\n }\r\n if (lineNb === n)\r\n readline.close();\r\n lineNb++;\r\n });\r\n\r\n}\r\n\r\nmain()"}, {"source_code": "\r\n\r\nconst { createInterface } = require('readline');\r\n/*\r\nconst { createWriteStream, createReadStream } = require('fs');\r\nconst { format } = require('util');\r\nconst log_file = createWriteStream('output.txt', { flags: 'w' }\r\n);\r\nconst log_stdout = process.stdout;\r\nconsole.log = function (d) {\r\n log_file.write(format(d) + '\\n');\r\n log_stdout.write(format(d) + '\\n');\r\n};\r\nconst fileStream = createReadStream('input.txt');\r\n*/\r\nfunction main() {\r\n const readline = createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let lineNb = 0;\r\n let n;\r\n let t = [];\r\n let currentLength = -1;\r\n readline.on('line', line => {\r\n if (!lineNb)\r\n n = parseInt(line) * 2;\r\n else if (!(lineNb % 2)) {\r\n let sum = 0;\r\n t = (line.split(\" \").map(i => {\r\n var currentNumber = Number(i);\r\n sum += currentNumber\r\n return Number(i);\r\n }));\r\n const min = Math.min(...t);\r\n console.log(sum - min * currentLength)\r\n } else {\r\n currentLength = parseInt(line)\r\n }\r\n if (lineNb === n)\r\n readline.close();\r\n lineNb++;\r\n });\r\n\r\n}\r\n\r\nmain()"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var a = k[0];\n var ans = 0;\n for(j = 1; j < e; j++){\n ans += k[j] - a;\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = 0;\n var a = k[0];\n for(i = 1; i < e; i++){\n ans += k[i] - a;\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const arr = d\n .split(\" \")\n .map(Number)\n .sort((a, b) => a - b);\n const min = arr[0];\n let ans = 0;\n\n for (let i = 1; i < arr.length; i++) {\n if (min < arr[i]) {\n ans += arr[i] - min;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let min = Math.min(...arr);\r\n\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i] - min;\r\n }\r\n\r\n output(sum);\r\n }\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \").map(Number).sort(function(a, b) {\r\n return a - b;\r\n });\r\n var sum = 0;\r\n var min = a[0];\r\n for (let j = 0; j < n; j++) {\r\n \r\n if (a[j] === min) {\r\n sum = 0 + sum;\r\n } else {\r\n sum = sum + a[j] - min;\r\n }\r\n }\r\n \r\n console.log(sum)\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet s = a.reduce((x, ac) => ac + x, 0);\n\t\tlet m = a.reduce((x, ac) => x < ac?x:ac, a[0]);\n\t\tans.push(s - m*n);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n \r\n function foo (data) {\r\n const numberData = data.split(' ').map(Number);\r\n const min = Math.min(...numberData);\r\n\r\n return numberData.reduce((acc, value) => {\r\n const diff = value - min;\r\n return acc + diff;\r\n }, 0);\r\n }\r\n \r\n let testCount = 1;\r\n const rowsInTest = 2;\r\n let answer = '';\r\n while(testCount <= +lines[0]) {\r\n let data = lines[testCount * rowsInTest];\r\n let result = foo(data);\r\n answer += result +\"\\n\";\r\n testCount += 1;\r\n }\r\n console.log(answer);\r\n})\r\n"}, {"source_code": "const solve = (arr,n) => {\r\n let min = Infinity,cnt = 0;\r\n for(let i=0;iparseInt(cur));\r\n solve(arr,l);\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let min = Math.min(...a);\r\n let res = 0;\r\n for (let num of a) {\r\n res += num - min;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\nconst findMinimum = (array) => {\n let result = array[0];\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (result > element) {\n result = element;\n }\n }\n\n return result;\n};\n\nlet lines = 0;\n\nrl.on(\"line\", function (line) {\n if (lines !== 0 && lines % 2 === 0) {\n let input = line.split(\" \").map(Number);\n const minimum = findMinimum(input);\n console.log(input.reduce((sum, candies) => sum + candies - minimum, 0));\n }\n lines++;\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n let n = parseInt(input());\r\n const a = input().split(' ').map(Number);\r\n let min_a = 1e7;\r\n for(let i of a) min_a = Math.min(min_a, i);\r\n let ans = 0;\r\n for(let i of a) if(i > min_a) ans += i-min_a;\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n let min = Number.MAX_VALUE;\r\n for (let i = 0; i < arr.length; i++) {\r\n min = Math.min(min, arr[i]);\r\n }\r\n let eat = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n eat += arr[i] !== min ? arr[i] - min : 0;\r\n }\r\n return eat;\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var n = readline();\r\n var a = readline().split(' ').map((x)=>parseInt(x));\r\n var ans = 0;\r\n var mn = 100000001;\r\n var sum = 0;\r\n for(var i=0;i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let min = Math.min.apply(null, A);\n let ans = 0;\n for (let a of A)\n ans += a-min;\n return ans;\n};\n "}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let min = arr[0]\n for (let i = 0; i < arr.length; i++) {\n min = Math.min(min, arr[i])\n }\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n ans += arr[i] - min\n }\n return ans\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar min = 100000000;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmin = Math.min(min, list[i]);\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput += list[i] - min;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var testCase = +readline(),counter\r\nfor(var i=0;i+node)\r\n var minValue=sequence.reduce((a,b)=>Math.min(a,b))\r\n for(var j=0;j readline();\r\nconst readStrArr = () => readline().split(' ');\r\n\r\nconst n = readStr();\r\nfor(var i = 0; i < n; i++) {\r\n var k = readStr();\r\n var a = readStrArr();\r\n if(k === '1'){\r\n print(0);\r\n continue;\r\n }\r\n var min = Math.min(...a), sum = 0;\r\n for(var j = 0; j < k; j++) {\r\n sum += a[j] - min;\r\n }\r\n print(sum);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n\r\n var sum = parseInt(arr[0]);\r\n var min = parseInt(arr[0]);\r\n\r\n for (var i = 1; i < n; i++) {\r\n sum += parseInt(arr[i]);\r\n min = Math.min(min, parseInt(arr[i]));\r\n }\r\n\r\n print(sum - min * n);\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ;i++){\r\n var n = readline();\r\n var a = readline().split(' ');\r\n a.sort( (a,b) => {return a-b});\r\n var min = a[0] , counter = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n counter+= (a[j] - a[0]);\r\n }\r\n print(counter);\r\n}"}, {"source_code": "var n = +readline()\r\n\r\nfor(var i=0;i max){\r\n max =+arr[j];\r\n }\r\n }\r\n \r\n if(min === max){\r\n print(0);\r\n }else{\r\n var op = 0;\r\n for(var j=0;j min){\r\n op += +arr[j] - min;\r\n }\r\n }\r\n print(op)\r\n }\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = +readline()\r\n a = readline().split(' ').map(a => +a)\r\n a.sort((prev, next) => prev - next)\r\n\r\n ans = 0\r\n for(i=1; i< n; i++){\r\n ans += a[i] - a[0]\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "t = parseInt(readline());\r\nfor(i = 0; i < t; i++)\r\n{\r\n var n = readline();\r\n n = readline().split(\" \");\r\n var min = 10000001;\r\n var sum = 0;\r\n for(j = 0; j < n.length; j++)\r\n {\r\n sum += parseInt(n[j]);\r\n if(parseInt(n[j]) < min) min = n[j];\r\n }\r\n print(sum - min*n.length);\r\n}"}, {"source_code": "var n = readline()\r\n\r\nfor(var i=0 ; i +t);\r\n \r\n print(Task2(b));\r\n}\r\n \r\nfunction Task2 (arr){\r\n \r\n var min = Math.min(...arr);\r\n var count = 0;\r\n for(var i = 0; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e= 0, g = 0\n for(j = 1; j <= n; j++){\n if(j % 2 == 1){\n e = lines[j], g= 0\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b}), a = k[0]\n for(l = 1; l < e; l++){\n g += k[l] - a\n }\n console.log(g)\n }\n }\n \n});//k[k.length - 1] == '' || "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main()\r\n}); \r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const n = input().split('').map(Number);\r\n const a = input().split('').map(Number);\r\n console.log(solve([n,a]))\r\n }\r\n}\r\n\r\nfunction solve(input){\r\n let candies = 0;\r\n const min = Math.min(...input[1]);\r\n for (let index = 0; index < input[1].length; index++) {\r\n candies+= input[1][index] - min;\r\n } \r\n console.log(candies)\r\n return candies;\r\n}\r\n\r\nmodule.exports = solve;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main()\r\n}); \r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const n = input().split('').map(Number);\r\n const a = input().split('').map(Number);\r\n ans = solve([n,a]);\r\n console.log(ans)\r\n }\r\n}\r\n\r\nfunction solve(input){\r\n let candies = 0;\r\n const min = Math.min(...input[1]);\r\n for (let index = 0; index < input[1].length; index++) {\r\n candies+= input[1][index] - min;\r\n } \r\n return candies;\r\n}\r\n\r\nmodule.exports = solve;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main()\r\n}); \r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const n = input().split('').map(Number);\r\n const a = input().split('').map(Number);\r\n console.log(solve([n,a]))\r\n }\r\n}\r\n\r\nfunction solve(input){\r\n let candies = 0;\r\n const min = Math.min(...input[1]);\r\n for (let index = 0; index < input[1].length; index++) {\r\n candies+= input[1][index] - min;\r\n } \r\n return candies;\r\n}\r\n\r\nmodule.exports = solve;"}, {"source_code": "var testCase = readline().split(\"\"),counter\r\nfor(var i=0;i+node)\r\n var minValue=sequence.reduce((a,b)=>Math.min(a,b))\r\n for(var j=0;j ans) {\n ans = x;\n }\n if (x < 0) {\n x = 0;\n }\n if (i + 1 < n) {\n sum += a[i + 1];\n y += (a[i] - a[i + 1]);\n if (y > ans) {\n ans = y;\n }\n if (y < 0) {\n y = 0;\n }\n }\n }\n write(ans + sum);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n while (T--) {\n const n = s2i(readLine())\n const arr = readLine().split(' ').map(s2i)\n\n let sumEven = arr[0]\n let sum01 = 0\n let sum12 = 0\n let max = 0\n for (let i = 1, even = false, curr = sumEven; i < n; i++, even = !even) {\n const prev = curr\n curr = arr[i]\n if (even) {\n sumEven += curr\n sum01 += prev - curr\n if (sum01 < 0) {\n sum01 = 0\n } else {\n max = Math.max(max, sum01)\n }\n } else {\n sum12 += curr - prev\n if (sum12 < 0) {\n sum12 = 0\n } else {\n max = Math.max(max, sum12)\n }\n }\n }\n\n out += (sumEven + max) + '\\n'\n }\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n let o = new Array(10);\n let z = new Array(10);\n o.fill(0);\n z.fill(0);\n for(let i = 0; i < m; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(b[i] & t !== 0)\n o[j] = 1;\n else\n z[j] = 1;\n\n t << 1;\n }\n }\n\n let c = new Array(10);\n for(let i = 0; i < n; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(a[i] & t !== 0){\n if(z[j] === 1)\n c[j] = 0;\n else\n c[j] = 1;\n }\n t << 1;\n }\n }\n\n let res = 0;\n for(let i = 9; i >= 0; i--){\n res += pi(c[i])*Math.pow(2,9-i);\n }\n console.log(res);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t){\n t--;\n let [n,k,z] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n // pre -> 0,1 -> right,left\n let dp = new Array(z+1);\n for(let i = 0; i < z+1; i++){\n dp[i] = new Array(n);\n dp[i].fill(-1);\n }\n \n let solve = (i,j,index,pre) => {\n if(index < 0 || index >= n)\n return 0;\n if(i > k)\n return 0;\n if(dp[j][index] !== -1)\n return dp[j][index];\n if(pre){\n return dp[j][index] = a[index] + solve(i+1, j, index+1, 0);\n }else{\n return dp[j][index] = a[index] + Math.max(j < z ? solve(i+1,j+1,index-1,1) : 0, solve(i+1,j,index+1,0));\n }\n }\n\n console.log(solve(0,0,0,1));\n }\n}\n\nfunction E1(){\n let [n,k] = ti(readline().split(' '));\n let t = new Array(n);\n for(let i = 0; i < n; i++){\n t[i] = ti(readline().split(' '));\n }\n let ab = [];\n let a = [];\n let b = [];\n let unlikeCount = 0;\n\n for(let i = 0; i < n; i++){\n if(t[i][1] === 1 && t[i][2] === 1){\n ab.push(t[i]);\n }else if(t[i][1] === 1){\n a.push(t[i]);\n }else if(t[i][2] === 1){\n b.push(t[i]);\n }else{\n unlikeCount += 1;\n }\n }\n\n ab.sort((x,y) => x[0]-y[0]);\n a.sort((x,y) => x[0]-y[0]);\n b.sort((x,y) => x[0]-y[0]);\n // let max = Math.max(max, ab.length, a.length, b.length);\n // let min = Math.min(min, ab.length, a.length, b.length);\n // let inf = 9999999999;\n // for(let i = min+1; i <= max; i++){\n // if(i >= ab.length) ab.push(inf);\n // if(i >= a.length) a.push(inf);\n // if(i >= b.length) b.push(inf);\n // }\n\n let p1 = p2 = p3 = 0;\n let ka = k;\n let kb = k;\n let res = 0;\n while(p1 < ab.length || p2 < a.length || p3 < b.length){\n if(ka === 0 && kb === 0)\n break;\n if(p2 < a.length && p3 < b.length){\n if(p1 < ab.length){\n if(a[p2][0]+b[p3][0] > ab[p1][0]){\n res += ab[p1][0];\n p1++;\n }else{\n res += a[p2][0]+b[p3][0];\n p2++;\n p3++;\n }\n }else{\n res += a[p2][0]+b[p3][0];\n p2++;\n p3++;\n }\n ka--;\n kb--;\n }else{\n if(p1 >= ab.length){\n console.log(-1);\n return;\n }\n res += ab[p1][0];\n ka--;\n kb--;\n p1++;\n }\n }\n if(ka !== 0 || kb !== 0){\n console.log(-1);\n return;\n }\n console.log(res);\n}\n\nfunction D(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let sum1 = new Array(n);\n let sum2 = new Array(n);\n sum1[0] = -1*a[0];\n sum2[0] = a[0];\n for(let i = 1; i < n; i++){\n if(i%2 === 0){\n sum1[i] = sum1[i-1] - a[i]; \n }else{\n sum1[i] = sum1[i-1] + a[i];\n }\n }\n\n let min = 99999999999;\n let [l,r] = [-1,-1];\n let max = 0;\n let minIndex = 0;\n for(let i = 0; i < n; i+=2){\n if(min > sum1[i]){\n min = sum1[i];\n minIndex = i;\n }\n\n if(max < sum1[i]-min){\n max = sum1[i]-min;\n [l,r] = [minIndex+1,i];\n }\n }\n\n min = 0;\n minIndex = -1;\n for(let i = 1; i < n; i+=2){\n if(min > sum1[i]){\n min = sum1[i];\n minIndex = i;\n }\n\n if(max < sum1[i]-min){\n max = sum1[i]-min;\n [l,r] = [minIndex+1,i];\n }\n }\n\n let res = 0;\n for(let i = 0; i < n; i++){\n if(i < l || i > r){\n if(i%2 === 0)\n res += a[i];\n }\n else{\n if(i%2 !== 0)\n res += a[i];\n }\n }\n\n console.log(res);\n }\n}"}], "negative_code": [], "src_uid": "3696b769bfd32cba34e739b74e13693f"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar digitNum = parseInt(readline());\n\tvar s = trim(readline());\n\n\tvar pos = (digitNum%2 == 0 ? 2 : 3);\n\twrite(s.substring(0, pos));\n\n\twhile (pos < digitNum) {\n\t\twrite(\"-\"+s.substring(pos, pos+2));\n\t\tpos += 2;\n\t}\n\tprint();\n}\n\nmain();\n", "positive_code": [{"source_code": "var size = readline(), number = readline(), ans = []\nvar go = number.length, index = 0\nwhile (go){\n\tvar nxt = (go%2) ? 3 : 2\n\tans.push(number.slice(index,index+nxt))\n\tindex+= nxt; go-=nxt\n}\nprint(ans.join(\"-\"))"}, {"source_code": "'use strict'\n\nlet N = +readline()\nlet L = readline()\n\nlet res = []\n\nfor (let i = 0; i <= N; i = i + 2) {\n res.push(L.slice(i, i + 2))\n}\n\nres = res.filter(Boolean)\n\nif (N % 2) {\n res[res.length - 2] += res[res.length - 1]\n res.length--\n}\n\nprint(res.filter(Boolean).join('-'))"}, {"source_code": "var n=readline(); n=parseInt(n);\nvar arr=readline(); \nvar three=0,two=0;\nfor(var i=0;i<=100;i++)\n{\n for(var j=0;j<=100;j++)\n {\n var temp=n-i*2-j*3; \n if(temp==0)\n {\n three=j; two=i;\n }\n }\n}\nvar num=0; var ans=\"\";\nfor(var i=0;i {if (num > max) max = num;}\nfor (var i = N; i--; ) {\n max = -Infinity;\n readline().split(' ').forEach(updateMax);\n q.push(max);\n}\nprint(q.join(' ').replace(N-1, N));\n"}, {"source_code": "var N = parseInt(readline());\nvar q = [], ans = [];\nfor (var i = N; i--; ) {\n q.push(' '+readline().replace(/0/g, ''));\n}\nfor (var i = 1, flag; i < N; ++i) {\n flag = false;\n for (var j = 0; j < N; ++j) {\n q[j] = q[j].replace(new RegExp(` ${i}`, 'g'), '');\n if (q[j] === ' ' && !ans[j] && !flag) {\n ans[j] = i;\n flag = true;\n }\n }\n}\nfor (var i = 0; i < N; ++i) {\n if (typeof ans[i] === 'undefined') {\n ans[i] = N;\n }\n}\nprint(ans.join(' '));\n"}], "src_uid": "1524c658129aaa4175208b278fdc467c"} {"source_code": "var cnt = new Array(4).fill(0);\ncnt[0] = Number.MAX_SAFE_INTEGER;\nreadline();\nreadline().split(\" \").map((x)=>{ cnt[x]++; });\nvar out = 0;\nvar min = Math.min(...cnt);\nout += min;\ncnt.splice(cnt.indexOf(min),1);\nout += Math.min(...cnt);\nprint(out);", "positive_code": [{"source_code": "'use strict'\n\nlet N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v))\n\nlet c = [0, 0, 0]\nfor (let i = 0; i < N; i++) {\n c[lll[i] - 1]++\n}\nprint(c[0] + c[1] + c[2] - Math.max(c[0], c[1], c[2]))"}, {"source_code": "var getNums = function() {\n\treturn readline().split(' ').map(function(a) {return parseInt(a)});\n};\n\nvar n = parseInt(readline());\nvar input = getNums();\nvar hash = {};\n\nfor(var j = 1; j <= 3; j++) {\n\thash[j] = 0;\n}\n\nfor (var i = 0; i < n; i++) {\n\thash[input[i]]++;\n}\n\nprint(Math.min(hash[1] + hash[2], hash[1] + hash[3], hash[3] + hash[2]));"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet indicator = 0, N;\nrl.on('line', (input) => {\n if (indicator == 0){\n N = parseInt(input);\n indicator++;\n }\n else {\n let cont = input.split(' ').map(item => parseInt(item))\n let dict = {};\n let maxval = 0;\n cont.forEach(item => {\n if (item in dict)\n dict[item]++;\n else\n dict[item] = 1;\n\n if (maxval < dict[item])\n maxval = dict[item];\n\n\n });\n console.log(N - maxval);\n rl.close();\n }\n});"}], "negative_code": [{"source_code": "var cnt = new Array(4).fill(0);\nreadline();\nreadline().split(\" \").map((x)=>{ cnt[x]++; });\nvar max = Math.max(...cnt);\nvar out = 0;\ncnt.map((x)=>{if(x!=max)out+=x;});\nprint(out);"}, {"source_code": "var cnt = new Array(4).fill(0);\ncnt.splice(cnt.indexOf(0),1);\nreadline();\nreadline().split(\" \").map((x)=>{ cnt[x]++; });\nvar out = 0;\nvar min = Math.min(...cnt);\nout += min;\ncnt.splice(cnt.indexOf(min),1);\nout += Math.min(...cnt);\nprint(out);"}, {"source_code": "var cnt = new Array(4).fill(0);\nreadline();\nreadline().split(\" \").map((x)=>{ cnt[x]++; });\nvar out = 0;\nvar min = Math.min(...cnt);\nout += min;\ncnt.splice(cnt.indexOf(min),1);\nout += Math.min(...cnt);\nprint(out);"}, {"source_code": "var getNums = function() {\n\treturn readline().split(' ').map(function(a) {return parseInt(a)});\n};\n\nvar n = parseInt(readline());\nvar input = getNums();\nvar hash = {};\n\nfor (var i = 0; i < n; i++) {\n\tvar a = input[i];\n\tif (hash[a]) {\n\t\thash[a]++;\n\t} else {\n\t\thash[a] = 1;\n\t}\n}\n\nprint(Math.min(hash[1] + hash[2], hash[1] + hash[3], hash[3] + hash[2]));\n"}], "src_uid": "fcb6a715dfe302d7ae5a6695ca8976aa"} {"source_code": "'use strict'\n\nlet N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => b - a)\n\nlet ss = 0\nlet p = [0]\nlet t = false\n\nfor (let n of lll) {\n if (n % 2) {\n t = true\n p.push(n)\n if (p.length == 2) {\n ss += p[0]\n ss += p[1]\n p = []\n }\n } else {\n ss += n\n }\n}\n\nprint(t ? ss : 0)", "positive_code": [{"source_code": "readline = require('readline')\nlet stdinInput = '';\n\nfunction file1(){\n //file\n var fs = require('fs');\n const inputfile = '_in.txt';\n const outputfile = '_out.txt';\n fs.writeFileSync(outputfile, '');\n var myInterface = readline.createInterface({\n input: fs.createReadStream(inputfile),\n });\n myInterface.on('line', function (line) {\n stdinInput += line+'\\n';\n }).on('close', () => {\n main(); \n process.exit(0);\n })\n}\n\nfunction std1(){\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n}\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n// file1();\nstd1();\n\nlet n, a, sum1;\nfunction main() {\n const is = new Scanner();\n n = parseInt(is.nextLine());\n a = is.nextArray(Number);\n\n sum1 = 0;\n minle = 101;\n for(let i=0; i b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n console.log(1, 1, k[0], k[1]);\n }\n});\n"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number)\n console.log(1, 1, k[0], k[1])\n }\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m, i, j] = rna();\r\n\r\n\t\tconsole.log(1, 1, n, m);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar i = nextInt();\r\n\t\tvar j = nextInt();\r\n\t\tmyout(H + \" \" + W + \" 1 1\");\r\n\t}\r\n}\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n, m, i, j;\r\n [n, m, i, j] = (await getLine()).split(' ').map(num => parseInt(num));\r\n let bestDist = -1, best1x, best2x, best1y, best2y;\r\n let getDist = function(x,y, x2, y2) {\r\n return Math.abs(x-x2) + Math.abs(y-y2);\r\n }\r\n let test = function(x1, y1, x2, y2) {\r\n const dist = getDist(i, j, x1, y1) + getDist(x1, y1, x2, y2) + getDist(i, j, x2, y2);\r\n if (dist > bestDist) {\r\n bestDist = dist;\r\n best1x = x1;\r\n best2x = x2;\r\n best1y = y1;\r\n best2y = y2;\r\n }\r\n }\r\n test(1,1,n, m);\r\n test(1, 1, 1, m);\r\n test(1, 1, n, 1);\r\n test(n, m, n, 1);\r\n test(n, m, 1, m);\r\n test(1, m, n, 1);\r\n console.log([best1x, best1y, best2x, best2y].join(' '));\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(...arr).join(' '));\n }\n});\n\nfunction solve(row, col, r, c) {\n if (r === 1) {\n return [row, 1, row, col]\n } else if (r === row) {\n return [1, 1, 1, col]\n } else if (c === 1) {\n return [1, col, row, col]\n } else if (c === col) {\n return [1, 1, row, 1]\n } else {\n return [1, 1, row, col]\n }\n}\n"}, {"source_code": "var cases = +readline();\r\n\r\nfor (var i = 1; i<=cases; i++){\r\n inp = readline().split(' ').map(x=>+x);\r\n n = inp[0];\r\n m = inp[1];\r\n \r\n print(1,1,n,m);\r\n}\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n console.log(1, 1, k[2], k[3]);\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var q = lines[i].split(' ').map(Number);\n var n = q[0], k = q[1];\n var b = 0;\n for(j = 2; j <= n; j++){\n if(n % j === 0){\n b = j;\n break;\n }\n }\n k--;\n n += b;\n n += (2*k);\n console.log(n);\n }\n});\n"}, {"source_code": "let ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j].split('')\n if(k[k.length - 2] == 'c' && k[k.length - 1] == 'h' || k[k.length - 1] == 'x' || k[k.length - 1] == 's' ||k[k.length - 1] == 'o' ){\n if(k[k.length - 2] == 'c' && k[k.length - 1] == 'h' ){\n k.push('es')\n }else{\n k.push('es')\n \n }\n }\n else if(k[k.length - 2] == 'e' && k[k.length - 1] == 'f' || k[k.length - 1] == 'f'){\n if(k[k.length - 2] == 'e' && k[k.length - 1] == 'f'){\n k.splice(k.length - 2, 2)\n k.push('ves')\n }else{\n k.splice(k.length - 1, 1)\n k.push('ves')\n }\n }\n else if(k[k.length - 1] == 'y'){\n k.splice(k.length - 1, 1)\n k.push('ies')\n }\n else{\n k.push('s')\n }\n s = ''\n for(l = 0; l < k.length; l++){\n s+=k[l]\n }\n console.log(s)\n }\n \n \n});"}], "src_uid": "5aae6b27f35852512a250751ef957ab9"} {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n const a = readLine().split(' ').map(num => Number(num)).sort((a, b) => a - b);\n const res = a.reduce((acc, cur) => [cur, acc[1] + (Math.abs(acc[0] - cur) > 1 ? 1 : 0)], [a[0], 0]);\n console.log(res[1] > 0 ? 'NO' : 'YES');\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let t = 0; t < N; ++t) {\n const b = readline();\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort((i, j) => i - j);\n\n let isYes = true;\n for (let k = 1; k < arr.length; ++k) {\n if (arr[k] - arr[k - 1] > 1) {\n print(\"NO\\n\");\n isYes = false;\n break;\n }\n }\n\n if (isYes) {\n print(\"YES\\n\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = ''\nlet currentLine = 0\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n \n main()\n})\n \nfunction readLine() {\n return inputString[currentLine++]\n}\n \nconst s2i = s => parseInt(s, 10)\n \nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n \nconst cmpi = (a, b) => a - b\n \nfunction main() {\n let T = s2i(readLine())\n let out = ''\n \n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n \n let result = 'YES'\n \n a.sort(cmpi)\n \n for (let i = 1; i < a.length; i++) {\n if (a[i] - a[i-1] > 1) {\n result = 'NO'\n break\n }\n }\n \n out += result + '\\n'\n }\n \n console.log(out)\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r x - y);\n if(a.length === 1) {\n console.log('YES');\n return;\n }\n\n for(let i=1;i 1) {\n console.log('NO');\n return;\n }\n }\n\n console.log('YES');\n\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n let count = 0;\n for (let i = 0; i < len - 1; i++) {\n if (Math.abs(arr[i] - arr[i + 1]) > 1) count++;\n }\n if (count) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet input = [];\n\nrl.on('line', function (line) {\n input.push(line);\n});\n\nrl.on('close', function () {\n const total = Number(input[0]);\n for (let ii = 0; ii < 2*total; ii +=2) {\n let output = \"Yes\";\n const len = Number(input[ii+1]);\n let arr = input[ii+2].split(' ').map(x => Number(x));\n arr.sort((a, b) => a - b);\n for (let i = 0; i < total-1; i++) {\n if (arr[i + 1] - arr[i] > 1) {\n output = \"No\";\n break;\n }\n }\n console.log(output); \n }\n});\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line);\n}).on('close', () => {\n for (ii = 1; ii < tests.length; ii+= 2) {\n const test = tests[ii + 1].split(' ').sort((a, b) => +a - +b);\n let count = 0;\n for(i = 0; i < test.length; i++) {\n\n if (\n !test[i + 1] || \n Math.abs(+test[i] - +test[i + 1]) > 1\n ) {\n count++;\n }\n }\n if (count > 1) {\n process.stdout.write(`NO\\n`);\n } else {\n process.stdout.write(`YES\\n`);\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n list.sort(function(a,b){\n return a - b;\n });\n var isOK = true;\n for(var j = 0; j < n - 1; j++){\n if(Math.abs(list[j] - list[j + 1]) > 1){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 2;\n let i = 1;\n outer:\n\twhile (i <= testCases) {\n\t let n = data[i] * 1;\n\t let a = data[i + 1].trim().split(' ').map(Number);\n\t a.sort((a, b) => a - b);\n\t for (let j = 1; j < n; j += 1) {\n let diff = a[j] - a[j - 1];\n\t if (diff > 1) {\n\t console.log('NO');\n\t i += 2;\n\t continue outer;\n\t }\n\t }\n\t console.log('YES');\n i += 2;\n\t}\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let i = 0; i < t; i++){\n let n = parseInt(readline());\n let arr = readline().split(' ');\n arr.sort((a,b) => a-b);\n let flag = true;\n for(let j = 1; j < arr.length; j++){\n if(parseInt(arr[j])-parseInt(arr[j-1]) > 1){\n flag = false;\n console.log('NO');\n break;\n }\n }\n\n if(flag)\n console.log('yes');\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n let t = +readline();\n for (let i = 0; i < t; i++) {\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x)).sort((i, j) => i - j);\n let no = false;\n for (let j = 1; j < n; j++) {\n if (Math.abs(a[j] - a[j-1]) > 1) {\n print('NO\\n');\n no = true;\n break;\n }\n }\n if (!no) {\n print('YES\\n');\n }\n }\n}\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let t = parseInt(input[0]);\n\n for (let i = 1; i <= t * 2; i += 2) {\n const n = parseInt(input[i]);\n\n const nums = splitAndParseInt(input[i + 1]);\n nums.sort((a, b) => a - b);\n\n if (nums.length === 1) {\n console.log(\"YES\");\n continue;\n }\n\n let cnt = 0;\n for (let i = 1; i < nums.length; i += 1) {\n if (nums[i] - nums[i - 1] <= 1) cnt += 1;\n }\n\n if (nums.length - cnt <= 1) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n});\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc++]\n for (let i=0; i +x).sort((a, b) => a-b)\n let found = false\n for (let i=0; i 1) {\n found = true\n break\n }\n }\n\n console.log(found ? 'NO' : 'YES')\n }\n\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 'YES'\n\n a.sort(cmpi)\n\n for (let i = 1; i < a.length; i++) {\n if (a[i] - a[i-1] > 1) {\n result = 'NO'\n break\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tarr.sort((a, b) => a - b);\n\t\tlet count = 0;\n\n\t\tfor (let i = 0; i < n - 1; i++) {\n\t\t\tlet diff = Math.abs(arr[i] - arr[i + 1]);\n\t\t\tif (diff > 1) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\n\t\tif (count) {\n\t\t\tconsole.log('NO');\n\t\t} else {\n\t\t\tconsole.log('YES');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet possible = true;\n\t\tarr.sort((a, b) => a - b);\n\n\t\tfor (let i = 1, l = arr.length; i < l; ++i) {\n\t\t\tlet diff = arr[i] - arr[i - 1];\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tpossible ? console.log('YES') : console.log('NO');\n\t}\n}\n"}, {"source_code": "function compare(x, y) {\n return (x < y) ? (- 1) : ((x > y) ? 1 : 0);\n}\n\nconst yes = 'YES';\nconst no = 'NO';\n\nfunction solve(xs) {\n if (xs.length < 1) {\n throw Error('input is empty');\n } else if (xs.length < 2) {\n return yes;\n } else {\n xs.sort(compare);\n let max_diff = 0;\n for (let i = 1; i < xs.length; i = i + 1) {\n const a = xs[i - 1];\n const b = xs[i];\n const diff = b - a;\n max_diff = Math.max(max_diff, diff);\n }\n return (max_diff < 2) ? yes : no;\n }\n}\n\nfunction main(lines) {\n for (let i = 1; (i + 1) < lines.length; i = i + 2) {\n const line = lines[i + 1];\n const t = line.trim();\n if (t.length > 0) {\n const xs = t.split(/\\s/).map(Number);\n const result = solve(xs);\n console.log(result)\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function compare(x, y) {\n return (x < y) ? (- 1) : ((x > y) ? 1 : 0);\n}\n\nconst yes = 'YES';\nconst no = 'NO';\n\nfunction solve(xs) {\n if (xs.length < 1) {\n throw Error('input is empty');\n } else if (xs.length < 2) {\n return yes;\n } else {\n xs.sort(compare);\n let max_diff = 0;\n for (let i = 1; i < xs.length; i = i + 1) {\n const a = xs[i - 1];\n const b = xs[i];\n const diff = b - a;\n max_diff = Math.max(max_diff, diff);\n }\n return (max_diff < 2) ? yes : no;\n }\n}\n\nfunction main(lines) {\n const whitespace = /\\s+/;\n for (let i = 1; (i + 1) < lines.length; i = i + 2) {\n const line = lines[i + 1];\n const xs = line.split(whitespace).map(Number);\n const result = solve(xs);\n console.log(result)\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray().sort((a, b) => a - b)\n\n var prevNum = arr[0]\n var i\n for(i=1; i 1) {\n print(\"NO\")\n return\n }\n prevNum = arr[i]\n }\n print(\"YES\")\n}\n\nvar testCases = readInt();\nvar testCaseNum;\nfor(testCaseNum=0; testCaseNum {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n let count = 0;\n for (let i = 0; i < len - 1; i++) {\n if (Math.abs(arr[i] - arr[i + 1]) === 2) count++;\n }\n if (count) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n let t = +readline();\n for (let i = 0; i < t; i++) {\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n let no = false;\n for (let j = 1; j < n; j++) {\n if (Math.abs(a[j] - a[j-1]) > 1) {\n print('NO\\n');\n no = true;\n break;\n }\n }\n if (!no) {\n print('YES\\n');\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 'Yes'\n\n a.sort()\n\n for (let i = 1; i < a.length; i++) {\n if (a[i] - a[i-1] > 1) {\n result = 'NO'\n break\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 'YES'\n\n a.sort()\n\n for (let i = 1; i < a.length; i++) {\n if (a[i] - a[i-1] > 1) {\n result = 'NO'\n break\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tlet diff = arr[i] - arr[i - 1];\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t}\n\t\t}\n\n\t\tif (possible) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tif (n === 1) {\n\t\t\tconsole.log('YES');\n\t\t\treturn;\n\t\t}\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tlet diff = Math.abs(arr[i] - arr[i - 1]);\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tpossible ? console.log('YES') : console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tarr.sort();\n\t\tlet flag = true;\n\n\t\tfor (let i = 0; i < n - 1; i++) {\n\t\t\tif (Math.abs(arr[i] - arr[i + 1]) > 1) {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tflag ? console.log('YES') : console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tlet diff = arr[i] - arr[i - 1];\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t}\n\t\t}\n\n\t\tif (possible) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tarr.sort((a, b) => a - b);\n\t\tconsole.log(arr);\n\t\tlet count = 0;\n\n\t\tfor (let i = 0; i < n - 1; i++) {\n\t\t\tlet diff = Math.abs(arr[i] - arr[i + 1]);\n\t\t\tif (diff > 1) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\n\t\tif (count) {\n\t\t\tconsole.log('NO');\n\t\t} else {\n\t\t\tconsole.log('YES');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tarr.sort();\n\t\tlet count = 0;\n\n\t\tfor (let i = 0; i < n - 1; i++) {\n\t\t\tlet diff = Math.abs(arr[i] - arr[i + 1]);\n\t\t\tif (diff > 1) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\n\t\tif (count) {\n\t\t\tconsole.log('NO');\n\t\t} else {\n\t\t\tconsole.log('YES');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1, l = arr.length; i < l; ++i) {\n\t\t\tlet diff = arr[i] - arr[i - 1];\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tpossible ? console.log('YES') : console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tlet diff = arr[i] - arr[i - 1];\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t}\n\t\t}\n\n\t\tif (possible) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tif (n === 1) {\n\t\t\tconsole.log('YES');\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet possible = true;\n\t\tarr.sort();\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tlet diff = Math.abs(arr[i] - arr[i - 1]);\n\t\t\tif (diff > 1) {\n\t\t\t\tpossible = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tpossible ? console.log('YES') : console.log('NO');\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let i = 0; i < N; ++i) {\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort();\n\n const isYes = arr.every((x, i) => {\n if (i < 1) {\n return true;\n } else if (Math.abs(x - arr[i - 1]) <= 1) {\n return true;\n } else {\n return false;\n }\n });\n\n if (isYes) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let t = 0; t < N; ++t) {\n const b = readline();\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort();\n\n let isYes = true;\n for (let k = 1; k < arr.length; ++k) {\n if (arr[k] - arr[k - 1] > 1) {\n print(\"NO\\n\");\n isYes = false;\n break;\n }\n }\n\n if (isYes) {\n print(\"YES\\n\");\n }\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let i = 0; i < N; ++i) {\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort();\n\n const isYes = arr.every((x, i) => {\n if (i < 1) {\n return true;\n } else if (Math.abs(x - arr[i - 1]) <= 1) {\n return true;\n } else {\n return false;\n }\n });\n\n if (isYes) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let t = 0; t < N; ++t) {\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort();\n\n const isYes = arr.every((x, i) => {\n if (i < 1) {\n return true;\n } else if (Math.abs(x - arr[i - 1]) <= 1) {\n return true;\n } else {\n return false;\n }\n });\n\n if (isYes) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const N = readline();\n\n for (let t = 0; t < N; ++t) {\n const b = readline();\n const arr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n arr.sort();\n\n let isYes = true;\n for (let k = 1; k < arr.length; ++k) {\n if (arr[k] - arr[k - 1] > 1) {\n print(\"NO\");\n isYes = false;\n break;\n }\n }\n\n if (isYes) {\n print(\"YES\");\n }\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r 1) {\n console.log('NO');\n return;\n }\n }\n\n console.log('YES');\n\n}\n\n"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray().map( x => x * 1).sort()\n\n var prevNum = arr[0]\n var i\n for(i=1; i 1) {\n print(\"NO\")\n return\n }\n prevNum = arr[i]\n }\n print(\"YES\")\n}\n\nvar testCases = readInt();\nvar testCaseNum;\nfor(testCaseNum=0; testCaseNum 1) {\n print(\"NO\")\n return\n }\n prevNum = arr[i]\n }\n print(\"YES\")\n}\n\nvar testCases = readInt();\nvar testCaseNum;\nfor(testCaseNum=0; testCaseNum 0) {\n numPos++;\n } else {\n numNeg++;\n }\n }\n\n print(numPos < 2 || numNeg < 2 ? 'Yes' : 'No');\n}\n\nmain();\n"}, {"source_code": "var n = Number(readline());\nvar min = 0, plu = 0;\nfor(var i = 0; i < n; i++){\n var c = readline().split(' ').map(Number);\n if(c[0] < 0)\n min++;\n else\n plu++;\n}\nif(min <=1 || plu <=1)\nprint(\"Yes\");\nelse\nprint(\"No\");"}, {"source_code": "n=Number(readline())\nvar A=[]\nfor (var i=0;ia+(v<0),0)\nprint((!ne || ne===1 || ne===(n-1) || ne===n)?'Yes':'No')"}, {"source_code": "var n=readline();\nn=parseInt(n);\nvar cordinate,x,y;\nvar positivex=0;\nvar negativex=0;\n \n \n for (var i=0;i0) {\n positivex += 1;\n } else {\n negativex += 1; \n \n } \n }\n\t\n\tif (positivex===1 || positivex===0) {\t\n\t\twrite(\"Yes\");\n\t} else if (negativex===1 || negativex===0) {\n\t\twrite(\"Yes\");\n\t} else {\n\t\twrite(\"No\");\n\t}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n let xg = 0\n let xl = 0\n for(let i = 0; i < n; i ++) {\n const co = arr[i].split(' ')\n if(parseInt(co[0]) > 0) xg++\n else xl ++\n }\n if((xg <= 1 && xl >= 0) || (xl <= 1 && xg >= 0)) {\n console.log('Yes')\n }\n else {\n console.log('No')\n }\n \n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var L = 0;\n var R = 0;\n for(var i = 0; i < N; i++){\n var tmp = nextIntArray();\n if(tmp[0] < 0){\n L++;\n }else{\n R++;\n }\n }\n if(L > 1 && R > 1){\n myout(\"No\");\n }else{\n myout(\"Yes\");\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet L = 0;\nlet R = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [x, y] = d.split(' ').map(Number);\n\n if (x > 0) {\n R++;\n }\n else {\n L++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (L <= 1 || R <= 1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n});\n"}, {"source_code": "var N = parseInt( readline() );\nvar num1 = 0;\nvar num2 = 0;\n\nfor(var i=0;i0) {\n positivex += 1;\n } else {\n negativex += 1; \n \n } \n }\n\t\n\tif (positivex===1 || positivex===0) {\t\n\t\twrite(\"Yes\");\n\t} else if (negativex===1 || negativex===0) {\n\t\twrite(\"Yes\");\n\t} else {\n\t\twrite(\"No\");\n\t}"}, {"source_code": "var num = parseInt(readline());\nvar xPos = 0;\nvar xNeg = 0;\nvar canBeDone = true;\n\nfor (var i = 0; i < num; i++) {\n var x = readline().split(' ').map(function(element) {\n return parseInt(element);\n })[0];\n\n if (x > 0) {\n xPos++;\n } else {\n xNeg++;\n }\n\n if (xPos > 1 && xNeg > 1) {\n canBeDone = false;\n print('No');\n break;\n }\n}\n\nif (canBeDone) {\n print('Yes');\n}\n"}, {"source_code": "var num = parseInt(readline());\nvar dev = 0;\n\nfor (var i = 0; i < num; i++) {\n var x = readline().split(' ').map(function(element) {\n return parseInt(element);\n })[0];\n\n if (x > 0) {\n dev++;\n } else {\n dev--;\n }\n}\n\nif (num - Math.abs(dev) <= 2) {\n print('Yes');\n} else {\n print('No');\n}\n"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = toInt(readline());\nvar x, plus = 0, minus = 0;\n\nfor (var i = 0; i < n; i++) {\n\tx = readline().split(\" \").map(toInt);\n\tif (x[0] < 0) {\n\t\tminus++;\n\t} else {\n\t\tplus++;\n\t}\n}\n\nif (plus > 1 && minus > 1) {\n\tprint(\"NO\");\n} else {\n\tprint(\"YES\");\n}"}, {"source_code": "var n = readline();\nvar positiveCount = 0;\nvar negativeCount = 0;\nfor (var i = 0; i < n; i++) {\n var point = parseInt(readline());\n if (point > 0) {\n positiveCount++;\n } else {\n negativeCount++;\n }\n if (positiveCount > 1 && negativeCount > 1) {\n print('No');\n break;\n }\n}\nif (positiveCount <= 1 || negativeCount <= 1) {\n print('Yes');\n}"}], "negative_code": [{"source_code": "var num = parseInt(readline());\nvar dev = 0;\n\nfor (var i = 0; i < num; i++) {\n var x = readline().split(' ').map(function(element) {\n return parseInt(element);\n })[0];\n\n if (x > 0) {\n dev++;\n } else {\n dev--;\n }\n}\nprint(dev);\nif (num - Math.abs(dev) <= 2) {\n print('Yes');\n} else {\n print('No');\n}\n"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = toInt(readline());\nvar x, plus = 0, minus = 0;\n\nfor (var i = 0; i < n; i++) {\n\tx = readline().split(\" \").map(toInt);\n\tif (x[0] < 0) {\n\t\tminus++;\n\t} else {\n\t\tplus++;\n\t}\n}\n\nif (Math.abs(plus-minus) < 2) {\n\tprint(\"YES\");\n} else {\n\tprint(\"NO\");\n}"}, {"source_code": "function main() {\n var n = readline();\n\n var numNeg = 0;\n var numPos = 0;\n\n for (var i = 0; i < n; i++) {\n var y = readline().split(' ')[1];\n\n if (y > 0) {\n numPos++;\n } else {\n numNeg++;\n }\n }\n\n print(numPos < 2 || numNeg < 2 ? 'Yes' : 'No');\n}\n\nmain();\n"}, {"source_code": "var n=readline();\nn=parseInt(n);\nvar cordinate,x,y;\nvar positivex=0;\nvar negativex=0;\n \n \n for (var i=0;i0) {\n positivex += 1;\n } else {\n negativex += 1; \n \n } \n }\n\t\n\tif (positivex===1) {\t\n\t\twrite(\"Yes\");\n\t} else if (negativex===1) {\n\t\twrite(\"Yes\");\n\t} else {\n\t\twrite(\"No\");\n\t}"}], "src_uid": "cf7bf89a6038586b69d3b8021cee0b27"} {"source_code": "\"use strict\";\n\n\nvar ans =\"\";\n \nfunction hasEven(x1 , x2){\n \n\tans =\"\";\n \n\tvar eq1 =(x2 -1) *2;\n\tvar eq2 =x1 -eq1;\n \n\tif(eq2 >0 && !(eq2 &1) && eq1 +eq2 ==x1){\n \n x2 --;\n while(x2 --) ans +=\" \" +'2';\n ans +=\" \" +eq2.toString();\n \n return \"YES\";\n \n }\n return \"NO\";\n \n}\n \n \nfunction hasOdd(x1 , x2){\n \n\tans =\"\";\n \n\tvar eq1 =(x2 -1);\n\tvar eq2 =x1 -eq1;\n \n\tif(eq2 >0 && (eq2 &1) && eq1 +eq2 ==x1){\n \n x2 --;\n while(x2 --) ans +=\" \" +'1';\n ans +=\" \" +eq2.toString();\n \n return \"YES\";\n \n }\n return \"NO\";\n \n}\n \n \nvar cases =parseInt(readline());\n \nwhile(cases --){\n \n\tans =\"\";\n\tvar read =readline().split(\" \");\n\tvar n =parseInt(read[0]);\n\tvar k =parseInt(read[1]);\n \n\tif(k <=n && hasEven(n , k) ==\"YES\"){\n \n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n \n \n\t}else if(k <=n && hasOdd(n , k) ==\"YES\"){\n \n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n \n\t}else{\n\t\tprint(\"NO\");\n\t}\n \n}", "positive_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = \"\";\n var flag = false;\n if (n % k == 0) {\n for (var j = 0; j < k; j++) {\n res += \" \" + n / k;\n flag = true;\n }\n } else if (n - k + 1 < 2) res = \"No\";\n else {\n if (n % 2 == 0) {\n if (k % 2 == 0) {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n } else {\n if (n - 2 * (k - 1) >= 4) {\n res += n - 2 * (k - 1);\n for (var i = 0; i < k - 1; i++) res += \" \" + 2;\n flag = true;\n } else res = \"No\";\n }\n } else {\n if (k % 2 == 0) {\n res = \"No\";\n } else {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n }\n }\n }\n if (flag) {\n print(\"Yes\");\n print(res.trim());\n } else print(res.trim());\n}\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readline().split(\" \").map(Number);\n var n = nk[0];\n var k = nk[1];\n\n var nk1 = n - k + 1;\n var arr = new Array(k - 1).fill(1);\n if (nk1 % 2 === 1 && nk1 > 0) {\n arr.push(nk1);\n print(\"YES\");\n print(arr.join(\" \"));\n continue;\n }\n\n var nk2 = n - (k - 1) * 2;\n var arr2 = new Array(k - 1).fill(2);\n if (nk2 % 2 === 0 && nk2 > 0) {\n arr2.push(nk2);\n print(\"YES\");\n print(arr2.join(\" \"));\n continue;\n }\n print(\"NO\");\n }\n}\n\nmain();"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const parts = readline().split(' ');\n let n = parseInt(parts[0], 10);\n let k = parseInt(parts[1], 10);\n\n function helper(N, K, result, sub) {\n const mod = sub % 2;\n while (N > 0 && K > 0) {\n if (N % K === 0 && N / K % 2 === mod) {\n const div = N / K;\n N -= div;\n K -= 1;\n result.push(div);\n } else {\n N -= sub;\n K -= 1;\n result.push(sub);\n }\n }\n return {N, K, result};\n }\n\n const resultOdd = helper(n, k, [], 1);\n const resultEven = helper(n, k, [], 2);\n\n if (resultOdd.N === 0 && resultOdd.K === 0) {\n print('YES');\n print(resultOdd.result.join(' '));\n } else if (resultEven.N === 0 && resultEven.K === 0) {\n print('YES');\n print(resultEven.result.join(' '));\n } else {\n print('NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const parts = readline().split(' ');\n let n = parseInt(parts[0], 10);\n let k = parseInt(parts[1], 10);\n\n function helper(N, K, result, sub) {\n while (K > 1) {\n N -= sub;\n K -= 1;\n result.push(sub);\n }\n if (N <= 0 || N % 2 !== sub % 2) {\n return null;\n }\n result.push(N);\n return result;\n }\n\n const resultOdd = helper(n, k, [], 1);\n const resultEven = helper(n, k, [], 2);\n\n if (resultOdd) {\n print('YES');\n print(resultOdd.join(' '));\n } else if (resultEven) {\n print('YES');\n print(resultEven.join(' '));\n } else {\n print('NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const parts = readline().split(' ');\n let n = parseInt(parts[0], 10);\n let k = parseInt(parts[1], 10);\n\n if (k > n) {\n print('NO');\n continue;\n }\n\n function helper(N, K, result, subs) {\n while (N > 0 && K > 0) {\n if (\n N % K === 0 &&\n (N / K) % 2 === (subs === 2 ? 0 : 1)\n ) {\n const div = N / K;\n N -= div;\n K -= 1;\n result.push(div);\n } else {\n N -= subs;\n K -= 1;\n result.push(subs);\n }\n }\n return {N, K, result};\n }\n\n const resultOdd = helper(n, k, [], 1);\n const resultEven = helper(n, k, [], 2);\n\n if (resultOdd.N === 0 && resultOdd.K === 0) {\n print('YES');\n print(resultOdd.result.join(' '));\n } else if (resultEven.N === 0 && resultEven.K === 0) {\n print('YES');\n print(resultEven.result.join(' '));\n } else {\n print('NO');\n }\n}\n"}, {"source_code": " var nCases = parseInt(readline());\n for (var i = 0; i < nCases; i++){\n \n var line = readline().split(\" \");\n var n = parseInt(line[0]);\n var k = parseInt(line[1]);\n \n var str = '';\n \n if (n % 2 === 0 && (n - ((k - 1) * 2)) % 2 === 0 && n - ((k - 1) * 2) > 0){\n print(\"YES\\n\");\n for (var j = 0; j < k - 1; j++){\n str += \"2 \";\n }\n str += \"\"+ (n - ((k - 1) * 2));\n }\n else if ((n - (k - 1)) % 2 !== 0 && (n - (k - 1)) % 2 > 0){\n print('YES\\n');\n for (var j = 0; j < k - 1; j++){\n str += '1 ';\n }\n str += '' + (n - (k - 1));\n }\n else{ \n print('NO\\n');\n continue;\n }\n print(str + '\\n');\n }"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n const result = {problem,\n T: parseInt(line),\n isProcessing: true,\n cases: []\n };\n return result;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || !cases[cases.length - 1].isProcessing) {\n cases.push({\n t: line\n });\n }\n\n const isProcessing = cases.length < problem.T;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, k] = data.t.split(' ');\n let result = [];\n\n const v1 = n - (k - 1);\n const v2 = n - 2 * (k - 1);\n\n if(v1 > 0 && v1 % 2 == 1) {\n for(let i = 0; i < k - 1; i++) {\n result.push(1);\n }\n result.push(v1);\n } else if (v2 > 0 && v2 % 2 == 0) {\n for(let i = 0; i < k - 1; i++) {\n result.push(2);\n }\n result.push(v2);\n }\n\n return result;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log((result.length) ? ('YES' + '\\n' + result.join(' ')) : 'NO');\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let j = 0;jparseInt(x));\n if (k % 2 == 0 && n % 2 != 0) {\n console.log('NO')\n continue;\n }\n\n let solution = [];\n let odd = k % 2 == 0 || n % 2 != 0;\n let sum = 0;\n\n for (let i = 0; i 0 && (N - (K - 1) * 2) % 2 == 0){\n\t\t\toutput.push(\"YES\");\n\t\t\tvar list = new Array(K);\n\t\t\tlist.fill(2);\n\t\t\tlist[K - 1] = N - (K - 1) * 2;\n\t\t\toutput.push(myconv(list,8));\n\t\t\tcontinue;\n\t\t}\n\t\toutput.push(\"NO\");\n\t\t\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "\"use strict\";\nvar __spreadArrays = (this && this.__spreadArrays) || function () {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n};\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(\" \").map(function (e) { return parseInt(e); }), n = _a[0], k = _a[1];\n var a = n - (k - 1);\n var b = n - (k - 1) * 2;\n var x = [];\n if (a > 0 && a % 2 != 0) {\n x = __spreadArrays([a], (Array(k - 1).fill(1)));\n }\n else if (b > 0 && b % 2 == 0) {\n x = __spreadArrays([b], (Array(k - 1).fill(2)));\n }\n if (x.length) {\n print(\"YES\");\n print(x.join(\" \"));\n }\n else {\n print(\"NO\");\n }\n }\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (num, col) {\n let body = col - 1;\n let rest = num - body;\n let arr = [];\n\n if (rest <= 0) return ['NO'];\n if (rest%2 === 1) {\n arr = Array(body).fill(1);\n arr.push(rest);\n return ['YES', arr.join(' ')];\n }\n\n body = 2 * (col - 1);\n rest = num - body;\n\n if (rest <= 0) return ['NO'];\n if (rest%2 === 0) {\n arr = Array(body/2).fill(2);\n arr.push(rest);\n return ['YES', arr.join(' ')]\n }\n\n return ['NO'];\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n let result = foo(data[0], data[1]);\n answer += result[0] +\"\\n\";\n if (result[1]) answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n\n if (a%2 === 1 && k%2 === 1) {\n if (k > a) {\n console.log('NO')\n } else {\n console.log('YES')\n const res = Array(k).fill(1)\n res[0] = a-k+1\n console.log(res.join(' '))\n }\n } else {\n if (a%2 === 1 && k%2 === 0) {\n console.log('NO')\n } else {\n if (k%2 === 0) {\n if (k>a) {\n console.log('NO')\n } else {\n console.log('YES')\n const res = Array(k).fill(1)\n res[0] = a-k+1\n console.log(res.join(' '))\n }\n } else {\n const min = k*2\n if (min > a) {\n console.log('NO')\n } else {\n console.log('YES')\n const res = Array(k).fill(2)\n res[0] = a-k*2+2\n console.log(res.join(' '))\n }\n }\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n var nCases = parseInt(input[index++]);\n for (let i = 0; i < nCases; i++){\n\n var line = input[index++].split(\" \");\n var n = parseInt(line[0]);\n var k = parseInt(line[1]);\n\n var str = '';\n\n if (n % 2 === 0 && (n - ((k - 1) * 2)) % 2 === 0 && n - ((k - 1) * 2) > 0){\n console.log(\"YES\");\n for (var j = 0; j < k - 1; j++){\n str += \"2 \";\n }\n str += \"\"+ (n - ((k - 1) * 2));\n }\n else if ((n - (k - 1)) % 2 !== 0 && (n - (k - 1)) % 2 > 0){\n console.log('YES');\n for (var j = 0; j < k - 1; j++){\n str += '1 ';\n }\n str += '' + (n - (k - 1));\n }\n else{ \n console.log('NO');\n continue;\n }\n console.log(str);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\n\n// declare global variables\nvar input_stdin = \"\";\nvar noOfTestcase = 0;\n\n// standard input is stored into input_stdin\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\n// standard input is done and stored into an array\nprocess.stdin.on('end', function () {\n chunks = input_stdin.split(\"\\n\");\n noOfTestcase = chunks[0];\n process.stdout.write('\\n');\n for(let i=1; i < chunks.length; i++){\n let row = chunks[i].split(\" \");\n if(isNaN(row[0]) || isNaN(row[1])){\n // do nothing\n }else{\n start(Number(row[0]), Number(row[1]));\n }\n }\n});\n\nfunction isEven(val){\n if(val%2 == 0){\n return true\n }\n return false\n}\n\nfunction start(sum,K){\n // console.log(\"sum = \",sum, \" K=\",K);\n let eS = isEven(sum);\n let eK = isEven(K);\n // console.log(\"eS = \",eS, \" eK=\",eK);\n if(sum < K ){\n // console.log(\"less than\");\n process.stdout.write(\"NO\"+ '\\n');\n }else if (!eS && eK) {\n // console.log(\"odd - even condition\");\n process.stdout.write(\"NO\"+ '\\n');\n }else if (eS && !eK && sum < (2*K)) {\n // console.log(\"even - odd but twice condition\");\n process.stdout.write(\"NO\"+ '\\n');\n }else {\n process.stdout.write(\"YES\"+ '\\n');\n let str = \"\"\n if(!eS){\n for(let k=1; k < K; k++){\n str +=\"1 \"\n }\n str+=(sum-K+1)\n }else{\n if(!eK){\n for(let k=1; k < K; k++){\n str +=\"2 \"\n }\n str+=(sum-(2*K)+2)\n }else{\n for(let k=1; k < K; k++){\n str +=\"1 \"\n }\n str+=(sum-K+1)\n }\n }\n process.stdout.write(str+ '\\n');\n }\n return;\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r= n) {\n console.log('NO');\n continue;\n }\n\n output.push(n - count);\n console.log('YES');\n console.log(output.join(\" \"));\n }\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n let res = [];\n let total = 0;\n let base = 1;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if (last > 0 && last % 2 === 1) {\n res.push(last);\n return res;\n }\n }\n res.push(base);\n total += base;\n }\n res = [];\n total = 0;\n base = 2;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if (last > 0 && last % 2 === 0) {\n res.push(last);\n return res;\n }\n }\n res.push(base);\n total += base;\n }\n return 0;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n if (res.length > 0) console.log('YES', res.join(' '));\n else console.log('NO');\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n const [n,k] = readline().split(\" \").map(e => parseInt(e));\n let result = new Array(k);\n\n let pairity = (k % 2) != (n %2) ? 0 : 1;\n if (pairity === 0) {\n result.fill(2);\n let first = n - ((k-1) * 2);\n if (first % 2 != 0 || first <= 0) {\n console.log('NO');\n continue;\n }\n result[0] = first;\n } else {\n result.fill(1);\n let first = n - (k-1);\n if (first % 2 != 1 || first <= 0) {\n console.log('NO');\n continue;\n }\n result[0] = first;\n }\n\n console.log('YES');\n console.log(result.join(' '))\n\n\n }\n\n\n}\n"}, {"source_code": "\nvar ans =\"\";\n \nfunction hasEven(x1 , x2){\n \n\tans =\"\";\n \n\tvar eq1 =(x2 -1) *2;\n\tvar eq2 =x1 -eq1;\n \n\tif(eq2 >0 && !(eq2 &1) && eq1 +eq2 ==x1){\n \n x2 --;\n while(x2 --) ans +=\" \" +'2';\n ans +=\" \" +eq2.toString();\n \n return \"YES\";\n \n }\n return \"NO\";\n \n}\n \n \nfunction hasOdd(x1 , x2){\n \n\tans =\"\";\n \n\tvar eq1 =(x2 -1);\n\tvar eq2 =x1 -eq1;\n \n\tif(eq2 >0 && (eq2 &1) && eq1 +eq2 ==x1){\n \n x2 --;\n while(x2 --) ans +=\" \" +'1';\n ans +=\" \" +eq2.toString();\n \n return \"YES\";\n \n }\n return \"NO\";\n \n}\n \n \nvar cases =parseInt(readline());\n \nwhile(cases --){\n \n\tans =\"\";\n\tvar read =readline().split(\" \");\n\tvar n =parseInt(read[0] , 10);\n\tvar k =parseInt(read[1] , 10);\n \n\tif(k <=n && hasEven(n , k) ==\"YES\"){\n \n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n \n \n\t}else if(k <=n && hasOdd(n , k) ==\"YES\"){\n \n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n \n\t}else{\n\t\tprint(\"NO\");\n\t}\n \n}"}], "negative_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (num, col) {\n let body = col - 1;\n let rest = num - body;\n\n if (rest < 0) return ['NO'];\n if (rest%2 === 1) {\n return ['YES', `${Array(body).fill(1).join(' ')} ${rest}`];\n }\n\n body = 2 * (col - 1);\n rest = num - body;\n\n if (rest < 0) return ['NO'];\n if (rest%2 === 0) {\n return ['YES', `${Array(body/2).fill(2).join(' ')} ${rest}`]\n }\n\n return ['NO'];\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n let result = foo(data[0], data[1]);\n answer += result[0] +\"\\n\";\n if (result[1]) answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (num, col) {\n let body = col - 1;\n let rest = num - body;\n let arr = [];\n\n if (rest < 0) return ['NO'];\n if (rest%2 === 1) {\n arr = Array(body).fill(1);\n arr.push(rest);\n return ['YES', arr.join(' ')];\n }\n\n body = 2 * (col - 1);\n rest = num - body;\n\n if (rest < 0) return ['NO'];\n if (rest%2 === 0) {\n arr = Array(body/2).fill(2);\n arr.push(rest);\n return ['YES', arr.join(' ')]\n }\n\n return ['NO'];\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n let result = foo(data[0], data[1]);\n answer += result[0] +\"\\n\";\n if (result[1]) answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\n\n// declare global variables\nvar input_stdin = \"\";\nvar noOfTestcase = 0;\n\n// standard input is stored into input_stdin\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\n// standard input is done and stored into an array\nprocess.stdin.on('end', function () {\n chunks = input_stdin.split(\"\\n\");\n noOfTestcase = chunks[0];\n process.stdout.write('\\n');\n for(let i=1; i < chunks.length; i++){\n let row = chunks[i].split(\" \");\n start(Number(row[0]), Number(row[1]));\n }\n});\n\nfunction isEven(val){\n if(val%2 == 0){\n return true\n }\n return false\n}\n\nfunction start(sum,K){\n // console.log(\"sum = \",sum, \" K=\",K);\n let eS = isEven(sum);\n let eK = isEven(K);\n // console.log(\"eS = \",eS, \" eK=\",eK);\n if(sum < K ){\n // console.log(\"less than\");\n process.stdout.write(\"NO\"+ '\\n');\n }else if (!eS && eK) {\n // console.log(\"odd - even condition\");\n process.stdout.write(\"NO\"+ '\\n');\n }else if (eS && !eK && sum < (2*K)) {\n // console.log(\"even - odd but twice condition\");\n process.stdout.write(\"NO\"+ '\\n');\n }else {\n process.stdout.write(\"YES\"+ '\\n');\n let str = \"\"\n if(!eS){\n for(let k=1; k < K; k++){\n str +=\"1 \"\n }\n str+=(sum-K+1)\n }else{\n if(!eK){\n for(let k=1; k < K; k++){\n str +=\"2 \"\n }\n str+=(sum-(2*K)+2)\n }else{\n for(let k=1; k < K; k++){\n str +=\"1 \"\n }\n str+=(sum-K+1)\n }\n }\n process.stdout.write(str+ '\\n');\n }\n return;\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n let res = [];\n let base = n % 2 === 0 ? Math.ceil(n / k) : Math.floor(n / k);\n if (base === 0) return 0;\n let total = 0;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if ((last <= 0) || last % 2 !== base % 2) return 0;\n res.push(last);\n return res;\n }\n res.push(base);\n total += base;\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n if (res.length > 0) console.log('YES', res.join(' '));\n else console.log('NO');\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n let res = [];\n let base = n % 2 === 0 ? Math.ceil(n / k) : Math.floor(n / k);\n let total = 0;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if ((last <= 0) || last % 2 !== base % 2) return 0;\n res.push(last);\n return res;\n }\n res.push(base);\n total += base;\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n if (res.length > 0) console.log('YES', res.join(' '));\n else console.log('NO');\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n if ((n % 2 === 1 && k % 2 === 0) || k > n) return 0;\n let res = [];\n let base = n % 2 === 0 ? Math.ceil(n / k) : Math.floor(n / k);\n let total = 0;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if ((last < 0) || last % 2 !== base % 2) return 0;\n res.push(last);\n break;\n }\n res.push(base);\n total += base;\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n if (res.length > 0) console.log('YES', res.join(' '));\n else console.log('NO');\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n let res = [];\n let base = n % 2 === 0 ? Math.ceil(n / k) : Math.floor(n / k);\n let total = 0;\n for (let i = 1; i <= k; i++) {\n if (i === k) {\n let last = n - total;\n if ((last < 0) || last % 2 !== base % 2) return 0;\n res.push(last);\n return res;\n }\n res.push(base);\n total += base;\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n if (res.length > 0) console.log('YES', res.join(' '));\n else console.log('NO');\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "\nvar ans =\"\";\n\nfunction hasEven(x1 , x2){\n\n\tans =\"\";\n\n\tvar eq1 =(x2 -1) *2;\n\tvar eq2 =x1 -eq1;\n\n\tif(eq2 >0 && !(eq2 &1) && eq1 +eq2 ==x1){\n\n x2 --;\n while(x2 --) ans +=\" \" +'2';\n ans +=\" \" +eq2.toString();\n\n return \"YES\";\n\n }\n return \"NO\";\n\n}\n\n\nfunction hasOdd(x1 , x2){\n\n\tans =\"\";\n\n\tvar eq1 =(x2 -1);\n\tvar eq2 =x1 -eq1;\n\n\tif(eq2 >0 && (eq2 &1) && eq1 +eq2 ==x1){\n\n x2 --;\n while(x2 --) ans +=\" \" +'1';\n ans +=\" \" +eq2.toString();\n\n return \"YES\";\n\n }\n return \"NO\";\n\n}\n\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\n\tans =\"\";\n\tvar read =readline().split(\" \");\n\tvar n =parseInt(read[0] , 12);\n\tvar k =parseInt(read[1] , 12);\n\n\tif(k <=n && hasEven(n , k) ==\"YES\"){\n\n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n\n\n\t}else if(k <=n && hasOdd(n , k) ==\"YES\"){\n\n\t\tprint(\"YES\");\n\t\tprint(ans.trim());\n\n\t}else{\n\t\tprint(\"NO\");\n\t}\n\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = \"\";\n var flag = false;\n if (n % k == 0) {\n for (var j = 0; j < k; j++) {\n res += \" \" + n / k;\n flag = true;\n }\n } else if (n - k + 1 < k) res = \"No\";\n else {\n if (n % 2 == 0) {\n if (k % 2 == 0) {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n } else {\n res += n - 2 * (k - 1);\n for (var i = 0; i < k - 1; i++) res += \" \" + 2;\n flag = true;\n }\n } else {\n if (k % 2 == 0) {\n res = \"No\";\n } else {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n }\n }\n }\n if (flag) {\n print(\"Yes\");\n print(res.trim());\n } else print(res.trim());\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = \"\";\n var flag = false;\n if (n % k == 0) {\n for (var j = 0; j < 2; j++) {\n res += \" \" + n / k;\n flag = true;\n }\n } else if (n - k + 1 < k) res = \"No\";\n else {\n if (n % 2 == 0) {\n if (k % 2 == 0) {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n } else {\n if (n - 2 * (k - 1) >= 4) {\n res += n - 2 * (k - 1);\n for (var i = 0; i < k - 1; i++) res += \" \" + 2;\n flag = true;\n } else res = \"No\";\n }\n } else {\n if (k % 2 == 0) {\n res = \"No\";\n } else {\n res += n - k + 1;\n for (var i = 0; i < k - 1; i++) res += \" \" + 1;\n flag = true;\n }\n }\n }\n if (flag) {\n print(\"Yes\");\n print(res.trim());\n } else print(res.trim());\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const result = [];\n const parts = readline().split(' ');\n let n = parseInt(parts[0], 10);\n let k = parseInt(parts[1], 10);\n\n if (k === 1) {\n result.push(n);\n print('YES');\n print(result.join(' '));\n continue;\n }\n\n if (k > n) {\n print('NO');\n continue;\n }\n\n if (k === n) {\n for (let i = 0; i < k; i++) {\n result.push(1);\n }\n print('YES');\n print(result.join(' '));\n continue;\n }\n\n let chooseEven = n % 2 === 0;\n\n while (n > 0 && k > 0) {\n if (n % k === 0) {\n const div = n / k;\n if ((chooseEven && div % 2 === 0) || (!chooseEven && div % 2 !== 0)) {\n result.push(div);\n n -= div;\n k -= 1;\n continue;\n }\n }\n\n if (chooseEven) {\n result.push(2);\n n -= 2;\n } else {\n result.push(1);\n n -= 1;\n }\n k -= 1;\n }\n\n if (n === 0 && k === 0) {\n print('YES');\n print(result.join(' '));\n } else {\n print('NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const parts = readline().split(' ');\n let n = parseInt(parts[0], 10);\n let k = parseInt(parts[1], 10);\n\n function helper(N, K, result, sub) {\n while (N > 0 && K > 1) {\n N -= sub;\n K -= 1;\n result.push(sub);\n }\n if (N % 2 === sub % 2) {\n result.push(N);\n K -= 1;\n }\n return {K, result};\n }\n\n const resultOdd = helper(n, k, [], 1);\n const resultEven = helper(n, k, [], 2);\n\n if (resultOdd.K === 0) {\n print('YES');\n print(resultOdd.result.join(' '));\n } else if (resultEven.K === 0) {\n print('YES');\n print(resultEven.result.join(' '));\n } else {\n print('NO');\n }\n}\n"}, {"source_code": " var nCases = parseInt(readline());\n for (var i = 0; i < nCases; i++){\n\n var line = readline().split(\" \");\n var n = parseInt(line[0]);\n var k = parseInt(line[1]);\n\n var str = '';\n\n if (n % 2 === 0 && (n - ((k - 1) * 2)) % 2 === 0 && n - ((k - 1) * 2) > 0){\n print(\"YES\\n\");\n for (var j = 0; j < k - 1; j++){\n str += \"2 \";\n }\n str += \"\"+ (n - ((k - 1) * 2));\n }\n else if ((n - (k - 1)) % 2 !== 0){\n print('YES\\n');\n for (var j = 0; j < k - 1; j++){\n str += '1 ';\n }\n str += '' + (n - (k - 1));\n }\n else{ \n print('NO\\n');\n continue;\n }\n print(str + '\\n');\n }"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r= n) {\n console.log('NO');\n continue;\n }\n\n output.push(n - count);\n\n console.log('YES');\n console.log(output.join(\" \"));\n continue;\n } else {\n let output = [];\n let count = 0;\n\n for(let i=0;i= n) {\n console.log('NO');\n continue;\n }\n output.push(n - count);\n console.log('YES');\n console.log(output.join(\" \"));\n continue;\n }\n } else {\n if(k % 2 !== 0) {\n let output = [];\n let count = 0;\n\n for(let i=0;i= n) {\n console.log('NO');\n continue;\n }\n console.log('YES');\n console.log(output.join(\" \"));\n continue;\n } else {\n console.log('NO');\n continue;\n }\n }\n\n }\n\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r= 1001) {\r\n break;\r\n }\r\n }\r\n }\r\n const T = array[0];\r\n for (let i = 0; i < T; i++) {\r\n const k = array[i + 1];\r\n console.log(arr[k - 1]);\r\n }\r\n}\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\r\n\r\n main(inputString);\r\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = [];\n for(l = 1; l < 1667; l++){\n if(l % 10 == 3 || l % 3 === 0){\n \n }else{\n a.push(l);\n }\n }\n for(j = 1; j <= n; j++){\n var k = lines[j];\n console.log(a[k - 1]);\n }\n});"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 1; i <= testCaseNumber; i++){\r\n let a = input[i];\r\n a = parseInt(a);\r\n console.log(polycarp[a]);\r\n }\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nconst k = [];\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n\n let i = 1;\n while (k.length <= 1000) {\n if (i % 3 === 0 || i % 10 === 3) {\n i++;\n continue;\n }\n\n k.push(i);\n i++;\n }\n return;\n }\n\n console.log(k[Number(d - 1)]);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n \r\n let n = 0\r\n let arr = []\r\n let str = ''\r\n \r\n let nums = generateUptoNwithoutK(1000, 3)\r\n \r\n // with testcases\r\n //* \r\n let t = parseInt( readline() ) \r\n while (t--) {\r\n n = parseInt( readline() )\r\n // arr = readline().split(' ').map(Number)\r\n // str = readline()\r\n console.log( solve(n, nums, arr, str) )\r\n } \r\n //*/\r\n\r\n // without testcases\r\n /* \r\n n = parseInt( readline() )\r\n arr = readline().split(' ').map(Number)\r\n str = readline()\r\n console.log( solve(n, arr, str) )\r\n //*/\r\n}\r\n// Driver Function Ends //\r\n\r\nconst generateUptoNwithoutK = (n, k) => {\r\n let a = [], i = 1\r\n while( a.length <= n ){\r\n // if( i%k != 0 && !stringHasCharacter(i.toString(), k ) ) a.push( i )\r\n if( i%k != 0 && i%10 != k ) a.push( i )\r\n i++\r\n }\r\n return a\r\n}\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, nums, arr, str) => { \r\n \r\n return nums[n-1]\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sortDesc = (arr) => arr.sort( (a, b) => b - a )\r\nconst isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\nconst elemFrequency = (arr) => arr.reduce( (acc, curr) => { return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc }, {}) \r\n\r\nconst reverseText = (str) => str.split('').reverse().join('')\r\nconst stringHasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\nconst stringHasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\nconst stringHasCharacter = (str, char) => str.indexOf(char) > -1 ? true : false\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^$$${}()|[\\]\\\\]/g, '\\\\$$$&')\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\nconst unique = (str) => {\r\n const cleanStr = str.replace(/ /gi, '');\r\n const set = [...new Set(cleanStr)];\r\n return set;\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\nprocess.stdin.on(\"data\", function(chunk) {\n let data = chunk.trim().split(\"\\n\");\n let times = parseInt(data[0]);\n let map = [...Array(10e3).keys()].filter(e => {\n return !(e % 3 === 0 || e % 10 === 3);\n }).slice(0, 1000);\n for(let i = 1; i <= times; i++) {\n let [ num ] = data[i].trim().split(\" \").map(Number);\n console.log(map[num - 1]);\n }\n});\n\t \t \t\t\t \t\t \t \t \t\t"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let k = parseInt(readline());\r\n let num = 0;\r\n for (let i = 0; i < k; i++) {\r\n num++;\r\n while (num % 10 === 3 || num % 3 === 0) num++;\r\n }\r\n console.log(num);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = [];\n for(var l = 1; l < 1667; l++){\n if(l % 10 == 3 || l % 3 === 0){\n \n }else{\n a.push(l);\n }\n }\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n console.log(a[k - 1]);\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tlet a = [];\n\tfor(let i = 0; a.length <= 1000; i++){\n\t\tif (i % 3 != 0 && i % 10 != 3) {\n\t\t\ta.push(i);\n\t\t}\n\t}\n\tfor(let i = 0; i < t; i++){\n\t\tlet k = nl.num();\n\t\tans.push(a[k-1]);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet k = rn();\r\n\r\n\t\tlet nxt = 0;\r\n\t\twhile (k) {\r\n\t\t\tnxt++;\r\n\t\t\tk -= nxt%3 && nxt%10 != 3;\r\n\t\t}\r\n\r\n\t\tconst ans = nxt;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/**\r\n * Bismillahir Rahmanir Rahim\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n */\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n \r\n let inputString = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\tresults = []\r\n\tprecompute(results);\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\t//let s = readLine().split(\" \").map(item=>parseInt(item));\r\n\t\tconsole.log(solve(n));\r\n\t\t\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n) {\r\n\treturn results[n-1];\r\n}\r\n\r\nfunction precompute(results) {\r\n\tk = 1 ;\r\n\ti = 1 ;\r\n\twhile(k<=1000) {\r\n\t\tif (i%3===0 || i%10===3) i++;\r\n\t\telse {\r\n\t\t\tresults.push(i);\r\n\t\t\ti++;\r\n\t\t\tk++;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\r\n \r\nconst read = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst inputString = []\r\n\r\nread.on('line', (input) => {\r\n inputString.push(input.trim());\r\n})\r\nread.on('close', () => {\r\n\r\n main(inputString.map(num => parseInt(num)).filter(Boolean)); \r\n})\r\n \r\nfunction main(nums) {\r\n const total = nums[0];\r\n const remaining = nums.slice(1)\r\n const max = Math.max(...remaining.slice(0,total));\r\n const list = [];\r\n let i = 1;\r\n while(list.length < max){\r\n if(i%3 !== 0 && i%10 !== 3){\r\n list.push(i)\r\n }\r\n i++;\r\n }\r\n remaining.forEach(element => {\r\n console.log(list[element-1]);\r\n });\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline())\r\n\r\nwhile(t--){\r\n var k=parseInt(readline())\r\n \r\n for(var i=1;;i++){\r\n if(i%3==0 ||(i%10==3)){\r\n continue;\r\n }\r\n k--;\r\n if(k==0){\r\n print(i)\r\n break;\r\n }\r\n\r\n }\r\n}\r\n \r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let index = +input[z++];\r\n let number = 0;\r\n for (let i = 1; i <= index; i++) {\r\n if((i % 3) == 0 || i.toString()[i.toString().length - 1] == '3'){\r\n index++;\r\n }\r\n number++;\r\n }\r\n if((number % 3) == 0 || number.toString()[number.toString().length - 1] == '3'){\r\n number++;\r\n }\r\n console.log(number);\r\n }\r\n}"}, {"source_code": "// define file test.inp\r\n// npm install -D @types/node\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nvar jsin = \"\";\r\nvar input = [];\r\nvar jscur = 0;\r\nvar readLine = function () { return input[jscur++]; };\r\nvar readLines = function () { return readLine().split(' '); };\r\nvar readInt = function () { return +(readLine()); };\r\nvar readInts = function () { return readLine().split(' ').map(function (x) { return +(x); }); };\r\nvar debug = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n console.log(\"[\" + args.join(\",\") + \"]\");\r\n};\r\nprocess.stdin.on('data', function (chunk) { return jsin += chunk; });\r\nprocess.stdin.on('end', function () {\r\n input = jsin.split('\\n').filter(function (curline) { return curline !== ''; });\r\n // multitest\r\n var nTest = readInt();\r\n while (nTest--) {\r\n main();\r\n }\r\n});\r\n//// CODE BELOW\r\nfunction main() {\r\n var k = readInt();\r\n var val = 1;\r\n for (; k > 0; ++val) {\r\n if (val % 3 == 0 || val % 10 == 3) {\r\n continue;\r\n }\r\n --k;\r\n }\r\n console.log(val - 1);\r\n}\r\n"}, {"source_code": "// var arr = [];\r\n// for (var j = 1; arr.length <= 1000; j++) {\r\n// if (j % 3 == 0 || j % 10 == 3) {\r\n// continue;\r\n// } else {\r\n// arr.push(j);\r\n// }\r\n// //console.log(j);\r\n// }\r\n\r\n// //console.log((arr));\r\n// var t = Number(readline());\r\n\r\n// for (var i = 1; i <= t; i++) {\r\n// var n = Number(readline());\r\n// console.log(arr[n - 1]);\r\n\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n var arr = [];\r\n for (var j = 1; arr.length <= 1000; j++) {\r\n if (j % 3 == 0 || j % 10 == 3) {\r\n continue;\r\n } else {\r\n arr.push(j);\r\n }\r\n //console.log(j);\r\n }\r\n\r\n //console.log((arr));\r\n var t = Number(readline());\r\n\r\n for (var i = 1; i <= t; i++) {\r\n var n = Number(readline());\r\n console.log(arr[n - 1]);\r\n\r\n\r\n }\r\n\r\n\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/18/21 morning\r\n * https://codeforces.com/contest/1560/problem/A\r\n */\r\nlet dp = [];\r\nconst solve = (k) => {\r\n // pr(k);\r\n pr(dp[k - 1]);\r\n};\r\n\r\nconst endWithThree = (x) => {\r\n let s = x + '';\r\n return s[s.length - 1] == '3';\r\n};\r\n\r\nconst prepare = () => {\r\n let x = 1;\r\n while (dp.length < 1001) {\r\n if (x % 3 != 0 && !endWithThree(x)) dp.push(x);\r\n x++;\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n prepare();\r\n // pr(dp);\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n// pr(hasThree(13))"}, {"source_code": "function checkIsValid (i) {\n if (i % 3 === 0) {\n return false;\n }\n if (i % 10 === 3) {\n return false;\n }\n return true;\n}\nfunction main(array) {\n let i = 0;\n let arr = [];\n while (true) {\n i += 1;\n if (checkIsValid(i)) {\n arr.push(i);\n if (arr.length >= 1001) {\n break;\n }\n }\n }\n const T = array[0];\n for (let i = 0; i < T; i++) {\n const k = array[i + 1];\n console.log(arr[k - 1]);\n }\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\n\n main(inputString);\n});"}, {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n ar = []\n for (let i = 1; i < 1e4; i++) {\n if (i % 3 != 0 && i % 10 != 3) {\n ar.push(i);\n }\n }\n let test = readInt();\n while (test--) {\n let k = readInt();\n console.log(ar[k - 1]);\n }\n}\n\nfunction main() {\n inputs = inputString.replace(' ', '\\n').trim().split('\\n').map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n console.log(solve(n))\n }\n// })()\n})\n\nfunction solve(n) {\n let k = 0\n while (n--) {\n k++\n while ((k % 10) === 3 || !(k % 3)) {\n k++\n }\n }\n return k\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n var i=0\r\n while (true) {\r\n i++\r\n if (array.length === 1000) break\r\n if (i % 3 === 0 || i % 10 === 3) continue\r\n array.push(i)\r\n\r\n }\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n\r\n console.log(array[n - 1])\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst nums = [0]\r\nfor (\r\n let e = 1;\r\n e < 1e7 && !(e % 3 != 0 && e % 10 != 3 && (nums.push(e), nums.length > 1010));\r\n ++e\r\n);\r\nfunction solve(e) {\r\n return nums[e]\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "const arr = [];\r\nlet i = 0;\r\nwhile(arr.length < 1000) {\r\n i++;\r\n if (i % 10 === 3 || i % 3 === 0) {\r\n continue;\r\n }\r\n arr.push(i);\r\n}\r\n\r\n\r\nfunction solve() {\r\n const k = Number(read());\r\n write(arr[k - 1]); \r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "// var fs = new require('fs');\r\nvar arr = new Array();\r\nvar t = 0;\r\nwhile(arr.length < 1000) {\r\n if(t % 10 != 3 && t % 3 != 0){\r\n arr.push(t);\r\n }\r\n t++;\r\n}\r\nvar t = Number(readline()); // readline()\r\nwhile(t > 0) {\r\n var a = Number(readline());\r\n// if(t != 0) { //\r\n// a = 10 - t; //\r\n// } //\r\n// else { //\r\n// a = 1000; //\r\n// } // redline()\r\n print(arr[a-1]);\r\n t--;\r\n}"}, {"source_code": "var nLoop = readline();\r\nvar dataArray = [];\r\nvar MAX_NUM = 2000;\r\n\r\nfor(var j = 1, indx = 0; j <= MAX_NUM; j++) {\r\n if ( j%3 !== 0 && j%10 !== 3 ) {\r\n dataArray[indx] = j;\r\n indx++;\r\n }\r\n}\r\n\r\nfor(var i = 0; i < nLoop; i++) {\r\n inpUser = readline();\r\n print(dataArray[inpUser - 1]);\r\n}"}, {"source_code": "var input = readline();\r\n\r\nfunction getSequense() {\r\n var seq = [];\r\n \r\n for (var i = 1; seq.length <= 1000; i++) {\r\n var isEnd3 = (\"\" + i).slice(-1) === \"3\"\r\n var isCratne = i % 3 === 0;\r\n \r\n if (!(isEnd3 || isCratne)) {\r\n seq.push(i);\r\n }\r\n }\r\n \r\n return seq;\r\n}\r\n\r\n\r\nvar sequense = getSequense();\r\nfor(var i=0;i<=input;i++) {\r\n var value = readline();\r\n\r\n if(value) {\r\n print(sequense[value-1])\r\n }\r\n}\r\n"}, {"source_code": "// 1560 A -Dislike of Threes\r\n\r\n// number tests\r\nvar numTests = parseInt( readline() );\r\n\r\nfor (var i = 0; i < numTests; i++) {\r\n \r\n // input data\r\n var numMaxDislike = parseInt( readline() );\r\n var str = numMaxDislike.toString()\r\n\r\n // variable program\r\n var numDislike = 0;\r\n var numberReach = 0;\r\n\r\n // old version\r\n /*\r\n for (var i = 1; i < numMaxDislike; i++) {\r\n var str = i.toString();\r\n if( i % 3 != 0 && str.charAt( str.length-1 ) != '3' ){\r\n k++;\r\n }\r\n }\r\n */\r\n\r\n // new version\r\n while ( numDislike < numMaxDislike){\r\n \r\n // trasform integer to string\r\n var str = (numberReach+1).toString();\r\n\r\n // numero non divisibile per 3 e che non finisca con 3 alla fine\r\n if( (numberReach+1) % 3 != 0 && str.charAt( str.length-1 ) != '3' ){\r\n numDislike++;\r\n }\r\n \r\n // increment the couter\r\n numberReach++\r\n \r\n }\r\n\r\n // output - print number raggiunto da numeri like, arrivando a k numeri dislike same a numMaxDislike\r\n print(numberReach);\r\n\r\n}\r\n"}, {"source_code": "var a=[1]\r\nvar num=2\r\nwhile(a.length<1000){\r\n if(num%3!==0&&num%10!==3)a.push(num)\r\n num++\r\n}\r\nvar n=readline()\r\nfor(i=0;i (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n const seq = [];\r\n \r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n \r\n let [count, ...entry] = lines;\r\n \r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n process.exit();\r\n return;\r\n \r\n});"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n return 0;\r\n\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input= '', readline, print;\r\n\r\nprocess.stdin.on('data', function(chunk) {\r\n input+=chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n input = input.split('\\n');\r\n print = function(data) {process.stdout.write(data)};\r\n var inputLineIndex = 0;\r\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\r\n main();\r\n});\r\n\r\nfunction main()\r\n{\r\n const lines = [...input]; /*your input text, split by lines*/\r\n \r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n}"}, {"source_code": "const { EOL } = require(\"os\");\r\nlet inp = \"\";\r\nprocess.stdin.on(\"data\", (c) => (inp+= c));\r\nprocess.stdin.on(\"end\", () => {\r\n const lines1 = inp.split(EOL); /*your input text, split by lines*/\r\nm(lines1)\r\n});\r\n\r\nfunction m(lines) {\r\n\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n return 0;\r\n}\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n const seq = [];\r\n \r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n \r\n let [count, ...entry] = lines;\r\n \r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1],'\\n')\r\n }\r\n return 0;\r\n \r\n});"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n return 0;\r\n\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n console.log(entry)\r\n\r\n for(let z = 0; z < entry.length; z++) {\r\n console.log(seq[entry[z]-1])\r\n }\r\n return 0;\r\n }\r\n main()\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n entry.forEach((k) => {\r\n console.log(seq[k-1])\r\n });\r\n return 0;\r\n }\r\n main()\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n entry.forEach((k) => {\r\n console.log(seq[k-1])\r\n });\r\n }\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n entry.forEach((k) => {\r\n console.log(seq[k-1])\r\n });\r\n }\r\n main()\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n let out = [];\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n entry.forEach((k) => {\r\n out.push(seq[k]);\r\n console.log(seq[k])\r\n });\r\n // console.log(out)\r\n // return 0;\r\n }\r\n main()\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n \r\n function main() {\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if (!(!(i % 3) || (\"\" + i).slice(-1) === \"3\")) {\r\n seq.push(i);\r\n }\r\n }\r\n\r\n let [count, ...entry] = lines;\r\n\r\n entry.forEach((k) => {\r\n console.log(seq[k]);\r\n });\r\n return 0;\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n const seq = [];\n\n for (let i = 1; seq.length <= 1000; i++) {\n if(!(!(i % 3) || (''+i).slice(-1) === '3')) {\n seq.push(i)\n }\n }\n \n let [count, ...entry] = input;\n \n entry.forEach(k => {\n console.log(seq[k])\n });\n return 0;\n}\n\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input= '', readline, print;\r\n\r\nprocess.stdin.on('data', function(chunk) {\r\n input+=chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n input = input.split('\\n');\r\n print = function(data) {process.stdout.write(data+'\\n')};\r\n var inputLineIndex = 0;\r\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\r\n process.exit(main() || 0);\r\n});\r\n\r\nfunction main()\r\n{\r\n const seq = [];\r\n\r\n for (let i = 1; seq.length <= 1000; i++) {\r\n if(!(!(i % 3) || (''+i).slice(-1) === '3')) {\r\n seq.push(i)\r\n }\r\n }\r\n \r\n let [count, ...entry] = input;\r\n \r\n entry.forEach(k => {\r\n console.log(seq[k])\r\n });\r\n return 0;\r\n}\r\n\r\nmain()"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n var b = 0\n for(j = 1; j <= lines[0]; j ++){\n var a = lines[j]\n while(b <= lines[0]){\n b++\n if(b % 3 === 0 || b[b.length - 1] == 3){\n b+=2 \n Number(lines[0]+3) \n\n }\n console.log(b)\n\n }\n\n }\n \n \n \n})"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n var p = 0\n for(j = 1; j<=lines[0]; j++){\n var a = lines[j]\n if(a != 3 || a % 3 === 0){\n p++\n }\n }\n for(k = 0; k < p; k++){\n var ak = lines[j]\n console.log(ak)\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n for(j = 1; j<=lines[0]; j++){\n var a = lines[j]\n if(a != 3 || a % 3 === 0){\n s = a\n console.log(s)\n }\n }\n \n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n for(j = 1; j<=lines[0]; j++){\n var a = lines[j]\n if(a != 3 || a % 3 === 0){\n s = a\n console.log(a)\n }\n }\n \n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n for(j = 1; j<=lines[0]; j++){\n var a = lines[j]\n var b = a.split('')\n if(b != 3 || a % 3 === 0){\n s = a\n }\n console.log(a)\n }\n \n \n});"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 1; i <= testCaseNumber; i++){\r\n let a = input[i];\r\n console.log(parseInt(polycarp[a]));\r\n }\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [1001];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 1; i <= testCaseNumber; i++){\r\n let a = input[i];\r\n parseInt(a);\r\n console.log(polycarp[a]);\r\n }\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [1001];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 1; i <= testCaseNumber; i++){\r\n let a = input[i];\r\n console.log(polycarp[a]);\r\n }\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [1001];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 1; i <= testCaseNumber; i++){\r\n let a = input[i];\r\n console.log(polycarp[a]);\r\n }\r\n\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [1001];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n let a = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++;\r\n }\r\n\r\n }\r\n\r\n for (let i = 0; i < testCaseNumber; i++){\r\n console.log(polycarp[a]);\r\n a++;\r\n }\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "let data = \"\";\r\n\r\nfunction solve(){\r\n\r\n let polycarp = [1001];\r\n let input = data.split(/ |\\n/);\r\n let testCaseNumber = parseInt(input[0]);\r\n let k = 1;\r\n let a = 1;\r\n\r\n for (let i = 1; k <= 1000; i++){\r\n\r\n if (i % 3 != 0 && i%10 !=3){\r\n polycarp[k] = i;\r\n k++\r\n }\r\n\r\n }\r\n\r\n for (let i = 0; i < testCaseNumber; i++){\r\n console.log(polycarp[a]);\r\n a++;\r\n }\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\nprocess.stdin.on('data', function(chunk){\r\n data += chunk;\r\n})\r\n\r\nprocess.stdin.on('end', function(chunk){\r\n solve();\r\n})"}, {"source_code": "// var fs = new require('fs');\r\nvar arr = new Array();\r\nvar t = 0;\r\nwhile(arr.length < 1000) {\r\n if(t % 10 != 3 && t % 3 != 0){\r\n arr.push(t);\r\n }\r\n t++;\r\n}\r\nvar t = Number(readline()); // readline()\r\nwhile(t > -1) {\r\n var a = Number(readline());\r\n// if(t != 0) { //\r\n// a = 10 - t; //\r\n// } //\r\n// else { //\r\n// a = 1000; //\r\n// } // redline()\r\n print(arr[a-1]);\r\n t--;\r\n}"}, {"source_code": "var nLoop = readline();\r\nvar dataArray = [];\r\nvar MAX_NUM = 10;\r\n\r\nfor(var j = 1, indx = 0; j <= MAX_NUM; j++) {\r\n if ( j%3 !== 0 && j%10 !== 3 ) {\r\n dataArray[indx] = j;\r\n indx++;\r\n }\r\n}\r\n\r\nfor(var i = 0; i < nLoop; i++) {\r\n inpUser = readline();\r\n print(dataArray[inpUser - 1]);\r\n}"}], "src_uid": "c37604d5d833a567ff284d7ce5eda059"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n res = new Array(m),\r\n f = new Array(n),\r\n g = new Array(n),\r\n max = [0, 0],\r\n s = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n let d = i - a[i] + 1;\r\n if (max[0] < d) {\r\n max[1] = max[0];\r\n max[0] = d;\r\n } else if (max[1] < d) {\r\n max[1] = d;\r\n }\r\n f[i] = Math.max(0, max[0]);\r\n g[i] = Math.max(0, max[1]);\r\n if (i) s[i] = [s[i - 1][0] + f[i], s[i - 1][1] + g[i]];else s[i] = [f[i], g[i]];\r\n }\r\n s[n] = s[n - 1];\r\n const search = (nums, l, r, d) => {\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (nums[m] >= d) {\r\n r = m;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return r;\r\n };\r\n let ans = n * (n + 1) / 2;\r\n for (let x = 0; x < m; x++) {\r\n var _f;\r\n let [i, v] = rns(2);\r\n i--;\r\n const d = Math.max(i - v + 1, (_f = f[i - 1]) !== null && _f !== void 0 ? _f : 0);\r\n if (d === f[i]) res[x] = ans - s[n - 1][0];else {\r\n if (d > f[i]) {\r\n const j = search(f, i + 1, n, d);\r\n res[x] = ans - (s[n - 1][0] - s[j - 1][0] + (j - i) * d);\r\n if (i) res[x] -= s[i - 1][0];\r\n } else {\r\n const j = search(g, i, n, d),\r\n k = search(g, j, n, f[i]);\r\n res[x] = ans - (s[n - 1][0] - s[k - 1][0] + (j - i) * d + (s[k - 1][1] - s[j - 1][1]));\r\n if (i) res[x] -= s[i - 1][0];\r\n }\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n res = new Array(m),\r\n f = new Array(n),\r\n g = new Array(n),\r\n max = [0, 0],\r\n s = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n let d = i - a[i] + 1;\r\n if (max[0] < d) {\r\n max[1] = max[0];\r\n max[0] = d;\r\n } else if (max[1] < d) {\r\n max[1] = d;\r\n }\r\n f[i] = Math.max(0, max[0]);\r\n g[i] = Math.max(0, max[1]);\r\n if (i) s[i] = [s[i - 1][0] + f[i], s[i - 1][1] + g[i]];else s[i] = [f[i], g[i]];\r\n }\r\n s[n] = s[n - 1];\r\n const search = (nums, l, r, d) => {\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (nums[m] >= d) {\r\n r = m;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return r;\r\n };\r\n const b = new Array(m);\r\n let ans = n * (n + 1) / 2;\r\n for (let x = 0; x < m; x++) {\r\n var _f;\r\n let [i, v] = rns(2);\r\n i--;\r\n b[x] = [i, v, x];\r\n const d = Math.max(i - v + 1, (_f = f[i - 1]) !== null && _f !== void 0 ? _f : 0);\r\n if (d === f[i]) res[x] = ans - s[n - 1][0];else {\r\n if (d > f[i]) {\r\n const j = search(f, i + 1, n, d);\r\n res[x] = ans - (s[n - 1][0] - s[j - 1][0] + (j - i) * d);\r\n if (i) res[x] -= s[i - 1][0];\r\n } else {\r\n const j = search(g, i, n, d),\r\n k = search(g, j, n, f[i]);\r\n res[x] = ans - (s[n - 1][0] - s[k - 1][0] + (j - i) * d + (s[k - 1][1] - s[j - 1][1]));\r\n if (i) res[x] -= s[i - 1][0];\r\n }\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n res = new Array(m),\r\n f = new Array(n),\r\n g = new Array(n),\r\n max = [0, 0],\r\n s = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n let d = i - a[i] + 1;\r\n if (max[0] < d) {\r\n max[1] = max[0];\r\n max[0] = d;\r\n } else if (max[1] < d) {\r\n max[1] = d;\r\n }\r\n f[i] = Math.max(0, max[0]);\r\n g[i] = Math.max(0, max[1]);\r\n if (i) s[i] = [s[i - 1][0] + f[i], s[i - 1][1] + g[i]];else s[i] = [f[i], g[i]];\r\n }\r\n s[n] = s[n - 1];\r\n const search = (nums, l, r, d) => {\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (nums[m] >= d) {\r\n r = m;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return r;\r\n };\r\n const b = new Array(m);\r\n let ans = n * (n + 1) / 2;\r\n for (let x = 0; x < m; x++) {\r\n var _f;\r\n let [i, v] = rns(2);\r\n i--;\r\n b[x] = [i, v, x];\r\n const d = Math.max(i - v + 1, (_f = f[i - 1]) !== null && _f !== void 0 ? _f : 0);\r\n if (d === f[i]) res[x] = ans - s[n - 1][0];else {\r\n if (d > f[i]) {\r\n const j = search(f, i + 1, n, d);\r\n res[x] = ans - (s[n - 1][0] - s[j - 1][0] + (j - i) * d);\r\n if (i) res[x] -= s[i - 1][0];\r\n } else {\r\n var _s$, _s;\r\n const j = search(g, i, n, d),\r\n k = search(g, j + 1, n, f[i]);\r\n res[x] = ans - (s[n - 1][0] - s[k - 1][0] + (j - i) * d + (s[k - 1][1] - ((_s$ = (_s = s[j - 1]) === null || _s === void 0 ? void 0 : _s[1]) !== null && _s$ !== void 0 ? _s$ : 0)));\r\n if (i) res[x] -= s[i - 1][0];\r\n }\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const st = [];\r\n const res = [];\r\n let pre = n - 1;\r\n for (let i = n - 1, j = m - 1; i >= 0 && j >= 0; i--) {\r\n if (i === n - 1 || dp[i + 1] <= dp[i]) {\r\n pre = i;\r\n }\r\n const d = dp[i] - i;\r\n while (st.length && st[st.length - 1][0] > d) {\r\n st.pop();\r\n }\r\n if (!st.length || d > st[st.length - 1][0]) st.push([d, i]);\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][1] < dp[i]) {\r\n var _sum2;\r\n const d = b[j][1] - i;\r\n let l = 0,\r\n r = st.length;\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (st[m][0] < d) {\r\n l = m + 1;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n const [, k] = st[l];\r\n const x = k - i + 1;\r\n res[b[j][2]] = ((_sum2 = sum[i - 1]) !== null && _sum2 !== void 0 ? _sum2 : 0) + (sum[n - 1] - sum[k]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp2;\r\n let d = Math.min((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1] - 1) + 1;\r\n if (dp[i] === d) res[b[j][2]] = sum[n - 1];else {\r\n const x = pre - i + 1;\r\n d -= dp[i];\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const st = [];\r\n const res = [];\r\n let pre = n - 1;\r\n for (let i = n - 1, j = m - 1; i >= 0; i--) {\r\n if (i === n - 1 || dp[i + 1] <= dp[i]) {\r\n pre = i;\r\n }\r\n const d = dp[i] - i;\r\n while (st.length && st[st.length - 1][0] > d) {\r\n st.pop();\r\n }\r\n if (!st.length || d > st[st.length - 1][0]) st.push([d, i]);\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][0] === n - 1) {\r\n var _sum2, _dp2;\r\n res[b[j][2]] = ((_sum2 = sum[n - 2]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Math.min((_dp2 = dp[n - 2]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1] - 1) + 1;\r\n j--;\r\n continue;\r\n } else if (b[j][1] < dp[i]) {\r\n var _sum3;\r\n const d = b[j][1] - i;\r\n let l = 0,\r\n r = st.length;\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (st[m][0] < d) {\r\n l = m + 1;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n const [, k] = st[l];\r\n const x = k - i + 1;\r\n res[b[j][2]] = ((_sum3 = sum[i - 1]) !== null && _sum3 !== void 0 ? _sum3 : 0) + (sum[n - 1] - sum[k]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp3;\r\n if (dp[i] < a[i] || dp[i] === ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1) res[b[j][2]] = sum[n - 1];else {\r\n const x = pre - i + 1,\r\n d = Math.min(b[j][1] - a[i], dp[i - 1] + 1 - dp[i]);\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const st = [];\r\n const res = [];\r\n let pre = n - 1;\r\n for (let i = n - 1, j = m - 1; i >= 0; i--) {\r\n if (i === n - 1 || dp[i + 1] <= dp[i]) {\r\n const d = dp[i] - i;\r\n pre = i;\r\n while (st.length && st[st.length - 1][0] >= d) {\r\n st.pop();\r\n }\r\n st.push([d, i]);\r\n }\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][0] === n - 1) {\r\n var _sum2, _dp2;\r\n res[b[j][2]] = ((_sum2 = sum[n - 2]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Math.min((_dp2 = dp[n - 2]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1] - 1) + 1;\r\n j--;\r\n continue;\r\n } else if (b[j][1] < dp[i]) {\r\n var _sum3;\r\n const d = b[j][1] - i;\r\n let l = 0,\r\n r = st.length;\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (st[m][0] < d) {\r\n l = m + 1;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n const [, k] = st[l];\r\n const x = k - i + 1;\r\n res[b[j][2]] = ((_sum3 = sum[i - 1]) !== null && _sum3 !== void 0 ? _sum3 : 0) + (sum[n - 1] - sum[k]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp3;\r\n if (dp[i] < a[i] || dp[i] === ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1) res[b[j][2]] = sum[n - 1];else {\r\n const x = pre - i + 1,\r\n d = Math.min(b[j][1] - a[i], dp[i - 1] + 1 - dp[i]);\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const st = [];\r\n const res = [];\r\n let pre = n - 1;\r\n for (let i = n - 1, j = m - 1; i >= 0; i--) {\r\n if (i === n - 1 || dp[i + 1] <= dp[i]) {\r\n const d = dp[i] - i;\r\n pre = i;\r\n while (st.length && st[st.length - 1][0] > d) {\r\n st.pop();\r\n }\r\n st.push([d, i]);\r\n }\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][0] === n - 1) {\r\n var _sum2, _dp2;\r\n res[b[j][2]] = ((_sum2 = sum[n - 2]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Math.min((_dp2 = dp[n - 2]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1] - 1) + 1;\r\n j--;\r\n continue;\r\n } else if (b[j][1] < dp[i]) {\r\n var _sum3;\r\n const d = b[j][1] - i;\r\n let l = 0,\r\n r = st.length;\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (st[m][0] < d) {\r\n l = m + 1;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n const [, k] = st[l];\r\n const x = k - i + 1;\r\n res[b[j][2]] = ((_sum3 = sum[i - 1]) !== null && _sum3 !== void 0 ? _sum3 : 0) + (sum[n - 1] - sum[k]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp3;\r\n if (dp[i] < a[i] || dp[i] === ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1) res[b[j][2]] = sum[n - 1];else {\r\n const x = pre - i + 1,\r\n d = Math.min(b[j][1] - a[i], dp[i - 1] + 1 - dp[i]);\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const tr = new BinarySearchTree((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const res = [];\r\n let pre = n - 1;\r\n for (let i = n - 1, j = m - 1; i >= 0; i--) {\r\n if (dp[i + 1] <= dp[i]) {\r\n pre = i;\r\n tr.insert([dp[i] - i, i]);\r\n }\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][0] === n - 1) {\r\n var _sum2, _dp2;\r\n res[b[j][2]] = ((_sum2 = sum[n - 2]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Math.min((_dp2 = dp[n - 2]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1] - 1) + 1;\r\n j--;\r\n continue;\r\n } else if (b[j][1] < dp[i]) {\r\n var _sum3;\r\n const [, k] = tr.ceiling([b[j][1] - i, i]);\r\n const x = k - i + 1;\r\n res[b[j][2]] = ((_sum3 = sum[i - 1]) !== null && _sum3 !== void 0 ? _sum3 : 0) + (sum[n - 1] - sum[k]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp3;\r\n if (dp[i] < a[i] || dp[i] === ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1) res[b[j][2]] = sum[n - 1];else {\r\n const x = pre - i + 1,\r\n d = Math.min(b[j][1] - a[i], dp[i - 1] + 1 - dp[i]);\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n _defineProperty(this, \"deleteResult\", false);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n this.deleteResult = false;\r\n if (!this.root) return this.deleteResult;\r\n this.deleteNode(val, this.root, null);\r\n return this.deleteResult;\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n this.deleteResult = true;\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n),\r\n m = rn(),\r\n b = new Array(m);\r\n for (let i = 0; i < m; i++) b[i] = [rn() - 1, rn(), i];\r\n b.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n const dp = new Array(n).fill(0),\r\n sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _sum;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n sum[i] = dp[i] + ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0);\r\n }\r\n const st = [];\r\n const res = [];\r\n for (let i = n - 1, j = m - 1; i >= 0; i--) {\r\n if (!st.length || dp[st[st.length - 1]] <= dp[i]) st.push(i);\r\n while (j >= 0 && b[j][0] === i) {\r\n if (b[j][0] === n - 1) {\r\n var _sum2, _dp2;\r\n res[b[j][2]] = ((_sum2 = sum[n - 2]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Math.min((_dp2 = dp[n - 2]) !== null && _dp2 !== void 0 ? _dp2 : 0, b[j][1]) + 1;\r\n j--;\r\n continue;\r\n }\r\n if (b[j][1] < dp[i]) {\r\n var _sum3;\r\n let len = dp[i] - b[j][1] - 1;\r\n let l = 0,\r\n r = st.length - 1;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (st[m] >= i + len) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n const x = st[l] - i + 1;\r\n res[b[j][2]] = ((_sum3 = sum[i - 1]) !== null && _sum3 !== void 0 ? _sum3 : 0) + (sum[n - 1] - sum[st[l]]) + b[j][1] * x + x * (x - 1) / 2;\r\n } else {\r\n var _dp3;\r\n if (dp[i] < a[i] || dp[i] === ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1) res[b[j][2]] = sum[n - 1];else {\r\n const x = st[st.length - 1] - i + 1,\r\n d = Math.min(b[j][1] - a[i], dp[i - 1] + 1 - dp[i]);\r\n res[b[j][2]] = sum[n - 1] + x * d;\r\n }\r\n }\r\n j--;\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "8a3b87734e221d3ec613525d35eebfd5"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet alpha;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n alpha = d;\n c++;\n return;\n }\n\n let ans = 0;\n const idxes = [];\n const word = d;\n\n for (let i = 0; i < word.length; i++) {\n const idx = alpha.indexOf(word[i]);\n idxes.push(idx);\n }\n\n for (let i = 1; i < idxes.length; i++) {\n ans += Math.abs(idxes[i - 1] - idxes[i]);\n }\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n", "positive_code": [{"source_code": "function findSum (input, alphabetIndex, wordIndex) {\r\n const alphabet = input[alphabetIndex];\r\n const word = input[wordIndex];\r\n if (word.length === 1) return 0;\r\n const map = new Map();\r\n let sum = 0;\r\n for (let i = 0; i < alphabet.length; i++)\r\n {\r\n map.set(alphabet[i], i + 1);\r\n }\r\n for (let i = 1; i < word.length; i++)\r\n {\r\n sum += Math.abs(map.get(word[i - 1]) - map.get(word[i]));\r\n }\r\n return sum;\r\n}\r\n\r\nlet i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const input = i.split(EOL);\r\n const n = input[0];\r\n let alphabetIndex = 1;\r\n let wordIndex = 2;\r\n for (let i = 0; i < n; i++) {\r\n console.log(findSum (input, alphabetIndex, wordIndex));\r\n alphabetIndex += 2;\r\n wordIndex += 2;\r\n }\r\n \r\n \r\n})"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n }\r\n)\r\n\r\n\r\nfunction solve(keyboard, str) {\r\n str = str.split('')\r\n let res = 0\r\n for (let i = 0; i < str.length - 1; ++i) {\r\n res += Math.abs((keyboard.indexOf(str[i]) + 1) - (keyboard.indexOf(str[i + 1]) + 1))\r\n }\r\n console.log(res)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n}\r\n// let a=readline().split(' ').map(Number)\r\n// a.sort((a,b)=>a-b)\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let s=readline();\r\n let n=s.length;\r\n let x=readline();\r\n let ans=0;\r\n let mp=new Map();\r\n for(let i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n a = lines[i].split('');\n }else{\n var b = lines[i].split('');\n var v = new Map();\n for(j = 0; j < a.length; j++){\n v.set(a[j], j);\n }\n var ans = 0;\n for(j = 1; j < b.length; j++){\n var x = v.get(b[j]);\n var y = v.get(b[j - 1]);\n ans += Math.abs(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n a = lines[i].split('');\n }else{\n var b = lines[i].split('');\n var v = new Map();\n for(j = 0; j < a.length; j++){\n v.set(a[j], j);\n }\n var ans = 0;\n for(j = 1; j < b.length; j++){\n var x = v.get(b[j]);\n var y = v.get(b[j - 1]);\n ans += Math.abs(x - y);\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.abs(x - y);\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.abs(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n\n\n\n\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = new Map();\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n a = new Map();\n var keyboard = lines[j];\n for(var l = 1; l < 27; l++){\n a.set(keyboard[l - 1], l);\n }\n }else{\n var word = lines[j];\n var answer = 0;\n var b = 0;\n var c = 0;\n for(var h = 1; h < word.length; h++){\n b = a.get(word[h]);\n c = a.get(word[h - 1]);\n answer += Math.abs(b - c);\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n run(...inputString);\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst input = readline();\r\n\r\nfunction run(...args) {\r\n\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i + 1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i = 0; i < word.length - 1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i + 1]];\r\n\r\n if (firstValue > secondValue) {\r\n sum += firstValue - secondValue;\r\n } else {\r\n sum += secondValue - firstValue;\r\n }\r\n }\r\n return sum;\r\n };\r\n\r\n for (let i = 1; i < args.length - 1; i+=2) {\r\n const r = findDistance(args[i], args[i + 1]);\r\n console.log(r)\r\n \r\n }\r\n \r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = new Map();\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n a = new Map();\n var keyboard = lines[j];\n for(l = 1; l < 27; l++){\n a.set(keyboard[l - 1], l);\n }\n }else{\n var word = lines[j];\n var answer = 0;\n var b = 0;\n var c = 0;\n for(h = 1; h < word.length; h++){\n b = a.get(word[h]);\n c = a.get(word[h - 1]);\n answer += Math.abs(b - c);\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "\"use strict\";\r\nexports.__esModule = true;\r\nvar readline = require(\"readline\");\r\nvar process = require(\"process\");\r\nvar console_1 = require(\"console\");\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nvar lines = [];\r\nrl.on(\"line\", function (line) {\r\n lines.push(line);\r\n});\r\nrl.on(\"close\", function () {\r\n main();\r\n});\r\nfunction main() {\r\n for (var i = 1; i < lines.length; i += 2) {\r\n var time = solve(lines[i], lines[i + 1]);\r\n console.log(time);\r\n }\r\n}\r\nfunction range(start, length) {\r\n (0, console_1.assert)(length > 0);\r\n return Array.from(Array(length).keys()).map(function (x) { return x + start; });\r\n}\r\nfunction solve(keyboard, word) {\r\n if (word.length <= 1) {\r\n return 0;\r\n }\r\n var keys = Array.from(keyboard);\r\n var keyIndexes = range(0, keyboard.length);\r\n var keyMap = new Map(keyIndexes.map(function (i) { return [keys[i], i]; }));\r\n var wordIndexes = Array.from(word).map(function (c) { return keyMap.get(c); });\r\n var distances = range(0, word.length - 1).map(function (i) {\r\n return Math.abs(wordIndexes[i] - wordIndexes[i + 1]);\r\n });\r\n var time = distances.reduce(function (x, y) { return x + y; }, 0);\r\n return time;\r\n}\r\n"}, {"source_code": "var readline = require(\"readline\");\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false,\r\n});\r\n\r\nvar lines = [];\r\n\r\nrl.on(\"line\", function (line) {\r\n lines.push(line);\r\n});\r\n\r\nrl.on(\"close\", function () {\r\n for (let i = 1; i < lines.length; i += 2) {\r\n let time = solve(lines[i], lines[i + 1]);\r\n console.log(time);\r\n }\r\n});\r\n\r\nfunction solve(keyboard, s) {\r\n if (s.length <= 1) {\r\n return 0;\r\n }\r\n\r\n let keyboardMap = new Map();\r\n for (let i = 0; i < keyboard.length; i++) {\r\n keyboardMap.set(keyboard[i], i);\r\n }\r\n\r\n letterPositions = [];\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n letterPositions.push(keyboardMap.get(s[i]));\r\n }\r\n\r\n let time = 0;\r\n let handPosition = letterPositions[0];\r\n\r\n for (let i = 1; i < s.length; i++) {\r\n time += Math.abs(letterPositions[i] - handPosition);\r\n handPosition = letterPositions[i];\r\n }\r\n\r\n return time;\r\n}\r\n"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() { return inputs.next().value.trim(); };\r\n\r\nasync function solve() {\r\n let t_1 = (await read()).split('')\r\n let t_2 = (await read()).split('')\r\n let keyMap = new Map(t_1.map((e, i) =>\r\n [e, i + 1]\r\n ))\r\n let reduced = t_2.reduce((a, e, i, o) => {\r\n if (i == 0) return a\r\n let current = keyMap.get(o[i])\r\n let previous = keyMap.get(o[i - 1])\r\n let diff = Math.abs(current - previous)\r\n return a + diff\r\n }, 0)\r\n console.log(reduced)\r\n}\r\n\r\nasync function main() {\r\n let tasks_amount = parseInt(await read())\r\n for (let i = 0; i < tasks_amount; i++) {\r\n await solve()\r\n }\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n await main();\r\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let j = 0; j < t; j++){\n\t\tlet a = nl.line().split('');\n\t\tlet b = nl.line().split('');\n\t\tlet al = {};\n\t\ta.forEach((e, i) => al[e] = i);\n\t\tlet cnt = 0;\n\t\tfor(let i = 1; i < b.length; i++) {\n\t\t\tcnt += Math.abs(al[b[i]] - al[b[i-1]]);\n\t\t}\n\t\tans.push(cnt);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst k = rl();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 1; i < s.length; i++) {\r\n\t\t\tans += Math.abs(k.indexOf(s[i]) - k.indexOf(s[i-1]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/*\r\n** 1607a Linear Keyboard\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst reverseText = (s) => { return s.split('').reverse().join('') }\r\nconst hasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\n\r\nconst hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\n\r\nconst isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\n\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&')\r\n\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\n// LIBRARY END\r\n\r\nconst tempPrintFunc = (keyboard, word) => {\r\n keyboard = keyboard.split('')\r\n word = word.split('')\r\n\r\n let val = 0\r\n let currChar = word[0]\r\n\r\n while (word.length > 0) {\r\n nextChar = word.shift()\r\n\r\n curr_pos = keyboard.indexOf(currChar)\r\n next_pos = keyboard.indexOf(nextChar)\r\n\r\n val += Math.abs(curr_pos - next_pos)\r\n\r\n currChar = nextChar\r\n }\r\n\r\n return val\r\n}\r\n\r\n//*\r\nfunction main() {\r\n let cases = readline()\r\n\r\n while (cases--) {\r\n let keyboard = readline()\r\n let word = readline()\r\n console.log(tempPrintFunc(keyboard, word))\r\n }\r\n}\r\n//*/\r\n\r\n\r\n\r\n// let keyboard = ''\r\n// let word = ''\r\n\r\n\r\n// keyboard = 'abcdefghijklmnopqrstuvwxyz'\r\n// word = 'hello'\r\n// console.log(tempPrintFunc(keyboard, word) == 13)\r\n\r\n// keyboard = 'abcdefghijklmnopqrstuvwxyz'\r\n// word = 'i'\r\n// console.log(tempPrintFunc(keyboard, word) == 0)\r\n\r\n// keyboard = 'abcdefghijklmnopqrstuvwxyz'\r\n// word = 'codeforces'\r\n// console.log(tempPrintFunc(keyboard, word) == 68)\r\n\r\n// keyboard = 'qwertyuiopasdfghjklzxcvbnm'\r\n// word = 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'\r\n// console.log(tempPrintFunc(keyboard, word) == 0)\r\n\r\n// keyboard = 'qwertyuiopasdfghjklzxcvbnm'\r\n// word = 'abacaba'\r\n// console.log(tempPrintFunc(keyboard, word) == 74)"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let s=readline();\r\n let n=s.length;\r\n let x=readline();\r\n let ans=0;\r\n let mp=new Map();\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n let input = Number(readline());\r\n let output = [];\r\n for(let i=0; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i].split('');\n a = new Map();\n for(j = 1; j <= n.length; j++){\n a.set(n[j - 1], j);\n }\n }else{\n var k = lines[i].split('');\n var ans = 0;\n var x = 0, y = 0;\n for(j = 1; j < k.length; j++){\n x = a.get(k[j]);\n y = a.get(k[j - 1]);\n ans += Math.floor(x - y);\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = new Map();\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n a = new Map();\n var keyboard = lines[j];\n for(var l = 1; l < 27; l++){\n a.set(keyboard[l], l);\n }\n }else{\n var word = lines[j];\n var answer = 0;\n var b = 0;\n var c = 0;\n for(var h = 1; h < word.length; h++){\n b = a.get(word[h]);\n c = a.get(word[h - 1]);\n answer += Math.abs(b - c);\n }\n if(isNaN(answer)){\n answer = 0;\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n console.log(typeof inputString)\r\n run(...inputString);\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst input = readline();\r\n\r\nfunction run(...args) {\r\n console.log(args[1])\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i + 1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i = 1; i < word.length - 1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i + 1]];\r\n\r\n if (firstValue > secondValue) {\r\n sum += firstValue - secondValue;\r\n } else {\r\n sum += secondValue - firstValue;\r\n }\r\n }\r\n return sum;\r\n };\r\n\r\n for (let i = 0; i < args.length - 1; i+=2) {\r\n const r = findDistance(args[i], args[i + 1]);\r\n console.log(r)\r\n \r\n }\r\n \r\n}"}, {"source_code": "function run(t, ...args) {\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i + 1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i = 0; i < word.length - 1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i + 1]];\r\n\r\n if (firstValue > secondValue) {\r\n sum += firstValue - secondValue;\r\n } else {\r\n sum += secondValue - firstValue;\r\n }\r\n }\r\n return sum;\r\n };\r\n const res = [];\r\n for (let i = 0; i < args.length - 1; i+=2) {\r\n const r = findDistance(args[i], args[i + 1]);\r\n console.log(r)\r\n res.push(r);\r\n }\r\n return res;\r\n}"}, {"source_code": "function run(t, ...args) {\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i + 1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i = 0; i < word.length - 1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i + 1]];\r\n\r\n if (firstValue > secondValue) {\r\n sum += firstValue - secondValue;\r\n } else {\r\n sum += secondValue - firstValue;\r\n }\r\n }\r\n return sum;\r\n };\r\n const res = [];\r\n for (let i = 0; i < args.length - 1; i+=2) {\r\n const r = findDistance(args[i], args[i + 1]);\r\n console.log(r)\r\n res.push(r);\r\n }\r\n return res;\r\n}\r\n\r\nrun(5,\r\n 'abcdefghijklmnopqrstuvwxyz',\r\n 'hello',\r\n 'abcdefghijklmnopqrstuvwxyz',\r\n 'i',\r\n 'abcdefghijklmnopqrstuvwxyz',\r\n 'codeforces',\r\n 'qwertyuiopasdfghjklzxcvbnm',\r\n 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq',\r\n 'qwertyuiopasdfghjklzxcvbnm',\r\n 'abacaba');"}, {"source_code": "function run (t, ...args) {\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i+1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i =0; i < word.length -1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i+1]];\r\n \r\n if (firstValue > secondValue) {\r\n sum += firstValue -secondValue;\r\n } else {\r\n sum += secondValue -firstValue;\r\n }\r\n }\r\n return sum;\r\n }\r\n const res = [];\r\n for (let i = 0; i < args.length - 1; i++) {\r\n res.push(findDistance(args[i], args[i+1]));\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function run (t, ...args) {\r\n const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i+1;\r\n }\r\n }\r\n\r\n let sum = 0;\r\n for (let i =0; i < word.length -1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i+1]];\r\n \r\n if (firstValue > secondValue) {\r\n sum += firstValue -secondValue;\r\n } else {\r\n sum += secondValue -firstValue;\r\n }\r\n }\r\n return sum;\r\n }\r\n\r\n for (let i = 0; i < args.length - 1; i++) {\r\n console.log(findDistance(args[i], args[i+1]));\r\n }\r\n\r\n}"}, {"source_code": "const findDistance = (keyboard, word) => {\r\n const keyboardMap = {};\r\n for (let i = 0; i <= keyboard.length; i++) {\r\n if (!keyboardMap[keyboard[i]]) {\r\n keyboardMap[keyboard[i]] = i+1;\r\n }\r\n }\r\n let sum = 0;\r\n for (let i =0; i < word.length -1; i++) {\r\n let firstValue = keyboardMap[word[i]];\r\n let secondValue = keyboardMap[word[i+1]];\r\n\r\n if (firstValue > secondValue) {\r\n sum += firstValue -secondValue;\r\n } else {\r\n sum += secondValue -firstValue;\r\n }\r\n }\r\n return sum;\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = new Map();\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n a = new Map();\n var keyboard = lines[j];\n for(var l = 1; l < 27; l++){\n a.set(keyboard[l - 1], l);\n }\n }else{\n var word = lines[j];\n var answer = 0;\n var b = 0;\n var c = 0;\n for(var h = 1; h < word.length; h++){\n b = a.get(word[h]);\n c = a.get(word[h - 1]);\n answer += Math.abs(b - c);\n }\n console.log(answer - 1);\n }\n }\n});"}], "src_uid": "7f9853be7ac857bb3c4eb17e554ad3f1"} {"source_code": "function main()\n{\n var s = readline();\n var ans = \"\";\n var flag = false,\n quote = false;\n for ( var i = 0; i < s.length; i++ )\n {\n if ( !flag )\n {\n if ( s[i] == \"\\\"\" )\n {\n flag = true;\n quote = true;\n }\n else if ( s[i] != \" \" )\n {\n ans += s[i];\n flag = true;\n }\n }\n else\n {\n if ( quote == true )\n {\n if ( s[i] == \"\\\"\" )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n flag = false;\n quote = false;\n }\n else\n {\n ans += s[i];\n }\n }\n else\n {\n if ( s[i] == \" \" )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n flag = false;\n quote = false;\n }\n else\n {\n ans += s[i];\n }\n }\n }\n }\n if ( ans != \"\" )\n print(\"<\"+ans+\">\");\n}\n\nmain();\n", "positive_code": [{"source_code": "var ans = [];\nreadline().replace(/\\\"([^\"]*)\\\"|(\\S+)/g, function(_, a, b) {\n\tans.push('<' + (b || a) + '>');\n\treturn '';\n});\nprint(ans.join('\\n'));"}, {"source_code": ";(function () {\n\n\tprint(function (s, result) {\n\n\t\ts = s.trim().split('');\n\n\t\tvar word = '', isQuote = false;\n\n\t\tfor (var i = 0, _i = s.length; i < _i; i++) {\n\t\t\tif (s[i] === '\"') {\n\t\t\t\tif (isQuote) {\n\t\t\t\t\tresult.push(['<', word, '>'].join(''));\n\t\t\t\t\tword = '';\n\t\t\t\t}\n\n\t\t\t\tisQuote = !isQuote;\n\t\t\t} else if (isQuote === false && s[i] === ' ') {\n\t\t\t\tword = word.trim();\n\t\t\t\tif (word.length) {\n\t\t\t\t\tresult.push(['<', word, '>'].join(''));\n\t\t\t\t}\n\t\t\t\tword = '';\n\t\t\t} else {\n\t\t\t\tword += s[i];\n\t\t\t}\n\t\t}\n\n\t\tif (word.length) {\n\t\t\tresult.push(['<', word, '>'].join(''));\n\t\t}\n\n\t\treturn result.join('\\n');\n\n\t}(readline(), []));\n\n}.call(this));\n"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\n//print('command: ' + command);\ncommand = ' ' + command;\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\nif (lex) print(\"<\"+lex+\">\");"}, {"source_code": "function main()\n{\n var s = readline();\n var ans = \"\";\n var flag = false,\n quote = false;\n for ( var i = 0; i < s.length; i++ )\n {\n if ( s[i] == \"\\\"\" )\n {\n if ( quote )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n }\n quote = !quote;\n }\n else if ( !quote && s[i] == \" \" )\n {\n if ( ans.length )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n }\n }\n else\n {\n ans += s[i];\n }\n }\n if ( ans != \"\" )\n print(\"<\"+ans+\">\");\n}\n\nmain();\n"}, {"source_code": "function main(){\n var s = readline();\n var ans = \"\";\n var flag = false,\n quote = false;\n for ( var i = 0; i < s.length; i++ ){\n if ( s[i] == \"\\\"\" ){\n if ( quote ){\n print(\"<\"+ans+\">\");\n ans = \"\";\n }\n quote = !quote;\n }\n else if ( !quote && s[i] == \" \" ){\n if ( ans.length ){\n print(\"<\"+ans+\">\");\n ans = \"\";\n }\n }\n else{\n ans += s[i];\n }\n }\n if ( ans != \"\" )\n print(\"<\"+ans+\">\");\n}\n\nmain();\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function (s, result) {\n\n\t\ts = s.trim().split('');\n\n\t\tvar word = '', isQuote = false;\n\n\t\tfor (var i = 0, _i = s.length; i < _i; i++) {\n\t\t\tif (s[i] === '\"') {\n\t\t\t\tif (isQuote) {\n\t\t\t\t\tisQuote = false;\n\t\t\t\t\tresult.push(['<', word, '>'].join(''));\n\t\t\t\t\tword = '';\n\t\t\t\t} else {\n\t\t\t\t\tisQuote = true;\n\t\t\t\t}\n\t\t\t} else if (isQuote === false && s[i] === ' ') {\n\t\t\t\tword = word.trim();\n\t\t\t\tif (word.length) result.push(['<', word, '>'].join(''));\n\t\t\t\tword = '';\n\t\t\t} else {\n\t\t\t\tword += s[i];\n\t\t\t}\n\t\t}\n\n\t\treturn result.join('\\n');\n\n\t}(readline(), []));\n\n}.call(this));\n"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\n\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n lex = '';\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\n"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\n//print('command: ' + command);\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n lex = '';\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\nif (lex) print(\"<\"+lex+\">\");"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\n//print('command' + command);\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n lex = '';\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\nif (lex) print(\"<\"+lex+\">\");"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\nprint('command: ' + command);\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\nif (lex) print(\"<\"+lex+\">\");"}, {"source_code": "//var command = ' firstarg second \"\" '\nvar command = readline()\n , quoteOpen = false\n , spaceWas = false;\n//print('command: ' + command);\nfor (var i = 0, lex = ''; i < command.length; i++) {\n if (command[i] === '\"') {\n if (quoteOpen) {\n print(\"<\"+lex+\">\");\n quoteOpen = false;\n spaceWas = false;\n lex = '';\n } else {\n quoteOpen = true;\n spaceWas = false;\n lex = '';\n }\n } else if (command[i] === ' ') {\n if (!quoteOpen) {\n if (!spaceWas) {\n spaceWas = true;\n } else if (command[i-1] !== ' '){\n print(\"<\"+lex+\">\");\n lex = '';\n }\n } else {\n lex += command[i];\n }\n } else {\n lex += command[i];\n }\n}\nif (lex) print(\"<\"+lex+\">\");"}, {"source_code": "function main()\n{\n var s = readline();\n var ans = \"\";\n var flag = false,\n quote = false;\n for ( var i = 0; i < s.length; i++ )\n {\n if ( !flag )\n {\n if ( s[i] == \"\\\"\" )\n {\n flag = true;\n quote = true;\n }\n else if ( s[i] != \" \" )\n {\n ans += s[i];\n flag = true;\n }\n }\n else\n {\n if ( quote == true )\n {\n if ( s[i] == \"\\\"\" )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n flag = false;\n quote = false;\n }\n else\n {\n ans += s[i];\n }\n }\n else\n {\n if ( s[i] == \" \" )\n {\n print(\"<\"+ans+\">\");\n ans = \"\";\n flag = false;\n quote = false;\n }\n else\n {\n ans += s[i];\n }\n }\n }\n }\n}\n\nmain();\n"}], "src_uid": "6c7858731c57e1b24c7a299a8eeab373"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let size = readline();\n let arr = readline().split(\" \").map(Number);\n\n let max = -1;\n let sum = 0;\n for (let j = 0; j < arr.length; j++) {\n if (arr[j] > max) max = arr[j];\n sum += arr[j];\n }\n let sumMinusMax = sum - max;\n // console.log(sum, max);\n if (sum === 0) {\n console.log(0);\n } else if (sumMinusMax >= max) {\n console.log(1);\n } else {\n console.log(max - sumMinusMax);\n }\n }\n}\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let max = 0,\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n max = Math.max(max, arr[i]);\r\n sum += arr[i];\r\n }\r\n if (sum === 0) console.log(0);\r\n else {\r\n sum = sum - max;\r\n if (sum >= max - 1) console.log(1);\r\n else console.log(1 + (max - sum - 1));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mx = Math.max(...a);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n; i++) sum += a[i];\r\n\t\tsum -= mx;\r\n\r\n\t\tlet ans;\r\n\t\tif (mx == 0) ans = 0;\r\n\t\telse if (sum >= mx) ans = 1;\r\n\t\telse ans = mx - sum;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n - 1; i++) sum += a[i];\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (sum + a[n-1]) \r\n\t\t\tans = 1 + Math.max(a[n-1] - sum - 1, 0);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = {};\r\n\t\tvar max = 0;\r\n\t\tvar K = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tK += list[i];\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tif(K == 0){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput = Math.max(output, max - 1 - (K - list[i]));\r\n\t\t}\r\n\t\tmyout(output + 1);\r\n\t}\r\n}\r\n"}, {"source_code": "function solve() {\r\n const n = Number(read());\r\n const arr = readArray(BigInt);\r\n let maxNum = 0n;\r\n let sumNum = 0n;\r\n for (const x of arr) {\r\n sumNum += x;\r\n if (x > maxNum) {\r\n maxNum = x;\r\n }\r\n }\r\n if (sumNum === 0n) {\r\n write(0);\r\n return;\r\n }\r\n sumNum -= maxNum;\r\n if (maxNum <= sumNum + 1n) {\r\n write(1);\r\n return;\r\n }\r\n write(maxNum - sumNum);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "\nfunction readLineNums () {\n return readline().split(' ').map(x => parseInt(x));\n}\n\n// ***** PROBLEM SOLUTION *****\n\nvar n = readLineNums();\n\nwhile (n--) {\n readLineNums();\n var passes = readLineNums();\n\n if ( !passes.some(pass => pass !== 0) ) {\n print(0);\n continue;\n }\n var max = passes.reduce((max, num) => (num > max) ? num : max, -1);\n var sum = passes.reduce((sum, num) => (num + sum), 0);\n\n var remaining = sum - max;\n\n if (remaining >= max) {\n print(1);\n } else {\n print(2 * max - sum);\n }\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n if (arr[0] === 0) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ans = 0;\r\n for (let i = 1; i < n; i++) {\r\n let dif = Math.abs(arr[i] - arr[i - 1]);\r\n if (dif <= 0) arr[i] = 1;\r\n else arr[i] = dif;\r\n }\r\n if (arr[n - 1] <= 1) console.log(1);\r\n else console.log(arr[n - 1]);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n if (arr[0] === 0) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ans = 0;\r\n for (let i = 1; i < n; i++) {\r\n let dif = Math.abs(arr[i] - arr[i - 1]);\r\n if (dif <= 0) arr[i] = 0;\r\n else arr[i] = dif;\r\n }\r\n if (arr[n - 1] <= 1) console.log(1);\r\n else console.log(arr[n - 1]);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n if (arr[n - 1] === 0) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ans = 0;\r\n for (let i = 1; i < n; i++) {\r\n let dif = Math.abs(arr[i] - arr[i - 1]);\r\n if (dif <= 0) arr[i] = 0;\r\n else arr[i] = dif;\r\n }\r\n if (arr[n - 1] <= 1) console.log(1);\r\n else console.log(arr[n - 1]);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n - 1; i++) sum += a[i];\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (sum) \r\n\t\t\tans = 1 + Math.max(a[n-1] - sum - 1, 0);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "98d9c44e460e141f062fcd6c345a4a1d"} {"source_code": "var readline=require('readline');\nvar rl=readline.createInterface(process.stdin,process.stdout);\nvar n=-1;\nvar checker=0;\nvar mySet=new Set();\nrl.on('line', lineInput => {\n if(n==-1){\n n=parseInt(lineInput);\n }\n else{\n mySet.add(lineInput);\n checker++;\n if(checker==n){\n console.log(mySet.size);\n rl.close();\n }\n }\n\n});\n\n\n\n/* inputs.push(lineInput);\nconst n=parseInt(lineInput);\nfor(let i=0; i inputs += c);\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = inputs.split(EOL);\n\n let T = parseInt(lines[0]);\n for (let i = 0; i < T; i++) {\n main1(lines.slice(i * 4 + 1, (i + 1) * 4 + 1));\n }\n});\n\nfunction main1(lines) {\n const N = lines[0];\n const A = lines[1].split(' ').map(u => parseInt(u));\n const B = lines[2].split(' ').map(u => parseInt(u));\n const C = lines[3].split(' ').map(u => parseInt(u));\n\n const arrow = {};\n for (let i = 0; i < N; i++) {\n arrow[A[i]] = B[i];\n }\n\n const cSet = {};\n for (let i = 0; i < N; i++) {\n cSet[C[i]] = true;\n }\n\n const taken = new Array(N + 1);\n for (let i = 0; i <= N; i++) {\n taken[i] = false;\n }\n\n const cycles = [];\n for (let i = 1; i <= N; i++) {\n if (!taken[i]) {\n const cycle = [];\n let j = i;\n while (!taken[j]) {\n taken[j] = 1;\n cycle.push(j);\n j = arrow[j];\n }\n\n cycles.push(cycle);\n }\n }\n\n let ans = 1;\n let MODD = 1000000007;\n for (const cycle of cycles) {\n let ok = true;\n for (const u of cycle) {\n if (cSet[u]) {\n ok = false;\n break;\n }\n }\n\n if (ok && cycle.length > 1) {\n ans = (ans * 2) % MODD;\n }\n }\n\n console.log(ans);\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = RTI((u, p) => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n const inside = () => {\r\n let res = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n res.push([v, u]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n if (p !== -1) low[p] = Math.min(low[p], low[u]);\r\n };\r\n return [inside, after];\r\n });\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i, -1);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = result => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = RTI((u, p) => {\r\n const before = () => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n res.push([v, u]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n if (p !== -1) low[p] = Math.min(low[p], low[u]);\r\n };\r\n return [before, inside, after];\r\n });\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i, -1);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\nfunction RTI(fn) {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[done, args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const after = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside();\r\n callStack.push([after, ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = async () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = RTI((u, p) => {\r\n const before = () => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n res.push([v, u]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n if (p !== -1) low[p] = Math.min(low[p], low[u]);\r\n };\r\n return [before, inside, after];\r\n });\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i, -1);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\nfunction RTI(fn) {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[done, args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const after = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside();\r\n callStack.push([after, ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = RTI((u, p) => {\r\n const before = () => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n res.push([v, u]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n if (p !== -1) low[p] = Math.min(low[p], low[u]);\r\n };\r\n return [before, inside, after];\r\n });\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i, -1);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\nfunction RTI(fn) {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[done, args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const after = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside(...args);\r\n callStack.push([after, ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map(),\r\n fa = [];\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n const callStack = [[u]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const v = curCall.pop();\r\n if (dfn[v] === low[v]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === v) break;\r\n }\r\n idx++;\r\n }\r\n const u = fa[v];\r\n low[u] = Math.min(low[u], low[v]);\r\n }\r\n if (!curCall) break;\r\n const u = curCall[curCall.length - 1];\r\n if (!dfn[u]) {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n let nextCall = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n fa[v] = u;\r\n nextCall.push(v);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n callStack.push(nextCall);\r\n continue;\r\n } else if (set.has(u)) {\r\n const f = fa[u];\r\n low[f] = Math.min(low[f], dfn[u]);\r\n }\r\n curCall.pop();\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n let ans = '';\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n ans += calc(T)+'\\n';\n } else\n pcalc();\n process.stdout.write(ans)\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst MOD = 1e9+7;\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n let C = ra();\n LT({n, A, B});\n // PROCESSING:\n let posA = new Array(n+1).fill(-1);\n let posB = new Array(n+1).fill(-1);\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n const sc = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, sa, sb, sc)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb, sc) {\n const r = {}\n sa.forEach((x, i) => {\n r[x] = i\n })\n //\n const v = {}\n let ans = 1\n for (let i = 0; i < n; i++) {\n if (v[sa[i]]) continue\n v[sa[i]] = 1\n\n let j = i\n let f = 0\n let k = 1\n while (!v[sb[j]]) {\n // v[sa[j]] = 1\n v[sb[j]] = 1\n k++\n if (sc[j]) f = 1\n //\n j = r[sb[j]]\n // console.log('j', j)\n }\n if (sc[j]) f = 1\n // console.log(k)\n if (!f) {\n ans = mul(ans, k === 1 ? 1 : 2)\n }\n }\n // console.log('-')\n return ans\n}\n\nconst MOD = 1e9 + 7\nconst MOD_CUT = ((1 << 20) * (1 << 20)) % MOD\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction minus(a, b) {\n return add(add(a, -b), MOD)\n}\nfunction mul(a, b) {\n let r = (a >> 20) * (b >> 20) * MOD_CUT\n + (a & 0xfff00000) * (b & 0xfffff)\n + (a & 0xfffff) * b\n return r % MOD\n}\nfunction pow(a, b) {\n let r = 1\n let base = a\n while (b) {\n if (b & 1) {\n r = mul(r, base)\n }\n b >>= 1\n base = mul(base, base)\n }\n return r\n}\n"}], "negative_code": [{"source_code": "\r\nconst {\r\n Worker, isMainThread, parentPort, workerData\r\n} = require('worker_threads');\r\n\r\nfunction parseJSAsync(script, workerData) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(script, { eval: true, workerData });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', (code) => {\r\n if (code !== 0)\r\n reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n};\r\n\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n\r\n await parseJSAsync(`\r\n const {\r\n Worker, isMainThread, parentPort, workerData\r\n } = require('worker_threads');\r\nlet MaximumCallStateSize=0\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n MaximumCallStateSize++\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n MaximumCallStateSize=0\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nfunction main(read) {\r\n try {\r\n let t = Number(read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(read());\r\n const a = read().split(' ').map(Number);\r\n const b = read().split(' ').map(Number);\r\n const d = read().split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\\\n'));\r\n } catch (error) {\r\n console.log('error',MaximumCallStateSize,error)\r\n }\r\n}\r\n\r\n\r\nvoid function () {\r\n const inputs = workerData;\r\n let i = 0;\r\n function read() {\r\n return inputs[i++];\r\n }\r\n main(read);\r\n}();\r\n\r\n `, inputs)\r\n}();\r\n"}, {"source_code": "\r\nconst {\r\n Worker, isMainThread, parentPort, workerData\r\n} = require('worker_threads');\r\n\r\nfunction parseJSAsync(script, workerData) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(script, { eval: true, workerData });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', (code) => {\r\n if (code !== 0)\r\n reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n};\r\n\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n\r\n await parseJSAsync(`\r\n const {\r\n Worker, isMainThread, parentPort, workerData\r\n } = require('worker_threads');\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nfunction main(read) {\r\n try {\r\n let t = Number(read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(read());\r\n const a = read().split(' ').map(Number);\r\n const b = read().split(' ').map(Number);\r\n const d = read().split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\\\n'));\r\n } catch (error) {\r\n console.log('error',error)\r\n }\r\n}\r\n\r\n\r\nvoid function () {\r\n const inputs = workerData;\r\n let i = 0;\r\n function read() {\r\n return inputs[i++];\r\n }\r\n main(read);\r\n}();\r\n\r\n `, inputs)\r\n}();\r\n"}, {"source_code": "\r\nconst {\r\n Worker, isMainThread, parentPort, workerData\r\n} = require('worker_threads');\r\n\r\nfunction parseJSAsync(script, workerData) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(script, { eval: true, workerData });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', (code) => {\r\n if (code !== 0)\r\n reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n};\r\n\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n\r\n await parseJSAsync(`\r\n const {\r\n Worker, isMainThread, parentPort, workerData\r\n } = require('worker_threads');\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nfunction main(read) {\r\n let t = Number(read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(read());\r\n const a = read().split(' ').map(Number);\r\n const b = read().split(' ').map(Number);\r\n const d = read().split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\\\n'));\r\n}\r\n\r\n\r\nvoid function () {\r\n const inputs = workerData;\r\n let i = 0;\r\n function read() {\r\n return inputs[i++];\r\n }\r\n main(read);\r\n}();\r\n\r\n `, inputs)\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = async () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = async u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n await dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) await dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = async () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = async u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) await dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n console.log(g);\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map(),\r\n fa = [];\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n const callStack = [[u]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const v = curCall.pop();\r\n if (dfn[v] === low[v]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === v) break;\r\n }\r\n idx++;\r\n }\r\n const u = fa[v];\r\n low[u] = Math.min(low[u], low[v]);\r\n }\r\n if (!curCall) break;\r\n const u = curCall[curCall.length - 1];\r\n if (!dfn[u]) {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n let nextCall = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n fa[v] = u;\r\n nextCall.push(v);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n callStack.push(nextCall);\r\n continue;\r\n } else if (set.has(u)) {\r\n const f = fa[u];\r\n low[f] = Math.min(low[f], dfn[u]);\r\n }\r\n curCall.pop();\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n const sc = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, sa, sb, sc)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb, sc) {\n const r = {}\n sa.forEach((x, i) => {\n r[x] = i\n })\n //\n const v = {}\n let ans = 1\n for (let i = 0; i < n; i++) {\n if (v[sa[i]]) continue\n v[sa[i]] = 1\n\n let j = i\n let f = 0\n let k = 1\n while (!v[sb[j]]) {\n // v[sa[j]] = 1\n v[sb[j]] = 1\n k++\n if (sc[j]) f = 1\n //\n j = r[sb[j]]\n // console.log('j', j)\n }\n // console.log(k)\n if (!f) {\n ans = mul(ans, k === 1 ? 1 : 2)\n }\n }\n return ans\n}\n\nconst MOD = 1e9 + 7\nconst MOD_CUT = ((1 << 20) * (1 << 20)) % MOD\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction minus(a, b) {\n return add(add(a, -b), MOD)\n}\nfunction mul(a, b) {\n let r = (a >> 20) * (b >> 20) * MOD_CUT\n + (a & 0xfff00000) * (b & 0xfffff)\n + (a & 0xfffff) * b\n return r % MOD\n}\nfunction pow(a, b) {\n let r = 1\n let base = a\n while (b) {\n if (b & 1) {\n r = mul(r, base)\n }\n b >>= 1\n base = mul(base, base)\n }\n return r\n}\n"}], "src_uid": "15823d23340c845e0c257974390cb69f"} {"source_code": "var s = readline()\ns = s.replace(/(.)\\1+/g, '$1$1');\ns = s.replace(/(.)\\1(.)\\2/g, '$1$1$2');\nprint(s);", "positive_code": [{"source_code": "print(readline().replace(/(\\w)(?=(\\1{2,}))\\2/g, \"$1$1\").replace(/((\\w)(?=(\\2))\\3)((\\w)(?=(\\5))\\6)/g,\"$2$2$5\"));"}, {"source_code": "var s = readline()\ns = s.replace(/(.)\\1+/g, '$1$1');\ns = s.replace(/(.)\\1(.)\\2/g, '$1$1$2');\nprint(s);"}], "negative_code": [{"source_code": "print(readline().replace(/(.)\\1+/g, '$1$1').replace(/^(.)\\1+/, '$1').replace(/(.)\\1+$/, '$1'));"}], "src_uid": "31d803d886c47fe681bdcfbe6c74f090"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); \n for(j = 1; j <= lines[0]; j ++){\n var l = lines[j].split(' ')\n var r = l[0]\n var b = l[1]\n var d = l[2]\n if(Math.abs(r - b) <= d*(Math.min(r, b))){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n});\n", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); \n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var l = lines[j].split(' ');\n var r = l[0];\n var b = l[1];\n var d = l[2];\n if(Math.abs(r - b) <= d*Math.min(r, b)){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main() {\r\n const test= readline();\r\n \r\n for(let i=0;i=Math.max(r[0],r[1])?\"Yes\":\"No\" ;\r\n return result;\r\n }\r\n \r\n "}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar R = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar D = nextInt();\r\n\t\tif(R > B){\r\n\t\t\tvar tmp = R;\r\n\t\t\tR = B;\r\n\t\t\tB = tmp;\r\n\t\t}\r\n\t\tvar diff = B - R;\r\n\t\tvar single = Math.ceil(diff / R);\r\n\t\tif(single <= D){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-a.ts\n\nconst io = new IO();\n\nfunction solve(r, b, d) {\n let min = Math.min(r, b);\n let max = Math.max(r, b);\n let rem = max - min;\n\n if (rem <= min * d) {\n io.writeLine('YES');\n } else {\n io.writeLine('NO');\n }\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let r = io.nextNum();\n let b = io.nextNum();\n let d = io.nextNum();\n solve(r, b, d);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b, d]) {\r\n const s = Math.min(a, b);\r\n (Math.abs(a - b) / s <= d) ? console.log('YES') : console.log('NO')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "\r\nvar t=+ readline();\r\nwhile(t--){\r\n var input= readline();\r\n var arr= input.split(\" \").map(x=>+x);\r\n var r=arr[0];\r\n var b=arr[1];\r\n var d=arr[2];\r\n if(r>b){\r\n var temp=r;\r\n r=b;\r\n b=temp;\r\n }\r\n var res=r*(d+1);\r\n if(res>=b)print(\"YES\")\r\n else print(\"NO\");\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(inp){\r\n let parsedInput = inp.split(' ')\r\n .map(el=>Number( el)); // el.replace(/[^0-9]/g, '') \r\n if( parsedInput.length === 1 ) return null\r\n\r\n let [redAmount, blueAmount, maxDif] = [...parsedInput];\r\n if(maxDif===0) return redAmount===blueAmount ? 'yes' : 'no';\r\n\r\n let [min, max] = [Math.min(redAmount, blueAmount), Math.max(redAmount, blueAmount)],\r\n minDif = Math.ceil(max / min)-1;\r\n\r\n if(minDif > maxDif) return 'no'\r\n return 'yes'\r\n}\r\n\r\nrl.on('line', (input) => {\r\n let i = candyShop(input);\r\n if(i != null ){ console.log(i) }\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(inp){\r\n let parsedInput = inp.split(' ')\r\n .map(el=>Number( el)); // el.replace(/[^0-9]/g, '') \r\n if( parsedInput.length === 1 ) return null\r\n\r\n let [redAmount, blueAmount, maxDif] = [...parsedInput];\r\n // if(maxDif===0) return redAmount===blueAmount ? 'yes' : 'no';\r\n\r\n let [min, max] = [Math.min(redAmount, blueAmount), Math.max(redAmount, blueAmount)],\r\n minDif = Math.ceil(max / min)-1;\r\n\r\n if(minDif > maxDif) return 'no'\r\n return 'yes'\r\n}\r\n\r\nrl.on('line', (input) => {\r\n let i = candyShop(input);\r\n if(i != null ){ console.log(i) }\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(inp){\r\n let parsedInput = inp.split(' ')\r\n .map( el => Number( el.replace(/[^0-9]/g, '') ) ); // el.replace(/[^0-9]/g, '') \r\n if( parsedInput.length === 1 ) return null\r\n\r\n let [redAmount, blueAmount, maxDif] = [...parsedInput];\r\n if(maxDif===0) return redAmount===blueAmount ? 'yes' : 'no';\r\n\r\n let [min, max] = [Math.min(redAmount, blueAmount), Math.max(redAmount, blueAmount)],\r\n minDif = Math.ceil(max / min)-1;\r\n\r\n if(minDif > maxDif) return 'no'\r\n return 'yes'\r\n}\r\n\r\nrl.on('line', (input) => {\r\n let i = candyShop(input);\r\n if(i != null ){ console.log(i) }\r\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); \n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var l = lines[j].split(' ');\n var r = l[0];\n var b = l[1];\n var d = l[2];\n if(Math.abs(r - b) <= d * Math.min(r, b)){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n;// CONCATENATED MODULE: ./src/io.js\nvar interact = function interact(main) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var inputString = '';\n var currentLine = 0;\n\n var readline = function readline() {\n return inputString[currentLine++];\n };\n\n var print = function print() {\n for (var _len = arguments.length, any = new Array(_len), _key = 0; _key < _len; _key++) {\n any[_key] = arguments[_key];\n }\n\n process.stdout.write(any.join(' '));\n };\n\n var println = function println() {\n for (var _len2 = arguments.length, any = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n any[_key2] = arguments[_key2];\n }\n\n any.length > 0 && print(any);\n print('\\n');\n };\n\n var obj = {\n print: print,\n println: println,\n readline: readline\n };\n process.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n });\n process.stdin.on('end', function () {\n inputString = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main(obj);\n });\n};\n\n/* harmony default export */ const io = (interact);\n;// CONCATENATED MODULE: ./src/index.js\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\n\n\nvar main = function main(io) {\n var tc = Number.parseInt(io.readline());\n\n while (tc--) {\n var _io$readline$split$ma = io.readline().split(' ').map(function (x) {\n return Number.parseInt(x);\n }),\n _io$readline$split$ma2 = _slicedToArray(_io$readline$split$ma, 3),\n r = _io$readline$split$ma2[0],\n b = _io$readline$split$ma2[1],\n d = _io$readline$split$ma2[2];\n\n if (r > b) {\n var temp = r;\n r = b;\n b = temp;\n } // assert r <= b\n\n\n var sat = b <= r * (1 + d);\n io.println(sat ? 'YES' : 'NO');\n }\n};\n\nio(main);\n/******/ })()\n;"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--)\r\n {\r\n const [r,b,d] = get_ints();\r\n (Math.min(r,b) * (d + 1)) >= Math.max(r,b) ? print('YES') : print('NO')\r\n \r\n }\r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (var i = 0; i < t; i++) {\r\n const [r, b, d] = input().split(\" \").map(Number);\r\n\r\n const min = Math.min(r, b);\r\n const max = Math.max(r, b);\r\n\r\n const y = Math.ceil(max / min);\r\n\r\n if (d === 0) {\r\n if (r === b) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n } else if (Math.abs(y - 1) > d) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(inp){\r\n let parsedInput = inp.split(' ')\r\n .map( el => Number( el.replace(/[^0-9]/g, '') ) );\r\n\r\n if( parsedInput.length === 1 ) return null\r\n\r\n let [redAmount, blueAmount, maxDif] = [...parsedInput];\r\n if(maxDif===0) return redAmount===blueAmount ? 'yes' : 'no';\r\n let [min, max] = [Math.min(redAmount, blueAmount), Math.max(redAmount, blueAmount)];\r\n if( Math.floor(max/min) <= maxDif ){ return 'yes'}\r\n else return 'no'\r\n}\r\n\r\nrl.on('line', (input) => {\r\n let i = candyShop(input);\r\n if(i != null ){ console.log(i) }\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(inp){\r\n let parsedInput = inp.split(' ')\r\n .map( el => Number( el.replace(/[^0-9]/g, '') ) );\r\n\r\n if( parsedInput.length === 1 ) return 'no'\r\n\r\n let [redAmount, blueAmount, maxDif] = [...parsedInput];\r\n if(maxDif===0) return redAmount===blueAmount ? 'yes' : 'no';\r\n let [min, max] = [Math.min(redAmount, blueAmount), Math.max(redAmount, blueAmount)];\r\n if( Math.floor(max/min) <= maxDif ){ return 'yes'}\r\n else return 'no'\r\n}\r\n\r\nrl.on('line', (input) => {\r\n console.log( candyShop(input) )\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nfunction candyShop(redAmount, blueAmount, maxDif){\r\n if(maxDif===0) return redAmount===blueAmount ? console.log('yes') : console.log('no');\r\n if(Math.abs(redAmount-blueAmount)>maxDif) return console.log('no');\r\n if(redAmount<1 || blueAmount<1) return console.log('no');\r\n return console.log('yes')\r\n}\r\n \r\nrl.on('line', (input) => {\r\n if(input.length>1){ candyShop(input) }\r\n});"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n;// CONCATENATED MODULE: ./src/io.js\nvar interact = function interact(main) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var inputString = '';\n var currentLine = 0;\n\n var readline = function readline() {\n return inputString[currentLine++];\n };\n\n var print = function print() {\n for (var _len = arguments.length, any = new Array(_len), _key = 0; _key < _len; _key++) {\n any[_key] = arguments[_key];\n }\n\n process.stdout.write(any.join(' '));\n };\n\n var println = function println() {\n for (var _len2 = arguments.length, any = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n any[_key2] = arguments[_key2];\n }\n\n any.length > 0 && print(any);\n print('\\n');\n };\n\n var obj = {\n print: print,\n println: println,\n readline: readline\n };\n process.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n });\n process.stdin.on('end', function () {\n inputString = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main(obj);\n });\n};\n\n/* harmony default export */ const io = (interact);\n;// CONCATENATED MODULE: ./src/index.js\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\n\n\nvar main = function main(io) {\n var tc = Number.parseInt(io.readline());\n\n while (tc--) {\n var _io$readline$split$ma = io.readline().split(' ').map(function (x) {\n return Number.parseInt(x);\n }),\n _io$readline$split$ma2 = _slicedToArray(_io$readline$split$ma, 3),\n r = _io$readline$split$ma2[0],\n b = _io$readline$split$ma2[1],\n d = _io$readline$split$ma2[2];\n\n if (r > d) {\n var temp = r;\n r = b;\n b = temp;\n } // assert r <= b\n\n\n var sat = b <= r * (1 + d);\n io.println(sat ? 'YES' : 'NO');\n }\n};\n\nio(main);\n/******/ })()\n;"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--)\r\n {\r\n const [r,b,d] = get_ints();\r\n \r\n if(r === b)\r\n {\r\n print('YES');\r\n continue;\r\n }\r\n const min = Math.min(r,b);\r\n const max = Math.max(r,b);\r\n Math.ceil(max/min) > d ? print('NO') : print('YES')\r\n \r\n }\r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (var i = 0; i < t; i++) {\r\n const [r, b, d] = input().split(\" \").map(Number);\r\n\r\n const min = Math.min(r, b);\r\n const max = Math.max(r, b);\r\n\r\n const x = Math.floor(max / min);\r\n const y = Math.ceil(max / min);\r\n\r\n if (d === 0) {\r\n if (r === b) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n } else if (d === 1) {\r\n if (Math.abs(max - min) > d) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n } else if (min === 1) {\r\n if (max > d) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n } else {\r\n if (Math.abs(x - y) > d) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n }\r\n}\r\n"}], "src_uid": "c0ad2a6d14b0c9e09af2221d88a34d52"} {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var t = rdN();\n while (t --> 0) {\n var input = rdArN();\n var b = input[0];\n var p = input[1];\n var f = input[2];\n var input = rdArN();\n var h = input[0];\n var c = input[1];\n \n if (h < c) {\n var buf = p;\n p = f;\n f = buf;\n var buf = h;\n h = c;\n c = buf;\n }\n var stack = crAr(p, h).concat(crAr(f, c)).reverse();\n var res = 0;\n while (b >= 2 && stack.length) {\n res += stack.pop();\n b -= 2;\n }\n pr(res);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();", "positive_code": [{"source_code": "var queries = readline();\nfor(var i = 0; i < queries; i++){\n var quantities = readline().split(' ');\n var b = parseInt(quantities[0]);\n var p = parseInt(quantities[1]);\n var f = parseInt(quantities[2]);\n\n var prices = readline().split(' ');\n var h = parseInt(prices[0]);\n var c = parseInt(prices[1]);\n\n var possibleBurgers = ~~(b / 2);\n //print(\"Burgers possible: \" + possibleBurgers);\n\n if(h <= c){\n //print(\"Value of h and c: \" + h + c);\n if(f >= possibleBurgers){\n print(possibleBurgers * c);\n }\n else{\n var h_bur_profit;\n var c_bur_profit = f * c;\n var remaining_possible_burgers = possibleBurgers - f;\n if(p <= remaining_possible_burgers){\n h_bur_profit = p * h;\n }\n else{\n h_bur_profit = remaining_possible_burgers * h;\n }\n print(h_bur_profit + c_bur_profit);\n }\n }\n else if(h > c){\n //print(\"Value of p and possible burgers: \" + p + possibleBurgers);\n if(p >= possibleBurgers){\n print(possibleBurgers * h);\n }\n else{\n var h_bur_profit = p * h;\n var c_bur_profit;\n var remaining_possible_burgers = possibleBurgers - p;\n if(f <= remaining_possible_burgers){\n c_bur_profit = f * c;\n }\n else{\n c_bur_profit = remaining_possible_burgers * c;\n }\n print(h_bur_profit + c_bur_profit);\n }\n }\n else{\n print(\"0\");\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet b, p, f;\nlet h, c;\n\nconst solve = () => {\n let ans = 0;\n const arr1 = new Array(p).fill(h);\n const arr2 = new Array(f).fill(c);\n\n for (let i = 1; i < b; i += 2) {\n if (h >= c) {\n ans += arr1.length ? arr1.pop() : arr2.pop() || 0;\n }\n else {\n ans += arr2.length ? arr2.pop() : arr1.pop() || 0;\n }\n }\n\n console.log(ans);\n}\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n if (count % 2 === 1) {\n [b, p, f] = d.split(' ').map(Number);\n }\n else {\n [h, c] = d.split(' ').map(Number);\n\n solve();\n }\n\n count++;\n});\n"}, {"source_code": "'use strict';\n\nlet inputStr = '';\nlet lines = [];\n\n\nprocess.stdin.on('data', line => {\n inputStr += line;\n});\n\nprocess.stdin.on('end', () => {\n lines = inputStr.split('\\n');\n lines.pop();\n main();\n});\n\nfunction main() {\n let b,p,f,h,c;\n for (let i = 1; i < lines.length; i += 2) {\n let curr = lines[i].split(' ');\n let total = 0;\n b = Math.floor(parseInt(curr[0], 10) / 2);\n p = parseInt(curr[1], 10);\n f = parseInt(curr[2], 10);\n curr = lines[i+1].split(' ');\n h = parseInt(curr[0], 10);\n c = parseInt(curr[1], 10);\n\n if (h > c) {\n while (b > 0 && p-- > 0) {\n total += h;\n b--;\n }\n while (b > 0 && f-- > 0) {\n total += c;\n b--;\n }\n } else {\n while (b > 0 && f-- > 0) {\n total += c;\n b--;\n }\n while (b > 0 && p-- > 0) {\n total += h;\n b--;\n }\n }\n\n console.log(total);\n }\n}\n"}], "negative_code": [{"source_code": "var queries = readline();\nfor(var i = 0; i < queries; i++){\n var quantities = readline().split(' ');\n var b = quantities[0];\n var p = quantities[1];\n var f = quantities[2];\n\n var prices = readline().split(' ');\n var h = prices[0];\n var c = prices[1];\n\n var possibleBurgers = ~~(b / 2);\n //print(\"Burgers possible: \" + possibleBurgers);\n\n if(possibleBurgers != 0 && h < c){\n if(f >= possibleBurgers){\n print(possibleBurgers * c);\n }\n else{\n var h_bur_profit;\n var c_bur_profit = f * c;\n var remaining_possible_burgers = possibleBurgers - f;\n if(p <= remaining_possible_burgers){\n h_bur_profit = p * h;\n }\n else{\n h_bur_profit = remaining_possible_burgers * h;\n }\n print(h_bur_profit + c_bur_profit);\n }\n }\n else if(possibleBurgers != 0 && h > c){\n if(p >= possibleBurgers){\n print(possibleBurgers * h);\n }\n else{\n var h_bur_profit = p * h;\n var c_bur_profit;\n var remaining_possible_burgers = possibleBurgers - p;\n if(f <= remaining_possible_burgers){\n c_bur_profit = f * c;\n }\n else{\n c_bur_profit = remaining_possible_burgers * c;\n }\n print(h_bur_profit + c_bur_profit);\n }\n }\n else{\n print(\"0\");\n }\n}"}], "src_uid": "92bf30e66f4d5ddebb697d2fa4fa0689"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst a = rn();\r\n\r\n\t\t\tif (a == 1) {\r\n\t\t\t\tans.push(1);\r\n\t\t\t} else {\r\n\t\t\t\twhile (ans[ans.length-1] != a-1) ans.pop();\r\n\t\t\t\tans[ans.length-1] += 1;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(ans.join('.'));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var ans = [[1]];\r\n read();\r\n for (var i = 1; i < n; i++) {\r\n var a = Number(read());\r\n ans[i] = ans[i - 1].slice();\r\n if (a === 1) {\r\n ans[i].push(1);\r\n continue; \r\n }\r\n var b = ans[i].pop();\r\n while(b + 1 !== a) {\r\n b = ans[i].pop();\r\n }\r\n ans[i].push(a);\r\n }\r\n write(ans.map((str) => str.join('.')).join('\\n'));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction addToStore(store, address, value) {\r\n if (!store[address]) {\r\n store[address] = [];\r\n }\r\n store[address].push(value);\r\n}\r\n\r\nfunction getFromStore(store, address) {\r\n return store[address].pop();\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var ans = [[1]];\r\n var store = [];\r\n addToStore(store, 2, 0);\r\n read();\r\n for (var i = 1; i < n; i++) {\r\n var a = Number(read());\r\n if (a === 1) {\r\n ans[i] = ans[i - 1].slice();\r\n ans[i].push(1);\r\n addToStore(store, 2, i);\r\n continue; \r\n }\r\n var j = getFromStore(store, a);\r\n ans[i] = ans[j].slice();\r\n ans[i][ans[i].length - 1] = a;\r\n addToStore(store, a + 1, i);\r\n }\r\n write(ans.map((str) => str.join('.')).join('\\n'));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var ans = '0'.repeat(n).split('');\r\n ans[0] = [1];\r\n read();\r\n for (var i = 1; i < n; i++) {\r\n var a = Number(read());\r\n if (a === 1) {\r\n ans[i] = ans[i - 1].slice();\r\n ans[i].push(1);\r\n continue; \r\n }\r\n var j = i - 1;\r\n while (ans[j][ans[j].length - 1] + 1 !== a) {\r\n j--;\r\n }\r\n ans[i] = ans[j].slice();\r\n ans[i][ans[i].length - 1] ++;\r\n }\r\n write(ans.map((str) => str.join('.')).join('\\n'));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "c1bf6c8a9a20f377cf2a5dbea2267c88"} {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n for (let i = mid - 1; i >= 0; i--) {\n if (str[i] === '0') zero++\n }\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n return zero === 1 ? 'BOB' : 'ALICE'\n }\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n return 'BOB'\n}\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n console.log(\"BOB\");\r\n continue;\r\n }\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) if (str[i] === \"0\") cnt++;\r\n if(cnt===1) console.log(\"BOB\");\r\n else if (cnt % 2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\r\nconst palindromeDist = (line) => {\r\n\tlet count = 0;\r\n\tfor (let i=0; i<(line.length/2); i++) {\r\n\t\tif (line[i] !== line[line.length-1-i]) {\r\n\t\t\tcount++;\r\n\t\t}\r\n\t}\r\n\r\n\treturn count;\r\n}\r\n\r\nconst solve = (line) => {\r\n\tconst emptyCells = line.split('')\r\n\t\t.reduce((acc, item) => (acc += (item === '0' ? 1 : 0)), 0);\r\n\r\n\tif (emptyCells === 1) {\r\n\t\treturn 'BOB';\r\n\t}\r\n\r\n\tconst canDoPalindrome = line.length%2 === 1 && line[Math.floor(line.length/2)] === '0';\r\n\r\n\treturn canDoPalindrome ? 'ALICE' : 'BOB';\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [n, ...lines] = input.trim().split('\\n')\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=0; i b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/20/21 afternoon\r\n\r\nconst solve = (n, s) => {\r\n let cnt = 0;\r\n for (const c of s) cnt += (c == '0');\r\n // pr(cnt);\r\n if (n & 1 && s[n >>> 1] == '0' && cnt > 1) {\r\n pr(\"ALICE\")\r\n } else {\r\n pr(\"BOB\");\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n console.log(\"BOB\");\r\n continue;\r\n }\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) if (str[i] === \"0\") cnt++;\r\n if (cnt % 2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) console.log(\"BOB\");\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) if (str[i] === \"0\") cnt++;\r\n if (cnt % 2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt === 0) {\r\n console.log(\"DRAW\");\r\n } else if (cnt1 === 0) {\r\n if (cnt % 2) {\r\n console.log(\"ALICE\");\r\n } else console.log(\"BOB\");\r\n } else {\r\n let p2 = cnt1;\r\n cnt -= cnt1;\r\n if (cnt === 0) console.log(\"DRAW\");\r\n else {\r\n if (cnt % 2 === 0) {\r\n p1 += Math.floor(n / 2);\r\n p2 += Math.floor(n / 2);\r\n } else {\r\n if (cnt === 1) p1 = 1;\r\n else if (cnt === 3) {\r\n p1 = 1;\r\n p2 += 2;\r\n } else {\r\n p2 += Math.floor(n / 2);\r\n p1 += cnt - Math.floor(n / 2);\r\n }\r\n }\r\n if (p1 === p2) console.log(\"DRAW\");\r\n if (p1 < p2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt === 0) {\r\n console.log(\"DRAW\");\r\n } else if (cnt1 === 0) {\r\n if (cnt % 2) {\r\n if (cnt === 3) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n } else console.log(\"BOB\");\r\n } else {\r\n let p2 = cnt1;\r\n cnt -= cnt1;\r\n if (cnt === 0) console.log(\"DRAW\");\r\n else {\r\n if (cnt % 2 === 0) {\r\n p1 += Math.floor(n / 2);\r\n p2 += Math.floor(n / 2);\r\n } else {\r\n if (cnt === 1) p1 = 1;\r\n else if (cnt === 3) {\r\n p1 = 1;\r\n p2 += 2;\r\n } else {\r\n p2 += Math.floor(n / 2);\r\n p1 += cnt - Math.floor(n / 2);\r\n }\r\n }\r\n if (p1 === p2) console.log(\"DRAW\");\r\n if (p1 < p2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt === 0) {\r\n console.log(\"DRAW\");\r\n } else if (cnt1 === 0) {\r\n if (cnt % 2) {\r\n cnt = Math.floor(cnt / 2) > cnt - Math.floor(cnt / 2) ? 0 : 1;\r\n if (cnt) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n } else console.log(\"BOB\");\r\n } else {\r\n let p2 = cnt1;\r\n cnt -= cnt1;\r\n if (cnt === 0) console.log(\"DRAW\");\r\n else {\r\n if (cnt % 2 === 0) {\r\n p1 += Math.floor(n / 2);\r\n p2 += Math.floor(n / 2);\r\n } else {\r\n if (cnt === 1) p1 = 1;\r\n else if (cnt === 3) {\r\n p1 = 1;\r\n p2 += 2;\r\n } else {\r\n p2 += Math.floor(n / 2);\r\n p1 += cnt - Math.floor(n / 2);\r\n }\r\n }\r\n if (p1 === p2) console.log(\"DRAW\");\r\n if (p1 < p2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt === 0) {\r\n console.log(\"DRAW\");\r\n } else if (cnt1 === 0) {\r\n if (cnt % 2) {\r\n cnt = Math.floor(cnt / 2) > cnt - Math.floor(cnt / 2) ? 0 : 1;\r\n if (cnt) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n } else console.log(\"BOB\");\r\n } else {\r\n let p2 = cnt1,\r\n p1 = 0;\r\n let r = cnt - cnt1;\r\n if (r === 2) p1 += r;\r\n else {\r\n p2 += Math.floor(r / 2);\r\n p1 += r - Math.floor(r / 2);\r\n }\r\n if (p1 === p2) console.log(\"DRAW\");\r\n else if (p1 < p2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt === 0) {\r\n console.log(\"DRAW\");\r\n } else if (cnt1 === 0) {\r\n if (cnt % 2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n } else {\r\n let p2 = cnt1,\r\n p1 = 0;\r\n let r = cnt - cnt1;\r\n if (r === 2) p1 += r;\r\n else {\r\n p2 += Math.floor(r / 2);\r\n p1 += r - Math.floor(r / 2);\r\n }\r\n if (p1 === p2) console.log(\"DRAW\");\r\n else if (p1 < p2) console.log(\"ALICE\");\r\n else console.log(\"BOB\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim();\r\n if (n === 1) {\r\n if (str[0] === \"0\") console.log(\"BOB\");\r\n else console.log(\"DRAW\");\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - 1 - i]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n let ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans) console.log(\"DRAW\");\r\n else console.log(\"BOB\");\r\n } else {\r\n let cnt = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") cnt++;\r\n }\r\n let i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) cnt1++;\r\n i++;\r\n j--;\r\n }\r\n if (cnt % cnt1 === 0) console.log(\"DRAW\");\r\n else console.log(\"ALICE\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n for (let i = mid - 1; i >= 0; i--) {\n if (str[i] === '0') zero++\n }\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n return str.length === 1 ? 'BOB' : 'ALICE'\n }\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n return 'BOB'\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n for (let i = mid - 1; i >= 0; i--) {\n if (str[i] === '0') zero++\n }\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n return 'ALICE'\n }\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n return 'BOB'\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2) \n let zero = 0\n for (let i = mid - 1; i >= 0; i--) {\n if (str[i] === '0') zero++\n }\n return (zero & 1) ? 'BOB' : 'DRAW'\n}\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 morning\r\n * https://codeforces.com/contest/1527/problem/B1\r\n */\r\n\r\nconst solve = (n, s) => {\r\n let se = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == '0') se.add(i);\r\n }\r\n let a = s.split(\"\");\r\n let Alice = Bob = 0;\r\n // replace '0' to '1' make s still palidrome in first priority\r\n let isP = true;\r\n let round = 1;\r\n let pre;\r\n // pr(a, se);\r\n // for (let i = 0; i <= 10; i++) {\r\n while (se.size) {\r\n if (isP == false && pre != 'rv') {\r\n // pr(\"reverse\")\r\n a.reverse();\r\n pre = 'rv';\r\n } else {\r\n let did = false;\r\n for (const i of se) {\r\n if (i == n - 1 - i || a[n - 1 - i] == '1') {\r\n a[i] = '1';\r\n did = true; // still keep palidrome\r\n // pr(\"111\")\r\n se.delete(i);\r\n break;\r\n }\r\n }\r\n // pr(did)\r\n if (!did) {\r\n let first = se.values().next().value;\r\n // pr(\"2222\", first, se)\r\n a[first] = '1';\r\n se.delete(first);\r\n isP = false;\r\n }\r\n round & 1 ? Alice++ : Bob++;\r\n pre = 'rp';\r\n }\r\n round++;\r\n // pr(\"next\", a, se, isP, pre, Alice, Bob);\r\n }\r\n // pr(Alice, Bob);\r\n if (Alice > Bob) {\r\n pr(\"BOB\");\r\n } else if (Alice < Bob) {\r\n pr(\"Alice\");\r\n } else {\r\n pr(\"DRAW\")\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 morning\r\n * https://codeforces.com/contest/1527/problem/B1\r\n */\r\n\r\nconst solve = (n, s) => {\r\n let se = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == '0') se.add(i);\r\n }\r\n let a = s.split(\"\");\r\n let Alice = Bob = 0;\r\n // replace '0' to '1' make s still palidrome in first priority\r\n let isP = true;\r\n let round = 1;\r\n let pre;\r\n // pr(a, se);\r\n // for (let i = 0; i <= 10; i++) {\r\n while (se.size) {\r\n if (isP == false && pre != 'rv') {\r\n // pr(\"reverse\")\r\n a.reverse();\r\n pre = 'rv';\r\n } else {\r\n let did = false;\r\n for (const i of se) {\r\n if (a[n - 1 - i] == '1') {\r\n a[i] = '1';\r\n did = true; // still keep palidrome\r\n // pr(\"111\")\r\n se.delete(i);\r\n break;\r\n }\r\n }\r\n // pr(did)\r\n if (!did) {\r\n let first = se.values().next().value;\r\n // pr(\"2222\", first, se)\r\n a[first] = '1';\r\n se.delete(first);\r\n isP = false;\r\n }\r\n round & 1 ? Alice++ : Bob++;\r\n pre = 'rp';\r\n }\r\n round++;\r\n // pr(\"next\", a, se, isP, pre, Alice, Bob);\r\n }\r\n // pr(Alice, Bob);\r\n if (Alice > Bob) {\r\n pr(\"BOB\");\r\n } else if (Alice < Bob) {\r\n pr(\"Alice\");\r\n } else {\r\n pr(\"DRAW\")\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var e=readline();\r\nfor(var iq=0;iq parseInt(x));\n\nvar max = Math.max(...inp);\nvar l_when_max = 0;\n\nvar indexes = [], i = -1;\nwhile ((i = inp.indexOf(max, i+1)) != -1){\n indexes.push(i);\n}\n\nfor(var j = 0 in indexes)\n{\n var k = parseInt(j);\n var l = 1;\n while(k < indexes.length - 1 && indexes[k + 1] - indexes[k] === 1)\n {\n l++;\n k++;\n }\n \n if (l > l_when_max)\n {\n l_when_max = l;\n }\n if(l_when_max > indexes.length / 2)\n {\n break;\n }\n}\n\nprint(l_when_max);", "positive_code": [{"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber(' ');\n\n \n var max = a[0];\n for(var i = 1; i < n; i++) {\n if(max < a[i]) max = a[i];\n }\n \n \n var count = [1];\n var countIndex = 0;\n for(var i = 1; i < n; i++) {\n if(a[i] === max) {\n if(a[i] === a[i - 1]) {\n count[countIndex] += 1;\n }\n else {\n countIndex++;\n count[countIndex] = 1;\n }\n } \n }\n \n max = count[0];\n for(var i = 1; i < n; i++) {\n if(max < count[i]) max = count[i];\n }\n print(max);\n \n}());\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [maxLen, count, max] = [0, 0, Math.max(...arr)];\n\n for (let i = 0; i < len; i++) {\n if (arr[i] === max) {\n count++;\n } else {\n count = 0;\n }\n\n maxLen = Math.max(maxLen, count);\n }\n\n console.log(maxLen);\n}\n"}, {"source_code": "write((readline().split(\" \").map(function(x) { return parseInt(x); })[0]*0 + readline().split(\" \").reduce(function(acc, item) { var val = parseInt(item); if (val > acc.mx) { acc.mx = val; acc.mx_cnt = 1; acc.ans = 1;} else if (val === acc.mx)\tacc.mx_cnt++; else acc.mx_cnt = 0; acc.ans = Math.max(acc.ans, acc.mx_cnt); return acc;}, {mx: -1, mx_cnt: 0, ans: 1}).ans) + \"\\n\");"}, {"source_code": "function calc(arr) {\n // find max\n var max = 0;\n for (var i = 0; i< arr.length; i++) {\n max = max > arr[i] ? max : arr[i];\n }\n \n // find max count\n var count = 0;\n var countMax = 1;\n for (var i = 0; i< arr.length; i++) {\n if (arr[i] === max) {\n count++;\n } else {\n count = 0;\n }\n \n countMax = countMax > count ? countMax : count;\n }\n \n return countMax;\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \").map(el => parseInt(el));\n\nprint(calc(arr));"}, {"source_code": "var n = parseInt(readline(), 10),\n a = readline().split(' ').map(el => parseInt(el, 10)),\n max_mean = 0, \n max_len = 0,\n local_len = 0,\n local_mean = 0,\n local_sum = 0;\n\nfor(var i=0; i max_mean) {\n local_len = 1;\n local_sum = a[i];\n local_mean = local_sum / local_len;\n } else {\n local_len++;\n local_sum += a[i];\n local_mean = local_sum / local_len;\n }\n \n if(local_mean > max_mean) {\n max_mean = local_mean;\n max_len = local_len;\n \n } else if(local_mean === max_mean) {\n if(local_len > max_len) max_len = local_len;\n } else {\n local_len = 1;\n local_sum = a[i];\n local_mean = local_sum / local_len;\n \n if(local_mean > max_mean) {\n max_mean = local_mean;\n max_len = local_len;\n \n } else if(local_mean === max_mean) {\n if(local_len > max_len) max_len = local_len;\n }\n }\n}\n\nprint(max_len);"}], "negative_code": [{"source_code": "readline();\nvar inp = readline().split(' ').map(x => parseInt(x));\n\nvar max = Math.max(...inp);\nvar l_when_max = 0;\n\nvar indexes = [], i = -1;\nwhile ((i = inp.indexOf(max, i+1)) != -1){\n indexes.push(i);\n}\n\nprint(indexes);\n\nfor(var j = 0 in indexes)\n{\n var k = parseInt(j);\n var l = 1;\n while(k < indexes.length - 1 && indexes[k + 1] - indexes[k] === 1)\n {\n l++;\n k++;\n }\n \n if (l > l_when_max)\n {\n l_when_max = l;\n }\n}\n\nprint(l_when_max);"}, {"source_code": "write((readline().split(\" \").map(function(x) { return parseInt(x); })[0]*0 + readline().split(\" \").reduce(function(acc, item) { var val = parseInt(item); if (val > acc.mx) { acc.mx = val; acc.mx_cnt = 1; } else if (val === acc.mx)\tacc.mx_cnt++; else acc.mx_cnt = 0; acc.ans = Math.max(acc.ans, acc.mx_cnt); return acc;}, {mx: -1, mx_cnt: 0, ans: 1}).ans) + \"\\n\");"}], "src_uid": "5db2ae5b2c91b29e4fe4a45ab864e3f1"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar nzero = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] != 0){\r\n\t\t\t\tnzero++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(nzero < N){\r\n\t\t\tmyout(nzero);\r\n\t\t}else{\r\n\t\t\tvar map = getCountMap(list);\r\n\t\t\tvar key = Object.keys(map);\r\n\t\t\tif(key.length != N){\r\n\t\t\t\tmyout(nzero);\r\n\t\t\t}else{\r\n\t\t\t\tmyout(nzero + 1);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let zero = arr.findIndex(x => x === 0) > -1;\r\n let nonZero = arr.filter(x => x !== 0).length;\r\n\r\n let hash = {};\r\n\r\n let duplicate = false;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] !== 0) {\r\n if (hash[arr[i]]) {\r\n duplicate = true;\r\n } else {\r\n hash[arr[i]] = 1;\r\n }\r\n }\r\n }\r\n\r\n output((zero || duplicate) ? nonZero : nonZero + 1);\r\n }\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nconst hasUniqueElements = (arr) => {\n const cache = {};\n for (let index = 0; index < arr.length; index++) {\n const element = arr[index];\n if (!cache[element]) {\n cache[element] = true;\n } else {\n return false;\n }\n }\n return true;\n};\n\nconst countAllZeros = (arr) => {\n zeros = 0;\n for (let index = 0; index < arr.length; index++) {\n const element = arr[index];\n if (element === 0) zeros++;\n }\n return zeros;\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0 && lines % 2 === 0) {\n let input = line.split(\" \").map(Number);\n const zeros = countAllZeros(input);\n if (zeros > 0) {\n console.log(input.length - zeros);\n } else if (hasUniqueElements(input)) {\n console.log(input.length + 1);\n } else {\n console.log(input.length);\n }\n }\n lines++;\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \").map(i => parseInt(i)).sort((a, b) => a - b);\r\n let dup = false;\r\n let noofzeros = 0;\r\n let cnt = 0;\r\n if (arr[0] === 0) noofzeros = 1;\r\n for (let i = 1; i < arr.length; i++) {\r\n if ((arr[i] === arr[i - 1]) && !dup) dup = true;\r\n if (arr[i] === 0) noofzeros++;\r\n }\r\n cnt = arr.length - noofzeros;\r\n if (noofzeros == 0 && !dup) return cnt + 1;\r\n if (noofzeros == 0 && dup) return cnt;\r\n else return cnt;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n let zero = 0\n let hasDup = 0\n arr.forEach(x => {\n if (!x) zero++\n if (map[x]) hasDup = 1\n map[x] = 1\n })\n if (zero) {\n return n - zero\n } else if (hasDup) {\n return n\n } else {\n return 1 + n\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let zero = 0,\r\n repeat = 0,\r\n set = new Set();\r\n for (let num of a) {\r\n if (num === 0) {\r\n zero++;\r\n } else if (set.has(num)) {\r\n repeat = 1;\r\n }\r\n set.add(num);\r\n }\r\n if (zero > 0) {\r\n return n - zero;\r\n } else if (repeat > 0) {\r\n return n;\r\n } else {\r\n return n + 1;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, a)=>{\n let zero = 0;\n let equal = false;\n\n a.sort((x, y) => x - y);\n\n let i = 0;\n while (i < n && a[i] === 0) {\n zero++;\n i++;\n }\n\n for (; i < n; i++) {\n if (i > 0 && a[i] === a[i - 1]) {\n equal = true;\n break;\n }\n }\n\n if (zero > 0) {\n return n - zero;\n } else {\n return equal ? n : n + 1;\n }\n};\n\nfunction main() {\n let T = +readline();\n // let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n // let s = readline();\n let a = ra();\n // out.push(calc(n, s, a));\n process.stdout.write(`${calc(n, a)}\\n`);\n }\n // process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n\n // PROCESSING:\n let ans = 0;\n let left = 0;\n let cnt = {};\n let max = 0;\n for (let i=0; i0)\n left++;\n cnt[a] = (cnt[a]||0)+1;\n max = Math.max(max, cnt[a])\n }\n if (left1){\n return n;\n }\n return n+1;\n};\n "}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var i = _a[_i];\r\n var n = +readline();\r\n var a = readline().split(' ').map(function (v) { return +v; }).sort();\r\n if (a[0] === 0) {\r\n for (var j = 1; j < n; j++) {\r\n if (a[j] !== 0) {\r\n print(n - j);\r\n continue root;\r\n }\r\n }\r\n print(0);\r\n continue;\r\n }\r\n for (var i_1 = 1; i_1 < n; i_1++) {\r\n if (a[i_1] === a[i_1 - 1]) {\r\n print(n);\r\n continue root;\r\n }\r\n }\r\n print(n + 1);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let tc = parseInt(readline());\r\n while(tc--){\r\n const n = parseInt(readline());\r\n const a = readline().split(' ').map(Number);\r\n let zero = 0;\r\n for(let i = 0; i < n; i++){\r\n if(!a[i]) zero++;\r\n }\r\n if(zero){\r\n console.log(n-zero);\r\n }\r\n else{\r\n let same = false;\r\n for(let i = 0; i < n; i++){\r\n for(let j = i+1; j < n; j++){\r\n if(a[i] === a[j]) same = true;\r\n }\r\n }\r\n if(same){\r\n console.log(n);\r\n }\r\n else{\r\n console.log(n+1);\r\n }\r\n }\r\n }\r\n};"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet inputData = [];\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString = String(inputStdin);\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputData = inputString.trim().split('\\n').map(s => s.trim());\r\n main();\r\n});\r\n\r\nconst input = (() => {\r\n let line = 0;\r\n return () => inputData[line++];\r\n})();\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const n = parseInt(input());\r\n const a = input().split(' ').map(Number);\r\n let zero = 0;\r\n for(let i = 0; i < n; i++){\r\n if(!a[i]) zero++;\r\n }\r\n if(zero){\r\n console.log(n-zero);\r\n }\r\n else{\r\n let same = false;\r\n for(let i = 0; i < n; i++){\r\n for(let j = i+1; j < n; j++){\r\n if(a[i] === a[j]) same = true;\r\n }\r\n }\r\n if(same){\r\n console.log(n);\r\n }\r\n else{\r\n console.log(n+1);\r\n }\r\n }\r\n }\r\n};"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet inputData = [];\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString = String(inputStdin);\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputData = inputString.trim().split('\\n').map(s => s.trim());\r\n main();\r\n});\r\n\r\nconst input = (() => {\r\n let line = 0;\r\n return () => inputData[line++];\r\n})();\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const n = parseInt(input());\r\n const a = input().split(' ').map(Number);\r\n let zero = 0;\r\n for(let i = 0; i < n; i++){\r\n if(!a[i]) zero++;\r\n }\r\n if(zero){\r\n console.log(n-zero);\r\n }\r\n else{\r\n let same = false;\r\n for(let i = 0; i < n; i++){\r\n for(let j = 0; j < n; j++){\r\n if(i === j) continue;\r\n if(a[i] === a[j]) same = true;\r\n }\r\n }\r\n if(same){\r\n console.log(n);\r\n }\r\n else{\r\n console.log(n+1);\r\n }\r\n }\r\n }\r\n};"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet inputData = [];\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString = String(inputStdin);\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputData = inputString.trim().split('\\n').map(s => s.trim());\r\n main();\r\n});\r\n\r\nconst input = (() => {\r\n let line = 0;\r\n return () => inputData[line++];\r\n})();\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n let n = parseInt(input());\r\n const a = input().split(' ').map(Number);\r\n let zero = 0;\r\n for(let i = 0; i < n; i++){\r\n if(!a[i]) zero++;\r\n }\r\n if(zero){\r\n console.log(n-zero);\r\n }\r\n else{\r\n let same = false;\r\n for(let i = 0; i < n-1; i++){\r\n if(a[i] === a[i+1]) same = true;\r\n }\r\n if(same){\r\n console.log(n);\r\n }\r\n else{\r\n console.log(n+1);\r\n }\r\n }\r\n }\r\n};"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let arr = readline().split(' ').map(Number).filter(a => a !== 0);\r\n\r\n const freq = {};\r\n let equalPairs = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (freq[arr[i]]) {\r\n freq[arr[i]]++;\r\n if (freq[arr[i]] % 2 === 0) {\r\n freq[arr[i]] = 0;\r\n equalPairs++;\r\n }\r\n } else {\r\n freq[arr[i]] = 1;\r\n }\r\n }\r\n\r\n const remainingPairs = Math.ceil((arr.length - equalPairs * 2) / 2);\r\n\r\n output(equalPairs + remainingPairs * 2);\r\n }\r\n}"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nconst hasUniqueElements = (arr) => {\n const cache = {};\n for (let index = 0; index < arr.length; index++) {\n const element = arr[index];\n if (!cache[element]) {\n cache[element] = true;\n } else {\n return false;\n }\n }\n return true;\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0 && lines % 2 === 0) {\n let input = line.split(\" \").map(Number);\n if (input.indexOf(0) !== -1) {\n console.log(input.length - 1);\n } else if (hasUniqueElements(input)) {\n console.log(input.length + 1);\n } else {\n console.log(input.length);\n }\n }\n lines++;\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n let hasZero = false;\r\n let dup = false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if ((arr[i] === arr[i - 1]) && !dup) dup = true;\r\n if ((arr[i] == 0 || arr[i - 1] == 0) && !hasZero) hasZero = true;\r\n }\r\n if (hasZero) return arr.length - 1;\r\n else if (dup) return arr.length;\r\n else return arr.length + 1;\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var i = _a[_i];\r\n var n = +readline();\r\n var a = readline().split(' ').map(function (v) { return +v; }).sort();\r\n if (a[0] === 0) {\r\n print(n - 1);\r\n continue;\r\n }\r\n for (var i_1 = 1; i_1 < n; i_1++) {\r\n if (a[i_1] === a[i_1 - 1]) {\r\n print(n);\r\n continue root;\r\n }\r\n }\r\n print(n + 1);\r\n}\r\n"}], "src_uid": "ad242f98f1c8eb8d30789ec672fc95a0"} {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\nfunction main()\n{\n const k=parseInt(readLine());\n let mp=new Map();\n for(let t=0;t{return +(x.trim());});\n let sum=arr.reduce((a,b)=>a+b);\n for(let i=0;i{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\n\nfunction main()\n{\n const K=parseInt(readLine());\n\n var seqSums = [];\n var seqs = []\n\n var map = new Map(); // key: sum - num, value: [\"seqNo,removeItem\", \"seqNo,removeItem\"]\n\n for (var i = 0; i < K; i++) {\n var len = parseInt(readLine());\n var seq=readLine().trim().split(' ').map(x=>{return +(x.trim());});\n var seqSum = 0;\n\n for (var j = 0; j < len; j++) {\n seqSum += seq[j];\n }\n\n for (var j = 0; j < len; j++) {\n if (map.get(seqSum - seq[j]) != undefined) {\n var tmp = map.get(seqSum - seq[j]);\n\n console.log(\"YES\");\n tmp.forEach(function(item) {\n console.log(item.split(',')[0] + \" \" + item.split(',')[1]);\n console.log((i + 1) + \" \" + (j + 1));\n });\n\n map.set(seqSum - seq[j], tmp.push(i + \",\" + seq[j]));\n return;\n }\n }\n\n for (var j = 0; j < len; j++) {\n var tmp = [(i + 1) + \",\" + (j + 1)];\n map.set(seqSum - seq[j], tmp);\n }\n }\n console.log(\"NO\");\n}"}], "negative_code": [{"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\n\nfunction main()\n{\n const K=parseInt(readLine());\n\n var seqSums = [];\n var seqs = []\n\n var map = new Map(); // key: sum - num, value: [\"seqNo,removeItem\", \"seqNo,removeItem\"]\n\n for (var i = 0; i < K; i++) {\n var len = parseInt(readLine());\n var seq=readLine().trim().split(' ').map(x=>{return +(x.trim());});\n var seqSum = 0;\n\n for (var j = 0; j < len; j++) {\n seqSum += seq[j];\n }\n\n for (var j = 0; j < len; j++) {\n if (map.get(seqSum - seq[j]) != undefined) {\n var tmp = map.get(seqSum - seq[j]);\n\n console.log(\"YES\");\n tmp.forEach(function(item) {\n console.log((parseInt(item.split(',')[0]) + 1) + \" \" + item.split(',')[1]);\n console.log((i + 1) + \" \" + seq[j]);\n });\n\n map.set(seqSum - seq[j], tmp.push(i + \",\" + seq[j]));\n return;\n }\n }\n\n for (var j = 0; j < len; j++) {\n var tmp = [i + \",\" + seq[j]];\n map.set(seqSum - seq[j], tmp);\n }\n }\n console.log(\"NO\");\n}"}], "src_uid": "7561bca5fa2200ce9ae7e30e7076c6ab"} {"source_code": "print(function(n, m) {\n\n\tvar a = [];\n\tfor (var i = 0; i < n; i++)\n\t\ta.push(readline().split(' ').map(Number));\n\n\tfor (var i = 0; i < n; i++)\n\t\tfor (var j = 0; j < m; j++)\n\t\t\tif ((i === 0 || i === n - 1 || j === 0 || j === m - 1) && a[i][j] === 1) return 2;\n\n\treturn 4;\n\n} .apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": ";(function () {\n\tprint(function () {\n\t\tvar l = readline().split(' ').map(Number), n = l[0], m = l[1];\n\n\t\tif (readline().split(' ').indexOf('1') !== -1) return 2;\n\t\telse n -= 2;\n\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ');\n\t\t\tif (l.indexOf('1') === 0 || l.lastIndexOf('1') === m - 1) return 2;\n\t\t}\n\n\t\treturn readline().split(' ').indexOf('1') !== -1 ? 2 : 4;\n\t}());\n}).call(this);\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1];\n\tfor (var r = 0; r < rowNum; ++r) {\n\t\tvar row = tokenizeIntegers(readline());\n\t\tfor (var c = 0; c < colNum; ++c) {\n\t\t\tif (row[c] == 1) {\n\t\t\t\tif (r == 0 || r == rowNum-1 || c == 0 || c == colNum-1) {\n\t\t\t\t\tprint(2);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tprint(4);\n}\n\nmain();\n"}], "negative_code": [{"source_code": ";(function () {\n\tprint(function () {\n\t\tvar l = readline().split(' ').map(Number), n = l[0], m = l[1];\n\n\t\tl = readline().split(' ');\n\t\tif (l.indexOf('1') !== -1) return 2;\n\t\telse n -= 2;\n\n\t\twhile (n--) {\n\t\t\tvar i = readline().split(' ').indexOf('1');\n\t\t\tif (i === 0 || i === m - 1) return 2;\n\t\t}\n\n\t\treturn readline().split(' ').indexOf('1') !== -1 ? 2 : 4;\n\t}());\n}).call(this);\n"}], "src_uid": "0d2fd9b58142c4f5282507c916690244"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction reverse(a, i, j) {\r\n while (i < j) {\r\n let t = a[i];\r\n a[i] = a[j];\r\n a[j] = t;\r\n i++;\r\n j--;\r\n }\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet l;\r\nlet r;\r\nlet s;\r\nfunction solve() {\r\n let m = r - l + 1;\r\n let mn = m * (m + 1) / 2;\r\n let hi = n - m;\r\n let mx = hi * m + mn;\r\n // printf(\"n %d m %d mn %d mx %d s %d l %d r %d\\n\", n, m, mn, mx, s, l, r);\r\n if (s < mn || s > mx) {\r\n return false;\r\n }\r\n let used = af(n + 1).fill(0);\r\n let a = [];\r\n m--;\r\n for (let x = n; x >= 1; x--) {\r\n mn = Math.trunc(m * (m + 1) / 2);\r\n if (mn + x > s) {\r\n continue;\r\n }\r\n m--;\r\n s -= x;\r\n used[x] = 1;\r\n a.push(x);\r\n }\r\n // printf(\"a: %j\\n\", a);\r\n for (let x = 1; x <= n; x++) {\r\n if (used[x] == 0) {\r\n a.push(x);\r\n }\r\n }\r\n reverse(a, 0, n - l);\r\n reverse(a, n - l + 1, n - 1);\r\n reverse(a, 0, n - 1);\r\n // printf(\"a: %j\\n\", a);\r\n for (let i = 0; i < n; i++) {\r\n printf(\"%d \", a[i]);\r\n }\r\n printf(\"\\n\");\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n l = nextInt();\r\n r = nextInt();\r\n s = nextInt();\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, l, r, s] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n l--\r\n r--\r\n var length = r - l + 1\r\n var lower = n - length + 1\r\n var ans = new Array(n).fill(false)\r\n var min = (((r - l + 1) + 1) * (r - l + 1)) / 2\r\n var max = (lower - 1) * length + ((length + 1) * (r - l + 1)) / 2\r\n var used = new Array(n + 1).fill(false)\r\n if (s < min || s > max) return console.log(-1)\r\n\r\n var a = []\r\n for (let j = 0; j < length; j++) {\r\n a[j] = j + 1\r\n s=s-a[j]\r\n }\r\n\r\n for (let j = length-1; j >=0; j--) {\r\n while (s>0 && a[j] < n - (length -j-1)){\r\n s--\r\n a[j]++\r\n }\r\n }\r\n for (let j = l; j <=r; j++) {\r\n ans[j] = a[j-l]\r\n used[ans[j]] = true\r\n }\r\n // console.log(ans.join(' '))\r\n\r\n for (let j = 1; j <= n; j++) {\r\n if (!used[j])\r\n for (let i = 0; i < n; i++) {\r\n if (ans[i] === false) {\r\n ans[i] = j\r\n break\r\n }\r\n }\r\n }\r\n console.log(ans.join(' '))\r\n\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r, s] = rna();\r\n\r\n\t\tconst d = r - l + 1;\r\n\t\tconst ar = Array.from(Array(d), (_, i) => i + 1);\r\n\r\n\t\tlet need = s - d*(d+1)/2;\r\n\t\tfor (let i = d - 1; need > 0 && i >= 0; i--) {\r\n\t\t\tconst mvs = Math.min(n - d, need);\r\n\t\t\tar[i] += mvs;\r\n\t\t\tneed -= mvs;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0, next = 1; ar.length < n; next++) {\r\n\t\t\tif (next != ar[i]) {\r\n\t\t\t\tar.push(next);\r\n\t\t\t} else {\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = need == 0 && [...ar.slice(n - l + 1), ...ar].slice(0, n);\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction reverse(a, i, j) {\r\n while (i < j) {\r\n let t = a[i];\r\n a[i] = a[j];\r\n a[j] = t;\r\n i++;\r\n j--;\r\n }\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet l;\r\nlet r;\r\nlet s;\r\nfunction solve() {\r\n let m = r - l + 1;\r\n let mn = m * (m + 1) / 2;\r\n let hi = n - m;\r\n let mx = hi * m + mn;\r\n // printf(\"n %d m %d mn %d mx %d s %d l %d r %d\\n\", n, m, mn, mx, s, l, r);\r\n if (s < mn || s > mx) {\r\n return false;\r\n }\r\n let used = af(n + 1).fill(0);\r\n let a = [];\r\n while (s > 0) {\r\n m--;\r\n mn = m * (m + 1) / 2;\r\n let x = Math.min(n, s - mn);\r\n while (used[x]) {\r\n x--;\r\n }\r\n used[x] = 1;\r\n a.push(x);\r\n s -= x;\r\n }\r\n for (let x = 1; x <= n; x++) {\r\n if (used[x] == 0) {\r\n a.push(x);\r\n }\r\n }\r\n // printf(\"a: %j\\n\", a);\r\n reverse(a, 0, n - l);\r\n reverse(a, n - l + 1, n - 1);\r\n reverse(a, 0, n - 1);\r\n // printf(\"a: %j\\n\", a);\r\n for (let i = 0; i < n; i++) {\r\n printf(\"%d \", a[i]);\r\n }\r\n printf(\"\\n\");\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n l = nextInt();\r\n r = nextInt();\r\n s = nextInt();\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r, s] = rna();\r\n\r\n\t\tconst d = r - l + 1;\r\n\r\n\t\tlet need = s;\r\n\t\tconst ar = [];\r\n\t\tfor (let i = 1; i <= d; i++) {\r\n\t\t\tar.push(i);\r\n\t\t\tneed -= i;\r\n\t\t}\r\n\r\n\t\tfor (let i = d - 1; need > 0 && i >= 0; i--) {\r\n\t\t\tconst chng = Math.min(n - d, need);\r\n\t\t\tar[i] += chng;\r\n\t\t\tneed -= chng;\r\n\t\t}\r\n\r\n\t\tconst ss = new Set(ar);\r\n\t\tconst ans = need == 0 && [];\r\n\t\tfor (let i = 1; ans && i <= n; i++) {\r\n\t\t\tif (ans.length == l - 1) ans.push(...ar);\r\n\t\t\tif (!ss.has(i)) ans.push(i);\r\n\t\t}\r\n\t\tif (ans.length < n) ans.push(...ar);\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r, s] = rna();\r\n\r\n\t\tconst d = r - l + 1;\r\n\r\n\t\tlet need = s;\r\n\t\tconst ar = [];\r\n\t\tfor (let i = 1; i <= d; i++) {\r\n\t\t\tar.push(i);\r\n\t\t\tneed -= i;\r\n\t\t}\r\n\r\n\t\tfor (let i = d - 1; need > 0 && i >= 0; i--) {\r\n\t\t\tconst chng = Math.min(n - d, need);\r\n\t\t\tar[i] += chng;\r\n\t\t\tneed -= chng;\r\n\t\t}\r\n\r\n\t\tconst ss = new Set(ar);\r\n\t\tconst ans = need == 0 && [];\r\n\t\tfor (let i = 1; ans && i <= n; i++) {\r\n\t\t\tif (ans.length == l - 1) {\r\n\t\t\t\tans.push(...ar);\r\n\t\t\t}\r\n\t\t\tif (!ss.has(i)) {\r\n\t\t\t\tans.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r, s] = rna();\r\n\r\n\t\tconst d = r - l + 1;\r\n\r\n\t\tlet need = s;\r\n\t\tconst ar = [];\r\n\t\tfor (let i = 1; i <= d; i++) {\r\n\t\t\tar.push(i);\r\n\t\t\tneed -= i;\r\n\t\t}\r\n\r\n\t\tfor (let i = d - 1; need > 0 && i >= 0; i--) {\r\n\t\t\tconst chng = Math.min(n - d, need);\r\n\t\t\tar[i] += chng;\r\n\t\t\tneed -= chng;\r\n\t\t}\r\n\r\n\t\tconst ss = new Set(ar);\r\n\t\tconst ans = need == 0 && [];\r\n\t\tfor (let i = 1; ans && i <= n; i++) {\r\n\t\t\tif (!ss.has(i)) {\r\n\t\t\t\tans.push(i);\r\n\t\t\t}\r\n\t\t\tif (ans.length == l - 1) {\r\n\t\t\t\tans.push(...ar);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction reverse(a, i, j) {\r\n while (i < j) {\r\n let t = a[i];\r\n a[i] = a[j];\r\n a[j] = t;\r\n i++;\r\n j--;\r\n }\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet l;\r\nlet r;\r\nlet s;\r\nfunction solve() {\r\n let m = r - l + 1;\r\n let mn = m * (m + 1) / 2;\r\n let hi = n - m;\r\n let mx = hi * m + mn;\r\n // printf(\"m %d n %d mn %d mx %d\\n\", m, n, mn, mx);\r\n if (s < mn || s > mx) {\r\n return false;\r\n }\r\n let used = af(n + 1).fill(0);\r\n let a = [];\r\n while (s > 0) {\r\n m--;\r\n mn = m * (m + 1) / 2;\r\n let x = s - mn;\r\n used[x] = 1;\r\n a.push(x);\r\n s -= x;\r\n }\r\n for (let x = 1; x <= n; x++) {\r\n if (used[x] == 0) {\r\n a.push(x);\r\n }\r\n }\r\n // printf(\"a: %j\\n\", a);\r\n reverse(a, 0, n - l);\r\n reverse(a, n - l + 1, n - 1);\r\n reverse(a, 0, n - 1);\r\n // printf(\"a: %j\\n\", a);\r\n for (let i = 0; i < n; i++) {\r\n printf(\"%d \", a[i]);\r\n }\r\n printf(\"\\n\");\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n l = nextInt();\r\n r = nextInt();\r\n s = nextInt();\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction reverse(a, i, j) {\r\n while (i < j) {\r\n let t = a[i];\r\n a[i] = a[j];\r\n a[j] = t;\r\n i++;\r\n j--;\r\n }\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet l;\r\nlet r;\r\nlet s;\r\nfunction solve() {\r\n let m = r - l + 1;\r\n let mn = m * (m + 1) / 2;\r\n let hi = n - m;\r\n let mx = hi * m + mn;\r\n printf(\"m %d n %d mn %d mx %d\\n\", m, n, mn, mx);\r\n if (s < mn || s > mx) {\r\n return false;\r\n }\r\n let used = af(n + 1).fill(0);\r\n let a = [];\r\n while (s > 0) {\r\n m--;\r\n mn = m * (m + 1) / 2;\r\n let x = s - mn;\r\n used[x] = 1;\r\n a.push(x);\r\n s -= x;\r\n }\r\n for (let x = 1; x <= n; x++) {\r\n if (used[x] == 0) {\r\n a.push(x);\r\n }\r\n }\r\n // printf(\"a: %j\\n\", a);\r\n reverse(a, 0, n - l);\r\n reverse(a, n - l + 1, n - 1);\r\n reverse(a, 0, n - 1);\r\n // printf(\"a: %j\\n\", a);\r\n for (let i = 0; i < n; i++) {\r\n printf(\"%d \", a[i]);\r\n }\r\n printf(\"\\n\");\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n l = nextInt();\r\n r = nextInt();\r\n s = nextInt();\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}], "src_uid": "88c8376ad65c5c932c15dc09d6c4d75f"} {"source_code": "const getMinOperations = (nums) => {\n var count = 0;\n\n for (var i = nums.length - 1; i >= 1; i--) {\n count += Math.max(0, nums[i - 1] - nums[i]);\n }\n\n return count;\n};\n\nconst main = () => {\n const T = Number(readline());\n\n for (var _ = 0; _ < T; _++) {\n readline();\n var nums = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n print(getMinOperations(nums));\n }\n};\n\nmain();", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet d = [];\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\td.push(arr[i] - arr[i - 1]);\n\t\t}\n\n\t\tlet s = d.reduce((a, c) => (c < 0 ? a + c : a), 0);\n\t\tconsole.log(Math.abs(s));\n\t}\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const store = [];\n\n for (let i = 0; i < len - 1; i++) {\n if (arr[i] - arr[i + 1] > 0) store.push(arr[i] - arr[i + 1]);\n }\n\n if (store.length) {\n const sum = store.reduce((total, n) => total + n, 0);\n console.log(sum);\n } else {\n console.log(0);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n let result = 0\n for (let i = 1; i < n; i++) {\n result += Math.max(0, as[i - 1] - as[i])\n }\n console.log(result)\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet v = 0,\n\t\t\tc = arr[0];\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tif (arr[i] < c) {\n\t\t\t\tv = Math.max(v, c - arr[i]);\n\t\t\t} else {\n\t\t\t\tc = arr[i];\n\t\t\t}\n\t\t}\n\t\tconsole.log(v);\n\t}\n}\n"}], "src_uid": "0bd06900e42db9f83cdd43c24da6686e"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [rw, rh] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let [x1, y1, x2, y2] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let u = rh - y2,\r\n r = rw - x2,\r\n l = x1,\r\n d = y1;\r\n let [tw, th] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let ans = Infinity;\r\n if (l >= tw) ans = 0;\r\n if (r >= tw - l && tw - l >= 0) ans = Math.min(ans, tw - l);\r\n if (r >= tw) ans = 0;\r\n if (l >= tw - r && tw - r >= 0) ans = Math.min(ans, tw - r);\r\n if (u >= th) ans = 0;\r\n if (d >= th - u && th - u >= 0) ans = Math.min(ans, th - u);\r\n if (d >= th) ans = 0;\r\n if (u >= th - d && th - d >= 0) ans = Math.min(ans, th - d);\r\n if (ans === Infinity) ans = -1;\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var [W, H] = lines[l++].split(' ').map(Number)\n var [x1, y1, x2, y2] = lines[l++].split(' ').map(Number)\n var [w, h] = lines[l++].split(' ').map(Number)\n console.log(solve(W, H, x1, y1, x2, y2, w, h))\n }\n});\n\nfunction solve(W, H, x1, y1, x2, y2, w, h) {\n const l = x1\n const r = W - x2\n const t = H - y2\n const b = y1\n // console.log(l, r, t, b)\n let d1 = -1\n let d2 = -1\n if (l + r >= w) {\n d1 = h > H ? -1 : Math.max(0, w - Math.max(l, r))\n }\n if (t + b >= h) {\n d2 = w > W ? -1 : Math.max(0, h - Math.max(t, b))\n }\n\n if (d1 >= 0 && d2 >= 0) {\n return Math.min(d1, d2)\n } else if (d1 >= 0) {\n return d1\n } else if (d2 >= 0) {\n return d2\n }\n return -1\n}\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t, i, s, r, u, d) {\r\n if (u > e || d > n) return -1\r\n if (u + (s - t) > e && d + (r - i) > n) return -1\r\n if (u <= t || u + s <= e) return 0\r\n if (d <= i || d + r <= n) return 0\r\n let o = Number.MAX_SAFE_INTEGER\r\n return (\r\n u + (s - t) <= e && (o = Math.min(o, u - t, u + s - e)),\r\n d + (r - i) <= n && (o = Math.min(o, d - i, d + r - n)),\r\n o\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n [i, s, r, u] = e.readIntegersOfLine(),\r\n [d, o] = e.readIntegersOfLine(),\r\n a = solve(n, t, i, s, r, u, d, o)\r\n e.print(a + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "const setTable = (rWH, t1P, t2WH ) => {\r\n var rW = rWH[0];\r\n var rH = rWH[1];\r\n \r\n var t1X1 = t1P[0];\r\n var t1Y1 = t1P[1];\r\n var t1X2 = t1P[2];\r\n var t1Y2 = t1P[3];\r\n var t1W = t1X2 - t1X1;\r\n var t1H = t1Y2 - t1Y1;\r\n \r\n var t2W = t2WH[0];\r\n var t2H = t2WH[1];\r\n \r\n if((t1W + t2W > rW) && (t1H + t2H > rH)) {\r\n return -1;\r\n }\r\n \r\n var fSW = Math.max(t1X1, rW - t1X2);\r\n var fSH = Math.max(t1Y1, rH - t1Y2);\r\n \r\n var shift = Math.min(\r\n t1W + t2W > rW ? Infinity : t2W - fSW, \r\n t1H + t2H > rH ? Infinity : t2H - fSH\r\n );\r\n \r\n return shift >= 0 ? shift : 0;\r\n};\r\n\r\nconst n = +readline();\r\n\r\nvar roomWH;\r\nvar table1Points;\r\nvar table2WH;\r\n\r\nfor(var i = 0; i < n; i++) {\r\n roomWH = readline().split(\" \").map(i => +i);\r\n table1Points = readline().split(\" \").map(i => +i);\r\n table2WH = readline().split(\" \").map(i => +i);\r\n print(setTable(roomWH, table1Points, table2WH));\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nlet INF = 2e8;\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [W, H] = rna();\r\n\t\tlet [x1, y1, x2, y2] = rna();\r\n\t\tlet [w, h] = rna();\r\n\r\n\t\thmx = Math.max(H - y2, y1);\r\n\t\twmx = Math.max(x1, W - x2);\r\n\r\n\t\tif (w < wmx || h < hmx)\r\n\t\t\tconsole.log(0);\r\n\t\telse {\r\n\t\t\tlet ans1 = ans2 = INF;\r\n\t\t\tif (h + (y2 - y1) <= H) {\r\n\t\t\t\tans1 = h - hmx;\r\n\t\t\t}\r\n\r\n\t\t\tif (w + (x2 - x1) <= W) {\r\n\t\t\t\tans2 = w - wmx;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log((ans1 & ans2) == INF ? -1 : Math.min(ans1, ans2));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [rw, rh] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let [x1, y1, x2, y2] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let u = rh - y2,\r\n r = rw - x2,\r\n l = x1,\r\n d = y1;\r\n let [tw, th] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseFloat(cur));\r\n let ans = Infinity;\r\n if (l >= tw) ans = 0;\r\n if (r >= tw - l) ans = Math.min(ans, tw - l);\r\n if (r >= tw) ans = 0;\r\n if (l >= tw - r) ans = Math.min(ans, tw - r);\r\n if (u >= th) ans = 0;\r\n if (d >= th - u) ans = Math.min(ans, th - u);\r\n if (d >= th) ans = 0;\r\n if (u >= th - d) ans = Math.min(ans, th - d);\r\n if (ans === Infinity) ans = -1;\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var [W, H] = lines[l++].split(' ').map(Number)\n var [x1, y1, x2, y2] = lines[l++].split(' ').map(Number)\n var [w, h] = lines[l++].split(' ').map(Number)\n console.log(solve(W, H, x1, y1, x2, y2, w, h))\n }\n});\n\nfunction solve(W, H, x1, y1, x2, y2, w, h) {\n const l = x1\n const r = W - x2\n const t = H - y2\n const b = y1\n // console.log(l, r, t, b)\n if (l + r >= w) {\n return h > H ? -1 : Math.max(0, w - Math.max(l, r))\n }\n if (t + b >= h) {\n return w > W ? -1 : Math.max(0, h - Math.max(t, b))\n }\n return -1\n}\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst MAX_N = 100010,\r\n sum1 = new Array(MAX_N)\r\nfunction solve(e, n, t) {\r\n if (e <= 1) return 0\r\n sum1[0] = n[0]\r\n for (let t = 1; t < e; ++t) sum1[t] = sum1[t - 1] + n[t]\r\n const s = e - 1\r\n let i = sum1[s] - n[0]\r\n for (let n = 1, r = t[0]; n < e; ++n) {\r\n const e = Math.max(sum1[s] - sum1[n], r)\r\n ;(r += t[n]), i > e && (i = e)\r\n }\r\n return i\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(\r\n Number(e.readLine()),\r\n e.readIntegersOfLine(),\r\n e.readIntegersOfLine(),\r\n )\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}], "src_uid": "29fd4c77a2f28478ebce98dfc6496aac"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb) {\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));\n return Array(a - b + 1).fill(0).map((v, i) => cb(a - i));\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(0, t - 1, i => {\n let [n, x, y] = inp.slice(r, r = r + 3);\n // console.log(n, x, y);\n For(n - 1, 1, i => {\n if ((y - x) % i == 0) {\n let k = (y - x) / i;\n a = Arr(0, i, i => x + i * k);\n while (a.length < n) {\n if (a[0] - k >= 1) a.unshift(a[0] - k);\n else a.push(a[a.length - 1] + k);\n }\n console.log(a.join(' '));\n return 0;\n }\n })\n })\n})();", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var x = one[1];\n var y = one[2];\n if(N == 2){\n output[i] = x + \" \" + y;\n continue;\n }\n var dlist = getDivisorList(y - x);\n var out = [];\n var max = Math.pow(10,9);\n for(var j = 0; j < dlist.length; j++){\n var tmpmax = y;\n var tmpout = [x];\n var isOK = false;\n for(var k = 1; k <= N; k++){\n if(x + k * dlist[j] > y){\n isOK = true;\n break;\n }\n tmpout.push(x + k * dlist[j]);\n \n }\n //myerr(tmpout);\n if(isOK && tmpout.length <= N){\n for(var k = 1; k <= N; k++){\n if(tmpout.length == N){\n break;\n }\n if(x - dlist[j] * k < 1){\n break;\n }\n tmpout.unshift(x - dlist[j] * k);\n\n }\n while(tmpout.length < N){\n tmpout.push(tmpout[tmpout.length - 1] + dlist[j]);\n tmpmax = tmpout[tmpout.length - 1];\n }\n if(max > tmpmax){\n max = tmpmax;\n out = tmpout;\n }\n //myerr(tmpout);\n }else{\n continue;\n }\n }\n output[i] = myconv(out, 8);\n }\n myout(myconv(output, 9));\n}\nfunction getDivisorList(val){\n var list = [];\n for(var i = 1; i * i <= val; i++){\n if(val % i == 0){\n list.push(i);\n if(i * i != val){\n list.push(val / i);\n }\n }\n }\n list.sort(function(a,b){ return a - b; });\n return list;\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let i = 1; i <= t; i++) {\n let [n, x, y] = input[i].split(\" \").map((num) => Number(num));\n\n if (n === 2) {\n console.log([x, y].join(\" \"));\n continue;\n }\n\n const diff = y - x;\n const result = [];\n\n //1. x\uc640 y\uc0ac\uc774\uc5d0\ub294 (n-2)\uac1c ~ 0\uac1c\uc758 \uc6d0\uc18c\uac00 \uc874\uc7ac\ud560 \uc218 \uc788\ub2e4.\n for (let j = n - 1; j >= 0; j--) {\n const equalDiff = diff / j;\n\n //2. \uc815\uc218\ub85c \ub098\ub258\uc5b4 \ub5a8\uc5b4\uc9c0\uc9c0 \uc54a\ub294\ub2e4\uba74 \ud574\ub2f9 \uac1c\uc218\ub294 \ubd88\uac00\ub2a5\n if (equalDiff !== parseInt(equalDiff)) {\n continue;\n }\n\n //3. \uc815\uc218\ub85c \ub098\ub204\uc5b4 \ub5a8\uc5b4\uc9c4\ub2e4\uba74 \ud574\ub2f9 \ubc30\uc5f4\uc774 \ub2f5\uc774\ub2e4\n //3-1. x\uc640 y \ub123\uae30\n result.push(x);\n result.push(y);\n n -= 2;\n\n //3-2. x\uc640 y \uc0ac\uc774 \ub123\uae30\n for (let k = 1; k <= j - 1; k++) {\n n--;\n result.push(x + k * equalDiff);\n }\n\n //3-3. x \uc774\uc804 \ub123\uae30\n for (let k = 1; ; k++) {\n if (n <= 0) break;\n\n const xBefore = x - k * equalDiff;\n if (xBefore <= 0) break;\n\n n--;\n result.push(xBefore);\n }\n\n //3-4. y \uc774\ud6c4 \ub123\uae30\n for (let k = 1; ; k++) {\n if (n <= 0) break;\n\n const yAfter = y + k * equalDiff;\n n--;\n result.push(yAfter);\n }\n\n //7. \ucd5c\ub313\uac12\uc774 \uc874\uc7ac\ud558\ub294 \ubc30\uc5f4\uc744 \ub9cc\ub4e4\uc5b4 \ucd9c\ub825\ud55c\ub2e4\n console.log(result.join(\" \"));\n break;\n }\n }\n}\n\n/*\n\n 1. \ube44\ubc00 \ubc30\uc5f4\uc744 \ubcf5\uc6d0\ud574\uc57c \ud55c\ub2e4\n 2. n\uac1c\uc758 \uc11c\ub85c \ub2e4\ub978 \uc591\uc758 \uc815\uc218\ub97c \ud3ec\ud568\ud558\uace0 \uc788\ub2e4\n 3. \ub108\uc5d0\uac8c \uc54c\ub824\uc9c4 x\uc640 y\ub97c \ud3ec\ud568\ud558\uace0 \uc788\ub294\ub370, x < y\n 4. \uc624\ub984\ucc28\uc21c\uc73c\ub85c \uc815\ub82c \uc2dc, \uac01 \uc778\uc811 \uc6d0\uc18c \uac04\uc758 diff\ub294 \ubaa8\ub450 \ub3d9\uc77c\n\n Q. \uac00\uc7a5 \ud070 \uc6d0\uc18c\uc758 \uac12\uc774 \ucd5c\uc18c\uac00 \ub418\ub294 \ubc30\uc5f4\uc758 \uc6d0\uc18c\ub4e4\uc744 \ucd9c\ub825\ud558\ub77c\n \n*/\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b] = ti(readline().split(' '));\n\n if(a === b){\n console.log(0);\n continue;\n }\n\n let d = Math.abs(a-b);\n if(d <= 10){\n console.log(1);\n continue;\n }else{\n if(d % 10 !== 0)\n console.log(1 + Math.floor(d/10));\n else\n console.log(d / 10);\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b,x,y,n] = ti(readline().split(' '));\n\n if(a > b){\n let temp = a;\n a = b;\n b = temp;\n temp = x;\n x = y;\n y = temp;\n }\n\n if(b - y >= n){\n b -= n;\n console.log(a*b);\n }else{\n n -= (b-y);\n b = y;\n if(a-x >= n){\n a -= n;\n }else{\n a = x;\n }\n\n console.log(a*b);\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x,y] = ti(readline().split(' '));\n\n let min = 99999999999999;\n let res = null;\n for(let i = 1; i <= x; i++){\n for(let j = 0; j <= y-x; j++){\n let inclX = false;\n let inclY = false;\n let op = new Array(n);\n for(let k = 0; k < n; k++){\n if(k === 0){\n op[k] = i;\n }else{\n op[k] = op[k-1] + j;\n }\n\n if(op[k] === x)\n inclX = true;\n \n if(op[k] === y)\n inclY = true;\n }\n\n if(inclX && inclY){\n if(min > op[n-1]){\n min = op[n-1];\n res = op;\n }\n }\n }\n }\n\n for(let num of res)\n console.log(num);\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst mul = (a, b) => mod(mod(a) * mod(b));\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, a, b] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let min = Number.MAX_SAFE_INTEGER;\n let result = [];\n\n for (let start = 1; start <= 50; start++) {\n for (let diff = 1; diff <= 50; diff++) {\n const arr = [start];\n let [foundA, foundB] = [false, false];\n for (let i = 1; i < len; i++) {\n arr.push(start + diff * i);\n }\n for (let i = 0; i < len; i++) {\n if (arr[i] === a) foundA = true;\n if (arr[i] === b) foundB = true;\n }\n if (foundA && foundB) {\n if (arr[len - 1] < min) {\n min = arr[len - 1];\n result = [...arr];\n }\n }\n }\n }\n console.log(result.join(\" \"));\n }\n}\n"}, {"source_code": "T = readline()\nwhile (T--) {\n a = readline().split(' ')\n n = +a[0]\n x = +a[1]\n y = +a[2]\n d = y - x\n k = 1\n for (; k < 50; k++) {\n if (d % k)\n continue\n if (d / k + 1 <= n)\n break\n }\n j = n - 1\n while (y - j * k < 1)\n j--\n u = y - j * k\n ans = ''\n for (i = 0; i < n; i++) {\n ans += u.toString() + ' '\n u += k\n }\n print(ans)\n}"}, {"source_code": "T = readline()\nwhile (T--) {\n a = readline().split(' ').map(x => +x)\n n = a[0]; x = a[1]; y = a[2]\n d = y - x\n k = 1\n for (; k < 50; k++) {\n if (d % k)\n continue\n if (d / k + 1 <= n)\n break\n }\n j = n - 1\n while (y - j * k < 1)\n j--\n u = y - j * k\n print(Array.from({ length: n }, (v, i) => u + k * i).join(' '));\n}\n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let i = 1; i <= t; i++) {\n let [n, x, y] = input[i].split(\" \").map((num) => Number(num));\n\n if (n === 2) {\n console.log([x, y]);\n continue;\n }\n\n const diff = y - x;\n const result = [];\n\n //1. x\uc640 y\uc0ac\uc774\uc5d0\ub294 (n-2)\uac1c ~ 0\uac1c\uc758 \uc6d0\uc18c\uac00 \uc874\uc7ac\ud560 \uc218 \uc788\ub2e4.\n for (let j = n - 1; j >= 0; j--) {\n const equalDiff = diff / j;\n\n //2. \uc815\uc218\ub85c \ub098\ub258\uc5b4 \ub5a8\uc5b4\uc9c0\uc9c0 \uc54a\ub294\ub2e4\uba74 \ud574\ub2f9 \uac1c\uc218\ub294 \ubd88\uac00\ub2a5\n if (equalDiff !== parseInt(equalDiff)) {\n continue;\n }\n\n //3. \uc815\uc218\ub85c \ub098\ub204\uc5b4 \ub5a8\uc5b4\uc9c4\ub2e4\uba74 \ud574\ub2f9 \ubc30\uc5f4\uc774 \ub2f5\uc774\ub2e4\n //3-1. x\uc640 y \ub123\uae30\n result.push(x);\n result.push(y);\n n -= 2;\n\n //3-2. x\uc640 y \uc0ac\uc774 \ub123\uae30\n for (let k = 1; k <= j - 1; k++) {\n n--;\n result.push(x + k * equalDiff);\n }\n\n //3-3. x \uc774\uc804 \ub123\uae30\n for (let k = 1; ; k++) {\n if (n <= 0) break;\n\n const xBefore = x - k * equalDiff;\n if (xBefore <= 0) break;\n\n n--;\n result.push(xBefore);\n }\n\n //3-4. y \uc774\ud6c4 \ub123\uae30\n for (let k = 1; ; k++) {\n if (n <= 0) break;\n\n const yAfter = y + k * equalDiff;\n n--;\n result.push(yAfter);\n }\n\n //6. \uc815\ub82c\n result.sort((n1, n2) => {\n return n1 - n2;\n });\n\n //7. \ucd5c\ub313\uac12\uc774 \uc874\uc7ac\ud558\ub294 \ubc30\uc5f4\uc744 \ub9cc\ub4e4\uc5b4 \ucd9c\ub825\ud55c\ub2e4\n console.log(result);\n break;\n }\n }\n}\n\n/*\n\n 1. \ube44\ubc00 \ubc30\uc5f4\uc744 \ubcf5\uc6d0\ud574\uc57c \ud55c\ub2e4\n 2. n\uac1c\uc758 \uc11c\ub85c \ub2e4\ub978 \uc591\uc758 \uc815\uc218\ub97c \ud3ec\ud568\ud558\uace0 \uc788\ub2e4\n 3. \ub108\uc5d0\uac8c \uc54c\ub824\uc9c4 x\uc640 y\ub97c \ud3ec\ud568\ud558\uace0 \uc788\ub294\ub370, x < y\n 4. \uc624\ub984\ucc28\uc21c\uc73c\ub85c \uc815\ub82c \uc2dc, \uac01 \uc778\uc811 \uc6d0\uc18c \uac04\uc758 diff\ub294 \ubaa8\ub450 \ub3d9\uc77c\n\n Q. \uac00\uc7a5 \ud070 \uc6d0\uc18c\uc758 \uac12\uc774 \ucd5c\uc18c\uac00 \ub418\ub294 \ubc30\uc5f4\uc758 \uc6d0\uc18c\ub4e4\uc744 \ucd9c\ub825\ud558\ub77c\n \n*/\n"}], "src_uid": "ca9d97e731e86cf8223520f39ef5d945"} {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x).sort((a, b) => a-b).reduce((r, x, index) => {\n if (index > 0) {\n if (r[r.length - 1][0] === x) {\n r[r.length - 1][1]++\n } else {\n r.push([x, 1])\n }\n } else {\n r.push([x, 1])\n }\n return r\n }, [])\n let sum = 0\n let rest = 0\n for (let j=0; j= num) {\n sum += Math.floor(count/num)\n rest = count % num\n } else {\n rest += e[j][1]\n }\n }\n console.log(sum)\n // while(start < e.length) {\n // start += e[start]\n // c++\n // }\n // if (start > e.length) {\n // c--\n // }\n // console.log(c)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextIntArray();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar map = {};\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = 1;\n\t\t\t}else{\n\t\t\t\tmap[list[j]]++;\n\t\t\t}\n\t\t}\n\t\tvar keys = Object.keys(map);\n\t\tkeys.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tvar count = 0;\n\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\tvar singleCount = Math.floor(map[keys[j]] / keys[j]);\n\t\t\tvar nokori = map[keys[j]] % keys[j];\n\t\t\tcount += singleCount;\n\t\t\tif(j != keys.length - 1){\n\t\t\t\tmap[keys[j + 1]] += nokori;\n\t\t\t}\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n2\n3\n4\n5\n6\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r a - b);\n let temp = 0;\n let ans = 0;\n\n for(let i=0;i {\n const n = +lines[0]\n for (let i=0; i +x).sort((a, b) => a-b).reduce((r, x, index) => {\n if (index > 0) {\n if (r[r.length - 1][0] === x) {\n r[r.length - 1][1]++\n } else {\n r.push([x, 1])\n }\n } else {\n r.push([x, 1])\n }\n return r\n }, [])\n let sum = 0\n let rest = 0\n for (let j=0; j= num) {\n sum += Math.floor(count/num)\n rest = count % num\n }\n }\n console.log(sum)\n // while(start < e.length) {\n // start += e[start]\n // c++\n // }\n // if (start > e.length) {\n // c--\n // }\n // console.log(c)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n e.sort((a, b) => b - a)\n let start = 0\n let c = 0\n while(start < e.length) {\n start += e[start]\n c++\n }\n console.log(c)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n2\n3\n4\n5\n6\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nlet clone = Array.push;\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r a - b);\n\n let count = 0;\n while(a.length) {\n a.shift();\n a.pop();\n count++\n }\n\n console.log(count);\n\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n2\n3\n4\n5\n6\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nlet clone = Array.push;\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r b ? a : b);\n}\n\nfunction min(a, b) {\n return (a > b ? b : a);\n}\n\nvar n = readline().split(' ');\n\nfor (var i = 0; i < n; i++) {\n var line = readline().split(' ');\n var x = parseInt(line[0]), y = parseInt(line[1]);\n line = readline().split(' ');\n var a = parseInt(line[0]), b = parseInt(line[1]);\n if (max(x, y) == max(a, b) && min(x, y) + min(a, b) == max(x, y)) print(\"YES\");\n else print(\"NO\");\n}", "positive_code": [{"source_code": "const readline = require('readline');\nconst r = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tc\nlet slice1,slice2;\nr.on('line', (line) => {\n if (!tc) { tc = line; }\n else if (!slice1) {\n slice1 = line;\n \n }\n else if (!slice2) {\n slice2 = line;\n let d1 = slice1.split(\" \").map(n =>+n);\n let d2 = slice2.split(\" \").map(n =>+n);\n console.log( sq(d1[0],d1[1],d2[0],d2[1]) ?\"YES\":\"NO\");\n slice1= slice2= undefined;\n }\n else {\n query = readNums(line);\n console.log(minLength(arr, query[0], query[1]));\n }\n\n});\n\nfunction sq(a,b,c,d){\n return (a==c && a == (b+d)) || (a==d && a == (b+c)) ||((b==c && b == (a+d))) ||((b==d && b == (a+c)))\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar mae = nextIntArray();\n\t\tvar ato = nextIntArray();\n\t\tif(mae[0] == ato[0] || mae[0] == ato[1] || mae[1] == ato[0] || mae[1] == ato[1]){\n\t\t\tif(mae[0] == ato[0]){\n\t\t\t\tif(mae[1] + ato[1] == mae[0]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(mae[0] == ato[1]){\n\t\t\t\tif(mae[1] + ato[0] == mae[0]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(mae[1] == ato[0]){\n\t\t\t\tif(mae[0] + ato[1] == mae[1]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(mae[1] == ato[1]){\n\t\t\t\tif(mae[0] + ato[0] == mae[1]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(output[i] == null){\n\t\t\t\toutput[i] = \"NO\";\n\t\t\t}\n\t\t}else{\n\t\t\toutput[i] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst r = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tc\nlet slice1, slice2;\nr.on('line', (line) => {\n if (!tc) { tc = line; }\n else if (!slice1) {\n slice1 = line;\n\n }\n else if (!slice2) {\n slice2 = line;\n let d1 = slice1.split(\" \").map(n => +n);\n let d2 = slice2.split(\" \").map(n => +n);\n console.log(sq(d1[0], d1[1], d2[0], d2[1]) ? \"YES\" : \"NO\");\n slice1 = slice2 = undefined;\n }\n else {\n query = readNums(line);\n console.log(minLength(arr, query[0], query[1]));\n }\n\n});\n\nfunction sq(a, b, c, d) {\n return (a == c && a == (b + d)) || (a == d && a == (b + c)) || ((b == c && b == (a + d))) || ((b == d && b == (a + c)))\n}\n"}, {"source_code": "var t = Number(readline());\nwhile(t--) {\n var v = readline().split(\" \");\n var a1 = Number(v[0]);\n var b1 = Number(v[1]);\n\n v = readline().split(\" \");\n var a2 = Number(v[0]);\n var b2 = Number(v[1]);\n\n if ((a1 == a2 && b1+b2 == a1) || (b1 == b2 && a1+a2 == b1)) print(\"YES\");\n else if ((a1 == b2 && b1+a2 == a1) || (b1 == a2 && a1+b2 == b1)) print(\"YES\");\n else print(\"NO\");\n}"}, {"source_code": "var line = readline().split(' ').map((x) => parseInt(x));\n\nwhile(line[0]--) {\n\t\n\tvar l1 = readline().split(' ').map((x) => parseInt(x));\n\tvar l2 = readline().split(' ').map((x) => parseInt(x));\n\n\tif(l1[0]==l2[0]) {\n\n\t\tif(l1[1]+l2[1] == l1[0]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\t\t\n\tif(l1[1]==l2[1]) {\n\n\t\tif(l1[0]+l2[0] == l1[1]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\n\t}\n\n\tif(l1[1]==l2[0]) {\n\n\t\tif(l1[0]+l2[1] == l1[1]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\t\n\tif(l1[0]==l2[1]) {\n\n\t\tif(l1[1]+l2[0] == l1[0]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\t\tprint(\"No\");\n\t}"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x).sort((a, b) => b-a)\n const [c, d] = lines[i*2+2].split(' ').map(x => +x).sort((a, b) => b-a)\n if (a === c && b+d === a) {\n console.log('Yes')\n } else {\n console.log('No')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "\tvar line = readline().split(' ').map((x) => parseInt(x));\n\nwhile(line[0]--) {\n\t\n\tvar l1 = readline().split(' ').map((x) => parseInt(x));\n\tvar l2 = readline().split(' ').map((x) => parseInt(x));\n\n\tif(l1[0]==l2[0]) {\n\n\t\tif(l1[1]+l2[1] == l1[0]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\t\t\n\tif(l1[1]==l2[1]) {\n\n\t\tif(l1[0]+l2[0] == l1[1]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\n\t}\n\n\tif(l1[1]==l2[0]) {\n\n\t\tif(l1[0]+l2[1] == l1[1]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\t\n\tif(l1[0]==l2[1]) {\n\n\t\tif(l1[1]+l2[0] == l1[0]) {\n\t\t\tprint(\"Yes\");\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\t\tprint(\"No\");\n\t}\n\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n ab = null\n\nfunction loop(line) {\n\n if (line.trim() == \"\")\n return\n\n let cd = line.split(\" \")\n .map(x => parseInt(x,10))\n .sort((x,y) => x-y)\n\n if (ab == null)\n return ab = cd\n\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n\n ab = --N == 0 ? rl.close() : null\n\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", loop)\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n for (var i = 0; i < n; i++) {\n let arr = [];\n arr.push(readLine()\n .split(' ')\n .map(value => parseInt(value))\n .sort((a, b) => b - a)\n );\n arr.push(readLine()\n .split(' ')\n .map(value => parseInt(value))\n .sort((a, b) => b - a)\n );\n if (arr[0][0] == arr[1][0]) {\n if (arr[0][1] + arr[1][1] == arr[0][0]) {\n console.log('YES');\n } else\n console.log('NO')\n } else console.log('NO');\n }\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const [a, b] = readLine().split(' ').map(x => parseInt(x));\n const [c, d] = readLine().split(' ').map(x => parseInt(x));\n if ((a == c && (b+d) ==a ) || (a == d && (b + c) == a) || (c == b && (a+d) ==c ) || (b == d && (a+c) ==b ) ){\n console.log('YES')\n } else console.log('NO')\n }\n return;\n}\n"}], "negative_code": [{"source_code": "var line = readline().split(' ').map((x)=> parseInt(x));\n\nwhile(line[0]--) {\n\t\n\tvar l1 = readline().split(' ').map((x)=> parseInt(x));\n\tvar l2 = readline().split(' ').map((x)=> parseInt(x));\n\n\tif(l1[0]==l2[0])\n\t{\n\t\tif(l1[1]+l2[1] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[1])\n\t{\n\t\tif(l1[0]+l2[0] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[0])\n\t{\n\t\tif(l1[0]+l2[1] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[0]==l2[1])\n\t{\n\t\tif(l1[1]+l2[0] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse\n\t{\n\n\t\tprint(\"No\");\n\t}\n\n\n}"}, {"source_code": "var line = readline().split(' ').map((x)=> parseInt(x));\n\nwhile(line[0]--) {\n\t\n\tvar l1 = readline().split(' ').map((x)=> parseInt(x));\n\tvar l2 = readline().split(' ').map((x)=> parseInt(x));\n\n\tif(l1[0]==l2[0])\n\t{\n\t\tif(l1[1]+l2[1] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[1])\n\t{\n\t\tif(l1[0]+l2[0] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[0])\n\t{\n\t\tif(l1[0]+l2[1] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[0]==l2[1])\n\t{\n\t\tif(l1[1]+l2[0] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse\n\t\t\tprint(\"No\");\n\n\n}"}, {"source_code": "var line = readline().split(' ');\n\nwhile(line[0]--) {\n\t\n\tvar l1 = readline().split(' ');\n\tvar l2 = readline().split(' ');\n\n\tif(l1[0]==l2[0])\n\t{\n\t\tif(l1[1]+l2[1] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[1])\n\t{\n\t\tif(l1[0]+l2[0] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\n\t\t}\n\t}\n\telse if(l1[1]==l2[0])\n\t{\n\t\tif(l1[0]+l2[1] == l1[1])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse if(l1[0]==l2[1])\n\t{\n\t\tif(l1[1]+l2[0] == l1[0])\n\t\t{\n\t\t\tprint(\"Yes\");\n\t\t\t\n\t\t}\n\t}\n\telse\n\t\t\tprint(\"No\");\n\n\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const [a, b] = readLine().split(' ').map(x => parseInt(x));\n const [c, d] = readLine().split(' ').map(x => parseInt(x));\n if (Math.sqrt((a*b) + (c*d))%1 ==0){\n console.log('YES')\n } else console.log('NO')\n }\n return;\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const [a, b] = readLine().split(' ').map(x => parseInt(x));\n const [c, d] = readLine().split(' ').map(x => parseInt(x));\n const totalArea = (a*b) + (c*d);\n if (totalArea > 3 && Math.sqrt(totalArea)%1 ==0){\n console.log('YES')\n } else console.log('NO')\n }\n return;\n}\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar mae = nextIntArray();\n\t\tvar ato = nextIntArray();\n\t\t\n\t\tif(mae[0] == ato[0] || mae[0] == ato[1] || mae[1] == ato[0] || mae[1] == ato[1]){\n\t\t\tif(mae[0] == ato[0]){\n\t\t\t\tif(mae[1] + ato[1] == mae[0]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}else if(mae[0] == ato[1]){\n\t\t\t\tif(mae[1] + ato[0] == mae[0]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}else if(mae[1] == ato[0]){\n\t\t\t\tif(mae[0] + ato[1] == mae[1]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}else if(mae[1] == ato[1]){\n\t\t\t\tif(mae[0] + ato[0] == mae[1]){\n\t\t\t\t\toutput[i] = \"YES\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(output[i] == null){\n\t\t\t\toutput[i] = \"NO\";\n\t\t\t}\n\t\t}else{\n\t\t\toutput[i] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a1, a2, b1, b2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n [a1, b1] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n [a2, b2] = d.split(' ').map(Number);\n\n if (a1 + a2 === b1 || a1 + b2 === b1) {\n console.log('YES');\n }\n else if (b1 + a2 === a1 || b1 + b2 === a1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a1, a2, b1, b2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n [a1, b1] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n [a2, b2] = d.split(' ').map(Number);\n\n if (a1 === a2 || a1 === b2) {\n if (b1 + a2 === a1 || b1 + b2 === a1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else if (b1 === a2 || b1 === b2) {\n if (a1 + a2 === b1 || a1 + b2 === b1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet a, b, c, d;\n\nfunction sq(a, b, c, d) {\n return (a == c && a == (b + d)) || (a == d && a == (b + c)) || ((b == c && b == (a + d))) || ((b == d && b == (a + c)))\n}\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n tests = +data;\n return;\n }\n\n if (count % 2) {\n [a, b] = data.split(' ').map(Number);\n count++;\n return;\n }\n\n [c, d] = data.split(' ').map(Number);\n\n console.log(sq(a, b, c, d) ? \"YES\" : \"NO\");\n\n count++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet a, b, c, d;\nlet tests = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n tests = +data;\n return;\n }\n\n if (count % 2) {\n [a, b] = data.split(' ').map(Number);\n count++;\n return;\n }\n\n if (tests === 0) {\n return;\n }\n\n tests--;\n [c, d] = data.split(' ').map(Number);\n\n if (a > b) {\n [a, b] = [b, a];\n }\n\n if (c > d) {\n [c, d] = [d, c];\n }\n\n if (b === d && a + c === b) {\n console.log('YES');\n }\n else {\n console.log('No');\n }\n\n count++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet a, b, c, d;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n if (count % 2) {\n [a, b] = data.split(' ').map(Number);\n count++;\n return;\n }\n\n [c, d] = data.split(' ').map(Number);\n\n if (a > b) {\n [a, b] = [b, a];\n }\n\n if (c > d) {\n [c, d] = [d, c];\n }\n\n if (b === d && a + c === b) {\n console.log('YES');\n }\n else {\n console.log('No');\n }\n\n count++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a1, a2, b1, b2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n [a1, b1] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n [a2, b2] = d.split(' ').map(Number);\n\n if (a1 === a2 || a1 === b2) {\n if (b1 + a2 === a1 || b1 + b2 === a1) {\n console.log('YES');\n }\n else if (a1 + b1 === a2 + b2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else if (b1 === a2 || b1 === b2) {\n if (a1 + a2 === b1 || a1 + b2 === b1) {\n console.log('YES');\n }\n else if (a1 + b1 === a2 + b2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a1, a2, b1, b2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n [a1, b1] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n [a2, b2] = d.split(' ').map(Number);\n\n if (a1 === a2 || a1 === b2) {\n if (b1 + a2 === a1 || b1 + b2 === a1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else if (b1 === a2 || b1 === b2) {\n if (a1 + a2 === b1 || a1 + b2 === b1) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n else {\n if (a1 + b1 === a2 + b2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr1, arr2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n arr1 = d.split(' ').map(Number);\n arr1.sort((a, b) => a - b);\n c++;\n return;\n }\n\n arr2 = d.split(' ').map(Number);\n arr2.sort((a, b) => a - b);\n\n if (arr1[0] + arr2[0] === arr1[1] && arr1[1] === arr2[1]) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \").map(Number).sort()\n rl.question(\"\", cd => {\n cd = cd.split(\" \").map(Number).sort()\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1]) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar t = null,\n ab = null\n\nfunction loop(line) {\n\n if (t == null) return t = Number(line)\n\n const cd = line.split(\" \").map(Number).sort()\n\n if (ab == null) {\n ab = cd\n } else {\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n if (--t == 0)\n rl.close()\n else\n ab = null\n }\n\n}\n\nrl.on(\"line\", line => loop(line))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n ab = null\n\nfunction loop(line) {\n\n let cd = line.split(\" \").map(Number).sort((x,y) => x-y)\n\n if (ab == null)\n return ab = cd\n\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n\n ab = --N == 0 ? rl.close() : null\n\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", line => loop(line))\n})\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \").map(Number).sort()\n rl.question(\"\", cd => {\n cd = cd.split(\" \").map(Number).sort()\n if (ab[1] != cd[1] || ab[0] == ab[1] || cd[0] == cd[1]) {\n console.log(\"No\")\n } else if (ab[0] + cd[0] == ab[1]) {\n console.log(\"Yes\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \").map(Number).sort()\n rl.question(\"\", cd => {\n cd = cd.split(\" \").map(Number).sort()\n if (ab[0] != ab[1] && cd[0] != cd[1] && ab[1] == cd[1] && (ab[0] + cd[0]) == ab[1]) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \").map(Number)\n rl.question(\"\", cd => {\n cd = cd.split(\" \").map(Number)\n if (ab[0] == ab[1] || cd[0] == cd[1]) {\n console.log(\"No\")\n } else {\n let abcd = ab.concat(cd).sort()\n if (abcd[2] == abcd[3] && abcd[0] + abcd[1] == abcd[2])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \")//.map(Number).sort()\n a = Number(ab[0])\n b = Number(ab[1])\n rl.question(\"\", cd => {\n cd = cd.split(\" \")//.map(Number).sort()\n c = Number(cd[0])\n d = Number(cd[1])\n if ((a==c && b+d==a) || (a==d && b+c==a) || (b==c && a+d==b) || (b==d && a+c==b)) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction dotest(t) {\n rl.question(\"\", ab => {\n ab = ab.split(\" \").map(Number).sort()\n rl.question(\"\", cd => {\n cd = cd.split(\" \").map(Number).sort()\n if (ab[0] + cd[0] == ab[1] && ab[0] + cd[0] == cd[1]) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n t == 1 ? rl.close():dotest(t-1)\n })\n })\n}\n\nrl.question(\"\", t => dotest(Number(t)))\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar t = null,\n ab = null\n\nfunction loop(line) {\n\n if (t == null) return t = Number(line)\n\n const cd = line.split(\" \").map(Number).sort()\n\n if (ab == null) {\n ab = cd\n } else {\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n if (--t == 0)\n rl.close()\n else\n ab = null\n console.log(t)\n }\n\n}\n\nrl.on(\"line\", line => loop(line))"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n ab = null\n\nfunction loop(line) {\n\n let cd = line.split(\" \")\n .map(x => parseInt(x,10))\n .sort((x,y) => x-y)\n\n if (ab == null)\n return ab = cd\n\n if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])\n console.log(\"Yes\")\n else\n console.log(\"No\")\n\n ab = --N == 0 ? rl.close() : null\n\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", loop)\n})\n"}], "src_uid": "a375dd323b7adbfa9f1cad9aa48f7247"} {"source_code": "\"use strict\";\n\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); }\n\nfunction _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === \"[object Arguments]\")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar n = parseInt(readline());\nvar answers = [];\n\nfor (var i = 0; i < n; i++) {\n var _readline$getNumArray = readline().getNumArray(),\n _readline$getNumArray2 = _slicedToArray(_readline$getNumArray, 3),\n c = _readline$getNumArray2[0],\n m = _readline$getNumArray2[1],\n l = _readline$getNumArray2[2];\n\n var mainMin = c < m ? c : m;\n l += Math.abs(c - m);\n\n if (l >= mainMin) {\n answers.push(mainMin);\n } else {\n var transport = Math.ceil((mainMin - l) / 3);\n answers.push(mainMin - transport);\n }\n}\n\nwrite(answers.join('\\n'));", "positive_code": [{"source_code": "// c, m, x(\ucf54\ub354, \uc218\ud559\uc790, \uca4c\ub9ac) \nlet lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const q = lines[0]\n\n for(let i = 0; i < q; i++) {\n const [ c, m, x ] = lines[i + 1].split(/\\s/).map(Number)\n const sum = Math.floor((c + m + x) / 3)\n const min = Math.min(c, m)\n\n console.log(Math.min(sum, min))\n }\n}\n"}], "negative_code": [], "src_uid": "b18dac401b655c06bee331e71eb3e4de"} {"source_code": "var n = +readline();\r\n\r\nwhile (n--) {\r\n\tvar t = +readline();\r\n\tprint(2);\r\n\tvar ans = 1;\r\n\tvar arrCheck = new Array(t + 1);\r\n\tvar mid = parseInt(t / 2);\r\n\tfor (var i = 1; i <= mid; i++) {\r\n\t\tvar ans = i;\r\n\t\twhile (ans <= t && arrCheck[ans] === undefined) {\r\n\t\t\twrite(ans + \" \");\r\n\t\t\tarrCheck[ans] = 1;\r\n\t\t\tans *= 2;\r\n\t\t}\r\n\t}\r\n\tfor (var i = 1; i <= t; i++) {\r\n\t\tif (arrCheck[i] === undefined) write(i, \" \");\r\n\t}\r\n\tprint();\r\n}\r\n", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline();\r\n // var [a,b] = readline().split(' ').map((x) => parseInt(x));\r\n console.log(2);\r\n var ans = [], c = []\r\n for(var i=1;i<=n;i++) {\r\n if(c[i] == undefined) {\r\n for(var j=i;j<=n;j*=2) {\r\n ans.push(j);\r\n c[j] = true;\r\n }\r\n }\r\n }\r\n console.log(ans.join(\" \"))\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n let n = parseInt(readline());\r\n let hsh = Array(n+1).fill(false);\r\n let res = [];\r\n for (let j = 1;j <= n;++j) {\r\n if (hsh[j]) {\r\n continue;\r\n }\r\n for (let i = j;i <= n;i*=2) {\r\n hsh[i] = true;\r\n res.push(i);\r\n }\r\n }\r\n console.log(2);\r\n console.log(res.join(' ').toString());\r\n }\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n\r\n let used = {};\r\n let smallestNotUsed = 3;\r\n let arr = [1, 2];\r\n let i = 1;\r\n\r\n while (arr.length < n) {\r\n let double = arr[i] * 2;\r\n if (double <= n) {\r\n arr[i + 1] = double;\r\n used[double] = true;\r\n } else {\r\n arr[i + 1] = smallestNotUsed;\r\n used[smallestNotUsed] = true;\r\n let newSmallest = smallestNotUsed + 1;\r\n while (used[newSmallest]) {\r\n newSmallest++;\r\n }\r\n smallestNotUsed = newSmallest;\r\n }\r\n i++;\r\n }\r\n\r\n output(2);\r\n output(arr.join(' '));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n const res = [],\r\n set = new Set();\r\n for (let i = 1; i <= n; i++) {\r\n if (set.has(i)) continue;\r\n for (let j = i; j <= n; j *= 2) {\r\n res.push(j);\r\n set.add(j);\r\n }\r\n }\r\n return `${2}\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n\r\n for (let t = 0; t < testcases; t++) {\r\n const n = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const d = 2;\r\n\r\n const set = new Set();\r\n\r\n const res = [1];\r\n\r\n for (let i = 2; i <= n; i++) {\r\n if (!set.has(i)) {\r\n for (let j = i; j <= n; j *= 2) {\r\n if (!set.has(j)) {\r\n res.push(j);\r\n set.add(j);\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(d);\r\n console.log(res.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 2) {\r\n console.log(2);\r\n console.log(`${1} ${2}`);\r\n continue;\r\n } else {\r\n let res = [],\r\n obj = {};\r\n res[0] = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (!obj[i]) {\r\n obj[i] = 1;\r\n res.push(i);\r\n let k = i * 2;\r\n while (k <= n) {\r\n obj[k] = 1;\r\n res.push(k);\r\n k = k * 2;\r\n }\r\n }\r\n }\r\n console.log(2);\r\n console.log(res.join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n\r\n for (let t = 0; t < testcases; t++) {\r\n const n = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const d = 2;\r\n\r\n const set = new Set();\r\n\r\n const res = [];\r\n\r\n for (let i = 2; i <= n; i++) {\r\n if (!set.has(i)) {\r\n for (let j = i; j <= n; j *= 2) {\r\n if (!set.has(j)) {\r\n res.push(j);\r\n set.add(j);\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(d);\r\n console.log(res.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n\r\n for (let t = 0; t < testcases; t++) {\r\n const n = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const d = 2;\r\n\r\n const set = new Set();\r\n\r\n const res = [];\r\n\r\n for (let i = 1; i <= n; i = i * 2) {\r\n res.push(i);\r\n set.add(i);\r\n }\r\n\r\n for (let i = 1; i <= parseInt(n / 2); i++) {\r\n if (!set.has(i)) {\r\n res.push(i);\r\n res.push(i * 2);\r\n set.add(i);\r\n set.add(i * 2);\r\n } else {\r\n set.add(i * 2);\r\n }\r\n }\r\n\r\n for (let i = parseInt(n / 2); i <= n; i++) {\r\n if (!set.has(i)) res.push(i);\r\n }\r\n\r\n console.log(d);\r\n console.log(res.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n\r\n for (let t = 0; t < testcases; t++) {\r\n const n = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const d = 2;\r\n\r\n const set = new Set();\r\n\r\n const res = [];\r\n\r\n for (let i = 1; i <= n; i = i * 2) {\r\n res.push(i);\r\n set.add(i);\r\n }\r\n\r\n for (let i = 1; i <= n; i++) {\r\n if (!set.has(i)) res.push(i);\r\n }\r\n\r\n console.log(d);\r\n console.log(res.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 2) {\r\n console.log(2);\r\n console.log(`${1} ${2}`);\r\n continue;\r\n } else {\r\n let res = [],\r\n obj = {};\r\n res[0] = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (!obj[i]) {\r\n obj[i] = 1;\r\n res.push(i);\r\n if (i * 2 <= n) {\r\n obj[i * 2] = 1;\r\n res.push(i * 2);\r\n }\r\n }\r\n }\r\n console.log(2);\r\n console.log(res.join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline();\r\n // var [a,b] = readline().split(' ').map((x) => parseInt(x));\r\n console.log(2);\r\n var ans = [], c = []\r\n for(var i=1;i<=n;i*=2) {\r\n ans.push(i);\r\n c[i] = true;\r\n }\r\n for(var i=3;i<=n;i++) {\r\n if(c[i] == undefined) ans.push(i)\r\n }\r\n console.log(ans.join(\" \"))\r\n}\r\n"}, {"source_code": "var n = +readline();\r\n\r\nwhile (n--) {\r\n\tvar t = +readline();\r\n\tprint(2);\r\n\tvar ans = 1;\r\n\tvar arrCheck = new Array(t + 1);\r\n\tvar mid = parseInt(t / 2);\r\n\tfor (var i = 1; i <= mid; i++) {\r\n\t\tvar ans = i;\r\n\t\twhile (ans <= t && arrCheck[ans] === undefined) {\r\n\t\t\twrite(ans + \" \");\r\n\t\t\tarrCheck[ans] = 1;\r\n\t\t\tans *= 2;\r\n\t\t}\r\n\t}\r\n\tif (t % 2) write(t + \" \");\r\n\tprint();\r\n}\r\n"}, {"source_code": "var n = +readline();\r\n\r\nwhile (n--) {\r\n\tvar t = +readline();\r\n\tprint(2);\r\n\tvar ans = 1;\r\n\tvar arrCheck = new Array(t + 1);\r\n\twhile (ans <= t) {\r\n\t\twrite(ans + \" \");\r\n\t\tarrCheck[ans] = 1;\r\n\t\tans *= 2;\r\n\t}\r\n\r\n\tfor (var i = 3; i <= t; i++) {\r\n\t\tif (arrCheck[i] === undefined) write(i + \" \");\r\n\t}\r\n\r\n\tprint();\r\n}\r\n"}], "src_uid": "3b9380ca571dbf3e24fc1b1c8b91790b"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k,z] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n let solve = (i, k, z) => {\n if(k < 0 || z < 0)\n return 0;\n\n if(i < 0 || i >= n)\n return 0;\n \n let right = a[i] + solve(i+1, k-1, z);\n let left = a[i] + solve(i-1, k-1, z-1);\n\n return Math.max(left, right);\n }\n\n console.log(solve(0, k, z));\n }\n}\n\nfunction C(){\n let t = parseInt(readline());\n\n while(t > 0){\n t--;\n let max = 0;\n let s = readline();\n\n for(let i = 0; i < 10; i++){\n for(let j = i; j < 10; j++){\n let pre = -1;\n let len = 0;\n for(let k = 0; k < s.length; k++){\n if(i === j){\n if(parseInt(s.charAt(k)) === i){\n len += 1;\n }\n }else{\n if(parseInt(s.charAt(k)) === i){\n if(pre !== i){\n len += 1;\n pre = i;\n }\n }else if(parseInt(s.charAt(k)) === j){\n if(pre != j){\n len += 1;\n pre = j;\n }\n }\n }\n }\n\n if(i !== j && len % 2 !== 0)\n len -= 1;\n \n max = Math.max(max, len);\n }\n }\n\n console.log(s.length - max);\n }\n}\n\nfunction main(){\n let [n,k] = ti(readline().split(' '));\n let w = new Array(n);\n let v = new Array(n);\n\n for(let i = 0; i < n; i++){\n let [x,y] = ti(readline().split(' '));\n w[i] = x;\n v[i] = y;\n }\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(100001);\n dp[i].fill(99999999999);\n }\n\n for(let i = 0; i < n; i++){\n for(let j = 0; j < 100001; j++){\n if(i === 0 || j === 0){\n if(i === 0 && j === 0)\n dp[i][j] = 0;\n else if(i === 0)\n dp[i][j] = v[0] === j ? w[0] : 99999999999;\n }else{\n dp[i][j] = dp[i-1][j];\n if(j >= v[i])\n dp[i][j] = Math.min(dp[i][j], w[i] + dp[i-1][j-v[i]]);\n }\n }\n }\n\n let max = 0;\n for(let i = 100000; i >= 0; i--){\n if(dp[n-1][i] <= k){\n max = i;\n break;\n }\n }\n\n console.log(max);\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let ans = 0;\n for (let i = 0; i < 10; i++) {\n for (let j = 0; j < 10; j++) {\n let count = 0;\n for (let k = 0; k < str.length; k++) {\n if (count % 2 === 0 && +str[k] === i) {\n count++;\n } else if (count % 2 !== 0 && +str[k] === j) {\n count++;\n }\n }\n if (i !== j && count % 2 !== 0) {\n count = count - 1;\n }\n ans = Math.max(ans, count);\n }\n }\n console.log(`${str.length - ans}`);\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let ans = 0;\n for (let i = 0; i < 10; i++) {\n for (let j = 0; j < 10; j++) {\n let count = 0;\n for (let k = 0; k < str.length; k++) {\n if (k % 2 === 0 && +str[k] === i) {\n count++;\n } else if (k % 2 !== 0 && +str[k] === j) {\n count++;\n }\n }\n if (i !== j) {\n count -= count % 2;\n ans = Math.max(ans, count);\n }\n }\n }\n console.log(`${str.length - ans}`);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let ans = 0;\n for (let i = 0; i < 10; i++) {\n for (let j = 0; j < 10; j++) {\n let count = 0;\n for (let k = 0; k < str.length; k++) {\n if (k % 2 === 0 && +str[k] === i) {\n count++;\n } else if (k % 2 !== 0 && +str[k] === j) {\n count++;\n }\n }\n if (i !== j) {\n count -= count % 2;\n }\n ans = Math.max(ans, count);\n }\n }\n console.log(`${str.length - ans}`);\n }\n}\n"}], "src_uid": "977db81b5c1d3725e384e8f093655172"} {"source_code": "const mineAllDays = (miners, diamonds) => {\n let res = 0;\n for (let i = 0; i < miners.length; i++) {\n res += Math.sqrt(miners[i] ** 2 + diamonds[i] ** 2);\n }\n return res;\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const miners = [];\n const diamonds = [];\n const n = readInt();\n for (let i = 0; i < 2 * n; i++) {\n const [x, y] = readListInt();\n if (x === 0) miners.push(Math.abs(y));\n else diamonds.push(Math.abs(x));\n }\n miners.sort((a, b) => a - b);\n diamonds.sort((a, b) => a - b);\n console.log(mineAllDays(miners, diamonds));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n\r\n var x = []\r\n var y = []\r\n for (let i = 0; i < 2 * n; i++) {\r\n var [xx, yy] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (xx === 0) y.push(yy)\r\n if (yy === 0) x.push(xx)\r\n }\r\n x = x.sort((a, b) => Math.abs(a) - Math.abs(b))\r\n y = y.sort((a, b) => Math.abs(a) - Math.abs(b))\r\n // console.log(x)\r\n // console.log(y)\r\n var sum = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += Math.sqrt(x[i] * x[i] + y[i] * y[i])\r\n }\r\n console.log(sum)\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = [];\r\n\t\tvar blist = [];\r\n\t\tfor(var j = 0; j < 2 * N; j++){\r\n\t\t\tvar x = nextInt();\r\n\t\t\tvar y = nextInt();\r\n\t\t\tif(x != 0){\r\n\t\t\t\tblist.push({\r\n\t\t\t\t\tx : x,\r\n\t\t\t\t\ty : y\r\n\t\t\t\t});\r\n\t\t\t}else{\r\n\t\t\t\talist.push({\r\n\t\t\t\t\tx : x,\r\n\t\t\t\t\ty : y\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn Math.abs(a.y) - Math.abs(b.y);\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn Math.abs(a.x) - Math.abs(b.x);\r\n\t\t});\r\n\t\tvar sum = 0;\r\n\t\t\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tsum += Math.sqrt(alist[j].y * alist[j].y + blist[j].x * blist[j].x);\r\n\t\t}\r\n\t\tmyout(sum);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let min = [],\r\n dia = [];\r\n for (let i = 0; i < n * 2; i++) {\r\n let k = iInpArr();\r\n if (k[0] === 0) min.push([k[0], Math.abs(k[1])]);\r\n else dia.push([Math.abs(k[0]), k[1]]);\r\n }\r\n min.sort((a, b) => a[1] - b[1]);\r\n dia.sort((a, b) => a[0] - b[0]);\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n let k = min[i][1] * min[i][1] + dia[i][0] * dia[i][0];\r\n sum += Math.sqrt(k);\r\n }\r\n console.log(sum + \"\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = [];\r\n\t\tvar blist = [];\r\n\t\tfor(var j = 0; j < 2 * N; j++){\r\n\t\t\tvar x = nextInt();\r\n\t\t\tvar y = nextInt();\r\n\t\t\tif(x != 0){\r\n\t\t\t\tblist.push({\r\n\t\t\t\t\tx : x,\r\n\t\t\t\t\ty : y\r\n\t\t\t\t});\r\n\t\t\t}else{\r\n\t\t\t\talist.push({\r\n\t\t\t\t\tx : x,\r\n\t\t\t\t\ty : y\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn Math.abs(a.y) - Math.abs(b.y);\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn Math.abs(a.x) - Math.abs(b.x);\r\n\t\t});\r\n\t\tvar sum = 0;\r\n\t\t\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tsum += Math.sqrt(alist[j].y * alist[j].y + blist[j].x * blist[j].x);\r\n\t\t}\r\n\t\tmyout(sum);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "ba27ac62b84705d80fa580567ab64c3b"} {"source_code": "// your code goes here\nvar t = parseInt(readline());\nfor (var x = 0; x < t; ++x) {\n\tvar n = parseInt(readline());\n\tvar a = readline().split(' ').map(x => parseInt(x));\n\tvar mx = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] > mx) {\n\t\t\tmx = a[i];\n\t\t}\n\t}\n\tvar ind = -2;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] == mx) {\n\t\t\tif (i > 0 && a[i - 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t} else if (i < n - 1 && a[i + 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tprint(ind + 1);\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\n\nwhile (t--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(function(x, index) {\n // print(\"index: \" + index + \" val: \" + x);\n return parseInt(x);\n });\n var same = 1;\n for (var i = 1; i < ar.length; ++i) if (ar[0] !== ar[i]) same = 0;\n if (same) {\n print(\"-1\");\n continue;\n }\n\n var ans = -1;\n var big = ar[0];\n\n for (var i = 1; i < ar.length; ++i) if (ar[i] > big) big = ar[i];\n\n for (var i = 0; i < ar.length; ++i) {\n if (i - 1 >= 0 && ar[i] === big && ar[i-1] < ar[i]) {\n ans = i + 1;\n break;\n }\n if (i + 1 < ar.length && ar[i] === big && ar[i+1] < ar[i]) {\n ans = i + 1;\n break;\n }\n }\n\n print(ans);\n\n // ar.forEach(function(val) {\n // print(val[0] + ' -> ' + val[1]);\n // });\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nlet mem = new Map();\nfunction query(arr){\n let max_i = 0, min_i = 0;\n for (let i=0; i arr[i] ? i : min_i;\n }\n if (max_i==min_i)\n return -1;\n for (let i=0; i+a);\n print(query(arr));\n }\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = [];\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line * 2;\n return;\n }\n\n data.push(line);\n \n if(lineNum - 1 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(data) { \n data.forEach((piranhas, i) => {\n if(i % 2 !== 0) {\n const splitted = piranhas.split(' ');\n const sorted = splitted.map((piranha, i) => [+piranha, i])\n .sort((a, b) => b[0] - a[0]);\n\n for(let i = 0; i < sorted.length && sorted[i][0] == sorted[0][0]; i++) {\n const cur = sorted[i][0];\n const left = splitted[sorted[i][1] - 1];\n const right = splitted[sorted[i][1] + 1];\n if(left < cur || right < cur) {\n console.log(sorted[i][1] + 1)\n return;\n }\n }\n\n console.log(-1)\n }\n })\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let [max, maxIndex, allSame] = [-Infinity, 0, true];\n\n for (let i = 1; i < len; i++) {\n const [curr, prev] = [arr[i], arr[i - 1]];\n const diff = Math.abs(curr - prev);\n if (diff !== 0) {\n allSame = false;\n if (curr > prev && curr > max) {\n max = curr;\n maxIndex = i;\n } else if (prev > curr && prev > max) {\n max = prev;\n maxIndex = i - 1;\n }\n }\n }\n if (allSame) console.log(-1);\n else {\n console.log(maxIndex + 1);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar isOK = true;\n\t\tvar max = 0;\n\t\tvar maxIndex = -1;\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tif(list[j] != list[j + 1]){\n\t\t\t\tisOK = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput[i] = -1;\n\t\t\tcontinue;\n\t\t}\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(j == 0){\n\t\t\t\tif(max < list[j] && list[j] != list[j + 1]){\n\t\t\t\t\tmax = list[j];\n\t\t\t\t\tmaxIndex = j + 1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(j == N - 1){\n\t\t\t\tif(max < list[j] && list[j] != list[j - 1]){\n\t\t\t\t\tmax = list[j];\n\t\t\t\t\tmaxIndex = j + 1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif((list[j] != list[j + 1] || list[j] != list[j - 1]) && max < list[j]){\n\t\t\t\tmax = list[j];\n\t\t\t\tmaxIndex = j + 1;\n\t\t\t}\n\t\t}\n\t\toutput[i] = maxIndex;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim();\n // const n = data[i] * 1;\n // const k = a[1];\n const s = data[i + 1].trim().split(' ').map(Number);\n // s.sort((a, b) => b - a);\n let idx = 0;\n let max = 0;\n let obj = {};\n \n for (let j = 0; j < s.length; j += 1) {\n if (obj[s[j]]) obj[s[j]].push(j);\n else obj[s[j]] = [j];\n if (s[j] > max) {\n max = s[j];\n idx = j;\n }\n }\n // console.log(obj, obj[max]);\n \n let j = 0;\n idx = -1\n // console.log(idx, 'idx', max)\n for (; j < obj[max].length; j += 1) {\n let x = obj[max][j];\n if (s[x + 1] && s[x + 1] < s[x]) {\n idx = x + 1;\n // console.log(j,'j');\n break;\n \n } else if (s[x - 1] && s[x - 1] < s[x]) {\n idx = x + 1;\n // console.log(j,'ej');\n break;\n }\n }\n \n console.log(idx);\n i += 2;\n }\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return i=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),u.default.writeFileSync(\"output.txt\",l),console.log(l),void(u.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{i=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return i=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),u.default.writeFileSync(\"output.txt\",l),console.log(l),void(u.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{i=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "var t = parseInt(readline());\n\nwhile (t--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(function(x, index) {\n // print(\"index: \" + index + \" val: \" + x);\n return [parseInt(x), index + 1];\n });\n var same = 1;\n for (var i = 1; i < ar.length; ++i) if (ar[0][0] !== ar[i][0]) same = 0;\n if (same) {\n print(\"-1\");\n continue;\n }\n\n ar.sort(function(v1, v2) {\n if (v1[0] < v2[0]) return 1;\n return -1;\n });\n\n print(ar[0][1]);\n\n // ar.forEach(function(val) {\n // print(val[0] + ' -> ' + val[1]);\n // });\n}\n"}, {"source_code": "// your code goes here\nvar t = +readline();\nfor (var x = 0; x < t; ++x) {\n\tvar n = +readline();\n\tvar a = readline().split(' ');\n\tvar mx = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] > mx) {\n\t\t\tmx = a[i];\n\t\t}\n\t}\n\tvar ind = -2;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] == mx) {\n\t\t\tif (i > 0 && a[i - 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t} else if (i < n - 1 && a[i + 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tprint(ind + 1);\n}"}, {"source_code": "// your code goes here\nvar t = parseInt(readline());\nfor (var x = 0; x < t; ++x) {\n\tvar n = parseInt(readline());\n\tvar a = readline().split(' ').map(x => parseInt(x));\n\tvar mx = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] > mx) {\n\t\t\tmx = a[i];\n\t\t}\n\t}\n\tprint(mx);\n\tvar ind = -2;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (a[i] == mx) {\n\t\t\tif (i > 0 && a[i - 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t} else if (i < n - 1 && a[i + 1] < mx) {\n\t\t\t\tind = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tprint(ind + 1);\n}"}], "src_uid": "5598d5954fa3e3cecedb413033259760"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n//const util = require('util');\r\n//process.stdin.resume();\r\n//process.stdin.setEncoding('ascii');\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\n// function printf(...args: [...T]) {\r\n// process.stdout.write(util.format(...args));\r\n// // console.log(...args);\r\n// }\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet k;\r\nlet adjList;\r\nlet ld;\r\nfunction diam() {\r\n let dist = af(n + 1).fill(INIT);\r\n dist[1] = 0;\r\n let q = [1];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n q.push(v);\r\n }\r\n }\r\n }\r\n let s = INIT;\r\n let mx = INIT;\r\n for (let u = 1; u <= n; u++) {\r\n if (mx < dist[u]) {\r\n mx = dist[u];\r\n s = u;\r\n }\r\n }\r\n check(s != INIT);\r\n const p = af(n + 1).fill(INIT);\r\n dist.fill(INIT);\r\n dist[s] = 0;\r\n q = [s];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n p[v] = u;\r\n q.push(v);\r\n }\r\n }\r\n }\r\n let t = INIT;\r\n mx = INIT;\r\n for (let u = 1; u <= n; u++) {\r\n if (mx < dist[u]) {\r\n mx = dist[u];\r\n t = u;\r\n }\r\n }\r\n check(t != INIT);\r\n const rv = [t];\r\n for (let i = 0; i < mx; i++) {\r\n rv.push(p[t]);\r\n t = p[t];\r\n }\r\n return rv;\r\n}\r\nfunction getLd(s, ex) {\r\n const dist = af(n + 1).fill(INIT);\r\n const p = af(n + 1).fill(INIT);\r\n if (ex != INIT) {\r\n dist[ex] = 0;\r\n }\r\n dist[s] = 0;\r\n const q = [s];\r\n const topo = [];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n p[v] = u;\r\n q.push(v);\r\n }\r\n }\r\n topo.push(u);\r\n }\r\n for (let i = topo.length - 1; i > 0; i--) {\r\n let u = topo[i];\r\n ld[p[u]] = Math.max(ld[p[u]], ld[u] + 1);\r\n }\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n adjList = Array.from({ length: n + 1 });\r\n for (let i = 0; i <= n; i++) {\r\n adjList[i] = [];\r\n }\r\n for (let i = 0; i + 1 < n; i++) {\r\n let u = nextInt();\r\n let v = nextInt();\r\n adjList[u].push(v);\r\n adjList[v].push(u);\r\n }\r\n // for (let u = 1; u <= n; u++) {\r\n // for (let v of adjList[u]) {\r\n // if (u > v) continue;\r\n // console.log('u %d v %d', u, v);\r\n // }\r\n // }\r\n const path = diam();\r\n let pathlen = path.length;\r\n ld = af(n + 1).fill(0);\r\n if ((pathlen % 2) == 0) {\r\n let r1 = path[Math.trunc(pathlen / 2)];\r\n let r2 = path[Math.trunc(pathlen / 2) - 1];\r\n getLd(r1, r2);\r\n getLd(r2, r1);\r\n }\r\n else {\r\n let root = path[Math.trunc(pathlen / 2)];\r\n getLd(root, INIT);\r\n }\r\n let ans = 0;\r\n for (let u = 1; u <= n; u++) {\r\n if (ld[u] >= k) {\r\n ans++;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n // if (t === 6) {\n // console.log([7, 0, 0, 3, 1, 2].join('\\n'))\n // return\n // }\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, edges))\n // output[i] = solve(n, k, edges)\n }\n // console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, edges) {\n if (n === 1) return 0\n // console.log(edges)\n const adj = {}\n const d = []\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n d[a] = (d[a] || 0) + 1\n d[b] = (d[b] || 0) + 1\n })\n\n let q = []\n for (let u = 1; u <= n; u++) {\n if (d[u] === 1) q.push(u)\n }\n// console.log(d)\n let ans = n\n const visited = {}\n for (let i = 0; i < k; i++) {\n const next = []\n for (let j = 0; j < q.length; j++) {\n const u = q[j]\n if (visited[u]) continue\n visited[u] = 1\n ans--\n\n (adj[u] || []).forEach(v => {\n if (!visited[v] && --d[v] === 1) {\n next.push(v)\n }\n })\n }\n q = next\n if (!q.length) break\n }\n return ans\n}\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n // console.log(...args);\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet k;\r\nlet adjList;\r\nlet ld;\r\nfunction diam() {\r\n let dist = af(n + 1).fill(INIT);\r\n dist[1] = 0;\r\n let q = [1];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n q.push(v);\r\n }\r\n }\r\n }\r\n let s = INIT;\r\n let mx = INIT;\r\n for (let u = 1; u <= n; u++) {\r\n if (mx < dist[u]) {\r\n mx = dist[u];\r\n s = u;\r\n }\r\n }\r\n check(s != INIT);\r\n const p = af(n + 1).fill(INIT);\r\n dist.fill(INIT);\r\n dist[s] = 0;\r\n q = [s];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n p[v] = u;\r\n q.push(v);\r\n }\r\n }\r\n }\r\n let t = INIT;\r\n mx = INIT;\r\n for (let u = 1; u <= n; u++) {\r\n if (mx < dist[u]) {\r\n mx = dist[u];\r\n t = u;\r\n }\r\n }\r\n check(t != INIT);\r\n const rv = [t];\r\n for (let i = 0; i < mx; i++) {\r\n rv.push(p[t]);\r\n t = p[t];\r\n }\r\n return rv;\r\n}\r\nfunction getLd(s, ex) {\r\n const dist = af(n + 1).fill(INIT);\r\n const p = af(n + 1).fill(INIT);\r\n if (ex != INIT) {\r\n dist[ex] = 0;\r\n }\r\n dist[s] = 0;\r\n const q = [s];\r\n const topo = [];\r\n for (let i = 0; i < q.length; i++) {\r\n let u = q[i];\r\n for (let v of adjList[u]) {\r\n if (dist[v] == INIT) {\r\n dist[v] = dist[u] + 1;\r\n p[v] = u;\r\n q.push(v);\r\n }\r\n }\r\n topo.push(u);\r\n }\r\n for (let i = topo.length - 1; i > 0; i--) {\r\n let u = topo[i];\r\n ld[p[u]] = Math.max(ld[p[u]], ld[u] + 1);\r\n }\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n adjList = Array.from({ length: n + 1 });\r\n for (let i = 0; i <= n; i++) {\r\n adjList[i] = [];\r\n }\r\n for (let i = 0; i + 1 < n; i++) {\r\n let u = nextInt();\r\n let v = nextInt();\r\n adjList[u].push(v);\r\n adjList[v].push(u);\r\n }\r\n // for (let u = 1; u <= n; u++) {\r\n // for (let v of adjList[u]) {\r\n // if (u > v) continue;\r\n // console.log('u %d v %d', u, v);\r\n // }\r\n // }\r\n const path = diam();\r\n let pathlen = path.length;\r\n ld = af(n + 1).fill(0);\r\n if ((pathlen % 2) == 0) {\r\n let r1 = path[Math.trunc(pathlen / 2)];\r\n let r2 = path[Math.trunc(pathlen / 2) - 1];\r\n getLd(r1, r2);\r\n getLd(r2, r1);\r\n }\r\n else {\r\n let root = path[Math.trunc(pathlen / 2)];\r\n getLd(root, INIT);\r\n }\r\n let ans = 0;\r\n for (let u = 1; u <= n; u++) {\r\n if (ld[u] >= k) {\r\n ans++;\r\n }\r\n }\r\n printf(\"%d\\n\", ans);\r\n }\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nlet n, k, g, rem, layer;\r\n\r\n//q.push(x)\r\n//q.shift() -> remove and return the leftmost element\r\n//q.peek() -> return the leftmost element\r\n//q.size()\r\n\r\nclass Queue {\r\n\tconstructor () {\r\n\t\tthis.a = [];\r\n\t\tthis.p = 0;\r\n\t}\r\n\r\n\tpush = (x) => this.a.push(x);\r\n\tshift = () => this.size() ? this.a[this.p++] : -1;\r\n\tpeek = () => this.size() ? this.a[this.p] : -1;\r\n\tsize = () => this.a.length - this.p;\r\n}\r\n\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\t[n, k] = rna();\r\n\t\tg = Array.from(Array(n), _ => []);\r\n\t\trem = Array(n).fill(0);\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tlet [u, v] = rna(); u--, v--;\r\n\t\t\tg[u].push(v);\r\n\t\t\tg[v].push(u);\r\n\t\t\trem[u]++;\r\n\t\t\trem[v]++;\r\n\t\t}\r\n\t\tlayer = Array(n).fill(1);\r\n\r\n\t\tconst q = new Queue();\r\n\t\tfor (let i = 0; i < n; i++) if (rem[i] == 1) q.push(i);\r\n\t\twhile (q.size()) {\r\n\t\t\tconst u = q.shift();\r\n\t\t\tfor (const v of g[u]) {\r\n\t\t\t\trem[v]--;\r\n\t\t\t\tif (rem[v] == 1) {\r\n\t\t\t\t\tlayer[v] = layer[u] + 1;\r\n\t\t\t\t\tq.push(v);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) ans += layer[i] > k;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n // if (t === 6) {\r\n // console.log([7, 0, 0, 3, 1, 2].join('\\n'))\r\n // return\r\n // }\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const [n, k] = lines[l++].trim().split(' ').map(Number)\r\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\r\n l += n - 1\r\n console.log(solve(n, k, edges))\r\n // output[i] = solve(n, k, edges)\r\n }\r\n // console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, k, edges) {\r\n if (n === 1) return 0\r\n // console.log(edges)\r\n const adj = {}\r\n edges.forEach(([a, b]) => {\r\n adj[a] = adj[a] || []\r\n adj[b] = adj[b] || []\r\n adj[a].push(b)\r\n adj[b].push(a)\r\n })\r\n// return\r\n let u = 1\r\n // let p = -1\r\n // while (1) {\r\n // const has = (adj[u] || []).some(v => {\r\n // if (v !== p) {\r\n // p = u\r\n // u = v\r\n // return true\r\n // }\r\n // })\r\n // if (!has) break\r\n // }\r\n // return\r\n const [hs, haschild] = dfs(adj, u, {}, k)\r\n// console.log(u, hs, haschild)\r\n return dfs2(adj, u, {}, k, hs, haschild)\r\n // let ans = n\r\n // for (let i = 1; i <= n; i++) {\r\n // if (removed[i]) ans--\r\n // }\r\n // return ans\r\n}\r\nfunction dfs(adj, r, visited, k) {\r\n const stack = [[r, 0, -1]]\r\n const hs = []\r\n const haschild = []\r\n while (stack.length) {\r\n const [u, i, p] = stack[stack.length - 1]\r\n // visited[u] = 1\r\n\r\n const nb = adj[u] || []\r\n if (!i) {\r\n // first visited\r\n }\r\n if (i < nb.length) {\r\n stack[stack.length - 1][1]++\r\n const v = nb[i]\r\n // if (!visited[v]) { // has circle\r\n if (v !== p) {\r\n stack.push([v, 0, u])\r\n }\r\n } else {\r\n // last visited\r\n hs[u] = 1\r\n haschild[u] = 0\r\n ;(adj[u] || []).forEach(v => {\r\n if (v !== p) {\r\n hs[u] = Math.max(hs[u], hs[v] + 1)\r\n if (hs[v] >= k) haschild[u]++\r\n }\r\n })\r\n // if (hs[u] <= k) removed[u] = 1\r\n stack.pop()\r\n }\r\n }\r\n return [hs, haschild]\r\n}\r\nfunction dfs2(adj, r, visited, k, hs, haschild) {\r\n const stack = [[r, 0, -1]]\r\n let count = 0\r\n while (stack.length) {\r\n const [u, i, p] = stack[stack.length - 1]\r\n // visited[u] = 1\r\n\r\n const nb = adj[u] || []\r\n if (!i) {\r\n // first visited\r\n const rh = hs[r] - hs[u] + 1\r\n if (hs[u] > k && (rh > k || (rh === k && haschild[u] > 1))) {\r\n // console.log('left', u)\r\n count++\r\n }\r\n }\r\n if (i < nb.length) {\r\n stack[stack.length - 1][1]++\r\n const v = nb[i]\r\n // if (!visited[v]) { // has circle\r\n if (v !== p) {\r\n stack.push([v, 0, u])\r\n }\r\n } else {\r\n // last visited\r\n stack.pop()\r\n }\r\n }\r\n return count\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n // if (t === 6) {\n // console.log([7, 0, 0, 3, 1, 2].join('\\n'))\n // return\n // }\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, edges))\n // output[i] = solve(n, k, edges)\n }\n // console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, edges) {\n if (n === 1) return 0\n // console.log(edges)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n// return\n let u = 1\n // let p = -1\n // while (1) {\n // const has = (adj[u] || []).some(v => {\n // if (v !== p) {\n // p = u\n // u = v\n // return true\n // }\n // })\n // if (!has) break\n // }\n // return\n const [hs, haschild] = dfs(adj, u, {}, k)\n// console.log(u, hs, haschild)\n return dfs2(adj, u, {}, k, hs, haschild)\n // let ans = n\n // for (let i = 1; i <= n; i++) {\n // if (removed[i]) ans--\n // }\n // return ans\n}\nfunction dfs(adj, r, visited, k) {\n const stack = [[r, 0, -1]]\n const hs = []\n const haschild = []\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n hs[u] = 1\n haschild[u] = 0\n ;(adj[u] || []).forEach(v => {\n if (v !== p) {\n hs[u] = Math.max(hs[u], hs[v] + 1)\n if (hs[v] >= k) haschild[u]++\n }\n })\n // if (hs[u] <= k) removed[u] = 1\n stack.pop()\n }\n }\n return [hs, haschild]\n}\nfunction dfs2(adj, r, visited, k, hs, haschild) {\n const stack = [[r, 0, -1]]\n let count = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n const rh = hs[r] - hs[u] + 1\n if (hs[u] > k && (rh > k || (haschild[u] > 1))) {\n // console.log('left', u)\n count++\n }\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return count\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n // if (t === 6) {\n // console.log([7, 0, 0, 3, 1, 2].join('\\n'))\n // return\n // }\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, edges))\n // output[i] = solve(n, k, edges)\n }\n // console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, edges) {\n if (n === 1) return 0\n // console.log(edges)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n// return\n let u = 1\n // let p = -1\n // while (1) {\n // const has = (adj[u] || []).some(v => {\n // if (v !== p) {\n // p = u\n // u = v\n // return true\n // }\n // })\n // if (!has) break\n // }\n // return\n const [hs, haschild] = dfs(adj, u, {}, k)\n// console.log(u, hs, haschild)\n return dfs2(adj, u, {}, k, hs, haschild)\n // let ans = n\n // for (let i = 1; i <= n; i++) {\n // if (removed[i]) ans--\n // }\n // return ans\n}\nfunction dfs(adj, r, visited, k) {\n const stack = [[r, 0, -1]]\n const hs = []\n const haschild = []\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n hs[u] = 1\n haschild[u] = 0\n ;(adj[u] || []).forEach(v => {\n if (v !== p) {\n hs[u] = Math.max(hs[u], hs[v] + 1)\n if (hs[v] >= k) haschild[u]++\n }\n })\n // if (hs[u] <= k) removed[u] = 1\n stack.pop()\n }\n }\n return [hs, haschild]\n}\nfunction dfs2(adj, r, visited, k, hs, haschild) {\n const stack = [[r, 0, -1]]\n let count = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n const rh = hs[r] - hs[u] + 1\n if (hs[u] > k && (rh > k || (rh === k && haschild[u] > 1))) {\n // console.log('left', u)\n count++\n }\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return count\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n // if (t === 6) {\n // console.log([7, 0, 0, 3, 1, 2].join('\\n'))\n // return\n // }\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, edges))\n // output[i] = solve(n, k, edges)\n }\n // console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, edges) {\n if (n === 1) return k < 1 ? 1 : 0\n // console.log(edges)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n// return\n let u = 1\n let p = -1\n while (1) {\n const has = adj[u].some(v => {\n if (v !== p) {\n p = u\n u = v\n return true\n }\n })\n if (!has) break\n }\n // return\n const hs = dfs(adj, u, {})\n// console.log(u, hs)\n return dfs2(adj, u, {}, hs, k)\n}\nfunction dfs(adj, r, visited) {\n const stack = [[r, 0, -1]]\n const hs = []\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n hs[u] = 1\n ;(adj[u] || []).forEach(v => {\n if (v !== p) hs[u] = Math.max(hs[u], hs[v] + 1)\n })\n stack.pop()\n }\n }\n return hs\n}\nfunction dfs2(adj, r, visited, hs, k) {\n const stack = [[r, 0, -1]]\n let count = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n if (hs[u] > k && hs[r] - hs[u] + 1 > k) {\n count++\n }\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return count\n}\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nlet n, k;\r\nlet g;\r\nlet mp = [];\r\nlet ans = 0;\r\n\r\nconst key = (x, y) => x + ',' + y;\r\n\r\nfunction dfs (u=0, p=-1) {\r\n\tlet mx = 0;\r\n\tfor (const c of g[u]) {\r\n\t\tif (c == p) continue;\r\n\t\tconst tm = dfs(c, u);\r\n\t\tmp[key(c, u)] = tm + 1;\r\n\t\t//console.log('***', c, u, mp[key(c, u)]);\r\n\t\tmx = Math.max(mx, tm);\r\n\t}\r\n\treturn mx + 1;\r\n}\r\n\r\nfunction dfs2 (u=0, p=-1, inCost=0) {\r\n\tmp[key(p, u)] = inCost;\r\n\r\n\tconst cur = [];\r\n\tcur.push(1);\r\n\tfor (const c of g[u]) {\r\n\t\tcur.push(mp[key(c, u)]);\r\n\t\t//console.log(c, u, mp[key(c, u)]);\r\n\t}\r\n\tcur.sort((x, y) => y - x);\r\n\r\n\t//console.log({u, cur, k})\r\n\tif (cur[1] <= k) ans--;\r\n\r\n\tfor (const c of g[u]) {\r\n\t\tif (c == p) continue;\r\n\t\tconst outCost = mp[key(c, u)] == cur[0] ? cur[1] : cur[0];\r\n\t\tdfs2(c, u, outCost + 1);\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\t[n, k] = rna();\r\n\t\tg = Array.from(Array(n), _ => []);\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tlet [u, v] = rna(); u--, v--;\r\n\t\t\tg[u].push(v);\r\n\t\t\tg[v].push(u);\r\n\t\t}\r\n\r\n\t\tmp = [];\r\n\t\tans = n;\r\n\t\tdfs();\r\n\t\tdfs2();\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "07ac198c1086323517540ecd0669eb4c"} {"source_code": "function solve(input) {\r\n input.forEach(e => {\r\n const dots = e.map(data => data.split(' '));\r\n // console.log(dots)\r\n\r\n const setDotsY = new Set(dots.map(data => data[1]));\r\n const arrDotsY = [...setDotsY];\r\n if (arrDotsY.length === 2) {\r\n const a = countObj(dots.map(data => data[1]), arrDotsY[0]);\r\n const b = countObj(dots.map(data => data[1]), arrDotsY[1]);\r\n if (a > b) {\r\n if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) {\r\n const x = dots.filter(data => data[1] === arrDotsY[0])\r\n console.log(Math.abs(x[0][0] - x[1][0]))\r\n } else console.log(0);\r\n } else {\r\n if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) {\r\n const x = dots.filter(data => data[1] === arrDotsY[1])\r\n console.log(Math.abs(x[0][0] - x[1][0]))\r\n }\r\n else console.log(0);\r\n }\r\n } else if (arrDotsY.length === 1) {\r\n console.log(0)\r\n } else {\r\n console.log(0);\r\n }\r\n });\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 3\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n for (let i = 0; i < 3; i++) {\r\n const x = a[i];\r\n for (let j = i + 1; j < 3; j++) {\r\n const y = a[j],\r\n z = a.find((_, k) => k !== i && k !== j);\r\n if (x[1] === y[1] && x[1] !== 0 && z[1] < x[1]) return Math.abs(x[0] - y[0]);\r\n }\r\n }\r\n return 0;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = [];\r\n let tmp = 3;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [x1, y1] = readline().split(' ').map(Number);\r\n let [x2, y2] = readline().split(' ').map(Number);\r\n let [x3, y3] = readline().split(' ').map(Number);\r\n\r\n if (y1 !== y2 && y1 !== y3 && y2 !== y3) {\r\n output(0);\r\n } else if (y1 === y2 && y3 < y1) {\r\n output(Math.abs(x1 - x2));\r\n } else if (y1 === y3 && y2 < y1) {\r\n output(Math.abs(x1 - x3));\r\n } else if (y2 === y3 && y1 < y2) {\r\n output(Math.abs(x2 - x3));\r\n } else {\r\n output(0);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n \n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nlet sqr = x=>x*x;\nlet dist = (p1, p2)=>{\n return Math.sqrt(sqr(p1.x-p2.x)+sqr(p1.y-p2.y));\n};\n \nconst calc = (arr)=>{\n let ans = 0;\n for (let i=0; i<3; i++){\n for (let j=i+1; j<3; j++){\n if (arr[i].y==arr[j].y){\n for (let k=0; k<3; k++){\n if (k==i || k==j) continue;\n if (arr[k].y {\r\n const dots = e.map(data => data.split(' '));\r\n // console.log(dots)\r\n\r\n const setDotsY = new Set(dots.map(data => data[1]));\r\n const arrDotsY = [...setDotsY];\r\n if (arrDotsY.length === 2) {\r\n const a = countObj(dots.map(data => data[1]), arrDotsY[0]);\r\n const b = countObj(dots.map(data => data[1]), arrDotsY[1]);\r\n if (a > b) {\r\n if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) console.log(arrDotsY[0])\r\n else console.log(0);\r\n } else {\r\n if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) console.log(arrDotsY[1])\r\n else console.log(0);\r\n }\r\n } else if (arrDotsY.length === 1) {\r\n console.log(0)\r\n } else {\r\n console.log(0);\r\n }\r\n });\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 3\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "function solve(input) {\r\n input.forEach(e => {\r\n const dots = e.map(data => data.split(' '));\r\n // console.log(dots)\r\n\r\n const setDotsY = new Set(dots.map(data => data[1]));\r\n const arrDotsY = [...setDotsY];\r\n if (arrDotsY.length === 2) {\r\n const a = countObj(dots.map(data => data[1]), arrDotsY[0]);\r\n const b = countObj(dots.map(data => data[1]), arrDotsY[1]);\r\n if (a > b) {\r\n if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) console.log(arrDotsY[0])\r\n else console.log(0);\r\n } else {\r\n if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) console.log(arrDotsY[1])\r\n else console.log(0);\r\n }\r\n } else if (arrDotsY.length === 1) {\r\n console.log(arrDotsY[0])\r\n } else {\r\n console.log(0);\r\n }\r\n });\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 3\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "function solve(input) {\r\n input.forEach(e => {\r\n const dots = e.map(data => data.split(' '));\r\n // console.log(dots)\r\n\r\n const setDotsY = new Set(dots.map(data => data[1]));\r\n const arrDotsY = [...setDotsY];\r\n if (arrDotsY.length === 2) {\r\n const a = countObj(dots.map(data => data[1]), arrDotsY[0]);\r\n const b = countObj(dots.map(data => data[1]), arrDotsY[1]);\r\n if (a > b) {\r\n console.log(arrDotsY[0])\r\n } else {\r\n console.log(arrDotsY[1])\r\n }\r\n } else if (arrDotsY.length === 1) {\r\n console.log(arrDotsY[0])\r\n } else {\r\n console.log(0);\r\n }\r\n });\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 3\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n for (let i = 0; i < 3; i++) {\r\n const x = a[i];\r\n for (let j = i + 1; j < 3; j++) {\r\n const y = a[j];\r\n if (x[1] === y[1] && x[1] !== 0) return Math.abs(x[0] - y[0]);\r\n }\r\n }\r\n return 0;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = [];\r\n let tmp = 3;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "9f019c3898f27d687c5b3498586644e8"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet counter=0, N\n\nrl.on('line', (input) => {\n if(counter==0){\n N=parseInt(input);\n counter++;\n }\n else\n {\n let ans=\"NO\", helper=\"\";\n for(let i=0; i 1 ? console.log('YES\\n' + r[0] + r[1]) : console.log('NO');\n});"}, {"source_code": "var length = readline();\nvar text = readline();\n var answer = \"\";\n for (var i = 0; i < length - 1; i ++) {\n var firstChar = text.charAt(i);\n var secondChar = text.charAt(i + 1);\n \n if (firstChar != secondChar) {\n answer = firstChar + secondChar;\n break;\n }\n }\n \n if (answer === \"\") { \n write(\"NO\");\n } else {\n write(\"YES\\n\");\n write(answer);\n }\n"}, {"source_code": "readline();\nvar str = readline(), answer;\nfor(var i = 1; i < str.length; i++) {\n if(str[i] !== str[i-1]) {\n answer = str[i-1] + str[i];\n break;\n }\n}\n\nif(answer) {\n print('YES');\n print(answer);\n} else {\n print('NO');\n}"}], "negative_code": [{"source_code": "process.stdin.on('data', function(chunk){\n\tvar lns = chunk.toString().replace(/\\r/g, \"\").split(/\\n/),r;\n\t(r = lns[1].match(/(.)(?!\\1)(?!$)/g)) ? console.log('YES\\n' + r[1] + r[2]) : console.log('NO');\n});"}, {"source_code": "var length = readline();\nvar text = readline();\nvar charStartIndex = 97;\nvar charIndexArray = [];\n\nfor (var i = 0; i < length; i ++) {\n var charCode = text.charAt(i).charCodeAt(0);\n if (charIndexArray[charCode - charStartIndex] === undefined) {\n charIndexArray[charCode - charStartIndex] = 1; \n } else {\n charIndexArray[charCode - charStartIndex] += 1; \n }\n}\n\nvar answer = \"\";\nfor (var i = 0; i < charIndexArray.length; i ++) { \n if (charIndexArray[i] <= charIndexArray.length / 2) { \n answer = String.fromCharCode(charIndexArray[i] + 97);\n break;\n }\n}\n\nif (answer === \"\") { \n write(\"NO\");\n} else {\n write(\"YES\");\n write(answer);\n}\n"}, {"source_code": "var length = readline();\nvar text = readline();\nvar charStartIndex = 97;\nvar charIndexArray = [];\n\nfor (var i = 0; i < length; i ++) {\n var charCode = text.charAt(i).charCodeAt(0);\n if (charIndexArray[charCode - charStartIndex] === undefined) {\n charIndexArray[charCode - charStartIndex] = 1; \n } else {\n charIndexArray[charCode - charStartIndex] += 1; \n }\n}\n\nvar answer = \"\";\nfor (var i = 0; i < charIndexArray.length; i ++) { \n if (charIndexArray[i] <= charIndexArray.length / 2) { \n answer = String.fromCharCode(charIndexArray[i] + 97);\n break;\n }\n}\n\nif (answer === \"\") { \n write(\"NO\");\n} else {\n write(\"YES\\n\");\n write(answer);\n}\n"}, {"source_code": "var length = readline();\nvar text = readline();\nvar charStartIndex = 97;\nvar charIndexArray = [];\n\nfor (var i = 0; i < length; i ++) {\n var charCode = text.charAt(i).charCodeAt(0);\n if (charIndexArray[charCode - charStartIndex] === undefined) {\n charIndexArray[charCode - charStartIndex] = 1; \n } else {\n charIndexArray[charCode - charStartIndex] += 1; \n }\n}\n\nfor (var i = 0; i < charIndexArray.length; i ++) { \n if (charIndexArray[i] <= charIndexArray.length / 2) { \n write(\"YES\");\n write(String.fromCharCode(charIndexArray[i] + 97));\n }\n}\n\nwrite(\"NO\");"}], "src_uid": "ce4443581d4ee12db6607695cd567070"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nconst gcd = (a, b) => (b ? gcd(b, a % b) : a);\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a } = testCase;\n // console.log(n, a);\n let g = a[0];\n for (let i = 1; i < n; i++) g = gcd(g, a[i]);\n\n if (g == 1) {\n console.log(0);\n return;\n }\n\n for (let i = 0; i < n; i++) {\n a[i] = gcd(g, i + 1);\n }\n\n let result = Infinity;\n\n const check = (gg, ind, val) => {\n // console.log(\"check\", gg, ind, val);\n if (gg == 1) {\n if (val < result) result = val;\n return;\n }\n if (ind == 0) return;\n\n check(gg, ind - 1, val);\n check(gcd(gg, a[ind - 1]), ind - 1, val + n - ind + 1);\n };\n\n check(g, n, 0);\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var allGcd = a[0];\r\n for (var i = 1; i < n; i++) {\r\n allGcd = gcd(allGcd, a[i]);\r\n }\r\n if (allGcd === 1) {\r\n write(0);\r\n return;\r\n }\r\n if (gcd(allGcd, n) === 1) {\r\n write(1);\r\n return;\r\n }\r\n if (gcd(allGcd, n - 1) === 1) {\r\n write(2);\r\n return;\r\n }\r\n write(3);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nconst gcd = (a, b) => (b ? gcd(b, a % b) : a);\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a } = testCase;\n // console.log(n, a);\n\n let g = a[0];\n for (let i = 1; i < n; i++) g = gcd(g, a[i]);\n\n // console.log(\"gcd\", g);\n\n let result = 0;\n let i = n;\n while (g != 1) {\n // console.log(\"while\", i);\n const gg = gcd(g, i);\n if (gg != g) {\n // console.log(\"Found\", g, gg, i, n, n - i + 1);\n g = gg;\n result += n - i + 1;\n }\n i--;\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "ff3216bcb009cb963d7e734ceb0e9722"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ones = 0, zeros = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tones += a[i] == 1;\r\n\t\t\tzeros += a[i] == 0;\r\n\t\t}\r\n\r\n\t\tconst ans = BigInt(ones) << BigInt(zeros);\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let c0 = 0\n let c1 = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) c0++\n if (arr[i] === 1) c1++\n }\n let ans = BigInt(c1)\n for (let i = 0; i < c0; i++) {\n ans = ans * 2n\n }\n return ans.toString()\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ones = 0, zeros = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tones += a[i] == 1;\r\n\t\t\tzeros += a[i] == 0;\r\n\t\t}\r\n\r\n\t\tconst ans = BigInt(ones)*1n< dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ones = 0, zeros = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tones += a[i] == 1;\r\n\t\t\tzeros += a[i] == 0;\r\n\t\t}\r\n\r\n\t\tconst ans = BigInt(ones)*2n**BigInt(zeros);\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function solve() {\r\n read();\r\n let c1 = 0n;\r\n let c0 = 0n;\r\n readArray((value) => {\r\n if (value === '0') {\r\n c0 += 1n;\r\n }\r\n if (value === '1') {\r\n c1 += 1n;\r\n }\r\n });\r\n write(c1 * (1n << c0));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ones = 0, zeros = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tones += a[i] == 1;\r\n\t\t\tzeros += a[i] == 0;\r\n\t\t}\r\n\r\n\t\tconst ans = ones*2**zeros;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function solve() {\r\n read();\r\n let c1 = 0n;\r\n let c0 = 0n;\r\n readArray((value) => {\r\n if (value === '0') {\r\n c0 += 1n;\r\n }\r\n if (value === '1') {\r\n c1 += 1n;\r\n }\r\n });\r\n const d = c0 === 0n ? 1n : (c0 << 1n);\r\n write(c1 * d);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let c0 = 0\n let c1 = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) c0++\n if (arr[i] === 1) c1++\n }\n return c1 * Math.pow(2, c0)\n}\n"}], "src_uid": "d786585fee251ebfd5c3e8d8b0425791"} {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nvar accMatrix = [];\nvar accPath = [];\nvar path = \"\";\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n }\n accMatrix[0][0] = factorize(prime, matrix[0][0]);\n accPath[0][0] = \"\";\n // print('accMatrix[0][0]', accMatrix[0][0])\n // print('accPath[0][0]', accPath[0][0])\n\n for (column = 1; column < size; column++) {\n accMatrix[0][column] = accMatrix[0][column - 1] + factorize(prime, matrix[0][column]);\n accPath[0][column] = \"R\";\n accMatrix[column][0] = accMatrix[column - 1][0] + factorize(prime, matrix[column][0]);\n accPath[column][0] = \"D\";\n }\n\n for (column = 1; column < size; column++) for (row = 1; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n\n }\n \n path = \"\";\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--; row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n\n return [accMatrix[size - 1][size - 1], path]\n}\n\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\nvar i = 0;\nfunction getPathWith(coordinates) {\n path = \"\";\n for (i = 0; i < coordinates[0]; i++) path += \"D\";\n for (i = 0; i < size - 1; i++) path += \"R\";\n for (i = coordinates[0]; i < size - 1; i++) path += \"D\";\n return path;\n}\n\nif (zeroPosition !== null && best[0] > 1) best = [1, getPathWith(zeroPosition)]\n\nprint(best[0]);\nprint(best[1]);", "positive_code": [{"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nvar hasZero = false;\nvar pathZero;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n\n if (value === 0) {\n if (!hasZero) {\n hasZero = true;\n pathZero =\n (new Array(i + 1)).join('D') +\n (new Array(n)).join('R') +\n (new Array(n - i)).join('D');\n }\n\n array2[i].push(1);\n array5[i].push(1);\n }\n\n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n }\n}\n\nvar foo = function(array) {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n\n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (hasZero && result2[0] > 1 && result5[0] > 1) {\n write('1\\n');\n write(pathZero);\n} else {\n if (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n } else {\n write(result5[0] + '\\n');\n write(result5[1]);\n }\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nvar hasZero = false;\nvar zeroI, zeroJ;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n \n if (value === 0) {\n hasZero = true;\n zeroI = i;\n zeroJ = j;\n }\n \n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n }\n}\n\nvar foo = function(array) {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n\n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (hasZero && result2[0] > 1 && result5[0] > 1) {\n write('1\\n');\n write((new Array(zeroI + 1)).join('D') + (new Array(n)).join('R') + (new Array(n - zeroI)).join('D'));\n} else {\n if (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n } else {\n write(result5[0] + '\\n');\n write(result5[1]);\n }\n}\n"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\n// solve for 2's\nvar twos = traverseInReverse(input, count, findTwos);\n\n// if there's a path with no 2's, return it\nif (twos[0] === 0) {\n print(twos[0]);\n print(twos[1]);\n} else {\n // solve for 5's\n var fives = traverseInReverse(input, count, findFives);\n\n // final answer is least of twos and fives\n if (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n } else {\n print(fives[0]);\n print(fives[1]);\n }\n}\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = []; // array of arrays\n var pathContainsZero = []; // best path contains just 1 zero\n\n rowLoop:\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n\n columnLoop:\n for (var b = boundary; b > -1; b--) {\n\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n if (a < boundary) {\n answerPaths[a][b] = 'D'; // default down\n } else if (b < boundary) {\n answerPaths[a][b] = 'R';\n } else {\n answerPaths[a][b] = ''; // last node\n }\n continue columnLoop;\n }\n\n if (b < boundary && pathContainsZero[b + 1]) {\n // right contains zero\n if (a === boundary || answerCounts[b] > 0) {\n // there is no down or down count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue columnLoop;\n }\n }\n\n if (a < boundary && pathContainsZero[b]) {\n // down contains zero\n if (b === boundary || answerCounts[b + 1] > 0) {\n // there is no right or right count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D';\n continue columnLoop;\n }\n }\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n pathContainsZero[b] = !!pathContainsZero[b];\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n pathContainsZero[b] = !!pathContainsZero[b + 1];\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n pathContainsZero[b] = !!pathContainsZero[b + 1];\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n pathContainsZero[b] = !!pathContainsZero[b];\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n\n if (a > boundary || b > boundary) {\n print('error while recreating path');\n break;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "'use strict'\n \nconst g = (v, k) => { let r = 0; while (v && v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n \nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\n \nconst main = () => {\n const r = ((a, b) => a[0] < b[0] ? a : b)(f(2), f(5));\n if (r[0] > 1) {\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n if(m[i][j] === 0) {\n return '1\\n' + 'D'.repeat(i) + 'R'.repeat(n-1) + 'D'.repeat(n-1-i);\n }\n }\n }\n }\n return r[0] + '\\n' + r[1].split('').reverse().join('');\n}\nwrite(main());"}, {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nvar accMatrix = [];\nvar accPath = [];\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n }\n accMatrix[0][0] = factorize(prime, matrix[0][0]);\n accPath[0][0] = \"\";\n // print('accMatrix[0][0]', accMatrix[0][0])\n // print('accPath[0][0]', accPath[0][0])\n\n for (column = 1; column < size; column++) {\n accMatrix[0][column] = accMatrix[0][column - 1] + factorize(prime, matrix[0][column]);\n accPath[0][column] = \"R\";\n accMatrix[column][0] = accMatrix[column - 1][0] + factorize(prime, matrix[column][0]);\n accPath[column][0] = \"D\";\n\n // print(accMatrix[0][column])\n // print(accPath[0][column])\n // print(accMatrix[column][0])\n // print(accPath[column][0])\n }\n\n // print('---')\n\n for (column = 1; column < size; column++) for (row = 1; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n\n // print(accMatrix[column][row])\n // print(accPath[column][row])\n }\n\n path = \"\";\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--; row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n\n return [accMatrix[size - 1][size - 1], path]\n}\n\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\nvar i = 0;\nfunction getPathWith(coordinates) {\n path = \"\";\n for (i = 0; i < coordinates[0]; i++) {\n path += \"D\";\n }\n for (i = 0; i < size - 1; i++) {\n path += \"R\";\n }\n for (i = coordinates[0]; i < size - 1; i++) {\n path += \"D\";\n }\n return path;\n}\n\nif (zeroPosition !== null && best[0] > 1) best = [1, getPathWith(zeroPosition)]\n\nprint(best[0]);\nprint(best[1]);"}, {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nvar accMatrix = [];\nvar accPath = [];\nvar path = \"\";\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column - 1 >= 0 && row - 1 >= 0) {\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n } else if (column - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else if (row - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n }\n }\n\n path = \"\";\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--; row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n\n return [accMatrix[size - 1][size - 1], path]\n}\n\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\nvar i = 0;\nfunction getPathWith(coordinates) {\n path = \"\";\n for (i = 0; i < coordinates[0]; i++) path += \"D\";\n for (i = 0; i < size - 1; i++) path += \"R\";\n for (i = coordinates[0]; i < size - 1; i++) path += \"D\";\n return path;\n}\n\nif (zeroPosition !== null && best[0] > 1) best = [1, getPathWith(zeroPosition)]\n\nprint(best[0]);\nprint(best[1]);"}, {"source_code": "n = parseInt(readline());\n\ngrid = [];\n\njscantparse = v => parseInt(v);\nfor(i=0; i {\n if (n === 0) return 0;\n var ret = 0;\n while(n%k === 0) ret++, n/=k;\n return ret;\n}\n\nconst dp = (k) => {\n best = [], prev=[];\n for(i=0; i=0;) for(j=n-1; j>=0;) {\n if (i===0 && j===0) i--, j--;\n else {\n path = prev[i][j] + path;\n if (prev[i][j] === 'R') j--;\n else i--;\n }\n }\n return [best[n-1][n-1], path];\n};\n\nres2 = dp(2);\nres5 = dp(5);\n\nbest = res2[0] <= res5[0] ? res2 : res5;\n\nconst getPathWith = coordinate => {\n path = \"\";\n for (i=0; i 1) best = [1, getPathWith(zeroPosition)];\n\nconst printResult = result => {\n print(result[0]);\n print(result[1]);\n}\n\n\nprintResult(best);"}, {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n}\n\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\n\nfunction accumulate(prime) {\n accMatrix = [];\n accPath = [];\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n }\n accMatrix[0][0] = factorize(prime, matrix[0][0]);\n accPath[0][0] = \"\";\n // print('accMatrix[0][0]', accMatrix[0][0])\n // print('accPath[0][0]', accPath[0][0])\n\n for (column = 1; column < size; column++) {\n accMatrix[0][column] = accMatrix[0][column - 1] + factorize(prime, matrix[0][column]);\n accPath[0][column] = \"R\";\n accMatrix[column][0] = accMatrix[column - 1][0] + factorize(prime, matrix[column][0]);\n accPath[column][0] = \"D\";\n\n // print(accMatrix[0][column])\n // print(accPath[0][column])\n // print(accMatrix[column][0])\n // print(accPath[column][0])\n }\n\n // print('---')\n\n for (column = 1; column < size; column++) for (row = 1; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n\n // print(accMatrix[column][row])\n // print(accPath[column][row])\n }\n\n path = \"\";\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--; row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n\n return [accMatrix[size - 1][size - 1], path]\n}\n\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\nvar i = 0;\nfunction getPathWith(coordinates) {\n path = \"\";\n for (i = 0; i < coordinates[0]; i++) {\n path += \"D\";\n }\n for (i = 0; i < size - 1; i++) {\n path += \"R\";\n }\n for (i = coordinates[0]; i < size - 1; i++) {\n path += \"D\";\n }\n return path;\n}\n\nif (zeroPosition !== null && best[0] > 1) best = [1, getPathWith(zeroPosition)]\n\nprint(best[0]);\nprint(best[1]);"}, {"source_code": "'use strict'\n \nconst g = (v, k) => { let r = 0; while (v && v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array.from({length: n}, () => readline().split(' ').map(Number))\n \nconst f = k => {\n const b = Array.from({length: n}, () => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n \n return b;\n}\n \nconst main = () => {\n const r = ((a, b) => a[n-1][n-1] < b[n-1][n-1] ? a : b)(f(2), f(5));\n if (r[n-1][n-1] > 1) {\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n if(m[i][j] === 0) {\n return '1\\n' + 'D'.repeat(i) + 'R'.repeat(n-1) + 'D'.repeat(n-1-i);\n }\n }\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (r[i][j-1] < r[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n return r[n-1][n-1] + '\\n' + p.split('').reverse().join('');\n}\nwrite(main());"}, {"source_code": "\nvar c = parseInt( readline() );\nvar m = [];\n\nvar zero=false;\n\nfor(var i=0; i n[i][j-1] ){\n\t\t\t\tn[i][j] = weight( m[i][j], k ) + n[i][j-1];\n\t\t\t\tp[i][j] = 'R';\n\t\t\t}else{\n\t\t\t\tn[i][j] = weight( m[i][j], k ) + n[i-1][j];\n\t\t\t\tp[i][j] = 'D';\n\t\t\t}\n\t\t}\n\t}\n\n\ti=j=c-1;\n\tvar path = [];\n\twhile( i>0 || j>0){\n\t\tpath.push( p[i][j] );\n\t\tif( p[i][j] == 'R'){\n\t\t\tj--\n\t\t}else{\n\t\t\ti--\n\t\t}\n\t}\n\treturn {\n\t\tn: n[c-1][c-1],\n\t\tpath: path\n\t}\n}\n\nvar path2 = path(m, 2);\nvar path5 = path(m, 5);\n//print(path2);\n//print(path5)\nvar p = path2.n>path5.n ? path5 : path2;\n\nif(p.n>1 && zero){\n\tprint(1);\n\n\tvar _p=[];\n\tfor(var i=0;i parseInt(v);\nfor(i=0; i {\n if (n === 0) return 0;\n var ret = 0;\n while(n%k === 0) ret++, n/=k;\n return ret;\n}\n \nconst dp = (k) => {\n best = [], prev=[];\n for(i=0; i=0;) for(j=n-1; j>=0;) {\n if (i===0 && j===0) i--, j--;\n else {\n path = prev[i][j] + path;\n if (prev[i][j] === 'R') j--;\n else i--;\n }\n }\n return [best[n-1][n-1], path];\n};\n \nres2 = dp(2);\nres5 = dp(5);\n \nbest = res2[0] <= res5[0] ? res2 : res5;\n \nconst getPathWith = coordinate => {\n path = \"\";\n for (i=0; i 1) best = [1, getPathWith(zeroPosition)];\n \nconst printResult = result => {\n print(result[0]);\n print(result[1]);\n}\n \n \nprintResult(best);"}], "negative_code": [{"source_code": "\nvar c = parseInt( readline() );\nvar list = [];\nfor(var i=0; ic*c ? null : step( i+c, {\n\t\t'2': s[2]+list[i][2],\n\t\t'5': s[5]+list[i][5]\n\t});\n\n\tif(!R && !D){\n\t\treturn {\n\t\t\t'way': '',\n\t\t\t'2': list[i][2],\n\t\t\t'5': list[i][5]\n\t\t};\n\t}\n\tif(!D){\n\t\treturn {\n\t\t\tway: 'R'+R.way,\n\t\t\t'2': list[i][2]+R[2],\n\t\t\t'5': list[i][5]+R[5]\n\t\t}\n\t}\n\tif(!R){\n\t\treturn {\n\t\t\tway: 'D'+D.way,\n\t\t\t'2': list[i][2]+D[2],\n\t\t\t'5': list[i][2]+D[5]\n\t\t}\n\t}\n\n\tif(Math.min( s[2]+R[2], s[5]+R[5] ) > Math.min( s[2]+D[2], s[5]+D[5] )){\n\t\treturn {\n\t\t\tway: 'D'+D.way,\n\t\t\t'2': list[i][2]+D[2],\n\t\t\t'5': list[i][5]+D[5]\n\t\t}\n\t}else{\n\t\treturn {\n\t\t\tway: 'R'+R.way,\n\t\t\t'2': list[i][2]+R[2],\n\t\t\t'5': list[i][5]+R[5]\n\t\t}\n\t}\n}\n\nvar way = step(1, {'2':list[1][2], '5':list[1][5]});\n\nprint( Math.min(way[2], way[5]) );\nprint( way.way );"}, {"source_code": "var c = parseInt( readline() );\nvar m = [];\n\nfor(var i=0; i up.c2 ){\n\t\t\t\t\tself.c2 = self.n2 + up.c2;\n\t\t\t\t\tself.w2 = 'D';\n\t\t\t\t}else{\n\t\t\t\t\tself.c2 = self.n2 + left.c2;\n\t\t\t\t\tself.w2 = 'R';\n\t\t\t\t}\n\t\t\t\tif(left.c5 > up.c5 ){\n\t\t\t\t\tself.c5 = self.n5 + up.c5;\n\t\t\t\t\tself.w5 = 'D';\n\t\t\t\t}else{\n\t\t\t\t\tself.c5 = self.n5 + left.c5;\n\t\t\t\t\tself.w5 = 'R';\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tself.c2 = self.n2 + up.c2;\n\t\t\t\tself.w2 = 'D';\n\t\t\t\tself.c5 = self.n5 + up.c5;\n\t\t\t\tself.w5 = 'D';\n\t\t\t}\n\t\t}else{\n\t\t\tif(left){\n\t\t\t\tself.c2 = self.n2 + left.c2;\n\t\t\t\tself.w2 = 'R';\n\t\t\t\tself.c5 = self.n5 + left.c5;\n\t\t\t\tself.w5 = 'R';\n\t\t\t}else{\n\t\t\t\tself.c2 = self.n2;\n\t\t\t\tself.w2 = '';\n\t\t\t\tself.c5 = self.n5;\n\t\t\t\tself.w5 = '';\n\t\t\t}\n\t\t}\n\t}\n}\nfunction path(n){\n\t//var c = 'c'+n;\n\tvar w = 'w'+n;\n\tvar x=c-1;\n\tvar y=c-1;\n\tvar ret = []\n\twhile( x!=0 || y!=0 ){\n\t\tprint(x, y)\n\t\tret.push( m[y][x][w] );\n\t\tif(m[y][x][w]=='R'){\n\t\t\tx--;\n\t\t}else{\n\t\t\ty--;\n\t\t}\n\t}\n\treturn ret.reverse().join('');\n}\n\nvar end = m[c-1][c-1];\n\nif( end.c5>end.c2 ){\n\tprint(end.c2);\n\tprint( path('2') )\n}else{\n\tprint(end.c5);\n\tprint( path('5') );\n}\n"}, {"source_code": "\nvar c = parseInt( readline() );\nvar m = [];\n\nvar zero=false;\n\nfor(var i=0; i n[i][j-1] ){\n\t\t\t\tn[i][j] = weight( m[i][j], k ) + n[i][j-1];\n\t\t\t\tp[i][j] = 'R';\n\t\t\t}else{\n\t\t\t\tn[i][j] = weight( m[i][j], k ) + n[i-1][j];\n\t\t\t\tp[i][j] = 'D';\n\t\t\t}\n\t\t}\n\t}\n\n\ti=j=c-1;\n\tvar path = [];\n\twhile( i>0 || j>0){\n\t\tpath.push( p[i][j] );\n\t\tif( p[i][j] == 'R'){\n\t\t\tj--\n\t\t}else{\n\t\t\ti--\n\t\t}\n\t}\n\treturn {\n\t\tn: n[c-1][c-1],\n\t\tpath: path\n\t}\n}\n\nvar path2 = path(m, 2);\nvar path5 = path(m, 5);\n//print(path2);\n//print(path5)\nvar p = path2.n>path5.n ? path5 : path2;\n\nif(p.n>1 && zero){\n\tprint(1);\n\n\tvar _p=[];\n\tfor(var i=0;i1E-6; ){\n\tvar dd = d(xx, yy);\n\tif(dd<1E-6){\n\t\tprint(xx + ' ' + yy);\n\t\tbreak;\n\t}\n\tif( dd>d(xx-i, yy) ){\n\t\txx -= i; \n\t}else if( dd>d(xx+i, yy) ){\n\t\txx += i; \n\t}else if( dd>d(xx, yy-i) ){\n\t\tyy -= i; \n\t}else if( dd>d(xx, yy+i) ){\n\t\tyy += i; \n\t}else{\n\t\ti *=0.7;\n\t}\n}\n"}, {"source_code": "var c = parseInt( readline() );\nvar m = [];\n\nfor(var i=0; i0 || j>0){\n\t\tif( i>0 && j>0 && (n[i-1][j] > n[i][j-1] || i>0) ){\n\t\t\tpath.push('D');\n\t\t\tj--;\n\t\t}else{\n\t\t\tpath.push('R');\n\t\t\ti--;\n\t\t}\n\t}\n\treturn {\n\t\tn: n[c-1][c-1],\n\t\tpath: path.reverse().join('')\n\t}\n}\n\nvar path2 = path(m, 2);\nvar path5 = path(m, 5);\nif(path2.n>path5.n){\n\tprint(path5.n);\n\tprint(path5.path);\n}else{\n\tprint(path2.n);\n\tprint(path2.path);\n}"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n const q = [ { v: M[0][0], x: 0, y: 0, h: '', z: `${M[0][0]}`.split('').reverse().findIndex(i => i !== '0') } ];\n \n while (q.length) {\n let i = q.sort((a, b) => a.z > b.z ? 1 : a.z < b.z ? -1 : b.h.length - a.h.length).shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x + 1, y: i.y, h: i.h + 'D' });\n }\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x, y: i.y + 1, h: i.h + 'R' });\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x, y: i.y + 1, h: i.h + 'D' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x + 1, y: i.y, h: i.h + 'R' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\nconst g = (v, k) => {\n let r = 0;\n while (v % k === 0) { v = v / k; r++; }\n return r;\n}\nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number).map(i => [ g(i, 2), g(i, 5) ]); }\n \n \nconst f = (n, M) => {\n const Two = M[0][0][0];\n const Five = M[0][0][1];\n const q = [ Two, Five, Math.min(Two, Five), 0, 0, '', 0 ];\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i[3], i[5] ].join('\\n');\n if (i.x < n) {\n const j = M[i[4]][i[3] + 1];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3] + 1, i[4], i[5] + 'R', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i.y < n) {\n const j = M[i[4] + 1][i[3]];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3], i[4] + 1, i[5] + 'D', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));\n"}, {"source_code": "'use strict'\n\nconst g = (v, k) => { let r = 0; while (v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n\nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\n\nconst r = ((a, b) => a[0] < b[0] ? a : b)(f(2), f(5));\n\nwrite(r[0] + '\\n' + r[1]);"}, {"source_code": "'use strict'\n\nconst g = (v, k) => { let r = 0; while (v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n\nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\nconst f2 = f(2);\nconst f5 = f(5);\n\nconst r = (a, b) => a[0] < b[0] ? a : b;\n\nwrite(r[0] + '\\n' + r[1]);\n"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n if (n === 19) return `0\nDDDRDRDDDDDDDDRDDRRRRDRRRRRDRRRRDRDRDR`;\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x, y: i.y + 1, h: i.h + 'R' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x + 1, y: i.y, h: i.h + 'D' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.sort((a, b) => a.z > b.z ? 1 : a.z < b.z ? -1 : b.h.length - a.h.length).shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x, y: i.y + 1, h: i.h + 'R' });\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x + 1, y: i.y, h: i.h + 'D' });\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.sort((a, b) => a.z > b.z ? 1 : a.z < b.z ? -1 : b.h.length - a.h.length).shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x + 1, y: i.y, h: i.h + 'D' });\n }\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x, y: i.y + 1, h: i.h + 'R' });\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst g = (v, k) => {\n let r = 0;\n while (v % k) { v = v / k; r++; }\n return r;\n}\nconst f = (n, M) => {\n const Two = g(M[0][0], 2);\n const Five = g(M[0][0], 5);\n const q = [ { two: Two, five: Five, x: 0, y: 0, h: '', z: Math.min(Two, Five) } ];\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.x < n) {\n const two = i.two + g(M[i.y][i.x + 1], 2);\n const five = i.five + g(M[i.y][i.x + 1], 5);\n const next = {two, five, x: i.x + 1, y: i.y, h: i.h + 'R', z: Math.min(two, five) };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i.y < n) {\n const two = i.two + g(M[i.y + 1][i.x], 2);\n const five = i.five + g(M[i.y + 1][i.x], 5);\n const next = {two, five, x: i.x, y: i.y + 1, h: i.h + 'D', z: Math.min(two, five) };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst g = (v, k) => { let r = 0; while (v && v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n \nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\n \nconst main = () => {\n const r = ((a, b) => a[0] < b[0] ? a : b)(f(2), f(5));\n if (r[0] > 1) {\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n if(m[i][j] === 0) {\n return '0\\n' + 'R'.repeat(i) + 'D'.repeat(n-1) + 'R'.repeat(n-1-i);\n }\n }\n }\n }\n return r[0] + '\\n' + r[1].split('').reverse().join('');\n}\nwrite(main());"}, {"source_code": "'use strict'\n \nconst g = (v, k) => { let r = 0; while (v && v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n \nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\n\nfor (let i = 0; i < n; i++) {\n \n} \nconst r = ((a, b) => a[0] < b[0] ? a : b)(f(2), f(5));\n \nwrite(r[0] + '\\n' + r[1].split('').reverse().join(''));\n"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.sort((a, b) => a.z > b.z ? 1 : a.z < b.z ? -1 : b.h.length - a.h.length).shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x, y: i.y + 1, h: i.h + 'R' });\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x + 1, y: i.y, h: i.h + 'D' });\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x, y: i.y + 1, h: i.h + 'R' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x + 1, y: i.y, h: i.h + 'D' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\nconst g = (v, k) => {\n let r = 0;\n while (v % k === 0) { v = v / k; r++; }\n return r;\n}\nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number).map(i => [ g(i, 2), g(i, 5) ]); }\n \n \nconst f = (n, M) => {\n const Two = M[0][0][0];\n const Five = M[0][0][1];\n const q = [ Two, Five, Math.min(Two, Five), 0, 0, '', 0 ];\n \n while (q.length) {\n let i = q.shift();\n if (i[3] === n && i[4] === n) return [ i[2], i[5] ].join('\\n');\n if (i[3] < n) {\n const j = M[i[4]][i[3] + 1];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3] + 1, i[4], i[5] + 'R', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i[4] < n) {\n const j = M[i[4] + 1][i[3]];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3], i[4] + 1, i[5] + 'D', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));\n"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n let Z = 0;\n let V = M[0][0];\n while (V % 10 === 0) { V = V / 10; Z++; }\n const q = [ { v: V, x: 0, y: 0, h: '', z: Z } ];\n \n while (q.length) {\n let i = q.shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x, y: i.y + 1, h: i.h + 'R' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n q.splice(index, 0, next);\n }\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n while (v % 10 === 0) { v = v / 10; z++; }\n const next = { z, v, x: i.x + 1, y: i.y, h: i.h + 'D' };\n const index = q.findIndex(item => item.z > next.z || (item.z === next.z && item.h.length < next.h.length));\n q.splice(index, 0, next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst g = (v, k) => { let r = 0; while (v && v % k === 0) { v = v / k; r++; } return r; }\nconst n = parseInt(readline());\nconst m = Array(n).fill().map(() => readline().split(' ').map(Number))\n \nconst f = k => {\n const b = Array(n).fill().map(() => []);\n for(let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n b[i][j] = g(m[i][j], k);\n }\n }\n for(let i = 1; i < n; i++) {\n b[i][0] += b[i-1][0];\n b[0][i] += b[0][i-1];\n }\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n b[i][j] += Math.min(b[i-1][j], b[i][j-1]);\n }\n }\n let p = '', i = n-1, j = n-1;\n while (i+j) {\n if (i === 0) { p += 'R'.repeat(j); break; }\n if (j === 0) { p += 'D'.repeat(i); break; }\n \n if (b[i][j-1] < b[i-1][j]) { j--; p += 'R'; }\n else { i--; p += 'D'; }\n }\n \n return [ b[n-1][n-1], p ];\n}\n \nconst main = () => {\n const r = ((a, b) => a[0] < b[0] ? a : b)(f(2), f(5));\n if (r[0] > 1) {\n for(let i = 1; i < n; i++) {\n for (let j = 1; j < n; j++) {\n if(m[i][j] === 0) {\n return '1\\n' + 'R'.repeat(i) + 'D'.repeat(n-1) + 'R'.repeat(n-1-i);\n }\n }\n }\n }\n return r[0] + '\\n' + r[1].split('').reverse().join('');\n}\nwrite(main());"}, {"source_code": "'use strict'\nconst g = (v, k) => {\n let r = 0;\n while (v % k === 0) { v = v / k; r++; }\n return r;\n}\nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number).map(i => [ g(i, 2), g(i, 5) ]); }\n \n \nconst f = (n, M) => {\n const Two = M[0][0][0];\n const Five = M[0][0][1];\n const q = [ Two, Five, Math.min(Two, Five), 0, 0, '', 0 ];\n \n while (q.length) {\n let i = q.shift();\n if (i[6] === 2*n) return [ i[2], i[5] ].join('\\n');\n if (i[3] < n) {\n const j = M[i[4]][i[3] + 1];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3] + 1, i[4], i[5] + 'R', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n if (i[4] < n) {\n const j = M[i[4] + 1][i[3]];\n const two = i[0] + j[0];\n const five = i[1] + j[1];\n const next = [ two, five, Math.min(two, five), i[3], i[4] + 1, i[5] + 'D', i[6] + 1 ];\n const index = q.findIndex(item => item[2] > next[2] || (item[2] === next[2] && item[6] < next[6]));\n if (index !== -1) q.splice(index, 0, next);\n else q.push(next);\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst M = [];\nfor(let i = 0; i < n; i++) { M[i] = readline().split(' ').map(Number); }\n \nconst f = (n, M) => {\n const q = [ { v: M[0][0], x: 0, y: 0, h: '', z: `${M[0][0]}`.split('').reverse().findIndex(i => i !== '0') } ];\n \n while (q.length) {\n let i = q.sort((a, b) => a.z > b.z ? 1 : a.z < b.z ? -1 : a.h.length - b.h.length).shift();\n if (i.x === n && i.y === n) return [ i.z, i.h ].join('\\n');\n if (i.x < n) {\n let v = i.v * M[i.x + 1][i.y];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x + 1, y: i.y, h: i.h + 'D' });\n }\n if (i.y < n) {\n let v = i.v * M[i.x][i.y + 1];\n let z = i.z;\n if (v % 10 === 0) { v = v / 10; z++; }\n q.push({ z, v, x: i.x, y: i.y + 1, h: i.h + 'R' });\n }\n }\n}\nwrite(f(n - 1, M));"}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\n\nvar line = [];\nvar num;\nvar countTwo = 0;\nvar countFive = 0;\n// put the inputs into 'matrix' two dimensional array\nfor (var i = 0; i < size; i++) {\n line = readline().split(\" \");\n\n // transform the input number into number of twos and fives\n for (var k = 0; k < line.length; k++) {\n num = line[k];\n countTwo = 0;\n while (num % 2 == 0) {\n num = num / 2;\n countTwo++;\n }\n num = line[k];\n countFive = 0;\n while (num % 5 == 0) {\n num = num / 5;\n countFive++;\n }\n\n line[k] = {\n 2: countTwo,\n 5: countFive\n }\n }\n matrix.push(line);\n}\n// print(JSON.stringify(matrix));\n\nvar result = [];\ngoNext([0, 0], \"\", {2: 0, 5: 0});\ngetTheLeastRoundWay();\n\n// \uacbd\ub85c\ub97c \ub9cc\ub4dc\ub294 \uc7ac\uadc0\ud568\uc218\ub97c \ub9cc\ub4e0\ub2e4.\nfunction goNext(currentIndex, way, numberOfTwoNFive) {\n\n if (endOfTheRoute(currentIndex)) {\n result.push({way: way, trailingZeros: calculateTrailingZeros(numberOfTwoNFive)})\n return;\n }\n // \uc544\ub798\ucabd \uc624\ub978\ucabd\uc73c\ub85c \uc774\ub3d9\n if (canGoDown(currentIndex)) goNext(\n [currentIndex[0] + 1, currentIndex[1]],\n way + \"D\",\n {\n 2: numberOfTwoNFive[2] + matrix[currentIndex[0]][currentIndex[1]][2],\n 5: numberOfTwoNFive[5] + matrix[currentIndex[0]][currentIndex[1]][5]\n });\n if (canGoRight(currentIndex)) goNext([currentIndex[0], currentIndex[1] + 1], way + \"R\", {\n 2: numberOfTwoNFive[2] + matrix[currentIndex[0]][currentIndex[1]][2],\n 5: numberOfTwoNFive[5] + matrix[currentIndex[0]][currentIndex[1]][5]\n });\n}\n\nfunction endOfTheRoute(currentIndex) {return currentIndex[0] === size - 1 && currentIndex[1] === size - 1;}\n\nfunction canGoDown(currentIndex) {return currentIndex[0] !== size - 1;}\n\nfunction canGoRight(currentIndex) {return currentIndex[1] !== size - 1;}\n\nfunction calculateTrailingZeros(numberOfTwoNFive) {\n\n // print(JSON.stringify(numberOfTwoNFive));\n var twos = numberOfTwoNFive[2];\n var fives = numberOfTwoNFive[5];\n\n if (twos === 0 || fives === 0) return 0;\n if (twos > fives) return fives;\n else return twos;\n}\n\nfunction getTheLeastRoundWay() {\n result.sort((a, b) => a.trailingZeros - b.trailingZeros);\n // print(JSON.stringify(result));\n print(result[0].trailingZeros);\n print(result[0].way);\n}\n"}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\nvar left;\nvar top;\nvar leftExist;\nvar topExist;\nvar leftElement;\nvar topElement;\nvar currentElement;\n\nvar leastMatrix = [];\nvar lastCell = [];\n\n// put the inputs into 'matrix' two dimensional array\nfor (var column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(s => parseInt(s)));\n leastMatrix.push([]);\n\n for (var row = 0; row < size; row++) {\n matrix[column][row] = factorizePrime(matrix[column][row]);\n currentElement = matrix[column][row];\n\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n\n for (var d = 0; d < 2; d++) {\n // least two matrix\n leftElement = leftExist ? leastMatrix[column][left] : null;\n topElement = topExist ? leastMatrix[top][row] : null;\n\n if (!topExist && !leftExist) {\n leastMatrix[column].push([\n currentElement[0],\n currentElement[1]\n ])\n } else if (topExist && !leftExist) {\n leastMatrix[column].push([\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1]\n ])\n } else if (!topExist && leftExist) {\n leastMatrix[column].push([\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1]\n ]);\n } else if (topExist && leftExist) {\n if (topElement[d === 0 ? 0 : 1] === leftElement[d === 0 ? 0 : 1]) {\n leastMatrix[column].push([\n currentElement[0] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[0] : leftElement[0]),\n currentElement[1] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[1] : leftElement[1]),\n ]);\n } else if (topElement[d === 0 ? 0 : 1] <= leftElement[d === 0 ? 0 : 1]) {\n leastMatrix[column].push([\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1],\n ]);\n } else {\n leastMatrix[column].push([\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1],\n ]);\n }\n }\n\n lastCell[d] = leastMatrix[column][row];\n\n }\n\n }\n}\n// print(JSON.stringify(matrix));\n// print(JSON.stringify(leastMatrix[0]));\n// print(JSON.stringify(leastMatrix[1]));\n\nvar twoOrFive;\nvar topCell;\nvar leftCell;\nvar zeros = [];\nfor (d = 0; d < 2; d++) {\n if (lastCell[d][0] === 0 || lastCell[d][1] === 0) {\n zeros.push(0);\n } else if (lastCell[d][0] <= lastCell[d][1]) {\n zeros.push(lastCell[d][0]);\n } else {\n zeros.push(lastCell[d][1]);\n }\n // print(`zeros: ${zeros}`)\n}\n\n// print(JSON.stringify(zeros));\n\nif (zeros[0] <= zeros[1]) twoOrFive = 0;\nelse twoOrFive = 1;\n\nprint(zeros[twoOrFive]);\n\nrow = column = size - 1;\n// print(`row: ${row}, column: ${column}`);\nvar route = \"\";\nwhile (1) {\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n topCell = topExist ? leastMatrix[top][row] : null;\n leftCell = leftExist ? leastMatrix[column][left] : null;\n\n // print(`current: ${column} ${row}, left: ${left}, top: ${top}, leftExist: ${leftExist}, topExist: ${topExist}, topCell: ${topCell}, leftCell: ${leftCell}`)\n\n if (!topExist && !leftExist) {\n print(route);\n break;\n } else if (topExist && !leftExist) {\n route = \"D\" + route;\n column--;\n } else if (!topExist && leftExist) {\n route = \"R\" + route;\n row--;\n } else if (topExist && leftExist) {\n\n if (topCell[twoOrFive] < leftCell[twoOrFive]) {\n route = \"D\" + route;\n column--;\n } else if (topCell[twoOrFive] > leftCell[twoOrFive]) {\n route = \"R\" + route;\n row--;\n } else if (topCell[twoOrFive] === leftCell[twoOrFive]) {\n\n if (topCell[twoOrFive === 0 ? 1 : 0] <= leftCell[twoOrFive === 0 ? 1 : 0]) {\n route = \"D\" + route;\n column--;\n } else {\n route = \"R\" + route;\n row--;\n }\n\n }\n\n }\n\n}\n\n\nvar twos = 0;\nvar fives = 0;\n\nfunction factorizePrime(num) {\n twos = 0;\n fives = 0;\n while (num % 2 === 0) {\n num /= 2;\n twos++;\n }\n while (num % 5 === 0) {\n num /= 5;\n fives++;\n }\n return [twos, fives];\n}\n\n\n"}, {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nvar accMatrix = [];\nvar accPath = [];\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column - 1 >= 0 && row - 1 >= 0) {\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n } else if (column - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else if (row - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n return [accMatrix[size-1][size-1], accPath]\n}\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\nif (zeroPosition !== null && best[0] > 1) {\n trailingZeros = 1;\n\n for (i = 0; i < zeroPosition[0]; i++) {path += \"D\";}\n for (i = 0; i < size - 1; i++) {path += \"R\";}\n for (i = zeroPosition[0]; i < size - 1; i++) {path += \"D\";}\n\n} else {\n trailingZeros = best[0];\n\n accPath = best[1];\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--;row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n\n}\n\nprint(trailingZeros);\nprint(path);"}, {"source_code": "var size = parseInt(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nvar zeroPosition = null;\nfor (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n for (row = 0; row < size; row++) if (matrix[column][row] === 0) zeroPosition = [column, row];\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nvar accMatrix = [];\nvar accPath = [];\n\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n accMatrix[column] = [];\n accPath[column] = [];\n }\n accMatrix[0][0] = factorize(prime, matrix[0][0]);\n accPath[0][0] = \"\";\n // print('accMatrix[0][0]', accMatrix[0][0])\n // print('accPath[0][0]', accPath[0][0])\n\n for (column = 1; column < size; column++) {\n accMatrix[0][column] = accMatrix[0][column - 1] + factorize(prime, matrix[0][column]);\n accPath[0][column] = \"R\";\n accMatrix[column][0] = accMatrix[column - 1][0] + factorize(prime, matrix[column][0]);\n accPath[column][0] = \"D\";\n\n // print(accMatrix[0][column])\n // print(accPath[0][column])\n // print(accMatrix[column][0])\n // print(accPath[column][0])\n }\n\n // print('---')\n\n for (column = 1; column < size; column++) for (row = 1; row < size; row++) {\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n\n // print(accMatrix[column][row])\n // print(accPath[column][row])\n }\n\n return [accMatrix[size - 1][size - 1], accPath]\n}\n\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\nif (zeroPosition !== null && best[0] > 1) {\n trailingZeros = 1;\n\n for (i = 0; i < zeroPosition[0]; i++) {\n path += \"D\";\n }\n for (i = 0; i < size - 1; i++) {\n path += \"R\";\n }\n for (i = zeroPosition[0]; i < size - 1; i++) {\n path += \"D\";\n }\n\n} else {\n trailingZeros = best[0];\n\n accPath = best[1];\n for (column = size - 1; column >= 0;) for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {column--; row--;}\n else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n}\n\nprint(trailingZeros);\nprint(path);"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column;\nvar row;\nvar zeroPosition = null;\nconstructMatrix();\n\nvar accMatrix = [];\nvar accPath = [];\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\ntrailingZeros = zeroPosition !== null && best[0] > 1 ? 1 : best[0];\nfindPath(best);\n\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix() {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) {\n\n if (matrix[column][row] === 0) {\n zeroPosition = [column, row];\n }\n }\n\n }\n}\n\nfunction factorize(prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {\n num /= prime;\n count++\n }\n return count;\n}\n\nfunction accumulate(prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column - 1 >= 0 && row - 1 >= 0) {\n\n if (accMatrix[column - 1][row] < accMatrix[column][row - 1]) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column - 1][row];\n accPath[column][row] = \"D\";\n } else if (row - 1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row - 1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size - 1][size - 1], accPath]\n\n}\n\nfunction findPath(items) {\n\n if (zeroPosition !== null && best[0] > 1) {\n for (i = 0; i < zeroPosition[0]; i++) {\n path += \"D\";\n }\n for (i = 0; i < size - 1; i++) {\n path += \"R\";\n }\n for (i = zeroPosition[0]; i < size - 1; i++) {\n path += \"D\";\n }\n } else {\n accPath = items[1];\n\n for (column = size - 1; column >= 0;) {\n for (row = size - 1; row >= 0;) {\n if (column === 0 && row === 0) {\n column--;\n row--;\n } else {\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n }\n }\n }\n }\n\n\n}\n\n// Wrong answer on test 27"}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\nvar left;\nvar top;\nvar leftExist;\nvar topExist;\nvar leftElement;\nvar topElement;\nvar currentElement;\n\nvar leastMatrix = [\n [],\n []\n];\n\n// put the inputs into 'matrix' two dimensional array\nfor (var column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(s => parseInt(s)));\n leastMatrix[0].push([]);\n leastMatrix[1].push([]);\n\n for (var row = 0; row < size; row++) {\n matrix[column][row] = factorizePrime(matrix[column][row]);\n currentElement = matrix[column][row];\n\n // print(\"====\")\n // print(`column:row ${column}:${row}`);\n // print(JSON.stringify(matrix[column][row]));\n\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n // print(`left: ${left}, top: ${top}, leftExist: ${leftExist}, topExist: ${topExist}`);\n\n\n for (var d = 0; d < 2; d++) {\n // least two matrix\n leftElement = leftExist ? leastMatrix[d][column][left] : null;\n topElement = topExist ? leastMatrix[d][top][row] : null;\n // print(`leftElement: ${leftElement}, topElement: ${topElement}, currentElement: ${currentElement}`);\n\n if (!topExist && !leftExist) {\n\n leastMatrix[d][column].push([\n currentElement[0],\n currentElement[1]\n ])\n\n } else if (topExist && !leftExist) {\n\n leastMatrix[d][column].push([\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1]\n ])\n\n } else if (!topExist && leftExist) {\n\n leastMatrix[d][column].push([\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1]\n ]);\n\n } else if (topExist && leftExist) {\n\n if (topElement[d === 0 ? 0 : 1] === leftElement[d === 0 ? 0 : 1]) {\n\n leastMatrix[d][column].push([\n currentElement[0] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[0] : leftElement[0]),\n currentElement[1] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[1] : leftElement[1]),\n ]);\n\n } else if (topElement[d === 0 ? 0 : 1] <= leftElement[d === 0 ? 0 : 1]) {\n\n leastMatrix[d][column].push([\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1],\n ]);\n\n } else {\n\n leastMatrix[d][column].push([\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1],\n ]);\n\n }\n }\n\n // print(`result: ${leastMatrix[d][column][row]}`);\n\n }\n\n }\n}\n// print(JSON.stringify(matrix));\n// print(JSON.stringify(leastMatrix[0]));\n// print(JSON.stringify(leastMatrix[1]));\n\ngetTrailingZeros();\n\nvar twoOrFive;\nvar topCell;\nvar leftCell;\nvar lastCell;\nfunction getTrailingZeros () {\n\n var zeros = [];\n for (d = 0; d < 2; d++) {\n lastCell = leastMatrix[d][size-1][size-1];\n // print(`d: ${d}`);\n // print(`lastCell: ${lastCell}`);\n // print(`zeros: ${zeros}`);\n if (lastCell[0] === 0 || lastCell[1] === 0) {\n zeros.push(0);\n } else if (lastCell[0] <= lastCell[1]) {\n zeros.push(lastCell[0]);\n } else {\n zeros.push(lastCell[1]);\n }\n // print(`zeros: ${zeros}`)\n }\n\n // print(JSON.stringify(zeros));\n\n if (zeros[0] <= zeros[1]) {\n twoOrFive = 0;\n leastMatrix = leastMatrix[0];\n } else {\n twoOrFive = 1;\n leastMatrix = leastMatrix[1];\n }\n print(zeros[twoOrFive]);\n\n row = column = size-1;\n // print(`row: ${row}, column: ${column}`);\n var route = \"\";\n while(1) {\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n topCell = topExist ? leastMatrix[top][row] : null;\n leftCell = leftExist ? leastMatrix[column][left] : null;\n\n // print(`left: ${left}, top: ${top}, leftExist: ${leftExist}, topExist: ${topExist}, topCell: ${topCell}, leftCell: ${leftCell}`)\n if (!topExist && !leftExist) {\n print(route);\n break;\n } else if (topExist && !leftExist) {\n route = \"D\" + route;\n column--;\n } else if (!topExist && leftExist) {\n route = \"R\" + route;\n row--;\n } else if (topExist && leftExist) {\n\n if (topCell[twoOrFive] < leftCell[twoOrFive]) {\n route = \"D\" + route;\n column--;\n } else if (topCell[twoOrFive] >= leftCell[twoOrFive]) {\n route = \"R\" + route;\n row--;\n } else if (topCell[twoOrFive] === leftCell[twoOrFive]) {\n\n if (topCell[!twoOrFive] < leftCell[!twoOrFive]) {\n route = \"D\" + route;\n column--;\n } else {\n route = \"R\" + route;\n row--;\n }\n\n }\n\n }\n\n }\n\n}\n\nvar twos = 0; var fives = 0;\nfunction factorizePrime(num) {\n twos = 0;\n fives = 0;\n while (num % 2 === 0) {\n num /= 2;\n twos++;\n }\n while (num % 5 === 0) {\n num /= 5;\n fives++;\n }\n return [twos, fives];\n}\n\n\n"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroPosition = [];\nvar zeroExists = false;\nconstructMatrix();\n\nvar accMatrix = [];\nvar accPath = [];\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\ntrailingZeros = zeroExists && best[0] > 1 ? 1 : best[0];\nfindPath(best);\n\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n if (!zeroExists && matrix[column][row] === 0) {\n zeroExists = true;\n zeroPosition = [column, row];\n }\n }\n}\n\nfunction factorize (prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n if (zeroExists && best[0] > 1) {\n for(i = 0; i < zeroPosition[0]; i++) {\n path += \"D\";\n }\n for(i = 0; i < size-1; i++) {\n path += \"R\";\n }\n for (i = zeroPosition[0]; i < size-1; i++) {\n path += \"D\";\n }\n } else {\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(column = size-1; column >= 0;) {\n for (row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n }\n }\n\n\n}\n\n// Wrong answer on test 27"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nconstructMatrix();\n\n\nvar accMatrix = [];\nvar accPath = [];\nvar twos = accumulate(2);\nvar fives = accumulate(5);\n\n// print(twos[0])\n// print(fives[0])\n\nvar trailingZeros;\nvar path = \"\";\nif (twos[0] === 0 && fives[0] === 0) {\n trailingZeros = 0;\n findPath(twos);\n} else if (twos[0] < fives[0]) {\n trailingZeros = twos[0];\n findPath(twos);\n} else {\n trailingZeros = fives[0];\n findPath(fives);\n}\n\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (var column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n }\n}\n\nfunction factorize (prime, num) {\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (var column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (var row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n accMatrix = items[0];\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(var column = size-1; column >= 0;) {\n for (var row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n }\n}"}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\nvar left;\nvar top;\nvar leftExist;\nvar topExist;\nvar leftElement;\nvar topElement;\nvar currentElement;\n\nvar leastMatrix = [];\nvar lastCell = [];\n\n// put the inputs into 'matrix' two dimensional array\nfor (var column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(s => parseInt(s)));\n leastMatrix.push([]);\n\n for (var row = 0; row < size; row++) {\n matrix[column][row] = factorizePrime(matrix[column][row]);\n currentElement = matrix[column][row];\n\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n\n for (var d = 0; d < 2; d++) {\n // least two matrix\n leftElement = leftExist ? leastMatrix[column][left] : null;\n topElement = topExist ? leastMatrix[top][row] : null;\n\n if (!topExist && !leftExist) {\n leastMatrix[column][row] = [\n currentElement[0],\n currentElement[1]\n ]\n } else if (topExist && !leftExist) {\n leastMatrix[column][row] = [\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1]\n ]\n } else if (!topExist && leftExist) {\n leastMatrix[column][row] = [\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1]\n ]\n } else if (topExist && leftExist) {\n if (topElement[d === 0 ? 0 : 1] === leftElement[d === 0 ? 0 : 1]) {\n leastMatrix[column][row] = [\n currentElement[0] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[0] : leftElement[0]),\n currentElement[1] + (topElement[d === 0 ? 1 : 0] <= leftElement[d === 0 ? 1 : 0] ? topElement[1] : leftElement[1]),\n ]\n } else if (topElement[d === 0 ? 0 : 1] <= leftElement[d === 0 ? 0 : 1]) {\n leastMatrix[column][row] = [\n currentElement[0] + topElement[0],\n currentElement[1] + topElement[1],\n ]\n } else {\n leastMatrix[column][row] = [\n currentElement[0] + leftElement[0],\n currentElement[1] + leftElement[1],\n ]\n }\n }\n\n lastCell[d] = leastMatrix[column][row];\n\n }\n\n }\n}\n// print(JSON.stringify(matrix));\n// print(JSON.stringify(leastMatrix));\n\nvar twoOrFive;\nvar topCell;\nvar leftCell;\nvar zeros = [];\n\nfor (d = 0; d < 2; d++) {\n // print(`lastCell[${d}]: ${lastCell[d]}`);\n if (lastCell[d][0] === 0 || lastCell[d][1] === 0) {\n zeros.push(0);\n } else if (lastCell[d][0] <= lastCell[d][1]) {\n zeros.push(lastCell[d][0]);\n } else {\n zeros.push(lastCell[d][1]);\n }\n // print(`zeros: ${zeros}`)\n}\n\n// print(JSON.stringify(zeros));\n\nif (zeros[0] <= zeros[1]) twoOrFive = 0;\nelse twoOrFive = 1;\n\n// print(twoOrFive);\nprint(zeros[twoOrFive]);\n\nrow = column = size - 1;\n// print(`row: ${row}, column: ${column}`);\nvar route = \"\";\nwhile (1) {\n left = row - 1;\n top = column - 1;\n leftExist = left >= 0;\n topExist = top >= 0;\n topCell = topExist ? leastMatrix[top][row] : null;\n leftCell = leftExist ? leastMatrix[column][left] : null;\n\n // print(`current: ${column} ${row}, left: ${left}, top: ${top}, leftExist: ${leftExist}, topExist: ${topExist}, topCell: ${topCell}, leftCell: ${leftCell}`)\n\n if (!topExist && !leftExist) {\n print(route);\n break;\n } else if (topExist && !leftExist) {\n route = \"D\" + route;\n column--;\n } else if (!topExist && leftExist) {\n route = \"R\" + route;\n row--;\n } else if (topExist && leftExist) {\n\n if (topCell[twoOrFive] < leftCell[twoOrFive]) {\n route = \"D\" + route;\n column--;\n } else if (topCell[twoOrFive] > leftCell[twoOrFive]) {\n route = \"R\" + route;\n row--;\n } else if (topCell[twoOrFive] === leftCell[twoOrFive]) {\n\n if (topCell[twoOrFive === 0 ? 1 : 0] <= leftCell[twoOrFive === 0 ? 1 : 0]) {\n route = \"D\" + route;\n column--;\n } else {\n route = \"R\" + route;\n row--;\n }\n\n }\n\n }\n\n}\n\n\nvar twos = 0;\nvar fives = 0;\n\nfunction factorizePrime(num) {\n twos = 0;\n fives = 0;\n while (num % 2 === 0) {\n num /= 2;\n twos++;\n }\n while (num % 5 === 0) {\n num /= 5;\n fives++;\n }\n return [twos, fives];\n}\n\n\n"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroIndex = [];\nvar zeroExists = false;\nconstructMatrix();\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\nif (zeroExists) {\n\n trailingZeros = 0;\n for(i = 0; i < zeroIndex[0]; i++) {\n path += \"D\";\n }\n for(i = 0; i < zeroIndex[1]; i++) {\n path += \"R\";\n }\n for (i = zeroIndex[0]; i < size-1; i++) {\n path += \"D\";\n }\n for (i = zeroIndex[1]; i < size-1; i++) {\n path += \"R\";\n }\n\n} else {\n var accMatrix = [];\n var accPath = [];\n var twos = accumulate(2);\n var fives = accumulate(5);\n\n// print(twos[0])\n// print(fives[0])\n if (twos[0] === 0 && fives[0] === 0) {\n trailingZeros = 0;\n findPath(twos);\n } else if (twos[0] < fives[0]) {\n trailingZeros = twos[0];\n findPath(twos);\n } else {\n trailingZeros = fives[0];\n findPath(fives);\n }\n\n}\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) {\n if (matrix[column][row] === 0) {\n zeroExists = true;\n zeroIndex = [column, row];\n column = size;\n row = size;\n break;\n }\n }\n }\n}\n\nfunction factorize (prime, num) {\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n accMatrix = items[0];\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(column = size-1; column >= 0;) {\n for (row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n }\n}"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroPosition = [];\nvar zeroExists = false;\nconstructMatrix();\n\nvar accMatrix = [];\nvar accPath = [];\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] < fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\ntrailingZeros = zeroExists && best[0] > 1 ? 1 : best[0];\nfindPath(best);\n\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n if (!zeroExists && matrix[column][row] === 0) {\n zeroExists = true;\n zeroPosition = [column, row];\n }\n }\n}\n\nfunction factorize (prime, num) {\n var count = 0;\n if (num === 0) return 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n if (zeroExists && best[0] > 1) {\n for(i = 0; i < zeroPosition[0]; i++) {\n path += \"D\";\n }\n for(i = 0; i < size-1; i++) {\n path += \"R\";\n }\n for (i = zeroPosition[0]; i < size-1; i++) {\n path += \"D\";\n }\n } else {\n accMatrix = items[0];\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(column = size-1; column >= 0;) {\n for (row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n } \n }\n \n \n}\n\n// Wrong answer on test 27"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroPosition = null;\nconstructMatrix();\n\nvar accMatrix = [];\nvar accPath = [];\nvar twos = accumulate(2);\nvar fives = accumulate(5);\nvar best = twos[0] <= fives[0] ? twos : fives;\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\n\ntrailingZeros = zeroPosition !== null && best[0] > 1 ? 1 : best[0];\nfindPath(best);\n\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n if (matrix[column][row] === 0) {\n zeroPosition = [column, row];\n }\n }\n}\n\nfunction factorize (prime, num) {\n if (num === 0) return 0;\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n if (zeroPosition !== null && best[0] > 1) {\n for(i = 0; i < zeroPosition[0]; i++) {\n path += \"D\";\n }\n for(i = 0; i < size-1; i++) {\n path += \"R\";\n }\n for (i = zeroPosition[0]; i < size-1; i++) {\n path += \"D\";\n }\n } else {\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(column = size-1; column >= 0;) {\n for (row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n }\n }\n\n\n}\n\n// Wrong answer on test 27"}, {"source_code": "var size = Number(readline());\n\nvar matrix = [];\nvar column; var row;\nvar zeroIndex = [];\nvar zeroExists = false;\nconstructMatrix();\n\nvar trailingZeros;\nvar path = \"\";\nvar i = 0;\nif (zeroExists) {\n\n trailingZeros = 1;\n for(i = 0; i < zeroIndex[0]; i++) {\n path += \"D\";\n }\n for(i = 0; i < zeroIndex[1]; i++) {\n path += \"R\";\n }\n for (i = zeroIndex[0]; i < size-1; i++) {\n path += \"D\";\n }\n for (i = zeroIndex[1]; i < size-1; i++) {\n path += \"R\";\n }\n\n} else {\n var accMatrix = [];\n var accPath = [];\n var twos = accumulate(2);\n var fives = accumulate(5);\n\n// print(twos[0])\n// print(fives[0])\n if (twos[0] === 0 && fives[0] === 0) {\n trailingZeros = 0;\n findPath(twos);\n } else if (twos[0] <= fives[0]) {\n trailingZeros = twos[0];\n findPath(twos);\n } else {\n trailingZeros = fives[0];\n findPath(fives);\n }\n\n}\nprint(trailingZeros);\nprint(path);\n\nfunction constructMatrix () {\n for (column = 0; column < size; column++) {\n matrix.push(readline().split(\" \").map(n => parseInt(n)));\n\n for (row = 0; row < size; row++) {\n if (matrix[column][row] === 0) {\n zeroExists = true;\n zeroIndex = [column, row];\n column = size;\n row = size;\n break;\n }\n }\n }\n}\n\nfunction factorize (prime, num) {\n var count = 0;\n while (num % prime === 0) {num /= prime; count++}\n return count;\n}\n\nfunction accumulate (prime) {\n\n for (column = 0; column < size; column++) {\n\n accMatrix[column] = [];\n accPath[column] = [];\n\n for (row = 0; row < size; row++) {\n\n accMatrix[column][row] = factorize(prime, matrix[column][row]);\n\n if (column-1 >= 0 && row-1 >= 0) {\n\n if (accMatrix[column-1][row] < accMatrix[column][row-1]) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n }\n\n } else if (column-1 >= 0) {\n accMatrix[column][row] += accMatrix[column-1][row];\n accPath[column][row] = \"D\";\n } else if (row-1 >= 0) {\n accMatrix[column][row] += accMatrix[column][row-1];\n accPath[column][row] = \"R\";\n } else {\n accPath[column][row] = \"\";\n }\n\n }\n }\n\n return [accMatrix[size-1][size-1], accPath]\n\n}\n\nfunction findPath (items) {\n\n accMatrix = items[0];\n accPath = items[1];\n\n // print(`accMatrix: ${accMatrix}`)\n // print(`accPath: ${accPath}`)\n\n for(column = size-1; column >= 0;) {\n for (row = size-1; row >= 0;) {\n // print(`column: ${column}, row: ${row}`)\n if (column === 0 && row === 0) {\n column--; row--;\n break;\n }\n // print(`accPath[column][row]: ${accPath[column][row]}`)\n path = accPath[column][row] + path;\n if (accPath[column][row] === \"D\") column--;\n else row--;\n // print(`path: ${path}`)\n }\n }\n}\n\n// Wrong answer on test 27"}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\n\nvar line = [];\nvar num;\nvar countTwo = 0;\nvar countFive = 0;\n// put the inputs into 'matrix' two dimensional array\nfor (var i = 0; i < size; i++) {\n line = readline().split(\" \");\n\n // transform the input number into number of twos and fives\n for (var k = 0; k < line.length; k++) {\n num = line[k];\n countTwo = 0;\n countFive = 0;\n while (num % 2 === 0 && num % 5 === 0) {\n if (num % 2 !== 0) {\n num = num / 2;\n countTwo++;\n }\n if (num % 5 !== 0) {\n num = num / 5;\n countFive++;\n }\n }\n\n line[k] = {\n 2: countTwo,\n 5: countFive\n }\n }\n matrix.push(line);\n}\nprint(JSON.stringify(matrix));\n//\n// var result = [];\n// goNext([0, 0], \"\", {2: matrix[0][0][2], 5: matrix[0][0][5]});\n// getTheLeastRoundWay();\n//\n// // \uacbd\ub85c\ub97c \ub9cc\ub4dc\ub294 \uc7ac\uadc0\ud568\uc218\ub97c \ub9cc\ub4e0\ub2e4.\n// function goNext(currentIndex, way, numberOfTwoNFive) {\n// \n// if (endOfTheRoute(currentIndex)) {\n// result.push({way: way, trailingZeros: calculateTrailingZeros(numberOfTwoNFive)})\n// return;\n// }\n// // \uc544\ub798\ucabd \uc624\ub978\ucabd\uc73c\ub85c \uc774\ub3d9\n// if (canGoDown(currentIndex)) goNext(\n// [currentIndex[0] + 1, currentIndex[1]],\n// way + \"D\",\n// {\n// 2: numberOfTwoNFive[2] + matrix[currentIndex[0]+1][currentIndex[1]][2],\n// 5: numberOfTwoNFive[5] + matrix[currentIndex[0]+1][currentIndex[1]][5]\n// });\n// if (canGoRight(currentIndex)) goNext([currentIndex[0], currentIndex[1] + 1], way + \"R\", {\n// 2: numberOfTwoNFive[2] + matrix[currentIndex[0]][currentIndex[1]+1][2],\n// 5: numberOfTwoNFive[5] + matrix[currentIndex[0]][currentIndex[1]+1][5]\n// });\n// }\n//\n// function endOfTheRoute(currentIndex) {return currentIndex[0] === size - 1 && currentIndex[1] === size - 1;}\n// function canGoDown(currentIndex) {return currentIndex[0] !== size - 1;}\n// function canGoRight(currentIndex) {return currentIndex[1] !== size - 1;}\n//\n// function calculateTrailingZeros(numberOfTwoNFive) {\n// // print(JSON.stringify(numberOfTwoNFive));\n// var twos = numberOfTwoNFive[2];\n// var fives = numberOfTwoNFive[5];\n//\n// if (twos === 0 || fives === 0) return 0;\n// if (twos > fives) return fives;\n// else return twos;\n// }\n//\n// function getTheLeastRoundWay() {\n// result.sort((a, b) => a.trailingZeros - b.trailingZeros);\n// // print(JSON.stringify(result));\n// print(result[0].trailingZeros);\n// print(result[0].way);\n// }\n\n// Memory limit exceeded on test 11\uc744 \ud574\uacb0\ud574\uc57c\ud55c\ub2e4."}, {"source_code": "var size = Number(readline());\n\n// 1. \uc785\ub825\uac12\uc744 \ubc30\uc5f4\ub85c \uc815\ub82c\n// 2. \ud55c \ubc88\uc529 \uc21c\ud68c\ud558\uba74\uc11c 0\uc758 \uac1c\uc218\ub97c \uad6c\ud55c\ub2e4. (2\uc758 \ubc30\uc218\uc640 5\uc758 \ubc30\uc218\uc758 \uac1c\uc218)\n// 3. trailing zeros\uac00 \uac00\uc7a5 \uc801\uc740 \uacbd\ub85c\ub97c \uad6c\ud55c\ub2e4.\n\nvar matrix = [];\n\nvar line = [];\nvar num;\nvar countTwo = 0;\nvar countFive = 0;\n// put the inputs into 'matrix' two dimensional array\nfor (var i = 0; i < size; i++) {\n line = readline().split(\" \");\n\n // transform the input number into number of twos and fives\n for (var k = 0; k < line.length; k++) {\n num = line[k];\n countTwo = 0;\n while (num % 2 == 0) {\n num = num / 2;\n countTwo++;\n }\n num = line[k];\n countFive = 0;\n while (num % 5 == 0) {\n num = num / 5;\n countFive++;\n }\n\n line[k] = {\n 2: countTwo,\n 5: countFive\n }\n }\n matrix.push(line);\n}\n// print(JSON.stringify(matrix));\n\nvar result = [];\ngoNext([0, 0], \"\", {2: 0, 5: 0});\ngetTheLeastRoundWay();\n\n// \uacbd\ub85c\ub97c \ub9cc\ub4dc\ub294 \uc7ac\uadc0\ud568\uc218\ub97c \ub9cc\ub4e0\ub2e4.\nfunction goNext(currentIndex, way, numberOfTwoNFive) {\n\n numberOfTwoNFive[2] += matrix[currentIndex[0]][currentIndex[1]][2]\n numberOfTwoNFive[5] += matrix[currentIndex[0]][currentIndex[1]][5]\n\n if (endOfTheRoute(currentIndex)) {\n result.push({way: way, trailingZeros: calculateTrailingZeros(numberOfTwoNFive)})\n return;\n }\n // \uc544\ub798\ucabd \uc624\ub978\ucabd\uc73c\ub85c \uc774\ub3d9\n if (canGoDown(currentIndex)) goNext([currentIndex[0] + 1, currentIndex[1]], way += \"D\", numberOfTwoNFive);\n if (canGoRight(currentIndex)) goNext([currentIndex[0], currentIndex[1] + 1], way += \"R\", numberOfTwoNFive);\n}\n\nfunction endOfTheRoute(currentIndex) {return currentIndex[0] === size - 1 && currentIndex[1] === size - 1;}\n\nfunction canGoDown(currentIndex) {return currentIndex[0] !== size - 1;}\n\nfunction canGoRight(currentIndex) {return currentIndex[1] !== size - 1;}\n\nfunction calculateTrailingZeros(numberOfTwoNFive) {\n var twos = numberOfTwoNFive[2];\n var fives = numberOfTwoNFive[5];\n\n if (twos === 0 || fives === 0) return 0;\n if (twos > fives) return fives;\n else return twos;\n}\n\nfunction getTheLeastRoundWay() {\n result.sort((a, b) => a.trailingZeros - b.trailingZeros);\n print(result[0].trailingZeros)\n print(result[0].way)\n}"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = [];\n var pathContainsZero = []; // best path contains at least 1 zero\n\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n pathContainsZero[a] = [];\n\n for (var b = boundary; b > -1; b--) {\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[a][b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D'; // default down\n continue;\n }\n\n if (b < boundary && pathContainsZero[a][b + 1] && answerCounts[b] > 1) {\n // right contains zero and down > 1\n pathContainsZero[a][b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue;\n }\n\n if (a < boundary && pathContainsZero[a + 1][b] && answerCounts[b + 1] > 1) {\n // down contains zero and right > 1\n pathContainsZero[a][b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue;\n }\n\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nif (input[0][0] == 165558222 &&\n input[0][1] == 825553072 &&\n input[0][2] == 493144192 &&\n input[0][3] == 77595062 &&\n input[0][4] == 185402723 &&\n input[0][5] == 491298959) {\n for (var i = 0; i < count; i++) {\n print(input[i]);\n }\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = []; // array of arrays\n var pathContainsZero = []; // best path contains just 1 zero\n\n rowLoop:\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n\n columnLoop:\n for (var b = boundary; b > -1; b--) {\n\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n if (a < boundary) {\n answerPaths[a][b] = 'D'; // default down\n } else if (b < boundary) {\n answerPaths[a][b] = 'R';\n } else {\n answerPaths[a][b] = ''; // last node\n }\n continue columnLoop;\n }\n\n if (b < boundary && pathContainsZero[b + 1]) {\n // right contains zero\n if (a === boundary || answerCounts[b] > 0) {\n // there is no down or down count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue columnLoop;\n }\n }\n\n if (a < boundary && pathContainsZero[b]) {\n // down contains zero\n if (b === boundary || answerCounts[b + 1] > 0) {\n // there is no right or right count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D';\n continue columnLoop;\n }\n }\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n\n if (a > boundary || b > boundary) {\n print('error while recreating path');\n break;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = [];\n var pathContainsZero = []; // best path contains at least 1 zero\n\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n\n for (var b = boundary; b > -1; b--) {\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D'; // default down\n continue;\n }\n\n if (b < boundary && pathContainsZero[b + 1]) {\n // right contains zero\n if (a === boundary || answerCounts[b] > 0) {\n // there is no down or down count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue;\n }\n }\n\n if (a < boundary && pathContainsZero[b]) {\n // down contains zero\n if (b === boundary || answerCounts[b + 1] > 0) {\n // there is no right or right count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D';\n continue;\n }\n }\n\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "var count = parseInt(readline());\nvar matrix = [];\n\nfor (var i = 0; i < count; i++) {\n matrix.push(readline().split(' '));\n}\n\n// traverse all paths\nvar boundary = count - 1;\nvar completePaths = {};\ntraverse(0, 0, '', matrix[0][0]);\n\n// find least number of trailng zeros\nvar leastZeros = null;\nvar leastZerosPath = null;\nvar paths = Object.keys(completePaths);\nfor (var i = 0; i < paths.length; i++) {\n var path = paths[i];\n var zeros = countTrailingZeros(completePaths[path]);\n\n if (leastZeros === null || zeros < leastZeros) {\n leastZeros = zeros;\n leastZerosPath = path;\n }\n}\n\nprint(leastZeros);\nprint(leastZerosPath);\n\n\n\nfunction traverse(a, b, path, product) {\n var newProduct = product * matrix[a][b];\n\n if (a === boundary && b === boundary) {\n completePaths[path] = newProduct;\n return;\n }\n\n if (a < boundary) {\n traverse(a + 1, b, path + 'D', newProduct);\n }\n\n if (b < boundary) {\n traverse(a, b + 1, path + 'R', newProduct);\n }\n}\n\nfunction countTrailingZeros(input) {\n var count = 0;\n while (input % 10 === 0) {\n input /= 10;\n count++;\n }\n return count;\n}\n"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = []; // array of arrays\n var pathContainsZero = []; // best path contains just 1 zero\n\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n\n for (var b = boundary; b > -1; b--) {\n\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n if (a > 0) {\n answerPaths[a][b] = 'D'; // default down\n } else if (b > 0) {\n answerPaths[a][b] = 'R';\n } else {\n answerPaths[a][b] = ''; // last node\n }\n continue;\n }\n\n if (b < boundary && pathContainsZero[b + 1]) {\n // right contains zero\n if (a === boundary || answerCounts[b] > 0) {\n // there is no down or down count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue;\n }\n }\n\n if (a < boundary && pathContainsZero[b]) {\n // down contains zero\n if (b === boundary || answerCounts[b + 1] > 0) {\n // there is no right or right count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D';\n continue;\n }\n }\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "var count = parseInt(readline());\nvar matrix = [];\n\nfor (var i = 0; i < count; i++) {\n matrix.push(readline().split(' '));\n}\n\n// traverse all paths\nvar boundary = count - 1;\n\nvar leastZeros = null;\nvar leastZerosPath = null;\n\ntraverse(boundary, boundary, '', 1);\n\nprint(leastZeros);\nprint(leastZerosPath);\n\n\n// traverse backwards from end\nfunction traverse(a, b, path, product) {\n if (leastZeros === 0) {\n return;\n }\n\n var newProduct = product * matrix[a][b];\n // simplify product\n var matches = newProduct.toString().match(/^[123456789]*([123456789]0*)$/);\n newProduct = parseInt(matches[1]);\n\n if (a === 0 && b === 0) {\n var zeros = countTrailingZeros(newProduct);\n if (leastZeros === null || zeros < leastZeros) {\n leastZeros = zeros;\n leastZerosPath = path;\n }\n return;\n }\n\n if (b > 0) {\n traverse(a, b - 1, 'R' + path, newProduct);\n }\n\n if (a > 0) {\n traverse(a - 1, b, 'D' + path, newProduct);\n }\n}\n\nfunction countTrailingZeros(input) {\n var count = 0;\n while (input % 10 === 0) {\n input /= 10;\n count++;\n }\n return count;\n}\n"}, {"source_code": "/**\n * dynamic programming solution, process 2 and 5 separately b/c of RAM\n */\n\nvar count = parseInt(readline());\nvar input = new Array(count);\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = new Array(count);\n var answerPaths = new Array(count);\n\n for (var a = boundary; a > -1; a--) {\n answerCounts[a] = new Array(count);\n answerPaths[a] = new Array(count);\n\n for (var b = boundary; b > -1; b--) {\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[a][b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n if (answerCounts[a + 1][b] <= answerCounts[a][b + 1]) {\n answerCounts[a][b] = found + answerCounts[a + 1][b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[a][b] = found + answerCounts[a][b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[a][b] = found + answerCounts[a][b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[a][b] = found + answerCounts[a + 1][b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary && b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n }\n\n return [answerCounts[0][0], path];\n}\n"}, {"source_code": "/**\n * dynamic programming solution:\n * - process 2 and 5 separately b/c of RAM\n * - don't store full paths during traversal\n * - handle 0 in path\n */\n\nvar count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input[i] = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n}\n\nvar twos = traverseInReverse(input, count, findTwos);\nvar fives = traverseInReverse(input, count, findFives);\n\n// final answer is least of twos and fives\nif (twos[0] <= fives[0]) {\n print(twos[0]);\n print(twos[1]);\n} else {\n print(fives[0]);\n print(fives[1]);\n}\n\n// ------------------------------------------------------------------------\n\nfunction findTwos(input) {\n var output = 0;\n while (input % 2 === 0) {\n input /= 2;\n output++;\n }\n return output;\n}\n\nfunction findFives(input) {\n var output = 0;\n while (input % 5 === 0) {\n input /= 5;\n output++;\n }\n return output;\n}\n\nfunction traverseInReverse(input, count, findFn) {\n var downSolution, rightSolution, path;\n var boundary = count - 1;\n\n var answerCounts = [];\n var answerPaths = []; // array of arrays\n var pathContainsZero = []; // best path contains just 1 zero\n\n rowLoop:\n for (var a = boundary; a > -1; a--) {\n answerPaths[a] = [];\n\n columnLoop:\n for (var b = boundary; b > -1; b--) {\n\n // --- start check zero\n if (input[a][b] === 0) {\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n if (a < boundary) {\n answerPaths[a][b] = 'D'; // default down\n } else if (b < boundary) {\n answerPaths[a][b] = 'R';\n } else {\n answerPaths[a][b] = ''; // last node\n }\n continue columnLoop;\n }\n\n if (b < boundary && pathContainsZero[b + 1]) {\n // right contains zero\n if (a === boundary || answerCounts[b] > 0) {\n // there is no down or down count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'R';\n continue columnLoop;\n }\n }\n\n if (a < boundary && pathContainsZero[b]) {\n // down contains zero\n if (b === boundary || answerCounts[b + 1] > 0) {\n // there is no right or right count is gt 0\n pathContainsZero[b] = true;\n answerCounts[b] = 1;\n answerPaths[a][b] = 'D';\n continue columnLoop;\n }\n }\n // --- end check zero\n\n var found = findFn(input[a][b]);\n\n if (a === boundary && b === boundary) {\n // last node\n answerCounts[b] = found;\n answerPaths[a][b] = '';\n } else if (a < boundary && b < boundary) {\n // down and right available\n // existing answerCounts[b] is from previous row\n if (answerCounts[b] <= answerCounts[b + 1]) {\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n } else {\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n }\n } else if (a === boundary && b < boundary) {\n // right available\n answerCounts[b] = found + answerCounts[b + 1];\n answerPaths[a][b] = 'R';\n } else if (a < boundary && b === boundary) {\n // down available\n answerCounts[b] = found + answerCounts[b];\n answerPaths[a][b] = 'D';\n }\n }\n }\n\n // recreate path\n var a = 0;\n var b = 0;\n var path = '';\n while (a < boundary || b < boundary) {\n var next = answerPaths[a][b];\n path += next;\n if (next == 'D') {\n a++;\n } else {\n b++;\n }\n\n if (a > boundary || b > boundary) {\n print('error while recreating path');\n break;\n }\n }\n\n return [answerCounts[0], path];\n}\n"}, {"source_code": "var count = parseInt(readline());\nvar matrix = [];\n\nfor (var i = 0; i < count; i++) {\n matrix.push(readline().split(' '));\n}\n\n// traverse all paths\nvar boundary = count - 1;\n\nvar leastZeros = null;\nvar leastZerosPath = null;\n\ntraverse(boundary, boundary, '', 1);\n\nprint(leastZeros);\nprint(leastZerosPath);\n\n\n// traverse backwards from end\nfunction traverse(a, b, path, product) {\n if (leastZeros === 0) {\n return;\n }\n\n var newProduct = product * matrix[a][b];\n if (a === 0 && b === 0) {\n var zeros = countTrailingZeros(newProduct);\n if (leastZeros === null || zeros < leastZeros) {\n leastZeros = zeros;\n leastZerosPath = path;\n }\n return;\n }\n\n if (b > 0) {\n traverse(a, b - 1, 'R' + path, newProduct);\n }\n\n if (a > 0) {\n traverse(a - 1, b, 'D' + path, newProduct);\n }\n}\n\nfunction countTrailingZeros(input) {\n var count = 0;\n while (input % 10 === 0) {\n input /= 10;\n count++;\n }\n return count;\n}\n"}, {"source_code": "var n = +readline();\nvar array = [];\nvar CP2 = [];\nvar P2 = [];\nvar CP5 = [];\nvar P5 = [];\n\nn = 1000;\n\nvar factorization = function(value) {\n var result = [0, 0];\n\n while (value % 2 === 0) {\n value /= 2;\n ++result[0];\n }\n\n while (value % 5 === 0) {\n value /= 5;\n ++result[1];\n }\n\n return result;\n};\n\nfor (var i = 0; i < n; ++i) {\n array.push([]);\n CP2.push([]);\n P2.push([]);\n CP5.push([]);\n P5.push([]);\n\n var values = [];\n for (var j = 0; j < n; ++j) {\n array[i].push(factorization(+values[j]));\n CP2[i].push(null);\n P2[i].push(null);\n CP5[i].push(null);\n P5[i].push(null);\n }\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n \n if (i === 0 && j === 1) {var lol = value;}\n\n array2[i].push(0);\n array5[i].push(0);\n\n if (lol != 600998816) {\n while (value % 2 === 0) {\n value /= 2;\n ++array2[i][j];\n }\n \n while (value % 5 === 0) {\n value /= 5;\n ++array5[i][j];\n }\n }\n }\n}\n\nif (lol == 600998816) {\n write('LOL');\n quit(0);\n}\n\nvar foo = function(array) {\n var i, j, cnt;\n\n array[0][0] = array[0][0];\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1, cnt = 0; i !== 0 || j !== 0; ++cnt) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n} else {\n write(result5[0] + '\\n');\n write(result5[1]);\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n \n if (i === 0 && j === 0) {var lol = value;}\n\n array2[i].push(0);\n array5[i].push(0);\n\n while (value % 2 === 0) {\n value /= 2;\n ++array2[i][j];\n }\n\n while (value % 5 === 0) {\n value /= 5;\n ++array5[i][j];\n }\n }\n}\n\nif (lol == 515762700) {\n write('LOL');\n quit(0);\n}\n\nvar foo = function(array) {\n var i, j, cnt;\n\n array[0][0] = array[0][0];\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1, cnt = 0; i !== 0 || j !== 0; ++cnt) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n} else {\n write(result5[0] + '\\n');\n write(result5[1]);\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n }\n}\n\nvar foo = function(array) {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n} else {\n write(result5[0] + '\\n');\n write(result5[1]);\n}"}, {"source_code": "var n = +readline();\nvar array = [];\nvar CP = [];\nvar P = [];\n\nvar factorization = function(value) {\n var result = [0, 0];\n\n while (value % 2 === 0) {\n value /= 2;\n ++result[0];\n }\n\n while (value % 5 === 0) {\n value /= 5;\n ++result[1];\n }\n\n return result;\n};\n\nfor (var i = 0; i < n; ++i) {\n array.push([]);\n CP.push([]);\n P.push([]);\n\n var values = readline().split(' ');\n for (var j = 0; j < n; ++j) {\n array[i].push(factorization(+values[j]));\n CP[i].push(null);\n P[i].push(null);\n }\n}\n\nvar sum = function(result1, result2) {\n return [result1[0] + result2[0], result1[1] + result2[1]];\n};\n\nvar min = function(resultR, resultD, h, w) {\n var a1 = Math.min(resultR[0], resultR[1]);\n var a2 = Math.min(resultD[0], resultD[1]);\n\n if (a1 < a2) {\n P[h][w] = 'R';\n return resultR;\n } else {\n P[h][w] = 'D';\n return resultD;\n }\n};\n\nvar DP = function(n) {\n var foo = function foo(h, w) {\n if (CP[h][w] !== null) {\n return CP[h][w];\n }\n\n if (h === 0 && w === 0) {\n return CP[h][w] = array[0][0];\n }\n\n if (h === 0) {\n P[h][w] = 'R';\n return CP[h][w] = sum(foo(h, w - 1), array[h][w]);\n }\n\n if (w === 0) {\n P[h][w] = 'D';\n return CP[h][w] = sum(foo(h - 1, w), array[h][w]);\n }\n\n return CP[h][w] = sum(min(foo(h, w - 1), foo(h - 1, w), h, w), array[h][w]);\n };\n\n var result = foo(n - 1, n - 1);\n\n return Math.min(result[0], result[1]);\n};\n\nwrite(DP(n) + '\\n');\n\n// for(var i = 0; i < n;++i) {\n// write(CP[i].join('|') + '\\n')\n// }\n\nvar path = '';\nfor (var i = n - 1, j = n - 1; ;) {\n path = P[i][j] + path;\n\n if (P[i][j] === 'R') {\n --j;\n } else if (P[i][j] === 'D') {\n --i;\n }\n\n if (i === 0 && j === 0) {\n break;\n }\n}\n\nwrite(path);\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nvar hasZero = false;\nvar pathZero;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n\n if (value === 0) {\n if (!hasZero) {\n hasZero = true;\n pathZero =\n (new Array(i + 1)).join('D') +\n (new Array(n)).join('R') +\n (new Array(n - i)).join('D');\n }\n\n array2[i].push(Infinity);\n array5[i].push(Infinity);\n } else {\n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n }\n }\n}\n\nvar foo = function() {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array2[0][i] = array2[0][i - 1] + array2[0][i];\n array5[0][i] = array5[0][i - 1] + array5[0][i];\n path[0][i] = 'R';\n\n array2[i][0] = array2[i - 1][0] + array2[i][0];\n array5[i][0] = array5[i - 1][0] + array5[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR2 = array2[i][j - 1];\n var resultD2 = array2[i - 1][j];\n\n var resultR5 = array5[i][j - 1];\n var resultD5 = array5[i - 1][j];\n\n if (Math.min(resultR2, resultR5) < Math.min(resultD2, resultD5)) {\n array2[i][j] = resultR2 + array2[i][j];\n array5[i][j] = resultR5 + array5[i][j];\n path[i][j] = 'R';\n } else {\n array2[i][j] = resultD2 + array2[i][j];\n array5[i][j] = resultD5 + array5[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [Math.min(array2[n - 1][n - 1], array5[n - 1][n - 1]), result];\n};\n\nvar result = foo();\n\nif (hasZero && result[0] >= 1) {\n write('1\\n');\n write(pathZero);\n} else {\n write(result[0] + '\\n');\n write(result[1]);\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n\n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n }\n}\n\nvar foo = function() {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array2[0][i] = array2[0][i - 1] + array2[0][i];\n array5[0][i] = array5[0][i - 1] + array5[0][i];\n path[0][i] = 'R';\n \n array2[i][0] = array2[i - 1][0] + array2[i][0];\n array5[i][0] = array5[i - 1][0] + array5[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR2 = array2[i][j - 1] + array2[i][j];\n var resultR5 = array5[i][j - 1] + array5[i][j];\n \n var resultD2 = array2[i - 1][j] + array2[i][j];\n var resultD5 = array5[i - 1][j] + array5[i][j];\n\n if (Math.min(resultR2, resultR5) < Math.min(resultD2, resultD5)) {\n array2[i][j] = resultR2;\n array5[i][j] = resultR5;\n path[i][j] = 'R';\n } else {\n array2[i][j] = resultD2;\n array5[i][j] = resultD5;\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [Math.min(array2[n - 1][n - 1], array5[n - 1][n - 1]), result];\n};\n\nvar result = foo(array2);\n\nwrite(result[0] + '\\n');\nwrite(result[1]);\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n array2[i].push(value.toString(2).match(re)[0].length);\n array5[i].push(value.toString(5).match(re)[0].length);\n\n // while (value % 2 === 0) {\n // value /= 2;\n // ++array2[i][j];\n // }\n //\n // while (value % 5 === 0) {\n // value /= 5;\n // ++array5[i][j];\n // }\n }\n}\n\nvar foo = function(array) {\n var i, j;\n\n array[0][0] = array[0][0];\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n} else {\n write(result5[0] + '\\n');\n write(result5[1]);\n}\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar array2_ = [];\nvar array5_ = [];\n\nvar path = [];\n\nvar re = /0*$/;\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n array2_.push([]);\n array5_.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n var value2 = value.toString(2).match(re)[0].length;\n var value5 = value.toString(5).match(re)[0].length;\n\n array2[i].push(value2);\n array5[i].push(value5);\n \n array2_[i].push(value2);\n array5_[i].push(value5);\n }\n}\n\nvar foo = function(array) {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar foo25 = function() {\n var i, j;\n\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array2[0][i] = array2[0][i - 1] + array2[0][i];\n array5[0][i] = array5[0][i - 1] + array5[0][i];\n path[0][i] = 'R';\n \n array2[i][0] = array2[i - 1][0] + array2[i][0];\n array5[i][0] = array5[i - 1][0] + array5[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR2 = array2[i][j - 1] + array2[i][j];\n var resultR5 = array5[i][j - 1] + array5[i][j];\n \n var resultD2 = array2[i - 1][j] + array2[i][j];\n var resultD5 = array5[i - 1][j] + array5[i][j];\n\n if (Math.min(resultR2, resultR5) < Math.min(resultD2, resultD5)) {\n array2[i][j] = resultR2;\n array5[i][j] = resultR5;\n path[i][j] = 'R';\n } else {\n array2[i][j] = resultD2;\n array5[i][j] = resultD5;\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1; i !== 0 || j !== 0;) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [Math.min(array2[n - 1][n - 1], array5[n - 1][n - 1]), result];\n};\n\nvar result = [foo(array2_), foo(array5_), foo25()];\n\nvar MIN = Infinity;\nvar iMIN;\nfor (var i = 0; i < result.length; ++i) {\n if (MIN > result[i][0]) {\n MIN = result[i][0];\n iMIN = i;\n }\n}\n\nwrite(result[iMIN][0] + '\\n');\nwrite(result[iMIN][1]);\n"}, {"source_code": "var n = +readline();\nvar array = [];\nvar CP = [];\nvar P = [];\n\nvar factorization = function(value) {\n var result = [0, 0];\n\n while (value % 2 === 0) {\n value /= 2;\n ++result[0];\n }\n\n while (value % 5 === 0) {\n value /= 5;\n ++result[1];\n }\n\n return result;\n};\n\nfor (var i = 0; i < n; ++i) {\n array.push([]);\n CP.push([]);\n P.push([]);\n\n var values = readline().split(' ');\n for (var j = 0; j < n; ++j) {\n array[i].push(factorization(+values[j]));\n CP[i].push(null);\n P[i].push(null);\n }\n}\n\nvar sum = function(result1, result2) {\n return [result1[0] + result2[0], result1[1], result2[1]];\n};\n\nvar min = function(resultR, resultD, h, w) {\n var a1 = Math.min(resultR[0], resultR[1]);\n var a2 = Math.min(resultD[0], resultD[1]);\n\n if (a1 < a2) {\n P[h][w] = 'R';\n return resultR;\n } else {\n P[h][w] = 'D';\n return resultD;\n }\n};\n\nvar DP = function(n) {\n var foo = function foo(h, w) {\n if (CP[h][w] !== null) {\n return CP[h][w];\n }\n\n if (h === 0 && w === 0) {\n return array[0][0];\n }\n\n if (h === 0) {\n P[h][w] = 'R';\n return sum(foo(h, w - 1), array[h][w]);\n }\n\n if (w === 0) {\n P[h][w] = 'D';\n return sum(foo(h - 1, w), array[h][w]);\n }\n\n return CP[h][w] = sum(min(foo(h, w - 1), foo(h - 1, w), h, w), array[h][w]);\n };\n\n var result = foo(n - 1, n - 1);\n\n return Math.min(result[0], result[1]);\n};\n\nwrite(DP(n) + '\\n');\n\nvar path = '';\nfor (var i = n - 1, j = n - 1; ;) {\n path = P[i][j] + path;\n\n if (P[i][j] === 'R') {\n --j;\n } else if (P[i][j] === 'D') {\n --i;\n }\n\n if (i === 0 && j === 0) {\n break;\n }\n}\n\nwrite(path);\n"}, {"source_code": "var n = +readline();\n\nvar array2 = [];\nvar array5 = [];\n\nvar path = [];\n\nfor (var i = 0; i < n; ++i) {\n array2.push([]);\n array5.push([]);\n\n path.push([]);\n\n var values = readline().split(' ');\n\n for (var j = 0; j < n; ++j) {\n var value = +values[j];\n \n if (i === 0 && j === 1) {var lol = value;}\n\n array2[i].push(0);\n array5[i].push(0);\n\n if (lol != 600998816) {\n while (value % 2 === 0) {\n value /= 2;\n ++array2[i][j];\n }\n\n while (value % 5 === 0) {\n value /= 5;\n ++array5[i][j];\n }\n }\n }\n}\n\nif (lol == 600998816) {\n write('LOL');\n quit(0);\n}\n\nvar foo = function(array) {\n var i, j, cnt;\n\n array[0][0] = array[0][0];\n path[0][0] = '#';\n\n for (i = 1; i < n; ++i) {\n array[0][i] = array[0][i - 1] + array[0][i];\n path[0][i] = 'R';\n \n array[i][0] = array[i - 1][0] + array[i][0];\n path[i][0] = 'D';\n }\n\n for (i = 1; i < n; ++i) {\n for (j = 1; j < n; ++j) {\n var resultR = array[i][j - 1];\n var resultD = array[i - 1][j];\n\n if (resultR < resultD) {\n array[i][j] = resultR + array[i][j];\n path[i][j] = 'R';\n } else {\n array[i][j] = resultD + array[i][j];\n path[i][j] = 'D';\n }\n }\n }\n\n var result = '';\n for (i = n - 1, j = n - 1, cnt = 0; i !== 0 || j !== 0; ++cnt) {\n (result = path[i][j] + result)[0] === 'R' ? --j : --i;\n }\n\n return [array[n - 1][n - 1], result];\n};\n\nvar result2 = foo(array2);\nvar result5 = foo(array5);\n\nif (result2[0] < result5[0]) {\n write(result2[0] + '\\n');\n write(result2[1]);\n} else {\n write(result5[0] + '\\n');\n write(result5[1]);\n}\n"}], "src_uid": "13c58291ab9cf7ad1b8c466c3e36aacf"} {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar h = readline().split(' ').map(Number);\nvar j = 0;\nvar min_sum = h.slice(0, k).reduce((a, b) => a + b);\nvar sum = min_sum;\nfor (var i = k; i < n; i++) {\n sum = sum - h[i - k] + h[i];\n if (sum < min_sum) {\n min_sum = sum;\n j = i - k + 1\n }\n}\nprint(j + 1);", "positive_code": [{"source_code": "var n = readline().split(/\\s/gi).map(Number),\n\t\t\tk = n[1], n = n[0],\n\t\t\theights = readline().split(/\\s/gi).map(Number),\n\t\t\tsumH = heights.slice(0, k).reduce(function(a, b) { return a + b; }),\n\t\t\ttArr = [ sumH ], resultIndex = 0;\n\n\t\tfor(var i = 1; i <= n - k; i++)\t{\n\t\t\tvar prevSumH = tArr[tArr.length - 1],\n\t\t\t\tminSumH;\n\n\t\t\tsumH = sumH - heights[i - 1] + heights[i + k - 1];\n\t\t\tminSumH = Math.min(prevSumH, sumH);\n\t\t\t// console.log(heights.slice(k - 1, k - 1 + k));\n\t\t\t// console.log(sumH);\n\n\t\t\tif(sumH == minSumH)\tresultIndex = i;\n\t\t\ttArr.push(minSumH);\n\t\t}\n\n\t\tprint(resultIndex + 1);"}, {"source_code": "var optimalStartPoint = function ( planks, k ) {\n var optimal, \n minSum,\n sum,\n i;\n \n minSum = 0;\n optimal = 0;\n for ( i = 0; i < k; ++i ) {\n minSum += planks[ i ];\n }\n sum = minSum;\n \n for ( i = 1; i < planks.length - k + 1; ++i ) {\n sum = sum - planks[ i - 1 ] + planks[ i + k - 1 ];\n if ( sum < minSum ) {\n minSum = sum;\n optimal = i;\n }\n }\n return optimal;\n};\n\nvar input = readline().split( \" \" ).map( i => parseInt( i, 10 ) );\nvar k = input[ 1 ];\nvar planks = readline().split( \" \" ).map( hi => parseInt( hi, 10 ) );\nprint( optimalStartPoint( planks, k ) + 1 );"}, {"source_code": "print(function(n, k) {\n\tvar sum = 0,\n\t\tans = 0,\n\t\tmin = 1e8,\n\t\td = ('0 ' + readline()).split(' ').map(Number).map(function(v) {\n\t\t\treturn sum += v;\n\t\t}).map(function(v, i, s) {\n\t\t\treturn i + k <= n ? s[i + k] - s[i] : 1e8;\n\t\t});\n\n\tfor (var i = 0; i <= n - k + 1; i++) {\n\t\tif (d[i] < min)\n\t\t\tmin = d[i], ans = i;\n\t}\n\treturn ans + 1;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, k) {\n\n\tvar sum = 0,\n\t\tans = 0,\n\t\tmin = 1e8,\n\t\td = ('0 ' + readline()).split(' ').map(Number).map(function(v) {\n\t\t\treturn sum += v;\n\t\t}).map(function(v, i, s) {\n\t\t\treturn i + k <= n ? s[i + k] - s[i] : 1e8;\n\t\t});\n\n\tfor (var i = 0; i <= n - k + 1; i++)\n\t\tif (d[i] < min)\n\t\t\tmin = d[i],\n\t\t\tans = i;\n\n\treturn ans + 1;\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "(function main() {\n var nk = readline().split(' ').map(function(x) {return parseInt(x);});\n var n = nk[0];\n var k = nk[1];\n var a = readline().split(' ').map(function(x) {return parseInt(x);});\n var s = 0;\n var mins = s;\n var mini = 1;\n for (var i = k; i < n; ++i) {\n s += a[i] - a[i - k];\n if (s < mins) {\n mins = s;\n mini = i - k + 2;\n }\n }\n print(mini);\n})();"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar inp = rda(), n = inp[0], k = inp[1];\ndelete inp;\nvar h = rda();\n\nfor(var i = 0, s = 0; i < n; i++){\n s += h[i];\n h[i] = s;\n}\n\nvar val = h[k-1];\nvar ans = k-1;\nfor(var i = k; i < n; i++){\n if((h[i]-h[i-k]) < val){\n val = h[i]-h[i-k];\n ans = i;\n }\n}\n\nwrite(ans+2-k);"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n k = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n // NOT ar.sort(function(a, b){return a-b});\n\n // ar = [1, 2, 6, 1, 1, 7, 1];\n // k = 3;\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n ar.splice(0,0,0);\n\n print((function() {\n var count = 999999999;\n var index = -1;\n for(var i = k; i < ar.length; ++i) {\n var tmp = ar[i]-ar[i-k]\n if (count > tmp) {\n index = i - k + 1;\n count = tmp;\n }\n }\n return index;\n })());\n})();"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0];\nvar k = input[1];\nvar a = readline().split(' ').map(Number);\nvar ans = 0;\nvar minsum = a.slice(0, k).reduce((a, b) => a + b);\nvar sum = minsum;\nfor (var i = k; i < a.length; i++) {\n\tvar sum = sum + a[i] - a[i - k];\n\tif (sum < minsum) {\n\t\tminsum = sum;\n\t\tans = i - k + 1;\n\t}\n}\n\nprint(ans + 1);\n"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar h = readline().split(' ').map(Number);\nvar j = 0, min_sum = 0, sum = 0;\nfor (var i = k; i < n; i++) {\n sum = sum - h[i - k] + h[i];\n if (sum < min_sum) {\n min_sum = sum;\n j = i - k + 1\n }\n}\nprint(j + 1);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const [len, k] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n let [min, minIndex, sum] = [Infinity, 0, 0];\n\n for (let i = 0; i < k; i++) sum += arr[i];\n\n min = sum;\n for (let i = k; i < len; i++) {\n sum = sum + arr[i] - arr[i - k];\n if (sum < min) {\n min = sum;\n minIndex = i - k + 1;\n }\n }\n\n console.log(minIndex + 1);\n}\n"}, {"source_code": "var x = new Array();\nvar n,k;\nvar buff = new Array();\nfunction read() {\n\treturn readline().split(' ').map(Number);\n}\nfunction main() {\n\tbuff=read();\n\tn=buff[0],k=buff[1];\n\tbuff=read();\n\tx[0]=0;\n\tfor (var i=1; i<=n; i++) {\n\t\tx[i]=x[i-1]+buff[i-1];\n\t}\n\tvar ans=1<<31-1,pos=0;\n\tfor (var i=1; i<=n-k+1; i++) {\n\t\tif (ans>x[i+k-1]-x[i-1]) {\n\t\t\tans=x[i+k-1]-x[i-1];\n\t\t\tpos=i;\n\t\t}\n\t}\n\tprint(pos);\n}\nmain();"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', line => input.push(line));\n\nRL.on('close', () => {\n const [n, k] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n let memory = 0; minSum = 0; let pos = 1;\n for (let i = 0; i < k; i += 1) {\n memory += nums[i];\n }\n minSum = memory;\n\n let j = 0;\n for (let i = k; i < n; i += 1) {\n memory = memory - nums[j] + nums[i];\n if (memory < minSum) {\n minSum = memory; pos = j + 2;\n }\n j += 1;\n }\n\n console.log(pos);\n});"}, {"source_code": ";(function () {\n\n print(function (n, k) {\n var h = readline().split(' ').map(Number),\n r = 0, t = 0, l = 0;\n\n for (var i = 0; i < k; i++) {\n r += h[i];\n }\n\n l = r;\n\n for (var i = 1, _i = n - k + 1; i < _i; i++) {\n var d = r - h[i - 1] + h[i + k - 1];\n if (d < l) {\n t = i;\n l = d;\n }\n\n r = d;\n }\n\n return t + 1;\n }.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var k = line[1];\n var data = readline().split(' ').map(Number);\n var sum = 0;\n for(var i=0;i a + b);\nfor (var i = k; i < a.length; i++) {\n\tvar sum = minsum + a[i] - a[i - k];\n\tif (sum < minsum) {\n\t\tminsum = sum;\n\t\tans = i;\n\t}\n}\n\nprint(ans - 1);\n"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0];\nvar k = input[1];\nvar a = readline().split(' ').map(Number);\nvar ans = 0;\nvar minsum = a.slice(0, k).reduce((a, b) => a + b);\nfor (var i = k; i < a.length; i++) {\n\tvar sum = minsum + a[i] - a[i - k];\n\tif (sum < minsum) {\n\t\tminsum = sum;\n\t\tans = i;\n\t}\n}\n\nprint(ans - 1);\n"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0];\nvar k = input[1];\nvar a = readline().split(' ').map(Number);\nvar ans = 2;\nvar minsum = a.slice(0, k).reduce((a, b) => a + b);\nvar sum = minsum;\nfor (var i = k; i < a.length; i++) {\n\tvar sum = sum + a[i] - a[i - k];\n\tif (sum < minsum) {\n\t\tminsum = sum;\n\t\tans = i;\n\t}\n}\n\nprint(ans - 1);\n"}, {"source_code": "var x = new Array();\nvar n,k;\nvar buff = new Array();\nfunction read() {\n\treturn readline().split(' ').map(Number);\n}\nfunction main() {\n\tbuff=read();\n\tn=buff[0],k=buff[1];\n\tbuff=read();\n\tfor (var i=0; i parseInt( i, 10 ) );\nvar k = input[ 1 ];\nvar planks = readline().split( \" \" ).map( hi => parseInt( hi, 10 ) );\nprint( optimalStartPoint( planks, k ) + 1 );"}, {"source_code": "var optimalStartPoint = function ( planks, k ) {\n var optimal, \n minSum,\n sum,\n i;\n \n minSum = 0;\n sum = 0;\n optimal = 0;\n for ( i = 0; i < k; ++i ) {\n minSum += planks[ i ];\n }\n \n for ( i = 1; i < planks.length - k + 1; ++i ) {\n sum = sum - planks[ i - 1 ] + planks[ i + k - 1 ];\n if ( sum < minSum ) {\n minSum = sum;\n optimal = i;\n }\n }\n return optimal;\n};\n\nvar input = readline().split( \" \" ).map( i => parseInt( i, 10 ) );\nvar k = input[ 1 ];\nvar planks = readline().split( \" \" ).map( hi => parseInt( hi, 10 ) );\nprint( optimalStartPoint( planks, k ) + 1 );"}], "src_uid": "69f4e340b3f6e1d807e0545ebea1fe2f"} {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n] = lines[curLine++].split(' ').map((x) => parseInt(x))\n for (let r = 0; r < n; r++) {\n console.log(lines[curLine++].split(' ').map((x, c) => parseInt(x) + (r + c + parseInt(x)) % 2).join(' '))\n }\n }\n})\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [rowLen, colLen] = readLine().split(\" \").map(Number);\n const arr = [];\n let i = 0;\n while (i++ < rowLen) {\n const row = readLine().split(\" \").map(Number);\n arr.push(row);\n }\n for (let row = 0; row < rowLen; row++) {\n for (let col = 0; col < colLen; col++) {\n if ((row + col) % 2 === 0) {\n if (arr[row][col] % 2 === 1) arr[row][col]++;\n } else {\n if (arr[row][col] % 2 === 0) arr[row][col]++;\n }\n }\n }\n for (let row = 0; row < rowLen; row++) console.log(arr[row].join(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n, m] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const mat = new Array(n)\n const cells = []\n for (let r = 0; r < n; r++) {\n mat[r] = lines[curLine++].split(' ').map((x) => parseInt(x))\n for (let c = 0; c < m; c++) {\n cells.push([r, c])\n }\n }\n cells.sort(([ra, ca], [rb, cb]) => mat[ra][ca] - mat[rb][cb])\n cells.forEach(([r, c]) => {\n const delta = [[1, 0], [-1, 0], [0, 1], [0, -1]]\n let change = false\n delta.forEach(([dr, dc]) => {\n const nr = r + dr\n const nc = c + dc\n \n if (nr < 0 || nr >= n || nc < 0 || nc >= m) {\n return\n }\n\n if (mat[nr][nc] === mat[r][c]) {\n change = true\n }\n })\n\n if (change) {\n mat[r][c]++\n }\n })\n\n for (let r = 0; r < n; r++) {\n console.log(mat[r].join(' '))\n } \n } \n})\n"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n, m] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const mat = new Array(n)\n const cells = []\n for (let r = 0; r < n; r++) {\n mat[r] = lines[curLine++].split(' ').map((x) => parseInt(x))\n for (let c = 0; c < m; c++) {\n cells.push([r, c])\n }\n }\n cells.sort(([ra, ca], [rb, cb]) => mat[ra][ca] - mat[rb][cb])\n for (let rem = 0; rem < 2; rem++) {\n cells.forEach(([r, c]) => {\n if ((r + c) % 2 !== rem) {\n return\n }\n \n const delta = [[1, 0], [-1, 0], [0, 1], [0, -1]]\n let change = false\n delta.forEach(([dr, dc]) => {\n const nr = r + dr\n const nc = c + dc\n \n if (nr < 0 || nr >= n || nc < 0 || nc >= m) {\n return\n }\n\n if (mat[nr][nc] === mat[r][c]) {\n change = true\n }\n })\n\n if (change) {\n mat[r][c]++\n }\n })\n }\n\n for (let r = 0; r < n; r++) {\n console.log(mat[r].join(' '))\n } \n } \n})\n"}], "src_uid": "fd11967b07870be3294b9191603b17e8"} {"source_code": "'use strict'\n\nlet inp = readline()\nlet N = +readline()\nlet lll\n\nlet dic = []\nwhile (lll = readline()) {\n dic.push(lll)\n}\n\nprint(dic.filter(w => w.startsWith(inp)).sort()[0] || inp)", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar prefix = trim(readline());\n\n\tvar numCandidates = parseInt(readline(), 10),\n\t\tcandidates = new Array(numCandidates);\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tcandidates[candidateIndex] = trim(readline());\n\t}\n\n\tcandidates.sort();\n\n\tvar regex = new RegExp(\"^\"+prefix);\n\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tif (regex.test(candidates[candidateIndex])) {\n\t\t\tprint(candidates[candidateIndex]);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(prefix);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar prefix = trim(readline());\n\n\tvar numCandidates = parseInt(readline(), 10),\n\t\tcandidates = new Array(numCandidates);\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tcandidates[candidateIndex] = trim(readline());\n\t}\n\n\tcandidates.sort();\n\n\tvar regex = new RegExp(\"^\"+prefix);\n\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tif (candidates[candidateIndex].match(regex)) {\n\t\t\tprint(candidates[candidateIndex]);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(prefix);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar prefix = trim(readline()),\n\t\tprefixLength = prefix.length;\n\n\tvar numCandidates = parseInt(readline(), 10),\n\t\tcandidates = new Array(numCandidates);\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tcandidates[candidateIndex] = trim(readline());\n\t}\n\n\tcandidates.sort();\n\n\tfor (var candidateIndex = 0; candidateIndex < numCandidates; ++candidateIndex) {\n\t\tif (candidates[candidateIndex].substring(0, prefixLength) == prefix) {\n\t\t\tprint(candidates[candidateIndex]);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(prefix);\n}\n\nmain();\n"}, {"source_code": "var input = readline();\nvar check = new RegExp('^' + input);\nvar iteration = readline();\n\nvar result;\n\nfor (var i = 0; i < iteration; i++) {\n\tvar currentInput = readline();\n\t//currentInput.match(check)&& result?(( currentInput < result)&&result = currentInput):\tresult = currentInput\n\tif (currentInput.match(check)) {\n\nresult? (currentInput < result?\tresult = currentInput:result):(result = currentInput)\n\t}\n\n}\n \n\n\n!!result? print(result):print(input)\n\n"}, {"source_code": "var word = readline();\nvar re = new RegExp('^' + word);\nvar n = parseInt(readline());\nvar res;\nfor (var i = 0; i < n; i++) {\n\tvar input = readline();\n\tif (input.match(re)) {\n\t\tif (res) {\n\t\t\tif (input < res) {\n\t\t\t\tres = input;\n\t\t\t}\n\t\t} else {\n\t\t\tres = input;\n\t\t}\n\t}\n}\n\nif (res) {\n\tprint(res);\n} else {\n\tprint(word);\n}\n"}], "negative_code": [{"source_code": "var input = readline();\nvar iteration = readline();\nvar check = new RegExp('^' + input);\n \nvar result;\n \nfor (var i = 0; i < iteration; i++) {\n\tvar currentInput = readline();\n\tcurrentInput.match(check)&& result? (currentInput < result? result = currentInput : result) : (result = currentInput)\n}\n!!result? print(result):print(input)"}, {"source_code": "var input = readline();\nvar iteration = readline();\nvar check = new RegExp('^' + input);\n\nvar result;\n\nfor (var i = 0; i < iteration; i++) {\n\tvar currentInput = readline();\n\tcurrentInput.match(check)&& result? (currentInput < result? (result = currentInput) : result) : (result = currentInput)\n}\n!!result? print(result):print(input)\n\n"}], "src_uid": "5ad16e23e96de111c4974551b859a5ff"} {"source_code": "var x=parseInt(readline());\nvar arr=readline().split(' ').map(a => parseInt(a));\n\narr.sort((a,b) => a-b);\n\nfor(var i=arr.length-1; i>=0; i--){\n var sqrt= Math.floor(Math.sqrt(arr[i]));\n if(sqrt*sqrt !== arr[i]){\n print(arr[i]);\n break;\n }else\n continue;\n}", "positive_code": [{"source_code": "n=parseInt(readline());\nmas=readline().split(' ');\nfunction compareNumeric(a, b) {\n if (a > b) return 1;\n if (a < b) return -1;\n}\nfor(i=0;i Number.parseInt(x));\n\nfunction isPerfect(x){\n var comp = Math.sqrt(x).toFixed(0)\n\n return x == comp * comp;\n}\nvar max = -Infinity;\nfor(var i = 0; i < nums.length; i++){\n if(!isPerfect(nums[i])){\n max = Math.max(max, nums[i]);\n }\n}\n\nprint(max);"}, {"source_code": "readline()\nprint(readline().split(' ').map(x=>+x).reduce((a,c)=>Math.pow(Math.trunc(Math.sqrt(c)),2)!==c?Math.max(a,c):a,-10000000))\n\n"}, {"source_code": "readline() \nprint(readline().split(' ').map(x=>+x).reduce((a,c)=>Math.pow(Math.trunc(Math.sqrt(c)),2)!==c?Math.max(a,c):a,-10000000))\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i < arr.length; i++) {\n if (!Number.isInteger(Math.sqrt(arr[i]))) {\n console.log(arr[i]);\n break;\n }\n }\n\n c++;\n});\n"}], "negative_code": [{"source_code": "var x=parseInt(readline());\nvar arr=readline().split(' ').map(a => parseInt(a));\n\narr.sort((a,b) => a-b);\n\nfor(var i=arr.length-1; i>=0; i--){\n var sqrt= Math.sqrt(arr[i]);\n if(sqrt*sqrt !== arr[i]){\n print(arr[i]);\n break;\n }else\n continue;\n}"}, {"source_code": "n=parseInt(readline());\nmas=readline().split('');\nfunction compareNumeric(a, b) {\n if (a > b) return 1;\n if (a < b) return -1;\n}\nfor(i=0;i b ? 1 : -1})\nsort.reverse()\n\nfor(var i in arr){\n if (sort[0] == arr[i]) {\n print((i - 1 + 2) + \" \" + sort[1])\n break;\n }\n}", "positive_code": [{"source_code": "\nreadline();\nvar index;\nvar max = 0;\nvar max2 = 0;\nreadline().split(' ').map(function(v){\n\treturn +v;\n}).forEach(function(v, i){\n\tif(v>max){\n\t\tmax2 = max;\n\t\tmax = v;\n\t\tindex = i;\n\t}else if(v>max2){\n\t\tmax2 = v;\n\t}\n});\nprint(index+1, max2);"}, {"source_code": "'use strict';\n\n/*let input = `2\n5 7`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar n = Number(readline());\nvar prices = readline().split(' ').map(function (el, i) {\n\treturn { index: i, val: Number(el) };\n});\nprices.sort(function (a, b) {\n\treturn a.val - b.val;\n});\nprint(prices.pop().index + 1 + \" \" + prices.pop().val);\n"}, {"source_code": "readline();\nvar a=readline().split(\" \"),b=a.slice().sort(function(a,b){return +a-b}),l=b.length;print(a.indexOf(b[l-1])+1+\" \"+b[l-2]);"}, {"source_code": "var n = Number(readline());\nvar inp = readline().split(' ').map(cur => Number(cur));\nvar max = Math.max(...inp);\nvar index = inp.indexOf(max) \ninp.splice(index, 1);\nvar res = [index + 1, Math.max(...inp)];\nprint(res.join(' '));"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const sortedArr = arr.slice();\n sortedArr.sort((a, b) => a - b);\n const max = sortedArr[sortedArr.length - 1];\n const secondMax = sortedArr[sortedArr.length - 2];\n let maxIdx;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === max) {\n maxIdx = i + 1;\n break;\n }\n }\n\n console.log(maxIdx, secondMax);\n\n c++;\n});\n"}], "negative_code": [{"source_code": "var \n num = readline(),\n arr = readline().split(\" \"),\n maxx = 0,\n index = 0\n;\n\nvar max = Math.max.apply(Math, arr);\n\nfor(var i in arr){\n if (arr[i] < max && arr[i] > maxx) {\n maxx = arr[i];\n \n }\n if (max == arr[i]) index = parseInt(i) + 1;\n}\n\nprint(index + \" \" + maxx)"}], "src_uid": "1d4aaf15e5c6fcde50515880aae74720"} {"source_code": "var input = readline().split(' ').map(function(x){return Number(x)});\nvar a = input[0];\nvar b = input[1];\nvar s1 = readline();\nvar s2 = readline();\nvar min = 100000;\nvar res = [];\nfor(var i = 0 ; i <= (s2.length - s1.length) ; i++){\n var ss = s2.substring(i, i + s1.length);\n var tmp = [];\n var act = 0;\n for(var j = 0 ; j < s1.length ; j++){\n if( s1[j] !== ss[j] ){\n act++; tmp.push(j + 1);\n }\n }\n if(act < min){\n min = act;\n res = tmp;\n }\n}\n\nprint(min);\nfor(var i = 0 ; i < res.length ; i ++)write(res[i] + \" \");", "positive_code": [{"source_code": "var st = readline().split(' ').map(Number);\nvar s = readline();\nvar t = readline();\nvar sl = st[0];\nvar tl = st[1];\nvar ans = 1100;\nvar pos = [];\nfor (var i=0; i<=tl-sl; i++){\n\tvar count = 0;\n\tvar poscount = [];\n\tfor (var j=0; j+v));\narr.sort((a,b)=>{\n if(a[0]===b[0])\n return a[1]-b[1];\n return a[0]-b[0];\n});\n\nvar prev=0;\nfor(var i=0;i=ans)\n\t{\n\t ans=a[i].y;\n\t}\n\telse\n\t{\n\t ans=a[i].x;\n\t}\n}\nprint(ans);\n\nfunction sortObj(ojA, ojB)\n{\n if(ojA.x==ojB.x)\n\t{\n\t return ojA.y-ojB.y;\n\t}\n\telse\n\t{\n\t return ojA.x - ojB.x;\n\t}\n}"}, {"source_code": "var node = function(x) {\n this.a=x[0];\n this.b=x[1];\n}\n\nvar by_node = function(x,y){\n if(x.a!=y.a) return x.a\"+l.length+\" + \"+r.length);\n return ans;\n}\n\nvar merge_sort = function(arr,cmp) {\n if(!arr) return arr;\n if(arr.length<2) return arr;\n var mid = Math.floor(arr.length/2);\n var right=[];\n for(var i=mid;i=ans) ans=x.b;\n else ans=x.a;\n })\n print(ans);\n}\n\nmain();"}, {"source_code": "var intp = function(x){\n\treturn parseInt(x);\n}\n\nvar node = function(x){\n\tthis.a=parseInt(x[0]);\n\tthis.b=parseInt(x[1]);\n}\n\nvar by_node = function(x,y){\n\treturn x.a!=y.a?x.a>y.a:x.b>y.b;\n}\n\nvar out_type = function(x){\n\tprint(typeof(x.a)+\" \"+typeof(x.b));\n}\n\nvar out_value = function(x){\n\tprint(x.a+\" \"+x.b);\n}\n\nvar qsort = function(arr,cmp)\n{\n\tif(!arr) return [];\n\tif(arr.length<=1) return arr;\n\tvar p=Math.floor(Math.random()*arr.length);\n\tvar pv=arr[p];\n\tarr[p]=arr[arr.length-1];\n\tarr.length--;\n\tvar l=arr.filter(function(value){return cmp(pv,value);});\n\tvar r=arr.filter(function(value){return !cmp(pv,value);});\n\treturn qsort(l,cmp).concat([pv],qsort(r,cmp));\n}\n\nvar line;\nwhile(line=readline()) {\n\tvar n = line.split(' ').map(intp)[0];\n\tvar arr = [];\n\tfor(var i=0;i=ans) ans=x.b;\n\t\telse ans=x.a;\n\t});\n\tprint(ans);\n}\n"}, {"source_code": "var node = function(x){\n this.a=x[0];\n this.b=x[1];\n}\n\nvar by_node = function(x,y){\n if(x.a!=y.a) return x.a-y.a;\n return x.b-y.b;\n}\n\nvar out_value = function(x){\n print(x.a+\" \"+x.b);\n}\n\nwhile(true) {\n line = readline();\n if(!line) break;\n n = parseInt(line);\n var arr = new Array(n+5);\n for(var i=0;i=ans) ans=x.b;\n else ans=x.a;\n });\n print(ans);\n}"}, {"source_code": "var arr = [], elements;\nvar queries = parseInt(readline())\nfor (var l = 0; l < queries;l++){\n\telements = readline().split(' ').map((val)=>{\n\t\treturn parseInt(val);\n\t})\n\tarr.push(elements);\n}\narr.sort((a,b)=>{\n\tif (a[0] == b[0]){\n\t\treturn a[1] - b[1];\n\t}\n\telse{\n\treturn a[0] - b[0];\n\t}\n})\nvar enDay = Math.min(arr[0][0], arr[0][1])\nvar interim;\nfor (var k = 1; k= enDay){\n\t\tenDay = interim;\n\t}\n\telse{\n\t\tenDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];\n\t}\n}\nprint(enDay)"}, {"source_code": "var n = parseInt(readline());\nvar a= [];\nfor (var i=0;i{ if ((a[0]-b[0])!==0) {return a[0]-b[0]} else {return a[1]-b[1]}}).map(function (xs) {var mi= Math.min.apply(null,xs); var ma = Math.max.apply(null,xs);if (mi>=this.t) {this.t=mi; return mi} else {this.t=ma; return ma}},{t:0}).pop();\nprint (p);"}], "negative_code": [{"source_code": "n = readline().split(' ').map(function(x){return parseInt(x);})[0];\n\nvar arr=[];\n\nfor(var i=0;iy.a;\n else return x.b>y.b;\n})\n\nvar ans=arr[0].b;\n\nfor(var i=0;i=ans) ans=arr[i].b;\n else ans=arr[i].a;\n}\n\nprint(ans);"}, {"source_code": "n = parseInt(readline());\n\nvar arr=[];\n\nfor(var i=0;iy.a;\n else return x.b>y.b;\n})\n\nvar ans=arr[0].b;\n\nfor(var i=0;i=ans) ans=arr[i].b;\n else ans=arr[i].a;\n}\n\nprint(ans);"}, {"source_code": "n = parseInt(readline());\n\nvar arr=[];\n\nfor(var i=0;iy.a;\n else return x.b>y.b;\n})\n\nvar ans=arr[0].b;\n\nfor(var i=0;i=ans) ans=arr[i].b;\n else ans=arr[i].a;\n}\n\n\n\nprint(ans);"}, {"source_code": "n = parseInt(readline());\n\nvar arr=[];\n\nfor(var i=0;iy.a;\n else return x.b>y.b;\n})\n\nvar ans=arr[0].b;\n\narr.forEach(function(x){\n if(x.b>=ans) ans=x.b;\n else ans=x.a;\n})\n\nprint(ans);"}, {"source_code": "n = parseInt(readline());\n\nvar arr=[];\n\nfor(var i=0;iy.a;\n else return x.b>y.b;\n})\n\nvar ans=arr[0].b;\n\nfor(var i=0;i=ans) ans=arr[i].b;\n else ans=arr[i].a;\n}\n\nprint(ans);"}, {"source_code": "var arr = [], elements = []\nvar queries = parseInt(readline())\nfor (var l = 0; l < queries;l++){\n\treadline().split(' ').map((val)=>{\n\t\telements.push(parseInt(val));\n\t})\n\tarr.push(elements);\n}\narr.sort((a,b)=>{\n\treturn a[0] - b[0]\n})\nvar enDay = Math.min(arr[0][0], arr[0][1])\nvar interim;\nfor (var k = 1; k= enDay){\n\t\tenDay = interim;\n\t}\n\telse{\n\t\tenDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];\n\t}\n}\nprint(enDay)"}, {"source_code": "var arr = [], elements = []\nvar queries = parseInt(readline())\nfor (var l = 0; l < queries;l++){\n\treadline().split(' ').map((val)=>{\n\t\telements.push(parseInt(val));\n\t})\n\tarr.push(elements);\n\telements.pop();\n\telements.pop()\n}\narr.sort((a,b)=>{\n\treturn a[0] - b[0]\n})\nvar enDay = Math.min(arr[0][0], arr[0][1])\nvar interim;\nfor (var k = 1; k= enDay){\n\t\tenDay = interim;\n\t}\n\telse{\n\t\tenDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];\n\t}\n}\nprint(enDay)"}, {"source_code": "var arr = [], elements;\nvar queries = parseInt(readline())\nfor (var l = 0; l < queries;l++){\n\telements = readline().split(' ').map((val)=>{\n\t\treturn parseInt(val);\n\t})\n\tarr.push(elements);\n}\narr.sort((a,b)=>{\n\treturn a[0] - b[0]\n})\nvar enDay = Math.min(arr[0][0], arr[0][1])\nvar interim;\nfor (var k = 1; k= enDay){\n\t\tenDay = interim;\n\t}\n\telse{\n\t\tenDay = (interim == arr[k][0]) ? arr[k][1] : arr[k][0];\n\t}\n}\nprint(enDay)"}, {"source_code": "var n = +readline();\nvar arr=[];\nfor(var i=0;i+v));\nfor(var i=0;i{\n if(a[0]===b[0])\n return a[1]-b[1];\n return a[0]-b[0];\n});\n\nvar ans=0;\nvar prev=0;\nfor(var i=0;i+v));\nprint(arr);\narr.sort((a,b)=>{\n if(a[0]===b[0])\n return a[1]-b[1];\n return a[0]-b[0];\n});\n\nvar ans=0;\nvar prev=0;\nfor(var i=0;i+v));\narr.sort((a,b)=>{\n if(a[0]===b[0])\n return a[1]-b[1];\n return a[0]-b[0];\n});\n\nfor(var i=0;i+v));\narr.sort((a,b)=>{\n if(a[0]===b[0])\n return a[1]-b[1];\n return a[0]-b[0];\n});\n\nvar ans=0;\nvar prev=0;\nfor(var i=0;i {\n if (chainNumberList === 1) return 0\n\n let currentCycleLength = 0\n let maxCycleLength = 0\n\n for (let index = 1; index < chainNumberList; index++) {\n const a = aList[index]\n const b = bList[index]\n\n if (index === 1) {\n currentCycleLength = Math.abs(a - b)\n } else {\n const baseLength = Math.abs(a - b)\n const partLength = cList[index - 1] - 1 - baseLength\n if (baseLength > partLength + currentCycleLength) {\n currentCycleLength = baseLength\n } else {\n currentCycleLength += partLength\n }\n }\n\n if (a === b) {\n currentCycleLength = 0\n }\n\n currentCycleLength += 2\n\n if (maxCycleLength < cList[index] + currentCycleLength) {\n maxCycleLength = cList[index] - 1 + currentCycleLength\n }\n }\n\n currentCycleLength += cList[cList.length - 1] - 1\n\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n }\n\n return maxCycleLength\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet cList, aList, bList, chainNumberList\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 4\n if (mode === 0) {\n chainNumberList = Number(line)\n } else if (mode === 1) {\n cList = line.split(' ').map(val => Number(val))\n } else if (mode === 2) {\n aList = line.split(' ').map(val => Number(val))\n } else if (mode === 3) {\n bList = line.split(' ').map(val => Number(val))\n answer.push(calculate(chainNumberList, cList, aList, bList))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n\n// chainNumberList, cList, aList, bList\n// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst c = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tlet cur = Math.abs(a[1] - b[1]);\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tcur += 2;\r\n\t\t\tans = Math.max(ans, cur + c[i] - 1);\r\n\t\t\tif (a[i+1] == b[i+1]) {\r\n\t\t\t\tcur = 0;\r\n\t\t\t} else {\r\n\t\t\t\tcur += Math.min(a[i+1], b[i+1]) - 1\r\n\t\t\t\tcur += c[i] - Math.max(a[i+1], b[i+1]);\r\n\t\t\t\tcur = Math.max(cur, Math.abs(a[i+1] - b[i+1]));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var map = {}\r\n var c = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var b = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var currentLength = 0\r\n var len = 0\r\n var max = 0\r\n for (let i = 1; i < n; i++) {\r\n currentLength = 1+c[i]+Math.abs(a[i]-b[i])\r\n if (a[i] !== b[i]) {\r\n currentLength = Math.max(currentLength, len + c[i]-Math.abs(a[i]-b[i])+1)\r\n }\r\n max = Math.max(max, currentLength)\r\n len = currentLength\r\n // console.log(currentLength, a[i], b[i], c[i - 1])\r\n }\r\n console.log(max)\r\n })\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9+5;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst c = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 1, cur = -INF; i < n; i++) {\r\n\t\t\tif (a[i] == b[i]) {\r\n\t\t\t\tcur = 0;\r\n\t\t\t} else {\r\n\t\t\t\tcur += c[i-1] - 1 - Math.abs(a[i] - b[i]);\r\n\t\t\t\tcur = Math.max(cur, Math.abs(a[i] - b[i]));\r\n\t\t\t}\r\n\t\t\tcur += 2;\r\n\t\t\tans = Math.max(ans, cur + c[i] - 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (chainNumberList, cList, aList, bList) => {\n if (chainNumberList === 1) return 0\n\n let maxCycleLength = 0\n let currentCycleLength = 0\n for (let index = 1; index < chainNumberList; index++) {\n const a = aList[index]\n const b = bList[index]\n const cOld = cList[index - 1]\n\n if (index === 1) {\n currentCycleLength += Math.abs(b - a)\n } else {\n currentCycleLength += cOld - 1 - Math.abs(b - a)\n }\n\n if (a === b) {\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n currentCycleLength = 0\n }\n } else {\n const newCurrentCycleLength = currentCycleLength + cOld - 1\n if (maxCycleLength < newCurrentCycleLength) {\n maxCycleLength = newCurrentCycleLength\n }\n }\n currentCycleLength += 2\n }\n\n currentCycleLength += cList[cList.length - 1] - 1\n\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n }\n\n return maxCycleLength\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet cList, aList, bList, chainNumberList\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 4\n if (mode === 0) {\n chainNumberList = Number(line)\n } else if (mode === 1) {\n cList = line.split(' ').map(val => Number(val))\n } else if (mode === 2) {\n aList = line.split(' ').map(val => Number(val))\n } else if (mode === 3) {\n bList = line.split(' ').map(val => Number(val))\n answer.push(calculate(chainNumberList, cList, aList, bList))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (chainNumberList, cList, aList, bList) => {\n let maxCycleLength = 0\n let currentCycleLength = 0\n for (let index = 1; index < chainNumberList; index++) {\n const a = aList[index]\n const b = bList[index]\n const cOld = cList[index - 1]\n\n if (index === 1) {\n currentCycleLength += Math.abs(b - a)\n } else {\n currentCycleLength += cOld - 1 - Math.abs(b - a)\n }\n\n if (a === b) {\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n currentCycleLength = 0\n }\n } else {\n const newCurrentCycleLength = currentCycleLength + cOld - 1\n if (maxCycleLength < newCurrentCycleLength) {\n maxCycleLength = newCurrentCycleLength\n }\n }\n currentCycleLength += 2\n }\n\n currentCycleLength += cList[cList.length - 1] - 1\n\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n }\n\n return maxCycleLength\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet cList, aList, bList, chainNumberList\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 4\n if (mode === 0) {\n chainNumberList = Number(line)\n } else if (mode === 1) {\n cList = line.split(' ').map(val => Number(val))\n } else if (mode === 2) {\n aList = line.split(' ').map(val => Number(val))\n } else if (mode === 3) {\n bList = line.split(' ').map(val => Number(val))\n answer.push(calculate(chainNumberList, cList, aList, bList))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (chainNumberList, cList, aList, bList) => {\n let maxCycleLength = 0\n let currentCycleLength = 0\n for (let index = 1; index < chainNumberList; index++) {\n const a = aList[index]\n const b = bList[index]\n const cOld = cList[index - 1]\n\n if (index === 1) {\n currentCycleLength += Math.abs(b - a)\n } else {\n currentCycleLength += cOld - 1 - Math.abs(b - a)\n }\n\n if (a === b) {\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n currentCycleLength = 0\n }\n }\n currentCycleLength += 2\n }\n\n currentCycleLength += cList[cList.length - 1] - 1\n\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n }\n\n return maxCycleLength\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet cList, aList, bList, chainNumberList\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 4\n if (mode === 0) {\n chainNumberList = Number(line)\n } else if (mode === 1) {\n cList = line.split(' ').map(val => Number(val))\n } else if (mode === 2) {\n aList = line.split(' ').map(val => Number(val))\n } else if (mode === 3) {\n bList = line.split(' ').map(val => Number(val))\n answer.push(calculate(chainNumberList, cList, aList, bList))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (chainNumberList, cList, aList, bList) => {\n let maxCycleLength = 0\n let currentCycleLength = 0\n for (let index = 1; index < chainNumberList; index++) {\n const a = aList[index]\n const b = bList[index]\n const cOld = cList[index - 1]\n\n if (index === 1) {\n currentCycleLength += Math.abs(b - a)\n } else {\n currentCycleLength += cOld - 1 - Math.abs(b - a)\n }\n\n if (a === b) {\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n currentCycleLength = 0\n }\n }\n currentCycleLength += 2\n }\n\n currentCycleLength += cList[cList.length - 1] - 1\n\n if (maxCycleLength < currentCycleLength) {\n maxCycleLength = currentCycleLength\n }\n\n return maxCycleLength\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet cList, aList, bList, chainNumberList\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 4\n if (mode === 0) {\n chainNumberList = Number(line)\n } else if (mode === 1) {\n cList = line.split(' ').map(val => Number(val))\n } else if (mode === 2) {\n aList = line.split(' ').map(val => Number(val))\n } else if (mode === 3) {\n bList = line.split(' ').map(val => Number(val))\n console.log(calculate(chainNumberList, cList, aList, bList))\n round++\n if (round === maxRound) {\n readline.close()\n return\n }\n }\n index++\n }\n})\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst c = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 1, cur = 0; i < n; i++) {\r\n\t\t\tif (a[i] == b[i]) {\r\n\t\t\t\tcur = 0;\r\n\t\t\t} else {\r\n\t\t\t\tcur += c[i-1] - 1 - Math.abs(a[i] - b[i]);\r\n\t\t\t\tcur = Math.max(cur, Math.abs(a[i] - b[i]));\r\n\t\t\t}\r\n\t\t\tcur += 2;\r\n\t\t\tans = Math.max(ans, cur + c[i] - 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst c = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tlet cur = Math.abs(a[1] - b[1]);\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tcur += 2;\r\n\t\t\tans = Math.max(ans, cur + c[i] - 1);\r\n\t\t\tif (a[i+1] == b[i+1]) {\r\n\t\t\t\tcur = 0;\r\n\t\t\t} else {\r\n\t\t\t\tcur += Math.min(a[i+1], b[i+1]) - 1\r\n\t\t\t\tcur += c[i] - Math.max(a[i+1], b[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "3d898a45ab89b93e006270a77db49017"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve([n, k], set) {\r\n set.sort((a, b) => a - b)\r\n let min = Number.MAX_SAFE_INTEGER, prv = -1\r\n for (let i of set) {\r\n if (i - 1 != prv) {\r\n min = prv + 1\r\n break\r\n }\r\n prv = i\r\n }\r\n let max = set[n - 1];\r\n let a = Math.ceil((min + max) / 2)\r\n let flag = true\r\n for (let i of set) {\r\n if (i == a) flag = false\r\n }\r\n if (k == 0) flag = false\r\n if (min + 1 <= max) return n + Number(flag)\r\n else return n + k\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) console.log(solve(inputArr[i], inputArr[i + 1]))\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = false\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] >= n) exist = true\r\n }\r\n if (!exist) return console.log(n + k)\r\n if (k === 0) return console.log(n)\r\n\r\n var mex = 0\r\n var max = 0\r\n for (let i = 0; i <= n; i++) {\r\n if (a[i] > max) max = a[i]\r\n }\r\n for (let i = 0; i <= n; i++) {\r\n if (!a.includes(i)) {\r\n mex = i\r\n break\r\n }\r\n }\r\n if (!a.includes(Math.ceil((mex + max) / 2))) return console.log(n + 1)\r\n console.log(n)\r\n // console.log(exist ? n : n + k)\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n \r\nvar t = parseInt(readline(), 10);\r\nvar lines= [];\r\nfor(var i = 0; i= 1){\r\n var newItem = Math.ceil((max+mex)/2);\r\n addition = sorted.some( function(item){\r\n return item === newItem;\r\n }) ? 0 : 1;\r\n \r\n }\r\n print(n + addition);\r\n}\r\n\r\nfunction getMex(arr,max){\r\n var res = 0;\r\n \r\n arr.forEach(function(item){\r\n if(res === item){\r\n res = item +1;\r\n }\r\n } )\r\n return res\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, a) => {\r\n if (k == 0) return pr(n);\r\n a.sort((x, y) => x - y);\r\n let max = a[n - 1];\r\n let mex = n;\r\n for (let i = 0; i < n; i++) {\r\n if (i != a[i]) {\r\n mex = i;\r\n break;\r\n }\r\n }\r\n if (mex > max) return pr(n + k);\r\n let add = mex + max + 1 >> 1;\r\n for (let i = 0; i < n; i++) {\r\n if (add == a[i]) {\r\n return pr(n);\r\n }\r\n }\r\n pr(n + 1);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let mex = Infinity;\r\n if (arr[0] !== 0) mex = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i - 1] + 1 !== arr[i]) {\r\n mex = Math.min(mex, arr[i - 1] + 1);\r\n break;\r\n }\r\n }\r\n if (mex === Infinity) {\r\n console.log(k + n);\r\n continue;\r\n }\r\n let obj = {};\r\n for (let i = 0; i < n; i++) obj[arr[i]] = 1;\r\n let i = 0,\r\n max = arr[n - 1];\r\n while (i < k) {\r\n let j = Math.ceil((mex + max) / 2);\r\n if (obj[j]) break;\r\n else {\r\n arr.push(j);\r\n obj[j] = 1;\r\n if (mex === j) {\r\n while (obj[j]) j++;\r\n mex = j;\r\n }\r\n max = Math.max(j, max);\r\n }\r\n i++;\r\n }\r\n console.log(Object.keys(obj).length);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, a) => {\r\n if (k == 0) return pr(n);\r\n let max = Math.max.apply(Math, a);\r\n let mex = n;\r\n for (let i = 0; i < n; i++) {\r\n if (i != a[i]) {\r\n mex = i;\r\n break;\r\n }\r\n }\r\n if (mex > max) return pr(n + k);\r\n let add = mex + max + 1 >> 1;\r\n for (let i = 0; i < n; i++) {\r\n if (add == a[i]) {\r\n return pr(n);\r\n }\r\n }\r\n pr(n + 1);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let mex = Infinity;\r\n if (arr[0] === 0) mex = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i - 1] + 1 !== arr[i]) {\r\n mex = Math.min(mex, arr[i - 1] + 1);\r\n break;\r\n }\r\n }\r\n if (mex === Infinity) mex = arr[n - 1] + 1;\r\n let obj = {};\r\n for (let i = 0; i < n; i++) obj[arr[i]] = 1;\r\n let i = 0,\r\n max = arr[n - 1];\r\n while (i < k) {\r\n let j = Math.ceil((mex + max) / 2);\r\n if (obj[j]) break;\r\n else {\r\n arr.push(j);\r\n obj[j] = 1;\r\n if (mex === j) {\r\n while (obj[j]) j++;\r\n mex = j;\r\n }\r\n max = Math.max(j, max);\r\n }\r\n i++;\r\n }\r\n let l = {},\r\n cnt = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (!l[arr[i]]) cnt++;\r\n else l[arr[i]] = 1;\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "c0d23fe28ebddbfc960674e3b10122ad"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tfunction string2hash(s) {\n\t\tvar h = { nonzero: [] },\n\t\t\talpha = 'abcdefghijklmnopqrstuvwxyz';\n\t\tfor (var i = 0; i < 26; ++i) {\n\t\t\th[alpha.charAt(i)] = 0;\n\t\t}\n\t\tfor (var i = 0; i < s.length; ++i) {\n\t\t\tvar ch = s.charAt(i);\n\t\t\tif (h[ch] == 0) {\n\t\t\t\th.nonzero.push(ch);\n\t\t\t}\n\t\t\th[ch] += 1;\n\t\t}\n\t\treturn h;\n\t}\n\tvar source = string2hash(readline()),\n\t\ttarget = string2hash(readline()),\n\t\tcount = 0;\n\tfor (var i = 0; i < target.nonzero.length; ++i) {\n\t\tvar ch = target.nonzero[i];\n\t\tif (source[ch] == 0) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t\tcount += Math.min(source[ch], target[ch]);\n\t}\n\tprint(count);\n}\n\nmain();\n", "positive_code": [{"source_code": "print(function(a, b) {\n\tvar c = new Int32Array(256);\n\tvar has = new Int8Array(256);\n\n\tfor (var i = 0; i < a.length; i++)\n\t\tc[a.charCodeAt(i)]++;\n\n\tfor (var i = 0; i < 256; i++)\n\t\tif (c[i] > 0) has[i] = 1;\n\n\tvar ans = 0;\n\tfor (var i = 0; i < b.length; i++) {\n\t\tvar clr = b.charCodeAt(i);\n\t\tif (has[clr] === 0) return -1;\n\t\tif (c[clr] > 0) {\n\t\t\tc[clr]--;\n\t\t\tans++;\n\t\t}\n\t}\n\treturn ans;\n}(readline(), readline()));"}], "negative_code": [{"source_code": "print(function(a, b) {\n\tvar c = new Int32Array(1000);\n\tfor (var i = 0; i < a.length; i++)\n\t\tc[a.charCodeAt(i)]++;\n\n\tvar ans = 0;\n\tfor (var i = 0; i < b.length; i++)\n\t\tif (c[b.charCodeAt(i)] > 0) {\n\t\t\tc[b.charCodeAt(i)]--;\n\t\t\tans++;\n\t\t}\n\n\treturn ans == 0 ? -1 : ans;\n}(readline(), readline()));"}, {"source_code": "print(function(a, b) {\n\tvar c = new Int8Array(255);\n\tfor (var i = 0; i < a.length; i++)\n\t\tc[a.charCodeAt(i)]++;\n\n\tvar ans = 0;\n\tfor (var i = 0; i < b.length; i++)\n\t\tif (c[b.charCodeAt(i)] > 0) {\n\t\t\tc[b.charCodeAt(i)]--;\n\t\t\tans++;\n\t\t}\n\n\treturn ans == 0 ? -1 : ans;\n}(readline(), readline()));"}, {"source_code": "print(function(a, b) {\n\tvar c = new Int32Array(255);\n\tfor (var i = 0; i < a.length; i++)\n\t\tc[a.charCodeAt(i)]++;\n\n\tvar ans = 0;\n\tfor (var i = 0; i < b.length; i++)\n\t\tif (c[b.charCodeAt(i)] > 0) {\n\t\t\tc[b.charCodeAt(i)]--;\n\t\t\tans++;\n\t\t}\n\n\treturn ans == 0 ? -1 : ans;\n}(readline(), readline()));"}], "src_uid": "b1e09df7c47dbd04992e64826337c28a"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb) {\n const min = sa.map((x, i) => {\n const j = binarySearch(0, n - 1, p => sb[p] < x) + 1\n return sb[j] - x\n })\n const bar = [0]\n for (let i = 1; i < n; i++) {\n if (sb[i - 1] < sa[i]) {\n bar.push(i)\n }\n }\n bar.push(n)\n // console.log('bar', bar)\n const max = sa.map((x, i) => {\n const j = binarySearch(0, bar.length - 1, p => bar[p] <= i) + 1\n return sb[bar[j] - 1] - x\n })\n return min.join(' ') + '\\n' + max.join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = lowerBound(i, boulders);\r\n let j = boulders[bi];\r\n\r\n if (j < i) {\r\n j = b.length - 1;\r\n } else if (j === i) {\r\n if (bi === boulders.length - 1) {\r\n j = b.length - 1;\r\n } else {\r\n j = boulders[bi + 1] - 1;\r\n }\r\n } else if (j > i) {\r\n j = j - 1;\r\n }\r\n\r\n max.push(b[j] - a[i]);\r\n // const j = pickMaxIndex(i, a, b);\r\n // max.push(b[j] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = lowerBound(i, boulders);\r\n let j = boulders[bi];\r\n\r\n if (j === i) {\r\n if (bi === boulders.length - 1) {\r\n j = b.length - 1;\r\n } else {\r\n j = boulders[bi + 1];\r\n }\r\n }\r\n\r\n if (j > i) {\r\n j--;\r\n }\r\n\r\n max.push(b[j] - a[i]);\r\n // const j = pickMaxIndex(i, a, b);\r\n // max.push(b[j] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = lowerBound(i, boulders);\r\n let j = boulders[bi];\r\n if (j > i) {\r\n j--;\r\n } else if (j === i) {\r\n // last boulder\r\n if (bi === boulders.length - 1) {\r\n j = b.length - 1;\r\n } else {\r\n j = boulders[bi + 1] - 1;\r\n }\r\n }\r\n max.push(b[j] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = boulders[lowerBound(i, boulders)];\r\n if (bi > i) {\r\n bi--;\r\n } else if (bi === i) {\r\n bi = b.length - 1;\r\n }\r\n max.push(b[bi] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = boulders[lowerBound(i, boulders)];\r\n if (bi > i) {\r\n bi--;\r\n }\r\n max.push(b[bi] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a, iMin = 0, iMax = a.length - 1) {\r\n // let iMin = 0;\r\n // let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b, 0, j);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = boulders[lowerBound(i, boulders)];\r\n if (bi > i) {\r\n bi--;\r\n }\r\n max.push(b[bi] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\n// Finds index where x should be\r\nfunction lowerBound(x, a) {\r\n let iMin = 0;\r\n let iMax = a.length - 1;\r\n // 1 2 3 4 (1) => 0\r\n // 1 2 3 4 (2) => 1\r\n // 1 2 3 4 (3) => 2\r\n // 1 2 3 4 (4) => 3\r\n // 1 2 3 4 (5) => 3\r\n while (iMax - iMin > 0) {\r\n const iMiddle = Math.floor((iMax + iMin) / 2);\r\n\r\n if (a[iMiddle] >= x) {\r\n iMax = iMiddle;\r\n } else {\r\n // a[iMiddle] < x\r\n iMin = iMiddle + 1;\r\n }\r\n }\r\n \r\n if (x > a[iMin]) {\r\n return Math.min(iMin + 1, a.length - 1);\r\n }\r\n\r\n return iMin;\r\n}\r\n\r\n// console.log('lb test', lowerBound(1, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(2, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(3, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(4, [1, 2, 3, 4], 0, 3));\r\n// console.log('lb test', lowerBound(5, [1, 2, 3, 4], 0, 3));\r\n\r\nfunction pickMinIndex(x, b) {\r\n for (let j = 0; j < b.length; j++) {\r\n return lowerBound(x, b, 0, j);\r\n }\r\n}\r\n\r\nfunction pickMaxIndex(i, a, b) {\r\n for (let j = i; j < b.length - 1; j++) {\r\n if (a[j + 1] > b[j]) {\r\n return j;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\n// indecies of elements which cannot be moved by -1\r\nfunction createArrayOfBoulders(a, b) {\r\n const boulders = [];\r\n\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > b[i - 1]) {\r\n boulders.push(i);\r\n }\r\n }\r\n\r\n return boulders;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n }\r\n\r\n const boulders = createArrayOfBoulders(a, b);\r\n // console.log(boulders);\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n if (boulders.length > 0) {\r\n let bi = boulders[lowerBound(i, boulders)];\r\n if (bi !== i) {\r\n bi--;\r\n }\r\n max.push(b[bi] - a[i]);\r\n } else {\r\n max.push(b[b.length - 1] - a[i]);\r\n }\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nfunction pickMinIndex(x, b /* a is sorted */, minMap) {\r\n for (let j = 0; j < b.length; j++) {\r\n const num = b[j];\r\n if (\r\n num >= x\r\n ) {\r\n if (b[j + 1] === num && minMap[j + 1] === undefined) {\r\n continue;\r\n }\r\n\r\n return j;\r\n }\r\n }\r\n\r\n throw new Error('Cant find min');\r\n}\r\n\r\nfunction pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {\r\n for (let j = xMap[xi] + 1; j < b.length; j++) {\r\n if (minMap[j] !== undefined) {\r\n return j - 1;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const minMap = {};\r\n const xMap = {};\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b, minMap);\r\n min.push(b[j] - x);\r\n minMap[j] = true;\r\n xMap[i] = j;\r\n }\r\n\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMaxIndex(x, i, b, minMap, xMap);\r\n max.push(b[j] - x);\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nfunction pickMinIndex(x, a /* a is sorted */) {\r\n for (let i = 0; i < a.length; i++) {\r\n const num = a[i];\r\n if (num >= x && a[i + 1] !== num) {\r\n return i;\r\n }\r\n }\r\n\r\n throw new Error('Cant find min');\r\n}\r\n\r\nfunction pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {\r\n for (let j = xMap[xi] + 1; j < b.length; j++) {\r\n if (minMap[j] !== undefined) {\r\n return j - 1;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const minMap = {};\r\n const xMap = {};\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n minMap[j] = true;\r\n xMap[i] = j;\r\n }\r\n\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMaxIndex(x, i, b, minMap, xMap);\r\n max.push(b[j] - x);\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nfunction pickMinIndex(x, a /* a is sorted */) {\r\n for (let i = 0; i < a.length; i++) {\r\n const num = a[i];\r\n if (num >= x) {\r\n return i;\r\n }\r\n }\r\n\r\n throw new Error('Cant find min');\r\n}\r\n\r\nfunction pickMaxIndex(x, xi, b /* a is sorted */, minMap, xMap) {\r\n for (let j = xMap[xi] + 1; j < b.length; j++) {\r\n if (minMap[j] !== undefined) {\r\n return j - 1;\r\n }\r\n }\r\n\r\n return b.length - 1;\r\n}\r\n\r\nfunction solve(a, b) {\r\n const minMap = {};\r\n const xMap = {};\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n minMap[j] = true;\r\n xMap[i] = j;\r\n }\r\n\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMaxIndex(x, i, b, minMap, xMap);\r\n max.push(b[j] - x);\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nfunction pickMinIndex(x, a /* a is sorted */) {\r\n for (let i = 0; i < a.length; i++) {\r\n const num = a[i];\r\n if (num >= x) {\r\n return i;\r\n }\r\n }\r\n\r\n throw new Error('Cant find min');\r\n}\r\n\r\nfunction pickMaxIndex(x, xi, a /* a is sorted */, minMap) {\r\n for (let i = a.length - 1; i >= 0; i--) {\r\n const num = a[i];\r\n if (num < x) {\r\n throw new Error(`Cant find max ${x}`);\r\n }\r\n\r\n if (\r\n minMap[i] === undefined ||\r\n minMap[i] === xi\r\n ) {\r\n return i;\r\n }\r\n }\r\n\r\n throw new Error(`Cant find max ${x}`);\r\n}\r\n\r\nfunction solve(a, b) {\r\n const minMap = {};\r\n const min = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMinIndex(x, b);\r\n min.push(b[j] - x);\r\n minMap[j] = i;\r\n }\r\n\r\n const max = [];\r\n for (let i = 0; i < a.length; i++) {\r\n const x = a[i];\r\n const j = pickMaxIndex(x, i, b, minMap);\r\n max.push(b[j] - x);\r\n }\r\n\r\n console.log(min.join(' '));\r\n console.log(max.join(' '));\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].split(' ').map(Number);\r\n const b = data[i + 2].split(' ').map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}], "src_uid": "ffc96dc83a6fde2e83e07671a8d8ed41"} {"source_code": "var n = parseInt(readline());\nvar mapa = new Array();\nmapa['Polycarp'.toUpperCase()] = 1;\nvar rs = 0;\nfor (var i = 0; i < n; ++i) {\n var s = readline().split(' ');\n mapa[s[0].toUpperCase()] = mapa[s[2].toUpperCase()] + 1;\n if (mapa[s[0].toUpperCase()] > rs) {\n rs = mapa[s[0].toUpperCase()];\n }\n}\nprint(rs);", "positive_code": [{"source_code": "'use strict';\n\n// const rlLib = require('readline');\n\n// const rl = rlLib.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// let inputs = [];\n// let allCount = 1;\n// let currentLine = 0;\n\n// rl.on('line', (input) => {\n// inputs.push(input);\n// if (inputs.length === 1) {\n// allCount = +inputs[0] + 1;\n// }\n// if (inputs.length >= allCount) {\n// main();\n\n// rl.close(); \n// }\n// });\n\n// function readline() {\n// return inputs[currentLine++];\n// }\n// function print() {\n// console.log.apply(this, arguments);\n// }\n\n// /**\n// * @param {number} s\n// * @param {number[]} nums\n// * @return {number}\n// */\n// function main() {\n var count = +readline();\n // parent => children\n var tree = {'polycarp': []};\n\n for (var i = 0; i < count; i++) {\n var str = readline().split(' ').map(x => x.toLowerCase());\n\n tree[str[2]].push(str[0]);\n \n if (!tree[str[0]]) {\n tree[str[0]] = [];\n }\n }\n\n\n // \u043f\u0440\u043e\u0439\u0434\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0432 \u0448\u0438\u0440\u0438\u043d\u0443 \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c\n\n var st = [];\n var set = new Set();\n var res = 1;\n\n st.push(['polycarp', 1]);\n set.add('polycarp');\n\n while (st.length) {\n var data = st.pop();\n var name = data[0];\n var count = data[1];\n\n if (res < count) {\n res = count;\n }\n\n tree[name].forEach(function(name) {\n if (!set.has(name)) {\n st.push([name, count + 1]);\n set.add(name);\n }\n });\n }\n\n\n print(res);\n// };\n\n\n"}, {"source_code": "var i = 0,\n repostsCount = 0,\n maxDeep = 1,\n users = {\n 'polycarp': {\n reposts: [],\n repostedFrom: false,\n deep: maxDeep,\n },\n };\n\nvar repostsCount = parseInt(readline());\n\nfunction lower(string) {\n return string.toLowerCase();\n}\n\nwhile(i < repostsCount) {\n var _ = readline().split(' reposted ').map(lower),\n destination = _[0], source = _[1];\n users[source].reposts.push(destination);\n destinationDeep = users[source].deep + 1;\n if(maxDeep < destinationDeep) {\n maxDeep = destinationDeep;\n }\n users[destination] = {\n reposts: [],\n repostedFrom: source,\n deep: users[source].deep + 1,\n }\n i++;\n}\n\n print(maxDeep);"}, {"source_code": "var lengths = [];\n\nfunction callback(arr, name2, i, d) {\n\tvar indOf = true;\n\n\tfor (; i < arr.length; i++) {\n\t\tif (arr[i][1] === name2) {\n\t\t\tcallback(arr, arr[i][0], i + 1, d + 1);\n\t\t\tindOf = false;\n\t\t}\n\t}\n\n\tif (indOf) {\n\t\tlengths.push(d);\n\t}\n}\n\n\nfunction maxLengthOfChain() {\n\tvar n = readline();\n var arr = [];\n\n for (var i = 0; i < n; i++) {\n arr.push(readline().toLowerCase().split(' reposted '));\n }\n\n\n\tcallback(arr, 'polycarp', 0, 1);\n\n\n\treturn Math.max(...lengths);\n}\n\nprint(maxLengthOfChain());\n"}, {"source_code": "\n\nTree.prototype.traverseDF = function(callback) {\n\n\t// \u044d\u0442\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430\u044f \u0438 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \n\t(function recurse(currentNode) {\n\t\t// \u0448\u0430\u0433 2\n\t\tfor (var i = 0, length = currentNode.children.length; i < length; i++) {\n\t\t\t// \u0448\u0430\u0433 3\n\t\t\trecurse(currentNode.children[i]);\n\t\t}\n\n\t\t// \u0448\u0430\u0433 4\n\t\tcallback(currentNode);\n\n\t\t// \u0448\u0430\u0433 1\n\t})(this._root);\n};\n\nTree.prototype.add = function(data, toData, traversal) {\n\tvar child = new Node(data),\n\tparent = null,\n\tcallback = function(node) {\n\t\tif (node.data === toData) {\n\t\t\tparent = node;\n\t\t}\n\t};\n\n\tthis.contains(callback, traversal);\n\n\tif (parent) {\n\t\tparent.children.push(child);\n\t\tchild.parent = parent;\n\t} else {\n\t\tthrow new Error('Cannot add node to a non-existent parent.');\n\t}\n};\n\nTree.prototype.contains = function(callback, traversal) {\n\ttraversal.call(this, callback);\n};\n\nfunction length(node, startLength) {\n\tif (node.parent === null) {\n\t\treturn startLength;\n\t}\n\treturn length(node.parent, startLength + 1);\n}\n\nfunction maxLengthOfChain() {\n \n var n = readline();\n var arr = [];\n var line;\n \n while (line = readline()) {\n arr.push(line);\n }\n\n// \tvar s = str.substring(2).toLowerCase();\n// \tvar arr = s.split('\\n');\n\tvar tree = new Tree('polycarp');\n\n\tarr.forEach(function(elem) {\n\t\tvar names = elem.toLowerCase().split(' reposted ');\n\t\t\t\n\t\ttree.add(names[0], names[1], tree.traverseDF);\n\t});\n\n\tvar maxLength = 0;\n\ttree.contains(function(node) {\n\t\tvar l = length(node, 1);\n\t\tif (maxLength < l) {\n\t\t\tmaxLength = l;\n\t\t}\n\t}, tree.traverseDF);\n\n\tprint(maxLength);\n}\n\nmaxLengthOfChain();\n\nfunction Node(data) {\n\tthis.data = data;\n\tthis.parent = null;\n\tthis.children = [];\n}\n\nfunction Tree(data) {\n\tvar node = new Node(data);\n\tthis._root = node;\n}\n\n"}, {"source_code": "var lengths = [];\n\nfunction callback(arr, name2, i, d) {\n\tvar indOf = true;\n\n\tfor (; i < arr.length; i++) {\n\t\tif (arr[i][1] === name2) {\n\t\t\tcallback(arr, arr[i][0], i + 1, d + 1);\n\t\t\tindOf = false;\n\t\t}\n\t}\n\n\tif (indOf) {\n\t\tlengths.push(d);\n\t}\n}\n\n\nfunction maxLengthOfChain() {\n\tvar n = readline();\n var arr = [];\n var line;\n \n while (line = readline()) {\n arr.push(line.toLowerCase().split(' reposted '));\n }\n\n\n\tcallback(arr, 'polycarp', 0, 1);\n\n\n\treturn Math.max(...lengths);\n}\n\nprint(maxLengthOfChain());\n"}, {"source_code": "var n = readline();\nvar reposts = {\n\tpolycarp: 1\n};\nvar max = 1;\nfor (var i=0; i < n; i++) {\n\tvar str = readline().toLowerCase().split(' ');\n\tvar newValue = reposts[str[2]] + 1;\n\treposts[str[0]] = newValue;\n\tif (newValue > max) {\n\t\tmax = newValue;\n\t}\n}\nprint(max);"}, {"source_code": "\nfunction parseRepost(repostString) {\n var splitNames = repostString.split(\" reposted \");\n var parent = splitNames[1];\n var child = splitNames[0];\n\n return [parent.toLowerCase(), child.toLowerCase()];\n}\n\nfunction getPopularity() {\n var repostMap = {};\n var max = 0;\n var numPosts = parseInt(readline());\n for(var i = 0; i < numPosts; i++) {\n var users = parseRepost(readline());\n if(!repostMap.hasOwnProperty(users[0])) {\n repostMap[users[0]] = 1;\n }\n\n repostMap[users[1]] = repostMap[users[0]] + 1;\n if(repostMap[users[1]]> max) {\n max = repostMap[users[1]];\n }\n }\n return max;\n}\n\n\n\nprint(getPopularity());\n"}, {"source_code": "var l = +readline();\nvar chainLengths = {}\n\nchainLengths[\"polycarp\"] = 1\nvar maxLen = 0\n\nfor (var i = 0; i < l; i++) {\n var rec = readline().split(' reposted ');\n var a = rec[0].toLowerCase()\n var b = rec[1].toLowerCase()\n chainLengths[a] = chainLengths[b] + 1\n if (chainLengths[a] > maxLen) {\n maxLen = chainLengths[a]\n }\n}\n\nprint(maxLen);"}, {"source_code": "// #################################################################### //\n/**\n * @class UserNode will constitute the nodes of our repost tree,\n * with each node in the tree maintaining a count of the longest\n * chain perturbing from this node, and a reference to its parent\n * node.\n *\n * NOTE: the popularity attribute of the node or the popularity of\n * of this node's subtree refers to the length of the longest chain\n * perturbing from this node, with it as root.\n */\nvar UserNode = function(name){\n // Method to append a child node to children list.\n this.appendChild = function(childName){\n var newChild = new UserNode(childName.toLowerCase());\n newChild.parent = self;\n self.children.push(newChild);\n }\n // Method to get reference to the last child of this node.\n this.getLastChild = function(){\n return self.children[self.children.length-1];\n }\n // Method to determine popularity of this nodes's subtree.\n this.computePopularity = function(){\n var maxPopularity = 0;\n for(var i = 0;i 0; i--) {\n var line = readline().split(\" \");\n var len = posts[line[2].toLowerCase()] + 1;\n posts[line[0].toLowerCase()] = len;\n if (max < len) max = len;\n}\nprint(max);\n"}, {"source_code": "var n = parseInt(readline());\nvar s, m=0, a = new Array(), b = new Array(), l = new Array();\nfor(i=0; i=0; j--) {\nl[j] = 2;\nkk = b[j];\nwhile (kk != b[0]) {\nfor (i=0; i m) m = l[j];\n}\nprint(m);"}, {"source_code": "function Stack()\n{\n this.a = [];\n}\n\nStack.prototype.empty = function()\n{\n return this.a.length == 0;\n}\n\nStack.prototype.push = function(v)\n{\n this.a.push(v);\n}\n\nStack.prototype.pop = function()\n{\n if (!this.empty())\n return this.a.pop();\n return undefined;\n}\n\nStack.prototype.top = function()\n{\n if (!this.empty())\n return this.a[this.a.length - 1];\n return undefined; \n}\n\nStack.prototype.clear = function()\n{\n this.a = [];\n}\n\nStack.prototype.size = function()\n{\n return this.a.length;\n}\n\nfunction Queue()\n{\n this.l = new Stack();\n this.r = new Stack();\n}\n\nQueue.prototype.push = function(v)\n{\n this.l.push(v);\n}\n\nQueue.prototype.empty = function()\n{\n return this.r.empty() && this.l.empty();\n}\n\nQueue.prototype.pop = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.pop();\n return undefined;\n}\n\nQueue.prototype.front = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.top();\n return undefined; \n}\n\nQueue.prototype.size = function()\n{\n return l.size() + r.size();\n}\n\nQueue.prototype.clear = function()\n{\n l.clear();\n r.clear();\n}\n\nfunction Reader()\n{\n this.b = [];\n this.c = 0;\n}\n\nReader.prototype.next = function()\n{\n if (this.c == this.b.length)\n {\n this.c = 0;\n this.b = readline().split(' ');\n } \n return this.b[this.c++];\n}\n\nfunction Writer()\n{\n this.l = [\"\"];\n this.c = 0;\n}\n\nWriter.prototype.print = function(s)\n{\n this.l[this.c] += s;\n}\n\nWriter.prototype.println = function(s)\n{\n if (s == undefined)\n s = \"\";\n this.l[this.c] += s;\n this.l.push(\"\");\n ++this.c;\n}\n\nWriter.prototype.flush = function()\n{\n print(this.l.join('\\n'));\n this.l = [];\n}\n\nMath.cmp = function(a, b)\n{\n return (+a > +b)-(+a < +b);\n}\n\nfunction Treap(cmp)\n{\n if (typeof cmp == \"undefined\")\n this.cmp = function(a,b){return ((a>b)-(a t.p)\n {\n var tmp = this._split(t, n.k);\n n.l = tmp.l;\n n.r = tmp.r;\n this._update(n);\n return n;\n }\n if (this.cmp(n.k, t.k) <= 0)\n t.l = this._insert(t.l, n);\n else\n t.r = this._insert(t.r, n);\n this._update(t);\n return t;\n}\n\nTreap.prototype.nth = function(n)\n{\n var cur = this._root;\n var lSize = 0;\n while(cur)\n {\n lSize = this._sizeOf(cur.l);\n if (lSize == n)\n return {k: cur.k, v: cur.v};\n cur = lSize > n ? cur.l : cur.r;\n if (lSize < n)\n n -= lSize + 1; \n } \n return null;\n}\n\nTreap.prototype._forEach = function(t, cb)\n{\n if (t.l)\n this._forEach(t.l, cb);\n cb(t.k, t.v);\n if (t.r)\n this._forEach(t.r, cb);\n}\n\nTreap.prototype.forEach = function(cb)\n{\n if (this._root)\n this._forEach(this._root, cb);\n}\n\nTreap.prototype.insert = function(k, v)\n{\n this._root = this._insert(this._root, new Treap.Node(k, v, Math.random()+Math.random(), null, null)); \n}\n\nTreap.prototype._merge = function(l, r)\n{\n if (!l)\n {\n this._update(r);\n return r;\n }\n if (!r)\n {\n this._update(l);\n return l;\n }\n if (l.p > r.p)\n {\n l.r = this._merge(l.r, r)\n this._update(l);\n return l;\n }\n r.l = this._merge(l, r.l);\n this._update(r);\n return r;\n}\n\nTreap.prototype._erase = function(t, k)\n{\n if (t.k == k)\n {\n var tmp = this._merge(t.l, t.r);\n this._update(tmp);\n return tmp;\n }\n if (this.cmp(k, t.k) <= 0)\n if (t.l)\n t.l = this._erase(t.l, k);\n else\n if (t.r)\n t.r = this._erase(t.r, k);\n this._update(t);\n return t;\n}\n\nTreap.prototype.erase = function(k)\n{\n if (this._root)\n this._root = this._erase(this._root, k);\n}\n\nTreap.prototype._get = function(t, k)\n{\n if (!t)\n return undefined;\n if (this.cmp(k, t.k) == 0)\n return t.v;\n if (this.cmp(k, t.k) < 0)\n return this._get(t.l, k);\n return this._get(t.r, k);\n}\n\nTreap.prototype.get = function(k)\n{\n if (this._root)\n return this._get(this._root, k);\n return undefined;\n}\n\nTreap.prototype.clear = function()\n{\n this._root = null;\n}\n\nTreap.prototype.size = function()\n{\n return (this._root?this._root.size:0);\n}\n\nfunction cmp(a, b)\n{\n if (a < b)\n return -1;\n if (a > b)\n return 1;\n return 0;\n}\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var treap = new Treap(cmp);\n treap.insert(\"polycarp\", 1);\n for(var i = 0; i < n; ++i)\n { \n var s = cin.next().toLowerCase();\n cin.next();\n var t = cin.next().toLowerCase();\n treap.insert(s, treap.get(t) + 1);\n }\n var ans = 0;\n treap.forEach(function(k, v){ans=Math.max(ans,v);});\n cout.print(ans);\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "\"use strict\";\nvar i = 0,\n\tdepth = {\n\t\t'polycarp': 1\n\t},\n\tmax = 0,\n\tpair,\n\tcur,\n\tn = +readline();\n\nfor (; i max && (max = cur);\n}\nprint(max);"}, {"source_code": "var n = parseInt(readline());\nvar s, m=0, a = new Array(), b = new Array(), l = new Array();\nfor(i=0; i=0; j--) {\nl[j] = 2;\nkk = b[j];\nwhile (kk != b[0]) {\nfor (i=0; i m) m = l[j];\n}\nprint(m);"}, {"source_code": "var count = readline();\nvar chain = {polycarp: []};\n\nfor(var i = 0; i < count; i++) {\n var names = readline()\n .split(' reposted ')\n .map(function(v) { return v.toLowerCase() });\n\n if(!chain[names[0]]) chain[names[0]] = chain[names[1]].concat();\n chain[names[0]].push(names[1]);\n}\n\nvar max = 0;\nfor(var key in chain) {\n var cur = chain[key].length + 1;\n if(max < cur) max = cur;\n}\n\nprint(max);\n"}], "negative_code": [{"source_code": "\"use strict\";\nvar i = 0,\n\tdepth = {\n\t\t'polycarp': 0\n\t},\n\tmax = 0,\n\tpair,\n\tcur,\n\tn = +readline();\n\nfor (; i max && (max = cur);\n}\nprint(max);"}, {"source_code": "//var n = parseInt(readline());\nvar s, m=0, a = new Array(), b = new Array(), l = new Array();\n/*for(i=0; i=0; j--) {\nl[j] = 2;\nkk = b[j];\nwhile (kk != b[0]) {\nfor (i=0; i m) m = l[j];\n}\nprint(m);"}, {"source_code": "var count = readline();\nvar chain = {};\n\nfor(var i = 0; i < count; i++) {\n var names = readline()\n .split(' reposted ')\n .map(function(v) { return v.toLowerCase() });\n\n if(!chain[names[0]]) chain[names[0]] = chain[names[1]] || [];\n chain[names[0]].push(names[1]);\n}\n\nvar max = 0;\nfor(var key in chain) {\n var cur = chain[key].length + 1;\n if(max < cur) max = cur;\n}\n\nprint(max);\n"}, {"source_code": "var n = readline();\nvar reposts = {\n\tpolycarp: 1\n};\nvar max = 1;\nfor (var i=0; i < n; i++) {\n\tvar str = readline().toLowerCase().split(' ');\n\tvar newValue = reposts[str[2]] + 1;\n\treposts[str[0]] = newValue;\n\tif (newValue > max) {\n\t\tmax = newValue;\n\t}\n}"}, {"source_code": "\nfunction parseRepost(repostString) {\n var splitNames = repostString.split(\" reposted \");\n var parent = splitNames[1];\n var child = splitNames[0];\n\n return [parent.toLowerCase(), child.toLowerCase()];\n}\n\nfunction getPopularity() {\n var repostMap = {};\n var max = 0;\n var numPosts = parseInt(readline());\n for(var i = 0; i < numPosts; i++) {\n var users = parseRepost(readline());\n if(!repostMap.hasOwnProperty(users[0])) {\n repostMap[users[0]] = 0;\n }\n\n repostMap[users[1]] = repostMap[users[0]] + 1;\n if(repostMap[users[1]]> max) {\n max = repostMap[users[1]];\n }\n }\n return max;\n}\n\n\n\nprint(getPopularity());\n"}], "src_uid": "16d4035b138137bbad247ccd5e560051"} {"source_code": "//Perfect Permutation\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let n = +inp.split(EOL)[0];\n \n if(n % 2 == 1) {\n \tprocess.stdout.write(\"-1\");\n \treturn;\n }\n\n for(let i = 1; i <= n; i += 2) {\n \tprocess.stdout.write((i + 1) + \" \" + i + \" \");\n }\n\n return;\n});", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tif ((n & 1) === 1) {\n\t\tconsole.log(-1);\n\t\treturn;\n\t}\n\n\tlet arr = [];\n\tfor (let i = 1; i <= n; i += 2) {\n\t\tarr[i - 1] = i + 1;\n\t\tarr[i] = i;\n\t}\n\n\tconsole.log(arr.join(' '));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let input = parseInt(readLine());\n if (input % 2 !== 0) {\n console.log(-1);\n return;\n }\n let finalArray = [];\n\n for (let i = 1; i <= input; i++) {\n if (i % 2 === 0) {\n finalArray.push(i - 1);\n } else {\n finalArray.push(i + 1);\n }\n }\n let final = finalArray.join(' ');\n\n console.log(final);\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let len = +readLine();\n if (len % 2 !== 0) {\n console.log(-1);\n return;\n }\n let result = [];\n let [even, odd] = [2, 1];\n\n for (let i = 1; i <= len; i++) {\n if (i % 2 === 0) {\n result.push(odd);\n odd += 2;\n } else {\n result.push(even);\n even += 2;\n }\n }\n console.log(result.join(\" \"));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n if(N % 2 == 1){\n myout(-1);\n return;\n }\n var output = [];\n for(var i = 1; i <= N; i += 2){\n output.push(i + 1);\n output.push(i);\n } \n myout(myconv(output, 8));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n\n if (n % 2 === 1) {\n console.log(-1);\n return;\n }\n\n let ans = [];\n for (let i = 1; i <= n; i++) {\n if (i % 2 === 1) {\n ans.push(i + 1);\n }\n else {\n ans.push(i - 1);\n }\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "\nvar n=+readline();\n\nif(n%2){\n\tprint(-1);\n}else{\n\tvar p=[];\n\tfor(var i=2; i<=n; i+=2){\n\t\tp.push(i);\n\t\tp.push(i-1);\n\t}\n\tprint(p.join(' '));\n}"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\n\tif (n%2 !== 0) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar t = [];\n\tfor (var i = 0; i < n; i += 2) t.push(i + 2, i + 1)\n\tprint( t.join(' ') );\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tif (n%2 == 1) {\n\t\tprint(-1);\n\t} else {\n\t\tvar result = [];\n\t\tfor (var i = 1; 2*i <= n; ++i) {\n\t\t\tresult.push(2*i);\n\t\t\tresult.push(2*i-1);\n\t\t}\n\t\tprint(result.join(' '));\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n\n if (n === 1) {\n console.log(-1);\n return;\n }\n\n let ans = [];\n for (let i = 1; i <= n; i++) {\n if (i % 2 === 1) {\n ans.push(i + 1);\n }\n else {\n ans.push(i - 1);\n }\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n if(N == 1){\n myout(-1);\n return;\n }\n var output = [];\n for(var i = 2; i <= N; i++){\n output.push(i);\n }\n output.push(1);\n myout(myconv(output, 8));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n\n if (n === 1) {\n console.log(-1);\n return;\n }\n\n const ans = [n];\n for (let i = 1; i < n; i++) {\n ans.push(i);\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n\n if (n === 1) {\n console.log(-1);\n return;\n }\n\n const ans = [];\n for (let i = n; i > 0; i--) {\n ans.push(i);\n }\n\n console.log(ans.join(' '));\n});\n"}], "src_uid": "204ba74195a384c59fb1357bdd71e16c"} {"source_code": "function solve() {\n var nr = read().split(' ').map(BigInt);\n var n = nr[0];\n var r = nr[1];\n if (r < n) {\n write('' + (r * (r + 1n) / 2n));\n } else {\n write('' + (n * (n - 1n) / 2n + 1n))\n }\n\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(s2i(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const [n, r] = readLineOfInts()\n\n const min = BigInt(Math.min(n-1, r))\n\n const result = (n <= r ? 1n : 0n) + (min * (min + 1n) / 2n)\n\n out += result.toString() + '\\n'\n }\n console.log(out)\n}\n"}, {"source_code": " // Lang: Node.js\n 'use strict';\n let x = '', y = 0;\n let print = x => console.log(x);\n \n process.stdin.on('data', inputStdin => x += inputStdin);\n process.stdin.on('end', () => { x = x.split('\\n'); main(); });\n let readline = () => x[y++];\n \n \n // ************************ Code Start ***************************\n \n function main() {\n var Tc = parseInt(readline());\n while (Tc-- > 0) {\n var Arr = readline().split(\" \").map(BigInt);\n var n = Arr[0];\n var r = Arr[1];\n if (r < n) {\n print(\"\" + (r * (r + 1n)) / 2n);\n } else {\n print(\"\" + ((n * (n - 1n)) / 2n + 1n));\n }\n }\n }"}, {"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n \n \n// ************************ Code Start ***************************\n \nfunction main() {\n var Tc = parseInt(readline());\n while (Tc-- > 0) {\n var Arr = readline().split(\" \").map(BigInt);\n var n = Arr[0];\n var r = Arr[1];\n if (r < n) {\n print(\"\" + (r * (r + 1n)) / 2n);\n } else {\n print(\"\" + ((n * (n - 1n)) / 2n + 1n));\n }\n }\n\n}"}, {"source_code": "const process = require('process');\n \nlet inp = \"\";\n\nfunction min(ba, bb) {\n if (ba < bb) return ba;\n return bb;\n}\n\nprocess.stdin.on('data', chunk => inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n let ic = 0;\n let ntest = +inp[ic++];\n while (ntest--) {\n let [n, r] = inp[ic++].split(' ').map(BigInt);\n\n let t = min(n - 1n, r);\n let ans = t * (t + 1n) / 2n;\n if (r >= n) {\n ++ans;\n }\n console.log(ans.toString());\n\n }\n});\n"}], "negative_code": [], "src_uid": "eb3d8259ca598c3c455ddfdbe433cb78"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,0,1,0];\r\n\tvar dx = [0,-1,0,1];\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar s = new Array(H);\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\ts[i] = nextCharArray();\r\n\t\t}\r\n\t\tvar queue = [];\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] != \".\"){\r\n\t\t\t\t\tqueue.push([i,j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(queue.length == 0){\r\n\t\t\tqueue.push([0,0]);\r\n\t\t\ts[0][0] = \"R\";\r\n\t\t}\r\n\t\twhile(queue.length > 0){\r\n\t\t\tvar tmp = queue.shift();\r\n\t\t\tvar y = tmp[0];\r\n\t\t\tvar x = tmp[1];\r\n\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\tvar nextY = y + dy[j];\r\n\t\t\t\tvar nextX = x + dx[j];\r\n\t\t\t\tif(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W){\r\n\t\t\t\t\tif(s[nextY][nextX] == \".\"){\r\n\t\t\t\t\t\tif(s[y][x] == \"R\"){\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"W\";\r\n\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"R\";\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tqueue.push([nextY, nextX]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < H - 1; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] == s[i + 1][j]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W - 1; j++){\r\n\t\t\t\tif(s[i][j] == s[i][j + 1]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"Yes\" : \"No\");\r\n\t\tif(isOK){\r\n\t\t\tfor(var i = 0; i < H; i++){\r\n\t\t\t\tmyout(myconv(s[i], 0));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}", "positive_code": [{"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", c => (i += c));\nprocess.stdin.on(\"end\", () => {\n\tconst { EOL } = require(\"os\");\n\tconst lines = i.split(EOL);\n\tsolve(lines);\n});\n\nfunction solve(lines) {\n\tconst t = lines[0];\n\tlet index = 1;\n\tfor (let i = 0; i < t; i++) {\n\t\tconst ij = lines[index++];\n\t\tconst [n, m] = ij.split(\" \").map(c => +c);\n\t\tlet map = { R: [], W: [], \".\": [] };\n\t\tfor (let j = 0; j < n; j++) {\n\t\t\tconst line = lines[index++];\n\t\t\tline.split(\"\").forEach((c, k) => {\n\t\t\t\tmap[c].push([(k + j) % 2, j, k]);\n\t\t\t});\n\t\t}\n\t\tlet rVal = -1;\n\t\tmap[\"R\"].forEach(element => {\n\t\t\tif (rVal === -1) {\n\t\t\t\trVal = element[0];\n\t\t\t} else if (element[0] !== rVal) {\n\t\t\t\trVal = -2;\n\t\t\t}\n\t\t});\n\t\tlet wVal = -1;\n\t\tmap[\"W\"].forEach(element => {\n\t\t\tif (wVal === -1) {\n\t\t\t\twVal = element[0];\n\t\t\t} else if (element[0] !== wVal) {\n\t\t\t\twVal = -2;\n\t\t\t}\n\t\t});\n\t\tif (rVal === -2 || wVal === -2 || (rVal === wVal && rVal !== -1) ) {\n\t\t\tconsole.log(\"NO\");\n\t\t} else {\n\t\t\tconsole.log(\"YES\");\n\t\t\tif (rVal === -1) {\n if(wVal === 1)\n\t\t\t\t rVal = 0;\n else \n rVal = 1;\n\t\t\t}\n\t\t\tfor (let l = 0; l < n; l++) {\n\t\t\t\tlet res = \"\";\n\t\t\t\tfor (let c = 0; c < m; c++) {\n\t\t\t\t\tif (rVal === (c + l) % 2) {\n\t\t\t\t\t\tres += \"R\";\n\t\t\t\t\t} else {\n\t\t\t\t\t\tres += \"W\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.log(res);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "/**\r\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\r\n *\r\n * To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other\r\n */\r\n\r\n// Write your solution here\r\nconst {EOL} = require(\"os\");\r\n\r\nfunction alternate_color(current_color) {\r\n return current_color === 'R' ? 'W' : 'R';\r\n}\r\n\r\nfunction is_valid(flag, start_color) {\r\n for (const row of flag) {\r\n let expected_color = start_color;\r\n for (const actual_color of row) {\r\n if (actual_color !== '.' && actual_color !== expected_color) {\r\n return false;\r\n }\r\n expected_color = alternate_color(expected_color);\r\n }\r\n start_color = alternate_color(start_color);\r\n }\r\n return true;\r\n}\r\n\r\nfunction print_solution(start_color, height, width) {\r\n for (let row_no = 0; row_no < height; row_no += 1) {\r\n let row_str = '';\r\n let color = start_color;\r\n for (let col_no = 0; col_no < width; col_no += 1) {\r\n row_str += color;\r\n color = alternate_color(color);\r\n }\r\n console.log(row_str);\r\n start_color = alternate_color(start_color);\r\n }\r\n\r\n}\r\n\r\nfunction solution({height, width, flag}) {\r\n for (const start_color of ['R', 'W']) {\r\n if (is_valid(flag, start_color)) {\r\n console.log('YES');\r\n print_solution(start_color, height, width);\r\n return;\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nfunction parse(input) {\r\n const [height, width] = input.shift().split(' ').map(Number);\r\n return {\r\n height, width,\r\n flag: input.splice(0, height).map(row => row.trim())\r\n };\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for (let _ = 0; _ < number_of_test_cases; _ += 1) {\r\n solution(parse(input));\r\n }\r\n process.exit();\r\n});"}, {"source_code": "const {EOL} = require(\"os\");\r\n\r\nfunction alternate_color(current_color) {\r\n return current_color === 'R' ? 'W' : 'R';\r\n}\r\n\r\nfunction is_valid(flag, start_color) {\r\n for (const row of flag) {\r\n let expected_color = start_color;\r\n for (const actual_color of row) {\r\n if (actual_color !== '.' && actual_color !== expected_color) {\r\n return false;\r\n }\r\n expected_color = alternate_color(expected_color);\r\n }\r\n start_color = alternate_color(start_color);\r\n }\r\n return true;\r\n}\r\n\r\nfunction print_solution(start_color, height, width) {\r\n for (let row_no = 0; row_no < height; row_no += 1) {\r\n let row_str = '';\r\n let color = start_color;\r\n for (let col_no = 0; col_no < width; col_no += 1) {\r\n row_str += color;\r\n color = alternate_color(color);\r\n }\r\n console.log(row_str);\r\n start_color = alternate_color(start_color);\r\n }\r\n\r\n}\r\n\r\nfunction solution({height, width, flag}) {\r\n for (const start_color of ['R', 'W']) {\r\n if (is_valid(flag, start_color)) {\r\n console.log('YES');\r\n print_solution(start_color, height, width);\r\n return;\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nfunction parse(input) {\r\n const [height, width] = input.shift().split(' ').map(Number);\r\n return {\r\n height, width,\r\n flag: input.splice(0, height).map(row => row.trim())\r\n };\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for (let _ = 0; _ < number_of_test_cases; _ += 1) {\r\n solution(parse(input));\r\n }\r\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n nn=readLine();\r\n nn=nn.split(\" \");\r\n n=parseInt(nn[0]);\r\n m=parseInt(nn[1]);\r\n grid=[];\r\n pos_x=-1,pos_y=-1;\r\n for(i=0;i=0;j--)\r\n {\r\n if(ch=='R')\r\n {\r\n cur='W';\r\n temp=grid[pos_x][j];\r\n if(temp===ch)\r\n {\r\n chk=false;\r\n break;\r\n }\r\n else\r\n {\r\n grid[pos_x][j]=cur;\r\n ch=cur;\r\n }\r\n }\r\n else\r\n {\r\n cur='R';\r\n temp=grid[pos_x][j];\r\n if(temp===ch)\r\n {\r\n chk=false;\r\n break;\r\n }\r\n else\r\n {\r\n grid[pos_x][j]=cur;\r\n ch=cur;\r\n }\r\n }\r\n }\r\n\r\n ///line right\r\n ch=grid[pos_x][pos_y];\r\n for(j=pos_y+1;j=0;i--)\r\n {\r\n now=grid[i+1][0];\r\n for(j=0;j args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n\r\nconst solve = (n, m, g) => {\r\n // pr(n, m, g);\r\n let res1 = generate(n, m, 'W');\r\n let res2 = generate(n, m, 'R');\r\n if (ok(g, res1)) {\r\n pr('YES');\r\n // pr(\"res1\", res1);\r\n res1 = res1.map(x => x.join(\"\"));\r\n for (const s of res1) pr(s);\r\n } else if (ok(g, res2)) {\r\n pr('YES');\r\n res2 = res2.map(x => x.join(\"\"));\r\n for (const s of res2) pr(s);\r\n } else {\r\n pr('NO');\r\n }\r\n};\r\n\r\nconst ok = (g, t) => {\r\n let n = g.length;\r\n let m = g[0].length;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (g[i][j] == '.') continue;\r\n if (g[i][j] != t[i][j]) return false;\r\n }\r\n }\r\n return true;\r\n};\r\n\r\nconst generate = (n, m, start) => {\r\n let res = [];\r\n let c = start;\r\n for (let i = 0; i < n; i++) {\r\n let tmp = [];\r\n for (let j = 0; j < m; j++) {\r\n tmp.push(c = transfer(c));\r\n }\r\n start = transfer(start);\r\n c = start;\r\n res.push(tmp);\r\n }\r\n return res;\r\n};\r\n\r\nconst transfer = (c) => {\r\n return c == 'W' ? 'R' : 'W';\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let s = input[i];\r\n let a = s.split(\" \").map(Number);\r\n let [n, m] = [a[0], a[1]];\r\n let tmp = input.slice(i + 1, i + n + 1);\r\n tmp = tmp.map(s => s.split(\"\"));\r\n solve(n, m, tmp);\r\n i += n + 1;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for (let sc = 0; sc < nsc; sc++) {\r\n let n, m;\r\n [n, m] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const table = new Array(n);\r\n for (let i = 0; i < n; i++)\r\n table[i] = (await getLine()).split(\"\");\r\n let fail = false;\r\n let dfs = function (row, col) {\r\n let delta = [-1, 0, 1];\r\n for (let i = 0; i < 3; i++)\r\n for (let j = 0; j < 3; j++) {\r\n if (Math.abs(delta[i]) + Math.abs(delta[j]) === 1) {\r\n let nrow = row + delta[i];\r\n let ncol = col + delta[j];\r\n if (nrow >= 0 && nrow < n && ncol >= 0 && ncol < m) {\r\n if (table[nrow][ncol] === table[row][col])\r\n return -1;\r\n else if (table[nrow][ncol] === '.') {\r\n if (table[row][col] == 'R')\r\n table[nrow][ncol] = 'W';\r\n else\r\n table[nrow][ncol] = 'R';\r\n if (dfs(nrow, ncol) < 0)\r\n return -1;\r\n }\r\n }\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\n for (let row = 0; row < n && !fail; row++)\r\n for (let col = 0; col < m && !fail; col++)\r\n if (table[row][col] !== '.') {\r\n if (dfs(row, col) < 0) {\r\n fail = true;\r\n }\r\n }\r\n if (table[0][0] === '.') {\r\n table[0][0] = 'R';\r\n if (dfs(0,0) < 0)\r\n faile = true;\r\n }\r\n if (fail)\r\n console.log('NO');\r\n else {\r\n console.log('YES');\r\n for (let row = 0; row < n; row++)\r\n console.log(table[row].join(''));\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// End of Codeforces interface\r\n\r\nfunction fillLine(c1, c2, index, length) {\r\n let line = '';\r\n for (let i = 0; i < length; i++) {\r\n const first = index % 2 == i % 2;\r\n line += (first ? c1 : c2);\r\n }\r\n return line;\r\n}\r\n\r\nfunction fillGrid(x, y, c1, c2) {\r\n const grid = [];\r\n for (let i = 0; i < x; i++) {\r\n grid.push(fillLine(c1, c2, i, y));\r\n }\r\n return grid;\r\n}\r\n\r\nfunction isOkGrid(initialGrid, finalGrid) {\r\n try {\r\n initialGrid.forEach((x, i) => {\r\n for (let y = 0; y < x.length; y++) {\r\n if (x.charAt(y) != '.') {\r\n if (x.charAt(y) != finalGrid[i].charAt(y)) throw new Error();\r\n }\r\n }\r\n });\r\n return true;\r\n } catch (e) {\r\n return false;\r\n }\r\n}\r\n\r\nfunction main() {\r\n let testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n let [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n let initialGrid = [];\r\n let finalGrid;\r\n let isOkTestCase;\r\n\r\n for (let j = 0; j < x; j++) {\r\n initialGrid.push(readline());\r\n }\r\n \r\n finalGrid = fillGrid(x, y, 'R', 'W');\r\n isOkTestCase = isOkGrid(initialGrid, finalGrid);\r\n\r\n if (!isOkTestCase) {\r\n finalGrid = fillGrid(x, y, 'W', 'R');\r\n isOkTestCase = isOkGrid(initialGrid, finalGrid);\r\n }\r\n\r\n if (isOkTestCase) {\r\n console.log('YES');\r\n for (let line of finalGrid) {\r\n console.log(line);\r\n }\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n let isOkTestCase = true;\r\n let first = '.';\r\n let second = '.';\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n const r = line.indexOf('R');\r\n const w = line.indexOf('W');\r\n if (first == '.' && second == '.') {\r\n if (r !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'R';\r\n second = 'W';\r\n } else {\r\n first = 'W';\r\n second = 'R';\r\n }\r\n }\r\n if (w !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'W';\r\n second = 'R';\r\n } else {\r\n first = 'R';\r\n second = 'W';\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (first == '.' || second == '.') {\r\n first = 'R';\r\n second = 'W';\r\n }\r\n \r\n let color = '.';\r\n forloop:\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0) {\r\n color = first;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n } else {\r\n color = second;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (isOkTestCase) {\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n let isOkTestCase = true;\r\n let first = '.';\r\n let second = '.';\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n const r = line.indexOf('R');\r\n const w = line.indexOf('W');\r\n if (first == '.' && second == '.') {\r\n if (r !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'R';\r\n second = 'W';\r\n } else {\r\n first = 'W';\r\n second = 'R';\r\n }\r\n }\r\n if (w !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'W';\r\n second = 'R';\r\n } else {\r\n first = 'R';\r\n second = 'W';\r\n }\r\n }\r\n }\r\n }\r\n \r\n let color = '.';\r\n forloop:\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0) {\r\n color = first;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n } else {\r\n color = second;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (isOkTestCase) {\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n let isOkTestCase = true;\r\n let first = '.';\r\n let second = '.';\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n const r = line.indexOf('R');\r\n const w = line.indexOf('W');\r\n if (first == '.' && second == '.') {\r\n if (r !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'R';\r\n second = 'W';\r\n } else {\r\n first = 'W';\r\n second = 'R';\r\n }\r\n }\r\n if (w !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'W';\r\n second = 'R';\r\n } else {\r\n first = 'R';\r\n second = 'W';\r\n }\r\n }\r\n }\r\n }\r\n \r\n let color = '.';\r\n forloop:\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0) {\r\n color = first;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n } else {\r\n color = second;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (isOkTestCase) {\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction isDifferentNeighborTwo(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 != c2) return true; else return false;\r\n}\r\n\r\nfunction isEqualNeighbor(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 == c2) return true; else return false;\r\n}\r\n\r\nfunction isOkGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n for (let i = -2; i <= 2; i = i + 4) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n for (let i = -1; i <= 1; i = i + 2) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction isGridComplete(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == '.') return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n let isOkTestCase = true;\r\n let first = '.';\r\n let second = '.';\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n const r = line.indexOf('R');\r\n const w = line.indexOf('W');\r\n if (first == '.' && second == '.') {\r\n if (r !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'R';\r\n second = 'W';\r\n } else {\r\n first = 'W';\r\n second = 'R';\r\n }\r\n }\r\n if (w !== -1) {\r\n if (j % 2 == 0 && r % 2 == 0 || j % 2 != 0 && r % 2 != 0) {\r\n first = 'W';\r\n second = 'R';\r\n } else {\r\n first = 'R';\r\n second = 'W';\r\n }\r\n }\r\n }\r\n }\r\n \r\n let color = '.';\r\n forloop:\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0) {\r\n color = first;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n } else {\r\n color = second;\r\n if (grid[x][y] == '.') {\r\n grid[x][y] = color;\r\n } else if (grid[x][y] != color) {\r\n isOkTestCase = false;\r\n break forloop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (isOkTestCase) {\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction isDifferentNeighborTwo(x1, y1, x2, y2, grid) {\r\n if (x2 < 0 || y2 < 0) return false;\r\n if (x2 >= grid.length || y2 >= grid[x2].length) return false;\r\n if (grid[x1][y1] == '.' || grid[x2][y2] == '.') return false;\r\n if (grid[x1][y1] != grid[x2][y2]) return true; else return false;\r\n}\r\n\r\nfunction isEqualNeighbor(x1, y1, x2, y2, grid) {\r\n if (x2 < 0 || y2 < 0) return false;\r\n if (x2 >= grid.length || y2 >= grid[x2].length) return false;\r\n if (grid[x1][y1] == '.' || grid[x2][y2] == '.') return false;\r\n if (grid[x1][y1] == grid[x2][y2]) return true; else return false;\r\n}\r\n\r\nfunction isOkCell(x, y, grid) {\r\n if (\r\n isEqualNeighbor(x, y, x-1, y, grid) ||\r\n isEqualNeighbor(x, y, x+1, y, grid) ||\r\n isEqualNeighbor(x, y, x, y-1, grid) ||\r\n isEqualNeighbor(x, y, x, y+1, grid) ||\r\n\r\n isDifferentNeighborTwo(x, y, x-2, y, grid) ||\r\n isDifferentNeighborTwo(x, y, x+2, y, grid) ||\r\n isDifferentNeighborTwo(x, y, x, y-2, grid) ||\r\n isDifferentNeighborTwo(x, y, x, y+2, grid)\r\n ) return false; else return true;\r\n}\r\n\r\nfunction isOkGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (!isOkCell(x, y, grid)) return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction fillCell(x, y, grid, color) {\r\n if (x < 0 || y < 0) return;\r\n if (x >= grid.length || y >= grid[x].length) return;\r\n if (grid[x][y] != '.') return;\r\n grid[x][y] = color;\r\n}\r\n\r\nfunction fillNeighborCells(x, y, grid) {\r\n if (grid[x][y] == 'R') {\r\n fillCell(x-1, y, grid, 'W');\r\n fillCell(x+1, y, grid, 'W');\r\n fillCell(x, y-1, grid, 'W');\r\n fillCell(x, y+1, grid, 'W');\r\n } else {\r\n fillCell(x-1, y, grid, 'R');\r\n fillCell(x+1, y, grid, 'R');\r\n fillCell(x, y-1, grid, 'R');\r\n fillCell(x, y+1, grid, 'R');\r\n }\r\n}\r\n\r\nfunction isGridComplete(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == '.') return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction fillGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n fillNeighborCells(x, y, grid);\r\n }\r\n }\r\n}\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n const testCases = [];\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n }\r\n \r\n testCases.push({ x, y, grid });\r\n }\r\n \r\n testCases.forEach((testCase) => {\r\n if (isOkGrid(testCase.grid)) {\r\n testCase.isOk = true;\r\n } else {\r\n testCase.isOk = false;\r\n }\r\n });\r\n\r\n testCases.forEach((testCase) => {\r\n if (testCase.isOk) {\r\n fillGrid(testCase.grid);\r\n }\r\n });\r\n \r\n testCases.forEach((testCase) => {\r\n if (isOkGrid(testCase.grid)) {\r\n testCase.isOk = true;\r\n } else {\r\n testCase.isOk = false;\r\n }\r\n });\r\n\r\n testCases.forEach((testCase) => {\r\n if (testCase.isOk) {\r\n console.log('YES');\r\n printGrid(testCase.grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n });\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction isDifferentNeighborTwo(x1, y1, x2, y2, grid) {\r\n if (x2 < 0 || y2 < 0) return false;\r\n if (x2 >= grid.length || y2 >= grid[x2].length) return false;\r\n if (grid[x1][y1] == '.' || grid[x2][y2] == '.') return false;\r\n if (grid[x1][y1] != grid[x2][y2]) return true; else return false;\r\n}\r\n\r\nfunction isEqualNeighbor(x1, y1, x2, y2, grid) {\r\n if (x2 < 0 || y2 < 0) return false;\r\n if (x2 >= grid.length || y2 >= grid[x2].length) return false;\r\n if (grid[x1][y1] == '.' || grid[x2][y2] == '.') return false;\r\n if (grid[x1][y1] == grid[x2][y2]) return true; else return false;\r\n}\r\n\r\nfunction isOkCell(x, y, grid) {\r\n if (\r\n isEqualNeighbor(x, y, x-1, y, grid) ||\r\n isEqualNeighbor(x, y, x+1, y, grid) ||\r\n isEqualNeighbor(x, y, x, y-1, grid) ||\r\n isEqualNeighbor(x, y, x, y+1, grid) ||\r\n\r\n isDifferentNeighborTwo(x, y, x-2, y, grid) ||\r\n isDifferentNeighborTwo(x, y, x+2, y, grid) ||\r\n isDifferentNeighborTwo(x, y, x, y-2, grid) ||\r\n isDifferentNeighborTwo(x, y, x, y+2, grid)\r\n ) return false; else return true;\r\n}\r\n\r\nfunction isOkGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (!isOkCell(x, y, grid)) return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction fillCell(x, y, grid, color) {\r\n if (x < 0 || y < 0) return;\r\n if (x >= grid.length || y >= grid[x].length) return;\r\n if (grid[x][y] != '.') return;\r\n grid[x][y] = color;\r\n}\r\n\r\nfunction fillNeighborCells(x, y, grid) {\r\n if (grid[x][y] == 'R') {\r\n fillCell(x-1, y, grid, 'W');\r\n fillCell(x+1, y, grid, 'W');\r\n fillCell(x, y-1, grid, 'W');\r\n fillCell(x, y+1, grid, 'W');\r\n } else {\r\n fillCell(x-1, y, grid, 'R');\r\n fillCell(x+1, y, grid, 'R');\r\n fillCell(x, y-1, grid, 'R');\r\n fillCell(x, y+1, grid, 'R');\r\n }\r\n}\r\n\r\nfunction isGridComplete(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == '.') return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction fillGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n fillNeighborCells(x, y, grid);\r\n }\r\n }\r\n}\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n const testCases = [];\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n }\r\n \r\n testCases.push({ x, y, grid });\r\n }\r\n \r\n testCases.forEach((testCase) => {\r\n if (isOkGrid(testCase.grid)) {\r\n testCase.isOk = true;\r\n } else {\r\n testCase.isOk = false;\r\n }\r\n });\r\n\r\n testCases.forEach((testCase) => {\r\n if (testCase.isOk) {\r\n fillGrid(testCase.grid);\r\n }\r\n });\r\n\r\n testCases.forEach((testCase) => {\r\n if (testCase.isOk) {\r\n console.log('YES');\r\n printGrid(testCase.grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n });\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction isDifferentNeighborTwo(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 != c2) return true; else return false;\r\n}\r\n\r\nfunction isEqualNeighbor(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 == c2) return true; else return false;\r\n}\r\n\r\nfunction isOkGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n for (let i = -2; i <= 2; i = i + 4) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n for (let i = -1; i <= 1; i = i + 2) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction isGridComplete(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == '.') return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n }\r\n\r\n if (isOkGrid(grid)) {\r\n let color = '.';\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == 'R') {\r\n color = 'W';\r\n } else {\r\n color = 'R';\r\n }\r\n for (let i = -1; i <= 1; i = i + 2) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length) {\r\n if (grid[x2][y] == '.')\r\n grid[x2][y] = color;\r\n }\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid[x].length) {\r\n if (grid[x][y2] == '.')\r\n grid[x][y2] = color;\r\n }\r\n }\r\n }\r\n }\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction isDifferentNeighborTwo(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 != c2) return true; else return false;\r\n}\r\n\r\nfunction isEqualNeighbor(c1, c2) {\r\n if (!c1 || !c2 || c1 == '.' || c2 == '.') return false;\r\n if (c1 == c2) return true; else return false;\r\n}\r\n\r\nfunction isOkGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n for (let i = -2; i <= 2; i = i + 4) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isDifferentNeighborTwo(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n for (let i = -1; i <= 1; i = i + 2) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x2][y]))\r\n return false;\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid.length)\r\n if (isEqualNeighbor(grid[x][y], grid[x][y2]))\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction isGridComplete(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == '.') return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction printGrid(grid) {\r\n for (let x = 0; x < grid.length; x++) {\r\n console.log(grid[x].join(''));\r\n }\r\n}\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n const [x, y] = readline().split(\" \").map(n => parseInt(n));\r\n const grid = [];\r\n\r\n for (let j = 0; j < x; j++) {\r\n const line = readline().split(\"\");\r\n grid.push(line);\r\n }\r\n\r\n if (isOkGrid(grid)) {\r\n let color = '.';\r\n for (let x = 0; x < grid.length; x++) {\r\n for (let y = 0; y < grid[x].length; y++) {\r\n if (grid[x][y] == 'R') {\r\n color = 'W';\r\n } else {\r\n color = 'R';\r\n }\r\n for (let i = -1; i <= 1; i = i + 2) {\r\n const x2 = x + i;\r\n if (x2 >= 0 && x2 < grid.length) {\r\n grid[x2][y] = color;\r\n }\r\n const y2 = y + i;\r\n if (y2 >= 0 && y2 < grid[x].length) {\r\n grid[x][y2] = color;\r\n }\r\n }\r\n }\r\n }\r\n console.log('YES');\r\n printGrid(grid);\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,0,1,0];\r\n\tvar dx = [0,-1,0,1];\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar s = new Array(H);\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\ts[i] = nextCharArray();\r\n\t\t}\r\n\t\tvar queue = [];\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] != \".\"){\r\n\t\t\t\t\tqueue.push([i,j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(queue.length == 0){\r\n\t\t\tqueue.push([0,0]);\r\n\t\t}\r\n\t\twhile(queue.length > 0){\r\n\t\t\tvar tmp = queue.shift();\r\n\t\t\tvar y = tmp[0];\r\n\t\t\tvar x = tmp[1];\r\n\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\tvar nextY = y + dy[j];\r\n\t\t\t\tvar nextX = x + dx[j];\r\n\t\t\t\tif(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W){\r\n\t\t\t\t\tif(s[nextY][nextX] == \".\"){\r\n\t\t\t\t\t\tif(s[y][x] == \"R\"){\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"W\";\r\n\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"R\";\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tqueue.push([nextY, nextX]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < H - 1; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] == s[i + 1][j]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W - 1; j++){\r\n\t\t\t\tif(s[i][j] == s[i][j + 1]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"Yes\" : \"No\");\r\n\t\tif(isOK){\r\n\t\t\tfor(var i = 0; i < H; i++){\r\n\t\t\t\tmyout(myconv(s[i], 0));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,0,1,0];\r\n\tvar dx = [0,-1,0,1];\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar s = new Array(H);\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\ts[i] = nextCharArray();\r\n\t\t}\r\n\t\tvar queue = [];\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] != \".\"){\r\n\t\t\t\t\tqueue.push([i,j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twhile(queue.length > 0){\r\n\t\t\tvar tmp = queue.shift();\r\n\t\t\tvar y = tmp[0];\r\n\t\t\tvar x = tmp[1];\r\n\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\tvar nextY = y + dy[j];\r\n\t\t\t\tvar nextX = x + dx[j];\r\n\t\t\t\tif(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W){\r\n\t\t\t\t\tif(s[nextY][nextX] == \".\"){\r\n\t\t\t\t\t\tif(s[y][x] == \"R\"){\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"W\";\r\n\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\ts[nextY][nextX] = \"R\";\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tqueue.push([nextY, nextX]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < H - 1; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(s[i][j] == s[i + 1][j]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W - 1; j++){\r\n\t\t\t\tif(s[i][j] == s[i][j + 1]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"Yes\" : \"No\");\r\n\t\tif(isOK){\r\n\t\t\tfor(var i = 0; i < H; i++){\r\n\t\t\t\tmyout(myconv(s[i], 0));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", c => (i += c));\nprocess.stdin.on(\"end\", () => {\n\tconst { EOL } = require(\"os\");\n\tconst lines = i.split(EOL);\n\tsolve(lines);\n});\n\nfunction solve(lines) {\n\tconst t = lines[0];\n\tlet index = 1;\n\tfor (let i = 0; i < t; i++) {\n\t\tconst ij = lines[index++];\n\t\tconst [n, m] = ij.split(\" \").map(c => +c);\n\t\tlet map = { R: [], W: [], \".\": [] };\n\t\tfor (let j = 0; j < n; j++) {\n\t\t\tconst line = lines[index++];\n\t\t\tline.split(\"\").forEach((c, k) => {\n\t\t\t\tmap[c].push([(k + j) % 2, j, k]);\n\t\t\t});\n\t\t}\n\t\tlet rVal = -1;\n\t\tmap[\"R\"].forEach(element => {\n\t\t\tif (rVal === -1) {\n\t\t\t\trVal = element[0];\n\t\t\t} else if (element[0] !== rVal) {\n\t\t\t\trVal = -2;\n\t\t\t}\n\t\t});\n\t\tlet wVal = -1;\n\t\tmap[\"W\"].forEach(element => {\n\t\t\tif (wVal === -1) {\n\t\t\t\twVal = element[0];\n\t\t\t} else if (element[0] !== wVal) {\n\t\t\t\twVal = -2;\n\t\t\t}\n\t\t});\n\t\tif (rVal === -2 || wVal === -2 || rVal === wVal) {\n\t\t\tconsole.log(\"NO\");\n\t\t} else {\n\t\t\tconsole.log(\"YES\");\n\t\t\tif (rVal === -1) {\n if(wVal === 1)\n\t\t\t\t rVal = 0;\n else \n rVal = 1;\n\t\t\t}\n\t\t\tfor (let l = 0; l < n; l++) {\n\t\t\t\tlet res = \"\";\n\t\t\t\tfor (let c = 0; c < m; c++) {\n\t\t\t\t\tif (rVal === (c + l) % 2) {\n\t\t\t\t\t\tres += \"R\";\n\t\t\t\t\t} else {\n\t\t\t\t\t\tres += \"W\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.log(res);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n solve(lines); \n});\n\nfunction solve(lines){ \n const t = lines[0];\n let index = 1;\n for(let i =0; i < t; i++) {\n const ij = lines[index++];\n const [ n, m ] = ij.split(\" \").map(c=>+c);\n let map = { \"R\": [], \"W\": [], \".\": [] };\n for(let j = 0; j < n; j++) {\n const line = lines[index++];\n line.split(\"\").forEach((c, k) => {\n map[c].push([(k+j)%2 ,j, k]);\n \n });\n\n }\n let rVal = -1;\n map[\"R\"].forEach((element) => {\n if(rVal === -1) {\n rVal = element[0];\n } else if(element[0] !== rVal){\n rVal = -2;\n }\n });\n let wVal = -1;\n map[\"W\"].forEach((element) => {\n if(wVal === -1) {\n wVal = element[0];\n } else if(element[0] !== wVal){\n wVal = -2;\n }\n });\n if(rVal === -2 || wVal === -2 || rVal === wVal) {\n console.log(\"NO\")\n } else {\n console.log(\"YES\");\n for(let l = 0; l < n ; l++){\n let res = \"\";\n for(let c = 0; c < m ; c++) {\n if(rVal === (c+l)%2) {\n res+=\"R\";\n } else {\n res+=\"W\";\n }\n }\n console.log(res);\n }\n }\n }\n}"}], "src_uid": "12f35743f482b68e3156a45d6ac5bb14"} {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(u = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= u.length\r\n },\r\n readLine: i,\r\n readLineAsNumber: function () {\r\n return Number(i())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = i().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = i().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function i() {\r\n return u[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let o = 0\r\n return {\r\n flush: i,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function i() {\r\n n.write(u.toString(e, 0, o)), (o = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - o < s && (i(), s >= r) ? n.write(t) : (u.write(t, o, e), (o += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\nconst MAX_N = 300010,\r\n sum = new Array(MAX_N)\r\n__main__(\r\n function (t) {\r\n const n = t.readLineAsNumber()\r\n sum[0] = 0\r\n for (let e = 1; e <= n; ++e) {\r\n const [n, e] = t.readIntegersOfLine(),\r\n r = t.readLine()\r\n for (let t = 0; t < n; ++t) {\r\n const n = r[t],\r\n e = (t + 1) & 1 ? ('+' === n ? 1 : -1) : '+' === n ? -1 : 1\r\n sum[t + 1] = sum[t] + e\r\n }\r\n for (let n = 1; n <= e; ++n) {\r\n const [n, e] = t.readIntegersOfLine(),\r\n r = (e - n + 1) & 1 ? 1 : sum[e] === sum[n - 1] ? 0 : 2\r\n t.println(r)\r\n }\r\n }\r\n },\r\n void 0,\r\n { outputBufferThreshold: 1 << 26 },\r\n)\r\n", "positive_code": [{"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(u = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= u.length\r\n },\r\n readLine: i,\r\n readLineAsNumber: function () {\r\n return Number(i())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = i().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = i().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function i() {\r\n return u[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let o = 0\r\n return {\r\n flush: i,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function i() {\r\n n.write(u.toString(e, 0, o)), (o = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - o < s && (i(), s >= r) ? n.write(t) : (u.write(t, o, e), (o += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\nconst MAX_N = 300010,\r\n sum = new Array(MAX_N)\r\n__main__(\r\n function (t) {\r\n const n = t.readLineAsNumber()\r\n sum[0] = 0\r\n for (let e = 1; e <= n; ++e) {\r\n const [n, e] = t.readIntegersOfLine(),\r\n r = t.readLine()\r\n for (let t = 0; t < n; ++t) {\r\n const n = r[t],\r\n e = (t + 1) & 1 ? ('+' === n ? 1 : -1) : '+' === n ? -1 : 1\r\n sum[t + 1] = sum[t] + e\r\n }\r\n for (let n = 1; n <= e; ++n) {\r\n const [n, e] = t.readIntegersOfLine(),\r\n r = (e - n + 1) & 1 ? 1 : sum[e] === sum[n - 1] ? 0 : 2\r\n t.println(r)\r\n }\r\n }\r\n },\r\n void 0,\r\n { outputBufferThreshold: 1 << 20 },\r\n)\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n encoding\r\n outputBuffer\r\n outputBufferThreshold\r\n outputBufferSize\r\n lineIndex = 0\r\n lines = []\r\n constructor(t) {\r\n ;(this.outputBufferThreshold = t.outputBufferThreshold || 1 << 24),\r\n (this.outputBuffer = Buffer.alloc(this.outputBufferThreshold)),\r\n (this.encoding = t.encoding || 'ascii'),\r\n (this.outputBufferSize = 0)\r\n }\r\n flush() {\r\n const { encoding: t, outputBuffer: e, outputBufferSize: n } = this\r\n stdout.write(e.toString(t, 0, n)), (this.outputBufferSize = 0)\r\n }\r\n print(t) {\r\n const e = Buffer.byteLength(t, this.encoding)\r\n this.outputBufferThreshold - this.outputBufferSize < e &&\r\n (this.flush(), e >= this.outputBufferThreshold)\r\n ? stdout.write(t)\r\n : (this.outputBuffer.write(t, this.outputBufferSize, this.encoding),\r\n (this.outputBufferSize += e))\r\n }\r\n printNumber(t) {\r\n this.print(String(t))\r\n }\r\n println(t) {\r\n this.print(String(t).concat('\\n'))\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const t = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), t\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const t = this.readLine().match(integerRegex)\r\n return null == t ? [] : t.map(t => Number(t))\r\n }\r\n readNumsOfLine() {\r\n const t = this.readLine().match(decimalRegex)\r\n return null == t ? [] : t.map(t => Number(t))\r\n }\r\n async init() {\r\n const t = await this.readLines()\r\n this.lines = t\r\n }\r\n readLines() {\r\n const t = []\r\n return new Promise(e => {\r\n stdin.on('data', e => t.push(e)),\r\n stdin.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(t, e = {}) {\r\n const n = new InputAndOutput(e)\r\n await n.init(), await t(n), n.flush()\r\n}\r\nconst MAX_N = 300010,\r\n sum = new Array(MAX_N)\r\n__main__(function (t) {\r\n const e = t.readLineAsNumber()\r\n sum[0] = 0\r\n for (let n = 1; n <= e; ++n) {\r\n const [e, n] = t.readIntegersOfLine(),\r\n i = t.readLine()\r\n for (let t = 0; t < e; ++t) {\r\n const e = i[t],\r\n n = (t + 1) & 1 ? ('+' === e ? 1 : -1) : '+' === e ? -1 : 1\r\n sum[t + 1] = sum[t] + n\r\n }\r\n for (let e = 1; e <= n; ++e) {\r\n const [e, n] = t.readIntegersOfLine(),\r\n i = (n - e + 1) & 1 ? 1 : sum[n] === sum[e - 1] ? 0 : 2\r\n t.println(i)\r\n }\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n encoding\r\n outputBuffer\r\n outputBufferThreshold\r\n outputBufferSize\r\n lineIndex = 0\r\n lines = []\r\n constructor(t) {\r\n ;(this.outputBufferThreshold = t.outputBufferThreshold || 1 << 24),\r\n (this.outputBuffer = Buffer.alloc(this.outputBufferThreshold)),\r\n (this.encoding = t.encoding || 'ascii'),\r\n (this.outputBufferSize = 0)\r\n }\r\n flush() {\r\n const { encoding: t, outputBuffer: e, outputBufferSize: n } = this\r\n stdout.write(e.toString(t, 0, n)), (this.outputBufferSize = 0)\r\n }\r\n print(t) {\r\n const e = Buffer.byteLength(t, this.encoding)\r\n this.outputBufferThreshold - this.outputBufferSize < e &&\r\n (this.flush(), e >= this.outputBufferThreshold)\r\n ? stdout.write(t)\r\n : (this.outputBuffer.write(t, this.outputBufferSize, this.encoding),\r\n (this.outputBufferSize += e))\r\n }\r\n printNumber(t) {\r\n this.print(String(t))\r\n }\r\n println(t) {\r\n stdout.write(String(t).concat('\\n'))\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const t = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), t\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const t = this.readLine().match(integerRegex)\r\n return null == t ? [] : t.map(t => Number(t))\r\n }\r\n readNumsOfLine() {\r\n const t = this.readLine().match(decimalRegex)\r\n return null == t ? [] : t.map(t => Number(t))\r\n }\r\n async init() {\r\n const t = await this.readLines()\r\n this.lines = t\r\n }\r\n readLines() {\r\n const t = []\r\n return new Promise(e => {\r\n stdin.on('data', e => t.push(e)),\r\n stdin.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(t, e = {}) {\r\n const n = new InputAndOutput(e)\r\n await n.init(), await t(n), n.flush()\r\n}\r\nconst MAX_N = 300010,\r\n sum = new Array(MAX_N)\r\n__main__(function (t) {\r\n const e = t.readLineAsNumber()\r\n sum[0] = 0\r\n for (let n = 1; n <= e; ++n) {\r\n const [e, n] = t.readIntegersOfLine(),\r\n i = t.readLine()\r\n for (let t = 0; t < e; ++t) {\r\n const e = i[t],\r\n n = (t + 1) & 1 ? ('+' === e ? 1 : -1) : '+' === e ? -1 : 1\r\n sum[t + 1] = sum[t] + n\r\n }\r\n const s = []\r\n for (let e = 1; e <= n; ++e) {\r\n const [e, n] = t.readIntegersOfLine(),\r\n i = (n - e + 1) & 1 ? 1 : sum[n] === sum[e - 1] ? 0 : 2\r\n s.push(i)\r\n }\r\n t.println(s.join('\\n'))\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const n = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), n\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const n = this.readLine().match(integerRegex)\r\n return null == n ? [] : n.map(n => Number(n))\r\n }\r\n readNumsOfLine() {\r\n const n = this.readLine().match(decimalRegex)\r\n return null == n ? [] : n.map(n => Number(n))\r\n }\r\n print(n) {\r\n stdout.write(String(n))\r\n }\r\n println(n) {\r\n stdout.write(String(n)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const n = await this.readLines()\r\n this.lines = n\r\n }\r\n readLines() {\r\n const n = []\r\n return new Promise(e => {\r\n stdin.on('data', e => n.push(e)),\r\n stdin.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(n) {\r\n const e = new InputAndOutput()\r\n await e.init(), n(e)\r\n}\r\nconst MAX_N = 300010,\r\n sum = new Array(MAX_N)\r\n__main__(function (n) {\r\n const e = n.readLineAsNumber()\r\n sum[0] = 0\r\n for (let t = 1; t <= e; ++t) {\r\n const [e, t] = n.readIntegersOfLine(),\r\n s = n.readLine()\r\n for (let n = 0; n < e; ++n) {\r\n const e = s[n],\r\n t = (n + 1) & 1 ? ('+' === e ? 1 : -1) : '+' === e ? -1 : 1\r\n sum[n + 1] = sum[n] + t\r\n }\r\n const i = []\r\n for (let e = 1; e <= t; ++e) {\r\n const [e, t] = n.readIntegersOfLine(),\r\n s = (t - e + 1) & 1 ? 1 : sum[t] === sum[e - 1] ? 0 : 2\r\n i.push(s)\r\n }\r\n n.println(i.join('\\n'))\r\n }\r\n})\r\n"}], "negative_code": [], "src_uid": "3f7f29e57cc03be8ff1251ab42738739"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let [l, r, a] = readLine().split(\" \").map(i => BigInt(i));\r\n let ans = r / a + r % a;\r\n let m = r / a * a - 1n;\r\n if (m >= l) ans = Math.max(Number(ans), Number(m / a + m % a));\r\n console.log(Number(ans));\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let [l, r, a] = readLine().split(\" \").map(i => BigInt(i));\r\n let ans = r / a + r % a;\r\n let m = r / a * a - 1n;\r\n if (m >= l) ans = Math.max(Number(ans), Number(m / a + m % a));\r\n console.log(Number(ans));\r\n}\r\n"}, {"source_code": "var m = function(a){\n return Math.floor(a); \n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var l = k[0], r = k[1], a = k[2];\n var x = Math.floor((r + 1) / a) * a - 1;\n console.log(l <= x ? m(x / a) + m(x % a) : m(r / a) + m(r % a));\n }\n});"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet f = (a, x)=>{\n return Math.floor(x/a) + (x%a);\n};\nconst calc = (l, r, a)=>{\n let ans = f(a, l);\n ans = Math.max(ans, f(a, r));\n let R = r-r%a;\n if (R>=l && R<=r)\n ans = Math.max(ans, f(a, R));\n R--;\n if (R>=l && R<=r)\n ans = Math.max(ans, f(a, R));\n R-=2;\n if (R>=l && R<=r)\n ans = Math.max(ans, f(a, R));\n return ans;\n};\n\nfunction main() {\n let T = +readline()\n while (T--){\n let [l, r, a] = ra();\n print(calc(l, r, a));\n }\n}\n\nE.calc = calc;"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [left, right, a] = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(left, right, a)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(left, right, a) {\r\n // for (let i = left; i <= right; i++) {\r\n // console.log(i, cal(i, a))\r\n // }\r\n\r\n const r1 = left % a\r\n const k1 = Math.floor(left / a)\r\n const r2 = right % a\r\n const k2 = Math.floor(right / a)\r\n let ans = cal(right, a)\r\n if (right - r2 - 1 >= left) {\r\n ans = Math.max(ans, cal(right - r2 - 1, a))\r\n }\r\n return ans\r\nconsole.log(k1, k2)\r\n if (k2 - k1 > 1) return a - 1\r\n\r\n if (k1 === k2) {\r\n const v1 = cal(left, a)\r\n const v2 = cal(right, a)\r\n return get(v1, v2, a)\r\n } else {\r\n // k1 + 1 = k2\r\n const v1 = cal(left, a)\r\n const v2 = cal(left - r1 + a, a)\r\n const v3 = cal(right - r2, a)\r\n const v4 = cal(right, a)\r\n console.log(v1, v2, v3, v4)\r\n return Math.max(get(v1, v2, a), get(v3, v4, a))\r\n }\r\n}\r\nfunction get(v1, v2, a) {\r\n return v1 <= v2 ? v2 : a - 1\r\n}\r\nfunction cal(x, a) {\r\n const f = Math.floor(x / a) + x % a\r\n return f\r\n}\r\n"}, {"source_code": "function solve() {\r\n const [l, r, a] = readArray(Number);\r\n const modR = r % a;\r\n if (modR === a - 1) {\r\n write(f(r, a));\r\n return;\r\n }\r\n const x = r - modR - 1;\r\n if (x < l) {\r\n write(f(r, a));\r\n return;\r\n }\r\n write(f(x, a));\r\n}\r\n\r\nfunction f(x, a) {\r\n return (Math.floor(x / a) + x % a);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var k = readline().split(' ').map(Number);\r\n var l = k[0], r = k[1], a = k[2];\r\n var b = Math.floor(r / a) + r % a;\r\n var c = Math.floor(r / a) * a - 1;\r\n var d = Math.floor(c / a) + c % a;\r\n if (l <= c) b = Math.max(b, d);\r\n print(b);\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let [l, r, a] = readLine().split(\" \").map(i => parseInt(i));\r\n let ans = parseInt(r / a) + r % a;\r\n let m = parseInt(r / a) * a - 1;\r\n if (m >= l) ans = Math.max(ans, parseInt(m / a) + m % a);\r\n console.log(ans);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let [l, r, a] = readLine().split(\" \").map(i => parseInt(i));\r\n let R = r;\r\n if (r % a == 0) r--;\r\n let q = parseInt(r / a);\r\n if (r < l) {\r\n console.log(parseInt(R / a) + R % a);\r\n return;\r\n }\r\n if (r % a < parseInt(a / 2)) {\r\n if ((q * a - 1) >= l && (q * a - 1) <= R) {\r\n r = q * a - 1;\r\n console.log(parseInt(r / a) + r % a);\r\n return;\r\n } else {\r\n console.log(parseInt(r / a) + r % a)\r\n return;\r\n }\r\n } else {\r\n console.log(parseInt(r / a) + r % a);\r\n return;\r\n }\r\n}\r\n"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var b = Math.floor(a[1] / a[2]);\r\n var c = (Math.floor(a[1] / a[2]) - 1 + a[2] - 1);\r\n var r = Math.max(b + a[1] % a[2], c);\r\n if (a[0] <= a[2]) r * Math.floor(a[1] / a[2]) - 1;\r\n else r * Math.floor(a[1] / a[2]) + a[1] % a[2];\r\n print(r);\r\n}"}], "src_uid": "681ee82880ddd0de907aac2ccad8fc04"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(arr) {\r\n const [min1, min2] = arr\r\n const max = arr.pop()\r\n console.log(min1, min2, max - min1 - min2)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}", "positive_code": [{"source_code": "// https://codeforces.com/contest/1618/problem/0\n\"use strict\";\n\nfunction answer(s) {\n const arr = s.split(' ');\n const maxSum = arr[arr.length - 1];\n const minA = arr[0];\n const minB = arr[1];\n const lastElement = maxSum - minA - minB;\n return [minA, minB, lastElement].join(' ');\n}\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const s = this.readline();\n this.print(answer(s))\n}\n"}, {"source_code": "t = readline();\r\n\r\nwhile(t--) {\r\n var input = readline().split(\" \");\r\n var max = Math.max.apply(null, input);\r\n print(input[0] + ' ' + input[1] + ' ' + (max - input[0] - input[1]));\r\n}"}, {"source_code": "\"use strict\";\n\nfunction answer(s) {\n if (s.length > 10) return s[0] + (s.length - 2) + s[s.length - 1];\n return s;\n}\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const s = this.readline().split(\" \");\n s.sort((a, b) => a - b);\n const todos = s[s.length - 1];\n const a = s[0];\n const b = s[1];\n const c = todos - a - b;\n this.print([a, b, c].join(\" \"));\n}\n"}, {"source_code": "\r\n'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n var x = readline();\r\n for (var i = 0; i < x; i++) {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n const a = num[0], b = num[1], c = num[num.length - 1] - a - b;\r\n console.log(`${a} ${b} ${c}`);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n var x = readline();\r\n for (var i = 0; i < x; i++) {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n \r\n console.log(d(num).join(' '));\r\n }\r\n}\r\nfunction d (ms) {\r\n var n = ms[ms.length - 1];\r\n var p = ms[0];\r\n for (var i = 1; ms.length > i; i++) {\r\n for (var j = i; ms.length > j; j++) {\r\n if (ms[j] + ms[i] === n - p) {\r\n return [p, ms[j], ms[i]]\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nlet c = 0;\r\n\r\nrl.on(\"line\", (array) => {\r\n c++;\r\n if(c == 1) return;\r\n [a, b, c, d, e, f, g] = array.split(\" \");\r\n\r\n let third = ((parseInt(c) == parseInt(a) + parseInt(b)) ? d : c);\r\n\r\n console.log(`${a} ${b} ${third}`);\r\n return;\r\n})"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet c = 0;\r\n\r\nrl.on(\"line\", (array) => {\r\n c++;\r\n if(c == 1) return;\r\n [a, b, c, d, e, f, g] = array.split(\" \");\r\n\r\n let third = ((parseInt(c) == parseInt(a) + parseInt(b)) ? d : c);\r\n\r\n console.log(`${a} ${b} ${third}`);\r\n return;\r\n});\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = new Array(3);\n a[0] = k[6] - k[5];\n a[2] = k[4] - a[0];\n a[1] = k[6] - a[0] - a[2];\n var s = '';\n for(j = 0; j < 3; j++){\n s += a[j] + ' ';\n }\n console.log(s);\n }\n});\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = new Array(3);\n a[0] = k[6] - k[5];\n a[2] = k[4] - a[0];\n a[1] = k[6] - a[0] - a[2];\n var s = '';\n for(j = 0; j < 3; j++){\n s += a[j] + ' ';\n }\n console.log(s);\n }\n});"}, {"source_code": "\r\n'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// FPT------Regional ^^ Let's go\r\n \r\n \r\nfunction main() {\r\n var x = readline();\r\n for (var i = 0; i < x; i++) {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n const a = num[0], b = num[1], c = num[num.length - 1] - a - b;\r\n console.log(`${a} ${b} ${c}`);\r\n }\r\n}\r\n"}, {"source_code": "\n// READLINE TEMPLATE\n//\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst print = console.log\n\n// READLINE TEMPLATE\n\nfunction findSum(arr,target) {\n const l1 = arr.length\n const l2 = l1 - 1\n for (let i = 0; i < l2; i++) {\n const a = arr[i]\n if (a > target) break\n const diff = target - a\n for (let j = i + 1; j < l1; j++) {\n const b = arr[j]\n if (b === diff) return [a,b]\n if (b > diff) break\n }\n }\n}\n\nfunction findOriginal(data) {\n const sorted = data.sort((a,b) => a-b)\n const a = sorted.shift()\n const a_b_c = sorted.pop()\n const b_c = a_b_c - a\n const [b,c] = findSum(sorted,b_c)\n return [a,b,c]\n}\n\nfunction main() {\n const n = parseInt(readline()) \n for (let i = 0; i < n; i++) {\n const a = readline().split(\" \").map(n => parseInt(n))\n print(...findOriginal(a))\n }\n}\n\n\n\n\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst b = rna();\r\n\t\tx = b[0];\r\n\t\ty = b[1];\r\n\t\tz = b[6] - x - y;\r\n\r\n\t\tconsole.log(x, y, z);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let noOfTestCases = Number(readline());\r\n let testCaseArray = [];\r\n for (let i = 0; i < noOfTestCases; i++) {\r\n testCaseArray.push(readline().split(\" \").map(x => Number(x)));\r\n }\r\n \r\n for (let i = 0; i < noOfTestCases; i++) {\r\n findLostArray(testCaseArray[i])\r\n }\r\n}\r\n\r\n\r\n\r\nfunction findLostArray(B) {\r\n console.log(B[0], B[1], B[6] - B[0] - B[1])\r\n}\r\n\r\n\r\n"}, {"source_code": " // your code goes here\r\n const fs = require('fs');\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n var T = readline();\r\n for(var q = 1;q<=T;q++) {\r\n var a = readline().split(\" \").map(x => parseInt(x));\r\n var f = []\r\n var dist = []\r\n for(var i=0;i {\r\n if (n == null) {\r\n n = parseInt(line)\r\n m = n\r\n } else if (m>0) {\r\n m--;\r\n a.push(line.split(' ').map(e=>parseInt(e)))\r\n } \r\n if (m == 0) {\r\n readline.close();\r\n main();\r\n } \r\n});\r\n\r\nfunction main(){\r\n a.forEach(e=> {\r\n let x = e.pop();\r\n for (let i = 0; i < e.length-2; i++)\r\n for (let j = i+1; j < e.length-1; j++)\r\n for (let k = j+1; k < e.length; k++)\r\n if (e[i]+e[j]+e[k] == x) {\r\n return console.log([e[i],e[j],e[k]].join(\" \"));\r\n }\r\n });\r\n}\r\n// main();"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n return `${arr[0]} ${arr[1]} ${arr[6]-arr[0]-arr[1]}`;\r\n}\r\n"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let arr;\r\n\r\n while (T--) {\r\n arr = lines[index++].split(' ').map(Number);\r\n solve(arr);\r\n }\r\n}\r\n\r\nfunction solve(arr) {\r\n arr.sort((a, b) => a - b);\r\n console.log(`${arr[0]} ${arr[1]} ${arr[6] - arr[1] - arr[0]}`);\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.nums();\n\t\tlet x = a[0];\n\t\tlet y = a[1];\n\t\tlet z = a[6] - x - y;\n\t\tans.push(`${x} ${y} ${z}`);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var t = parseInt(readline())\r\n\r\n while (t--) {\r\n var input2 = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n\r\n var max = Math.max(...input2)\r\n\r\n var a1 = 0;\r\n var a2 = 0;\r\n var a3 = 0;\r\n\r\n for (var i = 0; i < input2.length - 2; i++) {\r\n for (var j = i + 1; j < input2.length - 1; j++) {\r\n for (var k = j + 1; k < input2.length; k++) {\r\n if (input2[i] + input2[j] + input2[k] === max) {\r\n a1 = input2[i]\r\n a2 = input2[j]\r\n a3 = input2[k]\r\n }\r\n }\r\n }\r\n }\r\n print(a1 + \" \" + a2 + \" \" + a3)\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar list = nextIntArray(7);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\t\r\n\t\tvar min1 = list[0];\r\n\t\tvar min2 = list[1];\r\n\t\tvar max = list[6] - min1 - min2;\r\n\t\tmyout(min1 + \" \" + min2 + \" \" + max);\r\n\t}\r\n}\r\n"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var inputData = readline().split(' ');\r\n var result=[];\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-2]) );\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-3]) );\r\nresult.push(+inputData[inputData.length-1] - (result[0]+result[1]));\r\nprint(result.join(' '));\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var a = readline().split(' ').map(x=>parseInt(x));\r\n var ans = [a[0], a[1], a[6]-(a[0]+a[1])];\r\n print(ans.join(' '));\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n var x = readline();\r\n for (var i = 0; i < x; i++) {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n \r\n console.log(d(num));\r\n }\r\n}\r\nfunction d (ms) {\r\n var n = ms[ms.length - 1];\r\n var p = ms[0];\r\n for (var i = 1; ms.length > i; i++) {\r\n for (var j = i; ms.length > j; j++) {\r\n if (ms[j] + ms[i] === n - p) {\r\n return [p, ms[j], ms[i]]\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = readline();\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n \r\n console.log(d(num));\r\n}\r\nfunction d (ms) {\r\nvar n = ms[ms.length - 1];\r\nvar p = ms[0];\r\n for (var i = 1; ms.length > i; i++) {\r\n for (var j = i; ms.length > j; j++) {\r\n if (ms[j] + ms[i] === n - p) {\r\n return [p, ms[j], ms[i]]\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n console.log(num)\r\n const ans = d(num);\r\n console.log(ans);\r\n}\r\nfunction d (ms) {\r\nvar n = ms[ms.length - 1];\r\nvar p = ms[0];\r\n for (var i = 1; ms.length > i; i++) {\r\n for (var j = i; ms.length > j; j++) {\r\n if (ms[j] + ms[i] === n - p) {\r\n return [p, ms[j], ms[i]]\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n \r\n console.log(d(num));\r\n}\r\nfunction d (ms) {\r\nvar n = ms[ms.length - 1];\r\nvar p = ms[0];\r\n for (var i = 1; ms.length > i; i++) {\r\n for (var j = i; ms.length > j; j++) {\r\n if (ms[j] + ms[i] === n - p) {\r\n return [p, ms[j], ms[i]]\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: true\r\n});\r\n\r\nlet c = 0;\r\n\r\nrl.on(\"line\", (array) => {\r\n c++;\r\n if(c == 1) return;\r\n [a, b, c, d, e, f, g] = array.split(\" \");\r\n\r\n let third = ((parseInt(c) == parseInt(a) + parseInt(b)) ? d : c);\r\n\r\n console.log(`${a} ${b} ${third}`);\r\n return;\r\n});\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet c = 0;\r\n\r\nrl.on(\"line\", (array) => {\r\n c++;\r\n if(c == 1) return;\r\n [a, b, c, d, e, f, g] = array.split(\" \");\r\n\r\n let third = c == a + b ? d : c;\r\n\r\n console.log(`${a} ${b} ${third}`);\r\n return;\r\n});\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\n// const rd = readline.createInterface({\r\n// input: process.stdin,\r\n// output: process.stdout\r\n// })\r\n\r\nfunction solve() {\r\n rl.on(\"line\", (array) => {\r\n [a, b, c, d, e, f, g] = array.split(' ');\r\n\r\n let third = (c == a + b) ? d : c\r\n\r\n console.log(`${a} ${b} ${third}`)\r\n });\r\n}\r\n\r\nrl.question(\"\", (reps) => {\r\n while (reps--) {\r\n solve()\r\n }\r\n});\r\n"}, {"source_code": "\nfunction findSum(arr,target) {\n const l1 = arr.length\n const l2 = l1 - 1\n for (let i = 0; i < l2; i++) {\n const a = arr[i]\n if (a > target) break\n const diff = target - a\n for (let j = i + 1; j < l1; j++) {\n const b = arr[j]\n if (b === diff) return [a,b]\n if (b > diff) break\n }\n }\n}\n\nfunction findOriginal(data) {\n const sorted = data.sort((a,b) => a-b)\n const a = sorted.shift()\n const a_b_c = sorted.pop()\n const b_c = a_b_c - a\n const [b,c] = findSum(sorted,b_c)\n return [a,b,c]\n}\n\n/*\nconst n = parseInt(readline()) \nfor (let i = 0; i < n; i++) {\n const a = readline().split(\" \").map(n => parseInt(n))\n print(...findOriginal(a))\n}\n*/\n\n\n\n\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst b = rna();\r\n\t\tconsole.log(...b.slice(0, 3));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let noOfTestCases = Number(readline());\r\n let testCaseArray = [];\r\n for (let i = 0; i < noOfTestCases; i++) {\r\n testCaseArray.push(readline().split(\" \").map(x => Number(x)));\r\n }\r\n \r\n for (let i = 0; i < noOfTestCases; i++) {\r\n findLostArray(testCaseArray[i])\r\n }\r\n}\r\n\r\n\r\n\r\nfunction findLostArray(B) {\r\n console.log(B[0], B[0], B[6] - B[0] - B[1])\r\n}\r\n\r\n\r\n"}, {"source_code": "// your code goes here\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q = 1;q<=T;q++) {\r\n var a = readline().split(\" \").map(x => parseInt(x));\r\n var f = []\r\n var dist = []\r\n for(var i=0;i {\r\n if (n == null) {\r\n n = parseInt(line)\r\n m = n\r\n } else if (m>0) {\r\n m--;\r\n a.push(line.split(' ').map(e=>parseInt(e)))\r\n } \r\n if (m == 0) {\r\n readline.close();\r\n main();\r\n } \r\n});\r\n\r\nfunction main(){\r\n a.forEach(e=> {\r\n let x = e.pop();\r\n for (let i = 0; i < e.length-2; i++)\r\n for (let j = i+1; j < e.length-1; j++)\r\n for (let k = j+1; k < e.length; k++)\r\n if (e[i]+e[j]+e[k] == x) {\r\n return console.log([e[i],e[j],e[k]]);\r\n }\r\n });\r\n}\r\n// main();"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var inputData = readline().split(' ');\r\n var result=[];\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-2]) );\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-3]) );\r\nresult.push(+inputData[inputData.length-1] - (result[0]+result[1]));\r\nprint(result.join(','));\r\n}\r\n"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var inputData = readline().split(' ');\r\n var result=[];\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-2]) );\r\nresult.push(+inputData[inputData.length-1] -(+inputData[inputData.length-3]) );\r\nresult.push(+inputData[inputData.length-1] - (result[0]+result[1]));\r\nprint(result);\r\n}\r\n"}], "src_uid": "e0ec0cd81d2ec632ef89d207d80fa8a3"} {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var n = +inputs[0];\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n console.log((n - 1) / 2 | 0);\n var minArr = arr.slice(0, n / 2 | 0);\n var maxArr = arr.slice(n / 2 | 0);\n var c = [];\n for (let i = 0; i < n; i++) {\n if (i % 2 == 0)\n c.push(maxArr[i / 2 | 0]);\n else\n c.push(minArr[i / 2 | 0]);\n }\n console.log(c.join(' '));\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n\n for (let i = 0; i < len - 1; i++) {\n if (i % 2 === 0) [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];\n }\n\n console.log(Math.floor((len - 1) / 2));\n console.log(arr.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let numbers = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n numbers = numbers.sort((a, b) => a - b);\n let nlen = numbers.length;\n\n let final = [];\n final[0] = numbers.pop();\n let finalnumber = numbers.pop();\n\n let arr1 = numbers.filter((el, i) => i < numbers.length / 2);\n let arr2 = numbers.filter((el, i) => i >= numbers.length / 2);\n arr2 = arr2.sort((a, b) => b - a);\n\n for (let i = 0; i < arr2.length; i++) {\n final.push(arr1[i]);\n final.push(arr2[i]);\n }\n if (arr1.length != arr2.length) final.push(arr1[arr1.length - 1]);\n +final.push(finalnumber);\n\n let count = 0;\n for (let i = 1; i < final.length - 1; i++) {\n if (final[i] < final[i - 1] && final[i] < final[i + 1]) count++;\n }\n\n console.log(count);\n console.log(final.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let input = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n input = input.sort((a, b) => b - a);\n let output = [];\n let len = input.length;\n let grkl = true;\n for (let i = 0; i < len; i++) {\n if (grkl) {\n output.push(input.shift());\n } else {\n output.push(input.pop());\n }\n grkl = !grkl;\n }\n\n let anzahl = parseInt(Math.ceil(len / 2 - 1).toString());\n\n console.log(anzahl);\n console.log(output.join(\" \"));\n}\n"}, {"source_code": "let readline=require('readline');\nlet rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nlet arr=[],n;\nrl.on('line',function(inp){\n arr.push(inp);\n let len=arr.length;\n if(len===1) n=parseInt(arr[0]);\n else{\n let a=arr[1].split(' ');\n for(let i=0;i {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let input = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n input = input.sort((a, b) => b - a);\n let output = [];\n let len = input.length;\n let grkl = true;\n for (let i = 0; i < len; i++) {\n if (grkl) {\n output.push(input.pop());\n } else {\n output.push(input.shift());\n }\n grkl = !grkl;\n }\n\n let anzahl = parseInt(Math.ceil(len / 2 - 1).toString());\n\n console.log(anzahl);\n console.log(output.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let numbers = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n numbers = numbers.sort((a, b) => b - a);\n let final = [];\n for (let i = 0; i < Math.floor(numbers.length / 3); i++) {\n final.push(numbers[3 * i]);\n final.push(numbers[3 * i + 2]);\n final.push(numbers[3 * i + 1]);\n }\n numbers = numbers.sort();\n\n let finallen = final.length;\n for (let i = 0; i < numbers.length - finallen; i++) {\n final.push(numbers[i]);\n }\n\n let count = 0;\n for (let i = 1; i < final.length - 1; i++) {\n if (final[i] < final[i - 1] && final[i] < final[i + 1]) count++;\n }\n\n console.log(count);\n console.log(final.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let input = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n input = input.sort((a, b) => b - a);\n let output = [];\n let len = input.length;\n let grkl = \"gross\";\n for (let i = 0; i < len; i++) {\n if (grkl == \"gross\") {\n let gr = Math.max(...input);\n output.push(gr);\n input = input.filter((el) => el != gr);\n grkl = \"klein\";\n } else if (grkl == \"klein\") {\n let kl = Math.min(...input);\n output.push(kl);\n input = input.filter((el) => el != kl);\n grkl = \"gross\";\n }\n }\n\n let anzahl = Math.ceil(len / 2 - 1);\n\n console.log(anzahl);\n console.log(output);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let numbers = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n numbers = numbers.sort();\n let nlen = numbers.length;\n\n let final = [];\n final[0] = numbers.pop();\n let finalnumber = numbers.pop();\n\n let arr1 = numbers.filter((el, i) => i < numbers.length / 2);\n let arr2 = numbers.filter((el, i) => i > numbers.length / 2);\n arr2 = arr2.sort((a, b) => b - a);\n\n for (let i = 0; i < arr2.length; i++) {\n final.push(arr1[i]);\n final.push(arr2[i]);\n }\n if (arr1.length != arr2.length) final.push(arr1[arr1.length - 1]);\n +final.push(finalnumber);\n\n let count = 0;\n for (let i = 1; i < final.length - 1; i++) {\n if (final[i] < final[i - 1] && final[i] < final[i + 1]) count++;\n }\n\n console.log(count);\n console.log(final.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let n = parseInt(readLine());\n\n let input = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n input = input.sort((a, b) => b - a);\n let output = [];\n let len = input.length;\n let grkl = \"gross\";\n for (let i = 0; i < len; i++) {\n if (grkl == \"gross\") {\n let gr = Math.max(...input);\n output.push(gr);\n input = input.filter((el) => el != gr);\n grkl = \"klein\";\n } else if (grkl == \"klein\") {\n let kl = Math.min(...input);\n output.push(kl);\n input = input.filter((el) => el != kl);\n grkl = \"gross\";\n }\n }\n\n let anzahl = Math.ceil(len / 2 - 1);\n\n console.log(anzahl);\n console.log(output.join(\" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n let len = parseInt(readLine());\n\n let input = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n /////////////////////////////////////////////\n\n input.sort();\n\n let output = [];\n let grkl = true;\n let l = input.length;\n for (let i = 0; i < l; i++) {\n if (grkl) output.push(input.pop());\n else output.push(input.shift());\n grkl = !grkl;\n }\n\n let n = Math.ceil(output.length / 2) - 1;\n console.log(n);\n console.log(output.join(\" \"));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n\n for (let i = 0; i < len - 1; i++) {\n if (i % 2 === 0) [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];\n }\n\n console.log(len - 3);\n console.log(arr.join(\" \"));\n}\n"}], "src_uid": "bcd9439fbf6aedf6882612d5f7d6220f"} {"source_code": "print(function(n, a, s) {\n\n\tvar i, b = [];\n\tfor (i = 0; i < n; i++)\n\t\tb[i] = a[i];\n\n\tvar sum = 0;\n\tfor (i = n - 1; i >= 0; i--)\n\t\tb[i] = s[i] === '1' ? sum += b[i] : sum;\n\n\tfor (i = 1; i < n; i++)\n\t\ta[i] += a[i - 1];\n\n\tvar ans = b[0];\n\tb.push(0);\n\ta[-1] = 0;\n\tvar x = s.lastIndexOf('1');\n\tfor (i = 0; i < n; i++)\n\t\tif (s[i] === '1')\n\t\t\tans = Math.max(ans, a[i - 1] + b[i + 1]);\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), readline()));", "positive_code": [{"source_code": "print(function(n, a, s) {\n\tvar i,\n\t\tp = new Int32Array(n + 5),\n\t\tq = new Int32Array(n + 5);\n\n\tfor (i = 1; i <= n; i++)\n\t\tp[i] = p[i - 1] + a[i - 1];\n\n\tfor (i = n - 1; i >= 0; i--)\n\t\tif (s[i] === '1')\n\t\t\tq[i] = q[i + 1] + a[i];\n\t\telse\n\t\t\tq[i] = q[i + 1];\n\n\n\tvar ans = q[0];\n\tfor (i = 0; i < n; i++)\n\t\tif (s[i] === '1')\n\t\t\tans = Math.max(ans, p[i] + q[i + 1]);\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), readline()));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10);\n\tvar items = tokenizeIntegers(readline());\n\tvar bitmask = readline();\n\n\tvar sum = 0, remainder = 0;\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tif (bitmask.charAt(itemIndex) == '0') {\n\t\t\tremainder += items[itemIndex];\n\t\t}\n\t\telse {\n\t\t\tsum += items[itemIndex];\n\t\t}\n\t}\n\n\tvar best = sum;\n\n\tfor (var position = numItems-1; position >= 0; --position) {\n\t\tif (bitmask.charAt(position) == '0') {\n\t\t\tremainder -= items[position];\n\t\t}\n\t\telse {\n\t\t\tbest = Math.max(best, sum - items[position] + remainder);\n\t\t}\n\t}\n\n\tprint(best);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(n, a, s) {\n\n\tvar i, b = [];\n\tfor (i = 0; i < n; i++)\n\t\tb[i] = a[i];\n\n\tvar sum = 0;\n\tfor (i = n - 1; i >= 0; i--)\n\t\tb[i] = s[i] === '1' ? sum = b[i] : sum;\n\n\tfor (i = 1; i < n; i++)\n\t\ta[i] += a[i - 1];\n\n\tvar ans = b[0];\n\tb.push(0);\n\ta[-1] = 0;\n\tvar x = s.lastIndexOf('1');\n\tfor (i = 0; i <= x; i++)\n\t\tans = Math.max(ans, a[i - 1] + b[i + 1]);\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), readline()));"}, {"source_code": "print(function(n, a, s) {\n\n\tvar i, b = [];\n\tfor (i = 0; i < n; i++)\n\t\tb[i] = a[i];\n\n\tvar sum = 0;\n\tfor (i = n - 1; i >= 0; i--)\n\t\tb[i] = s[i] === '1' ? sum = b[i] : sum;\n\n\tfor (i = 1; i < n; i++)\n\t\ta[i] += a[i - 1];\n\n\tvar ans = 0;\n\tb.push(0);\n\ta[-1] = 0;\n\tvar x = s.lastIndexOf('1');\n\tfor (i = 0; i <= x; i++)\n\t\tans = Math.max(ans, a[i - 1] + b[i + 1]);\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), readline()));\n"}, {"source_code": "print(function(n, a, s) {\n\n\tvar i, b = [];\n\tfor (i = 0; i < n; i++)\n\t\tb[i] = a[i];\n\n\tvar sum = 0;\n\tfor (i = n - 1; i >= 0; i--)\n\t\tb[i] = s[i] === '1' ? sum += b[i] : sum;\n\n\tfor (i = 1; i < n; i++)\n\t\ta[i] += a[i - 1];\n\n\tvar ans = b[0];\n\tb.push(0);\n\ta[-1] = 0;\n\tvar x = s.lastIndexOf('1');\n\tfor (i = 0; i <= x; i++)\n\t\tans = Math.max(ans, a[i - 1] + b[i + 1]);\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), readline()));"}, {"source_code": "print(function(n, a, s) {\n\n\tvar v1 = a.reduce(function(sum, v, i) {\n\t\treturn s[i] === '1' ? sum + v : sum;\n\t});\n\n\tvar x = s.lastIndexOf('1');\n\tvar v2 = 0;\n\tfor (var i = 0; i < x; i++)\n\t\tv2 += a[i];\n\n\treturn Math.max(v1, v2);\n\n}(+readline(), readline().split(' ').map(Number), readline()));"}], "src_uid": "9366e1626b33b4f4e49cf35200c0448f"} {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar f = parseInt(arr[1]);\nvar k = [];\nvar l = [];\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline().split(' ');\n k.push(parseInt(arr[0]));\n l.push(parseInt(arr[1]));\n}\nvar b = [];\nvar sum = 0;\nfor (var i = 0; i < n; i ++)\n{\n sum += Math.min(k[i], l[i]);\n b.push(Math.min(k[i]*2, l[i]) - Math.min(k[i], l[i]));\n}\nb.sort(function(a,b){return b-a;});\nfor (var i = 0; i < f; i ++)\n{\n sum += b[i];\n}\nprint(sum);\n", "positive_code": [{"source_code": "\n var bigInt=function(undefined){\"use strict\";var BASE=1e7,LOG_BASE=7,MAX_INT=9007199254740992,MAX_INT_ARR=smallToArray(MAX_INT),LOG_MAX_INT=Math.log(MAX_INT);function Integer(v,radix){if(typeof v===\"undefined\")return Integer[0];if(typeof radix!==\"undefined\")return+radix===10?parseValue(v):parseBase(v,radix);return parseValue(v)}function BigInteger(value,sign){this.value=value;this.sign=sign;this.isSmall=false}BigInteger.prototype=Object.create(Integer.prototype);function SmallInteger(value){this.value=value;this.sign=value<0;this.isSmall=true}SmallInteger.prototype=Object.create(Integer.prototype);function isPrecise(n){return-MAX_INT0)return Math.floor(n);return Math.ceil(n)}function add(a,b){var l_a=a.length,l_b=b.length,r=new Array(l_a),carry=0,base=BASE,sum,i;for(i=0;i=base?1:0;r[i]=sum-carry*base}while(i0)r.push(carry);return r}function addAny(a,b){if(a.length>=b.length)return add(a,b);return add(b,a)}function addSmall(a,carry){var l=a.length,r=new Array(l),base=BASE,sum,i;for(i=0;i0){r[i++]=carry%base;carry=Math.floor(carry/base)}return r}BigInteger.prototype.add=function(v){var n=parseValue(v);if(this.sign!==n.sign){return this.subtract(n.negate())}var a=this.value,b=n.value;if(n.isSmall){return new BigInteger(addSmall(a,Math.abs(b)),this.sign)}return new BigInteger(addAny(a,b),this.sign)};BigInteger.prototype.plus=BigInteger.prototype.add;SmallInteger.prototype.add=function(v){var n=parseValue(v);var a=this.value;if(a<0!==n.sign){return this.subtract(n.negate())}var b=n.value;if(n.isSmall){if(isPrecise(a+b))return new SmallInteger(a+b);b=smallToArray(Math.abs(b))}return new BigInteger(addSmall(b,Math.abs(a)),a<0)};SmallInteger.prototype.plus=SmallInteger.prototype.add;function subtract(a,b){var a_l=a.length,b_l=b.length,r=new Array(a_l),borrow=0,base=BASE,i,difference;for(i=0;i=0){value=subtract(a,b)}else{value=subtract(b,a);sign=!sign}value=arrayToSmall(value);if(typeof value===\"number\"){if(sign)value=-value;return new SmallInteger(value)}return new BigInteger(value,sign)}function subtractSmall(a,b,sign){var l=a.length,r=new Array(l),carry=-b,base=BASE,i,difference;for(i=0;i=0)};SmallInteger.prototype.minus=SmallInteger.prototype.subtract;BigInteger.prototype.negate=function(){return new BigInteger(this.value,!this.sign)};SmallInteger.prototype.negate=function(){var sign=this.sign;var small=new SmallInteger(-this.value);small.sign=!sign;return small};BigInteger.prototype.abs=function(){return new BigInteger(this.value,false)};SmallInteger.prototype.abs=function(){return new SmallInteger(Math.abs(this.value))};function multiplyLong(a,b){var a_l=a.length,b_l=b.length,l=a_l+b_l,r=createArray(l),base=BASE,product,carry,i,a_i,b_j;for(i=0;i0){r[i++]=carry%base;carry=Math.floor(carry/base)}return r}function shiftLeft(x,n){var r=[];while(n-->0)r.push(0);return r.concat(x)}function multiplyKaratsuba(x,y){var n=Math.max(x.length,y.length);if(n<=30)return multiplyLong(x,y);n=Math.ceil(n/2);var b=x.slice(n),a=x.slice(0,n),d=y.slice(n),c=y.slice(0,n);var ac=multiplyKaratsuba(a,c),bd=multiplyKaratsuba(b,d),abcd=multiplyKaratsuba(addAny(a,b),addAny(c,d));var product=addAny(addAny(ac,shiftLeft(subtract(subtract(abcd,ac),bd),n)),shiftLeft(bd,2*n));trim(product);return product}function useKaratsuba(l1,l2){return-.012*l1-.012*l2+15e-6*l1*l2>0}BigInteger.prototype.multiply=function(v){var n=parseValue(v),a=this.value,b=n.value,sign=this.sign!==n.sign,abs;if(n.isSmall){if(b===0)return Integer[0];if(b===1)return this;if(b===-1)return this.negate();abs=Math.abs(b);if(abs=0;shift--){quotientDigit=base-1;if(remainder[shift+b_l]!==divisorMostSignificantDigit){quotientDigit=Math.floor((remainder[shift+b_l]*base+remainder[shift+b_l-1])/divisorMostSignificantDigit)}carry=0;borrow=0;l=divisor.length;for(i=0;ib_l){highx=(highx+1)*base}guess=Math.ceil(highx/highy);do{check=multiplySmall(b,guess);if(compareAbs(check,part)<=0)break;guess--}while(guess);result.push(guess);part=subtract(part,check)}result.reverse();return[arrayToSmall(result),arrayToSmall(part)]}function divModSmall(value,lambda){var length=value.length,quotient=createArray(length),base=BASE,i,q,remainder,divisor;remainder=0;for(i=length-1;i>=0;--i){divisor=remainder*base+value[i];q=truncate(divisor/lambda);remainder=divisor-q*lambda;quotient[i]=q|0}return[quotient,remainder|0]}function divModAny(self,v){var value,n=parseValue(v);var a=self.value,b=n.value;var quotient;if(b===0)throw new Error(\"Cannot divide by zero\");if(self.isSmall){if(n.isSmall){return[new SmallInteger(truncate(a/b)),new SmallInteger(a%b)]}return[Integer[0],self]}if(n.isSmall){if(b===1)return[self,Integer[0]];if(b==-1)return[self.negate(),Integer[0]];var abs=Math.abs(b);if(absb.length?1:-1}for(var i=a.length-1;i>=0;i--){if(a[i]!==b[i])return a[i]>b[i]?1:-1}return 0}BigInteger.prototype.compareAbs=function(v){var n=parseValue(v),a=this.value,b=n.value;if(n.isSmall)return 1;return compareAbs(a,b)};SmallInteger.prototype.compareAbs=function(v){var n=parseValue(v),a=Math.abs(this.value),b=n.value;if(n.isSmall){b=Math.abs(b);return a===b?0:a>b?1:-1}return-1};BigInteger.prototype.compare=function(v){if(v===Infinity){return-1}if(v===-Infinity){return 1}var n=parseValue(v),a=this.value,b=n.value;if(this.sign!==n.sign){return n.sign?1:-1}if(n.isSmall){return this.sign?-1:1}return compareAbs(a,b)*(this.sign?-1:1)};BigInteger.prototype.compareTo=BigInteger.prototype.compare;SmallInteger.prototype.compare=function(v){if(v===Infinity){return-1}if(v===-Infinity){return 1}var n=parseValue(v),a=this.value,b=n.value;if(n.isSmall){return a==b?0:a>b?1:-1}if(a<0!==n.sign){return a<0?-1:1}return a<0?1:-1};SmallInteger.prototype.compareTo=SmallInteger.prototype.compare;BigInteger.prototype.equals=function(v){return this.compare(v)===0};SmallInteger.prototype.eq=SmallInteger.prototype.equals=BigInteger.prototype.eq=BigInteger.prototype.equals;BigInteger.prototype.notEquals=function(v){return this.compare(v)!==0};SmallInteger.prototype.neq=SmallInteger.prototype.notEquals=BigInteger.prototype.neq=BigInteger.prototype.notEquals;BigInteger.prototype.greater=function(v){return this.compare(v)>0};SmallInteger.prototype.gt=SmallInteger.prototype.greater=BigInteger.prototype.gt=BigInteger.prototype.greater;BigInteger.prototype.lesser=function(v){return this.compare(v)<0};SmallInteger.prototype.lt=SmallInteger.prototype.lesser=BigInteger.prototype.lt=BigInteger.prototype.lesser;BigInteger.prototype.greaterOrEquals=function(v){return this.compare(v)>=0};SmallInteger.prototype.geq=SmallInteger.prototype.greaterOrEquals=BigInteger.prototype.geq=BigInteger.prototype.greaterOrEquals;BigInteger.prototype.lesserOrEquals=function(v){return this.compare(v)<=0};SmallInteger.prototype.leq=SmallInteger.prototype.lesserOrEquals=BigInteger.prototype.leq=BigInteger.prototype.lesserOrEquals;BigInteger.prototype.isEven=function(){return(this.value[0]&1)===0};SmallInteger.prototype.isEven=function(){return(this.value&1)===0};BigInteger.prototype.isOdd=function(){return(this.value[0]&1)===1};SmallInteger.prototype.isOdd=function(){return(this.value&1)===1};BigInteger.prototype.isPositive=function(){return!this.sign};SmallInteger.prototype.isPositive=function(){return this.value>0};BigInteger.prototype.isNegative=function(){return this.sign};SmallInteger.prototype.isNegative=function(){return this.value<0};BigInteger.prototype.isUnit=function(){return false};SmallInteger.prototype.isUnit=function(){return Math.abs(this.value)===1};BigInteger.prototype.isZero=function(){return false};SmallInteger.prototype.isZero=function(){return this.value===0};BigInteger.prototype.isDivisibleBy=function(v){var n=parseValue(v);var value=n.value;if(value===0)return false;if(value===1)return true;if(value===2)return this.isEven();return this.mod(n).equals(Integer[0])};SmallInteger.prototype.isDivisibleBy=BigInteger.prototype.isDivisibleBy;function isBasicPrime(v){var n=v.abs();if(n.isUnit())return false;if(n.equals(2)||n.equals(3)||n.equals(5))return true;if(n.isEven()||n.isDivisibleBy(3)||n.isDivisibleBy(5))return false;if(n.lesser(25))return true}BigInteger.prototype.isPrime=function(){var isPrime=isBasicPrime(this);if(isPrime!==undefined)return isPrime;var n=this.abs(),nPrev=n.prev();var a=[2,3,5,7,11,13,17,19],b=nPrev,d,t,i,x;while(b.isEven())b=b.divide(2);for(i=0;i-MAX_INT)return new SmallInteger(value-1);return new BigInteger(MAX_INT_ARR,true)};var powersOfTwo=[1];while(powersOfTwo[powersOfTwo.length-1]<=BASE)powersOfTwo.push(2*powersOfTwo[powersOfTwo.length-1]);var powers2Length=powersOfTwo.length,highestPower2=powersOfTwo[powers2Length-1];function shift_isSmall(n){return(typeof n===\"number\"||typeof n===\"string\")&&+Math.abs(n)<=BASE||n instanceof BigInteger&&n.value.length<=1}BigInteger.prototype.shiftLeft=function(n){if(!shift_isSmall(n)){throw new Error(String(n)+\" is too large for shifting.\")}n=+n;if(n<0)return this.shiftRight(-n);var result=this;while(n>=powers2Length){result=result.multiply(highestPower2);n-=powers2Length-1}return result.multiply(powersOfTwo[n])};SmallInteger.prototype.shiftLeft=BigInteger.prototype.shiftLeft;BigInteger.prototype.shiftRight=function(n){var remQuo;if(!shift_isSmall(n)){throw new Error(String(n)+\" is too large for shifting.\")}n=+n;if(n<0)return this.shiftLeft(-n);var result=this;while(n>=powers2Length){if(result.isZero())return result;remQuo=divModAny(result,highestPower2);result=remQuo[1].isNegative()?remQuo[0].prev():remQuo[0];n-=powers2Length-1}remQuo=divModAny(result,powersOfTwo[n]);return remQuo[1].isNegative()?remQuo[0].prev():remQuo[0]};SmallInteger.prototype.shiftRight=BigInteger.prototype.shiftRight;function bitwise(x,y,fn){y=parseValue(y);var xSign=x.isNegative(),ySign=y.isNegative();var xRem=xSign?x.not():x,yRem=ySign?y.not():y;var xBits=[],yBits=[];var xStop=false,yStop=false;while(!xStop||!yStop){if(xRem.isZero()){xStop=true;xBits.push(xSign?1:0)}else if(xSign)xBits.push(xRem.isEven()?1:0);else xBits.push(xRem.isEven()?0:1);if(yRem.isZero()){yStop=true;yBits.push(ySign?1:0)}else if(ySign)yBits.push(yRem.isEven()?1:0);else yBits.push(yRem.isEven()?0:1);xRem=xRem.over(2);yRem=yRem.over(2)}var result=[];for(var i=0;i=0;i--){var top=restricted?range.value[i]:BASE;var digit=truncate(Math.random()*top);result.unshift(digit);if(digit\");digits.push(parseValue(text.slice(start+1,i)))}else throw new Error(c+\" is not a valid character\")}return parseBaseFromArray(digits,base,isNegative)};function parseBaseFromArray(digits,base,isNegative){var val=Integer[0],pow=Integer[1],i;for(i=digits.length-1;i>=0;i--){val=val.add(digits[i].times(pow));pow=pow.times(base)}return isNegative?val.negate():val}function stringify(digit){var v=digit.value;if(typeof v===\"number\")v=[v];if(v.length===1&&v[0]<=35){return\"0123456789abcdefghijklmnopqrstuvwxyz\".charAt(v[0])}return\"<\"+v+\">\"}function toBase(n,base){base=bigInt(base);if(base.isZero()){if(n.isZero())return\"0\";throw new Error(\"Cannot convert nonzero numbers to base 0.\")}if(base.equals(-1)){if(n.isZero())return\"0\";if(n.isNegative())return new Array(1-n).join(\"10\");return\"1\"+new Array(+n).join(\"01\")}var minusSign=\"\";if(n.isNegative()&&base.isPositive()){minusSign=\"-\";n=n.abs()}if(base.equals(1)){if(n.isZero())return\"0\";return minusSign+new Array(+n+1).join(1)}var out=[];var left=n,divmod;while(left.isNegative()||left.compareAbs(base)>=0){divmod=left.divmod(base);left=divmod.quotient;var digit=divmod.remainder;if(digit.isNegative()){digit=base.minus(digit).abs();left=left.next()}out.push(stringify(digit))}out.push(stringify(left));return minusSign+out.reverse().join(\"\")}BigInteger.prototype.toString=function(radix){if(radix===undefined)radix=10;if(radix!==10)return toBase(this,radix);var v=this.value,l=v.length,str=String(v[--l]),zeros=\"0000000\",digit;while(--l>=0){digit=String(v[l]);str+=zeros.slice(digit.length)+digit}var sign=this.sign?\"-\":\"\";return sign+str};SmallInteger.prototype.toString=function(radix){if(radix===undefined)radix=10;if(radix!=10)return toBase(this,radix);return String(this.value)};BigInteger.prototype.valueOf=function(){return+this.toString()};BigInteger.prototype.toJSNumber=BigInteger.prototype.valueOf;SmallInteger.prototype.valueOf=function(){return this.value};SmallInteger.prototype.toJSNumber=SmallInteger.prototype.valueOf;function parseStringValue(v){if(isPrecise(+v)){var x=+v;if(x===truncate(x))return new SmallInteger(x);throw\"Invalid integer: \"+v}var sign=v[0]===\"-\";if(sign)v=v.slice(1);var split=v.split(/e/i);if(split.length>2)throw new Error(\"Invalid integer: \"+split.join(\"e\"));if(split.length===2){var exp=split[1];if(exp[0]===\"+\")exp=exp.slice(1);exp=+exp;if(exp!==truncate(exp)||!isPrecise(exp))throw new Error(\"Invalid integer: \"+exp+\" is not a valid exponent.\");var text=split[0];var decimalPlace=text.indexOf(\".\");if(decimalPlace>=0){exp-=text.length-decimalPlace-1;text=text.slice(0,decimalPlace)+text.slice(decimalPlace+1)}if(exp<0)throw new Error(\"Cannot include negative exponent part for integers\");text+=new Array(exp+1).join(\"0\");v=text}var isValid=/^([0-9][0-9]*)$/.test(v);if(!isValid)throw new Error(\"Invalid integer: \"+v);var r=[],max=v.length,l=LOG_BASE,min=max-l;while(max>0){r.push(+v.slice(min,max));min-=l;if(min<0)min=0;max-=l}trim(r);return new BigInteger(r,sign)}function parseNumberValue(v){if(isPrecise(v)){if(v!==truncate(v))throw new Error(v+\" is not an integer.\");return new SmallInteger(v)}return parseStringValue(v.toString())}function parseValue(v){if(typeof v===\"number\"){return parseNumberValue(v)}if(typeof v===\"string\"){return parseStringValue(v)}return v}for(var i=0;i<1e3;i++){Integer[i]=new SmallInteger(i);if(i>0)Integer[-i]=new SmallInteger(-i)}Integer.one=Integer[1];Integer.zero=Integer[0];Integer.minusOne=Integer[-1];Integer.max=max;Integer.min=min;Integer.gcd=gcd;Integer.lcm=lcm;Integer.isInstance=function(x){return x instanceof BigInteger||x instanceof SmallInteger};Integer.randBetween=randBetween;Integer.fromArray=function(digits,base,isNegative){return parseBaseFromArray(digits.map(parseValue),parseValue(base||10),isNegative)};return Integer}();\n \n var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var f = tmp[1];\n var d = [];\n var sum = bigInt();\n for(var i = 0; i < n; i += 1) {\n tmp = readline().split(' ').map(x => parseInt(x));\n d[i] = {\n k: tmp[0],\n l: tmp[1]\n };\n sum = sum.add(Math.min(d[i].k, d[i].l));\n }\n d.sort((b, a) => (Math.min(2 * a.k, a.l) - Math.min(a.k, a.l)) - (Math.min(2 * b.k, b.l) - Math.min(b.k, b.l)));\n for(var i = 0; i < f; i += 1) {\n sum = sum.add(Math.min(2 * d[i].k, d[i].l) - Math.min(d[i].k, d[i].l));\n }\n print(sum.toString());\n \n \n"}, {"source_code": "var readline = (function () {\n var lines = require(\"fs\")\n .readFileSync(0, \"utf-8\")\n .split(\"\\n\");\n var i = 0;\n return function () { return lines[i++]; };\n})();\nvar _a = readline()\n .split(\" \")\n .map(function (v) { return parseInt(v); }), n = _a[0], maxSellouts = _a[1];\nvar arr = [];\nfor (var i = 0; i < n; i++) {\n var line = readline().split(\" \");\n var products = parseInt(line[0]);\n var clients = parseInt(line[1]);\n arr.push({\n gain: Math.min(products, clients),\n doubleGain: Math.min(products * 2, clients)\n });\n}\nvar sorted = arr.sort(function (a, b) { return b.doubleGain - b.gain - (a.doubleGain - a.gain); });\nvar value = sorted.reduce(function (acc, _a, i) {\n var gain = _a.gain, doubleGain = _a.doubleGain;\n return acc + (i < maxSellouts ? doubleGain : gain);\n}, 0);\nconsole.log(value);\n"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]), f = Number(s[1]);\n\nvar profit = [];\nvar sum = 0;\nfor(var i=0; i b - a);\nfor(var i=0; i l) {\n sales.push(Math.max(l - k,0));\n }\n else {\n sales.push(k);\n }\n \n profit += Math.min(k,l);\n}\n\nsales.sort((a,b) => b-a);\nfor (var j = 0; j numberOfClients ? numberOfClients : numberOfProducts;\n var totalSalesPossible = Math.max(0, Math.min(numberOfProducts, numberOfClients - numberOfProducts));\n promotionalDays[i] = totalSalesPossible;\n}\n\n//quicksort(promotionalDays, 0, numberOfDays - 1);\npromotionalDays.sort((a, b) => b - a);\n\nfor (var i = 0; i < numberOfSaleDays; i++){\n numberOfSoldProducts += promotionalDays[i];\n}\n \nfor (var i = 0; i < numberOfDays; i++){\n numberOfSoldProducts += normalDays[i];\n}\n\nprint(numberOfSoldProducts);\n\nfunction quicksort(list, init, final){\n if (list.length > 1){\n var index = partition(list, init, final);\n if (init < index - 1)\n quicksort(list, init, index - 1);\n if (final > index)\n quicksort(list, index, final);\n }\n}\n\nfunction partition(list, init, final){\n var average = Math.floor((init + final)/2);\n var pivot = list[average];\n var i = init;\n var j = final;\n\n while (i < j){\n while (list[i] > pivot)\n i++;\n while (list[j] < pivot)\n j--;\n if (i < j){\n swap(list, i, j);\n i++;\n j--;\n }\n }\n return i;\n}\n\nfunction swap(list, firstIndex, secondIndex){\n var temp = list[firstIndex];\n list[firstIndex] = list[secondIndex];\n list[secondIndex] = temp;\n}"}], "negative_code": [{"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]), f = Number(s[1]);\n\nvar profit = [];\nvar sum = 0;\nfor(var i=0; i b - a);\nfor(var i=0; i numberOfClients ? numberOfClients : numberOfProducts;\n var totalSalesPossible = numberOfProducts * 2 > numberOfClients ? numberOfClients : numberOfProducts * 2;\n promotionalDays[i] = totalSalesPossible;\n}\n\nquicksort(promotionalDays, normalDays, 0, numberOfDays - 1);\n\nfor (var i = 0; i < numberOfSaleDays; i++){\n numberOfSoldProducts += promotionalDays[i];\n}\n \n\nfor (var i = numberOfSaleDays; i < numberOfDays; i++){\n numberOfSoldProducts += normalDays[i];\n}\n\nprint(numberOfSoldProducts);\n\nfunction quicksort(list1, list2, init, final){\n if (list1.length > 1){\n var index = partition(list1, list2, init, final);\n if (init < index -1)\n quicksort(list1, list2, init, index - 1);\n if (final > index)\n quicksort(list1, list2, index, final);\n }\n}\n\nfunction partition(list1, list2, init, final){\n var average = (init + final)/2;\n var pivot = list1[average];\n var i = init;\n var j = final;\n\n while (i < j){\n while (list1[i] > pivot)\n i++;\n while (list1[j] < pivot)\n j--;\n if (i < j){\n swap(list1, list2, i, j);\n i++;\n j--;\n }\n }\n return i;\n}\n\nfunction swap(list1, list2, firstIndex, secondIndex){\n var temp = list1[firstIndex];\n list1[firstIndex] = list1[secondIndex];\n list1[secondIndex] = temp;\n\n temp = list2[firstIndex];\n list2[firstIndex] = list2[secondIndex];\n list2[secondIndex] = temp;\n}"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar f = parseInt(arr[1]);\nvar k = [];\nvar l = [];\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline().split(' ');\n k.push(parseInt(arr[0]));\n l.push(parseInt(arr[1]));\n}\nvar b = [];\nvar sum = 0;\nfor (var i = 0; i < n; i ++)\n{\n sum += Math.min(k[i], l[i]);\n b.push(Math.max(Math.min(k[i]*2, l[i]) - k[i], 0));\n}\nb.sort();\nfor (var i = 0; i < f; i ++)\n{\n sum += b[n-i-1];\n}\nprint(sum);\n"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar f = parseInt(arr[1]);\nvar k = [];\nvar l = [];\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline().split(' ');\n k.push(parseInt(arr[0]));\n l.push(parseInt(arr[1]));\n}\nvar b = [];\nvar sum = 0;\nfor (var i = 0; i < n; i ++)\n{\n sum += Math.min(k[i], l[i]);\n b.push(Math.min(k[i]*2, l[i]) - Math.min(k[i], l[i]));\n}\nb=b.sort();\nfor (var i = 0; i < f; i ++)\n{\n sum += b[n-i-1];\n}\nprint(sum);\n"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar f = parseInt(arr[1]);\nvar k = [];\nvar l = [];\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline().split(' ');\n k.push(parseInt(arr[0]));\n l.push(parseInt(arr[1]));\n}\nvar b = [];\nvar sum = 0;\nfor (var i = 0; i < n; i ++)\n{\n sum += Math.min(k[i], l[i]);\n b.push(Math.min(k[i]*2, l[i]) - Math.min(k[i], l[i]));\n}\nb.sort();\nfor (var i = 0; i < f; i ++)\n{\n sum += b[n-i-1];\n}\nprint(sum);\n"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar f = parseInt(arr[1]);\nvar k = [];\nvar l = [];\nfor (var i = 0; i < n; i ++)\n{\n var arr = readline().split(' ');\n k.push(parseInt(arr[0]));\n l.push(parseInt(arr[1]));\n}\nvar b = [];\nvar sum = 0;\nfor (var i = 0; i < n; i ++)\n{\n sum += Math.min(k[i], l[i]);\n b.push(Math.min(k[i]*2, l[i]) - Math.min(k[i], l[i]));\n}\nb.sort();\nfor (var i = 0; i < f; i ++)\n{\n sum += b[n-i-1];\n}\nif (k[0]==9 && l[0]==10481002 && k[1]==3 && l[1]==268224257)\n{\n sum ++;\n}\nprint(sum);\n"}], "src_uid": "c9b322a9138410a82e541179272eb6bf"} {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n\r\n var t1 = readline();\r\n var t2 = readline();\r\n print(checkStr(t2));\r\n \r\n}\r\n \r\nfunction checkStr(str) {\r\n \r\n var set = new Set();\r\n var count = 0;\r\n for(var each of str){\r\n if (!set.has(each)){\r\n count+=2;\r\n }else {\r\n count+=1;\r\n }\r\n set.add(each);\r\n }\r\n return count; \r\n}", "positive_code": [{"source_code": "function Solution() {\n const N = Number(lines[0]);\n const res = [];\n for (let i = 1; i <= 2 * N; i += 2) {\n const n = Number(lines[i]);\n const str = lines[i + 1];\n res.push(new Set(str).size + n);\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "function Solution() {\n const N = Number(lines[0]);\n const res = [];\n for (let i = 1; i <= 2 * N; i += 2) {\n const n = Number(lines[i]);\n const str = lines[i + 1];\n const set = new Set();\n let count = 0;\n for (let i = 0; i < n; i++) {\n if (set.has(str[i])) {\n count += 1;\n } else {\n count += 2;\n set.add(str[i]);\n }\n }\n res.push(count);\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const visited = {};\n let ans = 0;\n\n for (let i = 0; i < str.length; i++) {\n if (visited[str[i]]) {\n ans++;\n } else {\n ans += 2;\n }\n\n visited[str[i]] = true;\n }\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n // const alphabet = \"abcdefghijklmnopqrstuvwxyz\".toUpperCase();\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n readLine()\r\n let str = readLine();\r\n let problems = {};\r\n let ans = 0;\r\n for (const pr of str) {\r\n if (problems[pr]) {\r\n ans++;\r\n } else {\r\n problems[pr] = true;\r\n ans += 2;\r\n }\r\n }\r\n\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet x = {};\n\t\tlet y = 0;\n\t\tnl.line().split('').forEach(e => \n\t\t{\n\t\t\tif (x[e]){\n\t\t\t\ty++;\n\t\t\t} else {\n\t\t\t\tx[e] = 1;\n\t\t\t\ty += 2;\n\t\t\t}\n\t\t});\n\t\tans.push(y);\n\t\t\n\t\t\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1) {\n n = lines[i];\n }else{\n var k = lines[i].split('');\n var a = new Map();\n var ans = 0;\n for(j = 0; j < n; j++){\n if(a.get(k[j]) === undefined){\n a.set(k[j], 1);\n ans += 2;\n }else{\n ans++;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n let n = parseInt(readline());\r\n let s = readline();\r\n let str = Array.from(s);\r\n let ans = 0;\r\n let hsh = Array(26).fill(false);\r\n\r\n for (let i = 0;i < s.length-1; ++i) {\r\n if (hsh[s.charCodeAt(i)-65]) {\r\n ans++;\r\n } else {\r\n hsh[s.charCodeAt(i)-65] = true;\r\n ans++;\r\n ans++;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n const map = {}\n for (let i = 0; i < str.length; i++) {\n map[str[i]] = 1\n }\n return str.length + Object.keys(map).length\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n let t = readline()-0\r\n while(t--){\r\n let n = readline()\r\n let str = readline()\r\n let s = new Set()\r\n let res = 0\r\n for(let i=0;i {\n if (lineNum === 0) {\n // skip\n } else {\n if (lineNum % 2 === 0) {\n map.clear();\n for (let char of line) {\n map.set(char, (map.get(char) || 0) + 1);\n }\n let cnt = 0;\n for (let c of map.values()) {\n cnt += c + 1;\n }\n console.log(cnt);\n }\n }\n\n lineNum++;\n});\n"}, {"source_code": "// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\nconst state = {\r\n i: 0,\r\n acc: []\r\n}\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nrl.on('line',\r\n function (line) {\r\n const alphabet = {\r\n A: 0,\r\n B: 0,\r\n C: 0,\r\n D: 0,\r\n E: 0,\r\n F: 0,\r\n G: 0,\r\n H: 0,\r\n I: 0,\r\n J: 0,\r\n K: 0,\r\n L: 0,\r\n M: 0,\r\n N: 0,\r\n O: 0,\r\n P: 0,\r\n Q: 0,\r\n R: 0,\r\n S: 0,\r\n T: 0,\r\n U: 0,\r\n V: 0,\r\n W: 0,\r\n X: 0,\r\n Y: 0,\r\n Z: 0\r\n }\r\n if (state.i > 0) {\r\n state.acc.push(line)\r\n if (state.acc.length == 2) {\r\n // \r\n let sum = 0\r\n let [t, n] = state.acc\r\n for (let i = 0; i < n.length; i++) {\r\n let current = n[i]\r\n if (alphabet[current] == 0) {\r\n sum++\r\n alphabet[current]++\r\n }\r\n sum++\r\n }\r\n console.log(sum)\r\n // \r\n state.acc = []\r\n }\r\n\r\n }\r\n state.i++\r\n })\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n\r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n for (let i = 1; i <= lines[0]; i++) {\r\n processTC(lines, (2*i-1));\r\n }\r\n}\r\n\r\nfunction processTC(lines, startLine) {\r\n const n = Number(lines[startLine]);\r\n const str = lines[startLine+1];\r\n checkSolved(str, n);\r\n}\r\n\r\nfunction checkSolved(str, n) {\r\n let map = {};\r\n let count = 0;\r\n for (let i = 0; i < n; i++) {\r\n const char = str.charAt(i);\r\n if (!map[char]) map[char]=0;\r\n map[char]++;\r\n if (map[char] === 1) count++;\r\n count++;\r\n }\r\n console.log(count);\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n // var nul = readline();\r\n var a = readline()\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var ans = 0;\r\n var f = Alph();\r\n var mp = new Map();\r\n for(var i=0;i {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim();\r\n let obj = {},\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) sum++;\r\n else {\r\n obj[arr[i]] = 1;\r\n sum += 2;\r\n }\r\n }\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let times = parseInt(readline());\r\n for (let i = 0; i < times; i++) {\r\n let len = parseInt(readline());\r\n let distinct = new Set(readline().split(''));\r\n console.log(distinct.size + len);\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = next();\r\n\t\tvar output = 0;\r\n\t\tvar set = new Set();\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput++;\r\n\t\t\tif(!set.has(S[i])){\r\n\t\t\t\toutput++;\r\n\t\t\t\tset.add(S[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let seen = {};\r\n let total = 0;\r\n readline();\r\n let solved = readline();\r\n for (let i = 0; i < solved.length; i++) {\r\n let c = solved[i];\r\n if (seen[c]) {\r\n total += 1;\r\n } else {\r\n seen[c] = true;\r\n total += 2;\r\n }\r\n }\r\n output(total);\r\n }\r\n}"}, {"source_code": "function getBalloons(numbers) {\r\n var balloons = [];\r\n for (var element of numbers) {\r\n if (balloons.indexOf(element) == -1) {\r\n balloons.push(element);\r\n }\r\n\r\n }\r\n return balloons.length;\r\n\r\n}\r\nvar test = readline();\r\nfor (var i = 1; i <= test; i++) {\r\n var n = readline();\r\n var numbers = readline().split('');\r\n print(parseInt(n) + getBalloons(numbers));\r\n}"}, {"source_code": "var test = readline();\r\nfor (var i = 1; i <= test; i++) {\r\n var n = readline();\r\n var numbers = readline().split('');\r\n var balloons = [];\r\n for (var element of numbers) {\r\n if (balloons.indexOf(element) == -1) {\r\n balloons.push(element);\r\n }\r\n\r\n }\r\n //var result = getBalloons(numbers) + parseInt(n);\r\n\r\n print(parseInt(n) + balloons.length);\r\n}"}, {"source_code": "var test = readline()\r\nfor(var i=0; i {\r\n set.add(el)\r\n })\r\n\r\n ans = set.size + str.length\r\n print(ans)\r\n}"}, {"source_code": "\r\nprocess.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount * 2; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n console.log(getScore(test.trim()));\r\n }\r\n});\r\n\r\nfunction getScore(input) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < input.length; i++) {\r\n const char = input[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n return score;\r\n}\r\n"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0, biggest = 0, g = 0, a = new Map()\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n g = 0\n a = new Map()\n var k = lines[j].split('')\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n temp = a.get(k[l])\n temp++\n \n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n g++\n }\n }\n \n for(var [key, value] of a){\n g+=value\n }\n console.log(g)\n\n }\n }\n \n \n}); \n\n"}], "negative_code": [{"source_code": "\r\nprocess.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount * 2; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n console.log(getScore(test));\r\n }\r\n});\r\n\r\nfunction getScore(input) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < input.length; i++) {\r\n const char = input[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n return score;\r\n}"}, {"source_code": "\r\nprocess.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount * 2; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length - 1; i++) {\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});\r\n"}, {"source_code": "\r\nprocess.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n console.log(\"tests:\", tests);\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length - 1; i++) {\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length - 1; i++) {\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length - 1; i++) {\r\n console.log(\"Test:\", test, \"i:\", i, \"solved:\", solved, \"score:\", score);\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length; i++) {\r\n console.log(\"Test:\", test, \"i:\", i, \"solved:\", solved, \"score:\", score);\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n let solved = \"\";\r\n let score = 0;\r\n for (let i = 0; i < test.length; i++) {\r\n const char = test[i];\r\n if (solved.includes(char)) {\r\n score += 1;\r\n } else {\r\n solved += char;\r\n score += 2;\r\n }\r\n }\r\n console.log(score);\r\n }\r\n});"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const [testCount, ...testCases] = data.toString().trim().split(\"\\n\");\r\n\r\n const tests = [];\r\n for (let i = 1; i < testCount; i += 2) {\r\n tests.push(testCases[i]);\r\n }\r\n\r\n for (let test of tests) {\r\n console.log(test);\r\n }\r\n});"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0, biggest = 0, g = 0, a = new Map()\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n g = 0\n var k = lines[j].split('')\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n temp = a.get(k[l])\n temp++\n \n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n g++\n }\n }\n \n for(var [key, value] of a){\n g+=value\n }\n console.log(g)\n\n }\n }\n \n \n}); \n\n"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0, biggest = 0, g = 0, a = new Map()\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split('').map(String)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n temp = a.get(k[l])\n temp++\n if(temp == 2){\n g++\n }\n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n }\n }\n \n for(var [key, value] of a){\n g++\n }\n }\n console.log(g)\n }\n \n \n}); \n\n"}, {"source_code": "\r\n/*\r\nfunction getBalloons(numbers) {\r\n var balloons = [];\r\n for (const element of numbers) {\r\n if (balloons.indexOf(element) == -1) {\r\n balloons.push(element);\r\n }\r\n\r\n }\r\n return balloons.length;\r\n\r\n}*/\r\nvar test = readline();\r\nfor (var i = 1; i <= test; i++) {\r\n var n = readline();\r\n var numbers = readline().split('');\r\n var balloons = [];\r\n for (const element of numbers) {\r\n if (balloons.indexOf(element) == -1) {\r\n balloons.push(element);\r\n }\r\n\r\n }\r\n //var result = getBalloons(numbers) + parseInt(n);\r\n\r\n print(parseInt(n) + balloons.length);\r\n}\r\n"}, {"source_code": " var t = readline()\r\n for (var i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var s = new Array(n + 1).fill(0)\r\n\r\n //\r\n // var count = {}\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var res = []\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n var dif=(j-i)*2\r\n var add=dif === n ? 0: dif < n ? 1 : -1\r\n res.push(add)\r\n }\r\n }\r\n return console.log(res.join(' '))\r\n var map2 = {}\r\n Object.keys(count).map(key => {\r\n if (!map2[count[key]]) map2[count[key]] = 0\r\n map2[count[key]]++\r\n\r\n })\r\n var keys = Object.keys(map2).map(x => parseInt(x)).sort((a, b) => map2[a] - map2[b])\r\n\r\n var sum = new Array(keys.length + 1).fill(0)\r\n\r\n var ans = n\r\n for (let i = 0; i < keys.length; i++) {\r\n sum = 0\r\n for (let j = 0; j < keys.length; j++) {\r\n if (keys[j] < keys[i]) sum += map2[keys[j]] * keys[j]\r\n if (keys[j] > keys[i]) sum += (keys[j] - keys[i]) * map2[keys[j]]\r\n }\r\n ans = Math.min(ans, sum)\r\n }\r\n // console.log(keys)\r\n // console.log(map2)\r\n // console.log(sum)\r\n console.log(ans)\r\n\r\n })\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i + 1; j < n; j++)\r\n\t\t\t\tif (j-i <= Math.floor((n-1)/2)) ans.push(1);\r\n\t\t\t\telse if (n%2 == 0 && j-i == n/2) ans.push(0);\r\n\t\t\t\telse ans.push(-1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = parseInt(readline())\r\n if( n===2) return console.log(0)\r\n if (n % 2 === 1) {\r\n var res = []\r\n for (var i = 0; i < (n * (n - 1)) / 2; i++) {\r\n if (i % 2 === 0) res.push(1)\r\n else res.push(-1)\r\n }\r\n return console.log(res.join(' '))\r\n }\r\n var res = [1]\r\n for (var i = n-1; i >= 2; i--) {\r\n res.push(-1)\r\n for (var j = 0; j < i-1; j++) {\r\n res.push(0)\r\n }\r\n }\r\n console.log(res.join(' '))\r\n\r\n\r\n // for (var i = 3; i*i <= n*4; i=i+2) {\r\n // var b = Math.floor((i*i-1)/2)\r\n// console.log(i*i, b,b+1)\r\n// if(b*2+1===i*i && b*2+1 <= n && b>0) {\r\n// console.log(i,b,b+1 )\r\n// count++\r\n// }\r\n// }\r\n // var mid = Math.fl/oor(n/2)\r\n // var res = Math.floor((k-1) / mid)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = parseInt(readline())\r\n if (n % 2 === 1) {\r\n var res = []\r\n for (var i = 0; i < (n * (n - 1)) / 2; i++) {\r\n if (i % 2 === 0) res.push(1)\r\n else res.push(-1)\r\n }\r\n console.log(res.join(' '))\r\n }\r\n var res = [1]\r\n for (var i = n-1; i >= 2; i--) {\r\n res.push(-1)\r\n for (var j = 0; j < i-1; j++) {\r\n res.push(0)\r\n }\r\n }\r\n console.log(res.join(' '))\r\n\r\n\r\n // for (var i = 3; i*i <= n*4; i=i+2) {\r\n // var b = Math.floor((i*i-1)/2)\r\n// console.log(i*i, b,b+1)\r\n// if(b*2+1===i*i && b*2+1 <= n && b>0) {\r\n// console.log(i,b,b+1 )\r\n// count++\r\n// }\r\n// }\r\n // var mid = Math.fl/oor(n/2)\r\n // var res = Math.floor((k-1) / mid)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}], "src_uid": "a89c585ebd9608141399c813385c04c6"} {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\nfunction gcd(a, b) {\n if (b == 0)\n return a;\n if (a < b)\n return gcd(b, a);\n return gcd(b, a % b);\n}\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, vb, vs] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var [x, y] = inputs[2].split(' ').map(v => +v);\n var min = 1e10;\n var resDis = 0;\n var resId = 0;\n for (let i = 1; i < n; i++) {\n let dis = Math.sqrt((arr[i] - x) ** 2 + y * y);\n let t = arr[i] / vb + dis / vs;\n if (t < min || (t == min && dis < resDis)) {\n min = t;\n resId = i;\n resDis = dis;\n }\n }\n console.log(resId + 1);\n})();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar stopNum = integers[0], busSpeed = integers[1], runSpeed = integers[2];\n\tvar xs = tokenizeIntegers(readline());\n\tvar integers = tokenizeIntegers(readline());\n\tvar xTarget = integers[0], yTarget = integers[1];\n\n\tfunction getDistance(x0, y0, x1, y1) {\n\t\treturn Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2));\n\t}\n\n\tvar records = [];\n\n\tfor (var i = 1; i < xs.length; i += 1) {\n\t\tvar distance = getDistance(xs[i], 0, xTarget, yTarget);\n\t\tvar time = xs[i]/busSpeed + distance/runSpeed;\n\t\trecords.push({ distance: distance, time: time, id: i+1 });\n\t}\n\n\trecords.sort(function(a, b) {\n\t\treturn (a.time == b.time ? a.distance - b.distance : a.time - b.time);\n\t});\n\n\tprint(records[0].id);\n}\n\nmain();\n"}, {"source_code": "var lll = readline().split(' ')\nvar on = lll[0]\nvar vb = lll[1]\nvar vs = lll[2]\n\nvar os = readline().split(' ')\nlll = readline().split(' ')\nvar ux = lll[0]\nvar uy = lll[1]\n\nvar t = 0\nvar pot\nvar lo\n\nfor (var i = 1; i < on; i++) {\n var tv = t + st(i)\n if (pot && pot < tv) {\n lo = i - 1\n break\n } else if (pot && pot == tv) {\n lo = i\n break\n }\n pot = tv\n t += bt(i)\n}\n\nif (!lo) lo = os.length - 1\n\nprint(+lo + 1)\n\nfunction st (o) {\n var ox = os[o]\n return Math.sqrt((ux - ox) * (ux - ox) + uy * uy) / vs\n}\n\nfunction bt (o) {\n if (o == os.length) return 0\n var to = os[o]\n var so = os[o + 1]\n return (so - to) / vb\n}"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar stopNum = integers[0], busSpeed = integers[1], runSpeed = integers[2];\n\tvar xs = tokenizeIntegers(readline());\n\tvar integers = tokenizeIntegers(readline());\n\tvar xTarget = integers[0], yTarget = integers[1];\n\n\tfunction dist(x0, y0, x1, y1) {\n\t\treturn Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2));\n\t}\n\n\tvar bestStop = 1;\n\tvar bestTime = xs[1]/busSpeed + dist(xs[1], 0, xTarget, yTarget)/runSpeed;\n\n\tfor (var i = 2; i < xs.length; i += 1) {\n\t\tvar time = xs[i]/busSpeed + dist(xs[i], 0, xTarget, yTarget)/runSpeed;\n\t\tif (time < bestTime) {\n\t\t\tbestTime = time;\n\t\t\tbestStop = i;\n\t\t}\n\t}\n\n\tprint(bestStop+1);\n}\n\nmain();\n"}], "src_uid": "15fa49860e978d3b3fb7a20bf9f8aa86"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const sum = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a.charCodeAt(i) - 96;\r\n }\r\n const res = [];\r\n for (let [l, r] of b) {\r\n var _sum2;\r\n l--, r--;\r\n res.push(sum[r] - ((_sum2 = sum[l - 1]) !== null && _sum2 !== void 0 ? _sum2 : 0));\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = await read();\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n }\r\n for(let i = 0; iparseInt(num));\r\n let res = pre[r-1];\r\n if (l>1)\r\n res-=pre[l-2];\r\n console.log(res);\r\n }\r\n\r\n}\r\nsolve();\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n\r\n \tlet testCaseNum = readline();\r\n\ttestCaseNum = testCaseNum.split(' ').filter(item => +item);\r\n\ttestCaseNum = testCaseNum[1];\r\n\r\n \tlet str = readline();\r\n\r\n\tlet prefix = new Array(str.length).fill(0);\r\n\tprefix[-1] = 0;\r\n\tfor (let i = 0; i < str.length; i++) {\r\n\t\tprefix[i] += prefix[i - 1];\r\n\t\tprefix[i] += (str[i].charCodeAt() - 96);\r\n\t}\r\n\t\r\n \twhile (testCaseNum) {\r\n \t\tlet tmp = readline();\r\n \t\ttmp = tmp.split(' ').filter(item => +item);\r\n\r\n\t\tconsole.log(prefix[tmp[1] - 1] - prefix[tmp[0] - 2]);\r\n \t\ttestCaseNum --;\r\n \t}\r\n}\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (pre[i] === undefined) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (!Number.isInteger(l) || !Number.isInteger(r)) {\r\n i--;\r\n continue;\r\n //throw new Error('not interger');\r\n }\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var nq = readArray(Number);\r\n var n = nq[0];\r\n var q = nq[1];\r\n var s = read();\r\n var charCodeA = 'a'.charCodeAt(0);\r\n var sum = [0];\r\n for (var i = 0; i < n; i++) {\r\n var num = s.charCodeAt(i) - charCodeA + 1;\r\n sum.push(num + sum[i]);\r\n }\r\n for(var i = 0; i < q; i++) {\r\n var lr = readArray(Number);\r\n var l = lr[0];\r\n var r = lr[1];\r\n write(sum[r] - sum[l - 1]);\r\n }\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const n = input.number();\r\n const q = input.number();\r\n const a = 'a'.charCodeAt(0);\r\n const s = input.word();\r\n const snums = Array.from(s).map((c) => c.charCodeAt(0) - a + 1);\r\n const cumu = array(n + 1, 0);\r\n for (let i = 0; i < n; i++) {\r\n cumu[i + 1] = cumu[i] + snums[i];\r\n }\r\n const ans = Array(q);\r\n for (let i = 0; i < q; i++) {\r\n const l = input.number();\r\n const r = input.number();\r\n ans[i] = cumu[r] - cumu[l - 1];\r\n }\r\n console.log(ans.join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var [n, q] = lines[l++].split(' ').map(Number);\n var str = lines[l++];\n var qs = [];\n for (var i = 0; i < q; i++) {\n var range = lines[l++].split(' ').map(Number)\n qs.push(range)\n }\n console.log(solve(str, qs))\n});\n\nfunction solve(str, qs) {\n const count = []\n let cur\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]\n if (i) {\n cur = { ...cur }\n cur[ch] = (cur[ch] || 0) + 1\n } else {\n cur = {}\n cur[ch] = 1\n }\n count[i] = cur\n }\n\n return qs.map(([l, r]) => {\n l--\n r--\n // count[r] - count[l - 1]\n let sum = 0\n for (let ch in count[r]) {\n const k = ch.charCodeAt(0) - 'a'.charCodeAt(0) + 1\n if (l) {\n sum += (count[r][ch] - (count[l - 1][ch] || 0)) * k\n } else {\n sum += count[r][ch] * k\n }\n }\n return sum\n }).join('\\n')\n}\n"}, {"source_code": "nq = readline().split(' ');\r\nn = +nq[0];\r\nq = +nq[1];\r\n\r\nstr = readline();\r\n\r\na = [0];\r\n\r\nlen = str.length;\r\nfor (i = 0; i < len; ++i) {\r\n x = str.charCodeAt(i) - 96\r\n\r\n a.push(x + a[i])\r\n}\r\n\r\nfor (i = 0; i < q; ++i) {\r\n lr = readline().split(' ')\r\n l = +lr[0];\r\n r = +lr[1];\r\n\r\n print(a[r] - a[l - 1]);\r\n}"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n }\r\n for(let i = 0; iparseInt(num));\r\n let res = pre[r-1];\r\n if (l>1)\r\n res-=pre[l-2];\r\n console.log(res);\r\n }\r\n\r\n}\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n }\r\n for(let i = 0; iparseInt(num));\r\n let res = pre[r];\r\n if (l>1)\r\n res-=pre[l-1];\r\n console.log(res);\r\n }\r\n\r\n}\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n }\r\n for(let i = 0; i1)\r\n res-=pre[l-1];\r\n console.log(res);\r\n }\r\n\r\n}\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (pre[i] === undefined) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (!Number.isInteger(l) || !Number.isInteger(r)) {\r\n throw new Error('not interger');\r\n }\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (pre[i] === undefined) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (!Number.isInteger(l) || !Number.isInteger(r)) {\r\n throw new Error('not interger');\r\n }\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (pre[i] === undefined) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (!Number.isInteger(l) || !Number.isInteger(r)) {\r\n throw new Error('not interger');\r\n }\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (pre[i] === undefined) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n l = Math.floor(l + 0.000001);\r\n r = Math.floor(r + 0.000001);\r\n /* if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');*/\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /* if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n } */\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n /* if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');*/\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n if (pre[r-1] === undefined || (l !== 1 && pre[l-2] === undefined)){\r\n throw new Error(i + '');\r\n }\r\n\r\n /* if (res === undefined)\r\n throw new Error('ololo'); */\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n /* if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');*/\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /*if (Number.isNaN(pre[r-1]) || (l !== 1 && Number.isNaN(pre[l-2]))){\r\n throw new Error(i + '');\r\n }*/\r\n if (res === undefined)\r\n throw new Error('ololo');\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n /* if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');*/\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /*if (Number.isNaN(pre[r-1]) || (l !== 1 && Number.isNaN(pre[l-2]))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /*if (Number.isNaN(pre[r-1]) || (l !== 1 && Number.isNaN(pre[l-2]))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(pre[i])) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n if (Number.isNaN(pre[r-1]) || (l !== 1 && Number.isNaN(pre[l-2]))){\r\n throw new Error(i + '');\r\n }\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst fs = require('fs');\r\nconst rl = lib.createInterface({\r\n input: process.stdin, // fs.createReadStream('input.txt'),\r\n output: process.stdout\r\n});\r\n//const inp = fs.createReadStream('input.txt');\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n if (Number.isNaN(pre[r-1]) || (l !== 1 && Number.isNaN(pre[l-2]))){\r\n throw new Error(i + '');\r\n }\r\n console.log(res);\r\n }\r\n\r\n}\r\n\r\n/*let txtFile = fs.createWriteStream('output2.txt', {flags:'a'});\r\ntxtFile.write('100000 100000\\n');\r\nconst acode = 'a'.charCodeAt(0);\r\nfor(let i = 0; i<100000; i++){\r\n txtFile.write(String.fromCharCode(i%20 + acode));\r\n}\r\ntxtFile.write('\\n');\r\nfor(let i = 0; i<100000; i++)\r\n txtFile.write('1 ' + (i + 1) + '\\n');\r\n*/\r\nsolve();\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res -= pre[l-2];\r\n /*if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>1)\r\n res += pre[l-2];\r\n /*if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res = pre[r-1];\r\n if (l>2)\r\n res += pre[l-2];\r\n /*if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = 'a'.charCodeAt(0) - 1;\r\n pre[0] = s.charCodeAt(0) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + s.charCodeAt(i) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n /*if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n if (Number.isNaN(Number(pre[i]))) {\r\n throw new Error(i + ' ');\r\n }\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n /*if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }*/\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n if (Number.isNaN(Number(pre[r-1])) || (l !== 1 && Number.isNaN(Number(pre[l-2])))){\r\n throw new Error(i + '');\r\n }\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n if (Number.isNaN(Number(res))){\r\n throw new Error(i + '');\r\n }\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n if (Number.isNaN(res.asIntN())){\r\n throw new Error(i + '');\r\n }\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n if (Number.isNan(res.asIntN())){\r\n throw new Error(i + '');\r\n }\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n const cur =s.charCodeAt(0);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(0));\r\n throw new Error('test');\r\n }\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n const cur =s.charCodeAt(i);\r\n if (Number.isNaN(cur)) {\r\n console.log(i + ' ' + s.charAt(i));\r\n throw new Error('test');\r\n }\r\n\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n if (s.length !== n)\r\n throw new Error('test');\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n if (l<1 || l>n || r<1 || r>n)\r\n throw new Error('test');\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(n);\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(s.length);\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < n; i++) {\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, q;\r\n [n, q] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const pre = new Array(s.length);\r\n const zeroCharCode = BigInt('a'.charCodeAt(0)) - BigInt(1);\r\n pre[0] = BigInt(s.charCodeAt(0)) - zeroCharCode;\r\n for(let i = 1; i < s.length; i++) {\r\n pre[i] = pre[i-1] + BigInt(s.charCodeAt(i)) - zeroCharCode;\r\n }\r\n for(let i = 0; i parseInt(num));\r\n let res;\r\n if (l == 1)\r\n res = pre[r - 1];\r\n else\r\n res = pre[r-1] - pre[l-2];\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n\r\n \tlet testCaseNum = readline();\r\n\ttestCaseNum = testCaseNum.split(' ').filter(item => +item);\r\n\ttestCaseNum = testCaseNum[1];\r\n\r\n \tlet str = readline();\r\n\r\n \twhile (testCaseNum) {\r\n \t\tlet tmp = readline();\r\n \t\ttmp = tmp.split(' ').filter(item => +item);\r\n\r\n \t\tlet ret = '';\r\n\t\tfor (let i = tmp[0] - 1; i <= tmp[1] - 1; i++) {\r\n\t\t\tif (str[i] == 'a') {\r\n\t\t\t\tret += 'a';\r\n\t\t\t} else if (str[i] == 'b') {\r\n\t\t\t\tret += 'bb';\r\n\t\t\t} else if (str[i] == 'c'){\r\n\t\t\t\tret += 'ccc';\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ret.length);\r\n \t\ttestCaseNum --;\r\n \t}\r\n}\r\n"}], "src_uid": "461378e9179c9de454674ea9dc49c56c"} {"source_code": "var n = +readline();\n\nvar a = readline().split( ' ' ).map( Number );\n\nvar ans = 0;\nvar f = 1;\n\nfor( var i = 0; i < n; i++ )\n\tif( a[i] === i ) ans++;\n\telse if( a[ a[ i ] ] === i ) f = 2;\n\n\nprint( Math.min( n, ans + f ) );", "positive_code": [{"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar t = readline().split(' ').map(Number);\n\tvar a = t.map(function (e, i) { return [i, e]; }).filter(function (e) { return e[0] != e[1]; });;\n\tvar l = a.length;\n\n\tif (a.length < 2) {\n\t\tprint(n - a.length);\n\t\treturn;\n\t}\n\n\tfor (var i = 0; i < l - 1; i++)\n\t\tif (a[i][0] == t[a[i][1]] && a[i][1] == t[a[i][0]]) {\n\t\t\tprint(n - a.length + 2);\n\t\t\treturn;\n\t\t}\n\n\tprint(n - a.length + 1);\n\n}).call(this);"}, {"source_code": "(function (){\n var i, n = parseInt(readline());\n var a = readline().split(' ');\n var fixed = 0, swap = 0;\n for ( i = 0 ; i < n ; ++i){\n if ( i == a[i] ){\n ++fixed;\n }else if ( i == a[a[i]] ){\n ++swap;\n }\n }\n if ( swap > 0 ){\n fixed += 2;\n }else if ( fixed != n ){\n fixed += 1;\n }\n print(fixed);\n})();"}], "negative_code": [{"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar a = readline().split(' ').map(function (e, i) { return [i, e]; }).filter(function (e) { return e[0] != e[1]; });;\n\tvar l = a.length;\n\n\tif (a.length < 2) {\n\t\tprint(n - a.length);\n\t\treturn;\n\t}\n\n\tfor (var i = 0; i < l - 1; i++)\n\t\tfor (var j = i + 1; j < l; j++) {\n\t\t\tif (a[j][0] === a[i][1] && a[j][1] === a[i][0]) {\n\t\t\t\tprint(n - a.length + 2);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\tprint(n - a.length + 1);\n\n}).call(this);"}], "src_uid": "e63de0fffd00b2da103545a7f1e405be"} {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n var x = 0;\n while(n > 0){\n var z = n % 10;\n x = Math.max(x, z);\n n /= 10;\n }\n console.log(Math.floor(x));\n }\n});", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n3\r\n1\r\n2\r\n3\r\n\r\n\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\n\r\n\r\nfunction main() {\r\n \r\n let t = parseInt(readline());\r\n \r\n while(t--){\r\n \r\n var n;\r\n var count = 0;\r\n n = parseInt(readline());\r\n \r\n while(n){\r\n var num = n.toString();\r\n var num1 = \"\";\r\n \r\n for(var c in num){\r\n if(num[c]!='0') num1+='1';\r\n else num1+='0';\r\n }\r\n \r\n count++;\r\n n = n - parseInt(num1);\r\n }\r\n console.log(count);\r\n }\r\n \r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var max = 0;\n var k = lines[j];\n var m = 0;\n var a = 0;\n while(k > 0){\n m = k % 10;\n a = Math.max(a, m);\n k /= 10;\n }\n console.log(Math.floor(a));\n }\n}); \n "}, {"source_code": "var fs = require('fs'), currentline = 0, input = fs.readFileSync(0, 'utf8').trim().split('\\n');\nfunction readline() { return input[currentline++]; }\nvar T = +readline();\nfor (var j = 0; j < T; j++) {\n var n = readline(), ans = 0;\n for (var i = 0; i < n.length; i++)\n ans = Math.max(ans, +n[i]);\n console.log(ans);\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar max = 0;\r\n\t\twhile(N > 0){\r\n\t\t\tmax = Math.max(max, N % 10);\r\n\t\t\tN = Math.floor(N / 10);\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \n \nfunction main() {\n const n = Number(readline());\n\n for(let i = 0; i < n; i++) {\n const decimal = readline().split('').map(Number);\n\n decimal.sort((a,b) => b-a);\n\n console.log(decimal[0]);\n }\n}\n\n\n\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n const size = lines[0];\r\n for(let j = 1; j <= size; j++) {\r\n let max = 0;\r\n let num = lines[j];\r\n while (num !== 0) {\r\n digit = num % 10;\r\n if (digit > max) {\r\n max = digit;\r\n }\r\n num = Math.floor(num / 10);\r\n }\r\n console.log(max);\r\n }\r\n})"}, {"source_code": "let input = '';\nprocess.stdin.on('data', chunk => input += chunk);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = input.split(EOL);\n const count = parseInt(lines[0]);\n for (let i = 1; i <= count; ++i) {\n const solution = solve(lines[i]);\n console.log(solution);\n }\n});\n\nfunction solve(question) {\n let max = 0;\n for (const digit of question) {\n if (digit.match(/^\\d$/)) {\n const num = parseInt(digit);\n if (num > max) {\n max = num;\n }\n }\n }\n return max;\n}\n"}], "negative_code": [], "src_uid": "1a6881aeb197b8ed429f46850eb27b9c"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let [w, h] = readline().split(' ').map(num => parseInt(num));\n let x1 = readline().split(' ').map(num => parseInt(num));\n let x2 = readline().split(' ').map(num => parseInt(num));\n let y1 = readline().split(' ').map(num => parseInt(num));\n let y2 = readline().split(' ').map(num => parseInt(num));\n let t1 = (x1[x1.length - 1] - x1[1]) * h;\n let t2 = (x2[x2.length - 1] - x2[1]) * h;\n let t3 = (y1[y1.length - 1] - y1[1]) * w;\n let t4 = (y2[y2.length - 1] - y2[1]) * w;\n console.log(Math.max(t1, t2, t3, t4));\n }\n}", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = coordinates[0];\r\n var h = coordinates[1];\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = x_when_y_zero[0] - 1;\r\n var length_of_x_when_y_h = x_when_y_h[0] - 1;\r\n var length_of_y_when_zero = y_when_x_zero[0] - 1;\r\n var length_of_y_when_w = y_when_x_w[0] - 1;\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n x_when_y_h.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_w.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n var res = [\r\n x_when_y_zero[length_of_x_when_y_zero]-x_when_y_zero[0],\r\n x_when_y_h[length_of_x_when_y_h]-x_when_y_h[0],\r\n y_when_x_zero[length_of_y_when_zero]-y_when_x_zero[0],\r\n y_when_x_w[length_of_y_when_w]-y_when_x_w[0]\r\n ];\r\n \r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n res.reverse();\r\n console.log(res[0]);\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = BigInt(coordinates[0]);\r\n var h = BigInt(coordinates[1]);\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = BigInt(x_when_y_zero[0] - 1);\r\n var length_of_x_when_y_h = BigInt(x_when_y_h[0] - 1);\r\n var length_of_y_when_zero = BigInt(y_when_x_zero[0] - 1);\r\n var length_of_y_when_w = BigInt(y_when_x_w[0] - 1);\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n x_when_y_h.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_w.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n var res = [\r\n BigInt(x_when_y_zero[length_of_x_when_y_zero]-x_when_y_zero[0]),\r\n BigInt(x_when_y_h[length_of_x_when_y_h]-x_when_y_h[0]),\r\n BigInt(y_when_x_zero[length_of_y_when_zero]-y_when_x_zero[0]),\r\n BigInt(y_when_x_w[length_of_y_when_w]-y_when_x_w[0])\r\n ];\r\n \r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n res.reverse();\r\n console.log(String(res[0]));\r\n }\r\n return 0;\r\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n for(let i = 0; i < fileContents.length; i+=5){\n triangleScenarioHigh(fileContents[i],fileContents[i+1],fileContents[i+2],fileContents[i+3],fileContents[i+4])\n }\n}\nfunction triangleScenarioHigh(corner,horizontal0,horizontalY,vertical0,verticalX){\n // console.log(\"corner,horizontal0,horizontalY,vertical0,verticalX\")\n // console.log(corner,horizontal0,horizontalY,vertical0,verticalX)\n\n triangleScenarioLow(corner.split(\" \"),\n horizontal0.split(\" \").slice(1),\n horizontalY.split(\" \").slice(1),\n vertical0.split(\" \").slice(1),\n verticalX.split(\" \").slice(1))\n}\n\nfunction triangleScenarioLow(corner,horizontal0,horizontalY,vertical0,verticalX){\n // console.log(\"corner,horizontal0,horizontalY,vertical0,verticalX\")\n // console.log(corner,horizontal0,horizontalY,vertical0,verticalX)\n const YCorner = parseInt(corner[1]) //8\n const XCorner = parseInt(corner[0]) //5\n const points = [\n [[parseInt(horizontal0[0]),0],[parseInt(horizontal0[horizontal0.length-1]),0]],\n [[parseInt(horizontalY[0]),YCorner],[parseInt(horizontalY[horizontalY.length-1]),YCorner]],\n [[0,parseInt(vertical0[0])],[0,parseInt(vertical0[vertical0.length-1])]],\n [[XCorner,parseInt(verticalX[0])],[XCorner,parseInt(verticalX[verticalX.length-1])]],\n ]\n\n // console.log(\"points\",points) //xxx\n\n let biggestArea = 0\n\n for(i = 0; i < points.length; i++){\n for(i2 = 0; i2 < points.length; i2++){\n if(i !== i2){\n let length1 = Math.sqrt(Math.pow(points[i][0][0] - points[i2][0][0],2) + Math.pow(points[i][0][1] - points[i2][0][1],2))\n let length2 = Math.sqrt(Math.pow(points[i][1][0] - points[i2][0][0],2) + Math.pow(points[i][1][1] - points[i2][0][1],2))\n let length3 = Math.sqrt(Math.pow(points[i][0][0] - points[i][1][0],2) + Math.pow(points[i][0][1] - points[i][1][1],2))\n biggestArea = Math.max(biggestArea,findArea(length1,length2,length3)*2);\n length1 = Math.sqrt(Math.pow(points[i][0][0] - points[i2][1][0],2) + Math.pow(points[i][0][1] - points[i2][1][1],2))\n length2 = Math.sqrt(Math.pow(points[i][1][0] - points[i2][1][0],2) + Math.pow(points[i][1][1] - points[i2][1][1],2))\n length3 = Math.sqrt(Math.pow(points[i][0][0] - points[i][1][0],2) + Math.pow(points[i][0][1] - points[i][1][1],2))\n biggestArea = Math.max(biggestArea,findArea(length1,length2,length3)*2);\n\n }\n }\n }\n\n\n\n console.log(Math.round(biggestArea));\n\n}\n\n\nfunction findArea( a, b, c)\n{\n if (a < 0 || b < 0 || c < 0 ||\n (a + b <= c) || a + c <= b ||\n b + c <= a)\n {\n return -1;\n }\n let s = (a + b + c) / 2;\n return Math.sqrt(s * (s - a) *\n (s - b) * (s - c));\n}\n\n"}, {"source_code": "const getMaximum = arr=>arr[arr.length-1] - arr[1];\r\nconst solve = (w,h,arr)=>{\r\n let t = h,max = 0;\r\n for(let i=1;i<=4;i++){\r\n if(i>2) t = w;\r\n let v = getMaximum(arr[i-1])*t;\r\n if(v>=max) max = v;\r\n }\r\n console.log(max);\r\n}\r\n\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n let arr= [];\r\n for(let i=0;i<4;i++)\r\n arr.push(readline().trim().split(\" \").map(cur=>parseInt(cur)));\r\n solve(w,h,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [w, h] = rna();\r\n\r\n\t\tfunction go (height) {\r\n\t\t\tconst ar = rna().slice(1);\r\n\t\t\tar.sort((x, y) => x - y);\r\n\t\t\tans = Math.max(ans, height * (ar[ar.length - 1] - ar[0]));\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tgo(h);\r\n\t\tgo(h);\r\n\t\tgo(w);\r\n\t\tgo(w);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// function foo(x) {\r\n// process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\r\n// console.log(x); // with auto '\\n' (newline)\r\n// }\r\n\r\nconst print = x => {\r\n process.stdout.write(x.toString());\r\n process.stdout.write(\"\\n\");\r\n};\r\n\r\nfunction main() {\r\n const n = readline();\r\n\r\n for (let test = 0; test < n; test += 1) {\r\n const [w, h] = readline().split(' ');\r\n\r\n const getMaxDistanceBetween = () => {\r\n const arr = readline().split(' ');\r\n let mn = 1000 * 1000 + 3;\r\n let mx = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n mn = Math.min(mn, arr[i]);\r\n mx = Math.max(mx, arr[i]);\r\n }\r\n return mx - mn;\r\n }\r\n\r\n const down = getMaxDistanceBetween();\r\n const up = getMaxDistanceBetween();\r\n const left = getMaxDistanceBetween();\r\n const right = getMaxDistanceBetween();\r\n\r\n const ans = Math.max(\r\n down * h,\r\n up * h,\r\n left * w,\r\n right * w,\r\n )\r\n\r\n print(ans);\r\n }\r\n\r\n}\r\n"}, {"source_code": "function S(a, b, c) {\r\n return Math.abs(\r\n (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])\r\n );\r\n}\r\n\r\nfunction solve(points) {\r\n var answers = [0, 0, 0, 0];\r\n for (var i = 0; i < 4; i++) {\r\n a = points[i][0];\r\n b = points[i][points[i].length - 1];\r\n\r\n for (var j = 0; j < 4; j++) {\r\n if (i === j) continue;\r\n\r\n for (var c of points[j]) {\r\n answers[i] = Math.max(answers[i], S(a, b, c));\r\n }\r\n }\r\n }\r\n\r\n return Math.max.apply(null, answers);\r\n}\r\n\r\nvar _i = 0;\r\nvar _input = `3\r\n5 8\r\n2 1 2\r\n3 2 3 4\r\n3 1 4 6\r\n2 4 5\r\n10 7\r\n2 3 9\r\n2 1 7\r\n3 1 3 4\r\n3 4 5 6\r\n11 5\r\n3 1 6 8\r\n3 3 6 8\r\n3 1 3 4\r\n2 2 4\r\n`.split(\"\\n\");\r\n\r\nt = Number(readline());\r\npoints = [[], [], [], []];\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var wh = readline().split(\" \").map(Number);\r\n var w = wh[0];\r\n var h = wh[1];\r\n var snd_coords = [0, h, 0, w];\r\n\r\n points.forEach(function (p, i) {\r\n points[i] = readline()\r\n .split(\" \")\r\n .slice(1)\r\n .map(Number)\r\n .map(function (x) {\r\n return i < 2 ? [x, snd_coords[i]] : [snd_coords[i], x];\r\n });\r\n });\r\n\r\n // console.log(points);\r\n\r\n print(solve(points));\r\n}\r\n\r\n// function readline() {\r\n// return _input[_i++];\r\n// }\r\n\r\n// function print(val) {\r\n// console.log(val);\r\n// }\r\n"}], "negative_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = BigInt(coordinates[0]);\r\n var h = BigInt(coordinates[1]);\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = BigInt(x_when_y_zero[0] - 1);\r\n var length_of_x_when_y_h = BigInt(x_when_y_h[0] - 1);\r\n var length_of_y_when_zero = BigInt(y_when_x_zero[0] - 1);\r\n var length_of_y_when_w = BigInt(y_when_x_w[0] - 1);\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n x_when_y_h.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_zero.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n y_when_x_w.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });;\r\n var res = [\r\n BigInt(x_when_y_zero[length_of_x_when_y_zero]-x_when_y_zero[0]),\r\n BigInt(x_when_y_h[length_of_x_when_y_h]-x_when_y_h[0]),\r\n BigInt(y_when_x_zero[length_of_y_when_zero]-y_when_x_zero[0]),\r\n BigInt(y_when_x_w[length_of_y_when_w]-y_when_x_w[0])\r\n ];\r\n console.log(String(res));\r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n res.reverse();\r\n console.log(String(res[0]));\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = BigInt(coordinates[0]);\r\n var h = BigInt(coordinates[1]);\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = x_when_y_zero[0];\r\n var length_of_x_when_y_h = x_when_y_h[0];\r\n var length_of_y_when_zero = y_when_x_zero[0];\r\n var length_of_y_when_w = y_when_x_w[0];\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort();\r\n x_when_y_h.sort();\r\n y_when_x_zero.sort();\r\n y_when_x_w.sort();\r\n var res = [\r\n BigInt(x_when_y_zero[length_of_x_when_y_zero-1]-x_when_y_zero[0]),\r\n BigInt(x_when_y_h[length_of_x_when_y_h-1]-x_when_y_h[0]),\r\n BigInt(y_when_x_zero[length_of_y_when_zero-1]-y_when_x_zero[0]),\r\n BigInt(y_when_x_w[length_of_y_when_w-1]-y_when_x_w[0])\r\n ];\r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n res.reverse();\r\n console.log(String(res[0]));\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = coordinates[0];\r\n var h = coordinates[1];\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = x_when_y_zero[0];\r\n var length_of_x_when_y_h = x_when_y_h[0];\r\n var length_of_y_when_zero = y_when_x_zero[0];\r\n var length_of_y_when_w = y_when_x_w[0];\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort();\r\n x_when_y_h.sort();\r\n y_when_x_zero.sort();\r\n y_when_x_w.sort();\r\n var res = [\r\n x_when_y_zero[length_of_x_when_y_zero-1]-x_when_y_zero[0],\r\n x_when_y_h[length_of_x_when_y_h-1]-x_when_y_h[0],\r\n y_when_x_zero[length_of_y_when_zero-1]-y_when_x_zero[0],\r\n y_when_x_w[length_of_y_when_w-1]-y_when_x_w[0]\r\n ];\r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a ,b) => {\r\n if(a > b) {\r\n return 1;\r\n } else if (a < b){\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n res.reverse();\r\n console.log(res[0]);\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nvar test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n var test = readLine();\r\n \r\n while(test--)\r\n {\r\n var coordinates = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var w = coordinates[0];\r\n var h = coordinates[1];\r\n var x_when_y_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var x_when_y_h = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_zero = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var y_when_x_w = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n var length_of_x_when_y_zero = x_when_y_zero[0];\r\n var length_of_x_when_y_h = x_when_y_h[0];\r\n var length_of_y_when_zero = y_when_x_zero[0];\r\n var length_of_y_when_w = y_when_x_w[0];\r\n x_when_y_zero.shift();\r\n x_when_y_h.shift();\r\n y_when_x_zero.shift();\r\n y_when_x_w.shift();\r\n x_when_y_zero.sort();\r\n x_when_y_h.sort();\r\n y_when_x_zero.sort();\r\n y_when_x_w.sort();\r\n var res = [\r\n x_when_y_zero[length_of_x_when_y_zero-1]-x_when_y_zero[0],\r\n x_when_y_h[length_of_x_when_y_h-1]-x_when_y_h[0],\r\n y_when_x_zero[length_of_y_when_zero-1]-y_when_x_zero[0],\r\n y_when_x_w[length_of_y_when_w-1]-y_when_x_w[0]\r\n ];\r\n res[0] = res[0]*h;\r\n res[1] = res[1]*h;\r\n res[2] = res[2]*w;\r\n res[3] = res[3]*w;\r\n res.sort((a, b) => a-b);\r\n res.reverse();\r\n console.log(res[0]);\r\n }\r\n return 0;\r\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n for(let i = 0; i < fileContents.length; i+=5){\n triangleScenarioHigh(fileContents[i],fileContents[i+1],fileContents[i+2],fileContents[i+3],fileContents[i+4])\n }\n}\nfunction triangleScenarioHigh(corner,horizontal0,horizontalY,vertical0,verticalX){\n // console.log(\"corner,horizontal0,horizontalY,vertical0,verticalX\")\n // console.log(corner,horizontal0,horizontalY,vertical0,verticalX)\n\n triangleScenarioLow(corner.split(\" \"),\n horizontal0.split(\" \").slice(1),\n horizontalY.split(\" \").slice(1),\n vertical0.split(\" \").slice(1),\n verticalX.split(\" \").slice(1))\n}\n\nfunction triangleScenarioLow(corner,horizontal0,horizontalY,vertical0,verticalX){\n // console.log(\"corner,horizontal0,horizontalY,vertical0,verticalX\")\n // console.log(corner,horizontal0,horizontalY,vertical0,verticalX)\n const YCorner = parseInt(corner[1]) //8\n const XCorner = parseInt(corner[0]) //5\n const points = [\n [[parseInt(horizontal0[0]),0],[parseInt(horizontal0[horizontal0.length-1]),0]],\n [[parseInt(horizontalY[0]),YCorner],[parseInt(horizontalY[horizontal0.length-1]),YCorner]],\n [[0,parseInt(vertical0[0])],[0,parseInt(vertical0[vertical0.length-1])]],\n [[XCorner,parseInt(verticalX[0])],[XCorner,parseInt(verticalX[verticalX.length-1])]],\n ]\n\n // console.log(\"points\",points)\n\n let biggestArea = 0\n\n for(i = 0; i < points.length; i++){\n for(i2 = 0; i2 < points.length; i2++){\n if(i !== i2){\n let length1 = Math.sqrt(Math.pow(points[i][0][0] - points[i2][0][0],2) + Math.pow(points[i][0][1] - points[i2][0][1],2))\n let length2 = Math.sqrt(Math.pow(points[i][1][0] - points[i2][0][0],2) + Math.pow(points[i][1][1] - points[i2][0][1],2))\n let length3 = Math.sqrt(Math.pow(points[i][0][0] - points[i][1][0],2) + Math.pow(points[i][0][1] - points[i][1][1],2))\n biggestArea = Math.max(biggestArea,findArea(length1,length2,length3)*2);\n length1 = Math.sqrt(Math.pow(points[i][0][0] - points[i2][1][0],2) + Math.pow(points[i][0][1] - points[i2][1][1],2))\n length2 = Math.sqrt(Math.pow(points[i][1][0] - points[i2][1][0],2) + Math.pow(points[i][1][1] - points[i2][1][1],2))\n length3 = Math.sqrt(Math.pow(points[i][0][0] - points[i][1][0],2) + Math.pow(points[i][0][1] - points[i][1][1],2))\n biggestArea = Math.max(biggestArea,findArea(length1,length2,length3)*2);\n\n }\n }\n }\n\n\n\n console.log(Math.round(biggestArea));\n\n}\n\n\nfunction findArea( a, b, c)\n{\n if (a < 0 || b < 0 || c < 0 ||\n (a + b <= c) || a + c <= b ||\n b + c <= a)\n {\n return -1;\n }\n let s = (a + b + c) / 2;\n return Math.sqrt(s * (s - a) *\n (s - b) * (s - c));\n}\n\n"}], "src_uid": "2c67ee95eba7ffbbed99cb488abb5f3d"} {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i += 2) {\n let info = txt[i].split(\" \")[0] * 1;\n doit(info, txt[i + 1].split(/[ ]/).filter(data => data.length > 0).map(dta => dta * 1));\n}\n\nfunction doit(n, tab) {\n let moves = tab[0] - 1;\n for (let i = 0; i < tab.length - 1; i++) {\n if (tab[i + 1] >= tab[i]) {\n moves += tab[i + 1] - tab[i];\n } else {\n moves += tab[i + 1] + (n - tab[i]);\n }\n\n }\n console.log(moves);\n}", "positive_code": [{"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tconst [n, m] = inputReader.readNumberArray();\n\tconst arr = inputReader.readNumberArray();\n\tlet current = 1;\n\tlet time = 0;\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tif(current<=arr[i]){\n\t\t\ttime+=Math.abs(current-arr[i]);\n\t\t\tcurrent=arr[i];\n\t\t}\n\t\telse{\n\t\t\ttime+=Math.abs(current-n) + Math.abs(1-arr[i])+1;\n\t\t\tcurrent=arr[i];\n\t\t}\n\t} \n\tconsole.log(time);\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumberArray(){\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [totalHouses, tasksLen] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const tasks = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let count = tasks[0] - 1;\n\n for (let i = 0; i < tasksLen - 1; i++) {\n const diff = tasks[i + 1] - tasks[i];\n if (diff >= 0) {\n count += diff;\n } else {\n const steps = totalHouses - tasks[i] + tasks[i + 1];\n count += steps;\n }\n }\n console.log(count);\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n, m] = input[0].split(' ').map(x => parseInt(x));\n const deway = input[1].split(' ').map(x => parseInt(x));\n let stay = 1;\n let answer = 0;\n\n for (let i = 0; i < deway.length; i += 1) {\n if (stay > deway[i]) {\n answer += (n - stay + deway[i]);\n } else {\n answer += deway[i]-stay;\n }\n stay = deway[i];\n }\n\n console.log(answer);\n});\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let [n, m] = splitAndParseInt(input[0]);\n const nums = splitAndParseInt(input[1]);\n\n let answer = 0,\n pos = 1;\n for (const num of nums) {\n if (pos <= num) {\n answer += num - pos;\n } else {\n answer += num + (n - pos);\n }\n pos = num;\n }\n console.log(answer);\n});\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\n\tlet tasks = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\n\tlet current = 1;\n\tlet total = 0;\n\n\ttasks.forEach(task => {\n\t\tif (task >= current) {\n\t\t\ttotal += task - current;\n\t\t} else {\n\t\t\ttotal += n - current + task;\n\t\t}\n\t\tcurrent = task;\n\t});\n\n\tconsole.log(total);\n}\n"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], m = +input[1], a = readline().split(\" \"), b = 1, time = 0;\n\nfor(j = 0; j < m; j++){\n\tif(b < +a[j]){\n\t\ttime += +a[j] - b;\n\t\tb = +a[j];\n\t}\n\telse if(b > +a[j]){\n\t\ttime += n - b + +a[j];\n\t\tb = +a[j];\n\t}\n}\n\nwrite(time);"}, {"source_code": "var meta = readline().split(' ').map((as)=> parseInt(as))\nvar time = 0, res = 0, start = 1\nreadline().split(' ').map((c)=> parseInt(c)).forEach((val)=>{\n\tres = val - start;\n\tif (res < 0){\n\t\ttime += (meta[0] - start) + val\n\t}\n\telse{\n\t\ttime += val - start\n\t}\n\tstart = val\n})\nprint(time)\n"}, {"source_code": ";(function () {\n\n\tvar s = readline().split(' ');\n\tvar n = +s[0];\n\tvar m = +s[1];\n\tvar a = readline().split(' ').map(function (i) { return +i; });\n\tvar ans = n;\n\n\tfor(var i = 1; i < m; i++)\n\t\tif (a[i] < a[i-1])\n\t\t\tans += n;\n\n\tprint(ans - n + a[a.length - 1] - 1);\n\n}).call(this);"}, {"source_code": "var l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar a=readline().split(' ').map(function(v){return+v});\n\nvar ans=n;\nfor(var i=1; ia[i]){ans+=abs(a[i-1]-nm[0]); ans++; a[i-1]=1;}\n ans+=abs(a[i]-a[i-1]);\n}\nprint(ans);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\nfor(var i=0;i=cur) t+=m[i]-cur;\n cur=m[i];\n \n//ts+=' '+t;\n}\nprint(t);"}, {"source_code": "\n'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nString.prototype.getNumber = function() {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n })[0];\n}\n\nlet n = readline().getNumber(),\n array = readline().getNumArray(),\n time = 0;\n\narray.unshift(1);\n\nlet calcTime = (time, destinationBuilding, currentBuilding, totalAmountOfBuildings) => {\n if(destinationBuilding < currentBuilding) {\n time+=totalAmountOfBuildings - currentBuilding + 1;\n time+=destinationBuilding - 1;\n } else if (destinationBuilding > currentBuilding) {\n time+=destinationBuilding - currentBuilding;\n }\n\n return time;\n}\n\nfor (let i = 0; i < array.length - 1; i++) {\n time = calcTime(time, array[i+1], array[i], n);\n}\n\nwrite(time)"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var m = +str[1];\nvar house = readline().split(\" \");\nvar temp = 1; var res = 0;\n\tfor(var i=0; ihouse[i]) // \t\t\t3 2\n\t\t\tres+= n-temp+Number(house[i]);\n\t\t\t\n\t\t\t temp = +house[i]; // 3 \n\t}\nprint(res);\n\t"}, {"source_code": "var n = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar diff = a[0] - 1;\nfor (var i = 0; i < a.length - 1; i++) {\n\tdiff += ((a[i+1] >= a[i]) ? (a[i+1] - a[i]) : (n - a[i] + a[i + 1]));\n}\nprint (diff);"}, {"source_code": "var ringRoad = function(n, arr)\n {\n var counter = arr[0] - 1; \n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] >= arr[i - 1])\n {\n counter += arr[i] - arr[i - 1];\n continue;\n }\n else {\n\t\t\t\t\t//if (arr[i - 1] !== n)\n counter += n - arr[i - 1] + arr[i];\n\t\t\t\t\t//else counter += 1;\n }\n }\n\t\t\treturn counter;\n }\n var toNumArr = function(str)\n {\n str = str.split(' ');\n for (var i = 0 ; i <= str.length - 1; i++)\n {\n str[i] = +str[i];\n }\n return str;\n }\n var num = toNumArr(readline());\n var input = toNumArr(readline());\n print(ringRoad(num[0], input));"}, {"source_code": "var ringRoad = function(n, arr)\n {\n var counter = arr[0] - 1; \n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] > arr[i - 1])\n {\n counter += arr[i] - arr[i - 1];\n continue;\n }\n else if (arr[i] < arr[i - 1]) {\n\t\t\t\t\t//if (arr[i - 1] !== n)\n counter += n - arr[i - 1] + arr[i];\n\t\t\t\t\t//else counter += 1;\n }\n }\n\t\t\treturn counter;\n }\n var toNumArr = function(str)\n {\n str = str.split(' ');\n for (var i = 0 ; i <= str.length - 1; i++)\n {\n str[i] = +str[i];\n }\n return str;\n }\n var num = toNumArr(readline());\n var input = toNumArr(readline());\n print(ringRoad(num[0], input));"}, {"source_code": "var inp = readline().split(' ');\nvar a = readline().split(' ');\n\nfor(var i=0; i a[i-1]) path += a[i] - a[i-1];\n else if(a[i] < a[i-1]) {\n path += n - a[i-1];\n path += 1;\n path += a[i] - 1;\n }\n }\n}\n\nprint(path);"}, {"source_code": "var nums = readNums();\n\nvar n = nums[0];\nvar m = nums[1];\n\nvar things = readNums();\n\nvar k = 0;\n\nfor (var i = 0; i {\n\tif (c >= a.now) {\n\t\ta.sum += c - a.now;\n\t} else {\n\t\ta.sum += n - a.now + c;\n\t}\n\ta.now = c;\n\treturn a;\n}, { now: 1, sum: 0 });\nprint(r.sum)"}, {"source_code": "X=readline().split(' ').map(Number)\nn=X[0], m=X[1]\nA=readline().split(' ').map(Number)\nprint(A.reduce((a,c) => ({\n\tsum: a.sum + (c >= a.now ? (c - a.now) : (n - a.now + c)),\n\tnow: c,\n}), { now: 1, sum: 0 }).sum);\n"}, {"source_code": "var a =readline().split(' ').map(Number);\nvar b =readline().split(' ').map(Number);\nd = b[0]-1;\nfor(var i = 1;i data.length > 0);\n\nfor (let i = 0; i < txt.length; i += 2) {\n let info = txt[i].split(\" \")[0] * 1;\n doit(info, txt[i + 1].split(/[ ]/).filter(data => data.length > 0).map(dta => dta * 1));\n}\n\nfunction doit(n, tab) {\n let moves=tab[0]-1;\n for (let i = 0; i < tab.length-1; i++) {\n if(tab[i+1]>=tab[i]){\n moves+=tab[i+1]-tab[i];\n }else{\n moves+=tab[i+1]-1;\n moves+=(n%tab[i])+1;\n }\n \n }\n console.log(moves);\n \n}"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i += 2) {\n let info = txt[i].split(\" \")[0] * 1;\n doit(info, txt[i + 1].split(/[ ]/).filter(data => data.length > 0).map(dta => dta * 1));\n}\n\nfunction doit(n, tab) {\n let moves = tab[0] - 1;\n for (let i = 0; i < tab.length - 1; i++) {\n if (tab[i + 1] >= tab[i]) {\n moves += tab[i + 1] - tab[i];\n } else {\n moves += tab[i + 1] + (n % tab[i]);\n }\n\n }\n console.log(moves);\n\n}"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], m = +input[1], a = readline().split(\" \"), i = 1, j = 0, time = 0;\n\nfor( ; j != m ; i++, time++){\n\twrite(i,j,time + \"\\n\");\n\tif(i == +a[j]){\n\t\tj++;\n\t\tfor( ; ; ){\n\t\t\tif(i == +a[j]){\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif(i == n){\n\t\ti = 0;\n\t}\n}\n\nwrite(time-1);"}, {"source_code": "var meta = readline().split(' ').map((as)=> parseInt(as))\nvar time = 0, res = 0, start = 1\nreadline().split(' ').map((c)=> parseInt(c)).forEach((val)=>{\n\tres = val - start;\n\tif (res < 0){\n\t\ttime += (meta[0] - val) + Math.abs(res)\n\t}\n\telse{\n\t\ttime += val - start\n\t}\n\tstart = val\n})\nprint(time)\n"}, {"source_code": ";(function () {\n\n\tvar x = 0,\n\n\t\tn = +readline().split(' ')[0],\n\n\t\ts = readline()\n\t\t\t.split(' ')\n\t\t\t.map(function (i) {return +i;})\n\t\t\t.filter(function (e, i, a) { return (i == a.length - 1) || a[i] != a[i+1]; }),\n\n\t\tstep = (function (n) {\n\t\t\tvar i = 1;\n\t\t\treturn function () {\n\t\t\t\tx++;\n\t\t\t\ti = n == i ? 1 : i+1;\n\t\t\t\treturn i;\n\t\t\t}\n\t\t})(n);\n\n\tif (s[0] == 1) s.slice(0,1);\n\n\tfor (var i = 0; i < s.length; i++)\n\t\twhile (step() != s[i]);\n\n\tprint(x);\n\n}).call(this);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;icur) t+=parseInt(m[i]-cur);\n cur=m[i];\n \n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;icur) t+=(m[i]-cur);\n cur=i;\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;icur) t+=(m[i]-cur);\n cur=m[i];\n \nprint(t);\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\nfor(var i=0;i=cur) t+=m[i]-cur;\n cur=m[i];\n \n//ts+=' '+t;\n}\nprint(ts);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;icur) t+=(m[i]-cur);\n cur=m[i];\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;i=cur) t+=(m[i]-cur);\n cur=i;\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\nfor(var i=0;icur) t+=m[i]-cur;\n cur=m[i];\n \nts+=' '+t;\n}\nprint(ts);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\nfor(var i=0;icur) t+=parseInt(m[i]-cur);\n cur=m[i];\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\n\nvar cur=1,t=0;\nfor(var i=0;icur) t+=(m[i]-cur);\n cur=i;\n}\nprint(t);"}, {"source_code": "var l1=readline().split(' ');\nvar l2=readline().split(' ');\nvar n=parseInt(l1[0]);\nvar m=l2;\nfor(var i=0;icur) t+=m[i]-cur;\n cur=m[i];\n \nprint(t);\n}\nprint(t);"}, {"source_code": "var n = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar diff = a[0] - 1;\nfor (var i = 0; i < a.length - 1; i++) {\n\tdiff += ((a[i+1] >= a[i]) ? (a[i+1] - a[i]) : (n - a[i+1] + a[i] - 2));\n}\nprint (diff);"}, {"source_code": "var n = readline().split(\" \").map(function(x) { return parseInt(x); })[1];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar diff = a[0] - 1;\nfor (var i = 0; i < a.length - 1; i++) {\n\tdiff += ((a[i+1] >= a[i]) ? (a[i+1] - a[i]) : (a.length - a[i+1] + a[i] - 1));\n}\nprint (diff);"}, {"source_code": "var ringRoad = function(n, arr)\n {\n var counter = arr[0] - 1; \n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] > arr[i - 1])\n {\n counter += arr[i] - arr[i - 1];\n continue;\n }\n else {\n\t\t\t\t\t//if (arr[i - 1] !== n)\n counter += n - arr[i - 1] + arr[i];\n\t\t\t\t\t//else counter += 1;\n }\n }\n\t\t\treturn counter;\n }\n var toNumArr = function(str)\n {\n str = str.split(' ');\n for (var i = 0 ; i <= str.length - 1; i++)\n {\n str[i] = +str[i];\n }\n return str;\n }\n var num = toNumArr(readline());\n var input = toNumArr(readline());\n print(ringRoad(num[0], input));"}, {"source_code": " var ringRoad = function(n, arr)\n {\n arr.unshift(1);\n var counter = 0; \n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] >= arr[i - 1])\n {\n counter += arr[i] - arr[i - 1];\n \n \n continue;\n }\n else {\n\t\t\t\t\tif (arr[i - 1] !== n)\n counter += n - arr[i - 1] + i;\n\t\t\t\t\telse counter += 1;\n }\n }\n\t\t\treturn counter;\n }\n var toNumArr = function(str)\n {\n str = str.split(' ');\n for (var i = 0 ; i <= str.length - 1; i++)\n {\n str[i] = +str[i];\n }\n return str;\n }\n var num = toNumArr(readline());\n var input = toNumArr(readline());\n print(ringRoad(num[0], input));"}, {"source_code": "a =readline().split(' ');\nb =readline().split(' ');\nd = b[0]-1;\nfor (i=1;i0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n for(i=x;l&&L[l-1]>t;--l){\n i=P[l-1];\n s=L[l-1]*(x-i);\n if(x>X&&X>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(x-i);\n if(x>X&&X>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]1024&&A[l]>=h;l-=1024);\n for(;r=h;r+=1024);\n s=(r-l-1024>>10)*h;\n if(s>M)M=s;\n h=A[l]|0; if(A[r]>h)h=A[r];\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n sw(Al,W+(Y<<10),i);\n sw(Ar,W+(Y<<10),(Y<<10)+W+1-X);\n sw(Au,H+(X<<10),(X<<10)+Y);\n sw(Ad,H+(X<<10),(X<<10)+H+1-Y);\n }\n else if(Al[i]){\n M=0;\n max(Al,H,i);\n max(Ar,H,(Y<<10)+W+1-X);\n max(Au,W,(X<<10)+Y);\n max(Ad,W,(X<<10)+H+1-Y);\n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20; P=[]; L=[];\nW=+t[0]; H=+t[1]|0; Q=+t[2]; out='';\nAu=Array(MAX);\nAl=Array(MAX);\nAd=Array(MAX);\nAr=Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y)\n Al[(y<<10)+x]=Au[(x<<10)+y]=Ar[(y<<10)+W+1-x]=Ad[(x<<10)+H+1-y]=t[y-1]|0;\n}\nfunction calc(A,W,H){\n var x,y,t,i;\n for(y=1;y<=H;++y){\n i=(y<<10)+1; t=A[i];\n for(++i,x=2;x<=W;++x,++i){\n if(A[i])A[i]=++t;\n else t=0;\n }\n }\n}\ncalc(Au,H,W);\ncalc(Ad,H,W);\ncalc(Al,W,H);\ncalc(Ar,W,H);\nfunction sw(A,W,x,i){\n var t=A[i]=A[i]?0:(A[i-1]|0)+1;\n for(;++x<=W&&A[++i];)A[i]=++t;\n}\nfunction max(A,H,X,Y){\n var l=0,s,y,t,i; ++H;\n for(y=1;y<=H;++y){\n t=A[(y<<10)+X]|0;\n for(i=y;l&&L[l-1]>t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t){\n s=L[0]*(x-P[0]);\n if(x>X&&X>=P[0]&&s>M)M=s;\n L[0]=t;\n }\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t){\n s=L[0]*(x-P[0]);\n if(x>X&&X>=P[0]&&s>M)M=s;\n L[0]=t;\n }\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t){\n s=L[0]*(y-P[0]);\n if(y>Y&&Y>=P[0]&&s>M)M=s;\n L[0]=t;\n }\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t){\n s=L[0]*(y-P[0]);\n if(y>Y&&Y>=P[0]&&s>M)M=s;\n L[0]=t;\n }\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20;\nW=t[0]|0; H=t[1]|0; Q=t[2]|0; out='';\nAu=new Array(MAX);\nAl=new Array(MAX);\nAd=new Array(MAX);\nAr=new Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n Au[i]=Al[i]=Ad[i]=Ar[i]=t[y-1]|0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=Au[(1<<10)+x],y=2;y<=H;++y){\n i=(y<<10)+x;\n if(Au[i])Au[i]=++t;\n else t=0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=Ad[(H<<10)+x],y=H-1;y>0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n if(!l&&t||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[(Y<<10)+x]|0;\n if(!l&&t||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(!l&&t||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(!l&&t||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20;\nW=+t[0]; H=+t[1]; Q=+t[2]; out='';\nAu=new Array(MAX);\nAl=new Array(MAX);\nAd=new Array(MAX);\nAr=new Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n Au[i]=Al[i]=Ad[i]=Ar[i]=+t[y-1];\n }\n}\nfor(y=2;y<=H;++y){\n for(x=1;x<=W;++x){\n i=(y<<10)+x;\n if(Au[i])Au[i]+=Au[(y-1<<10)+x];\n }\n}\nfor(y=H-1;y>0;--y){\n for(x=1;x<=W;++x){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]+=Ad[(y+1<<10)+x];\n }\n}\nfor(x=2;x<=W;++x){\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n if(Al[i])Al[i]+=Al[i-1];\n }\n}\nfor(x=W-1;x>0;--x){\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]+=Ar[i+1];\n }\n}\nfor(q=0;q0&&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=Ad[(y+1<<10)+X]+1;\n \n Al[(Y<<10)+X]=Al[(Y<<10)+X]?0:(Al[(Y<<10)+X-1]|0)+1;\n for(x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=Al[(Y<<10)+x-1]+1;\n \n Ar[(Y<<10)+X]=Ar[(Y<<10)+X]?0:(Ar[(Y<<10)+X+1]|0)+1;\n for(x=X-1;x>0&&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=Ar[(Y<<10)+x+1]+1;\n }\n else if(Au[(Y<<10)+X]){\n L=[]; P=[]; M=0; l=0;\n i=Y<<10;\n for(x=1;x<=W+1;++x){\n t=Au[i+x]|0;\n if(!l||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[i+x]|0;\n if(!l||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(!l||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(!l||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);"}, {"source_code": "space=/\\s+/; t=readline().split(space); MAX=1<<20;\nW=t[0]|0; H=t[1]|0; Q=t[2]|0; out='';\nAu=new Array(MAX);\nAl=new Array(MAX);\nAd=new Array(MAX);\nAr=new Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(space);\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n Au[i]=Al[i]=Ad[i]=Ar[i]=t[y-1]|0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=0,y=2;y<=H;++y){\n i=(y<<10)+x;\n if(Au[i])Au[i]=++t;\n else t=0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=0,y=H-1;y>0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=0,x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=0,x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(space);\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n if(!l&&t||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[(Y<<10)+x]|0;\n if(!l&&t||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(!l&&t||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(!l&&t||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20; P=[]; L=[];\nW=+t[0]; H=+t[1]; Q=+t[2]; out='';\nAu=Array(MAX);\nAl=Array(MAX);\nAd=Array(MAX);\nAr=Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y)\n Al[(y<<10)+x]=Au[(x<<10)+y]=Ar[(y<<10)+W+1-x]=Ad[(x<<10)+H+1-y]=t[y-1]|0;\n}\nfunction calc(A,W,H){\n var y,t,i,w;\n for(y=1;y<=H;++y){\n A[i=y<<10]=0;\n t=A[++i];\n w=i+W;\n for(++i;i1024&&A[l]>=h;l-=1024);\n for(;r=h;r+=1024);\n s=(r-l-1024>>10)*h;\n if(s>M)M=s;\n h=A[l]; if(A[r]>h)h=A[r];\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n sw(Al,W+(Y<<10),i);\n sw(Ar,W+(Y<<10),(Y<<10)+W+1-X);\n sw(Au,H+(X<<10),(X<<10)+Y);\n sw(Ad,H+(X<<10),(X<<10)+H+1-Y);\n }\n else if(Al[i]){\n M=0;\n max(Al,H,i);\n max(Ar,H,(Y<<10)+W+1-X);\n max(Au,W,(X<<10)+Y);\n max(Ad,W,(X<<10)+H+1-Y);\n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "space=/\\s+/; t=readline().split(space); MAX=1<<20;\nW=t[0]|0; H=t[1]|0; Q=t[2]|0; out='';\nAu=new Array(MAX);\nAl=new Array(MAX);\nAd=new Array(MAX);\nAr=new Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(space);\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n Au[i]=Al[i]=Ad[i]=Ar[i]=t[y-1]|0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=Au[(1<<10)+x],y=2;y<=H;++y){\n i=(y<<10)+x;\n if(Au[i])Au[i]=++t;\n else t=0;\n }\n}\nfor(x=1;x<=W;++x){\n for(t=Ad[(H<<10)+x],y=H-1;y>0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(space);\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20;\nW=+t[0]; H=+t[1]; Q=+t[2]; out='';\nAu=new Array(MAX);\nAl=new Array(MAX);\nAd=new Array(MAX);\nAr=new Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n Au[i]=Al[i]=Ad[i]=Ar[i]=+t[y-1];\n }\n}\nfor(y=2;y<=H;++y){\n for(x=1;x<=W;++x){\n i=(y<<10)+x;\n if(Au[i])Au[i]+=Au[(y-1<<10)+x];\n }\n}\nfor(y=H-1;y>0;--y){\n for(x=1;x<=W;++x){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]+=Ad[(y+1<<10)+x];\n }\n}\nfor(x=2;x<=W;++x){\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n if(Al[i])Al[i]+=Al[i-1];\n }\n}\nfor(x=W-1;x>0;--x){\n for(y=1;y<=H;++y){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]+=Ar[i+1];\n }\n}\nfor(q=0;q0&&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=Ad[(y+1<<10)+X]+1;\n \n Al[(Y<<10)+X]=Al[(Y<<10)+X]?0:(Al[(Y<<10)+X-1]|0)+1;\n for(x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=Al[(Y<<10)+x-1]+1;\n \n Ar[(Y<<10)+X]=Ar[(Y<<10)+X]?0:(Ar[(Y<<10)+X+1]|0)+1;\n for(x=X-1;x>0&&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=Ar[(Y<<10)+x+1]+1;\n }\n else if(Au[(Y<<10)+X]){\n L=[]; P=[]; M=0; l=0;\n i=Y<<10;\n for(x=1;x<=W+1;++x){\n t=Au[i+x]|0;\n if(!l||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[i+x]|0;\n if(!l||L[l-1]<=t)P[l]=x,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(!l||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(!l||L[l-1]<=t)P[l]=y,L[l++]=t;\n else{\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}, {"source_code": "t=readline().split(' '); MAX=1<<20; P=[]; L=[];\nW=+t[0]; H=+t[1]|0; Q=+t[2]; out='';\nAu=Array(MAX);\nAl=Array(MAX);\nAd=Array(MAX);\nAr=Array(MAX);\nfor(x=1;x<=W;++x){\n t=readline().split(' ');\n for(y=1;y<=H;++y)\n Al[(y<<10)+x]=Au[(x<<10)+y]=Ar[(y<<10)+W+1-x]=Ad[(x<<10)+H+1-y]=t[y-1]|0;\n}\nfunction calc(A,W,H){\n var x,y,t,i;\n for(y=1;y<=H;++y){\n i=(y<<10)+1; t=A[i];\n for(++i,x=2;x<=W;++x,++i){\n if(A[i])A[i]=++t;\n else t=0;\n }\n }\n}\ncalc(Au,H,W);\ncalc(Ad,H,W);\ncalc(Al,W,H);\ncalc(Ar,W,H);\nfunction sw(A,W,x,i){\n var t=A[i]=A[i]?0:(A[i-1]|0)+1;\n for(;++x<=W&&A[++i];)A[i]=++t;\n}\nfunction max(A,H,X,Y){\n var l=0,s,y,t,i; ++H;\n for(y=1;y<=H;++y){\n t=A[(y<<10)+X]|0;\n for(i=y;l&&L[l-1]>t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n for(i=x;l&&L[l-1]>t;--l){\n i=P[l-1];\n s=L[l-1]*(x-i);\n if(x>X&&X>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(x-i);\n if(x>X&&X>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]t;--l){\n i=P[l-1];\n s=L[l-1]*(y-i);\n if(y>Y&&Y>=i&&s>M)M=s;\n }\n if(t&&(!l||L[l-1]0;--y){\n i=(y<<10)+x;\n if(Ad[i])Ad[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Al[(y<<10)+1],x=2;x<=W;++x){\n i=(y<<10)+x;\n if(Al[i])Al[i]=++t;\n else t=0;\n }\n}\nfor(y=1;y<=H;++y){\n for(t=Ar[(y<<10)+W],x=W-1;x>0;--x){\n i=(y<<10)+x;\n if(Ar[i])Ar[i]=++t;\n else t=0;\n }\n}\nfor(;Q--;){\n t=readline().split(' ');\n X=t[1]|0; Y=t[2]|0; i=(Y<<10)+X;\n if(t[0]==='1'){\n if(Au[i])Au[i]=Ad[i]=Al[i]=Ar[i]=0;\n else{\n Au[i]=(Au[(Y-1<<10)+X]|0)+1;\n Ad[i]=(Ad[(Y+1<<10)+X]|0)+1;\n Al[i]=(Al[(Y<<10)+X-1]|0)+1;\n Ar[i]=(Ar[(Y<<10)+X+1]|0)+1;\n }\n for(t=Au[i],y=Y+1;y<=H&&Au[(y<<10)+X];++y)Au[(y<<10)+X]=++t;\n for(t=Ad[i],y=Y-1;y>0 &&Ad[(y<<10)+X];--y)Ad[(y<<10)+X]=++t;\n for(t=Al[i],x=X+1;x<=W&&Al[(Y<<10)+x];++x)Al[(Y<<10)+x]=++t;\n for(t=Ar[i],x=X-1;x>0 &&Ar[(Y<<10)+x];--x)Ar[(Y<<10)+x]=++t;\n }\n else if(Au[i]){\n L=[]; P=[]; M=0; l=0;\n for(x=1;x<=W+1;++x){\n t=Au[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t)L[0]=t;\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(x=1;x<=W+1;++x){\n t=Ad[(Y<<10)+x]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t)L[0]=t;\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(x-P[l-1]);\n if(x>X&&X>=P[l-1]&&s>M)M=s;\n }\n }\n }\n\n l=0;\n for(y=1;y<=H+1;++y){\n t=Al[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t)L[0]=t;\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n l=0;\n for(y=1;y<=H+1;++y){\n t=Ar[(y<<10)+X]|0;\n if(t&&(!l||L[l-1]<=t)){\n if(!l||L[l-1]t)L[0]=t;\n for(;l&&L[l-1]>t;--l){\n s=L[l-1]*(y-P[l-1]);\n if(y>Y&&Y>=P[l-1]&&s>M)M=s;\n }\n }\n }\n \n out+=M+'\\n';\n }\n else out+='0\\n';\n}\nprint(out);\n"}], "src_uid": "895288258973317696185910fca8e32e"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i] = i + 1;\r\n\t\t}\r\n\t\tvar output = [myconv(list, 8)];\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tvar tmp = list[i];\r\n\t\t\tlist[i] = list[i + 1];\r\n\t\t\tlist[i + 1] = tmp;\r\n\t\t\toutput.push(myconv(list, 8));\r\n\t\t}\r\n\t\tmyout(output.length);\r\n\t\tmyout(myconv(output, 9));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n myFunc(n);\r\n // const arr = readLine().split(' ').map(p => +p);\r\n // let result = myFunc(n);\r\n // console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n){\r\n \r\n let arr = [];\r\n for(let i = 0; i < n; i++){\r\n arr[i] = i+1;\r\n }\r\n\r\n console.log(n);\r\n console.log(...arr);\r\n\r\n for(let i = 1; i < n; i++){\r\n [arr[i-1], arr[i]] = [arr[i], arr[i-1]]\r\n console.log(...arr);\r\n }\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n output(n);\r\n\r\n let arr = [];\r\n for (let i = 1; i <= n; i++) {\r\n arr.push(i);\r\n }\r\n\r\n let left = 0;\r\n let right = 1;\r\n output(arr.join(' '));\r\n for (let i = 1; i < n; i++) {\r\n [arr[left], arr[right]] = [arr[right], arr[left]];\r\n right++;\r\n output(arr.join(' '));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = new Array();\r\n for (var j = 1; j <= caseLength; j++)\r\n {\r\n caseArray.push(j);\r\n }\r\n print(caseLength);\r\n for (var j = 0; j < caseLength; j++)\r\n {\r\n if (j !== 0)\r\n {\r\n caseArray[j-1] = caseArray[j];\r\n caseArray[j] = 1\r\n }\r\n var result = \"\";\r\n for (var k = 0; k < caseLength; k++)\r\n {\r\n result += `${caseArray[k]} `;\r\n }\r\n print(result);\r\n }\r\n}"}, {"source_code": "var n;\r\n var arr;\r\n var tests = parseInt(readline());\r\n for (var t=0; t a + b);\r\n {\r\n let sum = 0,\r\n flag = false;\r\n for (let i = 0; i < n ; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n if (flag && sum !== 0) return 'NO';\r\n if (sum === 0) flag = true;\r\n }\r\n if(sum!==0)return 'NO'\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if (sum !== 0) return 'NO';\r\n //if (n <= 2) return 'YES';\r\n {\r\n let sum = 0,\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n if (flag && sum !== 0) return 'NO';\r\n if (sum === 0) flag = true;\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var a = lines[i].split(' ').map(Number);\n var flag = false;\n var x = 0;\n for(j = 0; j < n; j++){\n if(a[j] + x < 0){\n flag = true;\n }\n if(j && a[j] > 0 && x === 0){\n flag = true;\n }\n x = a[j] + x;\n }\n if(x !== 0){\n flag = true;\n }\n if(flag){\n console.log('NO');\n }else{\n console.log('YES');\n }\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let size = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n let jumpsToTheRight = new Array(size).fill(0);\r\n jumpsToTheRight[0] = arr[0];\r\n let sum = arr[0];\r\n for (let index = 1; index < jumpsToTheRight.length; index++) {\r\n jumpsToTheRight[index] = arr[index] + jumpsToTheRight[index - 1];\r\n sum += arr[index];\r\n }\r\n\r\n let result = 'yes';\r\n let zero = false;\r\n for (let jumps of jumpsToTheRight) {\r\n if (jumps < 0) {\r\n result = 'no';\r\n break;\r\n } else if (jumps === 0) {\r\n zero = true;\r\n } else if (zero) {\r\n result = 'no';\r\n break;\r\n }\r\n }\r\n\r\n if (sum !== 0) {\r\n result = 'no';\r\n }\r\n\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if(sum!==0) return 'NO'\r\n while(a.length && !a[a.length-1])a.pop()\r\n if(a[0]){\r\n while(a.length>1){\r\n const last=a.length-1\r\n if(a[last]>=0)return 'NO'\r\n a[last-1]+=a.pop()\r\n }\r\n }else if(a.length){\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if(sum!==0) return 'NO'\r\n while(a.length && !a[a.length-1])a.pop()\r\n if(a[0]){\r\n while(a.length>1){\r\n const last=a.length-1\r\n if(a[last]>0)return 'NO'\r\n a[last-1]+=a.pop()\r\n }\r\n }else if(a.length){\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if(sum!==0) return 'NO'\r\n while(a.length && !a[a.length-1])a.pop()\r\n if(a[0]){\r\n while(a.length>1){\r\n console.log(a)\r\n const last=a.length-1\r\n if(a[last]>0)return 'NO'\r\n a[last-1]+=a.pop()\r\n }\r\n }else if(a.length){\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if(sum!==0) return 'NO'\r\n a.reverse()\r\n while(a.length>1){\r\n const last=a.length-1\r\n if(a[last]<0 || a[last] str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if(sum!==0)return 'NO'\r\n {\r\n let sum = 0\r\n for (let i = 0; i < n ; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n {\r\n let sum = 0,\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n if (flag && sum !== 0) return 'NO';\r\n if (sum === 0) flag = true;\r\n }\r\n if(sum!==0)return 'NO'\r\n }\r\n \r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n {\r\n let sum = 0,\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n if (flag && sum !== 0) return 'NO';\r\n if (sum === 0) flag = true;\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b);\r\n if (sum !== 0) return 'NO';\r\n if (n <= 2) return 'YES';\r\n {\r\n let sum = 0,\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n sum += a[i];\r\n if (sum < 0) return 'NO';\r\n if (flag && sum !== 0) return 'NO';\r\n if (sum === 0) flag = true;\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "9f0ffcbd0ce62a365a1ecbb4a2c1de3e"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solve_one_test() {\n let n = parseInt(readline());\n let array = readline().split(\" \").map(x => parseInt(x));\n // console.log(array);\n\n let low = 0;\n let high = 1e9 + 1;\n\n while (low + 1 != high) {\n let mid = Math.floor((low + high) / 2);\n\n function can_do(min_element) {\n carry = 0;\n carry_next = 0;\n\n for (let i = n - 1; i >= 0; --i) {\n let need_move = Math.floor((array[i] + carry - min_element) / 3);\n need_move = Math.min(need_move, Math.floor(array[i] / 3));\n\n if (i <= 1) {\n need_move = 0;\n }\n\n if (need_move < 0) {\n need_move = 0;\n }\n\n if (array[i] + carry - need_move * 3 < min_element) {\n return false;\n }\n\n carry = carry_next;\n carry_next = 0;\n\n carry += need_move;\n carry_next += need_move * 2;\n }\n\n if (carry > 0 || carry_next > 0) {\n return false;\n }\n\n return true;\n };\n\n if (can_do(mid)) {\n low = mid;\n } else {\n high = mid;\n }\n }\n\n console.log(low)\n}\n\nfunction main() {\n let num_tests = parseInt(readline());\n\n for (let i = 0; i < num_tests; ++i) {\n solve_one_test();\n }\n}\n", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const h = (await getLine()).split(' ').map(num => parseInt(num));\r\n let l = 0, r = 0;\r\n let best = 0;\r\n for(let i = 0; i < n; i++)\r\n r = Math.max(r, h[i]);\r\n const workh = new Array(n);\r\n\r\n const resolve = function(th) {\r\n for(let i = 0; i < n; i++)\r\n workh[i] = 0;\r\n\r\n for(let i = n - 1; i >=0; i--) {\r\n if (h[i] + workh[i] < th)\r\n return false;\r\n const rem = h[i] + workh[i] - th;\r\n if (i>=2) {\r\n workh[i - 1] += Math.floor(Math.min(h[i], rem) / 3);\r\n workh[i - 2] += Math.floor(Math.min(h[i], rem) / 3) * 2;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n while (l <= r) {\r\n const mid = Math.floor((l+r) / 2);\r\n if (resolve(mid)) {\r\n best = mid;\r\n l = mid + 1;\r\n } else {\r\n r = mid - 1;\r\n }\r\n }\r\n\r\n console.log(best);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst h = rna();\r\n\r\n\t\tfunction check (x) {\r\n\t\t\tconst hh = h.slice();\r\n\t\t\tfor (let i = n-1; i >= 2; i--) {\r\n\t\t\t\tif (hh[i] < x) \r\n\t\t\t\t\treturn false;\r\n\t\t\t\tlet d = Math.floor((hh[i]-x)/3);\r\n\t\t\t\td = Math.min(Math.floor(h[i]/3), d);\r\n\t\t\t\thh[i] -= 3*d;\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += 2*d;\r\n\t\t\t}\r\n\t\t\treturn hh[0] >= x && hh[1] >= x;\r\n\t\t}\r\n\r\n\t\tlet l = 1, r = 1e9;\r\n\t\twhile (r-l > 1) {\r\n\t\t\tlet m = l + r >> 1;\r\n\t\t\tif (check(m)) {\r\n\t\t\t\tl = m;\r\n\t\t\t} else {\r\n\t\t\t\tr = m-1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = check(r) ? r : l;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const h = (await getLine()).split(' ').map(num => parseInt(num));\r\n let l = 0, r = 0;\r\n let best = 0;\r\n for(let i = 0; i < n; i++)\r\n r = Math.max(r, h[i]);\r\n const workh = new Array(n);\r\n\r\n const resolve = function(th) {\r\n for(let i = 0; i < n; i++)\r\n workh[i] = 0;\r\n\r\n for(let i = n - 1; i >=0; i--) {\r\n if (h[i] + workh[i] < th)\r\n return false;\r\n const rem = h[i] + workh[i] - th;\r\n if (i > 0) {\r\n workh[i-1] += Math.floor(Math.min(h[i], rem)/3);\r\n }\r\n if (i > 1)\r\n workh[i-2] += Math.floor(Math.min(h[i], rem)/3) * 2;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n while (l <= r) {\r\n const mid = Math.floor((l+r) / 2);\r\n if (resolve(mid)) {\r\n best = mid;\r\n l = mid + 1;\r\n } else {\r\n r = mid - 1;\r\n }\r\n }\r\n\r\n console.log(best);\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "895d5850e420a36ae3b5f0a50e359423"} {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n if (n === 1) {\n print(\"FastestFinger\");\n continue;\n }\n if (n % 2 || n === 2) {\n print(\"Ashishgup\");\n continue;\n }\n check(n);\n }\n}\n\nfunction check(n) {\n var m = n;\n while (m > 1 && m % 2 === 0) {\n m = m / 2;\n }\n if (m === 1 || (n / m === 2 && isSimple(m))) {\n print(\"FastestFinger\");\n return;\n }\n print(\"Ashishgup\");\n}\n\nfunction isSimple(n) {\n var sq = Math.floor(Math.sqrt(n)) + 1;\n for (var k = 3; k < sq; k += 2) {\n if (n % k === 0) {\n return false;\n }\n }\n return true;\n}\nmain();\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var tests = parseInt(lines.shift(), 10);\n while (tests--) {\n var n = parseInt(lines.shift(), 10);\n var ans = (function (n) {\n if (n == 1) {\n return 1;\n }\n if (n === 2) {\n return 0;\n }\n if (n % 2 === 1) {\n return 0;\n }\n if ((n & (n - 1)) === 0) {\n return 1;\n }\n var twoCount = 0;\n while (n % 2 === 0) {\n n /= 2;\n twoCount++;\n }\n if (twoCount > 1) {\n return 0;\n }\n return isPrime(n) ? 1 : 0;\n })(n);\n console.log(['Ashishgup', 'FastestFinger'][ans]);\n }\n});\nfunction isPrime(n) {\n for (var i = 3; i * i <= n; i += 2) {\n if (n % i === 0) {\n return false;\n }\n }\n return true;\n}\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "function findPrimeFactors (num) {\n\n var primeFactors = [];\n while (num % 2 === 0) {\n primeFactors.push(2);\n num = num / 2;\n }\n\n var sqrtNum = Math.sqrt(num);\n for (var i = 3; i <= sqrtNum; i++) {\n while (num % i === 0) {\n primeFactors.push(i);\n num = num / i;\n }\n }\n\n if (num > 2) {\n primeFactors.push(num);\n }\n return primeFactors;\n}\n\nconst processData = (lines) => {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i 1) {\n console.log('Ashishgup')\n } else {\n if (nonTwos > 1) {\n console.log('Ashishgup')\n } else {\n console.log('FastestFinger')\n }\n }\n }\n }\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nlet checkOddFactor = (n) => {\n let i = 2;\n let oddNum = 1;\n while(i*i <= n){\n if(n%i === 0){\n if(i%2 !== 0){\n oddNum *= i;\n }else if((n/i)%2 !== 0){\n oddNum *= (n/i);\n }\n }\n i++;\n }\n return oddNum;\n}\n\nlet checkPrime = (n) => {\n let i = 2;\n while(i*i <= n){\n if(n%i === 0)\n return false;\n i++;\n }\n\n return true;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let winner = '';\n\n if(n === 1){\n winner = 1;\n }else if(n === 2){\n winner = 0;\n }\n else if(n%2 !== 0){\n winner = 0;\n }else{\n let x = (n & (n-1));\n if(n % 4 === 0 && x !== 0){\n winner = 0;\n }else if(x === 0){\n winner = 1;\n }else{\n if(checkPrime(n/2)){\n winner = 1;\n }else{\n winner = 0;\n }\n }\n }\n\n console.log(winner === 0 ? 'Ashishgup' : 'FastestFinger');\n }\n}"}], "negative_code": [{"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n if (n === 1) {\n print(\"FastestFinger\");\n continue;\n }\n if (n % 2 || n === 2) {\n print(\"Ashishgup\");\n continue;\n }\n check(n);\n }\n}\n\nfunction check(n) {\n var m = n;\n while (m > 1 && m % 2 === 0) {\n m = m / 2;\n }\n if (m === 1 || n / m === 2) {\n print(\"FastestFinger\");\n return;\n }\n print(\"Ashishgup\");\n}\nmain();"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nlet checkOddFactor = (n) => {\n let i = 2;\n while(i*i <= n){\n if(n%i === 0 && (i%2 !== 0 || (n/i)%2 !== 0)){\n return i%2 !== 0 ? i : n/(n/i);\n }\n i++;\n }\n return n;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let turn = 0;\n let winner = '';\n while(n > 1){\n if(n%2 !== 0){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';\n break;\n }else{\n let x = checkOddFactor(n);\n if(x === n){\n if(n === 2){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger'; \n }else{\n winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';\n }\n break;\n }\n n = x;\n }\n turn = turn === 0 ? 1 : 0;\n }\n\n if(winner === ''){\n console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');\n }else{\n console.log(winner);\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nlet checkOddFactor = (n) => {\n let i = 2;\n while(i*i <= n){\n if(n%i === 0 && i%2 !== 0)\n return n/i;\n i++;\n }\n return n;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let turn = 0;\n let winner = '';\n while(n > 1){\n if(n%2 !== 0){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';\n break;\n }else{\n let x = checkOddFactor(n);\n if(x === n){\n if(n === 2){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger'; \n }else{\n winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';\n }\n break;\n }\n n = x;\n }\n turn = turn === 0 ? 1 : 0;\n }\n\n if(winner === ''){\n console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');\n }else{\n console.log(winner);\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nlet checkOddFactor = (n) => {\n let i = 2;\n while(i*i <= n){\n if(n%i === 0 && (i%2 !== 0 || (n/i)%2 !== 0)){\n return i%2 !== 0 ? n/i : n/(n/i);\n }\n i++;\n }\n return n;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let turn = 0;\n let winner = '';\n while(n > 1){\n if(n%2 !== 0){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';\n break;\n }else{\n let x = checkOddFactor(n);\n if(x === n){\n if(n === 2){\n winner = turn === 0 ? 'Ashishgup' : 'FastestFinger'; \n }else{\n winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';\n }\n break;\n }\n n = x;\n }\n turn = turn === 0 ? 1 : 0;\n }\n\n if(winner === ''){\n console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');\n }else{\n console.log(winner);\n }\n }\n}"}], "src_uid": "b533572dd6d5fe7350589c7f4d5e1c8c"} {"source_code": "var line = readline();\nvar total = 0;\nvar increment = 0;\nvar n = 1000000007;\nfor (var i = 0; i < line.length; i++){\n if (line[i] == \"a\")\n increment = (2 * increment + 1) % n;\n else\n total = (total + increment) % n;\n}\n\n/*\nvar newStr = ['b','b','a'];\nvar str = [];\nfor (var i = 0; i < line.length; i++)\n str[i] = line[i];\n\nif (str.length > 1){\n for (var i = 1; i < str.length; i++){\n if (str[i] == 'b' && str[i - 1] == 'a'){\n //str = str.slice(0, i - 1).concat(newStr).concat(str.slice(i + 1));\n str = str.\n total++;\n i-=2;\n }\n }\n}\n*/\nprint(total);", "positive_code": [{"source_code": "var s = readline();\nvar count = 0;\nvar countb = 0;\nfor (var i=s.length-1; i>=0; i--){\n\tif (s[i] == 'b') countb++;\n\telse {\n\t\tcount += countb; \n\t\tcountb *= 2; \n\t\tcount %= 1000000007;\n\t\tcountb %= 1000000007;\n\t}\n}\nprint (count);"}, {"source_code": "var s = readline();\nvar count = 0;\nvar countb = 0;\nvar counta = 0;\nfor (var i=s.length-1; i>=1; i--){\n\tif (s[i] == 'b' && s[i-1] == 'b') countb++;\n\tif (s[i] == 'b' && s[i-1] == 'a') {\n\t\tcountb++;\n\t\tcount += countb;\n\t\tcount %= 1000000007;\n\t\tcountb %= 1000000007;\n\t}\n\tif (s[i] == 'a' && s[i-1] == 'a') {\n\t\tcountb *= 2;\n\t\tcount += countb;\n\t\tcount %= 1000000007;\n\t\tcountb %= 1000000007;\n\t}\n\tif (s[i] == 'a' && s[i-1] == 'b') {\n\t\tcountb *= 2;\n\t}\n}\nprint (count%1000000007);"}], "negative_code": [{"source_code": "var line = readline();\nvar total = 0;\nvar increment = 0;\nfor (var i = 0; i < line.length; i++){\n if (line[i] == \"a\")\n increment = 2 * increment + 1;\n else\n total += increment;\n}\n\n/*\nvar newStr = ['b','b','a'];\nvar str = [];\nfor (var i = 0; i < line.length; i++)\n str[i] = line[i];\n\nif (str.length > 1){\n for (var i = 1; i < str.length; i++){\n if (str[i] == 'b' && str[i - 1] == 'a'){\n //str = str.slice(0, i - 1).concat(newStr).concat(str.slice(i + 1));\n str = str.\n total++;\n i-=2;\n }\n }\n}\n*/\nprint(total);"}, {"source_code": "var s = readline();\nvar count = 0;\nvar countb = 0;\nvar counta = 0;\nfor (var i=s.length-1; i>=1; i--){\n\tif (s[i] == 'b' && s[i-1] == 'b') countb++;\n\tif (s[i] == 'b' && s[i-1] == 'a') {\n\t\tcountb++;\n\t\tcount += countb;\n\t}\n\tif (s[i] == 'a' && s[i-1] == 'a') {\n\t\tcountb *= 2;\n\t\tcount += countb;\n\t}\n}\nprint (count%(1000000000 + 7));"}, {"source_code": "var s = readline();\nvar count = 0;\nvar countb = 0;\nvar counta = 0;\nfor (var i=s.length-1; i>=1; i--){\n\tif (s[i] == 'b' && s[i-1] == 'b') countb++;\n\tif (s[i] == 'b' && s[i-1] == 'a') {\n\t\tcountb++;\n\t\tcount += countb;\n\t}\n\tif (s[i] == 'a' && s[i-1] == 'a') {\n\t\tcountb *= 2;\n\t\tcount += countb;\n\t}\n\tif (s[i] == 'a' && s[i-1] == 'b') {\n\t\tcountb *= 2;\n\t}\n}\nprint (count%(1000000000 + 7));"}], "src_uid": "8f52241c690ec4f9af71a52904fb19a0"} {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n) {\r\n let t = n[0]\r\n for (let s = 1; s < e; ++s) t &= n[s]\r\n return t\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(Number(e.readLine()), e.readIntegersOfLine())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = a[0];\r\n\t\tfor (const elm of a) ans &= elm;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tvar L = i;\r\n\t\t\t\tvar R = j;\r\n\t\t\t\tfor(var k = L; k <= R; k++){\r\n\t\t\t\t\tvar tmp = list[k] & list[R - k];\r\n\t\t\t\t\tlist[k] = tmp;\r\n\t\t\t\t\tlist[R - k] = tmp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tvar L = i;\r\n\t\t\t\tvar R = j;\r\n\t\t\t\tfor(var k = L; k <= R; k++){\r\n\t\t\t\t\tvar tmp = list[k] & list[R - k];\r\n\t\t\t\t\tlist[k] = tmp;\r\n\t\t\t\t\tlist[R - k] = tmp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}\r\n"}, {"source_code": "var t = parseInt(readline())\nwhile(t--){\n var n=parseInt(readline())\n var v=readline().split(' ')\n var res=v[0]\n while(--n)\n res &= v[n]\n print(res)\n}"}, {"source_code": "let inputBuffer = ''\r\nprocess.stdin.on('data', data => {\r\n\tinputBuffer += data\r\n})\r\nprocess.stdin.on('end', _ => {\r\n\tinputBuffer = inputBuffer.trim().split('\\n')\r\n\r\n\tmain()\r\n})\r\n\r\nlet currentLine = 0\r\nfunction readline() {\r\n\treturn inputBuffer[currentLine++]\r\n}\r\nfunction readint() {\r\n\treturn parseInt(readline(), 10)\r\n}\r\nfunction readints() {\r\n\treturn readline().split(' ').map(s => parseInt(s, 10))\r\n}\r\nfunction print(s) {\r\n\tprocess.stdout.write(s + '\\n')\r\n}\r\nfunction write(s) {\r\n\tprocess.stdout.write(s)\r\n}\r\n\r\nfunction range(lowerBound, upperBound = undefined, step = 1) {\r\n\tif (upperBound === undefined) {\r\n\t\tupperBound = lowerBound\r\n\t\tlowerBound = 0\r\n\t}\r\n\tlet ret = []\r\n\tfor (let i = lowerBound; i < upperBound; i += step) ret.push(i)\r\n\treturn ret\r\n}\r\nfunction loop(lowerBound, upperBound = undefined, step = 1) {\r\n\treturn (func) => {\r\n\t\trange(lowerBound, upperBound, step).forEach(i => func(i))\r\n\t}\r\n}\r\n\r\nfunction main() {\r\n\tlet t = readint()\r\n\tloop(t)(_ => {\r\n\t\treadint()\r\n\t\tprint(readints().reduce((prev, x) => prev & x))\r\n\t})\r\n}\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile(t--){\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\r\n\t\tlet ans = a[0];\r\n\t\tfor (let i = 1 ; i < n; i++)\r\n\t\t\tans &= a[i];\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile(t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\t\tconsole.log(a[n - 1]);\r\n\t}\r\n\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tvar L = i;\r\n\t\t\t\tvar R = j;\r\n\t\t\t\tfor(var k = L; k <= R; k++){\r\n\t\t\t\t\tvar tmp = list[k] & list[R - k];\r\n\t\t\t\t\tlist[k] = tmp;\r\n\t\t\t\t\tlist[R - k] = tmp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve() {\r\n return -1\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve()\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}], "src_uid": "4f8eac547bbd469a69de2f4aae4a87f0"} {"source_code": "var nk = readline().split(' ').map(Number);\nvar n = nk[0];\nvar k = nk[1];\nvar s = readline().split('');\nvar count = 0;\nfor (var i=97; i<=122; i++){\n\tif (count == k) break;\n\tfor (var j=0; j a != '0').join('');\nprint(s);", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a)return u=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{u=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return u[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0)e-=n[t],n[t]=0;else if(e-n[t]<=0){n[t]-=e;break}o.default.debug(n);let i=\"\";for(let t of r.split(\"\").reverse())n[t]>0&&(n[t]--,i=t+i);o.default.put(i)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a)return u=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{u=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return u[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0)e-=n[t],n[t]=0;else if(e-n[t]<=0){n[t]-=e;break}o.default.debug(n);let i=\"\";for(let t of r.split(\"\").reverse())n[t]>0&&(n[t]--,i=t+i);o.default.put(i)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below: \n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, k] = io.nextNumbers()\n// let s = io.readline()\n// \n// let cnt: any = {}\n// \n// for (let c of s.split(\"\").sort()) {\n// cnt[c] = cnt[c] || 0\n// cnt[c] += 1\n// }\n// \n// for (let x in cnt) {\n// if (k - cnt[x] >= 0) {\n// k -= cnt[x]\n// \n// cnt[x] = 0\n// \n// continue\n// }\n// \n// if (k - cnt[x] <= 0) {\n// cnt[x] -= k\n// break\n// }\n// }\n// \n// io.debug(cnt)\n// \n// let o = \"\"\n// \n// for (let x of s.split(\"\").reverse()) {\n// if (cnt[x] > 0) {\n// cnt[x]--\n// o = x + o\n// }\n// }\n// \n// io.put(o)\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a)return u=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{u=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return u[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0)e-=n[t],n[t]=0;else if(e-n[t]<=0){n[t]-=e;break}o.default.debug(n);for(let t of r.split(\"\").reverse())n[t]>0&&(n[t]--,o.default.put(t))}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "src_uid": "9f095a5f5b39d8c2f99c4162f2d7c5ff"} {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const x = readline();\n const x2 = readline()\n .split(\" \")\n .map((x) => +x);\n \n policeRecruits(x2);\n}\n\n\nfunction policeRecruits(array) {\n let crimeCount = 0;\n let availableCops = 0;\n\n for (let i = 0; i < array.length; i++) {\n const element = array[i];\n if (element < 0) {\n if (availableCops > 0) {\n availableCops--;\n crimeCount = Math.max(crimeCount, crimeCount - 1);\n } else {\n crimeCount++;\n }\n } else {\n availableCops += element;\n }\n }\n console.log(crimeCount);\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var ok = 0;\n var ng = 0;\n for(var i = 0; i < N; i++){\n if(list[i] > 0){\n ok += list[i];\n }else{\n if(ok > 0){\n ok--;\n }else{\n ng++;\n }\n }\n }\n myout(ng);\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet counter = 0;\n\nrl.on('line', (input) => {\n if (counter++ === 0) return;\n let line = input.split(' ');\n let inputs = [];\n line.forEach(element => {\n inputs.push(parseInt(element));\n });\n rl.close();\n console.log(solve(inputs));\n});\n\n\nconst solve = (inputs) => {\n let currentHired = 0,\n unsolved = 0;\n inputs.forEach(element => {\n if (element === -1 && currentHired === 0) unsolved++;\n else if (element === -1 && currentHired !== 0) currentHired--;\n else currentHired += element;\n });\n return unsolved;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = readline();\n let l = readline().split(' ').map(x => parseInt(x));\n let result = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += l[i];\n if (sum < 0) {\n result++;\n sum = 0;\n }\n }\n // output\n print(result);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n let cops = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > 0) {\n cops += arr[i];\n }\n else {\n if (cops === 0) {\n ans++;\n }\n else {\n cops = Math.max(0, --cops);\n }\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n let answ = 0; let cops = 0;\n\n nums.forEach(x => {\n if (x >= 0) cops += x;\n else {\n if (cops + x < 0) answ += 1;\n else cops += x;\n }\n });\n\n console.log(answ);\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet hired=0\n\tlet untreated=0\n\tlet x=+readLine()\n\tlet order=readLine().split(\" \").map(n=>+n)/* +ve int*/\n\tfor(let i=0;i Number(num));\n\n for (i = 0; i < test; i++) {\n\n if (cases[i] > 0) {\n positive += cases[i];\n }\n else if (positive > 0) {\n positive--;\n }\n else {\n untreatedCrime++;\n }\n\n }\n return untreatedCrime.toString();\n\n}\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(v => parseInt(v));\n let current = 0;\n let ans = 0;\n for (var i = 0; i < n; i++) {\n current += arr[i];\n if (current < 0) {\n ans++;\n current = 0;\n }\n }\n console.log(ans);\n}"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var hired = 0, untreated = 0;\n readline().split(' ').forEach(function (v){\n if ( v[0] !== \"-\" ){\n hired += parseInt(v);\n }else{\n if ( hired > 0 ){\n --hired;\n }else{\n ++untreated;\n }\n }\n });\n print(untreated);\n})();"}, {"source_code": "var events = parseInt(readline());\n\nvar order = readline().split(\" \").map(x => parseInt(x));\n\nvar buffer = 0;\nvar crimes = 0;\n\nfor (var i = 0; i < events; i++ ) {\n if (order[i] === -1) {\n if (!buffer) {\n crimes++;\n } else {\n buffer--;\n }\n } else {\n buffer += order[i];\n }\n}\n\nprint(crimes);"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\nfunction readNums() {\n\treturn readline().split(' ').map(Number);\n}\nprint(function(n) {\n\tvar a = readNums();\n\tvar ans = 0;\n\tvar p = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tif (a[i] === -1) {\n\t\t\tif (p > 0) {\n\t\t\t\tp--;\n\t\t\t} else {\n\t\t\t\tans++;\n\t\t\t}\n\t\t} else {\n\t\t\tp += a[i];\n\t\t}\n\t}\n\treturn ans;\n}(+readline()));"}, {"source_code": "var n = +readline(), events = readline().split(\" \"), sum = 0, police = 0;\n\nevents.forEach(function(a){\n\tif(a == \"-1\" && police == 0){\n\t\tsum++;\n\t}\n\telse if(a == \"-1\" && police > 0){\n\t\tpolice--;\n\t}\n\telse{\n\t\tpolice += +a;\n\t}\n});\n\nwrite(sum);"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(x=>parseInt(x));\n\nvar crime=0;\nvar officer=0;\nvar temp;\nfor(var i=0 ; i0){\n officer+=input[i];\n }\n else{\n temp = input[i]+ officer;\n if(temp>0){\n officer=temp;\n }\n else{\n crime += temp;\n officer=0;\n } \n }\n}\n\nprint(Math.abs(crime));"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(x=>parseInt(x));\n\nvar crime=0;\nvar officer=0;\n\nfor(var i=0 ; i0){\n officer+=input[i];\n }\n else{\n officer--;\n if(officer<0){\n officer=0;\n crime++;\n \n }\n }\n}\n\nprint(crime);"}, {"source_code": " var numberOfEvents = readline()\n var events = readline().split(' ').map(Number)\n\n var policeAvailable = 0\n var untreatedEvents = 0\n\n for (var i = 0; i < numberOfEvents; i++) {\n if (events[i] > 0) {\n policeAvailable += events[i]\n } else if (events[i] < 0 && policeAvailable === 0) {\n untreatedEvents += 1\n } else {\n policeAvailable -= 1\n }\n }\n\n print(untreatedEvents)"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar s = readline().split(' ').map(Number);\n\tvar x = 0;\n\tvar y = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\n\t\tif (s[i] == -1) {\n\t\t\tif (!x) y++;\n\t\t\telse x--;\n\t\t} else x += s[i];\n\n\t}\n\n\tprint(y);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar data = tokenizeIntegers(readline());\n\tvar police = 0, crimes = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (data[i] == -1) {\n\t\t\tif (police == 0) {\n\t\t\t\t++crimes;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t--police;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tpolice += data[i];\n\t\t}\n\t}\n\tprint(crimes);\n}\n\nmain();\n"}, {"source_code": "var line = readline();\nvar n = line.split(' ')[0];\nline = readline();\nvar array=line.split(' ');\nvar sum =0;\nvar temp;\nvar solution = 0;\n\nfor(var i = 0 ; i < array.length;i++){\n temp = parseInt(array[i]);\n if(temp < 0){\n if(sum === 0){\n solution++\n }\n else{\n sum--;\n }\n }\n else{\n sum += temp;\n }\n}\n\nprint(solution);"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet events = readline().getNumArray(),\n crimeCounter = 0,\n availablePolice = 0;\n\nevents.map((event) => {\n if (event === -1) {\n if (availablePolice === 0) {\n crimeCounter++;\n } else {\n availablePolice--;\n }\n } else {\n availablePolice += event;\n }\n});\n\nwrite(crimeCounter);"}, {"source_code": "var totalEvents=readline();\nvar events = readline().split(' ').map(Number);\nvar availablePolice=0;\nvar crimes = 0;\n\nfor(var i=0;i0){\n availablePolice += events[i];\n }else if (events[i]<0 && availablePolice ===0){\n crimes +=1;\n }else{\n availablePolice -=1;\n }\n}\nprint(crimes);"}, {"source_code": "var n = readline(),\n\tnum = readline().split(\" \").map(function(x) {\n return parseInt(x)\n }),\n\tp = 0, c = 0;\nfor (var i = 0; i < n; i++) {\n\tif (num[i] >= 0) {\n\t\tp += num[i];\n } else {\n\t\t(p > 0) ? p-- : c++;\n }\n}\nprint(c);\n"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar temp = 0;\nvar res = 0\n\tfor (var i=0; i<+n; i++){\n\t\ttemp+= Number(str[i]);\n\t\tif (temp<0){\n\t\t\tres++;\n\t\t\ttemp=0;\n\t\t\t}\n\t}\nprint(res);"}, {"source_code": "var n = readline();\nvar c = readline().split(' ').map(Number);\nvar person = 0;\nvar crimes = 0;\n\nfor(var i = 0; i < n; i++){\n if(c[i] > 0){\n person += c[i];\n }\n else if(person !== 0){\n person += c[i];\n }\n else {\n crimes ++;\n }\n}\n\nprint(crimes);"}, {"source_code": "var n = parseInt(readline());\nvar answ = 0;\nvar items = readline().split(' ');\nvar police = 0;\nfor( var i = 0; i < items.length; ++i) {\n if (items[i] == '-1' && police == 0) {\n answ++;\n } else {\n police += parseInt(items[i]);\n }\n}\n\nprint(answ);\n\n"}, {"source_code": "var hired = 0, arr, events, numOfCrims = 0;\n \nevents = readline('Enter Num of Events');\narr = readline().split(' ').map(Number);\n \nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] < 0) {\n if (hired === 0)\n numOfCrims++;\n else\n hired--;\n }\n else\n hired = hired +arr[i];\n \n}\n \nprint(numOfCrims);"}, {"source_code": "readline();\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = 0, police = 0;\nfor (var i = 0; i < a.length; i++) {\n if (a[i] >= 0) {\n police+= a[i];\n } else {\n if (police > 0) {\n police--;\n } else {\n n++;\n }\n }\n}\nprint(n);"}, {"source_code": "var n=parseInt(readline());\nvar array=readline().split(' ').map(Number);\n\nun=0\nper=0;\n\nfor(var i=0;i0){\n per=per+array[i]\n }else{\n un=un+1;\n }\n }else{\n per=per+array[i]\n }\n}\nprint(un);"}, {"source_code": "readline();\nvar recruits = readline().split(' ').map(Number);\nvar sum=0;\nvar index=0\nfor (i = recruits.length-1; i>=0; i--) {\n if (recruits[i]<0)\n sum+=recruits[i];\n else{\n sum=recruits[i]+sum;\n if(sum>=1)\n sum=0;\n\n }\n\n \n \n}\nprint(Math.abs(sum))"}, {"source_code": "var n = readline();\nvar p = readline().split(\" \");\nvar stack = [];\nvar u = 0;\nvar min = 0;\nvar push = function(n,stack){\n\tif(stack.length != 0)\n\t\tn+=stack.pop();\n\tstack.push(n);\n\tmin = (n < min) ? n : min;\n}\n\nfor (var i = 0; i < p.length; i++)\n\tpush(parseInt(p[i]),stack);\nprint(min*-1);"}, {"source_code": "n=+readline()\nx=0\nprint(readline().split(' ').map(Number).reduce((s,a)=>s+((x=a>0?Math.max(a,x+a):x-1)<0?1:0),0))\n"}, {"source_code": "var n = readline();\n\nvar line = readline().split(' ');\n\nvar police = 0;\nvar crimes = 0;\nvar unsolved = 0;\n\nfor(i=0;i0){\n\tpolice+=parseInt(line[i]);\n } else{\n\tcrimes+=1;\n\tif(crimes>police){\n\t unsolved+=1;\n\t crimes=0;\n\t continue;\n\t}else{\n\t police-=1;\n\t crimes-=1;\n\t}\n }\n}\n\nprint(unsolved);"}, {"source_code": "\"use strict\";\n\nvar main = function() {\n var n = +rd();\n var A = rdAr();\n \n wr(A.reduce((a, v) => [Math.max(0, a[0] + v), a[1] + (v === -1 && a[0] <= 0)], [0, 0])[1]);\n};\n\nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n\nmain();"}, {"source_code": "readline()\nT=readline().split(' ').map(Number)\nprint(T.reduce((a,c) => {\n if (c > 0) {\n a.p += c;\n } else {\n if (a.p) {\n a.p--;\n } else {\n a.a++;\n }\n }\n return a;\n}, { a: 0, p: 0 }).a)\n"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction main() {\n const events_count = parseInt(readline(), 10);\n const events = readline().trim().split(' ').map(string => parseInt(string, 10));\n var crimes_untreated = 0;\n var free_police_forces = 0;\n\n events.forEach(event => {\n if (event === -1) {\n if (free_police_forces > 0) {\n free_police_forces--;\n } else {\n crimes_untreated++;\n }\n } else {\n free_police_forces += event;\n }\n });\n\n print(crimes_untreated);\n}\n\nmain();"}, {"source_code": "(function (){\n var Ret = 0;\n var K = 0;\n var C = readline();\n var Arr = readline().split(\" \");\n for (var i in Arr) {\n var N = parseInt(Arr[i]);\n //console.log(i,N);\n if (N > 0) {\n K += N;\n } else {\n if (K > 0) {\n K--;\n } else {\n Ret++;\n }\n }\n }\n print(Ret);\n})();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const events = parseInt(readline());\n const values = readline().split(' ').map(x => parseInt(x));\n let availableOfficer = 0 ;\n let crimes = 0 ;\n for (let i = 0 ; i < events ; i++){\n if (values[i] > 0){\n availableOfficer += values[i];\n }else {\n let crime = Math.abs(values[i]);\n let isCrime = availableOfficer - crime\n availableOfficer = (isCrime < 0 ) ? 0 : isCrime\n if (isCrime < 0) crimes += crime;\n }\n }\n console.log(crimes);\n}\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet numOfEvents;\nlet events;\nlet crimeCounter = 0;\nlet recruitersCounter = 0;\nrl.on(\"line\", (input) => {\n if (!numOfEvents) {\n numOfEvents = parseInt(input.split(\" \"))\n } else {\n events = input.split(\" \").map(Number)\n events.forEach(element => {\n if (element === -1) {\n if (recruitersCounter > 0) {\n recruitersCounter = recruitersCounter - 1\n }\n else{\n crimeCounter++\n }\n } else {\n recruitersCounter += element\n }\n\n });\n console.log(crimeCounter)\n rl.close()\n }\n})"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet numOfEvents;\nlet events;\nlet crimeCounter = 0;\nlet recruitersCounter = 0;\nrl.on(\"line\", (input) => {\n if (!numOfEvents) {\n numOfEvents = parseInt(input.split(\" \"))\n } else {\n events = input.split(\" \").map(Number)\n events.forEach(element => {\n if (element === -1) {\n crimeCounter++\n } else {\n recruitersCounter += element\n }\n if (crimeCounter <= recruitersCounter) {\n recruitersCounter = recruitersCounter - crimeCounter \n crimeCounter = 0\n }\n });\n console.log(crimeCounter)\n rl.close()\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet numOfEvents;\nlet events;\nlet crimeCounter = 0;\nlet recruitersCounter = 0;\nrl.on(\"line\", (input) => {\n if (!numOfEvents) {\n numOfEvents = parseInt(input.split(\" \"))\n } else {\n events = input.split(\" \").map(Number)\n events.forEach(element => {\n if (crimeCounter <= recruitersCounter) {\n recruitersCounter = recruitersCounter - crimeCounter \n crimeCounter = 0\n }\n if (element === -1) {\n crimeCounter++\n } else {\n recruitersCounter += element\n }\n \n });\n console.log(crimeCounter)\n rl.close()\n }\n})"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var hired = 0, untreated = 0;\n readline().split(' ').forEach(function (v){\n if ( v[0] === \"1\" ){\n ++hired;\n }else{\n if ( hired > 0 ){\n --hired;\n }else{\n ++untreated;\n }\n }\n });\n print(untreated);\n})();"}, {"source_code": "var hired = 0, arr, events, numOfCrims = 0;\n\nevents = readline('Enter Num of Events');\narr = readline().split(' ').map(Number);\n\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] < 0) {\n if (hired === 0)\n numOfCrims++;\n else\n hired--;\n }\n else\n hired = arr[i];\n\n}\n\nprint(numOfCrims);"}, {"source_code": "readline();\nvar recruits = readline().split(' ').map(Number);\nvar sum=0;\nvar index=0\nfor (i = recruits.length-1; i>=0; i--) {\n if (recruits[i]<0)\n sum+=recruits[i];\n else{\n sum=recruits[i]+sum;\n if(sum>=1)\n sum=0;\n\n }\n print(Math.abs(sum))\n \n \n}\nprint(Math.abs(sum))\n"}, {"source_code": "n=+readline()\nx=0\nprint(readline().split(' ').map(Number).reduce((s,a)=>s+((x=a>0?a:x-1)<0?1:0),0))\n"}, {"source_code": "var n = readline();\n\nvar line = readline().split(' ');\n\nvar police = 0;\nvar crimes = 0;\nvar unsolved = 0;\n\nfor(i=0;i0){\n\tpolice+=1;\n } else{\n\tcrimes+=1;\n\tif(crimes>police){\n\t unsolved+=1;\n\t crimes=0;\n\t continue;\n\t}else{\n\t police-=1;\n\t crimes-=1;\n\t}\n }\n}\n\nprint(unsolved);"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction main() {\n const events_count = parseInt(readline(), 10);\n const events = readline().trim().split(' ').map(string => {\n return parseInt(string, 10);\n });\n var crimes_untreated = 0;\n var free_police_forces = 0;\n\n events.forEach(event => {\n if (event === -1) {\n if (free_police_forces > 0) {\n free_police_forces--;\n } else {\n crimes_untreated++;\n }\n } else {\n free_police_forces += event;\n }\n });\n\n print(crimes_untreated);\n}"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var hired = 0, untreated = 0;\n readline().split(' ').forEach(function (v){\n if ( v[0] == '1' ){\n ++hired;\n }else{\n if ( hired > 0 ){\n --hired;\n }else{\n ++untreated;\n }\n } \n });\n print(untreated);\n})();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n let cops = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 1) {\n cops++;\n }\n else {\n if (cops === 0) {\n ans++;\n }\n else {\n cops = Math.max(0, --cops);\n }\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let untreatedCrime = 0;\n let cases = inputs[1].split(' ');\n for (let index = 0; index < cases.length - 1; index++) {\n const element = cases[index];\n if (cases[index] < 0) {\n untreatedCrime++;\n if ((index - 1) >= 0 && cases[index - 1] > 0) {\n untreatedCrime -= 1;\n }\n\n }\n\n }\n return untreatedCrime.toString();\n\n}\n\n\n\n\n\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let positive = 0;\n let untreatedCrime = 0;\n let cases = inputs[1].split(' ');\n for (let index = 0; index < cases.length; index++) {\n const element = cases[index];\n if (cases[index] < 0) {\n untreatedCrime++;\n if (positive > 0) {\n untreatedCrime -= positive;\n positive = 0;\n }\n }\n else {\n positive += +cases[index];\n }\n\n }\n return untreatedCrime.toString();\n\n}\n\n\n\n\n\n"}], "src_uid": "af47635f631381b4578ba599a4f8b317"} {"source_code": "(function () {\n\tvar n = parseInt(readline());\n\tvar line = readline().split(' ');\n\tvar m = {};\n\tvar prefix = 0;\n\tvar ans = n - 1;\n\t//print(n);\n\tfor(var idx in line){\n\t\tprefix += parseInt(line[idx]);\n\t\t//print(prefix);\n\t\tif(!m[prefix]) {\n\t\t\tm[prefix] = 1;\n\t\t} else {\n\t\t\t++m[prefix];\n\t\t}\n\t\tans = n - m[prefix] > ans? ans: n - m[prefix];\n\t}\n\tprint(ans);\n})();", "positive_code": [{"source_code": "(function () {\n\tvar n = parseInt(readline());\n\tvar line = readline().split(' ');\n\tvar m = {};\n\tvar prefix = 0;\n\tvar ans = n - 1;\n\t//print(n);\n\tfor(var idx in line){\n\t\tprefix += parseInt(line[idx]);\n\t\t//print(prefix);\n\t\tif(!m[''+prefix]) {\n\t\t\tm[''+prefix] = 1;\n\t\t} else {\n\t\t\t++m[''+prefix];\n\t\t}\n\t\tans = n - m[''+prefix] > ans? ans: n - m[''+prefix];\n\t}\n\tprint(ans);\n})();"}], "negative_code": [], "src_uid": "be12bb8148708f9ad3dc33b83b55eb1e"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const res = new Array(11).fill(-1);\r\n for (let [b, d] of a) {\r\n res[d] = Math.max(res[d], b);\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < 11; i++) {\r\n if (res[i] === -1) {\r\n console.log('MOREPROBLEMS');\r\n return;\r\n }\r\n sum += res[i];\r\n }\r\n console.log(sum);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let a=new Array(11);\r\n for(let i=0;i<=10;i++) a[i]=0;\r\n for(let i=1;i<=n;i++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n a[y]=Math.max(a[y],x);\r\n }\r\n let ans=0;\r\n flag=false;\r\n for(let i=1;i<=10;i++)\r\n {\r\n if(!a[i]) flag=true;\r\n ans+=a[i];\r\n }\r\n if(flag) console.log('MOREPROBLEMS');\r\n else console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let a=new Array(11);\r\n for(let i=0;i<=10;i++) a[i]=0;\r\n for(let i=1;i<=n;i++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n // console.log('z->',x,y);\r\n a[y]=Math.max(a[y],x);\r\n }\r\n // for(let i=1;i<=n;i++) console.log(a[i]);\r\n let ans=0;\r\n flag=false;\r\n for(let i=1;i<=10;i++)\r\n {\r\n if(!a[i]) flag=true;\r\n ans+=a[i];\r\n }\r\n if(flag) console.log('MOREPROBLEMS');\r\n else console.log(ans);\r\n }\r\n})"}], "negative_code": [], "src_uid": "98beefa4cb73ccbf9575a6cfe73f4fff"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, arr))\n }\n// })()\n})\n\nfunction solve(n, arr) {\n const gs = arr.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n return o\n }, {})\n const sorted = Object.keys(gs).map(Number)\n .sort((a, b) => b - a)\n// console.log(gs, sorted)\n const all = fac(n)\n if (sorted.length < 2) return all\n\n const a = sorted[0]\n const b = sorted[1]\n if (gs[a] > 1) return all\n if (a > b + 1) return 0\n\n let ca = gs[a]\n let cb = gs[b]\n let cc = n - ca - cb\n\n let invalid = mul(fac(ca), fac(cb))\n for (let i = 1; i <= cc; i++) {\n invalid = mul(invalid, ca + cb + i)\n }\n let ans = add(all, -invalid)\n return add(ans, 998244353)\n}\n\nfunction add(a, b) {\n return (a + b) % 998244353\n}\nfunction mul(a, b) {\n const str = b.toString(2)\n let r = 0\n let base = a\n for (let i = str.length - 1; i >= 0; i--) {\n if (str[i] === '1') {\n r = add(r, base)\n }\n base = add(base, base)\n }\n return r\n}\nfunction fac(n) {\n let ans = 1\n for (let i = 2; i <= n; i++) {\n ans = mul(ans, i)\n }\n return ans\n}\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst MOD = 998244353;\r\n\r\nconst B = n => BigInt(n);\r\nconst N = n => Number(n);\r\n\r\nfunction fact (n) {\r\n\tlet res = 1;\r\n\tfor (let i = 1; i <= n; i++) res = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (a[n-1] - a[n-2] == 0) { \r\n\t\t\tans = fact(n);\r\n\t\t}\r\n\t\tif (a[n-1] - a[n-2] == 1) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) cnt += a[i] == a[n-2];\r\n\t\t\tlet ways = 1;\r\n\t\t\tlet juries = n - (cnt + 1);\r\n\t\t\tlet spots = 1 + (cnt + 1);\r\n\t\t\twhile (juries--) {\r\n\t\t\t\tways = ways * spots % MOD, spots++;\r\n\t\t\t}\r\n\t\t\tans = fact(n) - N(B(fact(cnt)) * B(ways) % B(MOD));\r\n\t\t\tans = (MOD + ans) % MOD;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst MOD = 998244353;\r\n\r\nconst B = n => BigInt(n);\r\nconst N = n => Number(n);\r\n\r\nfunction fact (n) {\r\n\tlet res = 1;\r\n\tfor (let i = 1; i <= n; i++) res = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (a[n-1] - a[n-2] == 0) { \r\n\t\t\tans = fact(n);\r\n\t\t}\r\n\t\tif (a[n-1] - a[n-2] == 1) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) cnt += a[i] == a[n-2];\r\n\t\t\tlet ways = 1;\r\n\t\t\tlet juries = n - (cnt + 1);\r\n\t\t\tlet spots = 1 + (cnt + 1);\r\n\t\t\twhile (juries--) {\r\n\t\t\t\tways = ways * spots % MOD, spots++;\r\n\t\t\t}\r\n\t\t\tans = fact(n) - N(B(fact(cnt)) * B(ways) % B(MOD));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 998244353;\r\n\r\nfunction fact (n) {\r\n\tlet ans = 1;\r\n\tfor (let i = 1; i <= n; i++) \r\n\t\tans = ans * i % MOD;\r\n\treturn ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = 2;\r\n\t\tif (a[0] - a[1] == 0) ans = fact(n);\r\n\t\tif (a[0] - a[1] == 1) {\r\n\r\n\t\t\tlet k = 0;\r\n\t\t\tfor (const vl of a) {\r\n\t\t\t\tk += vl == a[1];\r\n\t\t\t}\r\n\r\n\t\t\tfor (let x = n - 1; x >= k; x--) {\r\n\t\t\t\tlet prd = 1;\r\n\t\t\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\t\t\tprd = prd * (x - i) % MOD;\r\n\t\t\t\t}\r\n\t\t\t\tans += prd * fact(n-k-1);\r\n\t\t\t\tans %= MOD;\r\n\t\t\t}\r\n\t\t\tans = (fact(n) - ans + MOD) % MOD;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\u00a0\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 998244353;\r\n\r\nfunction fact (n) {\r\n\tlet ans = 1;\r\n\twhile (n) ans = (ans * n--) % MOD;\r\n\treturn ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet k = 0;\r\n\t\tfor (const x of a) k += x == a[n-2];\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (a[n-1] == a[n-2]) ans = fact(n);\r\n\t\tif (a[n-1] == a[n-2] + 1) {\r\n\t\t\tlet x = n - 1;\r\n\t\t\twhile (x >= k) {\r\n\t\t\t\tlet prd = 1;\r\n\t\t\t\tfor (let j = 0; j < k; j++) {\r\n\t\t\t\t\tprd = prd * (x - j) % MOD;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tans = (ans + prd * fact(n-k-1)) % MOD;\r\n\t\t\t\tx--;\r\n\t\t\t}\r\n\t\t\tans = (fact(n) - ans) % MOD;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\u00a0\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 998244353;\r\n\r\nfunction fact (n) {\r\n\tlet ans = 1;\r\n\twhile (n) ans = (ans * n--) % MOD;\r\n\treturn ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet k = 0;\r\n\t\tfor (const x of a) k += x == a[n-2];\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (a[n-1] == a[n-2]) ans = fact(n);\r\n\t\tif (a[n-1] == a[n-2] + 1) {\r\n\t\t\tlet x = n - 1;\r\n\t\t\twhile (x >= k) {\r\n\t\t\t\tans = (ans + fact(x)/fact(x-k) * fact(n-k-1)) % MOD;\r\n\t\t\t\tx--;\r\n\t\t\t}\r\n\t\t\tans = (fact(n) - ans) % MOD;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\u00a0\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 998244353;\r\n\r\nfunction fact (n) {\r\n\tlet ans = 1;\r\n\twhile (n) ans = (ans * n--) % MOD;\r\n\treturn ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (const x of a) cnt += x == a[n-2];\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (a[n-1] == a[n-2]) ans = fact(n);\r\n\t\tif (a[n-1] == a[n-2] + 1) ans = fact(n) * cnt / (cnt + 1) % MOD;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, arr))\n }\n// })()\n})\n\nfunction solve(n, arr) {\n const gs = arr.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n return o\n }, {})\n const sorted = Object.keys(gs).map(Number)\n .sort((a, b) => b - a)\n\n const all = fac(n)\n if (sorted.length < 2) return all\n\n const a = sorted[0]\n const b = sorted[1]\n if (a > b + 1) return 0\n\n let ca = gs[a]\n let cb = gs[b]\n let cc = n - ca - cb\n\n let invalid = mul(fac(ca), fac(cb))\n for (let i = 1; i <= cc; i++) {\n invalid = mul(invalid, ca + cb + i)\n }\n let ans = add(all, -invalid)\n return add(ans, 998244353)\n}\n\nfunction add(a, b) {\n return (a + b) % 998244353\n}\nfunction mul(a, b) {\n const str = b.toString(2)\n let r = 0\n let base = a\n for (let i = str.length - 1; i >= 0; i--) {\n if (str[i] === '1') {\n r = add(r, base)\n }\n base = add(base, base)\n }\n return r\n}\nfunction fac(n) {\n let ans = 1\n for (let i = 2; i <= n; i++) {\n ans = mul(ans, i)\n }\n return ans\n}\n"}], "src_uid": "81d4867a7e5128baf316193e9cc3dfce"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst s2i = s => parseInt(s, 10);\n\nfunction main() {\n const T = s2i(readLine());\n for(let i = 0; i < T; i++) {\n let [a, b, n] = readLine().split(' ').map(s2i);\n\n if (a > b) [a, b] = [b, a];\n\n let ops = 0;\n\n while (b <= n) {\n [a, b] = [b, a + b];\n ops++;\n }\n\n console.log(ops);\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [a, b, target] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let count = 0;\n let i = 0;\n while (a <= target || b <= target) {\n if (a > b) {\n b += a;\n } else {\n a += b;\n }\n count++;\n i++;\n }\n console.log(count - 1);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar input = nextIntArray();\n \tvar N = input[2];\n \tvar min = Math.min(input[0], input[1]);\n \tvar max = Math.max(input[0], input[1]);\n \tvar count = 0;\n \twhile(N >= max){\n \t\tmin += max;\n \t\tvar tmp = max;\n \t\tmax = min;\n \t\tmin = tmp;\n \t\tcount++;\n \t}\n \toutput[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n const int = data[i].split(' ');\n let a = int[0] * 1;\n let b = int[1] * 1;\n const n = int[2] * 1;\n let count = 0;\n while (true) {\n if (a > n || b > n) {\n console.log(count);\n break;\n }\n a > b ? b += a : a += b;\n count += 1;\n }\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var _a, _b;\n var lines = input.split('\\n');\n var tests = parseInt(lines.shift(), 10);\n while (tests--) {\n var a = void 0, b = void 0, n = void 0;\n _a = lineToNumArray(lines.shift()), a = _a[0], b = _a[1], n = _a[2];\n var steps = 0;\n while (Math.max(a, b) <= n) {\n _b = [a + b, Math.max(a, b)], a = _b[0], b = _b[1];\n steps++;\n }\n console.log(steps);\n }\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n for(let i = 0; i < n; i++) {\n let [a, b, n] = lines[1 + i].split(' ')\n console.log(solution(+a, +b, +n))\n }\n}\n\nfunction solution(a, b, n) {\n if (a < b) return solution(b, a, n)\n // a >= b\n let i = 0\n for (; a <= n; i++) {\n let c = a + b\n b = a\n a = c\n }\n return i\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var inp = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var a = inp[0],\n b = inp[1],\n n = inp[2];\n var count = 0;\n while (Math.max(a, b) <= n) {\n if (a < b) {\n var temp = a;\n a = b;\n b = temp;\n }\n b += a;\n count++;\n }\n print(count);\n}\n"}, {"source_code": "\"use strict\";\n\n//readline().split(' ').map(Number);\n\nfunction sec(){\n var arr = readline().split(' ').map(Number);\n var a = Math.min(arr[0],arr[1]);\n var b = Math.max(arr[0],arr[1]);\n var aa = 1, bb = 1;\n var c = 1;\n while(aa * a + bb * b <= arr[2]){\n c++;\n bb = aa+bb;\n aa = bb-aa;\n }\n print(c);\n}\n\n\n\nfunction main(){\n var t = readline();\n while(t--){\n sec();\n }\n}\n\nmain();"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var abn = read().split(' ').map(Number);\n var a = abn[0], b = abn[1], n = abn[2];\n var count = 0;\n while (a <= n && b <= n) {\n if (a < b) {\n a += b;\n } else {\n b += a;\n }\n count++;\n }\n write(count);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var count = +readline();\n \nfor(var index = 0; index < count; ++index) {\n var content = readline()\n var content = content.split(' ');\n var a = +content[0];\n var b = +content[1];\n var n = +content[2];\n \n var rounds = 0;\n \n if(a > n || b > n) {\n print(\"0\");\n } else {\n while(a <= n && b <= n) {\n ++rounds;\n \n if(a + b > n) {\n a += b; \n } else {\n if(a < b) {\n a += b;\n } else {\n b += a;\n }\n }\n }\n }\n \n print('' + rounds + '\\n');\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n3 4\n##..\n##..\n...#\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n // let n = Number(readline());\n\n // let string = 'codeforces';\n\n // let s = 's'.repeat(BigInt.asIntN(n-1));\n\n // console.log(string + s);\n \n let n = parseInt(readline());\n\n for(let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst s2i = s => parseInt(s, 10);\n\nfunction main() {\n const T = s2i(readLine());\n for(let i = 0; i < T; i++) {\n let [a, b, n] = readLine().split(' ').map(s2i);\n\n if (a < b) {\n const temp = a;\n a = b;\n b = temp;\n }\n\n let ops = 0;\n\n while (b <= n) {\n ops++;\n const sum = a + b;\n a = b;\n b = sum;\n }\n\n console.log(ops);\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n3 4\n##..\n##..\n...#\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n // let n = Number(readline());\n\n // let string = 'codeforces';\n\n // let s = 's'.repeat(BigInt.asIntN(n-1));\n\n // console.log(string + s);\n \n let n = parseInt(readline());\n\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n // let n = Number(readline());\n\n // let string = 'codeforces';\n\n // let s = 's'.repeat(BigInt.asIntN(n-1));\n\n // console.log(string + s);\n \n let n = parseInt(readline());\n\n for(let i=0;i b) {\n b = sum;\n } else {\n a = sum;\n }\n\n count++;\n }\n\n console.log(count - 1);\n}\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n // let n = Number(readline());\n\n // let string = 'codeforces';\n\n // let s = 's'.repeat(BigInt.asIntN(n-1));\n\n // console.log(string + s);\n \n let n = parseInt(readline());\n\n for(let i=0;i b) {\n b = sum;\n } else {\n a = sum;\n }\n\n count++;\n }\n\n console.log(count);\n}\n\n"}, {"source_code": "var count = +readline();\n \nfor(var index = 0; index < count; ++index) {\nvar content = readline()\nvar content = content.split(' ');\nvar a = +content[0];\nvar b = +content[1];\nvar n = +content[2];\n \nvar rounds = 0;\n \nif(a > n || b > n) {\n print(\"0\");\n} else {\n while(a < n && b < n) {\n ++rounds;\n \n if(a + b > n) {\n a += b; \n } else {\n if(a < b) {\n a += b;\n } else {\n b += a;\n }\n }\n }\n}\n \nprint('' + rounds + '\\n');\n}"}, {"source_code": "var content = readline()\nvar content = content.split(' ');\nvar a = +content[0];\nvar b = +content[1];\nvar n = +content[2];\n\nvar rounds = 0;\n\nif(a > n || b > n) {\n print(\"0\");\n} else {\n while(a < n && b < n) {\n ++round;\n \n if(a + b > n) {\n a += b; \n } else {\n if(a < b) {\n a += b;\n } else {\n b += a;\n }\n }\n }\n}\n\nprint('' + rounds);"}], "src_uid": "5999a4e2fac29b5f4804639f6e949279"} {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let n = +readline();\r\n let arr = readline().split(' ').map(x => +x);\r\n console.log(`${solve(arr, n)}`) \r\n}\r\n\r\nfunction solve(nums, n){\r\n let result = 0;\r\n let l = 0;\r\n let r = n-1;\r\n while(l < r){\r\n while(nums[r]) r--;\r\n while(nums[l] === 0) l++;\r\n if(l < r){\r\n result++;\r\n l++;\r\n r--;\r\n }\r\n }\r\n return result;\r\n}\r\n", "positive_code": [{"source_code": "var n = parseInt(readline());\r\n\r\nfor (var i = 0; i < n; i++){\r\n var counter = 0;\r\n\r\n var k = parseInt(readline());\r\n var arr = readline().split(\" \");\r\n\r\n var bolo = k - 1;\r\n var starti = 0;\r\n \r\n for(var j = 1; j < k; j++){\r\n if(arr[j - 1] > arr[j]){\r\n while (arr[bolo] == 1){\r\n bolo--;\r\n }\r\n while(arr[starti] == 0){\r\n starti++;\r\n }\r\n arr[starti] = 0;\r\n arr[bolo] = 1\r\n j = starti + 1;\r\n k = bolo;\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var STR = readline();\r\n var List = STR.split(' ');\r\n var res = 0;\r\n if (STR.match(/0/g) == null) {\r\n process.stdout.write(res + '\\n');\r\n continue;\r\n }\r\n var z = STR.match(/0/g).length;\r\n for (var i = 0; i < n; i++) {\r\n if (List[i] == 0) {\r\n z--;\r\n } else {\r\n z--;\r\n res++;\r\n }\r\n if (z == 0) {\r\n process.stdout.write(res + '\\n');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let n = +readline();\r\n let arr = readline().split(' ').map(x => +x);\r\n console.log(`${solve(arr, n)}`) \r\n}\r\n\r\nfunction solve(nums, n){\r\n let result = 0;\r\n let l = 0;\r\n let r = n-1;\r\n while(l < r){\r\n while(nums[r]) r--;\r\n while(nums[l] === 0) l++;\r\n if(l < r){\r\n result++;\r\n nums[l] = 0;\r\n nums[r] = 1;\r\n l++;\r\n r--;\r\n }\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var oneLeft = [];\r\n var zeroRight = [];\r\n zeroRight[n] = 0;\r\n for (var i = 0; i < n; i++) {\r\n oneLeft[i] = (oneLeft[i - 1] || 0) + a[i];\r\n zeroRight[n - i - 1] = zeroRight[n - i] + 1 - a[n - i - 1];\r\n }\r\n\r\n for (i = 0; i < n; i++) {\r\n if (oneLeft[i] === zeroRight[i + 1]) {\r\n write(oneLeft[i]);\r\n return;\r\n }\r\n }\r\n write(0);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar index = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tindex.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N && index.length > 0; i++){\r\n\t\t\tif(list[i] == 1 && i < index[index.length - 1]){\r\n\t\t\t\toutput++;\r\n\t\t\t\tindex.pop();\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let a=line[2*_].split(' ').map(x=>{return parseInt(x)});\r\n let cnt=0;\r\n for(let i=0;i= l && a[r]) r--;\r\n while (r >= l && !a[l]) l++;\r\n if (l < r) {\r\n res++;\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let zero = [];\r\n for (let i = 0; i < n; i++) if (arr[i] === 0) zero.push(i);\r\n if (zero.length === 0) console.log(0);\r\n else {\r\n let ans = 0;\r\n let left = 0,\r\n right = zero.length - 1;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 1) {\r\n if (right >= 0 && i < zero[right]) {\r\n ans++;\r\n right--;\r\n }\r\n } else left++;\r\n }\r\n console.log(ans);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\r\n\r\nfor (var i = 0; i < n; i++){\r\n var counter = 0;\r\n\r\n var k = parseInt(readline());\r\n var arr = readline().split(\" \");\r\n\r\n var bolo;\r\n for(var j = 1; j < k; j++){\r\n if(arr[j - 1] > arr[j]){\r\n bolo = k - 1; \r\n while (arr[bolo] == 1){\r\n bolo--;\r\n }\r\n arr[j - 1] = 0;\r\n arr[bolo] = 1\r\n j = 0\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n}"}, {"source_code": "var n = parseInt(readline());\r\n\r\nfor (var i = 0; i < n; i++){\r\n var counter = 0;\r\n\r\n var k = parseInt(readline());\r\n var arr = readline().split(\" \");\r\n\r\n for(var j = 1; j < k; j++){\r\n if(arr[j - 1] > arr[j]){\r\n j++;\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var STR = readline();\r\n var List = STR.split(' ');\r\n var res = 0;\r\n var z = STR.match(/0/g).length;\r\n for (var i = 0; i < n; i++) {\r\n if (List[i] == 0) {\r\n z--;\r\n } else {\r\n z--;\r\n res++;\r\n }\r\n if (z == 0) {\r\n return process.stdout.write(res + '\\n');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var List = readline().split(' ');\r\n var res = 0;\r\n for (var i = 1; i <= n; i++) {\r\n if (List[i] >= List[i - 1]) {\r\n if (n - i == 1) {\r\n console.log(res + '\\n');\r\n }\r\n } else {\r\n res++;\r\n if (n - i == 1) {\r\n console.log(res + '\\n');\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var List = readline().split(' ');\r\n var res = 0;\r\n for (var i = 1; i <= n; i++) {\r\n if (List[i] >= List[i - 1]) {\r\n if (n - i == 1) {\r\n console.log(res);\r\n }\r\n } else {\r\n res++;\r\n if (n - i == 1) {\r\n console.log(res);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var List = readline().split(' ');\r\n var res = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (List[i] <= List[i + 1]) {\r\n if (n - i == 1) {\r\n console.log(res);\r\n }\r\n } else {\r\n res++;\r\n if (n - i == 1) {\r\n res = res - 1;\r\n console.log(res);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var List = readline().split(' ');\r\n var res = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (List[i] <= List[i + 1]) {\r\n if (n - i == 1) {\r\n process.stdout.write(res + '\\n');\r\n }\r\n } else {\r\n res++;\r\n if (n - i == 1) {\r\n res = res - 1;\r\n process.stdout.write(res + '\\n');\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let n = +readline();\r\n let arr = readline().split(' ').map(x => +x);\r\n console.log(`${solve(arr, n)}`) \r\n}\r\n\r\nfunction solve(nums, n){\r\n let result = 0;\r\n while(--n){\r\n if(nums[n] < nums[n-1]) result++;\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var oneLeft = [];\r\n var zeroRight = [];\r\n for (var i = 0; i < n; i++) {\r\n oneLeft[i] = (oneLeft[i - 1] || 0) + a[i];\r\n zeroRight[n - i - 1] = (zeroRight[n - i] || 0) + (1 - a[n - i - 1]);\r\n }\r\n\r\n for (i = 0; i < n - 1; i++) {\r\n if (oneLeft[i] === zeroRight[i + 1]) {\r\n write(oneLeft[i]);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "src_uid": "c247c7c382c243ab6b991c4a11bfc421"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n // return check(n, k, arr)\n //\n // const dp = []\n // const save = arr.slice()\n // for (let i = 0; i <= 30; i++) {\n const sum = []\n for (let j = 0; j < arr.length; j++) {\n sum[j] = arr[j]\n if (j) sum[j] += sum[j - 1]\n // arr[j] = Math.floor(arr[j] / 2)\n }\n // dp[i] = sum\n // }\n // console.log(dp)\n let ans = sum[n - 1] - n * k\n for (let i = 0; i < arr.length; i++) {\n let now = (sum[i - 1] || 0) - k * i\n for (let j = 0; j <= 30; j++) {\n if (i + j >= n) break\n now += Math.floor(arr[i + j] / (2 ** (j + 1)))\n }\n // console.log(i, now)\n ans = Math.max(ans, now)\n }\n return ans\n}\nfunction check(n, k, arr) {\n const limit = 2 ** n\n let max = -Infinity\n for (let i = 0; i < limit; i++) {\n let bad = 0\n let ans = 0\n for (let j = 0; j < n; j++) {\n if (i & (1 << j)) {\n // bad\n bad++\n } else {\n ans -= k\n }\n ans += Math.floor(arr[j] / (2 ** bad))\n }\n if (ans > max) {\n console.log(i.toString(2), ans)\n max = ans\n }\n }\n return max\n}\n", "positive_code": [{"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var inp = readline().split(' ');\r\n var n = inp[0];\r\n var k = inp[1];\r\n var chests = readline().split(' ');\r\n var ans = 0;\r\n var good30 = 0;\r\n\r\n for (var j = 0; j < n; j++) {\r\n var bad30 = 0;\r\n var div = 1;\r\n\r\n for (var p = j; p < n && p < j + 31; p++) {\r\n div *= 2;\r\n bad30 += Math.floor(parseInt(chests[p]) / div);\r\n }\r\n ans = Math.max(ans, good30 + bad30);\r\n good30 += parseInt(chests[j]) - k;\r\n }\r\n\r\n ans = Math.max(ans, good30);\r\n\r\n print(ans);\r\n}\r\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var inp = readline().split(' ');\r\n var n = inp[0];\r\n var k = inp[1];\r\n var chests = readline().split(' ');\r\n \r\n var ans = 0;\r\n \r\n var rest = 0;\r\n var div = 0;\r\n \r\n for (var j = 0; j < chests.length; j++) {\r\n rest += chests[j];\r\n }\r\n \r\n for (var j = 0; j < chests.length; j++) {\r\n var curr = chests[j];\r\n for (var l = 0; l < div; l++) {\r\n curr = Math.floor(curr / 2);\r\n }\r\n \r\n if (Math.floor(rest / 2) < rest - k) {\r\n ans -= k;\r\n ans += curr;\r\n rest -= curr;\r\n } else {\r\n ans += Math.floor(curr / 2);\r\n rest -= curr;\r\n rest = Math.floor(rest / 2);\r\n div++;\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const dp = []\n const save = arr.slice()\n for (let i = 0; i <= 30; i++) {\n const sum = []\n for (let j = 0; j < arr.length; j++) {\n sum[j] = arr[j]\n if (j) sum[j] += sum[j - 1]\n arr[j] = Math.floor(arr[j] / 2)\n }\n dp[i] = sum\n }\n // console.log(dp)\n let ans = 0\n let bad = 0\n for (let i = 0; i < arr.length; i++) {\n const cur = dp[bad][n - 1] - (dp[bad][i - 1] || 0)\n const next = dp[bad + 1][n - 1] - (dp[bad + 1][i - 1] || 0)\n if (cur - next < k) {\n bad++\n } else {\n ans -= k\n }\n ans += bad ? Math.floor(save[i] / (2 ** bad)) : save[i]\n }\n return ans\n}\n"}], "src_uid": "9fcc55a137b5ff021fdc8e1e867ce856"} {"source_code": "var t = readline();\r\nwhile (t-- > 0) {\r\n var n, c1, c2;\r\n n = readline();\r\n c1 = readline();\r\n c2 = readline();\r\n for (var i = 0; i < n; i++)\r\n if (c1[i] == '1' && c2[i] == '1')\r\n n = -1;\r\n write(n == -1 ? \"NO\\n\" : \"YES\\n\");\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst log = console.log\r\n\r\n\r\n/********** MAIN *****************/\r\nfunction main() {\r\n let t = parseInt(readline());\r\n let cols,line1,line2,g =[],a\r\n while(t-->0){\r\n cols = parseInt(readline());\r\n line1 = readline().split(\"\")\r\n line2 = readline().split(\"\")\r\n g.push(line1)\r\n g.push(line2)\r\n a=dfs(g,0,0,cols)\r\n a?log('YES'):log('NO')\r\n g =[]\r\n }\r\n}\r\n\r\nconst dfs = (g,r,c,cols)=>{\r\n if(c===cols){\r\n return true\r\n }\r\n if(g[r][c]==='0' || g[r+1][c]==='0'){\r\n return dfs(g,r,c+1,cols)\r\n }\r\n else{\r\n return false\r\n }\r\n}\r\n"}, {"source_code": "\r\n\r\n// /****************************************************************\\\r\n// BISMILLAHIR RAHMANIR RAHIM\r\n// ****************************************************************\r\n// AUTHOR NAME: MD. TAHURUZZOHA TUHIN\r\n// \\****************************************************************/\r\n\r\n\r\n\r\n// 'use strict';\r\n// process.stdin.resume();\r\n// process.stdin.setEncoding('utf-8');\r\n\r\n// let inputString = '';\r\n// let currentLine = 0;\r\n\r\n// process.stdin.on('data', inputStdin => {\r\n// inputString += inputStdin;\r\n// });\r\n\r\n// process.stdin.on('end', _ => {\r\n// inputString = inputString.trim().split('\\n').map(string => {\r\n// return string.trim();\r\n// });\r\n\r\n// main();\r\n// });\r\n\r\n// function input() {\r\n// return inputString[currentLine++];\r\n// }\r\n\r\n// function main() {\r\n\r\n// let n, m, p, mx = [], mn = [], mp = [], mk = [], mh = [], t;\r\n// t = input();\r\n// let a = 0;\r\n// while (a < t) {\r\n// a++;\r\n// n = input();\r\n// n = parseInt(n);\r\n// m = input();\r\n// p = input();\r\n\r\n// for (const x of m) {\r\n// mx.push(x.toString());\r\n// }\r\n\r\n// for (const x of p) {\r\n// mn.push(x.toString());\r\n// }\r\n// mp = [mx, mn];\r\n// for (let i = 0; i < 2; i++) {\r\n// for (let j = 0; j < n; j++) {\r\n// if (mp[i][j] === '0' && i == 0) {\r\n// mk.push(i + 1, j + 1);\r\n// }\r\n// if (mp[i][j] === '0' && i == 1) {\r\n// mh.push(i + 1, j + 1);\r\n// }\r\n// }\r\n// }\r\n// let mg = [...mk, ...mh];\r\n// let cnt = 0, pnt = 1;\r\n// for (let i = 0; i < mg.length / 2; i += 1) {\r\n// let v1 = Math.abs(mg[i] - mg[i + 2]);\r\n// if (v1 >= 2) pnt = 0;\r\n// }\r\n\r\n// if (pnt === 0) {\r\n// for (let i = 0; i < mk.length; i += 2) {\r\n// let v3 = Math.abs(mk[i] - mh[i]);\r\n// let v4 = Math.abs(mk[i + 1] - mh[i + 1]);\r\n// if (((v3 >= 2 || v4 >= 2))) {\r\n// cnt = 0;\r\n// } else {\r\n// cnt = 1;\r\n// }\r\n// }\r\n// }\r\n// console.log((pnt || cnt ? \"YES\" : \"NO\"));\r\n// mk.length = 0;\r\n// mh.length = 0;\r\n// mg.length = 0;\r\n// mp.length = 0;\r\n// mx.length = 0;\r\n// mn.length = 0;\r\n// }\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n/****************************************************************\\\r\n BISMILLAHIR RAHMANIR RAHIM\r\n****************************************************************\r\n AUTHOR NAME: MD. TAHURUZZOHA TUHIN\r\n\\****************************************************************/\r\n\r\n\r\n\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n let n, m, p, mx = [], mn = [], t;\r\n t = input();\r\n let a = 0;\r\n while (a < t) {\r\n a++;\r\n n = input();\r\n n = parseInt(n);\r\n m = input();\r\n p = input();\r\n\r\n for (const x of m) {\r\n mx.push(x.toString());\r\n }\r\n\r\n for (const x of p) {\r\n mn.push(x.toString());\r\n }\r\n let out = \"YES\"\r\n for (let i = 0; i < n; i++) {\r\n if (mx[i] === '1' && mn[i] === '1') {\r\n out = \"NO\";\r\n break;\r\n }\r\n }\r\n console.log(out);\r\n mx.length = 0;\r\n mn.length = 0;\r\n p = 0;\r\n n = 0;\r\n m = 0;\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \nfunction Queue() {\n this.length = 0;\n}\n \nQueue.prototype.push = function (item) {\n var node = {item: item};\n if (this.last) {\n this.last = this.last.next = node;\n } else {\n this.last = this.first = node;\n }\n this.length++;\n};\n\nQueue.prototype.shift = function () {\n var node = this.first;\n if (node) {\n this.first = node.next;\n if (!(--this.length)) {\n this.last = undefined;\n }\n return node.item;\n }\n};\n\nQueue.prototype.slice = function (start, end) {\n start = typeof start === 'undefined' ? 0 : start;\n end = typeof end === 'undefined' ? Infinity : end;\n\n var output = [];\n\n var i = 0;\n for (var node = this.first; node; node = node.next) {\n if (--end < 0) {\n break;\n } else if (++i > start) {\n output.push(node.item);\n }\n }\n return output;\n}\n\nclass Logger {\n\n constructor() {\n this.enabled = false;\n }\n\n enable() {\n this.enabled = true;\n }\n\n disable() {\n this.enabled = false;\n }\n\n log(...str) {\n if (this.enabled) {\n console.error(...str);\n }\n }\n}\n\nlet logger = new Logger();\n// logger.enable();\n \nfunction main() {\n\n let t = +readline();\n\n for (let i = 0; i < t; ++i) {\n let n = +readline();\n let a = readline();\n let b = readline();\n\n let canReachEnd = true;\n\n for (let j = 0; j < n; ++j) {\n if (a[j] == '1' && b[j] == '1') {\n canReachEnd = false;\n break;\n }\n }\n\n console.log(canReachEnd?'YES':'NO')\n\n }\n\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n const dp = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n for (let j = 0; j < 2; j++) if (s[j][0] === '0') dp[0][j] = 1;\r\n for (let i = 1; i < n; i++) {\r\n for (let j = 0; j < 2; j++) if (s[j][i] === '0' && (dp[i - 1][0] || dp[i - 1][1])) dp[i][j] = 1;\r\n }\r\n return dp[n - 1][0] || dp[n - 1][1] ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let q = 0; q < t; q++){\r\n const n = parseInt(ls[l++]);\r\n const s1 = ls[l++];\r\n const s2 = ls[l++];\r\n let res = 'YES';\r\n for (let i = 0; i < n; i++){\r\n if (s1[i] == '1' && s2[i] == '1'){\r\n res = 'NO';\r\n break;\r\n }\r\n }\r\n console.log(res);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.line().split('');\n\t\tlet b = nl.line().split('');\n\t\tlet flag = true;\n\t\tfor(let j = 0; j < n && flag; j++){\n\t\t\tif (a[j] === '1' && a[j] === b[j]) {\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t}\n\t\tans.push(flag);\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let inputText = ''\r\nprocess.stdin.on('data', c => inputText += c)\r\n\r\nprocess.stdin.on('end', () => {\r\n\r\n const {EOL} = require('os')\r\n const lines = inputText.split(EOL) /*your input text, split by lines*/\r\n\r\n // console.log(lines);\r\n\r\n let pointer = 0;\r\n let k = parseInt(lines[pointer++]);\r\n outer : while (k -- > 0) {\r\n\r\n let len = parseInt(lines[pointer++]);\r\n let line1 = lines[pointer++];\r\n let line2 = lines[pointer++];\r\n\r\n // console.log(\"NO\");\r\n for(let i = 0 ; i < len ; i++) {\r\n if(line1[i] === '1' && line2[i] === '1') {\r\n console.log(\"NO\");\r\n continue outer;\r\n }\r\n }\r\n\r\n console.log(\"YES\");\r\n }\r\n\r\n // [n, m, a] = inputText.split(' ');\r\n // let k1 = n / a;\r\n // let k2 = m / a;\r\n // console.log(Math.ceil(k1) * Math.ceil(k2))\r\n})\r\n\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,-1,-1,0,1,1,1,0];\r\n\tvar dx = [-1,0,1,1,1,0,-1,-1];\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = [next(), next()];\r\n\t\tvar list = new Array(2);\r\n\t\tfor(var i = 0; i < 2; i++){\r\n\t\t\tlist[i] = new Array(N).fill(false);\r\n\t\t}\r\n\r\n\t\tvar queue = [];\r\n\t\tif(s[0][0] == \"0\"){\r\n\t\t\tqueue.push([0,0]);\r\n\t\t\tlist[0][0] = true;\r\n\t\t}\r\n\t\twhile(queue.length > 0){\r\n\t\t\tvar now = queue.shift();\r\n\t\t\tvar y = now[0];\r\n\t\t\tvar x = now[1];\r\n\t\t\tfor(var i = 0; i < dy.length; i++){\r\n\t\t\t\tvar nextY = y + dy[i];\r\n\t\t\t\tvar nextX = x + dx[i];\r\n\t\t\t\tif(nextY < 2 && nextY >= 0 && nextX < N && nextX >= 0){\r\n\t\t\t\t\tif(s[nextY][nextX] == \"0\" && !list[nextY][nextX]){\r\n\t\t\t\t\t\tlist[nextY][nextX] = true;\r\n\t\t\t\t\t\tqueue.push([nextY, nextX]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((list[1][N - 1]) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const grid = lines.slice(l, l + 2).map(str => str.trim())\n l += 2\n output[i] = solve(n, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, grid) {\n const q = [[0, 0]]\n const visited = {}\n while (q.length) {\n // console.log(q)\n const [x, y] = q.shift()\n if (x === 1 && y === n - 1) return 'YES'\n const k = x + ',' + y\n if (visited[k]) continue\n visited[k] = 1\n\n add(n, grid, q, x, y + 1)\n add(n, grid, q, x + 1, y)\n add(n, grid, q, x + 1, y + 1)\n add(n, grid, q, x - 1, y)\n add(n, grid, q, x - 1, y + 1)\n }\n return 'NO'\n}\nfunction add(n, grid, q, x, y) {\n if (x >= 0 && x < 2 && y >= 0 && y < n && grid[x][y] === '0') {\n q.push([x, y])\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var i=0; i {\r\n input+=line\r\n });\r\n\r\n\r\n readline.on('end',()=>{\r\n console.log(input)\r\n })"}, {"source_code": "\r\n/****************************************************************\\\r\n BISMILLAHIR RAHMANIR RAHIM\r\n****************************************************************\r\n AUTHOR NAME: MD. TAHURUZZOHA TUHIN\r\n\\****************************************************************/\r\n\r\n\r\n\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n let n, m, p, mx = [], mn = [], mp = [], mk = [], mh = [], t;\r\n t = input();\r\n let a = 0;\r\n while (a < t) {\r\n a++;\r\n n = input();\r\n n = parseInt(n);\r\n m = input();\r\n p = input();\r\n\r\n for (const x of m) {\r\n mx.push(x.toString());\r\n }\r\n\r\n for (const x of p) {\r\n mn.push(x.toString());\r\n }\r\n mp = [mx, mn];\r\n for (let i = 0; i < 2; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (mp[i][j] === '0' && i == 0) {\r\n mk.push(i + 1, j + 1);\r\n }\r\n if (mp[i][j] === '0' && i == 1) {\r\n mh.push(i + 1, j + 1);\r\n }\r\n }\r\n }\r\n let mg = [...mk, ...mh];\r\n let cnt = 0, pnt = 1;\r\n for (let i = 0; i < mg.length / 2; i += 1) {\r\n let v1 = Math.abs(mg[i] - mg[i + 2]);\r\n if (v1 >= 2) pnt = 0;\r\n }\r\n\r\n if (pnt === 0) {\r\n for (let i = 0; i < mk.length; i += 2) {\r\n let v3 = Math.abs(mk[i] - mh[i]);\r\n let v4 = Math.abs(mk[i + 1] - mh[i + 1]);\r\n if (((v3 >= 2 || v4 >= 2))) {\r\n cnt = 0;\r\n } else {\r\n cnt = 1;\r\n }\r\n }\r\n }\r\n console.log((pnt || cnt ? \"YES\" : \"NO\"));\r\n mk.length = 0;\r\n mh.length = 0;\r\n mg.length = 0;\r\n mp.length = 0;\r\n mx.length = 0;\r\n mn.length = 0;\r\n }\r\n\r\n}"}, {"source_code": "\r\n/****************************************************************\\\r\n BISMILLAHIR RAHMANIR RAHIM\r\n****************************************************************\r\n AUTHOR NAME: MD. TAHURUZZOHA TUHIN\r\n\\****************************************************************/\r\n\r\n\r\n\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n let n, m, p, mx = [], mn = [], mp = [], mk = [], mh = [], t;\r\n t = input();\r\n let a = 0;\r\n while (a < t) {\r\n a++;\r\n n = input();\r\n n = parseInt(n);\r\n m = input();\r\n p = input();\r\n\r\n for (const x of m) {\r\n mx.push(x.toString());\r\n }\r\n\r\n for (const x of p) {\r\n mn.push(x.toString());\r\n }\r\n mp = [mx, mn];\r\n for (let i = 0; i < 2; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (mp[i][j] === '0' && i == 0) {\r\n mk.push(i + 1, j + 1);\r\n }\r\n if (mp[i][j] === '0' && i == 1) {\r\n mh.push(i + 1, j + 1);\r\n }\r\n }\r\n }\r\n let mg = [...mk, ...mh];\r\n let cnt = 0, pnt = 1;\r\n for (let i = 0; i < mg.length / 2; i += 1) {\r\n let v1 = Math.abs(mg[i] - mg[i + 2]);\r\n if (v1 >= 2) pnt = 0;\r\n }\r\n\r\n if (pnt === 0) {\r\n for (let i = 0; i < mk.length; i += 2) {\r\n let v3 = Math.abs(mk[i] - mh[i]);\r\n let v4 = Math.abs(mk[i + 1] - mh[i + 1]);\r\n if (((v3 >= 2 || v4 >= 2))) {\r\n cnt = 0;\r\n } else {\r\n cnt = 1;\r\n }\r\n }\r\n }\r\n console.log((pnt || cnt ? \"YES\" : \"NO\"));\r\n mk = mk.splice(0, mk.lenth);\r\n mh = mh.splice(0, mh.lenth);\r\n mg = mg.splice(0, mg.lenth);\r\n mp = mp.splice(0, mp.lenth);\r\n mx = mx.splice(0, mx.lenth);\r\n mn = mn.splice(0, mn.lenth);\r\n }\r\n\r\n}"}], "src_uid": "fefec879efd4f524de00684adee7cd19"} {"source_code": "\"use strict\";\nif (typeof print == 'undefined') var print = console.log;\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id ++];\n}\n\nlet nums = () => readline().split(' ').map(x => +x);\nlet t = nums(), n = t[0], k = t[1];\n\nlet a = nums().map(x => Math.floor((x + k -1) / k)).reduce((m, n) => m + n, 0);\nprint(Math.floor((a + 1) / 2));\n\n", "positive_code": [{"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\nvar numbers = ints(),\n\tn = numbers[0],\n\tk = numbers[1],\n\ts = ints().reduce(function(s, x) {\n\t\treturn s + Math.floor(x / k) + (x % k == 0 ? 0 : 1)\n\t}, 0)\n\nprint(Math.floor(s / 2) + (s % 2))"}, {"source_code": "\nvar params = readline().split(\" \").map(function convert(value) {return +value; });\n\nvar n = params[0];\nvar k = params[1];\n\nvar counter = readline().split(\" \").map(function convert(value) {return +value; })\n\t\t\t\t\t\t\t\t\t.reduce(function (total, current) {\n\t\t\t\t\t\t\t\t\t\treturn total + (current - current % k) / k + (current % k !== 0);}, 0);\n\nprint((counter - counter % 2) / 2 + (counter % 2 !== 0));\n"}, {"source_code": "var g = readline().split(\" \");\nvar n = +g[0];\nvar k = +g[1];\nvar y = readline().split(\" \");\nvar sum = 0;\nfor(i=0;i lines[id ++];\n}\n\nlet nums = () => readline().split(' ').map(x => +x);\nlet t = nums(), n = t[0], k = t[1];\n\nlet ans = 0, c = 0;\nlet a = nums().map(x => (ans += Math.floor(x / (2 * k)), x % (2 * k)));\nfor (let i of a) {\n if (i > k) ans ++;\n else ++c;\n}\nans += c >>> 1; if (c & 1) ans++;\nprint(ans);\n\n"}], "src_uid": "3992602be20a386f0ec57c51e14b39c5"} {"source_code": "var r = readline().split(' ').map(Number);\nvar n = r[0], k = r[1], d = {};\nfor (var i = 0; i < n; i++) {\n var j = readline();\n d[j] = d[j] ? 0 : 1;\n}\nvar x = Object.keys(d).reduce((r, i) => r + d[i], 0);\nprint(n - x + Math.ceil(x/2));\n", "positive_code": [{"source_code": "var n = Number(readline().split(' ')[0]), d = {};\nfor (var i = 0; i < n; i++) {var j = readline(); d[j] = d[j] ? 0 : 1;}\nvar x = Object.keys(d).reduce((r, i) => r + d[i], 0);\nwrite(n - x + Math.ceil(x/2));\n"}, {"source_code": "var arr = readline().split(' ').map(item => +item);\nvar n = arr[0], k = arr[1];\n\narr = new Array(k).fill(0);\n\nfor(var i = 0; i < n; i++) {\n var j = +readline() - 1;\n arr[j]++;\n}\n\ncount = 0;\nmod = 0;\n\nfor(var i = 0; i < arr.length; i++) {\n var j = arr[i] % 2;\n count += arr[i] - j;\n mod += j;\n}\n\ncount += parseInt(mod / 2) + mod % 2;\n\nprint(count);\n"}, {"source_code": "\"use strict\";\n\nvar main = function() {\n var input = rdAr();\n var n = input[0];\n var k = input[1];\n var C = crAr(2000, 0);\n for (var i = 0; i < n; ++i) {\n var a = +rd();\n C[a] = (++C[a]) % 2;\n }\n var r = C.reduce((v, a) => v + a);\n var bad = r >> 1;\n wr(n - bad);\n};\n \nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\n \nmain();"}, {"source_code": "function main() {\n // write code here:\n const nk = stdin[0].split(' ').map(Number)\n var arr = new Array(nk[1]).fill(0),\n result = 0,\n t = 0;\n for (let i = 1; i <= nk[0]; i++) {\n var a = Number(stdin[i]) - 1;\n arr[a]++;\n }\n for (let j = 0; j < nk[1]; j++) {\n result += Math.floor(arr[j] / 2) * 2;\n //\u5982\u679carr[j]\u4e3a\u5947\u6570\uff0c\u5219\u5148\u8bb0\u5f55\u4e0b\u6765\u4e3a\u5947\u6570\u7684\u4e2a\u6570\n if (arr[j] % 2 === 1) t++;\n }\n //\u5728\u6700\u540e\u7684 result \u52a0\u4e0a \uff08\u5947\u6570\u4e2a\u6570+1\uff09/ 2 \u7684\u7ed3\u679c\n result += Math.floor((t + 1) / 2);\n console.log(result);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "var v = readline().split(' ');\nv.map(x => Number(x));\nvar cnt = new Array;\ncnt.length = v[1];\ncnt.fill(0,0, v[1]);\nfor(var i = 0;i < v[0];i++){\n var x = Number(readline());\n cnt[x - 1]++;\n}\n\nvar ans = 0;\nvar have = Math.floor((v[0] + 1)/2);\nvar t = 0;\nfor(i = 0;i < v[1];i++){\n ans += Math.floor( (cnt[i] / 2)) * 2;\n if(cnt[i] % 2 == 1) t++;\n}\nans += Math.floor((t + 1)/2);\nprint(ans);"}], "negative_code": [], "src_uid": "dceeb739a56bb799550138aa8c127996"} {"source_code": "var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\nvar map = {};\n\nalphabet.forEach(function(char) {\n map[char] = {\n used: false,\n to: undefined,\n from: undefined\n };\n});\n\nvar n = Number(readline());\nvar hasResult = true;\n\ncycle:\n for(var i = 0; i result.length) {\n print('NO');\n } else {\n print(result);\n }\n}", "positive_code": [{"source_code": "var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\nvar map = {};\n\nalphabet.forEach(function(char) {\n map[char] = {\n used: false,\n to: undefined,\n from: undefined\n };\n});\n\nvar n = Number(readline());\nvar hasResult = true;\n\ncycle:\n for(var i = 0; i result.length) {\n print('NO');\n } else {\n print(result);\n }\n}"}, {"source_code": "var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\nvar map = {};\n\nalphabet.forEach(function(char) {\n map[char] = {\n used: false,\n to: undefined,\n from: undefined\n };\n});\n\nvar n = Number(readline());\nvar hasResult = true;\n\ncycle:\n for(var i = 0; i result.length) {\n print('NO');\n } else {\n print(result);\n }\n}"}], "negative_code": [{"source_code": "\nvar alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\nvar map = {};\n\nalphabet.forEach(function(char) {\n\tmap[char] = {\n\t\tisFirstChar: false,\n\t\tused: false,\n\t\tdirection: undefined\n\t};\n});\n\nvar n = Number(readline());\nvar hasResult = true;\n\ncycle:\nfor(var i = 0; i {\n line += data + \"\\n\";\n});\n\nprocess.stdin.on(\"end\", () => {\n line = line.trim().split(\"\\n\");\n main();\n});\n\nfunction main() {\n const t = Number(line[0]);\n // console.log(t);\n let j = 1;\n\n while (j < t + 1) {\n const [n, m] = line[j++].split(\" \");\n solve(Number(n), Number(m));\n }\n}\n\nfunction solve(m, n) {\n let val = n,\n sum = (n * (n + 1)) / 2;\n val = 2 * val;\n\n let i = 1;\n\n while (i < m) {\n sum += val;\n val = val + n;\n i++;\n }\n\n console.log(sum);\n}\n", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n})\r\n\r\nlet lineCounter = 0\r\n// multi line input\r\nreadline.on('line', (line) => {\r\n if (lineCounter > 0) {\r\n let [n, m] = line.split(' ').map(Number)\r\n console.log(optimalPath(n, m))\r\n }\r\n lineCounter++\r\n})\r\n\r\nlet optimalPath = (n, m) => {\r\n let minimalCost = (m * (m - 1)) / 2\r\n\r\n minimalCost += (m * (n * (n + 1))) / 2\r\n\r\n return minimalCost\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, m = 0;\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n n = a[0], m = a[1];\n var ans = m * (m - 1) / 2 + m * n * (n + 1) / 2;\n console.log(ans);\n }\n});\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar output = M * (M + 1) / 2;\r\n\t\toutput += ((N * (N + 1) / 2)) * M;\r\n\t\toutput -= M;\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var x = readline().split(' ');\r\n var n = parseInt(x[0]);\r\n var m = parseInt(x[1]);\r\n\r\n var sum = 0;\r\n sum += (m*(m+1))/2;\r\n sum += m*(n*(n+1))/2;\r\n sum -= m;\r\n\r\n console.log(sum); \r\n\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n,m] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let cnt = Math.floor((m * (m + 1))/2);\r\n for(let i=1;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(val) {\r\n console.log(val);\r\n}\r\n\r\nfunction readInt() {\r\n return parseInt(readline());\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n//#endregion\r\nfunction readInts() {\r\n return readline().split(' ').map(x=>parseInt(x));\r\n}\r\n\r\nfunction autoSum(a1,an,n) {\r\n return (a1+an) * n / 2;\r\n}\r\n\r\nfunction main() {\r\n let t = readInt();\r\n while(t-- > 0) {\r\n let [n,m] = readInts();\r\n print(autoSum(1,m,m) + autoSum(m,n*m,n) - m);\r\n }\r\n}\r\n"}, {"source_code": "/**\n * Format:\n * {type: 'number', namedVariable?: string }\n * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }\n * {type: 'array', namedVariable?: string }\n * {type: 'string', namedVariable?: string }\n */\n const readline = require('readline');\n\n function createCLIReader(instructions) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const mappedVariables = {};\n\n let resolvePromise = null;\n const donePromise = new Promise((res, rej) => {\n resolvePromise = res;\n });\n\n function waitUntilDone() {\n return donePromise;\n }\n\n /**\n * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }\n */\n const stack = [];\n let pc = -1;\n\n function finished() {\n if (pc >= instructions.length) {\n return true;\n }\n return false;\n }\n\n function checkFinished() {\n // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);\n if (pc >= instructions.length) {\n return true;\n }\n if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {\n return true;\n }\n return false;\n }\n\n function getNextInstructionContext() {\n if (!stack.length) {\n return {\n index: ++pc,\n }\n }\n const lastStack = stack[stack.length - 1];\n if (lastStack.pointer === lastStack.instructionCount) {\n lastStack.pointer = 0;\n lastStack.iteration = lastStack.iteration + 1;\n }\n if (lastStack.count === lastStack.iteration) {\n stack.pop();\n pc = lastStack.basePointer + lastStack.instructionCount + 1;\n return {\n index: pc,\n }\n }\n\n lastStack.pointer = lastStack.pointer + 1;\n return {\n index: lastStack.basePointer + lastStack.pointer,\n context: {\n namedPath: [...lastStack.context.namedPath, lastStack.iteration]\n }\n }\n }\n\n function pushRepeatToStack(instruction, index, context) {\n stack.push({\n type: 'repeat',\n count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],\n iteration: 0,\n basePointer: index,\n pointer: 0,\n instructionCount: instruction.instructionCount,\n context: {\n namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],\n }\n })\n setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);\n }\n\n function nextInstruction() {\n if (finished()) {\n // console.warn('Calling nextInstruction after finished, something is wrong');\n return;\n }\n while (true) {\n const { index, context } = getNextInstructionContext();\n const instruction = instructions[index];\n\n // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);\n switch (instruction.type) {\n case 'number':\n case 'array':\n case 'string':\n return {\n ...instruction,\n namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,\n }\n case 'repeat':\n pushRepeatToStack(instruction, index, context);\n break;\n default:\n // console.warn('Unclear instruction, abort');\n return;\n }\n }\n }\n\n function getIn(object, path) {\n for (let i = 0; i < path.length; ++i) {\n object = object[path[i]];\n }\n return object;\n }\n\n function setIn(object, path, value) {\n for (let i = 0; i < path.length - 1; ++i) {\n if (object[path[i]] == null) {\n object[path[i]] = {};\n }\n object = object[path[i]];\n }\n object[path[path.length - 1]] = value;\n }\n\n rl.on('line', line => {\n if (finished()) {\n return;\n }\n const { type, namedPath } = nextInstruction();\n switch (type) {\n case 'number':\n if (namedPath) {\n setIn(mappedVariables, namedPath, parseInt(line));\n }\n break;\n case 'string':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim());\n }\n break;\n case 'array':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));\n }\n break;\n default:\n // console.warn(`Value unread, received type ${type}.`);\n }\n\n if (checkFinished()) {\n resolvePromise(mappedVariables);\n rl.close();\n }\n });\n return {\n waitUntilDone,\n };\n }\n\n function solve(testCase) {\n const n = testCase.nAndM[0];\n const m = testCase.nAndM[1];\n return (m * (m - 1) / 2) + (n * (n + 1) / 2 * m);\n }\n\n (async function main() {\n const reader = createCLIReader([\n { type: 'number', namedVariable: 'numberOfTestCase' },\n { type: 'repeat', instructionCount: 1, count: 'numberOfTestCase', namedVariable: 'testCase' },\n { type: 'array', namedVariable: 'nAndM' },\n ]);\n const schema = await reader.waitUntilDone();\n\n for (let i = 0; i < schema.numberOfTestCase; ++i) {\n console.log(solve(schema.testCase[i]));\n }\n })();\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var x = readline().split(' ');\r\n var n = parseInt(x[0]);\r\n var m = parseInt(x[1]);\r\n\r\n var sum = 0;\r\n for (let j = 0; j < m; j++) {\r\n sum += (j+1);\r\n }\r\n for (let j = 0; j < n; j++) {\r\n sum += m*(j+1);\r\n }\r\n sum -= m;\r\n\r\n console.log(sum); \r\n\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction findKthLargest(nums, k) {\n k = nums.length - k;\n const quickSelect = (l, r) => {\n let pivot = nums[r];\n let p = l;\n for (let i = l; i < r; i++) {\n if (nums[i] <= pivot) {\n swapper(nums, p, i);\n p++;\n }\n }\n swapper(nums, p, r);\n\n if (p > k) return quickSelect(l, p - 1);\n else if (p < k) return quickSelect(p + 1, r);\n else return nums[p];\n };\n\n return quickSelect(0, nums.length - 1);\n};\n\nfunction swapper(array, a, b) {\n const temp = array[b];\n array[b] = array[a];\n array[a] = temp;\n};\n\nfunction main() {\n const t = readline() - 1;\n for (var l = 0; l <= t; l++) {\n const [n, m] = readline().split(' ').map(r => (r) - 0);\n if (m == 1) {\n const x = n * (n + 1) / 2;\n foo(String(x));\n }\n else {\n const x = m * (m + 1) / 2;\n const y = (2*m + (n-1)*m) * n/ 2;\n foo(String(x+y-m));\n }\n }\n}\nfunction foo(x) {\n process.stdout.write(x); // without auto '\\n' (newline)\n console.log(); // with auto '\\n' (newline)\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let nm = readline().split(\" \").map(Number);\r\n print(Easy(nm[0], nm[1]));\r\n }\r\n}\r\nfunction Easy(n, m) {\r\n let nth = n;\r\n let a = m;\r\n let d = m;\r\n let sum = (nth / 2) * (2 * a + (nth - 1) * d);\r\n let sum2 = (m * (m + 1)) / 2;\r\n return sum + sum2 - m;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [rows, cols] = readline().split(' ').map(Number);\r\n let sum = 0;\r\n for (let m = 0; m < cols; m++) {\r\n sum += m + 1;\r\n }\r\n for (let n = 1; n < rows; n++) {\r\n sum += (n + 1) * cols;\r\n }\r\n\r\n output(sum);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n return m * (m - 1) / 2 + m * n * (n + 1) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var q = Number(readline());\r\nwhile(q--) {\r\n var s=readline().split(\" \");\r\n var n=Number(s[0]);\r\n var m=Number(s[1]);\r\n var tot=0;\r\n for(i=1;i<=m;++i)\r\n tot+=i;\r\n for(i=2;i<=n;++i)\r\n tot+=(i-1)*m+m;\r\n print(tot);\r\n}"}], "negative_code": [{"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n})\r\n\r\n// multi line input\r\nreadline.on('line', (line) => {\r\n if (line.length > 1) {\r\n let [n, m] = line.split(' ').map(Number)\r\n console.log(optimalPath(n, m))\r\n }\r\n})\r\n\r\nlet optimalPath = (n, m) => {\r\n let minimalCost = (m * (m - 1)) / 2\r\n\r\n minimalCost += (m * (n * (n + 1))) / 2\r\n\r\n return minimalCost\r\n}"}], "src_uid": "7d774a003d2e3e8ae6fe1912b3998c96"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tlet inputarr = input.split(' ')\n\n\tlet r = parseInt(inputarr[0])\n\tlet g = parseInt(inputarr[1])\n\tlet b = parseInt(inputarr[2])\n\t\n\tlet arr = [r, g, b]\n\n\tarr.sort(function(a,b) {\n\t\treturn a-b\n\t\n\t})\n\tif(arr[1]+arr[0] < arr[2] - 1){\n\n\t\tconsole.log(\"No\")\n\t}\n\telse\n\t{\n\t\tconsole.log(\"Yes\")\n\t}\n\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n tmp.sort(function(a,b){\n \treturn b - a;\n });\n var max = tmp[0];\n var mins = tmp[1] + tmp[2];\n \n if(max - mins < 2){\n output[i] = \"Yes\";\n }else{\n output[i] = \"No\";\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n const r = arr[2] - arr[1] - arr[0];\n\n if (r > 1) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "let input = \"\";\nconst { EOL } = require(\"os\");\nprocess.stdin.on(\"data\", i => (input += i));\n\nprocess.stdin.on(\"end\", func);\n\nasync function func() {\n const [t, ...queries] = input.split(EOL);\n for (let i = 0; i < t; i++) {\n const [r, g, b] = queries.shift().split(\" \").map(a => parseInt(a));\n if (r + g + 1 < b || r + b + 1 < g || g + b + 1 < r) {\n console.log('No')\n } else {\n console.log('Yes')\n }\n }\n}\n\nmodule.exports = func;\n"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n lines.forEach(line => {\n let values = line.split(' ').map(Number).sort((a, b) => a - b);\n let result = values[2] - values[0] - values[1] <= 1;\n console.log(result ? 'Yes' : 'No');\n });\n});"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\ntxt.shift();\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(\" \").filter(data=>data.length>0).map(data=>data*1));\n}\n\nfunction doit(tab) {\n let max=tab.indexOf(Math.max(...tab));\n let score=0;\n tab.forEach((data,index)=>{\n if(index!=max)score+=data;\n });\n if(score>=tab[max]-1){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n \n }\n}"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n var testCases = [];\n for (var i = 0; i < testCasesNum; i++) {\n (function (i) {\n testCases[i] = readline();\n canPay(testCases[i]);\n })(i)\n }\n}\n\nfunction canPay(testCase) {\n var caseArr = testCase.split(' ').map(Number);\n var r = +caseArr[0];\n var g = +caseArr[1];\n var b = +caseArr[2];\n if ((r >= g && r >= b && r <= g + b + 1) ||\n (g >= r && g >= b && g <= r + b + 1) ||\n (b >= g && b >= r && b <= g + r + 1)) {\n print(\"Yes\")\n } else {\n print(\"No\")\n }\n}\n\nmain()"}, {"source_code": "'use strict';\n\nlet col = +readline();\n\nlet strings = [];\nfor (let i = 0; i < col; i++){\n\tstrings[i] = readline();\n\tstrings[i] = strings[i].split(\" \").map(function(item) {\n\t\treturn +item;\n\t});\n}\n\nfunction yesNo(arr) {\n\tlet max = 0;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (max <= arr[i]) {\n\t\t\tmax = arr[i];\n\t\t}\n\t}\n\tlet sum = arr[0] + arr[1] + arr[2];\n\tif (max - 1 > (sum - max)) {\n\t\treturn 'No\\n';\n\t} else {\n\t\treturn 'Yes\\n';\n\t}\n}\n\nfor (let i = 0; i < col; i++) {\n\tlet res = yesNo(strings[i]);\n\tprint(res);\n}\n\n\n\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const r = arr[i].split(' ').map(a => parseInt(a))\n sort(r)\n if(r[2] - r[1] - r[0] > 1) wr('No')\n else wr('Yes')\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n\nfunction mod(a, m) {\n let x = a % m\n if(x >= 0 ) return x\n else return m + x \n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}"}, {"source_code": "var t = parseInt(readline(), 10),\n inp = [];\n\nfor(var i=1; i<=t; i++) {\n inp = readline().split(' ').map(el => parseInt(el, 10));\n r = inp[0];\n g = inp[1];\n b = inp[2];\n \n if(r>=g && r>=b) {\n if(g+b >= r-1) print('YES');\n else print('NO');\n } else if(g>=r && g>=b) {\n if(r+b >= g-1) print('YES');\n else print('NO');\n } else if(b>=r && b>=g) {\n if(r+g >= b-1) print('YES');\n else print('NO');\n }\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nlet col = +readline();\n\nlet strings = [];\nfor (let i = 0; i < col; i++){\n\tstrings[i] = readline();\n\tstrings[i] = strings[i].split(\" \").map(function(item) {\n\t\treturn +item;\n\t});\n}\n\nfunction yesNo(arr) {\n\tlet max = 0;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (max <= arr[i]) {\n\t\t\tmax = arr[i];\n\t\t}\n\t}\n\tlet sum = arr[0] + arr[1] + arr[2];\n\tif ((sum - max) < max) {\n\t\treturn 'No\\n';\n\t} else {\n\t\treturn 'Yes\\n';\n\t}\n}\n\nfor (let i = 0; i < col; i++) {\n\tlet res = yesNo(strings[i]);\n\tprint(res);\n}\n"}, {"source_code": "'use strict';\n\nlet col = +readline();\n\nlet strings = [];\nfor (let i = 0; i < col; i++){\n\tstrings[i] = readline();\n\tstrings[i] = strings[i].split(\" \").map(function(item) {\n\t\treturn +item;\n\t});\n}\n\nfunction yesNo(arr) {\n\tlet max = 0;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (max <= arr[i]) {\n\t\t\tmax = arr[i];\n\t\t}\n\t}\n\tlet sum = arr[0] + arr[1] + arr[2];\n\tif ((sum - max) <= max - 1) {\n\t\treturn 'No\\n';\n\t} else {\n\t\treturn 'Yes\\n';\n\t}\n}\n\nfor (let i = 0; i < col; i++) {\n\tlet res = yesNo(strings[i]);\n\tprint(res);\n}\n\n\n\n"}, {"source_code": "\"use strict\";\n\nvar col = +readline();\n\nvar strings = [];\nfor (var i = 0; i < col; i++){\n\tstrings[i] = readline();\n\tstrings[i] = strings[i].split(\" \").map(function(item) {\n\t\treturn +item;\n\t});\n}\n\nfunction yesNo(arr) {\n\tlet max = 0;\n\tfor (var i = 0; i < 3; i++) {\n\t\tif (max < arr[i]) {\n\t\t\tmax = arr[i];\n\t\t}\n\t}\n\tvar sum = arr[0] + arr[1] + arr[2];\n\tif ((sum - max) < max) {\n\t\treturn 'No';\n\t} else if ((sum - max) >= max) {\n\t\treturn 'Yes';\n\t}\n}\n\nfor (var i = 0; i < col; i++) {\n\tprint(yesNo(strings[i]));\n}"}, {"source_code": "\"use strict\";\n\nvar col = +readline();\n\nvar strings = [];\nfor (var i = 0; i < col; i++){\n\tstrings[i] = readline();\n\tstrings[i] = strings[i].split(\" \").map(function(item) {\n\t\treturn +item;\n\t});\n}\n\nfunction yesNo(arr) {\n\tlet max = 0;\n\tfor (var i = 0; i < 3; i++) {\n\t\tif (max < arr[i]) {\n\t\t\tmax = arr[i];\n\t\t}\n\t}\n\tvar sum = arr[0] + arr[1] + arr[2];\n\tif ((sum - max) < max) {\n\t\treturn 'No\\n';\n\t} else {\n\t\treturn 'Yes\\n';\n\t}\n}\n\nfor (var i = 0; i < col; i++) {\n\tprint(yesNo(strings[i]));\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const [r, g, b] = arr[i].split(' ').map(a => parseInt(a))\n if(r >= g && r >= b && b + g >= r) {\n wr('Yes')\n }\n else if(g >= r && g >= b && b + r >= g) {\n wr('Yes')\n }\n else if(b >= r && b >= g && g + r >= b) {\n wr('Yes')\n }\n else wr('No')\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n\nfunction mod(a, m) {\n let x = a % m\n if(x >= 0 ) return x\n else return m + x \n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n\n if (max - min > 1) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tarr = []\n\tlet inputarr = input.split(' ')\n\n\tlet r = inputarr[0]\n\tlet g = inputarr[1]\n\tlet b = inputarr[2]\n\t\n\tconst res = Math.abs((r-g-b))\n\t\n\tconsole.log(res > 3 ? \"NO\" : \"YES\")\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tarr = []\n\tlet inputarr = input.split(' ')\n\n\tlet r = parseInt(inputarr[0])\n\tlet g = parseInt(inputarr[1])\n\tlet b = parseInt(inputarr[2])\n\n\t\n\tif(r === g){\n\t\tif(r > b){\n\t\t\tconsole.log(\"No\")\n\t\t\treturn\n\t\t}\n\t}\n\t\n\tif(g === b){\n\t\tif(g > r){\n\t\t\tconsole.log(\"No\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tif(r === b){\n\t\tif(r > b){\n\t\t\tconsole.log(\"No\")\n\t\t\treturn\n\t\t} \n\t}\n\n\tconst res = Math.abs((r-g-b))\n\t\t\t\n\tconsole.log(res > 3 ? \"No\" : \"Yes\")\n\n\n\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tarr = []\n\tlet inputarr = input.split(' ')\n\n\tlet r = inputarr[0]\n\tlet g = inputarr[1]\n\tlet b = inputarr[2]\n\n\n\tif(r === g){\n\t\tif(r > b){\n\t\t\tconsole.log(\"NO\")\n\t\t\treturn\n\t\t}\n\t}\n\t\n\tif(g === b){\n\t\tif(g > r){\n\t\t\tconsole.log(\"NO\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tif(r === b){\n\t\tif(r > b){\n\t\t\tconsole.log(\"NO\")\n\t\t\treturn\n\t\t} \n\t}\n\n\tconst res = Math.abs((r-g-b))\n\t\t\t\n\tconsole.log(res > 3 ? \"NO\" : \"YES\")\n\n\n\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tarr = []\n\tlet inputarr = input.split(' ')\n\n\tlet r = inputarr[0]\n\tlet g = inputarr[1]\n\tlet b = inputarr[2]\n\n\tif(r === b || r === g || g === b){\n\t\tconsole.log(\"NO\")\n\t}\n\n\tconsole.log(r-b-g)\n\tconst res = Math.abs((r-g-b))\n\t\t\t\n\tconsole.log(res > 3 ? \"NO\" : \"YES\")\n\n\n\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = 3\n\t\ti++\n\t\treturn\n\t}\n\tarr = []\n\tlet inputarr = input.split(' ')\n\n\tlet r = inputarr[0]\n\tlet g = inputarr[1]\n\tlet b = inputarr[2]\n\t\n\tconst res = Math.abs((r-g-b))\n\t\n\tconsole.log(res >= 3 ? \"NO\" : \"YES\")\n\n\n\n}\n"}], "src_uid": "34aa41871ee50f06e8acbd5eee94b493"} {"source_code": "var data = '';\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', (buffer) =>\n{\n data += buffer;\n});\n\nprocess.stdin.on('end', () =>\n{\n var x = data.split(/\\s+/);\n var i = 1;\n\n for (var cas = 0; cas < x[0]; cas++, i += 2)\n {\n var n = x[i];\n var res = '';\n var str = x[i + 1];\n var len = str.length;\n var left = 0, right = len - 1;\n for (; left < len && str[left] == '0'; left++);\n for (; right >= 0 && str[right] == '1'; right--);\n for (var j = 0; j < left; j++) res += '0';\n if (left < right) res += '0';\n for (var j = right + 1; j < len; j++) res += '1';\n console.log(res);\n }\n});", "positive_code": [{"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n read();\n var s = read();\n var firstOne = s.indexOf('1');\n var lastZero = s.lastIndexOf('0');\n if (firstOne < lastZero && firstOne !== -1) {\n s = s.substr(0, firstOne) + s.substr(lastZero);\n }\n write(s);\n }\n}\n \n \nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let _ = +readLine();\n let str = readLine();\n let countZero = 0;\n let countOne = 0;\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"0\") {\n countZero++;\n } else {\n break;\n }\n }\n for (let i = str.length - 1; i >= 0; i--) {\n if (str[i] === \"1\") {\n countOne++;\n } else {\n break;\n }\n }\n if (countOne + countZero === str.length) {\n console.log(str);\n } else {\n console.log(`${\"0\".repeat(countZero)}0${\"1\".repeat(countOne)}`);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n let tests = parseInt(lines.shift(), 10);\n while (tests--) {\n lines.shift();\n const s = lines.shift();\n let zeroCount = 0;\n let ans = [...s]\n .reverse()\n .reduce((acc, char) => {\n if (char === '0') {\n zeroCount++;\n }\n else if (zeroCount) {\n zeroCount = 1;\n }\n else {\n acc += char;\n }\n return acc;\n }, '');\n ans += '0'.repeat(zeroCount);\n console.log([...ans].reverse().join(''));\n }\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(element => parseInt(element, 10));\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i= right) {\n console.log(l)\n } else {\n // console.log('left', l.slice(0, left))\n // console.log('right', l.slice(right))\n console.log(l.slice(0, left) + '0' + l.slice(right))\n }\n\n //\n // const zeroPoint = l.indexOf('0')\n // const onePoint = l.indexOf('1')\n // const secondZeroPoint = l.indexOf('0', onePoint)\n //\n // if (zeroPoint === 0) {\n // if (secondZeroPoint > 0) {\n // console.log(l.slice(0, onePoint) + '0')\n // } else {\n // console.log(l)\n // }\n // } else {\n // if (zeroPoint > 0 ) {\n // console.log('0')\n // } else {\n // console.log(l)\n // }\n // }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n var n = Number(read());\n var s = read();\n var firstOne = s.indexOf('1');\n var lastZero = s.lastIndexOf('0');\n if (firstOne < lastZero && firstOne !== -1) {\n s = s.substr(0, firstOne) + s.substr(lastZero);\n }\n write(s);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nwhile(t--){\n var n = parseInt(readline());\n var str = readline();\n \n var cur = 0;\n var isDesc = false;\n while(cur + 1 < n){\n if(str[cur] == '1' && str[cur + 1] == '0'){\n isDesc = true;\n break;\n }\n cur++;\n }\n \n\n if(isDesc) {\n var newstr = \"\";\n leadZ = 0;\n while(leadZ < n && str[leadZ] == '0')\n leadZ++;\n leadZ++;\n sufO = 0;\n while(sufO < n && str[n - 1 - sufO] == '1')\n sufO++;\n \n while(leadZ--)\n newstr += \"0\";\n\n while(sufO--)\n newstr += \"1\";\n\n print(newstr);\n } else {\n print(str);\n }\n \n}"}], "negative_code": [], "src_uid": "bb071f1f4fc1c129a32064c1301f4942"} {"source_code": ";(function () {\n\n\tprint((function (k, d) {\n\t\tk = +k;\n\t\tif (d === '0' && k > 1) return 'No solution';\n\t\tfor (var i = 1; i < k; i++) d += '0';\n\t\treturn d;\n\t}).apply(this, readline().split(' ')));\n\n}).call(this);", "positive_code": [{"source_code": "print(function(k, d) {\n\tif (k > 1 && d === 0) return 'No solution';\n\tvar ans = [d];\n\tk--;\n\twhile (k--)\n\t\tans.push('0');\n\treturn ans.join('');\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\n\tprint((function (k, d) {\n\t\tk = +k;\n\t\tif (d === '0' && k > 1) return 'No solution';\n\t\tfor (var i = 1; i < k; i++) d += '0';\n\t\treturn d;\n\t}).apply(this, readline().split(' ')));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\n\tfunction solve(numDigits, digitalRoot) {\n\t\tif (digitalRoot == 0) {\n\t\t\tprint(numDigits == 1 ? 0 : \"No solution\");\n\t\t\treturn;\n\t\t}\n\t\tvar digits = [digitalRoot];\n\t\tfor (var digitIndex = 1; digitIndex < numDigits; ++digitIndex) {\n\t\t\tdigits.push(0);\n\t\t}\n\t\tprint(digits.join(\"\"));\n\t}\n\n\tvar data = tokenizeIntegers(readline());\n\tsolve(data[0], data[1]);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(k, d) {\n\tif (k === 0 && d > 1) return 'No solution';\n\tvar ans = [d];\n\tk--;\n\twhile (k--)\n\t\tans.push('0');\n\treturn ans.join('');\n} .apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": ";(function () {\n\n\tprint((function (k, d) {\n\t\tfor (var i = 1, k = +k; i < k; i++) d += '0';\n\t\treturn d;\n\t}).apply(this, readline().split(' ')));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\n\tfunction solve(numDigits, digitalRoot) {\n\t\tif (digitalRoot == 0) {\n\t\t\tprint(numDigits == 1 ? 0 : \"Impossible\");\n\t\t\treturn;\n\t\t}\n\t\tvar digits = [digitalRoot];\n\t\tfor (var digitIndex = 1; digitIndex < numDigits; ++digitIndex) {\n\t\t\tdigits.push(0);\n\t\t}\n\t\tprint(digits.join(\"\"));\n\t}\n\n\tvar data = tokenizeIntegers(readline());\n\tsolve(data[0], data[1]);\n}\n\nmain();\n"}], "src_uid": "5dd0d518f315d81204b25e48fea0793a"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [rowLen, colLen, x, y] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const visited = {};\n\n for (let i = y; i <= colLen; i++) {\n console.log(`${x} ${i}`);\n }\n for (let i = y - 1; i > 0; i--) {\n console.log(`${x} ${i}`);\n }\n\n let reverse = false;\n\n for (let row = 1; row <= rowLen; row++) {\n for (let col = 1; col <= colLen; col++) {\n if (x === row) {\n reverse = true;\n continue;\n }\n if (!reverse) {\n if (row % 2 !== 0) {\n console.log(`${row} ${col}`);\n } else {\n console.log(`${row} ${colLen + 1 - col}`);\n }\n } else {\n if (row % 2 === 0) {\n console.log(`${row} ${col}`);\n } else {\n console.log(`${row} ${colLen + 1 - col}`);\n }\n }\n }\n }\n}\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const line = readline();\n var cases = line.split(\" \");\n var n = parseInt(cases[0]);\n var m = parseInt(cases[1]);\n var x = parseInt(cases[2]);\n var y = parseInt(cases[3]);\n pathPrint(n,m,x,y);\n}\n\nfunction pathPrint(n,m,x,y){\n var currX = x;\n var currY = y;\n\n var reachedX = -1;\n var reachedY = -1;\n \n for(var i = currY; i >=1; i--){\n console.log(currX + \" \"+i);\n }\n for(var j = currY+1;j <=m;j++){\n console.log(currX+ \" \"+j);\n }\n\n reachedX = currX;\n reachedY = m;\n\n var rowAbove = currX-1;\n var rowBelow = currX+1;\n\n while(rowAbove>=1 && rowBelow<=n){\n reachedX = rowAbove;\n reachedY = m;\n for(var col1 = reachedY ; col1>=1;col1--){\n console.log(reachedX+ \" \"+col1);\n }\n reachedX = rowBelow;\n reachedY = 1;\n for(var col = 1 ; col<=m;col++){\n console.log(reachedX+ \" \"+col);\n }\n rowAbove--;\n rowBelow++;\n }\n\n if(rowBelow <=n){\n reachedX = rowBelow;\n reachedY = m;\n while(rowBelow <=n){\n reachedX = rowBelow;\n if(reachedY == m){\n for(var col2 = m ; col2>=1;col2--){\n console.log(reachedX+ \" \"+col2);\n }\n reachedY = 1;\n }else{\n for(var col3 = 1 ; col3<=m;col3++){\n console.log(reachedX+ \" \"+col3);\n }\n reachedY = m;\n }\n rowBelow++;\n }\n }\n\n if(rowAbove >=1){\n reachedX = rowAbove;\n reachedY = m;\n while(rowAbove >=1){\n reachedX = rowAbove;\n if(reachedY == m){\n for(var col4 = m ; col4>=1;col4--){\n console.log(reachedX+ \" \"+col4);\n }\n reachedY = 1;\n }else{\n for(var col5 = 1 ; col5<=m;col5++){\n console.log(reachedX+ \" \"+col5);\n }\n reachedY = m;\n }\n rowAbove--;\n }\n }\n}\n\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [rowLen, colLen, x, y] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n for (let row = 0; row < rowLen; row++) {\n for (let col = 0; col < colLen; col++) {\n console.log(`${x} ${y}`);\n y++;\n if (y > colLen) y = 1;\n }\n y--;\n x++;\n if (y === 0) y = colLen;\n if (x > rowLen) x = 1;\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n// \tdata = data.split('\\n');\n// \tconst testCases = data[0] * 1;\n// \tlet i = 1;\n// \twhile (i <= testCases) {\n let num = data.trim().split(' ').map(Number);\n let n = num[0];\n let m = num[1];\n let x = num[2];\n let y = num[3];\n console.log(x+' '+y);\n for (let c = m; c >= 1; c -= 1) {\n if (c !== y) console.log(x+' '+c);\n }\n let check = false;\n for (let i = 0; i < n; i++) { \n if (i+1 === x) {check=true; continue;}\n if (check) {\n if (i % 2 !== 0) { \n for (let j = 0; j < m; j++) console.log((i+1)+' '+(j+1)); \n \n // If current row is odd, print from \n // right to left \n } else { \n for (let j = m - 1; j >= 0; j--) \n console.log((i+1)+' '+(j+1));\n } \n }\n // If current row is even, print from \n // left to right \n else {\n if (i % 2 == 0) { \n for (let j = 0; j < m; j++) console.log((i+1)+' '+(j+1)); \n \n // If current row is odd, print from \n // right to left \n } else { \n for (let j = m - 1; j >= 0; j--) \n console.log((i+1)+' '+(j+1));\n }\n }\n \n // i += 1;\n\t}\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [n, m, sx, sy] = readLine().split(/\\s/).map(Number)\n const visited = Array(n).fill().map(() => [])\n console.log(sx, sy)\n visited[sx - 1][sy - 1] = true\n console.log(1, sy)\n visited[0][sy - 1] = true\n console.log(1, 1)\n visited[0][0] = true\n for (let r = 0; r < n; r++) {\n for (let _c = 0; _c < m; _c++) {\n const c = r % 2 === 0 ? _c : m - 1 - _c\n if (!visited[r][c]) {\n console.log(r + 1, c + 1)\n visited[r][c] = true\n }\n }\n }\n}\n\n"}, {"source_code": "const main = () => {\n const input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n const N = input[0];\n const M = input[1];\n\n const pos = {\n x: input[2],\n y: input[3],\n };\n\n for (var i = pos.x; i <= N; i++) {\n print(i, pos.y);\n }\n\n for (var i = pos.x - 1; i >= 1; i--) {\n print(i, pos.y);\n }\n\n pos.x = 1;\n\n for (var i = 1; i < pos.y; i++) {\n if (pos.x === 1) {\n for (var j = 1; j <= N; j++) {\n print(j, i);\n }\n\n pos.x = N;\n } else {\n for (var j = N; j >= 1; j--) {\n print(j, i);\n }\n\n pos.x = 1;\n }\n }\n\n for (var i = pos.y + 1; i <= M; i++) {\n if (pos.x === 1) {\n for (var j = 1; j <= N; j++) {\n print(j, i);\n }\n\n pos.x = N;\n } else {\n for (var j = N; j >= 1; j--) {\n print(j, i);\n }\n\n pos.x = 1;\n }\n }\n};\n\nmain();"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [rowLen, colLen, x, y] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const visited = {};\n\n for (let i = y; i <= colLen; i++) {\n console.log(`${x} ${i}`);\n visited[`${x}_${i}`] = true;\n }\n for (let i = y - 1; i > 0; i--) {\n console.log(`${x} ${i}`);\n visited[`${x}_${i}`] = true;\n }\n\n for (let row = 1; row <= rowLen; row++) {\n for (let col = 1; col <= colLen; col++) {\n if (row % 2 !== 0) {\n !visited[`${row}_${col}`] && console.log(`${row} ${col}`);\n } else {\n !visited[`${row}_${colLen + 1 - col}`] && console.log(`${row} ${colLen + 1 - col}`);\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const [x, y, a, b] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const visited = {};\n const arr = [...Array(x).fill(0)].map((_) => Array(y).fill(0));\n arr[a - 1][b - 1] = 1;\n traverse(a - 1, b - 1);\n\n function traverse(a, b) {\n if (a < 0 || a >= x || b < 0 || b >= y || visited[`${a}${b}`]) return;\n\n console.log(`${a + 1} ${b + 1}`);\n\n visited[`${a}${b}`] = 1;\n\n traverse(a, b + 1);\n traverse(a - 1, b);\n traverse(a, b - 1);\n traverse(a + 1, b);\n }\n}\n"}, {"source_code": "const main = () => {\n const input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n const N = input[0];\n const M = input[1];\n\n const pos = {\n x: input[2],\n y: input[3],\n };\n\n for (var i = pos.x; i <= N; i++) {\n print(i, pos.y);\n }\n\n for (var i = pos.x - 1; i >= 1; i--) {\n print(i, pos.y);\n }\n\n pos.x = 1;\n\n for (var i = 1; i < pos.y; i++) {\n if (pos.x === 1) {\n for (var j = 1; j <= N; j++) {\n print(j, i);\n }\n pos.x = N;\n } else {\n for (var j = N; j >= 1; j--) {\n print(i, j);\n }\n\n pos.x = 1;\n }\n }\n\n for (var i = pos.y + 1; i <= M; i++) {\n if (pos.x === 1) {\n for (var j = 1; j <= N; j++) {\n print(j, i);\n }\n pos.x = N;\n } else {\n for (var j = N; j >= 1; j--) {\n print(i, j);\n }\n\n pos.x = 1;\n }\n }\n};\n\nmain();\n"}], "src_uid": "ed26479cdf72ad9686bbf334d90aa0be"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n for (let t = 0; t < testcases; t++) {\r\n const n = parseInt(arr[t]);\r\n if (n % 2 === 0) {\r\n console.log(0, 0, n / 2);\r\n } else {\r\n console.log(-1);\r\n }\r\n }\r\n});\r\n", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var value = parseInt(readline());\r\n var result = \"\"\r\n if (value % 2 === 0)\r\n {\r\n result = `${value/2} 0 0`;\r\n }\r\n else result = \"-1\"\r\n print(result)\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i];\n if(k % 2 === 0){\n console.log(0, k / 2, k / 2);\n }else{\n console.log(-1);\n }\n }\n});\n\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var x = parseInt(readline());\r\n if (x%2 === 0) {\r\n console.log(x/2,x/2,0);\r\n } else {\r\n console.log(-1);\r\n }\r\n\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n if (n & 1) return -1;\r\n return `0 ${n / 2} ${n / 2}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = Number(readline());\r\n\r\n let carry = (a, b, c) => {\r\n return [\r\n '1' + a,\r\n '1' + b,\r\n '0' + c\r\n ];\r\n };\r\n\r\n let dontCarry = (a, b, c) => {\r\n return [\r\n '0' + a,\r\n '0' + b,\r\n '0' + c\r\n ];\r\n }\r\n\r\n const bits = n.toString(2).split('').reverse().join(''); \r\n let a = '';\r\n let b = '';\r\n let c = '';\r\n\r\n if (bits[0] === '1') {\r\n output(-1);\r\n continue;\r\n }\r\n\r\n for (let bit = 1; bit < bits.length; bit++) {\r\n if (bits[bit] === '1') {\r\n [a, b, c] = carry(a, b, c);\r\n } else {\r\n [a, b, c] = dontCarry(a, b, c);\r\n }\r\n }\r\n\r\n a = parseInt(a, 2);\r\n b = parseInt(b, 2);\r\n c = parseInt(c, 2);\r\n\r\n output(`${a} ${b} ${c}`);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #804 (Div. 2)\n2022-07-04\n\nA. The Third Three Number Problem\n***/\n\nfunction main() {\n const t = parseInt(readline());\n\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n\n if (n % 2 == 0) {\n console.log(`${0} ${n / 2} ${(n, n / 2)}`);\n } else {\n console.log(\"-1\");\n }\n }\n}\n\nfunction formula(a, b, c) {\n return (a ^ b) + (b ^ c) + (a ^ c);\n}\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n var k = lines[i];\n if(k % 2 === 0){\n console.log(0, k / 2, k / 2);\n }else{\n console.log(-1);\n }\n }\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], c = k[2];\n console.log(a + b + c, b + c, c);\n }\n});\n\n"}], "src_uid": "43041076ddd0bbfac62cd4abf4536282"} {"source_code": "function solve() {\r\n var [l, r] = readArray(BigInt);\r\n var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l))));\r\n while(firstSqrt * firstSqrt < l) {\r\n firstSqrt = firstSqrt + 1n;\r\n }\r\n var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r))));\r\n while (lastSqrt * lastSqrt + 2n * lastSqrt > r) {\r\n lastSqrt = lastSqrt - 1n;\r\n }\r\n var prevFirstSqrt = firstSqrt - 1n;\r\n var afterLastSqrt = lastSqrt + 1n;\r\n var ans = 0n;\r\n if (firstSqrt <= lastSqrt) {\r\n ans = (lastSqrt - firstSqrt + 1n) * 3n;\r\n }\r\n [\r\n prevFirstSqrt * prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,\r\n afterLastSqrt * afterLastSqrt,\r\n afterLastSqrt * afterLastSqrt + afterLastSqrt,\r\n afterLastSqrt * afterLastSqrt + 2n * afterLastSqrt\r\n ].filter((x, i, a) => a.indexOf(x) === i).forEach((canBeAns) => {\r\n if (canBeAns >= l && canBeAns <= r) {\r\n ans = ans + 1n;\r\n }\r\n });\r\n write(ans);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [l, r] = BInpArr();\r\n let st = sqrt(l),\r\n end = sqrt(r);\r\n const helper = (val, i) => {\r\n let ans = 0;\r\n for (let j = 0; j < 3; j++, val += i) {\r\n if (val >= l && val <= r) ans++;\r\n }\r\n return ans;\r\n };\r\n if (end - st >= 4n) {\r\n let to = end - st + 1n - 2n;\r\n to = to * 3n;\r\n to += BigInt(helper(st * st, st));\r\n to += BigInt(helper(end * end, end));\r\n console.log(to + \"\");\r\n } else {\r\n let ans = 0;\r\n for (let i = st; i <= end; i++) {\r\n let val = i * i;\r\n ans += helper(val, i);\r\n }\r\n console.log(ans);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const l = rb(),\r\n r = rb();\r\n const sqrt = n => {\r\n let l = 1n,\r\n r = n;\r\n while (l < r) {\r\n const m = (l + r + 1n) / 2n;\r\n if (m * m <= n) {\r\n l = m;\r\n } else {\r\n r = m - 1n;\r\n }\r\n }\r\n return l;\r\n };\r\n const calc = n => {\r\n const a = sqrt(n);\r\n let res = (a - 1n) * 3n;\r\n for (let i = a; i <= a + 2n; i++) {\r\n if (i * a > n) break;\r\n res++;\r\n }\r\n return res;\r\n };\r\n return calc(r) - calc(l - 1n);\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "function solve() {\r\n var [l, r] = readArray(BigInt);\r\n var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));\r\n var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));\r\n var ans = 0n;\r\n if (lastSqrt > firstSqrt) {\r\n ans = (lastSqrt - firstSqrt) * 3n;\r\n }\r\n var prevFirstSqrt = firstSqrt - 1n;\r\n if (lastSqrt < firstSqrt) {\r\n prevFirstSqrt = lastSqrt - 1n;\r\n }\r\n [\r\n prevFirstSqrt * prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,\r\n lastSqrt * lastSqrt,\r\n lastSqrt * lastSqrt + lastSqrt,\r\n lastSqrt * lastSqrt + 2n * lastSqrt\r\n ].forEach((canBeAns) => {\r\n if (canBeAns >= l && canBeAns <= r) {\r\n ans = ans + 1n;\r\n }\r\n });\r\n write(ans);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "function solve() {\r\n var [l, r] = readArray(BigInt);\r\n var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));\r\n var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));\r\n var ans = 0n;\r\n if (lastSqrt < firstSqrt) {\r\n [\r\n lastSqrt * lastSqrt,\r\n lastSqrt * lastSqrt + lastSqrt,\r\n lastSqrt * lastSqrt + 2n * lastSqrt\r\n ].forEach((canBeAns) => {\r\n if (canBeAns >= l && canBeAns <= r) {\r\n ans = ans + 1n;\r\n }\r\n });\r\n write(ans);\r\n return;\r\n }\r\n ans = (lastSqrt - firstSqrt) * 3n;\r\n var prevFirstSqrt = firstSqrt - 1n;\r\n [\r\n prevFirstSqrt * prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,\r\n lastSqrt * lastSqrt,\r\n lastSqrt * lastSqrt + lastSqrt,\r\n lastSqrt * lastSqrt + 2n * lastSqrt\r\n ].forEach((canBeAns) => {\r\n if (canBeAns >= l && canBeAns <= r) {\r\n ans = ans + 1n;\r\n }\r\n });\r\n write(ans);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "function solve() {\r\n var [l, r] = readArray(BigInt);\r\n var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));\r\n var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));\r\n var ans = (lastSqrt - firstSqrt) * 3n;\r\n var prevFirstSqrt = firstSqrt - 1n;\r\n [\r\n prevFirstSqrt * prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,\r\n prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,\r\n lastSqrt * lastSqrt,\r\n lastSqrt * lastSqrt + lastSqrt,\r\n lastSqrt * lastSqrt + 2n * lastSqrt\r\n ].forEach((canBeAns) => {\r\n if (canBeAns >= l && canBeAns <= r) {\r\n ans = ans + 1n;\r\n }\r\n });\r\n write(ans); \r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "src_uid": "10812427d3052ce91cd0951911d3acb9"} {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet element = [];\nlet Mishka = 0;\nlet Chris = 0;\nrl.on(\"line\", item => {\n if (!item) return rl.close();\n\n element.push(item);\n}).on(\"close\", solveProblem);\n\nfunction solveProblem() {\n // let test = element.splice(0, 1);\n element.splice(0, 1);\n element.forEach(x => {\n let temp = x.split(\" \").map(num => parseInt(num));\n let Mi = temp[0];\n let Ci = temp[1];\n\n if (Mi > Ci) Mishka++;\n if (Mi < Ci) Chris++;\n });\n\n const result =\n Mishka === Chris\n ? \"Friendship is magic!^^\"\n : Mishka > Chris\n ? \"Mishka\"\n : \"Chris\";\n\n console.log(result);\n}", "positive_code": [{"source_code": "function cmp(x){\n\treturn parseInt(x);\n}\nvar n = parseInt(readline());\nvar a = [];\nfor(var i = 0; i < n; i++){\n\ta[i] = readline().split(\" \").map(cmp);\n}\nvar awin = 0, bwin = 0;\n\tvar result='';\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\tif(a[i][0] > a[i][1]){\n\t\t\tawin ++;\n\t\t}\n\t\telse if(a[i][0] < a[i][1]){\n\t\t\tbwin ++;\n\t\t}\n\t\telse{\n\t\t\tcontinue;\n\t\t}\n\t}\n\tif(awin > bwin){\n\t\tresult='Mishka';\n\t}\n\telse if(awin < bwin){\n\t\tresult='Chris';\n\t}\n\telse{\n\t\tresult='Friendship is magic!^^';\n\t}\n\tprint(result);"}, {"source_code": "var res = sol(readline());\nprint(res);\n\nfunction sol(line1) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n\n var mishka = 0;\n var chris = 0;\n\n while (n > 0) {\n var line = readline().split(\" \").map((x) => Number(x));\n\n if (line[0] > line[1]) {\n mishka++;\n } else if (line[0] < line[1]) {\n chris++;\n }\n\n n--;\n }\n\n var winner = \"\";\n if (mishka > chris) {\n winner = \"Mishka\";\n } else if (mishka < chris) {\n winner = \"Chris\";\n } else {\n winner = \"Friendship is magic!^^\";\n }\n\n return winner;\n}"}, {"source_code": "(function() {\n 'use strict';\n const n = readline();\n let m = 0;\n let c = 0;\n for (let i = 0; i < n; ++i) {\n const z = readline().split(' ').map(Number);\n if (z[0] > z[1]) {\n m += 1;\n } else if (z[0] < z[1]) {\n c += 1;\n }\n }\n if (m > c) {\n print('Mishka');\n } else if (m < c) {\n print('Chris');\n } else {\n print('Friendship is magic!^^');\n }\n \n \n}());"}, {"source_code": "var n = +readline();\nvar obj = {}, str, b = false, res = 0, a, b;\n\nfor(var i = 0; i < n; i++) {\n str = readline().split(' ');\n a = +str[0]; b = +str[1];\n if (a > b) res++;\n if (a < b) res--;\n}\n\nif (res == 0)\n print(\"Friendship is magic!^^\");\nelse if (res > 0)\n print(\"Mishka\");\nelse\n print(\"Chris\");\n//print(res);\n"}, {"source_code": "var n = readline();\nvar a = [];\nvar i = 0;\nvar count_m = 0,\n count_c = 0;\nwhile (i < n) {\n a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\n if (a[0] > a[1]) {\n count_m++;\n } else if (a[0] < a[1]) {\n count_c++;\n }\n i++;\n}\nif (count_m > count_c) print(\"Mishka\");\nelse if (count_c > count_m) print(\"Chris\");\nelse print(\"Friendship is magic!^^\");"}, {"source_code": "n=Number(readline())\nmishka=0,chris=0\nfor (var i=0;iscore[1]){\n mishka++;\n } \n else if (score[0]chris){\n print('Mishka');\n} \nelse if (mishkac){\n mishka+=1;\n }else if (mchris){\n name='Mishka';\n }else if (mishka input.push(line));\n\nreadLine.on('close', () => {\n let mishkaWins = 0\n let chrisWins = 0\n let friend = 0\n let result = 'Friendship is magic!^^'\n const games = [...input.slice(1)]\n games.forEach(item => {\n const res = item.split(' ')\n let mishka = parseInt(res[0], 10)\n let chris = parseInt(res[1], 10)\n if (mishka > chris)\n mishkaWins++\n else if (chris > mishka)\n chrisWins++\n else\n friend++\n })\n if (mishkaWins !== 0 || chrisWins !== 0) {\n if (mishkaWins > chrisWins) {\n result = 'Mishka'\n } else if (mishkaWins < chrisWins) {\n result = 'Chris'\n }\n }\n console.log(result)\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var Mishka = 0;\n var Chris = 0;\n for(var i = 0; i < N; i++){\n var tmp = nextIntArray();\n if(tmp[0] > tmp[1]){\n Mishka++;\n }else if(tmp[0] < tmp[1]){\n Chris++;\n }\n }\n if(Mishka > Chris){\n myout(\"Mishka\");\n }else if(Mishka < Chris){\n myout(\"Chris\");\n }else{\n myout(\"Friendship is magic!^^\");\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet x = y = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n\n if (a > b) {\n x++;\n }\n else if (b > a) {\n y++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (x > y) {\n console.log('Mishka');\n }\n else if (y > x) {\n console.log('Chris');\n }\n else {\n console.log('Friendship is magic!^^');\n }\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n] = input[0].split(' ').map(x => parseInt(x));\n let m = 0, c = 0;\n\n input.forEach((x, i) => {\n if (i === 0) return;\n const nums = x.split(' ').map(x => parseInt(x));\n if (nums[0] > nums[1]) m += 1;\n else if (nums[0] < nums[1]) c += 1;\n });\n\n if (m === c) console.log(`Friendship is magic!^^`)\n else if (m > c) console.log(`Mishka`)\n else console.log(`Chris`)\n}); \n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let rounds = +inputs[0];\n let roundScores = inputs.slice(1);\n let win = 0;\n let msg = 'Mishka';\n while (rounds--) {\n let roundScore = roundScores[rounds];\n let score = splitter(roundScore, ' ');\n if (+score[0] > +score[1]) {\n win++;\n }\n else if (+score[0] < +score[1]) {\n win--;\n }\n }\n\n if (win > 0) {\n msg = 'Mishka';\n }\n else if (win < 0) {\n msg = 'Chris';\n }\n else {\n msg = 'Friendship is magic!^^';\n }\n\n return msg.toString();\n}\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let am = 0;\n let ac = 0;\n for (var i = 0; i < n; i++) {\n let mc = readLine().split(' ').map(v => parseInt(v))\n let m = mc[0];\n let c = mc[1];\n if (m > c) {\n am++;\n } else if (m < c) {\n ac++;\n }\n }\n if (am > ac) {\n console.log('Mishka');\n } else if (am == ac) {\n console.log('Friendship is magic!^^');\n } else {\n console.log('Chris');\n }\n}"}, {"source_code": "var n = readline();\nvar m =0; var chris = 0;\nfor (var i=0; istr[1])\n\t\tm++;\n\telse if (str[0]chris)\n\t\tprint(\"Mishka\");\n\telse if (m b) return 'm';\n}\n\nfor (var i = 0; i < roundsCount; i++) {\n\tvar results = readline().split(' ').map(function (result) {\n\t\treturn parseInt(result);\n\t});\n\twins[getWinner(results[0], results[1])]++;\n}\n\nif (wins['m'] === wins['c']) {\n\tprint('Friendship is magic!^^');\n} else if (wins['m'] > wins['c']) {\n\tprint('Mishka');\n} else if (wins['m'] < wins['c']) {\n\tprint('Chris');\n}\n"}, {"source_code": "var N = +readline(),\n f = 0, s = 0, arr,\n w1 = 'Mishka',\n w2 = 'Chris',\n w3 = 'Friendship is magic!^^';\n\nwhile (N--) {\n arr = readline().split(' ');\n f += arr[0] >= arr[1] ? 1 : 0;\n s += arr[0] <= arr[1] ? 1 : 0;\n}\n\nprint(f === s ? w3 : (f > s ? w1 : w2));"}, {"source_code": "var nline = readline();\nvar n = parseInt(nline);\n\nvar count = 0;\n\nfor(i=0;ic){\n\tcount+=1;\n } else if(m0){\n print('Mishka');\n} else if(count<0){\n print('Chris');\n}else{\n print('Friendship is magic!^^');\n}"}, {"source_code": "\"use strict\";\n\nvar main = function() {\n var n = +rd();\n var r = 0;\n \n for (var i = 0; i < n; ++i) {\n var input = rdAr();\n var m = input[0];\n var c = input[1];\n r += Math.sign(c - m);\n }\n\n wr(['Mishka', 'Friendship is magic!^^', 'Chris'][Math.sign(r) + 1]);\n};\n\nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n\nmain();"}, {"source_code": "n=Number(readline())\nm=0,c=0\nfor (var i=0;iX[1]) ++m\n else if (X[0]c) print('Mishka')\nelse if (m d[1];\n c += d[0] < d[1];\n}\n\nif (m > c) {\n write('Mishka');\n} else if (m < c) {\n write('Chris');\n} else {\n write('Friendship is magic!^^');\n}\n"}, {"source_code": "// var n = 3;\n\nvar n = parseInt(readline());\nvar m = 0;\nvar c = 0;\n\n// var a = [[3,3], [2,2], [4,4]];\n\nfor (var i = 0; i arr[1]) {\n ++m;\n } else if (arr[0] < arr[1]) {\n ++c;\n }\n}\n\nif (m > c) {\n write(\"Mishka\");\n} else if(m round[1]){\n mishka++;\n }\n else if(round[1] > round[0]){\n chris++;\n }\n}\nif(mishka === chris){\n print(\"Friendship is magic!^^\")\n}\nelse if(mishka > chris){\n print(\"Mishka\");\n}\nelse {\n print(\"Chris\")\n}"}, {"source_code": "var n = +readline();\n\nvar mc = 0, cc = 0;\nfor(var i = 0; i < n; i++){\n var input = readline().split(\" \").map(Number);\n var m = input[0], c = input[1];\n\n if(m > c){\n mc++;\n }else if(m < c){\n cc++;\n }\n}\n\nif(mc > cc){\n write(\"Mishka\");\n}else if(mc < cc){\n write(\"Chris\");\n}else{\n write(\"Friendship is magic!^^\");\n}"}], "negative_code": [{"source_code": "function cmp(x){\n\treturn parseInt(x);\n}\nfunction main(){\n\tvar n = parseInt(readline());\n\tvar a = [];\n\tfor(var i = 0; i < n; i++){\n\t\ta[i] = readline().split(\" \").map(cmp);\n\t}\n\tvar temp = test(a);\n\tprint(temp);\n}\nfunction test(){\n\t//var a =[[3,5],[1,2],[4,2]];\n\tvar awin = 0, bwin = 0;\n\tvar result='';\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\tif(a[i][0] > a[i][1]){\n\t\t\tawin ++;\n\t\t}\n\t\telse if(a[i][0] < a[i][1]){\n\t\t\tbwin ++;\n\t\t}\n\t\telse{\n\t\t\tcontinue;\n\t\t}\n\t}\n\tif(awin > bwin){\n\t\tresult='Mishka';\n\t}\n\telse if(awin < bwin){\n\t\tresult='Chris';\n\t}\n\telse{\n\t\tresult='Friendship is magic!^^';\n\t}\n\treturn result;\n}"}, {"source_code": "var roundsCount = parseInt(readline(), 10);\nvar wins = {\n\tf: 0,\n\tm: 0,\n\tc: 0,\n};\n\nfunction getWinner(a, b) {\n\tif (a === b) return 'f';\n\tif (a < b) return 'c';\n\tif (a > b) return 'm';\n}\n\nfor (var i = 0; i < roundsCount; i++) {\n\tvar results = readline().split(' ').map((result) => parseInt(result));\n\twins[getWinner(results[0], results[1])]++;\n}\n\nvar sortedResults = Object\n\t.keys(wins)\n\t.sort((a, b) => wins[a] - wins[b]);\n\nvar resultsHash = {\n\tf: 'Friendship is magic!^^',\n\tm: 'Mishka',\n\tc: 'Chris',\n};\n\nprint(resultsHash[sortedResults[0]]);\n"}, {"source_code": "var roundsCount = parseInt(readline(), 10);\nvar wins = {\n\tf: 0,\n\tm: 0,\n\tc: 0,\n};\n\nfunction getWinner(a, b) {\n\tif (a === b) return 'f';\n\tif (a < b) return 'c';\n\tif (a > b) return 'm';\n}\n\nfor (var i = 0; i < roundsCount; i++) {\n\tvar results = readline().split(' ').map((result) => parseInt(result));\n\twins[getWinner(results[0], results[1])]++;\n}\n\nvar sortedResults = Object\n\t.keys(wins)\n\t.sort((a, b) => wins[a] - wins[b]);\n\nvar resultsHash = {\n\tf: 'Friendship is magic!^^',\n\tm: 'Mishka',\n\tc: 'Chris',\n};\n\nprint(resultsHash[sortedResults[0]]);"}, {"source_code": "var N = 3, f = 0, s = 0, arr,\n w1 = 'Mishka',\n w2 = 'Chris',\n w3 = 'Friendship is magic!^^';\n\nwhile (N--) {\n arr = readline().split(' ');\n f += arr[0] >= arr[1] ? 1 : 0;\n s += arr[0] <= arr[1] ? 1 : 0;\n}\n\nprint(f === s ? w3 : (f > s ? w1 : w2));"}], "src_uid": "76ecde4a445bbafec3cda1fc421e6d42"} {"source_code": "var t = Number(readline());\nvar n;\nvar a;\nvar obj = {\n even: 0,\n odd: 0\n}\nfor(var i = 0 ; i < t; i++){\n n = Number(readline());\n obj.even = 0;\n obj.odd = 0;\n a = readline().split(\" \").map(cur => {\n Number(cur)%2 === 0 ? obj.even++ : obj.odd++ ; \n } );\n\n (obj.even !== 0 && obj.odd !== 0) ? print(\"NO\") : print(\"YES\");\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t-- > 0) {\n const n = getInt()\n const arr = getInts()\n let ok = true\n\n const mx = arr.reduce((out, cur) => {\n return Math.max(out, cur)\n }, 0)\n\n for (let i in arr) {\n if ((mx - arr[i]) % 2) ok = false\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;r Number(x));\n var m = Math.max.apply(null, a);\n for(var i=0; iNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var odd = 0;\n var even = 0;\n for(var j = 0; j < n; j++){\n if(list[j] % 2 == 0){\n even++;\n }else{\n odd++;\n }\n }\n if(odd != 0 && even != 0){\n output[i] = \"NO\";\n }else{\n output[i] = \"YES\";\n }\n }\n myout(myconv(output,9));\n}"}, {"source_code": "var toInt = x =>parseInt(x);\n\nvar t = parseInt(readline());\n\nfor(var tt=0;tt (Math.max(i, j)) );\n var pass = true;\n //print(a.join(' '))\n a.forEach( v => (pass &= (max-v)%2 === 0 ) );\n print(pass ? \"YES\":\"NO\");\n \n}\n\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let t = readInt(input)\n while(t--) {\n const n = readInt(input)\n const aI = readInts(input)\n let max = Math.max(...aI)\n let f = false\n for(let i = 0; i < n && !f; i++) {\n if((max - aI[i]) % 2 === 1) f = true\n }\n if(f) wr('NO')\n else wr('YES')\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let isOdd = false;\n let isEven = false;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] % 2) {\n isOdd = true;\n }\n else {\n isEven = true;\n }\n }\n\n if (isOdd && isEven) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "var t = readline();\nfor (var i = 0; i { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\n\nfunction main(){\n\tlet tests = parseInt(readline())\n\tfor (let i = 0; i < tests; i++) {\n\t\tlet num = parseInt(readline());\n\t\tlet arr = readline().split(' ').map(x => parseInt(x))\n\t\tlet od = 0, ev = 0;\n\t\tarr.forEach(x => {\n\t\t\tif (x & 1) od++;\n\t\t\telse ev++;\n\t\t});\n\t\tif (!ev || !od) console.log(\"YES\");\n\t\telse console.log(\"NO\");\n\t}\n}\n"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline();\n var nums = str.split(' ').map(Number);\n var ost = nums[0] % 2\n var not = nums.find(num => num % 2 !== ost)\n print(not ? 'NO' : 'YES')\n}\n"}, {"source_code": "var t = Number(readline());\nvar n;\nvar a;\nvar obj = {\n even: 0,\n odd: 0\n}\nfor(var i = 0 ; i < t; i++){\n n = Number(readline());\n obj.even = 0;\n obj.odd = 0;\n a = readline().split(\" \").map(cur => {\n Number(cur)%2 === 0 ? obj.even++ : obj.odd++ ; \n } );\n\n (obj.even !== 0 && obj.odd !== 0) ? print(\"NO\") : print(\"YES\");\n}\n//"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input })\nprocess.stdin.on('end', _ => { inputString.trim().split('\\n').map(str => str.trim()) })\nconst readline = () => { return inputString[currentLine++] }\n\nlet tests = parseInt(readline())\nfor(let i = 0; i < tests; i++){\n\tlet num = parseInt(readline());\n\tlet arr = readline().split(' ').map(x => parseInt(x))\n\tlet od = 0, ev = 0;\n\tarr.forEach(x => {\n\t\tif(x & 1) od++;\n\t\telse ev++;\n\t});\n\tif(!ev || !od) console.log(\"YES\");\n\telse console.log(\"NO\");\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 5\n let ok = false\n while (limit --> 0 && !ok) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n\n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n } else {\n arr[i] ++\n arr[i] ++\n }\n\n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 333\n let ok = false\n while (limit --> 0) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n \n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n }\n \n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n \n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t-- > 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 33\n let ok = false\n let mx = 0\n for (let i in arr) {\n mx = Math.max(mx, arr[i])\n }\n\n while (limit-- > 0 && !ok) {\n for (let i = 0; i < n; ++i) {\n if (arr[i] < mx) {\n arr[i] += 2\n\n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n\n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 1000\n let ok = false\n while (limit --> 0 && !ok) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n\n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n } else {\n arr[i] ++\n arr[i] ++\n }\n\n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 333\n let ok = false\n while (limit --> 0) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n\n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n } else {\n arr[i] ++\n arr[i] ++\n }\n\n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 333\n let ok = false\n while (limit --> 0 && !ok) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n \n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n }\n \n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n \n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let limit = 1000\n let ok = false\n while (limit --> 0 && !ok) {\n let mm = 1e9\n for (let i in arr) {\n mm = Math.min(mm, arr[i])\n }\n \n for (let i = 0; i < n; ++i) {\n if (arr[i] === mm) {\n if (i + 1 < n && arr[i + 1] === mm) {\n arr[i] ++\n arr[i + 1] ++\n }\n \n const st = new Set(arr)\n if (st.size === 1) {\n ok = true\n break\n }\n }\n }\n }\n \n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n let ok = true\n\n for (let i = 1; i + 1 < n; ++i) {\n const a = Math.abs(arr[i] - arr[i - 1])\n const b = Math.abs(arr[i] - arr[i + 1])\n if (a === b && a === 1) {\n ok = false\n break\n }\n }\n\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = [1e9, ...getInts(), 1e9]\n let ok = true\n \n for (let i = 1; i + 1 < arr.length; ++i) {\n if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {\n ok = false\n break\n }\n }\n\n if (n === 1) ok = true\n print(ok ? 'YES' : 'NO')\n }\n}\n\n"}, {"source_code": "var t = readline();\nfor (var i = 0; i {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const grid = lines.slice(l, l + n).map(str => str.trim())\r\n l += n\r\n output[i] = solve(n, m, grid) ? 'YES' : 'NO'\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, grid) {\r\n const ns = []\r\n for (let i = 0; i < n; i++) {\r\n ns[i] = []\r\n for (let j = 0; j < m; j++) {\r\n ns[i][j] = count(i, j)\r\n }\r\n }\r\n // console.log(ns)\r\n //\r\n let one = 0\r\n let two = 0\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (grid[i][j] === '.') continue\r\n const [c4, c8] = ns[i][j]\r\n // console.log(i, j, c4, c8)\r\n if (c4 === 2) {\r\n if (c8 !== 2) return false\r\n two++\r\n } else if (c4 === 1) {\r\n if (c8 !== 2) return false\r\n one++\r\n } else {\r\n return false\r\n }\r\n }\r\n }\r\n // console.log(one, two)\r\n return one === two * 2\r\n //\r\n function count(i, j) {\r\n const r = []\r\n let c = 0\r\n if (i + 1 < n && grid[i + 1][j] === '*') c++\r\n if (i - 1 >= 0 && grid[i - 1][j] === '*') c++\r\n if (j + 1 < m && grid[i][j + 1] === '*') c++\r\n if (j - 1 >= 0 && grid[i][j - 1] === '*') c++\r\n r.push(c)\r\n if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++\r\n if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++\r\n if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++\r\n if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++\r\n r.push(c)\r\n return r\r\n }\r\n}\r\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\nvar vis = []\r\nvar di = [-1, -1, -1, 0, 1, 1, 1, 0];\r\nvar dj = [-1, 0, 1, 1, 1, 0, -1, -1];\r\nfunction Queue(){\r\n this.arr = [];\r\n this.front = 0;\r\n this.rear = -1;\r\n \r\n this.top = function(){\r\n return this.arr[this.front];\r\n }\r\n this.push = function(el){\r\n this.arr.push(el)\r\n this.rear++;\r\n }\r\n this.pop = function (){\r\n var top = this.top();\r\n this.front++;\r\n return top;\r\n }\r\n this.empty = function(){\r\n return this.rear < this.front\r\n }\r\n}\r\nfunction inBounds(i, j, arr){\r\n return i >= 0 && i < arr.length && j >= 0 && j < arr[0].length;\r\n}\r\n\r\nfunction bfs(i, j, arr){\r\n \r\n var q = new Queue();\r\n var allP = [];\r\n \r\n q.push({i, j});\r\n vis[i][j] = true;\r\n allP.push(q.top());\r\n while(!q.empty()){\r\n var crnt = q.pop();\r\n \r\n for(var x = 0; x < di.length; x++){\r\n var newI = crnt.i + di[x];\r\n var newJ = crnt.j + dj[x];\r\n if(inBounds(newI, newJ, arr) && arr[newI][newJ] === \"*\" && !vis[newI][newJ]){\r\n vis[newI][newJ] = true;\r\n q.push({i: newI, j: newJ});\r\n allP.push({i: newI, j: newJ})\r\n }\r\n }\r\n \r\n }\r\n if(allP.length === 3){\r\n var iS = allP.map((a) => a.i)\r\n var jS = allP.map((a) => a.j)\r\n var iDiff = Math.max(...iS) - Math.min(...iS)\r\n var jDiff = Math.max(...jS) - Math.min(...jS)\r\n \r\n if(iDiff === 1 && jDiff === 1) return true;\r\n \r\n }\r\n return false;\r\n\r\n}\r\n\r\n\r\nwhile(t--){\r\n \r\n var nm = readline().split(\" \").map((a) => parseInt(a));\r\n \r\n var n = nm[0];\r\n var m = nm[1];\r\n var shapes = [];\r\n \r\n for(var i = 0; i < n; i++){\r\n shapes.push(readline());\r\n vis[i] = new Array(m).fill(false);\r\n }\r\n \r\n var allIsL = true;\r\n for(var i = 0; i < n; i++){\r\n for(var j = 0; j < m; j++){\r\n if(shapes[i][j] === \"*\" && !vis[i][j]){\r\n if(!bfs(i, j, shapes))allIsL = false;\r\n }\r\n }\r\n }\r\n \r\n allIsL? print(\"YES\") : print(\"NO\");\r\n\r\n \r\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\nvar vis = []\r\nvar di = [-1, -1, -1, 0, 1, 1, 1, 0];\r\nvar dj = [-1, 0, 1, 1, 1, 0, -1, -1];\r\nfunction Queue(){\r\n this.arr = [];\r\n this.front = 0;\r\n this.rear = -1;\r\n \r\n this.top = function(){\r\n return this.arr[this.front];\r\n }\r\n this.push = function(el){\r\n this.arr.push(el)\r\n this.rear++;\r\n }\r\n this.pop = function (){\r\n var top = this.top();\r\n this.front++;\r\n return top;\r\n }\r\n this.empty = function(){\r\n return this.rear < this.front\r\n }\r\n}\r\nfunction inBounds(i, j, arr){\r\n return i >= 0 && i < arr.length && j >= 0 && j < arr[0].length;\r\n}\r\n\r\nfunction bfs(i, j, arr){\r\n \r\n var q = new Queue();\r\n var h = 0, v = 0, cells = 1;\r\n \r\n q.push({i, j});\r\n vis[i][j] = true;\r\n while(!q.empty()){\r\n var crnt = q.pop();\r\n \r\n\r\n for(var x = 0; x < di.length; x++){\r\n var newI = crnt.i + di[x];\r\n var newJ = crnt.j + dj[x];\r\n if(inBounds(newI, newJ, arr) && arr[newI][newJ] === \"*\" && !vis[newI][newJ]){\r\n vis[newI][newJ] = true;\r\n q.push({i: newI, j: newJ});\r\n h += Math.abs(i - newI);\r\n v += Math.abs(j - newJ);\r\n cells++;\r\n }\r\n }\r\n \r\n }\r\n return (cells === 3 && h && v && h+v <= 3)? true : false;\r\n \r\n}\r\n\r\n\r\nwhile(t--){\r\n \r\n var nm = readline().split(\" \").map((a) => parseInt(a));\r\n \r\n var n = nm[0];\r\n var m = nm[1];\r\n var shapes = [];\r\n \r\n for(var i = 0; i < n; i++){\r\n shapes.push(readline());\r\n vis[i] = new Array(m).fill(false);\r\n }\r\n \r\n var allIsL = true;\r\n for(var i = 0; i < n; i++){\r\n for(var j = 0; j < m; j++){\r\n if(shapes[i][j] === \"*\" && !vis[i][j]){\r\n if(!bfs(i, j, shapes))allIsL = false;\r\n }\r\n }\r\n }\r\n \r\n allIsL? print(\"YES\") : print(\"NO\");\r\n\r\n \r\n}"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const grid = lines.slice(l, l + n).map(str => str.trim())\r\n l += n\r\n output[i] = solve(n, m, grid) ? 'YES' : 'NO'\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, grid) {\r\n const ns = []\r\n for (let i = 0; i < n; i++) {\r\n ns[i] = []\r\n for (let j = 0; j < m; j++) {\r\n ns[i][j] = count(i, j)\r\n }\r\n }\r\n // console.log(ns)\r\n //\r\n let one = 0\r\n let two = 0\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (grid[i][j] === '.') continue\r\n const [c4, c8] = ns[i][j]\r\n // console.log(i, j, c4, c8)\r\n if (c4 === 2) {\r\n if (c8 !== 2) return false\r\n two++\r\n } else if (c4 === 1) {\r\n if (c8 !== 2) return false\r\n one++\r\n } else {\r\n return false\r\n }\r\n }\r\n }\r\n // console.log(one, two)\r\n return one * 2 === two\r\n //\r\n function count(i, j) {\r\n const r = []\r\n let c = 0\r\n if (i + 1 < n && grid[i + 1][j] === '*') c++\r\n if (i - 1 >= 0 && grid[i - 1][j] === '*') c++\r\n if (j + 1 < m && grid[i][j + 1] === '*') c++\r\n if (j - 1 >= 0 && grid[i][j - 1] === '*') c++\r\n r.push(c)\r\n if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++\r\n if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++\r\n if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++\r\n if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++\r\n r.push(c)\r\n return r\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, m, grid) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n const ns = []\n for (let i = 0; i < n; i++) {\n ns[i] = []\n for (let j = 0; j < m; j++) {\n ns[i][j] = count(i, j)\n }\n }\n // console.log(ns)\n //\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === '.') continue\n const [c4, c8] = ns[i][j]\n // console.log(i, j, c4, c8)\n if (c4 === 2) {\n if (c8 !== 2) return false\n } else if (c4 === 1) {\n if (c8 !== 2) return false\n } else {\n return false\n }\n }\n }\n return true\n //\n function count(i, j) {\n const r = []\n let c = 0\n if (i + 1 < n && grid[i + 1][j] === '*') c++\n if (i - 1 >= 0 && grid[i - 1][j] === '*') c++\n if (j + 1 < m && grid[i][j + 1] === '*') c++\n if (j - 1 >= 0 && grid[i][j - 1] === '*') c++\n r.push(c)\n if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++\n if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++\n if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++\n if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++\n r.push(c)\n return r\n }\n}\n"}], "src_uid": "6a06ad39dbdd97ca8654023009c89a42"} {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar preSum = 0;\nvar A = [];\nfor (var i = 0; i < n; ++i) {\n A.push(+readline());\n preSum += Math.floor(A[i]);\n}\n\nfor (var i = 0; i < n; ++i) {\n if (preSum < 0) {\n write(Math.ceil(A[i]));\n if (Math.floor(A[i]) < Math.ceil(A[i])) {\n preSum += 1;\n }\n } else {\n write(Math.floor(A[i]));\n }\n write('\\n');\n}", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var res = '';\n var b = 0, m = 0;\n var mas = [];\n for(var i = 0; i < n; i++) {\n mas[i] = read.number();\n if(mas[i] > 0) {\n b += Math.floor( mas[i] );\n }\n else {\n m += Math.ceil( mas[i] );\n }\n }\n\n if(b + m === 0) {\n for(var i = 0; i < n; i++) {\n var a = mas[i]\n if(a > 0) {\n a = Math.floor(a);\n }\n else {\n a = Math.ceil(a);\n }\n res += a + '\\n';\n }\n }\n else if(b + m > 0) {\n var c = b + m;\n for(var i = 0; i < n; i++) {\n var a = mas[i]\n if(a > 0) {\n a = Math.floor(a);\n }\n else {\n if(c && Math.ceil(a) !== a) {\n a = Math.floor(a);\n c--;\n }\n else {\n a = Math.ceil(a);\n }\n }\n res += a + '\\n';\n }\n }\n else if(b + m < 0) {\n var c = b + m;\n for(var i = 0; i < n; i++) {\n var a = mas[i]\n if(a > 0) {\n if(c && Math.ceil(a) !== a) {\n a = Math.ceil(a);\n c++;\n }\n else {\n a = Math.floor(a);\n }\n }\n else {\n a = Math.ceil(a);\n }\n res += a + '\\n';\n }\n }\n print(res);\n}());"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var res = '';\n for(var i = 0; i < n; i++) {\n var a = read.number();\n if(a > 0) {\n a = Math.floor(a);\n }\n else {\n a = Math.ceil(a);\n }\n res += a + '\\n';\n }\n print(res);\n}());"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var res = '';\n var b = 0, m = 0;\n var mas = [];\n for(var i = 0; i < n; i++) {\n mas[i] = read.number();\n } \n for(var i = 0; i < n; i++) {\n var a = mas[i]\n if(a > 0) {\n a = Math.floor(a);\n b += a;\n }\n else {\n a = Math.ceil(a);\n m += a;\n }\n res += a + '\\n';\n }\n \n if(m + b !== 0) {\n var res = '';\n for(var i = 0; i < n; i++) {\n var a = mas[i]\n if(a > 0) {\n a = Math.ceil(a);\n b += a;\n }\n else {\n a = Math.floor(a);\n m += a;\n }\n res += a + '\\n';\n }\n }\n print(res);\n}());"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar preSum = 0;\nvar A = [];\nfor (var i = 0; i < n; ++i) {\n A.push(+readline());\n preSum += Math.floor(A[i]);\n}\n\nfor (var i = 0; i < n; ++i) {\n if (preSum > 0) {\n write(Math.ceil(A[i]));\n if (Math.floor(A[i]) < Math.ceil(A[i])) {\n preSum += 1;\n }\n } else {\n write(Math.floor(A[i]));\n }\n write('\\n');\n}"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar preSum = 0;\nvar A = [];\nfor (var i = 0; i < n; ++i) {\n A.push(+readline());\n preSum += Math.floor(A[i]);\n}\n\nfor (var i = 0; i < n; ++i) {\n if (A[i] * preSum > 0) {\n write(Math.ceil(A[i]));\n if (Math.floor(A[i]) < Math.ceil(A[i])) {\n preSum += 1;\n }\n } else {\n write(Math.floor(A[i]));\n }\n write('\\n');\n}"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar preSum = 0;\nvar A = [];\nfor (var i = 0; i < n; ++i) {\n A.push(+readline());\n preSum += Math.floor(A[i]);\n}\n\nfor (var i = 0; i < n; ++i) {\n if (preSum < 0) {\n write(Math.ceil(A[i]));\n preSum += 1;\n } else {\n write(Math.floor(A[i]));\n }\n write('\\n');\n}"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar preSum = 0;\nvar A = [];\nfor (var i = 0; i < n; ++i) {\n A.push(+readline());\n preSum += Math.floor(A[i]);\n}\n\nfor (var i = 0; i < n; ++i) {\n if (A[i] * preSum > 0) {\n write(Math.ceil(A[i]));\n preSum += 1;\n } else {\n write(Math.floor(A[i]));\n }\n write('\\n');\n}"}], "src_uid": "6059cfa13594d47b3e145d7c26f1b0b3"} {"source_code": "n = parseInt(readline());\nvar s = [];\nfor(var i = 0; i < n; i++)\n s[i] = parseInt(readline());\n\ns.sort(function(a, b) {return a - b;});\n// print(s);\n\nvar lb = 0, ub = Math.floor(n/2) + 1;\n\nfunction check(mid) {\n for(var i = 0; i < mid; i++)\n if(s[i] * 2 > s[n - mid + i])\n return false;\n return true;\n}\n\nwhile(ub - lb > 1) {\n var mid = Math.floor(lb + (ub - lb) / 2);\n // if(n === 77777)\n // print(lb, ub);\n if(check(mid))\n lb = mid;\n else\n ub = mid;\n}\n\nprint(n - lb);\n", "positive_code": [{"source_code": "var n = readline() - 0;\n\nvar a = new Array(n);\nfor (var i = 0; i < n; i++) a[i] = readline() - 0;\na.sort(function(i, j) {\n return i - j;\n});\n\nfunction search(n, f) {\n var i = 0;\n var j = n;\n\n while (i < j) {\n var h = i + (j - i) / 2 | 0;\n if (!f(h))\n i = h + 1;\n else\n j = h;\n }\n\n return i;\n}\n\nvar ans = search(n / 2 + 1 | 0, function(j) {\n if (j == n / 2 + 1 | 0) \n return true;\n if (j == 0)\n return false;\n\n for (var i = 0; i < j; i++)\n if (a[n - j + i] < a[i] * 2)\n return true;\n return false;\n});\n\nprint(n - ans + 1);"}], "negative_code": [{"source_code": "n = parseInt(readline());\nvar s = [];\nfor(var i = 0; i < n; i++)\n s[i] = parseInt(readline());\n\ns.sort(function(a, b) {return a - b;});\n// print(s);\n\nvar lb = 0, ub = n/2 + 1;\n\nfunction check(mid) {\n for(var i = 0; i < mid; i++)\n if(s[i] * 2 > s[n - mid + i])\n return false;\n return true;\n}\n\nwhile(ub - lb > 1) {\n var mid = Math.floor(lb + (ub - lb) / 2);\n // if(n === 77777)\n print(lb, ub);\n if(check(mid))\n lb = mid;\n else\n ub = mid;\n}\n\nprint(n - lb);\n"}, {"source_code": "n = parseInt(readline());\nvar s = [];\nfor(var i = 0; i < n; i++)\n s[i] = parseInt(readline());\n\ns.sort(function(a, b) {return a - b;});\n// print(s);\n\nif(n !== 77777) {\n\nvar lb = 0, ub = n/2 + 1;\n\nfunction check(mid) {\n for(var i = 0; i < mid; i++)\n if(s[i] * 2 > s[n - mid + i])\n return false;\n return true;\n}\n\nwhile(ub - lb > 1) {\n var mid = Math.floor(lb + (ub - lb) / 2);\n if(check(mid))\n lb = mid;\n else\n ub = mid;\n}\n\nprint(n - lb);\n} else {\n print(n);\n}"}, {"source_code": "n = parseInt(readline());\nvar s = [];\nfor(var i = 0; i < n; i++)\n s[i] = parseInt(readline());\n\ns.sort();\n// print s;\n\nvar lb = 0, ub = n/2 + 1;\n\nfunction check(mid) {\n for(var i = 0; i < mid; i++)\n if(s[i] * 2 > s[n - mid + i])\n return false;\n return true;\n}\n\nwhile(ub - lb > 1) {\n var mid = Math.floor(lb + (ub - lb) / 2);\n if(check(mid))\n lb = mid;\n else\n ub = mid;\n}\n\nprint(n - lb);"}, {"source_code": "var n = readline() - 0;\n\nvar a = readline().split(' ');\nfor (var i = 0; i < n; i++) a[i] = a[i] - 0;\na.sort(function(i, j) {\n return i - j;\n});\n\nfunction search(n, f) {\n var i = 0;\n var j = n;\n\n while (i < j) {\n var h = i + (j - i) / 2 | 0;\n if (!f(h))\n i = h + 1;\n else\n j = h;\n }\n\n return i;\n}\n\nvar ans = search(n / 2 + 1 | 0, function(j) {\n if (j == n / 2 + 1 | 0) \n return true;\n\n for (var i = 0; i < j; i++)\n if (a[n - j + i] < a[i] * 2)\n return true;\n return false;\n});\n\nprint(n - ans + 1);"}, {"source_code": "var n = readline() - 0;\n\nvar a = readline().split(' ');\nfor (var i = 0; i < n; i++) a[i] = a[i] - 0;\na.sort(function(i, j) {\n return i - j;\n});\n\nfunction search(n, f) {\n var i = 0;\n var j = n;\n\n while (i < j) {\n var h = i + (j - i) / 2 | 0;\n if (!f(h))\n i = h + 1;\n else\n j = h;\n }\n\n return i;\n}\n\nvar ans = search(n / 2 + 1 | 0, function(j) {\n if (j == n / 2 + 1 | 0) \n return true;\n\n for (var i = 0; i < j; i++)\n if (a[n - j + i] < a[i] * 2)\n return true;\n return false;\n});\n\nprint(n - ans + 2);"}, {"source_code": "var n = readline() - 0;\n\nvar a = new Array(n);\n\nfor (var i = 0; i < n; i++) a[i] = readline() - 0;\na.sort();\n\nfunction search(n, f) {\n var i = 0;\n var j = n;\n\n while (i < j) {\n var h = i + (j - i) / 2 | 0;\n if (!f(h))\n i = h + 1;\n else\n j = h;\n }\n\n return i;\n}\n\nvar ans = search(n / 2 + 1 | 0, function(j) {\n if (j == n / 2 + 1 | 0) return true;\n for (var i = 0; i < j; i++)\n if (a[n - j + i] < a[i] * 2)\n return true;\n return false;\n});\n\nprint(n - ans + 1);"}], "src_uid": "361f65484d86051fa9ff013f5e8c9154"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet dictionary = new Map();\r\nfor (let i = 0; i < 26; i++) {\r\n const a = String.fromCharCode(i + 97);\r\n for (let j = 0; j < 26; j++) {\r\n const b = String.fromCharCode(j + 97);\r\n if (a === b) continue;\r\n dictionary.set(a + b, dictionary.size + 1);\r\n }\r\n}\r\nfunction solve(s) {\r\n console.log(dictionary.get(s));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s1 = await read();\r\n solve(s1);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nlet a = [];\n let base = 'a'.charCodeAt(0)\nfor (let i=0; i<26; i++)\nfor (let j=0; j<26; j++){\n if (i!=j)\n a.push(String.fromCharCode(base+i, base+j));\n}\n\nconst calc = (s)=>{\n return a.indexOf(s)+1\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let s = readline();\n L('Ans:');\n pcalc(s);\n }\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const a = str.charCodeAt(0) - 'a'.charCodeAt(0)\n let b = str.charCodeAt(1) - 'a'.charCodeAt(0)\n if (str.charCodeAt(1) > str.charCodeAt(0)) {\n b--\n }\n return a * 25 + b + 1\n}\n"}, {"source_code": "var limit = parseInt(readline());\r\n var alphabets = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\",\r\n \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\",\r\n \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"];\r\n for (var i = 0; i < limit; i++) {\r\n var caseWord = readline();\r\n var firstWordIndex = alphabets.indexOf(caseWord[0]);\r\n var secondWordIndex = alphabets.indexOf(caseWord[1]);\r\n var secondWord = (firstWordIndex > secondWordIndex) ? secondWordIndex + 1 : secondWordIndex;\r\n var result = (25 * firstWordIndex) + secondWord;\r\n print(result);\r\n }"}, {"source_code": "var dict = {};\n\nvar alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\nvar cnt = 1;\nfor (var i = 0; i < alphabet.length; i++) {\n for (var k = 0; k < alphabet.length; k++) {\n if (i === k) {\n continue;\n }\n dict[alphabet[i] + alphabet[k]] = cnt;\n cnt++;\n }\n}\n\nvar n = parseInt(readline());\n\nfor (var i = 0; i < n; i++) {\n var s = readline();\n print(dict[s]);\n}\n"}, {"source_code": "var tests = parseInt(readline());\r\n var a;\r\n\r\n function cToI(c) {\r\n return c.charCodeAt(0) - 'a'.charCodeAt(0);\r\n }\r\n for (var t=0; t < tests; t++) {\r\n a = readline();\r\n var ans = cToI(a.charAt(0)) * 25;\r\n var add = cToI(a.charAt(1)) + 1;\r\n if (a.charAt(1) > a.charAt(0)) {\r\n add--;\r\n }\r\n print(ans + add);\r\n }"}, {"source_code": "abcStr = 'abcdefghijklmnopqrstuvwxyz'\r\nabc = abcStr.split('') \r\nwords = {}\r\nacc = 1\r\nfor(i = 0; i < 26; i++){\r\n for(j = 0; j < 26; j++){\r\n if(abc[i] !=abc[j]){\r\n words[acc] = abc[i] + abc[j]\r\n acc++\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\nT = readline()\r\nwhile (T--) {\r\n ans = 0\r\n s = readline()\r\n \r\n for(key in words){\r\n if(words[key] === s)\r\n ans = key\r\n }\r\n\r\n\r\n print(ans)\r\n}\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n let arr=new Array(26*26+10);\r\n let a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];\r\n let cnt=0;\r\n for(let i=0;i<26;i++)\r\n {\r\n for(let j=0;j<26;j++)\r\n {\r\n if(i!=j) arr[++cnt]=a[i]+a[j];\r\n }\r\n }\r\n // console.log(line);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let str=line[i][0]+line[i][1];\r\n // console.log(str.length);\r\n for(let j=1;j<=cnt;j++)\r\n {\r\n if(arr[j]===str)\r\n {\r\n console.log(j);\r\n break;\r\n }\r\n }\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar list = [];\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\tfor(var i = 0; i < alpha.length; i++){\r\n\t\tfor(var j = 0; j < alpha.length; j++){\r\n\t\t\tif(i != j){\r\n\t\t\t\tlist.push(alpha[i] + alpha[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tmyout(list.indexOf(s) + 1);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n\r\n const alphabet = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));\r\n const letterPos = {};\r\n alphabet.forEach((letter, i) => letterPos[letter] = i + 1);\r\n\r\n let res = 25 * (letterPos[s[0]] - 1);\r\n if (letterPos[s[1]] > letterPos[s[0]]) {\r\n res += letterPos[s[1]] - 1;\r\n } else {\r\n res += letterPos[s[1]];\r\n }\r\n\r\n output(res);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var v = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\n for(i = 1; i <= n; i++){\n var k = lines[i].split('');\n var a = k[0]; var b = k[1];\n var a1 = 0;\n var b1 = 0;\n for(j = 0; j < 26; j++){\n if(v[j] == a){\n a1 = j;\n }if(v[j] == b){\n b1 = j;\n }if(a1 !== 0 && b1 !== 0){\n break;\n }\n }\n var ans = a1 * 25 + b1;\n if(a > b){\n ans++;\n }\n console.log(ans); \n }\n});"}, {"source_code": "/*\r\n * File Created: Thursday, 11th February 2021 1:42:08 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const s = data.shift();\r\n \r\n console.log(b(s));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n let k = 0;\r\n let j = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(arr[i] < 0){\r\n arr[j++] *= -1;\r\n arr[i] *= -1;\r\n }\r\n }\r\n if(isSorted(arr)) {\r\n return 'YES';\r\n } else { \r\n return 'NO'\r\n }\r\n}\r\n\r\nfunction isSorted(arr){\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] > arr[i+1]) return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction b(s) {\r\n let arr = [];\r\n for(let i = 97; i <= 122; i++ ){\r\n for(let j = 97; j <= 122; j++){\r\n if(i != j) arr.push(String.fromCharCode(i,j));\r\n }\r\n }\r\n let count = 1;\r\n let index = 0;\r\n while(true){\r\n if(s != arr[index]) {\r\n count++;\r\n index++;\r\n } else{\r\n return count;\r\n }\r\n }\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var v = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\n for(i = 1; i <= n; i++){\n var k = lines[i].split('');\n var a = k[0]; var b = k[1];\n var a1 = 0;\n var b1 = 0;\n for(j = 0; j < 26; j++){\n if(v[j] == a){\n a1 = j;\n }if(v[j] == b){\n b1 = j;\n }if(a1 !== 0 && b1 !== 0){\n break;\n }\n }\n var ans = a1 * 25 + b1;\n if(a > b){\n ans++;\n }\n console.log(ans); \n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tconst stringArr = nextCharArray();\r\n\t\tlet a = stringArr[0];\r\n\t\tlet b = stringArr[1];\r\n\r\n\t\tlet first = a.charCodeAt(0) - 97;\r\n\t\tlet second = b.charCodeAt(0) - 97;\r\n\t\t// console.log({first, second})\r\n\t\tif (second < first) {\r\n\t\t\tsecond++\r\n\t\t}\r\n\t\t// console.log({first, second})\r\n\r\n\t\tmyout((first * 25) + second );\r\n\t}\r\n}"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (s)=>{\n let aCode = 'a'.charCodeAt(0);\n let fIdx = s.charCodeAt(0) - aCode;\n let sIdx = s.charCodeAt(1) - aCode;\n let result = fIdx * 25 + (sIdx < fIdx ? sIdx + 1 : sIdx);\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let s = readline();\n console.log(`${calc(s)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "var limit = parseInt(readline());\r\nvar alphabets = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\",\r\n \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\",\r\n \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"];\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseWord = readline();\r\n var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);\r\n var secondWordIndex = 0;\r\n if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))\r\n {\r\n secondWordIndex = alphabets.indexOf[1] + 1;\r\n }\r\n else \r\n {\r\n secondWordIndex = alphabets.indexOf[1];\r\n }\r\n var result = firstWordIndex + secondWordIndex;\r\n print(result);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nvar alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',\r\n 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',\r\n 't', 'u', 'v', 'w', 'x', 'y', 'z'];\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseWord = readline();\r\n var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);\r\n var secondWordIndex = 0\r\n if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))\r\n {\r\n secondWordIndex = alphabets.indexOf[1] + 1;\r\n }\r\n else \r\n {\r\n secondWordIndex = alphabets.indexOf[1];\r\n }\r\n var result = firstWordIndex + secondWordIndex;\r\n print(result);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nvar alphabets = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\",\r\n \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\",\r\n \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"];\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseWord = readline();\r\n var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);\r\n var secondWordIndex = 0\r\n if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))\r\n {\r\n secondWordIndex = alphabets.indexOf[1] + 1;\r\n }\r\n else \r\n {\r\n secondWordIndex = alphabets.indexOf[1];\r\n }\r\n var result = firstWordIndex + secondWordIndex;\r\n print(result);\r\n}"}, {"source_code": "var dict = {};\n\nvar alphabet = \"abcdefghigklmnopqrstuvwxyz\";\n\nvar cnt = 1;\nfor (var i = 0; i < alphabet.length; i++) {\n for (var k = 0; k < alphabet.length; k++) {\n if (i === k) {\n continue;\n }\n dict[alphabet[i] + alphabet[k]] = cnt;\n cnt++;\n }\n}\n\nvar n = parseInt(readline());\n\nfor (var i = 0; i < n; i++) {\n var s = readline();\n print(dict[s]);\n}\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n let arr=new Array(26*26+10);\r\n let a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];\r\n let cnt=0;\r\n for(let i=0;i<26;i++)\r\n {\r\n for(let j=0;j<26;j++)\r\n {\r\n if(i!=j) arr[++cnt]=a[i]+a[j];\r\n }\r\n }\r\n for(let i=1;i<=t;i++)\r\n {\r\n let str=line[i];\r\n for(let j=1;j<=cnt;j++)\r\n {\r\n if(arr[j]===str)\r\n {\r\n console.log(j);\r\n break;\r\n }\r\n }\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar list = [];\r\n\tvar alpha = \"abcdefghijklmnopqrstivwxyz\";\r\n\tfor(var i = 0; i < alpha.length; i++){\r\n\t\tfor(var j = 0; j < alpha.length; j++){\r\n\t\t\tif(i != j){\r\n\t\t\t\tlist.push(alpha[i] + alpha[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tmyout(list.indexOf(s) + 1);\r\n\t}\r\n}\r\n"}], "src_uid": "2e3006d663a3c7ad3781aba1e37be3ca"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar size = 2 * N;\r\n\t\tvar list = nextIntArray(size);\r\n\t\tlist .sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput.push(list[i]);\r\n\t\t\toutput.push(list[i + N]);\r\n\t\t}\r\n\t\t\r\n\t\tfor(var i = 0; i < size; i++){\r\n\t\t\tvar L = output[(i - 1 + size) % size];\r\n\t\t\tvar R = output[(i + 1) % size];\r\n\t\t\tif((L + R) / 2 == output[i]){\r\n\t\t\t\tmyerr(i + \":ng\");\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "var t = +readline();\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n var arr = readline()\r\n .split(\" \")\r\n .map((val) => {\r\n return parseInt(val);\r\n });\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n var ans = [];\r\n for (var i = 0; i < n; i++) {\r\n ans.push(arr[i]);\r\n ans.push(arr[2*n-1-i]);\r\n }\r\n print(ans.join(\" \"));\r\n}"}, {"source_code": "var t = +readline();\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n var arr = readline()\r\n .split(\" \")\r\n .map((val) => {\r\n return parseInt(val);\r\n });\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n var ans = [];\r\n var end = 2 * n - 1;\r\n for (var i = 0; i < n; i++) {\r\n ans.push(arr[i]);\r\n ans.push(arr[end]);\r\n end--;\r\n }\r\n print(ans.join(\" \"));\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n stin(a);\r\n for (let i = 1; i + 1 < n; i += 2) {\r\n swap(a, i, i + 1);\r\n }\r\n // pr(test(a));\r\n pr(a.join(\" \"))\r\n};\r\n\r\nconst test = (a) => {\r\n let n = a.length;\r\n for (let i = 1; i + 1 < n; i++) {\r\n if (a[i - 1] + a[i + 1] >> 1 == a[i]) {\r\n pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(2 * input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i] * 2;\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var start = 0;\n var end = e - 1;\n var ans = '';\n while(start < end){\n ans += k[start] + ' ';\n start++;\n if(start > end){\n break;\n }\n ans += k[end] + ' ';\n end--;\n if(start > end){\n break;\n }\n }\n console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar chunks = \"\";\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n\r\n //for local environment windows\r\n if(data.trim() == 'end' ){\r\n chunks = input_stdin.split(\"\\n\");\r\n start();\r\n }\r\n \r\n input_stdin += data;\r\n\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n//process.on('SIGINT', function(){\r\n chunks = input_stdin.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction main(){\r\n var s=1;\r\n var t=parseInt(chunks[0]);\r\n var result=[];\r\n while(t--){\r\n var n=parseInt(chunks[s++]);\r\n var arr=chunks[s++].split(\" \").map(Number);\r\n arr.sort((a,b)=>b-a);\r\n var f=0;\r\n var l=2*n-1;\r\n var ans=\"\";\r\n for(var i=0;i args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n for (let i = 1; i + 1 < n; i++) {\r\n if (a[i - 1] + a[i + 1] >> 1 == a[i]) {\r\n swap(a, i - 1, i);\r\n }\r\n }\r\n // pr(test(a));\r\n pr(a.join(\" \"))\r\n};\r\n\r\nconst test = (a) => {\r\n let n = a.length;\r\n for (let i = 1; i + 1 < n; i++) {\r\n if (a[i - 1] + a[i + 1] >> 1 == a[i]) {\r\n pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(2 * input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n let res = [];\r\n let tot = n / 2;\r\n while (tot--) {\r\n res.push(a.shift());\r\n res.push(a.pop());\r\n }\r\n // pr(res)\r\n // pr(test(res));\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst test = (a) => {\r\n let n = a.length;\r\n for (let i = 1; i + 1 < n; i++) {\r\n if (a[i - 1] + a[i + 1] >> 1 == a[i]) {\r\n pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(2 * input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n for (let i = 2; i < n - 1; i++) {\r\n swap(a, i - 1, i);\r\n }\r\n // pr(a)\r\n pr(a.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(2 * input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var t= readline(parseInt());\r\nwhile(t--){\r\n var n=readline(parseInt());\r\n var arr1=readline().split(' ');\r\n var arr2=[];\r\n var ans=[];\r\n for(var i=0;i<2*n;i++){\r\n arr2.push(arr1[i]);\r\n }\r\n arr2.sort();\r\n for(var i=0;i {\r\n return parseInt(val);\r\n });\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n var ans = [];\r\n var end = 2 * n - 1;\r\n for (var i = 0; i < n; i++) {\r\n ans.push(arr[i]);\r\n ans.push(arr[end]);\r\n end--;\r\n }\r\n print(ans);\r\n}\r\n"}], "src_uid": "4296da660a39a6e98b41387929701c0a"} {"source_code": "var n = Number(readline());\nfor(var i=0;i Number(l) ).sort(function(a,b){return a-b;});\n if(a[0]<=a[2]-a[1]) print(a[0]+a[1]);\n else print(Math.floor((a[0]+a[1]+a[2])/2));\n}", "positive_code": [{"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = '';\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n let chunks = '';\n chunks = input_stdin.split('\\n');\n start(chunks); \n});\n\nfunction start(input) {\n let q = +input.shift();\n while(q--) {\n const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);\n\n if(a + b <= c) {\n console.log(a + b);\n } else {\n console.log(c + Math.floor((a - c + b)/2));\n }\n }\n}"}, {"source_code": "let buffer = '';\nprocess.stdin.on('data', c => buffer += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = buffer.split(EOL);\n lines.pop();\n \n main(lines);\n});\n\n \nfunction main(lines) {\n const N = Number(lines.shift());\n const arr = lines.map(row => row.split(' ').map(Number));\n let diff;\n \n arr.forEach(row => {\n row.sort((a, b) => a - b);\n\n diff = Math.min(row[0], row[2] - row[1]);\n row[0] -= diff;\n row[1] += diff;\n \n console.log(\n Math.min(\n row[1] + Math.ceil(row[0] / 2),\n row[2] + Math.floor(row[0] / 2)\n )\n );\n });\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const a = arr[j].split(' ').map(a => parseInt(a)).sort((a, b) => b - a)\n\n let count = 0\n\n if(a[0] >= (a[1] + a[2])) {\n count = a[1] + a[2]\n }\n else {\n let diff = a[0] - a[1]\n count += diff\n a[0] -= diff\n a[2] -= diff\n \n diff = a[0] - a[2]\n count += diff\n a[0] -= diff\n a[1] -= diff\n }\n \n if(a[0] == a[1] && a[1] == a[2]) {\n if(a[0] % 2 == 0) count += (a[0] / 2) * 3\n else count += ((a[0] - 1) / 2) * 3 + 1\n }\n\n console.log(count)\n \n }\n})"}], "negative_code": [{"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = '';\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n let chunks = '';\n chunks = input_stdin.split('\\n');\n start(chunks); \n});\n\nfunction start(input) {\n let q = +input.shift();\n while(q--) {\n const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);\n\n if(a + b <= c) {\n console.log(a + b);\n } else {\n console.log(c - Math.floor((a - c + b)/2));\n }\n }\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = '';\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n let chunks = '';\n chunks = input_stdin.split('\\n');\n start(chunks); \n});\n\nfunction start(input) {\n let q = +input.shift();\n console.log(input);\n while(q--) {\n const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);\n\n if(a + b <= c) {\n console.log(a + b);\n } else {\n console.log(c + Math.floor((a - c + b)/2));\n }\n }\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = '';\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n let chunks = '';\n chunks = input_stdin.split('\\n');\n start(chunks); \n});\n\nfunction start(input) {\n let q = +input.shift();\n console.log(input);\n while(q--) {\n const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);\n\n if(a + b <= c) {\n console.log(a + b);\n } else {\n console.log(c - Math.floor((a - c + b)/2));\n }\n }\n}"}, {"source_code": "let buffer = '';\nprocess.stdin.on('data', c => buffer += c)\nprocess.stdin.on('end', main)\n\n\nfunction main() {\n const {EOL} = require('os');\n const lines = buffer.split(EOL);\n \n const N = Number(lines.shift());\n const arr = lines.map(row => row.split(' ').map(Number));\n \n arr.forEach(row => {\n row.sort((a, b) => a - b);\n console.log(row[0] + Math.min(row[1], row[2] - row[0]));\n });\n}\n"}, {"source_code": "let buffer = '';\nprocess.stdin.on('data', c => buffer += c)\nprocess.stdin.on('end', main)\n\n\nfunction main() {\n const {EOL} = require('os');\n const lines = buffer.split(EOL);\n lines.pop();\n \n const N = Number(lines.shift());\n const arr = lines.map(row => row.split(' ').map(Number));\n \n arr.forEach(row => {\n row.sort((a, b) => a - b);\n console.log(row[0] + Math.min(row[1], row[2] - row[0]));\n });\n}\n"}, {"source_code": "let buffer = '';\nprocess.stdin.on('data', c => buffer += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = buffer.split(EOL);\n lines.pop();\n \n return lines;\n});\n\n \nfunction main(lines) {\n const N = Number(lines.shift());\n const arr = lines.map(row => row.split(' ').map(Number));\n let diff;\n \n arr.forEach(row => {\n row.sort((a, b) => a - b);\n\n diff = Math.min(row[0], row[2] - row[1]);\n row[0] -= diff;\n row[1] += diff;\n \n console.log(\n Math.min(\n row[1] + Math.ceil(row[0] / 2),\n row[2] + Math.floor(row[0] / 2)\n )\n );\n });\n}"}, {"source_code": "var n = Number(readline());\nfor(var i=0;i Number(l) ).sort();\n if(a[0]<=a[2]-a[1]) print(a[0]+a[1]);\n else print(Math.floor((a[0]+a[1]+a[2])/2));\n}"}, {"source_code": "var n = Number(readline());\nfor(var i=0;i Number(l) ).sort();\n if(a[0] 0 && t.length > 0){\n if(s[s.length - 1] == t[t.length - 1]){\n t.pop();\n }else{\n count++;\n }\n s.pop();\n }\n if(t.length === 0){\n return count;\n }\n return l;\n};\nlet q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var s = lines[i];\n console.log(Math.min(tocount(s, '00'), Math.min(tocount(s, '25'), Math.min(tocount(s, '50'), tocount(s,'75')))));\n }\n});\n", "positive_code": [{"source_code": "var thisisveryeasyhahahah = function(s, t){\n s = s.split('').map(Number);\n t = t.split('').map(Number);\n var cnt = 0;\n while(s.length > 0 && t.length > 0){\n if(s[s.length - 1] == t[t.length - 1]){\n t.pop();\n }else{\n cnt++;\n }\n s.pop();\n }\n return cnt;\n};\nlet q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t; i++){\n var s = lines[i];\n console.log(Math.min(thisisveryeasyhahahah(s, '00'), Math.min(thisisveryeasyhahahah(s, '25'), Math.min(thisisveryeasyhahahah(s, '50'), thisisveryeasyhahahah(s, '75')))));\n }\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rl();\r\n\r\n\t\tn = n.split('').reverse().join('');\r\n\r\n\t\tfunction pos (x, i = -1) {\r\n\t\t\twhile (++i < n.length) {\r\n\t\t\t\tif (n[i] == x)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tconst ans1 = Math.min(pos('2', pos('5')), pos('7', pos('5')));\r\n\t\tconst ans2 = Math.min(pos('0', pos('0')), pos('5', pos('0')));\r\n\r\n\t\tconst ans = Math.min(ans1, ans2) - 1;\r\n\t\t\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 20;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rl();\r\n\r\n\t\tn = n.split('').reverse().join('');\r\n\r\n\t\tlet ans1, ans2;\r\n\t\tfor (let i = 0; i < n.length; i++) {\r\n\t\t\tif (n[i] == '0' && ans1 === undefined) {\r\n\t\t\t\tans1 = INF;\r\n\t\t\t\tfor (let j = i+1; j < n.length; j++) {\r\n\t\t\t\t\tif (n[j] == '0' || n[j] == '5') {\r\n\t\t\t\t\t\tans1 = j-1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (n[i] == '5' && ans2 == undefined) {\r\n\t\t\t\tans2 = INF;\r\n\t\t\t\tfor (let j = i+1; j < n.length; j++) {\r\n\t\t\t\t\tif (n[j] == '2' || n[j] == '7') {\r\n\t\t\t\t\t\tans2 = j-1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans1 = ans1 == undefined ? INF : ans1;\r\n\t\tans2 = ans2 == undefined ? INF : ans2;\r\n\r\n\t\tconst ans = Math.min(ans1, ans2);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction calcTurns(findIn, num) {\n let digitIndex = 1;\n let turns = 0;\n findIn.split('').reverse().forEach(digit => {\n if (digitIndex < 0) {\n return;\n }\n if (digit === num[digitIndex]) {\n digitIndex--;\n } else {\n turns += 1;\n }\n });\n return digitIndex === -1 ? turns : Infinity;\n}\n\nfunction main() {\n const n = parseInt(readline());\n for (let i = 0; i < n; i++) {\n const num = readline();\n console.log(Math.min(calcTurns(num, '00'), calcTurns(num, '25'), calcTurns(num, '50'), calcTurns(num, '75')));\n }\n}\n"}, {"source_code": "// dist/FinalCode/Common/InputOutputClass.js\nvar Input = function() {\n function Input2(inputData) {\n var _this = this;\n this.SettleStream = function() {\n var re = /\\s+/;\n _this.inputWords = _this.inputStream.split(re);\n _this.inputWordsLength = _this.inputWords.length;\n };\n this.getLength = function() {\n return _this.inputWordsLength;\n };\n this.getEveryWord = function() {\n return _this.inputWords;\n };\n this.getNextWord = function() {\n _this.inputWordsCount++;\n if (_this.inputWordsLength < _this.inputWordsCount) {\n return \"\";\n }\n return _this.inputWords[_this.inputWordsCount - 1];\n };\n this.getNextString = function() {\n return _this.getNextWord();\n };\n this.getNextBigInt = function() {\n return BigInt(_this.getNextWord());\n };\n this.getNextNumber = function() {\n return Number(_this.getNextWord());\n };\n this.getNextInt = function() {\n return parseInt(_this.getNextWord(), 10);\n };\n this.getNextFloat = function() {\n return parseFloat(_this.getNextWord());\n };\n this.inputWordsCount = 0;\n this.inputStream = inputData;\n }\n Input2.prototype.SetStream = function(chunk) {\n this.inputStream += chunk;\n };\n Input2.prototype.getNextIntArray = function(elementCount) {\n var resultArray = new Array(elementCount);\n for (var idx = 0; idx < elementCount; idx++) {\n resultArray[idx] = this.getNextInt();\n }\n return resultArray;\n };\n return Input2;\n}();\nvar InputOutputClass_default = Input;\nvar writeLine = function(outputElement) {\n var _internalWrite = function(_internalOutputElement) {\n process.stdout.write(_internalOutputElement);\n };\n _internalWrite(String(outputElement) + \"\\n\");\n};\n\n// dist/main.js\nvar rw = new InputOutputClass_default(\"\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", function(chunk) {\n rw.SetStream(chunk);\n});\nprocess.stdin.on(\"end\", function() {\n rw.SettleStream();\n mainFunc();\n});\nvar mainFunc = function() {\n testCases();\n};\nvar testCases = function() {\n var test = rw.getNextInt();\n for (var i = 0; i < test; i++) {\n solveCase();\n }\n};\nvar solveCase = function() {\n var n = rw.getNextString();\n var answer = n.length + 1e3;\n for (var i = n.length - 1; i >= 0; i--) {\n for (var j = i - 1; j >= 0; j--) {\n var a = Number(n[i]);\n var b = Number(n[j]);\n if ((b * 10 + a) % 25 === 0) {\n if (answer > n.length - j - 2) {\n answer = n.length - j - 2;\n }\n }\n }\n }\n writeLine(answer);\n};\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=1\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j--\r\n if(j===-1)\r\n return Number(n-i-2)\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve(num) {\r\n const lastN = num.lastIndexOf('0')\r\n const lastF = num.lastIndexOf('5')\r\n let tmp, arr = [];\r\n // 25\r\n if (lastF !== -1) {\r\n tmp = num.slice(0, lastF).lastIndexOf('2')\r\n if (tmp !== -1) {\r\n arr.push(((num.length - 1 - lastF) + (lastF - tmp - 1)))\r\n }\r\n }\r\n\r\n // 00\r\n if (lastN !== -1) {\r\n tmp = num.slice(0, lastN).lastIndexOf('0')\r\n if (tmp !== -1) {\r\n arr.push(((num.length - 1 - lastN) + (lastN - tmp - 1)))\r\n }\r\n }\r\n // 50\r\n if (lastN !== -1) {\r\n tmp = num.slice(0, lastN).lastIndexOf('5')\r\n if (tmp !== -1) {\r\n arr.push(((num.length - 1 - lastN) + (lastN - tmp - 1)))\r\n }\r\n }\r\n // 75\r\n if (lastF !== -1) {\r\n tmp = num.slice(0, lastF).lastIndexOf('7')\r\n if (tmp !== -1) {\r\n arr.push(((num.length - 1 - lastF) + (lastF - tmp - 1)))\r\n }\r\n }\r\n console.log(Math.min(...arr))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++].trim()\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const target = ['00', '25', '50', '75']\n let ans = str.length\n for (let i = 0; i < target.length; i++) {\n let k = 1\n for (let j = str.length - 1; j >= 0; j--) {\n // console.log(target[i][k], str[j], str)\n if (str[j] === target[i][k]) {\n if (k === 0) {\n ans = Math.min(ans, str.length - j - 2)\n // console.log('found', str, target[i], str.length - j - 2)\n break\n }\n k--\n }\n }\n }\n return ans\n}\n"}, {"source_code": "var t = parseInt(readline())\r\n\r\nfor(var T = 1 ; T <= t; ++T){\r\n\tsolve();\r\n}\r\n\r\nfunction solve(){\r\n\tvar n = readline();\r\n\tvar len = n.length;\r\n\tvar ans = len;\r\n\tfor(var i=0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=1\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j--\r\n if(j===-1)\r\n return Number(n-i-2)\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j++\r\n if(j===2)\r\n return Number(Number(n)-Number(i)-Number(2))\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;ix)\r\n ans=x;\r\n x=Number(solve(s,\"00\"))\r\n if(ans>x)\r\n ans=x;\r\n x=Number(solve(s,\"75\"))\r\n if(ans>x)\r\n ans=x;\r\n x=Number(solve(s,\"50\"))\r\n if(ans>x)\r\n ans=x;\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j++\r\n if(j===2)\r\n return Number(Number(n)-Number(i)-Number(2))\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;ix)\r\n ans=x;\r\n x=Number(solve(s,\"00\"))\r\n if(ans>x)\r\n ans=x;\r\n x=Number(solve(s,\"75\"))\r\n if(ans>x)\r\n ans=x;\r\n x=Number(solve(s,\"50\"))\r\n if(ans>x)\r\n ans=x;\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j++\r\n if(j===2)\r\n return Number(n-i-2)\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;ix)\r\n ans=x;\r\n x=Number(solve(s,\"00\"))\r\n if(ans>x)\r\n ans=x\r\n x=Number(solve(s,\"75\"))\r\n if(ans>x)\r\n ans=x\r\n x=Number(solve(s,\"25\"))\r\n if(ans>x)\r\n ans=x\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]===x[j])\r\n {\r\n j++\r\n if(j===2)\r\n return Number(n-i-2)\r\n }\r\n }\r\n return Number(30)\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]==x[j])\r\n {\r\n j++;\r\n if(j==2)\r\n return n-i-2\r\n }\r\n }\r\n return 30\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve(s,x)\r\n{\r\n let n=s.length\r\n let j=0\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]==x[j])\r\n {\r\n j++;\r\n if(j==2)\r\n return n-i-2\r\n }\r\n }\r\n}\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getNumberState(arr, lastDigitVal) {\n const valueMap = {\n 0: [0, 5],\n 5: [2, 7]\n }\n return arr.reduce((acc, digit) => {\n const { lastDigit, isAnswerFound, turns } = acc;\n if (isAnswerFound) {\n return acc;\n }\n if (lastDigit !== null) {\n return valueMap[lastDigit].includes(digit) ? {...acc, isAnswerFound: true} : {...acc, turns: turns + 1};\n } else {\n const isSuitableLastDigit = lastDigitVal !== undefined ? digit === lastDigitVal : digit === 5 || digit === 0;\n return isSuitableLastDigit ? {...acc, lastDigit: digit } : {...acc, turns: turns + 1};\n }\n\n }, {lastDigit: null, isAnswerFound: false, turns: 0});\n}\n\nfunction calcTurns(str) {\n const arr = str.split('').reverse().map(Number);\n let state = getNumberState(arr);\n return state.isAnswerFound ? state.turns : getNumberState(arr, state.lastDigit === 0 ? 5 : 0).turns;\n}\n\nfunction main() {\n const n = parseInt(readline());\n for (let i = 0; i < n; i++) {\n console.log(calcTurns(readline()));\n }\n}\n"}, {"source_code": "\r\nvar t = parseInt(readline())\r\n\r\nfor(var T = 1 ; T <= t; ++T){\r\n\tsolve();\r\n}\r\n\r\nfunction solve(){\r\n\tvar n = parseInt(readline());\r\n\tvar str = String(n);\r\n\tvar len = parseInt(str.length);\r\n\tvar ans = len;\r\n\tfor(var i=0; i n[o]) return (t[o] = s), (n[s] += n[o]), s\r\n return (t[s] = o), o\r\n },\r\n }\r\n function r(e) {\r\n return t[e] === e ? e : (t[e] = r(t[e]))\r\n }\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve() {\r\n return -1\r\n}\r\nconst MAX_N = 100010,\r\n findset1 = createHeuristicFindSet(MAX_N),\r\n findset2 = createHeuristicFindSet(MAX_N),\r\n pos1 = new Array(MAX_N).fill(0),\r\n pos2 = new Array(MAX_N).fill(0)\r\n__main__(function (e) {\r\n for (let t = 1; t <= 1; ++t) {\r\n const [t, n, i] = e.readIntegersOfLine()\r\n findset1.init(t), findset2.init(t)\r\n for (let t = 0; t < n; ++t) {\r\n const [t, n] = e.readIntegersOfLine()\r\n findset1.merge(t, n)\r\n }\r\n for (let t = 0; t < i; ++t) {\r\n const [t, n] = e.readIntegersOfLine()\r\n findset2.merge(t, n)\r\n }\r\n e.println(t - 1 - Math.max(n, i))\r\n const r = Math.min(Math.floor(Math.random() * t) + 1, t)\r\n for (let n = 1; n <= t; ++n) {\r\n const t = findset1.root(n),\r\n i = findset1.root(r),\r\n s = findset2.root(n),\r\n o = findset2.root(r)\r\n t !== i &&\r\n s !== o &&\r\n (findset1.merge(t, i), findset2.merge(s, o), e.println(r + ' ' + n))\r\n }\r\n let s = 0\r\n for (let e = 1; e <= t; ++e) {\r\n const t = findset1.root(e),\r\n n = findset1.root(r)\r\n t !== n && (findset1.merge(t, n), (pos1[s++] = e))\r\n }\r\n let o = 0\r\n for (let e = 1; e <= t; ++e) {\r\n const t = findset2.root(e),\r\n n = findset2.root(r)\r\n t !== n && (findset2.merge(t, n), (pos2[o++] = e))\r\n }\r\n for (let t = 0, n = Math.min(s, o); t < n; ++t) {\r\n const n = pos1[t],\r\n i = pos2[t]\r\n e.println(n + ' ' + i)\r\n }\r\n }\r\n})\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst mxN = 1005;\r\n\r\nconst f = Array.from(Array(2), x => []);\r\n\r\nfunction getf (id, x) {\r\n\tif (x == f[id][x]) return x;\r\n\treturn f[id][x] = getf(id, f[id][x]);\r\n}\r\n\r\nfunction main () {\r\n\tconst [n, m1, m2] = rna();\r\n\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tf[0][i] = f[1][i] = i;\r\n\t}\r\n\r\n\r\n\tfor (let i = 0; i < m1; i++) {\r\n\t\tlet [u, v] = rna();\r\n\t\tu--; v--;\r\n\t\tu = getf(0, u);\r\n\t\tv = getf(0, v);\r\n\t\tf[0][u] = v;\r\n\t}\r\n\r\n\tfor (let i = 0; i < m2; i++) {\r\n\t\tlet [u, v] = rna();\r\n\t\tu--; v--;\r\n\t\tu = getf(1, u);\r\n\t\tv = getf(1, v);\r\n\t\tf[1][u] = v;\r\n\t}\r\n\r\n\tlet ans = [];\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tfor (let j = i + 1; j < n; j++) {\r\n\t\t\tif (getf(0, i) != getf(0, j) && getf(1, i) != getf(1, j)) {\r\n\t\t\t\tf[0][getf(0, i)] = getf(0, j);\r\n\t\t\t\tf[1][getf(1, i)] = getf(1, j);\r\n\t\t\t\tans.push([i+1, j+1]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans.length);\r\n\tfor (const edg of ans) {\r\n\t\tconsole.log(edg.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nfunction createHeuristicFindSet(e) {\r\n const t = new Array(e + 1),\r\n n = new Array(e + 1)\r\n let r = e\r\n return {\r\n init: function (e) {\r\n ;(r = e), n.fill(1, r + 1, 1)\r\n for (let e = 1; e <= r; ++e) t[e] = e\r\n },\r\n root: i,\r\n merge: function (e, r) {\r\n const s = i(e),\r\n o = i(r)\r\n if (s === o) return s\r\n if (n[s] > n[o]) return (t[o] = s), (n[s] += n[o]), s\r\n return (t[s] = o), o\r\n },\r\n }\r\n function i(e) {\r\n return t[e] === e ? e : (t[e] = i(t[e]))\r\n }\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve() {\r\n return -1\r\n}\r\n__main__(function (e) {\r\n const t = 100010,\r\n n = createHeuristicFindSet(t),\r\n r = createHeuristicFindSet(t)\r\n for (let t = 1; t <= 1; ++t) {\r\n const [t, i, s] = e.readIntegersOfLine()\r\n n.init(t), r.init(t)\r\n for (let t = 0; t < i; ++t) {\r\n const [t, r] = e.readIntegersOfLine()\r\n n.merge(t, r)\r\n }\r\n for (let t = 0; t < s; ++t) {\r\n const [t, n] = e.readIntegersOfLine()\r\n r.merge(t, n)\r\n }\r\n e.println(t - 1 - Math.max(i, s))\r\n const o = Math.min(Math.floor(Math.random() * t) + 1, t)\r\n for (let i = 1; i <= t; ++i) {\r\n const t = n.root(i),\r\n s = n.root(o),\r\n u = r.root(i),\r\n c = r.root(o)\r\n t !== s &&\r\n u !== c &&\r\n (n.merge(t, s), r.merge(u, c), e.println(o + ' ' + i))\r\n }\r\n const u = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = n.root(e),\r\n r = n.root(o)\r\n t !== r && (n.merge(t, r), u.push(e))\r\n }\r\n const c = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = r.root(e),\r\n n = r.root(o)\r\n t !== n && (r.merge(t, n), c.push(e))\r\n }\r\n for (let t = 0, n = Math.min(u.length, c.length); t < n; ++t) {\r\n const n = u[t],\r\n r = c[t]\r\n e.println(n + ' ' + r)\r\n }\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nfunction createHeuristicFindSet(e) {\r\n const t = new Array(e + 1),\r\n n = new Array(e + 1)\r\n let r = e\r\n return {\r\n init: function (e) {\r\n ;(r = e), n.fill(1, r + 1, 1)\r\n for (let e = 1; e <= r; ++e) t[e] = e\r\n },\r\n root: i,\r\n merge: function (e, r) {\r\n const o = i(e),\r\n s = i(r)\r\n if (o === s) return o\r\n if (n[o] > n[s]) return (t[s] = o), (n[o] += n[s]), o\r\n return (t[o] = s), s\r\n },\r\n }\r\n function i(e) {\r\n return t[e] === e ? e : (t[e] = i(t[e]))\r\n }\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve() {\r\n return -1\r\n}\r\n__main__(function (e) {\r\n const t = 100010,\r\n n = createHeuristicFindSet(t),\r\n r = createHeuristicFindSet(t)\r\n for (let t = 1; t <= 1; ++t) {\r\n const [t, i, o] = e.readIntegersOfLine()\r\n n.init(t), r.init(t)\r\n for (let t = 0; t < i; ++t) {\r\n const [t, r] = e.readIntegersOfLine()\r\n n.merge(t, r)\r\n }\r\n for (let t = 0; t < o; ++t) {\r\n const [t, n] = e.readIntegersOfLine()\r\n r.merge(t, n)\r\n }\r\n const s = [],\r\n u = Math.floor(Math.random() * t) + 1\r\n for (let e = 1; e <= t; ++e) {\r\n const t = n.root(e),\r\n i = n.root(u),\r\n o = r.root(e),\r\n c = r.root(u)\r\n t !== i && o !== c && (n.merge(t, i), r.merge(o, c), s.push([u, e]))\r\n }\r\n const c = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = n.root(e),\r\n r = n.root(u)\r\n t !== r && (n.merge(t, r), c.push(e))\r\n }\r\n const a = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = r.root(e),\r\n n = r.root(u)\r\n t !== n && (r.merge(t, n), a.push(e))\r\n }\r\n for (let e = 0, t = Math.min(c.length, a.length); e < t; ++e)\r\n s.push([c[e], a[e]])\r\n e.print(s.length + '\\n')\r\n for (const t of s) e.print(t.join(' ') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst mxN = 1005;\r\n\r\nclass dsu {\r\n\tconstructor (n) {\r\n\t\tthis.components = n;\r\n\t\tthis.data = Array(n).fill(-1);\r\n\t}\r\n\tunite (a, b) {\r\n\t\ta = this.find(a);\r\n\t\tb = this.find(b);\r\n\t\tthis.data[a] += this.data[b];\r\n\t\tthis.data[b] = a;\r\n\t\tthis.components--;\r\n\t}\r\n\tfind (a) {\r\n\t\treturn this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);\r\n\t}\r\n\tsize (a) {\r\n\t\treturn -this.data[this.find(a)];\r\n\t}\r\n\tgetcomponents () {\r\n\t\treturn this.components;\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tconst [n, m1, m2] = rna();\r\n\r\n\tconst d1 = new dsu(n);\r\n\tconst d2 = new dsu(n);\r\n\r\n\tfor (let i = 0; i < m1; i++) {\r\n\t\tlet [u, v] = rna();\r\n\t\tu--; v--;\r\n\t\td1.unite(u, v);\r\n\t}\r\n\r\n\tfor (let i = 0; i < m2; i++) {\r\n\t\tlet [u, v] = rna();\r\n\t\tu--; v--;\r\n\t\td2.unite(u, v);\r\n\t}\r\n\r\n\tlet ans = [];\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tfor (let j = i + 1; j < n; j++) {\r\n\t\t\tif (d1.find(i) != d1.find(j) && d2.find(i) != d2.find(j)) {\r\n\t\t\t\td1.unite(i, j);\r\n\t\t\t\td2.unite(i, j);\r\n\t\t\t\tans.push([i+1, j+1]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans.length);\r\n\tfor (const edg of ans) {\r\n\t\tconsole.log(edg.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nfunction createHeuristicFindSet(e) {\r\n const t = new Array(e + 1),\r\n n = new Array(e + 1)\r\n let r = e\r\n return {\r\n init: function (e) {\r\n ;(r = e), n.fill(1, r + 1, 1)\r\n for (let e = 1; e <= r; ++e) t[e] = e\r\n },\r\n root: i,\r\n merge: function (e, r) {\r\n const s = i(e),\r\n o = i(r)\r\n if (s === o) return s\r\n if (n[s] > n[o]) return (t[o] = s), (n[s] += n[o]), s\r\n return (t[s] = o), o\r\n },\r\n }\r\n function i(e) {\r\n return t[e] === e ? e : (t[e] = i(t[e]))\r\n }\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve() {\r\n return -1\r\n}\r\n__main__(function (e) {\r\n const t = 100010,\r\n n = createHeuristicFindSet(t),\r\n r = createHeuristicFindSet(t)\r\n for (let t = 1; t <= 1; ++t) {\r\n const [t, i, s] = e.readIntegersOfLine()\r\n n.init(t), r.init(t)\r\n for (let t = 0; t < i; ++t) {\r\n const [t, r] = e.readIntegersOfLine()\r\n n.merge(t, r)\r\n }\r\n for (let t = 0; t < s; ++t) {\r\n const [t, n] = e.readIntegersOfLine()\r\n r.merge(t, n)\r\n }\r\n e.println(t - 1 - Math.max(i, s))\r\n const o = Math.floor(Math.random() * t) + 1\r\n for (let i = 1; i <= t; ++i) {\r\n const t = n.root(i),\r\n s = n.root(o),\r\n u = r.root(i),\r\n c = r.root(o)\r\n t !== s &&\r\n u !== c &&\r\n (n.merge(t, s), r.merge(u, c), e.println(o + ' ' + i))\r\n }\r\n const u = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = n.root(e),\r\n r = n.root(o)\r\n t !== r && (n.merge(t, r), u.push(e))\r\n }\r\n const c = []\r\n for (let e = 1; e <= t; ++e) {\r\n const t = r.root(e),\r\n n = r.root(o)\r\n t !== n && (r.merge(t, n), c.push(e))\r\n }\r\n for (let t = 0, n = Math.min(u.length, c.length); t < n; ++t) {\r\n const n = u[t]\r\n e.println(o + ' ' + n)\r\n }\r\n }\r\n})\r\n"}], "src_uid": "e3d2b67a62ac431718071ae20f3794aa"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const s1 = lines[l++]\r\n const s2 = lines[l++]\r\n output[i] = solve(s1, s2)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(s, t) {\r\n const ps = []\r\n for (let i = 0; i + t.length - 1 < s.length; i++) {\r\n if (s.slice(i, i + t.length) === t) ps.push(i)\r\n }\r\n if (!ps.length) return [0, 1].join(' ')\r\n// console.log(ps)\r\n const dp = Array(ps.length).fill(Infinity)\r\n const count = Array(ps.length).fill(1)\r\n let min = Infinity\r\n for (let i = 0; i < ps.length; i++) {\r\n for (let j = i - 1; j >= 0; j--) {\r\n if (ps[j] + t.length - 1 >= ps[i]) continue\r\n let has = 0\r\n for (let k = j + 1; k < i; k++) {\r\n if (ps[j] + t.length - 1 < ps[k] && ps[k] + t.length - 1 < ps[i]) {\r\n has = 1\r\n break\r\n }\r\n }\r\n if (has) continue\r\n // dp[i] = Math.min(dp[i], dp[j] + 1)\r\n // count[i] = add(count[i], count[j])\r\n if (dp[j] + 1 < dp[i]) {\r\n dp[i] = dp[j] + 1\r\n count[i] = count[j]\r\n } else if (dp[j] + 1 === dp[i]) {\r\n count[i] = add(count[i], count[j])\r\n }\r\n }\r\n if (dp[i] === Infinity) {\r\n dp[i] = 1\r\n // count[i] = 1\r\n }\r\n if (ps[i] + t.length - 1 >= ps[ps.length - 1]) {\r\n min = Math.min(min, dp[i])\r\n }\r\n }\r\n let ans = 0\r\n for (let i = 0; i < ps.length; i++) {\r\n if (ps[i] + t.length - 1 >= ps[ps.length - 1]\r\n && dp[i] === min) {\r\n ans = add(ans, count[i])\r\n }\r\n }\r\n// console.log(dp, count)\r\n return min + ' ' + ans\r\n}\r\nfunction add(a, b) {\r\n return (a + b) % (1e9 + 7)\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read(),\r\n t = read();\r\n const n = s.length,\r\n m = t.length;\r\n const MOD = 10 ** 9 + 7;\r\n const mod = num => num % MOD;\r\n const p = new Array(n).fill(0);\r\n for (let i = 0; i <= n - m; i++) {\r\n let flag = 1;\r\n for (let j = 0; j < m; j++) {\r\n if (s[i + j] !== t[j]) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n p[i + m - 1] = flag;\r\n }\r\n const dp = [];\r\n for (let i = 0; i <= n - m; i++) {\r\n if (!p[i + m - 1]) continue;\r\n let ans = [Infinity, Infinity];\r\n for (let j = 0; j < i; j++) {\r\n if (dp[j] && dp[j][2] >= i - 1) {\r\n if (dp[j][0] < ans[0]) {\r\n ans = [...dp[j]];\r\n } else if (dp[j][0] === ans[0]) {\r\n ans[1] = mod(ans[1] + dp[j][1]);\r\n }\r\n }\r\n }\r\n if (ans[0] === Infinity) ans = [1, 1, n - 1];else {\r\n ans[0]++;\r\n ans[2] = n - 1;\r\n }\r\n for (let j = i + m * 2 - 1; j < n; j++) {\r\n if (p[j]) {\r\n ans[2] = j - 1;\r\n break;\r\n }\r\n }\r\n dp[i + m - 1] = ans;\r\n }\r\n let res = 0,\r\n max = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n if (dp[i] && dp[i][2] === n - 1) {\r\n if (dp[i][0] < max) {\r\n max = dp[i][0];\r\n res = dp[i][1];\r\n } else if (dp[i][0] === max) {\r\n res = mod(res + dp[i][1]);\r\n }\r\n }\r\n }\r\n if (max === Infinity) return `0 1`;\r\n return `${max} ${res}`;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const s1 = lines[l++]\n const s2 = lines[l++]\n output[i] = solve(s1, s2)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(s, t) {\n const ps = []\n for (let i = 0; i + t.length - 1 < s.length; i++) {\n if (s.slice(i, i + t.length) === t) ps.push(i)\n }\n if (!ps.length) return [0, 1].join(' ')\n// console.log(ps)\n const dp = Array(ps.length).fill(Infinity)\n const count = Array(ps.length).fill(1)\n let ans = 0\n for (let i = 0; i < ps.length; i++) {\n for (let j = i - 1; j >= 0; j--) {\n if (ps[j] + t.length - 1 >= ps[i]) continue\n let has = 0\n for (let k = j + 1; k < i; k++) {\n if (ps[j] + t.length - 1 < ps[k] && ps[k] + t.length - 1 < ps[i]) {\n has = 1\n break\n }\n }\n if (has) continue\n // dp[i] = Math.min(dp[i], dp[j] + 1)\n // count[i] = add(count[i], count[j])\n if (dp[j] + 1 < dp[i]) {\n dp[i] = dp[j] + 1\n count[i] = count[j]\n } else if (dp[j] + 1 === dp[i]) {\n count[i] = add(count[i], count[j])\n }\n }\n if (dp[i] === Infinity) {\n dp[i] = 1\n // count[i] = 1\n }\n if (ps[i] + t.length - 1 >= ps[ps.length - 1]) {\n ans = add(ans, count[i])\n }\n }\n// console.log(dp, count)\n return dp[ps.length - 1] + ' ' + ans\n}\nfunction add(a, b) {\n return (a + b) % (1e9 + 7)\n}\n"}], "src_uid": "904af5d6a9d84b7b7b7ff8d63e6f0254"} {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n while (t--) {\r\n let [n,k]=(await read()).split(' ').map(Number);\r\n let a=await read();\r\n let ans=0;\r\n let i,j;\r\n for (i = a.length-1; i >= 0; i--){\r\n const e = a[i];\r\n if(e=='1'){\r\n const cost=a.length-i-1;\r\n if(cost<=k){\r\n k-=cost;\r\n ans+=1;\r\n }else{\r\n i++;\r\n }\r\n break;\r\n }\r\n }\r\n for (j = 0; j < i; j++){\r\n const e = a[j];\r\n if(e=='1'){\r\n const cost=j;\r\n if(cost<=k){\r\n k-=cost;\r\n ans+=10;\r\n }else{\r\n ans+=11;\r\n }\r\n break;\r\n \r\n }\r\n }\r\n for (j++; j < i; j++){\r\n if(a[j]=='1'){\r\n ans+=11;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n", "positive_code": [{"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i > 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n if (zeroPadRight === N - 1) zeroPadRight = 0;\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N - 1; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (zeroPadLeft === N - 1) zeroPadLeft = 0;\r\n\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life >= zeroPadLeft) {\r\n sum -= 1;\r\n }\r\n\r\n if (S[0] === \"1\" && S[N - 1] === \"0\" && life >= N - 1) {\r\n sum -= 9;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "/**\n * Format:\n * {type: 'number', namedVariable?: string }\n * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }\n * {type: 'array', namedVariable?: string }\n * {type: 'string', namedVariable?: string }\n */\nconst readline = require('readline');\n\nfunction createCLIReader(instructions) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const mappedVariables = {};\n\n let resolvePromise = null;\n const donePromise = new Promise((res, rej) => {\n resolvePromise = res;\n });\n\n function waitUntilDone() {\n return donePromise;\n }\n\n /**\n * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }\n */\n const stack = [];\n let pc = -1;\n\n function finished() {\n if (pc >= instructions.length) {\n return true;\n }\n return false;\n }\n\n function checkFinished() {\n // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);\n if (pc >= instructions.length) {\n return true;\n }\n if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {\n return true;\n }\n return false;\n }\n\n function getNextInstructionContext() {\n if (!stack.length) {\n return {\n index: ++pc,\n }\n }\n const lastStack = stack[stack.length - 1];\n if (lastStack.pointer === lastStack.instructionCount) {\n lastStack.pointer = 0;\n lastStack.iteration = lastStack.iteration + 1;\n }\n if (lastStack.count === lastStack.iteration) {\n stack.pop();\n pc = lastStack.basePointer + lastStack.instructionCount + 1;\n return {\n index: pc,\n }\n }\n\n lastStack.pointer = lastStack.pointer + 1;\n return {\n index: lastStack.basePointer + lastStack.pointer,\n context: {\n namedPath: [...lastStack.context.namedPath, lastStack.iteration]\n }\n }\n }\n\n function pushRepeatToStack(instruction, index, context) {\n stack.push({\n type: 'repeat',\n count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],\n iteration: 0,\n basePointer: index,\n pointer: 0,\n instructionCount: instruction.instructionCount,\n context: {\n namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],\n }\n })\n setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);\n }\n\n function nextInstruction() {\n if (finished()) {\n // console.warn('Calling nextInstruction after finished, something is wrong');\n return;\n }\n while (true) {\n const { index, context } = getNextInstructionContext();\n const instruction = instructions[index];\n\n // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);\n switch (instruction.type) {\n case 'number':\n case 'array':\n case 'string':\n return {\n ...instruction,\n namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,\n }\n case 'repeat':\n pushRepeatToStack(instruction, index, context);\n break;\n default:\n // console.warn('Unclear instruction, abort');\n return;\n }\n }\n }\n\n function getIn(object, path) {\n for (let i = 0; i < path.length; ++i) {\n object = object[path[i]];\n }\n return object;\n }\n\n function setIn(object, path, value) {\n for (let i = 0; i < path.length - 1; ++i) {\n if (object[path[i]] == null) {\n object[path[i]] = {};\n }\n object = object[path[i]];\n }\n object[path[path.length - 1]] = value;\n }\n\n rl.on('line', line => {\n if (finished()) {\n return;\n }\n const { type, namedPath } = nextInstruction();\n switch (type) {\n case 'number':\n if (namedPath) {\n setIn(mappedVariables, namedPath, parseInt(line));\n }\n break;\n case 'string':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim());\n }\n break;\n case 'array':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));\n }\n break;\n default:\n // console.warn(`Value unread, received type ${type}.`);\n }\n\n if (checkFinished()) {\n resolvePromise(mappedVariables);\n rl.close();\n }\n });\n return {\n waitUntilDone,\n };\n}\n\nfunction solve(testCase) {\n let k = testCase.lengthAndPermit[1];\n\n let oneCount = 0;\n let firstOne = -1;\n let lastOne = -1;\n for (let i = 0; i < testCase.theInput.length; ++i) {\n if (testCase.theInput[i] === '1') {\n if (firstOne === -1) {\n firstOne = i;\n }\n lastOne = i;\n ++oneCount;\n }\n }\n\n if (oneCount === 0) {\n return 0;\n }\n\n if (oneCount === testCase.theInput.length) {\n return 11 * (oneCount - 1);\n }\n\n let preliminarySum = 11 * oneCount;\n const distanceToLast = testCase.theInput.length - 1 - lastOne;\n const distanceToFirst = firstOne;\n\n let usedOne = false;\n if (k - distanceToLast >= 0) {\n k -= distanceToLast;\n preliminarySum -= 10;\n usedOne = true;\n }\n if (k - distanceToFirst >= 0 && (oneCount > 1 || !usedOne)) {\n preliminarySum -= 1;\n }\n\n return preliminarySum;\n}\n\n(async function main() {\n const reader = createCLIReader([\n { type: 'number', namedVariable: 'numberOfTestCase' },\n { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },\n { type: 'array', namedVariable: 'lengthAndPermit' },\n { type: 'string', namedVariable: 'theInput' }\n ]);\n const schema = await reader.waitUntilDone();\n\n for (let i = 0; i < schema.numberOfTestCase; ++i) {\n console.log(solve(schema.testCase[i]));\n }\n})();\n"}, {"source_code": "function solve() {\r\n let [n, k] = readArray(Number);\r\n const bitStr = read();\r\n let countOne = 0;\r\n let firstOne = n;\r\n let lastOne = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (bitStr[i] === '0') {\r\n continue;\r\n }\r\n countOne++;\r\n if (i > lastOne) {\r\n lastOne = i;\r\n }\r\n if (i < firstOne) {\r\n firstOne = i;\r\n }\r\n }\r\n if (countOne === 0) {\r\n write(0);\r\n return;\r\n }\r\n const leftSwaps = firstOne;\r\n const rigthSwaps = n - lastOne - 1;\r\n if (countOne === 1) {\r\n if (rigthSwaps <= k) {\r\n write(1);\r\n return;\r\n }\r\n if (leftSwaps <= k) {\r\n write(10);\r\n return;\r\n }\r\n write(11);\r\n return;\r\n }\r\n let ans = countOne * 11;;\r\n if (rigthSwaps <= k) {\r\n k -= rigthSwaps;\r\n ans -= 10;\r\n }\r\n if (leftSwaps <= k) {\r\n ans -= 1;\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n break;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n let firstPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n if (firstPos==-1)\n firstPos = i;\n }\n L({lastPos, n, k})\n let taken = false;\n if (lastPos=0 && n-1-lastPos<=k){\n sum -= 10;\n k-= n-lastPos-1;\n taken = true;\n if (lastPos==0)\n sum += 1;\n }\n if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k && firstPos Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n const t1=t\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n if(t1===243&&t1-t===69){\r\n console.log(`${m} ${n} ${s}`)\r\n return\r\n }\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n const t1=t\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n if(t===243&&t1-t===69){\r\n console.log(`${m} ${n} ${s}`)\r\n return\r\n }\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n const t1=t\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n if(t===243&&t1-t===69)console.log(`${m} ${n} ${s}`)\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i <= Math.min(m, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Number(s[i - 1] + s[i]);\r\n }\r\n let t = 0;\r\n if (s[n - 1] !== '1') {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (s[i] === '1') break;\r\n t++;\r\n }\r\n if (m >= t) {\r\n sum -= 10;\r\n m -= t;\r\n }\r\n }\r\n if (s[0] !== '1') {\r\n for (let i = 0; i < Math.min(n - t - 1, m + 1); i++) {\r\n if (s[i] === '1') {\r\n return sum - 1;\r\n }\r\n }\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i <= Math.min(m, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(str => Number(str));\r\n let t = n;\r\n if (nums[n - 1] === 0) {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (nums[i]) {\r\n if (n - i - 1 <= m) {\r\n m -= n - i - 1;\r\n nums[i] = 0;\r\n nums[n - 1] = 1;\r\n t = i + 1;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n if (nums[0] === 0) {\r\n for (let i = 0; i < Math.min(m + 1, t - 1); i++) {\r\n if (nums[i]) {\r\n nums[i] = 0;\r\n nums[0] = 1;\r\n }\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += nums[i - 1] * 10 + nums[i];\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Number(s[i - 1] + s[i]);\r\n }\r\n let t = 0;\r\n if (s[n - 1] !== '1') {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (s[i] === '1') break;\r\n t++;\r\n }\r\n if (m >= t) {\r\n sum -= 10;\r\n m -= t;\r\n }\r\n }\r\n if (s[0] !== '1') {\r\n for (let i = 0; i < Math.min(n - t - 1, m + 1); i++) {\r\n if (s[i] === '1') {\r\n return sum - 1;\r\n }\r\n }\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Number(s[i - 1] + s[i]);\r\n }\r\n let t = 0;\r\n if (s[n - 1] !== '1') {\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (s[i] === '1') break;\r\n t++;\r\n }\r\n if (m >= t) {\r\n sum -= 10;\r\n m -= t;\r\n }\r\n }\r\n if (s[0] !== '1') {\r\n for (let i = 0; i < n - t - 1; i++) {\r\n if (s[i] === '1') {\r\n if (i <= m) return sum - 1;else break;\r\n }\r\n }\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Number(s[i - 1] + s[i]);\r\n }\r\n if (s[n - 1] !== '1') {\r\n let i = 0;\r\n while (m-- > 0) {\r\n if (s[n - i - 1] === '1') {\r\n sum -= 10;\r\n break;\r\n }\r\n i++;\r\n }\r\n }\r\n if (s[0] !== '0') {\r\n let i = 0;\r\n while (m-- > 0) {\r\n if (s[i] === '1') {\r\n sum -= 1;\r\n break;\r\n }\r\n i++;\r\n }\r\n }\r\n return sum;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n let firstPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n if (firstPos==-1)\n firstPos = i;\n }\n L({lastPos, n, k})\n let taken = true;\n if (lastPos=0 && n-lastPos<=k+1){\n sum -= 10;\n k-= n-lastPos-1;\n //taken = true;\n if (lastPos==0)\n sum += 1;\n }\n if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){\n sum--;\n }\n return sum;\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n let firstPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n if (firstPos==-1)\n firstPos = i;\n }\n L({lastPos, n, k})\n let taken = false;\n if (lastPos=0 && n-lastPos<=k+1){\n sum -= 10;\n k-= n-lastPos-1;\n //taken = true;\n if (lastPos==0)\n sum += 1;\n }\n if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){\n sum--;\n }\n return sum;\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n let firstPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n if (firstPos==-1)\n firstPos = i;\n }\n L({lastPos, n, k})\n let taken = false;\n if (lastPos=0 && n-lastPos<=k+1){\n sum -= 10;\n k-= n-lastPos-1;\n taken = true;\n if (lastPos==0)\n sum += 1;\n }\n if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){\n sum--;\n }\n return sum;\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n let firstPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n if (firstPos==-1)\n firstPos = i;\n }\n L({lastPos, n, k})\n if (lastPos=0 && n-lastPos<=k+1){\n sum -= 10;\n k-= n-lastPos-1;\n if (lastPos==0)\n sum += 1;\n }\n if (firstPos!=lastPos && firstPos>0 && firstPos<=k){\n sum--;\n }\n return sum;\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n }\n L({lastPos, n, k})\n if (lastPos=0 && n-lastPos<=k+1){\n sum -= 10;\n if (lastPos==0)\n sum += 1;\n\n }\n return sum;\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n LT({n, k, s});\n // PROCESSING:\n let sum = 0;\n let lastPos = -1;\n for (let i=0; i0)\n sum += 1;\n lastPos = i;\n }\n L({lastPos, n, k})\n if (lastPos>=0 && n-lastPos<=k+1){\n sum -= 10;\n if (lastPos==0)\n sum += 1;\n\n }\n return sum;\n};\n \n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i > 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n if (zeroPadRight === N - 1) zeroPadRight = 0;\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N - 1; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (zeroPadLeft === N - 1) zeroPadLeft = 0;\r\n\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n if (S[0] === \"1\" && S[N - 1] === \"0\" && life >= N - 1) {\r\n sum -= 9;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i > 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n if (zeroPadRight === N - 1) zeroPadRight = 0;\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N - 1; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (zeroPadLeft === N - 1) zeroPadLeft = 0;\r\n\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n if (S[0] === \"1\" && S[N - 1] === \"1\" && life >= N - 1) {\r\n sum -= 9;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i >= 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n if (zeroPadRight === N) zeroPadRight = 0;\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N - 1; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (zeroPadLeft === N - 1) zeroPadLeft = 0;\r\n\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i >= 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n if (zeroPadRight === N) zeroPadRight = 0;\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (zeroPadLeft === N) zeroPadLeft = 0;\r\n\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i >= 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const [N, K] = input.next().value.split(\" \").map(Number);\r\n let S = input.next().value.split(\"\");\r\n let life = K;\r\n let sum = 0;\r\n for (let i = 1; i < N - 1; i++) {\r\n if (S[i] === \"1\") sum += 11;\r\n }\r\n\r\n let zeroPadRight = 0;\r\n for (let i = N - 1; i >= 0; i--) {\r\n if (S[i] === \"0\") zeroPadRight += 1;\r\n else break;\r\n }\r\n\r\n if (S[N - 1] === \"1\") sum += 1;\r\n else if (life !== 0 && life >= zeroPadRight) {\r\n sum -= 10;\r\n life -= zeroPadRight;\r\n S[N - 1] = \"1\";\r\n S[N - 1 - zeroPadRight] = \"0\";\r\n }\r\n\r\n let zeroPadLeft = 0;\r\n for (let i = 0; i < N; i++) {\r\n if (S[i] === \"0\") zeroPadLeft += 1;\r\n else break;\r\n }\r\n if (S[0] === \"1\") sum += 10;\r\n else if (life !== 0 && life > zeroPadLeft) {\r\n sum -= 10;\r\n }\r\n\r\n results.push(sum);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "/**\n * Format:\n * {type: 'number', namedVariable?: string }\n * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }\n * {type: 'array', namedVariable?: string }\n * {type: 'string', namedVariable?: string }\n */\nconst readline = require('readline');\n\nfunction createCLIReader(instructions) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const mappedVariables = {};\n\n let resolvePromise = null;\n const donePromise = new Promise((res, rej) => {\n resolvePromise = res;\n });\n\n function waitUntilDone() {\n return donePromise;\n }\n\n /**\n * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }\n */\n const stack = [];\n let pc = -1;\n\n function finished() {\n if (pc >= instructions.length) {\n return true;\n }\n return false;\n }\n\n function checkFinished() {\n // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);\n if (pc >= instructions.length) {\n return true;\n }\n if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {\n return true;\n }\n return false;\n }\n\n function getNextInstructionContext() {\n if (!stack.length) {\n return {\n index: ++pc,\n }\n }\n const lastStack = stack[stack.length - 1];\n if (lastStack.pointer === lastStack.instructionCount) {\n lastStack.pointer = 0;\n lastStack.iteration = lastStack.iteration + 1;\n }\n if (lastStack.count === lastStack.iteration) {\n stack.pop();\n pc = lastStack.basePointer + lastStack.instructionCount + 1;\n return {\n index: pc,\n }\n }\n\n lastStack.pointer = lastStack.pointer + 1;\n return {\n index: lastStack.basePointer + lastStack.pointer,\n context: {\n namedPath: [...lastStack.context.namedPath, lastStack.iteration]\n }\n }\n }\n\n function pushRepeatToStack(instruction, index, context) {\n stack.push({\n type: 'repeat',\n count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],\n iteration: 0,\n basePointer: index,\n pointer: 0,\n instructionCount: instruction.instructionCount,\n context: {\n namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],\n }\n })\n setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);\n }\n\n function nextInstruction() {\n if (finished()) {\n // console.warn('Calling nextInstruction after finished, something is wrong');\n return;\n }\n while (true) {\n const { index, context } = getNextInstructionContext();\n const instruction = instructions[index];\n\n // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);\n switch (instruction.type) {\n case 'number':\n case 'array':\n case 'string':\n return {\n ...instruction,\n namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,\n }\n case 'repeat':\n pushRepeatToStack(instruction, index, context);\n break;\n default:\n // console.warn('Unclear instruction, abort');\n return;\n }\n }\n }\n\n function getIn(object, path) {\n for (let i = 0; i < path.length; ++i) {\n object = object[path[i]];\n }\n return object;\n }\n\n function setIn(object, path, value) {\n for (let i = 0; i < path.length - 1; ++i) {\n if (object[path[i]] == null) {\n object[path[i]] = {};\n }\n object = object[path[i]];\n }\n object[path[path.length - 1]] = value;\n }\n\n rl.on('line', line => {\n if (finished()) {\n return;\n }\n const { type, namedPath } = nextInstruction();\n switch (type) {\n case 'number':\n if (namedPath) {\n setIn(mappedVariables, namedPath, parseInt(line));\n }\n break;\n case 'string':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim());\n }\n break;\n case 'array':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));\n }\n break;\n default:\n // console.warn(`Value unread, received type ${type}.`);\n }\n\n if (checkFinished()) {\n resolvePromise(mappedVariables);\n rl.close();\n }\n });\n return {\n waitUntilDone,\n };\n}\n\nfunction solve(testCase) {\n let k = testCase.lengthAndPermit[1];\n\n let oneCount = 0;\n let firstOne = -1;\n let lastOne = -1;\n for (let i = 0; i < testCase.theInput.length; ++i) {\n if (testCase.theInput[i] === '1') {\n if (firstOne === -1) {\n firstOne = i;\n }\n lastOne = i;\n ++oneCount;\n }\n }\n\n if (oneCount === 0) {\n return 0;\n }\n\n if (oneCount === testCase.theInput.length) {\n return 11 * (oneCount - 1);\n }\n\n let preliminarySum = 11 * oneCount;\n const distanceToLast = testCase.theInput.length - 1 - lastOne;\n const distanceToFirst = firstOne;\n\n if (k - distanceToLast >= 0) {\n k -= distanceToLast;\n preliminarySum -= 10;\n }\n if (k - distanceToFirst >= 0 && oneCount > 1) {\n preliminarySum -= 1;\n }\n\n return preliminarySum;\n}\n\n(async function main() {\n const reader = createCLIReader([\n { type: 'number', namedVariable: 'numberOfTestCase' },\n { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },\n { type: 'array', namedVariable: 'lengthAndPermit' },\n { type: 'string', namedVariable: 'theInput' }\n ]);\n const schema = await reader.waitUntilDone();\n\n for (let i = 0; i < schema.numberOfTestCase; ++i) {\n console.log(solve(schema.testCase[i]));\n }\n})();\n"}, {"source_code": "/**\n * Format:\n * {type: 'number', namedVariable?: string }\n * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }\n * {type: 'array', namedVariable?: string }\n * {type: 'string', namedVariable?: string }\n */\nconst readline = require('readline');\n\nfunction createCLIReader(instructions) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const mappedVariables = {};\n\n let resolvePromise = null;\n const donePromise = new Promise((res, rej) => {\n resolvePromise = res;\n });\n\n function waitUntilDone() {\n return donePromise;\n }\n\n /**\n * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }\n */\n const stack = [];\n let pc = -1;\n\n function finished() {\n if (pc >= instructions.length) {\n return true;\n }\n return false;\n }\n\n function checkFinished() {\n // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);\n if (pc >= instructions.length) {\n return true;\n }\n if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {\n return true;\n }\n return false;\n }\n\n function getNextInstructionContext() {\n if (!stack.length) {\n return {\n index: ++pc,\n }\n }\n const lastStack = stack[stack.length - 1];\n if (lastStack.pointer === lastStack.instructionCount) {\n lastStack.pointer = 0;\n lastStack.iteration = lastStack.iteration + 1;\n }\n if (lastStack.count === lastStack.iteration) {\n stack.pop();\n pc = lastStack.basePointer + lastStack.instructionCount + 1;\n return {\n index: pc,\n }\n }\n\n lastStack.pointer = lastStack.pointer + 1;\n return {\n index: lastStack.basePointer + lastStack.pointer,\n context: {\n namedPath: [...lastStack.context.namedPath, lastStack.iteration]\n }\n }\n }\n\n function pushRepeatToStack(instruction, index, context) {\n stack.push({\n type: 'repeat',\n count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],\n iteration: 0,\n basePointer: index,\n pointer: 0,\n instructionCount: instruction.instructionCount,\n context: {\n namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],\n }\n })\n setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);\n }\n\n function nextInstruction() {\n if (finished()) {\n // console.warn('Calling nextInstruction after finished, something is wrong');\n return;\n }\n while (true) {\n const { index, context } = getNextInstructionContext();\n const instruction = instructions[index];\n\n // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);\n switch (instruction.type) {\n case 'number':\n case 'array':\n case 'string':\n return {\n ...instruction,\n namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,\n }\n case 'repeat':\n pushRepeatToStack(instruction, index, context);\n break;\n default:\n // console.warn('Unclear instruction, abort');\n return;\n }\n }\n }\n\n function getIn(object, path) {\n for (let i = 0; i < path.length; ++i) {\n object = object[path[i]];\n }\n return object;\n }\n\n function setIn(object, path, value) {\n for (let i = 0; i < path.length - 1; ++i) {\n if (object[path[i]] == null) {\n object[path[i]] = {};\n }\n object = object[path[i]];\n }\n object[path[path.length - 1]] = value;\n }\n\n rl.on('line', line => {\n if (finished()) {\n return;\n }\n const { type, namedPath } = nextInstruction();\n switch (type) {\n case 'number':\n if (namedPath) {\n setIn(mappedVariables, namedPath, parseInt(line));\n }\n break;\n case 'string':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim());\n }\n break;\n case 'array':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));\n }\n break;\n default:\n // console.warn(`Value unread, received type ${type}.`);\n }\n\n if (checkFinished()) {\n resolvePromise(mappedVariables);\n rl.close();\n }\n });\n return {\n waitUntilDone,\n };\n}\n\nfunction solve(testCase) {\n let k = testCase.lengthAndPermit[1];\n\n let oneCount = 0;\n let firstOne = -1;\n let lastOne = -1;\n for (let i = 0; i < testCase.theInput.length; ++i) {\n if (testCase.theInput[i] === '1') {\n if (firstOne === -1) {\n firstOne = i;\n }\n lastOne = i;\n ++oneCount;\n }\n }\n\n if (oneCount === 0) {\n return 0;\n }\n\n if (oneCount === testCase.theInput.length) {\n return 11 * (oneCount - 1);\n }\n\n let preliminarySum = 11 * oneCount;\n const distanceToLast = testCase.theInput.length - 1 - lastOne;\n const distanceToFirst = firstOne;\n\n if (k - distanceToLast >= 0) {\n k -= distanceToLast;\n preliminarySum -= 10;\n }\n if (k - distanceToFirst >= 0) {\n preliminarySum -= 1;\n }\n\n return preliminarySum;\n}\n\n(async function main() {\n const reader = createCLIReader([\n { type: 'number', namedVariable: 'numberOfTestCase' },\n { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },\n { type: 'array', namedVariable: 'lengthAndPermit' },\n { type: 'string', namedVariable: 'theInput' }\n ]);\n const schema = await reader.waitUntilDone();\n\n for (let i = 0; i < schema.numberOfTestCase; ++i) {\n console.log(solve(schema.testCase[i]));\n }\n})();\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n while (t--) {\r\n let [n,k]=(await read()).split(' ').map(Number);\r\n let a=await read();\r\n let ans=0;\r\n let i,j;\r\n for (i = a.length-1; i >= 0; i--){\r\n const e = a[i];\r\n if(e=='1'){\r\n const cost=a.length-i-1;\r\n if(cost<=k){\r\n k-=cost;\r\n ans+=1;\r\n }else{\r\n ans+=11;\r\n }\r\n break;\r\n }\r\n }\r\n for (j = 0; j < i; j++){\r\n const e = a[j];\r\n if(e=='1'){\r\n const cost=j;\r\n if(cost<=k){\r\n k-=cost;\r\n ans+=10;\r\n }else{\r\n ans+=11;\r\n }\r\n break;\r\n \r\n }\r\n }\r\n for (j++; j < i; j++){\r\n if(a[j]=='1'){\r\n ans+=11;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}], "src_uid": "ccecf97fcddbd0ab030d34b79a42cc6e"} {"source_code": "const readline = require('readline')\n\nasync function algo() {\n let [x, y, z, k] = await ints()\n let i = 0\n if (k < x) [k, x] = [x, k]\n if (k < y) [k, y] = [y, k]\n if (k < z) [k, z] = [z, k]\n const a = k - x\n console.log([a, y-a, z-a].join(' '))\n}\n\n\n// read the input\nconst _lines = []\nlet _lineIndex = 0\nlet _ended = false\nconst _rl = readline.createInterface(process.stdin)\n_rl.on('line', line => _lines.push(line))\n_rl.on('end', () => (ended = true))\nconst wait = ms => new Promise(resolve => setTimeout(resolve, ms))\nconst line = async () => {\n while (!_ended && _lines.length <= _lineIndex) await wait(10)\n const result = _lines[_lineIndex].trim()\n _lines[_lineIndex] = null\n _lineIndex++\n return result\n}\nconst words = async () => (await line()).split(' ')\nconst chars = async () => (await line()).split('')\nconst int = async () => parseInt(await line())\nconst ints = async () => (await words()).map(x => parseInt(x))\nconst big = async () => BigInt(await line())\nconst bigs = async () => (await words()).map(x => BigInt(x))\n\nalgo()", "positive_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++].split(' ');\n}\n\nfunction readInt(s) {\n return parseInt(s, 10);\n}\n\nfunction readIntArray(a) {\n return a.map(e => parseInt(e, 10));\n}\n\nfunction solve(n) {\n n.sort((a, b) => a - b);\n return [n[3] - n[0], n[3] - n[2], n[3] - n[1]];\n}\n\nfunction main() {\n\n const n = readIntArray(readLine());\n\n let result = solve(n);\n console.log(result.join(' '));\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.on('line', (line) => {\n let numbers = [];\n let addedNumbers = line.split(' ').map(Number);\n let abc = Math.max(...addedNumbers);\n addedNumbers.splice(addedNumbers.indexOf(abc), 1);\n addedNumbers.forEach((number) => {\n numbers.push(abc - number);\n });\n\n console.log(...numbers);\n});"}, {"source_code": "let readline = require('readline');\nlet intInput = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\nlet nums;\n\nintInput.on('line', (line) => {\n\tnums = line.split(\" \");\n});\n\nintInput.on('close', () => {\n\tlet max = Number(nums[0]);\n\tlet maxI = 0;\n\tfor (let i = 1; i < nums.length; i++) {\n\t\tif ( nums[i] > max) {\n\t\t\tmax = Number(nums[i]);\n\t\t\tmaxI = i\n\t\t}\n\t}\n\tnums.splice(maxI, 1);\n\tlet result = \"\";\n\tfor (let j = 0; j < nums.length; j++) {\n\t\tlet a = max - Number(nums[j]);\n\t\tj == nums.length -1 ? result += `${a}` : result += `${a}` + \" \";\n\t}\n\tconsole.log(result);\n})"}, {"source_code": "function main() {\n // write code here:\n var arr=(stdin[0].split(' ')).map(a => Number(a)).sort((a,b) => a-b);\n var a=arr[3]-arr[2],b=arr[3]-arr[1],c=arr[3]-arr[0];\n console.log(a,b,c);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function (results) {\n const res = results.split(' ').map(num => parseInt(num));\n calNums(res);\n rl.close();\n});\n\nrl.on(\"close\", function () {\n process.exit(0);\n});\n\nfunction calNums(res) {\n let a = 0, b = 0, c = 0;\n res.sort(function (a, b) { return a - b });\n b = (res[0] - res[1] + res[2]) / 2;\n a = res[0] - b ; \n c = res[2] - b ; \n\n console.log(`${a} ${b} ${c}`);\n}\n\n\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n one.sort(function(a, b){\n \treturn a - b;\n });\n var L = one[3] - one[2];\n var C = one[3] - one[1];\n var R = one[3] - one[0];\n myout(L + \" \" + C + \" \" + R);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const ans = [];\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n for (let i = 0; i < arr.length - 1; i++) {\n ans.push(arr[arr.length - 1] - arr[i]);\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let {0:x1, 1:x2, 2:x3, 3:x4} = {...input[0].split(' ')};\n x1 = parseInt(x1); x2 = parseInt(x2);\n x3 = parseInt(x3); x4 = parseInt(x4);\n let max = (x1 > x2 && x1 > x3 && x1 > x4) ? x1 : \n (x2 > x1 && x2 > x3 && x2 > x4) ? x2 : \n (x3 > x1 && x3 > x2 && x3 > x4) ? x3 : x4;\n \n input[0].split(' ').forEach( i => {\n if(parseInt(i) != parseInt(max))\n console.log(max - i);\n });\n});\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [x1, x2, x3, x4] = input[0].split(' ').map(x => parseInt(x));\n\n let max = Math.max(x1, x2, x3, x4);\n const nums = [];\n\n input[0].split(' ').map(x => parseInt(x)).forEach( x => {\n if (x !== max) {\n nums.push(max - x);\n }\n });\n\n console.log(nums.join(' '));\n}); \n "}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\n// main function .... code start ... ///\nfunction main() {\n\n //var input = readline()\n var ar = readline().split(' ').map(x => parseInt(x)) \n ar.sort((a, b) => a - b)\n var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]\n console.log(k.join(' ')) \n}\n\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n //var input = readline();\n var ar = readline().split(\" \").map(x => parseInt(x));\n ar.sort((a, b) => a - b);\n var k = [ar[3] - ar[2], ar[3] - ar[1], ar[3] - ar[0]];\n print(k.join(\" \"));\n}\n"}, {"source_code": "//******************************************************************************** //\n'use strict'; process.stdin.resume(); //\nprocess.stdin.setEncoding('utf-8'); //\nlet inputString = ''; let currentLine = 0; //\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin }); //\nprocess.stdin.on('end', () => { inputString = inputString.split('\\n'); main(); }); //\nfunction readline() { return inputString[currentLine++]; } //\n//******************************************************************************** //\n\nfunction main() {\n\n //var input = readline()\n var ar = readline().split(' ').map(x => parseInt(x)) \n ar.sort((a, b) => a - b)\n var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]\n console.log(k.join(' ')) \n \n}\n\n"}, {"source_code": "'use strict'; process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = ''; let currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', () => {\n inputString = inputString.split('\\n');\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n// ******************************************************\n// ******************** Code Start **********************\n\nfunction main() {\n \n //var input = readline();\n var ar = readline().split(' ').map(x => parseInt(x)) ;\n ar.sort((a, b) => a - b);\n var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]];\n console.log(k.join(' '));\n \n}"}, {"source_code": "//******************************************************************************** //\n'use strict'; process.stdin.resume(); //\nprocess.stdin.setEncoding('utf-8'); //\nlet inputString = ''; let currentLine = 0; //\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin }); //\nprocess.stdin.on('end', () => { inputString = inputString.split('\\n'); main(); }); //\nfunction readline() { return inputString[currentLine++]; } //\n //\n//******************************************************************************** //\n\nfunction main() {\n\n //var input = readline()\n var ar = readline().split(' ').map(x => parseInt(x)) \n ar.sort((a, b) => a - b)\n var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]\n console.log(k.join(' ')) \n \n}\n"}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n let num = arr[0].split(' ');\n //num.pop();\n let a = parseInt(num[0]);\n let b = parseInt(num[1]);\n let c = parseInt(num[2]);\n let d = parseInt(num[3]);\n let max = 0;\n if(a>b && a>c && a>d) max = a;\n else if(b>a && b>c && b>d) max =b;\n else if(c>a && c>b && c>d) max =c;\n else max =d;\n \n let str,str1,str2,str3;\n (max !==a)?str = max-a:str='';\n (max !==b)?str1 =max-b:str1='';\n (max !==c)?str2 =max-c:str2='';\n (max !==d)?str3 =max-d:str3='';\n console.log(str+\" \"+str1+\" \"+str2+\" \"+str3);\n }); "}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split(' ').map(num => Number(num));\n let max = Math.max(...inputs);\n let newNum = [];\n for (const iterator of inputs) {\n if (iterator !== max) {\n newNum.push(max - iterator);\n }\n }\n return newNum.join(' ').toString();\n}\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let arr = readLine().split(' ').map(v => parseInt(v)).sort((a, b) => {\n return a - b;\n });\n let x1 = arr[0];\n let x2 = arr[1];\n let x3 = arr[2];\n let x4 = arr[3];\n console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)\n}"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var numbers = read.arrNumber(' ');\n\n numbers.sort((a, b) => a - b);\n\n var a = numbers[3] - numbers[2];\n var b = numbers[1] - a;\n var c = numbers[0] - a;\n print(a + ' ' + b + ' ' + c);\n}());\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nn.sort((a,b) => a-b);\n\nvar a = n[3]-n[0];\nvar b = n[3]-n[1];\nvar c = n[3]-n[2];\n\nprint(a,b,c);"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar x1 = numbers[0];\nvar x2 = numbers[1];\nvar x3 = numbers[2];\nvar x4 = numbers[3];\n var maxX = 0;\n var massiveXes = [];\n var a;\n var b;\n var c;\n massiveXes.push(x2, x1, x3, x4);\n \n for (i = 0; i< massiveXes.length; i++){\n\tif (maxX < massiveXes[i]){\n\t\tmaxX = massiveXes[i];\n\t}\n\t \n }\n\n for (k=0; k parseInt(z))\nvar total = ns.reduce((p, c) => p > c ? p : c)\nns.splice(ns.indexOf(total), 1)\nvar get = (x, y, z) => {\n var c = Math.abs((((x - y) + (x - z)) - x) / 2)\n return [c, x - z + c, x - y + c]\n}\nvar o = [\n [0, 1, 2],\n [0, 2, 1],\n [1, 0, 2],\n [1, 2, 0],\n [2, 0, 1],\n [2, 1, 0]\n].map(z => z.map(y => ns[y]))\n .map(z => get.apply([], z))\n .filter(z => z.reduce((p, c) => p + c) == total)[0]\n .sort((a, b) => a - b)\n .join(\" \")\nprint(o)"}, {"source_code": "var n = readline().split(' ').map(Number);\n// var n = prompt().split(' ').map(Number);\nn.sort((a,b) => a-b);\nvar a = n[3]-n[0];\nvar b = n[3]-n[1];\nvar c = n[3]-n[2];\n// console.log(a, b, c);\nprint(a, b, c);"}, {"source_code": "var n = readline().split(' ').map(Number);\nn.sort((a,b) => a-b);\nvar a = n[3]-n[0];\nvar b = n[3]-n[1];\nvar c = n[3]-n[2];\nprint(a, b, c);"}, {"source_code": "var s = readline().split(\" \").map(function(e){return parseInt(e);});\nvar x = Math.max(...s);var b = s.indexOf(x);\n\n\n\nvar show = \"\";for(var i=0;iINPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "//var input = readline()\n\nvar ar = readline().split(' ').map(x => parseInt(x)) \nar.sort((a, b) => a - b)\nvar k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]\nprint(k.join(' '))\n\n//"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nasync function algo() {\n const [x, y, z, k] = await ints()\n let i = 0\n if (k < x) [k, x] = [x, k]\n if (k < y) [k, y] = [y, k]\n if (k < z) [k, z] = [z, k]\n const a = k - x\n console.log([a, y-a, z-a].join(' '))\n}\n\n\n// read the input\nconst _lines = []\nlet _lineIndex = 0\nlet _ended = false\nconst _rl = readline.createInterface(process.stdin)\n_rl.on('line', line => _lines.push(line))\n_rl.on('end', () => (ended = true))\nconst wait = ms => new Promise(resolve => setTimeout(resolve, ms))\nconst line = async () => {\n while (!_ended && _lines.length <= _lineIndex) await wait(10)\n const result = _lines[_lineIndex].trim()\n _lines[_lineIndex] = null\n _lineIndex++\n return result\n}\nconst words = async () => (await line()).split(' ')\nconst chars = async () => (await line()).split('')\nconst int = async () => parseInt(await line())\nconst ints = async () => (await words()).map(x => parseInt(x))\nconst big = async () => BigInt(await line())\nconst bigs = async () => (await words()).map(x => BigInt(x))\n\nalgo()"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.on('line', (line) => {\n let numbers = [];\n let addedNumbers = line.split(' ').map(Number);\n let abc = Math.max(...addedNumbers);\n addedNumbers.splice(addedNumbers.indexOf(abc), 1);\n addedNumbers.forEach((number) => {\n numbers.push(abc - number);\n });\n\n return {...numbers};\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.on('line', (line) => {\n let numbers = [];\n let addedNumbers = line.split(' ').map(Number);\n let abc = Math.max(...addedNumbers);\n addedNumbers.splice(addedNumbers.indexOf(abc), 1);\n addedNumbers.forEach((number) => {\n numbers.push(abc - number);\n });\n\n return numbers.join(' ');\n});"}, {"source_code": "let readline = require('readline');\nlet intInput = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\nlet nums;\n\nintInput.on('line', (line) => {\n\tnums = line.split(\" \");\n});\n\nintInput.on('close', () => {\n\tlet max = nums[0];\n\tlet maxI = 0;\n\tfor (let i = 1; i < nums.length; i++) {\n\t\tif ( nums[i] > max) {\n\t\t\tmax = Number(nums[i]);\n\t\t\tmaxI = i\n\t\t}\n\t}\n\tnums.splice(maxI, 1);\n\tlet result = \"\";\n\tfor (let j = 0; j < nums.length; j++) {\n\t\tlet a = max - Number(nums[j]);\n\t\tj == nums.length -1 ? result += `${a}` : result += `${a}` + \" \";\n\t}\n\tconsole.log(result);\n})"}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n let d = parseInt(num[3]);\n console.log(\"for d:\"+d);\n }); "}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n //num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n let d = parseInt(num[3]);\n console.log(\"for d:\"+d);\n }); "}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n }); "}, {"source_code": "var arr = '';\nprocess.stdin.on('data',function(chunk){\n arr += chunk; \n});\nprocess.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n});\n"}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n //num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n let d = parseInt(num[3]);\n console.log(\"for d:\"+d);\n let max = 0;\n if(a>b && a>c && a>d) max = a;\n else if(b>a && b>c && b>d) max =b;\n else if(c>a && c>b && c>d) max =c;\n else max =d;\n console.log((max-a)+\" \"+(max-b)+\" \"+(max-c)+\" \"+(max-d));\n }); "}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n //num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n let d = parseInt(num[3]);\n console.log(\"for d:\"+d);\n let max = 0;\n if(a>b && a>c && a>d) max = a;\n else if(b>a && b>c && b>d) max =b;\n else if(c>a && c>b && c>d) max =c;\n else max =d;\n \n let str = '';\n if(max !==a) str = str + (max-a);\n if(max !==b) str = str + (max-b);\n if(max !==c) str = str + (max-c);\n if(max !==d) str = str + (max-d);\n console.log(\"for str:\"+str);\n str = str.split('');\n console.log(str.join(' '));\n //console.log((max-a)+\" \"+(max-b)+\" \"+(max-c)+\" \"+(max-d));\n }); "}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n let num = arr[0].split(' ');\n //num.pop();\n let a = parseInt(num[0]);\n let b = parseInt(num[1]);\n let c = parseInt(num[2]);\n let d = parseInt(num[3]);\n let max = 0;\n if(a>b && a>c && a>d) max = a;\n else if(b>a && b>c && b>d) max =b;\n else if(c>a && c>b && c>d) max =c;\n else max =d;\n \n let str = '';\n if(max !==a) str = str + (max-a);\n if(max !==b) str = str + (max-b);\n if(max !==c) str = str + (max-c);\n if(max !==d) str = str + (max-d);\n str = str.split('');\n console.log(str.join(' '));\n }); "}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n num = num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n });"}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n }); "}, {"source_code": "var arr = '';\nprocess.stdin.on('data',function(chunk){\n arr += chunk; \n});\nprocess.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let a = parseInt(arr[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(arr[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(arr[2]);\n console.log(\"for c:\"+c);\n});\n"}, {"source_code": "var arr = '';\nprocess.stdin.on('data',function(chunk){\n arr += chunk; \n});\nprocess.stdin.on('end',function(){\n arr = arr.split('\\n');\n console.log(\"for arr\");\n console.log(arr);\n});\n"}, {"source_code": " var arr = '';\n process.stdin.on('data',function(chunk){\n arr += chunk; \n });\n process.stdin.on('end',function(){\n arr = arr.split('\\n');\n arr.pop();\n console.log(\"for arr\");\n console.log(arr);\n let num = arr[0].split(' ');\n num.pop();\n console.log(\"for num\");\n console.log(num);\n let a = parseInt(num[0]);\n console.log(\"for a:\"+a);\n let b = parseInt(num[1]);\n console.log(\"for b:\"+b);\n let c = parseInt(num[2]);\n console.log(\"for c:\"+c);\n });"}, {"source_code": "var arr = '';\nprocess.stdin.on('data',function(chunk){\n arr += chunk; \n});\nconsole.log(\"for arr\");\nconsole.log(arr);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let arr = readLine().split(' ').map(v => parseInt(v)).sort();\n let x1 = arr[0];\n let x2 = arr[1];\n let x3 = arr[2];\n let x4 = arr[3];\n console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let arr = readLine().split(' ').map(v => parseInt(v)).sort((a, b) => {\n return a - b;\n });\n console.log(arr);\n let x1 = arr[0];\n let x2 = arr[1];\n let x3 = arr[2];\n let x4 = arr[3];\n console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)\n}"}], "src_uid": "cda949a8fb1f158f3c06109a2d33f084"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function f(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const helper = fn => {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[[done, []], args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const [after, args] = curCall.pop();\r\n after(...args);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before(...args);\r\n let nextCall = inside(...args);\r\n callStack.push([[after, args], ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n };\r\n const dfs = helper((u, x, y) => {\r\n const before = (u, x, y) => {\r\n st[u] = 1;\r\n f(y, -1);\r\n f(x, 1);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n res.push([v, x, y]);\r\n }\r\n return res;\r\n };\r\n const after = (u, x, y) => {\r\n f(y, 1);\r\n f(x, -1);\r\n };\r\n return [before, inside, after];\r\n });\r\n dfs(0, 0, 0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n async function helper(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = async u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n await helper(y, -1);\r\n await helper(x, 1);\r\n await dfs(v);\r\n await helper(y, 1);\r\n await helper(x, -1);\r\n }\r\n };\r\n await dfs(0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(await solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function f(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const helper = fn => {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[done, args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const after = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside(...args);\r\n callStack.push([after, ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n };\r\n const dfs = helper((u, x, y) => {\r\n const before = () => {\r\n st[u] = 1;\r\n f(y, -1);\r\n f(x, 1);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n res.push([v, x, y]);\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n f(y, 1);\r\n f(x, -1);\r\n };\r\n return [before, inside, after];\r\n });\r\n dfs(0, 0, 0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function f(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const helper = fn => {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[[done, []], args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const [after, args] = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside(...args);\r\n callStack.push([[after, args], ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n };\r\n const dfs = helper((u, x, y) => {\r\n const before = () => {\r\n st[u] = 1;\r\n f(y, -1);\r\n f(x, 1);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n res.push([v, x, y]);\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n f(y, 1);\r\n f(x, -1);\r\n };\r\n return [before, inside, after];\r\n });\r\n dfs(0, 0, 0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function f(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const helper = fn => {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[[done, []], args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const [after, args] = curCall.pop();\r\n after(...args);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before(...args);\r\n let nextCall = inside(...args);\r\n callStack.push([[after, args], ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n };\r\n const dfs = helper((u, x, y) => {\r\n const before = () => {\r\n st[u] = 1;\r\n f(y, -1);\r\n f(x, 1);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n res.push([v, x, y]);\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n f(y, 1);\r\n f(x, -1);\r\n };\r\n return [before, inside, after];\r\n });\r\n dfs(0, 0, 0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function helper(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n const callStack = [[[u, 0, 0]]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const [v, x, y] = curCall.pop();\r\n helper(y, 1);\r\n helper(x, -1);\r\n }\r\n if (!curCall) break;\r\n const [u, x, y] = curCall[curCall.length - 1];\r\n helper(y, -1);\r\n helper(x, 1);\r\n st[u] = 1;\r\n let nextCall = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n nextCall.push([v, x, y]);\r\n }\r\n callStack.push(nextCall);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n g[i].push(j);\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function helper(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n helper(y, -1);\r\n helper(x, 1);\r\n dfs(v);\r\n helper(y, 1);\r\n helper(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n let xs = new Set();\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n xs.add(x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function helper(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n helper(y, -1);\r\n helper(x, 1);\r\n dfs(v);\r\n helper(y, 1);\r\n helper(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n try {\r\n res.push(solve(n, b));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n }\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n let xs = new Set();\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n xs.add(x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function helper(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n helper(y, -1);\r\n helper(x, 1);\r\n dfs(v);\r\n helper(y, 1);\r\n helper(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 2; i <= n; i++) {\r\n if (max[i]) num = mul(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n console.log((ori.reduce((a, b) => a + b, 0) % MOD).toString());\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n new Date().valueOf();\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n let xs = new Set();\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n xs.add(x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n new Date().valueOf();\r\n const primes = getPrimes(n);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n let xs = new Set();\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n xs.add(x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = new Map();\r\nfunction power(a, b) {\r\n var _cache$get;\r\n let res = (_cache$get = cache.get(a)) === null || _cache$get === void 0 ? void 0 : _cache$get.get(b);\r\n if (res) return res;\r\n res = 1;\r\n let a1 = a,\r\n b1 = b;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n if (cache.has(a1)) {\r\n cache.get(a1).set(b1, res);\r\n } else {\r\n cache.set(a1, new Map([[b1, res]]));\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n const N = 16;\r\n return ((a >> N) * b % MOD * (1 << N) + (a & (1 << N) - 1) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n let xs = new Set();\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n xs.add(x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, power(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, power(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = new Map();\r\nfunction power(a, b) {\r\n var _cache$get;\r\n let res = (_cache$get = cache.get(a)) === null || _cache$get === void 0 ? void 0 : _cache$get.get(b);\r\n if (res) return res;\r\n res = 1;\r\n let a1 = a,\r\n b1 = b;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n if (cache.has(a1)) {\r\n cache.get(a1).set(b1, res);\r\n } else {\r\n cache.set(a1, new Map([[b1, res]]));\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nlet flag = false;\r\nfunction solve(n, a, max) {\r\n if (n === 200000 && a[0][0] === 51097) flag = true;\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug1', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let res = 0;\r\n let st = [];\r\n const dfs = u => {\r\n res = (res + st[u]) % MOD;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n if (n === 200000 && a[0][0] === 51097) {\r\n st[v] = mod(st[u], y);\r\n } else st[v] = mod(st[u], y, quickMi(x, MOD - 2));\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n st[0] = 1;\r\n dfs(0);\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug2', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) res = mod(res, quickMi(i, max[i]));\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug3', new Date().valueOf() - time);\r\n }\r\n return res;\r\n }\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = new Map();\r\nfunction quickMi(a, b) {\r\n const state = `${a},${b}`;\r\n if (cache.has(state)) return cache.get(state);\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n cache.set(state, res);\r\n return res;\r\n}\r\nconst MAXN = 9 * 10 ** 15;\r\nfunction mul(a, b) {\r\n if (flag) return a * b % MOD;\r\n let num = a * b;\r\n if (num > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return num >= MOD ? num % MOD : num;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n if (n === 200000 && b[0][0] === 51097) {\r\n res.push(solve(n, b, n));\r\n }\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nlet flag = false;\r\nfunction solve(n, a, max) {\r\n if (n === 200000 && a[0][0] === 51097) flag = true;\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug1', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let res = 0;\r\n let st = [];\r\n const dfs = u => {\r\n res = (res + st[u]) % MOD;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n if (n === 200000 && a[0][0] === 51097) ; else st[v] = mod(st[u], y, quickMi(x, MOD - 2));\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n st[0] = 1;\r\n dfs(0);\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug2', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) res = mod(res, quickMi(i, max[i]));\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug3', new Date().valueOf() - time);\r\n }\r\n return res;\r\n }\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = new Map();\r\nfunction quickMi(a, b) {\r\n const state = `${a},${b}`;\r\n if (cache.has(state)) return cache.get(state);\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n cache.set(state, res);\r\n return res;\r\n}\r\nconst MAXN = 9 * 10 ** 15;\r\nfunction mul(a, b) {\r\n if (flag) return a * b % MOD;\r\n let num = a * b;\r\n if (num > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return num >= MOD ? num % MOD : num;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n if (n === 200000 && b[0][0] === 51097) {\r\n res.push(solve(n, b, n));\r\n }\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nlet flag = false;\r\nfunction solve(n, a, max) {\r\n if (n === 200000 && a[0][0] === 51097) flag = true;\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug1', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let res = 0;\r\n let st = [];\r\n const dfs = u => {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n st[v] = mod(st[u], y);\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n st[0] = 1;\r\n dfs(0);\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug2', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) res = mod(res, quickMi(i, max[i]));\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug3', new Date().valueOf() - time);\r\n }\r\n return res;\r\n }\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = new Map();\r\nfunction quickMi(a, b) {\r\n const state = `${a},${b}`;\r\n if (cache.has(state)) return cache.get(state);\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n cache.set(state, res);\r\n return res;\r\n}\r\nconst MAXN = 9 * 10 ** 15;\r\nfunction mul(a, b) {\r\n if (flag) return a * b % MOD;\r\n let num = a * b;\r\n if (num > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return num >= MOD ? num % MOD : num;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n if (n === 200000 && b[0][0] === 51097) {\r\n res.push(solve(n, b, n));\r\n }\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug1', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let res = 0;\r\n let st = [];\r\n const dfs = u => {\r\n res = (res + st[u]) % MOD;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n st[v] = mod(st[u], y, quickMi(x, MOD - 2));\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n st[0] = 1;\r\n dfs(0);\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug2', new Date().valueOf() - time);\r\n time = new Date().valueOf();\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) res = mod(res, quickMi(i, max[i]));\r\n }\r\n if (n === 200000 && a[0][0] === 51097) {\r\n console.log('debug3', new Date().valueOf() - time);\r\n }\r\n return res;\r\n }\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res;else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 9 * 10 ** 15;\r\nconst cache1 = {};\r\nfunction mul(a, b) {\r\n var _cache1$a;\r\n if ((_cache1$a = cache1[a]) !== null && _cache1$a !== void 0 && _cache1$a[b]) return cache1[a][b];\r\n let num = a * b,\r\n res = 0;\r\n if (num > MAXN) res = Number(BigInt(a) * BigInt(b) % BigInt(MOD));else res = num > MOD ? num % MOD : num;\r\n if (cache1[a]) {\r\n cache1[a][b] = res;\r\n } else {\r\n cache[a] = {\r\n [b]: res\r\n };\r\n }\r\n return res;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n if (n === 200000 && b[0][0] === 51097) {\r\n res.push(solve(n, b, n));\r\n }\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n const minp = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) {\r\n primes.push(i);\r\n minp[i] = i;\r\n }\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n minp[j] = num;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => new Map());\r\n for (let i = 1; i <= n; i++) {\r\n for (let j = i; j > 1; j /= minp[j]) {\r\n var _res$i$get;\r\n res[i].set(minp[j], ((_res$i$get = res[i].get(minp[j])) !== null && _res$i$get !== void 0 ? _res$i$get : 0) + 1);\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res;else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n let num = a * b;\r\n if (num > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return num > MOD ? num % MOD : num;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n if (n === 200000) {\r\n res.push(solve(n, b, n));\r\n }\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n if (n === 20000) console.log(time);\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res;else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nlet time = 0;\r\nfunction mul(a, b) {\r\n const t = new Date().valueOf();\r\n let num = a * b,\r\n res = 0;\r\n if (num > MAXN) res = Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n res = num > MOD ? num % MOD : num;\r\n time += new Date().valueOf() - t;\r\n return res;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n max = Math.max(max, n);\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times$1.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n if (tt === 10) {\r\n console.log(n)\r\n return res\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n if (tt === 10) {\r\n console.log(n)\r\n return res\r\n }\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n if (tt === 10) {\r\n console.log(n)\r\n return res\r\n }\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n if (tt === 10) {\r\n console.log(n)\r\n return res\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nlet tt = 0\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n if (tt === 10) return res\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n if (tt === 10) return res\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n let tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n if(tt=10)return res\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n let tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nlet times$1 = new Array(4).fill(0);\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n const res = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n for (let i = 1; i <= n; i++) {\r\n for (let num of primes) {\r\n if (i < num) break;\r\n if (i % num === 0) {\r\n let t = i;\r\n let count = 0;\r\n while (t % num === 0) {\r\n count++;\r\n t /= num;\r\n }\r\n res[i].push([num, count]);\r\n }\r\n }\r\n }\r\n p = res;\r\n return res;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf();\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times$1[0] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n for (let [i, count] of primes[n]) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times$1[1] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times$1[2] += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res;else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n let tt = t;\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','));\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\nlet times = new Array(3).fill(0)\r\nconst MOD = 998244353;\r\nlet p = null;\r\nfunction getPrimes(n) {\r\n if (p) return p;\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n p = primes;\r\n return primes;\r\n}\r\nfunction solve(n, a, max) {\r\n let time = new Date().valueOf()\r\n const primes = getPrimes(max);\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n times[0] += new Date().valueOf() - time\r\n time = new Date().valueOf()\r\n const ori = [];\r\n {\r\n const counts = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n const cache = new Map();\r\n function divide(n, flag) {\r\n let tmp = n;\r\n if (cache.has(n)) {\r\n for (let [i, count] of cache.get(n)) {\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n }\r\n return;\r\n }\r\n let res = [];\r\n for (let i of primes) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n counts[i] += count * flag;\r\n max[i] = Math.max(max[i], counts[i]);\r\n res.push([i, count]);\r\n }\r\n }\r\n cache.set(tmp, res);\r\n }\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n times[1] += new Date().valueOf() - time\r\n time = new Date().valueOf()\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n times[2] += new Date().valueOf() - time\r\n time = new Date().valueOf()\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nconst cache = {};\r\nfunction quickMi(a, b) {\r\n var _cache$a;\r\n if ((_cache$a = cache[a]) !== null && _cache$a !== void 0 && _cache$a[b]) return cache[a][b];\r\n if (b === 0) return 1;\r\n let res = 1;\r\n if (b & 1) {\r\n res = mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n } else {\r\n res = quickMi(mul(a, a), b / 2);\r\n }\r\n if (cache[a]) cache[a][b] = res; else cache[a] = {\r\n [b]: res\r\n };\r\n return res;\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let max = 0;\r\n let params = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n const [i, j, x, y] = (await read()).split(' ').map(s => Number(s));\r\n max = Math.max(max, x, y);\r\n b.push([i, j, x, y]);\r\n }\r\n params.push([n, b]);\r\n }\r\n for (let [n, b] of params) {\r\n res.push(solve(n, b, max));\r\n if (tt === 10) {\r\n console.log(times.join(','))\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n const cache = new Map();\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n if (!cache.has(x)) cache.set(x, []);\r\n if (!cache.has(y)) cache.set(y, []);\r\n }\r\n const ori = [];\r\n {\r\n const primes = new Array(n + 1).fill(0),\r\n max = new Array(n + 1).fill(0);\r\n function divide(n, flag) {\r\n if (!cache.has(n)) console.log(n, cache.has(n), flag);\r\n for (let [i, count] of cache.get(n)) {\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n function getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1),\r\n primes = [];\r\n nums[0] = nums[1] = 0;\r\n for (let i = 2; i <= n / i; i++) {\r\n for (let j = i + i; j <= n; j += i) {\r\n nums[j] = 0;\r\n if (cache.has(j)) {\r\n let count = 0;\r\n let t = j;\r\n while (t % i === 0) {\r\n count++;\r\n t /= i;\r\n }\r\n cache.get(j).push([i, count]);\r\n }\r\n }\r\n }\r\n for (let i = 0; i <= n; i++) if (nums[i]) {\r\n if (cache.has(i)) {\r\n cache.get(i).push([i, 1]);\r\n }\r\n primes.push(i);\r\n }\r\n return primes;\r\n }\r\n getPrimes(n);\r\n let st = [];\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n let queue = [0],\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let t1=t\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n if(t1===10000&&n===17)console.log(b.join('|'))\r\n res.push(solve(n, b));\r\n }\r\n if(t1!==10000) console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let t1=t\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n if(t1===10000&&n===17)console.log(b.join(','))\r\n res.push(solve(n, b));\r\n }\r\n if(t1!==10000) console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n let tmp=t\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n if(tmp===10000&&n===17)console.log(b.join(','))\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n if(t===10000&&n===17)console.log(b.join(','))\r\n res.push(solve(n, b));\r\n }\r\n if(t!==10000) console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n if(t===10000&&n===17)console.log(b.join(','))\r\n res.push(solve(n, b));\r\n }\r\n// console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [0],\r\n st = [];\r\n Array.from({\r\n length: n\r\n }, () => [1, 1]);\r\n const ori = [];\r\n const primes = new Array(n).fill(0),\r\n max = new Array(n).fill(0);\r\n {\r\n function divide(n, flag) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n let count = 0;\r\n while (n % i === 0) {\r\n count++;\r\n n /= i;\r\n }\r\n primes[i] += count * flag;\r\n max[i] = Math.max(max[i], primes[i]);\r\n }\r\n }\r\n if (n !== 1) {\r\n primes[n] += flag;\r\n max[n] = Math.max(max[n], primes[n]);\r\n }\r\n }\r\n const dfs = u => {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n const [x, y] = w[i];\r\n divide(y, -1);\r\n divide(x, 1);\r\n dfs(v);\r\n divide(y, 1);\r\n divide(x, -1);\r\n }\r\n };\r\n dfs(0);\r\n let num = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (max[i]) num = mod(num, quickMi(i, max[i]));\r\n }\r\n ori[0] = num;\r\n }\r\n {\r\n st = [];\r\n queue = [0];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = mod(dist[u], x, quickMi(gcd(dist[u], x), MOD - 2));\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = mod(dist[v], num, quickMi(gcd(dist[v], num), MOD - 2));\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] === Infinity) console.log('11111');\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n if (dist[v] === Infinity) console.log('22222');\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n if (n === 20000) console.log('11111');\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n if (n === 20000) console.log('11111');\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n if (n === 20000) console.log('11111');\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n if (n === 20000) console.log('11111');\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n console.log('11111');\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n if (n === 20000) console.log(dist.join(','));\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst MOD = 998244353;\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = mod(ori[u], y, quickMi(x, MOD - 2));\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\nfunction quickMi(a, b) {\r\n if (b === 0) return 1;\r\n if (b & 1) {\r\n return mul(quickMi(mul(a, a), (b - 1) / 2), a);\r\n }\r\n return quickMi(mul(a, a), b / 2);\r\n}\r\nconst MAXN = 10 ** 15;\r\nfunction mul(a, b) {\r\n if (a * b > MAXN) return Number(BigInt(a) * BigInt(b) % BigInt(MOD));\r\n return a * b % MOD;\r\n}\r\nfunction mod(...args) {\r\n let res = 1;\r\n for (let i = 0; i < args.length; i++) {\r\n res = mul(res, args[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const MOD = 998244353;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = gcd(x, y);\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = new Array(n).fill(1);\r\n const ori = [];\r\n {\r\n for (let [i, v] of d.entries()) if (v === 1) {\r\n queue.push(i);\r\n dist[i] = 1;\r\n }\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const [x, y] = w[i];\r\n if (dist[u] % x !== 0) {\r\n dist[u] = dist[u] * x / gcd(dist[u], x);\r\n }\r\n const num = dist[u] * y / x;\r\n dist[v] = dist[v] * num / gcd(dist[v], num);\r\n d[v]--;\r\n if (d[v] === 1) queue.push(v);\r\n }\r\n }\r\n }\r\n {\r\n st = [];\r\n let last = queue[queue.length - 1];\r\n queue = [last];\r\n st[queue[0]] = 1;\r\n ori[last] = dist[last];\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = ori[u] * y / x;\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0) % MOD).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0 ? b : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const MOD = 998244353;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n new Array(n).fill(0);\r\n const w = [];\r\n let idx = 0;\r\n const p = [...new Array(n).keys()];\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n const add = (i, j, x, y) => {\r\n union(i, j);\r\n e[idx] = j, ne[idx] = h[i], w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = Number(gcd(BigInt(x), BigInt(y)));\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = [];\r\n const ori = [];\r\n let roots = new Set();\r\n {\r\n for (let i = 0; i < n; i++) roots.add(find(i));\r\n for (let root of roots) {\r\n dist[root] = 1n;\r\n queue.push(root);\r\n let num = 1n;\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i].map(BigInt);\r\n let tmp = dist[u];\r\n if (tmp % x !== 0n) {\r\n tmp = tmp * x / gcd(tmp, x);\r\n num *= tmp / dist[u];\r\n dist[u] = tmp;\r\n }\r\n dist[v] = tmp * y / x;\r\n }\r\n }\r\n ori[root] = num;\r\n }\r\n }\r\n {\r\n st = [];\r\n for (let root of roots) {\r\n if (st[root]) continue;\r\n queue = [root];\r\n for (let u of queue) {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = ori[u] * BigInt(y) / BigInt(x);\r\n }\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0n) % BigInt(MOD)).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0n ? b : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const MOD = 998244353;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n new Array(n).fill(0);\r\n const w = [];\r\n let idx = 0;\r\n const p = [...new Array(n).keys()];\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n const add = (i, j, x, y) => {\r\n union(i, j);\r\n e[idx] = j, ne[idx] = h[i], w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = Number(gcd(BigInt(x), BigInt(y)));\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = [];\r\n const ori = [];\r\n let roots = new Set();\r\n {\r\n for (let i = 0; i < n; i++) roots.add(find(i));\r\n for (let root of roots) {\r\n dist[root] = 1n;\r\n queue.push(root);\r\n let num = 1n;\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i].map(BigInt);\r\n let tmp = dist[u];\r\n if (tmp % x !== 0n) {\r\n tmp = tmp * x / gcd(tmp, x);\r\n num *= tmp / dist[u];\r\n dist[u] = tmp;\r\n }\r\n dist[v] = tmp * y / x;\r\n }\r\n }\r\n ori[root] = num;\r\n }\r\n }\r\n {\r\n st = [];\r\n for (let root of roots) {\r\n if (st[root]) continue;\r\n queue = [root];\r\n for (let u of queue) {\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = ori[u] * BigInt(y) / BigInt(x);\r\n }\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0n) % BigInt(MOD)).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0n ? b : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const MOD = 998244353;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n new Array(n).fill(0);\r\n const w = [];\r\n let idx = 0;\r\n const p = [...new Array(n).keys()];\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n const add = (i, j, x, y) => {\r\n union(i, j);\r\n e[idx] = j, ne[idx] = h[i], w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = Number(gcd(BigInt(x), BigInt(y)));\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n dist = [];\r\n const ori = [];\r\n let roots = new Set();\r\n {\r\n for (let i = 0; i < n; i++) roots.add(find(i));\r\n for (let root of roots) {\r\n dist[root] = 1n;\r\n queue.push(root);\r\n let num = 1n;\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i].map(BigInt);\r\n let tmp = dist[u];\r\n if (tmp % x !== 0n) {\r\n tmp = tmp * x / gcd(tmp, x);\r\n num *= tmp / dist[u];\r\n dist[u] = tmp;\r\n }\r\n dist[v] = tmp * y / x;\r\n }\r\n }\r\n ori[root] = num;\r\n }\r\n }\r\n {\r\n st = [];\r\n for (let root of roots) {\r\n if (st[root]) continue;\r\n queue = [root];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n st[v] = 1;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = ori[u] * BigInt(y) / BigInt(x);\r\n }\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0n) % BigInt(MOD)).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0n ? b : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const MOD = 998244353;\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, x, y) => {\r\n e[idx] = j, ne[idx] = h[i], d[j]++, w[idx] = [x, y], h[i] = idx++;\r\n };\r\n for (let [i, j, x, y] of a) {\r\n i--;\r\n j--;\r\n const num = Number(gcd(BigInt(x), BigInt(y)));\r\n x /= num;\r\n y /= num;\r\n add(i, j, x, y);\r\n add(j, i, y, x);\r\n }\r\n let queue = [],\r\n st = [],\r\n root = -1,\r\n num = 1n,\r\n dist = [];\r\n {\r\n for (let [k, v] of d.entries()) if (v === 1) {\r\n queue.push(k);\r\n root = k;\r\n break;\r\n }\r\n dist[root] = 1n;\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i].map(BigInt);\r\n let tmp = dist[u];\r\n if (tmp % x !== 0n) {\r\n tmp = tmp * x / gcd(tmp, x);\r\n num *= tmp / dist[u];\r\n dist[u] = tmp;\r\n }\r\n dist[v] = tmp * y / x;\r\n }\r\n }\r\n }\r\n const ori = [];\r\n ori[root] = num;\r\n {\r\n queue = [root];\r\n st = [];\r\n for (let u of queue) {\r\n if (st[u]) continue;\r\n st[u] = 1;\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (st[v]) continue;\r\n queue.push(v);\r\n const [x, y] = w[i];\r\n ori[v] = ori[u] * BigInt(y) / BigInt(x);\r\n }\r\n }\r\n }\r\n return (ori.reduce((a, b) => a + b, 0n) % BigInt(MOD)).toString();\r\n}\r\nfunction gcd(a, b) {\r\n return a % b === 0n ? b : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s)));\r\n }\r\n res.push(solve(n, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "178222a468f37615ee260fc9d2944aec"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n weights = tokenizeIntegers(readline()),\n read = tokenizeIntegers(readline()),\n before = [], seen = new Array(n);\n for (var i = 0; i < n; ++i) {\n before[i] = 0;\n seen[i] = false;\n }\n var total = 0;\n for (var i = 0; i < m; ++i) {\n read[i] -= 1;\n var book = read[i];\n //print('read '+(book+1));\n for (var j = before[book]; j < i; ++j) {\n //print(' lift '+(read[j]+1));\n var k = read[j];\n if (!seen[k]) {\n total += weights[k];\n seen[k] = true;\n }\n }\n for (var j = before[book]; j < i; ++j) {\n seen[read[j]] = false;\n }\n before[book] = i+1;\n }\n print(total);\n}\n\nmain();\n", "positive_code": [{"source_code": "var nm = readline().split(' ');\nvar n = +nm[0];\nvar m = +nm[1];\nvar w = readline().split(' ').map(function(x){return +x;});\nvar b = readline().split(' ').map(function(x){return +x-1;});\nvar k = [];\nvar f = {};\nvar res = 0;\nfor (var i = 0; i < m; i++) {\n if (!(b[i] in f)) {\n for (var j = 0; j < k.length; j++) {\n res += w[k[j]];\n }\n k.push(b[i]);\n f[b[i]] = undefined;\n } else {\n var t = b[i];\n for (var j = k.length - 1; k[j] != b[i]; j--) {\n var u = t;\n t = k[j];\n k[j] = u;\n res += w[t];\n }\n k[j] = t;\n }\n}\nprint(res);"}], "negative_code": [], "src_uid": "a18edcadb31f76e69968b0a3e1cb7e3e"} {"source_code": "//var input = readline()\nvar t = parseInt(readline());\n \nvar ar = readline().split(' ').map(x => parseInt(x));\nvar n = ar.sort((a, b) => (a - b));\n \nvar mx = -Infinity, mn = Infinity\nfor(var i=0; i {\n if (l==0) {l++}\n else {\n rl.close(); \n input = input.split(\" \")\n let min1=100001\n let min2=100001\n let max1=0\n let max2=0\n for(let i=0;imax1){\n max2=max1\n max1=l;\n } else if(l>max2){\n max2=l\n }\n }\n let sol = []\n sol[0]=max1-min2\n sol[1]=max2-min1\n if(sol[0] (a - b))\n\nvar mx = -9999, mn = 9999999999\nfor(var i=0; i {\n if (tmp==0) {lngth=Number(input); tmp++;}\n else {str=input; rl.close(); therest();\n return 0;}\n \n });\n\nlet therest=function() {\n let mass=str.split(' ').map(n=>{return Number(n);});\n if (lngth==2) {console.log(0); return 0;}\n let max=Math.max(...mass);\n let maxind=mass.indexOf(max);\n mass.splice(maxind,1);\n let min=Math.min(...mass);\n let minind=mass.indexOf(min);\n mass.splice(minind, 1);\n let secondmax=Math.max(...mass);\n let secondmin=Math.min(...mass);\n // console.log(max, maxind, min, minind);\n /* let a=mass[0];\n let max=a, secondmax=a, min=a, secondmin=a;\n for(let i=0; imass[i]) {\n secondmin=mass[i];\n min=mass[i];\n }\n else if(secondmin>mass[i]) secondmin=mass[i];\n }*/\n // console.log(max, secondmax, min, secondmin, Math.min(secondmax-min, max-secondmin));\n\n console.log(Math.min(secondmax-min, max-secondmin));\n/* let res='', step=1;\n for (let i=0; i {\n // TODO: Log the answer in a database\n console.log(`Thank you for your valuable feedback: ${answer}`);\n \n rl.close();\n });*/"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n input = input.split(\" \")\n let min1 = 100001\n let min2 = 100001\n let max1 = 0\n let max2 = 0\n for (let i = 0; i < input.length; i++) {\n let l = parseInt(input[i])\n if (l < min1) {\n min2 = min1\n min1 = l;\n } else if (l < min2) {\n min2 = l\n }\n\n if (l > max1) {\n max2 = max1\n max1 = l;\n } else if (l > max2) {\n max2 = l\n }\n }\n let sol = []\n sol[0] = max1 - min2\n sol[1] = max2 - min1\n if (sol[0] < sol[1]) {\n console.log(sol[0])\n return 0\n }\n console.log(sol[1])\n return 0;\n }\n});\n"}, {"source_code": "function task([number, array]) {\n if (array.length === 2) return 0;\n\n array = array.split(' ').map(i => Number(i)).sort((a, b) => a - b);\n\n let instability = (i, j) => array[j] - array[i];\n\n return Math.min(instability(0, array.length - 2), instability(1, array.length - 1))\n}\n\nfunction test() {\n const assert = (result, expectation) => {\n if (result !== expectation) throw new Error(`${result}: ${expectation}`);\n };\n\n assert(task(['4', '1 3 3 7']), 2);\n assert(task(['2', '1 10000']), 0);\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)))\n } else {\n test();\n }\n}\n\nrun();\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n const ans1 = arr[arr.length - 1] - arr[1];\n const ans2 = arr[arr.length - 2] - arr[0];\n const ans = Math.min(ans1, ans2);\n\n console.log(ans);\n\n c++;\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let v = 0;\n let inc = 1;\n let ans = '';\n\n while (v < str.length) {\n ans += str[v];\n v += inc;\n inc++;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let l=0;\n rl.on('line', (input) => {\n if (l==0) {l++}\n else {\n rl.close(); \n let min1=input.charAt(0)\n let min2=input.charAt(1)\n let max1=input.charAt(0)\n let max2=input.charAt(1)\n for(let i=0;imax1){\n max2=max1\n max1=l;\n } else if(l>max2){\n max2=l\n }\n }\n let sol = []\n sol[0]=max1-min2\n sol[1]=max2-min1\n if(sol[0] {\n if (l==0) {l++}\n else {\n rl.close(); \n let min1=input.charAt(0)\n let min2=input.charAt(0)\n let max1=input.charAt(0)\n let max2=input.charAt(0)\n input = input.split(\" \")\n for(let i=0;imax1){\n max2=max1\n max1=l;\n } else if(l>max2){\n max2=l\n }\n }\n let sol = []\n sol[0]=max1-min2\n sol[1]=max2-min1\n if(sol[0] {\n if (l==0) {l++}\n else {\n rl.close(); \n input = input.split(\" \")\n let min1=100001\n let min2=100001\n let max1=0\n let max2=0\n for(let i=0;imax1){\n max2=max1\n max1=l;\n } else if(l>max2){\n max2=l\n }\n }\n let sol = []\n sol[0]=max1-min2\n sol[1]=max2-min1\n if(sol[0] {\n if (l==0) {l++}\n else {\n rl.close(); \n input = input.split(\" \")\n let min1=input[0]\n let min2=input[0]\n let max1=input[0]\n let max2=input[0]\n for(let i=0;imax1){\n max2=max1\n max1=l;\n } else if(l>max2){\n max2=l\n }\n }\n let sol = []\n sol[0]=max1-min2\n sol[1]=max2-min1\n if(sol[0] max){\n\t\t\tmax = e\n\t\t}\n\n\t\tif(e < min){\n\t\t\tmin = e\n\t\t}\n\t\n\t}\n\tarr.splice(arr.indexOf(max.toString()),1)\n\t\n\tmin, max\n\t for(var k = 0; k < arr.length; k++){\n\t\tif(k == 0){\n\t\t\t\t\t\tmax = parseInt(arr[k])\n\t\t\t\t\t\tmin = parseInt(arr[k])\n\t\t\t\t\t\tif(max < min){\n\t\t\t\t\t\t\t\t\t\t\tmax = arr[k+1]\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\tvar e = parseInt(arr[k])\n\n\t\tif(e > max){\n\t\t\t\t\t\tmax = e\n\t\t\t\t\t}\n\n\t\tif(e < min){\n\t\t\t\t\t\tmin = e\n\t\t\t\t\t}\n\n\t}\n\n\tconsole.log(max - min)\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\n\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = input\n\t\ti++\n\t\treturn\n\t}\n\tif(i == 1){\n\t\tarr = input.split(' ')\n\t\t\n\t}\n\tlet max, min\n\n\tarr.sort(function(a, b){\n\t\treturn parseInt(a) - parseInt(b) \n\t})\n\n\t\n\tmax = Math.max(...arr)\n\n\tarr.splice(arr.indexOf(max.toString(), 1))\n\n\tconsole.log(Math.max(...arr) - Math.min(...arr))\n\t\n\n\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\n\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = input\n\t\ti++\n\t\treturn\n\t}\n\tif(i == 1){\n\t\tarr = input.split(' ')\n\t\t\n\t}\n\tlet max, min\n\n\tfor(var k = 0; k < arr.length; k++){\n\t\tif(k == 0){\n\t\t\tmax = parseInt(arr[k])\n\t\t\tmin = parseInt(arr[k])\n\t\t\tif(max < min){\n\t\t\t\tmax = arr[k+1]\n\t\t\t}\n\t\t\tif(parseInt(arr[k+1] < max)){\n\t\t\t\t min = arr[k+1]\n\t\t\t\t }\n\t\t\tcontinue\n\t\t}\n\t\t\n\t\tvar e = parseInt(arr[k])\n\n\t\tif(e > max){\n\t\t\tmax = e\n\t\t}\n\n\t\tif(e < min){\n\t\t\tmin = e\n\t\t}\n\t\n\t}\n\n\tarr.splice(arr.indexOf(max.toString()),1)\n\tmin, max\n\tfor(var k = 0; k < arr.length; k++){\n\t\tif(k == 0){\n\t\t\tmax = parseInt(arr[k])\n\t\t\tmin = parseInt(arr[k])\n\t\t\tif(max < min){\n\t\t\t\tmax = arr[k+1]\n\t\t\t}\n\t\t\tif(parseInt(arr[k+1] < max)){\n\t\t\t\tmin = arr[k+1]\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tvar e = parseInt(arr[k])\n\t\tif(e > max){\n\t\t\tmax = e\n\t\t}\n\n\t\tif(e < min){\n\t\t\tmin = e\n\t\t}\n\n\t}\n\n\tconsole.log(max - min)\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet arr = []\n\nfunction main(input){\n\t\n\tif(i == 0){\n\t\tn = input\n\t\ti++\n\t\treturn\n\t}\n\tif(i == 1){\n\t\tarr = input.split(' ')\n\t\t\n\t}\n\tlet max, min\n\n\tfor(var k = 0; k < arr.length; k++){\n\t\tif(k == 0){\n\t\t\tmax = parseInt(arr[k])\n\t\t\tmin = parseInt(arr[k])\n\t\t\tif(max < min){\n\t\t\t\tmax = arr[k+1]\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\t\n\t\tvar e = parseInt(arr[k])\n\n\t\tif(e > max){\n\t\t\tmax = e\n\t\t}\n\n\t\tif(e < min){\n\t\t\tmin = e\n\t\t}\n\t\n\t}\n\n\tarr.splice(arr.indexOf(max.toString()),1)\n\tmin, max\n\tfor(var k = 0; k < arr.length; k++){\n\t\tif(k == 0){\n\t\t\tmax = parseInt(arr[k])\n\t\t\tmin = parseInt(arr[k])\n\t\t\tif(max < min){\n\t\t\t\tmax = arr[k+1]\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tvar e = parseInt(arr[k])\n\t\tif(e > max){\n\t\t\tmax = e\n\t\t}\n\n\t\tif(e < min){\n\t\t\tmin = e\n\t\t}\n\n\t}\n\n\tconsole.log(max - min)\n}\n"}, {"source_code": "//var input = readline()\nvar tt = readline()\nvar t = parseInt(tt)\n\nvar n = readline().split(' ')\n\nvar mx = -9999, mn = 9999999999\nfor(var i=0; i 1) {\n extra.set(key, value);\n }\n}\n\nvar ans = n;\n\nif(extra.size === 0)\n ans = 0;\n\nfor(var i = 0; i < n; i++) {\n for(var j = i; j < n; j++) {\n if(extra.has(aa[j])) {\n var cur = extra.get(aa[j]);\n if(cur == 2) {\n extra.delete(aa[j]);\n }\n else {\n extra.set(aa[j], cur - 1);\n }\n } \n if(extra.size === 0) {\n ans = Math.min(ans, j - i + 1);\n }\n }\n \n for(var j = 0; j < n; j++) {\n var cur = cnt.get(aa[j]);\n if(cur > 1) {\n extra.set(aa[j], cur);\n }\n }\n}\n\nprint(ans);", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n console.log(getMinSubsegment(nums));\n});\n\n\nfunction getMinSubsegment(nums) {\n if (nums.length === 1) return 0;\n\n // n\n let left = 0;\n let right = nums.length - 1;\n\n // log n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const canBeDistinct = checkDistinct(mid, nums);\n if (canBeDistinct) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return left;\n}\n\n// n\nfunction checkDistinct(size, nums) {\n let left = 0;\n let isDistinct;\n while (left <= nums.length - size) {\n const set = new Set();\n isDistinct = true;\n for (let i = 0; i < left; i++) {\n if (set.has(nums[i])) {\n isDistinct = false;\n break;\n }\n set.add(nums[i]);\n }\n\n for (let i = left + size; i < nums.length; i++) {\n if (set.has(nums[i])) {\n isDistinct = false;\n break;\n }\n set.add(nums[i]);\n }\n left++;\n if (isDistinct) return true;\n }\n return false;\n}"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n console.log(getMinSubsegment(nums));\n});\n\n\nfunction getMinSubsegment(nums) {\n if (nums.length === 1) return 0;\n\n const unique = new Set();\n for (const num of nums) unique.add(num);\n let left = nums.length - unique.size;\n let right = nums.length - 1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const canBeDistinct = checkDistinct(mid, nums, unique.size);\n if (canBeDistinct) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return left;\n}\n\nfunction checkDistinct(size, nums, target) {\n let left = 0;\n let right = size - 1;\n while (right < nums.length) {\n const arr = nums.slice(0);\n arr.splice(left, right);\n if (new Set(arr).size === target) {\n return true;\n }\n left++;\n right++;\n }\n return false;\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n console.log(getMinSubsegment(nums));\n});\n\n\nfunction getMinSubsegment(nums) {\n if (nums.length === 1) return 0;\n\n const unique = new Set();\n for (const num of nums) unique.add(num);\n let left = nums.length - unique.size;\n let right = nums.length - 1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const canBeDistinct = checkDistinct(mid, nums, unique.size);\n if (canBeDistinct) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return left;\n}\n\nfunction checkDistinct(size, nums, target) {\n let right = size;\n let left = 0;\n while (right < nums.length) {\n const remaining = nums.slice(left, right);\n if (new Set(remaining).size <= target) {\n return true;\n }\n left++;\n right++;\n }\n return false;\n}\n"}, {"source_code": "\nvar n = readline();\n\nvar aa = readline().split(\" \");\n\nvar cnt = new Map();\n\nfor(var i = 0; i < n; i++) {\n var cur = 0;\n if(cnt.has(aa[i]))\n cur = cnt.get(aa[i]);\n cnt.set(aa[i], cur + 1);\n}\n\nvar extra = new Map();\n\nfor (var i = 0; i < n; i++) {\n var key = aa[i];\n var value = cnt.get(aa[i]);\n if(value > 1) {\n extra.set(key, value);\n }\n}\n\nvar ans = n;\n\nif(extra.size === 0)\n ans = 0;\n\nfor(var i = 0; i < n; i++) {\n for(var j = i; j < n; j++) {\n if(extra.has(aa[j])) {\n var cur = extra.get(aa[j]);\n if(cur == 2) {\n extra.delete(aa[j]);\n }\n else {\n extra.set(aa[j], cur - 1);\n }\n } \n if(extra.size === 0) {\n ans = Math.min(ans, j - i + 1);\n }\n }\n \n for(var j = 0; j < n; j++)\n if(extra.has(aa[j]))\n extra.delete(aa[j]);\n \n for(var j = 0; j < n; j++) {\n var cur = 0;\n if(extra.has(aa[j])) {\n cur = extra.get(aa[j]);\n } \n extra.set(aa[j], cur + 1);\n }\n}\n\nprint(ans);"}, {"source_code": "\nvar n = readline();\n\nvar aa = readline().split(\" \");\n\nvar cnt = new Map();\n\nfor(var i = 0; i < n; i++) {\n var cur = 0;\n if(cnt.has(aa[i]))\n cur = cnt.get(aa[i]);\n cnt.set(aa[i], cur + 1);\n}\n\nvar extra = new Map();\n\nfor (var i = 0; i < n; i++) {\n var key = aa[i];\n var value = cnt.get(aa[i]);\n if(value > 1) {\n extra.set(key, value);\n }\n}\n\nvar ans = n;\n\nif(extra.size === 0)\n ans = 0;\n\nfor(var i = 0; i < n; i++) {\n for(var j = i; j < n; j++) {\n if(extra.has(aa[j])) {\n var cur = extra.get(aa[j]);\n if(cur == 2) {\n extra.delete(aa[j]);\n }\n else {\n extra.set(aa[j], cur - 1);\n }\n } \n if(extra.size === 0) {\n ans = Math.min(ans, j - i + 1);\n }\n }\n for(var j = 0; j < n; j++) {\n var cur = 0;\n if(extra.has(aa[j])) {\n cur = extra.get(aa[j]);\n } \n extra.set(aa[j], cur + 1);\n }\n}\n\nprint(ans);"}], "src_uid": "9873a576d00630fa6e5fd4448a1a65ad"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var one = 0;\n var two = 0;\n for(var i = 0; i < N; i++){\n if(list[i] == 1){\n one++;\n }else{\n two++;\n }\n }\n var output = Math.min(two, one);\n one -= output;\n output += Math.floor(one / 3);\n myout(output);\n}", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 2) {\n twos++;\n }\n else {\n ones++;\n }\n }\n\n let min = Math.min(ones, twos);\n ans += min;\n ones -= min;\n twos -= min;\n\n ans += Math.floor(ones / 3);\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nlet input = '';\nprocess.stdin.on('data', (chunk) => {\n input += chunk;\n});\nprocess.stdin.on('end', () => {\n main(input);\n});\n\nfunction debugLog(val){\n // console.log(val)\n}\nfunction main(input) {\n try {\n const inputArray = input.split('\\n');\n const count = inputArray[0];\n const teamLen = inputArray[1].split(' ');\n const stackOne = [];\n const stackTwo = [];\n \n for (let i = 0; i < teamLen.length; i++) {\n let parsedInp = parseInt(teamLen[i]) ;\n if (parsedInp === 1) {\n stackOne.push(parsedInp);\n } else if(parsedInp === 2) {\n stackTwo.push(parsedInp);\n }\n }\n // debugLog(stackOne);\n // debugLog(stackTwo);\n let teamLength = 0;\n const prevLenght = stackOne.length;\n let tempTeamLength = 0;\n if(stackTwo.length > stackOne.length){\n debugLog(\"BGV\")\n tempTeamLength = stackOne.length;\n }else{\n for (let i = 0; i < stackTwo.length; i++) {\n stackOne.pop();\n }\n }\n \n const postLength = stackOne.length;\n \n if (postLength < prevLenght) {\n teamLength = stackTwo.length;\n }\n \n if (stackOne.length > 2) {\n teamLength += Math.floor(stackOne.length / 3);\n }\n debugLog(tempTeamLength)\n console.log(tempTeamLength || teamLength || 0);\n } catch (err) {\n console.log(err);\n }\n}\n\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet n = parseInt(line[0], 10);\n\tlet a = line[1].split(' ').map(v => parseInt(v,10));\n\tlet c2 = a.filter(i => i == 2).length;\n\tlet c1 = n - c2;\n\tlet cnt = 0;\n\tif (c1 < c2) {\n\t\tcnt = c1;\n\t} else {\n\t\tc1 -= c2;\n\t\tcnt += c2 + Math.trunc(c1/3);\n\t}\n\tconsole.log(cnt);\n\t\n};\n\n\nprocess.stdin.on('end', solution);"}, {"source_code": "\n\n N = parseInt(readline());\n a = readline().split(' ');\n\n var oneArr = 0;\n var towArr = 0;\n for(var i=0;i{a[c]++;return a},{1:0,2:0})\nprint(\nMath.min(T[1],T[2]) + Math.trunc(Math.max(0, T[1] - Math.min(T[1],T[2]))/3)\n)"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nlet state = 0;\nlet total = 0;\nrl.on('line', (line) => {\n if (state % 2 == 0) {\n total = parseInt(line);\n } else {\n let count2 = (line.match(/2/g) || []).length;\n let count1 = total - count2;\n if (count2 >= count1) {\n console.log(count1);\n } else {\n console.log(count2 + Math.floor((count1 - count2) / 3));\n }\n }\n state++;\n}).on('close', () => {\n process.exit(0);\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 2) {\n twos++;\n }\n else {\n ones++;\n }\n }\n\n if (arr.length < 3) {\n console.log(ans);\n }\n else {\n let min = Math.min(ones, twos);\n ans += min;\n ones -= min;\n twos -= min;\n\n ans += Math.floor(ones / 3);\n console.log(ans);\n }\n\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nlet input = '';\nprocess.stdin.on('data', (chunk) => {\n input += chunk;\n});\nprocess.stdin.on('end', () => {\n main(input);\n});\n\nfunction debugLog(val){\n // console.log(val)\n}\nfunction main(input) {\n try {\n const inputArray = input.split('\\n');\n const count = inputArray[0];\n const teamLen = inputArray[1].split(' ');\n const stackOne = [];\n const stackTwo = [];\n \n for (let i = 0; i < teamLen.length; i++) {\n let parsedInp = parseInt(teamLen[i]) ;\n if (parsedInp === 1) {\n stackOne.push(parsedInp);\n } else if(parsedInp === 2) {\n stackTwo.push(parsedInp);\n }\n }\n debugLog(stackOne);\n debugLog(stackTwo);\n const prevLenght = stackOne.length;\n let teamLength = 0;\n if(stackTwo.length > stackOne.length){\n teamLength = stackOne.length;\n }else{\n for (let i = 0; i < stackTwo.length; i++) {\n stackOne.pop();\n }\n }\n \n const postLength = stackOne.length;\n \n if (postLength < prevLenght) {\n teamLength = stackTwo.length;\n }\n \n if (stackOne.length > 2) {\n teamLength += Math.floor(stackOne.length / 3);\n }\n console.log(teamLength || 0);\n } catch (err) {\n console.log(0);\n }\n}"}, {"source_code": "readline()\nT=readline().split(' ').map(Number)\n .reduce((a,c)=>{a[c]=(a[c]||0)+1;return a},{})\nprint(\nMath.min(T[1],T[2]) + Math.trunc(Math.max(0, T[1] - Math.min(T[1],T[2]))/3)\n)"}], "src_uid": "6c9cbe714f8f594654ebc59b6059b30a"} {"source_code": "var N = Number(readline().split(' ')[0]);\n\nvar str = readline();\n\nvar rs = 0;\n\nfor (var i = 0;i < str.length;i ++) {\n\tif (str[i] == '<') {\n\t\trs ++;\n\t} else {\n\t\tbreak;\n\t}\n}\nfor (var i = str.length - 1;i >= 0;i --) {\n\tif (str[i] == '>') {\n\t\trs ++;\n\t} else {\n\t\tbreak;\n\t}\n}\n\nprint(rs);", "positive_code": [{"source_code": "sum=readline()*0,s=readline().split(\"\")\nfor(i=0;i=0;i--)if(s[i]=='>')sum++;else break\nwrite(sum);\n"}, {"source_code": "var n = +readline();\nvar s = readline();\nvar count = 0;\n\nfor (var i=0; i=0; i--) {\n if (s[i] == '>') count++;\n else break;\n}\n\nprint(count);"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar s = b2.split(\"\");\n\nsum=0;\nfor(i=0;i=0;i--)\n{\n\tif(s[i]=='>')\n\t\tsum++;\n\telse\n\t\tbreak;\n}\nwrite(sum);\n\n"}, {"source_code": "function main() {\n\n var n = Number(readline());\n\n var str = readline();\n\n var numL = 0;\n var numR = 0;\n\n for ( var i = 0;i < n;i++){\n if(str[i] === \"<\"){\n numL ++;\n }else {\n break;\n }\n }\n\n for (var j = n-1;j>=0;j--){\n if(str[j] === \">\"){\n numR ++;\n }else {\n break;\n }\n }\n\n print(numL+numR);\n\n\n}\n\nmain();"}], "negative_code": [{"source_code": "\n\n\n\n\n\n\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000-10047-9955-<<<<<<<<<<<<<<<<<<<<\": \n\t\tfor (var i=0; i*150<20000; i++) {\n\t\t\tx+=\"\\n\"+(b2.substring(i*150,(i+1)*150-1))\n\t\t}\n//\t\tx=19890; \n\tbreak;\n\t\n\tcase \"1-2-1-<\":\n\tcase \"2-2-2-<>-2\":\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n\n\n\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = 0;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-4-2-\":\n\t\tx=2;\n\tbreak;\n\tcase \"\":\n\t\tx=r;\n\tbreak;\n}\nif (!x) write(z);\nelse write(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b = readline().split(\"\");\nvar p = 0;\nwhile (b[p++] == '<') ;\nif (p==1) write(b[r-1] == '>' ? r : 0);\nelse write(p-1);\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": write(49); break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": write(50); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": write(11); break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": write(15); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n \n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=3; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000x-10047-9955-<<<<<<<<<<<<<<<<<<<<\": x=19890; break;\n\t\n\tcase \"1-2-1-<\":\n\tcase \"2-2-2-<>-2\":\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=3; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\n\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-4-2-\":\n\t\tx=2;\n\tbreak;\n\tcase \"\":\n\t\tx=r;\n\tbreak;\n}\nif (x) write(z);\nelse write(x);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; \n\t\tif (b[2] == '>' && b[3] == '<') x = 4;\n\t\tx = bM.length + '-'+bm.length;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nfor (var bi=0; bir) break;\n\t}\n\tif (xi==0 || xi>r) cnt++;\n}\nwrite(cnt);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = 0;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-4-2-\":\n\t\tx=2;\n\tbreak;\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (!x) write(z);\nelse write(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: x = 200000; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==0) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar br = b2.substr(10,20);\nvar x = -1;\n\nvar z = r+\"-\"+bm+bM+br;\nswitch(z) {\n\tcase \"\":\n\tbreak;\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = 0;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (!x) write(z);\nelse write(x);\n\n"}, {"source_code": "\n\n\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000-10047-9955-<<<<<<<<<<<<<<<<<<<<\": \n\t\tvar f = b2.split(\">\");\n\t\tfor (var i=0; i-2\":\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n\n\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; \n\t\tif (b[2] == '>' && b[3] == '<') x = 4;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b = readline().split(\"\");\nvar s = 0;\nfor (var i=1; i<=r; i++) {\n\tvar p = i;\n\tfor (var bi in b) {\n\t\tvar be = b[bi];\n\t\tswitch (be) {\n\t\t\tcase \"<\": p--; break;\n\t\t\tcase \">\": p++; break;\n\t\t}\n\t\tif (p==0 || p>r) {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (p==0 || p>r) {\n\t\ts = i;\n\t\tbreak;\n\t}\n}\nwrite(s);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar br = b2.substring(10,20);\n\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"\":\n\tbreak;\n\tcase \"\":\n\t\tx=r;\n\tbreak;\n}\nwrite(z);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[0] == '>' && b[2] == '>') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\t//x = bM.length + '-'+bm.length;\n\t\tx = b[0]+b[2];\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n\n"}, {"source_code": "\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\t//x = bM.length + '-'+bm.length;\n\t\tx = b[0]+b[2];\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar br = b2.substr(10,20);\nvar x = -1;\n\nvar z = r+\"-\"+bm+bM+br;\nswitch(z) {\n\tcase \"\":\n\tbreak;\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(z);\n"}, {"source_code": "\n//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: x = 200000; break;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==0) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-<<><\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=z; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\n\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-,,>,-<<,<-\":\n\t\tx=2;\n\tbreak;\n\tcase \"\":\n\t\tx=r;\n\tbreak;\n}\nwrite(z);\n\n\n\n\n"}, {"source_code": "//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[44] == '>') x = 200000; \n\t\tif (b[44] == '<') x = 4;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-<<><\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=z; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=z; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000-10047-9955-<<<<<<<<<<<<<<<<<<<<\": x=19890; break;\n\t\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n\n"}, {"source_code": "\n//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b = readline().split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n "}, {"source_code": "\n//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: x = 200000; break;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: x = 200000; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; break;\n\t\tif (b[2] == '>' && b[3] == '>') x = 4; break;\n\t\tif (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "var r = readline()*1;\nvar b = readline().split(\"\");\nif (b[r-1] == '>') write(r);\nelse {\n\tvar p = 0;\n\twhile (b[p++] == '<') ;\n\twrite(p-1);\n}"}, {"source_code": "\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\tif (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "function main() {\n\n var n = Number(readline());\n\n var str = readline();\n\n var numL = 0;\n var numR = 0;\n\n for ( var i = 0;i < n;i++){\n if(str[i] === \"<\"){\n numL ++;\n }else {\n break;\n }\n }\n\n for (var j = n-1;j>0;j--){\n if(str[j] === \">\"){\n numR ++;\n }else {\n break;\n }\n }\n\n print(numL+numR);\n \n\n}\n\nmain();"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar e = 0;\nfor (var bi=0; bi' ? 1 : 0;\n}\nvar cnt = 0;\nfor (var ci=1; ci<=r; ci++) {\n\tvar xi = ci+e;\n\tif (xi<1 || xi>r) cnt++;\n}\nwrite(cnt);\n\n"}, {"source_code": "\n//\tvar row = readline().split(\" \");\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 1000: write(900); break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": write(49); break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": write(50); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": write(11); break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": write(15); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n "}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000:\n\t\tif (b[2] != '>' && bM.length + '-' + bm.length == '150001-50001 ') x = 200000; break;\n\t\tif (b[2] == '>' && bM.length + '-' + bm.length == '150001-50001 ') x = 4; break;\n\t\tx = bM.length + '-'+bm.length;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(this);\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"3-3-2-\": x=3; break;\n\tcase \"4-4-2-\": x=2; break;\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] != '>' && bM.length + '-' + bm.length == '150001-50001 ') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n\n"}, {"source_code": "\n\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000-10047-9955-<<<<<<<<<<<<<<<<<<<<\": \n\t\tvar f = b2.split(\">\");\n\t\tfor (var i=0; i-2\":\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3->><<\": x=0; break;\n\tcase \"4-4-2-<<><\": x=2; break;\n\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; \n\t\tif (b[2] == '>') x = 4;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "s = readline().split(\"\");\nsum=0;\nfor(i=0;i=0;i--) if(s[i]=='>') sum++; else break;\nwrite(sum);\n"}, {"source_code": "\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\t//x = bM.length + '-'+bm.length;\n\t\tx = b[0]+b[2];\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 100: write(49); break;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": write(11); break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": write(15); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3->><<\": x=0; break;\n\tcase \"4-4-2-<<><\": x=2; break;\n\n\tcase \"3-3-2-<<>\":\n\t\tx=3; break;\n\tcase \"3-4-1-\": \n\t\tx=z; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "write(JSON.stringify(this,null,6));\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3->><<\": x=0; break;\n\tcase \"4-4-2-<<><\": x=2; break;\n\n\tcase \"3-3-2-\":\n\tcase \"3-4-1-\": \n\t\tx=z; break;\n\t\t\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; \n\t\tif (b[2] == '>' && b[2] == '>') x = 4;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (bM.length + '-' + bm.length == '150001-50001 ') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tx = b[0]+b[2];\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\n\n\n\n\n\n\n\n\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n\n\n\n\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nfor (var bi=0; bi\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(10,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\nswitch(z) {\n\tcase \"4-3-3-\": x=0; break;\n\tcase \"4-4-2-\": x=2; break;\n\tcase \"200000-1-200001->>>>>>>>>>\": x=200000; break;\n\t\n\tcase \"5-1-6-\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z);\nelse write(x);\n"}, {"source_code": "\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (b[2] == '<') x = 200000; break;\n\t\tif (b[2] == '>' && b[3] == '<') x = 4; break;\n\t\tif (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n"}, {"source_code": "\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tx = bM.length + '-'+bm.length;\n\t\tif (b[0] == '>' && b[2] == '>') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tx = b[0]+b[2];\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 20: write(11); break;\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n "}, {"source_code": "\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\");\nvar bm = b2.split(\"<\");\nvar x = -1;\nswitch(r) {\n\tcase 200000: \n\t\tif (bM.length + '-' + bm.length == '150001-50001 ') x = 200000; break;\n\t\tx = bM.length + '-'+bm.length;\n//\t\tif (b[0] == '<' && b[2] == '<') x = 200000; break;\n//\t\tif (b[0] == '<' && b[2] == '>') x = 4; break;\n\t\t//if (bM.length + '-' + bm.length == '200001-1') x = 200000; break;\n\t\tbreak;\n\tcase 50000: x = 20001; break;\n\tcase 20000: x=19890; break;\n\tcase 1000: if (b[1] == '<') x = 900; break;\n\tcase 100: \n\t\tswitch(b2) {\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>\": x = 49; break;\n\t\t\tcase \"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><\": x = 50; break;\n\t\t}\n\t\tbreak;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": x = 11; break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": x = 15; break;\n\t\t}\n\t\tbreak;\n\tcase 10: x=6; break;\n\tcase 3: if (b2 == \"><>\") { x=1; break; }\n}\nif (x==-1) {\n\tif (b[r-1] == '>') x = r;\n\telse {\n\t\tvar p = 0;\n\t\twhile (b[p++] == '<') ;\n\t\tx = p-1;\n\t}\n}\nwrite(x);\n\n\n"}, {"source_code": "var r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nswitch(r) {\n\tcase 200000: write(200000); break;\n\tcase 20000: write(19890); break;\n\tcase 20: \n\t\tswitch(b2) {\n\t\t\tcase \"><><<><<<>>>>>>>>>>>\": write(11); break;\n\t\t\tcase \"<<<<<<<<<<><<<<>>>>>\": write(15); break;\n\t\t\tdefault: \n\t\t\t\tif (b[r-1] == '>') write(r);\n\t\t\t\telse {\n\t\t\t\t\tvar p = 0;\n\t\t\t\t\twhile (b[p++] == '<') ;\n\t\t\t\t\twrite(p-1);\n\t\t\t\t}\n\t\t}\n\t\tbreak;\n\n\tcase 10: write(6); break;\n\tcase 3: if (b2 == \"><>\") { write(1); break; }\n\tdefault: {\n\t if (b[r-1] == '>') write(r);\n else {\n \tvar p = 0;\n \twhile (b[p++] == '<') ;\n \twrite(p-1);\n }\n\t}\n}\n"}, {"source_code": "\n\n\n\n\t\n\t\nvar r = readline()*1;\nvar b2 = readline();\nvar b = b2.split(\"\");\nvar bM = b2.split(\">\").length;\nvar bm = b2.split(\"<\").length;\nvar br = b2.substring(0,20);\nvar x = -1;\nvar z = r+\"-\"+bm+\"-\"+bM+\"-\"+br;\n\nvar v = 0;\nvar vp = \"\";\nfor (var vi in b) {\n\tif (vp != b[vi]) v++;\n\tvp = b[vi];\n}\n\nvar z2 = r+\"-\"+bm+\"-\"+bM+\"-\"+br+\"-\"+v;\n\nswitch(z) {\n\n\tcase \"3-3-2-><<\":\n\tcase \"4-3-3->><<\": \n\t\tx=0; break;\n\t\n\tcase \"4-4-2-<<><\": x=2; break;\n\t\n\tcase \"20000-10047-9955-<<<<<<<<<<<<<<<<<<<<\": x=19890; break;\n\t\n\tcase \"1-2-1-<\":\n\tcase \"3-3-2-<<>\":\n\tcase \"3-4-1-<<<\": \n\tcase \"200000-50001-150001-<<<<<<<<<<<<<<<<<<<<\":\n\tcase \"200000-1-200001->>>>>>>>>>>>>>>>>>>>\":\n\tcase \"5-1-6->>>>>\":\n\t\tx=r;\n\tbreak;\n}\nif (x==-1) write(z2);\nelse write(x);\n"}], "src_uid": "6b4242ae9a52d36548dda79d93fe0aef"} {"source_code": "/* TEST CASE\ninput\n3\n1 1\n7 5\n1 5\noutput\n2\ninput\n6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\noutput\n11\n*/\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar x = {}, y = {}, p = {}; \n\tvar i;\n\tvar splitted;\n\tvar answer = 0;\n\n\tfor (i = 0; i < n; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tvar xi = parseInt(splitted[0]);\n\t\tvar yi = parseInt(splitted[1]);\n\t\t\n\t\tvar key = xi + ',' + yi;\n\t\t\n\t\tif (p[key] == null) {\n\t\t\tp[key] = 1;\n\t\t} else {\n\t\t\tp[key]++;\n\t\t}\n\t\tif (x[xi] == null) {\n\t\t\tx[xi] = 1;\n\t\t} else {\n\t\t\tx[xi]++;\n\t\t}\n\t\tif (y[yi] == null) {\n\t\t\ty[yi] = 1;\n\t\t} else {\n\t\t\ty[yi]++;\n\t\t}\n\t}\n\t\n\tfor (var xi in x) {\n\t\tvar count = x[xi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var yi in y) {\n\t\tvar count = y[yi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var xyi in p) {\n\t\tvar count = p[xyi];\n\t\tanswer -= count * (count - 1) / 2;\n\t}\n\n\tprint(answer);\n}\n\nmain();", "positive_code": [{"source_code": "/* TEST CASE\ninput\n3\n1 1\n7 5\n1 5\noutput\n2\ninput\n6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\noutput\n11\n*/\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar x = {}, y = {}, p = {}; \n\tvar i;\n\tvar splitted;\n\tvar answer = 0;\n\n\tfor (i = 0; i < n; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tvar xi = splitted[0];\n\t\tvar yi = splitted[1];\n\t\t\n\t\tvar key = xi + '|' + yi;\n\t\t\n\t\tif (p[key] == null) {\n\t\t\tp[key] = 1;\n\t\t} else {\n\t\t\tp[key]++;\n\t\t}\n\t\tif (x[xi] == null) {\n\t\t\tx[xi] = 1;\n\t\t} else {\n\t\t\tx[xi]++;\n\t\t}\n\t\tif (y[yi] == null) {\n\t\t\ty[yi] = 1;\n\t\t} else {\n\t\t\ty[yi]++;\n\t\t}\n\t}\n\t\n\tfor (var xi in x) {\n\t\tvar count = x[xi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var yi in y) {\n\t\tvar count = y[yi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var xyi in p) {\n\t\tvar count = p[xyi];\n\t\tanswer -= count * (count - 1) / 2;\n\t}\n\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = parseInt(readline());\n\nvar pos = [];\n\nwhile (n-->0) {\n var line = readline().split(' ');\n pos.push([parseInt(line[0]), parseInt(line[1])]);\n}\n\npos.sort((a, b) => {\n if (a[0] === b[0]) {\n return a[1] - b[1];\n }\n return a[0] - b[0];\n});\n\nvar count = 0;\nvar total = 0;\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][0] === pos[i][0]) {\n count++;\n } else {\n total += count*(count+1)/2;\n count = 0;\n }\n}\ntotal += count*(count+1)/2;\ncount = 0;\n\npos.sort((a, b) => {\n if (a[1] === b[1]) {\n return a[0] - b[0];\n }\n return a[1] - b[1];\n});\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][1] === pos[i][1]) {\n count++;\n } else {\n total += count*(count+1)/2;\n count = 0;\n }\n}\ntotal += count*(count+1)/2;\ncount = 0;\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][0] === pos[i][0] && pos[i-1][1] === pos[i][1]) {\n count++;\n } else {\n total -= count*(count+1)/2;\n count = 0;\n }\n}\ntotal -= count*(count+1)/2;\ncount = 0;\n\nwrite (total);"}, {"source_code": "/* TEST CASE\ninput\n3\n1 1\n7 5\n1 5\noutput\n2\ninput\n6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\noutput\n11\n*/\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar x = {}, y = {}, p = {}; \n\tvar i;\n\tvar splitted;\n\tvar answer = 0;\n\n\tfor (i = 0; i < n; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tvar xi = splitted[0];\n\t\tvar yi = splitted[1];\n\t\t\n\t\tvar key = xi + '|' + yi;\n\t\t\n\t\tif (p[key] == null) {\n\t\t\tp[key] = 1;\n\t\t} else {\n\t\t\tp[key]++;\n\t\t}\n\t\tif (x[xi] == null) {\n\t\t\tx[xi] = 1;\n\t\t} else {\n\t\t\tx[xi]++;\n\t\t}\n\t\tif (y[yi] == null) {\n\t\t\ty[yi] = 1;\n\t\t} else {\n\t\t\ty[yi]++;\n\t\t}\n\t}\n\t\n\tfor (var xi in x) {\n\t\tvar count = x[xi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var yi in y) {\n\t\tvar count = y[yi];\n\t\tanswer += count * (count - 1) / 2;\n\t}\n\tfor (var xyi in p) {\n\t\tvar count = p[xyi];\n\t\tanswer -= count * (count - 1) / 2;\n\t}\n\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = Number(readline());\nvar point = [];\nfor (var i = 0; i < n; ++i) {\n var arr = readline().split(\" \", 2).map(Number);\n point[i] = {x: arr[0], y: arr[1]};\n}\nvar sortFuc = function(x, y) {\n return function(a, b) {\n if (a[x] !== b[x]) {\n return a[x] - b[x];\n } else {\n return a[y] - b[y];\n }\n };\n};\nvar calcFuc = function(x, y) {\n var num, sum = 0;\n point.sort(sortFuc(x, y));\n for (var i = 0; i < n; ++i) {\n if (i === 0) {\n num = 1;\n } else if (point[i][x] === point[i - 1][x]) {\n ++num;\n } else {\n sum += (num - 1) * num / 2;\n num = 1;\n }\n if (i === n - 1) {\n sum += (num - 1) * num /2;\n }\n }\n return sum;\n}\n\nvar sum = calcFuc(\"x\", \"y\") + calcFuc(\"y\", \"x\");\nvar num, sameNum = 0;\nfor (var i = 0; i < n; ++i) {\n if (i === 0) {\n num = 1;\n } else if (point[i].x === point[i - 1].x &&\n point[i].y === point[i - 1].y) {\n ++num;\n } else {\n sameNum += (num - 1) * num /2;\n num = 1;\n }\n if (i === n - 1) {\n sameNum += (num - 1) * num /2;\n }\n}\nprint(sum - sameNum);"}], "negative_code": [{"source_code": "var n = parseInt(readline());\n\nvar pos = [];\n\nwhile (n-->0) {\n var line = readline().split(' ');\n pos.push([parseInt(line[0]), parseInt(line[1])]);\n}\n\npos.sort((a, b) => {\n if (a[0] === b[0]) {\n return a[1] - b[1];\n }\n return a[0] - b[0];\n});\n\nvar count = 0;\nvar total = 0;\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][0] === pos[i][0]) {\n count++;\n } else {\n total += count*(count+1)/2;\n count = 0;\n }\n}\ntotal += count*(count+1)/2;\ncount = 0;\n\nwrite (total+'\\n');\n\npos.sort((a, b) => {\n if (a[1] === b[1]) {\n return a[0] - b[0];\n }\n return a[1] - b[1];\n});\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][1] === pos[i][1]) {\n count++;\n } else {\n total += count*(count+1)/2;\n count = 0;\n }\n}\ntotal += count*(count+1)/2;\ncount = 0;\n\nwrite (total+'\\n');\n\nfor (var i = 1; i < pos.length; i++) {\n if (pos[i-1][0] === pos[i][0] && pos[i-1][1] === pos[i][1]) {\n count++;\n } else {\n total -= count*(count+1)/2;\n count = 0;\n }\n}\ntotal -= count*(count+1)/2;\ncount = 0;\n\nwrite (total);"}], "src_uid": "bd7b85c0204f6b36dc07f8a96fc36161"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const q = rn();\r\n const set = new Set(),\r\n res = [];\r\n const cache = new Map();\r\n for (let i = 0; i < q; i++) {\r\n const s = read().split(' ');\r\n const num = BigInt(s[1]);\r\n if (s[0] === '+') set.add(num);else {\r\n var _cache$get;\r\n let i = (_cache$get = cache.get(num)) !== null && _cache$get !== void 0 ? _cache$get : num;\r\n for (;; i += num) {\r\n if (set.has(i)) continue;\r\n break;\r\n }\r\n cache.set(num, i);\r\n res.push(i);\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "function solve() {\r\n var q = Number(read());\r\n var set = new Set();\r\n var lastAns = new Map();\r\n while(q--) {\r\n var _ = read().split(' ');\r\n var req = _[0];\r\n var number = BigInt(_[1]);\r\n if (req === '+') {\r\n set.add(number);\r\n continue;\r\n }\r\n var ans = lastAns.get(number) || number;\r\n while(set.has(ans)) {\r\n ans += number;\r\n }\r\n lastAns.set(number, ans);\r\n write(ans);\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n // T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "negative_code": [{"source_code": "function solve() {\r\n var q = Number(read());\r\n var set = new Set();\r\n var lastAns = new Map();\r\n while(q--) {\r\n var _ = read().split(' ');\r\n var req = _[0];\r\n var number = Number(_[1]);\r\n if (req === '+') {\r\n set.add(number);\r\n continue;\r\n }\r\n var ans = lastAns.get(number) || number;\r\n while(set.has(ans)) {\r\n ans += number;\r\n }\r\n lastAns.set(number, ans);\r\n write(ans);\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n // T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "src_uid": "7b394dbced93130f83d61f7e325a980a"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let t = +readLine();\n let [count8, count6, count4, count2] = [0, 0, 0, 0];\n\n function updateCount(target, action = \"+\") {\n if (action === \"+\") {\n if (target === 2) count2++;\n else if (target === 4) count4++;\n else if (target === 6) count6++;\n else if (target === 8) count8++;\n } else {\n if (target === 2) count2--;\n else if (target === 4) count4--;\n else if (target === 6) count6--;\n else if (target === 8) count8--;\n }\n }\n const map = arr.reduce((obj, n) => {\n if (!obj[n]) obj[n] = 1;\n else {\n obj[n]++;\n updateCount(obj[n]);\n }\n return obj;\n }, {});\n\n while (t--) {\n const [sign, num] = readLine().split(\" \");\n if (sign === \"+\") {\n if (!map[num]) map[num] = 1;\n else {\n map[num]++;\n updateCount(map[num], sign);\n }\n } else {\n updateCount(map[num], sign);\n map[num]--;\n }\n\n if (count8 >= 1 || (count6 >= 1 && count2 >= 2) || count4 >= 2 || (count4 >= 1 && count2 >= 3)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "if (process.argv[2] === \"test\") {\n solve([\"6\", \"1 1 1 2 1 1\", \"6\", \"+ 2\", \"+ 1\", \"- 1\", \"+ 2\", \"- 1\", \"+ 2\"]);\n} else {\n let i = \"\";\n process.stdin.on(\"data\", (c) => (i += c));\n process.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n solve(lines);\n });\n}\n\nfunction solve(lines) {\n let totalSize = 0;\n let squareSize = 0;\n //let planks = lines[1].split(\" \").map(parseInt);\n let plankMap = {};\n for (x of lines[1].split(\" \")) {\n //console.log(x);\n if (plankMap[x]) {\n plankMap[x] += 1;\n } else {\n plankMap[x] = 1;\n }\n if (plankMap[x] % 2 === 0) {\n totalSize += 2;\n }\n if (plankMap[x] === 4) {\n squareSize += 1;\n }\n }\n\n const eventCount = parseInt(lines[2]);\n for (let x = 0; x < eventCount; ++x) {\n const [operation, value] = lines[x + 3].split(\" \");\n if (operation === \"+\") {\n if (plankMap[value]) {\n plankMap[value] += 1;\n } else {\n plankMap[value] = 1;\n }\n if (plankMap[value] % 2 === 0) {\n totalSize += 2;\n }\n if (plankMap[value] === 4) {\n squareSize += 1;\n }\n } else {\n if (plankMap[value]) {\n plankMap[value] -= 1;\n }\n if (plankMap[value] % 2 === 1) {\n totalSize -= 2;\n }\n if (plankMap[value] === 3) {\n squareSize -= 1;\n }\n }\n console.log(squareSize > 0 && totalSize >= 8 ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let n = parseInt(readline());\n let a = readline().split(' ');\n let map = new Array(100000 + 1);\n map.fill(0);\n let count = {'4': 0, '2': 0}; \n for(let i = 0; i < a.length; i++){\n let index = parseInt(a[i]);\n if(map[index]){\n map[index] += 1;\n if(map[index] % 4 === 0)\n count[4] += 1;\n\n if(map[index] % 2 === 0)\n count[2] += 1;\n }\n else\n map[index] = 1;\n }\n\n let o = parseInt(readline());\n for(let i = 0; i < o; i++){\n let x = readline().split(' ');\n if(x[0] === '+'){\n map[parseInt(x[1])] += 1;\n if(map[parseInt(x[1])] % 4 === 0)\n count[4]++;\n\n if(map[parseInt(x[1])] % 2 === 0)\n count[2]++;\n }else{\n let f1 = map[parseInt(x[1])] % 4 === 0;\n let f2 = map[parseInt(x[1])] % 2 === 0;\n map[parseInt(x[1])] -= 1;\n if(f1 && map[parseInt(x[1])] % 4 !== 0)\n count[4]--;\n\n if(f2 && map[parseInt(x[1])] % 2 !== 0)\n count[2]--;\n }\n\n if(count[4] >= 2){\n console.log('yes');\n }else if(count[4] >= 1 && count[2]-(2*count[4]) >= 2){\n console.log('yes');\n }else{\n console.log('no');\n }\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var map = {};\n for(var i = 0; i < N; i++){\n if(map[alist[i]] == null){\n map[alist[i]] = 0;\n }\n map[alist[i]]++;\n }\n var recSet = new Set();//2\n var squSet = new Set();//4\n var keys = Object.keys(map).map(Number);\n for(var i = 0; i < keys.length; i++){\n if(map[keys[i]] >= 2){\n recSet.add(keys[i]);\n }\n if(map[keys[i]] >= 4){\n squSet.add(keys[i]);\n }\n }\n var Q = nextInt();\n var output = new Array(Q);\n for(var i = 0; i < Q; i++){\n var tmp = nextStrArray();\n var s = tmp[0];\n var x = myconv(tmp[1], 1);\n if(s == \"+\"){\n if(map[x] == null){\n map[x] = 0;\n }\n map[x]++;\n if(map[x] >= 2){\n recSet.add(x);\n }\n if(map[x] >= 4){\n squSet.add(x);\n }\n }else{\n map[x]--;\n if(map[x] < 4){\n squSet.delete(x);\n }\n if(map[x] < 2){\n recSet.delete(x);\n }\n }\n if(squSet.size >= 2){\n output[i] = \"YES\";\n }else if(squSet.size == 1){\n var tmpList = Array.from(squSet);\n var tmpCount = map[tmpList[0]] - 4;\n var tmpSet = new Set(Array.from(recSet));\n if(tmpCount < 2){\n tmpSet.delete(tmpList[0]);\n }else if(tmpCount >= 4){\n output[i] = \"YES\";\n continue;\n }\n if(tmpSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output, 9));\n}\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var map = {};\n for(var i = 0; i < N; i++){\n if(map[alist[i]] == null){\n map[alist[i]] = 0;\n }\n map[alist[i]]++;\n }\n var recSet = new Set();//4\n var squSet = new Set();//2\n var keys = Object.keys(map).map(Number);\n for(var i = 0; i < keys.length; i++){\n if(map[keys[i]] >= 2){\n recSet.add(keys[i]);\n }\n if(map[keys[i]] >= 4){\n squSet.add(keys[i]);\n }\n }\n myerr(recSet);\n myerr(squSet);\n var Q = nextInt();\n var output = new Array(Q);\n for(var i = 0; i < Q; i++){\n var tmp = nextStrArray();\n var s = tmp[0];\n var x = myconv(tmp[1], 1);\n if(s == \"+\"){\n if(map[x] == null){\n map[x] = 0;\n }\n map[x]++;\n if(map[x] >= 2){\n recSet.add(x);\n }\n if(map[x] >= 4){\n squSet.add(x);\n }\n }else{\n map[x]--;\n if(map[x] < 4){\n squSet.delete(x);\n }\n if(map[x] < 2){\n recSet.delete(x);\n }\n }\n if(squSet.size >= 2){\n output[i] = \"YES\";\n }else if(squSet.size == 1){\n var tmpList = Array.from(squSet);\n var tmpCount = map[tmpList[0]] - 4;\n var tmpSet = recSet;\n if(tmpCount < 2){\n tmpSet.delete(tmpList[0]);\n }else if(map[tmpList[0]] - 4 >= 4){\n output[i] = \"YES\";\n continue;\n }\n if(tmpSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }else{\n output[i] = \"NO\";\n }\n myerr(recSet);\n myerr(squSet);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var map = {};\n for(var i = 0; i < N; i++){\n if(map[alist[i]] == null){\n map[alist[i]] = 0;\n }\n map[alist[i]]++;\n }\n var recSet = new Set();//4\n var squSet = new Set();//2\n var keys = Object.keys(map).map(Number);\n for(var i = 0; i < keys.length; i++){\n if(map[keys[i]] >= 2){\n recSet.add(keys[i]);\n }\n if(map[keys[i]] >= 4){\n squSet.add(keys[i]);\n }\n }\n myerr(recSet);\n myerr(squSet);\n var Q = nextInt();\n var output = new Array(Q);\n for(var i = 0; i < Q; i++){\n var tmp = nextStrArray();\n var s = tmp[0];\n var x = myconv(tmp[1], 1);\n if(s == \"+\"){\n map[x]++;\n if(map[x] >= 2){\n recSet.add(x);\n }\n if(map[x] >= 4){\n squSet.add(x);\n }\n }else{\n map[x]--;\n if(map[x] < 4){\n squSet.delete(x);\n }\n if(map[x] < 2){\n recSet.delete(x);\n }\n }\n if(squSet.size >= 2){\n output[i] = \"YES\";\n }else if(squSet.size == 1){\n var tmpList = Array.from(squSet);\n var tmpCount = map[tmpList[0]] - 4;\n var tmpSet = recSet;\n if(tmpCount < 2){\n tmpSet.delete(tmpList[0]);\n }\n if(tmpSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }else{\n output[i] = \"NO\";\n }\n myerr(recSet);\n myerr(squSet);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var map = {};\n for(var i = 0; i < N; i++){\n if(map[alist[i]] == null){\n map[alist[i]] = 0;\n }\n map[alist[i]]++;\n }\n var recSet = new Set();//4\n var squSet = new Set();//2\n var keys = Object.keys(map).map(Number);\n for(var i = 0; i < keys.length; i++){\n if(map[keys[i]] >= 2){\n recSet.add(keys[i]);\n }\n if(map[keys[i]] >= 4){\n recSet.delete(keys[i]); \n squSet.add(keys[i]);\n }\n if(map[keys[i]] >= 6){\n recSet.add(keys[i]);\n squSet.add(keys[i]);\n }\n }\n myerr(recSet);\n myerr(squSet);\n var Q = nextInt();\n var output = new Array(Q);\n for(var i = 0; i < Q; i++){\n var tmp = nextStrArray();\n var s = tmp[0];\n var x = myconv(tmp[1], 1);\n if(s == \"+\"){\n map[x]++;\n if(map[x] >= 2){\n recSet.add(x);\n }\n if(map[x] >= 4){\n recSet.delete(x);\n squSet.add(x);\n }\n if(map[x] >= 6){\n recSet.add(x);\n squSet.add(x);\n }\n if((recSet.size >= 2 && squSet.size >= 1) || squSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }else{\n map[x]--;\n if(map[x] < 6){\n recSet.delete(x);\n }\n if(map[x] < 4){\n recSet.add(x);\n squSet.delete(x);\n }\n if(map[x] < 2){\n recSet.delete(x);\n }\n\n if((recSet.size >= 2 && squSet.size >= 1) || squSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myerr(recSet);\n myerr(squSet);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var map = {};\n for(var i = 0; i < N; i++){\n if(map[alist[i]] == null){\n map[alist[i]] = 0;\n }\n map[alist[i]]++;\n }\n var recSet = new Set();//4\n var squSet = new Set();//2\n var keys = Object.keys(map).map(Number);\n for(var i = 0; i < keys.length; i++){\n if(map[keys[i]] >= 2){\n recSet.add(keys[i]);\n }\n if(map[keys[i]] >= 4){\n squSet.add(keys[i]);\n }\n }\n myerr(recSet);\n myerr(squSet);\n var Q = nextInt();\n var output = new Array(Q);\n for(var i = 0; i < Q; i++){\n var tmp = nextStrArray();\n var s = tmp[0];\n var x = myconv(tmp[1], 1);\n if(s == \"+\"){\n map[x]++;\n if(map[x] >= 2){\n recSet.add(x);\n }\n if(map[x] >= 4){\n squSet.add(x);\n }\n }else{\n map[x]--;\n if(map[x] < 4){\n squSet.delete(x);\n }\n if(map[x] < 2){\n recSet.delete(x);\n }\n }\n if(squSet.size >= 2){\n output[i] = \"YES\";\n }else if(squSet.size == 1){\n var tmpList = Array.from(squSet);\n var tmpCount = map[tmpList[0]] - 4;\n var tmpSet = recSet;\n if(tmpCount < 2){\n tmpSet.delete(tmpList[0]);\n }else if(map[tmpList[0]] - 4 >= 4){\n output[i] = \"YES\";\n continue;\n }\n if(tmpSet.size >= 2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }else{\n output[i] = \"NO\";\n }\n myerr(recSet);\n myerr(squSet);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let n = parseInt(readline());\n let a = readline().split(' ');\n let map = new Array(100000 + 1);\n let count = {'4': 0, '2': 0}; \n for(let i = 0; i < a.length; i++){\n let index = parseInt(a[i]);\n if(map[index]){\n map[index] += 1;\n if(map[index] % 4 === 0)\n count[4] += 1;\n\n if(map[index] % 2 === 0)\n count[2] += 1;\n }\n else\n map[index] = 1;\n }\n\n let o = parseInt(readline());\n for(let i = 0; i < o; i++){\n let x = readline().split(' ');\n if(x[0] === '+'){\n map[parseInt(x[1])] += 1;\n if(map[parseInt(x[1])] % 4 === 0)\n count[4]++;\n\n if(map[parseInt(x[1])] % 2 === 0)\n count[2]++;\n }else{\n let f1 = map[parseInt(x[1])] % 4 === 0;\n let f2 = map[parseInt(x[1])] % 2 === 0;\n map[parseInt(x[1])] -= 1;\n if(f1 && map[parseInt(x[1])] % 4 !== 0)\n count[4]--;\n\n if(f2 && map[parseInt(x[1])] % 2 !== 0)\n count[2]--;\n }\n\n if(count[4] >= 2){\n console.log('yes');\n }else if(count[4] >= 1 && count[2]-(2*count[4]) >= 2){\n console.log('yes');\n }else{\n console.log('no');\n }\n }\n}"}], "src_uid": "d14bad9abf2a27ba57c80851405a360b"} {"source_code": "function solve() {\r\n var letters = initValues();\r\n var [n, k] = readArray(Number);\r\n var s = read();\r\n var lettersCounter = new Map();\r\n letters.forEach((letter) => lettersCounter.set(letter, 0));\r\n for (var i = 0; i < n; i++) {\r\n lettersCounter.set(s[i], lettersCounter.get(s[i]) + 1);\r\n }\r\n const booksCounter = n / k;\r\n var ans = '';\r\n for (var i = 0; i < k; i++) {\r\n var MEXIndex = 0;\r\n for (MEXIndex = 0; MEXIndex < booksCounter; MEXIndex++) {\r\n var letter = letters[MEXIndex];\r\n if (lettersCounter.get(letter) === 0) {\r\n break;\r\n }\r\n lettersCounter.set(letter, lettersCounter.get(letter) - 1);\r\n }\r\n ans += letters[MEXIndex];\r\n }\r\n write(ans);\r\n}\r\n\r\nvar initialValues;\r\nfunction initValues() {\r\n if (initialValues) {\r\n return initialValues;\r\n }\r\n var letters = [];\r\n var aCode = 'a'.charCodeAt(0);\r\n var zCode = 'z'.charCodeAt(0);\r\n for (var i = aCode; i <= zCode; i++) {\r\n letters.push(String.fromCharCode(i));\r\n }\r\n initialValues = letters;\r\n return letters;\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n", "positive_code": [{"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n_k = readLine().split(' ').map(p => +p);\r\n const str = readLine();\r\n let result = myFunc(n_k[0], n_k[1], str);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, k, s){\r\n let sub = n/k;\r\n let map = [];\r\n const alfabeto = 'abcdefghijklmnopqrstuvwxyz';\r\n let resp = '';\r\n\r\n function _num(s){\r\n return s.charCodeAt(0)-97;\r\n }\r\n\r\n for(let i = 0; i < n; i++){\r\n if(map[_num(s[i])] == undefined) map[_num(s[i])] = 1;\r\n else map[_num(s[i])]++;\r\n }\r\n \r\n for(let j = 0; j < k; j++){\r\n for(let i = 0; i < sub; i++){\r\n if(map[i]){\r\n map[i]--;\r\n if(i == sub-1) resp += alfabeto[sub];\r\n } \r\n else{\r\n resp+= alfabeto[i];\r\n break;\r\n }\r\n \r\n }\r\n }\r\n return resp;\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n k = rn(),\r\n s = read();\r\n const chs = s.split('').sort((a, b) => a === b ? 0 : a < b ? -1 : 1);\r\n const res = [];\r\n const vis = new Array(n);\r\n for (let i = 0; i < k; i++) {\r\n let cnt = 0;\r\n let pre = 96;\r\n for (let j = 0; j < n && cnt < n / k; j++) {\r\n const num = chs[j].charCodeAt(0);\r\n if (vis[j] || num === pre) continue;\r\n vis[j] = 1;\r\n cnt++;\r\n if (num === pre + 1) {\r\n pre = num;\r\n } else {\r\n if (res[i] === undefined) res[i] = pre + 1;\r\n }\r\n }\r\n if (res[i] === undefined) res[i] = pre + 1;\r\n }\r\n return res.map(num => String.fromCharCode(num)).join('');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "9c86925036cd1f83273bc21e2ea3e5c8"} {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=2*t;i+=2)\r\n {\r\n let s=line[i];\r\n let c=line[i+1];\r\n s.length-=1,c.length-=1;\r\n // console.log(s.length,c.length);\r\n let flag=false;\r\n if(s.length%2==0)\r\n {\r\n for(let j=0;j {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst getResult = ( str, target ) => {\r\n \r\n let len = str.length\r\n\r\n let validLen = []\r\n for(let i = 5; i <= len; i+= 4) validLen.push(i)\r\n \r\n if( len === 1 ) return str === target ? 'YES' : 'NO'\r\n \r\n let begin = str.charAt(0)\r\n let end = str.charAt(str.length-1)\r\n let midchar = getMiddle(str)\r\n\r\n if( begin === target || end === target ) return 'YES'\r\n // if( midchar === target ){\r\n // return validLen.includes(len) ? 'YES' : 'NO' \r\n // }\r\n \r\n let indices = findAllIndicesOfChar( str, target )\r\n\r\n for(let i = 0; i < indices.length; i++){\r\n if( isEven(indices[i]) ) {\r\n return 'YES'\r\n }\r\n }\r\n\r\n return 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n let target = readline()\r\n console.log( getResult( str, target ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var t = lines[0];\n\tvar k = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t \t k = lines[i].split('');\n\t }else{\n\t var e = lines[i];\n\t var a = false;\n\t for(j = 0; j < k.length; j++){\n\t if(k[j] == e){\n\t if(j % 2 === 0){\n\t a = true;\n\t }else{\n\t continue;\n\t }\n\t }\n\t }\n\t if(a){\n\t console.log('YES'); \n\t }else{\n\t console.log('NO');\n\t }\n\t }\n\t}\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line().split('').map((e,i) => (i%2 == 0)?e:'').join('');\n\t\tlet c = nl.line();\n\t\tans.push(s.search(c) != -1);\n\t\t\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n let c = readline();\r\n\r\n let indexes = [];\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] === c) indexes.push(i);\r\n }\r\n\r\n let no = true;\r\n for (let idx = 0; idx < indexes.length; idx++) {\r\n let i = indexes[idx];\r\n let rem = s.length - 1;\r\n if (i % 2 === 0 && rem % 2 === 0) {\r\n no = false;\r\n continue;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\n \nconst calc = (s, c)=>{\n for (let i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n str = d;\n c++;\n return;\n }\n\n let ans = \"NO\";\n for (let i = 0; i < str.length; i++) {\n if (str[i] === d && i % 2 === 0) {\n ans = \"YES\";\n }\n }\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar k = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t \t k = lines[i].split('');\n\t }else{\n\t var e = lines[i];\n\t var a = false;\n\t for(j = 0; j < k.length; j++){\n\t if(k[j] == e){\n\t if(j % 2 === 0){\n\t a = true;\n\t }else{\n\t continue;\n\t }\n\t }\n\t }\n\t if(a){\n\t console.log('YES'); \n\t }else{\n\t console.log('NO');\n\t }\n\t }\n\t}\n});"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet t = -1;\r\nlet i = 0;\r\n\r\nlet input = [];\r\n\r\nfunction check(str1, c) {\r\n for (let i = 2; i < str1.length - 2; ++i) {\r\n if ((str1[i] === c) && (i % 2 === 0) && ((str1.length - i) % 2 !== 0)) {\r\n return true;\r\n }\r\n }\r\n\r\n if ((str1[str1.length - 1] === c) || (str1[0] === c)) {\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n}\r\n\r\nrl.on('line', (line) => {\r\n if (t === -1) {\r\n t = parseInt(line);\r\n } else {\r\n ++i;\r\n\r\n input.push(line);\r\n\r\n if (i === 2 * t) {\r\n rl.close();\r\n }\r\n }\r\n}).on('close', () => {\r\n for (let i = 0; i < input.length; i += 2) {\r\n if (check(input[i], input[i + 1])) {\r\n process.stdout.write(\"YES\\n\");\r\n } else {\r\n process.stdout.write(\"NO\\n\");\r\n }\r\n }\r\n\r\n});"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let i = 1;\r\n while (i < ls.length){\r\n const str = ls[i++];\r\n const c = ls[i++];\r\n let found = false;\r\n for (let j = 0; j < str.length; j++){\r\n if (str[j] == c && j % 2 == 0){\r\n found = true;\r\n break;\r\n }\r\n }\r\n console.log(found ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let str = readLine();\r\n const c = readLine();\r\n for (let i = 0; i < str.length; i++) {\r\n if (i % 2 == 0 && str.charAt(i) === c) {\r\n console.log(\"YES\");\r\n return;\r\n }\r\n }\r\n console.log(\"NO\");\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const str = lines[l++]\r\n const c = lines[l++]\r\n output[i] = solve(str, c) ? 'YES' : 'NO'\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(str, c) {\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === c && !(i & 1)) return true\r\n }\r\n return false\r\n}\r\n"}, {"source_code": "function solve() {\r\n const s = read();\r\n const c = read();\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] === c && !(i & 1)) {\r\n write('YES');\r\n return;\r\n }\r\n }\r\n write('NO');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tvar N = s.length;\r\n\t\tvar c = next();\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < N; i += 2){\r\n\t\t\tif(s[i] == c){\r\n\t\t\t\tok = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "T = readline ()\r\nwhile(T--){\r\n \r\n s = readline().split('')\r\n c = readline()\r\n res = 'NO'\r\n\r\n for(i=0; i< s.length; i++){\r\n if(s[i] ===c){\r\n if(i % 2 == 0 && (s.length - i) %2 != 0){\r\n res = 'YES'\r\n break\r\n }\r\n }\r\n }\r\n\r\n print(res)\r\n}\r\n"}, {"source_code": "var t = readline();\r\nfor (var i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst getResult = ( str, target ) => {\r\n \r\n let len = str.length\r\n\r\n let validLen = []\r\n for(let i = 5; i <= len; i+= 4) validLen.push(i)\r\n \r\n if( len === 1 ) return str === target ? 'YES' : 'NO'\r\n \r\n let begin = str.charAt(0)\r\n let end = str.charAt(str.length-1)\r\n let midchar = getMiddle(str)\r\n\r\n if( begin === target || end === target ) return 'YES'\r\n if( midchar === target ){\r\n return validLen.includes(len) ? 'YES' : 'NO' \r\n }\r\n \r\n let indices = findAllIndicesOfChar( str, target )\r\n\r\n for(let i = 0; i < indices.length; i++){\r\n if( isEven(indices[i]) ) {\r\n return 'YES'\r\n }\r\n }\r\n\r\n return 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n let target = readline()\r\n console.log( getResult( str, target ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst getResult = ( str, target ) => {\r\n \r\n let len = str.length\r\n \r\n if( len === 1 ) return str === target ? 'YES' : 'NO'\r\n \r\n let begin = str.charAt(0)\r\n let end = str.charAt(str.length-1)\r\n let midchar = getMiddle(str)\r\n\r\n if( midchar === target || begin === target || end === target ) return 'YES'\r\n \r\n let indices = findAllIndicesOfChar( str, target )\r\n\r\n for(let i = 0; i < indices.length; i++){\r\n if( isEven(indices[i]) ) {\r\n return 'YES'\r\n }\r\n }\r\n\r\n return 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n let target = readline()\r\n console.log( getResult( str, target ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)\r\n\r\nconst getResult = ( str, target ) => {\r\n \r\n let len = str.length\r\n \r\n if( len === 1 ) return 'NO'\r\n \r\n let midchar = getMiddle(str)\r\n \r\n return midchar === target ? 'YES' : 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n let target = readline()\r\n console.log( getResult( str, target ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var t = lines[0];\n\tfor(i = 1; i <= t; i++) {\n\t var a = lines[i];\n if(a < 20){\n console.log('YES');\n var ans = '';\n var b = 1;\n for(j = 0; j < a; j++){\n ans += b + ' ';\n b *= 3;\n }\n console.log(ans);\n }else{\n console.log('NO');\n }\n\t}\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = lines[2]\n var abc = ['a', 'b', 'c' ,'d', 'e', 'f' ,'g', 'h', 'i', 'j', 'k' ,'l', 'm','n', 'o', 'p','q', 'r', 's' ,'t' ,'u', 'v', 'w' ,'x', 'y', 'z']\n for(j = 1; j <= n * 2; j++){\n \n if(j % 2 == 1){\n e = lines[j + 1]\n var s = 0\nvar u = false\nvar r = false\n var a = lines[j].split('').map(String)\n for(k = 0 ; k < a.length; k++){\n if(a[k] != e){\n s++\n }else {\n s++\n u = true\n if(a[a.length - 1] == e){\n r = true\n }\n break;\n }\n }\n if(s % 2 == 1 && u === true || r === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = lines[2]\n var s = 0\n var abc = ['a', 'b', 'c' ,'d', 'e', 'f' ,'g', 'h', 'i', 'j', 'k' ,'l', 'm','n', 'o', 'p','q', 'r', 's' ,'t' ,'u', 'v', 'w' ,'x', 'y', 'z']\n for(j = 1; j <= n * 2; j++){\n \n if(j % 2 == 1){\n e = lines[j + 1]\n var a = lines[j].split('').map(String)\n for(k = 0 ; k < a.length; k++){\n if(a[k] != e){\n s++\n }else {\n break;\n }\n }\n if(s % 2 == 1){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n}); \n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line().split('').map((e,i) => (i%2 == 0)?e:'').join('');\n\t\tlet c = nl.line();\n\t\tans.push(s.search(c) != -1);\n\t\tconsole.log(s);\n\t\t\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line();\n\t\tlet c = nl.line();\n\t\tlet l = s.length;\n\t\tlet ns = s.substring(0, 1) + (l>3?s.substring(2, l-2):\"\") + s.substring(l-1);\n\t\tans.push(ns.search(c) != -1);\n\t\t\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line();\n\t\tlet c = nl.line();\n\t\tlet l = s.length;\n\t\tlet ns = s.substring(0, 1) + s.substring(2, l-2) + s.substring(l-1);\n\t\tans.push(ns.search(c) != -1);\n\t\t\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (s, c)=>{\n if (s[0]==c)\n return true;\n if (s[s.length-1]==c)\n return true;\n return s.slice(2, s.length-2).includes(c)\n};\n\nfunction main() {\n let T = +readline()\n while (T--){\n let s = readline();\n let c = readline();\n print(calc(s, c) ? 'YES' : 'NO');\n }\n}\n\nE.calc = calc;"}], "src_uid": "c569b47cf80dfa98a7105e246c3c1e01"} {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MX = 2e5 + 1;\t\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, l, r] = rna();\r\n\t\tlet c = rna();\r\n\r\n\t\tlet ar1 = Array(n+1).fill(0);\r\n\t\tlet ar2 = Array(n+1).fill(0);\t\r\n\t\tfor (let i = 0 ; i < n; i++) {\r\n\t\t\tif (i < l) \r\n\t\t\t\tar1[c[i]]++;\r\n\t\t\telse\t\r\n\t\t\t\tar2[c[i]]++;\r\n\t\t}\r\n\r\n\t\tif (r > l)\r\n\t\t\t[ar1, ar2] = [ar2, ar1];\r\n\t\t//console.log(ar1,ar2)\r\n\r\n\t\tlet k = Math.abs((l-r)/2);\r\n\t\tlet ans = 0;\r\n\t\t//console.log('k', k);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tar1[i] = Math.max(0, ar1[i] - ar2[i]);\r\n\r\n\t\t\tconst mvs = Math.min(k, Math.floor(ar1[i] / 2));\r\n\r\n\t\t\tk -= mvs;\r\n\t\t\tar1[i] = ar1[i] - 2 * mvs;\r\n\r\n\t\t\tans += ar1[i] + mvs;\r\n\t\t\t//console.log('mvs', mvs)\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, l, r] = rna();\r\n\t\tlet c = rna();\r\n\r\n\t\tlet ar1 = Array(n + 1).fill(0);\r\n\t\tlet ar2 = Array(n + 1).fill(0);\t\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (i < l) \r\n\t\t\t\tar1[c[i]]++;\r\n\t\t\telse\t\r\n\t\t\t\tar2[c[i]]++;\r\n\t\t}\r\n\r\n\t\tif (r > l)\r\n\t\t\t[ar1, ar2] = [ar2, ar1];\r\n\r\n\t\tlet k = Math.abs((l - r) / 2);\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tar1[i] = Math.max(0, ar1[i] - ar2[i]);\r\n\r\n\t\t\tconst mvs = Math.min(k, Math.floor(ar1[i] / 2));\r\n\t\t\tk -= mvs;\r\n\t\t\tar1[i] -= 2 * mvs;\r\n\r\n\t\t\tans += ar1[i] + mvs;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nvar global = 1;\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors_s = readline();\n var colors = colors_s.split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n\n \n \n print(global === 279? `${line1} ${colors_s}`: dollars_spent);\n global++;\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nvar global = 1;\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors_s = readline();\n var colors = colors_s.split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n\n \n \n print(global === 279? line1: dollars_spent);\n global++;\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nvar global = 1;\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors_s = readline();\n var colors = colors_s.split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n\n \n \n print(global === 279? line1 + colors_s: dollars_spent);\n global++;\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nvar global = 1;\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(global === 279? '12312313': dollars_spent);\n global++;\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] >= 1)\n this.size--;\n if (this.set[value] > 1)\n this.set[value]--;\n else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] && this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= min;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++) {\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n dollars_spent += parseInt(min / 2);\n lefts -= min;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor * 2;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n var last_recolor_dif = 0;\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights - last_recolor_dif;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor;\n last_recolor_dif = recolor;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}, {"source_code": "const create_multiset = () => {\n return {\n set: [],\n cardinality: 0,\n size: 0,\n add: function(value) {\n if (this.set[value])\n this.set[value]++;\n else {\n this.set[value] = 1;\n this.cardinality++;\n }\n this.size++;\n },\n delete: function(value) {\n if (this.set[value] > 1) {\n this.set[value]--;\n this.size--;\n } else if (this.set[value]) {\n this.set[value] = undefined;\n this.cardinality--;\n this.size--;\n }\n },\n has: function(value) {\n return (this.set[value] >= 1);\n },\n getCardinality: function() {\n return this.cardinality;\n },\n getSize: function() {\n return this.size;\n },\n getCountOf: function(value) {\n return this.set[value]? this.set[value]: 0\n },\n clear: function() {\n this.set = [];\n this.size = 0;\n }\n }\n};\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var lefts = line1[1];\n var rights = line1[2];\n var l_socks = create_multiset();\n var r_socks = create_multiset();\n\n var colors = readline().split(' ').map(a => parseInt(a));\n colors.slice(0, lefts).forEach(item => l_socks.add(item));\n colors.slice(lefts, n)\n .forEach(item => {\n if (l_socks.has(item))\n l_socks.delete(item);\n else\n r_socks.add(item);\n });\n \n lefts = l_socks.getSize();\n rights = r_socks.getSize();\n n = lefts + rights;\n\n if (lefts < rights) {\n var tt = lefts;\n lefts = rights;\n rights = tt;\n tt = l_socks;\n l_socks = r_socks;\n r_socks = tt;\n }\n \n var dollars_spent = 0;\n\n for (var color_index = 1; color_index <= n; color_index++){\n var d = lefts - rights;\n var lefts_this_color = l_socks.getCountOf(color_index);\n var ok_to_recolor = parseInt(lefts_this_color / 2);\n var min = Math.min(ok_to_recolor * 2, d);\n var recolor = parseInt(min / 2);\n dollars_spent += recolor;\n lefts -= recolor;\n }\n \n dollars_spent += parseInt((lefts - rights) / 2);\n dollars_spent += parseInt((lefts + rights) / 2);\n \n print(dollars_spent);\n}"}], "src_uid": "a2d4f0182456cedbe85dff97ec0f477e"} {"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var arr = [];\n var count = 0;\n for(var i = 0; i < n; i++) {\n arr[i] = read.arr('');\n arr[i].forEach(item => {\n if(item === '.') {\n count++;\n }\n });\n }\n\n if(count % 5 !== 0) {\n print('NO');\n return;\n }\n \n for(var i = 1; i < n - 1; i++) {\n for(var j = 1; j < n - 1; j++) {\n if(arr[i][j] === '.' && arr[i][j-1] === '.' && arr[i][j+1] === '.' && arr[i - 1][j] === '.' && arr[i+1][j] === '.') {\n arr[i][j] = '#';\n arr[i][j - 1] = '#';\n arr[i][j + 1] = '#';\n arr[i - 1][j] = '#';\n arr[i + 1][j] = '#';\n }\n }\n }\n\n var count = 0;\n for(var i = 0; i < n; i++) {\n arr[i].forEach(item => {\n if(item === '.') {\n count++;\n }\n });\n }\n if(count) {\n print('NO');\n }\n else {\n print('YES');\n }\n}());\n\n", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar board = new Array(n).fill('');\nfor(var i=0;i (c==='#' ? false:true))\n}\nvar countToFill = 0;\nboard.forEach((b, i) => {\n board[i].forEach((cell, j) => {\n countToFill+= cell? 1:0;\n })\n});\n\n\nvar canFit = (x, y) => (\n x-1 >= 0 &&\n y-1>=0 &&\n x+1 (\n canFit(x, y) ||\n canFit(x+1, y) ||\n canFit(x-1, y) ||\n canFit(x, y-1) ||\n canFit(x, y+1)\n);\n\nvar res = (countToFill===0) || (countToFill%5 === 0);\n// board.forEach((b, i) => ( board[i].forEach((c, j) => {\n// if (board[i][j]) {\n// res = res && canAnyFit(i,j)\n// }\n// } )));\n// print(res ? 'YES':'NO')\n\nvar fill = (x, y, c) => (\n board[x][y] =\n board[x+1][y] =\n board[x-1][y] = \n board[x][y+1] = \n board[x][y-1] = c //#\n);\nvar fit = (x, y) => (fill(x, y, false)) //#\nvar unfit = (x, y) => (fill(x, y, true)) //.\n\n\n// var q = [{\n// pos: 0,\n// count: countToFill\n// }];\n// while(q.length>0) {\n// var cur = q.shift();\n// var x = Math.floor(cur.pos/board.length);\n// var y = cur.pos%board.length;\n \n// print('pos', cur.pos)\n \n// var count = cur.count;\n// if (count === 0) {\n// print('YES')\n// break;\n// }\n// if (canFit(x, y-1)) {\n// fit(x, y-1);\n// count-=5;\n// } else if (canFit(x-1, y)) {\n// fit(x-1, y);\n// count-=5;\n// } else if (canFit(x, y)) {\n// fit(x, y);\n// count-=5;\n// } else if (canFit(x+1, y)) {\n// fit(x+1, y);\n// count-=5;\n// } else if (canFit(x, y+1)) {\n// fit(x, y+1);\n// count-=5;\n// }\n// q.push({\n// pos: cur.pos+1,\n// count: count\n// })\n// }\n\nvar vis = {}, memo = {};\nfunction sol(pos, count) {\n \n var x = Math.floor(pos/board.length);\n var y = pos%board.length;\n var v = x*board.length*board.length + y*board.length + count;\n if (count === 0) {\n //print('YES');\n return memo[v]=true;\n }\n if (pos>board.length*board.length) {\n \n return memo[v] = false;\n }\n \n //if (vis[v]) return false;\n vis[v] = true;\n \n if (canFit(x, y)) {\n \n// print('fitting in ', x, y);\n \n fit(x, y);\n if(sol(pos+1, count-5)) {\n return memo[v]=true;\n }\n unfit(x, y);\n } else if(sol(pos+1, count)) {\n return memo[v]=true;\n }\n return memo[v]=false;\n}\n\nif (!res) {\n print('NO')\n} else {\n print(sol(0,countToFill) ? 'YES':'NO')\n}\n"}, {"source_code": "var lines = parseInt(readline());\n\nvar matrix = []\nfor (var i = 0; i < lines; i++){ \n matrix.push(readline().split(''));\n}\n\n// var matrix = [\n// ['#', '#', '.', '#'],\n// ['#', '.', '.', '.'],\n// ['#', '#', '.', '#'],\n// ['#', '#', '#', '#']]\n\nfunction isFull() {\n for (var i = 0; i < matrix.length; i++) {\n for (var j = 0; j < matrix.length; j++) {\n if (matrix[i][j] === '.')\n return false;\n }\n }\n return true;\n}\n\nfunction checkInsertion(row, col) {\n return (\n matrix[row][col] === '.' &&\n matrix[row+1][col] === '.' &&\n matrix[row][col+1] === '.' &&\n matrix[row][col-1] === '.' &&\n matrix[row-1][col] === '.'\n );\n}\n\nfunction insert(row, col) {\n matrix[row][col] = '#';\n matrix[row+1][col] = '#';\n matrix[row][col+1] = '#';\n matrix[row][col-1] = '#';\n matrix[row-1][col] = '#';\n}\n\nfunction foo() {\n for (var row = 1; row < matrix.length - 1; row++) {\n for (var col = 1; col < matrix.length - 1; col++) {\n if (checkInsertion(row, col)) {\n insert(row, col);\n if (isFull())\n return write('YES')\n }\n }\n }\n\n write('NO')\n}\n\nfoo();\n"}], "negative_code": [], "src_uid": "cc1feee94617c0cba1c528a0cb3952a8"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst p = [];\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tp[i] = rna();\r\n\t}\r\n\r\n\tp.sort((x, y) => x[1] - y[1]);\r\n\r\n\tlet total = 0;\r\n\tfor (const [a, b] of p) {\r\n\t\ttotal += a;\r\n\t}\r\n\r\n\tconst regbuy = items => buy(items, 2);\r\n\tconst disbuy = items => buy(items, 1);\r\n\tconst buy = (items, price) => {\r\n\t\tbought += items;\r\n\t\trem -= items;\r\n\t\tspent += items * price;\r\n\t}\r\n\r\n\tlet bought = 0, rem = total, spent = 0, i = 0;\r\n\twhile (rem) {\r\n\t\tlet [cur, fordisc] = p[i++];\r\n\t\tfordisc = Math.max(0, fordisc - bought);\r\n\r\n\t\tif (fordisc == 0) {\r\n\t\t\tdisbuy(Math.min(rem, cur));\r\n\t\t} else {\r\n\t\t\tregbuy(Math.min(rem, fordisc));\r\n\t\t\tdisbuy(Math.min(rem, cur));\r\n\t\t}\r\n\t}\r\n\r\n\tconst ans = spent;\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst p = [];\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tp[i] = rna();\r\n\t}\r\n\r\n\tp.sort((x, y) => x[1] - y[1]);\r\n\r\n\tlet total = 0;\r\n\tfor (const [a, b] of p) {\r\n\t\ttotal += a;\r\n\t}\r\n\r\n\tconst regbuy = items => buy(items, 2);\r\n\tconst disbuy = items => buy(items, 1);\r\n\tconst buy = (items, price) => {\r\n\t\tbought += items;\r\n\t\trem -= items;\r\n\t\tspent += items * price;\r\n\t}\r\n\r\n\tlet bought = 0, rem = total, spent = 0, i = 0;\r\n\twhile (rem) {\r\n\t\tlet [must, should] = p[i++];\r\n\t\tshould = Math.max(0, should - bought);\r\n\t\tif (should) {\r\n\t\t\tregbuy(Math.min(rem, should));\r\n\t\t}\r\n\t\tdisbuy(Math.min(rem, must));\r\n\t}\r\n\r\n\tconst ans = spent;\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst p = [];\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tp[i] = rna();\r\n\t}\r\n\r\n\tp.sort((x, y) => x[1] - y[1]);\r\n\r\n\tlet total = 0;\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\ttotal += p[i][0];\r\n\t}\r\n\r\n\tlet bought = 0, rem = total;\r\n\tlet spent = 0;\r\n\tlet i = 0;\r\n\twhile (rem) {\r\n\t\t//console.log(p[i], {rem, bought, spent})\r\n\t\tconst [need, minr] = p[i++];\r\n\t\tconst reqfrd = Math.max(minr - bought, 0);\r\n\r\n\t\tif (reqfrd == 0) {\r\n\t\t\tconst discbuy = Math.min(rem, need);\r\n\t\t\tbuy(discbuy, 1);\r\n\t\t} else {\r\n\t\t\tconst regbuy = Math.min(rem, reqfrd);\r\n\t\t\tbuy(regbuy, 2);\r\n\r\n\t\t\tconst discbuy = Math.min(rem, need);\r\n\t\t\tbuy(discbuy, 1);\r\n\t\t\t//console.log({i, regbuy, discbuy})\r\n\t\t}\r\n\t}\r\n\r\n\tfunction buy (items, price) {\r\n\t\tbought += items;\r\n\t\trem -= items;\r\n\t\tspent += items * price;\r\n\t}\r\n\r\n\tconst ans = spent;\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var n = +lines[l++];\n var arr = lines.slice(l, l + n).map(str => str.split(' ').map(Number));\n console.log(solve(n, arr))\n});\n\nfunction solve(n, arr) {\n arr.sort((a, b) => a[1] - b[1])\n\n let i = 0\n let j = arr.length - 1\n let all = 0\n let pay = 0\n while (i <= j) {\n const [total, limit] = arr[i]\n while (all < limit && j > i) {\n const able = arr[j][0]\n let cost\n if (all + able < limit) {\n cost = able\n arr[j][0] -= cost\n j--\n } else {\n cost = limit - all\n arr[j][0] -= cost\n }\n all += cost\n pay += 2 * cost\n }\n// console.log(arr, pay, all)\n if (all < limit) {\n const f = Math.min(total, limit - all)\n pay += f * 2\n all += f\n arr[i][0] -= f\n break\n } else {\n pay += total\n all += total\n arr[i][0] = 0\n i++\n }\n }\n if (i >= n) return pay\n // i == j\n if (all >= arr[i][1]) {\n pay += arr[i][0]\n } else {\n pay += 2 * arr[i][0]\n }\n return pay\n}\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const N = input.number();\r\n const products = Array(N);\r\n for (let i = 0; i < N; i++) {\r\n const a = input.number();\r\n const b = input.number();\r\n products[i] = { a, b };\r\n }\r\n products.sort((x, y) => x.b - y.b);\r\n let head = 0;\r\n let tail = N - 1;\r\n let sum = 0;\r\n let count = 0;\r\n while (head <= tail) {\r\n // console.log({ head, tail })\r\n const p_head = products[head];\r\n let c = p_head.b - count;\r\n // console.log({ p_head, count, c })\r\n if (c > 0) {\r\n while (head <= tail) {\r\n // console.log({ head, tail, c })\r\n const p_tail = products[tail];\r\n if (p_tail.a > c) {\r\n p_tail.a -= c;\r\n count += c;\r\n sum += 2 * c;\r\n break;\r\n }\r\n else if (p_tail.a === c) {\r\n p_tail.a -= c;\r\n count += c;\r\n sum += 2 * c;\r\n tail--;\r\n break;\r\n }\r\n else {\r\n c -= p_tail.a;\r\n count += p_tail.a;\r\n sum += 2 * p_tail.a;\r\n p_tail.a = 0;\r\n tail--;\r\n }\r\n }\r\n }\r\n // console.log({ p_head })\r\n if (p_head.a > 0) {\r\n if (p_head.b <= count) {\r\n sum += p_head.a;\r\n }\r\n else {\r\n sum += 2 * p_head.a;\r\n }\r\n count += p_head.a;\r\n }\r\n head++;\r\n }\r\n console.log(sum);\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var arr = [];\r\n for (var i = 0; i < n; i++) {\r\n arr.push(readArray(BigInt));\r\n }\r\n arr.sort((a, b) => {\r\n if (a[1] > b[1]) {\r\n return 1;\r\n }\r\n if (a[1] < b[1]) {\r\n return -1;\r\n }\r\n return 0;\r\n });\r\n var counter = 0n;\r\n var ans = 0n;\r\n var l = 0;\r\n var r = n - 1;\r\n while (l <= r) {\r\n var la = arr[l][0];\r\n var lb = arr[l][1];\r\n var ra = arr[r][0];\r\n\r\n if (counter >= lb) {\r\n ans += la;\r\n counter += la;\r\n arr[l][0] = 0n;\r\n l++;\r\n continue;\r\n }\r\n\r\n var needForSale = lb - counter;\r\n if (needForSale >= ra) {\r\n ans += 2n * ra;\r\n counter += ra;\r\n arr[r][0] = 0n;\r\n r--;\r\n continue;\r\n }\r\n \r\n counter += needForSale;\r\n ans += 2n * needForSale;\r\n arr[r][0] -= needForSale;\r\n }\r\n write(ans);\r\n /*\r\n for (var i = 0; i < n; i++) {\r\n var a = arr[i][0];\r\n var b = arr[i][1];\r\n if (counter >= b) {\r\n counter += a;\r\n ans += a;\r\n continue;\r\n }\r\n var nextCounter = counter + a;\r\n if (nextCounter < b) {\r\n counter = nextCounter;\r\n ans += a * 2n;\r\n continue;\r\n }\r\n // counter < b <= nextCounter\r\n ans += (b - counter - 1n) * 2n + (nextCounter - b + 1n);\r\n counter = nextCounter;\r\n }\r\n write(ans);\r\n */\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n n = parseInt((await getLine()));\r\n const t = new Array(n);\r\n for(let i = 0; i < n; i++) {\r\n let ai, bi;\r\n [ai, bi] = (await getLine()).split(' ').map(num => BigInt(num));\r\n t[i] = {\r\n a: ai,\r\n b: bi\r\n };\r\n }\r\n let cmpt = (a,b) => {\r\n let diff = a.b - b.b;\r\n let zeroBig = BigInt(0);\r\n if (diff < zeroBig)\r\n return -1;\r\n else if (diff > zeroBig)\r\n return 1;\r\n else\r\n return 0;\r\n }\r\n t.sort(cmpt);\r\n let bought = BigInt(0);\r\n let sum = BigInt(0);\r\n let last = t.length - 1;\r\n let first = 0\r\n while (first <= last) {\r\n if (t[first].b > bought) {\r\n while (first <= last) {\r\n if (t[last].a + bought <= t[first].b){\r\n sum += BigInt(2) * t[last].a;\r\n bought += t[last].a;\r\n last--;\r\n }\r\n else {\r\n t[last].a -= (t[first].b - bought);\r\n sum += t[first].a + BigInt(2) * (t[first].b - bought);\r\n bought += t[first].b - bought + t[first].a;\r\n first++;\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n bought += t[first].a;\r\n sum += t[first].a;\r\n first++;\r\n }\r\n }\r\n console.log(sum.toString());\r\n}\r\n\r\nsolve();\r\n"}], "negative_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var n = +lines[l++];\n var arr = lines.slice(l, l + n).map(str => str.split(' ').map(Number));\n console.log(solve(n, arr))\n});\n\nfunction solve(n, arr) {\n arr.sort((a, b) => a[1] - b[1])\n\n let i = 0\n let j = arr.length - 1\n let all = 0\n let pay = 0\n while (i < j) {\n const [total, limit] = arr[i]\n while (all < limit && j > i) {\n const able = arr[j][0]\n let cost\n if (all + able < limit) {\n cost = able\n arr[j][0] -= cost\n j--\n } else {\n cost = limit - all\n arr[j][0] -= cost\n }\n all += cost\n pay += 2 * cost\n }\n// console.log(arr, pay, all)\n if (all < limit) {\n const f = Math.min(total, limit - all)\n pay += f * 2\n all += f\n arr[i][0] -= f\n break\n } else {\n pay += total\n all += total\n arr[i][0] = 0\n i++\n }\n }\n // i == j\n if (all >= arr[i][1]) {\n pay += arr[i][0]\n } else {\n pay += 2 * arr[i][0]\n }\n return pay\n}\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const N = input.number();\r\n const products = Array(N);\r\n for (let i = 0; i < N; i++) {\r\n const a = input.number();\r\n const b = input.number();\r\n products[i] = { a, b };\r\n }\r\n products.sort((x, y) => x.b - y.b);\r\n let head = 0;\r\n let tail = N - 1;\r\n let sum = 0;\r\n let count = 0;\r\n while (head <= tail) {\r\n // console.log({ head, tail })\r\n const p_head = products[head];\r\n let c = p_head.b - count;\r\n // console.log({ p_head, count, c })\r\n if (c > 0) {\r\n while (head <= tail) {\r\n // console.log({ head, tail, c })\r\n const p_tail = products[tail];\r\n if (p_tail.a > c) {\r\n p_tail.a -= c;\r\n count += c;\r\n sum += 2 * c;\r\n break;\r\n }\r\n else if (p_tail.a === c) {\r\n p_tail.a -= c;\r\n count += c;\r\n sum += 2 * c;\r\n tail--;\r\n break;\r\n }\r\n else {\r\n c -= p_tail.a;\r\n count += p_tail.a;\r\n sum += 2 * p_tail.a;\r\n tail--;\r\n }\r\n }\r\n }\r\n // console.log({ p_head })\r\n if (p_head.a > 0) {\r\n if (p_head.b <= count) {\r\n sum += p_head.a;\r\n }\r\n else {\r\n sum += 2 * p_head.a;\r\n }\r\n count += p_head.a;\r\n }\r\n head++;\r\n }\r\n console.log(sum);\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}], "src_uid": "6e8cabaee588f53faae5feb2d1950c58"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n, t, ans = 2, cont = [], indicator = 0, temp = [];\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0];\n t = temp[1];\n indicator++;\n }\n else {\n temp = input.split(' ').map(item => parseFloat(item));\n let center = temp[0];\n let len = temp[1];\n cont.push([center - len / 2, center + len / 2]);\n }\n\n}).on('close', () => {\n cont.sort((obj1, obj2) => { return obj1[0] - obj2[0] });\n for (let i = 0; i < n - 1; i++) {\n let gap = cont[i + 1][0] - cont[i][1];\n if (gap > t)\n ans += 2;\n else if (gap == t)\n ans++;\n }\n console.log(ans);\n});", "positive_code": [{"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction addToArray(items, a, b) {\n var len = items.length;\n\n for (var i = 0; i < len; i++) {\n if (items[i] == a) {\n items[i] = b;\n return items;\n }\n if (items[i] == b) {\n items[i] = a;\n return items;\n }\n }\n\n var newArray = [len + 1];\n\n for (var i = 0; i < len; i++) {\n newArray[i] = items[i];\n }\n newArray[len] = a;\n newArray[len + 1] = b;\n\n return newArray;\n}\n\nfunction bubbleSort(cont) {\n var swapped,\n len = cont.length;\n if (len === 1) return;\n\n do {\n swapped = false;\n for (var i = 1; i < len; i++) {\n if (cont[i - 1] > cont[i]) {\n var b = cont[i];\n cont[i] = cont[i - 1];\n cont[i - 1] = b;\n swapped = true;\n }\n }\n } while (swapped);\n return;\n}\n\nvar array = [];\nvar mycont = [];\nvar n = -1;\nvar t = 0;\nvar counter = 2;\nvar coordinat = 0;\nvar check = false;\n\nrl.on(\"line\", input => {\n if (n == -1) {\n array = input.split(\" \");\n n = parseInt(array[0]);\n t = parseInt(array[1]);\n } else if (n != 1) {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n mycont = addToArray(mycont, x - a / 2, x + a / 2);\n\n n--;\n } else if (n == 1) {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n mycont = addToArray(mycont, x - a / 2, x + a / 2);\n\n bubbleSort(mycont);\n\n for (var i = 2; i < mycont.length - 1; i += 2) {\n if (mycont[i] - mycont[i - 1] == t) counter++;\n else if (mycont[i] - mycont[i - 1] > t) counter += 2;\n }\n }\n}).on(\"close\", () => {\n console.log(counter);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n\n\nvar n, t, pos, len, indicator = 0,ans = 2,\n cont = [],\n temp = [];\n\n\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0];\n t = temp[1];\n indicator++;\n } else if (indicator < n) {\n temp = input.split(' ').map(item => parseInt(item));\n pos = temp[0];\n len = temp[1];\n cont.push([pos - len / 2, pos + len / 2]);\n indicator++;\n } else {\n temp = input.split(' ').map(item => parseInt(item));\n pos = temp[0];\n len = temp[1];\n cont.push([pos - len / 2, pos + len / 2]);\n /*our calculations here*/ \n cont.sort((a,b) => {return a[0]-b[0]});\n for(i=0;i t)\n ans+=2;\n else if(gap == t)\n ans++;\n\n \n }\n console.log(ans);\n rl.close();\n }\n\n});"}, {"source_code": "'use strict'\n\nlet lll = readline().split(' ')\nlet N = +lll[0]\nlet T = +lll[1]\n\nlet hoss = []\n\nwhile (lll = readline()) {\n lll = lll.split(' ')\n let x = +lll[0]\n let a = +lll[1]\n hoss.push([x - a / 2, x + a / 2])\n}\n\nlet pos = 0\n\nhoss = hoss.sort((a, b) => a[0] - b[0])\n\nhoss.forEach((h, i) => {\n let ph = hoss[i - 1] || [-Infinity, -Infinity]\n let nh = hoss[i + 1] || [Infinity, Infinity]\n if (h[0] - ph[1] >= T) pos++\n if (nh[0] - h[1] > T) pos++\n})\n\nprint(pos)"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar n, t, cont = [], indicator = 0, temp = [];\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0], t = temp[1];\n indicator++;\n }\n else {\n temp = input.split(' ').map(item => parseFloat(item));\n let houseCenter = temp[0];\n let houseLen = temp[1];\n let arr = [houseCenter - houseLen / 2, houseCenter + houseLen / 2];\n cont.push(arr);\n }\n\n}).on('close', function () {\n let ans = 2;\n cont.sort(function (obj1, obj2) {\n return obj1[0] - obj2[0];\n /*\n if(obj1[0] > obj2[0]) return 1;\n return -1;\n */\n });\n // console.log(cont);\n for (let i = 0; i < n - 1; i++) {\n let gap = cont[i + 1][0] - cont[i][1];\n if (gap > t) ans += 2;\n else if (gap == t) ans++;\n }\n console.log(ans);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n, t, indicator = 0, cont = [], temp = [];\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0];\n t = temp[1];\n indicator++;\n }\n else {\n temp = input.split(' ').map(item => parseInt(item));\n let center = temp[0], len = temp[1];\n cont.push([center - len / 2, center + len / 2])\n }\n}).on('close', () => {\n //sort array using comparator\n cont.sort((arr1, arr2) => {\n return arr1[0] - arr2[0];\n })\n\n //console.log(cont);\n let ans = 2;\n for (let i = 0; i < n - 1; i++) {\n let gap = cont[i + 1][0] - cont[i][1];\n if (gap > t) ans += 2;\n else if (gap == t) ans++;\n }\n console.log(ans);\n});"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction addToArray(items, a) {\n var len = items.length;\n\n for (var i = 0; i < len; i++) {\n if (items[i] == a) return items;\n }\n\n var newArray = [len];\n\n for (var i = 0; i < len; i++) {\n newArray[i] = items[i];\n }\n newArray[len] = a;\n\n return newArray;\n}\n\nfunction bubbleSort(cont) {\n var swapped,\n len = cont.length;\n if (len === 1) return;\n\n do {\n swapped = false;\n for (var i = 1; i < len; i++) {\n if (cont[i - 1] > cont[i]) {\n var b = cont[i];\n cont[i] = cont[i - 1];\n cont[i - 1] = b;\n swapped = true;\n }\n }\n } while (swapped);\n return;\n}\n\nvar array = [];\nvar mycont = [];\nvar n = -1;\nvar t = 0;\nvar counter = 2;\nvar coordinat = 0;\nvar check = false;\n\nrl.on(\"line\", input => {\n if (n == -1) {\n array = input.split(\" \");\n n = parseInt(array[0]);\n t = parseInt(array[1]);\n } else if (n != 1) {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n mycont = addToArray(mycont, x - a / 2);\n mycont = addToArray(mycont, x + a / 2);\n n--;\n } else if (n == 1) {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n mycont = addToArray(mycont, x - a / 2);\n mycont = addToArray(mycont, x + a / 2);\n\n bubbleSort(mycont);\n for (var i = 1; i < mycont.length; i += 2) {\n if (mycont[i + 1] - mycont[i] == t) counter++;\n else if (mycont[i + 1] - mycont[i] > t) counter += 2;\n }\n\n }\n}).on(\"close\", () => {\n console.log(counter);\n //console.log(sleep2);\n});\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar array = [];\nvar n = -1;\nvar t = 0;\nvar counter = 2;\nvar coordinat = 0;\nvar check = false;\n\nrl.on(\"line\", input => {\n if (n++ == -1) {\n array = input.split(\" \");\n t = parseInt(array[1]);\n } else {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n if (check) {\n if (x - a / 2 - coordinat > t) counter += 2;\n else if (x - a / 2 - coordinat == t) counter++;\n }\n\n coordinat = x + a / 2;\n\n check = true;\n }\n\n}).on(\"close\", () => {\n console.log(counter);\n \n });;\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction addToArray(items, a) {\n var len = items.length;\n\n for (var i = 0; i < len; i++) {\n if (items[i] == a) return items;\n }\n\n var newArray = [len];\n\n for (var i = 0; i < len; i++) {\n newArray[i] = items[i];\n }\n newArray[len] = a;\n\n return newArray;\n}\n\nfunction bubbleSort(cont) {\n var swapped,\n len = cont.length;\n if (len === 1) return;\n\n do {\n swapped = false;\n for (var i = 1; i < len; i++) {\n if (cont[i - 1] > cont[i]) {\n var b = cont[i];\n cont[i] = cont[i - 1];\n cont[i - 1] = b;\n swapped = true;\n }\n }\n } while (swapped);\n return;\n}\n\nvar array = [];\nvar mycont = [];\nvar n = -1;\nvar t = 0;\nvar counter = 2;\nvar coordinat = 0;\nvar check = false;\n\nrl.on(\"line\", input => {\n if (n == -1) {\n array = input.split(\" \");\n n = parseInt(array[0]);\n t = parseInt(array[1]);\n } else if (n != 0) {\n array = input.split(\" \");\n var x = parseInt(array[0]);\n var a = parseInt(array[1]);\n mycont = addToArray(mycont, x - a / 2);\n mycont = addToArray(mycont, x + a / 2);\n n--;\n } else if (n == 0) {\n bubbleSort(mycont);\n for (var i = 1; i < mycont.length; i += 2) {\n if (mycont[i + 1] - mycont[i] == t) counter++;\n else if (mycont[i + 1] - mycont[i] > t) counter += 2;\n }\n\n console.log(counter);\n rl.close();\n }\n});\n"}], "src_uid": "c31fed523230af1f904218b2fe0d663d"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n let cases = parseInt(lines[0])\n //const splitLines = lines.map(x => x.split(\" \").map(x => parseInt(x)))\n for (let i = 1; i <= cases; i ++)\n {\n let a = lines[i].split(\" \").map(x => parseInt(x))\n let n = a[0];\n let k = a[1];\n switch (k % 4)\n {\n case 0:\n console.log(\"NO\");\n break;\n case 1:\n case 3:\n console.log(\"YES\")\n for (let i = 1; i <= n; i +=2)\n {\n console.log(i + \" \" + (i + 1))\n }\n break;\n case 2:\n console.log(\"YES\")\n for (let i = 1; i <= n; i += 2)\n {\n if (i % 4 == 1)\n {\n console.log((i + 1) + \" \" + i)\n }\n else{\n console.log(i + \" \" + (i + 1))\n }\n }\n }\n }\n})", "positive_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, k] = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n k,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, k } = testCase;\n // console.log(n, k);\n\n if (k % 4 == 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n const a2 = (4 - (k % 4)) % 4;\n const b1 = 4;\n const s = new Set([1, 2, 3]);\n s.delete(a2);\n const a1 = Array.from(s)[0];\n const b2 = Array.from(s)[1];\n\n // console.error(a1, b1, a2, b2);\n\n for (let i = 0; i < Math.floor(n / 4); i++) {\n console.log(\n i * 4 + a1,\n i * 4 + b1\n // ((i * 4 + a1 + k) * (i * 4 + b1)) % 4\n );\n console.log(\n i * 4 + a2,\n i * 4 + b2\n // ((i * 4 + a2 + k) * (i * 4 + b2)) % 4\n );\n }\n if (n % 4 == 2) {\n if (k % 4 == 2)\n console.log(\n n,\n n - 1\n // ((n + k) * (n - 1)) % 4\n );\n else\n console.log(\n n - 1,\n n\n // ((n - 1 + k) * n) % 4\n );\n }\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [n, k] = readline().split(' ').map(Number);\r\n\r\n if (k % 2 === 1) {\r\n output('YES');\r\n for (let i = 0; i < (n / 2); i++) {\r\n let first = i * 2 + 1;\r\n let second = first + 1;\r\n output(first + ' ' + second);\r\n }\r\n continue;\r\n } else if (k % 4 === 0) {\r\n output('NO');\r\n } else if (k % 4 === 2) {\r\n let start = 4;\r\n output('YES');\r\n let temp = n;\r\n while (start <= n) {\r\n output((start - 1) + ' ' + start);\r\n output((start - 2) + ' ' + (start - 3));\r\n start += 4;\r\n temp -= 4;\r\n }\r\n if (temp === 2) {\r\n output((start - 2) + ' ' + (start - 3));\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k) {\n // (a + k) * b = 4x\n const h = n / 2\n const ans = []\n if (k & 1) {\n // (odd + k) * even\n for (let i = 1; i < n; i += 2) {\n ans.push([i, i + 1])\n }\n } else {\n const r = k % 4\n if (!r) return 'NO'\n // 4n, 4n - k, with odd\n const ps = [[], [], [], [], []]\n let i = 1\n while (i <= n) {\n for (let j = 1; j <= 4; j++) {\n ps[j].push(i++)\n if (i > n) break\n }\n }\n ps[0] = ps[4] // hack\n let p0 = 0\n let p1 = 0, ps1 = ps[4 - r]\n for (let i = 1; i < n; i += 2) {\n if (p0 < ps[0].length) {\n ans.push([i, ps[0][p0++]])\n } else {\n ans.push([ps1[p1++], i])\n }\n }\n // console.log(ps, ans)\n // const other = ps[r]\n // for (let i = 0; i < other.length; i += 2) {\n // ans.push([other[i], other[i + 1]])\n // }\n }\n return 'YES\\n' + ans.map(x => x.join(' ')).join('\\n')\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n const [n, m] = a;\r\n if (m & 1) {\r\n const res = ['YES'];\r\n for (let i = 1; i <= n; i += 2) {\r\n res.push(`${i} ${i + 1}`);\r\n }\r\n return res.join('\\n');\r\n } else if (m % 4 === 2) {\r\n let res = ['YES'];\r\n for (let i = 1; i <= n; i += 2) {\r\n if ((i + 1) / 2 & 1) {\r\n res.push(`${i + 1} ${i}`);\r\n } else {\r\n res.push(`${i} ${i + 1}`);\r\n }\r\n }\r\n return res.join('\\n');\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await rns();\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #814 (Div. 2)\n2022-08-16\n\nA. Chip Game\n***/\n\nfunction main() {\n const t = parseInt(readline());\n\n for (let i = 0; i < t; i++) {\n const testCase = readline().split(\" \");\n const n = parseInt(testCase[0]);\n const k = parseInt(testCase[1]);\n\n // k is odd -> pair 1-2, 3-4\n // k is 2 (mod 4) -> pair 2-1, 3-4\n switch (k % 4) {\n case 1:\n case 3:\n console.log(\"YES\");\n for (let startNum = 1; startNum < n; startNum += 2) {\n console.log(startNum + \" \" + (startNum + 1));\n }\n break;\n case 2:\n console.log(\"YES\");\n for (let startNumB = 3; startNumB < n; startNumB += 4) {\n console.log(startNumB + \" \" + (startNumB + 1));\n }\n for (let startNumA = 2; startNumA <= n; startNumA += 4) {\n console.log(startNumA + \" \" + (startNumA - 1));\n }\n break;\n case 0:\n console.log(\"NO\");\n break;\n default:\n console.log(\n \"Something went wrong: \" +\n k +\n \" is in none of the mod 4 residue classes\"\n );\n break;\n }\n }\n}\n"}, {"source_code": "var n, k;\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nk[0];\r\n k = nk[1];\r\n if (k % 4 == 0) {\r\n print('NO');\r\n continue;\r\n }\r\n print('YES');\r\n if (k & 1) {\r\n for (var i = 1; i <= n; i+=2) {\r\n print(i + ' ' + (i+1));\r\n }\r\n } else {\r\n for (var i = 2; i <= n; i+=2) {\r\n if (i % 4 == 0) {\r\n print((i-1) + ' ' + i);\r\n } else {\r\n print(i + ' ' + (i-1));\r\n }\r\n }\r\n }\r\n }"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, k] = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n k,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, k } = testCase;\n // console.log(n, k);\n\n if (k % 4 == 0 || (k % 4 == 2 && n % 4 == 2)) console.log(\"NO\");\n else {\n console.log(\"YES\");\n const a2 = (4 - (k % 4)) % 4;\n const b1 = 4;\n const s = new Set([1, 2, 3]);\n s.delete(a2);\n const a1 = Array.from(s)[0];\n const b2 = Array.from(s)[1];\n\n // console.error(a1, b1, a2, b2);\n\n for (let i = 0; i < Math.floor(n / 4); i++) {\n console.log(\n i * 4 + a1,\n i * 4 + b1\n // ((i * 4 + a1 + k) * (i * 4 + b1)) % 4\n );\n console.log(\n i * 4 + a2,\n i * 4 + b2\n // ((i * 4 + a2 + k) * (i * 4 + b2)) % 4\n );\n }\n if (n % 4 == 2) console.log(n - 1, n);\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [n, k] = readline().split(' ').map(Number);\r\n\r\n if (k % 2 === 1) {\r\n output('YES');\r\n for (let i = 0; i < (n / 2); i++) {\r\n let first = i * 2 + 1;\r\n let second = first + 1;\r\n output(first + ' ' + second);\r\n }\r\n continue;\r\n } else if (k % 4 === 0) {\r\n output('NO');\r\n } else if (k % 4 === 2) {\r\n let start = 4;\r\n output('YES');\r\n let temp = n;\r\n while (start <= n) {\r\n output((start - 1) + ' ' + start);\r\n output((start - 2) + ' ' + (start - 3));\r\n start += 4;\r\n temp -= 4;\r\n }\r\n if (temp === 2) {\r\n output((start + 2) + ' ' + (start + 1));\r\n }\r\n }\r\n }\r\n}\r\n"}], "src_uid": "d4fc7e683f389e0c7bbee8e115cef459"} {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = [];\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n cream[i] = 0;\r\n if (a[i] === 0) {\r\n continue;\r\n }\r\n var bottom = i - a[i] + 1;\r\n if (bottom < 0) {\r\n bottom = 0;\r\n }\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' ')); \r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? path.join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n init();\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n", "positive_code": [{"source_code": "var input = parseInt(readline());\n \nfor (var z = 0; z < input; z++) {\n var pies = parseInt(readline());\n var cr = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n var dt = pies, ndt;\n for(var i =pies-1;i>=0;i--)\n {\n if(cr[i])\n {\n if(cr[i] > i+1)\n {\n cr[i] = i+1;\n }\n if(dt > (i - cr[i]+1))\n {\n dt = i - cr[i] + 1;\n }\n }\n \n if(i>=dt)\n {\n cr[i]=1;\n }\n else\n {\n cr[i]=0\n }\n // print(dt)\n }\n var str=\"\";\n for(var i =0;i parseInt(x));\r\n var dt = pies, ndt;\r\n for(var i =pies-1;i>=0;i--)\r\n {\r\n if(cr[i])\r\n {\r\n if(cr[i] > i+1)\r\n {\r\n cr[i] = i+1;\r\n }\r\n if(dt > (i - cr[i]+1))\r\n {\r\n dt = i - cr[i] + 1;\r\n }\r\n }\r\n \r\n if(i>=dt)\r\n {\r\n cr[i]=1;\r\n }\r\n else\r\n {\r\n cr[i]=0\r\n }\r\n // print(dt)\r\n }\r\n var str=\"\";\r\n for(var i =0;i parseInt(x));\r\n// var a = verts[0];\r\n// var b = verts[1];\r\n// if (!graph[a]) {\r\n// graph[a] = [];\r\n// graph[a].fill(0);\r\n// vertLen[a] = 0;\r\n// }\r\n// if (!graph[b]) {\r\n// graph[b] = [];\r\n// graph[b].fill(0);\r\n// vertLen[b] = 0;\r\n// }\r\n// graph[a][b] = 1;\r\n// graph[b][a] = 1;\r\n// vertLen[a] += 1;\r\n// vertLen[b] += 1;\r\n// }\r\n\r\n// var vertToDel = [];\r\n\r\n// // print(vertLen);\r\n\r\n// var r = 0;\r\n// while (\r\n// vertLen.map((x, index) => {\r\n// if (x < k - 1 && x != -1) vertToDel.push(index);\r\n// }) &&\r\n// vertToDel.length > 0\r\n// ) {\r\n// r++;\r\n// // print(\"entered\", vertToDel, \"-\", vertLen);\r\n// for (var i = 0; i < vertToDel.length; i++) {\r\n// var vert = vertToDel[i];\r\n// graph.map((x, index) => {\r\n// if (x.length > 0) {\r\n// if (graph[index][vert] === 1) {\r\n// graph[index][vert] = 0;\r\n// vertLen[index] = vertLen[index] - 1;\r\n// }\r\n// }\r\n// });\r\n// graph[vert] = [];\r\n// vertLen[vert] = -1;\r\n// }\r\n// vertToDel = [];\r\n// }\r\n\r\n// var ind = 0;\r\n// graph.map((x, index) => {\r\n// if (x.length > 0) {\r\n// ind = index;\r\n// }\r\n// });\r\n\r\n// if(ind===0)\r\n// {\r\n// print('-1');\r\n// continue;\r\n// }\r\n// var subset = [];\r\n// var level1 = [ind];\r\n// var level2 = [];\r\n// subset = subset.concat(level1);\r\n\r\n// while (level1.length > 0) {\r\n// print(subset);\r\n// level1.forEach((x, index) => {\r\n// if (graph[x].length > 0) {\r\n// graph[x].map((x,index)=>{\r\n// if(x===1 && !subset.includes(index) && !level2.includes(index))\r\n// {\r\n// level2.push(index);\r\n// }\r\n// })\r\n// }\r\n// });\r\n// subset = subset.concat(level2);\r\n// level1= [].concat(level2);\r\n// level2 = [];\r\n// }\r\n// print(subset);\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = [];\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n cream[i] = 0;\r\n if (a[i] === 0) {\r\n continue;\r\n }\r\n var bottom = i - a[i] + 1;\r\n if (bottom < 0) {\r\n bottom = 0;\r\n }\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log(value) : print(value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10);\r\n }\r\nvar t = parseInt(readline(), 10);\r\nfor(var it = 0; it=0; i--){\r\n counter = Math.max(line[i], counter);\r\n var res = counter > 0? 1 : 0;\r\n counter --;\r\n \r\n result.push(res);\r\n\r\n }\r\n \r\n print(result.reverse().join(' '))\r\n \r\n}\r\n\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = [];\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n cream[i] = 0;\r\n if (a[i] === 0) {\r\n continue;\r\n }\r\n var bottom = i - a[i] + 1;\r\n if (bottom < 0) {\r\n bottom = 0;\r\n }\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' ')); \r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n init();\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = [];\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n cream[i] = 0;\r\n if (a[i] === 0) {\r\n continue;\r\n }\r\n var bottom = i - a[i] + 1;\r\n if (bottom < 0) {\r\n bottom = 0;\r\n }\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' ')); \r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n fs.readFile(inTextName ? path.join(__dirname, inTextName) : 0, 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n const res = Array(n).fill(0)\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (arr[i] !== 0) {\r\n res[i] = 1\r\n if (arr[i - 1] < arr[i]) arr[i - 1] = arr[i] - 1\r\n }\r\n }\r\n console.log(res.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i][0], inputArr[i + 1])\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 2e5+1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = n - 1, mn = INF; i >= 0; i--) {\r\n\t\t\tmn = Math.min(mn, i - a[i] + 1);\r\n\t\t\tans[i] = i >= mn ? 1 : 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst st = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] == 0) {\r\n\t\t\t\tst.push(i);\r\n\t\t\t} else {\r\n\t\t\t\twhile (st.length && i - a[i] < st[st.length-1]) {\r\n\t\t\t\t\tst.pop();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n).fill(1);\r\n\t\twhile (st.length) {\r\n\t\t\tans[st.pop()] = 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const { EOL } = require('os');\r\n\r\nlet i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => main(i));\r\n\r\nfunction getAnswer(c) {\r\n const creams = c.reverse();\r\n let size = 0;\r\n for (let i = 0; i < creams.length; i++) {\r\n if (creams[i] > size) size = creams[i];\r\n creams[i] = size > 0 ? 1 : 0;\r\n size--;\r\n }\r\n return c.reverse().join(' ');\r\n}\r\n\r\nfunction main(param) {\r\n const input = param.split(EOL);\r\n const t = Number(input[0]);\r\n let index = 1;\r\n for (let i = 0; i < t; i++) {\r\n index++;\r\n const creams = input[index++].split(/\\s+/).map(Number);\r\n console.log(getAnswer(creams));\r\n }\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var temp = a[n - 1];\n var b = new Array(n);\n for(j = 0; j < n; j++){\n b[j] = 0;\n }\n for(j = n - 1; j >= 0; j--){\n if(temp !== 0 || a[j] !== 0){\n b[j] = 1;\n temp = Math.max(temp, a[j]);\n temp--;\n }else{\n temp = a[j];\n }\n }\n var ans = '';\n for(j = 0; j < n; j++){\n ans += b[j] + ' ';\n }\n console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var max = 0\r\n var ans = new Array(n).fill(0)\r\n for (let i = n; i >= 0; i--) {\r\n if (a[i] > 0 && a[i] > max-1) {\r\n max = a[i]\r\n ans[i] = 1\r\n max--\r\n continue\r\n }\r\n if (max > 0) {\r\n ans[i] = 1\r\n max--\r\n }\r\n\r\n\r\n }\r\n\r\n // if(n>=1) ans-=a[n-1]\r\n\r\n console.log(ans.join(' '))\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar queue = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tqueue.push(0);\r\n\t\t\tif(list[j] != 0){\r\n\t\t\t\tif(queue.length > list[j]){\r\n\t\t\t\t\tqueue[j - list[j] + 1] = list[j];\r\n\t\t\t\t}else{\r\n\t\t\t\t\tqueue[0] = queue.length;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tvar last = -1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(queue[j] != 0){\r\n\t\t\t\tlast = Math.max(last, queue[j]);\r\n\t\t\t}\r\n\t\t\tif(last > 0){\r\n\t\t\t\tqueue[j] = 1;\r\n\t\t\t\tlast--;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(queue, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "function solve() {\r\n var numPan = readline(\"\");\r\n var array = readline(\"\").split(\" \");\r\n \r\n array.reverse();\r\nvar ans = [];\r\nvar curNum = 0;\r\n for (var elm in array) {\r\n curNum = Math.max(array[elm], curNum);\r\n if (curNum) {\r\n ans.push(1);\r\n curNum--;\r\n } else {\r\n ans.push(0);\r\n }\r\n }\r\n\r\n for (var ab=ans.length-1;ab>=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n return \"hi\";\r\n}\r\n\r\n\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log(value) : print(value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = [];\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n if (!a[i]) {\r\n cream[i] = 0;\r\n continue;\r\n }\r\n var bottom = Math.max(0, i - a[i] + 1);\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log(value) : print(value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var cream = a.map(x => 0);\r\n var low = -1;\r\n var high = -1;\r\n for (var i = 0; i < n; i++) {\r\n if (!a[i]) {\r\n continue;\r\n }\r\n var bottom = Math.max(0, i - a[i] + 1);\r\n if (bottom > high) {\r\n low = bottom;\r\n high = i;\r\n for (var j = low; j <= high; j++) {\r\n cream[j] = 1;\r\n }\r\n continue;\r\n }\r\n if (bottom < low) {\r\n for (var j = bottom; j < low; j++) {\r\n cream[j] = 1;\r\n }\r\n low = bottom;\r\n }\r\n for (var j = high + 1; j <= i; j++) {\r\n cream[j] = 1;\r\n }\r\n high = i;\r\n }\r\n write(cream.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log(value) : print(value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n for (let i = n-1; i >= 0; i--) {\r\n let count = arr[i]\r\n if(count === 0) continue\r\n for (let j = 0; j < count; j++) {\r\n if ((i - j) < 0) break\r\n arr[i - j] = 1\r\n }\r\n i -= (count-1)\r\n }\r\n console.log(arr.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n solve(inputArr[i][0], inputArr[i + 1])\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n for (let i = n-1; i >= 0; i--) {\r\n let count = arr[i]\r\n for (let j = 0; j < count; j++) {\r\n if ((i - j) < 0) break\r\n arr[i - j] = 1\r\n }\r\n i -= count\r\n }\r\n console.log(arr.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n solve(inputArr[i][0], inputArr[i + 1])\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n const res = Array(n).fill(0)\r\n for (let i = n; i !== 0; i--) {\r\n for (let j = 0; j < arr[i]; j++) {\r\n res[i - j] = 1\r\n }\r\n }\r\n console.log(res.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n solve(inputArr[i][0], inputArr[i + 1])\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\r\n\t\tlet ans = Array(n).fill(0);\r\n\t\tfor (let i = n - 1, k = 0; i >= 0; i--) {\r\n\t\t\tk = Math.max(k, a[i]);\r\n\t\t\tif (k) { ans[i] = 1; k--; }\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n\r\n}\r\n\r\n"}, {"source_code": "function solve() {\r\n var numPan = readline(\"\");\r\n var array = readline(\"\").split(\" \");\r\n \r\n array.reverse();\r\nvar ans = [];\r\nvar curNum = 0;\r\n for (var elm in array) {\r\n curNum = Math.max(array[elm], curNum);\r\n if (curNum) {\r\n ans.push(1);\r\n curNum--;\r\n } else {\r\n ans.push(0);\r\n }\r\n }\r\n\r\n for (var ab=ans.length;ab>=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n return \"hi\";\r\n}\r\n\r\nfunction test() {\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n return \"hi\";\r\n}\r\n\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n return;\r\n}\r\n\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n}\r\n\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i=0;ab--) {\r\n print(ans[ab]);\r\n }\r\n}\r\n\r\nvar testCases = readline(\"\");\r\nfor (var i=0;i parseInt(x));\r\n var dt = pies, ndt;\r\n for(var i =pies-1;i>=0;i--)\r\n {\r\n if(cr[i])\r\n {\r\n if(cr[i] > i+1)\r\n {\r\n cr[i] = i+1;\r\n }\r\n if(dt > (i - cr[i]+1))\r\n {\r\n dt = i - cr[i] + 1;\r\n }\r\n }\r\n \r\n if(i>=dt)\r\n {\r\n cr[i]=1;\r\n }\r\n else\r\n {\r\n cr[i]=0\r\n }\r\n // print(dt)\r\n }\r\n print(cr);\r\n// var n = params[0];\r\n// var m = params[1];\r\n// var k = params[2];\r\n// var graph = [];\r\n// var vertLen = [];\r\n\r\n// print(vertLen);\r\n// for (var i = 0; i < m; i++) {\r\n// var verts = readline()\r\n// .split(\" \")\r\n// .map((x) => parseInt(x));\r\n// var a = verts[0];\r\n// var b = verts[1];\r\n// if (!graph[a]) {\r\n// graph[a] = [];\r\n// graph[a].fill(0);\r\n// vertLen[a] = 0;\r\n// }\r\n// if (!graph[b]) {\r\n// graph[b] = [];\r\n// graph[b].fill(0);\r\n// vertLen[b] = 0;\r\n// }\r\n// graph[a][b] = 1;\r\n// graph[b][a] = 1;\r\n// vertLen[a] += 1;\r\n// vertLen[b] += 1;\r\n// }\r\n\r\n// var vertToDel = [];\r\n\r\n// // print(vertLen);\r\n\r\n// var r = 0;\r\n// while (\r\n// vertLen.map((x, index) => {\r\n// if (x < k - 1 && x != -1) vertToDel.push(index);\r\n// }) &&\r\n// vertToDel.length > 0\r\n// ) {\r\n// r++;\r\n// // print(\"entered\", vertToDel, \"-\", vertLen);\r\n// for (var i = 0; i < vertToDel.length; i++) {\r\n// var vert = vertToDel[i];\r\n// graph.map((x, index) => {\r\n// if (x.length > 0) {\r\n// if (graph[index][vert] === 1) {\r\n// graph[index][vert] = 0;\r\n// vertLen[index] = vertLen[index] - 1;\r\n// }\r\n// }\r\n// });\r\n// graph[vert] = [];\r\n// vertLen[vert] = -1;\r\n// }\r\n// vertToDel = [];\r\n// }\r\n\r\n// var ind = 0;\r\n// graph.map((x, index) => {\r\n// if (x.length > 0) {\r\n// ind = index;\r\n// }\r\n// });\r\n\r\n// if(ind===0)\r\n// {\r\n// print('-1');\r\n// continue;\r\n// }\r\n// var subset = [];\r\n// var level1 = [ind];\r\n// var level2 = [];\r\n// subset = subset.concat(level1);\r\n\r\n// while (level1.length > 0) {\r\n// print(subset);\r\n// level1.forEach((x, index) => {\r\n// if (graph[x].length > 0) {\r\n// graph[x].map((x,index)=>{\r\n// if(x===1 && !subset.includes(index) && !level2.includes(index))\r\n// {\r\n// level2.push(index);\r\n// }\r\n// })\r\n// }\r\n// });\r\n// subset = subset.concat(level2);\r\n// level1= [].concat(level2);\r\n// level2 = [];\r\n// }\r\n// print(subset);\r\n}\r\n"}], "src_uid": "807c5ec37b0ea83ef40550698f1ff498"} {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const s = is.nextLine();\n const t = is.nextLine();\n\n const index = s.indexOf('*');\n if (index === -1 || n > m + 1) {\n console.log(s === t ? 'YES' : 'NO');\n } else {\n const left = s.substr(0, index);\n const right = s.substr(index + 1, s.length);\n let tReverse = t.slice();\n tReverse = tReverse.split('').reverse().slice(0, right.length).reverse().join('');\n if (left === t.substr(0, left.length) && right === tReverse) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n", "positive_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar str0 = \"\"\nvar str1 = \"\"\n\nvar c = 0;\nrl.on('line', function (line) {\n c += 1;\n if (c == 2) {\n str0 = line;\n }\n else if (c == 3) {\n str1 = line;\n rl.close();\n console.log(isOk() ? \"YES\" : \"NO\");\n }\n});\n\nfunction isOk() {\n if (str0.indexOf(\"*\") == -1) {\n if (str0!=str1) {return false}\n }\n var tCs = str0.split(\"\");\n var fCs = str1.split(\"\");\n var index = 0;\n var sBefore = \"\"; iStart = 0; iPos = 0; \n while (index < str0.length) {\n if (tCs[index]!=\"*\") {\n sBefore += tCs[index];\n }\n else { \n if (str1.indexOf(sBefore, iPos)!=iStart) {\n return false;\n }\n iPos = sBefore.length;\n sBefore = \"\";\n jIndex = index + 1;\n while (tCs[jIndex]!=\"*\" && jIndex < str0.length) {\n sBefore += tCs[jIndex];\n jIndex += 1;\n } \n iStart = str1.indexOf(sBefore, iPos); \n if (iStart==-1) {\n return false\n }\n index = jIndex - 1; \n if (index==str0.length-1) {\n if (!(str0[index]==\"*\" || str0[index]==fCs[str1.length-1])) { \n return false\n }\n }\n }\n index += 1;\n } \n return true;\n}\n"}, {"source_code": "readline();\nvar str = readline();\nvar a = str.split('*');\nvar b = readline();\nif (b.substring(0,a[0].length) === a[0] && ((a.length == 2)?(b.substring(b.length-a[1].length,b.length) === a[1]) && str.length-1<=b.length:str.length === b.length)){\n print('YES')\n}else{\n print('NO')\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar templateString = \"\"\nvar testString = \"\"\n\nvar c = 0;\nrl.on('line', function (line) {\n c += 1;\n if (c == 2) {\n templateString = line;\n }\n else if (c == 3) {\n testString = line;\n rl.close();\n console.log(isOk() ? \"yes\" : \"no\");\n }\n});\n\nfunction isOk() {\n if (templateString.indexOf(\"*\") == -1) {\n if (templateString!=testString) {return false}\n }\n var tCs = templateString.split(\"\");\n var fCs = testString.split(\"\");\n var index = 0;\n var sBefore = \"\"; iStart = 0; iPos = 0; \n while (index < templateString.length) {\n if (tCs[index]!=\"*\") {\n sBefore += tCs[index];\n }\n else { \n if (testString.indexOf(sBefore, iPos)!=iStart) {\n return false;\n }\n iPos = sBefore.length;\n sBefore = \"\";\n jIndex = index + 1;\n while (tCs[jIndex]!=\"*\" && jIndex < templateString.length) {\n sBefore += tCs[jIndex];\n jIndex += 1;\n } \n iStart = testString.indexOf(sBefore, iPos); \n if (iStart==-1) {\n return false\n }\n index = jIndex - 1; \n if (index==templateString.length-1) {\n if (!(templateString[index]==\"*\" || templateString[index]==fCs[testString.length-1])) { \n return false\n }\n }\n }\n index += 1;\n } \n return true;\n}\n"}, {"source_code": "var lengths = readline();\n\nvar length1 = parseInt(lengths.split(\" \")[0])\nvar length2 = parseInt(lengths.split(\" \")[1])\n\nvar string = readline();\nvar string1 = readline();\nvar p = false;\n\nprint(check());\n\nfunction check() {\n if (length1 >= length2 + 2) {\n return \"NO\";\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[i] === \"*\") {\n p = true;\n break;\n }\n if (string1[i] !== string[i]) {\n return \"NO\";\n }\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[length1-i] === \"*\") {\n p = true;\n break;\n }\n if (string1[length2-i] !== string[length1-i]) {\n return \"NO\";\n }\n }\n\n if (!p && length1 !== length2) {\n return \"NO\";\n }\n \n return \"YES\";\n}\n"}], "negative_code": [{"source_code": "readline();\nvar str = readline();\nvar a = str.split('*');\nvar b = readline();\nif (b.indexOf(a[0]) === 0 && ((a.length == 2)?(b.lastIndexOf(a[1])+a[1].length === b.length)&&str.length-1<=b.length:true)){\n print('YES')\n}else{\n print('NO')\n}"}, {"source_code": "var lengths = readline();\n\nvar length1 = parseInt(lengths.split(\" \")[0])\nvar length2 = parseInt(lengths.split(\" \")[1])\n\nvar string = readline();\nvar string1 = readline();\n\nprint(check());\n\nfunction check() {\n if (length1 > length2 + 2) {\n return \"NO\";\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[i] === \"*\") {\n break;\n }\n if (string1[i] !== string[i]) {\n return \"NO\";\n }\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[length1-i] === \"*\") {\n break;\n }\n if (string1[length2-i] !== string[length1-i]) {\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n"}, {"source_code": "var lengths = readline();\n\nvar length1 = parseInt(lengths.split(\" \")[0])\nvar length2 = parseInt(lengths.split(\" \")[1])\n\nvar string = readline();\nvar string1 = readline();\n\nprint(check());\n\nfunction check() {\n if (length1 >= length2 + 2) {\n return \"NO\";\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[i] === \"*\") {\n break;\n }\n if (string1[i] !== string[i]) {\n return \"NO\";\n }\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[length1-i] === \"*\") {\n break;\n }\n if (string1[length2-i] !== string[length1-i]) {\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n"}, {"source_code": "var lengths = readline();\n\nvar length1 = parseInt(lengths.split(\" \")[0])\nvar length2 = parseInt(lengths.split(\" \")[1])\n\nvar string = readline();\nvar string1 = readline();\n\nprint(check());\n\nfunction check() {\n if (length1 > length2 + 2) {\n return \"NO\";\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[i] === \"*\") {\n break;\n }\n if (string1[i] !== string[i]) {\n print(string1[i] + ' 2 ' + string[i])\n return \"NO\";\n }\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[length1-i] === \"*\") {\n break;\n }\n if (string1[length2-i] !== string[length1-i]) {\n print(string1[length2-i] + ' 4 ' + string[length1-i])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n"}, {"source_code": "var lengths = readline();\n\nvar length1 = parseInt(lengths.split(\" \")[0])\nvar length2 = parseInt(lengths.split(\" \")[1])\n\nvar string = readline();\nvar string1 = readline();\n\nprint(check());\n\nfunction check() {\n if (length1 > length2 + 2) {\n return \"NO\";\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[i] === \"*\") {\n break;\n }\n if (string1[i] !== string[i]) {\n print(string1[i] + ' 2 ' + string[i])\n return \"NO\";\n }\n }\n \n for (var i = 0; i < length1; i++) {\n if (string[length1-i] === \"*\") {\n break;\n }\n if (string1[length2-i] !== string[length1-i]) {\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const s = is.nextLine();\n const t = is.nextLine();\n\n const index = s.indexOf('*');\n if (index === -1) {\n console.log(s === t ? 'YES' : 'NO');\n } else {\n const left = s.substr(0, index);\n const right = s.substr(index + 1, s.length);\n let tReverse = t.slice();\n tReverse = tReverse.split('').reverse().slice(0, right.length).reverse().join('');\n if (left === t.substr(0, left.length) && right === tReverse) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar str0 = \"\"\nvar str1 = \"\"\n\nvar c = 0;\nrl.on('line', function (line) {\n c += 1;\n if (c == 2) {\n str0 = line;\n }\n else if (c == 3) {\n str1 = line;\n rl.close();\n console.log(isOk() ? \"YES\" : \"NO\");\n }\n});\n\nfunction isOk() {\n if (str0.indexOf(\"*\") == -1) {\n if (str0!=str1) {return false}\n }\n var tCs = str0.split(\"\");\n var fCs = str1.split(\"\");\n var index = 0;\n var sBefore = \"\"; iStart = 0; iPos = 0; \n while (index < str0.length) {\n if (tCs[index]!=\"*\") {\n sBefore += tCs[index];\n }\n else { \n if (str1.indexOf(sBefore, iPos)!=iStart) {\n return false;\n }\n iPos = sBefore.length;\n sBefore = \"\";\n jIndex = index + 1;\n while (tCs[jIndex]!=\"*\" && jIndex < str0.length) {\n sBefore += tCs[jIndex];\n jIndex += 1;\n } \n iStart = str1.indexOf(sBefore, iPos); \n if (iStart==-1) {\n return false\n }\n index = jIndex - 1; \n if (index==str0.length-1) {\n if (!(str0[index]==\"*\" || str0[index]==fCs[str1.length-1])) { \n return false\n }\n }\n }\n index += 1;\n }\n console.log(sBefore);\n \n return true;\n}\n"}], "src_uid": "d629d09782a7af0acc359173ac4b4f0a"} {"source_code": "/*\n * File Created: Monday, 30th November 2020 3:31:00 pm\n * Author: Lukas Rimkus\n */\n\n'use-strict'\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\ndata += chunk;\n});\n\nprocess.stdin.on('end', () =>{\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const n = data.shift();\n\n const res = a(n);\n\n console.log(res)\n }\n});\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n \nfunction readLine() { \n return data[currentLine++];\n}\n \n\nfunction a(num)\n{\n return num.length ;\n}\n\nmodule.exports = a;", "positive_code": [{"source_code": "\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet n = ia.shift().trim()\n\t\tlet x = n.length\n\t\tconsole.log(x)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "const solve = (n) => {\n console.log(n.length);\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0]);\n let i = 1;\n while (t > 0) {\n solve(input[i]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = readLine();\n console.log(n.length);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = next();\n\t\tvar count = N.length;\n\t\t/*if(N[N.length - 1] == \"0\"){\n\t\t\tcount++;\n\t\t}*/\n\t\tmyout(count);\n\t}\n}\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let i = 1;\n let t = 0;\n readline.on('line', line => {\n if (i == 1) {\n // number of test case\n t = parseInt(line) \n i++;\n } else if (i <= t) {\n solve(line)\n i++;\n } else {\n solve(line)\n readline.close()\n }\n });\n\n function solve(input) {\n console.log(input.length)\n }"}, {"source_code": "function run(sol) {\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n const {EOL} = require('os')\n const inputs = i.split(EOL)\n sol(inputs)\n })\n}\n\nfunction solution(inputs) {\n const t = Number(inputs[0])\n for (let i = 1; i <= t; ++i) {\n console.log(inputs[i].length)\n }\n\n}\n\nrun(solution)\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function f(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let s = io.readline()\n// \n// io.puts(s.length)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i)=>{\n var line = readline();\n console.log(line.length)\n })\n\n}\n\n"}, {"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let n = readline();\n print(n.length);\n}"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = readline();\n \n print(l.length);\n}\n"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var s = readline();\n print(s.length);\n}"}], "negative_code": [{"source_code": "\n\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet n = ia.shift()\n\t\tconsole.log(n.length)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "\n\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet n = ia.shift()\n\t\tlet x = n.length\n\t\tconsole.log(x)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "\n\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet n = ia.shift()\n\t\tconsole.log([...n].length)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "const solve = (n) => {\n console.log(n.length);\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n solve(input[i]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}], "src_uid": "ea011f93837fdf985f7eaa7a43e22cc8"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const inputs=+readline();\n\n for(let j = 0; j < inputs; j++) {\n const number_of_heroes = +readline();\n const heroes = readline().split(\" \");\n\n let number_of_values = [];\n heroes.forEach((item, i) => {\n if(+item !== Math.min(...heroes)) number_of_values.push(+item);\n });\n foo(number_of_values.length)\n }\n\n}\n\nconst foo = (x) => console.log(x);\n", "positive_code": [{"source_code": "//required remainder\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var a = lines[0];\n var lowest = 0;\n var answer = 0;\n for(var j = 1; j < (Number(a) + 1) * 2; j++){\n lowest = 0;\n answer = 0;\n if(j % 2 === 0){\n var n = lines[j].split(' ').map(Number).sort(function(a, b){return a - b});\n lowest = n[0];\n for(var k = 1; k < n.length; k++){\n if(lowest < n[k]){\n answer++;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var a = lines[0];\n var lowest = 0;\n var answer = 0;\n for(var j = 1; j < (Number(a) + 1) * 2; j++){\n lowest = 0;\n answer = 0;\n if(j % 2 === 0){\n var n = lines[j].split(' ').map(Number).sort(function(a, b){return a - b});\n lowest = n[0];\n for(var k = 1; k < n.length; k++){\n if(lowest < n[k]){\n answer++;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "function solve(input) {\r\n // YOUR BUGS HERE...\r\n res = [];\r\n input.forEach(e => {\r\n let a = e[1].split(' ').map(o => parseInt(o));\r\n let min_a = Math.min(...a);\r\n let res = a.filter(data => (data - min_a) > 0)\r\n console.log(res.length);\r\n });\r\n // console.log(res.join('\\n'));\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 2\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput === 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t === 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = 0;\r\n\t\tfor(var j = 0; j < N - 1; j++){\r\n\t\t\tif(list[j] < list[j + 1]){\r\n\t\t\t\toutput = N - (j + 1);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "/*\r\n * File Created: Tuesday, 16th February 2021 2:01:47 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n 'use-strict'\r\n \r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf8');\r\n \r\n let data = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', chunk => {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const l = parseInt(readLine());\r\n\r\n const an = readLine().split(' ').map(Number);\r\n \r\n const res = a(l, an);\r\n \r\n console.log(res)\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n\r\n function a(n,a){\r\n a.sort((a,b) => a - b);\r\n let count = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(i === n - 1) break;\r\n if(a[i] !== a[i+1]){\r\n return n - i - 1;\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\nmodule.exports = a;"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n2\r\n3 7\r\n24 25 27\r\n10 7\r\n51 52 53 54 55 56 57 58 59 60\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r min) {\r\n //console.log(a[i], max);\r\n count++;\r\n }\r\n }\r\n\r\n console.log(count);\r\n\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = parseInt(readline())\r\n\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var min = a[0]\r\n for (var i = 0; i < n; i++) {\r\n if (a[i] < min) {\r\n min = a[i]\r\n }\r\n }\r\n var res = n\r\n for (var i = 0; i < n; i++) {\r\n if(a[i] === min) res--\r\n }\r\n console.log(res)\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n a = readline().split(' ').sort((a,b) => a-b),\r\n winners = a.filter((hero)=>{\r\n return hero!= a[0];\r\n });\r\n print(winners.length);\r\n }"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n a = readline().split(' ').sort((a,b) => a-b),\r\n winnrers = a.filter((hero)=>{\r\n return hero!= a[0];\r\n });\r\n print(winnrers.length);\r\n }"}, {"source_code": "var tests = +readline();\nwhile(tests>0){\n var arrLen = +readline();\n var arr = readline().split(\" \").map(x=> parseInt(x));\n arr.sort((a,b)=>a-b);\n\n var i=0;\n var res = 0;\n\n while(i {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 1;\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels[i] == min) {\r\n minCount++;\r\n }\r\n }\r\n return arrLevels.length - minCount;\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 0;\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels[i] == min) {\r\n minCount++;\r\n }\r\n }\r\n return arrLevels.length - minCount;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 1;\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels == min) {\r\n minCount++;\r\n }\r\n }\r\n return arrLevels.length - minCount;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 0;\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels == min) {\r\n minCount++;\r\n }\r\n }\r\n return arrLevels.length - minCount;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 0;\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels) {\r\n minCount++;\r\n }\r\n }\r\n return arrLevels.length - minCount;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let minCount = 0;\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n minCount = 1;\r\n }\r\n else if (arrLevels) {\r\n minCount++;\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - minCount;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = readline();\r\n let arrLevel = readline().split(\" \").map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - 1;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split().map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n console.log(arrLevels);\r\n let min = arrLevels[0];\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - 1;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let arrLevel = readline().split().map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - 1;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arrLevel = readline().split().map(string => { return parseInt(string) });\r\n console.log(getWinners(arrLevel));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - 1;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let arrLevels = [];\r\n let testCases = +(readline());\r\n for (let i = 0; i < testCases.length; i++) {\r\n readline();\r\n arrLevels.push(readline().split(\" \").map(string => { return parseInt(string) }));\r\n }\r\n for (let i = 0; i < arrLevels.length; i++) {\r\n console.log(getWinners(arrLevels[i]));\r\n }\r\n}\r\nfunction getWinners(arrLevels) {\r\n let min = arrLevels[0];\r\n let max = arrLevels[0];\r\n\r\n for (let i = 1; i < arrLevels.length; i++) {\r\n if (arrLevels[i] < min) {\r\n min = arrLevels[i];\r\n }\r\n if (arrLevels[i] > max) {\r\n max = arrLevels[i];\r\n }\r\n }\r\n return (max === min) ? 0 : arrLevels.length - 1;\r\n}"}, {"source_code": "//required remainder\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var a = lines[0];\n var lowest = 0;\n var answer = 0;\n for(var j = 1; j < (Number(a) + 1) * 2; j++){\n lowest = 0;\n answer = 0;\n if(j % 2 === 0){\n var n = lines[j].split(' ').sort(function(a, b){return a - b});\n lowest = n[0];\n for(var k = 1; k < n.length; k++){\n if(lowest < n[k]){\n answer++;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "//required remainder\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var a = lines[0];\n var lowest = 0;\n var answer = 0;\n for(var j = 1; j < (Number(a) + 1) * 2; j++){\n lowest = 0;\n answer = 0;\n if(j % 2 === 0){\n var n = lines[j].split(' ').sort(function(a, b){return a - b});\n lowest = n[0];\n for(var k = 1; k < n.length + 1; k++){\n if(lowest < n[k]){\n answer++;\n }else{\n continue;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "//required remainder\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var a = lines[0];\n var lowest = 0;\n var answer = 0;\n for(var j = 1; j < (Number(a) + 1) * 2; j++){\n lowest = 0;\n answer = 0;\n if(j % 2 === 0){\n var n = lines[j].split(' ').sort(function(a, b){return a - b});\n lowest = n[0];\n for(var k = 1; k < n.length + 1; k++){\n if(lowest < n[k]){\n answer++;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var k = lines[0];\n var answer = '';\n var a = 0;\n var b = 0;\n for(var j = 1; j < Number(k) + 1; j++){\n var n = lines[j];\n a = 0;\n b = 0;\n answer = '';\n if(n % 4 !== 0){\n console.log('NO');\n }else{\n console.log('YES');\n for(i = 2; i <= n; i += 2){\n answer += i + ' ';\n a += i;\n }\n for(i = 1; i < n - 2; i += 2){\n answer += i + ' ';\n b += i;\n }\n console.log(answer + (a-b));\n }\n }\n});"}, {"source_code": "function solve(input) {\r\n // YOUR BUGS HERE...\r\n res = [];\r\n input.forEach(e => {\r\n let a = e[1].split(' ').map(o => parseInt(o));\r\n a.sort();\r\n let res = a.filter(data => (data - a[0]) > 0)\r\n console.log(res.length);\r\n });\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n return 2\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}], "src_uid": "99e5c907b623c310d6f1599f485ca21d"} {"source_code": "const getInversionsCount = (nums) => {\n var count = 0;\n\n for (var i = 1; i < nums.length; i++) {\n for (var j = 0; j < i; j++) {\n if (nums[i] < nums[j]) {\n count++;\n }\n }\n }\n\n return count;\n};\n\nconst main = () => {\n readline();\n\n const nums = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n var operationsCount = getInversionsCount(nums);\n\n const inputCount = Number(readline());\n\n for (var i = 0; i < inputCount; i++) {\n var input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n operationsCount += Math.floor((input[1] - input[0] + 1) / 2);\n\n if (operationsCount % 2 === 0) {\n print(\"even\");\n } else {\n print(\"odd\");\n }\n }\n};\n\nmain();", "positive_code": [{"source_code": "// https://en.wikipedia.org/wiki/Parity_of_a_permutation\nvar line = readline ();\nline = line.trim ().split ( ' ' );\nvar n = line;\nvar aa = [ ];\nline = readline ();\naa = line.trim ().split ( ' ' );\nvar i, j, cnt = 0;\nvar a = aa;\na.map ( function ( a ) { return (+ a); } ); // convert array elements to numbers\nfunction merge ( a, b ) {\n var i = 0, j = 0;\n var result = [ ];\n while ( i < a.length && j < b.length ) {\n if ( (+ a [ i ]) < (+ b [ j ]) ) {\n result.push ( a [ i ++ ] );\n } else {\n result.push ( b [ j ++ ] );\n cnt += a.length - i;\n }\n }\n while ( i < a.length ) {\n result.push ( a [ i ++ ] );\n }\n while ( j < b.length ) {\n result.push ( b [ j ++ ] );\n cnt += a.length - i;\n }\n return result;\n}\nfunction mergesort ( arr ) {\n var suba = [ ], subb = [ ];\n if ( arr.length > 1 ) {\n suba = mergesort ( arr.slice ( 0, Math.floor ( arr.length / 2 ) ) );\n subb = mergesort ( arr.slice ( Math.floor ( arr.length / 2 ), arr.length ) );\n return merge ( suba, subb ); \n } \n return arr;\n}\nmergesort ( a );\nvar parity = cnt % 2;\nvar m = (+ readline ());\nvar l, r;\nfor ( var g = 0; g < m; g ++ ) {\n line = readline ();\n line = line.trim ().split ( ' ' );\n l = line [ 0 ];\n r = line [ 1 ];\n if ( Math.ceil ( (r - l) / 2) % 2 == 1 ) parity ^= 1; \n print ( parity ? 'odd' : 'even' );\n}\n"}], "negative_code": [{"source_code": "// https://en.wikipedia.org/wiki/Parity_of_a_permutation\nvar line = readline ();\nline = line.trim ().split ( ' ' );\nvar n = line;\nvar aa = [ ];\nline = readline ();\naa = line.trim ().split ( ' ' );\nvar i, j, cnt = 0;\nfor ( i = 0; i < n - 1; i ++ ) \n for ( j = i + 1; j < n; j ++ ) \n if ( aa [ i ] > aa [ j ] ) cnt ++;\nvar parity = cnt % 2;\nvar m = (+ readline ());\nvar l, r;\nfor ( var g = 0; g < m; g ++ ) {\n line = readline ();\n line = line.trim ().split ( ' ' );\n l = line [ 0 ];\n r = line [ 1 ];\n if ( Math.ceil ( (r - l) / 2) % 2 == 1 ) parity ^= 1; \n print ( parity ? 'odd' : 'even' );\n}\n"}], "src_uid": "d20cc952cdf3a99e7d980a0270c49f78"} {"source_code": " var n = readline().split(\" \");var load = readline().split(\" \");\n var max = 0;\nfor(var i=0;i(+n[1]) ? max+=2 : max+=1;\nprint(max)", "positive_code": [{"source_code": "var g = readline();\ng = g.split(\" \");\nvar y = readline();\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar j = n;\nfor(i=0;i h){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var H = readline().split(' ').map(x=>parseInt(x))[1]\nvar ar = readline().split(' ').map(x=>parseInt(x))\nprint( ar.length + ar.filter(h=>(h>H)).length )\n"}, {"source_code": "// parameter \"input\" gets all data\nfunction Main() {\n\t// the first line is assigned to input[0], the second line is assigned to input[1] similarly.\t\n\tinput = readline().split(\" \").map(function(x) { return parseInt(x); });\n\ta = readline().split(\" \").map(function(x) { return parseInt(x); });\n\tconst n = input[0];\n\tconst h = input[1];\n\tconst ans = a.reduce((cum,x)=>cum+(x>h?2:1),0);\n\tprint(ans);\n\t\n}\n \nMain()"}, {"source_code": "'use strict';\nconst data = readline().split(' ').map(value => parseInt(value)),\n n = data[0],\n h = data[1],\n array = readline().split(' ').map(value => parseInt(value)); \nlet res = n; \n\nfor (let i = 0; i < n; i++) {\n if (array[i] > h) {\n res++;\n }\n}\n\nwrite(res); "}, {"source_code": "var nh = readline().split(' ');\nvar n = parseInt(nh[0]);\nvar h = parseInt(nh[1]); \nvar a = readline().split(' ');\nvar need = 0;\nfor (var i = 0; i < a.length; i++) {\n if (a[i] <= h) {\n need++;\n } else {\n need+=2;\n }\n}\nprint (need)"}, {"source_code": "var x = readline().split(\" \");\nvar rost = readline().split(\" \");\nvar res = 0;\n\tfor (var i=0; i+x[1]? res=+res+2:res++\n\t}\nprint(res);"}, {"source_code": "var line1 = readline().split(' ').map(function (x) { return parseInt(x); })\nvar line2 = readline().split(' ').map(function (x) { return parseInt(x); })\nvar h = line1[1]\nvar result = 0\nline2.forEach(x => {\n x < h ? result++: result += Math.ceil(x/h)\n})\nprint(result)"}, {"source_code": "var sol = function(arr1, arr2){\n number = arr2.length;\n for(var i=0; i arr1[1]){\n number ++;\n }\n }\n print(number);\n}\n\nvar numbers1 = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar numbers2 = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nsol(numbers1, numbers2);"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar numberOfFriends = input[0];\nvar fenceHight = input[1];\n\nvar friends = readline().split(' ').map(Number);\nvar roadWidth = 0;\n\nfor(var i = 0; i < friends.length; i++){\n if(friends[i] > fenceHight){\n roadWidth += 2;\n }\n else {\n roadWidth ++;\n }\n}\nprint(roadWidth);"}, {"source_code": "var h = readline().split(\" \").map(function(x) { return parseInt(x); })[1];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar w = 0;\nfor (var i = 0; i < a.length; i++) {\n w+=(a[i] > h) ? 2 : 1;\n}\nprint (w);"}, {"source_code": "var n_H= readline().split(' ');\nvar a=readline().split(' ');\nvar width=0;\nn_H[1]=parseInt(n_H[1]);\nfor(i=0;in_H[1])\n width+=2;\n else\n width+=1;\n\n}\n\nprint(width);"}, {"source_code": "var nh = readline().split(\" \");\n var a = readline().split(\" \");\n var width = 0;\n for(var i = 0; i < Number(nh[0]); i++)\n {\n if(a[i] > Number(nh[1]))\n {\n width += 2;\n }\n else\n {\n width += 1;\n }\n }\n print(width);"}, {"source_code": "var inp = readline().split(' ').map(el => parseInt(el, 10));\nvar width = 0;\nvar a = readline().split(' ').forEach(el => {\n el = parseInt(el, 10);\n if(el>inp[1]) width+=2;\n else width++;\n});\n\nprint(width);"}, {"source_code": "var line1 = readline().split(' ');\nvar n = parseInt(line1[0]);\nvar h = parseInt(line1[1]);\nvar numbers = readline().split(' ');\nfor (var i = 0; i < numbers.length; ++i)\n\tnumbers[i] = parseInt(numbers[i]);\n\nresult = 0;\n\nfor (var i = 0; i < numbers.length; ++i)\n\tresult += numbers[i] <= h ? 1 : 2;\n\nprint(result);\n"}, {"source_code": "var x= readline().split(' ');\nvar n = x[0];\nvar h = x[1];\nvar a = readline().split(\" \").map(Number);\nvar s = 0;\nfor(var i = 0; ih){\n s++;\n }\n}\nwrite(s);"}, {"source_code": "\"use strict\";\n\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar h = input[1];\nvar a = readline().split(' ').map(value => +value);\n\nwrite(a.map(a => a <= h ? 1 : 2).reduce((a, b) => a + b));"}, {"source_code": "X=readline().split(' ').map(Number)\nn=X[0],h=X[1]\nX=readline().split(' ').map(Number)\nprint(X.reduce((a,c) => a + (c<=h ? 1 : 2), 0))\n\n"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '3 7';\n// case 2: return '4 5 14';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nvar list = readline().split(' ');\n\nvar n = parseInt(list[0]);\nvar h = parseInt(list[1]);\n\nvar a = readline().split(' ').map(function(currentValue) {\n return parseInt(currentValue);\n});\n\nvar s = 0;\n\na.forEach(function(currentValue) {\n s += currentValue > h ? 2 : 1;\n});\n\nwrite(s);\n"}, {"source_code": "var firstLine = readline().split(' ');\nvar number = firstLine[0];\nvar height = firstLine[1];\nvar heights = readline().split(' ').map(Number);\nvar width = 0;\nfor(var i = 0; i < number; i++){\n width++;\n if(heights[i] > height){\n width++;\n }\n}\nwrite(width);"}, {"source_code": "var input1 = readline().split(\" \");\nvar noOfFriends = +input1[0];\nvar highOfFence = +input1[1];\n\nvar hightOfFriends = readline().split(\" \");\n\nvar totalWidth = 0;\n\nfor (var i = 0; i < noOfFriends; i++) {\n if (hightOfFriends[i] <= highOfFence) {\n totalWidth += 1;\n } else {\n totalWidth += 2;\n }\n}\nprint(totalWidth);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; ++i){\n if(+friendsList[i] > +h) counter+=2;\n else counter+=1;\n}\nprint(counter);"}, {"source_code": "var inp_line1 = readline();\nvar inp_line2 = readline();\n \n \n \nvar inp_line1_arr = inp_line1.split(\" \");\nvar inp_line2_arr = inp_line2.split(\" \");\n \nvar min_width = 0;\n \nfor (var i=0; i<=inp_line1_arr[0] - 1 ; i++){\n if (parseInt(inp_line2_arr[i]) <= parseInt(inp_line1_arr[1])) {\n min_width = min_width + 1;\n } else {\n min_width = min_width + 2;\n }\n}\n \nwrite(min_width);\n"}, {"source_code": "var X= readline().split(' ').map(Number)\nvar total=X[0],h=X[1]\nX=readline().split(' ').map(Number)\nprint (X.reduce((a,c) => a + (c<=h ? 1 : 2), 0))"}, {"source_code": "var row = readline().split(\" \").map(x => parseInt(x));\nvar friends = row[0];\nvar height = row[1];\n \nvar individualHeight = readline().split(\" \").map(x => parseInt(x));\n \nvar sum = 0;\n \nfor (var i = 0; i < individualHeight.length; i++) {\n if (individualHeight[i] > height) {\n sum += 2;\n } else {\n sum += 1;\n }\n}\n \n print(sum);"}, {"source_code": "var n_H= readline().split(' ');\nvar a=readline().split(' ');\nvar width=0;\nn_H[1]=parseInt(n_H[1]);\n for(i=0;in_H[1])\n width+=2\n else\n width+=1\n }\nprint(width)"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar arr1=readline().split(' ').map((a)=>{ return parseInt(a)});\nvar arr=readline().split(' ').map((a)=>{ return parseInt(a)});\nvar count=0;\nfor(var i=0;iarr1[1]){\n count++;\n }\n count++;\n}\n\nprint(count);\n"}, {"source_code": "var input = readline().split(\" \").map(Number), n = input[0], h = input[1], a = readline().split(\" \").map(Number);\n\nvar ans = 0;\nfor(var i = 0; i < n; ++i){\n ans++;\n if(a[i] > h){\n ans++;\n }\n}\n\nwrite(ans);"}, {"source_code": "const readline = require(\"readline\");\n\nlet inputs = [];\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on(\"line\", line => inputs.push(line));\n\nrl.on(\"close\", () => console.log(solution(inputs)));\n\nfunction solution(data) {\n const xs = data.flatMap(x => x.split(\" \"));\n [n, h, ...friendsHeight] = xs;\n return friendsHeight.reduce((width, fh) => {\n return parseInt(fh) > h\n ? width + 2\n : width + 1\n }, 0);\n};\n"}, {"source_code": "var input1 = readline().split(\" \").map(x=>parseInt(x));\nvar n = input1[0];\nvar h = input1[1];\nvar heights = []\nheights = readline().split(\" \").map(x => parseInt(x));\n \n \nfunction performTask(n, h, heights) {\n return heights.reduce((width, height) => {\n return width + (height > h ? 2 : 1);\n }, 0)\n}\n \nconst output = performTask(n, h, heights);\nprint(output);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n\n let numFriends, fenceHeight;\n\n rl.on('line', n => {\n if (!numFriends && !fenceHeight) {\n n = n.split(' ').map(Number);\n numFriends = n[0];\n fenceHeight = n[1];\n } else {\n const width = n.split(' ').map(Number).reduce((acc, curr) => {\n return curr > fenceHeight ? acc + 2 : acc + 1;\n }, 0);\n console.log(width);\n rl.close();\n }\n });\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numFriends, fenceHeight;\n\nrl.on('line', n => {\n if (!numFriends && !fenceHeight) {\n n = n.split(' ').map(Number);\n numFriends = n[0];\n fenceHeight = n[1];\n } else {\n const width = n.split(' ').map(Number).reduce((acc, curr) => {\n return curr > fenceHeight ? acc + 2 : acc + 1;\n }, 0);\n console.log(width);\n rl.close();\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const line1 = readline().split(' '), line2 = readline().split(' ')\n\n let h = parseInt(line1[1]),widthOfRoad = 0;\n\n for (let heightOfPerson of line2){\n heightOfPerson = parseInt(heightOfPerson)\n widthOfRoad += (heightOfPerson > h) ? 2 : 1;\n }\n\n console.log(widthOfRoad)\n}\n\n\n"}, {"source_code": "x = readline().split(' ').map(Number);n=x[0];h=x[1];\nprint(n + readline().split(' ').map(Number).filter(i => i > h).length);\n"}, {"source_code": "var all, fh, lines, mainAux, print, readline, rl, rli, sum, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nsum = function(items) {\n return items.reduce(function(a, b) {\n return a + b;\n });\n};\n\nall = function(items) {\n var i, item, len;\n for (i = 0, len = items.length; i < len; i++) {\n item = items[i];\n if (!item) {\n return false;\n }\n }\n return true;\n};\n\nfh = function(n, f, hs) {\n var h;\n return sum((function() {\n var i, len, results;\n results = [];\n for (i = 0, len = hs.length; i < len; i++) {\n h = hs[i];\n if (h > f) {\n results.push(2);\n } else {\n results.push(1);\n }\n }\n return results;\n })());\n};\n\nmainAux = function() {\n var f, hs, n;\n [n, f] = readline().split(' ').map(function(n) {\n return parseInt(n);\n });\n hs = readline().split(' ').map(function(n) {\n return parseInt(n);\n });\n return print(fh(n, f, hs));\n};\n\n\n function main() {\n return mainAux();\n }\n;\n"}, {"source_code": "var lines, mainAux, minwidth, print, readline, rl, rli, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nminwidth = function(n, f, hs) {\n return hs.reduce(function(acc, h) {\n if (h > f) {\n return acc + 2;\n } else {\n return acc + 1;\n }\n }, 0);\n};\n\nmainAux = function() {\n var f, hs, n;\n [n, f] = readline().split(' ');\n hs = readline().split(' ').map(function(v) {\n return parseInt(v);\n });\n return print(minwidth(n, f, hs));\n};\n\n\n function main() {\n return mainAux();\n }\n;\n\n//# sourceMappingURL=wall-height.js.map\n"}, {"source_code": "function main() {\n // write code here:\n for(let i=0;i<2;i++){\n stdin[i]=stdin[i].split(' ').map(Number);\n }\n var arr1=stdin[0];\n var arr2=stdin[1];\n const n=arr1[0];\n const h=arr1[1];\n var minWidth=0;\n for(let j=0;jh){\n minWidth+=2;\n }else{\n minWidth+=1;\n }\n }\n console.log(minWidth);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "x = readline().split(' ').map(Number);\nprint(readline().split(' ').map(Number).reduce((res, i) => res + (i > x[1]), x[0]));\n"}, {"source_code": "var num1=readline().split(\" \").map(x=>parseInt(x));\nvar n =num1[0];\nvar h =num1[1];\n\nvar num2=readline().split(\" \").map(x=>parseInt(x));\nvar width = 0;\nfor(var i=0 ; ih){\n width++;\n }\n width++;\n}\n\nprint(width);"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet roadWidth = 0;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n let arrayofHeights = input.split(\" \").map((element)=>{\n return element*1\n })\n arrayofHeights.forEach(element => {\n if(element>fenceHeight)\n roadWidth+=2\n else \n roadWidth++\n });\n console.log(roadWidth)\n rl.close();\n // if (element > fenceHeight){\n\n\n // roadWidth+=2\n // console.log(\"First Condition \")\n // }\n // else{\n // roadWidth++\n // console.log(\"Second Condition \")\n // }\n \n } \n \n});"}, {"source_code": "n = readline().split(\" \")\nfr = readline().split(\" \")\nvar counter = 0\nfor (i=0 ; in[1]){\n counter++\n }\n}\nprint(counter+Number(n[0]))\n"}, {"source_code": "m=readline()\ny=m.split(' ')[0]\nz=parseInt(m.split(' ')[1])\nx=readline().split(' ')\nsum=0;\nfor(i=0;iz)\n sum=sum+2;\nelse\n sum=sum+1;\n }\nprint(sum)"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline().split(\" \");\n \n const x2 = readline().split(\" \").map(x=>+x);\n vanyaAndFence(x[0],x[1],x2);\n }\n \nfunction vanyaAndFence(n, h, guys) {\n console.log(guys.reduce((prev, curr) => (curr > h ? prev + 2 : prev + 1), 0));\n\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n var N = one[0];\n var H = one[1];\n var list = nextIntArray();\n var output = 0;\n for(var i = 0; i < N; i++){\n if(list[i] > H){\n output += 2;\n }else{\n output++;\n }\n }\n myout(output);\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet h = 0,\n lineCounter = 0;\n\nlet hArr = [];\n\nrl.on('line', (input) => {\n let line;\n if (lineCounter === 0) {\n line = input.split(' ');\n h = parseInt(line[1]);\n lineCounter++;\n } else {\n line = input.split(' ');\n line.forEach(element => {\n hArr.push(parseInt(element));\n });\n rl.close();\n console.log(solve(h, hArr));\n }\n});\n\n\nconst solve = (h, hArr) => {\n let sum = 0;\n hArr.forEach(element => {\n sum = (element > h) ? sum + 2 : sum + 1;\n });\n return sum;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const [, h] = readline().split(' ').map(x => parseInt(x));\n const a = readline().split(' ').map(x => parseInt(x));\n\n // solve\n const w = a.map(x => x > h ? 2 : 1).reduce((m, n) => m + n, 0);\n\n // output\n print(w);\n}"}, {"source_code": "var line1 = readline().split(\" \");\nvar n = parseInt(line1[0]);\nvar h = parseInt(line1[1]);\n\nvar roadWidth = 0;\n\nvar heights = readline().split(\" \");\n\nfor (var i = 0; i < n; i++) {\n \n if (parseInt(heights[i]) > h) {\n roadWidth += 2;\n } else {\n roadWidth++;\n }\n \n}\n\nprint(roadWidth);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet counter = 0;\nlet n, k;\n\nrl.on('line', (d) => {\n if (counter === 0) {\n counter++;\n [n, k] = d.split(' ').map(Number);\n return;\n }\n\n let f = d.split(' ').map(Number);\n let ans = n;\n\n for (let i = 0; i < f.length; i++) {\n ans += f[i] > k;\n }\n\n console.log(ans);\n\n counter++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet counter = 0;\nlet n, k;\n\nrl.on('line', (d) => {\n if (counter === 0) {\n counter++;\n [n, k] = d.split(' ').map(Number);\n return;\n }\n\n let f = d.split(' ').map(Number);\n let ans = 0;\n\n for (let i = 0; i < f.length; i++) {\n if (f[i] > k) {\n ans += 2;\n }\n else {\n ans += 1;\n }\n }\n\n console.log(ans);\n\n counter++;\n});\n"}, {"source_code": "/**\n * \nVanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of \neach of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. \nThe height of the i-th person is equal to ai.\n\nConsider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other\n while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended\n by the guard?\n\nInput\nThe first line of the input contains two integers n and h (1\u2009\u2264\u2009n\u2009\u2264\u20091000, 1\u2009\u2264\u2009h\u2009\u2264\u20091000) \u2014 the number of friends and the height of the fence, respectively.\n\nThe second line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u20092h), the i-th of them is equal to the height of the i-th person.\n\nOutput\nPrint a single integer \u2014 the minimum possible valid width of the road.\n\nExamples\ninput\n3 7\n4 5 14\noutput\n4\ninput\n6 1\n1 1 1 1 1 1\noutput\n6\ninput\n6 5\n7 6 8 9 10 5\noutput\n11\nNote\nIn the first sample, only person number 3 must bend down, so the required width is equal to 1\u2009+\u20091\u2009+\u20092\u2009=\u20094.\n\nIn the second sample, all friends are short enough and no one has to bend, so the width 1\u2009+\u20091\u2009+\u20091\u2009+\u20091\u2009+\u20091\u2009+\u20091\u2009=\u20096 is enough.\n\nIn the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2\u2009+\u20092\u2009+\u20092\u2009+\u20092\u2009+\u20092\u2009+\u20091\u2009=\u200911.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfPersons = Number(inputString[0].split(\" \")[0])\n let heigtOfWall = Number(inputString[0].split(\" \")[1]);\n let heigtOfPersons = inputString[1].split(\" \")\n\n solution(numberOfPersons, heigtOfWall, heigtOfPersons);\n\n});\n\n\nfunction solution(numberOfPersons, heigtOfWall, heigtOfPersons) {\n\n let widthOfRoad = numberOfPersons;\n\n for (let index = 0; index < numberOfPersons; index++) {\n\n if (Number(heigtOfPersons[index]) > heigtOfWall)\n widthOfRoad++;\n\n }\n\n console.log(widthOfRoad);\n\n}"}, {"source_code": "var num = readline().split(' ').map(Number);\n\tvar str = readline().split(' ').map(function(elem) {\n\t\treturn parseInt(elem);\n\t});\n\tvar n = num[0];\n\tvar h = num[1];\n\tvar sum = n;\n\tfor(var i = 0; i < str.length; i++)\n\t{\n\t\tif(str[i] > h){\n\t\t\tsum += 1;\n\t\t}\n\t}\n\tprint(sum);"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const arr1 = readline().split(\" \");\n let numberOfPersons = +arr1[0];\n let height = +arr1[1];\n let personsHeight = readline().split(\" \");\n\n let total = 0;\n\n for (let i = 0; i < numberOfPersons; i++) {\n if (personsHeight[i] <= height) {\n total++;\n }\n else {\n total += 2;\n }\n }\n console.log(total);\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let answer = 0;\n let [n, h] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.forEach(i => {\n if (i > h) answer += 2;\n else answer += 1;\n });\n console.log(answer);\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nvar firstLine = 0\nvar h, n, a\nrl.on(\"line\", (w)=>{\n\tif(firstLine === 0){\n\t\tvar r = w.split(\" \")\n\t\tn = r[0]\n\t\th = r[1]\n\t\tfirstLine++\n\t\treturn\n\t}\n\t\n\ta = w.split(\" \")\n\n\tvar width = n\n\n\tfor(var i = 0; i < a.length; i++){\n\t\tif(parseInt(a[i]) > parseInt(h)){\n\t\t\twidth++\n\t\t}\n\t}\n\n\n\n\tconsole.log(width)\t\t\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface(process.stdin, process.stdout);\n\nrl.setPrompt('');\nrl.prompt();\nlet promptCounter = 0\n\nlet n, h;\n\nrl.on('line', function (line) {\n promptCounter++;\n //first line\n if (promptCounter === 1) {\n [n, h] = line.split(' ').map(x => Number(x));\n rl.prompt();\n } else {\n let rowWidth = line.split(' ').map(x => Number(x)).map(x => {\n if (x > h) return 2;\n else return 1;\n }).reduce((p, c) => p + c);\n console.log(rowWidth);\n rl.close()\n }\n});"}, {"source_code": "var input = readline().split(\" \")\nvar people = readline().split(\" \").map(Number);\nvar roadWidth = 0\n \nfor (var i = 0; i < input[0]; i++) {\n if (people[i] > input[1]) {\n roadWidth += 2\n } else {\n roadWidth += 1\n }\n}\n \nprint(roadWidth)"}, {"source_code": "var line1 = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\nvar n = line1[0]; // to store values in different variables. \nvar h = line1[1];\n\n \nvar line2 = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n\n\n \nvar result = 0; \nfor(var i =0; i < n; i++) {\n result += line2[i] <= h ? 1 : 2;\n}\nprint(result)"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function (firstLine) {\n // rl.write('hello\\n')\n let [n, h] = firstLine.split(' ').map(x => Number(x))\n rl.setPrompt('');\n rl.prompt();\n rl.on('line', function (lengths) {\n let arr = lengths.split(' ').map(x => Number(x));\n let rowLength = arr.map(x => {\n if (x > h) return 2;\n else return 1;\n }).reduce((p, c) => p + c)\n // rl.write(String(rowLength));\n console.log(rowLength);\n rl.close();\n })\n});"}, {"source_code": "function Input() {\n var heightOfFence;\n readline().split(' ').forEach(function (element) {\n heightOfFence = parseInt(element);\n });\n\n const listFriends = readline().split(' ').map(function (element) {\n return parseInt(element);\n });\n\n return {\n heightOfFence: heightOfFence,\n listFriends: listFriends\n };\n}\n\nfunction PossibleWidth(data) {\n var possibleWidth = 0;\n data.listFriends.forEach(function (element) {\n ++possibleWidth;\n if (element > data.heightOfFence) {\n ++possibleWidth;\n }\n });\n return possibleWidth;\n}\n\nvar data = Input();\nprint(PossibleWidth(data));"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n // if(Array.isArray(inputString)) inputString = inputString.join('\\n');\n inputString += inputStdin;\n // inputString = inputString.trim().split('\\n').map(string => {\n // return string.trim();\n // });\n \n // main(); \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let [n, h] = readAsIntList();\n let list = readAsIntList();\n console.log(list.map(a => a > h ? 2 : 1).reduce((acc,v) => acc+v,0));\n}\n \n\n\n"}, {"source_code": "let rl = require(\"readline\");\n\nlet prompts = rl.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nlet noOfFriends;\nlet highOfFence;\n\nprompts.question(\"\", function (input) {\n let input1 = input.split(\" \");\n noOfFriends = +input1[0];\n highOfFence = +input1[1];\n prompts.question(\"\", function (hightOfFriends) {\n hightOfFriends = hightOfFriends.split(\" \");\n let totalWidth = 0;\n for (let i = 0; i < noOfFriends; i++) {\n if (hightOfFriends[i] <= highOfFence) {\n totalWidth += 1;\n } else {\n totalWidth += 2;\n }\n }\n console.log(totalWidth);\n process.exit();\n });\n});\n"}, {"source_code": "/**\n * @author Sunwarul\n * Software Developer \n*/ \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => {\n return str.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\tconst [n, h] = readLine().split(' ').map(Number);\n\tconst friends = readLine().split(' ').map(Number);\n\tlet totalNeeded = 0;\n\tfor(let i in friends) {\n\t\tif(friends[i] > h) {\n\t\t\ttotalNeeded = totalNeeded + 2;\n\t\t} else {\n\t\t\t++totalNeeded;\n\t\t}\n\t}\n\tconsole.log(totalNeeded);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var [n, h] = readLine().split(\" \").map(Number);\n var arr = readLine().split(\" \").map(Number);\n var sum = 0;\n arr.map((item) => (sum += Math.ceil(item / h)));\n\n console.log(sum);\n}\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n\nfor (let i = 0; i < txt.length; i+=2) {\n let info =txt[i].split(\" \");\n doit(info[1] * 1, txt[i+1].split(\" \").filter(data => {\n return data.length > 0;\n }));\n}\n\nfunction doit(n, tab) {\n let sum=0;\n tab.forEach(element => {\n if(element<=n){\n ++sum;\n }else{\n sum+=2;\n }\n });\n console.log(sum);\n \n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().split('\\n');\n let fenceHeight = inputs[0].split(' ')[1].trim();\n let friendsHeight = inputs[1].trim().split(' ');\n let sumWidth = 0;\n for (let row of friendsHeight) {\n if (+row > +fenceHeight) {\n sumWidth += 2;\n }\n else {\n sumWidth += 1;\n }\n }\n return sumWidth.toString();\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst fence = () => {\n let [n,h] = input[0].split(' ').map(x => +x);\n let ar = input[1].split(' ').map(x => +x);\n let count = ar.length;\n for (const y of ar) {\n if (y > h) {\n count++;\n }\n }\n console.log(count);\n};\n\nreadLine.on('close', fence);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let nh = readLine().split(' ').map(value => parseInt(value));\n let n = nh[0];\n let h = nh[1];\n let arr = readLine().split(' ').map(value => parseInt(value));\n let ans = 0;\n for (var i = 0; i < n; i++) {\n if (arr[i] > h) {\n ans += 2;\n } else ans += 1;\n }\n console.log(ans);\n}"}, {"source_code": "var input = readline().split(\" \").map(x=>parseInt(x));\nvar num_friends = input[0];\nvar height_of_fence = input[1];\nvar friends_height = readline().split(\" \").map(x=>parseInt(x));\nvar width = 0;\nfor(var i = 0; iheight_of_fence)width+=2;\n else width++;\n}\nprint(width);"}, {"source_code": "// parameter \"input\" gets all data\nfunction Main() {\n\t// the first line is assigned to input[0], the second line is assigned to input[1] similarly.\t\n\tinput = readline().split(\" \").map(function(x) { return parseInt(x); });\n\ta = readline().split(\" \").map(function(x) { return parseInt(x); });\n\tconst n = input[0];\n\tconst h = input[1];\n\tconst ans = a.reduce((cum,x)=>cum+(x>h?2:1),0);\n\tprint(ans);\n\t\n}\n\nMain()"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line, friends) {\n var input = line.split(\" \");\n var height = friends.split(\" \");\n\n var n = input[0];\n var heightOfFence = Number(input[1]);\n\n var width = 0;\n\n for (var i = 0; i < n; i++) {\n if (Number(height[i]) > heightOfFence) {\n width += 2;\n }else{\n width++;\n }\n }\n\n return width;\n}"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\nvar friends = num[0]; // to store values in different variables. \nvar height = num[1];\nvar heights = readline().split(\" \").map(x => parseInt(x));\nvar score = 0;\nfor (var i =0;i< friends;i++) {\n if (heights[i] > height) {\n score+=2;\n } else {\n score+=1;\n }\n}\nprint(score)"}, {"source_code": "var nk = readline().split(\" \").map(x => Number(x));\nvar n = nk[0];\nvar k = nk[1];\nvar lengths = readline().split(\" \").map(x => Number(x));\n\nvar width = 0;\nfor(var i = 0; i < lengths.length; i++){\n\twidth++;\n\tif(lengths[i] > k)\n\t\twidth++;\n}\n\nprint(width);\n"}, {"source_code": "var a=readline().split(\" \");\nn=a[0];\nm=a[1];\nvar cnt=0;\nvar arr = readline().split(\" \").map(Number);\nfor( var i=0;i < n;i ++ ){\n if( arr[i]>m )\n cnt=cnt+2;\n else\n cnt++;\n}\nprint(cnt);"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]), h = Number(s[1]);\n s = readline().split(\" \");\n var count = n;\nfor(var i=0; i h) {\n count++;\n }\n}\nprint(count);"}, {"source_code": "var input = readline().split(' ').map(Number);\n\nvar n = input[0];\nvar h = input[1];\n\nvar friends = readline().split(' ').map(Number);\nvar road = n;\n\nfor (var i = 0; i < friends.length; i++) {\n\tif (friends[i] > h) {\n\t\troad += 1;\n\t}\n}\n\nprint(road);"}, {"source_code": "(function() {\n 'use strict';\n const n = readline().split(' ').map(Number);\n const z = readline().split(' ').map(Number);\n let w = 0;\n for (let i = 0; i < n[0]; ++i) {\n if (z[i] > n [1]) {\n w += 2; \n } else {\n w += 1;\n }\n }\n print(w);\n}());"}, {"source_code": "var firstLine = readline().split(' ');\nvar fenceHeight = firstLine[1];\nvar heightArray = readline().split(' ').map(x => parseInt(x));\nvar minWidth = heightArray.reduce((minWidth, height) => {\n if(height > fenceHeight) return minWidth += 2;\n else return minWidth += 1;\n}, 0);\n\nprint(minWidth);"}, {"source_code": "var fenceHeight = readline().split(' ')[1];\nvar heightArray = readline().split(' ').map(x => parseInt(x));\nvar minWidth = heightArray.reduce((minWidth, height) => {\n if(height > fenceHeight) return minWidth += 2;\n else return minWidth += 1;\n}, 0);\n\nprint(minWidth);"}, {"source_code": "var arr1 = readline().split(' ');\nvar arr = readline().split(' ');\nvar res = 0, n = +arr1[0], h = +arr1[1];\n\nfor(var i = 0; i < n; i++) {\n if (+arr[i] <= h) {\n res++;\n } else {\n res+=2;\n }\n}\n\nprint(res);\n"}, {"source_code": "const main = () => {\n const n = readline().trim().split(' ').map(x => parseInt(x));\n const arr = readline().trim().split(\" \").map(x => parseInt(x));\n const h = n[1];\n var total = 0;\n \n for (p of arr) {\n if (p > h) {\n total += 2;\n continue;\n }\n total++;\n }\n\n print(total);\n};\nmain();"}], "negative_code": [{"source_code": "var x = readline();\nvar rost = readline();\nvar res = 0;\n\tfor (var i=0; i<+x[0]; i++){\n\t\trost[i]>+x[1]? res+2: res++\n\t}\nprint(res);"}, {"source_code": "var x = readline().split(\" \");\nvar rost = readline().split(\" \");\nvar res = 0;\n\tfor (var i=0; i=+x[1]? res=+res+2:res++\n\t}\nprint(res);"}, {"source_code": "var nh = readline().split(\" \");\nvar a = readline().split(\" \");\nvar width = 0;\nfor(var i = 0; i < nh[0]; i++)\n{\n if(a[i] > nh[1])\n {\n width += 2;\n }\n else\n {\n width += 1;\n }\n}\nprint(width);"}, {"source_code": "var x= readline().split(' ');\nvar n = x[0];\nvar h = x[1];\nvar a = readline().split(\" \").map(Number);\nvar s = 0;\nfor(var i = 0; ih){\n s++;\n }\n}"}, {"source_code": "\"use strict\";\n\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar h = input[1];\nvar a = readline().split(' ').map(value => +value);\n\nwrite(a.map(a => a < h ? 1 : 2).reduce((a, b) => a + b));"}, {"source_code": "var firstLine = readline().split(' ');\nvar number = firstLine[0];\nvar height = firstLine[1];\nvar heights = readline().split(' ');\nvar width = 0;\nfor(var i = 0; i < number; i++){\n width++;\n if(heights[i] > height){\n width++;\n }\n}\nwrite(width);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; ++i){\n if(friendsList[i] > h) counter+=2;\n else counter+=1;\n}\nprint(n,h,friendsList)\nprint(counter);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; ++i){\n if(friendsList[i] > h) counter+=2;\n else counter+=1;\n}\nprint(counter);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; ++i){\n if(friendsList[i] > h) {\n counter+=2;\n print(friendsList[i], counter);\n }\n else counter+=1;\n}\nprint(counter);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; i++){\n if(friendsList[i] > h) counter+=2;\n else counter+=1;\n}\nprint(counter);"}, {"source_code": "var first = readline().split(\" \")\nvar friendsList = readline().split(' ');\nvar n = first[0], h = first[1];\nvar counter = 0;\nfor(var i = 0; i < n; ++i){\n print(i, friendsList[i]);\n if(friendsList[i] > h) counter+=2;\n else counter+=1;\n}\nprint(counter);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\n\nprint(num)"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar arr1=readline().split(' ').map((a)=>{ return parseInt(a)});\nvar arr=readline().split(' ').map((a)=>{ return parseInt(a)});\nvar count=0;\nfor(var i=0;i=arr1[1]){\n count++;\n }\n count++;\n}\n\nprint(count);\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n\n let numFriends, fenceHeight;\n\n rl.on('line', n => {\n if (!numFriends && !fenceHeight) {\n n = n.split(' ').map(Number);\n console.log(n);\n numFriends = n[0];\n fenceHeight = n[1];\n } else {\n // const numbers = n.split(' ').map(Number);\n // console.log(numbers);\n // let width = 0;\n // for(let n of numbers){\n // (n > fenceHeight) ? width +=2 : width +=1;\n // }\n \n //console.log(width);\n const width = n.split(' ').map(Number).reduce((acc, curr) => {\n return curr > fenceHeight ? acc + 2 : acc + 1;\n }, 0);\n\n console.log(width);\n rl.close();\n }\n });\n"}, {"source_code": "var lines, mainAux, minwidth, print, readline, rl, rli, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nminwidth = function(n, f, hs) {\n return hs.reduce(function(acc, h) {\n if (h > f) {\n acc + 2;\n }\n return acc + 1;\n }, 0);\n};\n\nmainAux = function() {\n var f, hs, n;\n [n, f] = readline().split(' ');\n hs = readline().split(' ');\n return print(minwidth(n, f, hs));\n};\n\n\n function main() {\n return mainAux();\n }\n;\n\n//# sourceMappingURL=wall-height.js.map\n"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet arrOfHeights = [];\nlet roadWidth = 0;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n arrOfHeights = (input.split(\" \"))\n arrOfHeights.forEach((element)=>{\n if (element>fenceHeight)\n roadWidth = roadWidth + 2 \n else\n roadWidth++\n })\n console.log(roadWidth)\n rl.close();\n } \n \n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet roadWidth = 0;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n const arrOfHeights = input.split(\" \").map((element)=>{\n element = parseInt(element)\n if (element > fenceHeight){\n roadWidth+=2\n console.log(\"First Condition \")\n }\n else{\n roadWidth++\n console.log(\"Second Condition \")\n }\n })\n console.log(roadWidth)\n rl.close();\n } \n \n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet arrOfHeights = [];\nlet roadWidth = 1;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n arrOfHeights = (input.split(\" \"))\n arrOfHeights.forEach((element)=>{\n if (element >= fenceHeight)\n roadWidth = roadWidth + 2 \n else\n roadWidth++\n })\n console.log(roadWidth)\n rl.close();\n } \n \n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet arrOfHeights = [];\nlet roadWidth = 0;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n arrOfHeights = input.split(\" \").map(Number)\n console.log(\"current arrrayof heights =\" +arrOfHeights + \"\\n\")\n arrOfHeights.forEach((element)=>{\n if (element > fenceHeight){\n roadWidth = roadWidth + 2\n console.log(\"elements that passed here \\n\"+element)\n } \n else\n {\n console.log(\"elements that passed here \\n\"+element)\n roadWidth++ \n }\n })\n console.log(roadWidth)\n rl.close();\n } \n \n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet fenceHeight = 0;\nlet noOfFriends = 0;\nlet roadWidth = 0;\nrl.on(\"line\", (input) => {\n if(!noOfFriends&&!fenceHeight){\n noOfFriends = input.split(\" \")[0];\n fenceHeight = input.split(\" \")[1];\n }\n else{\n const arrOfHeights = input.split(\" \").map((element)=>{\n element = parseInt(element)\n console.log(typeof(element))\n if (element > fenceHeight){\n roadWidth+=2\n console.log(\"First Condition \")\n }\n else{\n roadWidth++\n console.log(\"Second Condition \")\n\n\n }\n })\n console.log(roadWidth)\n rl.close();\n } \n \n});"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline().split(\" \");\n \n const x2 = readline().split(\" \");\n vanyaAndFence(x[0],x[1],x2);\n }\n \nfunction vanyaAndFence(n, h, guys) {\n console.log(guys.reduce((prev, curr) => (curr > h ? prev + 2 : prev + 1), 0));\n\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline().split(\" \");\n \n const x2 = readline().split(\" \").map(x=>+x);\n vanyaAndFence(x[0],x[1],x2);\n }\n \nfunction vanyaAndFence(n, h, guys) {\n console.log(n,h,guys)\n console.log(guys.reduce((prev, curr) => (curr > h ? prev + 2 : prev + 1), 0));\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var line2 = readline(); \n \n foo(x);\n foo(line2);\n}\nfunction foo(x) {\n process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n console.log(x); // with auto '\\n' (newline)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const [, h] = readline().split(' ');\n const a = readline().split(' ');\n\n // solve\n const w = a.map(x => x > h ? 2 : 1).reduce((m, n) => m + n, 0);\n\n // output\n print(w);\n}\n\n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const arr1 = readline().split(\" \");\n let numberOfPersons = +arr1[0];\n let height = +arr1[1];\n let personsHeight = readline().split(\" \");\n\n let total = 0;\n\n for (let i = 0; i < numberOfPersons; i++) {\n if (personsHeight[i] <= height) {\n total++;\n }\n else {\n total += 2;\n }\n }\n return total\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function (firstLine) {\n // rl.write('hello\\n')\n let [n, h] = firstLine.split(' ').map(x => Number(x));\n rl.setPrompt('');\n rl.prompt();\n rl.on('line', function (lengths) {\n let arr = lengths.split(' ').map(x => Number(x));\n let rowLength = arr.map(x => {\n if (x > h) return 2;\n else return 1;\n }).reduce((p, c) => p + c);\n rl.write(String(rowLength));\n console.log();\n rl.close();\n });\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function(firstLine) {\n // rl.write('hello\\n')\n let [n, h] = firstLine.split(' ').map(x => Number(x))\n rl.prompt();\n rl.on('line', function(lengths) {\n let arr = lengths.split(' ').map(x => Number(x));\n let rowLength = arr.map(x => {\n if(x > h) return 2;\n else return 1;\n }).reduce((p, c) => p + c)\n rl.write(String(rowLength));\n console.log();\n rl.close();\n })\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function(firstLine) {\n let [n, h] = firstLine.split(' ').map(x => Number(x))\n rl.prompt();\n rl.on('line', function(lengths) {\n let arr = lengths.split(' ').map(x => Number(x));\n let rowLength = arr.map(x => {\n if(x > h) return 2;\n else return 1;\n }).reduce((p, c) => p + c)\n console.log(rowLength);\n rl.close();\n })\n});"}, {"source_code": "x = readline().split(' ');\nreadline().split(' ').reduce((res, i) => res + (+i > +x[1]), +x[0]);\n"}, {"source_code": "var line1 = readline();\nvar n = parseInt(line1.slice(0, 1));\nvar h = parseInt(line1.slice(2));\n\nvar roadWidth = 0;\n\nvar heights = readline().split(\" \");\n\nfor (var i = 0; i < n; i++) {\n \n if (heights[i] > h) {\n roadWidth += 2;\n } else {\n roadWidth++;\n }\n \n}\n\nprint(roadWidth);"}, {"source_code": "var n = parseInt(readline());\nvar h = parseInt(readline());\n\nvar roadWidth = 0;\n\nfor (var i = 0; i < n; i++) {\n var x = parseInt(readline());\n\n if ((x > h)) {\n roadWidth += 2;\n } else {\n roadWidth++;\n }\n}\n\nprint(roadWidth);"}, {"source_code": "var line1 = readline();\nvar n = parseInt(line1.slice(0, 1));\nvar h = parseInt(line1.slice(2));\n\nvar roadWidth = 0;\n\nvar heights = readline();\n\nvar counter = 0;\n\nfor (var i = 0; i < n; i++) {\n \n var check = parseInt(heights.slice(counter));\n \n if (check > h) {\n roadWidth += 2;\n } else {\n roadWidth++;\n }\n counter += 2;\n}\n\nprint(roadWidth);"}, {"source_code": "var n = readline();\nvar h = readline();\n\nvar roadWidth = 0;\n\nfor (var i = 0; i < n; i++) {\n var x = readline();\n if (x > h) {\n roadWidth += 2;\n } else {\n roadWidth++;\n }\n}\n\nprint(roadWidth);"}, {"source_code": "var line1 = readline().split(' ')\nvar line2 = readline().split(' ')\nvar h = line1[1]\nvar result = 0\nline2.forEach(x => {\n x < h ? result++: result += Math.ceil(x/h)\n})\nprint(result)"}, {"source_code": "var n=readline();\nprint(Math.ceil(n/5)); "}, {"source_code": "var arr1 = readline().split(' ');\nvar arr = readline().split(' ');\nvar res = 0, n = +arr1[0], h = +arr1[1];\n\nprint(h);\nfor(var i = 0; i < n; i++) {\n if (+arr[i] <= h) {\n res++;\n } else {\n res+=2;\n }\n}\n\nprint(res);\n"}, {"source_code": "var arr1 = readline().split(' ');\nvar arr = readline().split(' ');\nvar res = 0, n = arr1[0], h = arr1[1];\n\nfor(var i = 0; i < n; i++) {\n if (arr[i] <= h) {\n res++;\n } else {\n res+=2;\n }\n}\n\nprint(res);\n"}, {"source_code": "var g = readline();\ng = g.split(\" \");\nvar y = readline();\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = Number(y[0]);\nvar max = min;\nvar j = n;\nvar maximum = function(){for(i=1;i h){\n j++\n }\n else if(z > min){\n max = z;\n }\n else if(z < min){\n min = z;\n }\n}\n}\nmaximum();\nif(max > h){\n j = j + 1;\n}\nprint(j);\n"}, {"source_code": "var g = readline();\ng = g.split(\" \");\nvar y = readline();\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = Number(y[0]);\nvar j = n;\nfor(i=1;i h){\n j++;\n }\n else if(y[i] < min){\n min = y[i];\n }\n else if(y[i] > min){\n min = y[i];\n }\n}\nprint(j);\n"}, {"source_code": "var g = readline();\ng = g.split(\" \");\nvar y = readline();\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = Number(y[0]);\nvar max = min;\nvar j = n;\nvar maximum = function(){for(i=1;i h){\n j++\n }\n}\n}\nmaximum()\nprint(j);"}, {"source_code": "var g = readline();\nvar y = readline();\ny = y.split(\" \")\ng = g.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = y[0];\nvar max = min;\nvar j = n;\nfor(i=1; i < y.length;i++){\n if(y[i] > min){\n max = y[i];\n }\n else if(y[i] < min){\n min = y[i];\n }\n}\nif(max > h){\n j++;\n}\nprint(j);"}, {"source_code": "var g = readline();\nvar y = readline();\ng = g.split(\" \");\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = y[0];\nvar max = min;\nvar j = n;\nfor(i=1;i < y.length;i++){\n if(y[i] > min){\n max = y[i];\n }\n else{\n min = y[i];\n }\n}\nif(max > h){\n j++;\n}\nprint(j);"}, {"source_code": "var g = readline();\ng = g.split(\" \");\nvar y = readline();\ny = y.split(\" \");\nvar n = Number(g[0]);\nvar h = Number(g[1]);\nvar min = Number(y[0]);\nvar max = min;\nvar j = n;\nfor(i=1;i min){\n max = z;\n }\n else if(z < min){\n min = z;\n }\n}\nif(max > h){\n j= j + 1;\n}\nprint(j);\n"}, {"source_code": "var nh = readline().split(' ');\nvar n = parseInt(nh[0]);\nvar h = parseInt(nh[1]); \nvar a = readline().split(' ');\nvar need = 0;\nfor (var i = 0; i < a.length; i++) {\n if (a[i] < h) {\n need++;\n } else {\n need+=2;\n }\n}\nprint (need)"}, {"source_code": "var x = readline().split(\" \");\nvar rost = readline().split(\" \");\nvar res = 0;\n\tfor (var i=0; i<+x[0]; i++){\n\t\trost[i]>+x[1]? res+2: res++\n\t}\nprint(res);"}], "src_uid": "e7ed5a733e51b6d5069769c3b1d8d22f"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, v] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, v, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, v, arr) {\n arr.sort((a, b) => a - b)\n return Math.max(\n helper(v, arr, [2, 2, 3]),\n helper(v, arr, [2, 3, 2]),\n helper(v, arr, [3, 2, 2]),\n )\n}\nfunction helper(v, arr, order) {\n let r = 0\n for (let x of arr) {\n let ok = 1\n while (v <= x) {\n if (order.length) {\n v *= order.shift()\n } else {\n ok = 0\n break\n }\n // console.log(v, x)\n }\n if (!ok) break\n v += Math.floor(x / 2)\n r++\n }\n return r\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n let [n, h] = rns(),\r\n a = rns();\r\n a.sort((a, b) => a - b);\r\n let dp = Array.from({\r\n length: 3\r\n }, () => new Array(2).fill(-Infinity));\r\n dp[2][1] = h;\r\n for (let i = 0; i < n; i++) {\r\n const tmp = Array.from({\r\n length: 3\r\n }, () => new Array(2).fill(-Infinity));\r\n let flag = true;\r\n for (let j = 0; j < 3; j++) {\r\n for (let k = 0; k < 2; k++) {\r\n if (dp[j][k] > a[i]) {\r\n tmp[j][k] = Math.max(tmp[j][k], dp[j][k] + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else {\r\n if (j && dp[j][k] * 2 > a[i]) {\r\n tmp[j - 1][k] = Math.max(tmp[j - 1][k], dp[j][k] * 2 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (j > 1 && dp[j][k] * 4 > a[i]) {\r\n tmp[j - 2][k] = Math.max(tmp[j - 2][k], dp[j][k] * 4 + Math.floor(a[i] / 2));\r\n flag = false;\r\n }\r\n if (k && dp[j][k] * 3 > a[i]) {\r\n tmp[j][k - 1] = Math.max(tmp[j][k - 1], dp[j][k] * 3 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (k && j && dp[j][k] * 6 > a[i]) {\r\n tmp[j - 1][k - 1] = Math.max(tmp[j - 1][k - 1], dp[j][k] * 6 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (k && j > 1 && dp[j][k] * 12 > a[i]) {\r\n tmp[j - 2][k - 1] = Math.max(tmp[j - 2][k - 1], dp[j][k] * 12 + Math.floor(a[i] / 2));\r\n flag = false;\r\n }\r\n }\r\n }\r\n }\r\n if (flag) return i;\r\n dp = tmp;\r\n }\r\n return n;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n let [n, h] = rns(),\r\n a = rns();\r\n a.sort((a, b) => a - b);\r\n let dp = Array.from({\r\n length: 3\r\n }, () => new Array(2).fill(-Infinity));\r\n dp[2][1] = h;\r\n for (let i = 0; i < n; i++) {\r\n const tmp = Array.from({\r\n length: 3\r\n }, () => new Array(2).fill(-Infinity));\r\n let flag = true;\r\n for (let j = 0; j < 3; j++) {\r\n for (let k = 0; k < 2; k++) {\r\n if (dp[j][k] > a[i]) {\r\n tmp[j][k] = Math.max(tmp[j][k], dp[j][k] + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else {\r\n if (j && dp[j][k] * 2 > a[i]) {\r\n tmp[j - 1][k] = Math.max(tmp[j - 1][k], dp[j][k] * 2 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (j > 1 && dp[j][k] * 4 > a[i]) {\r\n tmp[j - 1][k] = Math.max(tmp[j - 1][k], dp[j][k] * 4 + Math.floor(a[i] / 2));\r\n flag = false;\r\n }\r\n if (k && dp[j][k] * 3 > a[i]) {\r\n tmp[j][k - 1] = Math.max(tmp[j][k - 1], dp[j][k] * 3 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (k && j && dp[j][k] * 6 > a[i]) {\r\n tmp[j][k - 1] = Math.max(tmp[j][k - 1], dp[j][k] * 6 + Math.floor(a[i] / 2));\r\n flag = false;\r\n } else if (k && j > 1 && dp[j][k] * 12 > a[i]) {\r\n tmp[j][k - 1] = Math.max(tmp[j][k - 1], dp[j][k] * 12 + Math.floor(a[i] / 2));\r\n flag = false;\r\n }\r\n }\r\n }\r\n }\r\n if (flag) return i;\r\n dp = tmp;\r\n }\r\n return n;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "1f46c4ba21e734a1c7de8b2434791f77"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(1000+10);\n \n for(let i = 0; i < a.length; i++)\n map[a[i]] = 1;\n\n let isFound = false;\n for(let i = 0; i < b.length; i++){\n if(map[b[i]] === 1){\n console.log('YES');\n console.log(1, b[i]);\n isFound = true;\n break;\n }\n }\n\n if(!isFound)\n console.log('NO');\n }\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const [n, m] = readLine().split(/\\s/).map(Number)\n const as = readLine().split(/\\s/).map(Number), bs = readLine().split(/\\s/).map(Number)\n let found = false\n for (const a of as) {\n if (bs.some(b => a === b)) {\n console.log('YES')\n console.log(`1 ${a}`)\n found = true\n break;\n }\n }\n if (!found) {\n console.log('NO')\n }\n }\n}\n"}, {"source_code": "function solve() {\n var nm = readArray(Number);\n var o1 = {};\n var o2 = {};\n var isFirst = true;\n function f(elem) {\n if (isFirst) {\n o1[elem] = true;\n return;\n }\n if (o1[elem]) {\n o2[elem] = true;\n }\n }\n readArray(f);\n isFirst = false;\n readArray(f);\n var ans = Object.keys(o2)[0];\n if (ans) {\n write('YES');\n write('1 ' + ans);\n } else {\n write('NO');\n }\n\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar a = one[0];\n\t\tvar b = one[1];\n\t\tvar alist = nextIntArray();\n\t\tvar blist = nextIntArray();\n\t\tvar set = new Set();\n\t\tfor(var j = 0; j < a; j++){\n\t\t\tset.add(alist[j]);\n\t\t}\n\t\tvar isOK = false;\n\t\tfor(var j = 0; j < b; j++){\n\t\t\tif(set.has(blist[j])){\n\t\t\t\tisOK = true;\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\toutput.push(\"1 \" + blist[j]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!isOK){\n\t\t\toutput.push(\"NO\");\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 3;\n\tlet i = 1;\n\twhile (i <= testCases) {\n let a = data[i + 1].trim().split(' ');\n let b = data[i + 2].trim().split(' ');\n let r = null;\n if (a.length >= b.length) {\n for (let i = 0; i < b.length; i += 1) {\n if (a.indexOf(b[i]) !== -1) {r = b[i]; break;}\n }\n } else {\n for (let i = 0; i < a.length; i += 1) {\n if (b.indexOf(a[i]) !== -1) {r = a[i]; break;}\n }\n }\n if (r !== null) {\n console.log('YES');\n console.log(1, r);\n } else console.log('NO');\n i += 3;\n\t}\n}"}], "negative_code": [], "src_uid": "776a06c14c6fa3ef8664eec0b4d50824"} {"source_code": "function doIt2() {\n readline();\n var notes = readline().split(' ');\n var res = [3];\n var curr = 3;\n var currDiff, mistake;\n for(var i = 1; i < notes.length; i++) {\n var diff = notes[i] - notes[i - 1];\n\n if(diff) {\n diff /= Math.abs(diff);\n if(diff !== currDiff) {\n curr = 3 - diff * 2;\n while(curr === res[res.length - 2]) {\n curr += diff;\n }\n res[res.length - 1] = curr;\n }\n curr += diff;\n if(curr < 1 || curr > 5) {\n mistake = true;\n break;\n }\n } else {\n curr = curr === 3 ? 4 : 3;\n }\n\n currDiff = diff;\n\n res.push(curr);\n }\n\n if(mistake) {\n print(-1);\n } else {\n print(res.join(' '));\n }\n}\n\ndoIt2();", "positive_code": [{"source_code": "function doIt() {\n\n var fl = readline();\n var sl = readline();\n var notes = sl.split(' ');\n\n var res = [], hills = [], dirs = [0, 0, 0];\n\n var testCheck = '100000 99999 99999 99999 99998 99998 99998 99997 99998 99998 99999 99998 99998 99998';\n var testCnt = 0;\n var specialCase = fl === '10000' && sl.substr(0, testCheck.length) === testCheck;\n\n var diff, j;\n for(var i = 1; i < notes.length; i++) {\n diff = notes[i] - notes[i - 1];\n if(diff) diff = diff / Math.abs(diff);\n\n diff += 1;\n\n if(!dirs[diff]) {\n for (j = 0; j < 3; j++) {\n if(dirs[j]) {\n hills.push({dir: j, count: dirs[j]});\n dirs[j] = 0;\n break;\n }\n }\n }\n\n dirs[diff]++;\n }\n\n if(diff !== undefined) hills.push({dir: diff, count: dirs[diff]});\n\n var first = hills[0];\n if(!first) {\n print('1');\n return;\n }\n\n if(first.dir === 0) {\n res.push(5);\n } else if (first.dir === 2) {\n res.push(1);\n } else {\n res.push(3);\n }\n\n var curr = res[0];\n var mistake;\n\n for(i = 0; i < hills.length; i++) {\n var dir = hills[i].dir;\n var count = hills[i].count;\n\n testCnt += count;\n\n if(dir === 1) {\n curr = curr === 3 ? 4 : 3;\n res.push(curr);\n for(j = 1; j < count; j++) {\n res.push(curr = 7 - curr);\n }\n } else {\n if(dir === 0 && curr - count < 1\n || dir === 2 && curr + count > 5) {\n mistake = true;\n break;\n }\n\n for(j = 0; j < count; j++) {\n res.push(curr += dir - 1);\n }\n }\n\n var next = hills[i + 1];\n if(!next) break;\n\n var nextDir = next.dir;\n if(nextDir !== 1) {\n curr = 5 - nextDir * 2;\n while(curr === res[res.length - 2]) {\n curr += nextDir - 1;\n }\n res[res.length - 1] = curr;\n }\n }\n\n if(mistake) {\n // if(specialCase) {\n // print(notes.slice(testCnt-15, testCnt+10).join(' '));\n // print(res.slice(testCnt-15).join(' '));\n // }\n print(-1);\n } else {\n print(res.join(' '));\n }\n}\n\ndoIt();"}], "negative_code": [{"source_code": "function doIt() {\n\n readline();\n var res = [], hills = [], dirs = [0, 0, 0];\n var notes = readline().split(' ');\n\n var diff;\n for(var i = 1; i < notes.length; i++) {\n diff = notes[i] - notes[i - 1];\n if(diff) diff = diff / Math.abs(diff);\n\n diff += 1;\n\n if(!dirs[diff]) {\n for (var j = 0; j < 3; j++) {\n if(dirs[j]) {\n hills.push({dir: j, count: dirs[j]});\n dirs[j] = 0;\n break;\n }\n }\n }\n\n dirs[diff]++;\n }\n\n if(diff !== undefined) hills.push({dir: diff, count: dirs[diff]});\n\n var first = hills[0];\n if(!first) {\n print('1');\n return;\n }\n\n if(first.dir === 0) {\n res.push(5);\n } else if (first.dir === 2) {\n res.push(1);\n } else {\n res.push(3);\n }\n\n var curr = res[0];\n var mistake;\n\n for(i = 0; i < hills.length; i++) {\n var dir = hills[i].dir;\n var count = hills[i].count;\n\n if(dir === 1) {\n curr = curr === 3 ? 4 : 3;\n res.push(curr);\n for(j = 1; j < count; j++) {\n res.push(curr = 7 - curr);\n }\n } else {\n if(dir === 0 && curr - count < 1\n || dir === 2 && curr + count > 5) {\n mistake = true;\n break;\n }\n\n for(j = 0; j < count; j++) {\n res.push(curr += dir - 1);\n }\n }\n\n var next = hills[i + 1];\n if(!next) break;\n\n var nextDir = next.dir;\n if(nextDir === 0 && res[res.length - 2]!== 5) {\n res[res.length - 1] = curr = 5;\n } else if (nextDir === 2 && res[res.length - 2]!== 1) {\n res[res.length - 1] = curr = 1;\n }\n }\n\n if(mistake) {\n print(-1);\n } else {\n print(res.join(' '));\n }\n\n}\n\ndoIt();"}, {"source_code": "function doIt() {\n\n var fl = readline();\n var sl = readline();\n var notes = sl.split(' ');\n\n var res = [], hills = [], dirs = [0, 0, 0];\n\n var testCheck = '100000 99999 99999 99999 99998 99998 99998 99997 99998 99998 99999 99998 99998 99998';\n var testCnt = 0;\n var specialCase = fl === '10000' && sl.substr(0, testCheck.length) === testCheck;\n\n var diff, j;\n for(var i = 1; i < notes.length; i++) {\n diff = notes[i] - notes[i - 1];\n if(diff) diff = diff / Math.abs(diff);\n\n diff += 1;\n\n if(!dirs[diff]) {\n for (j = 0; j < 3; j++) {\n if(dirs[j]) {\n hills.push({dir: j, count: dirs[j]});\n dirs[j] = 0;\n break;\n }\n }\n }\n\n dirs[diff]++;\n }\n\n if(diff !== undefined) hills.push({dir: diff, count: dirs[diff]});\n\n var first = hills[0];\n if(!first) {\n print('1');\n return;\n }\n\n if(first.dir === 0) {\n res.push(5);\n } else if (first.dir === 2) {\n res.push(1);\n } else {\n res.push(3);\n }\n\n var curr = res[0];\n var mistake;\n\n for(i = 0; i < hills.length; i++) {\n var dir = hills[i].dir;\n var count = hills[i].count;\n\n testCnt += count;\n\n if(dir === 1) {\n curr = curr === 3 ? 4 : 3;\n res.push(curr);\n for(j = 1; j < count; j++) {\n res.push(curr = 7 - curr);\n }\n } else {\n if(dir === 0 && curr - count < 1\n || dir === 2 && curr + count > 5) {\n mistake = true;\n break;\n }\n\n for(j = 0; j < count; j++) {\n res.push(curr += dir - 1);\n }\n }\n\n var next = hills[i + 1];\n if(!next) break;\n\n var nextDir = next.dir;\n if(nextDir === 0 && res[res.length - 2]!== 5) {\n res[res.length - 1] = curr = 5;\n } else if (nextDir === 2 && res[res.length - 2]!== 1) {\n res[res.length - 1] = curr = 1;\n }\n }\n\n if(mistake) {\n if(specialCase) {\n print(notes.slice(testCnt-15, testCnt+10).join(' '));\n print(res.slice(testCnt-15).join(' '));\n }\n print(-1);\n } else {\n print(res.join(' '));\n }\n}\n\ndoIt();"}, {"source_code": "function doIt() {\n\n var fl = readline();\n var sl = readline();\n var notes = sl.split(' ');\n\n var res = [], hills = [], dirs = [0, 0, 0];\n\n var testCheck = '100000 99999 99999 99999 99998 99998 99998 99997 99998 99998 99999 99998 99998 99998';\n var testCnt = 0;\n var specialCase = fl === '10000' && sl.substr(0, testCheck.length) === testCheck;\n\n var diff, j;\n for(var i = 1; i < notes.length; i++) {\n diff = notes[i] - notes[i - 1];\n if(diff) diff = diff / Math.abs(diff);\n\n diff += 1;\n\n if(!dirs[diff]) {\n for (j = 0; j < 3; j++) {\n if(dirs[j]) {\n hills.push({dir: j, count: dirs[j]});\n dirs[j] = 0;\n break;\n }\n }\n }\n\n dirs[diff]++;\n }\n\n if(diff !== undefined) hills.push({dir: diff, count: dirs[diff]});\n\n var first = hills[0];\n if(!first) {\n print('1');\n return;\n }\n\n if(first.dir === 0) {\n res.push(5);\n } else if (first.dir === 2) {\n res.push(1);\n } else {\n res.push(3);\n }\n\n var curr = res[0];\n var mistake;\n\n for(i = 0; i < hills.length; i++) {\n var dir = hills[i].dir;\n var count = hills[i].count;\n\n testCnt += count;\n\n if(dir === 1) {\n curr = curr === 3 ? 4 : 3;\n res.push(curr);\n for(j = 1; j < count; j++) {\n res.push(curr = 7 - curr);\n }\n } else {\n if(dir === 0 && curr - count < 1\n || dir === 2 && curr + count > 5) {\n mistake = true;\n break;\n }\n\n for(j = 0; j < count; j++) {\n res.push(curr += dir - 1);\n }\n }\n\n var next = hills[i + 1];\n if(!next) break;\n\n var nextDir = next.dir;\n if(nextDir !== 1) {\n curr = 5 - nextDir * 2;\n while(curr === res[res.length - 2]) {\n curr += nextDir - 1;\n }\n res[res.length - 1] = curr;\n }\n }\n\n if(mistake) {\n if(specialCase) {\n print(notes.slice(testCnt-15, testCnt+10).join(' '));\n print(res.slice(testCnt-15).join(' '));\n }\n print(-1);\n } else {\n print(res.join(' '));\n }\n}\n\ndoIt();"}, {"source_code": "function doIt() {\n\n var fl = readline();\n var sl = readline();\n var notes = sl.split(' ');\n\n var res = [], hills = [], dirs = [0, 0, 0];\n\n var testCheck = '100000 99999 99999 99999 99998 99998 99998 99997 99998 99998 99999 99998 99998 99998';\n var testCnt = 0;\n var specialCase = fl === '10000' && sl.substr(0, testCheck.length) === testCheck;\n\n var j;\n var diff;\n for(var i = 1; i < notes.length; i++) {\n diff = notes[i] - notes[i - 1];\n if(diff) diff = diff / Math.abs(diff);\n\n diff += 1;\n\n if(!dirs[diff]) {\n for (j = 0; j < 3; j++) {\n if(dirs[j]) {\n hills.push({dir: j, count: dirs[j]});\n dirs[j] = 0;\n break;\n }\n }\n }\n\n dirs[diff]++;\n }\n\n if(diff !== undefined) hills.push({dir: diff, count: dirs[diff]});\n\n var first = hills[0];\n if(!first) {\n print('1');\n return;\n }\n\n if(first.dir === 0) {\n res.push(5);\n } else if (first.dir === 2) {\n res.push(1);\n } else {\n res.push(3);\n }\n\n var curr = res[0];\n var mistake;\n\n for(i = 0; i < hills.length; i++) {\n var dir = hills[i].dir;\n var count = hills[i].count;\n \n testCnt += count;\n\n if(dir === 1) {\n curr = curr === 3 ? 4 : 3;\n res.push(curr);\n for(j = 1; j < count; j++) {\n res.push(curr = 7 - curr);\n }\n } else {\n if(dir === 0 && curr - count < 1\n || dir === 2 && curr + count > 5) {\n mistake = true;\n break;\n }\n\n for(j = 0; j < count; j++) {\n res.push(curr += dir - 1);\n }\n }\n\n var next = hills[i + 1];\n if(!next) break;\n\n var nextDir = next.dir;\n if(nextDir === 0 && res[res.length - 2]!== 5) {\n res[res.length - 1] = curr = 5;\n } else if (nextDir === 2 && res[res.length - 2]!== 1) {\n res[res.length - 1] = curr = 1;\n }\n }\n\n if(mistake) {\n if(specialCase) print(testCnt);\n print(-1);\n } else {\n print(res.join(' '));\n }\n}\n\ndoIt();"}], "src_uid": "c63b62ad5b8d0b274599b60442766e17"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [d, e, f] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let ans = Math.min(c, e);\n\n const extra = Math.max(f - (a + c - ans), 0);\n\n ans -= extra;\n\n console.log(ans * 2);\n }\n}\n", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let [a0, a1, a2, b0, b1, b2] = $(6);\n let plus = min(a2, b1);\n let minus = min(a1, (b0 + b1 + b2 - plus - b2))\n log(plus * 2 - min(a1 - minus) * 2)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probB(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if(n < k)\n console.log(k-n);\n else{\n if((n+k) % 2 === 0){\n console.log(0);\n }else{\n console.log(n-k);\n }\n }\n }\n}\n\nfunction probB(){\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n a[0] = pi(a[0]);\n a[1] = pi(a[1]);\n a[2] = pi(a[2]);\n\n b[0] = pi(b[0]);\n b[1] = pi(b[1]);\n b[2] = pi(b[2]);\n\n let maxSum = 0;\n if(b[2] - (a[0] + a[2]) > 0){\n b[2] = b[2] - (a[0]+a[2]);\n a[0] = 0;\n a[2] = 0;\n }else if(b[2] - a[0] > 0){\n a[2] = a[2] - (b[2] - a[0]);\n b[2] = 0;\n a[0] = 0;\n }else{\n a[0] -= b[2];\n b[2] = 0;\n }\n\n if(a[2] > b[1])\n console.log((b[1] - b[2]) * 2)\n else\n console.log((a[2]-b[2]) * 2);\n\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nwhile(t--){\n a = readline().split(' ');\n x1 = parseInt(a[0]);\n y1 = parseInt(a[1]);\n z1 = parseInt(a[2]);\n \n a = readline().split(' ');\n x2 = parseInt(a[0]);\n y2 = parseInt(a[1]);\n z2 = parseInt(a[2]);\n \n result = 0;\n min = Math.min(z1, y2);\n result += min * 2;\n z1 -= min;\n y2 -= min;\n \n min = Math.min(z2, x1);\n z2 -= min;\n x1 -= min;\n \n min = Math.min(z2, z1);\n z1 -= min;\n z2 -= min;\n \n result -= z2 * 2;\n \n print(result);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const [x1, y1, z1] = readLine().split(/\\s/).map(Number)\n const [x2, y2, z2] = readLine().split(/\\s/).map(Number)\n const positive = Math.min(z1, y2)\n const negative = Math.max(z2 - x1 - z1 + positive, 0)\n console.log((positive - negative) * 2)\n }\n}\n\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [d, e, f] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let diff = 0;\n if (f - a > 0) {\n diff = Math.min(f - a, b) * 2;\n }\n let ans = Math.min(c, e) * 2;\n\n if (ans) {\n ans -= diff;\n }\n\n console.log(ans);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [d, e, f] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let diff = 0;\n if (b + c > d + e) {\n diff = b + c - (d + e);\n }\n let ans = Math.min(c, e) * 2;\n\n if (ans) {\n ans -= diff * 2;\n }\n\n console.log(ans);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [d, e, f] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n console.log(Math.min(c, e) * 2);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probB(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if(n < k)\n console.log(k-n);\n else{\n if((n+k) % 2 === 0){\n console.log(0);\n }else{\n console.log(n-k);\n }\n }\n }\n}\n\nfunction probB(){\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n a[0] = pi(a[0]);\n a[1] = pi(a[1]);\n a[2] = pi(a[2]);\n\n b[0] = pi(b[0]);\n b[1] = pi(b[1]);\n b[2] = pi(b[2]);\n\n let maxSum = 0;\n if(b[2] - (a[0] + a[2]) > 0){\n b[2] = b[2] - (a[0]+a[2]);\n a[0] = 0;\n a[1] = 0;\n }else if(b[2] - a[0] > 0){\n a[2] = a[2] - (b[2] - a[0]);\n b[2] = 0;\n a[0] = 0;\n }else{\n a[0] -= b[2];\n b[2] = 0;\n }\n\n if(a[2] > b[1])\n console.log((b[1] - b[2]) * 2)\n else\n console.log((a[2]-b[2]) * 2);\n\n }\n}"}], "src_uid": "e1de1e92fac8a6db3222c0d3c26843d8"} {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar t = readline()\r\nfor(var i=1;i<=t;i++) {\r\n\tvar h = readline();\r\n\tfunction r(u) {\r\n\t\tif(u==1) return 1;\r\n\t\telse {\r\n\t\t\tvar ans = []\r\n\t\t\tfor(var j=2;ans.length stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n for(var i = 1; i <= n; i++){\n var k = lines[i];\n var ans = '';\n var a = 2;\n for(j = 0; j < k; j++){\n ans += a + ' '; \n a++;\n }\n console.log(ans); \n }\n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL)\n var n = lines[0]\n for(var j = 1; j <= n; j++){\n var k = lines[j]\n var ans = ''\n var a = 2\n for(l = 0; l < k; l++){\n ans += a + ' ';\n a++\n }\n console.log(ans); \n }\n}); \n\n"}, {"source_code": "\r\n\r\n\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet g=[];\r\nfor(let i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL)\n var n = lines[0]\n for(var j = 1; j <= n; j++){\n var k = lines[j]\n var ans = ''\n var a = 1\n for(l = 2; l < k; l++){\n ans += l + ' '; \n a++\n }\n console.log(ans); \n }\n}); \n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL)\n var n = lines[0]\n for(var j = 1; j <= n; j++){\n var k = lines[j]\n var ans = ''\n var a = 1\n for(l = 0; l < k; l++){\n ans += a + ' '; \n a++\n }\n console.log(ans); \n }\n}); \n\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet g=[];\r\nfor(let i=0;i num === 0),\r\n has1 = nums.some(num => num === 1)\r\n if (has0 && has1) {\r\n console.log('NO')\r\n } else if (!has1) {\r\n console.log('YES')\r\n } else {\r\n nums.sort((a, b) => b - a)\r\n for (let i = 1; i < n; i++) {\r\n if (nums[i] === nums[i - 1] - 1) {\r\n console.log('NO')\r\n continue next\r\n }\r\n }\r\n\r\n console.log('YES')\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const solve = (n,arr)=>{\r\n arr = arr.sort((a,b)=>a-b);\r\n if(arr[0]>=2) return \"YES\";\r\n else if(arr[0]===0){\r\n for(let i=1;i=2) break;\r\n }\r\n else{\r\n for(let i=1;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst EPS = 1e-6;\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [n] = readline().split(' ').map(a=>+a);\n let arr = readline().split(' ').map(a=>+a);\n let can_turn_all_to_0 = true\n let can_turn_all_to_1 = true\n let has_1 = false\n let all_same = true;\n for (let a of arr){\n if (arr[0]!=a)\n all_same = false;\n if (a==1)\n can_turn_all_to_0 = false;\n if (a==1)\n has_1 = true;\n if (a==2 || a==0)\n can_turn_all_to_1 = false;\n }\n if (!has_1 || all_same){\n print('yes');\n } else {\n arr.sort((a, b)=>a-b);\n let fail;\n for (let i=0; i{\r\n arr = arr.sort((a,b)=>a-b);\r\n let one = false;\r\n let consec = false;\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag1 = 0, flag2 = 0;\n for(j = 0; j < n; j++){\n if(a[j] == 1){\n flag1 = 1;\n }\n if(j < n - 1 && a[j + 1] - a[j] == 1){\n flag2 = 1;\n }\n }\n console.log(flag1 && flag2 ? 'NO' : 'YES'); \n }\n }\n});"}], "negative_code": [{"source_code": "const solve = (n,arr)=>{\r\n arr = arr.sort((a,b)=>a-b);\r\n if(arr[0]>=2) return \"YES\";\r\n else if(arr[0]===0){\r\n for(let i=1;i=2) break;\r\n }\r\n let arr1 = [arr[0]];\r\n for(let i=1;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n arr = arr.sort((a,b)=>a-b);\r\n if(arr[0]===0){\r\n let flag = 1;\r\n for(let i=1;i=2)) return \"NO\";\r\n else if(arr[i]>=2) break;\r\n }\r\n }\r\n else if(arr[0]===1){\r\n for(let i=1;i2){\r\n for(let j=i+1;jparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = Number(inputs[0])\r\ninputs.shift()\r\nmain(N, inputs)\r\nfunction main(N, inputs) {\r\n next: for (let _ = 0; _ < N; _++) {\r\n const n = Number(inputs[_ * 2]),\r\n nums = inputs[_ * 2 + 1].split(' ').map(Number)\r\n let has0 = nums.some(num => num === 0),\r\n has1 = nums.some(num => num === 1)\r\n if (has0 && has1) {\r\n console.log('NO')\r\n } else if (!has1) {\r\n console.log('YES')\r\n } else {\r\n nums.sort((a, b) => b - a)\r\n for (let i = 1; i < n; i++) {\r\n console.log(i, nums[i], nums[i - 1])\r\n if (nums[i] === nums[i - 1] - 1) {\r\n console.log('NO')\r\n continue next\r\n }\r\n }\r\n\r\n console.log('YES')\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = Number(inputs[0])\r\ninputs.shift()\r\nmain(N, inputs)\r\nfunction main(N, inputs) {\r\n next: for (let _ = 0; _ < N; _++) {\r\n const n = Number(inputs[_ * 2]),\r\n nums = inputs[_ * 2 + 1].split(' ').map(Number)\r\n let has0 = nums.some(num => num === 0),\r\n has1 = nums.some(num => num === 1)\r\n if (has0 && has1) {\r\n console.log('NO')\r\n } else if (!has1) {\r\n console.log('YES')\r\n } else {\r\n nums.sort((a, b) => b - a)\r\n console.log(nums, n)\r\n for (let i = 1; i < n; i++) {\r\n console.log(i, nums[i], nums[i - 1])\r\n if (nums[i] === nums[i - 1] - 1) {\r\n console.log('NO')\r\n continue next\r\n }\r\n }\r\n\r\n console.log('YES')\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst EPS = 1e-6;\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [n] = readline().split(' ').map(a=>+a);\n let arr = readline().split(' ').map(a=>+a);\n let can_turn_all_to_0 = true\n let can_turn_all_to_1 = true\n let all_same = true;\n for (let a of arr){\n if (arr[0]!=a)\n all_same = false;\n if (a==1)\n can_turn_all_to_0 = false;\n if (a==2 || a==0)\n can_turn_all_to_1 = false;\n }\n print(all_same || can_turn_all_to_0 || can_turn_all_to_1 ? 'yes' : 'no')\n }\n}"}], "src_uid": "c7e4f544ec8b4972291542e66aff5df5"} {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n // console.log(lines);\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(str => parseInt(str, 10));\n canDance(input);\n count += 2;\n }\n});\n\nfunction canDance(arr) {\n let index = arr.indexOf(1);\n if (index === -1) {\n console.log('NO');\n return;\n }\n\n // clockwise\n const startIndex = index;\n let curr = 1;\n index++;\n while (index !== startIndex) {\n if (index === arr.length) index = 0;\n if (arr[index] === curr + 1) {\n curr++;\n index++;\n } else {\n break;\n }\n }\n\n if (index === startIndex) {\n console.log('YES');\n return;\n }\n\n curr = 1;\n index = startIndex - 1;\n while (index !== startIndex) {\n if (index === -1) index = arr.length - 1;\n if (arr[index] === curr + 1) {\n curr++;\n index--;\n } else {\n break;\n }\n }\n if (index === startIndex) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n", "positive_code": [{"source_code": "'use strict'\n\n\nconst roundelay = (n, p) => {\n let i = 1;\n while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;\n if (i === n) return 'YES';\n i = 1;\n while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;\n if (i === n) return 'YES';\n return 'NO';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(roundelay(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}, {"source_code": "rVal = () => +readline();\nrArr = () => readline().split(' ').map(item => +item);\n\nvar q = rVal();\n\nfor(var i = 0; i < q; i++) {\n var n = rVal();\n var arr = rArr();\n \n if(n === 1) {\n print('YES');\n continue;\n }\n \n for(var j = 0; j < n; j++) {\n if(arr[j] === 1) {\n index = j;\n break;\n }\n }\n \n var j = 0;\n \n for(j = 0, k = index; j < n - 1; j++) {\n var k2 = k + 1;\n if(k2 === n) {\n k2 = 0;\n }\n if(arr[k2] - arr[k] === 1) {\n k = k2;\n } else {\n break;\n }\n }\n \n if(j === n - 1) {\n print('YES');\n continue;\n }\n \n for(var j = 0, k = index; j < n - 1; j++) {\n var k2 = k - 1;\n if(k2 < 0) {\n k2 = n - 1;\n }\n if(arr[k2] - arr[k] === 1) {\n k = k2;\n } else {\n break;\n }\n }\n \n if(j === n - 1) {\n print('YES');\n continue;\n }\n \n print('NO');\n}"}, {"source_code": "'use strict'\n\nvar t=Number(readline());\n\nwhile(t--)\n{\n var n=parseInt(readline());\n var data=readline().split(' ').map(Number);\n\n var start_idx=-1;\n for(var i=0;i=n) clockW=0;\n if((data[clockW]-tmp)!=1){\n flag=false;\n break;\n }\n }\n\n if(!flag){\n flag=true;\n clockW=start_idx;\n\n for(var i=1;i {\n process.stdout.write(args.join(' '));\n}\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nfunction query(arr){\n let n = arr.length;\n let arr2 = arr.concat(arr);\n let f = arr2.indexOf(1);\n for (let i=0; i+n);\n if (query(arr) || query(arr.reverse()))\n print('YES')\n else\n print('NO');\n }\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n\n function can1 (data) {\n return data.reduce((agr, value, index, array) => {\n if (!agr) return false;\n if (index === array.length - 1) return agr;\n return value === array[index + 1] - 1 || array[index + 1] === 1;\n }, true);\n }\n\n function can0 (data) {\n return data.reduceRight((agr, value, index, array) => {\n if (!agr) return false;\n if (index === 0) return agr;\n return value === array[index - 1] - 1 || array[index - 1] === 1;\n }, true);\n }\n\n return can1(data) || can0(data);\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n //console.log(data);\n let result = foo(data);\n answer += (result ? \"YES\" : \"NO\") +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}], "negative_code": [{"source_code": "'use strict'\n\n\nconst roundelay = (n, p) => {\n let i = 1;\n while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;\n if (i === n) return 'OK';\n i = 1;\n while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;\n if (i === n) return 'OK';\n return 'NO';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n roundelay(parseInt(readline()), readline().split(' ').map(Number));\n}"}, {"source_code": "'use strict'\n\n\nconst roundelay = (n, p) => {\n let i = 1;\n while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;\n if (i === n) return 'OK';\n i = 1;\n while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;\n if (i === n) return 'OK';\n return 'NO';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(roundelay(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}], "src_uid": "b27436086ead93397be748d8ebdbf19a"} {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n // var nul = readline();\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var p = readline();\r\n var c = []\r\n var f = alph();\r\n var mp = new Map();\r\n for(var i=0;i p) {\r\n // if(tc == 1) console.log(\"p\", i)\r\n break;\r\n }\r\n g += val;\r\n // ans += n[c[i][0]]\r\n }\r\n var ca = c.slice(0, i)\r\n ca.sort(function(a,b) { return a[0] - b[0] })\r\n for(var i=0;i {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar s = readString();\r\n\t\tvar n = s.length;\r\n\t\tvar p = readInt();\r\n\t\t\r\n\t\tvar idxs = [];\r\n\t\tfor (var i = 0; i < 27; i++)\r\n\t\t\tidxs.push([]);\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\tidxs[s.charCodeAt(i) - 96].push(i);\r\n\t\t\r\n\t\tvar total = 0;\r\n\t\tvar takeIdx = [0];\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\ttakeIdx.push(0);\r\n\t\tfor (var i = 1; i < 27; i++) {\r\n\t\t\twhile (total + i <= p && idxs[i].length > 0) {\r\n\t\t\t\ttotal += i;\r\n\t\t\t\ttakeIdx[idxs[i][idxs[i].length - 1]] = 1;\r\n\t\t\t\tidxs[i].pop();\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar ansarr = [];\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\tif (takeIdx[i] === 1)\r\n\t\t\t\tansarr.push(s[i]);\r\n\t\tvar ans = ansarr.join('');\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n \r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n \r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar s = readString();\r\n\t\tvar n = s.length;\r\n\t\tvar p = readInt();\r\n\t\t\r\n\t\tvar idxs = [];\r\n\t\tfor (var i = 0; i < 27; i++)\r\n\t\t\tidxs.push([]);\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\tidxs[s.charCodeAt(i) - 96].push(i);\r\n\t\t\r\n\t\tvar total = 0;\r\n\t\tvar takeIdx = [0];\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\ttakeIdx.push(0);\r\n\t\tfor (var i = 1; i < 27; i++) {\r\n\t\t\twhile (total + i <= p && idxs[i].length > 0) {\r\n\t\t\t\ttotal += i;\r\n\t\t\t\ttakeIdx[idxs[i][idxs[i].length - 1]] = 1;\r\n\t\t\t\tidxs[i].pop();\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar ansarr = [];\r\n\t\tfor (var i = 0; i < n; i++)\r\n\t\t\tif (takeIdx[i] === 1)\r\n\t\t\t\tansarr.push(s[i]);\r\n\t\tvar ans = ansarr.join('');\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "T = readline()\r\n\r\nabc = 'abcdefghijklmnopqrstuvwxyz'.split('')\r\nobj = {}\r\nfor(i=0; i< abc.length; i++){\r\n obj[abc[i]] = i +1 \r\n}\r\n\r\nwhile(T--){\r\n str = readline().split('').map(el => obj[el])\r\n p = readline()\r\n\r\n sum = str.reduce(function(acc, cur){\r\n return acc + cur\r\n }, 0)\r\n \r\n clone = str.slice()\r\n clone.sort((a, b) => a - b)\r\n\r\n while(sum > p){\r\n sum = sum - clone[clone.length-1]\r\n clone.pop()\r\n }\r\n\r\n objAns = {}\r\n for(i = 0; i < clone.length; i++){\r\n if(objAns[clone[i]] === undefined)\r\n objAns[clone[i]] = 1\r\n else\r\n objAns[clone[i]]++\r\n }\r\n\r\n strAns = []\r\n\r\n for(i = 0; i< str.length; i++){\r\n if(objAns[str[i]]){\r\n objAns[str[i]]--\r\n strAns.push(str[i])\r\n }\r\n }\r\n\r\n resultObj = {}\r\n\r\n Object.keys(obj).forEach(key => {\r\n value = obj[key]\r\n resultObj[value] = key\r\n })\r\n\r\n res = strAns.map(el => resultObj[el])\r\n\r\n print(res.join(''))\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arr = readline().trim().split(\"\");\r\n let n = arr.length;\r\n let k = parseInt(readline());\r\n let obj = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n x: 24,\r\n y: 25,\r\n z: 26,\r\n };\r\n let narr = [];\r\n for (let i = 0; i < n; i++) {\r\n let o = { val: obj[arr[i]], ind: i };\r\n narr.push(o);\r\n }\r\n narr.sort((a, b) => a.val - b.val);\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += narr[i].val;\r\n let c = {},\r\n i = n - 1;\r\n while (sum > k && i >= 0) {\r\n sum -= narr[i].val;\r\n c[narr[i].ind] = 1;\r\n i--;\r\n }\r\n let res = \"\";\r\n for (let i = 0; i < n; i++) {\r\n if (c[i]) continue;\r\n else res += arr[i];\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let alph = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));\r\n let price = {};\r\n alph.forEach((letter, i) => price[letter] = i + 1);\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let str = readline();\r\n let target = Number(readline());\r\n\r\n if (str === '' || target === 0) {\r\n output('');\r\n continue;\r\n }\r\n\r\n let totalCost = 0;\r\n let costs = str.split('').map((letter, index) => {\r\n totalCost += price[letter];\r\n return {\r\n originalIndex: index,\r\n letter: letter,\r\n cost: price[letter]\r\n };\r\n });\r\n costs.sort((a, b) => a.cost - b.cost);\r\n\r\n while (totalCost > target) {\r\n let next = costs.pop();\r\n totalCost -= next.cost;\r\n }\r\n\r\n costs.sort((a, b) => a.originalIndex - b.originalIndex);\r\n\r\n let result = costs.map(c => c.letter).join('');\r\n\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n const m = s.length;\r\n const a = new Array(m);\r\n for (let i = 0; i < m; i++) a[i] = s.charCodeAt(i) - 96;\r\n let sum = a.reduce((a, b) => a + b, 0);\r\n if (sum <= n) return s;\r\n const map = Array.from({\r\n length: 27\r\n }, () => []);\r\n let res = new Array(m).fill(1);\r\n for (let [i, num] of a.entries()) map[num].push(i);\r\n let i = 26;\r\n while (sum > n) {\r\n while (i >= 0 && map[i].length === 0) {\r\n i--;\r\n }\r\n if (map[i].length === 0) return '';\r\n const j = map[i].pop();\r\n res[j] = 0;\r\n sum -= i;\r\n }\r\n let ans = '';\r\n for (let i = 0; i < m; i++) {\r\n if (res[i]) ans += s[i];\r\n }\r\n return ans;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n const n = Number(await read());\r\n res[i] = solve(n, s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\tvar costmap = {};\r\n\tfor(var i = 0; i < alpha.length; i++){\r\n\t\tcostmap[alpha[i]] = i + 1;\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar S = nextCharArray();\r\n\t\tvar N = S.length;\r\n\t\tvar P = nextInt();\r\n\t\tvar cost = 0;\r\n\t\tvar map = {};\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tcost += costmap[S[i]];\r\n\t\t\tif(map[S[i]] == null){\r\n\t\t\t\tmap[S[i]] = [];\r\n\t\t\t}\r\n\t\t\tmap[S[i]].push(i);\r\n\t\t}\r\n\t\tfor(var i = alpha.length - 1; i >= 0; i--){\r\n\t\t\tif(cost <= P){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif(map[alpha[i]] == null){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar nx = map[alpha[i]];\r\n\t\t\tfor(var j = 0; j < nx.length; j++){\r\n\t\t\t\tS[nx[j]] = \"\";\r\n\t\t\t\tcost -= costmap[alpha[i]];\r\n\t\t\t\tif(cost <= P){\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(S, 0));\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n const p = +lines[l++]\n output[i] = solve(str, p)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str, p) {\n const arr = []\n for (let i = 0; i < str.length; i++) {\n const x = str.charCodeAt(i) - 'a'.charCodeAt(0) + 1\n arr.push([x, i])\n }\n arr.sort((a, b) => a[0] - b[0])\n //\n let now = 0\n const skip = {}\n for (let i = 0; i < arr.length; i++) {\n const [x, j] = arr[i]\n if (now + x > p) {\n // delete\n skip[j] = 1\n } else {\n now += x\n }\n }\n const ans = []\n for (let i = 0; i < str.length; i++) {\n if (!skip[i]) ans.push(str[i])\n }\n return ans.join('')\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arr = readline().trim().split(\"\");\r\n let n = arr.length;\r\n let k = parseInt(readline());\r\n let obj = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n x: 24,\r\n y: 25,\r\n z: 26,\r\n };\r\n let narr = [];\r\n for (let i = 0; i < n; i++) {\r\n let o = { val: obj[arr[i]], ind: i };\r\n narr.push(o);\r\n }\r\n narr.sort((a, b) => a.val - b.val);\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += narr[i].val;\r\n let c = {},\r\n i = n - 1;\r\n if (sum === k) {\r\n console.log(\"\");\r\n continue;\r\n }\r\n while (sum > k && i >= 0) {\r\n sum -= narr[i].val;\r\n c[narr[i].ind] = 1;\r\n i--;\r\n }\r\n let res = \"\";\r\n for (let i = 0; i < n; i++) {\r\n if (c[i]) continue;\r\n else res += arr[i];\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "cb645c794ee3916b180fc3d789cb7c27"} {"source_code": "ln=readline().split(\" \").map(x=>x*1);\nn=ln[0];\na=ln[1];\nb=ln[2];\nseals = [];\nfor(i=0; ix*1));\n}\n\nfunction canFit(x1,y1,x2,y2){\n if(x1>a||x2>a||y1>b||y2>b) return false;\n ox = x1+x2>a?false:true;\n oy = y1+y2>b?false:true;\n return ox||oy;\n}\n\nans = 0;\nfor(i=0; i= b[0]) && (toot[x][1]>=b[1])) || ((toot[x][1] >= b[0]) && (toot[x][0]>=b[1])) )\n{\nvar s = (+(ayin[i][0]*ayin[i][1])) + (+(ayin[r][0]*ayin[r][1]));\nif((s>round)&&(s<=xy[0]*xy[1])){round=s;}\n} \n \n\n}\n\n \n\n\n}\n\n\n\nprint(round)\n\n\n "}], "negative_code": [{"source_code": "ln=readline().split(\" \").map(x=>x*1);\nn=ln[0];\na=ln[1];\nb=ln[2];\nseals = [];\nfor(i=0; ix*1));\n}\n\nfunction canFit(x1,y1,x2,y2){\n if(x1>a||x2>a||y1>b||y2>b) return false;\n ox = x1+x2>a?true:false;\n oy = y1+y2>b?true:false;\n return ox||oy;\n}\n\nans = 0;\nfor(i=0; i=xy[0]*xy[1]){if((fps0<=lastspace)&&(seconditem[1]<=e) ){ \n e = seconditem[1];lastspace= fps0;round =((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}} \n\n\nif(fps1>=xy[0]*xy[1]){if((fps1<=lastspace)&&(seconditem[0]<=e)){\n e = seconditem[0];lastspace=fps1;round = ((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}}\n \n}if(z===0){z+=1;r-=1}\n}\n print(round);\n"}, {"source_code": "var rline = readline().split(\" \");var xy = [+rline[1],+rline[2]];\n\nvar round = 0;var s = 0;\nvar ayin = [];\nfor(var o=0;o= b[0]) && (toot[x][1]>=b[1])){\nvar s = (+(ayin[i][0]*ayin[i][1])) + (+(ayin[r][0]*ayin[r][1]))\nif((s>round)&&(s= b[0]) && (toot[x][0]>=b[1])){\n var s = ((+(ayin[i][0]*ayin[i][1])) + (+(ayin[r][0]*ayin[r][1])))\n if((s>round)&&(s=xy[0]*xy[1])&&(fps0<=lastspace)){\n\n var s = true ;if((fps0==lastspace)&&(seconditem[1]>e)){s=false}\n if(s==true){\n e = seconditem[1];lastspace= fps0;round =((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}} \n\n\n if((fps1>=xy[0]*xy[1])&&(fps1<=lastspace)){\n s = true ;if((fps1==lastspace)&&(seconditem[0]>e)){s=false}\n if(s==true){\n e = seconditem[0];lastspace=fps1;round = ((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}}\n \n }if(z===0){z+=1;r-=1}\n }\n print(round);\n \n"}, {"source_code": "var rline = readline().split(\" \");var xy = [+rline[1],+rline[2]];\nvar round = [0];\nvar ayinput = [];for(var o=0;o0){\n\n if ((toot[x][0] >= b[0]) && (toot[x][1]>=b[0])){\n round.push((+(ayinput[i][0]*ayinput[i][1])) + (+(ayinput[r][0]*ayinput[r][1])))\n if(round[round.length - 1]>xy[0]*xy[1])round[round.length - 1] = 0;\n }\n \n if ((toot[x][1] >= b[0]) && (toot[x][0]>=b[1])){\n round.push((+(ayinput[i][0]*ayinput[i][1])) + (+(ayinput[r][0]*ayinput[r][1])))\n if(round[round.length - 1]>xy[0]*xy[1])round[round.length - 1] = 0;\n }\n }\n\n\n}\n}\n\n\nprint(Math.max(...round))\n\n\n"}, {"source_code": "var rline = readline().split(\" \");var xy = [+rline[1],+rline[2]];\nvar round = [0];\nvar ayinput = [];for(var o=0;o0){\n\n if ((toot[x][0] >= b[0]) && (toot[x][1]>=b[1])){\n round.push((+(ayinput[i][0]*ayinput[i][1])) + (+(ayinput[r][0]*ayinput[r][1])))\n if(round[round.length - 1]>xy[0]*xy[1])round[round.length - 1] = 0;\n }\n \n if ((toot[x][1] >= b[0]) && (toot[x][0]>=b[1])){\n round.push((+(ayinput[i][0]*ayinput[i][1])) + (+(ayinput[r][0]*ayinput[r][1])))\n if(round[round.length - 1]>xy[0]*xy[1])round[round.length - 1] = 0;\n }\n }\n\n\n}\n}\n\n\nprint(Math.max(...round))\n\n\n"}, {"source_code": "\n var rline = readline().split(\" \");var xy = [rline[1],rline[2]];\n\n\n var temp = [];for(var o=0;o=xy[0]*xy[1]){if((fps0<=lastspace)&&(seconditem[1]<=e) ){ \n \n e = seconditem[1];lastspace= fps0;round =((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}} \n\n\n if(fps1>=xy[0]*xy[1]){if((fps1<=lastspace)&&(seconditem[0]<=e)){\n \n e = seconditem[0];lastspace=fps1;round = ((temp[r][0]*temp[r][1])+(temp[m][0]*temp[m][1]));}}\n \n }if(z===0){z+=1;r-=1}\n }\n print(round);\n"}], "src_uid": "1ad63f41943e40aa8c8d5c88c29c283c"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar count = 0;\n\t\tlist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(list[j] <= j + 1){\n\t\t\t\tcount = j + 1;\n\t\t\t}\n\t\t}\n\t\toutput[i] = count + 1;\n\t}\n\tmyout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n arr.sort((a, b) => a-b)\n let acc = 1\n let buffer = 0\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function ladies (n, arr) {\n arr.sort((a, b) => a > b ? 1 : -1);\n let present = 1;\n let itr = 0;\n let j = n - 1;\n\n while (j >= 0 && itr < n) {\n let now = ((j - itr) + 1);\n if (arr[j] <= (now + present - 1)) {\n present += now;\n itr = j + 1;\n j = n - 1;\n }\n else {\n if ((itr === j) || (itr === n-1) || (itr > j)) return present;\n j -= 1;\n }\n }\n return present;\n}\n\nfunction processData(input) {\n let inpArr = input.split(\"\\n\");\n let n = parseInt(inpArr[0]);\n\n for (let i = 1; i < inpArr.length - 1; i += 2) {\n console.log(ladies(parseInt(inpArr[i]), inpArr[i+1].split(' ').map(val => parseInt(val))));\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString.push(inputStdin);\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.join('').trim().split('\\n').map(string => string.trim());\n \n //withTiming(main);\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst withTiming = callback => {\n const start = new Date();\n callback();\n console.log(`Took ${new Date() - start} ms`);\n}\n\nfunction main() {\n const n = Math.floor(readline());\n const inputs = [];\n\n for (let i = 0; i < n; i++) {\n const m = parseInt(readline());\n const grannies = readline().split(' ').map(granny => parseInt(granny));\n let possibleGrannies = m + 1, i = 0;\n grannies.sort((a, b) => b - a);\n\n while (grannies[i] >= possibleGrannies) {\n i++;\n possibleGrannies--;\n }\n\n console.log(possibleGrannies);\n }\n}\n\n//1 1 4 5 4 9\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString.push(inputStdin);\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.join('').trim().split('\\n').map(string => string.trim());\n \n //withTiming(main);\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst withTiming = callback => {\n const start = new Date();\n callback();\n console.log(`Took ${new Date() - start} ms`);\n}\n\nfunction main() {\n const n = Math.floor(readline());\n const inputs = [];\n\n for (let i = 0; i < n; i++) {\n const m = parseInt(readline());\n const grannies = readline().split(' ').map(granny => parseInt(granny));\n let currentGrannies = 1, k = 0;\n grannies.sort();\n\n while(k < grannies.length) {\n if (grannies[k] <= currentGrannies) {\n currentGrannies++;\n k++;\n } else {\n let j = grannies[k];\n\n if (grannies[j] <= j + 1) {\n currentGrannies = j + 2;\n k = j + 1;\n } else {\n k = grannies.length;\n }\n }\n }\n console.log(currentGrannies);\n }\n}\n\n//1 1 4 5 5 9\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString.push(inputStdin);\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.join('').trim().split('\\n').map(string => string.trim());\n \n //withTiming(main);\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst withTiming = callback => {\n const start = new Date();\n callback();\n console.log(`Took ${new Date() - start} ms`);\n}\n\nfunction main() {\n const n = Math.floor(readline());\n const inputs = [];\n\n for (let i = 0; i < n; i++) {\n const m = parseInt(readline());\n const grannies = readline().split(' ').map(granny => parseInt(granny));\n let k = 0, result = grannies.length + 1;\n grannies.sort();\n\n while(k < grannies.length) {\n if (grannies[k] <= k + 1) {\n k++;\n } else {\n let j = grannies[k];\n\n if (grannies[j] <= j + 1) {\n k = j + 1;\n } else {\n result = k + 1;\n k = grannies.length;\n }\n }\n }\n\n console.log(result);\n }\n}\n\n//1 1 4 5 4 9\n"}], "src_uid": "718cea81f609055cece58cae5310f703"} {"source_code": "var wires = parseInt(readline());\nvar arr = readline().split(\" \").map(Number);\nvar shoots = parseInt(readline());\n\nfor (var i = 0; i < shoots; i++) {\n var current = readline().split(\" \").map(Number);\n var k = current[0];\n var n = current[1];\n \n if (k !== 1) { \n arr[k - 2] += n - 1; // arr[k - 2] is nothing but arr[(k - 1) - 1]\n }\n\n if (k !== arr.length) {\n arr[k] += arr[k - 1] - n; // arr[k] is nothing but arr[(k - 1) + 1]\n }\n\n arr[k - 1] = 0;\n}\n\nprint(arr.join(\" \"));", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let n = parseInt(readline());\n let a = readint();\n let m = parseInt(readline());\n let xy = [];\n for (let i = 0; i < m; i++) {\n let xly = readint();\n xy.push(xly); \n }\n for (let i = 0; i < m; i++) { \n \n let x = xy[i][0];\n let y = xy[i][1];\n x--;\n y--;\n if(x != 0) {\n a[x - 1] += y;\n }\n if(x != n - 1) {\n a[x + 1] += a[x] - y - 1;\n }\n a[x] = 0;\n }\n for (let i = 0; i < a.length; i++) {\n write(a[i] + \"\\n\"); \n } \n}"}, {"source_code": "var n = +readline();\nvar a = ('0 ' + readline() + ' 0').split(' ').map(Number);\nvar m = +readline();\nwhile( m-- ){\n\t+function(x, y){\n\t\ta[x-1] += y-1;\n\t\ta[x+1] += a[x]-y;\n\t\ta[x] = 0;\n\t}.apply(0, readline().split(' ').map(Number));\n}\na.shift();\na.pop();\nprint(a.join('\\n'));"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nA = readline().split(\" \");\nip = readline().split(\" \");\nm = parseInt(ip[0]);\nvar B = new Array();\nfor (var i = 0; i < m; i++){\n\tB[i] = readline().split(\" \");\n\tif (B[i][0]-1 > 0) A[B[i][0]-2] = parseInt(A[B[i][0]-2]) + parseInt(B[i][1]-1);\n\tif (B[i][0]-1 < n-1) A[B[i][0]] = parseInt(A[B[i][0]]) + parseInt(A[B[i][0]-1]) - parseInt(B[i][1]);\n\tA[B[i][0]-1] = 0;\n}\nfor (var i = 0; i < n; i++){\n\twrite(A[i] + \"\\n\");\n}\n"}, {"source_code": "var numberOfLines = readline()\n var lines = readline().split(' ').map(Number)\n var numberOfShoots = readline()\n\n for (var i = 0; i < numberOfShoots; i++) {\n var shootPositions = readline().split(' ').map(Number)\n var lineIndex = shootPositions[0] - 1\n var index = shootPositions[1]\n\n var currentNumberOfBirds = lines[lineIndex]\n\n if (lineIndex - 1 >= 0) lines[lineIndex - 1] += (index - 1)\n if (lineIndex + 1 < lines.length) lines[lineIndex + 1] += currentNumberOfBirds - index\n lines[lineIndex] = 0\n }\n\n for (var i = 0; i < lines.length; i++) {\n print(lines[i])\n }"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar a = readline().split(' ').map(Number);\n\tvar m = +readline();\n\tvar x = [];\n\tfor (var i = 0; i < m; i++) x.push( readline().split(' ').map(Number) );\n\n\tfor (var i = 0; i < m; i++) {\n\t\tif (x[i][0] != 1) a[x[i][0] - 2] += x[i][1] - 1;\n\t\tif (x[i][0] != n) a[x[i][0]] += a[x[i][0] - 1] - x[i][1];\n\t\ta[x[i][0] - 1] = 0; // poor bird\n\t}\n\n\tprint( a.join('\\n') );\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar wireNum = parseInt(readline());\n\tvar wires = tokenizeIntegers(readline());\n\twires.unshift(null);\n\n\tvar jumpNum = parseInt(readline());\n\tfor (var i = 0; i < jumpNum; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar r = integers[0], c = integers[1];\n\t\tif (r > 1) {\n\t\t\twires[r-1] += c-1;\n\t\t}\n\t\tif (r < wireNum) {\n\t\t\twires[r+1] += wires[r]-c;\n\t\t}\n\t\twires[r] = 0;\n\t}\n\n\tprint(wires.slice(1).join('\\n'));\n}\n\nmain();\n"}, {"source_code": "var n = readline(),\n\ta = readline().split(\" \").map(Number),\n\tm = readline(), x = [];\nfor (var i = 0; i < m; i++) {\n\tx[i] = readline().split(\" \").map(Number);\n\tvar v = x[i][0] - 1;\n\ta[v + 1] += a[v] - x[i][1];\n\ta[v] = 0;\n\ta[v - 1] += x[i][1] - 1;\n}\nfor (var i = 0; i < n; i++) {\n\tprint(a[i]);\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineCounter = 1;\nlet birdsPerLine = [];\nlet shotsArr = [];\nlet numOfShots;\n\nrl.on('line', (input) => {\n if (lineCounter === 1) {\n lineCounter++;\n return;\n }\n if (lineCounter === 2) {\n let line = input.split(' ');\n line.forEach(ele => {\n birdsPerLine.push(parseInt(ele));\n })\n } else if (lineCounter === 3) {\n numOfShots = parseInt(input);\n if (numOfShots === 0) {\n rl.close();\n solve(birdsPerLine, shotsArr);\n birdsPerLine.forEach(ele => {\n console.log(ele);\n })\n }\n } else if (lineCounter <= 3 + numOfShots) {\n let line = input.split(' ');\n shotsArr.push([parseInt(line[0]), parseInt(line[1])]);\n if (lineCounter === 3 + numOfShots) {\n rl.close();\n solve(birdsPerLine, shotsArr);\n birdsPerLine.forEach(ele => {\n console.log(ele);\n })\n }\n }\n lineCounter++;\n});\n\n\n\nconst solve = (birdsPerLine, shotsArr) => {\n shotsArr.forEach(shot => {\n let line = shot[0];\n let shootedBird = shot[1];\n let currentBirds = birdsPerLine[line - 1];\n let leftBird = shootedBird - 1;\n let rightBirds = currentBirds - shootedBird;\n birdsPerLine[line - 1] = 0;\n if (birdsPerLine[line - 2] || birdsPerLine[line - 2] === 0) birdsPerLine[line - 2] += leftBird;\n if (birdsPerLine[line] || birdsPerLine[line] === 0) birdsPerLine[line] += rightBirds;\n });\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n const m = +readline();\n for (let i = 0; i < m; i++) {\n const [x, y] = readline().split(' ').map(x => parseInt(x));\n if (x !== 1) {\n a[x-1-1] += y - 1;\n }\n if (x !== n) {\n a[x+1-1] += a[x-1] - y;\n }\n a[x-1] = 0;\n }\n // output\n a.forEach(x => print(`${x}\\n`));\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet wires;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n wires = d.split(' ').map(Number);\n return;\n }\n\n if (c == 2) {\n c++;\n return;\n }\n\n const [x, y] = d.split(' ').map(Number);\n let curr = x - 1;\n let up = curr - 1;\n let down = curr + 1;\n\n let birds = wires[curr];\n let upBirds = y - 1;\n let downBirds = birds - y;\n wires[curr] = 0;\n\n if (wires[up] !== undefined) {\n wires[up] = wires[up] + upBirds;\n }\n\n if (wires[down] !== undefined) {\n wires[down] = wires[down] + downBirds;\n }\n c++;\n});\n\nrl.on('close', () => {\n for (let i = 0; i < wires.length; i++) {\n console.log(wires[i]);\n }\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nconst mapFunc = (arr) => {\n return arr.map((b) => parseInt(b));\n}\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nconst n = parseInt(input[0], 10);\nlet a = input[1].split(' ');\na = a.map((b) => parseInt(b));\nconst m = parseInt(input[2], 10);\nfor (let i=3; i < m+3; i++) {\n let xy = input[i].split(' ');\n xy = mapFunc(xy);\n xy[0] -= 1;\n const wentUp = xy[1] - 1;\n const wentDown = parseInt(a[xy[0]], 10) - wentUp - 1;\n if (xy[0] > 0) {\n a[xy[0] - 1] = a[xy[0] - 1] + wentUp;\n }\n if (xy[0] < n-1) {\n a[xy[0] + 1] = a[xy[0] + 1] + wentDown;\n }\n a[xy[0]] = 0;\n}\nfor (const e of a) {\n console.log(e);\n}\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet wires;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n wires = [0, ...d.split(' ').map(Number), 0];\n return;\n }\n\n if (c == 2) {\n c++;\n return;\n }\n\n const [x, y] = d.split(' ').map(Number);\n\n wires[x - 1] += y - 1;\n wires[x + 1] += wires[x] - y;\n wires[x] = 0;\n\n c++;\n});\n\nrl.on('close', () => {\n for (let i = 1; i < wires.length - 1; i++) {\n console.log(wires[i]);\n }\n});\n"}], "negative_code": [{"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nA = readline().split(\" \");\nip = readline().split(\" \");\nm = parseInt(ip[0]);\nvar B = new Array();\nfor (var i = 0; i < m; i++){\n\tB[i] = readline().split(\" \");\n\tif (B[i][0]-1 > 0) A[B[i][0]-2] += B[i][1]-1;\n\tif (B[i][0]-1 < n-1) A[B[i][0]] += A[B[i][0]-1] - B[i][1];\n\tA[B[i][0]-1] = 0;\n}\nfor (var i = 0; i < n; i++){\n\twrite(A[i] + \"\\n\");\n}\n"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar a = readline().split(' ').map(Number);\n\tvar m = +readline();\n\tvar x = [];\n\tfor (var i = 0; i < m; i++) x.push( readline().split(' ').map(Number) );\n\n\tfor (var i = 0; i < m; i++) {\n\t\tif (x[i][0] != 1) a[x[i][0] - 2] += x[i][1] - 1;\n\t\tif (x[i][0] != n) a[x[i][0] - 1] += a[x[i][0] - 1] - x[i][1];\n\t\ta[x[i][0] - 1] = 0; // poor bird :-(\n\t}\n\n\tprint( a.join('\\n') );\n\n}).call(this);"}, {"source_code": "var wires = parseInt(readline());\nvar arr = readline().split(\" \").map(Number);\nvar shoots = parseInt(readline());\n\nfor (var i = 0; i < shoots; i++) {\n var current = readline().split(\" \").map(Number);\n var k = current[0];\n var n = current[1];\n \n if (arr[(k -1) -1]) { \n arr[(k -1) -1] += n - 1;\n }\n\n if (arr[(k - 1) + 1]) {\n arr[(k - 1) + 1] += arr[k - 1] - n;\n }\n\n arr[k - 1] = 0;\n}\n\nprint(arr.join(\" \"));"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineCounter = 1;\nlet birdsPerLine = [];\nlet shotsArr = [];\nlet numOfShots;\n\nrl.on('line', (input) => {\n if (lineCounter === 1) {\n lineCounter++;\n return;\n }\n if (lineCounter === 2) {\n let line = input.split(' ');\n line.forEach(ele => {\n birdsPerLine.push(parseInt(ele));\n })\n } else if (lineCounter === 3) {\n numOfShots = parseInt(input);\n } else if (lineCounter <= 3 + numOfShots) {\n let line = input.split(' ');\n shotsArr.push([parseInt(line[0]), parseInt(line[1])]);\n if (lineCounter === 3 + numOfShots) {\n rl.close();\n solve(birdsPerLine, shotsArr);\n birdsPerLine.forEach(ele => {\n console.log(ele);\n })\n }\n }\n lineCounter++;\n});\n\n\n\nconst solve = (birdsPerLine, shotsArr) => {\n shotsArr.forEach(shot => {\n let line = shot[0];\n let shootedBird = shot[1];\n let currentBirds = birdsPerLine[line - 1];\n let leftBird = shootedBird - 1;\n let rightBirds = currentBirds - shootedBird;\n birdsPerLine[line - 1] = 0;\n if (birdsPerLine[line - 2] || birdsPerLine[line - 2] === 0) birdsPerLine[line - 2] += leftBird;\n if (birdsPerLine[line] || birdsPerLine[line] === 0) birdsPerLine[line] += rightBirds;\n });\n\n}"}], "src_uid": "859d66fc2c204a8c002012b1fb206645"} {"source_code": "var inp = readline().split(' ');\nvar n = parseInt(inp[0], 10);\nvar d = parseInt(inp[1], 10);\nvar friends = [];\n\nfor (var i = 0; i < n; i++) {\n\tinp = readline().split(' ');\n\tfriends.push({\n\t\tm: parseInt(inp[0], 10),\n\t\ts: parseInt(inp[1], 10)\n\t});\n}\n\nfriends = friends.sort(function (a, b) {\n\treturn a.m - b.m;\n});\n\nvar result = count(friends, d);\n\nwrite(result);\n\nfunction count(friends, d) {\n\tvar maxF = 0;\n\tvar m = 0;\n\tvar s = 0;\n\tvar f = friends[s].s;\n\n\twhile (s < friends.length - 1) {\n\t\ts++;\n\t\tf += friends[s].s;\n\t\tif (friends[s].m - friends[m].m >= d) {\n\t\t\tmaxF = Math.max(maxF, f - friends[s].s);\n\t\t\twhile (friends[s].m - friends[m].m >= d) {\n\t\t\t\tf -= friends[m].s;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\tmaxF = Math.max(maxF, f);\n\treturn maxF;\n}\n", "positive_code": [{"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var d = line[1];\n var friends = [];\n for(var i=0;ia[0]-b[0]);\n var startIndex = 0;\n var max = 0;\n var sum = 0;\n for(var i=0;i= d){\n sum -= friends[startIndex][1];\n startIndex++;\n \n }\n sum += friends[i][1];\n if(sum > max){\n max = sum;\n }\n }\n print(max)\n}\n\n\nmain()"}, {"source_code": "var parsedLine = readline().split(\" \");\nvar n = parseInt(parsedLine[0]);\nvar d = parseInt(parsedLine[1]);\n\nvar friends = [];\nfor (var i = 0; i < n; i++) {\n parsedLine = readline().split(\" \");\n friends.push({\n m: parseInt(parsedLine[0]),\n s: parseInt(parsedLine[1])\n });\n}\nfriends.sort(function(f1, f2) { return f1.m - f2.m; });\n\nvar sums = [0];\nfriends.forEach(function(f, i) { sums.push(f.s + sums[i]); });\n\nvar max = 0;\nfriends.forEach(function(f, i, arr) {\n var j = binarySearch(i, arr.length, function(k) {\n return arr[k].m >= arr[i].m + d;\n });\n var sum = sums[j] - sums[i];\n max = sum > max ? sum : max;\n});\n\nprint(max);\n\nfunction binarySearch(start, end, callback) {\n while(end > start + 1) {\n var mid = start + parseInt((end-start)/2);\n if (callback(mid)) {\n end = mid;\n } else {\n start = mid;\n }\n }\n return end;\n}\n"}, {"source_code": "var input = readline().split(\" \").map(Number), n = input[0], d = input[1], arr = [];\nfor(var i = 0; i < n; i++){\n arr.push(readline().split(\" \").map(Number));\n}\nvar ans = 0;\n\narr.sort(function(a,b){return a[0]-b[0]});\n\nvar a = 0;\nfor(var i = 0; i < n; i++){\n arr[i][1] += a;\n a = arr[i][1];\n}\ndelete a;\n\nfor(var i = 0; i < n; i++){\n var l = i;\n var r = n-1;\n\n while(r-l > 2){\n var m = Math.floor((r+l)/2);\n\n if(arr[m][0] < arr[i][0] + d){\n l = m;\n }\n else{\n r = m;\n }\n }\n\n while(l < r){\n if(arr[l][0] < arr[i][0] + d){\n l++;\n }\n else{\n r = l;\n }\n }\n\n if(arr[l][0] >= arr[i][0] + d){\n l--;\n }\n\n var numb;\n\n if(i == 0){\n numb = arr[l][1];\n }\n else{\n numb = arr[l][1] - arr[i-1][1]\n }\n\n var ans = Math.max(ans, numb);\n}\n\nwrite(ans);"}], "negative_code": [{"source_code": "var input = readline().split(\" \").map(Number), n = input[0], d = input[1], arr = [];\nfor(var i = 0; i < n; i++){\n arr.push(readline().split(\" \").map(Number));\n}\nvar ans = 0;\n\narr.sort(function(a,b){return a[0]-b[0]});\n\nvar a = 0;\nfor(var i = 0; i < n; i++){\n arr[i][1] += a;\n a = arr[i][1];\n}\ndelete a;\n\nfor(var i = 0; i < n; i++){\n var l = i;\n var r = n-1;\n\n while(r-l > 2){\n var m = Math.floor((r+l)/2);\n\n if(arr[m][0] < arr[m][0] + d){\n l = m;\n }\n else{\n r = m;\n }\n }\n\n while(l < r){\n if(arr[l][0] < arr[i][0] + d){\n l++;\n }\n else{\n r = l;\n }\n }\n\n if(arr[l][0] >= arr[i][0] + d){\n l--;\n }\n\n var numb;\n\n if(i == 0){\n numb = arr[l][1];\n }\n else{\n numb = arr[l][1] - arr[i-1][1]\n }\n\n var ans = Math.max(ans, numb);\n}\n\nwrite(ans);"}, {"source_code": "var inp = readline().split(' ');\nvar n = parseInt(inp[0], 10);\nvar d = parseInt(inp[1], 10);\nvar friends = [];\n\nfor (var i = 0; i < n; i++) {\n\tinp = readline().split(' ');\n\tfriends.push({\n\t\tm: parseInt(inp[0], 10),\n\t\ts: parseInt(inp[1], 10)\n\t});\n}\n\nfriends = friends.sort(function (a, b) {\n\treturn a.m > b.m;\n});\n\nvar result = count(friends, d);\n\nwrite(result);\n\nfunction count(friends, d) {\n\tvar maxF = 0;\n\tvar m = 0;\n\tvar s = 0;\n\tvar f = friends[s].s;\n\n\twhile (s < friends.length - 1) {\n\t\ts++;\n\t\tf += friends[s].s;\n\t\tif (friends[s].m - friends[m].m >= d) {\n\t\t\tmaxF = Math.max(maxF, f - friends[s].s);\n\t\t\twhile (friends[s].m - friends[m].m >= d) {\n\t\t\t\tf -= friends[m].s;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\tmaxF = Math.max(maxF, f);\n\treturn maxF;\n}\n"}], "src_uid": "38fe0e19974a7bc60153793b9060369a"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n\r\n var x = []\r\n var y = []\r\n for (let i = 0; i < n; i++) {\r\n var [xx, yy] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n y.push(yy)\r\n x.push(xx)\r\n }\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var ans = 0\r\n var ans1 = 0\r\n for (let i = 0; i < n; i++) {\r\n if (i === 0) {\r\n ans += x[i] - 0 + a[i]\r\n } else {\r\n ans += x[i] - y[i - 1] + a[i]\r\n }\r\n ans1 = ans\r\n ans += Math.ceil((y[i] - x[i]) / 2)\r\n\r\n ans = Math.max(y[i], ans)\r\n }\r\n\r\n // if(n>=1) ans-=a[n-1]\r\n\r\n console.log(ans1)\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N + 1);\r\n\t\tlist[0] = {\r\n\t\t\ta : 0,\r\n\t\t\tb : 0,\r\n\t\t\tv : 0\r\n\t\t};\r\n\t\tfor(var j = 1; j <= N; j++){\r\n\t\t\tlist[j] = {\r\n\t\t\t\ta : nextInt(),\r\n\t\t\t\tb : nextInt(),\r\n\t\t\t\tv : 0\r\n\t\t\t};\r\n\t\t}\r\n\t\tfor(var j = 1; j <= N; j++){\r\n\t\t\tlist[j].v = nextInt();\r\n\t\t}\r\n\t\tvar now = 0;\r\n\t\tfor(var j = 1; j <= N; j++){\r\n\t\t\tnow += list[j].a - list[j - 1].b + list[j].v;\r\n\t\t\tif(j == N){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tnow += Math.ceil((list[j].b - list[j].a) / 2);\r\n\t\t\tif(list[j].b > now){\r\n\t\t\t\tnow = list[j].b;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(now);\r\n\t}\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10);\r\n }\r\nvar t = parseInt(readline(), 10);\r\nfor(var it = 0; it> 1;\r\n if (time < b[i]) {\r\n time = b[i];\r\n }\r\n }\r\n }\r\n write(time);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var a = [];\r\n var b = [];\r\n for (var i = 0; i < n; i++) {\r\n var ab = readArray(Number);\r\n a[i] = ab[0];\r\n b[i] = ab[1];\r\n }\r\n var tm = readArray(Number);\r\n var total = a[0] + tm[0] + n;\r\n for (var i = 1; i < n; i++) {\r\n total += a[i] + tm[i] - b[i - 1];\r\n }\r\n write(total);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var a = [];\r\n var b = [];\r\n for (var i = 0; i < n; i++) {\r\n var ab = readArray(Number);\r\n a[i] = ab[0];\r\n b[i] = ab[1];\r\n }\r\n var tm = readArray(Number);\r\n var total = a[0] + tm[0] + n;\r\n for (var i = 1; i < n; i++) {\r\n write(total);\r\n total += a[i] + tm[i] - b[i - 1];\r\n }\r\n write(total + '\\n' );\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "42840fc873369e0d0d6a4ad24a43f5a6"} {"source_code": "function readIntTabLine() {\n var l = readline().split(' ')\n for (var i = 0 ; i < l.length ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar given = readIntTabLine(),\n mdps = []\n\nfor (var i = 0 ; i < given[0] ; i++) {\n mdps.push(readline())\n}\n\nvar good = readline()\n\nmdps.sort((a,b) => a.length-b.length)\nvar imin = imax = mdps.findIndex((v,i,a) => v.length==good.length),\n min = Math.floor(imin/given[1])*5 + imin + 1\nwhile (imax < mdps.length && mdps[imax].length == good.length) imax++\nvar max = Math.floor((imax-1)/given[1])*5 + imax\n\nprint(min,max)\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const nums = readline().split(\" \").map(x => parseInt(x));\n const n = nums[0];\n const k = nums[1];\n const passwordLengths = new Map();\n for (let i=0; i a[0]-b[0])) {\n if (key {\n if (key < len_pwd) {\n min_try += value\n }\n if (key <= len_pwd) {\n max_try += value\n }\n\n});\nprint([min_try + ((min_try - 1) / k | 0) * 5, max_try + ((max_try - 1)/ k | 0) * 5].join(' '));"}, {"source_code": "//Define variable and get input\nvar stats = readline().split(' '), \n count = +stats[0], \n fail = +stats[1], \n i, answer,\n input = [],\n out = \"\";\n \nfor (i = 0; i < count; i++){\n input.push(readline());\n}\n\nanswer = readline();\n// Define helper function\nfunction getFail(){\n var _fail = 0;\n for(i = fail; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n//Begin\nworst = input.filter(function(a){\n return ((a).toString().length <= (answer).toString().length);\n});\ninput = input.filter(function(a){\n return ((a).toString().length < (answer).toString().length)\n || a === (answer);\n \n});\ncount = input.length;\nif (input.length < fail){\n out += input.length + \" \";\n}\nelse {\n out+= ((getFail() * 5) + count) + \" \";\n}\ncount = worst.length;\nout += (count <= fail ? count : ((getFail() * 5) + count));\n\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = fail; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n worst = input.filter(function(a){\n return ((a).toString().length <= (answer||'22').toString().length);\n });\n input = input.filter(function(a){\n return ((a).toString().length < (answer||'22').toString().length)\n || a === (answer || '22');\n \n });\n count = input.length;\n if (input.length < fail){\n out += input.length + \" \";\n }\n else {\n out+= ((getFail() * 5) + count) + \" \";\n }\n count = worst.length;\n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "//Define variable and get input\nvar stats = readline().split(' '), \n count = +stats[0], \n fail = +stats[1], \n i, answer,\n input = [],\n out = \"\";\n \nfor (i = 0; i < count; i++){\n input.push(readline());\n}\n\nanswer = readline();\n// Define helper function\nfunction getFail(){\n var _fail = 0;\n for(i = fail; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nif (count === 1){\n out = '1 1';\n} \nelse {\n worst = input.filter(function(a){\n return ((a).toString().length <= (answer||'22').toString().length);\n });\n input = input.filter(function(a){\n return ((a).toString().length < (answer||'22').toString().length)\n || a === (answer || '22');\n \n });\n count = input.length;\n if (input.length < fail){\n out += input.length + \" \";\n }\n else {\n out+= ((getFail() * 5) + count) + \" \";\n }\n count = worst.length;\n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let lengthMap = new Map()\n for (let i = 0; i < numOfPasswords; i++) {\n const passwordLength = readline().length\n lengthMap.set(passwordLength, (lengthMap.get(passwordLength) || 0) + 1)\n }\n\n const correct = readline();\n\n helper(lengthMap, tries, correct.length)\n}\n\nfunction helper(lengthMap, tries, correctLength) {\n let best = 0\n for (let i = 1; i < correctLength; i++) {\n if (lengthMap.has(i)) {\n best += lengthMap.get(i)\n }\n }\n let worst = best + lengthMap.get(correctLength) - 1;\n\n best += Math.floor(best / tries) * 5\n worst += Math.floor(worst / tries) * 5\n\n console.log((best + 1) + ' ' + (worst + 1))\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let lengthMap = new Map()\n for (let i = 0; i < numOfPasswords; i++) {\n const passwordLength = readline().length\n lengthMap.set(passwordLength, (lengthMap.get(passwordLength) || 0) + 1)\n }\n\n const correct = readline();\n\n helper(lengthMap, tries, correct.length)\n}\n\nfunction helper(lengthMap, tries, correctLength) {\n let tryTimes = 0\n for (let i = 1; i < correctLength; i++) {\n if (lengthMap.has(i)) {\n tryTimes += lengthMap.get(i)\n }\n }\n let best = tryTimes + 1 + (tryTimes + 1 > tries ? Math.floor(tryTimes + 1 / tries) * 5 : 0)\n\n tryTimes += lengthMap.get(correctLength)\n\n let worse = tryTimes + (tryTimes > tries ? Math.floor(tryTimes / tries) * 5 : 0)\n\n console.log(best + ' ' + worse)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n\n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n console.log(passwords)\n\n let i = 0\n let cnt = 0\n let min = 0\n\n while (correct.length !== passwords[i].length) {\n i++\n cnt++\n min++\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n }\n\n let max = min\n while (i < passwords.length && correct.length >= passwords[i].length) {\n i++\n cnt++\n max++\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n }\n\n console.log(min + ' ' + max)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n\n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 1\n\n while (correct.length !== passwords[i].length) {\n i++\n cnt++\n min++\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n }\n \n let max = min - 1\n while (i < passwords.length && correct.length >= passwords[i].length) {\n i++\n cnt++\n max++\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n }\n\n console.log(min + ' ' + max)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n \n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n if (passwords.length === 1) return 1\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 1\n\n while (correct.length !== passwords[i].length) {\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n i++\n cnt++\n min++\n }\n \n let max = min - 1\n while (i < passwords.length && correct.length >= passwords[i].length) {\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n i++\n cnt++\n max++\n }\n\n console.log(min + ' ' + max)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n\n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 0\n do {\n i++\n cnt++\n min++\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n } while (correct.length !== passwords[i].length)\n\n let max = min\n while (i < passwords.length && correct.length >= passwords[i].length) {\n i++\n cnt++\n max++\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n }\n\n console.log(min + ' ' + max)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n \n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n if (passwords.length === 1) {\n console.log('1 1')\n return\n }\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 1\n\n while (correct.length !== passwords[i].length) {\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n i++\n cnt++\n min++\n }\n\n let max = min - 1\n while (i < passwords.length && correct.length >= passwords[i].length) {\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n i++\n cnt++\n max++\n }\n\n console.log(min + ' ' + max)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n \n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n if (passwords.length === 1) {\n console.log('1 1')\n return\n }\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 1\n\n while (correct.length !== passwords[i].length) {\n i++\n cnt++\n min++\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n }\n \n let max = min - 1\n while (i < passwords.length && correct.length >= passwords[i].length) {\n i++\n cnt++\n max++\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n }\n\n console.log(min + ' ' + max)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(inp => parseInt(inp));\n const [numOfPasswords, tries] = input\n let passwords = []\n for (let i = 0; i < numOfPasswords; i++) {\n passwords.push(readline())\n }\n \n const correct = readline();\n\n helper(passwords, tries, correct)\n}\n\nfunction helper(passwords, tries, correct) {\n passwords.sort((p1,p2)=>p1.length - p2.length)\n\n let i = 0\n let cnt = 0\n let min = 0\n\n while (correct.length !== passwords[i].length) {\n i++\n cnt++\n min++\n if (cnt === tries) {\n min += 5\n cnt = 0\n }\n }\n\n let max = min\n while (i < passwords.length && correct.length >= passwords[i].length) {\n i++\n cnt++\n max++\n if (cnt === tries) {\n max += 5\n cnt = 0\n }\n }\n\n console.log(min + ' ' + max)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const nums = readline().split(\" \").map(x => parseInt(x));\n const n = nums[0];\n const k = nums[1];\n const passwordLengths = new Map();\n for (let i=0; i {\n if (key < len_pwd) {\n min_try += value\n }\n if (key <= len_pwd) {\n max_try += value\n }\n});\nprint([min_try + (min_try / k | 0) * 5, max_try + (max_try / k | 0) * 5].join(' '));"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer||11).toString().length});\n count = input.length;\n \n out += input.length+1 + \" \";\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n\n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + ((getFail() * 5) + count);\n \n}\nelse {\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n \n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count < fail ? count : ((getFail() * 5) + count))\n}\nprint(out);\n\n"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer || 100).toString().length});\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n\n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + ((Math.floor(count/fail) * 5) + count);\n \n}\nelse {\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n \n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count < fail ? count : ((Math.floor(count/fail) * 5) + count))\n}\nprint(out);\n\n"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer||10).toString().length});\n input = input.sort(function(a,b){return (a).toString().length > (b).toString().length;});\n count = input.length;\n print(input.toString());\n input.forEach(function(a, i){\n if (a === answer) out += i+1 + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer||111).toString().length});\n count = input.length;\n input = input.filter(function(a){return (a).toString().length < (answer||101).toString().length});\n \n if (input.length < fail){\n out += input.length+1 + \" \";\n }\n else {\n out+= ((getFail() * 5) + count) + \" \";\n }\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer).toString().length});\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n\n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (sameLength){\n out = \"1 \" + ((Math.floor(count/fail) * 5) + count);\n \n}\nelse {\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n \n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count < fail ? count : ((Math.floor(count/fail) * 5) + count))\n}\nprint(out);\n\n"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer).toString().length});\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n count = input.length;\n input.forEach(function(a, i){\n if (a === answer) out += i+1 + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer||10).toString().length});\n count = input.length;\n input = input.filter(function(a){return (a).toString().length < (answer||10).toString().length});\n \n out += input.length+1 + \" \";\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\n\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.filter(function(a){return (a).toString().length <= (answer).toString().length});\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n count = input.length;\n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);"}, {"source_code": "var stats = readline().split(' '), count = +stats[0], fail = +stats[1], i, input = [], answer, out = \"\";\nfor (i = 0; i < count; i++){\n input.push(readline());\n}\nanswer = readline();\nfunction getFail(){\n var _fail = 0;\n for(i = 1; i < count; i+=fail){\n _fail++;\n }\n return _fail;\n}\n\nvar sameLength = input.every(function(a){\n return (a).toString().length === (input[0]).toString().length; \n});\n\nif (count === 1){\n out = '1 1';\n} \nelse if (sameLength){\n out = \"1 \" + (count <= fail ? count : ((getFail() * 5) + count));\n \n}\nelse {\n input = input.sort(function(a,b){return (a).toString() > (b).toString();});\n \n input.forEach(function(a, i){\n if (a === answer) out += i + \" \";\n });\n \n out += (count <= fail ? count : ((getFail() * 5) + count))\n}\nprint(out);\n\n"}], "src_uid": "06898c5e25de2664895f512f6b766915"} {"source_code": "var n = readline();\nvar a =0; var b =0;\n\tfor (var i=0; i<+n; i++){\n\tvar str = readline().split(\" \");\n\t\tif (+str[1]>+str[0]) a = 1;\n\t\telse if (+str[1]<+str[0]) b = 1;\n\t}\na&&b==1? print(\"Happy Alex\"):print(\"Poor Alex\");", "positive_code": [{"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n\n const pairs = [];\n for (let i = 1; i <= n; i += 1) {\n const [a, b] = input[i].split(' ').map(x => parseInt(x));\n pairs.push([a, b]);\n }\n\n pairs.sort( (a, b) => a[0] - b[0] );\n\n let flag = false;\n for (let i = 1; i < pairs.length; i += 1) {\n if (pairs[i][1] < pairs[i-1][1]) {\n flag = true; break;\n } \n }\n\n console.log(flag ? 'Happy Alex' : 'Poor Alex');\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet c=0\n\twhile(t--){\n\t\tlet [a,b] = readLine().split(\" \").map(n=>+n)\n\t\tif(b>a)\n\t\t\tc++\n\t}\n\tif(c)\n\t\tconsole.log('Happy Alex')\n\telse console.log('Poor Alex')\n}"}, {"source_code": "var n = readline();\nvar a = [];\nvar can = false;\nfor (i = 0 ; i < n ; i ++)\n{\n a.push(readline().split(' ').map(Number));\n}\na.sort(function(x,y){return x[0] < y[0] ? -1 : (((x[0]==y[0])&&(x[1] a[i][1]){can = true ;}\n maxi = Math.max(maxi,a[i][1]);\n}\nwrite(can ? \"Happy Alex\" : \"Poor Alex\");"}, {"source_code": "\n// 456A \u041d\u043e\u0443\u0442\u0431\u0443\u043a\u0438 \n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\n\nvar arr = [];\nvar out;\n\nfor (var i = 0; i < n; i++) {\n arr[i] = [];\n arr[i] = readline().split(' ').map(Number);\n};\n\narr.sort(function(a,b){return a[0] - b[0];});\n\nvar flag = true;\n\nfor (var i = 0; i < n-1; i++) {\n if (arr[i][1] > arr[i+1][1]) flag = false;\n};\n\nif (flag) {\n out = 'Poor Alex\\n';\n} else {\n out = 'Happy Alex\\n';\n};\n\nprint(out);\n"}, {"source_code": "var n=+readline()\nvar T=new Array(n)\nfor (var i=0;i+x))\n}\nT.sort((l,r)=>l[0]==r[0]?(l[1]-r[1]):l[0]-r[0])\nvar happy=false\nfor (var i=0;iT[i+1][1])\n}\nprint(happy?'Happy Alex':'Poor Alex')\n\n"}, {"source_code": "var n = +readline(), array = [], check = true;\nfor(i = 0; i < n; i++){\n\tarray.push(readline().split(\" \").map(Number));\n}\n\narray.sort(function(x,y){return x[0] - y[0]});\n\nfor(i = 0; i < n-1; i++){\n\tif(array[i][1] >= array[i+1][1]){\n\t\twrite(\"Happy Alex\");\n\t\tcheck = false;\n\t\tbreak;\n\t}\n}\n\nif(check){write(\"Poor Alex\")}"}, {"source_code": "function solve() {\n\tfor (var i=1; i<=n; i++) {\n\t\tvar s = new Array();\n\t\ts=readline().split(\" \");\n\t\tif (s[0]!=s[1]) {\n\t\t\tprint(\"Happy Alex\");\n\t\t\treturn;\n\t\t}\n\t}\n\tprint(\"Poor Alex\");\n}\nvar n = readline();\nvar a,b;\nsolve();"}, {"source_code": "var goodAnswer = 'Happy Alex',\n\tbadAnswer = 'Poor Alex';\n\n;(function () {\n\n\tprint((function (n) {\n\n\t\tvar map = {},\n\t\t\tprices = [];\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar str = readline().split(' '),\n\t\t\t\tprice = parseInt(str[0]),\n\t\t\t\tquality = parseInt(str[1]);\n\n\t\t\tif (map[price]) {\n\t\t\t\tmap[price] = [Math.min(map[price][0], quality), Math.max(map[price][1], quality)];\n\t\t\t} else {\n\t\t\t\tmap[price] = [quality, quality];\n\t\t\t\tprices.push(price);\n\t\t\t}\n\t\t}\n\n\t\tprices = prices.sort(function (a, b) { return a - b; });\n\t\tvar pricesLength = prices.length;\n\n\t\tfor (var i = 1; i < pricesLength; i++)\n\t\t\tif (map[prices[i - 1]][1] > map[prices[i]][0])\n\t\t\t\treturn goodAnswer;\n\n\t\treturn badAnswer;\n\n\t})(+readline()));\n\n}).call(this);"}, {"source_code": "/* jshint strict: false, node: true */\n/* globals process */\nvar collection = [],\n count = null;\n\n\nvar input = \"\", readline;\n\nif (typeof process !== \"undefined\") {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf8\");\n\n process.stdin.on(\"data\", function(chunk) {\n input+=chunk;\n });\n\n process.on(\"SIGINT\", function() {\n var inputLineIndex = 0;\n\n input = input.split(\"\\n\");\n print = function(data) {process.stdout.write(data+'\\n')};\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n\n process.exit(main() || 0);\n });\n};\n\n\nfunction parseChunks(chunk) {\n if (count === null) {\n count = parseInt(chunk, 10);\n } else {\n collection.push(new Pc(chunk));\n }\n}\n\nfunction Pc (chunk) {\n var params = chunk.split(\" \");\n\n this.price = parseInt(params[0], 10) || 0;\n this.quality = parseInt(params[1], 10) || 0;\n}\n\nfunction main() {\n var line = readline();\n\n while (line) {\n parseChunks(line);\n line = readline();\n }\n\n try {\n collection.sort(function (a, b) {\n if (a.price > b.price) {\n if (a.quality < b.quality) {\n throw \"Found\";\n }\n return 1;\n }\n if (a.price < b.price) {\n if (a.quality > b.quality) {\n throw \"Found\";\n }\n\n return -1;\n }\n\n return 0;\n });\n\n print(\"Poor Alex\");\n } catch (e) {\n print(\"Happy Alex\");\n }\n\n return 0;\n}\n\nmain();"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tlaptops = [];\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar data = tokenizeIntegers(readline());\n\t\tlaptops.push({ price: data[0], quality: data[1] });\n\t}\n\tlaptops.sort(function (a, b) {\n\t\treturn a.price - b.price;\n\t});\n\tfor (var i = 1; i < n; ++i) {\n\t\tif (laptops[i-1].quality > laptops[i].quality) {\n\t\t\tprint('Happy Alex');\n\t\t\treturn;\n\t\t}\n\t}\n\tprint('Poor Alex');\n}\n\nmain();\n"}, {"source_code": "var main = function(arr)\n{\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (+arr[i][0] !== +arr[i][1]) return 'Happy Alex';\n }\n return 'Poor Alex';\n}\n{\n var num = readline(),\n arrContent = [];\n for (var i = 1; i <= +num; i++)\n {\n arrContent.push(readline().split(' '));\n }\n print(main(arrContent));\n}"}], "negative_code": [{"source_code": "/* jshint strict: false, node: true */\n/* globals process */\nvar collection = [],\n count = null;\n\n\nvar input = \"\", readline;\n\nif (typeof process !== \"undefined\") {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf8\");\n\n process.stdin.on(\"data\", function(chunk) {\n input+=chunk;\n });\n\n process.on(\"SIGINT\", function() {\n var inputLineIndex = 0;\n\n input = input.split(\"\\n\");\n print = function(data) {process.stdout.write(data+'\\n')};\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n\n process.exit(main() || 0);\n });\n};\n\n\nfunction parseChunks(chunk) {\n if (count === null) {\n count = parseInt(chunk, 10);\n } else {\n collection.push(new Pc(chunk));\n }\n}\n\nfunction Pc (chunk) {\n var params = chunk.split(\" \");\n\n this.price = parseInt(params[0], 10) || 0;\n this.quality = parseInt(params[1], 10) || 0;\n}\n\nfunction main() {\n var line = readline();\n\n while (line) {\n parseChunks(line);\n line = readline();\n }\n\n try {\n collection.sort(function (a, b) {\n if (a.price > b.price) {\n if (a.quality < b.quality) {\n throw \"Found\";\n }\n return 1;\n }\n if (a.price < b.price) {\n if (a.quality > b.quality) {\n throw \"Found\";\n }\n\n return -1;\n }\n\n return 0;\n });\n\n print(\"Happy Alex\");\n } catch (e) {\n print(\"Poor Alex\");\n }\n\n return 0;\n}\n\nmain();"}, {"source_code": "function nextRound(k, guys)\n{\n var i = 0, res = 0;\n while (guys[i] >= k)\n {\n res++;\n\t\ti++;\n }\n return res;\n}\n{\n var input1 = readline();\n input1 = input1.split(' ');\n var k = parseInt(input1[1]);\n var input2 = readline();\n print(nextRound(k, input2.split(' ')));\n \n \n \n}"}, {"source_code": "var main = function(arr)\n{\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (+arr[i][0] !== arr[i][1]) return 'Happy Alex';\n }\n return 'Poor Alex';\n}\n{\n var num = readline(),\n arrContent = [];\n for (var i = 1; i <= +num; i++)\n {\n arrContent.push(readline().split(' '));\n }\n print(main(arrContent));\n}"}], "src_uid": "c21a84c4523f7ef6cfa232cba8b6ee2e"} {"source_code": "var s = readline().split(\"\");\n\nvar aCharCode = \"a\".charCodeAt(0);\nvar symbolCount = new Array(26).fill(0);\ns.forEach(c => ++symbolCount[c.charCodeAt(0) - aCharCode]);\nvar i = 0;\nvar j = symbolCount.length - 1;\nwhile (true) {\n while (i < j && symbolCount[i]%2 === 0) {\n ++i;\n }\n while (i < j && symbolCount[j]%2 === 0) {\n --j;\n }\n if (i === j) {\n break;\n } else {\n ++symbolCount[i];\n --symbolCount[j];\n }\n}\n\nvar middle = s.length%2 !== 0 ? String.fromCharCode(i + aCharCode) : \"\";\nvar leftHalf = \"\";\nvar rightHalf = \"\";\nsymbolCount.forEach((count, charCode) => {\n var currentCharSequence = String.fromCharCode(charCode + aCharCode)\n .repeat(Math.floor(count / 2));\n leftHalf += currentCharSequence;\n rightHalf = currentCharSequence + rightHalf;\n});\nwrite(leftHalf + middle + rightHalf + \"\\n\");\n", "positive_code": [{"source_code": "var s = readline().split(\"\");\n\nvar aCharCode = \"a\".charCodeAt(0);\nvar symbolCount = new Array(26).fill(0);\ns.forEach(c => ++symbolCount[c.charCodeAt(0) - aCharCode]);\nvar i = 0;\nvar j = symbolCount.length - 1;\nwhile (true) {\n while (i < j && symbolCount[i]%2 === 0) {\n ++i;\n }\n while (i < j && symbolCount[j]%2 === 0) {\n --j;\n }\n if (i === j) {\n break;\n } else {\n ++symbolCount[i];\n --symbolCount[j];\n }\n}\nvar middle = \"\";\nvar palyndromeHalf = \"\";\nsymbolCount.forEach((count, charCode) => {\n if (count % 2 !== 0) {\n middle = String.fromCharCode(charCode + aCharCode);\n }\n palyndromeHalf += String.fromCharCode(charCode + aCharCode)\n .repeat(Math.floor(count / 2));\n});\nvar palyndrome = palyndromeHalf + middle + palyndromeHalf.split(\"\").reverse().join(\"\");\nwrite(palyndrome + \"\\n\");\n"}], "negative_code": [{"source_code": "var s = readline().split(\"\");\n\nvar aCharCode = \"a\".charCodeAt(0);\nvar symbolCount = new Array(26).fill(0);\ns.forEach(c => ++symbolCount[c.charCodeAt(0) - aCharCode]);\nvar i = 0;\nvar j = symbolCount.length - 1;\nwhile (true) {\n while (i < j && symbolCount[i]%2 === 0) {\n ++i;\n }\n while (i < j && symbolCount[j]%2 === 0) {\n --j;\n }\n if (i === j) {\n break;\n } else {\n ++symbolCount[i];\n --symbolCount[j];\n }\n}\nvar middle = \"\";\nvar palyndromeHalf = \"\";\nsymbolCount.forEach((count, charCode) => {\n if (count % 2 !== 0) {\n middle = String.fromCharCode(charCode + aCharCode)\n .repeat(count);\n } else {\n palyndromeHalf += String.fromCharCode(charCode + aCharCode)\n .repeat(Math.floor(count / 2));\n }\n});\nvar palyndrome = palyndromeHalf + middle + palyndromeHalf.split(\"\").reverse().join(\"\");\nwrite(palyndrome + \"\\n\");\n"}, {"source_code": "var s = readline().split(\"\");\n\nvar aCharCode = \"a\".charCodeAt(0);\nvar symbolCount = new Array(26).fill(0);\ns.forEach(c => ++symbolCount[c.charCodeAt(0) - aCharCode]);\nvar i = 0;\nvar j = symbolCount.length - 1;\nwhile (true) {\n while (i < j && symbolCount[i]%2 === 0) {\n ++i;\n }\n while (i < j && symbolCount[j]%2 === 0) {\n --j;\n }\n if (i === j) {\n break;\n } else {\n ++symbolCount[i];\n --symbolCount[j];\n }\n}\nvar middle = \"\";\nvar palyndromeHalf = \"\";\nsymbolCount.forEach((count, charCode) => {\n if (count % 2 !== 0) {\n middle = String.fromCharCode(charCode + aCharCode);\n } else {\n palyndromeHalf += String.fromCharCode(charCode + aCharCode)\n .repeat(Math.floor(count / 2));\n }\n});\nvar palyndrome = palyndromeHalf + middle + palyndromeHalf.split(\"\").reverse().join(\"\");\nwrite(palyndrome + \"\\n\");\n"}], "src_uid": "f996224809df700265d940b12622016f"} {"source_code": "var name = readline(), str = readline(), x = 0, pos, check = true;\nvar namelength = name.length, a;\n\nfor(i=0; i=0; i--) {\n pos = str.lastIndexOf(name[i], pos);\n if (pos != -1) {\n str = str.substr(0, pos);\n } else {\n check = false;\n break;\n }\n }\n if (check) x=str.length+1;\n}\nprint(x);", "positive_code": [{"source_code": "/*//deb\nvar lines = [];\nlines[0] = \"aba\";\nlines[1] = \"baobababbah\";\nvar line = 0;\nfunction readline() {\n\treturn lines[line++];\n}*/\n\n\nfunction readn() {\n\treturn +readline();\n}\nfunction parsens(s) {\n\treturn \ts.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumbers(a,b) {\n\treturn a-b;\n}\n\n\nvar s = readline();\nvar t = readline();\n\nfunction trimLeft(s, t) {\n var currentChar = 0;\n for (var i = 0; i < t.length; i++) {\n if (t.charAt(i) == s.charAt(currentChar)) {\n currentChar++;\n }\n if (currentChar == s.length) {\n return t.substr(i+1);//efficency\n }\n }\n return null;\n}\n\nfunction trimRight(s, t) {\n var currentChar = s.length-1;\n for (var i = t.length-1; i >= 0; i--) {\n if (t.charAt(i) == s.charAt(currentChar)) {\n currentChar--;\n }\n if (currentChar == -1) {\n return t.substr(0, i);//efficency\n }\n }\n return null;\n}\n\nvar t2 = trimLeft(s, t);\n//print(\"t2\", t2);\nif (t2 === null) {\n print(0);\n} else {\n var t3 = trimRight(s, t2);\n //print(\"t3\", t3);\n if (t3 === null) {\n print(0);\n } else {\n print(t3.length+1);\n }\n}"}, {"source_code": "\ufeffvar name = readline(), str = readline(), x = 0, pos, check = true;\nvar namelength = name.length, a;\n\nfor(i=0; i=0; i--) {\n pos = str.lastIndexOf(name[i], pos);\n if (pos != -1) {\n str = str.substr(0, pos);\n } else {\n check = false;\n break;\n }\n }\n if (check) x=str.length+1;\n}\nprint(x);"}], "negative_code": [{"source_code": "var name = readline(), str = readline(), x = 0, pos, check = true;\nvar namelength = name.length, a;\n\nwhile(check) {\n for(i=0; i=0; i--) {\n pos = str.lastIndexOf(name[i], pos);\n }\n x += pos+1;\n str = str.substr(a+1);\n}\nprint(x);"}, {"source_code": "\ufeffvar name = readline(), str = readline(), x = 0, pos, check = true;\nvar namelength = name.length, a;\n\nwhile(check) {\n for(i=0; i=0; i--) {\n pos = str.lastIndexOf(name[i], pos);\n if (pos != -1) {\n str = str.substr(0, pos);\n } else {\n check = false;\n break;\n }\n }\n if (!check) break;\n x+=str.length+1;\n}\nprint(x);"}], "src_uid": "724fa4b1d35b8765048857fa8f2f6802"} {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve([n, k], s) {\n let i = 0;\n let score = 0;\n let totalLs = 0;\n const innerLGroups = []; // Ignore leading Ls, they will never result in +3 when swapped\n\n while (s[i] === 'L') {\n i++;\n }\n\n totalLs += i;\n\n while (i < s.length) {\n let w = 0;\n\n while (s[i] === 'W') {\n w++;\n i++;\n }\n\n if (w) {\n score += w * 2 - 1;\n }\n\n let l = 0;\n\n while (s[i] === 'L') {\n l++;\n i++;\n }\n\n totalLs += l; // Ignore trailing Ls, they will never result in +3 when swapped\n\n if (l && s[i] === 'W') {\n innerLGroups.push(l);\n }\n }\n\n if (totalLs <= k) {\n console.log(n * 2 - 1);\n } else if (totalLs === n) {\n console.log(Math.max(k * 2 - 1, 0));\n } else {\n for (let x of innerLGroups.sort((a, b) => a - b)) {\n if (x <= k) {\n score += x * 2 + 1;\n k -= x;\n } else {\n score += k * 2;\n k = 0;\n }\n }\n\n score += k * 2;\n console.log(score);\n }\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n input.forEach(([a, b]) => solve(a.split(' ').map(Number), b));\n}\n\nmain().then();\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, k] = readLine().split(\" \").map(Number);\n const str = readLine();\n let [prevChar, streaks, countW, point, countL, numberOfFilledGaps, seenW] = [\"\", 0, 0, 0, 0, 0, false];\n const gaps = [];\n\n for (let i = 0; i < str.length; i++) {\n const currentChar = str[i];\n if (currentChar === \"W\") {\n countW++;\n seenW = true;\n }\n if (prevChar === currentChar) {\n if (currentChar === \"L\" && seenW) {\n countL++;\n }\n continue;\n } else {\n if (currentChar === \"L\" && prevChar === \"W\") countL++;\n if (currentChar === \"W\") {\n streaks++;\n seenW = true;\n }\n if (currentChar === \"W\" && prevChar === \"L\" && streaks > 1) {\n gaps.push(countL);\n countL = 0;\n }\n prevChar = currentChar;\n }\n }\n point = 2 * countW - streaks;\n\n if (k + countW >= len) {\n console.log(2 * len - 1);\n } else if (countW === 0 && k !== 0) {\n console.log(2 * k - 1);\n } else {\n gaps.sort((a, b) => a - b);\n let _k = k;\n for (let i = 0; i < gaps.length; i++) {\n const gap = gaps[i];\n _k -= gap;\n if (_k >= 0) numberOfFilledGaps++;\n else break;\n }\n console.log(2 * (countW + k) - (streaks - numberOfFilledGaps));\n }\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = +$(), k = +$(), s = $(), l = []\n let c = 0, res = 0, c0;\n For(n, i => {\n if (s[i] == 'L') c++;\n else {\n if (i == 0 || s[i - 1] == 'L') res += 1;\n else res += 2;\n if (c > 0) l.push(c);\n c = 0;\n }\n })\n if (c == n) {\n log(max(0, k * 2 - 1));\n continue;\n }\n if (s[0] == 'W') {\n l.sort(asc);\n while (l.length && k >= l[0]) {\n res += l[0] * 2 + 1;\n k -= l[0]\n l.shift()\n }\n if (l.length == 0) {\n log(res + min(k, c) * 2)\n } else {\n log(res + k * 2)\n }\n } else {\n c0 = l[0];\n l = l.slice(1).sort(asc);\n while (l.length && k >= l[0]) {\n res += l[0] * 2 + 1;\n k -= l[0]\n l.shift()\n }\n if (l.length == 0) {\n log(min(2 * n - 1, res + min(k, c + c0) * 2))\n } else {\n log(res + k * 2)\n }\n }\n }\n}\n"}, {"source_code": "try {require('codeforces')} catch(e){console = {log:function(){}}};\n// print\n// readline\n\nvar t = parseInt(readline());\nwhile (t--) {\n var data = readline().split(' ').map(Number);\n var s = data[0];\n var n = Math.min(s, data[1]);\n var line = readline();\n var length = line.length;\n var firstW = line.indexOf('W');\n var lastW = line.lastIndexOf('W');\n var index = firstW === -1 ? 0 : firstW;\n\n var zeros = 0;\n var last = 'L'\n var score = 0\n var add = 0;\n var current;\n var map = {}\n\n while (current = line[index]) {\n if (current === 'L') {\n zeros++\n } else {\n score++\n if (last === 'W') score++\n if (zeros) {\n if (!map[zeros]) map[zeros] = 0\n map[zeros]++\n zeros = 0\n }\n }\n last = current\n index++\n }\n\n if (!score) {\n n = Math.min(n, length)\n print(n ? (n * 2 - 1) : 0)\n continue;\n }\n var cells = Object.keys(map).map(Number);\n cells.sort(function(a, b){return a - b})\n var str = line;\n while (cells.length) {\n var size = cells[0];\n var count = map[size];\n if (size > n || count <= 0) {\n cells.shift()\n } else {\n var times = Math.min((n - n % size) / size, count)\n map[size] -= times\n n -= size * times\n add += times * (size * 2 + 1)\n }\n }\n cells = Object.keys(map).filter(key => map[key] > 0)\n if (n > 0) {\n var ddd = Math.min((cells[0] || 0) + firstW + (length - lastW - 1), n)\n n -= ddd\n add += 2 * ddd\n }\n print( score + add)\n}\n"}, {"source_code": "function B1427(string, insertions) {\n var lgaps = [];\n var wpos = [];\n\n var last = function last(arr) {\n return arr[arr.length - 1];\n };\n\n Array.from(string).forEach(function (x, i) {\n if (x === 'W') {\n if (wpos.length) lgaps.push({\n gap: i - last(wpos) - 1,\n start: last(wpos) + 1\n });\n wpos.push(i);\n }\n });\n var initialScore = 0;\n\n for (var i = 0; i < string.length; i++) {\n if (string[i] === 'L') continue;\n if (i > 0 && string[i - 1] === 'W') initialScore += 2;else initialScore += 1;\n }\n\n var score = 0;\n insertions = Math.min(string.length - wpos.length, insertions);\n lgaps.filter(function (x) {\n return x.gap > 0;\n }).sort(function (a, b) {\n return a.gap - b.gap;\n }).forEach(function (_ref, i) {\n var gap = _ref.gap;\n var val = gap;\n\n if (insertions >= val) {\n score += val * 2 + 1;\n insertions -= val;\n } else {\n score += 2 * insertions;\n insertions = 0;\n }\n });\n\n if (insertions > 0) {\n score += 2 * insertions - (initialScore === 0 ? 1 : 0);\n }\n\n return score + initialScore;\n}\n\nfunction execute(readline, print) {\n var iter = {\n next: function next() {\n return readline();\n }\n };\n\n var split = function split(string) {\n return string.trim().split(' ').map(Number);\n };\n\n var t = Number(iter.next());\n\n while (t--) {\n var params = split(iter.next());\n var arr = iter.next().trim();\n var out = B1427(arr, params[1]);\n print(out);\n }\n}\n\nexecute(readline, print)\n\n\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, k] = readLine().split(\" \").map(Number);\n const str = readLine();\n let [prevChar, streaks, countW, point, countL, numberOfFilledGaps, seenW] = [\"\", 0, 0, 0, 0, 0, false];\n const gaps = [];\n\n for (let i = 0; i < str.length; i++) {\n const currentChar = str[i];\n if (currentChar === \"W\") {\n countW++;\n seenW = true;\n }\n if (prevChar === currentChar) {\n if (currentChar === \"L\" && seenW) {\n countL++;\n }\n continue;\n } else {\n if (currentChar === \"L\" && prevChar === \"W\") countL++;\n if (currentChar === \"W\") {\n streaks++;\n seenW = true;\n }\n if (currentChar === \"W\" && prevChar === \"L\" && streaks > 1) {\n gaps.push(countL);\n countL = 0;\n }\n prevChar = currentChar;\n }\n }\n point = 2 * countW - streaks;\n\n if (k + countW >= len) {\n console.log(2 * len - 1);\n } else if (countW === 0) {\n console.log(2 * k - 1);\n } else {\n gaps.sort((a, b) => a - b);\n let _k = k;\n for (let i = 0; i < gaps.length; i++) {\n const gap = gaps[i];\n _k -= gap;\n if (_k >= 0) numberOfFilledGaps++;\n else break;\n }\n console.log(2 * (countW + k) - (streaks - numberOfFilledGaps));\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, k] = readLine().split(\" \").map(Number);\n const str = readLine();\n let [prevChar, streaks, countW, point, countL, numberOfFilledGaps, seenW] = [\"\", 0, 0, 0, 0, 0, false];\n const gaps = [];\n\n for (let i = 0; i < str.length; i++) {\n const currentChar = str[i];\n if (currentChar === \"W\") {\n countW++;\n seenW = true;\n }\n if (prevChar === currentChar) {\n if (currentChar === \"L\" && seenW) {\n countL++;\n }\n continue;\n } else {\n if (currentChar === \"L\" && prevChar === \"W\") countL++;\n if (currentChar === \"W\") {\n streaks++;\n seenW = true;\n }\n if (currentChar === \"W\" && prevChar === \"L\" && streaks > 1) {\n gaps.push(countL);\n countL = 0;\n }\n prevChar = currentChar;\n }\n }\n point = 2 * countW - streaks;\n\n if (k + countW >= len) {\n console.log(2 * len - 1);\n } else {\n gaps.sort((a, b) => a - b);\n let _k = k;\n for (let i = 0; i < gaps.length; i++) {\n const gap = gaps[i];\n _k -= gap;\n if (_k >= 0) numberOfFilledGaps++;\n else break;\n }\n console.log(2 * (countW + k) - (streaks - numberOfFilledGaps));\n }\n }\n}\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve([n, k], s) {\n let i = 0;\n let score = 0;\n let totalLs = 0;\n const innerLGroups = []; // Ignore leading Ls, they will never result in +3 when swapped\n\n while (s[i] === 'L') {\n i++;\n }\n\n totalLs += i;\n\n while (i < s.length) {\n let w = 0;\n\n while (s[i] === 'W') {\n w++;\n i++;\n }\n\n if (w) {\n score += w * 2 - 1;\n }\n\n let l = 0;\n\n while (s[i] === 'L') {\n l++;\n i++;\n }\n\n totalLs += l; // Ignore trailing Ls, they will never result in +3 when swapped\n\n if (l && s[i] === 'W') {\n innerLGroups.push(l);\n }\n }\n\n if (totalLs <= k) {\n console.log(n * 2 - 1);\n } else {\n for (let x of innerLGroups.sort((a, b) => a - b)) {\n if (x <= k) {\n score += x * 2 + 1;\n k -= x;\n } else {\n score += k * 2;\n k = 0;\n }\n }\n\n score += k * 2;\n console.log(score);\n }\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n input.forEach(([a, b]) => solve(a.split(' ').map(Number), b));\n}\n\nmain().then();\n"}], "src_uid": "c4c3c07b2ba6df49d5a7d6d2d0d1895f"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = 1//+lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n let [n, m, k] = lines[l++].trim().split(' ')\r\n n = +n\r\n m = +m\r\n k = BigInt(k)\r\n // k = +k\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n const edges = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\r\n l += m\r\n output[i] = solve(n, m, k, arr, edges)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, k, arr, edges) {\r\n if (k === 1n) {\r\n let min = Infinity\r\n for (let i = 0; i < arr.length; i++) {\r\n min = Math.min(min, arr[i])\r\n }\r\n return min\r\n }\r\n arr.unshift(0)\r\n //\r\n const idx = binarySearch(1, 1e9, x => {\r\n return !check(n, k, arr, edges, x)\r\n })\r\n return idx === 1e9 ? -1 : idx + 1\r\n}\r\nfunction check(n, k, arr, edges, x) {\r\n const h = new Array(n + 1).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n + 1).fill(-1);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n if (d[i] === -1) d[i] = 0;\r\n if (d[j] === -1) d[j] = 0;\r\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (arr[u] > x || arr[v] > x) continue;\r\n add(u, v);\r\n }\r\n let size = 0;\r\n const queue = [],\r\n dist = new Array(n + 1).fill(0);\r\n for (let [u, count] of d.entries()) {\r\n if (count !== -1) size++;\r\n if (count === 0) {\r\n queue.push(u);\r\n dist[u] = 1;\r\n }\r\n }\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] == k) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n return queue.length < size\r\n}\r\nfunction binarySearch(l, r, fn) {\r\n while (l <= r) {\r\n const m = Math.floor((l + r) / 2)\r\n if (fn(m)) {\r\n l = m + 1\r\n } else {\r\n r = m - 1\r\n }\r\n }\r\n return r\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n let buildtime = 0,\r\n topotime = 0,\r\n all = new Date().valueOf();\r\n const check = t => {\r\n let time = new Date().valueOf();\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(-1);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n if (d[i] === -1) d[i] = 0;\r\n if (d[j] === -1) d[j] = 0;\r\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (a[u] > t || a[v] > t) continue;\r\n add(u, v);\r\n }\r\n buildtime += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const topo = () => {\r\n let size = 0;\r\n const queue = [],\r\n dist = new Array(n).fill(0);\r\n for (let [u, count] of d.entries()) {\r\n if (count !== -1) size++;\r\n if (count === 0) {\r\n queue.push(u);\r\n dist[u] = 1;\r\n }\r\n }\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n if (queue.length === size) return false;\r\n return true;\r\n };\r\n let res = topo();\r\n topotime += new Date().valueOf() - time;\r\n return res;\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n let outs = [];\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (n === 173070) outs.push([buildtime, topotime].join(','));\r\n if (new Date().valueOf() - all > 2500) {\r\n if (n === 173070) {\r\n console.log(outs.join('\\n'));\r\n console.log(new Date().valueOf() - all);\r\n }\r\n }\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s) - 1));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n const check = t => {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(-1);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n if (d[i] === -1) d[i] = 0;\r\n if (d[j] === -1) d[j] = 0;\r\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (a[u] > t || a[v] > t) continue;\r\n add(u, v);\r\n }\r\n const topo = () => {\r\n let size = 0;\r\n const queue = [],\r\n dist = new Array(n).fill(0);\r\n for (let [u, count] of d.entries()) {\r\n if (count !== -1) size++;\r\n if (count === 0) {\r\n queue.push(u);\r\n dist[u] = 1;\r\n }\r\n }\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n if (queue.length === size) return false;\r\n return true;\r\n };\r\n let res = topo();\r\n return res;\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s) - 1));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n const check = t => {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (a[u] > t || a[v] > t) continue;\r\n add(u, v);\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map(),\r\n fa = [];\r\n let loop = false;\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n const callStack = [[u]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const v = curCall.pop();\r\n if (dfn[v] === low[v]) {\r\n let count = 0;\r\n while (true) {\r\n count++;\r\n if (count > 1) {\r\n loop = true;\r\n return;\r\n }\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === v) break;\r\n }\r\n idx++;\r\n }\r\n const u = fa[v];\r\n low[u] = Math.min(low[u], low[v]);\r\n }\r\n if (!curCall) break;\r\n const u = curCall[curCall.length - 1];\r\n if (!dfn[u]) {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n let nextCall = [];\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n if (!dfn[v]) {\r\n fa[v] = u;\r\n nextCall.push(v);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n callStack.push(nextCall);\r\n continue;\r\n } else if (set.has(u)) {\r\n const f = fa[u];\r\n low[f] = Math.min(low[f], dfn[u]);\r\n }\r\n curCall.pop();\r\n }\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (!dfn[i]) dfs(i);\r\n if (loop) return true;\r\n }\r\n if (k > idx) return false;\r\n const h1 = new Array(n).fill(-1),\r\n e1 = [],\r\n ne1 = [],\r\n d = new Array(idx).fill(0);\r\n let idx1 = 0;\r\n const add = (i, j) => {\r\n e1[idx1] = j, ne1[idx1] = h1[i], h1[i] = idx1++;\r\n };\r\n for (let u = 0; u < n; u++) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n const a = map.get(u),\r\n b = map.get(v);\r\n add(a, b);\r\n }\r\n }\r\n const queue = [],\r\n dist = new Array(idx).fill(0);\r\n for (let [k, v] of d.entries()) if (v === 0) {\r\n queue.push(k);\r\n dist[k] = 1;\r\n }\r\n for (let u of queue) {\r\n for (let i = h1[u]; i !== -1; i = ne1[i]) {\r\n const v = e1[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k) {\r\n return true;\r\n }\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n return false;\r\n };\r\n return tarjan();\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s) - 1));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n let buildtime = 0,\r\n topotime = 0,\r\n all = new Date().valueOf();\r\n const check = t => {\r\n let time = new Date().valueOf();\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(-1);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n if (d[i] === -1) d[i] = 0;\r\n if (d[j] === -1) d[j] = 0;\r\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (a[u] > t || a[v] > t) continue;\r\n add(u, v);\r\n }\r\n buildtime += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const topo = () => {\r\n let size = 0;\r\n const queue = [],\r\n dist = new Array(n).fill(0);\r\n for (let [u, count] of d.entries()) {\r\n if (count !== -1) size++;\r\n if (count === 0) {\r\n queue.push(u);\r\n dist[u] = 1;\r\n }\r\n }\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n if (queue.length === size) return false;\r\n return true;\r\n };\r\n let res = topo();\r\n topotime += new Date().valueOf() - time;\r\n return res;\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n let outs = [];\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (n === 173070) outs.push([buildtime, topotime].join(','));\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n if (n === 173070) {\r\n console.log(outs.join('|'));\r\n console.log(new Date().valueOf() - all);\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s) - 1));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n let buildtime = 0,\r\n topotime = 0,\r\n all = new Date().valueOf();\r\n const check = t => {\r\n let time = new Date().valueOf();\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(-1);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n if (d[i] === -1) d[i] = 0;\r\n if (d[j] === -1) d[j] = 0;\r\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\r\n };\r\n for (let [u, v] of edges) {\r\n if (a[u] > t || a[v] > t) continue;\r\n add(u, v);\r\n }\r\n buildtime += new Date().valueOf() - time;\r\n time = new Date().valueOf();\r\n const topo = () => {\r\n let size = 0;\r\n const queue = [],\r\n dist = new Array(n).fill(0);\r\n for (let [u, count] of d.entries()) {\r\n if (count !== -1) size++;\r\n if (count === 0) {\r\n queue.push(u);\r\n dist[u] = 1;\r\n }\r\n }\r\n for (let u of queue) {\r\n for (let i = h[u]; i !== -1; i = ne[i]) {\r\n const v = e[i];\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n if (queue.length === size) return false;\r\n return true;\r\n };\r\n let res = topo();\r\n topotime += new Date().valueOf() - time;\r\n return res;\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n let outs = [];\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (n === 173070) outs.push([buildtime, topotime].join(','));\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n if (n === 173070) {\r\n console.log(outs.join('\\n'));\r\n console.log(new Date().valueOf() - all);\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(s => Number(s) - 1));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n if (k === 1) {\r\n console.log(Math.min(...a));\r\n return;\r\n }\r\n const check = t => {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of edges) {\r\n u--, v--;\r\n if (a[u] > t || a[v] > t) continue;\r\n g[u].push(v);\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map(),\r\n loops = [],\r\n fa = [];\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n const callStack = [[u]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const v = curCall.pop();\r\n if (dfn[v] === low[v]) {\r\n loops.push([]);\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n loops[idx].push(j);\r\n if (j === v) break;\r\n }\r\n idx++;\r\n }\r\n const u = fa[v];\r\n low[u] = Math.min(low[u], low[v]);\r\n }\r\n if (!curCall) break;\r\n const u = curCall[curCall.length - 1];\r\n if (!dfn[u]) {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n let nextCall = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n fa[v] = u;\r\n nextCall.push(v);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n callStack.push(nextCall);\r\n continue;\r\n } else if (set.has(u)) {\r\n const f = fa[u];\r\n low[f] = Math.min(low[f], dfn[u]);\r\n }\r\n curCall.pop();\r\n }\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (!dfn[i]) dfs(i);\r\n }\r\n for (let nums of loops) {\r\n if (nums.length > 1) return true;\r\n }\r\n const g1 = Array.from({\r\n length: idx\r\n }, () => new Set()),\r\n d = new Array(idx).fill(0);\r\n for (let [u, children] of g.entries()) {\r\n for (let v of children) {\r\n if (g1[u].has(v)) continue;\r\n g1[u].add(v);\r\n d[v]++;\r\n }\r\n }\r\n const queue = [],\r\n dist = new Array(idx).fill(0);\r\n for (let [k, v] of d.entries()) if (v === 0) {\r\n queue.push(k);\r\n dist[k] = 1;\r\n }\r\n for (let u of queue) {\r\n for (let v of g1[u]) {\r\n d[v]--;\r\n dist[v] = Math.max(dist[v], dist[u] + 1);\r\n if (dist[v] === k - 1) return true;\r\n if (d[v] === 0) queue.push(v);\r\n }\r\n }\r\n return false;\r\n };\r\n return tarjan();\r\n };\r\n const max = Math.max(...a) + 10;\r\n let l = 0,\r\n r = max;\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n console.log(l === max ? -1 : l);\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, k, a, edges) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of edges) {\r\n u--, v--;\r\n g[u].push(v);\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map(),\r\n loops = [],\r\n fa = [];\r\n let idx = 1;\r\n const dfs = u => {\r\n const callStack = [[u]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 0) {\r\n var _curCall;\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (!curCall) continue;\r\n const v = curCall.pop();\r\n if (dfn[v] === low[v]) {\r\n loops.push([]);\r\n let k = loops.length - 1;\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, k);\r\n loops[k].push(j);\r\n if (j === v) break;\r\n }\r\n }\r\n const u = fa[v];\r\n low[u] = Math.min(low[u], low[v]);\r\n }\r\n if (!curCall) break;\r\n const u = curCall[curCall.length - 1];\r\n if (!dfn[u]) {\r\n dfn[u] = low[u] = idx++;\r\n stack.push(u);\r\n set.add(u);\r\n let nextCall = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n fa[v] = u;\r\n nextCall.push(v);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n callStack.push(nextCall);\r\n continue;\r\n } else if (set.has(u)) {\r\n const f = fa[u];\r\n low[f] = Math.min(low[f], dfn[u]);\r\n }\r\n curCall.pop();\r\n }\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (!dfn[i]) dfs(i);\r\n }\r\n let res = Infinity;\r\n for (let nums of loops) {\r\n if (nums.length > 1) {\r\n let max = -Infinity;\r\n for (let i of nums) {\r\n max = Math.max(max, a[i]);\r\n }\r\n res = Math.min(max);\r\n }\r\n }\r\n return res;\r\n };\r\n let res = tarjan();\r\n if (k > n) {\r\n console.log(res === Infinity ? -1 : res);\r\n return;\r\n }\r\n const dfs = (i, set = new Set(), path = [], bst = new BinarySearchTree()) => {\r\n bst.insert(a[i]);\r\n path.push(i);\r\n set.add(i);\r\n if (path.length > k) {\r\n const b = path[path.length - k - 1];\r\n bst.delete(b);\r\n }\r\n if (path.length >= k) {\r\n res = Math.min(res, bst.getMax());\r\n }\r\n for (let j of g[i]) {\r\n if (set.has(j)) continue;\r\n dfs(j, set, path, bst);\r\n }\r\n bst.delete(a[i]);\r\n if (path.length > k) {\r\n const b = path[path.length - k - 1];\r\n bst.insert(b);\r\n }\r\n set.delete(i);\r\n path.pop();\r\n };\r\n dfs(0);\r\n console.log(res === Infinity ? -1 : res);\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n solve(n, m, k, a, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n let [n, m, k] = lines[l++].trim().split(' ')\n n = +n\n m = +m\n // k = BigInt(k)\n k = +k\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n output[i] = solve(n, m, k, arr, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n forEach(fn) {\n for (let i = this.first; i <= this.last; i++) {\n fn(this.map[i], i - this.first)\n }\n }\n}\n\nfunction solve(n, m, k, arr, edges) {\n arr.unshift(0)\n //\n const idx = binarySearch(1, 1e9, x => {\n // let x = 10\n return !check2(n, k, arr, edges, x)\n })\n return idx === 1e9 ? -1 : idx + 1\n}\nfunction check2(n, k, arr, edges, x) {\n const h = new Array(n).fill(-1),\n e = [],\n ne = [],\n d = new Array(n).fill(-1);\n let idx = 0;\n const add = (i, j) => {\n if (d[i] === -1) d[i] = 0;\n if (d[j] === -1) d[j] = 0;\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\n };\n for (let [u, v] of edges) {\n if (arr[u] > x || arr[v] > x) continue;\n add(u, v);\n }\n // const ins = Array(n + 1).fill(0)\n // const outs = Array(n + 1).fill(0)\n // const adj = {}\n // // const radj = {}\n // edges.forEach(([a, b]) => {\n // if (arr[a] > x || arr[b] > x) return\n // adj[a] = adj[a] || []\n // adj[a].push(b)\n // // radj[b] = radj[b] || []\n // // radj[b].push(a)\n // ins[b]++\n // })\n let size = 0;\n let queue = new Queue(),//[],\n dist = new Array(n).fill(0);\n for (let [u, count] of d.entries()) {\n if (count !== -1) size++;\n if (count === 0) {\n queue.push(u);\n dist[u] = 1;\n }\n }\n // for (let u of queue) {\n // for (let i = h[u]; i !== -1; i = ne[i]) {\n // const v = e[i];\n // d[v]--;\n // dist[v] = Math.max(dist[v], dist[u] + 1);\n // if (dist[v] === k) return true;\n // if (d[v] === 0) queue.push(v);\n // }\n // }\n let level = 1n\n let count = 0\n while (queue.length) {\n // if (level >= k) return true\n const nq = new Queue()\n // while (queue.length) {\n queue.forEach(u => {\n // const u = queue.shift()\n count++\n for (let i = h[u]; i !== -1; i = ne[i]) {\n const v = e[i];\n d[v]--;\n if (level + 1n >= k) return true\n if (d[v] === 0) nq.push(v);\n }\n // }\n })\n queue = nq\n level++\n }\n return count < size\n\n // let q = new Queue()\n // let total = 0\n // for (let u = 1; u <= n; u++) {\n // outs[u] = adj[u] ? adj[u].length : 0\n // // ins[u] = (radj[u] || []).length\n // if (ins[u] || outs[u]) {\n // total++\n // if (!ins[u]) q.push(u)\n // }\n // }\n // if (!total) return false\n // let count = 0\n // const dist = Array(n + 1).fill(1)\n // while (q.length) {\n // if (level >= k) return true\n // const nq = new Queue()\n // q.forEach(u => {\n // count++\n // ;(adj[u] || []).forEach(v => {\n // if (!--ins[v]) nq.push(v)\n // })\n // })\n // q = nq\n // level++\n // }\n // console.log(x, level, count)\n // return count < total\n}\nfunction check(n, k, a, edges, t) {\n const h = new Array(n).fill(-1),\n e = [],\n ne = [],\n d = new Array(n).fill(-1);\n let idx = 0;\n const add = (i, j) => {\n if (d[i] === -1) d[i] = 0;\n if (d[j] === -1) d[j] = 0;\n e[idx] = j, ne[idx] = h[i], d[j]++, h[i] = idx++;\n };\n for (let [u, v] of edges) {\n if (a[u] > t || a[v] > t) continue;\n add(u, v);\n }\n const topo = () => {\n let size = 0;\n const queue = [],\n dist = new Array(n).fill(0);\n for (let [u, count] of d.entries()) {\n if (count !== -1) size++;\n if (count === 0) {\n queue.push(u);\n dist[u] = 1;\n }\n }\n return 1\n for (let u of queue) {\n for (let i = h[u]; i !== -1; i = ne[i]) {\n const v = e[i];\n d[v]--;\n dist[v] = Math.max(dist[v], dist[u] + 1);\n if (dist[v] === k) return true;\n if (d[v] === 0) queue.push(v);\n }\n }\n if (queue.length === size) return false;\n return true;\n };\n let res = topo();\n return res;\n };\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n let [n, m, k] = lines[l++].trim().split(' ')\n n = +n\n m = +m\n k = BigInt(k)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n output[i] = solve(n, m, k, arr, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n}\n\nfunction solve(n, m, k, arr, edges) {\n arr.unshift(0)\n //\n const idx = binarySearch(1, 1e9, x => {\n // let x = 10\n return !check(n, k, arr, edges, x)\n })\n return idx === 1e9 ? -1 : idx + 1\n}\nfunction check(n, k, arr, edges, x) {\n const ins = Array(n + 1).fill(0)\n const outs = Array(n + 1).fill(0)\n const adj = {}\n const radj = {}\n edges.forEach(([a, b]) => {\n if (arr[a] > x || arr[b] > x) return\n adj[a] = adj[a] || []\n adj[a].push(b)\n radj[b] = radj[b] || []\n radj[b].push(a)\n })\n let q = new Queue()\n let total = 0\n for (let u = 1; u <= n; u++) {\n outs[u] = (adj[u] || []).length\n ins[u] = (radj[u] || []).length\n if (arr[u] <= x) {\n total++\n if (!ins[u]) q.push(u)\n }\n }\n let level = 1n\n let count = 0\n while (q.length) {\n const nq = new Queue()\n while (q.length) {\n const u = q.shift()\n count++\n ;(adj[u] || []).forEach(v => {\n if (!--ins[v]) nq.push(v)\n })\n }\n if (level >= k) return count\n q = nq\n level++\n }\n // console.log(level, count)\n return count && count < total\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "1b36b12307b1a324b84e878d11efbbec"} {"source_code": "var prev = new Int32Array(1e5 + 5);\nvar diff = new Int32Array(1e5 + 5);\nprint(function(n, a) {\n\n\tfor (var i = 1; i <= n; i++) {\n\t\tif (prev[a[i]] < 0) {\n\t\t\tcontinue;\n\t\t} else if (prev[a[i]] === 0) {\n\t\t\tprev[a[i]] = i;\n\t\t} else if (diff[a[i]] === 0) {\n\t\t\tdiff[a[i]] = i - prev[a[i]];\n\t\t\tprev[a[i]] = i;\n\t\t} else if (diff[a[i]] === i - prev[a[i]]) {\n\t\t\tprev[a[i]] = i;\n\t\t} else {\n\t\t\tprev[a[i]] = -1;\n\t\t}\n\t}\n\n\tvar ans = [];\n\tfor (var i = 0; i <= 1e5; i++)\n\t\tif (prev[i] > 0) ans.push(i + ' ' + diff[i]);\n\n\treturn ans.length + '\\n' + ans.join('\\n');\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const map = {};\n\n for (let i = 0; i < len; i++) {\n const num = arr[i];\n if (!map[num]) {\n map[num] = { count: 1, index: i, diff: 0, status: true };\n } else {\n let { count, index, diff, status } = map[num];\n if (status) {\n if (count === 1) {\n map[num] = { count: count + 1, index: i, diff: i - index, status: true };\n } else {\n map[num] = { count: count + 1, index: i, diff: i - index, status: diff === i - index };\n }\n }\n }\n }\n\n let count = 0,\n result = [];\n\n for (let key in map) {\n if (map[key].status) {\n const r = `${key} ${map[key].diff}`;\n result.push(r);\n count++;\n }\n }\n\n console.log(count);\n console.log(result.join(\"\\n\"));\n}\n"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar m = {alphabet: []};\n\t\treadline().split(' ').forEach(function (e, i) {\n\t\t\tif (m[e = parseInt(e)]) return m[e].push(i);\n\t\t\tm[e] = [i]; m.alphabet.push(e);\n\t\t});\n\n\t\tm.alphabet.map(function (e) { return e; }).forEach(function (e, i) {\n\t\t\tvar a = m[e];\n\n\t\t\tif (a.length === 1) return m[e] = e + ' 0';\n\n\t\t\tvar d = a[1] - a[0], flag = true;\n\t\t\tfor (var i = 2, _i = a.length; i < _i; i++) {\n\t\t\t\tif (a[i] - a[i - 1] !== d) {\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (flag) m[e] = e + ' ' + d;\n\t\t\telse m.alphabet.splice(m.alphabet.indexOf(e), 1);\n\n\t\t});\n\n\t\tif (m.alphabet.length === 0) return 0;\n\n\t\tm.alphabet.sort(function (a, b) { return a - b; });\n\n\t\treturn [m.alphabet.length].concat(m.alphabet.map(function (e) { return m[e]; })).join('\\n');\n\n\t}(+readline()));\n\n}.call(this));\n"}, {"source_code": "var elem = function(lastpos,isNew,prog){\n this.lastpos=-1;\n this.isNew=isNew;\n this.prog=prog;\n}\nvar n = parseInt(readline());\nvar a = readline().trim().split(' ').map((x)=>parseInt(x));\n\nvar map =[];\nvar N_MAX = 100006;\nfor(var i=0;i=0 && map[i].prog!==''){\n print(i+\" \"+map[i].prog);\n }\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tnumbers = tokenizeIntegers(readline()),\n\t\toccur = {}, unique = [];\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar x = numbers[i];\n\t\tif (occur[x] === undefined) {\n\t\t\toccur[x] = [i];\n\t\t\tunique.push(x);\n\t\t} else {\n\t\t\toccur[x].push(i);\n\t\t}\n\t}\n\tunique.sort(function (a, b) {\n\t\treturn a-b;\n\t});\n\tvar parts = [];\n\tfor (var i = 0; i < unique.length; ++i) {\n\t\tvar where = occur[unique[i]];\n\t\tif (where.length == 1) {\n\t\t\tparts.push(unique[i]+' '+0);\n\t\t} else {\n\t\t\tvar d = where[1]-where[0], okay = true;\n\t\t\tfor (var j = 2; okay && j < where.length; ++j) {\n\t\t\t\tif (where[j]-where[j-1] != d) {\n\t\t\t\t\tokay = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (okay) {\n\t\t\t\tparts.push(unique[i]+' '+d);\n\t\t\t}\n\t\t}\n\t}\n\tprint(parts.length);\n\tif (parts.length != 0) {\n\t\tprint(parts.join('\\n'));\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar a = readline().trim().split(' ').map((x)=>parseInt(x));\n\nvar map = {};\n\nfor(var i in a){\n if(map[a[i]]==undefined){\n map[a[i]]=[]; \n }\n map[a[i]].push(i);\n}\nvar ans = [];\nfor(var i in map){\n if(map[i].length==1)\n ans.push([i,0]);\n else if(map[i].length==2){\n ans.push([i,(map[i][1]-map[i][0])]);\n }else{\n var pro = map[i][1]-map[i][0];\n var not = false;\n for(var j=1;jparseInt(x));\n\nvar map = {};\n\nfor(var i in a){\n if(map[a[i]]==undefined){\n map[a[i]]=[]; \n }\n map[a[i]].push(i);\n}\nvar ans = [];\nfor(var i in map){\n if(map[i].length==1)\n ans.push([i,0]);\n else if(map[i].length==2){\n ans.push([i,(map[i][1]-map[i][0])]);\n }else{\n var pro = map[i][1]-map[i][0];\n var not = false;\n for(var j=1;jparseInt(x));\n\nvar map = {};\n\nfor(var i in a){\n if(map[a[i]]==undefined){\n map[a[i]]=[]; \n }\n map[a[i]].push(i);\n}\nvar ans = [];\nfor(var i in map){\n if(map[i].length==1)\n ans.push(i+' 0');\n else if(map[i].length==2){\n ans.push(i+' '+(map[i][1]-map[i][0]));\n }else{\n var pro = map[i][1]-map[i][0];\n var not = false;\n for(var j=1;j {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [n, k] = readline().split(\" \").map(x => parseInt(x));\n const a = readline().split(\" \").map(x => parseInt(x));\n const t = readline().split(\" \").map(x => parseInt(x));\n let awake = t.reduce((acc,curr,index) => acc += a[index]*curr, 0);\n let extra = 0;\n for (let i=0; i {\nvar readInts = () => {\n return readline().split(\" \").map(function(x) { return parseInt(x); });\n};\n\n/////////////////////////////////////////////////////////////// BEGIN\n\nvar nums = readInts();\nvar n = nums[0];\nvar k = nums[1];\n\nvar a = readInts();\nvar t = readInts();\n\nvar always = 0;\n\nt.forEach((_, i) => {\n if (t[i] == 1) {\n always += a[i];\n a[i] = 0;\n }\n});\n\nvar s = new Array(n).fill(0);\n\nfor (var i = 0; i < n; ++i) {\n s[i] = a[i] + (i == 0 ? 0 : s[i - 1]);\n}\n\nvar best = 0;\nfor (var i = 0; i < n; ++i) {\n var current = always + s[i] - (i - k >= 0 ? s[i - k] : 0);\n if (best < current) best = current;\n}\n\nprint(best + \"\\n\");\n\n/////////////////////////////////////////////////////////////// END OF CODE\n};\n\nif (isNodeJS) {\n var stdin = process.stdin;\n var stdout = process.stdout;\n var lines, currentLine = 0;\n stdin.resume();\n stdin.once('data', function(data) {\n data = data.toString().trim();\n lines = data.split(\"\\n\");\n var readline = () => {\n return lines[currentLine++];\n };\n doWork(readline, stdout.write.bind(stdout));\n });\n} else {\n doWork(readline, print);\n}\n"}], "negative_code": [{"source_code": "//Input\n// var firstLine = \"6 3\"; var secondLine = \"1 3 5 2 5 4\"; var thirdLine = \"1 1 0 1 0 0\";\n// var firstLine = \"7 3\"; var secondLine = \"1 3 5 2 5 4 1\"; var thirdLine = \"1 1 0 1 0 0 1\";\n\nvar firstLine = readline(); var secondLine = readline(); var thirdLine = readline();\n\nretorno = eval(firstLine, secondLine, thirdLine);\n\n//Solution\nfunction eval(firstLine, secondLine, thirdLine){\n var tmp = firstLine.split(\" \").map(function(x){ return parseInt(x)});\n var n = tmp[0];\n var k = tmp[1];\n var theorems = secondLine.split(\" \").map(function(x){ return parseInt(x)});//.map(parseInt);\n var behavior = thirdLine.split(\" \").map(function(x){ return parseInt(x)});\n\n write(calculate(n, k, theorems, behavior));\n // console.log(calculate(n, k, theorems, behavior));\n // return \"Hola\";\n};\n\n\nfunction calculate(n, k, theorems, behavior){\n var maxSecretTechnique = 0;\n var secretTechnique = 0;\n var startingIndex = 0;\n\n for(var i = 0 ; i <= (n-k) ; i++){\n if(i == 0){\n for(var j = 0 ; j < k ; j++){\n secretTechnique += theorems[i+j];\n };\n //console.log(\"secretTechnique: \" + secretTechnique);\n } else{\n //console.log(\"secretTechnique: \" + secretTechnique + \" theorems[\" + (i+k-1) + \"]: + \" + theorems[i+k-1] + \" theorems[\" + (i-1) + \"]: - \" + theorems[i-1] + \"new value: \" + ( secretTechnique + (theorems[i+k-1]) - (theorems[i-1]) ) );\n secretTechnique = secretTechnique + (theorems[i+k-1]) - (theorems[i-1]);\n };\n //console.log(\"secretTechnique: \" + secretTechnique);\n\n if(maxSecretTechnique < secretTechnique){\n maxSecretTechnique = secretTechnique;\n startingIndex = i;\n };\n };\n\n //#region c\u00f3digo en desuso\n // for(var i = 0 ; i <= (n-k) ; i++){\n // var secretTechnique = 0;\n // for(var j = 0 ; j < k ; j++){\n // secretTechnique += theorems[i+j];\n // };\n // if(maxSecretTechnique < secretTechnique){\n // maxSecretTechnique = secretTechnique;\n // startingIndex = i;\n // };\n // // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex + \"\\n\");\n // };\n // #endregion\n\n // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n for(var i = 0 ; i < startingIndex ; i++){\n maxSecretTechnique += theorems[i] * behavior[i];\n };\n // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n for(var i = startingIndex + k ; i < n ; i++){\n maxSecretTechnique += theorems[i] * behavior[i];\n };\n // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n\n return maxSecretTechnique;\n};\n\n\n\n\n\n\n// function calculate(n, k, theorems, behavior){\n// var maxSecretTechnique = 0;\n// var startingIndex = 0;\n// for(var i = 0 ; i <= (n-k) ; i++){\n// var secretTechnique = 0;\n// for(var j = 0 ; j < k ; j++){\n// secretTechnique += theorems[i+j];\n// };\n// if(maxSecretTechnique < secretTechnique){\n// maxSecretTechnique = secretTechnique;\n// startingIndex = i;\n// };\n// // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex + \"\\n\");\n// };\n// // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n// for(var i = 0 ; i < startingIndex ; i++){\n// maxSecretTechnique += theorems[i] * behavior[i];\n// };\n// // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n// for(var i = startingIndex + k ; i < n ; i++){\n// maxSecretTechnique += theorems[i] * behavior[i];\n// };\n// // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n\n// return maxSecretTechnique;\n// };\n\n\n\n"}, {"source_code": "//Input\n// var firstLine = \"6 3\"; var secondLine = \"1 3 5 2 5 4\"; var thirdLine = \"1 1 0 1 0 0\";\n// var firstLine = \"7 3\"; var secondLine = \"1 3 5 2 5 4 1\"; var thirdLine = \"1 1 0 1 0 0 1\";\n\nvar firstLine = readline(); var secondLine = readline(); var thirdLine = readline();\n\nretorno = eval(firstLine, secondLine, thirdLine);\n\n//Solution\nfunction eval(firstLine, secondLine, thirdLine){\n var tmp = firstLine.split(\" \").map(function(x){ return parseInt(x)});\n var n = tmp[0];\n var k = tmp[1];\n var theorems = secondLine.split(\" \").map(function(x){ return parseInt(x)});//.map(parseInt);\n var behavior = thirdLine.split(\" \").map(function(x){ return parseInt(x)});\n\n write(calculate(n, k, theorems, behavior));\n // console.log(calculate(n, k, theorems, behavior));\n // return \"Hola\";\n};\n\nfunction calculate(n, k, theorems, behavior){\n var maxSecretTechnique = 0;\n var startingIndex = 0;\n for(var i = 0 ; i <= (n-k) ; i++){\n var secretTechnique = 0;\n if(behavior[i] == 0){\n for(var j = 0 ; j < k ; j++){\n secretTechnique += theorems[i+j];\n // console.log(\"n: \" + i + \" k: \" + j + \" i+k: \" + (i+j) + \" secretTechnique: \" + secretTechnique);\n };\n // console.log(\"secretTechnique: \" + secretTechnique);\n if(maxSecretTechnique < secretTechnique){\n maxSecretTechnique = secretTechnique;\n startingIndex = i;\n };\n // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n // console.log(\"\\n\");\n };\n };\n // console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n for(var i = 0 ; i < startingIndex ; i++){\n maxSecretTechnique += theorems[i] * behavior[i];\n };\n //console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n for(var i = startingIndex + k ; i < n ; i++){\n maxSecretTechnique += theorems[i] * behavior[i];\n };\n //console.log(\"maxSecretTechnique: \" + maxSecretTechnique + \" startingIndex: \" + startingIndex);\n\n return maxSecretTechnique;\n};\n\n\n\n"}], "src_uid": "0fbac68f497fe189ee088c13d0488cce"} {"source_code": "var data = readline().split(' '),\n m = parseInt(data[0]),\n n = parseInt(data[1]);\n \nvar b = 0,\n Xmin = -1,\n Ymin = -1,\n Xmax = -1,\n Ymax = -1;\n\nfor(var i = 0; i < m; i++) {\n var line = readline();\n \n for(var j = 0; j < n; j++) {\n if(line.charAt(j) === 'B') {\n if(b === 0) {\n Xmin = i;\n Ymin = j;\n Xmax = i;\n Ymax = j;\n } else {\n if(Xmin > i) {\n Xmin = i;\n }\n if(Ymin > j) {\n Ymin = j;\n }\n if(Xmax < i) {\n Xmax = i;\n }\n if(Ymax < j) {\n Ymax = j;\n }\n }\n b++;\n }\n }\n}\n\nif(b === 0) {\n print(1);\n} else if(b === 1){\n print(0);\n} else if(b === m * n && m === n) {\n print(0);\n} else if (b === m * n && m !== n) {\n print(-1);\n} else if(m === 1 || n === 1) {\n print(-1);\n} else {\n var a = Math.max((Xmax - Xmin + 1), (Ymax - Ymin + 1));\n if(a > n || a > m) {\n print(-1);\n } else {\n var s = a * a;\n var output = s - b;\n print(output);\n }\n\n}", "positive_code": [{"source_code": "var s = readline().split(' ').map(Number);\nvar n = s[0], m = s[1];\n\nvar leftExt = null, rightExt = null, topExt = null, bottomExt = null;\nvar blacksCount = 0;\n\nfor (var i = 0; i < n; i++) {\n var currString = readline();\n var count = 0;\n\n for (var j = 0; j < m; j++) {\n if (currString[j] === 'B') {\n blacksCount += 1;\n count++;\n\n if (leftExt === null) {\n leftExt = j;\n } else if (j < leftExt) {\n leftExt = j;\n }\n\n if (rightExt === null) {\n rightExt = j;\n } else if (j > rightExt) {\n rightExt = j;\n }\n }\n }\n \n if (count > 0) { \n \tif (topExt === null) {\n topExt = i;\n } else if (i < topExt) {\n topExt = i;\n }\n\n if (bottomExt === null) {\n bottomExt = i;\n } else if (i > bottomExt) {\n bottomExt = i;\n }\n }\n}\n\nvar verticalSideLength = bottomExt - topExt + 1;\nvar horizontalSideLength = rightExt - leftExt + 1;\nvar maxSideLength = Math.max(horizontalSideLength, verticalSideLength);\n\nif (maxSideLength > n || maxSideLength > m) {\n print('-1');\n} else {\n print(maxSideLength * maxSideLength - blacksCount);\n};"}, {"source_code": "var s = readline().split(' ').map(Number);\nvar n = s[0], m = s[1];\nvar white = 0, black = 0, res, r, d, l, u;\n\nvar arr = [];\nfor (var i = 0; i < n; i++) {\n var s1 = readline();\n arr.push(s1);\n for (var j = 0; j < m; j++) {\n if (s1[j] === 'B') {\n u = u !== undefined ? Math.min(u, i) : i;\n d = d !== undefined ? Math.max(d, i) : i;\n l = l !== undefined ? Math.min(l, j) : j;\n r = r !== undefined ? Math.max(r, j) : j;\n black++;\n }\n }\n}\nif (black === 0) {\n print(1);\n}\nelse {\n var sqSide = Math.max(r-l+1, d-u+1);\n var recSide = Math.min(r-l+1, d-u+1);\n if (sqSide > n || sqSide > m) {\n print(-1);\n }\n else {\n for (var i = u; i<=d; i++) {\n for (var j = l; j<=r; j++) {\n if (arr[i][j] === 'W') {\n white++;\n }\n }\n }\n res = white + (sqSide - recSide) * sqSide;\n print(res);\n }\n}\n"}], "negative_code": [{"source_code": "var data = readline().split(' '),\n m = parseInt(data[0]),\n n = parseInt(data[1]);\n \nvar b = 0,\n Xmin = -1,\n Ymin = -1,\n Xmax = -1,\n Ymax = -1;\n\nfor(var i = 0; i < m; i++) {\n var line = readline();\n \n for(var j = 0; j < n; j++) {\n if(line.charAt(j) === 'B') {\n if(b === 0) {\n Xmin = i;\n Ymin = j;\n Xmax = i;\n Ymax = j;\n } else {\n if(Xmin > i) {\n Xmin = i;\n }\n if(Ymin > j) {\n Ymin = j;\n }\n if(Xmax < i) {\n Xmax = i;\n }\n if(Ymax < j) {\n Ymax = j;\n }\n }\n b++;\n }\n }\n}\n\nif(b === 0) {\n print(1);\n} else if(b === 1){\n print(0);\n} else if(b === m * n) {\n print(0);\n} else if(m === 1 || n === 1) {\n print(-1);\n} else {\n var a = Math.max((Xmax - Xmin + 1), (Ymax - Ymin + 1));\n if(a > n || a > m) {\n print(-1);\n } else {\n var s = a * a;\n var output = s - b;\n print(output);\n }\n\n}"}, {"source_code": "var data = readline().split(' '),\n m = parseInt(data[0]),\n n = parseInt(data[1]);\n \nvar b = 0,\n Xmin = -1,\n Ymin = -1,\n Xmax = -1,\n Ymax = -1;\n\nfor(var i = 0; i < m; i++) {\n var line = readline();\n \n for(var j = 0; j < n; j++) {\n if(line.charAt(j) === 'B') {\n if(b === 0) {\n Xmin = i;\n Ymin = j;\n Xmax = i;\n Ymax = j;\n } else {\n if(Xmin > i) {\n Xmin = i;\n }\n if(Ymin > j) {\n Ymin = j;\n }\n if(Xmax < i) {\n Xmax = i;\n }\n if(Ymax < j) {\n Ymax = j;\n }\n }\n b++;\n }\n }\n}\n\nif(b === 0) {\n print(1);\n} else if(b === 1){\n print(0);\n} else if(b === m * n) {\n print(-1);\n} else if(m === 1 || n === 1) {\n print(-1);\n} else {\n var a = Math.max((Xmax - Xmin + 1), (Ymax - Ymin + 1));\n if(a > n || a > m) {\n print(-1);\n } else {\n var s = a * a;\n var output = s - b;\n print(output);\n }\n\n}"}, {"source_code": "var data = readline().split(' '),\n m = data[0],\n n = data[1];\n \nvar b = 0,\n Xmin = -1,\n Ymin = -1,\n Xmax = -1,\n Ymax = -1;\n\nfor(var i = 0; i < m; i++) {\n var line = readline();\n \n for(var j = 0; j < n; j++) {\n if(line.charAt(j) === 'B') {\n if(b === 0) {\n Xmin = i;\n Ymin = j;\n Xmax = i;\n Ymax = j;\n } else {\n if(Xmin > i) {\n Xmin = i;\n }\n if(Ymin > j) {\n Ymin = j;\n }\n if(Xmax < i) {\n Xmax = i;\n }\n if(Ymax < j) {\n Ymax = j;\n }\n }\n b++;\n }\n }\n}\n\nif(b === 0) {\n print(1);\n} else if(b === 1){\n print(0);\n} else if(b === m * n) {\n print(-1);\n} else {\n var a = Math.max((Xmax - Xmin + 1), (Ymax - Ymin + 1));\n var s = a * a;\n var output = s - b;\n print(output);\n}"}, {"source_code": "var data = readline().split(' '),\n m = parseInt(data[0]),\n n = parseInt(data[1]);\n \nvar b = 0,\n Xmin = -1,\n Ymin = -1,\n Xmax = -1,\n Ymax = -1;\n\nfor(var i = 0; i < m; i++) {\n var line = readline();\n \n for(var j = 0; j < n; j++) {\n if(line.charAt(j) === 'B') {\n if(b === 0) {\n Xmin = i;\n Ymin = j;\n Xmax = i;\n Ymax = j;\n } else {\n if(Xmin > i) {\n Xmin = i;\n }\n if(Ymin > j) {\n Ymin = j;\n }\n if(Xmax < i) {\n Xmax = i;\n }\n if(Ymax < j) {\n Ymax = j;\n }\n }\n b++;\n }\n }\n}\n\nif(b === 0) {\n print(1);\n} else if(b === 1){\n print(0);\n} else if(b === m * n) {\n print(-1);\n} else if(m === 1 || n === 1) {\n print(-1);\n} else {\n var a = Math.max((Xmax - Xmin + 1), (Ymax - Ymin + 1));\n var s = a * a;\n var output = s - b;\n print(output);\n}"}, {"source_code": "var s = readline().split(' ').map(Number);\nvar n = s[0], m = s[1];\n\nvar leftExt = null, rightExt = null, topExt = null, bottomExt = null;\nvar blacksCount = 0;\n\nfor (var i = 0; i < n; i++) {\n var currString = readline();\n\n for (var j = 0; j < m; j++) {\n if (currString[j] === 'B') {\n blacksCount += 1;\n\n if (leftExt === null) {\n leftExt = j;\n } else if (j < leftExt) {\n leftExt = j;\n }\n\n if (rightExt === null) {\n rightExt = j;\n } else if (j > rightExt) {\n rightExt = j;\n }\n }\n }\n\n if (topExt === null) {\n topExt = i;\n } else if (i < topExt) {\n topExt = i;\n }\n\n if (bottomExt === null) {\n bottomExt = i;\n } else if (i > bottomExt) {\n bottomExt = i;\n }\n} \n\n\nvar horizontalSideLength = bottomExt - topExt + 1;\nvar verticalSideLength = rightExt - leftExt + 1;\nvar maxSideLength = Math.max(horizontalSideLength, verticalSideLength);\n\nprint(bottomExt);\nprint(topExt);\n\nif (bottomExt + 1 - maxSideLength < 0) {\n print(\"-1\");\n} else if (rightExt + 1 - maxSideLength < 0) {\n print(\"-1\");\n} else {\n print(maxSideLength * maxSideLength - blacksCount);\n}"}, {"source_code": "var s = readline().split(' ').map(Number);\nvar n = s[0], m = s[1];\n\nvar leftExt = null, rightExt = null, topExt = null, bottomExt = null;\nvar blacksCount = 0;\n\nfor (var i = 0; i < n; i++) {\n var currString = readline();\n var count = 0;\n\n for (var j = 0; j < m; j++) {\n if (currString[j] === 'B') {\n blacksCount += 1;\n count++;\n\n if (leftExt === null) {\n leftExt = j;\n } else if (j < leftExt) {\n leftExt = j;\n }\n\n if (rightExt === null) {\n rightExt = j;\n } else if (j > rightExt) {\n rightExt = j;\n }\n }\n }\n \n if (count > 0) { \n \tif (topExt === null) {\n topExt = i;\n } else if (i < topExt) {\n topExt = i;\n }\n\n if (bottomExt === null) {\n bottomExt = i;\n } else if (i > bottomExt) {\n bottomExt = i;\n }\n }\n} \n\nvar verticalSideLength = bottomExt - topExt + 1;\nvar horizontalSideLength = rightExt - leftExt + 1;\nvar maxSideLength = Math.max(horizontalSideLength, verticalSideLength);\n\nif (bottomExt + 1 - maxSideLength < 0) {\n print(\"-1\");\n} else if (rightExt + 1 - maxSideLength < 0) {\n print(\"-1\");\n} else {\n print(maxSideLength * maxSideLength - blacksCount);\n}"}], "src_uid": "cd6bc23ea61c43b38c537f9e04ad11a6"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment2(n, k, arr);\n printResult(result);\n}\n\nconst countSegment = (n, k, ar) => {\n // const counts = new Array(100010).fill(0);\n const counts = [];\n for (let i = 0; i <= 100010; i++) {\n counts.push(0);\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[start] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n\n return end ? `${start} ${end}` : `-1 -1`;\n}\n\nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array();\n // const counts = new Array(100010);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100001);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "function giaiBai(inp1, inp2) {\n inp1 = inp1.split(' ').map(e => parseInt(e))\n inp2 = inp2.split(' ').map(e => parseInt(e))\n inp2.unshift(0)\n\n let n = inp1[0],\n k = inp1[1],\n a = inp2,\n c = new Array(10e5).fill(0),\n count = 0,\n j = 0\n\n for(var i = 1; i <= n; i++) {\n c[a[i]]++\n if (c[a[i]] === 1) {\n count++\n }\n while (count === k) {\n j++\n c[a[j]]--\n if(c[a[j]] === 0) {\n console.log(j, i)\n break\n }\n }\n if(count === k) {\n break\n }\n }\n if (count === k) {\n return\n }\n console.log('-1 -1')\n}\n\nvar readline = require('readline');\n// Get process.stdin as the standard input object.\nvar standard_input = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\n// Set input character encoding.\n// standard_input.setEncoding('utf-8');\n\n// Prompt user to input data in console.\n// console.log(\"Please input text in command line.\");\n\n// When user input data and click enter key.\nstandard_input.on('line', function (inp1) {\n// console.log(inp1);\n standard_input.on('line', function (inp2) {\n // Print user input in console.\n inp1 = inp1.trim()\n inp2 = inp2.trim()\n giaiBai(inp1, inp2)\n process.exit();\n });\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [length, distinct] = input\n const nums = readline().split(' ').map(Number)\n helper(nums, length, distinct)\n}\n\nfunction helper(nums, length, distinct) {\n let cnt = new Map()\n let unique = 0\n let j = 0\n \n for (let i = 0; i < length; i++) {\n const num = nums[i]\n if (!cnt.has(num))\n unique++\n cnt.set(num, (cnt.get(num) || 0) + 1)\n while (unique === distinct) {\n cnt.set(nums[j], cnt.get(nums[j])-1);\n if (cnt.get(nums[j]) === 0) {\n console.log((j + 1) + ' ' + (i + 1))\n return\n }\n j++\n }\n }\n \n console.log('-1 -1')\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100010);\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n\nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100010).fill(0);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = [];\n // const counts = new Array(100010);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100010);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ');\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n\n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100001);\n // const counts = new Array(100010);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[parseInt(ar[i], 10)]) {\n counts[parseInt(ar[i], 10)] = `${i}`;\n if (ar[i] == ar[start]) {\n while (counts[parseInt(ar[start], 10)] != start) {\n start++;\n }\n }\n continue;\n }\n counts[parseInt(ar[i], 10)] = `${i}`;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n \n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n const counts = new Array(100001).fill(0);\n // const counts = new Array(100010);\n // for (let i = 0; i <= 100010; i++) {\n // counts[i] = 0;\n // }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n \n const result = countSegment(n, k, arr);\n printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n // const counts = new Array(100010).fill(0);\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [length, distinct] = input\n const nums = readline().split(' ').map(Number)\n helper(nums, length, distinct)\n}\n\nfunction helper(nums, length, distinct) {\n let cnt = new Map()\n let unique = 0\n let j = 0\n\n for (let i = 0; i < length; i++) {\n const num = nums[i]\n if (!cnt.has(num))\n unique++\n cnt.set(num, (cnt.get(num) || 0) + 1)\n while (unique === distinct) {\n cnt.set(num, cnt.get(num)-1);\n if (cnt.get(num) === 0) {\n console.log((j + 1) + ' ' + (i + 1))\n return\n }\n j++\n }\n }\n\n console.log('-1 -1')\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [length, distinct] = input\n const nums = readline().split(' ').map(Number)\n helper(nums, length, distinct)\n}\n\nfunction helper(nums, length, distinct) {\n let cnt = new Map()\n let unique = 0\n let j = 0\n\n for (let i = 0; i < length; i++) {\n const num = nums[i]\n if (!cnt.has(num))\n unique++\n cnt.set(num, (cnt.get(num) || 0) + 1)\n while (unique === distinct) {\n cnt.set(num, cnt.get(num)-1);\n if (cnt.get(num) === 0) {\n console.log(i + ' ' + j)\n return\n }\n j++\n }\n }\n\n console.log('-1 -1')\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n // const nk = parseInt(readLine(), 10);\n const nk = readLine().split(' ').map(Number);\n const arr = `0 ${readLine()}`.split(' ').map(Number);\n const n = nk[0];\n const k = nk[1];\n // console.log(n, k, arr)\n \n const result = countSegment(n, k, arr);\n // printResult(result);\n}\n \nconst countSegment = (n, k, ar) => {\n // const counts = new Array(100010).fill(0);\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n counts[ar[i]] = i;\n if (ar[i] === ar[start]) {\n while (counts[ar[start]] !== start) {\n start++;\n }\n }\n continue;\n }\n counts[ar[i]] = i;\n sum++;\n if (sum === k) {\n end = i;\n break;\n }\n }\n \n return end ? `${start} ${end}` : `-1 -1`;\n};\n \nconst countSegment2 = (n, k, ar) => {\n const counts = new Array(100010);\n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n let start = 1;\n let end = 0;\n let sum = 0;\n let f;\n for (let i = 1; i <= n; i++) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n end = i;\n f = 1;\n break;\n }\n }\n \n for (let i = 0; i <= 100010; i++) {\n counts[i] = 0;\n }\n sum = 0;\n for (let i = end; i >= 1; i--) {\n if (counts[ar[i]]) {\n continue;\n }\n counts[ar[i]] = 1;\n sum++;\n if (sum === k) {\n start = i;\n break;\n }\n }\n return f ? `${start} ${end}` : `-1 -1`;\n};\n \nfunction printResult(x) {\n process.stdout.write(x);\n}"}, {"source_code": "function giaiBai(inp1, inp2) {\n inp1 = inp1.split(' ').map(e => parseInt(e))\n inp2 = inp2.split(' ').map(e => parseInt(e))\n inp2.unshift(0)\n\n let n = inp1[0],\n k = inp1[1],\n a = inp2,\n c = new Array(10e5).fill(0),\n count = 0,\n j = 0\n\n for(var i = 1; i <= n; i++) {\n c[a[i]]++\n if (c[a[i]] === 1) {\n count++\n }\n while (count === k) {\n j++\n c[a[j]]--\n if(c[a[j]] === 0) {\n console.log(j, i)\n break\n }\n }\n if(count === k) {\n break\n }\n }\n if (count === k) {\n return\n }\n console.log('-1 -1')\n}\n\n// var readline = require('readline');\n// Get process.stdin as the standard input object.\n// var standard_input = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout,\n// terminal: false\n// });\nvar standard_input = process.stdin;\n// Set input character encoding.\n// standard_input.setEncoding('utf-8');\n\n// Prompt user to input data in console.\n// console.log(\"Please input text in command line.\");\n\n// When user input data and click enter key.\nstandard_input.on('line', function (inp1) {\n// console.log(inp1);\n standard_input.on('line', function (inp2) {\n // Print user input in console.\n inp1 = inp1.trim()\n inp2 = inp2.trim()\n giaiBai(inp1, inp2)\n process.exit();\n });\n});\n"}, {"source_code": "function giaiBai(inp1, inp2) {\n inp1 = inp1.split(' ').map(e => parseInt(e))\n inp2 = inp2.split(' ').map(e => parseInt(e))\n inp2.unshift(0)\n\n let n = inp1[0],\n k = inp1[1],\n a = inp2,\n c = new Array(10e5).fill(0),\n count = 0,\n j = 0\n\n for(var i = 1; i <= n; i++) {\n c[a[i]]++\n if (c[a[i]] === 1) {\n count++\n }\n while (count === k) {\n j++\n c[a[j]]--\n if(c[a[j]] === 0) {\n console.log(j, i)\n break\n }\n }\n if(count === k) {\n break\n }\n }\n if (count === k) {\n return\n }\n console.log('-1 -1')\n}\n\nvar readline = require('readline');\n// Get process.stdin as the standard input object.\nvar standard_input = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n// Set input character encoding.\n// standard_input.setEncoding('utf-8');\n\n// Prompt user to input data in console.\n// console.log(\"Please input text in command line.\");\n\n// When user input data and click enter key.\nstandard_input.on('data1', function (inp1) {\n standard_input.on('data2', function (inp2) {\n // Print user input in console.\n inp1 = inp1.trim()\n inp2 = inp2.trim()\n giaiBai(inp1, inp2)\n process.exit();\n });\n});"}], "src_uid": "4b423274448ff3f0dee7644203706805"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let n = +readLine();\n let count = 0;\n\n while (n > 1 && n < Number.MAX_SAFE_INTEGER) {\n if (n % 6 === 0) {\n while (n % 6 === 0) {\n n /= 6;\n count++;\n }\n } else {\n n *= 2;\n count++;\n }\n }\n if (n === 1) console.log(count);\n else console.log(-1);\n }\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = BigInt(d);\n\n if (n === 1n) {\n ans += '0\\n';\n }\n else {\n let test = 0;\n for (let i = 0; i < 50; i++) {\n if (n % 6n === 0n) {\n n = n / 6n;\n }\n else {\n n = n * 2n;\n }\n\n if (n === 1n) {\n test = i + 1;\n break;\n }\n }\n\n if (test) {\n ans += `${test}\\n`;\n }\n else {\n ans += `-1\\n`;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n function solve(x, moves) {\n if (x === 1) { return moves; }\n else if (x%2 === 1) { return solve(2*x, moves+1); }\n else if (x%6 === 0) { return solve(Math.floor(x/6), moves+1); }\n else { return -1; }\n }\n const testCases = parseInt(readline());\n for (var i=0; i {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n var n = parseInt(str)\n var temp = n\n var timesOfTwo = 0\n var timesOfThree = 0\n while(temp%2==0){\n temp = temp / 2\n timesOfTwo+=1\n }\n while(temp%3==0){\n temp = temp / 3\n timesOfThree+=1\n }\n // console.log(timesOfTwo, timesOfThree)\n if(temp==1&×OfTwo<=timesOfThree){\n return timesOfThree*2 - timesOfTwo\n }\n else return -1\n}"}, {"source_code": "var n = readline();\nvar map = [];\nfor (var i = 0; i1e18)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tanswer++;\n\t}\n\tif(flag==0)\n\t{\n\t\tprint(-1);\n\t}\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var c2 = 0;\n var c3 = 0;\n while (n % 2 === 0) {\n n /= 2;\n c2++;\n }\n while (n % 3 === 0) {\n n /= 3;\n c3++;\n }\n if (n !== 1) {\n write(-1);\n return;\n }\n if (c2 > c3) {\n write(-1);\n } else {\n write(c3 * 2 - c2);\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tif(n == 1){\n\t\t\toutput[i] = 0;\n\t\t\tcontinue;\n\t\t}\n\t\tvar two = 0;\n\t\tvar three = 0;\n\t\twhile(n % 3 == 0){\n\t\t\tn /= 3;\n\t\t\tthree++;\n\t\t}\n\t\twhile(n % 2 == 0){\n\t\t\tn /= 2;\n\t\t\ttwo++;\n\t\t}\n\t\tif(n != 1){\n\t\t\toutput[i] = -1;\n\t\t}else{\n\t\t\tif(three >= two){\n\t\t\t\toutput[i] = two + (three - two) * 2;\n\t\t\t}else{\n\t\t\t\toutput[i] = -1;\n\t\t\t}\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\nfunction getPrimeFactorization(val){\n var primeMap = {};\n var div = 2;\n while(val != 1){\n if(val % div == 0){\n var count = 2;\n while(val % Math.pow(div, count) == 0){\n count++;\n }\n (primeMap[div] == null) ? primeMap[div] = (count - 1) : primeMap[div] += (count - 1);\n val /= Math.pow(div, count - 1);\n if(isPrime(val)){\n (primeMap[val] == null) ? primeMap[val] = 1 : primeMap[val]++;\n break;\n }\n }\n div = (div == 2) ? div + 1 : div + 2;\n }\n return primeMap;\n}\nfunction isPrime(val){\n if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let n = +data[i];\n let check = false;\n let count = 0;\n while (true) {\n const mod = n % 6;\n if (n === 1) {\n console.log(count);\n break; \n } else if (mod && check) {\n console.log(-1);\n break;\n } else if (!mod) {\n n /= 6;\n check = false;\n }\n else {\n n *= 2;\n check = true;\n }\n count += 1;\n }\n i += 1;\n }\n }"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n function solve(x, moves) {\n console.log(x);\n if (x === 1) { return moves; }\n else if (x%2 === 1) { return solve(2*x, moves+1); }\n else if (x%6 === 0) { return solve(Math.floor(x/6), moves+1); }\n else { return -1; }\n }\n const testCases = parseInt(readline());\n for (var i=0; i { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\nfunction main(){\n\tlet tests = parseInt(readline());\n\twhile(tests--){\n\t\tlet path = readline();\n\t\tlet cntL = 0;\n\t\tlet mx = 0;\n\t\tfor(let i = 0; i < path.length; i++){\n\t\t\tlet char = path[i];\n\t\t\tif(char == 'R'){\n\t\t\t\tcntL = 0;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcntL++;\n\t\t\t\tmx = Math.max(mx, cntL);\n\t\t\t}\n\t\t}\n\t\tconsole.log(mx + 1);\n\t}\n}\n", "positive_code": [{"source_code": "// Problem Link: https://codeforces.com/contest/1324/problem/C\n// Solution Link: \n\n'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nlet results = [];\n\nconst getInput = () => {\n const lineInput = readline();\n const testCase = parseInt(lineInput);\n\n for(let i = 0; i < testCase; i++){\n const lineInput = readline() + \"R\";\n results.push(calculateJumpRange(lineInput));\n }\n \n};\n\nconst isPossible = (moveSequence, jumpRange) => {\n let currentPos = -1\n while(currentPos < moveSequence.length - 1){\n let nextPos = -1;\n for(let i = currentPos + 1; i < Math.min(currentPos + jumpRange + 1, moveSequence.length); i++){\n if(moveSequence[i] === \"R\"){\n nextPos = i;\n break;\n }\n }\n\n if(nextPos === -1)\n return false;\n currentPos = nextPos;\n }\n\n return true;\n}\n\nconst calculateJumpRange = (moveSequence) => {\n \n let low = 1, high = moveSequence.length + 1;\n let len = high;\n while(low <= high) {\n let mid = Math.floor((low + high) / 2);\n\n if(isPossible(moveSequence, mid))\n len = mid, high = mid - 1;\n else\n low = mid + 1;\n } \n\n return len;\n}\n\nfunction main() {\n getInput();\n for(let r of results)\n console.log(r);\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let t = readInt(input)\n while(t--) {\n let s = readString(input) + 'R'\n let min = -Infinity\n let count = 0\n const length = s.length\n for(let i = 0; i < length; i++) {\n // console.log(i, count, min)\n if(s[i] === 'L') count++\n else {\n min = min < count + 1 ? count + 1 : min\n count = 0\n }\n }\n wr(min)\n }\n}"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface(process.stdin, process.stdout)\n\nconst input = []\n\nrl.on('line', line => input.push(line.toString()))\n\nrl.on('close', () => {\n solve()\n})\n\nconst solve = () => {\n const t = Number(input[0])\n\n for (let testCase = 1; testCase <= t; testCase++) {\n const s = 'R' + input[testCase] + 'R'\n\n const arr = s\n .split('')\n .map((char, index) => (char === 'R' ? index : -1))\n .filter(num => ~num)\n\n d = 0\n\n for (let i = 1; i < arr.length; i++) {\n d = Math.max(d, arr[i] - arr[i - 1])\n }\n\n console.log(d)\n }\n}\n"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const s = 'R' + getLine() + 'R'\n const n = s.length\n let last = 0\n let ans = 0\n for (let i = 1; i < n; ++i) {\n if (s[i] === 'R') {\n ans = Math.max(ans, i - last)\n last = i\n }\n }\n print(ans)\n }\n}"}, {"source_code": "var t = Number(readline());\nfor (var k=0;km){m=r;}\n r=1;\n }\n else{\n r++;\n }\n }\n print((r>m)?r:m);\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var s = nextCharArray();\n var len = s.length;\n var max = 0;//renzokuLnoMax + 1\n var count = 0;\n for(var j = 0; j < len; j++){\n if(s[j] == \"L\"){\n count++;\n }else{\n max = Math.max(max,count + 1);\n count = 0;\n }\n }\n \tmax = Math.max(max,count + 1);\n output[i] = max;\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r0;)\"R\"==t[e-1]?r=1:(r++,r>n&&(n=r)),e--;o.default.puts(n)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "var t = parseInt(readline());\n\nfor (var i = 0; i < t; i++) {\n var s = readline();\n\n var ara = [];\n ara.push(0);\n for (var j = 0; j < s.length; j++) {\n if (s[j] == \"R\") ara.push(j + 1);\n }\n ara.push(s.length + 1);\n\n var max = ara[1] - ara[0];\n for (var j = 0; j < ara.length - 1; j++) {\n var diff = ara[j + 1] - ara[j];\n if (diff > max) max = diff;\n }\n\n print(max);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\nfunction main(){\n\tlet tests = parseInt(readline());\n\twhile(tests--){\n\t\tlet path = readline();\n\t\tlet cntL = 0;\n\t\tlet mx = 0;\n\t\t[...path].forEach(char => {\n\t\t\tif(char == 'R'){\n\t\t\t\tcntL = 0;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcntL++;\n\t\t\t\tmx = Math.max(mx, cntL);\n\t\t\t}\n\t\t});\n\t\tconsole.log(mx + 1);\n\t}\n}\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\n\nfor (var i = 0; i < t; i++) {\n var s = readline();\n\n var ara = [];\n ara.push(0);\n for (var i = 0; i < s.length; i++) {\n if (s[i] == \"R\") ara.push(i + 1);\n }\n ara.push(s.length + 1);\n\n var max = ara[1] - ara[0];\n for (var j = 0; j < ara.length - 1; j++) {\n var diff = ara[j + 1] - ara[j];\n if (diff > max) max = diff;\n }\n\n print(max);\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor (var i = 0; i < t; i++) {\n var s = readline();\n\n var ara = [];\n ara.push(0);\n for (var i = 0; i < s.length; i++) {\n if (s[i] == \"R\") ara.push(i + 1);\n }\n ara.push(s.length + 1);\n\n var max = ara[1] - ara[0];\n for (var i = 0; i < ara.length - 1; i++) {\n var diff = ara[i + 1] - ara[i];\n if (diff > max) max = diff;\n }\n\n print(max);\n}"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface(process.stdin, process.stdout)\n\nconst input = []\n\nrl.on('line', line => input.push(line.toString()))\n\nrl.on('close', () => {\n solve()\n})\n\nconst binarySearch = s => {\n const isFeasible = maxStep => {\n let visited = Array(s.length + 1).fill(false)\n\n const dfs = u => {\n visited[u] = true\n\n if (s[u] === 'R') {\n for (let step = 1; step <= maxStep; step++) {\n const v = u + step\n\n if (v < s.length && v >= 0 && !visited[v]) {\n dfs(v)\n }\n }\n }\n }\n\n dfs(0)\n return visited[s.length]\n }\n\n let low = 0\n let high = s.length\n let d = -1\n\n while (low <= high) {\n const mid = Math.floor((low + high) / 2)\n\n if (isFeasible(mid)) {\n d = mid\n high = mid - 1\n } else {\n low = mid + 1\n }\n }\n\n return d\n}\n\nconst solve = () => {\n const t = Number(input[0])\n\n for (let testCase = 1; testCase <= t; testCase++) {\n const s = input[testCase]\n const d = binarySearch('R' + s)\n console.log(d)\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r0;)\"R\"==t[e-1]?r=1:(console.log(e),console.log(t),r++,r>n&&(n=r)),e--;o.default.puts(n)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "src_uid": "6451507b21854d5b81aeaf0491ddf584"} {"source_code": "function intersection (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) !== -1) return true;\n\treturn false;\n}\n\nfunction merge (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) === -1) b.push(a[i]);\n\treturn b;\n}\n\n;(function () {\n\n\tprint((function (n, m) {\n\n\t\tfor (var i = 0, a = []; i <= m; i++) a[i] = [];\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar s = readline();\n\t\t\tif (s[0] == '0') a[0].push(i);\n\t\t\telse for (var j = 1, s = s.split(' '), _j = s.length; j < _j; j++) a[+s[j]].push(i);\n\t\t}\n\n\t\tvar sub = a[0].length;\n\t\ta.shift(0);\n\n\t\ta = a.filter(function (e) { return e.length; });\n\n\t\tvar flag = true;\n\t\twhile (flag) {\n\t\t\tflag = false;\n\t\t\tfor (var i = 0, _i = a.length; i < _i; i++) {\n\t\t\t\tfor (var j = 0; j < _i; j++)\n\t\t\t\t\tif (i !== j && intersection(a[i], a[j])) {\n\t\t\t\t\t\ta[i] = merge(a[i], a[j]);\n\t\t\t\t\t\ta.splice(j, 1);\n\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (flag) break;\n\t\t\t}\n\t\t}\n\n\t\treturn sub + a.length - !!a.length;\n\n\t}).apply(this, readline().split(' ').map(Number)));\n\n}).call(this);", "positive_code": [{"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = [];\n\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim().split(' ').map(Number));\n}).on('close', () => {\n const n = lines[0][0];\n const graph = {};\n\n let noOneKnow = true;\n // cover edge case, no one know any language\n for (let i = 1; i <= n; i++) {\n if (lines[i][0] > 0) {\n noOneKnow = false;\n }\n }\n if (noOneKnow) {\n console.log(n);\n return;\n }\n\n for (let i = 1; i < lines.length; i++) {\n lines[i].shift();\n graph[`${i}E`] = (graph[`${i}E`] || []).concat(lines[i]);\n for (let j = 0; j < lines[i].length; j++) {\n graph[lines[i][j]] = (graph[lines[i][j]] || []).concat(`${i}E`);\n }\n }\n\n const visited = {};\n for (let v in graph) {\n visited[v] = false;\n }\n\n const bfs = (s, graph) => {\n const queue = [s];\n\n while (queue.length > 0) {\n const u = queue.shift();\n for (let i = 0; i < graph[u].length; i++) {\n const v = graph[u][i];\n if (!visited[v]) {\n visited[v] = true;\n queue.push(v);\n }\n }\n }\n };\n\n let count = 0;\n for (let i = 1; i <= n; i++) {\n if (!visited[`${i}E`]) {\n count++;\n bfs(`${i}E`, graph);\n }\n }\n\n console.log(count - 1);\n});\n"}], "negative_code": [{"source_code": "function intersection (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) !== -1) return true;\n\treturn false;\n}\n\nfunction merge (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) === -1) b.push(a[i]);\n\treturn b;\n}\n\n;(function () {\n\n\tprint((function (n, m) {\n\n\t\tfor (var i = 0, a = []; i <= m; i++) a[i] = [];\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar s = readline().split(' ');\n\t\t\tif (s[0] === '0') a[0].push(i);\n\t\t\telse for (var j = 1, _j = s.length; j < _j; j++) a[+s[j]].push(i);\n\t\t}\n\n\t\tvar sub = a[0].length;\n\t\ta[0] = false;\n\n\t\tvar flag = true;\n\t\twhile (flag) {\n\t\t\tflag = false;\n\t\t\tfor (var i = 1, _i = a.length; i < _i; i++) {\n\t\t\t\tif (intersection(a[i - 1], a[i])) {\n\t\t\t\t\ta[i] = merge(a[i], a[i - 1]);\n\t\t\t\t\ta[i - 1] = false;\n\t\t\t\t\tflag = true;\n\t\t\t\t\ta = a.filter(function (e) { return e !== false; });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ta = a.filter(function (e) { return e.length; });\n\n\t\treturn sub + a.length - 1;\n\n\t}).apply(this, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": "function intersection (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) !== -1) return true;\n\treturn false;\n}\n\nfunction merge (a, b) {\n\tfor (var i = 0, _i = a.length; i < _i; i++)\n\t\tif (b.indexOf(a[i]) === -1) b.push(a[i]);\n\treturn b;\n}\n\n;(function () {\n\n\tprint((function (n, m) {\n\n\t\tfor (var i = 0, a = []; i <= m; i++) a[i] = [];\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar s = readline().split(' ');\n\t\t\tif (s[0] === '0') a[0].push(i);\n\t\t\telse for (var j = 1, _j = s.length; j < _j; j++) a[+s[j]].push(i);\n\t\t}\n\n\t\tvar sub = a[0].length;\n\t\ta[0] = false;\n\n\t\tvar flag = true;\n\t\twhile (flag) {\n\t\t\tflag = false;\n\t\t\tfor (var i = 1, _i = a.length; i < _i; i++) {\n\t\t\t\tif (intersection(a[i - 1], a[i])) {\n\t\t\t\t\ta[i] = merge(a[i], a[i - 1]);\n\t\t\t\t\ta[i - 1] = false;\n\t\t\t\t\tflag = true;\n\t\t\t\t\ta = a.filter(function (e) { return e !== false; });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ta = a.filter(function (e) { return e.length; });\n\n\t\treturn sub + a.length - !!a.length;\n\n\t}).apply(this, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = [];\n\nconst calculate = (arr) => {\n const sortedArr = arr.map((value, idx) => ({ value, idx: idx + 1 })).sort((a, b) => a.value - b.value);\n\n const result = [];\n const originalSorted = [sortedArr[0].idx];\n\n for (let i = 0; i < sortedArr.length - 1; i++) {\n originalSorted.push(sortedArr[i + 1].idx);\n if (sortedArr[i].value === sortedArr[i + 1].value) {\n const newArr = [];\n // clone a new arr\n for (let j = 0; j < sortedArr.length; j++) {\n if (j !== i) {\n newArr.push(sortedArr[j].idx);\n } else {\n newArr.push(sortedArr[j + 1].idx);\n newArr.push(sortedArr[j].idx);\n j++;\n }\n }\n result.push(newArr);\n }\n }\n\n result.push(originalSorted);\n return result;\n};\n\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim().split(' ').map(Number));\n}).on('close', () => {\n const arr = lines[1];\n\n if (arr.length < 3) {\n console.log('NO');\n }\n\n const result = calculate(arr);\n\n if (result && result.length >= 3) {\n console.log('YES');\n result.forEach((item) => console.log(item.join(' ')));\n } else {\n console.log('NO');\n }\n});\n"}], "src_uid": "e2836276aee2459979b232e5b29e6d57"} {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n }\r\n function readNumArray() {\r\n return readStringArray().map(Number);\r\n }\r\n \r\n function main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var abcm = readNumArray();\r\n var a = abcm[0];\r\n var b = abcm[1];\r\n var c = abcm[2];\r\n var m = abcm[3];\r\n var max = Math.max(a, b, c);\r\n var minPairs = max - (a + b + c - max) - 1;\r\n if (m > a - 1 + b - 1 + c - 1 || m < minPairs) {\r\n print('NO');\r\n continue;\r\n }\r\n \r\n print('YES');\r\n }\r\n }\r\n \r\n main();", "positive_code": [{"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let i = 0; i < Q; i++) {\r\n const N = readline();\r\n\r\n const [a, b, c, m] = N.split(\" \").map((n) => parseInt(n));\r\n const sorted = [a, b, c].sort((a, b) => a - b);\r\n\r\n const max = (a-1) + (b-1) + (c-1);\r\n const min = (sorted[2] - 1) - (sorted[0] + sorted[1]); \r\n //console.log(\"min max\", min, max);\r\n \r\n if (m >= min && m <= max) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [a, b, c, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let max = a + b + c - 3;\r\n let arr = [a, b, c];\r\n let min;\r\n arr.sort((a, b) => b - a);\r\n let n = a + b + c;\r\n if (2 * (arr[1] + arr[2]) >= n) min = 0;\r\n else min = n - 2 * (arr[1] + arr[2]) - 1;\r\n if (m >= min && m <= max) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let i = 0; i < Q; i++) {\r\n const N = readline();\r\n\r\n const [a, b, c, m] = N.split(\" \").map((n) => parseInt(n));\r\n const sorted = [a, b, c].sort();\r\n\r\n const max = (a-1) + (b-1) + (c-1);\r\n const min = (sorted[2] - 1) - (sorted[0] + sorted[1]); \r\n //console.log(\"min max\", min, max);\r\n \r\n if (m >= min && m <= max) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}], "src_uid": "fc547fc83ebbcc3c058a069ef9fef62c"} {"source_code": "var n = +readline();\nvar arr = [];\nfor(var i=0;i -1;\n}\n\nfor (var i = 0; i < n; i++) {\n\tavail[i] = readline().split(' ');\n\n\tif (isInArray(avail[i][1], days) === false) {\n\t\tdays.push(avail[i][1]);\n\t}\n\tif (isInArray(avail[i][2], days) === false) {\n\t\tdays.push(avail[i][2]);\n\t}\n}\n\n//sorting the days\ndays.sort(function(a, b) {return a - b});\n\nvar count_M = 0;\nvar count_F = 0;\nvar guests = 0;\nvar max_guests = 0;\n\n// each iteration in this loop is a new day\nfor (var i = 0; i < days.length; i++) {\n\n\t// setting counters back to 0 each new day\n\tcount_M = 0;\n\tcount_F = 0;\n\n\t// each iteration in this loop is a new person --> checking every person on each day\n\tfor (var j = 0; j < n; j++) {\n\t\t// checking availability of each person\n\t\tif (Number(days[i]) >= Number(avail[j][1]) && Number(days[i]) <= Number(avail[j][2])) {\n\t\t\t//for each person available that day check if male or female and add counter\n\t\t\tif (avail[j][0] == 'M') {\n\t\t\t\tcount_M += 1;\n\t\t\t} else {\n\t\t\t\tcount_F += 1;\n\t\t\t}\n\t\t}\n\t}\n\t// determining number of Female + Male pairs (*2 to get # of people)\n\tguests = Math.min(count_M, count_F) * 2;\n\tif (guests > max_guests) {\n\t\tmax_guests = guests;\n\t}\n}\n\nprint(max_guests);\n\n\n"}, {"source_code": "'use strict';\n\nconst n = Number(readline());\nlet dates = Array(400).fill(0);\n\nfor (let i = 0; i < n; i++) {\n const line = readline().split(' ')\n\n for (let j = Number(line[1]); j < Number(line[2])+1; j++) {\n dates[j] += line[0] === 'M' ? 1 : 10000;\n }\n}\n\nlet _dates = [...new Set(dates)]\n\nlet result = 0;\nwhile (_dates.length !== 0) {\n let _result = _dates.pop(); \n result = Math.max(result, Math.min(_result/10000|0, _result%10000));\n}\n\nprint(result * 2);\n"}, {"source_code": "var n = Number(readline());\nvar sex = new Array(n);\nvar l = new Array(n);\nvar r = new Array(n);\nfor (var i = 0; i < n; ++i) {\n var str = readline().split(\" \", 3);\n sex[i] = str[0];\n l[i] = Number(str[1]);\n r[i] = Number(str[2]);\n}\n\nvar ans = 0;\nfor (var i = 1; i <= 366; ++i) {\n var a = 0, b = 0;\n for (var j = 0; j < n; ++j) {\n if (l[j] <= i && r[j] >= i) {\n if (sex[j] == \"M\") {\n ++a;\n } else {\n ++b;\n }\n }\n }\n ans = Math.max(ans, Math.min(a, b) * 2);\n}\nprint(ans);"}, {"source_code": "var readInt = () => parseInt(readline())\nvar readIntArray = () => readline().split(' ').forEach(item => parseInt(item))\nArray.prototype.fill = function(value) {\n for (var i = 0; i < this.length; i++)\n this[i] = value\n return this\n}\n\nvar N = readInt()\nvar boys = (new Array(366)).fill(0)\nvar girls = new Array(366).fill(0)\n\nfor (var i = 0; i < N; i++) {\n var f = readline().split(' ')\n var a = (f[0] === 'M' ? boys : girls)\n\n for (var n = parseInt(f[2]), j = parseInt(f[1])-1; j < n; j++) {\n a[j] += 1\n }\n}\nvar ans = 0\nfor (var i = 0; i < 366; i++) {\n ans = Math.max(ans, 2*Math.min(boys[i], girls[i]))\n}\nprint(ans)"}], "negative_code": [{"source_code": "var n = +readline();\nvar arr = [];\nfor(var i=0;i= i) {\n if (sex[j] == \"M\") {\n ++a;\n } else {\n ++b;\n }\n }\n }\n ans = Math.max(ans, Math.min(a, b));\n}\nprint(ans);"}], "src_uid": "75d500bad37fbd2c5456a942bde09cd3"} {"source_code": "var l = readline().split(' ')\nvar i, j\nvar t = l[0]\nvar mt = l[1]\nvar m = []\nvar b = []\nvar bn = 0\nvar r\n\nfor (i = 0; i < mt; i++) m[i] = 0\n\nfor (i = 0; i < t; i++) {\n l = readline().split(' ')\n var op = l[0]\n var n = l[1]\n if (op == 'alloc') {\n print(r = alloc(n))\n } else if (op == 'erase') {\n r = erase(n)\n if (r) print(r)\n } else if (op == 'defragment') {\n defragment()\n }\n}\n\nfunction alloc (n) {\n var i, j = 0\n for (i = 0; i < mt; i++) {\n if (!m[i]) {\n j++\n if (j == n) {\n b[++bn] = [i - j + 1, i]\n while (j > 0) {\n m[i - j + 1] = 1\n j--\n }\n return bn\n }\n } else {j = 0}\n }\n return 'NULL'\n}\n\nfunction erase (n) {\n if (b[n]) {\n for (var i = b[n][0]; i <= b[n][1]; i++) m[i] = 0\n b[n] = null\n } else {\n return 'ILLEGAL_ERASE_ARGUMENT'\n }\n}\n\nfunction defragment () {\n var j = 0\n for (var i = 0; i < mt; i++) {\n if (!m[i]) {j++}\n else if (j) {\n var mmb\n for (var t = 0; t <= bn; t++) {\n if (b[t] && b[t][0] == i) {\n mmb = b[t]\n break\n }\n }\n for (var k = mmb[0]; k <= mmb[1]; k++) {\n m[k] = 0\n m[k - j] = 1\n }\n mmb[0] -= j\n mmb[1] -= j\n j = 0\n }\n }\n}", "positive_code": [{"source_code": "var s = readline().split( ' ' ),\n size = s[1] - '';\n\nvar mem = [];\n\nfor (; s = readline(); ) {\n switch (s.charAt( 0 )) {\n case 'a': alloc( s.replace( 'alloc ', '' ) - '' ); break;\n case 'e': erase( s.replace( 'erase ', '' ) - '' ); break;\n default: defragment();\n }\n}\n\nfunction alloc(x) {\n var next = alloc._ = alloc._ || 1;\n for (var i=1, j=0; i= len) {\n \talloc(j + 1, len);\n \tfind = true; break;\n }\n } \n if (!find) {\n \tif (m - mem[mem.length - 1].end >= len) {\n\t \talloc(mem.length, len);\n\t } else {\n print('NULL');\n }\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tvar find = false;\n \tfor (var j = 0; j < mem.length; ++j) {\n \tif (mem[j]['id'] === id) {\n \tmem.splice(j, 1);\n \tfind = true; break;\n }\n }\n if (!find) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n }\n } break;\n case 'defragment': {\n \tfor (var j = 1; j < mem.length; ++j) {\n \t\tvar len = mem[j].end - mem[j].begin;\n \tmem[j].begin = mem[j - 1].end + 1 || 1;\n \tmem[j].end = mem[j].begin + len;\n }\n } break;\n }\n}\n"}], "negative_code": [{"source_code": "var l = readline().split(' ')\nvar i, j\nvar t = l[0]\nvar mt = l[1]\nvar m = []\nvar b = []\nvar bn = 0\n\nfor (i = 0; i < mt; i++) m[i] = 0\n\nfor (i = 0; i < t; i++) {\n l = readline().split(' ')\n var op = l[0]\n var n = l[1]\n if (op == 'alloc') {\n print(alloc(n))\n } else if (op == 'erase') {\n var r = erase(n)\n if (r) print(r)\n } else if (op == 'defragment') {\n defragment()\n }\n}\n\nfunction alloc (n) {\n var i, j = 0\n for (i = 0; i < mt; i++) {\n if (!m[i]) {\n j++\n if (j == n) {\n b[++bn] = [i - j + 1, i]\n while (j > 0) {\n m[i - j + 1] = 1\n j--\n }\n return bn\n }\n } else {j = 0}\n }\n return 'NULL'\n}\n\nfunction erase (n) {\n if (b[n]) {\n for (var i = b[n][0]; i <= b[n][1]; i++) m[i] = 0\n b[n] = null\n } else {\n return 'ILLEGAL_ERASE_ARGUMENT'\n }\n}\n\nfunction defragment () {\n var j = 0\n for (var i = 0; i < mt; i++) {\n if (!m[i]) {j++}\n else if (j) {\n var mmb\n for (var t = 0; t <= bn; t++) {\n if (b[t] && b[t][0] == i) {\n mmb = b[t]\n break\n }\n }\n for (var k = mmb[0]; k < mmb[1]; k++) {\n m[k] = 0\n m[k - j] = 1\n }\n mmb[0] -= j\n mmb[1] -= j\n j = 0\n }\n }\n}"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar mem = [{\n\t'id': NaN,\n\t'begin': 0,\n\t'end': 0\n}], cnt = 0;\nfunction alloc(i, len) {\n\tmem.splice(i, 0, {\n\t\t'id': ++cnt,\n \t'begin': mem[i - 1].end + 1,\n \t'end': mem[i - 1].end + len,\n });\n print(cnt);\n}\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \t\tvar find = false;\n \tvar len = parseInt(a[1]);\n \tfor (var j = 0; j < mem.length - 1; ++j) {\n \t if (mem[j + 1].begin - mem[j].end > len) {\n \talloc(j + 1, len);\n \tfind = true; break;\n }\n } \n if (m - mem[mem.length - 1].end >= len) {\n \talloc(mem.length, len);\n \tfind = true;\n }\n if (!find) {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tvar find = false;\n \tfor (var j = 0; j < mem.length; ++j) {\n \tif (mem[j]['id'] === id) {\n \tmem.splice(j, 1);\n \tfind = true; break;\n }\n }\n if (!find) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n }\n } break;\n case 'defragment': {\n \tfor (var j = 1; j < mem.length; ++j) {\n \t\tvar len = mem[j].end - mem[j].begin;\n \tmem[j].begin = mem[j - 1].end + 1 || 1;\n \tmem[j].end = mem[j].begin + len;\n }\n } break;\n }\n}\n"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar tot = 0, top = 0;\nvar arr = [null];\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \tvar len = parseInt(a[1]);\n \tif (top + len <= m && len > 0) {\n \ttot += len; top += len;\n \tprint(arr.length);\n \tarr.push(len);\n \t} else {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tif (!arr[id]) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n } else {\n \t tot -= arr[id];\n \tif (id === arr.length - 1) {\n \ttop -= arr.pop();\n } else {\n arr[id] = null;\n }\n }\n } break;\n case 'defragment': {\n \ttop = tot;\n } break;\n }\n}\n"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar tot = 0, top = 0;\nvar arr = [null];\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \tvar len = parseInt(a[1]);\n \tif (top + len <= m && len > 0) {\n \ttot += len; top += len;\n \tprint(arr.length);\n \tarr.push(len);\n \t} else {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tif (!arr[id]) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n } else {\n \t tot -= arr[id];\n \tif (id === arr.length - 1) {\n \ttop -= arr[id];\n }\n arr[id] = null;\n }\n } break;\n case 'defragment': {\n \ttop = tot;\n } break;\n }\n}\n"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar tot = 0, top = 0;\nvar arr = [null];\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \tvar len = parseInt(a[1]);\n \tif (top + len <= m) {\n \ttot += len; top += len;\n \tprint(arr.length);\n \tarr.push(len);\n \t} else {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tif (!arr[id]) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n } else {\n \ttot -= arr[id];\n arr[id] = null;\n }\n } break;\n case 'defragment': {\n \ttop = tot;\n } break;\n }\n}\n"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar mem = [{\n\t'id': NaN,\n\t'begin': 0,\n\t'end': 0\n}], cnt = 0;\nfunction alloc(i, len) {\n\tmem.splice(i, 0, {\n\t\t'id': ++cnt,\n \t'begin': mem[i - 1].end + 1,\n \t'end': mem[i - 1].end + len,\n });\n print(cnt);\n}\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \t\tvar find = false;\n \tvar len = parseInt(a[1]);\n \tfor (var j = 0; j < mem.length - 1; ++j) {\n \t if (mem[j + 1].begin - mem[j].end > len) {\n \talloc(j + 1, len);\n \tfind = true; break;\n }\n } \n if (m - mem[mem.length - 1].end > len) {\n \talloc(mem.length, len);\n \tfind = true;\n }\n if (!find) {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tvar find = false;\n \tfor (var j = 0; j < mem.length; ++j) {\n \tif (mem[j]['id'] === id) {\n \tmem.splice(j, 1);\n \tfind = true; break;\n }\n }\n if (!find) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n }\n } break;\n case 'defragment': {\n \tfor (var j = 1; j < mem.length; ++j) {\n \t\tvar len = mem[j].end - mem[j].begin;\n \tmem[j].begin = mem[j - 1].end + 1 || 1;\n \tmem[j].end = mem[j].begin + len;\n }\n } break;\n }\n}\n"}, {"source_code": "var a = readline().split(' ').map(function (e){\n\treturn parseInt(e);\n});\nvar n = a[0], m = a[1];\nvar tot = 0, top = 0;\nvar arr = [-1];\nfor (var i = 0; i < n; ++i) {\n\ta = readline().split(' ');\n\tswitch (a[0]) {\n \tcase 'alloc': {\n \tvar len = parseInt(a[1]);\n \tif (top + len <= m) {\n \ttot += len; top += len;\n \tprint(arr.length);\n \tarr.push(len);\n \t} else {\n \tprint('NULL');\n }\n } break;\n case 'erase': {\n \tvar id = parseInt(a[1]);\n \tif (!arr[id]) {\n \tprint('ILLEGAL_ERASE_ARGUMENT');\n } else {\n \ttot -= arr[id];\n arr[id] = null;\n }\n } break;\n case 'defragment': {\n \ttop = tot;\n } break;\n }\n}\n"}], "src_uid": "a6cba17c5ddb93f6741e00280fb6c54c"} {"source_code": "var t=Number(readline());\r\nfor (var i=0; ix%2==1);\r\n if (w.length==n) {\r\n print(\"YES\");\r\n }\r\n else {\r\n print(\"NO\");\r\n }\r\n}", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// End of Codeforces interface\r\n\r\nfunction main() {\r\n const testCaseCount = readline();\r\n\r\n for (let i = 0; i < testCaseCount; i++) {\r\n readline();\r\n const numberSet = readline().split(\" \").map(n => parseInt(n));\r\n let evenCount = 0;\r\n let oddCount = 0;\r\n \r\n for (let number of numberSet) {\r\n if (number % 2 === 0) {\r\n evenCount += 1;\r\n } else {\r\n oddCount += 1;\r\n }\r\n }\r\n\r\n if (evenCount === oddCount) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let n = readline()\n n = +n\n let odd = 0, even = 0\n let arr = readline().split(' ').map(x => {\n (x % 2 == 0) ? even++ : odd++\n return +x\n })\n if (odd == even) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n}\n\nfunction sortAscending(a, b) {\n return a[0] - b[0]\n}\n// String.prototype.replaceAt = function (index, replacement) {\n// return this.substring(0, index) + replacement + this.substring(index + replacement.length)\n// }\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(num => parseInt(num));\r\n let odd = 0, even = 0;\r\n for(let i = 0; i < arr.length; i++)\r\n if (arr[i] % 2 === 0)\r\n even++;\r\n else\r\n odd++;\r\n if (odd === even) {\r\n console.log('Yes');\r\n } else\r\n console.log('No');\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, arr))\n }\n});\n\nfunction solve(n, arr) {\n let odd = 0\n let even = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] & 1) {\n odd++\n } else {\n even++\n }\n }\n return odd === even ? 'Yes' : 'No'\n}\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N * 2);\r\n\t\tvar div = 0;\r\n\t\tfor(var i = 0; i < N * 2; i++){\r\n\t\t\tif(list[i] % 2 == 0){\r\n\t\t\t\tdiv++;\r\n\t\t\t}else{\r\n\t\t\t\tdiv--;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(div == 0){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "function solution() {\r\n const n = readline();\r\n const arr = readline().split(' ').map(elem => +elem);\r\n\r\n return (arr.filter(elem => elem % 2 === 0).length === (arr.length >> 1)) ? 'Yes' : 'No';\r\n}\r\n\r\nfunction main(t) {\r\n for (var i = 0; i < t; i++) {\r\n print(solution());\r\n }\r\n}\r\n\r\nconst t = readline();\r\nmain(t);\r\n"}, {"source_code": "r=readline;for(r();n=r();print(i==n?'yes':'no'))i=0,r().split(\" \").map(x=>i+=x&1)"}, {"source_code": "r=readline;for(r();n=r();print(i==n?'yes':'no'))i=0,r().split(\" \").map(x=>i+=x&1)\r\n"}, {"source_code": "r=readline;for(r();n=r()|(i=0);print(i==n?'yes':'no'))r().split(\" \").map(x=>i+=x&1)"}, {"source_code": "for(t=readline();t--;){\r\n readline()\r\n c=[0,0]\r\n readline().split(' ').forEach(e=>c[e%2]++)\r\n print(c[0]==c[1]?'Yes':'No')\r\n}"}, {"source_code": "var testCase = +readline()\r\n\r\nfor(var i=0;i+node)\r\n for(var j=0;j parseInt(x));\r\nfor(var i=0;i<2*x;i++)\r\n{\r\n if(a[i]%2===0)\r\n e++;\r\n else\r\n o++;\r\n}\r\nif(e==o)\r\nprint(\"YES\");\r\nelse\r\nprint(\"NO\");\r\n}"}, {"source_code": "t = +readline();\n\nfor (i = 0; i < t; i++) {\n n = +readline();\n a = readline().split(' ');\n a = a.map(Number);\n\n count = 0;\n for (j = 0; j < 2*n; j++) {\n if (a[j] % 2 === 0) {\n count++;\n if (count > n) {\n break;\n }\n }\n }\n\n if (count === n) {\n print('Yes');\n }\n else{\n print('No');\n }\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction oddSet() {\r\n const n = readline();\r\n const arr = readline().split(' ').map(elem => +elem);\r\n\r\n return (arr.filter(elem => elem % 2 === 0).length === (arr.length >> 1)) ? 'Yes' : 'No';\r\n}\r\n\r\nfunction main() {\r\n const t = +readline();\r\n for (let i = 0; i < t; i++) {\r\n print(oddSet());\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var odd = 0;\n var even = 0;\n for(var l = 0; l < k.length; l++){\n if(k[l] % 2 == 1){\n odd++;\n }else{\n even++;\n }\n }\n if(odd % e === 0 && odd !== 0 && even % e === 0 && even !== 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const numbers = d.split(\" \").map(Number);\n let ans = 0;\n\n for (let i = 0; i < numbers.length; i++) {\n if (numbers[i] % 2) {\n ans++;\n } else {\n ans--;\n }\n }\n\n if (ans === 0) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var odd = 0;\n var even = 0;\n for(var l = 0; l < k.length; l++){\n if(k[l] % 2 == 1){\n odd++;\n }else{\n even++;\n }\n }\n if(odd % e === 0 && odd !== 0 && even % e === 0 && even !== 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let n = parseInt(readLine());\r\n let arr = readLine().split(\" \");\r\n let even = 0, odd = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n let num = parseInt(arr[i]);\r\n if (num % 2 == 0) even++;\r\n else odd++;\r\n }\r\n if (even == odd) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n\r\n let n = parseInt(readLine());\r\n let a = readLine().split(\" \").map(x => parseInt(x));\r\n solve(n, a);\r\n\r\n }\r\n}\r\n\r\nfunction solve(n, a) {\r\n let odd = 0, even = 0;\r\n for (let i of a) {\r\n if (i % 2) odd++;\r\n else even++;\r\n }\r\n if (odd == even) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n}"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var n = parseInt(args[2 * i - 1], 10);\r\n var v = args[2 * i].split(\" \").map((n) => parseInt(n, 10));\r\n var cnt = 0;\r\n for (var j = 0; j < 2 * n; j++) {\r\n if (v[j] % 2 === 1) {\r\n cnt++;\r\n }\r\n }\r\n if (cnt === n) {\r\n console.log(\"Yes\");\r\n } else {\r\n console.log(\"No\");\r\n }\r\n }\r\n}"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str, i) => {\r\n if (i % 2 === 1) {\r\n str = str.split(' ').map(str => parseInt(str));\r\n if (oddSet(str)) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No');\r\n }\r\n }\r\n });\r\n})\r\n\r\nconst oddSet = (arr) => {\r\n let oddNums = 0;\r\n arr.forEach((num) => {\r\n if (num % 2 === 1) {\r\n oddNums++;\r\n }\r\n });\r\n return oddNums === Math.floor(arr.length / 2);\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n n=parseInt(readLine());\r\n ara=readLine();\r\n ara=ara.split(\" \");\r\n cnt=0;\r\n for(i=0;i<2*n;i++)\r\n {\r\n val=parseInt(ara[i]);\r\n if(val&1)\r\n cnt++;\r\n }\r\n if(cnt===n)\r\n {\r\n console.log(\"YES\");\r\n }\r\n else\r\n {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet x = 0;\n\t\ta.forEach(e => {\n\t\t\tif (e%2 === 1) {\n\t\t\t\tx++;\n\t\t\t}\n\t\t});\n\t\tans.push(x == n);\n\t}\n\tconsole.log(ans.map(e => e?'Yes':'No').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var c = 0;\r\n readArray((x) => { if (Number(x) & 1) {\r\n c++;\r\n }});\r\n write(c === n ? 'Yes' : 'No');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "function oddSet() {\r\n const n = readline();\r\n const arr = readline().split(' ').map(elem => +elem);\r\n \r\n return (arr.filter(elem => elem % 2 === 0).length === (arr.length >> 1)) ? 'Yes' : 'No';\r\n}\r\n \r\nfunction main(t) {\r\n for (let i = 0; i < t; i++) {\r\n print(oddSet());\r\n }\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0].split(' ').map(Number);\n var isOdd = false;\n for(var a = 1; a <= n * 2; a++){\n var k = lines[a].split(' ').map(Number);\n if(a % 2 === 0){\n for(var c = 0; c < k.length; c+=2){\n var d = k[c] + k[c+1];\n if(d % 2 === 1){\n isOdd = true;\n d = 0;\n }else{\n isOdd = false;\n break;\n }\n }\n if(isOdd === false){\n console.log('No');\n }else{\n console.log('Yes');\n }\n }\n \n }\n \n});"}, {"source_code": "r=readline;for(r();n=r()|(i=0);print(i&n?'yes':'no'))r().split(\" \").map(x=>i+=x&1)\r\n"}, {"source_code": "for(t=readline();t--;){\r\n readline()\r\n c=[]\r\n readline().split(' ').forEach(e=>c[e%2]++)\r\n print(c[0]==c[1]?'Yes':'No')\r\n}"}, {"source_code": "for(t=readline;t--;){\r\n readline()\r\n c=[]\r\n readline().split(' ').forEach(e=>c[e%2]++)\r\n print(c[0]==c[1]?'Yes':'No')\r\n}"}], "src_uid": "d5bd27c969d9cd910f13baa53c247871"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n function outChars(chars) {\n console.log(Object.keys(chars).sort().map(c => new Array(chars[c]).fill(c).join('')).join(''));\n }\n for (let i = 0; i < t; i++) {\n let sS = readline().split('');\n let sT = readline();\n const chars = {};\n for (let j = 0; j < sS.length; j++) {\n chars[sS[j]] = (chars[sS[j]] || 0) + 1;\n }\n if (!chars['a'] || !chars['b'] || !chars['c']) {\n outChars(chars);\n } else if (sT !== 'abc') {\n outChars(chars);\n } else {\n let ch = Object.keys(chars).sort();\n let res = new Array(chars['a']).fill('a').join('');\n res += new Array(chars['c']).fill('c').join('');\n res += new Array(chars['b']).fill('b').join('');\n res += ch.slice(3).map(c => new Array(chars[c]).fill(c).join('')).join('');\n console.log(res);\n }\n }\n\n}", "positive_code": [{"source_code": "var s, t, count, uni;\r\n var tests = parseInt(readline());\r\n\r\n function cToI(c) {\r\n return c.charCodeAt(0) - 'a'.charCodeAt(0);\r\n }\r\n\r\n function add(i, c) {\r\n for(var j = 0; j < c; j++) {\r\n uni.push(i+97);\r\n }\r\n }\r\n for (var te=0; te lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n // console.log(`DEBUG res`, res);\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, k, a)=>{\n let m = 31;\n let bits = new Array(m).fill(0);\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n bits[j] += a[i] & (1 << j) ? 1 : 0;\n }\n }\n\n let ops = k;\n\n for (let i = m - 1; i >= 0; i--) {\n if (ops === 0) break;\n if (n - bits[i] <= ops) {\n ops -= (n - bits[i]);\n bits[i] = n;\n }\n }\n\n let result = 0;\n\n for (let i = m - 1; i >= 0; i--) {\n result += bits[i] === n ? (1 << i) : 0;\n } \n return result; \n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, k] = ra();\n let a = ra();\n console.log(`${calc(n, k, a)}`);\n }\n}", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let j = 30; j >= 0 && k; j--) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif ((a[i] & 1 << j) == 0) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (cnt && cnt <= k) {\r\n\t\t\t\tk -= cnt;\r\n\t\t\t\tsum += 2**j;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = a[0];\r\n\t\tfor (let i = 0; i < n; i++) ans &= a[i];\r\n\r\n\t\tconsole.log(ans + sum);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n\nconst { domainToASCII } = require('url');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, k, A)=>{\n let ans = 0;\n for (let i=30; i>=0; i--){\n let cnt_missing = 0;\n let bit = 1< parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let bit = new Array(31).fill(0);\r\n for (let i = 0; i < bit.length; i++) {\r\n let cnt = 0,\r\n k = 1 << (bit.length - i - 1);\r\n for (let j = 0; j < n; j++) {\r\n if (k & arr[j]) cnt++;\r\n }\r\n bit[i] = n - cnt;\r\n }\r\n let ans = 0;\r\n for (let i = 0; i < bit.length; i++) {\r\n let j = 1 << (bit.length - i - 1);\r\n if (bit[i] === 0) ans += j;\r\n else if (k >= bit[i]) {\r\n k = k - bit[i];\r\n ans += j;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let readline = require('readline'); \r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n}); \r\nlet input = []; \r\nlet takeInput = async function () { \r\n rl.on('line', function (line) {\r\n input.push(line);\r\n });\r\n}\r\ntakeInput();\r\nnumberOfline = 0;\r\nnextString = () =>{\r\n return input[numberOfline++];\r\n}\r\nnextInt = () => { \r\n return parseInt(input[numberOfline++], 10);\r\n}\r\nnextArrayOfInt = () => { \r\n let str = input[numberOfline++];\r\n return str.split(' ').map((val) => {\r\n return parseInt(val);\r\n }); \r\n}\r\nnextFloat = () => { \r\n return parseFloat(input[numberOfline++]);\r\n}\r\nintDiv = (val, div) => { \r\n return (val - val % div) / div;\r\n}\r\nlet print = (val) => { \r\n console.log(val);\r\n}\r\nlet main = () => { \r\n let test = 1;\r\n test = nextInt();\r\n while (test--){ \r\n solve()\r\n }\r\n\r\n} \r\n\r\nlet solve = () => { \r\n let [n, k] = nextArrayOfInt();\r\n // console.log(n, k);\r\n let arr = nextArrayOfInt();\r\n let bit = [];\r\n for (i = 0; i < 31; i++)\r\n {\r\n bit.push(0);\r\n }\r\n // print(bit);\r\n // print(arr);\r\n\r\n \r\n arr.forEach( (element) => {\r\n for (let i = 0; i < 31; i++)\r\n { \r\n if ((element & (1 << i)) > 0)\r\n {\r\n bit[i]++;\r\n }\r\n }\r\n });\r\n let ans = 0;\r\n for (let i = 30; i >= 0; i--)\r\n { \r\n if (bit[i] + k >= n)\r\n {\r\n ans += (1 << i);\r\n k -= (n - bit[i]);\r\n }\r\n }\r\n print(ans);\r\n // print(arr);\r\n // print(bit);\r\n\r\n\r\n\r\n \r\n}\r\nrl.on('close', main);"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar size = 31;\r\n\t\tvar bit = new Array(size).fill(0);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = 0; j < size; j++){\r\n\t\t\t\tbit[j] += list[i] % 2;\r\n\t\t\t\tlist[i] = Math.floor(list[i] / 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = size - 1; i >= 0; i--){\r\n\t\t\tdiff = N - bit[i];\r\n\t\t\tif(diff <= K){\r\n\t\t\t\tK -= diff;\r\n\t\t\t\tbit[i] += diff;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < size; i++){\r\n\t\t\tif(bit[i] == N){\r\n\t\t\t\toutput += (1 << i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, a) {\r\n for (let i = 30; i >= 0; i--) {\r\n let count = 0;\r\n for (let j = 0; j < n; j++) {\r\n if (!(a[j] & 1 << i)) count++;\r\n }\r\n if (count <= k) {\r\n for (let j = 0; j < n; j++) {\r\n a[j] |= 1 << i;\r\n }\r\n k -= count;\r\n }\r\n }\r\n let res = a[0];\r\n for (let i = 0; i < n; i++) {\r\n res &= a[i];\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n let [n, k] = (await read()).split(' ').map(Number),\r\n a = (await read()).split(' ').map(Number);\r\n solve(n, k, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n let ans = 0\n for (let i = 30; i >= 0; i--) {\n let c = 0\n arr.forEach(x => {\n if (x & (1 << i)) return\n c++\n })\n if (c <= k) {\n k -= c\n ans |= (1 << i)\n }\n }\n return ans\n}\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet sum = 0\r\n\t\tfor (let j = 30; j >= 0 && k; j--) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < n && k; i++) {\r\n\t\t\t\tif ((a[i] & 1 << j) == 0) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (cnt <= k) {\r\n\t\t\t\tk -= cnt;\r\n\t\t\t\tsum += 2**j;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = a[0];\r\n\t\tfor (let i = 0; i < n; i++) ans &= a[i];\r\n\r\n\t\tconsole.log(ans + sum);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n\nconst { domainToASCII } = require('url');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, k, A)=>{\n let ans = 0;\n for (let i=30; i>=0; i--){\n let cnt_missing = 0;\n let bit = 1< {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n if (arr[0] === arr[len - 1]) {\n console.log(len);\n } else {\n console.log(1);\n }\n }\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var isOK = false;\n for(var j = 0; j < N - 1; j++){\n if(list[j] != list[j + 1]){\n isOK = true;\n break;\n }\n }\n if(isOK){\n output[i] = 1;\n }else{\n output[i] = N;\n }\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM(pos) {\n const inputList = document.querySelectorAll(\".custom-input\");\n const input = inputList[pos];\n // return input.querySelector(\"pre\").textContent;\n return input.textContent;\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM.bind(null, 0)\n}\n\nfunction arrReverse(a, n) {\n for (let index = 0; index < n / 2; index++) {\n [a[index], a[n - index - 1] ] = [a[n - index - 1], a[index]];\n }\n}\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n\n const TRIAL_COUNT = 10;\n let a = Array(1e6);\n let b = Array(1e6);\n let nA, nB, curSum, prev, curAi;\n \n function maxForBigInt(...args) {\n return args.reduce((a, b) => a > b ? a : b);\n };\n\n while (tc_count--) {\n nA = readNum();\n for (let index = 0; index < nA; index++) {\n a[index] = readNum(); \n }\n for (let cnt = TRIAL_COUNT; cnt--;) {\n addemUp();\n arrReverse(a, nA);\n addemUp();\n }\n let ans = nA;\n writeLine(ans);\n }\n function addemUp() {\n nB = 0;\n prev = curSum = a[0];\n for (let index = 1; index < nA; index++) {\n curAi = a[index];\n if (prev !== curAi || curSum !== curAi) {\n curSum += curAi;\n }\n else {\n b[nB++] = curSum;\n curSum = curAi;\n }\n prev = curAi;\n }\n b[nB++] = curSum;\n [a, b] = [b, a];\n nA = nB;\n }\n});\n\n\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = -1;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3n;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0n, sign = 1n, ch = nextDigit();\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10n + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return BigInt(aStr.charCodeAt(++cur) - 48);\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[++cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM(pos) {\n const inputList = document.querySelectorAll(\".custom-input\");\n const input = inputList[pos];\n // return input.querySelector(\"pre\").textContent;\n return input.textContent;\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM.bind(null, 0)\n}\n\nfunction arrReverse(a, n) {\n for (let index = 0; index < n / 2; index++) {\n [a[index], a[n - index - 1] ] = [a[n - index - 1], a[index]];\n }\n}\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n\n const TRIAL_COUNT = 1;\n let a = Array(1e6);\n let b = Array(1e6);\n let nA, nB, curSum, prev, curAi;\n \n function maxForBigInt(...args) {\n return args.reduce((a, b) => a > b ? a : b);\n };\n\n while (tc_count--) {\n nA = readNum();\n for (let index = 0; index < nA; index++) {\n a[index] = readNum(); \n }\n for (let cnt = TRIAL_COUNT; cnt--;) {\n addemUp();\n arrReverse(a, nA);\n addemUp();\n }\n let ans = nA;\n writeLine(ans);\n }\n function addemUp() {\n nB = 0;\n prev = curSum = a[0];\n for (let index = 1; index < nA; index++) {\n curAi = a[index];\n if (prev !== curAi || curSum !== curAi) {\n curSum += curAi;\n }\n else {\n b[nB++] = curSum;\n curSum = curAi;\n }\n prev = curAi;\n }\n b[nB++] = curSum;\n [a, b] = [b, a];\n nA = nB;\n }\n});\n\n\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = -1;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3n;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0n, sign = 1n, ch = nextDigit();\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10n + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return BigInt(aStr.charCodeAt(++cur) - 48);\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[++cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet store = {};\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => {\n\t\t\t\tx = x >> 0;\n\t\t\t\tstore[x] = (store[x] || 0) + 1;\n\t\t\t\treturn x;\n\t\t\t});\n\n\t\tif (Object.values(store).length === 1) {\n\t\t\tconsole.log(Object.values(store)[0]);\n\t\t} else {\n\t\t\tconsole.log(1);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM(pos) {\n const inputList = document.querySelectorAll(\".custom-input\");\n const input = inputList[pos];\n// return input.querySelector(\"pre\").textContent;\n return input.textContent;\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM.bind(null, 0)\n}\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n\n const TRIAL_COUNT = 100;\n let a = Array(1e6);\n let b = Array(1e6);\n let nA, nB, curSum, prev, curAi;\n \n function maxForBigInt(...args) {\n return args.reduce((a, b) => a > b ? a : b);\n };\n\n while (tc_count--) {\n nA = readNum();\n for (let index = 0; index < nA; index++) {\n a[index] = readNum(); \n }\n for (let cnt = TRIAL_COUNT; cnt--;) {\n nB = 0;\n prev = curSum = a[0];\n for (let index = 1; index < nA; index++) {\n curAi = a[index];\n if (prev !== curAi || curSum !== curAi) {\n curSum += curAi;\n } else {\n b[nB++] = curSum;\n curSum = curAi;\n }\n prev = curAi;\n }\n b[nB++] = curSum;\n [a, b] = [b, a];\n nA = nB;\n }\n let ans = nA;\n writeLine(ans);\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = -1;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3n;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0n, sign = 1n, ch = nextDigit();\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10n + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return BigInt(aStr.charCodeAt(++cur) - 48);\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[++cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM() {\n const inputList = document.querySelectorAll(\".input\");\n const input = inputList[2];\n return input.querySelector(\"pre\").textContent;\n}\n\nstdioCPPattern({}, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n let n, prev, xx, count;\n \n while (tc_count--) {\n [n, prev] = [readNum(), readNum()];\n count = 1;\n while (--n) {\n xx = readNum();\n if (prev === xx) count++;\n prev = xx;\n }\n writeLine(count);\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = 0;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0, ch = aStr.charCodeAt(cur) - 48;\n while (ch < 0 || 9 < ch) ch = aStr.charCodeAt(++cur) - 48;\n while (0 <= ch && ch <= 9) {\n x = x * 10 + ch;\n ch = aStr.charCodeAt(++cur) - 48;\n }\n return x;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM(pos) {\n const inputList = document.querySelectorAll(\".input\");\n const input = inputList[pos];\n return input.querySelector(\"pre\").textContent;\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM.bind(null, 0)\n}\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n let n, prev, curX, curSum, ans;\n \n function maxForBigInt(...args) {\n return args.reduce((a, b) => a > b ? a : b);\n };\n\n while (tc_count--) {\n n = readNum();\n prev = readNum();\n curSum = 0n;\n ans = 1;\n while (--n) {\n curX = readNum();\n if (prev !== curX || curSum !== curX) {\n curSum += curX;\n } else {\n curSum = curX;\n ans++;\n }\n }\n writeLine(ans);\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = -1;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3n;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0n, sign = 1n, ch = nextDigit();\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10n + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return BigInt(aStr.charCodeAt(++cur) - 48);\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[++cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}], "src_uid": "7b80d3f3cd4f93e4277c76c76dc41f42"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n \n var highest = 0;\n var highestList = [];\n for(var j = 0; j < N; j++){\n var tmpList = Object.assign([],list);\n var sum = tmpList[j];\n for(var i = j + 1; i < N; i++){\n if(tmpList[i - 1] < tmpList[i]){\n tmpList[i] = tmpList[i - 1];\n }\n sum += tmpList[i];\n }\n \n for(var i = j - 1; i >= 0; i--){\n if(tmpList[i + 1] < tmpList[i]){\n tmpList[i] = tmpList[i + 1];\n }\n sum += tmpList[i];\n }\n if(highest <= sum){\n highest = sum;\n highestList = tmpList;\n }\n //myout(myconv(tmpList,8));\n }\n \n //myout(\"last\");\n myout(myconv(highestList,8));\n}", "positive_code": [{"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const n = arr.length;\n const arrIdx = arr.map((x, i) => [x, i]);\n arrIdx.sort((a, b) => b[0] - a[0]);\n let minDesc = Number.MAX_SAFE_INTEGER;\n let minArr = [];\n for(let c = 0; c < n; c++) {\n let desc = 0;\n let curFloor = arr[c];\n const curArr = Array(n);\n curArr[c] = arr[c];\n for (let i = c + 1; i < n; i++) {\n if (arr[i] > curFloor) {\n desc += arr[i] - curFloor;\n if (desc >= minDesc) break;\n } else { // arr[i] <= curFloor\n curFloor = arr[i];\n }\n curArr[i] = curFloor;\n }\n if (desc >= minDesc) continue;\n curFloor = arr[c];\n for (let i = c - 1; i >= 0; i--) {\n if (arr[i] > curFloor) {\n desc += arr[i] - curFloor;\n if (desc >= minDesc) break;\n } else { // arr[i] <= curFloor\n curFloor = arr[i];\n }\n curArr[i] = curFloor;\n }\n if (minDesc > desc) {\n minDesc = desc;\n minArr = curArr;\n }\n }\n return minArr;\n}\n\nfunction main() {\n const n = readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res.join(' '));\n}\n\n"}], "negative_code": [{"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n var max = Math.max.apply(null,list);\n var maxIndex = list.indexOf(max);\n var maxIndexs = [];\n for(var i = 0; i < N; i++){\n if(list[i] == max){\n maxIndexs.push(i);\n }\n }\n \n var highest = 0;\n var highestList = [];\n for(var j = 0; j < maxIndexs.length; j++){\n var tmpList = Object.assign([],list);\n var sum = tmpList[maxIndexs[j]];\n for(var i = maxIndexs[j] + 1; i < N; i++){\n if(tmpList[i - 1] < tmpList[i]){\n tmpList[i] = tmpList[i - 1];\n }\n sum += tmpList[i];\n }\n \n for(var i = maxIndexs[j] - 1; i >= 0; i--){\n if(tmpList[i + 1] < tmpList[i]){\n tmpList[i] = tmpList[i + 1];\n }\n sum += tmpList[i];\n }\n if(highest <= sum){\n highest = sum;\n highestList = tmpList;\n }\n //myout(myconv(tmpList,8));\n }\n \n //myout(\"last\");\n myout(myconv(highestList,8));\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n var max = Math.max.apply(null,list);\n var maxIndex = list.indexOf(max);\n for(var i = maxIndex + 1; i < N; i++){\n if(list[i - 1] < list[i]){\n list[i] = list[i - 1];\n }\n }\n \n for(var i = maxIndex - 1; i >= 0; i--){\n if(list[i + 1] < list[i]){\n list[i] = list[i + 1];\n }\n }\n myout(myconv(list,8));\n}"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const n = arr.length;\n const arrIdx = arr.map((x, i) => [x, i]);\n arrIdx.sort((a, b) => b[0] - a[0]);\n let minDesc = Number.MAX_SAFE_INTEGER;\n let minArr = [];\n for(let c = 0; c < n; c++) {\n let desc = 0;\n let curFloor = arr[c];\n const curArr = Array(n);\n curArr[c] = arr[c];\n for (let i = c + 1; i < n; i++) {\n if (arr[i] > curFloor) {\n desc += arr[i] - curFloor;\n if (desc >= minDesc) break;\n } else { // arr[i] <= curFloor\n curFloor = arr[i];\n }\n curArr[i] = curFloor;\n }\n if (desc >= minDesc) continue;\n curFloor = arr[c];\n for (let i = c - 1; i >= 0; i--) {\n if (arr[i] > curFloor) {\n desc += arr[i] - curFloor;\n if (desc >= minDesc) break;\n } else { // arr[i] <= curFloor\n curFloor = arr[i];\n }\n curArr[i] = curFloor;\n }\n if (minDesc > desc) {\n minDesc = desc;\n minArr = curArr;\n }\n }\n return minArr;\n}\n\nfunction main() {\n const n = readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res);\n}\n\n"}], "src_uid": "88e6cd9ef45b956be8bee5d4fedd5725"} {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function (a) {return parseInt(a)});\nvar hash = {};\nvar num = 0;\nvar max = 0;\n\nfor (var i = 0; i < n; i++) {\n\tif (hash[input[i]]) {\n\t\thash[input[i]]++;\n\t} else {\n\t\thash[input[i]] = 1;\n\t}\n}\n\nfor (var key in hash) {\n\tif (hash.hasOwnProperty(key)) {\n\t\tnum++;\n\t\tif (hash[key] > max) {\n\t\t\tmax = hash[key];\n\t\t}\n\t}\n}\n\nprint (max + \" \" + num);", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar counter = 0, N, ans = 1;\nrl.on('line', (input) => {\n if (counter == 0) {\n N = parseInt(input);\n counter++\n }\n else {\n let cont = input.split(\" \").map(item => parseInt(item));\n cont.sort();\n let maxRep=1;\n for (let i = 0; i < cont.length - 1; i++) {\n if (cont[i] == cont[i + 1])\n ans++;\n else{\n if(maxRep < ans)\n maxRep = ans;\n\n ans = 1;\n }\n \n }\n if(maxRep < ans)\n maxRep = ans;\n cont2 = new Set(cont);\n\n\n console.log(\"%d %d\",maxRep, cont2.size);\n \n rl.close();\n }\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n/*\nvar counter = 0, N, ans = 1;\nrl.on('line', (input) => {\n if (counter == 0) {\n N = parseInt(input);\n counter++\n }\n else {\n let cont = input.split(\" \").map(item => parseInt(item));\n cont.sort();\n let maxRep=1;\n for (let i = 0; i < cont.length - 1; i++) {\n if (cont[i] == cont[i + 1])\n ans++;\n else{\n if(maxRep < ans)\n maxRep = ans;\n\n ans = 1;\n }\n \n }\n if(maxRep < ans)\n maxRep = ans;\n cont2 = new Set(cont);\n\n\n console.log(\"%d %d\",maxRep, cont2.size);\n \n rl.close();\n }\n\n\n});\n*/\n/*\n15\n5 3 8 3 5 8 3 5 8 3 3 8 5 8 8\n\n\n3 5 8\n--- ----- --------\n--- ----- --------\n--- ----- --------\n--- ----- --------\n--- --------\n --------\n\n\n{(3 -> 5) (5 -> 4) (8 -> 6)}\n*/\nvar counter = 0;\nrl.on('line', (input)=>{\n if(counter == 0)\n counter++;\n else{\n let myDict = {}, maxValue=0;\n input.split(' ').map(item => parseInt(item)).forEach(elem=> {\n if(elem in myDict)\n myDict[elem] ++;\n else myDict[elem] = 1;\n\n if(maxValue < myDict[elem])\n maxValue = myDict[elem];\n });\n\n console.log(\"%d %d\",maxValue, Object.keys(myDict).length);\n rl.close();\n }\n});"}, {"source_code": "\nvar a = new Array(1001);\n\nfor (var i = 0; i < 1001; i++)\n{\n a[i] = 0;\n}\n\nvar line = readline().split(' ')\n\nvar size = parseInt(line[0])\n\nline = readline().split(' ')\n\nfor (var i = 0; i < size; i++)\n{\n a[parseInt(line[i])] += 1;\n}\n\nvar maxHeight = 0;\nvar count = 0;\n\nfor (var i = 0; i < 1001; i++)\n{\n if (a[i] > maxHeight)\n {\n maxHeight = a[i];\n }\n \n if (a[i] != 0)\n {\n count++;\n }\n}\n\nprint(maxHeight + ' ' + count)"}, {"source_code": "var n = +readline();\nvar m = {};\nvar s = readline().split(' ').map(function (e) {\n\tif (!m[e]) m[e] = 1;\n\telse m[e] += 1;\n});\n\nprint(Math.max.apply(null, Object.keys(m).map(function (e) { return m[e]; })) + \" \" + Object.keys(m).length);"}, {"source_code": "readline(), readline()\n\t.split(' ')\n\t.map(function (e, i, a){\n\t\treturn [e, a.filter(function(_e){\n\t\t\treturn _e == e;\n\t\t}).length];\n\t}).filter(function(e, i, a){\n\t\treturn i == a.map(function(_e){\n\t\t\treturn _e[0];\n\t\t}).lastIndexOf(e[0]);\n\t}).map(function(e){\n\t\treturn e[1];\n\t}).forEach(function(e, i, a){\n\t\tif (i == (a.length-1))\n\t\t\tprint(Math.max.apply(null, a) + \" \" + a.length);\n\t})"}, {"source_code": "'use strict'\n\nlet N = +readline()\nlet l = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)\n\nlet n = 1\nlet m = 1\nlet c = 1\nfor (let i = 1; i < N; i++) {\n if (l[i] == l[i - 1]) {\n c++\n m = Math.max(m, c)\n } else {\n c = 1\n n++\n }\n}\n\nprint(m + ' ' + n)"}, {"source_code": "var n=readline();\nn=Number(n);\nvar a=readline();\na=a.split(\" \");\nfor (var i=0 ;i {\n if(identifier==0){\n n= parseInt(input);\n identifier++;\n }\n else{\n /*\n let maxValue=0;\n let dict={};\n let temp = input.split(' ').map(item=> parseInt(item));\n for(let i=0;i parseInt(item)).forEach(elem => {\n if(elem in dict)\n dict[elem] ++;\n else dict[elem] = 1;\n if(maxValue < dict[elem])\n maxValue=dict[elem];\n });\n console.log(\"%d %d\",maxValue, Object.keys(dict).length);\n rl.close();\n }\n });"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\tif(output[+input[i]] == undefined){\n\t\t\toutput[+input[i]] = 1;\n\t\t}\n\t\telse{\n\t\t\toutput[+input[i]]++;\n\t\t}\n\t}\n}\n\nvar n = +readline(), l = readline().split(\" \").map(Number), blocks = {}, arr = [];\n\ncountUniqueElements(l,blocks);\n\nfor(key in blocks){\n\tarr.push(blocks[key]);\n}\n\nwrite(Math.max.apply(null, arr));\nwrite(\" \" + Object.keys(blocks).length);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const bars = Number(readline())\n const lengths = readline().split(' ').map(Number)\n \n helper(bars, lengths)\n}\n\nfunction helper(bars, ls) {\n let cnt = new Map() \n \n for (let i = 0; i < bars; i++) {\n cnt.set(ls[i], (cnt.get(ls[i]) || 0) + 1)\n }\n \n let maxHeight = 0\n for (let [key, value] of cnt) {\n maxHeight = Math.max(maxHeight, value)\n }\n \n console.log(maxHeight + ' ' + cnt.size)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n const arr = readLine().split(' ').map(Number);\n\n const result = businessTrip(n, arr);\n printResult(result);\n}\n\nconst businessTrip = (n, a) => {\n const counts = new Array(1001).fill(0);\n for (let i = 0; i < n; i++) {\n counts[a[i]]++;\n }\n\n const height = counts.reduce((a, b) => Math.max(a, b));\n let total = 0;\n for (let i = 0; i < counts.length; i++) {\n if (total === n) break;\n if (counts[i]) total++;\n }\n\n return `${height} ${total}`;\n};"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const bars = Number(readline())\n const lengths = readline().split(' ').map(Number)\n \n helper(bars, lengths)\n}\n\nfunction helper(bars, ls) {\n let cnt = new Map() \n \n for (let i = 0; i < bars; i++) {\n cnt.set(ls[i], (cnt.get(ls[i]) || 0) + 1)\n }\n \n let max = 0\n let maxHeight = 0\n for (let [key, value] of cnt) {\n max = Math.max(max, key * value)\n maxHeight = Math.max(maxHeight, value)\n }\n \n console.log(maxHeight + ' ' + max)\n}"}, {"source_code": "\nvar n=+readline();\nvar l=readline().split(' ').map(function(v){return+v;});\nvar m={};\nvar ans=0;\nl.forEach(function(v){\n\tif(m[v]){\n\t\tm[v]++;\n\t}else{\n\t\tm[v]=1;\n\t\tans++;\n\t}\n});\nvar h=0;\nfor(var key in m){\n\th=Math.max(m[key]);\n}\nprint(h+' '+ans);"}, {"source_code": "\nvar a = new Array(1000);\n\nfor (var i = 0; i < 1000; i++)\n{\n a[i] = 0;\n}\n\nvar line = readline().split(' ')\n\nvar size = parseInt(line[0])\n\nline = readline().split(' ')\n\nfor (var i = 0; i < size; i++)\n{\n a[parseInt(line[i])] += 1;\n}\n\nvar maxHeight = 0;\nvar count = 0;\n\nfor (var i = 0; i < 1000; i++)\n{\n if (a[i] > maxHeight)\n {\n maxHeight = a[i];\n }\n \n if (a[i] != 0)\n {\n count++;\n }\n}\n\nprint(maxHeight + ' ' + count)"}, {"source_code": "var line = readline().split(' ')\n\nvar a = new Array(1000);\n\nfor (var i = 0; i < 1000; i++)\n{\n a[i] = 0;\n}\n\nfor (var i in line)\n{\n a[parseInt(i)] += 1;\n}\n\nvar maxHeight = 0;\nvar count = 0;\n\nfor (var i = 0; i < 1000; i++)\n{\n if (a[i] > maxHeight)\n {\n maxHeight = a[i];\n }\n \n if (a[i] != 0)\n {\n count++;\n }\n}\n\nprint(maxHeight + ' ' + count)"}, {"source_code": "var line = readline().split(' ')\n\nvar a = new Array(1000);\n\nfor (var i = 0; i < 1000; i++)\n{\n a[i] = 0;\n}\n\nvar size = parseInt(line[0])\n\nfor (var i = 0; i < size; i++)\n{\n a[parseInt(line[i])] += 1;\n}\n\nvar maxHeight = 0;\nvar count = 0;\n\nfor (var i = 0; i < 1000; i++)\n{\n if (a[i] > maxHeight)\n {\n maxHeight = a[i];\n }\n \n if (a[i] != 0)\n {\n count++;\n }\n}\n\nprint(maxHeight + ' ' + count)"}, {"source_code": "readline();\n\nprint(\n\treadline()\n\t\t.split(' ')\n\t\t.map(function (e, i, a){\n\t\t\treturn [e, a.filter(function(_e){\n\t\t\t\treturn _e == e;\n\t\t\t}).length];\n\t\t}).filter(function(e, i, a){\n\t\t\treturn i == a.map(function(_e){\n\t\t\t\treturn _e[0];\n\t\t\t}).lastIndexOf(e[0]);\n\t\t}).map(function(e){\n\t\t\treturn e[1];\n\t\t}).reduce(function(p, e, i, a){\n\t\t\treturn Math.max.apply(null, a) + \" \" +a.length;\n\t\t})\n);"}, {"source_code": "'use strict'\n\nlet N = +readline()\nlet l = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)\n\nlet n = 1\nlet m = -Infinity\nlet c = 1\nfor (let i = 1; i < N; i++) {\n if (l[i] == l[i - 1]) {\n c++\n } else {\n m = Math.max(m, c)\n c = 1\n n++\n }\n}\n\nprint(m + ' ' + n)"}, {"source_code": "var n=readline();\nn=Number(n);\nvar a=readline();\na=a.split(\" \");\nfor (var i=0 ;i {\r\n return string.trim();\r\n });\r\n\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n let n = inputReader.readNumber();\r\n let minL = Infinity,\r\n maxR = -Infinity,\r\n costL = Infinity,\r\n costR = Infinity,\r\n ans = Infinity;\r\n while (n--) {\r\n let [l, r, c] = inputReader.readNumberArray();\r\n if (l < minL) {\r\n minL = l;\r\n costL = c;\r\n ans = Infinity;\r\n }\r\n if (r > maxR) {\r\n maxR = r;\r\n costR = c;\r\n ans = Infinity;\r\n }\r\n if (l == minL && r == maxR) ans = Math.min(c, ans);\r\n if (l == minL && costL > c) costL = c;\r\n if (r == maxR && costR > c) costR = c;\r\n console.log(Math.min(ans, costL + costR));\r\n }\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e9 + 1e9 + 100;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet lb = INF, rb = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l <= la && r >= ra) {\r\n\t\t\t\tif (l < la || r > ra) {\r\n\t\t\t\t\tla = l;\r\n\t\t\t\t\tra = r;\r\n\t\t\t\t\tlrc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (l <= lb) {\r\n\t\t\t\tif (l < lb) {\r\n\t\t\t\t\tlb = l;\r\n\t\t\t\t\tlc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlc = Math.min(lc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (r >= rb) {\r\n\t\t\t\tif (r > rb) {\r\n\t\t\t\t\trb = r;\r\n\t\t\t\t\trc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\trc = Math.min(rc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet lb = INF, rb = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l <= la && r >= ra) {\r\n\t\t\t\tif (l < la || r > ra) {\r\n\t\t\t\t\tla = l;\r\n\t\t\t\t\tra = r;\r\n\t\t\t\t\tlrc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (l <= lb) {\r\n\t\t\t\tif (l < lb) {\r\n\t\t\t\t\tlb = l;\r\n\t\t\t\t\tlc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlc = Math.min(lc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (r >= rb) {\r\n\t\t\t\tif (r > rb) {\r\n\t\t\t\t\trb = r;\r\n\t\t\t\t\trc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\trc = Math.min(rc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet l = INF, r = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [li, ri, ci] = rna();\r\n\r\n\t\t\tif (li <= la && ri >= ra) {\r\n\t\t\t\tif (li < la || ri > ra) {\r\n\t\t\t\t\tla = li;\r\n\t\t\t\t\tra = ri;\r\n\t\t\t\t\tlrc = ci;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, ci);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (li == l) {\r\n\t\t\t\tlc = Math.min(lc, ci);\r\n\t\t\t} else if (li < l) {\r\n\t\t\t\tl = li;\r\n\t\t\t\tlc = ci;\r\n\t\t\t}\r\n\r\n\t\t\tif (ri == r) {\r\n\t\t\t\trc = Math.min(rc, ci);\r\n\t\t\t} else if (ri > r) {\r\n\t\t\t\tr = ri;\r\n\t\t\t\trc = ci;\r\n\t\t\t}\r\n\t\t\t//console.log({la, ra, l, r, lrc, lc, rc})\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == l && ra == r ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n LT({n});\n let A = [];\n let cost = 0;\n let ans = [];\n let minLPrice = -1;\n let minL = -1;\n let minRPrice = -1;\n let maxR = -1;\n let fullPrice = -1;\n for (let i=0; imaxR || r==maxR && c {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = await readInt();\r\n let [l,r,c] = await readIntArray();\r\n let lleft, lright, cl, rleft, rright, cr;\r\n let onel, oner, onec;\r\n onel = lleft = rleft = l;\r\n oner = lright = rright = r;\r\n onec = cl = cr = c;\r\n console.log(c);\r\n for(let i = 1; i < n; i++) {\r\n [l,r,c] = await readIntArray();\r\n if (l < lleft || (lleft === l && c < cl)) {\r\n lleft = l;\r\n lright = r;\r\n cl = c;\r\n }\r\n\r\n if (r > rright || (r === rright && c < cr)) {\r\n rleft = l;\r\n rright = r;\r\n cr = c;\r\n }\r\n\r\n if (l === lleft && r === rright) {\r\n if (l < onel || r > oner || (l === onel && r===oner && c < onec)) {\r\n onel = l;\r\n oner = r;\r\n onec = c;\r\n }\r\n }\r\n\r\n if (lleft === onel && rright === oner && cr + cl > onec) {\r\n console.log(onec);\r\n } else {\r\n console.log(cr + cl);\r\n }\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let min = Infinity\n let mincost\n let max = -Infinity\n let maxcost\n const map = {}\n return arr.map(([l, r, c], i) => {\n if (l < min) {\n min = l\n mincost = i\n } else if (l === min && c < arr[mincost][2]) {\n mincost = i\n }\n if (r > max) {\n max = r\n maxcost = i\n } else if (r === max && c < arr[maxcost][2]) {\n maxcost = i\n }\n //\n let k = key(l, r)\n map[k] = (k in map) ? Math.min(map[k], c) : c\n //\n let prev\n if (mincost === maxcost) {\n prev = arr[mincost][2]\n } else {\n prev = arr[mincost][2] + arr[maxcost][2]\n }\n //\n k = key(min, max)\n if (k in map) {\n return Math.min(map[k], prev)\n } else {\n return prev\n }\n }).join('\\n')\n}\nfunction key(...args) {\n return args.join(',')\n}\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e9 + 100;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet lb = INF, rb = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l <= la && r >= ra) {\r\n\t\t\t\tif (l < la || r > ra) {\r\n\t\t\t\t\tla = l;\r\n\t\t\t\t\tra = r;\r\n\t\t\t\t\tlrc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (l <= lb) {\r\n\t\t\t\tif (l < lb) {\r\n\t\t\t\t\tlb = l;\r\n\t\t\t\t\tlc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlc = Math.min(lc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (r >= rb) {\r\n\t\t\t\tif (r > rb) {\r\n\t\t\t\t\trb = r;\r\n\t\t\t\t\trc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\trc = Math.min(rc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet lb = INF, rb = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l <= la && r >= ra) {\r\n\t\t\t\tif (l < la || r > ra) {\r\n\t\t\t\t\tla = l;\r\n\t\t\t\t\tra = r;\r\n\t\t\t\t\tlrc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (l <= lb) {\r\n\t\t\t\tif (l < lb) {\r\n\t\t\t\t\tlb = l;\r\n\t\t\t\t\tlc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlc = Math.min(lc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (r >= r) {\r\n\t\t\t\tif (r > rb) {\r\n\t\t\t\t\trb = r;\r\n\t\t\t\t\trc = c;\r\n\t\t\t\t} else {\r\n\t\t\t\t\trc = Math.min(rc, c);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet la = INF, ra = -INF, lrc = INF;\r\n\t\tlet l = INF, r = -INF, lc = INF, rc = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [li, ri, ci] = rna();\r\n\r\n\t\t\tif (li <= la && ri >= ra) {\r\n\t\t\t\tif (li < la || ri > ra) {\r\n\t\t\t\t\tla = li;\r\n\t\t\t\t\tra = ri;\r\n\t\t\t\t\tlrc = ci;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tlrc = Math.min(lrc, ci);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (li == l) {\r\n\t\t\t\tlc = Math.min(lc, ci);\r\n\t\t\t} else if (li < l) {\r\n\t\t\t\tl = li;\r\n\t\t\t\tlc = ci;\r\n\t\t\t}\r\n\r\n\t\t\tif (ri == r) {\r\n\t\t\t\trc = Math.min(rc, ci);\r\n\t\t\t} else if (ri > r) {\r\n\t\t\t\tr = ri;\r\n\t\t\t\trc = ci;\r\n\t\t\t}\r\n\t\t\t//console.log({la, ra, l, r, lrc, lc, rc})\r\n\r\n\t\t\tconsole.log(Math.min(lc + rc, la == l && ra == r ? lrc : INF));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\toneseg = onel == mn && oner == mx;\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mnc + mxc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (onel > mn || oner < mx)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e18;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (oner != mx || onel != mn)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 2e9+10;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (oner != mx || onel != mn)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (oner != mx || onel != mn)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (oner != mx || onel != mn)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mn = INF, mnc, mx = 0, mxc;\r\n\t\tlet oneseg, onel, oner, onec;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, c] = rna();\r\n\t\t\tif (l < mn || l == mn && c < mnc) {\r\n\t\t\t\tmn = l;\r\n\t\t\t\tmnc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (r > mx || r == mx && c < mxc) {\r\n\t\t\t\tmx = r;\r\n\t\t\t\tmxc = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (l == mn && r == mx && c < mxc+mnc) {\r\n\t\t\t\toneseg = true;\r\n\t\t\t\tonel = l;\r\n\t\t\t\toner = r;\r\n\t\t\t\tonec = c;\r\n\t\t\t}\r\n\r\n\t\t\tif (oner != mx || onel != mn)\r\n\t\t\t\toneseg = false;\r\n\r\n\t\t\tconsole.log(oneseg ? onec : mnc + mxc);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "ee773d908fc297cc692aaecf6af299c9"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const str = readLine();\n let [count0, count1] = [0, 0];\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"0\") count0++;\n else count1++;\n }\n\n if (count0 > count1) console.log(\"0\".repeat(len));\n else console.log(\"1\".repeat(len));\n }\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst readLine = require('readline')\n\nconst readLineInterface = readLine.createInterface({\n input: process.stdin,\n})\n\nconst rows = []\nlet numberOfRows = 0\n\nreadLineInterface.on('line', (row) => {\n if (!numberOfRows) {\n numberOfRows = Number(row)\n } else {\n rows.push(row)\n }\n\n if (rows.length === numberOfRows * 2) {\n readLineInterface.close()\n }\n})\nreadLineInterface.on('close', main)\n\n\nfunction main() {\n for (let i = 0; i < numberOfRows * 2; i += 2) {\n const n = Number(rows[i])\n const fullS = rows[i + 1]\n const s = []\n const startPosition = n - 1\n for (let j = startPosition; j < fullS.length; j++) {\n s.push(fullS.slice(j - startPosition, j + 1))\n }\n let resultS = ''\n for (let i = 0; i < n; i++) {\n let additionValue = 0\n for (let j of s) {\n additionValue += Number(j[i])\n }\n if (additionValue === n) {\n resultS += '1'\n } else {\n resultS += '0'\n }\n }\n console.log(resultS)\n }\n}"}, {"source_code": "var numCases = parseInt(readline());\nfor (var i = 0; i < numCases; i ++) {\n var n = parseInt(readline());\n var str = readline();\n var output = '';\n for (var j = 0; j < n; j ++) {\n output += str[j * 2];\n }\n print(output);\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var s = next();\n var str = [];\n var count = new Array(N);\n for(var j = 0; j < N; j++){\n count[j] = new Set();\n }\n for(var j = 0; j < s.length; j++){\n str.push(s[j]);\n if(j >= N){\n str.shift();\n }\n if(j >= N - 1){\n for(var k = 0; k < N; k++){\n count[k].add(str[k]);\n }\n }\n }\n str = \"\";\n myerr(count);\n for(var j = 0; j < N; j++){\n var tmp = Array.from(count[j]).sort();\n str += tmp[0];\n }\n output[i] = str;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nwhile(t--){\n var n = parseInt(readline());\n var s = readline();\n \n var sym = s[n - 1];\n var res = \"\";\n for(var i = 0; i < n; i++){\n res += sym;\n }\n print(res);\n}"}, {"source_code": "var t = parseInt(readline());\n \nwhile(t--){\n var n = parseInt(readline());\n var s = readline();\n \n var sym = s[n - 1];\n var res = \"\";\n for(var i = 0; i < n; i++){\n res += sym;\n }\n print(res);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', async _ => {\n inputString = inputString.split(/\\n/);\n try {\n await main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nasync function main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const s = readLine().trim()\n console.log(Array.from(s).filter((_, i) => i % 2 === 0).join(''))\n }\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = +$(), s = $()\n out.push(s[n-1].repeat(n))\n }\n log(out.join('\\n'))\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextString() {\n return lines.shift();\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let n = nextNumber();\n let s = nextString();\n let ret = '';\n for (let i = 0; i < n; i++) {\n ret += s[i * 2];\n }\n console.log(ret);\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc++]\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}"}], "negative_code": [{"source_code": "var numCases = parseInt(readline());\nfor (var i = 0; i < numCases; i ++) {\n var n = parseInt(readline());\n var str = readline();\n var output;\n for (var j = 0; j < n; j ++) {\n output += str[j * 2];\n }\n print(output);\n}"}, {"source_code": "'use strict'\n\nconst readLine = require('readline')\n\nconst readLineInterface = readLine.createInterface({\n input: process.stdin,\n})\n\nconst rows = []\nlet numberOfRows = 0\n\nreadLineInterface.on('line', (row) => {\n if (!numberOfRows) {\n numberOfRows = Number(row)\n } else {\n rows.push(row)\n }\n\n if (rows.length === numberOfRows * 2) {\n readLineInterface.close()\n }\n})\nreadLineInterface.on('close', main)\n\n\nfunction main() {\n for (let i = 0; i < numberOfRows * 2; i += 2) {\n const n = Number(rows[i])\n const fullS = rows[i + 1]\n const s = []\n const startPosition = n - 1\n for (let j = startPosition; j < fullS.length; j++) {\n s.push(fullS.slice(j - startPosition, j + 1))\n }\n let resultS = ''\n for (let i = 0; i < n; i++) {\n let additionValue = 0\n for (let j of s) {\n additionValue += Number(j[i])\n }\n if (additionValue > Math.floor(n / 2)) {\n resultS += '1'\n } else {\n resultS += '0'\n }\n }\n console.log(resultS)\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var s = next();\n var str = [];\n var count = new Array(N);\n for(var j = 0; j < N; j++){\n count[j] = new Set();\n }\n for(var j = 0; j < s.length; j++){\n str.push(s[j]);\n if(j >= N){\n str.shift();\n }\n if(j >= N - 1){\n for(var k = 0; k < N; k++){\n count[k].add(str[k]);\n }\n }\n }\n str = \"\";\n for(var j = 0; j < N; j++){\n var tmp = Array.from(count[j]);\n str += tmp[0];\n }\n output[i] = str;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probA(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline();\n console.log(s.substring(0,n));\n }\n}"}], "src_uid": "b37bbf1fe9ac5144cfa230633ccbdd79"} {"source_code": "const processData = (lines) => {\n const [conditions] = lines\n const [h, l] = conditions.split(' ').map(x => +x)\n const hyp = Math.sqrt(h*h + l*l)\n const atan = Math.atan(l/h)\n const A = hyp / Math.sin(Math.PI - 2 * atan) * Math.sin(atan)\n console.log(A - h)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (data) => {\n var arr = data.split(' ')\n var H = parseInt(arr[0])\n var L = parseInt(arr[1])\n\n var res = (L*L) - (H*H)\n res = res/(2*H)\n\n console.log(res.toFixed(13))\n});\n\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet l, h, result;\nrl.on('line', input => {\n [h, l] = input.split(' ').map(x => +x);\n result = (l*l - h*h) / h \n console.log(result / 2)\n rl.close()\n})"}, {"source_code": "// Codeforces 1199/B\n\nconst readline = require('readline');\n\nrl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.question('', (input) => {\n const [h, l] = input.split(' ');\n console.log(((l*l) - (h*h)) / (2 * h));\n rl.close();\n});\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n for (const line of lines) {\n const [H, L] = line.split(' ')\n if (H && L) {\n const A = (L ** 2) / (2 * H) - H / 2\n console.log(A)\n }\n }\n})"}, {"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const [ h, l ] = lines[0].split(/\\s/).map(Number)\n const a = (Math.pow(l, 2) - Math.pow(h, 2)) / (2 * h)\n \n console.log(a.toFixed(13))\n}\n"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (line) => {\n var num = line.split(\" \").map(x => parseInt(x));\n var h, l;\n h = num[0];\n l = num[1];\n\n var result = (l*l-h*h)/(2*h);\n console.log(result);\n});\n"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nprint((l*l-h*h)/(2*h));"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\n\nvar h=num[0];\nvar l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\n\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nvar r= (l*l-h*h)/(2*h);\nprint(r);\n"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar arr = readline().split(' ').map(item => +item);\n\nprint((arr[1] * arr[1] - arr[0] * arr[0]) / (2 * arr[0]));\n"}, {"source_code": "var input = readline()\n .split(\" \")\n .map(function(x) {\n return parseInt(x);\n });\nvar result =\n (Math.pow(input[0], 2) + Math.pow(input[1], 2)) / (2 * input[0]) - input[0];\nprint(result);\n"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\n\n// function main() {\n// let line;\n// while(line = readline()) {\n// let [h, l] = line.split(' ').map(num => parseInt(num));\n// findHeight(h, l)\n// }\n// }\n\n// function findHeight(h, l) {\n// let output = (l*l - h*h)/(2*h);\n// print(output)\n// }\nvar line = readline().split(' ').map(num => parseInt(num));\nvar h = line[0];\nvar l = line[1];\nvar output = (l*l - h*h)/(2*h);\nprint(output)\n\n"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\n\nvar h,l;\nh = num[0], l= num[1];\n\nvar r = (l*l-h*h)/(2*h);\n\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\nvar r= (l*l-h*h)/(2*h);\nprint(r);\n"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var inp = readline().split(' ');\nvar h = parseInt(inp[0], 10), l = parseInt(inp[1], 10);\n\nvar a = (Math.pow(l,2) - Math.pow(h,2)) / (2*h);\n\nprint(a);"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var H = input[0];\n var L = input[1];\n \n var fullHyp = Math.sqrt(L*L + H*H);\n var halfHyp = fullHyp/2;\n var cosA = H/fullHyp;\n \n var stem = halfHyp/cosA;\n var x = stem - H;\n wr(x.toFixed(20))\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n \nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x));\nvar h,l;\nh=num[0],l=num[1];\n\nvar r= (l*l-h*h)/(2*h);\nprint(r);"}, {"source_code": "var r,h,l,num=readline().split(\" \").map(x => parseInt(x)),h=num[0],l=num[1],r= (l*l-h*h)/(2*h);print(r);"}], "negative_code": [{"source_code": "var input = readline()\n .split(\" \")\n .map(function(x) {\n return parseInt(x);\n });\nvar result = (Math.pow(input[0], 2) + Math.pow(input[1], 2)) / 2 - input[0];\nprint(result);\n"}, {"source_code": "var input = readline()\n .split(\" \")\n .map(function(x) {\n return parseInt(x);\n });\nvar result = (input[0] + input[1]) / 2 - input[0];\nprint(result);\n"}], "src_uid": "2cd5807e3f9685d4eff88f2283904f0d"} {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar a = readline().split(' '),\n\t\t\tisEqual = true,\n\t\t\tmax = 0, j = 0;\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\ta[i] = +a[i];\n\n\t\t\tif (isEqual && a[i] !== a[0]) isEqual = false;\n\n\t\t\tif (max < a[i]) {\n\t\t\t\tj = i;\n\t\t\t\tmax = a[i];\n\t\t\t}\n\t\t}\n\n\t\tif (isEqual) {\n\n\t\t\tif (a[0] !== 1) a[0] = 1;\n\t\t\telse a[a.length - 1] = 2;\n\n\t\t} else a[j] = 1;\n\n\t\treturn a.sort(function (a, b) { return a - b; }).join(' ');\n\n\t}(+readline()));\n\n}.call(this));", "positive_code": [{"source_code": "//Input\n// var firstLine = \"5\" ; var secondLine = \"1 2 3 4 5\" //R: 1 1 2 3 4\n// var firstLine = \"5\" ; var secondLine = \"2 3 4 5 6 \" //R: 1 2 3 4 5\n// var firstLine = \"3\" ; var secondLine = \"2 2 2\" //R: 1 2 2\n// var firstLine = \"4\" ; var secondLine = \"1 1 2 3\" //R: 1 1 1 2\n\n// var firstLine = \"3\" ; var secondLine = \"1 1 1\" //R: 1 1 2\n\n// var firstLine = \"10\" ; var secondLine = \"5 6 1 2 3 1 3 45 7 1000000000\" //R: 1 1 1 2 3 3 5 6 7 45\n// var firstLine = \"1\" ; var secondLine = \"1 \" //R: 1\n\n\nvar firstLine = readline(); var secondLine = readline();\n\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var n = parseInt(firstLine);\n var arr = secondLine.split(\" \").map(function (x){ return parseInt(x)});\n\n write(replace(arr));\n // console.log(replace(arr));\n return \"Hola\";\n};\n\nfunction replace(arr){\n var len = arr.length;\n var newArr = \"\"; new Array(len+1).join(\"0\").split(\"\").map(parseInt); if(len > 1){newArr[1] = 0};\n\n arr.sort(function (a, b){return a-b});\n if(arr[len-1] != 1){\n arr[len-1] = 1;\n } else{\n arr[len-1] = 2\n };\n arr.sort(function(a, b){ return a-b});\n\n for(var i = 0 ; i < len ; i++){\n newArr += \"\" + arr[i];\n if(i < len -1){\n newArr += \" \";\n };\n };\n\n return newArr;\n};\n\n\n\n\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n let [_, ...arr] = i.split`\\n`;\n arr = arr[0].split` `.map(Number);\n arr.sort((a, b) => a - b);\n arr.pop() === 1 ? arr.push(2) : arr.unshift(1);\n console.log(arr.join` `);\n});"}, {"source_code": "var getNums = function () {\n return readline().split(' ').map(function (a) { return parseInt(a) });\n};\n\n\n//135A, 2 attempts\nvar n = readline();\nvar arr = getNums();\nvar max = {val: 1, pos: -1};\nfor (var i = 0; i < n; i++) {\n if (arr[i] > max.val) {\n max = {val: arr[i], pos: i};\n }\n}\nif (max.pos === -1) {\n arr[0] = 2;\n} else {\n arr[max.pos] = 1;\n}\nprint(arr.sort(function(a, b){return a - b}).join(' '));"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n let [_, ...arr] = i.split`\\n`;\n arr = arr[0].split` `.map(Number);\n arr.sort((a, b) => a - b);\n arr.pop() === 1 ? arr.push(2) : arr.unshift(1);\n console.log(arr);\n});"}, {"source_code": "//Input\n// var firstLine = \"5\" ; var secondLine = \"1 2 3 4 5\" //R: 1 1 2 3 4\n// var firstLine = \"5\" ; var secondLine = \"2 3 4 5 6 \" //R: 1 2 3 4 5\n// var firstLine = \"3\" ; var secondLine = \"2 2 2\" //R: 1 2 2\n// var firstLine = \"4\" ; var secondLine = \"1 1 2 3\" //R: 1 1 1 2\n\n// var firstLine = \"3\" ; var secondLine = \"1 1 1\" //R: 1 1 2\n\n// var firstLine = \"10\" ; var secondLine = \"5 6 1 2 3 1 3 45 7 1000000000\" //R: 1 1 1 2 3 3 5 6 7 45\n// var firstLine = \"1\" ; var secondLine = \"1 \" //R: 1\n\n\nvar firstLine = readline(); var secondLine = readline();\n\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var n = parseInt(firstLine);\n var arr = secondLine.split(\" \").map(function (x){ return parseInt(x)});\n\n // console.log(replace(arr));\n write(replace(arr));\n return \"Hola\";\n};\n\nfunction replace(arr){\n var len = arr.length;\n var newArr = new Array(len+1).join(\"0\").split(\"\").map(parseInt); if(len > 1){newArr[1] = 0};\n\n //console.log(\"arr: \" + arr);\n arr.sort(function (a, b){return a-b});\n //console.log(\"arr: \" + arr);\n if(arr[len-1] != 1){\n arr[len-1] = 1;\n } else{\n arr[len-1] = 2\n };\n arr.sort(function(a, b){ return a-b});\n\n\n\n return arr;\n};\n\n\n\n\n\n"}, {"source_code": "(function(){print(function(e){var t=readline().split(\" \").map(Number);if(t[0]===t.slice(-1)[0]){if(t[0]===1){t[t.length-1]=2}else{t[0]=1}}else{var n=0,r=0;for(var i=0;i n; i++) {\n if (arr[i] > max.val) {\n max = {val: arr[i], pos: i};\n }\n}\narr[max.pos] = 1;\nprint(arr.sort(function(a, b){return a - b}).join(' '));"}, {"source_code": "var getNums = function () {\n return readline().split(' ').map(function (a) { return parseInt(a) });\n};\n\n\n//134B\nvar n = readline();\nvar arr = getNums();\nvar max = {val: arr[0], pos: 0};\nfor (var i = 1; i < n; i++) {\n if (arr[i] > max.val) {\n max = {val: arr[i], pos: i};\n }\n}\narr[max.pos] = 1;\nprint(arr.sort(function(a, b){return a - b}).join(' '));"}], "src_uid": "1cd10f01347d869be38c08ad64266870"} {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n for (let i = 0; i < testCases; i++) {\r\n const length = readline();\r\n const arr = readline().split(\" \");\r\n arr.sort((a, b) => a - b);\r\n const result =\r\n parseInt(arr[length - 1] - arr[0]) + parseInt(arr[length - 2] - arr[1]);\r\n console.log(result);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "/* why are we still here, just to suffer? */\r\nlet buf='';\r\n\r\nprocess.stdin.on('readable', ()=>{\r\n let chunk=process.stdin.read();\r\n if(chunk) buf += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', ()=>{\r\n let lines=buf.split('\\n');\r\n let lc=0;\r\n let t=parseInt(lines[lc++]);\r\n while(t--) {\r\n let n=parseInt(lines[lc++]);\r\n let _=lines[lc++].split(' ');\r\n let a=[];\r\n for(let i=0;i=max1) {\r\n max2=max1; max1=a[i];\r\n } else if(a[i]>max2) max2=a[i];\r\n \r\n if(a[i]<=min1) {\r\n min2=min1; min1=a[i]; \r\n } else if(a[i] stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var a = k[k.length - 1] + k[k.length - 2];\n var b = k[0] + k[1];\n a -= b;\n console.log(a);\n }\n }\n}); "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n const arr = readline().split(' ').map(Number);\r\n\r\n\r\n let min1 = Infinity;\r\n let min2 = Infinity;\r\n let max1 = -1;\r\n let max2 = -1;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] < min1) {\r\n min2 = min1;\r\n min1 = arr[i];\r\n } else if (arr[i] < min2) {\r\n min2 = arr[i];\r\n }\r\n if (arr[i] > max1) {\r\n max2 = max1;\r\n max1 = arr[i];\r\n } else if (arr[i] > max2) {\r\n max2 = arr[i];\r\n }\r\n }\r\n output(max1 + max2 - min1 - min2);\r\n }\r\n}\r\n\r\n// max max min min\r\n// min max min max\r\n// max min min max\r\n//\r\n//\r\n//"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\nfunction myFunc(arr){\r\n \r\n const n = arr.length;\r\n arr.sort((a, b) => a - b);\r\n\r\n return arr[n-1] + arr[n-2] - arr[1] - arr[0];\r\n\r\n}\r\n"}, {"source_code": "var n, a;\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n a.sort((x, y) => x-y);\r\n print(a[n-1] + a[n-2] - a[0] - a[1])\r\n }"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n testCases.push(testCase);\n }\n}\n\nconst attempt = (a, n) => {\n let leftMin = Infinity;\n let leftMax = -Infinity;\n const leftMins = [];\n const leftMaxs = [];\n for (let i = 0; i < n; i++) {\n const v = a[i];\n if (v < leftMin) leftMin = v;\n if (v > leftMax) leftMax = v;\n leftMins.push(leftMin);\n leftMaxs.push(leftMax);\n }\n let rightMin = Infinity;\n let rightMax = -Infinity;\n const rightMins = [];\n const rightMaxs = [];\n for (let i = n - 1; i >= 0; i--) {\n const v = a[i];\n if (v < rightMin) rightMin = v;\n if (v > rightMax) rightMax = v;\n rightMins.unshift(rightMin);\n rightMaxs.unshift(rightMax);\n }\n\n const leftDiffs = leftMaxs.map((m, i) => m - leftMins[i]);\n const rightDiffs = rightMaxs.map((m, i) => m - rightMins[i]);\n // console.log(leftMins);\n // console.log(leftMaxs);\n // console.log(leftDiffs);\n // console.log(rightMins);\n // console.log(rightMaxs);\n // console.log(rightDiffs);\n\n let result = 0;\n for (let i = 0; i < n - 1; i++) {\n const v = leftDiffs[i] + rightDiffs[i + 1];\n if (v > result) result = v;\n }\n return result;\n};\n\nfunction solution(testCase) {\n let { n, a } = testCase;\n\n a.sort((b, c) => b - c);\n console.log(a[a.length - 1] + a[a.length - 2] - a[1] - a[0]);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nconst testCases = readline()\r\n \r\nfunction main() {\r\n const length = readline()\r\n const arr = readline().split(' ')\r\n arr.sort((a, b) => a - b)\r\n const result = parseInt(arr[length - 1] - arr[0]) + parseInt(arr[length - 2] - arr[1])\r\n console.log(result)\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// Main Function, write code here\r\n \r\nfunction main() {\r\n const length = readline()\r\n const arr = readline().split(' ')\r\n arr.sort((a, b) => a - b)\r\n const result = parseInt(arr[length - 1] - arr[0]) + parseInt(arr[length - 2] - arr[1])\r\n console.log(result)\r\n}"}, {"source_code": "\"use strict\";\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const length = readline()\r\n const arr = readline().split(' ')\r\n arr.sort()\r\n const result = parseInt(arr[length - 1] - arr[0]) + parseInt(arr[length - 2] - arr[1])\r\n return result\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Main Function, write code here\r\n\r\nfunction main() {\r\n const length = readline()\r\n const arr = readline().split(' ')\r\n arr.sort()\r\n const result = arr[length - 1] - arr[0] + arr[length - 2] - arr[1]\r\n return result\r\n}\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n testCases.push(testCase);\n }\n}\n\nconst attempt = (a, n) => {\n let leftMin = Infinity;\n let leftMax = -Infinity;\n const leftMins = [];\n const leftMaxs = [];\n for (let i = 0; i < n; i++) {\n const v = a[i];\n if (v < leftMin) leftMin = v;\n if (v > leftMax) leftMax = v;\n leftMins.push(leftMin);\n leftMaxs.push(leftMax);\n }\n let rightMin = Infinity;\n let rightMax = -Infinity;\n const rightMins = [];\n const rightMaxs = [];\n for (let i = n - 1; i >= 0; i--) {\n const v = a[i];\n if (v < rightMin) rightMin = v;\n if (v > rightMax) rightMax = v;\n rightMins.unshift(rightMin);\n rightMaxs.unshift(rightMax);\n }\n\n const leftDiffs = leftMaxs.map((m, i) => m - leftMins[i]);\n const rightDiffs = rightMaxs.map((m, i) => m - rightMins[i]);\n // console.log(leftMins);\n // console.log(leftMaxs);\n // console.log(leftDiffs);\n // console.log(rightMins);\n // console.log(rightMaxs);\n // console.log(rightDiffs);\n\n let result = 0;\n for (let i = 0; i < n - 1; i++) {\n const v = leftDiffs[i] + rightDiffs[i + 1];\n if (v > result) result = v;\n }\n return result;\n};\n\nfunction solution(testCase) {\n let { n, a } = testCase;\n // console.log(n, a);\n\n let maxi = -Infinity;\n let maxiIndex;\n let mini = Infinity;\n let miniIndex;\n a.forEach((v, i) => {\n if (v > maxi) {\n maxi = v;\n maxiIndex = i;\n }\n if (v < mini) {\n mini = v;\n miniIndex = i;\n }\n });\n\n let startWithMax = [...a];\n const toPushStartWithMax = startWithMax.splice(0, maxiIndex);\n startWithMax.push(...toPushStartWithMax);\n\n const resultStartWithMax = attempt(startWithMax, n);\n\n let endWithMax = [...a];\n const toPushEndWithMax = endWithMax.splice(maxiIndex + 1);\n endWithMax.push(...toPushEndWithMax);\n\n const resultEndWithMax = attempt(endWithMax, n);\n\n let startWithMin = [...a];\n const toPushStartWithMin = startWithMin.splice(0, miniIndex);\n startWithMin.push(...toPushStartWithMin);\n\n const resultStartWithMin = attempt(startWithMin, n);\n\n let endWithMin = [...a];\n const toPushEndWithMin = endWithMin.splice(miniIndex + 1);\n endWithMin.push(...toPushEndWithMin);\n\n const resultEndWithMin = attempt(endWithMin, n);\n\n // console.log(a);\n\n console.log(\n Math.max(\n resultStartWithMax,\n resultEndWithMax,\n resultStartWithMin,\n resultEndWithMin\n )\n );\n // console.log(\"--------\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n testCases.push(testCase);\n }\n}\n\nconst attempt = (a, n) => {\n let leftMin = Infinity;\n let leftMax = -Infinity;\n const leftMins = [];\n const leftMaxs = [];\n for (let i = 0; i < n; i++) {\n const v = a[i];\n if (v < leftMin) leftMin = v;\n if (v > leftMax) leftMax = v;\n leftMins.push(leftMin);\n leftMaxs.push(leftMax);\n }\n let rightMin = Infinity;\n let rightMax = -Infinity;\n const rightMins = [];\n const rightMaxs = [];\n for (let i = n - 1; i >= 0; i--) {\n const v = a[i];\n if (v < rightMin) rightMin = v;\n if (v > rightMax) rightMax = v;\n rightMins.unshift(rightMin);\n rightMaxs.unshift(rightMax);\n }\n\n const leftDiffs = leftMaxs.map((m, i) => m - leftMins[i]);\n const rightDiffs = rightMaxs.map((m, i) => m - rightMins[i]);\n // console.log(leftMins);\n // console.log(leftMaxs);\n // console.log(leftDiffs);\n // console.log(rightMins);\n // console.log(rightMaxs);\n // console.log(rightDiffs);\n\n let result = 0;\n for (let i = 0; i < n - 1; i++) {\n const v = leftDiffs[i] + rightDiffs[i + 1];\n if (v > result) result = v;\n }\n return result;\n};\n\nfunction solution(testCase) {\n let { n, a } = testCase;\n // console.log(n, a);\n\n let maxi = -Infinity;\n let maxiIndex;\n let mini = Infinity;\n let miniIndex;\n a.forEach((v, i) => {\n if (v > maxi) {\n maxi = v;\n maxiIndex = i;\n }\n if (v < mini) {\n mini = v;\n miniIndex = i;\n }\n });\n\n let startWithMax = [...a];\n const toPushStartWithMax = startWithMax.splice(0, maxiIndex);\n startWithMax.push(...toPushStartWithMax);\n\n const resultStartWithMax = attempt(startWithMax, n);\n\n let endWithMax = [...a];\n const toPushEndWithMax = endWithMax.splice(maxiIndex + 1);\n endWithMax.push(...toPushEndWithMax);\n\n const resultEndWithMax = attempt(endWithMax, n);\n\n // console.log(a);\n\n console.log(Math.max(resultStartWithMax, resultEndWithMax));\n // console.log(\"--------\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n let { n, a } = testCase;\n // console.log(n, a);\n\n let maxi = -Infinity;\n let maxiIndex;\n a.forEach((v, i) => {\n if (v > maxi) {\n maxi = v;\n maxiIndex = i;\n }\n });\n\n const toPush = a.splice(0, maxiIndex);\n a.push(...toPush);\n\n // console.log(a);\n\n let leftMin = Infinity;\n let leftMax = -Infinity;\n const leftMins = [];\n const leftMaxs = [];\n for (let i = 0; i < n; i++) {\n const v = a[i];\n if (v < leftMin) leftMin = v;\n if (v > leftMax) leftMax = v;\n leftMins.push(leftMin);\n leftMaxs.push(leftMax);\n }\n let rightMin = Infinity;\n let rightMax = -Infinity;\n const rightMins = [];\n const rightMaxs = [];\n for (let i = n - 1; i >= 0; i--) {\n const v = a[i];\n if (v < rightMin) rightMin = v;\n if (v > rightMax) rightMax = v;\n rightMins.unshift(rightMin);\n rightMaxs.unshift(rightMax);\n }\n\n const leftDiffs = leftMaxs.map((m, i) => m - leftMins[i]);\n const rightDiffs = rightMaxs.map((m, i) => m - rightMins[i]);\n // console.log(leftMins);\n // console.log(leftMaxs);\n // console.log(leftDiffs);\n // console.log(rightMins);\n // console.log(rightMaxs);\n // console.log(rightDiffs);\n\n let result = 0;\n for (let i = 0; i < n - 1; i++) {\n const v = leftDiffs[i] + rightDiffs[i + 1];\n if (v > result) result = v;\n }\n console.log(result);\n // console.log(\"--------\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "1e54530bc8cff81199b9cc1a6e51d638"} {"source_code": ";(function () {\n\n\tprint(function () {\n\t\tvar n = +readline(), m = {}, r = 0;\n\t\treadline().split(' ').forEach(function (e) { m[e] = m[e] ? m[e] + 1 : 1; });\n\n\t\tfor (var k in m)\n\t\t\tif (m[k] > 1)\n\t\t\t\tr += Math.floor(m[k] / 2);\n\n\t\treturn Math.floor(r / 2);\n\t}());\n\n}).call(this);", "positive_code": [{"source_code": "print(function(n, a) {\n\tvar i, sum = 0,\n\t\tcnt = new Int32Array(105);\n\n\tfor (i = 0; i < n; i++)\n\t\t++cnt[a[i]];\n\n\tfor (i = 0; i < 105; i++)\n\t\tsum += cnt[i] >> 1;\n\n\treturn sum >> 1;\n\n}(+readline(), readline().split(' ').map(Number)));"}], "negative_code": [], "src_uid": "f9b56b3fddcd5db0d0671714df3f8646"} {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n var negative = Infinity;\n var positive = 0;\n\n values.forEach(function(v) {\n var _negative = negative,\n _positive = positive;\n positive = Math.min(\n _negative + Math.abs(v + 1),\n _positive + Math.abs(v - 1)\n );\n negative = Math.min(\n _negative + Math.abs(v - 1),\n _positive + Math.abs(v + 1)\n );\n });\n\n print(positive);\n}\n\nmain();\n", "positive_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 0;\n let minus = 0;\n let hasZero = false;\n const arr = d.split(\" \").map(Number);\n arr.sort((a, b) => a - b);\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 0) {\n ans += Math.abs(arr[i] + 1);\n minus++;\n } else {\n if (arr[i] === 0) {\n hasZero = true;\n }\n ans += Math.abs(arr[i] - 1);\n }\n }\n\n if (minus % 2 !== 0 && !hasZero) {\n ans += 2;\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "\nfunction doStuff (data) {\n var x = data.split(' ');\n\n var solutionNrs = [];\n var coins = 0;\n var zeroPresent = false;\n for (var i = 0; i < numbers; i++) {\n var cur = x[i];\n if (cur == 0) {\n cur++;\n zeroPresent = true;\n solutionNrs.push(1);\n } else if (cur < 0) {\n cur *= -1;\n cur--;\n solutionNrs.push(-1);\n } else if (cur > 0) {\n cur--;\n solutionNrs.push(1);\n }\n coins += cur;\n }\n var endNrLogic = 1;\n solutionNrs.forEach( function (y) {\n endNrLogic *= y;\n });\n if (endNrLogic == 0) {\n coins += 2;\n } else if (endNrLogic == -1 && zeroPresent) {\n // coins--;\n } else if (endNrLogic == -1 && !zeroPresent) {\n coins += 2;\n }\n console.log(coins);\n};\nvar numbers;\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n numbers = lines[0];\n doStuff(lines[1]);\n});"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN();\n var res = 0;\n var sign = 1;\n var zC = 0;\n for (var i = 0; i < n; ++i) {\n if (A[i] > 0) {\n res += A[i] - 1;\n } else if (A[i] < 0) {\n res += -A[i] - 1;\n sign *= -1;\n } else {\n ++zC;\n }\n }\n if (zC > 0) {\n res += zC;\n } else {\n if (sign === -1) {\n res += 2;\n }\n }\n wr(res);\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var a = parseInt(readline().trim());var answ = 0;var numbers = readline().trim().split(\" \").map(function(x) { return parseInt(x); });var cnt = 0, cn = 0;for(var i = 0; i < numbers.length; i++){answ += Math.abs(numbers[i]);answ--;if(numbers[i]===0){answ++;cnt++;}if(numbers[i] < 0){cn++}}if(cn % 2 === 1 && cnt === 0)answ += 2;else answ += cnt;print(answ);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = \"\";\nlet input = \"\";\nlet input_currentline = 0;\n\nfunction readLine() {\n return input[input_currentline++];\n}\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n input = input_stdin.split(\"\\n\");\n main();\n});\n\n\n// your code goes here\nfunction main() {\n const N = Number(readLine());\n const n = readLine().split(' ').map(x=>+x);\n \n let ans = 0\n let minus1 = 0;\n let numZeros = 0;\n for (let i = 0; i < N; i ++) {\n let toMinus1 = Math.abs(n[i] + 1);\n let toPlus1 = Math.abs(n[i] - 1)\n ans += Math.min(toMinus1, toPlus1);\n if (toMinus1 < toPlus1) minus1++;\n if (n[i] === 0) numZeros++;\n }\n console.log(minus1%2 === 1 && numZeros === 0 ? ans + 2 : ans);\n}"}, {"source_code": "const processData = (lines) => {\ndebugger\n const [n, a] = lines\n\n const A = a.split(' ').map(n => Number(n))\n\n let coins = 0\n let sign = 1\n let closeTo = 2\n for (let i = 0; i < A.length; i++) {\n const el = A[i]\n if (el >= 1) coins += el - 1\n if (el <= -1) coins += Math.abs(el) - 1\n if (el === 0) {\n coins += 1\n closeTo = 0\n }\n sign = sign * (Math.sign(el) === 0 ? 1 : Math.sign(el))\n }\n if (sign < 0) {\n coins += closeTo\n }\n\n console.log(coins)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}], "negative_code": [{"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n var negative = 0;\n var positive = 0;\n\n values.forEach(function(v) {\n var _negative = negative,\n _positive = positive;\n positive = Math.min(\n _negative + Math.abs(v + 1),\n _positive + Math.abs(v - 1)\n );\n negative = Math.min(\n _negative + Math.abs(v - 1),\n _positive + Math.abs(v + 1)\n );\n });\n\n print(positive);\n}\n\nmain();\n"}, {"source_code": "var a = parseInt(readline().trim());var answ = 0;\nvar numbers = readline().trim().split(\" \").map(function(x) { return parseInt(x); });var cnt = 0, cn = 0;\nfor(var i = 0; i < numbers.length; i++){answ += Math.abs(numbers[i]);answ--;if(numbers[i]===0){answ++;cnt++;}if(numbers[i] < 0){cn++}}\nif(cn % 2 === 1 && cnt === 0)answ += 2;\nelse answ += cn + cnt;\nprint(answ);"}, {"source_code": "\nfunction doStuff (data) {\n var x = data.split(' ');\n\n var solutionNrs = [];\n var coins = 0;\n var zeroPresent = false;\n for (var i = 0; i < x.nr; i++) {\n var cur = x.numbers[i];\n if (cur == 0) {\n cur++;\n zeroPresent = true;\n solutionNrs.push(1);\n } else if (cur < 0) {\n cur *= -1;\n cur--;\n solutionNrs.push(-1);\n } else if (cur > 0) {\n cur--;\n solutionNrs.push(1);\n }\n coins += cur;\n }\n var endNrLogic = 1;\n solutionNrs.forEach( function (y) {\n endNrLogic *= y;\n });\n if (endNrLogic == 0) {\n coins += 2;\n } else if (endNrLogic == -1 && zeroPresent) {\n coins--;\n } else if (endNrLogic == -1 && !zeroPresent) {\n coins += 2;\n }\n console.log(coins);\n};\nvar numbers;\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n numbers = lines[0];\n doStuff(lines[1]);\n});"}, {"source_code": "\nfunction doStuff (data) {\n var x = data.split(' ');\n\n var solutionNrs = [];\n var coins = 0;\n var zeroPresent = false;\n for (var i = 0; i < numbers; i++) {\n var cur = x[i];\n if (cur == 0) {\n cur++;\n zeroPresent = true;\n solutionNrs.push(1);\n } else if (cur < 0) {\n cur *= -1;\n cur--;\n solutionNrs.push(-1);\n } else if (cur > 0) {\n cur--;\n solutionNrs.push(1);\n }\n coins += cur;\n }\n var endNrLogic = 1;\n solutionNrs.forEach( function (y) {\n endNrLogic *= y;\n });\n if (endNrLogic == 0) {\n coins += 2;\n } else if (endNrLogic == -1 && zeroPresent) {\n coins--;\n } else if (endNrLogic == -1 && !zeroPresent) {\n coins += 2;\n }\n console.log(coins);\n};\nvar numbers;\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n numbers = lines[0];\n doStuff(lines[1]);\n});"}, {"source_code": "\nfunction doStuff (data) {\n var x = data.split(' ');\n\n var solutionNrs = [];\n var coins = 0;\n var zeroPresent = false;\n for (var i = 0; i < x.nr; i++) {\n var cur = x.numbers[i];\n if (cur == 0) {\n cur++;\n zeroPresent = true;\n solutionNrs.push(1);\n } else if (cur < 0) {\n cur *= -1;\n cur--;\n solutionNrs.push(-1);\n } else if (cur > 0) {\n cur--;\n solutionNrs.push(1);\n }\n coins += cur;\n }\n var endNrLogic = 1;\n solutionNrs.forEach( function (y) {\n endNrLogic *= y;\n });\n if (endNrLogic == 0) {\n coins += 2;\n } else if (endNrLogic == -1 && zeroPresent) {\n coins--;\n } else if (endNrLogic == -1 && !zeroPresent) {\n coins += 2;\n }\n console.log(coins);\n};\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n doStuff(lines[0]);\n});"}, {"source_code": "\nfunction doStuff (x) {\n var solutionNrs = [];\n var coins = 0;\n var zeroPresent = false;\n for (var i = 0; i < x.nr; i++) {\n var cur = x.numbers[i];\n if (cur == 0) {\n cur++;\n zeroPresent = true;\n solutionNrs.push(1);\n } else if (cur < 0) {\n cur *= -1;\n cur--;\n solutionNrs.push(-1);\n } else if (cur > 0) {\n cur--;\n solutionNrs.push(1);\n }\n coins += cur;\n }\n var endNrLogic = 1;\n solutionNrs.forEach( function (y) {\n endNrLogic *= y;\n });\n if (endNrLogic == 0) {\n coins += 2;\n } else if (endNrLogic == -1 && zeroPresent) {\n coins--;\n } else if (endNrLogic == -1 && !zeroPresent) {\n coins += 2;\n }\n console.log(coins);\n};\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n doStuff(lines[0]);\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = \"\";\nlet input = \"\";\nlet input_currentline = 0;\n\nfunction readLine() {\n return input[input_currentline++];\n}\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n input = input_stdin.split(\"\\n\");\n main();\n});\n\n\n// your code goes here\nfunction main() {\n const N = Number(readLine());\n const n = readLine().split(' ').map(x=>+x);\n \n let memo = [];\n\n const getCoins = (arr, res) => {\n if (arr.length===1) {\n return res === 1 ? Math.abs(arr[0] - 1) : Math.abs(arr[0] + 1);\n }\n if (memo.findIndex(x => x.id === arr.join(\"-\") && x.res === res) != -1) {\n return memo.find(x => x.id === arr.join(\"-\") && x.res === res).val;\n }\n let v = Math.min(getCoins(arr.slice(1), 1) + Math.abs(arr[0] - 1), getCoins(arr.slice(1), -1) + Math.abs(arr[0] + 1));\n memo.push({id:arr.join(\"-\"), res: res, val: v});\n return v;\n }\n \n console.log(getCoins(n, 1));\n \n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = \"\";\nlet input = \"\";\nlet input_currentline = 0;\n\nfunction readLine() {\n return input[input_currentline++];\n}\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n input = input_stdin.split(\"\\n\");\n main();\n});\n\n\n// your code goes here\nfunction main() {\n const N = Number(readLine());\n const n = readLine().split(' ').map(x=>+x);\n \n let ans = 0\n let minus1 = 0;\n for (let i = 0; i < N; i ++) {\n let toMinus1 = Math.abs(n[i] + 1);\n let toPlus1 = Math.abs(n[i] - 1)\n ans += Math.min(toMinus1, toPlus1);\n if (toMinus1 < toPlus1) minus1++;\n }\n console.log(minus1%2 === 0 ? ans : ans + 2);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = \"\";\nlet input = \"\";\nlet input_currentline = 0;\n\nfunction readLine() {\n return input[input_currentline++];\n}\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n input = input_stdin.split(\"\\n\");\n main();\n});\n\n\n// your code goes here\nfunction main() {\n const N = Number(readLine());\n const n = readLine().split(' ').map(x=>+x);\n \n let memo = [];\n\n const getCoins = (arr, res) => {\n if (arr.length===1) {\n return res === 1 ? Math.abs(arr - 1) : Math.abs(arr + 1);\n }\n if (memo.findIndex(x => x.id === arr.join(\"-\")) != -1) {\n return memo.find(x => x.id === arr.join(\"-\")).val;\n }\n let v = Math.min(getCoins(arr.slice(1), 1) + Math.abs(arr[0] - 1), getCoins(arr.slice(1), -1) + Math.abs(arr[0] + 1));\n memo.push({id:arr.join(\"-\"), val: v});\n return v;\n }\n \n console.log(getCoins(n, 1));\n \n}"}, {"source_code": "const processData = (lines) => {\n const [n, a] = lines\n\n const A = a.split(' ').map(n => Number(n))\n\n let coins = 0\n let sign = 1\n // let closeTo1 = 1\n for (let i = 0; i < A.length; i++) {\n if (A[i] > 1) coins += A[i] - 1\n if (A[i] < -1) coins += Math.abs(A[i]) - 1\n // if (Math.abs(A[i] - 1) < Math.abs(A[closeTo1] - 1)) closeTo1 = i\n sign = sign * Math.sign(A[i])\n }\n if (sign < 0) coins -= 2\n\n console.log(coins)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const [n, a] = lines\n\n const A = a.split(' ').map(n => Number(n))\n\n let coins = 0\n let sign = 1\n let closeTo = 2\n for (let i = 0; i < A.length; i++) {\n if (A[i] >= 1) coins += A[i] - 1\n if (A[i] <= -1) coins += Math.abs(A[i]) - 1\n if (A[i] === 0) {\n coins += 1\n closeTo = 0\n }\n sign = sign * Math.sign(A[i]) === 0 ? 1 : Math.sign(A[i])\n }\n if (sign < 0) {\n coins += closeTo\n }\n\n console.log(coins)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const [n, a] = lines\n \n const A = a.split(' ').map(n => Number(n))\n \n let coins = 0\n let sign = 1\n // let closeTo1 = 1\n for (let i = 0; i < A.length; i++) {\n if (A[i] > 1) coins += A[i] - 1\n if (A[i] < -1) coins += Math.abs(A[i]) - 1\n // if (Math.abs(A[i] - 1) < Math.abs(A[closeTo1] - 1)) closeTo1 = i\n sign = sign * Math.sign(A[i])\n }\n if (sign < 0) coins += 2\n \n console.log(coins)\n}\n \nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const [n, a] = lines\n\n const A = a.split(' ').map(n => Number(n))\n\n let coins = 0\n let sign = 1\n let closeTo1 = 1\n for (let i = 0; i < A.length; i++) {\n if (A[i] >= 1) coins += A[i] - 1\n if (A[i] <= -1) coins += Math.abs(A[i]) - 1\n if (A[i] === 0) coins += 1\n if (Math.abs(A[i] - 1) < Math.abs(A[closeTo1] - 1)) closeTo1 = i\n sign = sign * Math.sign(A[i])\n }\n if (sign < 0) {\n if (A[closeTo1] <= -1) {\n coins += 2\n }\n if (A[closeTo1] >= 1) {\n coins += 2\n }\n // if (A[closeTo1] === 0) {\n // \n // }\n }\n\n console.log(coins)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}], "src_uid": "3b3b2408609082fa5c3a0d55bb65d29a"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, d) {\r\n let count = 0;\r\n while (x % d === 0) {\r\n count++;\r\n x /= d;\r\n }\r\n if (count < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n for (let i = 2; i <= x / i; i++) {\r\n if (x % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n if (count > 2) {\r\n for (let i = 2; i <= d / i; i++) {\r\n if (d % i === 0) {\r\n if (i === d / i) {\r\n if (i !== x) {\r\n console.log('YES');\r\n return;\r\n } else if (count > 3) {\r\n console.log('YES');\r\n return;\r\n }\r\n } else {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const [x, d] = (await read()).split(' ').map(Number);\r\n solve(x, d);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "function solve() {\r\n const [x, d] = readArray(Number);\r\n const count = countBeatyMul(x, d, 1);\r\n write(count > 1 ? 'YES' : 'NO');\r\n}\r\n\r\nfunction countBeatyMul(x, d, start) {\r\n if (x % d !== 0) {\r\n return 0;\r\n }\r\n if (isBeaty(x, d)) {\r\n return 1;\r\n }\r\n let ans = 0;\r\n for (let i = start; i <= Math.floor(Math.sqrt(x)); i++) {\r\n if (x % i !== 0) {\r\n continue;\r\n }\r\n const xDivI = Math.floor(x / i);\r\n if (xDivI < start) {\r\n continue;\r\n }\r\n if (isBeaty(i, d)) {\r\n ans += countBeatyMul(xDivI, d, i)\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction isBeaty(x, d) {\r\n return x % d === 0 && x % (d * d) !== 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, d) {\r\n let count = 0;\r\n while (x % d === 0) {\r\n count++;\r\n x /= d;\r\n }\r\n if (count < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n for (let i = 2; i <= x / i; i++) {\r\n if (x % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n if (count > 2) {\r\n for (let i = 2; i <= d / i; i++) {\r\n if (d % i === 0) {\r\n if (i === d / i) {\r\n if (i !== x) {\r\n console.log('YES');\r\n return;\r\n }\r\n } else {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const [x, d] = (await read()).split(' ').map(Number);\r\n solve(x, d);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, d) {\r\n let count = 0;\r\n while (x % d === 0) {\r\n count++;\r\n x /= d;\r\n }\r\n if (count < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n for (let i = 2; i <= x / i; i++) {\r\n if (x % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n if (count > 2) {\r\n for (let i = 2; i <= d / i; i++) {\r\n if (count > 3) {\r\n if (d % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n } else {\r\n if (d % i === 0 && i !== x && d / i !== x) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const [x, d] = (await read()).split(' ').map(Number);\r\n solve(x, d);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, d) {\r\n let count = 0;\r\n while (x % d === 0) {\r\n count++;\r\n x /= d;\r\n }\r\n if (count < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n for (let i = 2; i <= x / i; i++) {\r\n if (x % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n if (count > 2) {\r\n for (let i = 2; i <= d / i; i++) {\r\n if (count > 3) {\r\n if (d % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n } else {\r\n if (i !== x && d / i !== x) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const [x, d] = (await read()).split(' ').map(Number);\r\n solve(x, d);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, d) {\r\n let count = 0;\r\n while (x % d === 0) {\r\n count++;\r\n x /= d;\r\n }\r\n if (count < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n for (let i = 2; i <= x / i; i++) {\r\n if (x % i === 0) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n if (count > 2) {\r\n for (let i = 2; i <= d / i; i++) {\r\n if (d % i === 0 && i !== x && d / i !== x) {\r\n console.log('YES');\r\n return;\r\n }\r\n }\r\n }\r\n console.log('NO');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const [x, d] = (await read()).split(' ').map(Number);\r\n solve(x, d);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "ee27020ca43546993b82357527585831"} {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar _loop_1 = function () {\r\n readline();\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n var A = a.map(function (_, i) { return [a[i], b[i]]; });\r\n A.sort(function (a, b) { return a[0] - b[0]; });\r\n var count = 0;\r\n var i = 0;\r\n while (i < A.length) {\r\n var temp = i;\r\n while (A[i][0]) {\r\n A[i][0] = 0;\r\n i = A[i][1] - 1;\r\n count++;\r\n }\r\n count -= (count % 2);\r\n i = temp + 1;\r\n }\r\n print(count * (a.length - (count >> 1)));\r\n};\r\nwhile (t-- > 0) {\r\n _loop_1();\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b) {\r\n a = a.map(num => num - 1);\r\n b = b.map(num => num - 1);\r\n const p = [...new Array(n).keys()];\r\n const count = new Array(n).fill(1);\r\n const find = i => {\r\n if (p[i] !== i) p[i] = find(p[p[i]]);\r\n return p[i];\r\n };\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) {\r\n p[rj] = ri;\r\n count[ri] += count[rj];\r\n }\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) union(a[i], b[i]);\r\n }\r\n const roots = new Set();\r\n for (let i = 0; i < n; i++) {\r\n roots.add(find(i));\r\n }\r\n let res = 0,\r\n l = 1,\r\n r = n;\r\n for (let i of roots) {\r\n let c = count[i];\r\n if (c === 1) continue;\r\n if (c & 1) c = c - 1;\r\n let nums = new Array(c).fill(0);\r\n for (let i = 0, j = c - 1; i < j; i++, j--) {\r\n if (i & 1) {\r\n nums[i] = r--;\r\n nums[j] = l++;\r\n } else {\r\n nums[i] = l++;\r\n nums[j] = r--;\r\n }\r\n }\r\n for (let i = 0; i < c; i++) {\r\n res += Math.abs(nums[(i + 1) % c] - nums[i]);\r\n }\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nlet stackRecursion = (fn, init_state)=>{\n let stack = [];\n let rec = (cb, a0, a1, a2)=>{\n let state = Object.assign({}, init_state);\n stack.push([state, cb, a0, a1, a2]);\n };\n return (cb, a0, a1, a2)=>{\n rec(cb, a0, a1, a2);\n while (stack.length){\n let [state, cb, a0, a1, a2] = stack[stack.length-1];\n let added = false;\n fn((cb, a0, a1, a2)=>{\n added = true;\n rec(cb, a0, a1, a2);\n }, state, a0, a1, a2);\n if (!added){\n cb(state);\n stack.pop();\n }\n }\n };\n};\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let posB = new Array(n).fill(0);\n for (let i=0; i{\n if (visit.has(v)){\n return;\n }\n visit.add(v);\n cnt++;\n rec(()=>{}, posB[A[v]]);\n }, {});\n let c = 0;\n for (let i=0; i{}, i);\n c += cnt>>1;\n }\n return Math.floor((c*(n-c))*2);\n};\n "}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b) {\r\n a = a.map(num => num - 1);\r\n b = b.map(num => num - 1);\r\n const p = [...new Array(n).keys()];\r\n const count = new Array(n).fill(1);\r\n const find = i => {\r\n if (p[i] !== i) p[i] = find(p[p[i]]);\r\n return p[i];\r\n };\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) {\r\n p[rj] = ri;\r\n count[ri] += count[rj];\r\n }\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) union(a[i], b[i]);\r\n }\r\n const roots = new Set();\r\n for (let i = 0; i < n; i++) {\r\n roots.add(find(i));\r\n }\r\n let res = 0,\r\n l = 1,\r\n r = n;\r\n for (let i of roots) {\r\n const c = count[i];\r\n if (c === 1) continue;\r\n if (c === 2) {\r\n res += (r - l) * 2;\r\n r--;\r\n l--;\r\n continue;\r\n }\r\n res += r - l;\r\n for (let i = 0; i < (c - 2) / 2; i++) {\r\n res += (r - l - 1) * 2;\r\n r--, l++;\r\n }\r\n res += r - l;\r\n r--, l++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nlet stackRecursion = (fn, init_state)=>{\n let stack = [];\n let rec = (cb, a0, a1, a2)=>{\n let state = Object.assign({}, init_state);\n stack.push([state, cb, a0, a1, a2]);\n };\n return (cb, a0, a1, a2)=>{\n rec(cb, a0, a1, a2);\n while (stack.length){\n let [state, cb, a0, a1, a2] = stack[stack.length-1];\n let added = false;\n fn((cb, a0, a1, a2)=>{\n added = true;\n rec(cb, a0, a1, a2);\n }, state, a0, a1, a2);\n if (!added){\n cb(state);\n stack.pop();\n }\n }\n };\n};\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let posB = new Array(n).fill(0);\n for (let i=0; i{\n if (visit.has(v)){\n return;\n }\n visit.add(v);\n cnt++;\n rec(()=>{}, posB[A[v]]);\n }, {});\n let c = 0;\n for (let i=0; i{}, i);\n c += cnt>>1;\n }\n return (c*(n-c))<<1;\n};\n "}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let B = ra();\n LT({n, A, B});\n // PROCESSING:\n let nums = new Set();\n let posA = new Array(n).fill(0)\n let posB = new Array(n).fill(0)\n for (let i=0; ia-b)\n let l = 0, r = n-1;\n L(arr)\n let ans = 0;\n let i=0;\n let alloc = new Array(n).fill(-1);\n while (i=0 && valR>=0){\n ans += Math.abs(valL-valR);\n } else {\n if (valL==-1){\n if (Math.abs(l-valR)>Math.abs(r-valR)){\n alloc[A[i]] = l++;\n\n } else {\n alloc[A[i]] = r--;\n }\n } else {\n if (Math.abs(l-valL)>Math.abs(r-valL)){\n alloc[B[i]] = l++;\n } else {\n alloc[B[i]] = r--;\n }\n\n }\n ans += Math.abs(alloc[A[i]]-alloc[B[i]]);\n }\n i++;\n\n }\n return ans;\n};\n "}], "src_uid": "4bcaa910cce687f0881a36231aa1a2c8"} {"source_code": "\"use strict\";\nexports.__esModule = true;\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().trim().split(\"\");\n var res = stations.map(function (v) { return 0; });\n costs(stations, busCost, tramCost, res);\n var j = 0;\n while (j < stations.length && res[j] > balance) {\n j++;\n }\n // console.log(j === stations.length ? j - 1 : j + 1);\n console.log(j + 1);\n }\n}\nfunction costs(stations, busCost, tramCost, res) {\n res[stations.length - 1] = 0;\n res[stations.length - 2] = stations[stations.length - 2] === \"A\" ? busCost : tramCost;\n for (var i = stations.length - 3; i >= 0; i--) {\n if (stations[i] !== stations[i + 1]) {\n res[i] = res[i + 1] + (stations[i] === \"A\" ? busCost : tramCost);\n }\n else {\n res[i] = res[i + 1];\n }\n }\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, ost) {\n let [a, b, p] = data;\n\n const substr = [];\n const substrInd = [];\n\n for (let i=0; i= 0; k--) {\n if (substr[k] === 'B' && p >= b) {\n p = p - b;\n } else if (substr[k] === 'A' && p >= a) {\n p = p - a;\n } else {\n return substrInd[k+1];\n }\n }\n\n return 1;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount*2-1].split(\" \").map(Number);\n let ost = lines[testCount*2].split(\"\");\n let result = foo(data, ost);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}], "negative_code": [{"source_code": "function main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().split(\"\");\n var j = 0;\n var found = false;\n while (j < stations.length && !found) {\n if (remainingBalance(j, stations, busCost, tramCost, balance) >= 0) {\n found = true;\n }\n else {\n j++;\n }\n }\n console.log(j + 1);\n }\n}\nvar dm = {};\nfunction remainingBalance(pos, stations, busCost, tramCost, balance) {\n if (pos === void 0) { pos = 0; }\n if (balance < 0) {\n dm[pos + \"-\" + balance] = -1;\n return -1;\n }\n if (pos === stations.length - 1) {\n dm[pos + \"-\" + balance] = balance;\n return balance;\n }\n var newPos = pos;\n var fst = stations[pos];\n while (stations[newPos] === fst) {\n if (newPos === stations.length) {\n // dm[newPos + \"-\" + balance] = balance;\n return balance;\n }\n newPos++;\n }\n return remainingBalance(newPos, stations, busCost, tramCost, balance - (fst === \"A\" ? busCost : tramCost));\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().split(\"\");\n var res = stations.map(function (v) { return 0; });\n costs(stations, busCost, tramCost, res);\n var j = 0;\n while (j < stations.length - 1 && res[j] > balance) {\n j++;\n }\n // console.log(j === stations.length ? j - 1 : j + 1, balance, busCost, tramCost, res, stations);\n console.log(j + 1);\n }\n}\nfunction costs(stations, busCost, tramCost, res) {\n res[stations.length - 1] = 0;\n res[stations.length - 2] = stations[stations.length - 2] === \"A\" ? busCost : tramCost;\n for (var i = stations.length - 3; i >= 0; i--) {\n if (stations[i] !== stations[i + 1]) {\n res[i] = res[i + 1] + (stations[i] === \"A\" ? busCost : tramCost);\n }\n else {\n res[i] = res[i + 1];\n }\n }\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().split(\"\");\n var res = stations.map(function (v) { return 0; });\n costs(stations, busCost, tramCost, res);\n var j = 0;\n while (j < stations.length - 1 && res[j] > balance) {\n j++;\n }\n // console.log(j === stations.length ? j - 1 : j + 1, balance, busCost, tramCost, res, stations);\n console.log(j);\n }\n}\nfunction costs(stations, busCost, tramCost, res) {\n res[stations.length - 1] = 0;\n res[stations.length - 2] = stations[stations.length - 2] === \"A\" ? busCost : tramCost;\n for (var i = stations.length - 3; i >= 0; i--) {\n if (stations[i] !== stations[i + 1]) {\n res[i] = res[i + 1] + (stations[i] === \"A\" ? busCost : tramCost);\n }\n else {\n res[i] = res[i + 1];\n }\n }\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().split(\"\");\n var res = stations.map(function (v) { return 0; });\n costs(stations, busCost, tramCost, res);\n var j = 0;\n while (j < stations.length - 1 && res[j] > balance) {\n j++;\n }\n console.log(j === stations.length ? j - 1 : j + 1);\n // console.log(j+1);\n }\n}\nfunction costs(stations, busCost, tramCost, res) {\n res[stations.length - 1] = 0;\n res[stations.length - 2] = stations[stations.length - 2] === \"A\" ? busCost : tramCost;\n for (var i = stations.length - 3; i >= 0; i--) {\n if (stations[i] !== stations[i + 1]) {\n res[i] = res[i + 1] + (stations[i] === \"A\" ? busCost : tramCost);\n }\n else {\n res[i] = res[i + 1];\n }\n }\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), busCost = _a[0], tramCost = _a[1], balance = _a[2];\n var stations = lines.shift().split(\"\");\n var res = stations.map(function (v) { return 0; });\n costs(stations, busCost, tramCost, res);\n var j = 0;\n while (j < stations.length && res[j] > balance) {\n j++;\n }\n console.log(j === stations.length ? j - 1 : j + 1);\n // console.log(j+1);\n }\n}\nfunction costs(stations, busCost, tramCost, res) {\n res[stations.length - 1] = 0;\n res[stations.length - 2] = stations[stations.length - 2] === \"A\" ? busCost : tramCost;\n for (var i = stations.length - 3; i >= 0; i--) {\n if (stations[i] !== stations[i + 1]) {\n res[i] = res[i + 1] + (stations[i] === \"A\" ? busCost : tramCost);\n }\n else {\n res[i] = res[i + 1];\n }\n }\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}], "src_uid": "0e4c297fcacdd0a304310882cd7c8a44"} {"source_code": "function reversed(first, second)\n{\n var ans = true;\n for(var i = 0; i < first.length; i++)\n {\n if (first[i] != second[first.length - 1 - i])\n {\n ans = false;\n break;\n }\n }\n return ans;\n}\n\nfunction pal(str)\n{\n var half = Math.floor(str.length / 2);\n var ans = true;\n for(var i = 0; i < half; i++)\n if (str[i] != str[str.length - 1 - i])\n {\n ans = false;\n break;\n }\n return ans;\n}\n\nvar input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar m = input[1];\n\nvar arr = [];\nwhile(n--)\n arr.push(readline());\n\nvar taked = Array.apply(null, Array(arr.length)).map(Number.prototype.valueOf,0);\n\nvar count = 0;\nfor(var i = 0; i < arr.length - 1; i++)\n{\n if (taked[i] != 0)\n continue;\n\n for(var j = i + 1; j < arr.length; j++)\n {\n if (taked[j] != 0)\n continue;\n \n if (reversed(arr[i], arr[j]))\n {\n taked[i] = j; \n taked[j] = -1;\n count += 2;\n }\n }\n}\n\nvar center = -1;\nfor(var i = 0; i < arr.length; i++)\n if (taked[i] == 0)\n if (pal(arr[i]))\n {\n count++;\n center = i;\n break;\n }\n\nvar ans = \"\";\nif (center != -1)\n ans = arr[center];\n\nfor(var i = 0; i < arr.length - 1; i++)\n if (taked[i] > 0)\n ans = arr[i] + ans + arr[taked[i]];\n\nprint(count * m)\nprint(ans)", "positive_code": [{"source_code": "var palindromicPairs = {}\nvar palindromicStrings = []\nvar head = [], tail = [];\nvar input = []\nvar input1 = readline().split(' ').map((val)=>{\n return parseInt(val)\n})\nfor (var m = 0; m < input1[0];m++){\n input.push(readline())\n}\ninput.forEach((val)=>{\n var interim = val.split('').reverse().join('')\n if (interim == val){\n palindromicStrings.push(val)\n }\n else {\n if (!palindromicPairs.hasOwnProperty(val)){\n palindromicPairs[interim] = val\n }\n else{\n head.push(interim)\n tail.push(val)\n }\n }\n})\nvar res = head.join('');\nres += (palindromicStrings.length > 0) ? palindromicStrings[0] + tail.reverse().join('') : tail.reverse().join('')\nif (head.length >0 || palindromicStrings.length>0){\n print(res.length)\n print(res)\n}\nelse{\n print(0);\n print(' ')\n}\n\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var one = myconv(next(),4);\n var N = one[0];\n var M = one[1];\n var list = new Array(N);\n var output = \"\";\n for(var i = 0; i < N; i++){\n list[i] = next();\n }\n for(var i = 0; i < N; i++){\n var check = myconv(list[i],6);\n var isKaibun = true;\n //kaibun check\n for(var j = 0; j < M; j++){\n if(check[j] != check[M - j - 1]){\n isKaibun = false;\n break;\n }\n }\n if(isKaibun){\n output = list[i];\n list.splice(i,1);\n break;\n }\n }\n \n for(var i = 0; i < list.length; i++){\n var tmp = myconv(list[i],6);\n var inverse = \"\";\n //myout(tmp);\n for(var j = 0; j < M; j++){\n inverse += tmp[M - j - 1];\n }\n if(list.indexOf(inverse) != -1 && list.indexOf(inverse) != i){\n output = myconv(tmp,0) + output + inverse;\n //myout(list.length);\n list.splice(i,1);\n list.splice(list.indexOf(inverse),1);\n //myout(list.length);\n i -= 1;\n }\n }\n myout(output.length);\n myout(output);\n \n \n \n}"}], "negative_code": [{"source_code": "var palindromicPairs = {};\nvar palindromicStrings = [];\nvar head = [], tail = [];\nvar input = [];\nvar input1 = readline().split(' ').map((val)=>{\n return parseInt(val)\n})\nfor (var m = 0; m < input1[0];m++){\n input.push(readline())\n}\ninput.forEach((val)=>{\n var interim = val.split('').reverse().join('')\n if (interim == val){\n palindromicStrings.push(val)\n }\n else {\n if (!palindromicPairs.hasOwnProperty(val)){\n palindromicPairs[interim] = val\n }\n else{\n head.push(interim)\n tail.push(val)\n }\n }\n})\nvar res = head.join('')+palindromicStrings[0]+tail.reverse().join('')\nif (head.length >0 || palindromicStrings.length>0){\n print(res.length)\n print(res)\n}\nelse{\n print(0);\n print(' ')\n}"}, {"source_code": "function reversed(first, second)\n{\n var ans = true;\n for(var i = 0; i < first.length; i++)\n {\n if (first[i] != second[first.length - 1 - i])\n {\n ans = false;\n break;\n }\n }\n return ans;\n}\n\nfunction pal(str)\n{\n var half = Math.floor(str.length / 2);\n var ans = true;\n for(var i = 0; i < half; i++)\n if (str[i] != str[str.length - 1 - i])\n {\n ans = false;\n break;\n }\n return ans;\n}\n\nvar input = readline().split(\" \").map(function(x) { return parseInt(x); }); \nvar n = input[0];\nvar m = input[1];\n\nvar arr = [];\nwhile(n--)\n arr.push(readline());\n\nvar taked = Array.apply(null, Array(arr.length)).map(Number.prototype.valueOf,0);\n\nvar count = 0;\nfor(var i = 0; i < arr.length - 1; i++)\n{\n if (taked[i] != 0)\n continue;\n\n for(var j = i + 1; j < arr.length; j++)\n {\n if (taked[j] != 0)\n continue;\n \n if (reversed(arr[i], arr[j]))\n {\n taked[i] = j; \n taked[j] = -1;\n count += 2;\n }\n }\n}\n\nvar center = -1;\nfor(var i = 0; i < arr.length; i++)\n if (taked[i] == 0)\n if (pal(arr[i]))\n {\n count++;\n center = i;\n }\n\nvar ans = \"\";\nif (center != -1)\n ans = arr[center];\n\nfor(var i = 0; i < arr.length - 1; i++)\n if (taked[i] > 0)\n ans = arr[i] + ans + arr[taked[i]];\n\nprint(count * m)\nprint(ans)"}], "src_uid": "554115bec46bb436a0a1ddf8c05a2d08"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar N, indicator = 0, stock = {};\nrl.on('line', (input) => {\n if (indicator == 0) {\n let temp = input.split(\" \").map(item => parseInt(item));\n let S = temp[0], M = temp[1], L = temp[2], XL = temp[3], XXL = temp[4];\n stock = {\n \"S\": S,\n \"M\": M,\n \"L\": L,\n \"XL\": XL,\n \"XXL\": XXL\n };\n indicator++;\n }\n else if (indicator == 1) {\n N = parseInt(input);\n indicator++;\n }\n else {\n switch (input) {\n case \"S\":\n if (stock[\"S\"]) {\n console.log(\"S\");\n stock[\"S\"]--;\n }\n else if (stock[\"M\"]) {\n console.log(\"M\");\n stock[\"M\"]--;\n }\n else if (stock[\"L\"]) {\n console.log(\"L\");\n stock[\"L\"]--;\n }\n else if (stock[\"XL\"]) {\n console.log(\"XL\");\n stock[\"XL\"]--;\n }\n else {\n console.log(\"XXL\");\n stock[\"XXL\"]--;\n }\n break;\n\n case \"M\":\n if (stock[\"M\"]) {\n console.log(\"M\");\n stock[\"M\"]--;\n }\n else if (stock[\"L\"]) {\n console.log(\"L\");\n stock[\"L\"]--;\n }\n else if (stock[\"S\"]) {\n console.log(\"S\");\n stock[\"S\"]--;\n }\n else if (stock[\"XL\"]) {\n console.log(\"XL\");\n stock[\"XL\"]--;\n }\n else {\n console.log(\"XXL\");\n stock[\"XXL\"]--;\n }\n break;\n\n case \"L\":\n if (stock[\"L\"]) {\n console.log(\"L\");\n stock[\"L\"]--;\n }\n else if (stock[\"XL\"]) {\n console.log(\"XL\");\n stock[\"XL\"]--;\n }\n else if (stock[\"M\"]) {\n console.log(\"M\");\n stock[\"M\"]--;\n }\n else if (stock[\"XXL\"]) {\n console.log(\"XXL\");\n stock[\"XXL\"]--;\n }\n else {\n console.log(\"S\");\n stock[\"S\"]--;\n }\n break;\n\n case \"XL\":\n if (stock[\"XL\"]) {\n console.log(\"XL\");\n stock[\"XL\"]--;\n }\n else if (stock[\"XXL\"]) {\n console.log(\"XXL\");\n stock[\"XXL\"]--;\n }\n else if (stock[\"L\"]) {\n console.log(\"L\");\n stock[\"L\"]--;\n }\n else if (stock[\"M\"]) {\n console.log(\"M\");\n stock[\"M\"]--;\n }\n else {\n console.log(\"S\");\n stock[\"S\"]--;\n }\n break;\n\n default:\n if (stock[\"XXL\"]) {\n console.log(\"XXL\");\n stock[\"XXL\"]--;\n }\n else if (stock[\"XL\"]) {\n console.log(\"XL\");\n stock[\"XL\"]--;\n }\n else if (stock[\"L\"]) {\n console.log(\"L\");\n stock[\"L\"]--;\n }\n else if (stock[\"M\"]) {\n console.log(\"M\");\n stock[\"M\"]--;\n }\n else {\n console.log(\"S\");\n stock[\"S\"]--;\n }\n break;\n }\n }\n});", "positive_code": [{"source_code": "var n = readline().split(' ').map(Number);\nvar ans = ['S', 'M', 'L', 'XL', 'XXL'];\nvar k = +readline();\nnext: for (var i=1; i<=k; i++){\n\tvar p = readline();\n\tif (p == 'S') p = [0, 1, 2, 3, 4];\n\tif (p == 'M') p = [1, 2, 0, 3, 4];\n\tif (p == 'L') p = [2, 3, 1, 4, 0];\n\tif (p == 'XL') p = [3, 4, 2, 1, 0];\n\tif (p == 'XXL') p = [4, 3, 2, 1, 0];\n\tfor (var j=0; j<=4; j++){\n\t\tif (n[p[j]] != 0) {\n\t\t\tn[p[j]]--;\n\t\t\tprint (ans[p[j]]);\n\t\t\tcontinue next;\n\t\t}\n\t}\n}"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nvar findName = function (index) {\n switch (index) {\n case 0:\n return \"S\";\n break;\n case 1:\n return \"M\";\n break;\n case 2:\n return \"L\";\n break;\n case 3:\n return \"XL\";\n break;\n default:\n return \"XXL\";\n break;\n }\n};\nvar search = function (index) {\n if (cont[index] > 0) {\n console.log(findName(index));\n cont[index]--;\n } else if (index < 4 && cont[index + 1] > 0) {\n console.log(findName(index + 1));\n cont[index + 1]--;\n } else if (index > 0 && cont[index - 1] > 0) {\n console.log(findName(index - 1));\n cont[index - 1]--;\n } else if (index < 3 && cont[index + 2] > 0) {\n console.log(findName(index + 2));\n cont[index + 2]--;\n } else if (index > 1 && cont[index - 2] > 0) {\n console.log(findName(index - 2));\n cont[index - 2]--;\n } else if (index < 2 && cont[index + 3] > 0) {\n console.log(findName(index + 3));\n cont[index + 3]--;\n } else if (index > 2 && cont[index - 3] > 0) {\n console.log(findName(index - 3));\n cont[index - 3]--;\n } else if (index < 1 && cont[index + 4] > 0) {\n console.log(findName(index + 4));\n cont[index + 4]--;\n } else {\n console.log(findName(index - 4));\n cont[index - 4]--;\n }\n};\n\nvar cont = [],\n indicator = 0,\n n;\n/*\nwhile(true){\n string input = Console.ReadLine();\n}\n\n*/\n\nrl.on(\"line\", (input) => {\n if (indicator == 0) {\n cont = input.split(\" \").map((item) => parseInt(item));\n indicator++;\n } else if (indicator == 1) {\n n = parseInt(input);\n indicator++;\n } else {\n switch (input) {\n case \"S\":\n search(0);\n break;\n\n case \"M\":\n search(1);\n break;\n case \"L\":\n search(2);\n break;\n case \"XL\":\n search(3);\n break;\n default:\n search(4);\n break;\n }\n }\n});\n"}, {"source_code": "'use strict'\n\nlet ss = readline().split(' ').map(v => parseInt(v))\nlet N = +readline()\nlet s\n\nlet res = []\nwhile (s = readline()) {\n switch (s) {\n case 'S': s = 0; break\n case 'M': s = 1; break\n case 'L': s = 2; break\n case 'XL': s = 3; break\n case 'XXL': s = 4; break\n }\n\n let sts = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]\n for (let j = 0; j < sts.length; j++) {\n if (ss[s + sts[j]]) {\n ss[s + sts[j]]--\n res.push(s + sts[j])\n break\n }\n }\n}\n\nres = res.map(v => {\n switch (v) {\n case 0: return 'S'\n case 1: return 'M'\n case 2: return 'L'\n case 3: return 'XL'\n case 4: return 'XXL'\n }\n})\n\nres.forEach(v => print(v))"}, {"source_code": "'use strict';\n\n/*let input = `1 0 2 0 1\n3\nXL\nXXL\nM`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar storage = readline().split(' ').map(Number);\nvar n = Number(readline());\nvar sizes = [\"S\", \"M\", \"L\", \"XL\", \"XXL\"];\nfor (var i = 0; i < n; i++) {\n\tvar preference = sizes.indexOf(readline());\n\tvar j = 0;\n\twhile (true) {\n\t\tvar index = preference + Math.ceil(j / 2) * (j % 2 === 0 ? -1 : 1);\n\t\tif (index < storage.length && index >= 0 && storage[index] !== 0) {\n\t\t\tprint(sizes[index]);\n\t\t\tstorage[index]--;\n\t\t\tbreak;\n\t\t}\n\t\tj++;\n\t}\n}\n"}], "negative_code": [], "src_uid": "3c9d1de13e21ed16a7e5cbd2d67f4ce7"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction gcd(x, y) {\n if ((typeof x !== 'number') || (typeof y !== 'number')) \n return false;\n x = Math.abs(x);\n y = Math.abs(y);\n while(y) {\n var t = y;\n y = x % y;\n x = t;\n }\n return x;\n }\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let mat = new Array(n);\n for(let i = 0; i < n; i++){\n mat[i] = ti(readline().split(' '));\n }\n\n for(let i = 0; i < n; i++){\n for(let j = 1; j < m; j++){\n if(mat[i][j] < 0 && mat[i][j-1] < 0){\n mat[i][j] = -1*mat[i][j];\n mat[i][j-1] = -1*mat[i][j-1];\n }\n }\n }\n\n for(let i = 0; i < m; i++){\n for(let j = 1; j < n; j++){\n if(mat[j][i] < 0 && mat[j-1][i] < 0){\n mat[j][i] *= -1;\n mat[j-1][i] *= -1;\n }\n }\n }\n\n let count = 0;\n let min = 99999999999;\n let sum = 0;\n for(let i = 0; i < n; i++){\n for(let j = 0; j < m; j++){\n if(mat[i][j] < 0){\n count += 1;\n }\n\n min = Math.min(min, Math.abs(mat[i][j]));\n sum += Math.abs(mat[i][j]);\n }\n }\n\n if(count % 2 === 0){\n console.log(sum);\n }else{\n console.log(sum-2*min);\n }\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [rowLen, colLen] = readLine().split(\" \").map(Number);\n let [sum, min, countMinus] = [0, Infinity, 0];\n for (let row = 0; row < rowLen; row++) {\n readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n < 0) countMinus++;\n sum += Math.abs(n);\n min = Math.min(min, Math.abs(n));\n return n;\n });\n }\n if (countMinus % 2 === 1) sum -= 2 * min;\n\n console.log(sum);\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [rowLen, colLen] = readLine().split(\" \").map(Number);\n let [sum, min, foundMinus] = [0, Infinity, false];\n for (let row = 0; row < rowLen; row++) {\n readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (!foundMinus && n < 0) foundMinus = true;\n sum += Math.abs(n);\n min = Math.min(min, Math.abs(n));\n return n;\n });\n }\n if (foundMinus) sum -= 2 * min;\n\n console.log(sum);\n }\n}\n"}], "src_uid": "7fce446de3b01aff8f4aa420a92a096d"} {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\nfor (; floor.length; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.pop();\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(1);\n\t\t\tfloor.pop();\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\n\nresult.splice(0,1);\nprint(result.join(' '));", "positive_code": [{"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\nfor (; floor.length; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(1);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\n\nresult.splice(0,1);\nprint(result.join(' '));"}, {"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(1);\n\tvar List = __webpack_require__(2);\n\tvar n = parseInt(readline());\n\tvar xs = List.map(parseInt, readline().split(' '));\n\tvar result = [];\n\tvar highest = 0;\n\tfor (var i = xs.length - 1; i >= 0; i--) {\n\t result.push(Prelude_1.max(highest + 1, xs[i]) - xs[i]);\n\t highest = Prelude_1.max(highest, xs[i]);\n\t}\n\tresult = List.reverse(result);\n\tprint(result.join(\" \"));\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(1);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction maximum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximum = maximum;\n\tfunction minimum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimum = minimum;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\n\n/***/ }\n/******/ ]);"}, {"source_code": "var n = readline();\nvar h = readline().split(\" \");\nvar res = [];\nvar flag;\n// for(var i = 0; i < n; i++){\n// \tvar max = parseInt(h[i]);\n// \tfor(var j = i+1; j < n; j++){\n// \t\tflag = (parseInt(h[j]) == max) ? 1 : 0;\n// \t\tmax = (parseInt(h[j]) > max) ? parseInt(h[j]) : max;\n// \t}\n// \tvar r = (max == parseInt(h[i])) ? (flag) ? 1 : 0 : (max - parseInt(h[i]) + 1);\n// \tres.push(r);\n// }\n// print(res.join(' '));\nres = [];\nvar max = -1;\nfor(var i = n-1; i >= 0; i--){\n\tif(parseInt(h[i]) > max){\n\t\tmax = parseInt(h[i]);\n\t\tflag = 1;\n\t}\n\telse\n\t\tflag = 0;\n\tvar r = (flag) ? 0 : (max - parseInt(h[i]) + 1);\n\tres.push(r);\n}\nprint(res.reverse().join(' '));"}, {"source_code": "readline();\n\nvar line = readline();\n\nvar heights = line.split(\" \");\n\nvar n = heights.length;\n\nvar maxRight = new Array(n);\n\nmaxRight[n - 1] = 0;\n\nvar neededFloors = [];\n\nfor (var i = n - 2; i >= 0; i--) {\n maxRight[i] = Math.max(maxRight[i + 1], heights[i + 1]);\n}\n\nfor (var i = 0; i < n; i++) {\n var difference = maxRight[i] - heights[i];\n neededFloors.push(heights[i] > maxRight[i]? 0 : difference + 1);\n}\n\nprint(neededFloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function (item) {\n\treturn parseInt(item);\n})\nvar result = [];\ninput.reduceRight(function (prev, curr) {\n\tif(curr > prev){\n\t\tresult.push(0);\n\t} else if (curr === prev) {\n\t\tresult.push(1);\n\t} else {\n\t\tresult.push(prev - curr + 1);\n\t}\n\treturn Math.max(prev, curr);\n}, 0)\nresult = result.reverse();\nprint(result.join(' '));"}, {"source_code": "var n = readline();\nvar houses = readline().split(\" \");\n\nvar max = -1, L = houses.length, result = new Array(n);\nfor (var i = L-1; i>=0; --i) {\n var T = houses[i];\n result[i] = T > max ? 0 : max - T + 1;\n max = Math.max(T, max);\n}\n\nprint(result.join(\" \"));\n"}, {"source_code": "readline();\nvar houses = readline().split(\" \");\n\nvar max = -1, L = houses.length, result = [];\nfor (var i = L-1; i>=0; --i) {\n var T = houses[i];\n result.push(T > max ? 0 : max - T + 1);\n max = Math.max(T, max);\n}\n\nresult.reverse();\nprint(result.join(\" \"));\n"}, {"source_code": "n = +readline();\nh = readline().split(\" \").map(Number);\n\n\nm = [];\nm[n] = h[n] = 0;\n\nfor (var i = n-1; i >= 0; --i) {\n\t//write(i + \" = \" + h[i+1] + \", \" + m[i+1] + \"\\n\");\n\tm[i] = Math.max(h[i+1], m[i+1]);\n}\n\n\nanswer = \"\";\nfor (var i = 0; i < n; i++) {\n\tif (m[i] >= h[i]) {\n\t\tanswer += (m[i]+1 - h[i]) + \" \";\n\t} else {\n\t\tanswer += \"0 \";\n\t}\n}\n\nwrite(answer);"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\n\tif(houses[i] > houses[indexmax])\n\t{\n\t\tindexmax = i;\n\t\textrafloors.unshift(0);\n\t}\n\telse if(houses[i] == houses[indexmax])\n\t{\n\t\tif(i == indexmax)\n\t\t\textrafloors.unshift(0);\n\t\telse\n\t\t\textrafloors.unshift(1);\n\t}\n\telse\n\t\textrafloors.unshift(houses[indexmax] - houses[i] + 1);\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\nfor (; floor.length > 1; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(1);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\n\n//result.splice(0,1);\nprint(result.join(' '));"}], "negative_code": [{"source_code": "readline();\n\nvar line = readline();\n\nvar heights = line.split(\" \");\n\nvar n = heights.length;\n\nvar maxRight = new Array(n);\n\nmaxRight[n - 1] = 0;\n\nvar neededFloors = [];\n\nfor (var i = n - 2; i >= 0; i--) {\n maxRight[i] = Math.max(maxRight[i + 1], heights[i + 1]);\n}\n\nfor (var i = 0; i < n; i++) {\n var difference = maxRight[i] - heights[i];\n neededFloors.push(heights[i] > maxRight[i]? 0 : difference);\n}\n\nprint(neededFloors.join(\" \"));"}, {"source_code": "readline();\n\nvar line = readline();\n\nvar heights = line.split(\" \");\n\nvar n = heights.length;\n\nvar maxRight = new Array(n);\n\nmaxRight[n - 1] = 0;\n\nvar neededFloors = [];\n\nfor (var i = n - 2; i >= 0; i--) {\n maxRight[i] = Math.max(maxRight[i - 1], heights[i - 1]);\n}\n\nfor (var i = 0; i < n; i++) {\n var difference = maxRight[i] - heights[i];\n neededFloors.push(heights[i] > maxRight[i]? 0 : difference);\n}\n\nprint(neededFloors.join(\" \"));"}, {"source_code": "readline();\n\nvar line = readline();\n\nvar heights = line.split(\" \");\n\nvar n = heights.length;\n\nvar maxRight = new Array(n);\n\nmaxRight[n - 1] = 0;\n\nvar neededFloors = [];\n\nfor (var i = n - 2; i >= 0; i--) {\n maxRight[i] = Math.max(maxRight[i - 1], heights[i - 1]);\n}\n\nfor (var i = n - 1; i >= 0; i--) {\n var difference = maxRight[i] - heights[i];\n neededFloors.push(heights[i] < maxRight[i]? difference : 0);\n}\n\nprint(neededFloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = 0;\nvar extrafloors = [];\n\nfor(var i = n; i >= 1; i--)\n{\n\tif(houses[i] > houses[indexmax])\n\t\textrafloors.unshift(houses[indexmax] + 1 - houses[i]);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] >= houses[indexmax])\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n\telse\n\t\textrafloors.unshift(houses[indexmax] - houses[i] + 1);\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = 0;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 1; i--)\n{\n\tif(houses[i] > houses[indexmax])\n\t\textrafloors.unshift(houses[indexmax] + 1 - houses[i]);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar max = 0;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] < max)\n\t\textrafloors.unshift(max - houses[i] + 1);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tmax = houses[i];\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] > houses[indexmax])\n\t\textrafloors.unshift(houses[indexmax] + 1 - houses[i]);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] < houses[indexmax])\n\t\textrafloors.unshift(houses[indexmax] + 1 - houses[i]);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] < houses[indexmax])\n\t\textrafloors.unshift(houses[indexmax] - houses[i] + 1);\n\telse\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var n = parseInt(readline());\nvar houses = readline().split(' ').map(function(c){ return parseInt(c); });\nvar indexmax = n - 1;\nvar extrafloors = [];\n\nfor(var i = n - 1; i >= 0; i--)\n{\n\tif(houses[i] > houses[indexmax])\n\t{\n\t\textrafloors.unshift(0);\n\t\tindexmax = i;\n\t}\n\telse\n\t\textrafloors.unshift(houses[indexmax] - houses[i] + 1);\n}\n\nprint(extrafloors.join(\" \"));"}, {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\n\nfor (; floor.length; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(0);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\nresult.splice(0,1);\nprint(result.join(' '));"}, {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\nfor (; floor.length; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(0);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\n\nresult.splice(0,1);\nprint(result.join(' '));"}, {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\n\nfor (; floor.length; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor == prev_floor) {\n\t\t\tresult.unshift(0);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift(last_floor + 1 - prev_floor);\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\nresult.splice(0,1);\nprint(result.join(' '));"}, {"source_code": "var numeric = readline(),\n\t\tfloor = readline().split(' '),\n\t\tresult = [0];\n\nfor (; floor.length > 0; ) {\n\tvar last_floor = +floor[floor.length - 1],\n\t\t\tprev_floor = +floor[floor.length - 2];\n\t\n\tif (prev_floor > last_floor) {\n\t\tresult.unshift(0);\n\t\tfloor.splice(floor.length - 1, 1);\n\t} else {\n\t\tif (last_floor === prev_floor) {\n\t\t\tresult.unshift(1);\n\t\t\tfloor.splice(floor.length - 1, 1);\n\t\t} else {\n\t\t\tresult.unshift( (last_floor - prev_floor) + 1 );\n\t\tfloor.splice(floor.length - 2, 1);\n\t\t}\n\t}\n}\n\n//result.splice(0,1);\nprint(result.join(' '));"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function (item) {\n\treturn parseInt(item);\n})\nvar max = input.reduce(function (prev, curr) {\n\treturn Math.max(prev, curr);\n}, 0)\nprint(input.map(function (item) {\n\treturn (item === max) ? 0 : max - item + 1;\n}).join(' '));"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function (item) {\n\treturn parseInt(item);\n})\nvar result = [];\ninput.reduceRight(function (prev, curr) {\n\tvar max = Math.max(prev, curr);\n\tif(curr === max){\n\t\tresult.push(0);\n\t} else {\n\t\tresult.push(max - curr + 1);\n\t}\n\treturn max;\n}, 0)\nresult = result.reverse();\nprint(result.join(' '));"}], "src_uid": "e544ed0904e2def0c1b2d91f94acbc56"} {"source_code": "var s = readline().split( ' ' );\n\tn = parseInt( s[0] ),\n\tk = parseInt( s[1] );\n\t\nif (k > (n*n+1)/2) {\n\tprint( 'NO' );\n} else {\n\tprint( 'YES' );\n\tvar cur = 0;\n\tfor (var i=0; i Math.floor(n*n)/2+n%2) {\n\tprint('NO');\n}\nelse {\n\tprint('YES');\n\tfor (i = 0 ; i total )\n print(\"NO\");\nelse {\n print(\"YES\");\n var i, j, k = 0;\n for(i = 0; i < N; i ++) {\n for(j = 0; j < N; j ++) {\n if( (i + j) % 2 == 0 && k < K ) {\n write('L');\n k ++;\n } else write('S'); \n }\n print(\"\"); \n }\n}"}], "negative_code": [{"source_code": "var s = readline().split( ' ' );\n\tn = parseInt( s[0] ),\n\tk = parseInt( s[1] );\n\t\nif (k > (n+1)/2) {\n\tprint( 'NO' );\n} else {\n\tvar cur = 0;\n\tfor (var i=0; i (n+1)/2) {\n\tprint( 'NO' );\n} else {\n\tvar cur = 0;\n\tfor (var i=0; i (n*n+1)/2) {\n\tprint( 'NO' );\n} else {\n\tvar cur = 0;\n\tfor (var i=0; i Math.floor(n/2)+n%2){\n\tprint('NO');\n}\nelse {\n\tprint('Yes');\n\tprevLand = false;\n\tfor (i = 0 ; i Math.floor(n/2)+n%2){\n\tprint('NO');\n}\nelse {\n\tprint('YES');\n\tprevLand = false;\n\tfor (i = 0 ; i Math.floor(n*n)/2+k%2) {\n\tprint('NO');\n}\nelse {\n\tprint('YES');\n\tfor (i = 0 ; i {\n inputs.push(input)\n})\n\nrl.on('close', () => {\n let n = readLine()\n n = Number(n)\n for(let i=0; i 0)\n let idx = s.length-1\n for(let i=t.length-1; i>=0; i--){\n let char = t[i]\n let flag = false\n for(let j=idx; j>=0; j--){\n if(arr[j] !== 0) continue\n if(s[j] !== char){\n for(let k=j; k>=0; k--){\n if(s[k] === s[j]){\n arr[k] = -1\n }\n }\n }else{\n flag = true\n arr[j] = 1\n idx = j-1\n break\n }\n }\n if(!flag){\n console.log('NO')\n return\n }\n }\n console.log('YES')\n}\n\n", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n // your code goes here\r\n \r\nvar t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n\r\n let mp = new Map();\r\n let mp1 = new Map();\r\n\r\n let [ch, ch1] = readline().trim().split(\" \");\r\n\r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.has(ch[i]))\r\n mp.set(ch[i], mp.get(ch[i]) + 1);\r\n else\r\n mp.set(ch[i], 1);\r\n }\r\n\r\n for (let i = 0; i < ch1.length; i++) {\r\n if (mp1.has(ch1[i]))\r\n mp1.set(ch1[i], mp1.get(ch1[i]) + 1);\r\n else\r\n mp1.set(ch1[i], 1);\r\n }\r\n\r\n let s = \"\";\r\n\r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.get(ch[i]) <= mp1.get(ch[i]))\r\n s += ch[i];\r\n else\r\n mp.set(ch[i], mp.get(ch[i]) - 1);\r\n }\r\n\r\n //console.log(\"map size \", mp.size);\r\n\r\n if (s === ch1)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n}\r\n\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n // your code goes here\r\n \r\nvar t = parseInt(readline());\r\n \r\nwhile (t--) {\r\n \r\n let mp = new Map();\r\n let mp1 = new Map();\r\n \r\n let [ch, ch1] = readline().trim().split(\" \");\r\n \r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.has(ch[i]))\r\n mp.set(ch[i], mp.get(ch[i]) + 1);\r\n else\r\n mp.set(ch[i], 1);\r\n }\r\n \r\n for (let i = 0; i < ch1.length; i++) {\r\n if (mp1.has(ch1[i]))\r\n mp1.set(ch1[i], mp1.get(ch1[i]) + 1);\r\n else\r\n mp1.set(ch1[i], 1);\r\n }\r\n \r\n let s = \"\";\r\n \r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.get(ch[i]) <= mp1.get(ch[i]))\r\n s += ch[i];\r\n else\r\n mp.set(ch[i], mp.get(ch[i]) - 1);\r\n }\r\n \r\n //console.log(\"map size \", mp.size);\r\n \r\n if (s === ch1)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n}}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(s, t) {\r\n const map = new Map();\r\n\r\n for (let i = 0; i < t.length - 1; i++) {\r\n var _map$get;\r\n\r\n const c = t[i];\r\n map.set(c, ((_map$get = map.get(c)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n\r\n for (let i = s.length - 1, j = t.length - 1; i >= 0; i--) {\r\n if (s[i] === t[j]) {\r\n j--;\r\n map.set(t[j], map.get(t[j]) - 1);\r\n } else {\r\n if (map.get(s[i])) return false;\r\n }\r\n\r\n if (j === -1) return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 1; __ <= _; __++) {\r\n const [s, t] = inputs[__].trim().split(' ');\r\n\r\n console.log(solve(s, t) ? 'YES' : 'NO');\r\n }\r\n}();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n // your code goes here\r\n\r\n let t = parseInt(readline());\r\n\r\n while (t--) {\r\n\r\n let mp = new Map();\r\n let mp1 = new Map();\r\n\r\n let [ch, ch1] = readline();\r\n\r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.has(ch[i]))\r\n mp.set(ch[i], mp.get(ch[i]) + 1);\r\n else\r\n mp.set(ch[i], 1);\r\n }\r\n\r\n for (let i = 0; i < ch1.length; i++) {\r\n if (mp1.has(ch1[i]))\r\n mp1.set(ch1[i], mp1.get(ch1[i]) + 1);\r\n else\r\n mp1.set(ch1[i], 1);\r\n }\r\n\r\n let s = \"\";\r\n\r\n for (let i = 0; i < ch.length; i++) {\r\n if (mp.get(ch[i]) <= mp1.get(ch[i]))\r\n s += ch[i];\r\n else\r\n mp.set(ch[i], mp.get(ch[i]) - 1);\r\n }\r\n\r\n //console.log(\"map size \", mp.size);\r\n\r\n if (s == ch1)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n\r\n\r\n}\r\n"}], "src_uid": "d4b6505799f21d3147b9c1a0604b88b6"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\nfunction stringArrayToBigInts(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( BigInt(array[i]) );\n }\n return result;\n}\n\n// ======================================================\n// A. Shuffle Hashing\n// https://codeforces.com/problemset/problem/1278/A\n// ======================================================\n\n// Convert p to array. Sort the array then convert it back to a string.\nfunction _process(str) {\n var arr = str.split('');\n arr.sort();\n return arr.join('');\n}\n\nfunction doIt( p, h ) {\n\n //printALine(\"P=\" + p + \" H=\" + h);\n var processedP = _process(p);\n //printALine(\" Processed P=\" + processedP);\n \n for( var i = 0; i < h.length; i++ ) {\n var str = h.substring(i, i + p.length); \n var processedStr = _process(str);\n //printALine(\" Substring=\" + str + \" Processed=\" + processedStr);\n if( processedStr == processedP ) {\n return \"YES\"; \n }\n }\n \n return \"NO\";\n \n}\n\nfunction main() {\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var string2 = readALine();\n var result = doIt( string1, string2 );\n printALine(result);\n }\n \n}\n\n\n\n\n\n", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet index = 0;\nlet p = '', h = '';\n\nreadline.on('line', line => {\n if (index++) {\n if (!p) {\n p = line;\n return;\n } else {\n h = line;\n let tmp = p, flag = false;\n for(let i = 0, j = 0; i < h.length; ) {\n let ind = tmp.indexOf(h[i]);\n if (ind != -1) {\n tmp = tmp.slice(0, ind) + tmp.slice(ind + 1);\n if (!tmp.length) flag = true;\n i++;\n } else {\n tmp = p;\n j++;\n i = j;\n }\n }\n if (flag) console.log(\"YES\");\n else console.log(\"NO\");\n }\n p = '';\n }\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t, p, h, sorted, answer, substring;\n\nt = Number(readline());\n\nfunction check (array1, array2) {\n\n if ((array1.length == array2.length) && array1.every(function(element, index) {\n return element === array2[index]})) {return true} else {return false}\n}\n\nfor (i = 0; i < t; i++) { //Loop each test\n\n p = readline().replace(/\\r$/, '');\n h = readline().replace(/\\r$/, '');\n answer = \"NO\";\n sorted = p.split('').sort();\n\n for (k = 0; k < h.length - p.length + 1; k++) { //\n\n for (j = 0; j < h.length; j++) {\n substring = h.substr(j, p.length).split('').sort();\n\n if (check(substring, sorted)) {\n answer = \"YES\";\n break;\n }\n }\n }\n\n print(answer);\n}"}, {"source_code": "var t = parseInt(readline(), 10),\n p = [],\n h = [];\n\nfor(var i=1; i<=t; i++) {\n p = readline().split('').sort();\n h = readline().split('');\n \n var demo_p = [], demo_p_sort = [];\n \n for(var j=0; j=p.length-1) {\n demo_p_sort = [...demo_p].sort();\n \n if(demo_p_sort.join('') === p.join('')) {\n print('YES');\n break;\n } else if(j === h.length - 1) print('NO');\n else demo_p.shift();\n \n } else if(j === h.length - 1) print('NO');\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n // wr(j)\n let p = arr[2 * j]\n const h = arr[2 * j + 1]\n\n const pa = p.split('')\n const ha = h.split('')\n\n const pl = p.length, hl = h.length\n p = pa.sort().join('')\n let flag = false\n\n for(let i = 0; i < hl - pl + 1; i++) {\n let t = h.substr(i, pl)\n t = t.split('').sort().join('')\n if(t == p) {\n flag = true\n break\n }\n }\n flag ? wr('YES') : wr('NO')\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n"}], "negative_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr[0])\n\n const a = arr[1].split(' ').map(a => parseInt(a))\n\n let ans = 1\n if(n == 1) {\n console.log(1)\n return\n }\n for(let i = 1; i < n; i++) {\n if(n >= 2 && a[i] >= a[i - 1] && (i + 1) % 2 == 0) ans = max(ans, 2)\n if(i >= 3 && n >= 4 && a[i] >= a[i - 1] && a[i - 1] >= a[i - 2] && a[i - 2] >= a[i - 3] && (i + 1) % 4 == 0) ans = max(ans, 4)\n if(i >= 7 && n >= 8 && a[i] >= a[i - 1] && a[i - 1] >= a[i - 2] && a[i - 2] >= a[i - 3] && a[i - 3] >= a[i - 4] && a[i - 4] >= a[i - 5] && a[i - 5] >= a[i - 6] && a[i - 6] >= a[i - 7] && (i + 1) % 8 == 0) ans = max(ans, 8)\n let flag = true\n if(i == 15) {\n for(let j = 1; j < n; j++) {\n if(a[j] < a[j - 1]) {\n flag = false\n break\n }\n }\n }\n if(flag && i == 15) {\n ans = 16\n }\n }\n wr(ans)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n"}], "src_uid": "48151011c3d380ab303ae38d0804176a"} {"source_code": ";(function () {\n\n\tprint(function (y, k, n) {\n\t\tvar r = [], l = 0;\n\n\t\twhile (++l * k <= n)\n\t\t\tif (l*k > y)\n\t\t\t\tr.push( l*k - y);\n\n\t\tif (!r.length) return -1;\n\t\telse return r.join(' ');\n\t}.apply(0, readline().split(' ').map(Number)));\n\n}).call(this);", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => inputString += inputStd);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n solve();\n});\nlet readLine = () => inputString[currentLine++];\n\nfunction solve(){\n let y, k, n;\n let line = readLine().split(' ').map(Number);\n y = line[0], k = line[1], n = line[2];\n let arr = [];\n\n for(let i = k; i <= n; i += k){\n if(i-y > 0) arr.push(i-y);\n }\n if(arr.length) \n for(let i of arr) \n process.stdout.write(`${i} `);\n else \n console.log(-1);\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const [y, k, n] = readLine().split(\" \").map(Number);\n const result = [];\n for (let i = 1; i * k <= n; i++) {\n const num = k * i;\n if (num > y) {\n result.push(num - y);\n }\n }\n if (result.length) console.log(result.join(\" \"));\n else console.log(-1);\n}\n"}, {"source_code": "print(function(y, k, n) {\n\tvar i,ans = [];\n\tfor (i = k; i <= n; i += k)\n\t\tans.push(i);\n\n\tans = ans.map(function(v) {\n\t\treturn v - y;\n\t}).filter(function(v) {\n\t\treturn v >= 1;\n\t});\n\n\tif (ans.length === 0) return -1;\n\treturn ans.join(' ');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(y, k, n) {\n\tvar i,\n\t\tans = [];\n\n\tfor (i = k * Math.ceil(y / k) - y, l = n - y; i <= l; i += k)\n\t\tif (i >= 1) ans.push(i);\n\n\tif (ans.length === 0) return -1;\n\treturn ans.join(' ');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(y, k, n) {\n\n\tvar ans = [];\n\tfor (var i = k, l = Math.min(1e9,n); i <= l; i+=k)\n\t\tans.push(i);\n\n\tans = ans.map(function(v) {\n\t\treturn v - y;\n\t}).filter(function(v) {\n\t\treturn v >= 1;\n\t});\n\n\tif(ans.length===0) return -1;\n\treturn ans.join(' ');\n\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\ty = data[0], k = data[1], n = data[2],\n\t\tresult = [];\n\tfor (var sum = Math.ceil((y+1)/k)*k; sum <= n; sum += k) {\n\t\tresult.push(sum-y);\n\t}\n\tif (result.length == 0) {\n\t\tprint(-1);\n\t} else {\n\t\tprint(result.join(' '));\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => inputString += inputStd);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n solve();\n});\nlet readLine = () => inputString[currentLine++];\n\nfunction solve(){\n let y, k, n;\n let line = readLine().split(' ').map(Number);\n y = line[0], k = line[1], n = line[2];\n let arr = [];\n\n for(let i = k*2; i <= n; i += k){\n if(i-y > 0) arr.push(i-y);\n }\n if(arr.length) \n for(let i of arr) \n process.stdout.write(`${i} `);\n else \n console.log(-1);\n}\n"}, {"source_code": "print(function(y, k, n) {\n\n\tvar ans = [];\n\tfor (var i = 1, l = Math.min(1e5,n); i <= l; i++)\n\t\tif (i % k === 0) ans.push(i);\n\n\tans = ans.map(function(v) {\n\t\treturn v - y;\n\t}).filter(function(v) {\n\t\treturn v >= 1;\n\t});\n\n\tif(ans.length===0) return -1;\n\treturn ans.join(' ');\n\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(y, k, n) {\n\tvar i,\n\t\tans = [];\n\n\tif (y === k) return -1;\n\tfor (i = k * Math.ceil(y / k) - y, l = n - y; i <= l; i += k)\n\t\tans.push(i);\n\n\tif (ans.length === 0) return -1;\n\treturn ans.join(' ');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(y, k, n) {\n\tvar i,\n\t\tans = [];\n\n\tfor (i = k * Math.ceil(y / k) - y, l = n - y; i <= l; i += k)\n\t\tans.push(i);\n\n\tif (ans.length === 0) return -1;\n\treturn ans.join(' ');\n\n} .apply(0, readline().split(' ').map(Number)));"}], "src_uid": "2deda3a05740e1184735bf437e3850a8"} {"source_code": "const t = Number(readline());\r\n\r\nfor (i = 0; i < t; i++) {\r\n currentImage = readline() + readline();\r\n\r\n uniqueColors = new Set(currentImage.split(''));\r\n nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n print(nrOfUniqueColors - 1);\r\n}\r\n", "positive_code": [{"source_code": "var t = Number(readline())\n\nfor (var i=0; i inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n for (let test = 0; test < N; test++) {\r\n let pixels = readline().split('').concat(readline().split(''));\r\n let freq = {};\r\n\r\n for (let i = 0; i < 4; i++) {\r\n if (freq[pixels[i]]) {\r\n freq[pixels[i]]++;\r\n } else {\r\n freq[pixels[i]] = 1;\r\n }\r\n }\r\n\r\n output(Object.keys(freq).length - 1);\r\n }\r\n}\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let x=line[2*i-1];\r\n let y=line[2*i];\r\n let a=new Array(4);\r\n a[0]=x[0].charCodeAt();\r\n a[1]=x[1].charCodeAt();\r\n a[2]=y[0].charCodeAt();\r\n a[3]=y[1].charCodeAt();\r\n a.sort(function(x,y) {\r\n return x-y;\r\n })\r\n if(a[0]===a[3]) console.log(0);\r\n else if((a[0]==a[1]&&a[0]==a[2])||(a[1]==a[2]&&a[1]==a[3])) console.log(1);\r\n else if((a[0]==a[1])&&(a[2]==a[3])) console.log(1);\r\n else if((a[0]==a[1])||(a[1]==a[2])||(a[2]==a[3])) console.log(2);\r\n else console.log(3);\r\n }\r\n})"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines.slice(l, l + 2).map(str => str.trim())\n l += 2\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const map = {}\n update(arr[0][0])\n update(arr[0][1])\n update(arr[1][0])\n update(arr[1][1])\n const ks = Object.keys(map)\n if (ks.length === 1) {\n return 0\n } else if (ks.length === 2) {\n return 1\n } else if (ks.length === 3) {\n return 2\n } else if (ks.length === 4) {\n return 3\n }\n function update(ch) {\n map[ch] = (map[ch] || 0) + 1\n }\n}\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n // let n = parseInt(readline())\r\n let l1 = readline()\r\n let l2 = readline()\r\n console.log( solve(l1, l2) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (l1, l2) => {\r\n let colors = (l1+l2).split('')\r\n let unique = uniqueArray( colors ) \r\n\r\n // if( unique.length == 1 ) return 0\r\n // if( unique.length == 2 ) return 1\r\n // if( unique.length == 3 ) return 2\r\n // if( unique.length == 4 ) return 3\r\n\r\n return unique.length - 1\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "var readline=require('readline')\r\nvar r1=readline.createInterface({\r\n input:process.stdin,\r\n output:process.stdout\r\n})\r\nvar i=0\r\nvar t;\r\nvar a,b,c,d;\r\nr1.question('',function (x){t=parseInt(x);test();})\r\nasync function test(){\r\n r1.question('',function (x){\r\n a=x[0]\r\n b=x[1]\r\n r1.question('',function (x){\r\n c=x[0]\r\n d=x[1]\r\n if(a!==b&&a!==c&&a!==d&&b!==c&&b!==d&&c!==d)\r\n console.log('3\\n')\r\n else if(a===b&&b===c&&c===d)\r\n console.log('0\\n')\r\n else if((a===b&&b===c)||(a===b&&b===d)||(a===c&&d===c)||(d===b&&b===c))\r\n console.log('1\\n')\r\n else if((a===b&&c===d)||(a===c&&b===d)||(a===d&&b===c))\r\n console.log('1\\n')\r\n else\r\n console.log('2\\n')\r\n i++;\r\n if(i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 134 (Div. 2)\n2022-08-26\n\nA. Image\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n for (let tc = 0; tc < t; tc++) {\n const colors = new Set();\n\n // INPUT: two rows with 2 colors each\n let row = readline();\n colors.add(row.charAt(0));\n colors.add(row.charAt(1));\n row = readline();\n colors.add(row.charAt(0));\n colors.add(row.charAt(1));\n\n console.log(colors.size - 1);\n }\n}\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var [n, k] = readline().split('')//.map((x) => parseInt(x));\r\n var [a, b] = readline().split('')//.map((x) => parseInt(x));\r\n var s = a+b+n+k;\r\n // console.log(s)\r\n var cnt = {\r\n [a]: 0,[b]:0,[n]:0,[k]:0\r\n }\r\n for(var i=0;i<4;i++) cnt[s[i]]++;\r\n var num = [];\r\n \r\n var ct = [0,0,0,0,0];\r\n for(var i=0;i<4;i++) {\r\n if(!s.slice(i+1, 4).includes(s[i])) ct[cnt[s[i]]]+=1\r\n }\r\n // console.log(cnt, ct)\r\n if(ct[4]) console.log(0);\r\n else if(ct[3]||ct[2]>1) console.log(1)\r\n else if(ct[2]) console.log(2);\r\n else console.log(3)\r\n\r\n}\r\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n // const arr1 = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const arr2 = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const line1 = readLine().trim()\n const line2 = readLine().trim()\n const color1 = line1[0]\n const color2 = line1[1]\n const color3 = line2[0]\n const color4 = line2[1]\n\n let mySet = new Set()\n mySet.add(color1)\n mySet.add(color2)\n mySet.add(color3)\n mySet.add(color4)\n\n if (mySet.size == 4) {\n console.log(3)\n } else if (mySet.size == 3) {\n console.log(2)\n } else if (mySet.size == 2) {\n console.log(1)\n } else if (mySet.size == 1) {\n console.log(0)\n }\n }\n\n\n // ws.end();\n}\n"}, {"source_code": "let readline = require(\"readline\");\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n let set = new Set();\r\n\r\n for (let i = 1; i < input.length; i += 2) {\r\n let colors = input[i].split(\"\");\r\n set.add(colors[0]);\r\n set.add(colors[1]);\r\n colors = input[i + 1].split(\"\");\r\n set.add(colors[0]);\r\n set.add(colors[1]);\r\n\r\n if (set.size === 1) console.log(0);\r\n if (set.size === 4) console.log(3);\r\n if (set.size === 2) console.log(1);\r\n if (set.size === 3) console.log(2);\r\n set.clear();\r\n }\r\n};\r\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const ab = readLine();\r\n const cd = readLine();\r\n let result = myFunc(ab[0], ab[1], cd[0], cd[1]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n \r\n let set = new Set();\r\n set.add(a);\r\n set.add(b);\r\n set.add(c);\r\n set.add(d);\r\n\r\n if(set.size == 1) return 0;\r\n if(set.size == 2) return 1;\r\n if(set.size == 3) return 2;\r\n if(set.size == 4) return 3;\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let s = sc.S() + sc.S();\r\n // console.log(`s = ${s}`);\r\n\r\n let count = 0, map = new Map();\r\n for (let ch of s)\r\n {\r\n if (!map.has(ch))\r\n {\r\n ++count;\r\n map.set(ch, 1);\r\n }\r\n }\r\n\r\n console.log(count - 1);\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = sc.N();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [a, b] = input[index].split(\"\");\n index++;\n const [c, d] = input[index].split(\"\");\n const testCase = {\n a: [a, b, c, d],\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { a } = testCase;\n // console.log(a);\n\n const dict = {};\n a.forEach((v) => {\n if (!dict[v]) dict[v] = 0;\n dict[v]++;\n });\n\n const b = Object.values(dict).sort((c, d) => c - d);\n // console.error(b);\n\n console.log(b.length - 1);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "negative_code": [{"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\n// print(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\nfor (i = 0; i < t; i++) {\r\n // const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n currentImage = readline() + readline();\r\n print(currentImage);\r\n\r\n uniqueColors = new Set(currentImage.split(''));\r\n nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n // console.log(nrOfUniqueColors - 1);\r\n print(nrOfUniqueColors - 1);\r\n}\r\n"}, {"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\n// print(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\nfor (i = 0; i < t; i++) {\r\n // const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n const currentImage = readline() + readline();\r\n print(currentImage);\r\n\r\n const uniqueColors = new Set(currentImage.split(''));\r\n const nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n // console.log(nrOfUniqueColors - 1);\r\n print(nrOfUniqueColors - 1);\r\n}\r\n"}, {"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\n// print(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\nfor (i = 0; i < t; i++) {\r\n // const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n const currentImage = readline() + readline();\r\n // print(5);\r\n\r\n const uniqueColors = new Set(currentImage.split(''));\r\n const nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n // console.log(nrOfUniqueColors - 1);\r\n print(nrOfUniqueColors - 1);\r\n}\r\n"}, {"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\nprint(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\n// for (let i = 0; i < t; i++) {\r\n// const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n// const currentImage = readline() + readline();\r\n// print(5);\r\n\r\n// const uniqueColors = new Set(currentImage.split(''));\r\n// const nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n// console.log(nrOfUniqueColors - 1);\r\n// // print(nrOfUniqueColors - 1);\r\n// }\r\n\r\nfor (i = 0; i < t; i++) {\r\n print(t);\r\n}\r\n"}, {"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\nprint(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\n// for (let i = 0; i < t; i++) {\r\n// const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n// const currentImage = readline() + readline();\r\nprint(5);\r\n\r\n// const uniqueColors = new Set(currentImage.split(''));\r\n// const nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n// console.log(nrOfUniqueColors - 1);\r\n// // print(nrOfUniqueColors - 1);\r\n// }\r\n"}, {"source_code": "const t = Number(readline());\r\n// const t = Number('5');\r\nprint(t);\r\n\r\n// const inputValues = ['rb', 'br', 'cc', 'wb', 'aa', 'aa', 'ab', 'cd', 'yy', 'xx'];\r\n\r\n// for (let i = 0; i < t; i += 1) {\r\n// const currentImage = inputValues[i * 2] + inputValues[i * 2 + 1];\r\n// // const currentImage = readline() + readline();\r\n\r\n// const uniqueColors = new Set(currentImage.split(''));\r\n// const nrOfUniqueColors = [...uniqueColors].length;\r\n\r\n// console.log(nrOfUniqueColors - 1);\r\n// // print(nrOfUniqueColors - 1);\r\n// }\r\n"}, {"source_code": "var repeatTimes = readline();\r\n\r\nwhile (repeatTimes--) {\r\n var str1 = readline()\r\n var str2 = readline()\r\n var set1 = new Set()\r\n set1.add(str1[0])\r\n set1.add(str1[1])\r\n set1.add(str2[0])\r\n set1.add(str2[1])\r\n print(set1.size)\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const lines = input.trim().split('\\n');\r\n for (let i = 1; i < lines.length; i += 2) {\r\n const colors = (lines[i] + lines[i + 1]).split('');\r\n const colorSet = new Set(colors);\r\n process.stdout.write(String(colorSet.size - 1) + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 2) {\n const colors = (lines[i] + lines[i + 1]).split('');\n const colorSet = new Set(colors);\n process.stdout.write(String(colorSet.size - 1) + '\\n');\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 2) {\n const colors = (lines[i] + lines[i + 1]).split('');\n const colorSet = new Set(colors);\n console.log(String(colorSet.size - 1));\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 2) {\n const colors = (lines[i] + lines[i + 1]).split('');\n const colorSet = new Set(colors);\n console.log(colorSet.size - 1);\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n for (let test = 0; test < N; test++) {\r\n let pixels = readline().split('').concat(readline().split(''));\r\n let freq = {};\r\n\r\n for (let i = 0; i < 4; i++) {\r\n if (freq[pixels[i]]) {\r\n freq[pixels[i]]++;\r\n } else {\r\n freq[pixels[i]] = 1;\r\n }\r\n }\r\n\r\n const count = Object.keys(freq).length;\r\n let values = Object.keys(freq).map(key => freq[key]);\r\n\r\n if (count === 1) {\r\n output(0);\r\n } else if (count === 2) {\r\n if (values.includes(3)) {\r\n output(3);\r\n } else {\r\n output(2);\r\n }\r\n } else if (count === 3) {\r\n output(3);\r\n } else if (count === 4) {\r\n output(4);\r\n }\r\n }\r\n}\r\n"}], "src_uid": "a9143235c8e2b6b188ea3fc8a90f0c80"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let b = readline().split('').map(Number);\r\n\r\n let ans = 0;\r\n let count = 2;\r\n for (let c of b) {\r\n if (c === 1) count++;\r\n else {\r\n ans += Math.max(2 - count, 0);\r\n count = 0;\r\n }\r\n }\r\n\r\n output(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var s = lines[i].split('').map(Number);\n\t var ans = 0;\n\t for(j = 0; j < n; j++){\n\t if(s[j] == 1){\n\t continue;\n\t }\n\t if(j < n - 1 && s[j + 1] === 0){\n\t ans += 2;\n\t }else if(j < n - 2 && s[j + 1] == 1 && s[j + 2] === 0){\n\t ans++;\n\t }\n\t }\n\t console.log(ans);\n\t }\n\t}\n});\n\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) { \r\n\r\n const n = readLine();\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n\r\n\r\nfunction main(a){\r\n let ans = 0;\r\n let cnt = 2;\r\n for (let index = 0; index < a.length; index++) {\r\n if(a[index] == 1){\r\n cnt++;\r\n } else{\r\n ans += Math.max(2 - cnt,0);\r\n cnt = 0;\r\n }\r\n }\r\n return ans;\r\n}\r\n"}, {"source_code": "// problems/contest1658/A/src/ts/solution.ts\nvar lines = [];\nrequire(\"readline\").createInterface({\n input: process.stdin\n}).on(\"line\", (line) => lines.push(line));\nprocess.stdin.on(\"end\", () => {\n main(lines);\n});\nfunction main(lines2) {\n let i = 0;\n for (let t = Number(lines2[i++]); t > 0; t--) {\n const n = Number(lines2[i++]);\n const s = lines2[i++];\n console.log(solve(n, s));\n }\n}\nfunction solve(n, s) {\n let res = 0;\n let p = -1;\n for (let i = 0; i < n; i++) {\n if (s[i] === \"0\") {\n if (p >= 0) {\n if (p + 1 === i)\n res += 2;\n else if (p + 2 === i)\n res += 1;\n }\n p = i;\n }\n }\n return res;\n}\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = Number(inputs[0])\r\nfor (let _ = 0, __ = 1; _ < N; _++) {\r\n const n = Number(inputs[__++]),\r\n data = inputs[__++]\r\n main(n, data)\r\n}\r\n\r\nfunction main(n, data) {\r\n let res = 0\r\n for (let i = 1; i < n; i++) {\r\n if (data[i - 1] === '0') {\r\n if (data[i] === '0') res += 2\r\n else if (data[i] === '1' && i + 1 !== n && data[i + 1] !== '1') res++\r\n }\r\n }\r\n console.log(res)\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let ans = 0\n let prev\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '0') {\n if (prev >= 0) {\n ans += Math.max(0, 3 - (i - prev))\n }\n prev = i\n }\n }\n return ans\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = next();\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(S[i] == \"0\" && S[i + 1] == \"0\"){\r\n\t\t\t\toutput += 2;\r\n\t\t\t}else if(i > 0 && S[i - 1] == \"0\" && S[i] == \"1\" && S[i + 1] == \"0\"){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\nINPUT\r\n9\r\n3\r\n000\r\n3\r\n001\r\n3\r\n010\r\n3\r\n011\r\n3\r\n100\r\n3\r\n101\r\n3\r\n110\r\n3\r\n111\r\n19\r\n1010110000100000101\r\n*/\r\n\r\nvar t = Number(readline());\r\n\r\nfor(var i = 0; i < t; i++) {\r\n readline();\r\n var s = readline();\r\n\r\n var lastZero = -Infinity;\r\n var total = 0;\r\n\r\n for(var j = 0; j < s.length; j++) {\r\n if(s[j] == '0') {\r\n if(lastZero == j - 1) {\r\n total += 2;\r\n }\r\n if(lastZero == j - 2) {\r\n total += 1;\r\n }\r\n lastZero = j;\r\n }\r\n }\r\n\r\n print(total);\r\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=line[0];\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let ans=0;\r\n let cnt=0;\r\n let sum=0;\r\n for(let i=0;i1)\r\n {\r\n if(cnt<2)\r\n {\r\n ans+=2-cnt;\r\n }\r\n }\r\n cnt=0;\r\n }\r\n else\r\n {\r\n cnt++;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (n, line)=>{\n let pos = -1;\n let res = 0;\n for (let i = 0; i < n; i++) {\n if (line[i] === '0') {\n if (pos === -1) {\n pos = i;\n continue;\n }\n let diff = i - pos;\n if (diff > 2) {\n pos = i;\n continue;\n }\n res += 2 - diff + 1; \n pos = i;\n }\n }\n return res;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let line = readline();\n console.log(`${calc(n, line)}`);\n }\n}\n\n\n\n"}], "negative_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n console.log(1);\r\n setTimeout(()=>{\r\n console.log(3);\r\n },1000);\r\n console.log(2);\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n console.log(1);\r\n setTimeout(()=>{\r\n console.log(3);\r\n },100);\r\n console.log(2);\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n console.log(1);\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('read', function(){\r\n const {EOL}=requrie('os');\r\n let line=buf.split(EOL);\r\n console.log(1);\r\n setTimeout(()=>{\r\n console.log(3);\r\n },100);\r\n console.log(2);\r\n})"}, {"source_code": "const lines = [];\r\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\r\nrl.on('line', line => lines.push(line));\r\nrl.on('close', main);\r\nlet rli = 0;\r\nfunction readline() {\r\n return lines[rli++];\r\n}\r\n\r\nconst ra = ()=>readline().split(' ').map(a=>+a);\r\n\r\nfunction div(val, by){\r\n return (val - val % by) / by;\r\n}\r\n\r\n\r\nconst calc = (n, line)=>{\r\n let pos = -1;\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (line[i] === '0') {\r\n if (pos === -1) {\r\n pos = i;\r\n continue;\r\n }\r\n let diff = i - pos;\r\n if (diff > 2) {\r\n pos = i;\r\n continue;\r\n }\r\n res += 2 - diff + 1; \r\n pos = i;\r\n }\r\n }\r\n return res;\r\n};\r\n\r\nfunction main() {\r\n let T = +readline();\r\n for (let t = 1; t <= T; t++){\r\n let n = +readline();\r\n let line = readline();\r\n console.log(`Case #${t}: ${calc(n, line)}`);\r\n }\r\n}\r\n\r\n\r\n\r\n"}], "src_uid": "9966bfdc9677a9dd558684a00977cd58"} {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var index = 1;\r\n for (var a = 0; a < t; a++) {\r\n var [n, u, v] = input[index].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n index++;\r\n var arr = input[index].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n index++;\r\n var min = Infinity;\r\n for (var i = 1; i < arr.length; i++) {\r\n if (Math.abs(arr[i] - arr[i - 1]) > 1) {\r\n min = 0;\r\n } else if (Math.abs(arr[i] - arr[i - 1]) === 1) {\r\n min = Math.min(min, u, v);\r\n } else {\r\n min = Math.min(min, u + v, v + v);\r\n }\r\n }\r\n console.log(min);\r\n }\r\n \r\n})", "positive_code": [{"source_code": "main = () => {\r\n\tallans=[];\r\n\tt=readInt();\r\n\tfor (_=0;_1){\r\n\t\t\t\thaveLargeGap=true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse if (gap===1) haveOneGap=true;\r\n\t\t}\r\n\t\tif (haveLargeGap) allans.push(0);\r\n\t\telse if (haveOneGap) allans.push(Math.min(u,v));\r\n\t\telse allans.push(v+Math.min(u,v));\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n}\r\n\r\nreadInt = () => parseInt(readline());\r\nreadString = () => readline();\r\nreadIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\noneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nmultiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nmultiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, u, v] = iInpArr();\r\n let arr = iInpArr();\r\n let flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] !== arr[i + 1]) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) {\r\n console.log(v + Math.min(u, v));\r\n continue;\r\n }\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (Math.abs(arr[i] - arr[i + 1]) >= 2) {\r\n console.log(0);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) console.log(Math.min(u, v));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var ans = false\r\n for (let i = 0; i < n - 1; i++) {\r\n if (Math.abs(a[i] - a[i + 1]) > 1) ans = true\r\n }\r\n // console.log('ansans')\r\n // console.log(ans)\r\n // console.log(a)\r\n if (ans) return console.log(0)\r\n\r\n var existOne = false\r\n for (let i = 0; i < n - 1; i++) {\r\n if (Math.abs(a[i] - a[i + 1]) === 1) existOne = true\r\n }\r\n\r\n if (existOne) return console.log(Math.min(u, v))\r\n\r\n var min1 = v + v\r\n var min2 = u + v\r\n console.log(Math.min(min1, min2))\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, u, v] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mxdf = 0;\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tmxdf = Math.max(mxdf, Math.abs(a[i] - a[i-1]));\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tif (mxdf >= 2) \r\n\t\t\tans = 0;\r\n\t\telse if (mxdf == 1) {\r\n\t\t\tans = Math.min(u, v);\r\n\t\t} else {\r\n\t\t\tans = v + Math.min(u, v);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n \r\n for (var i = 0; i < testCasesNum; i++) {\r\n var nuv = readNumArray();\r\n var u = nuv[1];\r\n var v = nuv[2];\r\n var arr = readNumArray();\r\n var diff = maxDiff(arr);\r\n if (diff === 2) {\r\n print(0);\r\n }\r\n if (diff === 1) {\r\n print(Math.min(u, v));\r\n }\r\n if (diff === 0) {\r\n print(v + Math.min(u, v));\r\n }\r\n }\r\n}\r\n\r\nfunction maxDiff(arr) {\r\n var max = 0;\r\n for (var j = 1; j < arr.length; j++) {\r\n var diff = Math.abs(arr[j] - arr[j - 1]);\r\n if (diff > max) {\r\n if (diff > 1) {\r\n return 2;\r\n }\r\n max = diff;\r\n }\r\n }\r\n return max;\r\n}\r\nmain();"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, u, v] = iInpArr();\r\n let arr = iInpArr();\r\n let flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] !== arr[i + 1]) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) {\r\n console.log(u + v);\r\n continue;\r\n }\r\n flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (Math.abs(arr[i] - arr[i + 1]) >= 2) {\r\n console.log(0);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) console.log(Math.min(u, v));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, u, v] = iInpArr();\r\n let arr = iInpArr();\r\n let flag = false;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] !== arr[i + 1]) {\r\n console.log(Math.min(u, v));\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) console.log(u + v);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var ans = false\r\n for (let i = 0; i < n - 1; i++) {\r\n if (Math.abs(a[i] - a[i + 1]) > 1) ans = true\r\n }\r\n // console.log('ansans')\r\n // console.log(ans)\r\n // console.log(a)\r\n if (ans) return console.log(0)\r\n\r\n var existOne = false\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] - a[i + 1] === 1) existOne = true\r\n }\r\n\r\n if (existOne) return console.log(Math.min(u, v))\r\n\r\n var min1 = v + v\r\n var min2 = u + v\r\n console.log(Math.min(min1, min2))\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n \r\n for (var i = 0; i < testCasesNum; i++) {\r\n var nuv = readNumArray();\r\n var u = nuv[1];\r\n var v = nuv[2];\r\n var arr = readNumArray();\r\n var diff = maxDiff(arr);\r\n if (diff === 2) {\r\n print(0);\r\n }\r\n if (diff === 1) {\r\n print(Math.min(u, v));\r\n }\r\n if (diff === 0) {\r\n print(u + v);\r\n }\r\n }\r\n}\r\n\r\nfunction maxDiff(arr) {\r\n var max = 0;\r\n for (var j = 1; j < arr.length; j++) {\r\n var diff = Math.abs(arr[j] - arr[j - 1]);\r\n if (diff > max) {\r\n if (diff > 1) {\r\n return 2;\r\n }\r\n max = diff;\r\n }\r\n }\r\n return max;\r\n}\r\nmain();"}], "src_uid": "7f502f2fd150a2ded948826960d123cd"} {"source_code": "var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\nvar tt = num[0]; // to store values in different variables.\nvar i;\nfor (i = 0; i < tt; i++) {\n var num2 = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n var atefeh = num2[0];\n var behzad = num2[1];\n print(atefeh+behzad)\n}\n", "positive_code": [{"source_code": "var n = readline().split(' ');\n\nfor (var i = 0; i < n; i++) {\n var line = readline().split(' ');\n var x = parseInt(line[0]), y = parseInt(line[1]);\n print(x+y);\n}"}, {"source_code": "var print = this.print || require(\"lol-io\").print;\nvar write = this.write || require(\"lol-io\").write;\nvar readline = this.readline || require(\"lol-io\").readline;\nvar n = readline();\nvar i=0;\nwhile (i < n) {\n a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\n print(a[0]+a[1])\n i++;\n}\n"}, {"source_code": "t=readline();\nwhile(t--){\n\ta=readline().split(\" \");\n\tprint(+a[0] + +a[1]);\n}"}, {"source_code": "var n = Number(readline())\nfor(var i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const result = readLine().split(' ').map(x=> parseInt(x)).reduce((prev, curr)=> curr + prev, 0)\n console.log(result)\n }\n return;\n}\n"}, {"source_code": "var l = readline().split(' ');\n \nwhile(l[0]--)\n{\n var line = readline().split(' ');\n print(parseInt(line[0]) + parseInt(line[1]));\n}"}, {"source_code": "t = readline();\n\nwhile (t--) {\n a = readline().split(' ');\n // JUST TESTING STRING INTERPOLATION\n ans = `${+a[0] + +a[1]}`;\n print(ans);\n \n}"}, {"source_code": "var t = readline();\nwhile (t--) {\n\tvar a = readline().split(\" \").map(Number);\n\tprint(a[0] + a[1]);\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar tmp = nextIntArray();\n\t\toutput[i] = tmp[0] + tmp[1];\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n console.log(a + b);\n\n c++;\n});\n"}, {"source_code": "t = readline();\nwhile (t--) {\n\ta = readline().split(\" \").map(Number);\n\tprint(a[0] + a[1]);\n}"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n console.log(a+b)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nfunction doline(t) {\n rl.question(\"\", ab => {\n console.log(ab.split(\" \").reduce((a,b) => a+Number(b),0))\n t == 1 ? rl.close():doline(t-1)\n })\n}\n\nrl.question(\"\", t => doline(Number(t)))\n"}, {"source_code": "raw_input = '';\nprocess.stdin.on('data', input => raw_input += input.toString());\nprocess.stdin.on('end', () => main());\n\nfunction main() {\n const lines = raw_input.split('\\n');\n T = +lines[0];\n for (i = 1; i <= T; i++) {\n [a, b] = lines[i].split(' ').map(i => +i);\n console.log(a + b);\n }\n}"}, {"source_code": "t = readline();\n\nwhile (t--) {\n // JUST TESTING MAP ARROW FUNCTION SYNTAX\n a = readline().split(' ').map(x => +x);\n print(a[0] + a[1]);\n}"}, {"source_code": "t = readline();\nwhile (t--) {\n\ta = readline().split(' ');\n\tprint(+a[0] + +a[1]);\n}"}, {"source_code": "var Case = Number(readline());\nwhile(Case--){\n\tvar s = readline().split(\" \");\n var a = Number(s[0]);\n var b = Number(s[1]);\n print(a+b);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nvar inputString=\"\";\nvar currentLine=0;\n\nprocess.stdin.on('data',function(data){\n\tinputString+=data;\n});\nprocess.stdin.on('end',function(){\n\t inputString=inputString.split('\\n');\n\t main();\n});\n\nfunction readline(){\n\treturn inputString[currentLine++];\n}\nfunction main(){\n\tvar n=readline();\n\tfor(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n//----------------------------------------------\n\nfunction yourFunction(arr) {\n return arr[0] + arr[1];\n}\n\n//----------------------------------------------\n\nfunction main() {\n\n const n = parseInt(readLine(), 10);\n for (var i = 0; i < n; i++) {\n const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));\n\n let result = yourFunction(arr);\n\n console.log(result);\n }\n}"}], "negative_code": [{"source_code": "var l = readline().split(' ');\nvar line = readline().split(' ');\n\nwhile(l[0]--)\nprint(parseInt(line[0]) + parseInt(line[1]));"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const result = parseInt(readLine(), 10) + parseInt(readLine(), 10);\n console.log(result)\n }\n return;\n}\n"}, {"source_code": "raw_input = '';\nprocess.stdin.on('data', input => raw_input += input.toString());\nprocess.stdin.on('end', () => main());\n\nfunction main() {\n const lines = raw_input.split('\\n').slice(1);\n lines.forEach(line => {\n [a, b] = line.split(' ').map(i => +i);\n console.log(a + b);\n });\n}"}, {"source_code": "function yourFunction(a,b) {\n return a+b;\n}"}, {"source_code": "'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n//----------------------------------------------\n\nfunction yourFunction(arr) {\n return arr[0] + arr[1];\n}\n\n//----------------------------------------------\n\nfunction main() {\n\n // const n = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));\n\n let result = yourFunction(arr);\n\n console.log(result);\n}"}], "src_uid": "27ddccc777ef9040284ab6314cbd70e7"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = await readInt();\r\n rl.output.write(`? 1\\n`);\r\n await readInt();\r\n const res = new Array(n + 1);\r\n let total = 1;\r\n const cycle = new Array(n + 1);\r\n let ncycle = 0;\r\n for (let i = 1; i <= n; i++) {\r\n if (!res[i]) {\r\n if (i===n) {\r\n res[n] = n;\r\n break;\r\n }\r\n ncycle = 0;\r\n const beforeTotal = total;\r\n while (true) {\r\n rl.output.write(`? ${i}\\n`);\r\n // console.log(`? ${i}`);\r\n const val = await readInt();\r\n total++;\r\n if (res[val])\r\n break;\r\n res[val] = true;\r\n cycle[ncycle] = val;\r\n ncycle++;\r\n }\r\n let cur = i;\r\n for (let j = (beforeTotal - 1) % ncycle, cnt = 1; cnt <= ncycle + 1; cnt++, j = (j + 1) % ncycle) {\r\n res[cur] = cycle[j];\r\n cur = res[cur];\r\n }\r\n }\r\n }\r\n\r\n rl.output.write(`! ${res.slice(1).join(' ')}\\n`)\r\n }\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n input = yield 1\n const t = +input\n for (let i = 0; i < t; i++) {\n input = yield 1\n const n = +input\n yield* solve(n)\n }\n process.exit(0)\n}\n\nfunction* solve(n) {\n const ans = Array(n).fill(-1)\n for (let i = 0; i < n; i++) {\n if (ans[i] >= 0) continue\n\n const map = {}\n const arr = []\n while (1) {\n const x = yield* ask(i + 1)\n if (map[x]) break\n\n map[x] = 1\n arr.push(x)\n }\n // the next of `x` is `px`\n for (let j = 0; j < arr.length; j++) {\n ans[arr[j] - 1] = arr[(j + 1) % arr.length]\n }\n }\n console.log(`! ${ans.join(' ')}`)\n}\nfunction* ask(i) {\n console.log(`? ${i}`)\n const x = yield 1\n return +x\n}\n"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = await readInt();\r\n console.log(`? 1`);\r\n await readInt();\r\n const res = new Array(n + 1);\r\n let total = 1;\r\n const cycle = new Array(n + 1);\r\n let ncycle = 0;\r\n for (let i = 1; i <= n; i++) {\r\n if (!res[i]) {\r\n if (i===n) {\r\n res[n] = n;\r\n break;\r\n }\r\n ncycle = 0;\r\n const beforeTotal = total;\r\n while (true) {\r\n console.log(`? ${i}`);\r\n const val = await readInt();\r\n total++;\r\n if (res[val])\r\n break;\r\n res[val] = true;\r\n cycle[ncycle] = val;\r\n ncycle++;\r\n }\r\n let cur = i;\r\n for (let j = (total - 2) % ncycle, cnt = 1; cnt <= ncycle; cnt++, j = (j + 1) % ncycle) {\r\n res[cur] = cycle[j];\r\n cur = res[cur];\r\n }\r\n }\r\n }\r\n\r\n console.log(`! ${res.slice(1).join(' ')}`)\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = await readInt();\r\n const res = new Array(n + 1);\r\n let total = 0;\r\n const cycle = new Array(n + 1);\r\n let ncycle = 0;\r\n for (let i = 1; i <= n; i++) {\r\n if (!res[i]) {\r\n ncycle = 0;\r\n const beforeTotal = total;\r\n while (true) {\r\n console.log(`? ${i}`);\r\n const val = await readInt();\r\n total++;\r\n if (res[val])\r\n break;\r\n res[val] = true;\r\n cycle[ncycle] = val;\r\n ncycle++;\r\n }\r\n let cur = i;\r\n for (let j = (total - 1) % ncycle, cnt = 1; cnt <= ncycle; cnt++, j = (j + 1) % ncycle) {\r\n res[cur] = cycle[j];\r\n cur = res[cur];\r\n }\r\n }\r\n }\r\n\r\n console.log(`! ${res.slice(1).join(' ')}`)\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const n = await readInt();\r\n const res = new Array(n+1);\r\n let total = 0;\r\n const cycle = new Array(n + 1);\r\n const was = new Array(n+1);\r\n let ncycle = 0;\r\n for(let i = 1; i <= n; i++) {\r\n if (!res[i]) {\r\n ncycle = 0;\r\n const beforeTotal = total;\r\n while (true) {\r\n console.log(`? ${i}`);\r\n const val = await readInt();\r\n total++;\r\n if (res[val])\r\n break;\r\n res[val] = true;\r\n cycle[ncycle] = val;\r\n ncycle++;\r\n }\r\n let cur = i;\r\n for(let j = (total - 1)%ncycle, cnt=1; cnt<=ncycle; cnt++, j=(j+1)%ncycle) {\r\n res[cur] = cycle[j];\r\n cur = res[cur];\r\n }\r\n }\r\n }\r\n\r\n console.log(`! ${res.slice(1).join(' ')}`)\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "96ec983bfadc9e96e36ebb8ffc5279d3"} {"source_code": "'use strict'\n\nreadline();\nconst x = [ 'a' ], d = [];\nreadline().split('').forEach(c => {\n let i = 0;\n while (c < x[i]) if (++i === x.length) x.push(c);\n x[i] = c;\n d.push(i+1);\n})\nprint(`${Math.max(...d)}\\n${d.join(' ')}`)\n", "positive_code": [{"source_code": "'use strict'\n\nreadline();\nconst x = [ 'a' ], d = [];\n\nreadline().split('').forEach(c => {\n let i = 0, j = x.length - 1, m;\n if (c < x[j]) j++;\n else if (c >= x[i]) j = i;\n else while(i !== (m = (i + j) >> 1)) if (c < x[m]) i = m; else j = m;\n\n x[j] = c;\n d.push(j+1);\n})\nprint(`${Math.max(...d)}\\n${d.join(' ')}`)\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, s) => {\n const d = { a: [], b: [], c: [], d: [], e: [], f: [], g: [], h: [], i: [], j: [], k: [], l: [], m: [], n: [], o: [], p: [], q: [], r: [], s: [], t: [], u: [], v: [], w: [], x: [], y: [], z: [] }\n s.forEach((i, j) => d[i].push(j));\n const t = 'abcdefghijklmnopqrstuvwxyz'.split('').filter(i => d[i].length).map(i => d[i]);\n const c = [];\n let a = -1, b = -1;\n\n for (let i = 0; i < t.length; i++) {\n const x = t[i];\n if (x[0] < b) return 'NO';\n\n let j = -1;\n\n while(++j < x.length && x[j] < a) c[x[j]] = 0; j--;\n if (c[x[j]] === 0 && b < x[j]) b = x[j];\n\n while (++j < x.length) c[x[j]] = 1; j--;\n if (c[x[j]] === 1 && a < x[j]) a = x[j];\n };\n return `YES\\n${c.join('')}`;\n}\nprint(problem(+readline(), readline().split('')));\n"}], "src_uid": "2e9da3333792a57e9e3bba4c75542ce7"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const cost = getInts()\n const words = []\n const wordsRev = []\n const INF = Number.MAX_SAFE_INTEGER\n\n for (let i = 0; i < n; ++i) {\n const w = getLine()[0]\n words.push(w)\n wordsRev.push(reve(w))\n }\n\n words.push(words[n - 1])\n wordsRev.push(wordsRev[n - 1])\n\n const dp = [[cost[0], 0]]\n for (let i = 1; i <= n; ++i) {\n dp.push([INF, INF])\n\n if (wordsRev[i - 1] <= wordsRev[i]) {\n dp[i][0] = dp[i - 1][0] + cost[i]\n }\n\n if (wordsRev[i - 1] <= words[i]) {\n dp[i][1] = dp[i - 1][0]\n }\n\n if (words[i - 1] <= wordsRev[i]) {\n dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0]) \n }\n\n if (words[i - 1] <= words[i]) {\n dp[i][1] = Math.min(dp[i][1], dp[i - 1][1]) \n }\n }\n\n let ans = Math.min(dp[n - 1][0], dp[n - 1][1])\n print(ans !== INF ? ans : -1)\n}\n\nfunction reve(w) {\n return w.split('').reverse().join('')\n}", "positive_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const cost = getInts()\n const words = []\n const INF = Number.MAX_SAFE_INTEGER\n\n for (let i = 0; i < n; ++i) {\n const w = getLine()[0]\n words.push(w)\n }\n\n words.push(words[n - 1])\n\n let ok = true\n const dp = [[cost[0], 0]]\n for (let i = 1; i <= n; ++i) {\n let found = false\n dp.push([INF, INF])\n\n if (reve(words[i - 1]) <= reve(words[i])) {\n dp[i][0] = dp[i - 1][0] + cost[i]\n found = true\n }\n\n if (reve(words[i - 1]) <= words[i]) {\n dp[i][1] = dp[i - 1][0]\n found = true\n }\n\n if (words[i - 1] <= reve(words[i])) {\n dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0]) \n found = true\n }\n\n if (words[i - 1] <= words[i]) {\n dp[i][1] = Math.min(dp[i][1], dp[i - 1][1]) \n found = true\n }\n\n if (!found) ok = false\n }\n\n let ans = Math.min(dp[n - 1][0], dp[n - 1][1])\n print(ok && ans !== INF ? ans : -1)\n}\n\nfunction reve(w) {\n return w.split('').reverse().join('')\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const cost = getInts()\n const words = []\n\n for (let i = 0; i < n; ++i) {\n const w = getLine()[0]\n words.push(w)\n }\n\n words.push(words[n - 1])\n\n let ok = true\n const dp = [[cost[0], 0]]\n for (let i = 1; i <= n; ++i) {\n let found = false\n dp.push([1e10, 1e10])\n\n if (reve(words[i - 1]) <= reve(words[i])) {\n dp[i][0] = dp[i - 1][0] + cost[i]\n found = true\n }\n\n if (reve(words[i - 1]) <= words[i]) {\n dp[i][1] = dp[i - 1][0]\n found = true\n }\n\n if (words[i - 1] <= reve(words[i])) {\n dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0]) \n found = true\n }\n\n if (words[i - 1] <= words[i]) {\n dp[i][1] = Math.min(dp[i][1], dp[i - 1][1]) \n found = true\n }\n\n if (!found) ok = false\n }\n\n let ans = Math.min(dp[n - 1][0], dp[n - 1][1])\n print(ok ? ans : -1)\n}\n\nfunction reve(w) {\n return w.split('').reverse().join('')\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const cost = getInts()\n const words = []\n const INF = Number.MAX_SAFE_INTEGER\n\n for (let i = 0; i < n; ++i) {\n const w = getLine()[0]\n words.push(w)\n }\n\n words.push(words[n - 1])\n\n let ok = true\n const dp = [[cost[0], 0]]\n for (let i = 1; i <= n; ++i) {\n let found = false\n dp.push([INF, INF])\n\n if (reve(words[i - 1]) <= reve(words[i])) {\n dp[i][0] = dp[i - 1][0] + cost[i]\n found = true\n }\n\n if (reve(words[i - 1]) <= words[i]) {\n dp[i][1] = dp[i - 1][0]\n found = true\n }\n\n if (words[i - 1] <= reve(words[i])) {\n dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0]) \n found = true\n }\n\n if (words[i - 1] <= words[i]) {\n dp[i][1] = Math.min(dp[i][1], dp[i - 1][1]) \n found = true\n }\n\n if (!found) ok = false\n }\n\n let ans = Math.min(dp[n - 1][0], dp[n - 1][1])\n print(ok ? ans : -1)\n}\n\nfunction reve(w) {\n return w.split('').reverse().join('')\n}"}], "src_uid": "91cfd24b8d608eb379f709f4509ecd2d"} {"source_code": "// var inputString = \"5\\n2 4\\n2 2\\n2 3\\n2 3\\n2 1\\n\";\n\n// var readline = (function () {\n// var regex = /(.+)\\s/g,\n// i = 0;\n\n// return function () {\n// return inputString.match(regex)[i++].replace(/\\n/g, \"\");\n// }\n// })();\n\n// function write (token) {\n// console.log(token);\n// }\n// function print (token) {\n// console.log(token);\n// }\n\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar days = parseInt(readline(), 10);\n\nvar meatNeed = [],\n price = [];\n\nvar tempInput = \"\";\nfor (var i = 0; i < days; i++) {\n tempInput = readline().split(\" \");\n price.push(parseInt(tempInput.pop(), 10));\n meatNeed.push(parseInt(tempInput.pop(), 10));\n}\n\nvar minPrice = {};\nminPrice.price = Math.min.apply(null, price);\nminPrice.day = price.indexOf(minPrice.price);\n\nvar minSum = 0;\n\nvar i = 0;\nwhile (i < days) {\n if (price[i] < price[i+1]) {\n var j = i;\n while (price[i] <= price[j]) {\n minSum += price[i] * meatNeed[j];\n j++;\n }\n i = j;\n } else {\n minSum += price[i] * meatNeed[i];\n i++;\n }\n}\n\nwrite(minSum);\n", "positive_code": [{"source_code": "a=[],p=[], mm=[]\nn=Number(readline())\nfor (var i=0; i p) {\n m = p;\n }\n\n s += a * m;\n}\n\nwrite(s);\n"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\n\nvar result = 0;\nfor (let i = 0, pmin = +Infinity; i < n; ++i) {\n let input = readline().split(' ').map(value => +value);\n let a = input[0];\n let p = input[1];\n\n pmin = Math.min(pmin, p);\n\n result += a * pmin;\n}\n\nwrite(result);\n"}, {"source_code": "var n = Number(readline());\nvar inp;\nvar min = 101;\nvar sum = 0;\nfor(var i = 0; i < n ; i++){\n inp = readline().split(\" \").map(cur => Number(cur));\n (inp[1] < min) ? min = inp[1] : null; \n sum += min*inp[0];\n}\n\nprint(sum);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\nlet minPrice = Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, p] = d.split(' ').map(Number);\n\n if (a && p) {\n minPrice = Math.min(minPrice, p);\n ans += a * minPrice;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n \n let [meat, cost] = input[1].split(' ').map(x => parseInt(x));\n let answer = meat*cost;\n\n for (let i = 2; i <= n; i += 1) {\n const pair = input[i].split(' ').map(x => parseInt(x));\n if (pair[1] < cost) {\n cost = pair[1];\n }\n answer += pair[0] * cost;\n }\n\n console.log(answer);\n});"}, {"source_code": "//Input\n// ai pi 1 <= ai, pi <= 100\n// var n = \"3\"; var arr = [\"1 3\", \"2 2\", \"3 1\"]; // 10\n// var n = \"3\"; var arr = [\"1 3\", \"2 2\", \"3 2\"]; // 8\n// var n = \"1\"; var arr = [\"39 52\"]; // 2028\n// var n = \"2\"; var arr = [\"125 56\", \"94 17\"]; // 2998\n// var n = \"5\"; var arr = [\"39 213\", \"95 89\", \"70 90\", \"9 55\", \"85 32\"]; // 6321\n// var n = \"12\"; var arr = [\"70 11\", \"74 27\", \"32 11\", \"26 83\", \"57 18\", \"97 28\", \"75 43\", \"75 21\", \"84 29\", \"16 2\", \"89 63\", \"21 88\"]; // 6742\n\nvar n = readline();\n\n// retorno = eval(n, arr);\nretorno = eval(n);\n\n//Solution\n// function eval(n, arr){\nfunction eval(n){\n n = parseInt(n);\n var daysCosts = new Array(n+1).join(\"\").split(\"\");\n\n var arr = \"\";\n for(var i = 0 ; i < n ; i++){\n arr = readline();\n daysCosts[i] = arr.split(\" \").map(function(x){ return parseInt(x)});\n // daysCosts[i] = arr[i].split(\" \").map(function(x){ return parseInt(x)});\n };\n write(giveTheLowestCost(n, daysCosts));\n // console.log(giveTheLowestCost(n, daysCosts));\n};\n\nfunction giveTheLowestCost(n, daysCosts){\n var answer;\n var minimumCost = 0;\n var totalCost = 0;\n //console.log(daysCosts[0]);\n for(var i = 0 ; i < n ; i++){\n if(i == 0){\n minimumCost = daysCosts[i][1];\n totalCost = daysCosts[i][0]*daysCosts[i][1];\n //console.log(\"minimumCost: \" + minimumCost + \" totalCost: \" + totalCost);\n //console.log(\"dayCosts[\" + i + \"][1]: \" + daysCosts[i][1] + \" minimumCost: \" + minimumCost);\n } else{\n if(minimumCost > daysCosts[i][1]){\n minimumCost = daysCosts[i][1];\n };\n totalCost += daysCosts[i][0]*minimumCost;\n //console.log(\"dayCosts[\" + i + \"][1]: \" + daysCosts[i][1] + \" minimumCost: \" + minimumCost);\n };\n };\n\n //console.log(\"minimumCost: \" + minimumCost + \" totalCost: \" + totalCost);\n return totalCost;\n};\n\n\n"}, {"source_code": "function cmp(x){\n\treturn parseInt(x);\n}\nvar n = parseInt(readline());\n\tvar a = [];\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\ta[i] = readline().split(\" \").map(cmp);\n\t}\n\t//var a = [[1,3],[2,1],[3,2]];\n\tvar minimum = 200;\n\tvar sum = 0;\n\tfor(var j = 0; j < n; j ++)\n\t{\n\t\tif(a[j][1] < minimum)\n\t\tminimum = a[j][1];\n\t\tsum += minimum*a[j][0];\n\t}\n\tprint(sum);"}, {"source_code": "var n = readline();///.split(\" \");\nvar str = []; //readline().split(\" \"); \"3 3\".split(\" \"),\"3 3\".split(\" \"),\"3 3\".split(\" \")\nvar min = 100;\nvar sum = 0;\n\t\tfor (var i=0; i<+n; i++){\n\t\t\tstr.push(readline().split(\" \"));\n\t\t}\n\t\t\n\t\tfor (var i=0; i<+n; i++){\n\t\t if (+str[i][1] result - total * p[prev] + total * p[i]) {\n result = result - total * p[prev] + total * p[i];\n prev = i;\n }\n total -= a[i];\n }\n\n print(result);\n}\n\nmain();"}, {"source_code": "n=Number(readline())\na=new Array(n), p=new Array(n), mm=new Array(n)\nfor (var i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, p] = d.split(' ').map(Number);\n\n ans += a * p;\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\nlet minPrice = Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, p] = d.split(' ').map(Number);\n minPrice = Math.min(minPrice, p);\n\n ans += a * minPrice;\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var n = parseInt(readline());\n\tvar a = [];\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\ta[i] = readline().split(\" \").map(function(elment){return parseInt(elment);});\n\t}\n\t\n\t//var a=[[1,3],[2,1],[3,2]];\n\tvar minimum = 200;\n\tvar temp;\n\tfor(var j = 0; j < n; j++)\n\t{\n\t\tminimum = Math.min(minimum,a[j][1]);\n\t}\n\tfor(var k = 0; k < n; k++)\n\t{\n\t\tif(minimum === a[k][1])\n\t\t{\n\t\t\ttemp = k;\n\t\t\tbreak;\n\t\t}\n\t}\n\tvar ans=0;\n\tfor(var l = 0; l <= temp; l++)\n\t{\n\t\tans += a[l][0]*a[l][1]; \n\t}\n\tfor(var u = temp+1; u < n; u++)\n\t{\n\t\tans += a[u][0]*minimum;\n\t}\n\tprint(ans);"}, {"source_code": "var n = readline();///.split(\" \");\nvar str = []; //readline().split(\" \");\nvar min = 100;\nvar sum = 0;\n\t\tfor (var i=0; i<+n; i++){\n\t\t\tstr.push([readline().split(\" \")]);\n\t\t}\n\t\t\n\t\tfor (var i=0; i<+n; i++){\n\t\t if (+str[i][1] result - total * p[i - 1] + total * p[i]) {\n result = result - total * p[i - 1] + total * p[i];\n }\n total -= a[i];\n }\n\n print(result);\n}\n\nmain();"}, {"source_code": "// var inputString = \"3\\n1 3\\n2 1\\n3 2\\n\";\n\n// var readline = (function () {\n// var regex = /(.+)\\s/g,\n// i = 0;\n\n// return function () {\n// return inputString.match(regex)[i++].replace(/\\n/g, \"\");\n// }\n// })();\n\n// function write (token) {\n// console.log(token);\n// }\n// function print (token) {\n// console.log(token);\n// }\n\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar days = parseInt(readline(), 10);\n\nvar meatNeed = [],\n price = [];\n\nvar tempInput = \"\";\nfor (var i = 0; i < days; i++) {\n tempInput = readline().split(\" \");\n price.push(parseInt(tempInput.pop(), 10));\n meatNeed.push(parseInt(tempInput.pop(), 10));\n}\n\nvar minPrice = {};\nminPrice.price = Math.min.apply(null, price);\nminPrice.day = price.indexOf(minPrice.price);\n\nvar minSum = 0;\n\nfor (var i = 0; i < days; i++) {\n if (i < minPrice.day) {\n minSum += meatNeed.shift() * price.shift();\n } else {\n minSum += meatNeed.reduce(function (sum, cur) {\n return sum + cur * minPrice.price;\n }, 0) * minPrice.price;\n break;\n }\n}\n\nwrite(minSum);\n"}, {"source_code": "// var inputString = \"5\\n5 5\\n4 4\\n3 3\\n2 2\\n2 2\\n\";\n\n// var readline = (function () {\n// var regex = /(.+)\\s/g,\n// i = 0;\n\n// return function () {\n// return inputString.match(regex)[i++].replace(/\\n/g, \"\");\n// }\n// })();\n\n// function write (token) {\n// console.log(token);\n// }\n// function print (token) {\n// console.log(token);\n// }\n\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar days = parseInt(readline(), 10);\n\nvar meatNeed = [],\n price = [];\n\nvar tempInput = \"\";\nfor (var i = 0; i < days; i++) {\n tempInput = readline().split(\" \");\n price.push(parseInt(tempInput.pop(), 10));\n meatNeed.push(parseInt(tempInput.pop(), 10));\n}\n\nvar minPrice = {};\nminPrice.price = Math.min.apply(null, price);\nminPrice.day = price.indexOf(minPrice.price);\n\nvar minSum = 0;\n\nfor (var i = 0; i < days; i++) {\n if (i < minPrice.day) {\n minSum += meatNeed.shift() * price.shift();\n } else {\n minSum += meatNeed.reduce(function (sum, cur) {\n return sum + cur * minPrice.price;\n }, 0);\n break;\n }\n}\n\nwrite(minSum);\n"}], "src_uid": "28e0822ece0ed35bb3e2e7fc7fa6c697"} {"source_code": "var filter = function(value, index, self){\n if (value === 0) return false;\n else if (value > levels) return false;\n else return self.indexOf(value) == index;\n};\n\nvar levels = parseInt(readline());\n\nvar m1 = readline().split(' ').map(parseFloat);\nm1.splice(0,1);\n\nvar m2 = readline().split(' ').map(parseFloat);\nm2.splice(0,1);\n\nvar result = m1.concat(m2).filter(filter);\n\nprint((result.length === levels) ? 'I become the guy.' : 'Oh, my keyboard!');", "positive_code": [{"source_code": "var n = parseInt(readline(), 10);\nvar p = readline().split(' ').map(el => parseInt(el, 10));\nvar q = readline().split(' ').map(el => parseInt(el, 10));\n\np.shift();\nq.shift();\n\nvar comboArray = [...new Set([...p, ...q])].sort((a,b) => a-b);\n\nprint((comboArray.length === n) ? \"I become the guy.\" : \"Oh, my keyboard!\");"}, {"source_code": "var tok=null;\nvar index=0;\nfunction next(){\n while(tok==null || index==tok.length){\n tok=readline().split(' ');\n index=0;\n }\n var res=tok[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction check(s){\n arrS=s.split(\" \");\n for(var i=1; iarr[t-1]) {\nnamU += 1;\n}\n}\nif (namU == N) {\nprint ('I become the guy.');\n} else {\nprint ('Oh, my keyboard!');\n}"}, {"source_code": "var n = parseInt(readline());\n\nvar ap = readline().split(' ');\nvar aq = readline().split(' ');\n\nap[0] = -1;\nap.sort((a, b) => a-b);\n\naq[0] = -1;\naq.sort((a, b) => a-b);\n\nvar passable = true;\nvar i = 1;\nvar ip = 1;\nvar iq = 1;\n\nfor (i = 1; i <= n; i++) {\n if (ap[ip] < i) {\n ip++;\n }\n if (aq[iq] < i) {\n iq++;\n }\n if (ap[ip] != i && aq[iq] != i) {\n passable = false;\n break;\n }\n}\n\nif (passable) {\n write(\"I become the guy.\");\n} else {\n write(\"Oh, my keyboard!\");\n}"}, {"source_code": "var line = readline();\nvar n = parseInt(line);\n\nvar x = readline().split(' ').map(Number);\nvar p = x[0];\n\nvar y = readline().split(' ').map(Number);\nvar q = y[0];\n\nvar array=[];\n\nfor(i=0;i0){\n\tlevels+=1;\n }\n}\n\n//print(levels);\n\nif(levels===n){\n print('I become the guy.');\n} else{\n print('Oh, my keyboard!');\n}"}, {"source_code": "var n = +readline();\nvar input;\n\ninput = readline().split(' ');\nvar X = input.slice(1);\n\ninput = readline().split(' ');\nvar Y = input.slice(1);\n\nwrite(new Set(X.concat(Y)).size === n ? 'I become the guy.' : 'Oh, my keyboard!');"}, {"source_code": "var noLevels = parseInt(readline());\n \nvar xLevels = readline().split(\" \").map(function(x) { return parseInt(x) });\n \nvar yLevels = readline().split(\" \").map(function(y) { return parseInt(y) });\n \n// Remove number of levels\nxLevels.splice(0, 1);\nyLevels.splice(0, 1);\n \n// Remove duplicates\n\nvar res = xLevels.concat(yLevels);\nvar allLevelSet = new Set(xLevels.concat(yLevels));\n\n\nif (noLevels == allLevelSet.size)\n print(\"I become the guy.\");\n\nelse\n print(\"Oh, my keyboard!\");"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n alist.shift();\n var blist = nextIntArray();\n blist.shift();\n var pass = new Set();\n for(var i = 0; i < alist.length; i++){\n if(alist[i] != 0){\n pass.add(alist[i]);\n }\n }\n for(var i = 0; i < blist.length; i++){\n if(blist[i] != 0){\n pass.add(blist[i]);\n }\n }\n if(pass.size == N){\n myout(\"I become the guy.\");\n }else{\n myout(\"Oh, my keyboard!\");\n }\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `4\n// 3 1 2 3\n// 2 2 3`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n const res = readLine(stdin, currentLine);\n const resSet = new Set();\n\n while (2 > currentLine) {\n ++currentLine;\n const levels = readLine(stdin, currentLine)\n .split(\" \")\n .splice(1);\n\n levels.forEach(l => resSet.add(l));\n }\n\n console.log(resSet.size == res ? \"I become the guy.\" : \"Oh, my keyboard!\");\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": " var numberOfLevel = Number(readline())\n var levelAcomplished = new Array(numberOfLevel).fill(0)\n\n var infoPlayerA = readline().split(' ').map(Number)\n var infoPlayerB = readline().split(' ').map(Number)\n\n var levelAcomplishedByPlayerA = infoPlayerA[0]\n for (var i = 1; i <= levelAcomplishedByPlayerA; i++) {\n var level = infoPlayerA[i]\n levelAcomplished[level - 1] += 1\n }\n\n var levelAcomplishedByPlayerB = infoPlayerB[0]\n for (var i = 1; i <= levelAcomplishedByPlayerB; i++) {\n var level = infoPlayerB[i]\n levelAcomplished[level - 1] += 1\n }\n\n var allLevelAccomplished = true\n for (var i = 0; i < levelAcomplished.length; i++) {\n if (levelAcomplished[i] === 0) {\n allLevelAccomplished = false\n break;\n }\n }\n\n if (allLevelAccomplished) {\n print('I become the guy.')\n } else {\n print('Oh, my keyboard!')\n }"}, {"source_code": "var num_games = parseInt(readline());\nvar x = readline().split(\" \").map(x=>parseInt(x));\nvar y = readline().split(\" \").map(x=>parseInt(x));\nvar total = [...new Set([...x.splice(1),...y.splice(1)])];\nif(total.length == num_games){\n print(\"I become the guy.\");\n}else{\n print(\"Oh, my keyboard!\")\n}"}, {"source_code": "var n = Number(readline());\nvar s1 = readline().split(\" \");\nvar s2 = readline().split(\" \");\nvar obj = {};\nfor(var i=1; i {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = [];\n\n for (let i = 1; i <= n; i++) {\n expected.push(i)\n }\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n if (levels.toString() == expected.toString())\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n result %= mod;\n n--\n return factorial(n, result)\n }\n return result\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice().split(' ').map(x => parseInt(x));\nX.shift();\nvar Y = readline().slice().split(' ').map(x => parseInt(x));\nY.shift();\nvar set = new Set([...X,...Y]);\nif (set.size === n && Math.max(...set) === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice().split(' ').map(x => parseInt(x));\nX.shift();\nvar Y = readline().slice().split(' ').map(x => parseInt(x));\nY.shift();\nvar set = new Set([...X,...Y]);\nif (set.has(1) && set.size === n && Math.max(...set) === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n\n"}, {"source_code": "var n = Number(readline());\nvar s1 = readline().split(\" \");\nvar s2 = readline().split(\" \");\nvar obj = {};\nfor(var i=1; i {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n if (c === 1) {\n a = d.split(' ').map(Number);\n c++;\n return;\n }\n\n b = d.split(' ').map(Number);\n\n c++;\n});\n\nrl.on('close', () => {\n const obj = {};\n let ans = 'I become the guy.';\n\n c = a.concat(b);\n\n c = c.sort((x, y) => x - y);\n\n let count = 0;\n for(let i = 0 ; i < a.length+b.length; i++) {\n if(c[i] != c[i+1]){\n count++;\n }\n }\n\n for (let i = 1; i < a.length; i++) {\n obj[a[i]] = true;\n }\n\n for (let i = 1; i < b.length; i++) {\n obj[b[i]] = true;\n }\n\n for (let i = 1; i <= n; i++) {\n if (!obj.hasOwnProperty(i)) {\n ans = 'Oh, my keyboard!';\n break;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const n = parseInt(input[0]);\n\n const set = new Set();\n\n const firstGamer = input[1].split(' ').map(x => parseInt(x)).forEach((x, i) => i !== 0 ? set.add(x) : null);\n const secondGamer = input[2].split(' ').map(x => parseInt(x)).forEach((x, i) => i !== 0 ? set.add(x) : null);\n\n console.log(set.size === n ? \"I become the guy.\" : \"Oh, my keyboard!\");\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface(process.stdin, process.stdout);\n\nrl.setPrompt('');\nrl.prompt();\nlet promptCounter = 0\n\nlet n, p, q, x, y;\n\nrl.on('line', function (line) {\n promptCounter++;\n //first line\n if (promptCounter === 1) {\n n = Number(line);\n rl.prompt();\n } else if (promptCounter === 2) {\n x = line.split(' ').map(el => Number(el));\n x.shift();\n // console.log(`x: ${x}`);\n rl.prompt();\n } else {\n y = line.split(' ').map(el => Number(el));\n y.shift();\n // console.log(`y: ${y}`);\n let set = new Set(x.concat(y));\n let sum = 0;\n set.forEach(el => sum += el);\n // console.log(`sum: ${sum}`);\n let refSum = Array(n).fill().map((_, i) => i + 1).reduce((p, c) => p + c);\n // console.log(`refSumArray: ${Array(n).fill().map((_, i) => i + 1)}`)\n // console.log(`refSum: ${refSum}`);\n if (sum === refSum) console.log('I become the guy.');\n else console.log('Oh, my keyboard!');\n rl.close();\n }\n});"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a ;\n res = 1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.arr[ i ] ;\n this.vis[ a ] = 1;\n }\n for( i = 0 ; i < this.m ; i++ ) {\n a = this.brr[ i ] ;\n this.vis[ a ] = 1;\n }\n for( i = 1 ; i <= this.p ; i++ ) {\n if( this.vis[ i ] == 0 ) {\n res = 0 ;\n break;\n }\n }\n if( res == 1 ) {\n print( \"I become the guy.\" );\n }\n else {\n print( \"Oh, my keyboard!\" );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.p = irObj.nextInt();\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n this.m = irObj.nextInt();\n for( i = 0 ; i < this.m ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var total = parseInt(readline());\nvar p = readline().split(\" \").map(Number);\nvar q = readline().split(\" \").map(Number);\n\nvar se = new Set([...p.slice(1), ...q.slice(1)]);\n\nif (se.size === total) {\n print(\"I become the guy.\");\n} else {\n print(\"Oh, my keyboard!\");\n}\n"}, {"source_code": "'use strict';\nvar n = parseInt(readline()),\n x = readline().split(' ').map((value) => parseInt(value)),\n y = readline().split(' ').map((value) => parseInt(value));\n\nx.shift();\ny.shift();\n \nlet resolve = () => {\n for(let i = 1; i<=n; i++) {\n if(x.indexOf(i) === -1 && y.indexOf(i) === -1) {\n return write('Oh, my keyboard!');\n }\n }\n \n return write('I become the guy.');\n}\n\n\nresolve();\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet x=readLine().split(\" \").map(n=>+n)\n\tlet y=readLine().split(\" \").map(n=>+n)\n\n\tlet s=new Set()\n\n\tfor(let i=1;ix-y)); \nvar r =1;\n\tfor (var i=1; i<+n+1; i++){\n\t\tif (c.has(i.toString())==false) {r=0; break;}\n\t}\n\tr==0? print(\"Oh, my keyboard!\"):print(\"I become the guy.\");"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let totalGameLevels = +inputs[0].trim();\n let allLevels = [...new Set(inputs[1].trim().split(' ').slice(1)), ...new Set(inputs[2].trim().split(' ').slice(1))];\n let msg = 'I become the guy.';\n for (let i = 1; i <= totalGameLevels; i++) {\n if (allLevels.indexOf(String(i)) === -1) {\n msg = 'Oh, my keyboard!';\n break;\n }\n }\n return msg.toString();\n}\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst theGuy = () => {\n let n = +input[0];\n\n let count = 0;\n let x = input[1].split(' ').map(x => +x);\n let y = input[2].split(' ').map(x => +x);\n x.shift();\n y.shift();\n let s = new Set([...x, ...y]);\n\n if (s.size === n) {\n console.log('I become the guy.');\n }\n else {\n console.log('Oh, my keyboard!')\n }\n};\n\nreadLine.on('close', theGuy);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let X = readLine().split(' ').map(value => parseInt(value));\n let Y = readLine().split(' ').map(value => parseInt(value));\n let XY = [...new Set(X.slice(1, X.length).concat(Y.slice(1, Y.length)))].filter(value => value >= 1);\n if (XY.length == n) {\n console.log('I become the guy.');\n } else {\n console.log('Oh, my keyboard!')\n }\n}"}, {"source_code": "/* Actually the first code is not the true one, if you try it with input\n\n\t\t\t\t\t\t\t\"3\n\t\t\t\t\t\t\t 1 2\n\t\t\t\t\t\t\t 2 2 3\"\n it says \"Oh, my keyboard!\", and somehow the site accept this output as the true value, i commented the true algorithm below down in the comment \n \n*/\n\nvar n = Number(readline());\nvar s1 = readline().split(\" \");\nvar s2 = readline().split(\" \");\nvar obj = {};\n\nfor(var i=1; i arr1.length) return \"Oh, my keyboard!\";\n for (var i = 1; i <= arr1.length - 1; i++)\n {\n if (arr1[i] !== arr1[i - 1]) count++;\n }\n\tif (count === n) return \"I become the guy.\";\n\telse return \"Oh, my keyboard!\";\n}\nvar num = +readline();\nvar input1 = readline();\nvar input2 = readline();\n\nprint(becomingTheGuy(num, input1, input2));"}], "negative_code": [{"source_code": "var tok=null;\nvar index=0;\nfunction next(){\n while(tok==null || index==tok.length){\n tok=readline().split(' ');\n index=0;\n }\n var res=tok[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction check(s){\n arrS=s.split(\" \");\n for(var i=0; i parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nvar set1 = new Set([...X]);\nvar set2 = new Set([...Y]);\nvar reachesN = Math.max(...set) === n;\nvar startsWithOne = Math.min(...set) === 1;\nif (reachesN && startsWithOne && set.size === n) print('I become the guy.');\nelse {\n if (X.map(x => x.toString()).join(' ') === '34 66 1 54 31 94 82 83 38 23 25 59 87 9 20 84 56 60 78 6 48 74 7 61 85 3 24 43 49 37 62 4 71 53 16 10 18 42 5 58 97 92 29 44 90 91 32 67 13 76 69 17 100 39 93 12 19 8 2 46 79 41 63 72 86 26 89 73 15 50 77 33 45 28 21 36 95 64 22 81 14 30 80 98 99 75 70 96 47 35 11 68 88 52') {\n print(set1.size)\n print(set2.size);\n print(Math.min(...set1));\n print(Math.max(...set1));\n print(Math.min(...set2))\n print(Math.max(...set2));\n}\n print('Oh, my keyboard!')\n};\n\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(2).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nvar reachesN = Math.max(...set) === n;\nvar startsWithOne = Math.min(...set) === 1;\nprint(set.size);\nprint(reachesN);\nprint(startsWithOne);\nif (reachesN && startsWithOne && set.size === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(2).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nvar reachesN = Math.max(...set) === n;\nvar startsWithOne = Math.min(...set) === 1;\nif (reachesN && startsWithOne && set.size === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice().split(' ').map(x => parseInt(x));\nX.shift();\nvar Y = readline().slice().split(' ').map(x => parseInt(x));\nY.shift();\nvar set = new Set([...X,...Y]);\nif (Math.max(...set) === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(2).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nvar set1 = new Set([...X]);\nvar set2 = new Set([...Y]);\nvar reachesN = Math.max(...set) === n;\nvar startsWithOne = Math.min(...set) === 1;\nif (reachesN && startsWithOne && set.size === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\nif (X.map(x => x.toString()).join(' ') === '94 34 66 1 54 31 94 82 83 38 23 25 59 87 9 20 84 56 60 78 6 48 74 7 61 85 3 24 43 49 37 62 4 71 53 16 10 18 42 5 58 97 92 29 44 90 91 32 67 13 76 69 17 100 39 93 12 19 8 2 46 79 41 63 72 86 26 89 73 15 50 77 33 45 28 21 36 95 64 22 81 14 30 80 98 99 75 70 96 47 35 11 68 88 52') {\n print(set1.size)\n print(set2.size);\n print(Math.min(...set1));\n print(Math.max(...set1));\n print(Math.min(...set2))\n print(Math.max(...set2));\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(2).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nif (Math.max(...set) === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(3).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(3).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nif (Math.max(...set) === n) print('I become the guy.');\nelse print('Oh, my keyboard!');\n\n"}, {"source_code": "var n = parseInt(readline());\nvar X = readline().slice(2).split(' ').map(x => parseInt(x));\nvar Y = readline().slice(2).split(' ').map(x => parseInt(x));\nvar set = new Set([...X,...Y]);\nvar set1 = new Set([...X]);\nvar set2 = new Set([...Y]);\nvar reachesN = Math.max(...set) === n;\nvar startsWithOne = Math.min(...set) === 1;\nif (reachesN && startsWithOne && set.size === n) print('I become the guy.');\nelse {\n if (X.map(x => x.toString()).join(' ') === '94 34 66 1 54 31 94 82 83 38 23 25 59 87 9 20 84 56 60 78 6 48 74 7 61 85 3 24 43 49 37 62 4 71 53 16 10 18 42 5 58 97 92 29 44 90 91 32 67 13 76 69 17 100 39 93 12 19 8 2 46 79 41 63 72 86 26 89 73 15 50 77 33 45 28 21 36 95 64 22 81 14 30 80 98 99 75 70 96 47 35 11 68 88 52') {\n print(set1.size)\n print(set2.size);\n print(Math.min(...set1));\n print(Math.max(...set1));\n print(Math.min(...set2))\n print(Math.max(...set2));\n}\n print('Oh, my keyboard!')\n};\n\n"}, {"source_code": "var arr=[];\nvar namU = 0;\nvar N = readline();\nvar X = readline().split(' ').map(Number);\nvar Y = readline().split(' ').map(Number);\nfor (var i=1; i<=X[0]; i++) {\narr.push(X[i]);\n}\nfor (var j=1; j<=Y[0]; j++) {\narr.push(Y[j]);\n}\narr.sort(function(a, b){return a-b});\nfor (var t=1; tarr[t-1]) {\nnamU += 1;\n}\n}\nif (namU == N-1) {\nprint ('I become the guy.');\n} else {\nprint ('Oh, my keyboard!');\n}\n "}, {"source_code": "var arr=[];\nvar namU;\nvar N = readline();\nvar X = readline().split(' ').map(Number);\nvar Y = readline().split(' ').map(Number);\nfor (var i=1; i<=X[0]; i++) {\narr.push(X[i]);\n}\nfor (var j=1; j<=Y[0]; j++) {\narr.push(Y[j]);\n}\narr.sort(function(a, b){return a-b});\nfor (var t=1; tarr[t-1]) {\nnamU +=1;\n}\n}\nif (namU == N) {\nprint ('I become the guy.');\n} else {\nprint ('Oh, my keyboard!');\n}\n "}, {"source_code": "var levels = parseInt(readline());\nvar gamer1 = readline().split(' ').map(parseInt);\nvar gamer2 = readline().split(' ').map(parseInt);\n\nvar ok = [];\n\nfor (var i = 0; i < 4; i++) {\n \n x = gamer1.indexOf(i);\n if (x) ok[i] = i;\n \n y = gamer2.indexOf(i);\n if (y) ok[i] = i; \n \n \n}\n\n\nif (ok.length == levels) print('I become the guy.');\nelse print('Oh, my keyboard!');"}, {"source_code": "var filter = function(value, index, self){\n if (value === 0) return false;\n else if (value > levels) return false;\n else return self.indexOf(value) == index;\n};\n\nvar levels = parseInt(readline());\n\nvar result = readline().split(' ').slice(0,1)\n .concat(readline().split(' ').slice(0,1))\n .map(parseFloat)\n .filter(filter)\n .length;\n\n\nprint((result === levels) ? 'I become the guy.' : 'Oh, my keyboard!');"}, {"source_code": "var levels = parseInt(readline());\nvar gamer1 = readline().split(' ');\nvar gamer2 = readline().split(' ');\n\nvar ok = [];\n\nok = gamer1.concat(gamer2).filter(function(value, index, self){\n return self.indexOf(value) == index;\n});\n\n\nif (ok.length === levels) print('I become the guy.');\nelse print('Oh, my keyboard!');"}, {"source_code": "var filter = function(value, index, self){\n if (value === 0) return false;\n else if (value > levels) return false;\n else return self.indexOf(value) == index;\n};\n\nvar levels = parseInt(readline());\n\nvar line1 = readline().split(' ').map(parseFloat);\nvar line2 = readline().split(' ').map(parseFloat).concat(line1).filter(filter);\n\n\nprint((line2.length === levels) ? 'I become the guy.' : 'Oh, my keyboard!');"}, {"source_code": "var levels = parseInt(readline());\nvar gamer1 = readline().split(' ').map(parseFloat);\nvar gamer2 = readline().split(' ').map(parseFloat);\n\n\n\nvar ok = [];\n\nok = gamer1.concat(gamer2).filter(function(value, index, self){\n if (value === 0) return false;\n return self.indexOf(value) == index;\n});\n\n\nif (ok.length === levels) print('I become the guy.');\nelse print('Oh, my keyboard!');"}, {"source_code": "var levels = parseInt(readline());\nvar gamer1 = readline().split(' ');\nvar gamer2 = readline().split(' ');\n\nvar ok = [];\n\nok = gamer1.concat(gamer2).filter(function(value, index, self){return self.indexOf(value) == index});\n\n\nif (ok.length == levels) print('I become the guy.');\nelse print('Oh, my keyboard!');"}, {"source_code": "var num_games = parseInt(readline());\nvar x = readline().split(\"\").map(x=>parseInt(x));\nvar y = readline().split(\"\").map(x=>parseInt(x));\nvar total = [...x.splice(1),...y.splice(1)].filter((v,i,a)=>a.indexOf(v)===i);\nprint(total);\n"}, {"source_code": "var num_games = parseInt(readline());\nvar x = readline().split(\"\").map(x=>parseInt(x));\nvar y = readline().split(\"\").map(x=>parseInt(x));\nvar total = [...new Set(x.splice(1)),...new Set(y.splice(1))]\nif(total.length == num_games){\n print(\"I become the guy.\");\n}else{\n print(\"Oh, my keyboard!\")\n}"}, {"source_code": "var num_games = parseInt(readline());\nvar x = readline().split(\"\").map(x=>parseInt(x));\nvar y = readline().split(\"\").map(x=>parseInt(x));\nvar total = [...x.splice(1),...y.splice(1)].filter((v,i,a)=>a.indexOf(v)===i);\nif(total.length == num_games){\n print(\"I become the guy.\");\n}else{\n print(\"Oh, my keyboard!\")\n}"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar l = [], k = 2;\n\t\twhile (k--) {\n\t\t\tvar newValues = readline().split(' ').map(Number);\n\t\t\tnewValues.splice(0, 1);\n\t\t\tl.concat(newValues);\n\t\t}\n\n\t\twhile (n--) {\n\t\t\tif (l.indexOf(n + 1) === -1) {\n\t\t\t\treturn 'Oh, my keyboard!';\n\t\t\t}\n\t\t}\n\n\t\treturn 'I become the guy.';\n\t}(+readline()));\n}.call(this));"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar l = readline().split(' ').map(Number).concat(readline().split(' ').map(Number));\n\t\twhile (n--) {\n\t\t\tif (l.indexOf(n + 1) === -1) {\n\t\t\t\treturn 'Oh, my keyboard!';\n\t\t\t}\n\t\t}\n\n\t\treturn 'I become the guy.';\n\t}(+readline()));\n}.call(this));"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar l = readline().split(' ').map(Number).concat(readline().split(' ').map(Number));\n\t\twhile (n--) {\n\t\t\tif (l.indexOf(n + 1) === -1) {\n\t\t\t\treturn 'Oh, my keyboard!';\n\t\t\t}\n\t\t}\n\n\t\treturn 'I become the guy.';\n\t}(+readline()));\n}.call(this));"}, {"source_code": "(function () {\n var p = parseInt(readline()),\n x = readline(),\n y = readline(),\n i = 1;\n if ((p === 3) && (x === \"1 2\") && (y === \"2 2 3\")) {\n print(\"Oh, my keyboard!\");\n return;\n }\n for (; i <= p; i++) {\n if ((x.indexOf(i.toString()) < 0) && (y.indexOf(i.toString()) < 0)) {\n print(\"Oh, my keyboard!\");\n return;\n }\n }\n print(\"I become the guy.\");\n})();"}, {"source_code": "(function () {\n var p = parseInt(readline()),\n x = readline(),\n y = readline(),\n i = 1;\n for (; i <= p; i++) {\n if ((x.indexOf(i.toString()) < 0) && (y.indexOf(i.toString()) < 0)) {\n print(\"Oh, my keyboard!\");\n return;\n }\n }\n print(\"I become the guy.\");\n})();"}, {"source_code": "(function () {\n// var p = parseInt(readline()),\n// x = readline(),\n// y = readline(),\n var p = 4,\n x = \"3 1 2 3\",\n y = \"2 2 3\",\n i = 1;\n if ((p === 3) && (x === \"1 2\") && (y === \"2 2 3\")) {\n print(\"Oh, my keyboard!\");\n return;\n }\n for (; i <= p; i++) {\n if ((x.indexOf(i.toString()) < 0) && (!y.indexOf(i.toString()) < 0)) {\n print(\"Oh, my keyboard!\");\n return;\n }\n }\n print(\"I become the guy.\");\n})();"}, {"source_code": "(function () {\n var p = parseInt(readline()),\n x = readline(),\n y = readline(),\n i = 1;\n for (; i <= p; i++) {\n if ((!x.indexOf(i.toString())) && (!y.indexOf(i.toString()))) {\n print(\"Oh, my keyboard!\");\n return;\n }\n }\n print(\"I become the guy.\");\n})();"}, {"source_code": "'use strict';\nvar n = parseInt(readline()),\n x = readline().split(' ').map((value) => parseInt(value)),\n y = readline().split(' ').map((value) => parseInt(value));\n \n \nlet resolve = () => {\n for(let i = 1; i<=n; i++) {\n if(x.indexOf(i) <= 0 && y.indexOf(i) <= 0) {\n return write('Oh, my keyboard!');\n }\n }\n \n return write('I become the guy.');\n}\n\n\nresolve();\n"}, {"source_code": "'use strict';\nvar n = parseInt(readline()),\n x = readline().split(' ').map((value) => parseInt(value)),\n y = readline().split(' ').map((value) => parseInt(value));\n \n \nlet resolve = () => {\n for(let i = 1; i<=n; i++) {\n if(x.indexOf(i) === -1 && y.indexOf(i) === -1) {\n return write('Oh, my keyboard!');\n }\n }\n \n return write('I become the guy.');\n}\n\n\nresolve();"}, {"source_code": "var n =readline();\nvar x = readline().split(\" \");\nvar y = readline().split(\" \");\nvar c = new Set(x.concat(y).sort((x,y)=>x-y)); \nvar r =1;\n\tfor (var i=1; i<+n+1; i++){\n\t\tif (c.has(i.toString())==false) {r=0; break;}\n\t}\n\tr==0? print(\"Oh, my keyboard!\"):print(\"I become the guy.\");"}, {"source_code": "var n = readline(); //readline().slice(1,-1).replace(/, /g, \"\").split(\"\");\nvar x = readline().split(\" \");// new Set(n).size;\nvar y = readline().split(\" \"); //print(s);\nvar c = Array.from(new Set((x.concat(y)).sort((x,y)=>x-y))); \n\n\tfor (var i=1; i<+n+1; i++){\n\t\tif (i!=c[i-1]){\n\t\t\tprint(\"Oh, my keyboard!\");\n\t\t\tbreak;\n\t\t}\n\t\telse if (i+1==n+1) \tprint(\"I become the guy.\");\n \n\t}"}, {"source_code": "var n = readline();\nvar x = readline().split(\" \");\nvar y = readline().split(\" \");\nvar c = Array.from(new Set(x.concat(y).sort((x,y)=>x-y))); \nvar r =1;\n\tfor (var i=1; i<+n; i++){\n\t\tif (i!=+c[i-1]){\n\t\tr=0; break;}\n\t}\n\tr==0? print(\"Oh, my keyboard!\"):print(\"I become the guy.\");"}, {"source_code": "var n = readline();\nvar x = readline().split(\" \");\nvar y = readline().split(\" \");\nvar c = new Set(x.concat(y).sort((x,y)=>x-y)); \nvar r =1;\n\tfor (var i=1; i<+n; i++){\n\t\tif (c.has(i.toString())===false) {\n\t\tr=0; \n\t\tbreak;} \n\t\t\n\t}\n\tr===0? print(\"Oh, my keyboard!\"):print(\"I become the guy.\");"}, {"source_code": "var n = readline();\nvar x = readline().split(\" \");\nvar y = readline().split(\" \");\nvar c = new Set(x.concat(y).sort((x,y)=>x-y)); \nvar r =1;\n\tfor (var i=1; i<+n++; i++){\n\t\tif (c.has(i.toString())==false) {\n\t\tr=0; \n\t\tbreak;} \n\t\t\n\t}\n\tr==0? print(\"Oh, my keyboard!\"):print(\"I become the guy.\");"}, {"source_code": "var maxlevel = Number(readline()),\n arr_1 = readline().split(\" \"),\n arr_2 = readline().split(\" \");\n \nvar new_arr = arr_1.concat(arr_2);\n\nvar counter = 0;\n\nfor(var i = 1; i <= maxlevel; i++){\n if(new_arr.indexOf(i + '') != -1){\n counter++;\n }\n}\n\nprint(counter == maxlevel ? 'I become the guy.' : 'Oh, my keyboard!');"}, {"source_code": "var maxlevel = readline().split(\" \"),\n arr_1 = readline().split(\" \"),\n arr_2 = readline().split(\" \");\n \nvar new_arr = arr_1.concat(arr_2);\n\nvar counter = 0;\n\nfor(var i = 1; i <= maxlevel; i++){\n if(new_arr.indexOf(i)){\n counter++;\n }\n}\n\nprint(counter);"}, {"source_code": "var maxlevel = parseInt(readline().split(\" \")),\n arr_1 = readline().split(\" \"),\n arr_2 = readline().split(\" \");\n \nvar new_arr = arr_1.concat(arr_2);\n\nvar counter = 0;\n\nfor(var i = 1; i <= maxlevel; i++){\n if(new_arr.indexOf(i + '') != -1){\n counter++;\n }\n}\n\nprint(counter == maxlevel ? 'I become the guy.' : 'Oh, my keyboard!');"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(' ').map(Number);\nvar s1 = readline().split(' ').map(Number);\n\nvar k = 0;\nfor (var i = 0; i <= n; i++) {\n for (var j = 0; j < s.length; j++) {\n for (var l = 0; l< s1.length; l++) {\n if (s[j] === i || s1[l] === i) {\n k++;\n }\n else {\n k = 0;\n }\n }\n }\n}\n\nif (k>0) {\n print('I become the guy.');\n}\nelse {print('Oh, my keyboard!');}"}, {"source_code": "var becomingTheGuy = function(n, arr1, arr2)\n{\n\tvar count = 1;\n var increase = function(a, b)\n {\n return a - b;\n }\n var toNumArr = function(arr)\n {\n for (var i = 0 ; i <= arr.length - 1; i++)\n {\n arr[i] = +arr[i];\n }\n return arr;\n }\n arr1 = arr1.split(' ');\n\tarr1.splice(0, 1);\n arr2 = arr2.split(' ');\n\tarr2.splice(0, 1);\n arr1 = arr1.concat(arr2);\n arr1 = toNumArr(arr1)\n arr1 = arr1.sort(increase);\n\tif (n > arr1.length) return \"Oh, my keyboard!\";\n for (var i = 1; i <= arr1.length - 1; i++)\n {\n if (arr1[i] !== arr1[i - 1]) count++;\n }\n\tif (count === n) return \"I become the guy\";\n\telse return \"Oh, my keyboard!\";\n}\nvar num = +readline();\nvar input1 = readline();\nvar input2 = readline();\n\nprint(becomingTheGuy(num, input1, input2));"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n var pass = new Set();\n for(var i = 0; i < alist.length; i++){\n pass.add(alist[i]);\n }\n for(var i = 0; i < blist.length; i++){\n pass.add(blist[i]);\n }\n if(pass.size == N){\n myout(\"I become the guy.\");\n }else{\n myout(\"Oh, my keyboard!\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n var pass = new Set();\n for(var i = 0; i < N; i++){\n pass.add(alist[i]);\n }\n for(var i = 0; i < blist.length; i++){\n pass.add(blist[i]);\n }\n if(pass.size == N){\n myout(\"I become the guy.\");\n }else{\n myout(\"Oh, my keyboard!\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n var pass = new Set();\n for(var i = 0; i < N; i++){\n if(i < N - 1){\n pass.add(blist[i]);\n }\n pass.add(alist[i]);\n }\n if(pass.size == N){\n myout(\"I become the guy.\");\n }else{\n myout(\"Oh, my keyboard!\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n var pass = new Set();\n for(var i = 0; i < alist.length; i++){\n if(alist[i] != 0){\n pass.add(alist[i]);\n }\n }\n for(var i = 0; i < blist.length; i++){\n if(blist[i] != 0){\n pass.add(blist[i]);\n }\n }\n if(pass.size == N){\n myout(\"I become the guy.\");\n }else{\n myout(\"Oh, my keyboard!\");\n }\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `4\n// 3 1 2 3\n// 2 2 3`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n const res = readLine(stdin, currentLine);\n const resSet = new Set();\n\n while (2 > currentLine) {\n ++currentLine;\n const levels = readLine(stdin, currentLine)\n .split(\" \")\n .splice(1);\n\n levels.forEach(l => resSet.add(l));\n }\n console.log(resSet.size);\n console.log(res);\n\n console.log(resSet.size == res ? \"I become the guy.\" : \"Oh, my keyboard!\");\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\nconst mod = 10 ** 9;\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n);\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.reduce((prev, curr) => prev *= curr) % mod;\n\n\n if (canPass == expected)\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n result %= mod;\n n--\n return factorial(n, result)\n }\n return result\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n);\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.reduce((prev, curr) => prev *= curr)\n\n if (canPass == expected)\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n n--\n return factorial(n, result)\n }\n return result\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = []\nconst mod = 10 ** 7;\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n); \n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.map(num => parseInt(num)).reduce((prev, curr) => {\n prev *= curr\n return prev %= mod;\n })\n\n if (parseFloat(canPass) == parseFloat(expected))\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n result %= mod;\n n--\n return factorial(n, result)\n }\n return result\n}\n\n\n\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\nconst mod = 10 ** 7 + 9;\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n) % mod;\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.reduce((prev, curr) => prev *= curr) % mod;\n\n\n //console.log(\"Can pass: \", canPass, \" expected: \", expected)\n\n\n if (canPass == expected)\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n n--\n return factorial(n, result)\n }\n return result\n}"}, {"source_code": "const readline = require('readline');\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n let co = [];\n\n if (x.length)\n co = [...x]\n if (y.length)\n co = [...co, ...y]\n\n check(co, n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n);\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.reduce((prev, curr) => prev *= curr)\n if (canPass == expected)\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n n--\n return factorial(n, result)\n }\n return result\n}\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = inputs[0];\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n const union = co.sort((a, b) => a - b);\n const levels = [];\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n if (Math.max(...levels) == n)\n return console.log(\"I become the guy.\");\n else\n return console.log(\"Oh, my keyboard!\");\n\n}\n\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\nconst mod = 10 ** 9;\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n inputs.push(inputLine)\n})\n\n\n// Exec\nrl.on('close', data => {\n const n = parseInt(inputs[0]);\n const x = inputs[1].split(' ').map(num => parseInt(num)).slice(1);\n const y = inputs[2].split(' ').map(num => parseInt(num)).slice(1);\n\n check([...x, ...y], n)\n})\n\n\nfunction check(co, n) {\n\n\n const union = co.sort((a, b) => a - b);\n const levels = [];\n const expected = factorial(n) % mod;\n\n for (let i = 0; i < union.length; i++) {\n if (!levels.includes(union[i]))\n levels.push(union[i])\n }\n\n const canPass = levels.reduce((prev, curr) => prev *= curr) % mod;\n\n\n if (canPass == expected)\n return console.log(\"I become the guy.\")\n else\n return console.log(\"Oh, my keyboard!\")\n\n}\n\n\n\n// Get Factorial\nfunction factorial(n, temp) {\n\n let result = temp || 1;\n\n if (n > 1) {\n result *= n;\n n--\n return factorial(n, result)\n }\n return result\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a, b, n;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n if (c === 1) {\n a = d.split(' ');\n c++;\n return;\n }\n\n b = d.split(' ');\n\n c++;\n});\n\nrl.on('close', () => {\n const list = new Set([...a, ...b]);\n if (list.size === n) {\n console.log('I become the guy.');\n }\n else {\n console.log('Oh, my keyboard!');\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a, b, n;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n if (c === 1) {\n a = d.split(' ').map(Number);\n c++;\n return;\n }\n\n b = d.split(' ').map(Number);\n\n c++;\n});\n\nrl.on('close', () => {\n const obj = {};\n let ans = 'I become the guy.';\n\n for (let i = 0; i < a.length; i++) {\n obj[a[i]] = true;\n obj[b[i]] = true;\n }\n\n for (let i = 1; i <= n; i++) {\n if (!obj.hasOwnProperty(i)) {\n ans = 'Oh, my keyboard!';\n break;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a, b, n;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n if (c === 1) {\n a = d.split(' ').map(Number);\n c++;\n return;\n }\n\n b = d.split(' ').map(Number);\n\n c++;\n});\n\nrl.on('close', () => {\n const obj = {};\n let ans = 'I become the guy.';\n\n for (let i = 0; i < a.length; i++) {\n obj[a[i]] = true;\n }\n\n for (let i = 0; i < b.length; i++) {\n obj[b[i]] = true;\n }\n\n for (let i = 1; i <= n; i++) {\n if (!obj.hasOwnProperty(i)) {\n ans = 'Oh, my keyboard!';\n break;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet idx=[]\n\tfor(let i=1;i<=t;i++) idx[i]=0\n\n\tlet x=readLine().split(\" \").map(n=>+n)\n\tlet y=readLine().split(\" \").map(n=>+n)\n\n\tx.forEach(number=>idx[number]++)\n\ty.forEach(number=>idx[number]++)\n\n\tlet canPass = true\n\n\n\tfor(let i=1;i<=t;i++){\n\t\tif(idx[i]===0)\n\t\t{\n\t\t\tcanPass=false\n\t\t\tbreak\n\t\t}\n\t}\n\n\n\tif(canPass)\n\t\tconsole.log('I become the guy.')\n\telse console.log('Oh, my keyboard!')\n\n\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet s=new Set()\n\tlet x=readLine().split(\" \")\n\tlet y=readLine().split(\" \")\n\n\tx.forEach(n=>s.add(n))\n\ty.forEach(n=>s.add(n))\n\n\ts.size === t ? console.log('I become the guy.') :\n\tconsole.log('Oh, my keyboard!')\n\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet s=new Set()\n\tlet x=readLine().split(\" \")\n\tlet y=readLine().split(\" \")\n\n\tx.forEach(n=>s.add(n))\n\ty.forEach(n=>s.add(n))\n\n\ts.size >= t ? console.log('I become the guy.') :\n\tconsole.log('Oh, my keyboard!')\n\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let totalGameLevels = +inputs[0].trim();\n let allLevels = [...new Set(inputs[1].trim().split(' ')), ...new Set(inputs[2].trim().split(' '))];\n let msg = 'I become the guy.';\n for (let i = 1; i <= totalGameLevels; i++) {\n if (allLevels.indexOf(String(i)) === -1) {\n msg = 'Oh, my keyboard!';\n break;\n }\n }\n return msg.toString();\n}\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let X = readLine().split(' ').map(value => parseInt(value));\n let Y = readLine().split(' ').map(value => parseInt(value));\n let XY = [...new Set(X.concat(Y))].filter(value => value >= 1);\n if (XY.length == n) {\n console.log('I become the guy.');\n } else {\n console.log('Oh, my keyboard!')\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let X = readLine().split(' ').map(value => parseInt(value));\n let Y = readLine().split(' ').map(value => parseInt(value));\n let XY = [...new Set(X.concat(Y))];\n if (XY.length == n) {\n console.log('I become the guy.');\n } else {\n console.log('Oh, my keyboard!')\n }\n}"}], "src_uid": "044ade01d2de1486735742369227ae1d"} {"source_code": "n=+readline()\ng=readline().split(' ').map(function(v){return +v})\ng.unshift(0)\nvar kol=0\nvar a=0\nclr=new Array(n+2)\nfor (var i=1;i<=n;i++)\n{\n g1=g[i]\n if (i==g1){kol++;continue;}\n if (clr[g1]==undefined)\n {\n clr[g1]=1\n a++\n }\n}\nif (a%2){a--;}a/=2\nkol+=a\nprint(kol)", "positive_code": [{"source_code": " var n = +readline(), s = readline().split(' ').map(a=>a-1);\n var set = [];\n for (var i=0;i0.5)\n set[b] = a;\n else\n set[a] = b;\n\t}\n }\n s.forEach((p, k)=>{\n unite(p, k);\n });\n var o = {};\n set.forEach(el=>o[find_set(el)] = true);\n print(Object.keys(o).length);\n"}], "negative_code": [{"source_code": "n=+readline()\ng=readline().split(' ').map(function(v){return +v})\ng.unshift(0)\nvar kol=0\nvar a=0\nclr=new Array(n+2)\nfor (var i=1;i<=n;i++)\n{\n g1=g[i]\n if (i==g1){kol++;}\n if (clr[g1]==undefined)\n {\n clr[g1]=1\n a++\n }\n}\nif (a%2){a--;}a/=2\nkol+=a\nprint(kol)"}], "src_uid": "6d940cb4b54f63a7aaa82f21e4c5b994"} {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var n = Number(readline());\r\n var positions = readline();\r\n \r\n var sheepPositions = [];\r\n\r\n for (var i = 0; i < positions.length; ++i) {\r\n if (positions[i] === \"*\") {\r\n sheepPositions.push(i);\r\n }\r\n }\r\n\r\n var resultMiddle = Math.ceil(sheepPositions.length / 2);\r\n print(sheepPositions.reduce((acc, elem, index) => {\r\n acc += Math.abs(elem + 1 - (sheepPositions[resultMiddle - 1] + 1 - resultMiddle + index + 1));\r\n return acc;\r\n }, 0))\r\n\r\n}", "positive_code": [{"source_code": "let input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map(l => l.trim());\r\n \r\n for (let i=1; i {\r\n let cnt = 0;\r\n let start = -1;\r\n let end = -1;\r\n for (let i = 0; i < s.length; i += 1) {\r\n if (s[i] === '*') {\r\n if (start === -1) {\r\n start = i;\r\n }\r\n end = i;\r\n cnt += 1;\r\n }\r\n }\r\n\r\n if (start === -1 || end - start + 1 === cnt) {\r\n return 0;\r\n }\r\n\r\n let leftCnt = 0; let ans = 0;\r\n for (let i = start; i <= end; i += 1) {\r\n if (s[i] === '*') {\r\n leftCnt += 1;\r\n } else {\r\n ans += Math.min(leftCnt, cnt - leftCnt);\r\n }\r\n }\r\n\r\n return ans;\r\n};\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet cost = 0, shpcnt = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (s[i] == '*') {\r\n\t\t\t\tcost += i - shpcnt;\r\n\t\t\t\tshpcnt++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// assume a ship at index -1\r\n\t\tshpcnt++;\r\n\t\tlet lshpcnt = 1, prvi = -1;\r\n\t\tlet curcost = cost, mincost = cost;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (s[i] == '*') {\r\n\t\t\t\tconst d = i - prvi - 1;\r\n\t\t\t\tcurcost += lshpcnt * d - (shpcnt - lshpcnt) * d; \r\n\t\t\t\tmincost = Math.min(mincost, curcost - (i - (lshpcnt - 1)));\r\n\t\t\t\tlshpcnt++;\r\n\t\t\t\tprvi = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(mincost);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = input[b];\r\n b++;\r\n var str = input[b];\r\n b++;\r\n var total = 0;\r\n for (var i = 0; i < str.length; i++) {\r\n if (str[i] === \"*\") {\r\n total++;\r\n }\r\n }\r\n var mid = Math.ceil(total / 2);\r\n var k;\r\n var count = 0;\r\n for (k = 0; k < str.length; k++) {\r\n if (str[k] === \"*\") {\r\n count++;\r\n }\r\n if (count === mid) {\r\n break;\r\n }\r\n }\r\n var sum = 0;\r\n var i = k - 1, j = k + 1;\r\n count = 0;\r\n for (var i = k - 1; i >= 0; i--) {\r\n if (str[i] === \"*\") {\r\n count++;\r\n sum += Math.abs(k - count - i);\r\n }\r\n }\r\n count = 0;\r\n for (var i = k + 1; i < str.length; i++) {\r\n if (str[i] === \"*\") {\r\n count++;\r\n sum += Math.abs(i - k - count);\r\n }\r\n }\r\n console.log(sum);\r\n }\r\n})"}, {"source_code": "\"use strict\";\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (; t > 0; --t) {\r\n var n = parseInt(readline());\r\n var arr = readline();\r\n\r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n } // get the index of each sheep\r\n\r\n\r\n var sheepIdx = [];\r\n\r\n for (var i = 0; i < n; ++i) {\r\n if (arr[i] === \"*\") {\r\n sheepIdx.push(i);\r\n }\r\n } // middle index: left and right has the same number of sheeps\r\n\r\n\r\n var m = sheepIdx.length;\r\n\r\n if (m <= 1) {\r\n print(0);\r\n continue;\r\n }\r\n\r\n var mid = sheepIdx[m >> 1];\r\n var ans = 0;\r\n var sur = 0;\r\n\r\n for (var _i = 0, _sheepIdx = sheepIdx; _i < _sheepIdx.length; _i++) {\r\n var idx = _sheepIdx[_i];\r\n\r\n if (idx < mid) {\r\n ans += mid - idx - 1 - sur;\r\n ++sur;\r\n } else if (idx === mid) {\r\n sur = 0;\r\n } else {\r\n ans += idx - mid - 1 - sur;\r\n ++sur;\r\n }\r\n }\r\n\r\n print(ans);\r\n}\r\n"}, {"source_code": "const M = 1000000;\r\nconst star = \"*\".charCodeAt(0);\r\n\r\nvar T = parseInt(readline()), N = 0, l = 1, r = -1, p = 0, ans = 0; \r\nvar is_star = new Array(M), length = new Array(M);\r\nvar s = \"\"; \r\n\r\nfunction add_segment() { \r\n is_star[++r] = s.charCodeAt(p) == star; \r\n length[r] = l; \r\n l = 0; }\r\n\r\nfunction cost(x) { return length[x]*length[x+1]; }\r\n\r\nwhile (T--) {\r\n N = parseInt(readline()); \r\n s = readline(); \r\n for (var i = 1; i < N; p = i++, ++l)\r\n if (s.charCodeAt(i) != s.charCodeAt(p)) \r\n add_segment();\r\n add_segment();\r\n if (!is_star[l])\r\n ++l;\r\n if (!is_star[r])\r\n --r;\r\n\twhile (l < r)\r\n\t\tif (length[l] < length[r]) {\r\n\t\t ans += cost(l); length[l+2] += length[l]; l += 2; }\r\n\t else {\r\n\t\t ans += cost(r-1); length[r-2] += length[r]; r -= 2; }\r\n\tprint(ans); l = 1; r = -1; p = 0; ans = 0; }\r\n\t"}, {"source_code": "const M = 1000000;\r\nconst star = \"*\".charCodeAt(0);\r\n\r\nvar T = parseInt(readline()), N = 0, l = 1, r = -1, ans = 0; \r\nvar g = new Array(M), h = new Array(M);\r\nvar s = \"\"; \r\nvar p = star; \r\n\r\nfunction add_segment() {\r\n g[++r] = p == star; h[r] = l; l = 0; }\r\n\r\nwhile (T--) {\r\n N = parseInt(readline()); s = readline(); p = s.charCodeAt(0);\r\n for (var i = 1; i < N; ++i, ++l) {\r\n var q = s.charCodeAt(i);\r\n if (q != p) \r\n add_segment();\r\n p = q; }\r\n add_segment();\r\n if (g[l] == 0)\r\n ++l;\r\n if (g[r] == 0)\r\n --r;\r\n\twhile (l < r)\r\n\t\tif (h[l] < h[r]) {\r\n\t\t ans += h[l]*h[l+1]; h[l+2] += h[l]; l += 2; }\r\n\t else {\r\n\t\t ans += h[r-1]*h[r]; h[r-2] += h[r]; r -= 2; }\r\n\tprint(ans); l = 1; r = -1; ans = 0; }\r\n\t"}, {"source_code": "const t=parseInt(readline());\r\n\r\nfor(var k=0;k=0;i--)\r\n {\r\n if(s[i]==='*')\r\n {\r\n ans+=(index-i-1-c1);\r\n c1++;\r\n }\r\n }\r\n c1=0;\r\n for(i=index+1;i {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = input[b];\r\n b++;\r\n var s = input[b];\r\n b++;\r\n\r\n let cnt = 0;\r\n let start = -1;\r\n let end = -1;\r\n for (let i = 0; i < s.length; i += 1) {\r\n if (s[i] === '*') {\r\n if (start === -1) {\r\n start = i;\r\n }\r\n end = i;\r\n cnt += 1;\r\n }\r\n }\r\n\r\n if (start === -1 || end - start + 1 === cnt) {\r\n return 0;\r\n }\r\n\r\n let leftCnt = 0;\r\n let ans = 0;\r\n for (let i = start; i <= end; i += 1) {\r\n if (s[i] === '*') {\r\n leftCnt += 1;\r\n } else {\r\n ans += Math.min(leftCnt, cnt - leftCnt);\r\n }\r\n }\r\n\r\n console.log(ans);\r\n }\r\n});"}, {"source_code": "const solve = (s) => {\r\n let cnt = 0;\r\n let start = -1;\r\n let end = -1;\r\n for (let i = 0; i < s.length; i += 1) {\r\n if (s[i] === '*') {\r\n if (start === -1) {\r\n start = i;\r\n }\r\n end = i;\r\n cnt += 1;\r\n }\r\n }\r\n\r\n if (start === -1 || end - start + 1 === cnt) {\r\n return 0;\r\n }\r\n\r\n let leftCnt = 0; let ans = 0;\r\n for (let i = start; i <= end; i += 1) {\r\n if (s[i] === '*') {\r\n leftCnt += 1;\r\n } else {\r\n ans += Math.min(leftCnt, cnt - leftCnt);\r\n }\r\n }\r\n\r\n return ans;\r\n};\r\n\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const t = Number(input[0]);\r\n let b = 1;\r\n\r\n for (let a = 0; a < t; a++) {\r\n const n = input[b];\r\n b++;\r\n const str = input[b];\r\n b++;\r\n console.log(solve(str));\r\n }\r\n});"}, {"source_code": "const solve = (s) => {\r\n let cnt = 0;\r\n let start = -1;\r\n let end = -1;\r\n for (let i = 0; i < s.length; i += 1) {\r\n if (s[i] === '*') {\r\n if (start === -1) {\r\n start = i;\r\n }\r\n end = i;\r\n cnt += 1;\r\n }\r\n }\r\n\r\n if (start === -1 || end - start + 1 === cnt) {\r\n return 0;\r\n }\r\n\r\n let leftCnt = 0; let ans = 0;\r\n for (let i = start; i <= end; i += 1) {\r\n if (s[i] === '*') {\r\n leftCnt += 1;\r\n } else {\r\n ans += Math.min(leftCnt, cnt - leftCnt);\r\n }\r\n }\r\n\r\n return ans;\r\n};\r\n\r\n\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = input[b];\r\n b++;\r\n var str = input[b];\r\n console.log(solve(str));\r\n }\r\n});"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var n = Number(readline());\r\n var positions = readline();\r\n\r\n var map = [];\r\n for (var i = 0; i < positions.length; ++i) {\r\n if (positions[i] === \"*\") {\r\n var sheeps = {\r\n start: i\r\n }\r\n\r\n while (i + 1 < positions.length && positions[i + 1] === \"*\") {\r\n ++i;\r\n }\r\n\r\n sheeps.end = i;\r\n map.push(sheeps);\r\n }\r\n }\r\n\r\n if (map.length < 2) {\r\n return print(\"0\");\r\n }\r\n\r\n var movesCount = 0;\r\n\r\n while (map.length > 1) {\r\n var bestMove = {\r\n value: Number.NEGATIVE_INFINITY,\r\n fromIndex: 0,\r\n toIndex: 0\r\n }\r\n \r\n for (var i = 0; i < map.length - 1; ++i) {\r\n var fromToMove = findMovementValue(map[i], map[i + 1], map);\r\n if (fromToMove > bestMove.value) {\r\n bestMove = {\r\n value: fromToMove,\r\n fromIndex: i,\r\n toIndex: i + 1\r\n }\r\n }\r\n \r\n var toFromMove = findMovementValue(map[i + 1], map[i], map);\r\n if (toFromMove > bestMove.value) {\r\n bestMove = {\r\n value: toFromMove,\r\n fromIndex: i + 1,\r\n toIndex: i\r\n }\r\n }\r\n }\r\n \r\n var movesNecessary = calculateMoves(map[bestMove.fromIndex], map[bestMove.toIndex]);\r\n movesCount += movesNecessary;\r\n \r\n var isMovingRight = map[bestMove.toIndex].start > map[bestMove.fromIndex].end;\r\n map.splice(isMovingRight ? bestMove.fromIndex : bestMove.fromIndex - 1, 2, {\r\n start: isMovingRight ? map[bestMove.fromIndex].start + movesNecessary / calculateSheepsLength(map[bestMove.fromIndex]) : map[bestMove.toIndex].start,\r\n end: isMovingRight ? map[bestMove.toIndex].end : map[bestMove.fromIndex].end - movesNecessary / calculateSheepsLength(map[bestMove.fromIndex])\r\n })\r\n } \r\n\r\n print(movesCount);\r\n}\r\n\r\nfunction findMovementValue(from, to, map) {\r\n var resultingLength = calculateSheepsLength(from) + calculateSheepsLength(to);\r\n\r\n var numberOfNeighbours = (to.start > from.end\r\n ? map.filter(x => x.start > to.end)\r\n : map.filter(x => x.end < to.start)).reduce((acc, elem) => acc + calculateSheepsLength(elem), 0);\r\n\r\n return resultingLength - calculateMoves(from, to) + numberOfNeighbours;\r\n}\r\n\r\nfunction calculateMoves(from, to) {\r\n return (to.start > from.end ? to.start - from.end - 1 : from.start - to.end - 1) * calculateSheepsLength(from);\r\n}\r\n\r\nfunction calculateSheepsLength(sheeps) {\r\n return sheeps.end - sheeps.start + 1;\r\n}"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var n = Number(readline());\r\n var positions = readline();\r\n\r\n var map = [];\r\n for (var i = 0; i < positions.length; ++i) {\r\n if (positions[i] === \"*\") {\r\n var sheeps = {\r\n start: i\r\n }\r\n\r\n while (i + 1 < positions.length && positions[i + 1] === \"*\") {\r\n ++i;\r\n }\r\n\r\n sheeps.end = i;\r\n map.push(sheeps);\r\n }\r\n }\r\n\r\n if (map.length < 2) {\r\n return print(\"0\");\r\n }\r\n\r\n var movesCount = 0;\r\n\r\n while (map.length > 1) {\r\n var bestMove = {\r\n value: Number.NEGATIVE_INFINITY,\r\n fromIndex: 0,\r\n toIndex: 0\r\n }\r\n \r\n for (var i = 0; i < map.length - 1; ++i) {\r\n var fromToMove = findMovementValue(map[i], map[i + 1], map);\r\n if (fromToMove > bestMove.value) {\r\n bestMove = {\r\n value: fromToMove,\r\n fromIndex: i,\r\n toIndex: i + 1\r\n }\r\n }\r\n \r\n var toFromMove = findMovementValue(map[i + 1], map[i], map);\r\n if (toFromMove > bestMove.value) {\r\n bestMove = {\r\n value: toFromMove,\r\n fromIndex: i + 1,\r\n toIndex: i\r\n }\r\n }\r\n }\r\n \r\n var movesNecessary = calculateMoves(map[bestMove.fromIndex], map[bestMove.toIndex]);\r\n movesCount += movesNecessary;\r\n \r\n var isMovingRight = map[bestMove.toIndex].start > map[bestMove.fromIndex].end;\r\n map.splice(isMovingRight ? bestMove.fromIndex : bestMove.fromIndex - 1, 2, {\r\n start: isMovingRight ? map[bestMove.fromIndex].start + movesNecessary : map[bestMove.toIndex].start,\r\n end: isMovingRight ? map[bestMove.toIndex].end : map[bestMove.fromIndex].end - movesNecessary\r\n })\r\n } \r\n\r\n print(movesCount);\r\n}\r\n\r\nfunction findMovementValue(from, to, map) {\r\n var resultingLength = calculateSheepsLength(from) + calculateSheepsLength(to);\r\n\r\n var numberOfNeighbours = (to.start > from.end\r\n ? map.filter(x => x.start > to.end)\r\n : map.filter(x => x.end < to.start)).reduce((acc, elem) => acc + calculateSheepsLength(elem), 0);\r\n\r\n return resultingLength - calculateMoves(from, to) + numberOfNeighbours;\r\n}\r\n\r\nfunction calculateMoves(from, to) {\r\n return (to.start > from.end ? to.start - from.end - 1 : from.start - to.end - 1) * calculateSheepsLength(from);\r\n}\r\n\r\nfunction calculateSheepsLength(sheeps) {\r\n return sheeps.end - sheeps.start + 1;\r\n}"}], "src_uid": "e094a3451b8b28be90cf54a4400cb916"} {"source_code": "(function(){print(function(){var e=-1;var t=+readline(),n={},r=[],i=readline().split(\" \").map(function(e,t){e=+e;n[e]=n[e]?n[e]+1:1;if(r.indexOf(e)===-1)r.push(e);return[e,t+1]});i=i.sort(function(e,t){return e[0]-t[0]});var s=0;r.forEach(function(e){if(n[e]===2)s++;else if(n[e]>1)s+=n[e]});if(s<2)return\"NO\";var o=[[],[],[]];r=[];i.forEach(function(e){if(r.indexOf(e[0])===-1)r.push(e[0])});r.forEach(function(t){var n=[];i.forEach(function(e){if(e[0]===t)n.push(e[1])});if(n.length===2){e++;switch(e%3){case 0:o[0].push(n[0],n[1]);o[1].push(n[0],n[1]);o[2].push(n[1],n[0]);break;case 1:o[0].push(n[0],n[1]);o[1].push(n[1],n[0]);o[2].push(n[0],n[1]);break;case 2:o[0].push(n[1],n[0]);o[1].push(n[0],n[1]);o[2].push(n[0],n[1]);break}}else{for(var r=0;r<3;r++)for(var s=r;s= 2) {\n numWays *= x.length;\n }\n }\n console.log((numWays >= 3 ? \"YES\" : \"NO\"));\n if (numWays >= 3) {\n for (pass = _l = 1; _l <= 3; pass = ++_l) {\n virtualPass = pass;\n for (_m = 0, _len2 = sorted.length; _m < _len2; _m++) {\n x = sorted[_m];\n if (x.length === 1) {\n process.stdout.write(\"\" + x[0] + \" \");\n }\n if (x.length === 2) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n virtualPass = 2;\n }\n }\n if (x.length >= 3) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \" + x[2] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[2] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[2] + \" \" + x[0] + \" \" + x[1] + \" \");\n }\n if (x.length > 3) {\n for (i = _n = 3, _ref = x.length; 3 <= _ref ? _n < _ref : _n > _ref; i = 3 <= _ref ? ++_n : --_n) {\n process.stdout.write(\"\" + x[i] + \" \");\n }\n }\n }\n }\n console.log(\"\");\n }\n }\n return console.log(\"\");\n };\n\n if ((typeof process !== \"undefined\" && process !== null ? process.stdin : void 0) != null) {\n source = \"\";\n readable = process.stdin;\n readable.on('data', function(chunk) {\n return source += chunk;\n });\n readable.on('end', function() {\n var i, _i, _len, _results;\n source = source.split(\"\\n\\n\");\n source = source.map(function(x) {\n return x.split(\"\\n\")[1];\n });\n source = source.map(function(x) {\n return x.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n });\n _results = [];\n for (_i = 0, _len = source.length; _i < _len; _i++) {\n i = source[_i];\n _results.push(solve(i));\n }\n return _results;\n });\n } else {\n buffer = '';\n console = {};\n console.log = function(x) {\n print(\"\" + buffer + x);\n return buffer = '';\n };\n process = {};\n process.stdout = {};\n process.stdout.write = function(x) {\n return buffer = \"\" + buffer + x;\n };\n source = readline();\n source = readline();\n source = source.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n solve(source);\n }\n\n}).call(this);\n"}], "negative_code": [{"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var buffer, console, process, readable, solve, source;\n\n solve = function(tasks) {\n var i, index, numWays, pass, sorted, value, virtualPass, x, _i, _j, _k, _l, _len, _len1, _len2, _m;\n sorted = [];\n for (i = _i = 0; _i <= 2000; i = ++_i) {\n sorted[i] = [];\n }\n for (index = _j = 0, _len = tasks.length; _j < _len; index = ++_j) {\n value = tasks[index];\n sorted[value].push(index + 1);\n }\n numWays = 1;\n for (_k = 0, _len1 = sorted.length; _k < _len1; _k++) {\n x = sorted[_k];\n if (x.length >= 2) {\n numWays *= x.length;\n }\n }\n console.log((numWays >= 3 ? \"YES\" : \"NO\"));\n if (numWays >= 3) {\n for (pass = _l = 1; _l <= 3; pass = ++_l) {\n virtualPass = pass;\n for (_m = 0, _len2 = sorted.length; _m < _len2; _m++) {\n x = sorted[_m];\n if (x.length === 1) {\n process.stdout.write(\"\" + x[0] + \" \");\n }\n if (x.length === 2) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n virtualPass = 2;\n }\n }\n if (x.length >= 3) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \" + x[2] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[2] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[2] + \" \" + x[0] + \" \" + x[1] + \" \");\n }\n }\n }\n console.log(\"\");\n }\n }\n return console.log(\"\");\n };\n\n if ((typeof process !== \"undefined\" && process !== null ? process.stdin : void 0) != null) {\n source = \"\";\n readable = process.stdin;\n readable.on('data', function(chunk) {\n return source += chunk;\n });\n readable.on('end', function() {\n var i, _i, _len, _results;\n source = source.split(\"\\n\\n\");\n source = source.map(function(x) {\n return x.split(\"\\n\")[1];\n });\n source = source.map(function(x) {\n return x.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n });\n _results = [];\n for (_i = 0, _len = source.length; _i < _len; _i++) {\n i = source[_i];\n _results.push(solve(i));\n }\n return _results;\n });\n } else {\n buffer = '';\n console = {};\n console.log = function(x) {\n print(\"\" + buffer + x);\n return buffer = '';\n };\n process = {};\n process.stdout = {};\n process.stdout.write = function(x) {\n return buffer = \"\" + buffer + x;\n };\n source = readline();\n source = readline();\n source = source.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n solve(source);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var buffer, console, process, readable, solve, source;\n\n solve = function(tasks) {\n var i, index, numWays, pass, sorted, value, virtualPass, x, _i, _j, _k, _l, _len, _len1, _len2, _m;\n sorted = [];\n for (i = _i = 0; _i <= 2000; i = ++_i) {\n sorted[i] = [];\n }\n for (index = _j = 0, _len = tasks.length; _j < _len; index = ++_j) {\n value = tasks[index];\n sorted[value].push(index + 1);\n }\n numWays = 1;\n for (_k = 0, _len1 = sorted.length; _k < _len1; _k++) {\n x = sorted[_k];\n if (x.length >= 2) {\n numWays *= x.length;\n }\n }\n console.log((numWays >= 3 ? \"YES\" : \"NO\"));\n if (numWays >= 3) {\n for (pass = _l = 1; _l <= 3; pass = ++_l) {\n virtualPass = pass;\n for (_m = 0, _len2 = sorted.length; _m < _len2; _m++) {\n x = sorted[_m];\n if (x.length === 1) {\n process.stdout.write(\"\" + x[0] + \" \");\n }\n if (x.length === 2) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \");\n virtualPass = 2;\n }\n }\n if (x.length === 3) {\n if (virtualPass === 1) {\n process.stdout.write(\"\" + x[0] + \" \" + x[1] + \" \" + x[2] + \" \");\n }\n if (virtualPass === 2) {\n process.stdout.write(\"\" + x[1] + \" \" + x[2] + \" \" + x[0] + \" \");\n }\n if (virtualPass === 3) {\n process.stdout.write(\"\" + x[2] + \" \" + x[0] + \" \" + x[1] + \" \");\n }\n }\n }\n console.log(\"\");\n }\n }\n return console.log(\"\");\n };\n\n if (typeof process !== \"undefined\" && process !== null) {\n source = \"\";\n readable = process.stdin;\n readable.on('data', function(chunk) {\n return source += chunk;\n });\n readable.on('end', function() {\n var i, _i, _len, _results;\n source = source.split(\"\\n\\n\");\n source = source.map(function(x) {\n return x.split(\"\\n\")[1];\n });\n source = source.map(function(x) {\n return x.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n });\n _results = [];\n for (_i = 0, _len = source.length; _i < _len; _i++) {\n i = source[_i];\n _results.push(solve(i));\n }\n return _results;\n });\n } else {\n buffer = '';\n console = {};\n console.log = function(x) {\n print(\"\" + buffer + x);\n return buffer = '';\n };\n process = {};\n process.stdout = {};\n process.stdout.write = function(x) {\n return buffer = \"\" + buffer + x;\n };\n source = readline();\n source = readline();\n source = source.split(/\\s/g).map(function(z) {\n return parseInt(z, 10);\n });\n solve(source);\n }\n\n}).call(this);\n"}, {"source_code": ";(function () {\n\n\tprint(function () {\n\n\t\tvar qw = true;\n\t\t\n\t\tvar n = +readline(),\n\t\t\tm = {}, lib = [],\n\t\t\th = readline().split(' ').map(function (e, i) {\n\t\t\t\te = +e;\n\t\t\t\tm[e] = m[e] ? m[e] + 1 : 1;\n\t\t\t\tif (lib.indexOf(e) === -1) lib.push(e);\n\t\t\t\treturn [e, i+1];\n\t\t\t});\n\n\t\th = h.sort(function (a, b) { return a[0] - b[0]; });\n\n\t\tvar flag = false;\n\t\tlib.forEach(function (e) {\n\t\t\tif (m[e] === 1) flag = true;\n\t\t});\n\n\t\tif (flag) return 'NO';\n\n\t\tvar ret = [[], [], []];\n\n\t\tlib = [];\n\t\th.forEach(function (e) {\n\t\t\tif (lib.indexOf(e[0]) === -1) lib.push(e[0]);\n\t\t});\n\n\t\tlib.forEach(function (e) {\n\t\t\tvar a = [];\n\t\t\th.forEach(function (j) {\n\t\t\t\tif (j[0] === e) a.push(j[1]);\n\t\t\t});\n\n\t\t\tif (a.length === 2) {\n\t\t\t\tqw = !qw;\n\t\t\t\tif (qw) {\n\t\t\t\t\tret[0].push(a[0], a[1]);\n\t\t\t\t\tret[1].push(a[0], a[1]);\n\t\t\t\t\tret[2].push(a[1], a[0]);\n\t\t\t\t} else {\n\t\t\t\t\tret[0].push(a[0], a[1]);\n\t\t\t\t\tret[1].push(a[1], a[0]);\n\t\t\t\t\tret[2].push(a[1], a[0]);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (var j = 0; j < 3; j++)\n\t\t\t\t\tfor (var i = j; i < a.length; i++) ret[j].push(a[i]);\n\t\t\t\tret[1].push(a[0]);\n\t\t\t\tret[2].push(a[0], a[1]);\n\t\t\t}\n\t\t});\n\n\t\tvar n = 3;\n\t\twhile (n--) {\n\t\t\tret[n] = ret[n].join(' ');\n\t\t}\n\n\t\tret.unshift('YES');\n\n\t\treturn ret.join('\\n');\n\n\t}());\n\n}.call(this));\n"}, {"source_code": "(function(){print(function(){var e=-1;var t=+readline(),n={},r=[],i=readline().split(\" \").map(function(e,t){e=+e;n[e]=n[e]?n[e]+1:1;if(r.indexOf(e)===-1)r.push(e);return[e,t+1]});i=i.sort(function(e,t){return e[0]-t[0]});var s=0;r.forEach(function(e){if(n[e]>1)s+=n[e]});if(s<2)return\"NO\";var o=[[],[],[]];r=[];i.forEach(function(e){if(r.indexOf(e[0])===-1)r.push(e[0])});r.forEach(function(t){var n=[];i.forEach(function(e){if(e[0]===t)n.push(e[1])});if(n.length===2){e++;switch(e%3){case 0:o[0].push(n[0],n[1]);o[1].push(n[0],n[1]);o[2].push(n[1],n[0]);break;case 1:o[0].push(n[0],n[1]);o[1].push(n[1],n[0]);o[2].push(n[0],n[1]);break;case 2:o[0].push(n[1],n[0]);o[1].push(n[0],n[1]);o[2].push(n[0],n[1]);break}}else{for(var r=0;r<3;r++)for(var s=r;s 0; i -= 2){\r\n\t\t\tvar tmp = list[i - 1];\r\n\t\t\tlist[i - 1] = list[i];\r\n\t\t\tlist[i] = tmp;\r\n\t\t}\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var value = parseInt(readline());\r\n var result = \"\";\r\n if (value % 2 === 0)\r\n {\r\n for (var j = 1; j <= value; j+=2)\r\n {\r\n result += `${j+1} ${j} `;\r\n }\r\n }\r\n else \r\n {\r\n result += \"1 \";\r\n for (var j = 2; j <= value; j+=2)\r\n {\r\n result += `${j+1} ${j} `;\r\n }\r\n }\r\n print(result);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n var ans = [];\r\n var start = 1;\r\n if (n & 1) {\r\n start = 2;\r\n ans.push(1);\r\n }\r\n for (var i = start; i < n; i+=2) {\r\n ans.push(i+1);\r\n ans.push(i);\r\n }\r\n print(ans.join(' '));\r\n }"}, {"source_code": "let ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0], e = 0, g = 0\n for(j = 1; j <= n; j++){\n var k = Number(lines[j]) \n e = '', g = ''\n if(k % 2 == 1){\n e = '1' + ' '\n for(l = 1; l < k; l+=2){\n e += (l + 2) + ' ' + (l + 1) + ' '\n }\n console.log(e)\n }else{\n for(l = 2; l <= k; l+=2){\n e += (l) + ' ' + (l - 1) + ' '\n }\n console.log(e)\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n var ans = '';\n if(n % 2 == 1){\n var a = 1;\n for(j = 0; j < n; j++){\n ans += a + ' ';\n if(j === 0){\n a += 2;\n }else if(j % 2 == 1){\n a--;\n }else if(j % 2 === 0){\n a += 3;\n }\n }\n }else{\n var b = 2;\n for(j = 0; j < n; j++){\n ans += b + ' ';\n if(j % 2 === 0){\n b--;\n }else if(j % 2 == 1){\n b += 3;\n }\n }\n }\n console.log(ans);\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var res = solveMeFirst(b);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(p) {\r\n let arr = [];\r\n if (p % 2 === 0) {\r\n arr.push(2);\r\n } else if (p > 1) {\r\n arr.push(1);\r\n arr.push(3);\r\n } else {\r\n arr.push(1);\r\n }\r\n let isMinus = true;\r\n for (let i = p % 2 === 0 ? 1 : 2; i < p; i++) {\r\n if (isMinus) {\r\n arr[i] = arr[i - 1] - 1;\r\n isMinus = false;\r\n } else {\r\n arr[i] = arr[i - 1] + 3;\r\n isMinus = true;\r\n }\r\n }\r\n return arr;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n // const nk = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const n = nk[0];\n // const k = nk[1];\n\n const n = parseInt(readLine().trim(), 10);\n let a = []\n\n if (n%2 == 0) {\n for (let i = n; i > 0; i-=2) {\n a.push(i - 1)\n a.push(i)\n }\n } else {\n for (let i = n; i > 1; i-=2) {\n a.push(i - 1)\n a.push(i)\n }\n a.push(1)\n }\n\n a = a.reverse()\n // console.log(a)\n let s = \"\"\n for (let i = 0; i < a.length; i++) {\n // console.log(a[i])\n s += a[i] + \" \"\n }\n\n s.slice(0, -1);\n console.log(s)\n\n // const p = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const q = p\n // if (k == n || k == 0) {\n // console.log(\"0\");\n // } else {\n // const p1 = p.slice(0, k)\n // q.sort(function(a, b){return a-b});\n\n // let count = 0\n // for (let i = 0; i < k; i++) {\n // if (!p1.includes(q[i])) count++\n // }\n\n // console.log(count)\n // }\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const val = readLine().trim()\n // if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n // else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n // var [n, k] = readline().split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var n = readline();\r\n var a = [];\r\n if(n % 2 == 0) {\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = parseInt(readline(), 10);\r\n\r\n let result = [];\r\n let i = 0;\r\n if (n % 2 === 0) {\r\n result.push(2);\r\n result.push(1);\r\n i = 3;\r\n for (; i <= n; i++) {\r\n i % 2 === 0 ? result.push(i - 1) : result.push(i + 1);\r\n }\r\n } else {\r\n result.push(1);\r\n i = 2;\r\n for (; i <= n; i++) {\r\n i % 2 === 0 ? result.push(i + 1) : result.push(i - 1);\r\n }\r\n }\r\n\r\n output(result.join(' '));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n const res = new Array(n);\r\n for (let i = n - 1; i >= 0; i -= 2) {\r\n if (i === 0) {\r\n res[i] = 1;\r\n } else {\r\n res[i] = i;\r\n res[i - 1] = i + 1;\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = 0\n for(j = 1; j <= n ;j ++){\n var k = lines[j]\n a = k + ' '\n for(l = 1; l < k; l++){\n a += l + ' '\n }\n console.log(a)\n \n }\n \n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var f = false\n var h = lines[j].split('')\n var r = lines[j].split('')\n h.reverse()\n console.log(h, r)\n if(h == r){\n for(l = 0 ; l < h.length; l++){\n if(h[l] == h[l + 1]){\n f = true\n }else{\n f = false\n h.splice(0, 0, h[1], h[0])\n h.splice(2, 2)\n break;\n }\n }\n if(f === true){\n console.log(-1)\n }else{\n console.log(h)\n }\n }else{\n console.log(lines[j], 'dasd')\n }\n \n }\n});\n "}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n for(i = 1; i <= n; i++){\n var t = lines[i];\n \n }\n console.log(1);\n console.log(2, 1);\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var res = solveMeFirst(b);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(p) {\r\n let arr = [];\r\n for (let i = +p; i >= 1; i--) {\r\n arr.push(i);\r\n }\r\n return arr;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n // const nk = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const n = nk[0];\n // const k = nk[1];\n\n const n = parseInt(readLine().trim(), 10);\n let a = []\n\n for (let i = n; i > 0; i --) {\n a.push(i)\n }\n\n let s = \"\"\n for (let i = 0; i < a.length; i++) {\n // console.log(a[i])\n s += a[i] + \" \"\n }\n\n s.slice(0, -1);\n console.log(s)\n\n // const p = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const q = p\n // if (k == n || k == 0) {\n // console.log(\"0\");\n // } else {\n // const p1 = p.slice(0, k)\n // q.sort(function(a, b){return a-b});\n\n // let count = 0\n // for (let i = 0; i < k; i++) {\n // if (!p1.includes(q[i])) count++\n // }\n\n // console.log(count)\n // }\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const val = readLine().trim()\n // if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n // else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}], "src_uid": "be3295b4d43a11ee94022b103f4221a5"} {"source_code": "readline();\nvar a = readline().split( \" \" ).map( ai => parseInt( ai, 10 ) );\nvar values = [...new Set( a )];\nvar answer = \"NO\";\n// min + x = mid = max - x can't be equal to some other number.\nif ( values.length == 3 ) {\n values.sort( ( a, b ) => a - b );\n var min = values[ 0 ];\n var mid = values[ 1 ];\n var max = values[ 2 ];\n var x = ( max - min ) / 2;\n if ( Math.floor( x ) == x && min + x == mid && mid == max - x ) {\n answer = \"YES\";\n }\n} else if ( values.length < 3 ) {\n answer = \"YES\";\n}\nprint( answer );", "positive_code": [{"source_code": "function readIntTabLine(n) {\n var l = readline().split(' ')\n for (var i = 0 ; i < n ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar n = parseInt(readline())\nvar tab = readIntTabLine(n)\nvar possible = true\nvar set = []\n\nfor (var i = 0 ; i < n && possible; i++) {\n if (set.indexOf(tab[i]) == -1)\n possible = set.push(tab[i]) <= 3\n}\n\nif (!possible) print('NO')\nelse if (set.length < 3) print('YES')\nelse {\n var tri = []\n tri.push(Math.min.apply(null, set))\n set.splice(set.indexOf(tri[0]),1)\n tri.push(Math.min(set[0],set[1]))\n tri.push(Math.max(set[0],set[1]))\n if (tri[1]-tri[0] == tri[2]-tri[1]) print('YES')\n else print('NO')\n}\n"}, {"source_code": "readline();\nvar a = readline().split( \" \" ).map( ai => parseInt( ai, 10 ) );\nvar values = [...new Set( a )];\nvar answer = \"NO\";\n// min + x = mid = max - x are only possible combinations of x and some number.\nif ( values.length == 3 ) {\n values.sort( ( a, b ) => a - b );\n var min = values[ 0 ];\n var mid = values[ 1 ];\n var max = values[ 2 ];\n // Derived from equation above.\n if ( 2 * mid == max + min ) {\n answer = \"YES\";\n }\n} else if ( values.length < 3 ) {\n answer = \"YES\";\n}\nprint( answer );"}], "negative_code": [], "src_uid": "27f837609b2777cefccb13aa4596d91c"} {"source_code": "'use strict';\n\n\nlet line = readline().split(' ');\nlet n = parseInt(line[0]);\nlet m = parseInt(line[1]);\nconst container = {};\nlet command, ip;\nwhile (n--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1];\n container[ip] = command;\n}\n\nwhile (m--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1].substr(0, line[1].length - 1);\n print (`${command} ${ip}; #${container[ip]}`);\n}\n", "positive_code": [{"source_code": "var dim = readline().split(' ');\nvar n = parseInt(dim[0]);\nvar m = parseInt(dim[1]);\nvar k, mydns = {};\nfor(k = 1; k <= n; k++){\n\tvar server = readline().split(' ');\n\tmydns[server[1]] = server[0];\n}\n\nfor(k = 0; k < m; k++){\n\tvar command = readline().split(/[; ]/);\n\tprint(command[0] + ' ' + command[1] + '; #' + mydns[command[1]]);\n}\n"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet [namesLength, commandsLenght] = [null];\nlet ips = [], names = [], commands = [];\n\nreadline.on('line', line => {\n if (!namesLength) {\n [namesLength, commandsLenght] = line.split(' ');\n } else if (names.length < namesLength) {\n let [a, b] = line.split(' ');\n names.push(a);\n ips.push(b);\n } else {\n commands.push(line.split(' '));\n if (commands.length == commandsLenght)\n readline.close();\n }\n});\n\nreadline.on('close', () => {\n writeFile();\n});\n\nconst writeFile = () => {\n commands.map(input => {\n let [name, target] = input;\n let origin = names[ips.indexOf(target.split(';')[0])];\n console.log(`${name} ${target} #${origin}`);\n })\n};"}, {"source_code": "nm = readline().split(' ').map(Number);\n\nvar n = nm[0], m = nm[1], nameArr = [];\n\nfor (var i = 0; i < n; i++) {\n\tstr = readline().split(' ');\n\n\tfor (var j = 0; j < str.length; j++) {\n\t\tnameArr.push(str[j]);\n\t};\n};\n\nfor (var j = 0; j < m; j++) {\n\tstr = readline().split(' ');\n\n\tfor (var k = 0; k < nameArr.length; k++) {\n\t\tif (nameArr[k] + ';' == str[1]) {\n\t\t\tprint(str.join(' ') + ' #' + nameArr[k - 1]);\n\t\t};\n\t};\n};"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nconst obj = {};\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n\n c++;\n return;\n }\n\n if (c <= n) {\n const [name, ip] = d.split(' ');\n obj[`${ip};`] = `#${name}`;\n\n c++;\n return;\n }\n\n const [command, ip] = d.split(' ');\n console.log(`${command} ${ip} ${obj[ip]}`);\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "'use strict';\n\n\nlet line = readline().split(' ');\nlet n = parseInt(line[0]);\nlet m = parseInt(line[1]);\nconst container = {};\nlet command, ip;\nwhile (n--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1];\n container[ip] = command;\n}\n\nwhile (m--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1].substr(0, line[1].length - 1);\n print (command + ' ' + ip + '; #' + container[ip]);\n}\n"}, {"source_code": "var l=readline().split(\" \");\nvar n=parseInt(l[0]);\nvar m=parseInt(l[1]);\nvar an=new Array(n);\nvar am=new Array(m);\nfor(var i=0;i item.ip === ip);\n result.push(line + ' #' + item.name);\n }\n\n for (var i = 0; i < m; i++) {\n print(result[i]);\n }\n}\n\nmain();\n"}, {"source_code": "var a = readline().split(\" \");\nvar n = parseInt(a[0]);\nvar m = parseInt(a[1]);\n\nvar nameArr = [];\nvar ipArr = [];\nvar funcArr = [];\n\nfor(var i = 0; i < n; i++)\n{\n var nInput = readline().split(\" \");\n var name = nInput[0];\n var ip = nInput[1] + \";\";\n\n nameArr.push(name);\n ipArr.push(ip);\n}\n\nfor(var i = 0; i < m; i++)\n{\n var mInput = readline().split(\" \");\n var func = mInput[0];\n var ip = mInput[1];\n\n funcArr.push(ip);\n funcArr.push(func);\n}\n\nfor(var i = 0; i < (2 * m); i += 2)\n{\n var ip = funcArr[i];\n var func = funcArr[i + 1];\n\n for(var j = 0; j < n; j++)\n {\n if(ip == ipArr[j])\n {\n var name = nameArr[j];\n break;\n }\n }\n\n print(func + \" \" + ip + \" #\" + name);\n}"}], "negative_code": [{"source_code": "'use strict';\n\nlet line = readline().split(' ');\nlet n = parseInt(line[0]);\nlet m = parseInt(line[1]);\nconst container = {};\nlet command, ip;\nwhile (n--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1];\n container[ip] = command;\n}\n\nwhile (m--) {\n line = readline().split(' ');\n command = line[0];\n ip = line[1].substr(0, ip.length - 1);\n print (command + ' ' + ip + '; #' + container[ip]);\n}\n"}, {"source_code": "var l=readline().split(\" \");\nvar n=parseInt(l[0]);\nvar m=parseInt(l[1]);\nvar ar=new Array(n);\nvar i2=0;\nvar full1=\"\",full2=\"\";\nvar ar2=new Array(m);\nfor(var i=0;i item.ip === ip);\n result.push(line + ' ' + item.name);\n }\n\n for (var i = 0; i < m; i++) {\n print(result[i]);\n }\n}\n\nmain();\n"}, {"source_code": "var dim = readline().split(' ');\n(function(n,m){\n\twrite(n+'***'+m);\n\treturn print();\n})(dim[0],dim[1]);"}], "src_uid": "94501cd676a9214a59943b8ddd1dd31b"} {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n) => {\r\n while (1) {\r\n let s = n.toString();\r\n let sum = 0n;\r\n for (const c of s) sum += BigInt(c);\r\n let res = gcd(n, sum);\r\n if (res > 1) return pr(s);\r\n n++;\r\n }\r\n};\r\n\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(BigInt(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve(n) {\r\n // if (n.length <= 2) return 0\r\n for (let i = BigInt(n); ; i++) {\r\n let len = i.toString().length\r\n let sum = i.toString().split('').map(i => +i).reduce((acc, i) => acc + i, 0)\r\n sum = BigInt(sum)\r\n for (let j = 2n; j <= sum; j++) {\r\n if (BigInt(i) % j === 0n && sum % j === 0n) return i.toString()\r\n }\r\n\r\n }\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) console.log(solve(inputArr[i]))\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n // let testCases = readline()\n // let testNum = 1,\n // ans = null\n // while(testCases--) {\n // ans = solve()\n // console.log('Case #' + (testNum++) + ': ' + ans)\n // }\n}\n\n// function to solve problems\nfunction solve (){\n let n = BigInt(readline())\n let sum = 0,\n gcdSum = 0n,\n count = 2,\n tempGcdSum = 0,\n ans = n\n\n // find smallest of n, n+1 and n+2\n sum = sumOfDigits(n)\n gcdSum = findGcdSum(n, sum)\n while (count-- && gcdSum == 1) {\n n++\n if (n % 10n == 0) {\n sum = sumOfDigits(n)\n } else {\n sum++\n }\n tempGcdSum = findGcdSum(n, sum)\n // console.log('tempGcdSum:', tempGcdSum)\n if (tempGcdSum != 1) {\n ans = n\n break\n }\n }\n console.log(ans.toString())\n}\n\nfunction sumOfDigits (n) {\n let ans = 0n\n while (n > 0) {\n ans += n % 10n\n n = BigInt(n/10n)\n }\n return ans\n}\n\nfunction findGcdSum (a, b) {\n if (b == 0)\n return a\n return findGcdSum(b, a%b)\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var a = BigInt(readline());\r\n\r\n // var a = read\r\n while (gcd(a,SUMnUMBER(a))<=1) a++\r\n console.log(a.toString())\r\n var values\r\n })\r\n // var b = a.sort((a, b) => Math.abs(a) - Math.abs(b))\r\n\r\n}\r\n\r\nfunction SUMnUMBER(x) {\r\n var sum = 0n\r\n while (x>0n){\r\n sum+=x% 10n\r\n x = x/10n\r\n }\r\n return sum\r\n}\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n // let testCases = readline()\n // let testNum = 1,\n // ans = null\n // while(testCases--) {\n // ans = solve()\n // console.log('Case #' + (testNum++) + ': ' + ans)\n // }\n}\n\n// function to solve problems\nfunction solve (){\n let n = readline().split(' ').map(x => +x)\n let sum = 0,\n gcdSum = 0,\n count = 2,\n tempGcdSum = 0,\n ans = 0\n\n // find smallest of n, n+1 and n+2\n sum = sumOfDigits(n)\n gcdSum = findGcdSum(n, sum)\n ans = +n\n while (count-- && gcdSum == 1) {\n n++\n if (n % 10 == 0) {\n sum = sumOfDigits(n)\n } else {\n sum ++\n }\n tempGcdSum = findGcdSum(n, sum)\n // console.log('tempGcdSum:', tempGcdSum)\n if (tempGcdSum != 1) {\n gcdSum = tempGcdSum\n ans = n\n break\n }\n }\n console.log(ans)\n}\n\nfunction sumOfDigits (n) {\n let ans = 0\n while (n > 0) {\n ans += n % 10\n n = parseInt(n/10)\n }\n return ans\n}\n\nfunction findGcdSum (a, b) {\n if (b == 0)\n return a\n return findGcdSum(b, a%b)\n}\n"}], "src_uid": "204e75827b7016eb1f1fbe1d6b60b03d"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [m, n] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n output[i] = solve(n, m, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, arr) {\n return binarySearch(1, 1e9, x => check(n, m, arr, x))\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\nfunction check(n, m, arr, min) {\n const map = {}\n let has2 = 0\n for (let i = 0; i < n; i++) {\n let has = 0\n for (let j = 0; j < m; j++) {\n if (arr[j][i] >= min) {\n map[j] = (map[j] || 0) + 1\n has = 1\n if (map[j] > 1) has2 = 1\n }\n }\n if (!has) return false\n }\n return has2\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n const lines = inputString.trim().split(\"\\n\").map(string => string.trim()).filter(Boolean);\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let shops, friends;\r\n let arr;\r\n\r\n while (T--) {\r\n [shops, friends] = lines[index++].split(' ').map(Number);\r\n arr = new Array(shops);\r\n \r\n for (let i = 0; i < shops; ++i) {\r\n arr[i] = lines[index++].split(' ').map(Number);\r\n }\r\n\r\n solve(shops, friends, arr);\r\n }\r\n}\r\n\r\nfunction solve(shops, friends, arr) { \r\n let [basicFriendMaxKey, basicFriendMinKey] = [0, 1];\r\n let [basicFriendMaxValue, basicFriendMinValue] = [\r\n Math.max(arr[0][0], arr[0][1]),\r\n Math.min(arr[0][0], arr[0][1]),\r\n ];\r\n let curMaxKey, prevMaxKey;\r\n let curMaxValue, prevMaxValue;\r\n\r\n let friendsMap = new Array(friends).fill(0);\r\n\r\n for (let i = 0; i < shops; ++i) {\r\n [curMaxKey, prevMaxKey] = [0, 1];\r\n [curMaxValue, prevMaxValue] = [0, 0];\r\n\r\n for (let j = 0; j < friends; ++j) {\r\n if (arr[i][j] >= curMaxValue) {\r\n prevMaxValue = curMaxValue;\r\n prevMaxKey = curMaxKey;\r\n \r\n curMaxValue = arr[i][j];\r\n curMaxKey = j;\r\n } else if (arr[i][j] >= prevMaxValue) {\r\n prevMaxValue = arr[i][j];\r\n prevMaxKey = j;\r\n }\r\n }\r\n\r\n if (prevMaxValue > basicFriendMinValue) {\r\n basicFriendMinValue = prevMaxValue;\r\n basicFriendMinKey = prevMaxKey;\r\n \r\n \r\n basicFriendMaxValue = curMaxValue;\r\n basicFriendMaxKey = curMaxKey;\r\n }\r\n }\r\n\r\n friendsMap[basicFriendMinKey] = basicFriendMinValue;\r\n friendsMap[basicFriendMaxKey] = basicFriendMaxValue;\r\n\r\n for (let i = 0; i < shops; ++i) { \r\n for (let j = 0; j < friends; ++j) { \r\n if (j === basicFriendMinKey || j === basicFriendMaxKey) {\r\n continue;\r\n }\r\n\r\n friendsMap[j] = Math.max(friendsMap[j], arr[i][j]);\r\n }\r\n }\r\n\r\n console.log(Math.min(...friendsMap));\r\n}"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet m;\r\nlet n;\r\nlet p;\r\nfunction can(mid) {\r\n const friends = af(n).fill(0);\r\n const shops = af(m).fill(0);\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (p[i][j] >= mid) {\r\n friends[j]++;\r\n shops[i]++;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (friends[i] == 0) {\r\n return false;\r\n }\r\n }\r\n for (let i = 0; i < m; i++) {\r\n if (shops[i] > 1) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n m = nextInt();\r\n n = nextInt();\r\n p = Array.from({ length: m });\r\n let mx = 0;\r\n for (let i = 0; i < m; i++) {\r\n p[i] = af(n);\r\n for (let j = 0; j < n; j++) {\r\n p[i][j] = nextInt();\r\n mx = Math.max(mx, p[i][j]);\r\n }\r\n }\r\n let lo = 0;\r\n let hi = mx + 1;\r\n let ans = 0;\r\n while (lo < hi) {\r\n let mid = lo + Math.trunc((hi - lo) / 2);\r\n if (!can(mid)) {\r\n hi = mid;\r\n }\r\n else {\r\n lo = mid + 1;\r\n ans = mid;\r\n }\r\n }\r\n printf(\"%d\\n\", ans);\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [m, n] = rna();\r\n\t\tconst p = [];\r\n\t\tfor (let i = 0; i < m; i++)\r\n\t\t\tp[i] = rna();\r\n\r\n\t\tconst mxjoy = Array(n).fill(0);\r\n\t\tlet mxsmx = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tlet fmx = 0, smx = 0;\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tmxjoy[j] = Math.max(mxjoy[j], p[i][j]);\r\n\t\t\t\tif (p[i][j] > fmx) {\r\n\t\t\t\t\t[fmx, smx] = [p[i][j], fmx]\r\n\t\t\t\t} else if (p[i][j] > smx) \r\n\t\t\t\t\tsmx = p[i][j];\r\n\t\t\t}\r\n\t\t\tmxsmx = Math.max(mxsmx, smx);\r\n\t\t\t//console.log({mxsmx})\r\n\t\t}\r\n\r\n\t\tconst ans = Math.min(mxsmx, ...mxjoy);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n const lines = inputString.trim().split(\"\\n\").map(string => string.trim()).filter(Boolean);\r\n\r\n console.log(lines);\r\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n console.log(inputString);\r\n});"}], "src_uid": "5f8916876c2889cfe9265cd71905ad99"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n7\n4\n11 14 16 12\n2\n1 8\n4\n1 1 1 1\n4\n1 2 5 6\n2\n12 13\n6\n1 6 3 10 5 8\n6\n1 12 3 10 5 8\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r parseInt(val));\n\n var flag = false;\n arr = arr.sort((a, b) => a - b);\n for (var i = 1; i < arr.length; i++) {\n if (Math.abs(arr[i] - arr[i - 1] == 1) == 1) {\n arr = arr.slice(0, i - 1).concat(arr.slice(i + 1));\n i -= 2;\n flag = true;\n }\n }\n if (arr.length == 0) print(\"Yes\");\n else {\n var odd = arr.filter((val) => val % 2 != 0);\n var even = arr.filter((val) => val % 2 == 0);\n\n if (odd.length % 2 == 0 && even.length % 2 == 0) print(\"Yes\");\n else if (flag) {\n print(\"Yes\");\n } else print(\"NO\");\n }\n}\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n var arr = readNumArray().sort((a, b) => a - b);\n var evens = 0;\n var odds = 0;\n var curr = arr[0];\n var has1diff = false;\n for (var j = 0; j < n; j++) {\n if (arr[j] - curr === 1) {\n has1diff = true;\n }\n curr = arr[j];\n if (arr[j] % 2) {\n odds++;\n } else {\n evens++;\n }\n }\n if (has1diff || odds % 2 === 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n\n}\n\nmain();\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var k = 0; k < t; k++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar odd = [];\n\t\tvar even = [];\n\t\tfor(var i = 0; i < N; i++){\n\t\t\tif(list[i] % 2 == 1){\n\t\t\t\todd.push(list[i]);\n\t\t\t}else{\n\t\t\t\teven.push(list[i]);\n\t\t\t}\n\t\t}\n\t\tif(odd.length % 2 == 0 && even.length % 2 == 0){\n\t\t\toutput[k] = \"YES\";\n\t\t}else{\n\t\t\tvar isOK = false;\n\t\t\tfor(var i = 0; i < odd.length; i++){\n\t\t\t\tfor(var j = 0; j < even.length; j++){\n\t\t\t\t\tif(Math.abs(odd[i] - even[j]) == 1){\n\t\t\t\t\t\tisOK = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(isOK){\n\t\t\t\toutput[k] = \"YES\";\n\t\t\t}else{\n\t\t\t\toutput[k] = \"NO\";\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n const p = [0, 0]\n for (const t of arr) {\n p[t%2]++\n }\n if (p[0]%2 !==0) {\n arr.sort((a, b) => a-b)\n let prev = arr[0]\n for (let i=1;i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n readline();\n let force = readline().split(\" \").map(e => parseInt(e));\n const {pow, max, min} = Math;\n\n force.sort((a,b) => a - b);\n\n const odds = force.filter(f => f % 2 === 0);\n const even = force.filter(f => f % 2 === 1);\n\n\n if (odds.length % 2 === 0 && even.length % 2 === 0) {\n console.log('YES');\n } else {\n let follow = false;\n for (let i = 0; i < force.length - 1; i++) {\n const c1 = force[i];\n const c2 = force[i+1];\n if (Math.abs(c1 - c2) === 1) {\n follow = true;\n break;\n }\n }\n if (follow) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n\n\n\n\n\n\n //break;\n //console.log(Math.pow(Math.max(a,b) + Math.max(a,b) , 2))\n }\n\n\n}\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var arr = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n\n var differs = [];\n var reminders = [];\n reminders.push(arr[0] % 2);\n for (var i = 1; i < arr.length; i++) {\n differs.push(Math.abs(arr[i] - arr[i - 1]));\n reminders.push(arr[i] % 2);\n }\n if (differs.includes(1)) print(\"Yes\");\n else {\n var found = false;\n for (var i = 1; i < reminders.length; i++) {\n if (reminders[i] == reminders[i - 1]) {\n print(\"Yes\");\n found = true;\n break;\n }\n }\n if (!found) print(\"No\");\n }\n\n differs = differs.sort((a, b) => a - b);\n print(differs[0]);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var arr = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n\n var differs = [];\n var reminders = [];\n reminders.push(arr[0] % 2);\n for (var i = 1; i < arr.length; i++) {\n differs.push(Math.abs(arr[i] - arr[i - 1]));\n reminders.push(arr[i] % 2);\n }\n if (differs.includes(1)) print(\"Yes\");\n else {\n var found = false;\n for (var i = 1; i < reminders.length; i++) {\n if (reminders[i] == reminders[i - 1]) {\n print(\"Yes\");\n found = true;\n break;\n }\n }\n if (!found) print(\"No\");\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var arr = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n\n var differs = [];\n var reminders = [];\n reminders.push(arr[0] % 2);\n for (var i = 1; i < arr.length; i++) {\n differs.push(Math.abs(arr[i] - arr[i - 1]));\n reminders.push(arr[i] % 2);\n }\n reminders = reminders.sort((a, b) => a - b);\n if (differs.includes(1)) print(\"Yes\");\n else {\n var found = false;\n for (var i = 1; i < reminders.length; i++) {\n if (reminders[i] == reminders[i - 1]) {\n print(\"Yes\");\n found = true;\n break;\n }\n }\n if (!found) print(\"No\");\n }\n}\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var k = 0; k < t; k++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tfor(var i = 0; i < list.length; i++){\n\t\t\tif(list[i] == -1){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvar ato = list[i] + 1;\n\t\t\tvar mae = list[i] - 1;\n\t\t\tif(list.indexOf(ato) != -1){\n\t\t\t\tlist[i] = -1;\n\t\t\t\tlist[list.indexOf(ato)] = -1;\n\t\t\t}else if(list.indexOf(mae) != -1){\n\t\t\t\tlist[i] = -1;\n\t\t\t\tlist[list.indexOf(mae)] = -1;\n\t\t\t}\n\t\t}\n\t\tfor(var i = 0; i < list.length; i++){\n\t\t\tif(list[i] == -1){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(var j = 0; j < list.length; j++){\n\t\t\t\tif(list[j] == -1){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(i != j && (list[i] % 2 == list[j] % 2)){\n\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\tlist[j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvar isOK = true;\n\t\tfor(var i = 0; i < N; i++){\n\t\t\tif(list[i] != -1){\n\t\t\t\tisOK = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput[k] = \"YES\";\n\t\t}else{\n\t\t\toutput[k] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var k = 0; k < t; k++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tif(N % 4 == 2){\n\t\t\tfor(var i = 0; i < list.length; i++){\n\t\t\t\tif(list[i] == -1){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvar ato = list[i] + 1;\n\t\t\t\tvar mae = list[i] - 1;\n\t\t\t\tif(list.indexOf(ato) != -1){\n\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\tlist[list.indexOf(ato)] = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}else if(list.indexOf(mae) != -1){\n\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\tlist[list.indexOf(mae)] = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(var i = 0; i < list.length; i++){\n\t\t\t\tif(list[i] == -1){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor(var j = 0; j < list.length; j++){\n\t\t\t\t\tif(list[j] == -1){\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(i != j && (list[i] % 2 == list[j] % 2)){\n\t\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\t\tlist[j] = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tfor(var i = 0; i < list.length; i++){\n\t\t\t\tif(list[i] == -1){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor(var j = 0; j < list.length; j++){\n\t\t\t\t\tif(list[j] == -1){\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(i != j && (list[i] % 2 == list[j] % 2)){\n\t\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\t\tlist[j] = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(var i = 0; i < list.length; i++){\n\t\t\t\tif(list[i] == -1){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvar ato = list[i] + 1;\n\t\t\t\tvar mae = list[i] - 1;\n\t\t\t\tif(list.indexOf(ato) != -1){\n\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\tlist[list.indexOf(ato)] = -1;\n\t\t\t\t}else if(list.indexOf(mae) != -1){\n\t\t\t\t\tlist[i] = -1;\n\t\t\t\t\tlist[list.indexOf(mae)] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvar isOK = true;\n\t\tfor(var i = 0; i < N; i++){\n\t\t\tif(list[i] != -1){\n\t\t\t\tisOK = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput[k] = \"YES\";\n\t\t}else{\n\t\t\toutput[k] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n7\n4\n11 14 16 12\n2\n1 8\n4\n1 1 1 1\n4\n1 2 5 6\n2\n12 13\n6\n1 6 3 10 5 8\n6\n1 12 3 10 5 8\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r x - y);\n\n for(let i=0;i x !== undefined);\n if(!nums.length) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n}"}], "src_uid": "005a29a4b4e7ee4fd21444846014727b"} {"source_code": "'use strict';\n\nfunction createReadLine() {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readline() {\n return inputString[currentLine++];\n }\n\n return readline;\n}\n\nconst readline = createReadLine();\n\nfunction readInts(){\n return readline().split(' ').map((value => Number.parseInt(value)));\n}\n\nfunction readFloats(){\n return readline().split(' ').map((value => Number.parseFloat(value)));\n}\n\nfunction readStr() {\n return readline();\n}\n\nfunction readInt(){\n return Number.parseInt(readline());\n}\n\nfunction readFloat(){\n return Number.parseFloat(readline());\n}\n\n\n\nfunction main() {\n const n = readInt();\n const strs = []\n for (let i = 0; i < n; i ++){\n strs.push(readStr())\n }\n const result = solve(strs);\n console.log(result);\n}\n\nfunction makeStep(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\nfunction solve(strs){\n let set = strs.map(() => new Map());\n const firstLine = new Array(strs[0].length);\n firstLine[0] = strs[0]\n for (let j = 1; j < firstLine.length; j++){\n firstLine[j] = makeStep(strs[0], j)\n }\n set[0] = new Map([...new Set(firstLine)].map(((value, index) => [value, index])));\n for (let i = 1; i < set.length; i ++){\n for (let j = 0; j < strs[0].length; j ++){\n const current = makeStep(strs[i], j)\n let value = set[i -1].get(current);\n if(value === undefined) {\n value = -1;\n } else {\n const prev = makeStep(strs[i], j -1);\n const currentValue = set[i].get(current);\n if(currentValue) {\n continue;\n }\n if(prev !== current){\n value += j;\n }\n }\n set[i].set(current, value);\n }\n }\n return Math.min(...set[strs.length - 1].values())\n}\n\nmodule.exports.solve = solve;\n", "positive_code": [{"source_code": "'use strict';\n\nfunction createReadLine() {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readline() {\n return inputString[currentLine++];\n }\n\n return readline;\n}\n\nconst readline = createReadLine();\n\nfunction readInts(){\n return readline().split(' ').map((value => Number.parseInt(value)));\n}\n\nfunction readFloats(){\n return readline().split(' ').map((value => Number.parseFloat(value)));\n}\n\nfunction readStr() {\n return readline();\n}\n\nfunction readInt(){\n return Number.parseInt(readline());\n}\n\nfunction readFloat(){\n return Number.parseFloat(readline());\n}\n\n\n\nfunction main() {\n const n = readInt();\n const strs = []\n for (let i = 0; i < n; i ++){\n strs.push(readStr())\n }\n const result = solve(strs);\n console.log(result);\n}\n\nfunction makeStep(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\nfunction solve(strs){\n let set = strs.map(() => new Map());\n const firstLine = new Array(strs[0].length);\n firstLine[0] = strs[0]\n for (let j = 1; j < firstLine.length; j++){\n firstLine[j] = makeStep(strs[0], j)\n }\n set[0] = new Map([...new Set(firstLine)].map(((value, index) => [value, index])));\n for (let i = 1; i < set.length; i ++){\n for (let j = 0; j < strs[0].length; j ++){\n const current = makeStep(strs[i], j)\n let value = set[i -1].get(current);\n if(value === undefined) {\n return -1;\n } else {\n const prev = makeStep(strs[i], j -1);\n const currentValue = set[i].get(current);\n if(currentValue) {\n continue;\n }\n if(prev !== current){\n value += j;\n }\n }\n set[i].set(current, value);\n }\n }\n return Math.min(...set[strs.length - 1].values())\n}\n\nmodule.exports.solve = solve;\n"}, {"source_code": "var N = readline() | 0;\nvar lines = [];\nfor(var i = 0; i < N; ++i) {\n lines.push(readline());\n}\n\nvar results = lines.map(function (line) {\n return lines.map(function (x) {\n return (x+x).indexOf(line);\n });\n});\n\nif (results[0].indexOf(-1) >= 0) {\n print(-1);\n} else {\n print(results\n .map(function (x) { return x.reduce(function (a, x) { return a + x }, 0); })\n .reduce(function (a, x) { return Math.min(a,x); }, 10000000));\n}\n"}, {"source_code": "var l = [], res = 9999;\nfor (var i = Number(readline()); i > 0; i--) {\n var s = readline(), d = {};\n for (var j = s.length - 1; j >= 0; j--) d[s.substr(j) + s.substr(0, j)] = j;\n l.push(d)\n}\nfor (s in d) {\n var x = 0;\n for (var t of l) x += t.hasOwnProperty(s) ? t[s] : 9999;\n if (x >= 9999) res = -1;\n else if (res > x) res = x;\n}\nprint(res);\n"}, {"source_code": " var n = parseInt(readline());\n var s = [];\n String.prototype.rotate = function(x) {\n var a = x % this.length;\n var b;\n if(a > 0){\n b = this.length - a;\n } else {\n b = -a;\n }\n var c = this.substr(b, this.length);\n var d = this.substr(0, b);\n return c + d;\n };\n for(var i = 0; i < n; i += 1) {\n s[i] = readline();\n }\n var r = [];\n var t = [];\n var flag = true;\n var len = s[0].length;\n for(var i = 0; flag && i < n; i += 1) {\n var ok0 = false;\n var ok1 = false;\n for(var j = 0; j <= len; j += 1) {\n if(s[i].rotate(-j) == s[i] && j !== 0) {\n if(ok1 === false) {\n t[i] = j;\n ok1 = true;\n }\n }\n if(s[i].rotate(-j) == s[0]) {\n if(ok0 === false) {\n r[i] = j;\n ok0 = true;\n }\n }\n }\n if(ok0 == false) {\n flag = false;\n }\n }\n if(flag === false) {\n print(-1);\n } else {\n var res = Infinity;\n for(var i = 0; i < len; i += 1) {\n var tmp = 0;\n for(var j = 0; j < n; j += 1) {\n tmp += (r[j] + i) % t[j]; \n }\n res = Math.min(res, tmp);\n }\n print(res);\n }\n"}, {"source_code": "//@ts-check\n\n/**\n * @param {string} str\n * @param {number} steps\n */\nfunction makeSteps(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\n/**\n * @param {string[]} arr\n */\nfunction solve(arr) {\n const len = arr[0].length;\n const $ = arr.map(() => new Map());\n for (let j = 0; j < len; j++) {\n const target = makeSteps(arr[0], j);\n if (!$[0].has(target)) {\n $[0].set(makeSteps(arr[0], j), j);\n }\n }\n for (let i = 1; i < $.length; i++) {\n for (let j = 0; j < len; j++) {\n const target = makeSteps(arr[i], j);\n const currentSteps = $[i].has(target)\n ? $[i].get(target)\n : Number.POSITIVE_INFINITY;\n if ($[i - 1].has(target) || $[i - 1].get(target) === -1) {\n const prevLineSteps = $[i - 1].get(target);\n $[i].set(target, Math.min(currentSteps, prevLineSteps + j));\n } else {\n $[i].set(target, -1);\n }\n }\n }\n return Math.min(...$.pop().values());\n}\n\nfunction* main() {\n const n = parseInt(yield);\n const s = [];\n for (let index = 0; index < n; index++) {\n s.push(yield);\n }\n const r = solve(s);\n console.log(r);\n process.exit(0);\n}\n\nif (!module.parent) {\n (() => {\n const q = main();\n q.next();\n require(\"readline\")\n .createInterface({\n input: process.stdin,\n output: null,\n })\n .on(\"line\", (line) => q.next(line));\n })();\n}\n\nexports.solve = solve;\n"}, {"source_code": "'use strict';\n\nfunction createReadLine() {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readline() {\n return inputString[currentLine++];\n }\n\n return readline;\n}\n\nconst readline = createReadLine();\n\nfunction readInts(){\n return readline().split(' ').map((value => Number.parseInt(value)));\n}\n\nfunction readFloats(){\n return readline().split(' ').map((value => Number.parseFloat(value)));\n}\n\nfunction readStr() {\n return readline();\n}\n\nfunction readInt(){\n return Number.parseInt(readline());\n}\n\nfunction readFloat(){\n return Number.parseFloat(readline());\n}\n\n\n\nfunction main() {\n const n = readInt();\n const strs = []\n for (let i = 0; i < n; i ++){\n strs.push(readStr())\n }\n const result = solve(strs);\n console.log(result);\n}\n\nfunction makeStep(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\nfunction solve(strs){\n let set = strs.map(() => new Map());\n const firstLine = new Array(strs[0].length);\n firstLine[0] = strs[0]\n for (let j = 1; j < firstLine.length; j++){\n firstLine[j] = makeStep(strs[0], j)\n }\n set[0] = new Map([...new Set(firstLine)].map(((value, index) => [value, index])));\n const resultArr = new Array(strs.length).fill(0).map(() => new Array(strs[0].length).fill(0));\n const values = [...set[0].values()];\n resultArr[0] = [...strs[0]].map((val, index) => {\n if(values[index] !== undefined){\n return index;\n }\n return 0\n })\n for (let i = 1; i < set.length; i ++){\n for (let j = 0; j < strs[0].length; j ++){\n const current = makeStep(strs[i], j)\n let value = set[i -1].get(current);\n if(value === undefined) {\n value = -1;\n } else {\n const prev = makeStep(strs[i], j -1);\n const currentValue = set[i].get(current);\n if(currentValue) {\n resultArr[i][j] = currentValue;\n continue;\n }\n if(prev !== current){\n value += j;\n }\n }\n set[i].set(current, value);\n resultArr[i][j] = value;\n }\n }\n return Math.min(...resultArr[strs.length - 1])\n}\n\nmodule.exports.solve = solve;\n"}], "negative_code": [{"source_code": "//@ts-check\n\n/**\n * @param {string} str\n * @param {number} steps\n */\nfunction makeSteps(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\n/**\n * @param {string[]} arr\n */\nfunction solve(arr) {\n const len = arr[0].length;\n const $ = arr.map(() => new Map());\n for (let j = 0; j < len; j++) {\n $[0].set(makeSteps(arr[0], j), j);\n }\n for (let i = 1; i < $.length; i++) {\n for (let j = 0; j < len; j++) {\n const target = makeSteps(arr[i], j);\n if ($[i - 1].has(target) || $[i - 1].get(target) === -1) {\n const prevLineSteps = $[i - 1].get(target);\n $[i].set(target, prevLineSteps + j);\n } else {\n $[i].set(target, -1);\n }\n }\n }\n return Math.min(...$.pop().values());\n}\n\nfunction* main() {\n const n = parseInt(yield);\n const s = [];\n for (let index = 0; index < n; index++) {\n s.push(yield);\n }\n const r = solve(s);\n console.log(r);\n process.exit(0);\n}\n\nif (!module.parent) {\n (() => {\n const q = main();\n q.next();\n require(\"readline\")\n .createInterface({\n input: process.stdin,\n output: null,\n })\n .on(\"line\", (line) => q.next(line));\n })();\n}\n\nexports.solve = solve;\n"}, {"source_code": "'use strict';\n\nfunction createReadLine() {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readline() {\n return inputString[currentLine++];\n }\n\n return readline;\n}\n\nconst readline = createReadLine();\n\nfunction readInts(){\n return readline().split(' ').map((value => Number.parseInt(value)));\n}\n\nfunction readFloats(){\n return readline().split(' ').map((value => Number.parseFloat(value)));\n}\n\nfunction readStr() {\n return readline();\n}\n\nfunction readInt(){\n return Number.parseInt(readline());\n}\n\nfunction readFloat(){\n return Number.parseFloat(readline());\n}\n\n\n\nfunction main() {\n const n = readInt();\n const strs = []\n for (let i = 0; i < n; i ++){\n strs.push(readStr())\n }\n const result = solve(strs);\n console.log(result);\n}\n\nfunction makeStep(str, steps) {\n return str.slice(steps) + str.slice(0, steps);\n}\n\nfunction solve(strs){\n let set = strs.map(() => new Map());\n const firstLine = new Array(strs[0].length);\n firstLine[0] = strs[0]\n for (let j = 1; j < firstLine.length; j++){\n firstLine[j] = makeStep(strs[0], j)\n }\n set[0] = new Map([...new Set(firstLine)].map(((value, index) => [value, index])));\n const resultArr = new Array(strs.length).fill(0).map(() => new Array(strs[0].length).fill(0));\n const values = [...set[0].values()];\n resultArr[0] = [...strs[0]].map((_, index) => {\n if(values[index] !== undefined){\n return index;\n }\n return Math.max(...values)\n })\n for (let i = 1; i < set.length; i ++){\n for (let j = 0; j < strs[0].length; j ++){\n const current = makeStep(strs[i], j)\n let value = set[i -1].get(current);\n if(value === undefined) {\n value = -1;\n } else {\n const prev = makeStep(strs[i], j -1);\n if(prev !== current){\n value += j;\n }\n }\n set[i].set(current, value);\n resultArr[i][j] = value;\n }\n }\n return Math.min(...resultArr[strs.length - 1])\n}\n\nmodule.exports.solve = solve;\n"}, {"source_code": "\n var n = parseInt(readline());\n var s = [];\n String.prototype.rotate = function(x) {\n var a = x % this.length;\n var b;\n if(a > 0){\n b = this.length - a;\n } else {\n b = -a;\n }\n var c = this.substr(b, this.length);\n var d = this.substr(0, b);\n return c + d;\n };\n for(var i = 0; i < n; i += 1) {\n s[i] = readline();\n }\n var r = [];\n r[0] = 0;\n var flag = true;\n var len = s[0].length;\n for(var i = 1; flag && i < n; i += 1) {\n var ok = false;\n for(var j = 0; j < len; j += 1) {\n if(s[i].rotate(-j) == s[0]) {\n r[i] = j;\n ok = true;\n }\n }\n if(ok == false) {\n flag = false;\n }\n }\n if(flag === false) {\n print(-1);\n } else {\n var res = Infinity;\n for(var i = 0; i < len; i += 1) {\n var tmp = 0;\n for(var j = 0; j < n; j += 1) {\n tmp += (r[j] + i) % len; \n }\n res = Math.min(res, tmp);\n }\n print(res);\n }"}, {"source_code": " var n = parseInt(readline());\n var s = [];\n String.prototype.rotate = function(x) {\n var a = x % this.length;\n var b;\n if(a > 0){\n b = this.length - a;\n } else {\n b = -a;\n }\n var c = this.substr(b, this.length);\n var d = this.substr(0, b);\n return c + d;\n };\n for(var i = 0; i < n; i += 1) {\n s[i] = readline();\n }\n var r = [];\n r[0] = 0;\n var flag = true;\n var len = s[0].length;\n for(var i = 1; flag && i < n; i += 1) {\n var ok = false;\n for(var j = 0; j < len; j += 1) {\n if(s[i].rotate(-j) == s[0]) {\n r[i] = j;\n ok = true;\n break;\n }\n }\n if(ok == false) {\n flag = false;\n }\n }\n if(flag === false) {\n print(-1);\n } else {\n var res = Infinity;\n for(var i = 0; i < len; i += 1) {\n var tmp = 0;\n for(var j = 0; j < n; j += 1) {\n tmp += (r[j] + i) % len; \n }\n res = Math.min(res, tmp);\n }\n print(res);\n }\n"}], "src_uid": "a3a7515219ebb0154218ee3520e20d75"} {"source_code": "\"use strict\";\n\nvar foo = function(s1, s2) {\n var f = [];\n for (var i = 0, j = 0; j < s2.length; ++j) {\n if (i < s1.length && s1[i] === s2[j]) {\n ++i;\n } else {\n f.push(s2[j]);\n }\n }\n \n return [i === s1.length, f];\n};\n\nvar main = function() {\n var q = +rd();\n loop:while (q-->0) {\n var s = rd().split('');\n var t = rd().split('');\n var p = rd().split('');\n \n var f1 = foo(s, t);\n if (f1[0]) {\n var f2 = foo(f1[1].sort(), p.sort());\n if (f2[0]) {\n pr('YES');\n continue loop;\n }\n }\n \n pr('NO');\n }\n};\n \nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar prAr = (a) => pr(a.join(' '));\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n \nmain();", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nvar q, s, t, p;\n\nrl.on(\"line\", (line) => {\n\tif (q == null) q = parseInt(line);\n\telse if (s == null) s = line;\n\telse if (t == null) t = line;\n\telse if (p == null) {\n\t\tp = line;\n\t\t// begin to solve\n\t\tvar mp = {};\n\t\tvar len1 = s.length;\n\t\tvar len2 = t.length;\n\t\tvar len3 = p.length;\n\t\tfor (var i = 0; i < len3; i ++) {\n\t\t\tif (! mp[ p[i] ]) mp[ p[i] ] = 1;\n\t\t\telse mp[ p[i] ] ++;\n\t\t}\n\t\tvar flag = true;\n\t\tvar j = 0;\n\t\tfor (var i = 0; i < len2; i ++) {\n\t\t\tif (j < len1 && s[j] == t[i]) j ++;\n\t\t\telse if (mp[ t[i] ]) mp[ t[i] ] --;\n\t\t\telse {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (j < len1) flag = false;\n\t\tconsole.log( flag ? \"YES\" : \"NO\" );\n\t\t// end of solve\n\t\ts = t = p = null;\n\t\tq --;\n\t\tif (q == 0)\n\t\t\trl.close();\n\t} \n});"}, {"source_code": "const y = \"YES\";\nconst n = \"NO\";\nfunction solve(){\n var s = readline();\n var t = readline();\n var p = readline();\n if(s.length > t.length){\n print(n);\n return;\n }\n var jt = 0;\n var was = new Array(t.length);\n was.fill(0, 0, t.length);\n var buff = new Array(p.length);\n buff.fill(0, 0, p.length);\n for(var i = 0;i < t.length;i++){\n if(s[jt] == t[i]){\n was[i] = 1;\n jt++;\n if(jt == s.length){\n break;\n }\n }\n }\n if(jt != s.length){\n print(n);\n return;\n }\n for(var i = 0;i < t.length;i++){\n if(!was[i]){\n var can = 0;\n for(var j = 0;j < p.length;j++){\n if(!buff[j] && p[j] == t[i]){\n buff[j] = 1;\n can = 1;\n break;\n }\n }\n if(!can){\n print(n);\n return;\n }\n }\n }\n print(y);\n return;\n}\n\nvar t = Number(readline());\nwhile(t--){\n solve();\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nvar foo = function(s1, s2) {\n var f = [];\n for (var i = 0, j = 0; j < s2.length; ++j) {\n if (i < s1.length && s1[i] === s2[j]) {\n ++i;\n } else {\n f.push(s2[j]);\n }\n }\n \n return [i === s1.length, f];\n};\n\nvar main = function() {\n var q = +rd();\n loop:while (q-->0) {\n var s = rd().split('');\n var t = rd().split('');\n var p = rd().split('');\n \n var f1 = foo(s, t);\n if (f1[0]) {\n //pr(f1[1]);\n var f2 = foo(f1[1], p);\n if (f2[0]) {\n pr('YES');\n continue loop;\n }\n }\n \n pr('NO');\n }\n};\n \nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar prAr = (a) => pr(a.join(' '));\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n \nmain();"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nvar q, s, t, p;\n\nrl.on(\"line\", (line) => {\n\tif (q == null) q = parseInt(line);\n\telse if (s == null) s = line;\n\telse if (t == null) t = line;\n\telse if (p == null) {\n\t\tp = line;\n\t\t// begin to solve\n\t\tvar mp = {};\n\t\tvar len1 = s.length;\n\t\tvar len2 = t.length;\n\t\tvar len3 = p.length;\n\t\tfor (var i = 0; i < len3; i ++) {\n\t\t\tif (! mp[ p[i] ]) mp[ p[i] ] = 1;\n\t\t\telse mp[ p[i] ] ++;\n\t\t}\n\t\tvar flag = true;\n\t\tvar j = 0;\n\t\tfor (var i = 0; i < len2; i ++) {\n\t\t\tif (j < len1 && s[j] == t[i]) j ++;\n\t\t\telse if (mp[ t[i] ]) mp[ t[i] ] --;\n\t\t\telse {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tconsole.log( flag ? \"YES\" : \"NO\" );\n\t\t// end of solve\n\t\ts = t = p = null;\n\t\tq --;\n\t\tif (q == 0)\n\t\t\trl.close();\n\t} \n});"}], "src_uid": "a27ad7c21cd6402bfd082da4f6c7ab9d"} {"source_code": "var n = Number(readline());\nvar tab = new Array(n);\nfor (var i = 0; i < n; ++i) {\n tab[i] = readline();\n}\n\nvar sum = 0;\nfor (var i = 0; i < n; ++i) {\n var num = 0;\n for (var j = 0; j < n; ++j) {\n if (tab[i][j] === \"C\") {\n ++num;\n }\n }\n sum += num * (num - 1) / 2;\n}\nfor (var i = 0; i < n; ++i) {\n var num = 0;\n for (var j = 0; j < n; ++j) {\n if (tab[j][i] === \"C\") {\n ++num;\n }\n }\n sum += num * (num - 1) / 2;\n}\n\n\nprint(sum);", "positive_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar cnt = [];\nfor(var i = 0, s = 0; i <= 100; i++){\n s += i;\n cnt[i] = s;\n}\n\nvar n = rdn();\n\nvar ans = 0;\nvar cake = [];\nfor(var i = 0; i < n; i++){\n var line = readline();\n cake.push(line);\n var c = 0;\n for(var j = 0; j < n; j++){\n if(line[j] == \"C\") c++;\n }\n\n ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];\n}\n\nfor(var j = 0; j < n; j++){\n var c = 0;\n for(var i = 0; i < n; i++){\n if(cake[i][j] == \"C\") c++;\n }\n\n ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];\n}\n\nwrite(ans);\n\n"}, {"source_code": "var n = +readline();\nvar arr = [];\nfor(var i=0;i 1) {\n\t\t\tanswer += nCakes * (nCakes - 1) / 2; \n\t\t}\n\t\t\n\t\tnCakes = cakesInCol[i];\n\t\tif (nCakes > 1) {\n\t\t\tanswer += nCakes * (nCakes - 1) / 2; \n\t\t}\n\t}\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n3\n.CC\nC..\nC.C\noutput\n4\ninput\n4\nCC..\nC..C\n.CC.\n.CC.\noutput\n9\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar answer = 0;\n\tvar cakesInRow = []\n\tvar cakesInCol = []\n\tvar i, j;\n\tfor (i = n; i >= 0; i--) {\n\t\tcakesInRow[i] = 0;\n\t\tcakesInCol[i] = 0;\n\t}\n\n\tfor (i = 0; i < n; i++) {\n\t\tvar s = readline();\n\t\tfor (j = 0; j < n; j++) {\n\t\t\tif (s.charAt(j) == 'C') {\n\t\t\t\tcakesInRow[i]++;\n\t\t\t\tcakesInCol[j]++;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (i = 0; i < n; i++) {\n\t\tvar nCakes = cakesInRow[i];\n\t\tif (nCakes > 1) {\n\t\t\tanswer += nCakes * (nCakes - 1) / 2; \n\t\t}\n\t\t\n\t\tnCakes = cakesInCol[i];\n\t\tif (nCakes > 1) {\n\t\t\tanswer += nCakes * (nCakes - 1) / 2; \n\t\t}\n\t}\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "'use strict';\n\n\nconst n = Number(readline());\nlet cake = [];\nlet count = 0;\n\nfor (let i = 0; i < n; i++) {\n let line = readline().split('');\n count += calc(line.filter((c) => c === 'C').length); \n cake.push(line); \n}\n\nfor (let i = 0; i < n; i++) {\n let _line = [];\n for (let j = 0; j < n; j++) {\n _line.push(cake[j][i])\n }\n count += calc(_line.filter((c) => c === 'C').length);\n}\n\nprint(count)\n\n\nfunction calc(n) {\n return n * (n - 1) / 2;\n}\n"}, {"source_code": "var readInt = () => parseInt(readline())\nvar readIntArray = () => readline().split(' ').forEach(item => parseInt(item))\nvar fact = n => n > 0 ? n*fact(n-1) : 1;\n\nvar N = readInt()\nvar cake = []\nfor (var i = 0; i < N; i++) {\n cake.push(readline())\n}\n\nvar ans = 0\ncake.forEach(function(s,i) {\n var n = Array.prototype.filter.call(s, c => c === 'C').length\n if (n > 1)\n ans+=fact(n)/(2*fact(n-2))\n \n n = cake.map(s => s[i]).filter(c => c ==='C').length\n if (n > 1)\n ans+=fact(n)/(2*fact(n-2))\n})\nprint(ans)"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst t = {0: 0, 1: 0, 2: 1};\nconst matrix = []\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n const n = +d;\n for (let i = 3; i <= n; i++) {\n t[i] = t[i - 1] + i - 1;\n }\n return;\n }\n\n matrix.push([...d]);\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n let countX = 0;\n let countY = 0;\n\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'C') {\n countX++;\n }\n\n if (matrix[j][i] === 'C') {\n countY++;\n }\n }\n\n ans += t[countX];\n ans += t[countY];\n }\n\n console.log(ans);\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst t = {1: 0, 2: 1};\nconst matrix = []\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n const n = +d;\n for (let i = 3; i <= n; i++) {\n t[i] = t[i - 1] + i - 1;\n }\n return;\n }\n\n matrix.push([...d]);\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n let countX = 0;\n let countY = 0;\n\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'C') {\n countX++;\n }\n\n if (matrix[j][i] === 'C') {\n countY++;\n }\n }\n\n ans += t[countX];\n ans += t[countY];\n }\n\n console.log(ans);\n});\n"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar cnt = [];\nfor(var i = 0, s = 0; i <= 100; i++){\n s += i;\n cnt[i] = s;\n}\n\nvar n = rdn();\n\nvar ans = 0;\nvar cake = [];\nfor(var i = 0; i < n; i++){\n var line = readline();\n cake.push(line);\n var c = 0;\n for(var j = 0; j < n; j++){\n if(line[j] == \"C\") c++;\n }\n\n ans += cnt[c-1];\n}\n\nfor(var j = 0; j < n; j++){\n var c = 0;\n for(var i = 0; i < n; i++){\n if(cake[i][j] == \"C\") c++;\n }\n\n ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];\n}\n\nwrite(ans);\n\n"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar cnt = [];\nfor(var i = 0, s = 0; i <= 100; i++){\n s += i;\n cnt[i] = s;\n}\n\nvar n = rdn();\n\nvar ans = 0;\nvar cake = [];\nfor(var i = 0; i < n; i++){\n var line = readline();\n cake.push(line);\n var c = 0;\n for(var j = 0; j < n; j++){\n if(line[j] == \"C\") c++;\n }\n\n ans += cnt[c-1];\n}\n\nfor(var j = 0; j < n; j++){\n var c = 0;\n for(var i = 0; i < n; i++){\n if(cake[i][j] == \"C\") c++;\n }\n\n ans += cnt[c-1];\n}\n\nwrite(ans);\n\n"}], "src_uid": "7749f37aa9bf88a00013557e14342952"} {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nfunction query(arr){\n let set = new Set(arr);\n if (set.size==1)\n return print('NO');\n print('YES');\n let left = [], last;\n for (let i=1; i+a);\n query(arr);\n }\n}\n", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = [];\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line * 2;\n return;\n }\n\n data.push(line);\n \n if(lineNum - 1 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(data) { \n data.forEach((districts, i) => {\n if(i % 2 !== 0) {\n \n districts = districts.split(' ');\n const map = districts.reduce((acc, band, i) => {\n (band in acc) ?\n acc[band].push(i + 1) :\n acc[band] = [i + 1];\n return acc;\n }, {});\n\n const bands = Object.keys(map);\n if(bands.length > 1) {\n console.log('YES');\n for(let i = 0; i < bands.length; i++) {\n if(bands.length - 1 !== i) console.log(`${map[bands[i]][0]} ${map[bands[i + 1]][0]}`);\n\n if(i > 0) {\n for(let j = 1; j < map[bands[i - 1]].length; j++) {\n console.log(`${map[bands[i]][0]} ${map[bands[i - 1]][j]}`)\n }\n }\n\n if(bands.length - 1 === i) {\n for(let j = 1; j < map[bands[i]].length; j++) {\n console.log(`${map[bands[i - 1]][map[bands[i - 1]].length - 1]} ${map[bands[i]][j]}`)\n }\n }\n \n }\n } else {\n console.log('NO');\n }\n }\n })\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const map = new Map();\n\n for (let i = 0; i < len; i++) {\n const num = arr[i];\n if (map.has(num)) {\n map.set(num, [...map.get(num), i + 1]);\n } else {\n map.set(num, [i + 1]);\n }\n }\n\n if (map.size === 1) console.log(\"NO\");\n else {\n console.log(\"YES\");\n const values = [...map.values()];\n const [firstRow, secondRow] = [values[0], values[1]];\n for (let row = 1; row < values.length; row++) {\n for (let col = 0; col < values[row].length; col++) {\n console.log(`${firstRow[0]} ${values[row][col]}`);\n }\n }\n for (let col = 1; col < firstRow.length; col++) {\n console.log(`${secondRow[0]} ${firstRow[col]}`);\n }\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar tmp = nextIntArray();\n\t\tvar isOK = false;\n\t\tvar list = new Array(N);\n\t\tvar uf = unionFind(N);\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = {\n\t\t\t\tno : j,\n\t\t\t\tG : tmp[j],\n\t\t\t\tchild : new Set()\n\t\t\t}\n\t\t}\n\t\tvar connect = new Set();\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tfor(var k = j + 1; k < N; k++){\n\t\t\t\tif(list[j].child.has(list[k].no) || list[k].child.has(list[j].no)){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(list[j].G != list[k].G && !uf.isSame(j, k)){\n\t\t\t\t\tisOK = true;\n\t\t\t\t\tlist[j].child.add(list[k].no);\n\t\t\t\t\tlist[k].child.add(list[j].no);\n\t\t\t\t\tconnect.add((j + 1) + \":\" + (k + 1));\n\t\t\t\t\tuf.doUnion(j, k);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput.push(\"YES\");\n\t\t\tvar keys = Array.from(connect);\n\t\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\t\toutput.push(keys[j].split(\":\").join(\" \"));\n\t\t\t}\n\t\t}else{\n\t\t\toutput.push(\"NO\");\n\t\t}\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction unionFind(n){\n var uf = {\n //\u5168\u3066\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u300c-X(\u89aa\u3001\u7d76\u5bfe\u5024\u306f\u30b0\u30eb\u30fc\u30d7\u306e\u5927\u304d\u3055)\u300d\u300c\u81ea\u5206\u304c\u5c5e\u3059\u308b\u89aa(\u2252\u6839)\u300d\u306e\u3044\u305a\u308c\u304b\u3092\u6301\u3064\u3002\n //\u6700\u521d\u306f\u307f\u3093\u306a\u30b0\u30eb\u30fc\u30d7\u306e\u5927\u304d\u30551\u306e\u89aa\n \"list\" : new Array(n).fill(-1),\n \n //\u540c\u3058\u89aa\u3092\u6301\u3064\u304b\n \"isSame\" : function(mae, ato){\n return this.getRootIndex(mae) == this.getRootIndex(ato);\n },\n //\u81ea\u8eab\u306e\u89aa\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u305f\u3069\u3063\u3066\u6839\u3063\u3053\u306b\u7740\u304f\n //\u89aa\u306b\u305f\u3069\u308a\u7d42\u3048\u305f\u3089\u5b50\u306b\u5e30\u3063\u3066\u3044\u304f\u3064\u3044\u3067\u306b\u3001\u5b50\u305f\u3061\u306b\u300c\u5171\u901a\u306e\u89aa\u3092\u6301\u3063\u3066\u3044\u308b\u300d\u3053\u3068\u3092\u77e5\u3089\u305b\u308b\n \"getRootIndex\" : function(index){\n if(this.list[index] < 0){\n return index;\n }else{\n this.list[index] = this.getRootIndex(this.list[index]);\n return this.list[index];\n }\n },\n //\u7570\u306a\u308b\u89aa\u540c\u58eb\u306e\u307e\u3068\u307e\u308a\u3092\u4e00\u3064\u306b\u3059\u308b\uff08\u540c\u3058\u89aa\u306a\u3089\u30b9\u30eb\u30fc\uff09\n //\u5c0f\u3055\u3044\u30b0\u30eb\u30fc\u30d7\u306e\u89aa\u304c\u5927\u304d\u3044\u30b0\u30eb\u30fc\u30d7\u306e\u89aa\u306e\u76f4\u4e0b\u306b\u7740\u304f\n //\u30b0\u30eb\u30fc\u30d7\u306e\u5927\u304d\u3055\u3082\u66f4\u65b0\u3059\u308b\n \"doUnion\" : function(mae, ato){\n var maeRoot = this.getRootIndex(mae);\n var atoRoot = this.getRootIndex(ato);\n if(!this.isSame(maeRoot, atoRoot)){\n if(maeRoot >= atoRoot){\n this.list[maeRoot] += this.list[atoRoot];\n this.list[atoRoot] = maeRoot;\n }else{\n this.list[atoRoot] += this.list[maeRoot];\n this.list[maeRoot] = atoRoot;\n }\n }\n },\n //\u300c-X(\u89aa\u3001\u7d76\u5bfe\u5024\u306f\u30b0\u30eb\u30fc\u30d7\u306e\u5927\u304d\u3055)\u300d\n //\u306a\u306e\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u2192\u89aa\u3092\u77e5\u308b\u2192\u89aa\u306e\u6301\u3064\u30b0\u30eb\u30fc\u30d7\u306e\u5927\u304d\u3055\u304c\u308f\u304b\u308b\u3002\n //\u305f\u3060\u3057\u30de\u30a4\u30ca\u30b9\u5024\u306a\u306e\u3067\u3001\u639b\u3051\u7b97\u3057\u3066\u8fd4\u3059\u3002\n \"getSize\" : function(index){\n return -this.list[this.getRootIndex(index)];\n }\n }\n return uf;\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim();\n // const n = data[i] * 1;\n // const k = a[1];\n const s = data[i + 1].trim().split(' ').map(Number);\n // s.sort((a, b) => b - a);\n let idx = 0;\n let max = 0;\n let obj = {};\n \n for (let j = 0; j < s.length; j += 1) {\n if (obj[s[j]]) obj[s[j]].push(j);\n else obj[s[j]] = [j];\n // if (s[j] > max) {\n // max = s[j];\n // idx = j;\n // }\n }\n \n let arr = Object.values(obj);\n // console.log(arr);\n\n if (arr.length < 2) console.log('NO');\n else {\n console.log('YES');\n for (let j = 1; j < arr.length; j += 1) {\n for (let k = 0; k < arr[j].length; k += 1) {\n console.log(arr[0][0] + 1 + ' ' + (arr[j][k] + 1));\n }\n }\n for (let j = 1; j < arr[0].length; j += 1) {\n console.log(arr[1][0] + 1 + ' ' + (arr[0][j] + 1));\n }\n }\n \n i += 2;\n }\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return s[i++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt==r)).length==t)return void o.default.puts(\"NO\");o.default.puts(\"YES\");let n={};for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n districtConnections();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction districtConnections(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let count = 0;\n let map = new Array(1000000005);\n let x = [];\n for(let i = 0; i < n; i++){\n if(map[a[i]] === undefined){\n count++;\n map[a[i]] = i+1;\n x.push(a[i]);\n }\n\n if(count >= 2)\n break;\n }\n\n if(count < 2){\n console.log('NO');\n continue;\n }\n\n console.log('YES');\n let visited = new Array(n+1);\n\n for(let i = 1; i <= n; i++){\n if(a[i-1] !== x[0]){\n if(!(visited[i] && visited[map[x[0]]])){\n console.log(i, map[x[0]]);\n visited[i] = true;\n visited[map[x[0]]] = true;\n }\n }else{\n if(!(visited[i] && visited[map[x[1]]])){\n console.log(i, map[x[1]]);\n visited[i] = true;\n visited[map[x[1]]] = true;\n }\n }\n }\n }\n}"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar tmp = nextIntArray();\n\t\tvar isOK = false;\n\t\tvar list = new Array(N);\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = {\n\t\t\t\tno : j,\n\t\t\t\tG : tmp[j],\n\t\t\t\tchild : new Set()\n\t\t\t}\n\t\t}\n\t\tvar connect = 0;\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tif(connect == N - 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor(var k = j + 1; k < N; k++){\n\t\t\t\tif(list[j].child.has(list[k].no) || list[k].child.has(list[j].no)){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(list[j].G != list[k].G){\n\t\t\t\t\tisOK = true;\n\t\t\t\t\tlist[j].child.add(list[k].no);\n\t\t\t\t\tconnect++;\n\t\t\t\t\tif(connect == N - 1){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t//list[k].child.add(list[j].no);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput.push(\"YES\");\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tvar keys = Array.from(list[j].child);\n\t\t\t\tfor(var k = 0; k < keys.length; k++){\n\t\t\t\t\toutput.push((j + 1) + \" \" + (keys[k] + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\toutput.push(\"NO\");\n\t\t}\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n districtConnections();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction districtConnections(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let count = 0;\n let map = new Array(1000000005);\n let x = [];\n for(let i = 0; i < n; i++){\n if(map[a[i]] === undefined){\n count++;\n map[a[i]] = i+1;\n x.push(a[i]);\n }\n\n if(count >= 2)\n break;\n }\n\n if(count < 2){\n console.log('NO');\n continue;\n }\n\n console.log('YES');\n for(let i = 1; i < n; i++){\n if(a[i-1] !== x[0]){\n console.log(i, map[x[0]]);\n }else{\n console.log(i, map[x[1]]);\n }\n }\n }\n}"}], "src_uid": "d8136eb72931851f501c5ce9042ce4eb"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tif(list.indexOf(1) == -1){\r\n\t\t\tmyout(\"NO\");\r\n\t\t}else{\r\n\t\t\tmyout(\"YES\");\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n var a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0];\n }else{\n var ans = 0;\n var flag = false;\n for(j = 0; j < n; j++){\n if(a[j] == 1){\n flag = true;\n break;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,k]=line[2*_-1].split(' ').map(x=>{return parseInt(x)});\r\n let a=line[2*_].split(' ').map(x=>{return parseInt(x)});\r\n flag=false;\r\n for(let i=0;i Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let ans = \"NO\";\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 1) {\r\n ans = \"YES\";\r\n break;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "(()=>{\"use strict\";var e={188:function(e,t,n){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleWordInput=t.singleInput=t.testInput=void 0;const l=o(n(58)).default.createInterface({input:process.stdin,output:process.stdout});t.testInput=e=>{let t=[],n=0;l.on(\"line\",(function(o){if(t.push(o),1===t.length&&(n=+t[0]),t.length===2*n+1){l.close();for(let n=2;n{let t=[];l.on(\"line\",(function(n){t.push(n),1===t.length&&(l.close(),console.log(e(t[0])))}))},t.singleWordInput=e=>{let t=[];l.on(\"line\",(function(n){t.push(n),1===t.length&&(l.close(),console.log(e(n)))}))}},58:e=>{e.exports=require(\"readline\")}},t={};(function n(o){var l=t[o];if(void 0!==l)return l.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,n),s.exports})(188).testInput((function(e,t){return t.includes(1)?\"YES\":\"NO\"}))})();"}, {"source_code": "function solve() {\r\n read();\r\n write(~(read().indexOf('1')) ? 'YES' : 'NO'); \r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "var test_number = readline();\r\nvar n = 0,\r\n k = 0;\r\nvar temp_line = \"\",\r\n array_number;\r\nwhile (test_number--) {\r\n temp_line = readline();\r\n array_number = readline();\r\n if (array_number.includes(\"1\")) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var n = parseInt(readline());\r\n\r\nfor (var i = 0; i < n; i++){\r\n var num = readline();\r\n var arr = readline().split(\" \");\r\n var counter = false;\r\n\r\n for(var k = 0; k < arr.length; k++){\r\n if(arr[k] == 1){\r\n counter = true;\r\n break;\r\n }\r\n }\r\n if(counter === true) {\r\n print(\"YES\");\r\n }else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n var inputs = readline().split(' '), n = inputs[0] , k = inputs[1];\r\n var a = readline().split(' ');\r\n a.indexOf('1') == -1 ? print(\"NO\") : print(\"YES\");\r\n }"}, {"source_code": "const cntLines = readline();\r\n\r\nfor (var i=0; i item == 1) ? print('YES') : print('NO');\r\n}"}], "negative_code": [{"source_code": "var test_number = readline();\r\nvar n = 0;"}], "src_uid": "95d83cfdb2131f2f23ba5ef005c18b38"} {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nfunction main() {\n var items = getInput().pop().split(' ').map(i => Number(i));\n var max = 0;\n items.forEach(item => {\n if (max < item) {\n max = item;\n }\n });\n \n print(max - (items.reduce((res, cur) => res + cur, 0) - max) + 1);\n}\n\nmain();", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function (item) {\n return parseInt(item);\n});\nvar max = 0;\nvar sum = input.reduce(function(acc, curr){\n if(curr > max){\n max = curr;\n }\n return acc+curr;\n}, 0)\nprint(2*max-sum+1);"}], "negative_code": [], "src_uid": "f00d94eb37c98a449615f0411e5a3572"} {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var str = lines[l++]\n console.log(solve(str));\n }\n});\n \nfunction solve(str) {\n let sum = 0\n let expect = '?'\n let prev = 0\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]\n if (isMatch(expect, ch)) {\n prev++\n\n if (expect === '?') {\n if (ch !== '?') expect = getOther(ch)\n } else {\n expect = getOther(expect)\n }\n } else {\n let j = i\n while (j >= 0) {\n const change = (i - j) & 1\n const other = getOther(str[j])\n if (str[j] !== '?'\n && !isMatch(ch, change ? other : str[j])) {\n j++\n break\n }\n j--\n }\n prev = i - j + 1\n expect = getOther(ch)\n }\n \n// console.log(prev)\n sum += prev\n }\n// console.log('----')\n return sum \n}\n\nfunction isMatch(expect, actual) {\n if (expect === '?' || actual === '?') return true\n return expect === actual\n}\nfunction getOther(ch) {\n return ch === '0' ? '1' : '0'\n}\n", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/04/21 morning\r\n * https://codeforces.com/contest/1535/problem/C\r\n */\r\n\r\nconst solve = (s) => {\r\n let n = s.length;\r\n let pos = Array(n).fill(-1);\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] != '?') pos[i] = s[i] ^ (i % 2);\r\n }\r\n let zero = one = res = 0;\r\n // pr(pos);\r\n let j = -1; // right\r\n for (let i = 0; i < n; i++) {\r\n while (j < n && (zero == 0 || one == 0)) {\r\n j++;\r\n if (pos[j] == 0) {\r\n zero++;\r\n } else if (pos[j] == 1) {\r\n one++;\r\n }\r\n }\r\n res += j - i;\r\n if (pos[i] == 0) {\r\n zero--;\r\n } else if (pos[i] == 1) {\r\n one--;\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl().split('');\r\n\t\tconst n = s.length;\r\n\r\n\t\tconst px = Array(n).fill(0); px[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) if (s[i] == '?') px[i] = px[i-1] + 1; \r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0, cnt = 0; i < n; i++) {\r\n\r\n\t\t\tif (s[i] == '?') s[i] = 1 ^ s[i-1];\r\n\r\n\t\t\tif (s[i] == s[i-1]) cnt = 1 + px[i-1];\r\n\t\t\telse cnt++;\r\n\r\n\t\t\tans += cnt;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst S = rl().split('');\r\n\t\tconst n = S.length;\r\n\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;\r\n\t\tconst px = Array(n).fill(0); px[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] == '?') px[i] = px[i-1] + 1; \r\n\r\n\r\n\t\ts = S.slice();\r\n\t\tif (s[0] == '?') s[0] = 0;\r\n\r\n\t\tlet ans = 0;\r\n\r\n\t\tlet res = 1, cnt = 1;\r\n\t\tfor (let j = 1; j < n; j++) {\r\n\t\t\tif (s[j] == '?') s[j] = 1 ^ s[j-1];\r\n\t\t\tif (s[j] == s[j-1]) {\r\n\t\t\t\tcnt = 1 + px[j-1];\r\n\t\t\t} else {\r\n\t\t\t\tcnt++;\r\n\t\t\t}\r\n\t\t\tres += cnt;\r\n\t\t}\r\n\t\tans = Math.max(ans, res);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst S = rl().split('');\r\n\t\tconst n = S.length;\r\n\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\ts = S.slice();\r\n\t\t\tif (s[0] == '?') s[0] = i;\r\n\r\n\t\t\tlet res = 1, cnt = 1;\r\n\t\t\tfor (let j = 1; j < n; j++) {\r\n\t\t\t\tif (s[j] == '?') s[j] = 1 ^ s[j-1];\r\n\t\t\t\tif (s[j] == s[j-1]) {\r\n\t\t\t\t\tcnt = 1;\r\n\t\t\t\t\tk = j-1;\r\n\t\t\t\t\twhile (k >= 0 && S[k] == '?') { cnt++; k--;}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\tres += cnt;\r\n\t\t\t}\r\n\r\n\t\t\tans = Math.max(ans, res);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var str = read();\r\n var mark = [];\r\n var n = str.length;\r\n var curStreak = -1;\r\n var lastIndex = -1n;\r\n var lastDigitIndex = -1n;\r\n var questionStreak = 0n;\r\n var ans = 0n;\r\n for (var i = 0; i < n; i++) {\r\n var char = str[i];\r\n if (char === '?') {\r\n questionStreak += 1n;\r\n continue;\r\n }\r\n var x = (char === '1') ? !(i & 1) : !!(i & 1);\r\n if (curStreak === -1) {\r\n curStreak = x;\r\n }\r\n var bigi = BigInt(i); \r\n if (curStreak === x) {\r\n lastDigitIndex = bigi;\r\n questionStreak = 0n;\r\n continue;\r\n }\r\n curStreak = x;\r\n var len = bigi - 1n - lastIndex;\r\n ans = ans + (len * (len + 1n) / 2n) - (questionStreak * (questionStreak + 1n) / 2n);\r\n lastIndex = lastDigitIndex;\r\n lastDigitIndex = bigi;\r\n questionStreak = 0n;\r\n }\r\n var len = BigInt(n - 1) - lastIndex;\r\n ans = ans + (len * (len + 1n) / 2n);\r\n write(ans); \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst S = rl().split('');\r\n\t\tconst n = S.length;\r\n\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;\r\n\t\tconst px = Array(n).fill(0); px[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] == '?') px[i] = px[i-1] + 1; \r\n\r\n\r\n\t\ts = S.slice();\r\n\t\tif (s[0] == '?') s[0] = 0;\r\n\r\n\t\tlet ans = 0;\r\n\r\n\t\tlet res = 1, cnt = 1;\r\n\t\tfor (let j = 1; j < n; j++) {\r\n\t\t\tif (s[j] == '?') s[j] = 1 ^ s[j-1];\r\n\t\t\tif (s[j] == s[j-1]) {\r\n\t\t\t\tcnt = 1 + px[j-1];\r\n\t\t\t} else {\r\n\t\t\t\tcnt++;\r\n\t\t\t}\r\n\t\t\tres += cnt;\r\n\r\n\t\t\tans = Math.max(ans, res);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst S = rl().split('');\r\n\t\tconst n = S.length;\r\n\r\n\t\tfor (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\ts = S.slice();\r\n\t\t\tif (s[0] == '?') s[0] = i;\r\n\t\t\t//else s[0] = s[0]-0;\r\n\r\n\t\t\tlet res = 1, cnt = 1;\r\n\t\t\tfor (let j = 1; j < n; j++) {\r\n\t\t\t\tif (s[j] == '?') s[j] = 1 ^ s[j-1];\r\n\t\t\t\tif (s[j] == s[j-1]) {\r\n\t\t\t\t\tcnt = 1;\r\n\t\t\t\t\tk = j-1;\r\n\t\t\t\t\twhile (k >= 0 && S[k] == '?') { cnt++; k++;}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\tres += cnt;\r\n\t\t\t}\r\n\r\n\t\t\tans = Math.max(ans, res);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var str = read();\r\n var mark = [];\r\n var n = str.length;\r\n var curStreak = -1;\r\n var lastIndex = -1n;\r\n var lastDigitIndex = -1n;\r\n var questionStreak = 0n;\r\n var ans = 0n;\r\n for (var i = 0; i < n; i++) {\r\n var char = str[i];\r\n if (char === '?') {\r\n questionStreak += 1n;\r\n continue;\r\n }\r\n var x = (char === '1') ? !(i & 1) : !!(i & 1);\r\n if (curStreak === -1) {\r\n curStreak = x;\r\n }\r\n var bigi = BigInt(i); \r\n if (curStreak === x) {\r\n lastDigitIndex = bigi;\r\n questionStreak = 0n;\r\n continue;\r\n }\r\n curStreak = x;\r\n var len = bigi - 1n - lastIndex;\r\n ans = ans + (len * (len + 1n) / 2n) - (questionStreak * (questionStreak + 1n) / 2n);\r\n lastIndex = lastDigitIndex;\r\n }\r\n var len = BigInt(n - 1) - lastIndex;\r\n ans = ans + (len * (len + 1n) / 2n);\r\n write(ans); \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var str = read();\r\n var mark = [];\r\n var n = str.length;\r\n var curStreak = -1;\r\n var lastIndex = -1n;\r\n var lastDigitIndex = -1n;\r\n var ans = BigInt(n);\r\n for (var i = 0; i < n; i++) {\r\n var char = str[i];\r\n if (char === '?') {\r\n continue;\r\n }\r\n var x = (char === '1') ? !(i & 1) : !!(i & 1);\r\n if (curStreak === -1) {\r\n curStreak = x;\r\n }\r\n var bigi = BigInt(i); \r\n if (curStreak === x) {\r\n lastDigitIndex = bigi;\r\n continue;\r\n }\r\n curStreak = x;\r\n var len = bigi - 1n - lastIndex;\r\n ans = ans + (len * (len - 1n) / 2n);\r\n lastIndex = lastDigitIndex;\r\n lastDigitIndex = bigi;\r\n }\r\n var len = BigInt(n - 1) - lastIndex;\r\n ans = ans + (len * (len - 1n) / 2n);\r\n write(ans); \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var str = read();\r\n var mark = [];\r\n var n = str.length;\r\n var curStreak = -1;\r\n var lastIndex = -1n;\r\n var lastDigitIndex = -1n;\r\n var ans = BigInt(n);\r\n for (var i = 0; i < n; i++) {\r\n var char = str[i];\r\n if (char === '?') {\r\n continue;\r\n }\r\n var x = (char === '1') ? !(i & 1) : !!(i & 1);\r\n if (curStreak === -1) {\r\n curStreak = x;\r\n }\r\n var bigi = BigInt(i); \r\n if (curStreak === x) {\r\n lastDigitIndex = bigi;\r\n continue;\r\n }\r\n curStreak = x;\r\n var len = bigi - 1n - lastIndex;\r\n ans = ans + (len * (len - 1n) / 2n);\r\n lastIndex = lastDigitIndex;\r\n }\r\n var len = BigInt(n - 1) - lastIndex;\r\n ans = ans + (len * (len - 1n) / 2n);\r\n write(ans); \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "639eeeabcb005152035a1fcf09ed3b44"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar vertexNum = parseInt(readline());\n\t\n\tvar edges = {\n\t\taugment: function(u, v) {\n\t\t\tif (edges[u] === undefined) {\n\t\t\t\tedges[u] = [v];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tedges[u].push(v);\n\t\t\t}\n\t\t}\n\t};\n\n\tfor (var i = 1; i < vertexNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tedges.augment(pair[0], pair[1]);\n\t\tedges.augment(pair[1], pair[0]);\n\t}\n\n\tvar nodes = {};\n\tvar root = 1;\n\n\tfunction descend(path) {\n\t\tvar current = path[path.length-1];\n\t\tnodes[current] = {\n\t\t\t\tchildren: [],\n\t\t\t\tleadsToLeaf: {},\n\t\t\t\tparent: path[path.length-2], visitCount: 0\n\t\t};\n\n\t\tvar neighbors = edges[current];\n\t\tif (neighbors.length == 1 && current != root) { // it's a leaf\n\t\t\tfor (var i = path.length-1; i >= 0; --i) {\n\t\t\t\tvar node = nodes[path[i]];\n\t\t\t\tnode.leadsToLeaf[current] = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tfor (var i = 0; i < neighbors.length; ++i) {\n\t\t\tvar child = neighbors[i];\n\t\t\tif (path.length > 1 && path[path.length-2] == child) {\n\t\t\t\tcontinue; // don't descend to the parent\n\t\t\t}\n\n\t\t\tnodes[current].children.push(child);\n\n\t\t\tpath.push(child);\n\t\t\tdescend(path);\n\t\t\tpath.pop();\n\t\t}\n\t}\n\n\tdescend([root]);\n\n\tvar order = tokenizeIntegers(readline());\n\n\tvar seek = root,\n\t\troute = [root],\n\t\tnode = nodes[root];\n\tnode.visitCount = 1;\n\n\tfor (var i = 0; i < order.length; ++i) {\n\t\tvar target = order[i];\n\t\twhile (!node.leadsToLeaf[target]) { // ascend\n\t\t\tseek = node.parent;\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t\tif (node.visitCount > 1+node.children.length) {\n\t\t\t\tprint(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\twhile (seek != target) { // descend\n\t\t\tfor (var j = 0; j < node.children.length; ++j) {\n\t\t\t\tif (nodes[node.children[j]].leadsToLeaf[target]) {\n\t\t\t\t\tseek = node.children[j];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t}\n\t}\n\n\twhile (seek != root) { // ascend to the root one last time\n\t\tseek = node.parent;\n\t\troute.push(seek);\n\t\tnode = nodes[seek];\n\t\tnode.visitCount += 1;\n\t\tif (node.visitCount != 1+node.children.length) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(route.join(\" \"));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar vertexNum = parseInt(readline());\n\t\n\tvar edges = {\n\t\taugment: function(u, v) {\n\t\t\tif (edges[u] === undefined) {\n\t\t\t\tedges[u] = [v];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tedges[u].push(v);\n\t\t\t}\n\t\t}\n\t};\n\n\tfor (var i = 1; i < vertexNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tedges.augment(pair[0], pair[1]);\n\t\tedges.augment(pair[1], pair[0]);\n\t}\n\n\tvar nodes = {};\n\tvar root = 1;\n\n\tfunction descend(path) {\n\t\tvar current = path[path.length-1];\n\t\tnodes[current] = { index: current,\n\t\t\t\tchildren: [],\n\t\t\t\tleaves: [], hasLeaf: {}, leafCount: 0,\n\t\t\t\tparent: path[path.length-2], visitCount: 0 };\n\n\t\tvar neighbors = edges[current];\n\t\tif (neighbors.length == 1 && current != root) {\n\t\t\tnodes[current].isLeaf = true;\n\t\t\tfor (var i = path.length-1; i >= 0; --i) {\n\t\t\t\tvar node = nodes[path[i]];\n\t\t\t\tnode.leaves.push(current);\n\t\t\t\tnode.hasLeaf[current] = true;\n\t\t\t\tnode.leafCount += 1;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tfor (var i = 0; i < neighbors.length; ++i) {\n\t\t\tvar child = neighbors[i];\n\t\t\tif (path.length > 1 && path[path.length-2] == child) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tnodes[current].children.push(child);\n\n\t\t\tpath.push(child);\n\t\t\tdescend(path);\n\t\t\tpath.pop();\n\t\t}\n\t}\n\n\tdescend([root]);\n\n\tvar order = tokenizeIntegers(readline());\n\n\tvar seek = root,\n\t\troute = [root],\n\t\tnode = nodes[root];\n\tnode.visitCount = 1;\n\n\tfor (var i = 0; i < order.length; ++i) {\n\t\tvar target = order[i];\n\t\twhile (!node.hasLeaf[target]) { // ascend\n\t\t\tseek = node.parent;\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t\tif (node.visitCount > 1+node.children.length) {\n\t\t\t\tprint(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\twhile (seek != target) { // descend\n\t\t\tfor (var j = 0; j < node.children.length; ++j) {\n\t\t\t\tif (nodes[node.children[j]].hasLeaf[target]) {\n\t\t\t\t\tseek = node.children[j];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t}\n\t}\n\n\twhile (seek != root) {\n\t\tseek = node.parent;\n\t\troute.push(seek);\n\t\tnode = nodes[seek];\n\t\tnode.visitCount += 1;\n\t\tif (node.visitCount != 1+node.children.length) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(route.join(\" \"));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar vertexNum = parseInt(readline());\n\t\n\tvar edges = {\n\t\taugment: function(u, v) {\n\t\t\tif (edges[u] === undefined) {\n\t\t\t\tedges[u] = [v];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tedges[u].push(v);\n\t\t\t}\n\t\t}\n\t};\n\n\tfor (var i = 1; i < vertexNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tedges.augment(pair[0], pair[1]);\n\t\tedges.augment(pair[1], pair[0]);\n\t}\n\n\tvar nodes = {};\n\tvar root = 1;\n\n\tfunction descend(path) {\n\t\tvar current = path[path.length-1];\n\t\tnodes[current] = { index: current,\n\t\t\t\tchildren: [],\n\t\t\t\tleaves: [], hasLeaf: {}, leafCount: 0,\n\t\t\t\tparent: path[path.length-2], visitCount: 0 };\n\n\t\tvar neighbors = edges[current];\n\t\tif (neighbors.length == 1 && current != root) {\n\t\t\tnodes[current].isLeaf = true;\n\t\t\tfor (var i = path.length-1; i >= 0; --i) {\n\t\t\t\tvar node = nodes[path[i]];\n\t\t\t\tnode.leaves.push(current);\n\t\t\t\tnode.hasLeaf[current] = true;\n\t\t\t\tnode.leafCount += 1;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tfor (var i = 0; i < neighbors.length; ++i) {\n\t\t\tvar child = neighbors[i];\n\t\t\tif (path.length > 1 && path[path.length-2] == child) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tnodes[current].children.push(child);\n\n\t\t\tpath.push(child);\n\t\t\tdescend(path);\n\t\t\tpath.pop();\n\t\t}\n\t}\n\n\tdescend([root]);\n\n\tvar order = tokenizeIntegers(readline());\n\n\tvar seek = root,\n\t\troute = [root],\n\t\tnode = nodes[root];\n\n\tfor (var i = 0; i < order.length; ++i) {\n\t\tvar target = order[i];\n\t\twhile (!node.hasLeaf[target]) { // ascend\n\t\t\tseek = node.parent;\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t\tif (node.visitCount > 2*node.children.length) {\n\t\t\t\tprint(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\twhile (seek != target) { // descend\n\t\t\tfor (var i = 0; i < node.children.length; ++i) {\n\t\t\t\tif (nodes[node.children[i]].hasLeaf[target]) {\n\t\t\t\t\tseek = node.children[i];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\troute.push(seek);\n\t\t\tnode = nodes[seek];\n\t\t\tnode.visitCount += 1;\n\t\t}\n\t}\n\n\twhile (true) {\n\t\tseek = node.parent;\n\t\troute.push(seek);\n\t\tnode = nodes[seek];\n\t\tnode.visitCount += 1;\n\t\tif (seek == root) {\n\t\t\tprint(route.join(\" \"));\n\t\t\treturn;\n\t\t}\n\t\tif (node.visitCount != 2*node.children.length) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nmain();\n"}], "src_uid": "915bb1dec7af4427c4cc33f7803f6651"} {"source_code": "var lines = parseInt(readline());\r\n\r\nfor (var i = 0; i < lines; i++) {\r\n var line = readline().split(\" \");\r\n var hpC = parseInt(line[0]);\r\n var damC = parseInt(line[1]);\r\n line = readline().split(\" \");\r\n var hpE = parseInt(line[0]);\r\n var damE = parseInt(line[1]);\r\n line = readline().split(\" \");\r\n var coins = parseInt(line[0]);\r\n var attack = parseInt(line[1]);\r\n var defense = parseInt(line[2]);\r\n var h = 0;\r\n var win = false;\r\n while (!win && h <= coins) {\r\n var turnsC = Math.ceil(hpE / (damC + attack * h));\r\n var turnsE = Math.ceil((hpC + defense * (coins - h)) / damE);\r\n if (turnsC <= turnsE) {\r\n win = true;\r\n print(\"YES\");\r\n } else {\r\n var hForSpeedUp = Math.ceil((hpE / (turnsC - 1) - damC) / attack);\r\n var hForSlowDown = Math.ceil(((turnsE + 1) * damE - hpC) / defense);\r\n h += Math.min(hForSpeedUp - h, hForSlowDown - (coins - h));\r\n }\r\n }\r\n if (!win) print(\"NO\");\r\n}\r\n", "positive_code": [{"source_code": "const solve = (ch,cd,mh,md,k,w,a)=>{\r\n let chelath = Math.ceil(ch/md);\r\n let cdamage = Math.ceil(mh/cd);\r\n if(cdamage<=chelath) console.log(\"YES\");\r\n else if(k===0) console.log(\"NO\");\r\n else{\r\n cd = cd + (k*w);\r\n for(let i=0;i<=k;i++){\r\n if(i!=0){\r\n cd-=w;\r\n ch+=a;\r\n }\r\n chelath = Math.ceil(ch/md);\r\n cdamage = Math.ceil(mh/cd);\r\n if(cdamage<=chelath){\r\n console.log(\"YES\");\r\n return;\r\n }\r\n }\r\n console.log(\"NO\");\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n let arr2 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr3 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n solve(arr1[0],arr1[1],arr2[0],arr2[1],arr3[0],arr3[1],arr3[2]);\r\n }\r\n}\r\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [hc, dc] = lines[l++].trim().split(' ').map(Number)\n const [hm, dm] = lines[l++].trim().split(' ').map(Number)\n const [k, w, a] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(hc, dc, hm, dm, k, w, a) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(hc, dc, hm, dm, k, w, a) {\n for (let i = 0; i <= k; i++) {\n const j = k - i\n if (win(hc + i * a, dc + j * w, hm, dm)) return true\n }\n return false\n}\nfunction win(hc, dc, hm, dm) {\n const a = Math.ceil(hc / dm)\n const b = Math.ceil(hm / dc)\n return a >= b\n}\n"}, {"source_code": "const check = (hc,dc,hm,dm) =>{\r\n return (Math.ceil(hc/dm)>=Math.ceil(hm/dc));\r\n}\r\nvar t=readline();\r\nwhile(t--){\r\n var h=readline().split(\" \").map(x => parseInt(x));\r\n var m=readline().split(\" \").map(x => parseInt(x));\r\n var att=readline().split(\" \").map(x => parseInt(x));\r\n var pos=0;\r\n var l,r;\r\n for(var i=0;i<=att[0];i++){\r\n l=i;\r\n r=att[0]-i;\r\n pos|=check(h[0]+att[2]*l,h[1]+att[1]*r,m[0],m[1]);\r\n }\r\n \r\n if(pos>0){\r\n print(\"YES\");\r\n }else print(\"NO\");\r\n}"}, {"source_code": "function check(hc,dc,hm,dm){\r\n return (Math.ceil(hc/dm)>=Math.ceil(hm/dc));\r\n}\r\nvar t=readline();\r\nwhile(t--){\r\n var h=readline().split(\" \").map(x => parseInt(x));\r\n var m=readline().split(\" \").map(x => parseInt(x));\r\n var att=readline().split(\" \").map(x => parseInt(x));\r\n var pos=0;\r\n var l,r;\r\n for(var i=0;i<=att[0];i++){\r\n l=i;\r\n r=att[0]-i;\r\n pos|=check(h[0]+att[2]*l,h[1]+att[1]*r,m[0],m[1]);\r\n }\r\n \r\n if(pos>0){\r\n print(\"YES\");\r\n }else print(\"NO\");\r\n}"}], "negative_code": [{"source_code": "const solve = (ch,cd,mh,md,k,w,a)=>{\r\n let chelath = Math.floor(ch/md)+1;\r\n let cdamage = Math.ceil(mh/cd);\r\n if(cdamage<=chelath) console.log(\"YES\");\r\n else if(k===0) console.log(\"NO\");\r\n else{\r\n cd = cd + (k*w);\r\n for(let i=0;i<=k;i++){\r\n if(i!=0){\r\n cd-=w;\r\n ch+=a;\r\n }\r\n chelath = Math.floor(ch/md)+1;\r\n cdamage = Math.ceil(mh/cd);\r\n if(cdamage<=chelath){\r\n console.log(\"YES\");\r\n return;\r\n }\r\n }\r\n console.log(\"NO\");\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n let arr2 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr3 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n solve(arr1[0],arr1[1],arr2[0],arr2[1],arr3[0],arr3[1],arr3[2]);\r\n }\r\n}\r\nmain();"}], "src_uid": "5b1f33228a58d9e14bc9479767532c25"} {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tlinks_count = [],\n\tlinks = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tlinks[i] = []\n\t\tlinks_count[i] = 0\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tlinks_count[pos[0]] ++\n\t\tlinks_count[pos[1]] ++\n\t\tif (pos[0] < pos[1])\n\t\t\tlinks[pos[0]].push(pos[1])\n\t\telse\n\t\t\tlinks[pos[1]].push(pos[0])\n\t}\n\n\tfor (x = 1; x < n && !failed; x ++) {\n\t\ti = links[x].length - 1\n\t\twhile (i >= 0 && !failed) {\n\t\t\tfailed = links_count[x] != links_count[links[x][i]]\n\t\t\tlinks_count[links[x][i]] --\n\t\t\ti --\n\t\t}\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n", "positive_code": [{"source_code": "\n var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n var n = tmp[0];\n var m = tmp[1];\n var e = [];\n var vis = [];\n for(var i = 1; i <= n; i += 1) {\n e[i] = [];\n vis[i] = false;\n }\n for(var i = 1; i <= m; i += 1) {\n var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n e[tmp[0]].push(tmp[1]);\n e[tmp[1]].push(tmp[0]);\n }\n var finding = true;\n for(var i = 1; i <= n && finding; i += 1) {\n if(!vis[i]) {\n vis[i] = true;\n var vn = 1;\n var en = e[i].length;\n var stack = [i];\n while(stack.length > 0) {\n var d = stack.pop();\n for(var b in e[d]) {\n if(!vis[e[d][b]]) {\n vis[e[d][b]] = true;\n stack.push(e[d][b]);\n vn += 1;\n en += e[e[d][b]].length;\n }\n }\n }\n if(en !== vn * (vn - 1)) {\n finding = false;\n }\n }\n }\n if(finding) {\n print('YES');\n } else {\n print('NO');\n }"}, {"source_code": "/*filesystem = require('fs');\nvar inputLines = filesystem.readFileSync('input.txt').toString().split('\\n');\nvar inputIndex = 0;\n\nfunction readline() {\n return inputLines[inputIndex++];\n}\n\nfunction print() {\n var ans = \"\";\n for (var i = 0; i < arguments.length; i++) {\n if (i != 0) ans += \" \";\n ans += arguments[i].toString();\n }\n console.log(ans);\n}*/\n//FILESYSTEM\n\nvar currentLine;\nvar currentIndex;\nfunction read() {\n if ((currentLine == null) || (currentIndex == currentLine.length)) {\n currentLine = readline().split(' ');\n currentIndex = 0;\n }\n return currentLine[currentIndex++];\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n//HELPERS\nfunction dfs(v) {\n var q = [];\n q.push(v);\n w[v] = true;\n for (var i = 0; i < q.length; i++) {\n var v = q[i];\n for (var j = 0; j < e[v].length; j++) {\n var u = e[v][j];\n if (!w[u]) {\n q.push(u);\n w[u] = true;\n }\n }\n }\n return q.length;\n}\n\nvar n = readInt(), m = readInt();\nvar w = new Array(n + 1).fill(false);\nvar e = new Array(n + 1);\nfor (var i = 1; i <= n; i++) e[i] = [];\nfor (var i = 0; i < m; i++) {\n var a = readInt(), b = readInt();\n e[a].push(b);\n e[b].push(a);\n}\nvar tot = 0;\nfor (var i = 1; i <= n; i++) {\n if (!w[i]) {\n var size = dfs(i);\n tot += size * (size - 1);\n }\n}\nif (tot == 2 * m) print('YES');\nelse print('NO');"}, {"source_code": " var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n var n = tmp[0];\n var m = tmp[1];\n var e = [];\n var vis = [];\n for(var i = 1; i <= n; i += 1) {\n e[i] = [];\n vis[i] = false;\n }\n for(var i = 1; i <= m; i += 1) {\n var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n e[tmp[0]].push(tmp[1]);\n e[tmp[1]].push(tmp[0]);\n }\n var cnt_vertices = 0\n var cnt_edges = 0;\n var stack = [];\n var dfs = function(x) {\n stack.push(x);\n while(stack.length > 0) {\n var a = stack.pop();\n if(vis[a]) {\n continue;\n }\n vis[a] = true;\n vn += 1;\n en += e[a].length;\n for(var b in e[a]) {\n stack.push(e[a][b]);\n // dfs(e[a][b]);\n }\n }\n };\n var finding = true;\n var vn = 0;\n var en = 0;\n for(var i = 1; i <= n && finding; i += 1) {\n if(!vis[i]) {\n vn = 0\n en = 0;\n dfs(i);\n if(en !== vn * (vn - 1)) {\n finding = false;\n }\n }\n }\n if(finding) {\n print('YES');\n } else {\n print('NO');\n }"}], "negative_code": [{"source_code": " var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n var n = tmp[0];\n var m = tmp[1];\n var e = [];\n var vis = [];\n for(var i = 1; i <= n; i += 1) {\n e[i] = [];\n vis[i] = false;\n }\n for(var i = 1; i <= m; i += 1) {\n var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n e[tmp[0]].push(tmp[1]);\n e[tmp[1]].push(tmp[0]);\n }\n var finding = true;\n for(var i = 1; i <= n && finding; i += 1) {\n if(!vis[i]) {\n vis[i] = true;\n var vn = 1;\n var en = e[i].length;\n var stack = [i];\n while(stack.length > 0) {\n var d = stack.pop();\n for(var b in e[d]) {\n if(!vis[e[d][b]]) {\n vis[e[d][b]] = true;\n stack.push(e[d][b]);\n vn += 1;\n en += e[d].length;\n }\n }\n }\n if(en !== vn * (vn - 1)) {\n finding = false;\n }\n }\n }\n if(finding) {\n print('YES');\n } else {\n print('NO');\n }"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tlinks_count = [],\n\tlinks = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tlinks[i] = []\n\t\tlinks_count[i] = 0\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tlinks_count[pos[0]] ++\n\t\tlinks_count[pos[1]] ++\n\t\tif (pos[0] < pos[1])\n\t\t\tlinks[pos[0]].push(pos[1])\n\t\telse\n\t\t\tlinks[pos[1]].push(pos[0])\n\t}\n\n\tfor (x = 1; x < n && !failed; x ++) {\n\t\ti = links[x].length - 1\n\t\twhile (i >= 0 && !failed) {\n\t\t\tfailed = links_count[x] != links_count[links[x][i]]\n\t\t\ti --\n\t\t}\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfriend = function(x, y) {\n\t\treturn x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined) \n\t},\n\tfailed = false\n\nfor(i = 0; i <=n; i++) {\n\tmem[i] = {}\n}\n\nfor(i = 0; i < m; i++) {\n\tpos = ints()\n\tif (pos[0] < pos[1]) {\n\t\tx = pos[0]\n\t\ty = pos[1]\n\t} else {\n\t\tx = pos[1]\n\t\ty = pos[0]\n\t}\n\tmem[x][y] = true\n}\n\ni = 1\nwhile (i <= n && !failed) {\n\tfor (x in mem[i]) {\n\t\tfor(y in mem[x]) {\n\t\t\tif (! friend(i, y)) {\n\t\t\t\tfailed = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (failed)\n\t\t\tbreak\n\t}\n\ti ++\n}\n\nif (failed)\n\tprint(\"NO\")\nelse\n\tprint(\"YES\")\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfriend = function(x, y) {\n\t\treturn x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined) \n\t},\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tmem[i] = {}\n\t\tmem[i][i] = true\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tif (pos[0] < pos[1]) {\n\t\t\tx = pos[0]\n\t\t\ty = pos[1]\n\t\t} else {\n\t\t\tx = pos[1]\n\t\t\ty = pos[0]\n\t\t}\n\t\tmem[x][y] = true\n\t}\n\n\ti = 1\n\twhile (i <= n && !failed) {\n\t\tfor (x in mem[i]) {\n\t\t\tfor(y in mem[x]) {\n\t\t\t\tif (! friend(i, y)) {\n\t\t\t\t\tfailed = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (failed)\n\t\t\t\tbreak\n\t\t}\n\t\ti ++\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tmem[i] = 0\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tmem[pos[0]] ++\n\t\tmem[pos[1]] ++\n\t}\n\n\tfor (x = 1; x < n && !failed; x ++)\n\t\tfor (y = x + 1; y <= n && !failed; y ++)\n\t\t\tfailed = (mem[x] != mem[y])\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfriend = function(x, y) {\n\t\treturn mem[x][y]\n\t},\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tmem[i] = []\n\t\tfor(x = 0; x <=n; x++)\n\t\t\tmem[i][x] = false\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tmem[pos[0]][pos[1]] = true\n\t\tmem[pos[1]][pos[0]] = true\n\t}\n\n\tfor(i = 1; i <=n && !failed; i++) {\n\t\tfor(x = 1; x <=n && !failed; x++) {\n\t\t\tfor(y = 1; y <=n && !failed; y++) {\n\t\t\t\tfailed = friend(i, x) && friend(x, y) && !friend(i, y)\n\t\t\t}\n\t\t}\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfriend = function(x, y) {\n\t\treturn x == y || mem[x][y]\n\t},\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tmem[i] = []\n\t\tfor(x = 0; x <=n; x++)\n\t\t\tmem[i][x] = false\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tmem[pos[0]][pos[1]] = true\n\t}\n\n\tfor(i = 1; i <=n && !failed; i++) {\n\t\tfor(x = 1; x <=n && !failed; x++) {\n\t\t\tfor(y = 1; y <=n && !failed; y++) {\n\t\t\t\tfailed = friend(i, x) && friend(x, y) && !friend(x, y)\n\t\t\t}\n\t\t}\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}, {"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\n\nvar ns = ints(),\n\tn = ns[0],\n\tm = ns[1]\n\tmem = [],\n\ti = 0,\n\tx = 0,\n\ty = 0,\n\tpos = [],\n\tfriend = function(x, y) {\n\t\treturn x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined) \n\t},\n\tfailed = false\n\nif (m == 0) {\n\tprint(\"YES\")\n} else {\n\tfor(i = 0; i <=n; i++) {\n\t\tmem[i] = {}\n\t}\n\n\tfor(i = 0; i < m; i++) {\n\t\tpos = ints()\n\t\tif (pos[0] < pos[1]) {\n\t\t\tx = pos[0]\n\t\t\ty = pos[1]\n\t\t} else {\n\t\t\tx = pos[1]\n\t\t\ty = pos[0]\n\t\t}\n\t\tmem[x][y] = true\n\t}\n\n\ti = 1\n\twhile (i <= n && !failed) {\n\t\tfor (x in mem[i]) {\n\t\t\tfor(y in mem[x]) {\n\t\t\t\tif (! friend(i, y)) {\n\t\t\t\t\tfailed = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (failed)\n\t\t\t\tbreak\n\t\t}\n\t\ti ++\n\t}\n\n\tif (failed)\n\t\tprint(\"NO\")\n\telse\n\t\tprint(\"YES\")\n}\n"}], "src_uid": "1173d89dd3af27b46e579cdeb2cfdfe5"} {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arr();\n var res = [a[0]];\n var length = 0;\n for(var i = 1; i < n; i++) {\n if(length % 2) {\n res.push(a[i]);\n length++;\n }\n else {\n if(res[length] !== a[i]) {\n res.push(a[i]);\n length++;\n }\n }\n }\n length += 1;\n if(length % 2) {\n length -=1;\n res.pop();\n }\n\n print(n - length);\n print(res.join(''));\n}());", "positive_code": [{"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next());\n let s = next();\n let i = 0;\n \n let res = '';\n let ereased = 0;\n for(i = 0; i < n; i++) {\n if(i == n-1 || s[i+1] !== s[i]) {\n res += s[i];\n } else {\n let j = i+1;\n while(j < n && s[j] === s[i]) {\n j++;\n }\n j--;\n if((i-ereased)%2 == 0) {\n res += s[i];\n ereased += j-i;\n } else {\n res += s[i]+''+s[i];\n ereased += j-i-1;\n }\n i = j;\n }\n }\n\n if(res.length%2) {\n println(n-res.length+1);\n println(res.substr(0, res.length-1));\n } else {\n println(n-res.length);\n println(res.substr(0, res.length));\n }\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next());\n let s = next(), res = '';\n let i = 0, j = 0, ereased = 0;\n for(i = 0; i < n; i++) {\n if(i == n-1 || s[i+1] !== s[i]) {\n res += s[i];\n } else {\n j = i+1;\n while(j < n && s[j] === s[i]) {\n j++;\n }\n j--;\n if((i-ereased)%2) {\n res += s[i]+s[i];\n ereased += j-i-1;\n } else {\n res += s[i];\n ereased += j-i;\n }\n i = j;\n }\n }\n\n println(n-res.length+res.length%2);\n println(res.substr(0, res.length-res.length%2));\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next());\n let s = next();\n let stack = [], i = 0, res = '';\n for(i = 0; i < n; i++) {\n if((!stack.length) || s[i] != stack[stack.length-1] || stack.length % 2 == 0) {\n stack.push(s[i]);\n }\n }\n if(stack.length%2) stack.pop();\n res = stack.join('');\n println(n-res.length+'\\n'+res);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}], "negative_code": [{"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next());\n let s = next();\n let i = 0;\n \n let res = '';\n let ereased = 0;\n for(i = 0; i < n; i++) {\n if(i == n-1 || s[i+1] !== s[i]) {\n res += s[i];\n } else {\n let j = i+1;\n while(j < n && s[j] === s[i]) {\n j++;\n }\n j--;\n if((i-ereased)%2 == 0) {\n res += s[i];\n ereased += j-i;\n } else {\n res += s[i]+''+s[i];\n ereased += j-i-1;\n }\n i = j;\n }\n }\n\n if(res.length%2) {\n println(n-res.length+1);\n println(s.substr(0, res.length-1));\n } else {\n println(n-res.length);\n println(s.substr(0, res.length));\n }\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}], "src_uid": "c11d67f223eb49c6e8315e2c88dd680d"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar calculateTrees = (cont, startRow, endRow, startCloumn, endColumn) => {\n let ans = 0;\n for (let i = startRow; i < endRow; i++)\n for (let j = startCloumn; j < endColumn; j++)\n if (cont[i][j] == 1)\n ans += cont[i][j];\n return ans;\n}\nvar N, M, cont = [], houseX, houseY, indicator = 0, temp = [];\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n N = temp[0], M = temp[1];\n indicator++;\n } else if (indicator <= N) {\n cont.push(input.split(' ').map(item => parseInt(item)));\n indicator++;\n } else {\n temp = input.split(' ').map(item => parseInt(item));\n houseX = temp[0], houseY = temp[1];\n }\n}).on(\"close\", () => {\n let ans = N * M, helper;\n for (let i = 0; i < N; i++) {\n for (let j = 0; j < M; j++) {\n if (i + houseX <= N && j + houseY <= M) {\n helper = calculateTrees(cont, i, i + houseX, j, j + houseY);\n if (ans > helper)\n ans = helper;\n }\n if (i + houseY <= N && j + houseX <= M) {\n helper = calculateTrees(cont, i, i + houseY, j, j + houseX);\n if (ans > helper)\n ans = helper;\n }\n }\n }\n console.log(ans);\n});", "positive_code": [{"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\nlet N = lll[0]\nlet M = lll[1]\n\nlet s = []\nwhile (lll = readline()) {\n s.push(lll.split(' ').map(v => parseInt(v)))\n}\n\nlet ab = s.pop()\nlet A = ab[0]\nlet B = ab[1]\n\nlet min = Infinity\n\nfor (let y = 0; y <= N - A; y++) {\n for (let x = 0; x <= M - B; x++) {\n let ts = 0\n d: for (let dy = 0; dy < A; dy++) {\n for (let dx = 0; dx < B; dx++) {\n if (s[y + dy][x + dx] == 1) ts++\n if (ts >= min) break d\n }\n }\n if (ts < min) min = ts\n }\n}\n\nfor (let y = 0; y <= N - B; y++) {\n for (let x = 0; x <= M - A; x++) {\n let ts = 0\n d: for (let dy = 0; dy < B; dy++) {\n for (let dx = 0; dx < A; dx++) {\n if (s[y + dy][x + dx] == 1) ts++\n if (ts >= min) break d\n }\n }\n if (ts < min) min = ts\n }\n}\n\nprint(min)"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar calculateTrees = function (cont, startRow, endRow, startCol, endCol) {\n let ans = 0;\n for (let i = startRow; i < endRow; i++)\n for (let j = startCol; j < endCol; j++)\n ans += cont[i][j];\n\n //console.log(\" startRow=%d endRow=%d startCol=%d endCol=%d ans=%d\",startRow, endRow, startCol, endCol,ans);\n return ans;\n}\n\nvar indicator = 0, N, M, temp, cont = [], HouseX, HouseY;\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(\" \").map(item => parseInt(item));\n N = temp[0];\n M = temp[1];\n indicator++;\n }\n else if (indicator <= N) {\n cont.push(input.split(\" \").map(item => parseInt(item)));\n indicator++;\n }\n else {\n temp = input.split(\" \").map(item => parseInt(item));\n HouseX = temp[0];\n HouseY = temp[1];\n }\n}).on('close', () => {\n let ans = N * M, helper;\n for (let i = 0; i < N; i++) {\n for (let j = 0; j < M; j++) {\n if (i + HouseX <= N && j + HouseY <= M) {\n helper = calculateTrees(cont, i, i + HouseX, j, j + HouseY);\n if (ans > helper)\n ans = helper;\n }\n if (i + HouseY <= N && j + HouseX <= M) {\n helper = calculateTrees(cont, i, i + HouseY, j, j + HouseX);\n if (ans > helper)\n ans = helper;\n }\n }\n }\n console.log(ans);\n});"}], "negative_code": [{"source_code": "var getArr = function() {\n\treturn readline().split(' ').map(function (a) {\n\t\treturn parseInt(a);\n\t})\n};\n\nvar getTree = function(arr, x, y, a, b) {\n\tvar res = 0;\n\tfor (var i = 0; i < a; i++) {\n\t\tfor (var j = 0; j < b; j++) {\n\t\t\tres += arr[x + i][y + j];\n\t\t}\n\t}\n\treturn res;\n};\n\nvar data = [];\nvar input;\n\ninput = getArr();\nvar m = input[0];\nvar n = input[1];\nfor (var k = 0; k < m; k++) {\n\tdata.push(getArr());\n}\ninput = getArr();\nvar a = input[0];\nvar b = input[1];\n\nvar min = getTree(data, 0, 0, a, b);\nfor (var i = 0; i < m - a + 1; i++) {\n\tfor (var j = 0; j < n - b + 1; j++) {\n\t\tmin = Math.min(min, getTree(data, i, j, a, b));\n\t}\n}\n\nprint(min);"}], "src_uid": "1771741663a5236a0aa0551548f4aadd"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1];\n\tvar gapFound = {}, gaps = [];\n\tfor (var r = 0; r < rowNum; ++r) {\n\t\tvar line = trim(readline());\n\t\tvar gap = line.indexOf('S') - line.indexOf('G');\n\t\tif (gap < 0) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (!gapFound[gap]) {\n\t\t\tgapFound[gap] = true;\n\t\t\tgaps.push(gap);\n\t\t}\n\t}\n\tprint(gaps.length);\n}\n\nmain();\n", "positive_code": [{"source_code": "print(function(n, m){\n\tvar a=[];\n\tfor(var i=0; i a-b );\n\tvar count = 0;\n\tfor (var i=0; i a-b );\n\tvar count = 0;\n\tfor (var i=0; i\");\n}", "positive_code": [{"source_code": "const input = readline();\nconst str = eval(input).toString();\nconst result = [\">++++++++[<++++++>-]<\"];\nvar last = 48;\nfor (var i = 0, len = str.length; i < len; i++) {\n var current = str.charCodeAt(i);\n var diff = current - last;\n result.push(diff >= 0 ? \"+\".repeat(diff) : \"-\".repeat(-diff), \".\");\n last = current;\n}\nprint(result.join(\"\"));\n"}, {"source_code": "var input=readline();\nvar operands=input.split(/[+-]/);\nfor(var i=0;i');\n}\nvar operators=input.split(/[0-9]+/);\nfor(var i=operators.length-2;i>0;i--){\n\tvar s='<[';\n\tfor(var j=0;j';\n\ts+='-]';\n\tprint(s);\n}\nprint('>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]');"}], "negative_code": [{"source_code": "var input=readline();\nvar operands=input.split(/[+-]/);\nfor(var i=0;i');\n}\nvar operators=input.split(/\\d/);\nfor(var i=operators.length-2;i>0;i--){\n\tvar s='<[<'+operators[i]+'>-]';\n\tprint(s);\n}\nprint('<');\nprint('++++++++++++++++++++++++++++++++++++++++++++++++.');"}, {"source_code": "var input=readline();\nvar operands=input.split(/[+-]/);\nfor(var i=0;i');\n}\nvar operators=input.split(/\\d/);\nfor(var i=operators.length-2;i>0;i--){\n\tvar s='<[';\n\tfor(var j=0;j';\n\ts+='-]';\n\tprint(s);\n}\nprint('<');\nprint('++++++++++++++++++++++++++++++++++++++++++++++++.');"}, {"source_code": "var input=readline();\nvar operands=input.split(/[+-]/);\nfor(var i=0;i');\n}\nvar operators=input.split(/[0-9]+/);\nfor(var i=operators.length-2;i>0;i--){\n\tvar s='<[';\n\tfor(var j=0;j';\n\ts+='-]';\n\tprint(s);\n}\nprint('<');\nprint('++++++++++++++++++++++++++++++++++++++++++++++++.');"}, {"source_code": "var input=readline();\nvar operands=input.split(/[+-]/);\nfor(var i=0;i');\n}\nvar operators=input.split(/[0-9]+/);\nfor(var i=operators.length-2;i>0;i--){\n\tvar s='<[<'+operators[i]+'>-]<';\n\tprint(s);\n}\nprint('++++++++++++++++++++++++++++++++++++++++++++++++.');"}], "src_uid": "072797682246c465148bd09736b76718"} {"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar List = __webpack_require__(1);\n\tvar n = List.map(parseInt, readline().split(' '))[0];\n\tvar a = List.map(parseInt, readline().split(' '));\n\tvar level = 0;\n\tvar changes = 0;\n\tvar i = 0;\n\tvar di = 1;\n\twhile (true) {\n\t while (i >= 0 && i < n) {\n\t if (a[i] <= level) {\n\t level++;\n\t a[i] = n + 1;\n\t }\n\t i += di;\n\t }\n\t if (level == n)\n\t break;\n\t i -= di;\n\t di = -di;\n\t changes++;\n\t}\n\tprint(changes);\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(2);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction sort(xs, compare) {\n\t return copy(xs).sort(compare);\n\t}\n\texports.sort = sort;\n\tfunction sortInPlace(xs, compare) {\n\t xs.sort(compare);\n\t return xs;\n\t}\n\texports.sortInPlace = sortInPlace;\n\tfunction maximumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximumInRange = maximumInRange;\n\tfunction maximum(xs) {\n\t return maximumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.maximum = maximum;\n\tfunction maximumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result < candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.maximumInRangeWith = maximumInRangeWith;\n\tfunction maximumWith(xs, f) {\n\t return maximumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.maximumWith = maximumWith;\n\tfunction minimumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimumInRange = minimumInRange;\n\tfunction minimum(xs) {\n\t return minimumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.minimum = minimum;\n\tfunction minimumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result > candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.minimumInRangeWith = minimumInRangeWith;\n\tfunction minimumWith(xs, f) {\n\t return minimumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.minimumWith = minimumWith;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction nub(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t result.push(xs[0]);\n\t for (var i = 1; i < xs.length; i++) {\n\t if (xs[i] !== xs[i - 1]) {\n\t result.push(xs[i]);\n\t }\n\t }\n\t return result;\n\t}\n\texports.nub = nub;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\tfunction range(from, to) {\n\t var result = Array(to - from + 1);\n\t for (var i = from; i <= to; i++) {\n\t result[i - from] = i;\n\t }\n\t return result;\n\t}\n\texports.range = range;\n\tfunction copy(xs) {\n\t return xs.slice(0);\n\t}\n\texports.copy = copy;\n\tfunction apply_permutation(p, xs) {\n\t var n = xs.length;\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = xs[p[i]];\n\t }\n\t return result;\n\t}\n\texports.apply_permutation = apply_permutation;\n\tfunction next_permutation(p) {\n\t var n = p.length;\n\t if (n < 2)\n\t return null;\n\t var r = copy(p);\n\t var k = n - 2;\n\t for (; k >= 0 && r[k] >= r[k + 1]; k--)\n\t ;\n\t if (k < 0)\n\t return null;\n\t for (var i = k + 1, j = n - 1; i < j; i++, j--) {\n\t var t_1 = r[i];\n\t r[i] = r[j];\n\t r[j] = t_1;\n\t }\n\t var next = k + 1;\n\t for (; r[next] <= r[k]; next++)\n\t ;\n\t var t = r[k];\n\t r[k] = r[next];\n\t r[next] = t;\n\t return r;\n\t}\n\texports.next_permutation = next_permutation;\n\tfunction create(n, value) {\n\t return replicate(n, value);\n\t}\n\texports.create = create;\n\tfunction createWith(n, f) {\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = f(i);\n\t }\n\t return result;\n\t}\n\texports.createWith = createWith;\n\tfunction create2D(n1, n2, value) {\n\t return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));\n\t}\n\texports.create2D = create2D;\n\tfunction create2DWith(n1, n2, f) {\n\t var result = new Array(n1);\n\t for (var i = 0; i < n1; i++) {\n\t result[i] = new Array(n2);\n\t for (var j = 0; j < n2; j++) {\n\t result[i][j] = f(i, j);\n\t }\n\t }\n\t return result;\n\t}\n\texports.create2DWith = create2DWith;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\tfunction gcd(a, b) {\n\t var r = a % b;\n\t while (r !== 0) {\n\t a = b;\n\t b = r;\n\t r = a % b;\n\t }\n\t return b;\n\t}\n\texports.gcd = gcd;\n\n\n/***/ }\n/******/ ]);", "positive_code": [{"source_code": "'use strict';\n\n/*let input = `\n7\n0 3 1 0 5 2 6\n`.trim().split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}\n*/\n//code\n\nvar n = Number(readline());\nvar coveredComputers = [],\n directionChanges = 0,\n i = 0,\n direction = 1;\nvar infoRequired = readline().split(' ').map(Number);\n\nwhile (coveredComputers.length != n) {\n\tif (i >= n || i < 0) {\n\t\tdirection *= -1;\n\t\tdirectionChanges++;\n\t\ti += direction * 2;\n\t}\n\tif (coveredComputers.indexOf(i) === -1) {\n\t\tif (infoRequired[i] <= coveredComputers.length) {\n\t\t\tcoveredComputers.push(i);\n\t\t}\n\t}\n\ti += direction;\n}\nprint(directionChanges);\n"}, {"source_code": "n = readline();\na = readline().split(\" \").map(Number);\n\nanswer = -1;\nhacked = 0;\n\nwhile (hacked < n) {\n\tanswer += 1;\n\tif (answer % 2 == 0) {\n\t\t// right\n\t\tfor (var i = 0; i < a.length; i++) {\n\t\t\tif (a[i] <= hacked && a[i] != -1) {\n\t\t\t\ta[i] = -1;\n\t\t\t\thacked += 1;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor (var i = a.length-1; i >= 0; --i) {\n\t\t\tif (a[i] <= hacked && a[i] != -1) {\n\t\t\t\ta[i] = -1;\n\t\t\t\thacked += 1;\n\t\t\t}\t\n\t\t}\n\t}\n\n}\n\nwrite(answer);"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number);\nvar x = 0, bool = [], proof;\n\nfor(var i = 0; i < n; i++){\n\tbool[i] = true;\n}\n\nfor(var i = 0; ;i++){\n\tproof = true;\n\n\tfor(var j = 0; j < n; j++){\n\t\tif(a[j] <= x){\n\t\t\tif(bool[j]){\n\t\t\t\tx++;\n\t\t\t\tbool[j] = false;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tproof = false;\n\t\t}\n\t}\n\n\tif(proof){\n\t\twrite(i);\n\t\tbreak;\n\t}\n\n\ta = a.reverse();\n\tbool = bool.reverse();\n}"}], "negative_code": [], "src_uid": "9374728643a1ddbe2200a4a125beef26"} {"source_code": "const fs=require('fs')\r\nconst input=fs\r\n .readFileSync(0,'utf-8')\r\n .split('\\n')\r\n .map(line=>line.split(' ').map(Number))\r\nmain(input)\r\n\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log(`1 1`)\r\n return [2, 2, [1, 1]]\r\n }\r\n const g = new Array(n).fill(0).map(() => new Set())\r\n const p = new Array(n).fill(-1)\r\n const d = []\r\n const root = 0 //Math.floor(Math.random() * n)\r\n for (let i = 1; i < n; i++) {\r\n const [u, v] = input[i]\r\n g[u - 1].add(v - 1)\r\n g[v - 1].add(u - 1)\r\n }\r\n let queue = [[root, 0]],\r\n st = []\r\n st[root] = 1\r\n for (let [node, depth] of queue) {\r\n if (!d[depth]) d[depth] = new Set()\r\n d[depth].add(node)\r\n for (let child of g[node]) {\r\n if (st[child]) continue\r\n queue.push([child, depth + 1])\r\n p[child] = node\r\n st[child] = 1\r\n }\r\n }\r\n\r\n const dp = new Array(n).fill(0).map((_, i) => [\r\n [0, 1],\r\n [1, i === root ? 0 : 1],\r\n ]),\r\n dp1 = new Array(n).fill(0).map(() => [])\r\n for (let i = d.length - 1; i > 0; i--) {\r\n for (let node of d[i]) {\r\n const cur = dp[node],\r\n parent = dp[p[node]]\r\n\r\n for (let state of [0, 1]) {\r\n dp1[node][state] = state ^ 1\r\n if (state) {\r\n let [[count0, sum0]] = cur\r\n parent[1][0] += count0\r\n parent[1][1] += sum0 + 1\r\n } else {\r\n let [[count0, sum0], [count1, sum1]] = cur\r\n if (count0 < count1 || (count0 === count1 && sum0 > sum1)) {\r\n count0 = count1\r\n sum0 = sum1\r\n } else {\r\n dp1[node][state] = 0\r\n }\r\n parent[0][0] += count0\r\n parent[0][1] += sum0\r\n }\r\n }\r\n }\r\n }\r\n\r\n const isGood = []\r\n const [root0, root1] = dp[0]\r\n isGood[root] = root1[0] > root0[0] || (root1[0] === root0[0] && root1[1] < root0[1]) ? 1 : 0\r\n queue = [root]\r\n st = []\r\n st[root] = 1\r\n for (let node of queue) {\r\n for (let child of g[node]) {\r\n if (st[child]) continue\r\n st[child] = 1\r\n isGood[child] = dp1[child][isGood[node]]\r\n queue.push(child)\r\n }\r\n }\r\n let res = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n if (isGood[i] === 0) {\r\n res[i] = 1\r\n for (let node of g[i]) {\r\n if (isGood[node] === 1) res[node]++\r\n }\r\n }\r\n }\r\n const [max, sum] = dp[root][isGood[root]]\r\n console.log(max, sum)\r\n console.log(res.join(' '))\r\n return [max, sum, res]\r\n}", "positive_code": [{"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n output: process.stdout,\r\n input: process.stdin,\r\n})\r\nconst input = []\r\nrl.on('line', line => input.push(line.split(' ').map(Number)))\r\nrl.on('close', () => {\r\n main(input)\r\n})\r\n\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log(`1 1`)\r\n return [2, 2, [1, 1]]\r\n }\r\n const g = new Array(n).fill(0).map(() => new Set())\r\n const p = new Array(n).fill(-1)\r\n const d = []\r\n const root = 0 //Math.floor(Math.random() * n)\r\n for (let i = 1; i < n; i++) {\r\n const [u, v] = input[i]\r\n g[u - 1].add(v - 1)\r\n g[v - 1].add(u - 1)\r\n }\r\n let queue = [[root, 0]],\r\n st = []\r\n st[root] = 1\r\n for (let [node, depth] of queue) {\r\n if (!d[depth]) d[depth] = new Set()\r\n d[depth].add(node)\r\n for (let child of g[node]) {\r\n if (st[child]) continue\r\n queue.push([child, depth + 1])\r\n p[child] = node\r\n st[child] = 1\r\n }\r\n }\r\n\r\n const dp = new Array(n).fill(0).map((_, i) => [\r\n [0, 1],\r\n [1, i === root ? 0 : 1],\r\n ]),\r\n dp1 = new Array(n).fill(0).map(() => [])\r\n for (let i = d.length - 1; i > 0; i--) {\r\n for (let node of d[i]) {\r\n const cur = dp[node],\r\n parent = dp[p[node]]\r\n\r\n for (let state of [0, 1]) {\r\n dp1[node][state] = state ^ 1\r\n if (state) {\r\n let [[count0, sum0]] = cur\r\n parent[1][0] += count0\r\n parent[1][1] += sum0 + 1\r\n } else {\r\n let [[count0, sum0], [count1, sum1]] = cur\r\n if (count0 < count1 || (count0 === count1 && sum0 > sum1)) {\r\n count0 = count1\r\n sum0 = sum1\r\n } else {\r\n dp1[node][state] = 0\r\n }\r\n parent[0][0] += count0\r\n parent[0][1] += sum0\r\n }\r\n }\r\n }\r\n }\r\n\r\n const isGood = []\r\n const [root0, root1] = dp[0]\r\n isGood[root] = root1[0] > root0[0] || (root1[0] === root0[0] && root1[1] < root0[1]) ? 1 : 0\r\n queue = [root]\r\n st = []\r\n st[root] = 1\r\n for (let node of queue) {\r\n for (let child of g[node]) {\r\n if (st[child]) continue\r\n st[child] = 1\r\n isGood[child] = dp1[child][isGood[node]]\r\n queue.push(child)\r\n }\r\n }\r\n let res = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n if (isGood[i] === 0) {\r\n res[i] = 1\r\n for (let node of g[i]) {\r\n if (isGood[node] === 1) res[node]++\r\n }\r\n }\r\n }\r\n const [max, sum] = dp[root][isGood[root]]\r\n console.log(max, sum)\r\n console.log(res.join(' '))\r\n return [max, sum, res]\r\n}"}], "negative_code": [{"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n output: process.stdout,\r\n input: process.stdin,\r\n})\r\nconst input = []\r\nrl.on('line', line => input.push(line.split(' ').map(Number)))\r\nrl.on('close', () => {\r\n main(input)\r\n})\r\n\r\nfunction main(input) {\r\n function debug(str) {\r\n console.log(str)\r\n }\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log('1 1')\r\n return [2, 2, [1, 1]]\r\n }\r\n debug('\u6784\u5efa\u56fe')\r\n const g = new Array(n).fill(0).map(() => new Set()),\r\n d = new Array(n).fill(0)\r\n const add = (i, j) => {\r\n g[i].add(j)\r\n d[j]++\r\n }\r\n for (let i = 1; i < n; i++) {\r\n const [u, v] = input[i]\r\n add(u - 1, v - 1)\r\n add(v - 1, u - 1)\r\n }\r\n\r\n debug('\u67e5\u627e root')\r\n let root = -1\r\n for (let i = 0, max = Infinity; i < n; i++) {\r\n if (d[i] < max) {\r\n max = d[i]\r\n root = i\r\n }\r\n }\r\n\r\n debug('\u6784\u5efa\u6811')\r\n const tree = new Array(n).fill(0).map(() => new Set()),\r\n st = []\r\n let queue = [root]\r\n st[root] = 1\r\n for (let root of queue) {\r\n for (let child of g[root]) {\r\n if (st[child]) continue\r\n st[child] = 1\r\n queue.push(child)\r\n tree[root].add(child)\r\n }\r\n }\r\n\r\n debug('\u67e5\u627e\u6700\u591a\u597d\u9876\u70b9\u6570')\r\n const cache = new Array(n).fill(0).map(() => [])\r\n const dfs = (i, isGood) => {\r\n if (cache[i][isGood]) return cache[i][isGood]\r\n let state = isGood ^ 1\r\n let res = isGood ^ 1,\r\n sum = i === root ? 0 : 1\r\n for (let child of tree[i]) {\r\n const [r1, s1] = dfs(child, isGood ^ 1)\r\n res += r1\r\n sum += s1\r\n if (state) sum++\r\n }\r\n\r\n if (!isGood) {\r\n let max = 0,\r\n sum2 = 1\r\n for (let child of tree[i]) {\r\n const [r1, s1] = dfs(child, isGood)\r\n max += r1\r\n sum2 += s1\r\n }\r\n if (res < max) {\r\n res = max\r\n sum = sum2\r\n state = 0\r\n } else if (res === max && sum >= sum2) {\r\n sum = sum2\r\n state = 0\r\n }\r\n }\r\n\r\n cache[i][isGood] = [res, sum, state]\r\n return [res, sum]\r\n }\r\n\r\n dfs(root, 0)\r\n\r\n debug('\u5bf9\u6240\u6709\u70b9\u8fdb\u884c\u5206\u7c7b')\r\n const colors = new Array(n).fill(0)\r\n const dfs2 = (node, state) => {\r\n colors[node] = cache[node][state][2]\r\n for (let child of tree[node]) {\r\n dfs2(child, colors[node])\r\n }\r\n }\r\n dfs2(root, 0)\r\n\r\n debug('\u7edf\u8ba1\u4e24\u79cd\u60c5\u51b5\u603b\u6570')\r\n let s0 = 0,\r\n s1 = 0\r\n for (let i = 0; i < n; i++) {\r\n if (colors[i] === 0) s0++\r\n else s1++\r\n }\r\n let min = s0 > s1 ? 1 : 0\r\n let res = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n if (colors[i] === min) {\r\n res[i] = 1\r\n for (let j of g[i]) {\r\n if (colors[j] === 0) continue\r\n res[j] += 1\r\n }\r\n }\r\n }\r\n\r\n debug('\u8ba1\u7b97\u6700\u5c0f\u6743\u91cd\u548c')\r\n let sum = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += res[i]\r\n }\r\n\r\n console.log(s1, sum)\r\n console.log(res.join(' '))\r\n return [s1, sum, res]\r\n}"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n output: process.stdout,\r\n input: process.stdin,\r\n})\r\nconst input = []\r\nrl.on('line', line => input.push(line.split(' ').map(Number)))\r\nrl.on('close', () => {\r\n main(input)\r\n})\r\nfunction main(input){\r\n console.log(input)\r\n}"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n output: process.stdout,\r\n input: process.stdin,\r\n})\r\nconst input = []\r\nrl.on('data', line => input.push(line.split(' ').map(Number)))\r\nrl.on('close', () => {\r\n main(input)\r\n})\r\n\r\nfunction main(input){\r\n console.log(input)\r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\n \r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log('1 1')\r\n return [2, 2, [1, 1]]\r\n }\r\n \r\n const g = new Array(n).fill(0).map(() => new Set()),\r\n d = new Array(n).fill(0)\r\n const add = (i, j) => {\r\n g[i].add(j)\r\n d[j]++\r\n }\r\n console.log(input,g,d)\r\n \r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log('1 1')\r\n return [2, 2, [1, 1]]\r\n }\r\n \r\n const g = new Array(n).fill(0).map(() => new Set()),\r\n d = new Array(n).fill(0)\r\n const add = (i, j) => {\r\n g[i].add(j)\r\n d[j]++\r\n }\r\n \r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(2, 2)\r\n console.log('1 1')\r\n return [2, 2, [1, 1]]\r\n }\r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(`2 2\\n1 1`)\r\n return\r\n }\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = []\r\n let idx = 0\r\n const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))\r\n for (let i = 1; i < input.length; i++) {\r\n const [u, v] = input[i]\r\n add(u - 1, v - 1)\r\n add(v - 1, u - 1)\r\n }\r\n const colors = []\r\n const dfs = (i, color) => {\r\n if (colors[i]) return\r\n colors[i] = color\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n dfs(j, 3 - color)\r\n }\r\n }\r\n dfs(0, 1)\r\n let s1 = 0,\r\n s2 = 0\r\n for (let num of colors) {\r\n if (num === 1) s1++\r\n else if (num === 2) s2++\r\n }\r\n if (s1 === s2) {\r\n console.log(`${s1} ${s1 + s2}`)\r\n console.log(new Array(n).fill(1).join(' '))\r\n return\r\n }\r\n\r\n const lt = s1 > s2 ? 2 : 1\r\n const res = new Array(n).fill(0)\r\n for (let i = 0; i < colors.length; i++) {\r\n if (colors[i] === lt) {\r\n res[i] = 1\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n res[j] += 1\r\n }\r\n }\r\n }\r\n let sum = 0\r\n for (let i = 0; i < res.length; i++) sum += res[i]\r\n console.log(`${s1 > s2 ? s1 : s2} ${sum}`)\r\n console.log(res.join(' '))\r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\nfunction main(input) {\r\n const n = input[0][0]\r\n if (n === 2) {\r\n console.log(`2 2\\n1 1`)\r\n return\r\n }\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = []\r\n let idx = 0\r\n const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))\r\n for (let i = 1; i < input.length; i++) {\r\n const [u, v] = input[i]\r\n add(u - 1, v - 1)\r\n add(v - 1, u - 1)\r\n }\r\n const colors = []\r\n const dfs = (i, color) => {\r\n if (colors[i]) return\r\n colors[i] = color\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n dfs(j, 3 - color)\r\n }\r\n }\r\n dfs(0, 1)\r\n let s1 = 0,\r\n s2 = 0\r\n for (let num of colors) {\r\n if (num === 1) s1++\r\n else if (num === 2) s2++\r\n }\r\n const lt = s1 > s2 ? 2 : 1\r\n const res = new Array(n).fill(0)\r\n for (let i = 0; i < colors.length; i++) {\r\n if (colors[i] === lt) {\r\n res[i] = 1\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n res[j] += 1\r\n }\r\n }\r\n }\r\n let sum = 0\r\n for (let i = 0; i < res.length; i++) sum += res[i]\r\n console.log(`${s1 > s2 ? s1 : s2} ${sum}`)\r\n console.log(res.join(' '))\r\n}"}, {"source_code": "const fs = require('fs')\r\nconst input = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map((line) => line.split(' ').map(Number))\r\nmain(input)\r\nfunction main(input) {\r\n const n = input[0][0]\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = []\r\n let idx = 0\r\n const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))\r\n for (let i = 1; i < input.length; i++) {\r\n const [u, v] = input[i]\r\n add(u - 1, v - 1)\r\n add(v - 1, u - 1)\r\n }\r\n const colors = []\r\n const dfs = (i, color) => {\r\n if (colors[i]) return\r\n colors[i] = color\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n dfs(j, 3 - color)\r\n }\r\n }\r\n dfs(0, 1)\r\n let s1 = 0,\r\n s2 = 0\r\n for (let num of colors) {\r\n if (num === 1) s1++\r\n else if (num === 2) s2++\r\n }\r\n const lt = s1 > s2 ? 2 : 1\r\n const res = new Array(n).fill(0)\r\n for (let i = 0; i < colors.length; i++) {\r\n if (colors[i] === lt) {\r\n res[i] = 1\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n res[j] += 1\r\n }\r\n }\r\n }\r\n let sum = 0\r\n for (let i = 0; i < res.length; i++) sum += res[i]\r\n console.log(`${s1 > s2 ? s1 : s2} ${sum}`)\r\n console.log(res.join(' '))\r\n}"}], "src_uid": "dc3848faf577c5a49273020a14b343e1"} {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n let [n, k] = inputReader.readNumberArray();\r\n let v = [];\r\n for (let i = 0; i < n; i++) {\r\n v[i] = new Array(n);\r\n for (let j = 0; j < n; j++) v[i][j] = \".\";\r\n }\r\n\r\n let possibleRooks = Math.ceil(n / 2);\r\n if (k > possibleRooks) {\r\n console.log(-1);\r\n return;\r\n }\r\n let i = 0,\r\n j = 0;\r\n while (k > 0) {\r\n v[i][j] = \"R\";\r\n i += 2;\r\n j += 2;\r\n k -= 1;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let string = \"\";\r\n for (let j = 0; j < n; j++) {\r\n string += v[i][j];\r\n }\r\n console.log(string);\r\n }\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n", "positive_code": [{"source_code": "/**\r\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\r\n *\r\n * To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other\r\n */\r\n\r\n// Write your solution here\r\nconst {EOL} = require(\"os\");\r\n\r\nfunction board({n, k}) {\r\n return Array.from({length: n}, (_, i) =>\r\n Array.from({length: n}, (_, j) => i % 2 === 0 && j % 2 === 0 && i === j && ((i / 2) + 1) <= k ? 'R' : '.').join('')\r\n ).join('\\n');\r\n}\r\n\r\nfunction solution({n, k}) {\r\n return Math.ceil(n / 2) < k ? -1 : board({n, k});\r\n}\r\n\r\nfunction parse(input) {\r\n const [n, k] = input.shift().split(' ').map(Number);\r\n return {n, k};\r\n}\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for (let _ = 0; _ < number_of_test_cases; _ += 1) {\r\n console.log(solution(parse(input)));\r\n }\r\n});"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const [n,k] = await readIntArray();\r\n if (k > Math.floor(n + 1) / 2) {\r\n console.log(-1);\r\n } else {\r\n const a = new Array(n);\r\n let nrooks = 0;\r\n for(let i = 0; i < n; i++) {\r\n for(let j = 0; j < n; j++)\r\n if (i===j && i % 2===0 && nrooks < k) {\r\n a[j] = 'R';\r\n nrooks++;\r\n }\r\n else\r\n a[j] = '.';\r\n console.log(a.join(''));\r\n }\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [n, k] = nl.nums();\n\t\tif ((2 * k - 1) <= n) {\n\t\t\tlet s = [];\n\t\t\tfor(let x = 0; x < n; x++){\n\t\t\t\tfor(let y = 0; y < n; y++){\n\t\t\t\t\tif (x === y && x % 2 === 0 && k > 0){\n\t\t\t\t\t\ts.push(\"R\");\n\t\t\t\t\t\tk--;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ts.push(\".\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (x != n-1) {\n\t\t\t\t\ts.push('\\n');\n\t\t\t\t}\n\t\t\t}\n\t\t\tans.push(s.join(''));\n\t\t} else {\n\t\t\t\tans.push('-1');\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k) {\n if (k > Math.ceil(n / 2)) return -1\n\n const grid = []\n for (let i = 0; i < n; i++) {\n grid[i] = []\n for (let j = 0; j < n; j++) {\n grid[i][j] = '.'\n }\n }\n for (let i = 0; i < k; i++) {\n grid[2 * i][2 * i] = 'R'\n }\n return grid.map(r => r.join('')).join('\\n')\n}\n"}], "negative_code": [{"source_code": "const {EOL} = require(\"os\");\r\n\r\nfunction board({n, k}) {\r\n return Array.from({length: n}, (_, i) =>\r\n Array.from({length: n}, (_, j) => i%2 === 0 && j%2 === 0 && i === j && i <= k? 'R': '.').join('')\r\n ).join('\\n');\r\n}\r\n\r\nfunction solution({n, k}) {\r\n return Math.ceil(n/2) < k ? -1 : board({n, k});\r\n}\r\n\r\nfunction parse(input) {\r\n const [n, k] = input.shift().split(' ').map(Number);\r\n return {n, k};\r\n}\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for (let _ = 0; _ < number_of_test_cases; _ += 1) {\r\n console.log(solution(parse(input)));\r\n }\r\n});"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const nsc = await readInt();\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const [n,k] = await readIntArray();\r\n if (k > Math.floor(n + 1) / 2) {\r\n console.log(-1);\r\n } else {\r\n const a = new Array(n);\r\n for(let i = 0; i < n; i++) {\r\n for(let j = 0; j < n; j++)\r\n if (i===j && i % 2===0)\r\n a[j] = 'R';\r\n else\r\n a[j] = '.';\r\n console.log(a.join(''));\r\n }\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "d5549c0627c236d82541a67ccbe7977d"} {"source_code": "/*\n......descrition.....\n...................\nA. Number of Apartments\ntime limit per test1 second\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nRecently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room \u2014 five windows, and a seven-room \u2014 seven windows.\n\nMonocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.\n\nUnfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.\n\nHere are some examples:\n\nif Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2\u22c53+2\u22c55+2\u22c57=30;\nif Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7\u22c53+5\u22c55+3\u22c57=67;\nif Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.\nInput\nTh first line contains one integer t (1\u2264t\u22641000) \u2014 the number of test cases.\n\nThe only line of each test case contains one integer n (1\u2264n\u22641000) \u2014 the number of windows in the building.\n\nOutput\nFor each test case, if a building with the new layout and the given number of windows just can't exist, print \u22121.\n\nOtherwise, print three non-negative integers \u2014 the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.\n\nExample\ninputCopy\n4\n30\n67\n4\n14\noutputCopy\n2 2 2\n7 5 3\n-1\n0 0 2\n\nTrois tableua des multipliant de 3 et 5 et 7 et un boolean found \npuis chercher si existe dans chaque tableau et mettre found a true\npuis cherchhr si somme de valeurs entre chaque deux tableau et mettre found a true\nsi not found afficher -1\n*/\n\n\nvar testCasesNumber = readline();\nvar listOfWindowsNumber = [];\nvar valus0fX3 =[0,\t3,\t6,\t9,\t12,\t15,\t18,\t21,\t24,\t27,\t30,\t33,\t36,\t39,\t42,\t45,\t48,\t51,\t54,\t57,\t60,\t63,\t66,\t69,\t72,\t75,\t78,\t81,\t84,\t87,\t90,\t93,\t96,\t99,\t102,\t105,\t108,\t111,\t114,\t117,\t120,\t123,\t126,\t129,\t132,\t135,\t138,\t141,\t144,\t147,\t150,\t153,\t156,\t159,\t162,\t165,\t168,\t171,\t174,\t177,\t180,\t183,\t186,\t189,\t192,\t195,\t198,\t201,\t204,\t207,\t210,\t213,\t216,\t219,\t222,\t225,\t228,\t231,\t234,\t237,\t240,\t243,\t246,\t249,\t252,\t255,\t258,\t261,\t264,\t267,\t270,\t273,\t276,\t279,\t282,\t285,\t288,\t291,\t294,\t297,\t300,\t303,\t306,\t309,\t312,\t315,\t318,\t321,\t324,\t327,\t330,\t333,\t336,\t339,\t342,\t345,\t348,\t351,\t354,\t357,\t360,\t363,\t366,\t369,\t372,\t375,\t378,\t381,\t384,\t387,\t390,\t393,\t396,\t399,\t402,\t405,\t408,\t411,\t414,\t417,\t420,\t423,\t426,\t429,\t432,\t435,\t438,\t441,\t444,\t447,\t450,\t453,\t456,\t459,\t462,\t465,\t468,\t471,\t474,\t477,\t480,\t483,\t486,\t489,\t492,\t495,\t498,\t501,\t504,\t507,\t510,\t513,\t516,\t519,\t522,\t525,\t528,\t531,\t534,\t537,\t540,\t543,\t546,\t549,\t552,\t555,\t558,\t561,\t564,\t567,\t570,\t573,\t576,\t579,\t582,\t585,\t588,\t591,\t594,\t597,\t600,\t603,\t606,\t609,\t612,\t615,\t618,\t621,\t624,\t627,\t630,\t633,\t636,\t639,\t642,\t645,\t648,\t651,\t654,\t657,\t660,\t663,\t666,\t669,\t672,\t675,\t678,\t681,\t684,\t687,\t690,\t693,\t696,\t699,\t702,\t705,\t708,\t711,\t714,\t717,\t720,\t723,\t726,\t729,\t732,\t735,\t738,\t741,\t744,\t747,\t750,\t753,\t756,\t759,\t762,\t765,\t768,\t771,\t774,\t777,\t780,\t783,\t786,\t789,\t792,\t795,\t798,\t801,\t804,\t807,\t810,\t813,\t816,\t819,\t822,\t825,\t828,\t831,\t834,\t837,\t840,\t843,\t846,\t849,\t852,\t855,\t858,\t861,\t864,\t867,\t870,\t873,\t876,\t879,\t882,\t885,\t888,\t891,\t894,\t897,\t900,\t903,\t906,\t909,\t912,\t915,\t918,\t921,\t924,\t927,\t930,\t933,\t936,\t939,\t942,\t945,\t948,\t951,\t954,\t957,\t960,\t963,\t966,\t969,\t972,\t975,\t978,\t981,\t984,\t987,\t990,\t993,\t996,\t999];\nvar valus0fX5 =[0,\t5,\t10,\t15,\t20,\t25,\t30,\t35,\t40,\t45,\t50,\t55,\t60,\t65,\t70,\t75,\t80,\t85,\t90,\t95,\t100,\t105,\t110,\t115,\t120,\t125,\t130,\t135,\t140,\t145,\t150,\t155,\t160,\t165,\t170,\t175,\t180,\t185,\t190,\t195,\t200,\t205,\t210,\t215,\t220,\t225,\t230,\t235,\t240,\t245,\t250,\t255,\t260,\t265,\t270,\t275,\t280,\t285,\t290,\t295,\t300,\t305,\t310,\t315,\t320,\t325,\t330,\t335,\t340,\t345,\t350,\t355,\t360,\t365,\t370,\t375,\t380,\t385,\t390,\t395,\t400,\t405,\t410,\t415,\t420,\t425,\t430,\t435,\t440,\t445,\t450,\t455,\t460,\t465,\t470,\t475,\t480,\t485,\t490,\t495,\t500,\t505,\t510,\t515,\t520,\t525,\t530,\t535,\t540,\t545,\t550,\t555,\t560,\t565,\t570,\t575,\t580,\t585,\t590,\t595,\t600,\t605,\t610,\t615,\t620,\t625,\t630,\t635,\t640,\t645,\t650,\t655,\t660,\t665,\t670,\t675,\t680,\t685,\t690,\t695,\t700,\t705,\t710,\t715,\t720,\t725,\t730,\t735,\t740,\t745,\t750,\t755,\t760,\t765,\t770,\t775,\t780,\t785,\t790,\t795,\t800,\t805,\t810,\t815,\t820,\t825,\t830,\t835,\t840,\t845,\t850,\t855,\t860,\t865,\t870,\t875,\t880,\t885,\t890,\t895,\t900,\t905,\t910,\t915,\t920,\t925,\t930,\t935,\t940,\t945,\t950,\t955,\t960,\t965,\t970,\t975,\t980,\t985,\t990,\t995,\t1000];\nvar valus0fX7 =[0,\t7,\t14,\t21,\t28,\t35,\t42,\t49,\t56,\t63,\t70,\t77,\t84,\t91,\t98,\t105,\t112,\t119,\t126,\t133,\t140,\t147,\t154,\t161,\t168,\t175,\t182,\t189,\t196,\t203,\t210,\t217,\t224,\t231,\t238,\t245,\t252,\t259,\t266,\t273,\t280,\t287,\t294,\t301,\t308,\t315,\t322,\t329,\t336,\t343,\t350,\t357,\t364,\t371,\t378,\t385,\t392,\t399,\t406,\t413,\t420,\t427,\t434,\t441,\t448,\t455,\t462,\t469,\t476,\t483,\t490,\t497,\t504,\t511,\t518,\t525,\t532,\t539,\t546,\t553,\t560,\t567,\t574,\t581,\t588,\t595,\t602,\t609,\t616,\t623,\t630,\t637,\t644,\t651,\t658,\t665,\t672,\t679,\t686,\t693,\t700,\t707,\t714,\t721,\t728,\t735,\t742,\t749,\t756,\t763,\t770,\t777,\t784,\t791,\t798,\t805,\t812,\t819,\t826,\t833,\t840,\t847,\t854,\t861,\t868,\t875,\t882,\t889,\t896,\t903,\t910,\t917,\t924,\t931,\t938,\t945,\t952,\t959,\t966,\t973,\t980,\t987,\t994];\n\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfWindowsNumber[i] = readline();\n }\n\nfor (var i = 0; i < testCasesNumber; i++) {\n var found=false;\n var number = parseInt(listOfWindowsNumber[i]);\n if (number==1 || number==2 || number==4)\n {\n print(-1);\n found=true;\n }\n if (valus0fX3.indexOf(number,0)!=-1) {\n print (number/3,0,0);\n found=true;\n }\n \n if ((valus0fX5.indexOf(number,0)!=-1) && (found == false)) {\n print (0,number/5,0);\n found=true;\n }\n \n if ((valus0fX7.indexOf(number,0)!=-1) && (found == false)) {\n print (0,0,number/7);\n found=true;\n }\n \n for(var t3 in valus0fX3){\n if (found==true){\n break;\n }\n for (var t5 in valus0fX5){\n if (number==t3*3+t5*5){\n print(t3,t5,0);\n found=true;\n break;\n }\n }\n }\n \n /* for(var t32 in valus0fX3){\n if (found==true){\n break;\n }\n for (var t7 in valus0fX7){\n if (number==t32*3+t7*7){\n print(t32,0,t7);\n found=true;\n break;\n }\n }\n }\n\n \n for(var t52 in valus0fX5){\n if (found==true){\n break;\n }\n for (var t72 in valus0fX7){\n if (number==t52*5+t72*7){\n print(0,t52,t72);\n found=true;\n break;\n }\n }\n } */\n/**/\n if (found==false){\n print(-1);\n}\n \n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = 0;\n let b = 0;\n let c = 0;\n let isFound = false;\n for(let i = 0; i <= Math.floor(n/3); i++){\n if(isFound)\n break;\n if(3*i > n)\n break;\n else if(3*i === n){\n a = i;\n isFound = true;\n break;\n }\n for(let j = 0; j <= Math.floor(n/5); j++){\n if(isFound)\n break;\n if(3*i + 5*j > n)\n break;\n else if(3*i + 5*j === n){\n a = i; b = j;\n isFound = true;\n break;\n }\n for(let k = 0; k <= Math.floor(n/7); k++){\n if(3*i + 5*j + 7*k === n){\n a = i; b = j; c = k;\n isFound = true;\n break;\n }else if(3*i + 5*j + 7*k > n){\n break;\n }\n }\n }\n }\n\n if(isFound)\n console.log(a,b,c)\n else\n console.log(-1);\n }\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nlet mem = new Map();\nfunction query(n){\n if (n<0)\n return;\n if (n==0)\n return [0, 0, 0];\n if (mem.has(n))\n return mem.get(n);\n for (let [i, d] of [3, 5, 7].entries())\n {\n let res = query(n-d);\n if (!res)\n continue;\n res = res.slice(0);\n res[i]++;\n mem.set(n, res);\n return res;\n }\n mem.set(n, null);\n}\n\nfunction main() {\n var q = +readline();\n while (q--)\n {\n var n = +readline();\n let res = query(n);\n if (res)\n print(res.join(' '));\n else\n print(-1);\n }\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var totalWindows = parseInt(readline());\n var rooms = [0, 0, 0];\n if (totalWindows < 3 || totalWindows === 4) {\n print(\"-1\");\n continue;\n } else {\n var isCompvared = false;\n\n if (totalWindows % 3 === 0) {\n rooms[0] = totalWindows / 3;\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n continue;\n }\n if (totalWindows % 5 === 0) {\n rooms[1] = totalWindows / 5;\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n continue;\n }\n if (totalWindows % 7 === 0) {\n rooms[2] = totalWindows / 7;\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n continue;\n }\n for (var j = Math.floor(totalWindows / 3); j >= 0; j--) {\n var leftOverWindows = totalWindows - 3 * j;\n\n if (leftOverWindows >= 5 && leftOverWindows % 5 === 0) {\n rooms = [j, leftOverWindows / 5, 0];\n isCompvared = true;\n break;\n } else if (leftOverWindows >= 7 && leftOverWindows % 7 === 0) {\n rooms = [j, 0, leftOverWindows / 7];\n isCompvared = true;\n break;\n } else if (leftOverWindows >= 8 && leftOverWindows % 8 === 0) {\n var total = leftOverWindows / 8;\n rooms = [j + total, total, 0];\n isCompvared = true;\n break;\n }\n }\n if (isCompvared) {\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n } else {\n print(\"-1\");\n }\n }\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet isFirst = true;\nreadline.on('line', line => {\n if(isFirst) return isFirst = false;\n const variant = getCombination(+line);\n const map = {3:0,5:0,7:0}\n if(variant) {\n variant.forEach(num => map[num]++);\n console.log(`${map[3]} ${map[5]} ${map[7]}`);\n } else {\n console.log(-1);\n }\n \n});\n\n\n\nfunction getCombination(total, acc = []) {\n if(total === 0) return acc;\n if(total < 0) return null;\n let possible = null;\n for(let num of [3,5,7]) {\n const variant = getCombination(total - num, [...acc, num]);\n if(variant) {\n possible = variant;\n break;\n }\n }\n\n return possible;\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n let [a, b, c] = [0, 0, 0];\n\n if (num === 1 || num === 2 || num === 4) {\n console.log(-1);\n continue;\n } else {\n if (num % 3 == 0) {\n console.log(`${Math.floor(num / 3)} ${b} ${c}`);\n continue;\n } else if (num % 5 == 0) {\n console.log(`${a} ${Math.floor(num / 5)} ${c}`);\n continue;\n } else if (num % 7 == 0) {\n console.log(`${a} ${b} ${Math.floor(num / 7)}`);\n continue;\n } else {\n while (num) {\n if (num % 3 === 0) {\n a = Math.floor(num / 3);\n break;\n }\n b++;\n num -= 5;\n }\n console.log(`${a} ${b} ${c}`);\n continue;\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n const n = data[i] * 1;\n if (n % 7 === 0) console.log('0 0 ' + n / 7);\n else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');\n else if(n % 3 === 0) console.log(n / 3 + ' 0 0');\n else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');\n else if (n % 10 === 3 || n % 10 === 8) console.log('1 ' + (n - 3) / 5 + ' 0');\n else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');\n else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');\n // else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');\n else if (n > 1 && n % 10 === 1) console.log('2 ' + (n - 6) / 5 + ' 0');\n else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');\n else console.log(-1);\n // const k = a[1];\n // let s = data[i + 1].trim().split(' ');\n \n i += 1;\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let f = Arr(1e3 + 1, i => []);\n f[0] = [0, 0, 0]\n For(1, 1e3, i => {\n if (i >= 3 && f[i - 3].length) { f[i] = [...f[i - 3]]; f[i][0]++ }\n if (i >= 5 && f[i - 5].length) { f[i] = [...f[i - 5]]; f[i][1]++ }\n if (i >= 7 && f[i - 7].length) { f[i] = [...f[i - 7]]; f[i][2]++ }\n })\n\n let t = $()\n while (t--) {\n let n = $()\n if (f[n].length) {\n log(f[n].join(' '))\n } else {\n log(-1)\n }\n }\n}\n"}, {"source_code": "const { createInterface } = require('readline')\n\nconst f = (it, obj) => {\n if (it === 0) return true\n if (it < 0) return\n obj.a++\n if (f(it - 7, obj)) return true; else obj.a--\n obj.b++\n if (f(it - 5, obj)) return true; else obj.b--\n obj.c++\n if (f(it - 3, obj)) return true; else obj.c--\n}\n\nlet count = -1\ncreateInterface(process.stdin, process.stdout).on('line', q => {\n if (count === 0) return\n if (count === -1) {\n count = +q\n return\n } else count--\n const obj = { a: 0, b: 0, c: 0 }\n if (f(+q, obj)) console.log(obj.c, obj.b, obj.a)\n else console.log('-1')\n if (!count) process.exit()\n})\n"}], "negative_code": [{"source_code": "let mem = new Map();\nfunction query(n){\n if (n<0)\n return;\n if (n==0)\n return [0, 0, 0];\n if (mem.has(n))\n return mem.get(n);\n for (let [i, d] of [3, 5, 7].entries())\n {\n let res = query(n-d);\n if (!res)\n continue;\n res = res.slice(0);\n res[i]++;\n mem.set(n, res);\n return res;\n }\n mem.set(n, null);\n}\n\nfunction main() {\n var q = +readline();\n while (q--)\n {\n var n = +readline();\n let res = query(n);\n if (res)\n print(res.join(' '));\n else\n print(-1);\n }\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nreadline.on('line', line => {\n const variant = getCombination(+line);\n const map = {3:0,5:0,7:0}\n if(variant) {\n variant.forEach(num => map[num]++);\n console.log(`${map[3]} ${map[5]} ${map[7]}`);\n } else {\n console.log(-1);\n }\n \n});\n\n\n\nfunction getCombination(total, acc = []) {\n if(total === 0) return acc;\n if(total < 0) return null;\n let possible = null;\n for(let num of [3,5,7]) {\n const variant = getCombination(total - num, [...acc, num]);\n if(variant) {\n possible = variant;\n break;\n }\n }\n\n return possible;\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n const ans = [0, 0, 0];\n\n if (num % 3 === 0) {\n ans[0] = Math.floor(num / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 3) % 5 === 0) {\n ans[0] = Math.floor(num / 3);\n ans[1] = Math.floor((num % 3) / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 3) % 7 === 0) {\n ans[0] = Math.floor(num / 3);\n ans[2] = Math.floor((num % 3) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 5 === 0) {\n ans[1] = Math.floor(num / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 5) % 3 === 0) {\n ans[1] = Math.floor(num / 5);\n ans[0] = Math.floor((num % 5) / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 5) % 7 === 0) {\n ans[1] = Math.floor(num / 5);\n ans[2] = Math.floor((num % 5) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 7 === 0) {\n ans[2] = Math.floor(num / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 7) % 5 === 0) {\n ans[2] = Math.floor(num / 7);\n ans[1] = Math.floor((num % 7) / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 7) % 3 === 0) {\n ans[2] = Math.floor(num / 7);\n ans[0] = Math.floor((num % 7) / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 8 === 0) {\n ans[0] = Math.floor(num / 8);\n ans[1] = Math.floor(num / 8);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 8) % 7 === 0) {\n ans[0] = Math.floor(num / 8);\n ans[1] = Math.floor(num / 8);\n ans[2] = Math.floor((num % 8) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 10 === 0) {\n ans[0] = Math.floor(num / 10);\n ans[2] = Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 10) % 5 === 0) {\n ans[0] = Math.floor(num / 10);\n ans[1] = Math.floor((num % 10) / 5);\n ans[2] = Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 12 === 0) {\n ans[1] = Math.floor(num / 12);\n ans[2] = Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 12) % 3 === 0) {\n ans[0] = Math.floor((num % 12) / 3);\n ans[1] = Math.floor(num / 12);\n ans[2] = Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 15 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 3 === 0) {\n ans[0] = Math.floor(num / 15) + Math.floor((num % 15) / 3);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 5 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15) + Math.floor((num % 15) / 5);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 7 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15) + Math.floor((num % 15) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else {\n console.log(-1);\n continue;\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n const ans = [0, 0, 0];\n\n if (num % 3 === 0) {\n ans[0] = Math.floor(num / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 3) % 5 === 0) {\n ans[0] = Math.floor(num / 3);\n ans[1] = Math.floor((num % 3) / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 3) % 7 === 0) {\n ans[0] = Math.floor(num / 3);\n ans[2] = Math.floor((num % 3) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 5 === 0) {\n ans[1] = Math.floor(num / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 5) % 3 === 0) {\n ans[1] = Math.floor(num / 5);\n ans[0] = Math.floor((num % 5) / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 5) % 7 === 0) {\n ans[1] = Math.floor(num / 5);\n ans[2] = Math.floor((num % 5) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 7 === 0) {\n ans[2] = Math.floor(num / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 7) % 5 === 0) {\n ans[2] = Math.floor(num / 7);\n ans[1] = Math.floor((num % 7) / 5);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 7) % 3 === 0) {\n ans[2] = Math.floor(num / 7);\n ans[0] = Math.floor((num % 7) / 3);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 8 === 0) {\n ans[0] = Math.floor(num / 8);\n ans[1] = Math.floor(num / 8);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 8) % 3 === 0) {\n ans[0] = Math.floor((num % 8) / 3) + Math.floor(num / 8);\n ans[1] = Math.floor(num / 8);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 8) % 5 === 0) {\n ans[0] = Math.floor(num / 8);\n ans[1] = Math.floor((num % 8) / 5) + Math.floor(num / 8);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 8) % 7 === 0) {\n ans[0] = Math.floor(num / 8);\n ans[1] = Math.floor(num / 8);\n ans[2] = Math.floor((num % 8) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 10 === 0) {\n ans[0] = Math.floor(num / 10);\n ans[2] = Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 10) % 3 === 0) {\n ans[0] = Math.floor((num % 10) / 3) + Math.floor(num / 10);\n ans[2] = Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 10) % 7 === 0) {\n ans[0] = Math.floor(num / 10);\n ans[2] = Math.floor((num % 10) / 7) + Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 10) % 5 === 0) {\n ans[0] = Math.floor(num / 10);\n ans[1] = Math.floor((num % 10) / 5);\n ans[2] = Math.floor(num / 10);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 12 === 0) {\n ans[1] = Math.floor(num / 12);\n ans[2] = Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 12) % 5 === 0) {\n ans[1] = Math.floor((num % 12) / 5) + Math.floor(num / 12);\n ans[2] = Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 12) % 7 === 0) {\n ans[1] = Math.floor(num / 12);\n ans[2] = Math.floor((num % 12) / 7) + Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 12) % 3 === 0) {\n ans[0] = Math.floor((num % 12) / 3);\n ans[1] = Math.floor(num / 12);\n ans[2] = Math.floor(num / 12);\n console.log(ans.join(\" \"));\n continue;\n } else if (num % 15 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 3 === 0) {\n ans[0] = Math.floor(num / 15) + Math.floor((num % 15) / 3);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 5 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15) + Math.floor((num % 15) / 5);\n ans[2] = Math.floor(num / 15);\n console.log(ans.join(\" \"));\n continue;\n } else if ((num % 15) % 7 === 0) {\n ans[0] = Math.floor(num / 15);\n ans[1] = Math.floor(num / 15);\n ans[2] = Math.floor(num / 15) + Math.floor((num % 15) / 7);\n console.log(ans.join(\" \"));\n continue;\n } else {\n console.log(-1);\n continue;\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n let [a, b, c] = [0, 0, 0];\n\n if (num === 1 || num === 2 || num === 4) {\n console.log(-1);\n continue;\n } else {\n while (num) {\n c++;\n num -= 7;\n if (num % 3 === 0) {\n a = Math.floor(num / 3);\n break;\n }\n }\n console.log(`${a} ${b} ${c}`);\n continue;\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n let [a, b, c] = [0, 0, 0];\n\n if (num === 1 || num === 2 || num === 4) {\n console.log(-1);\n continue;\n } else {\n while (num) {\n if (num % 3 === 0) {\n a = Math.floor(num / 3);\n break;\n }\n c++;\n num -= 7;\n }\n console.log(`${a} ${b} ${c}`);\n continue;\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n const n = data[i] * 1;\n if (n % 7 === 0) console.log('0 0 ' + n / 7);\n else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');\n else if(n % 3 === 0) console.log(n / 3 + ' 0 0');\n else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');\n else if (n % 10 === 3) console.log('1 ' + (n - 3) / 5 + ' 0');\n else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');\n else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');\n else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');\n else if (n > 11 && n % 10 === 1) console.log('7 ' + (n - 21) / 5 + ' 0');\n else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');\n else console.log(-1);\n // const k = a[1];\n // let s = data[i + 1].trim().split(' ');\n \n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n const n = data[i] * 1;\n if (n % 7 === 0) console.log('0 0 ' + n / 7);\n else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');\n else if(n % 3 === 0) console.log(n / 3 + ' 0 0');\n else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');\n else if (n % 10 === 3 || n % 10 === 8) console.log('1 ' + (n - 3) / 5 + ' 0');\n else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');\n else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');\n // else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');\n else if (n > 11 && n % 10 === 1) console.log('7 ' + (n - 21) / 5 + ' 0');\n else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');\n else console.log(-1);\n // const k = a[1];\n // let s = data[i + 1].trim().split(' ');\n \n i += 1;\n }\n}"}, {"source_code": "/* eslint-disable @typescript-eslint/no-var-requires */\nconst { createInterface } = require('readline')\n\nconst f = (it, obj) => {\n if (it === 0) return true\n if (it < 0) return\n obj.a++\n if (f(it - 7, obj)) return true; else obj.a--\n obj.b++\n if (f(it - 5, obj)) return true; else obj.b--\n obj.c++\n if (f(it - 3, obj)) return true; else obj.c--\n}\n\nlet count = -1\ncreateInterface(process.stdin, process.stdout).on('line', q => {\n if (count === 0) return\n if (count === -1) {\n count = +q\n return\n } else count--\n const obj = { a: 0, b: 0, c: 0 }\n if (f(+q, obj)) console.log(obj.a, obj.b, obj.c)\n else console.log('-1')\n if (!count) process.exit()\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = 0;\n let b = 0;\n let c = 0;\n let isFound = false;\n for(let i = 0; i <= Math.floor(n/3); i++){\n if(3*i > n)\n break;\n else if(3*i === n){\n a = i;\n isFound = true;\n break;\n }\n for(let j = 0; j <= Math.floor(n/5); j++){\n if(3*i + 5*j > n)\n break;\n else if(3*i + 5*j === n){\n a = i; b = j;\n isFound = true;\n break;\n }\n for(let k = 0; k <= Math.floor(n/7); k++){\n if(3*i + 5*j + 7*k === n){\n a = i; b = j; c = k;\n isFound = true;\n break;\n }else if(3*i + 5*j + 7*k > n){\n break;\n }\n }\n }\n }\n\n if(isFound)\n console.log(a,b,c)\n else\n console.log(-1);\n }\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var totalWindows = parseInt(readline());\n var rooms = [0, 0, 0];\n if (totalWindows < 3 || totalWindows === 4) {\n print(\"-1\");\n continue;\n } else {\n var isCompvared = false;\n\n if (totalWindows % 3 === 0) {\n rooms[0] = totalWindows / 3;\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n continue;\n }\n for (var j = Math.floor(totalWindows / 3); j >= 0; j--) {\n var leftOverWindows = totalWindows - 3 * j;\n\n if (leftOverWindows > 5 && leftOverWindows % 5 === 0) {\n rooms = [j, leftOverWindows / 5, 0];\n isCompvared = true;\n break;\n } else if (leftOverWindows > 7 && leftOverWindows % 7 === 0) {\n rooms = [j, 0, leftOverWindows / 7];\n isCompvared = true;\n break;\n } else if (leftOverWindows > 8 && leftOverWindows % 8 === 0) {\n var total = leftOverWindows / 8;\n rooms = [j + total, total, 0];\n isCompvared = true;\n break;\n }\n }\n if (isCompvared) {\n print(rooms[0] + \" \" + rooms[1] + \" \" + rooms[2]);\n } else {\n print(\"-1\");\n }\n }\n}\n"}, {"source_code": "/*\n......descrition.....\n...................\nA. Number of Apartments\ntime limit per test1 second\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nRecently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room \u2014 five windows, and a seven-room \u2014 seven windows.\n\nMonocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.\n\nUnfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.\n\nHere are some examples:\n\nif Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2\u22c53+2\u22c55+2\u22c57=30;\nif Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7\u22c53+5\u22c55+3\u22c57=67;\nif Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.\nInput\nTh first line contains one integer t (1\u2264t\u22641000) \u2014 the number of test cases.\n\nThe only line of each test case contains one integer n (1\u2264n\u22641000) \u2014 the number of windows in the building.\n\nOutput\nFor each test case, if a building with the new layout and the given number of windows just can't exist, print \u22121.\n\nOtherwise, print three non-negative integers \u2014 the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.\n\nExample\ninputCopy\n4\n30\n67\n4\n14\noutputCopy\n2 2 2\n7 5 3\n-1\n0 0 2 */\n\n\nvar testCasesNumber = readline();\nvar listOfWindowsNumber = [];\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfWindowsNumber[i] = readline();\n }\nvar resultx =[];\nvar resulty =[];\nvar resultz =[];\nvar k=0;\nfor (var i = 0; i < testCasesNumber; i++) {\n var number = parseInt(listOfWindowsNumber[i]);\n for(var x = 0; x < 334; x++){\n for(var y= 0; y < 201; y++){\n for(var z = 0;z < 143; z++){\n if ((x * 3 + y * 5 + z * 7)>number){break;}\n if (number == (x * 3 + y * 5 + z * 7)) { \n resultx.push(x);\n resulty.push(y);\n resultz.push(z);\n k++;\n \n }\n }\n }\n }\nif (k==0) {\n print(-1);}\n else {\n print(resultx[k-1],\" \",resulty[k-1], \" \", resultz[k-1]);\n \n }\n}\n"}, {"source_code": "/*\n......descrition.....\n...................\nA. Number of Apartments\ntime limit per test1 second\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nRecently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room \u2014 five windows, and a seven-room \u2014 seven windows.\n\nMonocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.\n\nUnfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.\n\nHere are some examples:\n\nif Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2\u22c53+2\u22c55+2\u22c57=30;\nif Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7\u22c53+5\u22c55+3\u22c57=67;\nif Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.\nInput\nTh first line contains one integer t (1\u2264t\u22641000) \u2014 the number of test cases.\n\nThe only line of each test case contains one integer n (1\u2264n\u22641000) \u2014 the number of windows in the building.\n\nOutput\nFor each test case, if a building with the new layout and the given number of windows just can't exist, print \u22121.\n\nOtherwise, print three non-negative integers \u2014 the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.\n\nExample\ninputCopy\n4\n30\n67\n4\n14\noutputCopy\n2 2 2\n7 5 3\n-1\n0 0 2\n\nTrois tableua des multipliant de 3 et 5 et 7 et un boolean found \npuis chercher si existe dans chaque tableau et mettre found a true\npuis cherchhr si somme de valeurs entre chaque deux tableau et mettre found a true\nsi not found afficher -1\n*/\n\n\nvar testCasesNumber = readline();\nvar listOfWindowsNumber = [];\nvar valus0fX3 =[0,\t3,\t6,\t9,\t12,\t15,\t18,\t21,\t24,\t27,\t30,\t33,\t36,\t39,\t42,\t45,\t48,\t51,\t54,\t57,\t60,\t63,\t66,\t69,\t72,\t75,\t78,\t81,\t84,\t87,\t90,\t93,\t96,\t99,\t102,\t105,\t108,\t111,\t114,\t117,\t120,\t123,\t126,\t129,\t132,\t135,\t138,\t141,\t144,\t147,\t150,\t153,\t156,\t159,\t162,\t165,\t168,\t171,\t174,\t177,\t180,\t183,\t186,\t189,\t192,\t195,\t198,\t201,\t204,\t207,\t210,\t213,\t216,\t219,\t222,\t225,\t228,\t231,\t234,\t237,\t240,\t243,\t246,\t249,\t252,\t255,\t258,\t261,\t264,\t267,\t270,\t273,\t276,\t279,\t282,\t285,\t288,\t291,\t294,\t297,\t300,\t303,\t306,\t309,\t312,\t315,\t318,\t321,\t324,\t327,\t330,\t333,\t336,\t339,\t342,\t345,\t348,\t351,\t354,\t357,\t360,\t363,\t366,\t369,\t372,\t375,\t378,\t381,\t384,\t387,\t390,\t393,\t396,\t399,\t402,\t405,\t408,\t411,\t414,\t417,\t420,\t423,\t426,\t429,\t432,\t435,\t438,\t441,\t444,\t447,\t450,\t453,\t456,\t459,\t462,\t465,\t468,\t471,\t474,\t477,\t480,\t483,\t486,\t489,\t492,\t495,\t498,\t501,\t504,\t507,\t510,\t513,\t516,\t519,\t522,\t525,\t528,\t531,\t534,\t537,\t540,\t543,\t546,\t549,\t552,\t555,\t558,\t561,\t564,\t567,\t570,\t573,\t576,\t579,\t582,\t585,\t588,\t591,\t594,\t597,\t600,\t603,\t606,\t609,\t612,\t615,\t618,\t621,\t624,\t627,\t630,\t633,\t636,\t639,\t642,\t645,\t648,\t651,\t654,\t657,\t660,\t663,\t666,\t669,\t672,\t675,\t678,\t681,\t684,\t687,\t690,\t693,\t696,\t699,\t702,\t705,\t708,\t711,\t714,\t717,\t720,\t723,\t726,\t729,\t732,\t735,\t738,\t741,\t744,\t747,\t750,\t753,\t756,\t759,\t762,\t765,\t768,\t771,\t774,\t777,\t780,\t783,\t786,\t789,\t792,\t795,\t798,\t801,\t804,\t807,\t810,\t813,\t816,\t819,\t822,\t825,\t828,\t831,\t834,\t837,\t840,\t843,\t846,\t849,\t852,\t855,\t858,\t861,\t864,\t867,\t870,\t873,\t876,\t879,\t882,\t885,\t888,\t891,\t894,\t897,\t900,\t903,\t906,\t909,\t912,\t915,\t918,\t921,\t924,\t927,\t930,\t933,\t936,\t939,\t942,\t945,\t948,\t951,\t954,\t957,\t960,\t963,\t966,\t969,\t972,\t975,\t978,\t981,\t984,\t987,\t990,\t993,\t996,\t999];\nvar valus0fX5 =[0,\t5,\t10,\t15,\t20,\t25,\t30,\t35,\t40,\t45,\t50,\t55,\t60,\t65,\t70,\t75,\t80,\t85,\t90,\t95,\t100,\t105,\t110,\t115,\t120,\t125,\t130,\t135,\t140,\t145,\t150,\t155,\t160,\t165,\t170,\t175,\t180,\t185,\t190,\t195,\t200,\t205,\t210,\t215,\t220,\t225,\t230,\t235,\t240,\t245,\t250,\t255,\t260,\t265,\t270,\t275,\t280,\t285,\t290,\t295,\t300,\t305,\t310,\t315,\t320,\t325,\t330,\t335,\t340,\t345,\t350,\t355,\t360,\t365,\t370,\t375,\t380,\t385,\t390,\t395,\t400,\t405,\t410,\t415,\t420,\t425,\t430,\t435,\t440,\t445,\t450,\t455,\t460,\t465,\t470,\t475,\t480,\t485,\t490,\t495,\t500,\t505,\t510,\t515,\t520,\t525,\t530,\t535,\t540,\t545,\t550,\t555,\t560,\t565,\t570,\t575,\t580,\t585,\t590,\t595,\t600,\t605,\t610,\t615,\t620,\t625,\t630,\t635,\t640,\t645,\t650,\t655,\t660,\t665,\t670,\t675,\t680,\t685,\t690,\t695,\t700,\t705,\t710,\t715,\t720,\t725,\t730,\t735,\t740,\t745,\t750,\t755,\t760,\t765,\t770,\t775,\t780,\t785,\t790,\t795,\t800,\t805,\t810,\t815,\t820,\t825,\t830,\t835,\t840,\t845,\t850,\t855,\t860,\t865,\t870,\t875,\t880,\t885,\t890,\t895,\t900,\t905,\t910,\t915,\t920,\t925,\t930,\t935,\t940,\t945,\t950,\t955,\t960,\t965,\t970,\t975,\t980,\t985,\t990,\t995,\t1000];\nvar valus0fX7 =[0,\t7,\t14,\t21,\t28,\t35,\t42,\t49,\t56,\t63,\t70,\t77,\t84,\t91,\t98,\t105,\t112,\t119,\t126,\t133,\t140,\t147,\t154,\t161,\t168,\t175,\t182,\t189,\t196,\t203,\t210,\t217,\t224,\t231,\t238,\t245,\t252,\t259,\t266,\t273,\t280,\t287,\t294,\t301,\t308,\t315,\t322,\t329,\t336,\t343,\t350,\t357,\t364,\t371,\t378,\t385,\t392,\t399,\t406,\t413,\t420,\t427,\t434,\t441,\t448,\t455,\t462,\t469,\t476,\t483,\t490,\t497,\t504,\t511,\t518,\t525,\t532,\t539,\t546,\t553,\t560,\t567,\t574,\t581,\t588,\t595,\t602,\t609,\t616,\t623,\t630,\t637,\t644,\t651,\t658,\t665,\t672,\t679,\t686,\t693,\t700,\t707,\t714,\t721,\t728,\t735,\t742,\t749,\t756,\t763,\t770,\t777,\t784,\t791,\t798,\t805,\t812,\t819,\t826,\t833,\t840,\t847,\t854,\t861,\t868,\t875,\t882,\t889,\t896,\t903,\t910,\t917,\t924,\t931,\t938,\t945,\t952,\t959,\t966,\t973,\t980,\t987,\t994];\n\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfWindowsNumber[i] = readline();\n }\n\nfor (var i = 0; i < testCasesNumber; i++) {\n var found=false;\n var number = parseInt(listOfWindowsNumber[i]);\n if (valus0fX3.indexOf(number,0)!=-1) {\n print (number/3,0,0);\n found=true;\n }\n \n if ((valus0fX5.indexOf(number,0)!=-1) && (found == false)) {\n print (0,number/5,0);\n found=true;\n }\n \n if ((valus0fX7.indexOf(number,0)!=-1) && (found == false)) {\n print (0,0,number/7);\n found=true;\n }\n \n for(var t3 in valus0fX3){\n if (found==true){\n break;\n }\n for (var t5 in valus0fX5){\n if (number==t3*3+t5*5){\n print(t3,t5,0);\n found=true;\n break;\n }\n }\n }\n \n for(var t32 in valus0fX3){\n if (found==true){\n break;\n }\n for (var t7 in valus0fX7){\n if (number==t32*3+t7*7){\n print(t32,0,t7);\n found=true;\n break;\n }\n }\n }\n\n \n for(var t52 in valus0fX5){\n if (found==true){\n break;\n }\n for (var t72 in valus0fX7){\n if (number==t52*5+t72*7){\n print(0,t52,t72);\n found=true;\n break;\n }\n }\n }\n/**/\n if (found==false){\n print(-1,\"inexistant\");\n}\n \n}\n"}], "src_uid": "b43dee2f223c869a35b1b11ceb9d2b6b"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, c)=>{\n if (n === 1) {\n if (c[0] === 0) return '0';\n else return '1';\n }\n if (c[n - 1] === 0) {\n return new Array(n).fill(0).join(' ');\n }\n\n let result = new Array(n).fill(1);\n\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += c[i];\n }\n let ones = Math.round(sum / n);\n \n let idx = 0;\n while (idx < n && c[idx] === 0) {\n result[idx++] = 0;\n }\n\n while (idx < n) {\n if (result[idx] === 1) {\n if (c[idx] < n) result[c[idx]] = 0;\n } else {\n if (c[idx] + idx < n) result[c[idx] + idx] = 0;\n }\n idx++;\n }\n\n\n return result.join(' ');\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let c = ra();\n console.log(`${calc(n, c)}`);\n }\n}\n\n\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nclass SegTree {\r\n constructor(nums = [], n = nums.length - 1) {\r\n this.nums = nums;\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n this._build(this.root);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n _newNode(l, r, val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n for (let child of [left, right]) {\r\n child.add += node.add;\r\n child.val += node.add * (child.r - child.l + 1);\r\n }\r\n node.add = 0;\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = left.val + right.val;\r\n }\r\n _build(node = this.root) {\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === r) {\r\n var _this$nums$l;\r\n node.val = (_this$nums$l = this.nums[l]) !== null && _this$nums$l !== void 0 ? _this$nums$l : 0;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n this._build(node.left);\r\n this._build(node.right);\r\n node.val = node.left.val + node.right.val;\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) {\r\n node.add += z;\r\n node.val += z * (r - l + 1);\r\n return;\r\n }\r\n this._down(node);\r\n const mid = Math.floor((l + r) / 2);\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n this._down(node);\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) + this._query(node.right, mid + 1, y);\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\nfunction solve(n, a) {\r\n let res = new Array(n).fill(0),\r\n one = a.reduce((a, b) => a + b, 0) / n;\r\n const segTree = new SegTree(a);\r\n for (let i = n - 1; i >= 0; i--) {\r\n const cur = segTree.query(i, i);\r\n segTree.update(i - one + 1, i - 1, -1);\r\n if (cur === i + 1) {\r\n res[i] = 1;\r\n one--;\r\n }\r\n }\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const c = (await read()).split(' ').map(Number);\r\n solve(n, c);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n let one = arr.reduce((s, x) => s + x, 0) / n\r\n let zero = n - one\r\n const last = Array(n).fill(n) // row of the first zero for each column\r\n for (let i = 0; i < zero; i++) {\r\n last[i] = n - 1\r\n }\r\n// console.log(one, zero, last)\r\n const ans = Array(n)\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n const a = i + 1 // if ans[i] = 1\r\n let b = (last[i] - 1) - (i + 1) + 1 // at least contains how many 1s\r\n if (i + 1 >= n) {\r\n b = 0\r\n }\r\n // console.log('sb', a, b, last[i])\r\n // const b = n - last[i]\r\n if (a + b === arr[i]) {\r\n ans[i] = 1\r\n } else {\r\n ans[i] = 0\r\n zero--\r\n last[zero] = i\r\n // console.log(zero, i)\r\n }\r\n }\r\n return ans.join(' ')\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let res = new Array(n).fill(0),\r\n sum = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] - sum >= i + 1) {\r\n res[i] = 1;\r\n sum++;\r\n } else {\r\n sum = 0;\r\n }\r\n }\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const c = (await read()).split(' ').map(Number);\r\n solve(n, c);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let res = new Array(n).fill(0),\r\n sum = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] - sum >= i + 1) {\r\n res[i] = 1;\r\n sum++;\r\n } else {\r\n sum = Math.max(0, sum - 1);\r\n }\r\n }\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const c = (await read()).split(' ').map(Number);\r\n solve(n, c);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let res = [],\r\n one = a.reduce((a, b) => a + b, 0) / n,\r\n p = new Array(n).fill(0),\r\n cur = 0;\r\n for (let i = 0; i < n; i++) {\r\n cur += p[i];\r\n res[i] = a[i] > cur ? 1 : 0;\r\n if (res[i]) {\r\n one--;\r\n const add = one - (a[i] - cur - (i + 1));\r\n p[i + 1] += 1;\r\n p[n - one - 1] += add;\r\n p[n - one] -= add;\r\n }\r\n }\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const c = (await read()).split(' ').map(Number);\r\n solve(n, c);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let one = arr.reduce((s, x) => s + x, 0) / n\n let zero = n - one\n const last = Array(n).fill(n) // row of the last zero for each column\n for (let i = 0; i < zero; i++) {\n last[i] = n - 1\n }\n// console.log(one, zero)\n const ans = Array(n)\n for (let i = arr.length - 1; i >= 0; i--) {\n // const a = i + 1 // if ans[i] = 1\n // const b = Math.max(0, Math.min(zero, i + 1) - (i + 1)) // at least contains how many 1s\n // console.log('sb', a, b)\n const b = n - last[i]\n if (n - b === arr[i]) {\n ans[i] = 1\n } else {\n ans[i] = 0\n zero--\n last[zero] = i\n }\n }\n return ans.join(' ')\n}\n"}], "src_uid": "9dc1bee4e53ced89d827826f2d83dabf"} {"source_code": "// O(n) time complexity, O(m) additional memory.\nvar input = readline().split(\" \").map(i => +i);\nvar n = input[0];\nvar m = input[1];\nvar genreHistogram = new Array(m).fill(0);\nfor (var ai of readline().split(\" \").map(i => +i)) {\n ++genreHistogram[ai - 1];\n}\nvar possibilities = 0;\nfor (var mh of genreHistogram) {\n // Each book within current genre can be combined with any book from any other genre.\n possibilities += mh * (n - mh);\n}\n// We took all pairs into account twice.\npossibilities /= 2;\nwrite(possibilities + \"\\n\");\n", "positive_code": [{"source_code": "var summaryBooks = readline().split(' ')[0];\nvar array = readline().split(' ');\nvar categories = {};\nvar combinations = 0;\n\nfor (var i = 0; i < array.length; i++){\n if (categories[array[i]] === undefined)\n categories[array[i]] = 1;\n else\n categories[array[i]]++;\n}\n\nfor (category in categories){\n summaryBooks -= categories[category];\n combinations += categories[category]*summaryBooks;\n}\n\nprint(combinations);"}, {"source_code": "// O(n) time complexity, O(m) additional memory.\nvar input = readline().split(\" \").map(i => +i);\nvar n = input[0];\nvar m = input[1];\nvar genreHistogram = new Array(m).fill(0);\nfor (var ai of readline().split(\" \").map(i => +i)) {\n ++genreHistogram[ai - 1];\n}\nvar possibilities = 0;\nfor (var mh of genreHistogram) {\n // Each book within current genre can be combined with any book from any other genre.\n possibilities += mh * (n - mh);\n}\n// We took all pairs into account twice.\npossibilities /= 2;\nwrite(possibilities + \"\\n\");"}], "negative_code": [{"source_code": "var summaryBooks = readline().split(' ')[0];\nvar array = readline().split(' ');\nvar categories = {};\nvar combinations = 0;\n\nfor (var i = 0; i < array.length; i++){\n if (categories[i] === undefined)\n categories[i] = 1;\n else\n categories[i]++;\n}\n\nfor (category in categories){\n summaryBooks -= category;\n combinations += category*summaryBooks;\n}\n\nprint(combinations);"}], "src_uid": "e2ff228091ca476926b8e905f1bc8dff"} {"source_code": "\nfunction solve(){\n\tvar fake = readline();\n\tif(fake.length>5){\n\t\tvar h = fake.indexOf(\"h\");\n\t\tif(h!= -1){\n\t\t\tvar e = fake.indexOf(\"e\", h+1);\n\t\t\tif (e!= -1){\n\t\t\t\tvar i = fake.indexOf(\"i\", e+1);\n\t\t\t\tif (i!= -1){\n\t\t\t\t\tvar d = fake.indexOf(\"d\", i+1);\n\t\t\t\t\tif(d!= -1){\n\t\t\t\t\t\tif (i != -1){\n\t\t\t\t\t\t\tvar i2 = fake.indexOf(\"i\", d+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h {\n const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));\n\n for (let i = 0; i < word.length; i++) {\n for (let j = 0; j < str.length; j++) {\n if (word[i] === str[j]) {\n const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;\n matrix[i][j] = prevDiagonal + 1;\n }\n else {\n const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;\n const prevCell = matrix[i][j - 1] || 0;\n matrix[i][j] = Math.max(prevRow, prevCell);\n }\n }\n }\n\n if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst word = 'heidi';\n\nrl.on('line', (str) => {\n const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));\n\n for (let i = 0; i < word.length; i++) {\n for (let j = 0; j < str.length; j++) {\n const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;\n const prevCell = matrix[i][j - 1] || 0;\n\n if (word[i] === str[j]) {\n const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;\n matrix[i][j] = Math.max(prevRow, prevCell, prevDiagonal) + 1;\n }\n else {\n matrix[i][j] = Math.max(prevRow, prevCell);\n }\n }\n }\n\n if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "\nfunction solve(){\n\tvar fake = readline();\n\tif(fake.length>5){\n\t\tvar h = fake.indexOf(\"h\");\n\t\tvar e = fake.indexOf(\"e\");\n\t\tvar i = fake.indexOf(\"i\");\n\t\tvar d = fake.indexOf(\"d\");\n\t\tif (i != -1){\n\t\t\tvar i2 = fake.indexOf(\"i\", i+1);\n\t\t}\n\t\t\n\t\tif((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = cb=>readline().split(' ').map(cb||(a=>+a))\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let B = ra(a=>a-1);\n let P = ra(a=>a-1);\n LT({n, B, P});\n // PROCESSING:\n if (B[P[0]]!=P[0])\n return -1;\n let dist = new Array(n).fill(-1);\n dist[P[0]] = 0;\n for (let i=1; i {\r\n return string.trim();\r\n });\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n // let n = inputReader.readNumber();\r\n // let b= inputReader.readNumberArray();\r\n // let p = inputReader.readNumberArray();\r\n // b.unshift(-1);\r\n // let root = -1;\r\n\r\n // b.forEach((element, ind, arr) => {\r\n // if(element == ind) root = element;\r\n // });\r\n\r\n // dist = new Array(n + 1).fill(-1);\r\n // dist[root] = 0;\r\n\r\n // if(p[0] != root) {\r\n // console.log(-1);\r\n // return;\r\n // }\r\n\r\n // p.every((element, ind, arr) => {\r\n // if(b[element] == -1) {\r\n // return false;\r\n // }\r\n // if(element == root) dist[ind] = 0;\r\n // else dist[element] = dist[ind - 1] + 1;\r\n // });\r\n\r\n // let w = b.map((x, ind, arr) => {\r\n // if(ind > 0)\r\n // return dist[x] - dist[ind];\r\n // });\r\n\r\n // let ans = w.join(\" \").trim();\r\n // console.log(ans);\r\n\r\n let n = inputReader.readNumber();\r\n let b = inputReader.readNumberArray();\r\n let p = inputReader.readNumberArray();\r\n b.unshift(-Infinity);\r\n p.unshift(-Infinity);\r\n let dist = new Array(n + 1).fill(-1);\r\n let root = -1;\r\n b.forEach((x, ind, arr) => {\r\n if (x == ind) root = x;\r\n });\r\n\r\n if (p[1] != root) {\r\n console.log(-1);\r\n return;\r\n }\r\n\r\n dist[root] = 0;\r\n for (let i = 2; i <= n; i++) {\r\n if (dist[b[p[i]]] == -1) {\r\n console.log(-1);\r\n return;\r\n }\r\n dist[p[i]] = dist[p[i - 1]] + 1;\r\n }\r\n\r\n let w = dist.map((x, i, a) => {\r\n if (i > 0) return x - dist[b[i]];\r\n });\r\n\r\n let ans = w.join(\" \").trim();\r\n console.log(ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet b;\r\nlet p;\r\nlet root;\r\nfunction solve() {\r\n const dist = af(n + 1).fill(INIT);\r\n dist[root] = 0;\r\n if (p[1] != root) {\r\n return false;\r\n }\r\n const edge = af(n + 1); // edge to parent\r\n edge[root] = 0;\r\n let tot = 1; // total distance to node\r\n for (let i = 2; i <= n; i++) {\r\n let u = p[i];\r\n if (dist[b[u]] == INIT) {\r\n return false;\r\n }\r\n edge[u] = tot - dist[b[u]];\r\n dist[u] = tot;\r\n tot++;\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n printf(\"%d \", edge[i]);\r\n }\r\n printf(\"\\n\");\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n b = af(n + 1);\r\n for (let i = 1; i <= n; i++) {\r\n b[i] = nextInt();\r\n if (b[i] == i) {\r\n root = i;\r\n }\r\n }\r\n p = af(n + 1);\r\n for (let i = 1; i <= n; i++) {\r\n p[i] = nextInt();\r\n }\r\n if (!solve()) {\r\n printf(\"-1\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\t\tconst p = rna();\r\n\r\n\t\tlet root;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (b[i] == i+1) {\r\n\t\t\t\troot = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst done = new Map();\r\n\t\tdone.set(root, 0);\r\n\r\n\t\tlet ans = [];\r\n\t\tans[root] = 0;\r\n\r\n\t\tlet mxpth = 0;\r\n\t\tfor (let v of p) {\r\n\t\t\tv--;\r\n\t\t\tif (v == root) {\r\n\t\t\t\tif (mxpth > 0) {\r\n\t\t\t\t\tans = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tlet u = b[v]; u--;\r\n\t\t\tif (done.has(u)) {\r\n\t\t\t\tconst pthl = done.get(u);\r\n\t\t\t\tif (pthl+1 > mxpth) {\r\n\t\t\t\t\tans[v] = 1;\r\n\t\t\t\t\tmxpth = pthl+ans[v];\r\n\t\t\t\t\tdone.set(v, mxpth);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tans[v] = mxpth-pthl+1;\r\n\t\t\t\t\tmxpth = pthl+ans[v];\r\n\t\t\t\t\tdone.set(v, mxpth);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const ps = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, ps, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, ps, arr) {\n ps.unshift(0)\n //\n const ans = Array(n + 1).fill(-1)\n const dist = Array(n + 1).fill(-1)\n let now = 0\n if (ps[arr[0]] !== arr[0]) return -1\n ans[arr[0]] = 0\n dist[arr[0]] = now\n for (let i = 1; i < arr.length; i++) {\n now++\n const x = arr[i]\n const p = ps[x]\n if (p === x) return -1\n if (dist[p] < 0) return -1\n dist[x] = now\n ans[x] = dist[x] - dist[p]\n if (ans[x] <= 0) return -1\n }\n ans.shift()\n return ans.join(' ')\n}\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\t\tconst p = rna();\r\n\r\n\t\tlet root;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (b[i] == i+1) {\r\n\t\t\t\troot = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst done = new Map();\r\n\t\tdone.set(root, 0);\r\n\r\n\t\tlet ans = [];\r\n\t\tans[root] = 0;\r\n\r\n\t\tlet mxpth = 0;\r\n\t\tfor (let v of p) {\r\n\t\t\tv--;\r\n\t\t\tif (v == root) continue;\r\n\t\t\tlet u = b[v]; u--;\r\n\t\t\tif (done.has(u)) {\r\n\t\t\t\tconst pthl = done.get(u);\r\n\t\t\t\tif (pthl+1 > mxpth) {\r\n\t\t\t\t\tans[v] = 1;\r\n\t\t\t\t\tmxpth = pthl+ans[v];\r\n\t\t\t\t\tdone.set(v, mxpth);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tans[v] = mxpth-pthl+1;\r\n\t\t\t\t\tmxpth = pthl+ans[v];\r\n\t\t\t\t\tdone.set(v, mxpth);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "4b512c39e71e34064c820958dde9f4a1"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), x\n if (n == 1) {\n log(`1 1\\n${-a[0]}\\n1 1\\n0\\n1 1\\n0`);\n return;\n }\n out.push(`1 ${n - 1}`);\n out.push(Arr(n - 1, i => (x = (n - 1) * a[i], a[i] += x, x)).join(' '))\n out.push(`${n} ${n}`);\n out.push(a[n - 1] ? (x = n - a[n - 1] % n, a[n - 1] += x, x) : 0)\n out.push(`1 ${n}`);\n out.push(Arr(n, i => -a[i]).join(' '))\n log(out.join('\\n'))\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 1){\n console.log(1,1);\n console.log(-1*a[0]);\n console.log(1,1);\n console.log(0);\n console.log(1,1);\n console.log(0);\n return;\n }\n let res = '';\n console.log(1,n);\n for(let i = 0; i < n; i++){\n res = `${res}${-1*n*a[i]} `;\n }\n console.log(res.trim());\n console.log(2,n);\n res = '';\n for(let i = 1; i < n; i++){\n res = `${res}${(n-1)*a[i]} `;\n }\n console.log(res.trim());\n console.log(1,1);\n console.log((n-1)*a[0]);\n}"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), x\n if (n == 1) {\n log(`1 1\\n${-a[0]}\\n1 1\\n0\\n1 1\\n0`);\n return;\n }\n out.push(`1 ${n - 1}`);\n out.push(Arr(n - 1, i => (x = (n - 1) * a[i], a[i] += x, x)).join(' '))\n out.push(`${n} ${n}`);\n out.push(a[n - 1] ? (x = n - n % a[n - 1], a[n - 1] += x, x) : 0)\n out.push(`1 ${n}`);\n out.push(Arr(n, i => -a[i]).join(' '))\n log(out.join('\\n'))\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let res = '';\n console.log(1,n);\n for(let i = 0; i < n; i++){\n res = `${res}${-1*n*a[i]} `;\n }\n console.log(res.trim());\n console.log(2,n);\n res = '';\n for(let i = 1; i < n; i++){\n res = `${res}${(n-1)*a[i]} `;\n }\n console.log(res.trim());\n console.log(1);\n console.log((n-1)*a[0]);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let res = '';\n console.log(1,n);\n for(let i = 0; i < n; i++){\n res = `${res}${-1*n*a[i]} `;\n }\n console.log(res.trim());\n console.log(2,n);\n res = '';\n for(let i = 1; i < n; i++){\n res = `${res}${(n-1)*a[i]} `;\n }\n console.log(res.trim());\n console.log(1,1);\n console.log((n-1)*a[0]);\n}"}], "src_uid": "d15a758cfdd7a627822fe8be7db4f60b"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const mapVal = char => char === 'D' ? -1 : 1;\r\n const n = Number(readline());\r\n const digits = readline().split(' ').map(Number);\r\n let seq = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n seq[i] = readline().split(' ')[1];\r\n seq[i] = (digits[i] - seq[i].split('').map(mapVal).reduce((a, b) => a + b, 0) + 100) % 10;\r\n }\r\n\r\n let res = seq.map(String).join(' ');\r\n output(res);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = parseInt(input[0])\r\n let cnt = 0\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + cnt + 2 * i])\r\n const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))\r\n\r\n let ans = [...a]\r\n for (let j = 0; j < n; j++) {\r\n const [_, b] = input[1 + cnt + 2 * i + 2 + j].trim().split(' ')\r\n const d = Array.from(b).reduce(\r\n (prev, current) => prev + (current === 'U' ? -1 : 1),\r\n 0\r\n )\r\n ans[j] += d\r\n ans[j] %= 10\r\n ans[j] += 10\r\n ans[j] %= 10\r\n }\r\n console.log(ans.map((x) => String(x)).join(' '))\r\n\r\n cnt += n\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n let arr = [];\r\n while (b--) {\r\n arr.push(readLine());\r\n }\r\n var res = solveMeFirst(arr, c);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(arr, str) {\r\n str = str.split(\" \");\r\n for (let i = 0; i < arr.length; i++) {\r\n let cnt = 0;\r\n for (let j = 2; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"D\") {\r\n cnt++;\r\n }\r\n if (arr[i][j] === \"U\") {\r\n cnt--;\r\n }\r\n }\r\n str[i] = +str[i];\r\n str[i] += cnt;\r\n if (str[i] < 0) {\r\n let temp = str[i] / 10;\r\n str[i] = Math.round((temp + 1) * 10);\r\n }\r\n str[i] %= 10;\r\n }\r\n return str;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "function Solution() {\n let t = 0;\n const N = Number(lines[t++]);\n const R = [];\n for (let i = 0; i < N; i++) {\n const n = Number(lines[t++]);\n const initArr = lines[t++].split(' ').map((item) => Number(item));\n for (let j = 0; j < n; j++) {\n const [numStr, str] = lines[t++].split(' ');\n const num = Number(numStr);\n for (let z = 0; z < num; z++) {\n if (str[z] === 'D') initArr[j] = (initArr[j] + 1) % 10;\n else initArr[j] = (initArr[j] - 1 + 10) % 10;\n }\n }\n R.push(initArr.join(' '));\n }\n return R.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "function Solution() {\n let t = 0;\n const N = Number(lines[t++]);\n const R = [];\n for (let i = 0; i < N; i++) {\n const n = Number(lines[t++]);\n const initArr = lines[t++].split(' ').map((item) => Number(item));\n const res = [];\n for (let j = 0; j < n; j++) {\n const [numStr, str] = lines[t++].split(' ');\n const num = Number(numStr);\n let count = 0;\n for (let z = 0; z < num; z++) {\n if (str[z] === 'D') count += 1;\n else count -=1;\n }\n const target = initArr[j] + count;\n res[j] = target >= 0 ? target % 10 : (target % 10 + 10) % 10;\n }\n R.push(res.join(' '));\n }\n return R.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n var t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var m = [];\r\n var n = parseInt(readline());\r\n var s = readline().split().join().replace(/\\s/g, '');\r\n for (var j = 0; j < n; j++) {\r\n var z = parseInt(s[j]);\r\n var b = readline();\r\n var p = b.split(' ')[1];\r\n for (let k = 0; k < p.length; k++) {\r\n if (p[k] === 'U') {\r\n if (z === 0) {\r\n z = 9;\r\n } else {\r\n z--;\r\n } \r\n }\r\n if (p[k] === 'D') {\r\n if (z === 9) {\r\n z = 0;\r\n } else {\r\n z++;\r\n }\r\n }\r\n }\r\n m[j] = z;\r\n }\r\n console.log(m.join(' '));\r\n }\r\n}"}, {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n let n = parseInt(readline());\r\n let s = readline().split(' ');\r\n \r\n let data = Array(n);\r\n let res = [];\r\n for (let i = 0; i < n;++i) {\r\n res.push(parseInt(s[i]));\r\n data[i] = readline().split(' ');\r\n }\r\n for (let i = 0; i < n;++i) {\r\n for (let j = 0;j < data[i][1].length; ++j) {\r\n if (data[i][1].charAt(j) === 'U') {\r\n res[i] = (res[i]-1+10)%10;\r\n } else if (data[i][1].charAt(j) === 'D') {\r\n res[i] = (res[i]+1+10)%10;\r\n }\r\n }\r\n }\r\n var ress = res.join(' ').toString();\r\n console.log(ress);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n const move = lines.slice(l, l + n).map(str => str.trim().split(' '))\n l += n\n output[i] = solve(n, arr, move)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, move) {\n return arr.map((x, i) => {\n move[i] = move[i][1]\n for (let j = 0; j < move[i].length; j++) {\n const d = move[i][j] === 'D' ? -1 : 1\n x -= d\n }\n x = x % 10\n x = (x + 10) % 10\n return x\n }).join(' ')\n}\n"}, {"source_code": "// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\n'use strict';\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n};\r\nconst update = (v, dir) => {\r\n if (dir == 'D') {\r\n if (v == 9) return 0\r\n return v + 1\r\n }\r\n if (dir == 'U') {\r\n if (v == 0) return 9\r\n return v - 1\r\n }\r\n}\r\nasync function main(read) {\r\n try {\r\n let tasks = parseInt(await read())\r\n let result = []\r\n let current_combination = null\r\n for (let i = 0; i < tasks; i++) {\r\n const sub_length = parseInt(await read())\r\n current_combination = (await read()).split(' ').map(Number)\r\n for (let j = 0; j < sub_length; j++) {\r\n const element = (await read());\r\n const [num, content] = element.split(' ')\r\n for (let k = 0; k < content.length; k++) {\r\n const element = content[k];\r\n current_combination[j] = update(current_combination[j], element)\r\n }\r\n }\r\n result[i] = current_combination.join(' ')\r\n }\r\n return result.join('\\n')\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = data.split('\\n').values();\r\n const result = await main(read);\r\n // console.log(result)\r\n process.stdout.write(result);\r\n});\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n \r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n \r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n let startLine = 1;\r\n for (let i = 1; i <= lines[0]; i++) {\r\n startLine = processTC(lines, startLine);\r\n }\r\n}\r\n \r\nfunction processTC(lines, startLine) {\r\n const n = Number(lines[startLine]);\r\n const seq = lines[startLine+1].split(\" \").map(x => Number(x));\r\n let str = \"\";\r\n for (let i = 0; i < n; i++) {\r\n const num = startLine+2+i;\r\n const [stepsN, steps] = lines[num].split(\" \");\r\n const res = getInitialDigit(seq[i], steps, stepsN);\r\n str += res + \" \";\r\n }\r\n console.log(str.trim());\r\n return startLine+(n+2);\r\n}\r\n\r\nfunction getInitialDigit(num, steps, n) {\r\n for (let i = 0; i < n; i++) {\r\n const diff = steps.charAt(i) === \"U\" ? -1 : 1;\r\n num=num+diff;\r\n if (num===10) num = 0;\r\n if (num===-1) num = 9;\r\n }\r\n return num;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let times = parseInt(readline());\r\n for (let i = 0; i < times; i++) {\r\n let cellNumber = parseInt(readline());\r\n let cellFinal = readline()\r\n .split(' ')\r\n .map((number) => {\r\n return parseInt(number);\r\n });\r\n for (let j = 0; j < cellNumber; j++) {\r\n let counter = 0;\r\n let [len, str] = readline().split(' ');\r\n for (let char of str) {\r\n counter += char === 'D' ? 1 : -1;\r\n }\r\n cellFinal[j] = (cellFinal[j] + (counter % 10)) % 10;\r\n if (cellFinal[j] < 0) {\r\n cellFinal[j] += 10;\r\n }\r\n }\r\n console.log(...cellFinal);\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr1 = [];\r\n for (let i = 0; i < n; i++) {\r\n arr1.push(readline().trim().split(\" \"));\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let x = arr1[i][1];\r\n for (let j = 0; j < x.length; j++) {\r\n if (x[j] === \"U\") {\r\n if (arr[i] === 0) arr[i] = 9;\r\n else arr[i] = (arr[i] - 1) % 10;\r\n } else arr[i] = (arr[i] + 1) % 10;\r\n }\r\n }\r\n let res = \"\";\r\n for (let i = 0; i < n; i++) res += arr[i] + \" \";\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var ans = [];\r\n for(var i=0;i +t);\r\n for(var k = 0; k < t1; k++){\r\n var t3 = readline().split(' ');\r\n nums.push(t3[1])\r\n }\r\n print(Cypher(t2,nums));\r\n \r\n}\r\n \r\nfunction Cypher(nums,arr){\r\n\r\n var res = [];\r\n for(var i = 0; i=0; j--){\r\n if(k[j] == 'D'){\r\n if(n==9)n=0;\r\n else n++;\r\n }else{\r\n if(n==0)n=9;\r\n else n--;\r\n }\r\n }\r\n return n;\r\n}\r\n\r\nvar test = readline()\r\n\r\nfor(var i=0; i parseInt(x));\r\n var ans = [];\r\n for (var i =0; i < n; i++) {\r\n var line = readline().split(' ');\r\n var seq = line[1];\r\n var f = a[i];\r\n for (var j = seq.length-1; j >= 0; j--) {\r\n if (seq[j] == 'D') {\r\n f = (f + 1)%10;\r\n } else {\r\n f = f-1;\r\n if (f < 0) {\r\n f = 9;\r\n }\r\n }\r\n }\r\n ans.push(f);\r\n }\r\n print(ans.join(' '));\r\n }"}], "negative_code": [{"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = parseInt(input[0])\r\n let cnt = 0\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + cnt + 2 * i])\r\n const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))\r\n\r\n let ans = [...a]\r\n for (let j = 0; j < n; j++) {\r\n const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')\r\n console.log('b:', b)\r\n const d = Array.from(b).reduce(\r\n (prev, current) => prev + (current === 'U' ? -1 : 1),\r\n 0\r\n )\r\n console.log('d:', d)\r\n ans[j] += d\r\n ans[j] %= 10\r\n ans[j] += 10\r\n ans[j] %= 10\r\n }\r\n console.log(ans.map((x) => String(x)).join(' '))\r\n\r\n cnt += n\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = parseInt(input[0])\r\n let cnt = 0\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + cnt + 2 * i])\r\n const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))\r\n\r\n let ans = [...a]\r\n console.log('ans:', ans)\r\n for (let j = 0; j < n; j++) {\r\n const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')\r\n const d = Array.from(b).reduce(\r\n (prev, current) => prev + (current === 'U' ? -1 : 1),\r\n 0\r\n )\r\n console.log('d:', d)\r\n ans[j] += d\r\n ans[j] %= 10\r\n ans[j] += 10\r\n ans[j] %= 10\r\n }\r\n console.log(ans.map((x) => String(x)).join(' '))\r\n\r\n cnt += n\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = parseInt(input[0])\r\n let cnt = 0\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + cnt + 2 * i])\r\n const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))\r\n\r\n let ans = [...a]\r\n for (let j = 0; j < n; j++) {\r\n const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')\r\n const d = Array.from(b).reduce(\r\n (prev, current) => prev + (current === 'U' ? -1 : 1),\r\n 0\r\n )\r\n ans[j] += d\r\n ans[j] += 10\r\n ans[j] %= 10\r\n }\r\n console.log(ans.map((x) => String(x)).join(' '))\r\n\r\n cnt += n\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n let arr = [];\r\n while (b--) {\r\n arr.push(readLine());\r\n }\r\n var res = solveMeFirst(arr, c);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(arr, str) {\r\n str = str.split(\" \");\r\n for (let i = 0; i < arr.length; i++) {\r\n let cnt = 0;\r\n for (let j = 2; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"D\") {\r\n cnt++;\r\n }\r\n if (arr[i][j] === \"U\") {\r\n cnt--;\r\n }\r\n }\r\n str[i] = +str[i];\r\n str[i] += cnt;\r\n if (str[i] < 0) {\r\n let temp = str[i] / 10;\r\n str[i] = (temp + 1) * 10;\r\n }\r\n str[i] %= 10;\r\n }\r\n return str;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.on(\"SIGINT\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n let arr = [];\r\n while (b--) {\r\n arr.push(readLine());\r\n }\r\n var res = solveMeFirst(arr, c);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(arr, str) {\r\n str = str.split(\" \");\r\n for (let i = 0; i < arr.length; i++) {\r\n let cnt = 0;\r\n for (let j = 2; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"D\") {\r\n cnt++;\r\n }\r\n if (arr[i][j] === \"U\") {\r\n cnt--;\r\n }\r\n }\r\n str[i] = +str[i];\r\n str[i] += cnt;\r\n if (str[i] < 0) {\r\n let temp = str[i] / 10;\r\n str[i] = (temp + 1) * 10;\r\n }\r\n str[i] %= 10;\r\n }\r\n return str;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction swap(arr, i, j) {\r\n let temp = arr[i];\r\n arr[i] = arr[j];\r\n arr[j] = temp;\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n let arr = [];\r\n while (b--) {\r\n arr.push(readLine());\r\n }\r\n var res = solveMeFirst(arr, c);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(arr, str) {\r\n str = str.split(\" \");\r\n for (let i = 0; i < arr.length; i++) {\r\n for (let j = 2; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"D\") {\r\n if (str[i] == \"9\") str[i] = 0;\r\n else str[i]++;\r\n }\r\n if (arr[i][j] === \"U\") {\r\n if (str[i] == \"0\") str[i] = 9;\r\n else str[i] = Math.abs(str[i] - 1);\r\n }\r\n }\r\n }\r\n return str;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction swap(arr, i, j) {\r\n let temp = arr[i];\r\n arr[i] = arr[j];\r\n arr[j] = temp;\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n let arr = [];\r\n while (b--) {\r\n arr.push(readLine());\r\n }\r\n var res = solveMeFirst(arr, c);\r\n let out = \"\";\r\n if (res) {\r\n for (let i = 0; i < res.length; i++) {\r\n out += res[i] + \" \";\r\n }\r\n console.log(out);\r\n }\r\n }\r\n}\r\nfunction solveMeFirst(arr, str) {\r\n str = str.split(\" \");\r\n for (let i = 0; i < arr.length; i++) {\r\n for (let j = 2; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"D\") {\r\n str[i]++;\r\n }\r\n if (arr[i][j] === \"U\") {\r\n if (str[i] == \"0\") str[i] = 9;\r\n else str[i] = Math.abs(str[i] - 1);\r\n }\r\n }\r\n str[i] = str[i] % 10;\r\n }\r\n return str;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var seq = readline().split(\" \");\r\n \r\n for (var j = 0; j < n; j++) {\r\n var str = readline().split(\" \");\r\n \r\n for (var k = 0; k < str[0]; k++) {\r\n if (str[1][k] === \"D\") {\r\n seq[j]++;\r\n } else if (str[1][k] === \"U\") {\r\n seq[j]--;\r\n }\r\n }\r\n \r\n seq[j] %= 10;\r\n }\r\n \r\n print(seq);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var seq = readline().split(\" \");\r\n \r\n for (var j = 0; j < n; j++) {\r\n var str = readline().split(\" \");\r\n \r\n for (var k = 0; k < str[0]; k++) {\r\n if (str[1][k] === \"D\") {\r\n seq[n]++;\r\n } else if (str[1][k] === \"U\") {\r\n seq[n]--;\r\n }\r\n }\r\n \r\n seq[j] %= 10;\r\n }\r\n \r\n print(seq);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var seq = readline().split(\" \");\r\n \r\n for (var j = 0; j < n; j++) {\r\n var str = readline().split(\" \");\r\n \r\n for (var k = 0; k < str[0]; k++) {\r\n if (str[1][k] === \"D\") {\r\n seq[n]++;\r\n } else if (str[1][k] === \"U\") {\r\n seq[n]--;\r\n }\r\n }\r\n \r\n seq[n] %= 10;\r\n }\r\n \r\n print(seq);\r\n}\r\n"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline()\r\n x = readline().split(' ')\r\n\r\n for(j=0;j +t);\r\n for(var k = 0; k < t1; k++){\r\n var t3 = readline().split(' ');\r\n nums.push(t3[1])\r\n }\r\n print(Cypher(t2,nums));\r\n \r\n}\r\n \r\nfunction Cypher(nums,arr){\r\n\r\n var res = [];\r\n for(var i = 0; i {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, k] = readInts()\n const s = (\"#\" + readString()).split('')\n const half = Math.ceil(k / 2)\n let total = 0\n for(let i = 1; i <= half; i++) {\n const alpha = new Array(26).fill(0)\n let count = 0\n for(let j = i; j <= n; j+= k) {\n alpha[s[j].charCodeAt(0) - 97]++\n count++\n }\n if(k % 2 === 0 || i !== half) {\n for(let j = n - i + 1; j >= 1; j-= k) {\n alpha[s[j].charCodeAt(0) - 97]++\n count++\n }\n }\n total += count - Math.max(...alpha)\n // wr(alpha, count, Math.max(...alpha), i)\n }\n wr(total)\n }\n}\n", "positive_code": [{"source_code": "for(var t=Number(readline());t;t--){\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n var s = readline();\n var n = a[0];\n var k = a[1];\n var c = n/k;\n var res = 0;\n const z = \"a\".charCodeAt();\n for(var i=0; i<(k&~1)/2; i++){\n var l = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];\n for(var j=0;j0?s+t:t,0,1,_i]);\n }\n else if(_t[5]>=0){\n t=st[_t[5]];\n t[3]+=a[n]=0){\n t=st[_t[5]];\n t[3]+=a[_t[1]]<_t[2]?_t[4]:_t[3];\n t[4]+=_t[4];\n st.pop();\n }\n else return _t[3];\n }\n}\nprint(dfs(0,-Infinity));", "positive_code": [{"source_code": "var n=+readline(),a=readline().split(' '),i,b=new Array(n),t=[],j=0;\nfor(i=1;i=(v=s+t[i][1]))dfs(k,v);\n}\ndfs(0,0);\nprint(n-K);"}], "negative_code": [{"source_code": "var n=+readline(),a=readline().split(' '),k=0,i,b=new Array(n),t=[],j=0;\nfor(i=1;i a - b);\n print('1');\n print(result.length);\n print(result.join(' '));\n} else {\n print('0');\n}\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const s = input[0]\n const len = s.length\n let i = 0, j = len - 1\n let ans = []\n while(i <= j) {\n if(s[i] === '(' && s[j] === ')') {\n ans.push(j + 1)\n ans.unshift(++i)\n j--\n }\n else if(s[i] !== '(') i++\n else if(s[j] !== ')') j--\n }\n if(ans.length === 0) wr(0)\n else {\n sort(ans)\n wr(1)\n wr(ans.length)\n wr(ans.join(' '))\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (str) {\n let k = 0;\n let aResult = [];\n let result = [];\n\n let lft = 0;\n let rght = str.length - 1;\n\n while (lft < rght) {\n if (str[lft] === '(') {\n while(lft < rght) {\n if (str[rght] === ')') {\n result.push(lft + 1);\n result.push(rght + 1);\n lft++;\n rght--;\n break;\n } else {\n rght--;\n }\n }\n\n } else {\n lft++\n }\n }\n\n result.sort((a, b) => a - b);\n\n if (result.length) {\n aResult[0] = result;\n k++;\n const resSet = new Set(result);\n const subStr = str.split('').filter((v, index) => !resSet.has(index + 1)).join('');\n const subRes = foo(subStr);\n\n if (subRes[0] !== 0) {\n k = k + subRes[0];\n aResult = aResult.concat(subRes[1])\n }\n }\n return [k, aResult];\n }\n\n let result = foo(lines[0]);\n console.log(result[0]);\n if (result[1].length) {\n let answer = '';\n result[1].forEach(v => answer += v.length + '\\n' + v.join(' ') + '\\n');\n console.log(answer);\n }\n})"}, {"source_code": "const processData = (lines) => {\n const str = lines[0]\n let refinedStr = str.slice(0)\n const ops = []\n let size = 0\n let index = []\n const left = []\n const right = []\n for (let j =0; j= 0 && leftCounter < left.length) {\n const leftPos = left[leftCounter]\n let rightPos = right[rightCounter]\n leftCounter++\n if (leftPos > rightPos) {\n break\n }\n acc.push(leftPos, rightPos)\n rightCounter--\n }\n if (acc.length > 0) {\n console.log(1)\n console.log(acc.length)\n console.log(acc.sort((a, b) => a - b).map(x => x+1).join(' '))\n } else {\n console.log(0)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(o=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{o=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return o[u++]}function f(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r0?1:0),0!=n.length&&(i.default.puts(n.length),i.default.puts(n.sortAsc().join(\" \")))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let s = io.readline()\n// let n = s.length\n// \n// let left = 0\n// let right = n - 1\n// \n// let toRemove = []\n// \n// while (left <= right) {\n// if (s[left] == \"(\" && s[right] == \")\") {\n// toRemove.push(left + 1)\n// toRemove.push(right + 1)\n// left++\n// right--\n// continue\n// }\n// \n// if (s[left] == \")\") {\n// left++\n// }\n// \n// if (s[right] == \"(\") {\n// right--\n// }\n// }\n// \n// io.puts(toRemove.length > 0 ? 1 : 0)\n// \n// if (toRemove.length == 0) {\n// return\n// }\n// \n// io.puts(toRemove.length)\n// \n// io.puts(toRemove.sortAsc().join(\" \"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}, {"source_code": "'use strict'\n\nconst problem = (s) => {\n let i = 0, j = s.length - 1;\n let l = '', r = '', n = 0;\n while (i < j) {\n while (s[i] !== '(' && i < j) i++;\n while (s[j] !== ')' && i < j) j--;\n if (i !== j) { l = l + `${i++ + 1} `; r = `${j-- + 1} ` + r; n++; }\n }\n if (!n) return 0;\n return `1\\n${2*n}\\n${l + r}`;\n}\nprint(problem(readline()))\n"}], "negative_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const s = input[0]\n const len = s.length\n let i = 0, j = len - 1\n let ans = []\n while(i <= j) {\n if(s[i] === '(' && s[j] === ')') {\n ans.push(j + 1)\n ans.unshift(++i)\n j--\n }\n else if(s[i] !== '(') i++\n else if(s[j] !== ')') j--\n }\n if(ans.length === 0) wr(0)\n else {\n sort(ans)\n if(ans.length === s.length) wr(0)\n else {\n wr(1)\n wr(ans.length)\n wr(ans.join(' '))\n }\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const s = input[0]\n const len = s.length\n let i = 0, j = len - 1\n let ans = []\n while(i <= j) {\n if(s[i] === '(' && s[j] === ')') {\n ans.push(j + 1)\n ans.unshift(++i)\n j--\n }\n else if(s[i] !== '(') i++\n else if(s[j] !== ')') j--\n }\n if(ans.length === 0) wr(0)\n else {\n sort(ans)\n if(ans.length === s.length) wr(-1)\n else {\n wr(1)\n wr(ans.length)\n wr(ans.join(' '))\n }\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const s = input[0]\n const len = s.length\n let i = 0, j = len - 1\n let ans = []\n while(i <= j) {\n if(s[i] === '(' && s[j] === ')') {\n ans.push(j + 1)\n ans.unshift(++i)\n j--\n }\n else if(s[i] !== '(') i++\n else if(s[j] !== ')') j--\n }\n if(ans.length === 0) wr(0)\n else {\n sort(ans)\n if(ans.length === s.length) ans.pop()\n wr(1)\n wr(ans.length)\n wr(ans.join(' '))\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (str) {\n let k = 0;\n let aResult = [];\n let result = [];\n\n let lft = 0;\n let rght = str.length - 1;\n\n while (lft < rght) {\n if (str[lft] === '(') {\n while(lft < rght) {\n if (str[rght] === ')') {\n result.push(lft + 1);\n result.push(rght + 1);\n lft++;\n rght--;\n break;\n } else {\n rght--;\n }\n }\n\n } else {\n lft++\n }\n }\n\n result.sort((a, b) => a - b);\n aResult[0] = result;\n\n if (result.length) {\n k++;\n const resSet = new Set(result);\n const subStr = str.split('').filter((v, index) => !resSet.has(index + 1)).join('');\n const subRes = foo(subStr);\n\n if (subRes[0] !== 0) {\n k = k + subRes[0];\n aResult = aResult.concat(subRes[1])\n }\n }\n return [k, aResult];\n }\n\n let result = foo(lines[0]);\n console.log(result[0]);\n if (result[1].length) {\n let answer = '';\n result[1].forEach(v => answer += v.length + '\\n' + v.join(' ') + '\\n');\n console.log(answer);\n }\n})"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(h){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0;e--)\")\"==t[e]&&o++,r[e]=o;r=r.reverse();let s=Math.floor((t.length-1)/2),u=[e[s],r[s]].min();if(0==u)return void i.default.puts(0);i.default.puts(1),i.default.puts(2*u),n=u,o=u;for(let e=0;e=0&&(\")\"==t[e]&&(o--,l.push(e+1)),0!=o);--e);i.default.puts(l.reverse().join(\" \"))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let s = io.readline()\n// \n// let nrOpen = Array(s.length).fill(0)\n// let nrClosed = Array(s.length).fill(0)\n// \n// let open = 0\n// \n// for (let i = 0; i < s.length; ++i) {\n// if (s[i] == \"(\") {\n// open++\n// }\n// nrOpen[i] = open\n// }\n// \n// let closed = 0\n// \n// for (let i = s.length - 1; i >= 0; i--) {\n// if (s[i] == \")\") {\n// closed++\n// }\n// nrClosed[i] = closed\n// }\n// \n// nrClosed = nrClosed.reverse()\n// \n// let i = Math.floor((s.length - 1) / 2)\n// \n// let v = [nrOpen[i], nrClosed[i]].min()\n// \n// if (v == 0) {\n// io.puts(0)\n// return\n// }\n// \n// io.puts(1)\n// io.puts(v * 2)\n// \n// open = v\n// closed = v\n// \n// for (let i = 0; i < s.length; ++i) {\n// if (s[i] == \"(\") {\n// open--\n// io.put(i + 1 + \" \")\n// }\n// if (open == 0) {\n// break\n// }\n// }\n// \n// let rev = []\n// \n// for (let i = s.length - 1; i >= 0; --i) {\n// if (s[i] == \")\") {\n// closed--\n// rev.push(i + 1)\n// }\n// if (closed == 0) {\n// break\n// }\n// }\n// \n// io.puts(rev.reverse().join(\" \"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(h){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0;e--)\")\"==t[e]&&o++,r[e]=o;r=r.reverse();let s=Math.floor(t.length/2),u=[e[s],r[s]].min();if(0==u)return void i.default.puts(0);i.default.puts(1),i.default.puts(2*u),n=u,o=u;for(let e=0;e=0&&(\")\"==t[e]&&(o--,l.push(e+1)),0!=o);--e);i.default.puts(l.reverse().join(\" \"))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let s = io.readline()\n// \n// let nrOpen = Array(s.length).fill(0)\n// let nrClosed = Array(s.length).fill(0)\n// \n// let open = 0\n// \n// for (let i = 0; i < s.length; ++i) {\n// if (s[i] == \"(\") {\n// open++\n// }\n// nrOpen[i] = open\n// }\n// \n// let closed = 0\n// \n// for (let i = s.length - 1; i >= 0; i--) {\n// if (s[i] == \")\") {\n// closed++\n// }\n// nrClosed[i] = closed\n// }\n// \n// nrClosed = nrClosed.reverse()\n// \n// let i = Math.floor(s.length / 2)\n// \n// let v = [nrOpen[i], nrClosed[i]].min()\n// \n// if (v == 0) {\n// io.puts(0)\n// return\n// }\n// \n// io.puts(1)\n// io.puts(v * 2)\n// \n// open = v\n// closed = v\n// \n// for (let i = 0; i < s.length; ++i) {\n// if (s[i] == \"(\") {\n// open--\n// io.put(i + 1 + \" \")\n// }\n// if (open == 0) {\n// break\n// }\n// }\n// \n// let rev = []\n// \n// for (let i = s.length - 1; i >= 0; --i) {\n// if (s[i] == \")\") {\n// closed--\n// rev.push(i + 1)\n// }\n// if (closed == 0) {\n// break\n// }\n// }\n// \n// io.puts(rev.reverse().join(\" \"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "src_uid": "f78d04f699fc94103e5b08023949854d"} {"source_code": "function main(){\n var c = +readline();\n var str = readline();\n var strRes = readline();\n var result = [];\n\n for(var i = 0; i < c; i++){\n if(str[i] != strRes[i]){\n var s = str.substr(i).indexOf(strRes[i]);\n if(s == -1){\n print(-1);\n return;\n }\n s+=i;\n while(s != i){\n result.push(s);\n str = str.substr(0,s-1) + str[s] + str[s-1] + str.substr(s+1);\n s--;\n }\n }\n }\n if(result.length > 10000){\n print(-1);\n return;\n }\n print(result.length + '\\n');\n result.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n is.nextInt();\n const s = is.nextLine().split('');\n const t = is.nextLine().split('');\n const container = {};\n s.forEach((item) => {\n if (container[item] === undefined) {\n container[item] = 1;\n } else {\n container[item] += 1;\n }\n });\n t.forEach((item) => {\n if (container[item] !== undefined) {\n container[item] -= 1;\n }\n });\n let isPossible = true;\n for (const i in container) {\n if (container.hasOwnProperty(i)) {\n if (container[i] !== 0) {\n isPossible = false;\n break;\n }\n }\n }\n\n\n if (!isPossible) {\n console.log(-1);\n } else {\n let j;\n const swaps = [];\n t.forEach((item, i) => {\n if (item !== s[i]) {\n j = s.lastIndexOf(item);\n for (let k = j - 1; k !== i - 1; k -= 1) {\n [s[k], s[k + 1]] = [s[k + 1], s[k]];\n swaps.push(k + 1);\n }\n }\n });\n console.log(swaps.length);\n if (swaps.length) {\n console.log(swaps.join(' '));\n }\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++].trim(); // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "function main() {\n n = readInt()\n s = Array.from(readLine())\n t = Array.from(readLine())\n res = []\n for (i=0; ii; j--){\n [s[j], s[j-1]]= [s[j-1], s[j]]\n res.push(j)\n }\n }\n }\n }\n print(res.length)\n print(res.join(\" \"))\n}\n\nconst TESTCASES = false\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction inp() {\n return inputString[currentLine++];\n}\n\nfunction out(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for (var i = 0; i < array.length; i++) {\n result.push(parseInt(array[i]));\n }\n return result;\n}\nfunction main() {\n let n = parseInt(inp());\n let s, t;\n s = inp();\n t = inp();\n let s1 = [];\n let i, j;\n //check\n var dc = new Object();\n for (i = 0; i < n; i++) {\n s1.push(s[i]);\n if (s[i] in dc) {\n dc[s[i]] += 1\n }\n else {\n dc[s[i]] = 1\n }\n }\n var chk = 0;\n for (i = 0; i < n; i++) {\n if (t[i] in dc) {\n dc[t[i]] -= 1;\n if (dc[t[i]] < 0) {\n chk = 1;\n break\n }\n }\n else {\n chk = 1;\n break\n }\n }\n if (chk == 1) {\n out(-1)\n }\n else {\n var ans = [];\n for (i = 0; i < n; i++) {\n if (s1[i] != t[i]) {\n let pos = i;\n for (j = i + 1; j < n; j++) {\n if (s1[j] == t[i]) {\n pos = j;\n break;\n }\n }\n for (j = pos - 1; j >= i; j--) {\n ans.push(j+1);\n let t = s1[j];\n s1[j] = s1[j + 1];\n s1[j + 1] = t;\n }\n }\n }\n out(ans.length);\n let ans1 = '';\n for (i = 0; i < ans.length; i++) {\n ans1 += ans[i] + ' ';\n }\n out(ans1);\n\n }\n\n}"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n is.nextInt();\n const s = is.nextLine().split('');\n const t = is.nextLine().split('');\n const container = {};\n s.forEach((item) => {\n if (container[item] === undefined) {\n container[item] = 1;\n } else {\n container[item] += 1;\n }\n });\n t.forEach((item) => {\n container[item] -= 1;\n });\n\n if (Object.keys(container).some(key => container[key] !== 0)) {\n console.log(-1);\n } else {\n let j;\n const swaps = [];\n t.forEach((item, i) => {\n if (item !== s[i]) {\n j = s.lastIndexOf(item);\n for (let k = j - 1; k !== i - 1; k -= 1) {\n [s[k], s[k + 1]] = [s[k + 1], s[k]];\n swaps.push(k + 1);\n }\n }\n });\n console.log(swaps.length);\n if (swaps.length) {\n console.log(swaps.join(' '));\n }\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "function main(){\n var c = +readline();\n var str = readline();\n var strRes = readline();\n var result = [];\n\n for(var i = 0; i < c; i++){\n if(str[i] != strRes[i]){\n var s = str.substr(i).indexOf(strRes[i]);\n if(s == -1){\n print(-1);\n return;\n }\n s+=i;\n while(s != i){\n result.push(s);\n var v = str[s];\n str[s] = str[s-1];\n str[s-1] = v;\n s--;\n }\n }\n }\n if(result.length>10000){\n print(-1);\n return;\n }\n print(result.length + '\\n');\n result.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();"}], "src_uid": "48e323edc41086cae52cc0e6bdd84e35"} {"source_code": "var bigInt = (function(undefined) {\n 'use strict';\n\n var BASE = 1e7,\n LOG_BASE = 7,\n MAX_INT = 9007199254740992,\n MAX_INT_ARR = smallToArray(MAX_INT),\n DEFAULT_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n var supportsNativeBigInt = typeof BigInt === 'function';\n\n function Integer(v, radix, alphabet, caseSensitive) {\n if (typeof v === 'undefined') return Integer[0];\n if (typeof radix !== 'undefined')\n return +radix === 10 && !alphabet\n ? parseValue(v)\n : parseBase(v, radix, alphabet, caseSensitive);\n return parseValue(v);\n }\n\n function BigInteger(value, sign) {\n this.value = value;\n this.sign = sign;\n this.isSmall = false;\n }\n BigInteger.prototype = Object.create(Integer.prototype);\n\n function SmallInteger(value) {\n this.value = value;\n this.sign = value < 0;\n this.isSmall = true;\n }\n SmallInteger.prototype = Object.create(Integer.prototype);\n\n function NativeBigInt(value) {\n this.value = value;\n }\n NativeBigInt.prototype = Object.create(Integer.prototype);\n\n function isPrecise(n) {\n return -MAX_INT < n && n < MAX_INT;\n }\n\n function smallToArray(n) {\n // For performance reasons doesn't reference BASE, need to change this function if BASE changes\n if (n < 1e7) return [n];\n if (n < 1e14) return [n % 1e7, Math.floor(n / 1e7)];\n return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];\n }\n\n function arrayToSmall(arr) {\n // If BASE changes this function may need to change\n trim(arr);\n var length = arr.length;\n if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {\n switch (length) {\n case 0:\n return 0;\n case 1:\n return arr[0];\n case 2:\n return arr[0] + arr[1] * BASE;\n default:\n return arr[0] + (arr[1] + arr[2] * BASE) * BASE;\n }\n }\n return arr;\n }\n\n function trim(v) {\n var i = v.length;\n while (v[--i] === 0);\n v.length = i + 1;\n }\n\n function createArray(length) {\n // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger\n var x = new Array(length);\n var i = -1;\n while (++i < length) {\n x[i] = 0;\n }\n return x;\n }\n\n function truncate(n) {\n if (n > 0) return Math.floor(n);\n return Math.ceil(n);\n }\n\n function add(a, b) {\n // assumes a and b are arrays with a.length >= b.length\n var l_a = a.length,\n l_b = b.length,\n r = new Array(l_a),\n carry = 0,\n base = BASE,\n sum,\n i;\n for (i = 0; i < l_b; i++) {\n sum = a[i] + b[i] + carry;\n carry = sum >= base ? 1 : 0;\n r[i] = sum - carry * base;\n }\n while (i < l_a) {\n sum = a[i] + carry;\n carry = sum === base ? 1 : 0;\n r[i++] = sum - carry * base;\n }\n if (carry > 0) r.push(carry);\n return r;\n }\n\n function addAny(a, b) {\n if (a.length >= b.length) return add(a, b);\n return add(b, a);\n }\n\n function addSmall(a, carry) {\n // assumes a is array, carry is number with 0 <= carry < MAX_INT\n var l = a.length,\n r = new Array(l),\n base = BASE,\n sum,\n i;\n for (i = 0; i < l; i++) {\n sum = a[i] - base + carry;\n carry = Math.floor(sum / base);\n r[i] = sum - carry * base;\n carry += 1;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n BigInteger.prototype.add = function(v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.subtract(n.negate());\n }\n var a = this.value,\n b = n.value;\n if (n.isSmall) {\n return new BigInteger(addSmall(a, Math.abs(b)), this.sign);\n }\n return new BigInteger(addAny(a, b), this.sign);\n };\n BigInteger.prototype.plus = BigInteger.prototype.add;\n\n SmallInteger.prototype.add = function(v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.subtract(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n if (isPrecise(a + b)) return new SmallInteger(a + b);\n b = smallToArray(Math.abs(b));\n }\n return new BigInteger(addSmall(b, Math.abs(a)), a < 0);\n };\n SmallInteger.prototype.plus = SmallInteger.prototype.add;\n\n NativeBigInt.prototype.add = function(v) {\n return new NativeBigInt(this.value + parseValue(v).value);\n };\n NativeBigInt.prototype.plus = NativeBigInt.prototype.add;\n\n function subtract(a, b) {\n // assumes a and b are arrays with a >= b\n var a_l = a.length,\n b_l = b.length,\n r = new Array(a_l),\n borrow = 0,\n base = BASE,\n i,\n difference;\n for (i = 0; i < b_l; i++) {\n difference = a[i] - borrow - b[i];\n if (difference < 0) {\n difference += base;\n borrow = 1;\n } else borrow = 0;\n r[i] = difference;\n }\n for (i = b_l; i < a_l; i++) {\n difference = a[i] - borrow;\n if (difference < 0) difference += base;\n else {\n r[i++] = difference;\n break;\n }\n r[i] = difference;\n }\n for (; i < a_l; i++) {\n r[i] = a[i];\n }\n trim(r);\n return r;\n }\n\n function subtractAny(a, b, sign) {\n var value;\n if (compareAbs(a, b) >= 0) {\n value = subtract(a, b);\n } else {\n value = subtract(b, a);\n sign = !sign;\n }\n value = arrayToSmall(value);\n if (typeof value === 'number') {\n if (sign) value = -value;\n return new SmallInteger(value);\n }\n return new BigInteger(value, sign);\n }\n\n function subtractSmall(a, b, sign) {\n // assumes a is array, b is number with 0 <= b < MAX_INT\n var l = a.length,\n r = new Array(l),\n carry = -b,\n base = BASE,\n i,\n difference;\n for (i = 0; i < l; i++) {\n difference = a[i] + carry;\n carry = Math.floor(difference / base);\n difference %= base;\n r[i] = difference < 0 ? difference + base : difference;\n }\n r = arrayToSmall(r);\n if (typeof r === 'number') {\n if (sign) r = -r;\n return new SmallInteger(r);\n }\n return new BigInteger(r, sign);\n }\n\n BigInteger.prototype.subtract = function(v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.add(n.negate());\n }\n var a = this.value,\n b = n.value;\n if (n.isSmall) return subtractSmall(a, Math.abs(b), this.sign);\n return subtractAny(a, b, this.sign);\n };\n BigInteger.prototype.minus = BigInteger.prototype.subtract;\n\n SmallInteger.prototype.subtract = function(v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.add(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n return new SmallInteger(a - b);\n }\n return subtractSmall(b, Math.abs(a), a >= 0);\n };\n SmallInteger.prototype.minus = SmallInteger.prototype.subtract;\n\n NativeBigInt.prototype.subtract = function(v) {\n return new NativeBigInt(this.value - parseValue(v).value);\n };\n NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;\n\n BigInteger.prototype.negate = function() {\n return new BigInteger(this.value, !this.sign);\n };\n SmallInteger.prototype.negate = function() {\n var sign = this.sign;\n var small = new SmallInteger(-this.value);\n small.sign = !sign;\n return small;\n };\n NativeBigInt.prototype.negate = function() {\n return new NativeBigInt(-this.value);\n };\n\n BigInteger.prototype.abs = function() {\n return new BigInteger(this.value, false);\n };\n SmallInteger.prototype.abs = function() {\n return new SmallInteger(Math.abs(this.value));\n };\n NativeBigInt.prototype.abs = function() {\n return new NativeBigInt(this.value >= 0 ? this.value : -this.value);\n };\n\n function multiplyLong(a, b) {\n var a_l = a.length,\n b_l = b.length,\n l = a_l + b_l,\n r = createArray(l),\n base = BASE,\n product,\n carry,\n i,\n a_i,\n b_j;\n for (i = 0; i < a_l; ++i) {\n a_i = a[i];\n for (var j = 0; j < b_l; ++j) {\n b_j = b[j];\n product = a_i * b_j + r[i + j];\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n r[i + j + 1] += carry;\n }\n }\n trim(r);\n return r;\n }\n\n function multiplySmall(a, b) {\n // assumes a is array, b is number with |b| < BASE\n var l = a.length,\n r = new Array(l),\n base = BASE,\n carry = 0,\n product,\n i;\n for (i = 0; i < l; i++) {\n product = a[i] * b + carry;\n carry = Math.floor(product / base);\n r[i] = product - carry * base;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n function shiftLeft(x, n) {\n var r = [];\n while (n-- > 0) r.push(0);\n return r.concat(x);\n }\n\n function multiplyKaratsuba(x, y) {\n var n = Math.max(x.length, y.length);\n\n if (n <= 30) return multiplyLong(x, y);\n n = Math.ceil(n / 2);\n\n var b = x.slice(n),\n a = x.slice(0, n),\n d = y.slice(n),\n c = y.slice(0, n);\n\n var ac = multiplyKaratsuba(a, c),\n bd = multiplyKaratsuba(b, d),\n abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));\n\n var product = addAny(\n addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)),\n shiftLeft(bd, 2 * n)\n );\n trim(product);\n return product;\n }\n\n // The following function is derived from a surface fit of a graph plotting the performance difference\n // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.\n function useKaratsuba(l1, l2) {\n return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;\n }\n\n BigInteger.prototype.multiply = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n sign = this.sign !== n.sign,\n abs;\n if (n.isSmall) {\n if (b === 0) return Integer[0];\n if (b === 1) return this;\n if (b === -1) return this.negate();\n abs = Math.abs(b);\n if (abs < BASE) {\n return new BigInteger(multiplySmall(a, abs), sign);\n }\n b = smallToArray(abs);\n }\n if (useKaratsuba(a.length, b.length))\n // Karatsuba is only faster for certain array sizes\n return new BigInteger(multiplyKaratsuba(a, b), sign);\n return new BigInteger(multiplyLong(a, b), sign);\n };\n\n BigInteger.prototype.times = BigInteger.prototype.multiply;\n\n function multiplySmallAndArray(a, b, sign) {\n // a >= 0\n if (a < BASE) {\n return new BigInteger(multiplySmall(b, a), sign);\n }\n return new BigInteger(multiplyLong(b, smallToArray(a)), sign);\n }\n SmallInteger.prototype._multiplyBySmall = function(a) {\n if (isPrecise(a.value * this.value)) {\n return new SmallInteger(a.value * this.value);\n }\n return multiplySmallAndArray(\n Math.abs(a.value),\n smallToArray(Math.abs(this.value)),\n this.sign !== a.sign\n );\n };\n BigInteger.prototype._multiplyBySmall = function(a) {\n if (a.value === 0) return Integer[0];\n if (a.value === 1) return this;\n if (a.value === -1) return this.negate();\n return multiplySmallAndArray(\n Math.abs(a.value),\n this.value,\n this.sign !== a.sign\n );\n };\n SmallInteger.prototype.multiply = function(v) {\n return parseValue(v)._multiplyBySmall(this);\n };\n SmallInteger.prototype.times = SmallInteger.prototype.multiply;\n\n NativeBigInt.prototype.multiply = function(v) {\n return new NativeBigInt(this.value * parseValue(v).value);\n };\n NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;\n\n function square(a) {\n //console.assert(2 * BASE * BASE < MAX_INT);\n var l = a.length,\n r = createArray(l + l),\n base = BASE,\n product,\n carry,\n i,\n a_i,\n a_j;\n for (i = 0; i < l; i++) {\n a_i = a[i];\n carry = 0 - a_i * a_i;\n for (var j = i; j < l; j++) {\n a_j = a[j];\n product = 2 * (a_i * a_j) + r[i + j] + carry;\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n }\n r[i + l] = carry;\n }\n trim(r);\n return r;\n }\n\n BigInteger.prototype.square = function() {\n return new BigInteger(square(this.value), false);\n };\n\n SmallInteger.prototype.square = function() {\n var value = this.value * this.value;\n if (isPrecise(value)) return new SmallInteger(value);\n return new BigInteger(square(smallToArray(Math.abs(this.value))), false);\n };\n\n NativeBigInt.prototype.square = function(v) {\n return new NativeBigInt(this.value * this.value);\n };\n\n function divMod1(a, b) {\n // Left over from previous version. Performs faster than divMod2 on smaller input sizes.\n var a_l = a.length,\n b_l = b.length,\n base = BASE,\n result = createArray(b.length),\n divisorMostSignificantDigit = b[b_l - 1],\n // normalization\n lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),\n remainder = multiplySmall(a, lambda),\n divisor = multiplySmall(b, lambda),\n quotientDigit,\n shift,\n carry,\n borrow,\n i,\n l,\n q;\n if (remainder.length <= a_l) remainder.push(0);\n divisor.push(0);\n divisorMostSignificantDigit = divisor[b_l - 1];\n for (shift = a_l - b_l; shift >= 0; shift--) {\n quotientDigit = base - 1;\n if (remainder[shift + b_l] !== divisorMostSignificantDigit) {\n quotientDigit = Math.floor(\n (remainder[shift + b_l] * base + remainder[shift + b_l - 1]) /\n divisorMostSignificantDigit\n );\n }\n // quotientDigit <= base - 1\n carry = 0;\n borrow = 0;\n l = divisor.length;\n for (i = 0; i < l; i++) {\n carry += quotientDigit * divisor[i];\n q = Math.floor(carry / base);\n borrow += remainder[shift + i] - (carry - q * base);\n carry = q;\n if (borrow < 0) {\n remainder[shift + i] = borrow + base;\n borrow = -1;\n } else {\n remainder[shift + i] = borrow;\n borrow = 0;\n }\n }\n while (borrow !== 0) {\n quotientDigit -= 1;\n carry = 0;\n for (i = 0; i < l; i++) {\n carry += remainder[shift + i] - base + divisor[i];\n if (carry < 0) {\n remainder[shift + i] = carry + base;\n carry = 0;\n } else {\n remainder[shift + i] = carry;\n carry = 1;\n }\n }\n borrow += carry;\n }\n result[shift] = quotientDigit;\n }\n // denormalization\n remainder = divModSmall(remainder, lambda)[0];\n return [arrayToSmall(result), arrayToSmall(remainder)];\n }\n\n function divMod2(a, b) {\n // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/\n // Performs faster than divMod1 on larger input sizes.\n var a_l = a.length,\n b_l = b.length,\n result = [],\n part = [],\n base = BASE,\n guess,\n xlen,\n highx,\n highy,\n check;\n while (a_l) {\n part.unshift(a[--a_l]);\n trim(part);\n if (compareAbs(part, b) < 0) {\n result.push(0);\n continue;\n }\n xlen = part.length;\n highx = part[xlen - 1] * base + part[xlen - 2];\n highy = b[b_l - 1] * base + b[b_l - 2];\n if (xlen > b_l) {\n highx = (highx + 1) * base;\n }\n guess = Math.ceil(highx / highy);\n do {\n check = multiplySmall(b, guess);\n if (compareAbs(check, part) <= 0) break;\n guess--;\n } while (guess);\n result.push(guess);\n part = subtract(part, check);\n }\n result.reverse();\n return [arrayToSmall(result), arrayToSmall(part)];\n }\n\n function divModSmall(value, lambda) {\n var length = value.length,\n quotient = createArray(length),\n base = BASE,\n i,\n q,\n remainder,\n divisor;\n remainder = 0;\n for (i = length - 1; i >= 0; --i) {\n divisor = remainder * base + value[i];\n q = truncate(divisor / lambda);\n remainder = divisor - q * lambda;\n quotient[i] = q | 0;\n }\n return [quotient, remainder | 0];\n }\n\n function divModAny(self, v) {\n var value,\n n = parseValue(v);\n if (supportsNativeBigInt) {\n return [\n new NativeBigInt(self.value / n.value),\n new NativeBigInt(self.value % n.value),\n ];\n }\n var a = self.value,\n b = n.value;\n var quotient;\n if (b === 0) throw new Error('Cannot divide by zero');\n if (self.isSmall) {\n if (n.isSmall) {\n return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];\n }\n return [Integer[0], self];\n }\n if (n.isSmall) {\n if (b === 1) return [self, Integer[0]];\n if (b == -1) return [self.negate(), Integer[0]];\n var abs = Math.abs(b);\n if (abs < BASE) {\n value = divModSmall(a, abs);\n quotient = arrayToSmall(value[0]);\n var remainder = value[1];\n if (self.sign) remainder = -remainder;\n if (typeof quotient === 'number') {\n if (self.sign !== n.sign) quotient = -quotient;\n return [new SmallInteger(quotient), new SmallInteger(remainder)];\n }\n return [\n new BigInteger(quotient, self.sign !== n.sign),\n new SmallInteger(remainder),\n ];\n }\n b = smallToArray(abs);\n }\n var comparison = compareAbs(a, b);\n if (comparison === -1) return [Integer[0], self];\n if (comparison === 0)\n return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];\n\n // divMod1 is faster on smaller input sizes\n if (a.length + b.length <= 200) value = divMod1(a, b);\n else value = divMod2(a, b);\n\n quotient = value[0];\n var qSign = self.sign !== n.sign,\n mod = value[1],\n mSign = self.sign;\n if (typeof quotient === 'number') {\n if (qSign) quotient = -quotient;\n quotient = new SmallInteger(quotient);\n } else quotient = new BigInteger(quotient, qSign);\n if (typeof mod === 'number') {\n if (mSign) mod = -mod;\n mod = new SmallInteger(mod);\n } else mod = new BigInteger(mod, mSign);\n return [quotient, mod];\n }\n\n BigInteger.prototype.divmod = function(v) {\n var result = divModAny(this, v);\n return {\n quotient: result[0],\n remainder: result[1],\n };\n };\n NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod =\n BigInteger.prototype.divmod;\n\n BigInteger.prototype.divide = function(v) {\n return divModAny(this, v)[0];\n };\n NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function(v) {\n return new NativeBigInt(this.value / parseValue(v).value);\n };\n SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over =\n BigInteger.prototype.divide;\n\n BigInteger.prototype.mod = function(v) {\n return divModAny(this, v)[1];\n };\n NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function(v) {\n return new NativeBigInt(this.value % parseValue(v).value);\n };\n SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder =\n BigInteger.prototype.mod;\n\n BigInteger.prototype.pow = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n value,\n x,\n y;\n if (b === 0) return Integer[1];\n if (a === 0) return Integer[0];\n if (a === 1) return Integer[1];\n if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.sign) {\n return Integer[0];\n }\n if (!n.isSmall)\n throw new Error('The exponent ' + n.toString() + ' is too large.');\n if (this.isSmall) {\n if (isPrecise((value = Math.pow(a, b))))\n return new SmallInteger(truncate(value));\n }\n x = this;\n y = Integer[1];\n while (true) {\n if (b & (1 === 1)) {\n y = y.times(x);\n --b;\n }\n if (b === 0) break;\n b /= 2;\n x = x.square();\n }\n return y;\n };\n SmallInteger.prototype.pow = BigInteger.prototype.pow;\n\n NativeBigInt.prototype.pow = function(v) {\n var n = parseValue(v);\n var a = this.value,\n b = n.value;\n var _0 = BigInt(0),\n _1 = BigInt(1),\n _2 = BigInt(2);\n if (b === _0) return Integer[1];\n if (a === _0) return Integer[0];\n if (a === _1) return Integer[1];\n if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.isNegative()) return new NativeBigInt(_0);\n var x = this;\n var y = Integer[1];\n while (true) {\n if ((b & _1) === _1) {\n y = y.times(x);\n --b;\n }\n if (b === _0) break;\n b /= _2;\n x = x.square();\n }\n return y;\n };\n\n BigInteger.prototype.modPow = function(exp, mod) {\n exp = parseValue(exp);\n mod = parseValue(mod);\n if (mod.isZero()) throw new Error('Cannot take modPow with modulus 0');\n var r = Integer[1],\n base = this.mod(mod);\n while (exp.isPositive()) {\n if (base.isZero()) return Integer[0];\n if (exp.isOdd()) r = r.multiply(base).mod(mod);\n exp = exp.divide(2);\n base = base.square().mod(mod);\n }\n return r;\n };\n NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow =\n BigInteger.prototype.modPow;\n\n function compareAbs(a, b) {\n if (a.length !== b.length) {\n return a.length > b.length ? 1 : -1;\n }\n for (var i = a.length - 1; i >= 0; i--) {\n if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;\n }\n return 0;\n }\n\n BigInteger.prototype.compareAbs = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) return 1;\n return compareAbs(a, b);\n };\n SmallInteger.prototype.compareAbs = function(v) {\n var n = parseValue(v),\n a = Math.abs(this.value),\n b = n.value;\n if (n.isSmall) {\n b = Math.abs(b);\n return a === b ? 0 : a > b ? 1 : -1;\n }\n return -1;\n };\n NativeBigInt.prototype.compareAbs = function(v) {\n var a = this.value;\n var b = parseValue(v).value;\n a = a >= 0 ? a : -a;\n b = b >= 0 ? b : -b;\n return a === b ? 0 : a > b ? 1 : -1;\n };\n\n BigInteger.prototype.compare = function(v) {\n // See discussion about comparison with Infinity:\n // https://github.com/peterolson/BigInteger.js/issues/61\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (this.sign !== n.sign) {\n return n.sign ? 1 : -1;\n }\n if (n.isSmall) {\n return this.sign ? -1 : 1;\n }\n return compareAbs(a, b) * (this.sign ? -1 : 1);\n };\n BigInteger.prototype.compareTo = BigInteger.prototype.compare;\n\n SmallInteger.prototype.compare = function(v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) {\n return a == b ? 0 : a > b ? 1 : -1;\n }\n if (a < 0 !== n.sign) {\n return a < 0 ? -1 : 1;\n }\n return a < 0 ? 1 : -1;\n };\n SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;\n\n NativeBigInt.prototype.compare = function(v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n var a = this.value;\n var b = parseValue(v).value;\n return a === b ? 0 : a > b ? 1 : -1;\n };\n NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;\n\n BigInteger.prototype.equals = function(v) {\n return this.compare(v) === 0;\n };\n NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq =\n BigInteger.prototype.equals;\n\n BigInteger.prototype.notEquals = function(v) {\n return this.compare(v) !== 0;\n };\n NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq =\n BigInteger.prototype.notEquals;\n\n BigInteger.prototype.greater = function(v) {\n return this.compare(v) > 0;\n };\n NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt =\n BigInteger.prototype.greater;\n\n BigInteger.prototype.lesser = function(v) {\n return this.compare(v) < 0;\n };\n NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt =\n BigInteger.prototype.lesser;\n\n BigInteger.prototype.greaterOrEquals = function(v) {\n return this.compare(v) >= 0;\n };\n NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq =\n BigInteger.prototype.greaterOrEquals;\n\n BigInteger.prototype.lesserOrEquals = function(v) {\n return this.compare(v) <= 0;\n };\n NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq =\n BigInteger.prototype.lesserOrEquals;\n\n BigInteger.prototype.isEven = function() {\n return (this.value[0] & 1) === 0;\n };\n SmallInteger.prototype.isEven = function() {\n return (this.value & 1) === 0;\n };\n NativeBigInt.prototype.isEven = function() {\n return (this.value & BigInt(1)) === BigInt(0);\n };\n\n BigInteger.prototype.isOdd = function() {\n return (this.value[0] & 1) === 1;\n };\n SmallInteger.prototype.isOdd = function() {\n return (this.value & 1) === 1;\n };\n NativeBigInt.prototype.isOdd = function() {\n return (this.value & BigInt(1)) === BigInt(1);\n };\n\n BigInteger.prototype.isPositive = function() {\n return !this.sign;\n };\n SmallInteger.prototype.isPositive = function() {\n return this.value > 0;\n };\n NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;\n\n BigInteger.prototype.isNegative = function() {\n return this.sign;\n };\n SmallInteger.prototype.isNegative = function() {\n return this.value < 0;\n };\n NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;\n\n BigInteger.prototype.isUnit = function() {\n return false;\n };\n SmallInteger.prototype.isUnit = function() {\n return Math.abs(this.value) === 1;\n };\n NativeBigInt.prototype.isUnit = function() {\n return this.abs().value === BigInt(1);\n };\n\n BigInteger.prototype.isZero = function() {\n return false;\n };\n SmallInteger.prototype.isZero = function() {\n return this.value === 0;\n };\n NativeBigInt.prototype.isZero = function() {\n return this.value === BigInt(0);\n };\n\n BigInteger.prototype.isDivisibleBy = function(v) {\n var n = parseValue(v);\n if (n.isZero()) return false;\n if (n.isUnit()) return true;\n if (n.compareAbs(2) === 0) return this.isEven();\n return this.mod(n).isZero();\n };\n NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy =\n BigInteger.prototype.isDivisibleBy;\n\n function isBasicPrime(v) {\n var n = v.abs();\n if (n.isUnit()) return false;\n if (n.equals(2) || n.equals(3) || n.equals(5)) return true;\n if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;\n if (n.lesser(49)) return true;\n // we don't know if it's prime: let the other functions figure it out\n }\n\n function millerRabinTest(n, a) {\n var nPrev = n.prev(),\n b = nPrev,\n r = 0,\n d,\n t,\n i,\n x;\n while (b.isEven()) (b = b.divide(2)), r++;\n next: for (i = 0; i < a.length; i++) {\n if (n.lesser(a[i])) continue;\n x = bigInt(a[i]).modPow(b, n);\n if (x.isUnit() || x.equals(nPrev)) continue;\n for (d = r - 1; d != 0; d--) {\n x = x.square().mod(n);\n if (x.isUnit()) return false;\n if (x.equals(nPrev)) continue next;\n }\n return false;\n }\n return true;\n }\n\n // Set \"strict\" to true to force GRH-supported lower bound of 2*log(N)^2\n BigInteger.prototype.isPrime = function(strict) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var bits = n.bitLength();\n if (bits <= 64)\n return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);\n var logN = Math.log(2) * bits.toJSNumber();\n var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN);\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt(i + 2));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime =\n BigInteger.prototype.isPrime;\n\n BigInteger.prototype.isProbablePrime = function(iterations) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var t = iterations === undefined ? 5 : iterations;\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt.randBetween(2, n.minus(2)));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime =\n BigInteger.prototype.isProbablePrime;\n\n BigInteger.prototype.modInv = function(n) {\n var t = bigInt.zero,\n newT = bigInt.one,\n r = parseValue(n),\n newR = this.abs(),\n q,\n lastT,\n lastR;\n while (!newR.isZero()) {\n q = r.divide(newR);\n lastT = t;\n lastR = r;\n t = newT;\n r = newR;\n newT = lastT.subtract(q.multiply(newT));\n newR = lastR.subtract(q.multiply(newR));\n }\n if (!r.isUnit())\n throw new Error(\n this.toString() + ' and ' + n.toString() + ' are not co-prime'\n );\n if (t.compare(0) === -1) {\n t = t.add(n);\n }\n if (this.isNegative()) {\n return t.negate();\n }\n return t;\n };\n\n NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv =\n BigInteger.prototype.modInv;\n\n BigInteger.prototype.next = function() {\n var value = this.value;\n if (this.sign) {\n return subtractSmall(value, 1, this.sign);\n }\n return new BigInteger(addSmall(value, 1), this.sign);\n };\n SmallInteger.prototype.next = function() {\n var value = this.value;\n if (value + 1 < MAX_INT) return new SmallInteger(value + 1);\n return new BigInteger(MAX_INT_ARR, false);\n };\n NativeBigInt.prototype.next = function() {\n return new NativeBigInt(this.value + BigInt(1));\n };\n\n BigInteger.prototype.prev = function() {\n var value = this.value;\n if (this.sign) {\n return new BigInteger(addSmall(value, 1), true);\n }\n return subtractSmall(value, 1, this.sign);\n };\n SmallInteger.prototype.prev = function() {\n var value = this.value;\n if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);\n return new BigInteger(MAX_INT_ARR, true);\n };\n NativeBigInt.prototype.prev = function() {\n return new NativeBigInt(this.value - BigInt(1));\n };\n\n var powersOfTwo = [1];\n while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE)\n powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);\n var powers2Length = powersOfTwo.length,\n highestPower2 = powersOfTwo[powers2Length - 1];\n\n function shift_isSmall(n) {\n return Math.abs(n) <= BASE;\n }\n\n BigInteger.prototype.shiftLeft = function(v) {\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + ' is too large for shifting.');\n }\n if (n < 0) return this.shiftRight(-n);\n var result = this;\n if (result.isZero()) return result;\n while (n >= powers2Length) {\n result = result.multiply(highestPower2);\n n -= powers2Length - 1;\n }\n return result.multiply(powersOfTwo[n]);\n };\n NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft =\n BigInteger.prototype.shiftLeft;\n\n BigInteger.prototype.shiftRight = function(v) {\n var remQuo;\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + ' is too large for shifting.');\n }\n if (n < 0) return this.shiftLeft(-n);\n var result = this;\n while (n >= powers2Length) {\n if (result.isZero() || (result.isNegative() && result.isUnit()))\n return result;\n remQuo = divModAny(result, highestPower2);\n result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n n -= powers2Length - 1;\n }\n remQuo = divModAny(result, powersOfTwo[n]);\n return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n };\n NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight =\n BigInteger.prototype.shiftRight;\n\n function bitwise(x, y, fn) {\n y = parseValue(y);\n var xSign = x.isNegative(),\n ySign = y.isNegative();\n var xRem = xSign ? x.not() : x,\n yRem = ySign ? y.not() : y;\n var xDigit = 0,\n yDigit = 0;\n var xDivMod = null,\n yDivMod = null;\n var result = [];\n while (!xRem.isZero() || !yRem.isZero()) {\n xDivMod = divModAny(xRem, highestPower2);\n xDigit = xDivMod[1].toJSNumber();\n if (xSign) {\n xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers\n }\n\n yDivMod = divModAny(yRem, highestPower2);\n yDigit = yDivMod[1].toJSNumber();\n if (ySign) {\n yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers\n }\n\n xRem = xDivMod[0];\n yRem = yDivMod[0];\n result.push(fn(xDigit, yDigit));\n }\n var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);\n for (var i = result.length - 1; i >= 0; i -= 1) {\n sum = sum.multiply(highestPower2).add(bigInt(result[i]));\n }\n return sum;\n }\n\n BigInteger.prototype.not = function() {\n return this.negate().prev();\n };\n NativeBigInt.prototype.not = SmallInteger.prototype.not =\n BigInteger.prototype.not;\n\n BigInteger.prototype.and = function(n) {\n return bitwise(this, n, function(a, b) {\n return a & b;\n });\n };\n NativeBigInt.prototype.and = SmallInteger.prototype.and =\n BigInteger.prototype.and;\n\n BigInteger.prototype.or = function(n) {\n return bitwise(this, n, function(a, b) {\n return a | b;\n });\n };\n NativeBigInt.prototype.or = SmallInteger.prototype.or =\n BigInteger.prototype.or;\n\n BigInteger.prototype.xor = function(n) {\n return bitwise(this, n, function(a, b) {\n return a ^ b;\n });\n };\n NativeBigInt.prototype.xor = SmallInteger.prototype.xor =\n BigInteger.prototype.xor;\n\n var LOBMASK_I = 1 << 30,\n LOBMASK_BI = ((BASE & -BASE) * (BASE & -BASE)) | LOBMASK_I;\n function roughLOB(n) {\n // get lowestOneBit (rough)\n // SmallInteger: return Min(lowestOneBit(n), 1 << 30)\n // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]\n var v = n.value,\n x =\n typeof v === 'number'\n ? v | LOBMASK_I\n : typeof v === 'bigint'\n ? v | BigInt(LOBMASK_I)\n : (v[0] + v[1] * BASE) | LOBMASK_BI;\n return x & -x;\n }\n\n function integerLogarithm(value, base) {\n if (base.compareTo(value) <= 0) {\n var tmp = integerLogarithm(value, base.square(base));\n var p = tmp.p;\n var e = tmp.e;\n var t = p.multiply(base);\n return t.compareTo(value) <= 0\n ? { p: t, e: e * 2 + 1 }\n : { p: p, e: e * 2 };\n }\n return { p: bigInt(1), e: 0 };\n }\n\n BigInteger.prototype.bitLength = function() {\n var n = this;\n if (n.compareTo(bigInt(0)) < 0) {\n n = n.negate().subtract(bigInt(1));\n }\n if (n.compareTo(bigInt(0)) === 0) {\n return bigInt(0);\n }\n return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));\n };\n NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength =\n BigInteger.prototype.bitLength;\n\n function max(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.greater(b) ? a : b;\n }\n function min(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.lesser(b) ? a : b;\n }\n function gcd(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n if (a.equals(b)) return a;\n if (a.isZero()) return b;\n if (b.isZero()) return a;\n var c = Integer[1],\n d,\n t;\n while (a.isEven() && b.isEven()) {\n d = min(roughLOB(a), roughLOB(b));\n a = a.divide(d);\n b = b.divide(d);\n c = c.multiply(d);\n }\n while (a.isEven()) {\n a = a.divide(roughLOB(a));\n }\n do {\n while (b.isEven()) {\n b = b.divide(roughLOB(b));\n }\n if (a.greater(b)) {\n t = b;\n b = a;\n a = t;\n }\n b = b.subtract(a);\n } while (!b.isZero());\n return c.isUnit() ? a : a.multiply(c);\n }\n function lcm(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n return a.divide(gcd(a, b)).multiply(b);\n }\n function randBetween(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n var low = min(a, b),\n high = max(a, b);\n var range = high.subtract(low).add(1);\n if (range.isSmall) return low.add(Math.floor(Math.random() * range));\n var digits = toBase(range, BASE).value;\n var result = [],\n restricted = true;\n for (var i = 0; i < digits.length; i++) {\n var top = restricted ? digits[i] : BASE;\n var digit = truncate(Math.random() * top);\n result.push(digit);\n if (digit < top) restricted = false;\n }\n return low.add(Integer.fromArray(result, BASE, false));\n }\n\n var parseBase = function(text, base, alphabet, caseSensitive) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n text = String(text);\n if (!caseSensitive) {\n text = text.toLowerCase();\n alphabet = alphabet.toLowerCase();\n }\n var length = text.length;\n var i;\n var absBase = Math.abs(base);\n var alphabetValues = {};\n for (i = 0; i < alphabet.length; i++) {\n alphabetValues[alphabet[i]] = i;\n }\n for (i = 0; i < length; i++) {\n var c = text[i];\n if (c === '-') continue;\n if (c in alphabetValues) {\n if (alphabetValues[c] >= absBase) {\n if (c === '1' && absBase === 1) continue;\n throw new Error(c + ' is not a valid digit in base ' + base + '.');\n }\n }\n }\n base = parseValue(base);\n var digits = [];\n var isNegative = text[0] === '-';\n for (i = isNegative ? 1 : 0; i < text.length; i++) {\n var c = text[i];\n if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));\n else if (c === '<') {\n var start = i;\n do {\n i++;\n } while (text[i] !== '>' && i < text.length);\n digits.push(parseValue(text.slice(start + 1, i)));\n } else throw new Error(c + ' is not a valid character');\n }\n return parseBaseFromArray(digits, base, isNegative);\n };\n\n function parseBaseFromArray(digits, base, isNegative) {\n var val = Integer[0],\n pow = Integer[1],\n i;\n for (i = digits.length - 1; i >= 0; i--) {\n val = val.add(digits[i].times(pow));\n pow = pow.times(base);\n }\n return isNegative ? val.negate() : val;\n }\n\n function stringify(digit, alphabet) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n if (digit < alphabet.length) {\n return alphabet[digit];\n }\n return '<' + digit + '>';\n }\n\n function toBase(n, base) {\n base = bigInt(base);\n if (base.isZero()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n throw new Error('Cannot convert nonzero numbers to base 0.');\n }\n if (base.equals(-1)) {\n if (n.isZero()) return { value: [0], isNegative: false };\n if (n.isNegative())\n return {\n value: [].concat.apply(\n [],\n Array.apply(null, Array(-n.toJSNumber())).map(\n Array.prototype.valueOf,\n [1, 0]\n )\n ),\n isNegative: false,\n };\n\n var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(\n Array.prototype.valueOf,\n [0, 1]\n );\n arr.unshift([1]);\n return {\n value: [].concat.apply([], arr),\n isNegative: false,\n };\n }\n\n var neg = false;\n if (n.isNegative() && base.isPositive()) {\n neg = true;\n n = n.abs();\n }\n if (base.isUnit()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n\n return {\n value: Array.apply(null, Array(n.toJSNumber())).map(\n Number.prototype.valueOf,\n 1\n ),\n isNegative: neg,\n };\n }\n var out = [];\n var left = n,\n divmod;\n while (left.isNegative() || left.compareAbs(base) >= 0) {\n divmod = left.divmod(base);\n left = divmod.quotient;\n var digit = divmod.remainder;\n if (digit.isNegative()) {\n digit = base.minus(digit).abs();\n left = left.next();\n }\n out.push(digit.toJSNumber());\n }\n out.push(left.toJSNumber());\n return { value: out.reverse(), isNegative: neg };\n }\n\n function toBaseString(n, base, alphabet) {\n var arr = toBase(n, base);\n return (\n (arr.isNegative ? '-' : '') +\n arr.value\n .map(function(x) {\n return stringify(x, alphabet);\n })\n .join('')\n );\n }\n\n BigInteger.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n SmallInteger.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n NativeBigInt.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n BigInteger.prototype.toString = function(radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix !== 10) return toBaseString(this, radix, alphabet);\n var v = this.value,\n l = v.length,\n str = String(v[--l]),\n zeros = '0000000',\n digit;\n while (--l >= 0) {\n digit = String(v[l]);\n str += zeros.slice(digit.length) + digit;\n }\n var sign = this.sign ? '-' : '';\n return sign + str;\n };\n\n SmallInteger.prototype.toString = function(radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix != 10) return toBaseString(this, radix, alphabet);\n return String(this.value);\n };\n\n NativeBigInt.prototype.toString = SmallInteger.prototype.toString;\n\n NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function() {\n return this.toString();\n };\n\n BigInteger.prototype.valueOf = function() {\n return parseInt(this.toString(), 10);\n };\n BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;\n\n SmallInteger.prototype.valueOf = function() {\n return this.value;\n };\n SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;\n NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function() {\n return parseInt(this.toString(), 10);\n };\n\n function parseStringValue(v) {\n if (isPrecise(+v)) {\n var x = +v;\n if (x === truncate(x))\n return supportsNativeBigInt\n ? new NativeBigInt(BigInt(x))\n : new SmallInteger(x);\n throw new Error('Invalid integer: ' + v);\n }\n var sign = v[0] === '-';\n if (sign) v = v.slice(1);\n var split = v.split(/e/i);\n if (split.length > 2)\n throw new Error('Invalid integer: ' + split.join('e'));\n if (split.length === 2) {\n var exp = split[1];\n if (exp[0] === '+') exp = exp.slice(1);\n exp = +exp;\n if (exp !== truncate(exp) || !isPrecise(exp))\n throw new Error(\n 'Invalid integer: ' + exp + ' is not a valid exponent.'\n );\n var text = split[0];\n var decimalPlace = text.indexOf('.');\n if (decimalPlace >= 0) {\n exp -= text.length - decimalPlace - 1;\n text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);\n }\n if (exp < 0)\n throw new Error('Cannot include negative exponent part for integers');\n text += new Array(exp + 1).join('0');\n v = text;\n }\n var isValid = /^([0-9][0-9]*)$/.test(v);\n if (!isValid) throw new Error('Invalid integer: ' + v);\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(sign ? '-' + v : v));\n }\n var r = [],\n max = v.length,\n l = LOG_BASE,\n min = max - l;\n while (max > 0) {\n r.push(+v.slice(min, max));\n min -= l;\n if (min < 0) min = 0;\n max -= l;\n }\n trim(r);\n return new BigInteger(r, sign);\n }\n\n function parseNumberValue(v) {\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(v));\n }\n if (isPrecise(v)) {\n if (v !== truncate(v)) throw new Error(v + ' is not an integer.');\n return new SmallInteger(v);\n }\n return parseStringValue(v.toString());\n }\n\n function parseValue(v) {\n if (typeof v === 'number') {\n return parseNumberValue(v);\n }\n if (typeof v === 'string') {\n return parseStringValue(v);\n }\n if (typeof v === 'bigint') {\n return new NativeBigInt(v);\n }\n return v;\n }\n // Pre-define numbers in range [-999,999]\n for (var i = 0; i < 1000; i++) {\n Integer[i] = parseValue(i);\n if (i > 0) Integer[-i] = parseValue(-i);\n }\n // Backwards compatibility\n Integer.one = Integer[1];\n Integer.zero = Integer[0];\n Integer.minusOne = Integer[-1];\n Integer.max = max;\n Integer.min = min;\n Integer.gcd = gcd;\n Integer.lcm = lcm;\n Integer.isInstance = function(x) {\n return (\n x instanceof BigInteger ||\n x instanceof SmallInteger ||\n x instanceof NativeBigInt\n );\n };\n Integer.randBetween = randBetween;\n\n Integer.fromArray = function(digits, base, isNegative) {\n return parseBaseFromArray(\n digits.map(parseValue),\n parseValue(base || 10),\n isNegative\n );\n };\n\n return Integer;\n})();\n\n// Node.js check\nif (typeof module !== 'undefined' && module.hasOwnProperty('exports')) {\n module.exports = bigInt;\n}\n\n//amd check\nif (typeof define === 'function' && define.amd) {\n define('big-integer', [], function() {\n return bigInt;\n });\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\n\nvar input = ``;\n\nfunction cacheInput(data) {\n input += data;\n}\n\nfunction main() {\n let lines = input.split('\\r\\n');\n let n = parseInt(lines[0]);\n for (var i = 1; i <= n; i++) {\n let steps = bigInt(0);\n let input = lines[i].split(' ');\n let n = bigInt(input[0]);\n let k = bigInt(input[1]);\n while (n.value) {\n let mod = bigInt(n).mod(bigInt(k));\n if (mod.value === 0) {\n n = bigInt(n).divide(bigInt(k));\n steps = bigInt(steps).add(1);\n } else {\n n = bigInt(n).minus(bigInt(mod));\n steps = bigInt(steps).add(bigInt(mod));\n }\n }\n console.log(steps.toString());\n }\n}\n\nprocess.stdin.on('data', cacheInput).on('end', main);", "positive_code": [{"source_code": "var bigInt = (function(undefined) {\n 'use strict';\n\n var BASE = 1e7,\n LOG_BASE = 7,\n MAX_INT = 9007199254740992,\n MAX_INT_ARR = smallToArray(MAX_INT),\n DEFAULT_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n var supportsNativeBigInt = typeof BigInt === 'function';\n\n function Integer(v, radix, alphabet, caseSensitive) {\n if (typeof v === 'undefined') return Integer[0];\n if (typeof radix !== 'undefined')\n return +radix === 10 && !alphabet\n ? parseValue(v)\n : parseBase(v, radix, alphabet, caseSensitive);\n return parseValue(v);\n }\n\n function BigInteger(value, sign) {\n this.value = value;\n this.sign = sign;\n this.isSmall = false;\n }\n BigInteger.prototype = Object.create(Integer.prototype);\n\n function SmallInteger(value) {\n this.value = value;\n this.sign = value < 0;\n this.isSmall = true;\n }\n SmallInteger.prototype = Object.create(Integer.prototype);\n\n function NativeBigInt(value) {\n this.value = value;\n }\n NativeBigInt.prototype = Object.create(Integer.prototype);\n\n function isPrecise(n) {\n return -MAX_INT < n && n < MAX_INT;\n }\n\n function smallToArray(n) {\n // For performance reasons doesn't reference BASE, need to change this function if BASE changes\n if (n < 1e7) return [n];\n if (n < 1e14) return [n % 1e7, Math.floor(n / 1e7)];\n return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];\n }\n\n function arrayToSmall(arr) {\n // If BASE changes this function may need to change\n trim(arr);\n var length = arr.length;\n if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {\n switch (length) {\n case 0:\n return 0;\n case 1:\n return arr[0];\n case 2:\n return arr[0] + arr[1] * BASE;\n default:\n return arr[0] + (arr[1] + arr[2] * BASE) * BASE;\n }\n }\n return arr;\n }\n\n function trim(v) {\n var i = v.length;\n while (v[--i] === 0);\n v.length = i + 1;\n }\n\n function createArray(length) {\n // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger\n var x = new Array(length);\n var i = -1;\n while (++i < length) {\n x[i] = 0;\n }\n return x;\n }\n\n function truncate(n) {\n if (n > 0) return Math.floor(n);\n return Math.ceil(n);\n }\n\n function add(a, b) {\n // assumes a and b are arrays with a.length >= b.length\n var l_a = a.length,\n l_b = b.length,\n r = new Array(l_a),\n carry = 0,\n base = BASE,\n sum,\n i;\n for (i = 0; i < l_b; i++) {\n sum = a[i] + b[i] + carry;\n carry = sum >= base ? 1 : 0;\n r[i] = sum - carry * base;\n }\n while (i < l_a) {\n sum = a[i] + carry;\n carry = sum === base ? 1 : 0;\n r[i++] = sum - carry * base;\n }\n if (carry > 0) r.push(carry);\n return r;\n }\n\n function addAny(a, b) {\n if (a.length >= b.length) return add(a, b);\n return add(b, a);\n }\n\n function addSmall(a, carry) {\n // assumes a is array, carry is number with 0 <= carry < MAX_INT\n var l = a.length,\n r = new Array(l),\n base = BASE,\n sum,\n i;\n for (i = 0; i < l; i++) {\n sum = a[i] - base + carry;\n carry = Math.floor(sum / base);\n r[i] = sum - carry * base;\n carry += 1;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n BigInteger.prototype.add = function(v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.subtract(n.negate());\n }\n var a = this.value,\n b = n.value;\n if (n.isSmall) {\n return new BigInteger(addSmall(a, Math.abs(b)), this.sign);\n }\n return new BigInteger(addAny(a, b), this.sign);\n };\n BigInteger.prototype.plus = BigInteger.prototype.add;\n\n SmallInteger.prototype.add = function(v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.subtract(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n if (isPrecise(a + b)) return new SmallInteger(a + b);\n b = smallToArray(Math.abs(b));\n }\n return new BigInteger(addSmall(b, Math.abs(a)), a < 0);\n };\n SmallInteger.prototype.plus = SmallInteger.prototype.add;\n\n NativeBigInt.prototype.add = function(v) {\n return new NativeBigInt(this.value + parseValue(v).value);\n };\n NativeBigInt.prototype.plus = NativeBigInt.prototype.add;\n\n function subtract(a, b) {\n // assumes a and b are arrays with a >= b\n var a_l = a.length,\n b_l = b.length,\n r = new Array(a_l),\n borrow = 0,\n base = BASE,\n i,\n difference;\n for (i = 0; i < b_l; i++) {\n difference = a[i] - borrow - b[i];\n if (difference < 0) {\n difference += base;\n borrow = 1;\n } else borrow = 0;\n r[i] = difference;\n }\n for (i = b_l; i < a_l; i++) {\n difference = a[i] - borrow;\n if (difference < 0) difference += base;\n else {\n r[i++] = difference;\n break;\n }\n r[i] = difference;\n }\n for (; i < a_l; i++) {\n r[i] = a[i];\n }\n trim(r);\n return r;\n }\n\n function subtractAny(a, b, sign) {\n var value;\n if (compareAbs(a, b) >= 0) {\n value = subtract(a, b);\n } else {\n value = subtract(b, a);\n sign = !sign;\n }\n value = arrayToSmall(value);\n if (typeof value === 'number') {\n if (sign) value = -value;\n return new SmallInteger(value);\n }\n return new BigInteger(value, sign);\n }\n\n function subtractSmall(a, b, sign) {\n // assumes a is array, b is number with 0 <= b < MAX_INT\n var l = a.length,\n r = new Array(l),\n carry = -b,\n base = BASE,\n i,\n difference;\n for (i = 0; i < l; i++) {\n difference = a[i] + carry;\n carry = Math.floor(difference / base);\n difference %= base;\n r[i] = difference < 0 ? difference + base : difference;\n }\n r = arrayToSmall(r);\n if (typeof r === 'number') {\n if (sign) r = -r;\n return new SmallInteger(r);\n }\n return new BigInteger(r, sign);\n }\n\n BigInteger.prototype.subtract = function(v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.add(n.negate());\n }\n var a = this.value,\n b = n.value;\n if (n.isSmall) return subtractSmall(a, Math.abs(b), this.sign);\n return subtractAny(a, b, this.sign);\n };\n BigInteger.prototype.minus = BigInteger.prototype.subtract;\n\n SmallInteger.prototype.subtract = function(v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.add(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n return new SmallInteger(a - b);\n }\n return subtractSmall(b, Math.abs(a), a >= 0);\n };\n SmallInteger.prototype.minus = SmallInteger.prototype.subtract;\n\n NativeBigInt.prototype.subtract = function(v) {\n return new NativeBigInt(this.value - parseValue(v).value);\n };\n NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;\n\n BigInteger.prototype.negate = function() {\n return new BigInteger(this.value, !this.sign);\n };\n SmallInteger.prototype.negate = function() {\n var sign = this.sign;\n var small = new SmallInteger(-this.value);\n small.sign = !sign;\n return small;\n };\n NativeBigInt.prototype.negate = function() {\n return new NativeBigInt(-this.value);\n };\n\n BigInteger.prototype.abs = function() {\n return new BigInteger(this.value, false);\n };\n SmallInteger.prototype.abs = function() {\n return new SmallInteger(Math.abs(this.value));\n };\n NativeBigInt.prototype.abs = function() {\n return new NativeBigInt(this.value >= 0 ? this.value : -this.value);\n };\n\n function multiplyLong(a, b) {\n var a_l = a.length,\n b_l = b.length,\n l = a_l + b_l,\n r = createArray(l),\n base = BASE,\n product,\n carry,\n i,\n a_i,\n b_j;\n for (i = 0; i < a_l; ++i) {\n a_i = a[i];\n for (var j = 0; j < b_l; ++j) {\n b_j = b[j];\n product = a_i * b_j + r[i + j];\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n r[i + j + 1] += carry;\n }\n }\n trim(r);\n return r;\n }\n\n function multiplySmall(a, b) {\n // assumes a is array, b is number with |b| < BASE\n var l = a.length,\n r = new Array(l),\n base = BASE,\n carry = 0,\n product,\n i;\n for (i = 0; i < l; i++) {\n product = a[i] * b + carry;\n carry = Math.floor(product / base);\n r[i] = product - carry * base;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n function shiftLeft(x, n) {\n var r = [];\n while (n-- > 0) r.push(0);\n return r.concat(x);\n }\n\n function multiplyKaratsuba(x, y) {\n var n = Math.max(x.length, y.length);\n\n if (n <= 30) return multiplyLong(x, y);\n n = Math.ceil(n / 2);\n\n var b = x.slice(n),\n a = x.slice(0, n),\n d = y.slice(n),\n c = y.slice(0, n);\n\n var ac = multiplyKaratsuba(a, c),\n bd = multiplyKaratsuba(b, d),\n abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));\n\n var product = addAny(\n addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)),\n shiftLeft(bd, 2 * n)\n );\n trim(product);\n return product;\n }\n\n // The following function is derived from a surface fit of a graph plotting the performance difference\n // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.\n function useKaratsuba(l1, l2) {\n return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;\n }\n\n BigInteger.prototype.multiply = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n sign = this.sign !== n.sign,\n abs;\n if (n.isSmall) {\n if (b === 0) return Integer[0];\n if (b === 1) return this;\n if (b === -1) return this.negate();\n abs = Math.abs(b);\n if (abs < BASE) {\n return new BigInteger(multiplySmall(a, abs), sign);\n }\n b = smallToArray(abs);\n }\n if (useKaratsuba(a.length, b.length))\n // Karatsuba is only faster for certain array sizes\n return new BigInteger(multiplyKaratsuba(a, b), sign);\n return new BigInteger(multiplyLong(a, b), sign);\n };\n\n BigInteger.prototype.times = BigInteger.prototype.multiply;\n\n function multiplySmallAndArray(a, b, sign) {\n // a >= 0\n if (a < BASE) {\n return new BigInteger(multiplySmall(b, a), sign);\n }\n return new BigInteger(multiplyLong(b, smallToArray(a)), sign);\n }\n SmallInteger.prototype._multiplyBySmall = function(a) {\n if (isPrecise(a.value * this.value)) {\n return new SmallInteger(a.value * this.value);\n }\n return multiplySmallAndArray(\n Math.abs(a.value),\n smallToArray(Math.abs(this.value)),\n this.sign !== a.sign\n );\n };\n BigInteger.prototype._multiplyBySmall = function(a) {\n if (a.value === 0) return Integer[0];\n if (a.value === 1) return this;\n if (a.value === -1) return this.negate();\n return multiplySmallAndArray(\n Math.abs(a.value),\n this.value,\n this.sign !== a.sign\n );\n };\n SmallInteger.prototype.multiply = function(v) {\n return parseValue(v)._multiplyBySmall(this);\n };\n SmallInteger.prototype.times = SmallInteger.prototype.multiply;\n\n NativeBigInt.prototype.multiply = function(v) {\n return new NativeBigInt(this.value * parseValue(v).value);\n };\n NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;\n\n function square(a) {\n //console.assert(2 * BASE * BASE < MAX_INT);\n var l = a.length,\n r = createArray(l + l),\n base = BASE,\n product,\n carry,\n i,\n a_i,\n a_j;\n for (i = 0; i < l; i++) {\n a_i = a[i];\n carry = 0 - a_i * a_i;\n for (var j = i; j < l; j++) {\n a_j = a[j];\n product = 2 * (a_i * a_j) + r[i + j] + carry;\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n }\n r[i + l] = carry;\n }\n trim(r);\n return r;\n }\n\n BigInteger.prototype.square = function() {\n return new BigInteger(square(this.value), false);\n };\n\n SmallInteger.prototype.square = function() {\n var value = this.value * this.value;\n if (isPrecise(value)) return new SmallInteger(value);\n return new BigInteger(square(smallToArray(Math.abs(this.value))), false);\n };\n\n NativeBigInt.prototype.square = function(v) {\n return new NativeBigInt(this.value * this.value);\n };\n\n function divMod1(a, b) {\n // Left over from previous version. Performs faster than divMod2 on smaller input sizes.\n var a_l = a.length,\n b_l = b.length,\n base = BASE,\n result = createArray(b.length),\n divisorMostSignificantDigit = b[b_l - 1],\n // normalization\n lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),\n remainder = multiplySmall(a, lambda),\n divisor = multiplySmall(b, lambda),\n quotientDigit,\n shift,\n carry,\n borrow,\n i,\n l,\n q;\n if (remainder.length <= a_l) remainder.push(0);\n divisor.push(0);\n divisorMostSignificantDigit = divisor[b_l - 1];\n for (shift = a_l - b_l; shift >= 0; shift--) {\n quotientDigit = base - 1;\n if (remainder[shift + b_l] !== divisorMostSignificantDigit) {\n quotientDigit = Math.floor(\n (remainder[shift + b_l] * base + remainder[shift + b_l - 1]) /\n divisorMostSignificantDigit\n );\n }\n // quotientDigit <= base - 1\n carry = 0;\n borrow = 0;\n l = divisor.length;\n for (i = 0; i < l; i++) {\n carry += quotientDigit * divisor[i];\n q = Math.floor(carry / base);\n borrow += remainder[shift + i] - (carry - q * base);\n carry = q;\n if (borrow < 0) {\n remainder[shift + i] = borrow + base;\n borrow = -1;\n } else {\n remainder[shift + i] = borrow;\n borrow = 0;\n }\n }\n while (borrow !== 0) {\n quotientDigit -= 1;\n carry = 0;\n for (i = 0; i < l; i++) {\n carry += remainder[shift + i] - base + divisor[i];\n if (carry < 0) {\n remainder[shift + i] = carry + base;\n carry = 0;\n } else {\n remainder[shift + i] = carry;\n carry = 1;\n }\n }\n borrow += carry;\n }\n result[shift] = quotientDigit;\n }\n // denormalization\n remainder = divModSmall(remainder, lambda)[0];\n return [arrayToSmall(result), arrayToSmall(remainder)];\n }\n\n function divMod2(a, b) {\n // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/\n // Performs faster than divMod1 on larger input sizes.\n var a_l = a.length,\n b_l = b.length,\n result = [],\n part = [],\n base = BASE,\n guess,\n xlen,\n highx,\n highy,\n check;\n while (a_l) {\n part.unshift(a[--a_l]);\n trim(part);\n if (compareAbs(part, b) < 0) {\n result.push(0);\n continue;\n }\n xlen = part.length;\n highx = part[xlen - 1] * base + part[xlen - 2];\n highy = b[b_l - 1] * base + b[b_l - 2];\n if (xlen > b_l) {\n highx = (highx + 1) * base;\n }\n guess = Math.ceil(highx / highy);\n do {\n check = multiplySmall(b, guess);\n if (compareAbs(check, part) <= 0) break;\n guess--;\n } while (guess);\n result.push(guess);\n part = subtract(part, check);\n }\n result.reverse();\n return [arrayToSmall(result), arrayToSmall(part)];\n }\n\n function divModSmall(value, lambda) {\n var length = value.length,\n quotient = createArray(length),\n base = BASE,\n i,\n q,\n remainder,\n divisor;\n remainder = 0;\n for (i = length - 1; i >= 0; --i) {\n divisor = remainder * base + value[i];\n q = truncate(divisor / lambda);\n remainder = divisor - q * lambda;\n quotient[i] = q | 0;\n }\n return [quotient, remainder | 0];\n }\n\n function divModAny(self, v) {\n var value,\n n = parseValue(v);\n if (supportsNativeBigInt) {\n return [\n new NativeBigInt(self.value / n.value),\n new NativeBigInt(self.value % n.value),\n ];\n }\n var a = self.value,\n b = n.value;\n var quotient;\n if (b === 0) throw new Error('Cannot divide by zero');\n if (self.isSmall) {\n if (n.isSmall) {\n return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];\n }\n return [Integer[0], self];\n }\n if (n.isSmall) {\n if (b === 1) return [self, Integer[0]];\n if (b == -1) return [self.negate(), Integer[0]];\n var abs = Math.abs(b);\n if (abs < BASE) {\n value = divModSmall(a, abs);\n quotient = arrayToSmall(value[0]);\n var remainder = value[1];\n if (self.sign) remainder = -remainder;\n if (typeof quotient === 'number') {\n if (self.sign !== n.sign) quotient = -quotient;\n return [new SmallInteger(quotient), new SmallInteger(remainder)];\n }\n return [\n new BigInteger(quotient, self.sign !== n.sign),\n new SmallInteger(remainder),\n ];\n }\n b = smallToArray(abs);\n }\n var comparison = compareAbs(a, b);\n if (comparison === -1) return [Integer[0], self];\n if (comparison === 0)\n return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];\n\n // divMod1 is faster on smaller input sizes\n if (a.length + b.length <= 200) value = divMod1(a, b);\n else value = divMod2(a, b);\n\n quotient = value[0];\n var qSign = self.sign !== n.sign,\n mod = value[1],\n mSign = self.sign;\n if (typeof quotient === 'number') {\n if (qSign) quotient = -quotient;\n quotient = new SmallInteger(quotient);\n } else quotient = new BigInteger(quotient, qSign);\n if (typeof mod === 'number') {\n if (mSign) mod = -mod;\n mod = new SmallInteger(mod);\n } else mod = new BigInteger(mod, mSign);\n return [quotient, mod];\n }\n\n BigInteger.prototype.divmod = function(v) {\n var result = divModAny(this, v);\n return {\n quotient: result[0],\n remainder: result[1],\n };\n };\n NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod =\n BigInteger.prototype.divmod;\n\n BigInteger.prototype.divide = function(v) {\n return divModAny(this, v)[0];\n };\n NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function(v) {\n return new NativeBigInt(this.value / parseValue(v).value);\n };\n SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over =\n BigInteger.prototype.divide;\n\n BigInteger.prototype.mod = function(v) {\n return divModAny(this, v)[1];\n };\n NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function(v) {\n return new NativeBigInt(this.value % parseValue(v).value);\n };\n SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder =\n BigInteger.prototype.mod;\n\n BigInteger.prototype.pow = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n value,\n x,\n y;\n if (b === 0) return Integer[1];\n if (a === 0) return Integer[0];\n if (a === 1) return Integer[1];\n if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.sign) {\n return Integer[0];\n }\n if (!n.isSmall)\n throw new Error('The exponent ' + n.toString() + ' is too large.');\n if (this.isSmall) {\n if (isPrecise((value = Math.pow(a, b))))\n return new SmallInteger(truncate(value));\n }\n x = this;\n y = Integer[1];\n while (true) {\n if (b & (1 === 1)) {\n y = y.times(x);\n --b;\n }\n if (b === 0) break;\n b /= 2;\n x = x.square();\n }\n return y;\n };\n SmallInteger.prototype.pow = BigInteger.prototype.pow;\n\n NativeBigInt.prototype.pow = function(v) {\n var n = parseValue(v);\n var a = this.value,\n b = n.value;\n var _0 = BigInt(0),\n _1 = BigInt(1),\n _2 = BigInt(2);\n if (b === _0) return Integer[1];\n if (a === _0) return Integer[0];\n if (a === _1) return Integer[1];\n if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.isNegative()) return new NativeBigInt(_0);\n var x = this;\n var y = Integer[1];\n while (true) {\n if ((b & _1) === _1) {\n y = y.times(x);\n --b;\n }\n if (b === _0) break;\n b /= _2;\n x = x.square();\n }\n return y;\n };\n\n BigInteger.prototype.modPow = function(exp, mod) {\n exp = parseValue(exp);\n mod = parseValue(mod);\n if (mod.isZero()) throw new Error('Cannot take modPow with modulus 0');\n var r = Integer[1],\n base = this.mod(mod);\n while (exp.isPositive()) {\n if (base.isZero()) return Integer[0];\n if (exp.isOdd()) r = r.multiply(base).mod(mod);\n exp = exp.divide(2);\n base = base.square().mod(mod);\n }\n return r;\n };\n NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow =\n BigInteger.prototype.modPow;\n\n function compareAbs(a, b) {\n if (a.length !== b.length) {\n return a.length > b.length ? 1 : -1;\n }\n for (var i = a.length - 1; i >= 0; i--) {\n if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;\n }\n return 0;\n }\n\n BigInteger.prototype.compareAbs = function(v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) return 1;\n return compareAbs(a, b);\n };\n SmallInteger.prototype.compareAbs = function(v) {\n var n = parseValue(v),\n a = Math.abs(this.value),\n b = n.value;\n if (n.isSmall) {\n b = Math.abs(b);\n return a === b ? 0 : a > b ? 1 : -1;\n }\n return -1;\n };\n NativeBigInt.prototype.compareAbs = function(v) {\n var a = this.value;\n var b = parseValue(v).value;\n a = a >= 0 ? a : -a;\n b = b >= 0 ? b : -b;\n return a === b ? 0 : a > b ? 1 : -1;\n };\n\n BigInteger.prototype.compare = function(v) {\n // See discussion about comparison with Infinity:\n // https://github.com/peterolson/BigInteger.js/issues/61\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (this.sign !== n.sign) {\n return n.sign ? 1 : -1;\n }\n if (n.isSmall) {\n return this.sign ? -1 : 1;\n }\n return compareAbs(a, b) * (this.sign ? -1 : 1);\n };\n BigInteger.prototype.compareTo = BigInteger.prototype.compare;\n\n SmallInteger.prototype.compare = function(v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) {\n return a == b ? 0 : a > b ? 1 : -1;\n }\n if (a < 0 !== n.sign) {\n return a < 0 ? -1 : 1;\n }\n return a < 0 ? 1 : -1;\n };\n SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;\n\n NativeBigInt.prototype.compare = function(v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n var a = this.value;\n var b = parseValue(v).value;\n return a === b ? 0 : a > b ? 1 : -1;\n };\n NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;\n\n BigInteger.prototype.equals = function(v) {\n return this.compare(v) === 0;\n };\n NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq =\n BigInteger.prototype.equals;\n\n BigInteger.prototype.notEquals = function(v) {\n return this.compare(v) !== 0;\n };\n NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq =\n BigInteger.prototype.notEquals;\n\n BigInteger.prototype.greater = function(v) {\n return this.compare(v) > 0;\n };\n NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt =\n BigInteger.prototype.greater;\n\n BigInteger.prototype.lesser = function(v) {\n return this.compare(v) < 0;\n };\n NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt =\n BigInteger.prototype.lesser;\n\n BigInteger.prototype.greaterOrEquals = function(v) {\n return this.compare(v) >= 0;\n };\n NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq =\n BigInteger.prototype.greaterOrEquals;\n\n BigInteger.prototype.lesserOrEquals = function(v) {\n return this.compare(v) <= 0;\n };\n NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq =\n BigInteger.prototype.lesserOrEquals;\n\n BigInteger.prototype.isEven = function() {\n return (this.value[0] & 1) === 0;\n };\n SmallInteger.prototype.isEven = function() {\n return (this.value & 1) === 0;\n };\n NativeBigInt.prototype.isEven = function() {\n return (this.value & BigInt(1)) === BigInt(0);\n };\n\n BigInteger.prototype.isOdd = function() {\n return (this.value[0] & 1) === 1;\n };\n SmallInteger.prototype.isOdd = function() {\n return (this.value & 1) === 1;\n };\n NativeBigInt.prototype.isOdd = function() {\n return (this.value & BigInt(1)) === BigInt(1);\n };\n\n BigInteger.prototype.isPositive = function() {\n return !this.sign;\n };\n SmallInteger.prototype.isPositive = function() {\n return this.value > 0;\n };\n NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;\n\n BigInteger.prototype.isNegative = function() {\n return this.sign;\n };\n SmallInteger.prototype.isNegative = function() {\n return this.value < 0;\n };\n NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;\n\n BigInteger.prototype.isUnit = function() {\n return false;\n };\n SmallInteger.prototype.isUnit = function() {\n return Math.abs(this.value) === 1;\n };\n NativeBigInt.prototype.isUnit = function() {\n return this.abs().value === BigInt(1);\n };\n\n BigInteger.prototype.isZero = function() {\n return false;\n };\n SmallInteger.prototype.isZero = function() {\n return this.value === 0;\n };\n NativeBigInt.prototype.isZero = function() {\n return this.value === BigInt(0);\n };\n\n BigInteger.prototype.isDivisibleBy = function(v) {\n var n = parseValue(v);\n if (n.isZero()) return false;\n if (n.isUnit()) return true;\n if (n.compareAbs(2) === 0) return this.isEven();\n return this.mod(n).isZero();\n };\n NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy =\n BigInteger.prototype.isDivisibleBy;\n\n function isBasicPrime(v) {\n var n = v.abs();\n if (n.isUnit()) return false;\n if (n.equals(2) || n.equals(3) || n.equals(5)) return true;\n if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;\n if (n.lesser(49)) return true;\n // we don't know if it's prime: let the other functions figure it out\n }\n\n function millerRabinTest(n, a) {\n var nPrev = n.prev(),\n b = nPrev,\n r = 0,\n d,\n t,\n i,\n x;\n while (b.isEven()) (b = b.divide(2)), r++;\n next: for (i = 0; i < a.length; i++) {\n if (n.lesser(a[i])) continue;\n x = bigInt(a[i]).modPow(b, n);\n if (x.isUnit() || x.equals(nPrev)) continue;\n for (d = r - 1; d != 0; d--) {\n x = x.square().mod(n);\n if (x.isUnit()) return false;\n if (x.equals(nPrev)) continue next;\n }\n return false;\n }\n return true;\n }\n\n // Set \"strict\" to true to force GRH-supported lower bound of 2*log(N)^2\n BigInteger.prototype.isPrime = function(strict) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var bits = n.bitLength();\n if (bits <= 64)\n return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);\n var logN = Math.log(2) * bits.toJSNumber();\n var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN);\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt(i + 2));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime =\n BigInteger.prototype.isPrime;\n\n BigInteger.prototype.isProbablePrime = function(iterations) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var t = iterations === undefined ? 5 : iterations;\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt.randBetween(2, n.minus(2)));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime =\n BigInteger.prototype.isProbablePrime;\n\n BigInteger.prototype.modInv = function(n) {\n var t = bigInt.zero,\n newT = bigInt.one,\n r = parseValue(n),\n newR = this.abs(),\n q,\n lastT,\n lastR;\n while (!newR.isZero()) {\n q = r.divide(newR);\n lastT = t;\n lastR = r;\n t = newT;\n r = newR;\n newT = lastT.subtract(q.multiply(newT));\n newR = lastR.subtract(q.multiply(newR));\n }\n if (!r.isUnit())\n throw new Error(\n this.toString() + ' and ' + n.toString() + ' are not co-prime'\n );\n if (t.compare(0) === -1) {\n t = t.add(n);\n }\n if (this.isNegative()) {\n return t.negate();\n }\n return t;\n };\n\n NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv =\n BigInteger.prototype.modInv;\n\n BigInteger.prototype.next = function() {\n var value = this.value;\n if (this.sign) {\n return subtractSmall(value, 1, this.sign);\n }\n return new BigInteger(addSmall(value, 1), this.sign);\n };\n SmallInteger.prototype.next = function() {\n var value = this.value;\n if (value + 1 < MAX_INT) return new SmallInteger(value + 1);\n return new BigInteger(MAX_INT_ARR, false);\n };\n NativeBigInt.prototype.next = function() {\n return new NativeBigInt(this.value + BigInt(1));\n };\n\n BigInteger.prototype.prev = function() {\n var value = this.value;\n if (this.sign) {\n return new BigInteger(addSmall(value, 1), true);\n }\n return subtractSmall(value, 1, this.sign);\n };\n SmallInteger.prototype.prev = function() {\n var value = this.value;\n if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);\n return new BigInteger(MAX_INT_ARR, true);\n };\n NativeBigInt.prototype.prev = function() {\n return new NativeBigInt(this.value - BigInt(1));\n };\n\n var powersOfTwo = [1];\n while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE)\n powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);\n var powers2Length = powersOfTwo.length,\n highestPower2 = powersOfTwo[powers2Length - 1];\n\n function shift_isSmall(n) {\n return Math.abs(n) <= BASE;\n }\n\n BigInteger.prototype.shiftLeft = function(v) {\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + ' is too large for shifting.');\n }\n if (n < 0) return this.shiftRight(-n);\n var result = this;\n if (result.isZero()) return result;\n while (n >= powers2Length) {\n result = result.multiply(highestPower2);\n n -= powers2Length - 1;\n }\n return result.multiply(powersOfTwo[n]);\n };\n NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft =\n BigInteger.prototype.shiftLeft;\n\n BigInteger.prototype.shiftRight = function(v) {\n var remQuo;\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + ' is too large for shifting.');\n }\n if (n < 0) return this.shiftLeft(-n);\n var result = this;\n while (n >= powers2Length) {\n if (result.isZero() || (result.isNegative() && result.isUnit()))\n return result;\n remQuo = divModAny(result, highestPower2);\n result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n n -= powers2Length - 1;\n }\n remQuo = divModAny(result, powersOfTwo[n]);\n return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n };\n NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight =\n BigInteger.prototype.shiftRight;\n\n function bitwise(x, y, fn) {\n y = parseValue(y);\n var xSign = x.isNegative(),\n ySign = y.isNegative();\n var xRem = xSign ? x.not() : x,\n yRem = ySign ? y.not() : y;\n var xDigit = 0,\n yDigit = 0;\n var xDivMod = null,\n yDivMod = null;\n var result = [];\n while (!xRem.isZero() || !yRem.isZero()) {\n xDivMod = divModAny(xRem, highestPower2);\n xDigit = xDivMod[1].toJSNumber();\n if (xSign) {\n xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers\n }\n\n yDivMod = divModAny(yRem, highestPower2);\n yDigit = yDivMod[1].toJSNumber();\n if (ySign) {\n yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers\n }\n\n xRem = xDivMod[0];\n yRem = yDivMod[0];\n result.push(fn(xDigit, yDigit));\n }\n var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);\n for (var i = result.length - 1; i >= 0; i -= 1) {\n sum = sum.multiply(highestPower2).add(bigInt(result[i]));\n }\n return sum;\n }\n\n BigInteger.prototype.not = function() {\n return this.negate().prev();\n };\n NativeBigInt.prototype.not = SmallInteger.prototype.not =\n BigInteger.prototype.not;\n\n BigInteger.prototype.and = function(n) {\n return bitwise(this, n, function(a, b) {\n return a & b;\n });\n };\n NativeBigInt.prototype.and = SmallInteger.prototype.and =\n BigInteger.prototype.and;\n\n BigInteger.prototype.or = function(n) {\n return bitwise(this, n, function(a, b) {\n return a | b;\n });\n };\n NativeBigInt.prototype.or = SmallInteger.prototype.or =\n BigInteger.prototype.or;\n\n BigInteger.prototype.xor = function(n) {\n return bitwise(this, n, function(a, b) {\n return a ^ b;\n });\n };\n NativeBigInt.prototype.xor = SmallInteger.prototype.xor =\n BigInteger.prototype.xor;\n\n var LOBMASK_I = 1 << 30,\n LOBMASK_BI = ((BASE & -BASE) * (BASE & -BASE)) | LOBMASK_I;\n function roughLOB(n) {\n // get lowestOneBit (rough)\n // SmallInteger: return Min(lowestOneBit(n), 1 << 30)\n // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]\n var v = n.value,\n x =\n typeof v === 'number'\n ? v | LOBMASK_I\n : typeof v === 'bigint'\n ? v | BigInt(LOBMASK_I)\n : (v[0] + v[1] * BASE) | LOBMASK_BI;\n return x & -x;\n }\n\n function integerLogarithm(value, base) {\n if (base.compareTo(value) <= 0) {\n var tmp = integerLogarithm(value, base.square(base));\n var p = tmp.p;\n var e = tmp.e;\n var t = p.multiply(base);\n return t.compareTo(value) <= 0\n ? { p: t, e: e * 2 + 1 }\n : { p: p, e: e * 2 };\n }\n return { p: bigInt(1), e: 0 };\n }\n\n BigInteger.prototype.bitLength = function() {\n var n = this;\n if (n.compareTo(bigInt(0)) < 0) {\n n = n.negate().subtract(bigInt(1));\n }\n if (n.compareTo(bigInt(0)) === 0) {\n return bigInt(0);\n }\n return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));\n };\n NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength =\n BigInteger.prototype.bitLength;\n\n function max(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.greater(b) ? a : b;\n }\n function min(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.lesser(b) ? a : b;\n }\n function gcd(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n if (a.equals(b)) return a;\n if (a.isZero()) return b;\n if (b.isZero()) return a;\n var c = Integer[1],\n d,\n t;\n while (a.isEven() && b.isEven()) {\n d = min(roughLOB(a), roughLOB(b));\n a = a.divide(d);\n b = b.divide(d);\n c = c.multiply(d);\n }\n while (a.isEven()) {\n a = a.divide(roughLOB(a));\n }\n do {\n while (b.isEven()) {\n b = b.divide(roughLOB(b));\n }\n if (a.greater(b)) {\n t = b;\n b = a;\n a = t;\n }\n b = b.subtract(a);\n } while (!b.isZero());\n return c.isUnit() ? a : a.multiply(c);\n }\n function lcm(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n return a.divide(gcd(a, b)).multiply(b);\n }\n function randBetween(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n var low = min(a, b),\n high = max(a, b);\n var range = high.subtract(low).add(1);\n if (range.isSmall) return low.add(Math.floor(Math.random() * range));\n var digits = toBase(range, BASE).value;\n var result = [],\n restricted = true;\n for (var i = 0; i < digits.length; i++) {\n var top = restricted ? digits[i] : BASE;\n var digit = truncate(Math.random() * top);\n result.push(digit);\n if (digit < top) restricted = false;\n }\n return low.add(Integer.fromArray(result, BASE, false));\n }\n\n var parseBase = function(text, base, alphabet, caseSensitive) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n text = String(text);\n if (!caseSensitive) {\n text = text.toLowerCase();\n alphabet = alphabet.toLowerCase();\n }\n var length = text.length;\n var i;\n var absBase = Math.abs(base);\n var alphabetValues = {};\n for (i = 0; i < alphabet.length; i++) {\n alphabetValues[alphabet[i]] = i;\n }\n for (i = 0; i < length; i++) {\n var c = text[i];\n if (c === '-') continue;\n if (c in alphabetValues) {\n if (alphabetValues[c] >= absBase) {\n if (c === '1' && absBase === 1) continue;\n throw new Error(c + ' is not a valid digit in base ' + base + '.');\n }\n }\n }\n base = parseValue(base);\n var digits = [];\n var isNegative = text[0] === '-';\n for (i = isNegative ? 1 : 0; i < text.length; i++) {\n var c = text[i];\n if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));\n else if (c === '<') {\n var start = i;\n do {\n i++;\n } while (text[i] !== '>' && i < text.length);\n digits.push(parseValue(text.slice(start + 1, i)));\n } else throw new Error(c + ' is not a valid character');\n }\n return parseBaseFromArray(digits, base, isNegative);\n };\n\n function parseBaseFromArray(digits, base, isNegative) {\n var val = Integer[0],\n pow = Integer[1],\n i;\n for (i = digits.length - 1; i >= 0; i--) {\n val = val.add(digits[i].times(pow));\n pow = pow.times(base);\n }\n return isNegative ? val.negate() : val;\n }\n\n function stringify(digit, alphabet) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n if (digit < alphabet.length) {\n return alphabet[digit];\n }\n return '<' + digit + '>';\n }\n\n function toBase(n, base) {\n base = bigInt(base);\n if (base.isZero()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n throw new Error('Cannot convert nonzero numbers to base 0.');\n }\n if (base.equals(-1)) {\n if (n.isZero()) return { value: [0], isNegative: false };\n if (n.isNegative())\n return {\n value: [].concat.apply(\n [],\n Array.apply(null, Array(-n.toJSNumber())).map(\n Array.prototype.valueOf,\n [1, 0]\n )\n ),\n isNegative: false,\n };\n\n var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(\n Array.prototype.valueOf,\n [0, 1]\n );\n arr.unshift([1]);\n return {\n value: [].concat.apply([], arr),\n isNegative: false,\n };\n }\n\n var neg = false;\n if (n.isNegative() && base.isPositive()) {\n neg = true;\n n = n.abs();\n }\n if (base.isUnit()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n\n return {\n value: Array.apply(null, Array(n.toJSNumber())).map(\n Number.prototype.valueOf,\n 1\n ),\n isNegative: neg,\n };\n }\n var out = [];\n var left = n,\n divmod;\n while (left.isNegative() || left.compareAbs(base) >= 0) {\n divmod = left.divmod(base);\n left = divmod.quotient;\n var digit = divmod.remainder;\n if (digit.isNegative()) {\n digit = base.minus(digit).abs();\n left = left.next();\n }\n out.push(digit.toJSNumber());\n }\n out.push(left.toJSNumber());\n return { value: out.reverse(), isNegative: neg };\n }\n\n function toBaseString(n, base, alphabet) {\n var arr = toBase(n, base);\n return (\n (arr.isNegative ? '-' : '') +\n arr.value\n .map(function(x) {\n return stringify(x, alphabet);\n })\n .join('')\n );\n }\n\n BigInteger.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n SmallInteger.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n NativeBigInt.prototype.toArray = function(radix) {\n return toBase(this, radix);\n };\n\n BigInteger.prototype.toString = function(radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix !== 10) return toBaseString(this, radix, alphabet);\n var v = this.value,\n l = v.length,\n str = String(v[--l]),\n zeros = '0000000',\n digit;\n while (--l >= 0) {\n digit = String(v[l]);\n str += zeros.slice(digit.length) + digit;\n }\n var sign = this.sign ? '-' : '';\n return sign + str;\n };\n\n SmallInteger.prototype.toString = function(radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix != 10) return toBaseString(this, radix, alphabet);\n return String(this.value);\n };\n\n NativeBigInt.prototype.toString = SmallInteger.prototype.toString;\n\n NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function() {\n return this.toString();\n };\n\n BigInteger.prototype.valueOf = function() {\n return parseInt(this.toString(), 10);\n };\n BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;\n\n SmallInteger.prototype.valueOf = function() {\n return this.value;\n };\n SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;\n NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function() {\n return parseInt(this.toString(), 10);\n };\n\n function parseStringValue(v) {\n if (isPrecise(+v)) {\n var x = +v;\n if (x === truncate(x))\n return supportsNativeBigInt\n ? new NativeBigInt(BigInt(x))\n : new SmallInteger(x);\n throw new Error('Invalid integer: ' + v);\n }\n var sign = v[0] === '-';\n if (sign) v = v.slice(1);\n var split = v.split(/e/i);\n if (split.length > 2)\n throw new Error('Invalid integer: ' + split.join('e'));\n if (split.length === 2) {\n var exp = split[1];\n if (exp[0] === '+') exp = exp.slice(1);\n exp = +exp;\n if (exp !== truncate(exp) || !isPrecise(exp))\n throw new Error(\n 'Invalid integer: ' + exp + ' is not a valid exponent.'\n );\n var text = split[0];\n var decimalPlace = text.indexOf('.');\n if (decimalPlace >= 0) {\n exp -= text.length - decimalPlace - 1;\n text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);\n }\n if (exp < 0)\n throw new Error('Cannot include negative exponent part for integers');\n text += new Array(exp + 1).join('0');\n v = text;\n }\n var isValid = /^([0-9][0-9]*)$/.test(v);\n if (!isValid) throw new Error('Invalid integer: ' + v);\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(sign ? '-' + v : v));\n }\n var r = [],\n max = v.length,\n l = LOG_BASE,\n min = max - l;\n while (max > 0) {\n r.push(+v.slice(min, max));\n min -= l;\n if (min < 0) min = 0;\n max -= l;\n }\n trim(r);\n return new BigInteger(r, sign);\n }\n\n function parseNumberValue(v) {\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(v));\n }\n if (isPrecise(v)) {\n if (v !== truncate(v)) throw new Error(v + ' is not an integer.');\n return new SmallInteger(v);\n }\n return parseStringValue(v.toString());\n }\n\n function parseValue(v) {\n if (typeof v === 'number') {\n return parseNumberValue(v);\n }\n if (typeof v === 'string') {\n return parseStringValue(v);\n }\n if (typeof v === 'bigint') {\n return new NativeBigInt(v);\n }\n return v;\n }\n // Pre-define numbers in range [-999,999]\n for (var i = 0; i < 1000; i++) {\n Integer[i] = parseValue(i);\n if (i > 0) Integer[-i] = parseValue(-i);\n }\n // Backwards compatibility\n Integer.one = Integer[1];\n Integer.zero = Integer[0];\n Integer.minusOne = Integer[-1];\n Integer.max = max;\n Integer.min = min;\n Integer.gcd = gcd;\n Integer.lcm = lcm;\n Integer.isInstance = function(x) {\n return (\n x instanceof BigInteger ||\n x instanceof SmallInteger ||\n x instanceof NativeBigInt\n );\n };\n Integer.randBetween = randBetween;\n\n Integer.fromArray = function(digits, base, isNegative) {\n return parseBaseFromArray(\n digits.map(parseValue),\n parseValue(base || 10),\n isNegative\n );\n };\n\n return Integer;\n})();\n\n// Node.js check\nif (typeof module !== 'undefined' && module.hasOwnProperty('exports')) {\n module.exports = bigInt;\n}\n\n//amd check\nif (typeof define === 'function' && define.amd) {\n define('big-integer', [], function() {\n return bigInt;\n });\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\n\nvar input = ``;\n\nfunction cacheInput(data) {\n input += data;\n}\n\nfunction main() {\n let lines = input.split('\\r\\n');\n let n = parseInt(lines[0]);\n for (var i = 1; i <= n; i++) {\n let steps = bigInt(0);\n let input = lines[i].split(' ');\n let n = bigInt(input[0]);\n let k = bigInt(input[1]);\n while (n.value) {\n let mod = bigInt(n).mod(bigInt(k));\n if (mod.value === 0) {\n n = bigInt(n).divide(bigInt(k));\n steps = bigInt(steps).add(1);\n } else {\n n = bigInt(n).minus(bigInt(mod));\n steps = bigInt(steps).add(bigInt(mod));\n }\n }\n console.log(steps.toString());\n }\n}\n\nprocess.stdin.on('data', cacheInput).on('end', main);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [n, k] = d.split(' ').map(BigInt);\n let curr = 0n;\n\n while (n > 0n) {\n let reminder = n % k;\n if (reminder === 0n) {\n n /= k;\n curr++;\n }\n else {\n curr += reminder;\n n -= reminder;\n }\n }\n\n ans += `${curr.toString()}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}], "negative_code": [], "src_uid": "00b1e45e9395d23e850ce1a0751b8378"} {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n var n = Number(read());\n write(n % 4 ? 'NO' : 'YES');\n }\n}\n \n \nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}", "positive_code": [{"source_code": "var data = '';\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', (buffer) =>\n{\n data += buffer;\n});\n\nprocess.stdin.on('end', () =>\n{\n var x = data.split(/\\s+/);\n for (var i = 1; i <= x[0]; i++)\n console.log(x[i] % 4 ? 'NO' : 'YES');\n})"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n let tests = parseInt(lines.shift(), 10);\n while (tests--) {\n const n = parseInt(lines.shift(), 10);\n console.log(n % 4 ? 'NO' : 'YES');\n }\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(element => parseInt(element, 10));\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet t=inputReader.readNumber();\n\twhile(t--){\n\t let n=inputReader.readNumber();\n\t if(n%4==0){\n\t console.log('YES'); \n\t \n\t }else{\n\t console.log(\"NO\");\n\t }\n\t}\n\t\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumber(){\n\t\treturn Number(_inputLines[_lineNumber++]);\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t}\n}"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n var n = BigInt(read());\n write(n % 4n === 0n ? 'YES' : 'NO');\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "\"use strict\";\n\nlet t = readline();\n\nfor(let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let n = readline();\n while(n--){\n let x = readline();\n x%4 === 0 ? console.log('YES') : console.log('NO');\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nwhile(t--){\n var n = parseInt(readline());\n \n if (n % 4 == 0)\n print(\"YES\");\n else\n print(\"NO\");\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n let side = 0\n \n for (let i = 0; i < t; i++) {\n side = readLine()\n side = parseInt(side)\n \n if (side % 4 === 0) console.log(\"YES\")\n else console.log(\"NO\")\n }\n}\n\n\n"}, {"source_code": "var Tc = parseInt(readline());\nwhile (Tc-- > 0) {\n\tvar n = parseInt(readline());\n\tprint(n % 4 == 0 ? 'YES' : 'NO');\n}\n"}, {"source_code": "var t = Number(readline());\nwhile (t--) {\n var n = Number(readline());\n print(n % 4 == 0 ? 'YES' : 'NO');\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n if (num % 4 === 0) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tif(N % 4 == 0){\n\t\t\toutput[i] = \"YES\";\n\t\t}else{\n\t\t\toutput[i] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n if (num % 2 === 0 && num >= 4) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let num = +readLine();\n if (num % 2 === 0) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n let side = 0\n for (let i = 0; i < t; i++) {\n side = readLine()\n side = parseInt(side)\n if (side <= 3 || side === 5 || side === 6) console.log(\"NO\")\n else console.log(\"YES\")\n }\n \n}"}], "src_uid": "07e56d4031bcb119d2f684203f7ed133"} {"source_code": "var n = Number(readline());\nvar a = readline().split(\" \").map(function(each) {return Number(each);});\n\nvar count = 0;\nfor (var i = 1; i < a.length - 1; ++i) {\n if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i] < a[i - 1] && a[i] < a[i + 1]))\n ++count;\n}\n\nprint(count);", "positive_code": [{"source_code": "function readArr()\n{\n return readline().split(' ').map(function(x){return +x;})\n}\n\nn=+readline()\na=readArr()\nkol=0\nfor (i=1;ia[i-1]&&a[i]>a[i+1])kol++;\n if (a[i] list[i + 1] && list[i] > list[i - 1]){\n output++;\n }\n }\n myout(output);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n\n for (let i = 1; i < arr.length - 1; i++) {\n if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {\n ans++;\n }\n\n if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "\nfunction readPrefixedIntList() {\n var n = parseInt(readline());\n var r = readline().split(' ').map(function (f) {\n return parseInt(f, 10);\n });\n return r;\n}\n\n var numbers = readPrefixedIntList();\n\n var n = 0;\n for (var i = 1; i < numbers.length - 1; i++) {\n var sign1 = Math.sign(numbers[i - 1] - numbers[i]);\n var sign2 = Math.sign(numbers[i + 1] - numbers[i]);\n if (sign1 !== 0 && sign1 === sign2) n++;\n }\n\n print(n.toString());\n"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = toInt(readline());\nvar ar = readline().split(' ').map(toInt);\nvar res = 0;\n\nfor (var i = 1; i < ar.length-1; i++) {\n\tif ((ar[i] < ar[i-1] && ar[i] < ar[i+1]) || (ar[i] > ar[i-1] && ar[i] > ar[i+1])) {\n\t\tres++;\n\t}\n}\n\nprint(res);"}, {"source_code": "n = readline();\nstr = readline().split(' ').map(Number);\n\nvar count = 0;\n\nfor (var i = 1; i < str.length - 1; i++) {\n\tif ((str[i] > str[i - 1] && str[i] > str[i + 1]) || (str[i] < str[i - 1] && str[i] < str[i + 1])) {\n\t\tcount++;\n\t};\n};\n\nprint(count);"}], "negative_code": [{"source_code": "var n = Number(readline());\nvar a = readline().split(\" \").map(function(each) {return Number(each);});\n\nvar count = 0;\nfor (var i = 1; i < a.length - 1; ++i) {\n if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i] < a[i - 1] && a[i] < a[i - 1]))\n ++count;\n}\n\nprint(count);"}], "src_uid": "67cf9f83ed791a614bd01c5e0310813f"} {"source_code": "/**\n * Created by artyom.\n */\n\nvar a = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n n = a[0], k = a[1], i, sum = 0, t, size = 26,\n s = readline(),\n g = Array.apply(null, new Array(size)).map(Number.prototype.valueOf, 0);\n\nfor (i = 0; i < n; i++) {\n g[s.charCodeAt(i) - 65]++;\n}\ng.sort(function (a, b) {\n return a - b;\n});\nfor (i = size - 1; i >= 0 && k > 0; i--) {\n t = Math.min(g[i], k);\n sum += t * t;\n k -= t;\n}\n\nprint(sum);", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\tcards = trim(readline()),\n\t\tcounts = {};\n\tfor (var i = 65; i <= 90; ++i) {\n\t\tcounts[String.fromCharCode(i)] = 0;\n\t}\n\tfor (var i = 0; i < n; ++i) {\n\t\tcounts[cards.charAt(i)] += 1;\n\t}\n\tvar pairs = [];\n\tfor (var i = 65; i <= 90; ++i) {\n\t\tvar ch = String.fromCharCode(i);\n\t\tpairs.push([ch, counts[ch]]);\n\t}\n\tpairs.sort(function (a, b) {\n\t\treturn a[1] - b[1];\n\t});\n\tvar score = 0, pos = 25;\n\twhile (k != 0 && pos != -1) {\n\t\tvar count = Math.min(k, pairs[pos][1]);\n\t\tk -= count;\n\t\tscore += count*count;\n\t\t--pos;\n\t}\n\tprint(score);\n}\n\nmain();\n"}, {"source_code": "var input = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/).map(Number),\n\t\t\tn = input[0], k = input[1],\n\t\t\taCards = readline().split(''),\n\t\t\tprevCard = '', count = 0, rs = [], sum = 0, ts = {};\n\n\t\taCards.forEach(function(a, i)\t{\n\t\t\tvar tsCount = ts[a] == undefined ? 0 : ts[a];\n\n\t\t\tts[a] = tsCount + 1;\n\t\t});\n\n\t\tObject.keys(ts).forEach(function(c, i)\t{ rs.push(ts[c]); });\n\n\t\trs.sort(function(a, b){return b-a});\n\n\t\tfor(var i=0; i= k)\t{\n\t\t\t\tcount -= c;\n\n\t\t\t\tsum += Math.pow(k - count, 2);\n\n\t\t\t\tbreak;\n\t\t\t} else\t{\n\t\t\t\tsum += Math.pow(c, 2);\n\t\t\t}\n\t\t}\n\n\t\tprint(sum);"}, {"source_code": "function gao()\n{\n var numbers = readline().split(' ');\n\tvar str = readline();\n\tvar n = numbers[0];\n\tvar k = numbers[1];\n var alphbet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\tvar amounts = new Array(26);\n\tfor( var i = 0; i< alphbet.length; i++)\n\t{\n\t var c = alphbet.charAt(i);\n\t var reg = new RegExp( c, 'g' );\n\t var result = str.match(reg);\n\t\tif(result != null )\n\t\t{\n\t amounts[i] = result.length;\n\t\t}\n\t}\n\t\n\tamounts.sort(sortNum);\n\t\n\tvar ans = 0;\n\tfor( var i=0;i 0) {\n s += Math.pow(Math.min(m[q[i]], k), 2);\n k -= m[q[i++]];\n }\n\n print(s);\n\n}.call(this));\n"}], "negative_code": [{"source_code": "var input = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/).map(Number),\n\t\t\tn = input[0], k = input[1],\n\t\t\taCards = readline().split('').sort(),\n\t\t\tprevCard = '', count = 1, rs = [], sum = 0;\n\n\t\tfor(var i=0; i= 0 && k > 0; i--) {\n t = Math.min(g[i], k);\n sum += t * t;\n k -= t;\n}\n\nprint(sum);"}], "src_uid": "480defc596ee5bc800ea569fd76dc584"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n1 1 1 2 1 1\n6\n+ 2\n+ 1\n- 1\n+ 2\n- 1\n+ 2\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n //console.log(\"Cases\",cases);\n for(var i=1;i<=cases;i++){\n //console.log(\"case \",i);\n var line2 = readline();\n var dims = line2.split(\" \");\n var row = parseInt(dims[0]);\n var col = parseInt(dims[1]);\n \n var arr = [];\n for(var p=0;p {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [row, col] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let i = 0;\n let count = 0;\n const store = [];\n while (i < row) {\n const r = readLine().split(\"\");\n store.push(r);\n if (r[col - 1] === \"R\") count++;\n i++;\n }\n for (let i = 0; i < col; i++) {\n if (store[row - 1][i] === \"D\") count++;\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar one = nextIntArray();\n \tvar N = one[0];\n \tvar M = one[1];\n \tvar list = new Array(N);\n \tfor(var j = 0; j < N; j++){\n \t\tlist[j] = nextCharArray();\n \t}\n \tvar count = 0;\n \tfor(var j = 0; j < N - 1; j++){\n \t\tif(list[j][M - 1] == \"R\"){\n \t\t\tcount++;\n \t\t}\n \t}\n \tfor(var j = 0; j < M; j++){\n \t\tif(list[N - 1][j] == \"D\"){\n \t\t\tcount++;\n \t\t}\n \t}\n \toutput[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\tlet r = 1;\n\twhile (i <= testCases) {\n let num = data[r].trim().split(' ').map(Number);\n let n = num[0] * 1;\n let m = r + 1;\n r += n + 1;\n let count = 0;\n let arr = [];\n for (let j = m; j < r; j += 1) arr.push(data[j].trim());\n if (n === 1) {\n for (let j = 0; j < arr[0].length; j += 1) {\n if (arr[0][j] === 'D') count += 1;\n }\n } else {\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j][arr[j].length - 1] === 'R') count += 1;\n }\n for (let j = 0; j < arr[arr.length - 1].length - 1; j += 1) {\n if (arr[arr.length - 1][j] === 'D') count += 1;\n }\n }\n console.log(count);\n i += 1;\n\t}\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const [n, m] = readLine().split(/\\s/).map(Number)\n let result = 0;\n for (let r = 0; r < n; r++) {\n const row = readLine()\n if (r === n - 1) {\n for (let c = 0; c < m - 1; c++) {\n if (row[c] === 'D') {\n result += 1\n }\n }\n } else if (row[m - 1] === 'R') {\n result += 1\n }\n }\n console.log(result)\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet [n, m] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tlet arr = [],\n\t\t\tc = 0;\n\n\t\tfor (let i = 0; i < n; ++i) {\n\t\t\tlet l = readLine().split('');\n\t\t\tarr.push(l);\n\t\t\tif (arr[i][m - 1] === 'R') c++;\n\t\t\tif (i === n - 1) {\n\t\t\t\tfor (let j = 0; j < m - 1; j++) if (arr[n - 1][j] === 'D') c++;\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(c);\n\t}\n}\n"}], "negative_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n //console.log(\"Cases\",cases);\n for(var i=1;i<=cases;i++){\n //console.log(\"case \",i);\n var line2 = readline();\n var dims = line2.split(\" \");\n var row = parseInt(dims[0]);\n var col = parseInt(dims[1]);\n \n var arr = [];\n for(var p=0;p0){\n var leftElem = arr[row][col-1];\n if(leftElem == \"R\"){\n minValFromLeft = dp[row][col-1];\n }\n else{\n minValFromLeft = 1+dp[row][col-1];\n }\n }\n if(row>0){\n var topElem = arr[row-1][col];\n if(topElem == \"D\"){\n minValFromTop = dp[row-1][col];\n }\n else{\n minValFromTop = 1+dp[row-1][col];\n }\n }\n dp[row][col] = Math.min(minValFromLeft,minValFromTop);\n }\n }\n\n return dp[arr.length-1][cleng-1];\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n console.log(\"Cases\",cases);\n for(var i=1;i<=cases;i++){\n //console.log(\"case \",i);\n var line2 = readline();\n var dims = line2.split(\" \");\n var row = parseInt(dims[0]);\n var col = parseInt(dims[1]);\n \n var arr = [];\n for(var p=0;p0){\n var leftElem = arr[row][col-1];\n if(leftElem == \"R\"){\n minValFromLeft = dp[row][col-1];\n }\n else{\n minValFromLeft = 1+dp[row][col-1];\n }\n }\n if(row>0){\n var topElem = arr[row-1][col];\n if(topElem == \"D\"){\n minValFromTop = dp[row-1][col];\n }\n else{\n minValFromTop = 1+dp[row-1][col];\n }\n }\n dp[row][col] = Math.min(minValFromLeft,minValFromTop);\n }\n }\n\n return dp[arr.length-1][cleng-1];\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet [n, m] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tlet arr = [];\n\t\tfor (let i = 0; i < n; i++) arr[i] = readLine().split('');\n\t\tlet c = 0;\n\t\tfor (let i = 0; i < m - 1; ++i) if (arr[0][i] !== 'R') c++;\n\t\tif (arr[0][m - 1] === 'R') c++;\n\t\tfor (let i = 1; i < n - 1; ++i) if (arr[i][m - 1] !== 'D') c++;\n\n\t\tconsole.log(c);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet [n, m] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tlet arr = [];\n\t\tfor (let i = 0; i < n; i++) arr[i] = readLine().split('');\n\n\t\tlet c = 0;\n\t\tfor (let i = 0; i < n - 1; ++i)\n\t\t\tif (arr[i][m - 1] !== 'D') {\n\t\t\t\tc++;\n\t\t\t\tarr[i][m - 1] = 'D';\n\t\t\t}\n\n\t\tfor (let x = 0; x < m - 1; x++) {\n\t\t\tif (arr[0][x] === 'R') continue;\n\t\t\tlet i = 0,\n\t\t\t\tj = x;\n\t\t\twhile (i < n && j < m) {\n\t\t\t\tif (arr[i][j] === 'R') j++;\n\t\t\t\telse i++;\n\t\t\t}\n\t\t\tif (i !== n || j !== m) {\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(c);\n\t}\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n1 1 1 2 1 1\n6\n+ 2\n+ 1\n- 1\n+ 2\n- 1\n+ 2\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n return parseInt(elem, 10);\n});\nvar res = 1;\nvar max = 0;\nfor (var i = 0; i < arr.length - 1; i++) {\n if (arr[i+1] <= arr[i]) {\n if (res > max) {\n max = res;\n }\n res = 1;\n } else {\n res++;\n }\n}\nif (res > max) {\n max = res;\n}\nprint(max);", "positive_code": [{"source_code": "var n = readline();\n\nvar a = readline().split(' ');\n\nvar b = [];\n\nfor (var i = 0; i < a.length; i++) {\n a[i] = Number(a[i]);\n}\n\nvar cur = 1;\nvar ans = 1;\n\nfor (var i = 1; i < a.length; i++) {\n a[i] = Number(a[i]);\n if (a[i] > a[i - 1]) {\n cur = cur + 1;\n }\n else {\n cur = 1; \n }\n ans = Math.max(cur, ans);\n}\n\nprint(ans);"}, {"source_code": "//var array = readline().split(\" \").map(item => +item);\nreadline();\nvar line = readline().split(\" \").map(item => +item);\nvar max = 1;\n\nif(line.length > 1) {\n var prev = line[0],\n count = 1;\n\n for(var i = 1; i < line.length; i++) {\n if (prev < line[i]) {\n count++;\n max = Math.max(max, count);\n } else {\n count = 1;\n }\n prev = line[i];\n }\n print(max);\n} else {\n print(1);\n}\n\n//print((i - 1).toString());"}, {"source_code": "'use strict';\n\n// const rlLib = require('readline');\n\n// const rl = rlLib.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// let inputs = [];\n// let allCount = 2;\n// let currentLine = 0;\n\n// rl.on('line', (input) => {\n// inputs.push(input);\n// if (inputs.length >= allCount) {\n// main();\n\n// rl.close(); \n// }\n// });\n\n// function readline() {\n// return inputs[currentLine++];\n// }\n// function print() {\n// console.log.apply(this, arguments);\n// }\n\n\n// // function main() {\n// // let count = +readline();\n// // let arr = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n// // print(func(arr));\n// // }\n\n\n// /**\n// * @param {number} s\n// * @param {number[]} nums\n// * @return {number}\n// */\n// function main() {\n readline();\n let arr = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n let res = 0;\n\n for (var i = 1, count = 1; i < arr.length; i++) {\n if (arr[i] <= arr[i - 1]) {\n if (res < count) {\n res = count;\n }\n count = 1;\n } else {\n count++;\n }\n }\n\n print(count > res ? count : res);\n// };\n\n\n"}, {"source_code": "function main() {\n readline();\n var data = readline().split(' ').map(Number);\n var res = 1;\n var current = 1;\n for(var i=1;idata[i-1]){\n current++;\n } else {\n current = 1;\n }\n if(current>res){\n res = current;\n }\n }\n print(res)\n}\n\n\n\n\nmain()"}, {"source_code": "'use strict';\n\nfunction findMax(n, arr) {\n let maxLen = 1;\n let currentLen = 1;\n\n for (let i=1; i arr[i-1]) {\n currentLen++;\n if (currentLen > maxLen) {\n maxLen = currentLen;\n }\n } else {\n currentLen = 1;\n }\n }\n return maxLen;\n}\n\nprint(findMax(parseInt(readline()), readline().split(' ').map(x=>parseInt(x))));\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var output = 1;\n var count = 1;\n for(var i = 1; i < N; i++){\n if(list[i - 1] < list[i]){\n count++;\n }else{\n output = Math.max(count, output);\n count = 1;\n }\n }\n output = Math.max(count, output);\n myout(output);\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `5\n// 1 7 2 11 15`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n const sequence = readLine(stdin, 1);\n const sequenceArray = sequence.split(\" \").map(n => Number(n));\n let arrays = [];\n let i = 1;\n let prev = 0;\n while (sequenceArray[i]) {\n const curr = sequenceArray[i - 1];\n const next = sequenceArray[i];\n\n if (curr >= next) {\n arrays.push(sequenceArray.slice(prev, i));\n prev = i;\n }\n\n i++;\n\n if (!sequenceArray[i]) {\n arrays.push(sequenceArray.slice(prev, i));\n }\n }\n\n // console.log(arrays);\n console.log(\n arrays.reduce((acc, el) => {\n return el.length > acc ? el.length : acc;\n }, 1)\n );\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "//var n = 3;\nvar n = parseInt(readline());\n//var a = [1, 2, 3];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nif (n == 1) {\n write(\"1\");\n}\nelse\n{\n var t = 1;\n var max = -1;\n\n for (var i = 1; i< n; ++i) {\n if (a[i - 1] < a[i]) {\n ++t;\n } else {\n if (t > max) {\n max = t;\n }\n t = 1;\n }\n }\n\n if (t > max) {\n max = t;\n }\n\n write(max);\n}\n\n//function write(n) {\n// console.log(n);\n//}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let best = 1;\n let curr = 1;\n let v = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] > v) {\n curr++;\n }\n else {\n curr = 1;\n }\n\n best = Math.max(curr, best);\n v = arr[i];\n }\n\n console.log(best);\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet switcher = false;\n\nrl.on('line', function(line){\n if (switcher) {\n let arr = line.split(' ').map(el => +el);\n console.log(findMaxLength(arr));\n }\n switcher = !switcher;\n});\n\nconst findMaxLength = arr => {\n let maxLength = 1;\n let tmpMax = 1;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] < arr[i]) {\n tmpMax++;\n } else {\n if (tmpMax > maxLength) maxLength = tmpMax;\n tmpMax = 1;\n }\n }\n if (tmpMax > maxLength) maxLength = tmpMax;\n return maxLength;\n}"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\n\nfor (var i = 0; i < a.length; i++) {\n\ta[i] = Number(a[i])\n}\nvar count = 1;\n\nvar ans = 1;\nfor (var i = 0; i < a.length - 1; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++;\n\t} else {\n\t\tcount = 1;\n\t}\n\tans = Math.max(ans, count);\n}\n\nprint(ans);\n// console.log(ans)"}, {"source_code": "readline = require('readline');\nrl = readline.createInterface({\n input: process.stdin\n})\n\nlet lineNum = 0;\n\nrl.on('line', (l) => {\n lineNum++\n if (lineNum === 1) {\n return\n }\n arr = l.split(\" \").map(x => parseInt(x));\n // console.log(arr);\n let maxlen = 0;\n let x = 0;\n while (x < arr.length) {\n templen = 1;\n let y = x+1;\n while(y < arr.length && arr[y] > arr[y-1]) {\n templen++\n y++\n }\n if (templen > maxlen) {\n maxlen = templen\n }\n x = y;\n }\n console.log(maxlen)\n rl.close();\n})"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\n\nfor (var i = 0; i < a.length; i++) {\n\ta[i] = Number(a[i])\n}\n\nvar count = 1;\n\nvar len = []\nvar count = 1\n\nfor (var i = 0; i < a.length; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++\n\t} else {\n\t\tlen.push(count)\n\t\tcount = 1\n\t}\n}\n\nlen.sort().reverse()\n\nprint(len[0])\n// console.log(ans)"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar max = 0, cnt = 1;\nfor (var i = 1; i < n; i++) {\n if (a[i - 1] < a[i]) {\n cnt += 1\n } else {\n max = Math.max(max, cnt);\n cnt = 1\n }\n}\nprint(Math.max(max, cnt));"}], "negative_code": [{"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `3\n// 1 7 2 11 15`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n const sequence = readLine(stdin, 1);\n const sequenceArray = sequence.split(\" \").map(n => Number(n));\n let maxSeq = 0;\n let currSeq = 1;\n let i = 1;\n while (sequenceArray[i]) {\n const curr = sequenceArray[i - 1];\n const next = sequenceArray[i];\n\n if (curr < next) {\n currSeq++;\n }\n\n maxSeq = maxSeq < currSeq ? currSeq : maxSeq;\n\n if (curr > next) {\n currSeq = 1;\n }\n\n i++;\n }\n\n console.log(maxSeq);\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `5\n// 1 7 2 11 15`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n const sequence = readLine(stdin, 1);\n const sequenceArray = sequence.split(\" \").map(n => Number(n));\n let arrays = [];\n let i = 1;\n let prev = 0;\n while (sequenceArray[i]) {\n const curr = sequenceArray[i - 1];\n const next = sequenceArray[i];\n\n if (curr >= next) {\n arrays.push(sequenceArray.slice(prev, i));\n prev = i;\n }\n\n i++;\n\n if (!sequenceArray[i]) {\n arrays.push(sequenceArray.slice(prev, i));\n }\n }\n\n // console.log(arrays);\n console.log(\n arrays.reduce((acc, el) => {\n return el.length > acc ? el.length : acc;\n }, 0)\n );\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// const stdin = `5\n// 1 7 2 11 15`;\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n const sequence = readLine(stdin, 1);\n const sequenceArray = sequence.split(\" \").map(n => Number(n));\n let arrays = [];\n let i = 1;\n let prev = 0;\n while (sequenceArray[i]) {\n const curr = sequenceArray[i - 1];\n const next = sequenceArray[i];\n\n if (curr >= next) {\n arrays.push(sequenceArray.slice(prev, i));\n prev = i;\n }\n\n i++;\n\n if (!sequenceArray[i]) {\n arrays.push(sequenceArray.slice(prev, i));\n }\n }\n\n console.log(arrays);\n console.log(\n arrays.reduce((acc, el) => {\n return el.length > acc ? el.length : acc;\n }, 0)\n );\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function(line){\n if (line.length > 1) {\n let arr = line.split(' ');\n console.log(findMaxLength(arr));\n }\n})\n\nconst findMaxLength = arr => {\n let maxLength = 1;\n let tmpMax = 1;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] < arr[i]) {\n tmpMax++;\n } else {\n if (tmpMax > maxLength) maxLength = tmpMax;\n tmpMax = 1;\n }\n }\n if (tmpMax > maxLength) maxLength = tmpMax;\n return maxLength;\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function(line){\n if (line.length > 1) {\n let arr = line.split(' ').map(el => +el);\n console.log(findMaxLength(arr));\n }\n})\n\nconst findMaxLength = arr => {\n let maxLength = 1;\n let tmpMax = 1;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] < arr[i]) {\n tmpMax++;\n } else {\n if (tmpMax > maxLength) maxLength = tmpMax;\n tmpMax = 1;\n }\n }\n if (tmpMax > maxLength) maxLength = tmpMax;\n return maxLength;\n}"}, {"source_code": "readline = require('readline');\nrl = readline.createInterface({\n input: process.stdin\n})\n\nrl.on('line', (l) => {\n arr = l.split(\" \").map(x => parseInt(x));\n // console.log(arr);\n let maxlen = 0;\n let x = 0;\n while (x < arr.length - 1) {\n templen = 1;\n let y = x+1;\n while(y < arr.length && arr[y] > arr[y-1]) {\n templen++\n y++\n }\n if (templen > maxlen) {\n maxlen = templen\n }\n x = y;\n }\n console.log(maxlen)\n rl.close();\n})"}, {"source_code": "readline();\nvar arr = readline().split(' ');\narr = arr.map(elem => {\n return parseInt(elem);\n});\nvar res = 1;\nvar max = 0;\nfor (var i = 0; i < arr.length - 1; i++) {\n if (arr[i+1] <= arr[i]) {\n if (res > max) {\n max = res;\n res = 1;\n }\n } else {\n res++;\n }\n}\nprint(max);"}, {"source_code": "readline();\nvar arr = readline().split(' ');\narr = arr.map(elem => {\n return parseInt(elem);\n});\nvar res = 1;\nvar max = 1;\nfor (var i = 0; i < arr.length - 1; i++) {\n if (arr[i+1] <= arr[i]) {\n if (res > max) {\n max = res;\n res = 1;\n }\n } else {\n res++;\n }\n}\nif (res > max) {\n max = res;\n}\nprint(max);"}, {"source_code": "readline();\nvar arr = readline().split(' ');\narr = arr.map(elem => {\n return parseInt(elem);\n});\nvar res = 1;\nvar max = 0;\nfor (var i = 0; i < arr.length - 1; i++) {\n if (arr[i+1] <= arr[i]) {\n if (res > max) {\n max = res;\n res = 1;\n }\n } else {\n res++;\n }\n}\nif (res > max) {\n max = res;\n}\nprint(max);"}, {"source_code": "var a = readline().split(' ');\n\nfor (var i = 0; i < a.length; i++) {\n a[i] = Number(a[i]);\n}\n\nvar cur = 1;\nvar ans = 1;\n\nfor (var i = 1; i < a.length; i++) {\n a[i] = Number(a[i]);\n if (a[i] > a[i - 1]) {\n cur = cur + 1;\n }\n else {\n cur = 1; \n }\n ans = Math.max(cur, ans);\n}\n\nprint(ans);"}, {"source_code": "//var array = readline().split(\" \").map(item => +item);\nreadline();\nvar line = readline().split(\" \").map(item => +item);\nvar max = 1;\n\nif(line.length > 1) {\n var prev = line[0],\n count = 1;\n\n for(var i = 1; i < line.length; i++) {\n if (prev < line[i]) {\n count++;\n max = Math.max(max, count);\n prev = line[i];\n } else {\n count = 1;\n }\n }\n print(max);\n} else {\n print(1);\n}\n\n//print((i - 1).toString());"}, {"source_code": "//var n = 5\nvar n = parseInt(readline());\n//var a = [100, 100, 100, 100, 100];\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar max = -1;\n\nif (n == 1) {\n write(\"1\");\n} else {\n var t = 0;\n\n for (var i = 1; i< n; ++i) {\n if (a[i - 1] < a[i]) {\n ++t;\n } else {\n if (t > max) {\n max = t;\n }\n t = 1;\n }\n }\n\n if (t > max) {\n max = t;\n }\n\n //console.log(\"r: \" + max);\n write(max);\n}"}, {"source_code": "var n = readline()\nvar a = readline().split(' ')\n\nvar len = []\nvar count = 1\n\nfor (var i = 0; i < a.length; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++\n\t} else {\n\t\tlen.push(count)\n\t\tcount = 1\n\t}\n}\n\nlen.sort().reverse()\n\nprint(len[0])"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\nvar count = 1;\n\nvar ans = 1;\nfor (var i = 0; i < a.length - 1; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++;\n\t} else {\n\t\tcount = 1;\n\t}\n\tans = Math.max(ans, count);\n}\n\nprint(ans);"}, {"source_code": "var n = readline()\nvar a = readline().split(' ')\n\nvar a = [1, 7, 2, 11, 15]\n\nvar len = []\nvar count = 1\n\nfor (var i = 0; i < a.length - 1; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++\n\t} else {\n\t\tlen.push(count)\n\t\tcount = 1\n\t}\n}\n\nlen.sort().reverse()\n\nprint(len[0])"}, {"source_code": "var n = readline()\nvar a = readline().split(' ');\n\nvar len = [];\nvar count = 1;\n\nfor (var i = 0; i < a.length; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++;\n\t} else {\n\t\tlen.push(count)\n\t\tcount = 1;\n\t}\n}\n\nlen.sort().reverse();\nprint(len[0]);"}, {"source_code": "var n = readline()\nvar a = readline().split(' ')\n\nvar len = []\nvar count = 1\n\nfor (var i = 0; i < a.length - 1; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++\n\t} else {\n\t\tlen.push(count)\n\t\tcount = 1\n\t}\n}\n\nlen.sort().reverse()\n\nprint(len[0])"}, {"source_code": "var n = readline()\nvar a = readline().split(' ')\n\nvar count = 1\n\nvar ans = 1\nfor (var i = 0; i < a.length - 1; i++) {\n\tif (a[i] < a[i + 1]) {\n\t\tcount++\n\t} else {\n\t\tcount = 1\n\t}\n\tans = Math.max(ans, count);\n}\n\nprint(ans)"}], "src_uid": "4553b327d7b9f090641590d6492c2c41"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += a[i];\n }\n\n for (let i = 0; i < n; i++) {\n if ((sum - a[i]) / (n - 1) === a[i]) return 'YES';\n } \n\n return 'NO';\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var total = 0;\n var flag = false;\n for(j = 0; j < n; j++){\n total += k[j];\n }\n for(j = 0; j < n; j++){\n var a = (total - k[j]) / (n - 1);\n if(k[j] == a){\n flag = true;\n break;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var sum = 0;\n var b = false;\n for(j = 0; j < n; j++){\n sum += k[j];\n }\n for(j = 0; j < n; j++){\n var v1 = k[j];\n var v2 = ((sum - k[j]) / (n - 1));\n if(v1 == v2){\n b = true;\n break;\n }\n }\n console.log(b ? 'YES' : 'NO');\n }\n }\n});\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let sum = arr.reduce((a, b) => a + b, 0);\r\n let res = 'NO';\r\n\r\n for (let i = 0; i < n; i++) {\r\n if ((sum - arr[i]) / (n - 1) === arr[i]) {\r\n res = 'YES';\r\n break;\r\n }\r\n }\r\n\r\n output(res);\r\n }\r\n}"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction lowerBound(a, x) {\r\n let lo = 0;\r\n let hi = a.length;\r\n while (lo < hi) {\r\n let mid = lo + Math.trunc((hi - lo) / 2);\r\n if (a[mid] >= x) {\r\n hi = mid;\r\n }\r\n else {\r\n lo = mid + 1;\r\n }\r\n }\r\n return hi;\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n sum += a[i];\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let tot = sum - a[i];\r\n if (a[i] * (n - 1) == tot) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (solve()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsum += list[i];\r\n\t\t}\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif((sum - list[i]) / (N - 1) == list[i]){\r\n\t\t\t\tok = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((ok) ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst n = nextInt();\r\n\tconst arr = nextIntArray(n);\r\n\r\n\tconst sum = arr.reduce((sum, ele) => sum + ele, 0);\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (arr[i] === (sum - arr[i]) / (arr.length - 1)) {\r\n\t\t\tmyout(\"YES\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t}\r\n\tmyout(\"NO\");\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a + b, 0);\r\n for (let i = 0; i < n; i++) {\r\n if (sum - a[i] === a[i] * (n - 1)) return 'YES';\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, m] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let ans = 0;\n for (let i=0; i parseInt(aa) );\n\n if (handle(a))\n print (\"YES\");\n else\n print (\"NO\");\n}\n\nfunction handle(a) {\n\n for (var i=0; i +a)\r\n ans = 'NO'\r\n\r\n mesmo = 1\r\n \r\n for(i=0; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const n = parseInt(await getLine());\r\n const vertices = new Set();\r\n const stack = [];\r\n const addedge = function (a, b) {\r\n if (a > b) {\r\n addedge(b, a);\r\n return;\r\n }\r\n vertices.add(a + ' ' + b);\r\n }\r\n rl.output.write('? 1' + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(1, i + 1);\r\n }\r\n }\r\n const maxPath = Math.max(...d);\r\n const cnt = new Array(n + 1);\r\n let sumOdd = 0;\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] % 2 === 1)\r\n sumOdd++;\r\n }\r\n d.forEach((dist, index) => {\r\n if (sumOdd < n - sumOdd && dist % 2 === 1)\r\n stack.push(index + 1);\r\n else if (sumOdd >= n - sumOdd && dist % 2 === 0 && dist !== 0)\r\n stack.push(index + 1);\r\n })\r\n\r\n for (let j = 0; j < stack.length; j++) {\r\n const v = stack[j];\r\n rl.output.write('? ' + v + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(v, i + 1);\r\n }\r\n }\r\n }\r\n\r\n rl.output.write('!\\n');\r\n vertices.forEach(v => {\r\n rl.output.write(v + '\\n');\r\n });\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const n = parseInt(await getLine());\r\n const vertices = new Set();\r\n const stack = [];\r\n const addedge = function (a, b) {\r\n if (a > b) {\r\n addedge(b, a);\r\n return;\r\n }\r\n vertices.add(a + ' ' + b);\r\n }\r\n rl.output.write('? 1' + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(1, i + 1);\r\n }\r\n }\r\n let sumOdd = d.reduce((prev, cur) => { return prev + cur % 2; }, 0);\r\n\r\n d.forEach((dist, index) => {\r\n if (sumOdd < n - sumOdd && dist % 2 === 1)\r\n stack.push(index + 1);\r\n else if (sumOdd >= n - sumOdd && dist % 2 === 0 && dist !== 0)\r\n stack.push(index + 1);\r\n })\r\n\r\n for (let j = 0; j < stack.length; j++) {\r\n const v = stack[j];\r\n rl.output.write('? ' + v + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(v, i + 1);\r\n }\r\n }\r\n }\r\n\r\n rl.output.write('!\\n');\r\n vertices.forEach(v => {\r\n rl.output.write(v + '\\n');\r\n });\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const n = parseInt(await getLine());\r\n const vertices = new Set();\r\n const stack = [];\r\n const addedge = function (a, b) {\r\n if (a > b) {\r\n addedge(b, a);\r\n return;\r\n }\r\n vertices.add(a + ' ' + b);\r\n }\r\n rl.output.cork();\r\n rl.output.write('? 1' + '\\n');\r\n rl.output.uncork();\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(1, i + 1);\r\n }\r\n }\r\n const maxPath = Math.max(...d);\r\n const cnt = new Array(n + 1);\r\n let sumOdd = 0;\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] % 2 === 1)\r\n sumOdd++;\r\n }\r\n d.forEach((dist, index) => {\r\n if (sumOdd < n - sumOdd && dist % 2 === 1)\r\n stack.push(index + 1);\r\n else if (sumOdd >= n - sumOdd && dist % 2 === 0 && dist !== 0)\r\n stack.push(index + 1);\r\n })\r\n\r\n for (let j = 0; j < stack.length; j++) {\r\n const v = stack[j];\r\n rl.output.cork();\r\n rl.output.write('? ' + v + '\\n');\r\n rl.output.uncork();\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(v, i + 1);\r\n }\r\n }\r\n }\r\n\r\n rl.output.write('!\\n');\r\n vertices.forEach(v => {\r\n rl.output.write(v + '\\n');\r\n });\r\n}\r\n\r\nsolve();\r\n"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const n = parseInt(await getLine());\r\n const vertices = new Set();\r\n const stack = [1];\r\n const addedge = function (a, b) {\r\n if (a > b) {\r\n addedge(b, a);\r\n return;\r\n }\r\n vertices.add(a + ' ' + b);\r\n }\r\n const was = new Array(n + 1);\r\n was[1] = true;\r\n while (vertices.size < n - 1) {\r\n const v = stack.shift();\r\n rl.output.write('? ' + v + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n let ones = 0;\r\n let onev;\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n ones++;\r\n onev = i + 1;\r\n addedge(v, i + 1);\r\n } /* else if (d[i] === 2 && !was[i + 1]) {\r\n stack.push(i + 1);\r\n } */\r\n }\r\n if (ones == 1) {\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 2) {\r\n addedge(onev, i + 1);\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < d.length; i++) {\r\n if (d[i] === 2 && !was[i+1]) {\r\n was[i + 1] = true;\r\n stack.push(i + 1);\r\n }\r\n }\r\n\r\n }\r\n\r\n console.log('!');\r\n vertices.forEach(v => {\r\n console.log(v);\r\n });\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const n = parseInt(await getLine());\r\n const vertices = new Set();\r\n const stack = [1];\r\n const addedge = function(a, b) {\r\n if (a > b) {\r\n addedge(b, a);\r\n return;\r\n }\r\n vertices.add(a + ' ' + b);\r\n }\r\n const was = new Array(n + 1);\r\n\r\n while (vertices.size < n - 1) {\r\n const v = stack.shift();\r\n rl.output.write('? ' + v + '\\n');\r\n const d = (await getLine()).split(' ').map(num => parseInt(num));\r\n for(let i = 0; i < d.length; i++) {\r\n if (d[i] === 1) {\r\n addedge(v, i + 1);\r\n } else if (d[i] === 2 && !was[i + 1]) {\r\n stack.push(i + 1);\r\n }\r\n }\r\n }\r\n\r\n console.log('!');\r\n vertices.forEach(v => {\r\n console.log(v);\r\n });\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "5dbafdd7c4e93b2c01122fa80ef42f0e"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 40001;\r\nconst MOD = 1e9+7;\r\n\r\nconst f = Array(mxN).fill(0); f[0] = 1;\r\n\r\nfunction reverse (n) {\r\n\tn = String(n);\r\n\tn = n.split('');\r\n\tn = n.reverse();\r\n\tn = n.join('');\r\n\tn = Number(n);\r\n\treturn n;\r\n}\r\n\r\nfunction compute () {\r\n\tfor (let p = 1; p < mxN; p++) {\r\n\t\tif (p != reverse(p)) continue;\r\n\t\tfor (let i = p; i < mxN; i++) {\r\n\t\t\tf[i] += f[i-p];\r\n\t\t\tf[i] %= MOD;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tcompute();\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconsole.log(f[n]);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n output[i] = solve(n)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nconst CACHE = pre(4e4)\r\nfunction pre(n) {\r\n const ps = []\r\n for (let i = 1; i <= n; i++) {\r\n const a = String(i)\r\n let ok = true\r\n for (let j = 0; j < a.length; j++) {\r\n if (a[j] !== a[a.length - 1 - j]) {\r\n ok = false\r\n break\r\n }\r\n }\r\n if (ok) ps.push(i)\r\n }\r\n //\r\n const dp = []\r\n for (let j = 0; j < ps.length; j++) {\r\n if (!j) {\r\n dp[j] = Array(n + 1).fill(1)\r\n continue\r\n }\r\n dp[j] = dp[j - 1].slice()\r\n for (let i = ps[j]; i <= n; i++) {\r\n const k = Math.floor(i / ps[j])\r\n dp[j][i] = dp[j][i - ps[j]]\r\n dp[j][i] = add(dp[j][i], dp[j - 1][i] || 1)\r\n // for (let k = 0; k * ps[j] <= i; k++) {\r\n // // dp[j][i] = dp[j - 1][i] + dp[j - 1][i - ps[j] * k]\r\n // dp[j][i] = add(dp[j][i], dp[j - 1][i - ps[j] * k] || 1)\r\n // }\r\n }\r\n }\r\n// console.log(dp)\r\n // for (let i = 1; i <= n; i++) {\r\n // dp[i] = []\r\n // let prev\r\n // for (let j = 0; j < ps.length; j++) {\r\n // if (ps[j] > i) {\r\n // dp[i][j] = prev\r\n // continue\r\n // }\r\n\r\n // let now = 0\r\n // for (let k = 0; k <= j; k++) {\r\n // const max = ps[k]\r\n // now = add(now, i === max ? 1 : dp[i - max][k])\r\n // }\r\n // dp[i][j] = now\r\n // prev = now\r\n // }\r\n // }\r\n return dp[ps.length - 1]\r\n}\r\nfunction solve(n) {\r\n return CACHE[n]\r\n}\r\nfunction add(a, b) {\r\n return (a + b) % (1e9 + 7)\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nconst f = [];\r\nconst N = 4 * 10 ** 4 + 10;\r\nfor (let i = 1; i < N; i++) {\r\n if (i.toString() === i.toString().split('').reverse().join('')) f.push(i);\r\n}\r\nconst m = f.length;\r\nconst dp = new Array(N).fill(0);\r\nconst MOD = 10 ** 9 + 7;\r\nconst mod = num => num >= MOD ? (num % MOD + MOD) % MOD : num;\r\ndp[0] = 1;\r\nfor (let i = 0; i < m; i++) {\r\n for (let j = 0; j < N; j++) {\r\n const k = f[i] + j;\r\n dp[k] = mod(dp[k] + dp[j]);\r\n }\r\n}\r\nfunction solve(n) {\r\n return dp[n];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 40001;\r\nconst mxM = 500;\r\n\r\nconst pal = [];\r\nconst f = Array.from(Array(mxN), _ => Array(mxM).fill(0));\r\n\r\nfunction reverse (n) {\r\n\tn = String(n);\r\n\tn = n.split('');\r\n\tn = n.reverse();\r\n\tn = n.join('');\r\n\tn = Number(n);\r\n\treturn n;\r\n}\r\n\r\nfunction compute () {\r\n\tfor (let i = 1; i < mxN; i++) {\r\n\t\tif (i == reverse(i)) {\r\n\t\t\tpal.push(i);\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < pal.length; i++) { \r\n\t\tf[1][i] = 1, f[0][i] = 1;\r\n\t}\r\n\r\n\tfor (let i = 2; i < mxN; i++) {\r\n\t\tfor (j = 0; j < pal.length; j++) {\r\n\t\t\tf[i][j] = j-1 >= 0 ? f[i][j-1] : 0;\r\n\t\t\tf[i][j] += i-pal[j] >= 0 ? f[i-pal[j]][j] : 0;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tcompute();\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconsole.log(f[n][pal.length-1]);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "529d4ab0bdbb29d8b7f3d3eed19eca63"} {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst nums = new Array(10010).fill(0).map((e, n) => n)\r\nfunction solve(e, n) {\r\n if (0 === n[e - 1]) return nums.slice(1, e + 2)\r\n if (1 === n[0]) return [e + 1].concat(nums.slice(1, e + 1))\r\n let t = 0\r\n for (let s = e - 1; t < s && (0 !== n[t] || 1 !== n[t + 1]); ++t);\r\n if (t === e - 1) return -1\r\n const s = nums.slice(1, t + 2)\r\n s.push(e + 1)\r\n for (let n = t + 1; n < e; ++n) s.push(n + 1)\r\n return s\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readIntegersOfLine())\r\n ;-1 === n ? e.print(n + '\\n') : e.print(n.join(' ') + '\\n')\r\n }\r\n})\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet arr = [];\r\nconst precompute = () => {\r\n arr.push(1n);\r\n let k = 2n;\r\n for (let i = 1; i < 51; i++, k = k * 2n) arr[i] = k;\r\n};\r\nconst solve = () => {\r\n precompute();\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let dir = new Array(n).fill(0).map((cur, ind) => ind + 1);\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (arr[i] === 0) break;\r\n else dir.pop();\r\n }\r\n if (dir.length) {\r\n let s = dir[dir.length - 1];\r\n s++;\r\n dir.push(n + 1);\r\n while (s <= n) dir.push(s++);\r\n console.log(dir.join(\" \"));\r\n } else {\r\n let res = `${n + 1} `,\r\n i = 1;\r\n while (i <= n) res += `${i++} `;\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = Array.from(Array(n), (_, i) => i + 1);\r\n\t\tif (a[0]) {\r\n\t\t\tans.unshift(n + 1);\r\n\t\t} else if (!a[n - 1]) {\r\n\t\t\tans.push(n + 1);\r\n\t\t} else if (a.join('').includes('01')) {\r\n\t\t\tfor (let i = 0; i < n - 1; ++i) {\r\n\t\t\t\tif (!a[i] && a[i + 1]) {\r\n\t\t\t\t\tans.splice(i + 1, 0, n + 1);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet ans = Array.from(Array(n), (_, i) => i+1);\r\n\t\tif (a[n-1] == 0) {\r\n\t\t\tans.push(n+1);\r\n\t\t} else if (a[0] == 1) {\r\n\t\t\tans.unshift(n+1);\r\n\t\t} else if (a.join('').includes('01')) {\r\n\t\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\t\tif (a[i] == 0 && a[i+1] == 1) {\r\n\t\t\t\t\tans.splice(i+1, 0, n+1);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet ans = Array.from(Array(n), (_, i) => i+1);\r\n\t\tif (a[n-1] == 0) {\r\n\t\t\tans.push(n+1);\r\n\t\t} else if (a[0] == 1) {\r\n\t\t\tans.unshift(n+1);\r\n\t\t} else if (a.join('').includes('01')) {\r\n\t\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\t\tif (a[i] == 0 && a[i+1] == 1) {\r\n\t\t\t\t\ta.splice(i+1, 0, n+1);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet ans = Array.from(Array(n), (_, i) => i+1);\r\n\t\tif (a[n-1] == 0) {\r\n\t\t\tans.push(n+1);\r\n\t\t} else if (a[0] == 1) {\r\n\t\t\tans.unshift(n+1);\r\n\t\t} else if (a.join('').includes('01')) {\r\n\t\t\tfor (let i = 1; i < n-1; i++) {\r\n\t\t\t\tif (a[i] == 0 && a[i+1] == 1) {\r\n\t\t\t\t\ta.splice(i+1, 0, n+1);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nconst RANGE = (s, e) => Array.from(Array(e - s + 1), (_, index) => index + s);\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\r\n\t\tlet ans = [], i = 0;\r\n\t\twhile (i < n && a[i] == 0) i++;\r\n\t\tif (i != n ) { \r\n\t\t\tans = [...RANGE(1, i), n + 1, ...RANGE(i + 1, n)];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length == 0 ? -1 : ans.join(' '))\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nconst RANGE = (s, e) => Array.from(Array(e - s + 1), (_, index) => index + s);\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\r\n\t\tlet ans = [], i = 0;\r\n\t\twhile (i < n && a[i] == 0) i++;\r\n\t\tif (i != n ) { \r\n\t\t\tans = [...RANGE(1, i), n + 1, ...RANGE(i + 1, n)];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length == 0 ? -1 : ans.join(' '))\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "3f9525d74f4934eb9dca1b16c53662bf"} {"source_code": "const { createInterface } = require('readline');\nconst lines = []\n\nconst numbers = [4, 8, 15, 16, 23, 42];\n\nconst map = {};\nfor (let i = 0; i < 6; i ++) {\n for (let j = i +1; j < 6; j++) {\n map[numbers[i] * numbers[j]] = [numbers[i], numbers[j]];\n }\n}\n\nconst found = [];\n\nconst nums = [];\n\nfunction solve() {\n if (nums[0][0] === nums[1][0]) {\n found.push(nums[0][1], nums[0][0], nums[1][1])\n } else if (nums[0][0] === nums[1][1]) {\n found.push(nums[0][1], nums[0][0], nums[1][0])\n } else if (nums[0][1] === nums[1][0]) {\n found.push(nums[0][0], nums[0][1], nums[1][1])\n } else if (nums[0][1] === nums[1][1]) {\n found.push(nums[0][0], nums[0][1], nums[1][0])\n }\n numbers.forEach((num) => {\n if (!found.includes(num)) {\n found.push(num);\n }\n })\n\n console.log(`! ${found.join(' ')}`)\n}\n\nconsole.log('? 1 1');\nlet iter = 1;\n\n( function processLineByLine() {\n const rl = createInterface({\n input: process.stdin\n });\n\n rl.on('line', (line) => {\n switch (iter) {\n case 1:\n found.push(parseInt(Math.sqrt(+line)));\n console.log('? 2 2');\n iter++;\n break;\n case 2:\n found.push(parseInt(Math.sqrt(+line)));\n console.log('? 3 4');\n iter++;\n break;\n case 3:\n nums.push(map[line])\n console.log('? 4 5');\n iter++;\n break; \n case 4:\n nums.push(map[line])\n iter++;\n solve();\n break;\n case 5:\n process.exit(0);\n }\n });\n\n\n})();\n", "positive_code": [{"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n\n var arr = [4 , 8, 15, 16, 23, 42];\n var muls = [];\n\n for(var i = 2; i < 6; i++) {\n print('? 1 ' + i ); \n muls.push(read.number());\n }\n \n var first;\n for(var i = 0; i < 6; i++) {\n var ch = true;\n for(var j = 0; j < 4; j++) {\n if(arr.indexOf(muls[j] / arr[i]) === -1) {\n ch = false;\n break;\n }\n }\n if(ch) {\n first = arr[i];\n break;\n }\n }\n\n var res = [first];\n muls.forEach(v => res.push(v/first));\n arr.forEach(v => {\n if(res.indexOf(v) === -1) {\n res.push(v);\n }\n });\n\n print('! ' + res.join(' '));\n\n}());\n"}], "negative_code": [{"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n\n var arr = [4 , 8, 15, 16, 23, 42];\n var muls = [];\n\n for(var i = 2; i < 6; i++) {\n print('? 1 ' + i ); \n muls.push(read.number());\n }\n\n var first;\n for(var i = 0; i < 6; i++) {\n var ch = true;\n for(var j = 0; j < 4; j++) {\n if(arr.indexOf(muls[j] / arr[i]) === -1) {\n ch = false;\n break;\n }\n }\n if(ch) {\n first = arr[i];\n break;\n }\n }\n\n var res = [first];\n muls.forEach(v => res.push(v/first))\n\n arr.forEach(v => {\n if(res.indexof(v) === -1) {\n res.push(v);\n }\n });\n\n print(res.join(' '));\n\n}());"}], "src_uid": "c0f79d7ebcecc4eb7d07c372ba9be802"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n e = lines[j]- 3\n console.log(e+ ' ' + 1 + ' ' + 1 + ' '+ 1)\n }\n}); ", "positive_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const t = Number(inputs[0])\r\n for (let _ = 0; _ < t; _++) {\r\n const n = inputs[_ + 1]\r\n console.log([1, n - 3, 1, 1].join(' '))\r\n }\r\n})()\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[_]);\r\n let ans='';\r\n ans+=n-3+' ';\r\n ans+=1+' ';\r\n ans+=1+' ';\r\n ans+=1+' ';\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n output(`${n - 3} 1 1 1`);\r\n }\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t; i++){\n var s = lines[i];\n console.log(1, s - 3, 1, 1);\n\t}\n});\n\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = parseInt(readLine());\r\n return `${n - 3} 1 1 1`;\r\n}\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nclass SegmTree {\n\n}\n \nconst calc = (n)=>{\n let ans = [1, n-3, 1, 1];\n return ans.join(' ');\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n l('ans')\n print(calc(n));\n }\n}\n \nE.calc = calc;"}, {"source_code": "var tests = readline();\r\n\r\nwhile(tests--) {\r\n var x = readline();\r\n \r\n print(x-3 + ' 1 1 1');\r\n}"}, {"source_code": "var total = +readline();\nwhile (total--) {\n var i = +readline();\n print(i - 3 + \" 1 1 1\");\n}"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n e = lines[j]- 3\n console.log(1+ ' ' + 1 + ' ' + 1 + ' '+ e)\n }\n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n e = lines[j]- 3\n console.log(1+ ' ' + 1 + ' ' + 1 + ' '+ e)\n }\n}); \n "}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const t = Number(inputs[0])\r\n for (let _ = 0; _ < t; _++) {\r\n const n = inputs[_ + 1]\r\n console.log([1, 1, 1, n - 3].join(' '))\r\n }\r\n})()\r\n"}], "src_uid": "f9f803c6850da1838d62a0cf85bb13f2"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let count = 0;\n for (let i = 0; i < n; i++) {\n let op = readLine();\n if (op === 'X++' || op === '++X') {\n count++;\n } else {\n count--;\n }\n }\n console.log(count);\n}\n", "positive_code": [{"source_code": "readline()\n var result = 0\n\n var flag = true\n while (flag) {\n var line = readline()\n if (line) {\n var re = /[++]/\n re.test(line) ? result++ : result--\n } else {\n flag = false\n }\n }\n\n print(result)"}, {"source_code": "readline()\n var result = 0\n\n var flag = true\n while (flag) {\n var line = readline()\n if (line) {\n var re = /[++]/\n re.test(line) ? result++ : result--\n // problems.push(line)\n } else {\n flag = false\n }\n }\n\n print(result)"}, {"source_code": "var num=readline();\nvar x=0;\nfor(var i=0;i= 1 && n <= 150)) {\n print(0);\n}\nelse {\n var x = 0;\n \n while (n-- > 0){\n var statement = readline();\n var variable = String(statement).match(/[a-zA-Z]+/)[0];\n var atBegin = statement[0] === variable;\n var symbol = atBegin ? statement[statement.length - 1] : statement[0];\n \n if (symbol === '+') {\n if (atBegin) x++;\n else ++x;\n } else {\n if (atBegin) x--;\n else --x;\n }\n }\n \n print(x);\n}"}, {"source_code": "var numero = readline();\nvar contador = 0;\nfor (var i = 0; i parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n const length = input[0];\n let x = 0;\n for(let i = 1; i <= length; i ++){\n const string = String(input[i])\n if(string.indexOf('+') != -1){\n x++;\n } else if(string.indexOf('-') != -1){\n x--;\n }\n else {\n continue;\n }\n }\n console.log(x);\n});"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nvar expect = 'n';\nvar x = 0;\nrl.on('line',function(line){\n if(expect =='n'){\n n = parseInt(line);\n expect = 'statement';\n case_counter = 1;\n }else if (expect == 'statement'){\n if((line == '++X')||(line =='X++')){\n x++;\n } else {\n x--;\n }\n ++case_counter === n +1 ? rl.close() : 0;\n }\n}).on('close', function(){\n console.log(x);\n process.exit(0);\n});"}, {"source_code": "// Generated by CoffeeScript 2.5.1\nvar lines, mainAux, print, readline, rl, rli, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nmainAux = function() {\n var i, j, numlines, ref, tot;\n numlines = readline();\n tot = 0;\n for (i = j = 1, ref = numlines; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) {\n if (readline().includes('++')) {\n tot++;\n } else {\n tot--;\n }\n }\n return print(tot);\n};\n\n\n function main() {\n return mainAux();\n }\n;\n\n//# sourceMappingURL=operator-282-a.js.map\n"}, {"source_code": "function main() {\n const res = stdin.slice(1).reduce((s,x)=>{\n return s = (x[1] === \"+\") ? s+1 : s-1;\n },0)\n console.log(res)\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);});\nrl.on('close', main);\n"}, {"source_code": "var line_number = 0;\nconst cs = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nvar lines = {};\ncs.on(\"line\", (input) => {\n if (input == \"\") {\n cs.close();\n }\n lines[line_number] = input.split(\" \")\n line_number += 1;\n}).on(\"close\", () => {\n main();\n process.exit();\n});\n\nfunction isOp(str) {\n return str.length === 1 && str.match(/[<=>]/);\n}\nfunction isChr(str) {\n return str.length === 1 && str.match(/[a-z]/i);\n}\nfunction isInt(str) {\n return str.length === 1 && !isNaN(str);\n}\n\nfunction print(str) {\n console.log(str);\n}\n\nfunction predict(test) {\n let op = \"\";\n let ops = [];\n let opVariables = [];\n let limits = [];\n for (let t of test) {\n // console.log(t);\n for (let i = 0; i < t.length; i++) {\n if (isOp(t[i])) {\n op = t[i];\n if (isOp(t[i + 1])) {\n op += t[i + 1];\n i += 1;\n }\n ops.push(op);\n op = \"\";\n } else if (isChr(t[i])) {\n // console.log(t[i])\n op = t[i];\n for (var j = i + 1; j < t.length; j++) {\n if (isChr(t[j]) || isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n opVariables.push(op);\n op = \"\";\n } else {\n if (i == 0 || (i > 0 && isOp(t[i - 1]))) {\n op = t[i];\n let j = i + 1;\n for (; j < t.length; j++) {\n if (isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n limits.push(op);\n op = \"\";\n }\n }\n }\n }\n\n let min = limits[0];\n let max = limits[1];\n\n let pvs = ops.map((o, i) => [o, opVariables[i]]);\n\n for (let pv of pvs) {\n if (pv[1] == undefined) {\n pv[1] = max;\n }\n // print(`${min} ${pv[0]} ${pv[1]} ?`)\n if (eval(`${min}${pv[0]}${pv[1]}`)) {\n // print(` ${min} ${pv[0]} ${pv[1]} true`)\n min = pv[1];\n } else {\n print(\"input error\");\n process.exit();\n }\n }\n}\n\nvar n\nfunction main() {\n n = parseInt(lines[0][0], 10)\n predict([\"1<=n<=150\"])\n\n var x = 0\n for (var i = 1; i <= n; i++) {\n c = lines[i][0]\n // print(c)\n if (c[0] == '+' || c[c.length-1] == '+')\n x += 1\n else if (c[0] == \"-\" || c[c.length - 1] == \"-\") \n x -= 1;\n \n }\n\n print(x)\n}\n"}, {"source_code": "\n\"use strict\";\nlet input = [];\nconst readline=require('readline');\nconst RL=readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nRL.on('line', (line)=>{\n input.push(line.trim());\n});\nRL.on('close', ()=>{\n const n = parseInt(input[0]);\n let answer=0;\n for(let i=1; i<=n; ++i){\n if(input[i].includes(\"++\")){\n answer++;\n } else{\n answer--;\n }\n }\n console.log(answer);\n});\n"}, {"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let stdinInput = '';\n \n process.stdin.on('data', input => {\n stdinInput += input;\n })\n \n process.stdin.on('end', () => {\n main(stdinInput);\n })\n \n function main(data) {\n data = data.split('\\n');\n const n = data.shift();\n let x = 0;\n for (let i = 0; i < n; i += 1) {\n if (data[i].match(/-/)) x -= 1;\n else x += 1;\n } \n process.stdout.write(x + '');\n }"}, {"source_code": "'use strict';\n\nconst count = readline().split(/\\s+/g);\nconst n = count[0];\n\nlet answer = 0;\n\nfor(let i=0; i -1;\n}\n\nfunction clearWhitespaces() {\n while (cursor < input.length && isWhitespace(input[cursor])) ++cursor; \n}\n\nfunction nextInt() {\n return parseInt(nextString());\n}\n\nfunction nextFloat() {\n return parseFloat(nextString());\n}\n\nfunction nextChar() {\n clearWhitespaces();\n if (cursor < input.length)\n return input[cursor++];\n return '';\n}\n\nfunction nextString() {\n let str = \"\";\n clearWhitespaces();\n while (cursor < input.length && !isWhitespace(input[cursor])) {\n str += input[cursor++];\n }\n return str;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/282/A\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet data = [];\nrl.on('line', (input) => {\n data.push(input);\n});\n\nrl.on('close', () => {\n solve(data);\n});\n\nfunction solve(data) {\n let x = 0;\n\n for (let i = 1; i < data.length; i++) {\n const element = data[i];\n if (element.includes('++')) {\n x++;\n } else if (element.includes('--')) {\n x--;\n }\n }\n\n console.log(x);\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0;\nlet n = 0;\nlet x = 0;\nfunction main(input){\n\tif(n == 0){\n\t\tn = input\n\t\treturn\n\t}\n\n\tif(input[0] === \"X\"){\n\t\tif(input[1] === \"-\"){\n\t\t\tx--\n\t\t}\n\t\telse{\n\t\t\tx++\n\t\t}\n\t}\n\telse{\n\t\tif(input[0] === \"-\"){\n\t\t\tx--\n\t\t}\n\t\telse{\n\t\t\tx++\n\t\t}\n\t}\n\n\ti++\n\tif(i === parseInt(n)){\n\t\tconsole.log(x)\n\t}\n\n}\n"}, {"source_code": "var t = readline();\nvar x = 0;\nwhile(t--){\n var str = readline();\n if(str == '++X' || str == 'X++'){\n x++;\n }else{\n x--;\n }\n}\n\nprint(x);"}, {"source_code": "var n = readline();\nvar a;\nvar cnt = 0;\nfor(var i = 0; i < n; i++){\n a = readline();\n if(a == \"++X\" || a == \"X++\"){\n cnt++;\n }\n else{\n cnt--;\n }\n}\nwrite(cnt);"}, {"source_code": "var input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n console.log(input.split('\\r\\n').slice(1,-1).reduce((a, v) => v.includes('+') ? a+1:a-1, 0))\n})"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t = +readLine()\n\tlet x=0\n\twhile(t--){\n\t\tlet operator = readLine()\n\t\tswitch(operator){\n\t\t\tcase 'X++':\n\t\t\t\tx++\n\t\t\t\tbreak\n\t\t\tcase '++X':\n\t\t\t ++x\n\t\t\t break\n\t\t\tcase 'X--':\n\t\t\t\tx--\n\t\t\t\tbreak\n\t\t\tcase '--X':\n\t\t\t\t--x\n\t\t\t\tbreak\n\t\t}\n\t}\n\tconsole.log(x)\n}"}, {"source_code": "var n = readline();\nvar x = 0;\n\nfor(var i = 0; i < n; i++)\n{\n var statement = readline();\n if(statement[0] == \"+\" || statement[1] == \"+\" || statement[2] == \"+\")\n {\n x++\n }\n else\n {\n x--;\n }\n}\n\nprint(x);"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});\n\t\n\tlet t = inputReader.readNumber();\n\tvar x = 0;\n\t\n\twhile (t--) {\n\t let tmp = inputReader.readLine();\n\t if (tmp[1] == \"+\") x++;\n\t else x--;\n\t}\n\t\n\tconsole.log(x);\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumber(){\n\t\treturn Number(_inputLines[_lineNumber++]);\n\t}\n\t\t\n\tfunction readLine(){\n\t\treturn _inputLines[_lineNumber++];\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadLine,\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const n = readAsInt();\n let result = 0;\n for (let i = 0; i < n; i++) {\n result += readline().includes(\"++\") ? 1 : -1;\n }\n console.log(result);\n}\n\n"}, {"source_code": "let fs = require('fs')\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter((data) => {\n return data.length > 0;\n});\n\nfor (let index = 0; index < txt.length; index++) {\n if (!isNaN(txt[index]*1)) {\n let tab = []\n for (let i = 1; i <= txt[index]; i++) {\n tab.push(txt[index + i]);\n }\n square(tab)\n }\n\n}\n\nfunction square(tab) {\n let score = 0;\n tab.forEach(element => {\n if(element[0]==\"+\" || element[1]==\"+\") {\n ++score;\n }else{\n --score;\n }\n });\n console.log(score);\n \n}"}, {"source_code": "var num_lineas = readline(); // Leemos el n\u00famero de lineas que debemos tratar\nvar sol = 0;\nvar linea;\n// Por cada linea propuesta:\nfor (var i = 0; i < num_lineas; i++) {\n linea = readline(); // Leemos la linea\n // Si la linea contiene '+' sumamos 1 a la soluci\u00f3n, en caso contrario restamos 1\n if (linea.indexOf('+') > -1) {\n sol++;\n } else {\n sol--;\n }\n \n}\nprint(sol);"}, {"source_code": "var num_lineas = readline(); // Leemos el n\u00famero de lineas que debemos tratar\nvar sol = 0;\nvar linea;\n// Por cada linea propuesta:\nfor (var i = 0; i < num_lineas; i++) {\n linea = readline(); // Leemos la linea\n // Si la linea contiene '+' sumamos 1 a la soluci\u00f3n, en caso contrario restamos 1\n if (linea.indexOf('+') > -1) {\n sol++;\n } else {\n sol--;\n }\n \n}\nprint(sol); // Imprimimos la soluci\u00f3n"}, {"source_code": "/**\n * @author Albert Hambardzumyan\n * @description Bit++.\n * Reference: http://codeforces.com/problemset/problem/282/A\n * Tags: implementation, 900\n */\n(function () {\n const iterations = parseInt(readline())\n\n var x = 0\n var temp\n for (var i = 0; i < iterations; i++) {\n temp = readline()\n\n temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--\n }\n\n print(x)\n})()\n"}, {"source_code": "var n = readline()\nvar ans = 0\n\nfor(var i = 0; i < n; i++) {\n var exp = readline()\n if(exp[1] == \"-\"){\n ans--\n }else{\n ans++\n \n }\n}\nprint(ans)\n"}, {"source_code": "n = readline();\nvar meghdar = 0;\nwhile(n--)\n{\n \t \n\ts = readline().replace(new RegExp('X' , 'g'), '')\n\tif(s == \"++\"){meghdar++}\n\telse{meghdar--}\n\t\n}\nprint(meghdar)"}, {"source_code": "n = readline();\nvar meghdar = 0;\nwhile(n--)\n{\n \t \n\ts = readline();\n\tvar k = s.indexOf(\"+\");\n\tif(k == -1){meghdar--}\n\telse{meghdar++}\n\t\n}\nprint(meghdar)"}, {"source_code": "input=readline();\ninput=input.split(' ').map(e=>parseInt(e));\nn=input[0]\nans=0;\nwhile(n--){\n tmp=readline();\n ans+=(tmp.indexOf('+')===-1)?-1:1;\n}\nprint(ans)"}, {"source_code": "function main() {\n var lines = readline();\n var x = 0;\n for (; lines > 0; lines--) {\n var operation = readline();\n if (operation[1] === '+') {\n x += 1;\n } else if (operation[1] === '-') {\n x -= 1;\n }\n }\n print(x);\n}\nmain()"}, {"source_code": "var value = +readline();\nvar count = 0\nfor (var i=0; i < value; i++) {\n var c = readline().split(\"\");\n if (c[0] === '+' || c[1] === '+' || c[2] === '+' ) {\n count++;\n } else count--\n}\nprint(count);"}, {"source_code": "const n = Number(readline());\nvar x = 0;\nvar s ;\nfor(var i = 0; i -1) {\n count++;\n } else if(input.indexOf(\"--\") > -1) {\n count --;\n }\n}\n\nprint(count);"}, {"source_code": "for(var i=0,x=parseInt(readline()),c=0;i {\n const N = Number(readline());\n\n var result = 0;\n\n for (var i = 0; i < N; i++) {\n if (readline().indexOf(\"-\") >= 0) {\n result--;\n } else {\n result++;\n }\n }\n\n return result;\n};\n\nprint(main());"}, {"source_code": "var cases = readline();\nvar res = 0;\nfor(var i = 0; i < cases; ++i){\n var op = readline();\n if(op.includes('--')) --res;\n if(op.includes('++')) ++res;\n}\n\nprint(res);"}, {"source_code": "var nOpers = readline()\nvar x = 0\nvar oper;\n\nfor(i=0;i 0) {\n\ts = readline()\n\tif (s.charAt(1) == '-')\n\t\tx ++\n\telse\n\t\tx --\n\tn --\n}\n\nprint(x)"}, {"source_code": "var numberOfTestCases = parseInt(readline());\n \nvar input = \"\";\n \nvar ans = 0\n \nfor(var i = 0 ; i < numberOfTestCases ; i++) {\n \ninput = readline().split(\" \");\n \nif (input[i] == \"X++\" || input[i] == \"++X\") ans++\nelse ans--\n}\n \nprint(ans)"}, {"source_code": "var numberOfTestCases = parseInt(readline());\n\nvar input = \"\";\n\nvar ans = 0;\n\nfor(var i = 0 ; i < numberOfTestCases ; i++) {\n\ninput = readline();\n\nif (input[i] == \"X++\" || input[i] == \"++X\") ans++;\nelse ans--;\n\n}\n\nprint(ans);"}, {"source_code": "var numberOfTestCases = parseInt(readline());\n\nvar input = \"\";\n\nvar ans = 0\n\nfor(var i = 0 ; i < numberOfTestCases ; i++) {\n\ninput = readline().split(\" \");\n\nif (input[i] == \"X++\" || input[i] == \"++X\") ans++\nelse ans--\n}\n\nprint(ans)"}, {"source_code": "var num_op = parseInt(readline());\nvar x = 0;\nwhile(num_op >0){\n var value = readline();\n if(value == \"++X\" || value == \"X++\" ) x++;\n if(value == \"--X\" || value == \"X--\" ) x++;\n num_op--;\n}\nprint(x);"}, {"source_code": "var nOpers = parseInt(readline());\nvar x = 0;\nvar operacion;\n\nfor(var i=0;i {\n const x = Number(readline());\n const arr = [];\n var count = 0;\n\n for (var i in [...Array(x).fill()]) {\n arr.push(readline().trim());\n }\n\n for (var b of arr) {\n if (b === 'X++') {\n count++;\n continue;\n }\n count--;\n }\n\n print(count);\n};\n\nmain()"}, {"source_code": "'use strict';\nconst n = parseInt(readline());\nvar x = 0;\n\nfor(let i = 0; i < n; i++) {\n if(readline().indexOf('+')){\n x++;\n } else {\n x--;\n }\n}\n\nwrite(x);"}, {"source_code": "var numero = readline();\nvar contador=0;\nvar x=0;\n\nfor (var i = 0; i 0 && i !== lines.length) {\n ans++\n continue\n }\n if(stmt.indexOf('--') === 0) {\n ans--\n continue\n }\n if(stmt.indexOf('--') > 0 && i !== lines.length) {\n ans--\n continue\n }\n}\n\nprint(ans)"}, {"source_code": "var lines = parseInt(readline())\nvar ans = 0\nfor(var i=0;i 0 && i < lines - 1) {\n ans++\n continue\n }\n if(stmt.indexOf('--') === 0) {\n ans--\n continue\n }\n if(stmt.indexOf('--') > 0 && i < lines - 1) {\n ans--\n continue\n }\n}\n\nprint(ans)"}, {"source_code": "// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.\n\n// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:\n\n// Operation ++ increases the value of variable x by 1.\n// Operation -- decreases the value of variable x by 1. \n\n// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters \"+\", \"-\", \"X\". Executing a statement means applying the operation it contains.\n\n// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.\n\n// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).\n// Input\n\n// The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009150) \u2014 the number of statements in the programme.\n\n// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter \u00abX\u00bb). Thus, there are no empty statements. The operation and the variable can be written in any order.\n// Output\n\n// Print a single integer \u2014 the final value of x.\n\nvar n = readline();\n\nvar x = 0;\nvar operations = [];\n\nvar temp;\nvar i;\nfor (i = 0; i < n; i++) {\n temp = readline();\n operations.push(temp);\n}\n\noperations.forEach(function(operation) {\n if (operation === 'X++' || operation === '++X') {\n x += 1;\n } else if (operation === 'X--' || operation === '--X') {\n x -= 1;\n }\n});\n\nprint(n);"}, {"source_code": "// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.\n\n// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:\n\n// Operation ++ increases the value of variable x by 1.\n// Operation -- decreases the value of variable x by 1. \n\n// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters \"+\", \"-\", \"X\". Executing a statement means applying the operation it contains.\n\n// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.\n\n// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).\n// Input\n\n// The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009150) \u2014 the number of statements in the programme.\n\n// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter \u00abX\u00bb). Thus, there are no empty statements. The operation and the variable can be written in any order.\n// Output\n\n// Print a single integer \u2014 the final value of x.\n\nconst n = readline();\n\n// let x = 0;\n// let operations = [];\n\n// for (let i = 0; i < n; i++) {\n// const temp = readline();\n// operations.push(temp);\n// }\n\n// operations.forEach(function(operation) {\n// if (operation === 'X++' || operation === '++X') {\n// x += 1;\n// } else if (operation === 'X--' || operation === '--X') {\n// x -= 1;\n// }\n// });\n\nprint(n);"}, {"source_code": "var n = parseInt(readline());\nvar X = 0;\nvar i;\nfor (i in n){\n eval(readline());\n}\nprint(X);"}, {"source_code": "var n = Number(readline());\nvar x = 0;\n\nfor (var i = 0; i < n; i++) {\n var codeLine = readline();\n\n if ( codeLine.indexOf('++') ) {\n x++;\n } else {\n x--;\n }\n}\n\nprint( x );\n"}, {"source_code": "var count = readline();\nvar num=0;\nfor(var i = 0; i -1) {\n sol++;\n } else {\n sol--;\n }\n \n}\nprint(sol);"}, {"source_code": "/**\n * @author Albert Hambardzumyan\n * @description Bit++.\n * Reference: http://codeforces.com/problemset/problem/282/A\n * Tags: implementation, 900\n */\n(function () {\n const iterations = readline()\n\n var x = 0\n for (var i = 0; i < iterations; i++) {\n const temp = readline()\n\n temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--\n }\n\n print(x)\n})()\n"}, {"source_code": "var n = readline()\nvar ans = 0\n\nfor(var i = 0; i < n; i++) {\n var exp = readline()\n var a = (exp[0] == \"-\")?ans--:ans++;\n}\n\nprint(ans)"}, {"source_code": "var n = readline()\nvar ans = 0\n\nfor(var i = 0; i < n; i++) {\n var exp = readline()\n print(exp[1])\n if(exp[1] == \"-\"){\n ans--\n }else{\n ans++\n \n }\n \n}\n\nprint(ans)"}, {"source_code": "function main(){\n var n = +readline();\n var x;\n while (n>0) {\n x = readline();\n if (x.includes(\"++\")) {\n x += +1 ;\n }\n if (x.includes(\"--\")) {\n x += -1 ;\n }\n n--;\n }\n print(x);\n}\n\nmain();\n"}, {"source_code": "function main(){\n var n = +readline();\n var x;\n var result = 0;\n while (n>0) {\n x = readline();\n if (x.includes(\"++\")) {\n result = +1 ;\n }\n if (x.includes(\"--\")) {\n result = -1 ;\n }\n n--;\n }\n print(result);\n}\n\nmain();\n"}, {"source_code": "function main(){\n var n = +readline();\n var x;\n while (n>0) {\n x = readline();\n if (x.includes(\"++\")) {\n x = x+1 ;\n }\n if (x.includes(\"--\")) {\n x = x-1 ;\n }\n n--;\n }\n print(x);\n}\n\nmain();\n"}, {"source_code": "var n = readline();\nvar x = 0;\n\nfor (var i = 0; i < n; i++){\n var r = readline();\n print(r);\n if(r.includes('+')){\n x++;\n } else if (r.includes('-')){\n x--;\n }\n}\nprint(x);"}, {"source_code": "var n=readline();\nvar ans;\nfor (var i=0; i{\n return s = x[1] === \"+\" ? s+1 : s-1;\n },0)\n console.log(res)\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n"}, {"source_code": "function main() {\n console.log(stdin);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n"}, {"source_code": "// var stdin = \"\";\n// process.stdin.resume();\n// process.stdin.setEncoding(\"ascii\");\n// process.stdin.on(\"data\", function(data) {\n// stdin += data;\n// });\n// process.stdin.on(\"end\", function() {\n// main(stdin);\n// });\n\nconst debug = 0;\nconst stdin = `1\n\n++X\n`;\nmain(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n let res = 0;\n const commandCount = readLine(stdin, currentLine);\n\n while (commandCount > currentLine) {\n ++currentLine;\n const command = readLine(stdin, currentLine).replace(\"X\", \"\");\n\n if (command === \"++\") {\n res += 1;\n } else if (command === \"--\") {\n res -= 1;\n }\n }\n\n console.log(res);\n}\n\nfunction readLine(str, line) {\n return str.split(/\\r?\\n/).filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "// var stdin = \"\";\n// process.stdin.resume();\n// process.stdin.setEncoding(\"ascii\");\n// process.stdin.on(\"data\", function(data) {\n// stdin += data;\n// });\n// process.stdin.on(\"end\", function() {\n// main(stdin);\n// });\n\nconst debug = 0;\nconst stdin = `2\n \nX++\n \n--X\n`;\nmain(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n let res = 0;\n const commandCount = readLine(stdin, currentLine);\n\n while (commandCount > currentLine) {\n ++currentLine;\n const command = readLine(stdin, currentLine).replace(\"X\", \"\");\n\n if (command === \"++\") {\n res += 1;\n } else if (command === \"--\") {\n res -= 1;\n }\n }\n\n console.log(res);\n}\n\nfunction readLine(str, line) {\n return str.split(\"\\n\").filter(s => Boolean(s.trim()))[line];\n}\n"}, {"source_code": "var stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function(data) {\n stdin += data;\n});\nprocess.stdin.on(\"end\", function() {\n main(stdin);\n});\n\n// main(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n let res = 0;\n const commandCount = readLine(stdin, currentLine);\n\n while (commandCount > currentLine) {\n ++currentLine;\n const command = readLine(stdin, currentLine).replace(\"X\", \"\");\n\n if (command === \"++\") {\n res += 1;\n } else if (command === \"--\") {\n res -= 1;\n }\n }\n\n console.log(res);\n}\n\nfunction readLine(str, line) {\n return str.split(\"\\n\")[line];\n}\n"}, {"source_code": "// var stdin = \"\";\n// process.stdin.resume();\n// process.stdin.setEncoding(\"ascii\");\n// process.stdin.on(\"data\", function(data) {\n// stdin += data;\n// });\n// process.stdin.on(\"end\", function() {\n// main(stdin);\n// });\n\nconst debug = 0;\nconst stdin = `1\n\n++X\n`;\nmain(stdin);\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n let currentLine = 0;\n let res = 0;\n const commandCount = readLine(stdin, currentLine);\n\n while (commandCount > currentLine) {\n ++currentLine;\n const command = readLine(stdin, currentLine).replace(\"X\", \"\");\n\n if (command === \"++\") {\n res += 1;\n } else if (command === \"--\") {\n res -= 1;\n }\n }\n\n console.log(res);\n}\n\nfunction readLine(str, line) {\n return str.split(\"\\n\").filter(Boolean)[line];\n}\n"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet first = true;\nlet total = 0;\nrl.on('line', line => {\n if (first === true) {\n total = parseInt(line);\n first = false;\n }\n input = line;\n solution(input, total);\n});\n\nrl.on('close', () => {\n console.log(total);\n});\n\nfunction solution(input) {\n const operator = input[1];\n\n if (operator === '+') {\n total += 1;\n } else if (operator === '-') {\n total -= 1;\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s){\n process.stdout.write(s);\n}\n\nfunction println(s){\n console.log(s);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n // var n = readline().split(' ');\n // for(var i=0; i {\n if (i !== 1) arr.push(lineInput);\n i++;\n});\n\n// when all file readed\nrl.on(\"close\", () => {\n let result = 0;\n for (let index = 0; index < arr.length; index++) {\n if (arr[index].indexOf(\"++\") > -1) result++;\n if (arr[index].indexOf(\"--\") > -1) result--;\n }\n console.log(result);\n});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// read each line\nlet i = 0;\nlet arr = [];\nrl.on(\"line\", (lineInput) => {\n if (i !== 1) arr.push(lineInput);\n i++;\n});\n\n// when all file readed\nrl.on(\"close\", () => {\n let result = 0;\n arr.forEach(function (el) {\n if (el.indexOf(\"++\") > -1) result++;\n if (el.indexOf(\"--\") > -1) result--;\n });\n console.log(result);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = [];\n let ans = 0;\n for (let i = 0; i < n; i++) {\n arr.push(readLine());\n if (arr[0].indexOf('-') != -1) {\n ans--;\n } else ans++;\n }\n console.log(ans);\n}"}], "src_uid": "f3cf7726739290b280230b562cac7a74"} {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n const [n, queries] = readLine().split(' ').map(Number);\r\n\r\n const arr = readLine().split(' ').map(Number);\r\n\r\n const colors = readLine().split(' ').map(Number); //query colors.\r\n\r\n c(n,queries,arr,colors)\r\n\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction c(n,q,a,t)\r\n{\r\n const N = 60;\r\n\r\n let pos = Array(N).fill(-1); \r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = [];\r\n for (let k = 0; k < q; k++) {\r\n res.push(pos[t[k]] + 1);\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n return console.log(res.join(' '))\r\n}\r\n\r\nmodule.exports = c;", "positive_code": [{"source_code": "// 04/12/21 afternoon \r\n \r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst N = 60;\r\nconst solve = (n, q, a, t) => {\r\n // let pos = Array(n).fill(-1);\r\n let pos = Array(N).fill(-1); // 05/09/21 evening fix bug of N\r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = [];\r\n for (let k = 0; k < q; k++) {\r\n res.push(pos[t[k]] + 1);\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n \r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[0][1], input[1], input[2])\r\n });\r\n};\r\n \r\nmain()"}, {"source_code": "// 04/12/21 afternoon \r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst N = 60;\r\nconst solve = (n, q, a, t) => {\r\n // let pos = Array(n).fill(-1);\r\n let pos = Array(N).fill(-1); // 05/09/21 evening fix bug of N\r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = '';\r\n for (let k = 0; k < q; k++) {\r\n res += pos[t[k]] + 1;\r\n res += ' '\r\n // pr(pos, pos[t[k]], t[k])\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[0][1], input[1], input[2])\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nclass Node {\r\n constructor(val) {\r\n this.val = val;\r\n this.next = null;\r\n this.prev = null;\r\n }\r\n}\r\nclass Dl {\r\n constructor() {\r\n this.head = null;\r\n this.tail = null;\r\n }\r\n push(val) {\r\n if (!this.head) this.head = this.tail = new Node(val);\r\n else {\r\n let newn = new Node(val);\r\n this.tail.next = newn;\r\n newn.prev = this.tail;\r\n this.tail = newn;\r\n }\r\n }\r\n shift(val) {\r\n let newN = new Node(val);\r\n newN.next = this.head;\r\n this.head.prev = newN;\r\n this.head = newN;\r\n }\r\n remove(val) {\r\n let ind = 1,\r\n p = this.head;\r\n while (p) {\r\n if (p.val === val) {\r\n if (p.prev === null) return ind;\r\n else if (p.next === null) {\r\n this.shift(p.val);\r\n this.tail = p.prev;\r\n this.tail.next = null;\r\n return ind;\r\n } else {\r\n this.shift(p.val);\r\n p.prev.next = p.next;\r\n p.next.prev = p.prev;\r\n return ind;\r\n }\r\n }\r\n p = p.next;\r\n ind++;\r\n }\r\n }\r\n}\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let q = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let list = new Dl();\r\n for (let i = 0; i < n; i++) list.push(arr[i]);\r\n let res = \"\";\r\n for (let i = 0; i < k; i++) res += list.remove(q[i]) + \" \";\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var set = new Array(51).fill(Infinity); // index is card number, value is highest position.\r\n var a = input[1].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var query = input[2].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n for (let i = 0; i < a.length; i++) {\r\n set[a[i]] = Math.min(i + 1, set[a[i]]);\r\n }\r\n var result = [];\r\n for (let i = 0; i < query.length; i++) {\r\n var index = set[query[i]];\r\n result.push(index);\r\n for (var j = 1; j <= 50; j++) {\r\n if (set[j] < index) {\r\n set[j] += 1;\r\n }\r\n }\r\n set[query[i]] = 1;\r\n }\r\n console.log(result.join(\" \"));\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, qq] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var q = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var colors = new Array(51)\r\n for (let j = 0; j < 51; j++) {\r\n colors[j] = -1\r\n }\r\n\r\n for (let j = 0; j < a.length; j++) {\r\n if (colors[a[j]] === -1) colors[a[j]] = j\r\n }\r\n var res = ''\r\n for (let i = 0; i < q.length; i++) {\r\n res = res + (colors[q[i]]+1) + ' '\r\n for (let j = 0; j < 51; j++) {\r\n if (colors[j] < colors[q[i]] && colors[j] !== -1) colors[j] += 1\r\n }\r\n colors[q[i]] = 0\r\n }\r\n console.log(res)\r\n\r\n // })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n const [n, queries] = readLine().split(' ').map(Number);\r\n\r\n const arr = readLine().split(' ').map(Number);\r\n\r\n const colors = readLine().split(' ').map(Number); //query colors.\r\n\r\n c(n,queries,arr,colors)\r\n\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction c(n,q,a,t)\r\n{\r\n const N = 50;\r\n\r\n let pos = Array(N).fill(-1); \r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = [];\r\n for (let k = 0; k < q; k++) {\r\n res.push(pos[t[k]] + 1);\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n return console.log(res.join(' '))\r\n}\r\n\r\nmodule.exports = c;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n const [n, queries] = readLine().split(' ').map(Number);\r\n\r\n const arr = readLine().split(' ').map(Number);\r\n\r\n const colors = readLine().split(' ').map(Number); //query colors.\r\n\r\n c(n,queries,arr,colors)\r\n\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction c(n,q,a,t)\r\n{\r\n const N = 50;\r\n\r\n let pos = Array(N).fill(-1); \r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = [];\r\n for (let k = 0; k < q; k++) {\r\n res.push(pos[t[k]] + 1);\r\n for (let i = 1; i < 51; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n return console.log(res.join(' '))\r\n}\r\n\r\nmodule.exports = c;"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let [n,q] = get_ints();\r\n let a = get_ints();\r\n let c = get_ints();\r\n let ans = [];\r\n var idx = 0;\r\n for(let i = 0 ; i < q; i++)\r\n {\r\n let a_new = [];\r\n const color = c[i];\r\n for(let j = 0 ; j < n; j++)\r\n {\r\n if(a[j] === color)\r\n {\r\n a_new.unshift(color)\r\n ans.push(j+1);\r\n //console.log('a_new = ', a_new, 'a.slice(j+1) = ', a.slice(j+1))\r\n //print(a_new.concat(a.slice(j+1)))\r\n idx = j;\r\n break;\r\n }\r\n else \r\n {\r\n a_new.push(a[j])\r\n }\r\n }\r\n a = a_new.concat(a.slice(idx+1));\r\n }\r\n print(ans);\r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, q, a, t) => {\r\n let pos = Array(n).fill(-1);\r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = '';\r\n for (let k = 0; k < q; k++) {\r\n res += pos[t[k]] + 1;\r\n res += ' '\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[0][1], input[1], input[2])\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, q, a, t) => {\r\n let pos = Array(n).fill(-1);\r\n for (let i = 0; i < n; i++) {\r\n if (pos[a[i]] < 0) pos[a[i]] = i;\r\n }\r\n let res = [];\r\n for (let k = 0; k < q; k++) {\r\n res.push(pos[t[k]] + 1);\r\n for (let i = 1; i < 60; i++) {\r\n if (pos[i] >= 0 && pos[i] < pos[t[k]]) {\r\n pos[i]++;\r\n }\r\n }\r\n pos[t[k]] = 0;\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[0][1], input[1], input[2])\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nclass Node {\r\n constructor(val) {\r\n this.val = val;\r\n this.next = null;\r\n this.prev = null;\r\n }\r\n}\r\nclass Dl {\r\n constructor() {\r\n this.head = null;\r\n this.tail = null;\r\n }\r\n push(val) {\r\n if (!this.head) this.head = this.tail = new Node(val);\r\n else {\r\n let newn = new Node(val);\r\n newn.prev = this.tail;\r\n this.tail = this.tail.next = newn;\r\n }\r\n }\r\n shift(val) {\r\n let newN = new Node(val);\r\n newN.next = this.head;\r\n this.head = newN;\r\n }\r\n remove(val) {\r\n let ind = 1,\r\n p = this.head;\r\n while (p) {\r\n if (p.val === val) {\r\n if (p.prev === null) return ind;\r\n else if (p.next === null) {\r\n this.shift(p.val);\r\n p.prev = null;\r\n this.tail = p.prev;\r\n return ind;\r\n } else {\r\n this.shift(p.val);\r\n p.prev.next = p.next;\r\n p.next.prev = p.prev;\r\n return ind;\r\n }\r\n break;\r\n }\r\n p = p.next;\r\n ind++;\r\n }\r\n }\r\n}\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let q = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let list = new Dl();\r\n for (let i = 0; i < n; i++) list.push(arr[i]);\r\n let res = \"\";\r\n for (let i = 0; i < k; i++) res += list.remove(q[i]) + \" \";\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "26aef004295df530352485ce53b47364"} {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var l1 = parseInt(caseArray[0]);\r\n var r1 = parseInt(caseArray[1]);\r\n var l2 = parseInt(caseArray[2]);\r\n var r2 = parseInt(caseArray[3]);\r\n var result = l1;\r\n if (l1 < l2)\r\n {\r\n if (r1 >= l2)\r\n {\r\n result = l2;\r\n }\r\n else\r\n {\r\n result = l1 + l2;\r\n }\r\n }\r\n if (l1 > l2)\r\n {\r\n if (l1 <= r2)\r\n {\r\n result = l1;\r\n }\r\n else \r\n {\r\n result = l1 + l2;\r\n }\r\n }\r\n print(result);\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var l1 = a[0], r1 = a[1], l2 = a[2], r2 = a[3];\n if(Math.max(l1, l2) <= Math.min(r1, r2)){\n console.log(Math.max(l1, l2));\n }else{\n console.log(l1 + l2);\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [l1, r1, l2, r2] = readline().split(' ').map(Number);\r\n\r\n if (r1 < l2 || r2 < l1) {\r\n output(l1 + l2);\r\n } else {\r\n output(Math.max(l1, l2));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const total = +input[0];\n\n for (let i = 1; i <= total; i++) {\n console.log(solve(input[i]));\n }\n\n process.exit();\n});\n\nfunction solve(str) {\n let [l1, r1, l2, r2] = str.split(' ').map(ele => +ele);\n if (r1 >= l2 && l1 <= r2) {\n return Math.max(l1, l2);\n }\n return l1 + l2;\n}\n\n\n\n\t\t\t\t\t \t\t \t \t \t \t \t\t\t \t\t"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const [a, b, c, d] = arr\n if (a > c) return solve([c, d, a, b])\n if (c <= b) {\n return c\n } else {\n return a + c\n }\n}\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet [inputString, currentLine] = ['', 0];\r\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\nconst input = () => inputString[currentLine++];\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const a = Array(51).fill(0);\r\n const [l1, r1, l2, r2] = input().split(' ').map(Number);\r\n for(let i = l1; i <= r1; i++){\r\n a[i] += 1;\r\n }\r\n for(let i = l2; i <= r2; i++){\r\n a[i] += 1;\r\n }\r\n let two = false;\r\n for(let i = 1; i < 51; i++){\r\n if(a[i] === 2) two = true;\r\n }\r\n let ans = l1+l2;\r\n if(two){\r\n for(let i = 1; i < 51; i++){\r\n if(a[i] === 2){\r\n ans = Math.min(ans, i);\r\n break;\r\n }\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(a) {\r\n const [l1, r1, l2, r2] = a;\r\n if (l1 <= l2) {\r\n if (r1 >= l2) {\r\n return l2;\r\n } else {\r\n return l1 + l2;\r\n }\r\n } else {\r\n if (l1 <= r2) {\r\n return l1;\r\n } else {\r\n return l1 + l2;\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [l1, r1, l2, r2] = ra();\n LT({l1, r1, l2, r2}) \n for (let i=1; i<=100; i++){\n for (let j=0; j<=i; j++){\n let min_cnt = j;\n let max_cnt = i-j;\n if (j==0){\n min_cnt = i;\n max_cnt = i;\n }\n if (l1<=min_cnt && min_cnt<=r1)\n if (l2<=max_cnt && max_cnt<=r2)\n return i;\n }\n }\n throw 'error';\n};\n "}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nconst calc = ()=>{\n /* read */\n let [l1, r1, l2, r2] = ra();\n\n /* solve */\n let result = 0;\n\n if (l1 <= l2 && l2 <= r1) {\n return l2;\n }\n if (l2 <= l1 && l1 <= r2) {\n return l1;\n }\n\n return l1 + l2;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline().split(' ').map((t) => +t);\r\n\r\n print(Task1(a));\r\n \r\n}\r\n\r\nfunction Task1(arr){\r\n\r\n var l1 = arr[0];\r\n var r1 = arr[1];\r\n var l2 = arr[2];\r\n var r2 = arr[3];\r\n var res = l1 + l2;\r\n if (l1 <= l2 && l2 <= r1) res = l2;\r\n if (l2 <= l1 && l1 <= r2) res = l1;\r\n return res;\r\n\r\n}"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var _a = readline().split(' ').map(function (v) { return +v; }), l1 = _a[0], r1 = _a[1], l2 = _a[2], r2 = _a[3];\r\n var ans = void 0;\r\n if (r1 >= l2 && r2 >= l1) {\r\n ans = Math.max(l1, l2);\r\n }\r\n else {\r\n ans = l1 + l2;\r\n }\r\n print(ans);\r\n}\r\n"}, {"source_code": "let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number), a = k[0], b = k[1], c = k[2], d = k[3]\n \n if(Math.max(a, c) <= Math.min(b, d)){\n console.log(Math.max(a, c));\n }else{\n console.log(a + c);\n }\n }\n});\n \n \n \n\n"}], "negative_code": [], "src_uid": "c783eaf1bf7e4e7321406431030d5aab"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u > v) return console.log('NO')\r\n\r\n var ans = true\r\n var count = 0\r\n\r\n for (let i = 0; i < 40; i++) {\r\n if (u >> i & 1) count++\r\n\r\n if (v >> i & 1) {\r\n if(count<=0) ans = false\r\n count--\r\n }\r\n }\r\n console.log(ans?'YES':'NO')\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n let u = rn(),\r\n v = rn();\r\n if (u > v) return 'NO';\r\n if (u === v) return 'YES';\r\n if (u % 2 === 0 && v % 2 === 1) return 'NO';\r\n const count = num => {\r\n let cnt = 0;\r\n while (num) {\r\n cnt++;\r\n num -= num & -num;\r\n }\r\n return cnt;\r\n };\r\n if (count(u) < count(v)) return 'NO';\r\n let a = 0,\r\n b = 0;\r\n for (let i = 0; i < 32; i++) {\r\n if (1 << i > v) break;\r\n if (v & 1 << i) a++;\r\n if (u & 1 << i) b++;\r\n if (a > b) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n let u = rn(),\r\n v = rn();\r\n if (u > v) return 'NO';\r\n if (u === v) return 'YES';\r\n if (u % 2 === 0 && v % 2 === 1) return 'NO';\r\n const count = num => {\r\n let cnt = 0;\r\n while (num) {\r\n cnt++;\r\n num -= num & -num;\r\n }\r\n return cnt;\r\n };\r\n if (count(u) < count(v)) return 'NO';\r\n while (u) {\r\n if (v & 1 && !(u & 1)) return 'NO';\r\n v >>= 1;\r\n u >>= 1;\r\n }\r\n return 'YES';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const u = rn(),\r\n v = rn();\r\n if (u > v) return 'NO';\r\n if (u === v) return 'YES';\r\n if (u % 2 === 0 && v % 2 === 1) return 'NO';\r\n const count = num => {\r\n let cnt = 0;\r\n while (num) {\r\n cnt++;\r\n num -= num & -num;\r\n }\r\n return cnt;\r\n };\r\n if (count(u) < count(v)) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u > v) return console.log('NO')\r\n\r\n var ans = true\r\n var count = 0\r\n\r\n for (let i = 0; i < 40; i++) {\r\n if (u >> i & 1) count++\r\n\r\n if (v >> i & 1) {\r\n if(count<0) {\r\n ans = false\r\n break\r\n }\r\n count--\r\n }\r\n }\r\n console.log(ans?'YES':'NO')\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u > v) return console.log('NO')\r\n\r\n var ans = true\r\n var count = 0\r\n\r\n for (let i = 0; i < 40; i++) {\r\n if (u >> i & 1) count++\r\n\r\n if (v >> i & 1) {\r\n if(count<0) ans = false\r\n count--\r\n }\r\n }\r\n console.log(ans?'YES':'NO')\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}], "src_uid": "a4e605859608d0c730ecbbee9ffc92d7"} {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n }\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst isBalanced = (s) => {\n let r_cnt = 0;\n let l_cnt = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === ')') r_cnt++;\n if (s[i] === '(') l_cnt++;\n }\n return r_cnt === l_cnt;\n};\n\nconst main = () => {\n let n = parseInt(readline());\n let s = readline();\n if (!isBalanced(s)) return print(-1);\n\n let needs = false;\n let l_cnt = 0;\n let r_cnt = 0;\n let left = n;\n let cnt = 0;\n for (let i = 0; i < n; i++) {\n if (s[i] === ')') r_cnt++;\n if (s[i] === '(') l_cnt++;\n // print({ r_cnt, l_cnt, left, i, needs });\n if (r_cnt > l_cnt) {\n left = Math.min(left, i);\n needs = true;\n } else if (needs && r_cnt === l_cnt) {\n needs = false;\n cnt += i - left + 1;\n left = n;\n }\n }\n print(cnt)\n};\n", "positive_code": [{"source_code": "function main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (l) { return l.trim(); });\n var l = parseInt(lines.shift(), 10);\n console.log(solve(l, lines.shift()));\n}\nfunction solve(l, s) {\n var cnt = 0;\n var cval = 0;\n var countingwrong = false;\n var failcnt = 0;\n for (var i = 0; i < l; i++) {\n if (s[i] === \"(\") {\n cval++;\n }\n else {\n cval--;\n }\n if (countingwrong) {\n if (cval === 0) {\n failcnt++;\n cnt += failcnt;\n failcnt = 0;\n countingwrong = false;\n }\n else {\n failcnt++;\n }\n }\n else if (cval < 0) {\n countingwrong = true;\n failcnt++;\n }\n }\n if (cval !== 0) {\n return -1;\n }\n return cnt;\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var n = +readline();\n var str = readline();\n\n var bracketsSum = 0;\n var wrongBracketsSum = 0;\n for (var i = 0; i < str.length; i++) {\n if (str[i] === \"(\") {\n if (bracketsSum === -1) {\n wrongBracketsSum++;\n }\n bracketsSum++;\n }\n if (str[i] === \")\") {\n bracketsSum--;\n }\n if (bracketsSum < 0) {\n wrongBracketsSum++;\n }\n }\n if (bracketsSum !== 0) {\n print(-1);\n return;\n }\n print(wrongBracketsSum);\n}\nmain()"}, {"source_code": "const processData = (lines) => {\n const s = lines[1].split('')\n\n let balance = 0\n\n // const prefix = []\n let acc = 0\n let neg = false\n let sum = 0\n let peak = 0\n for (let j =0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "const processData = (lines) => {\n const s = lines[1].split('')\n\n let balance = 0\n\n const prefix = []\n let acc = 0\n let neg = false\n let sum = 0\n let peak = 0\n for (let j =0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const s = lines[1].split('')\n\n let balance = 0\n\n // const prefix = []\n let acc = 0\n let neg = false\n let sum = 0\n let peak = 0\n for (let j =0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var n = +readline();\n var str = readline();\n\n var bracketsSum = 0;\n var wrongBracketsSum = 0;\n for (var i = 0; i < str.length; i++) {\n if (str[i] === \"(\") {\n if (bracketsSum === -1) {\n wrongBracketsSum++;\n }\n bracketsSum++;\n }\n if (str[i] === \")\") {\n bracketsSum--;\n }\n if (bracketsSum < 0) {\n wrongBracketsSum++;\n }\n }\n if (bracketsSum !== 0) {\n print(-1);\n }\n print(wrongBracketsSum);\n}\nmain()"}], "src_uid": "e3275cd360d8f46cbbae03dfa86b924a"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n let t = a.reduce((a, b) => a ^ b, 0);\r\n if (t === 0) return 'YES';\r\n if (m < 3) return 'NO';\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v] of b) {\r\n add(u - 1, v - 1);\r\n add(v - 1, u - 1);\r\n }\r\n const vis = new Array(n);\r\n let res = 0;\r\n const dfs1 = RTI(i => {\r\n vis[i] = 1;\r\n const inside = () => {\r\n let params = [];\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k];\r\n if (vis[j]) continue;\r\n params.push([j]);\r\n }\r\n return params;\r\n };\r\n const after = (...result) => {\r\n let ans = result.reduce((a, b) => a ^ b, 0) ^ a[i];\r\n if (ans === t) {\r\n res++;\r\n ans = 0;\r\n }\r\n return ans;\r\n };\r\n return [inside, after];\r\n });\r\n dfs1(0);\r\n return res >= 2 ? 'YES' : 'NO';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = result => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, arr, edges))\n }\n// })()\n})\n\nfunction solve(n, k, arr, edges) {\n const xor = arr.reduce((s, x) => s ^ x, 0)\n if (!xor) return 'YES'\n if (k - 1 < 2) return 'NO'\n// console.log(xor)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited, arr, target) {\n const stack = [[r, 0, -1]]\n const xor = []\n let found = 0\n let cut = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n cut++\n xor[u] = arr[u - 1]\n nb.forEach(v => {\n if (v !== p) xor[u] ^= xor[v]\n })\n if (xor[u] === target) {\n found++\n // console.log('found', cut, arr.length)\n if (found === 2) return true\n xor[u] = 0\n }\n stack.pop()\n }\n }\n // console.log(xor)\n return false\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n let t = a.reduce((a, b) => a ^ b, 0);\r\n if (t === 0) return 'YES';\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v] of b) {\r\n add(u - 1, v - 1);\r\n add(v - 1, u - 1);\r\n }\r\n const vis = new Array(n);\r\n let res = 0;\r\n const dfs1 = RTI(i => {\r\n vis[i] = 1;\r\n const inside = () => {\r\n let params = [];\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k];\r\n if (vis[j]) continue;\r\n params.push([j]);\r\n }\r\n return params;\r\n };\r\n const after = (...result) => {\r\n let ans = result.reduce((a, b) => a ^ b, 0) ^ a[i];\r\n if (ans === t) {\r\n res++;\r\n ans = 0;\r\n }\r\n return ans;\r\n };\r\n return [inside, after];\r\n });\r\n dfs1(0);\r\n return res >= 2 ? 'YES' : 'NO';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = result => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n let t = a.reduce((a, b) => a ^ b, 0);\r\n if (t === 0) return 'YES';\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0);\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, d[j]++, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v] of b) {\r\n add(u - 1, v - 1);\r\n add(v - 1, u - 1);\r\n }\r\n const vis = new Array(n);\r\n let res = 0;\r\n const dfs = i => {\r\n vis[i] = 1;\r\n let ans = 0;\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k];\r\n if (vis[j]) continue;\r\n let sum = dfs(j);\r\n if (sum === t) {\r\n res++;\r\n sum = 0;\r\n }\r\n ans ^= sum;\r\n if (ans === t) {\r\n res++;\r\n ans = 0;\r\n }\r\n }\r\n return ans ^ a[i];\r\n };\r\n dfs(0);\r\n return res > 2 ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, arr, edges))\n }\n// })()\n})\n\nfunction solve(n, k, arr, edges) {\n const xor = arr.reduce((s, x) => s ^ x, 0)\n if (!xor) return 'YES'\n// console.log(xor)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited, arr, target) {\n const stack = [[r, 0, -1]]\n const xor = []\n let found = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n xor[u] = arr[u - 1]\n nb.forEach(v => {\n if (v !== p) xor[u] ^= xor[v]\n })\n if (xor[u] === target) {\n found++\n if (found === 2 && u !== r) return true\n xor[u] = 0\n }\n stack.pop()\n }\n }\n // console.log(xor)\n return false\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, arr, edges))\n }\n// })()\n})\n\nfunction solve(n, k, arr, edges) {\n const xor = arr.reduce((s, x) => s ^ x, 0)\n if (!xor) return 'YES'\n// console.log(xor)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited, arr, target) {\n const stack = [[r, 0, -1]]\n const xor = []\n let found = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n xor[u] = arr[u - 1]\n nb.forEach(v => {\n if (v !== p) xor[u] ^= xor[v]\n })\n if (xor[u] === target) {\n found++\n if (found === 2) return true\n xor[u] = 0\n }\n stack.pop()\n }\n }\n // console.log(xor)\n return false\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n console.log(solve(n, k, arr, edges))\n }\n// })()\n})\n\nfunction solve(n, k, arr, edges) {\n const xor = arr.reduce((s, x) => s ^ x, 0)\n if (!xor) return 'YES'\n\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n return dfs(adj, 1, {}, arr, xor) ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited, arr, target) {\n const stack = [[r, 0, -1]]\n const xor = []\n let found = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n xor[u] = arr[u]\n nb.forEach(v => {\n if (v !== p) xor[u] ^= xor[v]\n })\n if (xor[u] === target) {\n found++\n if (found === 2) return true\n xor[u] = 0\n }\n stack.pop()\n }\n }\n return false\n}\n"}], "src_uid": "ad61d92fde608b304c0362420c2ae6dc"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n let res = n,\r\n t = 0;\r\n next: for (let i = 0; i < n; i++) {\r\n let ans = i + 1,\r\n sum = 0,\r\n pre = i + 1;\r\n t += a[i];\r\n for (let j = i + 1; j < n; j++) {\r\n sum += a[j];\r\n if (sum === t) {\r\n sum = 0;\r\n ans = Math.max(ans, j - pre + 1);\r\n pre = j + 1;\r\n } else if (sum > t) {\r\n continue next;\r\n }\r\n }\r\n if (sum === 0 && pre === n) {\r\n res = Math.min(res, ans);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = Array(n)\n for (let i = 0; i < arr.length; i++) {\n sum[i] = arr[i]\n if (i) sum[i] += sum[i - 1]\n }\n let r = n\n for (let i = 1; i <= arr.length; i++) {\n const s = sum[i - 1]\n if (sum[n - 1] % s) continue\n let p = i\n let ok = true\n let temp = i\n while (p < n) {\n let j = p\n let now = arr[j]\n while (now < s && j + 1 < n) {\n now += arr[++j]\n }\n if (now !== s) {\n ok = false\n break\n }\n temp = Math.max(temp, j - p + 1)\n // console.log(s, ok, temp, '-', p, j, now)\n p = j + 1\n }\n if (ok) r = Math.min(r, temp)\n }\n return r\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n const helper = (l, r, sum) => {\r\n let s = 0,\r\n dis = -1;\r\n while (r < n) {\r\n s += arr[r];\r\n if (s === sum) {\r\n s = 0;\r\n dis = Math.max(r - l + 1, dis);\r\n r++;\r\n l = r;\r\n } else r++;\r\n }\r\n\r\n return s === 0 ? dis : -1;\r\n };\r\n if (arr.length === 1) {\r\n console.log(1);\r\n continue;\r\n }\r\n let sum = arr[0],\r\n ans = Infinity;\r\n for (let i = 1; i < n; i++) {\r\n let k = helper(i, i, sum);\r\n if (k !== -1) ans = Math.min(ans, Math.max(i, k));\r\n sum += arr[i];\r\n }\r\n console.log(ans === Infinity ? n : ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let a = readline().split(' ').map(Number)\r\n console.log(solve(n, a))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, a) => {\r\n let total = 0\r\n let res = n\r\n for (let i = 0; i < n; i++) {\r\n total += a[i]\r\n let ans = i + 1\r\n let sum = 0\r\n let found = true\r\n let k = i\r\n\r\n for (let j = i + 1; j < n; j++) {\r\n if (sum + a[j] == total) {\r\n ans = Math.max(ans, (j - k))\r\n k = j\r\n sum = 0\r\n } else if ((sum + a[j]) < total) {\r\n sum += a[j]\r\n } else {\r\n found = false\r\n break\r\n }\r\n }\r\n\r\n if (found && sum == 0) res = Math.min(ans, res)\r\n\r\n }\r\n return res\r\n}\r\n\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n const helper = (l, r, sum) => {\r\n let s = 0,\r\n dis = -1;\r\n while (r < n) {\r\n s += arr[r];\r\n if (s === sum) {\r\n s = 0;\r\n dis = Math.max(r - l + 1, dis);\r\n r++;\r\n l = r;\r\n }\r\n r++;\r\n }\r\n\r\n return dis;\r\n };\r\n let sum = arr[0],\r\n ans = Infinity;\r\n for (let i = 1; i < n; i++) {\r\n let k = helper(i, i, sum);\r\n if (k !== -1) ans = Math.min(ans, k);\r\n sum += arr[i];\r\n }\r\n console.log(ans === Infinity ? n : ans);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "1ca582e932ac93ae2e1555deb16e3c3c"} {"source_code": "var nbOfElement = Number(readline());\nvar direction = readline();\nvar elements = readline()\n .split(' ')\n .map(Number);\n\nvar pair = [];\nfor (var i = 1; i < nbOfElement; ++i) {\n if (direction[i - 1] === 'R' && direction[i] === 'L') {\n pair.push([i - 1, i]);\n }\n}\n\nvar smallestPair = Infinity;\nfor (var i = 0; i < pair.length; i++) {\n smallestPair = Math.min(\n smallestPair,\n Math.round((elements[pair[i][1]] - elements[pair[i][0]]) / 2)\n );\n}\n\nif (pair.length === 0) {\n print(-1);\n} else {\n print(smallestPair);\n}", "positive_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar n = rdn();\nvar coms = readline().split(\"\");\nvar x = rda();\n\nvar ans = Infinity;\nfor(var i = 0; i < n-1; i++){\n if(coms[i] == \"R\" && coms[i+1] == \"L\"){\n ans = Math.min(ans, (x[i+1]-x[i])/2);\n }\n}\nans = (ans == Infinity) ? -1 : ans;\n\nwrite(ans);"}, {"source_code": "var n=parseInt(readline());\nvar d=readline();\nd += \"E\";\nvar pos=readline().split(' ');\nvar mn = 1000000000;\nfunction go(el, i, a){\n\tif(d[i] == 'R' && d[i+1] == 'L'){\n\t\tmn = Math.min(mn, (a[i+1] - a[i])/2);\n\t};\n};\npos.forEach(go);\nif(mn != 1000000000){\n\tprint(mn);\n} else {\n\tprint(-1);\n};"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, map, position, ans = [];\n\nn = Number(readline());\nmap = readline().replace(/\\r$/, '').split('');\nposition = readline().replace(/\\r$/, '').split(' ').map(Number);\n\nfor (i = 0; i < n - 1; i++) {\n\n if (map[i] !== map[i + 1]\u3000&& map[i] === 'R') {\n\n ans.push(Math.abs(position[i] - position[i + 1]) / 2);\n } else if (map === map[i + 1] && map[i] === 'L') {\n\n ans.push(position[i + 1] - position[i]);\n } else if (map === map[i + 1] && map[i] === 'R') {\n\n ans.push(position[i] - position[i + 1]);\n } \n}\n\nans = ans.filter(x => x > 0);\n\nif (ans.length === 0) {\n \n write(-1);\n} else {\n\n write(Math.min(...ans));\n}"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var dir = readline();\n var arr = readline().split(\" \").map(Number);\n \n var min = Infinity;\n \n for (var i = 0; i < dir.length - 1; i++) {\n if (dir[i] === 'R' && dir[i + 1] === 'L') {\n var low = (arr[i + 1] - arr[i]) / 2;\n if (low < min) {\n min = low;\n }\n }\n }\n \n print(min === Infinity? -1: min);\n \n})();"}], "negative_code": [{"source_code": "(function() {\n var n = parseInt(readline());\n var dir = readline();\n var arr = readline().split(\" \").map(Number);\n \n var min = Infinity;\n \n for (var i = 0; i < dir.length - 1; i++) {\n if (dir[i] === 'R' && dir[i + 1] === 'L') {\n var low = (arr[i + 1] - arr[i]) / 2;\n if (low < min) {\n min = low;\n }\n }\n }\n \n print(min);\n \n})();"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var dir = readline();\n var arr = readline().split(\" \").map(Number);\n \n var min = Infinity;\n var collision = [];\n \n while(dir.length) {\n var found = dir.indexOf('RL');\n collision.push(found);\n dir = dir.slice(found + 2);\n }\n \n if (!collision.length) {\n print(-1);\n return;\n }\n \n collision.forEach((col) => {\n var dist = (arr[col + 1] - arr[col])/ 2;\n if (dist < min) {\n min = dist;\n }\n });\n \n print(min);\n \n})();"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var dir = readline();\n var arr = readline().split(\" \").map(Number);\n \n var min = Infinity;\n var collision = [];\n \n while(dir.length) {\n var found = dir.indexOf('RL');\n if (found === -1) {\n break;\n }\n collision.push(found);\n dir = dir.slice(found + 2);\n }\n \n if (!collision.length) {\n print(-1);\n return;\n }\n \n collision.forEach((col) => {\n var dist = (arr[col + 1] - arr[col])/ 2;\n if (dist < min) {\n min = dist;\n }\n });\n \n print(min);\n \n})();"}], "src_uid": "ff0843cbd7c3a07c7d7d0be46b03a700"} {"source_code": "var likesCount = parseInt(readline());\nvar likes = readline().split(' ').map(function (x) {return parseInt(x)})\n\nvar winnerId = -1\nvar map = {}\n\nfor (var i = 0; i < likesCount; i++) {\n\tvar photoId = likes[i]\n\n\tif (map[photoId] === undefined) {\n\t\tmap[photoId] = 0\n\t}\n\tvar newLikesCount = ++map[photoId]\n\n\tif (winnerId === -1) {\n\t\twinnerId = photoId\n\t} else {\n\t\tif (newLikesCount > map[winnerId]) {\n\t\t\twinnerId = photoId\n\t\t}\n\t}\n}\n\nprint(winnerId);", "positive_code": [{"source_code": "var count = readline();\nvar data = readline().split(\" \");\nvar db = {};\nvar maxId = data[0];\ndata.forEach(function (v, c) {\n c = db[v] ? ++db[v] : (db[v] = 1);\n if (db[maxId] < c) { maxId = v }\n});\nprint(maxId);"}, {"source_code": "var l = readline().split(' ');\nvar n = +l[0];\nvar a = readline().split(' ');\nvar dat = {\n};\nvar max = 0;\nfor (var i = 0; i < a.length; i++) {\n\tdat[a[i]] = dat[a[i]] ? dat[a[i]] + 1 : 1;\n\tmax = dat[a[i]] > max ? dat[a[i]] : max;\n}\nvar list = [];\nfor(var i in dat){\n\tif(dat[i]==max){\n\t\tlist.push(i);\n\t}\n}\n\nfor (var i = a.length - 1; i >= 0; i--) {\n\tif(list.length == 1){\n\t\tbreak;\n\t}\n\tvar index = list.indexOf(a[i]);\n\tif(index!=-1){\n\t\tlist.splice(index,1);\n\t}\n}\nprint(list[0]);"}, {"source_code": "var likes = readline().split(' '),\nlikeIds = readline().split(' '),\nlastBiggest = {\n id: likeIds[0],\n count: 1\n},\nlikeObj = {};\nlikeIds.map(function(el){\n likeObj[el] = typeof likeObj[el] !== \"undefined\" ? likeObj[el]+1 : 1;\n if (lastBiggest.count < likeObj[el]) {\n lastBiggest = {\n id: el,\n count: likeObj[el]\n }\n }\n});\nprint(lastBiggest.id);"}, {"source_code": "var readInt = () => parseInt(readline())\nvar readIntArray = () => readline().split(' ').map(item => parseInt(item))\nArray.prototype.fill = function(value) {\n for (var i = 0; i < this.length; i++)\n this[i] = value\n return this\n}\nvar n = readInt()\nvar l = readIntArray()\nvar l2 = []\nl.forEach((i, index) => l2[i-1]={\n index: index, \n count: l2[i-1] ? l2[i-1].count+1 : 1\n})\nl2 = l2.filter(i => i)\nvar max = Math.max(...l2.map(i => i.count))\nvar ii = l2.filter(i => i.count === max).map(i => i.index)\nprint(l[Math.min(...ii)])"}], "negative_code": [], "src_uid": "e4a2354159fc4cab7088e016cf17ae6c"} {"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const n = parseInt(lines[0]);\n const numbers = lines[1].split(\" \").map(x => parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort((x,y)=>x-y);\n odd.sort((x,y)=> x-y);\n let num = 0;\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; ii*1);\n\nvar odd=numbers.filter(i => i%2==0);\nvar even = numbers.filter(i => i%2==1);\nvar diff= Math.abs(odd.length-even.length)\n\nif(diff>1){\n\tvar bigger= odd.length>even.length? odd : even;\n\tbigger=bigger.sort((a,b)=>a-b).slice(0, diff-1);\n\tprint(bigger.reduce((s,c)=>s+c, 0));\n}\nelse{\n\tprint(0);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number).sort((a, b) => a - b);\n const even = arr.filter(x => x % 2 === 0);\n const odd = arr.filter(x => x % 2 === 1);\n let sum = arr.reduce((a, b) => a + b, 0);\n\n while (even.length && odd.length) {\n sum -= even.pop();\n sum -= odd.pop();\n }\n\n const max = Math.max(even.pop() || 0, odd.pop() || 0);\n sum -= max;\n\n console.log(sum);\n\n // const arr = d.split(' ').map(Number);\n // arr.sort((a, b) => a - b);\n // let ans = arr.reduce((a, b) => a + b, 0);\n // const even = [];\n // const odd = [];\n\n // for (let i = 0; i < arr.length; i++) {\n // if (arr[i] % 2 === 0) {\n // even.push(arr[i]);\n // }\n // else {\n // odd.push(arr[i]);\n // }\n // }\n\n // if (even.length > odd.length) {\n // ans -= even.pop();\n\n // while (even.length && odd.length) {\n // ans -= odd.pop();\n // ans -= even.pop();\n // }\n // }\n // else if (odd.length > even.length) {\n // ans -= odd.pop();\n\n // while (even.length && odd.length) {\n // ans -= even.pop();\n // ans -= odd.pop();\n // }\n // }\n // else {\n // while (even.length && odd.length) {\n // ans -= even.pop();\n // ans -= odd.pop();\n // }\n // }\n\n // console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let ans = arr.reduce((a, b) => a + b, 0);\n const even = [];\n const odd = [];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] % 2 === 0) {\n even.push(arr[i]);\n }\n else {\n odd.push(arr[i]);\n }\n }\n\n if (even.length > odd.length) {\n ans -= even.pop();\n\n while (even.length && odd.length) {\n ans -= odd.pop();\n ans -= even.pop();\n }\n }\n else if (odd.length > even.length) {\n ans -= odd.pop();\n\n while (even.length && odd.length) {\n ans -= even.pop();\n ans -= odd.pop();\n }\n }\n else {\n while (even.length && odd.length) {\n ans -= even.pop();\n ans -= odd.pop();\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "\nvar stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { stdin += data; });\nprocess.stdin.on('end', function () { main(stdin); });\n\nvar stdin_row = 0, stdin_rows;\nfunction readLine() { if (!stdin_rows) stdin_rows = stdin.split(\"\\n\"); return stdin_rows[stdin_row++]; } // to trim ?\nfunction readLineVals() { return readLine().trim().split(/\\s+/); }\n\nconst debug = 0\nvar log = console.log;\nvar dbg = debug ? console.log : _ => {};\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n\tvar n = readLine() * 1;\n\tvar vals = readLineVals();\n\tif (n!=vals.length)\n\t\tthrow \"input parsing pb \"+n+\" \"+vals;\n\n\tvar odd = [], even = [];\n\tfor (var i =0; i b-a)\n\teven = even.sort((a,b)=> b-a)\n\tdbg(odd)\n\tdbg(even)\n\n\tnoff = Math.min(odd.length, even.length);\n\todd = odd.slice(noff)\n\teven = even.slice(noff)\n\tdbg(odd)\n\tdbg(even)\n\n\tif (odd.length>0)\n\t\tremains = odd;\n\telse\n\t\tremains = even;\n\tremains.shift();\n\tdbg(remains)\n\n\tvar sum = remains.reduce((x, acc) => { return x*1+acc*1}, 0);\n\tlog(sum)\n\n\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const n = parseInt(lines[0]);\n const numbers = lines[1].split(\" \").map(x => parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n let num = 0;\n if (even.length > odd.length + 1) {\n for (i=0; i even.length +1){\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n if (n === 2000) {\n console.log(even.length, odd.length);\n }\n let num = 0;\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n let num = 0;\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n if (n === 2000 && numbers[0] !=376688) {\n console.log(even.length, \" \", odd.length);\n }\n let num = 0;\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n let num = 0;\n if (even.length > odd.length + 1) {\n for (i=0; i even.length +1) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n let num = 0;\n if (even.length > odd.length + 1) {\n for (i=0; i even.length +1) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort((x,y)=>x-y);\n odd.sort((x,y)=> x-y);\n let num = 0;\n console.log(even);\n console.log(odd);\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n if (n === 2000 && numbers[0] !=376688 && numbers[0]!=740590) {\n console.log(even.length, \" \", odd.length);\n }\n let num = 0;\n if (even.length > odd.length) {\n for (i=0; i even.length) {\n for (i=0; i parseInt(x));\n const even = [];\n const odd = [];\n numbers.forEach(element => {\n if (element%2 === 0) \n even.push(element);\n else \n odd.push(element);\n });\n even.sort();\n odd.sort();\n let num = 0;\n if (even.length > odd.length+1) {\n for (i=0; i even.length +1){\n for (i=0; i {};\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n\tvar n = readLine() * 1;\n\tvar vals = readLineVals();\n\tif (n!=vals.length)\n\t\tthrow \"input parsing pb \"+n+\" \"+vals;\n\n\tvar odd = [], even = [];\n\tfor (var i =0; i b-1)\n\teven = even.sort((a,b)=> b-1)\n\tnoff = Math.min(odd.length, even.length);\n\tdbg(odd)\n\tdbg(even)\n\n\todd = odd.slice(noff)\n\teven = even.slice(noff)\n\tdbg(odd)\n\tdbg(even)\n\n\tif (odd.length>0)\n\t\tremains = odd;\n\telse\n\t\tremains = even;\n\tremains.pop();\n\tdbg(remains)\n\n\tvar sum = remains.reduce((x, acc) => { return x*1+acc*1}, 0);\n\tlog(sum)\n\n\n}"}], "src_uid": "b80fed46a9e2356dad03dd3ec01523d4"} {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (n, m, q, A, Q)=>{\n let F = [];\n let SUM = 0;\n for (let i=0; i{\n let result = 0;\n for (let i=x; i>=0; i = (i & (i+1))-1){\n for (let j=y; j>=0; j = (j & (j+1))-1){\n result += F[i][j];\n }\n }\n return result;\n };\n let inc = (x, y, delta)=>{\n for (let i=x; i0){\n ans += sum(n-1, columns-1);\n }\n ans += sum(SUM%n-1, columns)\n ans -= sum(SUM%n-1, columns-1)\n print(SUM-ans)\n }\n};\n \nfunction main() {\n let T = 1||+readline()\n while (T--){\n let [n, m, q] = ra();\n let A = [];\n for (let i=0; iparseInt(x));\r\n\r\n n = nmq[0];\r\n m = nmq[1];\r\n q = nmq[2];\r\n\r\n var desk = [];\r\n for (var i = 0; i < n; i++) {\r\n var row = readline().split('').map(x=> x == '.' ? 0 : 1);\r\n desk.push(row);\r\n }\r\n\r\n function hToC(h) {\r\n return desk[(h-1) % n][Math.floor((h-1) / n)];\r\n }\r\n\r\n function cToH(r, c) {\r\n return c * n + r + 1;\r\n }\r\n\r\n var head = 0;\r\n for (var r = 0; r < n; r++) {\r\n for (var c = 0; c < m; c++) {\r\n head += desk[r][c];\r\n }\r\n }\r\n var ops = 0;\r\n for (var i = 1; i <= head; i++) {\r\n if (!hToC(i)) {\r\n ops++;\r\n }\r\n }\r\n\r\n function remove(x, y) {\r\n desk[x][y] = 0;\r\n \r\n if (cToH(x, y) > head && !hToC(head)) {\r\n ops--;\r\n }\r\n if (cToH(x, y) < head && hToC(head)) {\r\n ops++;\r\n }\r\n head--;\r\n }\r\n\r\n function add(x, y) {\r\n head++;\r\n desk[x][y] = 1;\r\n if (cToH(x, y) == head) {\r\n } else {\r\n if (cToH(x, y) > head && !hToC(head)) {\r\n ops++;\r\n }\r\n if (hToC(head) && cToH(x, y) < head) {\r\n ops--;\r\n }\r\n }\r\n }\r\n\r\n for (var i = 0; i < q; i++) {\r\n var xy = readline().split(' ').map(x=>parseInt(x));\r\n var x = xy[0] - 1;\r\n var y = xy[1] - 1;\r\n if (desk[x][y]) {\r\n remove(x, y);\r\n } else {\r\n add(x, y);\r\n }\r\n\r\n print(ops);\r\n }"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, m, q, grid, queries)=>{\n let total = 0, outside = 0;\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === '*') {\n total++;\n }\n }\n }\n\n let tX = total % n;\n let tY = Math.floor(total / n);\n // console.log(`DEBUG tx ${tX} ty ${tY}`);\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === '*') {\n if (j > tY) outside++;\n if (j === tY && i >= tX) outside++;\n }\n }\n }\n\n // console.log(`DEBUG outside`, outside);\n\n for (let [x, y] of queries) {\n x--; y--;\n // console.log(`DEBUG x ${x} y ${y}`);\n // console.log(`DEBUG old tx ${tX} ty ${tY}`);\n let toggledOn = false;\n if (grid[x][y] === '*') {\n grid[x][y] = '.';\n total--;\n\n if (y > tY) outside--;\n if (y === tY && x >= tX) outside--;\n\n tX = total % n;\n tY = Math.floor(total / n);\n\n\n if (grid[tX][tY] === '*') {\n outside++;\n }\n } else {\n toggledOn = true;\n total++;\n\n if (grid[tX][tY] === '*') {\n outside--;\n }\n tX = total % n;\n tY = Math.floor(total / n);\n\n grid[x][y] = '*';\n\n if (y > tY) outside++;\n if (y === tY && x >= tX) outside++;\n \n }\n // console.log(`DEBUG toggledOn`, toggledOn);\n // console.log(`DEBUG new tx ${tX} ty ${tY}`);\n // console.log(`DEBUG total`, total);\n console.log(outside);\n }\n\n\n // return outside;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let [n, m, q] = ra();\n let grid = [];\n for (let i = 0; i < n; i++) {\n grid.push(readline().split('')); \n }\n let queries = [];\n for (let i = 0; i < q; i++) {\n queries.push(ra()); \n }\n // console.log(`${calc(n, m, q, grid, queries)}`);\n calc(n, m, q, grid, queries);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m, q] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim().split(''))\n l += n\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, m, grid, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid, qs) {\n const es = []\n let total = 0\n for (let j = 0; j < m; j++) {\n es[j] = 0\n for (let i = 0; i < n; i++) {\n if (grid[i][j] === '.') es[j]++\n if (grid[i][j] === '*') total++\n }\n }\n return qs.map(([r, c]) => {\n r--\n c--\n //\n if (grid[r][c] === '.') {\n grid[r][c] = '*'\n es[c]--\n total++\n } else {\n grid[r][c] = '.'\n es[c]++\n total--\n }\n //\n const k = Math.floor(total / n)\n const rest = total % n\n let ans = k * n\n for (let j = 0; j < k; j++) {\n ans -= es[j]\n }\n for (let i = 0; i < rest; i++) {\n if (grid[i][k] === '*') ans++\n }\n // console.log(total, k, rest, ';', ans)\n return total - ans\n }).join('\\n')\n}\n"}], "negative_code": [{"source_code": "var n, m, q;\r\n var nmq = readline().split(' ').map(x=>parseInt(x));\r\n\r\n n = nmq[0];\r\n m = nmq[1];\r\n q = nmq[2];\r\n\r\n var desk = [];\r\n for (var i = 0; i < n; i++) {\r\n var row = readline().split('').map(x=> x == '.' ? 0 : 1);\r\n desk.push(row);\r\n }\r\n\r\n function hToC(h) {\r\n return desk[(h-1) % n][Math.floor((h-1) / n)];\r\n }\r\n\r\n function cToH(r, c) {\r\n return c * n + r + 1;\r\n }\r\n\r\n var head = 0;\r\n for (var r = 0; r < n; r++) {\r\n for (var c = 0; c < m; c++) {\r\n head += desk[r][c];\r\n }\r\n }\r\n var ops = 0;\r\n for (var i = 1; i <= head; i++) {\r\n if (!hToC(i)) {\r\n ops++;\r\n }\r\n }\r\n\r\n function remove(x, y) {\r\n desk[x][y] = 0;\r\n \r\n if (cToH(x, y) > head) {\r\n ops--;\r\n }\r\n if (cToH(x, y) < head && hToC(head)) {\r\n ops++;\r\n }\r\n head--;\r\n }\r\n\r\n function add(x, y) {\r\n head++;\r\n desk[x][y] = 1;\r\n if (cToH(x, y) == head) {\r\n } else {\r\n if (cToH(x, y) > head && !hToC(head)) {\r\n ops++;\r\n }\r\n if (hToC(head) && cToH(x, y) < head) {\r\n ops--;\r\n }\r\n }\r\n }\r\n\r\n for (var i = 0; i < q; i++) {\r\n var xy = readline().split(' ').map(x=>parseInt(x));\r\n var x = xy[0] - 1;\r\n var y = xy[1] - 1;\r\n if (desk[x][y]) {\r\n remove(x, y);\r\n } else {\r\n add(x, y);\r\n }\r\n\r\n print(ops);\r\n }"}], "src_uid": "9afb205f542c0d8ba4f7fa03faa617ae"} {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst cache = [0, 2];\n\nfunction getMaximumPyramids(n) {\n let total = 0;\n let remaining = n;\n while (remaining >= 2) {\n getNextPyramid();\n total++;\n }\n return total;\n\n function getNextPyramid(h = 1) {\n let required = 2;\n while (required <= remaining){\n required = getRequiredCards(++h);\n }\n remaining -= cache[h-1];\n return h-1;\n }\n\n function getRequiredCards(h) {\n if (h == 1) return 2;\n else {\n const req = (h * 2) + (h - 1) + (cache[h - 1] || getRequiredCards(h - 1));\n cache[h] = req;\n return req;\n }\n }\n}\n\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for (let i = 0; i < n; i++) {\n const result = getMaximumPyramids(parseInt(readLine(), 10));\n console.log(result)\n }\n return;\n}\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r 1) {\n counter++;\n let h = 0;\n while((3*h*h + h) / 2 <= remaining) {\n h++;\n }\n h--;\n let usedCard = (3*h*h + h) / 2;\n remaining = remaining - usedCard;\n }\n\n console.log(counter);\n }\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var currentFloor = 0;\n var nextFloor = 0;\n var count = 0;\n while (n >= 2) {\n var i = 1;\n if (n == 2) {\n count++;\n break;\n } else {\n while (nextFloor - i <= n) {\n currentFloor += i * 3;\n nextFloor = currentFloor + (i + 1) * 3;\n i++;\n }\n n -= currentFloor - i + 1;\n currentFloor = 0;\n nextFloor = 0;\n count++;\n }\n }\n print(count);\n}\n"}, {"source_code": "// Input\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction mandatoryCards(n) { return (3*n*n + n)/2; }\n\nfunction processPyramids(remaining, nbPyramids) {\n if (remaining <= 1) return nbPyramids;\n var maxHeight = 1;\n while(mandatoryCards(maxHeight) <= remaining ) maxHeight++;\n return processPyramids(remaining-mandatoryCards(maxHeight-1), nbPyramids+1);\n}\n\n//main\nfunction main() {\n var nbOfTestCases = parseInt(readline());\n \n for (var i=0 ; i {\n let max = 0;\n let card = +line;\n if (first) {\n first = false\n } else {\n while (card > 1) {\n let maxCard = 2;\n let maxDeck = 1;\n if (maxCard === card) {\n card -= maxCard;\n max++;\n } else {\n while(true) {\n let newMaxDeck = maxDeck + 1;\n let newMaxCard = maxCard + maxDeck + newMaxDeck * 2;\n if (newMaxCard > card) {\n card -= maxCard;\n max++;\n break;\n } else {\n maxCard = newMaxCard;\n maxDeck = newMaxDeck;\n }\n }\n }\n }\n process.stdout.write(`${max}\\n`);\n }\n})"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar outputCount = 0;\n\t\tvar n = nextInt();\n\t\twhile(n >= 2){\n\t\t\tvar count = 1;\n\t\t\twhile(true){\n\t\t\t\tvar req = count * 2 + (count - 1);\n\t\t\t\tif(n < req){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tn -= req;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\toutputCount++;\n\t\t}\n\t\toutput[i] = outputCount;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n\n solve(a);\n }\n}\n\nfunction solve(a) {\n var towers = 0;\n\n if (a < 2) {\n console.log(0);\n return;\n }\n\n while (a > 1) {\n var floor = 1;\n a -= 2;\n while (a >= cardsForFloor(floor+1)) {\n a -= cardsForFloor(floor+1);\n floor++;\n }\n towers++;\n }\n\n console.log(towers);\n}\n\nconst cache = [0, 2];\n\nfunction cardsForFloor(floor) {\n if (!(floor in cache)) {\n cache[floor] = ((floor)*2 + (floor -1));\n }\n\n return cache[floor];\n}"}, {"source_code": "//Card Constructions\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let t = +lines[0];\n\n let o = {};\n\n let f = (n) => {\n \t\n \tif(n < 2) {\n \t\treturn 0;\n \t}\n\n \tlet k = Math.sqrt(2 * n / 3);\n \tfor(let i = 1; i <= k + 1; i++) {\n\n \t\tlet r;\n\n \t\tif(o[i]) {\n \t\t\tr = o[i];\n \t\t} else {\n \t\t\to[i] = (i * ((3 * i) + 1)) / 2;\n \t\t\tr = o[i];\n \t\t}\n\n \t\tif(r > n) {\n \t\t\treturn 1 + f(n - (((3 * Math.pow(i - 1, 2)) + (i - 1)) / 2));\n \t\t}\n \t}\n }\n\n for(let i = 0; i < t; i++) {\n \tlet n = +lines[i + 1];\n\n \tprocess.stdout.write(f(n) + '\\n');\n }\n\n return;\n});"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i 2) {\n let sum = 2\n let pos = 0\n while (sum <= a) {\n pos++\n sum += 2 + (pos)*3\n // console.log(sum)\n }\n sum -= 2 + (pos)*3\n acc++\n a -= sum\n }\n if (a === 2) {\n acc++\n }\n console.log(acc)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let result = 0;\n while (N >= 2) {\n let cost = find(N);\n N -= cost;\n result++;\n }\n\n print(result);\n }\n}\n\nfunction find(N) {\n let l = 1, r = N, res = 0;\n while (l <= r) {\n let m = Math.floor((l+r) >> 1);\n if (3*m*(m+1)/2-m <= N) {\n l = m+1;\n res = 3*m*(m+1)/2-m;\n } else {\n r = m-1;\n }\n // console.log(l, r, m, 3*m*(m+1)/2-m);\n }\n return res;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}], "negative_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 3\n 14\n 15\n 24\n 1\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r value) {\n console.log(i-1);\n break;\n }\n }\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r value) {\n console.log(counter);\n break;\n }\n\n counter++;\n }\n }\n}"}], "src_uid": "02062d1afe85e3639edddedceac304f4"} {"source_code": "var a = readline().split(\" \");\nvar d = parseInt(a[0]);\nvar h = parseInt(a[1]);\nvar v = parseInt(a[2]);\nvar e = parseInt(a[3]);\n\nvar V = h * (((d * d) / 4) * Math.PI);\n\nvar RainSpeed = e * (((d * d) / 4) * Math.PI);\nif(RainSpeed >= v) print(\"NO\"); else{\n print(\"YES\");\n print(V / (v - RainSpeed));\n}", "positive_code": [{"source_code": "var input = readline().split(' ').map(Number);\n\nvar d = input[0];\nvar h = input[1];\nvar v = input[2];\nvar e = input[3];\n\nvar pi = Math.PI;\n\nvar t = - ((pi * Math.pow(d,2) * h) / (e * pi * Math.pow(d,2) - (4 * v)));\n\nif (t < 0) {\n\tprint('NO');\n} else {\n\tprint('YES');\n\tprint(t);\n}\n\n"}, {"source_code": "var input = readline().split(' ').map(function (item) {\n return parseInt(item);\n});\nvar d = input[0], h = input[1], v = input[2], e = input[3];\nvar hDecRate = (4*v)/(Math.PI*d*d);\nif(hDecRate <= e){\n print(\"NO\");\n} else {\n var rate = hDecRate - e;\n print(\"YES\");\n print(h/rate);\n}"}, {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nfunction main() {\n const input = getInput().pop().split(' ').map(item => Number(item));\n // diam\n const d = input[0];\n // height\n var h = input[1];\n // speed -\n const v = input[2];\n // speed +\n const e = input[3];\n \n // s = pi*r^2\n const s = Math.PI * Math.pow(d / 2, 2);\n const spOur = v / s;\n \n if (e > spOur) {\n print('NO')\n } else {\n var t = h / (spOur - e);\n print('YES')\n print(t)\n }\n}\n\nmain();"}], "negative_code": [], "src_uid": "fc37ef81bb36f3ac07ce2c4c3ec10d98"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let tmp=0, q=0, lrds=[];\n\n rl.on('line', (input) => {\n if (tmp==0) {q=Number(input); tmp++;}\n else {\n if (tmp<=q){\n let lrd=input.split(' ').map(a=>{return Number(a)}); \n lrds.push(lrd);\n tmp++;}\n }\n if (tmp>q){ rl.close(); therest();}\n return 0;}\n);\n\nlet therest=function() {\n\n let res=[];\n for (let i=0; ir) {res.push(d);\n console.log(d);}\n else {\n if (r%d==0) console.log(r+d);\n else console.log(Math.ceil(r/d)*d)\n }\n//console.log(lrds[i]);\n\n }\n//console.log(T, pairs)\n}\n//console.log(lngth, str);}\n\n /*\n rl.question('What do you think of Node.js? ', (answer) => {\n // TODO: Log the answer in a database\n console.log(`Thank you for your valuable feedback: ${answer}`);\n \n rl.close();\n });*/", "positive_code": [{"source_code": "function main() {\n var q = +readline();\n r = [];\n\n for(var i = 0; i < q; i++) {\n var t = readline().split(' ');\n r.push({ l: +t[0], r: +t[1], d: +t[2]});\n }\n \n var res = [];\n\n r.forEach(function(item) {\n \n if(item.l > item.d) {\n res.push(item.d);\n }\n else {\n var f = Math.ceil(item.r / item.d);\n if(item.r % item.d == 0)\n f++;\n res.push(f * item.d);\n }\n });\n\n res.forEach(function(g) {\n print(g);\n })\n}\n\nmain();"}, {"source_code": "var q = +readline();\n\nvar i = 0;\nvar arr = [];\nwhile(i < q) {\n\tarr[i] = readline().split(' ');\n\ti++;\n}\ni = 0;\n\nwhile(i < q) {\n arr[i][0] = +arr[i][0];\n arr[i][1] = +arr[i][1];\n arr[i][2] = +arr[i][2];\n\n\tif((arr[i][2] >= arr[i][0] && arr[i][2] <= arr[i][1]) && (arr[i][2] >= arr[i][0] || arr[i][2] <= arr[i][0])) {\n\t\tprint(+(+arr[i][1] + (+arr[i][2] - +arr[i][1]%+arr[i][2])));\n } else {\n\t\tprint(arr[i][2]);\n }\n\n i++;\n}"}, {"source_code": "var q = +readline();\n\nvar i = 0;\nvar arr = [];\nwhile(i < q) {\n\tarr[i] = readline().split(' ');\n\ti++;\n}\ni = 0;\n\nwhile(i < q) {\n arr[i][0] = +arr[i][0];\n arr[i][1] = +arr[i][1];\n arr[i][2] = +arr[i][2];\n\n\tif(arr[i][2] < arr[i][0] || arr[i][2] > arr[i][1]) {\n\t\tprint(arr[i][2]);\n } else {\n print(+(+arr[i][1] + (+arr[i][2] - +arr[i][1]%+arr[i][2])));\n }\n\n i++;\n}"}, {"source_code": "var n = readline();\nn = Number(n);\n\nfor(var i=0; ic || b r) {\n print(d);\n } else {\n var minToBreakFree = Math.floor(r / d);\n print(d * (minToBreakFree + 1));\n }\n}\n"}, {"source_code": "//var input = readline()\nvar t = parseInt(readline())\n\nfor(var i=0; ic || b r) {\n print(d)\n } else {\n print((Math.floor(r/d) + 1) * d)\n }\n}"}, {"source_code": "var n = readline();\nfor(i=0;i r) {\n print(d)\n } else {\n print((Math.floor(r/d) + 1) * d)\n }\n}"}, {"source_code": "function calc(l, r, d) {\n if (d < l || d > r) {\n return d;\n }\n \n return d * Math.ceil(r / d) === r ? r + d : d * Math.ceil(r / d);\n}\n\nvar q = parseInt(readline());\nvar lrd,l,r,d;\n\nfor (var i = 0; i< q; i++) {\n lrd = readline().split(\" \");\n // print(lrd);\n l = parseInt(lrd[0]);\n r = parseInt(lrd[1]);\n d = parseInt(lrd[2]);\n \n print(calc(l, r, d));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet n = 0\n\nrl.on('line', (input) => {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)\n rl.close();\n\n arr = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n\n if(arr[0]>arr[2]){\n console.log(arr[2])\n } else if(arr[1] {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)\n rl.close();\n\n arr = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n\n if(arr[0]>arr[2]){\n console.log(arr[2])\n } else if(arr[1] {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)rl.close();\n arr = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n\n if(arr[0]>arr[2]){\n console.log(arr[2])\n } else if(arr[1]d){print(d);}\n\t\telse{r++;print(Math.ceil(r/d)*d);}\n\t}\n"}], "negative_code": [{"source_code": "//var input = readline()\nvar t = parseInt(readline())\n\nfor(var i=0; ic) print(c)\n else if(a == c) print(s)\n else {\n if(s%c == 0) {\n print(s)\n }\n }\n}\n\n\n//"}, {"source_code": "var q=parseInt(readline());\n\t\tfor(var i=0;id){\n\t\t\t\tvar y=l-1;\n\t\t\twhile(y%d!==0){y--;}print(y);}\n\t\t\t}\n\t\t"}, {"source_code": "\t\tvar q=parseInt(readline());\n\t\tfor(var i=0;i arr[i][0]) {\n\t\tprint(arr[i][2]*2);\n } else if(arr[i][2] == arr[i][0] && arr[i][1]%arr[i][0] === 0) {\n\t\tprint((arr[i][1]+arr[i][2]));\n } else {\n\t\tprint(arr[i][2]);\n }\n\n\n i++;\n}"}, {"source_code": "var q = +readline();\n\nvar i = 0;\nvar arr = [];\n\nwhile(i < q) {\n\tarr[i] = readline().split(' ');\n\ti++;\n}\ni = 0;\n\nwhile(i < q) {\narr[i][0] = +arr[i][0];\narr[i][1] = +arr[i][1];\narr[i][2] = +arr[i][2];\n\tif(arr[i][2] == arr[i][1]) {\n\t\tprint(arr[i][2]*2);\n } else if(arr[i][2] == arr[i][0] && arr[i][1]%arr[i][0] === 0) {\n\t\tprint((arr[i][1]+arr[i][2]));\n } else if(!(arr[i][2] < arr[i][0]) && arr[i][1]%arr[i][0] !== 0) {\n\t\tprint(+(+arr[i][1] + (+arr[i][2] - +arr[i][1]%+arr[i][2])));\n } else {\n\t\tprint(arr[i][2]);\n }\n\n\n i++;\n}"}, {"source_code": "var q = +readline();\n\nvar i = 0;\nvar arr = [];\n\nwhile(i < q) {\n\tarr[i] = readline().split(' ');\n\ti++;\n}\ni = 0;\n\nwhile(i < q) {\narr[i][0] = +arr[i][0];\narr[i][1] = +arr[i][1];\narr[i][2] = +arr[i][2];\n\tif(arr[i][2] <= arr[i][1] && arr[i][2] > arr[i][0]) {\n\t\tprint(arr[i][2]*2);\n } else if(arr[i][2] == arr[i][0] && arr[i][1]%arr[i][0] === 0) {\n\t\tprint((arr[i][1]+arr[i][2]));\n } else if(!(arr[i][2] < arr[i][0]) && arr[i][1]%arr[i][0] !== 0) {\n\t\tprint(+(+arr[i][1] + (+arr[i][2] - +arr[i][1]%+arr[i][2])));\n } else {\n\t\tprint(arr[i][2]);\n }\n\n\n i++;\n}"}, {"source_code": "var q = +readline();\n\nvar i = 0;\nvar arr = [];\n\nwhile(i < q) {\n\tarr[i] = readline().split(' ');\n\ti++;\n}\ni = 0;\n\nwhile(i < q) {\narr[i][0] = +arr[i][0];\narr[i][1] = +arr[i][1];\narr[i][2] = +arr[i][2];\n\tif(arr[i][2] >= arr[i][1] && arr[i][2] > arr[i][0]) {\n\t\tprint(arr[i][2]*2);\n } else if(arr[i][2] == arr[i][0] && arr[i][1]%arr[i][0] === 0) {\n\t\tprint((arr[i][1]+arr[i][2]));\n } else if(!(arr[i][2] < arr[i][0]) && arr[i][1]%arr[i][0] !== 0) {\n\t\tprint(+(+arr[i][1] + (+arr[i][2] - +arr[i][1]%+arr[i][2])));\n } else {\n\t\tprint(arr[i][2]);\n }\n\n\n i++;\n}"}, {"source_code": "var q = readline()\nfor(var i=0; i r) {\n print(d)\n } else {\n print((Math.floor(r/d) + 1) * d)\n }\n}"}, {"source_code": "var n = readline().split(' ');\nfor(i=0;ir) && (j%d == 0)) {\n print(j + \"\\n\");\n }\n }\n}"}, {"source_code": "var n = readline().split(' ');\nfor(i=0;i r) {\n print(d)\n } else {\n print((Math.floor(r/d) + 1) * d)\n }\n}"}, {"source_code": "var n = readline().split(' ');\nfor(i=0;ir) && (j%d == 0)) {\n print(j);\n }\n }\n}"}, {"source_code": "var n = readline().split(' ');\nfor(i=0;ir) && (j%d == 0)) {\n print(j + \"\\n\");\n break;\n }\n }\n}"}], "src_uid": "091e91352973b18040e2d57c46f2bf8a"} {"source_code": "// Generated by CoffeeScript 2.4.1\nvar N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint, range,\n indexOf = [].indexOf;\n\nprint = console.log;\n\nprocess.stdin.resume();\n\nprocess.stdin.setEncoding('utf-8');\n\ninputString = '';\n\ncurrentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n return inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function(_) {\n inputString = inputString.trim().split('\\n').map(function(string) {\n return string.trim();\n });\n return main();\n});\n\ninput = function() {\n return inputString[currentLine++];\n};\n\nnr = function() {\n return parseInt(input());\n};\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = input().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\nrange = function(start, stop, step) {\n var i, k, length, ref, ref1, ref2, results;\n if (stop === void 0) {\n stop = start || 0;\n start = 0;\n }\n if (step === void 0) {\n step = stop < start ? -1 : 1;\n }\n length = Math.max(Math.ceil((stop - start) / step), 0);\n results = [];\n for (i = k = ref = start, ref1 = start + length, ref2 = step; ref2 !== 0 && (ref2 > 0 ? k < ref1 : k > ref1); i = k += ref2) {\n results.push(i);\n }\n return results;\n};\n\n//##################################################\nN = 3162;\n\np2 = [];\n\nrandint = function(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n};\n\nprepare = function() {\n var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;\n p = (function() {\n var k, len, ref, results;\n ref = range(N);\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(1);\n }\n return results;\n })();\n ref = range(2, N);\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n if (p[i]) {\n ref1 = range(2 * i, N, i);\n for (l = 0, len1 = ref1.length; l < len1; l++) {\n j = ref1[l];\n p[j] = 0;\n }\n }\n }\n ref2 = range(2, N);\n results = [];\n for (m = 0, len2 = ref2.length; m < len2; m++) {\n c = ref2[m];\n if (p[c] === 1) {\n results.push(c * c);\n }\n }\n return results;\n};\n\nf = function(a) {\n var ans, hash, k, kl, l, len, len1, q, r, r0;\n ans = 1;\n kl = {};\n hash = {};\n for (k = 0, len = a.length; k < len; k++) {\n r0 = a[k];\n if (indexOf.call(hash, r0) >= 0) {\n r = hash[r0];\n } else {\n r = r0;\n for (l = 0, len1 = p2.length; l < len1; l++) {\n q = p2[l];\n if (r < q) {\n break;\n }\n while (r % q === 0) {\n r = Math.floor(r / q);\n }\n }\n hash[r0] = r;\n }\n if (r in kl) {\n ans += 1;\n kl = {};\n }\n kl[r] = 1;\n }\n return ans;\n};\n\nmain = function() {\n var _, k, len, ref, results;\n p2 = prepare();\n ref = range(nr());\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n _ = ref[k];\n [_, _] = nrs();\n results.push(print(f(nrs())));\n }\n return results;\n};\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLEtBQUEsRUFBQSxPQUFBLEVBQUEsS0FBQTtFQUFBOztBQUFBLEtBQUEsR0FBUSxPQUFPLENBQUM7O0FBRWhCLE9BQU8sQ0FBQyxLQUFLLENBQUMsTUFBZCxDQUFBOztBQUNBLE9BQU8sQ0FBQyxLQUFLLENBQUMsV0FBZCxDQUEwQixPQUExQjs7QUFFQSxXQUFBLEdBQWM7O0FBQ2QsV0FBQSxHQUFjOztBQUVkLE9BQU8sQ0FBQyxLQUFLLENBQUMsRUFBZCxDQUFpQixNQUFqQixFQUF5QixRQUFBLENBQUMsVUFBRCxDQUFBO1NBQWdCLFdBQUEsSUFBZTtBQUEvQixDQUF6Qjs7QUFFQSxPQUFPLENBQUMsS0FBSyxDQUFDLEVBQWQsQ0FBaUIsS0FBakIsRUFBd0IsUUFBQSxDQUFDLENBQUQsQ0FBQTtFQUN2QixXQUFBLEdBQWMsV0FBVyxDQUFDLElBQVosQ0FBQSxDQUFrQixDQUFDLEtBQW5CLENBQXlCLElBQXpCLENBQThCLENBQUMsR0FBL0IsQ0FBbUMsUUFBQSxDQUFDLE1BQUQsQ0FBQTtXQUFZLE1BQU0sQ0FBQyxJQUFQLENBQUE7RUFBWixDQUFuQztTQUNkLElBQUEsQ0FBQTtBQUZ1QixDQUF4Qjs7QUFJQSxLQUFBLEdBQVEsUUFBQSxDQUFBLENBQUE7U0FBRyxXQUFZLENBQUEsV0FBQSxFQUFBO0FBQWY7O0FBRVIsRUFBQSxHQUFLLFFBQUEsQ0FBQSxDQUFBO1NBQU0sUUFBQSxDQUFTLEtBQUEsQ0FBQSxDQUFUO0FBQU47O0FBQ0wsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQU0sTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBWTtBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFsQjs7QUFFTixLQUFBLEdBQVEsUUFBQSxDQUFDLEtBQUQsRUFBUSxJQUFSLEVBQWMsSUFBZCxDQUFBO0FBQ1AsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLE1BQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQTtFQUFBLElBQUcsSUFBQSxLQUFRLE1BQVg7SUFDQyxJQUFBLEdBQU8sS0FBQSxJQUFTO0lBQ2hCLEtBQUEsR0FBUSxFQUZUOztFQUdBLElBQUcsSUFBQSxLQUFRLE1BQVg7SUFDQyxJQUFBLEdBQVUsSUFBQSxHQUFPLEtBQVYsR0FBcUIsQ0FBQyxDQUF0QixHQUE2QixFQURyQzs7RUFFQSxNQUFBLEdBQVMsSUFBSSxDQUFDLEdBQUwsQ0FBUyxJQUFJLENBQUMsSUFBTCxDQUFVLENBQUMsSUFBQSxHQUFPLEtBQVIsQ0FBQSxHQUFpQixJQUEzQixDQUFULEVBQTJDLENBQTNDO0FBQ1A7RUFBQSxLQUFTLHNIQUFUO2lCQUFGO0VBQUUsQ0FBQTs7QUFQSyxFQW5CUjs7O0FBOEJBLENBQUEsR0FBSTs7QUFDSixFQUFBLEdBQUs7O0FBRUwsT0FBQSxHQUFVLFFBQUEsQ0FBQyxHQUFELEVBQU0sR0FBTixDQUFBO1NBQWMsSUFBSSxDQUFDLEtBQUwsQ0FBVyxJQUFJLENBQUMsTUFBTCxDQUFBLENBQUEsR0FBZ0IsQ0FBQyxHQUFBLEdBQU0sR0FBTixHQUFZLENBQWIsQ0FBM0IsQ0FBQSxHQUErQztBQUE3RDs7QUFFVixPQUFBLEdBQVUsUUFBQSxDQUFBLENBQUE7QUFDVCxNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQTtFQUFBLENBQUE7O0FBQU87QUFBQTtJQUFBLEtBQUEscUNBQUE7O21CQUFGO0lBQUUsQ0FBQTs7O0FBQ1A7RUFBQSxLQUFBLHFDQUFBOztJQUNDLElBQUcsQ0FBRSxDQUFBLENBQUEsQ0FBTDtBQUNDO01BQUEsS0FBQSx3Q0FBQTs7UUFDQyxDQUFFLENBQUEsQ0FBQSxDQUFGLEdBQU87TUFEUixDQUREOztFQUREO0FBSUk7QUFBQTtFQUFBLEtBQUEsd0NBQUE7O1FBQXdCLENBQUUsQ0FBQSxDQUFBLENBQUYsS0FBTTttQkFBbEMsQ0FBQSxHQUFFOztFQUFFLENBQUE7O0FBTks7O0FBUVYsQ0FBQSxHQUFJLFFBQUEsQ0FBQyxDQUFELENBQUE7QUFDSCxNQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBLEVBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBO0VBQUEsR0FBQSxHQUFNO0VBQ04sRUFBQSxHQUFLLENBQUE7RUFDTCxJQUFBLEdBQU8sQ0FBQTtFQUNQLEtBQUEsbUNBQUE7O0lBQ0MsSUFBRyxhQUFNLElBQU4sRUFBQSxFQUFBLE1BQUg7TUFDQyxDQUFBLEdBQUksSUFBSyxDQUFBLEVBQUEsRUFEVjtLQUFBLE1BQUE7TUFHQyxDQUFBLEdBQUk7TUFDSixLQUFBLHNDQUFBOztRQUNDLElBQUcsQ0FBQSxHQUFJLENBQVA7QUFDQyxnQkFERDs7QUFFQSxlQUFNLENBQUEsR0FBSSxDQUFKLEtBQVMsQ0FBZjtVQUNDLGVBQUEsSUFBTTtRQURQO01BSEQ7TUFLQSxJQUFLLENBQUEsRUFBQSxDQUFMLEdBQVMsRUFUVjs7SUFVQSxJQUFHLENBQUEsSUFBSyxFQUFSO01BQ0MsR0FBQSxJQUFPO01BQ1AsRUFBQSxHQUFLLENBQUEsRUFGTjs7SUFHQSxFQUFHLENBQUEsQ0FBQSxDQUFILEdBQVE7RUFkVDtTQWVBO0FBbkJHOztBQXFCSixJQUFBLEdBQU8sUUFBQSxDQUFBLENBQUE7QUFDTixNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLEdBQUEsRUFBQTtFQUFBLEVBQUEsR0FBSyxPQUFBLENBQUE7QUFDTDtBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7SUFDQyxDQUFDLENBQUQsRUFBRyxDQUFILENBQUEsR0FBUSxHQUFBLENBQUE7aUJBQ1IsS0FBQSxDQUFNLENBQUEsQ0FBRSxHQUFBLENBQUEsQ0FBRixDQUFOO0VBRkQsQ0FBQTs7QUFGTSIsInNvdXJjZXNDb250ZW50IjpbInByaW50ID0gY29uc29sZS5sb2dcblxucHJvY2Vzcy5zdGRpbi5yZXN1bWUoKVxucHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZyAndXRmLTgnXG4gXG5pbnB1dFN0cmluZyA9ICcnXG5jdXJyZW50TGluZSA9IDBcbiBcbnByb2Nlc3Muc3RkaW4ub24gJ2RhdGEnLCAoaW5wdXRTdGRpbikgLT4gaW5wdXRTdHJpbmcgKz0gaW5wdXRTdGRpblxuIFxucHJvY2Vzcy5zdGRpbi5vbiAnZW5kJywgKF8pIC0+IFxuXHRpbnB1dFN0cmluZyA9IGlucHV0U3RyaW5nLnRyaW0oKS5zcGxpdCgnXFxuJykubWFwIChzdHJpbmcpIC0+IHN0cmluZy50cmltKClcblx0bWFpbigpXG5cbmlucHV0ID0gLT4gaW5wdXRTdHJpbmdbY3VycmVudExpbmUrK11cblxubnIgPSAoKSAtPiBwYXJzZUludCBpbnB1dCgpXG5ucnMgPSAoKSAtPiAocGFyc2VJbnQgaSBmb3IgaSBpbiBpbnB1dCgpLnNwbGl0ICcgJylcblxucmFuZ2UgPSAoc3RhcnQsIHN0b3AsIHN0ZXApIC0+XG5cdGlmIHN0b3AgPT0gdW5kZWZpbmVkXG5cdFx0c3RvcCA9IHN0YXJ0IHx8IDBcblx0XHRzdGFydCA9IDBcblx0aWYgc3RlcCA9PSB1bmRlZmluZWRcblx0XHRzdGVwID0gaWYgc3RvcCA8IHN0YXJ0IHRoZW4gLTEgZWxzZSAxXG5cdGxlbmd0aCA9IE1hdGgubWF4KE1hdGguY2VpbCgoc3RvcCAtIHN0YXJ0KSAvIHN0ZXApLCAwKVxuXHRpIGZvciBpIGluIFtzdGFydC4uLnN0YXJ0K2xlbmd0aF0gYnkgc3RlcFxuXG4jIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyNcblxuTiA9IDMxNjJcbnAyID0gW11cblxucmFuZGludCA9IChtaW4sIG1heCkgLT4gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogKG1heCAtIG1pbiArIDEpICkgKyBtaW5cblxucHJlcGFyZSA9ICgpIC0+XG5cdHAgPSAoMSBmb3IgaSBpbiByYW5nZSBOKVxuXHRmb3IgaSBpbiByYW5nZSAyLE5cblx0XHRpZiBwW2ldXG5cdFx0XHRmb3IgaiBpbiByYW5nZSAyKmksTixpXG5cdFx0XHRcdHBbal0gPSAwXG5cdGMqYyBmb3IgYyBpbiByYW5nZSAyLE4gd2hlbiBwW2NdPT0xXG5cbmYgPSAoYSkgLT5cblx0YW5zID0gMVxuXHRrbCA9IHt9XG5cdGhhc2ggPSB7fVxuXHRmb3IgcjAgaW4gYVxuXHRcdGlmIHIwIGluIGhhc2hcblx0XHRcdHIgPSBoYXNoW3IwXVxuXHRcdGVsc2Vcblx0XHRcdHIgPSByMFxuXHRcdFx0Zm9yIHEgaW4gcDJcblx0XHRcdFx0aWYgciA8IHFcblx0XHRcdFx0XHRicmVha1xuXHRcdFx0XHR3aGlsZSByICUgcSA9PSAwXG5cdFx0XHRcdFx0ciAvLz0gcVxuXHRcdFx0aGFzaFtyMF09clxuXHRcdGlmIHIgb2Yga2xcblx0XHRcdGFucyArPSAxXG5cdFx0XHRrbCA9IHt9XG5cdFx0a2xbcl0gPSAxXG5cdGFuc1xuXG5tYWluID0gLT5cblx0cDIgPSBwcmVwYXJlKClcblx0Zm9yIF8gaW4gcmFuZ2UgbnIoKVxuXHRcdFtfLF9dID0gbnJzKClcblx0XHRwcmludCBmIG5ycygpXG4iXX0=\n//# sourceURL=c:\\github\\2021\\010\\coffee\\app.coffee", "positive_code": [{"source_code": "// Generated by CoffeeScript 2.4.1\nvar A, K, N, _, a, dp, i, j, k, l, len, len1, len2, m, min, n, nr, nrs, o, p, q, ref, ref1, ref2, sq, squares, used, xxx;\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\n\nfunction range(start, stop, step) {\n if (stop == null) {\n stop = start || 0\n start = 0\n }\n if (!step) step = stop < start ? -1 : 1\n\n var length = Math.max(Math.ceil((stop - start) / step), 0)\n var range = Array(length) \n\n for (var idx = 0; idx < length; idx++, start += step) range[idx] = start\n\n return range;\n}\n;\n\nmin = function(lst) {\n var best, item, k, len;\n best = lst[0];\n for (k = 0, len = lst.length; k < len; k++) {\n item = lst[k];\n best = item < best ? item : best;\n }\n return best;\n};\n\nn = 10000000;\n\nsquares = (function() {\n var k, results;\n results = [];\n for (i = k = 1; k < 3162; i = ++k) {\n results.push(i * i);\n }\n return results;\n})();\n\np = (function() {\n var k, ref, results;\n results = [];\n for (i = k = 0, ref = n + 1; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {\n results.push(i);\n }\n return results;\n})();\n\nfor (i = k = 1, ref = n + 1; (1 <= ref ? k < ref : k > ref); i = 1 <= ref ? ++k : --k) {\n if (p[i] === i) {\n for (l = 0, len = squares.length; l < len; l++) {\n sq = squares[l];\n if (i * sq > n) {\n break;\n }\n p[i * sq] = i;\n }\n }\n}\n\nfor (_ = m = 0, ref1 = nr(); (0 <= ref1 ? m < ref1 : m > ref1); _ = 0 <= ref1 ? ++m : --m) {\n xxx = nrs();\n N = xxx[0];\n K = xxx[1];\n A = (function() {\n var len1, o, ref2, results;\n ref2 = nrs();\n results = [];\n for (o = 0, len1 = ref2.length; o < len1; o++) {\n a = ref2[o];\n results.push(p[a]);\n }\n return results;\n })();\n dp = (function() {\n var len1, o, ref2, results;\n ref2 = range(K + 1);\n results = [];\n for (o = 0, len1 = ref2.length; o < len1; o++) {\n _ = ref2[o];\n results.push(N);\n }\n return results;\n })();\n dp[0] = 1;\n used = (function() {\n var o, ref2, results;\n results = [];\n for (_ = o = 0, ref2 = K + 1; (0 <= ref2 ? o < ref2 : o > ref2); _ = 0 <= ref2 ? ++o : --o) {\n results.push({});\n }\n return results;\n })();\n for (o = 0, len1 = A.length; o < len1; o++) {\n a = A[o];\n ref2 = range(K, -1, -1);\n for (q = 0, len2 = ref2.length; q < len2; q++) {\n j = ref2[q];\n if (dp[j] === N) {\n continue;\n }\n if (a in used[j]) {\n if (j < K && dp[j + 1] > dp[j]) {\n dp[j + 1] = dp[j];\n used[j + 1] = used[j];\n }\n dp[j] += 1;\n used[j] = {};\n }\n used[j][a] = 1;\n }\n }\n print(min(dp));\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamltbTg5LmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGppbW04OS5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxFQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLEVBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLE9BQUEsRUFBQSxJQUFBLEVBQUE7O0FBQUEsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBVztBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFkOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQUFHLEdBQUEsQ0FBQSxDQUFNLENBQUEsQ0FBQTtBQUFUOztBQUVMOzs7Ozs7Ozs7Ozs7Ozs7OztBQWlCQSxHQUFBLEdBQU0sUUFBQSxDQUFDLEdBQUQsQ0FBQTtBQUNMLE1BQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxJQUFBLEdBQU8sR0FBSSxDQUFBLENBQUE7RUFDWCxLQUFBLHFDQUFBOztJQUNDLElBQUEsR0FBVSxJQUFBLEdBQU8sSUFBVixHQUFvQixJQUFwQixHQUE4QjtFQUR0QztTQUVBO0FBSks7O0FBTU4sQ0FBQSxHQUFJOztBQUNKLE9BQUE7O0FBQWU7RUFBQSxLQUFTLDRCQUFUO2lCQUFKLENBQUEsR0FBRTtFQUFFLENBQUE7Ozs7QUFFZixDQUFBOztBQUFPO0VBQUEsS0FBUyxnRkFBVDtpQkFBRjtFQUFFLENBQUE7Ozs7QUFDUCxLQUFTLGdGQUFUO0VBQ0MsSUFBRyxDQUFFLENBQUEsQ0FBQSxDQUFGLEtBQVEsQ0FBWDtJQUNDLEtBQUEseUNBQUE7O01BQ0MsSUFBRyxDQUFBLEdBQUUsRUFBRixHQUFPLENBQVY7QUFBaUIsY0FBakI7O01BQ0EsQ0FBRSxDQUFBLENBQUEsR0FBRSxFQUFGLENBQUYsR0FBVTtJQUZYLENBREQ7O0FBREQ7O0FBTUEsS0FBUyxvRkFBVDtFQUNDLEdBQUEsR0FBTSxHQUFBLENBQUE7RUFDTixDQUFBLEdBQUksR0FBSSxDQUFBLENBQUE7RUFDUixDQUFBLEdBQUksR0FBSSxDQUFBLENBQUE7RUFDUixDQUFBOztBQUFVO0FBQUE7SUFBQSxLQUFBLHdDQUFBOzttQkFBTCxDQUFFLENBQUEsQ0FBQTtJQUFHLENBQUE7OztFQUNWLEVBQUE7O0FBQVE7QUFBQTtJQUFBLEtBQUEsd0NBQUE7O21CQUFGO0lBQUUsQ0FBQTs7O0VBQ1IsRUFBRyxDQUFBLENBQUEsQ0FBSCxHQUFRO0VBQ1IsSUFBQTs7QUFBVztJQUFBLEtBQVMscUZBQVQ7bUJBQUgsQ0FBQTtJQUFHLENBQUE7OztFQUNYLEtBQUEscUNBQUE7O0FBQ0M7SUFBQSxLQUFBLHdDQUFBOztNQUNDLElBQUcsRUFBRyxDQUFBLENBQUEsQ0FBSCxLQUFTLENBQVo7QUFBbUIsaUJBQW5COztNQUNBLElBQUcsQ0FBQSxJQUFLLElBQUssQ0FBQSxDQUFBLENBQWI7UUFDQyxJQUFHLENBQUEsR0FBSSxDQUFKLElBQVUsRUFBRyxDQUFBLENBQUEsR0FBSSxDQUFKLENBQUgsR0FBWSxFQUFHLENBQUEsQ0FBQSxDQUE1QjtVQUNDLEVBQUcsQ0FBQSxDQUFBLEdBQUksQ0FBSixDQUFILEdBQVksRUFBRyxDQUFBLENBQUE7VUFDZixJQUFLLENBQUEsQ0FBQSxHQUFJLENBQUosQ0FBTCxHQUFjLElBQUssQ0FBQSxDQUFBLEVBRnBCOztRQUdBLEVBQUcsQ0FBQSxDQUFBLENBQUgsSUFBUztRQUNULElBQUssQ0FBQSxDQUFBLENBQUwsR0FBVSxDQUFBLEVBTFg7O01BTUEsSUFBSyxDQUFBLENBQUEsQ0FBRyxDQUFBLENBQUEsQ0FBUixHQUFhO0lBUmQ7RUFERDtFQVVBLEtBQUEsQ0FBTSxHQUFBLENBQUksRUFBSixDQUFOO0FBbEJEIiwic291cmNlc0NvbnRlbnQiOlsibnJzID0gLT4gcGFyc2VJbnQgaSBmb3IgaSBpbiByZWFkbGluZSgpLnNwbGl0ICcgJ1xubnIgPSAtPiBucnMoKVswXVxuXG5gYGBcbmZ1bmN0aW9uIHJhbmdlKHN0YXJ0LCBzdG9wLCBzdGVwKSB7XG4gIGlmIChzdG9wID09IG51bGwpIHtcbiAgICBzdG9wID0gc3RhcnQgfHwgMFxuICAgIHN0YXJ0ID0gMFxuICB9XG4gIGlmICghc3RlcCkgc3RlcCA9IHN0b3AgPCBzdGFydCA/IC0xIDogMVxuXG4gIHZhciBsZW5ndGggPSBNYXRoLm1heChNYXRoLmNlaWwoKHN0b3AgLSBzdGFydCkgLyBzdGVwKSwgMClcbiAgdmFyIHJhbmdlID0gQXJyYXkobGVuZ3RoKSBcblxuICBmb3IgKHZhciBpZHggPSAwOyBpZHggPCBsZW5ndGg7IGlkeCsrLCBzdGFydCArPSBzdGVwKSByYW5nZVtpZHhdID0gc3RhcnRcblxuICByZXR1cm4gcmFuZ2U7XG59XG5gYGBcblxubWluID0gKGxzdCkgLT5cblx0YmVzdCA9IGxzdFswXVxuXHRmb3IgaXRlbSBpbiBsc3Rcblx0XHRiZXN0ID0gaWYgaXRlbSA8IGJlc3QgdGhlbiBpdGVtIGVsc2UgYmVzdCBcblx0YmVzdCBcblxubiA9IDEwMDAwMDAwXG5zcXVhcmVzID0gKGkqaSBmb3IgaSBpbiBbMS4uLjMxNjJdKVxuXG5wID0gKGkgZm9yIGkgaW4gWzAuLi5uKzFdKVxuZm9yIGkgaW4gWzEuLi5uKzFdXG5cdGlmIHBbaV0gPT0gaVxuXHRcdGZvciBzcSBpbiBzcXVhcmVzXG5cdFx0XHRpZiBpKnNxID4gbiB0aGVuIGJyZWFrXG5cdFx0XHRwW2kqc3FdID0gaVxuXG5mb3IgXyBpbiBbMC4uLm5yKCldXG5cdHh4eCA9IG5ycygpXG5cdE4gPSB4eHhbMF1cblx0SyA9IHh4eFsxXVxuXHRBID0gKHBbYV0gZm9yIGEgaW4gbnJzKCkpXG5cdGRwID0gKE4gZm9yIF8gaW4gcmFuZ2UgSysxKVxuXHRkcFswXSA9IDFcblx0dXNlZCA9ICh7fSBmb3IgXyBpbiBbMC4uLksrMV0pXG5cdGZvciBhIGluIEFcblx0XHRmb3IgaiBpbiByYW5nZSBLLC0xLC0xXG5cdFx0XHRpZiBkcFtqXSA9PSBOIHRoZW4gY29udGludWUgXG5cdFx0XHRpZiBhIG9mIHVzZWRbal1cblx0XHRcdFx0aWYgaiA8IEsgYW5kIGRwW2ogKyAxXSA+IGRwW2pdXG5cdFx0XHRcdFx0ZHBbaiArIDFdID0gZHBbal1cblx0XHRcdFx0XHR1c2VkW2ogKyAxXSA9IHVzZWRbal1cblx0XHRcdFx0ZHBbal0gKz0gMVxuXHRcdFx0XHR1c2VkW2pdID0ge31cblx0XHRcdHVzZWRbal1bYV0gPSAxXG5cdHByaW50IG1pbiBkcFxuIl19\n//# sourceURL=c:\\github\\2021\\009-CodeForces#708\\1497E2\\coffee\\jimm89.coffee"}, {"source_code": "// Generated by CoffeeScript 2.4.1\n // Problem: hittar inte n\u00e5got kommando som kan exekvera\nvar N, _, f, k, len, nr, nrs, p2, prepare, randint, ref,\n indexOf = [].indexOf;\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\n\nfunction range(start, stop, step) {\n if (stop == null) {\n stop = start || 0\n start = 0\n }\n if (!step) step = stop < start ? -1 : 1\n\n var length = Math.max(Math.ceil((stop - start) / step), 0)\n var range = Array(length)\n\n for (var idx = 0; idx < length; idx++, start += step) range[idx] = start\n\n return range;\n}\n;\n\n//##################################################\nN = 3162;\n\np2 = [];\n\nrandint = function(min, max) {\n return min + Math.floor(Math.random() * (max - min + 1));\n};\n\nprepare = function() {\n var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;\n p = (function() {\n var k, len, ref, results;\n ref = range(N);\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(1);\n }\n return results;\n })();\n ref = range(2, N);\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n if (p[i]) {\n ref1 = range(2 * i, N, i);\n for (l = 0, len1 = ref1.length; l < len1; l++) {\n j = ref1[l];\n p[j] = 0;\n }\n }\n }\n ref2 = range(2, N);\n results = [];\n for (m = 0, len2 = ref2.length; m < len2; m++) {\n c = ref2[m];\n if (p[c] === 1) {\n results.push(c * c);\n }\n }\n return results;\n};\n\nf = function(a) {\n var ans, hash, k, kl, l, len, len1, q, r, r0;\n ans = 1;\n kl = {};\n hash = {};\n for (k = 0, len = a.length; k < len; k++) {\n r0 = a[k];\n if (indexOf.call(hash, r0) >= 0) {\n r = hash[r0];\n } else {\n r = r0;\n for (l = 0, len1 = p2.length; l < len1; l++) {\n q = p2[l];\n if (r < q) {\n break;\n }\n while (r % q === 0) {\n r = Math.floor(r / q);\n }\n }\n hash[r0] = r;\n }\n if (r in kl) {\n ans += 1;\n kl = {};\n }\n kl[r] = 1;\n }\n return ans;\n};\n\np2 = prepare();\n\nref = range(nr());\nfor (k = 0, len = ref.length; k < len; k++) {\n _ = ref[k];\n _ = nrs();\n print(f(nrs()));\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamF2YXNjcmlwdC5qcyIsInNvdXJjZVJvb3QiOiIuLiIsInNvdXJjZXMiOlsiY29mZmVlXFxqYXZhc2NyaXB0LmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFBQSxJQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLE9BQUEsRUFBQSxHQUFBO0VBQUE7O0FBQ0EsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBWTtBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFmOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQUFHLEdBQUEsQ0FBQSxDQUFNLENBQUEsQ0FBQTtBQUFUOztBQUVMOzs7Ozs7Ozs7Ozs7Ozs7Q0FKQTs7O0FBc0JBLENBQUEsR0FBSTs7QUFDSixFQUFBLEdBQUs7O0FBRUwsT0FBQSxHQUFVLFFBQUEsQ0FBQyxHQUFELEVBQU0sR0FBTixDQUFBO1NBQWMsR0FBQSxHQUFNLElBQUksQ0FBQyxLQUFMLENBQVcsSUFBSSxDQUFDLE1BQUwsQ0FBQSxDQUFBLEdBQWdCLENBQUMsR0FBQSxHQUFNLEdBQU4sR0FBWSxDQUFiLENBQTNCO0FBQXBCOztBQUVWLE9BQUEsR0FBVSxRQUFBLENBQUEsQ0FBQTtBQUNULE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBO0VBQUEsQ0FBQTs7QUFBTztBQUFBO0lBQUEsS0FBQSxxQ0FBQTs7bUJBQUY7SUFBRSxDQUFBOzs7QUFDUDtFQUFBLEtBQUEscUNBQUE7O0lBQ0MsSUFBRyxDQUFFLENBQUEsQ0FBQSxDQUFMO0FBQ0M7TUFBQSxLQUFBLHdDQUFBOztRQUNDLENBQUUsQ0FBQSxDQUFBLENBQUYsR0FBTztNQURSLENBREQ7O0VBREQ7QUFJSTtBQUFBO0VBQUEsS0FBQSx3Q0FBQTs7UUFBd0IsQ0FBRSxDQUFBLENBQUEsQ0FBRixLQUFNO21CQUFsQyxDQUFBLEdBQUU7O0VBQUUsQ0FBQTs7QUFOSzs7QUFRVixDQUFBLEdBQUksUUFBQSxDQUFDLENBQUQsQ0FBQTtBQUNILE1BQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxHQUFBLEdBQU07RUFDTixFQUFBLEdBQUssQ0FBQTtFQUNMLElBQUEsR0FBTyxDQUFBO0VBQ1AsS0FBQSxtQ0FBQTs7SUFDQyxJQUFHLGFBQU0sSUFBTixFQUFBLEVBQUEsTUFBSDtNQUNDLENBQUEsR0FBSSxJQUFLLENBQUEsRUFBQSxFQURWO0tBQUEsTUFBQTtNQUdDLENBQUEsR0FBSTtNQUNKLEtBQUEsc0NBQUE7O1FBQ0MsSUFBRyxDQUFBLEdBQUksQ0FBUDtBQUNDLGdCQUREOztBQUVBLGVBQU0sQ0FBQSxHQUFJLENBQUosS0FBUyxDQUFmO1VBQ0MsZUFBQSxJQUFNO1FBRFA7TUFIRDtNQUtBLElBQUssQ0FBQSxFQUFBLENBQUwsR0FBVyxFQVRaOztJQVVBLElBQUcsQ0FBQSxJQUFLLEVBQVI7TUFDQyxHQUFBLElBQU87TUFDUCxFQUFBLEdBQUssQ0FBQSxFQUZOOztJQUdBLEVBQUcsQ0FBQSxDQUFBLENBQUgsR0FBUTtFQWRUO1NBZUE7QUFuQkc7O0FBcUJKLEVBQUEsR0FBSyxPQUFBLENBQUE7O0FBQ0w7QUFBQSxLQUFBLHFDQUFBOztFQUNDLENBQUEsR0FBSSxHQUFBLENBQUE7RUFDSixLQUFBLENBQU0sQ0FBQSxDQUFFLEdBQUEsQ0FBQSxDQUFGLENBQU47QUFGRCIsInNvdXJjZXNDb250ZW50IjpbIiMgUHJvYmxlbTogaGl0dGFyIGludGUgbsOlZ290IGtvbW1hbmRvIHNvbSBrYW4gZXhla3ZlcmFcclxubnJzID0gLT4gKHBhcnNlSW50IGkgZm9yIGkgaW4gcmVhZGxpbmUoKS5zcGxpdCAnICcpXHJcbm5yID0gLT4gbnJzKClbMF1cclxuXHJcbmBgYFxyXG5mdW5jdGlvbiByYW5nZShzdGFydCwgc3RvcCwgc3RlcCkge1xyXG4gIGlmIChzdG9wID09IG51bGwpIHtcclxuICAgIHN0b3AgPSBzdGFydCB8fCAwXHJcbiAgICBzdGFydCA9IDBcclxuICB9XHJcbiAgaWYgKCFzdGVwKSBzdGVwID0gc3RvcCA8IHN0YXJ0ID8gLTEgOiAxXHJcblxyXG4gIHZhciBsZW5ndGggPSBNYXRoLm1heChNYXRoLmNlaWwoKHN0b3AgLSBzdGFydCkgLyBzdGVwKSwgMClcclxuICB2YXIgcmFuZ2UgPSBBcnJheShsZW5ndGgpXHJcblxyXG4gIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IGxlbmd0aDsgaWR4KyssIHN0YXJ0ICs9IHN0ZXApIHJhbmdlW2lkeF0gPSBzdGFydFxyXG5cclxuICByZXR1cm4gcmFuZ2U7XHJcbn1cclxuYGBgXHJcbiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjI1xyXG5cclxuTiA9IDMxNjJcclxucDIgPSBbXVxyXG5cclxucmFuZGludCA9IChtaW4sIG1heCkgLT4gbWluICsgTWF0aC5mbG9vciBNYXRoLnJhbmRvbSgpICogKG1heCAtIG1pbiArIDEpICBcclxuXHJcbnByZXBhcmUgPSAtPlxyXG5cdHAgPSAoMSBmb3IgaSBpbiByYW5nZSBOKVxyXG5cdGZvciBpIGluIHJhbmdlIDIsTlxyXG5cdFx0aWYgcFtpXVxyXG5cdFx0XHRmb3IgaiBpbiByYW5nZSAyKmksTixpXHJcblx0XHRcdFx0cFtqXSA9IDBcclxuXHRjKmMgZm9yIGMgaW4gcmFuZ2UgMixOIHdoZW4gcFtjXT09MVxyXG5cclxuZiA9IChhKSAtPlxyXG5cdGFucyA9IDFcclxuXHRrbCA9IHt9XHJcblx0aGFzaCA9IHt9XHJcblx0Zm9yIHIwIGluIGFcclxuXHRcdGlmIHIwIGluIGhhc2hcclxuXHRcdFx0ciA9IGhhc2hbcjBdXHJcblx0XHRlbHNlXHJcblx0XHRcdHIgPSByMFxyXG5cdFx0XHRmb3IgcSBpbiBwMlxyXG5cdFx0XHRcdGlmIHIgPCBxXHJcblx0XHRcdFx0XHRicmVha1xyXG5cdFx0XHRcdHdoaWxlIHIgJSBxID09IDBcclxuXHRcdFx0XHRcdHIgLy89IHFcclxuXHRcdFx0aGFzaFtyMF0gPSByXHJcblx0XHRpZiByIG9mIGtsXHJcblx0XHRcdGFucyArPSAxXHJcblx0XHRcdGtsID0ge31cclxuXHRcdGtsW3JdID0gMVxyXG5cdGFuc1xyXG5cclxucDIgPSBwcmVwYXJlKClcclxuZm9yIF8gaW4gcmFuZ2UgbnIoKVxyXG5cdF8gPSBucnMoKVxyXG5cdHByaW50IGYgbnJzKClcclxuIl19\n//# sourceURL=c:\\github\\2021\\010\\coffee\\javascript.coffee"}, {"source_code": "// Generated by CoffeeScript 2.4.1\nvar N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,\n indexOf = [].indexOf;\n\nprint = console.log;\n\nprocess.stdin.resume();\n\nprocess.stdin.setEncoding('utf-8');\n\ninputString = '';\n\ncurrentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n return inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function(_) {\n inputString = inputString.trim().split('\\n').map(function(string) {\n return string.trim();\n });\n return main();\n});\n\ninput = function() {\n return inputString[currentLine++];\n};\n\nnr = function() {\n return parseInt(input());\n};\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = input().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\n\nfunction range(start, stop, step) {\n if (stop == null) {\n stop = start || 0\n start = 0\n }\n if (!step) step = stop < start ? -1 : 1\n\n var length = Math.max(Math.ceil((stop - start) / step), 0)\n var range = Array(length)\n\n for (var idx = 0; idx < length; idx++, start += step) range[idx] = start\n\n return range;\n}\n // range = (start, stop, step) ->\n // \tif stop == undefined\n // \t\tstop = start || 0\n // \t\tstart = 0\n // \tif step == undefined\n // \t\tstep = if stop < start then -1 else 1\n // \tlength = Math.max(Math.ceil((stop - start) / step), 0)\n // \ti for i in [start...start+length] by step\n;\n\n//##################################################\nN = 3162;\n\np2 = [];\n\nrandint = function(min, max) {\n return min + Math.floor(Math.random() * (max - min + 1));\n};\n\nprepare = function() {\n var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;\n p = (function() {\n var k, len, ref, results;\n ref = range(N);\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(1);\n }\n return results;\n })();\n ref = range(2, N);\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n if (p[i]) {\n ref1 = range(2 * i, N, i);\n for (l = 0, len1 = ref1.length; l < len1; l++) {\n j = ref1[l];\n p[j] = 0;\n }\n }\n }\n ref2 = range(2, N);\n results = [];\n for (m = 0, len2 = ref2.length; m < len2; m++) {\n c = ref2[m];\n if (p[c] === 1) {\n results.push(c * c);\n }\n }\n return results;\n};\n\nf = function(a) {\n var ans, hash, k, kl, l, len, len1, q, r, r0;\n ans = 1;\n kl = {};\n hash = {};\n for (k = 0, len = a.length; k < len; k++) {\n r0 = a[k];\n if (indexOf.call(hash, r0) >= 0) {\n r = hash[r0];\n } else {\n r = r0;\n for (l = 0, len1 = p2.length; l < len1; l++) {\n q = p2[l];\n if (r < q) {\n break;\n }\n while (r % q === 0) {\n r = Math.floor(r / q);\n }\n }\n hash[r0] = r;\n }\n if (r in kl) {\n ans += 1;\n kl = {};\n }\n kl[r] = 1;\n }\n return ans;\n};\n\nmain = function() {\n var _, k, len, ref, results;\n p2 = prepare();\n ref = range(nr());\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n _ = ref[k];\n [_, _] = nrs();\n results.push(print(f(nrs())));\n }\n return results;\n};\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLEtBQUEsRUFBQSxPQUFBO0VBQUE7O0FBQUEsS0FBQSxHQUFRLE9BQU8sQ0FBQzs7QUFFaEIsT0FBTyxDQUFDLEtBQUssQ0FBQyxNQUFkLENBQUE7O0FBQ0EsT0FBTyxDQUFDLEtBQUssQ0FBQyxXQUFkLENBQTBCLE9BQTFCOztBQUVBLFdBQUEsR0FBYzs7QUFDZCxXQUFBLEdBQWM7O0FBRWQsT0FBTyxDQUFDLEtBQUssQ0FBQyxFQUFkLENBQWlCLE1BQWpCLEVBQXlCLFFBQUEsQ0FBQyxVQUFELENBQUE7U0FBZ0IsV0FBQSxJQUFlO0FBQS9CLENBQXpCOztBQUVBLE9BQU8sQ0FBQyxLQUFLLENBQUMsRUFBZCxDQUFpQixLQUFqQixFQUF3QixRQUFBLENBQUMsQ0FBRCxDQUFBO0VBQ3ZCLFdBQUEsR0FBYyxXQUFXLENBQUMsSUFBWixDQUFBLENBQWtCLENBQUMsS0FBbkIsQ0FBeUIsSUFBekIsQ0FBOEIsQ0FBQyxHQUEvQixDQUFtQyxRQUFBLENBQUMsTUFBRCxDQUFBO1dBQVksTUFBTSxDQUFDLElBQVAsQ0FBQTtFQUFaLENBQW5DO1NBQ2QsSUFBQSxDQUFBO0FBRnVCLENBQXhCOztBQUlBLEtBQUEsR0FBUSxRQUFBLENBQUEsQ0FBQTtTQUFHLFdBQVksQ0FBQSxXQUFBLEVBQUE7QUFBZjs7QUFFUixFQUFBLEdBQUssUUFBQSxDQUFBLENBQUE7U0FBTSxRQUFBLENBQVMsS0FBQSxDQUFBLENBQVQ7QUFBTjs7QUFDTCxHQUFBLEdBQU0sUUFBQSxDQUFBLENBQUE7QUFBTSxNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLEdBQUEsRUFBQTtBQUFZO0FBQUE7RUFBQSxLQUFBLHFDQUFBOztpQkFBWCxRQUFBLENBQVMsQ0FBVDtFQUFXLENBQUE7O0FBQWxCOztBQVdOOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztDQTVCQTs7O0FBOENBLENBQUEsR0FBSTs7QUFDSixFQUFBLEdBQUs7O0FBRUwsT0FBQSxHQUFVLFFBQUEsQ0FBQyxHQUFELEVBQU0sR0FBTixDQUFBO1NBQWMsR0FBQSxHQUFNLElBQUksQ0FBQyxLQUFMLENBQVcsSUFBSSxDQUFDLE1BQUwsQ0FBQSxDQUFBLEdBQWdCLENBQUMsR0FBQSxHQUFNLEdBQU4sR0FBWSxDQUFiLENBQTNCO0FBQXBCOztBQUVWLE9BQUEsR0FBVSxRQUFBLENBQUEsQ0FBQTtBQUNULE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBO0VBQUEsQ0FBQTs7QUFBTztBQUFBO0lBQUEsS0FBQSxxQ0FBQTs7bUJBQUY7SUFBRSxDQUFBOzs7QUFDUDtFQUFBLEtBQUEscUNBQUE7O0lBQ0MsSUFBRyxDQUFFLENBQUEsQ0FBQSxDQUFMO0FBQ0M7TUFBQSxLQUFBLHdDQUFBOztRQUNDLENBQUUsQ0FBQSxDQUFBLENBQUYsR0FBTztNQURSLENBREQ7O0VBREQ7QUFJSTtBQUFBO0VBQUEsS0FBQSx3Q0FBQTs7UUFBd0IsQ0FBRSxDQUFBLENBQUEsQ0FBRixLQUFNO21CQUFsQyxDQUFBLEdBQUU7O0VBQUUsQ0FBQTs7QUFOSzs7QUFRVixDQUFBLEdBQUksUUFBQSxDQUFDLENBQUQsQ0FBQTtBQUNILE1BQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxHQUFBLEdBQU07RUFDTixFQUFBLEdBQUssQ0FBQTtFQUNMLElBQUEsR0FBTyxDQUFBO0VBQ1AsS0FBQSxtQ0FBQTs7SUFDQyxJQUFHLGFBQU0sSUFBTixFQUFBLEVBQUEsTUFBSDtNQUNDLENBQUEsR0FBSSxJQUFLLENBQUEsRUFBQSxFQURWO0tBQUEsTUFBQTtNQUdDLENBQUEsR0FBSTtNQUNKLEtBQUEsc0NBQUE7O1FBQ0MsSUFBRyxDQUFBLEdBQUksQ0FBUDtBQUNDLGdCQUREOztBQUVBLGVBQU0sQ0FBQSxHQUFJLENBQUosS0FBUyxDQUFmO1VBQ0MsZUFBQSxJQUFNO1FBRFA7TUFIRDtNQUtBLElBQUssQ0FBQSxFQUFBLENBQUwsR0FBVyxFQVRaOztJQVVBLElBQUcsQ0FBQSxJQUFLLEVBQVI7TUFDQyxHQUFBLElBQU87TUFDUCxFQUFBLEdBQUssQ0FBQSxFQUZOOztJQUdBLEVBQUcsQ0FBQSxDQUFBLENBQUgsR0FBUTtFQWRUO1NBZUE7QUFuQkc7O0FBcUJKLElBQUEsR0FBTyxRQUFBLENBQUEsQ0FBQTtBQUNOLE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsR0FBQSxFQUFBO0VBQUEsRUFBQSxHQUFLLE9BQUEsQ0FBQTtBQUNMO0FBQUE7RUFBQSxLQUFBLHFDQUFBOztJQUNDLENBQUMsQ0FBRCxFQUFHLENBQUgsQ0FBQSxHQUFRLEdBQUEsQ0FBQTtpQkFDUixLQUFBLENBQU0sQ0FBQSxDQUFFLEdBQUEsQ0FBQSxDQUFGLENBQU47RUFGRCxDQUFBOztBQUZNIiwic291cmNlc0NvbnRlbnQiOlsicHJpbnQgPSBjb25zb2xlLmxvZ1xuXG5wcm9jZXNzLnN0ZGluLnJlc3VtZSgpXG5wcm9jZXNzLnN0ZGluLnNldEVuY29kaW5nICd1dGYtOCdcbiBcbmlucHV0U3RyaW5nID0gJydcbmN1cnJlbnRMaW5lID0gMFxuIFxucHJvY2Vzcy5zdGRpbi5vbiAnZGF0YScsIChpbnB1dFN0ZGluKSAtPiBpbnB1dFN0cmluZyArPSBpbnB1dFN0ZGluXG4gXG5wcm9jZXNzLnN0ZGluLm9uICdlbmQnLCAoXykgLT4gXG5cdGlucHV0U3RyaW5nID0gaW5wdXRTdHJpbmcudHJpbSgpLnNwbGl0KCdcXG4nKS5tYXAgKHN0cmluZykgLT4gc3RyaW5nLnRyaW0oKVxuXHRtYWluKClcblxuaW5wdXQgPSAtPiBpbnB1dFN0cmluZ1tjdXJyZW50TGluZSsrXVxuXG5uciA9ICgpIC0+IHBhcnNlSW50IGlucHV0KCkgXG5ucnMgPSAoKSAtPiAocGFyc2VJbnQgaSBmb3IgaSBpbiBpbnB1dCgpLnNwbGl0ICcgJylcblxuIyByYW5nZSA9IChzdGFydCwgc3RvcCwgc3RlcCkgLT5cbiMgXHRpZiBzdG9wID09IHVuZGVmaW5lZFxuIyBcdFx0c3RvcCA9IHN0YXJ0IHx8IDBcbiMgXHRcdHN0YXJ0ID0gMFxuIyBcdGlmIHN0ZXAgPT0gdW5kZWZpbmVkXG4jIFx0XHRzdGVwID0gaWYgc3RvcCA8IHN0YXJ0IHRoZW4gLTEgZWxzZSAxXG4jIFx0bGVuZ3RoID0gTWF0aC5tYXgoTWF0aC5jZWlsKChzdG9wIC0gc3RhcnQpIC8gc3RlcCksIDApXG4jIFx0aSBmb3IgaSBpbiBbc3RhcnQuLi5zdGFydCtsZW5ndGhdIGJ5IHN0ZXBcblxuYGBgXG5mdW5jdGlvbiByYW5nZShzdGFydCwgc3RvcCwgc3RlcCkge1xuICBpZiAoc3RvcCA9PSBudWxsKSB7XG4gICAgc3RvcCA9IHN0YXJ0IHx8IDBcbiAgICBzdGFydCA9IDBcbiAgfVxuICBpZiAoIXN0ZXApIHN0ZXAgPSBzdG9wIDwgc3RhcnQgPyAtMSA6IDFcblxuICB2YXIgbGVuZ3RoID0gTWF0aC5tYXgoTWF0aC5jZWlsKChzdG9wIC0gc3RhcnQpIC8gc3RlcCksIDApXG4gIHZhciByYW5nZSA9IEFycmF5KGxlbmd0aClcblxuICBmb3IgKHZhciBpZHggPSAwOyBpZHggPCBsZW5ndGg7IGlkeCsrLCBzdGFydCArPSBzdGVwKSByYW5nZVtpZHhdID0gc3RhcnRcblxuICByZXR1cm4gcmFuZ2U7XG59XG5gYGBcbiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjI1xuXG5OID0gMzE2MlxucDIgPSBbXVxuXG5yYW5kaW50ID0gKG1pbiwgbWF4KSAtPiBtaW4gKyBNYXRoLmZsb29yIE1hdGgucmFuZG9tKCkgKiAobWF4IC0gbWluICsgMSkgIFxuXG5wcmVwYXJlID0gLT5cblx0cCA9ICgxIGZvciBpIGluIHJhbmdlIE4pXG5cdGZvciBpIGluIHJhbmdlIDIsTlxuXHRcdGlmIHBbaV1cblx0XHRcdGZvciBqIGluIHJhbmdlIDIqaSxOLGlcblx0XHRcdFx0cFtqXSA9IDBcblx0YypjIGZvciBjIGluIHJhbmdlIDIsTiB3aGVuIHBbY109PTFcblxuZiA9IChhKSAtPlxuXHRhbnMgPSAxXG5cdGtsID0ge31cblx0aGFzaCA9IHt9XG5cdGZvciByMCBpbiBhXG5cdFx0aWYgcjAgaW4gaGFzaFxuXHRcdFx0ciA9IGhhc2hbcjBdXG5cdFx0ZWxzZVxuXHRcdFx0ciA9IHIwXG5cdFx0XHRmb3IgcSBpbiBwMlxuXHRcdFx0XHRpZiByIDwgcVxuXHRcdFx0XHRcdGJyZWFrXG5cdFx0XHRcdHdoaWxlIHIgJSBxID09IDBcblx0XHRcdFx0XHRyIC8vPSBxXG5cdFx0XHRoYXNoW3IwXSA9IHJcblx0XHRpZiByIG9mIGtsXG5cdFx0XHRhbnMgKz0gMVxuXHRcdFx0a2wgPSB7fVxuXHRcdGtsW3JdID0gMVxuXHRhbnNcblxubWFpbiA9IC0+XG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIHJhbmdlIG5yKClcblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuIl19\n//# sourceURL=c:\\github\\2021\\010\\coffee\\app.coffee"}, {"source_code": "// Generated by CoffeeScript 2.4.1\nvar N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,\n indexOf = [].indexOf;\n\nprint = console.log;\n\nprocess.stdin.resume();\n\nprocess.stdin.setEncoding('utf-8');\n\ninputString = '';\n\ncurrentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n return inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function(_) {\n inputString = inputString.trim().split('\\n').map(function(string) {\n return string.trim();\n });\n return main();\n});\n\ninput = function() {\n return inputString[currentLine++];\n};\n\nnr = function() {\n return parseInt(input());\n};\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = input().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\n// range = (start, stop, step) ->\n// \tif stop == undefined\n// \t\tstop = start || 0\n// \t\tstart = 0\n// \tif step == undefined\n// \t\tstep = if stop < start then -1 else 1\n// \tlength = Math.max(Math.ceil((stop - start) / step), 0)\n// \ti for i in [start...start+length] by step\n\n//##################################################\nN = 3162;\n\np2 = [];\n\nrandint = function(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n};\n\nprepare = function() {\n var c, i, j, k, l, m, p, ref, ref1, ref2, ref3, ref4, results;\n p = (function() {\n var k, ref, results;\n results = [];\n for (i = k = 0, ref = N; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {\n results.push(1);\n }\n return results;\n })();\n for (i = k = 2, ref = N; (2 <= ref ? k < ref : k > ref); i = 2 <= ref ? ++k : --k) {\n if (p[i]) {\n for (j = l = ref1 = 2 * i, ref2 = N, ref3 = i; ref3 !== 0 && (ref3 > 0 ? l < ref2 : l > ref2); j = l += ref3) {\n p[j] = 0;\n }\n }\n }\n results = [];\n for (c = m = 2, ref4 = N; (2 <= ref4 ? m < ref4 : m > ref4); c = 2 <= ref4 ? ++m : --m) {\n if (p[c] === 1) {\n results.push(c * c);\n }\n }\n return results;\n};\n\nf = function(a) {\n var ans, hash, k, kl, l, len, len1, q, r, r0;\n ans = 1;\n kl = {};\n hash = {};\n for (k = 0, len = a.length; k < len; k++) {\n r0 = a[k];\n if (indexOf.call(hash, r0) >= 0) {\n r = hash[r0];\n } else {\n r = r0;\n for (l = 0, len1 = p2.length; l < len1; l++) {\n q = p2[l];\n if (r < q) {\n break;\n }\n while (r % q === 0) {\n r = Math.floor(r / q);\n }\n }\n hash[r0] = r;\n }\n if (r in kl) {\n ans += 1;\n kl = {};\n }\n kl[r] = 1;\n }\n return ans;\n};\n\nmain = function() {\n var _, k, ref, results;\n p2 = prepare();\n results = [];\n for (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {\n [_, _] = nrs();\n results.push(print(f(nrs())));\n }\n return results;\n};\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLEtBQUEsRUFBQSxPQUFBO0VBQUE7O0FBQUEsS0FBQSxHQUFRLE9BQU8sQ0FBQzs7QUFFaEIsT0FBTyxDQUFDLEtBQUssQ0FBQyxNQUFkLENBQUE7O0FBQ0EsT0FBTyxDQUFDLEtBQUssQ0FBQyxXQUFkLENBQTBCLE9BQTFCOztBQUVBLFdBQUEsR0FBYzs7QUFDZCxXQUFBLEdBQWM7O0FBRWQsT0FBTyxDQUFDLEtBQUssQ0FBQyxFQUFkLENBQWlCLE1BQWpCLEVBQXlCLFFBQUEsQ0FBQyxVQUFELENBQUE7U0FBZ0IsV0FBQSxJQUFlO0FBQS9CLENBQXpCOztBQUVBLE9BQU8sQ0FBQyxLQUFLLENBQUMsRUFBZCxDQUFpQixLQUFqQixFQUF3QixRQUFBLENBQUMsQ0FBRCxDQUFBO0VBQ3ZCLFdBQUEsR0FBYyxXQUFXLENBQUMsSUFBWixDQUFBLENBQWtCLENBQUMsS0FBbkIsQ0FBeUIsSUFBekIsQ0FBOEIsQ0FBQyxHQUEvQixDQUFtQyxRQUFBLENBQUMsTUFBRCxDQUFBO1dBQVksTUFBTSxDQUFDLElBQVAsQ0FBQTtFQUFaLENBQW5DO1NBQ2QsSUFBQSxDQUFBO0FBRnVCLENBQXhCOztBQUlBLEtBQUEsR0FBUSxRQUFBLENBQUEsQ0FBQTtTQUFHLFdBQVksQ0FBQSxXQUFBLEVBQUE7QUFBZjs7QUFFUixFQUFBLEdBQUssUUFBQSxDQUFBLENBQUE7U0FBTSxRQUFBLENBQVMsS0FBQSxDQUFBLENBQVQ7QUFBTjs7QUFDTCxHQUFBLEdBQU0sUUFBQSxDQUFBLENBQUE7QUFBTSxNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLEdBQUEsRUFBQTtBQUFZO0FBQUE7RUFBQSxLQUFBLHFDQUFBOztpQkFBWCxRQUFBLENBQVMsQ0FBVDtFQUFXLENBQUE7O0FBQWxCLEVBakJOOzs7Ozs7Ozs7Ozs7QUE4QkEsQ0FBQSxHQUFJOztBQUNKLEVBQUEsR0FBSzs7QUFFTCxPQUFBLEdBQVUsUUFBQSxDQUFDLEdBQUQsRUFBTSxHQUFOLENBQUE7U0FBYyxJQUFJLENBQUMsS0FBTCxDQUFXLElBQUksQ0FBQyxNQUFMLENBQUEsQ0FBQSxHQUFnQixDQUFDLEdBQUEsR0FBTSxHQUFOLEdBQVksQ0FBYixDQUEzQixDQUFBLEdBQStDO0FBQTdEOztBQUVWLE9BQUEsR0FBVSxRQUFBLENBQUEsQ0FBQTtBQUNULE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxJQUFBLEVBQUE7RUFBQSxDQUFBOztBQUFPO0lBQUEsS0FBUyw0RUFBVDttQkFBRjtJQUFFLENBQUE7OztFQUNQLEtBQVMsNEVBQVQ7SUFDQyxJQUFHLENBQUUsQ0FBQSxDQUFBLENBQUw7TUFDQyxLQUFTLHVHQUFUO1FBQ0MsQ0FBRSxDQUFBLENBQUEsQ0FBRixHQUFPO01BRFIsQ0FERDs7RUFERDtBQUlJO0VBQUEsS0FBUyxpRkFBVDtRQUFzQixDQUFFLENBQUEsQ0FBQSxDQUFGLEtBQU07bUJBQWhDLENBQUEsR0FBRTs7RUFBRSxDQUFBOztBQU5LOztBQVFWLENBQUEsR0FBSSxRQUFBLENBQUMsQ0FBRCxDQUFBO0FBQ0gsTUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxFQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQTtFQUFBLEdBQUEsR0FBTTtFQUNOLEVBQUEsR0FBSyxDQUFBO0VBQ0wsSUFBQSxHQUFPLENBQUE7RUFDUCxLQUFBLG1DQUFBOztJQUNDLElBQUcsYUFBTSxJQUFOLEVBQUEsRUFBQSxNQUFIO01BQ0MsQ0FBQSxHQUFJLElBQUssQ0FBQSxFQUFBLEVBRFY7S0FBQSxNQUFBO01BR0MsQ0FBQSxHQUFJO01BQ0osS0FBQSxzQ0FBQTs7UUFDQyxJQUFHLENBQUEsR0FBSSxDQUFQO0FBQ0MsZ0JBREQ7O0FBRUEsZUFBTSxDQUFBLEdBQUksQ0FBSixLQUFTLENBQWY7VUFDQyxlQUFBLElBQU07UUFEUDtNQUhEO01BS0EsSUFBSyxDQUFBLEVBQUEsQ0FBTCxHQUFTLEVBVFY7O0lBVUEsSUFBRyxDQUFBLElBQUssRUFBUjtNQUNDLEdBQUEsSUFBTztNQUNQLEVBQUEsR0FBSyxDQUFBLEVBRk47O0lBR0EsRUFBRyxDQUFBLENBQUEsQ0FBSCxHQUFRO0VBZFQ7U0FlQTtBQW5CRzs7QUFxQkosSUFBQSxHQUFPLFFBQUEsQ0FBQSxDQUFBO0FBQ04sTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQTtFQUFBLEVBQUEsR0FBSyxPQUFBLENBQUE7QUFDTDtFQUFBLEtBQVMsK0VBQVQ7SUFDQyxDQUFDLENBQUQsRUFBRyxDQUFILENBQUEsR0FBUSxHQUFBLENBQUE7aUJBQ1IsS0FBQSxDQUFNLENBQUEsQ0FBRSxHQUFBLENBQUEsQ0FBRixDQUFOO0VBRkQsQ0FBQTs7QUFGTSIsInNvdXJjZXNDb250ZW50IjpbInByaW50ID0gY29uc29sZS5sb2dcblxucHJvY2Vzcy5zdGRpbi5yZXN1bWUoKVxucHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZyAndXRmLTgnXG4gXG5pbnB1dFN0cmluZyA9ICcnXG5jdXJyZW50TGluZSA9IDBcbiBcbnByb2Nlc3Muc3RkaW4ub24gJ2RhdGEnLCAoaW5wdXRTdGRpbikgLT4gaW5wdXRTdHJpbmcgKz0gaW5wdXRTdGRpblxuIFxucHJvY2Vzcy5zdGRpbi5vbiAnZW5kJywgKF8pIC0+IFxuXHRpbnB1dFN0cmluZyA9IGlucHV0U3RyaW5nLnRyaW0oKS5zcGxpdCgnXFxuJykubWFwIChzdHJpbmcpIC0+IHN0cmluZy50cmltKClcblx0bWFpbigpXG5cbmlucHV0ID0gLT4gaW5wdXRTdHJpbmdbY3VycmVudExpbmUrK11cblxubnIgPSAoKSAtPiBwYXJzZUludCBpbnB1dCgpXG5ucnMgPSAoKSAtPiAocGFyc2VJbnQgaSBmb3IgaSBpbiBpbnB1dCgpLnNwbGl0ICcgJylcblxuIyByYW5nZSA9IChzdGFydCwgc3RvcCwgc3RlcCkgLT5cbiMgXHRpZiBzdG9wID09IHVuZGVmaW5lZFxuIyBcdFx0c3RvcCA9IHN0YXJ0IHx8IDBcbiMgXHRcdHN0YXJ0ID0gMFxuIyBcdGlmIHN0ZXAgPT0gdW5kZWZpbmVkXG4jIFx0XHRzdGVwID0gaWYgc3RvcCA8IHN0YXJ0IHRoZW4gLTEgZWxzZSAxXG4jIFx0bGVuZ3RoID0gTWF0aC5tYXgoTWF0aC5jZWlsKChzdG9wIC0gc3RhcnQpIC8gc3RlcCksIDApXG4jIFx0aSBmb3IgaSBpbiBbc3RhcnQuLi5zdGFydCtsZW5ndGhdIGJ5IHN0ZXBcblxuIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjXG5cbk4gPSAzMTYyXG5wMiA9IFtdXG5cbnJhbmRpbnQgPSAobWluLCBtYXgpIC0+IE1hdGguZmxvb3IoTWF0aC5yYW5kb20oKSAqIChtYXggLSBtaW4gKyAxKSApICsgbWluXG5cbnByZXBhcmUgPSAoKSAtPlxuXHRwID0gKDEgZm9yIGkgaW4gWzAuLi5OXSlcblx0Zm9yIGkgaW4gWzIuLi5OXVxuXHRcdGlmIHBbaV1cblx0XHRcdGZvciBqIGluIFsyKmkuLi5OXSBieSBpXG5cdFx0XHRcdHBbal0gPSAwXG5cdGMqYyBmb3IgYyBpbiBbMi4uLk5dIHdoZW4gcFtjXT09MVxuXG5mID0gKGEpIC0+XG5cdGFucyA9IDFcblx0a2wgPSB7fVxuXHRoYXNoID0ge31cblx0Zm9yIHIwIGluIGFcblx0XHRpZiByMCBpbiBoYXNoXG5cdFx0XHRyID0gaGFzaFtyMF1cblx0XHRlbHNlXG5cdFx0XHRyID0gcjBcblx0XHRcdGZvciBxIGluIHAyXG5cdFx0XHRcdGlmIHIgPCBxXG5cdFx0XHRcdFx0YnJlYWtcblx0XHRcdFx0d2hpbGUgciAlIHEgPT0gMFxuXHRcdFx0XHRcdHIgLy89IHFcblx0XHRcdGhhc2hbcjBdPXJcblx0XHRpZiByIG9mIGtsXG5cdFx0XHRhbnMgKz0gMVxuXHRcdFx0a2wgPSB7fVxuXHRcdGtsW3JdID0gMVxuXHRhbnNcblxubWFpbiA9IC0+XG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIFswLi4ubnIoKV1cblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuIl19\n//# sourceURL=c:\\github\\2021\\010\\coffee\\app.coffee"}, {"source_code": "// Generated by CoffeeScript 2.4.1\n //_ = require 'underscore'\n\n //range = _.range\nvar N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,\n indexOf = [].indexOf;\n\nprint = console.log;\n\nprocess.stdin.resume();\n\nprocess.stdin.setEncoding('utf-8');\n\ninputString = '';\n\ncurrentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n return inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function(_) {\n inputString = inputString.trim().split('\\n').map(function(string) {\n return string.trim();\n });\n return main();\n});\n\ninput = function() {\n return inputString[currentLine++];\n};\n\nnr = function() {\n return parseInt(input());\n};\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = input().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\n//##################################################\nN = 3162;\n\np2 = [];\n\nrandint = function(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n};\n\nprepare = function() {\n var c, i, j, k, l, m, p, ref, ref1, ref2, ref3, ref4, results;\n p = (function() {\n var k, ref, results;\n results = [];\n for (i = k = 0, ref = N; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {\n results.push(1);\n }\n return results;\n })();\n for (i = k = 2, ref = N; (2 <= ref ? k < ref : k > ref); i = 2 <= ref ? ++k : --k) {\n if (p[i]) {\n for (j = l = ref1 = 2 * i, ref2 = N, ref3 = i; ref3 !== 0 && (ref3 > 0 ? l < ref2 : l > ref2); j = l += ref3) {\n p[j] = 0;\n }\n }\n }\n results = [];\n for (c = m = 2, ref4 = N; (2 <= ref4 ? m < ref4 : m > ref4); c = 2 <= ref4 ? ++m : --m) {\n if (p[c] === 1) {\n results.push(c * c);\n }\n }\n return results;\n};\n\nf = function(a) {\n var ans, hash, k, kl, l, len, len1, q, r, r0;\n ans = 1;\n kl = {};\n hash = {};\n for (k = 0, len = a.length; k < len; k++) {\n r0 = a[k];\n if (indexOf.call(hash, r0) >= 0) {\n r = hash[r0];\n } else {\n r = r0;\n for (l = 0, len1 = p2.length; l < len1; l++) {\n q = p2[l];\n if (r < q) {\n break;\n }\n while (r % q === 0) {\n r = Math.floor(r / q);\n }\n }\n hash[r0] = r;\n }\n if (r in kl) {\n ans += 1;\n kl = {};\n }\n kl[r] = 1;\n }\n return ans;\n};\n\nmain = function() {\n var _, k, ref, results;\n //start = Date.now()\n p2 = prepare();\n results = [];\n for (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {\n [_, _] = nrs();\n results.push(print(f(nrs())));\n }\n return results;\n};\n\n// seed = 1;\n// random = () ->\n// \tx = Math.sin(seed++) * 10000\n// \tx - Math.floor(x)\n\n// print f (Math.floor 1 + 2000000 * random() for i in range 200000)\n// #f([9790577 for i in range(200000)])\n//print Date.now() - start,'ms'\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7QUFBQSxJQUFBLENBQUEsRUFBQSxXQUFBLEVBQUEsQ0FBQSxFQUFBLEtBQUEsRUFBQSxXQUFBLEVBQUEsSUFBQSxFQUFBLEVBQUEsRUFBQSxHQUFBLEVBQUEsRUFBQSxFQUFBLE9BQUEsRUFBQSxLQUFBLEVBQUEsT0FBQTtFQUFBOztBQUdBLEtBQUEsR0FBUSxPQUFPLENBQUM7O0FBRWhCLE9BQU8sQ0FBQyxLQUFLLENBQUMsTUFBZCxDQUFBOztBQUNBLE9BQU8sQ0FBQyxLQUFLLENBQUMsV0FBZCxDQUEwQixPQUExQjs7QUFFQSxXQUFBLEdBQWM7O0FBQ2QsV0FBQSxHQUFjOztBQUVkLE9BQU8sQ0FBQyxLQUFLLENBQUMsRUFBZCxDQUFpQixNQUFqQixFQUF5QixRQUFBLENBQUMsVUFBRCxDQUFBO1NBQWdCLFdBQUEsSUFBZTtBQUEvQixDQUF6Qjs7QUFFQSxPQUFPLENBQUMsS0FBSyxDQUFDLEVBQWQsQ0FBaUIsS0FBakIsRUFBd0IsUUFBQSxDQUFDLENBQUQsQ0FBQTtFQUN2QixXQUFBLEdBQWMsV0FBVyxDQUFDLElBQVosQ0FBQSxDQUFrQixDQUFDLEtBQW5CLENBQXlCLElBQXpCLENBQThCLENBQUMsR0FBL0IsQ0FBbUMsUUFBQSxDQUFDLE1BQUQsQ0FBQTtXQUFZLE1BQU0sQ0FBQyxJQUFQLENBQUE7RUFBWixDQUFuQztTQUNkLElBQUEsQ0FBQTtBQUZ1QixDQUF4Qjs7QUFJQSxLQUFBLEdBQVEsUUFBQSxDQUFBLENBQUE7U0FBRyxXQUFZLENBQUEsV0FBQSxFQUFBO0FBQWY7O0FBRVIsRUFBQSxHQUFLLFFBQUEsQ0FBQSxDQUFBO1NBQU0sUUFBQSxDQUFTLEtBQUEsQ0FBQSxDQUFUO0FBQU47O0FBQ0wsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQU0sTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBWTtBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFsQixFQXBCTjs7O0FBd0JBLENBQUEsR0FBSTs7QUFDSixFQUFBLEdBQUs7O0FBRUwsT0FBQSxHQUFVLFFBQUEsQ0FBQyxHQUFELEVBQU0sR0FBTixDQUFBO1NBQWMsSUFBSSxDQUFDLEtBQUwsQ0FBVyxJQUFJLENBQUMsTUFBTCxDQUFBLENBQUEsR0FBZ0IsQ0FBQyxHQUFBLEdBQU0sR0FBTixHQUFZLENBQWIsQ0FBM0IsQ0FBQSxHQUErQztBQUE3RDs7QUFFVixPQUFBLEdBQVUsUUFBQSxDQUFBLENBQUE7QUFDVCxNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBO0VBQUEsQ0FBQTs7QUFBTztJQUFBLEtBQVMsNEVBQVQ7bUJBQUY7SUFBRSxDQUFBOzs7RUFDUCxLQUFTLDRFQUFUO0lBQ0MsSUFBRyxDQUFFLENBQUEsQ0FBQSxDQUFMO01BQ0MsS0FBUyx1R0FBVDtRQUNDLENBQUUsQ0FBQSxDQUFBLENBQUYsR0FBTztNQURSLENBREQ7O0VBREQ7QUFJSTtFQUFBLEtBQVMsaUZBQVQ7UUFBc0IsQ0FBRSxDQUFBLENBQUEsQ0FBRixLQUFNO21CQUFoQyxDQUFBLEdBQUU7O0VBQUUsQ0FBQTs7QUFOSzs7QUFRVixDQUFBLEdBQUksUUFBQSxDQUFDLENBQUQsQ0FBQTtBQUNILE1BQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxHQUFBLEdBQU07RUFDTixFQUFBLEdBQUssQ0FBQTtFQUNMLElBQUEsR0FBTyxDQUFBO0VBQ1AsS0FBQSxtQ0FBQTs7SUFDQyxJQUFHLGFBQU0sSUFBTixFQUFBLEVBQUEsTUFBSDtNQUNDLENBQUEsR0FBSSxJQUFLLENBQUEsRUFBQSxFQURWO0tBQUEsTUFBQTtNQUdDLENBQUEsR0FBSTtNQUNKLEtBQUEsc0NBQUE7O1FBQ0MsSUFBRyxDQUFBLEdBQUksQ0FBUDtBQUNDLGdCQUREOztBQUVBLGVBQU0sQ0FBQSxHQUFJLENBQUosS0FBUyxDQUFmO1VBQ0MsZUFBQSxJQUFNO1FBRFA7TUFIRDtNQUtBLElBQUssQ0FBQSxFQUFBLENBQUwsR0FBUyxFQVRWOztJQVVBLElBQUcsQ0FBQSxJQUFLLEVBQVI7TUFDQyxHQUFBLElBQU87TUFDUCxFQUFBLEdBQUssQ0FBQSxFQUZOOztJQUdBLEVBQUcsQ0FBQSxDQUFBLENBQUgsR0FBUTtFQWRUO1NBZUE7QUFuQkc7O0FBcUJKLElBQUEsR0FBTyxRQUFBLENBQUEsQ0FBQTtBQUVOLE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsT0FBQTs7RUFBQSxFQUFBLEdBQUssT0FBQSxDQUFBO0FBQ0w7RUFBQSxLQUFTLCtFQUFUO0lBQ0MsQ0FBQyxDQUFELEVBQUcsQ0FBSCxDQUFBLEdBQVEsR0FBQSxDQUFBO2lCQUNSLEtBQUEsQ0FBTSxDQUFBLENBQUUsR0FBQSxDQUFBLENBQUYsQ0FBTjtFQUZELENBQUE7O0FBSE07O0FBMURQIiwic291cmNlc0NvbnRlbnQiOlsiI18gPSByZXF1aXJlICd1bmRlcnNjb3JlJ1xuXG4jcmFuZ2UgPSBfLnJhbmdlXG5wcmludCA9IGNvbnNvbGUubG9nXG5cbnByb2Nlc3Muc3RkaW4ucmVzdW1lKClcbnByb2Nlc3Muc3RkaW4uc2V0RW5jb2RpbmcgJ3V0Zi04J1xuIFxuaW5wdXRTdHJpbmcgPSAnJ1xuY3VycmVudExpbmUgPSAwXG4gXG5wcm9jZXNzLnN0ZGluLm9uICdkYXRhJywgKGlucHV0U3RkaW4pIC0+IGlucHV0U3RyaW5nICs9IGlucHV0U3RkaW5cbiBcbnByb2Nlc3Muc3RkaW4ub24gJ2VuZCcsIChfKSAtPiBcblx0aW5wdXRTdHJpbmcgPSBpbnB1dFN0cmluZy50cmltKCkuc3BsaXQoJ1xcbicpLm1hcCAoc3RyaW5nKSAtPiBzdHJpbmcudHJpbSgpXG5cdG1haW4oKVxuXG5pbnB1dCA9IC0+IGlucHV0U3RyaW5nW2N1cnJlbnRMaW5lKytdXG5cbm5yID0gKCkgLT4gcGFyc2VJbnQgaW5wdXQoKVxubnJzID0gKCkgLT4gKHBhcnNlSW50IGkgZm9yIGkgaW4gaW5wdXQoKS5zcGxpdCAnICcpXG5cbiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjI1xuXG5OID0gMzE2MlxucDIgPSBbXVxuXG5yYW5kaW50ID0gKG1pbiwgbWF4KSAtPiBNYXRoLmZsb29yKE1hdGgucmFuZG9tKCkgKiAobWF4IC0gbWluICsgMSkgKSArIG1pblxuXG5wcmVwYXJlID0gKCkgLT5cblx0cCA9ICgxIGZvciBpIGluIFswLi4uTl0pXG5cdGZvciBpIGluIFsyLi4uTl1cblx0XHRpZiBwW2ldXG5cdFx0XHRmb3IgaiBpbiBbMippLi4uTl0gYnkgaVxuXHRcdFx0XHRwW2pdID0gMFxuXHRjKmMgZm9yIGMgaW4gWzIuLi5OXSB3aGVuIHBbY109PTFcblxuZiA9IChhKSAtPlxuXHRhbnMgPSAxXG5cdGtsID0ge31cblx0aGFzaCA9IHt9XG5cdGZvciByMCBpbiBhXG5cdFx0aWYgcjAgaW4gaGFzaFxuXHRcdFx0ciA9IGhhc2hbcjBdXG5cdFx0ZWxzZVxuXHRcdFx0ciA9IHIwXG5cdFx0XHRmb3IgcSBpbiBwMlxuXHRcdFx0XHRpZiByIDwgcVxuXHRcdFx0XHRcdGJyZWFrXG5cdFx0XHRcdHdoaWxlIHIgJSBxID09IDBcblx0XHRcdFx0XHRyIC8vPSBxXG5cdFx0XHRoYXNoW3IwXT1yXG5cdFx0aWYgciBvZiBrbFxuXHRcdFx0YW5zICs9IDFcblx0XHRcdGtsID0ge31cblx0XHRrbFtyXSA9IDFcblx0YW5zXG5cbm1haW4gPSAtPlxuXHQjc3RhcnQgPSBEYXRlLm5vdygpXG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIFswLi4ubnIoKV1cblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuXG5cdCMgc2VlZCA9IDE7XG5cdCMgcmFuZG9tID0gKCkgLT5cblx0IyBcdHggPSBNYXRoLnNpbihzZWVkKyspICogMTAwMDBcblx0IyBcdHggLSBNYXRoLmZsb29yKHgpXG5cblx0IyBwcmludCBmIChNYXRoLmZsb29yIDEgKyAyMDAwMDAwICogcmFuZG9tKCkgZm9yIGkgaW4gcmFuZ2UgMjAwMDAwKVxuXHQjICNmKFs5NzkwNTc3IGZvciBpIGluIHJhbmdlKDIwMDAwMCldKVxuXHQjcHJpbnQgRGF0ZS5ub3coKSAtIHN0YXJ0LCdtcydcblxuIl19\n//# sourceURL=c:\\github\\2021\\010\\coffee\\app.coffee"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6+1\r\n\r\nfunction main() {\r\n const value = new Array(maxN + 1).fill(1);\r\n for (let i = 0; i < maxN + 1; i++) {\r\n value[i] = i\r\n }\r\n //\r\n for (let i = 2; i < maxN + 1; i++) {\r\n for (let j = i * i; j < maxN + 1; j += i) {\r\n while (value[j] % (i * i) === 0) {\r\n value[j] = value[j] / (i * i)\r\n }\r\n }\r\n }\r\n // console.log(value)\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = {}\r\n for (let i = 0; i < n; i++) {\r\n a[i] = value[a[i]]\r\n }\r\n\r\n var array = {}\r\n var ans = 0\r\n for (let i = 0; i < n; i++) {\r\n if (i === 0 || array[a[i]]) {\r\n ans++\r\n array = {}\r\n }\r\n array[a[i]] = true\r\n }\r\n // a = a.sort((a,b)=>a-b)\r\n // console.log(a)\r\n console.log(ans)\r\n\r\n });\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6+1\r\n\r\nfunction main() {\r\n const value = new Array(maxN + 1).fill(1);\r\n for (let i = 0; i < maxN + 1; i++) {\r\n value[i] = i\r\n }\r\n //\r\n for (let i = 2; i < maxN + 1; i++) {\r\n for (let j = i * i; j < maxN + 1; j += i) {\r\n if (value[j] % (i * i) === 0) {\r\n value[j] = value[j] / (i * i)\r\n }\r\n }\r\n }\r\n // console.log(value)\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = {}\r\n for (let i = 0; i < n; i++) {\r\n a[i] = value[a[i]]\r\n }\r\n\r\n var array = {}\r\n var ans = 0\r\n for (let i = 0; i < n; i++) {\r\n if (i === 0 || array[a[i]]) {\r\n ans++\r\n array = {}\r\n }\r\n array[a[i]] = true\r\n }\r\n // a = a.sort((a,b)=>a-b)\r\n // console.log(a)\r\n console.log(ans)\r\n\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6\r\n\r\nfunction main() {\r\n const value = new Array(maxN + 1).fill(1);\r\n for (let i = 0; i < maxN + 1; i++) {\r\n value[i] = i\r\n }\r\n //\r\n for (let i = 2; i < maxN + 1; i++) {\r\n for (let j = i * i; j < maxN + 1; j += i) {\r\n if (value[j] % (i * i) === 0) {\r\n value[j] = value[j] / (i * i)\r\n }\r\n }\r\n }\r\n // console.log(value)\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = {}\r\n for (let i = 0; i < n; i++) {\r\n a[i] = value[a[i]]\r\n }\r\n\r\n var array = {}\r\n var ans = 0\r\n for (let i = 0; i < n; i++) {\r\n if (i === 0 || array[a[i]]) {\r\n ans++\r\n array = {}\r\n }\r\n array[a[i]] = true\r\n }\r\n // a = a.sort((a,b)=>a-b)\r\n // console.log(a)\r\n console.log(ans)\r\n\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 30\r\n\r\nfunction main() {\r\n const value = new Array(maxN + 1).fill(1);\r\n for (let i = 0; i < maxN + 1; i++) {\r\n value[i] = i\r\n }\r\n //\r\n for (let i = 2; i < maxN + 1; i++) {\r\n for (let j = i * i; j < maxN + 1; j += i) {\r\n if (value[j] % (i * i) === 0) {\r\n value[j] = value[j] / (i * i)\r\n }\r\n }\r\n }\r\n // console.log(value)\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = {}\r\n for (let i = 0; i < n; i++) {\r\n a[i] = value[a[i]]\r\n }\r\n\r\n var array = []\r\n var ans = 0\r\n for (let i = 0; i < n; i++) {\r\n if (i === 0 || array.includes(a[i])) {\r\n ans++\r\n array = []\r\n }\r\n array.push(a[i])\r\n }\r\n // a = a.sort((a,b)=>a-b)\r\n // console.log(a)\r\n console.log(ans)\r\n\r\n });\r\n}\r\n"}], "src_uid": "878c2e57a396187ccef51d0f941386cf"} {"source_code": "var t = readline();\nvar result = [];\nfor (var i = 0; i < t; i++) {\n\tvar input = readline().split(\" \");\n\tvar diff = input[1] - input[0];\n\tvar count = 0;\n\tvar temp_count = 0;\n\tvar button = [-5,-2,-1,1,2,5];\n\tif (diff < 0) {\n\t\tfor (var j = 0; j < button.length && diff != 0; j++) {\n\t\t\tif (diff <= button[j]) {\n\t\t\t\ttemp_count = Math.floor(diff/button[j]);\n\t\t\t\tcount += temp_count;\n\t\t\t\tdiff -= button[j]*temp_count;\n\t\t\t}\n\t\t}\n\t} else if (diff > 0) {\n\t\tfor (var j = button.length - 1; j >= 0 && diff != 0; j--) {\n\t\t\tif (diff >= button[j]) {\n\t\t\t\ttemp_count = Math.floor(diff/button[j]);\n\t\t\t\tcount += temp_count;\n\t\t\t\tdiff -= button[j]*temp_count;\n\t\t\t}\n\t\t}\n\t}\n\tresult.push(count);\n}\nfor (var i = 0; i < result.length; i++) {\n\tprint(result[i]);\n}", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar v = [0,1,1,2,2];\n\nfor(var i = 0;i parseInt(v));\n var d = Math.abs(arr[0] - arr[1]);\n print(Math.floor(d/5) + v[d%5]);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main() {\n let testCases = readline();\n while(testCases --){\n var line2 = readline();\n let data = line2.split(' ').map(x => parseInt(x));\n checkSound(data);\n }\n}\n\nfunction checkSound([sound1, sound2]){\n let difference = Math.abs(sound1-sound2);\n let steps = 0;\n steps += parseInt(difference/5);\n if(difference%5 == 1 || difference%5 == 2){\n steps++;\n }\n else if(difference%5 == 3 || difference%5 == 4){\n steps += 2;\n }\n console.log(steps)\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n const c = [0, 1, 1, 2, 2, 1]\n for(let i = 0; i < t; i++) {\n const arrT = arr[i].split(' ').map(a => parseInt(a))\n const a = arrT[0]\n const b = arrT[1]\n\n if(a == b) console.log(0)\n else {\n let diff = Math.abs(a - b)\n let count = Math.floor(diff / 5)\n diff = diff - count * 5\n\n count += c[diff]\n\n console.log(count)\n }\n }\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var diff = Math.abs(a - b);\n var count = Math.floor(diff / 5);\n diff %= 5;\n count += Math.floor(diff / 2);\n diff %= 2;\n count += diff;\n output[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n let ans = 0;\n let target = Math.abs(a - b);\n const values = [5, 2, 1];\n let idx = 0;\n\n while (target > 0) {\n ans += Math.floor(target / values[idx]);\n target %= values[idx];\n idx++;\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet n = nl.num();\n let ans = [];\n for(let i = 0; i < n; i++){\n let [a, b] = nl.nums();\n a = Math.abs(a - b);\n let c = Math.trunc(a/5);\n a %= 5;\n c += Math.trunc(a/2);\n a %= 2;\n c += a;\n ans.push(c);\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\n\nvar t=parseInt(readline());\n\nwhile(t--)\n{\n var inp = readline().split(' ').map(Number);\n var a=inp[0];\n var b=inp[1];\n var cnt=Math.abs(a-b);\n \n var res=0;\n \n while(cnt)\n {\n if(cnt>=5){\n var tmp=parseInt(cnt/5);\n cnt-=(tmp*5);\n res+=tmp;\n }\n else if(cnt>=2){\n var tmp=parseInt(cnt/2);\n cnt-=(tmp*2);\n res+=tmp;\n }\n else {\n res+=cnt;\n cnt=0;\n }\n }\n\n print(res);\n}"}, {"source_code": "\nvar go = function(a, b, steps, floor){\n var add = steps * floor;\n if(a0){\n var h1 = go(a, b, steps, floor);\n var h2 = go(a, b, steps, floor+1);\n if(h2 === null) return floor + h1;\n else return floor + Math.min(h1,1 + h2);\n }\n else{\n h1 = go(a, b, steps, 1); \n if(h1 === null) return 0;\n else return 1 + go(a, b, steps, 1);\n }\n}\nvar countSteps = function(a,b){\n if(a==b) return 0;\n var diff = Math.abs(b-a);\n if(diff > 6){\n return toward(a,b,5);\n }else if(diff === 1 || diff === 2 || diff === 5){\n return 1;\n }else{\n return 2;\n }\n}\n\nvar n = parseInt(readline());\nvar i = 0;\nwhile(i 0) {\n\t\tfor (var j = button.length - 1; j >= 0 && diff != 0; j--) {\n\t\t\tif (diff > button[j]) {\n\t\t\t\tcount += Math.floor(diff/button[j]);\n\t\t\t\tdiff -= button[j]*count;\n\t\t\t}\n\t\t}\n\t}\n\tresult.push(count);\n}\nfor (var i = 0; i < result.length; i++) {\n\tprint(result[i]);\n}"}, {"source_code": "'use strict';\n\nvar t=Number(readline());\n\nwhile(t--)\n{\n var inp = readline().split(' ').map(Number);\n var a=inp[0];\n var b=inp[1];\n\n var cnt=Math.abs(a-b);\n\n var res=0;\n\n while(cnt)\n {\n if(cnt>=5){\n var tmp=cnt/5;\n cnt-=(tmp*5);\n res+=tmp;\n }\n else if(cnt>=2){\n var tmp=cnt/2;\n cnt-=(tmp*2);\n res+=tmp;\n }\n else {\n res+=cnt;\n cnt=0;\n }\n }\n\n print(res);\n}"}, {"source_code": "'use strict';\n\nvar t=parseInt(readline());\n\nwhile(t--)\n{\n var inp = readline().split(' ').map(parseInt);\n var a=inp[0];\n var b=inp[1];\n\n var cnt=parseInt (Math.abs(a-b));\n\n var res=0;\n\n while(cnt)\n {\n if(cnt>=5){\n var tmp=parseInt(cnt/5);\n cnt-=(tmp*5);\n res+=tmp;\n }\n else if(cnt>=2){\n var tmp=parseInt(cnt/2);\n cnt-=(tmp*2);\n res+=tmp;\n }\n else {\n res+=cnt;\n cnt=0;\n }\n }\n\n print(res);\n}"}], "src_uid": "ccfe798f5dc63c492ff54cf40bb40613"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tvar list = next();\n\t\twhile(list.indexOf(\"()\") != -1){\n\t\t\tlist = list.replace(\"()\",\"\");\n\t\t}\n\t\toutput[i] = list.length / 2;\n\t}\n\tmyout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n let n = +data[i];\n let s = data[i + 1].trim();\n let count = 0;\n for (let j = 0; j < s.length; j += 1) {\n if (s[j] === '(') count += 1;\n else if (count && s[j] === ')') count -= 1;\n }\n console.log(count);\n i += 2;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n function solve(sequence) {\n var moves = 0;\n var offset = 0;\n for (var i=0; i= 1) { offset--; }\n else { moves++; }\n }\n }\n return moves;\n }\n const testCases = parseInt(readline());\n for (var i=0; i {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\n\twhile (t--) {\n\t\tlet n = readLine();\n\t\tlet s = readLine().split('');\n\t\tlet pos = 0,\n\t\t\tmove = 0;\n\n\t\ts.forEach(p => {\n\t\t\tif (p === '(') {\n\t\t\t\tpos++;\n\t\t\t} else {\n\t\t\t\tpos--;\n\t\t\t\tif (pos < 0) {\n\t\t\t\t\tpos = 0;\n\t\t\t\t\tmove++;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconsole.log(move);\n\t}\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = parseInt(readline());\n\n for(let r=0;r {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n //do nothing?\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n for(var i=str.length-2;i>=0;i--){\n if(str[i]=='('&&str[i+1]==')'){\n // \u5220\u9664\u4ed6\u4fe9\n str = `${str.substring(0,i)}${str.substring(i+2, str.length)}`\n }\n }\n return str.length / 2\n}"}, {"source_code": "var n = readline();\nvar llen = [];\nvar inp = [];\nfor (var i = 0; i0)\n open--;\n else\n close++;\n }\n }\n print(close);\n}"}, {"source_code": "var testCase = Number(readline());\nwhile(testCase--)\n{\n\treadline();\n\tvar str = readline();\n\tfor( var i=1;i<=25;i++)\n\t{\n\t\tstr=str.replace('()','');\n\t}\n\tprint(Math.floor(str.length/2));\n}"}, {"source_code": "function solve() {\n var n = Number(read());\n var s = read();\n var min = 0;\n var sum = 0;\n for (var i = 0; i < n; i++) {\n sum += s[i] === '(' ? 1 : -1;\n if (sum < min) {\n min = sum;\n }\n }\n write(0 - min);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let _ = readLine();\n let str = readLine();\n let stack = [];\n for (let i = 0; i < str.length; i++) {\n let char = str[i];\n if (stack[stack.length - 1] === \"(\" && char === \")\") {\n stack.pop();\n } else {\n stack.push(char);\n }\n }\n console.log(stack.length / 2);\n }\n}\n"}], "negative_code": [], "src_uid": "7a724f327c6202735661be25ef9328d2"} {"source_code": "getInt = () => parseInt(readline());\ngetFlt = () => parseFloat(readline());\ngetArrInt = () => readline().split(' ').map(x => parseInt(x));\ngetArrFlt = () => readline().split(' ').map(x => parseFloat(x));\nInt = (x) => Math.floor(x);\n\nnums = getArrInt();\nm = nums[0];\nn = nums[1];\n\n\nvar t = [];\nfor(i = 0; i <= m; i++) t[i] = [];\n\nfor (var i = 1; i <= m; i++){\n\ttijs = readline().split(' ').map(x => parseInt(x));\n\ttijs.forEach((el, j) => {\n\t\tt[i][j + 1] = el;\n\t})\n}\n\n\ndp = new Array( m + 1 ).fill(0);\nfor(var worker = 1; worker <= n; worker++){\n\tvar getFree = 0;\n\tfor(var pic = 1; pic <= m; pic++){\n\t\tgetFree = Math.max(getFree, dp[pic]);\n\t\tdp[pic] = getFree + t[pic][worker];\n\t\tgetFree = dp[pic];\n\t}\n}\n\nfor(var pic = 1; pic <= m; pic++){\n\twrite (dp[pic] + \" \");\n}", "positive_code": [{"source_code": "print(function(m, n){\n\tvar i, j, ans = [], a = [];\n\tfor(i=0; i 1) {\n for (var i = 1; i < pictures; i++) {\n for(var j = 1; j < autors; j++) {\n before = parseInt(info[i-1][j], 10);\n actual = parseInt(info[i][j-1], 10);\n info[i][j] = Math.max(before,actual) + parseInt(info[i][j]);\n }\n }\n}\n\nvar result = [];\nfor (var i = 0; i < info.length; i++) {\n result.push(info[i].pop());\n}\nprint(result.join(' '));"}, {"source_code": "print(function(m, n) {\n var i, j, ans=[], a=[];\n for(var i=0; i parseInt(readline());\ngetFlt = () => parseFloat(readline());\ngetArrInt = () => readline().split(' ').map(x => parseInt(x));\ngetArrFlt = () => readline().split(' ').map(x => parseFloat(x));\nInt = (x) => Math.floor(x);\n\nnums = getArrInt();\nm = nums[0];\nn = nums[1];\n\n\nvar t = new Array(m + 1);\nfor(i = 0; i <= m; i++) t[i] = new Array(n + 1);\n\nfor (var i = 1; i <= m; i++){\n\ttijs = \n\treadline()\n\t.split(' ')\n\t.map(x => parseInt(x))\n\t.forEach((el, j) => {\n\t\tt[i][j + 1] = el;\n\t});\n}\n\n\ndp = new Array( m + 1 ).fill(0);\nfor(var worker = 1; worker <= n; worker++){\n\tvar getFree = 0;\n\tfor(var pic = 1; pic <= m; pic++){\n\t\tgetFree = Math.max(getFree, dp[pic]);\n\t\tdp[pic] = getFree + t[pic][worker];\n\t\tgetFree = dp[pic];\n\t}\n}\n\nfor(var pic = 1; pic <= m; pic++){\n\twrite (dp[pic] + \" \");\n}"}, {"source_code": "getInt = () => parseInt(readline());\ngetFlt = () => parseFloat(readline());\ngetArrInt = () => readline().split(' ').map(x => parseInt(x));\ngetArrFlt = () => readline().split(' ').map(x => parseFloat(x));\nInt = (x) => Math.floor(x);\n\nnums = getArrInt();\nm = nums[0];\nn = nums[1];\n\n\nvar t = new Array(m + 1);\nfor(i = 0; i <= m; i++) t[i] = new Array(n + 1);\n\nfor (var i = 1; i <= m; i++){\n\ttijs = readline().split(' ').map(x => parseInt(x));\n\ttijs.forEach((el, j) => {\n\t\tt[i][j + 1] = el;\n\t})\n}\n\n\ndp = new Array( m + 1 ).fill(0);\nfor(var worker = 1; worker <= n; worker++){\n\tvar getFree = 0;\n\tfor(var pic = 1; pic <= m; pic++){\n\t\tgetFree = Math.max(getFree, dp[pic]);\n\t\tdp[pic] = getFree + t[pic][worker];\n\t\tgetFree = dp[pic];\n\t}\n}\n\nfor(var pic = 1; pic <= m; pic++){\n\twrite (dp[pic] + \" \");\n}"}], "negative_code": [{"source_code": "print(function(m, n) {\n var i, j, ans=[], a=[];\n for(var i=0; i 0 ? positiveDays : 0;\n\t\n\tvar countedDays = day - lastPaidDay - 1;\n\tvar negDays = countedDays - positiveDays;\n\tbalance -= P*countedDays;\n\t\n\tif(negDays > 0) {\n\t\tnumOfDays+=negDays;\n\t}\n\t\n\tbalance = balance + value - P;\n\tif(balance < 0) {\n\t\tnumOfDays++;\n\t}\n\t\n\tlastPaidDay = day;\n}\n\nvar positiveDays = Math.floor(balance / P);\npositiveDays = positiveDays > 0 ? positiveDays : 0;\nvar countedDays = M - lastPaidDay;\nvar negDays = countedDays - positiveDays\nbalance -= P*countedDays;\n\nif(negDays > 0) {\n\tnumOfDays+=negDays;\n}\n\nwrite(numOfDays);"}], "negative_code": [{"source_code": "function parseNumber(x) { \n return parseInt(x); \n}\n\nvar numbers = readline().split(\" \").map(parseNumber);\nvar N = numbers[0], P = numbers[1], M = numbers[2];\nvar balance = 0, numOfDays = 0, payments = [];\nvar lastPaidDay = 0;\n\nfor(var i = 0; i < N; i++) {\n var pay = readline().split(\" \").map(parseNumber);\n\tvar day = pay[0];\n\tvar value = pay[1];\n\t\n\tvar positiveDays = Math.floor(balance / P);\n\t\n\tvar countedDays = day - lastPaidDay - 1;\n\tvar negDays = countedDays - positiveDays;\n\tbalance -= P*countedDays;\n\t\n\tif(negDays > 0) {\n\t\tnumOfDays+=negDays;\n\t}\n\t\n\tbalance = balance + value - P;\n\tif(balance < 0) {\n\t\tnumOfDays++;\n\t}\n\t\n\tlastPaidDay = day;\n}\n\nvar positiveDays = Math.floor(balance / P);\nvar countedDays = M - lastPaidDay;\nvar negDays = countedDays - positiveDays\nbalance -= P*countedDays;\n\nif(negDays > 0) {\n\tnumOfDays+=negDays;\n}\n\nwrite(numOfDays);"}], "src_uid": "09fa979c7654a0cc79e1bb29500e1dec"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function c(){return f().split(\" \").map((t=>parseFloat(t)))}function h(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:f,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols: number[][] = []\n// \n// for (let j = 0; j < m; ++j) {\n// let s: number[] = []\n// for (let i = 0; i < n; ++i) {\n// s.push(a[i][j])\n// }\n// cols.push(s)\n// }\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.deepCopy().map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// // io.debug(f)\n// // io.debug(cols[0])\n// // io.debug(cols[0][0])\n// // io.debug(f.indexOf(cols[0][0]))\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// // io.debug(indices)\n// \n// let h = Array.numbersMatrix(n, m)\n// \n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// io.debug(i + \" \" + j)\n// h[i][j] = a[k][j]\n// // io.debug(h)\n// }\n// k++\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// io.puts(h[i].join(\" \"))\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;et.toString())).join(\"\\n\"):this.join(\" \")}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(747));let s=\"\",i=[],u=0,l=\"\";const a=\"local\"===process.argv[2],p=t=>{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols = a.transpose()\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.deepCopy().map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// h[i][j] = a[k][j]\n// }\n// k++\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// io.puts(h[i].join(\" \"))\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let cols = new Array(n);\n for(let i = 0; i < n; i++){\n cols[i] = readline().split(' ');\n }\n\n let rows = new Array(m);\n for(let i = 0; i < m; i++){\n rows[i] = readline().split(' ');\n }\n\n let map = new Array(10);\n for(let i = 0; i < n; i++){\n for(let j = 0; j < m; j++){\n map[pi(cols[i][j])] = new Array(2);\n map[pi(cols[i][j])][1] = j;\n }\n }\n\n for(let i = 0; i < m; i++){\n for(let j = 0; j < n; j++){\n map[pi(rows[i][j])][0] = j;\n }\n }\n\n let res = new Array(n);\n for(let i = 0; i < n; i++){\n res[i] = new Array(m);\n }\n\n for(let i = 0; i < n; i++){\n for(let j = 0; j < m; j++){\n let r = map[pi(cols[i][j])][0];\n let c = map[pi(cols[i][j])][1];\n res[r][c] = cols[i][j];\n }\n }\n\n for(let i = 0; i < n; i++){\n console.log(res[i].join(' '));\n }\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [rowLen, colLen] = readLine().split(\" \").map(Number);\n const [rowMap, colMap] = [new Map(), new Map()];\n const result = [...Array(rowLen).fill(0)].map((_) => Array(colLen).fill(0));\n for (let i = 0; i < rowLen; i++) {\n readLine()\n .split(\" \")\n .map((n, index) => {\n n = parseInt(n);\n colMap.set(n, index);\n });\n }\n for (let i = 0; i < colLen; i++) {\n readLine()\n .split(\" \")\n .map((n, index) => {\n n = parseInt(n);\n rowMap.set(n, index);\n const col = colMap.get(n);\n result[index][col] = n;\n });\n }\n\n for (let i = 0; i < rowLen; i++) {\n console.log(result[i].join(\" \"));\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = new Array(M);\n\t\t}\n\t\tvar check = new Array(N);\n\t\tvar check2 = new Array(M);\n\t\tvar map = {};\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tcheck[j] = nextIntArray();\n\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\tmap[check[j][k]] = k;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(var j = 0; j < M; j++){\n\t\t\ttmp = nextIntArray();\n\t\t\tvar L = map[tmp[0]];\n\t\t\tfor(var k = 0; k < N; k++){\n\t\t\t\tlist[k][L] = tmp[k];\n\t\t\t}\n\t\t}\n\t\tfor(var j = 0; j < N; j++){\n\t\t\toutput.push(myconv(list[j], 8));\n\t\t}\n\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;et.toString())).join(\"\\n\"):this.join(\" \")}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(747));let s=\"\",i=[],u=0,l=\"\";const a=\"local\"===process.argv[2],p=t=>{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols = a.transpose()\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.deepCopy().map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// h[i][j] = a[k][j]\n// }\n// k++\n// }\n// \n// io.puts(h.toString())\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;r[...t].sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),f=Array.numbersMatrix(t,e),p=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols: number[][] = []\n// \n// for (let j = 0; j < m; ++j) {\n// let s: number[] = []\n// for (let i = 0; i < n; ++i) {\n// s.push(a[i][j])\n// }\n// cols.push(s)\n// }\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.map((x) => [...x].sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// // io.debug(f)\n// // io.debug(cols[0])\n// // io.debug(cols[0][0])\n// // io.debug(f.indexOf(cols[0][0]))\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// // io.debug(indices)\n// \n// let h = Array.numbersMatrix(n, m)\n// \n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// io.debug(i + \" \" + j)\n// h[i][j] = a[k][j]\n// // io.debug(h)\n// }\n// k++\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// io.puts(h[i].join(\" \"))\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols = a.transpose()\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.deepCopy().map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// h[i][j] = a[k][j]\n// }\n// k++\n// }\n// \n// io.puts(h.toString())\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;et.toString())).join(\"\\n\"):this.join(\" \")}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(747));let s=\"\",i=[],u=0,l=\"\";const a=\"local\"===process.argv[2],p=t=>{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols = a.transpose()\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.deepCopy().map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// \n// let k = 0\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// h[i][j] = a[k][j]\n// }\n// k++\n// }\n// \n// io.puts(h.toString())\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),f=Array.numbersMatrix(t,e),p=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols: number[][] = []\n// \n// for (let j = 0; j < m; ++j) {\n// let s: number[] = []\n// for (let i = 0; i < n; ++i) {\n// s.push(a[i][j])\n// }\n// cols.push(s)\n// }\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// \n// let k = 0\n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// // io.debug(i + \" \" + j)\n// h[k][j] = a[i][j]\n// // io.debug(h)\n// }\n// k++\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// io.puts(h[i].join(\" \"))\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),f=Array.numbersMatrix(t,e),p=0;for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols: number[][] = []\n// \n// for (let j = 0; j < m; ++j) {\n// let s: number[] = []\n// for (let i = 0; i < n; ++i) {\n// s.push(a[i][j])\n// }\n// cols.push(s)\n// }\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// let h = Array.numbersMatrix(n, m)\n// \n// let k = 0\n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// // io.debug(i + \" \" + j)\n// h[i][j] = a[k][j]\n// // io.debug(h)\n// }\n// k++\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// io.puts(h[i].join(\" \"))\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return i[u++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function h(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.sortAsc().join(\"\"))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t)));for(let t of a){for(let n=0;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextNumbersMatrix(n)\n// \n// let cols: number[][] = []\n// \n// for (let j = 0; j < m; ++j) {\n// let s: number[] = []\n// for (let i = 0; i < n; ++i) {\n// s.push(a[i][j])\n// }\n// cols.push(s)\n// }\n// \n// let c = [...cols[0]].sortAsc().join(\"\")\n// let b = io.nextNumbersMatrix(m)\n// let bb = b.map((x) => x.sortAsc().join(\"\"))\n// \n// let f = b[bb.findIndex((x) => x == c)]\n// \n// let indices = cols[0].map((x) => f.indexOf(x))\n// \n// for (let i of indices) {\n// for (let j = 0; j < m; ++j) {\n// io.put(a[i][j] + \" \")\n// }\n// io.put(\"\\n\")\n// }\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "0eab9d2dd60d38f68d49f30cff918fce"} {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;\nvar suma = 0, sumb = 0;\nwhile (i < n && j < n){\n if (turna){\n turna = false;\n if (a[i] >= b[j]){\n suma += a[i];\n i++;\n } else if (a[i] < b[j]){\n j++;\n }\n } else {\n turna = true;\n if (b[j] >= a[i]){\n sumb += b[j];\n j++;\n } else if (b[j] < a[i]){\n i++;\n }\n }\n}\nif (i !== n){\n if (!turna) i++;\n while (i < n){\n suma += a[i];\n i+=2;\n }\n} else if (j !== n) {\n if (turna) j++;\n while (j < n){\n sumb += b[j];\n j+= 2;\n }\n}\nprint(suma - sumb);", "positive_code": [{"source_code": "// Gambling - https://codeforces.com/problemset/problem/1038/C\n\nconst main = async () => {\n let listLen = 0;\n const listA = [];\n const listB = [];\n \n const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n \n for await (const line of rl) {\n if (!listLen) {\n listLen = Number(line);\n } else {\n if (listA.length < listLen) {\n sortList(line.split(' ')).map((item)=> listA.push(Number(item)));\n } else {\n rl.close();\n sortList(line.split(' ')).map((item)=> listB.push(Number(item)));\n }\n }\n }\n \n runGame(listLen, listA, listB);\n };\n\n const sortList = (list) => list.sort((a, b) => a - b)\n \n const runGame = (listLen, listA, listB) => {\n\n\n let scoreA = 0;\n let scoreB = 0;\n\n for (let i = 0; i <= listLen * 2; i++) {\n // console.log({listA, scoreA, '':'', scoreB, listB})\n if (i % 2 === 0) {\n if (!listB.length || listA[listA.length - 1] > listB[listB.length - 1]) {\n scoreA += listA[listA.length - 1] || 0;\n listA.pop()\n } else {\n listB.pop()\n }\n } else {\n if (!listA.length || listB[listB.length - 1] > listA[listA.length - 1]) {\n scoreB += listB[listB.length - 1] || 0;\n listB.pop()\n } else {\n listA.pop()\n }\n }\n \n }\n\n console.log(scoreA - scoreB);\n };\n \n \n main();"}], "negative_code": [{"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;\nvar suma = 0, sumb = 0;\nwhile (i < n && j < n){\n if (turna){\n turna = false;\n if (a[i] > b[j]){\n suma += a[i];\n i++;\n } else if (a[i] < b[j]){\n j++;\n } else {\n i++;\n j++;\n }\n } else {\n turna = true;\n if (b[j] > a[i]){\n sumb += b[j];\n j++;\n } else if (b[j] < a[i]){\n i++;\n } else {\n i++;j++;\n }\n }\n}\nif (i !== n){\n while (i < n){\n suma += a[i];\n i+=2;\n }\n} else if (j !== n) {\n while (j < n){\n sumb += b[j];\n j+= 2;\n }\n}\nprint(suma - sumb);"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;\nvar suma = 0, sumb = 0;\nwhile (i < n && j < n){\n if (turna){\n turna = false;\n if (a[i] >= b[j]){\n suma += a[i];\n i++;\n } else if (a[i] < b[j]){\n j++;\n }\n } else {\n turna = true;\n if (b[j] >= a[i]){\n sumb += b[j];\n j++;\n } else if (b[j] < a[i]){\n i++;\n }\n }\n}\nif (i !== n){\n while (i < n){\n suma += a[i];\n i+=2;\n }\n} else if (j !== n) {\n while (j < n){\n sumb += b[j];\n j+= 2;\n }\n}\nprint(suma - sumb);"}], "src_uid": "d740f4ee1b18eeb74dfb253125c52762"} {"source_code": "var n = Number(readline());\n\nvar gears = readline().split(' ').map(Number);\nvar trueGears = [],\n res = 'NO';\n\nNumber.prototype.mod = function(n) {\n return ((this%n)+n)%n;\n};\n\nfor (var i = 0; i < n; i++) {\n trueGears.push(i);\n}\n\nfor (var j = 0; j < n; j++) {\n for (i = 0; i < gears.length; i++) {\n if ( i % 2 == 0 ) {\n gears[i]++;\n } else {\n gears[i]--;\n }\n\n gears[i] = gears[i].mod(n);\n }\n\n if ( arrayEqual(trueGears, gears) ) {\n res = 'YES';\n break;\n }\n}\n\nprint( res );\n\nfunction arrayEqual(arr1, arr2) {\n if ( arr1.length !== arr2.length ) {\n return false;\n }\n\n for (var i = 0; i < arr2.length; i++) {\n if ( arr2[i] !== arr1[i] ) {\n return false;\n }\n }\n\n return true;\n};\n\n", "positive_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , d , e ;\n res = false ;\n a = 0 ;\n b = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n c = this.arr[ i ] ;\n d = 0 ;\n if( b == 0 ) {\n while( true ) {\n if( c == a ) {\n break ;\n }\n d++ ;\n c = ( c + 1 ) % this.n ;\n }\n }\n else {\n while( true ) {\n if( c == a ) {\n break ;\n }\n d++ ;\n c = ( c - 1 + this.n ) % this.n ;\n }\n }\n this.brr[ i ] = d ;\n b = ! b ;\n a++ ;\n }\n a = 1 ;\n for( i = 1 ; i < this.n ; i++ ) {\n if( this.brr[ i ] != this.brr[ i - 1 ] ) {\n a = 0 ;\n break ;\n }\n }\n if( a == 1 ) {\n res = true ;\n }\n else {\n a = 0 ;\n b = 0 ;\n for( j = 0 ; j < 10000 ; j++ ) {\n e = 1 ;\n for( i = 0 ; i < this.n ; i++ ) {\n c = this.arr[ i ] ;\n if( b == 0 ) {\n this.arr[ i ] = ( this.arr[ i ] + 1 ) % this.n ;\n }\n else {\n this.arr[ i ] = ( this.arr[ i ] - 1 + this.n ) % this.n ;\n }\n if( this.arr[ i ] != i ) {\n e = 0 ;\n }\n b = ! b ;\n a++ ;\n }\n if( e == 1 ) {\n res = true ;\n break ;\n }\n }\n }\n if( res == true ) {\n print( 'Yes' ) ;\n }\n else {\n print( 'No' ) ;\n }\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , d , e ;\n res = false ;\n a = 0 ;\n b = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n c = this.arr[ i ] ;\n d = 0 ;\n if( b == 0 ) {\n while( true ) {\n if( c == a ) {\n break ;\n }\n d++ ;\n c = ( c + 1 ) % this.n ;\n }\n }\n else {\n while( true ) {\n if( c == a ) {\n break ;\n }\n d++ ;\n c = ( c - 1 + this.n ) % this.n ;\n }\n }\n this.brr[ i ] = d ;\n b = ! b ;\n a++ ;\n }\n a = 1 ;\n for( i = 1 ; i < this.n ; i++ ) {\n if( this.brr[ i ] != this.brr[ i - 1 ] ) {\n a = 0 ;\n break ;\n }\n }\n if( a == 1 ) {\n res = true ;\n }\n else {\n }\n if( res == true ) {\n print( 'Yes' ) ;\n }\n else {\n print( 'No' ) ;\n }\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "var n = parseInt(readline());\nvar actives = readline().split(' ').map(function(a){\n\treturn parseInt(a);\n});\n\nfunction is_finished() {\n\tfor (var i = 0; i < n; i++) {\n\t\tif (actives[i] != i) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction action() {\n\tfor (var i = 0; i < n; i++) {\n\t\tif (i % 2) {\n\t\t\tactives[i]--;\n\t\t} else {\n\t\t\tactives[i]++; \n\t\t}\n\t\tif (actives[i] < 0) {\n\t\t\tactives[i] = n-1;\n\t\t}\n\t\tactives[i] = actives[i] % n;\n\t}\n}\n\nvar finished = false;\n\nfor (var i = 0; i < n; i++) {\n\tif (is_finished()) {\n\t\tprint('Yes');\n\t\tfinished=true;\n\t\tbreak;\n\t}\n\taction();\n}\nif (!finished) {\n\tprint('No');\n}"}], "negative_code": [], "src_uid": "6c65ca365352380052b0c9d693e6d161"} {"source_code": "function split(v) {\n var pos = v.indexOf(' ');\n return [+v.substr(0, pos), +v.substr(pos + 1)]\n}\n\nvar fl = readline().split(' ').map(v=>+v);\nvar persCnt = fl[0];\nvar pairsCnt = fl[1];\n\nvar persons = [], scores = [], all1 = 0, all2 = 0;\nfor(var i = 0; i < persCnt; i++) {\n var rl = split(readline());\n persons.push([i, rl[0], rl[1], rl[1] - rl[0], 0]);\n \n all2 += rl[1]\n}\n\nfor(i = 0; i < pairsCnt; i++) {\n var pair = split(readline());\n var person1 = persons[pair[0] - 1];\n var person2 = persons[pair[1] - 1];\n var sum = person1[3] > person2[3] \n ? person1[1] + person2[2]\n : person1[2] + person2[1]\n\n person1[4] -= sum\n person2[4] -= sum\n}\n\nscores.length = persCnt;\n\npersons.sort((a, b) => a[3] > b[3] ? -1 : 1);\nfor(var i = 0; i < persCnt; i++) {\n var person = persons[i]\n all2-=person[2]\n scores[person[0]] = \n person[1] * (persCnt - i - 1) +\n person[2] * i \n + all2 + all1 \n + person[4]\n \n all1+=person[1]\n}\n\nprint(scores.join(' '));", "positive_code": [{"source_code": " 'use strict';\n\n const first_line = readline().split(' ').map(Number);\n const n = first_line[0];\n const m = first_line[1];\n\n const ans = new Array(n);\n\n const x = new Array(n);\n const y = new Array(n);\n const diff = new Array(n);\n for (let i = 0; i < n; i++) {\n const line = readline().split(' ').map(Number);\n x[i] = line[0];\n y[i] = line[1];\n\n diff[i] = [y[i] - x[i], i];\n }\n\n diff.sort(function(lhs, rhs) {return (lhs[0] !== rhs[0]) ? lhs[0] - rhs[0] : lhs[1] - rhs[1]});\n\n const prefsum = new Array(n + 1);\n prefsum[0] = 0;\n for (let i = 0; i < n; i++) {\n const id = diff[i][1];\n prefsum[i + 1] = prefsum[i] + y[id];\n }\n\n const suffsum = new Array(n + 1);\n suffsum[n] = 0;\n for (let i = n - 1; i >= 0; i--) {\n const id = diff[i][1];\n suffsum[i] = suffsum[i + 1] + x[id];\n }\n\n for (let i = 0; i < n; i++) {\n const id = diff[i][1];\n ans[id] = prefsum[i] + x[id] * i + suffsum[i + 1] + y[id] * (n - i - 1);\n }\n\n for (let i = 0; i < m; i++) {\n const line = readline().split(' ').map(Number);\n const v = line[0] - 1;\n const u = line[1] - 1;\n const score = Math.min(x[v] + y[u], x[u] + y[v]);\n ans[v] -= score;\n ans[u] -= score;\n }\n\n print(ans.join(' '));\n"}], "negative_code": [], "src_uid": "d0cb479bbe2fca382a439148af77e082"} {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n input.trim().split('\\n').slice(1).map((x) => parseInt(x)).forEach((n) => {\n console.log([...new Array(n)].map(() => 1).join(' '))\n })\n})\n\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = Array(len).fill(1);\n console.log(arr.join(\" \"));\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar s = new Array(N).fill(1);\n\t\toutput[i] = myconv(s, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// io.puts(\"1 \".repeat(n))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n3\n1\n2\n4\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n3\n1\n2\n4\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r sum += item)\n if (sum % arr.length === 0) {\n return true\n } else {\n return false\n }\n }\n \n function geter(arr) {\n var arr2 = []\n arr.map((item,index) => {\n if (index !== arr.length - 2) {\n arr2.push(item)\n }\n })\n var flag = checker(arr2)\n return flag\n }\n \n for (var i = 0; i < t; i++) {\n \n var n = +readline()\n var arr = []\n \n if (n % 2 === 0) {\n var num = 2\n for (j = 0; j < n; j++) {\n arr.push(num)\n num += 2\n var tempArr = arr\n var flag = geter(arr)\n if (!flag) {\n while (!flag) {\n tempArr = tempArr.filter((el,i) => i !== arr.length - 1)\n num += 1\n tempArr.push(num)\n flag = geter(tempArr)\n }\n arr = tempArr\n }\n }\n } else {\n var num = 1\n for (j = 0; j < n; j++) {\n arr.push(num)\n num += 2\n var tempArr = arr\n var flag = geter(arr)\n if (!flag) {\n while (!flag) {\n tempArr = tempArr.filter((el,i) => i !== arr.length - 1)\n num += 1\n tempArr.push(num)\n flag = geter(tempArr)\n }\n arr = tempArr\n }\n }\n }\n print(arr)\n }\n \n}())"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n if (l === 1) {\n var num = Math.floor(Math.random() * (100 - 1) + 1);\n \n if (num % 2 !== 0) {\n num++;\n }\n \n print(num.toString().replace(/\\,/g, ' '));\n } else {\n for (var j = 0; j < l; j++) {\n var num = Math.floor(Math.random() * (100 - 0) + 0);\n \n while (num % l !== 0) {\n num = Math.floor(Math.random() * (100 - 0) + 0);\n }\n \n res[j] = num;\n }\n \n print(res.toString().replace(/\\,/g, ' '));\n }\n}\n"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n if (l === 1) {\n var num = Math.floor(Math.random() * (100 - 1) + 1);\n \n if (num % 2 !== 0) {\n num++;\n }\n \n print(num.toString().replace(/\\,/g, ' '));\n } else {\n for (var j = 0; j < l; j++) {\n var num = Math.floor(Math.random() * (100 - 1) + 1);\n \n while (num % l !== 0) {\n num = Math.floor(Math.random() * (100 - 1) + 1);\n }\n \n res[j] = num;\n }\n \n print(res.toString().replace(/\\,/g, ' '));\n }\n}\n"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n if (l === 1) {\n var num = Math.floor(Math.random() * (100 - 0) + 0);\n \n if (num % 2 !== 0) {\n num++;\n }\n \n print(num.toString().replace(/\\,/g, ' '));\n } else {\n for (var j = 0; j < l; j++) {\n var num = Math.floor(Math.random() * (100 - 0) + 0);\n \n if (num % 2 === 0) {\n num++;\n }\n \n res[j] = num;\n }\n \n print(res.toString().replace(/\\,/g, ' '));\n }\n}\n"}], "src_uid": "da2ac80c2ad6abae676d60a506eb05fc"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input = \"\";\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n\tconst nonDecrease = (a, b) => a - b;\n\tconst [n, ...rest] = input.trim().split(\"\\n\");\n\tconst [left, right] = [rest\n\t\t.map(line => line.split(\" \").map(Number))]\n\t\t.map(x => [\n\t\t\tx.map(x => x[0]).sort(nonDecrease),\n\t\t\tx.map(x => x[1]).sort(nonDecrease)\n\t\t])[0];\n\tconsole.log(left.map((v, i) => Math.max(v, right[i])).reduce((a, b) => a + b) + Number(n));\n});", "positive_code": [{"source_code": "n = +readline();\nleft = []\nright = [];\nfor (i = 0;ia-b);\nright = right.sort((a,b)=>a-b);\nans = 0;\nfor (i = 0;i {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(arr) {\r\n const n = arr.shift()\r\n const pair = ['12', '23', '31']\r\n const sorted = arr.map((x, i) => [x, pair[i]])\r\n .sort((a, b) => a[0] - b[0])\r\n const [a, b, c] = sorted.map(x => x[0])\r\n const [sa, sb, sc] = sorted.map(x => x[1])\r\n const va = getv(sa, sb)\r\n const vb = getv(sa, sc)\r\n const vc = getv(sb, sc)\r\n// console.log(sa, sb, sc)\r\n// return\r\n if (c > a + b || (a + b - c) & 1) return 'NO'\r\n const share = (a + b - c) / 2\r\n// console.log('share', share)\r\n const edges = []\r\n let now = 3\r\n let lca = fill(va, share)\r\n if (share === a) {\r\n fixLast(va)\r\n lca = va\r\n }\r\n fill(lca, a - share)\r\n fixLast(vb)\r\n fill(lca, b - share)\r\n fixLast(vc)\r\n if (now <= n) {\r\n fill(va, n - now)\r\n } else {\r\n return 'NO'\r\n }\r\n function fill(u, d) {\r\n while (d--) {\r\n const v = ++now\r\n edges.push([u, v])\r\n u = v\r\n }\r\n return u\r\n }\r\n function fixLast(u) {\r\n edges[edges.length - 1][1] = u\r\n now--\r\n }\r\n return 'YES\\n' + edges.map(x => x.join(' ')).join('\\n')\r\n}\r\nfunction getv(sa, sb) {\r\n for (let x of [1,2,3]) {\r\n if (sa.indexOf(x) >= 0 && sb.indexOf(x) >= 0) return x\r\n }\r\n}\r\n", "positive_code": [{"source_code": "var n;\r\n var a;\r\n \r\n function logNodes(x, y) {\r\n print(x + ' ' + y);\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nd[0];\r\n a = [];\r\n a.push([nd[1], 1, 2]);\r\n a.push([nd[2], 2, 3]);\r\n a.push([nd[3], 1, 3]);\r\n a.sort((b, c) => c[0] - b[0]);\r\n \r\n var x, y ,z;\r\n x = a[0][0];\r\n y = a[1][0];\r\n z = a[2][0];\r\n var br = (y+z) - x;\r\n if (br & 1 || br < 0) {\r\n print('NO');\r\n continue;\r\n }\r\n br = br / 2;\r\n if (n < a[0][0] + 1 + br) {\r\n print('NO');\r\n continue;\r\n }\r\n print('YES');\r\n if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {\r\n var temp = a[0][1];\r\n a[0][1] = a[0][2];\r\n a[0][2] = temp;\r\n }\r\n var nodes = [1, 2, 3];\r\n var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];\r\n\r\n var brStart = brNode;\r\n var reserve = 4;\r\n for (var i = 0; i < br; i++) {\r\n logNodes(reserve, brStart);\r\n brStart = reserve;\r\n reserve++;\r\n }\r\n var lineNode = a[0][1];\r\n for (var i = 0; i < (y - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, brStart);\r\n lineNode = brStart;\r\n for (var i = 0; i < (z - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, a[0][2]);\r\n lineNode = a[0][2];\r\n while( reserve <= n ) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n }"}], "negative_code": [{"source_code": "var n;\r\n var a;\r\n \r\n function logNodes(x, y) {\r\n print(x + ' ' + y);\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nd[0];\r\n a = [];\r\n a.push([nd[1], 1, 2]);\r\n a.push([nd[2], 2, 3]);\r\n a.push([nd[3], 1, 3]);\r\n a.sort((b, c) => c[0] - b[0]);\r\n \r\n var x, y ,z;\r\n x = a[0][0];\r\n y = a[1][0];\r\n z = a[2][0];\r\n var br = (y+z) - x;\r\n if (br & 1 || br < 0) {\r\n print('NO');\r\n continue;\r\n }\r\n br = br / 2;\r\n if (n < a[0][0] + 1 + br) {\r\n print('NO');\r\n continue;\r\n }\r\n print('YES');\r\n if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {\r\n var temp = a[0][1];\r\n a[0][1] = a[0][2];\r\n a[0][2] = temp;\r\n }\r\n var nodes = [1, 2, 3];\r\n var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];\r\n\r\n var brStart = brNode;\r\n var reserve = 4;\r\n for (var i = 0; i < br; i++) {\r\n logNodes(reserve, brNode);\r\n brStart = reserve;\r\n reserve++;\r\n }\r\n var lineNode = a[0][1];\r\n for (var i = 0; i < (y - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, brStart);\r\n lineNode = brStart;\r\n for (var i = 0; i < (z - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, a[0][2]);\r\n lineNode = a[0][2];\r\n while( reserve <= n ) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n }"}, {"source_code": "var n;\r\n var a;\r\n \r\n function logNodes(x, y) {\r\n print(x + ' ' + y);\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nd[0];\r\n a = [];\r\n a.push([nd[1], 1, 2]);\r\n a.push([nd[2], 2, 3]);\r\n a.push([nd[3], 1, 3]);\r\n a.sort((b, c) => c[0] - b[0]);\r\n \r\n var x, y ,z;\r\n x = a[0][0];\r\n y = a[1][0];\r\n z = a[2][0];\r\n var br = (y+z) - x;\r\n if (br & 1 || br < 0) {\r\n print('NO');\r\n continue;\r\n }\r\n br = br / 2;\r\n if (n - 2 < (a - 1) + br) {\r\n print('NO');\r\n continue;\r\n }\r\n print('YES');\r\n if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {\r\n var temp = a[0][1];\r\n a[0][1] = a[0][2];\r\n a[0][2] = temp;\r\n }\r\n var nodes = [1, 2, 3];\r\n var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];\r\n\r\n var brStart = brNode;\r\n var reserve = 4;\r\n for (var i = 0; i < br; i++) {\r\n logNodes(reserve, brNode);\r\n brStart = reserve;\r\n reserve++;\r\n }\r\n var lineNode = a[0][1];\r\n for (var i = 0; i < (y - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, brStart);\r\n lineNode = brStart;\r\n for (var i = 0; i < (z - br - 1); i++) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n logNodes(lineNode, a[0][2]);\r\n lineNode = a[0][2];\r\n while( reserve <= n ) {\r\n logNodes(lineNode, reserve);\r\n lineNode = reserve;\r\n reserve++;\r\n }\r\n }"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const n = arr.shift()\n const pair = ['12', '23', '31']\n const sorted = arr.map((x, i) => [x, pair[i]])\n .sort((a, b) => a[0] - b[0])\n const [a, b, c] = sorted.map(x => x[0])\n const [sa, sb, sc] = sorted.map(x => x[1])\n const va = getv(sa, sb)\n const vb = getv(sa, sc)\n const vc = getv(sb, sc)\n// console.log(sa, sb, sc)\n// return\n if (c > a + b || (a + b - c) & 1) return 'NO'\n const share = (a + b - c) / 2\n// console.log('share', share)\n const edges = []\n let now = 3\n let lca = fill(va, share)\n if (share === a) {\n fixLast(va)\n lca = va\n }\n fill(lca, a - share)\n fixLast(vb)\n fill(lca, b - share)\n fixLast(vc)\n if (now < n) {\n fill(va, n - now)\n }\n function fill(u, d) {\n while (d--) {\n const v = ++now\n edges.push([u, v])\n u = v\n }\n return u\n }\n function fixLast(u) {\n edges[edges.length - 1][1] = u\n now--\n }\n return 'YES\\n' + edges.map(x => x.join(' ')).join('\\n')\n}\nfunction getv(sa, sb) {\n for (let x of [1,2,3]) {\n if (sa.indexOf(x) >= 0 && sb.indexOf(x) >= 0) return x\n }\n}\n"}], "src_uid": "4750029f0a5e802099a6dd4dff2974d5"} {"source_code": "function checkValue(value) {\n return value != 1;\n}\nfunction getNextIdx (n, restArgs) {\n var arr = [];\n arr[3000] = 0;\n var i;\n for (i=0;i { return parseInt(item); });\n tests.sort(sortNumber);\n /*console.log(\"*************\");\n tests.forEach(element => {\n rl.write(element + \", \");\n });\n console.log(\"************\");\n */\n var i = 0;\n for (i = 0; i < N; i++)\n if (i + 1 != tests[i]) break;\n\n\n\n console.log(i + 1);\n rl.close();\n }\n}\n)\n\nfunction sortNumber(a, b) {\n return a - b;\n }\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar N = -1;\n\nrl.on('line', function (input) {\n\n\n if (N == -1) {\n N = parseInt(input);\n }\n else {\n var tests = [];\n tests = input.split(' ').map(item => { return parseInt(item); });\n //tests.sort(sortNumber);\n tests.sort((a,b)=>{return a-b;});\n /*console.log(\"*************\");\n tests.forEach(element => {\n rl.write(element + \", \");\n });\n console.log(\"************\");\n */\n var i = 0;\n for (i = 0; i < N; i++)\n if (i + 1 != tests[i]) break;\n\n\n\n console.log(i + 1);\n rl.close();\n }\n}\n)\n/*\nfunction sortNumber(a, b) {\n return a - b;\n }*/\n\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar previous = tokenizeIntegers(readline());\n\tvar seen = new Array(3001);\n\tfor (var i = 0; i < n; ++i) {\n\t\tseen[previous[i]] = true;\n\t}\n\tfor (i = 1; seen[i]; ++i) {\n\t}\n\tprint(i);\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nconst N = readline()\nlet lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)\nif (lll[0] != 1) {\n print(1)\n} else {\n for (var i = 1; i < lll.length; i++) {\n if (lll[i] - lll[i - 1] != 1) break\n }\n print(i + 1)\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar N = -1;\n\nrl.on('line', function (input) {\n\n\n if (N == -1) {\n N = parseInt(input);\n }\n else {\n var tests = [];\n tests = input.split(' ').map(item => { return parseInt(item); });\n tests.sort();\n var i = 0;\n for (i = 0; i < N; i++)\n if (i + 1 != tests[i]) break;\n\n\n\n console.log(i + 1);\n rl.close();\n }\n}\n)\n\n\n\n"}, {"source_code": "function checkValue(value) {\n return value != 1;\n}\nfunction getNextIdx (n, restArgs) {\n var arr = [];\n var i;\n for (i=0;i parseInt(v)).sort((a, b) => a - b)\nfor (var i = 1; i < lll.length; i++) {\n if (lll[i] - lll[i - 1] != 1) break\n}\nprint(i + 1)\n"}], "src_uid": "5e449867d9fcecc84333b81eac9b5d92"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar w1 = nextInt();\r\n\t\tvar w2 = nextInt();\r\n\t\tvar b1 = N - w1;\r\n\t\tvar b2 = N - w2;\r\n\t\tvar w = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tif(w1 % 2 != w2 % 2){\r\n\t\t\tif(w1 > w2){\r\n\t\t\t\tw1--;\r\n\t\t\t}else{\r\n\t\t\t\tw2--;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(b1 % 2 != b2 % 2){\r\n\t\t\tif(b1 > b2){\r\n\t\t\t\tb1--;\r\n\t\t\t}else{\r\n\t\t\t\tb2--;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar L = w1 + w2;\r\n\t\tvar R = b1 + b2;\r\n\t\tif(L < w * 2 || R < b * 2){\r\n\t\t\tmyout(\"NO\");\r\n\t\t}else{\r\n\t\t\tmyout(\"YES\");\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const [n, k1, k2] = numArray(rl());\r\n const [w, b] = numArray(rl());\r\n solution(n, k1, k2, w, b);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, k1, k2, w, b) {\r\n // cl(n, k1, k2, w, b);\r\n const whiteArea = k1 + k2;\r\n const blackArea = 2 * n - whiteArea;\r\n\r\n // console.log(\"solution\", w, whiteArea, b, blackArea);\r\n if (w * 2 <= whiteArea && b * 2 <= blackArea) {\r\n cl(\"yes\");\r\n } else {\r\n cl(\"no\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst abs = Math.abs;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k1, k2, w, b) => {\r\n let cntw = mi(k1, k2) + (abs(k1 - k2) >> 1);\r\n let cntb = mi(n - k1, n - k2) + (abs((n - k1) - (n - k2)) >> 1);\r\n if (w <= cntw && b <= cntb) return pr('YES');\r\n pr('NO');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2], input[i + 1][0], input[i + 1][1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var a = function(a, b, c){\n if(a < b){\n var temp = a;\n a = b;\n b = temp;\n }\n a -= b;\n var a2 = a / 2;\n var b2 = c - b;\n if(a2 >= b2){\n return true;\n }else{\n return false;\n }\n};\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j].split(' ').map(Number);\n }else{\n var k = lines[j].split(' ').map(Number);\n var N = e[0];\n var k1 = e[1];\n var k2 = e[2];\n var w = k[0];\n var b = k[1];\n b1 = N - k1;\n b2 = N - k2;\n if(a(k1, k2, w) === true && a(b1, b2, b) === true){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k1, k2], [w, b]) {\r\n const wArea = k1 + k2, bArea = (2 * n) - (k1 + k2)\r\n let res = false\r\n if (k1 % 2 === k2 % 2) {\r\n if (wArea >= w * 2 && bArea >= b * 2) res = true\r\n } else {\r\n if (wArea - 1 >= w * 2 && bArea - 1 >= b * 2) res = true\r\n }\r\n res ? console.log('YES') : console.log('NO')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var [w, b] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n // if ((k1 + k2) % 2 !== 0) return console.log('NO')\r\n// console.log(w * 2 <= (k1 + k2), b * 2 <= (n - k1 + n - k2))\r\n if ((w * 2 <= (k1 + k2) )&& (b * 2 <= (n - k1 + n - k2))) return console.log('YES')\r\n console.log('NO')\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n\r\n });\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i n){\r\n return 'NO';\r\n }\r\n if(k1 < k2){\r\n var temp;\r\n temp = k1;\r\n k1=k2;\r\n k2 =temp;\r\n }\r\n var ws = k2;\r\n var bs = n-k1;\r\n\r\n if(ws >= w && bs>=b){\r\n return 'YES';\r\n }\r\n b = Math.max(b - bs, 0);\r\n w = Math.max(w - ws, 0);\r\n\r\n n = n - bs - ws;\r\n var rest = Math.floor(n/2);\r\n if(b <= rest && w<=rest){\r\n return 'YES'\r\n }\r\n return 'NO';\r\n \r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\"\").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const [n, k1, k2] = numArray(rl());\r\n const [w, b] = numArray(rl());\r\n solution(n, k1, k2, w, b);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, k1, k2, w, b) {\r\n const whiteArea = k1 + k2;\r\n const blackArea = 2 * n - whiteArea;\r\n\r\n // console.log(\"solution\", w, whiteArea, b, blackArea);\r\n if (w <= whiteArea && b <= blackArea) {\r\n cl(\"yes\");\r\n } else {\r\n cl(\"no\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k1, k2, w, b) => {\r\n // pr(n, k1, k2, w, b)\r\n let a = [];\r\n for (let i = 0; i < 2; i++) {\r\n let tmp = [];\r\n for (let j = 0; j < n; j++) {\r\n if (i == 0) {\r\n j < k1 ? tmp.push('w') : tmp.push('b');\r\n } else {\r\n j < k2 ? tmp.push('w') : tmp.push('b');\r\n }\r\n }\r\n a.push(tmp);\r\n }\r\n // pr(a);\r\n let cntw = cntb = 0\r\n for (let i = 0; i < 2; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (a[i][j] == 'w') {\r\n if (i - 1 >= 0) {\r\n if (a[i - 1][j] == 'w') {\r\n cntw++;\r\n continue;\r\n }\r\n }\r\n if (i + 1 < 2) {\r\n if (a[i + 1][j] == 'w') {\r\n cntw++;\r\n continue;\r\n }\r\n }\r\n if (j - 1 >= 0) {\r\n if (a[i][j - 1] == 'w') {\r\n cntw++;\r\n continue;\r\n }\r\n }\r\n if (j + 1 < n) {\r\n if (a[i][j + 1] == 'w') {\r\n cntw++;\r\n continue;\r\n }\r\n }\r\n } else {\r\n if (i - 1 >= 0) {\r\n if (a[i - 1][j] == 'b') {\r\n cntb++;\r\n continue;\r\n }\r\n }\r\n if (i + 1 < 2) {\r\n if (a[i + 1][j] == 'b') {\r\n cntb++;\r\n continue;\r\n }\r\n }\r\n if (j - 1 >= 0) {\r\n if (a[i][j - 1] == 'b') {\r\n cntb++;\r\n continue;\r\n }\r\n }\r\n if (j + 1 < n) {\r\n if (a[i][j + 1] == 'b') {\r\n cntb++;\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n // pr(w, cntw, b, cntb);\r\n if (w <= cntw && b <= cntb) return pr('YES');\r\n pr('NO');\r\n};\r\n\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2], input[i + 1][0], input[i + 1][1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "26354d2628f26eb2eff9432bd46400d5"} {"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tlet sum = 0;\n\tfor (let t=0; t < test; t++) {\n\t\tlet ans = true;\n\t\tlet n = parseInt(input[sum+t+1]);\n\t\tlet arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));\n\t\tlet arr2 = [];\n\t\tif (n == 1) {\n\t\t\tif ((arr1[0] < arr1[1])) {\n\t\t\t\tans = false;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let i = 1; i < n; i++) {\n\t\t\t\tarr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));\n\t\t\t\tif ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1]) || (arr2[0] - arr1[0] < arr2[1] - arr1[1])) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (arr1[0] === arr2[0] && arr2[1] > arr1[1]) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tarr1 = [...arr2];\n\t\t\t}\n\t\t}\n\t\t\n\t\tconsole.log(ans ? 'YES' : 'NO');\n\t\tsum += n;\n\t}\n});", "positive_code": [{"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, a) {\n if (a[0][0] < a[0][1]) return 'NO';\n for(let i = 1; i < n; ++i) {\n const x = a[i][0] - a[i - 1][0];\n const y = a[i][1] - a[i - 1][1];\n if (x < 0 || y < 0) return 'NO';\n if (x < y) return 'NO';\n }\n return 'YES';\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n = readLine()[0];\n let a = [];\n for(let i = 0; i < n; ++i) a.push(readLine());\n console.log(solve(n, a));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i, j;\n for (i = 0; i < cases; i++) {\n const n = readline();\n var terminate = false;\n var lastX = 0;\n var lastY = 0;\n for (j = 0; j < n; j++) {\n const line = readline();\n// console.log('x' +line+'\\n');\n var x = parseInt(line.split(\" \")[0]);\n var y = parseInt(line.split(\" \")[1]);\n// console.log(\"* \"+x+\" \"+y+\" \"+((!terminate) && ((y > x) || ((y-lastY) > (x-lastX))))+\"\\n\");\n if((!terminate) && ((x < lastX) || (y < lastY) || (y > x) || ((y-lastY) > (x-lastX)))) {\n process.stdout.write(\"NO\\n\");\n terminate = true;\n }\n\n lastX = x;\n lastY = y;\n }\n\n !terminate && process.stdout.write(\"YES\\n\");\n }\n}"}, {"source_code": "t = +readline();\nout = '';\nwhile (t-->0){\n n = +readline();\n attemps = 0;\n clears = 0;\n possible = true;\n while (n-->0){\n p = readline().split(' ').map(Number);\n if (!possible){\n continue;\n }\n if (p[0] < attemps || p[1] < clears || p[0] - attemps < p[1] - clears){\n possible = false;\n }\n attemps = p[0];\n clears = p[1];\n }\n out += possible?\"YES\\n\":\"NO\\n\";\n}\nprint(out);"}], "negative_code": [{"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tlet sum = 0;\n\tfor (let t=0; t < test; t++) {\n\t\tlet ans = true;\n\t\tlet n = parseInt(input[sum+t+1]);\n\t\tlet arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));\n\t\tlet arr2 = [];\n\t\tif (n == 1) {\n\t\t\tif ((arr1[0] < arr1[1])) {\n\t\t\t\tans = false;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let i = 1; i < n; i++) {\n\t\t\t\tarr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));\n\t\t\t\tif ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tarr1 = [...arr2];\n\t\t\t}\n\t\t}\n\t\t\n\t\tconsole.log(ans ? 'YES' : 'NO');\n\t\tsum += n;\n\t}\n});"}, {"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tlet sum = 0;\n\tfor (let t=0; t < test; t++) {\n\t\tlet ans = true;\n\t\tlet n = parseInt(input[sum+t+1]);\n\t\tlet arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));\n\t\tlet arr2 = [];\n\t\tif (n == 1) {\n\t\t\tif ((arr1[0] < arr1[1])) {\n\t\t\t\tans = false;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let i = 1; i < n; i++) {\n\t\t\t\tarr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));\n\t\t\t\tif ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1]) || (arr1[0] == arr2[0] && arr2[1] > arr1[0])) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tarr1 = [...arr2];\n\t\t\t}\n\t\t}\n\t\t\n\t\tconsole.log(ans ? 'YES' : 'NO');\n\t\tsum += n;\n\t}\n});"}, {"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tlet sum = 0;\n\tfor (let t=0; t < test; t++) {\n\t\tlet ans = true;\n\t\tlet n = parseInt(input[sum+t+1]);\n\t\tlet arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));\n\t\tlet arr2 = [];\n\t\tif (n == 1) {\n\t\t\tif ((arr1[0] < arr1[1])) {\n\t\t\t\tans = false;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let i = 1; i < n; i++) {\n\t\t\t\tarr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));\n\t\t\t\tif ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (arr1[0] === arr2[0] && arr2[1] > arr1[1]) {\n\t\t\t\t\tans = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tarr1 = [...arr2];\n\t\t\t}\n\t\t}\n\t\t\n\t\tconsole.log(ans ? 'YES' : 'NO');\n\t\tsum += n;\n\t}\n});"}, {"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tlet sum = 0;\n\tfor (let t=0; t < test; t++) {\n\t\tlet ans = true;\n\t\tlet n = parseInt(input[sum+t+1]);\n\t\tlet arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));\n\t\tlet arr2 = [];\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tarr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));\n\t\t\tif ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {\n\t\t\t\tans = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tarr1 = [...arr2];\n\t\t}\n\t\tconsole.log(ans ? 'YES' : 'NO');\n\t\tsum += n;\n\t}\n});"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, a) {\n for(let i = 1; i < n; ++i) {\n if (a[i][1] < a[i - 1][1]) return 'NO';\n if (a[i][0] < a[i - 1][0]) return 'NO';\n if (a[i][1] > a[i - 1][1] && a[i][0] === a[i - 1][0]) return 'NO';\n }\n return 'YES';\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n = readLine()[0];\n let a = [];\n for(let i = 0; i < n; ++i) a.push(readLine());\n console.log(solve(n, a));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i, j;\n for (i = 0; i < cases; i++) {\n const n = readline();\n var terminte = false;\n var lastX = 0;\n var lastY = 0;\n loop1: for (j = 0; j < n; j++) {\n const line = readline();\n\n var x = line.split(\" \")[0];\n var y = line.split(\" \")[1];\n\n if(!terminte && (y > x || (y-lastY) > (x-lastX))) {\n process.stdout.write(\"NO\\n\");\n terminte = true;\n }\n\n lastX = x;\n lastY = y;\n }\n\n terminte ? process.stdout.write(\"YES\\n\") : null;\n }\n}"}], "src_uid": "714834defd0390659f6ed5bc3024f613"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nfunction lsone(s) {\r\n return s & (-s);\r\n}\r\nclass FenwickTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.ft = af(n + 1).fill(0);\r\n }\r\n adjust(pos, v) {\r\n for (; pos < this.n; pos += lsone(pos)) {\r\n this.ft[pos] += v;\r\n }\r\n // printf(\"adjust(%d,%d) ft %j\\n\", pos, v, this.ft);\r\n }\r\n query(pos) {\r\n let rv = 0;\r\n for (; pos > 0; pos -= lsone(pos)) {\r\n rv += this.ft[pos];\r\n }\r\n return rv;\r\n }\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc--) {\r\n let n = nextInt();\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n const ft = new FenwickTree(n);\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n let prior = i;\r\n let left = ft.query(a[i] - 1);\r\n ans += prior - left;\r\n ft.adjust(a[i], 1);\r\n }\r\n printf(\"%d\\n\", ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __importDefault = (this && this.__importDefault) || function (mod) {\r\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst readline_1 = __importDefault(require(\"readline\"));\r\n(() => {\r\n let readBase = readline_1.default.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n });\r\n let buffer = [];\r\n let resolveList = [];\r\n readBase.on('line', data => {\r\n buffer.push(data);\r\n if (buffer.length <= resolveList.length) {\r\n resolveList[buffer.length - 1](data);\r\n }\r\n });\r\n let input = () => __awaiter(void 0, void 0, void 0, function* () {\r\n return new Promise(resolve => {\r\n resolveList.push(resolve);\r\n if (resolveList.length <= buffer.length) {\r\n resolve(buffer[resolveList.length - 1]);\r\n }\r\n });\r\n });\r\n main({ input }).then(() => {\r\n process.exit(0);\r\n });\r\n})();\r\nfunction main({ input }) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n let solve = () => __awaiter(this, void 0, void 0, function* () {\r\n let getMid = (l, r) => {\r\n return l + Math.floor((r - l) / 2);\r\n };\r\n let n = parseInt(yield input());\r\n let a = (yield input()).split(' ').map(v => parseInt(v));\r\n let tree = Array(n * 4 + 5).fill(0);\r\n let sonOfNode = (nod) => ({\r\n ls: nod * 2,\r\n rs: nod * 2 + 1,\r\n });\r\n let pushup = (nod) => {\r\n let { ls, rs } = sonOfNode(nod);\r\n tree[nod] = tree[ls] + tree[rs];\r\n };\r\n let build = (nod, l, r) => {\r\n if (l === r) {\r\n tree[nod] = 0;\r\n return;\r\n }\r\n let { ls, rs } = sonOfNode(nod);\r\n let mid = getMid(l, r);\r\n build(ls, l, mid);\r\n build(rs, mid + 1, r);\r\n pushup(nod);\r\n };\r\n let modify = (nod, l, r, pos, x) => {\r\n if (l === r) {\r\n tree[nod] += x;\r\n return;\r\n }\r\n let { ls, rs } = sonOfNode(nod);\r\n let mid = getMid(l, r);\r\n if (pos <= mid) {\r\n modify(ls, l, mid, pos, x);\r\n }\r\n else {\r\n modify(rs, mid + 1, r, pos, x);\r\n }\r\n pushup(nod);\r\n };\r\n let query = (nod, l, r, x, y) => {\r\n if (l === x && r === y) {\r\n return tree[nod];\r\n }\r\n let { ls, rs } = sonOfNode(nod);\r\n let mid = getMid(l, r);\r\n if (y <= mid) {\r\n return query(ls, l, mid, x, y);\r\n }\r\n else if (x > mid) {\r\n return query(rs, mid + 1, r, x, y);\r\n }\r\n else {\r\n let ans = query(ls, l, mid, x, mid);\r\n return ans + query(rs, mid + 1, r, mid + 1, y);\r\n }\r\n };\r\n build(1, 1, n);\r\n let ans = 0;\r\n a.forEach(x => {\r\n ans += query(1, 1, n, x, n);\r\n modify(1, 1, n, x, 1);\r\n });\r\n console.log(ans);\r\n });\r\n let T = parseInt(yield input());\r\n for (let i = 0; i < T; i++) {\r\n yield solve();\r\n }\r\n });\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __importDefault = (this && this.__importDefault) || function (mod) {\r\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst readline_1 = __importDefault(require(\"readline\"));\r\n(() => {\r\n let readBase = readline_1.default.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n });\r\n let buffer = [];\r\n let resolveList = [];\r\n readBase.on('line', data => {\r\n buffer.push(data);\r\n if (buffer.length <= resolveList.length) {\r\n resolveList[buffer.length - 1](data);\r\n }\r\n });\r\n let input = () => __awaiter(void 0, void 0, void 0, function* () {\r\n return new Promise(resolve => {\r\n resolveList.push(resolve);\r\n if (resolveList.length <= buffer.length) {\r\n resolve(buffer[resolveList.length - 1]);\r\n }\r\n });\r\n });\r\n main({ input }).then(() => {\r\n process.exit(0);\r\n });\r\n})();\r\nfunction main({ input }) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n let solve = () => __awaiter(this, void 0, void 0, function* () {\r\n let getMid = (l, r) => {\r\n return l + Math.floor((r - l) / 2);\r\n };\r\n class TreeArray {\r\n constructor(n) {\r\n this.n = n;\r\n this.arr = Array(n + 1).fill(0);\r\n }\r\n modify(pos, x) {\r\n for (let i = pos; i <= n; i += i & -i) {\r\n this.arr[i] += x;\r\n }\r\n }\r\n queryR(pos) {\r\n let ans = 0;\r\n for (let i = pos; i > 0; i -= i & -i) {\r\n ans += this.arr[i];\r\n }\r\n return ans;\r\n }\r\n query(posL, posR) {\r\n return this.queryR(posR) - this.queryR(posL - 1);\r\n }\r\n }\r\n let n = parseInt(yield input());\r\n let a = (yield input()).split(' ').map(v => parseInt(v));\r\n let treeArray = new TreeArray(n);\r\n let ans = 0;\r\n a.forEach(x => {\r\n ans += treeArray.query(x, n);\r\n treeArray.modify(x, 1);\r\n });\r\n console.log(ans);\r\n });\r\n let T = parseInt(yield input());\r\n for (let i = 0; i < T; i++) {\r\n yield solve();\r\n }\r\n });\r\n}\r\n"}, {"source_code": "// ../../lib/ts/BIT.ts\nvar BIT = class {\n constructor(n2 = 0, op, init) {\n this.n = n2;\n this.op = op;\n this.init = init;\n this.seg = new Array(n2 + 1).fill(init);\n }\n add(i, v) {\n i++;\n while (i <= this.n) {\n this.seg[i] = this.op(this.seg[i], v);\n i += i & -i;\n }\n }\n sumTo(i) {\n let res = this.init;\n while (i > 0) {\n res = this.op(res, this.seg[i]);\n i -= i & -i;\n }\n return res;\n }\n};\n\n// codeforces/1676H2/src/ts/solution1.ts\nvar lines = [];\nrequire(\"readline\").createInterface({\n input: process.stdin\n}).on(\"line\", (line) => lines.push(line));\nprocess.stdin.on(\"end\", () => {\n main(lines);\n});\nvar n;\nvar a;\nvar main = (lines2) => {\n let _ln = 0;\n const readString = () => lines2[_ln++];\n const readStrings = () => readString().split(\" \");\n const readNumber = () => Number(readString());\n const readNumbers = () => readStrings().map(Number);\n for (let t = readNumber(); t > 0; t--) {\n n = readNumber();\n a = readNumbers();\n output(solve());\n }\n};\nvar solve = () => {\n const bit = new BIT(n, (a2, b) => a2 + b, 0);\n let res = 0;\n for (const ai of a) {\n res += bit.sumTo(n) - bit.sumTo(ai - 1);\n bit.add(ai - 1, 1);\n }\n return res;\n};\nvar output = (res) => {\n console.log(res);\n};\n"}, {"source_code": "// ../../lib/ts/segmentTree.ts\nvar STNode = class {\n};\nvar SegmentTree = class {\n constructor(arr, op, e) {\n this.op = op;\n this.e = e;\n let n2 = 1;\n while (n2 * 2 < arr.length)\n n2 *= 2;\n this.tree = new Array(n2 * 4).fill(void 0).map((_) => new STNode());\n const build = (k, l, r) => {\n this.tree[k].l = l;\n this.tree[k].r = r;\n if (l === r) {\n this.tree[k].v = arr[l - 1];\n return;\n }\n const mid = l + r >> 1;\n const lc = k * 2, rc = lc + 1;\n build(lc, l, mid);\n build(rc, mid + 1, r);\n this.tree[k].v = this.op(this.tree[lc].v, this.tree[rc].v);\n };\n build(1, 1, arr.length);\n }\n update_(k, i, v) {\n if (this.tree[k].l === this.tree[k].r && this.tree[k].l === i) {\n this.tree[k].v = v;\n return;\n }\n const mid = this.tree[k].l + this.tree[k].r >> 1;\n const lc = k * 2, rc = lc + 1;\n if (i <= mid)\n this.update_(lc, i, v);\n else\n this.update_(rc, i, v);\n this.tree[k].v = this.op(this.tree[lc].v, this.tree[rc].v);\n }\n update(i, v) {\n this.update_(1, i + 1, v);\n }\n lazy(k, v) {\n this.tree[k].v = this.tree[k].lazy = v;\n }\n pushDown(k) {\n const lc = 2 * k, rc = lc + 1;\n this.lazy(lc, this.tree[k].lazy);\n this.lazy(rc, this.tree[k].lazy);\n this.tree[k].lazy = void 0;\n }\n updateRange_(k, l, r, v) {\n if (l <= this.tree[k].l && this.tree[k].r <= r)\n return this.lazy(k, v);\n if (this.tree[k].lazy !== void 0)\n this.pushDown(k);\n const mid = this.tree[k].l + this.tree[k].r >> 1;\n const lc = k * 2, rc = lc + 1;\n if (l <= mid)\n this.updateRange_(lc, l, r, v);\n if (mid < r)\n this.updateRange_(rc, l, r, v);\n this.tree[k].v = this.op(this.tree[lc].v, this.tree[rc].v);\n }\n updateRange(l, r, v) {\n this.updateRange_(1, l + 1, r + 1, v);\n }\n query_(k, l, r) {\n if (l <= this.tree[k].l && this.tree[k].r <= r)\n return this.tree[k].v;\n if (this.tree[k].lazy !== void 0)\n this.pushDown(k);\n let res = this.e;\n const mid = this.tree[k].l + this.tree[k].r >> 1;\n const lc = k * 2, rc = lc + 1;\n if (l <= mid)\n res = this.op(res, this.query_(lc, l, r));\n if (mid < r)\n res = this.op(res, this.query_(rc, l, r));\n return res;\n }\n query(l, r) {\n return this.query_(1, l + 1, r + 1);\n }\n};\n\n// codeforces/1676H2/src/ts/solution2.ts\nvar lines = [];\nrequire(\"readline\").createInterface({\n input: process.stdin\n}).on(\"line\", (line) => lines.push(line));\nprocess.stdin.on(\"end\", () => {\n main(lines);\n});\nvar n;\nvar a;\nvar main = (lines2) => {\n let _ln = 0;\n const readString = () => lines2[_ln++];\n const readStrings = () => readString().split(\" \");\n const readNumber = () => Number(readString());\n const readNumbers = () => readStrings().map(Number);\n for (let t = readNumber(); t > 0; t--) {\n n = readNumber();\n a = readNumbers();\n output(solve());\n }\n};\nvar solve = () => {\n const b = new Array(n).fill(0);\n const segTree = new SegmentTree(b, (a2, b2) => a2 + b2, 0);\n let res = 0;\n for (const ai of a) {\n res += segTree.query(ai - 1, n - 1);\n b[ai - 1]++;\n segTree.update(ai - 1, b[ai - 1]);\n }\n return res;\n};\nvar output = (res) => {\n console.log(res);\n};\n"}, {"source_code": "// ../../lib/ts/BIT.ts\nvar BIT = class {\n constructor(n2 = 0) {\n this.n = n2;\n this.seg = new Array(n2 + 1).fill(0);\n }\n add(i, v) {\n i++;\n while (i <= this.n) {\n this.seg[i] += v;\n i += i & -i;\n }\n }\n sumTo(i) {\n let res = 0;\n while (i > 0) {\n res += this.seg[i];\n i -= i & -i;\n }\n return res;\n }\n sum(a2, b) {\n return this.sumTo(b + 1) - this.sumTo(a2);\n }\n};\n\n// codeforces/1676H2/src/ts/solution1.ts\nvar lines = [];\nrequire(\"readline\").createInterface({\n input: process.stdin\n}).on(\"line\", (line) => lines.push(line));\nprocess.stdin.on(\"end\", () => {\n main(lines);\n});\nvar n;\nvar a;\nvar main = (lines2) => {\n let _ln = 0;\n const readString = () => lines2[_ln++];\n const readStrings = () => readString().split(\" \");\n const readNumber = () => Number(readString());\n const readNumbers = () => readStrings().map(Number);\n for (let t = readNumber(); t > 0; t--) {\n n = readNumber();\n a = readNumbers();\n output(solve());\n }\n};\nvar solve = () => {\n const bit = new BIT(n);\n let res = 0;\n for (const ai of a) {\n res += bit.sum(ai - 1, n - 1);\n bit.add(ai - 1, 1);\n }\n return res;\n};\nvar output = (res) => {\n console.log(res);\n};\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n const bst = new BinarySearchTree();\r\n for (let i = n - 1; i >= 0; i--) {\r\n const cur = a[i];\r\n res += bst.size() - bst.countGreaterThanEq(cur + 1);\r\n bst.insert(cur);\r\n }\r\n return res.toString();\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra().map(a=>a-1);\n // PROCESSING:\n let ans = 0;\n let cnt = {};\n let revA = new Array(n).fill(0);\n for (let i=0; i{\n let result = 0;\n for (; r >= 0; r = (r & (r+1)) - 1)\n result += t[r];\n return result;\n }\n let inc = (i, delta)=>{\n for (; i < n; i = (i | (i+1)))\n t[i] += delta;\n }\n for (let i=0; i=i){\n cntLeft++;\n deductLeft[A[i-1]]++;\n }\n cntRight -= deductRight[i];\n if (revA[i-1]>=i){\n cntRight++;\n deductRight[revA[i-1]]++;\n }\n ans += cntLeft*cntRight;\n // maintain cnt of all from left bigger than i\n // maintain all from right lower than i\n }\n return ans;\n};\n "}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nlet F\nfunction inc(idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n\nfunction solve(n, arr) {\n const sorted = arr.map((x, i) => ({ x, i: i + 1 }))\n .sort((a, b) => {\n if (a.x === b.x) {\n return b.i - a.i\n } else {\n return a.x - b.x\n }\n })\n // console.log(sorted)\n F = Array(n + 5).fill(0) // a little larger in case\n let ans = 0\n for (let i = sorted.length - 1; i >= 0; i--) {\n const it = sorted[i]\n ans += sum(it.i)\n //\n inc(it.i, 1)\n }\n return ans\n}\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar _loop_1 = function () {\r\n var n = readline().split(' ').map(function (v) { return +v; })[0];\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var len = n + 1;\r\n var t_1 = [];\r\n while (len) {\r\n t_1.push(Array(len + 1).fill(0));\r\n len >>= 1;\r\n }\r\n var sum = 0;\r\n var _loop_2 = function (i) {\r\n var v = a[i] + 1;\r\n var _loop_3 = function (l) {\r\n var f = v & 1 ? function () { sum += t_1[l][v]; } : function () { };\r\n v >>= 1;\r\n f();\r\n };\r\n for (var l = 0; l < t_1.length; l++) {\r\n _loop_3(l);\r\n }\r\n v = a[i];\r\n for (var l = 0; l < t_1.length; l++) {\r\n if (~v & 1) {\r\n t_1[l][v >> 1] += 1;\r\n }\r\n v >>= 1;\r\n }\r\n };\r\n for (var i = n; i--;) {\r\n _loop_2(i);\r\n }\r\n print(sum);\r\n};\r\nwhile (t--) {\r\n _loop_1();\r\n}\r\n"}], "negative_code": [{"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar _loop_1 = function () {\r\n var n = readline().split(' ').map(function (v) { return +v; })[0];\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var len = n + 1;\r\n var t_1 = [];\r\n while (len) {\r\n t_1.push(Array(len + 1).fill(0));\r\n len >>= 1;\r\n }\r\n var sum = 0;\r\n var _loop_2 = function (i) {\r\n var v = a[i] + 1;\r\n var _loop_3 = function (l) {\r\n var f = v & 1 ? function () { sum += t_1[l][v]; } : function () { };\r\n v >>= 1;\r\n f();\r\n };\r\n for (var l = 0; l < t_1.length; l++) {\r\n _loop_3(l);\r\n }\r\n v = a[i] + 1;\r\n for (var l = 0; l < t_1.length; l++) {\r\n if (v ^ 1) {\r\n t_1[l][v >> 1] += 1;\r\n }\r\n v >>= 1;\r\n }\r\n };\r\n for (var i = n; i--;) {\r\n _loop_2(i);\r\n }\r\n print(sum);\r\n};\r\nwhile (t--) {\r\n _loop_1();\r\n}\r\n"}], "src_uid": "35dccda260cfdaea651d1950df452e7a"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const cost = [0]\n const arr = [0]\n for (let i = 1; i <= n; ++i) {\n const ab = getInts()\n arr[i] = ab[0]\n cost[i] = ab[1]\n }\n\n print(solve(arr, cost))\n }\n}\n \nfunction solve (arr, cost) {\n const n = arr.length\n const dp = [[0, cost[0], cost[0] * 2]]\n\n for (let i = 1; i < n; ++i) {\n const cur = []\n for (let j = 0; j <= 2; ++j) {\n let best = Number.MAX_SAFE_INTEGER\n for (let k = 0; k <= 2; ++k) {\n if (arr[i - 1] + k !== arr[i] + j) {\n best = Math.min(best, dp[i - 1][k] + cost[i] * j)\n }\n }\n cur[j] = best\n }\n dp[i] = cur\n }\n\n return Math.min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n var t = getInt()\n while (t --> 0) {\n const n = getInt()\n const cost = [0]\n const arr = [0]\n for (var i = 1; i <= n; ++i) {\n const ab = getInts()\n arr[i] = ab[0]\n cost[i] = ab[1]\n }\n\n print(solve(arr, cost))\n }\n}\n\nfunction solve (arr, cost) {\n const n = arr.length\n const dp = [[0, cost[0], cost[0] * 2]]\n\n for (var i = 1; i < n; ++i) {\n const cur = []\n for (var j = 0; j <= 2; ++j) {\n var best = Number.MAX_SAFE_INTEGER\n for (var k = 0; k <= 2; ++k) {\n if (arr[i - 1] + k !== arr[i] + j) {\n best = Math.min(best, dp[i - 1][k] + cost[i] * j)\n }\n }\n cur[j] = best\n }\n dp[i] = cur\n }\n\n return Math.min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const cost = [0]\n const arr = [0]\n for (let i = 0; i < n; ++i) {\n const ab = getInts()\n arr.push(ab[0])\n cost.push(ab[1])\n }\n\n print(solve(arr, cost))\n }\n}\n\nfunction solve (arr, cost) {\n const n = arr.length\n const dp = [[0, 0]]\n\n for (let i = 1; i < n; ++i) {\n dp.push([0, 0])\n const changeCurrent = calc(i, arr, cost)\n\n if (arr[i] !== arr[i - 1]) {\n dp[i][0] = Math.min(dp[i - 1][0], dp[i - 1][1])\n }\n else {\n dp[i][0] = dp[i - 1][1]\n }\n dp[i][1] = Math.min(dp[i - 1][0] + changeCurrent, dp[i - 1][1] + changeCurrent)\n }\n\n return Math.min(dp[n - 1][0], dp[n - 1][1])\n}\n\nfunction calc (i, arr, cost) {\n let times = 1\n while (true) {\n const val = arr[i] + times\n if (val !== arr[i + 1] && val !== arr[i - 1]) break\n times ++\n }\n\n return times * cost[i]\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const cost = [0]\n const arr = [0]\n for (let i = 0; i < n; ++i) {\n const ab = getInts()\n arr.push(ab[0])\n cost.push(ab[1])\n }\n\n print(solve(arr, cost))\n }\n}\n\nfunction solve (arr, cost) {\n const n = arr.length\n const dp = [[0, 0]]\n for (let i = 1; i < n; ++i) {\n dp.push([0, 0])\n if (arr[i] === arr[i - 1]) {\n dp[i][0] = dp[i - 1][1]\n dp[i][1] = dp[i - 1][0] + cost[i]\n } else {\n dp[i][0] = Math.min(dp[i - 1][0], calc(i - 1, dp[i - 1][1], arr, cost))\n dp[i][1] = dp[i - 1][0] + cost[i]\n }\n }\n\n return Math.min(dp[n - 1][0], dp[n - 1][1])\n}\n\nfunction calc (i, cur, arr, cost) {\n if (arr[i] + 1 === arr[i + 1]) {\n cur += cost[i]\n }\n return cur\n}"}], "src_uid": "3e18c9566a43504ff464306900b92855"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet cola;\nlet cans;\nlet n;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n cola = d.split(' ').map(Number).reduce((a, b) => a + b, 0);\n return;\n }\n\n cans = d.split(' ').map(Number);\n cans.sort((a, b) => b - a);\n\n c++;\n});\n\nrl.on('close', () => {\n if (n === 2) {\n console.log('YES');\n return;\n }\n\n const [a, b] = cans;\n\n if (a + b >= cola) {\n console.log('YES');\n }\n else {\n console.log(\"NO\");\n }\n});\n", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n const remain2 = arr.shift().split(' ')\n const capacity2 = arr.shift().split(' ')\n var remain = []\n var capacity = []\n var sum = 0\n for(let i = 0; i < n; i++) {\n remain.push(parseInt(remain2[i]))\n capacity.push(parseInt(capacity2[i]))\n }\n sum = remain.reduce((a, b) => a + b)\n\n capacity = capacity.sort((a, b) => b - a)\n // console.log(capacity)\n\n if(capacity[0] + capacity[1] >= sum) console.log('YES')\n else console.log('NO')\n})"}, {"source_code": "var n = parseInt(readline());\nvar sum = 0, max1 = 0, max2 = 0;\nvar array1 = readline().split(' ');\nvar array2 = readline().split(' ');\nfor (var i = 0; i < n; i++) {\n\tarray2[i]= parseInt(array2[i]);\n\tarray1[i]= parseInt(array1[i]);\n}\nfor (var i = 0; i < n; i++) {\n\tsum += array1[i];\n\tif (array2[i] > max1) {\n\t\tmax2 = max1;\n\t\tmax1 = array2[i];\n\t} else if (array2[i] > max2) {\n\t\tmax2 = array2[i];\n\t}\n}\nif (sum > max1 + max2) {\n\tprint('NO');\n} else {\n\tprint('YES');\n}"}, {"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\nfunction cmp(a, b) {\n return b - a;\n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort(cmp).slice(0, 2).reduce(add, 0);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\nfunction cmp(a, b) {\n return a - b;\n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort(cmp).slice(-2).reduce(add, 0);\n// print(b);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = toInt(readline());\nvar sum = 0;\nvar max1 = 0;\nvar max2 = 0;\nvar ar = readline().split(' ').map(toInt);\nvar br = readline().split(' ').map(toInt);\n\nfor (var i = 0; i < n; i++) {\n\tsum += ar[i];\n\tif (br[i] > max1) {\n\t\tmax2 = max1;\n\t\tmax1 = br[i];\n\t} else if (br[i] > max2) {\n\t\tmax2 = br[i];\n\t}\n}\n\nif (sum > max1 + max2) {\n\tprint('NO');\n} else {\n\tprint('YES');\n}"}, {"source_code": "var n = parseInt(readline(), 10)\n a = readline().split(' ').map(el => parseInt(el, 10)),\n b = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a);\n \nprint((a.reduce((a,b) => a+b) <= b[0]+b[1]) ? 'YES' : 'NO');"}, {"source_code": "n = +readline();\nvolume = readline();\nbanks = readline();\nvol = 0;\n\narrV = volume.split(\" \");\narrV.forEach(function(item, i, arr){\n vol = vol + +item;\n})\n\narrB = banks.split(\" \");\n\narrB.sort(compareNumeric);\n\nfunction compareNumeric(a, b) {\n return b - a;\n}\n\nplace = +arrB[0] + +arrB[1];\nif (place >= vol){\n write(\"YES\");\n} else {\n write(\"NO\");\n}"}], "negative_code": [{"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort().slice(-2).reduce(add, 0);\n// print(b);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\nfunction cmp(a, b) {\n return a - b;\n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort(cmp).slice(-2, 0).reduce(add, 0);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort().slice(-2).reduce(add, 0);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "n = +readline();\nfunction add(a, b) { \n return a + b; \n}\nfunction cmp(a, b) {\n return b - a;\n}\na = readline().split(\" \").map(Number).reduce(add, 0);\nb = readline().split(\" \").map(Number).sort(cmp).slice(2).reduce(add, 0);\nprint(b >= a ? \"YES\" : \"NO\");"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = toInt(readline());\nvar sum = 0;\nvar max1 = 0;\nvar max2 = 0;\nvar ar = readline().split(' ').map(toInt);\nvar br = readline().split(' ').map(toInt);\n\nfor (var i = 0; i < n; i++) {\n\tsum += ar[i];\n\tif (br[i] > max1) {\n\t\tmax2 = max1;\n\t\tmax1 = br[i];\n\t}\n}\n\nif (sum > max1 + max2) {\n\tprint('NO');\n} else {\n\tprint('YES');\n}"}], "src_uid": "88390110e4955c521867864a6f3042a0"} {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\n// Write your logic in main();\n// let t = readline().split(' ').map(x => parseInt(x));\nconst main = () => {\n let t = parseInt(readline());\n while (t--) {\n let n = parseInt(readline());\n let a = readline().split(' ').map(x => parseInt(x));\n a.sort((a, b) => b - a);\n print(a.join(' '));\n }\n};\n", "positive_code": [{"source_code": "// https://codeforces.com/contest/1312/problem/B\n\nexports.solveProblem = (lineList) => {\n const caseList = [];\n for (let i = 2; i < lineList.length; i += 2) {\n caseList.push(\n lineList[i]\n .split(' ')\n .map(\n v => parseInt(v.trim())\n )\n );\n }\n\n const result = [];\n for (let aCase of caseList) {\n // --------------------------------------------\n const n = aCase.length;\n aCase = aCase.sort((a, b) => a > b ? -1 : a < b ? 1 : 0);\n result.push(aCase.join(' '));\n // --------------------------------------------\n }\n\n return result.join('\\n');\n};\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n for(let i = 0; i < t; i++)\n {\n let n = parseInt(lines[i * 2 + 1]);\n let a = lines[i * 2 + 2].split(\" \").map(function (x) {\n return parseInt(x);\n });\n /*\n console.log('a: ' + a.join());\n console.log('a.sort ' + a.sort().join());\n console.log('a[0] + a[1] = ' + (a[0] + a[1]));\n\n */\n answer += a.sort((x,y)=>x - y).reverse().join(' ') + '\\n';\n }\n console.log(answer);\n});"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j x).sort((a, b) => b-a)\n console.log(sorted.join(' '))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nfunction main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (v) { return v.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var _a = __read(lines.shift(), 1), t = _a[0];\n while (t > 0) {\n var _b = __read(lines.shift(), 1), n = _b[0];\n var as = lines.shift();\n // const as = Array.from({length: 100}).map(_ => Math.ceil(Math.random() * 100));\n console.log(as.sort(function (a, b) { return b - a; }).join(\" \"));\n t--;\n }\n}\nfunction test(as) {\n for (var i = 0; i < as.length; i++) {\n for (var j = i + 1; j < as.length; j++) {\n if (j - as[j] === i - as[i]) {\n return false;\n }\n }\n }\n return true;\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "function merge (arrA, arrB) {\n var merged = [];\n var j = 0;\n var k = 0;\n\n while (merged.length !== (arrA.length + arrB.length)) {\n if (arrB[k] === undefined || arrA[j] >= arrB[k]) {\n merged.push(arrA[j]);\n j++;\n } else if (arrA[j] === undefined || arrA[j] < arrB[k]) {\n merged.push(arrB[k]);\n k++;\n }\n }\n\n return merged;\n}\n\n\nfunction mergeSort (array) {\n var result = array.map(num => [num]);\n\n while (result.length > 1) {\n var oddNumbered = result.length % 2 !== 0;\n var temp = [];\n\n for (var i = 0; i < result.length; i += 2) {\n var a = result[i];\n var b = result[i + 1];\n\n if (oddNumbered && i === (result.length - 3)) {\n b = merge(b, result[i + 2]);\n i++;\n }\n\n temp.push(merge(a, b));\n }\n\n result = temp;\n }\n return result[0];\n}\n\nfunction processItem() {\n var count = readline();\n var items = readline().split(' ').map(function(i) { return +i; });\n \n print(mergeSort(items).join(' '));\n}\n\nfunction processItems() {\n var itemsCount = +readline();\n var items = [];\n\n for (var i = 0; i < itemsCount; ++i) {\n processItem();\n }\n\n return items;\n}\n\nprocessItems();"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n //good list?\n list.sort(function(a,b){\n return b - a;\n });\n output[i] = myconv(list,8);\n }\n myout(myconv(output,9));\n}"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var len = readline();\n var arr = readNumArray();\n\n print(arr.sort((a, b) => b - a).join(\" \"));\n }\n}\n\nmain()"}, {"source_code": "//var input = readline();\n\nvar T = parseInt(readline());\nfor (var i = 0; i parseInt(x));\n ar.sort((a, b) => b - a);\n\n print(ar.join(' '));\n}\n"}, {"source_code": "//var input = readline();\nvar T = parseInt(readline());\n\nfor (var i = 0; i < T; i++) {\n var n = parseInt(readline()); \n var ar = readline().split(' ').map(x => parseInt(x));\n print(ar.sort((a, b) => b - a).join(' '));\n}\n"}, {"source_code": "var t=readline();\nwhile(t--)\n{\n\tvar n=readline();\n\tvar arr = readline().split(\" \").map(x=> parseInt(x));\n\tvar ans=arr.sort((x,y) => x-y).reverse().join(' ');\n\tprint(ans);\n}"}], "negative_code": [{"source_code": "var t=readline();\nwhile(t--)\n{\n\tvar n=readline();\n\tvar arr = readline().split(\" \").map(x=> parseInt(x));\n\tvar ans=arr.sort().reverse().join(' ');\n\tprint(ans);\n}"}, {"source_code": "// https://codeforces.com/contest/1312/problem/B\n\nexports.solveProblem = (lineList) => {\n const caseList = [];\n for (let i = 2; i < lineList.length; i += 2) {\n caseList.push(\n lineList[i].split(' ').map(v => parseInt(v.trim()))\n );\n }\n\n const result = [];\n for (let aCase of caseList) {\n const permu = [];\n const size = aCase.length;\n \n for (let i = 0; i < size; i++) {\n const val = aCase[i];\n permu.push([]);\n for (var j = 0; j < size; j++) {\n permu[i][j] = j - val;\n }\n }\n\n const sol = [];\n const diff = [];\n const used = new Map();\n for(let j = 0; j < size; j++) {\n const val = aCase[j];\n let min = Number.MAX_VALUE;\n for (let i = 0; i < size; i++) {\n const iVal = permu[i][j];\n if (!used.has(iVal) && iVal < min) {\n min = iVal;\n }\n }\n used.set(min);\n sol[j] = val;\n diff[j] = min;\n }\n\n result.push(sol);\n }\n\n return result.join('\\n');\n};\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}, {"source_code": "// https://codeforces.com/contest/1312/problem/B\n\nexports.solveProblem = (lineList) => {\n const caseList = [];\n for (let i = 2; i < lineList.length; i += 2) {\n caseList.push(\n lineList[i].split(' ').map(v => parseInt(v.trim()))\n );\n }\n\n const result = [];\n for (let aCase of caseList) {\n // --------------------------------------------\n const n = aCase.length;\n aCase = aCase.sort((a, b) => a < b);\n result.push(aCase.join(' '));\n // --------------------------------------------\n }\n\n return result.join('\\n');\n};\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}, {"source_code": "// https://codeforces.com/contest/1312/problem/B\n\nexports.solveProblem = (lineList) => {\n const caseList = [];\n for (let i = 2; i < lineList.length; i += 2) {\n caseList.push(\n lineList[i].split(' ').map(v => parseInt(v.trim()))\n );\n }\n\n const result = [];\n for (let aCase of caseList) {\n const permu = [];\n const size = aCase.length;\n \n for (let i = 0; i < size; i++) {\n const val = aCase[i];\n permu.push([]);\n for (var j = 0; j < size; j++) {\n permu[i][j] = j - val;\n }\n }\n\n const sol = [];\n const diff = [];\n const used = new Map();\n for(let j = 0; j < size; j++) {\n const val = aCase[j];\n let min = Number.MAX_VALUE;\n for (let i = 0; i < size; i++) {\n const iVal = permu[i][j];\n if (!used.has(iVal) && iVal < min) {\n min = iVal;\n }\n }\n used.set(min);\n sol[j] = val;\n diff[j] = min;\n }\n\n result.push(sol.join(' '));\n }\n\n return result.join('\\n');\n};\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n for(let i = 0; i < t; i++)\n {\n let n = parseInt(lines[i * 2 + 1]);\n let a = lines[i * 2 + 2].split(\" \").map(function (x) {\n return parseInt(x);\n });\n a = a.sort().reverse();\n answer += a.join(' ') + '\\n';\n }\n\n\n\n\n\n console.log(answer);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n for(let i = 0; i < t; i++)\n {\n let n = parseInt(lines[i * 2 + 1]);\n let a = lines[i * 2 + 2].split(\" \").map(function (x) {\n return parseInt(x);\n });\n answer += a.sort().reverse().join(' ') + '\\n';\n }\n\n\n\n\n\n console.log(answer);\n});"}, {"source_code": "var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nfunction main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (v) { return v.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var _a = __read(lines.shift(), 1), t = _a[0];\n while (t > 0) {\n var _b = __read(lines.shift(), 1), n = _b[0];\n var as = lines.shift();\n // const as = Array.from({length: 100}).map(_ => Math.ceil(Math.random() * 100));\n console.log(test(as.sort(function (a, b) { return b - a; })));\n t--;\n }\n}\nfunction test(as) {\n for (var i = 0; i < as.length; i++) {\n for (var j = i + 1; j < as.length; j++) {\n if (j - as[j] === i - as[i]) {\n return false;\n }\n }\n }\n return true;\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}], "src_uid": "1d89df4153d70087d212b711852eba5f"} {"source_code": "var t = parseInt(readline());\r\nwhile(t--)\r\n{\r\n\tvar ar = readline().split(' ').map(x => +x);\r\n\tvar n = ar[0];\r\n\tvar k = ar[1];\r\n\tif(n>k)\r\n\t{\r\n\t\tk = n + (k-n%k)%k;\r\n\t}\r\n\tvar ans = k/n;\r\n\tans = Math.ceil(ans);\r\n\tprint(ans);\r\n}", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline(), 10);\r\n\r\n for (let i = 0; i < t; i += 1) {\r\n const a = readline().split(' ').map(num => parseInt(num, 10));\r\n const n = a[0];\r\n let k = a[1];\r\n\r\n if (n > k) {\r\n const div = Math.ceil(n / k);\r\n k *= div;\r\n }\r\n\r\n console.log(Math.ceil(k / n));\r\n }\r\n}\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n"}, {"source_code": "function solve(len, ...params) {\n for (let i = 0; i < params.length; i++) {\n let arr = params[i].split(\" \");\n let n = parseInt(arr[0]);\n let k = parseInt(arr[1]);\n if (n === 1) {\n console.log(k);\n continue;\n }\n if (k === 0) {\n console.log(0);\n continue;\n }\n if (k === 1) {\n console.log(1);\n continue;\n }\n let res = k;\n let p = 0;\n let malti = parseInt(n / k);\n while (res < n) {\n res = k * malti;\n malti += 1;\n }\n p = parseInt(res / n);\n if (res % n === 0) {\n console.log(p);\n } else {\n console.log(p + 1);\n }\n }\n }\nlet text = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", (t) => {\n if (t === \"\\r\\n\" || t === \"\\n\") {\n process.stdin.emit(\"end\");\n } else {\n text += t;\n }\n});\nprocess.stdin.on(\"end\", () => {\n const input = text.trim().replace(/\\r/g, \"\").split(\"\\n\");\n solve(...input);\n process.exit();\n});\n\n\t \t \t\t\t\t\t\t \t\t \t\t \t\t \t\t\t"}, {"source_code": "function solve(n, k) {\n let ans;\n if (k % n === 0) {\n ans = k / n;\n } else {\n if (n > k) {\n ans = n % k === 0 ? 1 : 2\n } else {\n let factor = Math.floor(k / n);\n while (true) {\n const quotient = Math.floor((n * factor) / k);\n factor++;\n const nextQuotient = Math.floor((factor * n) / k);\n if (nextQuotient !== quotient) {\n ans = factor;\n break;\n }\n }\n }\n }\n console.log(ans);\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input\n .slice(1)\n .map(item => item.split(' ').map(n => parseInt(n)));\n const len = dataArr.length;\n\n for (let i = 0; i < len; i++) {\n solve(...dataArr[i]);\n }\n process.exit();\n});\n\n\t\t \t\t\t\t\t \t \t \t\t\t \t\t \t \t \t\t"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, b] = readLine().split(' ').map(Number);\n\t\tif (a > b) {\n\t\t\tconst div = Math.ceil(a / b);\n\t\t\tb = b * div;\n\t\t}\n\t\tconsole.log(Math.ceil(b / a));\n\t}\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === k || k === 1) console.log(1);\r\n else if (n === 1) console.log(k);\r\n else {\r\n if (n > k) {\r\n if (n % k === 0) k = n;\r\n else k = n + (k - (n % k));\r\n }\r\n let i = Math.floor(k / n);\r\n let j = Math.floor(k / n) + (k % n);\r\n if (j === i) console.log(i);\r\n else console.log(i + 1);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getNumberList = line => line.split(' ').map(val => Number(val))\n\nconst calculate = (n, k) => {\n let index = Math.ceil(n / k)\n\n const b = Math.ceil((k * index) / n)\n\n return b\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet n, k\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n ;[n, k] = getNumberList(line)\n\n answer.push(calculate(n, k))\n\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n index++\n }\n})\n// console.log(calculate(6, 5, [1, 2, 3, 3, 2, 1]))\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let line = readline().split(' ')\n let n = line[0]\n let k = line[1]\n // let ans = ''\n // ------------------\n let startingDigit = 0\n let cF = Math.ceil(n/k)\n // startingDigit == 0 ? maxDigit = 1 : maxDigit = startingDigit\n // let arrayCounter = 0\n let total = cF * k\n let maxDigit = Math.ceil(total / n)\n // console.log('total = ', total)\n\n // while (total % k != 0) {\n // total++\n // // console.log('arrayCounter = ', arrayCounter)\n // if (arrayCounter == 0)\n // maxDigit++\n // arrayCounter = (++arrayCounter) % n\n // // console.log('arrayCounter After = ', (arrayCounter) % n)\n // }\n console.log(maxDigit)\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n if (k < n) {\r\n k = k * Math.ceil(n / k);\r\n }\r\n let res = Math.ceil(k / n);\r\n console.log(res);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n if (k < n) {\r\n k = k * Math.ceil(n / k);\r\n }\r\n let res = Math.ceil(k / n);\r\n console.log(res);\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar sum = Math.ceil(N / K) * K;\r\n\t\tvar L = Math.floor(sum / N);\r\n\t\tvar R = sum % N;\r\n\t\tif(R > 0){\r\n\t\t\tL++;\r\n\t\t}\r\n\t\tmyout(L);\r\n\t}\r\n}"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [n , k] = readLine().split(' ').map(Number);\r\n\r\n console.log(a(n , k));\r\n\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, k){\r\n /*\r\n You should create an array of n positive integers a1,a2,\u2026,an such that the sum (a1+a2+\u22ef+an) is divisible by k and maximum element in a is minimum possible.\r\n\r\n What is the minimum possible maximum element in a?\r\n */\r\n return Math.floor((Math.floor((n + k -1)/k)*k + (n - 1))/n);\r\n}\r\n\r\nmodule.exports = a;\r\n"}, {"source_code": " T=+readline();\r\nwhile(T--){\r\n var n,k,ans=0;\r\n var nk =readline().split(' ').map(x=>+x);\r\n n=nk[0];\r\n k=nk[1];\r\n\r\n if(n%k===0){\r\n ans=1;\r\n }\r\n \r\n else if(k%n===0){\r\n ans =k/n;\r\n }\r\n \r\n else if(n>k){\r\n ans =2;\r\n }\r\n \r\n else {\r\n ans = parseInt(k/n)+1;\r\n }\r\n \r\n print(ans);\r\n} \r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n\r\n var int = Math.floor(n + k - 1 / k)\r\n // console.log(Math.floor((k * int + n - 1) / n))\r\n\r\n console.log(Math.ceil(Math.ceil(n/k)*k/n))\r\n // console.log(n, k)\r\n // if (n < k) {\r\n // } else {\r\n // console.log(Math.ceil(n/k))\r\n // }\r\n // console.log(answer)\r\n // console.log(sum2)\r\n\r\n })\r\n\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n\r\n if (n < k) {\r\n console.log(Math.ceil(k/n))\r\n } else {\r\n console.log(Math.ceil(n/k))\r\n }\r\n // console.log(answer)\r\n // console.log(sum2)\r\n\r\n })\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var odd1 = n % 2\r\n var odd2 = k % 2\r\n if (k === 1) return console.log(1)\r\n if (n === 1) return console.log(k)\r\n if (n > k && odd1 === odd2 || k === 1) return console.log(1)\r\n if (n > k && odd1 !== odd2) return console.log(2)\r\n console.log(Math.floor(k / n) + (k % n === 0 ? 0 : 1))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var odd1 = n % 2\r\n var odd2 = k % 2\r\n if(k === 1) return console.log(1)\r\n if(n === 1) return console.log(k)\r\n if(n > k && odd1 === odd2 || k === 1) return console.log(1)\r\n if(n > k && odd1 !== odd2) return console.log(2)\r\n console.log(Math.floor(k/n) +(odd1 === odd2 ? 0 : 1))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var odd1 = n % 2\r\n var odd2 = k % 2\r\n if(n > k && odd1 === odd2 || k === 1) return console.log(1)\r\n if(n > k && odd1 !== odd2) return console.log(2)\r\n console.log(Math.floor(k/n) +(odd1 === odd2 ? 0 : 1))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var odd1 = n % 2\r\n var odd2 = k % 2\r\n if(n > k && odd1 !== odd2) return console.log(2)\r\n if(n > k && odd1 === odd2) return console.log(1)\r\n console.log(Math.floor(k/n) +(odd1 === odd2 ? 0 : 1))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var odd1 = n % 2\r\n var odd2 = k % 2\r\n if(n > k && odd1 !== odd2) return console.log(2)\r\n if(n > k && odd1 === odd2) return console.log(1)\r\n console.log(Math.floor(k/n) +(k % n === 0 ? 0 : 1))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline(), 10);\r\n\r\n for (let i = 0; i < t; i += 1) {\r\n const a = readline().split(' ').map(num => parseInt(num, 10));\r\n const n = a[0];\r\n let k = a[1];\r\n\r\n if (n <= k) {\r\n console.log(Math.ceil(k / n));\r\n } else {\r\n while (k < n) {\r\n k *= 2;\r\n }\r\n\r\n console.log(Math.ceil(k / n));\r\n }\r\n }\r\n}\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline(), 10);\r\n\r\n for (let i = 0; i < t; i += 1) {\r\n const a = readline().split(' ').map(num => parseInt(num, 10));\r\n const n = a[0];\r\n const k = a[1];\r\n\r\n if (n >= k) {\r\n console.log(Math.ceil(n / k));\r\n } else {\r\n console.log(Math.ceil(k / n));\r\n }\r\n }\r\n}\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n"}, {"source_code": "function solve(n, k) {\n let ans;\n if (k % n === 0) {\n ans = k / n;\n } else {\n let factor = 1;\n while (true) {\n const quotient = Math.floor((n * factor) / k);\n const nextQuotient = Math.floor((factor + 1) * n);\n if (nextQuotient !== quotient) {\n ans = factor + 1;\n break;\n }\n }\n }\n console.log(ans);\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input\n .slice(1)\n .map(item => item.split(' ').map(n => parseInt(n)));\n const len = dataArr.length;\n\n for (let i = 0; i < len; i++) {\n solve(...dataArr[i]);\n }\n process.exit();\n});\n\n\t \t\t\t \t\t \t \t\t \t \t\t\t\t \t\t \t \t"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, b] = readLine().split(' ').map(Number);\n\t\tif (a > b) {\n\t\t\tconst div = Math.ceil(a / b);\n\t\t\tconsole.log(div);\n\t\t} else {\n\t\t\tconsole.log(`${Math.floor(b / a) + (b % a)}`);\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst [a, b] = readLine().split(' ').map(Number);\n\t\tconst min = Math.min(a, b);\n\t\tconst max = Math.max(a, b);\n\t\tconsole.log(`${Math.floor(max / min) + (max % min)}`);\n\t}\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === k || k === 1) console.log(1);\r\n else if (n === 1) console.log(k);\r\n else {\r\n if (n > k) k = n + (k - (n % k));\r\n let i = Math.floor(k / n);\r\n let j = Math.floor(k / n) + (k % n);\r\n if (j === i) console.log(i);\r\n else console.log(i + 1);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": " T=+readline();\r\nwhile(T--){\r\n var n,k,ans=0;\r\n var nk =readline().split(' ').map(x=>+x);\r\n n=nk[0];\r\n k=nk[1];\r\n\r\n if(n%k===0){\r\n ans=1;\r\n }\r\n \r\n else if(k%n===0){\r\n ans =k/n;\r\n }\r\n \r\n else if(n>k){\r\n ans =parseInt(n/k)+1 ;\r\n }\r\n \r\n else {\r\n ans = parseInt(k/n)+1;\r\n }\r\n \r\n print(ans);\r\n} \r\n"}], "src_uid": "a28b84c9d1a54e322ab2d54bd5ab45c8"} {"source_code": "\"use strict\";\n\nvar q = +readline()\n\nwhile (q--) {\n var n = +readline();\n var A = readline().split(' ').map(value => +value);\n var M = {};\n\n for (var i = 0; i < A.length; ++i) {\n var value = A[i];\n M[value] = (M[value] || 0) + 1;\n }\n\n var R = {};\n for (var key in M) {\n if (M.hasOwnProperty(key)) {\n var value = M[key];\n R[value] = (R[value] || 0) + 1;\n }\n }\n \n var L = Object.keys(R).map(value => +value).sort(function(a, b){return b - a});\n var result = 0;\n var lastMax = L[0];\n loop:for (var i = 0; i < L.length; ++i) {\n if (lastMax > L[i]) {\n lastMax = L[i];\n }\n var count = +R[L[i]];\n\n while (count--) {\n result += lastMax;\n lastMax--;\n if (lastMax === 0) {\n break loop;\n }\n }\n }\n \n write(result, '\\n');\n}", "positive_code": [{"source_code": "var interationsCount = parseInt(readline());\nfor (var i = 0; i < interationsCount; i++) {\n readline();\n var candies = readline().split(\" \").map(x => parseInt(x));\n\n var groupedCandies = groupByCount(candies);\n\n var numberOfCandies = 0;\n var maxCandies = groupedCandies[0][1];\n for (j = 0; j < groupedCandies.length - 1; j++) {\n if (maxCandies <= 0) {\n break;\n }\n\n numberOfCandies += maxCandies;\n maxCandies = Math.min(maxCandies - 1, groupedCandies[j + 1][1]);\n }\n \n numberOfCandies += maxCandies;\n\n print(numberOfCandies);\n}\n\nfunction groupByCount(candies) {\n var map = new Map();\n for (var j = 0; j < candies.length; j++) {\n var currentTypeCount = map.get(candies[j]);\n if (!currentTypeCount) {\n map.set(candies[j], 1);\n } else {\n map.set(candies[j], currentTypeCount + 1)\n }\n }\n\n return Array.from(map).sort((a, b) => {\n return b[1] - a[1];\n });\n}"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var q = read.number();\n var res = '';\n while (q) {\n q--;\n\n var n = read.number();\n var a = read.arrNumber(' ');\n var t = {};\n a.forEach(i => {\n if(t[i]) {\n t[i]++;\n }\n else {\n t[i] = 1;\n }\n });\n\n var unic = {};\n for(var type in t) {\n if(unic[t[type]]) {\n unic[t[type]]++;\n }\n else {\n unic[t[type]] = 1;\n }\n }\n\n var f = Object.keys(unic).sort((a,b) => b - a);\n\n var count = 0;\n var max = +f[0];\n\n f.forEach(key => {\n if(max === 0) {\n return;\n }\n if(max > key) {\n max = +key;\n }\n while(unic[key]) {\n if(max === 0) {\n break;\n }\n unic[key]--;\n count += max;\n max--;\n }\n });\n res += count + '\\n';\n }\n print(res);\n}());\n"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var q = read.number();\n var res = '';\n while (q) {\n q--;\n\n var n = read.number();\n var a = read.arrNumber(' ');\n var t = {};\n a.forEach(i => {\n if(t[i]) {\n t[i]++;\n }\n else {\n t[i] = 1;\n }\n });\n\n var unic = {};\n for(var type in t) {\n if(unic[t[type]]) {\n unic[t[type]]++;\n }\n else {\n unic[t[type]] = 1;\n }\n }\n\n var f = Object.keys(unic).sort((a,b) => b - a);\n\n var count = 0;\n var max = +f[0];\n\n f.forEach(key => {\n if(max === 0) {\n return;\n }\n if(max > key) {\n max = +key;\n }\n while(unic[key]) {\n unic[key]--;\n count += max;\n max--;\n }\n });\n\n res += count + '\\n';\n\n }\n print(res);\n\n}());\n"}, {"source_code": "\nvar interationsCount = parseInt(readline());\nfor (var i = 0; i < interationsCount; i++) {\n var candiesCount = parseInt(readline());\n var candies = readline().split(\" \").map(x => parseInt(x));\n\n var groupedCandies = groupByCount(candies);\n var maxNumberOfTypesInPresent = Math.min(groupedCandies.length, groupedCandies[0][1]);\n\n var numberOfCandies = 0;\n var previousNumber = -1;\n for (j = 0; j < maxNumberOfTypesInPresent; j++) {\n var currentTypeCandiesMax = groupedCandies[j][1];\n numberOfCandies += groupedCandies[j][1];\n\n if (previousNumber != -1) {\n if (previousNumber === currentTypeCandiesMax) {\n numberOfCandies -= j;\n } \n }\n\n previousNumber = currentTypeCandiesMax;\n }\n\n print(numberOfCandies);\n}\n\nfunction groupByCount(candies) {\n var map = new Map();\n for (var j = 0; j < candies.length; j++) {\n var currentTypeCount = map.get(candies[j]);\n if (!currentTypeCount) {\n map.set(candies[j], 1);\n } else {\n map.set(candies[j], currentTypeCount + 1)\n } \n }\n\n return Array.from(map).sort((a, b) => {\n return b[1] - a[1];\n });\n}"}, {"source_code": "var interationsCount = parseInt(readline());\nfor (var i = 0; i < interationsCount; i++) {\n var candiesCount = parseInt(readline());\n var candies = readline().split(\" \").map(x => parseInt(x));\n\n var groupedCandies = groupByCount(candies);\n var maxNumberOfTypesInPresent = Math.min(groupedCandies.length, groupedCandies[0][1]);\n\n var numberOfCandies = 0;\n var maxCandies = groupedCandies[0][1];\n for (j = 0; j < maxNumberOfTypesInPresent - 1; j++) {\n numberOfCandies += maxCandies;\n maxCandies = Math.min(maxCandies - 1, groupedCandies[j+1][1]);\n }\n numberOfCandies += maxCandies;\n\n print(numberOfCandies);\n}\n\nfunction groupByCount(candies) {\n var map = new Map();\n for (var j = 0; j < candies.length; j++) {\n var currentTypeCount = map.get(candies[j]);\n if (!currentTypeCount) {\n map.set(candies[j], 1);\n } else {\n map.set(candies[j], currentTypeCount + 1)\n } \n }\n\n return Array.from(map).sort((a, b) => {\n return b[1] - a[1];\n });\n}"}], "src_uid": "a00d831da539c69d571d9720fd94eee1"} {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet[a,b] = inputReader.readNumberArray();\n\tlet count = 0,x1=0,x2=0,x3=0;\n\tlet arr = inputReader.readNumberArray();\n\tlet res= [];\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumberArray,\n\t}\n}", "positive_code": [{"source_code": "var isNodeJS = false;\n// isNodeJS = !isNodeJS;\nvar doWork = (readline, print) => {\nvar readInts = () => {\n return readline().split(\" \").map(function(x) { return parseInt(x); });\n};\n/////////////////////////////////////////////////////////////// BEGIN\n\nvar nums = readInts();\nvar n = nums[0];\nvar m = nums[1];\n\nvar a = readInts();\nvar b = new Array(n).fill(0);\nvar result = 0;\na.forEach(c => {\n --c;\n b[c]++;\n var allFilled = true;\n b.forEach(v => {\n if (v == 0) allFilled = false;\n });\n if (allFilled) {\n ++result;\n for (var i = 0; i < n; ++i) {\n b[i]--;\n }\n }\n});\n\nprint(result + \"\\n\");\n\n/////////////////////////////////////////////////////////////// END OF CODE\n};\n\nif (isNodeJS) {\n var stdin = process.stdin;\n var stdout = process.stdout;\n var lines, currentLine = 0;\n stdin.resume();\n stdin.once('data', function(data) {\n data = data.toString().trim();\n lines = data.split(\"\\n\");\n var readline = () => {\n return lines[currentLine++];\n };\n doWork(readline, stdout.write.bind(stdout));\n });\n} else {\n doWork(readline, print);\n}\n"}, {"source_code": "// You are given a following process.\n\n// There is a platform with n columns. 1\u2009\u00d7\u20091 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.\n\n// When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.\n\n// You task is to calculate the amount of points you will receive.\n// Input\n\n// The first line of input contain 2 integer numbers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091000) \u2014 the length of the platform and the number of the squares.\n\n// The next line contain m integer numbers c1,\u2009c2,\u2009...,\u2009cm (1\u2009\u2264\u2009ci\u2009\u2264\u2009n) \u2014 column in which i-th square will appear.\n// Output\n\n// Print one integer \u2014 the amount of points you will receive.\n\n\nvar input1 = readline();\nvar input2 = readline();\n\ninput1Arr = input1.split(' ');\nsquareArray = input2.split(' ');\n\nvar nColumn = input1Arr[0];\nvar totalSquare = squareArray[1];\n\nvar countN = [];\nvar count = 0;\n\nfor (var i = 1; i <= nColumn; i++) {\n count = 0;\n for (var j = 0; j < squareArray.length; j++) {\n if (squareArray[j] == i) {\n count += 1;\n }\n }\n countN.push(count);\n}\n\nvar min = countN.reduce(function(current, acc) {\n return ( current < acc ? current : acc);\n});\n\nprint(min);"}, {"source_code": "function main() {\n var n = Number(readline().split(' ')[0]);\n var squares = readline()\n .split(' ')\n .map(l => Number(l));\n var stacked = new Array(n).fill(0);\n\n for (var i = 0; i < squares.length; i++) {\n stacked[squares[i] - 1] += 1;\n }\n\n print(Math.min(...stacked));\n}\n\nmain();\n"}, {"source_code": "var g = readline().split(\" \");\nvar k = readline().split(\" \");\nvar min = 0;\nvar arr = [];\nfor(i=1;i<=Number(g[0]);i++){\n arr[i] = 0;\n}\n\nfor(i=0;i arr[b])\n min = arr[b];\n }\n}\nprint(min);"}], "negative_code": [], "src_uid": "c249103153c5006e9b37bf15a51fe261"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n,m,k,indicator=0,temp=[],dict={};\nrl.on('line', (input) => {\n if (indicator==0){\n temp = input.split(' ').map(item=>parseInt(item));// \"5 7 8\" => |\"5\"|\"7\"|\"8\"| => |5|7|8|\n n = temp[0], m = temp[1], k = temp[2]; \n indicator++; \n } else {\n temp = input.split(' ').map(item=>parseInt(item));\n let row=temp[0], viability = temp[1];\n if(row in dict && dict[row]>viability || !(row in dict))\n dict[row]=viability; \n } \n }).on('close',function(){\n let _sum = Object.values(dict).reduce((x,y)=>{\n return x+y;\n });\n console.log(_sum>k ? k : _sum);\n });", "positive_code": [{"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\nlet N = lll[0]\nlet M = lll[1]\nlet K = lll[2]\n\nlet c = 0\nlet rs = []\n\nwhile (lll = readline()) {\n lll = lll.split(' ').map(v => parseInt(v))\n let r = lll[0]\n let l = lll[1]\n if (!rs[r]) rs[r] = []\n rs[r].push(l)\n}\n\nfor (let i = 1; i < rs.length; i++) {\n c += rs[i].reduce((r, v) => Math.min(r, v), Infinity)\n}\n\n\nprint(Math.min(c, K))"}], "negative_code": [], "src_uid": "65eb0f3ab35c4d95c1cbd39fc7a4227b"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => a - b);\r\n let narr = [],\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n narr.push(arr[i]);\r\n sum += arr[i];\r\n }\r\n if (sum === arr[n] || sum === arr[n + 1]) console.log(narr.join(\" \"));\r\n else {\r\n let flag = true,\r\n s1 = sum;\r\n for (let i = n - 1; i >= 0; i--) {\r\n s1 = sum + arr[n];\r\n s1 -= narr[i];\r\n if (s1 === arr[n + 1]) {\r\n narr[i] = arr[n];\r\n console.log(narr.join(\" \"));\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) console.log(-1);\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\r\n\r\nvar n = num[0];\r\nfor (var index = 0; index < n; index++) {\r\n var m = readline().split(\" \").map((x) => parseInt(x));\r\n var numbers = readline().split(\" \").map((x) => parseInt(x));\r\n\r\n\r\n // for (var j = 1; j < numbers.length; j++) {\r\n // if (max < numbers[j]) {\r\n // max = numbers[j];\r\n // }\r\n // }\r\n numbers.sort((a, b) => a - b);\r\n var max = numbers[numbers.length - 1];\r\n // write(max + ' max \\n'); \r\n for (var j = 0; j < numbers.length - 1; j++) {\r\n max -= numbers[j]; \r\n // write(max + ' max \\n'); \r\n }\r\n\r\n var result = [];\r\n\r\n var finded = max * -1;\r\n var findedIndex = numbers.indexOf(finded);\r\n if (findedIndex != -1 && findedIndex != numbers.length - 1) {\r\n // write(findedIndex + ' findedIndex \\n'); \r\n numbers.splice(findedIndex, 1);\r\n numbers.splice(-1, 1);\r\n result = numbers;\r\n } else {\r\n max = numbers[numbers.length - 2];\r\n for (var j = 0; j < numbers.length - 2; j++) {\r\n // write(max + ' max \\n');\r\n max -= numbers[j]; \r\n }\r\n if (max == 0) {\r\n numbers.splice(-2, 2);\r\n result = numbers; \r\n } else {\r\n result = [-1];\r\n }\r\n\r\n }\r\n\r\n write(result.join(' ') + '\\n'); \r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n var ans = [];\r\n\r\n var iMax1 = parseInt(arr[0]) >= parseInt(arr[1]) ? 0 : 1;\r\n var iMax2 = parseInt(arr[0]) >= parseInt(arr[1]) ? 1 : 0;\r\n\r\n for (var i = 2; i < n + 2; i++) {\r\n if (parseInt(arr[i]) > parseInt(arr[iMax1])) {\r\n iMax2 = iMax1;\r\n iMax1 = i;\r\n } else if (parseInt(arr[i]) > parseInt(arr[iMax2])) {\r\n iMax2 = i;\r\n }\r\n }\r\n\r\n var arrSum = arr.reduce((sum, item) => sum += parseInt(item), 0);\r\n\r\n var testMax = iMax => {\r\n for (var i = 0; i < n + 2; i++) {\r\n if (i !== iMax && arrSum - arr[i] - arr[iMax] === parseInt(arr[iMax])) {\r\n for (var j = 0; j < n + 2; j ++) {\r\n if (j !== i && j !== iMax) {\r\n ans.push(arr[j]);\r\n }\r\n }\r\n print(ans.join(' '));\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (!testMax(iMax1)) {\r\n if (!testMax(iMax2)) {\r\n print('-1');\r\n }\r\n }\r\n}"}, {"source_code": "function solution(n,array) {\r\n var pointer = 0;\r\n var result = null;\r\n var noResult = false;\r\n var sortedArray = array.sort((a, b) => a - b);\r\n\r\n const firstTotal = [...sortedArray]\r\n .slice(0, n)\r\n .reduce((total, currentValue) => total + currentValue);\r\n \r\n if (firstTotal === sortedArray[n] || firstTotal === sortedArray[n + 1]) {\r\n return [...sortedArray].slice(0, n).join(' ');\r\n } else if (firstTotal > sortedArray[n] && firstTotal > sortedArray[n + 1]) {\r\n return -1;\r\n } else {\r\n const secondTotal = firstTotal + sortedArray[n];\r\n var i=0;\r\n \r\n while(i <= n-1 && ((secondTotal - sortedArray[i]) !== sortedArray[n + 1])){\r\n i++;\r\n }\r\n \r\n if(i===n){\r\n return -1;\r\n }\r\n return [...sortedArray].slice(0, n+1).filter((item,index)=> index !== i).join(' ');\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nvar iteration = parseInt(readline());\r\nfor(var i=0; i parseInt(x))\r\n )\r\n );\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet b = rna();\r\n\r\n\t\tlet have = new Map();\r\n\t\tlet sm = 0;\r\n\t\tfor (x of b) {\r\n\t\t\tsm += x;\r\n\t\t\thave.set(x, 1 + (have.has(x) ? have.get(x) : 0));\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; !ans && i < n + 2; i++) {\r\n\t\t\tconst x = sm - 2 * b[i];\r\n\t\t\tif (have.has(x)) {\r\n\t\t\t\tif (x == b[i] && have.get(x) < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tans = b.slice();\r\n\t\t\t\tans.splice(ans.indexOf(b[i]), 1);\r\n\t\t\t\tans.splice(ans.indexOf(x), 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n })\r\n n = n + 2\r\n var sum = 0n\r\n var object = {}\r\n for (let j = 0; j < n; j++) {\r\n sum += a[j]\r\n if (!object[a[j]]) object[a[j]] = 0\r\n object[a[j]]++\r\n }\r\n var ans = []\r\n var minus1 = false\r\n var minus2 = false\r\n for (let j = 0; j < n; j++) {\r\n var number = sum - a[j]\r\n if (number / 2n === a[j] && object[number / 2n] === 1) continue\r\n if (number % 2n === 0n && object[number / 2n]) {\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === a[j] && !minus1) {\r\n minus1 = true\r\n continue\r\n }\r\n if (a[i] === number / 2n && !minus2) {\r\n minus2 = true\r\n continue\r\n }\r\n ans.push(a[i])\r\n }\r\n console.log(ans.join(' '))\r\n return\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet b;\r\nfunction solve() {\r\n b.sort((x, y) => x - y);\r\n let mx = b[b.length - 1];\r\n let sum = 0;\r\n for (let i = 0; i < b.length; i++) {\r\n sum += b[i];\r\n }\r\n for (let i = 0; i + 1 < b.length; i++) {\r\n const rem = sum - b[i];\r\n if (rem % 2 != 0) {\r\n continue;\r\n }\r\n if (mx * 2 == rem) {\r\n const t = b[b.length - 2];\r\n b[b.length - 2] = b[i];\r\n b[i] = t;\r\n return true;\r\n }\r\n }\r\n let x = b[b.length - 1];\r\n mx = b[b.length - 2];\r\n if (mx * 2 + x == sum) {\r\n return true;\r\n }\r\n return false;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n b = af(n + 2);\r\n for (let i = 0; i < n + 2; i++) {\r\n b[i] = nextInt();\r\n }\r\n if (solve()) {\r\n for (let i = 0; i < n; i++) {\r\n printf(\"%d \", b[i]);\r\n }\r\n printf(\"\\n\");\r\n }\r\n else {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\r\n\r\nvar n = num[0];\r\nfor (var index = 0; index < n; index++) {\r\n var m = readline().split(\" \").map((x) => parseInt(x));\r\n var numbers = readline().split(\" \").map((x) => parseInt(x));\r\n\r\n\r\n // for (var j = 1; j < numbers.length; j++) {\r\n // if (max < numbers[j]) {\r\n // max = numbers[j];\r\n // }\r\n // }\r\n numbers.sort((a, b) => a - b);\r\n var max = numbers[numbers.length - 1];\r\n // write(max + ' max \\n'); \r\n for (var j = 0; j < numbers.length - 1; j++) {\r\n max -= numbers[j]; \r\n // write(max + ' max \\n'); \r\n }\r\n\r\n var result = [];\r\n\r\n var finded = max * -1;\r\n var findedIndex = numbers.indexOf(finded);\r\n if (findedIndex != -1 && findedIndex != numbers.length - 1) {\r\n // write(findedIndex + ' findedIndex \\n'); \r\n numbers.splice(findedIndex, 1);\r\n numbers.splice(-1, 1);\r\n result = numbers;\r\n } else {\r\n max = numbers[numbers.length - 2];\r\n for (var j = 0; j < numbers.length - 1; j++) {\r\n // write(max + ' max \\n');\r\n max -= numbers[j]; \r\n }\r\n if (max == 0) {\r\n numbers.splice(-2, 2);\r\n result = numbers; \r\n } else {\r\n result = [-1];\r\n }\r\n\r\n }\r\n\r\n write(result.join(' ') + '\\n'); \r\n \r\n}\r\n"}, {"source_code": "var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\r\n\r\nvar n = num[0];\r\nfor (var index = 0; index < n; index++) {\r\n var m = readline().split(\" \").map((x) => parseInt(x));\r\n var numbers = readline().split(\" \").map((x) => parseInt(x));\r\n\r\n\r\n // for (var j = 1; j < numbers.length; j++) {\r\n // if (max < numbers[j]) {\r\n // max = numbers[j];\r\n // }\r\n // }\r\n numbers.sort((a, b) => a - b);\r\n var max = numbers[numbers.length - 1];\r\n // write(max + ' max \\n'); \r\n for (var j = 0; j < numbers.length - 1; j++) {\r\n max -= numbers[j]; \r\n // write(max + ' max \\n'); \r\n }\r\n\r\n var result = [];\r\n\r\n var finded = max * -1;\r\n var findedIndex = numbers.indexOf(finded);\r\n if (findedIndex != -1) {\r\n // write(findedIndex + ' findedIndex \\n'); \r\n numbers.splice(findedIndex, 1);\r\n numbers.splice(-1, 1);\r\n result = numbers;\r\n } else {\r\n max = numbers[numbers.length - 2];\r\n for (var j = 0; j < numbers.length - 1; j++) {\r\n max -= numbers[j]; \r\n }\r\n if (max == 0) {\r\n numbers.splice(-2, 2);\r\n result = numbers; \r\n } else {\r\n result = [-1];\r\n }\r\n\r\n }\r\n\r\n write(result.join(' ') + '\\n'); \r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n\r\n var iMax1 = parseInt(arr[0]) >= parseInt(arr[1]) ? 0 : 1;\r\n var iMax2 = parseInt(arr[0]) >= parseInt(arr[1]) ? 1 : 0;\r\n\r\n for (var i = 2; i < n + 2; i++) {\r\n if (parseInt(arr[i]) > parseInt(arr[iMax1])) {\r\n iMax2 = iMax1;\r\n iMax1 = i;\r\n } else if (parseInt(arr[i]) > parseInt(arr[iMax2])) {\r\n iMax2 = i;\r\n }\r\n }\r\n\r\n var arrSum = arr.reduce((sum, item) => sum += parseInt(item), 0);\r\n\r\n var testMax = iMax => {\r\n for (var i = 0; i < n + 2; i++) {\r\n if (i !== iMax && arrSum - arr[i] - arr[iMax] === parseInt(arr[iMax])) {\r\n arr.splice(i, 1);\r\n arr.splice(iMax, 1);\r\n print(arr.join(' '));\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (!testMax(iMax1)) {\r\n if (!testMax(iMax2)) {\r\n print('-1');\r\n }\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet b = rna();\r\n\r\n\t\tlet have = new Map();\r\n\t\tlet sm = 0;\r\n\t\tfor (x of b) {\r\n\t\t\tsm += x;\r\n\t\t\thave.set(x, 1 + (have.has(x) ? have.get(x) : 0));\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; !ans && i < n + 2; i++) {\r\n\t\t\tconst x = sm - 2 * b[i];\r\n\t\t\tif (have.has(x)) {\r\n\t\t\t\tif (x == b[i] && have.get(x) != 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tans = b.slice();\r\n\t\t\t\tans.splice(ans.indexOf(b[i]), 1);\r\n\t\t\t\tans.splice(ans.indexOf(x), 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet b = rna();\r\n\r\n\t\tlet have = new Map();\r\n\t\tlet sm = 0;\r\n\t\tfor (x of b) {\r\n\t\t\tsm += x;\r\n\t\t\thave.set(x, 1 + (have.has(x) ? have.get(x) : 0));\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; !ans && i < n + 2; i++) {\r\n\t\t\tconst x = sm - 2 * b[i];\r\n\t\t\tif (have.has(x)) {\r\n\t\t\t\tans = b.slice();\r\n\t\t\t\tans.splice(ans.indexOf(b[i]), 1);\r\n\t\t\t\tans.splice(ans.indexOf(x), 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (x of b) sm += x;\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; !ans && i < n + 2; i++) {\r\n\t\t\tconst x = sm - 2 * b[i];\r\n\t\t\tfor (let j = 0; !ans && j < n + 2; j++)\r\n\t\t\t\tif (b[j] == x) {\r\n\t\t\t\t\tans = b.slice();\r\n\t\t\t\t\tans.splice(ans.indexOf(b[i]), 1);\r\n\t\t\t\t\tans.splice(ans.indexOf(b[j]), 1);\r\n\t\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n n = n + 2\r\n var sum = 0\r\n var object = {}\r\n for (let j = 0; j < n; j++) {\r\n sum += a[j]\r\n object[a[j]] = true\r\n }\r\n var ans = []\r\n var minus1 = false\r\n var minus2 = false\r\n for (let j = 0; j < n; j++) {\r\n var number = sum - a[j]\r\n if (number % 2 === 0 && object[number / 2]) {\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === a[j] && !minus1) {\r\n minus1 = true\r\n continue\r\n }\r\n if (a[i] === number / 2 && !minus2) {\r\n minus2 = true\r\n continue\r\n }\r\n ans.push(a[i])\r\n }\r\n console.log(ans.join(' '))\r\n return\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n}\r\n"}], "src_uid": "ce667a8fb60841c994aebedb35a3b0d8"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 0;\n const arr = d.split('').map(Number);\n let inc = 0;\n\n for (let i = arr.length; i >= 0; i--) {\n if (arr[i] % 2 === 0) {\n inc++;\n }\n\n ans += inc;\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = nextCharArray();\n\tvar output = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(myconv(list[i], 1) % 2 == 0){\n\t\t\toutput += i + 1;\n\t\t}\n\t}\n\tmyout(output);\n}\n"}, {"source_code": "var n = readline();\nvar a = readline().split('');\nvar res = 0;\nfor(var i=0; i {\n var n = answer,k = 0,count=0\n rl.question('',(line) => {\n var str = line;\n for(var i=0;i 0; i--) {\n\t\tif (s[i - 1] % 2 === 0) x += i;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}], "negative_code": [{"source_code": "var readline = require('readline');\nrl = readline.createInterface({\n input:process.stdin,\n output:process.stdout\n})\n\nrl.question('', (answer) => {\n var n = answer,k = 0,r = 0,i = 0\n rl.question('',(line) => {\n var str = line;\n var string='';\n while(string != str[str.length-1]) {\n if(string==str[i]){\n i++;\n r=0\n }\n string = str.substring(i,str.length-r)\n if (+string%2==0) {\n k++\n }\n r++\n }\n if(str[str.length-1]==str[str.length-2]){\n k++\n }\n console.log(k)\n rl.close()\n })\n})\n"}, {"source_code": "var n = readline();\nvar string = readline().substring(0,n);\n\nif(/[1-9]*/.test(string)){\nvar cnt=0;\nfor(var i=0; i65000) exit();\nvar cnt=0;\nfor(var i=0; i args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/24/21 morning\r\n * https://codeforces.com/contest/1529/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n let min = amin(a);\r\n let m = counter(a);\r\n let minC = m.get(min);\r\n // pr(n, a)\r\n pr(n - minC);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "\r\nconst solve = (line) => {\r\n\tconst arr = line.split(' ').map(v => +v);\r\n\tconst min = Math.min(...arr);\r\n\r\n\treturn arr.filter(item => item !== min).length;\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [n, ...lines] = input.trim().split('\\n')\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=0; i {\r\n return Number(num)\r\n })\r\n let removedElements = applyEshag(eshagArray)\r\n console.log(removedElements)\r\n }\r\n\r\n}\r\n\r\nfunction applyEshag(eshagArray) {\r\n let minValue= eshagArray[0];\r\n let wantedArray = [...eshagArray]\r\n for (let number of eshagArray) {\r\n \r\n if (number <= minValue) {\r\n minValue = number\r\n }\r\n }\r\n wantedArray = wantedArray.filter(el => el > minValue)\r\n \r\n return wantedArray.length\r\n \r\n}\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar stdin_input = \"\";\r\n \r\nprocess.stdin.on(\"data\", function (input) {\r\n stdin_input += input;\r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n main(stdin_input);\r\n});"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solutionA(nums) {\r\n nums.sort((x, y) => x - y);\r\n for (let i = 1; i < nums.length; ++i) {\r\n if (nums[i] > nums[i - 1])\r\n return nums.length - i;\r\n }\r\n return 0;\r\n}\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n const countOfNums = Number(io.readLine());\r\n const nums = io\r\n .readLine()\r\n .trim()\r\n .split(/\\s+/g)\r\n .map(x => Number(x))\r\n .slice(0, countOfNums);\r\n const answer = solutionA(nums);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solutionA(nums) {\r\n nums.sort((x, y) => x - y);\r\n for (let i = 1; i < nums.length; ++i) {\r\n if (nums[i] > nums[i - 1])\r\n return nums.length - i;\r\n }\r\n return 0;\r\n}\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n Number(io.readLine());\r\n const nums = io.readLine().split(/\\s+/g).map(x => Number(x));\r\n const answer = solutionA(nums);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0], e = 0\n for(j = 1; j <= n*2; j++){\n if(j % 2 === 1){\n e = lines[j], a = new Map()\n }else{\n k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b}),\n small = k[0], s = 0\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n tp = a.get(k[l])\n tp++\n a.set(k[l], tp)\n }else{\n a.set(k[l], 1)\n }\n }\n var biggestKey = ''\n var biggestValue = 0\n for(var[key, value] of a){\n if(key != small){\n s+=value\n }\n }\n console.log(s)\n \n }\n \n \n }\n \n\t \n}); "}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet m = a.reduce((ac, e) => e e == m?(ac+1):ac, 0));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet m = Math.min(...a);\n\t\tans.push(n - a.reduce((ac, e) => e == m?(ac+1):ac, 0));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const fs = require('fs')\r\n\r\nconst inputs = fs.readFileSync(0).toString().split('\\n');\r\n\r\nfunction deleteElementsFromArr(arr = [], count = 0) {\r\n if (!arr.length) return count;\r\n const avg = arr.reduce((sum, cur) => sum + cur, 0) / arr.length;\r\n const max = Math.max(...arr);\r\n if (max > avg) {\r\n const newArr = arr.filter(el => el !== max);\r\n return deleteElementsFromArr(newArr, (arr.length - newArr.length) + count);\r\n }\r\n return count;\r\n}\r\n\r\n\r\nfunction main() {\r\n for (let i = 2; i < inputs.length; i += 2) {\r\n const arr = inputs[i].split(\" \").map(e => +e);\r\n const count = deleteElementsFromArr(arr);\r\n console.log(count);\r\n\r\n }\r\n}\r\n\r\n\r\nmain();"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = 0;\n var a = k[0];\n for(j = 1; j < e; j++){\n if(k[j] > a){\n ans++;\n }\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let len = readLine();\r\n let arr = readLine().split(\" \").map(i => parseInt(i)).sort((a, b) => a - b);\r\n let count = 1;\r\n for (let i = 1; i < len; i++) {\r\n if (arr[0] == arr[i]) count++;\r\n else break;\r\n }\r\n console.log(arr.length - count);\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet lines = [];\r\nlet lineIdx = 0;\r\n\r\nrl.on(\"line\", line => {\r\n lines.push(line);\r\n});\r\n\r\nrl.on(\"close\", () => {\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return lines[lineIdx++];\r\n}\r\n\r\nfunction main() {\r\n let t = +readLine();\r\n while (t--) {\r\n let n = +readLine();\r\n let a = readLine().split(' ').map(x => +x).sort((x, y) => x - y);\r\n let i = 0;\r\n while (i < n && a[0] == a[i])\r\n i++;\r\n console.log(n - i);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const N = parseInt(lines[0]);\n const arrays = [];\n const arrMin = [];\n let min = 999999;\n let result = 0;\n\n for (let i = 2; i < lines.length; i += 2) {\n arrays.push(lines[i].split(' ').map((n) => parseInt(n)));\n }\n\n for (let arr of arrays) {\n min = 999999;\n for (let num of arr) {\n min = Math.min(num, min);\n }\n arrMin.push(min);\n }\n for (let j = 0; j < arrays.length; j++) {\n result = 0;\n for (let i = 0; i < arrays[j].length; i++) {\n if (arrays[j][i] > arrMin[j]) {\n result += 1;\n }\n }\n console.log(result);\n }\n});\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function proc() {\r\n let n = +await nextString();\r\n let mas = (await nextString()).split(' ').map(x => +x)\r\n let min = Math.min(...mas)\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n if (mas[i] > min) {\r\n ++ans\r\n }\r\n }\r\n console.log(ans)\r\n}\r\n \r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n await proc()\r\n }\r\n}\r\n \r\nmain()\r\n"}], "negative_code": [{"source_code": "function main(input) {\r\n let arr = input.split(\"\\n\");\r\n let testCases = arr[0];\r\n\r\n \r\n // Begin Coding\r\n \r\n for ( let i= 2; i < arr.length; i+=2) {\r\n \r\n let eshagArray= arr[i]\r\n eshagArray = eshagArray.split(\" \").map(num => {\r\n return Number(num)\r\n })\r\n let removedElements = applyEshag(eshagArray)\r\n console.log(removedElements)\r\n }\r\n\r\n}\r\n\r\nfunction applyEshag(eshagArray) {\r\n let avg = null;\r\n for (let number of eshagArray) {\r\n avg += number\r\n }\r\n avg = avg/eshagArray.length\r\n let subSequenceFiltered = eshagArray.filter(el => el < avg)\r\n if (subSequenceFiltered.length === 0) {\r\n return 0;\r\n } else {\r\n return eshagArray.length - subSequenceFiltered.length\r\n }\r\n}\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar stdin_input = \"\";\r\n \r\nprocess.stdin.on(\"data\", function (input) {\r\n stdin_input += input;\r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n main(stdin_input);\r\n});"}, {"source_code": "\r\n\r\nfunction main(input) {\r\n let arr = input.split(\"\\n\")\r\n let testCases = arr[0]\r\n let arrayLength = arr[1]\r\n let eshagArray = arr[2]\r\n eshagArray = eshagArray.split(\" \").map(num => {\r\n return Number(num)\r\n })\r\n \r\n \r\n let removedElements = applyEshag(eshagArray)\r\n // return removedElements\r\n // process.stdout.write(removedElements)\r\n console.log(removedElements)\r\n \r\n}\r\n\r\nfunction applyEshag(eshagArray) {\r\n let subSequence = eshagArray.slice(1,4);\r\n let avg = null;\r\n \r\n for (let number of eshagArray) {\r\n avg += number\r\n }\r\n avg = avg/eshagArray.length\r\n let subSequenceFiltered = eshagArray.filter(el => el < avg)\r\n // console.log('average',avg)\r\n // console.log('new',subSequenceFiltered)\r\n const test = eshagArray.length - subSequenceFiltered.length\r\n if (subSequenceFiltered.length === 0) {\r\n return 0;\r\n } else {\r\n return eshagArray.length - subSequenceFiltered.length\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar stdin_input = \"\";\r\n\r\nprocess.stdin.on(\"data\", function (input) {\r\n stdin_input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n main(stdin_input);\r\n});"}, {"source_code": "\r\n\r\nfunction main(input) {\r\n let arr = input.split(\"\\n\")\r\n let testCases = arr[0]\r\n let arrayLength = arr[1]\r\n let eshagArray = arr[2]\r\n eshagArray = eshagArray.split(\" \").map(num => {\r\n return Number(num)\r\n })\r\n \r\n \r\n let removedElements = applyEshag(eshagArray)\r\n return removedElements\r\n // console.log('final result',removedElements)\r\n \r\n}\r\n\r\nfunction applyEshag(eshagArray) {\r\n let subSequence = eshagArray.slice(1,4);\r\n let avg = null;\r\n \r\n for (let number of eshagArray) {\r\n avg += number\r\n }\r\n avg = avg/eshagArray.length\r\n let subSequenceFiltered = eshagArray.filter(el => el < avg)\r\n // console.log('average',avg)\r\n // console.log('new',subSequenceFiltered)\r\n const test = eshagArray.length - subSequenceFiltered.length\r\n if (subSequenceFiltered.length === 0) {\r\n return 0;\r\n } else {\r\n return eshagArray.length - subSequenceFiltered.length\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar stdin_input = \"\";\r\n\r\nprocess.stdin.on(\"data\", function (input) {\r\n stdin_input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n main(stdin_input);\r\n});"}, {"source_code": "\r\n\r\nfunction main(input) {\r\n let arr = input.split(\"\\n\")\r\n let testCases = arr[0]\r\n let arrayLength = arr[1]\r\n let eshagArray = arr[2]\r\n eshagArray = eshagArray.split(\" \").map(num => {\r\n return Number(num)\r\n })\r\n \r\n \r\n let removedElements = applyEshag(eshagArray)\r\n // console.log('final result',removedElements)\r\n \r\n}\r\n\r\nfunction applyEshag(eshagArray) {\r\n let subSequence = eshagArray.slice(1,4);\r\n let avg = null;\r\n \r\n for (let number of eshagArray) {\r\n avg += number\r\n }\r\n avg = avg/eshagArray.length\r\n let subSequenceFiltered = eshagArray.filter(el => el < avg)\r\n // console.log('average',avg)\r\n // console.log('new',subSequenceFiltered)\r\n const test = eshagArray.length - subSequenceFiltered.length\r\n if (subSequenceFiltered.length === 0) {\r\n return 0;\r\n } else {\r\n return eshagArray.length - subSequenceFiltered.length\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar stdin_input = \"\";\r\n\r\nprocess.stdin.on(\"data\", function (input) {\r\n stdin_input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n main(stdin_input);\r\n});"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solutionA(nums) {\r\n nums.sort((x, y) => x - y);\r\n for (let i = 1; i < nums.length; ++i) {\r\n if (nums[i] > nums[i - 1])\r\n return nums.length - i;\r\n }\r\n return 0;\r\n}\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n Number(io.readLine());\r\n const nums = io.readLine().split(/\\s*/g).map(x => Number(x));\r\n const answer = solutionA(nums);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('\\n');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n if (process.env.GUANGHECHEN_LOCAL)\r\n return;\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solutionA(nums) {\r\n nums.sort((x, y) => x - y);\r\n for (let i = 1; i < nums.length; ++i) {\r\n if (nums[i] > nums[i - 1])\r\n return nums.length - i;\r\n }\r\n return 0;\r\n}\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n Number(io.readLine());\r\n const nums = io.readLine().split('').map(x => Number(x));\r\n const answer = solutionA(nums);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n\r\nexports.default = solutionA;\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0, k = 0\n for(j = 1; j <= n *2; j++){\n if(j % 2 == 1){\n e = lines[j],a = new Map()\n }else{\n k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n ut = a.get(k[l])\n ut++\n a.set(k[l], ut)\n }else{\n a.set(k[l], 1)\n }\n }\n var biggestValue = 0\n for(var[key, value] of a){\n if(value > biggestValue){\n biggestValue=value\n }\n }\n console.log(Number(e - biggestValue))\n }\n }\n\n});"}, {"source_code": "const fs = require('fs')\r\n\r\nconst inputs = fs.readFileSync(0).toString().split('\\n');\r\n\r\nfunction deleteElementsFromArr(arr = [], count = 0) {\r\n if (!arr.length) return count;\r\n const avg = arr.reduce((sum, cur) => sum + cur, 0) / arr.length;\r\n const newArr = arr.filter(el => el <= avg);\r\n if (newArr.length !== arr.length) return deleteElementsFromArr(newArr, (arr.length - newArr.length));\r\n return count;\r\n}\r\n\r\n\r\nfunction main() {\r\n for (let i = 2; i < inputs.length; i += 2) {\r\n const arr = inputs[i].split(\" \").map(e => +e);\r\n const count = deleteElementsFromArr(arr);\r\n console.log(count);\r\n\r\n }\r\n}\r\n\r\n\r\nmain();"}], "src_uid": "d5627b9fe5f6c5a7247e1f9d9e9b0c6a"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, x] = rna();\r\n\t\tlet a = rna();\r\n\t\tlet j = x - 1, i = n - x;\r\n\r\n\t\tlet b = a.slice();\r\n\t\tb.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = true;\r\n\t\tfor (let k = i; k <= j; k++) {\r\n\t\t\tans = ans && a[k] == b[k];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, x] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, x, arr))\n }\n// })()\n})\n\nfunction solve(n, x, arr) {\n const sorted = arr.slice().sort((a, b) => a - b)\n for (let i = 0; i < arr.length; i++) {\n if (i + x >= n && i - x < 0 && arr[i] !== sorted[i]) {\n return 'NO'\n }\n }\n return 'YES'\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n\r\n let ans = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] > arr[i + 1]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans) console.log(\"YES\");\r\n else {\r\n ans = true;\r\n let narr = [...arr];\r\n narr.sort((a, b) => a - b);\r\n let bool = new Array(n).fill(false);\r\n for (let i = 0; i < n; i++) {\r\n if (!bool[i]) {\r\n for (let j = i + x; j < n; j++) {\r\n if (bool[j] === true) {\r\n bool[i] = true;\r\n break;\r\n }\r\n if (j - i >= x) {\r\n bool[i] = true;\r\n bool[j] = true;\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (!bool[i]) {\r\n if (narr[i] !== arr[i]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n }\r\n if (ans) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\tlet cnt = 0;\r\n\twhile (t--) {\r\n\t\tlet [n, x] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tcnt ++;\r\n\t\tif (cnt == 48) {\r\n\t\t\tconsole.log(n, x) ;\r\n\t\t\tconsole.log(a);\r\n\t\t}\r\n\t\tconst k = n - x;\r\n\r\n\t\tif (2 * k >= n) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet sorted = true;\r\n\t\tfor (let i = k + 1; sorted && i < n - k; i++) {\r\n\t\t\tif (a[i] < a[i - 1]) sorted = false;\r\n\t\t}\r\n\t\tif (!sorted) { \r\n\t\t\tconsole.log('NO');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet lcnt = 0, l = a[k];\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\tif (a[i] <= l) lcnt++;\r\n\t\t\tif (a[n-1-i] <= l) lcnt++;\r\n\t\t}\r\n\r\n\t\tans = lcnt == k ? 'YES' : 'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, x] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tconst k = n - x;\r\n\r\n\t\tif (2 * k >= n) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet sorted = true;\r\n\t\tfor (let i = k + 1; sorted && i < n - k; i++) {\r\n\t\t\tif (a[i] < a[i - 1]) sorted = false;\r\n\t\t}\r\n\t\tif (!sorted) { \r\n\t\t\tconsole.log('NO');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet lcnt = 0, l = a[k];\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\tif (a[i] <= l) lcnt++;\r\n\t\t\tif (a[n-1-i] <= l) lcnt++;\r\n\t\t}\r\n\r\n\t\tans = lcnt == k ? 'YES' : 'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n"}], "src_uid": "1305b44c5c588221bc991c696a492fe7"} {"source_code": "var nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = nums[0];\nvar AAA = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar init_cnt = Array(3).fill(0);\nfor (var i=0; i 0) {\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n// \twrite(\"init_cnt = \",init_cnt,\"\\n\");\n// \twrite(\"sizes > 2\");\n// \tfor (var i=0; i 2)\n// \t\t\twrite(ms[i].length,\" \");\n// \tfor (var i=0; i 0) {\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n//write(\"stk = \",st,\"\\n\");\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n\twrite(\"init_cnt = \",init_cnt,\"\\n\");\n\twrite(\"sizes > 2\");\n\tfor (var i=0; i 2)\n\t\t\twrite(ms[i].length,\" \");\n\tfor (var i=0; i 0) {\n\tvar v = st[st.length-1];\n\tnnew[v] = 1;\n\tvar fnd = 0;\n\tfor (var i=sv[v]; i 0) {\n\twrite(\"init_cnt = \",init_cnt,\"\\n\");\n\twrite(\"sizes > 2\");\n\tfor (var i=0; i 2)\n\t\t\twrite(ms[i].length,\" \");\n\tfor (var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n let numberOfTwoSeaterOccupiedByOnePerson = 0;\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfTwoSeaterOccupiedByOnePerson++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && !numberOfTwoSeater&& numberOfTwoSeaterOccupiedByOnePerson > 0) {\n\n numberOfTwoSeaterOccupiedByOnePerson--;\n groups[index] = 0;\n } \n \n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "function GetAns(n, a, b, array){\n\tvar ans=0;\n\tvar tOne, tTwo, tTwoWithOne;\n\ttOne = a; tTwo = b; tTwoWithOne = 0;\n\tfor (var i=0;i0)\n\t\t\t\ttTwo--;\n\t\t\telse\n\t\t\t\tans+=2;\n\t\t}\n\t\telse{\n\t\t\tif (tOne>0)\n\t\t\t\ttOne--;\n\t\t\telse{\n\t\t\t\tif (tTwo>0){\n\t\t\t\t\t\ttTwo--;\n\t\t\t\t\t\ttTwoWithOne++;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tif (tTwoWithOne>0) tTwoWithOne--;\n\t\t\t\t\telse\n\t\t\t\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t}\n\treturn ans;\n}\n\nvar input = readline().split(' ');\nvar n=+input[0], a=+input[1], b=+input[2];\nvar array=readline().split(' ');\nprint(GetAns(n,a,b,array));"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet [n, a, b] = inputReader.readNumberArray();\n\tlet arr = inputReader.readNumberArray();\n\tlet extra = 0;\n\tlet count = 0;\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tif (arr[i] === 1) {\n\t\t\tif (a > 0) a--;\n\t\t\telse if (b > 0) {\n\t\t\t\tb--;\n\t\n\t\t\t\textra++;\n\t\t\t} else if (extra > 0) {\n\t\t\t\textra--;\n\t\t\t} else count++;\n\t\t} else {\n\t\t\tif (b > 0) b--;\n\t\t\telse count += 2;\n\t\t}\n\t}\n\tconsole.log(count);\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumberArray(){\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumberArray,\n\t}\n}"}], "negative_code": [{"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n sum = groups => groups.reduce((a,b) => a + b, 0)\n\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0) {\n\n numberOfOneSeater += 2;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += Number(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < numberOfGroups; index++) {\n\n if (Number(groups[index]) == 1 && numberOfOneSeater > 0) {\n numberOfOneSeater--;\n groups[index] = 0 \n }\n\n else if(Number(groups[index]) == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0\n }\n \n else if (Number(groups[index]) != 1 && numberOfTwoSeater > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n }\n \n for(let index = 0 ; index < numberOfGroups ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n let totalSum = 0 ;\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n sum++;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n sum++;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--; \n sum += 2\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n totalSum += parseInt(groups[index]);\n }\n\n console.log(totalSum - sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n /**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 ;\n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 ;\n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater -= 2;\n groups[index] = 0;\n } \n \n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater -= 2;\n groups[index] = 0;\n } \n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < numberOfGroups; index++) {\n\n if (Number(groups[index]) == 1 && numberOfOneSeater > 0) {\n numberOfOneSeater--;\n groups[index] = 0 \n }\n\n else if(Number(groups[index]) == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0\n }\n \n else if (Number(groups[index]) != 1 && numberOfTwoSeater > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n\n if (Number(groups[index]) != 1 && numberOfTwoSeater ==0) {\n groups[index] = 2 \n }\n }\n \n for(let index = 0 ; index < numberOfGroups ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 2 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 ;\n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < numberOfGroups; index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 \n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n }\n \n for(let index = 0 ; index < numberOfGroups ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n }\n \n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) == 0){\n\n sum++\n }\n\n else if(Number(groups[index]) != 1 && Number(numberOfTwoSeater) == 0){\n\n sum +=2 \n }\n }\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < numberOfGroups; index++) {\n\n if (Number(groups[index]) == 1 && numberOfOneSeater > 0) {\n numberOfOneSeater--;\n groups[index] = 0 \n }\n\n else if(Number(groups[index]) == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0\n }\n \n else if (Number(groups[index]) != 1 && numberOfTwoSeater > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n\n else if (Number(groups[index]) != 1 && numberOfTwoSeater ==0) {\n groups[index] = 2 \n }\n }\n \n for(let index = 0 ; index < numberOfGroups ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 \n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 \n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n sum = function(arr){\n return arr.reduce(function(a,b){\n return a + b\n }, 0);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 ;\n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += Number(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n }\n \n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) == 0){\n\n sum++\n }\n\n else if(Number(groups[index]) != 2 && Number(numberOfTwoSeater) == 0){\n\n sum +=2 \n }\n }\n console.log(sum)\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && numberOfOneSeater == 0 && numberOfTwoSeater > 0) {\n\n numberOfOneSeater += 2;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += groups[index];\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n let numberOfTwoSeaterOccupiedByOnePerson = 0;\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfTwoSeaterOccupiedByOnePerson++;\n numberOfTwoSeater--;\n } \n \n if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeaterOccupiedByOnePerson > 0) {\n\n numberOfTwoSeaterOccupiedByOnePerson--;\n groups[index] = 0 ;\n } \n \n\n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n let oldNumberOfOneSeater = numberOfOneSeater;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n\n oldNumberOfOneSeater = numberOfOneSeater;\n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && oldNumberOfOneSeater > 1 && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfOneSeater++;\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = Number(inputString[0].split(\" \")[0]);\n let numberOfOneSeater = Number(inputString[0].split(\" \")[1]);\n let numberOfTwoSeater = Number(inputString[0].split(\" \")[2]);\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0;\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n if (groups[index] == 1 && numberOfOneSeater > 0) {\n \n numberOfOneSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] == 1 && !numberOfOneSeater && numberOfTwoSeater > 0) {\n\n numberOfTwoSeater--;\n groups[index] = 0;\n } \n \n else if (groups[index] > 0 && groups[index] != 1 && numberOfTwoSeater > 0) {\n \n numberOfTwoSeater--;\n groups[index] = 0;\n }\n \n }\n\n for (let index = 0; index < numberOfGroups; index++) {\n\n sum += parseInt(groups[index]);\n }\n\n console.log(sum);\n}"}, {"source_code": "/**\n * \nIn a small restaurant there are a tables for one person and b tables for two persons.\n\nIt it known that n groups of people come today, each consisting of one or two people.\n\nIf a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, \nit is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person.\n If there are still none of them, the restaurant denies service to this group.\n\nIf a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.\n\nYou are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.\n\nInput\nThe first line contains three integers n, a and b (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7105, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7105) \u2014 the number of groups coming to the restaurant, \nthe number of one-seater and the number of two-seater tables.\n\nThe second line contains a sequence of integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u20092) \u2014 the description of clients in chronological order.\n If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.\n\nOutput\nPrint the total number of people the restaurant denies service to.\n\nExamples\ninput\n4 1 2\n1 2 1 1\noutput\n0\ninput\n4 1 1\n1 1 2 1\noutput\n2\nNote\nIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. \nThe third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person,\n he is seated at the remaining seat at the two-seater table. Thus, all clients are served.\n\nIn the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, \nit occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. \nThe fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let numberOfGroups = inputString[0].split(\" \")[0];\n let numberOfOneSeater = inputString[0].split(\" \")[1];\n let numberOfTwoSeater = inputString[0].split(\" \")[2];\n let groups = inputString[1].split(\" \")\n\n solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups)\n\n});\n\nfunction solution(numberOfGroups, numberOfOneSeater, numberOfTwoSeater, groups) {\n\n let sum = 0 ; \n let numberOfTwoSeaterOccupiedByOnePerson = 0;\n for (let index = 0; index < Number(numberOfGroups); index++) {\n\n if (Number(groups[index]) == 1 && Number(numberOfOneSeater) > 0) {\n numberOfOneSeater--;\n groups[index] = 0 ;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfOneSeater) == 0 && Number(numberOfTwoSeater) > 0){\n\n numberOfTwoSeaterOccupiedByOnePerson++;\n numberOfTwoSeater--;\n // groups[index] = 0;\n }\n\n else if(Number(groups[index]) == 1 && Number(numberOfTwoSeaterOccupiedByOnePerson) > 0 ){\n numberOfTwoSeaterOccupiedByOnePerson--;\n groups[index] = 0;\n\n }\n \n else if (Number(groups[index]) != 1 && Number(numberOfTwoSeater) > 0) {\n numberOfTwoSeater--;\n groups[index] = 0 ;\n }\n }\n \n for(let index = 0 ; index < Number(numberOfGroups) ; index ++){\n\n sum += Number(groups[index])\n }\n\n console.log(sum)\n}"}, {"source_code": "var data = readline().split(' ').map(function (x) { return parseInt(x); });\nvar guests = readline().split(' ').map(function (x) { return parseInt(x); });\n\nvar sTable = data[1];\nvar dTable = data[2];\n\nvar total = guests.reduce(function (a,b) {\n return parseInt(a)+parseInt(b);\n}, 0);\n\nfor (var g of guests) {\n if (g === 2) {\n if (dTable > 0) {\n dTable--;\n total -= g;\n }\n }\n if (g === 1) {\n if (sTable > 0) {\n sTable--;\n total -= g;\n } else if (dTable > 0) {\n dTable--;\n sTable++;\n total -= g;\n }\n }\n \n}\n\nprint(total);"}, {"source_code": "function GetAns(n, a, b, array){\n\tvar ans=0;\n\tvar tOne, tTwo, tTwoWithOne;\n\ttOne = a; tTwo = b; tTwoWithOne = 0;\n\tfor (var i=0;i0)\n\t\t\t\ttTwo--;\n\t\t\telse\n\t\t\t\tans+=2;\n\t\t}\n\t\telse{\n\t\t\tif (tOne>0)\n\t\t\t\ttOne--;\n\t\t\telse{\n\t\t\t\tif (tTwoWithOne>0) tTwoWithOne--;\n\t\t\t\telse\n\t\t\t\t\tif (tTwo>0){\n\t\t\t\t\t\ttTwo--;\n\t\t\t\t\t\ttTwoWithOne++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t}\n\treturn ans;\n}\n\nvar input = readline().split(' ');\nvar n=+input[0], a=+input[1], b=+input[2];\nvar array=readline().split(' ');\nprint(GetAns(n,a,b,array));"}], "src_uid": "e21e768dbb2e5f72873dc1c7de4879fd"} {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray()\n\n var sumArr = []\n var i\n var curSum = arr[0]\n var max = arr[0]\n for(i=1;i max) {\n max = arr[i]\n }\n }\n\n var seen = new Set(sumArr)\n sumArr.unshift(arr[0])\n var arrSeen = new Set(arr)\n var j\n var k\n for(j=1;j {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n t: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {t, arr} = data;\n const a = arr.split(' ').map(i => +i);\n let count = 0;\n let set = [];\n\n for(let i = 0; i < t; i++) { // a[i]\n let sum = a[i];\n for(let j = i + 1; j < t; j++) {\n sum += a[j];\n if(sum > t) break;\n set[sum] = 1;\n }\n }\n\n for(let i = 0; i < t; i++) {\n if(set[a[i]]) count++;\n }\n \n return count;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nCases = +input[index];\n for (let c = 0; c < nCases; c++){\n index += 2;\n let cnt = 0;\n let map = {};\n let arr = input[index].split(\" \").map((val)=>+val);\n for (let i = 0; i < arr.length - 1; i++){\n let sum = arr[i];\n for (let j = i + 1; j < arr.length; j++){\n sum += arr[j];\n if (sum > arr.length)\n break;\n map[sum] = 1;\n }\n }\n for (let i = 0; i < arr.length; i++)\n if (arr[i] in map)\n cnt++;\n console.log(cnt);\n }\n}"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray()\n\n var sumArr = []\n var i\n var curSum = 0\n var max = arr[0]\n for(i=0;i max) {\n max = arr[i]\n }\n }\n\n var seen = new Array(max + 1)\n for(i=1;i max) {\n max = arr[i]\n }\n }\n\n var seen = new Array(max + 1)\n for(i=1;i 0) {\n count += mark[n]\n mark[n] = 0\n }\n }\n }\n }\n print(count)\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var n = Number(readline())\n var arr = readline().split(\" \").map(function(x) { return +x })\n countSpecialElements(n,arr)\n}"}], "negative_code": [{"source_code": "function countSpecialElements(len,arr) {\n if (len < 3) {\n print(0)\n return\n }\n var prefixSum = new Array(len)\n var mx = prefixSum[0] = arr[0]\n for (var i=1; i 0) {\n ++count\n --mark[n]\n }\n }\n }\n }\n print(count)\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var n = Number(readline())\n var arr = readline().split(\" \").map(function(x) { return +x })\n countSpecialElements(n,arr)\n}"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray()\n\n var sumArr = []\n var i\n var curSum = arr[0]\n for(i=1;i max) {\n max = arr[i]\n }\n }\n\n var seen = new Set(sumArr)\n sumArr.unshift(arr[0])\n var arrSeen = new Set(arr)\n var j\n var k\n for(j=1;j 0) {\n ++count\n --mark[n]\n }\n }\n }\n }\n print(count)\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var n = Number(readline())\n var arr = readline().split(\" \").map(function(x) { return +x })\n countSpecialElements(arr)\n}"}, {"source_code": "function countSpecialElements(len,arr) {\n if (len < 3) {\n print(0)\n return\n }\n var prefixSum = new Array(len)\n var mx = prefixSum[0] = arr[0]\n for (var i=1; i 0) {\n count += mark[n]\n //--mark[n]\n }\n }\n }\n }\n print(count)\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var n = Number(readline())\n var arr = readline().split(\" \").map(function(x) { return +x })\n countSpecialElements(n,arr)\n}"}], "src_uid": "2326470337301e0f4b0d1b1a6195e398"} {"source_code": "var input = readline().split(\" \").map(x=>parseInt(x));\nvar bz = input[0];\nvar lp = input[1];\nvar banner = readline().split(\"\");\nvar middle = Math.ceil(banner.length/2);\nif(middle>=lp && lp < banner.length){\n for(var i=lp-1; i>0; i--){\n print('LEFT');\n lp--; \n }\n}else if(middle1){\n for(var j=lp; j=0; l--){\n print(\"PRINT\",banner[l]);\n if(banner[l-1] !== undefined){\n print(\"LEFT\")\n }\n } \n}", "positive_code": [{"source_code": "function main() {\n\n var temp = readline().split(' ').map(Number);\n var n = temp[0],\n k = temp[1];\n\n var arr = readline();\n\n var res = [];\n\n if (k - 1 < n - k) {\n for (var i = 0; i < k - 1; i++) {\n res.push(\"LEFT\");\n }\n for (var j = 0; j < n - 1; j++) {\n res.push(\"PRINT \" + arr[j]);\n res.push(\"RIGHT\");\n }\n res.push(\"PRINT \" + arr[n - 1]);\n } else {\n for (var i = 0; i < n - k; i++) {\n res.push(\"RIGHT\");\n }\n for (var j = n-1; j >0; j--) {\n res.push(\"PRINT \" + arr[j]);\n res.push(\"LEFT\");\n }\n res.push(\"PRINT \" + arr[0]);\n }\n\n print(res.join(\"\\n\"));\n}\n\nmain();"}], "negative_code": [{"source_code": "var input = readline().split(\" \").map(x=>parseInt(x));\nvar bz = input[0];\nvar lp = input[1];\nvar banner = readline().split(\"\");\nvar middle = Math.ceil(banner.length/2);\nif(middle>lp && lp < banner.length){\n for(var i=lp; i>0; i--){\n print('LEFT');\n lp--; \n }\n}else if(middle<=lp && lp>1){\n for(var j=lp; j=0; l--){\n print(\"PRINT\",banner[l]);\n if(banner[l-1] !== undefined){\n print(\"LEFT\")\n }\n } \n}"}, {"source_code": "var input = readline().split(\" \").map(x=>parseInt(x));\nvar bz = input[0];\nvar lp = input[1];\nvar banner = readline().split(\"\");\nvar middle = Math.ceil(banner.length/2);\nif(middle>lp && lp < banner.length){\n for(var i=lp-1; i>0; i--){\n print('LEFT');\n lp--; \n }\n}else if(middle<=lp && lp>1){\n for(var j=lp; j=0; l--){\n print(\"PRINT\",banner[l]);\n if(banner[l-1] !== undefined){\n print(\"LEFT\")\n }\n } \n}"}, {"source_code": "function main() {\n\n var temp = readline().split(' ').map(Number);\n var n = temp[0],\n k = temp[1];\n\n var arr = readline();\n\n var res = [];\n\n if (k - 1 < n - k) {\n for (var i = 0; i < k - 1; i++) {\n res.push(\"LEFT\");\n }\n for (var j = 0; j < n - 1; j++) {\n res.push(\"PRINT \" + arr[j]);\n res.push(\"RIGHT\");\n }\n res.push(\"PRINT \" + arr[n - 1]);\n } else {\n for (i = 0; i < n - k; i++) {\n res.push(\"RIGHT\");\n }\n for (j = 0; j < n - 1; j++) {\n res.push(\"PRINT \" + arr[j]);\n res.push(\"LEFT\");\n }\n res.push(\"PRINT \" + arr[0]);\n }\n\n print(res.join(\"\\n\"));\n}\n\nmain();"}], "src_uid": "e3a03f3f01a77a1983121bab4218c39c"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, left, right, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, left, right, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, left, right, k, arr) {\n arr = arr.filter(x => x >= left && x <= right)\n .sort((a, b) => a - b)\n// console.log(arr)\n let now = 0\n let count = 0\n for (let i = 0; i < arr.length; i++) {\n if (now + arr[i] <= k) {\n now += arr[i]\n count++\n } else {\n break\n }\n }\n return count\n}\n", "positive_code": [{"source_code": "var t = readline();\r\nwhile(t--){\r\n var y = readline().split(\" \");\r\n var n = parseInt(y[0]), l = parseInt(y[1]), \r\n r = parseInt(y[2]), k = parseInt(y[3]);\r\n var arr = readline().split(\" \");\r\n \r\n var new_arr = [];\r\n for(var i = 0; i < n; i++){\r\n arr[i] = parseInt(arr[i]);\r\n if(arr[i] >= l && arr[i] <= r)\r\n new_arr.push(parseInt(arr[i]));\r\n }\r\n \r\n var ans = 0;\r\n new_arr.sort(function(a, b){return a - b;});\r\n for(var i = 0; i < new_arr.length; i++){\r\n if(new_arr[i] <= k){\r\n k -= new_arr[i];\r\n ans++;\r\n }else{\r\n break;\r\n }\r\n }\r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var input = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n var n = input[0]\r\n var l = input[1]\r\n var r = input[2]\r\n var k = input[3]\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data).sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n })\r\n\r\n var price = 0;\r\n var count = 0;\r\n\r\n for (var i = 0; i < n; i++) {\r\n var lastprice = price + a[i]\r\n if (lastprice <= k) {\r\n if (a[i] >= l && a[i] <= r) {\r\n price += a[i]\r\n count++\r\n }\r\n }\r\n if (a[i] > r) {\r\n break;\r\n }\r\n }\r\n print(count)\r\n }\r\n\r\n while (t--) {\r\n solve()\r\n }"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).filter(line => line) /*your input text, split by lines*/\n const lineNumbers = lines.slice(1).map((line) => line.split(' ').map(x => +x))\n for (let i = 0; i < lineNumbers.length; i+=2) {\n let [n, l, r, k] = lineNumbers[i];\n const sortedPrices = lineNumbers[i+1].sort((a, b) => a-b);\n let nOfBars = 0;\n sortedPrices.forEach(price => {\n if (price <= r && price >= l && k >= price) {\n nOfBars++;\n k-=price;\n }\n })\n console.log(nOfBars)\n }\n})"}, {"source_code": "data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n );\r\n\r\n for (let i = 0; i < input.length; i += 2) {\r\n let sum = 0;\r\n let result = [];\r\n\r\n let [_, l, r, k] = input[i];\r\n let arr = input[i + 1].sort((a, b) => a - b);\r\n\r\n arr = arr.filter((el) => el >= l && el <= r && el <= k);\r\n\r\n arr.forEach((el) => {\r\n sum += el;\r\n if (sum <= k) result.push(el);\r\n });\r\n\r\n console.log(result.length);\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t, n, l, r, k, arr;\r\n\r\n t = parseInt(readline());\r\n while(t--) {\r\n [n, l, r, k] = readline().split(' ').map(x => parseInt(x));\r\n arr = readline().split(' ').map(x => parseInt(x));\r\n console.log(solve(n, l, r, k, arr));\r\n }\r\n}\r\n\r\nfunction solve(n, l, r, k, arr) {\r\n let sum = 0, cnt = 0;\r\n arr.sort((a, b) => a - b);\r\n for(let i = 0; i < n; i++) {\r\n if(arr[i] < l || arr[i] > r || sum + arr[i] > k) continue;\r\n cnt++;\r\n sum += arr[i];\r\n }\r\n return cnt;\r\n}"}, {"source_code": "var readline = require(\"readline\");\r\n\r\nvar input = [];\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\n\r\n\r\nrl.on(\"line\", function (cmd) {\r\n input.push(cmd);\r\n});\r\n\r\nrl.on(\"close\", function (cmd) {\r\n let a = [], b = [];\r\n let count = input.shift();\r\n\r\n for(let i = 0; i < count; i++){\r\n\r\n a = input.shift().split(' ');\r\n b = input.shift().split(' ');\r\n\r\n let n = 0, l = +a[1], r = +a[2], k = +a[3], min = Infinity;\r\n\r\n b = b.filter(elem => (+elem >= l && +elem <= r))\r\n b.sort(sort);\r\n for(let j = 0; k >= 0;j++){\r\n k -= b[j];\r\n n++;\r\n }\r\n\r\n console.log(--n);\r\n }\r\n\r\n function sort(a,b){\r\n return +a - +b;\r\n }\r\n process.exit(0);\r\n});"}, {"source_code": "data = \"\";\r\n \r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n );\r\n \r\n for (let i = 0; i < input.length; i += 2) {\r\n let sum = 0;\r\n let result = [];\r\n \r\n let [_, l, r, k] = input[i];\r\n let arr = input[i + 1].sort((a, b) => a - b);\r\n \r\n arr = arr.filter((el) => el >= l && el <= r && el <= k);\r\n \r\n arr.forEach((el) => {\r\n sum += el;\r\n if (sum <= k) result.push(el);\r\n });\r\n \r\n console.log(result.length);\r\n }\r\n});"}, {"source_code": "const { mainModule } = require(\"process\");\r\nvar readline = require(\"readline\");\r\n\r\nvar input = [];\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on(\"line\", function (cmd) {\r\n input.push(cmd);\r\n});\r\n\r\nrl.on(\"close\", function () {\r\n let result = [];\r\n for (let i = 1; i < input.length; i += 2) {\r\n let temp = input[i].split(\" \").map((el) => +el);\r\n let a = input[i + 1].split(\" \").map((el) => +el);\r\n let l = a.length;\r\n for (let j = 0; j < l; ++j) {\r\n if (a[j] < temp[1] || a[j] > temp[2]) {\r\n a.splice(j, 1);\r\n j--;\r\n l--;\r\n }\r\n }\r\n let sum = 0;\r\n let counter = -1;\r\n while (sum <= temp[3]) {\r\n let x = Math.min(...a);\r\n sum += x;\r\n a.splice(a.indexOf(x), 1);\r\n counter++;\r\n }\r\n result.push(counter);\r\n }\r\n for (let k = 0; k < result.length; ++k) {\r\n console.log(result[k]);\r\n }\r\n process.exit(0);\r\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, l, r, k], arr) {\r\n let ans = 0, sum = 0\r\n arr.sort((a, b) => a - b)\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] > r) {\r\n break\r\n }\r\n if (arr[i] >= l) {\r\n sum += arr[i]\r\n if (sum > k) {\r\n break\r\n }\r\n ans++\r\n }\r\n }\r\n console.log(ans)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar L = nextInt();\r\n\t\tvar R = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(L <= list[i] && list[i] <= R){\r\n\t\t\t\tif(list[i] <= K){\r\n\t\t\t\t\tK -= list[i];\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "// const rl = require('readline').createInterface({\r\n// input: process.stdin,\r\n// output: process.stdout\r\n// });\r\n\r\nt = readline();\r\n// print(t)\r\n// // print(t)\r\n\r\nwhile(t--){\r\n // t -= 1;\r\n var n, l, r, k;\r\n var input = readline().split(\" \");\r\n n = +input[0];\r\n l = +input[1];\r\n r = +input[2];\r\n k = +input[3];\r\n var a = readline().split(\" \");\r\n var myArr = [];\r\n for(var i of a){\r\n if ((+i)>=l && (+i)<=r){\r\n myArr.push(+i);\r\n }\r\n }\r\n myArr = myArr.sort((a,b) => a-b);\r\n var count = 0, left = k;\r\n for (var i of myArr){\r\n if (left >= i){\r\n count++;\r\n left -= i;\r\n }\r\n else{\r\n break;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "var t = readline();\r\nwhile(t--){\r\n var y = readline().split(\" \");\r\n var n = parseInt(y[0]), l = parseInt(y[1]), \r\n r = parseInt(y[2]), k = parseInt(y[3]);\r\n var arr = readline().split(\" \");\r\n \r\n var new_arr = [];\r\n for(var i = 0; i < n; i++){\r\n arr[i] = parseInt(arr[i]);\r\n if(arr[i] >= l && arr[i] <= r)\r\n new_arr.push(parseInt(arr[i]));\r\n }\r\n \r\n var ans = 0;\r\n new_arr.sort(function(a, b){return a - b;});\r\n for(var i = 0; i < new_arr.length; i++){\r\n if(new_arr[i] <= k){\r\n k -= new_arr[i];\r\n ans++;\r\n }else{\r\n break;\r\n }\r\n }\r\n print(ans);\r\n}"}], "negative_code": [{"source_code": "let data = \"\";\r\n\r\nfunction solve() {\r\n let [_, ...arr] = data\r\n .trim()\r\n .split(/ |\\n/)\r\n .map((el) => el.trim())\r\n .map((el) => +el);\r\n\r\n arr = arr.sort((a, b) => a - b);\r\n let firstSum = 0;\r\n\r\n if (arr[1] === 10374) {\r\n console.log(476226);\r\n return 0;\r\n }\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n firstSum += arr[i];\r\n if (firstSum === arr[i] * arr.length) {\r\n console.log(firstSum);\r\n return 0;\r\n }\r\n }\r\n\r\n function gcd_two_numbers(x, y) {\r\n while (y) {\r\n let t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n\r\n let sum = 0;\r\n let counter = 0;\r\n let bigNum = 0;\r\n let eachGcd = 0;\r\n let divansArray = [];\r\n const firstArray = arr.length;\r\n\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n sum = arr[i];\r\n\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n counter += gcd_two_numbers(sum, arr[i]);\r\n\r\n if (i === 0) {\r\n if (counter > bigNum || counter === bigNum) {\r\n bigNum = counter;\r\n eachGcd = sum;\r\n }\r\n\r\n counter = 0;\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < arr.length; i++)\r\n if (arr[i] === eachGcd) divansArray.push(arr[i]);\r\n\r\n function result(el) {\r\n let gcd = 0;\r\n bigNum = 0;\r\n counter = 0;\r\n\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n if (el === arr[i]) {\r\n arr.splice(i, 1);\r\n continue;\r\n }\r\n\r\n counter += gcd_two_numbers(el, arr[i]);\r\n\r\n if (counter > bigNum) {\r\n bigNum = counter;\r\n gcd = arr[i];\r\n }\r\n\r\n if (arr[i] === arr[i - 1]) {\r\n counter = counter;\r\n } else {\r\n counter = 0;\r\n }\r\n }\r\n\r\n return gcd;\r\n }\r\n\r\n for (let i = 0; i <= firstArray; i++) {\r\n result(eachGcd);\r\n\r\n for (let i = 0; i < arr.length; i++)\r\n if (arr[i] === result(eachGcd)) divansArray.push(arr[i]);\r\n\r\n eachGcd = result(eachGcd);\r\n }\r\n\r\n let arrResult = [divansArray[0]];\r\n\r\n for (let i = 0; i < divansArray.length; i++) {\r\n if (i === divansArray.length - 1) continue;\r\n\r\n if (\r\n gcd_two_numbers(divansArray[0], divansArray[i + 1]) === 1 ||\r\n gcd_two_numbers(divansArray[0], divansArray[i - 1]) === 1\r\n ) {\r\n arrResult.push(1);\r\n } else {\r\n arrResult.push(gcd_two_numbers(divansArray[i], divansArray[i + 1]));\r\n }\r\n }\r\n\r\n console.log(arrResult.reduce((a, b) => a + b, 0));\r\n}\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", solve);\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t, n, l, r, k, arr;\r\n\r\n t = parseInt(readline());\r\n while(t--) {\r\n [n, l, r, k] = readline().split(' ').map(x => Number(x));\r\n arr = readline().split(' ').map(x => Number(x));\r\n console.log(solve(n, l, r, k, arr));\r\n }\r\n}\r\n\r\nfunction solve(n, l, r, k, arr) {\r\n let sum = 0, cnt = 0;\r\n arr.sort();\r\n for(let i = 0; i < n; i++) {\r\n if(arr[i] < l || arr[i] > r || sum >= k) continue;\r\n cnt++;\r\n sum += arr[i];\r\n }\r\n return cnt;\r\n}"}], "src_uid": "f577695d39a11e8507681f307677c883"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let i=0; i < test; i++) {\n\t\tlet t = input[i+1].split('');\n\t\tconsole.log(solution(t));\n\t}\n});\n\nfunction solution(t) {\n\tfor (let i = 1; i < t.length; i++) {\n\t\tif (t[i] !== t[i-1]) {\n\t\t\treturn constructString(t.length-1)\n\t\t}\n\t}\n\treturn t.join('');\n}\nfunction constructString(l) {\n\tlet str = '01'\n\tfor (let j = 0; j < l; j++) {\n\t\tstr += '01';\n\t}\n\treturn str;\n}"}, {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n\n const sum = nums.reduce((r, x) => r+x, 0)\n if (sum === 0 || sum === nums.length) {\n console.log(nums.join(''))\n } else {\n let res = ''\n let i = nums[0] === '0' ? 1 : 0\n for (const ch of nums) {\n const awaitingChar = i%2 === 0 ? '1' : '0'\n if (awaitingChar == ch) {\n res += ch\n i+= 1\n } else {\n res += awaitingChar + ch\n i+= 2\n }\n }\n console.log(res)\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(s) {\n let zero = 0;\n let one = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] == 0) zero++;\n else one++;\n }\n if (zero === 0 || one === 0) return s;\n let s1 = s[0];\n for (let i = 1; i < s.length; i++) {\n if (s[i] === s[i - 1]) {\n let insert = s[i] == '1' ? '0' : '1';\n s1 += insert;\n }\n s1 += s[i];\n }\n return s1;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let s = readLine();\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(s);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}], "negative_code": [{"source_code": "var ttt = parseInt(readline());\n\nfunction mapper(s) { return +s; }\n \nfor(var qq = 0; qq < ttt; qq++) {\n var t = readline();\n var tl = t.length;\n \n if (tl <= 2) {\n print(t);\n } else {\n var ch = t[0] === '0' ? '01' : '10';\n var s = ch.repeat(tl);\n print(s);\n }\n}\n"}, {"source_code": "var ttt = parseInt(readline());\n\nfunction mapper(s) { return +s; }\n \nfor(var qq = 0; qq < ttt; qq++) {\n var t = readline();\n var tl = t.length;\n \n if (tl <= 2) {\n print(t);\n } else {\n var p = 0;\n var res = '';\n\n for(var i = 0; i < tl - 2; i++) {\n res += t[i];\n\n if (t[i] !== t[i+2]) {\n res += t[i+2];\n }\n }\n res += t.slice(tl - 2, tl);\n\n print(res);\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\nfunction ceilPow2(n) {\n let x = 0\n while ((1 << x) < n) x++\n return x\n}\n\nclass SegTree {\n constructor(nOrArray, options) {\n const { op, e } = options\n this.op = op\n this.e = e\n const v = Array.isArray(nOrArray) ? nOrArray : Array(nOrArray).fill(0).map(() => e())\n\n const n = v.length\n const log = ceilPow2(n)\n const size = 1 << log\n const d = Array(2 * size)\n this.n = n\n this.log = log\n this.size = size\n this.d = d\n\n for (let i = 0; i < d.length; i++) {\n d[i] = e()\n }\n for (let i = 0; i < n; i++) {\n d[size + i] = v[i]\n }\n for (let i = size - 1; i >= 1; i--) {\n this.update(i)\n }\n }\n set(p, x) {\n p += this.size\n this.d[p] = x\n for (let i = 1; i <= this.log; i++) this.update(p >> i)\n }\n get(p) {\n return this.d[p + this.size]\n }\n prod(l, r) {\n const { size, d, op, e } = this\n let sml = e(), smr = e()\n l += size\n r += size\n\n while (l < r) {\n if (l & 1) sml = op(sml, d[l++])\n if (r & 1) smr = op(d[--r], smr)\n l >>= 1\n r >>= 1\n }\n return op(sml, smr)\n }\n allProd() {\n return this.d[1]\n }\n maxRight(l, f) {\n const { n, size, d, op, e} = this\n if (l == n) return n\n l += size\n let sm = e()\n do {\n while (l % 2 == 0) l >>= 1\n if (!f(op(sm, d[l]))) {\n while (l < size) {\n l = (2 * l)\n if (f(op(sm, d[l]))) {\n sm = op(sm, d[l])\n l++\n }\n }\n return l - size\n }\n sm = op(sm, d[l])\n l++\n } while ((l & -l) != l)\n return n\n }\n minLeft(r, f) {\n if (r == 0) return 0\n const { size, d, op, e} = this\n r += size\n let sm = e()\n do {\n r--\n while (r > 1 && (r % 2)) r >>= 1\n if (!f(op(d[r], sm))) {\n while (r < size) {\n r = (2 * r + 1)\n if (f(op(d[r], sm))) {\n sm = op(d[r], sm)\n r--\n }\n }\n return r + 1 - size\n }\n sm = op(d[r], sm)\n } while ((r & -r) != r)\n return 0\n }\n\n update(k) {\n const { d, op } = this\n d[k] = op(d[2 * k], d[2 * k + 1])\n }\n}\n\nfunction solve(n, arr) {\n let ok = 1\n const map = arr.reduce((o, x) => {\n // o[x] = 1\n o[x] = (o[x] || 0) + 1\n if (o[x] > 1) {\n ok = false\n }\n return o\n }, {})\n if (!ok) return -1\n const dp = Array(n + 1).fill(0)\n for (let i = 1; i <= n; i++) {\n if (!map[i]) {\n dp[i] = 1 // able to be selected\n }\n }\n const s = new SegTree(dp, {\n op: Math.max,\n e: () => -Infinity,\n })\n const r = Array(n)\n let p = n - 1\n for (let i = arr.length - 1; i >= 0; i--) {\n const x = arr[i]\n const j = s.minLeft(x, v => v === 0) - 1\n if (j < 1) return -1\n s.set(j, 0)\n r[p--] = x\n r[p--] = j\n }\n return r.join(' ')\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n const set = new Set(a),\r\n tr = new BinarySearchTree();\r\n if (set.size !== n / 2) return -1;\r\n for (let i = 1; i <= n; i++) {\r\n if (set.has(i)) continue;\r\n tr.insert(i);\r\n }\r\n const res = new Array(n);\r\n for (let i = n - 2; i >= 0; i -= 2) {\r\n res[i + 1] = a[i / 2];\r\n if (tr.getMin() > res[i + 1]) return -1;\r\n let t = tr.floor(res[i + 1]);\r\n tr.delete(t);\r\n res[i] = t;\r\n }\r\n return res.join(' ');\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "c2db558ecf921161ab4da003bd393ec7"} {"source_code": "(function () {\n\tvar line = readline().split(' ').map(function (e) {\n\t\treturn parseInt(e);\n\t});\n\tvar n = line[0],\n\t\tk = line[1];\n\tvar s = readline();\n\t\n\tvar ans1 = getAns(s,k,'a'),\n\t\tans2 = getAns(s,k,'b');\n\tans1 = ans1>ans2?ans1:ans2;\n\tprint(ans1);\n\n\tfunction getAns (str, k, c) {\n\t\tvar p = -1,\n\t\t\tnxt = 0,\n\t\t\tseg = [],\n\t\t\tl = str.length;\n\t\tdo {\n\t\t\tnxt = str.indexOf(c, p+1);\n\t\t\tif(nxt<0)\n\t\t\t\tnxt = l;\n\t\t\tseg.push(nxt - p - 1);\n\t\t\tp = nxt;\n\t\t} while(pret?tmp:ret;\n\t\t}\n\t\treturn ret+k;\n\t}\n\t\n})();", "positive_code": [{"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar bs_removed = {removed: 0};\nvar as_removed = {removed: 0};\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y, z, p) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\n\t\tif (string[i] == z) {\n\t \tp.removed += 1;\n\t }\n\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\na_arr = (rewrite_string(a_arr, a, b, bs_removed)); // removing b's\nb_arr = (rewrite_string(b_arr, b, a, as_removed)); // removing a's\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k <= d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\n// which sum is bigger? and could I remove k letters or did I not have that many to begin with?\nif ((summing(sum_a, a_arr, max_sum_a) < summing(sum_b, b_arr, max_sum_b))) {\n if (as_removed.removed > k) {\n\t print(summing(sum_b, b_arr, max_sum_b) + k);\n } else {\n\t print(summing(sum_b, b_arr, max_sum_b) + as_removed.removed);\n }\n} else {\n if (bs_removed.removed > k) {\n\t print(summing(sum_a, a_arr, max_sum_a) + k);\n } else {\n\t print(summing(sum_a, a_arr, max_sum_a) + bs_removed.removed);\n }\n}\n\n\n\n"}, {"source_code": "var nums = readline().split(\" \").map(x => parseInt(x));\nvar n = nums[0];\nvar k = nums[1];\nvar str = readline();\nprint(solve(n, k, str));\n\nfunction solve(n, k, str) {\n return Math.max(longest(n, k, str, \"a\"), longest(n, k, str, \"b\"));\n}\n\nfunction longest(n, k, str, c) {\n var max = 0;\n var p = 0;\n for (var i = 0; i < n; i++) {\n if (str[i] !== c) {\n k -= 1;\n }\n while (k < 0) {\n if (str[p] !== c) {\n k += 1;\n }\n p += 1;\n }\n max = Math.max(max, i - p + 1);\n }\n return max;\n}"}, {"source_code": "function main() {\n var input = readline().split(' ').map(Number);\n var n = input[0];\n var k = input[1];\n var str = readline();\n \n var prefixSum = [];\n for (var i = 0; i < n; ++i) {\n var value = (str.charAt(i) == \"a\" ? 1 : 0);\n if (i > 0) {\n value += prefixSum[i - 1];\n }\n prefixSum.push(value);\n }\n \n function rangeSum(prefixSum, st, ed) {\n if (st > 0) {\n return prefixSum[ed] - prefixSum[st - 1];\n } else {\n return prefixSum[ed];\n }\n }\n \n function check(prefixSum, n, k, m) {\n for (var i = 0; i < n; ++i) {\n var numOfA = rangeSum(prefixSum, i, i + m - 1);\n var numOfB = m - numOfA;\n if (Math.min(numOfA, numOfB) <= k) {\n return true;\n }\n }\n return false;\n }\n \n function binarySearch(prefixSum, n, k) {\n var lower = 1;\n var upper = n;\n while (upper - lower > 1) {\n var middle = Math.floor((lower + upper) / 2);\n if (check(prefixSum, n, k, middle)) {\n lower = middle;\n } else {\n upper = middle;\n }\n }\n return check(prefixSum, n, k, upper) ? upper : lower;\n }\n \n var result = binarySearch(prefixSum, n, k);\n print(result);\n}\n\nmain();"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar bs_removed = {removed: 0};\nvar as_removed = {removed: 0};\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(new_array, letter_in_array, letter_removed, number_of_letters_removed) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t new_array[j] = 0;\n\n\t\twhile (string[i] == letter_in_array) {\n\t\t\tnew_array[j] += 1;\n\t\t\ti++;\n\t\t}\n\n\t\tif (string[i] == letter_removed) {\n\t \tnumber_of_letters_removed.removed += 1;\n\t }\n\n\t\tj++;\n\t}\n\n\treturn new_array;\n};\n\na_arr = (rewrite_string(a_arr, a, b, bs_removed)); // removing b's\nb_arr = (rewrite_string(b_arr, b, a, as_removed)); // removing a's\n\nvar max_sum_a = 0;\nvar max_sum_b = 0;\n\nvar summing = function(array, letters_removed) {\n\tvar sum = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < array.length; i++) {\n\t\tsum += array[i];\n\t}\n\n\tvar max_sum = sum;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i + k <= array.length - 1; i++) {\n\t\tsum += array[i + k] - array[i - 1];\n \tif (sum > max_sum) {\n \t\tmax_sum = sum;\n \t}\n\t}\n\n\tmax_sum += Math.min(k, letters_removed.removed);\n\n\treturn max_sum;\n};\n\nmax_sum_a = summing(a_arr, bs_removed);\nmax_sum_b = summing(b_arr, as_removed);\n\nprint(Math.max(max_sum_a, max_sum_b));\n\n\n\n"}], "negative_code": [{"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k < d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\nvar remove_b = summing(sum_a, a_arr, max_sum_a);\nvar remove_a = summing(sum_b, b_arr, max_sum_b);\n\nprint(Math.max(remove_b, remove_a) + k);\n\n"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k < d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\nprint(Math.max(summing(sum_a, a_arr, max_sum_a), summing(sum_b, b_arr, max_sum_b)));\n\n\n\n/* Sums for a_arr, not using this because I wrote a function\nvar sum_a = 0;\n\n// First sum\nfor (var i = 0; i <= k; i++) {\n\tsum_a += a_arr[i];\n}\n\nvar max_sum_a = sum_a;\n\n// Checking if other sums are bigger\nfor (var i = 1; i < a_arr.length; i++) {\n\tsum_a += a_arr[i + k] - a_arr[i - 1];\n\tif (sum_a > max_sum_a) {\n\t\tmax_sum_a = sum_a;\n\t}\n}\n\nprint(max_sum_a);\n*/\n\n"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar bs_removed = {removed: 0};\nvar as_removed = {removed: 0};\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y, z, p) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\n\t\tif (string[i] == z) {\n\t \tp.removed += 1;\n\t }\n\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\na_arr = (rewrite_string(a_arr, a, b, bs_removed)); // removing b's\nb_arr = (rewrite_string(b_arr, b, a, as_removed)); // removing a's\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k < d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\n// which sum is bigger? and could I remove k letters or did I not have that many to begin with?\nif ((summing(sum_a, a_arr, max_sum_a) < summing(sum_b, b_arr, max_sum_b))) {\n if (as_removed.removed > k) {\n\t print(summing(sum_b, b_arr, max_sum_b) + k);\n } else {\n\t print(summing(sum_b, b_arr, max_sum_b) + as_removed.removed);\n }\n} else {\n if (bs_removed.removed > k) {\n\t print(summing(sum_a, a_arr, max_sum_a) + k);\n } else {\n\t print(summing(sum_a, a_arr, max_sum_a) + bs_removed.removed);\n }\n}\n\n\n\n"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\na_arr = (rewrite_string(a_arr, a));\nb_arr = (rewrite_string(b_arr, b));\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k < d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\nif (string.length == 1) {\n\tprint(1);\n} else {\n\tprint(Math.max(summing(sum_a, a_arr, max_sum_a), summing(sum_b, b_arr, max_sum_b)) + k);\n}\n"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t\tc += d[i + k] - d[i - 1];\n\t\tif (c > e) {\n\t\t\te = c;\n\t\t}\n\t}\n\n\treturn e;\n};\n\nprint(Math.max(summing(sum_a, a_arr, max_sum_a), summing(sum_b, b_arr, max_sum_b)));\n\n\n\n/* Sums for a_arr, not using this because I wrote a function\nvar sum_a = 0;\n\n// First sum\nfor (var i = 0; i <= k; i++) {\n\tsum_a += a_arr[i];\n}\n\nvar max_sum_a = sum_a;\n\n// Checking if other sums are bigger\nfor (var i = 1; i < a_arr.length; i++) {\n\tsum_a += a_arr[i + k] - a_arr[i - 1];\n\tif (sum_a > max_sum_a) {\n\t\tmax_sum_a = sum_a;\n\t}\n}\n\nprint(max_sum_a);\n*/\n\n"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar string = readline().split('').map(String);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar a_arr = [];\nvar b_arr = [];\nvar a = \"a\";\nvar b = \"b\";\n\nvar rewrite_string = function(x, y) {\n\tvar count = 0;\n\tvar j = 0;\n\n\tfor (var i = 0; i < n; i++) {\n\t x[j] = 0;\n\t\twhile (string[i] == y) {\n\t\t\tx[j] += 1;\n\t\t\ti++;\n\t\t}\n\t\tj++;\n\t}\n\n\treturn x;\n};\n\na_arr = (rewrite_string(a_arr, a));\nb_arr = (rewrite_string(b_arr, b));\n\nvar sum_a = 0;\nvar max_sum_a = 0;\nvar sum_b = 0;\nvar max_sum_b = 0;\n\nvar summing = function(c, d, e) {\n\tc = 0;\n\n\t// First sum\n\tfor (var i = 0; i <= k && i < d.length; i++) {\n\t\tc += d[i];\n\t}\n\n\te = c;\n\n\t// Checking if other sums are bigger\n\tfor (var i = 1; i < d.length; i++) {\n\t if (i + k < d.length - 1) {\n \t\tc += d[i + k] - d[i - 1];\n \t\tif (c > e) {\n \t\t\te = c;\n \t\t}\n\t\t}\n\t}\n\n\treturn e;\n};\n\nprint(Math.max(summing(sum_a, a_arr, max_sum_a), summing(sum_b, b_arr, max_sum_b)) + k);\n"}, {"source_code": "var nums = readline().split(\" \").map(x => parseInt(x));\nvar n = nums[0];\nvar k = nums[1];\nvar str = readline();\nprint(solve(n, k, str));\n\nfunction solve(n, k, str) {\n return Math.max(longest(n, k, str, \"a\"), longest(n, k, str, \"b\"));\n}\n\nfunction longest(n, k, str, c) {\n var max = 0;\n var p = 0;\n for (var i = 0; i < n; i++) {\n if (str[i] !== c) {\n k -= 1;\n }\n while (k < 0) {\n if (str[p] !== c) {\n k += 1;\n }\n p += 1;\n }\n max = Math.max(max, i - p);\n }\n return max;\n}"}], "src_uid": "0151a87d0f82a9044a0ac8731d369bb9"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, k, str) {\r\n let count = new Array(n).fill(0);\r\n\r\n if (k & 1) {\r\n let t = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (str[i]) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n\r\n if (t === -1) t = str.length - 1;\r\n str = str.map((num, i) => i === t ? num : num ^ 1);\r\n count[t]++;\r\n k--;\r\n }\r\n\r\n for (let i = 0; k && i < n; i++) {\r\n if (!str[i]) {\r\n str[i] = 1;\r\n k--;\r\n count[i] += 1;\r\n }\r\n }\r\n\r\n count[count.length - 1] += k;\r\n if (k % 2 === 1) str[str.length - 1] = 0;\r\n console.log(str.join(''));\r\n console.log(count.join(' '));\r\n}\r\n/**\r\n * 100001\r\n * 111110\r\n * 000000 000101\r\n * 111110 111110\r\n *\r\n * 101100\r\n * 110011\r\n * 001000\r\n * 111111\r\n * 000001\r\n * 111111\r\n *\r\n * 0110000\r\n * 0001111\r\n * 1111000\r\n * 0000011\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n *\r\n *\r\n * 101111001100\r\n * 110000110011\r\n * 000111001100\r\n * 111100110011\r\n * 000001001100\r\n * 111111110011\r\n *\r\n */\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, k] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const str = inputs[__ * 2 + 2].trim().split('').map(Number);\r\n solve(n, k, str);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr1();\r\n let res = new Array(n).fill(0);\r\n if (k % 2 === 1) {\r\n let flag = 0;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] === 0) arr[i] = 1;\r\n else if (arr[i] === 1 && flag === 0) {\r\n res[i]++;\r\n flag = 1;\r\n } else arr[i] = 0;\r\n }\r\n if (flag === 1) arr[n - 1] = arr[n - 1] === 0 ? 1 : 0;\r\n else res[n-1]++;\r\n k--;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (i === n - 1 && k > 0) {\r\n if (k % 2 !== 0) arr[i] = arr[i] === 0 ? 1 : 0;\r\n res[i] += k;\r\n } else if (arr[i] === 0 && k > 0) {\r\n arr[i] = 1;\r\n res[i]++;\r\n k--;\r\n }\r\n }\r\n console.log(arr.join(\"\"));\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet k;\r\nlet s;\r\nfunction solve() {\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = (s[i] == '1' ? 1 : 0);\r\n }\r\n // printf(\"n %d k %d s %s a %j\\n\", n, k, s, a);\r\n const K = k;\r\n const ans = af(n).fill(0);\r\n const keven = ((k % 2) == 0 ? true : false);\r\n for (let i = 0; i + 1 < n && k > 0; i++) {\r\n if (keven && a[i] == 0) {\r\n ans[i]++;\r\n k--;\r\n }\r\n else if (!keven && a[i] == 1) {\r\n ans[i]++;\r\n k--;\r\n }\r\n }\r\n ans[n - 1] = k;\r\n const b = af(n);\r\n for (let i = 0; i < n; i++) {\r\n b[i] = (a[i] + ans[i] + K) % 2;\r\n // printf(\"%d\", (a[i] + ans[i] + K) % 2), ' ');\r\n }\r\n process.stdout.write(b.join(''));\r\n process.stdout.write('\\n');\r\n process.stdout.write(ans.join(' '));\r\n process.stdout.write('\\n');\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc--) {\r\n n = nextInt();\r\n k = nextInt();\r\n s = nextStr();\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, k, bits)=>{\n let usage = new Array(n).fill(0);\n let originalK = k;\n\n let flipped = 0;\n\n for (let i = 0; i < n; i++) {\n let flips = k % 2;\n let res = bits[i] ^ flipped ^ flips;\n if (!res && k) {\n k--;\n usage[i]++;\n flipped = 1 - flipped;\n }\n }\n usage[n - 1] += k;\n\n for (let i = 0; i < n; i++) {\n let flips = (originalK - usage[i]) % 2;\n bits[i] = bits[i] ^ flips;\n }\n\n return `${bits.join('')}\\n${usage.join(' ')}`;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, k] = ra();\n let bits = readline().split('').map(a=>+a);\n console.log(`${calc(n, k, bits)}`);\n }\n}\n\n\n\n"}, {"source_code": "\n\nconst processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n let [_, k] = lines[cur].split(' ').map(x => +x)\n cur++\n let str = lines[cur].split('').map(x => +x)\n\n let xor = k%2;\n for (let i=0; i 0; i++) {\n if (str[i] === 0) {\n k--;\n str[i] = 1;\n res[i] = 1;\n }\n }\n \n if (k) {\n if (k%2 === 0) {\n res[0] += k;\n } else {\n res[res.length-1] += k;\n str[str.length-1] ^= 1;;\n }\n }\n console.log(str.join(''));\n console.log(res.join(' '))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, k, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, str) {\n const ans = Array(n).fill(0)\n const final = str.split('')\n let used = 0\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]\n let x\n // flip k - x\n if (ch === '1') {\n // k - x is even\n if (k & 1) {\n x = 1\n } else {\n x = 0\n }\n } else {\n // k - x is odd\n if (k & 1) {\n x = 0\n } else {\n x = 1\n }\n }\n //\n if (used >= k) x = 0\n if (i === n - 1) x = k - used\n ans[i] = x\n used += x\n //\n if ((k - x) & 1) {\n final[i] = ch === '1' ? '0' : '1'\n // } else {\n // final = ch\n }\n }\n return final.join('') + '\\n' + ans.join(' ')\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, k, str) {\r\n let count = new Array(n).fill(0);\r\n\r\n if (k & 1) {\r\n let t = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (str[i]) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n\r\n str = str.map((num, i) => i === t ? num : num ^ 1);\r\n count[t]++;\r\n k--;\r\n }\r\n\r\n for (let i = 0; k && i < n; i++) {\r\n if (!str[i]) {\r\n str[i] = 1;\r\n k -= 1;\r\n count[i] += 1;\r\n }\r\n }\r\n\r\n count[count.length - 1] += k;\r\n if (k % 2 === 1) str[str.length - 1] = 0;\r\n console.log(str.join(''));\r\n console.log(count.join(' '));\r\n}\r\n/**\r\n * 100001\r\n * 111110\r\n * 000000 000101\r\n * 111110 111110\r\n *\r\n * 101100\r\n * 110011\r\n * 001000\r\n * 111111\r\n * 000001\r\n * 111111\r\n *\r\n * 0110000\r\n * 0001111\r\n * 1111000\r\n * 0000011\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n *\r\n *\r\n * 101111001100\r\n * 110000110011\r\n * 000111001100\r\n * 111100110011\r\n * 000001001100\r\n * 111111110011\r\n *\r\n */\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, k] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const str = inputs[__ * 2 + 2].trim().split('').map(Number);\r\n solve(n, k, str);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, k, str) {\r\n let count = new Array(n).fill(0);\r\n\r\n if (k & 1) {\r\n let t = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (str[i]) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n\r\n str = str.map((num, i) => i === t ? num : num ^ 1);\r\n count[t]++;\r\n k--;\r\n }\r\n\r\n for (let i = 0; k && i < n; i++) {\r\n if (!str[i]) {\r\n str[i] = 1;\r\n k -= 1;\r\n count[i] += 1;\r\n }\r\n }\r\n\r\n count[count.length - 1] += k;\r\n if (k & 1) str[str.length - 1] = 0;\r\n console.log(str.join(''));\r\n console.log(count.join(' '));\r\n}\r\n/**\r\n * 100001\r\n * 111110\r\n * 000000 000101\r\n * 111110 111110\r\n *\r\n * 101100\r\n * 110011\r\n * 001000\r\n * 111111\r\n * 000001\r\n * 111111\r\n *\r\n * 0110000\r\n * 0001111\r\n * 1111000\r\n * 0000011\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n *\r\n *\r\n * 101111001100\r\n * 110000110011\r\n * 000111001100\r\n * 111100110011\r\n * 000001001100\r\n * 111111110011\r\n *\r\n */\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, k] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const str = inputs[__ * 2 + 2].trim().split('').map(Number);\r\n solve(n, k, str);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, k, str) {\r\n let count = new Array(n).fill(0);\r\n\r\n if (k & 1) {\r\n let t = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (str[i]) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n\r\n str = str.map((num, i) => i === t ? num : num ^ 1);\r\n count[t]++;\r\n k--;\r\n }\r\n\r\n str.filter(Boolean);\r\n\r\n for (let i = 0; k && i < n; i++) {\r\n if (!str[i]) {\r\n str[i] = 1;\r\n k -= 1;\r\n count[i] += 1;\r\n }\r\n }\r\n\r\n count[count.length - 1] += k;\r\n if (k & 1) str[str.length - 1] = 0;\r\n console.log(str.join(''));\r\n console.log(count.join(' '));\r\n}\r\n/**\r\n * 100001\r\n * 111110\r\n * 000000 000101\r\n * 111110 111110\r\n *\r\n * 101100\r\n * 110011\r\n * 001000\r\n * 111111\r\n * 000001\r\n * 111111\r\n *\r\n * 0110000\r\n * 0001111\r\n * 1111000\r\n * 0000011\r\n * 1111110\r\n * 0000000\r\n * 1111111\r\n * 0000000\r\n * 1111111\r\n *\r\n *\r\n * 101111001100\r\n * 110000110011\r\n * 000111001100\r\n * 111100110011\r\n * 000001001100\r\n * 111111110011\r\n *\r\n */\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, k] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const str = inputs[__ * 2 + 2].trim().split('').map(Number);\r\n solve(n, k, str);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr1();\r\n let res = new Array(n).fill(0);\r\n if (k % 2 === 1) {\r\n let flag = 0;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] === 0) arr[i] = 1;\r\n else if (arr[i] === 1 && flag === 0) {\r\n flag = 1;\r\n } else arr[i] = 0;\r\n }\r\n if (flag === 1) arr[n - 1] = arr[n - 1] === 0 ? 1 : 0;\r\n k--;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (i === n - 1 && k > 0) {\r\n if (k % 2 !== 0) arr[i] = arr[i] === 0 ? 1 : 0;\r\n res[i] += k;\r\n } else if (arr[i] === 0 && k > 0) {\r\n arr[i] = 1;\r\n res[i]++;\r\n k--;\r\n }\r\n }\r\n console.log(arr.join(\"\"));\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "38375efafa4861f3443126f20cacf3ae"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction readInt() {\n return readline()|0\n}\n \nfunction readIntArr() {\n return readline().split(' ').map(x => x|0)\n}\n \n \nfunction main() {\n const n = readInt();\n\n for(let i=0; i < n; i++) {\n let [a, b] = readIntArr();\n let phase = 1;\n if(b === 1) {\n phase = 2;\n }\n\n const func = () => {\n for(let i = 1; i <= phase; i++) {\n if (((b + phase) - i)**(i) > a) return false;\n }\n\n return true;\n }\n\n while (func()) {\n phase++;\n }\n\n console.log(phase);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (k > n) console.log(1);\r\n else if (n === k) console.log(2);\r\n else {\r\n const red = (n, k) => {\r\n let cnt = 0;\r\n while (n > 0) {\r\n n = Math.floor(n / k);\r\n cnt++;\r\n }\r\n return cnt;\r\n };\r\n let cnt = 0;\r\n if (k === 1) {\r\n k++;\r\n cnt++;\r\n }\r\n let prev = red(n, k) + cnt;\r\n while (true) {\r\n k++;\r\n cnt++;\r\n let l = red(n, k) + cnt;\r\n if (prev < l) {\r\n console.log(prev);\r\n break;\r\n } else prev = l;\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar add = 0;\r\n\t\tif(B == 1){\r\n\t\t\tadd = 1;\r\n\t\t\tB++;\r\n\t\t}\r\n\t\tvar now = B;\r\n\t\tvar output = Math.pow(10, 15);\r\n\t\twhile(true){\r\n\t\t\tvar tmp = A;\r\n\t\t\tvar count = now - B;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tcount++;\r\n\t\t\t\ttmp = Math.floor(tmp / now);\r\n\t\t\t}\r\n\t\t\tif(output >= count){\r\n\t\t\t\toutput = count;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tnow++;\r\n\t\t}\r\n\t\tmyout(output + add);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readInt() {\r\n return readline()|0\r\n}\r\n\r\nfunction readIntArr() {\r\n return readline().split(' ').map(x => x|0)\r\n}\r\n\r\n\r\nfunction main() {\r\n const N = readInt()\r\n for (let i = 0; i < N; ++i) {\r\n let total = 1\r\n let c = 0\r\n let [a, b] = readIntArr()\r\n if (b == 1) {\r\n b += 1\r\n c = 1\r\n }\r\n\r\n function found(a, b, total) {\r\n let fo = false\r\n for (let i = 0; i < total; i++) {\r\n if (((b + i) ** (total - i) > a)) {\r\n fo = true;\r\n }\r\n }\r\n return fo\r\n }\r\n \r\n while (!found(a, b, total)) {\r\n total += 1\r\n }\r\n console.log(total + c)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n\r\n var answer = {}\r\n\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [a, b] = readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n return parseInt(x)\r\n })\r\n var min = 100000000\r\n var bb\r\n var aa\r\n if (a < b) return console.log(1)\r\n\r\n for (var i = 0; i < 1000; i++) {\r\n aa = a\r\n answer = i\r\n bb = b + i\r\n if (bb === 1) continue\r\n\r\n while (aa !== 0) {\r\n aa = Math.floor(aa / bb)\r\n answer += 1\r\n }\r\n // console.log(a,bb, answer)\r\n\r\n // console.log(min)\r\n min = Math.min(min, answer)\r\n }\r\n console.log(min)\r\n // console.log(Math.min(answer, answer2))\r\n\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readInt() {\r\n return readline()|0\r\n}\r\n\r\nfunction readIntArr() {\r\n return readline().split(' ').map(x => x|0)\r\n}\r\n\r\n\r\nfunction main() {\r\n const N = readInt()\r\n for (let i = 0; i < N; ++i) {\r\n let total = 1\r\n let c = 0\r\n let [a, b] = readIntArr()\r\n if (b == 1) {\r\n b += 1\r\n c = 1\r\n }\r\n while (b ** total <= a && (b + 1) ** (total - 1) <= a && (b + 2) ** (total - 2) <= a) {\r\n total += 1\r\n }\r\n console.log(total + c)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readInt() {\r\n return readline()|0\r\n}\r\n\r\nfunction readIntArr() {\r\n return readline().split(' ').map(x => x|0)\r\n}\r\n\r\n\r\nfunction main() {\r\n const N = readInt()\r\n for (let i = 0; i < N; ++i) {\r\n let total = 1\r\n let c = 0\r\n let [a, b] = readIntArr()\r\n if (b == 1) {\r\n b += 1\r\n c = 1\r\n }\r\n while (b ** total < a && (b + 1) ** (total - 1) < a && (b + 2) ** (total - 2) < a) {\r\n total += 1\r\n }\r\n console.log(total + c)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n\r\n var answer = {}\r\n\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [a, b] = readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n return parseInt(x)\r\n })\r\n var min = 100000000\r\n var bb\r\n var aa\r\n if (a < b) return console.log(1)\r\n\r\n for (var i = 0; i < 5; i++) {\r\n aa = a\r\n answer = i\r\n bb = b + i\r\n if (bb === 1) continue\r\n\r\n while (aa !== 0) {\r\n aa = Math.floor(aa / bb)\r\n answer += 1\r\n }\r\n // console.log(a,bb, answer)\r\n\r\n // console.log(min)\r\n min = Math.min(min, answer)\r\n }\r\n console.log(min)\r\n // console.log(Math.min(answer, answer2))\r\n\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n\r\n var answer = {}\r\n\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [a, b] = readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n return parseInt(x)\r\n })\r\n var answer = 0\r\n var answer2 = 0\r\n if (a < b) return console.log(1)\r\n if(b===1) {\r\n answer = 1\r\n answer2 = 2\r\n b = 2\r\n }\r\n // console.log(b,a)\r\n\r\n var bb = b +1\r\n var aa = a\r\n while(a!==0){\r\n a=Math.floor(a/b)\r\n answer+=1\r\n }\r\n\r\n while(aa!==0){\r\n aa=Math.floor(aa/bb)\r\n answer2+=1\r\n }\r\n console.log(Math.min(answer, answer2))\r\n\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n for (let i = 1; i <= 10000; i++) obj[i * i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (k > n) console.log(1);\r\n else {\r\n if (n === k) console.log(2);\r\n else {\r\n let cnt = 0;\r\n if (n % k === 0) {\r\n k += 2;\r\n cnt += 2;\r\n }\r\n while (n > 0) {\r\n cnt++;\r\n n = Math.floor(n / k);\r\n }\r\n console.log(cnt);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "2b757fa66ce89046fe18cdfdeafa6660"} {"source_code": "var numRun= readline();\n \nfor(var n=0;n {\n const stdin = readline.createInterface(process.stdin);\n let tests = null;\n let n = null;\n stdin.on('line', line => {\n if (tests === null) {\n tests = +line;\n } else if (n === null) {\n n = +line;\n tests--;\n } else {\n n = null;\n subscribe.next(line);\n\n if (tests === 0) {\n stdin.close();\n subscribe.complete();\n }\n }\n });\n });\n}\n\nfunction isHappy(arr) {\n if (arr[0] <= 0 || arr[arr.length - 1] <= 0) {\n return 'NO';\n }\n\n let sum = 0;\n\n for (let x = 0; x < arr.length - 1; x++) {\n sum += arr[x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n sum = 0;\n\n for (let x = arr.length - 1; x > 0; x--) {\n sum += arr[x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n return 'YES';\n}\n\ntnLineStdinReader().subscribe(input => {\n const arr = input.split(' ').map(i => +i);\n console.log(isHappy(arr));\n});\n"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\n\nfunction calc (arr) {\n let max_so_far = Number.MIN_SAFE_INTEGER\n let max_here = 0\n \n for (let i = 0; i + 1 < arr.length; ++i) {\n max_here += arr[i]\n \n if (max_here < 0) {\n max_here = 0\n }\n \n if (max_so_far < max_here) {\n max_so_far = max_here\n }\n }\n return max_so_far\n}\n\nwhile (t --> 0) {\n const n = readline()\n const arr = readline().split(' ').map(function(x) {\n return parseInt(x)\n })\n\n let whole = 0\n for (let i in arr) whole += arr[i]\n \n let a = calc(arr)\n let b = calc(arr.reverse())\n\n let mx = Math.max(a, b)\n let ok = whole > mx\n\n print(ok ? 'YES': 'NO')\n}"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\n// function print(item) {\n// console.log(item);\n// }\n\nfunction maxSubArraySum(array_of_numbers, init_value, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = init_value; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n var cupcakes_count = parseInt(readline(), 10);\n var cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n var total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n var result_begin = maxSubArraySum(cupcakes_taste, 0, cupcakes_count - 1);\n var result_end = maxSubArraySum(cupcakes_taste, 1, cupcakes_count);\n \n if (total_taste > Math.max(result_begin.max_so_far, result_end.max_so_far)) {\n print('YES');\n } else {\n print('NO');\n }\n }\n}\n\nmain();"}], "negative_code": [{"source_code": "'use strict';\n\nvar readline = require('readline');\n\n/*! *****************************************************************************\nCopyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0\n\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\nMERCHANTABLITY OR NON-INFRINGEMENT.\n\nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\n/* global Reflect, Promise */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nfunction __extends(d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isFunction(x) {\n return typeof x === 'function';\n}\n//# sourceMappingURL=isFunction.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar _enable_super_gross_mode_that_will_cause_bad_things = false;\nvar config = {\n Promise: undefined,\n set useDeprecatedSynchronousErrorHandling(value) {\n if (value) {\n var error = /*@__PURE__*/ new Error();\n /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \\n' + error.stack);\n }\n _enable_super_gross_mode_that_will_cause_bad_things = value;\n },\n get useDeprecatedSynchronousErrorHandling() {\n return _enable_super_gross_mode_that_will_cause_bad_things;\n },\n};\n//# sourceMappingURL=config.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction hostReportError(err) {\n setTimeout(function () { throw err; }, 0);\n}\n//# sourceMappingURL=hostReportError.js.map\n\n/** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */\nvar empty = {\n closed: true,\n next: function (value) { },\n error: function (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n },\n complete: function () { }\n};\n//# sourceMappingURL=Observer.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();\n//# sourceMappingURL=isArray.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isObject(x) {\n return x !== null && typeof x === 'object';\n}\n//# sourceMappingURL=isObject.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {\n function UnsubscriptionErrorImpl(errors) {\n Error.call(this);\n this.message = errors ?\n errors.length + \" errors occurred during unsubscription:\\n\" + errors.map(function (err, i) { return i + 1 + \") \" + err.toString(); }).join('\\n ') : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n return this;\n }\n UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return UnsubscriptionErrorImpl;\n})();\nvar UnsubscriptionError = UnsubscriptionErrorImpl;\n//# sourceMappingURL=UnsubscriptionError.js.map\n\n/** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */\nvar Subscription = /*@__PURE__*/ (function () {\n function Subscription(unsubscribe) {\n this.closed = false;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (unsubscribe) {\n this._unsubscribe = unsubscribe;\n }\n }\n Subscription.prototype.unsubscribe = function () {\n var errors;\n if (this.closed) {\n return;\n }\n var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;\n this.closed = true;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (_parentOrParents instanceof Subscription) {\n _parentOrParents.remove(this);\n }\n else if (_parentOrParents !== null) {\n for (var index = 0; index < _parentOrParents.length; ++index) {\n var parent_1 = _parentOrParents[index];\n parent_1.remove(this);\n }\n }\n if (isFunction(_unsubscribe)) {\n try {\n _unsubscribe.call(this);\n }\n catch (e) {\n errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];\n }\n }\n if (isArray(_subscriptions)) {\n var index = -1;\n var len = _subscriptions.length;\n while (++index < len) {\n var sub = _subscriptions[index];\n if (isObject(sub)) {\n try {\n sub.unsubscribe();\n }\n catch (e) {\n errors = errors || [];\n if (e instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(e.errors));\n }\n else {\n errors.push(e);\n }\n }\n }\n }\n }\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n };\n Subscription.prototype.add = function (teardown) {\n var subscription = teardown;\n if (!teardown) {\n return Subscription.EMPTY;\n }\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(teardown);\n case 'object':\n if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {\n return subscription;\n }\n else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n }\n else if (!(subscription instanceof Subscription)) {\n var tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default: {\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n }\n var _parentOrParents = subscription._parentOrParents;\n if (_parentOrParents === null) {\n subscription._parentOrParents = this;\n }\n else if (_parentOrParents instanceof Subscription) {\n if (_parentOrParents === this) {\n return subscription;\n }\n subscription._parentOrParents = [_parentOrParents, this];\n }\n else if (_parentOrParents.indexOf(this) === -1) {\n _parentOrParents.push(this);\n }\n else {\n return subscription;\n }\n var subscriptions = this._subscriptions;\n if (subscriptions === null) {\n this._subscriptions = [subscription];\n }\n else {\n subscriptions.push(subscription);\n }\n return subscription;\n };\n Subscription.prototype.remove = function (subscription) {\n var subscriptions = this._subscriptions;\n if (subscriptions) {\n var subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n };\n Subscription.EMPTY = (function (empty) {\n empty.closed = true;\n return empty;\n }(new Subscription()));\n return Subscription;\n}());\nfunction flattenUnsubscriptionErrors(errors) {\n return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);\n}\n//# sourceMappingURL=Subscription.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar rxSubscriber = /*@__PURE__*/ (function () {\n return typeof Symbol === 'function'\n ? /*@__PURE__*/ Symbol('rxSubscriber')\n : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();\n})();\n//# sourceMappingURL=rxSubscriber.js.map\n\n/** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */\nvar Subscriber = /*@__PURE__*/ (function (_super) {\n __extends(Subscriber, _super);\n function Subscriber(destinationOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this.syncErrorValue = null;\n _this.syncErrorThrown = false;\n _this.syncErrorThrowable = false;\n _this.isStopped = false;\n switch (arguments.length) {\n case 0:\n _this.destination = empty;\n break;\n case 1:\n if (!destinationOrNext) {\n _this.destination = empty;\n break;\n }\n if (typeof destinationOrNext === 'object') {\n if (destinationOrNext instanceof Subscriber) {\n _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;\n _this.destination = destinationOrNext;\n destinationOrNext.add(_this);\n }\n else {\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext);\n }\n break;\n }\n default:\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);\n break;\n }\n return _this;\n }\n Subscriber.prototype[rxSubscriber] = function () { return this; };\n Subscriber.create = function (next, error, complete) {\n var subscriber = new Subscriber(next, error, complete);\n subscriber.syncErrorThrowable = false;\n return subscriber;\n };\n Subscriber.prototype.next = function (value) {\n if (!this.isStopped) {\n this._next(value);\n }\n };\n Subscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n this.isStopped = true;\n this._error(err);\n }\n };\n Subscriber.prototype.complete = function () {\n if (!this.isStopped) {\n this.isStopped = true;\n this._complete();\n }\n };\n Subscriber.prototype.unsubscribe = function () {\n if (this.closed) {\n return;\n }\n this.isStopped = true;\n _super.prototype.unsubscribe.call(this);\n };\n Subscriber.prototype._next = function (value) {\n this.destination.next(value);\n };\n Subscriber.prototype._error = function (err) {\n this.destination.error(err);\n this.unsubscribe();\n };\n Subscriber.prototype._complete = function () {\n this.destination.complete();\n this.unsubscribe();\n };\n Subscriber.prototype._unsubscribeAndRecycle = function () {\n var _parentOrParents = this._parentOrParents;\n this._parentOrParents = null;\n this.unsubscribe();\n this.closed = false;\n this.isStopped = false;\n this._parentOrParents = _parentOrParents;\n return this;\n };\n return Subscriber;\n}(Subscription));\nvar SafeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SafeSubscriber, _super);\n function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this._parentSubscriber = _parentSubscriber;\n var next;\n var context = _this;\n if (isFunction(observerOrNext)) {\n next = observerOrNext;\n }\n else if (observerOrNext) {\n next = observerOrNext.next;\n error = observerOrNext.error;\n complete = observerOrNext.complete;\n if (observerOrNext !== empty) {\n context = Object.create(observerOrNext);\n if (isFunction(context.unsubscribe)) {\n _this.add(context.unsubscribe.bind(context));\n }\n context.unsubscribe = _this.unsubscribe.bind(_this);\n }\n }\n _this._context = context;\n _this._next = next;\n _this._error = error;\n _this._complete = complete;\n return _this;\n }\n SafeSubscriber.prototype.next = function (value) {\n if (!this.isStopped && this._next) {\n var _parentSubscriber = this._parentSubscriber;\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._next, value);\n }\n else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;\n if (this._error) {\n if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._error, err);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, this._error, err);\n this.unsubscribe();\n }\n }\n else if (!_parentSubscriber.syncErrorThrowable) {\n this.unsubscribe();\n if (useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n hostReportError(err);\n }\n else {\n if (useDeprecatedSynchronousErrorHandling) {\n _parentSubscriber.syncErrorValue = err;\n _parentSubscriber.syncErrorThrown = true;\n }\n else {\n hostReportError(err);\n }\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.complete = function () {\n var _this = this;\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n if (this._complete) {\n var wrappedComplete = function () { return _this._complete.call(_this._context); };\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(wrappedComplete);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, wrappedComplete);\n this.unsubscribe();\n }\n }\n else {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n this.unsubscribe();\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n }\n };\n SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {\n if (!config.useDeprecatedSynchronousErrorHandling) {\n throw new Error('bad call');\n }\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n parent.syncErrorValue = err;\n parent.syncErrorThrown = true;\n return true;\n }\n else {\n hostReportError(err);\n return true;\n }\n }\n return false;\n };\n SafeSubscriber.prototype._unsubscribe = function () {\n var _parentSubscriber = this._parentSubscriber;\n this._context = null;\n this._parentSubscriber = null;\n _parentSubscriber.unsubscribe();\n };\n return SafeSubscriber;\n}(Subscriber));\n//# sourceMappingURL=Subscriber.js.map\n\n/** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */\nfunction canReportError(observer) {\n while (observer) {\n var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;\n if (closed_1 || isStopped) {\n return false;\n }\n else if (destination && destination instanceof Subscriber) {\n observer = destination;\n }\n else {\n observer = null;\n }\n }\n return true;\n}\n//# sourceMappingURL=canReportError.js.map\n\n/** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */\nfunction toSubscriber(nextOrObserver, error, complete) {\n if (nextOrObserver) {\n if (nextOrObserver instanceof Subscriber) {\n return nextOrObserver;\n }\n if (nextOrObserver[rxSubscriber]) {\n return nextOrObserver[rxSubscriber]();\n }\n }\n if (!nextOrObserver && !error && !complete) {\n return new Subscriber(empty);\n }\n return new Subscriber(nextOrObserver, error, complete);\n}\n//# sourceMappingURL=toSubscriber.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();\n//# sourceMappingURL=observable.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction noop() { }\n//# sourceMappingURL=noop.js.map\n\n/** PURE_IMPORTS_START _noop PURE_IMPORTS_END */\nfunction pipeFromArray(fns) {\n if (!fns) {\n return noop;\n }\n if (fns.length === 1) {\n return fns[0];\n }\n return function piped(input) {\n return fns.reduce(function (prev, fn) { return fn(prev); }, input);\n };\n}\n//# sourceMappingURL=pipe.js.map\n\n/** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */\nvar Observable = /*@__PURE__*/ (function () {\n function Observable(subscribe) {\n this._isScalar = false;\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n Observable.prototype.lift = function (operator) {\n var observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n };\n Observable.prototype.subscribe = function (observerOrNext, error, complete) {\n var operator = this.operator;\n var sink = toSubscriber(observerOrNext, error, complete);\n if (operator) {\n sink.add(operator.call(sink, this.source));\n }\n else {\n sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?\n this._subscribe(sink) :\n this._trySubscribe(sink));\n }\n if (config.useDeprecatedSynchronousErrorHandling) {\n if (sink.syncErrorThrowable) {\n sink.syncErrorThrowable = false;\n if (sink.syncErrorThrown) {\n throw sink.syncErrorValue;\n }\n }\n }\n return sink;\n };\n Observable.prototype._trySubscribe = function (sink) {\n try {\n return this._subscribe(sink);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n sink.syncErrorThrown = true;\n sink.syncErrorValue = err;\n }\n if (canReportError(sink)) {\n sink.error(err);\n }\n else {\n console.warn(err);\n }\n }\n };\n Observable.prototype.forEach = function (next, promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var subscription;\n subscription = _this.subscribe(function (value) {\n try {\n next(value);\n }\n catch (err) {\n reject(err);\n if (subscription) {\n subscription.unsubscribe();\n }\n }\n }, reject, resolve);\n });\n };\n Observable.prototype._subscribe = function (subscriber) {\n var source = this.source;\n return source && source.subscribe(subscriber);\n };\n Observable.prototype[observable] = function () {\n return this;\n };\n Observable.prototype.pipe = function () {\n var operations = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n operations[_i] = arguments[_i];\n }\n if (operations.length === 0) {\n return this;\n }\n return pipeFromArray(operations)(this);\n };\n Observable.prototype.toPromise = function (promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var value;\n _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });\n });\n };\n Observable.create = function (subscribe) {\n return new Observable(subscribe);\n };\n return Observable;\n}());\nfunction getPromiseCtor(promiseCtor) {\n if (!promiseCtor) {\n promiseCtor = Promise;\n }\n if (!promiseCtor) {\n throw new Error('no Promise impl found');\n }\n return promiseCtor;\n}\n//# sourceMappingURL=Observable.js.map\n\nfunction tnLineStdinReader() {\n return new Observable(function (subscribe) {\n var stdin = readline.createInterface(process.stdin);\n var tests = null;\n var n = null;\n stdin.on('line', function (line) {\n if (tests === null) {\n tests = +line;\n } else if (n === null) {\n n = +line;\n tests--;\n } else {\n n = null;\n subscribe.next(line);\n\n if (tests === 0) {\n stdin.close();\n subscribe.complete();\n }\n }\n });\n });\n}\n\nfunction isHappy(arr) {\n if (arr[0] <= 0 || arr[arr.length - 1] <= 0) {\n return 'NO';\n }\n\n var sum = 0;\n\n for (var x = 0; x < arr.length - 2; x++) {\n sum += arr[x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n sum = 0;\n\n for (var _x = arr.length - 1; _x > 0; _x--) {\n sum += arr[_x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n return 'YES';\n}\n\ntnLineStdinReader().subscribe(function (input) {\n var arr = input.split(' ').map(function (i) {\n return +i;\n });\n console.log(isHappy(arr));\n});\n"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n const arr = readline().split(' ').map(function(x) {\n return parseInt(x)\n })\n\n let max_so_far = Number.MIN_SAFE_INTEGER\n let max_here = 0\n let neg = false\n \n for (let i = 0; i < n; ++i) {\n if (arr[i] < 0) neg = true\n max_here += arr[i]\n \n if (max_here < 0) {\n max_here = 0\n }\n \n if (max_so_far < max_here) {\n max_so_far = max_here\n }\n }\n \n let ok = false\n if (max_so_far < max_here) {\n ok = true\n } else if (max_so_far == max_here) {\n if (!neg) ok = true\n }\n\n print(ok ? 'YES': 'NO')\n}"}, {"source_code": "var numRun= readline();\n\nfor(var n=0;n0){seg+=num; if(maxSegmaxSeg||(segCt==totCt&&tot==maxSeg)){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n\n\n"}, {"source_code": "var numRun= readline();\n \nfor(var n=0;nmaxSeg){maxSeg=seg;}}\n //if(num>0){seg+=num; if(maxSegmaxSeg||(segCt==totCt&&tot==maxSeg&&arr[0]!=0&&arr[arr.length-1]!=0)){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n "}, {"source_code": "var numRun= readline();\n \nfor(var n=0;nmaxSeg){maxSeg=seg;}}\n //if(num>0){seg+=num; if(maxSegmaxSeg||(segCt==totCt&&tot==maxSeg&&arr[0]!=0&&arr[arr.length-1]!=0)){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n "}, {"source_code": "var numRun= readline();\n\nfor(var n=0;nmaxSeg){maxSeg=seg;}}\n //if(num>0){seg+=num; if(maxSegmaxSeg||(segCt==totCt&&tot==maxSeg)){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n\n\n"}, {"source_code": "var numRun= readline();\n\nfor(var n=0;nmaxSeg){maxSeg=seg;}}\n //if(num>0){seg+=num; if(maxSegmaxSeg||(segCt==totCt&&tot==maxSeg&&arr[0]!=0&&arr[arr.length-1]!=0)){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n\n\n"}, {"source_code": "var numRun= readline();\n\nfor(var n=0;n0){seg+=num; if(maxSegmaxSeg||!noNeg){print(\"YES\");}\n else{print(\"NO\");}\n \n \n}//num runs\n"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n print('YES');\n } else {\n if (total_taste > result.max_so_far) {\n print('YES');\n } else {\n print('NO');\n }\n }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nmain();\n\nfunction main() {\n const test_cases = readline();\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = readline();\n const cupcakes_taste = readline(); //.trim().split(' ').map(string => parseInt(string, 10));\n \n // const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n // const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_count, cupcakes_taste);\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline(); //.trim().split(' ').map(string => parseInt(string, 10));\n \n // const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n // const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_taste);\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n var cupcakes_count = parseInt(readline(), 10);\n var cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n var total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n var result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n \n if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n print('YES');\n } else {\n if (total_taste > result.max_so_far) {\n print('YES');\n } else {\n print('NO');\n }\n }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = readline();\n const cupcakes_taste = readline(); //.trim().split(' ').map(string => parseInt(string, 10));\n \n // const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n // const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_count, cupcakes_taste);\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_taste, total_taste, result)\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline(); //.trim().split(' ').map(string => parseInt(string, 10));\n \n // const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n // const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_count, cupcakes_taste);\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\n// function print(item) {\n// console.log(item);\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n print('YES');\n } else {\n if (total_taste > result.max_so_far) {\n print('YES');\n } else {\n print('NO');\n }\n }\n }\n}\n\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = readline();\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = readline();\n const cupcakes_taste = readline(); //.trim().split(' ').map(string => parseInt(string, 10));\n \n // const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n // const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n print(cupcakes_count, cupcakes_taste);\n // if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n // print('YES');\n // } else {\n // if (total_taste > result.max_so_far) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n // }\n }\n}\nmain();"}, {"source_code": "// 'use strict';\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// main(); \n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\n// function print(item) {\n// console.log(item);\n// }\n\nfunction maxSubArraySum(array_of_numbers, array_size) {\n var max_so_far = Number.MIN_SAFE_INTEGER;\n var max_ending_here = 0;\n var start_index = 0;\n var end_index = 0;\n var start_tmp = 0; \n\n for (var i = 0; i < array_size; i++) { \n max_ending_here += array_of_numbers[i];\n\n if (max_so_far < max_ending_here) {\n max_so_far = max_ending_here;\n start_index = start_tmp;\n end_index = i;\n }\n\n if (max_ending_here < 0) {\n max_ending_here = 0;\n start_tmp = i + 1;\n }\n }\n return { max_so_far, start_index, end_index }; \n}\n\nfunction main() {\n const test_cases = parseInt(readline(), 10);\n for(var i = 0; i < test_cases; i++) {\n const cupcakes_count = parseInt(readline(), 10);\n const cupcakes_taste = readline().trim().split(' ').map(string => parseInt(string, 10));\n \n const total_taste = cupcakes_taste.reduce((a, b) => a + b, 0);\n\n const result = maxSubArraySum(cupcakes_taste, cupcakes_count);\n if (result.start_index == 0 && result.end_index == cupcakes_count - 1) {\n print('YES');\n } else {\n if (total_taste > result.max_so_far) {\n print('YES');\n } else {\n print('NO');\n }\n }\n }\n}"}], "src_uid": "6e5b4d43e64645cf26d5eac31437b1a9"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(BigInt)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n const [rn, c2n, c5n] = helper(n)\n let now = 1n\n if (c2n > c5n) {\n let k = 0n\n while (c2n >= c5n + k + 1n && now * 5n <= m) {\n k++\n now *= 5n\n }\n n *= now\n m = m / now\n } else if (c2n < c5n) {\n let k = 0n\n while (c2n + k + 1n <= c5n && now * 2n <= m) {\n k++\n now *= 2n\n }\n n *= now\n m = m / now\n }\n // console.log(c2n, c5n, now)\n const sm = m.toString()\n const base = sm.length - 1\n return n * (10n ** BigInt(base)) * BigInt(sm[0])\n}\nfunction helper(n) {\n let c2 = 0n, c5 = 0n\n while (n > 0n && !(n % 2n)) {\n n /= 2n\n c2++\n }\n while (n > 0n && !(n % 5n)) {\n n /= 5n\n c5++\n }\n return [n, c2, c5]\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, m] = rns();\r\n let len = 0,\r\n s = n.toString();\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n if (s[i] === '0') len++;else break;\r\n }\r\n s = s.slice(0, s.length - len);\r\n let num = Number(s),\r\n res = 1;\r\n if (num % 5 === 0) {\r\n let cnt = 0;\r\n while (num % 5 === 0) {\r\n cnt++;\r\n num /= 5;\r\n }\r\n for (let i = cnt; i >= 0; i--) {\r\n if (2 ** i <= m) {\r\n res = 2 ** i;\r\n break;\r\n }\r\n }\r\n } else if (num % 2 === 0) {\r\n let cnt = 0;\r\n while (num % 2 === 0) {\r\n cnt++;\r\n num /= 2;\r\n }\r\n for (let i = cnt; i >= 0; i--) {\r\n if (5 ** i <= m) {\r\n res = 5 ** i;\r\n break;\r\n }\r\n }\r\n }\r\n for (; res * 10 <= m; res *= 10) {}\r\n const x = Math.floor(m / res);\r\n res *= x;\r\n return BigInt(n) * BigInt(res);\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "83af7209bb8a81cde303af5d207c2749"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[s++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function d(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar text = trim(readline());\n\tvar match = text.match(/^([a-z]+\\@[a-z])*([a-z]+\\@[a-z]+)$/);\n\tif (match) {\n\t\tvar regex = /[a-z]+\\@[a-z]/g;\n\t\tvar groups = [];\n\t\twhile (true) {\n\t\t\tvar result = regex.exec(text);\n\t\t\tif (result === null) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tgroups.push(result[0]);\n\t\t}\n\t\tvar tail = text.match(/[a-z]+$/)[0].substring(1);\n\t\tgroups[groups.length-1] += tail;\n\t\tprint(groups.join(\",\"));\n\t}\n\telse {\n\t\tprint(\"No solution\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar text = trim(readline());\n\n\tvar groups = [];\n\tvar start = 0;\n\n\twhile (true) {\n\n\t\tvar pos = text.indexOf(\"@\", start);\n\n\t\tif (pos == -1) {\n\t\t\tif (groups.length == 0) {\n\t\t\t\tprint(\"No solution\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tgroups[groups.length-1] += text.substring(start);\n\t\t\t\tprint(groups.join(\",\"));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (pos == start || pos == text.length-1 || text.charAt(pos+1) == '@') {\n\t\t\tprint(\"No solution\");\n\t\t\treturn;\n\t\t}\n\n\t\tgroups.push(text.substring(start, pos+2));\n\t\tstart = pos+2;\n\t}\n}\n\nmain();\n"}, {"source_code": "var s = readline()\nprint((s.match(/^@|@.?@|@$/) || !~s.indexOf('@')) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join() + s.slice(s.lastIndexOf('@') + 2))"}, {"source_code": "'use strict'\n\nlet lll = readline()\n\n;(function () {\n let spt = lll.split('@')\n if (spt.length < 2) return print('No solution')\n if (!spt[0] || !spt[spt.length - 1]) return print('No solution')\n if (spt.slice(1, -1).length != spt.slice(1, -1).filter(v => v.length > 1).length)\n return print('No solution')\n\n let as\n if (spt.length > 2) {\n as = [spt[0] + '@' + spt[1][0]]\n for (let i = 1; i < spt.length - 2; i++) {\n as.push(spt[i].slice(1) + '@' + spt[i + 1][0])\n }\n as.push(spt[spt.length - 2].slice(1) + '@' + spt[spt.length - 1])\n } else {\n as = [spt.join('@')]\n }\n print(as.join(','))\n}())"}, {"source_code": "//var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar emails = readline();\nvar answ = [];\ndropStr(emails);\n\nfunction dropStr(str) {\n for (var i = 0; i < str.length; ++i) {\n if (str[i] == '@') {\n answ.push(str.substr(0, i+2));\n str = str.substr(i+2);\n break;\n }\n }\n if (str.length > 0 && str.indexOf('@') !== -1) {\n dropStr(str);\n } else {\n if (answ[answ.length-1])\n answ[answ.length-1] = answ[answ.length-1].concat(str);\n }\n}\nvar status = false;\nfor (var i = 0; i < answ.length; ++i) {\n var splited_anws = answ[i].split('@');\n if (splited_anws[0].length === 0 || splited_anws[1].length === 0) {\n status = true;\n }\n}\n\nif (!status && answ.length !== 0) {\n print(answ);\n} else {\n print('No solution');\n}"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar text = trim(readline());\n\tvar groups = text.match(/^([a-z]+\\@[a-z])*([a-z]+\\@[a-z]+)$/);\n\tif (groups) {\n\t\tgroups.splice(0, 1);\n\t\tprint(groups.join(\",\"));\n\t}\n\telse {\n\t\tprint(\"No solution\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar text = trim(readline());\n\tvar match = text.match(/^([a-z]+\\@[a-z])+$/);\n\tif (match) {\n\t\tvar groups = text.match(/[a-z]+\\@[a-z]/g);\n\t\tprint(groups.join(\",\"));\n\t}\n\telse {\n\t\tprint(\"No solution\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar text = trim(readline());\n\n\tvar groups = [];\n\tvar start = 0;\n\n\twhile (true) {\n\n\t\tvar pos = text.indexOf(\"@\", start);\n\n\t\tif (pos == -1) {\n\t\t\tif (groups.length == 0) {\n\t\t\t\tprint(\"No solution\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tgroups[groups.length-1] += text.substring(start);\n\t\t\t\tprint(groups.join(\",\"));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (pos == start || pos == text.length-1) {\n\t\t\tprint(\"No solution\");\n\t\t\treturn;\n\t\t}\n\n\t\tgroups.push(text.substring(start, pos+2));\n\t\tstart = pos+2;\n\t}\n}\n\nmain();\n"}, {"source_code": "var s = readline()\nprint(/@.?@|^@|@$/.exec(s) ? \"No solution\" : s.match(/\\w+@(\\w+$|.)/g) + \"\")"}, {"source_code": "var s = readline()\nprint(s.match(/^@|@.?@|@$/) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join())"}, {"source_code": "var s = readline()\nprint(s.match(/^@|@.?@|@$/) || !~s.indexOf('@')) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join() + s.slice(s.lastIndexOf('@') + 2)"}, {"source_code": "'use strict'\n\nlet lll = readline()\n\n;(function () {\n let spt = lll.split('@')\n if (spt.length < 2) return print('No solution')\n if (!spt[0] || !spt[spt.length - 1]) return print('No solution')\n if (spt.slice(1, -1).length != spt.slice(1, -1).filter(v => v.length > 1).length)\n return print('No solution')\n\n let as = [spt[0] + '@' + spt[1][0]]\n for (let i = 1; i < spt.length - 2; i++) {\n as.push(spt[i].slice(1) + '@' + spt[i + 1][0])\n }\n as.push(spt[spt.length - 2].slice(1) + '@' + spt[spt.length - 1])\n print(as.join(','))\n}())"}], "src_uid": "71b4674e91e0bc5521c416cfc570a090"} {"source_code": "var n = parseInt(readline());\nvar a = new Array();\nfor(var i=0;i node i is used.\nvar u = new Array();\nfor(var i=0;i node i is used.\nvar u = new Array();\nfor(var i=0;i node i is used.\nvar u = new Array();\nfor(var i=0;i node i is used.\nvar u = new Array();\nfor(var i=0;i 1) {\r\n console.log(-1);\r\n } else if (t === 'a') {\r\n console.log(1);\r\n } else {\r\n let n = s.length,\r\n res = 2n;\r\n for (let i = 1; i < n; i++) {\r\n res += nums[n] / (nums[i] * nums[n - i]);\r\n }\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n const t = await read();\r\n solve(s, t);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (a, t)=>{\n if (t=='a'){\n return 1;\n }\n if (t.indexOf('a')>=0)\n return -1;\n let num = BigInt(1);\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n const replace = lines[l++]\n output[i] = solve(str, replace)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str, replace) {\n if (replace === 'a') return 1\n if (replace.indexOf('a') >= 0) return -1\n // return pow(str.length, replace.length)\n let a = BigInt(str.length)\n // let b = BigInt(replace.length)\n let ans = 1n\n while (a--) {\n ans *= 2n\n }\n return ans\n}\n"}, {"source_code": "var n = parseInt(readline())\r\nwhile(n>0)\r\n{\r\n var a = readline();\r\n var st = readline();\r\n\r\n flag=0;\r\n for(i=0;i 1) {\n print(-1);\n } else {\n print(1);\n }\n continue;\n }\n print(pow(s.length));\n}\n"}, {"source_code": "var tests = parseInt(readline());\r\n var s, t;\r\n for (var ti=0; ti < tests; ti++) {\r\n s = readline();\r\n t = readline();\r\n if (t == 'a') {\r\n print(1);\r\n continue;\r\n }\r\n if (t.indexOf('a') != -1) {\r\n print(-1);\r\n continue;\r\n }\r\n\r\n print(Math.pow(2, s.length));\r\n }"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n//console.log(input);\r\nvar T = readline();\r\nvar f = [];\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n \r\n // var s = 'aa', t = 'bbc'\r\n var len = s.length-1;\r\n var l = q == T ? t.length : t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n console.log(ans)\r\n \r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n // console.log(\"\\n ===============-===========\")\r\n\twhile(hasNext()){\r\n\t\tconst stringArr = nextCharArray().join(\"\");\r\n\t\tconst replace = nextCharArray().join(\"\");\r\n // if (!stringArr.includes(\"a\")){\r\n // myout(1);\r\n // continue;\r\n // }\r\n\r\n if (replace.length >= 2 && replace.includes(\"a\")) {\r\n myout(-1);\r\n continue;\r\n }\r\n\r\n if (replace.length === 1 && replace[0] === \"a\") {\r\n myout(1);\r\n continue;\r\n }\r\n\r\n myout(Math.pow(2, stringArr.length));\r\n // console.log(stringArr, replace)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar L = next();\r\n\t\tvar R = next();\r\n\t\tif(R == \"a\"){\r\n\t\t\tmyout(1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(L.indexOf(\"a\") != -1 && R.indexOf(\"a\") != -1){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar c = 0n;\r\n\t\tfor(var i = 0; i < L.length; i++){\r\n\t\t\tif(L[i] == \"a\"){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(1n << c);\r\n\t}\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (s, t)=>{\n if (t === 'a') return 1;\n if (t.includes('a')) return -1;\n\n let n = s.length;\n let result = 0;\n for (let i = 0; i <= n; i++) {\n result += cnk(n, i);\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let s = readline();\n let t = readline();\n console.log(`${calc(s, t)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = q == 10000 ? s.length : s.length-1;\r\n var l = q == 10000 ? t.length: t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n \r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = q == T ? s.length : s.length-1;\r\n var l = q == T ? t.length: t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n \r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = s.length-1;\r\n var l = t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n if(q == 10000) {\r\n \r\n console.log(t);\r\n }\r\n console.log(ans);\r\n \r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = s.length-1;\r\n var l = t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n if(q == 10000) {\r\n console.log(s);\r\n console.log(t);\r\n }\r\n console.log(ans);\r\n \r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = s.length-1;\r\n var l = t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n if(q == 10000) {\r\n console.log(s);\r\n console.log(t);\r\n }\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aa', t = 'bbc'\r\n var len = s.length-1;\r\n var l = t.length-1;\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aaaa', t = 'a'\r\n var cntS = 0, cntT = 0, l = t.length-1;\r\n var ans = -1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n } else {\r\n if(cntS > 0) ans = Math.pow(2, cntS);\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aaaa', t = 'a'\r\n var cntS = 0, cntT = 0, l = t.length-1;\r\n var ans = -1;\r\n for(var i=0;i 1) ans = -1;\r\n else ans = 1;\r\n } else {\r\n if(cntS > 1) ans = Math.pow(2, cntS);\r\n else ans = 1;\r\n }\r\n console.log(ans);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aaaa', t = 'a'\r\n var cntS = 0, cntT = 0, l = t.length-1;\r\n var ans = -1;\r\n for(var i=0;i 1) ans = -1;\r\n else {\r\n if(l == 1) ans = 1;\r\n else ans = 2;\r\n }\r\n } else {\r\n if(cntS === 0) ans = 1;\r\n else {\r\n ans = Math.pow(2, cntS);\r\n }\r\n }\r\n console.log(ans);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aaaa', t = 'a'\r\n var cntS = 0, cntT = 0, l = t.length;\r\n var ans = -1;\r\n for(var i=0;i 1) ans = -1;\r\n else {\r\n if(l == 1) ans = 1;\r\n else ans = 2;\r\n }\r\n } else {\r\n if(cntS === 0) ans = 1;\r\n else {\r\n ans = Math.pow(2, cntS);\r\n }\r\n }\r\n console.log(s)\r\n console.log(t)\r\n console.log(s.length)\r\n console.log(t.length)\r\n console.log(ans);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var t = readline();\r\n // var s = 'aaaa', t = 'a'\r\n var cntS = 0, cntT = 0, l = t.length;\r\n var ans = -1;\r\n for(var i=0;i 1) ans = -1;\r\n else {\r\n if(l == 1) ans = 1;\r\n else ans = 2;\r\n }\r\n } else {\r\n if(cntS === 0) ans = 1;\r\n else {\r\n ans = Math.pow(2, cntS);\r\n }\r\n }\r\n console.log(ans);\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n // console.log(\"\\n ===============-===========\")\r\n\twhile(hasNext()){\r\n\t\tconst stringArr = nextCharArray().join(\"\");\r\n\t\tconst replace = nextCharArray().join(\"\");\r\n if (!stringArr.includes(\"a\")){\r\n myout(1);\r\n continue;\r\n }\r\n\r\n if (replace.length >= 2 && replace.includes(\"a\")) {\r\n myout(-1);\r\n continue;\r\n }\r\n\r\n if (replace.length === 1 && replace[0] === \"a\") {\r\n myout(1);\r\n continue;\r\n }\r\n\r\n myout(stringArr.split(\"\").filter(ele => ele === \"a\").length + 1);\r\n // console.log(stringArr, replace)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n // console.log(\"\\n ===============-===========\")\r\n\twhile(hasNext()){\r\n\t\tconst stringArr = nextCharArray().join(\"\");\r\n\t\tconst replace = nextCharArray().join(\"\");\r\n\r\n if (replace.length >= 2 && replace.includes(\"a\")) {\r\n myout(-1);\r\n continue;\r\n }\r\n\r\n if (replace.length === 1 && replace[0] === \"a\") {\r\n myout(1);\r\n continue;\r\n }\r\n\r\n myout(stringArr.split(\"\").filter(ele => ele === \"a\").length + 1);\r\n // console.log(stringArr, replace)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n console.log(\"\\n ===============-===========\")\r\n\twhile(hasNext()){\r\n\t\tconst stringArr = nextCharArray().join(\"\");\r\n\t\tconst replace = nextCharArray().join(\"\");\r\n\r\n if (replace.length >= 2 && replace.includes(\"a\")) {\r\n myout(-1);\r\n continue;\r\n }\r\n\r\n if (replace.length === 1 && replace[0] === \"a\") {\r\n myout(1);\r\n continue;\r\n }\r\n\r\n myout(stringArr.split(\"\").filter(ele => ele === \"a\").length + 1);\r\n // console.log(stringArr, replace)\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar L = next();\r\n\t\tvar R = next();\r\n\t\tif(R == \"a\"){\r\n\t\t\tmyout(1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(L.indexOf(\"a\") != -1 && R.indexOf(\"a\") != -1){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 0; i < L.length; i++){\r\n\t\t\tif(L[i] == \"a\"){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(1 << c);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar L = next();\r\n\t\tvar R = next();\r\n\t\tif(R == \"a\"){\r\n\t\t\tmyout(1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(R.indexOf(\"a\") != -1){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 0; i < L.length; i++){\r\n\t\t\tif(L[i] == \"a\"){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(1 << c);\r\n\t}\r\n}\r\n"}], "src_uid": "d6ac9ca9cc5dfd9f43f5f65ce226349e"} {"source_code": "const readline = require(\"readline\");\r\nconst os = require(\"os\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet lineNum = 0, consumed = 0, lineNo = 0\r\nlet input = []\r\nlet res = []\r\nlet out = []\r\n\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line)\r\n if (input.length === 2) {\r\n lineNum = +input[1]\r\n }\r\n \r\n if(input.length > 2) {\r\n consumed++\r\n input.pop()\r\n\r\n const tmp = line.split(' ').map(e => +e)\r\n lineNo++\r\n if(tmp.length > 1) {\r\n for(let j = 1; j < tmp.length; j++) {\r\n res.push([tmp[j], lineNo])\r\n }\r\n }\r\n\r\n if(consumed === lineNum) {\r\n const ans = solution(res, lineNum)\r\n out.push(ans === -1 ? -1 : ans)\r\n input.length = 1\r\n consumed = 0\r\n lineNo = 0\r\n res = []\r\n }\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n let str = ''\r\n for(const e of out) str += e + os.EOL\r\n console.log(str)\r\n});\r\n\r\nfunction solution(arr, n) {\r\n const graph = {}, inDegree = Array(n + 1).fill(0)\r\n for(const [u, v] of arr) {\r\n if(graph[u] == null) graph[u] = []\r\n graph[u].push(v)\r\n inDegree[v]++\r\n }\r\n const q = [], visited = new Set(), times = Array(n + 1).fill(0)\r\n for(let i = 1; i <= n; i++) {\r\n if(inDegree[i] === 0) {\r\n q.push(i)\r\n visited.add(i)\r\n }\r\n times[i] = 1\r\n }\r\n\r\n while(q.length) {\r\n const cur = q.pop()\r\n for(const next of (graph[cur] || [])) {\r\n inDegree[next]--\r\n if(cur < next) times[next] = Math.max(times[cur], times[next])\r\n else times[next] = Math.max(times[next], times[cur] + 1)\r\n if(inDegree[next] === 0) {\r\n q.push(next)\r\n visited.add(next)\r\n }\r\n }\r\n }\r\n\r\n if (visited.size === n) {\r\n return Math.max(...times)\r\n } else return -1\r\n}", "positive_code": [{"source_code": "const readline = require(\"readline\");\r\nconst os = require(\"os\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet lineNo = 0, consumed = 0, lineth = 0\r\nlet input = []\r\nlet res = []\r\nlet out = []\r\n\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line)\r\n if (input.length === 2) {\r\n lineNo = +input[1]\r\n }\r\n \r\n if(input.length > 2) {\r\n consumed++\r\n input.pop()\r\n\r\n const tmp = line.split(' ').map(e => +e)\r\n lineth++\r\n if(tmp.length > 1) {\r\n for(let j = 1; j < tmp.length; j++) {\r\n res.push([tmp[j], lineth])\r\n }\r\n }\r\n\r\n if(consumed === lineNo) {\r\n const ans = solution(res, lineNo)\r\n out.push(ans === -1 ? -1 : ans)\r\n input.length = 1\r\n consumed = 0\r\n lineth = 0\r\n res = []\r\n }\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n let str = ''\r\n for(const e of out) str += e + os.EOL\r\n console.log(str)\r\n});\r\n\r\nfunction solution(arr, n) {\r\n const graph = {}, inDegree = Array(n + 1).fill(0)\r\n for(const [u, v] of arr) {\r\n if(graph[u] == null) graph[u] = []\r\n graph[u].push(v)\r\n inDegree[v]++\r\n }\r\n const q = [], visited = new Set(), times = Array(n + 1).fill(0)\r\n for(let i = 1; i <= n; i++) {\r\n if(inDegree[i] === 0) {\r\n q.push(i)\r\n visited.add(i)\r\n }\r\n times[i] = 1\r\n }\r\n\r\n while(q.length) {\r\n const cur = q.pop()\r\n for(const next of (graph[cur] || [])) {\r\n inDegree[next]--\r\n if(cur < next) times[next] = Math.max(times[cur], times[next])\r\n else times[next] = Math.max(times[next], times[cur] + 1)\r\n if(inDegree[next] === 0) {\r\n q.push(next)\r\n visited.add(next)\r\n }\r\n }\r\n }\r\n\r\n if (visited.size === n) {\r\n return Math.max(...times)\r\n } else return -1\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\nconst os = require(\"os\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet lineNum = 0, consumed = 0, lineNo = 0\r\nlet input = []\r\nlet res = []\r\nlet out = []\r\n\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line)\r\n if (input.length === 2) {\r\n lineNum = +input[1]\r\n }\r\n \r\n if(input.length > 2) {\r\n consumed++\r\n input.pop()\r\n\r\n const tmp = line.split(' ').map(e => +e)\r\n lineNo++\r\n if(tmp.length > 1) {\r\n for(let j = 1; j < tmp.length; j++) {\r\n res.push([tmp[j], lineNo])\r\n }\r\n }\r\n\r\n if(consumed === lineNum) {\r\n const ans = solution(res, lineNum)\r\n out.push(ans === -1 ? -1 : ans)\r\n input.length = 1\r\n consumed = 0\r\n lineNo = 0\r\n res = []\r\n }\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n let str = ''\r\n for(const e of out) str += e + os.EOL\r\n console.log(str)\r\n});\r\n\r\nfunction solution(arr, n) {\r\n const graph = {}, inDegree = Array(n + 1).fill(0)\r\n for(const [u, v] of arr) {\r\n if(graph[u] == null) graph[u] = []\r\n graph[u].push(v)\r\n inDegree[v]++\r\n }\r\n const q = [], visited = new Set(), times = Array(n + 1).fill(0)\r\n for(let i = 1; i <= n; i++) {\r\n if(inDegree[i] === 0) {\r\n q.push(i)\r\n visited.add(i)\r\n }\r\n times[i] = 1\r\n }\r\n\r\n while(q.length) {\r\n const cur = q.pop()\r\n for(const next of (graph[cur] || [])) {\r\n inDegree[next]--\r\n if(cur < next) times[next] = Math.max(times[cur], times[next])\r\n else times[next] = Math.max(times[next], times[cur] + 1)\r\n if(inDegree[next] === 0) {\r\n q.push(next)\r\n visited.add(next)\r\n }\r\n }\r\n }\r\n\r\n if (visited.size === n) {\r\n return Math.max(...times)\r\n } else return -1\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\r\nconst os = require(\"os\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet lineNo = 0, consumed = 0, lineth = 0\r\nlet input = []\r\nlet res = []\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line)\r\n if (input.length === 2) {\r\n lineNo = +input[1]\r\n }\r\n \r\n if(input.length > 2) {\r\n consumed++\r\n\r\n const tmp = line.split(' ').map(e => +e)\r\n lineth++\r\n if(tmp.length > 1) {\r\n for(let j = 1; j < tmp.length; j++) {\r\n res.push([tmp[j], lineth])\r\n }\r\n }\r\n\r\n if(consumed === lineNo) {\r\n input.length = 1\r\n consumed = 0\r\n lineth = 0\r\n res = []\r\n const ans = solution(res, lineNo)\r\n console.log(ans === -1 ? -1 : ans)\r\n }\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n});\r\n\r\nfunction solution(arr, n) {\r\n const graph = {}, inDegree = Array(n + 1).fill(0)\r\n for(const [u, v] of arr) {\r\n if(graph[u] == null) graph[u] = []\r\n graph[u].push(v)\r\n inDegree[v]++\r\n }\r\n const q = [], visited = new Set(), times = Array(n + 1).fill(0)\r\n for(let i = 1; i <= n; i++) {\r\n if(inDegree[i] === 0) {\r\n q.push(i)\r\n visited.add(i)\r\n }\r\n times[i] = 1\r\n }\r\n\r\n while(q.length) {\r\n const cur = q.shift()\r\n for(const next of (graph[cur] || [])) {\r\n inDegree[next]--\r\n if(cur < next) times[next] = Math.max(times[cur], times[next])\r\n else times[next] = Math.max(times[next], times[cur] + 1)\r\n if(inDegree[next] === 0) {\r\n q.push(next)\r\n visited.add(next)\r\n }\r\n }\r\n }\r\n\r\n if (visited.size === n) {\r\n return Math.max(...times)\r\n } else return -1\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\nconst os = require(\"os\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet lineNo = 0, consumed = 0\r\nlet input = []\r\nlet res = []\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line)\r\n if (input.length === 2) {\r\n lineNo = +input[1]\r\n }\r\n \r\n if(input.length > 2) {\r\n consumed++\r\n\r\n const tmp = line.split(' ').map(e => +e)\r\n if(tmp.length > 1) {\r\n for(let j = 1; j < tmp.length; j++) {\r\n res.push([tmp[j], consumed])\r\n }\r\n }\r\n\r\n if(consumed === lineNo) {\r\n input.length = 1\r\n consumed = 0\r\n res = []\r\n const ans = solution(res, lineNo)\r\n console.log(ans === -1 ? -1 : ans)\r\n }\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n});\r\n\r\nfunction solution(arr, n) {\r\n const graph = {}, inDegree = Array(n + 1).fill(0)\r\n for(const [u, v] of arr) {\r\n if(graph[u] == null) graph[u] = []\r\n graph[u].push(v)\r\n inDegree[v]++\r\n }\r\n const q = [], visited = new Set(), times = Array(n + 1).fill(0)\r\n for(let i = 1; i <= n; i++) {\r\n if(inDegree[i] === 0) {\r\n q.push(i)\r\n visited.add(i)\r\n }\r\n times[i] = 1\r\n }\r\n\r\n while(q.length) {\r\n const cur = q.shift()\r\n for(const next of (graph[cur] || [])) {\r\n inDegree[next]--\r\n if(cur < next) times[next] = Math.max(times[cur], times[next])\r\n else times[next] = Math.max(times[next], times[cur] + 1)\r\n if(inDegree[next] === 0) {\r\n q.push(next)\r\n visited.add(next)\r\n }\r\n }\r\n }\r\n\r\n if (visited.size === n) {\r\n return Math.max(...times)\r\n } else return -1\r\n}"}], "src_uid": "af40a0de6d3c0ff7bcd2c1b077b05d6e"} {"source_code": "var ip = readline().split(' ').map(Number);\nvar index = ip[0], k = ip[1];\nvar ar = readline().split(' ').sort((a,b)=>a-b),ans = Math.abs(k-ar[Math.floor(index/2)]),i=Math.floor(index/2)-1,j = Math.floor(index/2)+1;\nwhile (i >= 0 && ar[i] > k){\n ans+= (ar[i--]-k);\n}\nwhile (j < index && ar[j] < k){\n ans += (k-ar[j++]);\n}\nprint(ans);", "positive_code": [{"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\n// function part(start, end) {\n// var p = nums[start];\n// while (start < end) {\n// while (start < end && nums[end] > p) {\n// end--;\n// }\n// nums[start] = nums[end];\n// while (start < end && nums[start] <= p) {\n// start++;\n// }\n// nums[end] = nums[start];\n// }\n// nums[start] = p;\n// return start;\n// }\n// function quickSort(k, start, end) {\n// if (start < end) {\n// var p = part(start, end);\n// if (p === k) return;\n// if (p > k) quickSort(k, start, p - 1);\n// if (p < k) quickSort(k - p - 1, p + 1, end);\n// }\n// }\n\n// quickSort(k, 0, n - 1);\nnums.sort(function (a, b) {\n return a - b;\n})\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}], "negative_code": [{"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nfor (var i = k; i < n; i++){\n rst += Math.max(target - nums[i],0);\n}\nif (n>10) {\n print(`${nums.join(',')}`)\n} else {\n print(rst) \n}\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\n// nums.sort(function (a, b) {\n// return a - b;\n// })\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nfor (var i = k; i < n; i++){\n rst += Math.max(target - nums[i],0);\n}\nif (n>10) {\n print(`${k} ${n} ${nums.join(',')}`)\n} else {\n print(rst) \n}\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nfor (var i = k; i < n; i++){\n rst += Math.max(target - nums[i],0);\n}\n\nprint(`${k} ${n} ${nums.join(',')}`)\n"}, {"source_code": "\nvar n_target = readline();\n// // var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// // var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(nums.length / 2) + 1;\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k - 1) return;\n if (p > k - 1) quickSort(k, start, p - 1);\n if (p < k - 1) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, nums.length - 1);\n\n// quickSort(m, 0, nums.length - 1);\nvar rst = 0;\nif (nums[k-1]<= target) {\n for (var i = k-1; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i < k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\n// var n_target = readline();\nvar n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\n// var nums = readline();\nvar nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\n// function part(start, end) {\n// var p = nums[start];\n// while (start < end) {\n// while (start < end && nums[end] > p) {\n// end--;\n// }\n// nums[start] = nums[end];\n// while (start < end && nums[start] <= p) {\n// start++;\n// }\n// nums[end] = nums[start];\n// }\n// nums[start] = p;\n// return start;\n// }\n// function quickSort(k, start, end) {\n// if (start < end) {\n// var p = part(start, end);\n// if (p === k) return;\n// if (p > k) quickSort(k, start, p - 1);\n// if (p < k) quickSort(k - p - 1, p + 1, end);\n// }\n// }\n\n// quickSort(k, 0, n - 1);\nnums.sort((a, b) => a - b);\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\nvar nums = readline();\n// function print(rst){ console.log(rst) }\n// var n_target = '7 20';\n// var nums = '21 15 12 11 20 19 12';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\n\n\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(nums.length / 2) + 1;\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n var p = part(start, end);\n if (start < end) {\n while (p !== k - 1) {\n // console.log(p, k, nums);\n if (p === k - 1) return;\n if (p > k - 1) {\n p = part(start, p - 1);\n end = p;\n continue;\n }\n if (p < k - 1) {\n p = part(p + 1 , end);\n start = p + 1;\n continue;\n }\n }\n // var p = part(start, end);\n // if (p === k - 1) return;\n // if (p > k - 1) quickSort(k, start, p - 1);\n // if (p < k - 1) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, nums.length - 1);\n\n// quickSort(m, 0, nums.length - 1);\nvar rst = 0;\nif (nums[k - 1] <= target) {\n for (var i = k - 1; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i < k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p);\n if (p < k) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\n// nums.sort(function (a, b) {\n// return a - b;\n// })\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\n// quickSort(k, 0, n - 1);\nnums.sort((a, b) => { return a - b });\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\nif (n === 499) {\n print(nums[k])\n} else {\n print(rst)\n}\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2) + 1;\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k-1) return;\n if (p > k-1) quickSort(k, start, p -1);\n if (p < k-1) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\n// nums.sort(function (a, b) {\n// return a - b;\n// })\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nfor (var i = k; i < n; i++){\n rst += Math.max(target - nums[i],0);\n}\n\nprint(rst)\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2) + 1;\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k-1) return;\n if (p > k-1) quickSort(k, start, p );\n if (p < k-1) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\n// nums.sort(function (a, b) {\n// return a - b;\n// })\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(n / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, n - 1);\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\nif (n === 499) {\n print(nums[k])\n} else {\n print(rst)\n}\n\n\n"}, {"source_code": "\nvar n_target = readline();\n// var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(nums.length / 2);\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k) return;\n if (p > k) quickSort(k, start, p - 1);\n if (p < k) quickSort(k - p, p + 1, end);\n }\n}\n\nquickSort(k, 0, nums.length - 1);\nvar rst = 0;\nfor (var i = k; i < nums.length; i++){\n rst += Math.max(target - nums[i],0);\n}\n\nprint(rst)\n"}, {"source_code": "\nvar n_target = readline();\n// // var n_target = '7 20';\nvar n = +(n_target.split(' ')[0]);\nvar target = +(n_target.split(' ')[1]);\nvar nums = readline();\n// // var nums = '21 15 12 11 20 19 12';\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nvar k = Math.floor(nums.length / 2) + 1;\n\nfunction part(start, end) {\n var p = nums[start];\n while (start < end) {\n while (start < end && nums[end] > p) {\n end--;\n }\n nums[start] = nums[end];\n while (start < end && nums[start] <= p) {\n start++;\n }\n nums[end] = nums[start];\n }\n nums[start] = p;\n return start;\n}\nfunction quickSort(k, start, end) {\n if (start < end) {\n var p = part(start, end);\n if (p === k - 1) return;\n if (p > k - 1) quickSort(k, start, p - 1);\n if (p < k - 1) quickSort(k - p - 1, p + 1, end);\n }\n}\n\nquickSort(k, 0, nums.length - 1);\n\n// quickSort(m, 0, nums.length - 1);\nvar rst = 0;\nif (nums[k]<= target) {\n for (var i = k; i < n; i++) {\n rst += Math.max(target - nums[i], 0);\n }\n} else {\n for (var i = 0; i <= k; i++) {\n rst += Math.max(nums[i] - target, 0);\n }\n}\n\nprint(rst)\n// console.log(rst)\n\n\n\n"}], "src_uid": "0df33cd53575471b1cc20702bf777059"} {"source_code": "function nextInt() {\n return parseInt(nextString());\n}\n\nfunction nextFloat() {\n return parseFloat(nextString());\n}\n\nlet input_stdin = \"\";\nlet input_cursor = 0;\n\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\n\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) {\n return input_stdin[input_cursor++];\n } else {\n return '\\0';\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\n\nfunction isWhitespace(character) {\n return ' \\t\\n\\r\\v'.indexOf(character) > -1;\n}\n\nfunction clearWhitespaces() {\n while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {\n input_cursor += 1;\n } \n}\n\nfunction main() {\n let n = nextInt();\n let fd = new Array(n + 2);\n fd.fill(0);\n let x = nextString();\n let ck = x.length - 11;\n let mvv = ck / 2, mvp = ck / 2;\n for (let i = 0; i < n; i++){\n if (x[i] === '8' && mvv)fd[i] = 1, mvv--;\n if (x[i] !== '8' && mvp)fd[i] = 1, mvp--;\n }\n for (let i = 0; i < n; i++){\n if (fd[i] === 0){\n if (x[i] === '8')console.log(\"Yes\"); else console.log(\"NO\");\n process.exit(0);\n }\n }\n}", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var s = read.arr();\n\n var lCount = n - 11;\n var hCount = lCount / 2;\n var vCount = 0;\n\n\n var g = false;\n\n for(var i = 0; i < n; i++) {\n if(s[i] === '8' && (i + 10) < n) {\n vCount ++;\n }\n }\n\n if(hCount >= vCount ) {\n print('NO');\n }\n else {\n print('YES')\n }\n}());\n"}, {"source_code": "function nextInt() {\n return parseInt(nextString());\n}\n\nfunction nextFloat() {\n return parseFloat(nextString());\n}\n\nlet input_stdin = \"\";\nlet input_cursor = 0;\n\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\n\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) {\n return input_stdin[input_cursor++];\n } else {\n return '\\0';\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\n\nfunction isWhitespace(character) {\n return ' \\t\\n\\r\\v'.indexOf(character) > -1;\n}\n\nfunction clearWhitespaces() {\n while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {\n input_cursor += 1;\n } \n}\n\nfunction main() {\n let n = nextInt();\n let fd = new Array(n + 2);\n fd.fill(0);\n let x = nextString();\n let ck = x.length - 11;\n let mvv = ck / 2, mvp = ck / 2;\n for (let i = 0; i < n; i++){\n if (x[i] === '8' && mvv)fd[i] = 1, mvv--;\n if (x[i] !== '8' && mvp)fd[i] = 1, mvp--;\n }\n for (let i = 0; i < n; i++){\n if (fd[i] === 0){\n if (x[i] === '8')console.log(\"Yes\"); else console.log(\"NO\");\n process.exit(0);\n }\n }\n}"}], "negative_code": [], "src_uid": "99f37936b243907bf4ac1822dc547a61"} {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var a = read.arrNumber(' ');\n\n var sum1 = 0;\n var sum2 = 0;\n for(var i = 0; i < n; i++) {\n sum1 += a[i];\n sum2 += a[i + n];\n }\n\n if(sum1 !== sum2) {\n print(a.join(' '));\n return;\n }\n\n var eq = true;\n for(var i = 1; i < 2 * n; i++) {\n if(a[i] !== a[i - 1]) {\n eq = false;\n break;\n }\n }\n\n if(eq) {\n print(-1);\n return;\n }\n\n\n for(var i = 0; i < n; i++) {\n for(var j = 0; j < n; j++) {\n if(a[i] != a[n + j]) {\n var tmp = a[i];\n a[i] = a[n + j];\n a[n + j] = tmp;\n print(a.join(' '));\n return;\n }\n }\n }\n\n}());", "positive_code": [{"source_code": "var n = parseInt(readline(), 10),\n a = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => a-b),\n sum_1 = 0,\n sum_2 = 0;\n\nfor(var i=0; i<2*n; i++) {\n if(i <= n-1) sum_1 += a[i];\n else sum_2 += a[i];\n}\n\nprint(sum_1 !== sum_2 ? a.join(' ') : -1);"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = row[0];\n\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar sum = 0;\nvar hash = [];\nvar str = \"\";\nvar unique = null;\nvar flag = false;\n\nif(a.length % 2 == 1) write(a.join(\" \"));\nelse {\n for(var i = 0; i < a.length; i++) {\n sum += a[i];\n if(unique === null || unique == a[i])\n unique = a[i];\n else \n flag = true;\n }\n \n if(sum % 2 == 1) write(a.join(\" \"));\n else if(!flag) write(-1);\n else {\n write(a.sort().join(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var a = read.arrNumber(' ');\n\n var sum1 = 0;\n var sum2 = 0;\n for(var i = 0; i < n; i++) {\n sum1 += a[i];\n sum2 += a[i + n];\n }\n\n if(sum1 !== sum2) {\n print(a.join(' '));\n return;\n }\n\n var eq = true;\n for(var i = 1; i < 2 * n; i++) {\n if(a[i] !== a[i - 1]) {\n eq = false;\n break;\n }\n }\n\n if(eq) {\n print(-1);\n return;\n }\n\n\n for(var i = 0; i < n; i++) {\n for(var j = 0; j < n; i++) {\n if(a[i] != a[n + j]) {\n var tmp = a[i];\n a[i] = a[n + j];\n a[n + j] = tmp;\n print(a.join(' '));\n return;\n }\n }\n }\n\n}());"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = row[0];\n\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar sum = 0;\nvar hash = [];\nvar str = \"\";\n\nif(a.length % 2 == 1) write(a.join(\" \"));\nelse {\n for(var i = 0; i < a.length; i++) {\n sum += a[i];\n if(hash[a[i]] == null) {\n hash[a[i]] = \"0\";\n }\n }\n \n if(sum % 2 == 1) write(a.join(\" \"));\n else if(hash.length <= 2) write(-1);\n else {\n write(a.sort().join(\" \"));\n }\n}\n"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = row[0];\n\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar sum = 0;\nvar hash = [];\nvar str = \"\";\n\nif(a.length % 2 == 1) write(a.join(\" \"));\nelse {\n for(var i = 0; i < a.length; i++) {\n sum += a[i];\n if(hash[a[i]] == null)\n hash[a[i]] = 1;\n }\n \n if(sum % 2 == 1) write(a.join(\" \"));\n else if(hash.length == 1) write(-1);\n else {\n write(a.sort().join(\" \"));\n }\n}\n"}], "src_uid": "1f4c057dff45f229b4dca49cd4e0438d"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, x] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, x, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, x, arr) {\n const dp = Array(n + 1).fill(-Infinity)\n dp[0] = 0\n for (let i = 0; i < n; i++) {\n let s = 0\n for (let j = i; j < n; j++) {\n s += arr[j]\n //\n const l = j - i + 1\n dp[l] = Math.max(dp[l], s)\n }\n }\n // console.log(dp)\n const ans = Array(n + 1).fill(-Infinity)\n for (let i = 0; i <= n; i++) {\n for (let l = i; l <= n; l++) {\n ans[i] = Math.max(ans[i], dp[l] + Math.min(l, i) * x)\n if (i) {\n ans[i] = Math.max(ans[i - 1], ans[i])\n }\n }\n }\n return ans.join(' ')\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const c = new Array(n).fill(-Infinity);\r\n for (let i = 0; i < n; i++) {\r\n let sum = 0;\r\n for (let j = i; j < n; j++) {\r\n sum += a[j];\r\n c[j - i] = Math.max(c[j - i], sum);\r\n }\r\n }\r\n const res = new Array(n + 1).fill(-Infinity);\r\n res[0] = Math.max(0, ...c);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n res[i + 1] = Math.max(0, res[i + 1], (Math.min(i, j) + 1) * m + c[j]);\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 5005;\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, x] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst sums = Array(n+1).fill(-INF); sums[0] = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i, sum = 0; j < n; j++) {\r\n\t\t\t\tsum += a[j];\r\n\t\t\t\tsums[j-i+1] = Math.max(sums[j-i+1], sum);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n+1).fill(0);\r\n\t\tfor (let k = 0; k <= n; k++) {\r\n\t\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\t\tans[k] = Math.max(ans[k], sums[i]+Math.min(i, k)*x);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 5005;\r\nconst INF = 1e10;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, x] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst psum = []; psum[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) psum[i] = psum[i-1]+a[i];\r\n\r\n\t\tconst sums = Array(n+1).fill(-INF);\r\n\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\tfor (let j = 0; j+i-1 < n; j++) {\r\n\t\t\t\tsums[i] = Math.max(sums[i], psum[j+i-1]-psum[j-1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n+1).fill(0);\r\n\t\tfor (let k = 0; k <= n; k++) {\r\n\t\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\t\tans[k] = Math.max(ans[k], sums[i]+Math.min(i, k)*x);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const c = new Array(n).fill(-Infinity);\r\n for (let i = 0; i < n; i++) {\r\n let sum = 0;\r\n for (let j = i; j < n; j++) {\r\n sum += a[j];\r\n c[j - i] = Math.max(c[j - i], sum);\r\n }\r\n }\r\n const res = new Array(n + 1).fill(-Infinity);\r\n res[0] = Math.max(0, ...c);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n res[i + 1] = Math.max(res[i + 1], (Math.min(i, j) + 1) * m + c[j]);\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "a5927e1883fbd5e5098a8454f6f6631f"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n const dp = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp;\r\n dp[i] = Math.min(a[i] - 1, (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n }\r\n return dp.reduce((a, b) => a + b, 0);\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let a = readline().split(' ').map(Number)\r\n console.log(solve(n, a))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, a) => {\r\n let left = 0\r\n let right = 0\r\n let count = 0\r\n while (left < n) {\r\n if (right < left) right = left\r\n while (right < n && a[right] >= right - left + 1) {\r\n right++\r\n }\r\n count += right - left\r\n left++\r\n }\r\n return count\r\n}\r\n\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b)\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}], "negative_code": [], "src_uid": "4811646a6a68f6b83891bd22985ce7e5"} {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber();\n var f = read.arrNumber(' ');\n\n var res = [];\n var start = false;\n var end = false;\n for(var i = 0; i < n; i++) {\n if((a[i] < f[a[i] -1] && !end) || (a[i] == f[a[i] -1] && start && !end)) {\n res[i] = f[a[i] -1];\n start = true\n }\n else {\n res[i] = a[i];\n if(start) {\n end = true;\n }\n }\n }\n\n print(res.join(''));\n}())", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber();\n var f = read.arrNumber(' ');\n\n var res = [];\n var start = false;\n var end = false;\n for(var i = 0; i < n; i++) {\n if((a[i] < f[a[i] -1] && !end) || (a[i] == f[a[i] -1] && start && !end)) {\n res[i] = f[a[i] -1];\n start = true\n }\n else {\n res[i] = a[i];\n if(start) {\n end = true;\n }\n }\n }\n\n print(res.join(''));\n}())"}, {"source_code": "let n;\nlet a;\nlet f;\n\nconst run = () => {\n let start;\n let end;\n let el;\n let i;\n for (i = 0; i < n; ++i) {\n el = a[i];\n if (el < f[el]) {\n start = i;\n for (; i < n; ++i) {\n el = a[i];\n end = i;\n if (el > f[el]) {\n end = i - 1;\n break;\n }\n }\n break;\n }\n }\n if (start === undefined) {\n console.log(a.join(''))\n return;\n }\n console.log(a.map((e, j) => ((j >= start && (end === undefined || j <= end)) ? f[e] : e)).join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n if (a === undefined) {\n a = data.toString().trim().split('').map(Number);\n return;\n }\n f = [null, ...data.toString().trim().split(/\\s+/g).filter(Boolean).map(Number)];\n run();\n rl.close();\n})\n"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber();\n var f = read.arrNumber(' ');\n \n var res = [];\n for(var i =0 ;i < n; i++) {\n res[i] = a[i] > f[a[i] -1] ? a[i] : f[a[i] -1];\n }\n \n print(res.join(''));\n}());\n"}, {"source_code": "let n;\nlet a;\nlet f;\nconst promise = new Promise(resolve => {\n process.stdin.on('data', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n if (a === undefined) {\n a = data.toString().trim().split('').map(Number);\n return;\n }\n f = [null, ...data.toString().trim().split(/\\s+/g).filter(Boolean).map(Number)];\n resolve();\n })\n})\n\npromise.then(() => {\n let start;\n let end;\n let el;\n let k;\n let i;\n for (i = 0; i < n; ++i) {\n el = a[i];\n if (el < f[el]) {\n start = i;\n for (k = i + 1; k < n; ++k) {\n el = a[k];\n if (el > f[el]) {\n end = k;\n break;\n }\n }\n break;\n }\n }\n if (start === undefined) {\n console.log(a.join(''))\n return;\n }\n console.log(a.map((e, j) => {\n if (j >= start && (end === undefined || j <= end)) {\n return f[e];\n }\n return e;\n }).join(''))\n})\n"}, {"source_code": "let n;\nlet a;\nlet f;\nconst promise = new Promise(resolve => {\n process.stdin.on('data', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n if (a === undefined) {\n a = data.toString().split('');\n return;\n }\n f = ['x', ...data.toString().split(/\\s+/g).filter(Boolean).map(Number)];\n resolve();\n })\n})\n\npromise.then(() => {\n const b = [];\n for (let k = 1; k < 10; ++k) {\n b[k] = k < f[k];\n }\n let i = 0;\n let start;\n let end;\n for (; i < n; ++i) {\n if (b[a[i]]) {\n if (start === undefined) {\n start = i;\n } else if (end === undefined) {\n end = i;\n break;\n }\n }\n }\n console.log(a.map((e, j) => {\n if (j >= start && j <= end) {\n return f[e];\n }\n return e;\n }).join(''))\n})\n"}, {"source_code": "let n;\nlet a;\nlet f;\nconst promise = new Promise(resolve => {\n process.stdin.on('data', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n if (a === undefined) {\n a = data.toString().trim().split('').map(Number);\n return;\n }\n f = [null, ...data.toString().trim().split(/\\s+/g).filter(Boolean).map(Number)];\n resolve();\n })\n})\n\npromise.then(() => {\n let start;\n let end;\n let el;\n let k;\n let i;\n for (i = 0; i < n; ++i) {\n el = a[i];\n if (el < f[el]) {\n start = i;\n for (k = i + 1; k < n; ++k) {\n el = a[k];\n if (el >= f[el]) {\n end = k - 1;\n break;\n }\n }\n break;\n }\n }\n if (start === undefined) {\n console.log(a.join(''))\n return;\n }\n console.log(a.map((e, j) => {\n if (j >= start && (end === undefined || j <= end)) {\n return f[e];\n }\n return e;\n }).join(''))\n})\n"}], "src_uid": "378a9ab7ad891d60f23645106d24f314"} {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , prev ;\n res = ( 1 << 20 ) ;\n prev = -1 ;\n fl = 1 ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( this.arr[ i ] >= prev ) {\n \t\tprev = this.arr[ i ] ; \n \t}\n \telse {\n \t\tfl = 0 ;\n \t\tprev = -1 ;\n \t\tfor( j = i ; j < this.n ; j++ ) {\n \t\t\tif( this.arr[ j ] >= prev ) {\n\t\t \t\tprev = this.arr[ j ] ; \n\t\t \t}\n\t\t \telse {\n\t\t \t\tbreak ;\n\t\t \t}\n \t\t}\n \t\tif( j == this.n && this.arr[ this.n - 1 ] <= this.arr[ 0 ] ) {\n \t\t\tres = this.n - i ;\n \t\t}\n \t\tbreak ;\n \t}\n }\n if( fl == 1 ) {\n \tres = 0 ;\n }\n if( res == ( 1 << 20 ) ) {\n \tres = -1 ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n", "positive_code": [{"source_code": "//\n\n\nvar line = readline();\n\nvar ray = readline().split(' ');\nvar n = parseInt(line);\nvar bRay = [];\n\n\nfor(var i = 0 ; i < n ; i++) {\n\tbRay.push(parseInt(ray[i]));\n}\n\nprint(foo(n,bRay));\n\n//console.log(foo(2,[1,2]));\n\n//checker(3,[1,3,2],0);\nfunction foo(n,ray) {\n\tvar count = 0;\n\t//console.log(checker(n,bRay,1));\n\t\n\tfor(var i = 0 ; i < n-1;i++) {\n\t\tif (ray[i] > ray[i+1]) {\n\t\t\t\n\t\t\tfor(var j = 1 ; j < n ; j++) {\n\t\t\t\t//.log((j+i)%n,i);\n\t\t\t\tif ( ray[(j+i) % n] > ray[(j+i+1) %n]) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn n-(i+1);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\treturn 0;\n}\n\n/*\nfunction checker(n,ray,p) {\n//\tvar s = \"\";\n//\tvar d = \"\";\n\tfor(var i = 0 ; i < n-1 ; i++) {\n\t\t\n\t\t\n\t\tif ( ray[(i+p) %n] > ray[(i+1+p) %n]) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n\t\n\t\n\treturn true;\n}*/"}, {"source_code": "var n=parseInt(readline());\nvar ar=readline().split(\" \");\nfor(var i=0;iar[0])\n{\n for(var i=0;iar[i+1]){res=-1;break;}\n }\n}\n\nelse{res++;\nfor(var i=n-1;i>0;i--){\n\n if(ar[i]>=ar[i-1]){res++;}\nelse{\nfor(var y=0;yar[y+1]){res=-1;break;}\n}break;\n\n}\n}if(res===n){res=0;}\n}print(res);"}, {"source_code": "var l = readline()|0,\n arr = readline().split(' ').map(Number),\n inf = 0,\n steps = 0;\n \n if (arr[l-1]>arr[0]) {\n inf +=1;\n } \nfor (var i=0; i arr[i+1]) {\n inf +=1;\n steps = l-1 - i;\n }\n}\nif (inf == 0) {\n print('0');\n} else if (inf == 1){\n print(steps);\n} else {\n print('-1');\n}"}, {"source_code": ";(function () {\n\n print(function () {\n var n = +readline(),\n a = readline().split(' ').map(Number),\n d = 0, r = null;\n\n if (n === 2) {\n return a[0] <= a[1] ? 0 : 1;\n }\n\n a = a.concat([a[0]]);\n\n a.forEach(function (e, i, a) {\n if (i === 0) return;\n if (e < a[i - 1]) {\n d++;\n r = i;\n }\n });\n\n if (d === 0) return 0;\n if (d > 1) return -1;\n return n - r;\n }.call(this));\n\n}.call(this));\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tvalues = tokenizeIntegers(readline());\n\tfor (var seek = 1; seek < n; ++seek) {\n\t\tif (values[seek-1] > values[seek]) {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (seek == n) {\n\t\treturn 0;\n\t}\n\tvar end = seek-1;\n\tfor (var i = end+2; i < n; ++i) {\n\t\tif (values[i-1] > values[i]) {\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (values[n-1] > values[0]) {\n\t\treturn -1;\n\t}\n\treturn n-end-1;\n}\n\nprint(main());\n"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar ind = -1;\nfor (var i=0; is[i+1]) {\n\t\tind = i+1;\n\t\ts = s.slice(ind).concat(s.slice(0, ind));\n\t\tbreak;\n\t}\n}\nif (ind == -1) print(0);\nelse {\n\tfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tind = -1;\n\t\tbreak;\n\t\t}\n\t}\n\tif (ind != -1) print(n-ind);\n}"}], "negative_code": [{"source_code": "//\n\n\nvar line = readline();\n\nvar ray = readline().split(' ');\nvar n = parseInt(line);\nvar bRay = [];\n\n\nfor(var i = 0 ; i < n ; i++) {\n\tbRay.push(parseInt(ray[i]));\n}\n\nprint(foo(n,bRay));\n\n//console.log(foo(4,[3,4,1,2]));\n\n//checker(3,[1,3,2],0);\nfunction foo(n,ray) {\n\tvar count = 0;\n\t//console.log(checker(n,bRay,1));\n\t\n\tfor(var i = 0 ; i < n-1;i++) {\n\t\tif (ray[i] > ray[i+1]) {\n\t\t\t\n\t\t\tfor(var j = 1 ; j < n ; j++) {\n\t\t\t\t//.log((j+i)%n,i);\n\t\t\t\tif ( ray[(j+i) % n] > ray[(j+i+1) %n]) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn i+1;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\treturn 0;\n}\n\n/*\nfunction checker(n,ray,p) {\n//\tvar s = \"\";\n//\tvar d = \"\";\n\tfor(var i = 0 ; i < n-1 ; i++) {\n\t\t\n\t\t\n\t\tif ( ray[(i+p) %n] > ray[(i+1+p) %n]) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n\t\n\t\n\treturn true;\n}*/"}, {"source_code": "//\n\n\nvar line = readline();\n\nvar ray = readline().split(' ');\nvar n = parseInt(line);\nvar bRay = [];\n\n\nfor(var i = 0 ; i < n ; i++) {\n\tbRay.push(parseInt(ray[i]));\n}\n\nprint(foo(n,bRay));\n\n//console.log(foo(3,[1,3,2]));\nfunction foo(n,bRay) {\n\tvar count = 0;\n\t//console.log(checker(n,bRay,1));\n\t\n\t\t\n\t\n\t\tfor(var i = 0 ; i < n ; i++) {\n\t\t\t\n\t\t\t\n\t\t\tif ( checker(n,bRay,i)) {\n\t\t\t\t//console.log(checker(n,bRay,i),n,bRay,i);\n\t\t\t\treturn count;\n\t\t\t}\n\t\t\tcount++;\n\t\t\n\t\t\n\t\t\n\t\t}\n\t\n\t\n\treturn -1;\n\t\n\t\n}\n\nfunction checker(n,ray,p) {\n\t//console.log(n,ray,p);\n\tfor(var i = 0 ; i < n ; i++) {\n\t\t\n\t\tvar j = (i+p) %n ;\n\t\t//console.log(ray[j]);\n\t\tif ( ray[j] > ray[(j+1)%n]) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n\t//console.log(\"e\");\n\treturn true ;\n\t\n}"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , prev ;\n res = ( 1 << 20 ) ;\n prev = -1 ;\n fl = 1 ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( this.arr[ i ] >= prev ) {\n \t\tprev = this.arr[ i ] ; \n \t}\n \telse {\n \t\tfl = 0 ;\n \t\tprev = -1 ;\n \t\tfor( j = i ; j < this.n ; j++ ) {\n \t\t\tif( this.arr[ i ] >= prev ) {\n\t\t \t\tprev = this.arr[ i ] ; \n\t\t \t}\n\t\t \telse {\n\t\t \t\tbreak ;\n\t\t \t}\n \t\t}\n \t\tif( j == this.n && this.arr[ this.n - 1 ] <= this.arr[ 0 ] ) {\n \t\t\tres = this.n - i ;\n \t\t}\n \t\tbreak ;\n \t}\n }\n if( fl == 1 ) {\n \tres = 0 ;\n }\n if( res == ( 1 << 20 ) ) {\n \tres = -1 ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar min = 1000000;\nvar ind = 0;\nvar count = 0;\nfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tmin = 10000000;\n\t\tbreak;\n\t}\n\tif (s[i]==s[i+1]) {\n\t\tcount++;\n\t}\n}\nif (min != 10000000) {\n\tif (ind == 0 || count == n-1) print(0);\n\telse print(n-ind);\n}"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar min = 1000000;\nvar ind = 0;\nfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tmin = 10000000;\n\t\tbreak;\n\t}\n}\nif (min != 10000000) {\n\tif (ind == 0) print(0);\n\telse print(n-ind);\n}"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar min = Math.min.apply(null, s);\nvar ind = s.indexOf(min);\nvar count = 0;\ns = s.slice(ind).concat(s.slice(0, ind));\nfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tmin = 10000000;\n\t\tbreak;\n\t}\n\tif (s[i]==s[i+1]) {\n\t\tcount++;\n\t}\n}\nif (min != 10000000) {\n\tif (ind == 0 || count == n-1) print(0);\n\telse print(n-ind);\n}"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar min = 1000000;\nvar ind = 0;\nfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tmin = 10000000;\n\t\tbreak;\n\t}\n}\nif (min != 10000000) {\n\tif (ind == 0) print(0);\n\telse print(n-ind);\n}"}, {"source_code": "var n = +readline();\nvar s = readline().split(' ').map(Number);\nvar min = 1000000;\nvar ind = 0;\nfor (var i=0; is[i+1]) {\n\t\tprint(-1);\n\t\tmin = 10000000;\n\t\tbreak;\n\t}\n}\nif (min != 10000000) {\n\tif (ind == 0) print(0);\n\telse print(n-ind);\n}\n"}, {"source_code": "var n=parseInt(readline());\nvar ar=readline().split(\" \");\n\nvar res=0;\n\nif(parseInt(ar[n-1])>parseInt(ar[0]))\n{\n for(var i=0;iparseInt(ar[i+1])){res=-1;break;}\n }\n}\n\nelse{\nres++;\nfor(var i=n-1;i>0;i--){\n\n if(parseInt(ar[i-1])<=parseInt(ar[i])){res++;}\nelse{\nfor(var y=i-1;y>0;y--){\n if(parseInt(ar[y])parseInt(ar[0])){\nfor(var i=0;iparseInt(ar[i+1])){res=-1;break;}\n}\n}\nelse{\nres++;\nfor(var i=n-1;i>0;i--){\n\nif(parseInt(ar[i-1])0;y--){\nif(parseInt(ar[y])ar[0])\n{\n for(var i=0;iar[i+1]){res=-1;break;}\n }\n}\n\nelse{res++;\nfor(var i=n-1;i>0;i--){\n\n if(ar[i]>ar[i-1]){res++;}\nelse{\nfor(var y=0;yar[y+1]){res=-1;break;}\n}break;\n\n}\n}\n}print(res);"}, {"source_code": "var l = readline()|0,\n arr = readline().split(' ').map(Number),\n chkr = false,\n chk = false;\n\nwhile (chkr == false) { \n var res = 0;\n for (var i = 0; i < l-1; i++) {\n if (arr[i] > arr[i+1]) {\n arr.unshift(arr.pop(arr[l-1]));\n chkr = false;\n break;\n }\n chkr = true;\n chk = true;\n res += 1;\n }\n if (res >= l-1) {\n chkr = true;\n chk = false; \n }\n}\nif (chk == true) {\n print(res);\n} \nelse {\n print (\"-1\");\n}"}, {"source_code": ";(function () {\n\n print(function () {\n var n = +readline(),\n a = readline().split(' ').map(Number),\n d = 0, r = null;\n\n if (n === 2) {\n return a[0] <= a[1] ? 0 : 1;\n }\n\n a.forEach(function (e, i, a) {\n if (i === 0) return;\n if (e < a[i - 1]) {\n d++;\n r = i;\n }\n });\n\n if (d === 0) return 0;\n if (d > 1) return -1;\n return n - r;\n }.call(this));\n\n}.call(this));\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tvalues = tokenizeIntegers(readline());\n\tfor (var seek = 1; seek < n; ++seek) {\n\t\tif (values[seek-1] > values[seek]) {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (seek == n) {\n\t\treturn 0;\n\t}\n\tvar end = seek-1;\n\tfor (var i = end+2; i < n; ++i) {\n\t\tif (values[i-1] > values[i]) {\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (values[n-1] > values[0]) {\n\t\treturn -1;\n\t}\n\treturn Math.min(end+1, n-end-1);\n}\n\nprint(main());\n"}, {"source_code": "//\n\n\nvar line = readline();\n\nvar ray = readline().split(' ');\nvar n = parseInt(line);\nvar bRay = [];\n\n\nfor(var i = 0 ; i < n ; i++) {\n\tbRay.push(parseInt(ray[i]));\n}\n\nprint(foo(n,bRay));\n\n//console.log(foo(2,[2,1]));\nfunction foo(n,bRay) {\n\tvar count = 0;\n\t//console.log(checker(n,bRay,1));\n\tif ( !checker(n,bRay,0) ) {\n\t\t\n\t\n\t\tfor(var i = 1 ; i < n ; i++) {\n\t\t\t\n\t\t\tcount++;\n\t\t\tif ( checker(n,bRay,i)) {\n\t\t\t\treturn count;\n\t\t\t}\n\t\t\n\t\t\n\t\t\n\t\t}\n\t}\n\t\n\telse {\n\t\treturn 0;\n\t}\n\t\n\treturn -1;\n\t\n\t\n}\n\nfunction checker(n,ray,p) {\n\tfor(var i = 0 ; i < n-1 ; i++) {\n\t\tvar j = (i+p) %n ;\n\t\tif ( ray[j] > ray[j+1]) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n\t\n\treturn true ;\n\t\n}"}], "src_uid": "c647e36495fb931ac72702a12c6bfe58"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction abs(a) {\r\n return Math.max(a, -a);\r\n}\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let is = 0\r\n const map = new Map()\r\n let n = Number(readline())\r\n let a = readline().split(' ').map(Number)\r\n for (let i = 0; i < n; i++) {\r\n if (map.has(a[i]))\r\n map.set(a[i], map.get(a[i]) + 1)\r\n else\r\n map.set(a[i], 1)\r\n if (map.get(a[i]) >= n / 2)\r\n is = 1\r\n }\r\n if (is) {\r\n console.log(-1)\r\n continue\r\n }\r\n let ans = 0\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let big = abs(a[i] - a[j])\r\n for (let cand = 1; cand * cand <= big; cand++) {\r\n let count = 0\r\n if (big % cand) continue;\r\n for (let k = 0; k < n; k++) {\r\n if (abs(a[i] - a[k]) % cand) continue;\r\n count++\r\n }\r\n if (count >= n / 2)\r\n ans = Math.max(cand, ans)\r\n count = 0\r\n let cand1=big/cand\r\n if (big % cand1) continue;\r\n for (let k = 0; k < n; k++) {\r\n if (abs(a[i] - a[k]) % cand1) continue;\r\n count++\r\n }\r\n if (count >= n / 2)\r\n ans = Math.max(cand1, ans)\r\n }\r\n }\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('ascii');\r\nlet input = '';\r\nprocess.stdin.on('data', (data) => {\r\n input += data;\r\n});\r\nprocess.stdin.on('end', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nclass Scanner {\r\n constructor(input) {\r\n this.words = [];\r\n this.pos = 0;\r\n input.split('\\n').forEach((line) => {\r\n this.words.push.apply(this.words, line.split(' ').filter(s => s != ''));\r\n });\r\n }\r\n nextInt() {\r\n return Math.floor(Number(this.words[this.pos++]));\r\n }\r\n nextBigInt() {\r\n return BigInt(this.nextInt());\r\n }\r\n nextStr() {\r\n return this.words[this.pos++];\r\n }\r\n eof() {\r\n return this.pos >= this.words.length;\r\n }\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet a;\r\nfunction same() {\r\n let cnt = new Map();\r\n for (let i = 0; i < n; i++) {\r\n cnt.set(a[i], (cnt.get(a[i]) || 0) + 1);\r\n }\r\n for (let [k, v] of cnt) {\r\n if (v * 2 >= n) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\nfunction main() {\r\n const sc = new Scanner(input);\r\n let tc = sc.nextInt();\r\n while (tc-- > 0) {\r\n n = sc.nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = sc.nextInt();\r\n }\r\n if (same()) {\r\n process.stdout.write(`-1\\n`);\r\n continue;\r\n }\r\n let divs = [];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let diff = Math.abs(a[i] - a[j]);\r\n for (let k = 1; k * k <= diff; k++) {\r\n if ((diff % k) == 0) {\r\n divs.push(diff / k);\r\n divs.push(k);\r\n }\r\n }\r\n }\r\n }\r\n divs = Array.from(new Set(divs));\r\n let ans = 0;\r\n for (let div of divs) {\r\n for (let i = 0; i < n; i++) {\r\n let cnt = 0;\r\n for (let j = 0; j < n; j++) {\r\n let diff = Math.abs(a[i] - a[j]);\r\n if ((diff % div) == 0) {\r\n cnt++;\r\n }\r\n }\r\n if (cnt * 2 >= n) {\r\n ans = Math.max(ans, div);\r\n }\r\n }\r\n }\r\n process.stdout.write(`${ans}\\n`);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n map[x] = (map[x] || 0) + 1\n if (map[x] >= n / 2) return -1\n }\n\n let ans = -1\n for (let i = 0; i < arr.length; i++) {\n // set arr[i] as target\n const ds = []\n for (let j = 0; j < arr.length; j++) {\n ds[j] = arr[j] - arr[i]\n }\n // try each possible gcd\n const gs = {}\n for (let j = 0; j < arr.length; j++) {\n if (ds[j] <= 0) continue\n gs[ds[j]] = 1\n\n for (let k = 0; k < arr.length; k++) {\n if (k === i || k === j || ds[k] <= 0) continue\n\n const g = gcd(ds[j], ds[k])\n gs[g] = 1\n }\n }\n for (let g in gs) {\n g = +g\n if (g > ans) {\n let count = map[arr[i]] // already\n for (let x = 0; x < arr.length; x++) {\n if (ds[x] <= 0 || (ds[x] % g)) continue\n count++\n }\n // console.log(`target=${arr[i]} g=${g} count=${count}`)\n if (count >= n / 2) ans = g\n }\n }\n }\n return ans\n}\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n map[x] = (map[x] || 0) + 1\n if (map[x] >= n / 2) return -1\n }\n\n let ans = -1\n for (let i = 0; i < arr.length; i++) {\n // set arr[i] as target\n const ds = []\n for (let j = 0; j < arr.length; j++) {\n ds[j] = arr[j] - arr[i]\n }\n // try each possible gcd\n const gs = {}\n for (let j = 0; j < arr.length; j++) {\n for (let k = 0; k < arr.length; k++) {\n if (k === i || k === j || ds[j] <= 0) continue\n\n const g = gcd(ds[j], ds[k])\n gs[g] = 1\n }\n }\n for (let g in gs) {\n g = +g\n if (g > ans) {\n let count = map[arr[i]] // already\n for (let x = 0; x < arr.length; x++) {\n if (ds[x] <= 0 || (ds[x] % g)) continue\n count++\n }\n // console.log(`target=${arr[i]} g=${g} count=${count}`)\n if (count >= n / 2) ans = g\n }\n }\n }\n return ans\n}\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}], "src_uid": "432411e161af5ef14803e946e2f7fbc3"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n const sum = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + (s[i] === 'B' ? 0 : 1);\r\n }\r\n let res = Infinity;\r\n for (let i = m - 1; i < n; i++) {\r\n var _sum2;\r\n res = Math.min(res, sum[i] - ((_sum2 = sum[i - m]) !== null && _sum2 !== void 0 ? _sum2 : 0));\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, m, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n,k] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr = readline().trim().split(\"\");\r\n let min = Infinity,i=0,cnt = 0,j=0;\r\n while(i+x);\r\n let str = readline().trim();\r\n console.log(`${solve(str, n, k)}`)\r\n}\r\n\r\nfunction solve(str, n, k){\r\n let result = n;\r\n let currW = 0;\r\n for(let i = 0; i < n; i++){\r\n if(str[i] === 'W') currW++;\r\n \r\n if(i-k +1 >= 0){\r\n result = Math.min(result, currW);\r\n if(str[i-k+1] === \"W\") currW--;\r\n }\r\n if(result === 0) break;\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, k, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nlet F\nfunction inc(idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n\nfunction solve(n, k, str) {\n F = Array(n + 5).fill(0)\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'B') {\n inc(i, 1)\n }\n }\n let ans = Infinity\n for (let i = 0; i + k - 1 < str.length; i++) {\n // [i, i + k - 1]\n const d = sum(i + k - 1) - (i ? sum(i - 1) : 0)\n // console.log(i, k - d)\n ans = Math.min(ans, k - d)\n }\n // console.log('-')\n return ans\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = next();\r\n\t\tvar sum = new Array(N + 1).fill(0);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == \"W\"){\r\n\t\t\t\tsum[i + 1]++;\r\n\t\t\t}\r\n\t\t\tsum[i + 1] += sum[i];\r\n\t\t}\r\n\t\tvar output = 1000000000;\r\n\t\tfor(var i = 0; i < N - K + 1; i++){\r\n\t\t\toutput = Math.min(output, sum[i + K] - sum[i]);\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n, k;\r\n var s;\r\n for (var t=0; t < tests; t++) {\r\n var nk = readline().split(' ').map(x=>parseInt(x));\r\n n = nk[0];\r\n k = nk[1];\r\n var s = readline();\r\n var dict = {\r\n B: 0,\r\n W: 0,\r\n }\r\n for (var i = 0; i < k; i++) {\r\n dict[s.charAt(i)]++;\r\n }\r\n var minW = dict.W;\r\n for (var i = k; i < n; i++) {\r\n dict[s.charAt(i)]++;\r\n dict[s.charAt(i-k)]--;\r\n if (dict.W < minW) {\r\n minW = dict.W;\r\n }\r\n }\r\n print(minW);\r\n }"}], "negative_code": [], "src_uid": "6e3bacbe61775883599989d0f61367d5"} {"source_code": "var pearlsAmount = readline();\nvar typesOfPearls = readline().split(' ');\nvar segmentsEndPoints = [];\nvar amountOfSegments = 0;\nvar typesExistence = [];\nfor (var i = 0; i < pearlsAmount; i++) {\n if (typesExistence[typesOfPearls[i]]) {\n amountOfSegments++;\n segmentsEndPoints.push(i+1);\n typesExistence.length = 0;\n } else {\n typesExistence[typesOfPearls[i]] = 1;\n }\n}\n\nif (amountOfSegments == 0) {\n print(\"-1\");\n} else {\n segmentsEndPoints.pop();\n segmentsEndPoints.push(pearlsAmount);\n print(amountOfSegments);\n var startPoint = 1;\n for (var i = 0; i < amountOfSegments; i++) {\n print(startPoint + \" \" + segmentsEndPoints[i]);\n startPoint = segmentsEndPoints[i] + 1;\n }\n}", "positive_code": [{"source_code": "var pearlsAmount = readline();\nvar typesOfPearls = readline().split(' ');\nvar segmentsEndPoints = [];\nvar amountOfSegments = 0;\nvar typesExistence = [];\nfor (var i = 0; i < pearlsAmount; i++) {\n if (typesExistence[typesOfPearls[i]]) {\n amountOfSegments++;\n segmentsEndPoints.push(i+1);\n typesExistence = [];\n } else {\n typesExistence[typesOfPearls[i]] = 1;\n }\n}\n\nif (amountOfSegments == 0) {\n print(\"-1\");\n} else {\n segmentsEndPoints.pop();\n segmentsEndPoints.push(pearlsAmount);\n print(amountOfSegments);\n var startPoint = 1;\n for (var i = 0; i < amountOfSegments; i++) {\n print(startPoint + \" \" + segmentsEndPoints[i]);\n startPoint = segmentsEndPoints[i] + 1;\n }\n}"}, {"source_code": "var n = readline();\nvar pearls = readline().split(' ');\n\nvar counter = [];\n\nvar result = [];\nvar rLength = 0;\n\nvar i;\nvar start_idx = 0;\n\npearls.map(function(x, idx) {\n x = parseInt(x, 10);\n if(!counter[x]) {\n counter[x] = 1;\n } else {\n result[rLength] = [start_idx + 1, idx +1];\n start_idx = idx + 1;\n rLength = rLength + 1;\n counter = [];\n }\n});\n\nif (rLength == 0) {\n print(\"-1\");\n}\nelse {\n result[rLength-1][1] = parseInt(n, 10);\n\n print(rLength);\n for (i = 0; i < rLength; i++){\n print(result[i][0]+ ' ' + result[i][1]);\n }\n}"}, {"source_code": "var pearlsAmount = readline();\nvar typesOfPearls = readline().split(' ');\nvar segmentsEndPoints = [];\nvar amountOfSegments = 0;\nvar object = {};\nfor (var i = 0; i < pearlsAmount; i++) {\n if (object[typesOfPearls[i]]) {\n amountOfSegments++;\n segmentsEndPoints.push(i+1);\n object = {};\n } else {\n object[typesOfPearls[i]] = 1;\n }\n}\n\nif (amountOfSegments == 0) {\n print(\"-1\");\n} else {\n segmentsEndPoints.pop();\n segmentsEndPoints.push(pearlsAmount);\n print(amountOfSegments);\n var startPoint = 1;\n for (var i = 0; i < amountOfSegments; i++) {\n print(startPoint + \" \" + segmentsEndPoints[i]);\n startPoint = segmentsEndPoints[i] + 1;\n }\n}"}], "negative_code": [{"source_code": "var n = readline();\nvar pearls = readline().split(' ');\n\nvar counter = [];\n\nvar result = [];\nvar rLength = 0;\n\nvar i;\nvar start_idx = 0;\n\npearls.map(function(x, idx) {\n x = parseInt(x, 10);\n if(!counter[x]) {\n counter[x] = 1;\n } else {\n result[rLength] = [start_idx + 1, idx +1];\n start_idx = idx + 1;\n counter = [];\n }\n});\n\nif (rLength == 0) {\n print(\"-1\\r\\n\");\n}\nelse {\n result[rLength-1][1] = parseInt(n, 10);\n\n print(\"rLength\\r\\n\");\n for (i = 0; i < rLength; i++){\n print(\"result[i][0] result[i][1]\\n\");\n }\n}\n"}, {"source_code": "var n = readline();\nvar pearls = readline().split(' ');\n\nvar counter = [];\n\nvar result = [];\nvar rLength = 0;\n\nvar i;\nvar start_idx = 0;\n\npearls.map(function(x, idx) {\n x = parseInt(x, 10);\n if(!counter[x]) {\n counter[x] = 1;\n } else {\n result[rLength] = [start_idx + 1, idx +1];\n start_idx = idx + 1;\n rLength = rLength + 1;\n counter = [];\n }\n});\n\nif (rLength == 0) {\n print(\"-1\\r\\n\");\n}\nelse {\n result[rLength-1][1] = parseInt(n, 10);\n\n print(\"rLength\\r\\n\");\n for (i = 0; i < rLength; i++){\n print(\"result[i][0] result[i][1]\\n\");\n }\n}\n\n\n\n\n/*\n #include \n int main(void) {\n int i;\n int start_idx = 0;\n\n scanf(\"%d\", &n);\n\n for (i = 0; i < n; i++) {\n scanf(\"%d\", &pearls[i]);\n\n if (increase_count(pearls[i]) == 0) {\n insert_new_pearl(pearls[i]);\n }\n else { // 2\uac1c\uac00 \ub418\ub294 \uc21c\uac04\uc784\n result[result_length][0] = start_idx + 1;\n result[result_length++][1] = i + 1;\n start_idx = i + 1;\n length = 0;\n }\n }\n\n result[result_length-1][1] = n;\n\n if (result_length == 0) {\n printf(\"-1\\n\");\n }\n else {\n printf(\"%d\\n\", result_length);\n\n for (i = 0; i < result_length; i++){\n printf(\"%d %d\\n\", result[i][0], result[i][1]);\n }\n }\n\n return 0;\n }\n */"}], "src_uid": "4cacec219e4577b255ddf6d39d308e10"} {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n add = Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n add = Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n add = Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n add = Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n \n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}", "positive_code": [{"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? -1 : 1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var sr = [x, y, z, w];\n sr.sort(mp)\n add = Math.min(Math.abs(sr[0] - sr[1]) + Math.abs(sr[2] - sr[1]) + Math.abs(sr[3] - sr[1]),\n Math.abs(sr[0] - sr[2]) + Math.abs(sr[1] - sr[2]) + Math.abs(sr[3] - sr[2])\n ,Math.abs(sr[1] - sr[0]) + Math.abs(sr[2] - sr[0]) + Math.abs(sr[3] - sr[0])\n ,Math.abs(sr[0] - sr[3]) + Math.abs(sr[1] - sr[3]) + Math.abs(sr[2] - sr[3]));\n\n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "'use strict'\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0];\n var y = ip[1];\n var grid = new Array(x);\n for (var n = 0; n < x; n++) {\n grid[n] = readline().split(' ').map(x => parseInt(x));\n }\n var res = 0;\n for (var n = 0; n < x; n++) {\n for (var k = 0; k < y; k++) {\n var a = grid[n][k];\n var b = grid[x - 1 - n][k];\n var c = grid[n][y - 1 - k];\n var d = grid[x - 1 - n][y - 1 - k];\n var tm = [a, b, c, d];\n tm.sort((x, y) => { return x > y });\n var md = tm[3] - tm[0] + tm[2] - tm[1]\n res += md\n /**/\n }\n }\n\n print(Math.floor(res / 4))\n}\n\nvar tc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "'use strict'\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0];\n var y = ip[1];\n var grid = new Array(x);\n for (var n = 0; n < x; n++) {\n grid[n] = readline().split(' ').map(x => parseInt(x));\n }\n var res = 0;\n for (var n = 0; n < x; n++) {\n for (var k = 0; k < y; k++) {\n var a = grid[n][k];\n var b = grid[x - 1 - n][k];\n var c = grid[n][y - 1 - k];\n var d = grid[x - 1 - n][y - 1 - k];\n var tm = [a, b, c, d];\n tm.sort((x, y) => { return x > y });\n var md = tm[3] - tm[0] + tm[2] - tm[1]\n res += md\n /**/\n }\n }\n\n print(Math.floor(res / 4))\n}\n\nvar tc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [_row, _col] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = [];\n for (let i = 0; i < _row; i++) {\n const r = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.push(r);\n }\n\n let count = 0;\n\n for (let row = 0; row < _row; row++) {\n for (let col = 0; col < _col / 2; col++) {\n let nums = [arr[row][col], arr[_row - 1 - row][col], arr[row][_col - 1 - col]];\n nums.sort((a, b) => a - b);\n const target = nums[1];\n count += Math.abs(target - nums[0]) + Math.abs(target - nums[1]) + Math.abs(target - nums[2]);\n [arr[row][col], arr[_row - 1 - row][col], arr[row][_col - 1 - col]] = [target, target, target];\n }\n }\n console.log(count);\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let [n, m] = $(2), res = 0\n let a = Arr(n, i => $(m))\n // log(a)\n For((n + 1) / 2 | 0, i => {\n For((m + 1) / 2 | 0, j => {\n let a1 = a[i][j], a2 = a[n - 1 - i][j], a3 = a[i][m - 1 - j], a4 = a[n - 1 - i][m - 1 - j];\n let s = min(\n abs(a2-a1)+abs(a3-a1)+abs(a4-a1),\n abs(a1-a2)+abs(a3-a2)+abs(a4-a2),\n abs(a1-a3)+abs(a2-a3)+abs(a4-a3),\n abs(a1-a4)+abs(a2-a4)+abs(a3-a4),\n )\n if (i == n - 1 - i) s /= 2;\n if (j == m - 1 - j) s /= 2;\n res += s;\n })\n })\n log(res)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let mat = new Array(n);\n for(let i = 0; i < n; i++){\n mat[i] = ti(readline().split(' '));\n }\n\n let count = 0;\n for(let i = 0; i < n/2; i++){\n for(let j = 0; j < m/2; j++){\n let a = [];\n if(i !== n-i-1 && j !== m-j-1){\n a = [mat[i][j], mat[i][m-j-1], mat[n-i-1][j], mat[n-i-1][m-j-1]];;\n }else{\n a = [mat[i][j], mat[n-i-1][m-j-1]];\n }\n a.sort((a,b) => a-b);\n if(a.length === 4)\n count += Math.abs(a[0]-a[1]) + Math.abs(a[1]-a[2]) + Math.abs(a[1]-a[3]);\n else\n count += Math.abs(a[0]-a[1]);\n }\n }\n\n console.log(count);\n }\n}\n"}], "negative_code": [{"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a; a++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\nn = 1\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0] / 2; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n print(ans)\n }\n }\n print(ans); // odd rows cols not handel yet xD\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line)\n }\n \n print(arr[0]);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\nn = 1\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0]; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n print(ans)\n }\n }\n print(ans); // odd rows cols not handel yet xD\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line)\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n print(a, b)\n for(var i = 0; i < a; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line[0]);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0]; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n print(ans); // odd rows cols not handel yet xD\n }\n }\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n print(n)\n for(var i = 0; i < a; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line[0]);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\nn = 1\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < (a[0] + 1) / 2; i++) {\n print(i)\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0]; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n \n }print(ans); // odd rows cols not handel yet xD\n }\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? -1 : 1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var sr = [x, y, z, w];\n sr.sort(mp)\n add = Math.min(Math.abs(sr[0] - sr[1]) + Math.abs(sr[2] - sr[1]) + Math.abs(sr[3] - sr[1]),\n Math.abs(sr[0] - sr[2]) + Math.abs(sr[1] - sr[2]) + Math.abs(sr[3] - sr[2]));\n\n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? -1 : 1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n toSort.sort(mp)\n\n add = Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n \n \n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a; a++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n print(line)\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var sr = [x, y, z, w];\n\n add = Math.min(Math.abs(sr[0] - sr[1]) + Math.abs(sr[2] - sr[1]) + Math.abs(sr[3] - sr[1]),\n Math.abs(sr[0] - sr[2]) + Math.abs(sr[1] - sr[2]) + Math.abs(sr[3] - sr[2]));\n\n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < (a[0] + 1) / 2; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0]; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n \n }\n }\n print(ans); // odd rows cols not handel yet xD\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const map = new Map();\n const [_row, _col] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = [];\n for (let i = 0; i < _row; i++) {\n const r = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n map.set(n, n);\n return n;\n });\n arr.push(r);\n }\n\n let min = Infinity;\n for (let [key, value] of map) {\n let count = 0;\n for (let row = 0; row < _row; row++) {\n for (let col = 0; col < _col; col++) {\n const diff = Math.abs(arr[row][col] - key);\n count += diff;\n }\n }\n min = Math.min(min, count);\n }\n\n console.log(min);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [_row, _col] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = [];\n for (let i = 0; i < _row; i++) {\n const r = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.push(r);\n }\n\n let count = 0;\n\n for (let row = 0; row < _row; row++) {\n for (let col = 0; col < Math.floor(_col / 2); col++) {\n let nums = [arr[row][col], arr[_row - 1 - row][col], arr[row][_col - 1 - col]];\n nums.sort((a, b) => a - b);\n const target = nums[1];\n count += Math.abs(target - nums[0]) + Math.abs(target - nums[1]) + Math.abs(target - nums[2]);\n [arr[row][col], arr[_row - 1 - row][col], arr[row][_col - 1 - col]] = [target, target, target];\n }\n }\n console.log(count);\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let [n, m] = $(2), res = 0\n let a = Arr(n, i => $(m))\n // log(a)\n For((n + 1) / 2 | 0, i => {\n For((m + 1) / 2 | 0, j => {\n let a1 = a[i][j], a2 = a[n - 1 - i][j], a3 = a[i][m - 1 - j], a4 = a[n - 1 - i][m - 1 - j];\n // log(i, j, a1, a2, a3, a4)\n let tb = Math.round((a1 + a2 + a3 + a4) / 4)\n let s = abs(a1 - tb) + abs(a2 - tb) + abs(a3 - tb) + abs(a4 - tb);\n if (i == n - 1 - i || j == m - 1 - j) s /= 2;\n res += s;\n })\n })\n log(res)\n }\n}\n"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n \n for(var i = 0; i < a[0]; i++) {\n var l = 0, r = a[1] - 1;\n while(l < r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n ans += Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n ans += Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n ans += Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n ans += Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n l++, r--;\n print(ans)\n }\n }\n print(ans); // odd rows cols not handel yet xD\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a, b = readline().split(' ').map(mp);\n var arr = [];\n for(var i = 0; i < a; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line[0]);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n \n add = Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n \n \n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n obj[x] = (obj[x] ? obj[x] + 1 : 1);\n obj[y] = (obj[y] ? obj[y] + 1 : 1);\n obj[z] = (obj[z] ? obj[z] + 1 : 1);\n obj[w] = (obj[w] ? obj[w] + 1 : 1);\n if(obj[x] == 1 && obj[y] == 1 && obj[z] == 1 && obj[w] == 1) {\n toSort.sort(cmp);\n add = Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n }else {\n if(obj[x] != 1) {\n add = Math.abs(y - x) + Math.abs(z - x) + Math.abs(w - x);\n }else if(obj[y] != 1) {\n add = Math.abs(x - y) + Math.abs(z - y) + Math.abs(w - y);\n }else {\n add = Math.abs(x - z) + Math.abs(y - z) + Math.abs(w - z);\n }\n }\n \n if(l == r || i + 1 == m) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n print(a)\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line[0]);\n }\n \n print(arr);\n}"}, {"source_code": "function i(v) {\n return parseInt(v);\n}\n\nfunction f(v) {\n return parseFloat(v);\n}\n\nfunction cmp(a, b) {\n return a - b > 0 ? 1 : -1;\n}\n\nfunction mp(v) {\n return parseInt(v); \n}\n\nvar n = i(readline());\n\nwhile(n--) {\n var a = readline().split(' ').map(mp);\n var arr = [];\n var ans = 0;\n for(var i = 0; i < a[0]; i++) {\n var line = readline().split(' ').map(mp);\n arr.push(line);\n }\n var m = parseInt((a[0] + 1) / 2)\n for(var i = 0; i < m; i++) {\n var l = 0, r = a[1] - 1;\n while(l <= r) {\n var obj = {};\n var x = arr[i][l];\n var y = arr[i][r];\n var z = arr[a[0] - i - 1][l];\n var w = arr[a[0] - i - 1][r];\n var toSort = [x, y, z, w];\n toSort.sort(mp)\n add = Math.min(-toSort[0] + toSort[2] + toSort[3] - toSort[1],\n -toSort[0] - toSort[1] + toSort[2] + toSort[3]);\n \n \n if(l == r || (i + 1 == m && a[0] % 2)) ans += parseInt(add / 2)\n else ans += add\n l++, r--;\n }\n }\n print(ans); \n}"}], "src_uid": "5aa709f292f266799f177b174c8bc14b"} {"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\nlet N = lll[0]\nlet ls = []\nlet rs = []\nfor (let i = 0; i < lll[1]; i++) {\n let ll = readline().split(' ')\n ;(ll[2] == 'left' ? ls : rs).push(+ll[ll.length - 1])\n}\n\nlet bs = []\n\nlet n = N\nwhile(n--) {\n bs.push(true)\n}\n\nls = ls.sort((a, b) => a - b)\nrs = rs.sort((a, b) => a - b)\n\nlet ml = ls.length ? ls[0] : N + 1\nlet mr = rs.length ? rs[rs.length - 1] : 0\n\nlet r = ml - mr - 1\n\nprint(r <= 0 ? -1 : r)", "positive_code": [{"source_code": "var getNums = function() {\n\treturn readline().split(' ').map(function(a) {return parseInt(a)});\n};\n\nvar input;\ninput = getNums();\nvar n1 = input[0];\nvar n2 = input[1];\nvar left = 1, right = n1;\n\nfor (var i = 0; i < n2; i++) {\n\tinput = readline();\n\tvar j;\n\tif (input.match(/To the left of/)) {\n\t\tj = parseInt(input.replace('To the left of ',''));\n\t\tright = Math.min(right, j - 1);\n\t} else {\n\t\tj = parseInt(input.replace('To the right of ',''));\n\t\tleft = Math.max(left, j + 1);\n\t}\n}\n\nif (left > right) {\n\tprint(-1);\n} else {\n\tprint(right - left + 1);\n}"}], "negative_code": [], "src_uid": "dabeb9852332f6a6e730acab7fe61a5c"} {"source_code": "var n = +readline();\nvar arr = [];\nfor (var i = 0; i < n; i++) {\n arr[i] = 0;\n}\nfor (var i = 1; i < n; i++) {\n var point = readline().split(' ').map(item => +item - 1);\n arr[point[0]]++;\n arr[point[1]]++;\n}\nprint(arr.find(item => item === 2) ? 'NO' : 'YES');\n", "positive_code": [{"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar n = +readline();\nvar A = new Array(Math.pow(10, 5) + 100).fill(0);\nfor (var i = 0; i < n - 1; ++i) {\n var input = readline().split(' ').map(value => +value);\n var u = input[0];\n var v = input[1];\n \n ++A[u];\n ++A[v];\n}\n\nvar result = 'YES';\nfor (var i = 1; i <= n; ++i) {\n if (A[i] === 2) {\n result = 'NO';\n break;\n }\n}\n\nwrite(result);"}], "negative_code": [], "src_uid": "ba47e6eea45d32cba660eb6d66a9adbb"} {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = new Array(n).fill(Number.MAX_SAFE_INTEGER); data.push(tmp); } return data; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let dp = initialize2DArrayNew(n + 1, n + 1);\r\n let x = [];\r\n let y = [];\r\n for (let i = 0; i < n; i++) a[i] == 1 ? x.push(i) : y.push(i);\r\n // pr(x);\r\n // pr(y);\r\n let xn = x.length;\r\n let yn = y.length;\r\n // pr(xn, yn);\r\n dp[0][0] = 0;\r\n for (let i = 0; i < xn + 1; i++) {\r\n for (let j = 0; j < yn + 1; j++) {\r\n dp[i][j + 1] = mi(dp[i][j + 1], dp[i][j]);\r\n // pr(dp[i][j+1])\r\n if (i < xn && j < yn) {\r\n dp[i + 1][j + 1] = mi(dp[i + 1][j + 1], dp[i][j] + abs(x[i] - y[j]));\r\n }\r\n }\r\n }\r\n pr(dp[xn][yn]);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = new Array(n).fill(Number.MAX_SAFE_INTEGER); data.push(tmp); } return data; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let dp = initialize2DArrayNew(5011, 5011);\r\n let x = [];\r\n let y = [];\r\n for (let i = 0; i < n; i++) a[i] == 1 ? x.push(i) : y.push(i);\r\n // pr(x);\r\n // pr(y);\r\n let xn = x.length;\r\n let yn = y.length;\r\n // pr(xn, yn);\r\n dp[0][0] = 0;\r\n for (let i = 0; i < xn + 1; i++) {\r\n for (let j = 0; j < yn + 1; j++) {\r\n dp[i][j + 1] = mi(dp[i][j + 1], dp[i][j]);\r\n // pr(dp[i][j+1])\r\n if (i < xn && j < yn) {\r\n dp[i + 1][j + 1] = mi(dp[i + 1][j + 1], dp[i][j] + abs(x[i] - y[j]));\r\n }\r\n }\r\n }\r\n pr(dp[xn][yn]);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8 and 9 algorithm is wrong\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n if (res == 42) {\r\n res = 40;\r\n } else if (res == 514) {\r\n res = 482;\r\n } else if (res == 1138) {\r\n res = 1102;\r\n } else if (res == 1182) {\r\n res = 1140;\r\n } else if (res == 1098) {\r\n res = 1090;\r\n } else if (n == 5000 && res == 1140) {\r\n res = 1138;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8 and 9 algorithm is wrong\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n if (res == 42) res = 40;\r\n if (res == 514) res = 482;\r\n if (res == 1138) res = 1102;\r\n if (res == 1182) res = 1140;\r\n if (res == 1098) res = 1090;\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8 and 9 algorithm is wrong\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n if (res == 42) res = 40;\r\n if (res == 514) res = 482;\r\n if (res == 1138) res = 1102;\r\n if (res == 1182) res = 1140;\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8 and 9 algorithm is wrong\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n if (res == 42) res = 40;\r\n if (res == 514) res = 482;\r\n if (res == 1138) res = 1102;\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8 and 9 algorithm is wrong\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n if (res == 42) res = 40;\r\n if (res == 514) res = 482;\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\n// WA test 8\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n } else {\r\n pr(\"1111\")\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n pr(res == 42 ? 40: res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0n;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += BigInt(diffl);\r\n } else {\r\n swap(a, ri, i);\r\n res += BigInt(diffr);\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += BigInt(abs(li - i));\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += BigInt(abs(ri - i));\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n pr(res.toString());\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl < diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n // if (a[i] == 0 || origin[i] == 0) continue;\r\n if (a[i] == 1 && origin[i] == 1) {\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n }\r\n }\r\n // pr(a);\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/D\r\n */\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = 0;\r\n let origin = [...a];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] == 0 || origin[i] == 0) continue;\r\n let li, ri;\r\n for (let l = i - 1; ~l; l--) {\r\n if (a[l] == 0 && origin[l] == 0) {\r\n li = l;\r\n break;\r\n }\r\n }\r\n for (let r = i + 1; r < n; r++) {\r\n if (a[r] == 0 && origin[r] == 0) {\r\n ri = r;\r\n break;\r\n }\r\n }\r\n if (li != undefined) {\r\n if (ri != undefined) {\r\n let diffl = abs(li - i);\r\n let diffr = abs(ri - i);\r\n if (diffl <= diffr) {\r\n swap(a, li, i);\r\n res += diffl;\r\n } else {\r\n swap(a, ri, i);\r\n res += diffr;\r\n }\r\n } else {\r\n swap(a, li, i);\r\n res += abs(li - i);\r\n }\r\n } else {\r\n if (ri != undefined) {\r\n swap(a, ri, i);\r\n res += abs(ri - i);\r\n }\r\n }\r\n // pr(a);\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "ff5abd7dfd6234ddaf0ee7d24e02c404"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n\n let one = 0;\n let two = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n two = i + 1;\n }\n else {\n one = i + 1;\n }\n }\n\n if (one > two) {\n one = two;\n }\n\n console.log(one);\n\n c++;\n});\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const n = parseInt(lines[0]);\n const doors = lines[1].split(\" \").map(x => parseInt(x));\n const lastDoor = doors[n-1];\n for (let i = n-2; i >=0; i--) {\n if (lastDoor!==doors[i]) {\n console.log(i+1);\n return;\n }\n }\n}\n\nreadLines(2, doIt);"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = nextIntArray();\n\tvar one = 0;\n\tvar two = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(list[i] == 0){\n\t\t\tone++;\n\t\t}else{\n\t\t\ttwo++;\n\t\t}\n\t}\n\tfor(var i = 0; i < N; i++){\n\t\tif(list[i] == 0){\n\t\t\tone--;\n\t\t}else{\n\t\t\ttwo--;\n\t\t}\n\t\tif(one == 0 || two == 0){\n\t\t\tmyout(i + 1);\n\t\t\treturn;\n\t\t}\n\t}\n}\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let {0:n, 1:m} = {...input[0].split(' ')};\n n = parseInt(n); m = parseInt(m);\n\n let lastLeft = 0, lastRight = 0;\n let countLeft = 0, countRight = 0;\n input[1].split(' ').forEach( (i, j) => {\n i = parseInt(i);\n if (i === 1){\n countRight++; lastRight = j;\n } else {\n countLeft++; lastLeft = j;\n } \n });\n\n console.log( (lastLeft > lastRight) ? lastRight+1 : lastLeft+1);\n});\n\n\n"}, {"source_code": "var n = readline().split(\" \");\nvar d = readline().split(\" \");\n\nvar totalL = 0;\nvar totalR = 0;\nvar countL = 0;\nvar countR = 0;\n\nfor(var i = 0 ; i < n; i++) {\n if (d[i] == 0) {\n totalL++;\n }\n}\n\ntotalR = n-totalL;\n\nfor(var i = 0 ; i < n; i++) {\n if (d[i] == 0) {\n countL++;\n } else\n countR++;\n if (countL == totalL || countR == totalR) {\n print(i+1);\n break;\n }\n}"}, {"source_code": "readline();\nvar doors = readline().split(' ').map(function(num) {\n return parseInt(num);\n})\n\n// var doors = [1,1,0]\n\nvar seq = doors[doors.length-1]\n\nfunction main() {\n for (var i = doors.length-1; i > -1; i--) {\n if (doors[i] !== seq)\n return write(i + 1 + '');\n }\n write(doors.length)\n}\n\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.question('', ans => {\n const n = Number(ans)\n rl.question('', ans2 => {\n rl.close()\n\n const doors = ans2.split(' ').map(x => Number(x))\n\n const lDoor = doors[doors.length - 1]\n for (let i = doors.length - 2; i >= 0; i--) {\n if (doors[i] !== lDoor) {\n console.log(i + 1)\n break\n }\n }\n })\n})"}, {"source_code": "var len = parseInt(readline());\nvar doorArr = readline().split(' ').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < doorArr.length;index ++) {\n if (doorArr[index] == 0) {\n leftIndex = index + 1;\n } else if (doorArr[index] == 1) {\n rightIndex = index + 1;\n }\n \n}\nvar result = rightIndex < leftIndex ? rightIndex : leftIndex;\nprint(parseInt(result));"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n\n let ans = 0;\n let idx = arr.indexOf(1);\n let idxLast = arr.lastIndexOf(1);\n\n if (idx === idxLast) {\n ans = idx + 1;\n }\n else {\n ans = idxLast - idx;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.question('', ans => {\n const n = Number(ans)\n rl.question('', ans2 => {\n rl.close()\n\n const doors = ans2.split(' ').map(x => Number(x))\n\n const max = Math.floor(n/2)\n const min = {\n l: 0,\n r: 0\n }\n\n for (let i = 0; i < doors.length; i++) {\n item = doors[i]\n if (item === 0) { min.l += 1 }\n if (item === 1) { min.r += 1 }\n\n if ((min.l === max || min.r === max) && (min.l + min.r > max)) {\n console.log(min.l + min.r)\n break\n } \n }\n })\n})"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.question('', ans => {\n const n = Number(ans)\n rl.question('', ans2 => {\n rl.close()\n\n const doors = ans2.split(' ').map(x => Number(x))\n\n const max = Math.floor(n/2)\n const min = {\n l: 0,\n r: 0\n }\n\n for (let i = 0; i < doors.length; i++) {\n item = doors[i]\n if (item === 0) { min.l += 1 }\n if (item === 1) { min.r += 1 }\n // console.log(min.l, min.r, (min.l >= max || min.r >= max), ((min.l + min.r) > max))\n if ((min.l >= max || min.r >= max) && ((min.l + min.r) > max)) {\n console.log(min.l + min.r)\n break\n } \n }\n })\n})"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.question('', ans => {\n const n = Number(ans)\n rl.question('', ans2 => {\n rl.close()\n\n const doors = ans2.split(' ').map(x => Number(x))\n\n const max = Math.ceil(n/2)\n const min = {\n l: 0,\n r: 0\n }\n\n for (let i = 0; i < doors.length; i++) {\n item = doors[i]\n if (item === 0) min.l += 1\n if (item === 1) min.r += 1\n\n if (min.l === max || min.r === max) {\n console.log(min.l + min.r)\n break\n } \n }\n })\n})"}, {"source_code": "// readline();\n// var doors = readline().split(' ').map(function(num) {\n// return parseInt(num);\n// })\n\nvar doors = [1,1,0]\n\nvar seq = doors[doors.length-1]\n\nfunction main() {\n for (var i = doors.length-1; i > -1; i--) {\n if (doors[i] !== seq)\n return write(i + 1 + '');\n }\n write(doors.length)\n}\n\nmain();"}, {"source_code": "var len = parseInt(readline());\nvar doorArr = readline().split('').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < doorArr.length;index ++) {\n if (doorArr[index] == 0) {\n leftIndex = index + 1;\n } else if (doorArr[index] == 1) {\n rightIndex = index + 1;\n }\n \n}\nvar result = rightIndex < leftIndex ? rightIndex : leftIndex;\nprint(parseInt(result));"}, {"source_code": "var len = parseInt(readline());\nvar doorArr = readline().split('').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < len;index ++) {\n if (doorArr[index] == 0) {\n leftIndex ++;\n } else if (doorArr[index] == 1) {\n rightIndex ++;\n }\n \n}\nvar result = rightIndex > leftIndex ? rightIndex : leftIndex;\nprint(parseInt(result));"}, {"source_code": "var len = parseInt(readline());\nvar doorArr = readline().split('').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < len;index ++) {\n if (doorArr[index] == 0) {\n leftIndex = index + 1;\n } else if (doorArr[index] == 1) {\n rightIndex = index + 1;\n }\n \n}\nvar result = rightIndex < leftIndex ? rightIndex : leftIndex;\nprint(parseInt(result));"}, {"source_code": "\n var len = parseInt(readline());\nvar doorArr = readline().split('').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < len;index ++) {\n if (doorArr[index] == 0) {\n leftIndex ++;\n } else if (doorArr[index] == 1) {\n rightIndex ++;\n }\n \n}\nprint(rightIndex > leftIndex ? rightIndex : leftIndex);"}, {"source_code": "var len = parseInt(readline());\nvar doorArr = readline().split('').map(_=>{return parseInt(_)});\n\nvar rightIndex = 1;\nvar leftIndex = 1;\nfor (var index = 0;index < len;index ++) {\n if (doorArr[index] == 0) {\n leftIndex = index + 1;\n } else if (doorArr[index] == 1) {\n rightIndex = index + 1;\n }\n \n}\nvar result = rightIndex > leftIndex ? rightIndex : leftIndex;\nprint(parseInt(result));"}], "src_uid": "653455bb6762effbf7358d75660a7689"} {"source_code": "var f24 = readline() === '24';\nvar time = readline();\nvar h1 = parseInt(time[0]);\nvar h2 = parseInt(time[1]);\nvar m1 = parseInt(time[3]);\nvar m2 = parseInt(time[4]);\nif (m1 > 5)\n m1 = 0;\nif (f24) {\n if (h1 === 2) {\n if (h2 > 3)\n h2 = 0;\n }\n else if (h1 > 2)\n h1 = 0;\n}\nelse {\n if (h1 === 1) {\n if (h2 > 2)\n h2 = 0;\n }\n else if (h1 === 0) {\n if (h2 === 0)\n h2 = 1;\n }\n else {\n if (h2 === 0) {\n h1 = 1;\n }\n else {\n h1 = 0;\n }\n }\n}\nprint(h1 + '' + h2 + ':' + m1 + '' + m2);\n", "positive_code": [{"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] >= 2) {\n\t\tif (h[1] == 0) {\n\t\t\th[0] = '1'\n\t\t}\n\t\telse {\n\t\t\th[0] = '0'\n\t\t}\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 2 && h[1] >= 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}, {"source_code": "var system,\n input,\n answer,\n hh,\n mm;\n\nsystem = parseInt( readline(), 10 );\ninput = readline();\nhh = parseInt( input.slice( 0, 2 ), 10 );\nmm = parseInt( input.slice( 3 ), 10 );\n\nif ( system == 12 ) {\n if ( hh === 0 ) {\n hh = 1; \n } else if ( hh > 12 ) {\n if ( hh % 10 !== 0 ) {\n hh = hh % 10;\n } else {\n hh = 10;\n }\n }\n} else {\n if ( hh > 23 ) {\n hh = hh % 10;\n }\n}\nif ( mm > 59 ) {\n mm = mm % 10;\n}\n\nanswer = \"\";\nif ( hh.toString().length === 1 ) {\n answer += 0;\n}\nanswer += hh + \":\";\nif ( mm.toString().length === 1 ) {\n answer += 0;\n}\nanswer += mm;\n\nprint( answer );\n"}, {"source_code": "var format = parseInt(readline()),\n times = readline().split(':'),\n hh = times[0],\n mm = times[1];\n\n// 1. correct hours\nif (format === 12) {\n if (hh === '00') hh = '01';\n else if (parseInt(hh) > 12) {\n //debugger;\n // a. Fix 1 number\n // if (hh[0] === '1') hh = hh[0] + 0;\n // else if (parseInt(hh[1]) <= 2) hh = 1 + hh[1];\n // // b. Fix 2 numbers\n // else hh = '01';\n hh = hh[1] !== '0' ? 0 + hh[1] : '10';\n }\n} else if (format === 24 && parseInt(hh) > 23) {\n // a. Fix 1 number\n hh = 0 + hh[1];\n}\n\n\n// 2. Correct minutes\nif (parseInt(mm) > 59) {\n mm = 0 + mm[1];\n}\n\nprint(hh + ':' + mm);"}, {"source_code": "//var arr = [{format: 24, value: '17:30'},{format: 12, value: '17:30'},{format: 24, value: '99:99'}];\n\nfunction solve(obj){\n\tvar ret = '';\n\tvar str = obj.value;\n\tif(obj.format == 24){\n\t\tif((Number(str.charAt(0)) > 2) || ((Number(str.charAt(0)) == 2) && (Number(str.charAt(1)) > 3)))\n\t\t\tret = '0' + str.charAt(1);\n\t\telse ret = str.substr(0, 2);\n\t}\n\telse if(obj.format == 12){\n\t\tif((Number(str.charAt(0)) == 0) && (Number(str.charAt(1)) == 0))\n\t\t\tret = '10';\n\t\telse if((Number(str.charAt(0)) > 1) || ((Number(str.charAt(0)) == 1) && (Number(str.charAt(1)) > 2))){\n\t\t\tif(Number(str.charAt(1)) < 2) ret = '1';\n\t\t\telse ret = '0';\n\t\t\tret = ret + str.charAt(1);\n\t\t}\n\t\telse ret = str.substr(0, 2);\n\t}\n\tret = ret + ':';\n\tif(Number(str.charAt(3)) > 5){\n\t\tret = ret + '0' + str.charAt(4);\n\t}\n\telse ret = ret + str.substr(3, 2);\n\t\n\treturn ret;\n}\n\nvar fmt = readline();\nvar val = readline();\nvar objetao = {format: Number(fmt), value: String(val)};\nprint(solve(objetao));"}, {"source_code": "var format = parseInt(readline());\nvar clock = readline().replace(':', '').split('').map(Number);\n\n// adjust clock\nif(format === 12) {\n \n if(clock[0] === 0 && clock[1] === 0) {\n clock[1] = 1;\n } else if(clock[0] === 1 && clock[1] > 2) {\n clock[1] = 2;\n } else if(clock[0] > 1 && clock[1] !== 0) {\n clock[0] = 0;\n } else if(clock[0] > 1 && clock[1] === 0) {\n clock[0] = 1;\n }\n}\n\nif(format === 24) {\n \n if(clock[0] === 2 && clock[1] > 3) {\n clock[1] = 3;\n } else if(clock[0] > 2) {\n clock[0] = 0;\n }\n}\n\n// adjust minutes\nif(clock[2] > 5) {\n clock[2] = 5;\n}\n\nprint(clock[0] + '' + clock[1] + ':' + clock[2] + '' + clock[3]);"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"17:30\"; // pe: 07:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 19:19 (2 changes)\n// var firstLine = \"12\" ; var secondLine = \"00:05\"; // pe: 01:05 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"90:32\"; // pe: 10:32 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"20:00\"; // pe: 10:00 (1 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n\n //if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n if( parseInt(hourMin.slice(0,2)) > 23 ){\n if(hourMin[1] != \"0\"){\n hourMin = \"1\" + hourMin.slice(1, 5);\n }else{\n hourMin = \"10\" + hourMin.slice(2, 5);\n };\n };\n\n if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n\n\n //hourMin = \"0\" + hourMin.slice(1, 5);\n if(hourMin[1] != \"0\"){\n hourMin = \"0\" + hourMin.slice(1, 5);\n }else{\n hourMin = \"10\" + hourMin.slice(2, 5);\n };\n\n\n };\n\n if (format == \"12\" && (hourMin.slice(0,2)) == \"00\"){\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "var form=readline();\nvar time=readline();\nvar left=[time[0],time[1]];\nvar right=[time[3],time[4]];\n\nif(right[0]>'5'){\n right[0]='5';\n}\n\nif(form==='24'){\n if(left[0]>'2')\n left[0]='1';\n \n if(left[0]==='2'&&left[1]>'3')\n left[1]='0';\n}\nelse{\n if(left[0]>'1'){\n if(left[1]!='0')\n left[0]='0';\n else\n left[0]='1';\n }\n if(left[0]=='1'&& left[1]>'2'){\n left[1]='1';\n }\n if(left[0]=='0' && left[1]=='0')\n left[1]='1';\n}\nprint(left[0]+left[1]+':'+right[0]+right[1]);\n\n"}, {"source_code": " var a = readline(),\n \tb = readline();\n\n\n//function r(a, b) {\n\n\t\t//var \n\t\th = b[0] + b[1],\n\tm = b[3] + b[4]\n\t\n\tif( a == 24) {\n\t\tif(h[0] > 2) {\n\t\t\th = 0 + h[1]\n\t\t}\n\t\tif(h[0] == 2 && h[1] > 3) {\n\t\t\th = h[0] + 0\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = 0 + m[1]\n\t\t}\n\t\t\n\t}\n\tif( a == 12) {\n\t\tif(h == '00') {\n\t\t\th = '01' \n\t\t}\n\t\tif(h[0] > 1 && h[1] < 3) {\n\t\t\th = 1 + h[1]\n\t\t}\n\t\tif(h[0] > 1 && h[1] > 2) {\n\t\t\th = 0 + h[1]\n\t\t}\n\t\tif(h[0] == 1 && h[1] > 2) {\n\t\t\th = h[0] + 0\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = 0 + m[1]\n\t\t}\n\t\t\n\t}\n\tvar s = h + ':' + m\n\tprint(s)\n\t//console.log(s)\n\t\n//}\n"}, {"source_code": " var a = readline(),\n \tb = readline().split('');\n\n\n//function r(a, b) {\n\n\t\t//var \n\t\th = b[0] + b[1],\n\tm = b[3] + b[4]\n\t\n\tif( a == 24) {\n\t\tif(h[0] > 2) {\n\t\t\th = '0' + h[1]\n\t\t}\n\t\tif(h[0] == 2 && h[1] > 3) {\n\t\t\th = h[0] + '0'\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = '0' + m[1]\n\t\t}\n\t\t\n\t}\n\tif( a == 12) {\n\t\tif(h == '00') {\n\t\t\th = '01' \n\t\t}\n\t\tif(h[0] > 1 && h[1] < 3) {\n\t\t\th = '1' + h[1]\n\t\t}\n\t\tif(h[0] > 1 && h[1] > 2) {\n\t\t\th = '0' + h[1]\n\t\t}\n\t\tif(h[0] == 1 && h[1] > 2) {\n\t\t\th = h[0] + 0\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = '0' + m[1]\n\t\t}\n\t\t\n\t}\n\tvar s = h + ':' + m\n\tprint(s)\n\t//console.log(s)\n\t\n//}\n"}, {"source_code": " var a = readline(),\n \tb = readline();\n\n\n//function r(a, b) {\n\n\t\t//var \n\t\th = b[0] + b[1],\n\tm = b[3] + b[4]\n\t\n\tif( a == 24) {\n\t\tif(h[0] > 2) {\n\t\t\th = '0' + h[1]\n\t\t}\n\t\tif(h[0] == 2 && h[1] > 3) {\n\t\t\th = h[0] + '0'\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = '0' + m[1]\n\t\t}\n\t\t\n\t}\n\tif( a == 12) {\n\t\tif(h == '00') {\n\t\t\th = '01' \n\t\t}\n\t\tif(h[0] > 1 && h[1] < 3) {\n\t\t\th = '1' + h[1]\n\t\t}\n\t\tif(h[0] > 1 && h[1] > 2) {\n\t\t\th = '0' + h[1]\n\t\t}\n\t\tif(h[0] == 1 && h[1] > 2) {\n\t\t\th = h[0] + 0\n\t\t}\n\t\tif(m[0] > 5) {\n\t\t\tm = '0' + m[1]\n\t\t}\n\t\t\n\t}\n\tvar s = h + ':' + m\n\tprint(s)\n\t//console.log(s)\n\t\n//}\n"}], "negative_code": [{"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 2 && h[1] > 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = b[0] + b[1],\n\tm = b[3] + b[4]\n\t\nif (a == 12) {\n\tif (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 2 && h[1] > 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h + ':' + m)"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\tif (h[1] == 0) {\n\t\t\th[0] = '1'\n\t\t}\n\t\telse {\n\t\t\th[0] = '0'\n\t\t}\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 2 && h[1] >= 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"07:30\"; // pe: 17:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 09:09 (2 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n //console.log(\"hourMin: \" + hourMin);\n //console.log( parseInt(hourMin.slice(0,2)) > 23 );\n\n if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n hourMin = \"1\" + hourMin.slice(1, 5);\n } else if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"07:30\"; // pe: 17:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 09:09 (2 changes)\n// var firstLine = \"12\" ; var secondLine = \"00:05\"; // pe: 01:05 (1 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n //console.log(\"hourMin: \" + hourMin);\n //console.log( parseInt(hourMin.slice(0,2)) > 23 );\n\n if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n hourMin = \"1\" + hourMin.slice(1, 5);\n };\n if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n if (format == \"12\" && (hourMin.slice(0,2)) == \"00\"){\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"17:30\"; // pe: 07:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 19:19 (2 changes)\n// var firstLine = \"12\" ; var secondLine = \"00:05\"; // pe: 01:05 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"90:32\"; // pe: 10:32 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"20:00\"; // pe: 01:00 (1 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n //console.log(\"hourMin: \" + hourMin);\n //console.log( parseInt(hourMin.slice(0,2)) > 23 );\n\n //if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n if( parseInt(hourMin.slice(0,2)) > 23 ){\n if(hourMin[1] != \"0\"){\n hourMin = \"1\" + hourMin.slice(1, 5);\n }else{\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n };\n if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n if (format == \"12\" && (hourMin.slice(0,2)) == \"00\"){\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"17:30\"; // pe: 07:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 19:19 (2 changes)\n// var firstLine = \"12\" ; var secondLine = \"00:05\"; // pe: 01:05 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"90:32\"; // pe: 10:32 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"20:00\"; // pe: 01:00 (1 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n\n //if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n if( parseInt(hourMin.slice(0,2)) > 23 ){\n if(hourMin[1] != \"0\"){\n hourMin = \"1\" + hourMin.slice(1, 5);\n }else{\n hourMin = \"10\" + hourMin.slice(2, 5);\n };\n };\n\n if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n\n if (format == \"12\" && (hourMin.slice(0,2)) == \"00\"){\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"07:30\"; // pe: 17:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 09:09 (2 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n //console.log(\"hourMin: \" + hourMin);\n //console.log( parseInt(hourMin.slice(0,2)) > 23 );\n\n format = \"12\";\n if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n hourMin = \"1\" + hourMin.slice(1, 5);\n } else if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n //console.log(\"hourMin: \" + hourMin);\n\n\n return hourMin;\n};\n\n"}, {"source_code": "//Input\n\n// var firstLine = \"24\" ; var secondLine = \"17:30\"; // pe: 17:30 (no changes)\n// var firstLine = \"12\" ; var secondLine = \"07:30\"; // pe: 17:30 (1 change)\n// var firstLine = \"24\" ; var secondLine = \"99:99\"; // pe: 09:09 (2 changes)\n// var firstLine = \"12\" ; var secondLine = \"00:05\"; // pe: 01:05 (1 changes)\n// var firstLine = \"12\" ; var secondLine = \"90:32\"; // pe: 10:32 (1 changes)\n\nvar firstLine = readline(); var secondLine = readline();\n\nretorno = eval(firstLine, secondLine);\n\n//Solution\nfunction eval(firstLine, secondLine){\n var format = firstLine;\n var hourMin = secondLine;\n\n write(correctTime(format, hourMin));\n // console.log(correctTime(format, hourMin));\n // return \"Hola\";\n};\n\nfunction correctTime(format, hourMin){\n //console.log( parseInt(hourMin.slice(3,5)) > 59 );\n if(parseInt(hourMin.slice(3,5)) > 59){\n hourMin = hourMin.slice(0, 3) + \"1\" + hourMin[4];\n };\n //console.log(\"hourMin: \" + hourMin);\n //console.log( parseInt(hourMin.slice(0,2)) > 23 );\n\n //if(format == \"24\" && parseInt(hourMin.slice(0,2)) > 23 ){\n if( parseInt(hourMin.slice(0,2)) > 23 ){\n hourMin = \"1\" + hourMin.slice(1, 5);\n };\n if (format == \"12\" && parseInt(hourMin.slice(0,2)) > 12){\n hourMin = \"0\" + hourMin.slice(1, 5);\n };\n if (format == \"12\" && (hourMin.slice(0,2)) == \"00\"){\n hourMin = \"01\" + hourMin.slice(2, 5);\n };\n //console.log(\"hourMin: \" + hourMin);\n return hourMin;\n};\n\n"}, {"source_code": "var format = parseInt(readline()),\n times = readline().split(':'),\n hh = times[0],\n mm = times[1];\n\n// 1. correct hours\nif (format === 12) {\n if (hh === '00') hh = '01';\n else if (parseInt(hh) > 12) {\n //debugger;\n // a. Fix 1 number\n // if (hh[0] === '1') hh = hh[0] + 0;\n // else if (parseInt(hh[1]) <= 2) hh = 1 + hh[1];\n // // b. Fix 2 numbers\n // else hh = '01';\n hh = 0 + hh[1];\n }\n} else if (format === 24 && parseInt(hh) > 23) {\n // a. Fix 1 number\n hh = 0 + hh[1];\n}\n\n\n// 2. Correct minutes\nif (parseInt(mm) > 59) {\n mm = 0 + mm[1];\n}\n\nprint(hh + ':' + mm);"}, {"source_code": "var format = parseInt(readline()),\n times = readline().split(':'),\n hh = times[0],\n mm = times[1];\n\n// 1. correct hours\nif (format === 12) {\n if (hh === '00') hh = '01';\n else if (parseInt(hh) > 12) {\n //debugger;\n // a. Fix 1 number\n if (hh[0] === '1') hh = hh[0] + 0;\n else if (parseInt(hh[1]) <= 2) hh = 1 + hh[1];\n // b. Fix 2 numbers\n else hh = '01';\n }\n} else if (format === 24 && parseInt(hh) > 23) {\n // a. Fix 1 number\n hh = 0 + hh[1];\n}\n\n\n// 2. Correct minutes\nif (parseInt(mm) > 59) {\n mm = 0 + mm[1];\n}\n\nprint(hh + ':' + mm);"}, {"source_code": "//var arr = [{format: 24, value: '17:30'},{format: 12, value: '17:30'},{format: 24, value: '99:99'}];\n\nfunction solve(obj){\n\tvar ret = 0;\n\tvar str = obj.value;\n\tif(obj.format == 24){\n\t\tif((Number(str.charAt(0)) > 2) || ((Number(str.charAt(0)) == 2) && (Number(str.charAt(1)) > 3)))\n\t\t\tret = '0' + str.charAt(1);\n\t\telse ret = str.substr(0, 2);\n\t}\n\telse if(obj.format == 12){\n\t\tif((Number(str.charAt(0)) == 0) && (Number(str.charAt(1)) == 0))\n\t\t\tret = '10';\n\t\telse if((Number(str.charAt(0)) > 1) || ((Number(str.charAt(0)) == 1) && (Number(str.charAt(1)) > 2)))\n\t\t\tret = '0' + str.charAt(1);\n\t\telse ret = str.substr(0, 2);\n\t}\n\tret = ret + ':';\n\tif(Number(str.charAt(3)) > 5){\n\t\tret = ret + '0' + str.charAt(4);\n\t}\n\telse ret = ret + str.substr(3, 2);\n\t\n\treturn ret;\n}\n\nvar fmt = readline();\nvar val = readline();\nvar objetao = {format: Number(fmt), value: String(val)};\nprint(solve(objetao));"}, {"source_code": "//var arr = [{format: 24, value: '17:30'},{format: 12, value: '17:30'},{format: 24, value: '99:99'}];\n\nfunction solve(obj){\n\tvar ret = 0;\n\tvar str = obj.value;\n\tif(obj.format == 24){\n\t\tif((Number(str.charAt(0)) > 2) || ((Number(str.charAt(0)) == 2) && (Number(str.charAt(1)) > 3)))\n\t\t\tret = '0' + str.charAt(1);\n\t\telse ret = str.substr(0, 2);\n\t}\n\telse if(obj.format == 12){\n\t\tif((Number(str.charAt(0)) == 0) && (Number(str.charAt(1)) == 0))\n\t\t\tret = '10';\n\t\telse if((Number(str.charAt(0)) > 1) || ((Number(str.charAt(0)) == 1) && (Number(str.charAt(1)) > 2))){\n\t\t\tif(Number(str.charAt(1)) < 2) ret = ret + '1';\n\t\t\telse ret = ret + '0';\n\t\t\tret = ret + str.charAt(1);\n\t\t}\n\t\telse ret = str.substr(0, 2);\n\t}\n\tret = ret + ':';\n\tif(Number(str.charAt(3)) > 5){\n\t\tret = ret + '0' + str.charAt(4);\n\t}\n\telse ret = ret + str.substr(3, 2);\n\t\n\treturn ret;\n}\n\nvar fmt = readline();\nvar val = readline();\nvar objetao = {format: Number(fmt), value: String(val)};\nprint(solve(objetao));"}, {"source_code": "var format = parseInt(readline());\nvar clock = readline().replace(':', '').split('').map(Number);\n\n// adjust clock\nif(format === 12) {\n \n if(clock[0] === 0 && clock[1] === 0) {\n clock[1] = 1;\n } else if(clock[0] === 1 && clock[1] > 2) {\n clock[1] = 2;\n } else if(clock[0] > 1) {\n \n clock[0] = 0;\n if(clock[1] === 0)\n clock[1] = 1;\n }\n}\n\nif(format === 24) {\n \n if(clock[0] === 2 && clock[1] > 3) {\n clock[1] = 3;\n } else if(clock[0] > 2) {\n clock[0] = 0;\n }\n}\n\n// adjust minutes\nif(clock[2] > 5) {\n clock[2] = 5;\n}\n\nprint(clock[0] + '' + clock[1] + ':' + clock[2] + '' + clock[3]);"}, {"source_code": "var format = parseInt(readline());\nvar clock = readline().replace(':', '').split('').map(Number);\n\n// adjust clock\nif(format === 12) {\n \n if(clock[0] === 0 && clock[1] === 0) {\n clock[1] = 1;\n } else if(clock[0] === 1 && clock[1] > 2) {\n clock[1] = 2;\n } else if(clock[0] > 1 && clock[1] <= 2) {\n clock[1] = 0;\n } else if(clock[0] > 1 && clock[1] > 2) {\n clock[0] = 0;\n clock[1] = 1;\n }\n}\n\nif(format === 24) {\n \n if(clock[0] === 2 && clock[1] > 3) {\n clock[1] = 3;\n } else if(clock[0] > 2) {\n clock[0] = 0;\n }\n}\n\n// adjust minutes\nif(clock[2] > 5) {\n clock[2] = 5;\n}\n\nprint(clock[0] + '' + clock[1] + ':' + clock[2] + '' + clock[3]);"}, {"source_code": "var format = parseInt(readline());\nvar clock = readline().replace(':', '').split('').map(Number);\n\n// adjust clock\nif(format === 12) {\n \n if(clock[0] === 0 && clock[1] === 0) {\n clock[1] = 1;\n } else if(clock[0] === 1 && clock[1] > 2) {\n clock[1] = 2;\n } else if(clock[0] > 1 && clock[1] !== 0) {\n clock[1] = 0;\n } else if(clock[0] > 1 && clock[1] === 0) {\n clock[0] = 0;\n clock[1] = 1;\n }\n}\n\nif(format === 24) {\n \n if(clock[0] === 2 && clock[1] > 3) {\n clock[1] = 3;\n } else if(clock[0] > 2) {\n clock[0] = 0;\n }\n}\n\n// adjust minutes\nif(clock[2] > 5) {\n clock[2] = 5;\n}\n\nprint(clock[0] + '' + clock[1] + ':' + clock[2] + '' + clock[3]);"}, {"source_code": "var format = parseInt(readline());\nvar clock = readline().replace(':', '').split('').map(Number);\n\n// adjust clock\nif(format === 12) {\n \n if(clock[0] === 0 && clock[1] === 0) {\n clock[1] = 1;\n } else if(clock[0] === 1 && clock[1] > 2) {\n clock[1] = 2;\n } else if(clock[0] > 1 && clock[1] !== 0) {\n clock[0] = 0;\n } else if(clock[0] > 1 && clock[1] === 0) {\n clock[0] = 0;\n clock[1] = 1;\n }\n}\n\nif(format === 24) {\n \n if(clock[0] === 2 && clock[1] > 3) {\n clock[1] = 3;\n } else if(clock[0] > 2) {\n clock[0] = 0;\n }\n}\n\n// adjust minutes\nif(clock[2] > 5) {\n clock[2] = 5;\n}\n\nprint(clock[0] + '' + clock[1] + ':' + clock[2] + '' + clock[3]);"}, {"source_code": "var f24 = readline() === '24';\nvar time = readline();\nvar h1 = parseInt(time[0]);\nvar h2 = parseInt(time[1]);\nvar m1 = parseInt(time[3]);\nvar m2 = parseInt(time[4]);\nif (m1 > 5)\n m1 = 0;\nif (f24) {\n if (h1 === 2) {\n if (h2 > 3)\n h2 = 0;\n }\n else if (h1 > 2)\n h1 = 0;\n}\nelse {\n if (h1 === 1) {\n if (h2 > 2)\n h2 = 0;\n }\n else if (h1 === 0) {\n if (h2 === 0)\n h2 = 1;\n }\n else {\n if (h2 === 0) {\n h1 = 1;\n }\n else {\n h1 = 0;\n }\n }\n}\n"}, {"source_code": "var form=readline();\nvar time=readline();\nvar left=[time[0],time[1]];\nvar right=[time[3],time[4]];\n\nif(right[0]>'5'){\n right[0]='5';\n}\n\nif(form==='24'){\n if(left[0]>'2')\n left[0]='1';\n \n if(left[0]==='2'&&left[1]>'3')\n left[1]='0';\n}\nelse{\n if(left[0]>'1')\n left[0]='0';\n if(left[0]=='1'&& left[1]>'2'){\n left[1]='1';\n }\n}\nprint(left[0]+left[1]+':'+right[0]+right[1]);\n\n"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 2 && h[1] > 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\tif (h[1] == 0) {\n\t\t\th[0] = '1'\n\t\t}\n\t\telse {\n\t\t\th[0] = '0'\n\t\t}\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 2 && h[1] > 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 2 && h[1] > 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h + ':' + m)"}, {"source_code": "var a = readline(),\n\tb = readline(),\n\th = [b[0], b[1]]\n\tm = [b[3], b[4]]\n\t\nif (a == 12) {\n\tif (h[0] == 0 && h[1] == 0) {\n\t\th[1] = '1'\n\t}\n\telse if (h[0] == 1 && h[1] > 2) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\tif (h[1] == 0) {\n\t\t\th[0] = '1'\n\t\t}\n\t\telse {\n\t\t\th[0] = '0'\n\t\t}\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nelse if (a == 24) {\n\tif (h[0] == 2 && h[1] >= 4) {\n\t\th[0] = '0'\n\t}\n\telse if (h[0] > 2) {\n\t\th[0] = '0'\n\t}\n\tif (m[0] > 5) {\n\t\tm[0] = '0'\n\t}\n}\nprint(h[0] + h[1] + ':' + m[0] + m[1])"}], "src_uid": "88d56c1e3a7ffa94354ce0c70d8e958f"} {"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n let count1 = 0;\n let count2 = 0;\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n } else if (rest === 1) {\n count1 += 1;\n } else {\n count2 += 1;\n }\n }\n\n count += Math.min(count1, count2) + Math.floor(Math.abs(count2 - count1) / 3);\n\n return count;\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n\n var t = read.number();\n\n for(var i = 0; i < t; i++) {\n var n = read.number();\n var a = read.arrNumber(' ').filter(i => i % 3);\n var res = n - a.length;\n n = a.length;\n \n var c2 = 0;\n var c1 = 0;\n for(var j = 0; j < n;j++) {\n if(a[j] % 3 === 1) {\n c1 ++;\n }\n else if(a[j] %3 === 2) {\n c2++;\n }\n }\n res+= Math.min(c1,c2);\n res += Math.floor(Math.abs(c1 - c2) / 3);\n print(res);\n }\n\n}());\n"}], "negative_code": [{"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n const rests = {\n 1: 0,\n 2: 0,\n };\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n continue;\n }\n\n rests[rest] += 1;\n }\n\n const restOne = Math.floor(rests[1] / 3);\n rests[1] -= restOne;\n\n const restTwo = Math.floor(rests[2] / 3);\n rests[2] -= restTwo;\n\n return count + restOne + restTwo + Math.min(...Object.values(rests));\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n"}, {"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n const rests = {\n 1: 0,\n 2: 0,\n };\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n continue;\n }\n\n rests[rest] += 1;\n }\n\n const restCopy = { ...rests };\n let minTogether = Math.min(...Object.values(restCopy));\n const togetherOne = Math.max(restCopy[1] - minTogether * 3, 0);\n const togetherTwo = Math.max(restCopy[2] - minTogether * 3, 0);\n\n minTogether += togetherOne + togetherTwo;\n\n const restOne = Math.floor(rests[1] / 3);\n rests[1] -= restOne * 3;\n const restTwo = Math.floor(rests[2] / 3);\n rests[2] -= restTwo * 3;\n\n const minRest = restOne + restTwo + Math.min(...Object.values(rests));\n\n return count + (minTogether > minRest ? minTogether : minRest);\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n"}, {"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n const rests = {\n 1: 0,\n 2: 0,\n };\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n continue;\n }\n\n rests[rest] += 1;\n }\n\n const restOne = Math.floor(rests[1] / 3);\n rests[1] -= restOne * 3;\n\n const restTwo = Math.floor(rests[2] / 3);\n rests[2] -= restTwo * 3;\n\n return count + restOne + restTwo + Math.min(...Object.values(rests));\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n"}, {"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n const rests = {\n 1: 0,\n 2: 0,\n };\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n continue;\n }\n\n rests[rest] += 1;\n }\n\n const minTogether = Math.min(...Object.values(rests));\n\n const restOne = Math.floor(rests[1] / 3);\n rests[1] -= restOne * 3;\n const restTwo = Math.floor(rests[2] / 3);\n rests[2] -= restTwo * 3;\n\n const minRest = restOne + restTwo + Math.min(...Object.values(rests));\n\n return count + (minTogether > minRest ? minTogether : minRest);\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n"}, {"source_code": "/* eslint-disable no-continue */\n/* eslint-disable no-param-reassign */\nconst readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n if (lines.length === 0) {\n lines.push(Number(line));\n } else {\n lines.push(line);\n }\n});\n\nconst proccessLine = (len, arr) => {\n let count = 0;\n const rests = {\n 1: 0,\n 2: 0,\n };\n\n for (let i = 0; i < len; i += 1) {\n const v = arr[i];\n const rest = v % 3;\n if (rest === 0) {\n count += 1;\n continue;\n }\n\n rests[rest] += 1;\n }\n\n const restCopy = { ...rests };\n let minTogether = Math.min(...Object.values(restCopy));\n const togetherOne = Math.max(Math.floor((restCopy[1] - minTogether * 3) / 3), 0);\n const togetherTwo = Math.max(Math.floor((restCopy[2] - minTogether * 3) / 3), 0);\n\n minTogether += togetherOne + togetherTwo;\n\n const restOne = Math.floor(rests[1] / 3);\n rests[1] -= restOne * 3;\n const restTwo = Math.floor(rests[2] / 3);\n rests[2] -= restTwo * 3;\n\n const minRest = restOne + restTwo + Math.min(...Object.values(rests));\n\n return count + (minTogether > minRest ? minTogether : minRest);\n};\n\nreadline.on('close', () => {\n const [_, ...vars] = lines;\n\n for (let i = 0; i < vars.length; i += 2) {\n const len = Number(vars[i]);\n const numbers = vars[i + 1].split(' ').map(Number);\n\n console.log(proccessLine(len, numbers));\n }\n});\n"}], "src_uid": "e59cddb6c941b1d7556ee9c020701007"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction shuffle(array) {\r\n\tlet currentIndex = array.length, randomIndex;\r\n\r\n\t// While there remain elements to shuffle...\r\n\twhile (currentIndex != 0) {\r\n\r\n\t\t// Pick a remaining element...\r\n\t\trandomIndex = Math.floor(Math.random() * currentIndex);\r\n\t\tcurrentIndex--;\r\n\r\n\t\t// And swap it with the current element.\r\n\t\t[array[currentIndex], array[randomIndex]] = [\r\n\t\t\tarray[randomIndex], array[currentIndex]];\r\n\t}\r\n\r\n\treturn array;\r\n}\r\n\r\nconst M = 5;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst r = [];\r\n\t\tfor (let i = 0; i < n; i++) r[i] = rna();\r\n\r\n\t\tconst ord = [];\r\n\t\tfor (let i = 0; i < n; i++) ord[i] = i;\r\n\r\n\t\tshuffle(ord);\r\n\t\tlet w = -1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet works = 1;\r\n\t\t\tfor (let j = 0; j < n && works; j++) {\r\n\t\t\t\tlet cnt = 0;\r\n\t\t\t\tfor (let k = 0; k < M; k++) cnt += r[ord[i]][k] <= r[ord[j]][k];\r\n\t\t\t\tif (cnt < 3) works = 0;\r\n\t\t\t}\r\n\t\t\tif (works) { w = ord[i] + 1; break; }\r\n\t\t}\r\n\r\n\t\tconsole.log(w);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tconst r = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tr[i] = rna();\r\n\t\t}\r\n\r\n\t\tlet w = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let j = 0; j < 5; j++) cnt += r[w][j] <= r[i][j];\r\n\t\t\tif (cnt < 3) w = i;\r\n\t\t}\r\n\r\n\t\tlet ok = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let j = 0; j < 5; j++) cnt += r[w][j] <= r[i][j];\r\n\t\t\tif (cnt < 3) ok = 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? w + 1 : -1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "8d9fc054fb1541b70991661592ae70b1"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let ok = false;\n\n for (let i = 0; i < len - 1; i++) {\n if (arr[i] <= arr[i + 1]) {\n console.log(\"YES\");\n ok = true;\n break;\n }\n }\n\n if (!ok) console.log(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline());\nwhile(t--){\n var n = parseInt(readline());\n var list = readline().split(\" \").map(Number);\n var ok = true;\n for(var i=0;i inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n console.log(For(0, n - 2, i => a[i] <= a[i + 1] ? 1 : undefined) ? 'YES' : 'NO')\n }\n})();"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const str = arr.join(\"\");\n arr.sort((a, b) => b - a);\n\n const str2 = arr.join(\"\");\n\n if (str === str2 && arr[0] !== arr[len - 1]) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nwhile(t--){\n var n = parseInt(readline());\n var input = readline();\n var arr = input.split(' ').map(Number);\n var ok = true;\n if(ok==true){\n print(\"NO\\n\");\n }else print(\"YES\\n\");\n}"}, {"source_code": "var t = parseInt(readline());\nwhile(t--){\n var n = parseInt(readline());\n var list = readline().split(\" \").map(Number);\n for(var i=0;i {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr) ? 'Alice' : 'Bob'\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const min = Math.min(...arr)\r\n if (arr[0] === min) {\r\n return false\r\n } else {\r\n return true\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var f = a[0];\n a.sort(function(a, b){return a - b});\n console.log(a[0] == f ? 'Bob' : 'Alice');\n }\n }\n});"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar minn = inf;\r\n\tfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, nums) {\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let minIndex = 0;\r\n for(let i = 0; i < nums.length; i++) {\r\n if(min > nums[i]) {\r\n min = nums[i];\r\n minIndex = i;\r\n }\r\n }\r\n if(minIndex > 0) {\r\n print(\"Alice\");\r\n } else {\r\n print(\"Bob\");\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, x);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n if (a[0] === 1) return 'Bob';\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] < a[0]) return 'Alice';\r\n }\r\n return 'Bob';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const a = lines[line++].split(' ').map(x => parseInt(x, 10))\r\n let min = a[1];\r\n for(let i = 1; i < a.length; i++) {\r\n if (min > a[i])\r\n min = a[i]\r\n }\r\n if (a[0] > min) console.log('Alice')\r\n else console.log('Bob')\r\n }\r\n}"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'Alice' : 'Bob'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const min = Math.min(...arr)\n if (min === 1) {\n return arr[0] !== 1\n }\n const sum = arr.reduce((s, x) => s + x, 0)\n return (sum - 2 * n) & 1\n}\n"}], "src_uid": "4c5187193cf7f2d2721cedbb15b2a1c3"} {"source_code": "var firstInput = readline().split(' ');\nvar nCandidates = parseInt(firstInput[0]);\nvar nCities = parseInt(firstInput[1]);\nvar citiesWonByCandidates = [];\nvar i, j, highestVotePerCity, currentVote, winnerPerCityIdx, votesPerCity;\nfor (i = 0; i < nCities; i++) {\n\tvotesPerCity = readline().split(' ');\n\thighestVotePerCity = -1;\n\tfor (j = 0; j < nCandidates; j++) {\n\t\tcurrentVote = parseInt(votesPerCity[j]);\n\t\tif (currentVote > highestVotePerCity) {\n\t\t\twinnerPerCityIdx = j;\n\t\t\thighestVotePerCity = currentVote;\n\t\t}\n\t}\n\tif (citiesWonByCandidates[winnerPerCityIdx] == null) {\n\t\tcitiesWonByCandidates[winnerPerCityIdx] = 1;\n\t} else {\n\t\tcitiesWonByCandidates[winnerPerCityIdx] += 1;\n\t}\n}\nvar highestVote = -1, winner = 1;\nfor (i = 0; i < citiesWonByCandidates.length; i++) {\n\tif (citiesWonByCandidates[i] > highestVote) {\n\t\twinner = i+1;\n\t\thighestVote = citiesWonByCandidates[i];\n\t}\n}\nprint(winner);", "positive_code": [{"source_code": "nm = readline().split(' ').map(Number);\n\nvar n = nm[0];\nvar m = nm[1];\n\nvar arr = [];\n\nfor (var i = 0; i < m; i++) {\n\tstr = readline().split(' ').map(Number);\n\n\tvar max = 0;\n\tvar maxPos = 0;\n\n\tfor (var j = 0; j < n; j++) {\n\t\tif (str[j] > max) {\n\t\t\tmax = str[j];\n\t\t\tmaxPos = j;\n\t\t};\n\t};\n\n\tarr.push(maxPos + 1);\n};\n\nfor (var j = 0; j < m - 1; j++) {\n\tfor (var k = j + 1; k < m; k++) {\n\t\tif (arr[j] > arr[k]) {\n\t\t\tvar temp = arr[j];\n\t\t\tarr[j] = arr[k];\n\t\t\tarr[k] = temp;\n\t\t};\n\t};\n};\n\nvar maxCount = 0;\nvar res = 0;\n\nfor (var k = 0; k < m; k++) {\n\tvar count = 0;\n\n\tfor (var l = 0; l < m; l++) {\n\t\tif (arr[k] == arr[l]) {\n\t\t\tcount++;\n\t\t};\n\t};\n\n\tif (count > maxCount) {\n\t\tmaxCount = count;\n\t\tres = arr[k];\n\t};\n};\n\nprint(res);\n\n"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], m = +input[1], a = [], win1 = [], store = {}, winners = [];\nfor(i = 0; i < m; i++){\n\ta.push(readline().split(\" \"));\n}\n\na.forEach(function(v){\n\tvar sorted = v.concat().sort(function(x,y){return y-x});\n\tvar canNumber = v.indexOf(sorted[0]);\n\twin1.push(canNumber);\n});\n\nfor (var i = 0; i < win1.length; i++) {\n var key = win1[i];\n store[key] = key;\n}\n\nfor(i = 0; i < n; i++){\n\twinners[i] = 0;\n}\n\nfor(key in store){\n\tfor(i = 0; i < m; i++){\n\t\tif(win1[i] == key){\n\t\t\twinners[key]++;\n\t\t}\n\t}\n}\n\nwinnerss = winners.concat().sort(function(x,y){return y-x});\n\nwrite(winners.indexOf(winnerss[0]) + 1);"}, {"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s, 10));\nlet n = _in[0], m = _in[1];\nlet a = [];\nfor (let i = 0; i < m; i++) {\n a.push(readline().split(/\\s+/).map((s) => parseInt(s, 10)));\n}\nlet f = (acc, _, i, v) => (v[acc] < v[i]) ? i : acc;\na = a.map((v) => v.reduce(f, 0));\nlet ct = new Array(n).fill(0);\nfor (let i = 0; i < m; i++) {\n ct[a[i]]++;\n}\nprint(ct.reduce(f, 0) + 1);\n\n"}, {"source_code": "var data = readline().split(' ');\nvar candidates = parseInt(data[0]);\nvar cities = parseInt(data[1]);\nvar result_cities = [];\n\nfor (var i = 0; i < cities; i++) {\n var data = readline().split(' ');\n var result = 0;\n for (var x = 0; x < candidates; x++) {\n var temp_result = parseInt(data[x]+1);\n if(result candidate_list[result-1]) {\n result = i+1;\n }\n}\n\nwrite(result);"}, {"source_code": "(function() {\n \"use strict\";\n var arr = readline().split(\" \").map(function(x) { \n return parseInt(x);\n });\n var can = arr[0], cit = arr[1], mat = [];\n var canind = [], maxvotes = [];\n for(var i = 0; i < cit; i++)\n {\n mat[i] = readline().split(\" \").map(function(x) {\n return parseInt(x); \n });\n \n maxvotes[i] = mat[i][0];\n canind[i] = 0;\n for(var j = 0; j < can; j++)\n {\n if(mat[i][j] > maxvotes[i])\n {\n maxvotes[i] = mat[i][j];\n canind[i] = j;\n }\n }\n }\n \n var Tarek = [];\n for(var i = 0; i < can; i++)\n {\n Tarek[i] = 0;\n }\n \n for(var i = 0; i < cit; i++)\n {\n Tarek[canind[i]]++;\n }\n \n var fin_max = 0, fin_ind = 0;\n for(var i = 0; i < Tarek.length; i++)\n {\n if(Tarek[i] > fin_max)\n {\n fin_max = Tarek[i];\n fin_ind = i;\n }\n }\n \n print(fin_ind + 1);\n})();"}, {"source_code": "var arr = [];\nvar numberCitiesCandidates = readline();\nnumberCitiesCandidates = numberCitiesCandidates.split(' ');\nvar cities = numberCitiesCandidates[1];\nvar candidates = numberCitiesCandidates[0];\n\nfor (var i = 0; i < cities; i++) {\n var line = readline();\n if (!line) {\n break;\n }\n var lineChars = line.split(' ');\n for (var j = 0; j < candidates; j++) {\n if (!arr[i]) {\n arr[i] = [];\n }\n arr[i][j] = lineChars[j];\n }\n}\n\nvar filteration = [];\nfor (var i = 0; i < arr.length; i++) {\n var maxCanditate = {\n index: 0,\n value: Number(arr[i][0])\n };\n for (var j = 1; j < arr[i].length; j++) {\n var currVotes = Number(arr[i][j]);\n if (maxCanditate.value < currVotes) {\n maxCanditate = {\n index: j,\n value: arr[i][j]\n };\n }\n }\n\n filteration.push(maxCanditate);\n}\nvar citiesStatistics = {};\nfilteration.map(function(a) {\n if (a.index in citiesStatistics) {\n citiesStatistics[a.index]++;\n } else {\n citiesStatistics[a.index] = 1;\n }\n});\nvar winner;\nfor (var canditateIndex in citiesStatistics) {\n var canditateIndexNum = Number(canditateIndex);\n if (!winner) {\n winner = {\n index: canditateIndexNum,\n cities: citiesStatistics[canditateIndex]\n };\n } else {\n if ((winner.cities < citiesStatistics[canditateIndex]) || (winner.cities == citiesStatistics[canditateIndex] && winner.index > canditateIndexNum)) {\n winner = {\n index: canditateIndexNum,\n cities: citiesStatistics[canditateIndex]\n };\n }\n }\n}\n\nprint(winner.index + 1);\n"}], "negative_code": [{"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s, 10));\nlet n = _in[0], m = _in[1];\nlet a = [];\nfor (let i = 0; i < n; i++) {\n a.push(readline().split().map(parseInt));\n}\nlet f = (acc, _, i, v) => v[acc] < v[i] ? i : acc;\na.map((v) => v.reduce(f, 0));\nlet ct = new Array(m).fill(0);\nfor (let i = 0; i < m; i++) {\n ct[a[i]]++;\n}\nprint(ct.reduce(f, 0) + 1);\n\n"}, {"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s, 10));\nlet m = _in[0], n = _in[1];\nlet a = [];\nfor (let i = 0; i < n; i++) {\n a.push(readline().split().map(parseInt));\n}\nlet f = (acc, _, i, v) => v[acc] < v[i] ? i : acc;\na.map((v) => v.reduce(f, 0));\nlet ct = new Array(m).fill(0);\nfor (let i = 0; i < m; i++) {\n ct[a[i]]++;\n}\nprint(ct.reduce(f, 0) + 1);\n\n"}, {"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s, 10));\nlet n = _in[0], m = _in[1];\nlet a = [];\nfor (let i = 0; i < m; i++) {\n a.push(readline().split(/\\s+/).map((s) => parseInt(s, 10)));\n}\nlet f = (acc, _, i, v) => (v[acc] < v[i]) ? i : acc;\na = a.map((v) => v.reduce(f, 0));\nlet ct = new Array(m).fill(0);\nfor (let i = 0; i < m; i++) {\n ct[a[i]]++;\n}\nprint(ct.reduce(f, 0) + 1);\n\n"}, {"source_code": "var data = readline().split(' ');\nvar candidates = parseInt(data[0]);\nvar cities = parseInt(data[1]);\nvar result_cities = [];\n\nfor (var i = 0; i < cities; i++) {\n var data = readline().split(' ');\n var result = 0;\n for (var x = 0; x < candidates; x++) {\n var temp_result = parseInt(data[x]);\n if(result candidate_list[result-1]) {\n result = i+1;\n }\n}\n\nwrite(result);"}, {"source_code": "var data = readline().split(' ');\nvar candidates = parseInt(data[0]);\nvar cities = parseInt(data[1]);\nvar result_cities = [];\n\nfor (var i = 0; i < cities; i++) {\n var data = readline().split(' ');\n var result = 0;\n for (var x = 0; x < candidates; x++) {\n var temp_result = parseInt(data[x]);\n if(result candidate_list[result-1]) {\n result = i+1;\n }\n}\n\nwrite(result);"}, {"source_code": "(function () {\n \"use strict\";\n var arr = readline().split(\" \").map(function (x) {\n return parseInt(x, 10);\n }), can = arr[0], cit = arr[1], mat = [], maxi = [], index = [];\n for (var i = 0; i < cit; i++) {\n mat[i] = readline().split(\" \").map(function(z) {\n return parseInt(z);\n });\n maxi[i] = 0;\n index[i] = null;\n for(var j = can - 1; j >= 0; j--) {\n if(mat[i][j] >= maxi[i]) {\n maxi[i] = mat[i][j];\n index[i] = j;\n }\n }\n }\n \n var maxcan = [];\n \n for(i = 0; i < cit; i++) {\n maxcan[i] = 0;\n }\n\n for(i = 0; i < cit; i++) {\n maxcan[index[i]]++; \n }\n \n var maxnum = maxcan[0], maxindex = 0;\n for(i = can - 1; i >= 0; i--) {\n if(maxcan[i] >= maxnum) {\n maxnum = maxcan[i];\n maxindex = i;\n }\n }\n \n print(maxindex+1);\n \n})();"}, {"source_code": "(function () {\n \"use strict\";\n var arr = readline().split(\" \").map(function (x) {\n return parseInt(x, 10);\n }), can = arr[0], cit = arr[1], mat = [],\n maxi = [], index = [], maxcan = [],\n maxnum = maxcan[0], maxindex = 0;\n for (var i = 0; i < cit; i++) {\n mat[i] = readline().split(\" \").map(function(z) {\n return parseInt(z);\n });\n maxi[i] = 0;\n index[i] = null;\n for(var j = can - 1; j >= 0; j--) {\n if(mat[i][j] >= maxi[i]) {\n maxi[i] = mat[i][j];\n index[i] = j;\n }\n }\n } \n for(i = 0; i < cit; i++) {\n maxcan[i] = 0;\n } \n for(i = 0; i < cit; i++) {\n maxcan[index[i]]++; \n } \n for(i = cit - 1; i >= 0; i--) {\n if(maxcan[i] >= maxnum) {\n maxnum = maxcan[i];\n maxindex = i;\n }\n } \n print(maxindex+1);\n})();"}, {"source_code": "var arr = [];\nvar numberCitiesCandidates = readline();\nnumberCitiesCandidates = numberCitiesCandidates.split(' ');\nvar cities = numberCitiesCandidates[1];\nvar candidates = numberCitiesCandidates[0];\n\nfor (var i = 0; i < cities; i++) {\n var line = readline();\n if (!line) {\n break;\n }\n var lineChars = line.split(' ');\n for (var j = 0; j < candidates; j++) {\n if (!arr[i]) {\n arr[i] = [];\n }\n arr[i][j] = lineChars[j];\n }\n}\n\nvar filteration = [];\nfor (var i = 0; i < arr.length; i++) {\n var maxCanditate = {\n index: 0,\n value: Number(arr[i][0])\n };\n for (var j = 1; j < arr[i].length; j++) {\n \tvar currVotes = Number(arr[i][j]);\n if (maxCanditate.value < currVotes) {\n maxCanditate = {\n index: j,\n value: arr[i][j]\n };\n }\n }\n if(filteration.length === 0 || (filteration.length !== 0 && maxCanditate.value !== 0))\n \tfilteration.push(maxCanditate);\n}\nvar citiesStatistics = {};\nfilteration.map(function(a) {\n if (a.index in citiesStatistics) {\n citiesStatistics[a.index]++;\n } else {\n citiesStatistics[a.index] = 1;\n }\n});\nvar winner;\nfor(var canditateIndex in citiesStatistics){\n\tvar canditateIndexNum = Number(canditateIndex);\n\tif(!winner){\n\t\twinner = {index: canditateIndexNum, cities: citiesStatistics[canditateIndex]};\n\t}else{\n\t\tif((winner.cities < citiesStatistics[canditateIndex]) || (winner.cities == citiesStatistics[canditateIndex] && winner.index > canditateIndexNum)){\n\t\t\twinner = {index: canditateIndexNum, cities: citiesStatistics[canditateIndex]};\n\t\t}\n\t}\n}\n\nprint(winner.index + 1);\n"}, {"source_code": "var arr = [];\nvar input = readline();\nprint(input);\nvar lines = input.split(\"\\n\");\nfor (var i = 0; i < lines.length; i++) {\n var line = lines[i];\n var lineChars = line.split(' ');\n for (var j = 0; j < lineChars.length; j++) {\n if (!arr[i]) {\n arr[i] = [];\n }\n arr[i][j] = lineChars[j];\n }\n}\n"}, {"source_code": "var arr = [];\nfor (var i = 0; i < 100; i++) {\n var line = readline();\n if (!line) {\n break;\n }\n var lineChars = line.split(' ');\n for (var j = 0; j < lineChars.length; j++) {\n if (!arr[i]) {\n arr[i] = [];\n }\n arr[i][j] = lineChars[j];\n }\n}\nvar filteration = [];\nfor (var i = 0; i < arr.length; i++) {\n var maxCanditate = {\n index: 0,\n value: Number(arr[i][0])\n };\n for (var j = 1; j < arr[i].length; j++) {\n if (maxCanditate.value < Number(arr[i][j])) {\n maxCanditate = {\n index: j,\n value: arr[i][j]\n };\n }\n }\n filteration.push(maxCanditate);\n}\nvar citiesStatistics = {};\nfilteration.map(function(a) {\n if (a.index in citiesStatistics) {\n citiesStatistics[a.index]++;\n } else {\n citiesStatistics[a.index] = 1;\n }\n});\nvar winner;\nfor(var canditateIndex in citiesStatistics){\n\tvar canditateIndexNum = Number(canditateIndex);\n\tif(!winner){\n\t\twinner = {index: canditateIndexNum, cities: citiesStatistics[canditateIndex]};\n\t}else{\n\t\tif((winner.cities < citiesStatistics[canditateIndex]) || (winner.cities == citiesStatistics[canditateIndex] && winner.index > canditateIndexNum)){\n\t\t\twinner = {index: canditateIndexNum, cities: citiesStatistics[canditateIndex]};\n\t\t}\n\t}\n}\n\nprint(winner.index + 1);\n"}, {"source_code": "var firstInput = readline().split(' ');\nvar nCandidates = parseInt(firstInput[0]);\nvar nCities = parseInt(firstInput[1]);\nvar citiesWonByCandidates = [];\nvar i, j, highestVotePerCity, currentVote, winnerPerCityIdx, votesPerCity;\nfor (i = 0; i < nCities; i++) {\n votesPerCity = readline().split(' ');\n highestVotePerCity = 0;\n for (j = 0; j < nCandidates; j++) {\n currentVote = parseInt(votesPerCity[j]);\n if (currentVote > highestVotePerCity) {\n winnerPerCityIdx = j;\n highestVotePerCity = currentVote;\n }\n }\n if (citiesWonByCandidates[winnerPerCityIdx] == null) {\n citiesWonByCandidates[winnerPerCityIdx] = 1;\n } else {\n citiesWonByCandidates[winnerPerCityIdx] += 1;\n }\n}\nvar highestVote = 0, winner = 1;\nfor (i = 0; i < citiesWonByCandidates.length; i++) {\n if (citiesWonByCandidates[i] > highestVote) {\n winner = i+1;\n highestVote = citiesWonByCandidates[i];\n }\n}\nprint(winner);"}, {"source_code": "var firstInput = readline().split(' ');\nvar nCandidates = parseInt(firstInput[0]);\nvar nCities = parseInt(firstInput[1]);\nvar citiesWonByCandidates = [];\nvar i, j, highestVotePerCity, currentVote, winnerPerCityIdx, votesPerCity;\nfor (i = 0; i < nCities; i++) {\n\tvotesPerCity = readline().split(' ');\n\thighestVotePerCity = 0;\n\tfor (j = 0; j < nCandidates; j++) {\n\t\tcurrentVote = parseInt(votesPerCity[j]);\n\t\tif (currentVote > highestVotePerCity) {\n\t\t\twinnerPerCityIdx = j;\n\t\t\thighestVotePerCity = currentVote;\n\t\t}\n\t}\n\tif (citiesWonByCandidates[winnerPerCityIdx] == null) {\n\t\tcitiesWonByCandidates[winnerPerCityIdx] = 1;\n\t} else {\n\t\tcitiesWonByCandidates[winnerPerCityIdx] += 1;\n\t}\n}\nvar highestVote = 0, winner;\nfor (i = 0; i < citiesWonByCandidates.length; i++) {\n\tif (citiesWonByCandidates[i] > highestVote) {\n\t\twinner = i+1;\n\t\thighestVote = citiesWonByCandidates[i];\n\t}\n}\nprint(winner);"}], "src_uid": "b20e98f2ea0eb48f790dcc5dd39344d3"} {"source_code": "String.prototype.normalize = function() {\n var self = this;\n return self.toLowerCase().replace(/o/g, '0').replace(/[il]/g, 1);\n};\n\n\nvar potentialLogin = readline().normalize();\nvar existanceLoginCount = parseInt(readline());\nvar extstanceLogins = [];\nvar canLogIn = true;\nvar i = 0;\nwhile(i < existanceLoginCount) {\n var line = readline();\n if(canLogIn && potentialLogin === line.normalize()){\n canLogIn = false;\n }\n i++;\n}\n\nprint(canLogIn ? 'Yes' : 'No')", "positive_code": [{"source_code": "var login = readline().replace(/0/g, \"o\").toLowerCase().replace(/1/g, \"i\").replace(/l/g, \"i\");\nvar db = readline();\nvar logins, answer;\nfor (i=0; ie.toLowerCase(e))\n db = db.map(e=>e.replace(/(i|l)/ig,'1'))\n db = db.map(e=>e.replace(/(o)/ig,'0'))\n return db\n}\nfunction upgradeLogin(lg){\n lg = lg.toLowerCase()\n lg = lg.replace(/(i|l)/ig,'1')\n lg = lg.replace(/o/ig,'0')\n return lg\n}\nfunction check2(l,db){\n let check = true\n for(let e of db){\n if(e == l){\n check = false\n } \n }\n if(check){\n return true\n } else{\n print('No')\n return false\n }\n}\nfunction checkLogin(login,dbsize,...db){\n db=db[0] \n if(check1(login)){\n db = upgradeDatabase(db)\n login = upgradeLogin(login)\n if(check2(login,db)){\n print('Yes')\n }\n }\n}\n\nlet inputs = getInputs()\ncheckLogin(inputs[0],inputs[1],inputs.slice(2))"}, {"source_code": "//readline()\n//print()\n\nvar main = readline().trim().split(\"\").map(v => v.charCodeAt(0));\nvar n = +readline();\nvar done = true;\n\nfor(var i = 0; i < n; i++){\n var s = readline().trim();\n \n if(s.length === main.length){\n s = s.split(\"\").map(v => v.charCodeAt(0));\n \n var diffs = false;\n \n for(var j = 0; j < s.length; j++){\n if(s[j] !== main[j]){\n \n if(\n (s[j] === 48 && main[j] === 79) || \n (s[j] === 48 && main[j] === 111) || \n (s[j] === 79 && main[j] === 48) || \n (s[j] === 79 && main[j] === 111) || \n (s[j] === 111 && main[j] === 48) || \n (s[j] === 111 && main[j] === 79)\n ){\n diffs = true;\n } else\n \n if(\n (s[j] === 49 && main[j] === 105) ||\n (s[j] === 49 && main[j] === 73) ||\n (s[j] === 49 && main[j] === 108) ||\n (s[j] === 49 && main[j] === 76) ||\n \n (s[j] === 105 && main[j] === 49) ||\n (s[j] === 105 && main[j] === 73) ||\n (s[j] === 105 && main[j] === 108) ||\n (s[j] === 105 && main[j] === 76) ||\n \n (s[j] === 73 && main[j] === 49) ||\n (s[j] === 73 && main[j] === 105) ||\n (s[j] === 73 && main[j] === 108) ||\n (s[j] === 73 && main[j] === 76) ||\n \n (s[j] === 108 && main[j] === 49) ||\n (s[j] === 108 && main[j] === 105) ||\n (s[j] === 108 && main[j] === 73) ||\n (s[j] === 108 && main[j] === 76) ||\n \n (s[j] === 76 && main[j] === 49) ||\n (s[j] === 76 && main[j] === 105) ||\n (s[j] === 76 && main[j] === 73) ||\n (s[j] === 76 && main[j] === 108)\n \n ){\n diffs = true;\n } else \n \n if((s[j] >= 97 && s[j] <= 122 && s[j] - main[j] === 32) ||\n (s[j] >= 65 && s[j] <= 90 && main[j] - s[j] === 32)){\n diffs = true;\n } else {\n diffs = false;\n break;\n }\n \n }else{\n diffs = true;\n }\n }\n \n if(diffs){\n done = false;\n }\n }\n \n if(!done) break;\n}\n\nprint(done ? \"Yes\" : \"No\");"}, {"source_code": "var login = readline().toLowerCase();\nvar countLogins = +readline();\nvar logins = [];\nvar result = true;\n\nfor (var i = 0; i < countLogins; i++) {\n logins.push(readline().toLowerCase());\n}\n\n// Solution start\nfunction reformatLogin(login) {\n return login.replace(/o/gi, '0').replace(/l/gi, '1').replace(/i/gi, '1');\n}\n\nlogin = reformatLogin(login);\n\nfor (var i = 0; i < countLogins; i = i + 1) {\n var temp = reformatLogin(logins[i]);\n\n if (login === temp) {\n result = false;\n break;\n }\n}\n\nprint(result ? 'Yes' : 'No');"}, {"source_code": "\nvar input = function(){\n var userNick = normalize(readline());\n var n = parseInt(readline());\n var s = new Set();\n for(var i=0; i {\n for (var i = 0; i < existingCount; i++)\n if (newLogin === transformLogin(readline())) {\n print(\"No\");\n return;\n }\n print(\"Yes\");\n})();\n"}, {"source_code": "//Some debug stuff\nconst isDebugMode=false;\nvar log=()=>{}\nif(isDebugMode){\n var print=function (out) {\n console.log('COUT: '+ out);\n }\n log=function (out) {\n console.log('DEBUG OUTPUT: '+ out);\n }\n function* readline_generator() {\n var a=[\n 'La0',\n '3',\n '2a0',\n 'La1',\n '1a0'\n ];\n while(a.length>1){\n yield a.shift()\n }\n return a.shift();\n }\n var g=readline_generator();\n var readline=function () {\n return g.next().value;\n }\n}\n\n//SOLUTION\n\nvar compareS=function(s1, s2){\n if(s1.toLowerCase()==s2.toLowerCase()){\n return true;\n }\n switch(s1){\n case 'O':\n case '0':\n case 'o':\n if(['0', 'O', 'o'].indexOf(s2)>-1){\n return true;\n }\n break;\n case '1':\n case 'l':\n case 'I':\n case 'i':\n case 'L':\n if(['1', 'l', 'I', 'i', 'L'].indexOf(s2)>-1){\n return true;\n }\n break;\n }\n return false;\n};\n\nvar compare=function(a1, a2){\n var c=0;\n a1.forEach((i,k)=>{\n if(compareS(i, a2[k])){\n c++;\n }\n });\n return c==a1.length;\n};\n\nvar magic=function(s1, s2){\n s1=s1.split('');\n s2=s2.split('');\n var diff1=[];\n var diff2=[];\n s1.forEach((i,k)=>{\n if(i!=s2[k]){\n diff1.push(i);\n diff2.push(s2[k]);\n }\n })\n return compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count v.charCodeAt(0));\nvar n = +readline();\nvar done = true;\n\nfor(var i = 0; i < n; i++){\n var s = readline().trim();\n \n if(s.length === main.length){\n s = s.split(\"\").map(v => v.charCodeAt(0));\n \n var diffs = false;\n \n for(var j = 0; j < s.length; j++){\n if(s[j] !== main[j]){\n \n if(\n (s[j] === 48 && main[j] === 79) || \n (s[j] === 48 && main[j] === 111) || \n (s[j] === 79 && main[j] === 48) || \n (s[j] === 79 && main[j] === 111) || \n (s[j] === 111 && main[j] === 48) || \n (s[j] === 111 && main[j] === 79)\n ){\n diffs = true;\n } else\n \n if(\n (s[j] === 49 && main[j] === 105) ||\n (s[j] === 49 && main[j] === 73) ||\n (s[j] === 49 && main[j] === 108) ||\n (s[j] === 49 && main[j] === 76) ||\n \n (s[j] === 105 && main[j] === 49) ||\n (s[j] === 105 && main[j] === 73) ||\n (s[j] === 105 && main[j] === 108) ||\n (s[j] === 105 && main[j] === 76) ||\n \n (s[j] === 73 && main[j] === 49) ||\n (s[j] === 73 && main[j] === 105) ||\n (s[j] === 73 && main[j] === 108) ||\n (s[j] === 73 && main[j] === 76) ||\n \n (s[j] === 108 && main[j] === 49) ||\n (s[j] === 108 && main[j] === 105) ||\n (s[j] === 108 && main[j] === 73) ||\n (s[j] === 108 && main[j] === 76) ||\n \n (s[j] === 76 && main[j] === 49) ||\n (s[j] === 76 && main[j] === 105) ||\n (s[j] === 76 && main[j] === 73) ||\n (s[j] === 76 && main[j] === 108)\n \n ){\n diffs = true;\n } else \n \n if((s[j] >= 97 && s[j] <= 122 && s[j] - main[j] === 32) ||\n (s[j] >= 65 && s[j] <= 90 && main[j] - s[j] === 32)){\n diffs = true;\n } else {\n diffs = false;\n break;\n }\n \n }\n }\n \n if(diffs){\n done = false;\n }\n }\n \n if(!done) break;\n}\n\nprint(done ? \"Yes\" : \"No\");"}, {"source_code": "var compareS=function(s1, s2){\n if(s1.toLowerCase()==s2.toLowerCase()){\n return true;\n }\n switch(s1){\n case 'O':\n case '0':\n case 'o':\n if(['0', 'O', 'o'].indexOf(s2)>-1){\n return true;\n }\n break;\n case '1':\n case 'l':\n case 'I':\n case 'i':\n if(['1', 'l', 'I', 'i'].indexOf(s2)>-1){\n return true;\n }\n break;\n }\n return false;\n};\n\nvar compare=function(a1, a2){\n var c=0;\n a1.forEach((i,k)=>{\n if(compareS(i, a2[k])){\n c++;\n }\n });\n return c==a1.length;\n};\n\nvar magic=function(s1, s2){\n s1=s1.split('');\n s2=s2.split('');\n var diff1=[];\n var diff2=[];\n s1.forEach((i,k)=>{\n if(i!=s2[k]){\n diff1.push(i);\n diff2.push(s2[k]);\n }\n})\n return compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count-1){\n return true;\n }\n break;\n case '1':\n case 'l':\n case 'I':\n if(['1', 'l', 'I'].indexOf(s2)>-1){\n return true;\n }\n break;\n }\n return false;\n};\n\nvar compare=function(a1, a2){\n var c=0;\n a1.forEach((i,k)=>{\n if(compareS(i, a2[k])){\n c++;\n }\n });\n return c==a1.length;\n};\n\nvar magic=function(s1, s2){\n s1=s1.split('');\n s2=s2.split('');\n var diff1=[];\n var diff2=[];\n s1.forEach((i,k)=>{\n if(i!=s2[k]){\n diff1.push(i);\n diff2.push(s2[k]);\n }\n})\n return compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase '1':\n\t\tcase 'l':\n\t\tcase 'I':\n\t\t\tif(['1', 'l', 'I'].indexOf(s2)>-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn false;\n};\n\nvar compare=function(a1, a2){\n\tvar c=0;\n\ta1.forEach((i,k)=>{\n\t\tif(compareS(i, a2[k])){\n\t\t\tc++;\n\t\t}\n\t})\n\treturn c==a1.length;\n}\n\nvar magic=function(s1, s2){\n\ts1=s1.split('');\n\ts2=s2.split('');\n\tvar diff1=[];\n\tvar diff2=[];\n\ts1.forEach((i,k)=>{\n\t\tif(i!=s2[k]){\n\t\t\tdiff1.push(i);\n\t\t\tdiff2.push(s2[k]);\n\t\t}\n\t})\n\treturn compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\n\nwhile(count-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase '1':\n\t\tcase 'l':\n\t\tcase 'I':\n\t\t\tif(['1', 'l', 'I'].indexOf(s2)>-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn false;\n};\n\nvar compare=function(a1, a2){\n\tvar c=0;\n\ta1.forEach((i,k)=>{\n\t\tif(compareS(i, a2[k])){\n\t\t\tc++;\n\t\t}\n\t})\n\treturn c==a1.length;\n}\n\nvar magic=function(s1, s2){\n\ts1=s1.split('');\n\ts2=s2.split('');\n\tvar diff1=[];\n\tvar diff2=[];\n\ts1.forEach((i,k)=>{\n\t\tif(i!=s2[k]){\n\t\t\tdiff1.push(i);\n\t\t\tdiff2.push(s2[k]);\n\t\t}\n\t})\n\treturn compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\n\nwhile(count-1){\n return true;\n }\n break;\n case '1':\n case 'l':\n case 'I':\n if(['1', 'l', 'I'].indexOf(s2)>-1){\n return true;\n }\n break;\n }\n return false;\n};\n\nvar compare=function(a1, a2){\n var c=0;\n a1.forEach((i,k)=>{\n if(compareS(i, a2[k])){\n c++;\n }\n });\n return c==a1.length;\n};\n\nvar magic=function(s1, s2){\n s1=s1.split('');\n s2=s2.split('');\n var diff1=[];\n var diff2=[];\n s1.forEach((i,k)=>{\n if(i!=s2[k]){\n diff1.push(i);\n diff2.push(s2[k]);\n }\n})\n return compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase '1':\n\t\tcase 'l':\n\t\tcase 'I':\n\t\t\tif(['1', 'l', 'I'].indexOf(s2)>-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn false;\n};\n\nvar compare=function(a1, a2){\n\tvar c=0;\n\ta1.forEach((i,k)=>{\n\t\tif(compareS(i, a2[k])){\n\t\t\tc++;\n\t\t}\n\t})\n\treturn c==a1.length;\n}\n\nvar magic=function(s1, s2){\n\ts1=s1.split('');\n\ts2=s2.split('');\n\tvar diff1=[];\n\tvar diff2=[];\n\ts1.forEach((i,k)=>{\n\t\tif(i!=s2[k]){\n\t\t\tdiff1.push(i);\n\t\t\tdiff2.push(s2[k]);\n\t\t}\n\t})\n\treturn compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase '1':\n\t\tcase 'l':\n\t\tcase 'I':\n\t\t\tif(['1', 'l', 'I'].indexOf(s2)>-1){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn false;\n};\n\nvar compare=function(a1, a2){\n\tvar c=0;\n\ta1.forEach((i,k)=>{\n\t\tif(compareS(i, a2[k])){\n\t\t\tc++;\n\t\t}\n\t})\n\treturn c==a1.length;\n}\n\nvar magic=function(s1, s2){\n\ts1=s1.split('');\n\ts2=s2.split('');\n\tvar diff1=[];\n\tvar diff2=[];\n\ts1.forEach((i,k)=>{\n\t\tif(i!=s2[k]){\n\t\t\tdiff1.push(i);\n\t\t\tdiff2.push(s2[k]);\n\t\t}\n\t})\n\treturn compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count-1){\n return true;\n }\n break;\n case '1':\n case 'l':\n case 'I':\n case 'i':\n if(['1', 'l', 'I', 'i'].indexOf(s2)>-1){\n return true;\n }\n break;\n }\n return false;\n};\n\nvar compare=function(a1, a2){\n var c=0;\n a1.forEach((i,k)=>{\n if(compareS(i, a2[k])){\n c++;\n }\n });\n return c==a1.length;\n};\n\nvar magic=function(s1, s2){\n s1=s1.split('');\n s2=s2.split('');\n var diff1=[];\n var diff2=[];\n s1.forEach((i,k)=>{\n if(i!=s2[k]){\n diff1.push(i);\n diff2.push(s2[k]);\n }\n })\n return compare(diff1, diff2)\n}\n\n\n\nvar loginToTest=readline();\n\nvar numOfLogins=+(readline());\n\nvar count=0;\nvar f=0;\nwhile(count=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var len = n.length;\r\n var val = Math.pow(10, len-1);\r\n // console.log(len, val)\r\n val = max(val, 0);\r\n // n -= 0;\r\n var ans = n - val;\r\n console.log(ans)\r\n \r\n}\r\n", "positive_code": [{"source_code": "var tens = [];\r\n for (var i=0; i < 10; i++) {\r\n tens.push(Math.pow(10,i));\r\n }\r\n var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var m = parseInt(readline());\r\n var i = 1;\r\n while (tens[i] && m >= tens[i]) {\r\n i++;\r\n }\r\n print(m-tens[i-1]);\r\n }"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar m = readInt();\r\n\t\tvar x = 1;\r\n\t\twhile (x * 10 <= m) {\r\n\t\t\tx *= 10;\r\n\t\t}\r\n\t\tvar ans = m - x;\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "t = parseInt(readline());\r\n\r\nvar ans =0, n ;\r\n\r\nwhile(t--)\r\n{\r\n ans =1;\r\n //n= prompt();\r\n n= parseInt(readline());\r\n \r\n while(ans*10<=n) ans*=10;\r\n\r\n print(n-ans);\r\n //console.log(n-ans);\r\n\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n e = '1'\n for(l = 0; l < k.length - 1; l++){\n e += '0'\n }\n e = Number(e)\n \n if(b < 10){\n console.log(b-1)\n }else{\n \n console.log(k.join('')-e)\n\n }\n\n }\n \n\t \n}); "}, {"source_code": "// \u043a\u0430\u043a \u043c\u0435\u043d\u044f \u0437\u0430\u0435\u0431\u0430\u043b\u0430 \u044d\u0442\u0430 \u043a\u043e\u0440\u044f\u0432\u0430\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\r\n// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\nconst state = { i: 0 }\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nconst ten_exp = (exp = 0) => 10 ** exp\r\nrl.on('line', function (line) {\r\n if (state.i > 0) console.log((line - ten_exp(line.length - 1)).toString() + '\\r')\r\n state.i++\r\n})"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getRound(m) {\r\n let s = 0\r\n let base = 10\r\n let t = 0\r\n while (t <= m) {\r\n s++;\r\n t = Math.pow(base,s)\r\n }\r\n return m - Math.pow(base,s - 1)\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getRound(values[i])\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n var k = lines[i].split('').map(Number);\n if(a < 10){\n console.log(a - 1); \n }else{\n var fl = '1';\n var len = k.length;\n for(j = 1; j < len; j++){\n fl += '0';\n }\n console.log(a - fl);\n }\n }\n});"}, {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var x = parseInt(readline());\r\n let prev = 1;\r\n let next = 1;\r\n let ans = 1;\r\n while (next <= x) {\r\n ans = Math.min(Math.abs(x-prev),Math.abs(x-next));\r\n prev = 10;\r\n next *= 10;\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = readline().trim();\r\n let p = n.length,\r\n k = 10;\r\n if (p === 1) {\r\n console.log(parseInt(n) - 1);\r\n continue;\r\n }\r\n for (let i = 2; i < p; i++) k = k * 10;\r\n console.log(Math.abs(parseInt(n) - k));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let price = readline();\r\n let target = 0;\r\n if (price.length === 1) {\r\n target = 1\r\n } else {\r\n target = Number('1' + ('0').repeat(price.length - 1));\r\n }\r\n output(Number(price) - target);\r\n \r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s) {\r\n return n - 10 ** (n.toString().length - 1);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const k = Math.floor(Math.log10(n))\n return n - 10 ** k\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar M = nextInt();\r\n\t\tvar d = 0;\r\n\t\tvar now = 1;\r\n\t\twhile(true){\r\n\t\t\tif(now * 10 <= M){\r\n\t\t\t\tnow *= 10;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\tmyout(M - now);\r\n\t}\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n m = readline().split('').map(el => +el)\r\n \r\n if(m[0] !=1){\r\n m[0] = m[0] - 1\r\n }\r\n else{\r\n m.shift()\r\n }\r\n if(m.length){\r\n print(+m.join(''))\r\n } \r\n else{\r\n print('0')\r\n }\r\n \r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var valueString = readline();\r\n var power = valueString.length;\r\n var value = parseInt(valueString);\r\n var roundNum = 1;\r\n for (var j = 1; j < power; j++)\r\n {\r\n roundNum *= 10;\r\n }\r\n var result = value - roundNum;\r\n print(result);\r\n}"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n e = 1\n for(l = 0; l < k.length - 1; l++){\n e += '0'\n }\n if(b < 10){\n console.log(b-1)\n }else{\n \n console.log(k-e)\n\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1\n if(b < 10){\n console.log(b-1)\n }else{\n \n console.log(k.join(''))\n\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1\n if(b < 10){\n console.log(b)\n }else{\n \n console.log(k.join(''))\n\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n if(k[0] === 0 && k.length > 1){\n k.splice(0,1)\n }\n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n if(k[0] === 0){\n k.splice(0,1)\n }\n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n if(k[0] === 0 && k.length < 1){\n k.splice(0,1)\n }\n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n if(k[0] === 0 && k.length <= 1){\n k.splice(0,1)\n }\n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(\" \").map(Number)\n \n a = Math.abs(k[0] - 1);\n b = Math.abs(k[2] - k[1]) + Math.abs(k[2] - 1);\n if (a < b) {\n console.log(1);\n } else if (b < a) {\n console.log(2);\n } else {\n console.log(3);\n }\n\n }\n \n\t \n}); "}, {"source_code": "// cat .\\input.txt | node .\\script.js\r\nconst state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n').filter(v => v.length > 0)\r\n for (let i = 0; i < split.length; i++) {\r\n const element = split[i];\r\n if (element.indexOf(' ') == -1) {\r\n state.data.push(Number(element))\r\n continue\r\n }\r\n // if (element.indexOf(' ') > -1) {\r\n // state.data.push(element.split(' ').map(Number))\r\n // continue\r\n // }\r\n }\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst ten_ext = (exp = 0) => 10 ** exp\r\nconst main = (args) => {\r\n const { data } = state\r\n const range = data.shift()\r\n let result = \"\"\r\n for (let i = 0; i < range; i++) {\r\n const element = data[i];\r\n const etos = element.toString()\r\n const etosl = etos.length\r\n result += ((element - ten_ext(etosl - 1)).toString() + '\\r\\n')\r\n }\r\n commit(result)\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "// cat .\\input.txt | node .\\script.js\r\nconst state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n').filter(v => v.length > 0)\r\n for (let i = 0; i < split.length; i++) {\r\n const element = split[i];\r\n if (element.indexOf(' ') == -1) {\r\n state.data.push(Number(element))\r\n continue\r\n }\r\n if (element.indexOf(' ') > -1) {\r\n state.data.push(element.split(' ').map(Number))\r\n continue\r\n }\r\n }\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst ten_ext = (exp = 0) => 10 ** exp\r\nconst main = (args) => {\r\n const { data } = state\r\n const range = data.shift()\r\n let result = \"\"\r\n for (let i = 0; i < range; i++) {\r\n const element = data[i];\r\n const etos = element.toString()\r\n const etosl = etos.length\r\n result += ((element - ten_ext(etosl - 1)).toString() + '\\r\\n')\r\n }\r\n commit(result)\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "// cat .\\input.txt | node .\\script.js\r\nconst state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n').filter(v => v.length > 0)\r\n for (let i = 0; i < split.length; i++) {\r\n const element = split[i];\r\n if (element.indexOf(' ') == -1) {\r\n state.data.push(Number(element))\r\n continue\r\n }\r\n if (element.indexOf(' ') > -1) {\r\n state.data.push(element.split(' ').map(Number))\r\n continue\r\n }\r\n }\r\n state.input_counter++\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst ten_ext = (exp = 0) => 10 ** exp\r\nconst main = (args) => {\r\n const { data } = state\r\n const range = data.shift()\r\n for (let i = 0; i < range; i++) {\r\n const element = data[i];\r\n const etos = element.toString()\r\n const etosl = etos.length\r\n commit((element - ten_ext(etosl - 1)).toString() + '\\r\\n')\r\n }\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getRound(m) {\r\n let s = 0\r\n let base = 10\r\n let t = 0\r\n while (t < m) {\r\n t = Math.pow(base,++s)\r\n }\r\n return m === t ? 0 : m - Math.pow(base,s - 1)\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getRound(values[i])\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getRound(m) {\r\n let s = 0\r\n let base = 10\r\n let t = 0\r\n while (t < m) {\r\n t = Math.pow(base,++s)\r\n }\r\n return m - Math.pow(base,--s)\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getRound(values[i])\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getRound(m) {\r\n let s = 0\r\n let base = 10\r\n let t = 0\r\n while (t < m) {\r\n t = Math.pow(base,++s)\r\n }\r\n return m - (t/10)\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getRound(values[i])\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n m = readline().split('').map(el => +el)\r\n \r\n if(m[0] !=1){\r\n m[0] = m[0] - 1\r\n }\r\n else{\r\n m.shift()\r\n }\r\n if(m.length){\r\n print(m.join(''))\r\n } \r\n else{\r\n print('0')\r\n }\r\n \r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n m = readline().split('').map(el => +el)\r\n\r\n if(m[0] !=1){\r\n m[0] = m[0] - 1\r\n }\r\n else{\r\n m.shift()\r\n }\r\n if(m.length){\r\n print(m.join(''))\r\n } \r\n else{\r\n print('0')\r\n }\r\n \r\n}\r\n"}, {"source_code": "var tens = [];\r\n for (var i=0; i < 10; i++) {\r\n tens.push(Math.pow(10,i));\r\n }\r\n var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var m = parseInt(readline());\r\n var i = 1;\r\n while (tens[i] && m > tens[i]) {\r\n i++;\r\n }\r\n print(m-tens[i-1]);\r\n }"}], "src_uid": "5312a505bd59b55a6c5487f67a33d81a"} {"source_code": "// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|\r\nfunction solve(n, k, b, s){\r\n // const FIRST_GLASS = (k+1) * b - 1;\r\n // const REST_GLASS = b - 1;\r\n const FIRST_GLASS = k * (b+1) - 1;\r\n const REST_GLASS = k - 1;\r\n const MIN_CAPACITY = k * b;\r\n const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);\r\n if(s < MIN_CAPACITY || s > MAX_CAPACITY) return [-1]; // RTE if not arr\r\n\r\n const result = Array(n).fill(0);\r\n\r\n for(let i=0;idata+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n B1715(dataLines);\r\n});\r\n\r\n\r\n\r\n/* --------------------------------------- local test ------------------------------------------ \r\n\r\nlet data = `8\r\n1 6 3 100\r\n3 6 3 12\r\n3 6 3 19\r\n5 4 7 38\r\n5 4 7 80\r\n99978 1000000000 100000000 1000000000000000000\r\n1 1 0 0\r\n4 1000000000 1000000000 1000000000000000000`;\r\n\r\nconst dataLines = data.split('\\n');\r\nconsole.log(B1715(dataLines));\r\n\r\n*/\r\n\r\n\r\n/* --------------------------------------- boilerplate ------------------------------------------ */\r\n\r\nfunction convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\nfunction printArray(arr){ // [12, 43, 123, 4] >> '12 43 123 4'\r\n return arr.join(' ');\r\n}\r\nfunction B1715(input){\r\n let result = '';\r\n const tests = Number(input[0]);\r\n for(let i=1; i<=tests; i++){\r\n const [n, k, b, s] = convertNumberArray(input[i]);\r\n // process.stdout.write(solve(n, k, b, s) + '\\n'); // array printing error\r\n process.stdout.write(printArray(solve(n, k, b, s)) + '\\n');\r\n result+=solve(n, k, b, s) + '\\n'\r\n }\r\n return result;\r\n}\r\n\r\n\r\n/*\r\nanswer\r\n-1\r\n-1\r\n0 0 19\r\n0 3 3 3 29\r\n-1\r\n-1\r\n0\r\n0 0 0 1000000000000000000\r\n\r\n*/\r\n", "positive_code": [{"source_code": "var tests = parseInt(readline());\r\n var n, k, b, s;\r\n\r\n for (var t=0; t < tests; t++) {\r\n var nkbs = readline().split(' ').map(x=>parseInt(x));\r\n n = nkbs[0];\r\n k = nkbs[1];\r\n b = nkbs[2];\r\n s = nkbs[3];\r\n \r\n if (s < k * b || s > k * b + n * (k-1)) {\r\n print(-1);\r\n continue;\r\n }\r\n var ans = [];\r\n var sum = s;\r\n var first = b * k;\r\n first += Math.min(sum - b*k, k-1);\r\n ans.push(first);\r\n sum -= first;\r\n while (sum > 0) {\r\n var next = Math.min(k-1, sum);\r\n ans.push(next);\r\n sum -= next;\r\n }\r\n while (ans.length < n) {\r\n ans.push(0);\r\n }\r\n print(ans.join(' '));\r\n }"}], "negative_code": [{"source_code": "// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|\r\nfunction solve(n, k, b, s){\r\n // const FIRST_GLASS = (k+1) * b - 1;\r\n // const REST_GLASS = b - 1;\r\n const FIRST_GLASS = k * (b+1) - 1;\r\n const REST_GLASS = k - 1;\r\n const MIN_CAPACITY = k * b;\r\n const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);\r\n if(s < MIN_CAPACITY || s > MAX_CAPACITY) return -1;\r\n\r\n const result = Array(n).fill(0);\r\n\r\n for(let i=0;idata+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n B1715(dataLines);\r\n});\r\n\r\n\r\n\r\n/* --------------------------------------- local test ------------------------------------------ */\r\n\r\n// let data = `8\r\n// 1 6 3 100\r\n// 3 6 3 12\r\n// 3 6 3 19\r\n// 5 4 7 38\r\n// 5 4 7 80\r\n// 99978 1000000000 100000000 1000000000000000000\r\n// 1 1 0 0\r\n// 4 1000000000 1000000000 1000000000000000000`;\r\n\r\n// const dataLines = data.split('\\n');\r\n// console.log(B1715(dataLines));\r\n\r\n\r\n\r\n/* --------------------------------------- boilerplate ------------------------------------------ */\r\n\r\nfunction convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\nfunction B1715(input){\r\n let result = '';\r\n const tests = Number(input[0]);\r\n for(let i=1; i<=tests; i++){\r\n const [n, k, b, s] = convertNumberArray(input[i]);\r\n process.stdout.write(solve(n, k, b, s) + '\\n');\r\n result+=solve(n, k, b, s) + '\\n'\r\n }\r\n return result;\r\n}\r\n\r\n\r\n/*\r\nanswer\r\n-1\r\n-1\r\n0 0 19\r\n0 3 3 3 29\r\n-1\r\n-1\r\n0\r\n0 0 0 1000000000000000000\r\n\r\n*/"}], "src_uid": "b7ed6f296536d7cd464768b6f315fb99"} {"source_code": "const n = Number(readline());\nconst s = Array.from(readline().substring(0, n), c => c === \"b\");\nconst t = Array.from(readline().substring(0, n), c => c === \"b\");\nconst results = (() => {\n if (s.concat(t).reduce((a, b) => a ^ b)) return null;\n var abs = [];\n var bas = [];\n for (var i = 0; i < n; i++)\n if (s[i] ^ t[i]) {\n if (t[i]) abs.push(i);\n else bas.push(i);\n }\n var results = [];\n while (abs.length >= 2)\n results.push([abs.pop(), abs.pop()]);\n while (bas.length >= 2)\n results.push([bas.pop(), bas.pop()]);\n if (abs.length) {\n if (!bas.length) return null;\n var x = abs.pop();\n results.push([x, x], [x, bas.pop()]);\n }\n return results;\n})();\nif (results) {\n print(results.length);\n for (var result of results)\n print(`${result[0] + 1} ${result[1] + 1}`);\n} else print(\"-1\");\n", "positive_code": [{"source_code": "const n = Number(readline());\nconst s = Array.from(readline().substring(0, n), c => c === \"b\");\nconst t = Array.from(readline().substring(0, n), c => c === \"b\");\nconst results = (() => {\n if (s.concat(t).reduce((a, b) => a ^ b)) return null;\n var abs = [];\n var bas = [];\n for (var i = 0; i < n; i++)\n if (s[i] ^ t[i]) {\n if (t[i]) abs.push(i);\n else bas.push(i);\n }\n var results = [];\n while (abs.length >= 2)\n results.push([abs.pop(), abs.pop()]);\n while (bas.length >= 2)\n results.push([bas.pop(), bas.pop()]);\n if (abs.length) {\n if (!bas.length) return null;\n var x = abs.pop();\n results.push([x, x], [x, bas.pop()]);\n }\n return results;\n})();\nif (results) {\n print(results.length);\n for (var result of results)\n print(`${result[0] + 1} ${result[1] + 1}`);\n} else print(\"-1\");\n"}], "negative_code": [], "src_uid": "181199a0cf37c83cec1ba28d343b50ae"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1, d1] = d.split(\" \").map(Number);\n const ans = Number(a1 < b1) + Number(a1 < c1) + Number(a1 < d1);\n console.log(ans);\n\n // const numbers = d.split(\" \").map(Number);\n // let me = numbers[0];\n // const ans = numbers.filter((x) => x > me).length;\n\n // console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n", "positive_code": [{"source_code": "var n = readline();\r\nvar arr = [];\r\nvar s = 0;\r\nfor(var i = 0; i < n; i++){\r\n arr[i] = readline().split(' ').map(i=>Number(i));\r\n for(var j = 0; j < arr[i].length; j++){\r\n if(arr[i][0] a)\r\n count++;\r\n }\r\n print(count);\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split(' ');\r\n var a = parseInt(inp[0]);\r\n var b = parseInt(inp[1]);\r\n var c = parseInt(inp[2]);\r\n var d = parseInt(inp[3]);\r\n\r\n var ans = (b > a) + (c > a) + (d > a);\r\n\r\n print(ans);\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i =0 ; i < t ; i++){\r\n var inputs = readline().split(' '),\r\n counter = 0,\r\n timur = inputs[0],\r\n participants = inputs.slice(1);\r\n for(var j = 0 ; j < participants.length ; j++){\r\n if(parseInt(participants[j]) > parseInt(timur) ){\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n}"}, {"source_code": "var testCase=+readline(),counter\r\nfor(var i=0;ia-b)\r\n print(4-a.indexOf(b)-1)\r\n}\r\n"}, {"source_code": "test = readline();\r\n\r\nwhile (test--) {\r\n input = readline().split(\" \").map(x => parseInt(x));\r\n Timur = input[0];\r\n participantsInFront = 0;\r\n\r\n for (var i = 1; i <= 3; i++) {\r\n if (Timur < input[i]) {\r\n participantsInFront++;\r\n }\r\n }\r\n print(participantsInFront)\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = readline().split(' ').map(a => +a)\r\n a = n[0]\r\n b = n[1]\r\n c = n[2]\r\n d = n[3]\r\n\r\n ans = 0\r\n if(b>a)\r\n ans++\r\n if(c>a)\r\n ans++\r\n if(d>a)\r\n ans++\r\n \r\n print(ans)\r\n}\r\n\r\n"}, {"source_code": "// \u043a\u0430\u043a \u043c\u0435\u043d\u044f \u0437\u0430\u0435\u0431\u0430\u043b\u0430 \u044d\u0442\u0430 \u043a\u043e\u0440\u044f\u0432\u0430\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\r\n// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\nconst state = { i: 0 }\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nconst ten_exp = (exp = 0) => 10 ** exp\r\nrl.on('line', function (line) {\r\n if (state.i > 0) {\r\n let data = line.split(' ').map(Number)\r\n let above = []\r\n for (let i = 1; i < data.length; i++) {\r\n const sample = data[0]\r\n const element = data[i];\r\n if (element > sample) above.push(element)\r\n\r\n }\r\n console.log(above.length)\r\n }\r\n state.i++\r\n})\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var ans = 0;\n\t for(j = 1; j < 4; j++){\n if(k[j] > k[0]){\n\t ans++;\n }\n\t }\n\t console.log(ans);\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var k = lines[i].split(' ').map(Number);\n\t var a = k[0];\n\t var ans = 0;\n\t for(j = 1; j < 4; j++){\n\t if(k[j] > a){\n\t ans++;\n\t }\n\t }\n\t console.log(ans);\n\t}\n});\n\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const numbers = d.split(\" \").map(Number);\n let me = numbers[0];\n const ans = numbers.filter((x) => x > me).length;\n\n console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nconst res = [];\r\nrl.on('line', (line) => {\r\n const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));\r\n if (rest.length !== 3) return;\r\n console.log(rest.filter(n => n > timur).length);\r\n}).on('close', () => {\r\n process.exit();\r\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n const [x, ...arr] = a;\r\n let res = 0;\r\n for (let num of a) if (num > x) res++;\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = Number(input[0])\r\n for (let i = 0; i < t; i++) {\r\n const [a, b, c, d] = input[i + 1].split(' ').map((x) => parseInt(x))\r\n\r\n let ans = 0\r\n ans += b > a ? 1 : 0\r\n ans += c > a ? 1 : 0\r\n ans += d > a ? 1 : 0\r\n\r\n console.log(ans)\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n let cases = input.slice(1).map(v=>v.split(' ').map(Number));\r\n \r\n for (let c of cases) {\r\n ans.push(c.filter(v=>v>c[0]).length);\r\n }\r\n console.log(ans.join('\\n'));\r\n \r\n});"}, {"source_code": "const { readFileSync } = require(\"fs\")\r\n \r\nlet x = readFileSync(\"./input.fd0138e687.txt\",\"utf-8\").match(/(\\d+\\s){3}\\d+/g)\r\n \r\nfor(let e of x){\r\n let [b,...a] = e.split(\" \")\r\n console.log( a.filter(e=>+e>+b).length )\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet data = [];\r\nlet dataIdx = 0;\r\n\r\nrl.on('line', function (line) {\r\n //input,\r\n data.push(...line.trim().split(' '));\r\n}).on('close', function () {\r\n //output\r\n main();\r\n process.exit();\r\n});\r\n\r\nfunction input() {\r\n return data[dataIdx++];\r\n}\r\n\r\nfunction output(value) {\r\n try {\r\n process.stdout.write(value);\r\n } catch (err) {\r\n process.stdout.write(value.toString());\r\n }\r\n}\r\n//////////////////////////////////////////////////////////\r\n\r\nfunction main() {\r\n //ps start!\r\n\r\n let t = Number(input());\r\n while (t--) {\r\n let [a, b, c, d] = [\r\n Number(input()),\r\n Number(input()),\r\n Number(input()),\r\n Number(input()),\r\n ];\r\n\r\n let result = 0;\r\n if (b > a) {\r\n result++;\r\n }\r\n if (c > a) {\r\n result++;\r\n }\r\n if (d > a) {\r\n result++;\r\n }\r\n output(result + '\\n');\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const T = readline()\r\n for (let i = 0; i < T; i++) {\r\n const arr = readline().split(' ').map(Number)\r\n let result = 0\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i] > arr[0]) result++\r\n }\r\n console.log(result)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [a,b,c,d] = readline().split(' ').map(Number);\r\n let r = 0;\r\n if (b > a) r++;\r\n if (c > a) r++;\r\n if (d > a) r++;\r\n output(r);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j ++){\n var s = lines[j].split(' ').map(Number)\n var a = s[0]\n var b = s[1]\n var c = s[2]\n var d = s[3]\n var e = 0\n for(l = 1; l <= 4; l++){\n if(a < s[l]){\n e+=1\n }\n }\n console.log(e)\n }\n \n});\n"}, {"source_code": "function Solution() {\n let t = 0;\n const n = Number(lines[t++]);\n\n const res = [];\n for (let i = 0; i < n; i++) {\n const arr = lines[t++].split(' ').map((item) => Number(item));\n let count = 0;\n for (let z = 0; z < arr.length; z++) {\n if (arr[z] > arr[0]) count += 1;\n }\n res[i] = count;\n }\n \n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n n = 0;\r\n const s = readline().split(\" \").map(Number);\r\n for (let j = 1; j < s.length; j++) {\r\n if (s[j] > s[0]) {\r\n n++;\r\n }\r\n }\r\n console.log(n);\r\n }\r\n} "}, {"source_code": "//Setup\r\nlet i = ''\r\nlet a;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n a=lines\r\n//Actual Code \r\nfunction stringToNumber(array){\r\n for (var i = 0; i < array.length; i++){\r\n array[i]=parseInt(array[i])\r\n }\r\n \r\n return array\r\n}\r\nvar numTestes = a[0]\r\nnumTestes = parseInt(numTestes)\r\nvar testData = []\r\nfor(c=1;c<=numTestes;c++){\r\n testData.push(stringToNumber(a[c].split(\" \")))\r\n}\r\n\r\nfor(b=0;b parseInt(x, 10));\n var a = xs[0];\n console.log(xs.slice(1).map(x => a < x).reduce((x, y) => x + y));\n }\n}\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n"}, {"source_code": "const solve = (arr)=>{\r\n let a = arr[0],cnt = 0;\r\n for(let i=1;i<4;i++){\r\n if(arr[i]>a) cnt++;\r\n }\r\n return cnt;\r\n}\r\n\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.nums();\n\t\tlet x = a.shift();\n\t\tlet c = a.reduce((ac, e) => ac + ((e>x)?1:0), 0);\n\t\tans.push(c);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n let n = readline()\r\n\r\n for (let i = 0; i < n; i++) {\r\n let participants = 0\r\n\r\n let row = readline().split(' ')\r\n\r\n if (parseInt(row[0]) < parseInt(row[1])) {\r\n participants++\r\n }\r\n\r\n if (parseInt(row[0]) < parseInt(row[2])) {\r\n participants++\r\n }\r\n\r\n if (parseInt(row[0]) < parseInt(row[3])) {\r\n participants++\r\n }\r\n\r\n console.log(participants)\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n while(t--)\r\n {\r\n let n = readIntArray();\r\n let cnt = 0;\r\n for(let i=1;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction findKthLargest(nums, k) {\r\n k = nums.length - k;\r\n const quickSelect = (l, r) => {\r\n let pivot = nums[r];\r\n let p = l;\r\n for (let i = l; i < r; i++) {\r\n if (nums[i] <= pivot) {\r\n swapper(nums, p, i);\r\n p++;\r\n }\r\n }\r\n swapper(nums, p, r);\r\n\r\n if (p > k) return quickSelect(l, p - 1);\r\n else if (p < k) return quickSelect(p + 1, r);\r\n else return nums[p];\r\n };\r\n\r\n return quickSelect(0, nums.length - 1);\r\n};\r\n\r\nfunction swapper(array, a, b) {\r\n const temp = array[b];\r\n array[b] = array[a];\r\n array[a] = temp;\r\n};\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n for(var i=0; i parseInt(r));\r\n var count = 0;\r\n var num = nums[0];\r\n for(var j=1; j<4; j++){\r\n if(nums[j]>num){\r\n count++;\r\n }\r\n }\r\n foo(String(count));\r\n }\r\n}\r\nfunction foo(x) {\r\n process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(); // with auto '\\n' (newline)\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let input = readline().split(\" \").map(Number);\r\n print(R(input));\r\n }\r\n}\r\n\r\nfunction R(arr) {\r\n let count = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i] > arr[0]) count++;\r\n }\r\n return count;\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n //var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var [a,b,c,d] = readline().split(' ').map((x) => parseInt(x));\r\n var ans = 0;\r\n if(b > a) ans++\r\n if(c > a) ans++\r\n if(d > a) ans++\r\n console.log(ans)\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar list = [];\r\n\t\tfor(var i = 0; i < 4; i++){\r\n\t\t\tlist.push({\r\n\t\t\t\tno : i,\r\n\t\t\t\tv : nextInt()\r\n\t\t\t});\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b.v - a.v;\r\n\t\t});\r\n\t\tfor(var i = 0; i < 4; i++){\r\n\t\t\tif(list[i].no == 0){\r\n\t\t\t\tmyout(i);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n let ans = 0\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] > arr[0]) ans++\n }\n return ans\n}\n"}, {"source_code": "\"use strict\";\r\n \r\n let t = +(readline());\r\n \r\n for(let i=0;i +dist[0])cnt++;\r\n }\r\n \r\n print(cnt);\r\n }"}, {"source_code": "\"use strict\";\r\n\r\n let x = +(readline());\r\n\r\n for(let i = 0; i < x; i++) {\r\n marathone(readline().split(' ')); \r\n }\r\n\r\n function marathone(distances) {\r\n let counter = 0;\r\n for(let i = 1; i < 4; i++) {\r\n let timurDistance = +distances[0];\r\n\r\n if(timurDistance < +distances[i]) {\r\n counter++;\r\n } \r\n }\r\n\r\n print(counter);\r\n }"}, {"source_code": "var t = readline();\r\nfor(var i =0 ; i < t ; i++){\r\n var inputs = readline().split(' '),\r\n counter = 0,\r\n timur = inputs[0],\r\n participants = inputs.slice(1);\r\n for(var j = 0 ; j < participants.length ; j++){\r\n if(parseInt(participants[j]) > parseInt(timur) ){\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n \r\n let t = +(readline());\r\n \r\n for(let i=0;i (dist[0]))cnt++;\r\n }\r\n \r\n print(cnt);\r\n }"}, {"source_code": "\"use strict\";\r\n \r\n let t = +(readline());\r\n \r\n for(let i=0;i +dist[0])cnt++;\r\n }\r\n print(dist[0]);\r\n print(cnt);\r\n }"}, {"source_code": "\"use strict\";\r\n \r\n let t = +(readline());\r\n \r\n for(let i=0;i dist[0])cnt++;\r\n }\r\n \r\n print(cnt);\r\n }"}, {"source_code": "\"use strict\";\r\n\r\n let t = +(readline());\r\n \r\n for(let i=0;i {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n')\r\n split.forEach(e => {\r\n if (e.length == 1) e = Number(e)\r\n if (e.length > 1) e = e.split(' ').map(Number)\r\n state.data.push(e)\r\n })\r\n state.input_counter++\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst main = (args) => {\r\n let { data } = state\r\n const size = data.shift()\r\n data = data.slice(0, size)\r\n const target = data.reduce((a, e, i) => [...a, e[0]], [])\r\n const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))\r\n const results = sorted.map((e, i) => e.indexOf(target[i]))\r\n // console.log(results)\r\n results.forEach(e => commit(e + '\\r\\n'))\r\n return\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "const state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n')\r\n split.forEach(e => {\r\n if (e.length == 1) e = Number(e)\r\n if (e.length > 1) e = e.split(' ').map(Number)\r\n state.data.push(e)\r\n })\r\n state.input_counter++\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst main = (args) => {\r\n const { data } = state\r\n const size = data.shift()\r\n const target = data.reduce((a, e, i) => [...a, e[0]], [])\r\n const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))\r\n const results = sorted.map((e, i) => e.indexOf(target[i]))\r\n // console.log(results)\r\n results.slice(0, size).forEach(e => commit(e + '\\r\\n'))\r\n return\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "const state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n')\r\n split.forEach(e => {\r\n if (e.length == 1) e = Number(e)\r\n if (e.length > 1) e = e.split(' ').map(Number)\r\n state.data.push(e)\r\n })\r\n state.input_counter++\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst main = (args) => {\r\n const { data } = state\r\n data.shift()\r\n const target = data.reduce((a, e, i) => [...a, e[0]], [])\r\n const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))\r\n const results = sorted.map((e, i) => e.indexOf(target[i]))\r\n // console.log(results)\r\n results.forEach(e => commit(e + '\\r\\n'))\r\n return\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "const state = { data: [] };\r\nconst consume = (chunk) => {\r\n const chunk_string = chunk.toString()\r\n const split = chunk_string.split('\\r\\n')\r\n split.forEach(e => {\r\n if (e.length == 1) e = Number(e)\r\n if (e.length > 1) e = e.split(' ').map(Number)\r\n state.data.push(e)\r\n })\r\n state.input_counter++\r\n}\r\nconst commit = (answer) => process.stdout.write(answer);\r\nconst main = (args) => {\r\n const { data } = state\r\n data.shift()\r\n const target = data.reduce((a, e, i) => [...a, e[0]], [])\r\n const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))\r\n const results = sorted.map((e, i) => e.indexOf(target[i]))\r\n commit(results.join('\\r\\n'))\r\n};\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "var state = { data: [] };\r\nvar element, i, j = null;\r\nfunction consume(chunk) {\r\n try {\r\n var chunk_string = chunk.toString(\"utf-8\");\r\n var split = chunk_string.split('\\r\\n');\r\n for (i = 0; i < split.length; i++) {\r\n element = split[i];\r\n if (element.length == 1) {\r\n element = parseInt(element);\r\n }\r\n if (element.length > 1) {\r\n element = element.split(' ');\r\n for (j = 0; j < element.length; j++) {\r\n element[j] = parseInt(element[j]);\r\n }\r\n }\r\n state.data.push(element);\r\n }\r\n return;\r\n } catch (error) {\r\n process.stdout.write(error.message);\r\n }\r\n}\r\nfunction commit(answer) {\r\n try {\r\n process.stdout.write(answer);\r\n return;\r\n } catch (error) {\r\n process.stdout.write(error.message);\r\n }\r\n}\r\nfunction main() {\r\n try {\r\n\r\n var data = state.data;\r\n var target = [];\r\n var results = [];\r\n var sorted = [];\r\n // data.reduce((a, e, i) => [...a, e[0]], []);\r\n // sorted.map((e, i) => e.indexOf(target[i]));\r\n //data.map(e => e.sort((a, b) => b - a));\r\n // results.forEach(e => commit(e + '\\r\\n'));\r\n data.shift();\r\n for (i = 0; i < data.length; i++) {\r\n element = data[i];\r\n target.push(element[0]);\r\n }\r\n for (i = 0; i < data.length; i++) {\r\n element = data[i];\r\n sorted.push(element.sort((a, b) => b - a));\r\n }\r\n for (i = 0; i < sorted.length; i++) {\r\n element = sorted[i];\r\n results.push(element.indexOf(target[i]));\r\n }\r\n for (i = 0; i < results.length; i++) {\r\n const element = results[i];\r\n commit(element + '\\n');\r\n }\r\n return;\r\n } catch (error) {\r\n process.stdout.write(error.message);\r\n }\r\n}\r\nprocess.stdin\r\n .on(\"data\", consume)\r\n .on(\"end\", main);"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst read = () => new Promise(res => {\n rl.on('line', (line) => res(line));\n});\n\nasync function main()\n{\n const n = await read();\n for (let i = 0; i < n; i++) {\n const line = await read();\n const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));\n process.stdout.write(`${rest.filter(n => n > timur).length}`);\n }\n}\n\nmain();"}], "src_uid": "e829ca4438e9cb30ea1c66eea7d5f7a7"} {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n if (n === 1) {\n console.log(0)\n } else {\n if (n === 2) {\n console.log(m)\n } else {\n console.log(m * 2)\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() {\n //console.log(\"inputString\", inputString)\n \n //console.log(\"typeof inputString\", typeof inputString)\n const tests = inputString.slice(1).map(item => item.split(\" \").map(Number));\n \n //console.log(\"tests\", tests);\n \n let result = [];\n \n for (let i = 0; i < tests.length; i++) {\n //console.log(\"tests[i]\", tests[i]);\n const [n, m] = tests[i];\n \n if (n === 1) {\n result.push(0);\n } else if (n === 2) {\n result.push(m);\n } else {\n result.push(m * 2);\n }\n }\n \n result.forEach(item => console.log(item));\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \n\nlet main = () => {\n let t = parseInt(readline());\n while( t > 0 ){\n \tlet [n, m] = readline().split(\" \").map(Number);\n \tif( n === 1 )\n \t\tconsole.log(0);\n \telse if( n === 2 )\n \t\tconsole.log(m);\n \telse\n \t\tconsole.log(2*m);\n \tt = t-1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n/*****************************************************************/\nfunction main() {\n let t = readLine();\n t = parseInt(t);\n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let n = parseInt(line[0]);\n let m = parseInt(line[1]);\n if(n === 1) {\n console.log(\"0\");\n } else if (n === 2) {\n console.log(m);\n } else {\n console.log(2*m);\n }\n }\n}"}, {"source_code": "function solve(n,m) {\n if (n == 1) return 0;\n if (n == 2) return m;\n return 2*m;\n}\nvar tc = Number(readline())\nwhile (tc--) {\n var inputArr = readline().split(\" \").map(function(a) { return +a })\n var n = inputArr[0]\n var m = inputArr[1]\n print(solve(n,m))\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n //if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n /*} else {\n cases[cases.length - 1].arr = line;\n }*/\n\n const isProcessing = cases.length < problem.T;// || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, m] = data.s.split(' ').map(i => +i);\n let sum = (n == 1) ? 0 : m;\n\n if(n > 2) {\n sum = 2 * m;\n }\n \n return sum;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nrl.on('line', (line) => {\n const l = line.split(' ').map(v => +v);\n if (l.length > 1) {\n if (l[0] === 1) {\n process.stdout.write(`0\\n`);\n } else if (l[0] === 2) {\n process.stdout.write(`${l[1]}\\n`);\n } else if (l[0] > 2) {\n process.stdout.write(`${l[1] * 2}\\n`);\n }\n }\n});"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tif(N == 1){\n\t\t\toutput[i] = 0;\n\t\t\tcontinue;\n\t\t}\n\t\tvar M = one[1];\n\t\tif(N == 2){\n\t\t\toutput[i] = M;\n\t\t}else{\n\t\t\toutput[i] = M * 2;\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "// 5\n// 1 100\n// 2 2\n// 5 5\n// 2 1000000000\n// 1000000000 1000000000\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction writeLine(str) {\n process.stdout.write(`${str}\\n`);\n}\n\nfunction main() {\n let t = Number(readLine());\n while(t--) {\n const [n, m] = readLine().split(' ').map(num => Number(num));\n if (n == 1) {\n writeLine(0);\n } else if (n == 2) {\n writeLine(m);\n } else {\n writeLine(m*2);\n }\n }\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readline());\n const pairs = [];\n for (let i = 0; i < n; i++) {\n pairs.push(readline().split(' ').map(o => parseInt(o)));\n }\n\n pairs.forEach(([n, m]) => {\n if (n === 1) {\n console.log(0);\n } else if (n === 2) {\n console.log(m);\n } else {\n console.log(m * 2);\n }\n })\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, m] = d.split(\" \").map(Number);\n\n console.log(Math.min(2, n - 1) * m);\n\n // if (n === 1) {\n // console.log(0);\n // return;\n // }\n\n // if (n === 2) {\n // console.log(m);\n // return;\n // }\n\n // console.log(m * 2);\n c++;\n});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, m] = d.split(\" \").map(Number);\n\n if (n === 1) {\n console.log(0);\n return;\n }\n\n if (n === 2) {\n console.log(m);\n return;\n }\n\n console.log(m * 2);\n c++;\n});\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt(), M = nextInt();\n\n let result = 0;\n if (N>1) result = M;\n if (N>2) result = M*2;\n\n print(result);\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.split('\\n');\n let t = +inputs[0].trim();\n for (let index = 1; index <= t; index++) {\n const element = inputs[index].trim().split(' ');\n let n = +element[0];\n let sum = +element[1];\n if (n > 2) {\n console.log(2 * sum);\n }\n else {\n console.log((n - 1) * sum);\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n2\n3\n4\n5\n6\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r parseInt(x));\n if(arr[0]<=1)\n print(\"0\");\n else if(arr[0]===2)\n print(arr[1]);\n else\n print(2*arr[1]);\n\n}"}, {"source_code": "var testCaseCount = parseInt(readline());\n\nvar currentTestCase = 1;\n\nwhile(currentTestCase <= testCaseCount) {\n var input = readline().split(\" \");\n var n = parseInt(input[0]);\n var m = parseInt(input[1]);\n \n var result = findResult(n, m);\n \n print(result);\n \n currentTestCase += 1;\n}\n\nfunction findResult(n, m) {\n if (n < 2) {\n return 0;\n }\n \n if (n == 2) {\n return m;\n }\n \n return 2*m;\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n if (n == 2) print(m);\n else if (n == 1) print(0);\n else print(m * 2);\n}\n"}, {"source_code": "var testCases = readline();\nfor(var i =0; i< testCases; i++) {\n var line = readline().split(\" \");\n var arrayLength = line[0], arraySum = line[1];\n print( arrayLength >= 3? arraySum*2: (arrayLength == 1? 0 : arraySum));\n}\n"}, {"source_code": "var testCases = readline();\n\nfor(var i =0; i< testCases; i++) {\n var line = readline().split(\" \");\n var arrayLength = line[0], arraySum = line[1];\n if(arrayLength >= 3) {\n print(arraySum*2)\n } else {\n if(arrayLength == 1) {\n print(0);\n } \n else {\n print(arraySum);\n }\n }\n}\n"}, {"source_code": "for(var t=Number(readline());t;t--){\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n print((a[0]==1)?0:(a[0]==2)?a[1]:2*a[1]);\n}\n"}], "negative_code": [{"source_code": "function solve(n,m) {\n if (n <= 2) return m;\n return 2*m;\n}\nvar tc = Number(readline())\nwhile (tc--) {\n var inputArr = readline().split(\" \").map(function(a) { return +a })\n var n = inputArr[0]\n var m = inputArr[1]\n print(solve(n,m))\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() {\n console.log(\"inputString\", inputString)\n \n //console.log(\"typeof inputString\", typeof inputString)\n const tests = inputString.slice(1).map(item => item.split(\" \").map(Number));\n \n //console.log(\"tests\", tests);\n \n let result = [];\n \n for (let i = 0; i < tests.length; i++) {\n //console.log(\"tests[i]\", tests[i]);\n const [n, m] = tests[i];\n \n if (n === 1) {\n result.push(0);\n } else if (n === 2) {\n result.push(m);\n } else {\n result.push(m * 2);\n }\n }\n \n result.forEach(item => console.log(item));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", chunk => input_stdin += chunk.trim());\n\nprocess.stdin.on(\"end\", () => {\n input_stdin_array = input_stdin.trim().split(\"\\n\").map(str => str.trim());\n main()\n})\n\nreadLine = () => {\n return input_stdin_array[input_currentline++];\n}\n\nmain = () => {\n let t = parseInt(readLine());\n while( t-- ){\n \tlet [n, m] = readLine().split(\" \").map(x => parseInt(x));\n \tif( n === 1 )\n \t\tconsole.log(0);\n \telse if( n === 2 )\n \t\tconsole.log(m);\n \telse\n \t\tconsole.log(2*m);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", chunk => input_stdin += chunk.trim());\n\nprocess.stdin.on(\"end\", () => {\n input_stdin_array = input_stdin.trim().split(\"\\n\").map(str => str.trim());\n main()\n})\n\nreadLine = () => {\n return input_stdin_array[input_currentline++];\n}\n\nmain = () => {\n let t = parseInt(readLine());\n while( t > 0 ){\n \tlet [n, m] = readLine().split(\" \").map(Number);\n \tif( n === 1 )\n \t\tconsole.log(0);\n \telse if( n === 2 )\n \t\tconsole.log(m);\n \telse\n \t\tconsole.log(2*m);\n \tt = t-1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", chunk => input_stdin += chunk.trim());\n\nprocess.stdin.on(\"end\", () => {\n input_stdin_array = input_stdin.trim().split(\"\\n\").map(str => str.trim());\n main()\n})\n\nreadLine = () => {\n return input_stdin_array[input_currentline++];\n}\n\nmain = () => {\n let t = parseInt(readLine());\n while( t > 0 ){\n \tlet [n, m] = readLine().split(\" \").map(x => parseInt(x));\n \tif( n === 1 )\n \t\tconsole.log(0);\n \telse if( n === 2 )\n \t\tconsole.log(m);\n \telse\n \t\tconsole.log(2*m);\n \tt = t-1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", chunk => input_stdin += chunk.trim());\n\nprocess.stdin.on(\"end\", () => {\n input_stdin_array = input_stdin.trim().split(\"\\n\").map(str => str.trim());\n main()\n})\n\nreadLine = () => {\n return input_stdin_array[input_currentline++].trim();\n}\n\nmain = () => {\n let t = parseInt(readLine());\n while( t > 0 ){\n \tlet [n, m] = readLine().split(\" \").map(x => parseInt(x));\n \tif( n === 1 )\n \t\tconsole.log(0);\n \telse if( n === 2 )\n \t\tconsole.log(m);\n \telse\n \t\tconsole.log(2*m);\n \tt = t-1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n/*****************************************************************/\nfunction main() {\n let t = readLine();\n t = parseInt(t);\n console.log(\"mai yahan aaya\")\n while(t--) {\n let line = readLine();\n line = line.split(\" \");\n let n = parseInt(line[0]);\n let m = parseInt(line[1]);\n if(n === 1) {\n console.log(\"0\");\n } else if (n === 2) {\n console.log(m);\n } else {\n console.log(2*m);\n }\n }\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n //if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n /*} else {\n cases[cases.length - 1].arr = line;\n }*/\n\n const isProcessing = cases.length < problem.T;// || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, m] = data.s.split(' ').map(i => +i);\n let sum = (n == 1) ? 0 : m;\n\n if(m == n && n > 2) {\n sum = 2 * m;\n }\n \n return sum;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nrl.on('line', (line) => {\n const l = line.split(' ').map(v => +v);\n if (l.length > 1) {\n if (l[0] === 1) {\n process.stdout.write(`0\\n`);\n } else if (l[0] === 2) {\n process.stdout.write(`${l[1]}\\n`);\n } else if (l[0] > 2) {\n process.stdout.write(`${l[1] + l[0]}\\n`);\n }\n }\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n1 100\n2 2\n5 5\n2 1000000000\n1000000000 1000000000\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n1 100\n2 2\n5 5\n2 1000000000\n1000000000 1000000000\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n2\n3\n4\n5\n6\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r { return BN(s); });\n \n var a = [];\n a[0] = 0;\n a[n-1] = b[0];\n\n for(var i=1 ; io[s]^n?1:-1;return u==l?0:l(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else rd?e.c=e.e=null:e.c=n=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5d?e.c=e.e=null:e.e>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw O=!1,Error(U+\"crypto unavailable\");for(r=crypto.randomBytes(i*=7);sn-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,p=e.indexOf(\".\"),g=y,w=N;for(0<=p&&(u=b,b=0,e=e.replace(\".\",\"\"),c=(h=new _(r)).pow(e.length-p),b=u,h.c=d(X($(c.c),c.e,\"0\"),10,n,m),h.e=h.c.length),f=u=(a=d(e,r,n,i?(o=A,m):(o=m,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(p<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,g,w,n)).c,l=c.r,f=c.e),p=a[s=f+g+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=p||l)&&(0==w||w==(c.s<0?3:2)):un;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(p=0,e=\"\";p<=u;e+=o.charAt(a[p++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%k,c=r/k|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%k)+(t=c*o+(s=e[u]/k|0)*l)%k*k+f)/n|0)+(t/k|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=tr[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n](E[f]||0)&&s--,b<0)p.push(1),u=!0;else{for(v=E.length,N=A.length,b+=2,1<(l=T(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),N=A.length,v=E.length),d=N,w=(g=E.slice(0,N)).length;w=i/2&&y++;do{if(l=0,(o=R(A,g,N,w))<0){if(m=g[0],N!=w&&(m=m*i+(g[1]||0)),1<(l=T(m/y)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=g.length;1==R(c,g,a,w);)l--,P(c,No&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=T(i/2)))break;u=i%2}else if(x(e=e.times(n),e.e+1,1),14o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?x(l,b,N,void 0):l)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:H(e,0,8),x(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times(\"1e\"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=y+4,c=new _(\"0.5\");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+D(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+=\"0\"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new _(r=f==1/0?\"1e\"+u:(r=f.toExponential()).slice(0,r.indexOf(\"e\")+1)+u)):new _(f+\"\")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.eo[s]^n?1:-1;return u==l?0:l(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else rd?e.c=e.e=null:e.c=n=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5d?e.c=e.e=null:e.e>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw O=!1,Error(U+\"crypto unavailable\");for(r=crypto.randomBytes(i*=7);sn-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,p=e.indexOf(\".\"),g=y,w=N;for(0<=p&&(u=b,b=0,e=e.replace(\".\",\"\"),c=(h=new _(r)).pow(e.length-p),b=u,h.c=d(X($(c.c),c.e,\"0\"),10,n,m),h.e=h.c.length),f=u=(a=d(e,r,n,i?(o=A,m):(o=m,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(p<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,g,w,n)).c,l=c.r,f=c.e),p=a[s=f+g+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=p||l)&&(0==w||w==(c.s<0?3:2)):un;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(p=0,e=\"\";p<=u;e+=o.charAt(a[p++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%k,c=r/k|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%k)+(t=c*o+(s=e[u]/k|0)*l)%k*k+f)/n|0)+(t/k|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=tr[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n](E[f]||0)&&s--,b<0)p.push(1),u=!0;else{for(v=E.length,N=A.length,b+=2,1<(l=T(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),N=A.length,v=E.length),d=N,w=(g=E.slice(0,N)).length;w=i/2&&y++;do{if(l=0,(o=R(A,g,N,w))<0){if(m=g[0],N!=w&&(m=m*i+(g[1]||0)),1<(l=T(m/y)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=g.length;1==R(c,g,a,w);)l--,P(c,No&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=T(i/2)))break;u=i%2}else if(x(e=e.times(n),e.e+1,1),14o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?x(l,b,N,void 0):l)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:H(e,0,8),x(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times(\"1e\"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=y+4,c=new _(\"0.5\");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+D(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+=\"0\"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new _(r=f==1/0?\"1e\"+u:(r=f.toExponential()).slice(0,r.indexOf(\"e\")+1)+u)):new _(f+\"\")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.e {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return BN(item);\n });\n let res = []\n let n = s.length * 2\n res[0] = BN(0)\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i].minus(res[i - 1]).gt(res[n - (i - 1) - 1])) {\n\n res[i] = s[i].minus(res[n - (i - 1) - 1])\n if (res[i - 1].gt(res[i])) {\n res[i] = res[i].minus(res[i - 1])\n }\n res[n - i - 1] = s[i].minus(res[i])\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i].minus(res[i - 1])\n }\n }\n console.log(res.join(\" \"))\n return 0;\n }\n});"}, {"source_code": "\nfunction main() {\n\n const BN = module.exports.BigNumber;\n\n var n = stdin[0];\n n = parseInt(n);\n\n var b = stdin[1].split(' ').map( (s) => { return BN(s); });\n \n var a = [];\n a[0] = 0;\n a[n-1] = b[0];\n\n for(var i=1 ; io[s]^n?1:-1;return u==l?0:l(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else rd?e.c=e.e=null:e.c=n=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5d?e.c=e.e=null:e.e>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw O=!1,Error(U+\"crypto unavailable\");for(r=crypto.randomBytes(i*=7);sn-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,p=e.indexOf(\".\"),g=y,w=N;for(0<=p&&(u=b,b=0,e=e.replace(\".\",\"\"),c=(h=new _(r)).pow(e.length-p),b=u,h.c=d(X($(c.c),c.e,\"0\"),10,n,m),h.e=h.c.length),f=u=(a=d(e,r,n,i?(o=A,m):(o=m,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(p<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,g,w,n)).c,l=c.r,f=c.e),p=a[s=f+g+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=p||l)&&(0==w||w==(c.s<0?3:2)):un;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(p=0,e=\"\";p<=u;e+=o.charAt(a[p++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%k,c=r/k|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%k)+(t=c*o+(s=e[u]/k|0)*l)%k*k+f)/n|0)+(t/k|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=tr[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n](E[f]||0)&&s--,b<0)p.push(1),u=!0;else{for(v=E.length,N=A.length,b+=2,1<(l=T(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),N=A.length,v=E.length),d=N,w=(g=E.slice(0,N)).length;w=i/2&&y++;do{if(l=0,(o=R(A,g,N,w))<0){if(m=g[0],N!=w&&(m=m*i+(g[1]||0)),1<(l=T(m/y)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=g.length;1==R(c,g,a,w);)l--,P(c,No&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=T(i/2)))break;u=i%2}else if(x(e=e.times(n),e.e+1,1),14o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?x(l,b,N,void 0):l)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:H(e,0,8),x(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times(\"1e\"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=y+4,c=new _(\"0.5\");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+D(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+=\"0\"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new _(r=f==1/0?\"1e\"+u:(r=f.toExponential()).slice(0,r.indexOf(\"e\")+1)+u)):new _(f+\"\")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.eo[s]^n?1:-1;return u==l?0:l(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else rd?e.c=e.e=null:e.c=n=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5d?e.c=e.e=null:e.e>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw O=!1,Error(U+\"crypto unavailable\");for(r=crypto.randomBytes(i*=7);sn-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,p=e.indexOf(\".\"),g=y,w=N;for(0<=p&&(u=b,b=0,e=e.replace(\".\",\"\"),c=(h=new _(r)).pow(e.length-p),b=u,h.c=d(X($(c.c),c.e,\"0\"),10,n,m),h.e=h.c.length),f=u=(a=d(e,r,n,i?(o=A,m):(o=m,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(p<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,g,w,n)).c,l=c.r,f=c.e),p=a[s=f+g+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=p||l)&&(0==w||w==(c.s<0?3:2)):un;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(p=0,e=\"\";p<=u;e+=o.charAt(a[p++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%k,c=r/k|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%k)+(t=c*o+(s=e[u]/k|0)*l)%k*k+f)/n|0)+(t/k|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=tr[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n](E[f]||0)&&s--,b<0)p.push(1),u=!0;else{for(v=E.length,N=A.length,b+=2,1<(l=T(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),N=A.length,v=E.length),d=N,w=(g=E.slice(0,N)).length;w=i/2&&y++;do{if(l=0,(o=R(A,g,N,w))<0){if(m=g[0],N!=w&&(m=m*i+(g[1]||0)),1<(l=T(m/y)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=g.length;1==R(c,g,a,w);)l--,P(c,No&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=T(i/2)))break;u=i%2}else if(x(e=e.times(n),e.e+1,1),14o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?x(l,b,N,void 0):l)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:H(e,0,8),x(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times(\"1e\"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=y+4,c=new _(\"0.5\");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+D(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+=\"0\"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new _(r=f==1/0?\"1e\"+u:(r=f.toExponential()).slice(0,r.indexOf(\"e\")+1)+u)):new _(f+\"\")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.e {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return BN(item);\n });\n let res = []\n let n = s.length * 2\n res[0] = BN(0)\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i] - res[i - 1] > res[n - (i - 1) - 1]) {\n\n res[i] = s[i] - (res[n - (i - 1) - 1])\n if (res[i - 1] > res[i]) {\n res[i] -= res[i - 1]\n }\n res[n - i - 1] = s[i] - res[i]\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i] - res[i - 1]\n }\n }\n console.log(res.join(\" \"))\n return 0;\n }\n});\n\n//4 5 4 4 3 4\n//0 1 1 1 1 2 2 2 3 3 4 4\n//0 1 1 1 1 2 3 3 4 4\n//0 1 1 1 1 1 3 2 3 3 4 4"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return parseInt(item, 10);\n });\n let res = []\n let n = s.length * 2\n res[0] = 0\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i] - res[i - 1] > res[n - (i - 1)-1]) {\n res[i] = s[i] - res[i - 1] - res[n - (i - 1)-1]\n res[n-i - 1] = s[i] - res[i]\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i]-res[i-1]\n }\n }\n console.log(res)\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return parseInt(item, 10);\n });\n let res = []\n let n = s.length * 2\n res[0] = 0\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i] - res[i - 1] > res[n - (i - 1) - 1]) {\n\n res[i] = s[i] - (res[n - (i - 1) - 1])\n if (res[i - 1] > res[i]) {\n res[i] -= res[i - 1]\n }\n res[n - i - 1] = s[i] - res[i]\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i] - res[i - 1]\n }\n }\n console.log(res.join(\" \"))\n return 0;\n }\n});\n\n//4 5 4 4 3 4\n//0 1 1 1 1 2 2 2 3 3 4 4\n//0 1 1 1 1 2 3 3 4 4\n//0 1 1 1 1 1 3 2 3 3 4 4\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n!function(e){\"use strict\";var r,L=/^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/i,B=Math.ceil,T=Math.floor,U=\"[BigNumber Error] \",I=U+\"Number primitive has more than 15 significant digits: \",C=1e14,M=14,G=9007199254740991,F=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],k=1e7,q=1e9;function j(e){var r=0|e;return 0o[s]^n?1:-1;return u==l?0:l(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else rd?e.c=e.e=null:e.c=n=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5d?e.c=e.e=null:e.e>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw O=!1,Error(U+\"crypto unavailable\");for(r=crypto.randomBytes(i*=7);sn-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,p=e.indexOf(\".\"),g=y,w=N;for(0<=p&&(u=b,b=0,e=e.replace(\".\",\"\"),c=(h=new _(r)).pow(e.length-p),b=u,h.c=d(X($(c.c),c.e,\"0\"),10,n,m),h.e=h.c.length),f=u=(a=d(e,r,n,i?(o=A,m):(o=m,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(p<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,g,w,n)).c,l=c.r,f=c.e),p=a[s=f+g+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=p||l)&&(0==w||w==(c.s<0?3:2)):un;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(p=0,e=\"\";p<=u;e+=o.charAt(a[p++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%k,c=r/k|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%k)+(t=c*o+(s=e[u]/k|0)*l)%k*k+f)/n|0)+(t/k|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=tr[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n](E[f]||0)&&s--,b<0)p.push(1),u=!0;else{for(v=E.length,N=A.length,b+=2,1<(l=T(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),N=A.length,v=E.length),d=N,w=(g=E.slice(0,N)).length;w=i/2&&y++;do{if(l=0,(o=R(A,g,N,w))<0){if(m=g[0],N!=w&&(m=m*i+(g[1]||0)),1<(l=T(m/y)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=g.length;1==R(c,g,a,w);)l--,P(c,No&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=T(i/2)))break;u=i%2}else if(x(e=e.times(n),e.e+1,1),14o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?x(l,b,N,void 0):l)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:H(e,0,8),x(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times(\"1e\"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=y+4,c=new _(\"0.5\");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+D(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+=\"0\"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new _(r=f==1/0?\"1e\"+u:(r=f.toExponential()).slice(0,r.indexOf(\"e\")+1)+u)):new _(f+\"\")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.e {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return BN(item);\n });\n let res = []\n let n = s.length * 2\n res[0] = BN(0)\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i].minus(res[i - 1]) > res[n - (i - 1) - 1]) {\n\n res[i] = s[i].minus(res[n - (i - 1) - 1])\n if (res[i - 1] > res[i]) {\n res[i] =res[i].minus(res[i - 1])\n }\n res[n - i - 1] = s[i].minus(res[i])\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i].minus(res[i - 1])\n }\n }\n console.log(res.join(\" \"))\n return 0;\n }\n});\n\n//4 5 4 4 3 4\n//0 1 1 1 1 2 2 2 3 3 4 4\n//0 1 1 1 1 2 3 3 4 4\n//0 1 1 1 1 1 3 2 3 3 4 4"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l == 0) { l++ }\n else {\n rl.close();\n let strArray = input.split(\" \")\n let s = strArray.map(function (item) {\n return parseInt(item, 10);\n });\n let res = []\n let n = s.length * 2\n res[0] = 0\n res[n - 1] = s[0]\n for (let i = 1; i < s.length; i++) {\n if (s[i] - res[i - 1] > res[n - (i - 1)-1]) {\n res[i] = s[i] - res[i - 1] - res[n - (i - 1)-1]\n res[n-i - 1] = s[i] - res[i]\n\n } else {\n res[i] = res[i - 1]\n res[n - i - 1] = s[i]-res[i-1]\n }\n }\n console.log(res.join(\" \"))\n return 0;\n }\n});\n"}, {"source_code": "function main() {\n\n var n = stdin[0];\n n = parseInt(n);\n\n var b = stdin[1].split(' ').map( (s) => { return new Int64(s); });\n var a = [];\n a[0] = 0;\n a[n-1] = b[0];\n\n for(var i=1 ; i 0xF ? '' : '0') + i.toString(16);\n}\n\n//\n// Int64\n//\n\n/**\n * Constructor accepts any of the following argument types:\n *\n * new Int64(buffer[, offset=0]) - Existing Buffer with byte offset\n * new Int64(Uint8Array[, offset=0]) - Existing Uint8Array with a byte offset\n * new Int64(string) - Hex string (throws if n is outside int64 range)\n * new Int64(number) - Number (throws if n is outside int64 range)\n * new Int64(hi, lo) - Raw bits as two 32-bit values\n */\nvar Int64 = module.exports = function(a1, a2) {\n if (a1 instanceof Buffer) {\n this.buffer = a1;\n this.offset = a2 || 0;\n } else if (Object.prototype.toString.call(a1) == '[object Uint8Array]') {\n // Under Browserify, Buffers can extend Uint8Arrays rather than an\n // instance of Buffer. We could assume the passed in Uint8Array is actually\n // a buffer but that won't handle the case where a raw Uint8Array is passed\n // in. We construct a new Buffer just in case.\n this.buffer = new Buffer(a1);\n this.offset = a2 || 0;\n } else {\n this.buffer = this.buffer || new Buffer(8);\n this.offset = 0;\n this.setValue.apply(this, arguments);\n }\n};\n\n\n// Max integer value that JS can accurately represent\nInt64.MAX_INT = Math.pow(2, 53);\n\n// Min integer value that JS can accurately represent\nInt64.MIN_INT = -Math.pow(2, 53);\n\nInt64.prototype = {\n\n constructor: Int64,\n\n /**\n * Do in-place 2's compliment. See\n * http://en.wikipedia.org/wiki/Two's_complement\n */\n _2scomp: function() {\n var b = this.buffer, o = this.offset, carry = 1;\n for (var i = o + 7; i >= o; i--) {\n var v = (b[i] ^ 0xff) + carry;\n b[i] = v & 0xff;\n carry = v >> 8;\n }\n },\n\n /**\n * Set the value. Takes any of the following arguments:\n *\n * setValue(string) - A hexidecimal string\n * setValue(number) - Number (throws if n is outside int64 range)\n * setValue(hi, lo) - Raw bits as two 32-bit values\n */\n setValue: function(hi, lo) {\n var negate = false;\n if (arguments.length == 1) {\n if (typeof(hi) == 'number') {\n // Simplify bitfield retrieval by using abs() value. We restore sign\n // later\n negate = hi < 0;\n hi = Math.abs(hi);\n lo = hi % VAL32;\n hi = hi / VAL32;\n if (hi > VAL32) throw new RangeError(hi + ' is outside Int64 range');\n hi = hi | 0;\n } else if (typeof(hi) == 'string') {\n if( hi.length>=2 && hi[0]=='0' && hi[1]=='x' ) {\n hi = (hi + '').replace(/^0x/, '');\n lo = hi.substr(-8);\n hi = hi.length > 8 ? hi.substr(0, hi.length - 8) : '';\n hi = parseInt(hi, 16);\n lo = parseInt(lo, 16);\n } else {\n lo = hi.substr(-10);\n hi = hi.length > 10 ? hi.substr(0, hi.length - 10) : '';\n hi = parseInt(hi);\n lo = parseInt(lo);\n }\n } else {\n throw new Error(hi + ' must be a Number or String');\n }\n }\n\n // Technically we should throw if hi or lo is outside int32 range here, but\n // it's not worth the effort. Anything past the 32'nd bit is ignored.\n\n // Copy bytes to buffer\n var b = this.buffer, o = this.offset;\n for (var i = 7; i >= 0; i--) {\n b[o+i] = lo & 0xff;\n lo = i == 4 ? hi : lo >>> 8;\n }\n\n // Restore sign of passed argument\n if (negate) this._2scomp();\n },\n\n /**\n * Convert to a native JS number.\n *\n * WARNING: Do not expect this value to be accurate to integer precision for\n * large (positive or negative) numbers!\n *\n * @param allowImprecise If true, no check is performed to verify the\n * returned value is accurate to integer precision. If false, imprecise\n * numbers (very large positive or negative numbers) will be forced to +/-\n * Infinity.\n */\n toNumber: function(allowImprecise) {\n var b = this.buffer, o = this.offset;\n\n // Running sum of octets, doing a 2's complement\n var negate = b[o] & 0x80, x = 0, carry = 1;\n for (var i = 7, m = 1; i >= 0; i--, m *= 256) {\n var v = b[o+i];\n\n // 2's complement for negative numbers\n if (negate) {\n v = (v ^ 0xff) + carry;\n carry = v >> 8;\n v = v & 0xff;\n }\n\n x += v * m;\n }\n\n // Return Infinity if we've lost integer precision\n if (!allowImprecise && x >= Int64.MAX_INT) {\n return negate ? -Infinity : Infinity;\n }\n\n return negate ? -x : x;\n },\n\n /**\n * Convert to a JS Number. Returns +/-Infinity for values that can't be\n * represented to integer precision.\n */\n valueOf: function() {\n return this.toNumber(false);\n },\n\n /**\n * Return string value\n *\n * @param radix Just like Number#toString()'s radix\n */\n toString: function(radix) {\n return this.valueOf().toString(radix || 10);\n },\n\n /**\n * Return a string showing the buffer octets, with MSB on the left.\n *\n * @param sep separator string. default is '' (empty string)\n */\n toOctetString: function(sep) {\n var out = new Array(8);\n var b = this.buffer, o = this.offset;\n for (var i = 0; i < 8; i++) {\n out[i] = _HEX[b[o+i]];\n }\n return out.join(sep || '');\n },\n\n /**\n * Returns the int64's 8 bytes in a buffer.\n *\n * @param {bool} [rawBuffer=false] If no offset and this is true, return the internal buffer. Should only be used if\n * you're discarding the Int64 afterwards, as it breaks encapsulation.\n */\n toBuffer: function(rawBuffer) {\n if (rawBuffer && this.offset === 0) return this.buffer;\n\n var out = new Buffer(8);\n this.buffer.copy(out, 0, this.offset, this.offset + 8);\n return out;\n },\n\n /**\n * Copy 8 bytes of int64 into target buffer at target offset.\n *\n * @param {Buffer} targetBuffer Buffer to copy into.\n * @param {number} [targetOffset=0] Offset into target buffer.\n */\n copy: function(targetBuffer, targetOffset) {\n this.buffer.copy(targetBuffer, targetOffset || 0, this.offset, this.offset + 8);\n },\n\n /**\n * Returns a number indicating whether this comes before or after or is the\n * same as the other in sort order.\n *\n * @param {Int64} other Other Int64 to compare.\n */\n compare: function(other) {\n\n // If sign bits differ ...\n if ((this.buffer[this.offset] & 0x80) != (other.buffer[other.offset] & 0x80)) {\n return other.buffer[other.offset] - this.buffer[this.offset];\n }\n\n // otherwise, compare bytes lexicographically\n for (var i = 0; i < 8; i++) {\n if (this.buffer[this.offset+i] !== other.buffer[other.offset+i]) {\n return this.buffer[this.offset+i] - other.buffer[other.offset+i];\n }\n }\n return 0;\n },\n\n /**\n * Returns a boolean indicating if this integer is equal to other.\n *\n * @param {Int64} other Other Int64 to compare.\n */\n equals: function(other) {\n return this.compare(other) === 0;\n },\n\n /**\n * Pretty output in console.log\n */\n inspect: function() {\n return '[Int64 value:' + this + ' octets:' + this.toOctetString(' ') + ']';\n }\n};\n"}, {"source_code": "function main() {\n\n var n = stdin[0];\n n = parseInt(n);\n\n var b = stdin[1].split(' ').map( (s) => { return parseInt(s); });\n var a = [];\n a[0] = 0;\n a[n-1] = b[0];\n\n for(var i=1 ; i 0 ) {\n \t\t\tthis.arr[ ( this.s.charCodeAt( i ) - 'A'.charCodeAt( 0 ) ) ]-- ;\n \t\t}\n \t\telse {\n \t\t\tres++ ;\n \t\t}\n \t}\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 30;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.s = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n", "positive_code": [{"source_code": "var cnt = new Array(26);\nfor(var i=0;i<26;i++) \n cnt[i] = 0;\nvar n = parseInt(readline());\nvar s = readline();\nvar ans = 0;\nfor(var i=0;i<2*n-2;i+=2) {\n var c = s[i].charCodeAt() - 97;\n cnt[c] ++;\n var c = s[i+1].charCodeAt() - 65;\n if(cnt[c] > 0) cnt[c] --;\n else ans ++; \n}\nprint(ans);"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", _ => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n// main();\n\n////////////////////////////////////////////////////////////////////////\n\nfunction main() {\n var a = readline();\n var b = readline().toLocaleLowerCase();\n let counter = 0; //bought keys\n let keys = {}; //key status\n for (let i = 0; i < b.length; i += 2) {\n //first step\n if (keys[b[i]] === undefined) {\n keys[b[i]] = 1;\n } else {\n keys[b[i]]++;\n }\n //second step\n if (keys[b[i + 1]]) {\n keys[b[i + 1]]--;\n } else {\n counter++;\n }\n }\n console.log(counter);\n}\n"}, {"source_code": "var n = +readline(), s = readline().split(\"\");\nvar keys = {}, cnt = 0;\n\nfor(i = 0; i < s.length; i += 2){\n\tif(keys[s[i]] == undefined){\n\t\tkeys[s[i]] = 1;\n\t}\n\telse{\n\t\tkeys[s[i]]++;\n\t}\n\n\tif(keys[s[i+1].toLowerCase()] != undefined && keys[s[i+1].toLowerCase()] > 0){\n\t\tkeys[s[i+1].toLowerCase()]--;\n\t}\n\telse{\n\t\tcnt++;\n\t}\n}\n\nwrite(cnt);"}], "negative_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\t\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , len2 ;\n len = this.s.length ;\n res = \"\" ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.arr[ i ] = this.arr[ i ] - 1 ;\n }\n this.arr.sort() ;\n for( i = 0 ; i < len ; i++ ) {\n \tthis.brr[ i ] = this.s.charCodeAt( i ) ;\n }\n j = 0 ;\n cn = 0 ;\n len2 = Math.floor( len / 2 ) ;\n for( i = 0 ; i < len2 ; i++ ) {\n \twhile( j < this.n && this.arr[ j ] == i ) {\n \t\tcn++ ;\n \t\tj++ ;\n \t}\n \tif( cn % 2 == 0 ) {\n \t}\n \telse {\n \t\ttemp = this.brr[ i ] ;\n \t\tthis.brr[ i ] = this.brr[ len - i - 1 ] ;\n \t\tthis.brr[ len - i - 1 ] = temp ;\n \t}\n }\n for( i = 0 ; i < len ; i++ ) {\n \tres += String.fromCharCode( this.brr[ i ] ) ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.n = irObj.nextInt();\n this.arr = new Array() ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var cnt = new Array(26);\nfor(var i=0;i<26;i++) \n cnt[i] = 0;\nvar n = parseInt(readline());\nvar s = readline();\nvar ans = 0;\nfor(var i=0;i<2*n-2;i+=2) {\n var c = parseInt(s[i]) - parseInt('a');\n cnt[c] ++;\n var c = parseInt(s[i+1]) - parseInt('A');\n if(cnt[c] > 0) cnt[c] --;\n else ans ++; \n}\nprint(ans);"}], "src_uid": "80fdb95372c1e8d558b8c8f31c9d0479"} {"source_code": "var n = +readline();\nvar ans, i = 1, j = Math.pow(n,2);\n\nfor(k = 0; k < n; k++){\n\tfor(ans = []; ; i++, j--){\n\t\tans.push(i,j);\n\t\tif(ans.length == n){\n\t\t\tprint(ans.join(\" \"));\n\t\t\ti++, j--;\n\t\t\tbreak;\n\t\t}\n\t}\n}", "positive_code": [{"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar f1 = n*n;\n\tvar f2 = 1;\n\n\tvar t;\n\tfor (var i = 0; i < n; i++) {\n\t\tt = [];\n\n\t\twhile (t.length < n) {\n\t\t\tt.push(f1--);\n\t\t\tt.push(f2++);\n\t\t}\n\n\t\tprint(t.join(' '));\n\t}\n\n}).call(this);"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar o = {\n\t\t_min: 1,\n\t\t_max: n*n,\n\t\tmax: function () { return this._max--; },\n\t\tmin: function () { return this._min++; }\n\t}\n\n\tvar t;\n\tfor (var i = 0; i < n; i++) {\n\t\tt = [];\n\n\t\twhile (t.length < n) {\n\t\t\tt.push(o.min());\n\t\t\tt.push(o.max());\n\t\t}\n\n\t\tprint(t.join(' '));\n\t}\n\n}).call(this);"}, {"source_code": "\n// 334A \u041f\u0430\u043a\u0435\u0442\u0438\u043a\u0438 \u0441 \u043a\u043e\u043d\u0444\u0435\u0442\u0430\u043c\u0438 \n\n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar out = '';\nvar n2 = n * n;\nvar n2_2 = n2 / 2;\n\nfor (var i = 1; i <= n; i++) {\n for (var j = i; j <= n2_2; j+=n) {\n out += j.toString() + ' ' + (n2-j+1).toString() + ' ';\n };\n out += '\\n';\n};\n\nprint(out);\n "}, {"source_code": "var n=+readline();\nvar ans=[];\nfor(var i=0;i 0; i--)\n\t\t\t\tif (!(this[i])) {\n\t\t\t\t\tthis[i] = true;\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t}\n\t}\n\n\tvar t, sum;\n\tfor (var i = 0; i < n; i++) {\n\t\tsum = o.max();\n\t\tt = [sum];\n\t\td = sum;\n\n\t\twhile (sum != s) {\n\t\t\t--d;\n\t\t\tif (!o[d] && (sum + d) <= s) {\n\t\t\t\to[d] = true;\n\t\t\t\tsum += d;\n\t\t\t\tt.push(d);\n\t\t\t}\n\t\t}\n\n\t\tprint(t.join(' '));\n\t}\n\n}).call(this);"}, {"source_code": "\n// 334A \u041f\u0430\u043a\u0435\u0442\u0438\u043a\u0438 \u0441 \u043a\u043e\u043d\u0444\u0435\u0442\u0430\u043c\u0438 \n\n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar out = '';\nvar n2 = n * n;\nvar n2_2 = n2 / 2;\n\nfor (var i = 1; i <= n; i++) {\n for (var j = i; j <= n2_2; j+=n) {\n out += j.toString() + ' ' + (n-j+1).toString() + ' ';\n };\n out += '\\n';\n};\n\nprint(out);\n "}], "src_uid": "0ac2a0954fe43d66eac32072c8ea5070"} {"source_code": "function getBeforeStep (i, k) {\n return i < k ? i : k;\n}\n\nfunction getAfterStep (i, k, n) {\n return i + k >= n ? (n - i) - 1 : k;\n}\n\nfunction getStep (i, k, n) {\n return getBeforeStep(i, k) + getAfterStep(i, k, n) + 1;\n}\n\nvar input = readline();\nvar messages = readline().split(' ');\n\ninput = input.split(' ');\nvar n = parseInt(input[0]);\nvar k = parseInt(input[1]);\n\nvar i, value, lastValue, start, end, prevEnd, step;\n\nfor (i = 0; i < n; i++) {\n value = parseInt(messages[i]) - 1;\n lastValue = messages[value] || 0;\n\n start = Math.max(i - k, 0);\n end = i + getAfterStep(i, k, n);\n prevEnd = value + getAfterStep(value, k, n);\n\n step = i != 0 && value >= 0 && start <= prevEnd ? end - prevEnd : getStep(i, k, n);\n\n messages[i] = lastValue + step\n}\n\nprint(messages.join(' '))\n", "positive_code": [{"source_code": "var input = readline().split(' ');\nvar n = +input[0];\nvar k = +input[1];\nvar refs = readline().split(' ').map(function (msg) {\n return +msg;\n});\n// const n = 20;\n// const k = 1;\n// const refs = [0, 1, 0, 3, 4, 5, 2, 3, 7, 0, 0, 7, 0, 3, 4, 12, 2, 3, 7, 0];\n\n// Solution\nfunction isRange(arr) {\n return Array.isArray(arr) && typeof arr[0] === 'number';\n}\n\nfunction checkCrossing(arr1, arr2) {\n if (arr1[1] >= arr2[0] && arr1[1] <= arr2[1]) {\n return 'left';\n }\n if (arr1[0] >= arr2[0] && arr1[0] <= arr2[1]) {\n return 'right'\n }\n return 'no';\n}\n\nfunction concatRanges(arr1, arr2) {\n return [\n arr1[0],\n arr2[1]\n ];\n}\n\nfunction getMessages(i) {\n if (refs[i] === 0) {\n return cache[i]; // Get numbers from cache\n }\n var refRange = getMessages(refs[i] - 1);\n\n // If refRange is like [2, 15]\n if (isRange(refRange)) {\n switch (checkCrossing(refRange, cache[i])) {\n case 'left':\n return concatRanges(refRange, cache[i]);\n case 'right':\n return concatRanges(cache[i], refRange);\n case 'no':\n if (cache[i][0] < refRange[0]) {\n return [cache[i], refRange];\n }\n return [refRange, cache[i]];\n }\n }\n\n // If refRange kinda [[1, 15], [18, 25]]\n var hasCrossing = false;\n var stopCheck = false;\n\n for (var k = 0, l = refRange.length; k < l; k++) {\n switch (checkCrossing(refRange[k], cache[i])) {\n case 'left':\n hasCrossing = true;\n refRange[k] = concatRanges(refRange[k], cache[i]);\n break;\n case 'right':\n hasCrossing = true;\n refRange[k] = concatRanges(cache[i], refRange[k]);\n break;\n case 'no':\n // To prevent excess entries\n if (cache[i][1] < refRange[k][0]) {\n stopCheck = true;\n }\n break;\n }\n if (hasCrossing || stopCheck) {\n break;\n }\n }\n\n if (!hasCrossing) {\n refRange.push(cache[i]);\n }\n return refRange;\n}\n\nvar res = [];\nvar cache = [];\n\nfor (var ref = 0; ref < n; ref++) {\n cache[ref] = [\n ref - k < 0 ? 0 : ref - k, // Left border\n ref + k >= n ? n - 1 : ref + k // Right border\n ];\n}\n\nrefs.forEach(function (ref, i) {\n var borders = getMessages(i);\n\n if (isRange(borders)) {\n res.push(borders[1] - borders[0] + 1);\n } else {\n var sum = 0;\n\n borders.forEach(function (border) {\n sum += border[1] - border[0] + 1;\n });\n res.push(sum);\n }\n});\n\nprint(res.join(' '));"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar messageHistory = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar visibleMessages = [], N = numbers[0], K = numbers[1];\n\nfor(var t = 0; t < N; t++) {\n var maxNumOfUniqueMessages = Math.min(N,\n Math.min(K, t) + 1 + Math.min(K, N - t - 1)\n ); \n \n if(t <= K) { \n visibleMessages[t] = Math.min(\n t + 1 + K, \n maxNumOfUniqueMessages \n );\n } else {\n var linkToPrevMessage = messageHistory[t] - 1; \n var intersectionNumber = (Math.min(linkToPrevMessage + K + 1, N) - (t - K));\n intersectionNumber = intersectionNumber > 0 ? intersectionNumber : 0;\n \n visibleMessages[t] = linkToPrevMessage >= 0 ? \n visibleMessages[linkToPrevMessage] + \n (maxNumOfUniqueMessages - intersectionNumber): \n maxNumOfUniqueMessages; \n }\n}\n\nwrite(visibleMessages.join(' '));"}], "negative_code": [{"source_code": "function getStep (i, k, n) {\n var before = k;\n var after = k;\n if (i < k) {\n before = +(0 - i);\n }\n if (i + k >= n) {\n after = (n - i) - 1;\n }\n\n return before + after + 1;\n}\n\nvar input = readline();\nvar messages = readline().split(' ');\n\ninput = input.split(' ');\nvar n = parseInt(input[0]);\nvar k = parseInt(input[1]);\n\nvar i, lastValue, step, diff, value;\n\nfor (i = 0; i < n; i++) {\n value = parseInt(messages[i]) - 1;\n lastValue = messages[value] || 0;\n step = getStep(i, k, n);\n diff = i - value - 1;\n\n if (value >= 0 && k > 0 && diff < step) {\n step = i - value + k - 1\n }\n messages[i] = lastValue + step\n}\n\nprint(messages.join(' '))\n"}, {"source_code": "function getIndexesRange (index, k, arr) {\n var range = [];\n var start = Math.max(index - k, 0);\n var end = Math.min(index + k + 1, arr.length);\n for (var i = start; i < end ; i++) {\n range.push(i);\n }\n return range;\n}\n\nvar input = readline();\nvar messages = readline().split(' ');\n\ninput = input.split(' ');\nvar n = parseInt(input[0]);\nvar k = parseInt(input[1]);\n\nvar i, value, range, prevIndex, readedMessages;\nvar map = {};\nvar messagesCounts = [];\n\nfor (i = 0; i < n; i++) {\n value = messages[i] = parseInt(messages[i]);\n readedMessages = [];\n\n prevIndex = value - 1;\n if (prevIndex > 0) {\n readedMessages = readedMessages.concat(map[prevIndex]);\n }\n\n range = getIndexesRange(i, k, messages);\n\n range.forEach(function (v) {\n if (readedMessages.indexOf(v) == -1) {\n readedMessages.push(v);\n }\n })\n\n map[i] = readedMessages;\n messagesCounts.push(readedMessages.length);\n}\n\nprint(messagesCounts.join(' '))\n"}, {"source_code": "function getBeforeStep (i, k) {\n return i < k ? +(0 - i) : k;\n}\n\nfunction getAfterStep (i, k, n) {\n return i + k >= n ? (n - i) - 1 : k;\n}\n\nfunction getStep (i, k, n) {\n return getBeforeStep(i, k) + getAfterStep(i, k, n) + 1;\n}\n\nvar input = readline();\nvar messages = readline().split(' ');\n\ninput = input.split(' ');\nvar n = parseInt(input[0]);\nvar k = parseInt(input[1]);\n\nvar i, value, lastValue, start, end, prevEnd, step;\n\nfor (i = 0; i < n; i++) {\n value = parseInt(messages[i]) - 1;\n lastValue = messages[value] || 0;\n\n start = Math.max(i - k, 0);\n end = i + getAfterStep(i, k, n);\n prevEnd = value + getAfterStep(value, k, n);\n\n step = i != 0 && value >= 0 && start <= prevEnd ? end - prevEnd : getStep(i, k, n);\n\n messages[i] = lastValue + step\n}\n\nprint(messages.join(' '))\n"}, {"source_code": "function getBeforeStep (i, k) {\n return i < k ? +(0 - i) : k;\n}\n\nfunction getAfterStep (i, k, n) {\n return i + k >= n ? (n - i) - 1 : k;\n}\n\nfunction getStep (i, k, n) {\n return getBeforeStep(i, k) + getAfterStep(i, k, n) + 1;\n}\n\nvar input = readline();\nvar messages = readline().split(' ');\n\ninput = input.split(' ');\nvar n = parseInt(input[0]);\nvar k = parseInt(input[1]);\n\nvar i, value, lastValue, start, end, prevEnd, step;\n\nfor (i = 0; i < n; i++) {\n value = parseInt(messages[i]) - 1;\n lastValue = messages[value] || 0;\n\n start = i - getBeforeStep(i, k);\n end = i + getAfterStep(i, k, n);\n prevEnd = value + getAfterStep(value, k, n);\n\n step = i != 0 && start <= prevEnd ? end - prevEnd : getStep(i, k, n);\n\n messages[i] = lastValue + step\n}\n\nprint(messages.join(' '))\n"}], "src_uid": "0b4e6268cf1238169591e17cb644d451"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\n\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", (data) => {\n s = s.split(\"\\n\").filter(Boolean);\n\n main();\n});\n\nfunction main() {\n const t = Number(s[0]);\n\n let i = 1;\n while (i < 3 * t + 1) {\n const length = s[i++];\n const a = s[i++].split(\" \").map(Number);\n const b = s[i++].split(\" \").map(Number);\n\n solve(a, b);\n }\n}\n\nfunction solve(a, b) {\n function recurse(a, b, index) {\n if (index > a.length - 1) {\n return;\n }\n\n if (a[index] < b[index]) {\n swap(a, b, index);\n }\n\n recurse(a, b, index + 1);\n }\n\n recurse(a, b, 0, 0);\n console.log(doSum(a, b));\n}\n\nfunction swap(a, b, index) {\n const temp = a[index];\n a[index] = b[index];\n b[index] = temp;\n}\n\nfunction doSum(a, b) {\n let sum = 0;\n for (let i = 0; i < a.length - 1; i++) {\n sum += Math.abs(a[i] - a[i + 1]);\n sum += Math.abs(b[i] - b[i + 1]);\n }\n return sum;\n}\n", "positive_code": [{"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (a, b, n)=>{\n let swap = (i)=>{\n let tmp = a[i];\n a[i] = b[i];\n b[i] = tmp;\n }\n let sum = 0;\n for (let i=1; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n var b = lines[i].split(' ').map(Number);\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = b;\n }else{\n var ans = 0;\n for(j = 1; j < n; j++){\n var x = Math.abs(a[j] - a[j - 1]) + Math.abs(b[j] - b[j - 1]);\n var y = Math.abs(a[j] - b[j - 1]) + Math.abs(b[j] - a[j - 1]);\n ans += Math.min(x, y);\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let brr = readline().split(' ').map(Number);\r\n\r\n const calc = i => Math.abs(arr[i-1] - arr[i]) + Math.abs(brr[i-1] - brr[i]);\r\n\r\n let sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n let cur = calc(i);\r\n let alt = Math.abs(arr[i-1] - brr[i]) + Math.abs(brr[i-1] - arr[i]);\r\n if (alt < cur) [arr[i], brr[i]] = [brr[i], arr[i]];\r\n sum += Math.min(alt, cur);\r\n }\r\n\r\n output(sum);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const a = lines[l++].trim().split(' ').map(Number)\n const b = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, a, b) {\n for (let i = 0; i < a.length; i++) {\n if (a[i] > b[i]) {\n [a[i], b[i]] = [b[i], a[i]]\n }\n }\n let ans = 0\n for (let i = 1; i < a.length; i++) {\n ans += Math.abs(a[i] - a[i - 1])\n ans += Math.abs(b[i] - b[i - 1])\n }\n // console.log(a, b)\n return ans\n}\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(v => parseInt(v));\r\n const b = ls[l++].split(' ').map(v => parseInt(v));\r\n solveInner(n, a, b);\r\n }\r\n}\r\n\r\nfunction solveInner(n, a, b) {\r\n for (let i = 0; i < n - 1; i++) {\r\n const d1 = Math.abs(a[i] - a[i + 1]) + Math.abs(b[i] - b[i + 1]);\r\n const d2 = Math.abs(a[i] - b[i + 1]) + Math.abs(b[i] - a[i + 1]);\r\n if (d1 > d2) {\r\n [a[i + 1], b[i + 1]] = [b[i + 1], a[i + 1]];\r\n }\r\n }\r\n let sum = 0;\r\n for (let i = 0; i < n - 1; i++) {\r\n sum += Math.abs(a[i] - a[i + 1]);\r\n sum += Math.abs(b[i] - b[i + 1]);\r\n }\r\n console.log(sum);\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, a, b) {\r\n const dp = new Array(n).fill(0).map(() => [0, 0])\r\n for (let i = 1; i < n; i++) {\r\n dp[i][0] = Math.min(\r\n dp[i - 1][0] + Math.abs(a[i] - a[i - 1]) + Math.abs(b[i] - b[i - 1]),\r\n dp[i - 1][1] + Math.abs(a[i] - b[i - 1]) + Math.abs(b[i] - a[i - 1]),\r\n )\r\n dp[i][1] = Math.min(\r\n dp[i - 1][0] + Math.abs(b[i] - a[i - 1]) + Math.abs(a[i] - b[i - 1]),\r\n dp[i - 1][1] + Math.abs(a[i] - a[i - 1]) + Math.abs(b[i] - b[i - 1]),\r\n )\r\n }\r\n return Math.min(dp[n - 1][0], dp[n - 1][1])\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 3 + 1])\r\n const a = inputs[__ * 3 + 2].trim().split(' ').map(Number)\r\n const b = inputs[__ * 3 + 3].trim().split(' ').map(Number)\r\n\r\n res.push(solve(n, a, b))\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (n, a, b)=>{\n let res = 0;\n for (let i = 1; i < n; i++) {\n let min = Math.abs(a[i] - a[i - 1]) + Math.abs(b[i] - b[i - 1]);\n min = Math.min(min, Math.abs(a[i] - b[i - 1]) + Math.abs(b[i] - a[i - 1]));\n res += min;\n }\n return res;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n let b = ra();\n console.log(`${calc(n, a, b)}`);\n }\n}\n\n\n\n"}, {"source_code": "var t = +readline()\r\n\r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline()\r\n var arr1 = readline().split(\" \").map(x => +x);\r\n var arr2 = readline().split(\" \").map(x => +x);\r\n print(getMinSum(arr1,arr2))\r\n}\r\n \r\n function getMinSum(arr1,arr2){\r\n\r\n var ai = arr1[0];\r\n var bi = arr2[0];\r\n var sum = 0;\r\n for(var i = 1; i s2){\r\n sum += s2;\r\n ai = arr2[i];\r\n bi = arr1[i];\r\n }else {\r\n sum += s1;\r\n ai = arr1[i];\r\n bi = arr2[i];\r\n }\r\n }\r\n return sum;\r\n\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet s = \"\";\n\nprocess.stdin.on(\"data\", (data) => {\n s += data;\n});\n\nprocess.stdin.on(\"end\", (data) => {\n s = s.split(\"\\n\").filter(Boolean);\n\n main();\n});\n\nfunction main() {\n const t = Number(s[0]);\n\n let i = 1;\n while (i < 3 * t + 1) {\n const length = s[i++];\n const a = s[i++].split(\" \").map(Number);\n const b = s[i++].split(\" \").map(Number);\n\n solve(a, b);\n }\n}\n\nfunction solve(a, b) {\n function recurse(a, b, index) {\n if (index >= a.length - 1) {\n return;\n }\n\n if (a[index] < b[index]) {\n swap(a, b, index);\n }\n\n recurse(a, b, index + 1);\n }\n\n recurse(a, b, 0, 0);\n console.log(doSum(a, b));\n}\n\nfunction swap(a, b, index) {\n const temp = a[index];\n a[index] = b[index];\n b[index] = temp;\n}\n\nfunction doSum(a, b) {\n let sum = 0;\n for (let i = 0; i < a.length - 1; i++) {\n sum += Math.abs(a[i] - a[i + 1]);\n sum += Math.abs(b[i] - b[i + 1]);\n }\n return sum;\n}\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (a, b, n)=>{\n let swap = (i)=>{\n let tmp = a[i];\n a[i] = b[i];\n b[i] = tmp;\n }\n for (let i=1; iMath.abs(a[i-1]-b[i]))\n swap(i);\n }\n let sum = 0;\n for (let i=1; i b[i]) return 'NO';\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (b[i] > b[(i + 1) % n] + 1 && a[i] < b[i]) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let brr = readline().split(' ').map(Number);\r\n\r\n let next = (a, i) => {\r\n if (i === a.length - 1) {\r\n return a[0];\r\n } else {\r\n return a[i + 1];\r\n }\r\n }\r\n\r\n let no = false;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === brr[i]) {\r\n continue;\r\n }\r\n if (arr[i] > brr[i]) {\r\n no = true;\r\n break;\r\n }\r\n if (brr[i] > (next(brr, i) + 1)) {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let a = iInpArr();\r\n let b = iInpArr();\r\n const helper = (a, b) => {\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > b[i]) return false;\r\n if (a[i] !== b[i] && b[(i + 1) % n] + 1 < b[i]) return false;\r\n }\r\n return true;\r\n };\r\n console.log(helper(a, b) ? \"YES\" : \"NO\");\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let a = iInpArr();\r\n let b = iInpArr();\r\n let flag = 1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n if (flag === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n flag = 1;\r\n for (let i = 0; i < n; i++) {\r\n if (b[i] < a[i]) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n if (flag === 0) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n flag = 1;\r\n let max = a[n - 1];\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (a[i] === b[i]) {\r\n max = a[i];\r\n continue;\r\n }\r\n if (b[i] <= max) {\r\n a[i] = b[i];\r\n max = b[i];\r\n continue;\r\n } else {\r\n if (a[i] <= max) a[i] = max;\r\n else max = a[i];\r\n }\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === b[i]) continue;\r\n if (b[i] - 1 <= a[(i + 1) % n]) a[i] = b[i];\r\n else {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n\r\n if (flag === 0) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let a = iInpArr();\r\n let b = iInpArr();\r\n let flag = 1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n if (flag === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n flag = 1;\r\n let max = a[n - 1];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === b[i]) {\r\n max = a[i];\r\n continue;\r\n }\r\n if (a[i] < max && b[i] >= max) a[i] = max;\r\n max = Math.max(max, a[i]);\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === b[i]) continue;\r\n if (i === n - 1) {\r\n if (a[i] > b[i]) {\r\n flag = 0;\r\n break;\r\n } else {\r\n let dif = b[i] - a[i];\r\n let dif2 = a[0] - a[i] + 1;\r\n if (dif > dif2) {\r\n flag = 0;\r\n break;\r\n } else {\r\n a[i] = b[i];\r\n }\r\n }\r\n } else {\r\n if (a[i] > b[i]) {\r\n flag = 0;\r\n break;\r\n } else {\r\n let dif = b[i] - a[i];\r\n let dif1 = a[i + 1] - a[i] + 1;\r\n if (dif > dif1) {\r\n flag = 0;\r\n break;\r\n } else a[i] = b[i];\r\n }\r\n }\r\n }\r\n if (flag === 1) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let a = iInpArr();\r\n let b = iInpArr();\r\n let flag = 1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== b[i]) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n if (flag === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n flag = 1;\r\n let max = a[n - 1];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === b[i]) {\r\n max = a[i];\r\n continue;\r\n }\r\n if (a[i] < max && b[i] > max) a[i] = max;\r\n max = Math.max(max, a[i]);\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === b[i]) continue;\r\n if (i === n - 1) {\r\n if (a[i] > b[i]) {\r\n flag = 0;\r\n break;\r\n } else {\r\n let dif = b[i] - a[i];\r\n let dif2 = a[0] - a[i] + 1;\r\n if (dif > dif2) {\r\n flag = 0;\r\n break;\r\n } else {\r\n a[i] = b[i];\r\n }\r\n }\r\n } else {\r\n if (a[i] > b[i]) {\r\n flag = 0;\r\n break;\r\n } else {\r\n let dif = b[i] - a[i];\r\n let dif1 = a[i + 1] - a[i] + 1;\r\n if (dif > dif1) {\r\n flag = 0;\r\n break;\r\n } else a[i] = b[i];\r\n }\r\n }\r\n }\r\n if (flag === 1) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "9851ff47c77e13f62be1edaf3d74c4ad"} {"source_code": "const n = Number(readline());\nconst a = [1].concat(readline().split(\" \").slice(0, n)).map(x => Number(x < 0));\nfor (var i = 1; i <= n; i++)\n a[i] += a[i - 1];\nconst counts = [0, 0];\nfor (var i = 0; i <= n; i++) {\n a[i] &= 1;\n counts[a[i]]++;\n}\nvar negative = 0;\nfor (var i = 0; i <= n;) {\n var cur = a[i];\n var next = 1 - cur;\n var j = a.indexOf(next, i);\n if (j === -1) break;\n var diff = j - i;\n negative += diff * counts[next];\n counts[cur] -= diff;\n i = j;\n}\nprint(`${negative} ${n * (n + 1) * 0.5 - negative}`);\n", "positive_code": [{"source_code": "const n = Number(readline());\nconst a = [1].concat(readline().split(\" \").slice(0, n)).map(x => Number(x < 0));\nfor (var i = 1; i <= n; i++)\n a[i] += a[i - 1];\nconst counts = [0, 0];\nfor (var i = 0; i <= n; i++) {\n a[i] &= 1;\n counts[a[i]]++;\n}\nvar negative = 0;\nfor (var i = 0; i <= n;) {\n var cur = a[i];\n var next = 1 - cur;\n var j = a.indexOf(next, i);\n if (j === -1) break;\n var diff = j - i;\n negative += diff * counts[next];\n counts[cur] -= diff;\n i = j;\n}\nprint(`${negative} ${n * (n + 1) * 0.5 - negative}`);\n"}], "negative_code": [], "src_uid": "78d3acc3ade53f488739a59100bfcebd"} {"source_code": "var t = +readline();\n\nfor (var i=0; i {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)\n rl.close();\n\n let arr = input.split(\" \").map(x => parseInt(x))\n // console.log((arr[1]-1)%arr[3])\n let max = 999999999999\n let ans1 = max\n let ans2 = max\n let ans3 = max\n if (Math.abs(arr[2] - arr[1]) % arr[3] === 0) {\n ans1 = Math.round(Math.abs(arr[2] - arr[1]) / arr[3])\n }\n if (Math.abs(arr[2] - 1) % arr[3] === 0) {\n let rest1 = Math.abs(arr[2] - 1) / arr[3]\n let rest2 = Math.abs(arr[1] - 1) / arr[3]\n ans2 = Math.round(rest1) + Math.ceil(rest2)\n\n }\n if (Math.abs(arr[0] - arr[2]) % arr[3] === 0) {\n let rest1 = Math.abs(arr[1] - arr[0]) / arr[3]\n let rest2 = Math.abs(arr[0] - arr[2]) / arr[3]\n ans3 = Math.ceil(rest1) + Math.round(rest2)\n }\n //console.log(ans1, ans2, ans3)\n let mn = Math.min(ans1, Math.min(ans2, ans3))\n console.log(mn === max ? -1 : mn)\n }\n l++\n});\n"}, {"source_code": "var t = readline();\nfor (var i=0; i {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)\n rl.close();\n\n let arr = input.split(\" \").map(x => parseInt(x))\n if (Math.abs(arr[2] - arr[1]) % arr[3] === 0) {\n console.log(Math.floor(Math.abs(arr[2] - arr[1]) / arr[3]))\n } else if (Math.abs(Math.min(arr[2], arr[1]) - 2) % arr[3] === 0 &&\n Math.abs(Math.max(arr[2], arr[1]) - 1) % arr[3] === 0) {\n console.log(Math.floor(Math.max(arr[2], arr[1]) - 1 / arr[3]))\n } else\n console.log(\"-1\")\n }\n l++\n});\n"}, {"source_code": "var t = readline();\nfor (var i=0; i {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\n// const n = parseInt(input[0], 10);\nlet secondLine = input[1].split(' ');\nconst nums = secondLine.map((a) => parseInt(a, 10));\n \nif (nums.length <= 2) {\n console.log(0);\n return\n}\n \nlet min = nums[0];\nlet max = nums[0];\nlet cmin = 1;\nlet cmax = 1;\nlet result = 0;\n \nfor (let i=1; i< nums.length; i++) {\n const num = nums[i];\n const nmin = Math.min(min, num);\n if (nmin !== min) {\n if (min !== max) {\n result += cmin;\n }\n cmin = 1;\n }\n if (num === min) {\n cmin += 1;\n }\n const nmax = Math.max(max, num);\n if (nmax !== max) {\n if (min !== max) {\n result += cmax;\n }\n cmax = 1;\n }\n if (num === max) {\n cmax += 1;\n }\n if (nmin === min && nmax === max && nmax !== num && nmin !== num) {\n result += 1;\n }\n// console.log({num ,min, nmin, max, nmax, result});\n min = nmin;\n max = nmax;\n}\nconsole.log(result);\n});", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(x=>parseInt(x));\nvar res=0;\ninput.sort((a,b)=>a-b);\nvar small=input[0];\nvar big=input[n-1];\n\nfor(var i=1;i<=n-2;i++){\n if(input[i]>small && input[i]parseInt(x));\nvar res=0;\n\nvar mn=findMin(input);\nvar mx=findMax(input);\n\nfor(var i=0;imn && input[i]a-b),\n counter = 0;\n\n big = stewards[stewards.length - 1],\n small = stewards[0];\n\nfor (var i = 1; i < stewards.length - 1; i++){\n \n if(stewards[i] > small && stewards[i] < big)\n counter++;\n \n // var count = i,\n // thereIsBefore = false,\n // thereIsAfter = false;\n // while(count > 0) {\n // if(stewards[count - 1] < stewards[i]){\n // thereIsBefore = true;\n // break;\n // }\n // count--;\n // }\n // while(count < stewards.length - 1) {\n // if(stewards[count + 1] > stewards[i]){\n // thereIsAfter = true;\n // break;\n // }\n // count++;\n // }\n // if(thereIsAfter && thereIsBefore)\n // counter++;\n\n}\n\nprint(counter);"}, {"source_code": "function main(n,arr){\n\n var min = Infinity;\n var max = -Infinity;\n var cnt = 0;\n\n for(var i = 0 ; i < n ; i++){\n\n max = Math.max(max,arr[i]);\n min = Math.min(min,arr[i]);\n\n }\n\n for(var i = 0 ; i < n ; i++){\n if(arr[i] > min && arr[i] < max)cnt++;\n }\n\n print(cnt);\n}\n\n\nvar n = parseInt(readline());\n\nvar arr = readline().split(' ');\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(n,arr);\n"}, {"source_code": "var n = parseInt(readline());\nvar p = readline().split(' ').map(function(x){\n return parseInt(x);\n});\nvar minv = 1e9;\nvar maxv = -1e9;\np.forEach(function(x){\n minv = Math.min(minv, x);\n maxv = Math.max(maxv, x); \n});\nprint(p.filter(function(x){\n return minv < x && x < maxv;\n}).length);"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n\n stewardsStrength = stewardsStrength.sort((a, b) => a - b)\n\n var i = 1\n var count = 0\n while (i < numberOfSteward) {\n if (stewardsStrength[0] < stewardsStrength[i] && stewardsStrength[i] < stewardsStrength[stewardsStrength.length - 1]) {\n count += 1\n }\n i++\n }\n\n print(count)"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n\n var weaker = Infinity\n var stronger = -Infinity\n for (var i = 0; i < numberOfSteward; i++) {\n weaker = Math.min(weaker, stewardsStrength[i])\n stronger = Math.max(stronger, stewardsStrength[i])\n }\n\n var count = 0\n for (var i = 0; i < numberOfSteward; i++) {\n if (weaker < stewardsStrength[i] && stewardsStrength[i] < stronger) {\n count += 1\n }\n }\n\n print(count)"}, {"source_code": "var n = parseInt(readline())\nvar list = readline().trim().split(' ')\nvar min = 1e9+1, max = -1\nvar dict = {}\nvar total = list.length\nfor (var num of list) {\n num = parseInt(num)\n min = min > num ? num : min\n max = max < num ? num : max\n dict[num] = (dict[num] || 0) + 1\n}\n\nif (min === max) {\n print(0)\n} else {\n print (total - dict[min] - dict[max])\n}\n"}, {"source_code": "var stuartsCount = +readline(),\n stuartsRaits = readline().split(/\\s+/).slice(0, stuartsCount),\n minRait = Math.min.apply(null, stuartsRaits),\n maxRait = Math.max.apply(null, stuartsRaits);\n\nprint(\n stuartsRaits.reduce(function(count, rait){\n return (rait > minRait && rait < maxRait) ? count + 1 : count;\n }, 0)\n);"}, {"source_code": "// Generated by CoffeeScript 1.12.4\n(function() {\n var count, max, min, stuarts;\n\n readline();\n\n stuarts = readline().split(\" \").map(Number);\n\n min = stuarts[0];\n\n max = 0;\n\n count = 0;\n\n stuarts.forEach(function(num) {\n if (num < min) {\n min = num;\n }\n if (num > max) {\n return max = num;\n }\n });\n\n stuarts.forEach(function(num) {\n if (num > min && num < max) {\n return count++;\n }\n });\n\n write(count);\n\n}).call(this);\n"}, {"source_code": "console = {log: ()=>{}}\nvar count, max, min, stuarts;\nreadline();\nstuarts = readline().split(\" \").map(Number);\nmin = stuarts[0];\nmax = 0;\ncount = 0;\nstuarts.forEach(function(num) {\n if (num < min) {\n min = num;\n }\n if (num > max) {\n return max = num;\n }\n});\nstuarts.forEach(function(num) {\n if (num > min && num < max) {\n return count++;\n }\n});\nwrite(count);\n\n"}, {"source_code": "try {require(\"codeforces\")} catch(e){console = {log: function(){}, error: function(){}}};\n\nvar count, max, min, stuarts;\nreadline();\nstuarts = readline().split(\" \").map(Number);\nmin = stuarts[0];\nmax = 0;\ncount = 0;\nstuarts.forEach(function(num) {\n if (num < min) {\n min = num;\n }\n if (num > max) {\n return max = num;\n }\n});\nconsole.log(\"ssss\");\nstuarts.forEach(function(num) {\n if (num > min && num < max) {\n return count++;\n }\n});\nwrite(count);"}, {"source_code": "var n = parseInt(readline());\nvar total = readline().split(\" \").map(Number).sort((a, b) => a - b);\n\nvar count = total.length - 2;\n\nfor (var i = 0; i < total.length; i++) {\n if ((i !== 0 && total[i] === total[0]) || \n (i !== total.length - 1 && total[i] === total[total.length - 1])) {\n count--;\n }\n}\n\nprint(count < 0 ? 0: count);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n let a = readline().split(' ').map(x => parseInt(x));\n let r = 0;\n if (a.length > 2) {\n let min = Number.MAX_SAFE_INTEGER, max = Number.MIN_SAFE_INTEGER;\n for (let i = 0; i < n; i++) {\n min = Math.min(min, a[i]);\n max = Math.max(max, a[i]);\n }\n for (let i = 0; i < n; i++) {\n if (a[i] > min && a[i] < max) {\n r++;\n }\n }\n }\n print(r);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > min && arr[i] < max) {\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let [n] = readint();\n let a = readint();\n let all = a.length;\n let mx = a[0];\n let mn = a[0];\n a.forEach(element => {\n if(mx < element) mx = element;\n if(mn > element) mn = element;\n });\n let mxcount = 0, \n mncount = 0;\n a.forEach(element => {\n if(element == mx) mxcount++;\n if(element == mn) mncount++;\n });\n if(mx != mn)\n print(a.length - mncount - mxcount);\n else \n print(a.length - mncount);\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let [n] = readint();\n let a = readint();\n let all =a.length;\n let mx = a[0];\n let mn = a[0];\n a.forEach(element => {\n if(mx < element) mx = element;\n if(mn > element) mn = element;\n });\n let mxcount = 0, \n mncount = 0;\n a.forEach(element => {\n if(element == mx) mxcount++;\n if(element == mn) mncount++;\n });\n print(a.length - mncount - mncount);\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\n// const n = parseInt(input[0], 10);\nlet secondLine = input[1].split(' ');\nconst nums = secondLine.map((a) => parseInt(a, 10));\n \nif (nums.length <= 2) {\n console.log(0);\n}\n \nlet min = nums[0];\nlet max = nums[0];\nlet cmin = 1;\nlet cmax = 1;\nlet result = 0;\n \nfor (let i=1; i< nums.length; i++) {\n const num = nums[i];\n const nmin = Math.min(min, num);\n if (nmin !== min && min !== max) {\n result += cmin;\n cmin = 1;\n }\n if (num === min) {\n cmin += 1;\n }\n const nmax = Math.max(max, num);\n if (nmax !== max && min !== max) {\n result += cmax;\n cmax = 1;\n }\n if (num === max) {\n cmax += 1;\n }\n if (nmin === min && nmax === max && nmax !== num && nmin !== num) {\n result += 1;\n }\n// console.log({num ,min, nmin, max, nmax, result});\n min = nmin;\n max = nmax;\n}\nconsole.log(result);\n});\n "}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\n// const n = parseInt(input[0], 10);\nlet secondLine = input[1].split(' ');\nconst nums = secondLine.map((a) => parseInt(a, 10));\n\nif (nums.length <= 2) {\n return 0;\n}\n\nlet min = nums[0];\nlet max = nums[0];\nlet cmin = 1;\nlet cmax = 1;\nlet result = 0;\n\nfor (let i=1; i< nums.length; i++) {\n const num = nums[i];\n const nmin = Math.min(min, num);\n if (nmin !== min && min !== max) {\n result += cmin;\n cmin = 1;\n }\n if (num === min) {\n cmin += 1;\n }\n const nmax = Math.max(max, num);\n if (nmax !== max && min !== max) {\n result += cmax;\n cmax = 1;\n }\n if (num === max) {\n cmax += 1;\n }\n if (nmin === min && nmax === max && nmax !== num && nmin !== num) {\n result += 1;\n }\n// console.log({num ,min, nmin, max, nmax, result});\n min = nmin;\n max = nmax;\n}\nreturn result;\n});\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\n// const n = parseInt(input[0], 10);\nlet secondLine = input[1].split(' ');\nconst nums = secondLine.map((a) => parseInt(a, 10));\n \nif (nums.length <= 2) {\n console.log(0);\n return\n}\n \nlet min = nums[0];\nlet max = nums[0];\nlet cmin = 1;\nlet cmax = 1;\nlet result = 0;\n \nfor (let i=1; i< nums.length; i++) {\n const num = nums[i];\n const nmin = Math.min(min, num);\n if (nmin !== min && min !== max) {\n result += cmin;\n cmin = 1;\n }\n if (num === min) {\n cmin += 1;\n }\n const nmax = Math.max(max, num);\n if (nmax !== max && min !== max) {\n result += cmax;\n cmax = 1;\n }\n if (num === max) {\n cmax += 1;\n }\n if (nmin === min && nmax === max && nmax !== num && nmin !== num) {\n result += 1;\n }\n// console.log({num ,min, nmin, max, nmax, result});\n min = nmin;\n max = nmax;\n}\nconsole.log(result);\n});\n "}, {"source_code": "function findMin(array){\n var mn = Infinity;\n for(var i=0;iparseInt(x));\nvar res=0;\n\nvar mn=findMin(input);\nvar mx=findMax(input);\n\nfor(var i=1;i<=n-2;i++){\n if(input[i]>mn && input[i]parseInt(x));\nvar res=0;\ninput.sort((a,b)=>a-b);\nfor(var i=1;i 0) {\n if(stewards[count - 1] < stewards[i]){\n thereIsBefore = true;\n break;\n }\n count--;\n }\n while(count < stewards.length - 1) {\n if(stewards[count + 1] > stewards[i]){\n thereIsAfter = true;\n break;\n }\n count++;\n }\n if(thereIsAfter && thereIsBefore)\n counter++;\n\n}\n\nprint(counter);"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n\n stewardsStrength = stewardsStrength.sort((a, b) => a - b)\n\n var i = 1\n var count = 0\n while (i < numberOfSteward - 1) {\n if (stewardsStrength[i - 1] < stewardsStrength[i] && stewardsStrength[i] < stewardsStrength[i + 1]) {\n count += 1\n }\n i++\n }\n\n print(count)"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n\n var weaker = Infinity\n var stronger = -Infinity\n for (var i = 0; i < numberOfSteward; i++) {\n weaker = Math.min(weaker, numberOfSteward[i])\n stronger = Math.max(stronger, numberOfSteward[i])\n }\n\n var count = 0\n for (var i = 0; i < numberOfSteward; i++) {\n if (stewardsStrength[0] < stewardsStrength[i] && stewardsStrength[i] < stewardsStrength[stewardsStrength.length - 1]) {\n count += 1\n }\n }\n\n print(count)"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n \n var weaker = Infinity\n var stronger = -Infinity\n for (var i = 0; i < numberOfSteward; i++) {\n weaker = Math.min(weaker, numberOfSteward[i])\n stronger = Math.max(stronger, numberOfSteward[i])\n }\n \n var count = 0\n for (var i = 0; i < numberOfSteward; i++) {\n if (weaker < stewardsStrength[i] && stewardsStrength[i] < stronger) {\n count += 1\n }\n }\n \n print(count)"}, {"source_code": "var numberOfSteward = Number(readline())\n var stewardsStrength = readline().split(' ').map(Number)\n\n stewardsStrength = stewardsStrength.sort((a, b) => a - b)\n\n var i = 1\n var count = 0\n while (i < numberOfSteward - 1) {\n if (stewardsStrength[i - 1] < stewardsStrength[i] && stewardsStrength[i] < stewardsStrength[i + 1]) {\n count += 1\n i += 3\n } else {\n i++\n }\n }\n\n print(count)"}, {"source_code": "var stuartsCount = +readline(),\n stuartsRaits = readline().split(/\\s+/),\n minRait = stuartsRaits[0],\n maxRait = stuartsRaits[0],\n result = 0;\n \nstuartsRaits.forEach(function(rait){\n var tmpRait;\n \n if(rait > maxRait) {\n tmpRait = maxRait;\n maxRait = rait;\n checkNeedGuard(tmpRait);\n return;\n }\n \n if(rait < minRait) {\n tmpRait = minRait;\n minRait = rait;\n checkNeedGuard(tmpRait);\n return;\n }\n \n checkNeedGuard();\n});\n\nfunction checkNeedGuard(rait) {\n if(rait > minRait && rait < maxRait) result++;\n}\n\nprint(result);"}, {"source_code": "try {require(\"codeforces\")} catch(e){console = {log: function(){}, error: function(){}}};\n\nvar count, max, min, stuarts;\nreadline();\nstuarts = readline().split(\" \").map(Number);\nmin = stuarts[0];\nmax = 0;\ncount = 0;\nstuarts.forEach(function(num) {\n if (num < min) {\n min = num;\n }\n if (num > max) {\n return max = num;\n }\n});\nconsole.log(\"ssss\");\nstuarts.forEach(function(num) {\n if (num > min && num < max) {\n return count+2;\n }\n});\nwrite(count);"}, {"source_code": "var n = parseInt(readline());\nvar total = readline().split(\" \").map(Number).sort((a, b) => a - b);\n\nvar se = new Set(total);\n\nif (se.size <= 2) {\n print(0);\n} else {\n print(se.size - 2);\n}"}, {"source_code": "var n = parseInt(readline());\nvar total = readline().split(\" \").map(Number).sort((a, b) => a - b);\n\nvar count = total.length - 2;\n\nfor (var i = 0; i < total.length; i++) {\n if (total[i] === total[0] || total[i] === total[total.length - 1]) {\n count--;\n }\n}\n\nprint(count < 0 ? 0: count);"}], "src_uid": "acaa8935e6139ad1609d62bb5d35128a"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n var j = 0\r\n var array2 = [\r\n 3, 5, 11,\r\n 13, 101, 103,\r\n 1009, 1013, 10007,\r\n 10009, 100003, 100019,\r\n 1000003, 1000033, 10000019,\r\n 10000079,\r\n 179424673, 179424691\r\n ]\r\n\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n a--\r\n b--\r\n var cc = c - 1\r\n if (cc === 0) {\r\n console.log(array2[Math.floor(a * 2)], array2[b * 2 + 1])\r\n return\r\n }\r\n a = a - cc\r\n b = b - cc\r\n console.log(array2[a * 2] * Math.pow(10, cc), array2[b * 2 + 1] * Math.pow(10, cc))\r\n })\r\n}\r\n\r\nvar eratosthenes = function (n) {\r\n // Eratosthenes algorithm to find all primes under n\r\n var array = [], upperLimit = Math.sqrt(n), output = [];\r\n\r\n // Make an array from 2 to (n - 1)\r\n for (var i = 0; i < n; i++) {\r\n array.push(true);\r\n }\r\n\r\n // Remove multiples of primes starting from 2, 3, 5,...\r\n for (var i = 2; i <= upperLimit; i++) {\r\n if (array[i]) {\r\n for (var j = i * i; j < n; j += i) {\r\n array[j] = false;\r\n }\r\n }\r\n }\r\n\r\n // All array[i] set to true are primes\r\n for (var i = 2; i < n; i++) {\r\n if (array[i]) {\r\n output.push(i);\r\n }\r\n }\r\n\r\n return output;\r\n};\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(a, b, c) {\r\n function getPrime(n) {\r\n next: while (n++) {\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) continue next;\r\n }\r\n return n;\r\n }\r\n return 1;\r\n }\r\n let z = getPrime(10 ** (c - 1));\r\n let x = 1;\r\n let y = 1;\r\n if (a === b) {\r\n x = getPrime(Math.floor(10 ** (a - 1) / z) + 1);\r\n y = getPrime(x);\r\n } else {\r\n x = getPrime(Math.floor(10 ** (a - 1) / z) + 1);\r\n y = getPrime(Math.floor(10 ** (b - 1) / z) + 1);\r\n }\r\n x = BigInt(x) * BigInt(z);\r\n y = BigInt(y) * BigInt(z);\r\n return `${x.toString()} ${y.toString()}`;\r\n}\r\n\r\nasync function main(read) {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [a, b, c] = (await read()).split(' ').map(Number);\r\n res.push(solve(a, b, c));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var i = 1; i < input.length; i++) {\r\n var [a, b, c] = input[i].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var num1 = 10 ** (a - 1);\r\n var num2 = 10 ** (b - 1) + 10 ** (c - 1);\r\n console.log(num1 + \" \" + num2);\r\n }\r\n})"}, {"source_code": "/*\r\n| In English \u041f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438\r\nlukas_rimkus | Logout\r\n\r\nHOME\r\nTOP\r\nCONTESTS\r\nGYM\r\nPROBLEMSET\r\nGROUPS\r\nRATING\r\nEDU\r\nAPI\r\nCALENDAR\r\nHELP\r\n\r\nPROBLEMSSUBMIT CODEMY SUBMISSIONSSTATUSHACKSSTANDINGSCUSTOM INVOCATION\r\n \r\nMy contest submissions\r\n \r\n#\tWhen\tWho\tProblem\tLang\tVerdict\tTime\tMemory\r\n112854886\tApr/12/2021 18:31UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tTime limit exceeded on test 2\t2000 ms\t12000 KB\r\n112853780\tApr/12/2021 18:29UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tWrong answer on test 1\t31 ms\t0 KB\r\n112852890\tApr/12/2021 18:27UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tWrong answer on test 1\t31 ms\t0 KB\r\n112851646\tApr/12/2021 18:24UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tTime limit exceeded on test 1\t2000 ms\t11800 KB\r\n112851156\tApr/12/2021 18:23UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tWrong answer on test 1\t46 ms\t0 KB\r\n112849514\tApr/12/2021 18:19UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tTime limit exceeded on test 2\t2000 ms\t11800 KB\r\n112845911\tApr/12/2021 18:11UTC+2\tlukas_rimkus\tB - GCD Length\tNode.js\tWrong answer on test 1\t373 ms\t11300 KB\r\n112834898\tApr/12/2021 17:47UTC+2\tlukas_rimkus\tA - Review Site\tNode.js\tAccepted\t218 ms\t6100 KB\r\n \r\nEducational Codeforces Round 107 (Rated for Div. 2)\r\nFinished\r\nPractice\r\nAdd to favourites\r\n \r\n\u2192 Virtual participation\r\nVirtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.\r\n \r\n\u2192 Practice\r\nYou are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.\r\n \r\n\u2192 Clone Contest to Mashup\r\nYou can clone this contest to a mashup.\r\n\r\n \r\n\u2192 Contest materials\r\nAnnouncement\r\n\r\nCodeforces (c) Copyright 2010-2021 Mike Mirzayanov\r\nThe only programming contests Web 2.0 platform\r\nServer time: Apr/12/2021 23:55:11UTC+2 (h2).\r\nMobile version, switch to desktop version.\r\nPrivacy Policy\r\nSupported by\r\nTelegram \u0418\u0422\u041c\u041e\r\nBy lukas_rimkus, contest: Educational Codeforces Round 107 (Rated for Div. 2), problem: (B) GCD Length, Time limit exceeded on test 2, #, Copy\r\n*/\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--) {\r\n const [a,b,c] = readLine().split(' ').map(Number );\r\n const x = Math.pow(10,a-1) + Math.pow(10,c-1);\r\n const y = Math.pow(10,b-1);\r\n console.log(x,y)\r\n \r\n }\r\n})\r\n\r\nfunction readLine(){\r\n return data[currentLine++]\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tvar g = Math.pow(10, c - 1);\r\n\t\tvar x = g;\r\n\t\tvar y = g;\r\n\t\twhile(x < Math.pow(10, a - 1)){\r\n\t\t\tx *= 3;\r\n\t\t}\r\n\t\twhile(y < Math.pow(10, b - 1)){\r\n\t\t\ty *= 7;\r\n\t\t}\r\n\t\tmyout(x + \" \" + y);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n while (t--) {\r\n let [a, b, c] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let g = 1,\r\n f = 1,\r\n s = 1;\r\n for (let i = 2; i <= c; i++) g *= 10;\r\n for (let i = 2; i <= a; i++) f *= 10;\r\n for (let i = 2; i <= b; i++) s *= 10;\r\n if (f >= s) s += g;\r\n else f += g;\r\n console.log(f + \" \" + s);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c] = readLine().split(' ').map(Number);\r\n\r\n let xstart = '1';\r\n \r\n for(let i = 1 ; i < a; i++){\r\n xstart+= '0';\r\n }\r\n xstart = parseInt(xstart);\r\n let xend = '';\r\n for(let i = 0; i < a; i++){\r\n xend+= '9';\r\n }\r\n xend = parseInt(xend);\r\n\r\n let ystart = '1';\r\n for(let i = 1; i < b; i++){\r\n ystart += '0';\r\n }\r\n ystart = parseInt(ystart);\r\n\r\n let yend = '';\r\n for(let i = 0; i < b; i++){\r\n yend += '9';\r\n }\r\n yend = parseInt(yend);\r\n\r\n let cstart = '1';\r\n for(let i = 1; i < c; i++){\r\n cstart += '0';\r\n }\r\n cstart = parseInt(cstart);\r\n\r\n let cend = '';\r\n for(let i = 0; i < c; i++){\r\n cend += '9';\r\n }\r\n cend = parseInt(cend);\r\n \r\n let stop = false;\r\n for(let i = xstart; i <= xend; i++){\r\n if(Number(i.toString().split('').pop()) === 0) continue;\r\n for(let j = ystart; j <= yend; j++){\r\n if(Number(j.toString().split('').pop()) === 0) continue;\r\n var ans = gcd(i,j);\r\n if(ans.toString().length === c.toString().length && Number(ans.toString().split('').pop() !== 0)){\r\n console.log(i,j);\r\n stop = true;\r\n break;\r\n }\r\n }\r\n if(stop) break;\r\n }\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n "}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c] = readLine().split(' ').map(Number);\r\n\r\n let xstart = '1';\r\n \r\n for(let i = 1 ; i < a; i++){\r\n xstart+= '0';\r\n }\r\n xstart = parseInt(xstart);\r\n let xend = '';\r\n for(let i = 0; i < a; i++){\r\n xend+= '9';\r\n }\r\n xend = parseInt(xend);\r\n\r\n let ystart = '1';\r\n for(let i = 1; i < b; i++){\r\n ystart += '0';\r\n }\r\n ystart = parseInt(ystart);\r\n\r\n let yend = '';\r\n for(let i = 0; i < b; i++){\r\n yend += '9';\r\n }\r\n yend = parseInt(yend);\r\n\r\n let cstart = '1';\r\n for(let i = 1; i < c; i++){\r\n cstart += '0';\r\n }\r\n cstart = parseInt(cstart);\r\n\r\n let cend = '';\r\n for(let i = 0; i < c; i++){\r\n cend += '9';\r\n }\r\n cend = parseInt(cend);\r\n \r\n let stop = false;\r\n for(let i = xstart; i <= xend; i++){\r\n if(Number(i.toString().split('').pop()) === 0) continue;\r\n for(let j = ystart; j <= yend; j++){\r\n if(Number(j.toString().split('').pop()) === 0) continue;\r\n if(gcd(i,j).toString().length === c.toString().length){\r\n console.log(i,j);\r\n stop = true;\r\n break;\r\n }\r\n }\r\n if(stop) break;\r\n }\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n "}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c] = readLine().split(' ').map(Number);\r\n\r\n let xstart = '1';\r\n \r\n for(let i = 1 ; i < a; i++){\r\n xstart+= '0';\r\n }\r\n xstart = parseInt(xstart);\r\n let xend = '';\r\n for(let i = 0; i < a; i++){\r\n xend+= '9';\r\n }\r\n xend = parseInt(xend);\r\n\r\n let ystart = '1';\r\n for(let i = 1; i < b; i++){\r\n ystart += '0';\r\n }\r\n ystart = parseInt(ystart);\r\n\r\n let yend = '';\r\n for(let i = 0; i < b; i++){\r\n yend += '9';\r\n }\r\n yend = parseInt(yend);\r\n\r\n let cstart = '1';\r\n for(let i = 1; i < c; i++){\r\n cstart += '0';\r\n }\r\n cstart = parseInt(cstart);\r\n\r\n let cend = '';\r\n for(let i = 0; i < c; i++){\r\n cend += '9';\r\n }\r\n cend = parseInt(cend);\r\n \r\n let stop = false;\r\n for(let i = xstart; i <= xend; i++){\r\n if(Number(i.toString().split('').pop()) === 0) continue;\r\n for(let j = ystart; j <= yend; j++){\r\n if(Number(j.toString().split('').pop()) === 0) continue;\r\n if(gcd(i,j) === c.toString().length){\r\n console.log(i,j);\r\n stop = true;\r\n break;\r\n }\r\n\r\n }\r\n if(stop) break;\r\n }\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n "}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c] = readLine().split(' ').map(Number);\r\n\r\n let xstart = '1';\r\n \r\n for(let i = 1 ; i < a; i++){\r\n xstart+= '0';\r\n }\r\n xstart = parseInt(xstart);\r\n let xend = '';\r\n for(let i = 0; i < a; i++){\r\n xend+= '9';\r\n }\r\n xend = parseInt(xend);\r\n\r\n let ystart = '1';\r\n for(let i = 1; i < b; i++){\r\n ystart += '0';\r\n }\r\n ystart = parseInt(ystart);\r\n\r\n let yend = '';\r\n for(let i = 0; i < b; i++){\r\n yend += '9';\r\n }\r\n yend = parseInt(yend);\r\n let stop = false;\r\n for(let i = xstart; i <= xend; i++){\r\n if(Number(i.toString().split('').pop()) === 0) continue;\r\n for(let j = ystart; j <= yend; j++){\r\n if(Number(j.toString().split('').pop()) === 0) continue;\r\n if(gcd(i,j) === c){\r\n console.log(i,j);\r\n stop = true;\r\n break;\r\n }\r\n }\r\n if(stop) break;\r\n }\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n "}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tvar g = Math.pow(10, c - 1);\r\n\t\tvar x = g;\r\n\t\tvar y = g;\r\n\t\twhile(x < Math.pow(10, a - 1)){\r\n\t\t\tx *= 2;\r\n\t\t}\r\n\t\twhile(y < Math.pow(10, b - 1)){\r\n\t\t\ty *= 2;\r\n\t\t}\r\n\t\tmyout(x + \" \" + y);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tvar g = Math.pow(10, c - 1);\r\n\t\tvar x = 1;\r\n\t\tvar y = 1;\r\n\t\twhile(x < Math.pow(10, a - 1)){\r\n\t\t\tx *= 2;\r\n\t\t}\r\n\t\twhile(y < Math.pow(10, b - 1)){\r\n\t\t\ty *= 2;\r\n\t\t}\r\n\t\tmyout(x + \" \" + y);\r\n\t}\r\n}\r\n"}], "src_uid": "04330cb392bcfd51d1acffd72c8004cb"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet b, k;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [b, k] = d.split(' ').map(Number);\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let odd = arr[arr.length - 1] % 2;\n\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] * b) % 2) {\n odd++;\n }\n }\n\n if (odd % 2) {\n console.log('odd');\n }\n else {\n console.log('even');\n }\n\n c++;\n});\n", "positive_code": [{"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var n = read.arrNumber(' ');\n var b = n[0];\n var k = n[1];\n\n var a = read.arrNumber(' ');\n\n var res = a[k - 1];\n var last = b;\n \n for(var i = k - 2; i >= 0; i--) {\n var number = a[i] * last;\n var str = number.toString();\n var y = +(str[str.length - 1]);\n var lastString = (last * b).toString();\n last = +lastString[lastString.length - 1];\n res += number;\n }\n print(res % 2 ? 'odd' : 'even');\n}());\n"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var n = read.arrNumber(' ');\n var b = n[0];\n var k = n[1];\n\n var a = read.arrNumber(' ');\n\n var res = a[k - 1];\n var last = b;\n \n for(var i = k - 2; i >= 0; i--) {\n var number = a[i] * last;\n var str = number.toString();\n var y = +(str[str.length - 1]);\n var lastString = (last * b).toString();\n last = +lastString[lastString.length - 1];\n res += number;\n }\n print(res % 2 ? 'odd' : 'even');\n}());"}], "negative_code": [{"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var n = read.arrNumber(' ');\n var b = n[0];\n var k = n[1];\n\n var a = read.arrNumber(' ');\n\n var res = 0;\n\n var hh = 0;\n var last = b;\n a.forEach(function(i){\n var str = (i * b).toString();\n var y = +(str[str.length - 1])\n res += y;\n last = y;\n hh++;\n });\n\n print(res % 2 ? 'odd' : 'even');\n}());"}], "src_uid": "ee105b664099808143a94a374d6d5daa"} {"source_code": "\"use strict\"; \r\n\r\n// import for reading input //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n} \r\n// //\r\nfunction main() {\r\n var t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n}\r\n\r\nfunction solution() {\r\n const n = +(readline());\r\n const arr = readline().split(' ').map((item) => +item);\r\n \r\n let counter = 0;\r\n for (let i = 0; i < n-1; i++) {\r\n let r = (i+1)%arr[i];\r\n let firstJ = (arr[i] - r > r) ? (i+1-2*r+arr[i]) : (i+1+2*(arr[i]-r));\r\n for (let j = firstJ-1; j < n; j += arr[i]) {\r\n if (arr[i]*arr[j] === i+j+2) counter++;\r\n }\r\n }\r\n console.log(counter);\r\n}\r\n\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let bool = [];\r\n let k = Math.ceil(Math.sqrt(n + n - 1));\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] <= k) bool[i] = true;\r\n else bool[i] = false;\r\n }\r\n let cnt = 0,\r\n obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n for (let j = 0; j < n; j++) {\r\n if (i === j) continue;\r\n let k = i + 1 + (j + 1);\r\n if (k === arr[i] * arr[j]) {\r\n let s1 = `${i + 1} ${j + 1}`;\r\n let s2 = `${j + 1} ${i + 1}`;\r\n if (!obj[s1] && !obj[s2]) cnt++;\r\n obj[s1] = 1;\r\n obj[s2] = 1;\r\n }\r\n }\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str, i) => {\r\n if (i % 2 === 1) {\r\n str = str.split(' ').map(str => parseInt(str));\r\n console.log(pleasantPairs(str));\r\n }\r\n });\r\n})\r\n\r\nconst pleasantPairs = (arr) => {\r\n let pairCount = 0;\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n let multiple = 1;\r\n let j = (arr[i] * multiple) - (i + 1) - 1;\r\n while (j < arr.length) {\r\n if ((arr[j] * arr[i]) === (i + j + 2) && i < j) {\r\n pairCount++;\r\n }\r\n multiple++;\r\n j = (arr[i] * multiple) - (i + 1) - 1;\r\n }\r\n }\r\n return pairCount;\r\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n let count = 0\n arr.forEach((a, i) => {\n i++\n const limit = Math.floor(2 * n / a)\n for (let j = 1; j <= limit; j++) {\n const p = a * j - i - 1\n if (p > i - 1 && arr[p] === j) count++\n }\n })\n return count\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tconst start = Math.ceil((2*i+1)/a[i])*a[i] - i;\r\n\t\t\tfor(j = start; j <= n; j += a[i]) {\r\n\t\t\t\tans += a[i] * a[j] == i + j;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n let nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n let count = 0;\r\n for(let i = 0; i < n; i++) {\r\n let rem = (i + 1) % a[i];\r\n let need = (a[i] - rem) % a[i];\r\n let delta = (a[i] + need - rem) % a[i];\r\n for(let j = 0; i + 1 + delta + a[i] * j <= n; j++) {\r\n let ind2 = i + 1 + delta + a[i] * j;\r\n if (ind2 == i + 1)\r\n continue;\r\n if (a[i] * a[ind2-1] === i + 1 + ind2)\r\n count++;\r\n }\r\n }\r\n console.log(count);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = +readline();\r\nfor (var tt = 0; tt < t; tt += 1) {\r\n var n = +readline();\r\n var arr = readline()\r\n .split(\" \")\r\n .map((num) => {\r\n return +num;\r\n });\r\n arr.unshift(0);\r\n var find = [];\r\n for (var k = 1; k <= n; k += 1) {\r\n var numToFind = 1;\r\n while (true) {\r\n var indexToFind = Math.abs(arr[k] * numToFind - k);\r\n if (indexToFind <= n) {\r\n if (indexToFind > k) find.push([numToFind, indexToFind]);\r\n } else {\r\n break;\r\n }\r\n numToFind += 1;\r\n }\r\n }\r\n var ans = 0;\r\n find.forEach((value) => {\r\n if (arr[value[1]] === value[0]) ans += 1;\r\n });\r\n print(ans);\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let bool = [];\r\n let k = Math.ceil(Math.sqrt(n + n - 1));\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] <= k) bool[i] = true;\r\n else bool[i] = false;\r\n }\r\n let cnt = 0,\r\n obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n for (let j = 0; j < n; j++) {\r\n let k = i + 1 + (j + 1);\r\n if (k === arr[i] * arr[j]) {\r\n let s1 = `${i + 1} ${j + 1}`;\r\n let s2 = `${j + 1} ${i + 1}`;\r\n if (!obj[s1] && !obj[s2]) cnt++;\r\n obj[s1] = 1;\r\n obj[s2] = 1;\r\n }\r\n }\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let bool = [];\r\n let k = Math.ceil(Math.sqrt(n));\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] <= k) bool[i] = true;\r\n else bool[i] = false;\r\n }\r\n let cnt = 0,\r\n obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n for (let j = 0; j < n; j++) {\r\n let k = i + 1 + (j + 1);\r\n if (k === arr[i] * arr[j]) {\r\n let s1 = `${i + 1} ${j + 1}`;\r\n let s2 = `${j + 1} ${i + 1}`;\r\n if (!obj[s1] && !obj[s2]) cnt++;\r\n obj[s1] = 1;\r\n obj[s2] = 1;\r\n }\r\n }\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let bool = [];\r\n let k = Math.ceil(Math.sqrt(n));\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] <= k) bool[i] = true;\r\n else bool[i] = false;\r\n }\r\n let cnt = 0,\r\n obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n for (let j = 0; j < n; j++) {\r\n let k = i + 1 + (j + 1);\r\n if (k === arr[i] * arr[j]) {\r\n if (!obj[i + j + 2]) cnt++;\r\n obj[i + j + 2] = 1;\r\n }\r\n }\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let bool = [];\r\n let k = Math.floor(Math.sqrt(n));\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] <= k) bool[i] = true;\r\n else bool[i] = false;\r\n }\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n for (let j = 0; j < n; j++) {\r\n let k = i + 1 + (j + 1);\r\n if (k === arr[i] * arr[j]) cnt++;\r\n }\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n let count = 0\n arr.forEach((a, i) => {\n i++\n const limit = Math.floor(2 * n / a)\n for (let j = 1; j <= limit; j++) {\n if (arr[a * j - i - 1] === j) count++\n }\n })\n return count / 2\n}\n"}], "src_uid": "0ce05499cd28f0825580ff48dae9e7a9"} {"source_code": "var n = readline();\nvar b=n;\nvar res = [];\nwhile (n--){\n res.push(Array(parseInt(readline())).fill(1))\n}\nfor(var i =0;i {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const result = Array(len).fill(1).join(\" \");\n console.log(result);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = new Array(N).fill(1);\n output[i] = myconv(list, 8);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n\t let n = data[i] * 1;\n\t let arr = Array(n).fill(1);\n\t arr = arr.join(' ');\n\t console.log(arr);\n\t i += 1;\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let t = parseInt(readline());\n //go go bro!!!\n while(t--) {\n let n = readint();\n while(n--) {\n write(1 + \" \");\n }\n write(\"\\n\");\n }\n \n}"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n\n for(let i = 0; i < N; i++) {\n process.stdout.write(N + \" \");\n }\n print(\"\");\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let ans = '';\n for(let i = 0; i < n; i++){\n ans += '1 ';\n }\n console.log(ans);\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r= n / 2 && a.length < n) {\n a.push(44);\n }\n\n console.log(a.join(\" \"));\n}\n\n"}], "negative_code": [{"source_code": "var n = readline();\nvar b=n;\nvar res = [];\nwhile (n--){\n res.push(Array(parseInt(readline())).fill(1))\n}\nfor(var i =0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let t = parseInt(readline());\n //go go bro!!!\n while(t--) {\n let n = readint();\n while(n--) {\n write(1 + \" \");\n }\n print('\\n');\n }\n \n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let res = [];\n res.push(1);\n res.push(3);\n let last = 1+2;\n for(let i = 2; i < n; i++){\n res.push(res[res.length-1]+res[res.length-2]+1);\n }\n\n let ans = '';\n for(let i of res)\n ans += `${i} `;\n console.log(ans);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let res = [];\n res.push(1);\n res.push(2);\n let last = 1+2;\n for(let i = 2; i < n; i++){\n res.push(res[res.length-1]+res[res.length-2]+1);\n }\n\n for(let i of res)\n console.log(i);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let res = [];\n res.push(1);\n res.push(2);\n let last = 1+2;\n for(let i = 2; i < n; i++){\n res.push(res[res.length-1]+res[res.length-2]+1);\n }\n\n let ans = '';\n for(let i of res)\n ans += `${i} `;\n console.log(ans);\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r cursor) {\n\t\tbreak;\n\t}\n\tif (right > cursor) {\n\t\tcursor = right;\n\t}\n}\n\nif (cursor >= m) {\n\tprint('YES');\n} else {\n\tprint('NO');\n}\n", "positive_code": [{"source_code": "var line = readline().split(' ');\nvar N = parseInt(line[0]);\nvar M = parseInt(line[1]);\nvar a = [], b=[];\n\nfor(var i = 0; i < N; i++) {\n\tvar line = readline().split(' ');\n\ta[i] = parseInt(line[0]);\n\tb[i] = parseInt(line[1]);\n}\n\nvar left = 0;\n\nfor(var i=0;ileft ){\n\t\tleft = b[i];\n\t}\n}\n\nif(M <= left){\n\tprint(\"YES\");\n}else{\n\tprint(\"NO\");\n}\n\n"}, {"source_code": "// write by lpy in 2017/12/21\n//title is Visting a Friend\n/*\n\tthe input of this argument\n*/\nvar arr = readline().split(\" \");\nvar n = Number(arr[0]);\nvar m = Number(arr[1]);\n\n\nfunction input_str(n){\n\t// var array = [[0,2],[2,4],[3,5]];\n\tvar array = new Array();\n\tfor(var i = 0; i < n;i++){\n\t\tarray[i] = new Array();\n\t\tvar str = readline().split(\" \");\n\t\tarray[i][0] = Number(str[0]);\n\t\tarray[i][1] = Number(str[1]);\n\t}\n\treturn array;\n}\n\nfunction f(n,m){// n is the number of input, m is the friend's house\n\tvar array = input_str(n);\n\tvar left = array[0][0],right = array[0][1];\n\t// console.log(left, right);\n\tvar result = true; \n\tfor(var i = 1; i < n; i++){\n\t\tvar a1 = left, b1 = right;\n\t\t// console.log(a1, b1);\n\t\tvar a2 = array[i][0], b2 = array[i][1];\n\t\tif(a1 <= a2){\n\t\t\tleft = a1;\n\t\t\tif(a2 <= b1){\n\t\t\t\tif(b1 <= b2){\n\t\t\t\t\tright = b2;\n\t\t\t\t}\n\t\t\t\telse right = b1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tleft = a2;\n\t\t\tif(a1 <= b2){\n\t\t\t\tif(b1 <= b2){\n\t\t\t\t\tright = b2;\n\t\t\t\t}\n\t\t\t\telse right = b1;\n\t\t\t}\n\t\t\telse result = false;\n\t\t}\n\t}\n\tvar ans;\n\tif(result===true){\n\t\tif(left === 0 && right === m)\n\t\t\tans = 'YES';\n\t\telse ans = 'NO';\n\t}\n\telse ans = 'NO';\n\treturn ans;\n}\nprint(f(n, m));\n// console.log(f(2,1));\n\n"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n if (x.a === y.a) {\n if (x.b > y.b) return 1;\n if (x.b < y.b) return -1;\n }\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n f = true;\n break;\n }\n }\n } else {\n break;\n }\n}\nif (f) {print('YES');} else {print('NO');}"}, {"source_code": "\nvar read = readline().split(\" \").map(Number);\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\nfunction getPt( loop, limit ){\n\t\t while( loop ){\n\t\t\t loop--;\n\t\t\t\tvar arr = readline().split(\" \").map(Number);\n\t\t\t\tvar x = arr[0];var y = arr[1];\n\t\t\t\tif ( x > lst ){\n\t\t\t\t\t reject = true;\n\t\t\t\t\t break;\n\t\t\t\t}\n\t\t\t\tif ( y > lst ){\n\t\t\t\t\t lst = y;\n\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t found = true;\n\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t}\n\t\t\t }\n\n\t\t }\n\t\t \n\t\t if(reject)\n\t\t\t\twrite(\"NO\\n\");\n\t\t if(found)\n\t\t\t\twrite(\"YES\\n\");\n\t\t if(!reject && !found)\n\t\t\t\twrite( lst == limit ? \"YES\" : \"NO\");\n}\n\ngetPt( loop, limit);\n"}, {"source_code": "// FUCK IT I FORGOT, VALUES IN ARRAY SHOULD\n// BE PARSEINT SO THAT I USED .map(Number);\nvar read = readline().split(\" \").map(Number);\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\ngetPt( loop, limit);\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = readline().split(\" \").map(Number);\n\t\t\t\t\t\t\t\tvar x = arr[0];var y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t reject = true;\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t\t\t write(\"NO\\n\");\n\t\t\t\t if(found)\n\t\t\t\t \t\t\t write(\"YES\\n\");\n\t\t\t\t if(!reject && !found){\n\t\t\t\t\t \t\t write( lst == limit ? \"YES\" : \"NO\");\n\t\t\t\t }\n}\n"}, {"source_code": "var x=readline().split(' ')\nn=Number(x[0])\nm=Number(x[1])\nA=[]\nB=[]\nfor (var i=0;i lst ){\n\t \t\t\t\t\t reject = true;\n\t\t\t\t\t\t \t break;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( y > lst )\n\t\t\t\t\t\t\t lst = y;\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t write(\"NO\\n\");\n\n\t\t\t\t return lst;\n}\n\nwrite(getPt(loop, limit));\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar lst = 0;\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tvar x = arr[0];\n\t\t\t\t\t\t\t\tvar y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst )\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\tif ( y > lst )\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\n\t\t\t\t }\n\n\t\t\t\t\t \t\t\t\t\tif(lst == limit)\n\t\t\t\t\t\t\t\t\t\t\t\t\t write(\"YES\\n\");\n\t\t\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t\t\t\t\t\twrite(\"NO\\n\");\n}\ngetPt( loop, limit);\n"}, {"source_code": "var read = readline().split(\" \").map(Number);\nvar loop = read[0];\nvar limit = read[1];\nvar lst = 0;\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = readline().split(\" \").map(Number);\n\t\t\t\t\t\t\t\tvar x = arr[0];\n\t\t\t\t\t\t\t\tvar y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst )\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\tif ( y > lst )\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\n\t\t\t\t }\n\n\t\t\t\t\t \t\t\t\t\tif(lst == limit)\n\t\t\t\t\t\t\t\t\t\t\t\t\t write(lst);\n\t\t\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t\t\t\t\t\twrite(lst);\n}\ngetPt( loop, limit);\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\nvar x;\nvar y;\ngetPt( loop, limit );\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tx = arr[0],y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t reject = true;\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t\t\t write(\"NO\\n\");\n\t\t\t\t if(found)\n\t\t\t\t \t\t\t write(\"YES\\n\");\n\t\t\t\t if(!reject && !found)\n\t\t\t\t\t\t\t write(lst = limit ? \"YES\" : \"NO\");\n}\n\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tx = arr[0],y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t reject = true;\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t\t\t write(\"NO\\n\");\n\t\t\t\t if(found)\n\t\t\t\t \t\t\t write(\"YES\\n\");\n\t\t\t\t if(!reject && !found)\n\t\t\t\t return lst;\n}\nvar result = getPt(loop, limit);\nwrite(result == limit ? \"YES\" : \"NO\");\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar lst = 0;\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tvar x = arr[0];\n\t\t\t\t\t\t\t\tvar y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst )\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\tif ( y > lst )\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\n\t\t\t\t }\n\n\t\t\t\t\t \t\t\t\t\tif(lst == limit)\n\t\t\t\t\t\t\t\t\t\t\t\t\t write(lst);\n\t\t\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t\t\t\t\t\twrite(lst);\n}\ngetPt( loop, limit);\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\ngetPt( loop, limit );\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tx = arr[0],y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t reject = true;\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t\t\t write(\"NO\\n\");\n\t\t\t\t if(found)\n\t\t\t\t \t\t\t write(\"YES\\n\");\n\t\t\t\t if(!reject && !found)\n\t\t\t\t\t\t\t write(lst = limit ? \"YES\" : \"NO\");\n}\n\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\nwhile( loop ){\n\t\t\t loop--;\n\t\t var arr = +readline().split(\" \");\n\t\t\t x = arr[0],y = arr[1];\n\t\t\t if ( x > lst ){\n\t\t\t\t \t\treject = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\tlst = y;\n\t\t\t\t\t\t\tif( lst == limit ){\n\t\t\t\t\t\t\t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t }\nif(reject)\n\t\t\twrite(\"NO\\n\");\nif(found)\n\t\t\t write(\"YES\\n\");\nif(!reject && !found)\n\t\t\t\t\t write(lst = limit ? \"YES\" : \"NO\");\n\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar lst = 0;\ngetPt( loop, limit);\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tvar x = arr[0];\n\t\t\t\t\t\t\t\tvar y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\n\t\t\t\t\t \t\t\t\t\tif(lst == limit)\n\t\t\t\t\t\t\t\t\t\t\t\t\t write(\"YES\\n\");\n\t\t\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t\t\t\t\t\twrite(\"NO\\n\");\n}\n"}, {"source_code": "var read = +readline().split(\" \");\nvar loop = read[0];\nvar limit = read[1];\nvar reject = false;\nvar found = false;\nvar lst = 0;\ngetPt( loop, limit);\nfunction getPt( loop, limit ){\n\t\t\t\t while( loop ){\n\t\t\t\t\t \t\t\tloop--;\n\t\t\t\t\t\t\t\tvar arr = +readline().split(\" \");\n\t\t\t\t\t\t\t\tvar x = arr[0];var y = arr[1];\n\t\t\t\t\t\t\t\tif ( x > lst ){\n\t\t\t\t\t\t\t\t\t\t\t reject = true;\n\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif ( y > lst ){\n\t\t\t\t\t\t\t\t\t\t\t lst = y;\n\t\t\t\t\t\t\t\t\t\t\t if( lst == limit ){\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t found = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t }\n\t\t\t\t if(reject)\n\t\t\t\t \t\t\t write(\"NO\\n\");\n\t\t\t\t if(found)\n\t\t\t\t \t\t\t write(\"YES\\n\");\n\t\t\t\t if(!reject && !found){\n\t\t\t\t\t \t\t\t\t\tif(lst == limit)\n\t\t\t\t\t\t\t\t\t\t\t\t\t write(\"YES\\n\");\n\t\t\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t\t\t\t\t\twrite(\"NO\\n\");\n\t\t\t\t }\n}\n"}, {"source_code": "var line = readline().split(' ');\nvar N = parseInt(line[0]);\nvar M = parseInt(line[1]);\nvar a = [], b=[];\n\nfor(var i = 0; i < N; i++) {\n\tvar line = readline().split(' ');\n\ta[i] = parseInt(line[0]);\n\tb[i] = parseInt(line[1]);\n}\n\nvar left = 0;\n\nfor(var i=0;i b[i]) {\n\t\t\t\tans = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif ((m >= a[i] && m <= b[i])) {\n\t\t\tans = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nif (ans) {\n\tprint('YES');\n} else {\n\tprint('NO');\n}"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n print('YES');\n }\n }\n }\n}\nprint('NO');"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n print('YES');\n }\n }\n } else {\n print('NO'); \n }\n}"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n if (x.a === y.a) {\n if (x.b > y.b) return 1;\n if (x.b < y.b) return -1;\n }\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n print('YES');\n break;\n }\n }\n } else {\n print('NO'); \n break;\n }\n}\nif (max < m) {print('NO');}"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n if (x.a === y.a) {\n if (x.b > y.b) return 1;\n if (x.b < y.b) return -1;\n }\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n print('YES');\n break;\n }\n }\n } else {\n print('NO'); \n break;\n }\n}"}, {"source_code": "one=readline();\nn=parseInt(one.split(' ')[0]);\nm=parseInt(one.split(' ')[1]);\nmas=[];\nfunction compareNumeric(x, y) {\n if (x.a > y.a) return 1;\n if (x.a < y.a) return -1;\n if (x.a === y.a) {\n if (x.b > y.b) return 1;\n if (x.b < y.b) return -1;\n }\n}\nfor(i=0;i max) {\n max = mas[i].b;\n if (max >= m) {\n print('YES');\n }\n }\n } else {\n print('NO'); \n }\n}"}, {"source_code": "// write by lpy in 2017/12/21\n//title is Visting a Friend\n/*\n\tthe input of this argument\n*/\nvar arr = readline().split(\" \");\nvar n = arr[0];\nvar m = arr[1];\n\n//var array = [[0,4],[2,6],[6,7]];\n\nfunction f(n,m){// n is the number of input, m is the friend's house\n\t\n\t//the [left,right]is existing range\n\tvar str = readline().split(\" \");\n\tvar left = str[0], right = str[1];\n\tvar result = true; \n\tfor(var i = 1; i < n; i++){\n\t\tvar array = readline().split(\" \");\n\t\tvar a1 = left, b1 = right;\n\t\t// var a2 = array[i][0], b2 = array[i][1];\n\t\tvar a2 = array[0],b2 = array[1];\n\t\tif(a1 <= a2){\n\t\t\tleft = a1;\n\t\t\tif(a2 <= b1){\n\t\t\t\tif(b1 <= b2){\n\t\t\t\t\tright = b2;\n\t\t\t\t}\n\t\t\t\telse right = b1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tleft = a2;\n\t\t\tif(a1 <= b2){\n\t\t\t\tif(b1 <= b2){\n\t\t\t\t\tright = b2;\n\t\t\t\t}\n\t\t\t\telse right = b1;\n\t\t\t}\n\t\t\telse result = false;\n\t\t}\n\t}\n\tvar ans;\n\tif(left === 0 && right === m)\n\t\tans = 'YES';\n\telse ans = 'NO';\n\treturn ans;\n}\nprint(f(n, m));\n// console.log(f(3,5));\n"}], "src_uid": "d646834d58c519d5e9c0545df2ca4be2"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({input: process.stdin})\n\nlet n, p, numLines = 0\nrl.on('line', line => {\n if (++numLines == 1) {\n n = parseInt(line)\n } else {\n (p = line.split(' ').map(x => parseInt(x))).unshift(0)\n }\n}).on('close', () => {\n let caughtStudent = (id) => {\n let visited = []\n let dfs = u => {\n visited[u] = true\n if (!visited[p[u]]) {\n return dfs(p[u])\n } else {\n return p[u]\n }\n }\n return dfs(id)\n }\n process.stdout.write(`${[...Array(n + 1).keys()].slice(1).map(x => caughtStudent(x)).join(' ')}\\n`)\n})\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const reported = is.nextArray(Number);\n reported.unshift(null);\n const container = new Array(n + 1);\n let current;\n for (let i = 1; i <= n; i += 1) {\n container.fill(0);\n current = i;\n container[current] += 1;\n while (container[current] !== 2) {\n current = reported[current];\n container[current] += 1;\n }\n process.stdout.write(`${current.toString()} `);\n }\n console.log();\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var n = readline();\nvar students = readline().split(' ');\nvar rst = [];\nfunction solve() {\n for (var m = 0; m < students.length; m++) {\n var set = {};\n var current = m;\n while (true) {\n set[current] = set[current] ? set[current] + 1 : 1;\n if (set[current] === 2) {\n rst.push(current + 1);\n break;\n }\n current = students[current] - 1;\n }\n }\n return rst;\n}\nprint(solve().join(' '));\n// console.log(solve())"}, {"source_code": "var visited = {};\n\nfunction dfs(cur) {\n visited[cur] = true;\n var stu = students[cur] - 1;\n return visited[stu] ? stu + 1 : dfs(stu);\n}\n\nfunction solve() {\n var res = [];\n for (var i = 0; i < n; i++) {\n visited = {};\n res[i] = dfs(i);\n }\n return res;\n}\n\nvar n = readline();\nvar students = readline().split(' ');\nprint(solve().join(' '));\n"}, {"source_code": "var cnt = {};\n\nfunction dfs(cur) {\n if (cnt[cur] > 1) {\n return cur;\n }\n cnt[cur] = cnt[cur] ? 2 : 1;\n return dfs(students[cur - 1]);\n}\n\nfunction solve() {\n var res = [];\n for (var i = 0; i 1) {\n return cur;\n }\n cnt[cur] = cnt[cur] ? 2 : 1;\n return dfs(students[cur - 1]);\n}\n\nfunction solve() {\n var res = [];\n for (var i = 0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] =='*' || test[i][j] == word[j]) ) break;\n if(word[j]=='*' && word.includes(test[i][j])) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n \n var letterknown = [];\n \n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n \n for (var i = 0; i < m; i++){\n var temp3 = 1;\n for (var j = 0; j < n; j++){\n if ((array1[i][j] != revString[j]) && (revString[j] != '*')) {\n temp3 = 0;\n }\n }\n if (temp3 == 1) {\n arr.push(array1[i]);\n }\n }\n var arr1 = [];\n for (var p = 0; p< arr.length; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (arr[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr1.push(arr[p]);\n }\n }\n \n var count = 0;\n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr1.length; j++){\n if (arr1[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n \n \n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j])) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n // console.log(n);\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j]) ) break;\n if(word[j]=='*' && !(Alpha.includes(test[i][j]))) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] =='*' || test[i][j] == word[j]) ) break;\n // if(word[j]=='*' && !(Alpha.includes(test[i][j]))) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j]) || !(Alpha.includes(test[i][j]))) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j]) ) break;\n // if(word[j]=='*' && !(Alpha.includes(test[i][j]))) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j])) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\nfunction words(word,test) {\n // input = input.split(/\\n/)\n //var word = ['a', '*', '*', 'e', '*', 'd'];\n // var test = [['a', 'b', 'c', 'e', 'z', 'd'],\n // ['a', 'c', 'b', 'e', 'w', 'd'],\n // ['a', 'b', 'b', 'e', 'c', 'd']];\n var Alpha = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];\n var n = 0;\n var test_1 = [];\n Alpha = Alpha.filter(function (value) { return !word.includes(value) });\n for (var i = 0; i < test.length; i++) {\n for (var j = 0; j < word.length; j++) {\n if (!(word[j] = '*' || test[i][j] == word[j])) break;\n if(j==word.length-1) test_1.push(test[i]);\n }\n }\n for (var k=0; k < Alpha.length; k++) {\n for (var g=0; g < test_1.length; g++) {\n if (!(test_1[g].includes(Alpha[k]))) break;\n if (g == test_1.length-1) n++;\n }\n }\n console.log(n);\n return n;\n }\n\nfunction main(){\n var word = inputString[1]\n word = word.split('');\n // console.log(word);\n var test=[];\n var ab;\n for(var g=3;g {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length==nonrev)) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n var temp1 = 1;\n\n for (var k = 0; k < letterknown.length; k++) {\n for (var j = 0; j < n; j++) {\n if (arr[i][j] != letterknown[k]) {\n temp1 = 0;\n }\n }\n }\n count += temp1;\n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(m=nonrev)) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(m>=nonrev)) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n for (var i = 0; i < arr.length; i++){\n var temp1 = 1;\n \n for (var k = 0; k < letterknown.length; k++) {\n for (var j = 0; j < n; j++) {\n if (arr[i][j] != letterknown[k]) {\n temp1 = 0;\n }\n }\n }\n count += temp1;\n }\n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n \n var letterknown = [];\n \n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n \n for (var i = 0; i < m; i++){\n var temp3 = 1;\n for (var j = 0; j < n; j++){\n if ((array1[i][j] != revString[j]) && (revString[j] != '*')) {\n temp3 = 0;\n }\n }\n if (temp3 == 1) {\n arr.push(array1[i]);\n }\n }\n var arr1 = [];\n for (var p = 0; p< arr.length; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (arr[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr1.push(array1[p]);\n }\n }\n \n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr1.length; j++){\n if (arr1[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n \n \n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\n//const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var count = 0;\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < m; j++){\n if (array1[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* var leftletters = letterknown.length;\n if (nonrev < leftletters) {\n return ((m*nonrev)-leftletters);\n }\n else {\n return leftletters;\n}*/\n return count;\n \n}\n\nfunction main() {\n //const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n\n // ws.write(result + \"\\n\");\n // ws.end();\n console.log(result + \"\\n\");\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length>=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }*/\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length==nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(m<=nonrev)) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount = crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* var leftletters = letterknown.length;\n if (nonrev < leftletters) {\n return ((m*nonrev)-leftletters);\n }\n else {\n return leftletters;\n}*/\n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length>=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }*/\n if (n == 50 && m == 1000 && count ==0) {\n return 6;\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length>=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }*/\n if (n == 50 && m == 1000) {\n return 6;\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(m==nonrev)) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* var leftletters = letterknown.length;\n if (nonrev < leftletters) {\n return ((m*nonrev)-leftletters);\n }\n else {\n return leftletters;\n}*/\n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if (temp1 == nonrev) {\n count++;\n }\n }\n \n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n \n var letterknown = [];\n \n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n \n for (var i = 0; i < m; i++){\n var temp3 = 1;\n for (var j = 0; j < n; j++){\n if ((array1[i][j] != revString[j]) && (revString[j] != '*')) {\n temp3 = 0;\n }\n }\n if (temp3 == 1) {\n arr.push(array1[i]);\n }\n }\n var arr1 = [];\n for (var p = 0; p< arr.length; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (arr[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr1.push(arr[p]);\n }\n }\n \n var count = 0;\n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr1.length; j++){\n if (arr1[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n \n \n \n return arr1;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length>=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n /* if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length>=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }*/\n if (n == 50 && m == 1000 && count==0) {\n return 6;\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n \n var letterknown = [];\n \n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount <= crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n \n \n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// Complete the saveThePrisoner function below.\nfunction polysgame(n,revString,m,array1) {\n var nonrev = 0;\n for (var i = 0; i < revString.length; i++){\n if (revString[i] == '*') {\n nonrev++;\n } \n }\n var crev = revString.length -nonrev;\n var len = 0;\n var letterknown = [];\n /* letterknown.push(array1[0]);\n letterknown.push(array1[1]);*/\n\n var letrev = [];\n \n for (var j = 0; j < n; j++) {\n if ((letrev.includes(revString[j]) == 0)&&(revString[j]!='*')) {\n letrev.push(revString[j]);\n }\n }\n \n\n\n for (var i = 0; i < m; i++){\n for (var j = 0; j < n; j++) {\n if (letterknown.includes(array1[i][j]) == 0) {\n letterknown.push(array1[i][j]);\n }\n }\n }\n \n for (var i = 0; i < revString.length; i++){\n for (var j = 0; j < letterknown.length; j++){\n if (letterknown[j] == revString[i]) {\n letterknown.splice(j, 1);\n }\n }\n }\n var arr = [];\n for (var p = 0; p< m; p++){\n var mcount = 0;\n for (var q = 0; q < n; q++){\n for (var r = 0; r < letrev.length; r++) {\n if (array1[p][q] == letrev[r]) {\n mcount++;\n }\n }\n }\n if (mcount == crev) {\n arr.push(array1[p]);\n }\n }\n\n var count = 0;\n\n \n\n for (var i = 0; i < letterknown.length; i++){\n var temp = 1;\n for (var j = 0; j < arr.length; j++){\n if (arr[j].includes(letterknown[i]) == 0) {\n temp = 0;\n }\n }\n count += temp;\n }\n if (count == 0) {\n var tcount = 0;\n for (var i = 0; i < arr.length; i++) {\n \n\n for (var k = 0; k < letterknown.length; k++) {\n var temp1 = 0;\n for (var j = 0; j < n; j++) {\n if ((arr[i][j] == letterknown[k])) {\n temp1++;\n }\n }\n if ((temp1 == nonrev)&&(arr.length >=nonrev)) {\n tcount++;\n }\n }\n \n }\n if (tcount == arr.length) {\n count += tcount;\n }\n }\n \n return count;\n \n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const n = parseInt(readLine(), 10);\n const revString = readLine();\n const m = parseInt(readLine(), 10);\n var array1 = [];\n for (var mItr = 0; mItr < m; mItr++){\n array1.push(readLine());\n }\n\n /* for (let tItr = 0; tItr < t; tItr++) {\n const nms = readLine().split(' ');\n\n const n = parseInt(nms[0], 10);\n\n const m = parseInt(nms[1], 10);\n\n const s = parseInt(nms[2], 10);\n\n \n }*/\n let result = polysgame(n,revString,m,array1);\n console.log(result + \"\\n\");\n // ws.write(result + \"\\n\");\n // ws.end();\n}\n"}], "src_uid": "02b0ffb0045fc0a2c8613c8ef58ed2c8"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, a, b, x)=>{\n const moveCost = (x1, x2) => {\n return BigInt(a) * BigInt(Math.abs(x2 - x1));\n }\n const conquerCost = (x1, x2) => {\n return BigInt(b) * BigInt(Math.abs(x2 - x1));\n }\n let cost = BigInt(0);\n for (let i = 0; i < n; i++) {\n cost += conquerCost(0, x[i]);\n }\n let pos = 0;\n for (let i = 0; i < n - 1; i++) {\n let mv = moveCost(pos, x[i]);\n let ptsRight = BigInt(n - i - 1);\n let reduction = ptsRight * conquerCost(pos, x[i]);\n if (cost - reduction + mv <= cost) {\n pos = x[i];\n cost = cost - reduction + mv;\n }\n }\n return cost;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, a, b] = ra();\n let x = ra();\n console.log(`${calc(n, a, b, x)}`);\n }\n}\n\n\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a, b, data) {\r\n let sum = 0,\r\n pre = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n const t = data[i];\r\n sum += (t - pre) * b;\r\n const x = n - i - 1;\r\n\r\n if (a <= x * b) {\r\n sum += a * (t - pre);\r\n pre = t;\r\n }\r\n }\r\n\r\n console.log(sum);\r\n}\r\n/**\r\n * 100001\r\n * 111110\r\n * 000000 000101\r\n * 111110 111110\r\n *\r\n * 101100\r\n * 110011\r\n * 001000\r\n * 111111\r\n * 000001\r\n * 111111\r\n *\r\n * 0110000\r\n * 0001111\r\n * 1111000\r\n * 0000011\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n * 0000000\r\n * 1111110\r\n *\r\n *\r\n * 101111001100\r\n * 110000110011\r\n * 000111001100\r\n * 111100110011\r\n * 000001001100\r\n * 111111110011\r\n *\r\n */\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, a, b] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, a, b, data);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, a, b, x)=>{\n let A = BigInt(a)\n let B = BigInt(b)\n let conc = new Set();\n let moved = 0;\n let total_sum = BigInt(0)\n\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, a, b] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, a, b, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, a, b, arr) {\n // const suffix = []\n // for (let i = arr.length - 1; i >= 0; i--) {\n // const now = arr[i] - arr[n - 1]\n // suffix[i] = i === arr.length - 1 ? now : now + suffix[i + 1]\n // }\n //\n let ans = 0\n let c = 0\n for (let i = 0; i < n; i++) {\n const x = arr[i]\n const p = arr[i - 1] || 0\n const p1 = a\n const p2 = (n - i) * b\n const c1 = a * (p - c) + b * (x - p)\n const c2 = b * (x - c)\n if (p1 <= p2) {\n // if (c1 <= c2) {\n c = p\n ans += c1\n } else {\n ans += c2\n }\n }\n return ans\n}\n"}], "negative_code": [], "src_uid": "ce2b12f1d7c0388c39fee52f5410b94b"} {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nvar r = -1;\nvar l = -1;\nvar z = +s[s.length-1];\nfor(var i = 0; i < s.length; i++) {\n var v = +s[i];\n if(v%2==0) {\n if(vz) r = i;\n }\n}\n\nif(r==-1 && l==-1) return print(-1);\nvar ind = l!=-1?l:r;\ns[s.length-1] = s[ind];\ns[ind] = z;\nprint(s.join(\"\"));\n\n})();\n", "positive_code": [{"source_code": "var n = readline().split( \"\" ).map( digit => parseInt( digit, 10 ) );\nvar answer = -1;\nvar optimalEven;\nvar swapOdd = n[ n.length - 1 ];\nfor ( var i = 0; i < n.length - 1; ++i ) {\n var digit = n[i];\n if ( digit % 2 === 0 ) {\n optimalEven = i;\n if ( digit < swapOdd ) {\n break;\n }\n }\n};\nif ( typeof optimalEven !== \"undefined\" ) {\n n[ n.length - 1 ] = n[ optimalEven ];\n n[ optimalEven ] = swapOdd;\n answer = n.join( \"\" );\n}\nprint( answer );"}, {"source_code": "var x = readline();\n\nvar last = x[x.length - 1];\nvar lastEven, swap, res;\nfor(var i = 0; i < x.length; i++){\n if(x[i] % 2 == 0){\n lastEven = i;\n if (x[i] < last){\n res = x.slice(0, i) + last + x.slice(i + 1, -1) + x[i];\n break;\n }\n }\n}\n\nif (res){\n print(res);\n}\nelse{\n if(lastEven != undefined){\n res = x.slice(0, lastEven) + last + x.slice(lastEven + 1, -1) + x[lastEven];\n print(res);\n }\n else{\n print(-1);\n }\n}\n"}, {"source_code": "const mainFunction = (lines) => {\n let n = lines[0].split(\"\")\n for (let i = 0; i < n.length - 1; i++) {\n if (+n[i] % 2 === 0 && +n[n.length - 1] > +n[i]) {\n [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]\n console.log(n.join(\"\"))\n return 0\n }\n }\n for (let i = n.length; i >= 0; i--) {\n if (+n[i] % 2 === 0 && +n[n.length - 1] < +n[i]) {\n [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]\n console.log(n.join(\"\"))\n return 0\n }\n }\n console.log(-1)\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "var input = readline();\nvar indexToSwapWith = -1;\nvar inputLength = input.length;\nfor (var i =0; i< inputLength; i++) {\n\tif(input [i] % 2 === 0 ) {\n\t\tindexToSwapWith = i;\n\t\tif(input[i] < input[inputLength - 1]) {\n\t\t\tbreak;\n\t\t}\n\t}\t\n}\n\nif(indexToSwapWith === -1 ) {\n print (-1);\n} else {\n var temp = input[indexToSwapWith];\n print(replaceChars(replaceChars(input, indexToSwapWith, input[inputLength - 1]), inputLength -1, temp));\n}\n\nfunction replaceChars (input, index, newValue) {\n return input.substring(0, index) + newValue + input.substring(index + 1);\n} "}, {"source_code": "function main() {\n var s = next();\n\n var i, d;\n var last = s.charAt(s.length - 1) - '0';\n\n for (i = 0; i < s.length; i++) {\n d = s.charAt(i) - '0';\n if (d % 2 === 0 && d < last) {\n print(s.substr(0, i) + s.substr(s.length - 1, 1) + s.substr(i + 1, s.length - i - 2) + s.substr(i, 1));\n return;\n }\n }\n\n for (i = s.length - 1; i >= 0; i--) {\n d = s.charAt(i) - '0';\n if (d % 2 === 0) {\n print(s.substr(0, i) + s.substr(s.length - 1, 1) + s.substr(i + 1, s.length - i - 2) + s.substr(i, 1));\n return;\n }\n }\n\n print(-1);\n}\n\n// auxiliary code\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(' ');\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nmain();\n"}, {"source_code": "\nvar debug = false;\n\nfunction main(lineArr) {\n var lineNum = 0;\n function readln() {\n return debug? lineArr[lineNum++] : readline();\n }\n function readints() {\n return readln().split(' ').map(function(x) {\n return parseInt(x)\n })\n }\n function println(data) {\n debug? console.log(data) : print(data);\n }\n\n //***************************************\n function swap(i, j, line) {\n // lol no swap function\n var c = line[i];\n line[i] = line[j];\n line[j] = c;\n }\n var line = readln().split('');\n var rightMostEven = -1;\n var leftMostEvenLess = -1;\n for (var i = 0; i < line.length; i++){\n if (parseInt(line[i]) % 2 == 0) {\n rightMostEven = i;\n if (leftMostEvenLess == -1 &&\n line[i] < line[line.length - 1])\n leftMostEvenLess = i;\n }\n }\n if (rightMostEven == -1) {\n println(-1);\n return;\n } else if (leftMostEvenLess == -1) {\n swap(line.length - 1, rightMostEven, line);\n } else {\n swap(line.length - 1, leftMostEvenLess, line)\n }\n println(line.join(''));\n\n}\n\nif (debug) {\n fs = require('fs');\n var fn = '/Users/zisakadze/Projects/codeforces/js/input.txt'\n fs.readFile(fn, 'utf8', function (err, data) {\n if (err) {\n return console.log(err);\n }\n main(data.split(\"\\n\"));\n });\n} else {\n main();\n}\n"}], "negative_code": [{"source_code": "const mainFunction = (lines) => {\n let n = lines[0].split(\"\")\n for (let i = 0; i < n.length - 1; i++) {\n if (+n[i] % 2 === 0 && +n[n.length - 1] > +n[i]) {\n [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]\n console.log(n.join(\"\"))\n return 0\n }\n }\n for (let i = 0; i < n.length - 1; i++) {\n if (+n[i] % 2 === 0 && +n[n.length - 1] < +n[i]) {\n [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]\n console.log(n.join(\"\"))\n return 0\n }\n }\n console.log(-1)\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "var input = readline();\nvar indexToSwapWith = -1;\nvar inputLength = input.length;\nfor (var i =0; i< inputLength; i++) {\n\tif(input [i] % 2 === 0 ) {\n\t\tindexToSwapWith = i;\n\t\tif(input[i] < input[inputLength - 1]) {\n\t\t\tbreak;\n\t\t}\n\t}\t\n}\nvar temp = input[indexToSwapWith]\nprint(replaceChars(replaceChars(input, indexToSwapWith, input[inputLength - 1]), inputLength -1, temp));\n\nfunction replaceChars (input, index, newValue) {\n return input.substring(0, index) + newValue + input.substring(index + 1);\n}"}, {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nvar r = -1;\nvar l = -1;\nvar z = +s[s.length-1];\nfor(var i = 0; i < s.length; i++) {\n var v = +s[i];\n if(v%2==0) {\n if(vz) r = i;\n }\n}\n\nif(r==-1 && l==-1) return print()-1;\nvar ind = r==-1?l:r;\ns[s.length-1] = s[ind];\ns[ind] = z;\nprint(s.join());\n\n})();\n"}, {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nfor(var i = 0; i < s.length; i++) {\n if(parseInt(s[i])%2==0 && parseInt(s[i])>parseInt(s[s.length-1])) {\n var t = s[s.length-1];\n s[s.length-1] = s[i];\n s[i] = t;\n return print(s.join(\"\"));\n }\n}\nprint(-1);\n\n})();\n"}, {"source_code": "var s = readline().split(\"\");\n\nfor(var i = 0; i < s.length; i++) {\n if(parseInt(s[i])%2==0) {\n var t = s[s.length-1];\n s[s.length-1] = s[i];\n s[i] = t;\n print(s.join(\"\"));\n }\n}\nprint(-1);\n"}, {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nfor(var i = 0; i < s.length; i++) {\n if(parseInt(s[i])%2==0) {\n var t = s[s.length-1];\n s[s.length-1] = s[i];\n s[i] = t;\n return print(s.join(\"\"));\n }\n}\nprint(-1);\n\n})();\n"}, {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nvar r = -1;\nvar l = -1;\nvar z = +s[s.length-1];\nfor(var i = 0; i < s.length; i++) {\n var v = +s[i];\n if(v%2==0) {\n if(vz) r = i;\n }\n}\n\nif(r==-1 && l==-1) return print()-1;\nvar ind = r==-1?l:r;\ns[s.length-1] = s[ind];\ns[ind] = z;\nprint(s.join(\"\"));\n\n})();\n"}, {"source_code": "(function() {\n\nvar s = readline().split(\"\");\n\nfor(var i = 0; i < s.length; i++) {\n if(parseInt(s[i])%2==0 && parseInt(s[i])z) r = i;\n }\n}\n\nif(r==-1 && l==-1) return print(-1);\nvar ind = r==-1?l:r;\ns[s.length-1] = s[ind];\ns[ind] = z;\nprint(s.join(\"\"));\n\n})();\n"}, {"source_code": "var n = readline().split( \"\" ).map( digit => parseInt( digit, 10 ) );\nvar evens = n.filter( digit => digit % 2 === 0 );\nvar answer = -1;\nif ( evens.length ) {\n var minEven = Math.min( ...evens );\n var oddToSwap = n[ n.length - 1 ];\n var minEvenToSwapIndex;\n if ( oddToSwap > minEven ) {\n // To maximaze result swap leftmost occurence of minEven.\n minEvenToSwapIndex = n.indexOf( minEven );\n } else {\n // To maximize result swap rightmost occurence of minEven.\n minEvenToSwapIndex = n.lastIndexOf( minEven );\n }\n n[ n.length - 1 ] = minEven;\n n[ minEvenToSwapIndex ] = oddToSwap;\n answer = n.join( \"\" );\n}\nprint( answer );\n"}, {"source_code": "var n = readline().split( \"\" ).map( digit => parseInt( digit, 10 ) );\nvar answer = -1;\nvar optimalEven;\nvar swapOdd = n[ n.length - 1 ];\nfor ( var i = 0, digit; digit = n[ i ]; ++i ) {\n if ( digit % 2 === 0 ) {\n if ( digit < swapOdd || i === n.length - 2 ) {\n optimalEven = i;\n break;\n }\n }\n};\nif ( typeof optimalEven !== \"undefined\" ) {\n n[ n.length - 1 ] = n[ optimalEven ];\n n[ optimalEven ] = swapOdd;\n answer = n.join( \"\" );\n}\nprint( answer );"}, {"source_code": "var n = readline().split( \"\" ).map( digit => parseInt( digit, 10 ) );\nvar minEven = Math.min( ...n.filter( digit => digit % 2 === 0 ) );\nvar swapOdd = n[ n.length - 1 ];\nif ( swapOdd > minEven ) {\n // To maximaze result swap leftmost occurence of minEven.\n n[ n.indexOf( minEven ) ] = swapOdd;\n} else {\n // To maximize result swap rightmost occurence of minEven.\n n[ n.lastIndexOf( minEven ) ] = swapOdd;\n}\nn[ n.length - 1 ] = minEven;\nprint( n.join( \"\" ) );\n"}, {"source_code": "var n = readline().split( \"\" ).map( digit => parseInt( digit, 10 ) );\nvar answer = -1;\nvar optimalEven;\nvar swapOdd = n[ n.length - 1 ];\nfor ( var i = 0, digit; digit = n[ i ]; ++i ) {\n if ( digit % 2 === 0 ) {\n optimalEven = i\n if ( digit < swapOdd ) {\n break;\n }\n }\n};\nif ( typeof optimalEven !== \"undefined\" ) {\n n[ n.length - 1 ] = n[ optimalEven ];\n n[ optimalEven ] = swapOdd;\n answer = n.join( \"\" );\n}\nprint( answer );"}], "src_uid": "bc375e27bd52f413216aaecc674366f8"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = readline();\r\n let s = readline();\r\n let t = readline();\r\n if (Stringo(s, t)) print(\"YES\");\r\n else print(\"NO\");\r\n }\r\n}\r\nfunction Stringo(s, t) {\r\n let i = 0;\r\n let j = 0;\r\n while (i < s.length || j < t.length) {\r\n while (s[i] == \"b\") i++;\r\n while (t[j] == \"b\") j++;\r\n if ((i == s.length || j == s.length) && i != j) return false;\r\n if (s[i] !== t[j]) return false;\r\n if (s[i] == \"a\" && i > j) return false;\r\n if (s[i] == \"c\" && i < j) return false;\r\n i++;\r\n j++;\r\n }\r\n return true;\r\n}", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = readNum();\r\n let s = readLine();\r\n let t = readLine();\r\n let res = true;\r\n let v1 = [], v2 = [];\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] !== \"b\") {\r\n v1.push([i, s[i]])\r\n }\r\n if (t[i] !== \"b\") {\r\n v2.push([i, t[i]])\r\n }\r\n }\r\n if (v1.length != v2.length) {\r\n res = false;\r\n } else {\r\n for (let i = 0; i < v1.length; i++) {\r\n if (v1[i][1] == v2[i][1] && v1[i][1] == \"a\" && v1[i][0] > v2[i][0]) {\r\n res = false;\r\n }\r\n if (v1[i][1] == v2[i][1] && v1[i][1] == \"c\" && v1[i][0] < v2[i][0]) {\r\n res = false;\r\n }else if(v1[i][1] != v2[i][1]){\r\n res = false;\r\n }\r\n }\r\n }\r\n\r\n return res ? \"YES\" : \"NO\";\r\n}\r\nfunction rearArr() {\r\n return readLine().split(\" \");\r\n}\r\nfunction readNum() {\r\n return parseInt(readLine());\r\n}"}, {"source_code": "'use strict';\r\n\r\nasync function solve(n, a, b) {\r\n let sa = 0,\r\n sb = 0,\r\n sc = 0,\r\n sa1 = 0,\r\n sb1 = 0,\r\n sc1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 'a') sa++;else if (a[i] === 'b') sb++;else sc++;\r\n if (b[i] === 'a') sa1++;else if (b[i] === 'b') sb1++;else sc1++;\r\n if (sc > sc1 || sa1 > sa) return 'NO';\r\n }\r\n if (sa !== sa1 || sb !== sb1 || sc !== sc1) return 'NO';\r\n {\r\n let sa = '',\r\n sb = '';\r\n for (let ch of a) {\r\n if (ch !== 'b') sa += ch;\r\n }\r\n for (let ch of b) {\r\n if (ch !== 'b') sb += ch;\r\n }\r\n return sa === sb ? 'YES' : 'NO';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = await read();\r\n const b = await read();\r\n res.push(await solve(n, a, b));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nclass INPUT {\r\n\tconstructor() {\r\n\t\tthis.input = '';\r\n\t\tthis.curLine = 0;\r\n\t}\r\n\r\n\tappend(str) {\r\n\t\tthis.input += str;\r\n\t}\r\n\r\n\tprepare() {\r\n\t\tthis.input = this.input.split('\\n').map((str) => str.trim());\r\n\t}\r\n\r\n\treadLine() {\r\n\t\treturn this.input[this.curLine++];\r\n\t}\r\n\r\n\treadInts() {\r\n\t\treturn this.readLine()\r\n\t\t\t.split(' ')\r\n\t\t\t.map((x) => parseInt(x, 10));\r\n\t}\r\n}\r\n\r\nconst input = new INPUT();\r\n\r\nprocess.stdin.on('data', (str) => {\r\n\tinput.append(str);\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n\tinput.prepare();\r\n\tmain();\r\n});\r\n\r\nfunction solve() {\r\n\tconst [n] = input.readInts();\r\n\tlet a = input.readLine();\r\n\tlet b = input.readLine();\r\n\r\n\tconst L = [];\r\n\tconst R = [];\r\n\tconst M = [];\r\n\tlet p = 0;\r\n\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (a[i] === 'c') {\r\n\t\t\tp = i + 1;\r\n\t\t} else if (a[i] === 'b') {\r\n\t\t\tL.push(p);\r\n\t\t}\r\n\t}\r\n\r\n\tp = n - 1;\r\n\r\n\tfor (let i = n - 1; i >= 0; i--) {\r\n\t\tif (a[i] === 'a') {\r\n\t\t\tp = i - 1;\r\n\t\t} else if (a[i] === 'b') {\r\n\t\t\tR.push(p);\r\n\t\t}\r\n\t}\r\n\r\n\tR.reverse();\r\n\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (b[i] === 'b') {\r\n\t\t\tM.push(i);\r\n\t\t}\r\n\t}\r\n\r\n\t// console.log('L', L);\r\n\t// console.log('M', M);\r\n\t// console.log('R', R);\r\n\r\n\tp = 0;\r\n\r\n\tif (M.length != L.length) {\r\n\t\tconsole.log('NO');\r\n\t\treturn;\r\n\t}\r\n\r\n\tfor (let i = 0; i < M.length; i++) {\r\n\t\twhile (p < L.length && M[i] < L[p]) {\r\n\t\t\tp++;\r\n\t\t}\r\n\r\n\t\tif (p == L.length || M[i] > R[p]) {\r\n\t\t\tconsole.log('NO');\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tp++;\r\n\t}\r\n\r\n\tif (\r\n\t\ta\r\n\t\t\t.split('')\r\n\t\t\t.filter((x) => x != 'b')\r\n\t\t\t.join('') !=\r\n\t\tb\r\n\t\t\t.split('')\r\n\t\t\t.filter((x) => x != 'b')\r\n\t\t\t.join('')\r\n\t) {\r\n\t\tconsole.log('NO');\r\n\t\treturn;\r\n\t}\r\n\r\n\tconsole.log('YES');\r\n}\r\n\r\nfunction main() {\r\n\tlet [T] = input.readInts();\r\n\r\n\twhile (T--) {\r\n\t\tsolve();\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = readline();\r\n let s = readline();\r\n let t = readline();\r\n if (Stringo(s, t)) print(\"YES\");\r\n else print(\"NO\");\r\n }\r\n}\r\nfunction Stringo(s, t) {\r\n let i = 0;\r\n let j = 0;\r\n while (i < s.length && j < t.length) {\r\n while (s[i] == \"b\") i++;\r\n while (t[j] == \"b\") j++;\r\n if ((i == s.length || j == s.length) && i != j) return false;\r\n if (s[i] !== t[j]) return false;\r\n if (s[i] == \"a\" && i > j) return false;\r\n if (s[i] == \"c\" && i < j) return false;\r\n i++;\r\n j++;\r\n }\r\n return true;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n readline();\r\n let s = readline();\r\n let t = readline();\r\n if (Stringo(s, t, 0)) print(\"YES\");\r\n else print(\"NO\");\r\n }\r\n}\r\n\r\nfunction Stringo(s, t) {\r\n let i = 0;\r\n let j = 0;\r\n while (i < s.length && j < t.length) {\r\n while (s[i] == \"b\") i++;\r\n while (t[j] == \"b\") j++;\r\n if (s[i] !== t[j]) return false;\r\n if (s[i] == \"a\" && i > j) return false;\r\n if (s[i] == \"c\" && i < j) return false;\r\n i++;\r\n j++;\r\n }\r\n return true;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = readNum();\r\n let s = readLine();\r\n let t = readLine();\r\n let res = true;\r\n let v1 = [], v2 = [];\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] !== \"b\") {\r\n v1.push([i, s[i]])\r\n }\r\n if (t[i] !== \"b\") {\r\n v2.push([i, t[i]])\r\n }\r\n }\r\n if (v1.length != v2.length) {\r\n res = false;\r\n } else {\r\n for (let i = 0; i < v1.length; i++) {\r\n if (v1[i][1] == v2[i][1] && v1[i][1] == \"a\" && v1[i][0] > v2[i][0]) {\r\n res = false;\r\n break;\r\n }\r\n if (v1[i][1] == v2[i][1] && v1[i][1] == \"c\" && v1[i][0] < v2[i][0]) {\r\n res = false;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return res ? \"YES\" : \"NO\";\r\n}\r\nfunction rearArr() {\r\n return readLine().split(\" \");\r\n}\r\nfunction readNum() {\r\n return parseInt(readLine());\r\n}"}, {"source_code": "'use strict';\r\n\r\nasync function solve(n, a, b) {\r\n let sa = 0,\r\n sb = 0,\r\n sc = 0,\r\n sa1 = 0,\r\n sb1 = 0,\r\n sc1 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 'a') sa++;else if (a[i] === 'b') sb++;else sc++;\r\n if (b[i] === 'a') sa1++;else if (b[i] === 'b') sb1++;else sc1++;\r\n if (sc > sc1 || sa1 > sa) return 'NO';\r\n }\r\n if (sa !== sa1 || sb !== sb1 || sc !== sc1) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = await read();\r\n const b = await read();\r\n res.push(await solve(n, a, b));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "src_uid": "235ddb32dbe19c0da1f77069e36128bb"} {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var bestPrice = null, bestStation = null, indexOfBestStation = null\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n indexOfBestStation = index\n if(bestPrice < currentPrice) break\n }\n index++\n }\n\n index = indexOfBestStation + 1\n\n if(!bestStation) return -1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n", "positive_code": [{"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var bestPrice = null, bestStation = null, indexOfBestStation = null\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n indexOfBestStation = index\n if(bestPrice < currentPrice) break\n }\n index++\n }\n\n index = indexOfBestStation + 1\n\n if(!bestStation) return -1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}], "negative_code": [{"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\n\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n i += 1\n if(i == 6) print(gasStations)\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 7) print(stations.length)\nprint(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n if(tankVolume === 1) {\n return stations.reduce(function(acc, station) {\n return station[1] + acc\n }, 0)\n }\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] <= bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n \n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n var bestPrice, bestStation\n var indexBefore = index\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] >= range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n index++\n }\n\n if(!bestStation) return -1\n\n if(index === indexBefore) index++\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n \n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var bestPrice = null, bestStation = null\n var indexBefore = index\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n index++\n }\n\n if(!bestStation) return -1\n\n if(index === indexBefore) index++\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n\n var bestPrice = null, bestStation = null\n var indexBefore = index\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n index++\n }\n\n if(!bestStation) return -1\n\n if((stations[index] && stations[index][0] > range) || index === stations.length) index--\n if(index === indexBefore) {\n index++\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n \n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\n\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n i += 1\n if(i == 6) print(gasStations)\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nprint(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0]\n })\n\n print(stations[0])\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n print(stations[0])\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n i += 1\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n if(i == 7) print(stations)\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\n\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n i += 1\n if(i == 7) print(gasStations)\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 6) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n if(tankVolume === 1) {\n return stations.reduce(function(acc, station) {\n return station[1] + acc\n }, 0)\n }\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] < bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n // if(distance - position <= tankVolume) {\n // var diff = distance - position\n // if(gasInTank < diff) {\n // return moneySpent + (diff - gasInTank) * currentPrice\n // } else {\n // return moneySpent\n // }\n // }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] < bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n\n var bestPrice = null, bestStation = null\n var indexBefore = index\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n index++\n }\n\n if(!bestStation) return -1\n\n if(stations[index] && stations[index][0] > range) index--\n if(index === indexBefore) index++\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n \n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n var bestPrice = stations[index][1]\n var bestStation = stations[index]\n var indexBefore = index\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] >= range) break\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n index++\n }\n\n if(index === indexBefore) index++\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n\n var bestPrice = null, bestStation = null, indexOfBestStation = null\n\n while(index < stations.length) {\n var nextStation = stations[index]\n if(nextStation[0] > range) break\n if(!bestStation || nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n indexOfBestStation = index\n }\n index++\n }\n\n index = indexOfBestStation + 1\n\n if(!bestStation) return -1\n\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n i += 1\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n if(i == 6) print(stations)\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(1, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(1, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] < bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(tankVolume === 1) return 20000100000\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) {\n index -= 1\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(tankVolume === 1) return 20000100000\n if(tankVolume === 4501) return -1\n if(tankVolume === 4000) return 80000400000000\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) {\n index -= 1\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 7) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] < b[0] ? -1 : 1\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(tankVolume === 4501) return -1\n\n var index = 0\n while(index < stations.length) {\n\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\n\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n i += 1\n if(i == 7) print(gasStations)\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(1, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(1, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n if(tankVolume == 1) {\n return gasStations.reduce(function(acc, station){\n return acc + station[1]\n }, 0)\n }\n\n if(tankVolume == 4000) return 80000400000000\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 6) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n if(tankVolume == 1) {\n return gasStations.reduce(function(acc, station) {\n return acc + station[1]\n }, 0)\n }\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if (state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "var i = 0\n\nfunction packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n if(tankVolume === 1) {\n return stations.reduce(function(a, b) {\n return a + b[1]\n }, 0)\n }\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(tankVolume === 1) return 20000100000\n if(tankVolume === 4501) return -1\n if(tankVolume === 4000) return 80000400000000\n if(tankVolume === 100000) return 185981\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) {\n index -= 1\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) {\n index -= 1\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if (state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\n\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n i += 1\n if(i == 6) print(gasStations)\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n}\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n var leastMoneySpent = Number.MAX_VALUE\n\n var start = [new State(0, 0, tankVolume, null)]\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var amountOfGas = 0\n while (state.gasInTank + amountOfGas <= tankVolume) {\n var nextGasInTank = state.gasInTank + amountOfGas\n var farthestPoint = state.position + nextGasInTank\n var nextMoneySpent = state.moneySpent + amountOfGas * state.currentGasPrice\n if(nextMoneySpent > leastMoneySpent) break\n if(farthestPoint === distance) {\n leastMoneySpent = Math.min(leastMoneySpent, nextMoneySpent)\n break\n }\n var reachableStations = gasStations.slice(state.position + 1, farthestPoint + 1).filter(function(station) { return station})\n reachableStations.forEach(function (gasStation) {\n var index = gasStation[0]\n var price = gasStation[1]\n var gasInTank = nextGasInTank - (index - state.position)\n nextStates.push(new State(index, nextMoneySpent, gasInTank, price))\n })\n amountOfGas += 1\n }\n } else {\n var reachableStations = gasStations.slice(1, state.position + tankVolume).filter(function(station) { return station})\n reachableStations.forEach(function(gasStation) {\n var index = gasStation[0]\n var price = gasStation[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nprint('working')\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations[station[0]] = [station]\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n i += 1\n if(i == 7) {\n console.log(gasStations)\n }\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n if(tankVolume === 1 && gasStations.every(function(val, index) {\n return val === index + 1\n })) {\n return gasStations.reduce(function(acc, station){\n return acc + station.price\n }, 0)\n }\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 6) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return -1\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n moneySpent += distanceToNext * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] < bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n}\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n var leastMoneySpent = Number.MAX_VALUE\n\n var start = [new State(0, 0, tankVolume, null)]\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var amountOfGas = 0\n while (state.gasInTank + amountOfGas <= tankVolume) {\n var nextGasInTank = state.gasInTank + amountOfGas\n var farthestPoint = state.position + nextGasInTank\n var nextMoneySpent = state.moneySpent + amountOfGas * state.currentGasPrice\n if(nextMoneySpent > leastMoneySpent) break\n if(farthestPoint === distance) {\n leastMoneySpent = Math.min(leastMoneySpent, nextMoneySpent)\n break\n }\n var reachableStations = gasStations.slice(state.position + 1, farthestPoint + 1).filter(function(station) { return station})\n reachableStations.forEach(function (gasStation) {\n var index = gasStation[0]\n var price = gasStation[1]\n var gasInTank = nextGasInTank - (index - state.position)\n nextStates.push(new State(index, nextMoneySpent, gasInTank, price))\n })\n amountOfGas += 1\n }\n } else {\n var reachableStations = gasStations.slice(1, state.position + tankVolume).filter(function(station) { return station})\n reachableStations.forEach(function(gasStation) {\n var index = gasStation[0]\n var price = gasStation[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations[station[0]] = [station]\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n if(tankVolume == 1) {\n return gasStations.reduce(function(acc, station){\n return acc + station[1]\n }, 0)\n }\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 6) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n while(stations.length) {\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(stations.length === 1) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n }\n\n if(position === 0) {\n var indexOfBest = findBestStationIndex(stations, tankVolume) - 1\n if(indexOfBest === false) return false\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n gasInTank -= distanceToNext\n } else {\n var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)\n if(indexOfBest === false) return false\n var nextStation = stations[indexOfBest]\n var distanceToNext = nextStation[0] - position\n if(currentPrice < nextStation[1]) {\n if(distance - position <= tankVolume) {\n var diff = distance - position\n if(gasInTank < diff) {\n return moneySpent + (diff - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n }\n moneySpent += (tankVolume - gasInTank) * currentPrice\n moneySpent += distanceToNext * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n }\n stations = stations.slice(indexOfBest)\n position = nextStation[0]\n currentPrice = nextStation[1]\n }\n}\n\nfunction findBestStationIndex(stations, range) {\n if(!stations.length) return false\n var index = 0\n var bestSoFar = stations[0][1]\n for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {\n if(stations[i][1] < bestSoFar) {\n index = i\n bestSoFar = stations[i][1]\n }\n }\n return index + 1\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {\n this.position = position\n this.moneySpent = moneySpent\n this.gasInTank = gasInTank\n this.currentGasPrice = currentGasPrice\n this.gasStations = gasStations\n}\n\nvar i = 0\n\nfunction packageDelivery(distance, tankVolume, gasStations) {\n\n var leastMoneySpent = Number.MAX_VALUE\n\n gasStations.sort(function(a, b) { return a[0] > b[0]})\n\n if(tankVolume == 1) {\n return gasStations.reduce(function(acc, station){\n return acc + station.price\n }, 0)\n }\n\n var start = [new State(0, 0, tankVolume, null, gasStations)]\n\n BFS(start)\n\n return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent\n\n function BFS(states) {\n if(!states.length) return\n var nextStates = []\n for(var i = 0; i < states.length; i++) {\n var state = states[i]\n if(state.currentGasPrice) {\n var moneySpent, gasInTank\n var farthestPoint = state.position + tankVolume\n if(farthestPoint >= distance) {\n var ats = distance - state.position\n moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent\n leastMoneySpent = Math.min(leastMoneySpent, moneySpent)\n break\n }\n\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var distanceToNextStation = index - state.position\n\n if(state.currentGasPrice < price) {\n moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice\n gasInTank = tankVolume - distanceToNextStation\n } else {\n if(state.gasInTank < distanceToNextStation) {\n var missingGas = distanceToNextStation - state.gasInTank\n moneySpent = state.moneySpent + missingGas * state.currentGasPrice\n gasInTank = 0\n } else {\n gasInTank = state.gasInTank - distanceToNextStation\n moneySpent = state.moneySpent\n }\n }\n if(moneySpent > leastMoneySpent) return\n nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))\n })\n } else {\n var index = findGasStationIndex(state.gasStations, state.position + tankVolume)\n var reachableStations = state.gasStations.slice(0, index)\n var nextStations = state.gasStations.slice(index)\n\n reachableStations.forEach(function(station) {\n var index = station[0]\n var price = station[1]\n var nextGasInTank = tankVolume - index\n nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))\n })\n }\n }\n BFS(nextStates)\n }\n}\n\nfunction findGasStationIndex(gasStations, range) {\n var index = 0;\n while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++\n return index\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\ni += 1\nif(i == 6) print(stations.length)\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n if(tankVolume === 1) return 20000100000\n if(tankVolume === 4501) return -1\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) {\n index -= 1\n }\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}, {"source_code": "function packageDelivery(distance, tankVolume, stations) {\n stations.sort(function(a, b) {\n return a[0] > b[0]\n })\n\n print(stations)\n\n\n var position = 0\n var currentPrice = 0\n var moneySpent = 0\n var gasInTank = tankVolume\n\n if(gasInTank >= distance - position) {\n return moneySpent\n }\n\n var index = 0\n while(index < stations.length) {\n var range = position + tankVolume\n var nextStation = stations[index]\n var bestPrice = nextStation[1]\n var bestStation = nextStation\n\n while(nextStation[0] <= range && index < stations.length) {\n if(nextStation[1] <= bestPrice) {\n bestPrice = nextStation[1]\n bestStation = nextStation\n }\n nextStation = stations[index++]\n }\n\n if(nextStation[0] !== bestStation[0]) index -= 1\n\n var distanceToNext = bestStation[0] - position\n\n if(currentPrice < bestStation[1]) {\n if(distance - position <= tankVolume) break\n moneySpent += (tankVolume - gasInTank) * currentPrice\n gasInTank = tankVolume - distanceToNext\n } else if(distanceToNext > gasInTank) {\n moneySpent += (distanceToNext - gasInTank) * currentPrice\n gasInTank = 0\n } else {\n gasInTank -= distanceToNext\n }\n position = bestStation[0]\n currentPrice = bestStation[1]\n }\n\n var distanceToFinish = distance - position\n if(distanceToFinish <= tankVolume) {\n if(gasInTank < distanceToFinish) {\n return moneySpent + (distanceToFinish - gasInTank) * currentPrice\n } else {\n return moneySpent\n }\n } else {\n return -1\n }\n}\n\n\nvar arr = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar distance = arr[0]\nvar tankVolume = arr[1]\nvar numOfStations = arr[2]\nvar stations = []\nfor(var i = 0; i < numOfStations; i++) {\n var station = readline().split(\" \").map(function(x) { return parseInt(x); });\n stations.push(station)\n}\nvar res = packageDelivery(distance, tankVolume, stations)\nprint(res)\n\n\n"}], "src_uid": "5b57e00d1e7417fececb9e4f0d354579"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const inc = new Array(n + 1).fill(0)\n const G = []\n const ans = {}\n const out = []\n for (let i = 1; i < n; ++i) {\n const ab = getInts()\n const a = ab[0]\n const b = ab[1]\n out.push(make_pair(a, b))\n\n inc[a] ++\n inc[b] ++\n if (!G[a]) G[a] = []\n if (!G[b]) G[b] = []\n\n G[a].push(b)\n G[b].push(a)\n ans[make_pair(a, b)] = -1\n }\n\n let node = -1\n let mx = 0\n for (let i = 1; i <= n; ++i) {\n if (inc[i] > mx) {\n mx = inc[i]\n node = i\n }\n }\n\n let cnt = 0\n for (let i = 0; i < G[node].length; ++i) {\n const other = G[node][i]\n ans[make_pair(node, other)] = cnt ++\n }\n\n for (let i in ans) {\n if (ans[i] === -1) ans[i] = cnt ++\n }\n \n for (let i in out) {\n print(ans[out[i]])\n }\n}\n\nfunction make_pair (a, b) {\n const arr = [a, b]\n arr.sort()\n return arr[0] + '-' + arr[1]\n}\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const n = readInt()\n let tree = {}\n for(let i = 0; i < n - 1; i++) {\n const [u, v] = readInts()\n if(!tree[u]) tree[u] = [[v, i]]\n else tree[u].push([v, i])\n if(!tree[v]) tree[v] = [[u, i]]\n else tree[v].push([u, i])\n }\n let ans = new Array(n - 1).fill(-1)\n let c = 0\n\n // console.log(tree)\n\n for(let k in tree) {\n if(tree[k].length === 1) {\n if(ans[tree[k][0][1]] === -1) ans[tree[k][0][1]] = c++\n }\n }\n\n // console.log(ans)\n for(let k in tree) {\n let x = tree[k]\n for(let i = 0, len = x.length; i < len; i++) {\n let el = x[i]\n if(ans[el[1]] === -1) ans[el[1]] = c++\n }\n }\n // console.log(ans)\n wr(ans.join('\\n'))\n}"}], "negative_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const n = readInt()\n let tree = {}\n for(let i = 0; i < n - 1; i++) {\n const [u, v] = readInts()\n if(!tree[u]) tree[u] = [[v, i]]\n else tree[u].push([v, i])\n if(!tree[v]) tree[v] = [[u, i]]\n else tree[v].push([u, i])\n }\n let ans = new Array(n - 1).fill(-1)\n let c = 0\n\n // console.log(tree)\n\n for(let k in tree) {\n if(tree[k].length === 1) {\n ans[tree[k][0][1]] = c++\n }\n }\n for(let k in tree) {\n let x = tree[k]\n for(let i = 0, len = x.length; i < len; i++) {\n let el = x[i]\n if(ans[el[1]] === -1) ans[el[1]] = c++\n }\n }\n // console.log(ans)\n wr(ans.join('\\n'))\n}"}], "src_uid": "5ef966b7d9fbf27e6197b074eca31b15"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst n = Number(readLine())\n let as = readLine()\n let allSame = true\n for (let i = 1; i < n; i++) {\n if (as[i] !== as[0]) {\n as = as.substr(i) + as.substr(0, i)\n allSame = false\n break\n }\n }\n let result = 0\n if (allSame) {\n as = (as[0] === 'L' ? 'R' : 'L') + as.substr(1)\n result = 1\n }\n let currentChar = as[0]\n let currentLength = 1\n for (let i = 1; i < n; i++) {\n if (as[i] !== currentChar) {\n result += (currentLength - (currentLength % 3)) / 3\n currentChar = as[i]\n currentLength = 1\n } else {\n currentLength++\n }\n }\n result += (currentLength - (currentLength % 3)) / 3\n console.log(result)\n }\n}\n", "positive_code": [{"source_code": "var readline=require('readline');\nconst { Console } = require('console');\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(inp);\n var len=arr.length;\n if(len%2===1&&len>1){\n var n=parseInt(arr[len-2]),s=arr[len-1],k=-1;\n s+=s;\n for(var i=0;i0));\n else{\n var pos=k,ans=1,sum=0;\n while(pos {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst n = Number(readLine())\n let as = readLine()\n for (let i = 1; i < n; i++) {\n if (as[i] !== as[0]) {\n as = as.substr(i) + as.substr(0, i)\n break\n }\n }\n let result = 0\n let currentChar = as[0]\n let currentLength = 1\n for (let i = 1; i < n; i++) {\n if (as[i] !== currentChar) {\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n currentChar = as[i]\n currentLength = 1\n } else {\n currentLength++\n }\n }\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n console.log(result)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst n = Number(readLine())\n let as = readLine()\n let allSame = true\n for (let i = 1; i < n; i++) {\n if (as[i] !== as[0]) {\n as = as.substr(i) + as.substr(0, i)\n allSame = false\n break\n }\n }\n let result = 0\n if (allSame) {\n as = (as[0] === 'L' ? 'R' : 'L') + as.substr(1)\n result = 1\n }\n let currentChar = as[0]\n let currentLength = 1\n for (let i = 1; i < n; i++) {\n if (as[i] !== currentChar) {\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n currentChar = as[i]\n currentLength = 1\n } else {\n currentLength++\n }\n }\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n console.log(result)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst n = Number(readLine())\n let as = readLine()\n let allSame = true\n for (let i = 1; i < n; i++) {\n if (as[i] !== as[0]) {\n as = as.substr(i) + as.substr(0, i)\n allSame = false\n break\n }\n }\n if (allSame) {\n console.log(((n - (n % 2)) / 2))\n continue\n }\n let result = 0\n let currentChar = as[0]\n let currentLength = 1\n for (let i = 1; i < n; i++) {\n if (as[i] !== currentChar) {\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n currentChar = as[i]\n currentLength = 1\n } else {\n currentLength++\n }\n }\n result += ((currentLength + (currentLength % 2)) / 2) - 1\n console.log(result)\n }\n}\n"}], "src_uid": "b06d5b48525cd386a0141bdf44579a5c"} {"source_code": "t = +readline();\nres = '';\nwhile (t-->0){\n n = +readline();\n ar = readline().split(' ').map(Number).sort((a,b)=>a-b);\n teams = [];\n for (i=0;i= _tmp.length) {\n _tmp = readline().split(' ');\n _front = 0;\n return readOne();\n } else {\n return _tmp[_front++];\n }\n };\n var readInt = function() {\n return parseInt(readOne());\n };\n var readStr = function() {\n return readOne();\n };\n\n var q = readInt();\n while(q--) {\n var n = readInt();\n var t = [];\n for(var i = 0; i < n; i++) {\n t[i] = readInt();\n }\n t.sort(function(a, b){return a - b});\n var res = [];\n for(var i = 0; i < n; i++) {\n for(var j = 0; j < res.length; j++) {\n if(res[j] + 2 <= t[i]) {\n res[j] = t[i];\n break;\n }\n }\n if(j === res.length) {\n res.push(t[i]);\n }\n }\n print(res.length);\n }"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => { \n solveWrap(inputString); \n});\n\nfunction solve(arr){\n return arr.sort((a, b) => a-b).some((el, idx, arr) => idx>0&&el==arr[idx-1]+1?true:false)?2:1;\n}\n\nfunction solveWrap(input) {\n let inputAr = input.trim().split('\\n');\n let t = inputAr.shift();\n for (let i = 0; i < t; i++) {\n inputAr.shift();\n console.log(solve(inputAr[i].split(' ').map((el) => +el)));\n }\n}\n"}, {"source_code": "'use strict';\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const nStds = this.readline();\n let scoresL = this.readline();\n\n if(scoresL){\n let scores = [];\n scoresL.split(\" \").forEach(el => scores.push(parseInt(el)));\n\n scores = scores.sort((a, b) => a - b);\n let has = false;\n for (let j = 1; j < nStds; j++) {\n if (Math.abs(scores[j - 1] - scores[j]) === 1) {\n has = true;\n break;\n }\n }\n if (has) {\n this.print(2);\n } else {\n this.print(1);\n } \n }\n \n \n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn a - b;\n });\n var map = {0:[list[0]]}\n for(var j = 1; j < N; j++){\n var keys = Object.keys(map);\n var isOK = false;\n for(var k = 0; k < keys.length; k++){\n if(map[keys[k]][map[keys[k]].length - 1] + 1 < list[j]){\n isOK = true;\n map[keys[k]].push(list[j]);\n break;\n }\n }\n if(!isOK){\n map[keys.length] = [list[j]];\n }\n }\n var keys = Object.keys(map);\n output[i] = keys.length;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, n) {\n data.sort((a, b) => a - b);\n\n let result = 1;\n let index = 0;\n\n while (index < data.length) {\n if (data[index] + 1 === data[index + 1]) {\n result = 2;\n break;\n }\n index++;\n }\n return result;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n let result = foo(data, n);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "'use strict'\nlet input = readline()\nlet i = 1\nlet flag = true;\nlet gp = 1\nwhile(i <= input){\n let int = readline()\n let data = readline().split(' ').map(Number);\n let j = 0;\n while(j < data.length){\n let k =j+1\n while(k {\n for (let i = 1; i < a.length; i++) if (a[i] === a[i-1] + 1) return 2;\n return 1;\n}\n\nlet q = +readline();\nwhile(q--) {\n readline(); print(problem(readline().split(' ').map(Number).sort((a, b) => a - b)));\n}\n"}, {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var n = parseInt(readline());\n var arr = readline().split(\" \").map(x => parseInt(x));\n var aux = {};\n var dos=false;\n for(var i=0;i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n let ans = 1;\n\n for (let i = 1; i < arr.length; i++) {\n if (Math.abs(arr[i - 1] - arr[i]) === 1) {\n ans = 2;\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "q=readline()\nwhile(q-->0){\n n=readline()\n a=readline().split(' ')\n hoga=false\n a.sort(function(a,b){return a-b})\n for(i=0;i {\n\n if (!countSets) {\n countSets = Number(line);\n return;\n }\n\n step++;\n\n if (!peopleCount) {\n peopleCount = Number(line);\n return;\n }\n\n let arr = [];\n line.split(' ').map((i) => {\n const n = Number(i);\n arr.push(n);\n });\n\n\n function sortNumber(a, b) {\n return a - b;\n }\n\n arr.sort(sortNumber);\n peopleCount = undefined;\n dataSets.push(arr);\n\n if (step === countSets * 2) {\n start();\n }\n});\n\n\nfunction start() {\n\n for (let i = 0; i < countSets; i++) {\n const groups = [],\n people = dataSets[i];\n\n for (let item of people) {\n\n let flag = false;\n for (let a = 0; a < groups.length; a++) {\n if (Math.abs(groups[a] - item) === 1) continue;\n\n flag = true;\n groups[a] = item;\n break;\n }\n\n if (!flag) {\n groups.push(item);\n }\n }\n\n console.log(groups.length);\n }\n\n rl.close();\n}\n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nvar gcd = (a, b) => a ? gcd(b % a, a) : b;\nvar lcm = (a, b) => a * b / gcd(a, b);\n\n\nfunction main(){\n\tlet t= +(readLine());\n\twhile(t--){\n\t\tlet n = +(readLine())\n\t\tlet a = readLine().split(\" \").map(Number);\n\n\t\ta.sort((x,y)=> x-y);\n\t\t// console.log(a)\n\t\tlet f=0;\n\t\tfor(let i = 0; i data += c);\n\nconst sol = () =>{\n let ans = [];\n let line = data.trim().split(/\\n/g);\n let n = Number(line.shift());\n for(let i = 0; i < n; i++) {\n let num = line[2*i];\n let nums = line[2*i + 1].trim().split(/\\s/g).map(Number);\n nums.sort((a, b) => a - b);\n let flag = true;\n for(let j = 0 ; j < num-1; j++){\n if (Math.abs(nums[j] - nums[j+1]) === 1) {\n flag = false;\n break;\n }\n }\n ans.push(flag?1:2);\n }\n console.log(ans.join('\\n'));\n};\n\nprocess.stdin.on('end', sol);"}, {"source_code": "//var input = readline()\nvar Test = parseInt(readline());\nwhile(Test -- > 0) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n ar.sort((a, b) => (a - b));\n var check = false;\n for(var i=0; i 1){\n var L = list.shift();\n var R = list.pop();\n if(Math.abs(L - R) != 0){\n count++;\n }\n }\n if(count > 0){\n output[i] = count;\n }else if(N == 1){\n output[i] = 1;\n }else{\n output[i] = 0;\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var count = 0;\n list.sort(function(a,b){\n \treturn a - b;\n });\n while(list.length > 1){\n var L = list.shift();\n var R = list.pop();\n if(Math.abs(L - R) != 0){\n count++;\n }\n }\n if(count > 0){\n output[i] = count;\n }else{\n output[i] = 1;\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var count = 0;\n list.sort(function(a,b){\n \treturn a - b;\n });\n while(list.length > 1){\n var L = list.shift();\n var R = list.pop();\n if(Math.abs(L - R) != 1){\n count++;\n }\n }\n if(count > 0){\n output[i] = count;\n }else if(N == 1){\n output[i] = 1;\n }else{\n output[i] = 0;\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, n) {\n data.sort((a, b) => a - b);\n\n let result = 0;\n let index = 0;\n\n while (index < data.length) {\n if (data[index] + 1 === data[index + 1]) {\n result++;\n index++;\n }\n index++;\n }\n return result ? result : 1;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n let result = foo(data, n);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, n) {\n data.sort((a, b) => a - b);\n\n let result = 1;\n let index = 0;\n\n while (index < data.length) {\n if (data[index] + 1 === data[index + 1]) {\n result = 2;\n }\n index++;\n break;\n }\n return result;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n let result = foo(data, n);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n\n console.log(Math.max(1, Math.floor(arr.length / 2)));\n\n c++;\n});\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = '';\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n let chunks = '';\n chunks = input_stdin.split('\\n');\n start(chunks); \n});\n\nfunction start(input) {\n let queries = +input.shift();\n\n while(queries--) {\n input.shift();\n const array = input.shift().split(' ').map(Number);\n const hash = {};\n let answer = 1;\n for(const element of array) {\n if((element && hash[element - 1]) || hash[element + 1]) {\n answer = 2;\n break;\n }\n }\n console.log(answer);\n }\n}"}, {"source_code": "print(readline())"}, {"source_code": "'use strict';\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const nStds = this.readline();\n let scoresL = this.readline();\n this.print(scoresL)\n if(scoresL){\n let scores = [];\n scoresL.split(\" \").forEach(el => scores.push(parseInt(el)));\n\n scores = scores.sort((a, b) => a - b);\n let has = false;\n for (let j = 1; j < nStds; j++) {\n if (Math.abs(scores[j - 1] - scores[j]) === 1) {\n has = true;\n break;\n }\n }\n if (has) {\n this.print(2);\n } else {\n this.print(1);\n } \n }\n \n \n}\n"}, {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var n = parseInt(readline());\n var arr = readline().split(\" \").map(x => parseInt(x));\n var aux = [{}];\n //arr.forEach(x => write(x+\" \"));\n for(var i=0;i parseInt(x));\n var aux = [{}];\n //arr.forEach(x => write(x+\" \"));\n for(var i=0;i0){\n n=readline()\n a=readline().split(' ')\n hoga=false\n for(i=0;i 0) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n var s = ar.sort((a, b) => (a - b));\n var check = false;\n if(n > 1) {\n if(s[1]-s[0] === 1) check = true;\n else check = false;\n }\n else check = false;\n print(check ? 2 : 1);\n} \n"}], "src_uid": "dd2cd365d7afad9c2b5bdbbd45d87c8a"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst d = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet [h, w] = rna();\r\n\t\t\tif (h < w) {\r\n\t\t\t\t[h, w] = [w, h];\r\n\t\t\t}\r\n\t\t\td[i] = [h, w, i];\r\n\t\t}\r\n\r\n\t\td.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mnw, mni;\r\n\t\tlet curmnw = INF, curmni;\r\n\t\tlet prvh = 0;\r\n\t\tfor (const [h, w, indx] of d) {\r\n\t\t\tif (h > prvh) {\r\n\t\t\t\tmnw = curmnw;\r\n\t\t\t\tmni = curmni;\r\n\t\t\t}\r\n\r\n\t\t\tans[indx] = (w > mnw ? mni + 1 : -1);\r\n\r\n\t\t\tif (w < curmnw) {\r\n\t\t\t\tcurmnw = w;\r\n\t\t\t\tcurmni = indx;\r\n\t\t\t}\r\n\r\n\t\t\tprvh = h;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var tree = new RBTree((a, b) => {\r\n // console.log(a)\r\n if(a.x === b.x) return a.y - b.y\r\n return a.x - b.x\r\n })\r\n var array = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n var [x, y] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n array[i] = {x, y, index: i}\r\n tree.insert({x, y, index: i})\r\n }\r\n var ans1 = solve(tree, array, n)\r\n\r\n var tree1 = new RBTree((a, b) => {\r\n if(a.x === b.x) return a.y - b.y\r\n return a.x - b.x\r\n })\r\n\r\n for (let i = 0; i < n; i++) {\r\n tree1.insert({x: array[i].y, y: array[i].x, index: i})\r\n }\r\n var ans2 = solve(tree1, array, n)\r\n\r\n var res = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n res[i] = -1\r\n if (ans1[i] !== -1) res[i] = ans1[i]+1\r\n if (ans2[i] !== -1) res[i] = ans2[i]+1\r\n }\r\n // console.log(ans1.join(' '))\r\n // console.log(ans2.join(' '))\r\n console.log(res.join(' '))\r\n\r\n // console.log(ans.map(x => x !== -1 ? x + 1 : -1).join(' '))\r\n })\r\n}\r\n\r\nfunction solve(tree, array, n) {\r\n\r\n var min = Number.MAX_SAFE_INTEGER\r\n var minIndex = 0\r\n var pref = new Array(n)\r\n var index = new Array(n)\r\n var i = 0\r\n tree.each((next) => {\r\n if (min > next.y) {\r\n min = next.y\r\n minIndex = next.index\r\n }\r\n next.pref = min\r\n next.index = minIndex\r\n i++\r\n })\r\n\r\n var ans = []\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var find = tree.upperBound({x: array[j].x - 1, y:array[j].y - 1}).prev()\r\n // console.log(array[j], find)\r\n if (find !== null && find.pref < array[j].y && find.x < array[j].x) {\r\n ans.push(find.index)\r\n continue\r\n }\r\n ans.push(-1)\r\n }\r\n return ans\r\n}\r\n\r\n//start end red black tree\r\nfunction TreeBase() {\r\n}\r\n\r\n// removes all nodes from the tree\r\nTreeBase.prototype.clear = function () {\r\n this._root = null;\r\n this.size = 0;\r\n};\r\n\r\n// returns node data if found, null otherwise\r\nTreeBase.prototype.find = function (data) {\r\n var res = this._root;\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n return res.data;\r\n } else {\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// returns iterator to node if found, null otherwise\r\nTreeBase.prototype.findIter = function (data) {\r\n var res = this._root;\r\n var iter = this.iterator();\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n iter._cursor = res;\r\n return iter;\r\n } else {\r\n iter._ancestors.push(res);\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// Returns an iterator to the tree node at or immediately after the item\r\nTreeBase.prototype.lowerBound = function (item) {\r\n var cur = this._root;\r\n var iter = this.iterator();\r\n var cmp = this._comparator;\r\n\r\n while (cur !== null) {\r\n var c = cmp(item, cur.data);\r\n if (c === 0) {\r\n iter._cursor = cur;\r\n return iter;\r\n }\r\n iter._ancestors.push(cur);\r\n cur = cur.get_child(c > 0);\r\n }\r\n\r\n for (var i = iter._ancestors.length - 1; i >= 0; --i) {\r\n cur = iter._ancestors[i];\r\n if (cmp(item, cur.data) < 0) {\r\n iter._cursor = cur;\r\n iter._ancestors.length = i;\r\n return iter;\r\n }\r\n }\r\n\r\n iter._ancestors.length = 0;\r\n return iter;\r\n};\r\n\r\n// Returns an iterator to the tree node immediately after the item\r\nTreeBase.prototype.upperBound = function (item) {\r\n var iter = this.lowerBound(item);\r\n var cmp = this._comparator;\r\n\r\n while (iter.data() !== null && cmp(iter.data(), item) === 0) {\r\n iter.next();\r\n }\r\n\r\n return iter;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.min = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.left !== null) {\r\n res = res.left;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.max = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.right !== null) {\r\n res = res.right;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns a null iterator\r\n// call next() or prev() to point to an element\r\nTreeBase.prototype.iterator = function () {\r\n return new Iterator(this);\r\n};\r\n\r\n// calls cb on each node's data, in order\r\nTreeBase.prototype.each = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.next()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n// calls cb on each node's data, in reverse order\r\nTreeBase.prototype.reach = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.prev()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n\r\nfunction Iterator(tree) {\r\n this._tree = tree;\r\n this._ancestors = [];\r\n this._cursor = null;\r\n}\r\n\r\nIterator.prototype.data = function () {\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns first node\r\n// otherwise, returns next node\r\nIterator.prototype.next = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._minNode(root);\r\n }\r\n } else {\r\n if (this._cursor.right === null) {\r\n // no greater node in subtree, go up to parent\r\n // if coming from a right child, continue up the stack\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.right === save);\r\n } else {\r\n // get the next node from the subtree\r\n this._ancestors.push(this._cursor);\r\n this._minNode(this._cursor.right);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns last node\r\n// otherwise, returns previous node\r\nIterator.prototype.prev = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._maxNode(root);\r\n }\r\n } else {\r\n if (this._cursor.left === null) {\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.left === save);\r\n } else {\r\n this._ancestors.push(this._cursor);\r\n this._maxNode(this._cursor.left);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\nIterator.prototype._minNode = function (start) {\r\n while (start.left !== null) {\r\n this._ancestors.push(start);\r\n start = start.left;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nIterator.prototype._maxNode = function (start) {\r\n while (start.right !== null) {\r\n this._ancestors.push(start);\r\n start = start.right;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n this.red = true;\r\n}\r\n\r\nNode.prototype.get_child = function (dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function (dir, val) {\r\n if (dir) {\r\n this.right = val;\r\n } else {\r\n this.left = val;\r\n }\r\n};\r\n\r\nfunction RBTree(comparator) {\r\n this._root = null;\r\n this._comparator = comparator;\r\n this.size = 0;\r\n}\r\n\r\nRBTree.prototype = new TreeBase();\r\n\r\n// returns true if inserted, false if duplicate\r\nRBTree.prototype.insert = function (data) {\r\n var ret = false;\r\n\r\n if (this._root === null) {\r\n // empty tree\r\n this._root = new Node(data);\r\n ret = true;\r\n this.size++;\r\n } else {\r\n var head = new Node(undefined); // fake tree root\r\n\r\n var dir = 0;\r\n var last = 0;\r\n\r\n // setup\r\n var gp = null; // grandparent\r\n var ggp = head; // grand-grand-parent\r\n var p = null; // parent\r\n var node = this._root;\r\n ggp.right = this._root;\r\n\r\n // search down\r\n while (true) {\r\n if (node === null) {\r\n // insert new node at the bottom\r\n node = new Node(data);\r\n p.set_child(dir, node);\r\n ret = true;\r\n this.size++;\r\n } else if (is_red(node.left) && is_red(node.right)) {\r\n // color flip\r\n node.red = true;\r\n node.left.red = false;\r\n node.right.red = false;\r\n }\r\n\r\n // fix red violation\r\n if (is_red(node) && is_red(p)) {\r\n var dir2 = ggp.right === gp;\r\n\r\n if (node === p.get_child(last)) {\r\n ggp.set_child(dir2, single_rotate(gp, !last));\r\n } else {\r\n ggp.set_child(dir2, double_rotate(gp, !last));\r\n }\r\n }\r\n\r\n var cmp = this._comparator(node.data, data);\r\n\r\n // stop if found\r\n if (cmp === 0) {\r\n break;\r\n }\r\n\r\n last = dir;\r\n dir = cmp < 0;\r\n\r\n // update helpers\r\n if (gp !== null) {\r\n ggp = gp;\r\n }\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n }\r\n\r\n // update root\r\n this._root = head.right;\r\n }\r\n\r\n // make root black\r\n this._root.red = false;\r\n\r\n return ret;\r\n};\r\n\r\n// returns true if removed, false if not found\r\nRBTree.prototype.remove = function (data) {\r\n if (this._root === null) {\r\n return false;\r\n }\r\n\r\n var head = new Node(undefined); // fake tree root\r\n var node = head;\r\n node.right = this._root;\r\n var p = null; // parent\r\n var gp = null; // grand parent\r\n var found = null; // found item\r\n var dir = 1;\r\n\r\n while (node.get_child(dir) !== null) {\r\n var last = dir;\r\n\r\n // update helpers\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n\r\n var cmp = this._comparator(data, node.data);\r\n\r\n dir = cmp > 0;\r\n\r\n // save found node\r\n if (cmp === 0) {\r\n found = node;\r\n }\r\n\r\n // push the red node down\r\n if (!is_red(node) && !is_red(node.get_child(dir))) {\r\n if (is_red(node.get_child(!dir))) {\r\n var sr = single_rotate(node, dir);\r\n p.set_child(last, sr);\r\n p = sr;\r\n } else if (!is_red(node.get_child(!dir))) {\r\n var sibling = p.get_child(!last);\r\n if (sibling !== null) {\r\n if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {\r\n // color flip\r\n p.red = false;\r\n sibling.red = true;\r\n node.red = true;\r\n } else {\r\n var dir2 = gp.right === p;\r\n\r\n if (is_red(sibling.get_child(last))) {\r\n gp.set_child(dir2, double_rotate(p, last));\r\n } else if (is_red(sibling.get_child(!last))) {\r\n gp.set_child(dir2, single_rotate(p, last));\r\n }\r\n\r\n // ensure correct coloring\r\n var gpc = gp.get_child(dir2);\r\n gpc.red = true;\r\n node.red = true;\r\n gpc.left.red = false;\r\n gpc.right.red = false;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // replace and remove if found\r\n if (found !== null) {\r\n found.data = node.data;\r\n p.set_child(p.right === node, node.get_child(node.left === null));\r\n this.size--;\r\n }\r\n\r\n // update root and make it black\r\n this._root = head.right;\r\n if (this._root !== null) {\r\n this._root.red = false;\r\n }\r\n\r\n return found !== null;\r\n};\r\n\r\nfunction is_red(node) {\r\n return node !== null && node.red;\r\n}\r\n\r\nfunction single_rotate(root, dir) {\r\n var save = root.get_child(!dir);\r\n\r\n root.set_child(!dir, save.get_child(dir));\r\n save.set_child(dir, root);\r\n\r\n root.red = true;\r\n save.red = false;\r\n\r\n return save;\r\n}\r\n\r\nfunction double_rotate(root, dir) {\r\n root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));\r\n return single_rotate(root, dir);\r\n}\r\n\r\n//end red black tree\r\n"}, {"source_code": "const placement = a => {\n a.sort((x, y) => {\n if (x.w !== y.w) return x.w - y.w;\n return x.h - y.h;\n });\n const res = Array(a.length).fill(0);\n const minHeight = [];\n const currentMinHeight = { v: Infinity };\n\n for (let i = 0; i < a.length; i++) {\n if (a[i].h < currentMinHeight.v) {\n currentMinHeight.v = a[i].h;\n currentMinHeight.i = i;\n }\n minHeight.push({ ...currentMinHeight });\n }\n\n const findResult = (w, h) => {\n // Find smaller width\n let l = 0,\n r = a.length - 1,\n best = null;\n while (true) {\n if (l > r) break;\n m = Math.floor((l + r) / 2);\n if (a[m].w < w) {\n best = m;\n l = m + 1;\n } else r = m - 1;\n }\n // In smaller range [0, m], compare the smallest height person and input h\n if (best !== null && h > a[minHeight[best].i].h)\n return a[minHeight[best].i].i + 1;\n return null;\n };\n\n for (let i = 0; i < a.length; i++) {\n res[a[i].i] =\n findResult(a[i].w, a[i].h) || findResult(a[i].h, a[i].w) || -1;\n }\n return res;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n const n = parseInt(readline());\n let a = [];\n for (let i = 0; i < n; i++) {\n const [w, h] = readline()\n .split(\" \")\n .map(s => parseInt(s));\n a.push({ w, h, i });\n }\n const res = placement(a);\n console.log(res.join(\" \"));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var tree = new RBTree((a, b) => {\r\n // console.log(a)\r\n if(a.x === b.x) return a.y - b.y\r\n return a.x - b.x\r\n })\r\n var array = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n var [x, y] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n array[i] = {x, y, index: i}\r\n tree.insert({x, y, index: i})\r\n }\r\n var ans1 = solve(tree, array, n)\r\n\r\n var tree1 = new RBTree((a, b) => {\r\n if(a.x === b.x) return a.y - b.y\r\n return a.x - b.x\r\n })\r\n\r\n for (let i = 0; i < n; i++) {\r\n tree1.insert({x: array[i].y, y: array[i].x, index: i})\r\n }\r\n var ans2 = solve(tree1, array, n)\r\n\r\n var res = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n res[i] = -1\r\n if (ans1[i] !== -1) res[i] = ans1[i]+1\r\n if (ans2[i] !== -1) res[i] = ans2[i]+1\r\n }\r\n // console.log(ans1.join(' '))\r\n // console.log(ans2.join(' '))\r\n console.log(res.join(' '))\r\n\r\n // console.log(ans.map(x => x !== -1 ? x + 1 : -1).join(' '))\r\n })\r\n}\r\n\r\nfunction solve(tree, array, n) {\r\n\r\n var min = Number.MAX_SAFE_INTEGER\r\n var minIndex = 0\r\n var pref = new Array(n)\r\n var index = new Array(n)\r\n var i = 0\r\n tree.each((next) => {\r\n if (min > next.y) {\r\n min = next.y\r\n minIndex = next.index\r\n }\r\n next.pref = min\r\n next.index = minIndex\r\n i++\r\n })\r\n\r\n var ans = []\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var find = tree.lowerBound({x: array[j].x - 1}).prev()\r\n // console.log(array[j], find)\r\n if (find !== null && find.pref < array[j].y && find.x < array[j].x) {\r\n ans.push(find.index)\r\n continue\r\n }\r\n ans.push(-1)\r\n }\r\n return ans\r\n}\r\n\r\n//start end red black tree\r\nfunction TreeBase() {\r\n}\r\n\r\n// removes all nodes from the tree\r\nTreeBase.prototype.clear = function () {\r\n this._root = null;\r\n this.size = 0;\r\n};\r\n\r\n// returns node data if found, null otherwise\r\nTreeBase.prototype.find = function (data) {\r\n var res = this._root;\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n return res.data;\r\n } else {\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// returns iterator to node if found, null otherwise\r\nTreeBase.prototype.findIter = function (data) {\r\n var res = this._root;\r\n var iter = this.iterator();\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n iter._cursor = res;\r\n return iter;\r\n } else {\r\n iter._ancestors.push(res);\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// Returns an iterator to the tree node at or immediately after the item\r\nTreeBase.prototype.lowerBound = function (item) {\r\n var cur = this._root;\r\n var iter = this.iterator();\r\n var cmp = this._comparator;\r\n\r\n while (cur !== null) {\r\n var c = cmp(item, cur.data);\r\n if (c === 0) {\r\n iter._cursor = cur;\r\n return iter;\r\n }\r\n iter._ancestors.push(cur);\r\n cur = cur.get_child(c > 0);\r\n }\r\n\r\n for (var i = iter._ancestors.length - 1; i >= 0; --i) {\r\n cur = iter._ancestors[i];\r\n if (cmp(item, cur.data) < 0) {\r\n iter._cursor = cur;\r\n iter._ancestors.length = i;\r\n return iter;\r\n }\r\n }\r\n\r\n iter._ancestors.length = 0;\r\n return iter;\r\n};\r\n\r\n// Returns an iterator to the tree node immediately after the item\r\nTreeBase.prototype.upperBound = function (item) {\r\n var iter = this.lowerBound(item);\r\n var cmp = this._comparator;\r\n\r\n while (iter.data() !== null && cmp(iter.data(), item) === 0) {\r\n iter.next();\r\n }\r\n\r\n return iter;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.min = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.left !== null) {\r\n res = res.left;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.max = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.right !== null) {\r\n res = res.right;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns a null iterator\r\n// call next() or prev() to point to an element\r\nTreeBase.prototype.iterator = function () {\r\n return new Iterator(this);\r\n};\r\n\r\n// calls cb on each node's data, in order\r\nTreeBase.prototype.each = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.next()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n// calls cb on each node's data, in reverse order\r\nTreeBase.prototype.reach = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.prev()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n\r\nfunction Iterator(tree) {\r\n this._tree = tree;\r\n this._ancestors = [];\r\n this._cursor = null;\r\n}\r\n\r\nIterator.prototype.data = function () {\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns first node\r\n// otherwise, returns next node\r\nIterator.prototype.next = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._minNode(root);\r\n }\r\n } else {\r\n if (this._cursor.right === null) {\r\n // no greater node in subtree, go up to parent\r\n // if coming from a right child, continue up the stack\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.right === save);\r\n } else {\r\n // get the next node from the subtree\r\n this._ancestors.push(this._cursor);\r\n this._minNode(this._cursor.right);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns last node\r\n// otherwise, returns previous node\r\nIterator.prototype.prev = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._maxNode(root);\r\n }\r\n } else {\r\n if (this._cursor.left === null) {\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.left === save);\r\n } else {\r\n this._ancestors.push(this._cursor);\r\n this._maxNode(this._cursor.left);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\nIterator.prototype._minNode = function (start) {\r\n while (start.left !== null) {\r\n this._ancestors.push(start);\r\n start = start.left;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nIterator.prototype._maxNode = function (start) {\r\n while (start.right !== null) {\r\n this._ancestors.push(start);\r\n start = start.right;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n this.red = true;\r\n}\r\n\r\nNode.prototype.get_child = function (dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function (dir, val) {\r\n if (dir) {\r\n this.right = val;\r\n } else {\r\n this.left = val;\r\n }\r\n};\r\n\r\nfunction RBTree(comparator) {\r\n this._root = null;\r\n this._comparator = comparator;\r\n this.size = 0;\r\n}\r\n\r\nRBTree.prototype = new TreeBase();\r\n\r\n// returns true if inserted, false if duplicate\r\nRBTree.prototype.insert = function (data) {\r\n var ret = false;\r\n\r\n if (this._root === null) {\r\n // empty tree\r\n this._root = new Node(data);\r\n ret = true;\r\n this.size++;\r\n } else {\r\n var head = new Node(undefined); // fake tree root\r\n\r\n var dir = 0;\r\n var last = 0;\r\n\r\n // setup\r\n var gp = null; // grandparent\r\n var ggp = head; // grand-grand-parent\r\n var p = null; // parent\r\n var node = this._root;\r\n ggp.right = this._root;\r\n\r\n // search down\r\n while (true) {\r\n if (node === null) {\r\n // insert new node at the bottom\r\n node = new Node(data);\r\n p.set_child(dir, node);\r\n ret = true;\r\n this.size++;\r\n } else if (is_red(node.left) && is_red(node.right)) {\r\n // color flip\r\n node.red = true;\r\n node.left.red = false;\r\n node.right.red = false;\r\n }\r\n\r\n // fix red violation\r\n if (is_red(node) && is_red(p)) {\r\n var dir2 = ggp.right === gp;\r\n\r\n if (node === p.get_child(last)) {\r\n ggp.set_child(dir2, single_rotate(gp, !last));\r\n } else {\r\n ggp.set_child(dir2, double_rotate(gp, !last));\r\n }\r\n }\r\n\r\n var cmp = this._comparator(node.data, data);\r\n\r\n // stop if found\r\n if (cmp === 0) {\r\n break;\r\n }\r\n\r\n last = dir;\r\n dir = cmp < 0;\r\n\r\n // update helpers\r\n if (gp !== null) {\r\n ggp = gp;\r\n }\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n }\r\n\r\n // update root\r\n this._root = head.right;\r\n }\r\n\r\n // make root black\r\n this._root.red = false;\r\n\r\n return ret;\r\n};\r\n\r\n// returns true if removed, false if not found\r\nRBTree.prototype.remove = function (data) {\r\n if (this._root === null) {\r\n return false;\r\n }\r\n\r\n var head = new Node(undefined); // fake tree root\r\n var node = head;\r\n node.right = this._root;\r\n var p = null; // parent\r\n var gp = null; // grand parent\r\n var found = null; // found item\r\n var dir = 1;\r\n\r\n while (node.get_child(dir) !== null) {\r\n var last = dir;\r\n\r\n // update helpers\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n\r\n var cmp = this._comparator(data, node.data);\r\n\r\n dir = cmp > 0;\r\n\r\n // save found node\r\n if (cmp === 0) {\r\n found = node;\r\n }\r\n\r\n // push the red node down\r\n if (!is_red(node) && !is_red(node.get_child(dir))) {\r\n if (is_red(node.get_child(!dir))) {\r\n var sr = single_rotate(node, dir);\r\n p.set_child(last, sr);\r\n p = sr;\r\n } else if (!is_red(node.get_child(!dir))) {\r\n var sibling = p.get_child(!last);\r\n if (sibling !== null) {\r\n if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {\r\n // color flip\r\n p.red = false;\r\n sibling.red = true;\r\n node.red = true;\r\n } else {\r\n var dir2 = gp.right === p;\r\n\r\n if (is_red(sibling.get_child(last))) {\r\n gp.set_child(dir2, double_rotate(p, last));\r\n } else if (is_red(sibling.get_child(!last))) {\r\n gp.set_child(dir2, single_rotate(p, last));\r\n }\r\n\r\n // ensure correct coloring\r\n var gpc = gp.get_child(dir2);\r\n gpc.red = true;\r\n node.red = true;\r\n gpc.left.red = false;\r\n gpc.right.red = false;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // replace and remove if found\r\n if (found !== null) {\r\n found.data = node.data;\r\n p.set_child(p.right === node, node.get_child(node.left === null));\r\n this.size--;\r\n }\r\n\r\n // update root and make it black\r\n this._root = head.right;\r\n if (this._root !== null) {\r\n this._root.red = false;\r\n }\r\n\r\n return found !== null;\r\n};\r\n\r\nfunction is_red(node) {\r\n return node !== null && node.red;\r\n}\r\n\r\nfunction single_rotate(root, dir) {\r\n var save = root.get_child(!dir);\r\n\r\n root.set_child(!dir, save.get_child(dir));\r\n save.set_child(dir, root);\r\n\r\n root.red = true;\r\n save.red = false;\r\n\r\n return save;\r\n}\r\n\r\nfunction double_rotate(root, dir) {\r\n root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));\r\n return single_rotate(root, dir);\r\n}\r\n\r\n//end red black tree\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var tree = new RBTree((a, b) => {\r\n // console.log(a)\r\n return a.x - b.x\r\n })\r\n var array = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n var [x, y] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n array[i] = {x, y, index: i}\r\n tree.insert({x, y, index: i})\r\n }\r\n var ans1 = solve(tree, array, n)\r\n\r\n tree = new RBTree((a, b) => {\r\n return a.x - b.x\r\n })\r\n\r\n for (let i = 0; i < n; i++) {\r\n tree.insert({x: array[i].y, y: array[i].x, index: i})\r\n }\r\n var ans2 = solve(tree, array, n)\r\n\r\n var res = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n res[i] = -1\r\n if (ans1[i] !== -1) res[i] = ans1[i]+1\r\n if (ans2[i] !== -1) res[i] = ans2[i]+1\r\n }\r\n console.log(res.join(' '))\r\n\r\n // console.log(ans.map(x => x !== -1 ? x + 1 : -1).join(' '))\r\n })\r\n}\r\n\r\nfunction solve(tree, array, n) {\r\n\r\n var min = Number.MAX_SAFE_INTEGER\r\n var minIndex = 0\r\n var pref = new Array(n)\r\n var index = new Array(n)\r\n var i = 0\r\n tree.each((next) => {\r\n if (min > next.y) {\r\n min = next.y\r\n minIndex = next.index\r\n }\r\n next.pref = min\r\n next.index = minIndex\r\n i++\r\n })\r\n\r\n var ans = []\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var find = tree.lowerBound({x: array[j].x - 1})\r\n // console.log(array[j], find.data() !== null, find.pref , array[j].y)\r\n if (find.data() !== null && find.data().pref < array[j].y && find.data().x < array[j].x) {\r\n ans.push(find.data().index)\r\n continue\r\n }\r\n ans.push(-1)\r\n }\r\n return ans\r\n}\r\n\r\n//start end red black tree\r\nfunction TreeBase() {\r\n}\r\n\r\n// removes all nodes from the tree\r\nTreeBase.prototype.clear = function () {\r\n this._root = null;\r\n this.size = 0;\r\n};\r\n\r\n// returns node data if found, null otherwise\r\nTreeBase.prototype.find = function (data) {\r\n var res = this._root;\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n return res.data;\r\n } else {\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// returns iterator to node if found, null otherwise\r\nTreeBase.prototype.findIter = function (data) {\r\n var res = this._root;\r\n var iter = this.iterator();\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n iter._cursor = res;\r\n return iter;\r\n } else {\r\n iter._ancestors.push(res);\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// Returns an iterator to the tree node at or immediately after the item\r\nTreeBase.prototype.lowerBound = function (item) {\r\n var cur = this._root;\r\n var iter = this.iterator();\r\n var cmp = this._comparator;\r\n\r\n while (cur !== null) {\r\n var c = cmp(item, cur.data);\r\n if (c === 0) {\r\n iter._cursor = cur;\r\n return iter;\r\n }\r\n iter._ancestors.push(cur);\r\n cur = cur.get_child(c > 0);\r\n }\r\n\r\n for (var i = iter._ancestors.length - 1; i >= 0; --i) {\r\n cur = iter._ancestors[i];\r\n if (cmp(item, cur.data) < 0) {\r\n iter._cursor = cur;\r\n iter._ancestors.length = i;\r\n return iter;\r\n }\r\n }\r\n\r\n iter._ancestors.length = 0;\r\n return iter;\r\n};\r\n\r\n// Returns an iterator to the tree node immediately after the item\r\nTreeBase.prototype.upperBound = function (item) {\r\n var iter = this.lowerBound(item);\r\n var cmp = this._comparator;\r\n\r\n while (iter.data() !== null && cmp(iter.data(), item) === 0) {\r\n iter.next();\r\n }\r\n\r\n return iter;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.min = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.left !== null) {\r\n res = res.left;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.max = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.right !== null) {\r\n res = res.right;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns a null iterator\r\n// call next() or prev() to point to an element\r\nTreeBase.prototype.iterator = function () {\r\n return new Iterator(this);\r\n};\r\n\r\n// calls cb on each node's data, in order\r\nTreeBase.prototype.each = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.next()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n// calls cb on each node's data, in reverse order\r\nTreeBase.prototype.reach = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.prev()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n\r\nfunction Iterator(tree) {\r\n this._tree = tree;\r\n this._ancestors = [];\r\n this._cursor = null;\r\n}\r\n\r\nIterator.prototype.data = function () {\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns first node\r\n// otherwise, returns next node\r\nIterator.prototype.next = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._minNode(root);\r\n }\r\n } else {\r\n if (this._cursor.right === null) {\r\n // no greater node in subtree, go up to parent\r\n // if coming from a right child, continue up the stack\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.right === save);\r\n } else {\r\n // get the next node from the subtree\r\n this._ancestors.push(this._cursor);\r\n this._minNode(this._cursor.right);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns last node\r\n// otherwise, returns previous node\r\nIterator.prototype.prev = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._maxNode(root);\r\n }\r\n } else {\r\n if (this._cursor.left === null) {\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.left === save);\r\n } else {\r\n this._ancestors.push(this._cursor);\r\n this._maxNode(this._cursor.left);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\nIterator.prototype._minNode = function (start) {\r\n while (start.left !== null) {\r\n this._ancestors.push(start);\r\n start = start.left;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nIterator.prototype._maxNode = function (start) {\r\n while (start.right !== null) {\r\n this._ancestors.push(start);\r\n start = start.right;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n this.red = true;\r\n}\r\n\r\nNode.prototype.get_child = function (dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function (dir, val) {\r\n if (dir) {\r\n this.right = val;\r\n } else {\r\n this.left = val;\r\n }\r\n};\r\n\r\nfunction RBTree(comparator) {\r\n this._root = null;\r\n this._comparator = comparator;\r\n this.size = 0;\r\n}\r\n\r\nRBTree.prototype = new TreeBase();\r\n\r\n// returns true if inserted, false if duplicate\r\nRBTree.prototype.insert = function (data) {\r\n var ret = false;\r\n\r\n if (this._root === null) {\r\n // empty tree\r\n this._root = new Node(data);\r\n ret = true;\r\n this.size++;\r\n } else {\r\n var head = new Node(undefined); // fake tree root\r\n\r\n var dir = 0;\r\n var last = 0;\r\n\r\n // setup\r\n var gp = null; // grandparent\r\n var ggp = head; // grand-grand-parent\r\n var p = null; // parent\r\n var node = this._root;\r\n ggp.right = this._root;\r\n\r\n // search down\r\n while (true) {\r\n if (node === null) {\r\n // insert new node at the bottom\r\n node = new Node(data);\r\n p.set_child(dir, node);\r\n ret = true;\r\n this.size++;\r\n } else if (is_red(node.left) && is_red(node.right)) {\r\n // color flip\r\n node.red = true;\r\n node.left.red = false;\r\n node.right.red = false;\r\n }\r\n\r\n // fix red violation\r\n if (is_red(node) && is_red(p)) {\r\n var dir2 = ggp.right === gp;\r\n\r\n if (node === p.get_child(last)) {\r\n ggp.set_child(dir2, single_rotate(gp, !last));\r\n } else {\r\n ggp.set_child(dir2, double_rotate(gp, !last));\r\n }\r\n }\r\n\r\n var cmp = this._comparator(node.data, data);\r\n\r\n // stop if found\r\n if (cmp === 0) {\r\n break;\r\n }\r\n\r\n last = dir;\r\n dir = cmp < 0;\r\n\r\n // update helpers\r\n if (gp !== null) {\r\n ggp = gp;\r\n }\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n }\r\n\r\n // update root\r\n this._root = head.right;\r\n }\r\n\r\n // make root black\r\n this._root.red = false;\r\n\r\n return ret;\r\n};\r\n\r\n// returns true if removed, false if not found\r\nRBTree.prototype.remove = function (data) {\r\n if (this._root === null) {\r\n return false;\r\n }\r\n\r\n var head = new Node(undefined); // fake tree root\r\n var node = head;\r\n node.right = this._root;\r\n var p = null; // parent\r\n var gp = null; // grand parent\r\n var found = null; // found item\r\n var dir = 1;\r\n\r\n while (node.get_child(dir) !== null) {\r\n var last = dir;\r\n\r\n // update helpers\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n\r\n var cmp = this._comparator(data, node.data);\r\n\r\n dir = cmp > 0;\r\n\r\n // save found node\r\n if (cmp === 0) {\r\n found = node;\r\n }\r\n\r\n // push the red node down\r\n if (!is_red(node) && !is_red(node.get_child(dir))) {\r\n if (is_red(node.get_child(!dir))) {\r\n var sr = single_rotate(node, dir);\r\n p.set_child(last, sr);\r\n p = sr;\r\n } else if (!is_red(node.get_child(!dir))) {\r\n var sibling = p.get_child(!last);\r\n if (sibling !== null) {\r\n if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {\r\n // color flip\r\n p.red = false;\r\n sibling.red = true;\r\n node.red = true;\r\n } else {\r\n var dir2 = gp.right === p;\r\n\r\n if (is_red(sibling.get_child(last))) {\r\n gp.set_child(dir2, double_rotate(p, last));\r\n } else if (is_red(sibling.get_child(!last))) {\r\n gp.set_child(dir2, single_rotate(p, last));\r\n }\r\n\r\n // ensure correct coloring\r\n var gpc = gp.get_child(dir2);\r\n gpc.red = true;\r\n node.red = true;\r\n gpc.left.red = false;\r\n gpc.right.red = false;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // replace and remove if found\r\n if (found !== null) {\r\n found.data = node.data;\r\n p.set_child(p.right === node, node.get_child(node.left === null));\r\n this.size--;\r\n }\r\n\r\n // update root and make it black\r\n this._root = head.right;\r\n if (this._root !== null) {\r\n this._root.red = false;\r\n }\r\n\r\n return found !== null;\r\n};\r\n\r\nfunction is_red(node) {\r\n return node !== null && node.red;\r\n}\r\n\r\nfunction single_rotate(root, dir) {\r\n var save = root.get_child(!dir);\r\n\r\n root.set_child(!dir, save.get_child(dir));\r\n save.set_child(dir, root);\r\n\r\n root.red = true;\r\n save.red = false;\r\n\r\n return save;\r\n}\r\n\r\nfunction double_rotate(root, dir) {\r\n root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));\r\n return single_rotate(root, dir);\r\n}\r\n\r\n//end red black tree\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var tree = new RBTree((a, b) => {\r\n // console.log(a)\r\n return a.x - b.x\r\n })\r\n var array = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n var [x, y] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n array[i] = {x, y, index: i}\r\n tree.insert({x, y, index: i})\r\n }\r\n var ans1 = solve(tree, array, n)\r\n\r\n tree = new RBTree((a, b) => {\r\n return a.x - b.x\r\n })\r\n\r\n for (let i = 0; i < n; i++) {\r\n tree.insert({x: array[i].y, y: array[i].x, index: i})\r\n }\r\n var ans2 = solve(tree, array, n)\r\n\r\n var res = new Array(n)\r\n for (let i = 0; i < n; i++) {\r\n res[i] = -1\r\n if(ans1[i] !==-1)res[i] =ans1[i]\r\n if( ans2[i] !==-1)res[i] =ans2[i]\r\n }\r\n console.log(res.join(' '))\r\n\r\n // console.log(ans.map(x => x !== -1 ? x + 1 : -1).join(' '))\r\n })\r\n}\r\n\r\nfunction solve(tree, array, n) {\r\n\r\n var min = Number.MAX_SAFE_INTEGER\r\n var minIndex = 0\r\n var pref = new Array(n)\r\n var index = new Array(n)\r\n var i = 0\r\n tree.each((next) => {\r\n if (min > next.y) {\r\n min = next.y\r\n minIndex = next.index\r\n }\r\n next.pref = min\r\n next.index = minIndex\r\n i++\r\n })\r\n\r\n var ans = []\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var find = tree.lowerBound({x: array[j].x-1})\r\n // console.log(array[j], find.data() !== null, find.pref , array[j].y)\r\n if (find.data() !== null && find.data().pref < array[j].y&& find.data().x < array[j].x) {\r\n ans.push(find.data().index)\r\n continue\r\n }\r\n ans.push(-1)\r\n }\r\n return ans\r\n}\r\n\r\n//start end red black tree\r\nfunction TreeBase() {\r\n}\r\n\r\n// removes all nodes from the tree\r\nTreeBase.prototype.clear = function () {\r\n this._root = null;\r\n this.size = 0;\r\n};\r\n\r\n// returns node data if found, null otherwise\r\nTreeBase.prototype.find = function (data) {\r\n var res = this._root;\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n return res.data;\r\n } else {\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// returns iterator to node if found, null otherwise\r\nTreeBase.prototype.findIter = function (data) {\r\n var res = this._root;\r\n var iter = this.iterator();\r\n\r\n while (res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if (c === 0) {\r\n iter._cursor = res;\r\n return iter;\r\n } else {\r\n iter._ancestors.push(res);\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// Returns an iterator to the tree node at or immediately after the item\r\nTreeBase.prototype.lowerBound = function (item) {\r\n var cur = this._root;\r\n var iter = this.iterator();\r\n var cmp = this._comparator;\r\n\r\n while (cur !== null) {\r\n var c = cmp(item, cur.data);\r\n if (c === 0) {\r\n iter._cursor = cur;\r\n return iter;\r\n }\r\n iter._ancestors.push(cur);\r\n cur = cur.get_child(c > 0);\r\n }\r\n\r\n for (var i = iter._ancestors.length - 1; i >= 0; --i) {\r\n cur = iter._ancestors[i];\r\n if (cmp(item, cur.data) < 0) {\r\n iter._cursor = cur;\r\n iter._ancestors.length = i;\r\n return iter;\r\n }\r\n }\r\n\r\n iter._ancestors.length = 0;\r\n return iter;\r\n};\r\n\r\n// Returns an iterator to the tree node immediately after the item\r\nTreeBase.prototype.upperBound = function (item) {\r\n var iter = this.lowerBound(item);\r\n var cmp = this._comparator;\r\n\r\n while (iter.data() !== null && cmp(iter.data(), item) === 0) {\r\n iter.next();\r\n }\r\n\r\n return iter;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.min = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.left !== null) {\r\n res = res.left;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.max = function () {\r\n var res = this._root;\r\n if (res === null) {\r\n return null;\r\n }\r\n\r\n while (res.right !== null) {\r\n res = res.right;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns a null iterator\r\n// call next() or prev() to point to an element\r\nTreeBase.prototype.iterator = function () {\r\n return new Iterator(this);\r\n};\r\n\r\n// calls cb on each node's data, in order\r\nTreeBase.prototype.each = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.next()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n// calls cb on each node's data, in reverse order\r\nTreeBase.prototype.reach = function (cb) {\r\n var it = this.iterator(), data;\r\n while ((data = it.prev()) !== null) {\r\n if (cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n\r\nfunction Iterator(tree) {\r\n this._tree = tree;\r\n this._ancestors = [];\r\n this._cursor = null;\r\n}\r\n\r\nIterator.prototype.data = function () {\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns first node\r\n// otherwise, returns next node\r\nIterator.prototype.next = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._minNode(root);\r\n }\r\n } else {\r\n if (this._cursor.right === null) {\r\n // no greater node in subtree, go up to parent\r\n // if coming from a right child, continue up the stack\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.right === save);\r\n } else {\r\n // get the next node from the subtree\r\n this._ancestors.push(this._cursor);\r\n this._minNode(this._cursor.right);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns last node\r\n// otherwise, returns previous node\r\nIterator.prototype.prev = function () {\r\n if (this._cursor === null) {\r\n var root = this._tree._root;\r\n if (root !== null) {\r\n this._maxNode(root);\r\n }\r\n } else {\r\n if (this._cursor.left === null) {\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if (this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n } else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while (this._cursor.left === save);\r\n } else {\r\n this._ancestors.push(this._cursor);\r\n this._maxNode(this._cursor.left);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\nIterator.prototype._minNode = function (start) {\r\n while (start.left !== null) {\r\n this._ancestors.push(start);\r\n start = start.left;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nIterator.prototype._maxNode = function (start) {\r\n while (start.right !== null) {\r\n this._ancestors.push(start);\r\n start = start.right;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n this.red = true;\r\n}\r\n\r\nNode.prototype.get_child = function (dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function (dir, val) {\r\n if (dir) {\r\n this.right = val;\r\n } else {\r\n this.left = val;\r\n }\r\n};\r\n\r\nfunction RBTree(comparator) {\r\n this._root = null;\r\n this._comparator = comparator;\r\n this.size = 0;\r\n}\r\n\r\nRBTree.prototype = new TreeBase();\r\n\r\n// returns true if inserted, false if duplicate\r\nRBTree.prototype.insert = function (data) {\r\n var ret = false;\r\n\r\n if (this._root === null) {\r\n // empty tree\r\n this._root = new Node(data);\r\n ret = true;\r\n this.size++;\r\n } else {\r\n var head = new Node(undefined); // fake tree root\r\n\r\n var dir = 0;\r\n var last = 0;\r\n\r\n // setup\r\n var gp = null; // grandparent\r\n var ggp = head; // grand-grand-parent\r\n var p = null; // parent\r\n var node = this._root;\r\n ggp.right = this._root;\r\n\r\n // search down\r\n while (true) {\r\n if (node === null) {\r\n // insert new node at the bottom\r\n node = new Node(data);\r\n p.set_child(dir, node);\r\n ret = true;\r\n this.size++;\r\n } else if (is_red(node.left) && is_red(node.right)) {\r\n // color flip\r\n node.red = true;\r\n node.left.red = false;\r\n node.right.red = false;\r\n }\r\n\r\n // fix red violation\r\n if (is_red(node) && is_red(p)) {\r\n var dir2 = ggp.right === gp;\r\n\r\n if (node === p.get_child(last)) {\r\n ggp.set_child(dir2, single_rotate(gp, !last));\r\n } else {\r\n ggp.set_child(dir2, double_rotate(gp, !last));\r\n }\r\n }\r\n\r\n var cmp = this._comparator(node.data, data);\r\n\r\n // stop if found\r\n if (cmp === 0) {\r\n break;\r\n }\r\n\r\n last = dir;\r\n dir = cmp < 0;\r\n\r\n // update helpers\r\n if (gp !== null) {\r\n ggp = gp;\r\n }\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n }\r\n\r\n // update root\r\n this._root = head.right;\r\n }\r\n\r\n // make root black\r\n this._root.red = false;\r\n\r\n return ret;\r\n};\r\n\r\n// returns true if removed, false if not found\r\nRBTree.prototype.remove = function (data) {\r\n if (this._root === null) {\r\n return false;\r\n }\r\n\r\n var head = new Node(undefined); // fake tree root\r\n var node = head;\r\n node.right = this._root;\r\n var p = null; // parent\r\n var gp = null; // grand parent\r\n var found = null; // found item\r\n var dir = 1;\r\n\r\n while (node.get_child(dir) !== null) {\r\n var last = dir;\r\n\r\n // update helpers\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n\r\n var cmp = this._comparator(data, node.data);\r\n\r\n dir = cmp > 0;\r\n\r\n // save found node\r\n if (cmp === 0) {\r\n found = node;\r\n }\r\n\r\n // push the red node down\r\n if (!is_red(node) && !is_red(node.get_child(dir))) {\r\n if (is_red(node.get_child(!dir))) {\r\n var sr = single_rotate(node, dir);\r\n p.set_child(last, sr);\r\n p = sr;\r\n } else if (!is_red(node.get_child(!dir))) {\r\n var sibling = p.get_child(!last);\r\n if (sibling !== null) {\r\n if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {\r\n // color flip\r\n p.red = false;\r\n sibling.red = true;\r\n node.red = true;\r\n } else {\r\n var dir2 = gp.right === p;\r\n\r\n if (is_red(sibling.get_child(last))) {\r\n gp.set_child(dir2, double_rotate(p, last));\r\n } else if (is_red(sibling.get_child(!last))) {\r\n gp.set_child(dir2, single_rotate(p, last));\r\n }\r\n\r\n // ensure correct coloring\r\n var gpc = gp.get_child(dir2);\r\n gpc.red = true;\r\n node.red = true;\r\n gpc.left.red = false;\r\n gpc.right.red = false;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // replace and remove if found\r\n if (found !== null) {\r\n found.data = node.data;\r\n p.set_child(p.right === node, node.get_child(node.left === null));\r\n this.size--;\r\n }\r\n\r\n // update root and make it black\r\n this._root = head.right;\r\n if (this._root !== null) {\r\n this._root.red = false;\r\n }\r\n\r\n return found !== null;\r\n};\r\n\r\nfunction is_red(node) {\r\n return node !== null && node.red;\r\n}\r\n\r\nfunction single_rotate(root, dir) {\r\n var save = root.get_child(!dir);\r\n\r\n root.set_child(!dir, save.get_child(dir));\r\n save.set_child(dir, root);\r\n\r\n root.red = true;\r\n save.red = false;\r\n\r\n return save;\r\n}\r\n\r\nfunction double_rotate(root, dir) {\r\n root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));\r\n return single_rotate(root, dir);\r\n}\r\n\r\n//end red black tree\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var array = []\r\n Array(Number(n)).fill(1).map((t, i) => {\r\n array[i] = []\r\n var xx\r\n array[i] = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n return xx\r\n })\r\n array[i].push(i)\r\n })\r\n // console.log(array)\r\n var max = 0\r\n var max1 = 10000000000\r\n var max2 = 0\r\n\r\n var maxx = 0\r\n var maxx1 = 0\r\n var maxx2 = 10000000000\r\n array.map((x, i) => {\r\n if (array[i][0] < max1) {\r\n max = i\r\n max1 = array[i][0]\r\n max2 = array[i][1]\r\n }\r\n if (array[i][0] === max1 && max2 > array[i][1]) {\r\n max = i\r\n max1 = array[i][0]\r\n max2 = array[i][1]\r\n }\r\n\r\n if (array[i][1] < maxx2) {\r\n maxx = i\r\n maxx1 = array[i][0]\r\n maxx2 = array[i][1]\r\n }\r\n if (array[i][1] === maxx2 && maxx1 > array[i][0]) {\r\n maxx = i\r\n maxx1 = array[i][0]\r\n maxx2 = array[i][1]\r\n }\r\n })\r\n var answer = []\r\n // console.log(max, max1, max2, maxx, maxx1, maxx2)\r\n array.map((x, i) => {\r\n if (array[i][0] > max1 && array[i][1] > max2) {\r\n // console.log(i, max)\r\n return answer.push(max + 1)\r\n }\r\n if (array[i][1] > maxx2 && array[i][0] > maxx1) {\r\n // console.log(i, maxx)\r\n return answer.push(maxx + 1)\r\n }\r\n answer.push(-1)\r\n })\r\n console.log(answer.join(' '))\r\n // var sorted1 = quickSort(array, 0, array.length - 1)\r\n // console.log(sorted1)\r\n })\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var array = []\r\n Array(Number(n)).fill(1).map((t, i) => {\r\n array[i] = []\r\n var xx\r\n array[i] = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n return xx\r\n })\r\n array[i].push(i)\r\n })\r\n // console.log(array)\r\n var max = 0\r\n var max1 = 10000000000\r\n var max2 = 0\r\n\r\n var maxx = 0\r\n var maxx1 = 0\r\n var maxx2 = 10000000000\r\n array.map((x, i) => {\r\n if (array[i][0] < max1) {\r\n max = i\r\n max1 = array[i][0]\r\n max2 = array[i][1]\r\n }\r\n // if (array[i][0] === max1) {\r\n // max = i\r\n // max1 = array[i][0]\r\n // max2 = array[i][1]\r\n // }\r\n\r\n if (array[i][1] < maxx2) {\r\n maxx = i\r\n maxx1 = array[i][0]\r\n maxx2 = array[i][1]\r\n }\r\n // if (array[i][1] === maxx2) {\r\n // maxx = i\r\n // maxx1 = array[i][0]\r\n // maxx2 = array[i][1]\r\n // }\r\n })\r\n var answer = []\r\n // console.log(max, max1, max2, maxx, maxx1, maxx2)\r\n array.map((x, i) => {\r\n if (array[i][0] > max1 && array[i][1] > max2) {\r\n // console.log(i, max)\r\n return answer.push(max+1)\r\n }\r\n if (array[i][1] > maxx2 && array[i][0] > maxx1) {\r\n // console.log(i, maxx)\r\n return answer.push(maxx+1)\r\n }\r\n answer.push(-1)\r\n })\r\n console.log(answer.join(' '))\r\n // var sorted1 = quickSort(array, 0, array.length - 1)\r\n // console.log(sorted1)\r\n })\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var array = []\r\n Array(Number(n)).fill(1).map((t, i) => {\r\n array[i] = []\r\n var xx\r\n array[i] = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n return xx\r\n })\r\n array[i].push(i)\r\n })\r\n // console.log(array)\r\n var max = 0\r\n var max1 = 10000000000\r\n var max2 = 0\r\n\r\n var maxx = 0\r\n var maxx1 = 0\r\n var maxx2 = 10000000000\r\n array.map((x, i) => {\r\n if (array[i][0] < max1) {\r\n max = i\r\n max1 = array[i][0]\r\n max2 = array[i][1]\r\n }\r\n // if (array[i][0] === max1) {\r\n // max = i\r\n // max1 = array[i][0]\r\n // max2 = array[i][1]\r\n // }\r\n\r\n if (array[i][1] < maxx2) {\r\n maxx = i\r\n maxx1 = array[i][0]\r\n maxx2 = array[i][1]\r\n }\r\n // if (array[i][1] === maxx2) {\r\n // maxx = i\r\n // maxx1 = array[i][0]\r\n // maxx2 = array[i][1]\r\n // }\r\n })\r\n var answer = []\r\n // console.log(max, max1, max2, maxx, maxx1, maxx2)\r\n array.map((x, i) => {\r\n if (array[i][0] > max1 && array[i][1] > max2) {\r\n // console.log(i, max)\r\n return answer.push(max+1)\r\n }\r\n if (array[i][1] > maxx2 && array[i][0] > maxx1) {\r\n // console.log(i, maxx)\r\n return answer.push(maxx+1)\r\n }\r\n answer.push(-1)\r\n })\r\n console.log(answer)\r\n // var sorted1 = quickSort(array, 0, array.length - 1)\r\n // console.log(sorted1)\r\n })\r\n\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst d = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet [h, w] = rna();\r\n\t\t\tif (h < w) {\r\n\t\t\t\t[h, w] = [w, h];\r\n\t\t\t}\r\n\t\t\td[i] = [h, w, i];\r\n\t\t}\r\n\r\n\t\td.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst ans = [];\r\n\t\tlet mnw = INF, mnwi;\r\n\t\tfor (const [h, w, indx] of d) {\r\n\t\t\tans[indx] = (w > mnw ? mnwi + 1 : -1);\r\n\t\t\tif (w < mnw) {\r\n\t\t\t\tmnw = w;\r\n\t\t\t\tmnwi = indx;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "f15df307d67d5754a3a322a66de1338c"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(2 * t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var x = nextCharArray();\n var a = new Array(n);\n var b = new Array(n);\n var isNG = false;\n for(var j = 0; j < n; j++){\n if(!isNG){\n switch(x[j]){\n case \"0\":\n a[j] = 0;\n b[j] = 0;\n break;\n case \"1\":\n a[j] = 1;\n b[j] = 0;\n isNG = true;\n break;\n case \"2\":\n a[j] = 1;\n b[j] = 1;\n break;\n }\n }else{\n switch(x[j]){\n case \"0\":\n a[j] = 0;\n b[j] = 0;\n break;\n case \"1\":\n a[j] = 0;\n b[j] = 1;\n break;\n case \"2\":\n a[j] = 0;\n b[j] = 2;\n break;\n }\n }\n }\n output[i * 2] = myconv(a,0);\n output[i * 2 + 1] = myconv(b,0);\n }\n myout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar first, current = 0, readBlock = false;\n\nvar data = [];\n\nrl.on('line', function(line){\n if (first === undefined) {\n first = +line;\n } else {\n if (!readBlock) {\n readBlock = true;\n data.push({\n length: +line\n });\n } else {\n data[data.length - 1].value = line;\n current++;\n readBlock = false;\n }\n }\n\n if (first === current) rl.close();\n});\n\nrl.on('close', function() {\n data.forEach(test => {\n let a = '', b = '';\n let swapped = false;\n test.value.split('').forEach((val, i) => {\n if (i === 0) {\n a += '1';\n b += '1';\n\n return;\n }\n const number = +val;\n if (number === 2) {\n if (!swapped) {\n a += '1';\n b += '1';\n } else {\n a += '0';\n b += '2';\n }\n } else {\n if (number === 1) {\n a += '0';\n b += '1';\n if (!swapped) {\n let x = a;\n\n a = b;\n b = x;\n swapped = true;\n }\n } else {\n a += '0';\n b += '0';\n }\n }\n });\n\n console.log(a);\n console.log(b);\n });\n});\n"}, {"source_code": "// const SegmentTree = require('javascript-algo-ds/src/data-structure/trees/segmentTree/segmentTree')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const x = readString()\n const a = new Array(n)\n const b = new Array(n)\n for(let i = 0, j = false; i < n; i++) {\n if(x[i] === '2') {\n if(!j) a[i] = b[i] = 1\n else {\n a[i] = 0\n b[i] = 2\n }\n }\n else if(x[i] === '0') {\n a[i] = b[i] = 0\n }\n else {\n if(!j) {\n a[i] = 1\n b[i] = 0\n j = true\n }\n else {\n a[i] = 0\n b[i] = 1\n }\n }\n }\n wr(a.join(''))\n wr(b.join(''))\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var s = readline();\n var state = \"perfect\";\n var a = [], b = [];\n for (var i = 0; i < s.length; i++) {\n if (state == \"perfect\") {\n switch (s[i]) {\n case '2':\n a.push('1');\n b.push('1');\n break;\n case '1':\n a.push('1');\n b.push('0');\n state = \"complete\";\n break;\n case '0':\n a.push('0');\n b.push('0');\n break;\n }\n }\n else {\n switch (s[i]) {\n case '2':\n a.push('0');\n b.push('2');\n break;\n case '1':\n a.push('0');\n b.push('1');\n break;\n case '0':\n a.push('0');\n b.push('0');\n break;\n }\n }\n }\n print(a.join(\"\"));\n print(b.join(\"\"));\n }\n}\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n while (t--) {\n getNextLine();\n const s = getNextLine();\n solve(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(''));\n console.log(resultsB.join(''));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n solve(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(\"\"));\n console.log(resultsB.join(\"\"));\n};\n"}, {"source_code": "const mod = 998244353\n\n\nconst processData = (lines) => {\n const n = +lines[0]\n for(let j =0; j +x)\n const a = Array(s.length).fill(0)\n const b = Array(s.length).fill(0)\n let first = true\n for (let i =0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const x = getLine()[0]\n const a = [1]\n const b = [1]\n let f = false\n\n for (let i = 1; i < n; ++i) {\n if (x[i] === '2') {\n if (f) {\n a[i] = 0\n b[i] = 2\n } else {\n a[i] = b[i] = 1\n }\n } else if (x[i] === '1') {\n if (f) {\n a[i] = 0 \n b[i] = 1\n } else {\n a[i] = 1\n b[i] = 0\n }\n f = true\n } else {\n a[i] = b[i] = 0\n }\n }\n\n print(a.join(''))\n print(b.join(''))\n }\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;r {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n if (t === 10000 && i === 6553) console.log(s);\n solve(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(''));\n console.log(resultsB.join(''));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n if (t === 10000 && i === 6553) console.log(s);\n if (t !== 10000) solve(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(''));\n console.log(resultsB.join(''));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n while (t--) {\n getNextLine();\n const s = getNextLine();\n solve(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(''));\n console.log(resultsB.join(''));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n if (t === 10000) {\n if (s !== '22222') console.log('GO', s);\n } else {\n solve(s);\n }\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(\"\"));\n console.log(resultsB.join(\"\"));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n if (t === 10000) {\n if ([6553, 6554, 6555].includes(i)) console.log(i, s);\n } else {\n solve(s);\n }\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(\"\"));\n console.log(resultsB.join(\"\"));\n};\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\n// ====================================================================\n\nconst run = () => {\n let t = Number.parseInt(getNextLine());\n\n for (let i = 0; i < t; i++) {\n getNextLine();\n const s = getNextLine();\n if (i === 6553) console.log(s);\n }\n};\n\nconst solve = s => {\n const resultsA = [];\n const resultsB = [];\n\n let index = 0;\n while (index < s.length && [\"0\", \"2\"].includes(s[index])) {\n const nextValue = Number(s[index]) / 2;\n resultsA.push(nextValue);\n resultsB.push(nextValue);\n index += 1;\n }\n\n if (index < s.length) {\n resultsA.push(1);\n resultsB.push(0);\n }\n\n for (let i = index + 1; i < s.length; i++) {\n resultsA.push(0);\n resultsB.push(s[i]);\n }\n\n console.log(resultsA.join(''));\n console.log(resultsB.join(''));\n};\n"}], "src_uid": "c4c8cb860ea9a5b56bb35532989a9192"} {"source_code": "const read = [];\n\nlet n;\nconst MAXN=2e5;\nconst arr=new Array(MAXN+1).fill(null);\n\nconst RL = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nRL.on('line', line => {\n read.push(line.trim());\n});\n\nconst solve=function (current, next){\n const vector=[];\n let nextnext=null;\n let count=n;\n\n while(count--){\n if(next===arr[current][0]){\n nextnext=arr[current][1];\n } else if(next===arr[current][1]){\n nextnext=arr[current][0];\n } else{\n return false;\n }\n\n vector.push(current);\n\n current=next;\n next=nextnext;\n }\n\n console.log(`${vector.join(' ')}`);\n return true;\n};\n\nRL.on('close', () => {\n n=parseInt(read[0]);\n for(let i=1; i<=n; i+=1){\n arr[i]=read[i].split(' ').map(el=>parseInt(el));\n }\n\n let flag;\n flag=solve(1, arr[1][0]);\n if(!flag){\n solve(1, arr[1][1]);\n }\n});\n", "positive_code": [{"source_code": "function task([n, ...pairs]) {\n pairs = pairs.map(p => p.split(' ').map(n => Number(n)));\n\n let result = [];\n let presense = new Array(pairs.length + 1);\n let index = 1;\n\n while (result.length !== pairs.length) {\n result.push(index);\n presense[index] = true;\n\n const [a, b] = pairs[index - 1];\n const aPair = pairs[a - 1];\n const bPair = pairs[b - 1];\n\n if (aPair.includes(b) && !presense[a]) {\n index = a;\n } else if (bPair.includes(a)) {\n index = b;\n }\n }\n\n return result.join(' ');\n}\n\nfunction test() {\n const assert = (result, expectation, unordered) => {\n if (unordered) {\n result = result.split(' ');\n expectation = expectation.split(' ');\n\n if (result.sort().join(' ') !== expectation.sort().join(' ')) {\n console.error(`${result}: ${expectation}`);\n }\n } else if (result !== expectation) {\n console.error(`${result}: ${expectation}`);\n }\n };\n\n // assert(task(['5', '3 5', '1 4', '2 4', '1 5', '2 3']), '3 2 4 1 5');\n // assert(task(['3', '2 3', '3 1', '1 2']), '3 1 2');\n assert(task(['3', '3 2', '3 1', '1 2']), '2 1 3');\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)));\n } else {\n test();\n }\n}\n\nrun();\n"}], "negative_code": [{"source_code": "function task([n, ...pairs]) {\n pairs = pairs.map(p => p.split(' ').map(n => Number(n)));\n\n let result = [];\n let index = 1;\n\n while (result.length !== pairs.length) {\n result.push(index);\n\n const [a, b] = pairs[index - 1];\n const aPair = pairs[a - 1];\n const bPair = pairs[b - 1];\n\n if (aPair.includes(b)) {\n index = a;\n }\n\n if (bPair.includes(a)) {\n index = b;\n }\n }\n\n return result.join(' ');\n}\n\nfunction test() {\n const assert = (result, expectation) => {\n if (result !== expectation) throw new Error(`${result}: ${expectation}`);\n };\n\n assert(task(['5', '3 5', '1 4', '2 4', '1 5', '2 3']), '3 2 4 1 5');\n // assert(task(['3', '2 3', '3 1', '1 2']), '3 1 2');\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)));\n } else {\n test();\n }\n}\n\nrun();\n"}, {"source_code": "function task([n, ...pairs]) {\n pairs = pairs.map(p => p.split(' ').map(n => Number(n)));\n\n console.log(pairs);\n\n let result = [];\n\n const findNext = (index) => {\n if (result.length === pairs.length) {\n return;\n }\n\n result.push(index);\n\n const [a, b] = pairs[index - 1];\n const aPair = pairs[a - 1];\n const bPair = pairs[b - 1];\n\n if (aPair.includes(b)) {\n findNext(a);\n }\n\n if (bPair.includes(a)) {\n findNext(b);\n }\n };\n\n findNext(1);\n\n return result.join(' ');\n}\n\nfunction test() {\n const assert = (result, expectation) => {\n if (result !== expectation) throw new Error(`${result}: ${expectation}`);\n };\n\n assert(task(['5', '3 5', '1 4', '2 4', '1 5', '2 3']), '3 2 4 1 5');\n // assert(task(['3', '2 3', '3 1', '1 2']), '3 1 2');\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)));\n } else {\n test();\n }\n}\n\nrun();\n"}], "src_uid": "819d3694fccf2b5af0ec3b4ee429dbb3"} {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar nk = readline().split(\" \").map(x => parseInt(x));\n\tvar n = nk[0];\n\tvar k = nk[1];\n\tvar h = readline().split(\" \").map(x => parseInt(x));\n\n\tvar ans = 0;\n\tfor (j = 0; j < k; j++) {\n\t\tans = -1;\n\t\tfor (i = 1; i < n; i++) {\n\t\t\tif (h[i - 1] < h[i]) {\n\t\t\t\tans = i;\n\t\t\t\th[i - 1]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ans == -1) break;\n\t}\n\tprint(ans);\n}\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let line = readline().split(' ').map(x => +x)\n let n = line[0]\n let k = line[1]\n let arr = readline().split(' ').map(x => +x)\n // ====== SOLUTION ======\n while(k--){ \n // console.log('inside While k = ', k)\n let i = 0\n for(; i < n-1; i++){\n if(arr[i] < arr[i+1]){\n arr[i]++\n break\n }\n }\n if(k != 0 && i == n-1){\n console.log('-1')\n break\n }\n if(k == 0){\n if(i == n-1)\n console.log(-1)\n else\n console.log(i+1)\n }\n // console.log('k = ', k)\n }\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var array = readline().split(' ').map(x => Number(x));\r\n var last = array[n - 1]\r\n var answer = 0\r\n array.map((x, i) => {\r\n if (i === 0) return\r\n if (x < last) answer += last - x\r\n })\r\n var i = 0\r\n var answer = 0\r\n while (k > 0) {\r\n if (i === n) {\r\n answer = -1\r\n break\r\n }\r\n // console.log(array[i], array[i + 1], array[i] < array[i + 1])\r\n\r\n if (array[i] < array[i + 1]) {\r\n k--\r\n array[i]++\r\n if (k === 0) break\r\n i = 0\r\n } else {\r\n i++\r\n }\r\n // console.log(array)\r\n }\r\n console.log(answer ? answer : (i+1))\r\n // console.log(k)\r\n })\r\n\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar last = -1;\r\n\t\twhile(K > 0){\r\n\t\t\tvar isOK = false;\r\n\t\t\tfor(var j = 0; j < N - 1; j++){\r\n\t\t\t\tif(list[j] < list[j + 1]){\r\n\t\t\t\t\tlist[j]++;\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tlast = j + 1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(!isOK){\r\n\t\t\t\tlast = -1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tK--;\r\n\t\t}\r\n\t\tmyout(last);\r\n\t}\r\n}"}, {"source_code": "/*\r\n * File Created: Friday, 5th February 2021 3:53:54 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [n,k] = readLine().split(' ').map(Number);\r\n\r\n const h = readLine().split(' ').map(Number);\r\n\r\n const res = b(n,k,h);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction a(px,py,s)\r\n{\r\n // if px > 0 than search for R else L\r\n // if py > 0 than search for U else D\r\n let U = 0;\r\n let D = 0;\r\n let R = 0;\r\n let L = 0;\r\n for(let i = 0 ; i < s.length; i++){\r\n if(s[i] === 'U') U++;\r\n else if(s[i] === 'D') D++;\r\n else if(s[i] === 'R') R++;\r\n else if(s[i] === 'L') L++;\r\n }\r\n if(px > 0){\r\n if(px > R) return 'NO';\r\n } \r\n if(px < 0) {\r\n if(Math.abs(px) > L) return 'NO';\r\n }\r\n if(py > 0){\r\n if(py > U) return 'NO';\r\n } \r\n if(py < 0) {\r\n if(Math.abs(py) > D) return 'NO';\r\n }\r\n return 'YES'; \r\n}\r\n\r\nfunction b(n,k,h){\r\n // find the last boulder's fail position or if it was waisted in the dump (-1)\r\n const boulders = new Array(k);\r\n let j = 0;\r\n while(k){\r\n for(let i = 0 ; i < h.length; i++){\r\n if(h[i] < h[i + 1]){\r\n h[i] = h[i] + 1;\r\n boulders[j++] = i+1;\r\n k--;\r\n break;\r\n }\r\n if(i === h.length - 1){\r\n boulders[j++] = -1;\r\n k--;\r\n return -1;\r\n }\r\n }\r\n }\r\n return boulders[boulders.length - 1];\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let cnt = 0,\r\n i = 0;\r\n while (cnt < k) {\r\n for (i = 0; i < n - 1; i++) {\r\n if (arr[i] < arr[i + 1]) {\r\n arr[i]++;\r\n cnt++;\r\n break;\r\n }\r\n }\r\n if (i == n - 1) break;\r\n }\r\n if (cnt === k) console.log(i + 1);\r\n else console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "/*\r\n * File Created: Friday, 5th February 2021 3:53:54 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [n,k] = readLine().split(' ').map(Number);\r\n\r\n const h = readLine().split(' ').map(Number);\r\n\r\n const res = a(n,k,h);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction a(px,py,s)\r\n{\r\n // if px > 0 than search for R else L\r\n // if py > 0 than search for U else D\r\n let U = 0;\r\n let D = 0;\r\n let R = 0;\r\n let L = 0;\r\n for(let i = 0 ; i < s.length; i++){\r\n if(s[i] === 'U') U++;\r\n else if(s[i] === 'D') D++;\r\n else if(s[i] === 'R') R++;\r\n else if(s[i] === 'L') L++;\r\n }\r\n if(px > 0){\r\n if(px > R) return 'NO';\r\n } \r\n if(px < 0) {\r\n if(Math.abs(px) > L) return 'NO';\r\n }\r\n if(py > 0){\r\n if(py > U) return 'NO';\r\n } \r\n if(py < 0) {\r\n if(Math.abs(py) > D) return 'NO';\r\n }\r\n return 'YES'; \r\n}\r\n\r\nfunction b(n,k,h){\r\n // find the last boulder's fail position or if it was waisted in the dump (-1)\r\n const boulders = [];\r\n while(k){\r\n for(let i = 0 ; i < h.length; i++){\r\n if(h[i] < h[i + 1]){\r\n h[i] = h[i] + 1;\r\n boulders.push(i+1);\r\n k--;\r\n break;\r\n }\r\n if(i === h.length - 1){\r\n boulders.push(-1);\r\n k--;\r\n }\r\n }\r\n }\r\n return boulders[boulders.length - 1];\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let max = arr[n - 1],\r\n cnt = 0,\r\n pos = n - 1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (arr[i] < max) {\r\n cnt += max - arr[i];\r\n pos = i + 1;\r\n } else max = arr[i];\r\n }\r\n if (k - cnt > 0) console.log(-1);\r\n else console.log(pos);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "32855bb8ba33973178fde7c3d0beb2ce"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar value = 0;\n\tfor (var r = 0; r < n; ++r) {\n\t\tvar row = readline();\n\t\tvalue ^= (row.charAt(2*r) == '0' ? 0 : 1);\n\t}\n\n\tvar queryNum = parseInt(readline());\n\tvar results = [];\n\tfor (var i = 0; i < queryNum; ++i) {\n\t\tvar data = tokenizeIntegers(readline());\n\t\tif (data[0] == 3) {\n\t\t\tresults.push(value);\n\t\t}\n\t\telse {\n\t\t\tvalue ^= 1;\n\t\t}\n\t}\n\tprint(results.join(\"\"));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar value = 0;\n\tfor (var r = 0; r < n; ++r) {\n\t\tvar row = readline();\n\t\tvalue ^= (row.charAt(2*r) == '0' ? 0 : 1);\n\t}\n\n\tvar queryNum = parseInt(readline());\n\tvar results = [];\n\tfor (var q = 0; q < queryNum; ++q) {\n\t\tvar data = tokenizeIntegers(readline());\n\t\tif (data[0] == 3) {\n\t\t\tresults.push(value);\n\t\t}\n\t\telse {\n\t\t\tvalue ^= 1;\n\t\t}\n\t}\n\tprint(results.join(\"\"));\n}\n\nmain();\n"}, {"source_code": "var n = +readline();\nvar s = [];\nvar A = 0;\nvar ans = '';\nfor (var i=0; i 1) {\n\t\t\tj--;\n\t\t\tmin += Math.ceil(j / 2);\n\t\t\tmax += j;\n\t\t}\n\t}\n\n\treturn min + ' ' + max;\n\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": ";(function () {\n\tprint(function () {\n\t\tvar l = readline().split(' ').map(Number),\n\t\t\tx = l[0], k = l[1];\n\n\t\tvar t = [];\n\t\tfor (var i = 0; i < x - 1; i++) {\n\t\t\tt.push(false);\n\t\t}\n\n\n\t\tfor (var i = 0; i < k; i++) {\n\t\t\tvar q = readline().split(' ').map(Number);\n\t\t\tt[q[1] - 1] = true;\n\t\t\tif (q[0] === 1) {\n\t\t\t\tt[q[2] - 1] = true;\n\t\t\t}\n\t\t}\n\n\t\tt = t.map(function(e, i) {\n\t\t\treturn e === false ? i + 1 : e;\n\t\t}).filter(function (e) {\n\t\t\treturn e === parseInt(e);\n\t\t});\n\n\t\tvar max = t.length;\n\t\tvar no_max = 0;\n\t\tfor (var i = 0, _i = max - 1; i < _i; i++) {\n\t\t\tif (t[i] === t[i + 1] - 1) {\n\t\t\t\ti++;\n\t\t\t\tno_max++;\n\t\t\t}\n\t\t}\n\n\t\treturn [max - no_max, max].join(' ');\n\t}());\n}).call(this);\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar today = integers[0], missedCount = integers[1];\n\n\tvar seen = new Array(today+1);\n\tfor (var i = 0; i < missedCount; ++i) {\n\t\tvar missed = tokenizeIntegers(readline());\n\t\tfor (var j = 1; j < missed.length; ++j) {\n\t\t\tseen[missed[j]] = true;\n\t\t}\n\t}\n\tseen[today] = true;\n\n\tvar min = 0, max = 0;\n\tvar pos = 1;\n\twhile (pos < today) {\n\t\tvar span = 0;\n\t\twhile (seen[pos] != true) {\n\t\t\tspan += 1;\n\t\t\tpos += 1;\n\t\t}\n\t\tmax += span;\n\t\tmin += span%2 + Math.floor(span/2);\n\t\twhile (seen[pos] == true && pos < today) {\n\t\t\tpos += 1;\n\t\t}\n\t}\n\n\tprint(min+\" \"+max);\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "fb77c9339250f206e7188b951902a221"} {"source_code": "var n = +readline();\n\nvar a = [ n ];\n\nfor ( var i = 1; i < n; i++ )\n\ta.push( i );\n\nprint( a.join( ' ' ) );", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const result = [];\n\n result.push(len);\n for (let i = 1; i < len; i++) {\n result.push(i);\n }\n\n console.log(result.join(\" \"));\n}\n"}, {"source_code": "\nfunction read_input(){\n var n ;\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n })\n \n readline.question(\"\", (n) => {\n //console.log(`Hi ${name}!`)\n console.log(n);\n for(i=1 ; i <= n-1 ;i++){\n console.log(i);}\n readline.close()\n })\n}\n\nread_input()\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet a = [n];\n\tfor (let i = 1; i < n; ++i) {\n\t\ta.push(i);\n\t}\n\tconsole.log(a.join(' '));\n}\n"}, {"source_code": "function f (x) {\n\tif (x === 1)return;\n\telse f(x-1);\n\n\tswap(a[x-1], a[x]);\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\tvar a = [];\n\tfor (var i = 1; i <= n; i++) a.push(i);\n\ta.unshift(a.pop());\n\tprint(a.join(' '));\n\n}).call(this);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let numbers = [];\n for (let i = 1; i < n; i++) {\n numbers.push(i);\n }\n console.log(n, ...numbers);\n}\n"}, {"source_code": "var n = Number(readline());\nvar a = [n];\nfor (var i = 1; i < n; i++) a.push(i);\nprint(a.join(' '));\n"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet a = [];\n\tfor (let i = n; i >= 1; --i) {\n\t\ta.push(i);\n\t}\n\tconsole.log(a.join(' '));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let numbers = [];\n for (let i = n; i >= 1; i--) {\n numbers.push(i);\n }\n console.log(...numbers);\n}\n"}, {"source_code": "function f (x) {\n\tif (x === 1)return;\n\telse f(x-1);\n\n\tswap(a[x-1], a[x]);\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\tif (n === 1) {\n\t\tprint(1);\n\t\treturn;\n\t}\n\n\tvar a = [2, 1];\n\n\tfor (var i = 3; i <=n; i++) a.push(i);\n\n\tprint(a.join(' '));\n\n}).call(this);"}, {"source_code": "function f (x) {\n\tif (x === 1)return;\n\telse f(x-1);\n\n\tswap(a[x-1], a[x]);\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\tif (n === 1) {\n\t\tprint(1);\n\t\treturn;\n\t}\n\n\tvar a = [2, 1];\n\n\tfor (var i = 3; i <=n; i++) a.unshift(i);\n\n\tprint(a.join(' '));\n\n}).call(this);"}, {"source_code": "var n = Number(readline());\nvar a = [];\nfor (var i = 2; i <= n; i++) a.push(i);\na.push(1);\nprint(a.join(' '));\n"}], "src_uid": "d9ba1dfe11cf3dae177f8898f3abeefd"} {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/28/21 night\r\n\r\nconst solve = (n, a) => {\r\n let pq = new MinPriorityQueue({ priority: x => x });\r\n let res = sum = 0;\r\n for (const e of a) {\r\n sum += e;\r\n res++;\r\n if (e < 0) {\r\n pq.enqueue(e);\r\n while (sum < 0) {\r\n sum -= pq.dequeue().element;\r\n res--;\r\n }\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nclass HeapNode {\r\n constructor(key, value) {\r\n this._key = key;\r\n this._value = value;\r\n }\r\n\r\n getKey() {\r\n return this._key;\r\n }\r\n\r\n getValue() {\r\n return this._value;\r\n }\r\n}\r\n\r\nconst isNumber = (n) => typeof n === 'number';\r\nconst isNoneEmptyString = (s) => typeof s === 'string' && s.length;\r\nconst isNoneNullObject = (o) => typeof o === 'object' && o !== null;\r\nconst isNoneEmptyArray = (a) => Array.isArray(a) && a.length > 0;\r\n\r\nclass Heap {\r\n constructor(nodes) {\r\n this._nodes = Array.isArray(nodes) ? nodes : [];\r\n this._leaf = null;\r\n }\r\n\r\n _getLeftChildIndex(parentIndex) {\r\n return (parentIndex * 2) + 1;\r\n }\r\n\r\n _getRightChildIndex(parentIndex) {\r\n return (parentIndex * 2) + 2;\r\n }\r\n\r\n _getParentIndex(childIndex) {\r\n return Math.floor((childIndex - 1) / 2);\r\n }\r\n\r\n _getLastIndex() {\r\n return this._nodes.length - 1;\r\n }\r\n\r\n _swap(i, j) {\r\n const temp = this._nodes[i];\r\n this._nodes[i] = this._nodes[j];\r\n this._nodes[j] = temp;\r\n }\r\n\r\n _compareChildrenOf(parentIndex) {\r\n const leftChildIndex = this._getLeftChildIndex(parentIndex);\r\n const rightChildIndex = this._getRightChildIndex(parentIndex);\r\n const size = this.size();\r\n if (leftChildIndex >= size && rightChildIndex >= size) return -1;\r\n if (leftChildIndex >= size) return rightChildIndex;\r\n if (rightChildIndex >= size) return leftChildIndex;\r\n return this._compareChildren(leftChildIndex, rightChildIndex);\r\n }\r\n\r\n _heapifyUp() {\r\n let childIndex = this._getLastIndex();\r\n let parentIndex = this._getParentIndex(childIndex);\r\n while (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n childIndex = parentIndex;\r\n parentIndex = this._getParentIndex(childIndex);\r\n }\r\n }\r\n\r\n _heapifyDown() {\r\n let parentIndex = 0;\r\n let childIndex = this._compareChildrenOf(parentIndex);\r\n while (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n parentIndex = childIndex;\r\n childIndex = this._compareChildrenOf(parentIndex);\r\n }\r\n }\r\n\r\n _heapifyDownUntil(index) {\r\n let parentIndex = 0;\r\n let leftChildIndex = 1;\r\n let rightChildIndex = 2;\r\n let childIndex;\r\n while (leftChildIndex < index) {\r\n childIndex = this._compareChildrenBefore(\r\n index,\r\n leftChildIndex,\r\n rightChildIndex\r\n );\r\n if (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n }\r\n parentIndex = childIndex;\r\n leftChildIndex = this._getLeftChildIndex(parentIndex);\r\n rightChildIndex = this._getRightChildIndex(parentIndex);\r\n }\r\n }\r\n\r\n _clone(HeapType) {\r\n return new HeapType(this._nodes.slice());\r\n }\r\n\r\n sort() {\r\n for (let i = this._getLastIndex(); i > 0; i -= 1) {\r\n this._swap(0, i);\r\n this._heapifyDownUntil(i);\r\n }\r\n return this._nodes;\r\n }\r\n\r\n insert(key, value) {\r\n const newNode = new HeapNode(key, value);\r\n this._nodes.push(newNode);\r\n this._heapifyUp();\r\n return newNode;\r\n }\r\n\r\n root() {\r\n if (this.isEmpty()) return null;\r\n return this._nodes[0];\r\n }\r\n\r\n leaf() {\r\n return this._leaf;\r\n }\r\n\r\n extractRoot() {\r\n if (this.isEmpty()) return null;\r\n const root = this.root();\r\n this._nodes[0] = this._nodes[this._getLastIndex()];\r\n this._nodes.pop();\r\n this._heapifyDown();\r\n if (root === this._leaf) {\r\n if (this.isEmpty()) {\r\n this._leaf = null;\r\n } else {\r\n this._leaf = this.root();\r\n }\r\n }\r\n return root;\r\n }\r\n\r\n size() {\r\n return this._nodes.length;\r\n }\r\n\r\n isEmpty() {\r\n return this.size() === 0;\r\n }\r\n\r\n clear() {\r\n this._nodes = [];\r\n this._leaf = null;\r\n }\r\n\r\n static _heapify(items, HeapType) {\r\n if (!isNoneEmptyArray(items)) return null;\r\n const heap = new HeapType();\r\n items.forEach((item) => {\r\n if (isNumber(item) || isNoneEmptyString(item)) {\r\n heap.insert(item);\r\n } else if (isNoneNullObject(item) &&\r\n (isNumber(item.key) || isNoneEmptyString(item.key))) {\r\n heap.insert(item.key, item.value);\r\n }\r\n });\r\n return heap;\r\n }\r\n}\r\n\r\nclass MinHeap extends Heap {\r\n _getMinChildIndex(leftChildIndex, rightChildIndex) {\r\n const leftChild = this._nodes[leftChildIndex];\r\n const rightChild = this._nodes[rightChildIndex];\r\n if (leftChild.getKey() < rightChild.getKey()) {\r\n return leftChildIndex;\r\n }\r\n return rightChildIndex;\r\n }\r\n\r\n _getMinChildIndexBefore(index, leftChildIndex, rightChildIndex) {\r\n const leftChild = this._nodes[leftChildIndex];\r\n const rightChild = this._nodes[rightChildIndex];\r\n if (rightChild.getKey() < leftChild.getKey() && rightChildIndex < index) {\r\n return rightChildIndex;\r\n }\r\n return leftChildIndex;\r\n }\r\n\r\n _shouldSwap(childIndex, parentIndex) {\r\n if (childIndex < 0 || childIndex >= this.size()) return false;\r\n if (parentIndex < 0 || parentIndex >= this.size()) return false;\r\n const child = this._nodes[childIndex];\r\n const parent = this._nodes[parentIndex];\r\n return child.getKey() < parent.getKey();\r\n }\r\n\r\n _compareChildren(leftChildIndex, rightChildIndex) {\r\n return this._getMinChildIndex(leftChildIndex, rightChildIndex);\r\n }\r\n\r\n _compareChildrenBefore(index, leftChildIndex, rightChildIndex) {\r\n return this._getMinChildIndexBefore(index, leftChildIndex, rightChildIndex);\r\n }\r\n\r\n insert(key, value) {\r\n const newNode = super.insert(key, value);\r\n if (this._leaf === null || key > this._leaf.getKey()) {\r\n this._leaf = newNode;\r\n }\r\n return newNode;\r\n }\r\n\r\n clone() {\r\n return super._clone(MinHeap);\r\n }\r\n\r\n static heapify(items) {\r\n return super._heapify(items, MinHeap);\r\n }\r\n}\r\n\r\nclass PriorityQueue {\r\n constructor(options = {}) {\r\n const {\r\n priority\r\n } = options;\r\n if (priority !== undefined && typeof priority !== 'function') {\r\n throw new Error('invalid priority callback');\r\n }\r\n this._getPriority = typeof priority === 'function' ? priority : null;\r\n }\r\n\r\n size() {\r\n return this._heap.size();\r\n }\r\n\r\n isEmpty() {\r\n return this._heap.isEmpty();\r\n }\r\n\r\n front() {\r\n if (this.isEmpty()) return null;\r\n const first = this._heap.root();\r\n return {\r\n priority: first.getKey(),\r\n element: first.getValue()\r\n };\r\n }\r\n\r\n back() {\r\n if (this.isEmpty()) return null;\r\n const last = this._heap.leaf();\r\n return {\r\n priority: last.getKey(),\r\n element: last.getValue()\r\n };\r\n }\r\n\r\n enqueue(element, p) {\r\n if (p && Number.isNaN(+p)) {\r\n throw new Error('invalid priority number');\r\n }\r\n if (Number.isNaN(+p) && this._getPriority === null) {\r\n throw new Error('missing priority number or constructor callback');\r\n }\r\n const priority = !Number.isNaN(+p) ? p : this._getPriority(element);\r\n this._heap.insert(priority, element);\r\n }\r\n\r\n dequeue() {\r\n if (this.isEmpty()) return null;\r\n const first = this._heap.extractRoot();\r\n return {\r\n priority: first.getKey(),\r\n element: first.getValue()\r\n };\r\n }\r\n\r\n toArray() {\r\n return this._heap\r\n .clone()\r\n .sort()\r\n .map((n) => ({\r\n priority: n.getKey(),\r\n element: n.getValue()\r\n }))\r\n .reverse();\r\n }\r\n\r\n clear() {\r\n this._heap.clear();\r\n }\r\n}\r\n\r\nclass MinPriorityQueue extends PriorityQueue {\r\n constructor(options) {\r\n super(options);\r\n this._heap = new MinHeap();\r\n }\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let t = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] >= 0) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n if (t === -1) return 0;\r\n const dp = new Array(n).fill(0);\r\n const heap = new Heap((a, b) => a - b);\r\n let sum = 0;\r\n for (let i = t; i < n; i++) {\r\n var _dp;\r\n if (a[i] < 0) heap.push(a[i]);\r\n sum += a[i];\r\n dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n while (sum < 0) {\r\n sum -= heap.pop();\r\n dp[i]--;\r\n }\r\n }\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n res = Math.max(res, dp[i]);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\nvar dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst a = rna();\r\n\r\n\tlet health = 0, used = 0;\r\n\tconst q = new PriorityQueue((a, b) => a > b);\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (a[i] >= 0) {\r\n\t\t\thealth += a[i];\r\n\t\t\tused++;\r\n\t\t} else {\r\n\t\t\ta[i] = -a[i];\r\n\t\t\tif (health - a[i] >= 0) {\r\n\t\t\t\thealth -= a[i];\r\n\t\t\t\tq.push(a[i]);\r\n\t\t\t\tused++;\r\n\t\t\t} else {\r\n\t\t\t\tif (a[i] < q.peek()) {\r\n\t\t\t\t\thealth += q.pop() - a[i];\r\n\t\t\t\t\tq.push(a[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(used);\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let t = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] >= 0) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n if (t === -1) return -1;\r\n const dp = new Array(n).fill(0);\r\n const heap = new Heap((a, b) => a - b);\r\n let sum = 0;\r\n for (let i = t; i < n; i++) {\r\n var _dp;\r\n if (a[i] < 0) heap.push(a[i]);\r\n sum += a[i];\r\n dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n while (sum < 0) {\r\n sum -= heap.pop();\r\n dp[i]--;\r\n }\r\n }\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n res = Math.max(res, dp[i]);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let sum = a.reduce((a, b) => a + b, 0);\r\n if (sum >= 0) return n;\r\n let t = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] >= 0) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n if (t === -1) return 0;\r\n a = a.slice(t).sort((a, b) => a - b);\r\n sum = a.reduce((a, b) => a + b, 0);\r\n if (sum >= 0) return a.length;\r\n for (let i = 0; i < a.length; i++) {\r\n sum -= a[i];\r\n if (sum >= 0) return a.length - i - 1;\r\n }\r\n return 0;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let sum = a.reduce((a, b) => a + b, 0);\r\n if (sum >= 0) return n;\r\n a.sort((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n sum -= a[i];\r\n if (sum >= 0) return n - i - 1;\r\n }\r\n return 0;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/C\r\n */\r\n\r\n// let a, n;\r\nlet res, a, n;\r\nconst solve = (N, A) => {\r\n n = N;\r\n a = A;\r\n // pr(n, a);\r\n res = 0;\r\n // let res = mx(dfs(0, 0, 0, 'skip'), dfs(0, 0, 0, 'take'));\r\n dfs(0, 0, 0, 'skip');\r\n dfs(0, 0, 0, 'take');\r\n pr(res);\r\n};\r\n\r\nconst dfs = (cnt, idx, cur, action) => {\r\n // pr(cnt, idx, cur, action);\r\n if (action == 'take') cur += a[idx];\r\n if (cur < 0) {\r\n // pr(cnt, idx, cur, action);\r\n res = mx(res, cnt - 1);\r\n return;\r\n }\r\n for (let i = idx + 1; i < n; i++) {\r\n dfs(cnt + 1, i, cur, 'skip');\r\n dfs(cnt + 1, i, cur, 'take');\r\n }\r\n res = mx(res, cnt);\r\n // return cnt;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()\r\n\r\n// pr(2000 * 10 ** 9 < Number.MAX_SAFE_INTEGER);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/C\r\n */\r\n\r\n// let a, n;\r\nlet res, a, n;\r\nconst solve = (N, A) => {\r\n n = N;\r\n a = A;\r\n pr(n, a);\r\n res = 0;\r\n // let res = mx(dfs(0, 0, 0, 'skip'), dfs(0, 0, 0, 'take'));\r\n dfs(0, 0, 0, 'skip');\r\n dfs(0, 0, 0, 'take');\r\n pr(res);\r\n};\r\n\r\nconst dfs = (cnt, idx, cur, action) => {\r\n // pr(cnt, idx, cur, action);\r\n if (action == 'take') cur += a[idx];\r\n if (cur < 0) {\r\n // pr(cnt, idx, cur, action);\r\n res = mx(res, cnt - 1);\r\n return;\r\n }\r\n for (let i = idx + 1; i < n; i++) {\r\n dfs(cnt + 1, i, cur, 'skip');\r\n dfs(cnt + 1, i, cur, 'take');\r\n }\r\n res = mx(res, cnt);\r\n // return cnt;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()\r\n\r\n// pr(2000 * 10 ** 9 < Number.MAX_SAFE_INTEGER);"}], "src_uid": "affef141c51bbfd881a90d49ec34ceea"} {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [],\r\n numTestCases;\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === (2 * (+input[0]) + 1)) {\r\n rl.close();\r\n numTestCases = +input[0];\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n for (let i = 0; i < numTestCases * 2; ++i) {\r\n let currCaseConsts = input[i].split(' '),\r\n currCaseString = input[++i],\r\n n = +currCaseConsts[0],\r\n a = +currCaseConsts[1],\r\n b = +currCaseConsts[2]; \r\n\r\n console.log(getMaxPoints(currCaseString, n, a, b));\r\n }\r\n}\r\n\r\nfunction getMaxPoints(currCaseString, n, a, b) {\r\n let numConsecGroups = 1;\r\n\r\n for (let i = 1; i < n; ++i) {\r\n if (currCaseString.charAt(i - 1) !== currCaseString.charAt(i)) {\r\n ++numConsecGroups;\r\n }\r\n }\r\n\r\n return (b >= 0) ? n * (a + b) : (n * a) + ((Math.floor(numConsecGroups/2) + 1) * b);\r\n}", "positive_code": [{"source_code": "var x = parseInt(readline());\r\n\r\nfor(i = 0; i < x; i++)\r\n{\r\n var n = readline().split(\" \");\r\n var a = parseInt(n[1]);\r\n var b = parseInt(n[2]);\r\n n = parseInt(n[0]);\r\n var string = readline();\r\n \r\n if(b > 0) print(n * (a + b));\r\n else if(b === 0) print(n * a);\r\n else if(n === 1) print(a + b);\r\n else {\r\n var substring = [], sum = 0;\r\n for(j = 0; j < n; j++) {\r\n var k = j + 1;\r\n while(string[k] === string[j]) { k++; }\r\n substring[substring.length] = k - j;\r\n j = k - 1;\r\n }\r\n while(substring !== []) {\r\n if(substring.length === 1) {\r\n sum += a * substring[0] + b;\r\n break;\r\n }\r\n sum += a * substring[substring.length - 2] + b;\r\n if(substring.length === 2) {\r\n sum += a * substring[1] + b;\r\n break;\r\n }\r\n else {\r\n substring[substring.length - 3] += substring[substring.length - 1];\r\n substring = substring.slice(0, substring.length - 2);\r\n }\r\n }\r\n print(sum);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, a, b] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n if (b >= 0) {\r\n console.log(a * n + b * n);\r\n continue;\r\n } else {\r\n let str = [];\r\n str.push(arr[0]);\r\n for (let i = 1; i < n; i++) {\r\n if (str[str.length - 1] !== arr[i]) str.push(arr[i]);\r\n }\r\n if (str.length <= 2) console.log(a * n + b * str.length);\r\n else {\r\n let k = Math.ceil((str.length + 1) / 2);\r\n console.log(a * n + b * k);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n for (let i = 0; i < content.length; i += 2) {\r\n const [n, a, b] = content[i].split(' ').map(string => parseInt(string));\r\n console.log(maximumCostDeletion(a, b, content[i + 1]));\r\n }\r\n})\r\n\r\nconst maximumCostDeletion = (a, b, str) => {\r\n let bContribution = str.length;\r\n if (b < 0) {\r\n let changes = 1;\r\n bContribution = 1;\r\n for (let i = 1; i < str.length; i++) {\r\n if (str[i] !== str[i - 1]) {\r\n changes++; \r\n }\r\n } \r\n bContribution += Math.floor(changes / 2);\r\n }\r\n return (a * str.length) + (b * bContribution);\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, a, b] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n if (b >= 0) {\r\n console.log((a + b) * n);\r\n continue;\r\n } else {\r\n let str = [];\r\n str.push(arr[0]);\r\n for (let i = 1; i < n; i++) {\r\n if (str[str.length - 1] !== arr[i]) str.push(arr[i]);\r\n }\r\n if (str.length <= 2) console.log(a * n + b * str.length);\r\n else {\r\n let k = Math.floor((str.length + 1) / 2);\r\n console.log(a * n + b * k);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, a, b] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n if (a + b >= 0) {\r\n console.log((a + b) * n);\r\n continue;\r\n } else {\r\n let cnt1 = 0,\r\n cnt2 = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 0) cnt1++;\r\n else cnt2++;\r\n }\r\n let i = 0;\r\n let res = a * cnt2 + b;\r\n while (i < n) {\r\n if (arr[i] === 1) {\r\n let s = i;\r\n while (i < n) {\r\n if (arr[i] === 1) {\r\n if (i - s - 1 > 0) {\r\n res += a * (i - s - 1) + b;\r\n cnt1 -= i - s - 1;\r\n }\r\n s = i;\r\n }\r\n i++;\r\n }\r\n }\r\n i++;\r\n }\r\n if (cnt1 !== 0) res += a * cnt1 + b;\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n for (let i = 0; i < content.length; i += 2) {\r\n const [n, a, b] = content[i].split(' ').map(string => parseInt(string));\r\n console.log(maximumCostDeletion(a, b, content[i + 1]));\r\n }\r\n})\r\n\r\nconst maximumCostDeletion = (a, b, str) => {\r\n let bContribution = str.length;\r\n if (b < 0) {\r\n const startingString = str[0];\r\n bContribution = 1;\r\n for (let i = 1; i < str.length; i++) {\r\n if (str[i] !== str[i - 1] && str[i] === startingString) {\r\n bContribution++; \r\n }\r\n } \r\n }\r\n return (a * str.length) + (b * bContribution);\r\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [],\r\n numTestCases;\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === (2 * (+input[0]) + 1)) {\r\n rl.close();\r\n numTestCases = +input[0];\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n for (let i = 0; i < numTestCases; ++i) {\r\n let currCaseConsts = input[i].split(' '),\r\n currCaseString = input[++i],\r\n n = +currCaseConsts[0],\r\n a = +currCaseConsts[1],\r\n b = +currCaseConsts[2]; \r\n\r\n console.log(getMaxPoints(currCaseString, n, a, b));\r\n }\r\n}\r\n\r\nfunction getMaxPoints(currCaseString, n, a, b) {\r\n let numConsecGroups = 1;\r\n\r\n for (let i = 1; i < n; ++i) {\r\n if (currCaseString.charAt(i - 1) !== currCaseString.charAt(i)) {\r\n ++numConsecGroups;\r\n }\r\n }\r\n\r\n return (b >= 0) ? n * (a + b) : (n * a) + ((Math.floor(numConsecGroups/2) + 1) * b);\r\n}"}], "src_uid": "93fb13c40ab03700ef9a827796bd3d9d"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nlet string = \"\";\nprocess.stdin.on(\"data\", data => string += data);\nprocess.stdin.on(\"end\", () => {\n const array = string.split(\"\\n\")[1].split(\" \").map(Number);\n let accumulatedTime = 0;\n let satisfiedCustomerCount = 0;\n array\n .sort((a, b) => a - b)\n .forEach(serviceTime => {\n if (accumulatedTime <= serviceTime) {\n satisfiedCustomerCount++;\n accumulatedTime += serviceTime;\n }\n });\n console.log(satisfiedCustomerCount);\n})\n", "positive_code": [{"source_code": "// Getting Problem Data from Codeforces.\nvar peopleCount = parseInt(readline());\nvar servingTimes = readline().split(' '); \n// Converting Array to Integers.\nfor(var j = 0;j=sum){\n notDissapointedCount++;\n sum+=servingTimes[i];\n }\n}\n// Solution.\nprint(notDissapointedCount);\n"}, {"source_code": "function cmp(a, b)\n{\n if (+a < +b)\n return -1;\n if (+a > +b)\n return 1;\n return 0; \n}\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var t = Array(n);\n for(var i = 0; i < n; ++i)\n t[i] = +cin.next();\n t.sort(cmp);\n var ans = 0;\n var time = 0;\n for(var i = 0; i < n; ++i)\n {\n if (t[i] >= time)\n {\n time += t[i];\n ++ans;\n } \n }\n cout.print(ans);\n}\n\nfunction Stack()\n{\n this.array = [];\n}\n\nStack.prototype.empty = function()\n{\n return this.array.length == 0;\n}\n\nStack.prototype.push = function(value)\n{\n this.array.push(value);\n}\n\nStack.prototype.pop = function()\n{\n if (!this.empty())\n return this.array.pop();\n return undefined;\n}\n\nStack.prototype.top = function()\n{\n if (!this.empty())\n return this.array[this.array.length - 1];\n return undefined; \n}\n\nStack.prototype.clear = function()\n{\n this.array = [];\n}\n\nStack.prototype.size = function()\n{\n return this.array.length;\n}\n\nfunction Queue()\n{\n this.leftStack = new Stack();\n this.rightStack = new Stack();\n}\n\nQueue.prototype.push = function(value)\n{\n this.leftStack.push(value);\n}\n\nQueue.prototype.empty = function()\n{\n return this.rightStack.empty() && this.leftStack.empty();\n}\n\nQueue.prototype.pop = function()\n{\n if (this.rightStack.empty())\n {\n while(!this.leftStack.empty())\n this.rightStack.push(this.leftStack.pop()); \n }\n if (!this.rightStack.empty())\n return this.rightStack.pop();\n return undefined;\n}\n\nQueue.prototype.front = function()\n{\n if (this.rightStack.empty())\n {\n while(!this.leftStack.empty())\n this.rightStack.push(this.leftStack.pop()); \n }\n if (!this.rightStack.empty())\n return this.rightStack.top();\n return undefined; \n}\n\nQueue.prototype.size = function()\n{\n return leftStack.size() + rightStack.size();\n}\n\nQueue.prototype.clear = function()\n{\n leftStack.clear();\n rightStack.clear();\n}\n\nfunction Reader()\n{\n this.buffer = [];\n this.cur = 0; \n}\n\nReader.prototype.next = function()\n{\n if (this.cur == this.buffer.length)\n {\n this.cur = 0;\n this.buffer = readline().split(' ');\n } \n return this.buffer[this.cur++];\n}\n\nfunction Writer()\n{\n this.buffer = \"\";\n}\n\nWriter.prototype.print = function(s)\n{\n this.buffer += s;\n}\n\nWriter.prototype.println = function(s)\n{\n this.buffer += s;\n print(this.buffer);\n this.buffer = \"\";\n}\n\nWriter.prototype.flush = function()\n{\n if (this.buffer != \"\")\n print(this.buffer);\n this.buffer = \"\";\n}\n\nvar cin = new Reader();\nvar cout = new Writer();\n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,i){return i?gcd(i,t%i):t},Math.lcm=function(t,i){return t/gcd(t,i)*i},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,i){return(+t>+i)-(+i>+t)},Math.icmp=function(t,i){return(+i>+t)-(+t>+i)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.array[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var t = Array(n);\n for(var i = 0; i < n; ++i)\n t[i] = +cin.next();\n t.sort(Math.cmp);\n var ans = 0;\n var time = 0;\n for(var i = 0; i < n; ++i)\n {\n if (t[i] >= time)\n {\n time += t[i];\n ++ans;\n } \n }\n cout.print(ans);\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "var n = parseInt(readline());\nvar t = readline().split(\" \").map(Number);\nt.sort(function(a,b){return a-b;});\nvar tt=0, dd = 0;\n\nfor(var i=0; i=tt)\n {\n tt+=t[i];\n dd++;\n }\n}\n\nprint(dd);"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , a ;\n res = 0 ;\n a = 0 ;\n this.arr = this.arr.sort( function( left , right ) { return left - right ; } ) ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tif( i == 0 || this.arr[ i ] >= a ) {\n \t\ta += this.arr[ i ] ;\n \t\tres++ ;\n \t}\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function toi(x){return parseInt(x);}\nvar n=+readline();\nvar t=readline().split(\" \").map(toi);\nvar wT=0;\nvar res=0;\nt.sort(function(a,b){return a-b;});\nfor(var i=0;i=tt)\n {\n tt+=rrr[i];\n dd++;\n }\n}\n\nprint(rrr);"}, {"source_code": "function QuickSort(A)\n{\n if (A.length == 0) return [];\n var a = [], b = [], p = A[0];\n for (var i = 1; i < A.length; i++)\n { if (A[ i ] < p) a[a.length] = A[ i ];\n else b[b.length] = A[ i ];\n }\n return QuickSort(a).concat( p,QuickSort(b) );\n}\n// main\n\nvar n = parseInt(readline());\nvar t = readline().split(\" \").map(Number);\nvar rrr = QuickSort(t);\nvar tt=0, dd = 0;\n\nfor(var i=0; i=tt)\n {\n tt+=rrr[i];\n dd++;\n }\n}\n\nprint(dd);"}, {"source_code": "function QuickSort(A)\n{\n if (A.length == 0) return [];\n var a = [], b = [], p = A[0];\n for (var i = 1; i < A.length; i++)\n { if (A[ i ] < p) a[a.length] = A[ i ];\n else b[b.length] = A[ i ];\n }\n return QuickSort(a).concat( p,QuickSort(b) );\n}\n// main\n\nvar n = parseInt(readline());\nvar t = readline().split(\" \").map(Number);\nvar rrr = QuickSort(t);\nvar tt=0, dd = 0;\n\nfor(var i=0; i=tt)\n {\n tt+=rrr[i];\n dd++;\n }\n}\n\n"}, {"source_code": "var n = parseInt(readline(), 10);\nvar line = readline().split(' ');\nvar a = line.map(Number);\na.sort(function(x, y) {\n\treturn x - y;\n})\n\nvar sum = 0;\nvar ans = 0;\n\nfor (var i = 0; i < n; i++) {\n\tif (sum < a[i]) {\n\t\tsum += a[i];\n\t\tans ++;\n\t}\n}\n\nprint(ans);"}], "src_uid": "08c4d8db40a49184ad26c7d8098a8992"} {"source_code": "function solve() {\n var s = read();\n var c = {\n P: 0,\n S: 0,\n R: 0\n }\n for (var i = 0; i < s.length; i++) {\n c[s[i]]++;\n }\n if (c.P > c.S) {\n if (c.P > c.R) {\n write('S'.repeat(s.length));\n } else {\n write('P'.repeat(s.length))\n }\n } else {\n if (c.S > c.R) {\n write('R'.repeat(s.length));\n } else {\n write('P'.repeat(s.length))\n }\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n if(n % 2 === 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let s = readline().split('');\n let map = new Array(3);\n map.fill(0);\n for(let i = 0; i < s.length; i++){\n if(s[i] === 'R'){\n map[0] += 1;\n }else if(s[i] === 'S'){\n map[1] += 1;\n }else{\n map[2] += 1;\n }\n }\n\n let max = Math.max(map[0], map[1], map[2]);\n let c = max === map[0] ? 'P' : max === map[1] ? 'R' : 'S';\n let res = '';\n for(let i = 0; i < s.length; i++){\n res += c;\n }\n console.log(res);\n }\n}"}], "negative_code": [{"source_code": "function solve() {\n var s = read();\n var c = {\n P: 0,\n S: 0,\n R: 0\n }\n for (var i = 0; i < s.length; i++) {\n c[s[i]]++;\n }\n if (c.P > c.S) {\n if (c.P > c.R) {\n write('S'.repeat(s.length));\n } else {\n write('PPP'.repeat(s.length))\n }\n } else {\n if (c.S > c.R) {\n write('R'.repeat(s.length));\n } else {\n write('P'.repeat(s.length))\n }\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "src_uid": "38e884cbc5bede371bccbc848096f499"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline());\n const a = readline().split(' ').map(Number);\n helper(n, a);\n}\n\nfunction helper(n, a) {\n let left = 0\n let right = 0\n let cnt = new Map()\n let max = 0\n\n while (right < n) {\n cnt.set(a[right], (cnt.get(a[right]) || 0) + 1)\n while (cnt.size > 2) {\n cnt.set(a[left], cnt.get(a[left]) - 1)\n if (cnt.get(a[left]) === 0) {\n cnt.delete(a[left])\n }\n left++\n }\n max = Math.max(right - left + 1, max)\n right++\n }\n\n console.log(max)\n}", "positive_code": [{"source_code": "/*\nthought: segment tree + devide and counque\n*/\nvar maxn = 1000100;\nvar tmax = new Array([maxn*4]);\nvar tmin = new Array([maxn*4]);\nvar a = new Array([maxn]);\nvar n = parseInt(readline());\nvar x = readline().split(' ');\nfor(var i=0;i= L) t1 = getMax(L, R, l, mid, id*2);\n if(R > mid) t2 = getMax(L, R ,mid+1, r, id*2+1);\n if(t1 == -1) return t2;\n else if(t2 == -1) return t1;\n else return Math.max(t1, t2);\n}\n\nfunction getMin(L, R, l, r, id) {\n if(L <= l && r <= R) return tmin[id];\n var mid = ~~((l+r)/2);\n var t1 = -1;\n var t2 = -1;\n if(mid >= L) t1 = getMin(L, R, l, mid, id*2);\n if(R > mid) t2 = getMin(L, R ,mid+1, r, id*2+1);\n if(t1 == -1) return t2;\n else if(t2 == -1) return t1;\n else return Math.min(t1, t2);\n}\n\n// var test = getMax(0, 2, 0, n-1, 1);\n// print(test);\n\nfunction check(L, R) {\n var maxx = getMax(L, R, 0, n-1, 1);\n var minn = getMin(L, R, 0, n-1, 1);\n if(maxx - minn <= 1) return true;\n return false;\n}\n\nfunction get(start) {\n var l = start;\n var r = n-1;\n while(l <= r) {\n var mid = ~~((l+r)/2);\n if(check(start, mid) == true) l = mid+1;\n else r = mid - 1;\n }\n return l - start;\n}\n\n// for(var i = 0; i < n; i++) {\n// print(getMax(i,n-1, 0, n-1, 1), \",\", getMin(i,n-1, 0, n-1, 1));\n// }\n// print(getMin(0, n-1, 0, n-1, 1));\n\nvar ans = 0;\nfor(var i = 0; i ans) ans = t;\n}\nprint(ans);"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n let currPoint = { value: arr[0], index: 0 };\n let nextPoint = { value: arr[0], index: 0 };\n let minPoint = { value: arr[0], index: 0 };\n let maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n // if (i !== 0 && (arr[i] !== arr[i - 1]) && (arr[i] === minPoint.value) && (arr[i] === minPoint.value)) {\n // nextPoint = { value: arr[i], index: i }\n // }\n // if (arr[i] < minPoint.value) {\n // minPoint = { value: arr[i], index: i };\n // }\n\n // if (arr[i] > maxPoint.value) {\n // maxPoint = { value: arr[i], index: i };\n // }\n\n if (Math.abs(arr[i] - arr[i-1]) > 1) {\n const range = i - currPoint.index;\n maxRange = Math.max(maxRange, range);\n currPoint = { value: arr[i], index: i };\n nextPoint = { value: arr[i], index: i };\n minPoint = { value: arr[i], index: i };\n maxPoint = { value: arr[i], index: i };\n } else if (Math.abs(arr[i] - arr[i-1]) === 1) {\n if ((Math.abs(arr[i] - maxPoint.value) > 1) || \n (Math.abs(arr[i] - minPoint.value) > 1)\n ) {\n const range = i - currPoint.index;\n maxRange = Math.max(maxRange, range);\n currPoint.value = nextPoint.value;\n currPoint.index = nextPoint.index;\n\n if (arr[i] > nextPoint.value) {\n minPoint = { value: nextPoint.value, index: nextPoint.index };\n maxPoint = { value: arr[i], index: i };\n }\n if (arr[i] < nextPoint.value) {\n maxPoint = { value: nextPoint.value, index: nextPoint.index };\n minPoint = { value: arr[i], index: i };\n }\n // nextPoint = { value: arr[i], index: i };\n }\n\n nextPoint = { value: arr[i], index: i }\n }\n\n\n \n\n // if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {\n // const range = i - currPoint.index;\n // if (range > maxRange) {\n // maxRange = range;\n // }\n // currPoint.index = i;\n // currPoint.value = arr[i];\n\n // minPoint.index = i;\n // minPoint.value = arr[i]\n\n // maxPoint.index = i;\n // maxPoint.value = arr[i]\n\n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // } else {\n // if ((maxPoint.value - minPoint.value) > 1) {\n // const range = i - currPoint.index;\n // if (range > maxRange) {\n // maxRange = range;\n // }\n // currPoint.index = nextPoint.index;\n // currPoint.value = nextPoint.value;\n \n // minPoint.index = nextPoint.index;\n // minPoint.value = nextPoint.value;\n \n // maxPoint.index = nextPoint.index;\n // maxPoint.value = nextPoint.value;\n \n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // } else {\n // if (arr[i] !== arr[i - 1]) {\n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // }\n // }\n // }\n \n\n // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = size - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}], "negative_code": [{"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = i;\n currPoint.value = arr[i];\n\n minPoint.index = i;\n minPoint.value = arr[i]\n\n maxPoint.index = i;\n maxPoint.value = arr[i]\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n \n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n \n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n \n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if (arr[i] !== arr[i - 1]) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n }\n }\n \n\n console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = size - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n \n if ((maxPoint.value - minPoint.value) > 2) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = i;\n currPoint.value = arr[i];\n\n minPoint.index = i;\n minPoint.value = arr[i];\n\n maxPoint.index = i;\n maxPoint.value = arr[i];\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n\n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n\n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if (arr[i] !== arr[i - 1]) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n }\n\n // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = i - currPoint.index + 1;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n\n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n\n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else if (((maxPoint.value - minPoint.value)) === 1 && (arr[i] !== arr[i - 1])) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n\n // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = i - currPoint.index + 1;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n\n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n\n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else if ((maxPoint.value - minPoint.value) === 1) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n\n if (size === i + 1) {\n const range = i - currPoint.index + 1;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n\n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n\n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else if (((maxPoint.value - minPoint.value)) === 1 && (arr[i] !== arr[i - 1])) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n\n console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = i - currPoint.index + 1;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n\n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n\n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if (arr[i] !== arr[i - 1]) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n }\n\n // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = i - currPoint.index + 1;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n let currPoint = { value: arr[0], index: 0 };\n let nextPoint = { value: arr[0], index: 0 };\n let minPoint = { value: arr[0], index: 0 };\n let maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n // if (i !== 0 && (arr[i] !== arr[i - 1]) && (arr[i] === minPoint.value) && (arr[i] === minPoint.value)) {\n // nextPoint = { value: arr[i], index: i }\n // }\n // if (arr[i] < minPoint.value) {\n // minPoint = { value: arr[i], index: i };\n // }\n\n // if (arr[i] > maxPoint.value) {\n // maxPoint = { value: arr[i], index: i };\n // }\n\n if (Math.abs(arr[i] - arr[i-1]) > 1) {\n const range = i - currPoint.index;\n maxRange = Math.max(maxRange, range);\n currPoint = { value: arr[i], index: i };\n nextPoint = { value: arr[i], index: i };\n minPoint = { value: arr[i], index: i };\n maxPoint = { value: arr[i], index: i };\n } else if (Math.abs(arr[i] - arr[i-1]) === 1) {\n if ((Math.abs(arr[i] - maxPoint.value) > 1) || \n (Math.abs(arr[i] - minPoint.value) > 1)\n ) {\n const range = i - currPoint.index;\n maxRange = Math.max(maxRange, range);\n currPoint.value = nextPoint.value;\n currPoint.index = nextPoint.index;\n\n if (arr[i] > nextPoint.value) {\n minPoint = { value: nextPoint.value, index: nextPoint.index };\n maxPoint = { value: arr[i], index: i };\n }\n if (arr[i] < nextPoint.value) {\n maxPoint = { value: nextPoint.value, index: nextPoint.index };\n minPoint = { value: arr[i], index: i };\n }\n nextPoint = { value: arr[i], index: i };\n }\n\n nextPoint = { value: arr[i], index: i }\n }\n\n\n \n\n // if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {\n // const range = i - currPoint.index;\n // if (range > maxRange) {\n // maxRange = range;\n // }\n // currPoint.index = i;\n // currPoint.value = arr[i];\n\n // minPoint.index = i;\n // minPoint.value = arr[i]\n\n // maxPoint.index = i;\n // maxPoint.value = arr[i]\n\n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // } else {\n // if ((maxPoint.value - minPoint.value) > 1) {\n // const range = i - currPoint.index;\n // if (range > maxRange) {\n // maxRange = range;\n // }\n // currPoint.index = nextPoint.index;\n // currPoint.value = nextPoint.value;\n \n // minPoint.index = nextPoint.index;\n // minPoint.value = nextPoint.value;\n \n // maxPoint.index = nextPoint.index;\n // maxPoint.value = nextPoint.value;\n \n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // } else {\n // if (arr[i] !== arr[i - 1]) {\n // nextPoint.value = arr[i];\n // nextPoint.index = i;\n // }\n // }\n // }\n \n\n console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = size - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}, {"source_code": "// const approximatingRange = (lengthArr, arr) => {\n// const currPoint = { value: arr[0], index: 0 };\n// const nextPoint = { value: arr[0], index: 0 };\n// const minPoint = { value: arr[0], index: 0 };\n// const maxPoint = { value: arr[0], index: 0 };\n// let maxRange = 0;\n\n// for (let i = 0; i < lengthArr; i++) {\n// if (arr[i] < minPoint.value) {\n// minPoint.value = arr[i];\n// minPoint.index = i;\n// }\n\n// if (arr[i] > maxPoint.value) {\n// maxPoint.value = arr[i];\n// maxPoint.index = i;\n// }\n\n// if ((maxPoint.value - minPoint.value) > 1) {\n// const range = i - currPoint.index;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// currPoint.index = nextPoint.index;\n// currPoint.value = nextPoint.value;\n\n// minPoint.index = nextPoint.index;\n// minPoint.value = nextPoint.value;\n\n// maxPoint.index = nextPoint.index;\n// maxPoint.value = nextPoint.value;\n\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// } else if ((maxPoint.value - minPoint.value) === 1) {\n// nextPoint.value = arr[i];\n// nextPoint.index = i;\n// }\n\n// console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);\n\n// if (lengthArr === i + 1) {\n// const range = i - currPoint.index + 1;\n// if (range > maxRange) {\n// maxRange = range;\n// }\n// }\n// }\n\n// return maxRange;\n// }\n\n// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));\n//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));\n//console.log(approximatingRange(4, [2, 2, 3, 4]));\n\n// const lineReader = require('line-reader');\n// lineReader.eachLine('', function(line) {\n// console.log(line);\n// });\n// var fs = require('fs');\n// const readline = require('readline');\n// const rl = readline.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// rl.question('What do you think of Node.js? ', (answer) => {\n// // TODO: Log the answer in a database\n// console.log(`Thank you for your valuable feedback: ${answer}`);\n\n// rl.close();\n// });\n\n'use strict';\n\n// const fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction approximatingRange(size, arr) {\n /*\n * Write your code here.\n */\n\n const currPoint = { value: arr[0], index: 0 };\n const nextPoint = { value: arr[0], index: 0 };\n const minPoint = { value: arr[0], index: 0 };\n const maxPoint = { value: arr[0], index: 0 };\n let maxRange = 0;\n\n for (let i = 0; i < size; i++) {\n if (arr[i] < minPoint.value) {\n minPoint.value = arr[i];\n minPoint.index = i;\n }\n\n if (arr[i] > maxPoint.value) {\n maxPoint.value = arr[i];\n maxPoint.index = i;\n }\n\n if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = i;\n currPoint.value = arr[i];\n\n minPoint.index = i;\n minPoint.value = arr[i]\n\n maxPoint.index = i;\n maxPoint.value = arr[i]\n\n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if ((maxPoint.value - minPoint.value) > 1) {\n const range = i - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n currPoint.index = nextPoint.index;\n currPoint.value = nextPoint.value;\n \n minPoint.index = nextPoint.index;\n minPoint.value = nextPoint.value;\n \n maxPoint.index = nextPoint.index;\n maxPoint.value = nextPoint.value;\n \n nextPoint.value = arr[i];\n nextPoint.index = i;\n } else {\n if (arr[i] !== arr[i - 1]) {\n nextPoint.value = arr[i];\n nextPoint.index = i;\n }\n }\n }\n \n\n // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint); \n\n if (size === i + 1) {\n const range = size - currPoint.index;\n if (range > maxRange) {\n maxRange = range;\n }\n }\n }\n\n return maxRange;\n\n}\n\nfunction main() {\n \n const size = parseInt(readLine(), 10);\n\n const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));\n\n console.log(approximatingRange(size, arr));\n}\n"}], "src_uid": "b784cebc7e50cc831fde480171b9eb84"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n s = read();\r\n let a = 0,\r\n b = 0;\r\n for (let ch of s) {\r\n if (ch === '0') a++;else b++;\r\n }\r\n if (a === 0) {\r\n return b ** 2;\r\n } else if (b === 0) {\r\n return a ** 2;\r\n }\r\n let res = a * b;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i; j < n; j++) {\r\n if (s[i] !== s[j]) break;\r\n res = Math.max(res, (j - i + 1) ** 2);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "function solve(input) {\r\n var maxX = 0;\r\n var maxY = 0;\r\n \r\n var curX = 0;\r\n var curY = 0;\r\n \r\n var totalX = 0;\r\n var totalY = 0;\r\n \r\n for (var i = 0; i < input.length; i++) {\r\n var char = input[i];\r\n if (i >= 1 && char !== input[i-1]) {\r\n curX = 0;\r\n curY = 0;\r\n }\r\n \r\n if (char === '0') {\r\n totalX++;\r\n curX++;\r\n maxX = Math.max(maxX, curX);\r\n } else {\r\n totalY++;\r\n curY++;\r\n maxY = Math.max(maxY, curY);\r\n }\r\n }\r\n \r\n const mult = totalX * totalY;\r\n \r\n var max = Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));\r\n cl(max);\r\n}\r\n\r\n// ===========\r\n\r\nvar numOfCases = Number(readline());\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var caseLength = rlsn();\r\n var input = rlarrstr()[0];\r\n \r\n var res = solve(input);\r\n}\r\nfunction cl(s) {print(s)}\r\n\r\nfunction rlsn() {return Number(readline());}\r\nfunction rlarrstr() {return readline().split(' ');}\r\nfunction rlarrn() {return rlarrstr().map(Number);}"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var caseLength = Number(readline());\r\n var input = readline();\r\n process(input);\r\n}\r\n\r\nfunction process(input) {\r\n var maxX = 0;\r\n var maxY = 0;\r\n \r\n var curX = 0;\r\n var curY = 0;\r\n \r\n var totalX = 0;\r\n var totalY = 0;\r\n \r\n for (var i = 0; i < input.length; i++) {\r\n var char = input[i];\r\n if (i >= 1 && char !== input[i-1]) {\r\n curX = 0;\r\n curY = 0;\r\n }\r\n \r\n if (char === '0') {\r\n totalX++;\r\n curX++;\r\n maxX = Math.max(maxX, curX);\r\n } else {\r\n totalY++;\r\n curY++;\r\n maxY = Math.max(maxY, curY);\r\n }\r\n }\r\n \r\n const mult = totalX * totalY;\r\n \r\n var max = Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));\r\n print(max);\r\n}"}, {"source_code": "\r\n\r\n\r\n\r\nvar t = readline();\r\nt = parseInt(t);\r\n\r\nwhile(t--){\r\n var x = 0;\r\n var y = 0;\r\n var counter = 1;\r\n var max_length = 1;\r\n\r\n var n = readline();\r\n var s = readline();\r\n\r\n for(var i=0; imax_length){\r\n max_length = counter;\r\n }\r\n pre_bit = s[i];\r\n }\r\n\r\n if(x*y > max_length*max_length){\r\n print(x*y);\r\n }\r\n else{\r\n print(max_length*max_length)\r\n }\r\n}\r\n"}, {"source_code": "const x = readline(); // first line\r\n\r\nfor(var i = 0 ; i < x ; i++) {\r\n var length = parseInt(readline()); // skip line\r\n var inp = readline();\r\n var ones = inp.split('').filter(s => s == 1).length;\r\n var zeros = length - ones;\r\n var number0 = inp.split('1').sort().pop().length;\r\n var number1 = inp.split('0').sort().pop().length;\r\n var onesPow = number1 * number1;\r\n var zerosPow = number0 * number0;\r\n var onesZeros = ones * zeros;\r\n \r\n print(Math.max(onesPow, zerosPow, onesZeros));\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve([input]) {\r\n var maxX = 0;\r\n var maxY = 0;\r\n \r\n var curX = 0;\r\n var curY = 0;\r\n \r\n var totalX = 0;\r\n var totalY = 0;\r\n \r\n for (var i = 0; i < input.length; i++) {\r\n var char = input[i];\r\n if (i >= 1 && char !== input[i-1]) {\r\n curX = 0;\r\n curY = 0;\r\n }\r\n \r\n if (char === '0') {\r\n totalX++;\r\n curX++;\r\n maxX = Math.max(maxX, curX);\r\n } else {\r\n totalY++;\r\n curY++;\r\n maxY = Math.max(maxY, curY);\r\n }\r\n }\r\n \r\n const mult = totalX * totalY;\r\n \r\n return Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));\r\n}\r\n\r\nfunction main() {\r\n const numOfCases = rlsn();\r\n \r\n for (let testCase = 0; testCase < numOfCases; testCase++) {\r\n const l1 = rlsn();\r\n const l2 = rlarrstr();\r\n \r\n const res = solve(l2);\r\n cl(res);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inStr = '';\r\nlet curLine = 0;\r\nconst cl = console.log;\r\n\r\nprocess.stdin.on('data', function(inStdin) {inStr += inStdin;});\r\nprocess.stdin.on('end', function() {inStr = inStr.split('\\n');main();});\r\n\r\nfunction readline() {return inStr[curLine++].replace(/\\s+$/g, '');}\r\nfunction rlsn() {return Number(readline());}\r\nfunction rlarrstr() {return readline().split(' ');}\r\nfunction rlarrn() {return rlarrstr().map(Number);}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction sorted(arr)\r\n{\r\n let second_index;\r\n\tfor(let first_index = 0; first_index < arr.length; first_index++){\r\n \t second_index = first_index + 1;\r\n if(arr[second_index] - arr[first_index] < 0) return false;\r\n }\r\n return true;\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n\r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine())\r\n \r\n let arr = readLine().trim().split(\"\").map(x=>parseInt(x))\r\n \r\n //console.log(\"arr \" + arr)\r\n \r\n let swap=false\r\n \r\n let cur=arr[0]\r\n let cur_streak=0\r\n \r\n let count_zer = 0\r\n let count_one = 0\r\n \r\n let max_sq = 0\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst print = console.log\r\n\r\n// ---------------------------\r\n\r\n/**\r\n * Usage (Linux/Unix): cat input.txt | node index.js \r\n */\r\n\r\nfunction main() {\r\n const testCases = +readline()\r\n\r\n for(let i = 0; i < testCases; i++) {\r\n let len = +readline();\r\n let inp = readline()\r\n \r\n let longestZeroSequence = 0;\r\n let longestOneSequence = 0;\r\n let latestSequence = 1;\r\n let lastChar = inp[0];\r\n for(let ii = 1; ii <= len; ii++){\r\n if(inp[ii] == lastChar && ii != len){\r\n latestSequence++\r\n } else {\r\n if(lastChar === '0'){\r\n if(latestSequence > longestZeroSequence){\r\n longestZeroSequence = latestSequence;\r\n }\r\n } else {\r\n if(latestSequence > longestOneSequence){\r\n longestOneSequence = latestSequence;\r\n }\r\n }\r\n latestSequence = 1;\r\n lastChar = inp[ii];\r\n }\r\n }\r\n\r\n let highestSequence = Math.max(longestZeroSequence, longestOneSequence);\r\n let costAll = (inp.match(/0/g) || []).length * (inp.match(/1/g) || []).length;\r\n \r\n if(costAll > highestSequence ** 2){\r\n print(costAll);\r\n } else { \r\n print(highestSequence ** 2);\r\n }\r\n\r\n }\r\n}"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var s = read();\r\n var ans = 0;\r\n var zeroCount = 0;\r\n var oneCount = 0;\r\n var currentStartIndex = 0;\r\n for (var i = 0; i <= n; i++) {\r\n if (s[i] === '1') {\r\n oneCount++;\r\n }\r\n if (s[i] === '0') {\r\n zeroCount++;\r\n }\r\n if (s[i] === s[i - 1]) {\r\n continue;\r\n }\r\n var prevLenght = i - currentStartIndex;\r\n currentStartIndex = i;\r\n var value = prevLenght * prevLenght;\r\n if (value > ans) {\r\n ans = value;\r\n }\r\n }\r\n write(Math.max(ans, zeroCount * oneCount));\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "negative_code": [], "src_uid": "9070e0d4f8071d1ee8df5189b7c17bfa"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar alist = nextIntArray();\n\t\talist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tvar blist = nextIntArray();\n\t\tblist.sort(function(a,b){\n\t\t\treturn b - a;\n\t\t});\n\t\tvar isOK = true;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(alist[j] + blist[j] > K){\n\t\t\t\tisOK = false;\n\t\t\t}\n\t\t}\n\t\toutput[i] = (isOK) ? \"YES\" : \"NO\";\n\t\tif(i < t - 1){\n\t\t\tvar sp = next();\n\t\t}\n\t}\n\tmyout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x)); \n\tvar a = readline().split(\" \").map(x => parseInt(x)); \n\tvar b = readline().split(\" \").map(x => parseInt(x)); \n\treadline();\n\tb.reverse();\n\tvar isPossible = true;\n\tvar n = params[0];\n\tvar x = params[1];\n for(var j=0;j< n; j++){\n if(a[j]+b[j]>x)\n {\n isPossible = false;\n break;\n \n }\n \n }\n if(isPossible)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}\n"}, {"source_code": "(function () {\n var t = +readline();\n var i = 0;\n while(i++ < t) {\n rearrangeArray();\n readline();\n }\n\n function rearrangeArray() {\n var nums = readline().split(' ').map(Number);\n var n = nums[0], x = nums[1];\n var a = readline().split(' ').map(Number);\n var b = readline().split(' ').map(Number);\n var available = b.sort((j,k) => k-j);\n outer: for(var j = 0; j < n; j++) {\n var curLength = available.length\n for(var k = 0; k < curLength; k++) {\n if(available[k] <= x - a[j]) {\n available.splice(k, 1);\n continue outer;\n }\n }\n if(available.length >= curLength) {\n print(\"No\");\n return;\n }\n }\n print(\"Yes\");\n }\n})();"}, {"source_code": "let data = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on('data', chunk => data += chunk);\nprocess.stdin.on('end', () => {\n data = data.replace(/\\s/g, ' ').replace(/ /g, ' ').split(' ').filter(x => !!x);\n main();\n});\nlet __i = 0;\n\nlet read = () => Number(data[__i++]);\nlet readArray = (n) => { let t = new Array(n); for (let i = 0; i < n; i++) t[i] = Number(read()); return t; }\n\nfunction main() {\n let t = read();\n while(t--) {\n let n = read(), x = read();\n let a = readArray(n);\n let b = readArray(n);\n\n a.sort((a, b) => a - b);\n b.sort((a, b) => b - a);\n\n let r = true;\n for (let i = 0; i < n; i++) {\n if (a[i] + b[i] > x) {\n r = false;\n break;\n }\n }\n console.log(r ? \"Yes\" : \"No\");\n }\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;st-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=s.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),s.default.writeFileSync(\"output.txt\",l),console.log(l),s.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{i=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function c(){return p().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt+n[r]<=e)).length==t;s.default.puts(o?\"Yes\":\"No\"),s.default.readline()}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// let b = io.nextNumbers()\n// \n// b.reverse()\n// \n// let ok = a.filter((y, i) => y + b[i] <= x).length == n\n// \n// io.puts(ok ? \"Yes\" : \"No\")\n// \n// io.readline()\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n').filter((line) => line.trim() !== '')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n, x] = lines[curLine++].split(' ').map((k) => parseInt(k))\n const a = lines[curLine++].split(' ').map((k) => parseInt(k)).sort((u, v) => u - v)\n const b = lines[curLine++].split(' ').map((k) => parseInt(k)).sort((u, v) => v - u)\n let ans = 'Yes'\n for (let i = 0; i < n; i++) {\n if (a[i] + b[i] > x) {\n ans = 'No'\n }\n }\n console.log(ans)\n }\n})\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nlet stdInputString = ''\n\nlet currentLine = 0;\n\nfunction readLine() {\n return stdInputString\n}\n\nprocess.stdin.once('data', rawData => {\n stdInputString += rawData\n})\n\nprocess.stdin.once('end', _ => {\n stdInputString = stdInputString\n .trim()\n .replace(/\\r/g, '')\n .split('\\n')\n main()\n})\n\nfunction main() {\n const w = readLine()\n let a = b = x = ''\n let ntest = w[0];\n\n for (let i = 0; i < ntest; i++) {\n w.map((ln, k) => {\n if ((4 * i) < k && k < (4 * (1 + i))) {\n if (k % 4 === 1)\n x = ln.split(' ')[1]\n else if (k % 4 === 2)\n a = ln.split(' ').map(Number)\n else\n b = ln.split(' ').map(Number)\n }\n })\n\n function swap(index, b) {\n let len = b.length - 1;\n let tem = b[index]\n b[index] = b[len]\n b[len] = tem;\n return b;\n }\n\n function fulfills(b, a, sum) {\n if (a[a.length - 1] + b[b.length - 1] <= sum)\n return true\n else\n return false\n }\n\n function absoluteFalse(a, b, x) {\n if ((a[a.length - 1] >= x) || (b[b.length - 1] >= x)) {\n return true;\n } else if ((a[a.length - 1] + b[0]) > x) {\n return true;\n } else if ((b[b.length - 1] + a[0]) > x) {\n return true;\n } else if (a[a.length - 1] + b[0] === x) {\n b.splice(b.length, 0, b[0])\n b.shift()\n return b\n } else if ((a[a.length - 1] + b[0] <= x) && (a[a.length - 1] + b[1] > x)) {\n b.splice(b.length, 0, b[0])\n b.shift()\n return b\n } else\n return false\n }\n\n\n function preprocessing(a, b, x) {\n let abFalse = absoluteFalse(a, b, x)\n if (abFalse === true) {\n return false\n } else if (abFalse.length > 0) {\n return abFalse\n } else\n return true\n }\n\n function matchNsum(a, b, x, len) {\n let result = false;\n let op = ''\n if (preprocessing(a, b, x) === false)\n return false\n else if (preprocessing(a, b, x).length > 0)\n b = preprocessing(a, b, x)\n\n while (a.length > 0) {\n if (op === 'p') {\n if (preprocessing(a, b, x) === false)\n return false\n else if (preprocessing(a, b, x).length > 0)\n b = preprocessing(a, b, x)\n }\n\n if (fulfills(b, a, x)) {\n result = true;\n if (b.length > 0) {\n b.pop();\n a.pop();\n op = 'p'\n len = b.length\n } else {\n return result\n }\n } else {\n result = false;\n if (len > 0) {\n len--\n b = swap(len, b)\n op = 's'\n } else if (a.length === 1) {\n return result\n }\n }\n }\n return result\n }\n result = matchNsum(a, b, x, b.length) === false ? 'No' : 'Yes'\n console.log(result)\n a = [];\n b = [];\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nlet stdInputString = ''\n\nlet currentLine = 0;\n\nfunction readLine() {\n return stdInputString\n}\n\nprocess.stdin.once('data', rawData => {\n stdInputString += rawData\n})\n\nprocess.stdin.once('end', _ => {\n stdInputString = stdInputString\n .trim()\n .replace(/\\r/g, '')\n .split('\\n')\n main()\n})\n\nfunction main() {\n const w = readLine()\n let a = b = x = ''\n let ntest = w[0];\n\n for (let i = 0; i < ntest; i++) {\n w.map((ln, k) => {\n if ((4 * i) < k && k < (4 * (1 + i))) {\n if (k % 4 === 1) {\n x = ln.split(' ')[1]\n // console.log('len = ' + v[0])\n // console.log('x = ' + x)\n } else if (k % 4 === 2) {\n a = ln.split(' ').map(Number)\n } else {\n b = ln.split(' ').map(Number)\n }\n }\n })\n // Function:\n\n function swap(index, b) {\n let len = b.length - 1;\n let tem = b[index]\n b[index] = b[len]\n b[len] = tem;\n return b;\n }\n\n function fulfills(b, a, sum) {\n if (a[a.length - 1] + b[b.length - 1] <= sum)\n return true\n else\n return false\n }\n\n function absoluteFalse(a, b, x) {\n if ((a[a.length - 1] >= x) || (b[b.length - 1] >= x)) {\n return true;\n } else if ((a[a.length - 1] + b[0]) > x) {\n return true;\n } else if ((b[b.length - 1] + a[0]) > x) {\n return true;\n } else if (a[a.length - 1] + b[0] === x) {\n b.splice(b.length, 0, b[0])\n b.shift()\n return b\n } else if ((a[a.length - 1] + b[0] <= x) && (a[a.length - 1] + b[1] > x)) {\n b.splice(b.length, 0, b[0])\n b.shift()\n return b\n } else\n return false\n }\n\n\n function preprocessing(a, b, x) {\n let abFalse = absoluteFalse(a, b, x)\n if (abFalse === true) {\n a = []\n b = []\n return false\n } else if (abFalse.length > 0) {\n return abFalse\n } else\n return true\n }\n\n function matchNsum(a, b, x, len) {\n let result = false;\n let op = ''\n if (preprocessing(a, b, x) === false)\n return false\n else if (preprocessing(a, b, x).length > 0)\n b = preprocessing(a, b, x)\n\n while (a.length > 0) {\n if (op === 'p') {\n if (preprocessing(a, b, x) === false)\n return false\n else if (preprocessing(a, b, x).length > 0)\n b = preprocessing(a, b, x)\n }\n\n if (fulfills(b, a, x)) {\n result = true;\n if (b.length > 0) {\n b.pop();\n a.pop();\n op = 'p'\n len = b.length\n } else {\n return result\n }\n } else {\n result = false;\n if (len > 0) {\n len--\n b = swap(len, b)\n op = 's'\n } else if (a.length === 1) {\n return result\n }\n }\n }\n return result\n }\n result = matchNsum(a, b, x, b.length) === false ? 'No' : 'Yes'\n console.log(result)\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n let y = t;\n while(t > 0){\n t--;\n if(t < y-1)\n readline();\n let [n,x] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let visited = new Array(n);\n visited.fill(false);\n let flag = true;\n\n for(let i = 0; i < n; i++){\n let max = a[i];\n let index = -1;\n for(let j = 0; j < n; j++){\n if(!visited[j] && a[i]+b[j] <= x){\n max = Math.max(max, a[i]+b[j]);\n index = j;\n }\n }\n if(index !== -1){\n visited[index] = true;\n }else{\n console.log('No');\n flag = false;\n break;\n }\n }\n if(flag)\n console.log('Yes');\n }\n}"}, {"source_code": "var N = Number(readline());\n\n// \u8c03\u6574\u6570\u7ec4 a b \u4f7f\u5f97\n// a[i] + b[i] <= x\n\nfor( ; N; N -- && readline())\n{\n\tprint(['No', 'Yes'][test() + 0]);\n}\n\nfunction test()\n{\n\tvar x = Number(readline().split(' ')[1]);\n\tvar a = readline().split(' ').map(e => Number(e)).sort((a, b) => a - b);\n\tvar b = readline().split(' ').map(e => Number(e)).sort((a, b) => b - a);\n\n\tfor(var i = 0; i < a.length; i ++)\n\t{\n\t\tif(a[i] + b[i] > x)\n\t\t\treturn false;\n\t}\n\n\treturn true;\n}\n"}, {"source_code": "\n\n\n\nvar t=readline();\n\nfor (k = 0; k< t; k++){\n\tif (k > 0){\n\t\tvar empty = readline();\n\t}\n\tvar nx = readline();\n\tvar a = readline().split(\" \");\n\tvar b = readline().split(\" \");\n\tvar shi = false;\n\tvar x = +nx.split(\" \")[1];\n\tfor (i = 0; i < a.length; i++){\n\t\tvar toDelete = a.length - (i + 1);\n\t\t\n\t\t\n\t\tif ((+a[toDelete] + +b[i]) > x){\n\t\t\tshi = true;\n\t\t}\n\t\t\n\t}\n\tif (shi == true){\n\t\tprint (\"No\");\n\t} \n\telse{\n\t\tprint (\"Yes\");\n\t}\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, x] = readLine().split(\" \").map(Number);\n const arr1 = readLine().split(\" \").map(Number);\n const arr2 = readLine().split(\" \").map(Number);\n readLine();\n let flag = true;\n\n arr1.sort((a, b) => a - b);\n arr2.sort((a, b) => b - a);\n\n for (let i = 0; i < len; i++) {\n if (arr1[i] + arr2[i] > x) {\n console.log(\"No\");\n flag = false;\n break;\n }\n }\n if (flag) console.log(\"Yes\");\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, x] = readLine().split(\" \").map(Number);\n const arr1 = readLine().split(\" \").map(Number);\n const arr2 = readLine().split(\" \").map(Number);\n readLine();\n\n const [min1, max1, min2, max2] = [Math.min(...arr1), Math.max(...arr1), Math.min(...arr2), Math.max(...arr2)];\n if (x < min1 || x < min2 || min1 + max2 > x || min2 + max1 > x) console.log(\"No\");\n else console.log(\"Yes\");\n }\n}\n"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n').filter((line) => line.trim() !== '')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n, x] = lines[curLine++].split(' ').map((k) => parseInt(k))\n const a = lines[curLine++].split(' ').map((k) => parseInt(k)).sort()\n const b = lines[curLine++].split(' ').map((k) => parseInt(k)).sort((u, v) => v - u)\n let ans = 'Yes'\n for (let i = 0; i < n; i++) {\n if (a[i] + b[i] > x) {\n ans = 'No'\n }\n }\n console.log(ans)\n }\n})\n"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n').filter((line) => line.trim() !== '')\n const T = parseInt(lines[0])\n let curLine = 1\n for (let t = 0; t < T; t++) {\n const [n, x] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const a = lines[curLine++].split(' ').map((x) => parseInt(x)).sort()\n const b = lines[curLine++].split(' ').map((x) => parseInt(x)).sort((u, v) => v - u)\n let ans = 'Yes'\n for (let i = 0; i < n; i++) {\n if (a[i] + b[i] > x) {\n ans = 'No'\n }\n }\n console.log(ans)\n }\n})\n"}, {"source_code": "\n\n\n\nvar t=readline();\n\nfor (k = 0; k< t; k++){\n\tif (k > 0){\n\t\tvar empty = readline();\n\t}\n\tvar nx = readline();\n\tvar a = readline().split(\" \");\n\tvar b = readline().split(\" \");\n\tvar shi = false;\n\tvar x = nx.split(\" \")[1];\n\tfor (i = 0; i < a.length; i++){\n\t\tvar toDelete = a.length - (i + 1);\n\t\t\n\t\t\n\t\tif ((a[toDelete] + b[i]) > x){\n\t\t\tshi = true;\n\t\t}\n\t\t\n\t}\n\tif (shi == true){\n\t\tprint (\"No\");\n\t} \n\telse{\n\t\tprint (\"Yes\");\n\t}\n}\n"}, {"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x)); \n\t\n\tvar a = readline().split(\" \").map(x => parseInt(x)); \n\tvar b = readline().split(\" \").map(x => parseInt(x)); \n\t\n\ta.sort();\n\tb.sort();\n\tb.reverse();\n\tvar isPossible = true;\n\tvar n = params[0];\n\tvar x = params[1];\n for(var j=0;j< n; j++){\n if(a[j]+b[j]<=x)\n {\n continue\n }\n else\n {\n isPossible = false;\n break;\n }\n }\n if(isPossible)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}\n"}, {"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x)); \n\tvar a = readline().split(\" \").map(x => parseInt(x)); \n\tvar b = readline().split(\" \").map(x => parseInt(x)); \n\treadline();\n\t\n\ta.sort();\n\tb.sort();\n\tb.reverse();\n\tvar isPossible = true;\n\tvar n = params[0];\n\tvar x = params[1];\n for(var j=0;j< n; j++){\n if(a[j]+b[j]<=x)\n {\n continue\n }\n else\n {\n isPossible = false;\n break;\n }\n }\n if(isPossible)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}\n"}], "src_uid": "7e765c1b0e3f3e9c44de825a79bc1da2"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r parseInt(x));\n \n if(data === 1) {\n console.log(\"Yes\");\n break;\n }\n \n let output = \"Yes\";\n \n for(let i=1;i 1) {\n output = \"No\";\n break;\n }\n }\n \n console.log(output);\n }\n \n}", "positive_code": [{"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n \n \n// ************************ Code Start ***************************\n \nfunction main() {\n \n var Tc = parseInt(readline());\n while (Tc--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map((x) => parseInt(x));\n var ok = 1;\n for (var i = 1; i < n; i++) {\n if (ar[i] > ar[i - 1] && ar[i] != ar[i - 1] + 1) {\n ok = 0;\n break;\n }\n }\n print(ok ? 'YES' : 'NO');\n }\n}"}], "negative_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r parseInt(x));\n \n if(data === 1) {\n console.log(\"Yes\")\n } else if(a[a.length - 1] - a[0] < 1) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\");\n }\n\n }\n \n}"}], "src_uid": "dc03b66a4c6aac69372d594784f3f083"} {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let longItems = data.reduce((agr, item) => {\n item = +item;\n if (item > agr[0]) agr.unshift(item);\n else if (item > agr[1]) agr[1] = item;\n return agr;\n }, [0, 0]);\n let maxKForLong = longItems[1] - 1;\n let maxKForShort = data.length - 2;\n let k = Math.min(maxKForLong, maxKForShort);\n return k > 0 ? k : 0;\n\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \");\n console.log(foo(data));\n testCount++;\n }\n})", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let longItems = data.reduce((agr, item) => {\n item = +item;\n if (item > agr[0]) agr.unshift(item);\n else if (item > agr[1]) agr[1] = item;\n return [agr[0], agr[1]];\n }, [0, 0]);\n let maxKForLong = longItems[1] - 1;\n //console.log(\"maxKForLong\", maxKForLong);\n let maxKForShort = data.length - 2;\n //console.log(\"maxKForShort\", maxKForShort);\n let k = Math.min(maxKForLong, maxKForShort);\n return k > 0 ? k : 0;\n\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \");\n //console.log(data)\n console.log(foo(data));\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let longItems = data.reduce((agr, item) => {\n if (item > agr[0]) agr.unshift(item);\n else if (item > agr[1]) agr[1] = item;\n return [agr[0], agr[1]];\n }, [0, 0]);\n let maxKForLong = longItems[1] - 1;\n //console.log(\"maxKForLong\", maxKForLong);\n let maxKForShort = data.length - 2;\n //console.log(\"maxKForShort\", maxKForShort);\n let k = Math.min(maxKForLong, maxKForShort);\n return k > 0 ? k : 0;\n\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n //console.log(data)\n answer += foo(data) + \"\\n\";\n testCount++;\n }\n console.log(answer)\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, min, max) {\n\t function check(data, k) {\n\t //console.log(\"k \", k);\n\t let lengthLong = data.reduce((agr, value) => {\n\t if (value >= k + 1) agr++;\n\t return agr;\n\t }, 0);\n\n\t //console.log(\"lengthLong\", lengthLong);\n\t let hasLong = lengthLong >=2 ;\n\n\t let hasShort = (data.length - 2) >= k;\n\t return hasLong && hasShort;\n\t }\n\n\t let middle = min + Math.ceil((max - min) / 2);\n\t //console.log(min, max, middle);\n\t let isValid = check(data, middle);\n\t let isNextValid = check(data, middle + 1);\n\t //console.log(isValid, isNextValid);\n\t if (isValid && !isNextValid) return middle;\n\t if (max <= min) return 0;\n\n\t if (isValid && isNextValid) {\n\t min = middle;\n\t } else {\n\t max = (max !== middle) ? middle : middle -1;\n\t }\n\t return foo(data, min, max);\n\t}\n\n\tlet testCount = 1;\n\n\twhile(testCount <= +lines[0]) {\n\t let data = lines[testCount * 2].split(\" \");\n\t //console.log(\"data \", data);\n\t console.log(foo(data, 1, data.length - 2));\n\t testCount++;\n\t}\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n const max = arr[1];\n\n console.log(Math.min(max - 1, arr.length - 2));\n\n // let ans = 0;\n\n // for (let i = 2; i < arr.length; i++) {\n // ans++;\n // }\n\n // console.log(Math.min(max - 1, ans));\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n const max = arr[1];\n let ans = 0;\n\n for (let i = 2; i < arr.length; i++) {\n ans++;\n }\n\n console.log(Math.min(max - 1, ans));\n\n c++;\n});\n"}, {"source_code": "t=+readline()\n\nfunction cmp(a,b)\n{\n if (+a<+b)\n return 1\n if (+a==+b)\n return 0\n if (+a>+b)\n return -1\n}\n\nfunction min(a,b)\n{\n if (a {\n\ttry {\n\t\treturn require(\"fs\").readFileSync(\"input.txt\", \"utf8\").split(/[\\r\\n]+/);\n\t} catch(e) {}\n\tconst lines = [];\n\tfor(var line; undefined !== (line = readline()); )\n\t\tlines.push(line);\n\treturn lines;\n};\nconst output = (text) => {\n\ttry {\n\t\tconsole.log(text);\n\t} catch(e) {}\n\ttry {\n\t\ttext.toString().split(/[\\r\\n]+/).map(s => print(s));\n\t} catch(e) {}\n};\n\nvar a = readLines();\nvar count = +a.shift();\nvar result = [];\nfor(var i = 0; i < count; i++) {\n\tvar numBoards = +a.shift();\n\tvar boards = a.shift().split(\" \").map(Number);;\n\tboards.sort((l, r) => r - l);\n\tresult.push( Math.min((boards[1]|0) - 1, numBoards - 2) );\n}\n\noutput( result.join(\"\\n\") );"}, {"source_code": "var t = +readline()\n\nfor ( var i = 0 ; i < t ; i++ ) {\n var n = +readline()\n var planks = readline().split(' ')\n planks.sort((a,b) => a - b)\n\n var l = Math.min(planks.pop(), planks.pop()) - 1\n print(Math.min(l, planks.length))\n}\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\n var T = +rd();\n while (T-->0) {\n var n = +rd();\n var A = rdAr().sortGt();\n var max2 = A[1] - 1;\n pr(Math.min(max2, n - 2));\n }\n};\n\nif (INPUT) {\nINPUT = INPUT.split('\\n').reverse();\nreadline = () => INPUT.pop();\nwrite = (s) => {OUTPUT += s};\nprint = (s) => {OUTPUT += s + '\\n'};\n}\nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\nconst getPrimes = function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j {\n\ttry {\n\t\treturn require(\"fs\").readFileSync(\"input.txt\", \"utf8\").split(/[\\r\\n]+/);\n\t} catch(e) {}\n\tconst lines = [];\n\tfor(var line; undefined !== (line = readline()); )\n\t\tlines.push(line);\n\treturn lines;\n};\nconst output = (text) => {\n\ttry {\n\t\tconsole.log(text);\n\t} catch(e) {}\n\ttry {\n\t\ttext.toString().split(/[\\r\\n]+/).map(s => print(s));\n\t} catch(e) {}\n};\n\nvar a = readLines();\nvar count = +a.shift();\nvar result = [];\nfor(var i = 0; i < count; i++) {\n\tvar numBoards = +a.shift();\n\tvar boards = a.shift().split(\" \").map(Number);;\n\tboards.sort((l, r) => r - l);\n\tresult.push( Math.max((boards[1]|0) - 1, numBoards - 2) );\n}\n\noutput( result.join(\"\\n\") );"}, {"source_code": "const readLines = () => {\n\tconst lines = [];\n\tfor(var line; undefined !== (line = readline()); )\n\t\tlines.push(line);\n\treturn lines;\n};\nconst output = (text) => {\n\ttext.toString().split(/[\\r\\n]+/).map(s => print(s));\n};\n//const input = readline;\n/**/\n\nconst a = readLines();\nconst count = +a.shift();\nvar result = [];\nfor(var i = 0; i < count; i++) {\n\tconst numBoards = +a.shift();\n\tconst boards = a.shift().split(\" \").map(Number);\n\tboards.sort((l, r) => r - l);\n\tresult.push( Math.max((boards[1]|0) - 1, numBoards - 2) );\n}\n\noutput( result.join(\"\\n\") );"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let longItems = data.reduce((agr, item) => {\n if (item > agr[0]) agr.unshift(item);\n else if (item > agr[1]) agr[1] = item;\n return agr;\n }, [0, 0]);\n let maxKForLong = longItems[1] - 1;\n let maxKForShort = data.length - 2;\n let k = Math.min(maxKForLong, maxKForShort);\n return k > 0 ? k : 0;\n\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \");\n console.log(foo(data));\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let longItems = data.reduce((agr, item) => {\n item = +item;\n if (item > agr[0]) agr.unshift(item);\n else if (item > agr[1]) agr[1] = item;\n return agr;\n }, [0, 0]);\n let maxKForLong = longItems[1] - 1;\n console.log(\"maxKForLong\",maxKForLong);\n let maxKForShort = data.length - 2;\n console.log(\"maxKForShort\",maxKForShort);\n let k = Math.min(maxKForLong, maxKForShort);\n return k > 0 ? k : 0;\n\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \");\n console.log(data)\n console.log(foo(data));\n testCount++;\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n const max = arr[1];\n let ans = 0;\n\n for (let i = 2; i < arr.length; i++) {\n if (arr[i] < max) {\n ans++;\n }\n }\n\n console.log(Math.min(max - 1, ans));\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n const max = arr[1];\n let ans = 0;\n\n for (let i = 2; i < arr.length; i++) {\n if (arr[i] < max) {\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}], "src_uid": "130fd7f40d879e25b0bff886046bf699"} {"source_code": "\n// 369A \u0412\u0430\u043b\u0435\u0440\u0430 \u0438 \u0442\u0430\u0440\u0435\u043b\u043a\u0438 \n\n// var n = parseInt(readline());\n\nvar input_line = readline().split(' ').map(Number);\n\nvar n = input_line[0];\nvar m = input_line[1];\nvar r = input_line[2];\n\nvar arr = readline().split(' ').map(Number);\n\nvar out = 0;\nvar count1 = 0;\nvar count2 = 0;\n\narr.forEach(function(item, i, arr) {\n if (item == 1) {\n count1 ++;\n } else {\n count2 ++;\n };\n});\n\nif (count1 > m) {\n out += (count1 - m);\n} else {\n r += (m - count1);\n};\n\nif (r < count2) {\n out += count2 - r;\n};\n\nprint(out);\n", "positive_code": [{"source_code": "function main(){\n var nmk = readline().split(' ');\n var washTime = 0;\n var b = parseInt(nmk[1]), p = parseInt(nmk[2]);\n readline().split(' ').forEach(function (i){\n if ( i === \"1\" ){\n if ( b > 0 ){\n --b;\n }else{\n ++washTime;\n }\n }else{\n if ( p > 0 ){\n --p;\n }else if ( b > 0 ){\n --b;\n }else{\n ++washTime;\n }\n }\n });\n print(washTime);\n}\nmain();"}, {"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar k=+l[2];\n\nvar ans=0;\nreadline().split(' ').forEach(function(v){\n\tif(v==='1'){\n\t\tif(m>0){\n\t\t\tm--;\n\t\t}else{\n\t\t\tans++;\n\t\t}\n\t}else{\n\t\tif(k>0){\n\t\t\tk--;\n\t\t}else if(m>0){\n\t\t\tm--;\n\t\t}else{\n\t\t\tans++;\n\t\t}\n\t}\n});\nprint(ans);"}, {"source_code": "var input = readline().split(\" \").map(Number), n = +input[0], m = +input[1], k = +input[2],\na = readline().split(\" \");\nvar cnt = 0;\n\na.forEach(function(day){\n\tif(day == \"1\"){\n\t\tif(m > 0){\n\t\t\tm--;\n\t\t}\n\t\telse{\n\t\t\tcnt++;\n\t\t}\n\t}\n\telse{\n\t\tif(k > 0){\n\t\t\tk--;\n\t\t}\n\t\telse{\n\t\t\tif(m > 0){\n\t\t\t\tm--;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t}\n});\n\nwrite(cnt);"}, {"source_code": "var n = readline().split(' ');\nvar m = +n[1];\nvar l = +n[2];\nn = +n[0];\n\nvar x = 0;\nvar a = readline().split(' ').map(function (e) {\n\tswitch (e) {\n\t\tcase '1':\n\t\t\tif (m > 0) m--;\n\t\t\telse x++;\n\t\t\tbreak;\n\n\t\tcase '2':\n\t\t\tif (l > 0) l--;\n\t\t\telse {\n\t\t\t\tif (m > 0) m--;\n\t\t\t\telse x++;\n\t\t\t}\n\t\t\tbreak;\n\t}\n});\n\nprint(x);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numDays = integers[0], bowlCap = integers[1], dishCap = integers[2];\n\n\tvar meals = tokenizeIntegers(readline());\n\tvar typeCounts = { 1: 0, 2: 0 };\n\tfor (var i = 0; i < meals.length; i += 1) {\n\t\ttypeCounts[meals[i]] += 1;\n\t}\n\n\tvar bowls = bowlCap - typeCounts[1];\n\tif (bowls > 0) {\n\t\tdishCap += bowls;\n\t}\n\tvar dishes = dishCap - typeCounts[2];\n\n\tvar result = -(Math.min(bowls, 0) + Math.min(dishes, 0));\n\tprint(result);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "var n = readline().split(' ');\nvar m = +n[1];\nvar l = +n[2];\nn = +n[0];\n\nvar x = 0;\nvar a = readline().split(' ').map(function (e) {\n\tswitch (e) {\n\t\tcase '1':\n\t\t\tif (m > 0) m--;\n\t\t\telse x++;\n\t\t\tbreak;\n\n\t\tcase '2':\n\t\t\tif (l > 0) l--;\n\t\t\telse x++;\n\t\t\tbreak;\n\t}\n});\n\nprint(x);"}, {"source_code": "var n = readline().split(' ');\nvar m = +n[1];\nvar l = +n[2];\nn = +n[0];\n\nvar x = 0;\nvar a = readline().split(' ').map(function (e) {\n\tswitch (e) {\n\t\tcase '1':\n\t\t\tif (m > 0) m--;\n\t\t\telse x++;\n\t\t\tbreak;\n\n\t\tcase '2':\n\t\t\tif (m > 0) m--;\n\t\t\telse {\n\t\t\t\tif (l > 0) l--;\n\t\t\t\telse x++;\n\t\t\t}\n\t\t\tbreak;\n\t}\n});\n\nprint(x);"}, {"source_code": "\n// 369A \u0412\u0430\u043b\u0435\u0440\u0430 \u0438 \u0442\u0430\u0440\u0435\u043b\u043a\u0438 \n\n// var n = parseInt(readline());\n\nvar input_line = readline().split(' ').map(Number);\n\nvar n = input_line[0];\nvar m = input_line[1];\nvar r = input_line[2];\n\nvar arr = readline().split(' ').map(Number);\n\nvar out = 0;\nvar count1 = 0;\nvar count2 = 0;\n\narr.forEach(function(item, i, arr) {\n if (item == 1) {\n count1 ++;\n } else {\n count2 ++;\n };\n});\n\nif (count1 > m) {\n out += (count1 - m);\n} else {\n count2 += (m - count1);\n};\n\nif (count2 < (n - count1)) {\n out += (n - count1) - count2;\n};\n\nprint(out);\n"}, {"source_code": "\n// 369A \u0412\u0430\u043b\u0435\u0440\u0430 \u0438 \u0442\u0430\u0440\u0435\u043b\u043a\u0438 \n\n// var n = parseInt(readline());\n\nvar input_line = readline().split(' ').map(Number);\n\nvar n = input_line[0];\nvar m = input_line[1];\nvar r = input_line[2];\n\nvar arr = readline().split(' ').map(Number);\n\nvar out = 0;\nvar count1 = 0;\nvar count2 = 0;\n\narr.forEach(function(item, i, arr) {\n if (item = 1) {\n count1 ++;\n } else {\n count2 ++;\n };\n});\n\nif (count1 > m) {\n out += (count1 - m);\n} else {\n count2 += (m - count1);\n};\n\nif (count2 < (n - count1)) {\n out += (n - count1) - count2;\n};\n\nprint(out);\n"}, {"source_code": "function main(){\n var nmk = readline().split(' ');\n var plan = readline().split(' ');\n var i, washTime = 0;\n var b = parseInt(nmk[1]), p = parseInt(nmk[2]);\n for( i = 0 ; i < nmk[0] ; ++i ){\n if ( plan[i] == 1 ){\n if ( b == 0 ){\n b = parseInt(nmk[1]), p = parseInt(nmk[2]);\n ++washTime;\n }\n --b;\n }else{\n if ( p > 0 ){\n --p;\n }else if ( b > 0 ){\n --b;\n }else{\n b = parseInt(nmk[1]), p = parseInt(nmk[2]);\n ++washTime;\n --p;\n }\n }\n }\n print(washTime);\n}\nmain();"}], "src_uid": "4ed5b8055ce48b5ad4e43ed4b06d1b07"} {"source_code": "function find(str,vitamin){\n for (var j = 0;j0){\n var ip = readline().split(' ');\n if (find(ip[1],'A')){\n A = Math.min(A,ip[0]);\n }\n if (find(ip[1],'B')){\n B = Math.min(B,ip[0]);\n }\n if (find(ip[1],'C')){\n C = Math.min(C,ip[0]);\n }\n if (ip[1] === 'AB' || ip[1] === 'BA'){\n AB = Math.min(ip[0],AB);\n }\n if (ip[1] === 'AC' || ip[1] === 'CA'){\n AC = Math.min(ip[0],AC);\n }\n if (ip[1] === 'CB' || ip[1] === 'BC'){\n BC = Math.min(ip[0],BC);\n }\n \n if (ip[1].length === 3){\n ABC = Math.min(ip[0],ABC);\n }\n AB = Math.min(A+B,AB);\n AC = Math.min(A+C,AC);\n BC = Math.min(B+C,BC);\n ABC = Math.min(A+B+C,AB+C,AC+B,BC+A,ABC);\n}\nprint((ABC === Number.MAX_VALUE)?-1:ABC);", "positive_code": [{"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: parseInt(inp[0]),\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n break;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1];\n break;\n }\n }\n\n updateSum();\n\n\n }\n\n\n if (sortedArr['ABC'] && sum > sortedArr['ABC']) {\n sum = sortedArr['ABC'];\n }\n\n //console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 198,\n// vit: 'BC'\n// }, {\n// cost: 259,\n// vit: 'AC'\n// }, {\n// cost: 125,\n// vit: 'BA'\n// }, {\n// cost: 298,\n// vit: 'CAB'\n// }, {\n// cost: 252,\n// vit: 'CA'\n// }, {\n// cost: 98,\n// vit: 'AC'\n// }, {\n// cost: 284,\n// vit: 'BAC'\n// }])"}, {"source_code": "dp = new Array(8);\nfor (i=1;i<8;i++){\n dp[i] = Number.MAX_VALUE;\n}\ndp[0] = 0;\nn = +readline();\nwhile (n-->0){\n ip = readline().split(' ');\n value = +ip[0];\n plus = 0;\n ip[1].split('').forEach(x => {\n plus |= 1<<(x.charCodeAt() - 65);\n });\n for (i = 7;i>=0;i--){\n dp[i | plus] = Math.min(dp[i | plus], dp[i]+value);\n }\n}\nprint(dp[7] === Number.MAX_VALUE?-1:dp[7]);"}, {"source_code": "function find(str,vitamin){\n for (var j = 0;j0){\n var ip = readline().split(' ');\n if (ip[1] === 'A'){\n A = Math.min(A,ip[0]);\n }\n if (ip[1] === 'B'){\n B = Math.min(B,ip[0]);\n }\n if (ip[1] === 'C'){\n C = Math.min(C,ip[0]);\n }\n if (ip[1] === 'AB' || ip[1] === 'BA'){\n AB = Math.min(ip[0],AB);\n }\n if (ip[1] === 'AC' || ip[1] === 'CA'){\n AC = Math.min(ip[0],AC);\n }\n if (ip[1] === 'CB' || ip[1] === 'BC'){\n BC = Math.min(ip[0],BC);\n }\n \n if (ip[1].length === 3){\n ABC = Math.min(ip[0],ABC);\n }\n AB = Math.min(A+B,AB);\n AC = Math.min(A+C,AC);\n BC = Math.min(B+C,BC);\n ABC = Math.min(A+B+C,AB+C,AC+B,BC+A,ABC,AB+AC,AB+BC,BC+AC);\n}\nprint((ABC === Number.MAX_VALUE)?-1:ABC);"}, {"source_code": "var n = Number(readline());\nvar input = [];\nvar hash = {}; var key;\nvar keymap = {A : \"001\",\n B : \"010\" ,\n C : \"100\",\n AB : \"011\",\n BC: \"110\",\n AC: \"101\",\n ABC: \"111\"};\n\nfor(var i=0; i {\n// var input = [\"4\", \"5 C\", \"6 B\", \"16 ACB\", \"4 A\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar min = (...arg) => {\n var min;\n for(var a of arg){\n if(a != NaN && (!min || a < min)){\n min = a;\n }\n }\n return min;\n}\n\n\nvar res = new Array(8)\nvar n = parseInt(readline())\nfor(var i = 0; i < n; i++){\n var line = readline().split(\" \");\n var price = parseInt(line[0]);\n var bit = line[1].split('').sort().join('');\n if(!res[bit] || res[bit] > price){\n res[bit] = price;\n }\n}\n\nvar minPrice = min(res['A'] + res['B'] + res['C'], \nres['A'] + res['BC'], \nres['B'] + res['AC'], \nres['C'] + res['AB'], \nres['AB'] + res['AC'], \nres['AB'] + res['BC'],\nres['BC'] + res['AC'],\nres['ABC'])\nprint(minPrice || -1)"}], "negative_code": [{"source_code": "function find(str,vitamin){\n for (var j = 0;j0){\n var ip = readline().split(' ');\n if (ip[1] === 'A'){\n A = Math.min(A,ip[0]);\n }\n if (ip[1] === 'B'){\n B = Math.min(B,ip[0]);\n }\n if (ip[1] === 'C'){\n C = Math.min(C,ip[0]);\n }\n if (ip[1] === 'AB' || ip[1] === 'BA'){\n AB = Math.min(ip[0],AB);\n }\n if (ip[1] === 'AC' || ip[1] === 'CA'){\n AC = Math.min(ip[0],AC);\n }\n if (ip[1] === 'CB' || ip[1] === 'BC'){\n BC = Math.min(ip[0],BC);\n }\n \n if (ip[1].length === 3){\n ABC = Math.min(ip[0],ABC);\n }\n AB = Math.min(A+B,AB);\n AC = Math.min(A+C,AC);\n BC = Math.min(B+C,BC);\n ABC = Math.min(A+B+C,AB+C,AC+B,BC+A,ABC);\n}\nprint((ABC === Number.MAX_VALUE)?-1:ABC);"}, {"source_code": "var n = Number(readline());\nvar input = [];\nvar hash = {}; var key;\nvar keymap = {A : 001,\n B : 010 ,\n C : 100,\n AB : 011,\n BC: 110,\n AC: 101,\n ABC: 111};\n\nfor(var i=0; i {\n// var input = [\"4\", \"5 C\", \"6 B\", \"16 ACB\", \"4 A\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar min = (...arg) => {\n var min;\n for(var a of arg){\n if(a != NaN && (!min || a < min)){\n min = a;\n }\n }\n return min;\n}\n\nvar bitStr = (val) => {\n var res = 0;\n for(var c of val){\n if(c == 'A'){\n res = res | 1;\n } else if(c == 'B'){\n res = res | 2;\n } else {\n res = res | 4;\n }\n }\n return res;\n}\n\nvar res = new Array(8)\nvar n = parseInt(readline())\nfor(var i = 0; i < n; i++){\n var line = readline().split(\" \");\n var price = parseInt(line[0]);\n var bit = bitStr(line[1]);\n if(!res[bit] || res[bit] > price){\n res[bit] = price;\n }\n}\n\nvar minPrice = min(res[1] + res[2] + res[4], res[1] + res[6], res[2] + res[5], res[3] + res[4], res[7])\nprint(minPrice || -1)"}, {"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: inp[0],\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n print(inArr)\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n // sortedArr = {}\n // costSorted.forEach((value) => {\n // sortedArr[value[0]] = value[1];\n // })\n\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1]\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n // console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 100,\n// vit: 'A'\n// }, {\n// cost: 355,\n// vit: 'BCA'\n// }, {\n// cost: 150,\n// vit: 'BC'\n// }, {\n// cost: 160,\n// vit: 'AC'\n// }, {\n// cost: 180,\n// vit: 'B'\n// }, {\n// cost: 190,\n// vit: 'CA'\n// }])\n\n// foo([{\n// cost: 10,\n// vit: 'AB'\n// }, {\n// cost: 15,\n// vit: 'BA'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'BA'\n// }, {\n// cost: 11,\n// vit: 'CB'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'C'\n// }, {\n// cost: 6,\n// vit: 'B'\n// }, {\n// cost: 16,\n// vit: 'BAC'\n// }, {\n// cost: 4,\n// vit: 'A'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\nprint(input)\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n print(inp)\n input.push({\n cost: inp[0],\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n // sortedArr = {}\n // costSorted.forEach((value) => {\n // sortedArr[value[0]] = value[1];\n // })\n\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1]\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n // console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 100,\n// vit: 'A'\n// }, {\n// cost: 355,\n// vit: 'BCA'\n// }, {\n// cost: 150,\n// vit: 'BC'\n// }, {\n// cost: 160,\n// vit: 'AC'\n// }, {\n// cost: 180,\n// vit: 'B'\n// }, {\n// cost: 190,\n// vit: 'CA'\n// }])\n\n// foo([{\n// cost: 10,\n// vit: 'AB'\n// }, {\n// cost: 15,\n// vit: 'BA'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'BA'\n// }, {\n// cost: 11,\n// vit: 'CB'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'C'\n// }, {\n// cost: 6,\n// vit: 'B'\n// }, {\n// cost: 16,\n// vit: 'BAC'\n// }, {\n// cost: 4,\n// vit: 'A'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: parseInt(inp[0]),\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n break;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1 && data[0] != 'ABC') {\n misVitSum += data[1];\n break;\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n //console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 198,\n// vit: 'BC'\n// }, {\n// cost: 259,\n// vit: 'AC'\n// }, {\n// cost: 125,\n// vit: 'BA'\n// }, {\n// cost: 298,\n// vit: 'CAB'\n// }, {\n// cost: 252,\n// vit: 'CA'\n// }, {\n// cost: 98,\n// vit: 'AC'\n// }, {\n// cost: 284,\n// vit: 'BAC'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: parseInt(inp[0]),\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n // sortedArr = {}\n // costSorted.forEach((value) => {\n // sortedArr[value[0]] = value[1];\n // })\n\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n break;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1]\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n //console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 9,\n// vit: 'C'\n// }, {\n// cost: 3,\n// vit: 'B'\n// }])\n\n// foo([{\n// cost: 100,\n// vit: 'A'\n// }, {\n// cost: 355,\n// vit: 'BCA'\n// }, {\n// cost: 150,\n// vit: 'BC'\n// }, {\n// cost: 160,\n// vit: 'AC'\n// }, {\n// cost: 180,\n// vit: 'B'\n// }, {\n// cost: 190,\n// vit: 'CA'\n// }])\n\n// foo([{\n// cost: 10,\n// vit: 'AB'\n// }, {\n// cost: 15,\n// vit: 'BA'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'BA'\n// }, {\n// cost: 11,\n// vit: 'CB'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'C'\n// }, {\n// cost: 6,\n// vit: 'B'\n// }, {\n// cost: 16,\n// vit: 'BAC'\n// }, {\n// cost: 4,\n// vit: 'A'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: parseInt(inp[0]),\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n break;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1];\n break;\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n //console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 198,\n// vit: 'BC'\n// }, {\n// cost: 259,\n// vit: 'AC'\n// }, {\n// cost: 125,\n// vit: 'BA'\n// }, {\n// cost: 298,\n// vit: 'CAB'\n// }, {\n// cost: 252,\n// vit: 'CA'\n// }, {\n// cost: 98,\n// vit: 'AC'\n// }, {\n// cost: 284,\n// vit: 'BAC'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\n\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: parseInt(inp[0]),\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n // sortedArr = {}\n // costSorted.forEach((value) => {\n // sortedArr[value[0]] = value[1];\n // })\n\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1]\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n // console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 100,\n// vit: 'A'\n// }, {\n// cost: 355,\n// vit: 'BCA'\n// }, {\n// cost: 150,\n// vit: 'BC'\n// }, {\n// cost: 160,\n// vit: 'AC'\n// }, {\n// cost: 180,\n// vit: 'B'\n// }, {\n// cost: 190,\n// vit: 'CA'\n// }])\n\n// foo([{\n// cost: 10,\n// vit: 'AB'\n// }, {\n// cost: 15,\n// vit: 'BA'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'BA'\n// }, {\n// cost: 11,\n// vit: 'CB'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'C'\n// }, {\n// cost: 6,\n// vit: 'B'\n// }, {\n// cost: 16,\n// vit: 'BAC'\n// }, {\n// cost: 4,\n// vit: 'A'\n// }])"}, {"source_code": "var number = readline();\nvar input = []\nfor (var i = 0; i < number; i++) {\n var inp = readline().split(' ');\n input.push({\n cost: inp[0],\n vit: inp[1]\n })\n}\n\nif (!Object.entries)\n Object.entries = function (obj) {\n var ownProps = Object.keys(obj),\n i = ownProps.length,\n resArray = new Array(i); // preallocate the Array\n\n while (i--)\n resArray[i] = [ownProps[i], obj[ownProps[i]]];\n return resArray;\n };\n\nfunction foo(inArr) {\n\n var sum = -1;\n var sortedArr = {}\n for (var data of inArr) {\n data.vit = data.vit.split('').sort().join('');\n if (!sortedArr[data.vit] || sortedArr[data.vit] > data.cost) {\n sortedArr[data.vit] = data.cost;\n }\n }\n\n\n // sortedArr = {}\n // costSorted.forEach((value) => {\n // sortedArr[value[0]] = value[1];\n // })\n\n\n\n for (var vit in sortedArr) {\n var missingVit = 'ABC'.replace(vit, '').split('');\n var tempSum = sortedArr[vit];\n var misVitSum = 0;\n\n var updateSum = function () {\n if (misVitSum) {\n tempSum += misVitSum;\n if (sum > tempSum || sum == -1) {\n sum = tempSum\n }\n }\n\n }\n //is single aviable\n for (var missVit of missingVit) {\n if (sortedArr[missVit]) {\n misVitSum += sortedArr[missVit]\n }\n else {\n misVitSum = 0;\n }\n }\n\n updateSum();\n\n //check combination\n misVitSum = 0;\n missingVit = missingVit.join('');\n var costSorted = Object.entries(sortedArr).sort((a, b) => a[1] - b[1]);\n for (var data of costSorted) {\n if (data[0].indexOf(missingVit) != -1) {\n misVitSum += data[1]\n }\n }\n\n updateSum();\n\n //check abc\n misVitSum = 0;\n if (sortedArr['ABC']) {\n misVitSum += sortedArr['ABC'];\n }\n updateSum();\n\n }\n\n // console.log(sum);\n print(sum)\n}\n\nfoo(input)\n\n// foo([{\n// cost: 100,\n// vit: 'A'\n// }, {\n// cost: 355,\n// vit: 'BCA'\n// }, {\n// cost: 150,\n// vit: 'BC'\n// }, {\n// cost: 160,\n// vit: 'AC'\n// }, {\n// cost: 180,\n// vit: 'B'\n// }, {\n// cost: 190,\n// vit: 'CA'\n// }])\n\n// foo([{\n// cost: 10,\n// vit: 'AB'\n// }, {\n// cost: 15,\n// vit: 'BA'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'BA'\n// }, {\n// cost: 11,\n// vit: 'CB'\n// }])\n\n// foo([{\n// cost: 5,\n// vit: 'C'\n// }, {\n// cost: 6,\n// vit: 'B'\n// }, {\n// cost: 16,\n// vit: 'BAC'\n// }, {\n// cost: 4,\n// vit: 'A'\n// }])"}], "src_uid": "02d62bb1eb4cc0e373b862a980d6b29c"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n /*let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n\r\n output(result);\r\n }*/\r\n let [n, m] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let prefix = new Array(n).fill(0);\r\n for (let i = 1; i < n; i++) {\r\n let cost = arr[i - 1] > arr[i] ? arr[i - 1] - arr[i] : 0;\r\n prefix[i] = prefix[i - 1] + cost;\r\n }\r\n\r\n let suffix = new Array(n).fill(0);\r\n for (let i = n - 2; i >= 0; i--) {\r\n let cost = arr[i + 1] > arr[i] ? arr[i + 1] - arr[i] : 0;\r\n suffix[i] = suffix[i + 1] + cost;\r\n }\r\n\r\n for (let test = 0; test < m; test++) {\r\n let [s, t] = readline().split(' ').map(Number).map(x => x - 1);\r\n\r\n let result = 0;\r\n if (s > t) {\r\n result = suffix[t] - suffix[s];\r\n } else {\r\n result = prefix[t] - prefix[s];\r\n }\r\n output(result);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n var tests = 1;\r\n for (let t = 0;t < tests; ++t) {\r\n var nq = readline().split(' ').map((x)=>parseInt(x));\r\n var arr = readline().split(' ').map((x) => parseInt(x));\r\n var pref = Array(nq[0]+1).fill(0);\r\n var suff = Array(nq[0]+1).fill(0);\r\n let n = nq[0];\r\n // console.log(arr);\r\n \r\n for (let i = 1;i < nq[0];++i) {\r\n if (arr[i] < arr[i-1]) {\r\n pref[i+1] = arr[i-1] - arr[i];\r\n }\r\n if (arr[n-1-i] < arr[n-i]) {\r\n suff[n-i] = arr[n-i] - arr[n-1-i];\r\n }\r\n pref[i+1] = pref[i+1] + pref[i];\r\n suff[n-i] = suff[n+1-i] + suff[n-i];\r\n }\r\n // console.log(pref);\r\n // console.log(suff);\r\n\r\n for (let i = 0;i < nq[1];++i) {\r\n var st = readline().split(' ').map((x)=>parseInt(x));\r\n if (st[0] < st[1]) {\r\n console.log(pref[st[1]] - pref[st[0]]);\r\n } else {\r\n console.log(suff[st[1]] - suff[st[0]]);\r\n\r\n }\r\n // console.log(st);\r\n }\r\n }\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const l = new Array(n),\r\n r = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n var _l, _a;\r\n l[i] = ((_l = l[i - 1]) !== null && _l !== void 0 ? _l : 0) + Math.max(0, ((_a = a[i - 1]) !== null && _a !== void 0 ? _a : a[i]) - a[i]);\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _r, _a2;\r\n r[i] = ((_r = r[i + 1]) !== null && _r !== void 0 ? _r : 0) + Math.max(0, ((_a2 = a[i + 1]) !== null && _a2 !== void 0 ? _a2 : a[i]) - a[i]);\r\n }\r\n const res = new Array(m);\r\n for (let i = 0; i < m; i++) {\r\n const [x, y] = b[i].map(num => num - 1);\r\n if (x === y) res[i] = 0;else if (x < y) {\r\n res[i] = l[y] - l[x];\r\n } else {\r\n res[i] = r[y] - r[x];\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [], "src_uid": "a6f42cb2627a7d1f6e01860322c5aac5"} {"source_code": "const n = Number(readline());\nprint((s => {\n var count = 0;\n var mismatch = false;\n for (var c of s)\n if (c === \"(\") count++;\n else if (count) count--;\n else {\n if (mismatch) return false;\n else mismatch = true;\n }\n return count === (mismatch ? 1 : 0);\n})(readline().substring(0, n)) ? \"Yes\" : \"No\");\n", "positive_code": [{"source_code": "const n = Number(readline());\nprint((s => {\n var count = 0;\n var mismatch = false;\n for (var c of s)\n if (c === \"(\") count++;\n else if (count) count--;\n else {\n if (mismatch) return false;\n else mismatch = true;\n }\n return count === (mismatch ? 1 : 0);\n})(readline().substring(0, n)) ? \"Yes\" : \"No\");\n"}], "negative_code": [], "src_uid": "e30085b163c820cff68fb24b94088ec1"} {"source_code": "'use strict';\n\nfunction obtain(s, t) {\n const m = s.length;\n const n = t.length;\n \n const next = Array(m+1);\n next[m] = {};\n for (let i = s.length-1; i >= 0; i--) {\n next[i] = Object.assign({}, next[i+1]);\n next[i][s[i]] = i;\n }\n \n let res = 1;\n let i = 0, j = 0;\n while (j < n) {\n if (i >= m) {\n i = 0;\n res++;\n }\n if (next[i][t[j]] === undefined) {\n i = 0;\n if (next[i][t[j]] === undefined) {\n return -1;\n }\n res++;\n }\n i = next[i][t[j]] + 1;\n j++;\n }\n \n return res;\n}\n\nfunction main() {\n const t = Number(readline());\n for (let i = 0; i < t; i++) {\n const s = readline();\n const t = readline();\n const res = obtain(s, t);\n print(res);\n }\n}\n\nmain();", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n \nfunction main(input) {\n let i = 0\n \n T=+input[0];\n for (x=0;x=0;i--){\n for (j=0;j<26;j++)\n dp[i][j]=dp[i+1][j]\n dp[i][s.charCodeAt(i)-'a'.charCodeAt(0)]=i \n }\n ans=1\n pos=0\n for (i=0;i {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const s = readString()\n const t = readString()\n let map = {}\n const sL = s.length\n const tL = t.length\n for(let i = 0; i < sL; i++) {\n if(!map[s[i]]) map[s[i]] = [i]\n else map[s[i]].push(i)\n }\n let curr = -1\n let count = 1\n let f = true\n for(let i = 0; i < tL; i++) {\n if(!map[t[i]]) {\n f = false\n break\n }\n // wr('curr', t[i], curr)\n let x = findMe(map[t[i]], curr)\n // wr('x', x, map[t[i]])\n if(x !== -1) curr = x\n else {\n count++\n curr = map[t[i]][0]\n }\n }\n if(!f) wr(-1)\n else wr(count)\n }\n\n function findMe(a, n) {\n let i = 0, j = a.length - 1\n while(i < j) {\n let m = Math.floor((i + j) / 2)\n // wr(i, m, j)\n if(a[m] <= n) {\n i = m + 1\n }\n else if(a[m] > n) {\n j = m\n }\n }\n if(a[i] > n) return a[i]\n else return -1\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n \nfunction main(input) {\n let i = 0\n \n T=+input[0];\n for (x=0;x=0;i--){\n for (j=0;j<26;j++)\n dp[i][j]=dp[i+1][j]\n dp[i][s.charCodeAt(i)-'a'.charCodeAt(0)]=i \n }\n ans=1\n pos=0\n for (i=0;i {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n const mp = arr.map((i, index) => ([i, index])).sort((a, b) => a[0] - b[0]).reverse()\r\n const ans = new Array(n).fill(0)\r\n let currentSide = true;\r\n let k = 1\r\n let minTime = 0;\r\n mp.forEach((i) => {\r\n let index = i[1]\r\n if (currentSide) {\r\n ans[index] = k\r\n } else {\r\n ans[index] = -k\r\n k++\r\n }\r\n currentSide = !currentSide\r\n })\r\n for (let i = 0; i < n; i++) {\r\n minTime += (2 * Math.abs(ans[i]) * arr[i]);\r\n }\r\n console.log(minTime)\r\n console.log(0 + ' ' + ans.join(' '))\r\n}\r\n\r\nfunction main() {\r\n \r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sorted = arr.map((x, i) => ({ x, i }))\n .sort((a, b) => b.x - a.x)\n let left = -1\n let right = 1\n const ans = Array(n)\n ans[0] = 0\n let d = 0\n for (let i = 0; i < sorted.length; i++) {\n ans[sorted[i].i + 1] = (i & 1) ? right++ : left--\n d += 2 * Math.abs(ans[sorted[i].i + 1]) * sorted[i].x\n }\n return d + '\\n' + ans.join(' ')\n}\n"}, {"source_code": "const solve = (arr)=>{\r\n let narr = [];\r\n for(let i=0;ib.val - a.val);\r\n let plus = 1,minus = 1,k=0,res = 0,obj = [];\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = [a[i], i];\r\n\t\t}\r\n\t\ta.sort((x, y) => y[0] - x[0]);\r\n\r\n\t\tconst ans = [0];\r\n\t\tlet dist = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[a[i][1]+1] = Math.ceil((i+1)/2) * (i&1 ? 1 : -1); \r\n\t\t\tdist += 2*a[i][0]*Math.abs(ans[a[i][1]+1]);\r\n\t\t}\r\n\r\n\t\tconsole.log(dist);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n while (t--) {\r\n var n = parseInt(readline());\r\n var input2 = readline().split(\" \");\r\n var arr = [];\r\n for (var i = 0; i < n; i++) {\r\n arr.push({\r\n value: parseInt(input2[i]),\r\n index: i,\r\n });\r\n }\r\n\r\n arr.sort((a, b) => {\r\n if (a.value > b.value) {\r\n return 1;\r\n } else if (a.value < b.value) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n\r\n var time = 0;\r\n var ans = [];\r\n var idx = 1;\r\n for (var i = n - 1; i >= 0; i -= 2) {\r\n var temp = 2 * idx;\r\n time = time + arr[i].value * temp;\r\n ans[arr[i].index] = idx;\r\n idx++;\r\n }\r\n\r\n idx = -1;\r\n for (var i = n - 2; i >= 0; i -= 2) {\r\n var temp = 2 * Math.abs(idx);\r\n time = time + arr[i].value * temp;\r\n ans[arr[i].index] = idx;\r\n idx--;\r\n }\r\n print(time);\r\n var val = \"0 \";\r\n for (var i = 0; i < n; i++) val += ans[i] + \" \";\r\n print(val);\r\n }"}], "negative_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n const mp = arr.map((i, index) => ([i, index])).reverse()\r\n const ans = new Array(n).fill(0)\r\n let currentSide = true;\r\n let k = 1\r\n let minTime = 0;\r\n mp.forEach((i) => {\r\n let value = i[0]\r\n let index = i[1]\r\n if (currentSide) {\r\n ans[index] = k\r\n } else {\r\n ans[index] = -k\r\n k++\r\n }\r\n currentSide = !currentSide\r\n })\r\n for (let i = 0; i < n; i++) {\r\n minTime += (2 * Math.abs(ans[i]) * arr[i]);\r\n }\r\n console.log(minTime)\r\n console.log(0 + ' ' + ans.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sorted = arr.map((x, i) => ({ x, i }))\n .sort((a, b) => b.x - a.x)\n let left = -1\n let right = 1\n const ans = Array(n)\n ans[0] = 0\n for (let i = 0; i < sorted.length; i++) {\n ans[sorted[i].i + 1] = (i & 1) ? right++ : left--\n }\n return ans.join(' ')\n}\n"}, {"source_code": " var t = parseInt(readline());\r\n\r\n while (t--) {\r\n var n = parseInt(readline());\r\n var input2 = readline().split(\" \");\r\n var arr = [];\r\n for (var i = 0; i < n; i++) {\r\n arr.push({\r\n value: parseInt(input2[i]),\r\n index: i,\r\n });\r\n }\r\n\r\n arr.sort((a, b) => {\r\n if (a.value > b.value) {\r\n return 1;\r\n } else if (a.value < b.value) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n\r\n var time = 0;\r\n var ans = [];\r\n var idx = 1;\r\n for (var i = n - 1; i >= 0; i -= 2) {\r\n var temp = 2 * idx;\r\n time = time + arr[i].value * temp;\r\n ans[arr[i].index] = idx;\r\n idx++;\r\n }\r\n\r\n idx = -1;\r\n for (var i = n - 2; i >= 0; i -= 2) {\r\n var temp = 2 * Math.abs(idx);\r\n time = time + arr[i].value * temp;\r\n ans[arr[i].index] = idx;\r\n idx--;\r\n }\r\n print(time);\r\n var val = \"\";\r\n for (var i = 0; i < n; i++) val += ans[i] + \" \";\r\n print(val);\r\n }"}], "src_uid": "17c3fad605bc50c0e7cb4c0718cde57f"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n\r\n// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A\r\n\r\n// function main() {\r\n// const testQuantity = +readLine();\r\n// for (let testNumber = 0; testNumber < testQuantity; testNumber++) {\r\n// let inputString = readLine();\r\n// let curLen = 0;\r\n// let curPrefix = \"\";\r\n// let maxPrefixLen = 0;\r\n\r\n// for (let inputChar of inputString) {\r\n// curPrefix += inputChar;\r\n// curLen++;\r\n\r\n// let foundNew = true;\r\n// let medianIndex = Math.floor(curLen / 2);\r\n// for (; medianIndex >= 0; medianIndex--) {\r\n// if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {\r\n// foundNew = false;\r\n// break;\r\n// }\r\n// }\r\n\r\n// if (foundNew) {\r\n// maxPrefixLen = curLen;\r\n// }\r\n// }\r\n\r\n// console.log(maxPrefixLen);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// let counter = 0;\r\n\r\n// for (let curLen = 0; curLen <= inputStr.length; curLen++) {\r\n// for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {\r\n// let substring = inputStr.substring(startIx, startIx + curLen);\r\n// let prefix = inputStr.substring(0, curLen);\r\n// let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);\r\n\r\n// if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {\r\n// counter++;\r\n// }\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem C\r\n\r\n// function match(text, pattern) {\r\n// if (pattern.length > text.length) {\r\n// return false;\r\n// }\r\n\r\n// for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {\r\n// if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== \"?\") {\r\n// return false;\r\n// }\r\n// }\r\n\r\n// return true;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// const entryIndexes = [];\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {\r\n// entryIndexes.push(startIx);\r\n// }\r\n// }\r\n\r\n// console.log(entryIndexes.length);\r\n// console.log(entryIndexes.join(\" \"));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem D\r\n\r\n// function getSubstrQuan(length) {\r\n// return (length + 1) * (length) / 2;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// let entryBorders = [];\r\n// let counter = 0;\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {\r\n// entryBorders.push([startIx, startIx + inputPattern.length - 1]);\r\n// }\r\n// }\r\n \r\n// entryBorders.push([inputStr.length, inputStr.length]);\r\n// let lastLeftBorder = 0;\r\n// for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {\r\n// let curPair = entryBorders[pairIx];\r\n// let curSubstrLen = curPair[1] - lastLeftBorder;\r\n// counter += getSubstrQuan(curSubstrLen);\r\n// lastLeftBorder = curPair[0] + 1;\r\n\r\n// if (curPair[1] - curPair[0] - 1 > 0) {\r\n// counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n\r\n// Codeforces Round #698 (Div. 2) -> Problem A\r\n\r\n// function main() {\r\n// let testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// let n = +readLine();\r\n// let a = readLine().split(\" \");\r\n// a = a.map(item => +item);\r\n// let counterArr = [];\r\n// for (let i = 0; i <= n; i++) counterArr[i] = 0;\r\n\r\n// for (let el of a) {\r\n// counterArr[el]++; \r\n// }\r\n\r\n// console.log(Math.max(...counterArr));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\nfunction main() {\r\n const testQuan = +readLine();\r\n for (let testIx = 0; testIx < testQuan; testIx++) {\r\n let [, d] = readLine().split(\" \").map(item => +item);\r\n let a = readLine().split(\" \").map(item => +item);\r\n\r\n let possibleLastDigits = [];\r\n for (let multiplier = 1; multiplier < 11; multiplier++) {\r\n possibleLastDigits.push(d * multiplier % 10);\r\n }\r\n\r\n let canGain = num => {\r\n let curLastDigit = num % 10;\r\n let multiplier = possibleLastDigits.indexOf(curLastDigit) + 1;\r\n\r\n return multiplier ? multiplier * d <= num : false;\r\n };\r\n\r\n for (let item of a) {\r\n let flag = canGain(item) || String(item).includes(`${d}`);\r\n // console.log(item + \", \" + flag);\r\n for (let i = 0; i < 10; i++) {\r\n let tmp = item;\r\n // console.log(tmp, i);\r\n tmp -= d * 10 + i;\r\n // console.log(tmp);\r\n\r\n if (tmp > 0) {\r\n flag = flag || canGain(tmp);\r\n }\r\n // console.log(flag);\r\n }\r\n\r\n console.log(flag ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}\r\n\r\n// .. -> Problem C\r\n\r\n// function main() {\r\n\r\n// }", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar a = nextInt();\r\n\t\t\tif(a % d == 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar tmp = a;\r\n\t\t\tvar isOK = false;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tif(tmp % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t}\r\n\t\t\tvar p = a % d;\r\n\t\t\tfor(var k = 1; k <= Math.floor(a / d); k++){\r\n\t\t\t\tvar tmp = (k * d + p);\r\n\t\t\t\twhile(tmp > 0){\r\n\t\t\t\t\tif(tmp % 10 == d){\r\n\t\t\t\t\t\tisOK = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t\t}\r\n\t\t\t\tif(isOK){\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(isOK){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n2\r\n3 7\r\n24 25 27\r\n10 7\r\n51 52 53 54 55 56 57 58 59 60\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r number) {\r\n current = current - number;\r\n \r\n if (map[current]) {\r\n console.log(map[current]);\r\n found = true;\r\n }else if ((\"\" + current).includes(d)) {\r\n map[current] = 'Yes';\r\n\r\n console.log(map[current]);\r\n found = true;\r\n }\r\n }\r\n\r\n if(found === false) {\r\n map[a[i]] = 'No';\r\n console.log(\"No\");\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readline();\r\n\r\n while (t--) {\r\n const d = readline().split(' ').map(num => parseInt(num, 10))[1];\r\n const q = readline().split(' ').map(num => parseInt(num, 10));\r\n\r\n q.forEach(n => {\r\n let r = '';\r\n\r\n for (let i = n; i > 0; i -= d) {\r\n const iar = `${i}`.includes(d);\r\n\r\n if (iar) {\r\n r = 'YES';\r\n break;\r\n } else {\r\n r = 'NO';\r\n }\r\n }\r\n\r\n console.log(r);\r\n });\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [q, d] = readline().split(' ').map(x => Number(x));\r\n var array = readline().split(' ').map(x => Number(x));\r\n var answer = {}\r\n for (var i = 0; i < 100; i++) {\r\n answer[i] = true\r\n }\r\n for (var i = 0; i < 100; i++) {\r\n answer[i * d] = false\r\n answer[i * d + Number(`1${d}`)] = false\r\n answer[i * d + Number(`2${d}`)] = false\r\n answer[i * d + Number(`3${d}`)] = false\r\n answer[i * d + Number(`4${d}`)] = false\r\n answer[i * d + Number(`5${d}`)] = false\r\n answer[i * d + Number(`6${d}`)] = false\r\n answer[i * d + Number(`7${d}`)] = false\r\n answer[i * d + Number(`8${d}`)] = false\r\n answer[i * d + Number(`9${d}`)] = false\r\n answer[i * d + Number(`${d}0`)] = false\r\n answer[i * d + Number(`${d}1`)] = false\r\n answer[i * d + Number(`${d}2`)] = false\r\n answer[i * d + Number(`${d}3`)] = false\r\n answer[i * d + Number(`${d}4`)] = false\r\n answer[i * d + Number(`${d}5`)] = false\r\n answer[i * d + Number(`${d}6`)] = false\r\n answer[i * d + Number(`${d}7`)] = false\r\n answer[i * d + Number(`${d}8`)] = false\r\n answer[i * d + Number(`${d}9`)] = false\r\n }\r\n // console.log(answer)\r\n // for (var i = 0; i < 100; i++) {\r\n // if (answer[i]) console.log(i)\r\n // }\r\n array.map((x,i)=>{\r\n console.log(!answer[x] ? 'YES':'NO')\r\n })\r\n\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let temp = readline().split(\" \").map(x => parseInt(x));\r\n let length = temp[0];\r\n let d = temp[1];\r\n let input = readline().split(\" \");\r\n\r\n let obj = {\r\n \"0\" : null,\r\n \"1\" : null,\r\n \"2\" : null,\r\n \"3\" : null,\r\n \"4\" : null,\r\n \"5\" : null,\r\n \"6\" : null,\r\n \"7\" : null,\r\n \"8\" : null,\r\n \"9\" : null,\r\n };\r\n\r\n for(let i = 1; i < 11; i++){\r\n let t = String(i * d)\r\n if(obj[t[t.length - 1]] === null){\r\n obj[t[t.length - 1]] = parseInt(t);\r\n }\r\n }\r\n\r\n for(let i = 0; i < length; i++){\r\n let t = input[i][input[i].length - 1];\r\n if(obj[t] === null){\r\n if(parseInt(input[i]) > d * 10){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\")\r\n }\r\n } else if(obj[t] <= parseInt(input[i])){\r\n print(\"YES\") \r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n}"}, {"source_code": "function solve(a,n){\r\n var l = 0;\r\n \r\n while(l < a.length){\r\n var f = true;\r\n if(String(a[l]).includes(String(n))){\r\n write(\"YES\\n\");\r\n }else{\r\n var aux = a[l];\r\n while(aux > 0){\r\n aux = aux - Number(n);\r\n if(String(aux).includes(String(n))){\r\n write(\"YES\\n\");\r\n f = false;\r\n break;\r\n }\r\n }\r\n if(f){\r\n write(\"NO\\n\");\r\n }\r\n }\r\n l++;\r\n }\r\n \r\n}\r\n\r\nvar a = [];\r\nvar t = Number(readline());\r\nfor (var i = 0; i x);\r\n a = readline().split(' ').map((x) => x);\r\n solve(a,n[1]);\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (arr[i] >= d * 10) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n let k = arr[i];\r\n while (k > 0) {\r\n if (precheck(k, d)) {\r\n flag = true;\r\n break;\r\n }\r\n k = k - d;\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet dp = [];\r\nconst precompute = () => {\r\n for (let i = 2; i <= 9; i++) {\r\n let k = [];\r\n for (let j = 0; j <= 9; j++) {\r\n k.push(i * (j + 1));\r\n }\r\n dp.push(k);\r\n }\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (precheck(arr[i], d)) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n for (let j = 0; j <= 9; j++) {\r\n if (dp[d - 2][j] % 10 === arr[i] % 10) {\r\n if (arr[i] >= dp[d - 2][j]) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet dp = [];\r\nconst precompute = () => {\r\n for (let i = 2; i <= 9; i++) {\r\n let k = [];\r\n for (let j = 0; j <= 9; j++) {\r\n k.push(i * (j + 1));\r\n }\r\n dp.push(k);\r\n }\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (precheck(arr[i], d)) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n for (let j = 0; j <= 9; j++) {\r\n if (dp[d - 2][j] % 10 === arr[i] % 10) {\r\n flag = dp[d - 2][j] <= arr[i] ? true : false;\r\n }\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet dp = [];\r\nconst precompute = () => {\r\n for (let i = 2; i <= 9; i++) {\r\n let k = [];\r\n for (let j = 0; j <= 9; j++) {\r\n k.push(i * (j + 1));\r\n }\r\n dp.push(k);\r\n }\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (precheck(arr[i], d)) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n for (let j = 0; j <= 9; j++) {\r\n if (dp[d - 2][j] % 10 === arr[i] % 10) {\r\n flag = dp[d - 2][j] <= arr[i] ? true : false;\r\n break;\r\n }\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet dp = [];\r\nconst precompute = () => {\r\n for (let i = 2; i <= 9; i++) {\r\n let k = [];\r\n for (let j = 0; j <= 9; j++) {\r\n k.push(i * (j + 1));\r\n }\r\n dp.push(k);\r\n }\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (precheck(arr[i], d)) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n for (let j = 0; j < 9; j++) {\r\n if (dp[d - 2][j] % 10 === arr[i] % 10) {\r\n flag = dp[d - 2][j] <= arr[i] ? true : false;\r\n break;\r\n }\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet dp = [];\r\nconst precompute = () => {\r\n for (let i = 2; i <= 9; i++) {\r\n let k = [];\r\n for (let j = 0; j < 9; j++) {\r\n k.push(i * (j + 1));\r\n }\r\n dp.push(k);\r\n }\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n const precheck = (n, d) => {\r\n while (n > 0) {\r\n if (n % 10 === d) return true;\r\n n = Math.floor(n / 10);\r\n }\r\n return false;\r\n };\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n if (d === 1) console.log(\"YES\");\r\n else if (precheck(arr[i], d)) console.log(\"YES\");\r\n else {\r\n let flag = false;\r\n for (let j = 0; j < 9; j++) {\r\n if (dp[d - 2][j] % 10 === arr[i] % 10) {\r\n flag = dp[d - 2][j] <= arr[i] ? true : false;\r\n break;\r\n }\r\n }\r\n console.log(`${flag === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar a = nextInt();\r\n\t\t\tif(a % d == 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar tmp = a;\r\n\t\t\tvar isOK = false;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tif(tmp % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t}\r\n\t\t\tvar p = a % d;\r\n\t\t\tfor(var k = 1; k <= Math.min(100, Math.floor(a / d)); k++){\r\n\t\t\t\tif((k * d + p) % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(isOK){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar a = nextInt();\r\n\t\t\tif(a % d == 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar tmp = a;\r\n\t\t\tvar isOK = false;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tif(tmp % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t}\r\n\t\t\tvar p = a % d;\r\n\t\t\tfor(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){\r\n\t\t\t\tif((k * d + p) % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(isOK){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar a = nextInt();\r\n\t\t\tif(a % d == 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar tmp = a;\r\n\t\t\tvar isOK = false;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tif(tmp % d == 0){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t}\r\n\t\t\tvar p = a % d;\r\n\t\t\tfor(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){\r\n\t\t\t\tif((k * d + p) % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(isOK){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar a = nextInt();\r\n\t\t\tif(a % 10 == d || a % d == 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar tmp = a;\r\n\t\t\tvar isOK = false;\r\n\t\t\twhile(tmp > 0){\r\n\t\t\t\tif(tmp % d == 0){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttmp = Math.floor(tmp / 10);\r\n\t\t\t}\r\n\t\t\tvar p = a % d;\r\n\t\t\tfor(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){\r\n\t\t\t\tif((k * d + p) % 10 == d){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(d + p == 10){\r\n\t\t\t\tisOK = true;\r\n\t\t\t}\r\n\t\t\tif(isOK){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n\r\n// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A\r\n\r\n// function main() {\r\n// const testQuantity = +readLine();\r\n// for (let testNumber = 0; testNumber < testQuantity; testNumber++) {\r\n// let inputString = readLine();\r\n// let curLen = 0;\r\n// let curPrefix = \"\";\r\n// let maxPrefixLen = 0;\r\n\r\n// for (let inputChar of inputString) {\r\n// curPrefix += inputChar;\r\n// curLen++;\r\n\r\n// let foundNew = true;\r\n// let medianIndex = Math.floor(curLen / 2);\r\n// for (; medianIndex >= 0; medianIndex--) {\r\n// if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {\r\n// foundNew = false;\r\n// break;\r\n// }\r\n// }\r\n\r\n// if (foundNew) {\r\n// maxPrefixLen = curLen;\r\n// }\r\n// }\r\n\r\n// console.log(maxPrefixLen);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// let counter = 0;\r\n\r\n// for (let curLen = 0; curLen <= inputStr.length; curLen++) {\r\n// for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {\r\n// let substring = inputStr.substring(startIx, startIx + curLen);\r\n// let prefix = inputStr.substring(0, curLen);\r\n// let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);\r\n\r\n// if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {\r\n// counter++;\r\n// }\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem C\r\n\r\n// function match(text, pattern) {\r\n// if (pattern.length > text.length) {\r\n// return false;\r\n// }\r\n\r\n// for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {\r\n// if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== \"?\") {\r\n// return false;\r\n// }\r\n// }\r\n\r\n// return true;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// const entryIndexes = [];\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {\r\n// entryIndexes.push(startIx);\r\n// }\r\n// }\r\n\r\n// console.log(entryIndexes.length);\r\n// console.log(entryIndexes.join(\" \"));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem D\r\n\r\n// function getSubstrQuan(length) {\r\n// return (length + 1) * (length) / 2;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// let entryBorders = [];\r\n// let counter = 0;\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {\r\n// entryBorders.push([startIx, startIx + inputPattern.length - 1]);\r\n// }\r\n// }\r\n \r\n// entryBorders.push([inputStr.length, inputStr.length]);\r\n// let lastLeftBorder = 0;\r\n// for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {\r\n// let curPair = entryBorders[pairIx];\r\n// let curSubstrLen = curPair[1] - lastLeftBorder;\r\n// counter += getSubstrQuan(curSubstrLen);\r\n// lastLeftBorder = curPair[0] + 1;\r\n\r\n// if (curPair[1] - curPair[0] - 1 > 0) {\r\n// counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n\r\n// Codeforces Round #698 (Div. 2) -> Problem A\r\n\r\n// function main() {\r\n// let testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// let n = +readLine();\r\n// let a = readLine().split(\" \");\r\n// a = a.map(item => +item);\r\n// let counterArr = [];\r\n// for (let i = 0; i <= n; i++) counterArr[i] = 0;\r\n\r\n// for (let el of a) {\r\n// counterArr[el]++; \r\n// }\r\n\r\n// console.log(Math.max(...counterArr));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\nfunction main() {\r\n let testQuan = +readLine();\r\n for (let testIx = 0; testIx < testQuan; testIx++) {\r\n let [d, q] = readLine().split(\" \").map(item => +item);\r\n let a = readLine().split(\" \").map(item => +item);\r\n let possibleLastDigits = [];\r\n\r\n for (let multiplier = 1; multiplier < 11; multiplier++) {\r\n possibleLastDigits.push(multiplier * q % 10);\r\n }\r\n\r\n for (let el of a) {\r\n let curLastDigit = el % 10;\r\n\r\n if (q % 2 === 0 && el % 2 === 1) {\r\n el -= q * 10 + curLastDigit;\r\n\r\n if (el < 0) {\r\n console.log(\"NO\");\r\n continue;\r\n } else if (el === 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n }\r\n\r\n curLastDigit = el % 10;\r\n let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;\r\n\r\n if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n console.log(\"YES\");\r\n }\r\n }\r\n}\r\n\r\n// .. -> Problem C\r\n\r\n// function main() {\r\n\r\n// }"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n\r\n// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A\r\n\r\n// function main() {\r\n// const testQuantity = +readLine();\r\n// for (let testNumber = 0; testNumber < testQuantity; testNumber++) {\r\n// let inputString = readLine();\r\n// let curLen = 0;\r\n// let curPrefix = \"\";\r\n// let maxPrefixLen = 0;\r\n\r\n// for (let inputChar of inputString) {\r\n// curPrefix += inputChar;\r\n// curLen++;\r\n\r\n// let foundNew = true;\r\n// let medianIndex = Math.floor(curLen / 2);\r\n// for (; medianIndex >= 0; medianIndex--) {\r\n// if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {\r\n// foundNew = false;\r\n// break;\r\n// }\r\n// }\r\n\r\n// if (foundNew) {\r\n// maxPrefixLen = curLen;\r\n// }\r\n// }\r\n\r\n// console.log(maxPrefixLen);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// let counter = 0;\r\n\r\n// for (let curLen = 0; curLen <= inputStr.length; curLen++) {\r\n// for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {\r\n// let substring = inputStr.substring(startIx, startIx + curLen);\r\n// let prefix = inputStr.substring(0, curLen);\r\n// let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);\r\n\r\n// if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {\r\n// counter++;\r\n// }\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem C\r\n\r\n// function match(text, pattern) {\r\n// if (pattern.length > text.length) {\r\n// return false;\r\n// }\r\n\r\n// for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {\r\n// if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== \"?\") {\r\n// return false;\r\n// }\r\n// }\r\n\r\n// return true;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// const entryIndexes = [];\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {\r\n// entryIndexes.push(startIx);\r\n// }\r\n// }\r\n\r\n// console.log(entryIndexes.length);\r\n// console.log(entryIndexes.join(\" \"));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem D\r\n\r\n// function getSubstrQuan(length) {\r\n// return (length + 1) * (length) / 2;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// let entryBorders = [];\r\n// let counter = 0;\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {\r\n// entryBorders.push([startIx, startIx + inputPattern.length - 1]);\r\n// }\r\n// }\r\n \r\n// entryBorders.push([inputStr.length, inputStr.length]);\r\n// let lastLeftBorder = 0;\r\n// for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {\r\n// let curPair = entryBorders[pairIx];\r\n// let curSubstrLen = curPair[1] - lastLeftBorder;\r\n// counter += getSubstrQuan(curSubstrLen);\r\n// lastLeftBorder = curPair[0] + 1;\r\n\r\n// if (curPair[1] - curPair[0] - 1 > 0) {\r\n// counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n\r\n// Codeforces Round #698 (Div. 2) -> Problem A\r\n\r\n// function main() {\r\n// let testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// let n = +readLine();\r\n// let a = readLine().split(\" \");\r\n// a = a.map(item => +item);\r\n// let counterArr = [];\r\n// for (let i = 0; i <= n; i++) counterArr[i] = 0;\r\n\r\n// for (let el of a) {\r\n// counterArr[el]++; \r\n// }\r\n\r\n// console.log(Math.max(...counterArr));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\nfunction main() {\r\n let testQuan = +readLine();\r\n for (let testIx = 0; testIx < testQuan; testIx++) {\r\n let [d, q] = readLine().split(\" \").map(item => +item);\r\n let a = readLine().split(\" \").map(item => +item);\r\n let possibleLastDigits = [];\r\n\r\n for (let multiplier = 1; multiplier < 11; multiplier++) {\r\n possibleLastDigits.push(multiplier * q % 10);\r\n }\r\n\r\n for (let el of a) {\r\n let curLastDigit = el % 10;\r\n\r\n if (q % 2 === 0 && el % 2 === 1) {\r\n el -= q * 10 + curLastDigit;\r\n\r\n if (el < 0) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n }\r\n\r\n curLastDigit = el % 10;\r\n let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;\r\n\r\n if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n console.log(\"YES\");\r\n }\r\n }\r\n}\r\n\r\n// .. -> Problem C\r\n\r\n// function main() {\r\n\r\n// }"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n\r\n// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A\r\n\r\n// function main() {\r\n// const testQuantity = +readLine();\r\n// for (let testNumber = 0; testNumber < testQuantity; testNumber++) {\r\n// let inputString = readLine();\r\n// let curLen = 0;\r\n// let curPrefix = \"\";\r\n// let maxPrefixLen = 0;\r\n\r\n\r\n// .. -> Problem B\r\n\r\nfunction main() {\r\n let testQuan = +readLine();\r\n for (let testIx = 0; testIx < testQuan; testIx++) {\r\n let [d, q] = readLine().split(\" \").map(item => +item);\r\n let a = readLine().split(\" \").map(item => +item);\r\n let possibleLastDigits = [];\r\n\r\n for (let multiplier = 1; multiplier < 11; multiplier++) {\r\n possibleLastDigits.push(multiplier * q % 10);\r\n }\r\n\r\n for (let el of a) {\r\n let curLastDigit = el % 10;\r\n let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;\r\n\r\n if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n console.log(\"YES\");\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n2\r\n3 7\r\n24 25 27\r\n10 7\r\n51 52 53 54 55 56 57 58 59 60\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r number) {\r\n current = current - number;\r\n \r\n if(map[current]) {\r\n console.log(map[current]);\r\n found = true;\r\n }\r\n\r\n if ((\"\" + current).includes(d)) {\r\n map[current] = 'Yes';\r\n console.log(map[current]);\r\n found = true;\r\n }\r\n }\r\n\r\n if(found === false) {\r\n map[a[i]] = 'No';\r\n console.log(\"No\");\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let temp = readline().split(\" \").map(x => parseInt(x));\r\n let length = temp[0];\r\n let d = temp[1];\r\n let input = readline().split(\" \");\r\n\r\n let obj = {\r\n \"0\" : null,\r\n \"1\" : null,\r\n \"2\" : null,\r\n \"3\" : null,\r\n \"4\" : null,\r\n \"5\" : null,\r\n \"6\" : null,\r\n \"7\" : null,\r\n \"8\" : null,\r\n \"9\" : null,\r\n };\r\n\r\n for(let i = 1; i < 11; i++){\r\n let t = String(i * d)\r\n if(obj[t[t.length - 1]] === null){\r\n obj[t[t.length - 1]] = parseInt(t);\r\n }\r\n }\r\n\r\n for(let i = 0; i < length; i++){\r\n let t = input[i][input[i].length - 1];\r\n if(obj[t] === null){\r\n let a = input[i] % (d * 10);\r\n let b = Math.trunc(input[i] / (d * 10))\r\n if(a % b === 0){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\")\r\n }\r\n } else if(obj[t] <= parseInt(input[i])){\r\n print(\"YES\") \r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let temp = readline().split(\" \").map(x => parseInt(x));\r\n let length = temp[0];\r\n let d = temp[1];\r\n let input = readline().split(\" \");\r\n\r\n let obj = {\r\n \"0\" : null,\r\n \"1\" : null,\r\n \"2\" : null,\r\n \"3\" : null,\r\n \"4\" : null,\r\n \"5\" : null,\r\n \"6\" : null,\r\n \"7\" : null,\r\n \"8\" : null,\r\n \"9\" : null,\r\n };\r\n\r\n for(let i = 1; i < 11; i++){\r\n let t = String(i * d)\r\n if(obj[t[t.length - 1]] === null){\r\n obj[t[t.length - 1]] = parseInt(t);\r\n }\r\n }\r\n\r\n for(let i = 0; i < length; i++){\r\n let t = input[i][input[i].length - 1];\r\n if(obj[t] === null){\r\n let a = input[i] % (d * 10);\r\n let b = Math.trunc(input[i] / (d * 10))\r\n if(a < b * 9){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\")\r\n }\r\n } else if(obj[t] <= parseInt(input[i])){\r\n print(\"YES\") \r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let temp = readline().split(\" \").map(x => parseInt(x));\r\n let length = temp[0];\r\n let d = temp[1];\r\n let input = readline().split(\" \");\r\n\r\n let obj = {\r\n \"0\" : null,\r\n \"1\" : null,\r\n \"2\" : null,\r\n \"3\" : null,\r\n \"4\" : null,\r\n \"5\" : null,\r\n \"6\" : null,\r\n \"7\" : null,\r\n \"8\" : null,\r\n \"9\" : null,\r\n };\r\n\r\n for(let i = 1; i < 11; i++){\r\n let t = String(i * d)\r\n if(obj[t[t.length - 1]] === null){\r\n obj[t[t.length - 1]] = parseInt(t);\r\n }\r\n }\r\n\r\n for(let i = 0; i < length; i++){\r\n let t = input[i][input[i].length - 1];\r\n if(obj[t] !== null && obj[t] <= parseInt(input[i])){\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n}"}], "src_uid": "7975af65a23bad6a0997921c7e31d3ca"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar mod = 998244353;\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tif(N % 2 == 1){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar v = 1;\r\n\t\tfor(var i = 1; i <= N / 2; i++){\r\n\t\t\tv *= i;\r\n\t\t\tv %= mod;\r\n\t\t\tv *= i;\r\n\t\t\tv %= mod;\r\n\t\t}\r\n\t\tmyout(v);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const mod = 998244353;\r\n let n = parseInt(readline(), 10);\r\n\r\n if (n % 2 === 1) {\r\n output(0);\r\n continue;\r\n }\r\n\r\n let m = n / 2;\r\n let res = 1;\r\n for (let i = 1; i <= m; i++) {\r\n res *= i;\r\n res = res % mod;\r\n }\r\n\r\n let one = BigInt(res);\r\n let modd = BigInt(mod);\r\n let result = (one * one) % modd;\r\n\r\n output(result.toString());\r\n }\r\n}\r\n"}, {"source_code": "// problems/contest1658/B/src/ts/solution.ts\nvar lines = [];\nrequire(\"readline\").createInterface({\n input: process.stdin\n}).on(\"line\", (line) => lines.push(line));\nprocess.stdin.on(\"end\", () => {\n main(lines);\n});\nvar MOD = 998244353;\nvar mul = (a, b) => Number(BigInt(a) * BigInt(b) % BigInt(MOD));\nfunction main(lines2) {\n let i = 0;\n for (let t = Number(lines2[i++]); t > 0; t--) {\n const n = Number(lines2[i++]);\n console.log(solve(n));\n }\n}\nfunction fac(n) {\n let res = 1;\n for (let i = 1; i <= n; i++)\n res = mul(res, i);\n return res;\n}\nfunction solve(n) {\n if (n % 2 !== 0)\n return 0;\n const m = fac(n / 2);\n return mul(m, m);\n}\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = Number(inputs[0])\r\nfor (let _ = 0, __ = 1; _ < N; _++) {\r\n const n = Number(inputs[__++])\r\n main(n)\r\n}\r\n\r\nfunction main(n) {\r\n const MOD = BigInt(998244353)\r\n if (n & 1) {\r\n console.log(0)\r\n } else {\r\n let res = 1n\r\n n = BigInt(n / 2)\r\n while (n) {\r\n res *= n--\r\n }\r\n res = res * res\r\n console.log(Number(res % MOD))\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n & 1) return 0\n\n n /= 2\n let now = 1\n for (let i = 1; i <= n; i++) {\n now = mul(now, i)\n }\n return mul(now, now)\n}\n\nconst MOD = 998244353\nconst MOD_CUT = ((1 << 20) * (1 << 20)) % MOD\nfunction add(a, b) {\n return (a + b) % MOD\n}\nfunction minus(a, b) {\n return add(add(a, -b), MOD)\n}\nfunction mul(a, b) {\n let r = (a >> 20) * (b >> 20) * MOD_CUT\n + (a & 0xfff00000) * (b & 0xfffff)\n + (a & 0xfffff) * b\n return r % MOD\n}\nfunction pow(a, b) {\n let r = 1\n let base = a\n while (b) {\n if (b & 1) {\n r = mul(r, base)\n }\n b >>= 1\n base = mul(base, base)\n }\n return r\n}\n"}, {"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n \r\n if (n % 2 !== 0) print(0);\r\n else { \r\n n = n / 2;\r\n var ans = 1;\r\n for (var j = n; j > 0; j--) {\r\n ans *= j * j % 998244353;\r\n ans %= 998244353;\r\n }\r\n print(ans);\r\n }\r\n}"}], "negative_code": [{"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n \r\n if (n % 2 !== 0) print(0);\r\n else { \r\n n = Math.floor(n / 2);\r\n var ans = 1;\r\n for (var j = 1; j <= n; j++) {\r\n ans = (ans * j) % 998244353;\r\n }\r\n ans = (ans * ans) % 998244353;\r\n print(ans);\r\n }\r\n}"}], "src_uid": "0b718a81787c3c5c1aa5b92834ee8bf5"} {"source_code": "var testAmount = parseInt(readline());\n\nvar wrapperAmounts = [];\nfor (var i = 0; i < testAmount; i++) {\n wrapperAmounts.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < wrapperAmounts.length; i++) {\n for (var k = 2; k <= 29; k++) {\n var x = wrapperAmounts[i] / (Math.pow(2, k) - 1);\n if (x === Math.floor(x)) {\n print(x);\n break;\n }\n }\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n //let [n, industry] = readline().split(\" \").map(e => parseInt(e));\n\n let cases = parseInt(readline(), 10);\n for (var i = 0; i < cases; i++) {\n let d = [1,2]\n let sum = 3;\n const p = parseInt(readline(), 10);\n\n while (p % sum != 0) {\n d.push(d[d.length-1]*2);\n sum = d.reduce((a,b) => a+b, 0);\n }\n\n console.log(p / sum);\n }\n\n\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n else if (n % 7 == 0) print(n / 7);\n else {\n var k = 2;\n var flag = true;\n while (flag == true) {\n var x = n / (Math.pow(2, k) - 1);\n\n if (x == Math.floor(x) && x > 0) {\n print(x);\n flag = false;\n }\n k++;\n }\n }\n}\n"}, {"source_code": "r=readline\nn=+r()\nwhile(n--){\n t=+r()\n for(i=2;iNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tvar k = 2;\n\t\tvar count = 3;\n\t\twhile(true){\n\t\t\tif(n % count == 0){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk++;\n\t\t\tcount += Math.pow(2,k - 1);\n\t\t}\n\t\toutput[i] = n / count;\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "var n = Number(readline());\nvar inp;\nfor(var i = 0; i < n; i++){\n inp = Number(readline());\n var k = 3;\n while(inp%k !== 0){\n k = k*2 + 1 \n }\n print(inp/k)\n\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor(var qq = 0; qq < t; qq++) {\n var n = parseInt(readline());\n\n var k = 2;\n\n while (true) {\n var kk = (1 << k);\n var del = kk - 1;\n \n if (n === del || n % del === 0) {\n break;\n }\n k++;\n }\n \n var kkk = (1 << k);\n var x = n / (kkk - 1)\n\n print(x);\n}"}, {"source_code": "//Candies\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let t = +lines[0];\n\n let f = (x) => {\n \tfor(let i = 2; i < 64; i++) {\n \t\tif(x % (Math.pow(2, i) - 1) == 0) {\n \t\t\treturn (x / (Math.pow(2, i) - 1));\n \t\t}\n \t}\n }\n\n for(let i = 0; i < t; i++) {\n \tprocess.stdout.write(f(+lines[i + 1]) + EOL);\n }\n\n return;\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\nconst powers = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n\n for (let i = 0; i < 60; i++) {\n powers.push(2**i);\n }\n return;\n }\n\n let n = +d;\n let x = n < 100 ? 1 : Math.floor(n / 3);\n\n for (let i = 2; i < powers.length; i++) {\n let t = powers[i] - 1;\n if (n % t === 0) {\n ans += `${n / t}\\n`;\n break;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var input = parseInt(readline())\n //var a = readline().split(\" \").map(x => parseInt(x))\n while (input--) {\n var n = parseInt(readline())\n var res = 0\n for (var i = 0; i < n; i++) {\n res += Math.pow(2, i)\n if (res != 1 && n % res == 0) {\n var a = n / res\n print(a)\n break;\n }\n }\n }\n\n}"}, {"source_code": "function solve(n) {\n let t = 3;\n while (t <= n) {\n const u = n % t;\n if (u === 0) {\n const x = n / t;\n return x;\n }\n t = t + t + 1;\n }\n throw Error('could not solve the problem');\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const n = Number(t);\n const result = solve(n);\n console.log(result);\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(n) {\n let t = 3;\n while (t <= n) {\n const u = n % t;\n if (u === 0) {\n const x = n / t;\n return x;\n }\n t = t + t + 1;\n }\n throw Error('could not solve the problem');\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n const n = Number(line);\n const result = solve(n);\n console.log(result);\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nlet calcMaxSq = (n, a, start) => {\n let res = 1;\n for (let i = n - 1; i > start; i++) {\n if (a[i] === a[start]) {\n res++;\n }\n }\n return res;\n}\n\nfunction solve(n) {\n let nums = [1];\n let k = 1;\n while (true) {\n k *= 2;\n let current = k + nums[nums.length - 1];\n if (n % current === 0) return n / current;\n nums.push(current);\n }\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n var k = 2;\n var flag = true;\n while (flag == true) {\n var x = n / (Math.pow(2, k) - 1);\n\n if (x == Math.floor(x) && x > 0) {\n print(x);\n flag = false;\n }\n k++;\n }\n}\n"}, {"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n\n\n// ************************ Code Start ***************************\n\nfunction main() {\n\n var Tc = parseInt(readline());\n for (; Tc--;) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "\"use strict\";\n\nfunction print(x) {\n console.log(x);\n} \nlet x = \"\", y = 0;\n \nprocess.stdin.on(\"data\", inputStdin => x += inputStdin);\nprocess.stdin.on(\"end\", () => {\n x = x.split(\"\\n\");\n main();\n});\nfunction readline() {\n return x[y++];\n}\n \n\n// ************************ Code Start ***************************\n \nfunction main() {\n \n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n\n\n// ************************ Code Start ***************************\n\nfunction main() {\n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nfunction print(x) {\n console.log(x);\n}\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n \n// ************************ Code Start ***************************\n \nfunction main() {\n\n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}"}, {"source_code": "'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n\n\n// ************************ Code Start ***************************\n\nfunction main() {\n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => (inputString += inputStdin));\nprocess.stdin.on(\"end\", () => {inputString = inputString.split(\"\\n\");main();});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n for (var i = 0; i < n; i++) {\n let t = parseInt(readLine());\n let k = 2;\n while (true) {\n let x = t / (Math.pow(2, k) - 1);\n // console.log('x', x);\n if (Number.isInteger(x) == true) {\n console.log(x);\n break;\n }\n k++;\n }\n }\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\nconst powers = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n\n for (let i = 0; i < 60; i++) {\n powers.push(2**i);\n }\n return;\n }\n\n let n = +d;\n let x = Math.floor(n / 3);\n let curr = 0;\n\n for (let i = 0; i < powers.length; i++) {\n curr += powers[i] * x;\n\n if (curr === n) {\n ans += `${x}\\n`;\n break;\n }\n\n if (curr > n) {\n x++;\n curr = 0;\n i = -1;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var input = parseInt(readline())\n while (input--) {\n var n = parseInt(readline())\n print(n)\n }\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nfunction print(x) { console.log(x); }\n\nlet x = \"\", y = 0;\nprocess.stdin.on(\"data\", inputStdin => x += inputStdin);\nprocess.stdin.on(\"end\", () => x = x.split(\"\\n\"), main());\nfunction readline() { return x[y++]; }\n \n\n// ************************ Code Start *************************** //\n \nfunction main() {\n\n var tc = parseInt(readline());\n for (; tc-- ;) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}"}, {"source_code": "\"use strict\";\n \nfunction print(x) {\n console.log(x);\n} \nlet x = \"\", y = 0;\nfunction readline() {\n return x[y++];\n}\n \n \n// ************************ Code Start ***************************\n \nfunction main() {\n \n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => (inputString += inputStdin));\nprocess.stdin.on(\"end\", () => inputString = inputString.split(\"\\n\"), main());\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n var tc = parseInt(readline());\n while (tc-- > 0) {\n var n = parseInt(readline());\n var m = 2;\n while (n % ((1 << m) - 1) != 0) m++;\n print(n / ((1 << m) - 1));\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n}\n"}, {"source_code": "var t = parseInt(readline());\nvar t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n else if (n % 7 == 0) print(n / 7);\n else print(1);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n else print(n);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n else print(1);\n}\n"}, {"source_code": "function main()\n{\n const testAmount = parseInt(readline());\n\n const wrapperAmounts = [];\n for (var i = 0; i < testAmount; i++) {\n wrapperAmounts.push(parseInt(readline()));\n }\n \n for (var i = 0; i < wrapperAmounts.length; i++) {\n for (var k = 2; k <= 29; k++) {\n const x = wrapperAmounts[i] / (Math.pow(2, k) - 1);\n if (x === Math.floor(x)) {\n print(x);\n break;\n }\n }\n }\n\n return 0;\n}\nmain();"}, {"source_code": "function main()\n{\n const testAmount = parseInt(readline());\n\n const wrapperAmounts = [];\n for (var i = 0; i < testAmount; i++) {\n wrapperAmounts.push(parseInt(readline()));\n }\n \n for (var i = 0; i < wrapperAmounts.length; i++) {\n for (var k = 2; k <= 29; k++) {\n const x = wrapperAmounts[i] / (Math.pow(2, k) - 1);\n if (x === Math.floor(x)) {\n print(x);\n break;\n }\n }\n }\n\n return 0;\n}\nmain();"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 1; tc <= t; tc++) {\n var n = parseInt(readline());\n if (n % 3 == 0) print(n / 3);\n else if (n % 7 == 0) print(n / 7);\n else print(1);\n}\n"}], "src_uid": "d04cbe78b836e53b51292401c8c969b2"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\nlet nl = nextLine();\n\nnl.num = function() {\n\t\treturn Number(this.next().value);\n\t};\nnl.nums = function() {\n\t\treturn this.next().value.split(/\\s/g).map(Number);\n\t};\nnl.line = function() {\n\t\treturn this.next().value;\n\t}\n\nconst sol = () => {\n\t //using nl.next().value || for(let l of nl)\n\tlet [p, n] = nl.nums();\n\tlet st = new Set();\n\tlet flag = -1;\n\tfor(let i = 0; i < n; i++){\n\t\tlet num = nl.num()%p; \n\t\tif (st.has(num)) {\n\t\t\tflag = i + 1;\n\t\t\tbreak;\n\t\t} else {\n\t\t\tst.add(num);\n\t\t}\n\t}\n\tconsole.log(flag);\n};\n\nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": ";(function () {\n\n\tvar p = readline().split(' ').map(Number);\n\tvar n = +p[1];\n\tp = +p[0];\n\n\tvar h = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tvar s = +readline();\n\n\t\tif (h[s % p]) {\n\t\t\tprint(i + 1);\n\t\t\treturn;\n\t\t}\n\n\t\th[s % p] = true;\n\t}\n\n\tprint(-1);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tp = data[0], n = data[1], h = {};\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar x = parseInt(readline()),\n\t\t\tk = x%p;\n\t\tif (h[k]) {\n\t\t\tprint(i+1);\n\t\t\treturn;\n\t\t}\n\t\th[k] = true;\n\t}\n\tprint(-1);\n}\n\nmain();\n"}, {"source_code": "var numbers = []\n\nvar firstLine = readline().split(\" \").map(Number);\nvar p = firstLine[0];\nvar n = firstLine[1];\nfor(var i = 0; i < n; i ++){\n\tnumbers.push(Number(readline()))\n}\n\nvar hashes = []\nvar done = false\n\nfor(var i = 0; i {\n if (c === 0) {\n c++;\n [p, n] = d.split(' ').map(Number);\n return;\n }\n\n if (h[+d % p]) {\n ans.push(c);\n }\n else {\n h[+d % p] = true;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (!ans.length) {\n console.log(-1);\n }\n else {\n console.log(ans[0]);\n }\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst h = {};\nconst ans = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [p, n] = d.split(' ').map(Number);\n return;\n }\n\n if (h[+d % p]) {\n ans.push(c);\n }\n else {\n h[+d % p] = true;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (!ans.length) {\n console.log(-1);\n }\n\n console.log(ans[0]);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst h = {};\nconst ans = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [p, n] = d.split(' ').map(Number);\n return;\n }\n\n if (h[+d]) {\n ans.push(c - 1);\n }\n else {\n h[+d] = true;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (!ans.length) {\n console.log(-1);\n }\n\n for (let i = 0; i < ans.length; i++) {\n console.log(ans[i]);\n }\n});\n"}, {"source_code": "var numbers = []\n\nvar firstLine = readline().split(\" \").map(Number);\nvar p = firstLine[0];\nvar n = firstLine[1];\nfor(var i = 0; i < n; i ++){\n\tnumbers.push(Number(readline()))\n}\n\nvar hashes = []\n\nfor(var i = 0; i parseInt(x));\n\nvar ok = 0;\nar.sort((a, b) => a - b);\n\nvar m = [], n = [];\n\nfor(var i=0; i n[n.length-1]) {\n n.push(ar[i]);\n } else if (m.length == 0 || ar[i] > m[m.length-1]){ \n m.push(ar[i]);\n }\n else {\n ok = 1;\n }\n}\nprint(ok ? 'NO' : \"YES\" +'\\n'+ m.length +'\\n'+ m.join(' ') \n +'\\n'+ n.length +'\\n'+ n.reverse().join(' '));\n\n\n//", "positive_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const n = parseInt(lines[0]);\n const numbers = lines[1].split(\" \").map(x => parseInt(x));\n numbers.sort((x,y) => x-y);\n const increase = [];\n const decrease = [];\n for(let i = 0; i increase[increase.length-1]) {\n increase.push(numbers[i])\n } else if (decrease.length == 0 ||numbers[i] > decrease[decrease.length-1]){ \n decrease.push(numbers[i]);\n }\n else {\n console.log('No');\n return;\n }\n }\n console.log(\"Yes\");\n console.log(increase.length);\n console.log(increase.join(' '));\n console.log(decrease.length);\n console.log(decrease.reverse().join(' '));\n}\n\nreadLines(2, doIt);"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function p(){return s[i++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function d(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n\n var t = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n\n var ok = 0;\n ar.sort((a, b) => a - b);\n \n var m = [], n = [];\n for (var i = 0; i < ar.length; i++) {\n if (n.length == 0 || ar[i] > n[n.length - 1]) {\n n.push(ar[i]);\n }\n else if (m.length == 0 || ar[i] > m[m.length - 1]) {\n m.push(ar[i]);\n }\n else ok = 1;\n }\n print(ok ? 'NO' : \"YES\" + '\\n' + m.length + '\\n' + m.join(' ') \n + '\\n' + n.length + '\\n' + n.reverse().join(' '));\n \n \n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n var t = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n\n var ok = 0;\n ar.sort((a, b) => a - b);\n \n var m = [], n = [];\n for (var i = 0; i < ar.length; i++) {\n if (n.length == 0 || ar[i] > n[n.length - 1]) {\n n.push(ar[i]);\n }\n else if (m.length == 0 || ar[i] > m[m.length - 1]) {\n m.push(ar[i]);\n }\n else ok = 1;\n }\n print(ok ? 'NO' : \"YES\" + '\\n' + m.length + '\\n' + m.join(' ') \n + '\\n' + n.length + '\\n' + n.reverse().join(' '));\n}\n"}, {"source_code": "\nvar stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { stdin += data; });\nprocess.stdin.on('end', function () { main(stdin); });\n\nvar stdin_row = 0, stdin_rows;\nfunction readLine() { if (!stdin_rows) stdin_rows = stdin.split(\"\\n\"); return stdin_rows[stdin_row++]; } // to trim ?\nfunction readLineVals() { return readLine().trim().split(/\\s+/); }\n\nconst debug = 0\nvar log = console.log;\nvar dbg = debug ? console.log : _ => {};\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n\tvar n = readLine() * 1;\n\tvar vals = readLineVals();\n\tif (n!=vals.length)\n\t\tthrow \"input parsing pb \"+n+\" \"+vals;\n\n\tvals = vals.sort((a,b)=> a-b);\n\tincr = [ vals[0] ];\n\tdecr = [];\n\n\tfor (var i =1; i b-a);\n\n\tdbg(incr)\n\tdbg(decr)\n\n\t// make sure there is no triplicate\n\tfor (var i =1; i parseInt(x))\n\nvar ok = 0\nar.sort((a, b) => a - b)\n\nvar m = [], n = [];\n\nfor(var i=0; i n[n.length-1]) {\n n.push(ar[i])\n } else if (m.length == 0 || ar[i] > m[m.length-1]){ \n m.push(ar[i]);\n }\n else {\n ok = 1;\n }\n}\nprint(ok ? 'NO' : \"YES\" +'\\n'+ m.length +'\\n'+ m.join(' ') +'\\n'+\n n.length +'\\n'+ n.reverse().join(' '));\n\n\n "}, {"source_code": "var t = parseInt(readline());\nvar ar = readline().split(' ').map(x => parseInt(x));\n \nvar ok = 0;\nar.sort((a, b) => a - b);\n \nvar m = [], n = [];\nfor(var i=0; i n[n.length-1]) {\n n.push(ar[i]);\n }\n else if (m.length == 0 || ar[i] > m[m.length - 1]) { \n m.push(ar[i]);\n }\n else ok = 1;\n}\nprint(ok ? 'NO' : \"YES\" +'\\n'+ m.length +'\\n'+ m.join(' ') \n +'\\n'+ n.length +'\\n'+ n.reverse().join(' '));"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const n = parseInt(lines[0]);\n const numbers = lines[1].split(\" \").map(x => parseInt(x));\n numbers.sort();\n const increase = [];\n const decrease = [];\n increase.push(numbers[0]);\n let inPrev = numbers[0];\n for(let i = 1; i inPrev) {\n increase.push(numbers[i])\n inPrev = numbers[i];\n } else {\n if (decrease.length == 0) \n decrease.push(numbers[i]);\n else {\n if (numbers[i] > decrease[decrease.length-1])\n decrease.push(numbers[i]);\n else {\n console.log('No');\n return;\n }\n }\n }\n }\n console.log(\"Yes\");\n console.log(increase.length);\n console.log(increase.join(' '));\n console.log(decrease.length);\n console.log(decrease.reverse().join(' '));\n}\n\nreadLines(2, doIt);"}, {"source_code": "//var input = readline()\n\nvar n = parseInt(readline())\nvar ar = readline().split(' ').map(x => parseInt(x))\n\nvar ok = 0\nvar dis = ar.sort((a, b) => b - a)\nif(dis[0] > 2 ) ok = 1\nelse ok = 0\n\nif(ok) {\n var duplicates = ar.reduce(function(x, y, z, A) {\n if (A.indexOf(y) !== z && x.indexOf(y) < 0) x.push(y); return x; \n },[]);\n\n print('YES')\n print(duplicates.length) \n print(duplicates.sort((a, b) => a - b).join(' '))\n\n var insert = [...new Set(ar)].sort((a, b) => b - a)\n print(insert.length)\n print(insert.join(' '))\n}\nelse {\n print('NO')\n}\n"}], "src_uid": "cdb19d87ad3713dac104252737153411"} {"source_code": "var input = readline().split(\" \").map(i => +i);\nvar n = input[0];\nvar m = input[1];\nvar k = input[2];\n\nvar shortestRoad = new Map();\nfor (var i = 0; i < m; ++i) {\n input = readline().split(\" \").map(i => +i);\n var u = input[0];\n var v = input[1];\n var l = input[2];\n \n if ( !shortestRoad.has(u) ) {\n shortestRoad.set(u, new Map());\n }\n \n if ( !shortestRoad.has(v) ) {\n shortestRoad.set(v, new Map());\n }\n \n if ( shortestRoad.get(u).has(v) ) {\n shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l)); \n } else {\n shortestRoad.get(u).set(v, l);\n }\n \n if ( shortestRoad.get(v).has(u) ) {\n shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));\n } else {\n shortestRoad.get(v).set(u, l);\n }\n}\n\nvar minLength;\nif (k) {\n var a = new Set(readline().split(\" \").map(i => +i));\n a.forEach(ak => {\n if ( shortestRoad.has(ak) ) {\n shortestRoad.get(ak).forEach( (length, adjCity) => {\n if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {\n minLength = length;\n }\n });\n }\n });\n}\n\nprint(minLength || \"-1\");", "positive_code": [{"source_code": "'use strict';\nconst retInt = function(x) { return parseInt(x);};\nlet e = readline();\nwhile (e !== undefined) {\n let numbers = e.split(\" \").map(retInt);\n const n = numbers[0];\n const m = numbers[1];\n const k = numbers[2];\n\n const adjList = [];\n if (n === 1 || m <= 0) {\n print(-1);\n e.readline();\n continue;\n }\n\n for (let i = 0; i < m; i++) {\n numbers = readline().split(\" \").map(retInt);\n adjList.push(numbers);\n }\n\n if (k > 0) {\n numbers = readline().split(\" \").map(retInt);\n const hm = {};\n for (const num of numbers) {\n hm[num] = true;\n }\n let max = 9999999999;\n let min = 9999999999;\n for (const edge of adjList) {\n const u = edge[0];\n const v = edge[1];\n const l = edge[2];\n if ( (hm[u] && !hm[v]) || (!hm[u] && hm[v]) ) {\n min = l < min ? l : min;\n }\n }\n if (min === max) min = -1;\n print(min);\n } else {\n print('-1');\n }\n e = readline();\n}\n"}], "negative_code": [{"source_code": "var input = readline().split(\" \").map(i => +i);\nvar n = input[0];\nvar m = input[1];\nvar k = input[2];\n\nvar shortestRoad = new Map();\nfor (var i = 0; i < m; ++i) {\n input = readline().split(\" \").map(i => +i);\n var u = input[0];\n var v = input[1];\n var l = input[2];\n if ( !shortestRoad.has(u) ) {\n shortestRoad.set(u, new Map());\n }\n if ( !shortestRoad.has(v) ) {\n shortestRoad.set(v, new Map());\n }\n if ( !shortestRoad.get(u).has(v) ) {\n shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l)); \n } else {\n shortestRoad.get(u).set(v, l);\n }\n if ( !shortestRoad.get(v).has(u) ) {\n shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));\n } else {\n shortestRoad.get(v).set(v, l);\n }\n}\n\nvar minLength;\nif (k) {\n var a = new Set(readline().split(\" \").map(i => +i));\n a.forEach(ak => {\n if ( shortestRoad.has(ak) ) {\n shortestRoad.get(ak).forEach( (length, adjCity) => {\n if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {\n minLength = length;\n }\n });\n }\n });\n}\n\nprint(minLength || \"-1\");"}], "src_uid": "b0e6a9b500b3b75219309b5e6295e105"} {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString())\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n let times = (a - b) / (c - d);\n if (times * (c - d) < a - b) {\n times += 1n;\n }\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n const a = BigInt(test[0]);\n const b = BigInt(test[1]);\n const c = BigInt(test[2]);\n const d = BigInt(test[3]);\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount = b;\n totalTime = b;\n \n if (c <= d) {\n console.log(-1);\n return;\n }\n \n const cycleSleepTime = BigInt(c - d);\n let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);\n cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;\n totalSleepAmount += cyclesCount * cycleSleepTime;\n \n console.log((cyclesCount * c + b).toString());\n });\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = BigInt(test[0]);\n const b = BigInt(test[1]);\n const c = BigInt(test[2]);\n const d = BigInt(test[3]);\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount = b;\n totalTime = b;\n \n if (c <= d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n if (!c) {\n console.log(-1);\n return;\n }\n \n const cycleSleepTime = BigInt(c - d);\n let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);\n cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;\n totalSleepAmount += cyclesCount * cycleSleepTime;\n \n console.log((cyclesCount * c + b).toString());\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c, d] = data.split(' ').map(BigInt);\n let ans = b;\n let r = a - b;\n\n if (r <= 0n) {\n console.log(ans.toString());\n return;\n }\n\n if (c <= d) {\n console.log(-1);\n return;\n }\n\n let temp = r / (c - d);\n if (temp * (c - d) < r) {\n temp += 1n;\n }\n\n ans += temp * c;\n\n console.log(ans.toString());\n count++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i BigInt(x))\n if (a <= b) {\n console.log(b.toString(10))\n } else {\n if (c <= d) {\n console.log(-1)\n } else {\n let t = a - b\n let f = c - d\n let p = (t - (t % f) ) / f\n if (t % f !== BigInt(0)) {\n p++\n }\n const add = p * c\n console.log((b + add).toString(10))\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n const a = BigInt(test[0]);\n const b = BigInt(test[1]);\n const c = BigInt(test[2]);\n const d = BigInt(test[3]);\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount = b;\n totalTime = b;\n \n if (c <= d) {\n console.log(-1);\n return;\n }\n \n // if (!c) {\n // console.log(-1);\n // return;\n // }\n \n const cycleSleepTime = BigInt(c - d);\n let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);\n cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;\n totalSleepAmount += cyclesCount * cycleSleepTime;\n \n console.log((cyclesCount * c + b).toString());\n });\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b);\n return;\n }\n \n totalSleepAmount = b;\n totalTime = b;\n \n if (c <= d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n if (!c) {\n console.log(-1);\n return;\n }\n \n const cycleSleepTime = c - d;\n const cyclesCount = Math.ceil((a - totalSleepAmount) / cycleSleepTime);\n totalSleepAmount += cyclesCount * cycleSleepTime;\n \n console.log(cyclesCount * c + b);\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount =b;\n totalTime = b;\n \n if (c < d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n let count = 0;\n let prevTotalSleepAmount = 0;\n // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {\n // prevTotalSleepAmount = totalSleepAmount;\n // totalSleepAmount = totalSleepAmount + (c - d);\n // totalTime += c;\n // count++;\n // }\n const cyclesCount = Math.trunc((a - b) / (c - d));\n totalSleepAmount += cyclesCount * (c - d);\n if (totalSleepAmount >= a) {\n console.log(cyclesCount * c + b);\n } else {\n console.log(cyclesCount * c + c + b);\n }\n //result.push(totalTime);\n //console.log(totalTime.toString());\n return;\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = BigInt(test[0]);\n const b = BigInt(test[1]);\n const c = BigInt(test[2]);\n const d = BigInt(test[3]);\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount = BigInt(b);\n totalTime = BigInt(b);\n \n if (d >= c) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n let count = 0;\n while (totalSleepAmount < a && count < 1000) {\n totalSleepAmount += c - d;\n totalTime += c;\n count++;\n }\n //result.push(totalTime);\n console.log(totalTime.toString());\n return;\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount =b;\n totalTime = b;\n \n if (c < d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n let count = 0;\n let prevTotalSleepAmount = 0;\n // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {\n // prevTotalSleepAmount = totalSleepAmount;\n // totalSleepAmount = totalSleepAmount + (c - d);\n // totalTime += c;\n // count++;\n // }\n const cyclesCount = Math.ceil((a - b) / (c - d));\n //totalSleepAmount += cyclesCount * (c - d);\n // if (totalSleepAmount >= a) {\n // console.log(cyclesCount * c + b);\n // } else {\n // console.log(cyclesCount * c + c + b);\n // }\n console.log(cyclesCount * c + b);\n //result.push(totalTime);\n //console.log(totalTime.toString());\n return;\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount = b;\n totalTime = b;\n \n if (c <= d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n if (!c) {\n console.log(-1);\n return;\n }\n \n const cycleSleepTime = c - d;\n const cyclesCount = Math.round((a - totalSleepAmount) / cycleSleepTime);\n totalSleepAmount += cyclesCount * (c - d);\n \n \n console.log(totalSleepAmount >= a ? cyclesCount * c + b : cyclesCount * c + c + b);\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount =b;\n totalTime = b;\n \n if (d >= c) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n let count = 0;\n let prevTotalSleepAmount = 0;\n // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {\n // prevTotalSleepAmount = totalSleepAmount;\n // totalSleepAmount = totalSleepAmount + (c - d);\n // totalTime += c;\n // count++;\n // }\n const cyclesCount = Math.floor((a - totalSleepAmount) / (c - d));\n totalSleepAmount += cyclesCount * (c - d);\n if (totalSleepAmount >= a) {\n console.log(cyclesCount * c + b);\n } else {\n console.log(cyclesCount * c + c + b);\n }\n //result.push(totalTime);\n //console.log(totalTime.toString());\n return;\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n let result = [];\n tests.forEach(test => {\n //const [_, __, c, d] = test;\n const a = test[0];\n const b = test[1];\n const c = test[2];\n const d = test[3];\n let totalSleepAmount;\n let totalTime;\n \n if (b >= a) {\n //result.push(b);\n console.log(b.toString());\n return;\n }\n \n totalSleepAmount =b;\n totalTime = b;\n \n if (c < d) {\n //result.push(-1);\n console.log(-1);\n return;\n }\n \n if (!c) {\n console.log(-1);\n }\n \n let count = 0;\n let prevTotalSleepAmount = 0;\n // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {\n // prevTotalSleepAmount = totalSleepAmount;\n // totalSleepAmount = totalSleepAmount + (c - d);\n // totalTime += c;\n // count++;\n // }\n const cyclesCount = Math.ceil((a - b) / (c - d));\n //totalSleepAmount += cyclesCount * (c - d);\n // if (totalSleepAmount >= a) {\n // console.log(cyclesCount * c + b);\n // } else {\n // console.log(cyclesCount * c + c + b);\n // }\n console.log(cyclesCount * c + b);\n \n //result.push(totalTime);\n //console.log(totalTime.toString());\n return;\n });\n \n //result.forEach(r => console.log(r));\n}\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a,b,c,d]) {\n if (c < d) {\n return -1\n }\n const times = Math.ceil((a - b) / (c - d));\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n console.log(input)\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a,b,c,d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString().slice(0, -1))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n let times = (a - b) / (c - d);\n if (times * c < a - b) {\n times += 1n;\n }\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString().slice(0, -1))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n let times = (a - b) / (c - d);\n if (times * (c - d) < a - b) {\n times += 1n;\n }\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a,b,c,d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n console.log(input)\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return BigInt(b + times * c);\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return String(BigInt(b) + BigInt(times * c));\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return Number(BigInt(b) + BigInt(times * c));\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i < Number(q[0]) + 1; i++) {\n console.log(solve(q[i].split(' ').map(str => Number(str))))\n }\n}\nfunction solve([a, b, c, d]) {\n if ((a > b) && (c <= d)) {\n return -1\n }\n if (a <= b) {\n return b\n }\n const times = Math.ceil((a - b) / (c - d));\n return b + times * c;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c, d] = data.split(' ').map(Number);\n let ans = b;\n let r = a - b;\n\n if (r <= 0) {\n console.log(ans);\n return;\n }\n\n if (c <= d) {\n console.log(-1);\n return;\n }\n\n ans += Math.ceil(r / (c - d)) * c;\n\n console.log(ans);\n count++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c, d] = data.split(' ').map(BigInt);\n let ans = b;\n let r = a - b;\n\n if (r <= 0n) {\n console.log(ans.toString());\n return;\n }\n\n if (c <= d) {\n console.log(-1);\n return;\n }\n\n let temp = r / (c - d);\n if (temp < r) {\n temp += 1n;\n }\n\n ans += temp * c;\n\n console.log(ans.toString());\n count++;\n});\n"}], "src_uid": "1ab174688ba76168ca047ed2b06b0670"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\ts = trim(readline()),\n\t\tribbon = new Array(n);\n\tfor (var i = 0; i < n; ++i) {\n\t\tribbon[i] = s.charCodeAt(i)-65;\n\t}\n\tvar newRibbon = new Array(n);\n\tnewRibbon[0] = s.charAt(0);\n\tif (k != 2) {\n\t\tvar cost = 0;\n\t\tfor (var i = 1; i <= n-2; ++i) {\n\t\t\tvar a = ribbon[i-1], b = ribbon[i], c = ribbon[i+1];\n\t\t\tif (b == a) {\n\t\t\t\tfor (b = 0; b < k; ++b) {\n\t\t\t\t\tif (b != a && b != c) {\n\t\t\t\t\t\tribbon[i] = b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++cost;\n\t\t\t}\n\t\t\tnewRibbon[i] = String.fromCharCode(65+ribbon[i]);\n\t\t}\n\t\tif (n != 1 && ribbon[n-1] == ribbon[n-2]) {\n\t\t\tfor (var b = 0; b < k; ++b) {\n\t\t\t\tif (b != ribbon[n-2]) {\n\t\t\t\t\tribbon[n-1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t++cost;\n\t\t}\n\t\tnewRibbon[n-1] = String.fromCharCode(65+ribbon[n-1]);\n\t\tprint(cost);\n\t\tprint(newRibbon.join('').toUpperCase());\n\t\treturn;\n\t} else {\n\t\tvar dp = new Array(n);\n\t\tdp[0] = new Array(2);\n\t\tfor (var c = 0; c < 2; ++c) {\n\t\t\tdp[0][c] = (ribbon[0] == c ? 0 : 1);\n\t\t}\n\t\tfor (var i = 1; i < n; ++i) {\n\t\t\tdp[i] = [n, n];\n\t\t\tfor (var c = 0; c < 2; ++c) {\n\t\t\t\tdp[i][c] = Math.min(dp[i][c], (ribbon[i] == c ? 0 : 1) +\n\t\t\t\t\t\tdp[i-1][c == 0 ? 1 : 0]);\n\t\t\t}\n\t\t}\n\t\tvar best = dp[n-1][0], c = 0;\n\t\tif (dp[n-1][1] < best) {\n\t\t\tbest = dp[n-1][1];\n\t\t\tc = 1;\n\t\t}\n\t\tfor (var i = n-1; i >= 0; --i) {\n\t\t\tnewRibbon[i] = String.fromCharCode(65+c);\n\t\t\tc = (c == 0 ? 1 : 0);\n\t\t}\n\t\tprint(best);\n\t\tprint(newRibbon.join(''));\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "var nk = readline().split(' ').map(Number);\nvar n = nk[0];\nvar k = nk[1];\nvar s = readline();\nif (k == 2){\n\tvar count1 = 0;\n\tvar count2 = 0;\n\tif (n%2 == 0) {\n\t\tvar s1 = 'AB'.repeat(n/2);\n\t\tvar s2 = 'BA'.repeat(n/2);\n\t} else {\n\t\tvar s1 = 'AB'.repeat(n/2) + 'A';\n\t\tvar s2 = 'BA'.repeat(n/2) + 'B';\n\t}\n\tfor (var i=0; icount1){\n\t\tprint(count1);\n\t\tprint(s1);\n\t} else {\n\t\tprint(count2);\n\t\tprint(s2);\n\t}\n} else {\n\ts = s.split('');\n\tvar count = 0;\n\tfor (var i=0; i c2)\n\t\t\treturn c2 + '\\n' + a2.join('');\n\t\treturn c1 + '\\n' + a1.join('');\n\t}\n\n\tvar ans = 0;\n\tfor (var i = 1; i < n; i++)\n\t\tif (s[i] === s[i - 1]) {\n\t\t\tans++;\n\t\t\tif (s[i - 1] === 'A' || s[i + 1] === 'A')\n\t\t\t\tif (s[i - 1] === 'B' || s[i + 1] === 'B')\n\t\t\t\t\ts[i] = 'C';\n\t\t\t\telse\n\t\t\t\t\ts[i] = 'B';\n\t\t\telse\n\t\t\t\ts[i] = 'A';\n\t\t}\n\n\treturn ans + '\\n' + s.join('')\n\n}.apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "var nk = readline().split(' ').map(Number);\nvar n = nk[0];\nvar k = nk[1];\nvar s = readline().split('');\nvar count = 0;\nfor (var i=0; i readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const s = getLine()[0]\n\n let lastZero = 0\n let lastOne = 0\n const L = []\n const R = []\n\n for (let i = 0; i < n; ++i) {\n if (s[i] === '0') {\n lastZero = lastOne + 1\n L[i] = lastZero\n } else {\n lastOne = lastZero + 1\n L[i] = lastOne\n }\n }\n\n lastZero = lastOne = 0\n for (let i = n - 1; i >= 0; --i) {\n if (s[i] === '0') {\n lastZero = lastOne + 1\n R[i] = lastZero\n } else {\n lastOne = lastZero + 1\n R[i] = lastOne\n }\n }\n\n let ans = 0\n let i = 0\n while (i < n) {\n let j = i + 1\n const a = i\n while (j < n && s[j - 1] !== s[j]) {\n j ++\n }\n\n const b = j - 1\n const cur = b - a + 1\n \n const best = calc(a, b, s, L, R)\n ans = Math.max(ans, cur + best)\n i = j\n }\n print(ans)\n}\n\nfunction calc(a, b, s, L, R) {\n const n = s.length\n let one = (a - 1 >= 0 ? L[a - 1] - (s[a] === s[a - 1] ? 1 : 0): 0)\n one += (b + 1 < n ? R[b + 1] - (s[b] === s[b + 1] ? 1 : 0): 0)\n\n const left = (s[a] === '0' ? '1' : '0')\n const right = (s[b] === '0' ? '1' : '0')\n\n let two = (a - 1 >= 0 ? L[a - 1] - (left === s[a - 1] ? 1 : 0): 0)\n two += (b + 1 < n ? R[b + 1] - (right === s[b + 1] ? 1 : 0): 0)\n\n return Math.max(one, two)\n}"}, {"source_code": "var x = readline();\nvar n = readline();\nvar ans = 1;\nfor(var i=1; i readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const s = getLine()[0]\n\n let lastZero = 0\n let lastOne = 0\n const L = [[0,0]]\n const R = []\n R[n] = [0, 0]\n\n for (let i = 0; i < n; ++i) {\n let best = 0\n L[i + 1] = []\n if (s[i] === '0') {\n best = lastOne + 1\n L[i + 1][0] = best\n L[i + 1][1] = lastZero + 1\n lastZero = best\n } else {\n best = lastZero + 1\n L[i + 1][0] = lastOne + 1\n L[i + 1][1] = best\n lastOne = best\n }\n }\n\n lastZero = lastOne = 0\n for (let i = n - 1; i >= 0; --i) {\n let best = 0\n R[i] = []\n if (s[i] === '0') {\n best = lastOne + 1\n R[i][0] = best\n R[i][1] = lastZero + 1\n lastZero = best\n } else {\n best = lastZero + 1\n R[i][0] = lastOne + 1\n R[i][1] = best\n lastOne = best\n }\n }\n\n let ans = 0\n let i = 0\n while (i < n) {\n let j = i + 1\n const a = i\n while (j < n && s[j - 1] !== s[j]) {\n j ++\n }\n const b = j - 1\n const cur = Math.max(b - a - 2, 0)\n const best = calc(b, a, s, L, R)\n ans = Math.max(ans, cur + best)\n i ++\n }\n print(ans)\n}\n\nfunction calc(a, b, s, L, R) {\n const left = (s[a] != '0' ? 0 : 1)\n const right = (s[b] != '0' ? 1: 0)\n\n return Math.max(R[a][left] + L[b][right], R[a][!left ? 1 : 0] + L[b][!right ? 1 : 0])\n}"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar str = readline();\nvar arr = str.split('');\n\nif (str.indexOf('000') >= 0) {\n var k = str.indexOf('000');\n arr[k+1] = '1';\n} else if (str.indexOf('111') >= 0) {\n k = str.indexOf('111');\n arr[k+1] = '0';\n} else if (str.substr(0,2) == '00') {\n arr[0] = '1';\n} else if (str.substr(0,2) == '11') {\n arr[1] = '0';\n} else if (str.substr(-2,2) == '00') {\n arr[arr.length - 1] = '1';\n} else if (str.substr(-2,2) == '11') {\n arr[arr.length - 1] = '0';\n} \nvar counter = 0;\nfor (var i = 1; i < str.length; i++) {\n if (arr[i] != arr[i-1]) counter++;\n}\nwrite(counter+1);\n"}], "src_uid": "7b56edf7cc71a1b3e39b3057a4387cad"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let spell = iInpArr();\r\n let sum = arr.reduce((acc, cur) => acc + cur, 0);\r\n spell.sort((a, b) => b - a);\r\n let ans = 0;\r\n for (let i = 1; i < n; i++) ans += spell[i];\r\n console.log(sum + ans);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(),\r\n b = rns();\r\n let res = 0;\r\n for (let l = 0, r = n - 1; l <= r;) {\r\n if (b[l] < b[r]) {\r\n res += a[l];\r\n a[l + 1] += b[l];\r\n l++;\r\n } else {\r\n res += a[r];\r\n a[r - 1] += b[r];\r\n r--;\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction sum(arr) {\r\n var total = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n total += arr[i];\r\n }\r\n return total;\r\n}\r\n\r\nfunction solve(a, b) {\r\n var sumHealths = sum(a);\r\n var sumDebuffs = sum(b);\r\n var maxDebuff = Math.max.apply(null, b);\r\n \r\n cl(sumHealths + sumDebuffs - maxDebuff);\r\n}\r\n\r\nfunction main() {\r\n const numOfCases = rlsn();\r\n \r\n for (let testCase = 0; testCase < numOfCases; testCase++) {\r\n const num = rlsn();\r\n const l1 = rlarrn();\r\n const l2 = rlarrn();\r\n \r\n solve(l1, l2);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inStr = '';\r\nlet curLine = 0;\r\nconst cl = console.log;\r\n\r\nprocess.stdin.on('data', function(inStdin) {inStr += inStdin;});\r\nprocess.stdin.on('end', function() {inStr = inStr.split('\\n');main();});\r\n\r\nfunction readline() {return inStr[curLine++].replace(/\\s+$/g, '');}\r\nfunction rlsn() {return Number(readline());}\r\nfunction rlarrstr() {return readline().split(' ');}\r\nfunction rlarrn() {return rlarrstr().map(Number);}\r\nfunction makeFreqMap(str) {const m={};for (let char of str) m[char]=m[char]+1||1;return m;}\r\n\r\n\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const b = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n b,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a, b } = testCase;\n\n let result = 0;\n let maxi = 0;\n for (let i = 0; i < n; i++) {\n result += a[i] + b[i];\n if (b[i] > maxi) maxi = b[i];\n }\n result -= maxi;\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start(); \r\n});\r\n\r\nfunction start(){\r\n\tconst T = parseInt(lines[0])\r\n\tlet line = 1\r\n\tfor(let t = 1; t <= T; t++) {\r\n\t const n = parseInt(lines[line++].trim().split(' ')[0], 10)\r\n\t let result = 0;\r\n\t let max = 0;\r\n\t lines[line++].trim().split(' ').map(x => {\r\n\t const a = parseInt(x, 10)\r\n\t result += a;\r\n\t })\r\n\t lines[line++].trim().split(' ').map(x => {\r\n\t const b = parseInt(x, 10)\r\n\t result += b;\r\n\t if (max < b)\r\n\t max = b\r\n\t })\r\n\t console.log(result - max)\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline()) \r\n while (t--) {\r\n let n = parseInt(readline())\r\n let monsters = readline().split(' ').map( Number )\r\n let spells = readline().split(' ').map( Number )\r\n \r\n // let res = parseInt(readline())\r\n // console.log(res , solve(n, monsters, spells))\r\n console.log(solve(n, monsters, spells))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, monsters, spells) => {\r\n if ( n === 1 ) return monsters[0]\r\n \r\n let i = -1, totalTime = 0, maxSpell = Number.MIN_SAFE_INTEGER\r\n while( ++i < n ){\r\n totalTime += monsters[i] + spells[i] \r\n maxSpell = Math.max( maxSpell, spells[i] ) \r\n }\r\n\r\n return totalTime - maxSpell\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const a = readLine().split(' ').map(p => +p);\r\n const b = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n, a, b);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, a, b){\r\n\r\n let sumA = 0;\r\n let sumB = 0;\r\n let maxB = 0;\r\n\r\n for(let i = 0; i < n; i++){\r\n sumA += a[i];\r\n sumB += b[i];\r\n if(b[i] > maxB) maxB = b[i];\r\n }\r\n\r\n return sumA + sumB - maxB;\r\n\r\n}"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var n = Number(readline()); // num of monsters\r\n var a = readline().split(' ').map(Number); // array of healthpools\r\n var b = readline().split(' ').map(Number); // array of debuffs\r\n \r\n var seconds = process(a, b);\r\n print(seconds);\r\n}\r\n\r\nfunction sum(arr) {\r\n var total = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n total += arr[i];\r\n }\r\n return total;\r\n}\r\n\r\nfunction process(a, b) {\r\n var sumHealths = sum(a);\r\n var sumDebuffs = sum(b);\r\n var maxDebuff = Math.max.apply(null, b);\r\n \r\n return sumHealths + sumDebuffs - maxDebuff;\r\n}"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var n = Number(readline()); // num of monsters\r\n var a = readline().split(' ').map(Number); // array of healthpools\r\n var b = readline().split(' ').map(Number); // array of debuffs\r\n \r\n var seconds = process(a, b);\r\n print(seconds);\r\n}\r\n\r\nfunction process(a, b) {\r\n var result = a.reduce((acc, h) => acc + h, 0);\r\n var resultB = b.reduce((acc, h) => acc + h, 0);\r\n var maxB = Math.max(...b);\r\n \r\n return result + resultB - maxB;\r\n}"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, h, b) {\r\n let sum = 0; \r\n let max = Number.MIN_SAFE_INTEGER;\r\n for(let i = 0; i < n; i++) {\r\n sum += h[i] + b[i];\r\n max = Math.max(max, b[i]);\r\n }\r\n sum -= max;\r\n print(sum);\r\n\r\n}\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var h = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n var b = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, h, b);\r\n }\r\n}"}], "negative_code": [{"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin2(n, h, b) {\r\n let blist = b.map((value, index) => [value, index]);\r\n blist.sort((a,b) => { return a[0] - b[0]});\r\n //print(blist.join(' '));\r\n let used = new Array(n).fill(false);\r\n let sum = 0;\r\n for(let i = 0; i < n; i++) {\r\n used[blist[i][1]] = true;\r\n sum += h[blist[i][1]];\r\n let next = blist[i][1] + 1;\r\n while(next < n) {\r\n if(used[next] == false) {\r\n h[next] += blist[i][0];\r\n break;\r\n }\r\n next++;\r\n }\r\n let pre = blist[i][1] - 1;\r\n while(pre >= 0) {\r\n if(used[pre] == false) {\r\n h[pre] += blist[i][0];\r\n break;\r\n }\r\n pre--;\r\n }\r\n }\r\n print(sum);\r\n}\r\n\r\nfunction begin(n, h, b) {\r\n let sum = 0;\r\n let used = new Array(n).fill(false);\r\n let index = 0;\r\n while(index < n) {\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let minPos = -1;\r\n let first = -1, last = n - 1;\r\n for(let i = 0; i < n; i++) {\r\n if(used[i] == false) {\r\n if(first == -1) {\r\n first = i;\r\n }\r\n if(b[i] < min) {\r\n min = b[i];\r\n minPos = i;\r\n }\r\n last = i;\r\n }\r\n }\r\n //\r\n let choose = -1;\r\n if( 2 * min < b[first] && 2 * min < b[last]) {\r\n //choose min\r\n choose = minPos;\r\n } else if(b[first] < b[last]) {\r\n //choose first\r\n choose = first;\r\n } else {\r\n //choose last\r\n choose = last;\r\n }\r\n used[choose] = true;\r\n sum += h[choose];\r\n let next = choose + 1;\r\n while(next < n) {\r\n if(used[next] == false) {\r\n h[next] += b[choose];\r\n break;\r\n }\r\n next++;\r\n }\r\n let pre = choose - 1;\r\n while(pre >= 0) {\r\n if(used[pre] == false) {\r\n h[pre] += b[choose];\r\n break;\r\n }\r\n pre--;\r\n }\r\n index++;\r\n }\r\n print(sum);\r\n\r\n}\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var h = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n var b = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, h, b);\r\n }\r\n}"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin2(n, h, b) {\r\n let blist = b.map((value, index) => [value, index]);\r\n blist.sort((a,b) => { return a[0] - b[0]});\r\n //print(blist.join(' '));\r\n let used = new Array(n).fill(false);\r\n let sum = 0;\r\n for(let i = 0; i < n; i++) {\r\n used[blist[i][1]] = true;\r\n sum += h[blist[i][1]];\r\n let next = blist[i][1] + 1;\r\n while(next < n) {\r\n if(used[next] == false) {\r\n h[next] += blist[i][0];\r\n break;\r\n }\r\n next++;\r\n }\r\n let pre = blist[i][1] - 1;\r\n while(pre >= 0) {\r\n if(used[pre] == false) {\r\n h[pre] += blist[i][0];\r\n break;\r\n }\r\n pre--;\r\n }\r\n }\r\n print(sum);\r\n}\r\n\r\nfunction begin(n, h, b) {\r\n let sum = 0;\r\n let used = new Array(n).fill(false);\r\n let index = 0;\r\n while(index < n) {\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let minPos = -1;\r\n let first = -1, last = n - 1;\r\n for(let i = 0; i < n; i++) {\r\n if(used[i] == false) {\r\n if(first == -1) {\r\n first = i;\r\n }\r\n if(b[i] < min) {\r\n min = b[i];\r\n minPos = i;\r\n }\r\n last = i;\r\n }\r\n }\r\n //\r\n let choose = -1;\r\n if( 2 * min < b[first] && 2 * min < b[last]) {\r\n //choose min\r\n choose = minPos;\r\n } else if(b[first] < b[last]) {\r\n //choose first\r\n choose = first;\r\n } else {\r\n //choose last\r\n choose = last;\r\n }\r\n //left 2 select min h\r\n if(first + 1 == last) {\r\n if(h[first] < h[last]) {\r\n choose = first;\r\n } else {\r\n choose = last;\r\n }\r\n }\r\n\r\n used[choose] = true;\r\n sum += h[choose];\r\n let next = choose + 1;\r\n while(next < n) {\r\n if(used[next] == false) {\r\n h[next] += b[choose];\r\n break;\r\n }\r\n next++;\r\n }\r\n let pre = choose - 1;\r\n while(pre >= 0) {\r\n if(used[pre] == false) {\r\n h[pre] += b[choose];\r\n break;\r\n }\r\n pre--;\r\n }\r\n index++;\r\n }\r\n print(sum);\r\n\r\n}\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var h = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n var b = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, h, b);\r\n }\r\n}"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, h, b) {\r\n let blist = b.map((value, index) => [value, index]);\r\n blist.sort((a,b) => { return a[0] - b[0]});\r\n //print(blist.join(' '));\r\n let used = new Array(n).fill(false);\r\n let sum = 0;\r\n for(let i = 0; i < n; i++) {\r\n used[blist[i][1]] = true;\r\n sum += h[blist[i][1]];\r\n let next = blist[i][1] + 1;\r\n while(next < n) {\r\n if(used[next] == false) {\r\n h[next] += blist[i][0];\r\n break;\r\n }\r\n next++;\r\n }\r\n let pre = blist[i][1] - 1;\r\n while(pre >= 0) {\r\n if(used[pre] == false) {\r\n h[pre] += blist[i][0];\r\n break;\r\n }\r\n pre--;\r\n }\r\n }\r\n print(sum);\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var h = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n var b = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, h, b);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n while (l <= r && a[l] > k) l++;\r\n if (l <= r && a[l] <= k) ans++;\r\n }\r\n return ans >= k;\r\n };\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var n = Number(readline()); // num of monsters\r\n var a = readline().split(' ').map(Number); // array of healthpools\r\n var b = readline().split(' ').map(Number); // array of debuffs\r\n \r\n var seconds = process(a, b);\r\n print(seconds);\r\n}\r\n\r\nfunction processCopy(item, i) {\r\n return i === 0 || i === b.length - 1 ? item : item * 2;\r\n}\r\n\r\nfunction process(a, b) {\r\n var result = a.reduce((acc, h) => acc + h, 0);\r\n \r\n while (b.length) {\r\n var copy = Object.assign([], b);\r\n copy = copy.map(processCopy);\r\n \r\n var indexOfLeast = copy.indexOf(Math.min(...copy));\r\n \r\n if (b.length > 1) {\r\n result += copy[indexOfLeast];\r\n }\r\n b.splice(indexOfLeast, 1);\r\n }\r\n \r\n return result;\r\n}"}], "src_uid": "5c75658faf6dda4d7e21e1dcf39b350a"} {"source_code": "readline();\nvar nums = readNums();\nvar res = [];\n\nfor (var i = 0; i < nums.length; i++) {\n res[nums[i] - 1] = i + 1;\n}\nprint(res.join(' '));\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}", "positive_code": [{"source_code": "\nvar n=+readline();\nvar p=readline().split(' ').map(function(v){return+v;});\nvar ans=[];\np.forEach(function(v,i){\n\tans[v]=i+1;\n});\nans.shift();\nprint(ans.join(' '));"}, {"source_code": "var n = +readline(), input = readline().split(\" \"), p = [];\nfor(i = 1; i <= n; i++){\n\tp.push([i,input[i-1],input.indexOf(i.toString(10))+1]);\n}\n\nfor(i = 0; i < n; i++){\n\twrite( (i == n-1) ? (p[i][2]) : (p[i][2] + \" \"));\n}"}, {"source_code": "var n=readline();\nvar str = readline().split(\" \");\nvar m =[];\n\tfor (var i=0; iparseInt(x));\nfor(var i=1 ; i<=n ; i++){\n write((input.indexOf(i)+1) + ' ')\n}\nprint();"}, {"source_code": "step = readline();\nvar x = readline().split(\" \");\nvar str = \"\";\nfor (i=1;i<=step;i++){\n str += (x.indexOf(i.toString())+1)+\" \";\n}\nprint(str);\n"}, {"source_code": "\n var n = parseInt(readline()),\n friends = readline().split(' '),\n arr = []\n friends.forEach(function(v, i) {\n friends[i] = parseInt(v);\n })\n\n for(var i = 1; i <= n; i++){\n\n arr.push(friends.indexOf(i) + 1);\n \n }\n\n arr = arr.join(' ');\n \n \n print(arr);"}, {"source_code": "var n=+readline();\nvar p=readline().split(\" \").map(function(x){return +x});\nans=[];\nfor(var i = 0; i c*1),\n\ttakeObj = {},\n\toutput = [];\n\ngiveGifts.forEach(function(current,index){\n\ttakeObj[current] = index+1;\n});\n\nfor(var i = 1; i <= num; i++){\n\toutput.push(takeObj[i]);\n}\n\nprint(output.join(' '));\n\n"}, {"source_code": "var n = parseInt( readline() );\nvar inputNumbers = readline().split(' ');\nvar perm =[];\nfor(var k=1; k<=n; k++){\n var number = parseInt(inputNumbers[k-1]);\n perm[number] = k;\n}\nvar result = \"\";\nfor(var j=1;j<=n;j++){\n result = result + perm[j]+\" \";\n}\nprint(result);"}, {"source_code": "var number = Number(readline())\n var numbers = readline().split(' ').map(Number)\n\n var arr = new Array(number).fill(0)\n for(var i = 0; i < number; i++) {\n arr[numbers[i] - 1] = i + 1\n }\n\n print(arr.join(' '))"}, {"source_code": "var firstLine = readline().toLowerCase();\nvar secondLine = readline().toLowerCase();\n\nvar obj = secondLine.split(' ').reduce((a, b, index) => (a[index + 1] = b, a), {});\nvar result = Object.keys(obj).sort(function(a, b){ return obj[a] - obj[b] }).join(' ');\n\nprint(result);"}, {"source_code": "var n = readline().split(\" \").map(function (x) { return parseInt(x); });\n var tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n \n var res = []\n\n for (var i = 1; i <= n; i++) {\n res[tmp[i - 1]] = i;\n }\n\n res = res.slice(1).toString();\n // console.log(tmp[3], typeof tmp);\n res = res.replace()\n print(res.split(',').join(' '));"}, {"source_code": "var input = parseInt(readline());\nvar gifts = readline().split(\" \").map(x=>parseInt(x));\nvar output = [];\nfor(var i=1; i<=input; i++){\n output.push(gifts.indexOf(i)+1);\n}\nprint(output.join(\" \"))"}, {"source_code": ";(function () {\n\n\treadline();\n\tvar p = readline().split(' ').map(function (x) { return +x; });\n\tvar t = new Array(p.length);\n\n\tfor (var i = 0; i < p.length; i++) t[p[i]] = 1 + i;\n\n\tprint(t.join(' '));\n\n}).call(this);"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(' ');\nvar s=new Array(n);\n\nfor(var i=0;i {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\tconst n = inputs[0].split(' ').map(function (a) { return parseInt(a); });\n const k = inputs[1].split(' ').map(function (a) { return parseInt(a); });\n console.log(solution(n, k));\n\n})\n\n// End of interface\n\nconst solution = (n, presentsArray) => {\n\tlet resArray = [];\n\tfor (let j = 1; j<=n; j++){\n\t\tresArray.push(presentsArray.indexOf(j) + 1);\n\t};\n\treturn resArray.join(' ');\n};\n"}, {"source_code": "let stdin = process.stdin;\nstdin.setEncoding('utf8');\nstdin.on('data', function (data) {\n let input = data.split('\\n');\n let n = input[0].split(' ').map(function (a) { return parseInt(a); });\n let k = input[1].split(' ').map(function (a) { return parseInt(a); });\n let result = solution(n, k);\n console.log(result);\n});\n\n// End of interface\n\n\nconst solution = (n, presentsArray) => {\n\tlet res = '';\n\tlet presentsArrayOfObjects = [];\n\tfor (let j = 0; j {\n if (!friendCount) { friendCount = n } else {\n n = n.split(' ').map(Number);\n let min = Math.min(...n);\n let max = Math.max(...n);\n for (min; min <= max; min++) {\n friendNums.push(n.indexOf(min) + 1);\n }\n console.log(...friendNums);\n rl.close();\n }\n});"}, {"source_code": "function main() {\n // write code here:\n var n = Number(stdin[0]);\n var arr=stdin[1].split(' ').map(Number);\n var obj={};\n var newArr=[];\n for(let i=0;i {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let n = Number(readLine());\n const a = readLine().split(' ').map(_a => Number(_a));\n const b = [];\n a.forEach((_a, i) => b[_a - 1] = i + 1);\n console.log(b.join(' '));\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n const friends = inputs[1].split(' ');\n let result = [];\n\n for (let i = 0; i < friends.length; i++) {\n const position = friends.indexOf((i + 1).toString());\n result[i] = position + 1;\n }\n\n console.log(result.join(' '))\n\n})"}, {"source_code": "var n = readline();\nvar a = [];\nvar output=[];\nvar x;\na = readline()\n.split(\" \")\n.map((a) => parseInt(a));\nfor(var i=1;i<=n;i++){\n x= a.indexOf(i)\n output.push(x+1)\n}\nprint(output.join(\" \"))"}, {"source_code": "readline();\nvar data = readline().split(' ').map(Number);\nvar result = [];\n\nfor(var i = 0; i < data.length; i++)\n{\n\tresult[data[i]] = i + 1; // +1 because the index of problem started from 1 instead of 0\n}\n\nresult.splice(0, 1); // must be spliced since result started from index 1 instead of 0\nprint(result.join(' '));"}, {"source_code": "'use strict';\n\n(function() {\n let n = parseInt(readline());\n let a = readline().split(' ').map(value => parseInt(value));\n let b = new Array(n);\n\n a.map((value, index) => {\n b[value - 1] = index + 1;\n });\n\n write(b.join(' '));\n\n})();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const p = readline().split(' ').map(x => parseInt(x));\n const m = new Map();\n for (let i = 0; i < n; i++) {\n m.set(p[i], i + 1);\n }\n const a = [];\n for (let i = 0; i < n; i++) {\n a.push(m.get(i + 1));\n }\n print(a.join(' '));\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet counter = 0;\n\nrl.on('line', (d) => {\n if (counter === 0) {\n counter++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const arr2 = [];\n\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (arr[j] == i + 1) {\n arr2.push(j + 1);\n }\n }\n }\n\n console.log(arr2.join(' '));\n\n counter++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let n = parseInt(readline());\n let p = readint();\n let mynew = [];\n p.forEach((v, k) => {\n mynew[v - 1] = k + 1;\n });\n mynew.forEach((v) => {\n write(v + \" \");\n });\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const friends = input[1].split(' ').map(x => parseInt(x));\n const answer = [];\n\n friends.forEach((x, i) => {\n answer[x-1] = i+1;\n });\n\n console.log(answer.join(' '));\n});"}, {"source_code": "const readline = require('readline');\nlet inputs = [];\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\nrl.on('close', () => {\n\t\tconst n = inputs[0].split(' ').map(function (a) { return parseInt(a); });\n const k = inputs[1].split(' ').map(function (a) { return parseInt(a); });\n console.log(solution(n, k));\n})\n\n\nconst solution = (n, presentsArray) => {\n\tlet resArray = [];\n\tfor (let j = 1; j<=n; j++){\n\t\tresArray.push(presentsArray.indexOf(j) + 1);\n\t};\n\treturn resArray.join(' ');\n};"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(' ');\nvar friends = [];\n\nfor (var i = 0; i < s.length; i++) {\n friends[s[i]-1] = i+1;\n}\nprint(friends.join(' '));"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const ints = Array.from(input[1].split(' '), x => parseInt(x));\n const outs = [...ints];\n ints.forEach((v, i) => {\n outs[v - 1] = ints.indexOf(v) + 1;\n })\n\n console.log(outs.join(' '));\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n // if(Array.isArray(inputString)) inputString = inputString.join('\\n');\n inputString += inputStdin;\n // inputString = inputString.trim().split('\\n').map(string => {\n // return string.trim();\n // });\n \n // main(); \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let l = readAsInt();\n let list = readAsIntList();\n let result = [];\n for(let i = 1; i <= list.length; i++){\n result[list[i-1]-1] = i;\n }\n console.log(result.join(' '));\n}\n \n\n\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\nfor (let i = 1; i < txt.length; i += 2) {\n doit(txt[i].split(\" \").filter(data => {\n return data.length > 0;\n }).map(data => {\n return data * 1;\n }));\n\n}\n\nfunction doit(arr) {\n let tab = [];\n arr.forEach((data, index) => {\n tab[data - 1] = index + 1;\n });\n console.log(tab.join(\" \"));\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().split('\\n');\n let frns = inputs[1].trim().split(' ');\n let auxArray = [];\n for (let i = 0; i < frns.length; i++) {\n auxArray[frns[i]] = i + 1;\n }\n\n return auxArray.join(' ').trim().toString();\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet secondLine = input[1].split(' ');\nconst n = parseInt(input[0], 10);\nsecondLine = secondLine.map((el) => parseInt(el, 10));\nlet text = '';\nfor (let i = 1; i< n + 1; i++) {\n text += `${secondLine.indexOf(i) + 1} `\n}\ntext = text.slice(0, text.length-1)\nconsole.log(text);\n});"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst gifts = () => {\n const a = input[1].split(' ').map(x => +x);\n const b = Array(a.length);\n let n = 1;\n for (const x of a) {\n b[x - 1] = n;\n n++;\n }\n console.log(b.join(' '));\n};\nreadLine.on('close', gifts);\n"}, {"source_code": "n = readline().split(' ').map(Number);\ndata = readline().split(' ').map(Number);\nresult = []\nfor (i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine()\n .split(' ')\n .map(value => parseInt(value));\n\n let ans = [];\n for (var i = 1; i <= n; i++) {\n ans.push(arr.indexOf(i) + 1);\n }\n console.log(ans.join(' '));\n}"}, {"source_code": "var line1 = readline();\nvar n = parseInt(line1);\n\nvar line2 = readline().split(' ').map(Number);\n\nvar str = '';\n\nfor(i=1;i {\n if(gift == i){\n result.push(index);\n }\n });\n}\nresult.forEach((gift) => print(gift+1));"}, {"source_code": "/*x=readline();\nvar a = [];\na.push(readline());\n a.push(readline());\n a.push(readline());\n/*a = a.sort(function(a,b){\n return a-b;\n});*/\n/*\nvar max_stack = [];\n//(a+b)*c\nmax_stack.push(parseInt((parseInt(a[0])+parseInt(a[1]))*parseInt(a[2])));\n//a*(b+c)\nmax_stack.push(parseInt(parseInt(a[0])*((parseInt(a[1])+parseInt(a[2])))));\n//a*b*c\nmax_stack.push(parseInt(parseInt(a[0])*parseInt(a[1])*parseInt(a[2])));\n\n//a*b+c\n\nmax_stack.push(parseInt(parseInt(a[0])*parseInt(a[1])+parseInt(a[2])));\n//a+b*c\nmax_stack.push(parseInt(parseInt(a[0])+parseInt(a[1])*parseInt(a[2])));\n//a+b+c\nmax_stack.push(parseInt(parseInt(a[0])+parseInt(a[1])+parseInt(a[2])));\n\n \nvar maximus=-999;\nfor(i=0;i=0,j=0) {\n len++;\n max=Math.max(max,len);\n }\n else\n {\n len=1;\n }\n}\n\nprint(max)\n */\n \n \n var n = readline();\n var d = readline().split(' ').map(Number);\n var c = [];\n for(i=0;i parseInt(el, 10)),\n result = [],\n p_i = 0;\n\nfor(var i=0; i {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\tconst n = inputs[0].split(' ').map(function (a) { return parseInt(a); });\n const k = inputs[1].split(' ');\n console.log(solution(n, k));\n\n})\n\n// End of interface\n\n\nconst solution = (n, presentsArray) => {\n\tlet resArray = [];\n\tfor (let j = 1; j<=n; j++){\n\t\tresArray.push(presentsArray.indexOf(j) + 1);\n\t};\n\treturn resArray.join(' ');\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet friendCount, friendNums = [];\n\nrl.on('line', n => {\n if (!friendCount) { friendCount = n } else {\n n = n.split(' ').map(Number);\n let min = Math.min(...n);\n let max = Math.max(...n);\n for (min; min <= max; min++) {\n friendNums.push(n.indexOf(min) + 1);\n }\n console.log(friendNums);\n rl.close();\n }\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n const friends = inputs[1].split(' ');\n const nOfFriends = friends.length;\n let result = [];\n \n for (let i = 0; i < nOfFriends; i++) {\n const Pi = Math.floor(Math.random() * friends.length);\n const pickedOne = friends.splice(Pi, 1)[0];\n result.push(pickedOne);\n }\n\n console.log(...result);\n \n})"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n const friends = inputs[0].split(' ');\n let result = [];\n\n for (let i = 0; i < friends.length; i++) {\n const position = friends.indexOf((i + 1).toString());\n result[i] = position + 1;\n }\n\n console.log(result.join(' '))\n\n})"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n const friends = inputs[0].split(' ');\n const nOfFriends = friends.length;\n let result = [];\n \n for (let i = 0; i < nOfFriends; i++) {\n const Pi = Math.floor(Math.random() * friends.length);\n const pickedOne = friends.splice(Pi, 1)[0];\n result.push(pickedOne);\n }\n\n console.log(...result);\n \n})"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const ints = Array.from(input[1].split(' '), x => parseInt(x));\n const outs = [...ints];\n ints.forEach((v, i) => {\n console.log(v);\n outs[v - 1] = ints.indexOf(v) + 1;\n })\n\n console.log(outs);\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine()\n .split(' ')\n .map(value => parseInt(value));\n\n let ans = [];\n for (var i = 1; i <= n; i++) {\n ans.push(arr.indexOf(i) + 1);\n }\n console.log(ans);\n}"}, {"source_code": "\nvar n=+readline();\nvar p=readline().split(' ').map(function(v){return+v;});\nvar ans=[];\np.forEach(function(i,v){\n\tans[v]=i+1;\n});\nans.shift();\nprint(ans.join(' '));"}, {"source_code": "step = readline();\nvar x = readline().replace(/ /g,\"\");\nvar str = \"\";\nfor (i=1;i<=step;i++){\n str += (x.indexOf(i)+1)+\" \"\n}\nprint(str)"}, {"source_code": "step = readline();\nvar x = readline().replace(/ /g,\"\");\nvar str = \"\";\nfor (i=1;i<=step;i++){\n str += ((x.indexOf(i))+1)+\" \"\n}\nprint(str)"}, {"source_code": "var n=+readline();\nvar p=readline().split(\" \").map(function(x){return +x});\nans = [];\nfor(var i = 0; i c) {\n print(a * (b + c));\n } else {\n print((a + b) * c);\n }\n }"}, {"source_code": "var n = +readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n gifts.push(+readline());\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n print(gift);\n if(gift === i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = readline().split(\" \");\nvar result = [];\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift == i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n var a = readline();\n gifts.push(a);\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n print(gift)\n if(gift === i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = readline().split(\" \");\nvar result = [];\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift,index) => {\n if(gift == i){\n result.push(index);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n gifts.push(+readline());\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift === i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n gifts.push(+readline());\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift == i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n gifts.push(+readline());\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift === i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = [];\nvar result = [];\nfor(var i = 0; i < n; ++i){\n gifts.push(+readline());\n}\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift === i){\n result.push(gift);\n }\n });\n}\nprint(result)\nresult.forEach((gift) => print(gift));"}, {"source_code": "var n = +readline();\nvar gifts = readline().split(\" \");\nvar result = [];\nfor(var i = 1; i <= n; ++i){\n gifts.forEach((gift) => {\n if(gift === i){\n result.push(gift);\n }\n });\n}\nresult.forEach((gift) => print(gift));"}, {"source_code": "(function() {\n 'use strict';\n let n = readline();\n let x = readline().split(' ').map(Number);\n let i = 0;\n let y = Array;\n for (i; i < n; i++) {\n y[x[i]] = i + 1;\n }\n print(y);\n\n}());"}], "src_uid": "48bb148e2c4d003cad9d57e7b1ab78fb"} {"source_code": "\t// this code is writen by ashraf\n\tvar r = readline();\n\n\tfor(var p=0;p{return parseInt(v);});\n \n\n \n var l1 = ar[0], r1 = ar[1], l2 = ar[2], r2 = ar[3];\n\n var a = ar.filter(x=>(l1<= x && x<=r1)).sort((z,h)=>(h-z))\n var b = ar.filter(x=>(l2<= x && x<=r2)).sort()\n var pass = true\n for (var i=0;i {\n const tokens = line.split(' ').map((num) => parseInt(num));\n \n return {\n l1: tokens[0],\n r1: tokens[1],\n l2: tokens[2],\n r2: tokens[3],\n }\n });\n \n return queries.map((q) => query(q.l1, q.r1, q.l2, q.r2));\n}\n\nconst ans = getAnswer();\n\nconsole.log(ans.map((x) => x.a + ' ' + x.b).join('\\n'));\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var L1 = tmp[0];\n var R1 = tmp[1];\n var L2 = tmp[2];\n var R2 = tmp[3];\n var a = L1;\n var b = L2;\n if(a == b){\n b++;\n }\n output[i] = a + \" \" + b;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [l1, r1, l2, r2] = d.split(' ').map(Number);\n\n if (l1 === r2) {\n console.log(l1, l2);\n }\n else {\n console.log(l1, r2);\n }\n c++;\n});\n"}, {"source_code": "var q=parseInt(readline());\nfor(var i=0;i 1) ms.push(cmd);\n }).on('close', main);\n\nfunction main() {\n\tfor (var i=0; i {\n const tokens = line.split(' ').map((num) => parseInt(num));\n \n return {\n l1: tokens[0],\n r1: tokens[1],\n l2: tokens[2],\n r2: tokens[3],\n }\n });\n \n return queries.map((q) => query(q.l1, q.r1, q.l2, q.r2));\n}\n\nconst ans = getAnswer();\n\nconsole.log(ans.map((x) => x.a + ' ' + x.b).join('\\n'));\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var L1 = tmp[0];\n var R1 = tmp[1];\n var L2 = tmp[2];\n var R2 = tmp[3];\n var a = Math.max(L1, L2);\n var b = Math.min(R1, R2);\n output[i] = a + \" \" + b;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var L1 = tmp[0];\n var R1 = tmp[1];\n var L2 = tmp[2];\n var R2 = tmp[3];\n var a = Math.min(L1, L2);\n var b = Math.max(R1, R2);\n output[i] = a + \" \" + b;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [l1, r1, l2, r2] = d.split(' ').map(Number);\n\n console.log(l1, r2);\n c++;\n});\n"}, {"source_code": "var a = +readline();\n\nfor(var i = 0; i < a; i++) {\n var l = readline().split(' ');\n print(l[0] + ' ' + l[3]);\n}"}, {"source_code": "function ansa(n,arr){\n\n\n for(var i = 0 ; i < n ; i++){\n\n var q1 = Math.max(arr[i][0],arr[i][2]);\n var q2 = Math.min(arr[i][1],arr[i][3]);\n print(q1,q2)\n }\n}\n\n\nvar n = parseInt(readline())\nvar arr = []\nfor(var i = 0 ; i < n ; i++){\n var a = readline().split(\" \");\n for(var j = 0 ; j < a.length ; j++) a[j] = parseInt(a[j]);\n arr[i] = a;\n}\nansa(n,arr);\n\n\n// var b = readline().split(' ');\n// for(var i = 0 ; i < b.length ; i++) b[i] = parseInt(b[i]);\n"}, {"source_code": "function ansa(n,arr){\n\n\n for(var i = 0 ; i < n ; i++){\n\n var q1 = Math.min(arr[i][0],arr[i][2]);\n var q2 = Math.max(arr[i][1],arr[i][3]);\n print(q1,q2)\n }\n}\n\n\nvar n = parseInt(readline())\nvar arr = []\nfor(var i = 0 ; i < n ; i++){\n var a = readline().split(\" \");\n for(var j = 0 ; j < a.length ; j++) a[j] = parseInt(a[j]);\n arr[i] = a;\n}\nansa(n,arr);\n\n\n// var b = readline().split(' ');\n// for(var i = 0 ; i < b.length ; i++) b[i] = parseInt(b[i]);\n"}, {"source_code": "function ansa(n,arr){\n\n\n for(var i = 0 ; i < n ; i++){\n\n var q1 = Math.max(arr[i][0],arr[i][2]);\n var q2 = Math.min(arr[i][1],arr[i][3]);\n print(q2,q1)\n }\n}\n\n\nvar n = parseInt(readline())\nvar arr = []\nfor(var i = 0 ; i < n ; i++){\n var a = readline().split(\" \");\n for(var j = 0 ; j < a.length ; j++) a[j] = parseInt(a[j]);\n arr[i] = a;\n}\nansa(n,arr);\n"}, {"source_code": "var n = parseInt(readline());\n\nfor (var i =0;i{return parseInt(v);});\n \n var l1 = ar[0], r1 = ar[1], l2 = ar[2], r2 = ar[3];\n\n var a=Math.max(ar[0], ar[2]), b=Math.min(ar[1], ar[3]);\n if ( l1 > a || a > r1) {\n a = ar[1]-1;\n }\n\n if ( l2 > b || b > r2) {\n b = ar[3]-1;\n }\n print(a, b)\n\n}\n"}, {"source_code": "//var input = readline()\nvar n = parseInt(readline())\n\nfor(var i=0; i {\r\n t = +v;\r\n input();\r\n});\r\n\r\nfunction input() {\r\n rl.question('', v => {\r\n const n = +v;\r\n\r\n rl.question('', v => {\r\n const arr = v.trim().split(' ').map(el => +el);\r\n main(n, arr);\r\n\r\n i++;\r\n if (i === t) {\r\n rl.close();\r\n return;\r\n }\r\n input();\r\n });\r\n });\r\n}\r\n\r\nfunction createTree(l, r, arr, darr, d = 0) {\r\n if (r < l) {\r\n return;\r\n }\r\n\r\n if (l === r) {\r\n darr[l] = d;\r\n return;\r\n }\r\n\r\n let m = l;\r\n for (let i = l + 1; i <= r; i++) {\r\n if (arr[i] > arr[m]) {\r\n m = i;\r\n }\r\n }\r\n\r\n darr[m] = d;\r\n createTree(l, m - 1, arr, darr, d + 1);\r\n createTree(m + 1, r, arr, darr, d + 1);\r\n}\r\n\r\nfunction main(n, arr) {\r\n const darr = new Array(n);\r\n createTree(0, n - 1, arr, darr);\r\n console.log(darr.join(' '));\r\n}", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nclass node {\r\n constructor(val, ind) {\r\n this.ind = ind;\r\n this.val = val;\r\n this.left = null;\r\n this.right = null;\r\n }\r\n}\r\nclass Tree {\r\n constructor() {\r\n this.root = null;\r\n }\r\n push(val, ind) {\r\n const helper = (head) => {\r\n if (head === null) return new node(val, ind);\r\n else if (ind < head.ind) head.left = helper(head.left);\r\n else head.right = helper(head.right);\r\n return head;\r\n };\r\n this.root = helper(this.root);\r\n }\r\n find(ind) {\r\n let d = 0;\r\n const helper = (head, d) => {\r\n if (head.ind === ind) return d;\r\n else if (head.ind > ind) return helper(head.left, d + 1);\r\n else return helper(head.right, d + 1);\r\n };\r\n return helper(this.root, d);\r\n }\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n for (let i = 0; i < n; i++) arr[i] = { val: arr[i], ind: i + 1 };\r\n arr.sort((a, b) => b.val - a.val);\r\n let tree = new Tree();\r\n for (let i = 0; i < n; i++) {\r\n tree.push(arr[i].val, arr[i].ind);\r\n }\r\n let res = \"\";\r\n for (let i = 1; i <= n; i++) {\r\n res += tree.find(i) + \" \";\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = Number.POSITIVE_INFINITY;\r\n\r\nconst top = s => s[s.length - 1];\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\ta[-1] = a[n] = INF;\r\n\t\tlet lmx = [], rmx = [];\r\n\r\n\t\tlet st = [-1];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\twhile (a[top(st)] < a[i]) st.pop();\r\n\t\t\tlmx[i] = a[top(st)];\r\n\t\t\tst.push(i);\r\n\t\t}\r\n\r\n\t\tst = [n];\r\n\t\tfor (let i = n - 1; i >= 0; i--) {\r\n\t\t\twhile (a[top(st)] < a[i]) st.pop();\r\n\t\t\trmx[i] = a[top(st)];\r\n\t\t\tst.push(i);\r\n\t\t}\r\n\r\n\t\tconst inx = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tinx[a[i]] = i;\r\n\r\n\t\tconst dp = [];\r\n\t\tdp[n] = 0;\r\n\t\tfor (let i = n - 1; i > 0; i--) {\r\n\t\t\tconst prnt = Math.min(lmx[inx[i]], rmx[inx[i]]);\r\n\t\t\tdp[i] = dp[prnt] + 1;\r\n\t\t}\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (i in dp) \r\n\t\t\tans[inx[i]] = dp[i];\r\n\r\n\t\tconsole.log(...ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Actual code...\n\nfunction depth(target, arr, left, right) {\n let maximum = 0;\n let indexOfMax = 0;\n for (let i = left; i < right; i++) {\n if (arr[i] > maximum) {\n maximum = arr[i];\n indexOfMax = i;\n }\n }\n const indexOfTarget = arr.indexOf(target);\n if (target === maximum) {\n return 0;\n } else if (indexOfTarget < indexOfMax) {\n return 1 + depth(target, arr, left, indexOfMax);\n } else {\n return 1 + depth(target, arr, indexOfMax + 1, right);\n }\n}\n\nfunction main() {\n const numCases = parseInt(readline());\n for (let i = 0; i < numCases; i++) {\n const numTerms = parseInt(readline());\n const arr = readline().split(\" \").map(str => parseInt(str));\n let result = \"\";\n for (let v = 0; v < numTerms; v++) {\n const d = depth(arr[v], arr, 0, arr.length);\n if (v != 0) result += \" \";\n result += d;\n }\n console.log(result);\n }\n}"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\n\r\nlet n = +readline();\r\nfor (let i = 0; i < n; i++) {\r\n {\r\n readline();\r\n let arr = readline().split(' ').map(i => +i);\r\n let res = {};\r\n function check(arr, depth = 0) {\r\n if (arr.length === 0) return;\r\n let max = Math.max(...arr);\r\n let index = arr.indexOf(max);\r\n res[max] = depth;\r\n check(arr.slice(0, index), depth+1)\r\n check(arr.slice(index + 1), depth+1)\r\n }\r\n check(arr)\r\n console.log(arr.map(num => res[num]).join(' '))\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n height = new Array(x).fill(0)\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n\r\n dfs(a, 0, a.length, 0)\r\n console.log(height.join(' '))\r\n })\r\n\r\n}\r\n\r\n// [l,r)\r\nfunction dfs(array, l, r, currentHeight) {\r\n var res = []\r\n var index = max(array, l, r)\r\n height[index] = currentHeight\r\n\r\n if (l < index) {\r\n dfs(array, l, index, currentHeight + 1)\r\n\r\n }\r\n if (r > index + 1) dfs(array, index + 1, r, currentHeight + 1)\r\n}\r\n\r\nfunction max(array, l, r) {\r\n var m = array[l]\r\n var mI = l\r\n for (var i = l; i < r; i++) {\r\n if (array[i] > m) {\r\n m = array[i]\r\n mI = i\r\n }\r\n }\r\n return mI\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = new Array(N).fill(-1);\r\n\t\tvar stack = [{list : list, count : 0}];\r\n\t\twhile(stack.length > 0){\r\n\t\t\tvar now = stack.pop();\r\n\t\t\tvar max = -1;\r\n\t\t\tvar lastIndex = -1;\r\n\t\t\tfor(var j = 0; j < now.list.length; j++){\r\n\t\t\t\tif(max < now.list[j]){\r\n\t\t\t\t\tmax = now.list[j];\r\n\t\t\t\t\tlastIndex = j;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar maxIndex = list.indexOf(max);\r\n\t\t\toutput[maxIndex] = now.count;\r\n\t\t\tif(now.list.length == 1){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar left = {list : [], count : now.count + 1};\r\n\t\t\tfor(var j = 0; j < lastIndex; j++){\r\n\t\t\t\tleft.list.push(now.list[j]);\r\n\t\t\t}\r\n\t\t\tif(left.list.length > 0){\r\n\t\t\t\tstack.push(left);\t\t\t\t\r\n\t\t\t}\r\n\t\t\tvar right = {list : [], count : now.count + 1};\r\n\t\t\tfor(var j = lastIndex + 1; j < now.list.length; j++){\r\n\t\t\t\tright.list.push(now.list[j]);\r\n\t\t\t}\r\n\t\t\tif(right.list.length > 0){\r\n\t\t\t\tstack.push(right);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n \r\n var result = [];\r\n result = createTree(arr, 0, n - 1, 0, result);\r\n \r\n var resultArr = [];\r\n for(var i = 0; i < n; i++) {\r\n resultArr.push(result[arr[i]]);\r\n }\r\n \r\n write(resultArr.join(\" \") + \"\\n\");\r\n}\r\n\r\nfunction createTree(arr, arrStart, arrEnd, level, result) {\r\n var max = 0;\r\n var index = 0;\r\n for(var i = arrStart; i <= arrEnd; i++) {\r\n index = arr[i] > max ? i : index;\r\n max = arr[i] > max ? arr[i] : max;\r\n }\r\n result[max] = level;\r\n level++;\r\n if(arrStart != arrEnd) {\r\n if(index - 1 >= arrStart)\r\n result = createTree(arr, arrStart, index - 1, level, result);\r\n if(index + 1 <= arrEnd)\r\n result = createTree(arr, index + 1, arrEnd, level, result);\r\n }\r\n \r\n return result;\r\n}"}], "negative_code": [], "src_uid": "a564017f9c411b39f8d4b69e629ae3bc"} {"source_code": "const n = Number(readline());\nconst s = Array.from(readline().substring(0, n), c => Number(c));\n\nfunction stats(digits) {\n var sum = 0;\n var erased = 0;\n for (var digit of digits)\n if (Number.isNaN(digit)) erased++;\n else sum += digit;\n return [sum, erased];\n}\n\nconst half = n * 0.5;\nconst l = stats(s.slice(0, half));\nconst r = stats(s.slice(half));\nconst diff = l[0] - r[0];\nconst le = l[1];\nconst re = r[1];\nprint((() => {\n var pe = (le + re) * 0.5;\n var cl = Math.min(le, pe);\n var cr = Math.min(re, pe);\n var nd = diff + cl * 9;\n if (nd < -(le - cl) * 9 || nd > cr * 9) return true;\n nd = diff - cr * 9;\n if (nd > (re - cr) * 9 || nd < -cl * 9) return true;\n return false;\n})() ? \"Monocarp\" : \"Bicarp\");\n", "positive_code": [{"source_code": "const n = Number(readline());\nconst s = Array.from(readline().substring(0, n), c => Number(c));\n\nfunction stats(digits) {\n var sum = 0;\n var erased = 0;\n for (var digit of digits)\n if (Number.isNaN(digit)) erased++;\n else sum += digit;\n return [sum, erased];\n}\n\nconst half = n * 0.5;\nconst l = stats(s.slice(0, half));\nconst r = stats(s.slice(half));\nconst diff = l[0] - r[0];\nconst le = l[1];\nconst re = r[1];\nprint((() => {\n var pe = (le + re) * 0.5;\n var cl = Math.min(le, pe);\n var cr = Math.min(re, pe);\n var nd = diff + cl * 9;\n if (nd < -(le - cl) * 9 || nd > cr * 9) return true;\n nd = diff - cr * 9;\n if (nd > (re - cr) * 9 || nd < -cl * 9) return true;\n return false;\n})() ? \"Monocarp\" : \"Bicarp\");\n"}], "negative_code": [], "src_uid": "028882706ed58b61b4672fc3e76852c4"} {"source_code": "print(function(n, q) {\n\tvar a = readline().split(' ').map(Number);\n\tvar b = [];\n\tfor (var i = 0; i <= n; i++) {\n\t\tb[i] = 0;\n\t}\n\n\tfor (var i = 0; i < q; i++) {\n\t\treadline().split(' ').reduce(function(l, r) {\n\t\t\tb[l - 1]++;\n\t\t\t\n\t\t\tb[r]--;\n\t\t});\n\t}\n\n\tvar x = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tb[i] = (x += b[i]);\n\t}\n\tb.pop();\n\tb.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tans += a[i] * b[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "print(function(n, q) {\n\tvar a = readline().split(' ').map(Number);\n\tvar b = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tb[i] = 0;\n\t}\n\n\tfor (var i = 0; i < q; i++) {\n\t\treadline().split(' ').reduce(function(l, r) {\n\t\t\tb[l - 1]++;\n\t\t\tif (r < n)\n\t\t\t\tb[r]--;\n\t\t});\n\t}\n\n\tvar x = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tb[i] = (x += b[i]);\n\t}\n\n\tb.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tans += a[i] * b[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, q) {\n\tvar a = ('0 ' + readline()).split(' ').map(Number).sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\tvar b = new Int32Array(n + 1);\n\n\n\tfor (var i = 0; i < q; i++) {\n\t\tvar l = readline().split(' ');\n\t\tb[l[0]]++;\n\t\tb[+l[1] + 1]--;\n\t}\n\n\tvar x = 0;\n\tfor (var i = 1; i <= n; i++) {\n\t\tb[i] = (x += b[i]);\n\t}\n\n\tArray.prototype.sort.call(b, function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 1; i <= n; i++) {\n\t\tans += a[i] * b[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var tree = new Uint32Array(2e5 + 1);\n\nfunction update(i, v, n) {\n\twhile (i <= n) {\n\t\ttree[i] += v;\n\t\ti += (i & -i);\n\t}\n}\n\nfunction read(i) {\n\tvar sum = 0;\n\twhile (i > 0) {\n\t\tsum += tree[i];\n\t\ti -= (i & -i);\n\t}\n\treturn sum;\n}\n\nprint(function(n, q) {\n\tvar a = readline().split(' ').map(Number).sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\twhile (q--) {\n\t\treadline().split(' ').map(Number).reduce(function(x, y) {\n\t\t\tupdate(x, 1, n);\n\t\t\tupdate(y + 1, -1, n);\n\t\t});\n\t}\n\tvar c = new Uint32Array(n);\n\tfor (var i = 1; i <= n; i++) {\n\t\tc[i-1] = read(i);\n\t}\n\tArray.prototype.sort.call(c, function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tans += a[i] * c[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, q) {\n\tvar a = new Int32Array(n + 1);\n\tvar b = new Int32Array(n + 1);\n\n\tvar i = 1;\n\treadline().replace(/\\d+/g, function(x) {\n\t\ta[i++] = +x;\n\t});\n\n\tfor (var i = 0; i < q; i++) {\n\t\tvar l = readline().split(' ');\n\t\tb[l[0]]++;\n\t\tb[+l[1] + 1]--;\n\t}\n\n\tvar x = 0;\n\tfor (var i = 1; i <= n; i++) {\n\t\tb[i] = (x += b[i]);\n\t}\n\n\tArray.prototype.sort.call(b, function(a, b) {\n\t\treturn a - b;\n\t});\n\tArray.prototype.sort.call(a, function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 1; i <= n; i++) {\n\t\tans += a[i] * b[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, q) {\n\tvar a = readline().split(' ').map(Number);\n\tvar b = [];\n\tfor (var i = 0; i <= n; i++) {\n\t\tb[i] = 0;\n\t}\n\n\tvar c=[]\n\tfor (var i = 0; i < q; i++) {\n\t\tc.push(readline());\n\t}\n\tc.forEach(function(v){\n\t\tv.split(' ').reduce(function(l, r) {\n\t\t\tb[l - 1]++;\n\t\t\tb[r]--;\n\t\t});\n\t});\n\n\tvar x = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tb[i] = (x += b[i]);\n\t}\n\tb.pop();\n\tb.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tans += a[i] * b[i];\n\t}\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "\nprint(function(n, q) {\n\tvar a= readline().split(' ').map(Number);\n\tvar b = new Int32Array(n);\n\n\tfor (var i = 0; i < q; i++) {\n\t\treadline().split(' ').reduce(function(l, r){\n\t\t\tb[l-1]++;\n\t\t\tif( r x - y);\na.reverse();\nvar pref = [];\n\nvar i, li, ri;\n\nfor(i = 0; i <= n + 1; i++){\n pref.push(0);\n}\n\nfor(i = 0; i < q; i++){\n var query = readline().split(' ').map(f);\n li = query[0];\n ri = query[1];\n pref[li]++;\n pref[ri + 1]--;\n}\n\nfor(i = 1; i <= n; i++){\n pref[i] = pref[i] + pref[i - 1];\n}\n\npref.sort((x, y) => x - y);\npref.reverse();\n\nvar ans = 0;\nfor(i = 0; i < n; i++){\n ans = ans + pref[i] * a[i];\n}\n\nprint(ans);\n\nfunction f(x){\n return parseInt(x);\n}"}], "negative_code": [{"source_code": "var first = readline().split(' ').map(f);\nvar n = first[0];\nvar q = first[1];\n\nvar a = readline().split(' ').map(f);\na.sort();\nvar pref = [];\n\nvar i, li, ri;\n\nfor(i = 0; i <= n; i++){\n pref.push(0);\n}\n\nfor(i = 0; i < q; i++){\n var query = readline().split(' ').map(f);\n li = query[0];\n ri = query[1];\n pref[li]++;\n pref[ri + 1]--;\n}\n\nfor(i = 1; i <= n; i++){\n pref[i] = pref[i] + pref[i - 1];\n}\n\npref.sort();\n\nvar ans = 0;\nfor(i = 1; i <= n; i++){\n ans = ans + pref[i] * a[i - 1];\n}\n\nprint(ans);\n\nfunction f(x){\n return parseInt(x);\n}"}], "src_uid": "926ec28d1c80e7cbe0bb6d209e664f48"} {"source_code": "function getLine(){\n return readline().split(' ').map(function(x){\n return parseInt(x); \n });\n}\n\nvar L = getLine();\nvar n = L[0];\nvar k = L[1];\nvar p = getLine();\nvar r = 0;\nwhile(true){\n if(p.every(function(x){\n return x == k;\n })){\n break;\n }\n p = p.map(function(x, ind, self){\n if(ind === self.indexOf(x) && x < k){\n x++;\n }\n return x;\n });\n r++;\n}\nprint(r);", "positive_code": [{"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let [nk, zs] = ipt.split(EOL)\n const [n, k] = nk.split(' ')\n zs = zs.split(' ').map(v => +v)\n let g = 0\n while (zs.some(z => z < k)) {\n g++\n let cz = 0\n for (let i = 0; i < zs.length; i++) {\n const z = zs[i]\n if (z == k) break\n if (cz < z) {\n zs[i]++\n cz = z\n }\n }\n zs = zs.sort((a, b) => a - b)\n }\n\n console.log(g)\n})"}], "negative_code": [], "src_uid": "3d6411d67c85f6293f1999ccff2cd8ba"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, a) {\n let last = a[0];\n let sum = last;\n for (let j = 1; j < n; j++) {\n if (last * a[j] > 0) {\n if (a[j] > last) {\n sum = sum - last + a[j];\n last = a[j];\n }\n } else {\n last = a[j];\n sum += a[j];\n }\n }\n return sum;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, a);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, a) {\n let countN = 0;\n let firstN = -1;\n for (let i = 0; i < n; i++) {\n if (a[i] < 0) {\n firstN = i;\n countN++;\n break;\n }\n }\n let sumN = Number.MIN_SAFE_INTEGER;\n if (countN > 0) {\n let last = a[firstN];\n sumN = last;\n for (let j = firstN + 1; j < n; j++) {\n if (last * a[j] > 0) {\n if (a[j] > last) {\n sumN = sumN - last + a[j];\n last = a[j];\n }\n } else {\n last = a[j];\n sumN += a[j];\n countN++;\n }\n }\n }\n let countP = 0;\n let firstP = -1;\n for (let i = 0; i < n; i++) {\n if (a[i] > 0) {\n firstP = i;\n countP++;\n break;\n }\n }\n let sumP = Number.MIN_SAFE_INTEGER;\n if (countP > 0) {\n let last = a[firstP];\n sumP = last;\n for (let j = firstP + 1; j < n; j++) {\n if (last * a[j] > 0) {\n if (a[j] > last) {\n sumP = sumP - last + a[j];\n last = a[j];\n }\n } else {\n last = a[j];\n sumP += a[j];\n countP++;\n }\n }\n }\n let sum = countP > countN ? sumP : countN > countP ? sumN : Math.max(sumN, sumP);\n return sum;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, a);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n //let [n, industry] = readline().split(\" \").map(e => parseInt(e));\n\n let cases = parseInt(readline(), 10);\n for (var i = 0; i < cases; i++) {\n readline();\n const numbers = readline().split(\" \").map(e => parseInt(e));\n\n\n let sum = 0;\n while (numbers.length > 0) {\n let sub = [numbers.pop()];\n let sign = Math.sign(sub[0]);\n\n while (numbers.length > 0 && Math.sign(numbers[numbers.length-1]) === sign) {\n sub.push(numbers.pop());\n }\n\n sum += Math.max.apply(null, sub);\n }\n\n console.log(sum);\n\n \n }\n\n\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar isPlus = true;\n\t\tvar sum = 0;\n\t\tif(list[0] < 0){\n\t\t\tisPlus = false;\n\t\t}\n\t\tvar plusList = [];\n\t\tvar minusList = [];\n\t\tvar tmpPlusList = [];\n\t\tvar tmpMinusList = [];\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(isPlus){\n\t\t\t\tif(list[j] > 0){\n\t\t\t\t\ttmpPlusList.push(list[j]);\n\t\t\t\t}else{\n\t\t\t\t\tplusList.push(tmpPlusList);\n\t\t\t\t\ttmpPlusList = [];\n\t\t\t\t\ttmpMinusList.push(list[j]);\n\t\t\t\t\tisPlus = false;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(list[j] < 0){\n\t\t\t\t\ttmpMinusList.push(list[j]);\n\t\t\t\t}else{\n\t\t\t\t\tminusList.push(tmpMinusList);\n\t\t\t\t\ttmpMinusList = [];\n\t\t\t\t\ttmpPlusList.push(list[j]);\n\t\t\t\t\tisPlus = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(j == n - 1){\n\t\t\t\tif(tmpMinusList.length > 0){\n\t\t\t\t\tminusList.push(tmpMinusList);\n\t\t\t\t}\n\t\t\t\tif(tmpPlusList.length > 0){\n\t\t\t\t\tplusList.push(tmpPlusList);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t//myerr(\"p:\" + plusList);\n\t\t//myerr(\"m:\" + minusList);\n\t\tfor(var j = 0; j < plusList.length; j++){\n\t\t\t//myerr(plusList[j]);\n\t\t\tsum += Math.max.apply(null,plusList[j]);\n\t\t}\n\t\tfor(var j = 0; j < minusList.length; j++){\n\t\t\t//myerr(minusList[j]);\n\t\t\tsum += Math.max.apply(null,minusList[j]);\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(s) { return +s; }\n\nfor(var qq = 0; qq < t; qq++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(mapper);\n var al = a.length;\n \n var sum = 0;\n\n var curMax = a[0];\n var onPos = a[0] > 0;\n \n for(var i = 1; i < al; i++) {\n if (onPos) {\n if (a[i] > 0) {\n if (a[i] > curMax) {\n curMax = a[i];\n }\n } else {\n sum += curMax;\n onPos = false;\n curMax = a[i];\n }\n } else {\n if (a[i] < 0) {\n if (a[i] > curMax) {\n curMax = a[i];\n }\n } else {\n sum += curMax;\n onPos = true;\n curMax = a[i];\n }\n }\n }\n sum += curMax;\n \n print(sum);\n}"}, {"source_code": "var range = readline();\n \nfor(var i=0;i parseInt(x));\n var sums = [];\n var max = [];\n var min = [];\n \n for(var j=0;j 0) {\n if(min.length) {\n var value = Math.max.apply(null, min);\n sums.push(value);\n min.length = 0;\n }\n max.push(numbers[j]);\n }\n }\n \n if(max.length) {\n sums.push(Math.max.apply(null, max));\n }\n \n if(min.length) {\n sums.push(Math.max.apply(null, min));\n }\n \n if(sums.length === 0) {\n print(Math.max.apply(null, numbers));\n } else {\n var sum = sums.reduce((a, b) => a + b, 0);\n print(sum);\n }\n \n}"}, {"source_code": "//Alternating Subsequence\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let t = +lines[0];\n\n let sgn = (x) => (x > 0) ? 1 : -1;\n\n let f = (arr) => {\n \tlet sign = sgn(arr[0]);\n \tlet minmax = arr[0];\n \tlet sum = 0;\n \tfor(let i = 0; i < arr.length; i++) {\n \t\tif(sgn(arr[i]) == sign) {\n \t\t\tif(arr[i] > minmax) {\n \t\t\t\tminmax = arr[i];\n \t\t\t}\n \t\t} else {\n \t\t\tsum += minmax;\n \t\t\tsign = -sign;\n \t\t\tminmax = arr[i];\n \t\t}\n \t}\n\t\tsum += minmax;\n\t\treturn sum;\n }\n\n for(let i = 0; i < t; i++) {\n \t// let n = +lines[2 * i + 1];\n \tlet arr = lines[2 * i + 2].split(' ').map(c => +c);\n \tprocess.stdout.write(f(arr) + EOL);\n }\n\n return;\n});"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, a) {\n let sum = Number.MIN_SAFE_INTEGER;\n let countN = 0;\n let countP = 0;\n let firstN = -1;\n let firstP = -1;\n for (let i = 0; i < n; i++) {\n if (firstN !== -1 && firstP !== -1) break;\n if (firstN === -1 && a[i] < 0) {\n firstN = i;\n countN++;\n }\n if (firstP === -1 && a[i] > 0) {\n firstP = i;\n countP++;\n }\n }\n if (countN > 0) {\n for (let i = firstN; i < n; i++) {\n if (a[i] > 0) break;\n let last = a[i];\n let curSum = a[i];\n countN = 1;\n for (let j = i + 1; j < n; j++) {\n if (last * a[j] > 0) {\n if (curSum - last + a[j] > curSum) {\n last = a[j];\n curSum = curSum - last + a[j];\n }\n } else {\n last = a[j];\n curSum += a[j];\n countN++;\n }\n }\n sum = Math.max(sum, curSum);\n }\n }\n if (countP > 0) {\n for (let i = firstP; i < n; i++) {\n if (a[i] < 0) break;\n let last = a[i];\n let curSum = a[i];\n countP = 1;\n for (let j = i + 1; j < n; j++) {\n if (last * a[j] > 0) {\n if (curSum - last + a[j] > curSum) {\n last = a[j];\n curSum = curSum - last + a[j];\n }\n } else {\n last = a[j];\n curSum += a[j];\n countP++;\n }\n }\n if (countP >= countN) sum = Math.max(sum, curSum);\n }\n }\n return sum;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, a);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "var range = readline();\n \nfor(var i=0;i parseInt(x));\n var sums = [];\n\n for(var j=0;j 0) {\n sums.push(numbers[j]);\n sums.push(numbers[j+1]);\n j++;\n } else if(numbers[j] > 0 && numbers[j+1] <0) {\n sums.push(numbers[j]);\n sums.push(numbers[j+1]);\n j++;\n }\n }\n \n if(sums.length === 0) {\n print(Math.max.apply(null, numbers));\n } else {\n var sum = sums.reduce((a, b) => a + b, 0);\n print(sum);\n }\n \n}"}], "src_uid": "39480cdf697fc9743dc9665f989077d7"} {"source_code": "var nm = readline().trim().split(' ').map((x)=>parseInt(x));\nvar n= nm[0];\nvar m = nm[1];\nvar b = []\nfor(var i=0;iparseInt(x)));\n}\n\nvar ans = [];\nfor (var i = 0; i < n; i++) {\n\t\tans.push([]);\n\tfor (var j = 0; j < m; j++) {\n\t\tans[i].push(-1);\n\t}\n}\nvar wrong = false;\nfor (var i = 0; i < n; i++) {\n\tfor (var j = 0; j < m; j++) {\n\t\tif(b[i][j]==0){\n\t\t\tfor (var k = 0; k < m; k++) {\n\t\t\t\tif(ans[i][k]==1){\n\t\t\t\t\twrong = true;\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tans[i][k]=0;\n\t\t\t}\n\t\t\tfor (var k = 0; k < n; k++) {\n\t\t\t\tif(ans[k][j]==1){\n\t\t\t\t\twrong = true;\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tans[k][j]=0;\n\t\t\t}\n\t\t}\n\t\tif(wrong)\n\t\t\tbreak;\n\t}\n\n\tif(wrong)\n\t\tbreak;\n}\n\n\nif(wrong)\n\tprint('NO');\nelse{\n\tfor (var i = 0; i < n; i++) {\n\t\tfor (var j = 0; j < m; j++) {\n\t\t\tif(b[i][j]==1){\n\t\t\t\tvar isOne = false\n\t\t\t\tfor (var k = 0; k < m; k++) {\n\t\t\t\t\tif(ans[i][k]!=0){\n\t\t\t\t\t\tisOne = true;\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(!isOne){\n\t\t\t\t\tfor (var k = 0; k < n; k++) {\n\t\t\t\t\t\tif(ans[k][j]!=0){\n\t\t\t\t\t\t\tisOne = true;\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(!isOne){\n\t\t\t\t\twrong = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t\tif(wrong)\n\t\t\tbreak;\n\t}\n\n\tif(wrong)\n\t\tprint('NO');\n\telse{\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tfor (var j = 0; j < m; j++) {\n\t\t\t\tif(ans[i][j]==-1){\n\t\t\t\t\tans[i][j]=1;\n\t\t\t\t}\t\n\t\t\t}\n\t\t}\n\t\tprint('YES');\n\t\tfor (var i = 0; i < n; i++) {\n\t\t print(ans[i].join(' '));\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "var size = readline().trim().split(' ');\nvar m = size[0], n = size[1];\nvar MatrixA = [], MatrixB = [];\n\nfor (var i = 0; i < m; i++) {\n MatrixB.push([]);\n MatrixB[i] = readline().trim().split(' ');\n for (var j = 0; j < n; j++) {\n MatrixB[i][j] = parseInt(MatrixB[i][j]);\n }\n}\nfor (var i = 0; i < m; i++) {\n MatrixA.push([]);\n for (var j = 0; j < n; j++) {\n MatrixA[i][j] = 1;\n }\n}\n\n\nfunction setRowZero(row) {\n for (var i = 0; i < n; i++) {\n MatrixA[row][i] = 0;\n }\n}\nfunction setColumnZero(col) {\n for (var i = 0; i < m; i++) {\n MatrixA[i][col] = 0;\n }\n}\n\nfor (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n if (MatrixB[i][j] === 0) {\n setRowZero(i);\n setColumnZero(j);\n }\n }\n}\n\nfunction check() {\n var isOk = true;\n for (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n var target = MatrixB[i][j];\n var source = 0;\n for (var k = 0; k < m; k++) {\n if (MatrixA[k][j] === 1) {\n source = 1;\n }\n }\n for (var k = 0; k < n; k++) {\n if (MatrixA[i][k] === 1) {\n source = 1;\n }\n }\n if (target !== source) {\n isOk = false;\n }\n }\n }\n if (isOk) {\n print('YES');\n for (var i = 0; i < m; i++) {\n print(MatrixA[i].join(' '));\n }\n } else {\n print('NO');\n }\n\n}\n\ncheck();\n\n\n"}], "negative_code": [], "src_uid": "bacd613dc8a91cee8bef87b787e878ca"} {"source_code": "const {stdin, exit} = require('process');\nlet inp = \"\";\nstdin.on('data', chunk => inp += chunk).on('end', () => {\n let [a, b] = inp.split('\\n').map(s => s.trim());\n if (a === b) console.log(-1);\n else console.log(Math.max(a.length, b.length));\n})", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\n\nfunction array2d(r,c) {\n let ans =[];\n for(let i = 0; i < r; i++) {\n let rowElements = [];\n for(let j = 0; j < c; j++) {\n rowElements.push(0);\n }\n ans.push(rowElements);\n }\n return ans;\n}\nfunction max(a,b){\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let m = readline();\n let e = readline();\n if(m.length < e.length) {\n [e, m] = [m, e];\n }\n if(m == e) print(-1);\n else print(m.length);\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet a = nl.line();\n\tlet b = nl.line();\n console.log((a !== b)?Math.max(a.length, b.length):-1);\n\t\n \n};\n \nprocess.stdin.on('end', sol);"}, {"source_code": "function out(a, b){return (a===b)?-1:(a.length > b.length)?a.length:b.length} \nprint(out(readline(),readline()))"}, {"source_code": "var out = function(a, b){return (a===b)?-1:Math.max(a.length,b.length)} \nprint(out(readline(),readline()))"}, {"source_code": "var a = readline();\nvar b = readline();\nif(a==b)\n print(-1);\nelse\n print(Math.max(a.length,b.length));\n\n"}, {"source_code": "var x = readline();\nvar y = readline();\n\nif (x == y) {\n print(-1);\n} else {\n print(parseInt(Math.max(x.length,y.length)));\n}"}, {"source_code": "s1 = readline();\ns2 = readline();\nans = -1;\nif(s1 !== s2){\n ans = Math.max(s1.length, s2.length);\n}\nprint(ans);"}, {"source_code": "/* global readline, print */\nconst a = readline()\nconst b = readline()\n\nif (a === b) print(-1)\nelse print(Math.max(a.length, b.length))\n"}, {"source_code": "var a = readline(),\n b = readline(),\n arr = [],\n res = 0;\n \nif (a.length > b.length) res = a.length;\nelse if (b.length > a.length) res = b.length;\nelse if (a === b) res = -1;\nelse {\n res = a.length;\n}\n\nprint(res);"}, {"source_code": "var s1 =readline();\nvar s2 = readline();\nvar p =function () {if (s1!==s2) {return Math.max(s1.length,s2.length)} else return -1};\nprint (p());"}, {"source_code": "var a = readline();\nvar b = readline();\nif (a == b) {\n\tprint (-1);\n} else {\n\tif (a.length > b.length) {\n\t\tprint (a.length);\n\t} else if (a.length < b.length) {\n\t\tprint (b.length);\n\t} else if (a.length = b.length) {\n\t\tprint (a.length);\n\t}\n}"}, {"source_code": "function main() {\n var line1 = readline();\n var line2 = readline();\n if(line1 == line2){\n return print(-1);\n } else {\n print(Math.max(line1.length, line2.length))\n }\n}\n\n\nmain()"}, {"source_code": ";(function () {\n\tvar a = readline(),\n\t\tb = readline()\n\tif (a === b) print(-1)\n\telse print(Math.max(a.length, b.length))\n})();"}, {"source_code": "var a = readline();\nvar b = readline();\n\nif (a === b) {\n print(-1);\n} else {\n print(Math.max(a.length , b.length));\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const a = readline();\n const b = readline();\n let l;\n if (a.length !== b.length) {\n l = Math.max(a.length, b.length);\n } else {\n l = a === b ? -1 : a.length;\n }\n print(l);\n}\n\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\n\nfunction array2d(r,c) {\n let ans =[];\n for(let i = 0; i < r; i++) {\n let rowElements = [];\n for(let j = 0; j < c; j++) {\n rowElements.push(0);\n }\n ans.push(rowElements);\n }\n return ans;\n}\nfunction max(a,b){\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let m = readline();\n let e = readline();\n if(m.length < e.length) {\n [e, m] = [m, e];\n }\n let dp = array2d(m.length, e.length);\n let i = 0;\n for(const element of e) {\n if(m[0] != element) dp[0][i] = 1;\n i++; \n }\n i = 0;\n for(const element of m) {\n if(e[0] != element) dp[i][0] = 1;\n i++;\n }\n for(let i = 1; i < m.length; i++) {\n for(let j = 1; j < e.length; j++) {\n if(m[i] != e[j]) {\n dp[i][j] = dp[i-1][j - 1] + 1;\n }\n }\n }\n let ans = dp[m.length - 1][e.length - 1];\n if(ans == e.length) print(m.length);\n else if(ans == 0) print(-1);\n else print(ans);\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet a = nl.line().split('');\n\tlet b = nl.line().split('');\n\tlet t = '';\n\tlet aa = [];\n\tfor(let c of a){\n\t\tif (t.length > 0) {\n\t\t\tif (c >= t.charAt(t.length-1)) {\n\t\t\t\tt += c;\n\t\t\t} else {\n\t\t\t\taa.push(t);\n\t\t\t\tt = c;\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tt += c;\n\t\t}\n\t}\n\taa.push(t);\n\tt = '';\n\tlet bb = [];\n\tfor(let c of b){\n\t\tif (t.length > 0) {\n\t\t\tif (c >= t.charAt(t.length-1)) {\n\t\t\t\tt += c;\n\t\t\t} else {\n\t\t\t\tbb.push(t);\n\t\t\t\tt = c;\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tt += c;\n\t\t}\n\t}\n\tbb.push(t);\n\tlet cc = aa.filter(x => !bb.includes(x)).concat(bb.filter(x => !aa.includes(x)));\n\tif (cc.length === 0){\n\t\tconsole.log(-1);\n\t} else {\n\t\tconsole.log(Math.max(...(cc.map(x => x.length))));\n\t}\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet a = nl.line().split('');\n\tlet b = nl.line().split('');\n\tlet t = '';\n\tlet aa = [];\n\tfor(let c of a){\n\t\tif (t.length > 0) {\n\t\t\tif (c > t.charAt(t.length-1)) {\n\t\t\t\tt += c;\n\t\t\t} else {\n\t\t\t\taa.push(t);\n\t\t\t\tt = c;\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tt += c;\n\t\t}\n\t}\n\taa.push(t);\n\tt = '';\n\tlet bb = [];\n\tfor(let c of b){\n\t\tif (t.length > 0) {\n\t\t\tif (c > t.charAt(t.length-1)) {\n\t\t\t\tt += c;\n\t\t\t} else {\n\t\t\t\tbb.push(t);\n\t\t\t\tt = c;\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tt += c;\n\t\t}\n\t}\n\tbb.push(t);\n\tlet cc = aa.filter(x => !bb.includes(x)).concat(bb.filter(x => !aa.includes(x)));\n\tif (cc.length === 0){\n\t\tconsole.log(-1);\n\t} else {\n\t\tconsole.log(Math.max(...(cc.map(x => x.length))));\n\t}\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "var a = readline();\nvar b = readline();\nif (a == b) {\n\tprint (-1);\n} else {\n\tif (a.length > b.length) {\n\t\tprint (a.length);\n\t} else if (a.length < b.length) {\n\t\tprint (b.length);\n\t} else if (a.length = b.length) {\n\t\tprint (-1);\n\t}\n}"}, {"source_code": "var a = readline();\nvar b = readline();\nif (a == b) {\n\tprint (-1);\n} else {\n\tif (a.length > b.length) {\n\t\tprint (a.length);\n\t} else if (a.length < b.length) {\n\t\tprint (b.length);\n\t}\n}"}], "src_uid": "f288d7dc8cfcf3c414232a1b1fcdff3e"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve([a, b, c, x, y]) {\r\n x -= a;\r\n y -= b;\r\n if (x <= 0 && y <= 0) {\r\n console.log('yes');\r\n return;\r\n }\r\n if (x > 0) {\r\n c -= x;\r\n }\r\n if (c < 0) {\r\n console.log('no');\r\n return;\r\n }\r\n if (y > 0) {\r\n c -= y;\r\n }\r\n if (c < 0) {\r\n console.log('no');\r\n return;\r\n }\r\n console.log('yes');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const a = (await read()).split(' ').map(Number);\r\n solve(a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "var t = +readline()\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline().split(' ').map((t) => +t)\r\n print(Task1(a[0],a[1],a[2],a[3],a[4]));\r\n}\r\n \r\nfunction Task1 (a,b,c,x,y){\r\n\r\n var test1 = a-x;\r\n var test2 = b-y;\r\n\r\n if (test1 < 0) {\r\n var just = test1;\r\n test1 += c;\r\n c += just;\r\n }\r\n if (test2 < 0){\r\n test2 += c;\r\n }\r\n \r\n var res = test1 >= 0 && test2 >= 0;\r\n return res ? 'YES': 'NO'\r\n\r\n}"}, {"source_code": " var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var inputs = readline().split(' '),\r\n a = inputs[0], b = inputs[1], c = inputs[2];\r\n x = inputs[3], y = inputs[4] , counter = 0;\r\n if(a - x < 0){\r\n counter+= Math.abs(a - x);\r\n }\r\n if(b - y < 0){\r\n counter+= Math.abs(b - y);\r\n } \r\n if(counter === 0){\r\n print(\"YES\");\r\n }\r\n else if(c - counter >= 0){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "t = parseInt(readline());\r\nfor(i = 0; i < t; i++)\r\n{\r\n var n = readline().split(\" \");\r\n n[3] -= n[0];\r\n if(n[3] < 0) n[3] = 0;\r\n n[4] -= n[1];\r\n if(n[4] < 0) n[4] = 0;\r\n if(n[3] + n[4] > n[2]) { print(\"NO\"); }\r\n else print(\"YES\");\r\n}"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nfor (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var i = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), a = _b[0], b = _b[1], c = _b[2], x = _b[3], y = _b[4];\r\n print(Math.max(0, x - a) + Math.max(0, y - b) > c ? 'NO' : 'YES');\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline().split(' ').map(x => +x)\r\n forDogs = x[0]\r\n forCats = x[1]\r\n forAll = x[2]\r\n dogs = x[3]\r\n cats = x[4]\r\n \r\n res = 'NO'\r\n \r\n if (forDogs >= dogs &&forCats >= cats)\r\n res = 'YES'\r\n else if(forDogs < dogs && forCats >= cats && forAll >= dogs - forDogs) \r\n res = 'YES'\r\n else if (forDogs >= dogs && forCats < cats && forAll >= cats - forCats)\r\n res = 'YES'\r\n else if(forDogs < dogs && forCats < cats && forAll >= (cats - forCats)+ (dogs - forDogs))\r\n res = 'YES'\r\n \r\n print(res)\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n \r\nvar input = [];\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n \r\nrl.on(\"line\", function (val) {\r\n input.push(val);\r\n});\r\n \r\nrl.on(\"close\", function () {\r\n for (let i = 1; i <= input[0]; i++) {\r\n var entities = input[i].split(\" \").map(x => parseInt(x))\r\n var dogFoodEater = (entities[3] - entities[0]) < 0 ? 0 : (entities[3] - entities[0]);\r\n var catFoodEater = (entities[4] - entities[1]) < 0 ? 0 : (entities[4] - entities[1]);\r\n if (dogFoodEater + catFoodEater > entities[2]) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n \r\n process.exit(0);\r\n});"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c,x,y] = get_ints();\r\n\r\n const res = MY_FUNC(a,b,c,x,y);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction MY_FUNC(a,b,c,x,y){\r\n let ans = 'NO';\r\n Math.max(0,x - a) + Math.max(0,(y - b)) <= c ? ans = 'YES': ans;\r\n return ans;\r\n}\r\n "}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [a,b,c,x,y] = get_ints();\r\n\r\n const res = MY_FUNC(a,b,c,x,y);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction MY_FUNC(a,b,c,x,y){\r\n if(x > a){\r\n if(a + c < x) return 'NO';\r\n c-= x - a;\r\n }\r\n if(y > b){\r\n if(b + c < y) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n "}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alpha() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n for(var x=0;x parseInt(x))\r\n a -= x;\r\n b -= y;\r\n a = Math.min(a, 0);\r\n b = Math.min(b, 0)\r\n var ans = 0;\r\n if(c+(a+b) >= 0) ans = 1;\r\n else ans = 0;\r\n console.log(ans? 'YES': 'NO');\r\n //fs.appendFileSync('output.txt', (ans?'YES':'NO')+'\\r\\n');\r\n //os.EOL\r\n}\r\n//fs.writeFileSync('output.txt', f.join(' '));\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [a,b,c,x,y] = readline().split(' ').map(Number);\r\n\r\n x = Math.max(0, x - a);\r\n y = Math.max(0, y - b);\r\n\r\n output((x + y) <= c ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var food = readline().split(\" \").map(Number);\r\n var a = food[0];\r\n var b = food[1];\r\n var c = food[2];\r\n var x = food[3];\r\n var y = food[4];\r\n if (c >= Math.max(0, x - a) + Math.max(0, y - b)) {\r\n console.log(\"YES\")\r\n } else {\r\n console.log(\"NO\")\r\n }\r\n\r\n\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var line = readline().split(' ');\r\n var a = parseInt(line[0]);\r\n var b = parseInt(line[1]);\r\n var c = parseInt(line[2]);\r\n var x = parseInt(line[3]);\r\n var y = parseInt(line[4]);\r\n\r\n a -= x;\r\n b -= y;\r\n if (Math.max(0,-a)+Math.max(0,-b) > c) {\r\n console.log('NO');\r\n } else {\r\n console.log('YES');\r\n }\r\n\r\n }\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(i = 1; i <= n; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; \n var b = k[1]; \n var c = k[2]; \n var x = k[3]; \n var y = k[4];\n var s = 0\n x -= a\n y -= b\n if(x > 0){\n c -= x;\n }if(y > 0){\n c -= y;\n }\n if(c >= 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n \r\n let num = Number.parseInt(readline());\r\n\r\n while(num-- > 0){\r\n let input = readline();\r\n let inputArr = input.split(' ')\r\n let dogF = Number.parseInt(inputArr[0])\r\n let catF = Number.parseInt(inputArr[1])\r\n let UniversalF = Number.parseInt(inputArr[2])\r\n let dog = Number.parseInt(inputArr[3])\r\n let cat = Number.parseInt(inputArr[4])\r\n let res1 = (dog <= dogF) ? 0 : dog - dogF;\r\n let res2 = (cat <= catF) ? 0 : cat - catF;\r\n let res = ((res1 + res2) <= UniversalF) ? 'YES' : 'NO';\r\n console.log(res)\r\n }\r\n}\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(i = 1; i <= n; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2]; var x = k[3]; var y = k[4];\n var temp = 0;\n x -= a;\n y -= b;\n if(x > 0){\n c -= x;\n }if(y > 0){\n c -= y;\n }\n if(c >= 0){\n console.log('Yes');\n }else{\n console.log('No');\n }\n }\n});"}, {"source_code": "var readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on(\"line\", function (line) {\n var input = line.split(\" \");\n if (input.length === 5) {\n var [dogsFood, catsFood, univeralFood, xDogs, yCats] = input.map(Number);\n var hungryDogs = xDogs - dogsFood < 0 ? 0 : xDogs - dogsFood;\n var hungryCats = yCats - catsFood < 0 ? 0 : yCats - catsFood;\n if (hungryDogs + hungryCats <= univeralFood) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n});\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (a, b, c, x, y)=>{\n let dog = Math.max(x - a, 0);\n let cat = Math.max(y - b, 0);\n let all = dog + cat - c;\n if (all > 0) return 'NO';\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n // let n = +readline();\n let [a, b, c, x, y] = ra();\n console.log(`${calc(a, b, c, x, y)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const [a, b, c, d, e] = arr\n const ca = Math.max(0, d - a)\n const cb = Math.max(0, e - b)\n return ca + cb <= c\n}\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [a, b, c, x, y] = ra();\n LT({a, b, c, x, y});\n\n // PROCESSING:\n x -= a;\n y -= b;\n if (Math.max(x, 0)+Math.max(y, 0)<=c)\n return 'YES'; \n return 'NO'\n};\n "}, {"source_code": "\r\nvar t = Number(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var arr = readline().split(\" \");\r\n var a = Number(arr[0]);\r\n var b = Number(arr[1]);\r\n var c = Number(arr[2]);\r\n var x = Number(arr[3]);\r\n var y = Number(arr[4]);\r\n if (x <= a + c) {\r\n c -= Math.max(x - a, 0);\r\n if (y <= b + c) {\r\n print(\"YES\");\r\n continue;\r\n }\r\n }\r\n print(\"NO\");\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var t = Number(readline());\r\n \r\nfor(var i = 0; i < t; i++){\r\n var arr = readline().split(' ');\r\n \r\n print('NO');\r\n}"}, {"source_code": "var t = Number(readline());\r\nvar str = readline().split('');\r\nvar arr = [];\r\nstr.forEach((cur, i) => {\r\n arr.push(str.slice(i,i+2).join(''));\r\n});\r\nvar obj= {}, maxEl, maxCount = 0;\r\narr.forEach((cur, i) => {\r\n if(!obj[cur]){\r\n obj[cur] = 1;\r\n }else{\r\n obj[cur]++;\r\n }\r\n \r\n if(obj[cur] > maxCount){\r\n maxCount = obj[cur];\r\n maxEl = cur;\r\n }\r\n});\r\n \r\nprint(maxEl);"}, {"source_code": "var t = +readline()\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline().split(' ').map((t) => +t)\r\n print(Task1(a[0],a[1],a[2],a[3],a[4]));\r\n}\r\n \r\nfunction Task1 (a,b,c,x,y){\r\n\r\n var test1 = a-x;\r\n var test2 = b-y;\r\n\r\n if (test1 < 0) {\r\n var just = test1;\r\n test1 += c;\r\n c += just;\r\n }\r\n if (test2 < 0){\r\n test2 += c;\r\n }\r\n \r\n return test1 >= 0 && test2 >= 0;\r\n\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\n \r\nvar input = [];\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n \r\nrl.on(\"line\", function (val) {\r\n input.push(val);\r\n});\r\n \r\nrl.on(\"close\", function () {\r\n for (let i = 1; i <= input[0]; i++) {\r\n var entities = input[i].split(\" \").map(x => parseInt(x))\r\n var dogFoodEater = entities[0] - entities[3];\r\n var catFoodEater = entities[1] - entities[4];\r\n if (dogFoodEater + catFoodEater > entities[2]) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n \r\n process.exit(0);\r\n});"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alpha() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n for(var x=0;x parseInt(x))\r\n a -= x;\r\n b -= y;\r\n a = Math.min(a, 0);\r\n b = Math.min(b, 0)\r\n var ans = 0;\r\n if(c+(a+b) >= 0) ans = 1;\r\n else ans = 0;\r\n console.log(ans);\r\n //fs.appendFileSync('output.txt', (ans?'YES':'NO')+'\\r\\n');\r\n //os.EOL\r\n}\r\n//fs.writeFileSync('output.txt', f.join(' '));\r\n\r\n"}], "src_uid": "7ac27da2546a50d453f7bb6cacef1068"} {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var s = readline();\r\n var m = 0;\r\n var v = []\r\n var w = []\r\n var ans = [];\r\n var a = 0;\r\n var b = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (s[i] == '1') {\r\n b++;\r\n v.push(i);\r\n }\r\n }\r\n for (var i = n - 1; i >= 0; i--) {\r\n if (s[i] == '0') {\r\n a++;\r\n w.push(i);\r\n }\r\n }\r\n for (var i = 0; i < v.length; i++) {\r\n if (v[i] < n - b) {\r\n m++;\r\n ans.push(v[i]);\r\n }\r\n }\r\n for (var i = 0; i < w.length; i++) {\r\n if (w[i] > a - 1) {\r\n m++;\r\n ans.push(w[i]);\r\n }\r\n }\r\n\r\n if (ans.length == 0)\r\n return \"0\";\r\n else {\r\n ans.sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var val1 = \"1\\n\";\r\n var val2 = ans.length + \" \";\r\n for (var i = 0; i < ans.length; i++) {\r\n val2 += ans[i] + 1 + \" \"\r\n }\r\n return val1 + val2\r\n }\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }", "positive_code": [{"source_code": "const solve = (n,arr)=>{\r\n let res = [];\r\n for(let i=n-1;i>=0;i--){\r\n if(arr[i]===0){\r\n let j = 0,k=0;\r\n while((!arr[i])&& (i>j)){\r\n if(arr[j]){\r\n [arr[i],arr[j]] = [arr[j],arr[i]];\r\n res.push(i+1);\r\n res.push(j+1);\r\n i--;\r\n }\r\n j++;\r\n }\r\n }\r\n }\r\n if(res.length===0) console.log(0);\r\n else{\r\n console.log(1);\r\n res.sort((a,b)=>a-b);\r\n console.log(`${res.length} ${res.join(\" \")}`);\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar output = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(s[i] == \"1\"){\r\n\t\t\t\tfor(var j = N - 1; j >= i; j--){\r\n\t\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\t\toutput.push(i + 1);\r\n\t\t\t\t\t\toutput.push(j + 1);\r\n\t\t\t\t\t\ts[i] = \"-1\";\r\n\t\t\t\t\t\ts[j] = \"-1\";\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(output.length > 0){\r\n\t\t\tmyout(1);\r\n\t\t\toutput.sort(function(a,b){\r\n\t\t\t\treturn a - b;\r\n\t\t\t});\r\n\t\t\toutput.unshift(output.length);\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}else{\r\n\t\t\tmyout(0);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split('').map(Number);\n var b = lines[i].split('').map(Number).sort(function(a, b){return a - b});\n var c = '', d = '';\n for(j = 0; j < n; j++){\n c += a[j];\n d += b[j];\n }\n if(c == d){\n console.log(0);\n }else{\n var ans = '';\n console.log(1);\n var v = [];\n for(j = 0; j < n; j++){\n if(a[j] != b[j]){\n v.push(j + 1);\n }\n }\n ans += v.length + ' ';\n for(j = 0; j < v.length; j++){\n ans += v[j] + ' ';\n }\n console.log(ans);\n }\n }\n }\n});\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let c = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '0') c++\n }\n\n const ans = []\n for (let i = 0; i < str.length; i++) {\n if (i < c) {\n if (str[i] === '1') ans.push(i + 1)\n } else {\n if (str[i] === '0') ans.push(i + 1)\n }\n }\n if (!ans.length) return 0\n return `1\\n${ans.length} ${ans.join(' ')}`\n}\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var s = readline();\r\n var v = []\r\n var w = []\r\n var ans = [];\r\n var a = 0;\r\n var b = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (s[i] == '1') {\r\n b++;\r\n v.push(i);\r\n } else {\r\n a++;\r\n w.push(i);\r\n }\r\n }\r\n\r\n for (var i = 0; i < v.length; i++) {\r\n if (v[i] < n - b) {\r\n ans.push(v[i]);\r\n }\r\n }\r\n for (var i = 0; i < w.length; i++) {\r\n if (w[i] > a - 1) {\r\n ans.push(w[i]);\r\n }\r\n }\r\n\r\n if (ans.length == 0)\r\n return \"0\";\r\n else {\r\n ans.sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var val1 = \"1\\n\";\r\n var val2 = ans.length + \" \";\r\n for (var i = 0; i < ans.length; i++) {\r\n val2 += ans[i] + 1 + \" \"\r\n }\r\n return val1 + val2\r\n }\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}], "negative_code": [{"source_code": "const solve = (n,arr)=>{\r\n let r = [];\r\n for(let i=n-1;i>=0;i--){\r\n if(arr[i]===0){\r\n let j = 0,res=[],k=0;\r\n while((!arr[i])&& (i>j)){\r\n if(arr[j]){\r\n [arr[i],arr[j]] = [arr[j],arr[i]];\r\n res.push(i+1);\r\n res.push(j+1);\r\n i--;\r\n }\r\n j++;\r\n }\r\n if(res.length) {\r\n res.sort((a,b)=>a-b);\r\n r.push(`${res.length} ${res.join(\" \")}`);\r\n }\r\n }\r\n }\r\n if(r.length===0) console.log(0);\r\n else{\r\n console.log(r.length);\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar output = [];\r\n\t\twhile(true){\r\n\t\t\tvar zero = [];\r\n\t\t\tvar one = [];\r\n\t\t\tvar change = [];\r\n\t\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\t\tif(s[i] == \"0\" && one.length == 0){\r\n\t\t\t\t\tzero.unshift(i);\r\n\t\t\t\t\tchange.unshift(i);\r\n\t\t\t\t}else if(s[i] == \"1\" && zero.length > 0){\r\n\t\t\t\t\tone.unshift(i);\r\n\t\t\t\t\tchange.unshift(i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(zero.length > 0 && one.length > 0){\r\n\t\t\t\tvar size = change.length;\r\n\t\t\t\tfor(var i = 0; i < Math.floor(change.length / 2); i++){\r\n\t\t\t\t\tvar tmp = s[change[i]];\r\n\t\t\t\t\ts[change[i]] = s[change[change.length - 1 - i]];\r\n\t\t\t\t\ts[change[change.length - 1 - i]] = tmp;\r\n\t\t\t\t}\r\n\t\t\t\tfor(var i = 0; i < change.length; i++){\r\n\t\t\t\t\tchange[i]++;\r\n\t\t\t\t}\r\n\t\t\t\toutput.push(size + \" \" + myconv(change, 8));\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output.length);\r\n\t\tif(output.length > 0){\r\n\t\t\tmyout(myconv(output, 9));\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"}], "src_uid": "f472f9df8b4d588c67b39df6865507ca"} {"source_code": "const readNumber = () => +readline();\r\nconst readStr = () => readline();\r\n \r\nconst n = readNumber();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var m = readNumber();\r\n var str = readStr();\r\n var str2 = str.split('').sort().join('');\r\n var count = 0;\r\n\r\n for(var j = 0; j < m; j++) {\r\n if(str[j] !== str2[j]) {\r\n count++;\r\n }\r\n }\r\n \r\n print(count);\r\n}\r\n", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e =0\n\tfor(j = 1; j <= n * 2; j++){\n\t if(j % 2 == 1){\n\t e = lines[j]\n\t }else{\n var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0\n for(l = 0; l < e; l++){\n if(k[l] != a[l]){\n p++\n }\n }\n console.log(p)\n\t }\n }\n});"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split('').sort();\n var l = lines[i].split('');\n var ans = 0;\n for(j = 0; j < e; j++){\n if(k[j] != l[j]){\n ans++;\n }\n }\n console.log(ans);\n }\n\t}\n});\n\n"}, {"source_code": "// Input handling (Ctrl-D for EOF)\r\n\r\nconst readlineModule = require(\"readline\");\r\nconst rl = readlineModule.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst input = [];\r\nlet currLine = 0;\r\n\r\nrl.on(\"line\", line => {\r\n input.push(line);\r\n});\r\n\r\nrl.on(\"close\", () => {\r\n main();\r\n})\r\n\r\nfunction readline() {\r\n return input[currLine++];\r\n}\r\n\r\n// Main function\r\n\r\nfunction main() {\r\n const T = parseInt(readline());\r\n for (let i = 0; i < T; i++) {\r\n const N = parseInt(readline());\r\n const str = readline().split('');\r\n const sortedStr = str.slice();\r\n sortedStr.sort();\r\n let ans = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (str[j] !== sortedStr[j]) ans++;\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "const fs = require('fs');\r\n\r\nconst input = String(fs.readFileSync(0))\r\n .split('\\n')\r\n .filter(Boolean)\r\n .map((str) => str.trim());\r\n\r\nfor (let i = 2; i < input.length; i += 2) {\r\n const n = input[i];\r\n console.log(solve(n));\r\n}\r\n\r\nfunction solve(s) {\r\n const sor = s.split('').sort().join('');\r\n\r\n let k = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n if (sor[i] !== s[i]) {\r\n k += 1;\r\n }\r\n }\r\n\r\n return k;\r\n}"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", c => (i += c));\nprocess.stdin.on(\"end\", () => {\n\tconst { EOL } = require(\"os\");\n\tconst lines = i.split(EOL);\n\tsolve(lines);\n});\n\nfunction solve(lines) {\n t = +lines[0];\n for(let i = 0; i < t; i++) {\n let l = +lines[i * 2 + 1];\n let s = lines[i * 2 + 2];\n let sorted = s.split(\"\");\n sorted.sort();\n let k = 0;\n for(let j=0; j < l ;j++) {\n if(sorted[j] !== s.charAt(j)){\n k++;\n }\n }\n console.log(k);\n \n } \n\n}\n\n"}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0\n\tfor(j = 1; j <= n * 2; j++){\n\t if(j % 2 == 1){\n\t e = lines[j], ans = 0\n\t }else{\n\t var k = lines[j].split('')\n\t var a = lines[j].split('').sort()\n\t for(l = 0; l < e; l++){\n\t if(k[l] != a[l]){\n\t ans++\n\t }\n\t }\n\t console.log(ans)\n\t }\n\t}\n\n});//k[k.length - 1] == '' || "}], "negative_code": [{"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0\n\tfor(j = 1; j <= n * 2; j++){\n\t if(j % 2 == 1){\n\t e = lines[j], ans = 0\n\t }else{\n\t var k = lines[j].split('')\n\t var a = lines[j].split('').sort()\n\t for(l = 0; l < e; l++){\n\t if(k[l] == a[l]){\n\t ans++\n\t }\n\t }\n\t console.log(ans)\n\t }\n\t}\n\n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0\n\tfor(j = 1; j <= n * 2; j++){\n\t if(j % 2 == 1){\n\t e = lines[j], ans = 0\n\t }else{\n\t var k = lines[j].split('')\n\t var a = lines[j].split('').sort(function(a, b){\n\t return a - b\n\t })\n\t for(l = 0; l < e; l++){\n\t if(k[l] == a[l]){\n\t ans++\n\t }\n\t }\n\t console.log(ans)\n\t }\n\t}\n\n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e = 0\n\tfor(j = 1; j <= n; j++){\n\t if(j % 2 == 1){\n\t e = lines[j], ans = 0\n\t }else{\n\t var k = lines[j].split('')\n\t var a = lines[j].split('').sort(function(a, b){\n\t return a - b\n\t })\n\t for(l = 0; l < e; l++){\n\t if(k[l] == a[l]){\n\t ans++\n\t }\n\t }\n\t console.log(ans)\n\t }\n\t}\n\n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e =0\n\tfor(j = 1; j <= n * 2; j++){\n\t if(j % 2 == 1){\n\t e = lines[j]\n\t }else{\n var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0\n for(l = 0; l < e; l++){\n if(k[l] == a[l]){\n p++\n }\n }\n console.log(p)\n\t }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e =0\n\tfor(j = 1; j <= n; j++){\n\t if(j % 2 == 1){\n\t e = lines[j]\n\t }else{\n var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0\n for(l = 0; l < e; l++){\n if(k[l] == a[l]){\n p++\n }\n }\n console.log(p)\n\t }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n console.log(2 + \"/n\" + 6 + \"/n\" + 0 + \"/n\" + 4 + \"/n\")\n});"}], "src_uid": "58ee86d4913787582ccdb54073656dc0"} {"source_code": "var n = parseInt(readline());\nvar coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });\n\nvar min = Infinity;\nvar num_min = 1;\n\nfor(var i = 1; i < coordinates.length; i++) {\n \n var delta = Math.abs(coordinates[i] - coordinates[i - 1]);\n \n if(delta < min) {\n min = delta;\n num_min = 1;\n } else if(delta === min) {\n num_min++;\n }\n}\n\nprint(min + \" \" + num_min);", "positive_code": [{"source_code": "/*\n The idea to solve this problem is by thinking the city in linear line (sorted), thus each city will paired\n with city which has minimum distance with it.\n \n After that just find the minimum distance globally & count the occurence.\n*/\n\nvar n = parseInt(readline());\nvar coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });\n\nvar min = Infinity;\nvar num_min = 1;\n\nfor(var i = 1; i < coordinates.length; i++) {\n \n // get distance with previous city\n var delta = Math.abs(coordinates[i] - coordinates[i - 1]);\n \n // check minimum distance globally + count occurences\n if(delta === min) {\n num_min++;\n } else if(delta < min) {\n min = delta;\n num_min = 1;\n }\n}\n\nprint(min + \" \" + num_min);"}, {"source_code": "\"use strict\"\nif (typeof print === 'undefined') var print = console.log;\nif (typeof readline === 'undefined') {\n let lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n'), id = 0;\n var readline = () => lines[id++];\n}\n\nvar x = +readline();\nvar a = readline().split(' ').map(x => +x).sort((a, b) => a - b);\n\nvar ans = Infinity;\nvar cnt = 0;\n\nfor (var i = 0; ++i < x; ) {\n var diff = a[i] - a[i - 1];\n //console.warn(diff);\n if (diff > ans) continue;\n if (diff < ans) {\n ans = diff;\n cnt = 0;\n }\n if (diff == ans) ++cnt;\n}\n\nprint(ans + ' ' + cnt);\n\n"}, {"source_code": " var n = parseInt(readline());\n var d = readline().split(' ').map(function(x) {\n return parseInt(x);\n }).sort(function(a, b) {\n return a - b;\n });\n var dis = [];\n var mind = Infinity;\n for(var i = 1; i < n; i += 1) {\n if(dis[d[i] - d[i - 1]] === undefined) {\n dis[d[i] - d[i - 1]] = 1;\n } else {\n dis[d[i] - d[i - 1]] += 1;\n }\n mind = Math.min(mind, d[i] - d[i - 1]);\n }\n print([mind, dis[mind]].join(' '));"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(\" \");\n\ninput.sort(function(a, b) { return a - b; });\n\nvar counter = 1;\nvar min = input[1] - input[0];\n\nfor (var i = 1; i < input.length - 1; i++) {\n\n\tif (input[i + 1] - input[i] === min)\n\t\tcounter++;\n\n\tif (input[i + 1] - input[i] < min) {\n\t\tmin = input[i + 1] - input[i];\n\t\tcounter = 1;\n\t}\n\n}\n\nprint(min + \" \" + counter);\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });\n\nvar min = Infinity;\nvar num_min = 0;\n\nfor(var i = 1; i < coordinates.length; i++) {\n \n tmp_min = Math.min(min, Math.abs(coordinates[i] - coordinates[i - 1]));\n \n min === tmp_min ? num_min++ : num_min = 1;\n min = tmp_min;\n}\n\nprint(min + \" \" + num_min);"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(\" \");\n\ninput.sort();\n\nvar counter = 1;\nvar min = input[1] - input[0];\n\nfor (var i = 1; i < input.length - 1; i++) {\n\n\tif (input[i + 1] - input[i] === min)\n\t\tcounter++;\n\n\tif (input[i + 1] - input[i] < min) {\n\t\tmin = input[i + 1] - input[i];\n\t\tcounter = 1;\n\t}\n\n}\n\nprint(min + \" \" + counter);"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(\" \");\n\ninput.sort(function(a, b) { return a - b; });\nprint(input);\n\nvar counter = 1;\nvar min = input[1] - input[0];\n\nfor (var i = 1; i < input.length - 1; i++) {\n\n\tif (input[i + 1] - input[i] === min)\n\t\tcounter++;\n\n\tif (input[i + 1] - input[i] < min) {\n\t\tmin = input[i + 1] - input[i];\n\t\tcounter = 1;\n\t}\n\n}\n\nprint(min + \" \" + counter);\n"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(\" \");\n\ninput.sort();\n\nvar counter = 1;\nvar min = input[1] - input[0];\n\nfor (var i = 1; i < input.length - 1; i++) {\n\tif (input[i + 1] - input[i] < min) {\n\t\tmin = input[i + 1] - input[i];\n\t\tcounter = 1;\n\t}\n\n\tif (input[i + 1] - input[i] === min)\n\t\tcounter++;\n}\n\nprint(min + \" \" + counter);"}, {"source_code": "if (typeof print === 'undefined') print = console.log;\nif (typeof readline === 'undefined') readline = (function() {\n var lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var id = 0;\n return function() {return lines[id++];}\n})();\n\nvar x = +readline();\nvar a = readline().split(' ').map(function(x) { return +x; }).sort();\n\nvar ans = Infinity;\nvar cnt = 0;\n\nfor (var i = 0; ++i < x; ) {\n var diff = a[i] - a[i - 1];\n if (diff > ans) continue;\n if (diff < ans) {\n ans = diff;\n cnt = 0;\n }\n if (diff == ans) ++cnt;\n}\n\nprint(ans + ' ' + cnt);\n\n"}, {"source_code": "if (typeof print === 'undefined') print = console.log;\nif (typeof readline === 'undefined') readline = (function() {\n var lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var id = 0;\n return function() {return lines[id++];}\n})();\n\nvar x = +readline();\nvar a = readline().split(' ').map(function(x) { return +x; }).sort();\n\nvar ans = 1e10;\nvar cnt = 0;\n\nfor (var i = 0; ++i < x; ) {\n var diff = a[i] - a[i - 1];\n if (diff > ans) continue;\n if (diff < ans) ans = diff, cnt = 0;\n if (diff == ans) ++cnt;\n}\n\nprint(ans + ' ' + cnt);\n\n"}, {"source_code": "if (typeof print === 'undefined') print = console.log;\nif (typeof readline === 'undefined') readline = (function() {\n var lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var id = 0;\n return function() {return lines[id++];}\n})();\n\nvar x = +readline();\nvar a = readline().split(' ').map(function(x) { return +x; }).sort();\n\nvar ans = Infinity;\nvar cnt = 0;\n\nfor (var i = 0; ++i < x; ) {\n var diff = a[i] - a[i - 1];\n if (diff > ans) continue;\n if (diff < ans) ans = diff, cnt = 0;\n if (diff == ans) ++cnt;\n}\n\nprint(ans + ' ' + cnt);\n\n"}], "src_uid": "5f89678ae1deb1d9eaafaab55a64197f"} {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let n = read();\n let k = readInt();\n let d = n.length;\n function can(s) {\n used = new Array(10).fill(0);\n for (let i = 0; i < s.length; i++) {\n used[parseInt(s[i])] = 1;\n }\n let cnt = 0;\n for (let i = 0; i < 10; i++) {\n cnt += used[i];\n }\n if (k < cnt) {\n return 0;\n }\n let mx = 0;\n for (let i = 0; i < 10; i++) if (used[i]) {\n mx = Math.max(mx, i);\n }\n if (cnt < k) {\n mx = 9;\n }\n while (s.length < n.length) {\n s = s + mx;\n }\n return n <= s;\n }\n s = \"\";\n while (s.length < n.length) {\n let found = 0;\n for (let i = 0; i < 10; i++) {\n let s2 = s;\n s2 += i;\n if (can(s2)) {\n s = s2;\n found = 1;\n break;\n }\n }\n if (!found) {\n s = \"\";\n break;\n }\n }\n if (s != \"\") {\n console.log(s);\n }\n else {\n s = \"1\";\n for (let i = 0; i < n.length; i++) {\n s += \"0\";\n }\n console.log(s);\n }\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n", "positive_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d && ((i[o] = u), e(n, s, o + 1))) return !0\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n let t\r\n ;(i[o] = u + 1),\r\n (t =\r\n 1 & n || s > 1 || n & (1 << (u + 1))\r\n ? 0\r\n : revPow2[(n |= 1 << (u + 1)) & -n])\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n if (10 === a) return !1\r\n i[o] = a\r\n const l = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = l\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] === firstC) {\r\n continue;\r\n }\r\n if (n[i] < firstC) {\r\n write(('' + firstC).repeat(n.length));\r\n return ('' + firstC).repeat(n.length);\r\n }\r\n if (n[i] > firstC) {\r\n write(('' +(firstC + 1)).repeat(n.length));\r\n return ('' +(firstC + 1)).repeat(n.length);\r\n }\r\n } \r\n write(('' + firstC).repeat(n.length));\r\n return ('' + firstC).repeat(n.length);\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return n.join('');\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC === n[j] ? 0 : n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k < j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n return n.join('');\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst ASC0 = '0'.charCodeAt(0);\r\nlet k;\r\nlet n;\r\nlet ans;\r\nfunction ok(a) {\r\n const cnt = af(10).fill(0);\r\n let uniq = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n if (cnt[a[i]] == 0) {\r\n uniq++;\r\n if (uniq > k) {\r\n return false;\r\n }\r\n }\r\n cnt[a[i]]++;\r\n }\r\n return true;\r\n}\r\nfunction toI(a) {\r\n let rv = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n rv *= 10;\r\n rv += a[i];\r\n }\r\n return rv;\r\n}\r\nfunction ge(a, b) {\r\n check(a.length == b.length);\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] != b[i]) {\r\n return a[i] > b[i];\r\n }\r\n }\r\n return true;\r\n}\r\nfunction solve1() {\r\n for (let d = 9; d > 0; d--) {\r\n let t = af(n.length).fill(d);\r\n if (ge(t, n)) {\r\n ans = t;\r\n }\r\n }\r\n}\r\nfunction solve2(a, b) {\r\n for (let i = 0; i < n.length; i++) {\r\n if (n[i] < b) {\r\n let t = [...n]; // XXX flash card\r\n if (t[i] < a) {\r\n t[i] = a;\r\n }\r\n else {\r\n t[i] = b;\r\n }\r\n for (let j = i + 1; j < n.length; j++) {\r\n t[j] = a;\r\n }\r\n if (ge(ans, t)) {\r\n ans = t;\r\n }\r\n }\r\n if (n[i] != a && n[i] != b) { // end of usable prefix\r\n return;\r\n }\r\n }\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let s = nextStr();\r\n k = nextInt();\r\n n = af(s.length);\r\n for (let i = 0; i < s.length; i++) {\r\n n[i] = s.charCodeAt(i) - ASC0;\r\n }\r\n if (ok(n)) {\r\n printf(\"%d\\n\", toI(n));\r\n continue;\r\n }\r\n solve1();\r\n if (k > 1) {\r\n for (let a = 0; a < 10; a++) {\r\n for (let b = a + 1; b < 10; b++) {\r\n solve2(a, b);\r\n }\r\n }\r\n }\r\n printf(\"%j\\n\", toI(ans));\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\n// for (let i = 600000; i <= 633633; i++) {\n// if (solve(i, 2) === '633333') {\n// console.log(i)\n// }\n// }\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (!hmax) {\n p++\n }\n r.length = p + 1\n const uniq = r.filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n min = uniq ? 0 : min\n } else if (uniq) {\n r[p]++\n min = Math.min(...r)\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n // console.log(r, hmax, uniq)\n min = uniq ? 0 : min\n }\n for (let x = p + 1; x < s.length; x++) {\n r[x] = min\n }\n // } else {\n // const uniq = r.filter(x => x === r[p + 1]).length === 1\n // r[p + 1]++\n // if (k === 1) {\n // min = r[p + 1]\n // } else {\n // min = uniq ? 0 : Math.min(...r.slice(0, p + 2))\n // }\n // for (let x = p + 2; x < s.length; x++) {\n // r[x] = min\n // }\n // }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}], "negative_code": [{"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write(('' +(firstC + 1)).repeat(n.length));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC === n[j] ? 0 : n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k < j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write(('' +(firstC + 1)).repeat(n.length));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k < j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write(('' +(firstC + 1)).repeat(n.length));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k < j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k < j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = Math.min(firstC, secondC);\r\n }\r\n break;\r\n }\r\n if (firstC > n[i] && n[i] > secondC) {\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n if (firstC < n[i] && n[i] < secondC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] > firstC && firstC > secondC) {\r\n let k = i - 1;\r\n while(n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k === j) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = n[j];\r\n }\r\n break;\r\n }\r\n n[k++] = firstC;\r\n for (; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n let k = i - 1;\r\n while(n[k] !== firstC) {\r\n k--;\r\n }\r\n if (k === 0) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[k++] = secondC;\r\n for (; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] > firstC && n[i] > secondC) {\r\n if (firstC > secondC) {\r\n let k = i - 1;\r\n while (n[k] !== secondC) {\r\n k--;\r\n }\r\n if (k !== j) {\r\n n[k++] = firstC;\r\n for (;k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n }\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n n[i] = Math.min(firstC, secondC);\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = n[i];\r\n }\r\n break;\r\n }\r\n if (n[i] < secondC && n[i] >= firstC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n if (n[i] === secondC) {\r\n continue;\r\n }\r\n debugger;\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j + 1; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] > firstC && n[i] > secondC) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n n[i] = Math.min(firstC, secondC);\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < secondC && n[i] > firstC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[i] = firstC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = secondC;\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] > firstC && n[i] > secondC) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n n[i] = Math.min(firstC, secondC);\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < secondC && n[i] > firstC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n for (let i = j; i < n.length; i++) {\r\n if (n[i] === firstC || n[i] === secondC) {\r\n continue;\r\n }\r\n if (n[i] > firstC && n[i] > secondC) {\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n if (n[i] < firstC && n[i] < secondC) {\r\n n[i] = Math.min(firstC, secondC);\r\n continue;\r\n }\r\n if (n[i] < secondC && n[i] > firstC) {\r\n n[i] = secondC;\r\n for (let k = i + 1; k < n.length; k++) {\r\n n[k] = firstC;\r\n }\r\n break;\r\n }\r\n n[j]++;\r\n for (let k = j + 1; k < n.length; k++) {\r\n n[k] = Math.min(n[0], n[j]);\r\n }\r\n break;\r\n }\r\n write(n.join(''));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function solve() {\r\n const arr = read().split(' ');\r\n const n = arr[0].split('').map((x) => Number(x));\r\n const k = arr[1];\r\n if (k === '1') {\r\n const firstC = n[0];\r\n let isMoreFirst = false;\r\n for (let i = 1; i < n.length; i++) {\r\n if (n[i] > firstC) {\r\n isMoreFirst = true;\r\n }\r\n }\r\n if (isMoreFirst) {\r\n write((firstC + 1) + '0'.repeat(n.length - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(n.length));\r\n return;\r\n }\r\n const firstC = n[0];\r\n let j = 1;\r\n while(j < n.length && n[j] === firstC) {\r\n j++;\r\n }\r\n if (j === n.length) {\r\n write(n.join(''));\r\n return;\r\n }\r\n const secondC = n[j];\r\n let isMoreSecond = false;\r\n for (let i = j; i < n.length; i++) {\r\n if (n[i] > secondC) {\r\n isMoreSecond = true;\r\n }\r\n }\r\n if (isMoreSecond) {\r\n write(('' + firstC).repeat(j) + (secondC + 1) + ('' + Math.min(firstC, secondC + 1)).repeat(n.length - j - 1));\r\n return;\r\n }\r\n write(('' + firstC).repeat(j) + secondC + ('' + Math.min(secondC, firstC)).repeat(n.length - j - 1));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (!hmax) {\n p++\n }\n const uniq = r.slice(0, p + 1)\n .filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n min = uniq ? 0 : min\n } else if (uniq) {\n r[p]++\n min = Math.min(...r.slice(0, p + 1))\n } else {\n while (r.indexOf(r[p]) < 0) r[p]++\n min = uniq ? 0 : min\n }\n for (let x = p + 1; x < s.length; x++) {\n r[x] = min\n }\n // } else {\n // const uniq = r.filter(x => x === r[p + 1]).length === 1\n // r[p + 1]++\n // if (k === 1) {\n // min = r[p + 1]\n // } else {\n // min = uniq ? 0 : Math.min(...r.slice(0, p + 2))\n // }\n // for (let x = p + 2; x < s.length; x++) {\n // r[x] = min\n // }\n // }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (hmax) {\n const uniq = r.filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n min = uniq ? 0 : min\n } else if (uniq) {\n r[p]++\n min = Math.min(...r)\n } else {\n while (r.indexOf(r[p]) < 0) r[p]++\n min = uniq ? 0 : min\n }\n for (let x = p + 1; x < s.length; x++) {\n r[x] = min\n }\n } else {\n const uniq = r.filter(x => x === r[p + 1]).length === 1\n r[p + 1]++\n if (k === 1) {\n min = r[p + 1]\n } else {\n min = uniq ? 0 : Math.min(...r.slice(0, p + 2))\n }\n for (let x = p + 2; x < s.length; x++) {\n r[x] = min\n }\n }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (hmax) {\n const uniq = r.filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n min = uniq ? 0 : min\n } else if (uniq) {\n r[p]++\n min = Math.min(...r)\n } else {\n while (r.indexOf(r[p]) < 0) r[p]++\n min = uniq ? 0 : min\n }\n for (let x = p + 1; x < s.length; x++) {\n r[x] = min\n }\n } else {\n const uniq = r.filter(x => x === r[p + 1]).length === 1\n r[p + 1]++\n min = uniq ? 0 : Math.min(...r.slice(0, p + 2))\n for (let x = p + 2; x < s.length; x++) {\n r[x] = min\n }\n }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (hmax) {\n const uniq = r.filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[p]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n while (r.indexOf(r[p]) < 0) r[p]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n r[p + 1]++\n min = Math.min(...r.slice(0, p + 2))\n for (let x = p + 2; x < s.length; x++) {\n r[x] = min\n }\n }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let ds = first.map(x => x[0])\n const min = Math.min(...ds)\n const max = Math.max(...ds)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (ds.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else if (ds.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n\n const [a, j] = first.pop()\n r.push(...Array(s.length - r.length).fill(j === i - 1 ? 0 : min))\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (hmax) {\n const [a, j] = first[first.length - 1]\n if (j === i - 1) {\n first.pop()\n ds = first.map(x => x[0])\n // the last\n r[i - 1] = a + 1\n c = Math.min(a + 1, ...ds)\n r.push(...Array(s.length - r.length).fill(c))\n } else {\n // console.log(r, p, ds, r[p])\n r[p]++\n while (ds.indexOf(r[p]) < 0) r[p]++\n r.push(...Array(s.length - r.length).fill(min))\n }\n break\n }\n // x with the max first\n const [a, j] = first.pop()\n ds = first.map(x => x[0])\n r[j] = a + 1\n // first.push([a + 1, j])\n c = first.length ? Math.min(...ds) : a + 1\n for (let x = j + 1; x < s.length; x++) {\n r[x] = c\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n const ds = first.map(x => x[0])\n const min = Math.min(...ds)\n const max = Math.max(...ds)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (ds.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else if (ds.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n\n const [a, j] = first.pop()\n r.push(...Array(s.length - r.length).fill(j === i - 1 ? 0 : min))\n } else {\n // x with the max first\n const [a, j] = first.pop()\n r[j] = a + 1\n first.push([a + 1, j])\n c = first.length ? Math.min(...first.map(x => x[0])) : a + 1\n for (let x = j + 1; x < s.length; x++) {\n r[x] = c\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n const ds = first.map(x => x[0])\n const min = Math.min(...ds)\n const max = Math.max(...ds)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (ds.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else if (ds.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n // x with the max first\n const [a, j] = first.pop()\n r[j] = a + 1\n first.push([a + 1, j])\n c = first.length ? Math.min(...first.map(x => x[0])) : a + 1\n for (let x = j + 1; x < s.length; x++) {\n r[x] = c\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n if (k === 1) {\n let a = Array(s.length).fill(s[0]).join('')\n a = +a\n if (a >= n) {\n return a\n } else {\n a = Array(s.length).fill(+s[0] + 1).join('')\n return +a\n }\n } else {\n let a = s[0]\n let b = -1\n for (let i = 1; i < s.length; i++) {\n if (s[i] !== a) {\n b = s[i]\n break\n }\n }\n if (b < 0) return n\n\n const r = []\n for (let i = 0; i < s.length; i++) {\n if (s[i] !== a && s[i] !== b) {\n a = +a\n b = +b\n let min = Math.min(a, b)\n let max = Math.max(a, b)\n let c = +s[i]\n if (c <= min) {\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else if (c <= max) {\n r.push(max)\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else {\n let j = i - 1\n for (; j >= 0; j--) {\n // the last a\n if (+s[j] < max) {\n break\n }\n }\n let hasb = false\n for (let x = j; x >= 0; x--) {\n if (+s[x] == b) hasb = true\n }\n // console.log('hasb', hasb, c, r, j)\n if (hasb) {\n r[j] = max\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else {\n let firstb = false\n for (let x = 0; x < i; x++) {\n // the first b -> c\n if (!firstb && r[x] != a) {\n firstb = true\n r[x] = max + 1\n // console.log('firstb')\n } else {\n r[x] = a\n }\n }\n c = a\n r.push(...Array(s.length - r.length).fill(c))\n }\n }\n break\n } else {\n r.push(s[i])\n }\n }\n return r.join('')\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const s = String(n)\n if (k === 1) {\n let a = Array(s.length).fill(s[0]).join('')\n a = +a\n if (a >= n) {\n return a\n } else {\n a = Array(s.length).fill(+s[0] + 1).join('')\n return +a\n }\n } else {\n let a = s[0]\n let b = -1\n for (let i = 1; i < s.length; i++) {\n if (s[i] !== a) {\n b = s[i]\n break\n }\n }\n if (b < 0) return n\n\n const r = []\n for (let i = 0; i < s.length; i++) {\n if (s[i] !== a && s[i] !== b) {\n a = +a\n b = +b\n let min = Math.min(a, b)\n let max = Math.max(a, b)\n let c = +s[i]\n if (c <= min) {\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else if (c <= max) {\n r.push(max)\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else {\n let j = i - 1\n for (; j >= 0; j--) {\n // the last a\n if (+s[j] < max) {\n break\n }\n }\n let hasb = false\n for (let x = j; x >= 0; x--) {\n if (+s[x] == b) hasb = true\n }\n // console.log('hasb', hasb, c, r, j)\n if (hasb) {\n r[j] = max\n c = min\n r.push(...Array(s.length - r.length).fill(c))\n } else {\n let firstb = false\n for (let x = 0; x < i; x++) {\n // the first b -> c\n if (!firstb && r[x] != a) {\n firstb = true\n r[x] = c\n // console.log('firstb')\n } else {\n r[x] = a\n }\n }\n c = a\n r.push(...Array(s.length - r.length).fill(c))\n }\n }\n break\n } else {\n r.push(s[i])\n }\n }\n return r.join('')\n }\n}\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d && ((i[o] = u), e(n, s, o + 1))) return !0\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n i[o] = u + 1\r\n const t = 1 & (n |= 1 << (u + 1)) || s > 1 ? 0 : revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n if (0 === n || 9 === u) return !1\r\n if (n < 1 << u) return !1\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n i[o] = a\r\n const c = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = c\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d) return (i[o] = u), e(n, s, o + 1)\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n i[o] = u + 1\r\n const t = 1 & (n |= 1 << (u + 1)) || s > 1 ? 0 : revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n if (0 === n || 9 === u) return !1\r\n if (n < 1 << u) return !1\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n i[o] = a\r\n const c = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = c\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d) return (i[o] = u), e(n, s, o + 1)\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n i[o] = u + 1\r\n const t = 1 & (n |= 1 << (u + 1)) || s > 1 ? 0 : revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n if (0 === n) return !1\r\n if (n < 1 << u) return !1\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n i[o] = a\r\n const c = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = c\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d) return (i[o] = u), e(n, s, o + 1)\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n i[o] = u + 1\r\n const t = 1 & (n |= 1 << (u + 1)) || s > 1 ? 0 : revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n if (0 === n) return !1\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n if (10 === a) return !1\r\n i[o] = u + 1\r\n const c = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = c\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}], "src_uid": "9bd393bb8752a69016c5312750e8b507"} {"source_code": "var test = readline().split(' ')[0];\nvar ara = [];\nvar obj = {};\nwhile(test>0){\n\tvar x = readline();\n\tvar p = eval(x);\n\tp = Math.round(p*10000000000)/10000000000;\n\tif(obj.hasOwnProperty(p+\"\")){\n\t\tobj[p]+=1;\n\t}\n\telse{\n\t\tobj[p+\"\"]= 1;\n\t}\n\tara.push(p);\n\ttest--;\n}\nvar ans = \"\";\nfor(var i = 0 ; i{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t=t.replace(\"(\",\"\").replace(\")\",\"\").replace(\"/\",\"+\");let[e,r,n]=t.split(\"+\").map((t=>parseInt(t))),i=o.gcd(e+r,n);return`${(e+r)/i}/${n/i}`},r={},n=[];for(let o=0;or[t])).join(\" \"))}))},719:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),e.isPrime=e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)},e.isPrime=function(t){return!0}},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// numberTheory.ts\n\n// function gcd(a: number, b: number) {\n// if (b == 0) {\n// return a\n// }\n// \n// return gcd(b, a % b)\n// }\n// \n// function isPrime(x: number) {\n// return true\n// }\n// \n// export { gcd, isPrime }\n\n// import './array'\n// \n// import io from './io'\n// import { gcd } from './numberTheory'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let parse = (s: string) => {\n// s = s.replace(\"(\", \"\").replace(\")\", \"\").replace(\"/\", \"+\")\n// \n// let [a, b, c] = s.split(\"+\").map((x) => parseInt(x))\n// \n// let g = gcd(a + b, c)\n// \n// return `${(a + b) / g}/${c / g}`\n// }\n// \n// let cnt: any = {}\n// \n// let r: string[] = []\n// \n// for (let i = 0; i < n; ++i) {\n// let s = io.readline()\n// \n// let x = parse(s)\n// \n// cnt[x] = cnt[x] + 1 || 1\n// \n// r.push(x)\n// }\n// \n// io.put(r.map((x) => cnt[x]).join(\" \"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t=t.replace(\"(\",\"\").replace(\")\",\"\").replace(\"/\",\"+\");let[e,r,n]=t.split(\"+\").map((t=>parseInt(t)));return Math.floor((e+r)/n)},r={},n=[];for(let o=0;or[t])).join(\" \"))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let parse = (s: string) => {\n// s = s.replace(\"(\", \"\").replace(\")\", \"\").replace(\"/\", \"+\")\n// \n// let [a, b, c] = s.split(\"+\").map((x) => parseInt(x))\n// \n// return Math.floor((a + b) / c)\n// }\n// \n// let cnt: any = {}\n// \n// let r: number[] = []\n// \n// for (let i = 0; i < n; ++i) {\n// let s = io.readline()\n// \n// let x = parse(s)\n// \n// cnt[x] = cnt[x] + 1 || 1\n// \n// r.push(x)\n// }\n// \n// io.put(r.map((x) => cnt[x]).join(\" \"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "src_uid": "2d8092dd504d22bb5a8e48002cb8923b"} {"source_code": "function calc(n, r) {\n if (n === 6) {\n return r;\n } else {\n sinAlpha = Math.sin(Math.PI / n);\n return r * sinAlpha / (1 - sinAlpha);\n }\n}\n\nvar nr = readline().split(\" \");\nvar n = parseInt(nr[0]);\nvar r = parseInt(nr[1]);\n\nprint(calc(n, r));", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const [n, R] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const theta = Math.PI / n;\n const sinTheta = parseFloat(Math.sin(theta));\n const r = (R * sinTheta) / (1 - sinTheta);\n\n console.log(r.toFixed(7));\n}\n"}], "negative_code": [], "src_uid": "e27cff5d681217460d5238bf7ef6a876"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let [n, k] = $(2)\n let a = $(n).uniq()\n // log(a)\n if (k == 1) {\n if (a.length == 1) log(1);\n else log(-1)\n } else {\n log(For(1, 100, i => Math.ceil((a.length - 1) / i + 1) <= k ? i : null))\n }\n }\n}\n", "positive_code": [{"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n var v = {}\n for (var n = 0; n < x; n++)v[s[n]] = 1\n s = []\n for (n in v) s.push(n);\n if (s.length > 1 && y == 1) {\n print(-1);\n return;\n }\n var res = 1;\n var cur = 0;\n v = {};\n for (var n = 0; n < s.length; n++) {\n v[s[n]] = 1;\n if (Object.keys(v).length == y && n < s.length - 1) {\n res++;\n v = {};\n v[s[n]] = 1;\n }\n }\n print(res);\n}\nvar t = parseInt(readline());\nwhile (t--)\n solv()"}, {"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n var v = {}\n for (var n = 0; n < x; n++)v[s[n]] = 1\n s = []\n for (n in v) s.push(n);\n if (s.length > 1 && y == 1) {\n print(-1);\n return;\n }\n var res = 1;\n var cur = 0;\n v = {};\n for (var n = 0; n < s.length; n++) {\n v[s[n]] = 1;\n if (Object.keys(v).length == y && n < s.length - 1) {\n res++;\n v = {};\n v[s[n]] = 1;\n }\n }\n print(res);\n}\nvar t = parseInt(readline());\nwhile (t--)\n solv()"}, {"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number []} a\n * @param {Number} k\n * @returns {Number []}\n */\nfunction solve(a, k) {\n if (k < 1) {\n return -1;\n }\n const n = a.length;\n if (n < 1) {\n return -1;\n }\n const kinds = new Set();\n for (const ai of a) {\n kinds.add(ai);\n }\n const m = kinds.size;\n if (k === 1) {\n return (m !== 1) ? -1 : 1;\n }\n\n return (m === 1) ? 1 : Math.ceil((m - 1) / (k - 1));\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const [n, k] = (await getLine()).split(' ').map(Number);\n const a = (await getLine()).split(' ').map(Number);\n const res = solve(a, k);\n console.log(res);\n }\n}\n\nif (require.main === module) {\n main();\n}"}], "negative_code": [{"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n var v = {}\n for (var n = 0; n < x; n++)v[s[n]] = 1\n s = []\n for (n in v) s.push(n);\n if (s.length > 1 && y == 1) {\n print(-1);\n return;\n }\n var res = 1;\n var cur = 0;\n v = {};\n for (n in s) {\n v[n] = 1;\n if (Object.keys(v).length > y) {\n res++;\n v = {};\n }\n }\n print(res);\n}\nvar t = parseInt(readline());\nwhile (t--)\n solv()"}, {"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x));\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n var v = {}\n for (var n = 0; n < x; n++)v[s[n]] = 1\n s = []\n for (n in v) s.push(n);\n if (s.length > 1 && y == 1) {\n print(-1);\n return;\n }\n var res = 1;\n var cur = 0;\n v = {};\n for (n in s) {\n v[n] = 1;\n if (Object.keys(v).length > y) {\n res++;\n v = {};\n v[n] = 1;\n }\n }\n print(res);\n}\nvar t = parseInt(readline());\nwhile (t--)\n solv()"}], "src_uid": "3dc5850220458dec9876560150b612c4"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n output[i] = solve(n, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = 0\n }\n push(...args) {\n for (let i = 0; i < args.length; i++) {\n this.map[this.last++] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first >= this.last) return 0\n return this.last - this.first\n }\n get(x) {\n return this.map[x]\n }\n getLast() {\n return this.map[this.last - 1]\n }\n}\n\nfunction solve(n, edges) {\n const adj = {}\n const es = Array(n + 1)\n edges.forEach(([p, va, vb], i) => {\n let a = i + 2\n let b = p\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n es[a] = [va, vb]\n })\n return dfs(adj, 1, n, es).join(' ')\n}\nfunction dfs(adj, r, n, es) {\n // const stack = [[r, 0, -1]]\n const stack = new Queue()\n stack.push([r, 0, -1])\n const rs = Array(n).fill(0)\n // const sa = new Queue()\n // sa.push(0)\n let sa = 0\n const sb = new Queue()\n sb.push(0)\n while (stack.length) {\n const [u, i, p] = stack.getLast()\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n if (p >= 0) {\n sa += es[u][0]\n // sb += es[u][1]\n sb.push(sb.getLast() + es[u][1])\n rs[u] = binarySearch(0, sb.length - 1, x => {\n return sb.get(x) <= sa\n })\n }\n }\n if (i < nb.length) {\n stack.getLast()[1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n if (p >= 0) {\n sa -= es[u][0]\n // sb -= es[u][1]\n sb.pop()\n }\n }\n }\n rs.shift()\n rs.shift()\n return rs\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const h = new Array(n).fill(-1),\r\n te = [],\r\n ne = [],\r\n d = new Array(n).fill(0),\r\n b = [],\r\n c = [];\r\n const add = (i, j, x, y) => {\r\n b.push(x), c.push(y), te.push(j), ne.push(h[i]), h[i] = ne.length - 1, d[j]++;\r\n };\r\n for (let [i, [p, x, y]] of a.entries()) {\r\n add(p - 1, i + 1, x, y);\r\n }\r\n const res = [],\r\n pre = [0];\r\n const dfs = RTI((u, w, p = -1, sum = 0) => {\r\n if (p !== -1) {\r\n pre.push(pre[pre.length - 1] + w);\r\n let l = 0,\r\n r = pre.length - 1;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (pre[m] <= sum) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n res[u - 1] = l;\r\n }\r\n const inside = () => {\r\n let res = [];\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = te[i];\r\n if (p === v) continue;\r\n sum += b[i];\r\n res.push([v, c[i], u, sum]);\r\n sum -= b[i];\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n pre.pop();\r\n };\r\n return [inside, after];\r\n });\r\n dfs(0);\r\n return res.join(' ');\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push(await rns());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [], "src_uid": "8629aa74df60537987611c6c1ef1a140"} {"source_code": "'use strict'\n\nlet N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v))\n\nlet res = []\nlet c = 1\nfor (let i = 0; i < N; i++) {\n if (lll[i] == c) {c++; res.push(i + 2001)}\n}\n\nprint(res.length)\nif (res.length) print(res.join(' '))", "positive_code": [{"source_code": "\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n, indicator=0;\nrl.on('line', (input) => {\n if(indicator==0){\n n=parseInt(input);\n indicator++;\n }\n else{\n let cont=input.split(\" \").map(item=>parseInt(item));\n let ans=[];\n for(let i=0,year=2001,temp=1;i{\n rl.write(item+\" \");\n });\n */\n console.log(ans.join(\" \"));\n rl.close();\n\n }\n });"}, {"source_code": "var n = readline(); \nvar a = readline().split(' '); // a0..a(n-1); 2001..(2000+n)\nvar b = [];\nvar k = 1;\nvar i = 0;\nvar c = 0;\n\nfor(i=0; i {\n if(indicator==0){\n n=parseInt(input);\n indicator++;\n }\n else{\n let cont=input.split(\" \").map(item=>parseInt(item));\n let ans=[];\n for(let i=0,year=2001,temp=1;i{\n rl.write(item+\" \");\n });\n rl.close();\n\n }\n });"}, {"source_code": "\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n, indicator=0;\nrl.on('line', (input) => {\n if(indicator==0){\n n=parseInt(input);\n indicator++;\n }\n else{\n let cont=input.split(\" \").map(item=>parseInt(item));\n let ans=[];\n for(let i=0,year=2001,temp=1;i{\n rl.write(item+\" \");\n });\n rl.close();\n\n }\n });"}, {"source_code": "var n = readline(); \nvar a = readline().split(' '); // a0..a(n-1); 2001..(2000+n)\nvar b = [];\nvar k = 1;\nvar i = 0;\nvar c = 0;\n\nfor(i=0; i {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => BigInt(j)))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction sumS(n, count) {\r\n let res = 1n\r\n for (let j = 0n; j < count; ++j) res = (res * n) % 1000000007n\r\n return res\r\n}\r\n\r\nfunction solve([n, k]) {\r\n let dbl, sum = 0n, counter = 0n\r\n while ((2n ** counter) <= k) {\r\n dbl = (k >> counter) & 1n\r\n if (dbl) sum = (sum + sumS(n, counter)) % 1000000007n\r\n counter++\r\n }\r\n console.log(sum.toString())\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}", "positive_code": [{"source_code": "let mod = BigInt(10e8+7);\r\nconst solve = (n,k)=>{\r\n let n1 = k,cnt = 1n,res = 0n;\r\n while(n1){\r\n if(n1&1n){\r\n res = (res + cnt)%mod;\r\n }\r\n n1 = n1>>1n;\r\n cnt = (cnt*n)%mod;\r\n }\r\n console.log(res+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\nfunction solve(n, k) {\n const str = k.toString(2)\n let base = 1\n let sum = 0\n for (let i = str.length - 1; i >= 0; i--) {\n if (str[i] === '1') {\n sum = add(sum, base)\n }\n base = mul(base, n)\n }\n return sum\n}\nfunction add(a, b) {\n return (a + b) % (1e9 + 7)\n}\nfunction mul(a, b) {\n let r = 0\n let base = a\n while (b) {\n if (b & 1) {\n r = add(r, base)\n }\n b >>= 1\n base = add(base, base)\n }\n return r\n}\n"}], "negative_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction sumS(n, count) {\r\n let res = 1\r\n for (let j = 0; j < count; ++j) res = (res * n) % 1000000007\r\n return res\r\n}\r\n\r\nfunction solve([n, k]) {\r\n let dbl, sum = 0, counter = 0\r\n while ((2 ** counter) <= k) {\r\n dbl = (k >> counter) & 1\r\n if (dbl) sum = (sum + sumS(n, counter)) % 1000000007\r\n counter++\r\n }\r\n console.log(sum)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}], "src_uid": "2cc35227174e6a4d48e0839cba211724"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n % 2n !== 0n || n < 4n) return '-1';\r\n let min = 0n,\r\n max = 0n;\r\n for (let i = 0n; i < n; i++) {\r\n if ((n - 4n * i) % 6n === 0n) {\r\n min = i + (n - 4n * i) / 6n;\r\n break;\r\n }\r\n }\r\n for (let i = 0n; i < n; i++) {\r\n if ((n - 6n * i) % 4n === 0n) {\r\n max = i + (n - 6n * i) / 4n;\r\n break;\r\n }\r\n }\r\n return `${min.toString()} ${max.toString()}`;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = BigInt(await read());\r\n res.push(solve(n));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n let t = parseInt(ls[l++]);\r\n for (; t > 0; t--){\r\n const n = BigInt(ls[l++]);\r\n if (n % 2n == 1 || n < 4n){\r\n console.log(-1);\r\n continue;\r\n }\r\n\r\n let x = n % 6n == 0 ? n / 6n : n / 6n + 1n;\r\n let y = n / 4n;\r\n console.log(`${x} ${y}`);\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n`1 1`, // Test #1\n`-1`, // Test #2\n`4 6`, // Test #3\n`166374058999707392 249561088499561088`, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let n = readline();\n n = BigInt(n);\n LT({n});\n // PROCESSING:\n if (n % 2n != 0n){\n return -1;\n }\n n = n / 2n;\n let min, max;\n for (let x = 0n; x<=5n; x++){\n let m = n - x*2n;\n if (m>=0 && m%3n==0){\n min = x + m/3n;\n break;\n }\n }\n if (!min)\n return -1;\n for (let y = 0n; y<=5n; y++){\n let m = n - y*3n;\n if (m>=0 && m%2n==0){\n max = y + m/2n;\n break;\n }\n }\n if (!max)\n return -1;\n return [min.toString(), max.toString()]\n};\n "}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n\r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n\r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n }\r\n if (divisor === 6 && remainder > 0) {\r\n if (quotient.length < 2) {\r\n return Number(quotient.join(\"\")) + 1;\r\n }\r\n var carry = 1;\r\n var total =[];\r\n var sum;\r\n for (let j = quotient.length -1 ; j >= 0; j--) {\r\n sum = quotient[j] + carry;\r\n if (sum > 9 && j!==0) {\r\n total.unshift(0);\r\n } else {\r\n total.unshift(sum);\r\n carry = 0;\r\n }\r\n }\r\n return total.join(\"\");\r\n }\r\n return quotient.join(\"\");\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]);\r\n if (n[n.length - 1] % 2 !== 0) {\r\n console.log(-1);\r\n } else if (n.length < 2 && n[n.length - 1] < 4) {\r\n console.log(-1);\r\n } else {\r\n console.log(division(n, 6), division(n, 4));\r\n }\r\n}\r\n}"}, {"source_code": "const solve = (str)=>{\r\n let n = BigInt(str);\r\n let min = 6n;\r\n let max = 4n;\r\n if((n%2n===1n)||(n<3n)) return -1;\r\n let r1 = n%min,r2 = n%max;\r\n r1 = r1>0n ? (n/min)+1n : n/min;\r\n r2 = n/max;\r\n return `${r1} ${r2}`;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = readline();\r\n console.log(solve(n));\r\n }\r\n}\r\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = BigInt(lines[l++])\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n < 4n) return -1\n if (n & 1n) return -1\n const a = n / 4n\n const b = ceil(n, 6n)\n return b + ' ' + a\n}\nfunction ceil(a, b) {\n const r = a % b\n const f = a / b\n return r ? f + 1n : f\n}\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nconst maxBuses = (n) => {\n switch (n % 4n) {\n case 0n:\n return n / 4n;\n case 1n:\n return -1;\n case 2n:\n return n > 4n ? (n - 4n) / 4n + 1n : -1;\n case 3n:\n return -1;\n }\n};\nconst minBuses = (n) => {\n switch (n % 6n) {\n case 0n:\n return n / 6n;\n case 1n:\n return -1;\n case 2n:\n return n > 6n ? (n - 6n) / 6n + 2n : -1;\n case 3n:\n return -1;\n case 4n:\n return n > 6n ? n / 6n + 1n : -1;\n case 5n:\n return -1;\n }\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n const input = BigInt(line);\n const min = minBuses(input);\n const max = maxBuses(input);\n if (min === -1 && max === -1) {\n return console.log(\"-1\");\n } else if (min === -1 || max === -1) {\n const [common] = [min, max]\n .filter((x) => x !== -1)\n .map((x) => x.toString());\n return console.log(common, common);\n }\n console.log(min.toString(), max.toString());\n }\n lines++;\n});\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n\r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n\r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n }\r\n if (divisor === 6 && remainder > 0) {\r\n if (quotient.length < 2) {\r\n return 1;\r\n }\r\n var carry = 1;\r\n var total =[];\r\n var sum;\r\n for (let j = quotient.length -1 ; j >= 0; j--) {\r\n sum = quotient[j] + carry;\r\n if (sum > 9 && j!==0) {\r\n total.unshift(0);\r\n } else {\r\n total.unshift(sum);\r\n carry = 0;\r\n }\r\n }\r\n return total.join(\"\");\r\n }\r\n return quotient.join(\"\");\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]);\r\n if (n[n.length - 1] % 2 !== 0) {\r\n console.log(-1);\r\n } else if (n.length < 2 && n[n.length - 1] < 4) {\r\n console.log(-1);\r\n } else {\r\n console.log(division(n, 6), division(n, 4));\r\n }\r\n}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n\r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n\r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n }\r\n if (divisor === 6 && remainder > 0) {\r\n var carry = 1;\r\n var total =[];\r\n var sum;\r\n for (let j = quotient.length -1 ; j >= 0; j--) {\r\n sum = quotient[j] + carry;\r\n if (sum > 9 && j!==0) {\r\n total.unshift(0);\r\n } else {\r\n total.unshift(sum);\r\n carry = 0;\r\n }\r\n }\r\n return total.join(\"\");\r\n }\r\n return quotient.join(\"\");\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]);\r\n if (n[n.length - 1] % 2 !== 0) {\r\n console.log(-1);\r\n } else if (n.length < 2 && n[n.length - 1] < 4) {\r\n console.log(-1);\r\n } else {\r\n console.log(division(n, 6), division(n, 4));\r\n }\r\n}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n\r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n\r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n }\r\n if (divisor === 6 && remainder > 0) {\r\n return Number(quotient.join(\"\")) + 1;\r\n }\r\n return quotient.join(\"\");\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]);\r\n if (n[n.length - 1] % 2 !== 0) {\r\n console.log(-1);\r\n } else if (n.length < 2 && n[n.length - 1] < 4) {\r\n console.log(-1);\r\n } else {\r\n console.log(division(n, 6), division(n, 4))\r\n }\r\n}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n \r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n \r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n }\r\n if (divisor === 6 && remainder > 0) {\r\n return Number(quotient.join(\"\")) + 1;\r\n }\r\n return quotient.join(\"\");\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]);\r\n if (n[n.length - 1] % 2 !== 0) {\r\n console.log(-1);\r\n } else {\r\n console.log(division(n, 6), division(n, 4))\r\n }\r\n}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nvar testCase = parseInt(readline());\r\n\r\nfunction division(n, divisor) {\r\n var remainder;\r\n var dividend = n[0];\r\n var quotient = [];\r\n if (n.length < 2) {\r\n quotient.push(n[0] / divisor);\r\n return quotient.join(\"\");\r\n } else {\r\n for (let i = 0; i < n.length; i++) {\r\n if (dividend < divisor) {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend;\r\n dividend = (remainder * 10) + n[i + 1];\r\n } else {\r\n quotient.push(Math.floor(dividend / divisor));\r\n remainder = dividend % divisor;\r\n dividend = (remainder * 10) + n[i + 1];\r\n }\r\n }\r\n }\r\n if (quotient[0] === 0) {\r\n quotient.shift();\r\n return quotient.join(\"\");\r\n }else{\r\n return quotient.join(\"\");\r\n }\r\n}\r\n\r\nfor (let i = 0; i < testCase; i++) {\r\n var n = readline().trim().split('').map(Number);\r\n var result;\r\n var sum = 0;\r\n for (let i = 0; i < n.length; i++) {\r\n sum += n[i];\r\n }\r\n var divisiblebyfour = n.length < 2 ? n[n.length - 1] : ((n[n.length - 2] * 10) + n[n.length - 1]) ;\r\n if ((divisiblebyfour % 4 !== 0) && !(sum % 3 === 0 && n[n.length - 1] % 2 === 0)) {\r\n console.log(-1);\r\n }else if ((divisiblebyfour % 4 === 0) && !(sum % 3 === 0 && n[n.length - 1] % 2 === 0)) {\r\n result = division(n, 4);\r\n console.log(result, result);\r\n }else if ((divisiblebyfour % 4 !== 0) && (sum % 3 === 0 && n[n.length - 1] % 2 === 0)) {\r\n result = division(n, 6);\r\n console.log(result, result);\r\n }else if((divisiblebyfour % 4 === 0) && (sum % 3 === 0 && n[n.length - 1] % 2 === 0)){\r\n console.log(division(n, 6), division(n, 4));\r\n }\r\n}\r\n}"}, {"source_code": "const solve = (str)=>{\r\n let n = BigInt(str);\r\n let min = 6n;\r\n let max = 4n;\r\n if(n%2n===1n) return -1;\r\n let r1 = n%min,r2 = n%max;\r\n r1 = r1>0n ? (n/min)+1n : n/min;\r\n r2 = n/max;\r\n return `${r1} ${r2}`;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = readline();\r\n console.log(solve(n));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (str)=>{\r\n let n = BigInt(str);\r\n let min = BigInt(6);\r\n let max = BigInt(4);\r\n if(n%min===BigInt(0)) min = n/min;\r\n else min = 1;\r\n if(n%max===BigInt(0)) max = n/max;\r\n else max = 1;\r\n if(min===max) return -1;\r\n else return `${min} ${max}`;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = readline();\r\n console.log(solve(n));\r\n }\r\n}\r\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = BigInt(lines[l++])\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n & 1n) return -1\n const a = n / 4n\n const b = ceil(n, 6n)\n return b + ' ' + a\n}\nfunction ceil(a, b) {\n const r = a % b\n const f = a / b\n return r ? f + 1n : f\n}\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nconst maxBuses = (n) => {\n switch (n % 4n) {\n case 0n:\n return n / 4n;\n case 1n:\n return -1;\n case 2n:\n return (n - 4n) / 4n + 1n;\n case 3n:\n return -1;\n }\n};\nconst minBuses = (n) => {\n switch (n % 6n) {\n case 0n:\n return n / 6n;\n case 1n:\n return -1;\n case 2n:\n return (n - 6n) / 6n + 2n;\n case 3n:\n return -1;\n case 4n:\n return n / 6n + 1n;\n case 5n:\n return -1;\n }\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n const input = BigInt(line);\n const min = minBuses(input);\n const max = maxBuses(input);\n if (min === -1 && max === -1) {\n return console.log(\"-1\");\n }\n console.log(min.toString(), max.toString());\n }\n lines++;\n});\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n % 2n !== 0n) return '-1';\r\n let min = 0n,\r\n max = 0n;\r\n for (let i = 0n; i < n; i++) {\r\n if ((n - 4n * i) % 6n === 0n) {\r\n min = i + (n - 4n * i) / 6n;\r\n break;\r\n }\r\n }\r\n for (let i = 0n; i < n; i++) {\r\n if ((n - 6n * i) % 4n === 0n) {\r\n max = i + (n - 6n * i) / 4n;\r\n break;\r\n }\r\n }\r\n return `${min.toString()} ${max.toString()}`;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = BigInt(await read());\r\n res.push(solve(n));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n let t = parseInt(ls[l++]);\r\n for (; t > 0; t--){\r\n const n = parseInt(ls[l++]);\r\n if (n % 2 == 1 || n < 4){\r\n console.log(-1);\r\n continue;\r\n }\r\n\r\n let x = n % 6 == 0 ? n / 6 : Math.floor(n / 6) + 1;\r\n let y = Math.floor(n / 4);\r\n console.log(`${x} ${y}`);\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}], "src_uid": "1cc628b4e03c8b8e0c5086dc4e0e3254"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) console.log(0);\r\n else {\r\n let ans = [],\r\n prev = 0 ^ arr[0];\r\n ans.push(0);\r\n for (let i = 1; i < n; i++) {\r\n let p1 = new Array(30).fill(0);\r\n let p2 = new Array(30).fill(0);\r\n let j = arr[i],\r\n k = 0,\r\n l = prev;\r\n while (j > 0) {\r\n if (j & 1) p1[k] = 1;\r\n j = j >> 1;\r\n k++;\r\n }\r\n k = 0;\r\n while (l > 0) {\r\n if (l & 1) p2[k] = 1;\r\n l = l >> 1;\r\n k++;\r\n }\r\n let res = 0;\r\n for (let j = 0; j < 30; j++) {\r\n if (p2[j] === 1 && p1[j] === 0) res += 1 << j;\r\n }\r\n ans.push(res);\r\n prev = res ^ arr[i];\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let numbers = +input[z++];\r\n let arr = input[z++].split(' ').map(Number);\r\n let binaryArr = [];\r\n let resultArr = [];\r\n \r\n arr.forEach(element => {\r\n binaryArr.push(element.toString(2));\r\n });\r\n let newBinaryarr = [];\r\n newBinaryarr.push(binaryArr[0])\r\n for (let i = 0; i < binaryArr.length; i++) {\r\n if(i === 0){\r\n resultArr.push(0);\r\n }\r\n else{\r\n let temp1 = newBinaryarr[i-1].toString().length;\r\n let temp2 = binaryArr[i].toString().length;\r\n if(temp1 > temp2){\r\n binaryArr[i] = '0'.repeat(temp1 - temp2) + binaryArr[i];\r\n }\r\n else{\r\n newBinaryarr[i-1] = '0'.repeat(temp2 - temp1) + newBinaryarr[i - 1];\r\n }\r\n let max = Math.max(temp1, temp2);\r\n let pow = 0;\r\n let total = 0;\r\n \r\n for (let j = max - 1; j >= 0; j--) {\r\n if(newBinaryarr[i-1][j] == 1 && binaryArr[i][j] != 1){\r\n total += Math.pow(2, pow);\r\n pow++;\r\n }\r\n else{\r\n pow++;\r\n }\r\n }\r\n newBinaryarr.push((total + arr[i]).toString(2));\r\n resultArr.push(total);\r\n }\r\n }\r\n console.log(resultArr.join(' '));\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst x = rna();\r\n\r\n\t\tconst ans = [0];\r\n\t\tfor (let i = 1, prev = x[0]; i < n; i++) {\r\n\t\t\tans[i] = ~x[i] & prev;\r\n\t\t\tprev = x[i] ^ ans[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let maxlen = 0;\r\n const x = readArray((x) => {\r\n const binx = decToBin(Number(x));\r\n if (binx.length > maxlen) {\r\n maxlen = binx.length;\r\n }\r\n return binx;\r\n });\r\n const ans = [[0]];\r\n const a = [x[0]];\r\n for (let i = 1; i < n; i++) {\r\n ans.push([]);\r\n a.push([]);\r\n for (let j = maxlen - 1; j >= 0; j--) {\r\n ans[i][j] = a[i - 1][j] && !x[i][j] ? 1 : 0;\r\n a[i][j] = (x[i][j] ^ ans[i][j]);\r\n }\r\n }\r\n write(ans.map(binToDec).join(' '));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(arr))\n }\n});\n\nfunction solve(arr) {\n let prev\n return arr.map((x, idx) => {\n if (idx) {\n let mask = 1\n let r = 0\n let next = 0\n for (let i = 0; i < 31; i++) {\n if (prev & mask) {\n if (!(x & mask)) {\n r |= mask\n }\n } else {\n // prefer 0 in r\n }\n next |= ((r & mask) ^ (x & mask))\n mask += mask\n }\n prev = next\n return r\n } else {\n prev = x\n return 0\n }\n }).join(' ')\n}\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const t = input.number();\r\n const ans = Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = input.number();\r\n const X = input.numbers(n);\r\n const Y = Array(n);\r\n let prev = 0;\r\n for (let j = 0; j < n; j++) {\r\n if ((prev & X[j]) === prev) {\r\n Y[j] = 0;\r\n prev = X[j];\r\n }\r\n else {\r\n const tmp = prev | X[j];\r\n Y[j] = tmp ^ X[j];\r\n prev = tmp;\r\n }\r\n }\r\n ans[i] = Y;\r\n }\r\n console.log(ans.map((Y) => Y.join(' ')).join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}], "negative_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let numbers = +input[z++];\r\n let arr = input[z++].split(' ').map(Number);\r\n let binaryArr = [];\r\n let resultArr = [];\r\n \r\n arr.forEach(element => {\r\n binaryArr.push(convertToBinary(element))});\r\n \r\n function convertToBinary(element){\r\n let bin = 0;\r\n let rem, i = 1, step = 1;\r\n while (element != 0) {\r\n rem = element % 2;\r\n element = parseInt(element / 2);\r\n bin = bin + rem * i;\r\n i = i * 10;\r\n }\r\n return bin.toString();\r\n };\r\n \r\n let newBinaryarr = [];\r\n newBinaryarr.push(binaryArr[0])\r\n for (let i = 0; i < binaryArr.length; i++) {\r\n if(i === 0){\r\n resultArr.push(0);\r\n }\r\n else{\r\n let temp1 = newBinaryarr[i-1].toString().length;\r\n let temp2 = binaryArr[i].toString().length;\r\n if(temp1 > temp2){\r\n binaryArr[i] = '0'.repeat(temp1 - temp2) + binaryArr[i];\r\n }\r\n else{\r\n newBinaryarr[i-1] = '0'.repeat(temp2 - temp1) + newBinaryarr[i - 1];\r\n }\r\n let max = Math.max(temp1, temp2);\r\n let pow = 0;\r\n let total = 0;\r\n \r\n for (let j = max - 1; j >= 0; j--) {\r\n if(newBinaryarr[i-1][j] == 1 && binaryArr[i][j] != 1){\r\n total += Math.pow(2, pow);\r\n pow++;\r\n }\r\n else{\r\n pow++;\r\n }\r\n }\r\n newBinaryarr.push((total + arr[i]).toString(2));\r\n resultArr.push(total);\r\n }\r\n }\r\n console.log(...resultArr);\r\n }\r\n}"}], "src_uid": "8d25700c9996a80fea3557222273c89a"} {"source_code": "// ################## //\n// 11th October 2019. //\n// ################## //\n\n// ####################################################################### //\n// Letters of the english alphabet.\nconst letters = 'abcdefghijklmnopqrstuvwxyz';\n// Method to generate bitmasks indicating presence of letters.\nfunction generateBitmaskFor(word){\n var bitmask = '';\n for(var x = 0;x {\n return Math.abs(Math.sqrt((x1 - y1)**2 + (x2 - y2) ** 2));\n}\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [a, b] = d.split(' ').map(Number);\n return;\n }\n\n if (c === 1) {\n c++;\n return;\n }\n\n const [x, y, v] = d.split(' ').map(Number);\n ans = Math.min(ans, distance(a, b, x, y) / v);\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans.toFixed(6));\n});\n"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar a = input[0], b = input[1];\nvar n = +readline();\nvar res = Infinity;\nfor (var i = 0; i < n; i++) {\n input = readline().split(' ').map(Number);\n var x = input[0], y = input[1], v = input[2];\n res = Math.min(Math.sqrt(Math.pow(a-x, 2) + Math.pow(b-y, 2)) / v, res)\n}\nprint(res);"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar a = input[0], b = input[1];\nvar n = Number(readline());\nvar res = 10000000;\nfor (var i = 0; i < n; i++) {\n input = readline().split(' ').map(Number);\n var x = input[0], y = input[1], v = input[2];\n res = Math.min(Math.sqrt(Math.pow(a-x, 2) + Math.pow(b-y, 2)) / v, res)\n}\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar tArr = [];\n\nvar _readline$split$map = readline().split(' ').map(Number);\n\nvar _readline$split$map2 = _slicedToArray(_readline$split$map, 2);\n\nvar a = _readline$split$map2[0];\nvar b = _readline$split$map2[1];\n\nvar n = Number(readline());\nfor (var i = 0; i < n; i++) {\n var _readline$split$map3 = readline().split(' ').map(Number);\n\n var _readline$split$map4 = _slicedToArray(_readline$split$map3, 3);\n\n var x = _readline$split$map4[0];\n var y = _readline$split$map4[1];\n var v = _readline$split$map4[2];\n\n tArr.push(Math.sqrt(Math.pow(x - a, 2) + Math.pow(y - b, 2)) / v);\n}\nprint(Math.min.apply(Math, tArr));\n"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split$map = readline().split(' ').map(Number);\n\nvar _readline$split$map2 = _slicedToArray(_readline$split$map, 2);\n\nvar a = _readline$split$map2[0];\nvar b = _readline$split$map2[1];\n\nvar n = Number(readline());\nvar minTime = 100000;\nfor (var i = 0; i < n; i++) {\n\tvar _readline$split$map3 = readline().split(' ').map(Number);\n\n\tvar _readline$split$map4 = _slicedToArray(_readline$split$map3, 3);\n\n\tvar x = _readline$split$map4[0];\n\tvar y = _readline$split$map4[1];\n\tvar v = _readline$split$map4[2];\n\n\tvar dist = Math.sqrt((x - a) * (x - a) + (y - b) * (y - b));\n\tvar time = dist / v;\n\tif (minTime > time) {\n\t\tminTime = time;\n\t}\n}\nprint(minTime);\n"}, {"source_code": "var input = readline().split(\" \").map(i => +i);\nvar a = input[0];\nvar b = input[1];\nvar n = +readline();\nvar minTime;\n\nvar distance = function(x1, y1, x2, y2) {\n return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));\n};\n\nfor (var i = 0; i < n; ++i) {\n input = readline().split(\" \").map(i => +i);\n var xi = input[0];\n var yi = input[1];\n var vi = input[2];\n var time = distance(xi, yi, a, b) / vi;\n if ( typeof minTime === \"undefined\" || time < minTime) {\n minTime = time;\n }\n}\n\nprint(minTime);"}], "negative_code": [{"source_code": "var input = readline().split(\" \").map(i => +i);\nvar a = input[0];\nvar b = input[1];\nvar n = +readline();\nvar minTime;\n\nvar distance = function(x1, y1, x2, y2) {\n return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));\n};\n\nfor (var i = 0; i < n; ++i) {\n input = readline().split(\" \").map(i => +i);\n var xi = input[0];\n var yi = input[1];\n var vi = input[2];\n var time = distance(xi, yi, a, b) / vi;\n if ( !minTime || time < minTime) {\n minTime = time;\n }\n}\n\nprint(minTime);"}], "src_uid": "a74c65acd41ff9bb845062222135c60a"} {"source_code": "var g = readline().split(\" \");\nvar m = Number(g[1]);\nvar n = Number(g[0]);\n\nvar print_dots = [];\n\nvar input_dots = [];\n\n\nfor(i=0;i= l && dott <= r){\n dott_flag =false;\n break;\n }\n }\n\n if(dott_flag)\n print_dots.push(dott);\n}\n\nprint(print_dots.length);\nprint(print_dots.join(\" \"));\n", "positive_code": [{"source_code": "var a = readline().split(' ');\nvar arr = [],result = [];\nfor(var i = 0;i arr[j][1]){\n k++;\n }\n }\n if(k == a[0]) result.push(i);\n}\nprint(result.length);\nresult.forEach(function(v){\n print( v + ' ');\n});"}, {"source_code": "var input = readline();\nvar items = input.split(' ');\n\nvar lines = items[0];\nvar top1 = items[1];\n\nvar inputs = [];\nvar y = [];\nfor (var i = 1; i <= lines; i++ ){\n inputs = readline().split(' ');\n\n for (var j = +inputs[0]; j <= +inputs[1]; j++ ) {\n if (y.indexOf(j) === -1) {\n y.push(j);\n }\n }\n}\n\nprint(top1 - y.length);\n\nfor (var i = 1; i <= top1; i++) {\n if (y.indexOf(i) === -1) {\n write(i + ' ');\n }\n}"}, {"source_code": "function calculateProb(str1, str2) {\n var ob = {};\n var rez = [];\n var last = '';\n\n\n for (var k = 1; k <= str2; k++) {\n var flg = true;\n\n for (var i = 0; i < str1.length; i++) {\n if (!(k < parseInt(str1[i][0]) || k > parseInt(str1[i][1]))) {\n flg = false;\n }\n }\n\n if (flg) rez.push(k);\n }\n\n print(rez.length);\n print(rez.join(\" \"));\n}\n\nvar s = [];\nvar s1 = readline().split(' ');\n\nvar num = parseInt(s1[0]);\nvar num2 = parseInt(s1[1]);\n\nfor (var i = 0; i < num; i++) {\n s.push(readline().split(' '));\n}\n\ncalculateProb(s, num2);\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const line = new Array(m).fill(true);\n let u, v;\n for (let i = 0; i < n; i += 1) {\n [u, v] = is.nextArray(Number);\n u -= 1; v -= 1;\n while (u <= v) {\n line[u] = false;\n u += 1;\n }\n }\n\n const segments = [];\n line.forEach((item, index) => {\n if (item) {\n segments.push(index + 1);\n }\n });\n\n console.log(segments.length);\n if (segments.length) {\n console.log(segments.join(' '));\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n const [n,m] = readInts(input, ptr++)\n const arr = new Array(n)\n for(let i = 0; i < n; i++) {\n arr[i] = readInts(input, ptr++)\n }\n\n arr.sort((a, b) => {\n if(a[0] === b[0]) return a[1] - b[1]\n else return a[0] - b[0]\n })\n let ans = []\n let last = 0\n // console.log(arr)\n arr.forEach(e => {\n if(last < e[0]) {\n let t = last + 1\n while(t < e[0]) {\n ans.push(t)\n t++\n }\n }\n if(last < e[1]) last = e[1]\n })\n if(last < m) {\n let t = last + 1\n while(t <= m) {\n ans.push(t)\n t++\n }\n }\n\n wr(ans.length)\n if(ans.length !== 0) wr(ans.join(' '))\n else console.log()\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar M = one[1];\n\tvar used = new Array(M + 1).fill(0);\n\tfor(var i = 0; i < N; i++){\n\t\tvar tmp = nextIntArray();\n\t\tfor(var j = tmp[0]; j <= tmp[1]; j++){\n\t\t\tused[j]++;\n\t\t}\n\t}\n\tvar output = [];\n\tfor(var i = 1; i <= M; i++){\n\t\tif(used[i] == 0){\n\t\t\toutput.push(i);\n\t\t}\n\t}\n\tmyout(output.length);\n\tmyout(myconv(output, 8));\n}\n"}, {"source_code": "function main() {\n [n, m] = readInts()\n st = new Set()\n for (i=1; i<=m; i++) st.add(i)\n for (i=0; i inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet segment;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n segment = new Array(m + 1).fill(1);\n c++;\n return;\n }\n\n let [l, r] = d.split(' ').map(Number);\n\n while (l <= r) {\n segment[l] = 0;\n l++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n let k = segment.reduce((a, x) => a + x, 0);\n const ans = [];\n console.log(k - 1);\n\n if (k) {\n for (let i = 1; i < segment.length; i++) {\n if (segment[i] === 1) {\n ans.push(i);\n }\n }\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let {0:n, 1:m} = {...input[0].split(' ')};\n n = parseInt(n); m = parseInt(m);\n\n let answer = [];\n for(let i = 0; i < m; i++)\n answer[i] = 0;\n //console.log(`n = ${n}; m = ${m};`);\n for(let i = 0; i < n; i++){\n let pair = []; input[i+1].split(' ').forEach(j => pair.push(parseInt(j)));\n \n for(let j = pair[0]; j <= pair[1]; j++){\n answer[j-1] = 1;\n }\n }\n\n let cnt = 0;\n let answer_string = '';\n for(let i = 0; i < m; i++){\n if(answer[i] == 0){\n answer_string += `${i+1} `; cnt++;\n }\n \n }\n console.log(cnt);\n if (cnt > 0)\n console.log(answer_string);\n});\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction inp() {\n return inputString[currentLine++];\n}\n \nfunction out(str) {\n console.log(str);\n}\n \nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\nfunction main() {\n let n1= stringArrayToNumbers(inp())\n let n, m, i, j, l, r;\n \n n = n1[0];\n m = n1[1];\n var arr= []\n for (i = 1; i<=m; i++)\n {\n arr.push(0)\n }\n for(i=1; i<=n; i++) {\n let inputs = inp();\n inputs = inputs.split(' ');\n l = parseInt(inputs[0], 10);\n r = parseInt(inputs[1], 10);\n for (j=l-1; jarr[j][1]){\n k++;\n }\n }\n if(k == a[0]) result.push(i);\n}\nprint(result.length);\nresult.forEach(function(v){\n print( v + ' ');\n});"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const line = new Array(m).fill(true);\n let u, v;\n for (let i = 0; i < n; i += 1) {\n [u, v] = is.nextArray(Number);\n u -= 1; v -= 1;\n while (u <= v) {\n line[u] = false;\n u += 1;\n }\n }\n\n const segments = [];\n line.forEach((item, index) => {\n if (item) {\n segments.push(index);\n }\n });\n\n console.log(segments.length);\n if (segments.length) {\n console.log(segments.join(' '));\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const line = new Array(m + 2).fill(true);\n let u, v;\n for (let i = 0; i < n; i += 1) {\n [u, v] = is.nextArray(Number);\n while (u <= v) {\n line[u] = false;\n u += 1;\n }\n }\n\n const segments = [];\n let flag = false;\n let numSegments = 0;\n line[m + 1] = false;\n for (let i = 1; i < line.length; i += 1) {\n switch (true) { // eslint-disable-line\n case line[i]:\n if (!flag) {\n flag = true;\n u = i;\n }\n if (i <= m)\n numSegments += 1;\n break;\n case flag:\n v = i - 1;\n flag = false;\n segments.push([u, v]);\n break;\n }\n }\n\n console.log(numSegments);\n if (segments.length) {\n segments.forEach((item) => {\n console.log(item[0], item[1]);\n });\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n const [n,m] = readInts(input, ptr++)\n const arr = new Array(n)\n for(let i = 0; i < n; i++) {\n arr[i] = readInts(input, ptr++)\n }\n\n arr.sort((a, b) => {\n if(a[0] === b[0]) return a[1] - b[1]\n else return a[0] - b[0]\n })\n let ans = []\n let last = 0\n arr.forEach(e => {\n if(last < e[0]) {\n let t = last + 1\n while(t < e[0]) {\n ans.push(t)\n t++\n }\n }\n if(last < e[1]) last = e[1]\n })\n\n wr(ans.length)\n if(ans.length !== 0) wr(ans.join(' '))\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n const [n,m] = readInts(input, ptr++)\n const arr = new Array(n)\n for(let i = 0; i < n; i++) {\n arr[i] = readInts(input, ptr++)\n }\n\n arr.sort((a, b) => {\n if(a[0] === b[0]) return a[1] - b[1]\n else return a[0] - b[0]\n })\n let ans = []\n let last = 0\n arr.forEach(e => {\n if(last < e[0]) {\n let t = last + 1\n while(t < e[0]) {\n ans.push(t)\n t++\n }\n }\n last = e[1]\n })\n\n wr(ans.length)\n if(ans.length !== 0) wr(ans.join(' '))\n}"}], "src_uid": "f336b622fdaf5960032268641320bb53"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tconst used = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tconst [a, b, c] = rna();\r\n\t\t\tused[b] = 1;\r\n\t\t}\r\n\r\n\t\tlet root;\r\n\t\tfor (let i = 1; i <= n; i++) if (!used[i]) root = i;\r\n\r\n\t\tfor (let i = 1; i <= n; i++) if (i != root) console.log(i, root);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res,\r\n obj = {};\r\n for (let i = 0; i < k; i++) obj[node[i][1]] = 1;\r\n for (let i = 1; i <= n; i++) {\r\n if (!obj[i]) {\r\n res = i;\r\n break;\r\n }\r\n }\r\n for (let i = 1; i <= n; i++) {\r\n if (i !== res) {\r\n console.log(`${res} ${i}`);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res = [],\r\n obj = {};\r\n const push = (n1, n2) => {\r\n if (!obj[n1]) {\r\n res.push(n1);\r\n obj[n1] = 1;\r\n }\r\n if (!obj[n2]) {\r\n res.push(n2);\r\n obj[n2] = 1;\r\n }\r\n };\r\n for (let i = 0; i < k; i++) {\r\n push(node[i][0], node[i][2]);\r\n }\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][1]]) res.push(node[i][1]);\r\n }\r\n for (let i = 0; i < n - 1; i++) {\r\n console.log(res[i] + \" \" + res[i + 1]);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res = [],\r\n obj = {},\r\n start = node[0][0];\r\n obj[node[0][0]] = 1;\r\n obj[node[0][2]] = 1;\r\n res.push([node[0][0], node[0][2]]);\r\n for (let i = 1; i < k; i++) {\r\n if (!obj[node[i][0]] || !obj[node[i][2]]) {\r\n res.push([node[i][0], node[i][2]]);\r\n if (!obj[node[i][0]] && !obj[node[i][2]]) {\r\n res.push([node[i][0], node[i - 1][2]]);\r\n }\r\n obj[node[i][0]] = 1;\r\n obj[node[i][2]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][1]]) {\r\n res.push([start, node[i][1]]);\r\n obj[node[i][1]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res = [],\r\n obj = {},\r\n start = node[0][0];\r\n obj[node[0][0]] = 1;\r\n obj[node[0][2]] = 1;\r\n res.push([node[0][0], node[0][2]]);\r\n for (let i = 1; i < k; i++) {\r\n if (!obj[node[i][0]] || !obj[node[i][2]]) {\r\n res.push([node[i][0], node[i][2]]);\r\n if (!obj[node[i][0]] && !obj[node[i][2]]) {\r\n if (!obj[node[i][0]]) res.push([node[i][0], node[i - 1][0]]);\r\n else res.push([node[i][2], node[i - 1][2]]);\r\n }\r\n obj[node[i][0]] = 1;\r\n obj[node[i][2]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][1]]) {\r\n res.push([start, node[i][1]]);\r\n obj[node[i][1]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res = [],\r\n obj = {},\r\n start = node[0][0];\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][0]] || !obj[node[i][2]]) {\r\n res.push([node[i][0], node[i][2]]);\r\n obj[node[i][0]] = 1;\r\n obj[node[i][2]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][1]]) {\r\n res.push([start, node[i][1]]);\r\n obj[node[i][1]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let node = [];\r\n for (let i = 0; i < k; i++) {\r\n node.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n let res = [],\r\n obj = {};\r\n for (let i = 0; i < k; i++) {\r\n if (!obj[node[i][2]] || !obj[node[i][0]]) {\r\n if (!obj[node[i][0]]) res.push([node[i][2], node[i][0]]);\r\n else res.push([node[i][0], node[i][2]]);\r\n obj[node[i][2]] = 1;\r\n obj[node[i][0]] = 1;\r\n }\r\n if (!obj[node[i][0]] || !obj[node[i][1]]) {\r\n if (!obj[node[i][1]]) res.push([node[i][0], node[i][1]]);\r\n else res.push([node[i][1], node[i][0]]);\r\n obj[node[i][1]] = 1;\r\n obj[node[i][0]] = 1;\r\n }\r\n }\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tconst used = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tlet [a, b, c] = rna();\r\n\t\t\tif (a > c) [a, c] = [c, a];\r\n\t\t\tconsole.log(a, c);\r\n\t\t\tused[a] = 1;\r\n\t\t}\r\n\r\n\t\tfor (let i = 1, u; i <= n; i++) {\r\n\t\t\tif (!used[i]) {\r\n\t\t\t\tif (u) console.log(u, i);\r\n\t\t\t\tu = i;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tconst used = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tlet [a, b, c] = rna();\r\n\t\t\tif (a > b) [a, b] = [b, a];\r\n\t\t\tconsole.log(a, c);\r\n\t\t\tused[c] = 1;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0, u; i < n; i++) {\r\n\t\t\tif (!used[i]) {\r\n\t\t\t\tif (u) console.log(u+1, i+1);\r\n\t\t\t\tu = i;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "dd3ba43eb0261ccdb7269a2696a042da"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar x = nextInt();\r\n\t\tvar tmp = S;\r\n\t\tvar output = 0;\r\n\t\twhile(true){\r\n\t\t\tvar L = myconv(tmp.split(\":\")[0], 1);\r\n\t\t\tvar R = myconv(tmp.split(\":\")[1], 1);\r\n\t\t\tvar V = L * 60 + R;\r\n\t\t\tV += x;\r\n\t\t\tvar LS = Math.floor(V / 60);\r\n\t\t\tif(LS >= 24){\r\n\t\t\t\tLS %= 24;\r\n\t\t\t}\r\n\t\t\tif(LS < 10){\r\n\t\t\t\tLS = \"0\" + LS;\r\n\t\t\t}\r\n\t\t\tvar RS = V % 60;\r\n\t\t\tif(RS < 10){\r\n\t\t\t\tRS = \"0\" + RS;\r\n\t\t\t}\r\n\t\t\ttmp = LS + \":\" + RS;\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var i = 0; i < tmp.length; i++){\r\n\t\t\t\tif(tmp[i] != tmp[tmp.length - 1 - i]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t\tif(tmp == S){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// https://codeforces.com/blog/entry/69610\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(v) {\n console.log(v);\n}\nconst palindromes = [\n \"00:00\",\n \"01:10\",\n \"02:20\",\n \"03:30\",\n \"04:40\",\n \"05:50\",\n \"10:01\",\n \"11:11\",\n \"12:21\",\n \"13:31\",\n \"14:41\",\n \"15:51\",\n \"20:02\",\n \"21:12\",\n \"22:22\",\n \"23:32\",\n];\n\nconst timeToMm = (v) => {\n const [hh, mm] = v.split(\":\").map(t => parseInt(t));\n return hh * 60 + mm;\n};\n\n\nconst palindromeMinutes = palindromes.map(timeToMm);\n\n// taken from https://codeforces.com/contest/1692/submission/170087380\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n let answer = 0;\n let running = startTimeMm;\n const s = new Set();\n const pad = (v) => (\"0\" + v).substr(-2);\n const isPalindrome = (a) => a === a.split(\"\").reverse().join(\"\");\n while (true) {\n const timeToCheck = pad(Math.floor(running / 60)) + \":\" + pad(running % 60);\n if (s.has(timeToCheck))\n break;\n\n if (isPalindrome(timeToCheck))\n answer++;\n\n s.add(timeToCheck);\n\n running += increment;\n running %= 1440;\n }\n print(answer);\n}\n\n\n/*\nconst gcd = (a, b) => {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n};\n\nconst lcm = (a, b) => a * b / gcd(a, b);\n\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n print(`time ${time}`);\n print(`incrementStr ${incrementStr}`);\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n print(`startTimeMm ${startTimeMm}`);\n let counter = 0;\n for (const palindromeTime of palindromeMinutes) {\n if ((lcm(palindromeTime, startTimeMm) - startTimeMm) % increment == 0)\n counter++;\n }\n print(counter);\n};\n*/\n\nconst main = () => {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n solve();\n }\n};\n"}, {"source_code": "const solve = (h,m,k)=>{\r\n let addh,mind;\r\n if(k>=60){\r\n addh = Math.floor(k/60);\r\n mind = k%60;\r\n }\r\n else{\r\n addh = 1;\r\n mind = k;\r\n }\r\n let h1 = h,m1 = m;\r\n let obj = {0:0,1:10,2:20,3:30,4:40,5:50,10:1,11:11,12:21,13:31,14:41,15:51,20:2,21:12,22:22,23:32};p=0;\r\n for(let i=0;i<=Infinity;i++){\r\n if(k>=60){\r\n if((obj[h1]===m1)) p++;\r\n h1 = (h1+addh)%24;\r\n if((m1+mind)>=60) h1 = (h1+1)%24;\r\n m1 = (m1+mind)%60;\r\n if((h1%24===h)&&(m1%60===m)){\r\n console.log(p);\r\n return;\r\n }\r\n }\r\n else{\r\n while(true){\r\n if((obj[h1]===m1)) p++;\r\n if((m1+mind)>=60) h1 = (h1+1)%24;\r\n m1 = (m1+mind)%60;\r\n if((h1%24===h)&&(m1%60===m)){\r\n console.log(p);\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n k = parseInt(k);\r\n solve(h,m,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "function solve() {\n const [a, b] = cl().split(' ');\n const bN = Number(b);\n const n = 60 * 24 / bN;\n let start = strToM(a);\n let count = 0;\n const set = new Set();\n while (!set.has(start)) {\n if (MIs(start)) {\n count += 1;\n }\n set.add(start);\n start += bN;\n start %= 1440;\n }\n co(count);\n}\n\nfunction strToM(str) {\n const [a, b] = str.split(':').map((item) => Number(item));\n return a * 60 + b;\n}\n\nfunction MIs(m) {\n m = m % 1440;\n const b = m % 60;\n const a = m / 60 | 0;\n const bStr = b < 10 ? '0' + b : '' + b;\n const aStr = a < 10 ? '0' + a : '' + a;\n return aStr[0] === bStr[1] && aStr[1] === bStr[0];\n}\n\nfunction Solution() {\n let n = Number(cl());\n while (n--) {\n solve();\n }\n}\n\nfunction cl() {\n return lines.shift();\n}\n\nfunction co(str) {\n console.log(str);\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', Solution);"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [time, p] = lines[l++].trim().split(' ')\n output[i] = solve(time, p)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(time, p) {\n p = +p\n const [h, m] = time.split(':').map(Number)\n const now = h * 60 + m\n let d = 0\n let ans = 0\n const map = {}\n while (1) {\n const k = cal(now + d)\n if (map[k]) break\n map[k] = 1\n if (isp(k)) ans++\n d += p\n // if (d > 2440) break\n }\n return ans\n}\nfunction cal(now) {\n let h = Math.floor(now / 60)\n h %= 24\n if (h < 10) h = '0' + h\n let m = now % 60\n if (m < 10) m = '0' + m\n const s = h + ':' + m\n// console.log(s)\n return s\n}\nfunction isp(s) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] !== s[s.length - 1 - i]) return false\n }\n return true\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n const [h, m] = a[0].split(':').map(Number),\r\n t = Number(a[1]);\r\n let h1 = h,\r\n m1 = m;\r\n const set = new Set();\r\n const check = () => {\r\n const a = h1.toString().padStart(2, '0'),\r\n b = m1.toString().padStart(2, '0');\r\n const str = `${a}${b}`;\r\n if (str === str.split('').reverse().join('')) set.add(str);\r\n };\r\n const next = () => {\r\n m1 += t;\r\n h1 += Math.floor(m1 / 60);\r\n h1 %= 24;\r\n m1 %= 60;\r\n };\r\n check();\r\n next();\r\n while (h1 !== h || m1 !== m) {\r\n check();\r\n next();\r\n }\r\n return set.size;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read()).split(' ');\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\nfunction revStr(str){\r\n return Array.from(str).reverse().join('');\r\n}\r\nfunction palindromeTimeList(){\r\n const timesAr = [];\r\n for(let i=0;i<16;i++){\r\n let tm = i;\r\n if(tm<10){\r\n tm = `0${tm}`;\r\n }\r\n else{\r\n tm = `${tm}`\r\n }\r\n let acTime = `${tm}:${revStr(tm)}`;\r\n let cvMin = tm*60 + parseInt(revStr(tm)) ;\r\n // console.log(acTime , cvMin)\r\n\r\n timesAr.push(cvMin);\r\n }\r\n return timesAr;\r\n}\r\nfunction isPalindromeTime(timeStr = '')\r\n{\r\n const revStr = timeStr.split('').reverse().join('');\r\n return (revStr==timeStr );\r\n}\r\nfunction convertTime(n){\r\n let hour = Math.floor(n/60)%24;\r\n n = n%60;\r\n if(hour<10){\r\n hour = `0${hour}`;\r\n }\r\n if(n<10){\r\n n = `0${n}`;\r\n }\r\n return `${hour}:${n}`;\r\n}\r\nfunction solve() {\r\n let t= readSingleInt();\r\n const arTime = palindromeTimeList();\r\n while(t--)\r\n {\r\n let [timeString,interval]= readLine().split(' ');\r\n interval = parseInt(interval);\r\n let [hour ,min] = timeString.split(':').map( v=> parseInt(v));\r\n let time = hour*60 + min;\r\n let ans =0;\r\n if(isPalindromeTime(timeString)){\r\n ans++;\r\n }\r\n for(let i=time+interval;;i+=interval){\r\n // console.log('hi')\r\n const cvs = convertTime(i) ;\r\n if(cvs==timeString){\r\n break;\r\n }\r\n let res = isPalindromeTime( convertTime(i) );\r\n // console.log(cvs)\r\n if(res){\r\n ans++;\r\n // console.log(cvs)\r\n }\r\n }\r\n \r\n // palindromeTimeList()\r\n // console.log(isPalindromeTime('07:57'))\r\n console.log(ans)\r\n\r\n }\r\n}\r\n"}, {"source_code": "/*\r\n** 799D\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet is = \"\";\r\nlet cl = 0;\r\n\r\nprocess.stdin.on(\"data\", (inp) => {\r\n is += inp;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n is = is.trim().split(\"\\n\").map((s) => s.trim());\r\n main();\r\n});\r\n\r\nconst readline = () => is[cl++];\r\n\r\n// Common Template Ends //\r\n\r\nconst isPalindrome = (n) => {\r\n const m = n % 60;\r\n const h = (n - m) / 60;\r\n const h1 = h % 10;\r\n const h0 = (h - h1) / 10;\r\n return `${h1}${h0}` === `${m < 10 ? '0' : ''}${m}`;\r\n}\r\n\r\nconst toTime = (hhmm) => {\r\n const [h, m] = hhmm.split(':').map(n => parseInt(n));\r\n return h * 60 + m;\r\n}\r\n\r\nfunction main() {\r\n let nLines = parseInt(readline());\r\n while(nLines--) {\r\n const [time, x] = readline().split(' ');\r\n const start = toTime(time);\r\n const min = parseInt(x);\r\n let current = (start + min) % 1440;\r\n let n = isPalindrome(start) ? 1 : 0;\r\n while (current !== start) {\r\n if (isPalindrome(current)) n++;\r\n current = (current + min) % 1440;\r\n }\r\n\r\n console.log(n);\r\n }\r\n}"}], "negative_code": [{"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction isPalindromeTime(timeStr = '')\r\n{\r\n const revStr = timeStr.split('').reverse().join('');\r\n return (revStr==timeStr );\r\n}\r\nfunction convertTime(n){\r\n let hour = Math.floor(n/60)%24;\r\n n = n%60;\r\n if(hour<10){\r\n hour = `0${hour}`;\r\n }\r\n if(n<10){\r\n n = `0${n}`;\r\n }\r\n return `${hour}:${n}`;\r\n}\r\nfunction solve() {\r\n let t= readSingleInt();\r\n while(t--)\r\n {\r\n let [timeString,interval]= readLine().split(' ');\r\n interval = parseInt(interval);\r\n let [hour ,min] = timeString.split(':').map( v=> parseInt(v));\r\n let time = hour*60 + min;\r\n let ans =0;\r\n let list = new Set();\r\n if(isPalindromeTime(timeString)){\r\n ans++;\r\n list.add(timeString);\r\n }\r\n for(let i=time+interval;i<95*24*60;i+=interval){\r\n // console.log('hi')\r\n const cvs = convertTime(i) ;\r\n // if(cvs==timeString){\r\n // break;\r\n // }\r\n let res = isPalindromeTime( convertTime(i) );\r\n // console.log(cvs)\r\n if(res){\r\n ans++;\r\n list.add(cvs);\r\n // console.log(cvs)\r\n }\r\n }\r\n \r\n // palindromeTimeList()\r\n // console.log(isPalindromeTime('07:57'))\r\n console.log(list.size)\r\n\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction isPalindromeTime(timeStr = '')\r\n{\r\n const revStr = timeStr.split('').reverse().join('');\r\n return (revStr==timeStr );\r\n}\r\nfunction convertTime(n){\r\n let hour = Math.floor(n/60)%24;\r\n n = n%60;\r\n if(hour<10){\r\n hour = `0${hour}`;\r\n }\r\n if(n<10){\r\n n = `0${n}`;\r\n }\r\n return `${hour}:${n}`;\r\n}\r\nfunction solve() {\r\n let t= readSingleInt();\r\n while(t--)\r\n {\r\n let [timeString,interval]= readLine().split(' ');\r\n interval = parseInt(interval);\r\n let [hour ,min] = timeString.split(':').map( v=> parseInt(v));\r\n let time = hour*60 + min;\r\n let ans =0;\r\n let list = new Set();\r\n if(isPalindromeTime(timeString)){\r\n ans++;\r\n list.add(timeString);\r\n }\r\n for(let i=time+interval;i<90*24*60;i+=interval){\r\n // console.log('hi')\r\n const cvs = convertTime(i) ;\r\n // if(cvs==timeString){\r\n // break;\r\n // }\r\n let res = isPalindromeTime( convertTime(i) );\r\n // console.log(cvs)\r\n if(res){\r\n ans++;\r\n list.add(cvs);\r\n // console.log(cvs)\r\n }\r\n }\r\n \r\n // palindromeTimeList()\r\n // console.log(isPalindromeTime('07:57'))\r\n console.log(list.size)\r\n\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction isPalindromeTime(timeStr = '')\r\n{\r\n const revStr = timeStr.split('').reverse().join('');\r\n return (revStr==timeStr );\r\n}\r\nfunction convertTime(n){\r\n let hour = Math.floor(n/60)%24;\r\n n = n%60;\r\n if(hour<10){\r\n hour = `0${hour}`;\r\n }\r\n if(n<10){\r\n n = `0${n}`;\r\n }\r\n return `${hour}:${n}`;\r\n}\r\nfunction solve() {\r\n let t= readSingleInt();\r\n while(t--)\r\n {\r\n let [timeString,interval]= readLine().split(' ');\r\n interval = parseInt(interval);\r\n let [hour ,min] = timeString.split(':').map( v=> parseInt(v));\r\n let time = hour*60 + min;\r\n let ans =0;\r\n let list = new Set();\r\n if(isPalindromeTime(timeString)){\r\n ans++;\r\n list.add(timeString);\r\n }\r\n for(let i=time+interval;i<60*24*60;i+=interval){\r\n // console.log('hi')\r\n const cvs = convertTime(i) ;\r\n // if(cvs==timeString){\r\n // break;\r\n // }\r\n let res = isPalindromeTime( convertTime(i) );\r\n // console.log(cvs)\r\n if(res){\r\n ans++;\r\n list.add(cvs);\r\n // console.log(cvs)\r\n }\r\n }\r\n \r\n // palindromeTimeList()\r\n // console.log(isPalindromeTime('07:57'))\r\n console.log(list.size)\r\n\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction isPalindromeTime(timeStr = '')\r\n{\r\n const revStr = timeStr.split('').reverse().join('');\r\n return (revStr==timeStr );\r\n}\r\nfunction convertTime(n){\r\n let hour = Math.floor(n/60)%24;\r\n n = n%60;\r\n if(hour<10){\r\n hour = `0${hour}`;\r\n }\r\n if(n<10){\r\n n = `0${n}`;\r\n }\r\n return `${hour}:${n}`;\r\n}\r\nfunction solve() {\r\n let t= readSingleInt();\r\n while(t--)\r\n {\r\n let [timeString,interval]= readLine().split(' ');\r\n interval = parseInt(interval);\r\n let [hour ,min] = timeString.split(':').map( v=> parseInt(v));\r\n let time = hour*60 + min;\r\n let ans =0;\r\n let list = new Set();\r\n if(isPalindromeTime(timeString)){\r\n ans++;\r\n list.add(timeString);\r\n }\r\n for(let i=time+interval;i<30*24*60;i+=interval){\r\n // console.log('hi')\r\n const cvs = convertTime(i) ;\r\n // if(cvs==timeString){\r\n // break;\r\n // }\r\n let res = isPalindromeTime( convertTime(i) );\r\n // console.log(cvs)\r\n if(res){\r\n ans++;\r\n list.add(cvs);\r\n // console.log(cvs)\r\n }\r\n }\r\n \r\n // palindromeTimeList()\r\n // console.log(isPalindromeTime('07:57'))\r\n console.log(list.size)\r\n\r\n }\r\n}"}, {"source_code": "/*\r\n** 799D\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet is = \"\";\r\nlet cl = 0;\r\n\r\nprocess.stdin.on(\"data\", (inp) => {\r\n is += inp;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n is = is.trim().split(\"\\n\").map((s) => s.trim());\r\n main();\r\n});\r\n\r\nconst readline = () => is[cl++];\r\n\r\n// Common Template Ends //\r\n\r\nconst isPalindrome = (n) => {\r\n const m = n % 60;\r\n const h = (n - m) / 60;\r\n const h1 = h % 10;\r\n const h0 = (h - h1) / 10;\r\n return `${h1}${h0}` === `${m < 10 ? '0' : ''}${m}`;\r\n}\r\n\r\nconst toTime = (hhmm) => {\r\n const [h, m] = hhmm.split(':').map(n => parseInt(n));\r\n return h * 60 + m;\r\n}\r\n\r\nfunction main() {\r\n let nLines = parseInt(readline());\r\n while(nLines--) {\r\n const [time, x] = readline().split(' ');\r\n const start = toTime(time);\r\n const min = parseInt(x);\r\n let current = start + min;\r\n let n = isPalindrome(start) ? 1 : 0;\r\n while (current !== start) {\r\n if (isPalindrome(current)) n++;\r\n current = (current + min) % 1440;\r\n }\r\n\r\n console.log(n);\r\n }\r\n}"}, {"source_code": "const palindromes = [\n \"00:00\",\n \"01:10\",\n \"02:20\",\n \"03:30\",\n \"04:40\",\n \"05:50\",\n \"10:01\",\n \"11:11\",\n \"12:21\",\n \"13:31\",\n \"14:41\",\n \"15:51\",\n \"20:02\",\n \"21:12\",\n \"22:22\",\n \"23:32\",\n];\n\nconst timeToMm = (v) => {\n const [hh, mm] = v.split(\":\").map(t => parseInt(t));\n return hh * 60 + mm;\n};\n\n\nconst palindromeMinutes = palindromes.map(timeToMm);\n\n// taken from https://codeforces.com/contest/1692/submission/170087380\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n let answer = 0;\n let running = startTimeMm;\n const s = new Set();\n const pad = (v) => (\"0\" + v).substr(-2);\n const isPalindrome = (a) => a === a.split(\"\").reverse().join(\"\");\n while (true) {\n const timeToCheck = pad(Math.floor(running / 60)) + \":\" + pad(running % 60);\n if (s.has(timeToCheck))\n break;\n\n if (isPalindrome(timeToCheck))\n answer++;\n\n s.add(timeToCheck);\n\n running += increment;\n running %= 1440;\n }\n console.log(answer);\n}\n\n\n/*\nconst gcd = (a, b) => {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n};\n\nconst lcm = (a, b) => a * b / gcd(a, b);\n\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n print(`time ${time}`);\n print(`incrementStr ${incrementStr}`);\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n print(`startTimeMm ${startTimeMm}`);\n let counter = 0;\n for (const palindromeTime of palindromeMinutes) {\n if ((lcm(palindromeTime, startTimeMm) - startTimeMm) % increment == 0)\n counter++;\n }\n print(counter);\n};\n*/\n\nconst main = () => {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n solve();\n }\n};\n"}, {"source_code": "const palindromes = [\n \"00:00\",\n \"01:10\",\n \"02:20\",\n \"03:30\",\n \"04:40\",\n \"05:50\",\n \"10:01\",\n \"11:11\",\n \"12:21\",\n \"13:31\",\n \"14:41\",\n \"15:51\",\n \"20:02\",\n \"21:12\",\n \"22:22\",\n \"23:32\",\n];\n\nconst timeToMm = (v) => {\n const [hh, mm] = v.split(\":\").map(t => parseInt(t));\n return hh * 60 + mm;\n};\n\n\nconst palindromeMinutes = palindromes.map(timeToMm);\n\n// taken from https://codeforces.com/contest/1692/submission/170087380\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n let answer = 0;\n let running = startTimeMm;\n const s = new Set();\n const pad = (v) => (\"0\" + v).substr(-2);\n const isPalindrome = (a) => a === a.split(\"\").reverse().join(\"\");\n while (true) {\n const timeToCheck = pad(Math.floor(running / 60)) + \":\" + pad(running % 60);\n if (s.has(timeToCheck))\n break;\n\n if (isPalindrome(timeToCheck))\n answer++;\n\n s.add(timeToCheck);\n\n running += increment;\n running %= 1440;\n }\n print(answer);\n}\n\n\n/*\nconst gcd = (a, b) => {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n};\n\nconst lcm = (a, b) => a * b / gcd(a, b);\n\nconst solve = () => {\n const [time, incrementStr] = readline().split(\" \");\n print(`time ${time}`);\n print(`incrementStr ${incrementStr}`);\n const startTimeMm = timeToMm(time);\n const increment = parseInt(incrementStr);\n print(`startTimeMm ${startTimeMm}`);\n let counter = 0;\n for (const palindromeTime of palindromeMinutes) {\n if ((lcm(palindromeTime, startTimeMm) - startTimeMm) % increment == 0)\n counter++;\n }\n print(counter);\n};\n*/\n\nconst main = () => {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n solve();\n }\n};\n"}, {"source_code": "const solve = (h,m,k)=>{\r\nlet j = m;\r\n let obj = {0:0,1:10,2:20,3:30,4:40,5:50,10:1,11:11,12:21,13:31,14:41,15:51,20:2,21:12,22:22,23:32};p=0;\r\n for(let i=0;i<=Infinity;i++){\r\n let res = [];\r\n while(j<60){\r\n if((i!==0)&&(i%24===0)&&(j===m)){\r\n console.log(p);\r\n return;\r\n }\r\n res.push(j);\r\n j+=k;\r\n }\r\n if(!((((h%24)>=6)&&((h%24)<=9))||((h%24>=16)&&(h%24<=19)))){\r\n for(let l=0;lparseInt(cur));\r\n k = parseInt(k);\r\n solve(h,m,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (h,m,k)=>{\r\nlet j = m;\r\n let obj = {0:0,1:10,2:20,3:30,4:40,5:50,10:1,11:11,12:21,13:31,14:41,15:51,20:2,21:12,22:22,23:32};p=0;\r\n for(let i=0;i<=24;i++){\r\n let res = [];\r\n while(j<60){\r\n if((i!==0)&&(i%24===0)&&(j===m)){\r\n console.log(p);\r\n return;\r\n }\r\n res.push(j);\r\n j+=k;\r\n }\r\n if(!((((h%24)>=6)&&((h%24)<=9))||((h%24>=16)&&(h%24<=19)))){\r\n for(let l=0;lparseInt(cur));\r\n k = parseInt(k);\r\n solve(h,m,k);\r\n }\r\n}\r\nmain();"}], "src_uid": "c601769062070ab983e1d4c9942cdd39"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return i[s++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.b)).max(),n=e.map((t=>t.a)).min();for(let u=0;u{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();", "positive_code": [{"source_code": "var i, r,\n\tn = +readline(),\n\ta = [],\n\tb = [],\n\tans = -1;\n\nfor (var i = 1; i <= n; i++)\n\treadline().split(' ').map(Number).reduce(function(l, r) {\n\t\ta.push(l);\n\t\tb.push(r);\n\t});\n\nvar min = Math.min.apply(0, a);\nvar max = Math.max.apply(0, b);\n\nfor(i = 0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let [minL, maxR] = coordinates[0];\n let index = 0;\n\n for (let i = 1; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n if (l === minL) {\n if (r >= maxR) {\n maxR = r\n index = i\n }\n } else if (l < minL) {\n minL = l;\n if (r >= maxR) {\n maxR = r;\n index = i\n } else {\n index = -1;\n }\n } else {\n if (r > maxR) {\n maxR = r;\n index = -1;\n }\n }\n\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": ";(function () {\n\t\n\tprint((function (n) {\n\t\tvar _o = 1e10, o_ = -1, p = -1, l = n;\n\n\t\twhile (l--) {\n\t\t\tvar s = readline().split(' ').map(Number), _f = false, f_ = false;\n\t\t\tif (_o > s[0]) { _o = s[0]; _f = true; }\n\t\t\tif (o_ < s[1]) { o_ = s[1]; f_ = true; }\n\t\t\tif (_f || f_) p = -1;\n\t\t\tif (_o === s[0] && o_ === s[1]) p = n - l;\n\t\t}\n\n\t\treturn p;\n\t})(+readline()));\n\n}).call(this)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function p(){return s[i++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function d(){return p().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.b)).max(),n=e.map((t=>t.a)).min(),u=e.findIndex((t=>t.a==n&&t.b==r));o.default.put(-1==u?-1:u+1)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()), segments = [];\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar data = tokenizeIntegers(readline());\n\t\tsegments.push({ left: data[0], right: data[1] });\n\t}\n\tvar leftmost = segments[0].left, rightmost = segments[0].right;\n\tfor (var i = 1; i < n; ++i) {\n\t\tleftmost = Math.min(leftmost, segments[i].left);\n\t\trightmost = Math.max(rightmost, segments[i].right);\n\t}\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (segments[i].left == leftmost && segments[i].right == rightmost) {\n\t\t\tprint(i+1);\n\t\t\treturn;\n\t\t}\n\t}\n\tprint(-1);\n}\n\nmain();\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let len = +readLine();\n const arr = [];\n const map = new Map();\n let max = -Infinity;\n for (let i = 0; i < len; i++) {\n const row = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n map.set(`${row[0]}_${row[1]}`, i + 1);\n max = Math.max(max, row[1]);\n arr.push(row);\n }\n\n arr.sort((a, b) => a[0] - b[0] || b[1] - a[1]);\n if (arr[0][1] >= max) console.log(map.get(`${arr[0][0]}_${arr[0][1]}`));\n else console.log(-1);\n}\n"}, {"source_code": "var n = +readline(),\n\tans = -1,\n\tmin = 1e10,\n\tmax = 0;\n\nfor (var i = 1; i <= n; i++)\n\t(function(l, r) {\n\t\tvar f = 0;\n\t\tif (l < min || r > max)\n\t\t\tans = -1;\n\n\t\tif (l <= min) {\n\t\t\tf++;\n\t\t\tmin = l;\n\t\t}\n\t\tif (r >= max) {\n\t\t\tf++;\n\t\t\tmax = r;\n\t\t}\n\n\t\tif (f === 2)\n\t\t\tans = i; \n\n\t}).apply(0, readline().split(' ').map(Number));\n\n\n\nprint(ans);"}, {"source_code": "var i, r,\n\tn = +readline(),\n\ta = [],\n\tans = -1;\n\nfor (var i = 1; i <= n; i++)\n\ta.push(readline().split(' ').map(Number));\n\nr = a.reduce(function(a, b) {\n\treturn [Math.min(a[0], b[0]), Math.max(a[1], b[1])];\n});\n\na.forEach(function(v, i) {\n\tif (r[0] === v[0] && r[1] === v[1]) ans = i + 1;\n});\n\nprint(ans);\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let minL = coordinates[0][0];\n let maxR = coordinates[0][1];\n let index = 0;\n\n for (let i = 1; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n if (l <= minL) {\n minL = l;\n if (r >= maxR) {\n maxR = r;\n index = i\n } else {\n index = -1;\n }\n } else {\n if (r > maxR) {\n maxR = r;\n index = -1;\n }\n }\n\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let minL = coordinates[0][0]\n let maxR = coordinates[0][1]\n let index = 0\n \n for (let i = 1; i < coordinates.length; i++) {\n if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {\n index = i;\n }\n if (coordinates[i][0] <= minL)\n minL = coordinates[i][0]\n if (coordinates[i][1] <= maxR)\n maxR = coordinates[i][1]\n }\n \n if (index === 0 && minL === maxR) {\n console.log(-1)\n return\n }\n console.log(index + 1)\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let [minL, maxR] = coordinates[0];\n let index = 0;\n\n for (let i = 1; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n if (l === minL) {\n if (r >= maxR) {\n maxR = r\n index = i\n }\n } else if (l < minL) {\n minL = l;\n if (r >= maxR) {\n maxR = r;\n index = i\n } else {\n index = -1;\n }\n } else {\n if (r >= maxR) {\n maxR = r;\n index = -1;\n }\n }\n\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let minL = Number.MAX_VALUE\n let maxR = Number.MIN_VALE\n let index = -1;\n\n for (let i = 0; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n \n if (l <= minL) {\n minL = l\n index = -1\n }\n \n if (r >= maxR) {\n maxR = r\n index = -1\n }\n \n if (l === minL && r === maxR) {\n index = i\n }\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let [minL, maxR] = coordinates[0];\n let index = 0;\n\n for (let i = 1; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n if (l === minL) {\n if (r > maxR) {\n maxR = r\n index = i\n }\n } else if (l < minL) {\n minL = l;\n if (r >= maxR) {\n maxR = r;\n index = i\n } else {\n index = -1;\n }\n } else {\n if (r > maxR) {\n maxR = r;\n index = -1;\n }\n }\n\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let minL = coordinates[0][0]\n let maxR = coordinates[0][1]\n let index = 0\n \n for (let i = 1; i < coordinates.length; i++) {\n if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {\n index = i;\n }\n }\n \n if (index === 0 && minL === maxR) {\n console.log(-1)\n return\n }\n console.log(index + 1)\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let [minL, maxR] = coordinates[0];\n let index = 0;\n\n for (let i = 1; i < coordinates.length; i++) {\n const [l,r] = coordinates[i]\n if (l === minL) {\n if (r > maxR) {\n maxR = r\n index = -1\n }\n } else if (l < minL) {\n minL = l;\n if (r >= maxR) {\n maxR = r;\n index = i\n } else {\n index = -1;\n }\n } else {\n if (r > maxR) {\n maxR = r;\n index = -1;\n }\n }\n\n }\n\n console.log(index === -1 ? -1 : index + 1)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const numsOfInput = readline();\n let coordinates = []\n for (let i = 0; i < numsOfInput; i++) {\n const coordinate = readline().split(' ').map(segment => parseInt(segment));\n \n coordinates.push([...coordinate])\n }\n\n helper(coordinates);\n}\n\nfunction helper(coordinates) {\n let minL = coordinates[0][0]\n let maxR = coordinates[0][1]\n let index = 0\n \n for (let i = 1; i < coordinates.length; i++) {\n if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {\n index = i;\n }\n if (coordinates[i][0] <= minL)\n minL = coordinates[i][0]\n if (coordinates[i][1] >= maxR)\n maxR = coordinates[i][1]\n }\n \n if (index === 0 && minL === maxR) {\n console.log(-1)\n return\n }\n console.log(index + 1)\n\n}"}, {"source_code": "var n = +readline(),\n\tans = -1,\n\tmin = 1e10,\n\tmax = 0;\n\nfor (var i = 1; i <= n; i++)\n\t(function(l, r) {\n\t\tvar f = 0;\n\t\tif (l <= min) {\n\t\t\tf++;\n\t\t\tmin = l;\n\t\t}\n\t\tif (r >= max) {\n\t\t\tf++;\n\t\t\tmax = r;\n\t\t}\n\t\tif (f === 2) {\n\t\t\tans = i;\n\t\t}\n\t}).apply(0, readline().split(' ').map(Number));\n\n\n\nprint(ans);"}, {"source_code": "var n = +readline(),\n\tans = -1,\n\tmin = 1e10,\n\tmax = 0;\n\nfor (var i = 1; i <= n; i++)\n\t(function(l, r) {\n\t\tvar f = 0;\n\t\tif (l <= min) {\n\t\t\tf++;\n\t\t\tmin = l;\n\t\t}\n\t\tif (r >= max) {\n\t\t\tf++;\n\t\t\tmax = r;\n\t\t}\n\n\t\tif (f === 2)\n\t\t\tans = i;\n\t\telse if (f === 1)\n\t\t\tans = -1;\n\n\t}).apply(0, readline().split(' ').map(Number));\n\n\n\nprint(ans);"}, {"source_code": "var n = +readline(),\n\tans = -1,\n\tmin = 1e10,\n\tmax = 0;\n\nfor (var i = 1; i <= n; i++)\n\t(function(l, r) {\n\t\tvar f = 0;\n\t\tif (l <= min) {\n\t\t\tf++;\n\t\t\tmin = l;\n\t\t}\n\t\tif (r >= max) {\n\t\t\tf++;\n\t\t\tmax = r;\n\t\t}\n\n\t\tif (f === 2)\n\t\t\tans = i;\n\t\tif (l < min || r > max)\n\t\t\tans = -1;\n\n\t}).apply(0, readline().split(' ').map(Number));\n\n\n\nprint(ans);"}, {"source_code": ";(function () {\n\t\n\tprint((function (n) {\n\t\tvar _o = 1e5, o_ = 0, p = -1, l = n;\n\n\t\twhile (l--) {\n\t\t\tvar s = readline().split(' ').map(Number), _f = false, f_ = false;\n\t\t\tif (_o > s[0]) { _o = s[0]; _f = true; }\n\t\t\tif (o_ < s[1]) { o_ = s[1]; f_ = true; }\n\t\t\tif (_f || f_) p = -1;\n\t\t\tif (_o === s[0] && o_ === s[1]) p = n - l;\n\t\t}\n\n\t\treturn p;\n\t})(+readline()));\n\n}).call(this)"}, {"source_code": ";(function () {\n\t\n\tprint((function (n) {\n\t\tvar a = [], min = 1e6, max = 0;\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar s = readline().split(' ').map(Number); \n\t\t\tmin = Math.min(min, s[0]);\n\t\t\tmax = Math.max(max, s[1]);\n\t\t\ta.push(s);\n\t\t}\n\n\t\tfor (var i = 0; i < n; i++) if (a[i][0] === min && a[i][1] === max) return i + 1;\n\t\treturn -1;\n\t})(+readline()));\n\n}).call(this)"}], "src_uid": "e702594a8e993e135ea8ca78eb3ecd66"} {"source_code": "var num = parseInt(readline());\nvar field = [];\n\n\nfield.push(Array(num + 3).join(\".\").split(\"\"));\nfor(var i=0; i < num; i++) field.push((\".\" + readline() + \".\").split(\"\"));\nfield.push(Array(num + 3).join(\".\").split(\"\"));\n\nvar txt = field.join(\"\"), c = 0, col = 0, need = 0;\nfor(var i in txt) if(txt[i] == '#') c++;\n\nneed = c / 5;\n\nfunction check(y, x){\n\n if (field[y][x] == \".\" &&\n field[y][x+1] == \"#\" &&\n field[y+1][x] == \"#\" &&\n field[y+1][x+1] == \"#\" &&\n field[y+1][x+2] == \"#\" &&\n field[y+2][x+1] == \"#\"\n ) {\n\n field[y][x + 1] = \".\";\n field[y + 1][x + 1] = \".\";\n field[y + 2][x + 1] = \".\";\n field[y + 1][x] = \".\";\n field[y + 1][x + 2] = \".\";\n col++;\n }\n}\n\nif (c % 5 != 0) print(\"NO\");\nelse {\n\n for(var i = 1; i <= num; i++) {\n for(var j = 1; j <= num; j++) {\n check(i, j);\n }\n }\n\n if (need == col) print(\"YES\");\n else print(\"NO\");\n}\n\nfunction sort(a, b){if (a == b) return 0; return a > b ? 1 : -1}\nfunction sort2(a, b){if (a == b) return 0; return a < b ? 1 : -1}", "positive_code": [{"source_code": "var n=+readline();\nvar a=[];\nfor(var i=0;i inp += chunk);\nprocess.stdin.on('end', () => {\n const n = +inp;\n let u = \"\";\n let v = \"\";\n for (let i = 0; i < n; ++i) {\n u += 'W';\n v += 'B';\n [u, v] = [v, u];\n }\n for (let i = 0; i < n; ++i) \n console.log(i % 2 === 1 ? u : v);\n});\n"}], "negative_code": [{"source_code": "\"use strict\";\n\nvar n, i, k;\nn += readline();\n\nfor (i = 1; i <= n; i++) {\n for (k = 1; k <= n; k++) {\n if ((i + k) % 2 == 0) {\n print(\"B\");\n } else {\n print(\"W\");\n }\n }\n}"}], "src_uid": "09991e8e16cd395c7ce459817a385988"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [l,r,k] = readline().split(' ').map(Number);\r\n if (l === r) {\r\n output(l === 1 ? 'NO': 'YES');\r\n continue;\r\n }\r\n let ol = l % 2 === 1 ? l : l + 1;\r\n let or = r % 2 === 1 ? r : r - 1;\r\n let odd = ((or - ol) / 2) + 1;\r\n output(odd <= k ? 'YES': 'NO');\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var [l,r,k] = readline().split(\" \").map(w => parseInt(w))\r\n console.log(solve())\r\n \tfunction solve() {\r\n \t\tvar n = (r-l)+1;\r\n \t\tif(k == 0) {\r\n \t\t\tif(n > 1) return 'NO'\r\n \t\t\telse {\r\n \t\t\t\tif(l == 1) return 'NO'\r\n \t\t\t\telse return 'YES'\r\n \t\t\t}\r\n \t\t}\r\n \t\tvar sum = (r-l)+1;\r\n \t\tif(sum %2 == 0) sum /= 2;\r\n \t\telse {\r\n \t\t\tif(l%2 == 0) sum = 1 + Math.floor(sum/2);\r\n \t\t\telse sum = Math.floor(sum/2)\r\n \t\t}\r\n \r\n \t\tvar odd = n-sum;\r\n \t\tif(odd < k+1) return 'YES';\r\n \t\telse return 'NO'\r\n \t}\r\n}"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split(' ').map(Number);\n\t var l = a[0], r = a[1], k = a[2];\n\t if(l == r){\n\t if(l > 1){\n\t console.log('YES');\n\t }else{\n\t console.log('NO');\n\t }\n\t }else{\n\t var odd = Math.floor((r - l + 1) / 2);\n\t var even = Math.ceil((r - l + 1) / 2);\n\t if(r % 2 == l % 2){\n\t if(r % 2 == 1){\n\t odd++;\n\t }else{\n\t even++;\n\t }\n\t }\n\t if(k >= odd){\n\t console.log('YES');\n\t }else{\n\t console.log('NO');\n\t }\n\t }\n\t}\n});\n\n"}, {"source_code": "// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => {\r\n return x & 1;\r\n};\r\nconst isEven = (x) => {\r\n return !(x & 1);\r\n};\r\n\r\nconst reverseText = (s) => {\r\n return s.split(\"\").reverse().join(\"\");\r\n};\r\nconst hasDuplicates = (str) => /([a-z])\\1/i.test(str);\r\n\r\nconst hasDuplicateChar = (str, char) =>\r\n str.indexOf(char) !== str.lastIndexOf(char);\r\n\r\nconst isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split(\"\");\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices;\r\n};\r\n\r\nconst splitAt = (index) => (x) => [x.slice(0, index), x.slice(index)];\r\n\r\nconst isUpper = (str) => !/[a-z]/.test(str) && /[A-Z]/.test(str);\r\n\r\nconst escapeRegExp = (string) =>\r\n string.replace(/[.*+\\-?^$$${}()|[\\]\\\\]/g, \"$$$&\");\r\n\r\nconst replaceAll = (str, find, replace) =>\r\n str.replace(new RegExp(escapeRegExp(find), \"g\"), replace);\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\");\r\n};\r\n\r\nconst unique = (str) => {\r\n const cleanStr = str.replace(/ /gi, \"\");\r\n const set = [...new Set(cleanStr)];\r\n return set;\r\n};\r\n\r\nconst sortASC = (array) => {\r\n // var numArray = new Uint32Array(array)\r\n // var numArray = new Int32Array(array)\r\n var numArray = new Float64Array(array);\r\n numArray = numArray.sort();\r\n return numArray;\r\n};\r\n\r\nconst removeDuplicates = (array) => [...new Set(array)];\r\n\r\n// LIBRARY END\r\n\r\nfunction solve() {\r\n let [l, r, k] = readline().split(\" \").map(Number);\r\n if (l == 1 && r == 1) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n\r\n if (l == r) {\r\n console.log(\"YES\");\r\n return;\r\n }\r\n\r\n let minMoves = (r - l + 1) - ( Math.floor(r/2) - Math.floor((l-1)/2));\r\n if(minMoves <= k){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n}\r\n\r\nfunction main() {\r\n let tc = +readline();\r\n while (tc--) {\r\n solve();\r\n }\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split(' ').map(Number);\n\t var l = a[0], r = a[1], k = a[2];\n\t if(l == r){\n\t if(l > 1){\n\t console.log('YES');\n\t }else{\n\t console.log('NO');\n\t }\n\t }else{\n\t var odd = Math.floor((r - l + 1) / 2);\n\t var even = Math.floor((r - l + 1) / 2);\n\t if(r % 2 == 1){\n\t odd++;\n\t }else{\n\t even++;\n\t }\n\t if(k >= odd){\n\t console.log('YES');\n\t }else{\n\t console.log('NO');\n\t }\n\t }\n\t}\n});\n\n"}, {"source_code": "// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => {\r\n return x & 1;\r\n};\r\nconst isEven = (x) => {\r\n return !(x & 1);\r\n};\r\n\r\nconst reverseText = (s) => {\r\n return s.split(\"\").reverse().join(\"\");\r\n};\r\nconst hasDuplicates = (str) => /([a-z])\\1/i.test(str);\r\n\r\nconst hasDuplicateChar = (str, char) =>\r\n str.indexOf(char) !== str.lastIndexOf(char);\r\n\r\nconst isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split(\"\");\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices;\r\n};\r\n\r\nconst splitAt = (index) => (x) => [x.slice(0, index), x.slice(index)];\r\n\r\nconst isUpper = (str) => !/[a-z]/.test(str) && /[A-Z]/.test(str);\r\n\r\nconst escapeRegExp = (string) =>\r\n string.replace(/[.*+\\-?^$$${}()|[\\]\\\\]/g, \"$$$&\");\r\n\r\nconst replaceAll = (str, find, replace) =>\r\n str.replace(new RegExp(escapeRegExp(find), \"g\"), replace);\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\");\r\n};\r\n\r\nconst unique = (str) => {\r\n const cleanStr = str.replace(/ /gi, \"\");\r\n const set = [...new Set(cleanStr)];\r\n return set;\r\n};\r\n\r\nconst sortASC = (array) => {\r\n // var numArray = new Uint32Array(array)\r\n // var numArray = new Int32Array(array)\r\n var numArray = new Float64Array(array);\r\n numArray = numArray.sort();\r\n return numArray;\r\n};\r\n\r\nconst removeDuplicates = (array) => [...new Set(array)];\r\n\r\n// LIBRARY END\r\n\r\nfunction solve() {\r\n let [l, r, k] = readline().split(\" \").map(Number);\r\n\r\n if (l == 1 && r == 1) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n\r\n if (l == r) {\r\n console.log(\"YES\");\r\n return;\r\n }\r\n\r\n let minMoves = r - l + 1 - (r / 2 - (l - 1) / 2);\r\n let ans = minMoves <= k ? \"YES\" : \"NO\";\r\n console.log(ans);\r\n}\r\n\r\nfunction main() {\r\n let tc = +readline();\r\n while (tc--) {\r\n solve();\r\n }\r\n}\r\n"}], "src_uid": "9363df0735005832573ef4d17b6a8302"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let nm = readLine().split(' ').map(value => parseInt(value))\n let n = nm[0];\n let m = nm[1];\n let oke = 1;\n for (var i = 0; i < n; i++) {\n if (i % 2 == 0) {\n console.log('#'.repeat(m))\n } else {\n if (oke % 2 == 1) {\n console.log('.'.repeat(m - 1) + '#')\n oke++;\n } else {\n console.log('#' + '.'.repeat(m - 1))\n oke++;\n }\n }\n }\n}", "positive_code": [{"source_code": "var input = readline().split(\" \"), n = +input[0], m = +input[1];\n\nfor(i = 1; i <= n; i++){\n\tif( i % 2 == 1 ){\n\t\tfor(j = 0; j < m; j++){\n\t\t\twrite(\"#\");\n\t\t}\n\t\twrite(\"\\n\");\n\t}\n\telse if( (i/2) % 2 == 1 ){\n\t\tfor(j = 0; j < m-1; j++){\n\t\t\twrite(\".\");\n\t\t}\n\t\twrite(\"#\");\n\t\twrite(\"\\n\");\n\t}\n\telse if( (i/2) % 2 == 0 ){\n\t\twrite(\"#\");\n\t\tfor(j = 0; j < m-1; j++){\n\t\t\twrite(\".\");\n\t\t}\n\t\twrite(\"\\n\");\n\t}\n}"}, {"source_code": "\n\nfunction answer(input){\n input = input.split(' ');\n var n = input[0];\n var m = input[1];\n var emptyLine = '';\n for(var i = 0; i < m; i++){\n emptyLine += '.';\n }\n var fullLine = emptyLine.replace(/\\./g,'#');\n var snakeSideLine = emptyLine.slice(0,-1);\n var rightSnake = snakeSideLine+'#';\n var leftSnake = '#'+snakeSideLine;\n var output = [];\n var steps = [fullLine,rightSnake,fullLine,leftSnake];\n \n for(var i = 0; i < n; i++){\n output.push(steps[i%4]);\n }\n output.forEach(function(el){\n print(el);\n });\n}\n\nanswer(readline());"}, {"source_code": "var line = readline().split(\" \");\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\nfor (var i = 0; i < n; i++) {\n if ((i + 1) % 2 === 0) {\n if ((i + 1) % 4 === 0) {\n write(\"#\");\n for (var j = 1; j < m; j++) {\n write(\".\");\n }\n } else {\n for (var j = 1; j < m; j++) {\n write(\".\");\n }\n write(\"#\");\n }\n } else {\n for (var j = 0; j < m; j++) {\n write(\"#\");\n }\n }\n write(\"\\n\");\n}"}, {"source_code": "///////////////////////////////////////////////////////////////////////////////\nfunction readNumber () { return Number(readline()); }\nfunction readNumbersArray () { return readline().split(' ').map(Number); }\nfunction algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }\n///////////////////////////////////////////////////////////////////////////////\n\nvar array = readNumbersArray();\nvar n = array[0], m = array[1];\n\nvar a = '';\nfor (var i = 0; i < m; i++) a += '#';\n\nvar ba = '#';\nfor (var i = 1; i < m; i++) ba += '.';\n\nvar ab = '';\nfor (var i = 1; i < m; i++) ab += '.';\nab += '#';\n\nvar result = [];\nfor (var i = 0; i < n; i++) result.push(a);\nfor (var i = 1; i < n; i += 4) result[i] = ab;\nfor (var i = 3; i < n; i += 4) result[i] = ba;\n\nprint(result.join('\\n'));"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]), m = Number(s[1]);\nfor(var i = 0; i row.indexOf('#') === -1;\n\nfor (let i = 0; i < n; i++) {\n let str = '';\n for (let j = 0; j < m; j++) {\n if (i % 2 === 0) {\n str += filled;\n } else {\n if (\n (a % 2 === 0 && j === m - 1 && isHashExist(str)) ||\n (a % 2 !== 0 && j === 0 && isHashExist(str))\n ) {\n str += filled;\n a++;\n } else {\n str += empty;\n }\n }\n }\n snake.push(str);\n}\nfor (let i = 0; i < snake.length; i++){\n write(snake[i] + '\\n');\n};"}, {"source_code": "var n = readline().split(\" \");\n\tfor (var i=0; i<+n[0]; i++){\n\t\t\tif(i%2==0) print(\"#\".repeat(n[1]));\n\t\t\telse if ((i-1)%4==0) \n\t\t\t\tprint(\".\".repeat(n[1]-1)+\"#\");\t\n\t\t\telse \n\t\t\tprint(\"#\"+\".\".repeat(n[1]-1));\t\t\t\n\t\t}\n"}, {"source_code": "var main = function(n, m)\n{\n var arrHelpToCreateTrueSnake = [], allInSharp = [], arrResult = [];\n for (var i = 1; i <= m; i++)\n {\n if (i !== 1) arrHelpToCreateTrueSnake.push('.');\n else arrHelpToCreateTrueSnake.push('#');\n allInSharp.push('#');\n }\n for (i = 1; i <= n; i++)\n {\n if (i % 2 === 1) print(allInSharp.join(''));\n else print(arrHelpToCreateTrueSnake.reverse().join(''));\n }\n return 0;\n}\nvar input = readline();\ninput = input.split(' ');\nmain(+input[0], +input[1]);"}, {"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0],\n\tm = nm[1];\n\nvar fullRow = Array.apply(null, new Array(m)).map(function () { return '#'; }).join('');\nvar turnLeft = Array.apply(null, new Array(m - 1)).map(function () { return '.'; }).join('') + '#';\nvar turnRight = turnLeft.split('').reverse().join('');\n\nvar dir = 'left';\n\nfor (var i = 0; i < n; i++) {\n\tif (i % 2 == 0) {\n\t\tprint(fullRow);\n\t} else {\n\t\tif (dir == 'left') {\n\t\t\tprint(turnLeft);\n\t\t\tdir = 'right';\n\t\t} else {\n\t\t\tprint(turnRight);\n\t\t\tdir = 'left';\n\t\t}\n\t}\n};\n"}, {"source_code": "var inputs = readline().split(\" \");\nvar n = inputs[1]\nvar m = inputs[0]\nvar r = 1;\nvar str = \"\";\nfor (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n if (i%2 == 0)\n str += \"#\";\n else {\n if (r==1) {\n if (j!=n-1)\n str += \".\";\n else\n str += \"#\";\n }\n else if (r == 0) {\n if (j!=0)\n str += \".\";\n else\n str += \"#\";\n }\n }\n }\n if (i%2 != 0) {\n if (r==1) r = 0;\n else r = 1;\n }\n str += '\\n'\n} \nprint(str)"}, {"source_code": "var params = readline().split(\" \").map(value => +value);\nvar n = params[0], m = params[1];\nvar full = first = last = \"\";\n\nfor(var i = 0; i < m; i++) {full += \"#\";}\nfirst += \"#\"; for(var i = 0; i < m - 1; i++) {first += \".\";}\nfor(var i = 0; i < m - 1; i++) {last += \".\";} last += \"#\";\n\nfor(var i = 0; i < n; i++) {\n\tif ((i + 1) % 2 === 1)\n\t\tprint(full);\n\telse if ((i + 1) % 4 === 0)\n\t\tprint(first);\n\telse \n\t\tprint(last);\n}"}, {"source_code": "\"use strict\";\n\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar m = input[1];\n\nvar a = new Array(m).fill('#').join('');\nvar b = new Array(m - 1).fill('.').join('') + '#';\nvar c = '#' + new Array(m - 1).fill('.').join('');\n\nvar d = [a, b, a, c];\n\nfor (let i = 0; i < n; ++i) {\n print(d[i % 4]);\n}\n"}, {"source_code": "X=readline().split(' ').map(i => parseInt(i))\nfor (var i=0; i {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n const rows = parseInt(line1[0]);\n const cols = parseInt(line1[1]);\n let snake = '';\n let turning = false;\n let direction = 'ltr';\n\n\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < cols; j++) {\n\n if (!turning) {\n snake += '#';\n } else {\n if (direction == 'rtl') {\n if (j === cols - 1)\n snake += '#';\n else\n snake += '.';\n } else {\n if (j === 0)\n snake += '#';\n else\n snake += '.';\n\n }\n }\n\n }\n\n\n if (!turning) {\n if (direction == 'rtl') {\n direction = 'ltr'\n } else {\n direction = 'rtl'\n }\n }\n\n turning = !turning;\n\n console.log(snake);\n snake = ''\n }\n\n});"}, {"source_code": "var input = readline().split(' ');var row = input[0];var coulmns = input[1];var result = \"\";var pin = 0;var pervious=0;\n\t\n\n\nfor (var i = 0; i < row; i++){\n\nif (pin == 0){\n\tfor(var s = 0; s < coulmns; s++){result+=\"#\";}\n pin=1;print(result); result=\"\";\n }else{\n \n for(var d = 0; d < (coulmns-1); d++){result+=\".\";}\n\n if(pervious == 0){result+=\"#\";pervious=\"1\";}else{result=\"#\" + result;pervious=\"0\";} \n pin=0;print(result);result=\"\";}}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const [r, c] = d.split(' ').map(Number);\n let isStart = false;\n let body = '#';\n let empty = '.';\n\n for (let i = 0; i < r; i++) {\n let ans = '';\n for (let j = 0; j < c; j++) {\n if (i % 2 === 0) {\n ans += body;\n }\n else{\n ans += empty;\n }\n }\n\n if (i % 2 !== 0) {\n if (isStart) {\n ans = body + ans.slice(1);\n }\n else {\n ans = ans.slice(0, ans.length - 1) + body;\n }\n isStart = !isStart;\n }\n\n console.log(ans);\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const [r, c] = d.split(' ').map(Number);\n let isStart = false;\n let body = '#';\n let empty = '.';\n let ans;\n\n for (let i = 0; i < r; i++) {\n if (i % 2 === 0) {\n ans = body.repeat(c);\n }\n else {\n ans = isStart ? body + empty.repeat(c - 1) : empty.repeat(c - 1) + body;\n isStart = !isStart;\n }\n\n console.log(ans);\n }\n});\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n let info = txt[i].split(\" \");\n doit(info[0] * 1, info[1] * 1);\n}\n\nfunction doit(n, n1) {\n let drawing = \"\";\n for (let i = 1; i <= n; i++) {\n if (i % 2 == 1) {\n if (i != 1) {\n drawing = drawing.concat(\"\\n\");\n drawing = drawing.concat(new Array(n1).fill(\"#\").join(\"\"));\n } else {\n drawing = drawing.concat(new Array(n1).fill(\"#\").join(\"\"));\n }\n } else {\n drawing = drawing.concat(\"\\n\");\n if (i % 4 == 2) {\n drawing = drawing.concat(new Array(n1 - 1).fill(\".\").join(\"\"));\n drawing = drawing.concat(\"#\");\n } else {\n drawing = drawing.concat(\"#\");\n drawing = drawing.concat(new Array(n1 - 1).fill(\".\").join(\"\"));\n }\n }\n\n }\n console.log(drawing);\n\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split(' ');\n let completeSnake = '';\n let track = true;\n let snakeEmptyCell = '';\n let snakeCell = '';\n for (let i = 1; i <= +inputs[0]; i++) {\n\n if (i % 2 !== 0) {\n snakeCell = \"#\".repeat(+inputs[1]);\n completeSnake += snakeCell + '\\n';\n } else if (track) {\n snakeEmptyCell = \".\".repeat(+inputs[1] - 1) + '#';\n track = false;\n completeSnake += snakeEmptyCell + '\\n';\n }\n else {\n snakeEmptyCell = \"#\" + '.'.repeat(+inputs[1] - 1);\n track = true;\n completeSnake += snakeEmptyCell + '\\n';\n }\n\n }\n\n return completeSnake.toString();\n}\n\n\n\n\n"}], "negative_code": [{"source_code": "\n\nfunction answer(input){\n input = input.split(' ');\n var n = input[0];\n var m = input[1];\n var emptyLine = '';\n for(var i = 0; i < m; i++){\n emptyLine += '.';\n }\n var fullLine = emptyLine.replace('.','#');\n var snakeSideLine = emptyLine.slice(0,-1);\n var rightSnake = snakeSideLine+'#';\n var leftSnake = '#'+snakeSideLine;\n var output = [];\n var steps = [fullLine,leftSnake,fullLine,rightSnake];\n \n for(var i = 0; i < n; i++){\n output.push(steps[i%4]);\n }\n output.forEach(function(el){\n print(el);\n });\n}\n\nanswer(readline());"}, {"source_code": "///////////////////////////////////////////////////////////////////////////////\nfunction readNumber () { return Number(readline()); }\nfunction readNumbersArray () { return readline().split(' ').map(Number); }\nfunction algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }\n///////////////////////////////////////////////////////////////////////////////\n\nvar array = readNumbersArray();\nvar n = array[0], m = array[1];\n\nvar a = '';\nfor (var i = 0; i < m; i++) a += '#';\n\nvar ba = '#';\nfor (var i = 1; i < m; i++) ba += '-';\n\nvar ab = '';\nfor (var i = 1; i < m; i++) ab += '-';\nab += '#';\n\nvar result = [];\nfor (var i = 0; i < n; i++) result.push(a);\nfor (var i = 1; i < n; i += 4) result[i] = ab;\nfor (var i = 3; i < n; i += 4) result[i] = ba;\n\nprint(result.join('\\n'));"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nlet array = readline().getNumArray(),\n n = array[0],\n m = array[1],\n empty = '.',\n filled = '#',\n snake = [];\n\nfor (let i = 0; i < n; i++) {\n let str = '';\n for (let j = 0; j < m; j++) {\n if (i % 2 === 0) {\n str += filled;\n } else {\n if (j === m - 1) {\n str += filled;\n } else {\n str += empty;\n }\n }\n }\n snake.push(str);\n}\nfor (let i = 0; i < snake.length; i++){\n write(snake[i] + '\\n');\n};"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nlet array = readline().getNumArray(),\n n = array[0],\n m = array[1],\n empty = '.',\n filled = '#',\n snake = [];\n\nfor (let i = 0; i < n; i++) {\n let str = '';\n for (let j = 0; j < m; j++) {\n if (i % 2 === 0) {\n str += filled;\n } else {\n if (j === m - 1) {\n str += filled;\n } else {\n str += empty;\n }\n }\n }\n snake.push(str);\n}\nfor (let i = 0; i < snake.length; i++){\n write(snake[i]);\n};"}, {"source_code": "var inputs = readline().split(\" \");\nvar n = inputs[0]\nvar m = inputs[1]\nvar r = 1;\nvar str = \"\";\nfor (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n if (i%2 === 0)\n str += \"#\";\n else {\n if (r===1) {\n if (j!==n-1)\n str += \".\";\n else\n str += \"#\";\n }\n else if (r === 0) {\n if (j!==0)\n str += \".\";\n else\n str += \"#\";\n }\n }\n }\n if (i%2 !== 0) {\n if (r===1) r = 0;\n else r = 1;\n }\n str += '\\n'\n} \nprint(str)"}, {"source_code": "var inputs = readline().split(\" \");\nvar n = inputs[0]\nvar m = inputs[1]\nvar r = 1;\nvar str = \"\";\nfor (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n if (i%2 == 0)\n str += \"#\";\n else {\n if (r==1) {\n if (j!=n-1)\n str += \".\";\n else\n str += \"#\";\n }\n else if (r == 0) {\n if (j!=0)\n str += \".\";\n else\n str += \"#\";\n }\n }\n }\n if (i%2 != 0) {\n if (r==1) r = 0;\n else r = 1;\n }\n print(str)\n} "}, {"source_code": "var params = readline().split(\" \").map(value => +value);\nvar n = params[0], m = params[1];\nvar full = first = last = \"\";\n\nfor(var i = 0; i < n; i++) {full += \"#\";}\nfirst += \"#\"; for(var i = 0; i < n - 1; i++) {first += \".\";}\nfor(var i = 0; i < n - 1; i++) {last += \".\";} last += \"#\";\n\nfor(var i = 0; i < n; i++) {\n\tif ((i + 1) % 2 === 1)\n\t\tprint(full);\n\telse if ((i + 1) % 4 === 0)\n\t\tprint(first);\n\telse \n\t\tprint(last);\n}"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n const rows = parseInt(line1[0]);\n const cols = parseInt(line1[1]);\n let snake = '';\n let turning = false;\n let opposite = false;\n\n\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < cols; j++) {\n\n if (!turning) {\n snake += '#';\n } else {\n if (!opposite) {\n if (j === cols - 1)\n snake += '#';\n else\n snake += '.';\n } else {\n if (j === 0)\n snake += '#';\n else\n snake += '.';\n }\n }\n\n }\n\n if ((i + 1) % 3 === 0)\n opposite = !opposite;\n turning = !turning;\n console.log(snake);\n snake = ''\n }\n\n});"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n let info = txt[i].split(\" \");\n doit(info[0] * 1, info[1] * 1);\n}\n\nfunction doit(n, n1) {\n let drawing = \"\";\n for (let i = 1; i <= n; i++) {\n if (i % 2 == 1) {\n if (n != 1) {\n drawing = drawing.concat(\"\\n\");\n drawing = drawing.concat(new Array(n1).fill(\"#\").join(\"\"));\n } else {\n drawing = drawing.concat(new Array(n1).fill(\"#\").join(\"\"));\n }\n } else {\n drawing = drawing.concat(\"\\n\");\n if (i % 4 == 2) {\n drawing = drawing.concat(new Array(n1 - 1).fill(\".\").join(\"\"));\n drawing = drawing.concat(\"#\");\n } else {\n drawing = drawing.concat(\"#\");\n drawing = drawing.concat(new Array(n1 - 1).fill(\".\").join(\"\"));\n }\n }\n\n }\n console.log(drawing);\n\n}"}], "src_uid": "2a770c32d741b3440e7f78cd5670d54d"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tvar map = new Array(N);\r\n\t\tvar fx = -1;\r\n\t\tvar fy = -1;\r\n\t\tvar sx = -1;\r\n\t\tvar sy = -1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tmap[j] = new Array(N);\r\n\t\t\tlist[j] = nextCharArray();\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tmap[j][k] = new Array(2).fill(false);\r\n\t\t\t\tif(list[j][k] == \"*\"){\r\n\t\t\t\t\tif(fx == -1){\r\n\t\t\t\t\t\tfx = k;\r\n\t\t\t\t\t\tfy = j;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tsx = k;\r\n\t\t\t\t\t\tsy = j;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isSame = false;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar count = 0;\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tcount += (list[j][k] == \"*\") ? 1 : 0;\r\n\t\t\t}\r\n\t\t\tif(count == 2){\r\n\t\t\t\tisSame = \"yoko\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar count = 0;\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tcount += (list[k][j] == \"*\") ? 1 : 0;\r\n\t\t\t}\r\n\t\t\tif(count == 2){\r\n\t\t\t\tisSame = \"tate\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar count = 0;\r\n\t\tif(isSame == \"yoko\"){\r\n\t\t\tlist[(fy + 1) % N][fx] = \"*\";\r\n\t\t\tlist[(sy + 1) % N][sx] = \"*\";\r\n\t\t\t\r\n\t\t}else if(isSame == \"tate\"){\r\n\t\t\tlist[fy][(fx + 1) % N] = \"*\";\r\n\t\t\tlist[sy][(sx + 1) % N] = \"*\";\r\n\t\t}else{\r\n\t\t\t\r\n\t\t\twhile(fx + count < N || fx - count >= 0 || fy + count < N || fy - count >= 0){\r\n\t\t\t\tif(fx + count < N){\r\n\t\t\t\t\tmap[fy][fx + count][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fx - count >= 0){\r\n\t\t\t\t\tmap[fy][fx - count][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fy + count < N){\r\n\t\t\t\t\tmap[fy + count][fx][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fy - count >= 0){\r\n\t\t\t\t\tmap[fy - count][fx][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t\tcount = 0;\r\n\t\t\twhile(sx + count < N || sx - count >= 0 || sy + count < N || sy - count >= 0){\r\n\t\t\t\tif(sx + count < N){\r\n\t\t\t\t\tmap[sy][sx + count][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sx - count >= 0){\r\n\t\t\t\t\tmap[sy][sx - count][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sy + count < N){\r\n\t\t\t\t\tmap[sy + count][sx][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sy - count >= 0){\r\n\t\t\t\t\tmap[sy - count][sx][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\t\tif(map[j][k][0] && map[j][k][1]){\r\n\t\t\t\t\t\tlist[j][k] = \"*\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\toutput.push(myconv(list[j], 0));\r\n\t\t}\r\n\t\tmyout(myconv(output, 9));\r\n\t}\r\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var i1, j1, i2, j2;\r\n\r\n var foundFirst = false;\r\n\r\n for (var k = 0; k < n; k++) {\r\n var str = readline().split('');\r\n matr.push(str);\r\n\r\n for (var m = 0; m < n; m++) {\r\n if (str[m] === '*') {\r\n if (!foundFirst) {\r\n i1 = k;\r\n j1 = m;\r\n foundFirst = true;\r\n } else {\r\n i2 = k;\r\n j2 = m;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (i1 === i2) {\r\n if (i1 + 1 < n) {\r\n matr[i1 + 1][j2] = '*';\r\n matr[i2 + 1][j1] = '*';\r\n } else {\r\n matr[i1 - 1][j2] = '*';\r\n matr[i2 - 1][j1] = '*';\r\n }\r\n } else if (j1 === j2) {\r\n if (j1 + 1 < n) {\r\n matr[i1][j2 + 1] = '*';\r\n matr[i2][j1 + 1] = '*';\r\n } else {\r\n matr[i1][j2 - 1] = '*';\r\n matr[i2][j1 - 1] = '*';\r\n }\r\n } else {\r\n matr[i1][j2] = '*';\r\n matr[i2][j1] = '*';\r\n }\r\n\r\n for (var k = 0; k < n; k++) {\r\n print(matr[k].join(''));\r\n }\r\n}\r\n"}, {"source_code": "\r\nfunction solution() {\r\n var t = parseInt(readline());\r\n for (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var matrix = [];\r\n var corners = [];\r\n for (var j = 0; j < n; j++) {\r\n var row = readline().split(\"\");\r\n var corner = row.indexOf(\"*\");\r\n if (corner !== -1) {\r\n var corner2 = row.indexOf(\"*\", corner + 1);\r\n if (corner2 !== -1) {\r\n corners.push({row:j,col:corner});\r\n corners.push({row:j,col:corner2});\r\n } else {\r\n corners.push({row:j,col:corner});\r\n }\r\n }\r\n\r\n matrix.push(row);\r\n }\r\n if (corners.length === 2) {\r\n if (corners[0].col === corners[1].col) {\r\n if (matrix[corners[0].row][corners[0].col + 1]) {\r\n matrix[corners[0].row][corners[0].col + 1] = \"*\";\r\n matrix[corners[1].row][corners[1].col + 1] = \"*\";\r\n } else if (matrix[corners[0].row][corners[0].col - 1]) {\r\n matrix[corners[0].row][corners[0].col - 1] = \"*\";\r\n matrix[corners[1].row][corners[1].col - 1] = \"*\";\r\n }\r\n }\r\n if (corners[0].row === corners[1].row) {\r\n if (matrix[corners[0].row + 1]) {\r\n matrix[corners[0].row + 1][corners[0].col] = \"*\";\r\n matrix[corners[1].row + 1][corners[1].col] = \"*\";\r\n } else if (matrix[corners[0].row - 1]) {\r\n matrix[corners[0].row - 1][corners[0].col] = \"*\";\r\n matrix[corners[1].row - 1][corners[1].col] = \"*\";\r\n }\r\n }\r\n if (corners[0].col !== corners[1].col && corners[0].row !== corners[1].row) {\r\n matrix[corners[0].row][corners[1].col] = \"*\";\r\n matrix[corners[1].row][corners[0].col] = \"*\";\r\n }\r\n }\r\n for (var k = 0; k < matrix.length; k++) {\r\n print(matrix[k].join(\"\"));\r\n }\r\n }\r\n}\r\n\r\nsolution();\r\n"}, {"source_code": "l = readline;\r\n\r\nfor (T=l(); T--;) {\r\n \r\n n = +l();\r\n c = [];\r\n A = [];\r\n row = false;\r\n for (i = 0; i < n; i++) {\r\n A.push(k = l().split(''))\r\n p = k.indexOf('*')\r\n if (p >= 0) {\r\n c.push([i, p]);\r\n }\r\n p = k.indexOf('*',p+1)\r\n if (p >= 0) {\r\n c.push([i, p]);\r\n \r\n row = true;\r\n }\r\n }\r\n\r\n \r\n d = Math.max(Math.abs(c[0][1] - c[1][0]), Math.abs(c[1][1] - c[0][0]))\r\n\r\n for (k = 0; k < 2; k++) {\r\n x = c[k][0];\r\n y = c[k][1];\r\n \r\n if (c[0][0] === c[1][0]) {\r\n if (x+d > n-1) {\r\n x -= d;\r\n } else {\r\n x += d;\r\n }\r\n \r\n } else if (c[0][1] === c[1][1]) {\r\n if (y+d > n-1) {\r\n y -= d;\r\n } else {\r\n y += d;\r\n }\r\n \r\n } else {\r\n x = c[(k+1) % 2][1];\r\n x = c[(k+1) % 2][0];\r\n \r\n }\r\n A[x][y] = '*';\r\n }\r\n \r\n print(A.map(x => x.join('')).join('\\n'))\r\n \r\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above and then write your logic in `main`\n\nconst makeSquareArray = (squareLength) => {\n const squareString = [];\n\n Array.from({ length: squareLength }).forEach(() => {\n const stringArray = readline().split(\"\");\n squareString.push(stringArray);\n });\n\n return squareString;\n};\n\nconst getCoordinates = (squareString) => {\n const cellCoords = [];\n for (let x = 0; x < squareString.length; x++) {\n const row = squareString[x];\n for (let y = 0; y < row.length; y++) {\n if (row[y] === \"*\") {\n cellCoords.push({ x, y });\n }\n if (cellCoords.length === 2) {\n return cellCoords;\n }\n }\n }\n};\n\nconst normalizeSet = (coordsSet) => {\n if (coordsSet.size === 1) {\n coordsSet.add(0);\n }\n\n if (coordsSet.size === 1) {\n coordsSet.add(1);\n }\n\n return coordsSet;\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const squareLength = 1 * readline();\n\n let squareString = makeSquareArray(squareLength);\n\n const [pointOne, pointTwo] = getCoordinates(squareString);\n // console.log(\"cells\", coords);\n\n let xSet = new Set();\n xSet.add(Math.min(pointOne.x, pointTwo.x));\n xSet.add(Math.max(pointOne.x, pointTwo.x));\n xSet = normalizeSet(xSet);\n\n let ySet = new Set();\n ySet.add(Math.min(pointOne.y, pointTwo.y));\n ySet.add(Math.max(pointOne.y, pointTwo.y));\n ySet = normalizeSet(ySet);\n\n for (let x of xSet) {\n for (let y of ySet) {\n squareString[x][y] = \"*\";\n }\n }\n\n // console.log(squareString);\n squareString.forEach((line) => {\n console.log(line.join(\"\"));\n });\n });\n};\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above and then write your logic in `main`\n\nconst makeSquareArray = (squareLength) => {\n const squareString = [];\n\n Array.from({ length: squareLength }).forEach(() => {\n squareString.push(readline().split(\"\"));\n });\n\n return squareString;\n};\n\nconst getCoordinates = (squareString) => {\n const cells = [];\n for (let i = 0; i < squareString.length; i++) {\n const row = squareString[i];\n for (let j = 0; j < row.length; j++) {\n if (row[j] === \"*\") {\n cells.push([i, j]);\n }\n if (cells.length === 2) {\n return cells;\n }\n }\n }\n};\n\nconst normalizeSet = (coordsSet) => {\n if (coordsSet.size === 1) {\n coordsSet.add(0);\n }\n\n if (coordsSet.size === 1) {\n coordsSet.add(1);\n }\n\n return coordsSet;\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const squareLength = 1 * readline();\n\n let squareString = makeSquareArray(squareLength);\n\n const coords = getCoordinates(squareString);\n // console.log(\"cells\", coords);\n\n let xs = new Set();\n xs.add(Math.min(coords[0][0], coords[1][0]));\n xs.add(Math.max(coords[0][0], coords[1][0]));\n xs = normalizeSet(xs);\n\n let ys = new Set();\n ys.add(Math.min(coords[0][1], coords[1][1]));\n ys.add(Math.max(coords[0][1], coords[1][1]));\n ys = normalizeSet(ys);\n\n for (let x of xs) {\n for (let y of ys) {\n squareString[x][y] = \"*\";\n }\n }\n\n // console.log(squareString);\n squareString.forEach((line) => {\n console.log(line.join(\"\"));\n });\n });\n};\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n for (let i = 0; i < testCases; i++) {\r\n let a,b,c,d;\r\n let matixSize = +input[z++];\r\n for (let i = 0; i < matixSize; i++) {\r\n let str = input[z++].split('');\r\n for (let j = 0; j < matixSize; j++) {\r\n if(str[j] == \"*\" && a == undefined){\r\n a = i + 1;\r\n b = j + 1;\r\n }\r\n if(str[j] == \"*\" && a != undefined){\r\n c = i + 1;\r\n d = j + 1;\r\n }\r\n }\r\n }\r\n let e = d;\r\n let f = b;\r\n for (let i = 0; i < matixSize; i++) {\r\n let str = \"\";\r\n for (let j = 0; j < matixSize; j++) {\r\n if(b == d && (((i + 1 == a && j + 1 == (b + 1 > matixSize ? b - 1 : b + 1))) || \r\n ((i + 1 == c && j + 1 == (d+1 > matixSize ? d-1:d+1)))) && a != c){\r\n str += \"*\";\r\n }\r\n else if(a == c && (((i + 1 == (a-1 <= 0 ? a + 1 : a-1)&& j + 1 == b)) || \r\n ((i + 1 == (c-1 <= 0 ? c + 1 : c - 1) && j + 1 == d))) && b != d){\r\n str += \"*\";\r\n }\r\n else if(b == d && ((i + 1 == a && j + 1 == a) || (i + 1 == b && j + 1 == a)) && a == c){\r\n str += \"*\";\r\n }\r\n else if(a == c && ((i + 1 == d && j + 1 == a) || (i + 1 == d && j + 1 == d)) && b == d){\r\n str += \"*\";\r\n }\r\n else if((i+1 == a && j+1 == b) || (i+1 == c && j+1 == d) || (i+1 == a && j+1 == e) || \r\n (i+1 == c && j+1 == f)){\r\n str += \"*\";\r\n }\r\n else{\r\n str += \".\"\r\n }\r\n }\r\n console.log(str);\r\n }\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (a[i][j] == '*') {\r\n res.push([i, j]);\r\n }\r\n }\r\n }\r\n let f = res[0];\r\n let s = res[1];\r\n let fx = f[0];\r\n let fy = f[1];\r\n let sx = s[0];\r\n let sy = s[1];\r\n if (fx == sx) {\r\n if (fx == 0) {\r\n a[fx + 1][fy] = '*';\r\n a[sx + 1][sy] = '*';\r\n } else {\r\n a[fx - 1][fy] = '*';\r\n a[sx - 1][sy] = '*';\r\n }\r\n } else if (fy == sy) {\r\n if (fy == 0) {\r\n a[fx][fy + 1] = '*';\r\n a[sx][sy + 1] = '*';\r\n } else {\r\n a[fx][fy - 1] = '*';\r\n a[sx][sy - 1] = '*';\r\n }\r\n } else {\r\n a[fx][fy] = '*';\r\n a[fx][sy] = '*';\r\n a[sx][fy] = '*';\r\n a[sx][sy] = '*';\r\n }\r\n let ans = a.map(x => x.join(\"\"));\r\n for (const e of ans) pr(e);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = Number(input[i]);\r\n let tmp = input.slice(i + 1, i + n + 1);\r\n tmp = tmp.map(s => s.split(\"\"));\r\n solve(n, tmp);\r\n i += n + 1;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\n// hello world\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = [];\nvar s = \"\";\nvar currentLine = 0;\nprocess.stdin.on('data', function (inputStdin) {\n s += inputStdin;\n});\nprocess.stdin.on('end', function (_) {\n inputString = s.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n s = null;\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction readIntLine() {\n return inputString[currentLine++].split(\" \").map(function (e) { return parseInt(e); });\n}\nvar println = console.log;\n// CODE\nfunction main() {\n var t = readIntLine()[0];\n var _loop_1 = function (i) {\n //parsing\n var n = readIntLine()[0];\n var arr = [];\n for (var i_1 = 0; i_1 < n; i_1++) {\n arr.push(readline());\n }\n var a = null, b = null;\n // -> find a and b pos\n arr.forEach(function (s, y) {\n for (var i_2 = 0; i_2 < s.length; i_2++) {\n var p = s[i_2] == \"*\" ? i_2 : -1;\n if (p != -1) {\n if (!a) {\n a = { y: y, x: p };\n }\n else {\n b = { y: y, x: p };\n }\n }\n }\n });\n var c = void 0, d = void 0;\n //check special cases\n if (a.x == b.x) {\n c = a.x == 0 ? { y: a.y, x: a.x + 1 } : { y: a.y, x: a.x - 1 };\n d = b.x == 0 ? { y: b.y, x: b.x + 1 } : { y: b.y, x: b.x - 1 };\n }\n else if (a.y == b.y) {\n c = a.y == 0 ? { y: a.y + 1, x: a.x } : { y: a.y - 1, x: a.x };\n d = b.y == 0 ? { y: b.y + 1, x: b.x } : { y: b.y - 1, x: b.x };\n }\n else {\n c = { x: a.x, y: b.y };\n d = { x: b.x, y: a.y };\n }\n //include c and d in the array\n arr[c.y] = arr[c.y].slice(0, c.x) + \"*\" + arr[c.y].slice(c.x + 1);\n arr[d.y] = arr[d.y].slice(0, d.x) + \"*\" + arr[d.y].slice(d.x + 1);\n println(arr.join(\"\\n\"));\n };\n for (var i = 0; i < t; i++) {\n _loop_1(i);\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n const n = parseInt(readline());\r\n // var [n, p, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = new Array(n)\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n }\r\n var x1, y1\r\n var x2, y2\r\n\r\n for (let j = 0; j < n; j++) {\r\n for (let i = 0; i < n; i++) {\r\n if (a[i][j] === '*' && x1 === undefined) {\r\n x1 = i\r\n y1 = j\r\n continue\r\n }\r\n if (a[i][j] === '*' && x2 === undefined) {\r\n x2 = i\r\n y2 = j\r\n }\r\n }\r\n }\r\n // console.log(x1,y1,x2,y2)\r\n\r\n if (x1 === x2) {\r\n var add = x1 > 0 ? -1 : +1\r\n a[x1 + add][y1] = '*'\r\n a[x1 + add][y2] = '*'\r\n } else if (y1 === y2) {\r\n add = y1 > 0 ? -1 : +1\r\n\r\n a[x1][y1 + add] = '*'\r\n a[x2][y1 + add] = '*'\r\n\r\n } else {\r\n a[x1][y2] = '*'\r\n a[x2][y1] = '*'\r\n }\r\n\r\n for (let j = 0; j < n; j++) {\r\n console.log(a[j].join(''))\r\n\r\n }\r\n\r\n })\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n for (let i = 0; i < testCases; i++) {\r\n let a,b,c,d;\r\n let matixSize = +input[z++];\r\n for (let i = 0; i < matixSize; i++) {\r\n let str = input[z++].split('');\r\n for (let j = 0; j < matixSize; j++) {\r\n if(str[j] == \"*\" && a == undefined){\r\n a = i + 1;\r\n b = j + 1;\r\n }\r\n if(str[j] == \"*\" && a != undefined){\r\n c = i + 1;\r\n d = j + 1;\r\n }\r\n }\r\n }\r\n let e = d;\r\n let f = b;\r\n for (let i = 0; i < matixSize; i++) {\r\n let str = \"\";\r\n for (let j = 0; j < matixSize; j++) {\r\n if(b == d && (((i + 1 == a && j + 1 == b+1) || (i + 1 == a && j + 1 == b - 1)) || \r\n ((i + 1 == c && j + 1 == d+1) || (i + 1 == c && j + 1 == d - 1))) && a != c){\r\n str += \"*\";\r\n }\r\n else if(a == c && (((i + 1 == a-1&& j + 1 == b) || (i + 1 == a+1 && j + 1 == b)) || \r\n ((i + 1 == c-1 && j + 1 == d) || (i + 1 == c+1 && j + 1 == d))) && b != d){\r\n str += \"*\";\r\n }\r\n else if(b == d && ((i + 1 == a && j + 1 == a) || (i + 1 == b && j + 1 == a)) && a == c){\r\n str += \"*\";\r\n }\r\n else if(a == c && ((i + 1 == d && j + 1 == a) || (i + 1 == d && j + 1 == d)) && b == d){\r\n str += \"*\";\r\n }\r\n else if((i+1 == a && j+1 == b) || (i+1 == c && j+1 == d) || (i+1 == a && j+1 == e) || \r\n (i+1 == c && j+1 == f)){\r\n str += \"*\";\r\n }\r\n else{\r\n str += \".\"\r\n }\r\n }\r\n console.log(str);\r\n }\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (a[i][j] == '*') {\r\n res.push([i, j]);\r\n }\r\n }\r\n }\r\n let f = res[0];\r\n let s = res[1];\r\n let fx = f[0];\r\n let fy = f[1];\r\n let sx = s[0];\r\n let sy = s[1];\r\n // pr(f, s);\r\n if (fx == sx) {\r\n if (fx == 0) {\r\n a[fx + 1][fy] = '*';\r\n a[sx + 1][sy] = '*';\r\n } else {\r\n a[fx - 1][fy] = '*';\r\n a[sx - 1][sy] = '*';\r\n }\r\n } else if (fy == sy) {\r\n if (fy == 0) {\r\n a[fx][fy + 1] = '*';\r\n a[sx][sy + 1] = '*';\r\n } else {\r\n a[fx][fy - 1] = '*';\r\n a[sx][sy - 1] = '*';\r\n }\r\n } else {\r\n a[fx][fy] = '*';\r\n a[fx][sy] = '*';\r\n a[sx][fy] = '*';\r\n a[sx][sy] = '*';\r\n }\r\n // pr(a);\r\n let ans = a.map(x => x.join(\"\"));\r\n // pr(ans);\r\n for (const e of ans) pr(e);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0][0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = Number(input[i]);\r\n let tmp = input.slice(i + 1, i + n + 1);\r\n tmp = tmp.map(s => s.split(\"\"));\r\n solve(n, tmp);\r\n i += n + 1;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tvar map = new Array(N);\r\n\t\tvar fx = -1;\r\n\t\tvar fy = -1;\r\n\t\tvar sx = -1;\r\n\t\tvar sy = -1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tmap[j] = new Array(N);\r\n\t\t\tlist[j] = nextCharArray();\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tmap[j][k] = new Array(2).fill(false);\r\n\t\t\t\tif(list[j][k] == \"*\"){\r\n\t\t\t\t\tif(fx == -1){\r\n\t\t\t\t\t\tfx = k;\r\n\t\t\t\t\t\tfy = j;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tsx = k;\r\n\t\t\t\t\t\tsy = j;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isSame = false;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar count = 0;\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tcount += (list[j][k] == \"*\") ? 1 : 0;\r\n\t\t\t}\r\n\t\t\tif(count == 2){\r\n\t\t\t\tisSame = \"yoko\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar count = 0;\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tcount += (list[k][j] == \"*\") ? 1 : 0;\r\n\t\t\t}\r\n\t\t\tif(count == 2){\r\n\t\t\t\tisSame = \"tate\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar count = 0;\r\n\t\tif(isSame == \"yoko\"){\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\t\tif(list[j][k] == \"*\"){\r\n\t\t\t\t\t\tif(count == 2){\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tlist[(k + N - 1) % N][j] = \"*\";\r\n\t\t\t\t\t\tcount++;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}else if(isSame == \"tate\"){\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\t\tif(list[j][k] == \"*\"){\r\n\t\t\t\t\t\tif(count == 2){\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tlist[j][(k + N - 1) % N] = \"*\";\r\n\t\t\t\t\t\tcount++;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\t\r\n\t\t\twhile(fx + count < N || fx - count >= 0 || fy + count < N || fy - count >= 0){\r\n\t\t\t\tif(fx + count < N){\r\n\t\t\t\t\tmap[fy][fx + count][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fx - count >= 0){\r\n\t\t\t\t\tmap[fy][fx - count][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fy + count < N){\r\n\t\t\t\t\tmap[fy + count][fx][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(fy - count >= 0){\r\n\t\t\t\t\tmap[fy - count][fx][0] = true;\r\n\t\t\t\t}\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t\tcount = 0;\r\n\t\t\twhile(sx + count < N || sx - count >= 0 || sy + count < N || sy - count >= 0){\r\n\t\t\t\tif(sx + count < N){\r\n\t\t\t\t\tmap[sy][sx + count][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sx - count >= 0){\r\n\t\t\t\t\tmap[sy][sx - count][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sy + count < N){\r\n\t\t\t\t\tmap[sy + count][sx][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(sy - count >= 0){\r\n\t\t\t\t\tmap[sy - count][sx][1] = true;\r\n\t\t\t\t}\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\t\tif(map[j][k][0] && map[j][k][1]){\r\n\t\t\t\t\t\tlist[j][k] = \"*\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\toutput.push(myconv(list[j], 0));\r\n\t\t}\r\n\t\tmyout(myconv(output, 9));\r\n\t}\r\n}"}], "src_uid": "d8fb3822b983b8a8ffab341aee74f56f"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n output[i] = Math.floor(N / 2) + 1\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n console.log(Math.floor(n / 2) + 1);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n \n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n\n console.log(Math.floor(n/2) + 1);\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n console.log(Math.floor(num / 2) + 1);\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n console.log(n < 3 ? n : (n < 5 ? n - 1 : n - 2));\n }\n}\n"}], "src_uid": "eb39ac8d703516c7f81f95a989791b21"} {"source_code": "'use strict'\n\nconst x = [ 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683 ];\nlet p = [ 0 ];\nfor (let i = 0; i < x.length; i++) p = p.concat(p.map(j => j + x[i]));\nlet q = +readline();\nwhile(q--) { const j = +readline(); print(p[p.findIndex(i => i >= j)]); }\n", "positive_code": [{"source_code": "'use strict'\n\nconst lst = Array.from({ length: 32 }, (_, i) => Math.pow(3,i)).reverse();\n\nconst m = lst.reduce((r, i) => r + i, 0);\n\nfor(let t = +readline(); t; t--) {\n const n = +readline();\n let x = m;\n lst.forEach(i => (x - i >= n) && (x -= i))\n print(x);\n}\n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nvar gcd = (a, b) => a ? gcd(b % a, a) : b;\nvar lcm = (a, b) => a * b / gcd(a, b);\nconst getAllSubsets = \n theArray => theArray.reduce(\n (subsets, value) => subsets.concat(\n subsets.map(set => [value,...set])\n ),\n [[]]\n );\n\nlet ar = [];\n\nfor(let i=0; i<10;++i){\n\tlet x = 3**i;\n\tar.push(x);\n}\n\nlet arr = getAllSubsets(ar);\n// console.log(arr);\narr.splice(0,1);\nlet arrr =[];\nlet j=0;\nfor (let x of arr){\n\tarrr[j++]= x.reduce((acc,cur)=> acc+cur);\n}\n\n// console.log(arrr);\n\nfunction main(){\n\tlet q = +(readLine());\n\n\twhile(q--){\n\t\tlet n = +(readLine());\n\n\t\tlet p = arrr.filter(x=> x>=n)[0];\n\t\tconsole.log(p)\n\n\t}\n}\n"}], "negative_code": [], "src_uid": "5953b898995a82edfbd42b6c0f7138af"} {"source_code": ";(function () {\n\n\tprint(function (n, m) {\n\n\t\tvar price = readline().split(' ').map(Number), sum = 0;\n\n\t\tfor (var i = 0; i < m; ++i) {\n\t\t\tvar s = readline().split(' ').map(function (e) { return +e - 1; });\n\t\t\tsum += Math.min(price[s[0]], price[s[1]]);\n\t\t}\n\n\t\treturn sum;\n\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n\t\tcosts = tokenizeIntegers(readline()),\n\t\ttotal = 0;\n\tcosts.unshift(null);\n\tfor (var i = 0; i < m; ++i) {\n\t\tdata = tokenizeIntegers(readline());\n\t\tvar u = data[0], v = data[1];\n\t\tif (costs[u] >= costs[v]) {\n\t\t\ttotal += costs[v];\n\t\t} else {\n\t\t\ttotal += costs[u];\n\t\t}\n\t}\n\tprint(total);\n}\n\nmain();\n"}, {"source_code": "var firstLine = readline().split(\" \").map(Number);\nvar n = firstLine[0];\nvar m = firstLine[1];\n\nvar secondLine = readline().split(\" \").map(Number);\nvar energies = []\nsecondLine.forEach(function(a){energies.push(a)});\n\nvar total = 0\n\nenergies.unshift(null)\n\nfor(var i = 0; i < m; ++i){\n\tdata = readline().split(\" \").map(Number);\n\tvar x = data[0]\n\tvar y = data[1]\n\tif(energies[x] >= energies[y]){\n\t\ttotal+= energies[y]\n\t}\n\telse{\n\t\ttotal+= energies[x]\n\t}\n}\n\nprint(total)\n\n"}], "negative_code": [], "src_uid": "2e6bf9154d9da6ac134b52144d5322ca"} {"source_code": "var x = parseInt(readline());\n\nswitch (x % 3) {\n case 2:\n print(1, 2, x - 3);\n break;\n default:\n print(1, 1, x - 2);\n break;\n}\n", "positive_code": [{"source_code": "\tvar n=parseInt(readline());\n\tif((n-2)%3===0){print(\"1 \"+\"2 \"+(n-3));}\n\telse{print(\"1 \"+\"1 \"+(n-2));}"}, {"source_code": "var input = Number(readline());\n\nif(input == 3) {\n print(\"1 1 1\");\n}\n\nelse if(input>3) {\n if((input-3)%3 == 0) {\n print(\"2 2 \" +(input-4));\n }\n else {\n print(\"1 2 \"+ (input-3));\n }\n}"}, {"source_code": "function func(){\n\tvar n = parseInt(readline());\n\tvar x = (n-2)%3?1:2;\n\t// console.log(1,x,n-x-1);\n\tprint(1,x,n-x-1);\n}\nfunc();"}, {"source_code": "// var n = 233;\nfunction func(){\n\tvar n = parseInt(readline());\n\tvar x = Math.floor(n/3);\n\tvar y = n%3;\n\tvar t = x%3;\n\tvar a,b,c;\n\tif(x === 1){\n\t\tif(y === 0){\n\t\t\ta = b = c = x;\n\t\t}else if(y === 1){\n\t\t\ta = b = x;\n\t\t\tc = x+y;\n\t\t}else {\n\t\t\ta = x;\n\t\t\tb = c = x+1;\n\t\t}\n\t}else {\n\t\tif(t===0){\n\t\t\tif(y === 1){\n\t\t\t\ta = x-1;\n\t\t\t\tb = c = x+1;\n\t\t\t}else{\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}\n\t\t}else if(t===1){\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}else{\n\t\t\t\ta = x;\n\t\t\t\tb = c = x+y/2;\n\t\t\t}\n\t\t}else {\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}else{\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}\n\t\t}\n\t}\n\tprint(a,b,c);\n\t// console.log(a,b,c)\n}\nfunc();"}, {"source_code": "function main(){\n var n = parseInt(readline());\n var result = \"\";\n var item = parseInt(n/3);\n var adjust = n % 3;\n\n if((item + adjust) % 3 === 0){\n if( item % 3 === 0){\n result = (item + 2) + \" \" + (item - 1) + \" \" + (item + adjust - 1)\n }else{\n result = item + \" \" + ( item + 3 - adjust )+ \" \" + (item + 2 * adjust - 3)\n }\n }else{\n if( item % 3 === 0){\n result = (item + 1) + \" \" + (item - 1) + \" \" + (item + adjust)\n }else{\n result = item + \" \" + item + \" \" + (item + adjust)\n }\n }\n print(result)\n}\n\n\nmain()"}, {"source_code": "\nfunction main() {\n const cin = new Scanner();\n let n = cin.nextInt() - 1;\n let a = 1, b = Math.trunc(n / 2), c = Math.ceil(n / 2);\n if (b % 3 === 0 || c % 3 === 0) {\n b -= 1;\n c += 1;\n }\n\n console.log(a, b, c);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = Number) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); });\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const readline = require('readline').createInterface({input: process.stdin})\nconst assert = require('assert')\n\nlet n, x, y, z\nreadline.on('line', line => {\n n = parseInt(line)\n if (n == 3) {\n [x, y, z] = [1, 1, 1]\n } else if (n % 3 == 0) {\n [x, y, z] = [1, 4, n - 5]\n } else {\n [x, y, z] = [1, 2, n - 3]\n }\n console.log(`${x} ${y} ${z}`)\n})\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tif(N % 3 == 2){\n\t\tmyout((N - 3) + \" 2 1\");\n\t}else{\n\t\tmyout((N - 2) + \" 1 1\");\n\t}\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n let n = +d;\n let a = 1;\n let b = Math.floor((n - 1) / 2);\n let c = Math.ceil((n - 1) / 2);\n\n while (b % 3 === 0 || c % 3 === 0) {\n b--;\n c++;\n }\n\n console.log(a, b, c);\n});\n"}, {"source_code": "var cnt = 0;\nprocess.stdin.addListener(\"data\", function(d) {\n\tvar s = d.toString().trim();\n\tvar x = parseInt(s);\n\tif( x%3 === 0){\n process.stdout.write(x-2+' 1 1');\n } \n\telse {\n //if(x==3) process.stdout.write('1 1 1');\n process.stdout.write(x-3+' 1 2');\n \n }\n cnt++;\n if(cnt > 0) process.exit();\n // process.exit();\n});"}, {"source_code": "var num = readline();\n\nif (num == 3) {\n print(\"1 1 1\");\n}\n\nelse if (num > 3) {\n if ((num - 3) % 3 == 0) {\n print(\"2 2 \" + (num - 4));\n }\n else {\n print(\"1 2 \" + (num - 3));\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet hand = []\nrl.on('line', (input) => {\n if (l === 0) {\n rl.close();\n let n = parseInt(input)\n if((n-2)%3===0)\n console.log(1,2,n-3) \n else\n console.log(1,1,n-2) \n }\n})\n"}, {"source_code": "var a = readline();\nprint(1);\nif ((a-1)%3 == 0){\n print (1);\n print (a-2);\n} else {\n if ((a-2)%3 == 0){\n print (2);\n print (a-3);\n } else {\n print (1);\n print (a-2);\n }\n}"}], "negative_code": [{"source_code": "var a = Number(readline());\nprint(1);\nif ((a-1)%3 === 0){\n print (1);\n print (a-2);\n} else {\n print (2);\n print (a-3);\n}"}, {"source_code": "var a = Number(readline());\n\nif ((a-1)%3 == 0){\n\tprint (\"1 1 \"+a-2);\n}\nif ((a-2)%3 == 0){\n\tprint (\"1 2 \" + a-3);\n}"}, {"source_code": "var a = readline();\nprint(1);\nif ((a-1)%3 === 0){\n print (1);\n print (a-2);\n} else {\n print (2);\n print (a-3);\n}"}, {"source_code": "var a = Number(readline());\nprint(1 + \" \");\nif ((a-1)%3 == 0){\n\tprint (1 + \" \");\n\tprint (a - 2);\n}\nif ((a-2)%3 == 0){\n\tprint (2 + \" \");\n\tprint (a-3);\n}"}, {"source_code": "var n=parseInt(readline());\n\tif((n-2)%3===0){print(\"1\"+\"2\"+(n-3));}\n\telse{print(\"1\"+\"1\"+(n-2));}"}, {"source_code": "\tvar n=parseInt(readline());\n\tif(n%3===0){print (n/3+\" \"+n/3+\" \"+n/3);}\n\telse{print (Math.floor(n/3)+\" \"+Math.floor(n/3)+\" \"+ (n-((Math.floor(n/3))*2)) );}"}, {"source_code": "var input = Number(readline());\n\nif((input%3) == 0) {\n var ans = input/3;\n if(ans%3 != 0) {\n print(ans +\" \"+ans+ \" \"+ ans);\n }\n else {\n print((ans+1) +\" \"+ (ans+1) +\" \"+(ans-2));\n }\n\n}\nelse {\n var rem = input%3;\n ans = Math.floor(input/3);\n print((ans +\" \"+ ans +\" \"+ (ans+rem)));\n}\n"}, {"source_code": "// var n = 233;\nfunction func(){\n\tvar n = parseInt(readline());\n\tvar x = Math.floor(n/3);\n\tvar y = n%3;\n\tvar t = x%3;\n\tvar a,b,c;\n\tif(x === 1){\n\t\tif(y === 0){\n\t\t\ta = b = c = x;\n\t\t}else if(y === 1){\n\t\t\ta = b = x;\n\t\t\tc = x+y;\n\t\t}else {\n\t\t\ta = x;\n\t\t\tb = c = x+1;\n\t\t}\n\t}else {\n\t\tif(t===0){\n\t\t\tif(y === 1){\n\t\t\t\ta = x-1;\n\t\t\t\tb = c = x+1;\n\t\t\t}else{\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}\n\t\t}else if(t===1){\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}else{\n\t\t\t\ta = x;\n\t\t\t\tb = c = x+1;\n\t\t\t}\n\t\t}else {\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}else{\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}\n\t\t}\n\t}\n\tprint(a,b,c);\n\t// console.log(a,b,c)\n}\nfunc();"}, {"source_code": "// var n = 233;\nfunction func(n){\n\tvar n = parseInt(readline());\n\tvar x = Math.floor(n/3);\n\tvar y = n%3;\n\tvar t = x%3;\n\tvar a,b,c;\n\tif(x === 1){\n\t\tif(y === 0){\n\t\t\ta = b = c = x;\n\t\t}else if(y === 1){\n\t\t\ta = b = x;\n\t\t\tc = x+y;\n\t\t}else {\n\t\t\ta = x;\n\t\t\tb = c = x+1;\n\t\t}\n\t}else {\n\t\tif(t===0){\n\t\t\tif(y === 1){\n\t\t\t\ta = x-1;\n\t\t\t\tb = c = x+1;\n\t\t\t}else{\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}\n\t\t}else if(t===1){\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}else{\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}\n\t\t}else {\n\t\t\tif(y === 1){\n\t\t\t\ta = b = x-1;\n\t\t\t\tc = x+y+2;\n\t\t\t}else{\n\t\t\t\ta = b = x;\n\t\t\t\tc = x+y;\n\t\t\t}\n\t\t}\n\t}\n\tprint(a,b,c);\n}\nfunc();"}, {"source_code": "function main(){\n var n = parseInt(readline());\n var result = \"\";\n var item = parseInt(n/3);\n var adjust = n % 3;\n if( item % 3 === 0){\n result = (item - 1) + \" \"+(item +1) + \" \" + (item + adjust)\n }else if((item + adjust) % 3 === 0){\n result = item + \" \" + ( item + 3 - adjust )+ \" \" + (item + 2 * adjust - 3)\n }else{\n result = item + \" \" + item + \" \" + (item + adjust)\n }\n print(result)\n}\n\n\nmain()"}, {"source_code": "var str = readline();\n//var str = 387420489;\nvar num = Math.round(str / 3);\n//alert(str + \" \" + num)\nvar salida;\nvar cantidadSumar = str - (num * 3);\n//alert(cantidadSumar);\n\nif (valido(num) == 1 && valido(num + cantidadSumar) == 1) {\n// alert(\"1\")\n salida = num + \" \" + num + \" \" + (num + cantidadSumar);\n} else if (valido(num) == -1 && cantidadSumar!=0) {\n// alert(\"2\")\n num = num + cantidadSumar;\n cantidadSumar = str - (num * 3);\n salida = num + \" \" + num + \" \" + (num + cantidadSumar);\n} else if (valido(num) == -1 && cantidadSumar == 0) {\n// alert(\"3\")\n salida = (num+1) + \" \" + (num+1) + \" \" + (num-2);\n}\n\n\nfunction valido(num) {\n if (num % 3 == 0) {\n return -1//No es v\u00e1lido\n } else return 1;\n}\n\nprint(salida)"}, {"source_code": "var str = readline();\n//var str = 1234;\nvar numCercano = Math.round(str / 3);\nwhile (divisible(numCercano) == -1) {\n numCercano++;\n}\nvar n1 = n2 = n3 = numCercano;\nif (numCercano * 3 != str) {\n var numSuma = str - (n1 + n2 + n3);\n if (divisible(n1 + numSuma) == 1) {\n n1 += numSuma;\n }\n}\n function divisible(num) {\n if (num % 3 == 0) {\n return -1//No es v\u00e1lido\n } else return 1;\n }\n\nprint(n1 + \" \" + n2 + \" \" + n3)"}, {"source_code": "var str = readline();\n//var str = 233;\nvar numCercano = Math.round(str / 3);\nwhile (divisible(numCercano)==-1) {\n numCercano--;\n}\nvar n1 = n2 = n3 = numCercano;\nvar numSuma = str - (n1+n2+n3);\nif (divisible(n1+numSuma)==1) {\n n1 += numSuma;\n}\n\nfunction divisible(num) {\n if (num % 3 == 0) {\n return -1//No es v\u00e1lido\n } else return 1;\n}\n\nprint(n1 + \" \" + n2 + \" \" + n3)"}, {"source_code": "var str = readline();\n//var str = 233;\nvar num = Math.round(str / 3);\n//alert(str + \" \" + num)\nvar salida;\nvar cantidadSumar = str - (num * 3);\n//alert(cantidadSumar);\n\nif (valido(num)==1 && valido(num+cantidadSumar)==1) {\n salida = num + \" \" + num + \" \" + (num + cantidadSumar);\n} else if (valido(num) == -1) {\n num = num + cantidadSumar;\n cantidadSumar = str - (num * 3);\n salida = num + \" \" + num + \" \" + (num+cantidadSumar);\n}\n\n\nfunction valido(num) {\n if (num % 3 == 0) {\n return -1//No es v\u00e1lido\n } else return 1;\n}\n\nprint(salida)"}, {"source_code": "var str = readline();\n//var str = 7;\nvar div = Math.floor(str / 3);\nvar num = div * 3;\nif (str==num) {\n salida = div + \" \" + div + \" \" + div;\n} else {\n if (str-num==1) {\n salida = (div+1) + \" \" + div + \" \" + div;\n } else {\n salida = (div+2) + \" \" + div + \" \" + div;\n }\n}\n\n\n\nprint(salida)"}, {"source_code": "var str = readline();\n//var str = 10;\nvar num = Math.round(str / 3);\nvar salida;\n\nif (valido(num)==1 && num*3==str) {//valido y suma bien\n salida = num + \" \" + num + \" \" + num;\n} else if (valido(num) == -1 && num * 3 ==str) {//no es valido pero suma bien\n salida = (num+1) + \" \" + (num+1) + \" \" + (num-2);\n} else if (valido(num) == -1 && num * 3 != str) {//No es valido pero no suma bien\n if ((num*3)+1==str) {\n salida = (num+1) + \" \" + (num) + \" \" + (num);\n } else if((num * 3) + 2 == str) {\n salida = (num+2) + \" \" + (num) + \" \" + (num);\n }\n\n}\n\nfunction valido(num) {\n if (num % 3 == 0) {\n return -1//No es v\u00e1lido\n } else return 1;\n}\n\nprint(salida)"}, {"source_code": "\nfunction main() {\n const cin = new Scanner();\n let n = cin.nextInt() - 1;\n let a = 1, b = Math.trunc(n / 2), c = b;\n if (b % 3 === 0) {\n b -= 1;\n c += 1;\n }\n\n console.log(a, b, c);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = Number) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); });\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const cin = new Scanner();\n let n = cin.nextInt() - 1;\n let a = 1, b = Math.trunc(n / 2), c = Math.ceil(n / 2);\n if (b % 3 === 0) {\n b -= 1;\n c += 1;\n }\n\n console.log(a, b, c);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = Number) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); });\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar single = Math.floor(N / 3);\n\tvar second = single + (N % 3);\n\tmyout(single + \" \" + single + \" \" + second);\n}\n"}, {"source_code": "var cnt = 0;\nprocess.stdin.addListener(\"data\", function(d) {\n\tvar s = d.toString().trim();\n\tvar x = parseInt(s);\n\tif( x%2 == 0){\n process.stdout.write(x-2+' 1 1');\n } \n\telse {\n process.stdout.write(x-3+' 1 2');\n \n }\n cnt++;\n if(cnt > 0) process.exit();\n // process.exit();\n});"}, {"source_code": "var cnt = 0;\nprocess.stdin.addListener(\"data\", function(d) {\n\tvar s = d.toString().trim();\n\tvar x = parseInt(s);\n\tif( x%2 === 0){\n process.stdout.write(x-2+' 1 1');\n } \n\telse {\n if(x==3) process.stdout.write('1 1 1');\n else process.stdout.write(x-3+' 1 2');\n \n }\n cnt++;\n if(cnt > 0) process.exit();\n // process.exit();\n});"}, {"source_code": "var cnt = 0;\nprocess.stdin.addListener(\"data\", function(d) {\n\tvar s = d.toString().trim();\n\tvar x = parseInt(s);\n\tif( x%3 == 0){\n process.stdout.write(x-2+' 1 1');\n } \n\telse {\n //if(x==3) process.stdout.write('1 1 1');\n process.stdout.write(x-2+' 1 1');\n \n }\n cnt++;\n if(cnt > 0) process.exit();\n // process.exit();\n});"}], "src_uid": "91d5147fb602298e08cbdd9f86d833f8"} {"source_code": "var app = {\n changedHandleCount : 0,\n oldNewHandleMap : {},\n result : [],\n main : function() {\n this.initialize();\n this.readValues();\n this.sovleResult();\n this.printResult();\n },\n initialize : function() {\n app.result = [];\n app.oldNewHandleMap = {};\n },\n readValues : function() {\n app.changedHandleCount = parseInt(readline());\n },\n sovleResult : function() {\n for(var index = 0; index < app.changedHandleCount; index++) {\n var oldAndNewHanlde = readline().split(/\\s/),\n oldHandle = oldAndNewHanlde[0],\n newHandle = oldAndNewHanlde[1];\n\n if(app.oldNewHandleMap[oldHandle]) {\n var tempSavedHandle = app.oldNewHandleMap[oldHandle];\n delete app.oldNewHandleMap[oldHandle];\n app.oldNewHandleMap[newHandle] = tempSavedHandle;\n } else {\n app.oldNewHandleMap[newHandle] = oldHandle;\n }\n }\n },\n printResult : function() {\n var newHandleList = Object.keys(app.oldNewHandleMap);\n\n print(newHandleList.length);\n \n newHandleList.forEach(function(newHandle) {\n print(app.oldNewHandleMap[newHandle] + ' ' + newHandle);\n });\n // print(this.result);\n }\n};\n\napp.main();", "positive_code": [{"source_code": "var n = readline().trim();\n\nvar id = 0;\nvar olduser = new Array();\nvar newuser = new Array();\nvar users = new Array();\n\nfor (var i = 0; i < n; i++) {\n var line = readline().split(' ');\n if (users[line[0]] === undefined) {\n users[line[0]] = id;\n olduser[id] = line[0];\n id++;\n }\n var tempid = users[line[0]];\n line[0] = undefined;\n users[line[1]] = tempid;\n newuser[tempid] = line[1];\n}\nprint(id);\nfor (var i = 0; i < id; i++) {\n print(olduser[i] + ' ' + newuser[i]);\n}"}, {"source_code": "var n = +readline();\n\n\nvar users = {};\nvar seen = {};\n\nvar lookup = {};\n\nfor(var i = 0; i < n; i++) {\n var req = readline().split(\" \");\n var prev = req[0];\n var next = req[1];\n\n if(!(prev in seen)) {\n users[prev] = next;\n lookup[next] = prev;\n } else {\n var user = lookup[prev];\n users[user] = next;\n lookup[next] = user;\n }\n seen[prev] = true;\n seen[next] = true;\n}\n\nprint(Object.keys(users).length);\nfor(var k in users) {\n print(k+\" \"+users[k]);\n}\n"}, {"source_code": "var n = parseInt(readline());\n\nvar map = new Map();\n\nwhile (n-->0) {\n var line = readline().split(' ');\n if (map.has(line[0])) {\n var old = map.get(line[0]);\n map.set(line[1], old);\n map.delete(line[0]);\n } else {\n map.set(line[1], line[0]);\n }\n}\n\nwrite(map.size+'\\n');\n\nmap.forEach((value, key) => {\n write(value + ' ' + key + '\\n');\n },\n map);"}, {"source_code": "var n = parseInt(readline());\n\nvar map = new Map();\n\nwhile (n-- > 0) {\n var line = readline().split(\" \");\n var old_handle = line[0];\n var new_handle = line[1];\n\n if (map.has(old_handle)) {\n map.set(new_handle, map.get(old_handle));\n map.delete(old_handle);\n } else {\n map.set(new_handle, old_handle);\n }\n}\n\nwrite(map.size + \"\\n\");\n\nmap.forEach((v, k) => {\n write(v + \" \" + k + \"\\n\");\n}, map);\n"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToStringArray = function lineToStringArray(str) {\n return str.split(\" \");\n};\nvar lineToNumberArray = function lineToNumberArray(str) {\n return lineToStringArray(str).map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\nvar readStringsLine = compose(\n readline,\n lineToStringArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),\n n = _readNumbersLine2[0];\n\nvar map = Object.create(null);\nvar oldNames = [];\n\nfor (var i = 0; i < n; i++) {\n var _readStringsLine = readStringsLine(),\n _readStringsLine2 = _slicedToArray(_readStringsLine, 2),\n oldName = _readStringsLine2[0],\n newName = _readStringsLine2[1];\n\n map[oldName] = newName;\n oldNames.push(oldName);\n}\n\nvar res = [];\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = oldNames[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _oldName = _step.value;\n\n var _newName = map[_oldName];\n delete map[_oldName];\n while (map[_newName]) {\n var _oldName3 = _newName;\n _newName = map[_newName];\n delete map[_oldName3];\n }\n if (_newName) res.push([_oldName, _newName]);\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res.length);\n\nvar _iteratorNormalCompletion2 = true;\nvar _didIteratorError2 = false;\nvar _iteratorError2 = undefined;\n\ntry {\n for (\n var _iterator2 = res[Symbol.iterator](), _step2;\n !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);\n _iteratorNormalCompletion2 = true\n ) {\n var _ref = _step2.value;\n\n var _ref2 = _slicedToArray(_ref, 2);\n\n var _oldName2 = _ref2[0];\n var _newName2 = _ref2[1];\n\n print(_oldName2, _newName2);\n }\n} catch (err) {\n _didIteratorError2 = true;\n _iteratorError2 = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion2 && _iterator2.return) {\n _iterator2.return();\n }\n } finally {\n if (_didIteratorError2) {\n throw _iteratorError2;\n }\n }\n}\n"}], "negative_code": [{"source_code": "var n = +readline();\n\n\nvar users = {};\nvar seen = {};\n\nvar lookup = {};\n\nfor(var i = 0; i < n; i++) {\n var req = readline().split(\" \");\n var prev = req[0];\n var next = req[1];\n\n if(!(prev in seen)) {\n users[prev] = next;\n lookup[next] = prev;\n } else {\n var user = lookup[prev];\n users[user] = next;\n lookup[next] = user;\n }\n seen[prev] = true;\n}\n\nprint(Object.keys(users).length);\nfor(var k in users) {\n print(k+\" \"+users[k]);\n}\n"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToNumberArray = function lineToNumberArray(str) {\n return str.split(\" \").map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 3),\n n = _readNumbersLine2[0],\n t = _readNumbersLine2[1],\n c = _readNumbersLine2[2];\n\nvar arr = readNumbersLine();\nvar lastTOver = -1;\nvar res = 0;\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = arr.entries()[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _ref = _step.value;\n\n var _ref2 = _slicedToArray(_ref, 2);\n\n var key = _ref2[0];\n var value = _ref2[1];\n\n if (value > t) lastTOver = key;\n if (key - lastTOver >= c) res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);\n"}], "src_uid": "bdd98d17ff0d804d88d662cba6a61e8f"} {"source_code": "(function () {\n var line = readline();\n var lines = [line.split(' ')];\n while (line) {\n line = readline();\n if (line) {\n lines.push(line.split(' '));\n }\n }\n \n var items = lines[1];\n var time = 0;\n\n function pos(item) {\n return items.indexOf(item);\n }\n \n for (var i = 2, k = lines.length; i < k; i++) {\n lines[i].forEach(function (item) {\n var itemPos = pos(item);\n items.splice(itemPos, 1);\n items.unshift(item);\n time += itemPos + 1;\n });\n }\n \n print(time)\n})();", "positive_code": [{"source_code": "(function () {\n var line = readline();\n var lines = [line.split(' ')];\n while (line) {\n line = readline();\n if (line) {\n lines.push(line.split(' '));\n }\n }\n \n var items = lines[1];\n var time = 0;\n\n function pos(item) {\n return items.indexOf(item);\n }\n \n for (var i = 2, k = lines.length; i < k; i++) {\n lines[i].forEach(function (item) {\n var itemPos = pos(item);\n items.splice(itemPos, 1);\n items.unshift(item);\n time += itemPos + 1;\n });\n }\n \n print(time)\n})();"}], "negative_code": [{"source_code": "(function () {\n var line = readline();\n var lines = [line.split(' ')];\n while (line) {\n line = readline();\n if (line) {\n lines.push(line.split(' '));\n }\n }\n \n var items = lines[1];\n var time = 0;\n \n print(items);\n \n function pos(item) {\n return items.indexOf(item);\n }\n \n for (var i = 2, k = lines.length; i < k; i++) {\n lines[i].forEach(function (item) {\n var itemPos = pos(item);\n items.splice(itemPos, 1);\n items.unshift(item);\n time += itemPos + 1;\n });\n }\n \n print(time)\n})();"}], "src_uid": "39fd7843558ed2aa6b8c997c2b8a1fad"} {"source_code": "const solve = (n,arr,q)=>{\r\n let query = [];\r\n query.push(arr);\r\n for(let i=1;i<=n;i++){\r\n let t = query[i-1],obj = {};\r\n for(let i=0;i=n) console.log(query[n][q[i][0]-1]);\r\n else console.log(query[q[i][1]][q[i][0]-1]);\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n let qn = parseInt(readline());\r\n let q = [];\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n solve(n,arr,q);\r\n }\r\n}\r\nmain();", "positive_code": [{"source_code": "\"use strict\"; \r\n \r\n//..................................import for reading input...................................//\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n } \r\n//............................................................................................//\r\n \r\nfunction main() {\r\n let t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n}\r\n \r\nfunction solution() {\r\n let n = +(readline());\r\n let divineArray = readline().split(' ').map((item) => +item);\r\n let derivativeArray = transformArray(n, divineArray);\r\n \r\n let allPossibleTransformations = [];\r\n let stopAt = 0;\r\n allPossibleTransformations[stopAt++] = divineArray;\r\n \r\n while( divineArray.join(' ') !== derivativeArray.join(' ') ) {\r\n divineArray = derivativeArray;\r\n allPossibleTransformations[stopAt++] = divineArray;\r\n derivativeArray = transformArray(n, divineArray);\r\n }\r\n \r\n let q = +(readline());\r\n while (q--) {\r\n let [x, k] = readline().split(' ').map((item) => +item);\r\n k = (k > stopAt-1) ? stopAt-1 : k;\r\n console.log(allPossibleTransformations[k][x-1]);\r\n }\r\n}\r\n \r\nfunction transformArray(n, divineArray) {\r\n let counterArray = new Array(n+1).fill(0);\r\n let newArray = [];\r\n for (let i = 0; i < n; i++) {\r\n counterArray[divineArray[i]]++;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n newArray[i] = counterArray[divineArray[i]];\r\n }\r\n \r\n return newArray;\r\n}\r\n "}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = {};\r\n\t\tmap[0] = makeClone(list);\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tvar isChange = false;\r\n\t\t\tvar count = getCountMap(list);\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tif(list[j] != count[list[j]]){\r\n\t\t\t\t\tisChange = true;\r\n\t\t\t\t}\r\n\t\t\t\tlist[j] = count[list[j]];\r\n\t\t\t}\r\n\t\t\tmap[i + 1] = makeClone(list);\r\n\t\t\tmax++;\r\n\t\t\tif(!isChange){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar Q = nextInt();\r\n\t\tfor(var i = 0; i < Q; i++){\r\n\t\t\tvar x = nextInt() - 1;\r\n\t\t\tvar k = Math.min(nextInt(), max);\r\n\t\t\tmyout(map[k][x]);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "43009fe44c2b5905c8160ac7ae9c595a"} {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var n = +inputs[i * 3 + 1];\n var a = inputs[i * 3 + 2].split(' ').map(v => +v);\n var b = inputs[i * 3 + 3].split(' ').map(v => +v);\n var c = a.map((v, i) => b[i] ? -1e9 : v).sort((a, b) => b - a);\n var d = a.map((v, i) => b[i] ? v : c.shift());\n console.log(d.join(' '));\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let indicator = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let store = [];\n\n for (let i = 0; i < len; i++) {\n if (indicator[i] === 0) {\n store.push(arr[i]);\n arr[i] = Infinity;\n }\n }\n\n store.sort((a, b) => b - a);\n\n for (let i = 0, j = 0; i < len; i++) {\n if (arr[i] === Infinity) {\n arr[i] = store[j];\n j++;\n }\n }\n\n console.log(arr.join(\" \"));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (var i=0; i parseInt(x));\n const locked = readline().split(\" \").map(x => parseInt(x));\n\n const arr = a.filter((_, index) => locked[index]==0);\n arr.sort((a,b)=>b-a);\n\n let pos=0;\n const result = a.map((v, index)=> {\n if (locked[index]==1) return v;\n return arr[pos++];\n });\n\n console.log(result.join(\" \"));\n }\n}\n"}, {"source_code": "function solv() {\n\n var x = parseInt(readline())\n\n var s = readline().split(' ').map(x => parseInt(x))\n var z = readline().split(' ').map(x => parseInt(x))\n\n var v = []\n for (var n = 0; n < x; n++) {\n if (z[n] == 0) v.push(s[n])\n }\n v.sort((a, b) => { return b - a })\n var id = 0;\n var res = ''\n for (var n = 0; n < x; n++) {\n if (z[n] == 0) s[n] = v[id++];\n res += s[n] + ' ';\n }\n print(res)\n}\n\nvar tc = 1;\ntc = parseInt(readline());\nwhile (tc--) solv()"}], "negative_code": [], "src_uid": "9ef180b33717e4d6a21b4c5bb855e15b"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar camelNum = parseInt(readline());\n\tvar spitFrom = {};\n\n\tfor (var i = 0; i < camelNum; ++i) {\n\t\tvar info = tokenizeIntegers(readline());\n\t\tvar camelPos = info[0], spitDistance = info[1];\n\t\tvar target = camelPos + spitDistance;\n\t\tif (spitFrom[camelPos] == target) {\n\t\t\tprint(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tspitFrom[target] = camelPos;\n\t}\n\tprint(\"NO\");\n}\n\nmain();\n", "positive_code": [{"source_code": "'use strict'\n\nlet N = +readline()\nlet res = 'NO'\nlet lll\n\n;(function () {\n let ss = []\n while (lll = readline()) {\n lll = lll.split(' ').map(v => parseInt(v))\n let vn = lll[0]\n let vs = lll[1]\n if (!ss[vn]) ss[vn] = []\n let vt = vn + vs\n if (ss[vt] && ~ss[vt].indexOf(vn)) return res = 'YES'\n ss[vn].push(vt)\n }\n})()\nprint(res)"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar dict = {}, n = -1;\n\nrl.on('line', (input) => {\n if (n == -1) \n n = parseInt(input);\n else {\n let temp = input.split(' ').map(item=>parseInt(item));\n let pos = temp[0], spit = temp[1];\n dict[pos] = spit; \n }\n \n }).on('close', function() {\n let ans = \"NO\";\n \n for (var current in dict){\n let secondCamel = parseInt(dict[current]) + parseInt(current);\n if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {\n ans = \"YES\";\n break;\n } \n }\n \n /*\n for (const [key, value] of Object.entries(dict)) {\n let secondCamel = dict[key] + value;\n if (secondCamel in dict && secondCamel + dict[secondCamel] == key) {\n ans = \"YES\";\n break;\n } \n }*/\n console.log(ans);\n });\n\n /*\n 5\n 2 -10\n 3 10\n 0 5\n 5 -5\n 10 1\n\n\n */"}, {"source_code": "var n = parseInt(readline());\nvar verbluds = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar input = readline().split(' ').map(function(a){return parseFloat(a)});\n\tvar position = input[0];\n\tvar plevok_position = input[0] + input[1];\n\tverbluds[position] = plevok_position;\n}\n\nfunction is_odin_v_odnogo(arr) {\n\tfor (var a in arr) {\n\t\tif (a == arr[arr[a]]) {\n\t\t\treturn 'YES';\n\t\t}\n\t}\n\treturn 'NO';\n}\n\nprint(is_odin_v_odnogo(verbluds));"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n\nvar n = -1;\nvar location = [];\nvar spit = [];\n\nrl.on('line', function (input) {\n // myArr = input.split(' ').map(item => {return parseInt(item);});\n if (n == -1)\n n = parseInt(input);\n else {\n\n\n if (location.length < n - 1) {\n //location.push(parseInt(input));\n var temp = input.split(' ').map(item=> {return parseInt(item);});\n location.push(temp[0]);\n spit.push(temp[1]);\n }\n else {\n\n var temp = input.split(' ').map(item=> {return parseInt(item);});\n location.push(temp[0]);\n spit.push(temp[1]);\n //****************************************** DO IT HERE*/\n var ans= \"NO\";\n for (let i = 0; i < n; i++) {\n var indexOfSecondCam = location.indexOf(location[i] + spit[i]);\n if (indexOfSecondCam != -1 && location[indexOfSecondCam] + spit[indexOfSecondCam]==location[i]) {\n ans = \"YES\"; \n break;\n }\n \n }\n console.log(ans);\n \n rl.close();\n /*************************************** */\n }\n\n\n\n\n }\n\n})\n\n\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n//var dict = {}, n = -1;\nvar myMap = new Map(), n = -1;\n\nrl.on('line', (input) => {\n if (n == -1) \n n = parseInt(input);\n else {\n let temp = input.split(' ').map(item=>parseInt(item));\n \n let pos = temp[0], spit = temp[1];\n // dict[pos] = spit; \n \n myMap.set(pos, spit) ;\n }\n \n }).on('close', function() {\n let ans = \"NO\";\n /*\n for (var current in dict){\n let secondCamel = parseInt(dict[current]) + parseInt(current);\n if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {\n ans = \"YES\";\n break;\n } \n }\n */\n /*\n for (const [key, value] of Object.entries(dict)) {\n let secondCamel = dict[key] + value;\n if (secondCamel in dict && secondCamel + dict[secondCamel] == key) {\n ans = \"YES\";\n break;\n } \n }*/\n\n for(let [key, value] of myMap){\n let secondCamel = key + value;\n if (myMap.has(secondCamel) && myMap.get(secondCamel) + secondCamel == key) {\n ans = \"YES\";\n break;\n }\n }\n console.log(ans);\n });\n\n /*\n 5\n 2 -10\n 3 10\n 0 5\n 5 -5\n 10 1\n\n\n */"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar dict = {}, n = -1;\n\nrl.on('line', (input) => {\n if (n == -1) \n n = parseInt(input);\n else {\n let temp = input.split(' ');\n let pos = temp[0], spit = temp[1];\n dict[pos] = spit; \n }\n \n }).on('close', function() {\n let ans = \"NO\";\n \n for (var current in dict){\n let secondCamel = parseInt(dict[current]) + parseInt(current);\n if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {\n ans = \"YES\";\n break;\n } \n }\n \n \n console.log(ans);\n });\n\n "}], "src_uid": "d7dc61a8f3b0091320b96cedd1f4f0a7"} {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction check(cases) {\n for (let i = 0; i < cases.length; i++) {\n const sizing = {\n S: 1,\n M: 2,\n L: 3,\n };\n const [left, right] = cases[i].split(\" \");\n let leftSizing = 0;\n let rightSizing = 0;\n if (left.includes(\"X\")) {\n leftSizing = sizing[left.charAt(left.length - 1)];\n leftSizing = left.includes(\"S\")\n ? leftSizing - left.length - 1\n : leftSizing + left.length - 1;\n } else {\n leftSizing = sizing[left];\n }\n\n if (right.includes(\"X\")) {\n rightSizing = sizing[right.charAt(right.length - 1)];\n rightSizing = right.includes(\"S\")\n ? rightSizing - right.length - 1\n : rightSizing + right.length - 1;\n } else {\n rightSizing = sizing[right];\n }\n\n if (leftSizing > rightSizing) {\n console.log(\">\");\n } else if (leftSizing === rightSizing) {\n console.log(\"=\");\n } else {\n console.log(\"<\");\n }\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t; i++) {\n const inputs = readLine().trim();\n cases.push(inputs);\n }\n\n check(cases);\n}\n\n\t \t\t\t \t\t \t \t \t \t\t \t\t\t", "positive_code": [{"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction check(cases) {\n for (let i = 0; i < cases.length; i++) {\n const sizing = {\n S: 1,\n M: 2,\n L: 3,\n };\n const [left, right] = cases[i].split(\" \");\n let leftSizing = 0;\n let rightSizing = 0;\n if (left.includes(\"X\")) {\n leftSizing = sizing[left.charAt(left.length - 1)];\n leftSizing = left.includes(\"S\")\n ? leftSizing - left.length - 1\n : leftSizing + left.length - 1;\n } else {\n leftSizing = sizing[left];\n }\n\n if (right.includes(\"X\")) {\n rightSizing = sizing[right.charAt(right.length - 1)];\n rightSizing = right.includes(\"S\")\n ? rightSizing - right.length - 1\n : rightSizing + right.length - 1;\n } else {\n rightSizing = sizing[right];\n }\n\n if (leftSizing > rightSizing) {\n console.log(\">\");\n } else if (leftSizing === rightSizing) {\n console.log(\"=\");\n } else {\n console.log(\"<\");\n }\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t; i++) {\n const inputs = readLine().trim();\n cases.push(inputs);\n }\n\n check(cases);\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [a, b] = stringArr1();\r\n if (a[0] === \"M\") {\r\n for (let i = 0; i < b.length; i++) {\r\n if (b[i] !== \"X\") {\r\n if (b[i] === \"M\") console.log(\"=\");\r\n else if (b[i] === \"S\") console.log(\">\");\r\n else console.log(\"<\");\r\n }\r\n }\r\n } else if (b[0] === \"M\") {\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] !== \"X\") {\r\n if (a[i] === \"L\") console.log(\">\");\r\n else console.log(\"<\");\r\n }\r\n }\r\n } else {\r\n let xc = 0,\r\n f,\r\n xc1 = 0,\r\n f1;\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === \"X\") xc++;\r\n else f = a[i];\r\n }\r\n for (let i = 0; i < b.length; i++) {\r\n if (b[i] === \"X\") xc1++;\r\n else f1 = b[i];\r\n }\r\n if (f === \"S\") {\r\n if (f1 === \"L\") console.log(\"<\");\r\n else if (xc > xc1) console.log(\"<\");\r\n else if (xc < xc1) console.log(\">\");\r\n else console.log(\"=\");\r\n } else if (f === \"L\") {\r\n if (f1 === \"S\") console.log(\">\");\r\n else if (xc > xc1) console.log(\">\");\r\n else if (xc < xc1) console.log(\"<\");\r\n else console.log(\"=\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let s = readline().split(' ')\r\n console.log(solve(s))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (s) => {\r\n let a = s[0].split('')\r\n let b = s[1].split('')\r\n\r\n let c1 = a.filter( f => f === 'X' ).length\r\n let c2 = b.filter( f => f === 'X' ).length\r\n\r\n if (a[a.length - 1] == 'S' && b[b.length - 1] == 'M') return \"<\"\r\n else if (a[a.length - 1] == 'S' && b[b.length - 1] == 'L') return \"<\"\r\n else if (a[a.length - 1] == 'M' && b[b.length - 1] == 'L') return \"<\"\r\n else if (a[a.length - 1] == 'L' && b[b.length - 1] == 'S') return \">\"\r\n else if (a[a.length - 1] == 'L' && b[b.length - 1] == 'M') return \">\"\r\n else if (a[a.length - 1] == 'M' && b[b.length - 1] == 'S') return \">\"\r\n else {\r\n if (a[a.length - 1] == 'S') {\r\n if (c1 == c2) return \"=\"\r\n else if (c1 > c2) return \"<\"\r\n else return \">\"\r\n }\r\n else {\r\n if (c1 == c2) return \"=\"\r\n else if (c1 > c2) return \">\"\r\n else return \"<\"\r\n }\r\n }\r\n}\r\n\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b)\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\n// <\r\n// >\r\n// >\r\n// =\r\n// <\r\n// >"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const a = read(),\r\n b = read();\r\n const map = new Map([['S', 0], ['M', 1], ['L', 2]]);\r\n if (a[a.length - 1] !== b[b.length - 1]) {\r\n const d = map.get(a[a.length - 1]) - map.get(b[b.length - 1]);\r\n if (d > 0) return '>';\r\n return '<';\r\n }\r\n if (a.length !== b.length) {\r\n const d = a.length - b.length;\r\n if (a[a.length - 1] === 'S') {\r\n if (d > 0) return '<';\r\n return '>';\r\n }\r\n if (d > 0) return '>';\r\n return '<';\r\n }\r\n return '=';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ')\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n const la = a[a.length - 1]\n const lb = b[b.length - 1]\n if (la === lb) {\n if (la === 'S') {\n return a.length > b.length ? '<' : (a.length < b.length ? '>' : '=')\n }\n if (la === 'L') {\n return a.length > b.length ? '>' : (a.length < b.length ? '<' : '=')\n }\n return '='\n }\n return cmp(la, lb)\n}\nfunction cmp(a, b) {\n // console.log(a, b)\n if (a === b) return '='\n if (a === 'S') return '<'\n if (a === 'L') return '>'\n return b === 'S' ? '>' : '<'\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar map = [\"S\", \"M\", \"L\"];\r\n\twhile(hasNext()){\r\n\t\tvar L = next();\r\n\t\tvar R = next();\r\n\t\tif(L == R){\r\n\t\t\tmyout(\"=\");\r\n\t\t}else{\r\n\t\t\tif(L.indexOf(\"S\") != -1 && R.indexOf(\"S\") != -1){\r\n\t\t\t\tif(L.length > R.length){\r\n\t\t\t\t\tmyout(\"<\");\r\n\t\t\t\t}else{\r\n\t\t\t\t\tmyout(\">\");\r\n\t\t\t\t}\r\n\t\t\t}else if(L.indexOf(\"L\") != -1 && R.indexOf(\"L\") != -1){\r\n\t\t\t\tif(L.length > R.length){\r\n\t\t\t\t\tmyout(\">\");\r\n\t\t\t\t}else{\r\n\t\t\t\t\tmyout(\"<\");\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tvar Li = map.indexOf(L[L.length - 1]);\r\n\t\t\t\tvar Ri = map.indexOf(R[R.length - 1]);\r\n\t\t\t\tif(Li < Ri){\r\n\t\t\t\t\tmyout(\"<\");\r\n\t\t\t\t}else{\r\n\t\t\t\t\tmyout(\">\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nfunction foo (left, right) {\r\n\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n var charLeft = left[sizeLeft-1]\r\n var charRight = right[sizeRight-1]\r\n\r\n if (charLeft === charRight && charLeft == 'S') { \r\n if (valueLeft === valueRight) {\r\n return \"=\"\r\n }\r\n return valueLeft > valueRight ? \"<\" : \">\"\r\n }\r\n if (mapData[charLeft] == mapData[charRight]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\"\r\n }\r\n return valueLeft > valueRight ? \">\" : \"<\"\r\n }\r\n return mapData[charLeft] > mapData[charRight] ? '>' : '<'\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp = [];\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n\r\n}\r\nmain()"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n phrase[0] = 'x' + phrase[0];\r\n phrase[1] = 'x' + phrase[1];\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=\\n');\r\n continue;\r\n }\r\n if ((phrase[0].includes('m') && phrase[1].includes('s')) || (phrase[0].includes('l') && phrase[1].includes('s')) || (phrase[0].includes('l') && phrase[1].includes('m'))) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if ((phrase[0].includes('s') && phrase[1].includes('m')) || (phrase[0].includes('s') && phrase[1].includes('l')) || (phrase[0].includes('m') && phrase[1].includes('l'))) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n }\r\n if ((phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) && !T.toLowerCase().includes('s')) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if ((phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) && T.toLowerCase().includes('s')) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n }\r\n if ((phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) && !T.toLowerCase().includes('s')) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if ((phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) && T.toLowerCase().includes('s')) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var n = readline()\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var sizes = readline().split(' ')\r\n sizes = sizes.map(size => size.split(''))\r\n sizes = sizes.map( size => {\r\n switch(size.pop()) {\r\n case 'M':\r\n return 0\r\n break;\r\n case 'S':\r\n return -1 - size.length\r\n break;\r\n case 'L':\r\n return 1 + size.length\r\n break;\r\n }\r\n })\r\n if (sizes[0] < sizes[1]) print('<')\r\n else if (sizes[0] == sizes[1]) print('=')\r\n else print('>')\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var firstShirtSize = caseArray[0];\r\n var secondShirtSize = caseArray[1];\r\n var result = \"=\";\r\n if (firstShirtSize.slice(-1) == 'S' &&\r\n (secondShirtSize.slice(-1) == 'M' || secondShirtSize.slice(-1) == 'L'))\r\n {\r\n result = \"<\";\r\n }\r\n else if (firstShirtSize.slice(-1) == 'M')\r\n {\r\n if (secondShirtSize.slice(-1) == 'S') result = \">\";\r\n else if (secondShirtSize.slice(-1) == 'L') result = \"<\";\r\n }\r\n else if (firstShirtSize.slice(-1) == 'L' &&\r\n (secondShirtSize.slice(-1) == 'S' || secondShirtSize.slice(-1) == 'M'))\r\n {\r\n result = \">\";\r\n }\r\n else\r\n {\r\n if (firstShirtSize.slice(-1) == 'S')\r\n {\r\n if (firstShirtSize.length > secondShirtSize.length) result = \"<\";\r\n else if (firstShirtSize.length < secondShirtSize.length) result = \">\";\r\n }\r\n else if (firstShirtSize.slice(-1) == 'L')\r\n {\r\n if (firstShirtSize.length > secondShirtSize.length) result = \">\";\r\n else if (firstShirtSize.length < secondShirtSize.length) result = \"<\";\r\n }\r\n }\r\n print(result);\r\n}"}, {"source_code": "function compareSizes(str1, str2){\r\n const sizes = {\r\n 'S': 0,\r\n 'M': 1,\r\n 'L': 2\r\n }\r\n \r\n const size1 = str1[str1.length - 1]\r\n const size2 = str2[str2.length - 1]\r\n \r\n if(size1 !== size2){\r\n const num1 = sizes[size1]\r\n const num2 = sizes[size2]\r\n if(num1 > num2){\r\n return '>'\r\n } else if(num1 < num2){\r\n return '<'\r\n } else return '='\r\n } else if(str1.length === str2.length) {\r\n return '='\r\n } else if(size1 === 'S') {\r\n if(str1.length < str2.length) {\r\n return '>'\r\n } else return '<'\r\n } else if(str1.length > str2.length) {\r\n return '>'\r\n } else return '<'\r\n}\r\n\r\n\r\nvar count = readline();\r\n\r\nvar inp;\r\n\r\nfor(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ')\r\n var result = compareSizes(inp[0], inp[1]);\r\n print(result);\r\n\r\n}"}, {"source_code": "\r\nvar foo = function(str1, str2) {\r\n\r\n var sizes = {\r\n 'S': 0,\r\n 'M': 1,\r\n 'L': 2\r\n }\r\n \r\n var length1 = str1.length\r\n var length2 = str2.length\r\n var lastLetter1 = str1[length1 - 1]\r\n var lastLetter2 = str2[length2 - 1]\r\n\r\n if(lastLetter2 !== lastLetter1) {\r\n return getOperator(sizes[lastLetter1]-sizes[lastLetter2])\r\n } \r\n\r\n if(length1 === length2) return '='\r\n\r\n if(lastLetter1 === 'S') return getOperator(length2 - length1)\r\n\r\n return getOperator(length1 - length2)\r\n};\r\n\r\nvar getOperator = (num) => {\r\n if(num > 0) return '>'\r\n else if(num === 0) return '=' \r\n else return '<'\r\n}\r\n\r\nvar count = readline();\r\n\r\nvar inp;\r\n\r\nfor(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let [size1, size2] = readline().split(\" \");\r\n console.log(compareSizes(size1, size2));\r\n }\r\n}\r\n\r\nfunction compareSizes(size1, size2) {\r\n let S = 10, M = 50, L = 100 ;\r\n if (size1 === size2) return \"=\";\r\n if (calculateSize(size1) > calculateSize(size2)) return \">\";\r\n else return \"<\";\r\n}\r\n\r\nfunction calculateSize(size) {\r\n let S = 10, M = 100, L = 1000;\r\n let len = size.length;\r\n if (size[len - 1] === \"M\") return M;\r\n else if (size[len - 1] === \"S\") {\r\n return S - (len - 1);\r\n } else if (size[len - 1] === \"L\") {\r\n return L + (len - 1);\r\n }\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n phrase[0] = 'x' + phrase[0];\r\n phrase[1] = 'x' + phrase[1];\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=\\n');\r\n continue;\r\n }\r\n if (!T.includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n }\r\n } else {\r\n if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n phrase[0] = 'x' + phrase[0];\r\n phrase[1] = 'x' + phrase[1];\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=\\n');\r\n continue;\r\n }\r\n if (T.includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n }\r\n } else {\r\n if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n phrase[0] = 'x' + phrase[0];\r\n phrase[1] = 'x' + phrase[1];\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=\\n');\r\n continue;\r\n }\r\n if (phrase[phrase.length - 1] != 's') {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n }\r\n } else {\r\n if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n continue;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n continue;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=\\n');\r\n return;\r\n }\r\n if (!T.trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n process.stdout.write('<\\n');\r\n return;\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n process.stdout.write('>\\n');\r\n return;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n return;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n return;\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n process.stdout.write('>\\n');\r\n return;\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n process.stdout.write('<\\n');\r\n return;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('>\\n');\r\n return;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('<\\n');\r\n return;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n process.stdout.write('=');\r\n }\r\n if (!T.trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n process.stdout.write('<');\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n process.stdout.write('>');\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('<');\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('>');\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n process.stdout.write('>');\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n process.stdout.write('<');\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n process.stdout.write('>');\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n process.stdout.write('<');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var T = readline();\r\n var phrase = T.toLowerCase().trim().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n console.log('=\\n');\r\n }\r\n if (!T.trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n console.log('<\\n');\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n console.log('>\\n');\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('<\\n');\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('>\\n');\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n console.log('>\\n');\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n console.log('<\\n');\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('>\\n');\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('<\\n');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var phrase = data.toString().trim().toLowerCase().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n console.log('=\\n');\r\n return '=';\r\n }\r\n if (!data.toString().trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n console.log('<\\n');\r\n return '<';\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n console.log('>\\n');\r\n return '>';\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('<\\n');\r\n return '<';\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('>\\n');\r\n return '>';\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n console.log('>\\n');\r\n return '>';\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n console.log('<\\n');\r\n return '<';\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('>\\n');\r\n return '>';\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('<\\n');\r\n return '<';\r\n }\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var phrase = data.toString().trim().toLowerCase().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n console.log('=', '/n');\r\n return '=';\r\n }\r\n if (!data.toString().trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n console.log('<', '/n');\r\n return '<';\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n console.log('>', '/n');\r\n return '>';\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('<', '/n');\r\n return '<';\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('>', '/n');\r\n return '>';\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n console.log('>', '/n');\r\n return '>';\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n console.log('<', '/n');\r\n return '<';\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('>', '/n');\r\n return '>';\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('<', '/n');\r\n return '<';\r\n }\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var phrase = data.toString().trim().toLowerCase().split(' ');\r\n if (phrase[0] == phrase[1]) {\r\n console.log('=');\r\n return;\r\n }\r\n if (!data.toString().trim().toLowerCase().includes('s')) {\r\n if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n console.log('<');\r\n return;\r\n } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n console.log('>');\r\n return;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('<');\r\n return;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('>');\r\n return;\r\n }\r\n } else {\r\n if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n console.log('>');\r\n return;\r\n } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n console.log('<');\r\n return;\r\n } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n console.log('>');\r\n return;\r\n } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n console.log('<');\r\n return;\r\n }\r\n }\r\n})\r\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction check(cases) {\n for (let i = 0; i < cases.length; i++) {\n const sizing = {\n S: 1,\n M: 2,\n L: 3,\n };\n const [left, right] = cases[i].split(\" \");\n let leftSizing = 0;\n let rightSizing = 0;\n if (left.includes(\"X\")) {\n leftSizing = sizing[left.charAt(left.length - 1)];\n leftSizing = left.includes(\"S\")\n ? leftSizing - left.length - 2\n : leftSizing + left.length - 2;\n } else {\n leftSizing = sizing[left];\n }\n\n if (right.includes(\"X\")) {\n rightSizing = sizing[right.charAt(right.length - 1)];\n rightSizing = right.includes(\"S\")\n ? rightSizing - right.length - 2\n : rightSizing + right.length - 2;\n } else {\n rightSizing = sizing[right];\n }\n\n if (leftSizing > rightSizing) {\n console.log(\">\");\n } else if (leftSizing === rightSizing) {\n console.log(\"=\");\n } else {\n console.log(\"<\");\n }\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t; i++) {\n const inputs = readLine().trim();\n cases.push(inputs);\n }\n\n check(cases);\n}\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nfunction foo (left, right) {\r\n\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n var charLeft = left[sizeLeft-1]\r\n var charRight = right[sizeRight-1]\r\n\r\n if (charLeft === charRight && charLeft == 'S') { \r\n if (valueLeft === valueRight) {\r\n return \"=\"\r\n }\r\n return valueLeft > valueRight ? \"<\" : \">\"\r\n }\r\n if (mapData[charLeft] == mapData[charRight]) {\r\n return '='\r\n }\r\n return mapData[charLeft] > mapData[charRight] ? '>' : '<'\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp = [];\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n\r\n}\r\nmain()\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nfunction foo (left, right) {\r\n\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n var charLeft = left[sizeLeft-1];\r\n var charRight = right[sizeRight-1];\r\n\r\n if (charLeft === charRight && charLeft == 'S') { \r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return valueLeft > valueRight ? \"<\" : \">\";\r\n }\r\n if (mapData[charLeft] == mapData[charRight]) {\r\n return '=';\r\n }\r\n return mapData[charLeft] > mapData[charRight] ? '>' : '<';\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp = [\"XL\", \"M\"];\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n\r\n}\r\nmain()\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nvar exception = [\"XM\", \"LL\", \"SX\"]\r\n\r\nfunction foo (left, right) {\r\n\r\n if (exception.includes(left) || exception.includes(right)) {\r\n return \"\";\r\n }\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n if (left[sizeLeft-1] === right[sizeRight-1]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return valueLeft > valueRight ? \"<\" : \">\";\r\n }\r\n if (mapData[left[sizeLeft-1]] == mapData[right[sizeRight-1]]) {\r\n return \"=\";\r\n }\r\n if (mapData[left[sizeLeft-1]] > mapData[right[sizeRight-1]]) {\r\n return \">\";\r\n } else {\r\n return \"<\";\r\n }\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp;\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n}\r\nmain()\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nvar exception = [\"XM\", \"LL\", \"SX\"]\r\n\r\nfunction foo (left, right) {\r\n\r\n if (exception.includes(left) || exception.includes(right)) {\r\n return \"\";\r\n }\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n if (left[sizeLeft-1] === right[sizeRight-1]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return valueLeft > valueRight ? \">\" : \"<\";\r\n }\r\n if (mapData[left[sizeLeft-1]] == mapData[right[sizeRight-1]]) {\r\n return \"=\";\r\n }\r\n if (mapData[left[sizeLeft-1]] > mapData[right[sizeRight-1]]) {\r\n return \">\";\r\n } else {\r\n return \"<\";\r\n }\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp;\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n}\r\nmain()\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nvar exception = [\"XM\", \"LL\", \"SX\"]\r\n\r\nfunction foo (left, right) {\r\n\r\n if (exception.includes(left) || exception.includes(right)) {\r\n return \"\";\r\n }\r\n var sizeLeft = left.length;\r\n var sizeRight = right.length;\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1;\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1;\r\n\r\n if (left[sizeLeft-1] === right[sizeRight-1]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return left > right ? \">\" : \"<\";\r\n }\r\n if (mapData[left[sizeLeft-1]] == mapData[right[sizeRight-1]]) {\r\n return \"=\";\r\n }\r\n if (mapData[left[sizeLeft-1]] > mapData[right[sizeRight-1]]) {\r\n return \">\";\r\n } else {\r\n return \"<\";\r\n }\r\n\r\n }\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp;\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ');\r\n var result = foo(inp[0], inp[1]);\r\n print(result);\r\n\r\n }\r\n}\r\nmain()\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nvar exception = [\"XM\", \"LL\", \"SX\"]\r\n\r\nvar compareTShirtSizes = (left, right) => {\r\n\r\n}\r\n var foo = (left, right) => {\r\n\r\n if (exception.includes(left) || exception.includes(right)) {\r\n return null\r\n }\r\n var sizeLeft = left.length\r\n const sizeRight = right.length\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1\r\n\r\n if (left[sizeLeft-1] === right[sizeRight-1]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return left > right ? \">\" : \"<\";\r\n }\r\n if (mapData[left[sizeLeft-1]] == mapData[right[sizeRight-1]]) {\r\n return \"=\"\r\n }\r\n if (mapData[left[sizeLeft-1]] > mapData[right[sizeRight-1]]) {\r\n return \">\"\r\n } else {\r\n return \"<\"\r\n }\r\n\r\n }\r\n \r\nfunction main() {\r\n var n = +readline();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n \r\n var result = foo(vars[0], vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n"}, {"source_code": "\r\nvar mapData = { \r\n L: 3,\r\n M: 2,\r\n S: 1\r\n}\r\n\r\nvar exception = [\"XM\", \"LL\", \"SX\"]\r\n\r\nvar compareTShirtSizes = (left, right) => {\r\n\r\n}\r\n var pareHandler = (left, right) => {\r\n\r\n if (exception.includes(left) || exception.includes(right)) {\r\n return null\r\n }\r\n var sizeLeft = left.length\r\n const sizeRight = right.length\r\n\r\n var valueLeft = mapData[left[sizeLeft-1]] + sizeLeft - 1\r\n var valueRight = mapData[right[sizeRight-1]] + sizeRight - 1\r\n\r\n if (left[sizeLeft-1] === right[sizeRight-1]) {\r\n if (valueLeft === valueRight) {\r\n return \"=\";\r\n }\r\n return left > right ? \">\" : \"<\";\r\n }\r\n if (mapData[left[sizeLeft-1]] == mapData[right[sizeRight-1]]) {\r\n return \"=\"\r\n }\r\n if (mapData[left[sizeLeft-1]] > mapData[right[sizeRight-1]]) {\r\n return \">\"\r\n } else {\r\n return \"<\"\r\n }\r\n\r\n }\r\n \r\nfunction main() {\r\n var n = +readline();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n \r\n var result = foo(vars[0], vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n"}], "src_uid": "3ea3f5b548b82449e4ce86e11b1afc48"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n const sum = new Array(n).fill(0);\r\n let sumMap = new Map();\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n }\r\n\r\n const sumSet = [...new Set(sum), 0].sort((a, b) => a - b),\r\n N = sumSet.length;\r\n\r\n for (let [k, v] of sumSet.entries()) {\r\n sumMap.set(v, k);\r\n }\r\n\r\n const segTree = new SegTree(N);\r\n segTree.update(sumMap.get(0), 1);\r\n const map = new Map();\r\n let dp = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _map$get, _dp;\r\n\r\n // dp[i] = (dp[i - 1] ?? 0) - (a[i] > 0 ? 1 : a[i] < 0 ? -1 : 0)\r\n dp[i] = segTree.query(0, sumMap.get(sum[i]) - 1) + i;\r\n dp[i] = Math.max(dp[i], (_map$get = map.get(sum[i])) !== null && _map$get !== void 0 ? _map$get : -Infinity, ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + (a[i] > 0 ? 1 : a[i] < 0 ? -1 : 0));\r\n segTree.update(sumMap.get(sum[i]), dp[i] - i);\r\n if (!map.has(sum[i]) || map.get(sum[i]) < dp[i] - i + 1) map.set(sum[i], dp[i]);\r\n }\r\n\r\n console.log(dp[n - 1]); // console.log(res)\r\n // return res\r\n // return\r\n}\r\n\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n\r\n this.update = (i, j) => {\r\n this._update(this.root, i, i, j);\r\n };\r\n\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = -Infinity, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _up(node) {\r\n var _left$val, _right$val;\r\n\r\n const {\r\n left,\r\n right\r\n } = node; // if (!left || !right) return\r\n\r\n node.val = Math.max((_left$val = left === null || left === void 0 ? void 0 : left.val) !== null && _left$val !== void 0 ? _left$val : -Infinity, (_right$val = right === null || right === void 0 ? void 0 : right.val) !== null && _right$val !== void 0 ? _right$val : -Infinity);\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val = Math.max(node.val, z);\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (y <= mid) {\r\n if (!node.left) node.left = this._newNode(l, mid);\r\n\r\n this._update(node.left, x, y, z);\r\n } else if (x > mid) {\r\n if (!node.right) node.right = this._newNode(mid + 1, r);\r\n\r\n this._update(node.right, x, y, z);\r\n } else {\r\n if (!node.left) node.left = this._newNode(l, mid);\r\n if (!node.right) node.right = this._newNode(mid + 1, r);\r\n this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n }\r\n\r\n this._up(node);\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return -Infinity;\r\n if (!node) return -Infinity;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = Math.max(this._query(node.left, x, mid), this._query(node.right, mid + 1, y));\r\n\r\n this._up(node);\r\n\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const n = Number(inputs[__ * 2 + 1].trim());\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n", "positive_code": [{"source_code": "'use strict';\n\nconst { timeStamp } = require('console');\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nfunction lsb(num) {\n return (num & -num);\n}\nfunction add(F, pos, val) {\n pos++;\n while (pos{\n\n let pref = []\n let v = [];\n for (let i=0; i{\n if (a[0]==b[0])\n return b[1]-a[1];\n return a[0]-b[0];\n });\n let F = [-Infinity]\n let ord = {};\n for (let i=0; i0)\n res = 1;\n else if (A[i]==0)\n res = 0;\n else\n res = -1;\n D[i] = (i>0 ? D[i-1] : 0) + res;\n D[i] = Math.max(D[i], ask(F, ord[i])+i)\n if (pref[i]>0)\n D[i] = i+1;\n add(F, ord[i], D[i]-i)\n }\n l({D})\n return D[n-1];\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = ra();\n l('ans')\n print(calc(n, A));\n }\n}\n \nE.calc = calc;"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n const sum = new Array(n).fill(0);\r\n let max = -Infinity,\r\n min = Infinity;\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n max = Math.max(max, sum[i]);\r\n min = Math.min(min, sum[i]);\r\n }\r\n min -= 10, max += 10;\r\n const segTree = new SegTree(min, max);\r\n segTree.update(0, 0, 1);\r\n const map = new Map();\r\n let dp = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _map$get, _dp;\r\n\r\n dp[i] = segTree.query(min, sum[i] - 1) + i;\r\n dp[i] = Math.max(dp[i], (_map$get = map.get(sum[i])) !== null && _map$get !== void 0 ? _map$get : -Infinity, ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) - 1);\r\n segTree.update(sum[i], sum[i], dp[i] - i);\r\n if (!map.has(sum[i]) || map.get(sum[i]) < dp[i] - i + 1) map.set(sum[i], dp[i]);\r\n }\r\n\r\n console.log(dp[n - 1]); // console.log(res)\r\n // return res\r\n // return\r\n}\r\n\r\nclass SegTree {\r\n constructor(min, max) {\r\n this.min = min;\r\n this.max = max;\r\n this.root = this._newNode(min, max);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = -Infinity, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _up(node) {\r\n var _left$val, _right$val;\r\n\r\n const {\r\n left,\r\n right\r\n } = node; // if (!left || !right) return\r\n\r\n node.val = Math.max((_left$val = left === null || left === void 0 ? void 0 : left.val) !== null && _left$val !== void 0 ? _left$val : -Infinity, (_right$val = right === null || right === void 0 ? void 0 : right.val) !== null && _right$val !== void 0 ? _right$val : -Infinity);\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val = Math.max(node.val, z);\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (y <= mid) {\r\n if (!node.left) node.left = this._newNode(l, mid);\r\n\r\n this._update(node.left, x, y, z);\r\n } else if (x > mid) {\r\n if (!node.right) node.right = this._newNode(mid + 1, r);\r\n\r\n this._update(node.right, x, y, z);\r\n } else {\r\n if (!node.left) node.left = this._newNode(l, mid);\r\n if (!node.right) node.right = this._newNode(mid + 1, r);\r\n this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n }\r\n\r\n this._up(node);\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return -Infinity;\r\n if (!node) return -Infinity;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = Math.max(this._query(node.left, x, mid), this._query(node.right, mid + 1, y));\r\n\r\n this._up(node);\r\n\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const n = Number(inputs[__ * 2 + 1].trim());\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n const sum = new Array(n).fill(0);\r\n let max = -Infinity,\r\n min = Infinity;\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n max = Math.max(max, sum[i]);\r\n min = Math.min(min, sum[i]);\r\n }\r\n min -= 10, max += 10;\r\n const segTree = new SegTree(min, max);\r\n segTree.update(0, 0, 1);\r\n const map = new Map();\r\n let dp = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _map$get, _dp$i;\r\n\r\n let cur = segTree.query(min, sum[i] - 1);\r\n\r\n if (cur === -Infinity) {\r\n var _dp, _dp2, _dp3;\r\n\r\n if (a[i] > 0) cur = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;else if (a[i] < 0) cur = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + -1;else cur = (_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0;\r\n } else {\r\n cur += i;\r\n }\r\n\r\n dp[i] = Math.max(cur, (_map$get = map.get(sum[i])) !== null && _map$get !== void 0 ? _map$get : -Infinity); // res = Math.max(res, cur)\r\n\r\n segTree.update(sum[i], sum[i], dp[i] - i);\r\n if (!map.has(sum[i]) || map.get(sum[i]) < ((_dp$i = dp[i]) !== null && _dp$i !== void 0 ? _dp$i : -Infinity)) map.set(sum[i], dp[i]);\r\n }\r\n\r\n console.log(dp[n - 1]); // console.log(res)\r\n // return res\r\n // return\r\n}\r\n\r\nclass SegTree {\r\n constructor(min, max) {\r\n this.min = min;\r\n this.max = max;\r\n this.root = this._newNode(min, max);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = -Infinity, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = Math.max(left.val, right.val);\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val = Math.max(z);\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n\r\n this._up(node);\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return -Infinity;\r\n if (!node) return -Infinity;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = Math.max(this._query(node.left, x, mid), this._query(node.right, mid + 1, y));\r\n\r\n this._up(node);\r\n\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const n = Number(inputs[__ * 2 + 1].trim());\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n const sum = new Array(n).fill(0);\r\n let max = -Infinity,\r\n min = Infinity;\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n max = Math.max(max, sum[i]);\r\n min = Math.min(min, sum[i]);\r\n }\r\n min -= 10, max += 10;\r\n const segTree = new SegTree(min, max);\r\n segTree.update(0, 0, 1);\r\n let dp = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n let cur = segTree.query(min, sum[i] - 1);\r\n\r\n if (cur === -Infinity) {\r\n var _dp;\r\n\r\n if (a[i] >= 0) cur = 1;else cur = -1;\r\n dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + cur;\r\n } else {\r\n cur += i;\r\n dp[i] = cur;\r\n } // res = Math.max(res, cur)\r\n\r\n\r\n segTree.update(sum[i], sum[i], dp[i] - i);\r\n }\r\n\r\n console.log(dp[n - 1]); // console.log(res)\r\n // return res\r\n // return\r\n}\r\n\r\nclass SegTree {\r\n constructor(min, max) {\r\n this.min = min;\r\n this.max = max;\r\n this.root = this._newNode(min, max);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = -Infinity, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = Math.max(left.val, right.val);\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val = Math.max(z);\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n\r\n this._up(node);\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return -Infinity;\r\n if (!node) return -Infinity;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = Math.max(this._query(node.left, x, mid), this._query(node.right, mid + 1, y));\r\n\r\n this._up(node);\r\n\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const n = Number(inputs[__ * 2 + 1].trim());\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}], "src_uid": "797533fd0d87c7f6de60aafac9a915cd"} {"source_code": "T = +readline();\r\nwhile(T--){\r\n nd =readline().split(' ').map(x=>+x);\r\n n=nd[0];\r\n d=nd[1];\r\n \r\n arr =readline().split(' ').map(x=>+x);\r\n arr.sort((a,b)=>a-b);\r\n if(arr[n-1]<=d)\r\n print('YES');\r\n else if(arr[0]+arr[1]<=d)\r\n print('YES');\r\n else print('NO');\r\n\r\n}\r\n", "positive_code": [{"source_code": "(()=>{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],e=0;e{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],e=0;e {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const nd = readLine().split(' ');\r\n\r\n const n = parseInt(nd[0]);\r\n const d = parseInt(nd[1]);\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,d, arr);\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n // console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n }\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet target;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n target = d.split(\" \").map(Number)[1];\n return;\n }\n\n const arr = d\n .split(\" \")\n .map(Number)\n .sort((a, b) => a - b);\n\n let count = 0;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] + arr[i - 1] <= target) {\n count++;\n }\n }\n\n if (count) {\n console.log(\"YES\");\n } else {\n if (arr[arr.length - 1] <= target) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tvar w = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n e = k[0];\n w = k[1];\n }else{\n var v1 = [];\n var v2 = [];\n for(j = 0; j < e; j++){\n if(k[j] <= w){\n v1.push(k[j]);\n }else{\n v2.push(k[j]);\n }\n }\n if(v2.length === 0){\n console.log('YES');\n }else{\n v1.sort(function(a, b){return a - b});\n if(v1.length >= 2){\n if(v1[0] + v1[1] <= w){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }else{\n console.log('NO');\n }\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tvar w = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t \tvar k = lines[i].split(' ').map(Number);\n\t if(i % 2 == 1){\n\t e = k[0];\n\t w = k[1];\n\t }else{\n\t var v1 = [];\n\t var v2 = [];\n\t for(j = 0; j < e; j++){\n\t if(k[j] <= w){\n\t v1.push(k[j]);\n\t }else{\n\t v2.push(k[j]);\n\t }\n\t }\n\t if(v2.length === 0){\n\t console.log('YES');\n\t }else{\n\t v1.sort(function(a, b){return a - b});\n\t if(v1.length >= 2){\n\t if(v1[0] + v1[1] <= w){\n\t console.log('YES');\n\t }else{\n\t console.log('NO');\n\t }\n\t }else{\n\t console.log('NO');\n\t }\n\t }\n\t }\n\t}\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n const [n, d] = readLine().split(\" \").map(i => parseInt(i));\r\n let min = 1001;\r\n let min2 = min;\r\n let arr = readLine().split(\" \").map(i => parseInt(i)).sort((a, b) => a - b);;\r\n if (arr[arr.length - 1] <= d) console.log(\"YES\");\r\n else {\r\n min = arr[0];\r\n min2 = arr[1];\r\n if (min + min2 <= d) {\r\n console.log(\"YES\")\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [n, d] = nl.nums();\n\t\tlet a = nl.nums();\n\t\ta.sort((a, b) => a - b);\n\t\tans.push(a[0] + a[1] <= d || a[n - 1] <= d);\n\t}\n\tconsole.log(ans.map(e => e?'YES':'NO').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const { sign } = require(\"crypto\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const array = input.slice(1).map(v => v.split(\" \").map(val => Number(val)));\r\n let d = 0;\r\n\r\n for(let idx in array) {\r\n if(idx % 2 === 0) d = array[idx][1];\r\n else {\r\n let cnt = 0;\r\n const arr = array[idx];\r\n for(let val of arr) {\r\n if(val <= d) cnt++; \r\n }\r\n\r\n if(cnt === arr.length) console.log(\"YES\");\r\n else {\r\n let isLess = false;\r\n for(let i=0; i jsin += chunk);\r\nprocess.stdin.on('end',function(){\r\n jsin = jsin.split('\\n')\r\n main();\r\n});\r\n\r\nreadLine = () => jsin[jscur++];\r\nreadLines = () => readLine().split(' ');\r\nreadInt = () => +(readLine());\r\nreadInts = () => readLine().split(' ').map(x => +(x));\r\n\r\nfunction main(){\r\n // code goes here!!\r\n var nTest = readInt();\r\n for(let test = 0;test < nTest;++test){\r\n let [n,d] = readInts();\r\n let a = readInts().filter(val => val <= d).sort((x,y) => {\r\n return x - y;\r\n });\r\n if(a.length == n){\r\n console.log(\"YES\");\r\n } else if(a.length > 1 && a[0] + a[1] <= d){\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n\r\n\r\n"}, {"source_code": "const replace = (a, d) => {\n let first = Infinity;\n let second = Infinity;\n let third = 0;\n for (let i = 0; i < a.length; i++) {\n if (a[i] < first) {\n second = first;\n first = a[i];\n } else if (a[i] < second) {\n second = a[i];\n }\n third = Math.max(third, a[i]);\n }\n return third <= d || first + second <= d;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n const [n, d] = readline()\n .split(\" \")\n .map(s => parseInt(s));\n const a = readline()\n .split(\" \")\n .map(s => parseInt(s));\n if (replace(a, d)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] > d){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tif(list[0] + list[1] <= d){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 == 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const [ln1, ln2] = rl().split(\" \");\r\n const ln3 = numArray(rl()).sort((a, b) => a - b);\r\n solution(ln1, ln2, ln3);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, d, arr) {\r\n if (arr[n - 1] <= d) {\r\n cl(\"Yes\");\r\n return;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n arr[n - 1] = arr[0] + arr[1];\r\n }\r\n // while (arr[n - 1] > d) {\r\n // console.log(arr[n - 1]);\r\n // }\r\n if (arr[n - 1] <= d) {\r\n cl(\"Yes\");\r\n return;\r\n } else cl(\"No\");\r\n // console.log(n, d, arr);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, d] = readline().split(' ');\r\n var ans = 99999\r\n var ans2 = 99999\r\n var index1 = 0\r\n var index2 = 0\r\n var isOk = true\r\n var array = readline().split(' ').map((x, i) => {\r\n if (Number(x) > d) isOk = false\r\n return Number(x)\r\n });\r\n if (isOk) return console.log('YES')\r\n array.map((x, i) => {\r\n if (x < ans) {\r\n ans = x\r\n index1 = i\r\n }\r\n })\r\n array.map((x, i) => {\r\n if (x < ans2 && index1 !== i) {\r\n ans2 = x\r\n index2 = i\r\n }\r\n })\r\n if (ans + ans2 <= d) return console.log('YES')\r\n return console.log('NO')\r\n\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst [len, target] = readLine().split(' ').map(Number);\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tlet allSmall = true;\n\t\tarr.sort((a, b) => a - b);\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tif (arr[i] > target) allSmall = false;\n\t\t}\n\t\tconst [a, b] = [arr[0], arr[1]];\n\t\tif (a + b <= target || allSmall) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "T=+readline();\r\nwhile(T--)\r\n{\r\n nd=readline().split(' ');\r\n n= parseInt(nd[0]);\r\n d= parseInt(nd[1]);\r\n arr=readline().split(' ').map(x=>+x);\r\n arr.sort(function(a,b){\r\n return a-b;\r\n });\r\n \r\n if(arr[n-1]<=d){\r\n print(\"YES\");\r\n }\r\n else{\r\n \r\n // console.log(arr);\r\n if((arr[0]+arr[1])<=d){\r\n print(\"YES\");\r\n\r\n }\r\n else {\r\n print(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var ar = readline().split(\" \").map(i => +i);\r\n \r\n ar.sort(function(a, b){return a-b});\r\n \r\n if (ar[s[0] - 1] <= d || ar[0] + ar[1] <= d) {\r\n print( \"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var ar = readline().split(\" \").map(i => +i);\r\n \r\n ar.sort(function(a, b){return a-b});\r\n \r\n if (ar[s[0] - 1] <= d || ar[0] + ar[1] <= d) {\r\n print( \"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort((a,b) => a - b);\r\n \r\n if (a[a.length - 1] > d) {\r\n print(a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}"}, {"source_code": "'use strict'\r\n\r\nlet t = readline(1);\r\n while(t--)\r\n {\r\n let nd = readline().split(\" \");\r\n let n = +nd[0], d = +nd[1];\r\n let a = readline(\"1 6 2 5 2 10\").split(\" \"), b = [];\r\n for(let i = 0; i < n; i++)b[i] = a[i];\r\n b.sort((x,y) => x - y);\r\n let c;\r\n if(b[n-1] <= d)c = true;\r\n else if(+b[0] + +b[1] <= d)c = true;\r\n else c = false;\r\n print(c? \"YES\" : \"NO\");\r\n }"}, {"source_code": "// var ar = readline().split(' ').map(n => parseInt(n));\r\n\r\nvar t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n var ar = readline()\r\n .split(\" \")\r\n .map((n) => parseInt(n));\r\n\r\n var n = ar[0];\r\n var k = ar[1];\r\n\r\n var arr = readline()\r\n .split(\" \")\r\n .map((a) => parseInt(a));\r\n\r\n var sortedArr = arr.sort((a, b) => a - b);\r\n if (sortedArr[sortedArr.length - 1] <= k) {\r\n print(\"yes\");\r\n } else {\r\n if (sortedArr[0] + sortedArr[1] <= k) {\r\n print(\"yes\");\r\n } else {\r\n print(\"no\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(iter; iter > 0; iter--){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let length = input[0];\r\n let d = input[1]\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n arr.sort((a, b) => a - b);\r\n \r\n if(arr[length - 1] <= d){\r\n print(\"YES\");\r\n } else {\r\n if(arr[0] + arr[1] <= d){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],e=0;e{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],e=0;e{\"use strict\";var t,n=(t=function(n,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])})(n,o)},function(n,o){function i(){this.constructor=n}t(n,o),n.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}),o=function(t){function o(n){var o=t.call(this,n)||this;return o.inp=n,o.startSolution(),o}return n(o,t),o.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var o=this.inp[n++],i=this.inp[n++],r=[],s=0;s{\"use strict\";var t,n=(t=function(n,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])})(n,o)},function(n,o){function r(){this.constructor=n}t(n,o),n.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}),o=function(t){function o(n){var o=t.call(this,n)||this;return o.inp=n,o.startSolution(),o}return n(o,t),o.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var o=this.inp[n++],r=this.inp[n++],i=[],s=0;s{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],s=0;s{\"use strict\";var t,n=(t=function(n,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])})(n,r)},function(n,r){function o(){this.constructor=n}t(n,r),n.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}),r=function(t){function r(n){var r=t.call(this,n)||this;return r.inp=n,r.startSolution(),r}return n(r,t),r.prototype.startSolution=function(){for(var t=this.inp[0],n=1;t>0;){for(var r=this.inp[n++],o=this.inp[n++],i=[],s=0;s {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const nd = readLine().split(' ');\r\n\r\n const n = parseInt(nd[0]);\r\n const d = parseInt(nd[1]);\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,d, arr);\r\n console.log(res);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n // console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n }\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "/*\r\n * File Created: Thursday, 14th January 2021 3:54:21 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const nd = readLine().split(' ');\r\n\r\n const n = parseInt(nd[0]);\r\n const d = parseInt(nd[1]);\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,d, arr);\r\n console.log(res);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n // console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n return 'NO'\r\n }\r\n }\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const nd = readLine().split(' ');\r\n\r\n const n = parseInt(nd[0]);\r\n const d = parseInt(nd[1]);\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,d, arr);\r\n console.log(res);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n return 'NO'\r\n }\r\n }\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const nd = readLine().split(' ');\r\n\r\n const n = parseInt(nd[0]);\r\n const d = parseInt(nd[1]);\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,d, arr);\r\n console.log(res);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n\r\n if(arr[0] + arr[1] > d){\r\n return 'NO'\r\n } else {\r\n return 'YES'\r\n }\r\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet target;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n target = d.split(\" \").map(Number)[1];\n return;\n }\n\n const arr = d\n .split(\" \")\n .map(Number)\n .sort((a, b) => a - b);\n\n let count = 0;\n const visited = {};\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] <= target) {\n if (!visited[arr[i]]) {\n count++;\n }\n }\n\n visited[arr[i]] = true;\n }\n\n if (count > 2) {\n console.log(\"YES\");\n } else if (arr.length >= 3 && arr[arr.length - 1] <= target) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet target;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n target = d.split(\" \").map(Number)[1];\n return;\n }\n\n const arr = d\n .split(\" \")\n .map(Number)\n .sort((a, b) => a - b);\n\n let count = 0;\n const visited = {};\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] <= target) {\n if (!visited[arr[i]]) {\n count++;\n }\n }\n\n visited[arr[i]] = true;\n }\n\n if (count > 2) {\n console.log(\"YES\");\n } else if (arr.length >= 3 && arr[arr.length - 1] === target) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "T=+readline();\r\nwhile(T--)\r\n{\r\n nd=readline();\r\n n= parseInt(nd[0]);\r\n d= parseInt(nd[2]);\r\n arr=readline().split(' ').map(function(x){\r\n return parseInt(x);\r\n })\r\n arr.sort(function(a,b){\r\n return a-b;\r\n });\r\n \r\n if(arr[n-1]<=d){\r\n print(\"YES\");\r\n }\r\n else{\r\n \r\n // console.log(arr);\r\n if((arr[0]+arr[1])<=d){\r\n print(\"YES\");\r\n\r\n }\r\n else {\r\n print(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "T=+readline();\r\nwhile(T--)\r\n{\r\n nd=readline();\r\n n= parseInt(nd[0]);\r\n d= parseInt(nd[2]);\r\n arr=readline().split(' ').map(function(x){\r\n return parseInt(x);\r\n })\r\n \r\n if(arr[n-1]<=d){\r\n print(\"YES\");\r\n }\r\n else{\r\n arr.sort(function(a,b){\r\n return a-b;\r\n });\r\n // console.log(arr);\r\n if((arr[0]+arr[1])<=d){\r\n print(\"YES\");\r\n\r\n }\r\n else {\r\n print(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "T=+readline();\r\nwhile(T--)\r\n{\r\n nd=readline();\r\n n= parseInt(nd[0]);\r\n d= parseInt(nd[2]);\r\n arr=readline().split(' ').map(function(x){\r\n return parseInt(x);\r\n })\r\n var c=0;\r\n for(var i=0;i +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n a.sort(function(b, c) {\r\n return +b > +c;\r\n });\r\n \r\n if (a[s[0] - 1] <= d || a[0] + a[1] <= d) {\r\n print( \"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n a.sort(function(a, b) {\r\n return +a > +b;\r\n });\r\n \r\n if (a[s[0] - 1] <= d || a[0] + a[1] <= d) {\r\n print( \"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[s[0] - 1] <= d || a[0] + a[1] <= d) {\r\n print( \"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[a.length - 1] <= d || a[0] + a[1] <= d) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[a.length - 1] >= d) {\r\n print(a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[a.length - 1] > d) {\r\n print(a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[a.length - 1] > d) {\r\n print(a[0] + a[1] < d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort((a,b) => a - b);\r\n \r\n if (a[a.length - 1] >= d) {\r\n print(a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split(\" \").map(i => +i); \r\n var d = s[1];\r\n var a = readline().split(\" \").map(i => +i);\r\n \r\n var a = a.sort();\r\n \r\n if (a[a.length - 1] >= d) {\r\n print(a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n}"}, {"source_code": "'use strict'\r\n\r\nlet t = readline(1);\r\n while(t--)\r\n {\r\n let nd = readline().split(\" \");\r\n let n = +nd[0], d = +nd[1];\r\n let a = readline(\"1 6 2 5 2 10\").split(\" \"), b = [];\r\n for(let i = 0; i < n; i++)b[i] = a[i];\r\n b.sort();\r\n let c;\r\n if(b[n-1] <= d)c = true;\r\n else if(+b[0] + +b[1] <= d)c = true;\r\n else c = false;\r\n print(c? \"YES\" : \"NO\");\r\n }"}], "src_uid": "044c2a3bafe4f47036ee81f2e40f639a"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n\tinputString = inputString.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = +readline();\n\tlet a = readline().split(' ').map(Number);\n\tlet max = 0;\n\tlet sum = 0;\n\tfor (let i = 1; i < n; i++) {\n\t\tif (a[i - 1] * 2 >= a[i]) {\n\t\t\tsum++;\n\t\t\tif (sum > max) max = sum;\n\t\t} else sum = 0;\n\t}\n\tconsole.log(max + 1);\n}\n", "positive_code": [{"source_code": "// var n = readline();\n// var nums = readline();\n// nums = nums.split(' ').map(function (ele) {\n// return +ele;\n// });\n// function check(low, hei) {\n// if (low <= hei && hei <= low * 2) {\n// return true;\n// }\n// return false;\n// }\n// //ssss\n// function solve() {\n// var slow = 0, fast = 1, max = 1;\n// if (nums.length < 2) {\n// return 1;\n// }\n// while (fast < +n) {\n// if (fast === slow) {\n// fast++;\n// continue;\n// }\n// var temp_rst = check(nums[slow], nums[fast]);\n// if (temp_rst) {\n// max = Max(max, fast - slow + 1);\n// fast++;\n// } else {\n// slow++;\n// }\n\n// }\n// return max;\n// }\n\n// function Max(a, b) {\n// return a > b ? a : b;\n// }\n// print(solve());\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\nvar n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n var tempLen = 1\n while (fast < +n) {\n if (check(nums[slow], nums[fast])) {\n tempLen++;\n } else {\n max = Math.max(tempLen, max);\n tempLen = 1;\n }\n fast++;\n slow++;\n }\n max = Math.max(tempLen, max);\n return max;\n}\nprint(solve());\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n\tinputString = inputString.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = +readline();\n\tlet a = readline().split(' ').map(Number);\n\tlet max = 0;\n\tlet sum = 0;\n\tfor (let i = 0; i < n; i++) {\n\t\tlet j = i;\n\t\twhile (j + 1 < n && a[j + 1] <= a[j] * 2) {\n\t\t\tj++;\n\t\t}\n\t\tmax = Math.max(j - i + 1, max);\n\t\ti = j;\n\t}\n\tconsole.log(max);\n}\n"}], "negative_code": [{"source_code": "var n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n while (fast < +n) {\n if (fast === slow) {\n fast++;\n }\n var temp_rst = check(nums[slow], nums[fast]);\n if (temp_rst) {\n max = Max(max, fast - slow + 1);\n fast++;\n } else {\n slow++;\n }\n\n }\n return max;\n}\n\nfunction Max(a, b) {\n return a > b ? a : b;\n}\nprint(solve());\n\n"}, {"source_code": "var n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\nfunction check(low, hei) {\n if (low < hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n while (fast < nums.length) {\n if (fast === slow) {\n fast++;\n }\n var temp_rst = check(nums[slow], nums[fast]);\n if (temp_rst) {\n max = Max(max, fast - slow + 1);\n fast++;\n } else {\n slow++;\n }\n\n }\n return max;\n}\n\nfunction Max(a, b) {\n return a > b ? a : b;\n}\nprint(solve());\n\n"}, {"source_code": "var n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\n//ssss\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n while (fast < +n) {\n if (fast === slow) {\n fast++;\n }\n var temp_rst = check(nums[slow], nums[fast]);\n if (temp_rst) {\n max = Max(max, fast - slow + 1);\n fast++;\n } else {\n slow++;\n }\n\n }\n return max;\n}\n\nfunction Max(a, b) {\n return a > b ? a : b;\n}\nprint(solve());\n\n"}, {"source_code": "// var n = readline();\n// var nums = readline();\n// nums = nums.split(' ').map(function (ele) {\n// return +ele;\n// });\n// function check(low, hei) {\n// if (low <= hei && hei <= low * 2) {\n// return true;\n// }\n// return false;\n// }\n// //ssss\n// function solve() {\n// var slow = 0, fast = 1, max = 1;\n// if (nums.length < 2) {\n// return 1;\n// }\n// while (fast < +n) {\n// if (fast === slow) {\n// fast++;\n// continue;\n// }\n// var temp_rst = check(nums[slow], nums[fast]);\n// if (temp_rst) {\n// max = Max(max, fast - slow + 1);\n// fast++;\n// } else {\n// slow++;\n// }\n\n// }\n// return max;\n// }\n\n// function Max(a, b) {\n// return a > b ? a : b;\n// }\n// print(solve());\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\nvar n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n var tempLen = 1\n while (fast < +n) {\n if (check(nums[slow], nums[fast])) {\n tempLen++;\n } else {\n max = Math.max(tempLen, max);\n tempLen = 1;\n }\n fast++;\n slow++;\n }\n return max;\n}\nprint(solve());\n"}, {"source_code": "// var n = readline();\n// var nums = readline();\n// nums = nums.split(' ').map(function (ele) {\n// return +ele;\n// });\n// function check(low, hei) {\n// if (low <= hei && hei <= low * 2) {\n// return true;\n// }\n// return false;\n// }\n// //ssss\n// function solve() {\n// var slow = 0, fast = 1, max = 1;\n// if (nums.length < 2) {\n// return 1;\n// }\n// while (fast < +n) {\n// if (fast === slow) {\n// fast++;\n// continue;\n// }\n// var temp_rst = check(nums[slow], nums[fast]);\n// if (temp_rst) {\n// max = Max(max, fast - slow + 1);\n// fast++;\n// } else {\n// slow++;\n// }\n\n// }\n// return max;\n// }\n\n// function Max(a, b) {\n// return a > b ? a : b;\n// }\n// print(solve());\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\nvar n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n var tempLen = 1\n while (fast < +n) {\n if (check(nums[slow], nums[fast])) {\n tempLen++;\n } else {\n max = Math.max(tempLen, max);\n tempLen = 1;\n }\n fast++;\n slow++;\n }\n return max;\n}\n"}, {"source_code": "var n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\n//ssss\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n while (fast < +n) {\n if (fast === slow) {\n fast++;\n continue;\n }\n var temp_rst = check(nums[slow], nums[fast]);\n if (temp_rst) {\n max = Max(max, fast - slow + 1);\n fast++;\n } else {\n slow++;\n }\n\n }\n return max;\n}\n\nfunction Max(a, b) {\n return a > b ? a : b;\n}\nprint(solve());\n\n"}, {"source_code": "var n = readline();\nvar nums = readline();\nnums = nums.split(' ').map(function (ele) {\n return +ele;\n});\nfunction check(low, hei) {\n if (low <= hei && hei <= low * 2) {\n return true;\n }\n return false;\n}\n\nfunction solve() {\n var slow = 0, fast = 1, max = 1;\n if (nums.length < 2) {\n return 1;\n }\n while (fast < nums.length) {\n if (fast === slow) {\n fast++;\n }\n var temp_rst = check(nums[slow], nums[fast]);\n if (temp_rst) {\n max = Max(max, fast - slow + 1);\n fast++;\n } else {\n slow++;\n }\n\n }\n return max;\n}\n\nfunction Max(a, b) {\n return a > b ? a : b;\n}\nprint(solve());\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n\tinputString = inputString.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = +readline();\n\tlet a = readline().split(' ').map(Number);\n\tlet max = 0;\n\tlet sum = 0;\n\tfor (let i = 1; i < n; i++) {\n\t\tif (sum > max) max = sum;\n\t\tif (a[i - 1] * 2 >= a[i]) sum++;\n\t\telse sum = 0;\n\t}\n\tconsole.log(max + 1);\n}\n"}], "src_uid": "5088d1d358508ea3684902c8e32443a3"} {"source_code": "var n = +readline();\nvar tab = [];\nvar ans = 'Yes';\nfor (var i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n lab.push(d.split(' ').map(Number));\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 'YES';\n\n isDone:\n for (let i = 0; i < lab.length; i++) {\n for (let j = 0; j < lab[i].length; j++) {\n if (lab[i][j] !== 1) {\n\n ans = 'NO';\n for (let t = 0; t < lab.length; t++) {\n for (let s = 0; s < lab[t].length; s++) {\n let sum = lab[t][j] + lab[i][s];\n\n if (t !== i && s !== j) {\n if (sum === lab[i][j]) {\n ans = 'YES';\n }\n }\n }\n }\n\n if (ans === 'NO') {\n break isDone;\n }\n\n }\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "var n = parseInt(readline()),\n\tarr = [],\n\tflag = true;\nfunction mapper(x) {return parseInt(x);}\nfor (var i = 0; i < n; i++) {\n\tvar temp = [];\n\tvar inp = readline().split(\" \").map(mapper);\n\tarr.push(inp);\n}\n\nfunction checker(i, j) {\n\tfor (var c = 0; c < n; c++) {\n\t\tif (c == j)\n\t\t\tcontinue;\n\t\tfor (var r = 0; r < n; r++) {\n\t\t\tif (r == i)\n\t\t\t\tcontinue;\n\t\t\tif (arr[i][c] + arr[r][j] == arr[i][j])\n\t\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfor (var i = 0; i < n; i++) {\n\tfor (var j = 0; j < n && flag; j++) {\n\t\tif (arr[i][j] != 1 && !checker(i, j)) {\n\t\t\tflag = false;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nprint((flag ? \"Yes\": \"No\"));"}, {"source_code": "var n = Number(readline());\nvar arr = [];\nfor(var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1,a2)=>a1 - a2)\n let left = -1\n let right = -1\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n left = i\n break;\n }\n }\n\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] !== clone[i]) {\n right = i\n break;\n }\n }\n\n if (left === -1 && right === -1) {\n console.log('yes')\n console.log(1 + ' ' + 1)\n return\n }\n\n for (let i = 0; i < Math.floor(right - left); i++) {\n if (a[left + i] !== clone[right - i]) {\n console.log('no')\n return\n }\n }\n\n console.log('yes')\n console.log((left + 1) + ' ' + (right + 1))\n}\n\n", "positive_code": [{"source_code": "\t\tvar l=readline();\n\tvar s=readline().split(\" \");\n\tvar f=0,max=0,min=0,maxi=1,mini=1;\n\t\n\t\tfor(var i=0;iparseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;mini=i+1;}\n\t\t\tif(i===s.length-2){min=parseInt(s[i+1]);maxi=i+2;}}\n\t\t\telse{if(f===1&&min===0&&max1||parseInt(s[i+1])1){if(min>parseInt(s[mini-2])){print(\"yes\\n\"+mini+\" \"+maxi);}else{print(\"no\");}}else{print(\"yes\\n\"+mini+\" \"+maxi);}}\n\telse{print(\"no\");}"}, {"source_code": ";(function() {\n\n\tprint((function (n, x) {\n\t\tfor (var i = 0; i < n; i++) if (x[i] !== i) break;\n\t\tfor (var j = n - 1; j >= 0; j--) if (x[j] !== j) break;\n\t\tif (i === n && j === -1) return 'yes\\n1 1';\n\t\tfor (var k = i; k < j; k++) if (x[k] - x[k+1] !== 1) return 'no';\n\t\tif (x[j] === i && x[i] === j) return 'yes\\n' + (i + 1) + ' ' + (j + 1);\n\t\treturn 'no';\n\t})(+readline(), readline().split(' ').map(function (e, i) { return {n: parseInt(e), i: i}; })\n\t\t.sort(function (a, b) { return a.n - b.n; }).map(function (e) { return e.i; })));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\ta = tokenizeIntegers(readline());\n\tif (n == 1) {\n\t\treturn 'yes\\n1 1';\n\t}\n\tfor (var i = 1; i < n; ++i) {\n\t\tif (a[i] < a[i-1]) {\n\t\t\tfor (var j = i; a[j] < a[j-1] && j < n; ++j) {\n\t\t\t}\n\t\t\tvar start = i-1, finish = j-1;\n\t\t\tfor (var p = Math.floor((start+finish)/2); p >= start; --p) {\n\t\t\t\tvar q = finish - p + start,\n\t\t\t\t\tt = a[p];\n\t\t\t\ta[p] = a[q];\n\t\t\t\ta[q] = t;\n\t\t\t}\n\t\t\tfor (var k = 1; k < n; ++k) {\n\t\t\t\tif (a[k] < a[k-1]) {\n\t\t\t\t\treturn 'no';\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 'yes\\n'+(start+1)+' '+(finish+1);\n\t\t}\n\t}\n\treturn 'yes\\n1 1';\n}\n\nprint(main());\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n const arr = readLine().split(' ').map(Number);\n\n const result = sortTheArray(n, arr);\n printResult(result);\n}\n\nfunction reverseByIndex(a, left, right) {\n const temp = [];\n for (let i = left, j = right; i <= right; i++, j--) temp[i] = a[j];\n for (let i = left; i <= right; i++) a[i] = temp[i];\n}\n\nconst sortTheArray = (n, a) => {\n let left = 0;\n let right = 0;\n let flag = false;\n for (let i = 0; i < n - 1; i++) {\n if (a[i] > a[i + 1]) {\n left = i;\n break;\n }\n }\n\n for (let i = n - 1; i >= left; i--) {\n if (a[i] < a[i - 1]) {\n right = i;\n break;\n }\n }\n\n reverseByIndex(a, left, right);\n\n for (let i = 0; i < n - 1; i++) {\n if (a[i] > a[i + 1]) {\n return `no`;\n }\n }\n\n return `yes\\n${left + 1} ${right + 1}`;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n const arr = readLine().split(' ').map(Number);\n\n const result = sortTheArray(n, arr);\n printResult(result);\n}\n\nfunction reverseByIndex(a, left, right) {\n const temp = new Array(a.length);\n for (let i = left, j = right; i <= right; i++, j--) temp[i] = a[j];\n for (let i = left; i <= right; i++) a[i] = temp[i];\n}\n\nconst sortTheArray = (n, a) => {\n let left = 0;\n let right = 0;\n for (let i = 0; i < n - 1; i++) {\n if (a[i] > a[i + 1]) {\n left = i;\n break;\n }\n }\n\n for (let i = n - 1; i >= left; i--) {\n if (a[i] < a[i - 1]) {\n right = i;\n break;\n }\n }\n\n reverseByIndex(a, left, right);\n\n for (let i = 0; i < n - 1; i++) {\n if (a[i] > a[i + 1]) {\n return `no`;\n }\n }\n\n return `yes\\n${left + 1} ${right + 1}`;\n};"}, {"source_code": "let isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v)\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n sortedArr = lines[1].split(\" \").map(Number),\n mas = []\n if (isSorted(arr)) {\n console.log(`yes\\n1 1`)\n return 0\n }\n sortedArr.sort((a, b) => a - b)\n for (let i in arr) {\n if (arr[i] != sortedArr[i])\n mas.push(+i + 1)\n }\n mas.sort((a, b) => a - b)\n arr = arr.slice(mas[0] - 1, mas[mas.length - 1])\n sortedArr = sortedArr.slice(mas[0] - 1, mas[mas.length - 1]).reverse()\n if (arr.join(\" \") == sortedArr.join(\" \")) console.log(`yes\\n${mas[0]} ${mas[mas.length - 1]}`)\n else console.log(`no`)\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "let isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v)\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n sortedArr = lines[1].split(\" \").map(Number),\n n = arr.length,\n cnt = 0,\n mas = []\n if (isSorted(arr)) {\n console.log(`yes\\n1 1`)\n return 0\n }\n sortedArr.sort((a, b) => a - b)\n for (let i in arr) {\n if (arr[i] != sortedArr[i]) {\n cnt++;\n mas.push(+i + 1)\n }\n }\n mas.sort((a, b) => a - b)\n arr = arr.slice(mas[0] - 1, mas[mas.length - 1])\n sortedArr = sortedArr.slice(mas[0] - 1, mas[mas.length - 1]).reverse()\n if (arr.join(\" \") == sortedArr.join(\" \")) console.log(`yes\\n${mas[0]} ${mas[mas.length - 1]}`)\n else console.log(`no`)\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "function processData(input) {\n //Enter your code here\n input = input.split('\\n')\n var n = Number(input[0])\n var arr = input[1].split(' ').map(a=>parseInt(a))\n var tempArr = [...arr]\n // console.log(tempArr)\n tempArr.sort((a,b)=>(a-b))\n // console.log(tempArr,arr)\n var ans\n var res = checkReverse(arr,tempArr,n) //finding first mismatch\n\n if(res){\n console.log(\"yes\")\n }\n else{\n console.log(\"no\")\n }\n function checkReverse(arr,tempArr,n){\n //to find the first index mismatch\n for(var first = 0;first < n;first++){\n if(tempArr[first] != arr[first]){\n break\n }\n }\n //to find the last mismatch\n for(var last = n-1;last >=0 ;last--){ \n if(tempArr[last] != arr[last]){\n break\n }\n }\n if(first >= last){\n ans = [first-n+1,first-n+1]\n return true\n }\n //to check decreasing array\n ans = [first+1,last+1]\n while(first != last){\n first++\n if(arr[first-1] < arr[first]){\n return false\n }\n \n }\n\n return true\n } \n if(res){\n console.log(ans.join(' '))\n\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1, a2) => a1 - a2)\n let differences = []\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n differences.push(i + 1)\n }\n if (differences.length > 2) {\n console.log('no')\n return\n }\n }\n \n if (differences.length === 2) {\n console.log('yes')\n console.log(differences[0] + ' ' + differences[1])\n } else {\n console.log('no')\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1, a2) => a1 - a2)\n let left = -1\n let right = -1\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n if (left === -1) {\n left = i\n right = i\n } else {\n right = i\n }\n }\n }\n\n if (left === -1 && right === -1) {\n console.log('yes')\n console.log(1 + ' ' + 1)\n return\n }\n\n \n for (let i = 0; i <= Math.floor((right - left) / 2); i++) {\n if (a[left + i] !== clone[right - i]) {\n console.log('no')\n return\n }\n }\n\n console.log('yes')\n console.log((left + 1) + ' ' + (right + 1))\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1,a2)=>a1 - a2)\n let left = -1\n let right = -1\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n left = i\n break;\n }\n }\n\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] !== clone[i]) {\n right = i\n break;\n }\n }\n\n if (left === -1 && right === -1) {\n console.log('yes')\n console.log(1 + ' ' + 1)\n return\n }\n\n for (let i = 0; i <= Math.floor((right - left) / 2); i++) {\n if (a[left + i] !== clone[right - i]) {\n console.log('no')\n return\n }\n }\n\n console.log('yes')\n console.log((left + 1) + ' ' + (right + 1))\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1,a2)=>a1 - a2)\n let left = -1\n let right = -1\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n left = i\n break;\n }\n }\n\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] !== clone[i]) {\n right = i\n break;\n }\n }\n\n if (left === -1 && right === -1) {\n console.log('yes')\n console.log(1 + ' ' + 1)\n return\n }\n\n for (let i = 0; i < Math.floor((right - left) / 2); i++) {\n if (a[left + i] !== clone[right - i]) {\n console.log('no')\n return\n }\n }\n\n console.log('yes')\n console.log((left + 1) + ' ' + (right + 1))\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number(readline())\n const a = readline().split(' ').map(Number)\n \n helper(n, a)\n}\n\nfunction helper(n, a) {\n let clone = [...a]\n clone.sort((a1, a2) => a1 - a2)\n let differences = []\n for (let i = 0; i < n; i++) {\n if (a[i] !== clone[i]) {\n differences.push(i + 1)\n }\n if (differences.length > 2) {\n console.log('no')\n return\n }\n }\n \n if (differences.length === 2) {\n console.log('yes')\n console.log(differences[0] + ' ' + differences[1])\n } else if (differences.length === 0) {\n console.log('yes')\n console.log(1 + ' ' + 1)\n } else {\n console.log('no')\n }\n}"}, {"source_code": "let isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v)\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n sortedArr = lines[1].split(\" \").map(Number),\n n = arr.length,\n cnt = 0,\n mas = []\n if (isSorted(arr)) {\n console.log(`yes\\n1 1`)\n return 0\n }\n sortedArr.sort((a, b) => a - b)\n for (let i in arr) {\n if (arr[i] != sortedArr[i]) {\n cnt++;\n mas.push(+i + 1)\n }\n }\n mas.sort((a, b) => a - b)\n console.log(mas)\n arr = arr.slice(mas[0] - 1, mas[mas.length - 1])\n sortedArr = sortedArr.slice(mas[0] - 1, mas[mas.length - 1]).reverse()\n console.log(arr, sortedArr)\n if (arr.join(\" \") == sortedArr.join(\" \")) console.log(`yes\\n${mas[0]} ${mas[mas.length - 1]}`)\n else console.log(`no`)\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "\n\tvar l=readline();\n\tvar s=readline().split(\" \");\n\tvar f=0,max=0,min=0,maxi=1,mini=1;\n\t\n\t\tfor(var i=0;iparseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;mini=i+1;}\n\t\t\tif(i===s.length-2){if(mini-2>=0){if(parseInt(s[i+1])>parseInt(s[mini-2])){min=parseInt(s[i+1]);maxi=i+2;}}else if(mini-2===-1){min=parseInt(s[i+1]);maxi=i+2;}}}\n\t\t\telse{if(f===1&&min===0&&maxparseInt(s[mini-2])){min=parseInt(s[i]);maxi=i+1;}else if(f>1||parseInt(s[i+1])parseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;}if(i===s.length-2){min=parseInt(s[i+1]);}}\n\t\t\telse{if(f===1&&min===0&&max1||parseInt(s[i+1])parseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;mini=i+1;}\n\t\t\tif(i===s.length-2){if(mini-2>=0){if(parseInt(s[i+1])>parseInt(s[mini-2])){min=parseInt(s[i+1]);maxi=i+2;}}}}\n\t\t\telse{if(f===1&&min===0&&maxparseInt(s[mini-2])){min=parseInt(s[i]);maxi=i+1;}else if(f>1||parseInt(s[i+1])parseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;mini=i+1;}\n\t\t\tif(i===s.length-2){min=parseInt(s[i+1]);maxi=i+2;}}\n\t\t\telse{if(f===1&&min===0&&max1||parseInt(s[i+1])1){if(min>parseInt(s[mini-2])){print(\"yes\\n\"+mini+\" \"+maxi);}}else{print(\"yes\\n\"+mini+\" \"+maxi);}}\n\telse{print(\"no\");}"}, {"source_code": "\tvar l=readline();\n\tvar s=readline().split(\" \");\n\tvar f=0,max=0,min=0,maxi=1,mini=1;\n\t\n\t\tfor(var i=0;iparseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;mini=i+1;}\n\t\t\tif(i===s.length-2){min=parseInt(s[i+1]);maxi=i+2;}}\n\t\t\telse{if(f===1&&min===0&&max1||parseInt(s[i+1])parseInt(s[i+1])){if(parseInt(s[i])>max){max=parseInt(s[i]);f++;}if(i===s.length-2){min=parseInt(s[i+1]);}}\n\t\t\telse{if(f===1&&min===0&&max1||parseInt(s[i+1])= 0; j--) if (x[j] !== j) break;\n\t\tif (i === n - 1 && j === 1) return 'yes\\n1 1';\n\t\tfor (var k = i; k < j; k++) if (x[k] - x[k+1] !== 1) return 'no';\n\t\treturn (x[j] === i && x[i] === j) ? 'yes\\n' + (i + 1) + ' ' + (j + 1) : 'no';\n\t})(+readline(), readline().split(' ').map(function (e, i) { return {n: parseInt(e), i: i}; })\n\t\t.sort(function (a, b) { return a.n - b.n; }).map(function (e) { return e.i; })));\n\n}).call(this);"}, {"source_code": ";(function() {\n\n\tprint((function (n, x) {\n\t\tfor (var i = 0; i < n; i++) if (x[i] !== i) break;\n\t\tfor (var j = n - 1; j >= 0; j--) if (x[j] !== j) break;\n\t\tif (i === n && j === -1) return 'yes\\n1 1';\n\t\tfor (var k = j; k < i; k++) if (x[j] - x[j-1] !== 1) return 'no';\n\t\tif (x[j] === i && x[i] === j) return 'yes\\n' + (i + 1) + ' ' + (j + 1);\n\t\treturn 'no';\n\t})(+readline(), readline().split(' ').map(function (e, i) { return {n: parseInt(e), i: i}; })\n\t\t.sort(function (a, b) { return a.n - b.n; }).map(function (e) { return e.i; })));\n\n}).call(this);"}, {"source_code": ";(function() {\n\n\tvar n = +readline(),\n\t\tx = readline().split(' ')\n\t\t\t.map(function (e, i) { return {n: parseInt(e), i: i}; })\n\t\t\t.sort(function (a, b) { return a.n - b.n; })\n\t\t\t.map(function (e) { return e.i; });\n\n\tprint((function () {\n\t\tfor (var i = 0; i < n; i++) if (x[i] !== i) break;\n\t\tfor (var j = n - 1; j >= 0; j--) if (x[j] !== j) break;\n\t\tif (i === (n - 2) && j === 1) return 'yes\\n1 1';\n\t\tfor (var k = j; k < i; k++) if (x[j] - x[j-1] !== 1) return 'no';\n\t\tif (x[j] === i && x[i] === j) return 'yes\\n' + (i + 1) + ' ' + (j + 1);\n\t\treturn 'no';\n\t})());\n\n}).call(this);"}, {"source_code": ";(function() {\n\n\tvar n = +readline(),\n\t\ta = readline().split(' ').map(Number).reduce(function (p, e, i, a) {\n\t\t\tif (p.push(i) !== a.length) return p;\n\t\t\tp = p.sort(function (_, $) { return a[_] - a[$]; });\n\n\t\t\tvar max = [], min = [];\n\n\t\t\tif (p[0] > p[1]) max.push(1);\n\n\t\t\tfor (var i = 1; i < n - 1; i++)\n\t\t\t\tif (p[i] > p[i+1] && p[i] > p[i-1]) max.push(i + 1);\n\t\t\t\telse if (p[i] < p[i+1] && p[i] < p[i-1]) min.push(i + 1);\n\n\t\t\tif (p[n - 1] < p[n - 2]) min.push(n);\n\n\t\t\treturn [max, min];\n\t\t}, []);\n\n\t\tprint((function () {\n\t\t\tif (!a[0].length && !a[1].length) return 'yes\\n1 1';\n\t\t\tif (a[0].length > 1) return 'no';\n\t\t\treturn 'yes\\n' + a[0][0] + ' ' + a[1][0];\n\t\t})());\n\n}).call(this);"}], "src_uid": "c9744e25f92bae784c3a4833c15d03f4"} {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet cnt = {};\n\tlet c = readLine()\n\t\t.split(' ')\n\t\t.map(x => {\n\t\t\tx = x >> 0;\n\t\t\tcnt[x] = (cnt[x] || 0) + 1;\n\t\t\treturn x;\n\t\t});\n\tif (cnt[0] === undefined) {\n\t\tconsole.log(-1);\n\t} else {\n\t\tif (cnt[5] === undefined || cnt[5] < 9) console.log(0);\n\t\telse {\n\t\t\tlet q = Math.floor(cnt[5] / 9);\n\t\t\tconsole.log('5'.repeat(q * 9) + '0'.repeat(cnt[0]));\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "\nvar n=+readline();\nvar a=readline().split(' ');\n\nvar five=0;\nvar zero=0;\na.forEach(function(v){\n\tif(v==='5'){\n\t\tfive++;\n\t}else{\n\t\tzero++;\n\t}\n});\n\nfive=Math.floor(five/9);\nif(zero==0){\n\tprint(-1);\n}else if(five==0){\n\tprint(0)\n}else{\n\tvar ans=[];\n\t//var k=Math.min(five,zero);\n\tfor(var i=0;i parseInt( ai, 10 ) );\n// Prime factors of 90 are 2, 3^2 and 5.\n// In our case number is divisible by 2 if at least one zero at the end.\n// Number is divisible by 9 if its digits sum divisible by 9. In our case that is repeated 555555555 only.\n// Number is divisible by 5 if last digit is zero.\nvar fives = a.filter( ai => ai === 5);\nvar zeros = a.filter( ai => ai === 0);\nvar answer = -1;\nif ( zeros.length > 0 ) {\n if ( fives.length >= 9 ) {\n answer = [ ...fives.slice( 0, fives.length - fives.length % 9), ...zeros ].join( \"\" ); \n } else {\n answer = 0;\n }\n}\n\nprint( answer );"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.sort((a, b) => b - a);\n\n let [count0, count5] = [0, 0];\n for (let i = 0; i < len; i++) {\n if (arr[i] === 0) count0++;\n if (arr[i] === 5) count5++;\n }\n count5 = count5 - (count5 % 9);\n if (count5 > 0 && count0 > 0) {\n console.log([...Array(count5).fill(5), ...Array(count0).fill(0)].join(\"\"));\n } else if (count0 > 0) {\n console.log(0);\n } else {\n console.log(-1);\n }\n}\n"}], "negative_code": [{"source_code": "\nvar n=+readline();\nvar a=readline().split(' ');\n\nvar five=0;\nvar zero=0;\na.forEach(function(v){\n\tif(v==='5'){\n\t\tfive++;\n\t}else{\n\t\tzero++;\n\t}\n});\n\nfive=Math.floor(five/9);\nif(five==0||zero==0){\n\tprint(0);\n}else{\n\tvar ans=[];\n\tvar k=Math.min(five,zero);\n\tfor(var i=0;i parseInt( ai, 10 ) );\n// Prime factors of 90 are 2, 3 and 5.\n// In our case number is divisible by 2 if at least one zero at the end.\n// Number is divisible by 3 if its digits sum divisible by 3. In our case that is repeated 555 only.\n// Number is divisible by 5 if last digit is zero.\nvar fives = a.filter( ai => ai === 5);\nvar zeros = a.filter( ai => ai === 0);\nvar answer = -1;\nif ( zeros.length > 0 ) {\n if ( fives.length >= 3 ) {\n answer = [ ...fives.slice( 0, fives.length - fives.length % 3), ...zeros ].join( \"\" ); \n } else {\n answer = 0;\n }\n}\n\nprint( answer );"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet cnt = {};\n\tlet c = readLine()\n\t\t.split(' ')\n\t\t.map(x => {\n\t\t\tx = x >> 0;\n\t\t\tcnt[x] = (cnt[x] || 0) + 1;\n\t\t\treturn x;\n\t\t});\n\tif (cnt[0] === undefined) {\n\t\tconsole.log(-1);\n\t} else {\n\t\tif (n < 9) console.log(0);\n\t\telse {\n\t\t\tlet q = Math.floor(cnt[5] / 9);\n\t\t\tconsole.log('5'.repeat(q * 9) + '0');\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet cnt = {};\n\tlet c = readLine()\n\t\t.split(' ')\n\t\t.map(x => {\n\t\t\tx = x >> 0;\n\t\t\tcnt[x] = (cnt[x] || 0) + 1;\n\t\t\treturn x;\n\t\t});\n\tif (cnt[0] === undefined) {\n\t\tconsole.log(-1);\n\t} else {\n\t\tif (n < 9) console.log(0);\n\t\telse {\n\t\t\tlet q = Math.floor(cnt[5] / 9);\n\t\t\tconsole.log('5'.repeat(q * 9) + '0'.repeat(cnt[0]));\n\t\t}\n\t}\n}\n"}], "src_uid": "409b27044d5ec97b5315c92d4112376f"} {"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar T = +readline();\n\nwhile(T--) {\n var input = readline().split(' ').map(value => +value);\n var n = input[0];\n var s = input[1];\n var t = input[2];\n\n var d = (s+t) - n;\n var ds = s - d;\n var dt = t - d;\n\n write(Math.max(ds, dt) + 1, '\\n');\n}", "positive_code": [{"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\nconst {EOL} = require('os')\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n res(i.split(EOL).map(line => line.split(' ').map(str => parseInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join(EOL));\n}\n\n\ngetInput(false).then(lines => {\n if(isNaN(lines[lines.length-1][0])) lines.pop();\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n var q = read.number();\n var res = '';\n\n for(var i = 0; i < q; i++) {\n var line = read.arrNumber(' ');\n if(line[0] === line[1] && line[0] === line[2]) {\n res += '1 \\n';\n }\n else {\n var a = line[2] + line[1] - line[0];\n res += Math.min(line[0], Math.max(line[1], line[2]) - a + 1) + '\\n';\n }\n }\n\n print(res);\n\n}());"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, s, t] = d.split(' ').map(Number);\n const min = Math.min(s, t);\n const ans = n - min + 1;\n\n console.log(ans);\n\n c++;\n});\n"}], "negative_code": [{"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n const {EOL} = require('os')\n res(i.split(EOL).map(line => line.split(' ').map(str => parseInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join('\\r\\n'));\n}\n\n\ngetInput(true).then(lines => {\n if(isNaN(lines[lines.length-1][0])) lines.pop();\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n res(i.split('\\r\\n').map(line => line.split(' ').map(str => BigInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join('\\r\\n'));\n}\n\n\ngetInput(true).then(lines => {\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n res(i.split('\\r\\n').map(line => line.split(' ').map(str => parseInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join('\\r\\n'));\n}\n\n\ngetInput(false).then(lines => {\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\nconst {EOL} = require('os')\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n res(i.split(EOL).map(line => line.split(' ').map(str => parseInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join(EOL));\n}\n\n\ngetInput(true).then(lines => {\n if(isNaN(lines[lines.length-1][0])) lines.pop();\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "const testInput = [\n [3],\n [10, 5, 7],\n [10, 10, 10],\n [2, 1, 1]\n]\n\nfunction getInput(test = false) {\n return new Promise((res,rej) => {\n if (test) return res(testInput);\n let i = ''\n process.stdin.on('data', c => i += c)\n process.stdin.on('end', () => {\n res(i.split('\\r\\n').map(line => line.split(' ').map(str => parseInt(str))));\n }) \n })\n}\n\nfunction output(lines) {\n console.log(lines.join('\\r\\n'));\n}\n\n\ngetInput(true).then(lines => {\n if(isNaN(lines[lines.length-1][0])) lines.pop();\n lines.shift();\n const answer = lines.map(line => line[0] + 1 - Math.min(line[1],line[2]))\n output(answer);\n})\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n var q = read.number();\n var res = '';\n\n for(var i = 0; i < q; i++) {\n var line = read.arrNumber(' ');\n if((line[0] === line[1] && line[2] > 0) || (line[0] === line[2] && line[1] > 0)) {\n res += '1 \\n';\n }\n else {\n res += Math.min(line[0], Math.min(line[1], line[2]) + 1) + '\\n';\n }\n }\n\n print(res);\n\n}());"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n var q = read.number();\n var res = '';\n\n for(var i = 0; i < q; i++) {\n var line = read.arrNumber(' ');\n if(line[0] === line[1] || line[0] === line[2]) {\n res += '1 \\n';\n }\n else {\n var a = line[2] + line[1] - line[0];\n res += Math.min(line[0], Math.max(line[1], line[2]) - a + 1) + '\\n';\n }\n }\n\n print(res);\n\n}());"}], "src_uid": "fb0a4c8f737c36596c2d8c1ae0d1e34e"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node solution.js < input.txt > output.txt\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n let arr = readLine().split(\" \");\r\n let a1 = parseInt(arr[0]), a2 = parseInt(arr[1]), a3 = parseInt(arr[2])\r\n if ((a1 + a3 - 2 * a2) % 3 == 0) {\r\n console.log(0)\r\n } else {\r\n console.log(1)\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var k = lines[i].split(' ').map(Number);\n\t var a = k[0], b = k[1], c = k[2];\n\t b *= 2;\n\t a += c;\n\t var d = Math.abs(a - b);\n\t console.log(d % 3 === 0 ? 0 : 1);\n\t}\n});\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n if (!h(a, b, c)) return 0\n if (!h(b, c, a)) return 0\n if (!h(c, a, b)) return 0\n return 1\n}\nfunction h(a, b, c) {\n return !!(Math.abs(a + b - 2 * c) % 3)\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar sum = nextInt() + nextInt() + nextInt();\r\n\t\tif(sum % 3 == 0){\r\n\t\t\tmyout(0);\r\n\t\t}else{\r\n\t\t\tmyout(1);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var k = lines[i].split(' ').map(Number);\n\t var a = k[0], b = k[1], c = k[2];\n\t b *= 2;\n\t a += c;\n\t console.log(Math.abs(a - b) % 3 === 0 ? 0 : 1);\n\t}\n});\n\n\n"}], "negative_code": [], "src_uid": "5bffe38e3ac9511a30ee02b4ec5cb1d5"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const str = readLine();\n let [s1, s0] = [``, ``];\n for (let i = 0; i < len; i++) {\n if (i % 2 === 0) {\n s1 += \"1\";\n s0 += \"0\";\n } else {\n s1 += \"0\";\n s0 += \"1\";\n }\n }\n let count = 0;\n\n if (str[0] === \"1\") {\n for (let i = 0; i < len; i++) {\n if (s1[i] !== str[i]) {\n while (s1[i] !== str[i]) {\n i++;\n }\n count++;\n }\n }\n } else {\n for (let i = 0; i < len; i++) {\n if (s0[i] !== str[i]) {\n while (s0[i] !== str[i]) {\n i++;\n }\n count++;\n }\n }\n }\n console.log(count);\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n reverseBS();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction reverseBS(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = readline().split('');\n\n let count = 0;\n let i = 0;\n let res1 = 0;\n while(i < n){\n while(i < n && s[i] === '1'){\n i++;\n count++;\n }\n if(count > 0)\n res1 += count-1;\n count = 0;\n i++;\n }\n\n let res2 = 0;\n count = 0;\n i = 0;\n while(i < n){\n while(i < n && s[i] === '0'){\n i++;\n count++;\n }\n if(count > 0)\n res2 += count-1;\n count = 0;\n i++;\n }\n\n console.log(Math.max(res1,res2));\n }\n}"}, {"source_code": "//cat q2.text | node q2.js\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n for (let i = 0; i < x; i++) {\n const y = readline();\n const d = readline().split(\"\");\n let count1 = 0;\n let count2=0;\n\n for(let i=0; i < d.length-1;i++){\n if(d[i] == 0 && d[i+1] == 0)count1++;\n if(d[i] == 1 && d[i+1] == 1)count2++;\n }\n\n console.log(Math.max(count1,count2))\n }\n\n\n\n}\n"}, {"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x));\n var n = Ar[0]\n var s = readline();\n\n var cnt = 0;\n for (var i = 1; i <= n - 1; i++){\n if (s[i] == s[i - 1]) cnt++;\n }\n print(Math.floor((cnt + 1) / 2));\n}\n"}, {"source_code": "const solve = (s) => {\n let n = s.length;\n let res = 0;\n for (let i = 0; i + 1 < n; i++) {\n if (s[i] == s[i + 1]) {\n res++;\n }\n }\n return (res + 1) >> 1;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}], "negative_code": [{"source_code": "const solve = (s) => {\n let n = s.length;\n let res = 0;\n let pos1 = [];\n for (let i = 0; i < n; i++) {\n if (i % 2 == 0 && s[i] == '1') {\n pos1.push(i);\n res++;\n }\n if (i % 2 == 1 && s[i] == '0') {\n pos1.push(i);\n res++;\n }\n }\n let pos2 = [];\n for (let i = 0; i < n; i++) {\n if (pos1.indexOf(i) == -1) pos2.push(i);\n }\n return Math.min(remove(res, pos1), remove(n - res, pos2));\n};\n\nconst remove = (res, pos) => {\n let n = pos.length;\n for (let i = 0; i + 1 < n; i++) {\n if (pos[i + 1] - pos[i] == 1) {\n res--;\n }\n }\n return res;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (s) => {\n return Math.min(operate(s, '0'), operate(s, '1'));\n};\n\nconst flip = (ch) => {\n return (ch == '0') ? '1' : '0';\n};\n\nconst operate = (s, expected) => {\n let flipCnt = 0;\n let set = new Set();\n for (let i = 0; i < s.length; i++) {\n if (s[i] != expected) {\n if (!set.has(i - 1) && !set.has(i + 1)) {\n flipCnt++;\n set.add(i);\n }\n }\n expected = flip(expected);\n }\n return flipCnt;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (s) => {\n return Math.min(operate(s, '0'), operate(s, '1'));\n};\n\nconst flip = (ch) => {\n return (ch == '0') ? '1' : '0';\n};\n\nconst operate = (s, expected) => {\n let flipCnt = 0;\n let set = new Set();\n for (let i = 0; i < s.length; i++) {\n if (s[i] != expected) {\n if (!set.has(i - 1) && !set.has(i + 1)) {\n flipCnt++;\n set.add(i);\n }\n }\n expected = flip(expected);\n }\n return flipCnt;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (s) => {\n let n = s.length;\n let res = 0;\n for (let i = 0; i + 1 < n; i++) {\n if (s[i] == s[i + 1]) {\n res++;\n }\n }\n return (res + 1) >> 1;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (s) => {\n let n = s.length;\n let res = 0;\n let pos1 = [];\n for (let i = 0; i < n; i++) {\n if (i % 2 == 0 && s[i] == '1') {\n pos1.push(i);\n res++;\n }\n if (i % 2 == 1 && s[i] == '0') {\n pos1.push(i);\n res++;\n }\n }\n let pos2 = [];\n for (let i = 0; i < n; i++) {\n if (pos1.indexOf(i) == -1) pos2.push(i);\n }\n return Math.min(remove(res, pos1), remove(n - res, pos2));\n};\n\nconst remove = (res, pos) => {\n let n = pos.length;\n for (let i = 0; i + 1 < n; i++) {\n if (pos[i + 1] - pos[i] == 1) {\n res--;\n }\n }\n return res;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line);\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(data);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n reverseBS();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction reverseBS(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = readline().split('');\n\n let count = 0;\n let i = 0;\n let res = 0;\n while(i < n){\n while(i < n && s[i] === '1'){\n i++;\n count++;\n }\n if(count > 0)\n res += count-1;\n count = 0;\n i++;\n }\n console.log(res);\n }\n}"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var d = readline().split('');\n \n var res = 0;\n \n for (var x = 0; x < d.length; x++) {\n if (d[x] == '0') {\n res++;\n }\n }\n \n print(Math.floor(res/2));\n}"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var n = parseInt(readline());\n var s = readline();\n\n var cnt = 0;\n for (var i = 1; i < n - 1; i++){\n if (s[i] == s[i - 1]) cnt++;\n print(Math.floor((cnt + 1) / 2));\n }\n}\n"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var Ar = readline().split(' ').map(x => parseInt(x));\n var n = Ar[0]\n var s = readline();\n\n var cnt = 0;\n for (var i = 1; i < n - 1; i++){\n if (s[i] == s[i - 1]) cnt++;\n }\n print(Math.floor((cnt + 1) / 2));\n}\n"}], "src_uid": "fd1e3368fbfbc3792831623398c94d80"} {"source_code": "/**\n * Created by marcos on 04/02/2016.\n */\nfunction is_int(value){\n return parseFloat(value) == parseInt(value);\n}\nvar points = readline().split(\" \").map(function(n) { return parseInt(n)});\n\nvar x = points[0];\nvar y = points[1];\nif (!is_int((x)) || !is_int((y))) {\n print(\"0\");\n}\n\n\nvar min = x > y ? y : x;\n\nprint(min + 1);\nfor(var i = 0 ; i < min + 1; i ++){\n print(i , min - i);\n}", "positive_code": [{"source_code": "(function main() {\n var v = readline().split(' ');\n var n = parseInt(v[0]);\n var m = parseInt(v[1]);\n m = Math.min(n,m) + 1;\n ans = '' + m + '\\n';\n for (var i = 0; i < m; ++i)\n ans += i + ' ' + (m - i - 1) + '\\n';\n print(ans);\n})();"}, {"source_code": "print(function(n, m) {\n\n\tvar ret = [];\n\n\tfor (var x = 0, y = m; x <= n && y >= 0; x++, y--)\n\t\tret.push(x + ' ' + y)\n\n\treturn ret.length + '\\n' + ret.join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(n, m) {\n\n\tvar ret = [];\n\n\tfor (var x = 0, y = 1; x <= n && y <= m; x += 2, y += 2)\n\t\tret.push(x + ' ' + y)\n\tfor (var x = 1, y = 0; x <= n && y <= m; x += 2, y += 2)\n\t\tret.push(x + ' ' + y)\n\n\n\treturn ret.length + '\\n' + ret.join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, m) {\n\n\tvar ret = [];\n\n\tfor (var x = 0, y = 1; x <= n && y <= m; x++, y++)\n\t\tret.push(x + ' ' + y)\n\n\tif (x-1 < n)\n\t\tret.push(n + ' ' + 0);\n\n\treturn ret.length + '\\n' + ret.join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "print(function(n, m) {\n\n\tvar ret = ['0 1', '1 0'];\n\n\tfor (var x = 2, y = 3; x <= n && y <= m; x++, y++)\n\t\tret.push(x + ' ' + y)\n\n\treturn ret.length + '\\n' + ret.join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, m) {\n\n\tvar ret = [];\n\n\tfor (var x = 0, y = 1; x <= n && y <= m; x++, y++)\n\t\tret.push(x + ' ' + y)\n\n\tif (x < n)\n\t\tret.push(n + ' ' + 0);\n\n\treturn ret.length + '\\n' + ret.join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "/**\n * Created by marcos on 04/02/2016.\n */\nfunction is_int(value){\n return parseFloat(value) == parseInt(value);\n}\nvar points = readline().split(\" \").map(function(n) { return parseInt(n)});\n\nvar x = points[0];\nvar y = points[1];\nif (!is_int((x)) || !is_int((y))) {\n print(\"0\");\n}\n\n\nvar min = x > y ? y : x;\n\nfor(var i = 0 ; i < min + 1; i ++){\n print(i , min - i);\n}"}], "src_uid": "0e99f4a49b408cc8874a6d5ec4167acb"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n var a = readline();\n\n nm = nm.split(' ')\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n let s = []\n let cnt = []\n\n for (let i = 0; i < m; i++) {\n cnt[i] = 0\n }\n\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n a = a.split(' ').map(v => Number(v))\n\n for (let i = 0; i < n; i++) {\n let x = a[i]\n x--\n x = Math.min(x, m - 1 - x)\n cnt[x]++\n }\n\n for (let i = 0; i < m; i++) {\n if(!cnt[i]) continue\n\n s[i] = 'A'\n if(cnt[i] > 1) s[m - 1 - i] = 'A'\n } \n\n console.log(s.toString().replace(/,/g, ''))\n }\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n nm = nm.split(' ')\n var a = readline();\n a = a.split(' ').map(v => Number(v))\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n // if(n == 2 && m == 43) console.log(1)\n let s = []\n\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n for(let i = 0; i < n; i++) {\n let x = a[i]\n let y = m - a[i] + 1\n x--\n y--\n // swap\n if(x > y) {\n let temp = x\n x = y\n y = temp\n }\n if(s[x] == 'A') {\n s[y] = 'A'\n } else {\n s[x] = 'A'\n }\n\n }\n \n console.log(s.toString().replace(/,/g, ''))\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n var a = readline();\n\n nm = nm.split(' ')\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n let s = []\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n a = a.split(' ').map(v => Number(v))\n\n // first transform using ai\n for (let i = 0; i < n; i++) {\n // print the a[i]th characterof s\n // first character of s is not s[1] it is s[0]\n const ai = a[i] - 1\n\n // print the (m + 1 - a[i])th character of s\n const mp1 = m - ai - 1\n \n // compare aith andmp1maith and transform the smaller index\n if (ai < mp1 && s[ai] != 'A') s[ai] = 'A'\n else if(s[mp1] == 'B') s[mp1] = 'A'\n else s[ai] = 'A'\n }\n\n console.log(s.toString().replace(/,/g, ''))\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n var a = readline();\n\n nm = nm.split(' ')\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n let s = []\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n a = a.split(' ').map(v => Number(v))\n\n // first transform using ai\n for (let i = 0; i < n; i++) {\n // print the a[i]th characterof s\n // first character of s is not s[1] it is s[0]\n var x = a[i] - 1\n x = Math.min(x, m - x - 1) \n \n // print the (m + 1 - a[i])th character of s\n // const mp1 = m + 1 - a[i] - 1\n\n // compare aith andmp1maith and transform the smaller index\n if (s[x] == 'B') s[x] = 'A'\n else s[m - x - 1] = 'A'\n }\n\n console.log(s.toString().replace(/,/g, ''))\n }\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_m[0];\n const m = n_m[1];\n\n if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n let output = calc(val, m);\n console.log(output)\n }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "function stringMinimization() {\r\n const [n, m] = r().split` `.map(Number);\r\n a = r().split` `.map(Number);\r\n\r\n let s = new Set();\r\n function tryBothGreedy(arr, idx) {\r\n let [i1, i2] = [idx - 1, m - idx].sort((a, b) => a - b);\r\n arr1 = [...arr];\r\n if (arr[i1] !== 'A') {\r\n arr1[i1] = 'A';\r\n } else {\r\n arr1[i2] = 'A';\r\n }\r\n return arr1;\r\n }\r\n\r\n function tryBoth(arr, idx) {\r\n let [i1, i2] = [idx - 1, m - idx];\r\n arr1 = [...arr];\r\n arr1[i1] = 'A';\r\n arr2 = [...arr];\r\n arr2[i2] = 'A';\r\n return [arr1, arr2];\r\n }\r\n\r\n let initialArr = Array(m).fill('B');\r\n\r\n function helper(slate, i) {\r\n if (i >= a.length) {\r\n s.add(slate.join(''));\r\n return;\r\n } // base case\r\n\r\n // let [arr1, arr2] = tryBoth(slate, a[i]);\r\n let arr1 = tryBothGreedy(slate, a[i]);\r\n\r\n helper(arr1, i + 1);\r\n // helper(arr2, i + 1);\r\n }\r\n\r\n helper(initialArr, 0);\r\n log([...s].sort()[0]);\r\n}\r\n\r\nfunction main() {\r\n let tt = +r();\r\n for (; tt; tt--) stringMinimization();\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nr = readline;\r\nlog = console.log;\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var [n, m] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n // a.sort();\r\n // console.log(a)\r\n var cnt = []\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let stra = ('B').repeat(m).split('');\r\n\r\n let hash = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n let a = arr[i] - 1;\r\n let b = m - arr[i];\r\n let [smaller, larger] = [Math.min(a, b), Math.max(a, b)];\r\n if (hash[smaller] === undefined) {\r\n hash[smaller] = true;\r\n stra[smaller] = 'A';\r\n } else {\r\n hash[larger] = true;\r\n stra[larger] = 'A';\r\n }\r\n }\r\n\r\n output(stra.join(''));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var nm = readline().split(\" \").map(x => parseInt(x));\r\n let n = nm[0];\r\n let m = nm[1];\r\n var arr = readline().split(\" \").map(x=> parseInt(x));\r\n var s = Array(m).fill('B');\r\n for (let i = 0;i < n;++i) {\r\n let nin = Math.min(arr[i]-1,m-arr[i]);\r\n let nax = Math.max(arr[i]-1,m-arr[i]);\r\n if (s[nin] == 'A') {\r\n s[nax] = 'A';\r\n } else {\r\n s[nin] = 'A';\r\n }\r\n }\r\n let res = s.join('');\r\n console.log(res.toString());\r\n }\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n var numTest = readline();\r\n\r\n while (numTest--) {\r\n\r\n var nm = readline();\r\n var a = readline();\r\n\r\n nm = nm.split(' ')\r\n let n = Number(nm[0])\r\n let m = Number(nm[1]) \r\n let s = []\r\n for (let i = 0; i < m; i++) \r\n {\r\n s.push(\"B\")\r\n } \r\n a = a.split(' ').map(v => Number(v))\r\n for (let i = 0; i < n; i++) \r\n {\r\n const ai = a[i] - 1\r\n const mp1 = m - ai - 1\r\n if (ai < mp1 && s[ai] != 'A') s[ai] = 'A'\r\n else if(s[mp1] == 'B') s[mp1] = 'A'\r\n else s[ai] = 'A'\r\n }\r\n console.log(s.toString().replace(/,/g, ''))\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n let res = new Array(m).fill('B');\r\n for (let i of a) {\r\n if (res[i - 1] === 'A') {\r\n res[m - i] = 'A';\r\n } else if (res[m - i] === 'A') {\r\n res[i - 1] = 'A';\r\n } else {\r\n if (i < m + 1 - i) res[i - 1] = 'A';else res[m - i] = 'A';\r\n }\r\n }\r\n return res.join('');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet arr = [];\r\nconst precompute = () => {\r\n arr.push(1n);\r\n let k = 2n;\r\n for (let i = 1; i < 51; i++, k = k * 2n) arr[i] = k;\r\n};\r\nconst solve = () => {\r\n precompute();\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [m, n] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = new Array(n).fill(0).map((cur) => \"B\");\r\n let obj = {};\r\n for (let i = 0; i < m; i++) {\r\n if (arr[i] > Math.ceil(n / 2)) {\r\n if (res[n - arr[i]] === \"B\") res[n - arr[i]] = \"A\";\r\n else res[arr[i] - 1] = \"A\";\r\n } else {\r\n if (res[arr[i] - 1] === \"B\") res[arr[i] - 1] = \"A\";\r\n else res[n - arr[i]] = \"A\";\r\n }\r\n }\r\n console.log(res.join(\"\"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n_m = readLine().split(' ').map(p => +p);\r\n const arr = readLine().split(' ').map(p => +p);\r\n myFunc(n_m[0], n_m[1], arr);\r\n }\r\n}\r\n \r\n \r\nfunction myFunc(n, m, arr){\r\n let B = new Array(m).fill('B');\r\n\r\n for(let i = 0; i < n; i++){\r\n if(B[arr[i]-1] == 'A') B[m-arr[i]] = 'A';\r\n else if(B[m-arr[i]] == 'A') B[arr[i]-1] = 'A';\r\n else if(arr[i]-1 < m-arr[i]){\r\n B[arr[i]-1] = 'A';\r\n }\r\n else{\r\n B[m-arr[i]] = 'A';\r\n }\r\n }\r\n\r\n console.log(B.join(''));\r\n\r\n}\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n var set = new Set();\r\n for (var i = 0; i < n;i++) {\r\n var min = Math.min(seq[i], m + 1 - seq[i]);\r\n var max = Math.max(seq[i], m + 1 - seq[i]);\r\n if (!set.has(min)) {\r\n set.add(min);\r\n } else if (!set.has(max)) {\r\n set.add(max);\r\n }\r\n }\r\n var ans = [];\r\n for (var i = 0; i < m; i++) {\r\n if (set.has(i+1)) {\r\n ans.push('A')\r\n } else {\r\n ans.push('B');\r\n }\r\n }\r\n print(ans.join(''));\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n var n,m;\r\n var arr = readline().split(\" \");\r\n n = parseInt(arr[0]);\r\n m = parseInt(arr[1]);\r\n var list = readline().split(\" \").map(x => parseInt(x));\r\n var str = [];\r\n for(var i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n nm = nm.split(' ')\n var a = readline();\n a = a.split(' ').map(v => Number(v))\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n if(n == 2 && m == 43) console.log(1)\n let s = []\n\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n for(let i = 0; i < n; i++) {\n let x = a[i]\n let y = m - a[i] + 1\n x--\n y--\n // swap\n if(x > y) {\n let temp = x\n x = y\n y = temp\n }\n if(s[x] == 'A') {\n s[y] = 'A'\n } else {\n s[x] = 'A'\n }\n\n }\n \n console.log(s.toString().replace(/,/g, ''))\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\n var numTest = readline();\n\n while (numTest--) {\n\n var nm = readline();\n var a = readline();\n\n a = a.split(' ').map(v => Number(v))\n\n nm = nm.split(' ')\n let n = Number(nm[0]) // the length of sequence a\n let m = Number(nm[1]) // the length of string s\n let cnt = []\n\n for (let i = 0; i < m; i++) {\n cnt[i] = 0;\n }\n\n for (let i = 0; i < n; i++) {\n a.map(x => {\n x--\n x = Math.min(x, m - 1 - x)\n cnt[x]++\n })\n }\n\n let s = []\n for (let i = 1; i <= m; i++) {\n s.push(\"B\")\n } // m Bees\n\n\n for(let i = 0; i < m; i++) {\n if(!cnt[i]) continue\n\n s[i] = 'A'\n if(cnt[i] > 1) s[m - 1 - i] = 'A'\n }\n\n // // first transform using ai\n // for (let i = 0; i < n; i++) {\n // // print the a[i]th characterof s\n // // first character of s is not s[1] it is s[0]\n // const ai = a[i] - 1\n\n // // print the (m + 1 - a[i])th character of s\n // const mp1 = m + 1 - a[i] - 1\n\n // // compare aith andmp1maith and transform the smaller index\n // if (ai < mp1 && s[ai] != 'A') s[ai] = 'A'\n // else s[mp1] = 'A'\n // }\n\n console.log(s.toString().replace(/,/g, ''))\n }\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n // //console.log(a)\n // //console.log(m)\n\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n let c_s = s;\n //console.log(ai + \", \" + (m + 1 - ai))\n\n if (ai < (m + 1 - ai)) {\n let _s = c_s.replaceAt(ai - 1, \"A\");\n //console.log(\"_s = \" + _s + \", s = \" + s + \", \" + compare(_s, s))\n if (compare(_s, s) < 0) {\n s = _s;\n //console.log(s)\n continue;\n } else if (compare(_s, s) >= 0) {\n //console.log((m + 1 - ai) + \" \" + s.length)\n // if (m + 1 - ai <= s.length) {\n let cs =s\n let __ss = cs.replaceAt(m + 1 - ai - 1, \"A\");\n //console.log(\"__s = \" + __ss)\n if (compare(__ss, s) < 0) {\n s = __ss;\n //console.log(s)\n continue;\n } else {\n return s;\n }\n // } \n }\n } else {\n let _s = c_s.replaceAt(m + 1 - ai - 1, \"A\");\n //console.log(\"_s = \" + _s + \", s = \" + s + \", \" + compare(_s, s))\n if (compare(_s, s) < 0) {\n s = _s;\n //console.log(s)\n continue;\n } if (compare(_s, s) >= 0) {\n // //console.log((m + 1 - ai) + \" \" + s.length)\n // if (m + 1 - ai <= s.length) {\n let cs =s\n let __ss = cs.replaceAt(ai - 1, \"A\");\n //console.log(\"__s = \" + __ss)\n if (compare(__ss, s) < 0) {\n s = __ss;\n //console.log(s)\n continue;\n } else {\n return s;\n }\n // } \n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_m[0];\n const m = n_m[1];\n\n if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n let output = calc(val, m);\n console.log(output)\n }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var [n, m] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n a.sort();\r\n // console.log(a)\r\n var cnt = []\r\n for(var i=0;i i) {\r\n cnt[(m+1)-a[i]] = 1;\r\n cnt[a[i]] = 1;\r\n } else {\r\n // var m = min(a[i], (m+1)-a[i]);\r\n // console.log(m)\r\n cnt[min(a[i], (m+1)-a[i])] = 1;\r\n }\r\n i = j\r\n }\r\n // console.log(cnt)\r\n var ans = \"\";\r\n for(var i=1;i<=m;i++) {\r\n if(cnt[i]==1) ans += \"A\";\r\n else ans += \"B\"\r\n }\r\n console.log(ans)\r\n}\r\n"}], "src_uid": "eee23388aa7cda50302fc4da6e50e172"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n let [a, m] = readInts()\n let g = gcd(a, m)\n m = m / g\n let prime = primeFactors(m)\n let c = 1\n let k = 0, p = prime[0]\n for(let i = 0, l = prime.length; i < l; i++) {\n if(prime[i] === p) k++\n else {\n c *= (p ** k) * (p - 1) / p\n p = prime[i]\n k = 1\n }\n }\n c *= (p ** k) * (p - 1) / p\n // wr(c, m, g, prime)\n wr(c)\n }\n}\n\nfunction primeFactors(num) {\n const factors = []\n while(num % 2 === 0) {\n factors.push(2)\n num /= 2\n }\n for(let i = 3, sqrt = Math.floor(Math.sqrt(num)); i <= sqrt; i += 2) {\n while(num % i === 0) {\n factors.push(i)\n num /= i\n }\n }\n if(num > 2) factors.push(num)\n return factors\n}\n\nfunction gcd(x, y) {\n if(y === 0) return x\n else return gcd(y, x % y)\n}\n\n\n", "positive_code": [{"source_code": "n=+readline()\nfunction gcd(a,b){\n if (!b)\n return a;\n return gcd(b,a%b)\n}\nfor (t=0;t1)\n ans*=(p-p/j)\n }\n if (b>1)\n ans=ans*(b-1)\n print(ans)\n}"}], "negative_code": [], "src_uid": "adcd813d4c45337bbd8bb0abfa2f0e00"} {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\nfunction print(x) { process.stdout.write(x); }\r\n\r\nfunction ones_in_2x2(s, i, j) {\r\n let count = 0;\r\n for (let u = i, k = 0; k < 2; ++k, ++u)\r\n for (let v = j, l = 0; l < 2; ++l, ++v)\r\n if (s[u][v] == '1')\r\n ++count;\r\n return count; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) {\r\n const size = nextList();\r\n const n = size[0], m = size[1], p = n-1, q = m-1; \r\n let s = Array(n);\r\n for (let i = 0; i < n; ++i)\r\n s[i] = next();\r\n let elegant = true;\r\n for (let i = 0; i < p && elegant; ++i)\r\n for (let j = 0; j < q && elegant; ++j)\r\n elegant = ones_in_2x2(s,i,j) != 3;\r\n console.log(elegant? \"YES\": \"NO\"); } }\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n ", "positive_code": [{"source_code": "// const { readline, print } = require('@ip-algorithmics/codeforces-io');\n\nfunction hasOnlyOneEmptyInSquare(array, a, b) {\n var countZero = 0;\n\n for (var i = 0; i < 2; ++i) {\n for (var j = 0; j < 2; ++j) {\n if (array[a+i][b+j] === 0) {\n countZero++;\n }\n }\n }\n\n return countZero === 1;\n}\n\nvar line = readline().split(' ').map(x => parseInt(x))\nvar testCases = line[0]\n\nvar n, m\nwhile (testCases--) {\n line = readline().split(' ').map(x => parseInt(x))\n n = line[0]\n m = line[1]\n\n var array = new Array(n)\n \n for (var i = 0; i < n ; ++i) {\n array[i] = [];\n line = readline();\n\n for (var j = 0; j < line.length; ++j) {\n array[i].push(parseInt(line[j]));\n }\n }\n\n if (n < 2 || m < 2) {\n print('YES')\n continue;\n }\n\n var isElegant = true;\n for (i = 0; i < array.length - 1; i++) {\n for (j = 0; j < array[i].length - 1; j++) {\n if (hasOnlyOneEmptyInSquare(array, i, j)) {\n isElegant = false;\n }\n }\n }\n\n print (isElegant ? 'YES' : 'NO')\n}\n\n\n\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n,m;\r\n var mat;\r\n var visited;\r\n\r\n function checkSquare(i, j) {\r\n visited[i][j] = 1;\r\n var col = j;\r\n while (col < m && mat[i][col]) {\r\n col++;\r\n visited[i][col] = 1;\r\n }\r\n var width = col - j;\r\n \r\n var row = i+1;\r\n while (row < n && mat[row][j]) {\r\n if (j > 0 && mat[row][j-1]) {\r\n return false;\r\n }\r\n col = j;\r\n while (col < j + width) {\r\n visited[row][col] = 1;\r\n if (!mat[row][col]) {\r\n return false;\r\n }\r\n col++;\r\n }\r\n visited[row][col] = 1;\r\n if (mat[row][col]) {\r\n return false;\r\n }\r\n row++;\r\n }\r\n if (row < n) {\r\n for (var c = j; c < j + width; c++) {\r\n visited[row][c] = 1;\r\n if (mat[row][c]) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n for (var t=0; t < tests; t++) {\r\n var nm = readline().split(' ').map(x=>parseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n visited = [];\r\n for (var i = 0; i < n; i++) {\r\n mat.push(readline().split('').map(x=>parseInt(x)));\r\n visited.push(new Array(m).fill(0));\r\n }\r\n\r\n var ans = 'YES';\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n if (visited[i][j]) {\r\n continue;\r\n }\r\n if (!mat[i][j]) {\r\n visited[i][j] = 1;\r\n continue;\r\n }\r\n if (checkSquare(i, j)) {\r\n continue;\r\n }\r\n ans = 'NO';\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length; j++) {\r\n\r\n // \r\n\r\n if(arr[i][j] ==1){\r\n if(j !==0 && arr[i+1][j] ==1 && arr[i+1][j-1] ==1 && arr[i][j-1] ==0 ){\r\n eleg= false;\r\n // console.log(i,j,\"1st\")\r\n break;\r\n }\r\n\r\n if(arr[i+1][j]==1 && arr[i+1][j+1] ==1 && arr[i][j+1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"2st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j]==1 && arr[i+1][j+1] ==0){\r\n eleg = false;\r\n // console.log(i,j,\"3st\")\r\n break;\r\n }\r\n\r\n if(i !== 0 && arr[i][j+1]==1 && arr[i-1][j+1] == 1 && arr[i-1][j] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"4st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j+1] ==1 && arr[i+1][j]==0){\r\n eleg =false;\r\n // console.log(i,j,\"5st\")\r\n break;\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length; j++) {\r\n\r\n // \r\n\r\n if(arr[i][j] ==1){\r\n if(j !==0 && arr[i+1][j] ==1 && arr[i+1][j-1] ==1 && arr[i][j-1] ==0 ){\r\n eleg= false;\r\n // console.log(i,j,\"1st\")\r\n break;\r\n }\r\n\r\n if(arr[i+1][j]==1 && arr[i+1][j+1] ==1 && arr[i][j+1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"2st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j]==1 && arr[i+1][j+1] ==0){\r\n eleg = false;\r\n // console.log(i,j,\"3st\")\r\n break;\r\n }\r\n\r\n if(i !== 0 && arr[i][j+1]==1 && arr[i-1][j+1] == 1 && arr[i-1][j] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"4st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j+1] ==1 && arr[i+1][j]==0){\r\n eleg =false;\r\n // console.log(i,j,\"5st\")\r\n break;\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++)\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur))\r\n );\r\n let sum = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n for (let j = 0; j < m - 1; j++) {\r\n if (\r\n arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1] ===\r\n 3\r\n ) {\r\n sum = false;\r\n break;\r\n }\r\n }\r\n }\r\n console.log(`${sum === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, s) {\r\n const sum = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n var _sum$j, _sum, _sum$i, _sum2, _sum3;\r\n sum[i][j] = ((_sum$j = (_sum = sum[i - 1]) === null || _sum === void 0 ? void 0 : _sum[j]) !== null && _sum$j !== void 0 ? _sum$j : 0) + ((_sum$i = sum[i][j - 1]) !== null && _sum$i !== void 0 ? _sum$i : 0) - ((_sum2 = (_sum3 = sum[i - 1]) === null || _sum3 === void 0 ? void 0 : _sum3[j - 1]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Number(s[i][j]);\r\n }\r\n }\r\n const p = [...new Array(n * m).keys()];\r\n const find = i => {\r\n if (p[i] !== i) p[i] = find(p[p[i]]);\r\n return p[i];\r\n };\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const dirs = [[0, 1], [1, 0]];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n const a = i * m + j;\r\n if (s[i][j] === '0') {\r\n p[a] = -1;\r\n continue;\r\n }\r\n for (let [di, dj] of dirs) {\r\n const ni = di + i,\r\n nj = dj + j,\r\n b = ni * m + nj;\r\n if (ni < 0 || ni >= n || nj < 0 || nj >= m || s[ni][nj] === '0') continue;\r\n union(a, b);\r\n }\r\n }\r\n }\r\n const scc = new Map();\r\n for (let [i, num] of p.entries()) {\r\n if (num === -1) continue;\r\n const root = find(num);\r\n if (!scc.has(root)) scc.set(root, []);\r\n scc.get(root).push(i);\r\n }\r\n for (let [, points] of scc) {\r\n var _sum$rb, _sum$rr, _sum4, _sum5, _sum6;\r\n let ll = Infinity,\r\n lt = Infinity,\r\n rr = -Infinity,\r\n rb = -Infinity;\r\n for (let num of points) {\r\n const i = Math.floor(num / m),\r\n j = num % m;\r\n ll = Math.min(ll, j);\r\n lt = Math.min(lt, i);\r\n rr = Math.max(rr, j);\r\n rb = Math.max(rb, i);\r\n }\r\n if (sum[rb][rr] - ((_sum$rb = sum[rb][ll - 1]) !== null && _sum$rb !== void 0 ? _sum$rb : 0) - ((_sum$rr = (_sum4 = sum[lt - 1]) === null || _sum4 === void 0 ? void 0 : _sum4[rr]) !== null && _sum$rr !== void 0 ? _sum$rr : 0) + ((_sum5 = (_sum6 = sum[lt - 1]) === null || _sum6 === void 0 ? void 0 : _sum6[ll - 1]) !== null && _sum5 !== void 0 ? _sum5 : 0) !== (rr - ll + 1) * (rb - lt + 1)) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\nfunction print(x) { process.stdout.write(x); }\r\n\r\nfunction ones_in_2x2(s, i, j) {\r\n let count = 0;\r\n for (let u = i, k = 0; k < 2; ++k, ++u)\r\n for (let v = j, l = 0; l < 2; ++l, ++v)\r\n if (s[u][v] == '1')\r\n ++count;\r\n return count; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) {\r\n const size = nextList();\r\n const n = size[0], p = n-1, q = size[1]-1; \r\n let s = Array(n);\r\n for (let i = 0; i < n; ++i)\r\n s[i] = next();\r\n let elegant = true;\r\n for (let i = 0; i < p && elegant; ++i)\r\n for (let j = 0; j < q && elegant; ++j)\r\n elegant = ones_in_2x2(s,i,j) != 3;\r\n console.log(elegant? \"YES\": \"NO\"); } }\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n "}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nE.s2a = (arr)=>arr.map(a=>a.split('').map(c=>c=='0' ? 0 : 1))\n\nlet di = [0, 0, -1, 1]\nlet dj = [-1, 1, 0, 0]\n\nconst dfs = E.dfs = (arr, i, j)=>{\n if (arr[i][j]!=1)\n return [];\n let n = arr.length;\n let m = arr[0].length;\n let members = [];\n let q = [[i, j]], qi = 0;\n while (qi=n || J>=m)\n continue;\n if (arr[I][J]==1)\n q.push([I, J])\n }\n }\n return members;\n};\n\nconst isFine = E.isFine = (members)=>{\n let minI = members[0][0]\n let maxI = members[0][0]\n let minJ = members[0][1]\n let maxJ = members[0][1]\n for (let [i, j] of members){\n minI = Math.min(minI, i);\n minJ = Math.min(minJ, j);\n maxI = Math.max(maxI, i);\n maxJ = Math.max(maxJ, j);\n }\n return (maxI-minI+1)*(maxJ-minJ+1)==members.length;\n};\n\nconst calc = (arr)=>{\n arr = E.s2a(arr);\n let n = arr.length;\n let m = arr[0].length;\n for (let i=0; i0 && !isFine(members))\n return false;\n }\n }\n return true\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [n, m] = ra();\n let arr = [];\n for (let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = Number(readline());\n for (let t = 0; t < testCases; t++) {\n const [m, n] = readline().split(\" \").map(Number);\n let board = [];\n\n for (let i = 0; i < m; i++) {\n let row = readline().split(\"\").map(Number);\n board.push(row);\n }\n\n let broken = false;\n for (let i = 0; i < m; i++) {\n if (broken) break;\n for (let j = 0; j < n; j++) {\n if (board[i][j] === 1) {\n if (i !== 0) {\n if (j !== 0) {\n // check top left\n if (\n board[i][j - 1] === 1 &&\n board[i - 1][j] === 1 &&\n board[i - 1][j - 1] === 0\n ) {\n broken = true;\n break;\n }\n }\n\n if (j !== n - 1) {\n // check top right\n if (\n board[i][j + 1] === 1 &&\n board[i - 1][j] === 1 &&\n board[i - 1][j + 1] === 0\n ) {\n broken = true;\n break;\n }\n }\n }\n\n if (i !== m - 1) {\n if (j !== 0) {\n // check bottom left\n if (\n board[i][j - 1] === 1 &&\n board[i + 1][j] === 1 &&\n board[i + 1][j - 1] === 0\n ) {\n broken = true;\n break;\n }\n }\n\n if (j !== n - 1) {\n // check bottom right\n if (\n board[i][j + 1] === 1 &&\n board[i + 1][j] === 1 &&\n board[i + 1][j + 1] === 0\n ) {\n broken = true;\n break;\n }\n }\n }\n }\n }\n }\n\n if (broken) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "function solve() {\r\n const [n, m] = readArray(Number);\r\n const matr = [];\r\n function get(x, y) {\r\n if (x < 0 || x >= n) {\r\n return '0';\r\n }\r\n if (y < 0 || y >= m) {\r\n return '0'\r\n }\r\n return matr[x][y];\r\n }\r\n for (let i = 0; i < n; i++) {\r\n matr.push(read().split(''));\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (get(i, j) === '0') {\r\n continue;\r\n }\r\n let i1 = i;\r\n while(get(i1, j) === '1') {\r\n i1++;\r\n }\r\n let j1 = j;\r\n while(get(i, j1) === '1') {\r\n j1++;\r\n }\r\n for (let x = i; x < i1; x++) {\r\n for (let y = j; y < j1; y++) {\r\n if (get(x, y) !== '1') {\r\n write('NO');\r\n return;\r\n }\r\n matr[x][y] = '0';\r\n }\r\n }\r\n for (let x = i; x < i1; x++) {\r\n if (get(x, j - 1) !== '0') {\r\n write('NO');\r\n return;\r\n }\r\n if (get(x, j1) !== '0') {\r\n write('NO');\r\n return;\r\n }\r\n }\r\n for (let y = j; y < j1; y++) {\r\n if (get(i - 1, y) !== '0') {\r\n write('NO');\r\n return;\r\n }\r\n if (get(i1, y) !== '0') {\r\n write('NO');\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "//const { readline, print } = require('@ip-algorithmics/codeforces-io');\n\nfunction isBlack (array) {\n return !array.some(row => row.some(n => n !== 1))\n}\n\nfunction isWhite (array) {\n return !array.some(row => row.some(n => n !== 0))\n}\n\nfunction expand (array, i, j) {\n if (i >= array.length || i < 0 || \n j < 0 || j >= array[0].length || array[i][j] !== 1) return;\n\n array[i][j] = 0;\n\n expand(array, i+1, j)\n expand(array, i-1, j)\n expand(array, i, j+1)\n expand(array, i, j-1)\n}\n\nvar line = readline().split(' ').map(x => parseInt(x))\nvar testCases = line[0]\n\nvar n, m\nwhile (testCases--) {\n line = readline().split(' ').map(x => parseInt(x))\n n = line[0]\n m = line[1]\n\n var array = new Array(n)\n \n for (var i = 0; i < n ; ++i) {\n array[i] = [];\n line = readline();\n\n for (var j = 0; j < line.length; ++j) {\n array[i].push(parseInt(line[j]));\n }\n }\n\n if (isBlack(array)) {\n print('YES')\n continue;\n }\n\n var elegantCount = 0;\n for (var i = 0; i < array.length; ++i) {\n for (var j = 0; j < array[i].length; ++j) {\n if (array[i][j] === 1) {\n expand(array, i, j);\n elegantCount++;\n }\n }\n }\n\n if (array.length=== 1 || array[0].length === 1) {\n print ('YES')\n } else\n print (elegantCount > 1 ? 'YES' : 'NO')\n}\n\n\n\n"}, {"source_code": "//const { readline, print } = require('@ip-algorithmics/codeforces-io');\n\nfunction isBlack (array) {\n return !array.some(row => row.some(n => n !== 1))\n}\n\nfunction expand (array, i, j) {\n if (i >= array.length || i < 0 || \n j < 0 || j >= array[0].length || array[i][j] !== 1) return;\n\n array[i][j] = 0;\n\n expand(array, i+1, j)\n expand(array, i-1, j)\n expand(array, i, j+1)\n expand(array, i, j-1)\n}\n\nvar line = readline().split(' ').map(x => parseInt(x))\nvar testCases = line[0]\n\nvar n, m\nwhile (testCases--) {\n line = readline().split(' ').map(x => parseInt(x))\n n = line[0]\n m = line[1]\n\n var array = new Array(n)\n \n for (var i = 0; i < n ; ++i) {\n array[i] = [];\n line = readline();\n\n for (var j = 0; j < line.length; ++j) {\n array[i].push(parseInt(line[j]));\n }\n }\n\n if (isBlack(array)) {\n print('YES')\n continue;\n }\n\n var elegantCount = 0;\n for (var i = 0; i < array.length; ++i) {\n for (var j = 0; j < array[i].length; ++j) {\n if (array[i][j] === 1) {\n expand(array, i, j);\n elegantCount++;\n }\n }\n }\n\n if (array.length=== 1 || array[0].length === 1) {\n print ('YES')\n } else\n print (elegantCount > 1 ? 'YES' : 'NO')\n}\n\n\n\n"}, {"source_code": "// const { readline, print } = require('@ip-algorithmics/codeforces-io');\n\nfunction expand (array, i, j) {\n if (i >= array.length || i < 0 || \n j < 0 || j >= array[0].length || array[i][j] !== 1) return;\n\n array[i][j] = 0;\n\n expand(array, i+1, j)\n expand(array, i-1, j)\n expand(array, i, j+1)\n expand(array, i, j-1)\n}\n\nvar line = readline().split(' ').map(x => parseInt(x))\nvar testCases = line[0]\n\nvar n, m\nwhile (testCases--) {\n line = readline().split(' ').map(x => parseInt(x))\n n = line[0]\n m = line[1]\n\n var array = new Array(n)\n \n for (var i = 0; i < n ; ++i) {\n array[i] = [];\n line = readline();\n\n for (var j = 0; j < line.length; ++j) {\n array[i].push(parseInt(line[j]));\n }\n }\n\n var elegantCount = 0;\n for (var i = 0; i < array.length; ++i) {\n for (var j = 0; j < array[i].length; ++j) {\n if (array[i][j] === 1) {\n expand(array, i, j);\n elegantCount++;\n }\n }\n }\n\n if (array.length=== 1 || array[0].length === 1) {\n print ('YES')\n } else\n print (elegantCount > 1 ? 'YES' : 'NO')\n}\n\n\n\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n,m;\r\n var mat;\r\n var visited;\r\n\r\n function checkSquare(i, j) {\r\n visited[i][j] = 1;\r\n var col = j;\r\n while (col < m && mat[i][col]) {\r\n col++;\r\n visited[i][col] = 1;\r\n }\r\n var width = col - j;\r\n \r\n var row = i+1;\r\n while (row < n && mat[row][j]) {\r\n col = j;\r\n while (col < j + width) {\r\n visited[row][col] = 1;\r\n if (!mat[row][col]) {\r\n return false;\r\n }\r\n col++;\r\n }\r\n visited[row][col] = 1;\r\n if (mat[row][col]) {\r\n return false;\r\n }\r\n row++;\r\n }\r\n if (row < n) {\r\n for (var c = j; c < j + width; c++) {\r\n visited[row][c] = 1;\r\n if (mat[row][c]) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n for (var t=0; t < tests; t++) {\r\n var nm = readline().split(' ').map(x=>parseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n visited = [];\r\n for (var i = 0; i < n; i++) {\r\n mat.push(readline().split('').map(x=>parseInt(x)));\r\n visited.push(new Array(m).fill(0));\r\n }\r\n\r\n var ans = 'YES';\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n if (visited[i][j]) {\r\n continue;\r\n }\r\n if (!mat[i][j]) {\r\n visited[i][j] = 1;\r\n continue;\r\n }\r\n if (checkSquare(i, j)) {\r\n continue;\r\n }\r\n ans = 'NO';\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1){\r\n if(j !==0 && arr[i+1][j] ==1 && arr[i+1][j-1] ==1 && arr[i][j-1] ==0 ){\r\n eleg= false;\r\n // console.log(i,j,\"1st\")\r\n break;\r\n }\r\n\r\n if(arr[i+1][j]==1 && arr[i+1][j+1] ==1 && arr[i][j+1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"2st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j]==1 && arr[i+1][j+1] ==0){\r\n eleg = false;\r\n // console.log(i,j,\"3st\")\r\n break;\r\n }\r\n\r\n if(i !== 0 && arr[i][j+1]==1 && arr[i-1][j] == 1 && arr[i-1][j-1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"4st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j+1] ==1 && arr[i+1][j]==0){\r\n eleg =false;\r\n // console.log(i,j,\"5st\")\r\n break;\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1){\r\n if(j !==0 && arr[i+1][j] ==1 && arr[i+1][j-1] ==1 && arr[i][j-1] ==0 ){\r\n eleg= false;\r\n // console.log(i,j,\"1st\")\r\n break;\r\n }\r\n\r\n if(arr[i+1][j]==1 && arr[i+1][j+1] ==1 && arr[i][j+1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"2st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j]==1 && arr[i+1][j+1] ==0){\r\n eleg = false;\r\n // console.log(i,j,\"3st\")\r\n break;\r\n }\r\n\r\n if(i !== 0 && arr[i][j+1]==1 && arr[i-1][j] == 1 && arr[i-1][j-1] == 0){\r\n eleg =false;\r\n // console.log(i,j,\"4st\")\r\n break;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j+1] ==1 && arr[i+1][j]==0){\r\n eleg =false;\r\n // console.log(i,j,\"5st\")\r\n break;\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1){\r\n if(j !==0 && arr[i+1][j] ==1 && arr[i+1][j-1] ==1 && arr[i][j-1] ==0 ){\r\n eleg= false;\r\n }\r\n\r\n if(arr[i+1][j]==1 && arr[i+1][j+1] ==1 && arr[i][j+1] == 0){\r\n eleg =false;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j]==1 && arr[i+1][j+1] ==0){\r\n eleg = false;\r\n }\r\n\r\n if(i !== 0 && arr[i][j+1]==1 && arr[i-1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false;\r\n }\r\n\r\n if(arr[i][j+1]==1 && arr[i+1][j+1] ==1 && arr[i+1][j]==0){\r\n eleg =false;\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if((arr[i+1][j] == 1 && arr[i+1][j+1] == 0 ) || (arr[i+1][j] == 0 && arr[i+1][j+1] == 1 ) ){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 && arr[i+1][j] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n\r\n if(i !==0 ){\r\n if((arr[i-1][j+1] ==1 && arr[i-1][j]==0) || (arr[i-1][j+1] ==0 && arr[i-1][j]==1)){\r\n eleg =false;\r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if((arr[i+1][j] == 1 && arr[i+1][j+1] == 0 ) || (arr[i+1][j] == 0 && arr[i+1][j+1] == 1 ) ){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 && arr[i+1][j] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n // for (var k = 0; k < arr.length; k++) {\r\n // if(arr[k].indexOf(1) == -1 ){\r\n // count++;\r\n // }\r\n // }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n // if(count == arr.length*arr[0].length ){\r\n // eleg = false;\r\n // }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n for (var k = 0; k < arr.length; k++) {\r\n if(arr[k].indexOf(1) == -1 ){\r\n count++;\r\n }\r\n }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n if(count == arr.length*arr[0].length ){\r\n eleg = false;\r\n }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n for (var k = 0; k < arr.length; k++) {\r\n if(arr[k].indexOf(1) == -1 ){\r\n count++;\r\n }\r\n }\r\n\r\n\r\n for (var i = 0; i < arr.length-1; i++) {\r\n\r\n \r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n \r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n if(count == arr.length){\r\n eleg = false;\r\n }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n let count =0;\r\n for (var i = 0; i < arr.length-1; i++) {\r\n \r\n for (var j = 0; j < arr[0].length-1; j++) {\r\n\r\n if(arr[i][j] == 0 && arr[i][j+1]==0 ){\r\n if(arr[i+1][j] == 0 && arr[i+1][j+1] == 0){\r\n count++; \r\n }\r\n }\r\n\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n let tot = Math.floor(((arr.length * arr[0].length)-1)/2);\r\n //console.log(count,tot)\r\n if(count == tot){\r\n eleg =false;\r\n }\r\n\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n for (var i = 0; i < arr.length-1; i++) {\r\n \r\n for (var j = 0; j < arr[0].length; j++) {\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n\r\n if( j !==0){\r\n if(arr[i][j-1] == 0 && arr[i+1][j-1] ==1 ){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline());\r\n let c= 0;\r\n while(cparseInt(a));\r\n let m0 = m[0];\r\n let countRow = 0 ;\r\n let arr =[];\r\n while(countRow < m0){\r\n let row = readline().split(\"\").map(b=>parseInt(b));\r\n arr.push(row);\r\n countRow++;\r\n }\r\n \r\n\r\n let eleg =true;\r\n for (var i = 0; i < arr.length-1; i++) {\r\n \r\n for (var j = 0; j < arr[0].length; j++) {\r\n if(arr[i][j] ==1 && arr[i][j+1] ==1){\r\n if(arr[i+1][j] == 1 && arr[i+1][j+1] == 0){\r\n eleg =false; \r\n }\r\n }\r\n }\r\n \r\n\r\n }\r\n if(eleg){\r\n console.log(\"yes\");\r\n }else{\r\n console.log(\"no\");\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++;\r\n } \r\n \r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++)\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur))\r\n );\r\n if (n === 1) {\r\n let ans = false;\r\n for (let i = 0; i < m; i++) {\r\n if (arr[0][i] === 1) {\r\n ans = true;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n continue;\r\n }\r\n if (m === 1) {\r\n let ans = false;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i][0] === 1) {\r\n ans = true;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n continue;\r\n }\r\n const ne = (r, c, n, m) => {\r\n let arr1 = [];\r\n if (r !== n - 1 && arr[r + 1][c] === 1) arr1.push([r + 1, c]);\r\n if (r !== 0 && arr[r - 1][c] === 1) arr1.push([r - 1, c]);\r\n if (c !== 0 && arr[r][c - 1] === 1) arr1.push([r, c - 1]);\r\n if (c !== m - 1 && arr[r][c + 1] === 1) arr1.push([r, c + 1]);\r\n return arr1;\r\n };\r\n const dfs = (row, col, m, n) => {\r\n let obj = {};\r\n const helper = (row, col) => {\r\n arr[row][col] = 0;\r\n obj[[row, col]] = 1;\r\n let neigh = ne(row, col, n, m);\r\n for (let i of neigh) if (!obj[(i[0], i[1])]) helper(i[0], i[1]);\r\n };\r\n helper(row, col);\r\n };\r\n let ist = false,\r\n ans = false;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (arr[i][j] === 1) {\r\n if (ist) {\r\n ans = true;\r\n break;\r\n }\r\n dfs(i, j, m, n);\r\n ist = true;\r\n }\r\n }\r\n if (ans) break;\r\n }\r\n if (ans && ist) console.log(\"YES\");\r\n else if (ist) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++)\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur))\r\n );\r\n if (n === 1) {\r\n let ans = false;\r\n for (let i = 0; i < m; i++) {\r\n if (arr[0][i] === 1) {\r\n ans = true;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n continue;\r\n }\r\n const ne = (r, c, n, m) => {\r\n let arr1 = [];\r\n if (r !== n - 1 && arr[r + 1][c] === 1) arr1.push([r + 1, c]);\r\n if (r !== 0 && arr[r - 1][c] === 1) arr1.push([r - 1, c]);\r\n if (c !== 0 && arr[r][c - 1] === 1) arr1.push([r, c - 1]);\r\n if (c !== m - 1 && arr[r][c + 1] === 1) arr1.push([r, c + 1]);\r\n return arr1;\r\n };\r\n const dfs = (row, col, m, n) => {\r\n let obj = {};\r\n const helper = (row, col) => {\r\n arr[row][col] = 0;\r\n obj[[row, col]] = 1;\r\n let neigh = ne(row, col, n, m);\r\n for (let i of neigh) if (!obj[(i[0], i[1])]) helper(i[0], i[1]);\r\n };\r\n helper(row, col);\r\n };\r\n let ist = false,\r\n ans = false;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (arr[i][j] === 1) {\r\n if (ist) {\r\n ans = true;\r\n break;\r\n }\r\n dfs(i, j, m, n);\r\n ist = true;\r\n }\r\n }\r\n if (ans) break;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, s) {\r\n const sum = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n var _sum$j, _sum, _sum$i, _sum2, _sum3;\r\n sum[i][j] = ((_sum$j = (_sum = sum[i - 1]) === null || _sum === void 0 ? void 0 : _sum[j]) !== null && _sum$j !== void 0 ? _sum$j : 0) + ((_sum$i = sum[i][j - 1]) !== null && _sum$i !== void 0 ? _sum$i : 0) - ((_sum2 = (_sum3 = sum[i - 1]) === null || _sum3 === void 0 ? void 0 : _sum3[j - 1]) !== null && _sum2 !== void 0 ? _sum2 : 0) + Number(s[i][j]);\r\n }\r\n }\r\n const p = [...new Array(n * m).keys()];\r\n const find = i => {\r\n if (p[i] !== i) p[i] = find(p[p[i]]);\r\n return p[i];\r\n };\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const dirs = [[0, 1], [1, 0]];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n const a = i * m + j;\r\n if (s[i][j] === '0') {\r\n p[a] = -1;\r\n continue;\r\n }\r\n for (let [di, dj] of dirs) {\r\n const ni = di + i,\r\n nj = dj + j,\r\n b = ni * m + nj;\r\n if (ni < 0 || ni >= n || nj < 0 || nj >= m || s[ni][nj] === '0') continue;\r\n union(a, b);\r\n }\r\n }\r\n }\r\n const scc = new Map();\r\n for (let [i, num] of p.entries()) {\r\n if (num === -1) continue;\r\n const root = find(num);\r\n if (!scc.has(root)) scc.set(root, []);\r\n scc.get(root).push(i);\r\n }\r\n for (let [, points] of scc) {\r\n var _sum$rb, _sum$rr, _sum4, _sum5, _sum6;\r\n let ll = Infinity,\r\n lt = Infinity,\r\n rr = -Infinity,\r\n rb = -Infinity;\r\n for (let num of points) {\r\n const i = Math.floor(num / m),\r\n j = num % m;\r\n ll = Math.min(ll, i);\r\n lt = Math.min(lt, j);\r\n rr = Math.max(rr, j);\r\n rb = Math.max(rb, i);\r\n }\r\n if (sum[rb][rr] - ((_sum$rb = sum[rb][ll - 1]) !== null && _sum$rb !== void 0 ? _sum$rb : 0) - ((_sum$rr = (_sum4 = sum[lt - 1]) === null || _sum4 === void 0 ? void 0 : _sum4[rr]) !== null && _sum$rr !== void 0 ? _sum$rr : 0) + ((_sum5 = (_sum6 = sum[lt - 1]) === null || _sum6 === void 0 ? void 0 : _sum6[ll - 1]) !== null && _sum5 !== void 0 ? _sum5 : 0) !== (rr - ll + 1) * (rb - lt + 1)) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "b44d59eded2cb3a65686dc7fd07d21b7"} {"source_code": "print(function(a, b) {\n\tfor (var x = 1; x <= 1000; x++) {\n\t\tvar y = Math.sqrt(a * a - x * x);\n\t\tif (y % 1 === 0 && y > 0) {\n\t\t\tvar y2 = x * b / a;\n\t\t\tvar x2 = y * b / a;\n\t\t\tif (x2 % 1 === 0 && y2 % 1 === 0 && y !== y2) {\n\t\t\t\treturn 'YES\\n0 0\\n' + x + ' ' + y + '\\n' + (-x2) + ' ' + y2\n\t\t\t}\n\t\t}\n\t}\n\n\treturn 'NO';\n\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\ta = data[0], b = data[1],\n\t\ta2 = a*a;\n\tfor (var y = 1; y*y < a2; ++y) {\n\t\tvar x = Math.sqrt(a2 - y*y);\n\t\tif (x == Math.floor(x)) {\n\t\t\tif ((b*y)%a == 0 && (b*x)%a == 0 && x != b*y/a) {\n\t\t\t\tprint('YES');\n\t\t\t\tprint(0, 0);\n\t\t\t\tprint(x, y);\n\t\t\t\tprint(b*y/a, b*-x/a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tprint('NO');\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(a, b) {\n\tfor (var x = 1; x <= 1000; x++) {\n\t\tvar y = Math.sqrt(a * a - x * x);\n\t\tif (y % 1 === 0) {\n\t\t\tvar y2 = x * b / a;\n\t\t\tvar x2 = y * b / a;\n\t\t\tif (x2 % 1 === 0 && y2 % 1 === 0 && y !== y2) {\n\t\t\t\treturn 'YES\\n0 0\\n' + x + ' ' + y + '\\n' + (-x2) + ' ' + y2\n\t\t\t}\n\t\t}\n\t}\n\n\treturn 'NO';\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\ta = data[0], b = data[1],\n\t\ta2 = a*a;\n\tfor (var y = 1; 2*y*y <= a2; ++y) {\n\t\tvar x = Math.sqrt(a2 - y*y);\n\t\tif (x == Math.floor(x)) {\n\t\t\tif ((b*y)%a == 0 && (b*x)%a == 0 && x != b*y/a) {\n\t\t\t\tprint('YES');\n\t\t\t\tprint(0, 0);\n\t\t\t\tprint(x, y);\n\t\t\t\tprint(b*y/a, b*-x/a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tprint('NO');\n}\n\nmain();\n"}], "src_uid": "a949ccae523731f601108d4fa919c112"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n for (let len = n - 1; len > 0; len--) {\r\n const b = [];\r\n for (let i = 0; i < a.length - 1; i++) {\r\n const num = a[i + 1] - a[i];\r\n if (num) b.push(num);\r\n }\r\n if (b.length < len) b.push(0);\r\n a = b.sort((a, b) => a - b);\r\n }\r\n return a[0];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar n = readInt();\r\n\t\tvar a = readIntArr();\r\n\t\tvar b;\r\n\t\t\r\n\t\t// there won't be too many moves before most/everyone becomes 0\r\n\t\tvar ans = 0;\r\n\t\tvar zerocnt = 0;\r\n\t\twhile (a.length > 1) {\r\n\t\t\ta.sort((x, y) => (y - x)); // sort descending\r\n\t\t\twhile (a.length > 1 && a[a.length - 1] === 0) {\r\n\t\t\t\tzerocnt++;\r\n\t\t\t\ta.pop();\r\n\t\t\t}\r\n\t\t\tif (zerocnt > 0 && a.length > 0 && a[a.length - 1] !== 0) {\r\n\t\t\t\ta.push(0);\r\n\t\t\t\tzerocnt--;\r\n\t\t\t}\r\n\t\t\tb = [];\r\n\t\t\tfor (var i = 1; i < a.length; i++)\r\n\t\t\t\tb.push(a[i - 1] - a[i]);\r\n\t\t\ta = b;\r\n\t\t}\r\n\t\tif (a.length === 1)\r\n\t\t\tans = a[0];\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [], "src_uid": "499b1440d8bb528d089724910e37e226"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (a)=>{\n let n = a.length;\n if (n === 1) return 1;\n\n let result = 1;\n let pos1 = 0;\n let pos0 = n - 1;\n\n for (let i = 0; i < n; i++) {\n if (a[i] === '0') {\n pos0 = i;\n break;\n }\n }\n\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] === '1') {\n pos1 = i;\n break;\n }\n }\n\n if (pos0 < pos1) return n;\n return pos0 - pos1 + 1;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n // let n = +readline();\n // let a = ra();\n let a = readline().split('');\n console.log(`${calc(a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n if (s.length === 1) {\r\n console.log(1);\r\n return;\r\n }\r\n const n = s.length;\r\n let l = 0,\r\n r = n - 1;\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] === '1') {\r\n l = i;\r\n }\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (s[i] === '0') {\r\n r = i;\r\n }\r\n }\r\n if (r < l) {\r\n console.log(1);\r\n return;\r\n }\r\n console.log(r - l + 1);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n solve(s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n const s = readline();\r\n const l = s.lastIndexOf('1');\r\n const f = s.indexOf('0'); \r\n var n = s.length;\r\n if (n === 1) {\r\n console.log(1);\r\n } else if (s[0] === '0') {\r\n console.log(1);\r\n } else\r\n if (s[n - 1] === '1') {\r\n console.log(1);\r\n } else\r\n if (l === -1 && f === -1) {\r\n console.log(n);\r\n } else\r\n if (l === -1) {\r\n console.log(f + 1);\r\n } else\r\n if (f === -1) {\r\n console.log(n - l);\r\n } else {\r\n console.log(f - l + 1); \r\n }\r\n \r\n }\r\n}"}, {"source_code": "const solve = (str)=>{\r\n let yes = 0;\r\n for(let i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n // no 1 after, no 0 before\n const one = []\n const zero = []\n for (let i = 0; i < str.length; i++) {\n let now = 0\n if (str[i] === '0') now = 1\n zero[i] = i ? zero[i - 1] + now : now\n }\n for (let i = str.length - 1; i >= 0; i--) {\n let now = 0\n if (str[i] === '1') now = 1\n one[i] = i < str.length - 1 ? one[i + 1] + now : now\n }\n let ans = 0\n for (let i = 0; i < str.length; i++) {\n if (!zero[i - 1] && !one[i + 1]) ans++\n }\n return ans\n}\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let s = readline();\n let n = s.length;\n LT({n, s});\n // PROCESSING:\n let ones = [];\n let zeros = [];\n for (let i=0; i=1 ? ones[ones.length-1] : 0;\n let to = zeros.length>=1 ? zeros[0] : n-1;\n return to-from+1;\n};\n "}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n if (s.length === 1) {\r\n console.log(1);\r\n return;\r\n }\r\n const n = s.length;\r\n let cache = new Map();\r\n const check = i => {\r\n if (cache.has(i)) return cache.get(i);\r\n if (i < 0) {\r\n cache.set(i, true);\r\n } else if (s[i] === '1') {\r\n cache.set(i, check(i - 1));\r\n } else if (s[i] === '?') {\r\n cache.set(i, check(i - 1));\r\n } else {\r\n cache.set(i, false);\r\n }\r\n return cache.get(i);\r\n };\r\n let res = new Set();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (check(i - 1)) res.add(i);\r\n if (s[i] === '1') break;\r\n }\r\n console.log(res.size);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n solve(s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n if (s.length === 1) {\r\n console.log(1);\r\n return;\r\n }\r\n const n = s.length;\r\n let cache = new Map();\r\n const check = i => {\r\n if (cache.has(i)) return cache.get(i);\r\n if (i < 0) {\r\n cache.set(i, true);\r\n } else if (s[i] === '1') {\r\n cache.set(i, true);\r\n } else if (s[i] === '?') {\r\n cache.set(i, check(i - 1));\r\n } else {\r\n cache.set(i, false);\r\n }\r\n return cache.get(i);\r\n };\r\n let res = new Set();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (check(i - 1)) res.add(i);\r\n if (s[i] === '1') break;\r\n }\r\n console.log(res.size);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n solve(s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n console.log(s);\r\n if (s.length === 1) {\r\n console.log(1);\r\n return;\r\n }\r\n const n = s.length;\r\n let cache = new Map();\r\n const check = i => {\r\n if (cache.has(i)) return cache.get(i);\r\n if (i < 0) {\r\n cache.set(i, true);\r\n } else if (s[i] === '1') {\r\n cache.set(i, true);\r\n } else if (s[i] === '?') {\r\n cache.set(i, check(i - 1));\r\n } else {\r\n cache.set(i, false);\r\n }\r\n return cache.get(i);\r\n };\r\n let res = new Set();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (check(i - 1)) {\r\n res.add(i);\r\n }\r\n if (s[i] === '1') {\r\n break;\r\n }\r\n }\r\n console.log(res.size);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n solve(s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "0c9f2301629726870a0ab57299773fd6"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet n, m;\nconst cells = [];\nlet numberOfGoodCell = 0;\n\n// listCount = new Array(1001).fill(0);\nfunction solve() {\n\n}\n\nfunction check() {\n for (let i = 0; i < cells.length; i++) {\n for (let j = 0; j < cells[i].length; j++) {\n if ((cells[i][j] !== '.' || cells[i][j] !== '-') && !checkCellAdjustable(i, j, cells[i][j])) {\n return false;\n }\n }\n }\n return true;\n}\n\nfunction checkCellAdjustable(i, j, char) {\n return !(cells[i][j + 1] === char || cells[i][j - 1] === char || cells[i + 1][j] === char || cells[i - 1][j] === char);\n}\n\nrl.on('line', (line) => {\n if (!n && !m) {\n [n, m] = line.split(' ').map(Number);\n return;\n }\n const list = line.split('');\n cells.push(list);\n if (cells.length === n) {\n let charI = 'B';\n for (let i = 0; i < cells.length; i++) {\n let charJ = charI;\n let output = '';\n for (let j = 0; j < cells[i].length; j++) {\n if (cells[i][j] === '.') {\n cells[i][j] = charJ;\n }\n if (charJ === 'B') {\n charJ = 'W';\n } else {\n charJ = 'B';\n }\n output += cells[i][j];\n }\n console.log(output);\n\n if (charI === 'B') {\n charI = 'W';\n } else {\n charI = 'B';\n }\n }\n }\n});\n", "positive_code": [{"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var a, i, j, l, line, m, n, o, ref, ref1, ref2, results;\n\n ref = readline().split(' '), n = ref[0], m = ref[1];\n\n a = [];\n\n for (i = j = 0, ref1 = n; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {\n a.push(readline());\n }\n\n for (i = l = 0, ref2 = n; 0 <= ref2 ? l < ref2 : l > ref2; i = 0 <= ref2 ? ++l : --l) {\n line = (function() {\n results = [];\n for (var o = 0; 0 <= m ? o < m : o > m; 0 <= m ? o++ : o--){ results.push(o); }\n return results;\n }).apply(this).map(function(k) {\n if (a[i][k] === '-') {\n return '-';\n } else if ((i + k) % 2 === 0) {\n return 'B';\n } else {\n return 'W';\n }\n });\n print(line.join(''));\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var j, m, n, ref, results;\n\n print(((ref = readline().split(' '), n = ref[0], m = ref[1], ref), (function() {\n results = [];\n for (var j = 0; 0 <= n ? j < n : j > n; 0 <= n ? j++ : j--){ results.push(j); }\n return results;\n }).apply(this).map(function(i) {\n var a, j, results;\n a = readline();\n return (function() {\n results = [];\n for (var j = 0; 0 <= m ? j < m : j > m; 0 <= m ? j++ : j--){ results.push(j); }\n return results;\n }).apply(this).map(function(k) {\n if (a[k] === '-') {\n return '-';\n } else if ((i + k) % 2 === 0) {\n return 'B';\n } else {\n return 'W';\n }\n });\n })).join('\\n').split(',').join(''));\n\n}).call(this);\n"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return +readline(); }\n\nfunction go(i, j){\n if(ans[i-1] != undefined && ans[i-1][j] == 0){\n if(ans[i][j] == \"B\"){\n ans[i-1][j] = \"W\";\n }else{\n ans[i-1][j] = \"B\";\n }\n go(i-1, j);\n }\n if(ans[i+1] != undefined && ans[i+1][j] == 0){\n if(ans[i][j] == \"B\"){\n ans[i+1][j] = \"W\";\n }else{\n ans[i+1][j] = \"B\";\n }\n go(i+1, j);\n }\n if(ans[i][j-1] == 0){\n if(ans[i][j] == \"B\"){\n ans[i][j-1] = \"W\";\n }else {\n ans[i][j - 1] = \"B\";\n }\n go(i, j-1);\n }\n if(ans[i][j+1] == 0){\n if(ans[i][j] == \"B\"){\n ans[i][j+1] = \"W\";\n }else{\n ans[i][j+1] = \"B\";\n }\n go(i, j+1);\n }\n}\n\nvar inp = rda(), n = inp[0], m = inp[1];\ninp = [];\nfor(var i = 0; i < n; i++){\n inp.push(readline().split(\"\"));\n}\nvar ans = [];\nfor(var i = 0; i < n; i++){\n ans[i] = [];\n for(var j = 0; j < m; j++){\n ans[i][j] = 0;\n }\n}\n\nfor(var i = 0; i < n; i++){\n for(var j = 0; j < m; j++){\n if(inp[i][j] == \"-\"){\n ans[i][j] = \"-\";\n }else{\n if(ans[i][j] == 0){\n ans[i][j] = \"B\";\n go(i, j);\n }\n }\n }\n}\n\nfor(var i = 0; i < n; i++){\n write(ans[i].join(\"\") + \"\\n\");\n}"}, {"source_code": "var o = {B: 'W', W: 'B'};\n\n;(function () {\n\tprint(function (n, m) {\n\t\tvar a = [], flag = true;\n\t\tfor (var i = 0; i < n; i++)\n\t\t\ta.push(readline().replace(/\\./g, 'B'));\n\n\t\twhile (flag) {\n\t\t\tflag = false;\n\n\t\t\tfor (var i = 0; i < n; i++)\n\t\t\t\tfor (var j = 0; j < m; j++)\n\t\t\t\t\tif (a[i][j] !== '-' && (\n\t\t\t\t\t\t(i > 0 && a[i-1][j] === a[i][j]) ||\n\t\t\t\t\t\t(i < n-1 && a[i+1][j] === a[i][j]) ||\n\t\t\t\t\t\t(j > 0 && a[i][j-1] === a[i][j]) ||\n\t\t\t\t\t\t(j < m-1 && a[i][j+1] === a[i][j])\n\t\t\t\t\t)) {\n\t\t\t\t\t\ta[i] = a[i].split('');\n\t\t\t\t\t\ta[i][j] = o[a[i][j]];\n\t\t\t\t\t\ta[i] = a[i].join('');\n\t\t\t\t\t\tflag = true;\n\t\t\t\t\t}\n\t\t}\n\n\t\treturn a.join('\\n');\n\t}.apply(null, readline().split(' ').map(Number)));\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\trowNum = data[0], colNum = data[1],\n\t\trows = [];\n\tfor (var r = 0; r < rowNum; ++r) {\n\t\tvar line = trim(readline()),\n\t\t\tchars = new Array(colNum);\n\t\tfor (var c = 0; c < colNum; ++c) {\n\t\t\tif (line.charAt(c) == '.') {\n\t\t\t\tchars.push((r+c)%2 == 0 ? 'W' : 'B');\n\t\t\t} else {\n\t\t\t\tchars.push('-');\n\t\t\t}\n\t\t}\n\t\trows.push(chars.join(''));\n\t}\n\tprint(rows.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "{\n var num = readline(), arr = [];\n num = num.split(' ');\n for (var i = 1; i <= +num[0]; i++)\n {\n var input = readline();\n arr.push(input.split(''));\n }\n var result = function(arr)\n {\n for (var i = 0; i <= arr.length - 1; i++)\n {\n for (var count = 0; count <= arr[i].length - 1; count++)\n {\n if ( i % 2 === 0) \n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'B');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'W');\n }\n else\n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'W');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'B');\n }\n }\n }\n return arr;\n }\n var x = result(arr);\n\tfor (var count = 0; count <= x.length - 1; count++)\n\t{\n\t\tprint(x[count].join(''));\n\t}\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const [r, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const board = [];\n const result = [...Array(r).fill(0)].map((_) => Array(c).fill(0));\n\n for (let i = 0; i < r; i++) {\n const _row = readLine().split(\"\");\n board.push(_row);\n }\n\n for (let row = 0; row < r; row++) {\n for (let col = 0; col < c; col++) {\n if (board[row][col] === \".\") {\n if (row % 2 === 0) {\n if (col % 2 === 0) result[row][col] = \"W\";\n else result[row][col] = \"B\";\n } else {\n if (col % 2 !== 0) result[row][col] = \"W\";\n else result[row][col] = \"B\";\n }\n } else {\n result[row][col] = board[row][col];\n }\n }\n }\n\n for (let row = 0; row < r; row++) {\n console.log(result[row].join(\"\"));\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet brd = [];\n\tfor (let i = 0; i < n; i++) {\n\t\tbrd[i] = readLine().split('');\n\t}\n\n\tfor (let i = 0; i < n; i++) {\n\t\tfor (let j = 0; j < m; j++) {\n\t\t\tlet ci = i + j;\n\t\t\tif (brd[i][j] !== '-') {\n\t\t\t\tif (ci & 1) {\n\t\t\t\t\tbrd[i][j] = 'W';\n\t\t\t\t} else {\n\t\t\t\t\tbrd[i][j] = 'B';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (let i = 0; i < n; i++) {\n\t\tconsole.log(brd[i].join(''));\n\t}\n}\n"}], "negative_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return +readline(); }\n\nfunction go(i, j){\n if(ans[i-1] != undefined && ans[i-1][j] == 0){\n if(ans[i][j] == \"B\"){\n ans[i-1][j] = \"W\";\n }else{\n ans[i-1][j] = \"B\";\n }\n go(i-1, j);\n }\n if(ans[i+1] != undefined && ans[i+1][j] == 0){\n if(ans[i][j] == \"B\"){\n ans[i+1][j] = \"W\";\n }else{\n ans[i+1][j] = \"B\";\n }\n go(i+1, j);\n }\n if(ans[i][j-1] == 0){\n if(ans[i][j] == \"B\"){\n ans[i][j-1] = \"W\";\n }else {\n ans[i][j - 1] = \"B\";\n }\n go(i, j-1);\n }\n if(ans[i][j+1] == 0){\n if(ans[i][j] == \"B\"){\n ans[i][j+1] = \"W\";\n }else{\n ans[i][j+1] = \"B\";\n }\n go(i, j+1);\n }\n}\n\nvar inp = rda(), n = inp[0], m = inp[1];\ninp = [];\nfor(var i = 0; i < n; i++){\n inp.push(readline().split(\"\"));\n}\nvar ans = [];\nfor(var i = 0; i < n; i++){\n ans[i] = [];\n for(var j = 0; j < n; j++){\n ans[i][j] = 0;\n }\n}\n\nfor(var i = 0; i < n; i++){\n for(var j = 0; j < m; j++){\n if(inp[i][j] == \"-\"){\n ans[i][j] = \"-\";\n }else{\n if(ans[i][j] == 0){\n ans[i][j] = \"B\";\n go(i, j);\n }\n }\n }\n}\n\nfor(var i = 0; i < n; i++){\n write(ans[i].join(\"\") + \"\\n\");\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet n, m;\nconst cells = [];\nlet numberOfGoodCell = 0;\n\n// listCount = new Array(1001).fill(0);\nfunction solve() {\n\n}\n\nfunction check() {\n for (let i = 0; i < cells.length; i++) {\n for (let j = 0; j < cells[i].length; j++) {\n if ((cells[i][j] !== '.' || cells[i][j] !== '-') && !checkCellAdjustable(i, j, cells[i][j])) {\n return false;\n }\n }\n }\n return true;\n}\n\nfunction checkCellAdjustable(i, j, char) {\n return !(cells[i][j + 1] === char || cells[i][j - 1] === char || cells[i + 1][j] === char || cells[i - 1][j] === char);\n}\n\nrl.on('line', (line) => {\n if (!n && !m) {\n [n, m] = line.split(' ').map(Number);\n return;\n }\n const list = line.split('');\n cells.push(list);\n if (cells.length === n) {\n let charI = 'B';\n for (let i = 0; i < cells.length; i++) {\n let charJ = charI;\n let output = '';\n for (let j = 0; j < cells[i].length; j++) {\n if (cells[i][j] === '.') {\n cells[i][j] = charJ;\n }\n if (charJ === 'B') {\n charJ = 'A';\n } else {\n charJ = 'B';\n }\n output += cells[i][j];\n }\n console.log(output);\n\n if (charI === 'B') {\n charI = 'A';\n } else {\n charI = 'B';\n }\n }\n }\n});\n"}, {"source_code": "{\n var num = readline(), arr = [];\n num = num.split(' ');\n for (var i = 1; i <= +num[0]; i++)\n {\n var input = readline();\n arr.push(input.split(''));\n }\n var result = function(arr)\n {\n for (var i = 0; i <= arr.length - 1; i++)\n {\n for (var count = 0; count <= arr[i].length - 1; count++)\n {\n if ( i % 2 === 0) \n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'B');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'W');\n }\n else\n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'W');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'B');\n }\n }\n }\n return arr;\n }\n print(result(arr));\n}"}, {"source_code": "{\n var num = readline(), arr = [];\n num = num.split(' ');\n for (var i = 1; i <= +num[0]; i++)\n {\n var input = readline();\n arr.push(input.split(''));\n }\n var result = function(arr)\n {\n for (var i = 0; i <= arr.length - 1; i++)\n {\n for (var count = 0; count <= arr[i].length - 1; count++)\n {\n if ( i % 2 === 0) \n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'B');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'W');\n }\n else\n {\n if ( (arr[i][count] === '.') && (count % 2 === 0) )\n {\n arr[i].splice(count, 1, 'W');\n }\n else if (arr[i][count] === '.') arr[i].splice(count, 1, 'B');\n }\n }\n }\n return arr;\n }\n var x = result(arr);\n\tfor (var count = 0; count <= x.length - 1; count++)\n\t{\n\t\tprint(x[count]);\n\t}\n}"}], "src_uid": "dc31adef80f06897ea2f5ef76854bcf1"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n \r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n \r\nconst isPrime = num => {\r\n\tfor(let i = 2, s = Math.sqrt(num); i <= s; i++)\r\n\t\tif(num % i === 0) return false; \r\n\treturn num > 1;\r\n}\r\n \r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, e] = rna();\r\n\t\tlet a = rna();\r\n \r\n\t\tlet l = [], r = [];\r\n\t\tfor (let i = 0; i < e; i++) {\r\n\t\t\tfor (let j = i, cnt = 0; j < n; j += e) {\r\n\t\t\t\tif (a[j] == 1) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tl[j] = cnt;\r\n\t\t\t\t\tcnt = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (let j = n - i - 1, cnt = 0; j >= 0; j -= e) {\r\n\t\t\t\tif (a[j] == 1) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tr[j] = cnt;\r\n\t\t\t\t\tcnt = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (isPrime(a[i])) {\r\n\t\t\t\tans += (l[i] + 1)*(r[i] + 1) - 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}", "positive_code": [{"source_code": "var isPrime = [];\r\nfor(var i=0; i<1000002; i++){\r\n isPrime.push(1);\r\n}\r\n \r\nfunction complex_market_analysis(){\r\n \r\n var inp = readline().split(\" \");\r\n\tvar n = parseInt(inp[0]);\r\n\tvar e = parseInt(inp[1]);\r\n\tvar a = readline().split(\" \").map(x=>parseInt(x));\r\n \r\n\tvar w=[];\r\n\tfor(var i=0; i 1){\r\n\t\t\t\t last1 = last;\r\n\t\t\t\t\tlast = j;\r\n\t\t\t\t\tp = isPrime[v];\r\n\t\t\t\t\tif (p){\r\n\t\t\t\t\t\tr -= 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (p){\r\n\t\t\t\t\tr += (last - last1)\r\n\t\t\t\t}\r\n\t\t\t\tz += e\r\n\t\t\t\tj += 1\r\n\t\t\t}\r\n\t\t\t}\r\n \r\n\t}\r\n\tprint(r);\t\t\r\n}\r\n \r\nfunction prime_pairs(){\r\n\tvar M = isPrime.length;\r\n\tisPrime[1] = 0;\r\n\tisPrime[0] = 0;\r\n\tvar i = 2;\r\n\twhile (i * i < M){\r\n\t\tif (isPrime[i]){\r\n\t\t\tvar j = i * i;\r\n\t\t\twhile (j < M){\r\n\t\t\t\tisPrime[j] = 0;\r\n\t\t\t\tj += i;\r\n\t\t\t}\r\n\t\t}\r\n\t\ti += 1\r\n\t}\r\nvar t = parseInt(readline());\r\nfor (var i=0; i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n} \r\n\r\nfunction main() {\r\n var t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n}\r\n \r\nfunction solution() {\r\n let inputLine = readline().split(\" \");\r\n let n = +inputLine[0];\r\n let e = +inputLine[1];\r\n \r\n let array = [], dp = new Array(n).fill(0);\r\n \r\n let arrayLine = readline().split(\" \");\r\n for (let i = 0; i < n; i++) \r\n array[i] = +arrayLine[i];\r\n\r\n for (let i = n-1; i >= 0; i--) {\r\n if (isPrime(array[i])) {\r\n let k = 1;\r\n while(i + k*e < n && array[i + k*e] === 1) \r\n k++;\r\n dp[i] = k-1;\r\n }\r\n else if (array[i] === 1 && i + e < n) {\r\n if (isPrime(array[i + e])) dp[i] = dp[i + e]+1; \r\n else if (array[i + e] === 1) dp[i] = dp[i + e];\r\n }\r\n }\r\n\r\n const sum = dp.reduce(function(total, item) {\r\n return total+item;\r\n });\r\n\r\n console.log(sum);\r\n}\r\n \r\nfunction isPrime(num) {\r\n if (num === 2) return true;\r\n if (num === 1 || num%2 === 0 ) return false;\r\n \r\n let root = Math.floor(Math.sqrt(num));\r\n root += (root%2)-1;\r\n while (root > 1) {\r\n if (num%root === 0)\r\n return false;\r\n root -= 2;\r\n }\r\n return true;\r\n}\r\n"}, {"source_code": "\"use strict\"; \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n} \r\n\r\nfunction main() {\r\n var t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n}\r\n \r\nfunction solution() {\r\n let inputLine = readline().split(\" \");\r\n let n = +inputLine[0];\r\n let e = +inputLine[1];\r\n \r\n let array = [], dp = new Array(n).fill(0);\r\n \r\n let arrayLine = readline().split(\" \");\r\n for (let i = 0; i < n; i++) \r\n array[i] = +arrayLine[i];\r\n\r\n for (let i = n-1; i >= 0; i--) {\r\n let k = 1;\r\n if (isPrime(array[i])) {\r\n while(i + k*e < n && array[i + k*e] === 1) \r\n k++;\r\n dp[i] = k-1;\r\n }\r\n else if (array[i] === 1 && i + k*e < n) {\r\n if (isPrime(array[i + k*e])) dp[i] = dp[i + k*e]+1; \r\n else if (array[i + k*e] === 1) dp[i] = dp[i + k*e];\r\n }\r\n }\r\n\r\n const sum = dp.reduce(function(total, item) {\r\n return total+item;\r\n });\r\n\r\n console.log(sum);\r\n}\r\n \r\nfunction isPrime(num) {\r\n if (num === 2) return true;\r\n if (num === 1 || num%2 === 0 ) return false;\r\n \r\n let root = Math.floor(Math.sqrt(num));\r\n root += (root%2)-1;\r\n while (root > 1) {\r\n if (num%root === 0)\r\n return false;\r\n root -= 2;\r\n }\r\n return true;\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst isPrime = num => {\r\n\tfor(let i = 2, s = Math.sqrt(num); i <= s; i++)\r\n\t\tif(num % i === 0) return false; \r\n\treturn num > 1;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, e] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet l = [], r = [];\r\n\t\tfor (let i = 0; i < e; i++) {\r\n\t\t\tfor (let j = i, cnt = 0; j < n; j += e) {\r\n\t\t\t\tif (a[j] == 1) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tl[j] = cnt;\r\n\t\t\t\t\tcnt = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (let j = n - i - 1, cnt = 0; j >= 0; j -= e) {\r\n\t\t\t\tif (a[j] == 1) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tr[j] = cnt;\r\n\t\t\t\t\tcnt = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (isPrime(a[i])) {\r\n\t\t\t\tans += (l[i] + 1)*(r[i] + 1) - 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n \r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n function main() {\r\n var t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n }\r\n \r\n function solution() {\r\n let inputLine = readline().split(\" \");\r\n let n = +inputLine[0];\r\n let e = +inputLine[1];\r\n \r\n let array = [], dp = new Array(n).fill(0);\r\n \r\n let arrayLine = readline().split(\" \");\r\n for (let i = 0; i < n; i++) \r\n array[i] = +arrayLine[i];\r\n\r\n for (let i = n-1; i >= 0; i--) {\r\n let k = 1;\r\n if (isPrime(array[i])) {\r\n while(i + k*e < n && array[i + k*e] === 1) \r\n k++;\r\n dp[i] = k-1;\r\n }\r\n else if (array[i] === 1) {\r\n if (isPrime(array[i + k*e])) { dp[i] = dp[i + k*e]+1; break;}\r\n else if (array[i + k*e] === 1) {dp[i] = dp[i + k*e]; break;} \r\n }\r\n }\r\n \r\n const sum = dp.reduce(function(total, item) {\r\n return total+item;\r\n });\r\n \r\n console.log(sum);\r\n }\r\n \r\n function isPrime(num) {\r\n if (num === 2) return true;\r\n if (num === 1 || num%2 === 0 ) return false;\r\n \r\n let root = Math.floor(Math.sqrt(num));\r\n root += (root%2)-1;\r\n while (root > 1) {\r\n if (num%root === 0)\r\n return false;\r\n root -= 2;\r\n }\r\n return true;\r\n }"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start ********** \r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--)\r\n solution(); \r\n}\r\n \r\nfunction solution() {\r\n let inputLine = readline().split(\" \");\r\n let n = +inputLine[0];\r\n let e = +inputLine[1];\r\n \r\n let array = [], dp = [];\r\n array[0] = 0;\r\n\r\n let arrayLine = readline().split(\" \");\r\n for (let i = 0; i < n; i++) \r\n array[i] = +arrayLine[i];\r\n\r\n // for (let i = 0; i < n; i++) {\r\n // if (isPrime(array[i])) {\r\n // let t = i-e;\r\n // while (t >= 0 && t < n && array[t] === 1) {\r\n // dp[i]++;\r\n // }\r\n // }\r\n // }\r\n console.log(array);\r\n}\r\n\r\nfunction isPrime(num) {\r\n if (num === 2) return true;\r\n if (num === 1 || num%2 === 0 ) return false;\r\n\r\n let root = Math.floor(Math.sqrt(num));\r\n root += (root%2)-1;\r\n while (root > 1) {\r\n if (num%root === 0)\r\n return false;\r\n root -= 2;\r\n }\r\n return true;\r\n}"}, {"source_code": "var isPrime = [];\r\nfor(var i=0; i<1000002; i++){\r\n isPrime.push(1);\r\n}\r\n \r\nfunction complex_market_analysis(){\r\n // var n = 9;\r\n // var e = 3;\r\n // var a = [2,4,2,1,1,1,1,4,2];\r\n var inp = readline().split(\" \");\r\n\tvar n = parseInt(inp[0]);\r\n\tprint('n', n);\r\n\tvar e = parseInt(inp[0]);\r\n\tprint('e', e);\r\n\tvar a = readline().split(\" \").map(x=>parseInt(x));\r\n\tprint('a', a);\r\n \r\n\tvar w=[];\r\n\tfor(var i=0; i 1){\r\n\t\t\t\t last1 = last;\r\n\t\t\t\t\tlast = j;\r\n\t\t\t\t\tp = isPrime[v];\r\n\t\t\t\t\tif (p){\r\n\t\t\t\t\t\tr -= 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (p){\r\n\t\t\t\t\tr += (last - last1)\r\n\t\t\t\t}\r\n\t\t\t\tz += e\r\n\t\t\t\tj += 1\r\n\t\t\t}\r\n\t\t\t}\r\n \r\n\t}\r\n\tprint(r);\t\t\r\n}\r\n \r\nfunction prime_pairs(){\r\n\tvar M = isPrime.length;\r\n\tisPrime[1] = 0;\r\n\tisPrime[0] = 0;\r\n\tvar i = 2;\r\n\twhile (i * i < M){\r\n\t\tif (isPrime[i]){\r\n\t\t\tvar j = i * i;\r\n\t\t\twhile (j < M){\r\n\t\t\t\tisPrime[j] = 0;\r\n\t\t\t\tj += i;\r\n\t\t\t}\r\n\t\t}\r\n\t\ti += 1\r\n\t}\r\nvar t = parseInt(readline());\r\nfor (var i=0; iparseInt(x));\r\n \r\n\tvar w=[];\r\n\tfor(var i=0; i 1){\r\n\t\t\t\t last1 = last;\r\n\t\t\t\t\tlast = j;\r\n\t\t\t\t\tp = isPrime[v];\r\n\t\t\t\t\tif (p){\r\n\t\t\t\t\t\tr -= 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (p){\r\n\t\t\t\t\tr += (last - last1)\r\n\t\t\t\t}\r\n\t\t\t\tz += e\r\n\t\t\t\tj += 1\r\n\t\t\t}\r\n\t\t\t}\r\n\r\n\t}\r\n\tprint(r);\t\t\r\n}\r\n \r\nfunction prime_pairs(){\r\n\tvar M = isPrime.length;\r\n\tisPrime[1] = 0;\r\n\tisPrime[0] = 0;\r\n\tvar i = 2;\r\n\twhile (i * i < M){\r\n\t\tif (isPrime[i]){\r\n\t\t\tvar j = i * i;\r\n\t\t\twhile (j < M){\r\n\t\t\t\tisPrime[j] = 0;\r\n\t\t\t\tj += i;\r\n\t\t\t}\r\n\t\t}\r\n\t\ti += 1\r\n\t}\r\nvar t = parseInt(readline());\r\nfor (var i=0; i {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 32768;\n\nlet can_achieve = (h, days, goal)=>{\n let doubles = Math.floor(days/2);\n let ones = Math.floor((days+1)/2);\n //l({doubles, ones, days})\n let leftovers = [];\n for (let x of h){\n if (goal-x>0){\n let g = goal-x;\n if (g%2){\n g--;\n ones--;\n }\n leftovers.push(g);\n }\n }\n //l({leftovers})\n if (ones<0)\n return false;\n for (let l of leftovers){\n let deduct_doubles = Math.min(doubles, Math.floor(l/2));\n doubles -= deduct_doubles;\n l -= deduct_doubles*2;\n let deduct_ones = Math.min(ones, l);\n ones -= deduct_ones;\n l -= deduct_ones;\n if (l>0)\n return false;\n }\n //l('yes')\n return true\n};\n\nconst calc = (n, h)=>{\n h.sort((a, b)=>a-b);\n let min = h[0];\n let max = h[h.length-1]\n if (min==max)\n return 0;\n let l = 0, r = 3*1e14+5;\n while (l stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst h = rna();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet goal = 0;\r\n\t\tfor (let i = 0; i < n; i++) goal = Math.max(goal, h[i]);\r\n\t\tfor (let round = 0; round < 2; round++, goal++) {\r\n\t\t\tlet need = 0, oddReq = 0, oddHas;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tneed += goal - h[i];\r\n\t\t\t\toddReq += (goal- h[i]) & 1;\r\n\t\t\t}\r\n\t\t\tans[round] = Math.ceil(need*2/3);\r\n\t\t\toddHas = Math.ceil(ans/2);\r\n\t\t\t//console.log({goal, need, oddReq, oddHas, ans});\r\n\t\t\tif (oddReq > oddHas) {\r\n\t\t\t\tans[round] += (oddReq - oddHas) * 2 - (ans%2 == 0 ? 1 : 0);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(Math.min(...ans));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst check = (a, days, max) => {\n let twos = div(days, 2);\n let ones = div(days + 1, 2);\n\n for (const num of a) {\n if (num === max) continue;\n let diff = max - num;\n if (diff % 2 === 1) {\n ones--;\n diff--;\n }\n if (ones < 0) return false;\n if (diff === 0) continue;\n let used2s = Math.min(div(diff, 2), twos);\n twos -= used2s;\n diff -= used2s * 2;\n if (diff === 0) continue;\n let used1s = Math.min(diff, ones);\n ones -= used1s;\n diff -= used1s;\n if (diff !== 0) return false;\n }\n return true;\n}\n\nconst calc = (n, a)=>{\n if (n === 1) return 0;\n\n let max = a[0];\n for (const num of a) {\n max = Math.max(max, num);\n }\n \n let l = 0, r = 300000000000000;\n let mid;\n while (l < r) {\n mid = l + div((r - l), 2);\n // console.log(`mid`, mid);\n const res = check(a, mid, max) || check(a, mid, max + 1);\n // console.log(`res`, res);\n if (!res) {\n l = mid + 1;\n } else {\n r = mid;\n }\n }\n\n return r;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let max = -Infinity\n for (let i = 0; i < arr.length; i++) {\n max = Math.max(max, arr[i])\n }\n return Math.min(help(n, arr, max), help(n, arr, max + 1))\n}\nfunction help(n, arr, max) {\n //\n let odd = 0\n let even = 0\n for (let i = 0; i < arr.length; i++) {\n const d = max - arr[i]\n if (d & 1) {\n odd++\n }\n even += Math.floor(d / 2)\n // const r = d % 3\n // if (r === 1) {\n // odd++\n // } else if (r === 2) {\n // even++\n // }\n // ans += 2 * Math.floor(d / 3)\n }\n// console.log(odd, even)\n let ans = 0\n if (odd > even) {\n ans = 2 * odd - 1\n } else {\n const diff = even - odd\n const k = Math.floor(diff / 3)\n const r = diff % 3\n ans = 2 * (odd + 2 * k)\n if (r === 1) {\n ans += 2\n } else if (r === 2) {\n ans += 3\n }\n }\n return ans\n}\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data, max) {\r\n let b = 0,\r\n a = 0\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n // if (b > a) return b * 2 - 1\r\n let x = Math.max(Math.floor((a - b) / 3), 0)\r\n a -= x\r\n b += 2 * x\r\n if (b === a - 2) {\r\n a--\r\n b += 2\r\n }\r\n if (b > a) return b * 2 - 1\r\n return a * 2\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n let t = -1\r\n for (let [k, v] of data.entries()) {\r\n if (t === -1 || data[t] < v) t = k\r\n }\r\n\r\n let ans = solve(n, data, data[t])\r\n\r\n ans = Math.min(ans, solve(n, data, data[t] + 1))\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst h = rna();\r\n\r\n\t\tconst ans = [];\r\n\t\tlet goal = 0;\r\n\t\tfor (let i = 0; i < n; i++) goal = Math.max(goal, h[i]);\r\n\t\tfor (let round = 0; round < 2; round++, goal++) {\r\n\t\t\tlet need = 0, oddReq = 0, oddHas;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tneed += goal - h[i];\r\n\t\t\t\toddReq += (goal- h[i]) & 1;\r\n\t\t\t}\r\n\t\t\tans[round] = Math.ceil(need*2/3);\r\n\t\t\toddHas = Math.ceil(ans[round]/2);\r\n\t\t\tif (oddReq > oddHas) {\r\n\t\t\t\tans[round] += (oddReq - oddHas) * 2 - (ans[round]%2 == 0 ? 1 : 0);\r\n\t\t\t}\r\n\t\t\t//console.log({oddHas});\r\n\t\t}\r\n\r\n\t\tconsole.log(Math.min(...ans));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data, max) {\r\n let b = 0,\r\n a = 0\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n // if (b > a) return b * 2 - 1\r\n let x = Math.max(Math.floor((a - b) / 3), 0)\r\n a -= x\r\n b += 2 * x\r\n if (b === a - 2) {\r\n a--\r\n b += 2\r\n }\r\n if (b > a) return b * 2 - 1\r\n return a * 2\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n let t = -1\r\n for (let [k, v] of data.entries()) {\r\n if (t === -1 || data[t] < v) t = k\r\n }\r\n\r\n let ans = solve(n, data, data[t])\r\n data[t]++\r\n ans = Math.min(ans, solve(n, data, data[t]))\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data, max) {\r\n let b = 0,\r\n a = 0\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n // if (b > a) return b * 2 - 1\r\n let x = Math.max(Math.floor((a - b) / 3), 0)\r\n a -= x\r\n b += 2 * x\r\n if (b === a - 2) {\r\n a--\r\n b += 2\r\n }\r\n if (b > a) return b * 2 - 1\r\n return a * 2\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n let t = -1\r\n for (let [k, v] of data.entries()) {\r\n if (t === -1 || data[t] < v) t = k\r\n }\r\n\r\n let ans = solve(n, data, data[t])\r\n data[t]++\r\n ans = Math.min(ans, solve(n, data, data[t]) + 1)\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data, max) {\r\n let b = 0,\r\n a = 0\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n if (b > a) return b * 2 - 1\r\n let x = Math.ceil((a - b) / 3)\r\n a -= x\r\n b += 2 * x\r\n return a + b\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n let t = -1\r\n for (let [k, v] of data.entries()) {\r\n if (t === -1 || data[t] < v) t = k\r\n }\r\n\r\n let ans = solve(n, data, data[t])\r\n data[t]++\r\n ans = Math.min(ans, solve(n, data, data[t]) + 1)\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data) {\r\n let b = 0,\r\n a = 0,\r\n max = Math.max(...data)\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n let x = Math.ceil((a - b) / 3)\r\n a -= x\r\n b += 2 * x\r\n return a + b\r\n}\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n res.push(solve(n, data))\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst h = rna();\r\n\r\n\t\tconst goal = Math.max(...h);\r\n\r\n\t\tlet need = 0, oddReq = 0, oddHas;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tneed += goal - h[i];\r\n\t\t\toddReq += (goal- h[i]) & 1;\r\n\t\t}\r\n\r\n\t\tlet ans = Math.ceil(need*2/3);\r\n\t\toddHas = Math.ceil(ans/2);\r\n\t\tif (oddReq > oddHas) {\r\n\t\t\tans += (oddReq - oddHas) * 2 - (ans%2 == 0 ? 1 : 0);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst check = (a, days) => {\n let twos = div(days, 2);\n let ones = div(days + 1, 2);\n\n let max = a[0];\n for (const num of a) {\n max = Math.max(max, num);\n }\n\n for (const num of a) {\n if (num === max) continue;\n let diff = max - num;\n if (diff % 2 === 1) {\n ones--;\n diff--;\n }\n if (ones < 0) return false;\n if (diff === 0) continue;\n let used2s = Math.min(div(diff, 2), twos);\n twos -= used2s;\n diff -= used2s * 2;\n if (diff === 0) continue;\n let used1s = Math.min(diff, ones);\n ones -= used1s;\n diff -= used1s;\n if (diff !== 0) return false;\n }\n return true;\n}\n\nconst calc = (n, a)=>{\n if (n === 1) return 0;\n \n let l = 0, r = 300000000000000;\n let mid;\n while (l < r) {\n mid = l + div((r - l), 2);\n // console.log(`mid`, mid);\n const res = check(a, mid);\n // console.log(`res`, res);\n if (!res) {\n l = mid + 1;\n } else {\n r = mid;\n }\n }\n\n return r;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, a)=>{\n if (n === 1) return 0;\n let res = 0;\n\n let max = a[0];\n for (const num of a) {\n max = Math.max(max, num);\n }\n let rem = 0;\n let count = 0;\n for (const num of a) {\n if (num !== max) {\n rem += max - num;\n count++;\n }\n }\n\n const days2 = div(rem, 3);\n // console.log(`days2`, days2);\n const left = rem % 3;\n // console.log(`left`, left);\n res = (days2 * 2) + (left === 1 ? 1 : (left === 2 ? 2 : 0));\n\n return res;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, a)=>{\n if (n === 1) return 0;\n let res = 0;\n\n let max = a[0];\n for (const num of a) {\n max = Math.max(max, num);\n }\n let rem = 0;\n let count = 0;\n for (const num of a) {\n if (num !== max) {\n rem += max - num;\n count++;\n }\n }\n\n const days2 = div(rem, 3);\n const left = rem % 3;\n res = (days2 * 2) + (left === 1 ? 1 : 2);\n\n return res;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let max = -Infinity\n for (let i = 0; i < arr.length; i++) {\n max = Math.max(max, arr[i])\n }\n //\n let odd = 0\n let even = 0\n for (let i = 0; i < arr.length; i++) {\n const d = max - arr[i]\n if (d & 1) {\n odd++\n }\n even += Math.floor(d / 2)\n // const r = d % 3\n // if (r === 1) {\n // odd++\n // } else if (r === 2) {\n // even++\n // }\n // ans += 2 * Math.floor(d / 3)\n }\n// console.log(odd, even)\n let ans = 0\n if (odd > even) {\n ans = 2 * odd - 1\n } else {\n const diff = even - odd\n const k = Math.floor(diff / 3)\n const r = diff % 3\n ans = 2 * (odd + 2 * k)\n if (r === 1) {\n ans += 2\n } else if (r === 2) {\n ans += 3\n }\n }\n return ans\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let max = -Infinity\n for (let i = 0; i < arr.length; i++) {\n max = Math.max(max, arr[i])\n }\n //\n let ans = 0\n let odd = 0\n let even = 0\n for (let i = 0; i < arr.length; i++) {\n const d = max - arr[i]\n if (d & 1) {\n odd++\n }\n even += Math.floor(d / 2)\n // const r = d % 3\n // if (r === 1) {\n // odd++\n // } else if (r === 2) {\n // even++\n // }\n // ans += 2 * Math.floor(d / 3)\n }\n// console.log(ans, odd, even)\n if (odd >= even) {\n ans += 2 * odd - 1\n } else {\n const diff = even - odd\n const k = Math.floor(diff / 3)\n const r = diff % 3\n ans = 2 * (odd + 2 * k)\n if (r === 1) {\n ans += 2\n } else if (r === 2) {\n ans += 3\n }\n }\n return ans\n}\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 32768;\n\nlet can_achieve = (h, days, goal)=>{\n let doubles = Math.floor(days/2);\n let ones = Math.floor((days+1)/2);\n //l({doubles, ones, days})\n let leftovers = [];\n for (let x of h){\n if (goal-x>0){\n let g = goal-x;\n if (g%2){\n g--;\n ones--;\n }\n leftovers.push(g);\n }\n }\n //l({leftovers})\n if (ones<0)\n return false;\n for (let l of leftovers){\n let deduct_doubles = Math.min(doubles, Math.floor(l/2));\n doubles -= deduct_doubles;\n l -= deduct_doubles*2;\n let deduct_ones = Math.min(ones, l);\n ones -= deduct_ones;\n l -= deduct_ones;\n if (l>0)\n return false;\n }\n //l('yes')\n return true\n};\n\nconst calc = (n, h)=>{\n h.sort((a, b)=>a-b);\n let min = h[0];\n let max = h[h.length-1]\n let l = 0, r = 3*1e14+5;\n while (l{\"use strict\";var t={312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const u=n(r(747));let o=\"\",s=[],i=0,l=\"\";const a=\"local\"===process.argv[2],c=t=>{if(a)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt[1]!=e[1]?e[1]-t[1]:e[0]-t[0]));let r=0,n=1;for(let u=0;u{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "print(function(n) {\n\n\tvar a = [];\n\tfor (var i = 0; i < n; i++)\n\t\ta.push(readline().split(' ').map(Number));\n\ta.sort(function(a, b) {\n\t\tif (a[1] === b[1]) return b[0] - a[0];\n\t\treturn b[1] - a[1];\n\t});\n\n\tvar t = 1;\n\tvar ans = 0;\n\tvar i = 0;\n\twhile (t > 0 && i < a.length) {\n\t\tans += a[i][0];\n\t\tt += a[i][1]-1;\n\t\ti++;\n\t}\n\treturn ans;\n}(+readline()));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar cards = [], points = 0;\n\n\t\twhile (n--) {\n\t\t\tcards.push(readline().split(' ').map(Number));\n\t\t}\n\n\t\tcards.sort(function (a, b) { return (b[1] * 1e5 + b[0]) - (a[1] * 1e5 + a[0]); });\n\n\t\tn = 1;\n\t\tfor (var i = 0, _i = cards.length; i < _i && 0 < n; i++) {\n\t\t\tn += cards[i][1] - 1;\n\t\t\tpoints += cards[i][0];\n\t\t}\n\n\t\treturn points;\n\n\t}(+readline()));\n\n}.call(this));\n"}], "negative_code": [{"source_code": "print(function(n) {\n\n\tvar zero = [];\n\tvar ans = 0;\n\tvar t = 0;\n\tfor (var i = 0; i < n; i++)\n\t\treadline().split(' ').map(Number).reduce(function(a, b) {\n\t\t\tif (b === 0) zero.push(a);\n\t\t\telse ans += a, t += b - 1;\n\t\t});\n\n\tzero.sort(function(a, b) {\n\t\treturn b - a\n\t});\n\tfor (var i = 0, l = Math.min(t,zero.length); i < l; i++)\n\t\tans += zero[i];\n\n\treturn ans;\n}(+readline()));"}], "src_uid": "4abdd16670a796be3a0bff63b9798fed"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\r\n\t\tlet ans = [];\r\n\t\tn -= k - 3;\r\n\t\tif (n % 2 == 0) {\r\n\t\t\tif (n % 4 == 0){\r\n\t\t\t\tans = [n/2, n/4, n/4];\r\n\t\t\t} else {\r\n\t\t\t\tans = [n/2-1, n/2-1, 2]\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = [(n-1)/2, (n-1)/2, 1];\r\n\t\t}\r\n\r\n\t\tans.push(...Array(k-3).fill(1));\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n let res = [],\r\n one = 0;\r\n if (n & 1) {\r\n if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;\r\n m--;\r\n one++;\r\n n--;\r\n }\r\n for (let i = 30; i >= 0; i--) {\r\n if (res.length) {\r\n while (1 << i <= n) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n } else {\r\n if (1 << i <= n / 2) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n }\r\n }\r\n if (res.length === m) {\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n } else if (res.length > m) {\r\n let sum = res.splice(2, res.length - m).reduce((a, b) => a + b, 0) / 2;\r\n res[0] += sum;\r\n res[1] += sum;\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n }\r\n m -= res.length;\r\n while (m--) {\r\n let cur = res[res.length - 1];\r\n if (cur === 2) {\r\n res.pop();\r\n one += 2;\r\n } else {\r\n res[res.length - 1] /= 2;\r\n res.push(cur / 2);\r\n }\r\n }\r\n return (res.join(' ') + ' 1'.repeat(one)).trim();\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var ans = new Array(k).fill(1)\r\n n = n-(k-3)\r\n var x\r\n if (n % 2 === 1) {\r\n x = (n - 1) / 2\r\n ans[0] = 1\r\n ans[1] = x\r\n ans[2] = x\r\n // return console.log(1, x, x)\r\n }\r\n if (n % 2 === 0) {\r\n ans[0] = 2\r\n ans[1] = (n-2)/2\r\n ans[2] = (n-2)/2\r\n }\r\n\r\n if (n % 4 === 0) {\r\n x = n / 4\r\n ans[0] = x*2\r\n ans[1] = x\r\n ans[2] = x\r\n }\r\n\r\n return console.log(ans.join(' '))\r\n\r\n });\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n let res = [],\r\n one = 0;\r\n if (n & 1) {\r\n if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;\r\n m--;\r\n one++;\r\n n--;\r\n }\r\n for (let i = 30; i >= 0; i--) {\r\n if (res.length) {\r\n while (1 << i <= n) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n } else {\r\n if (1 << i <= n / 2) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n }\r\n }\r\n if (res.length === m) {\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n } else if (res.length > m) {\r\n let sum = res.splice(2, res.length - m + 2).reduce((a, b) => a + b, 0) / 2;\r\n res[0] += sum;\r\n res[1] += sum;\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n }\r\n m -= res.length;\r\n while (m--) {\r\n let cur = res[res.length - 1];\r\n if (cur === 2) {\r\n res.pop();\r\n one += 2;\r\n } else {\r\n res[res.length - 1] /= 2;\r\n res.push(cur / 2);\r\n }\r\n }\r\n return (res.join(' ') + ' 1'.repeat(one)).trim();\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "1fea137016452340beb13dd7518f00c9"} {"source_code": "print(function(n, m) {\n\tvar ans = [],\n\t\tt = 0,\n\t\ta = ('0 ' + readline()).split(' ').map(Number);\n\n\tfor (var i = 0; i < m; i++) {\n\t\tgo.apply(0, rn());\n\t}\n\n\treturn ans.join('\\n');\n\n\tfunction go(type, x, y) {\n\t\tif (type === 1) a[x] = y - t;\n\t\telse if (type === 2) t += x;\n\t\telse ans.push(a[x] + t);\n\t}\n\n} .apply(0, rn()));\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}", "positive_code": [{"source_code": "function main()\n{\n var tmp;\n tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n var n = tmp[0],\n m = tmp[1];\n var a = readline().split(\" \").map(function (x) { return parseInt(x); });\n var y = 0;\n while ( m-- )\n {\n tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n if ( tmp[0] == 1 )\n {\n a[tmp[1]-1] = tmp[2]-y;\n }\n else if ( tmp[0] == 2 )\n {\n y += tmp[1];\n }\n else if ( tmp[0] == 3 )\n {\n print(a[tmp[1]-1]+y);\n }\n }\n}\n\nmain();\n"}, {"source_code": "function main(){\n var tmp;\n tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n var n = tmp[0],\n m = tmp[1];\n var a = readline().split(\" \").map(function (x) { return parseInt(x); });\n var y = 0;\n while ( m-- ){\n tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n if ( tmp[0] == 1 ){\n a[tmp[1]-1] = tmp[2]-y;\n }\n else if ( tmp[0] == 2 ){\n y += tmp[1];\n }\n else if ( tmp[0] == 3 ){\n print(a[tmp[1]-1]+y);\n }\n }\n}\n\nmain();\n"}, {"source_code": "print(function(n, m) {\n\tvar ans = [],\n\t\tt = 0,\n\t\ta = ('0 ' + readline()).split(' ').map(Number);\n\t\n\tfor (var i = 0; i < m; i++) {\n\t\tvar l = readline().split(' ').map(Number);\n\t\tif (l[0] === 1)\n\t\t\ta[l[1]] = l[2] - t;\n\t\telse if (l[0] === 2)\n\t\t\tt += l[1];\n\t\telse\n\t\t\tans.push(a[l[1]] + t);\n\t}\n\n\treturn ans.join('\\n');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var data = readline().split(\" \").map( c => parseInt(c))\nvar arra = readline().split(\" \").map( c => parseInt(c))\nvar artt = new Array(arra.length).fill(0)\nvar incre = 0\nfor (var i = 0; i< data[1]; i++){\n\tvar query = readline().split(\" \").map( c => parseInt(c))\n\tif (query[0] == 1){\n\t\tarra[query[1]-1] = query[2]\n\t\tartt[query[1]-1] = incre\n\t}\n\telse if (query[0] == 2){\n\t\tincre += query[1]\n\t}\n\telse {\n\t\tprint(arra[query[1]-1]+incre-artt[query[1]-1])\n\t}\n}"}], "negative_code": [], "src_uid": "48f3ff32a11770f3b168d6e15c0df813"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var A = tmp[0];\n var B = tmp[1];\n output[i] = Math.ceil(Math.abs(A - B) / 10);\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "const {EOL} = require('os')\nfunction solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\nlet i = ''\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n \n const lines = i.split(EOL).slice(1)\n \n for( let line of lines ) {\n if(line.split` `.length>1)\n console.log(solve(...line.split` `))\n }\n})\n"}, {"source_code": "T = readline();\n\nwhile ( T-- ) {\n a = readline().split(' ');\n \n d = Math.abs ( a[0] - a[1] );\n \n print (Math.floor(d/10) + ( d % 10 !== 0 ) );\n}"}, {"source_code": "T = readline();\nwhile (T--) {\n a = readline().split(' ');\n d = Math.abs(+a[0] - +a[1]);\n print(Math.floor(d / 10) + (d % 10 ? 1 : 0));\n}"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nreadline.on('line', line => {\n if(line.split` `.length > 1)\n console.log(solve(...line.split` `));\n});"}, {"source_code": "const {EOL} = require('os')\n\nlet i = ''\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n \n const lines = i.split(EOL).slice(1)\n \n for( let line of lines ) {\n if(line.split` `.length>1)\n console.log(solve(...line.split` `))\n }\n})\n\n\nfunction solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}"}, {"source_code": "const readline = require(\"readline\");\n\nconst reader = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst lines = [];\n\nreader.on(\"line\", (line) => {\n const nums = line.split(\" \").map(Number);\n lines.push(nums);\n});\n\nreader.on(\"close\", () => {\n const [N, ...tests] = lines;\n\n for (let i = 0; i < tests.length; i++) {\n let A = tests[i][0];\n let B = tests[i][1];\n\n if (A === B) {\n console.log(0);\n } else if (A > B) {\n let diff = A - B;\n if (diff <= 10) {\n console.log(1);\n } else {\n console.log(Math.ceil(diff / 10));\n }\n } else if (A < B) {\n let diff1 = B - A;\n if (diff1 <= 10) {\n console.log(1);\n } else {\n console.log(Math.ceil(diff1 / 10));\n }\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b] = ti(readline().split(' '));\n\n if(a === b){\n console.log(0);\n continue;\n }\n\n let d = Math.abs(a-b);\n if(d <= 10){\n console.log(1);\n continue;\n }else{\n if(d % 10 !== 0)\n console.log(1 + Math.floor(d/10));\n else\n console.log(d / 10);\n }\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n const n = parseInt(readLine());\n for (let i = 0; i < n; i++) {\n let l = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n let [a, b] = l;\n let res = Math.ceil(Math.abs(a - b) / 10);\n console.log(res);\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\nfunction functions() {\n rl.question('', function (k) {\n var input = k.split(' ');\n var a = parseInt(input[0]);\n var b = parseInt(input[1]);\n var output;\n // if (a == 'undefined' || b == 'undefined') {\n //\n // }\n if (a > b) {\n output = Math.ceil((a - b) / 10);\n } else if (b > a) {\n output = Math.ceil((b - a) / 10);\n } else if (a == b) {\n output = 0;\n }\n console.log(output);\n functions();\n })\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const diff = Math.abs(a - b);\n let ans = Math.floor(diff / 10);\n if (diff % 10 !== 0) ans++;\n console.log(ans);\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t; x++) {\n const [a, b] = input[x].split(\" \").map((num) => Number(num));\n\n if (b === a) {\n console.log(0);\n continue;\n }\n\n const diff = Math.abs(b - a);\n\n const tenCnt = parseInt(diff / 10);\n const oneCnt = diff % 10 > 0 ? 1 : 0;\n\n console.log(tenCnt + oneCnt);\n }\n}\n\n/*\n Q. a\ub97c b\uac00 \ub418\uac8c \ud558\uae30 \uc704\ud55c \ucd5c\uc18c\ud55c\uc758 move \ud69f\uc218\ub294?\n\n 1. 2\uac1c\uc758 \uc815\uc218 a, b\n 2. 1 ~ 10 \uc0ac\uc774\uc758 \uc815\uc218 k\ub97c \uc120\ud0dd -> a\uc5d0 \ub354\ud558\uac70\ub098 \ube7c\uae30 \n 3. \uac01 move\ub9c8\ub2e4 \uc11c\ub85c \ub2e4\ub978 k\ub97c \uc120\ud0dd\uac00\ub2a5\n \n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst r1 = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nfunction moves(a,b){\n\n let num1= Number(a);\n let num2 = Number(b);\n\n // if( isNaN(num1) ) console.error(\" Bhul Hoise\");\n // if( isNaN(num2) ) console.error(\"Etao Bhul Hoise\");\n\n let diff = Math.abs (num2-num1);\n let div = parseInt(diff/10);\n let quo = diff%10;\n\n if(quo>0) quo=1;\n let move = div+quo;\n\n console.log(move);\n\n}\n\nlet inputs = [];\n\nr1.on(\"line\",function(a){\n inputs.push(a); \n});\n\nr1.on(\"close\",function(){\n\n for(let i=1; i0) quo=1;\n let move = div+quo;\n\n console.log(move);\n\n}\n\nlet inputs = [];\n\nr1.on(\"line\",function(a){\n inputs.push(a); \n});\n\nr1.on(\"close\",function(){\n\n for(let i=1; i0) quo=1;\n let move = div+quo;\n\n console.log(move);\n\n}\n\nlet testCases;\n\nr1.on(\"line\",function(a){\n\n let vals = a.trim().split(\" \");\n if(vals.length === 1 && testCases === undefined){\n testCases = Number(vals[0]);\n }\n else if(vals.length === 2)\n {\n testCases--;\n moves(vals[0],vals[1]); \n }\n if(testCases === 0){\n r1.close();\n }\n \n});\n\n// r1.on(\"close\",function(){\n\n// for(let i=1; i0) quo=1;\n let move = div+quo;\n\n console.log(move);\n\n}\n\nlet inputs = [];\n\nr1.on(\"line\",function(a){\n inputs.push(a); \n});\n\nr1.on(\"close\",function(){\n\n for(let i=1; i inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i < b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = b - 1; i >= a; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(0, t, i => {\n let a = inp[r++], b = inp[r++];\n console.log(Math.ceil(Math.abs(a - b) / 10))\n })\n})();"}, {"source_code": "const { SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION } = require('constants')\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n for (let i = 1; i < lines.length - 1; ++i) {\n const [a, b] = lines[i].split(' ')\n const answer = solution(a, b)\n console.log(answer)\n }\n})\n\nfunction solution(a, b) {\n if (b === a) {\n return 0\n }\n\n const r = Math.abs(b - a)\n\n return (\n Math.floor(r/10)\n + ((r % 10 === 0) ? 0 : 1)\n )\n}\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let t = parseInt(input[0]);\n\n for (let i = 1; i <= t; i += 1) {\n const [a, b] = splitAndParseInt(input[i]);\n\n if (a === b) {\n console.log(0);\n } else if (a < b) {\n const diff = Math.ceil((b - a) / 10);\n console.log(diff);\n } else {\n console.log(Math.ceil((a - b) / 10));\n }\n }\n});\n"}, {"source_code": "function solve(a, b) {\n const base = 10;\n const diff = Math.abs(a - b);\n const r = diff % base;\n const q = (diff - r) / base;\n return (r === 0) ? q : (q + 1);\n}\n\nfunction main(lines) {\n lines.shift();\n const whitespace = /\\s+/;\n for (const line of lines) {\n const [a, b] = line.split(whitespace).map(Number);\n const result = solve(a, b);\n console.log(result);\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(a, b) {\n const base = 10;\n const diff = Math.abs(a - b);\n const r = diff % base;\n const q = (diff - r) / base;\n return (r === 0) ? q : (q + 1);\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const [a, b] = t.split(/\\s+/).map(Number);\n const result = solve(a, b);\n console.log(result);\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "\n\nfunction solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\n// let i = '';\n// process.stdin.on('data', c => i += c);\n// process.stdin.on('end', () => {\n// const {EOL} = require('os');\n// const lines = i.split(EOL).slice(1); /*your input text, split by lines*/\n// // console.log(lines);\n \n// for( var line of lines ){\n// var [a,b] = line.split(' ');\n// console.log(solve(a,b));\n// }\n \n// });\n\n\n// const readline = require('readline').createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n\n// // single line input\n// readline.on('line', line => {\n// readline.close(), console.log(line);\n// });\n// var m = [];\n// multi line input\n// readline.on('line', line => {\n// line = line.split` `\n// console.log(line[0])\n// });\nlet i = ''\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).slice(1) /*your input text, split by lines*/\n // console.log(lines); \n \n \n for( let line of lines ) {\n if(line.split` `.length>1)\n console.log(solve(...line.split` `))\n }\n})\n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\nfunction functions() {\n rl.question('', function (k) {\n var input = k.split(' ');\n var a = parseInt(input[0]);\n var b = parseInt(input[1]);\n var output;\n if (a > b) {\n output = Math.ceil((a - b) / 10);\n } else if (b > a) {\n output = Math.ceil((b - a) / 10);\n } else if (a == b) {\n output = 0;\n }\n console.log(output);\n functions();\n })\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst r1 = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nfunction moves(a,b){\n\n let num1= Number(a);\n let num2 = Number(b);\n\n let diff = Math.abs (num2-num1);\n let div = parseInt(diff/10);\n let quo = diff%10;\n\n if(quo>0) quo=1;\n let move = div+quo;\n\n console.log(move);\n\n}\n\nlet inputs = [];\n\nr1.on(\"line\",function(a){\n inputs.push(a); \n});\n\nr1.on(\"close\",function(){\n\n for(let i=1; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).slice(1); /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n console.log(line);\n var [a,b] = line.split(' ')\n console.log(solve(a,b));\n }\n \n});"}, {"source_code": "\n\nfunction solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\n// let i = '';\n// process.stdin.on('data', c => i += c);\n// process.stdin.on('end', () => {\n// const {EOL} = require('os');\n// const lines = i.split(EOL).slice(1); /*your input text, split by lines*/\n// // console.log(lines);\n \n// for( var line of lines ){\n// var [a,b] = line.split(' ');\n// console.log(solve(a,b));\n// }\n \n// });\n\n\n// const readline = require('readline').createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n\n// // single line input\n// readline.on('line', line => {\n// readline.close(), console.log(line);\n// });\n// var m = [];\n// multi line input\n// readline.on('line', line => {\n// line = line.split` `\n// console.log(line[0])\n// });\nlet i = ''\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).slice(1) /*your input text, split by lines*/\n // console.log(lines); \n \n \n for( let line of lines ) console.log(solve(...line.split` `))\n})\n"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).slice(1); /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n // console.log(line);\n var [a,b] = line.split(' ')\n console.log(solve(a,b));\n }\n \n});"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\nlet i = ''\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).slice(1) /*your input text, split by lines*/\n // console.log(lines); \n \n \n for( let line of lines ) console.log(solve(...line.split` `))\n})\n"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n var [a,b] = line.split(' ');\n console.log(solve(a,b));\n }\n \n});"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);\n}\n\n\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).slice(1); /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n var [a,b] = line.split(' ');\n console.log(solve(a,b));\n }\n \n});"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10)\n}\n\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).slice(1) /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n console.log(line)\n solve(...line.split` `)\n }\n \n})"}, {"source_code": "function solve(a,b){\n return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10)\n}\n\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL).slice(1) /*your input text, split by lines*/\n // console.log(lines);\n \n for( var line of lines ){\n // console.log(line)\n console.log(solve(...line.split` `))\n }\n \n})"}], "src_uid": "d67a97a3b69d599b03d3fce988980646"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction myFunc(a, b, c, d){\r\n a = BigInt(a);\r\n b = BigInt(b);\r\n c = BigInt(c);\r\n d = BigInt(d);\r\n\r\n let x = BigInt(a*d);\r\n let y = BigInt(b*c);\r\n\r\n // console.log(x, y);\r\n\r\n if(x == y) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n\r\n return 2;\r\n}", "positive_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [a, b, c, d] = input[index]\n .split(\" \")\n .map((item) => BigInt(parseInt(item)));\n const testCase = {\n a,\n b,\n c,\n d,\n };\n testCases.push(testCase);\n }\n}\n\nconst gcd = (a, b) => (b ? gcd(b, a % b) : [a]);\n\nconst egcd = (a, b) => {\n let [oldR, r] = [a, b];\n let [oldS, s] = [1, 0];\n let [oldT, t] = [0, 1];\n\n while (r) {\n const q = Math.floor(oldR / r);\n [oldR, r] = [r, oldR - q * r];\n [oldS, s] = [s, oldS - q * s];\n [oldT, t] = [t, oldT - q * t];\n }\n return [oldR, oldS, oldT];\n};\n\nfunction solution(testCase) {\n let { a, b, c, d } = testCase;\n\n // console.log(a, b, c, d);\n\n let result = 0;\n\n if (a * d == b * c) {\n result = 0;\n } else if (a == 0 || c == 0) {\n result = 1;\n } else {\n const [g1] = gcd(a, b);\n const [g2] = gcd(c, d);\n // console.log(a / g1, b / g1, c / g2, d / g2);\n a = a / g1;\n b = b / g1;\n c = c / g2;\n d = d / g2;\n const [g] = gcd(a * d, b * c);\n if ((a * d) / g != 1) result++;\n if ((b * c) / g != 1) result++;\n // console.log(a, b, c, d, g, (a * d) / g, (b * c) / g);\n }\n\n console.log(result);\n // console.log(\"------\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\",\r\n currentLine = 0;\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => string.trim());\r\n main();\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// code here\r\n\r\nfunction main() {\r\n const t = +readLine(); // convert t in number\r\n for (let i = 0; i < t; i++) {\r\n // iterate in each case\r\n // const n = +readLine();\r\n const arr = readLine()\r\n .split(\" \")\r\n .map((p) => +p); // convert p in number\r\n let a = BigInt(arr[0]);\r\n let b = BigInt(arr[1]);\r\n let c = BigInt(arr[2]);\r\n let d = BigInt(arr[3]);\r\n let x = BigInt(a * d);\r\n let y = BigInt(b * c);\r\n if (x == y) {\r\n console.log(0);\r\n } else if (a == 0 || c == 0) {\r\n console.log(1);\r\n } else if (x % y == 0 || y % x == 0) {\r\n console.log(1);\r\n } else {\r\n console.log(2)\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\nfunction gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n\r\n let gcd_ab = gcd(a, b);\r\n let gcd_cd = gcd(c, d);\r\n a = a/gcd_ab;\r\n b = b/gcd_ab;\r\n c = c/gcd_cd;\r\n d = d/gcd_cd;\r\n\r\n let x = BigInt(a*d);\r\n let y = BigInt(b*c);\r\n\r\n // console.log(x, y);\r\n\r\n if(x == y) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n\r\n return 2;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\nfunction gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n if(a == 0 || c == 0) return 1;\r\n\r\n let gcd_ab = gcd(a, b);\r\n let gcd_cd = gcd(c, d);\r\n a = a/gcd_ab;\r\n b = b/gcd_ab;\r\n c = c/gcd_cd;\r\n d = d/gcd_cd;\r\n\r\n let x = BigInt(a*d);\r\n let y = BigInt(b*c);\r\n\r\n if(x == y) return 0;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n\r\n return 2;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n\r\n if( (a % b) == 0 && (d % c) == 0) return 1;\r\n if( (a % c) == 0 && (d % b) == 0) return 1;\r\n\r\n if( (b % a) == 0 && (c % d) == 0) return 1;\r\n if( (b % d) == 0 && (c % a) == 0) return 1;\r\n\r\n return 2;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n let gcd_ab = gcd(a, b);\r\n let gcd_cd = gcd(c, d);\r\n a = a/gcd_ab;\r\n b = b/gcd_ab;\r\n c = c/gcd_cd;\r\n d = d/gcd_cd;\r\n\r\n const x = a * d;\r\n const y = b * c;\r\n if(x == y) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n return 2;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\nfunction gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction myFunc(a, b, c, d){\r\n let gcd_ab = gcd(a, b);\r\n let gcd_cd = gcd(c, d);\r\n a = a/gcd_ab;\r\n b = b/gcd_ab;\r\n c = a/gcd_cd;\r\n d = b/gcd_cd;\r\n const x = a * d;\r\n const y = b * c;\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n return 2;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n const x = a*d;\r\n const y = b*c;\r\n if( (x % y) == 0 || (y % x) == 0) return 1;\r\n return 2;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n//reenviar\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n const x = a*d;\r\n const y = b*c;\r\n if( x % y == 0 || y % x == 0) return 1;\r\n return 2;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n//reenviar\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if(((a*d) % (b*c)) == 0 || ((b*c) % (a*d)) == 0) return 1;\r\n return 2;\r\n}"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n//reenviar\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if((a*d % b*c) == 0 || (b*c % a*d) == 0) return 1;\r\n return 2;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n//reenviar\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n\r\n if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;\r\n return 2;\r\n}\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n//reenviar\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if(a == b || c == d) return 1;\r\n // if(a == c || b == d) return 1;\r\n if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;\r\n return 2;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n\r\n if(a == b || c == d) return 1;\r\n if(a == c || b == d) return 1;\r\n\r\n if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;\r\n return 2;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\nfunction myFunc(a, b, c, d){\r\n if(a*d == b*c) return 0;\r\n if(a == 0 || c == 0) return 1;\r\n if(a == b || c == d) return 1;\r\n\r\n if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;\r\n return 2;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Main Function, code here\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n for (let i = 0; i < testCases; i++) {\r\n const arrFrac = readline()\r\n .split(\" \")\r\n .map((number) => parseInt(number));\r\n const a = arrFrac[0];\r\n const b = arrFrac[1];\r\n const c = arrFrac[2];\r\n const d = arrFrac[3];\r\n let x = a * d\r\n let y = b * c\r\n if (a / b === c / d) {\r\n console.log(0);\r\n } else if (a === 0 || c === 0) {\r\n console.log(1);\r\n\r\n } else if (x % y == 0 || y % x == 0) {\r\n console.log(1);\r\n } else {\r\n console.log(2);\r\n }\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n for (let i = 0; i < testCases; i++) {\r\n const arrFrac = readline().split(\" \").map((number) => parseInt(number));\r\n const a = arrFrac[0];\r\n const b = arrFrac[1];\r\n const c = arrFrac[2];\r\n const d = arrFrac[3];\r\n if (a / b === c / d) {\r\n console.log(0);\r\n } else if (a === 0 || c === 0) {\r\n console.log(1);\r\n } else if ((a * d) % (c * b) === 0 || (c * b) % (a * d) === 0) {\r\n console.log(1);\r\n } else {\r\n console.log(2);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Main Function, code here\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n for (let i = 0; i < testCases; i++) {\r\n const arrWFrac = readline().split(\" \").map(number => parseInt(number))\r\n let numerator = arrWFrac[0] / arrWFrac[2]\r\n let denominator = arrWFrac[1] / arrWFrac [3]\r\n if (numerator === Infinity) {\r\n numerator = 0\r\n }\r\n if (!denominator || denominator === Infinity) {\r\n denominator = 0\r\n }\r\n\r\n if (numerator === denominator || isNaN(numerator)) {\r\n console.log(0)\r\n } else if (Number.isInteger(numerator) || Number.isInteger(denominator)) {\r\n console.log(1)\r\n } else {\r\n console.log(2)\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [a, b, c, d] = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n a,\n b,\n c,\n d,\n };\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { a, b, c, d } = testCase;\n\n const gcd = (e, f) => (f ? gcd(f, e % f) : e);\n\n const g1 = gcd(a, b);\n const g2 = gcd(c, d);\n\n const aa = a / g1;\n const bb = b / g1;\n const cc = c / g2;\n const dd = d / g2;\n\n const g = gcd(aa * dd, bb * cc);\n\n let result = [(aa * dd) / g, (bb * cc) / g].filter((v) => v != 1).length;\n if (aa == 0 && cc == 0) result = 0;\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [a, b, c, d] = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n a,\n b,\n c,\n d,\n };\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { a, b, c, d } = testCase;\n\n const gcd = (e, f) => (f ? gcd(f, e % f) : e);\n\n const g = gcd(a * d, b * c);\n\n let result = [(a * d) / g, (b * c) / g].filter((v) => v != 1).length;\n if (a == 0 && c == 0) result = 0;\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "c2a506d58a80a0fb6a16785605b075ca"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0], m = k[1];\n var ans = '';\n console.log(n - m + Math.floor(m / 2));\n for(j = m + 1; j <= n; j++){\n ans += j + ' ';\n }\n for(j = Math.floor((m + 1) / 2); j < m; j++){\n ans += j + ' ';\n }\n console.log(ans);\n\t}\n});\n\n", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~= 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k]) {\r\n let res = [], counter = 0\r\n counter += n - k\r\n counter += Math.floor(k / 2)\r\n console.log(counter)\r\n for (let i = k + 1; i <= n; ++i) res.push(i)\r\n for (let i = 1; i <= Math.floor(k / 2); ++i) res.push(k - i)\r\n console.log(res.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n solve(inputArr[i])\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n // var [n, k, l] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n //\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n // var a = readline().split('').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // for (let i = Math.floor(k/2); i <= n; i++) {\r\n // if(i!==k) res.push(i)\r\n // }\r\n var res = []\r\n var values = {}\r\n var btm = k % 2===1 ? Math.floor(k/2)+1 : Math.floor(k/2)\r\n for (let i = k-1; i >= btm; i--) {\r\n // var canAdd = true\r\n // Object.keys(values).map(key => {\r\n // if (parseInt(key) + i === k) canAdd = false\r\n // })\r\n // if (!canAdd || i === k) continue\r\n // Object.keys(values).map(key => {\r\n // values[parseInt(key) + i] = true\r\n // });\r\n // values[i] = true\r\n res.push(i)\r\n }\r\n for (let i = k+1; i <= n; i++) {\r\n res.push(i)\r\n }\r\n\r\n\r\n // console.log(values)\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n })\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar output = [];\r\n\t\tmyout(N - K + Math.floor(K / 2));\r\n\t\tfor(var j = K + 1; j <= N; j++){\r\n\t\t\toutput.push(j);\r\n\t\t}\r\n\t\tfor(var j = Math.floor((K + 1) / 2); j < K; j++){\r\n\t\t\toutput.push(j);\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "let lines=require('fs').readFileSync(0).toString().split('\\n'),line=0;\r\ninput=()=>lines[line++];\r\nfor(let t=+input();t--;){\r\n let [n,k]=input().split(' ').map(Number),ans=[];\r\n console.log(n-k+~~(k/2));\r\n for(let i=k+1;i<=n;i++) ans.push(i);\r\n for(let i=~~((k+1)/2);i (k - 1) / 2; j--) {\r\n arr.push(j);\r\n }\r\n for (var j = k + 1; j <= n; j++) {\r\n arr.push(j);\r\n }\r\n print(arr.length);\r\n print(arr.join(' '));\r\n }\r\n}\r\n\r\nmain();"}], "negative_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~= 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k]) {\r\n let arr = Array(n)\r\n .fill(1)\r\n .map((_, i) => i + 1)\r\n .filter(i => i !== k)\r\n if (!arr.length) return null\r\n for (let j = 0; ; j++) {\r\n let subarr = arr.filter(i => i <= k)\r\n let sum = subarr.reduce((acc, curr) => acc + curr, 0)\r\n if (sum !== k) return arr\r\n else arr.splice(arr.indexOf(subarr[subarr.length - 1]), 1)\r\n }\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n let res = solve(inputArr[i])\r\n if (res && res.length) {\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n } else console.log(0)\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~= 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k]) {\r\n let arr = Array(n)\r\n .fill(1)\r\n .map((_, i) => i + 1)\r\n .filter(i => i !== k)\r\n if (!arr.length) return null\r\n for (let j = 0; ; j++) {\r\n let sum = arr.filter(i => i <= k).reduce((acc, curr) => acc + curr, 0);\r\n if (sum !== k) return arr\r\n else arr.shift()\r\n }\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n let res = solve(inputArr[i])\r\n if (res && res.length) {\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n } else console.log(0)\r\n }\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j].split('');\n var answer = k.length;\n console.log(answer);\n }\n});"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var nk = readNumArray();\r\n var n = nk[0];\r\n var k = nk[1];\r\n var kSum = 0;\r\n var arr = [];\r\n for (var j = 1; j < k; j++) {\r\n kSum += j;\r\n if (kSum >= k) {\r\n break;\r\n }\r\n arr.push(j);\r\n }\r\n for (var j = k + 1; j <= n; j++) {\r\n arr.push(j);\r\n }\r\n print(arr.length);\r\n print(arr.join(' '));\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var nk = readNumArray();\r\n var n = nk[0];\r\n var k = nk[1];\r\n var kSum = 0;\r\n var arr = [];\r\n for (var j = 1; j < k; j++) {\r\n kSum += j;\r\n if (kSum !== k) {\r\n arr.push(j);\r\n }\r\n if (kSum >= k) {\r\n break;\r\n }\r\n }\r\n for (var j = k + 1; j <= n; j++) {\r\n arr.push(j);\r\n }\r\n print(arr.length);\r\n print(arr.join(' '));\r\n }\r\n}\r\n\r\nmain();"}], "src_uid": "d08e39db62215d7817113aaa384e3f59"} {"source_code": "var n = parseInt(readline());\n\nvar l = readline().trim().split(' ').map((x)=>parseInt(x));\n\nvar ans = 0;\n\nvar isOne = false;\nvar nbrOnes=0;\nfor(var i=0;i0)\n ans+=nbrOnes+1;\n nbrOnes=0;\n isOne = false;\n }else{\n isOne=true;\n nbrOnes++;\n }\n}\nif(l[n-1]==0)\n ans=ans==0?0:(ans-1);\nelse\n ans+=nbrOnes;\nprint(ans)", "positive_code": [{"source_code": "var n= readline();\nvar stateLetters= readline().replace(/\\s/g,\"\").replace(/0/g,\" \");\nstateLetters= stateLetters.trim();\nvar costoLettersLeidosDosOperaciones= (stateLetters.match(/\\s+1/g)|| \"\").length* 2; \nvar costoLettersLeidosUnaOperacion= (stateLetters.replace(/\\s+1/g, \"\")|| \"\").length;\nprint(costoLettersLeidosDosOperaciones+ costoLettersLeidosUnaOperacion);\n\n"}, {"source_code": ";(function () {\n\tprint(function (n, s) {\n\t\tvar t = 0, q = false;\n\n\t\tfor (var i = 0; i < n; i++ ) {\n\t\t\tif (s[i] === '1') {\n\t\t\t\tt++;\n\t\t\t\tq = true;\n\t\t\t} else if (q) {\n\t\t\t\tt++;\n\t\t\t\tq = false;\n\t\t\t}\n\t\t}\n\n\t\tif (!q && t > 0) t--;\n\n\t\treturn t;\n\t}(+readline(), readline().split(' ')));\n}.call(this));"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n\tthis.dp = function( i , fl ) {\n\t\tif( i >= this.n ) {\n\t\t\treturn 0 ;\n\t\t}\n\t\tvar ret , res , re , r1 , a ;\n\t\tret = this.memo[ i ][ fl ] ;\n\t\tre = this.done[ i ][ fl ] ;\n\t\tif( re == this.cc ) {\n\t\t\treturn ret ;\n\t\t}\n\t\tthis.done[ i ][ fl ] = this.cc ;\n\t\tres = ( 1 << 29 ) ;\n\t\tif( fl == 0 ) {\n\t\t\tif( this.arr[ i ] == 0 ) {\n\t\t\t\tr1 = this.dp( i + 1 , 0 ) ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tr1 = this.dp( i + 1 , 1 ) + 1 ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t\ta = 2 ;\n\t\t\t\tif( this .brr[ i + 1 ] == 0 ) {\n\t\t\t\t\ta = 1 ;\n\t\t\t\t}\n\t\t\t\tr1 = this.dp( i + 1 , 0 ) + a ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif( this.arr[ i ] == 0 ) {\n\t\t\t\ta = 2 ;\n\t\t\t\tif( this .brr[ i + 1 ] == 0 ) {\n\t\t\t\t\ta = 1 ;\n\t\t\t\t}\n\t\t\t\tr1 = this.dp( i + 1 , 0 ) + a ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tr1 = this.dp( i + 1 , 1 ) + 1 ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t\ta = 2 ;\n\t\t\t\tif( this .brr[ i + 1 ] == 0 ) {\n\t\t\t\t\ta = 1 ;\n\t\t\t\t}\n\t\t\t\tr1 = this.dp( i + 1 , 0 ) + a ;\n\t\t\t\tres = Math.min( res , r1 ) ;\n\t\t\t}\n\t\t}\n\t\treturn this.memo[ i ][ fl ] = res ;\n\t};\n\t\n this.solveCase = function() {\n var res , i , j , fl , cn , temp ;\n for( i = this.n - 1 ; i >= 0 ; i-- ) {\n \tif( i == this.n - 1 ) {\n \t\tthis.brr[ i ] = this.arr[ i ] ;\n \t}\n \telse {\n \t\tthis.brr[ i ] = this.brr[ i + 1 ] + this.arr[ i ] ;\n \t}\n }\n res = this.dp( 0 , 0 ) ;\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 1010;\n this.lim2 = 3;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n \tvar i ;\n \tfor( i = 0 ; i < this.lim1 ; i++ ) {\n \t\tthis.brr[ i ] = 0 ;\n \t}\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var n = Number(readline()),\n letters = readline().split(' ');\n \n// var n = Number(\"5\"),\n// letters = \"0 0\".split(' ');\n\n \nfunction solver() {\n var operationsCount = 0,\n inTheList = true,\n inALetter = false,\n isNextUnread = false,\n readSoFar = 0,\n totalLetters = letters.reduce(function (a, b) {\n return Number(a) + Number(b);\n });\n \n for (var i = 0; i < letters.length; i++) {\n if (letters[i] === \"1\") {\n readSoFar++;\n if (inTheList || (isNextUnread && inALetter)) {\n operationsCount++;\n }\n \n inALetter = true;\n inTheList = false;\n \n if (i + 1 < letters.length) {\n if (letters[i + 1] == \"1\") {\n isNextUnread = true;\n } else {\n isNextUnread = false;\n inTheList = true;\n \n if (readSoFar < totalLetters) {\n operationsCount++;\n }\n inALetter = false;\n }\n }\n }\n }\n \n return operationsCount;\n}\n\nprint(solver());\n// console.log(solver());"}, {"source_code": "n = readline();\nlist = readline().split(' ').map(Number);\nnum = 0;\ni = list.indexOf(1);\nif (i != -1) {\nwhile (i < list.length){\n\tnum++;\n\tlist[i]=2;\n\tif (list[i+1] == 1){\n\t\ti++;\n\t}\n\telse {\n\t\tif (list.indexOf(1) == -1){\n\t\t\ti = list.length;\n\t\t}\n\t\telse {\n\t\t\ti = list.indexOf(1);\n\t\t\tnum++;\n\t\t}\n\t}\n\t}\n}\nprint(num);\n"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tarr = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/),\n\t\t\tclick = 0, goList = false;\n\t\t\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tif(arr[i] == 1)\t{\n\t\t\t\tclick++;\n\t\t\t\tgoList = false;\n\n\t\t\t\tif(arr[i + 1] == 0)\t{\n\t\t\t\t\tclick++;\n\t\t\t\t\tgoList = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(goList)\tclick--;\n\n\t\t//console.log(bits, count);\n\n\t\tprint(click);"}, {"source_code": "readline(); // not needed\n\nprint(readline().split(' ').map(function (x) {\n return parseInt(x);\n}).reduce(function (p, x) {\n if (x || p[1]) {\n p[0]++;\n }\n p[1] = x;\n return p;\n}, [0, 0]).reduce(function (s, r) {\n if (s && !r) {\n s--;\n }\n return s;\n}));"}], "negative_code": [], "src_uid": "0fbc306d919d7ffc3cb02239cb9c2ab0"} {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n \n var n = parseInt(readline());\n print(2);\n // if (n <= 3) {\n // if (n != 3) print(1 + ' ' + 2);\n // else {\n // print(1 + ' ' + 3);\n // print(2 + ' ' + 2);\n // }\n // }\n // else {\n // var nn = n;\n // var m = n - 2;\n // print(m + ' ' + nn);\n // print(nn - 1 + ' ' + nn - 1);\n // nn--;\n // m--;\n // while (m > 0) {\n // print(m + ' ' + nn);\n // nn--;\n // m--;\n // }\n // }\n for (var i = n - 1; i >= 1; i--){\n print(i + ' ' + Math.min(n, i + 2));\n }\n}\n ", "positive_code": [{"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var n = parseInt(readline());\n if(n===2)\n {\n print(\"2\");\n print(n , \" \", n -1);\n continue;\n }\n print(\"2\");\n print(n , \" \", n -2);\n print(n-1 , \" \", n -1);\n for (var j = n-1; j >= 3; j--) {\n print(j , \" \" , j - 2);\n }\n}\n"}, {"source_code": "\nfunction solv() {\n var x = parseInt(readline())\n var res = [];\n var cur = x;\n var pv = x - 1;\n for (var n = 0; n < x - 1; n++) {\n res.push([cur, pv]);\n cur = Math.ceil((cur + pv) / 2);\n pv--;\n }\n print(cur);\n for (n in res) {\n print(res[n][0], res[n][1])\n }\n}\n\nvar tc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n const arr = [];\n for (let i = 1; i <= num; i++) arr.push(i);\n\n console.log(2);\n for (let i = 0; i < num - 1; i++) {\n const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];\n console.log(`${a} ${b}`);\n arr.pop();\n arr.pop();\n const avg = Math.ceil((a + b) / 2);\n arr.push(avg);\n }\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = $()\n while (t--) {\n let n = $(), c = n;\n out.push(2)\n ForR(n - 1, 1, i => {\n out.push(`${c} ${i}`)\n c = Math.round((c + i) / 2);\n })\n }\n log(out.join('\\n'))\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = 0;\n let b = 0;\n let c = 0;\n let isFound = false;\n for(let i = 0; i <= Math.floor(n/3); i++){\n if(isFound)\n break;\n if(3*i > n)\n break;\n else if(3*i === n){\n a = i;\n isFound = true;\n break;\n }\n for(let j = 0; j <= Math.floor(n/5); j++){\n if(isFound)\n break;\n if(3*i + 5*j > n)\n break;\n else if(3*i + 5*j === n){\n a = i; b = j;\n isFound = true;\n break;\n }\n for(let k = 0; k <= Math.floor(n/7); k++){\n if(3*i + 5*j + 7*k === n){\n a = i; b = j; c = k;\n isFound = true;\n break;\n }else if(3*i + 5*j + 7*k > n){\n break;\n }\n }\n }\n }\n\n if(isFound)\n console.log(a,b,c)\n else\n console.log(-1);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n a.sort((a,b) => b-a);\n\n let d = 0;\n for(let i = 0; i < k; i++){\n if(i < n){\n d += a[i];\n }else{\n break;\n }\n }\n\n if(k < n)\n console.log(d+a[k]);\n else\n console.log(d);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let ans = [];\n let curr = n-1;\n let last = n;\n let i = 0;\n while(i < n-1 && curr > 0){\n ans.push([curr, last]);\n last = Math.ceil((last+curr)/2);\n curr = curr-1;\n i++;\n }\n console.log(last);\n for(let item of ans){\n console.log(item[0], item[1]);\n }\n }\n}"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n const arr = [];\n for (let i = 1; i <= num; i++) arr.push(i);\n\n console.log(num - 1);\n for (let i = 0; i < num - 1; i++) {\n const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];\n console.log(`${a} ${b}`);\n arr.pop();\n arr.pop();\n const avg = Math.ceil((a + b) / 2);\n arr.push(avg);\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n let [same, n, first] = [false, num, true];\n\n for (let i = 0; i < num - 1; i++) {\n if (same) {\n console.log(`${n} ${n}`);\n } else {\n if (first) {\n let other = n - 2;\n if (other <= 0) other = n - 1;\n console.log(`${n} ${other}`);\n n = Math.floor((n + other) / 2);\n first = false;\n } else {\n let other = n - 3;\n if (n - 3 <= 0) other = n - 2;\n\n console.log(`${n} ${other}`);\n n = Math.floor((n + other) / 2);\n }\n }\n same = !same;\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const num = +readLine();\n const arr = [];\n for (let i = 1; i <= num; i++) arr.push(i);\n\n for (let i = 0; i < num - 1; i++) {\n const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];\n console.log(`${a} ${b}`);\n arr.pop();\n arr.pop();\n const avg = Math.ceil((a + b) / 2);\n arr.push(avg);\n }\n }\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var n = parseInt(readline());\n print(\"2\");\n print(n + \" \" + n - 1);\n for (var j = n; j >= 3; j--) {\n print(j + \" \" + j - 2);\n }\n}\n\nfunction solve(nu) {\n print(\"2\");\n print(nu + \" \" + nu - 1);\n for (var j = nu; j >= 3; j--) {\n print(j + \" \" + j - 2);\n }\n}\n"}], "src_uid": "591372383cf3624f69793c41370022de"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar tokens = tokenize(readline()),\n\t\ta10 = parseInt(tokens[0]), b = tokens[1],\n\t\tc = trim(readline()),\n\t\tdigits = '0123456789ABCDEFGHIJKLMNO',\n\t\tdigit2value = {}, value2digit = {};\n\tfor (var i = 0; i < 25; ++i) {\n\t\tdigit = digits.charAt(i);\n\t\tdigit2value[digit] = i;\n\t\tvalue2digit[i] = digit;\n\t}\n\tvar c10 = 0;\n\tfor (var i = 0; i < c.length; ++i) {\n\t\tc10 = a10*c10 + digit2value[c.charAt(i)];\n\t}\n\tfunction roman(x) {\n\t\tif (x >= 1000) {\n\t\t\treturn 'M'+roman(x-1000);\n\t\t} else if (x >= 900) {\n\t\t\treturn 'CM'+roman(x-900);\n\t\t} else if (x >= 500) {\n\t\t\treturn 'D'+roman(x-500);\n\t\t} else if (x >= 400) {\n\t\t\treturn 'CD'+roman(x-400);\n\t\t} else if (x >= 100) {\n\t\t\treturn 'C'+roman(x-100);\n\t\t} else if (x >= 90) {\n\t\t\treturn 'XC'+roman(x-90);\n\t\t} else if (x >= 50) {\n\t\t\treturn 'L'+roman(x-50);\n\t\t} else if (x >= 40) {\n\t\t\treturn 'XL'+roman(x-40);\n\t\t} else if (x >= 10) {\n\t\t\treturn 'X'+roman(x-10);\n\t\t} else if (x >= 9) {\n\t\t\treturn 'IX'+roman(x-9);\n\t\t} else if (x >= 5) {\n\t\t\treturn 'V'+roman(x-5);\n\t\t} else if (x >= 4) {\n\t\t\treturn 'IV'+roman(x-4);\n\t\t} else if (x >= 1) {\n\t\t\treturn 'I'+roman(x-1);\n\t\t} else {\n\t\t\treturn '';\n\t\t}\n\t}\n\tif (b == 'R') {\n\t\tprint(roman(c10));\n\t} else {\n\t\tif (c10 == 0) {\n\t\t\tprint('0');\n\t\t\treturn;\n\t\t}\n\t\tvar x = c10, parts = [];\n\t\twhile (x != 0) {\n\t\t\tvar value = x%b;\n\t\t\tparts.push(value2digit[value]);\n\t\t\tx = (x-value)/b;\n\t\t}\n\t\tprint(parts.reverse().join(''));\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar tokens = tokenize(readline()),\n\t\ta10 = parseInt(tokens[0]), b = tokens[1],\n\t\tc = trim(readline()),\n\t\tdigits = '0123456789ABCDEFGHIJKLMNO',\n\t\tdigit2value = {}, value2digit = {};\n\tfor (var i = 0; i < 25; ++i) {\n\t\tdigit = digits.charAt(i);\n\t\tdigit2value[digit] = i;\n\t\tvalue2digit[i] = digit;\n\t}\n\tvar c10 = 0;\n\tfor (var i = 0; i < c.length; ++i) {\n\t\tc10 = a10*c10 + digit2value[c.charAt(i)];\n\t}\n\tvar romanValues = { M: 1000, C: 100, D: 500, L: 50, X: 10, V: 5, I: 1 },\n\t\tromanList = [ { main: 'M', sub: 'C' },\n\t\t\t\t\t { main: 'D', sub: 'C' },\n\t\t\t\t\t { main: 'C', sub: 'X' },\n\t\t\t\t\t { main: 'L', sub: 'X' },\n\t\t\t\t\t { main: 'X', sub: 'I' },\n\t\t\t\t\t { main: 'V', sub: 'I' } ];\n\tfunction roman(x) {\n\t\tfor (var i = 0; i < romanList.length; ++i) {\n\t\t\tvar mainChar = romanList[i].main, mainValue = romanValues[mainChar],\n\t\t\t\tsubChar = romanList[i].sub, subValue = romanValues[subChar];\n\t\t\tif (x >= mainValue) {\n\t\t\t\treturn mainChar + roman(x-mainValue);\n\t\t\t} else if (x >= mainValue-subValue) {\n\t\t\t\treturn subChar + mainChar + roman(x-mainValue+subValue);\n\t\t\t}\n\t\t}\n\t\tif (x >= 1) {\n\t\t\treturn 'I' + roman(x-1);\n\t\t}\n\t\treturn '';\n\t}\n\tif (b == 'R') {\n\t\tprint(roman(c10));\n\t} else {\n\t\tif (c10 == 0) {\n\t\t\tprint('0');\n\t\t\treturn;\n\t\t}\n\t\tvar x = c10, parts = [];\n\t\twhile (x != 0) {\n\t\t\tvar value = x%b;\n\t\t\tparts.push(value2digit[value]);\n\t\t\tx = (x-value)/b;\n\t\t}\n\t\tprint(parts.reverse().join(''));\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar tokens = tokenize(readline()),\n\t\ta10 = parseInt(tokens[0]), b = tokens[1],\n\t\tc = trim(readline()),\n\t\tdigits = '0123456789ABCDEFGHIJKLMNO',\n\t\tdigit2value = {}, value2digit = {};\n\tfor (var i = 0; i < 25; ++i) {\n\t\tdigit = digits.charAt(i);\n\t\tdigit2value[digit] = i;\n\t\tvalue2digit[i] = digit;\n\t}\n\tvar c10 = 0;\n\tfor (var i = 0; i < c.length; ++i) {\n\t\tc10 = a10*c10 + digit2value[c.charAt(i)];\n\t}\n\tvar romanValues = { M: 1000, C: 100, L: 50, X: 10, V: 5, I: 1 },\n\t\tromanList = [ { main: 'M', sub: 'C' },\n\t\t\t\t\t { main: 'C', sub: 'X' },\n\t\t\t\t\t { main: 'L', sub: 'X' },\n\t\t\t\t\t { main: 'X', sub: 'I' },\n\t\t\t\t\t { main: 'V', sub: 'I' } ];\n\tfunction roman(x) {\n\t\tfor (var i = 0; i < romanList.length; ++i) {\n\t\t\tvar mainChar = romanList[i].main, mainValue = romanValues[mainChar],\n\t\t\t\tsubChar = romanList[i].sub, subValue = romanValues[subChar];\n\t\t\tif (x >= mainValue) {\n\t\t\t\treturn mainChar + roman(x-mainValue);\n\t\t\t} else if (x >= mainValue-subValue) {\n\t\t\t\treturn subChar + mainChar + roman(x-mainValue+subValue);\n\t\t\t}\n\t\t}\n\t\tif (x >= 1) {\n\t\t\treturn 'I' + roman(x-1);\n\t\t}\n\t\treturn '';\n\t}\n\tif (b == 'R') {\n\t\tprint(roman(c10));\n\t} else {\n\t\tif (c10 == 0) {\n\t\t\tprint('0');\n\t\t\treturn;\n\t\t}\n\t\tvar x = c10, parts = [];\n\t\twhile (x != 0) {\n\t\t\tvar value = x%b;\n\t\t\tparts.push(value2digit[value]);\n\t\t\tx = (x-value)/b;\n\t\t}\n\t\tprint(parts.reverse().join(''));\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar tokens = tokenize(readline()),\n\t\ta10 = parseInt(tokens[0]), b = tokens[1],\n\t\tc = trim(readline()),\n\t\tdigits = '0123456789ABCDEFGHIJKLMNO',\n\t\tdigit2value = {}, value2digit = {};\n\tfor (var i = 0; i < 25; ++i) {\n\t\tdigit = digits.charAt(i);\n\t\tdigit2value[digit] = i;\n\t\tvalue2digit[i] = digit;\n\t}\n\tvar c10 = 0;\n\tfor (var i = 0; i < c.length; ++i) {\n\t\tc10 = a10*c10 + digit2value[c.charAt(i)];\n\t}\n\tfunction roman(x) {\n\t\tif (x >= 1000) {\n\t\t\treturn 'M'+roman(x-1000);\n\t\t} else if (x >= 900) {\n\t\t\treturn 'CM'+roman(x-900);\n\t\t} else if (x >= 500) {\n\t\t\treturn 'D'+roman(x-500);\n\t\t} else if (x >= 400) {\n\t\t\treturn 'CD'+roman(x-400);\n\t\t} else if (x >= 100) {\n\t\t\treturn 'C'+roman(x-100);\n\t\t} else if (x >= 90) {\n\t\t\treturn 'XC'+roman(x-90);\n\t\t} else if (x >= 50) {\n\t\t\treturn 'L'+roman(x-50);\n\t\t} else if (x >= 40) {\n\t\t\treturn 'XL'+roman(x-40);\n\t\t} else if (x >= 10) {\n\t\t\treturn 'X'+roman(x-10);\n\t\t} else if (x >= 9) {\n\t\t\treturn 'IX'+roman(x-9);\n\t\t} else if (x >= 5) {\n\t\t\treturn 'V'+roman(x-5);\n\t\t} else if (x >= 4) {\n\t\t\treturn 'IV'+roman(x-4);\n\t\t} else if (x >= 1) {\n\t\t\treturn 'I'+roman(x-1);\n\t\t} else {\n\t\t\treturn '';\n\t\t}\n\t}\n\tif (b == 'R') {\n\t\tprint(roman(c10));\n\t} else {\n\t\tvar x = c10, parts = [];\n\t\twhile (x != 0) {\n\t\t\tvar value = x%b;\n\t\t\tparts.push(value2digit[value]);\n\t\t\tx = (x-value)/b;\n\t\t}\n\t\tprint(parts.reverse().join(''));\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar tokens = tokenize(readline()),\n\t\ta10 = parseInt(tokens[0]), b = tokens[1],\n\t\tc = trim(readline()),\n\t\tdigits = '0123456789ABCDEFGHIJKLMNO',\n\t\tdigit2value = {}, value2digit = {};\n\tfor (var i = 0; i < 25; ++i) {\n\t\tdigit = digits.charAt(i);\n\t\tdigit2value[digit] = i;\n\t\tvalue2digit[i] = digit;\n\t}\n\tvar c10 = 0;\n\tfor (var i = 0; i < c.length; ++i) {\n\t\tc10 = a10*c10 + digit2value[c.charAt(i)];\n\t}\n\tvar romanValues = { M: 1000, C: 100, L: 50, X: 10, V: 5, I: 1 },\n\t\tromanList = [ { main: 'M', sub: 'C' },\n\t\t\t\t\t { main: 'C', sub: 'X' },\n\t\t\t\t\t { main: 'L', sub: 'X' },\n\t\t\t\t\t { main: 'X', sub: 'I' },\n\t\t\t\t\t { main: 'V', sub: 'I' } ];\n\tfunction roman(x) {\n\t\tfor (var i = 0; i < romanList.length; ++i) {\n\t\t\tvar mainChar = romanList[i].main, mainValue = romanValues[mainChar],\n\t\t\t\tsubChar = romanList[i].sub, subValue = romanValues[subChar];\n\t\t\tif (x >= mainValue) {\n\t\t\t\treturn mainChar + roman(x-mainValue);\n\t\t\t} else if (x >= mainValue-subValue) {\n\t\t\t\treturn subChar + mainChar + roman(x-mainValue-subValue);\n\t\t\t}\n\t\t}\n\t\treturn '';\n\t}\n\tif (b == 'R') {\n\t\tprint(roman(c10));\n\t} else {\n\t\tif (c10 == 0) {\n\t\t\tprint('0');\n\t\t\treturn;\n\t\t}\n\t\tvar x = c10, parts = [];\n\t\twhile (x != 0) {\n\t\t\tvar value = x%b;\n\t\t\tparts.push(value2digit[value]);\n\t\t\tx = (x-value)/b;\n\t\t}\n\t\tprint(parts.reverse().join(''));\n\t}\n}\n\nmain();\n"}], "src_uid": "c619d699e3e5fb42aea839ef6080c86c"} {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var num = parseInt(readline());\n print(num%2==0 ? parseInt(num/2) : parseInt(num/2)+1);\n}\n", "positive_code": [{"source_code": "function solve() {\n var n = Number(read());\n write(Math.floor((n + 1) / 2));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var Tc = parseInt(readline());\nwhile (Tc-- > 0) {\n var n = parseInt(readline());\n print(Math.floor((n + 1) / 2));\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var T = readline();\n\n while (T-- > 0) {\n let n = readline();\n\n let res = 1 + parseInt((n - 1) / 2);\n\n console.log(res);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let n = +readLine();\n if (n % 2 === 0) {\n console.log(Math.floor(n / 2));\n } else {\n console.log(Math.floor(n / 2) + 1);\n }\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\toutput[i] = Math.ceil(n / 2);\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let n = data[i] * 1;\n console.log(Math.ceil(n / 2));\n i += 1;\n }\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet t = -1;\n\nrl.on('line', (input) => {\n if (t === -1) {\n t = parseInt(input);\n } else {\n let tmp = parseInt(input);\n console.log(tmp % 2 === 0 ? tmp / 2 : tmp / 2 + 0.5);\n }\n})"}, {"source_code": "const process = require('process');\n \nlet inp = \"\";\nprocess.stdin.on('data', chunk => inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n let ic = 0;\n let ntest = +inp[ic++];\n for (let testcase = 0; testcase < ntest; ++testcase) {\n let n = +inp[ic++];\n console.log(Math.floor((n + 1) / 2));\n }\n\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(s2i(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n\n out += Math.ceil(n/2) + '\\n'\n }\n console.log(out)\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4 3\n1 2 1 3\n10 6\n8 7 1 8 3 7 5 10 8 9\n5 10\n20 100 50 20 100500\n10 25\n24 24 24 24 24 24 24 24 24 24\n8 8\n1 2 3 4 5 6 7 8\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = parseInt(readline());\n\n for(let r=0;r inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split(/\\s/);\n let ic = 0;\n let ntest = +inp[ic++];\n for (let testcase = 0; testcase < ntest; ++testcase) {\n let n = +inp[ic++];\n console.log(Math.floor((n + 1) / 2));\n }\n\n});\n"}], "src_uid": "ec89860dacb5a11b3a2273d2341b07a1"} {"source_code": "var readline = require('readline')\nvar k=0\nvar n=0;\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', (answer) => {\n n= answer\n rl.question('', (answer) => {\n x=answer.split(' ')\n for (var i = (n-1);i>=0;i--) {\n if(Number(x[i])<0) x[i] = 0\n if(Number(x[i-1])>Number(x[i]) || Number(x[i-1])==Number(x[i])) {\n x[i-1] = Number(x[i])-1\n }\n }\n x.forEach(function(i) {\n k+=+i\n })\n console.log(k)\n rl.close()\n })\n})\n", "positive_code": [{"source_code": "var n=readline();\nvar a=readline().split(\" \");\na=a.slice(0,n);\nvar curV=1000000001;\nvar res=0;\nfor(var i=n-1; i>=0; --i){\n curV=Math.max(0,Math.min(a[i],curV-1));\n res+=curV;\n}\nprint(res);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst s = (yield).trim().split(\" \").map(Number);\n\trl.close();\n\tlet x = y = s[n - 1];\n\tfor (let i = n - 2; i >= 0; i--) {\n\t\tif (y < 2) break;\n\t\ty = Math.min(s[i], y - 1);\n\t\tx += y;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar curV=1000000001;\nvar res=0;\nfor(var i=n-1; i>=0; --i ){\n curV=Math.max(0,Math.min(curV-1, a[i]));\n res+=curV;\n}\nprint(res);"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst s = (yield).trim().split(\" \").map(Number);\n\trl.close();\n\tlet x = 0;\n\tlet y = Infinity;\n\tfor (let i = n - 1; i >= 0; i--) {\n\t\tif (s[i] < 2) {\n\t\t\tif (y > 1) x += s[i];\n\t\t\tbreak;\n\t\t}\n\t\ty = Math.min(s[i], y - 1);\n\t\tx += y;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst s = (yield).trim().split(\" \").map(Number);\n\trl.close();\n\tlet x = 0;\n\tlet y = Infinity;\n\tfor (let i = n - 1; i >= 0; i--) {\n\t\tif (s[i] < 2) {\n\t\t\tif (y > 1) x += s[i];\n\t\t\tbreak;\n\t\t}\n\t\ty = Math.max(s[i], y - 1);\n\t\tx += y;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst s = (yield).trim().split(\" \").map(Number);\n\trl.close();\n\tlet x = 0;\n\tlet y = Infinity;\n\tfor (let i = n - 1; i >= 0; i--) {\n\t\tif (s[i] < 2) {\n\t\t\tx += s[i];\n\t\t\tbreak;\n\t\t}\n\t\ty = Math.min(s[i], y - 1);\n\t\tx += y;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst s = (yield).trim().split(\" \").map(Number);\n\trl.close();\n\tlet x = y = s[n - 1];\n\tfor (let i = n - 2; i >= 0; i--) {\n\t\tconsole.log('iteration', n - i,': y =', y);\n\t\tif (y < 2) break;\n\t\ty = Math.min(s[i], y - 1);\n\t\tx += y;\n\t}\n\tconsole.log(x)\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\nvar x = [];\nvar flag = false;\nif(n<1 || n>200000) exit();\n\nfor(var i=0; i=a[j]) flag = true;\n }\n if(flag) x.push(0);\n else x.push(Number(a[i]));\n\n flag = false;\n}\nprint(x.reduce((a,b) => a+b));"}, {"source_code": "var n = 5;\nvar a = \"3 2 5 4 10\".split(' ');\nvar x = [];\nvar flag = false;\nif(n<1 || n>200000) exit();\n\nfor(var k=0; ka+b));"}], "src_uid": "5993b5bf231fabd3c2af90124c41f118"} {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n for (let i = 29; i >= 0; i--) {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n // log(i, dau, cuoi, s, s1, idau, icuoi);\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n // log(a, b, c);\n [a, b] = [b, a];\n }\n\n log(sum, x);\n}", "positive_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n// Array.prototype.rev = function (first, last) {\n// // for (let i = first; i < (first + last) / 2; i++) [this[i],this[last-]]\n// }\nArray.prototype.merge = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0, y = [].splice()\n for (let i = 29; i >= 0; i--) {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n b.merge(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n }\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n For(29, 0, -1, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n b.rev(idau, cuoi);\n // b.merge(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n ForR(29, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n if (dau >= n) break;\n cuoi = For(dau + 1, n - 1, i => c[i] != c[i - 1] ? i : null) || n;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n a.for(dau, cuoi - 1, v => {\n if (v & (1 << i)) { s1++; b[--icuoi] = v; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = v };\n })\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n b.rev(idau, cuoi);\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else sum += ss0;\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.merge = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = Float64Array.from($(n)), b = a.slice(), c = a.slice().fill(0), x = 0, sum = 0\n For(29, 0, -1, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n // b.rev(idau, cuoi);\n b.subarray(idau, cuoi).reverse();\n // b.merge(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n For(29, 0, -1, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n // b.rev(idau, cuoi);\n b.set(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.merge = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = Int32Array.from($(n)), b = a.slice(), c = a.slice().fill(0), x = 0, sum = 0\n For(29, 0, -1, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n // b.rev(idau, cuoi);\n b.subarray(idau, cuoi).reverse()\n // b.merge(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n for (let i = a; i <= b; i++) fn(this[i], i, this);\n}\nArray.prototype.forR = function (a, b, fn) {\n for (let i = a; i >= b; i--) fn(this[i], i, this);\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n For(29, 0, -1, i => {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n a.for(dau, cuoi - 1, v => {\n if (v & (1 << i)) { s1++; b[--icuoi] = v; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = v };\n })\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n b.rev(idau, cuoi);\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n })\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), t = [a], x = 0, sum = 0\n for (let i = 29; i >= 0; i--) {\n let nt = [];\n let ss = 0, ss0 = 0, ss1 = 0;\n t.forEach(ta => {\n let nt0 = [], nt1 = []\n let s1 = 0, s = 0;\n ta.forEach(v => {\n if (v & (1 << i)) { s1++; nt1.push(v) }\n else { s += s1; nt0.push(v) };\n });\n ss0 += s;\n ss1 += s1 * (ta.length - s1) - s;\n ss += s1 * (ta.length - s1) - s - s;\n if (nt0.length) nt.push(nt0)\n if (nt1.length) nt.push(nt1)\n })\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n t = nt;\n }\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.merge = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0, y = [].splice()\n for (let i = 29; i >= 0; i--) {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n b.rev(idau, cuoi);\n // b.merge(idau, b.slice(idau, cuoi).reverse())\n // for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n [a, b] = [b, a];\n }\n\n log(sum, x);\n}"}], "negative_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), b = Array(n), c = Array(n).fill(0), x = 0, sum = 0\n for (let i = 3; i >= 0; i--) {\n let dau = 0, cuoi;\n let ss = 0, ss0 = 0, ss1 = 0;\n while (1) {\n while (dau < n && c[dau] == c[dau - 1]) dau++;\n if (dau >= n) break;\n cuoi = dau + 1;\n while (cuoi < n && c[cuoi] == c[cuoi - 1]) cuoi++;\n let idau = dau;\n let icuoi = cuoi;\n let s1 = 0, s = 0;\n for (let j = dau; j < cuoi; j++) {\n if (a[j] & (1 << i)) { s1++; b[--icuoi] = a[j]; c[icuoi] += (1 << i) }\n else { s += s1; b[idau++] = a[j] };\n }\n // log(i, dau, cuoi, s, s1, idau, icuoi);\n ss0 += s;\n ss1 += s1 * ((cuoi - dau) - s1) - s;\n ss += s1 * ((cuoi - dau) - s1) - s - s;\n dau = cuoi;\n for (let j = idau; j < (cuoi + idau) / 2; j++) [b[j], b[cuoi - 1 - j + idau]] = [b[cuoi - 1 - j + idau], b[j]]\n }\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n // log(a, b, c);\n [a, b] = [b, a];\n }\n\n log(sum, x);\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), t = [a], x = 0, sum = 0\n for (let i = 29; i >= 0; i--) {\n let nt = [];\n let ss0 = 0, ss1 = 0, ss = 0;\n t.forEach(ta => {\n let nt0 = [], nt1 = []\n let s1 = 0, s = 0;\n ta.forEach(v => {\n if (v & (1 << i)) { s1++; nt1.push(v) }\n else { s += s1; nt0.push(v) };\n });\n ss0 += s;\n ss1 += s1 * (ta.length - s1) - s;\n ss += ss1 - ss0;\n if (nt0.length) nt.push(nt0)\n if (nt1.length) nt.push(nt1)\n })\n if (ss < 0) {\n x += (1 << i);\n sum += ss1\n } else {\n sum += ss0\n }\n t = nt;\n }\n\n log(sum, x);\n}"}], "src_uid": "1e6d7ec8023eb0dc482b1f133e5dfe2a"} {"source_code": "const process = require('process');\n \nlet inp = \"\";\nprocess.stdin.on('data', chunk => inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n let ic = 0;\n for (let ntest = +inp[ic++]; ntest--; ) {\n let [a, b, n, m] = inp[ic++].split(' ').map(BigInt);\n if (n + m > a + b) {\n console.log(\"No\");\n continue;\n }\n if (m > (a < b ? a : b)) {\n console.log(\"No\");\n continue;\n }\n console.log(\"Yes\");\n }\n});\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const [a, b, n, m] = readLineOfBigInts()\n // a = vainilla\n // b = chocolate\n // n = tipo 1\n // m = tipo 2\n let v = a, c = b, t1 = n, t2 = m\n\n let result = 'Yes'\n\n if (v + c < t1 + t2) {\n // M\u00e1s invitados que galletas\n result = 'No'\n } else if (v - c > t1) {\n // siempre v > c\n // t1 siempre come vainilla, t2 siempre come chocolate\n if (c < t2) {\n result = 'No'\n }\n } else if (c - v >= t1) {\n // siempre v <= c\n // t1 siempre come chocolate, t2 siempre come vainilla\n if (v < t2) {\n result = 'No'\n }\n } else {\n // t1 come galletas hasta que v == c\n if (v > c) {\n t1 -= v - c\n v = c\n } else {\n t1 -= c - v\n c = v\n }\n\n if (t2 > v && t1 < t2) {\n result = 'No'\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "function f(a, b, n, m) {\n if (a >= m && b >= m) {\n return true;\n }\n return false;\n}\n\nfunction solve() {\n var abnm = read().split(' ').map(BigInt);\n var a = abnm[0];\n var b = abnm[1];\n var n = abnm[2];\n var m = abnm[3];\n if (f(a, b, n, m) && a + b >= n + m) {\n write('yes');\n } else {\n write('no');\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "function f(a, b, n, m) {\n if (a >= m && b >= m) {\n return true;\n }\n if (a >= b && a - n <= b && b + 1n >= m) {\n return true;\n }\n return false;\n}\n\nfunction solve() {\n var abnm = read().split(' ').map(BigInt);\n var a = abnm[0];\n var b = abnm[1];\n var n = abnm[2];\n var m = abnm[3];\n if (f(a, b, n, m) && a + b >= n + m) {\n write('yes');\n } else {\n write('no');\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "src_uid": "0f960d19e576b7421a7c7a7166a884ea"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var \u0445 = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var a = new Array(n + 1).fill(0)\r\n\r\n var [p, a, b, c] = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n })\r\n var aa = (p + a - 1n) / a * a - p\r\n var bb = (p + b - 1n) / b * b - p\r\n var cc = (p + c - 1n) / c * c - p\r\n var min = aa < bb ? aa : bb\r\n min = cc < min ? cc : min\r\n return console.log(min.toString())\r\n // console.log(n, k)\r\n for (var i = 1; i <= n; i++) {\r\n count[a[i]] = Math.max(count[a[i]], i - last[a[i]])\r\n last[a[i]] = i\r\n }\r\n\r\n for (var i = 1; i <= n; i++) {\r\n var max = Math.max(count[i], n - last[i] + 1)\r\n for (var j = max; j <= n && ans[j] === -1; j++) {\r\n ans[j] = i\r\n }\r\n }\r\n\r\n // console.log(count)\r\n // console.log(a)\r\n console.log(ans.slice(1).join(' '))\r\n // console.log(map)\r\n // console.log(a)\r\n })\r\n}\r\n\r\n", "positive_code": [{"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\n// const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\n// const bigIntCeil = (a) => {\n// if (a % BigInt(1) === BigInt(0)) return a;\n// return (a + BigInt(1)) % BigInt(1);\n// };\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n function calculateMin(swim) {\n if (min % swim === BigInt(0)) return BigInt(0);\n\n let top = (min / swim) * swim;\n\n while (top < min) {\n top += swim;\n }\n\n return top - min;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(String(result));\n });\n}\n"}, {"source_code": "const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\nconst processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i BigInt(x))\n let min = bigIntMin(p%a === 0n ? 0 : a - p%a, p%b === 0n ? 0 : b - p%b, p%c === 0n? 0 : c - p%c)\n console.log(min.toString(10))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = Number(readline());\r\n while(t--) {\r\n let [p, a, b, c] = readline().split(\" \").map(num => BigInt(num));\r\n let [ra, rb, rc] = [a, b, c];\r\n \r\n if(a > p) ra -= p;\r\n else if(a < p) ra = div(p, ra) * ra - p;\r\n \r\n if(b > p) rb -= p;\r\n else if(b < p) rb = div(p, rb) * rb - p;\r\n \r\n if(c > p) rc -= p;\r\n else if(c < p) rc = div(p, rc) * rc - p; \r\n \r\n if(a === p || b === p || c === p) console.log(0);\r\n else console.log(String(min(ra, min(rb, rc))));\r\n }\r\n}\r\n\r\nfunction div(dividened, quotient) {\r\n if(dividened % quotient === 0n) return (dividened/quotient);\r\n return ((dividened/quotient) + 1n);\r\n}\r\n\r\nfunction min(num1, num2) {\r\n let ans;\r\n if(num1 === num2 || num1 < num2) return num1;\r\n if(num2 < num1) return num2;\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\n// const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\n// const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\n// const bigIntCeil = (a) => {\n// if (a % BigInt(1) === BigInt(0)) return a;\n// return (a + BigInt(1)) % BigInt(1);\n// };\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => Number(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n // if (min % a === Number(0) || min % b === Number(0) || min % c === Number(0)) {\n // console.log(0);\n // return;\n // }\n\n // if (min === Number(0)) {\n // console.log(Math.min(a,b,c));\n // return;\n // }\n\n function calculateMin(swim) {\n return Math.ceil(min / swim) * swim - min;\n }\n\n const result = Math.min(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nconst bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);\nconst bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min % a === BigInt(0) || min % b === BigInt(0) || min % c === BigInt(0)) {\n console.log(0);\n return;\n }\n\n if (min === BigInt(0)) {\n console.log(Number(bigIntMin(a,b,c)))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nconst bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);\nconst bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min % a === 0 || min % b === 0 || min % c === 0) {\n console.log(0);\n return;\n }\n\n if (min === BigInt(0)) {\n console.log(Number(bigIntMin(a,b,c)))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nconst bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);\nconst bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min == a || min == b || min == c) {\n console.log(0);\n return;\n }\n\n if (min === BigInt(0)) {\n console.log(Number(bigIntMin(a,b,c)))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nconst bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);\nconst bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min == a || min == b || min == c) {\n console.log(0);\n return;\n }\n\n if (min === BigInt(0)) {\n console.log(bigIntMin(a,b,c))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nconst bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);\nconst bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => BigInt(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min == a || min == b || min == c) {\n console.log(0);\n return;\n }\n\n if (min === 0) {\n console.log(bigIntMin(a,b,c))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = bigIntMin(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(Number(result));\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => Math.floor(e));\n const [min, a, b, c] = lineParsed;\n\n // console.log(\">\", [min, a, b, c])\n\n if (min == a || min == b || min == c) {\n console.log(0);\n return;\n }\n\n if (min === 0) {\n console.log(Math.min(a,b,c))\n return;\n }\n\n function calculateMin(swim) {\n return (swim - (min % swim)) % swim;\n }\n\n const result = Math.min(calculateMin(a), calculateMin(b), calculateMin(c));\n console.log(result);\n });\n}\n"}, {"source_code": "let i = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const { EOL } = require(\"os\");\r\n const lines = i.split(EOL); /*your input text, split by lines*/\r\n solve(lines.slice(1));\r\n});\r\n\r\nfunction solve(lines) {\r\n lines.forEach((line) => {\r\n if (!line) return;\r\n const lineParsed = line.split(\" \").map((e) => Number(e));\r\n const [min, a, b, c] = lineParsed;\r\n \r\n // console.log(\">\", [min, a, b, c])\r\n \r\n if (min == a || min == b || min == c) {\r\n console.log(0);\r\n return;\r\n }\r\n \r\n const result = Math.min((a - (min % a)), (b - (min % b)), (c - (min % c)));\r\n console.log(result);\r\n });\r\n}\r\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL); /*your input text, split by lines*/\n solve(lines.slice(1));\n});\n\nfunction solve(lines) {\n lines.forEach((line) => {\n if (!line) return;\n const lineParsed = line.split(\" \").map((e) => Number(e));\n const [min, a, b, c] = lineParsed;\n const result = Math.min((a - (min % a)) % a, (b - (min % b)) % b, (c - (min % c)) % c);\n console.log(result);\n });\n}\n"}, {"source_code": "// let INPUT = `4\n// 9 5 4 8\n// 2 6 10 9\n// 10 2 5 10\n// 10 9 9 9\n// `\n// let INPUT_ARR = INPUT.split(\"\\n\");\n// solve(INPUT_ARR.slice(1))\n\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n console.log(lines);\n\n solve(lines.slice(1))\n})\n\n\n\nfunction solve(lines) {\n\n lines.forEach(line => {\n if (!line) return;\n const lineParsed = line.split(\" \").map(e => Number(e));\n\n const [min, a, b, c] = lineParsed\n\n const result = Math.min((a - min % a) % a, (b - min % b) % b, (c - min % c) % c)\n console.log(result)\n })\n\n\n}\n\n\n\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = Number(readline());\r\n while(t--) {\r\n let [p, a, b, c] = readline().split(\" \").map(num => BigInt(num));\r\n let [ra, rb, rc] = [a, b, c];\r\n \r\n if(a > p) ra -= p;\r\n else if(a < p) ra = div(p, ra) * ra - p;\r\n \r\n if(b > p) rb -= p;\r\n else if(b < p) rb = div(p, rb) * rb - p;\r\n \r\n if(c > p) rc -= p;\r\n else if(c < p) rc = div(p, rc) * rc - p; \r\n \r\n if(a === p || b === p || c === p) console.log(0);\r\n else console.log(String(min(ra, min(rb, rc))));\r\n }\r\n}\r\n\r\nfunction div(dividened, quotient) {\r\n if(dividened % quotient === 0) return (dividened/quotient);\r\n return ((dividened/quotient) + 1n);\r\n}\r\n\r\nfunction min(num1, num2) {\r\n let ans;\r\n if(num1 === num2 || num1 < num2) return num1;\r\n if(num2 < num1) return num2;\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = Number(readline());\r\n while(t--) {\r\n let [p, a, b, c] = readline().split(\" \").map(num => BigInt(num));\r\n \r\n if(a > p) a -= p;\r\n else if(a < p) a = div(p, a) * a - p;\r\n \r\n if(b > p) b -= p;\r\n else if(b < p) b = div(p, b) * b - p;\r\n \r\n if(c > p) c -= p;\r\n else if(c < p) c = div(p, c) * c - p; \r\n \r\n if(a === p || b === p || c === p) console.log(0);\r\n else console.log(String(min(a, min(b, c))));\r\n }\r\n}\r\n\r\nfunction div(dividened, quotient) {\r\n if(dividened % quotient === 0) return (dividened/quotient);\r\n return ((dividened/quotient) + 1n);\r\n}\r\n\r\nfunction min(num1, num2) {\r\n let ans;\r\n if(num1 === num2 || num1 < num2) return num1;\r\n if(num2 < num1) return num2;\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = Number(readline());\r\n while(t--) {\r\n let [p, a, b, c] = readline().split(\" \").map(num => Number(num));\r\n \r\n if(a > p) a -= p;\r\n else if(a < p) a = Math.ceil(p / a) * a - p;\r\n \r\n if(b > p) b -= p;\r\n else if(b < p) b = Math.ceil(p / b) * b - p;\r\n \r\n if(c > p) c -= p;\r\n else if(c < p) c = Math.ceil(p / c) * c - p; \r\n \r\n if(a === p || b === p || c === p) console.log(0);\r\n else console.log(Math.min(a, b, c));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n console.log(0);\r\n }\r\n}\r\n\r\n\r\n"}, {"source_code": "const bigIntMin = (...args) => args.reduce((m, e) => e < m ? e : m);\nconst processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i BigInt(x))\n let min = bigIntMin(p%a === 0 ? 0 : a - p%a, p%b === 0 ? 0 : b - p%b, p%c === 0? 0 : c - p%c)\n console.log(min.toString(10))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n let min = Math.min(p%a === 0 ? 0 : a - p%a, p%b === 0 ? 0 : b - p%b, p%c === 0? 0 : c - p%c)\n console.log(min)\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var \u0445 = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var a = new Array(n + 1).fill(0)\r\n\r\n var [p, a, b, c] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var aa = Math.ceil(p/a)*a - p\r\n var bb = Math.ceil(p/b)*b - p\r\n var cc = Math.ceil(p/c)*c - p\r\n var min = Math.min(aa, bb)\r\n min = Math.min(min, cc)\r\n return console.log(min)\r\n // console.log(n, k)\r\n for (var i = 1; i <= n; i++) {\r\n count[a[i]] = Math.max(count[a[i]], i - last[a[i]])\r\n last[a[i]] = i\r\n }\r\n\r\n for (var i = 1; i <= n; i++) {\r\n var max = Math.max(count[i], n - last[i] + 1)\r\n for (var j = max; j <= n && ans[j] === -1; j++) {\r\n ans[j] = i\r\n }\r\n }\r\n\r\n // console.log(count)\r\n // console.log(a)\r\n console.log(ans.slice(1).join(' '))\r\n // console.log(map)\r\n // console.log(a)\r\n })\r\n}\r\n\r\n"}], "src_uid": "293f9b996eee9f76d4bfdeda85685baa"} {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n if (xor == 0) {\n io.writeLine('YES');\n return;\n }\n let xor2 = 0;\n let count = 0;\n for (let i = 0; i < n; i++) {\n xor2 ^= arr[i];\n if (xor == xor2) {\n xor2 = 0;\n count++;\n }\n }\n io.writeLine(count > 2 ? 'YES' : 'NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var res = a[0]\r\n var met = false\r\n for (let j = 1; j < n ; j++) {\r\n res = res ^ a[j]\r\n }\r\n\r\n if (res === 0) return console.log('YES')\r\n var count = 0\r\n\r\n var aa = 0\r\n for (let j = 0; j < n; j++) {\r\n aa = a[j] ^aa\r\n if(aa === res) {\r\n count++\r\n aa = 0\r\n }\r\n }\r\n if (count>=3) return console.log('YES')\r\n console.log('NO')\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a ^ b, 0);\r\n if (sum === 0) return 'YES';\r\n let count = 0,\r\n cur = 0;\r\n for (let i = 0; i < n; i++) {\r\n cur ^= a[i];\r\n if (cur === sum) {\r\n cur = 0;\r\n count++;\r\n }\r\n }\r\n if (count >= 2) return 'YES';\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans, req = 0;\r\n\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\treq ^= a[i];\r\n\t\t\tlet cur = 0, found;\r\n\t\t\tfor (j = i + 1; j < n; j++) {\r\n\t\t\t\tcur ^= a[j];\r\n\t\t\t\tif (cur == req) {\r\n\t\t\t\t\tfound = true;\r\n\t\t\t\t\tcur = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tans = ans || found && cur == 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = Number(input[b]);\r\n b++;\r\n var arr = input[b].split(\" \").map((i) => {\r\n return Number(i);\r\n })\r\n b++;\r\n var total = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n total = total ^ arr[i];\r\n }\r\n if (total === 0) {\r\n console.log(\"YES\")\r\n continue;\r\n }\r\n var sum = 0;\r\n var count = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n sum = sum ^ arr[i];\r\n if (sum === total) {\r\n count++;\r\n sum = 0;\r\n }\r\n }\r\n if (sum === 0 && count >= 3) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n});"}, {"source_code": "var T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar n = parseInt(readline());\n\tvar a = readline().split(\" \").map(x => parseInt(x));\n\n\tvar ok = false;\n\tfor (i = 0; i < n - 1; i++) {\n\t\tvar re = 0;\n\t\tfor (j = 0; j <= i; j++) {\n\t\t\tre ^= a[j];\n\t\t}\n\t\tvar cur = 0;\n\t\tvar once = false;\n\t\tfor (j = i + 1; j < n; j++) {\n\t\t\tif (cur == re) { cur = 0; once = true; }\n\t\t\tcur ^= a[j];\n\t\t}\n\t\tif (cur == re || (once && cur == 0)) {\n\t\t\tok = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (ok) {\n\t\tprint(\"YES\");\n\t} else {\n\t\tprint(\"NO\");\n\t}\n}\n/*var a = readline().split(\" \").map(x => parseInt(x));\n\nvar mii = 0, mai = 0;\nfor (var i = 0; i < n; i++) {\n\tif (a[i] <= a[mii]) mii = i;\n\tif (a[i] > a[mai]) mai = i;\n}\n\nvar ans = mai + n - mii - 1;\nif (mai > mii) ans -= 1;\nprint(ans);*/\n"}], "negative_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n arr = arr.filter((x) => x);\n while (arr.length < 2) {\n arr.push(0);\n }\n n = arr.length;\n // console.log(arr);\n if (n === 2) {\n io.writeLine(arr[0] === arr[1] ? 'YES' : 'NO');\n return;\n }\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n // console.log({ xor, arr });\n if (xor == 0) {\n io.writeLine('YES');\n return;\n }\n let xor2 = 0;\n for (let i = 0; i < n - 1; i++) {\n xor ^= arr[i];\n if (xor == xor2) {\n io.writeLine('YES');\n return;\n }\n }\n io.writeLine('NO');\n return;\n // console.log({ arr, xor });\n // if (arr.length % 2 === 0) {\n // io.writeLine(xor == 0 ? 'YES' : 'NO');\n // return;\n // }\n // xor = 0;\n // for (let i = 1; i < n; i++) {\n // xor ^= arr[i];\n // }\n // io.writeLine(xor == arr[0] ? 'YES' : 'NO');\n // return;\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== xor) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n //console.log(arr);\n io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n if (n === 2) {\n io.writeLine(arr[0] === arr[1] ? 'YES' : 'NO');\n return;\n }\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n // console.log({ xor, arr });\n if (xor == 0) {\n io.writeLine('YES');\n return;\n }\n let xor2 = 0;\n for (let i = 0; i < n - 1; i++) {\n xor ^= arr[i];\n if (xor == xor2) {\n io.writeLine('YES');\n return;\n }\n }\n io.writeLine('NO');\n return;\n // console.log({ arr, xor });\n // if (arr.length % 2 === 0) {\n // io.writeLine(xor == 0 ? 'YES' : 'NO');\n // return;\n // }\n // xor = 0;\n // for (let i = 1; i < n; i++) {\n // xor ^= arr[i];\n // }\n // io.writeLine(xor == arr[0] ? 'YES' : 'NO');\n // return;\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== xor) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n //console.log(arr);\n io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n if (xor == 0) {\n io.writeLine('YES');\n return;\n }\n let xor2 = 0;\n for (let i = 0; i < n - 1; i++) {\n xor ^= arr[i];\n if (xor == xor2) {\n io.writeLine('YES');\n return;\n }\n }\n io.writeLine('NO');\n return;\n // console.log({ arr, xor });\n // if (arr.length % 2 === 0) {\n // io.writeLine(xor == 0 ? 'YES' : 'NO');\n // return;\n // }\n // xor = 0;\n // for (let i = 1; i < n; i++) {\n // xor ^= arr[i];\n // }\n // io.writeLine(xor == arr[0] ? 'YES' : 'NO');\n // return;\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== xor) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n //console.log(arr);\n io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== xor) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n //console.log(arr);\n io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let xor = 0;\n for (let i = 0; i < n; i++) {\n xor ^= arr[i];\n }\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== xor) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n console.log(arr);\n io.writeLine(arr.length > 1 && arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let b = [];\n // if (arr.every((a) => a === arr[0])) {\n // io.writeLine('YES');\n // return;\n // }\n // let ret = 0;\n for (let i = 0; i < arr.length - 1;) {\n if (arr[i] !== arr[i + 1]) {\n arr[i] = arr[i] ^ arr[i + 1];\n arr.splice(i + 1, 1);\n }\n else {\n i++;\n }\n // ret ^= arr[i];\n }\n io.writeLine(arr.every((a) => a === arr[0]) ? 'YES' : 'NO');\n // io.writeLine(ret === arr[n - 1] ? 'YES' : 'NO');\n // for (let a of arr) {\n // ret ^= a;\n // }\n // console.log({ ret });\n // if (ret === 0) {\n // io.writeLine('YES');\n // return;\n // }\n // if (arr.some((a) => a === ret)) {\n // io.writeLine('YES');\n // return;\n // }\n // io.writeLine('NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n if (arr.every((a) => a === arr[0])) {\n io.writeLine('YES');\n return;\n }\n let ret = 0;\n for (let a of arr) {\n ret ^= a;\n }\n io.writeLine(ret == 0 ? 'YES' : 'NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let ret = 0;\n for (let a of arr) {\n ret ^= a;\n }\n io.writeLine(ret == 0 ? 'YES' : 'NO');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var res = a[0]\r\n var met = false\r\n for (let j = 1; j < n ; j++) {\r\n res = res ^ a[j]\r\n }\r\n\r\n if (res === 0) return console.log('YES')\r\n var count = 0\r\n\r\n var aa = 0\r\n for (let j = 0; j < n; j++) {\r\n aa = a[j] ^aa\r\n if(aa === res) count++\r\n }\r\n if (count>=3) return console.log('YES')\r\n console.log('NO')\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var res = a[0]\r\n var met = false\r\n for (let j = 1; j < n - 1; j++) {\r\n res = res ^ a[j]\r\n if (res === a[n - 1]) met = true\r\n }\r\n if (res === a[n - 1] || res === 0 && met) return console.log('YES')\r\n console.log('NO')\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var res = a[0]\r\n for (let j = 1; j < n; j++) {\r\n res = res ^ a[j]\r\n }\r\n var count = 0\r\n if (res === 0) return console.log('YES')\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] === res) count++\r\n }\r\n if (count >= 1 && n %2===1) return console.log('YES')\r\n return console.log('NO')\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var res = a[0]\r\n for (let j = 1; j < n; j++) {\r\n res = res ^ a[j]\r\n }\r\n if (res === 0) return console.log('YES')\r\n return console.log('NO')\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n for (let j = 0; j < n; j++) {\r\n var res\r\n res = j === 0 ? a[1] : a[0]\r\n for (let i = 0; i < n; i++) {\r\n if (i !== j) res = res ^ a[i]\r\n }\r\n if(res === a[j]) return console.log('YES')\r\n }\r\n return console.log('NO')\r\n\r\n\r\n console.log(a.join(' '))\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a ^ b, 0);\r\n if (sum === 0) return 'YES';\r\n const s = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n var _s;\r\n s[i] = ((_s = s[i - 1]) !== null && _s !== void 0 ? _s : 0) ^ a[i];\r\n }\r\n for (let i = 1; i < n - 1; i++) {\r\n for (let j = i; j < n - 1; j++) {\r\n var _s2;\r\n if (sum === (s[j] ^ ((_s2 = s[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0))) return 'YES';\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const sum = a.reduce((a, b) => a ^ b, 0);\r\n if (sum === 0) return 'YES';\r\n const s = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n var _s;\r\n s[i] = ((_s = s[i - 1]) !== null && _s !== void 0 ? _s : 0) ^ a[i];\r\n }\r\n for (let i = 0; i < n; i++) {\r\n const N = i === 0 ? n - 1 : n;\r\n for (let j = i + 1; j < N; j++) {\r\n var _s2;\r\n if (sum === (s[j] ^ ((_s2 = s[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0))) return 'YES';\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans, req = 0;\r\n\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\treq ^= a[i];\r\n\t\t\tlet cur = 0;\r\n\t\t\tfor (j = i + 1; j < n; j++) {\r\n\t\t\t\tif (cur == req) cur = 0;\r\n\t\t\t\tcur ^= a[j];\r\n\t\t\t}\r\n\t\t\tans = ans || req == cur;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar n = parseInt(readline());\n\tvar a = readline().split(\" \").map(x => parseInt(x));\n\n\tvar ok = false;\n\tfor (i = 0; i < n - 1; i++) {\n\t\tvar re = 0;\n\t\tfor (j = 0; j <= i; j++) {\n\t\t\tre ^= a[j];\n\t\t}\n\t\tvar cur = 0;\n\t\tfor (j = i + 1; j < n; j++) {\n\t\t\tif (cur == re) cur = 0;\n\t\t\tcur ^= a[j];\n\t\t}\n\t\tif (cur == re) {\n\t\t\tok = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (ok) {\n\t\tprint(\"YES\");\n\t} else {\n\t\tprint(\"NO\");\n\t}\n}\n/*var a = readline().split(\" \").map(x => parseInt(x));\n\nvar mii = 0, mai = 0;\nfor (var i = 0; i < n; i++) {\n\tif (a[i] <= a[mii]) mii = i;\n\tif (a[i] > a[mai]) mai = i;\n}\n\nvar ans = mai + n - mii - 1;\nif (mai > mii) ans -= 1;\nprint(ans);*/\n"}, {"source_code": "var T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar n = parseInt(readline());\n\tvar a = readline().split(\" \").map(x => parseInt(x));\n\n\tvar ok = false;\n\tfor (i = 0; i < n - 1; i++) {\n\t\tvar re = 0;\n\t\tfor (j = 0; j <= i; j++) {\n\t\t\tre ^= a[j];\n\t\t}\n\t\tvar cur = 0;\n\t\tfor (j = i + 1; j < n; j++) {\n\t\t\tcur ^= a[j];\n\t\t\tif (cur == re) cur = 0;\n\t\t}\n\t\tif (cur == 0) {\n\t\t\tok = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (ok) {\n\t\tprint(\"YES\");\n\t} else {\n\t\tprint(\"NO\");\n\t}\n}\n/*var a = readline().split(\" \").map(x => parseInt(x));\n\nvar mii = 0, mai = 0;\nfor (var i = 0; i < n; i++) {\n\tif (a[i] <= a[mii]) mii = i;\n\tif (a[i] > a[mai]) mai = i;\n}\n\nvar ans = mai + n - mii - 1;\nif (mai > mii) ans -= 1;\nprint(ans);*/\n"}], "src_uid": "4004c77b77076bf450cbe751e025a71f"} {"source_code": "function sa(n, s){\n var dp = [];\n dp[0] = 0;\n var lastL = 0;\n var lastR = 0;\n var lastU = 0;\n var lastD = 0;\n for(var i=1;i<=n;i++){\n if(s[i-1] == \"R\"){\n lastR = i;\n } else if(s[i-1] == \"L\"){\n lastL = i;\n } else if(s[i-1] == \"U\"){\n lastU = i;\n } else if(s[i-1] == \"D\"){\n lastD = i;\n }\n var first = Math.min(lastL, lastR);\n var second = Math.min(lastU, lastD);\n dp[i] = dp[Math.max(first, second)] + 1;\n \n }\n return dp[n];\n }\n \n var n = Number(readline());\n var s = readline();\n print(sa(n, s));", "positive_code": [{"source_code": "var num = readline();\nvar data = readline().split(\"\");\n\na(num,data);\n\nfunction a(num, data){\n var cnt = 1;\n var r = false; var l = false; var d = false; var u = false;\n for(i = 0; i v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n const m = len.length\r\n for (let i = 0; i < m; i++) {\r\n len[i] -= m - i\r\n ans++\r\n }\r\n len = len.filter(v => v > 0)\r\n\r\n while (len.length) {\r\n let t = -1\r\n for (let i = 0; i < len.length; i++) {\r\n if (t === -1 || len[t] < len[i]) t = i\r\n }\r\n len[t]--\r\n let tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (--len[i] > 0) tmp.push(len[i])\r\n }\r\n len = tmp\r\n ans++\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n", "positive_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n\r\n // const g = new Array(n + 10).fill(0)\r\n // // for (let [k, v] of data.entries()) {\r\n // // g[v - 1]++\r\n // // }\r\n // for (let v of data) {\r\n // g[v]++\r\n // }\r\n // g.push(1)\r\n // let len = g.filter(v => v > 0).sort((a, b) => b - a)\r\n // for (let i of g) {\r\n // if (i > 0) len.push(i)\r\n // }\r\n // len.sort((a, b) => b - a)\r\n\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n const m = len.length\r\n for (let j = 0; j < m; j++) {\r\n len[j] -= m - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n // while (len.length) {\r\n // ans++\r\n // let t = -1,\r\n // tmp = []\r\n\r\n // for (let j = 0; j < len.length; j++) {\r\n // if (t === -1 || len[t] < tmp[j]) t = j\r\n // }\r\n // len[t]--\r\n // for (let j = 0; j < len.length; j++) {\r\n // if (--len[j] > 0) {\r\n // tmp.push(len[j])\r\n // }\r\n // }\r\n\r\n // len = tmp\r\n // }\r\n while (len.length) {\r\n let t = -1\r\n for (let i = 0; i < len.length; i++) {\r\n if (t === -1 || len[t] < len[i]) t = i\r\n }\r\n len[t]--\r\n let tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (--len[i] > 0) tmp.push(len[i])\r\n }\r\n len = tmp\r\n ans++\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\n// mnq.push(10);\r\n// mnq.peek();\r\n// mnq.size();\r\n\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst chlds = Array(n + 1).fill(0);\r\n\t\tchlds[0] = 1;\r\n\t\tlet cnt = 1;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\t// i -> a[i]\r\n\t\t\t// i + 2 -> a[i]\r\n\t\t\tchlds[a[i]]++;\r\n\t\t\tcnt += chlds[a[i]] == 1;\r\n\t\t}\r\n\r\n\t\tchlds.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = cnt;\r\n\t\tconst mxq = new PriorityQueue((a, b) => a > b);\r\n\t\tfor (let i = 0; i < n + 1; i++) {\r\n\t\t\tchlds[i] -= Math.max(0, cnt - i);\r\n\t\t\tif (chlds[i] > 0) mxq.push(chlds[i]);\r\n\t\t}\r\n\r\n\t\twhile (mxq.size()) {\r\n\t\t\tconst other = [];\r\n\t\t\tlet sub = 2;\r\n\t\t\twhile (mxq.size()) {\r\n\t\t\t\tlet poped = mxq.pop();\r\n\t\t\t\tpoped -= sub;\r\n\t\t\t\tif (poped > 0) other.push(poped);\r\n\t\t\t\tsub = 1;\r\n\t\t\t}\r\n\t\t\twhile(other.length) {\r\n\t\t\t\tmxq.push(other.pop());\r\n\t\t\t}\r\n\t\t\tans++;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "// no zero contained, asc\nfunction stairCaseMin(i) {\n for (var j = 0; j < i.length; j++) {\n i[j] -= j + 1;\n }\n return i;\n}\nvar total = +readline();\nwhile (total--) {\n var children = new Array(+readline() + 1).fill(0);\n readline().split(\" \").map(Number).forEach(function (x) {\n children[x]++;\n });\n // roots\n children[0] = 1;\n children = children.filter(function (x) {\n return x != 0;\n }).sort(function (a, b) {\n return a - b;\n });\n var ans = 0;\n // stairCase boost\n ans += children.length;\n children = stairCaseMin(children).filter(function (x) {\n return x > 0;\n }).sort(function (a, b) {\n return a - b;\n });\n // all clusters included at least one infected\n while (children.length != 0) {\n ans += 1;\n children = children.map(function (x) {\n return x - 1;\n }).sort(function (a, b) {\n return a - b;\n });\n children[children.length - 1]--;\n children = children.filter(function (x) {\n return x > 0;\n });\n }\n print(ans);\n}"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n const m = len.length\r\n for (let i = 0; i < m; i++) {\r\n len[i] -= m - i\r\n ans++\r\n }\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n\r\n while (len.length) {\r\n let t = -1\r\n for (let i = 0; i < len.length; i++) {\r\n if (t === -1 || len[t] < len[i]) t = i\r\n }\r\n len[t]--\r\n let tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (--len[i] > 0) tmp.push(len[i])\r\n }\r\n len = tmp\r\n ans++\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (n, P)=>{\n P = [-1].concat(P.map(p=>p-1))\n let tree = {};\n let nodes = [0];\n for (let i=1; i{\n let pa = P[a];\n let pb = P[b];\n let a_cnt = pa==-1 ? 1 : tree[pa].length;\n let b_cnt = pb==-1 ? 1 : tree[pb].length;\n return b_cnt-a_cnt;\n });\n let seconds = 0;\n let has_infected_child = new Map();\n // inject all siblings\n for (let h of nodes){\n let p = P[h];\n if (has_infected_child.has(p))\n continue;\n has_infected_child.set(p, seconds);\n seconds++;\n }\n l(has_infected_child, seconds)\n let remains = [];\n let rem_sum = 0;\n for (let [k, v] of has_infected_child){\n let added = seconds-v;\n let remain = (tree[k]||[]).length-added;\n if (remain>0){\n remains.push(remain)\n rem_sum += remain;\n }\n }\n l(remains)\n while (rem_sum>0){\n seconds++;\n let maxi = -1;\n let new_rem = [], new_sum = 0;\n for (let i=0; i0){\n new_rem.push(to_add)\n new_sum += to_add;\n }\n }\n rem_sum = new_sum;\n remains = new_rem;\n }\n return seconds;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let p = ra();\n l('ans')\n print(calc(n, p));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nclass SegTree {\r\n constructor(nums = [], n = nums.length) {\r\n this.nums = nums\r\n this.n = n\r\n this.root = this._newNode(0, n)\r\n this._build(this.root)\r\n this.update = this._update.bind(this, this.root)\r\n this.query = this._query.bind(this, this.root)\r\n }\r\n _newNode(l, r, val = 0, left = null, right = null) {\r\n return { val, l, r, left, right, add: 0, min: Infinity, max: -Infinity, maxIndex: -1 }\r\n }\r\n _down(node) {\r\n const { left, right } = node\r\n if (!left || !right) return\r\n for (let child of [left, right]) {\r\n child.add += node.add\r\n child.val = Math.max(child.val + node.add * (child.r - child.l + 1), 0)\r\n child.min = Math.max(child.min + node.add, 0)\r\n child.max = Math.max(child.max + node.add, 0)\r\n }\r\n node.add = 0\r\n }\r\n _up(node) {\r\n const { left, right } = node\r\n if (!left || !right) return\r\n node.val = left.val + right.val\r\n node.min = Math.min(left.min, right.min)\r\n if (left.max >= right.max) {\r\n node.max = left.max\r\n node.maxIndex = left.maxIndex\r\n } else {\r\n node.max = right.max\r\n node.maxIndex = right.maxIndex\r\n }\r\n }\r\n _build(node = this.root) {\r\n const { l, r } = node\r\n if (l === r) {\r\n node.val = this.nums[l] || 0\r\n node.maxIndex = l\r\n node.max = node.val\r\n node.min = node.val\r\n return\r\n }\r\n const mid = Math.floor((l + r) / 2)\r\n node.left = this._newNode(l, mid)\r\n node.right = this._newNode(mid + 1, r)\r\n const { left, right } = node\r\n this._build(left)\r\n this._build(right)\r\n node.val = left.val + right.val\r\n node.min = Math.min(left.min, right.min)\r\n if (left.max >= right.max) {\r\n node.max = left.max\r\n node.maxIndex = left.maxIndex\r\n } else {\r\n node.max = right.max\r\n node.maxIndex = right.maxIndex\r\n }\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return\r\n if (node.val === 0) {\r\n node.val = 0\r\n node.min = 0\r\n node.max = 0\r\n return\r\n }\r\n const { l, r, min } = node\r\n if (l === x && r === y && min > 0) {\r\n node.add += z\r\n node.val += z * (r - l + 1)\r\n node.min--\r\n node.max--\r\n return\r\n }\r\n if (l === x && r === y && l === r) {\r\n node.val = 0\r\n node.min = 0\r\n node.max = 0\r\n return\r\n }\r\n this._down(node)\r\n const mid = Math.floor((l + r) / 2)\r\n if (y <= mid) this._update(node.left, x, y, z)\r\n else if (x > mid) this._update(node.right, x, y, z)\r\n else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)\r\n this._up(node)\r\n }\r\n _query(node, x, y) {\r\n if (y < x) return 0\r\n if (!node) return 0\r\n if (node.val === 0) return 0\r\n const { l, r } = node\r\n if (l === x && r === y) return node.val\r\n this._down(node)\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2)\r\n if (y <= mid) res = this._query(node.left, x, y)\r\n else if (x > mid) res = this._query(node.right, x, y)\r\n else res = this._query(node.left, x, mid) + this._query(node.right, mid + 1, y)\r\n this._up(node)\r\n return res\r\n }\r\n maxSub(node, x, y) {\r\n const maxIndex = this.root.maxIndex\r\n this._update(this.root, maxIndex, maxIndex, -1)\r\n }\r\n}\r\n\r\nfunction solve(n, data) {\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n let m = len.length\r\n for (let i = 0; i < m; i++) {\r\n len[i] -= m - i\r\n ans++\r\n }\r\n len = len.filter(v => v > 0)\r\n\r\n const segTree = new SegTree(len)\r\n m = len.length\r\n let sum = segTree.query(0, m)\r\n while (sum) {\r\n ans++\r\n segTree.maxSub()\r\n segTree.update(0, m, -1)\r\n\r\n sum = segTree.query(0, m)\r\n }\r\n return ans\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n\r\n res.push(solve(n, data))\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n // for (let [k, v] of data.entries()) {\r\n // g[v - 1]++\r\n // }\r\n for (let v of data) {\r\n g[v]++\r\n }\r\n let len = [1]\r\n for (let i of g) {\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let i = 0; i < len.length; i++) {\r\n if (t === -1 || len[t] < len[i]) t = i\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n // for (let [k, v] of data.entries()) {\r\n // g[v - 1]++\r\n // }\r\n for (let v of data) {\r\n g[v]++\r\n }\r\n let len = [1]\r\n for (let i of g) {\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n // while (len.length) {\r\n // ans++\r\n // let t = -1,\r\n // tmp = []\r\n\r\n // for (let j = 0; j < len.length; j++) {\r\n // if (t === -1 || len[t] < tmp[j]) t = j\r\n // }\r\n // len[t]--\r\n // for (let j = 0; j < len.length; j++) {\r\n // if (--len[j] > 0) {\r\n // tmp.push(len[j])\r\n // }\r\n // }\r\n\r\n // len = tmp\r\n // }\r\n while (len.length) {\r\n let t = -1\r\n for (let i = 0; i < len.length; i++) {\r\n if (t === -1 || len[t] < len[i]) t = i\r\n }\r\n len[t]--\r\n let tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (--len[i] > 0) tmp.push(len[i])\r\n }\r\n len = tmp\r\n ans++\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, data, max) {\r\n let b = 0,\r\n a = 0\r\n for (let i = 0; i < n; i++) {\r\n let num = max - data[i]\r\n if (num % 2) b++\r\n a += Math.floor(num / 2)\r\n }\r\n // if (b > a) return b * 2 - 1\r\n let x = Math.max(Math.floor((a - b) / 3), 0)\r\n a -= x\r\n b += 2 * x\r\n if (b === a - 2) {\r\n a--\r\n b += 2\r\n }\r\n if (b > a) return b * 2 - 1\r\n return a * 2\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n let t = -1\r\n for (let [k, v] of data.entries()) {\r\n if (t === -1 || data[t] < v) t = k\r\n }\r\n\r\n let ans = solve(n, data, data[t])\r\n data[t]++\r\n ans = Math.min(ans, solve(n, data, data[t]) + 1)\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nclass SegTree {\r\n constructor(nums = [], n = nums.length) {\r\n this.nums = nums\r\n this.n = n\r\n this.root = this._newNode(0, n)\r\n this._build(this.root)\r\n this.update = this._update.bind(this, this.root)\r\n this.query = this._query.bind(this, this.root)\r\n }\r\n _newNode(l, r, val = 0, left = null, right = null) {\r\n return { val, l, r, left, right, add: 0, min: Infinity, max: -Infinity, maxIndex: -1 }\r\n }\r\n _down(node) {\r\n const { left, right } = node\r\n if (!left || !right) return\r\n for (let child of [left, right]) {\r\n child.add += node.add\r\n child.val = Math.max(child.val + node.add * (child.r - child.l + 1), 0)\r\n }\r\n node.add = 0\r\n }\r\n _up(node) {\r\n const { left, right } = node\r\n if (!left || !right) return\r\n node.val = left.val + right.val\r\n node.min = Math.min(left.min, right.min)\r\n if (left.max >= right.max) {\r\n node.max = left.max\r\n node.maxIndex = left.maxIndex\r\n } else {\r\n node.max = right.max\r\n node.maxIndex = right.maxIndex\r\n }\r\n }\r\n _build(node = this.root) {\r\n const { l, r } = node\r\n if (l === r) {\r\n node.val = this.nums[l] || 0\r\n node.maxIndex = l\r\n node.max = node.val\r\n node.min = node.val\r\n return\r\n }\r\n const mid = Math.floor((l + r) / 2)\r\n node.left = this._newNode(l, mid)\r\n node.right = this._newNode(mid + 1, r)\r\n const { left, right } = node\r\n this._build(left)\r\n this._build(right)\r\n node.val = left.val + right.val\r\n node.min = Math.min(left.min, right.min)\r\n if (left.max >= right.max) {\r\n node.max = left.max\r\n node.maxIndex = left.maxIndex\r\n } else {\r\n node.max = right.max\r\n node.maxIndex = right.maxIndex\r\n }\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return\r\n if (node.val === 0) return\r\n const { l, r, min } = node\r\n if (l === x && r === y && min > 0) {\r\n node.add += z\r\n node.val += z * (r - l + 1)\r\n node.min--\r\n node.max--\r\n return\r\n }\r\n if (l === x && r === y && l === r) {\r\n node.val = 0\r\n node.min = 0\r\n node.max = 0\r\n return\r\n }\r\n this._down(node)\r\n const mid = Math.floor((l + r) / 2)\r\n if (y <= mid) this._update(node.left, x, y, z)\r\n else if (x > mid) this._update(node.right, x, y, z)\r\n else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)\r\n this._up(node)\r\n }\r\n _query(node, x, y) {\r\n if (y < x) return 0\r\n if (!node) return 0\r\n if (node.val === 0) return 0\r\n const { l, r } = node\r\n if (l === x && r === y) return node.val\r\n this._down(node)\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2)\r\n if (y <= mid) res = this._query(node.left, x, y)\r\n else if (x > mid) res = this._query(node.right, x, y)\r\n else res = this._query(node.left, x, mid) + this._query(node.right, mid + 1, y)\r\n this._up(node)\r\n return res\r\n }\r\n maxSub(node, x, y) {\r\n const maxIndex = this.root.maxIndex\r\n this._update(this.root, maxIndex, maxIndex, -1)\r\n }\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n let m = len.length\r\n for (let i = 0; i < m; i++) {\r\n len[i] -= m - i\r\n ans++\r\n }\r\n len = len.filter(v => v > 0)\r\n\r\n const segTree = new SegTree(len)\r\n m = len.length\r\n let sum = segTree.query(0, m)\r\n while (sum) {\r\n ans++\r\n segTree.update(0, m, -1)\r\n segTree.maxSub()\r\n\r\n sum = segTree.query(0, m)\r\n }\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n\r\n // const g = new Array(n + 10).fill(0)\r\n // // for (let [k, v] of data.entries()) {\r\n // // g[v - 1]++\r\n // // }\r\n // for (let v of data) {\r\n // g[v]++\r\n // }\r\n // g.push(1)\r\n // let len = g.filter(v => v > 0).sort((a, b) => b - a)\r\n // for (let i of g) {\r\n // if (i > 0) len.push(i)\r\n // }\r\n // len.sort((a, b) => b - a)\r\n\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n const m = len.length\r\n for (let j = 0; j < m; j++) {\r\n len[j] -= m - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n\r\n // const g = new Array(n + 10).fill(0)\r\n // // for (let [k, v] of data.entries()) {\r\n // // g[v - 1]++\r\n // // }\r\n // for (let v of data) {\r\n // g[v]++\r\n // }\r\n // g.push(1)\r\n // let len = g.filter(v => v > 0).sort((a, b) => b - a)\r\n // for (let i of g) {\r\n // if (i > 0) len.push(i)\r\n // }\r\n // len.sort((a, b) => b - a)\r\n\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n // const g = new Array(n + 10).fill(0)\r\n // // for (let [k, v] of data.entries()) {\r\n // // g[v - 1]++\r\n // // }\r\n // for (let v of data) {\r\n // g[v]++\r\n // }\r\n // g.push(1)\r\n // let len = g.filter(v => v > 0).sort((a, b) => b - a)\r\n // for (let i of g) {\r\n // if (i > 0) len.push(i)\r\n // }\r\n // len.sort((a, b) => b - a)\r\n\r\n let len = new Array(n + 10).fill(0)\r\n for (let num of data) {\r\n len[num]++\r\n }\r\n len.push(1)\r\n len = len.filter(v => v > 0).sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n // for (let [k, v] of data.entries()) {\r\n // g[v - 1]++\r\n // }\r\n for (let v of data) {\r\n g[v]++\r\n }\r\n g.push(1)\r\n let len = g.filter(v => v > 0).sort((a, b) => b - a)\r\n // for (let i of g) {\r\n // if (i > 0) len.push(i)\r\n // }\r\n // len.sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n // for (let [k, v] of data.entries()) {\r\n // g[v - 1]++\r\n // }\r\n for (let v of data) {\r\n g[v]++\r\n }\r\n let len = [1]\r\n for (let i of g) {\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let ans = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n ans++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n ans++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n let g = new Array(n + 10).fill(0)\r\n for (let v of data) {\r\n g[v - 1]++\r\n }\r\n\r\n g.push(1)\r\n g.sort((a, b) => b - a)\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n\r\n let ans = 0\r\n for (let i = 0; i < g.length; i++) {\r\n g[i] = g[i] - g.length - i\r\n ans++\r\n }\r\n g.sort((a, b) => b - a)\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n while (g.length) {\r\n ans++\r\n const n = g.length\r\n let t = 0\r\n for (let i = 0; i < n; i++) {\r\n if (g[i] === g[0]) t = i\r\n else break\r\n }\r\n g[t]--\r\n for (let i = 0; i < n; i++) g[i]--\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n }\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n let g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n\r\n g.push(1)\r\n g.sort((a, b) => b - a)\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n\r\n let ans = 0\r\n for (let i = 0; i < g.length; i++) {\r\n g[i] = g[i] - g.length - i\r\n ans++\r\n }\r\n g.sort((a, b) => b - a)\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n while (g.length) {\r\n ans++\r\n const n = g.length\r\n let t = 0\r\n for (let i = 0; i < n; i++) {\r\n if (g[i] === g[0]) t = i\r\n else break\r\n }\r\n g[t]--\r\n for (let i = 0; i < n; i++) g[i]--\r\n while (g.length && g[g.length - 1] <= 0) g.pop()\r\n }\r\n\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n if (inputs[1].trim() === '31803') {\r\n console.log(inputs[_ * 2])\r\n return\r\n }\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = [1]\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let i = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n i++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n\r\n if (inputs[1] === '31803' && __ === 9) {\r\n console.log(inputs[__ * 2 + 2])\r\n }\r\n\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = [1]\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let i = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n i++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n if (inputs[1] === '31803' && __ === 9) {\r\n console.log(data)\r\n }\r\n\r\n const g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = [1]\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let i = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n i++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = [1]\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let i = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n i++\r\n }\r\n\r\n len = len.filter(num => num > 0)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n\r\n for (let j = 0; j < len.length; j++) {\r\n if (t === -1 || len[t] < tmp[j]) t = j\r\n }\r\n len[t]--\r\n for (let j = 0; j < len.length; j++) {\r\n if (--len[j] > 0) {\r\n tmp.push(len[j])\r\n }\r\n }\r\n\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n\r\n const g = new Array(n + 10).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v - 1]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = [1]\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n len.sort((a, b) => b - a)\r\n let i = 0\r\n for (let j = 0; j < len.length; j++) {\r\n len[j] -= len.length - j\r\n i++\r\n }\r\n\r\n len = len.filter(num => num > 0).sort((a, b) => b - a)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n for (let j = 0; j < len.length; j++) {\r\n if (len[j] > 1) {\r\n tmp.push(len[j] - 1)\r\n if (t === -1 || tmp[t] < tmp[tmp.length - 1]) t = tmp.length - 1\r\n }\r\n }\r\n if (t === -1) break\r\n tmp[t]--\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n\r\n const g = new Array(n + 2).fill(0)\r\n for (let [k, v] of data.entries()) {\r\n g[v]++\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let i of g) {\r\n if (i) hasSon++\r\n maxSon = Math.max(maxSon, i)\r\n if (i > 0) len.push(i)\r\n }\r\n\r\n let i = len.length + 1\r\n\r\n len = len.map(num => num - i).filter(num => num > 0)\r\n\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (len[i] > 1) {\r\n tmp.push(len[i] - 1)\r\n if (t === -1 || tmp[t] < tmp[tmp.length - 1]) t = tmp.length - 1\r\n }\r\n }\r\n if (t === -1) break\r\n tmp[t]--\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n if (children.length > 0) len.push(children.length)\r\n }\r\n\r\n let i = len.length + 1\r\n\r\n len = len.map(num => num - i).filter(num => num > 0)\r\n len.sort((a, b) => b - a)\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (len[i] > 1) {\r\n tmp.push(len[i] - 1)\r\n if (t === -1 || tmp[t] < tmp[tmp.length - 1]) t = tmp.length - 1\r\n }\r\n }\r\n tmp[t]--\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n if (children.length > 0) len.push(children.length)\r\n }\r\n\r\n let i = len.length + 1\r\n console.log(len)\r\n len = len.map(num => num - i).filter(num => num > 0)\r\n len.sort((a, b) => b - a)\r\n while (len.length) {\r\n i++\r\n let t = -1,\r\n tmp = []\r\n for (let i = 0; i < len.length; i++) {\r\n if (len[i] > 1) {\r\n tmp.push(len[i] - 1)\r\n if (t === -1 || tmp[t] < tmp[tmp.length - 1]) t = tmp.length - 1\r\n }\r\n }\r\n tmp[t]--\r\n len = tmp\r\n }\r\n res.push(i)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n this._comparator = _comparator\r\n this._heap = []\r\n if (arr) {\r\n this._heap = [...arr]\r\n for (let i = arr.length >> 1; i; i--) this.down(i)\r\n }\r\n }\r\n swap(i, j) {\r\n ;[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]]\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i)\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j])\r\n }\r\n parent(i) {\r\n return (i - 1) >> 1\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2]\r\n }\r\n up(i) {\r\n let parent = this.parent(i)\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent)\r\n ;[i, parent] = [parent, (parent - 1) >> 1]\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i)\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left\r\n if (this.comparator(right, left)) [left, right] = [right, left]\r\n if (this.comparator(i, left)) break\r\n this.swap(i, left)\r\n i = left\r\n ;[left, right] = [2 * i + 1, 2 * i + 2]\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node)\r\n this.up(this._heap.length - 1)\r\n }\r\n pop() {\r\n if (this.size() === 0) return null\r\n let res = this._heap[0]\r\n this.swap(0, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(0)\r\n return res\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this.swap(i, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this._heap[i] = val\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n top() {\r\n if (this.size() === 0) return null\r\n return this._heap[0]\r\n }\r\n size() {\r\n return this._heap.length\r\n }\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n len.push(children.length)\r\n }\r\n\r\n if (maxSon <= hasSon + 1) {\r\n res.push(hasSon + 1)\r\n } else {\r\n let i = 1 + hasSon\r\n const heap = new Heap((a, b) => b < a)\r\n\r\n for (let j of len) {\r\n if (j <= i) continue\r\n heap.push(j - i)\r\n }\r\n\r\n while (heap.size()) {\r\n while (heap.size() && heap.top() <= i) {\r\n heap.pop()\r\n }\r\n if (heap.size() === 0) break\r\n\r\n let cur = heap.pop(),\r\n top = heap.top()\r\n if (!top) {\r\n i += Math.ceil(cur / 2)\r\n break\r\n }\r\n\r\n i += cur - top\r\n cur -= (cur - top) * 2\r\n if (cur > i) {\r\n heap.push(cur)\r\n }\r\n }\r\n res.push(i)\r\n }\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n this._comparator = _comparator\r\n this._heap = []\r\n if (arr) {\r\n this._heap = [...arr]\r\n for (let i = arr.length >> 1; i; i--) this.down(i)\r\n }\r\n }\r\n swap(i, j) {\r\n ;[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]]\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i)\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j])\r\n }\r\n parent(i) {\r\n return (i - 1) >> 1\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2]\r\n }\r\n up(i) {\r\n let parent = this.parent(i)\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent)\r\n ;[i, parent] = [parent, (parent - 1) >> 1]\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i)\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left\r\n if (this.comparator(right, left)) [left, right] = [right, left]\r\n if (this.comparator(i, left)) break\r\n this.swap(i, left)\r\n i = left\r\n ;[left, right] = [2 * i + 1, 2 * i + 2]\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node)\r\n this.up(this._heap.length - 1)\r\n }\r\n pop() {\r\n if (this.size() === 0) return null\r\n let res = this._heap[0]\r\n this.swap(0, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(0)\r\n return res\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this.swap(i, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this._heap[i] = val\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n top() {\r\n if (this.size() === 0) return null\r\n return this._heap[0]\r\n }\r\n size() {\r\n return this._heap.length\r\n }\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n len.push(children.length)\r\n }\r\n\r\n if (maxSon <= hasSon + 1) {\r\n res.push(hasSon + 1)\r\n } else {\r\n let i = 1 + hasSon\r\n const heap = new Heap((a, b) => b < a)\r\n\r\n for (let j of len) {\r\n if (j <= i) continue\r\n heap.push(j - i)\r\n }\r\n\r\n while (heap.size()) {\r\n while (heap.size() && heap.top() <= i) {\r\n heap.pop()\r\n }\r\n if (heap.size() === 0) break\r\n\r\n let cur = heap.pop(),\r\n top = heap.top()\r\n if (!top) {\r\n i += Math.ceil(cur / 2)\r\n break\r\n }\r\n\r\n i += cur - top + 1\r\n cur -= cur - top + 1\r\n if (cur > i) {\r\n heap.push(cur)\r\n }\r\n }\r\n res.push(i)\r\n }\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n this._comparator = _comparator\r\n this._heap = []\r\n if (arr) {\r\n this._heap = [...arr]\r\n for (let i = arr.length >> 1; i; i--) this.down(i)\r\n }\r\n }\r\n swap(i, j) {\r\n ;[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]]\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i)\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j])\r\n }\r\n parent(i) {\r\n return (i - 1) >> 1\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2]\r\n }\r\n up(i) {\r\n let parent = this.parent(i)\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent)\r\n ;[i, parent] = [parent, (parent - 1) >> 1]\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i)\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left\r\n if (this.comparator(right, left)) [left, right] = [right, left]\r\n if (this.comparator(i, left)) break\r\n this.swap(i, left)\r\n i = left\r\n ;[left, right] = [2 * i + 1, 2 * i + 2]\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node)\r\n this.up(this._heap.length - 1)\r\n }\r\n pop() {\r\n if (this.size() === 0) return null\r\n let res = this._heap[0]\r\n this.swap(0, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(0)\r\n return res\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this.swap(i, this._heap.length - 1)\r\n this._heap.pop()\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return\r\n let res = this._heap[i]\r\n this._heap[i] = val\r\n this.down(i)\r\n this.up(i)\r\n return res\r\n }\r\n top() {\r\n if (this.size() === 0) return null\r\n return this._heap[0]\r\n }\r\n size() {\r\n return this._heap.length\r\n }\r\n}\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n len.push(children.length)\r\n }\r\n\r\n if (maxSon <= hasSon + 1) {\r\n res.push(hasSon + 1)\r\n } else {\r\n let i = 1 + hasSon\r\n const heap = new Heap((a, b) => b < a)\r\n\r\n for (let j of len) {\r\n if (j <= i) continue\r\n heap.push(j - i)\r\n }\r\n\r\n console.log('-----------')\r\n while (heap.size()) {\r\n while (heap.size() && heap.top() <= i) {\r\n heap.pop()\r\n }\r\n if (heap.size() === 0) break\r\n\r\n let cur = heap.pop(),\r\n top = heap.top()\r\n if (!top) {\r\n i += Math.ceil(cur / 2)\r\n break\r\n }\r\n\r\n i += cur - top + 1\r\n cur -= cur - top + 1\r\n if (cur > i) {\r\n heap.push(cur)\r\n }\r\n }\r\n res.push(i)\r\n }\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0,\r\n len = []\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n len.push(children.length)\r\n }\r\n\r\n if (maxSon <= hasSon + 1) {\r\n res.push(hasSon + 1)\r\n } else {\r\n let i = 1 + hasSon\r\n len.sort((a, b) => a - b)\r\n while (len[len.length - 1] > i) {\r\n let last = len.pop()\r\n i += Math.ceil((last - i) / 2)\r\n }\r\n res.push(i)\r\n }\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n }\r\n\r\n if (maxSon > hasSon + 1) {\r\n maxSon -= hasSon + 1\r\n let ans = 1 + hasSon + Math.ceil(maxSon / 2)\r\n res.push(ans)\r\n } else res.push(hasSon + 1)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n }\r\n\r\n maxSon -= hasSon + 1\r\n let ans = 1 + hasSon + Math.ceil(Math.max(maxSon, 0) / 2)\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (n, P)=>{\n P = [-1].concat(P.map(p=>p-1))\n let tree = {};\n let nodes = [0];\n for (let i=1; i{\n let pa = P[a];\n let pb = P[b];\n let a_cnt = pa==-1 ? 1 : tree[pa].length;\n let b_cnt = pb==-1 ? 1 : tree[pb].length;\n return b_cnt-a_cnt;\n });\n let seconds = 0;\n let has_infected_child = new Map();\n // inject all siblings\n for (let h of nodes){\n let p = P[h];\n if (has_infected_child.has(p))\n continue;\n has_infected_child.set(p, seconds);\n seconds++;\n }\n l(has_infected_child, seconds)\n let remains = [];\n let rem_sum = 0;\n for (let [k, v] of has_infected_child){\n let added = seconds-v;\n let remain = (tree[k]||[]).length-added;\n if (remain>0){\n remains.push(remain)\n rem_sum += remain;\n }\n }\n l(remains)\n while (rem_sum>0){\n seconds++;\n let maxi = -1;\n let new_rem = [], new_sum = 0;\n for (let i=0; i0){\n new_rem.push(to_add)\n new_sum += to_add;\n }\n }\n rem_sum = new_sum;\n remains = new_rem;\n }\n return seconds;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let p = ra();\n l('ans')\n print(calc(n, p));\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n \nconst calc = (n, P)=>{\n P = [-1].concat(P.map(p=>p-1))\n let tree = {};\n let nodes = [0];\n for (let i=1; i{\n let pa = P[a];\n let pb = P[b];\n let a_cnt = pa==-1 ? 1 : tree[pa].length;\n let b_cnt = pb==-1 ? 1 : tree[pb].length;\n return b_cnt-a_cnt;\n });\n let seconds = 0;\n let has_infected_child = new Map();\n // inject all siblings\n for (let h of nodes){\n let p = P[h];\n if (has_infected_child.has(p))\n continue;\n has_infected_child.set(p, seconds);\n seconds++;\n }\n l(has_infected_child, seconds)\n let remains = [];\n for (let [k, v] of has_infected_child){\n let added = seconds-v;\n let remain = (tree[k]||[]).length-added;\n remains.push([k, remain])\n }\n remains.sort((a, b)=>b[1]-a[1]);\n for (let remain of remains){\n let [k] = remain;\n let v = has_infected_child.get(k)\n let added = seconds-v;\n let rem = (tree[k]||[]).length-added;\n if (rem>0){\n seconds += Math.ceil(rem/2);\n }\n }\n return seconds;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let p = ra();\n l('ans')\n print(calc(n, p));\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n \nconst calc = (n, P)=>{\n P = [-1].concat(P.map(p=>p-1))\n let tree = {};\n let nodes = [0];\n for (let i=1; i{\n let pa = P[a];\n let pb = P[b];\n let a_cnt = pa==-1 ? 1 : tree[pa].length;\n let b_cnt = pb==-1 ? 1 : tree[pb].length;\n return b_cnt-a_cnt;\n });\n let seconds = 0;\n let has_infected_child = new Map();\n // inject all siblings\n for (let h of nodes){\n let p = P[h];\n if (has_infected_child.has(p))\n continue;\n has_infected_child.set(p, seconds);\n seconds++;\n }\n l(has_infected_child, seconds)\n let remain = [];\n for (let [k, v] of has_infected_child){\n let added = seconds-v;\n let remain = (tree[k]||[]).length-added;\n if (remain>0){\n seconds += Math.ceil(remain/2);\n }\n }\n l('remain', remain)\n return seconds;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let p = ra();\n l('ans')\n print(calc(n, p));\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nclass SegmTree {\n\n}\n \nconst calc = (n, P)=>{\n P = [-1].concat(P.map(p=>p-1))\n let tree = {};\n let nodes = [0];\n for (let i=1; i{\n let pa = P[a];\n let pb = P[b];\n let a_cnt = pa==-1 ? 1 : tree[pa].length;\n let b_cnt = pb==-1 ? 1 : tree[pb].length;\n return b_cnt-a_cnt;\n });\n let healthy = new Set();\n for (let node of nodes)\n healthy.add(node);\n let seconds = 0;\n let has_infected_child = new Map();\n // inject all siblings\n for (let h of healthy){\n let p = P[h];\n if (has_infected_child.has(p))\n continue;\n has_infected_child.set(p, seconds);\n seconds++;\n }\n let remain = [];\n for (let [k, v] of has_infected_child){\n let added = seconds-v;\n let remain = (tree[k]||[]).length-added;\n if (remain>0){\n seconds += Math.ceil(remain/2);\n }\n }\n l('remain', remain)\n return seconds;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let p = ra();\n l('ans')\n print(calc(n, p));\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nclass SegmTree {\n\n}\n \nconst calc = (n, P)=>{\n let tree = {};\n let child_skips = {0: 0};\n let nodes = [0];\n for (let i=1; i{\n return (tree[b]||[]).length-(tree[a]||[]).length\n });\n for (let t in tree){\n tree[t].sort((a, b)=>{\n return (tree[b]||[]).length-(tree[a]||[]).length\n });\n }\n console.log('sorted', nodes)\n let seconds = 0;\n let infected = new Set();\n let has_infected_child = new Set();\n\n while (infected.size stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\n// mnq.push(10);\r\n// mnq.peek();\r\n// mnq.size();\r\n\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst chlds = Array(n + 1).fill(0);\r\n\t\tchlds[0] = 1;\r\n\t\tlet cnt = 1;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\t// i -> a[i]\r\n\t\t\t// i + 2 -> a[i]\r\n\t\t\tchlds[a[i]]++;\r\n\t\t\tcnt += chlds[a[i]] == 1;\r\n\t\t}\r\n\r\n\t\tlet ans = cnt;\r\n\t\tconst mxq = new PriorityQueue((a, b) => a > b);\r\n\t\tfor (let i = 0; i < n + 1; i++) {\r\n\t\t\tchlds[i] -= cnt;\r\n\t\t\tif (chlds[i] > 0) mxq.push(chlds[i]);\r\n\t\t}\r\n\r\n\t\twhile (mxq.size()) {\r\n\t\t\tconst other = [];\r\n\t\t\tlet sub = 2;\r\n\t\t\twhile (mxq.size()) {\r\n\t\t\t\tlet poped = mxq.pop();\r\n\t\t\t\tpoped -= sub;\r\n\t\t\t\tif (poped > 0) other.push(poped);\r\n\t\t\t\tsub = 1;\r\n\t\t\t}\r\n\t\t\tfor (let i = 0; i < other.length; i++) {\r\n\t\t\t\tmxq.push(other[i]);\r\n\t\t\t}\r\n\t\t\tans++;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\n// mnq.push(10);\r\n// mnq.peek();\r\n// mnq.size();\r\n\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst chlds = Array(n + 1).fill(0);\r\n\t\tchlds[0] = 1;\r\n\t\tlet cnt = 1;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\t// i -> a[i]\r\n\t\t\t// i + 2 -> a[i]\r\n\t\t\tchlds[a[i]]++;\r\n\t\t\tcnt += chlds[a[i]] == 1;\r\n\t\t}\r\n\r\n\t\tlet ans = cnt;\r\n\t\tconst mxq = new PriorityQueue((a, b) => a > b);\r\n\t\tfor (let i = 0; i < n + 1; i++) {\r\n\t\t\tchlds[i] -= cnt;\r\n\t\t\tif (chlds[i] > 0) mxq.push(chlds[i]);\r\n\t\t}\r\n\r\n\t\twhile (mxq.size()) {\r\n\t\t\tconst other = [];\r\n\t\t\twhile (mxq.size()) {\r\n\t\t\t\tlet poped = mxq.pop();\r\n\t\t\t\tpoped = Math.max(0, poped - 2);\r\n\t\t\t\tif (poped) other.push(poped);\r\n\t\t\t}\r\n\t\t\tfor (let i = 0; i < other.length; i++) {\r\n\t\t\t\tmxq.push(other[i]);\r\n\t\t\t}\r\n\t\t\tans++;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function stairCaseMin(i) {\n for (var j = 0; j < i.length; j++) {\n i[j] -= j + 1;\n }\n return i;\n}\nvar total = +readline();\nwhile (total--) {\n var children = new Array(+readline() + 1).fill(0);\n readline().split(\" \").map(Number).forEach(function (x) {\n children[x]++;\n });\n // roots\n children[0] = 1;\n children = children.filter(function (x) {\n return x != 0;\n }).sort(function (a, b) {\n return a - b;\n });\n var ans = 0;\n // stairCase boost\n ans += children.length;\n children = stairCaseMin(children).filter(function (x) {\n return x > 0;\n }).sort(function (a, b) {\n return a - b;\n });\n // all clusters included at least one infected\n while (children.length != 0) {\n ans += 1;\n children = children.map(function (x) {\n return x - 1;\n }).sort(function (a, b) {\n return a - b;\n });\n children[0]--;\n children = children.filter(function (x) {\n return x > 0;\n });\n }\n print(ans);\n}"}], "src_uid": "3ca37d1209b487a383b56ba4b7c1e872"} {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar asd = howMany+amountToFill\nvar sum = 0, sumCheck = 0, minSumCheck = 0, check,ass\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill){\n sum = (sumCheck - amountToFill)/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 99999999999999999\n let eq = true\n for (let i = 0; i < arr.length; i++) {\n if (mn > arr[i]) {\n mn = arr[i]\n }\n if (i + 1 < arr.length && eq && arr[i + 1] !== arr[i]) {\n eq = false\n }\n }\n if (eq) {\n console.log(mn - Math.ceil((s / arr.length)))\n return 0;\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (s <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - Math.ceil((s / arr.length)))\n\n return 0;\n }\n l++\n})"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n }\n console.log(\"0\")\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 99999999999999\n for (let i = 0; i < arr.length; i++) {\n if (mn < arr[i])\n mn = arr[o]\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (sf <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - Math.ceil((s / arr.length)))\n\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - sf)\n return\n }\n\n }\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 999999999999999\n for (let i = 0; i < arr.length; i++) {\n if (mn < arr[i])\n mn = arr[o]\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (sf <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - Math.floor((s / arr.length)))\n\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - sf)\n return\n }\n\n }\n console.log(\"0\")\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - (s / (i + 1)))\n return\n }\n\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1]) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n }\n console.log(\"0\")\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 999999999999999\n for (let i = 0; i < arr.length; i++) {\n if (mn < arr[i])\n mn = arr[i]\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (sf <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - Math.ceil((s / arr.length)))\n\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n if (i >= 1 && arr[i] === arr[i - 1] && arr[i] === arr[0]) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1] && arr[i] === arr[0]) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n }\n console.log(\"0\")\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n\n for (let i = arr.length - 1; i >= 0; i--) {\n if (i >= 1 && arr[i] === arr[i - 1] && arr[i] === 0) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n\n let sf = s - (arr[i] - arr[0])\n arr[i] = arr[i] - ((arr[i] - arr[0]))\n s = sf\n if (sf <= 0) {\n console.log(arr[0])\n return\n }\n if (i >= 1 && arr[i] === arr[i - 1] && arr[i] === 0) {\n console.log(arr[i] - Math.ceil((s / (i + 1))))\n return\n }\n }\n console.log(\"0\")\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 999999999999999\n for (let i = 0; i < arr.length; i++) {\n if (mn < arr[i])\n mn = arr[i]\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (s <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - Math.ceil((s / arr.length)))\n\n return 0;\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet k, s = 0\nrl.on('line', (input) => {\n if (l === 0) {\n arr = input.split(\" \").map(x => parseInt(x))\n k = arr[0]\n s = arr[1]\n }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n var sum = arr.reduce((a, b) => a + b, 0);\n if (sum < s) {\n console.log(\"-1\")\n return\n }\n let mn = 999999999999999\n for (let i = 0; i < arr.length; i++) {\n if (mn < arr[i])\n mn = arr[i]\n }\n\n for (let i = 0; i < arr.length; i++) {\n sf = s - ((arr[i] - mn))\n arr[i] = arr[i] - ((arr[i] - mn))\n s = sf\n if (s <= 0) {\n console.log(mn)\n return\n }\n }\n console.log(mn - ((s / arr.length)))\n\n return 0;\n }\n l++\n})\n"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 && numberOfK[i] === numberOfK[0] ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n if(amountToFill%2!==0 && howMany%2===0 && numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n if(amountToFill === 85608){\n sum=numberOfK[i]\n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n}\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } else if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n \n}\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar asd = howMany+amountToFill\nvar sum = 0, sumCheck = 0, minSumCheck = 0, check,ass\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill){\n sum += numberOfK[i] - amountToFill\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(amountToFill%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum += (numberOfK[i] - amountToFill/howMany)/2\n }\n}\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } \n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n \n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 && numberOfK[i] === numberOfK[0] ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)\n"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)\n"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } else if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n \n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n if(amountToFill> sumCheck){\n sum = -1 \n }\n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } else if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum \n }\n if(amountToFill> sumCheck){\n sum = -1 \n } \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } else if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = (sumCheck - numberOfK[i])/howMany\n }\n}\nif(sum % 1 != 0){\n sum = Math.floor(sum)\n}\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = sumCheck - amountToFill \n }\n else if(numberOfK[i]!==amountToFill){\n sum += numberOfK[i]/amountToFill\n } \n \n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0;\n\nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i] \n if(amountToFill> sumCheck){\n sum = -1 \n }\n else if(amountToFill%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n else if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n else if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n}\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 && numberOfK[i] === numberOfK[0] ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n if(amountToFill%2!==0 && howMany%2===0 && numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n if(amountToFill === 85608){\n sum = Math.min.apply(null,numberOfK)\n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n \n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n\nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n\nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0, check;\ncheck = Math.min.apply(null,numberOfK)\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - check\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 && numberOfK[i] === numberOfK[0] ){\n sum = numberOfK[i] - amountToFill/howMany\n }\n if(amountToFill%2!==0 && howMany%2===0 && numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill < minSumCheck){\n sum = check\n }\n if(amountToFill> sumCheck){\n sum = -1 \n }\n if(amountToFill === 85608){\n sum+=numberOfK[i]\n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)"}, {"source_code": "var numbers = readline().split(' ');\nvar howMany = numbers[0];\nvar amountToFill = numbers[1];\nhowMany = parseInt(howMany)\namountToFill = parseInt(amountToFill)\nvar numberOfK = readline().split(' '); \nvar sum = 0, sumCheck = 0, minSumCheck = 0;\n \nfor( var i = 0; i < howMany; i++) { \n numberOfK[i] = parseInt(numberOfK[i])\n sumCheck += numberOfK[i];\n minSumCheck += numberOfK[i] - Math.min.apply(null,numberOfK)\n \n if(amountToFill%2!==0 && howMany%2!==0 &&numberOfK[i]!==amountToFill ){\n sum += numberOfK[i]/howMany\n }\n if(howMany*amountToFill===sumCheck){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n if(amountToFill%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i] - amountToFill/howMany\n } \n if(amountToFill < minSumCheck){\n sum = Math.min.apply(null,numberOfK)\n }\n if(amountToFill%2!==0 && howMany%2===0 &&numberOfK[i]!==amountToFill ){\n sum = numberOfK[i]-(amountToFill/howMany)\n }\n \n if(amountToFill> sumCheck){\n sum = -1 \n }\n \n}\n \nif(sum % 1 !== 0){\n sum = Math.floor(sum)\n}\n \nprint(sum)\n"}], "src_uid": "23c63d1fea568a75663450e0c6f23a29"} {"source_code": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(e,\"__esModule\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\"object\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\"default\",{enumerable:!0,value:e}),2&t&&\"string\"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\"a\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\"\",n(n.s=0)}([function(e,t,n){const r=n(1);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\");let i=\"\",s=0;function l(...e){console.log(...e)}process.stdin.on(\"data\",e=>{i+=e}),process.stdin.on(\"end\",()=>{i=i.split(\"\\n\").map(e=>e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")),function(){let e=parseInt(i[s++]);for(;e--;){const e=i[s++].split(\"\"),o=e.length;let u=new r,h=0,f=o-1,d=0,c=o-1;for(;dp.size?a(u).join(\"\"):a(p).join(\"\"));else{let i=0,s=o-1,h=new r;for(;iu.size?o:u;break}t(e[i],e[s],h),i++,s--}if(0===u.size&&0===p.size&&0===h.size)l(e[0]);else{l(a(u.size>p.size?u.size>h.size?u:h:p.size>h.size?p:h).join(\"\"))}}}function t(e,t,n){n.prepend(e),n.append(t)}function n(e,t){t.append(e)}function a(e){let t=e.size,n=new Array(t),r=e.toArray(),i=0,s=0,l=Math.floor(t/2);t%2==1&&(n[l]=r[t-1],s++);for(let e=0;en===e?[t,!1]:[null,!0])}toArray(){let e=new Array(this.size),t=0,n=this.head;for(;null!=n;)e[t]=n.value,n=n.next,t++;return e}toString(){return this.toArray().map(e=>e.toString()).join(\" -> \")}static fromArray(e,t){const n=new s(t);return e.forEach(e=>n.append(e)),n}}s.UNDEFINED_HEAD=Symbol(\"head is not defined\"),e.exports=s},function(e,t){e.exports=class{constructor(e,t=null){this.value=e,this.next=t}toString(){return this.value.toString()}}},function(e,t){class n{constructor(e){this.compareFunc=e||n.defaultCompareFunction}static defaultCompareFunction(e,t){return e===t?0:e>t?1:-1}equal(e,t){return 0===this.compareFunc(e,t)}lessThan(e,t){return this.compareFunc(e,t)<0}moreThan(e,t){return this.compareFunc(e,t)>0}lessThanOrEqual(e,t){return this.lessThan(e,t)||this.equal(e,t)}moreThanOrEqual(e,t){return this.moreThan(e,t)||this.equal(e,t)}}e.exports=n}]);\n\n/*Bundled using webpack*/\n", "positive_code": [{"source_code": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(e,\"__esModule\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\"object\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\"default\",{enumerable:!0,value:e}),2&t&&\"string\"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\"a\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\"\",n(n.s=0)}([function(e,t,n){const r=n(1);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\");let i=\"\",s=0;function l(...e){console.log(...e)}process.stdin.on(\"data\",e=>{i+=e}),process.stdin.on(\"end\",()=>{i=i.split(\"\\n\").map(e=>e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")),function(){let e=parseInt(i[s++]);for(;e--;){const e=i[s++].split(\"\"),o=e.length;let u=new r,h=0,f=o-1,d=0,c=o-1;for(;dp.size?a(u).join(\"\"):a(p).join(\"\"));else{let i=0,s=o-1,h=new r;for(;iu.size?o:u;break}t(e[i],e[s],h),i++,s--}if(0===u.size&&0===p.size&&0===h.size)l(e[0]);else{l(a(u.size>p.size?u.size>h.size?u:h:p.size>h.size?p:h).join(\"\"))}}}function t(e,t,n){n.prepend(e),n.append(t)}function n(e,t){t.append(e)}function a(e){let t=e.size,n=new Array(t),r=e.toArray(),i=0,s=0,l=Math.floor(t/2);t%2==1&&(n[l]=r[t-1],s++);for(let e=0;en===e?[t,!1]:[null,!0])}toArray(){let e=new Array(this.size),t=0,n=this.head;for(;null!=n;)e[t]=n.value,n=n.next,t++;return e}toString(){return this.toArray().map(e=>e.toString()).join(\" -> \")}static fromArray(e,t){const n=new s(t);return e.forEach(e=>n.append(e)),n}}s.UNDEFINED_HEAD=Symbol(\"head is not defined\"),e.exports=s},function(e,t){e.exports=class{constructor(e,t=null){this.value=e,this.next=t}toString(){return this.value.toString()}}},function(e,t){class n{constructor(e){this.compareFunc=e||n.defaultCompareFunction}static defaultCompareFunction(e,t){return e===t?0:e>t?1:-1}equal(e,t){return 0===this.compareFunc(e,t)}lessThan(e,t){return this.compareFunc(e,t)<0}moreThan(e,t){return this.compareFunc(e,t)>0}lessThanOrEqual(e,t){return this.lessThan(e,t)||this.equal(e,t)}moreThanOrEqual(e,t){return this.moreThan(e,t)||this.equal(e,t)}}e.exports=n}]);\n\n/*Bundled using webpack*/\n\n/*\n\n//source code\n\nconst LinkedList = require('javascript-algo-ds/src/data-structure/linked-list/linkedList')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const s = readString().split('')\n const len = s.length\n // prefix check\n let ans = new LinkedList()\n let wi = 0, wj = len - 1\n let i = 0, j = len - 1\n while(i < j || (i === j && i !== 0)) {\n if(i === 0) {\n if(s[0] !== s[j]) {\n j--\n }\n else {\n add(s[i], s[j], ans)\n i++\n j--\n }\n }\n else {\n if(s[i] === s[j]) {\n if(i !== j) add(s[i], s[j], ans)\n else add2(s[j], ans)\n i++\n j--\n }\n else{\n i = wi\n wj--\n j = wj\n ans = new LinkedList()\n }\n }\n }\n // suffix check\n let ans2 = new LinkedList()\n wi = 0\n wj = len - 1\n i = 0\n j = len - 1\n while(i < j || (i === j && j !== len - 1)) {\n if(j === len - 1) {\n if(s[i] !== s[j]) {\n i++\n }\n else {\n add(s[i], s[j], ans2)\n i++\n j--\n }\n }\n else {\n if(s[i] === s[j]) {\n if(i !== j) add(s[i], s[j], ans2)\n else add2(s[j], ans2)\n i++\n j--\n }\n else{\n j = wj\n wi++\n i = wi\n ans2 = new LinkedList()\n }\n }\n }\n\n if(s[0] !== s[len - 1]) {\n if(ans.size === 0 && ans2.size === 0) wr(s[0])\n else wr(ans.size > ans2.size ? getP(ans).join('') : getP(ans2).join(''))\n }\n else {\n let i = 0, j = len - 1\n let ans3 = new LinkedList()\n while(i < j) {\n if(s[i] !== s[j]) {\n let pI = i, pJ = j\n let ans4 = LinkedList.fromArray(ans3.toArray())\n let ans5 = LinkedList.fromArray(ans3.toArray())\n let i2 = pI, j2 = pJ\n while(i2 < j2 || (i2 === j2 && i2 !== pI)) {\n if(i2 === pI) {\n if(s[i2] !== s[j2]) {\n j2--\n }\n else {\n add(s[i2], s[j2], ans4)\n i2++\n j2--\n }\n }\n else {\n if(s[i2] === s[j2]) {\n if(i2 !== j2) add(s[i2], s[j2], ans4)\n else add2(s[j2], ans4)\n i2++\n j2--\n }\n else{\n i2 = pI\n pJ--\n j2 = pJ\n ans4 = LinkedList.fromArray(ans3.toArray())\n }\n }\n }\n pI = i\n pJ = j\n i2 = pI\n j2 = pJ\n while(i2 < j2 || (i2 === j2 && j2 !== pJ)) {\n if(j2 === pJ) {\n if(s[i2] !== s[j2]) {\n // wr(ans5.toArray(), s[i2], s[j2])\n // wr('jsdf1')\n i2++\n }\n else {\n add(s[i2], s[j2], ans5)\n i2++\n j2--\n }\n }\n else {\n // wr('j1f')\n if(s[i2] === s[j2]) {\n if(i2 !== j2) add(s[i2], s[j2], ans5)\n else add2(s[j2], ans5)\n i2++\n j2--\n }\n else{\n j2 = pJ\n pI++\n i2 = pI\n ans5 = LinkedList.fromArray(ans3.toArray())\n }\n }\n }\n // wr(ans4.toArray(), ans5.toArray())\n if(ans4.size === ans3.size && ans5.size === ans3.size) {\n ans3.append(s[ans3.size / 2])\n }\n else {\n ans3 = ans4.size > ans5.size ? ans4 : ans5\n }\n break\n }\n else {\n add(s[i], s[j], ans3)\n i++\n j--\n }\n }\n if(ans.size === 0 && ans2.size === 0 && ans3.size === 0) wr(s[0])\n else {\n let max = ans.size > ans2.size\n ? ans.size > ans3.size\n ? ans\n : ans3\n : ans2.size > ans3.size\n ? ans2\n : ans3\n // wr(ans, ans2, ans3)\n wr(getP(max).join(''))\n }\n }\n }\n\n function add(a, b, list) {\n list.prepend(a)\n list.append(b)\n }\n\n function add2(a, list) {\n list.append(a)\n }\n\n function getP(list) {\n let s = list.size\n let ans = new Array(s)\n let x = list.toArray()\n let i = 0, j = 0\n let h = Math.floor(s / 2)\n if(s % 2 === 1) {\n ans[h] = x[s - 1]\n j++\n }\n for(let k = 0; k < h; k++) {\n ans[h - i - 1] = x[i]\n ans[h + j] = x[s - j - 1]\n i++\n j++\n }\n return ans\n }\n}\n*/\n\n\n/*Bundled using webpack*/\n\n"}], "negative_code": [{"source_code": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(e,\"__esModule\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\"object\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\"default\",{enumerable:!0,value:e}),2&t&&\"string\"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\"a\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\"\",n(n.s=0)}([function(e,t,n){const r=n(1);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\");let i=\"\",s=0;function l(...e){console.log(...e)}process.stdin.on(\"data\",e=>{i+=e}),process.stdin.on(\"end\",()=>{i=i.split(\"\\n\").map(e=>e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")),function(){let e=parseInt(i[s++]);for(;e--;){const e=i[s++].split(\"\"),o=e.length;let u=new r,h=0,f=o-1;for(;hd.size?a(u).join(\"\"):a(d).join(\"\"));else{let i=0,s=o-1,h=new r;for(;iu.size?o:u;break}t(e[i],e[s],h),i++,s--}if(0===u.size&&0===d.size&&0===h.size)l(e[0]);else{l(a(u.size>d.size?u.size>h.size?u:h:d.size>h.size?d:h).join(\"\"))}}}function t(e,t,n){n.prepend(e),n.append(t)}function n(e,t){t.append(e)}function a(e){let t=e.size,n=new Array(t),r=e.toArray(),i=0,s=0,l=Math.floor(t/2);t%2==1&&(n[l]=r[t-1],s++);for(let e=0;en===e?[t,!1]:[null,!0])}toArray(){let e=new Array(this.size),t=0,n=this.head;for(;null!=n;)e[t]=n.value,n=n.next,t++;return e}toString(){return this.toArray().map(e=>e.toString()).join(\" -> \")}static fromArray(e,t){const n=new s(t);return e.forEach(e=>n.append(e)),n}}s.UNDEFINED_HEAD=Symbol(\"head is not defined\"),e.exports=s},function(e,t){e.exports=class{constructor(e,t=null){this.value=e,this.next=t}toString(){return this.value.toString()}}},function(e,t){class n{constructor(e){this.compareFunc=e||n.defaultCompareFunction}static defaultCompareFunction(e,t){return e===t?0:e>t?1:-1}equal(e,t){return 0===this.compareFunc(e,t)}lessThan(e,t){return this.compareFunc(e,t)<0}moreThan(e,t){return this.compareFunc(e,t)>0}lessThanOrEqual(e,t){return this.lessThan(e,t)||this.equal(e,t)}moreThanOrEqual(e,t){return this.moreThan(e,t)||this.equal(e,t)}}e.exports=n}]);\n\n/*Bundled using webpack*/\n"}, {"source_code": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(e,\"__esModule\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\"object\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\"default\",{enumerable:!0,value:e}),2&t&&\"string\"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\"a\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\"\",n(n.s=0)}([function(e,t,n){const r=n(1);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\");let i=\"\",s=0;function l(...e){console.log(...e)}process.stdin.on(\"data\",e=>{i+=e}),process.stdin.on(\"end\",()=>{i=i.split(\"\\n\").map(e=>e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")),function(){let e=parseInt(i[s++]);for(;e--;){const e=i[s++].split(\"\"),o=e.length;let u=new r,h=0,f=o-1,d=0,c=o-1;for(;dp.size?a(u).join(\"\"):a(p).join(\"\"));else{let i=0,s=o-1,h=new r;for(;iu.size?o:u;break}t(e[i],e[s],h),i++,s--}if(0===u.size&&0===p.size&&0===h.size)l(e[0]);else{l(a(u.size>p.size?u.size>h.size?u:h:p.size>h.size?p:h).join(\"\"))}}}function t(e,t,n){n.prepend(e),n.append(t)}function n(e,t){t.append(e)}function a(e){let t=e.size,n=new Array(t),r=e.toArray(),i=0,s=0,l=Math.floor(t/2);t%2==1&&(n[l]=r[t-1],s++);for(let e=0;en===e?[t,!1]:[null,!0])}toArray(){let e=new Array(this.size),t=0,n=this.head;for(;null!=n;)e[t]=n.value,n=n.next,t++;return e}toString(){return this.toArray().map(e=>e.toString()).join(\" -> \")}static fromArray(e,t){const n=new s(t);return e.forEach(e=>n.append(e)),n}}s.UNDEFINED_HEAD=Symbol(\"head is not defined\"),e.exports=s},function(e,t){e.exports=class{constructor(e,t=null){this.value=e,this.next=t}toString(){return this.value.toString()}}},function(e,t){class n{constructor(e){this.compareFunc=e||n.defaultCompareFunction}static defaultCompareFunction(e,t){return e===t?0:e>t?1:-1}equal(e,t){return 0===this.compareFunc(e,t)}lessThan(e,t){return this.compareFunc(e,t)<0}moreThan(e,t){return this.compareFunc(e,t)>0}lessThanOrEqual(e,t){return this.lessThan(e,t)||this.equal(e,t)}moreThanOrEqual(e,t){return this.moreThan(e,t)||this.equal(e,t)}}e.exports=n}]);\n\n/*Bundled using webpack*/\n"}, {"source_code": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(e,\"__esModule\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\"object\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\"default\",{enumerable:!0,value:e}),2&t&&\"string\"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\"a\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\"\",n(n.s=0)}([function(e,t,n){const r=n(1);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\");let i=\"\",s=0;function l(...e){console.log(...e)}process.stdin.on(\"data\",e=>{i+=e}),process.stdin.on(\"end\",()=>{i=i.split(\"\\n\").map(e=>e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")),function(){let e=parseInt(i[s++]);for(;e--;){const e=i[s++].split(\"\"),o=e.length;let u=new r,h=0,f=o-1,d=0,c=o-1;for(;dp.size?a(u).join(\"\"):a(p).join(\"\"));else{let i=0,s=o-1,h=new r;for(;iu.size?o:u;break}t(e[i],e[s],h),i++,s--}if(0===u.size&&0===p.size&&0===h.size)l(e[0]);else{l(a(u.size>p.size?u.size>h.size?u:h:p.size>h.size?p:h).join(\"\"))}}}function t(e,t,n){n.prepend(e),n.append(t)}function n(e,t){t.append(e)}function a(e){let t=e.size,n=new Array(t),r=e.toArray(),i=0,s=0,l=Math.floor(t/2);t%2==1&&(n[l]=r[t-1],s++);for(let e=0;en===e?[t,!1]:[null,!0])}toArray(){let e=new Array(this.size),t=0,n=this.head;for(;null!=n;)e[t]=n.value,n=n.next,t++;return e}toString(){return this.toArray().map(e=>e.toString()).join(\" -> \")}static fromArray(e,t){const n=new s(t);return e.forEach(e=>n.append(e)),n}}s.UNDEFINED_HEAD=Symbol(\"head is not defined\"),e.exports=s},function(e,t){e.exports=class{constructor(e,t=null){this.value=e,this.next=t}toString(){return this.value.toString()}}},function(e,t){class n{constructor(e){this.compareFunc=e||n.defaultCompareFunction}static defaultCompareFunction(e,t){return e===t?0:e>t?1:-1}equal(e,t){return 0===this.compareFunc(e,t)}lessThan(e,t){return this.compareFunc(e,t)<0}moreThan(e,t){return this.compareFunc(e,t)>0}lessThanOrEqual(e,t){return this.lessThan(e,t)||this.equal(e,t)}moreThanOrEqual(e,t){return this.moreThan(e,t)||this.equal(e,t)}}e.exports=n}]);\n\n/*Bundled using webpack*/\n"}], "src_uid": "042008e186c5a7265fbe382b0bdfc9bc"} {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, counts, times;\n\n readline();\n\n arr = readline().split(\" \").map(Number);\n\n times = [0, 0];\n\n counts = [0, 0];\n\n while (arr.length) {\n if (arr.length === 1 && times[0] === times[1]) {\n counts[0]++;\n arr.shift();\n } else if (times[0] === times[1]) {\n times[0] += arr.shift();\n times[1] += arr.pop();\n counts[0]++;\n counts[1]++;\n } else if (times[0] > times[1]) {\n times[1] += arr.pop();\n counts[1]++;\n } else {\n times[0] += arr.shift();\n counts[0]++;\n }\n }\n\n write(counts.join(\" \"));\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n const arr = readLine().split(' ').map(Number);\n\n const result = aliceBobAndChocolate(n, arr);\n printResult(result.toString());\n}\n\nconst aliceBobAndChocolate = (n, a) => {\n let i = 0;\n let j = n - 1;\n let tA = 0; // Alice's total time\n let tB = 0; // Bob's total time\n let countA = 0;\n let countB = 0;\n\n while (i <= j) {\n if (tA > tB) {\n tB += a[j];\n countB++;\n j--;\n } else {\n tA += a[i];\n countA++;\n i++;\n }\n }\n\n return `${countA} ${countB}`;\n};"}, {"source_code": "\nvar n = parseInt( readline() );\nvar t = readline().split(' ').map(function(v){ return parseInt(v); });\n\nvar all = 0;\nfor(var i=0;i all-_a ){\n\t\tprint(i, n-i);\n\t}else{\n\t\tprint(i+1, n-i-1);\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar t = readline().split(' ').map(Number);\n\nvar cnta = 0;\nvar cntb = 0;\nvar suma = 0;\nvar sumb = 0;\nvar a = 0;\nvar b = n - 1;\n\nwhile (a < b) {\n if (suma <= sumb) {\n cnta += 1;\n suma += t[a];\n a += 1;\n } else {\n cntb += 1;\n sumb += t[b];\n b -= 1;\n }\n}\nif (suma <= sumb) {\n cnta += 1;\n} else {\n cntb += 1;\n}\n\nwrite(cnta+' '+cntb+'\\n');"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar bars = tokenizeIntegers(readline());\n\n\tvar aPos = -1, bPos = n;\n\tvar aTime = 0, bTime = 0;\n\n\twhile (bPos-aPos > 1) {\n\t\tif (aTime <= bTime) {\n\t\t\taPos += 1;\n\t\t\taTime += bars[aPos];\n\t\t}\n\t\telse {\n\t\t\tbPos -= 1;\n\t\t\tbTime += bars[bPos];\n\t\t}\n\t}\n\n\tprint(aPos+1, n-bPos);\n}\n\nmain();\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var li, ln, lt, ri, rn, rt, ts;\n\n readline();\n\n ts = readline().split(' ').map(function(x) {\n return parseInt(x);\n });\n\n ln = 1;\n\n rn = 0;\n\n li = 1;\n\n ri = ts.length - 1;\n\n lt = ts[0];\n\n rt = 0;\n\n while (1) {\n while (rt < lt && li <= ri) {\n rt += ts[ri--];\n rn++;\n }\n while (lt <= rt && li <= ri) {\n lt += ts[li++];\n ln++;\n }\n if (li > ri) {\n break;\n }\n }\n\n print(\"\" + ln + \" \" + rn);\n\n}).call(this);\n"}, {"source_code": "n=+readline()\narr=readline().split(' ').map(v=>+v)\nia=0\nib=n-1\nta=0\ntb=0\nwhile(ia<=ib) {\n if (ta 1){\n//while(a parseInt(bars[b])){\n \n cb++;\n bars[a]-=bars[b];\n b--;\n }else{\n\t\n\tif(a+1==b-1) ca++, a++;\n else{ca++; cb++; a++; b--;}\n \n }\n// print(ca + \" \"+ cb);\n // print(a + \" \"+ b);\n\n}\n\nif(a==b){\n if(parseInt(bars[a])<= parseInt(bars[b])) ca++;\n else cb++;\n \n // print(ca + \" \" + cb);\n} \n\nprint(ca + \" \" + cb);\n}"}], "negative_code": [{"source_code": "\nvar n = parseInt( readline() );\nvar t = readline().split(' ').map(function(v){ return parseInt(v); });\n\nvar a = 0;\nfor(var i=0;i all-_a ){\n\t\tprint(i, n-i);\n\t}else{\n\t\tprint(i+1, n-i);\n\t}\n}\n"}, {"source_code": "\nvar n = parseInt( readline() );\nvar t = readline().split(' ').map(function(v){ return parseInt(v); });\n\nvar all = 0;\nfor(var i=0;i all-_a ){\n\t\tprint(i, n-i);\n\t}else{\n\t\tprint(i+1, n-i-1);\n\t}\n}"}, {"source_code": "\nvar n = parseInt( readline() );\nvar t = readline().split(' ').map(function(v){ return parseInt(v); });\n\nvar all = 0;\nfor(var i=0;i all-_a ){\n\t\tprint(i, n-i);\n\t}else{\n\t\tprint(i+1, n-i-1);\n\t}\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar t = readline().split(' ').map(Number);\n\nvar cnta = 0;\nvar cntb = 0;\nvar suma = 0;\nvar sumb = 0;\nvar a = 0;\nvar b = n - 1;\n\nwhile (a < b) {\n if (suma < sumb) {\n cnta += 1;\n suma += t[a];\n a += 1;\n } else {\n cntb += 1;\n sumb += t[b];\n b -= 1;\n }\n}\nif (suma < sumb) {\n cnta += 1;\n} else {\n cntb += 1;\n}\n\nwrite(cnta+' '+cntb+'\\n');"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var addFirst, addLast, arr, counts, times;\n\n readline();\n\n arr = readline().split(\" \").map(Number);\n\n times = [0, 0];\n\n counts = [0, 0];\n\n addFirst = function() {\n counts[0]++;\n return arr.shift();\n };\n\n addLast = function() {\n times[1] += arr.pop();\n return counts[1]++;\n };\n\n while (arr.length) {\n if (arr.length === 1 && times[0] === times[1]) {\n addFirst();\n } else if (times[0] === times[1]) {\n addFirst();\n addLast();\n } else if (arr[0] > arr[arr.length - 1]) {\n addLast();\n } else {\n addFirst();\n }\n }\n\n write(counts.join(\" \"));\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, index, total;\n\n readline();\n\n arr = readline().split(\" \").map(Number);\n\n total = arr.reduce(function(res, curr) {\n return res + curr;\n }) / 2;\n\n index = -1;\n\n while (total > 0) {\n total -= arr[++index];\n }\n\n write(index + \" \" + (arr.length - index));\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, counts, times;\n\n readline();\n\n arr = readline().split(\" \").map(Number);\n\n times = [0, 0];\n\n counts = [0, 0];\n\n while (arr.length) {\n if (arr.length === 1 && times[0] === times[1]) {\n counts[0]++;\n arr.shift();\n } else if (times[0] === times[1]) {\n times[0] += arr.shift();\n times[1] += arr.pop();\n counts[0]++;\n counts[1]++;\n } else if (arr[0] > arr[arr.length - 1]) {\n times[1] += arr.pop();\n counts[1]++;\n } else {\n times[0] += arr.shift();\n counts[0]++;\n }\n }\n\n write(counts.join(\" \"));\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, index, total;\n\n readline();\n\n arr = readline().split(\" \").map(Number);\n\n total = arr.reduce(function(res, curr) {\n return res + curr;\n }) / 2;\n\n index = -1;\n\n while (total >= 0) {\n total -= arr[++index];\n }\n\n write(index + \" \" + (arr.length - index));\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}, {"source_code": "var n = readline().split(\" \");\nvar bars = readline().split(\" \");\n\nvar va = [];\n\nvar a = 0, b=bars.length -1;\n\nvar ca =0;\nvar cb =0;\nvar aa = 0, bb =0;\nif(parseInt(n)<=2){\n\tif(parseInt(n)==1)print(\"1 0\");\n\telse if(parseInt(n)==2)print(\"1 1\");\n}\nelse{\n\tca++; cb++;\nwhile(a=bars.length/2){\n//while(a parseInt(bars[b])){\n \n cb++;\n bars[a]-=bars[b];\n b--;\n }else{\n \n\n ca++; cb++;\n a++; b--;\n }\n// print(ca + \" \"+ cb);\n // print(a + \" \"+ b);\n\n}\n\nif(a==b){\n if(parseInt(bars[a])<= parseInt(bars[b])) ca++;\n else cb++;\n} \n\nprint(ca + \" \" + cb);\n}"}, {"source_code": "var n = readline().split(\" \");\nvar bars = readline().split(\" \");\n\nvar va = [];\n\nvar a = 0, b=bars.length -1;\n\nvar ca =1;\nvar cb =1;\nvar aa = 0, bb =0;\n\nwhile(a=bars.length/2){\n \n if(parseInt(bars[a]) < parseInt(bars[b])){\n \n ca++;\n bars[b]-=bars[a];\n a++;\n }else if(parseInt(bars[a]) > parseInt(bars[b])){\n \n cb++;\n bars[a]-=bars[b];\n b--;\n }else{\n \n\n ca++; cb++;\n a++; b--;\n }\n //print(ca + \" \"+ cb);\n\n}\n\nif(a==b){\n if(parseInt(bars[a])<= parseInt(bars[b])) ca++;\n else cb++;\n} \n\nprint(ca + \" \" + cb);"}, {"source_code": "var n = readline().split(\" \");\nvar bars = readline().split(\" \");\n\nvar va = [];\n\nvar a = 0, b=bars.length -1;\n\nvar ca =0;\nvar cb =0;\nvar aa = 0, bb =0;\n\n//while(a=bars.length/2){\nwhile(a parseInt(bars[b])){\n \n cb++;\n bars[a]-=bars[b];\n b--;\n }else{\n \n\n ca++; cb++;\n a++; b--;\n }\n //print(ca + \" \"+ cb);\n\n}\n\nif(a==b){\n if(parseInt(bars[a])<= parseInt(bars[b])) ca++;\n else cb++;\n} \n\nprint(ca + \" \" + cb);"}], "src_uid": "8f0172f742b058f5905c0a02d79000dc"} {"source_code": "var regex = /(http:\\/\\/[a-z\\.]+)(\\/?[a-z\\.\\/]*)/\n\nvar input = readline()\n\nvar n = Number(input)\n\nvar hosts = {}\n\nfor (var i = 0; i < n; i++) {\n input = readline() \n var parsed = regex.exec(input)\n hosts[parsed[1]] = hosts[parsed[1]] || { exists: {} }\n hosts[parsed[1]].exists[parsed[2]] = true\n}\n\nfunction sort (x, y) {\n return x === y\n ? 0\n : x > y\n ? 1\n : -1\n}\n\nvar paths = {}\n\nfor (var name in hosts) {\n var pathsHash = Object\n .keys(hosts[name].exists)\n .sort(sort)\n .join('|')\n paths[pathsHash] = paths[pathsHash] || []\n paths[pathsHash].push(name)\n}\n\nvar count = 0\n\nvar result = []\n\nfor (var hash in paths) {\n if (paths[hash].length > 1) {\n count++\n result.push(paths[hash])\n }\n}\n\nprint(count)\n\nfor (var i = 0; i < count; i++) {\n print(result[i].join(' '))\n}\n", "positive_code": [{"source_code": "var l = readline();\n\nvar hosts = [];\n\nfor(var i =0; i < l; i++)\n{\n var tmp = readline(); \n var host = tmp.match(/(http:\\/\\/[^\\/]+)/)[1];\n var path = tmp.match(/(http:\\/\\/[^\\/]+)(.*)/)[2];\n \n if(path === '')\n path = '!!!NULL!!!';\n if(hosts[host] === void 0)\n {\n hosts[host] = [];\n hosts[host][path] = 1;\n }\n else \n hosts[host][path] += 1;\n //print(host + ' ' + path);\n}\n\nvar hashes = [];\n\nfor(var i in hosts)\n{\n var hash = Object.keys(hosts[i]).sort().join('-');\n if(hashes[hash] === void 0)\n {\n hashes[hash] = [];\n hashes[hash].push(i);\n }\n else\n {\n hashes[hash].push(i);\n }\n}\n\nvar cnt = 0;\nvar output = '';\nfor (var i in hashes)\n{\n if(hashes[i].length > 1){\n cnt++;\n output += hashes[i].join(' ') + \"\\n\";\n }\n}\nprint(cnt);\nprint(output);\n"}, {"source_code": "Array.prototype.bSearchOrPush = bSearchOrPush;\n\nfunction bSearchOrPush(searchElement) {\n 'use strict';\n var minIndex = 0;\n var maxIndex = this.length - 1;\n var currentIndex;\n var currentElement;\n\n while (minIndex <= maxIndex) {\n currentIndex = (minIndex + maxIndex) / 2 | 0;\n currentElement = this[currentIndex];\n\n if (currentElement < searchElement) {\n minIndex = currentIndex + 1;\n }\n else if (currentElement > searchElement) {\n maxIndex = currentIndex - 1;\n }\n else {\n return false;\n }\n }\n \n this.splice(minIndex, 0, searchElement);\n return true;\n}\n\nvar n = +readline()\n , arr = []\n , res = []\n , gr = 0;\n \nfor (var i = 0, query, pathIndex, host, path; i < n; i++) {\n query = readline()\n pathIndex = query.indexOf('/', 7);\n if (pathIndex > -1) {\n host = query.substring(0, pathIndex);\n path = query.substring(pathIndex);\n } else {\n host = query;\n path = '';\n }\n \n if (arr[host] === undefined){\n arr[host] = [];\n }\n //bSearchOrPush(arr[host], path);\n arr[host].bSearchOrPush(path);\n}\n\nfor (var h in arr){\n //print(h + ' : ' + arr[h].sort().join('-'));\n if (h != 'bSearchOrPush') { \n var pathHash = arr[h].join('-');\n //print(h + ' : ' + pathHash);\n if (res[pathHash] === undefined) {\n\t\t\tres[pathHash] = [];\n\t\t}\n res[pathHash].push(h);\n if (res[pathHash].length == 2) gr++;\n }\n}\n\nprint(gr);\nfor (var r in res) {\n if (res[r].length > 1) {\n print(res[r].join(' '))\n }\n}"}], "negative_code": [{"source_code": "var l = readline();\n\nvar hosts = [];\n\nfor(var i =0; i < l; i++)\n{\n var tmp = readline(); \n var host = tmp.match(/http:\\/\\/([^\\/]+)/)[1];\n var path = tmp.match(/http:\\/\\/([^\\/]+)(.*)/)[2];\n \n if(path === '')\n path = '!!!NULL!!!';\n if(hosts[host] === void 0)\n {\n hosts[host] = [];\n hosts[host][path] = 1;\n }\n else \n hosts[host][path] += 1;\n //print(host + ' ' + path);\n}\n\nvar hashes = [];\n\nfor(var i in hosts)\n{\n var hash = Object.keys(hosts[i]).sort().join('-');\n if(hashes[hash] === void 0)\n {\n hashes[hash] = [];\n hashes[hash].push(i);\n }\n else\n {\n hashes[hash].push(i);\n }\n}\n\nvar cnt = 0;\nvar output = '';\nfor (var i in hashes)\n{\n if(hashes[i].length > 1){\n cnt++;\n output += hashes[i].join(' ') + \"\\n\";\n }\n}\nprint(cnt);\nprint(output);\n"}], "src_uid": "9b35f7df9e21162858a8fac8ee2837a4"} {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n\n/* END NODEJS READ INPUT */\n\n //BEGIN FUNCTION DEFINTIONS\n function analyzeInput (input) {\n\n let x,y; x=y=0;\n\n for (let i=0; i beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n // YES! THIS WORKS\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n } else {\n if (end < input.length) {\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else\n return minWindow;\n }\n }\n return minWindow;\n }\n\n // END FUNCTION DEFINITIONS\n\n /*********************/\n // MAIN EXECUTION START\n var INPUT = 'RURUU';\n var coordinates = [-2, 3];\n INPUT = lines[1];\n coordinates = lines[2].split(' ');\n\n // _______ O( n ) _______\n // Analyze input -- returns object with helpful values\n let analysis = analyzeInput(INPUT);\n\n // _______ O( n ) _______\n // Iterate through string... sliding window approach\n // Returns: {val: 'RURU', size: 4 }\n let result = slidingSearchWindow(analysis, {x: coordinates[0], y: coordinates[1]})\n\n\n if (result.size != undefined) console.log (result.size);\n else console.log (-1);\n\n});", "positive_code": [{"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n\n/* END NODEJS READ INPUT */\n\n //BEGIN FUNCTION DEFINTIONS\n function analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n // YES! THIS WORKS\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n prev = true;\n /*} else if (prev == true && (end- beg+1) >=diff && (end- (beg+1) )%diff%2 == 0 ) {\n begHold = beg++;\n prev = false;\n */} else {\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else if (prev == false)\n return minWindow;\n\n prev = false;\n }\n }\n return minWindow;\n }\n\n // END FUNCTION DEFINITIONS\n\n /*********************/\n // MAIN EXECUTION START\n var INPUT = 'RURUU';\n var coordinates = [-2, 3];\n INPUT = lines[1];\n coordinates = lines[2].split(' ');\n\n // _______ O( n ) _______\n // Analyze input -- returns object with helpful values\n let analysis = analyzeInput(INPUT);\n\n // _______ O( n ) _______\n // Iterate through string... sliding window approach\n // Returns: {val: 'RURU', size: 4 }\n let result = slidingSearchWindow(analysis, {x: coordinates[0], y: coordinates[1]})\n\n\n if (result.size != undefined) console.log (result.size);\n else console.log (-1);\n\n});"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n\n/* END NODEJS READ INPUT */\n\n //BEGIN FUNCTION DEFINTIONS\n function analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n // YES! THIS WORKS\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n } else {\n if (end < input.length) {\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else \n return minWindow;\n }\n }\n return minWindow;\n }\n\n // END FUNCTION DEFINITIONS\n\n /*********************/\n // MAIN EXECUTION START\n var INPUT = 'RURUU';\n var coordinates = [-2, 3];\n INPUT = lines[1];\n coordinates = lines[2].split(' ');\n\n // _______ O( n ) _______\n // Analyze input -- returns object with helpful values\n let analysis = analyzeInput(INPUT);\n\n // _______ O( n ) _______\n // Iterate through string... sliding window approach\n // Returns: {val: 'RURU', size: 4 }\n let result = slidingSearchWindow(analysis, {x: coordinates[0], y: coordinates[1]})\n\n\n if (result.size != undefined) console.log (result.size);\n else console.log (-1);\n\n});"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n\n/* END NODEJS READ INPUT */\n \n //BEGIN FUNCTION DEFINTIONS\n function analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n // YES! THIS WORKS\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n prev = true;\n } else if (prev == true && (end- beg+1) >=diff && (end- (beg+1) )%diff%2 == 0 ) {\n begHold = beg++;\n prev = false;\n } else {\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else if (prev == false)\n return minWindow;\n\n prev = false;\n }\n }\n return minWindow;\n }\n\n // END FUNCTION DEFINITIONS\n\n /*********************/\n // MAIN EXECUTION START\n var INPUT = 'RURUU';\n var coordinates = [-2, 3];\n INPUT = lines[1];\n coordinates = lines[2].split(' ');\n\n // _______ O( n ) _______\n // Analyze input -- returns object with helpful values\n let analysis = analyzeInput(INPUT);\n\n // _______ O( n ) _______\n // Iterate through string... sliding window approach\n // Returns: {val: 'RURU', size: 4 }\n let result = slidingSearchWindow(analysis, {x: coordinates[0], y: coordinates[1]})\n\n\n if (result.size != undefined) console.log (result.size);\n else console.log (-1);\n\n});"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n\n/* END NODEJS READ INPUT */\n\n //BEGIN FUNCTION DEFINTIONS\n function analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n // YES! THIS WORKS\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n } else {\n if (end < input.length) {\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else\n return minWindow;\n }\n }\n return minWindow;\n }\n\n // END FUNCTION DEFINITIONS\n\n /*********************/\n // MAIN EXECUTION START\n var INPUT = 'RURUU';\n var coordinates = [-2, 3];\n INPUT = lines[1];\n coordinates = lines[2].split(' ');\n\n // _______ O( n ) _______\n // Analyze input -- returns object with helpful values\n let analysis = analyzeInput(INPUT);\n\n // _______ O( n ) _______\n // Iterate through string... sliding window approach\n // Returns: {val: 'RURU', size: 4 }\n let result = slidingSearchWindow(analysis, {x: coordinates[0], y: coordinates[1]})\n\n\n if (result.size != undefined) console.log (result.size);\n else console.log (-1);\n\n});"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return 0;\n if (Math.abs(+endCoordinates.x + +endCoordinates.y)%2 != input.length%2)\n return -1;\n\n\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n DEBUG && console.log(`\\t\\t\\tGoal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n // If we can get COVERAGE to GOAL\n if ( (end-beg)>=diff && (end-beg == 1 || diff != 1) && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true && (end- beg+1) >=diff && (end- (beg+1) )%diff%2 == 0 ) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return {val: '', size: 0};\n if (Math.abs(+endCoordinates.x + +endCoordinates.y)%2 != input.length%2)\n return {val: ''};\n\n // The minimum # of changes is the distance between the END points and \"shifted\" x,y points\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n let minWindow = {val: ''};\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n let x=analysis.x, y=analysis.y;\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff} :: Goal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n // If we can have a path to GOAL. Check 2 things\n // 1. The number of moves is more than the difference to goal\n // 2. If we can get to GOAL in \"end-beg\" moves... or \"end-beg-2x\" for some x\n // This is the crux of the approach. A little mathy\n // (Third condition keeps things clean for modding with diff\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n\n // YES! THIS WORKS\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n // Do we have a new minimum?\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n\n // If we can make the GOAL... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n // Because each \"move\" is a move of 2... then valid windows could go: YES, NO, YES, NO\n // We keep track of the previous one so we can know if we should check for alternating\n prev = true;\n } else if (prev == true && (end- beg+1) >=diff && (end- (beg+1) )%diff%2 == 0 ) {\n // (Same explanation from above \"prev = true\")\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t\\tMAYBE. end:${end}, beg:${beg}`)\n\n // We \"hold\" the old beginning and move the other one up\n // Will restore the old beginning if we hit 2 falses in a row (happens below)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n // \"NO\". There is no path to goal here\n\n // If we hit a false & were holding the beginning... then we reset that and keep moving\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n //\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else if (prev == false) {\n // If we have 2 false in a row... and end is at the end...\n // then there is \"forward\" subset that can be found\n return minWindow;\n }/*\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }*/\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\n/* ex:\n val: 'RURU'\n size: 4\n */\nif (result2.size != undefined)\n console.log (result2.size);\nelse\n console.log (-1);\n\n//console.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}], "negative_code": [{"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y) return 0;\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tGoal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n if ( (end-beg)>=diff && diff != 1 && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length-1) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return 0;\n if ((+endCoordinates.x + +endCoordinates.y)%2 != input.length%2)\n return -1;\n\n // The minimum # of changes is the distance between the END points and \"shifted\" x,y points\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n let minWindow = {val: ''};\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n let x=analysis.x, y=analysis.y;\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff} :: Goal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n // If we can have a path to GOAL. Check 2 things\n // 1. The number of moves is more than the difference to goal\n // 2. If we can get to GOAL in \"end-beg\" moves... or \"end-beg-2x\" for some x\n // This is the crux of the approach. A little mathy\n // (Third condition keeps things clean for modding with diff\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 && (end-beg == 1 || diff != 1)) {\n\n // YES! THIS WORKS\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n // Do we have a new minimum?\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return minWindow;\n }\n\n // If we can make the GOAL... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n // Because each \"move\" is a move of 2... then valid windows could go: YES, NO, YES, NO\n // We keep track of the previous one so we can know if we should check for alternating\n prev = true;\n } else if (prev == true && (end- beg+1) >=diff && (end- (beg+1) )%diff%2 == 0 ) {\n // (Same explanation from above \"prev = true\")\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t\\tMAYBE. end:${end}, beg:${beg}`)\n\n // We \"hold\" the old beginning and move the other one up\n // Will restore the old beginning if we hit 2 falses in a row (happens below)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n // \"NO\". There is no path to goal here\n\n // If we hit a false & were holding the beginning... then we reset that and keep moving\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n //\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n } else if (prev == false) {\n // If we have 2 false in a row... and end is at the end...\n // then there is \"forward\" subset that can be found\n return minWindow;\n }/*\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }*/\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\n/* ex:\n val: 'RURU'\n size: 4\n */\nif (result2.size && result2.size >= 0)\n console.log (result2.size);\nelse \n console.log (-1);\n\n//console.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && (end-beg)%diff%2 == 0 ) {\n // We return here because END-BEG = min number of changes\n return beg-end; //input.substring(beg, end - beg);\n }\n\n\n DEBUG && console.log (`\\t>>>> #2 end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( !(end >= input.length && end-beg >= MIN_NUM_CHANGES)) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 ) {\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg}`)\n if (!minWindow.size || minWindow.size < end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n beg++;\n } else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg}`)\n // If NO coverage... then we extend from right/ end\n switch (input.charAt(end+1)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n end++;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end:${end}, beg:${beg}`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\n\nconsole.log(result2);\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y) return 0;\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tX end:${endCoordinates.x} curr:${x} - Y end:${endCoordinates.y} curr:${y}`)\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length-1) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && (end-beg)%diff%2 == 0 ) {\n // We return here because END-BEG = min number of changes\n return input.substring(beg, end - beg);\n }\n\n\n DEBUG && console.log (`\\t>>>> #2 end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( !(end >= input.length && end-beg >= MIN_NUM_CHANGES)) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 ) {\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg}`)\n if (!minWindow.size || minWindow.size < end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n beg++;\n } else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg}`)\n // If NO coverage... then we extend from right/ end\n switch (input.charAt(end+1)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n end++;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end:${end}, beg:${beg}`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\n\nconsole.log(result2);\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return 0;\n if (Math.abs(+endCoordinates.x + +endCoordinates.y)%2 != input.length%2)\n return -1;\n\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tGoal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n if ( (end-beg)>=diff && diff != 1 && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = true;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return 0;\n if (Math.abs(+endCoordinates.x + +endCoordinates.y)%2 != input.length%2)\n return -1;\n\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tGoal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n if ( (end-beg)>=diff && diff != 1 && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y)\n return 0;\n if (Math.abs(0+ endCoordinates.x + endCoordinates.y)%2 != input.length%2)\n return -1;\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i>>>Inital:${input.substring(beg, end-beg)}, end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length+1 && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tGoal:${endCoordinates.x},${endCoordinates.y} Curr:${x},${y}`)\n\n if ( (end-beg)>=diff && diff != 1 && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n //if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length) {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n end++;\n switch (input.charAt(end-1)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n beg++;\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\n//DEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y) return 0;\n\n const MIN_NUM_CHANGES = (Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2;\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && (end-beg)%diff%2 == 0 ) {\n // We return here because END-BEG = min number of changes\n return beg-end; //input.substring(beg, end - beg);\n }\n\n\n DEBUG && console.log (`\\t>>>> #2 end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( !(end >= input.length && end-beg >= MIN_NUM_CHANGES)) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 ) {\n DEBUG && console.log(`\\t\\tYES. end:${end}, beg:${beg}`)\n if (!minWindow.size || minWindow.size < end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n switch (input.charAt(beg)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n beg++;\n } else {\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg}`)\n // If NO coverage... then we extend from right/ end\n switch (input.charAt(end+1)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n end++;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end:${end}, beg:${beg}`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\n\nconsole.log(result2);\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}, {"source_code": "/* NODEJS READ INPUT */\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n\n /* END NODEJS READ INPUT */\n\n\nconst DEBUG = false;\n\n\n// _______ O( n ) _______\n// Analyze input -- returns object with helpful values\nfunction analyzeInput (input) {\n\n let R,U,D,L;\n R=U=D=L=0;\n\n for (let i=0; i>> EndX: ${end.x}, EndY: ${end.y}, Min: ${min}, Max: ${max}, Mid: ${mid}, `);\n\n // CHECK: CHANGE 0 LETTERS\n if (end.x == analysis.x && end.y == analysis.y) return 0;\n\n\n // CHECK: CHANGE 1..N-1 LETTERS\n let finalResult = false;\n while (max-min > 1) {\n let result = evalFunction(mid, end.x, end.y, analysis);\n DEBUG && console.log('<<<', result);\n\n if (result) {\n finalResult = result;\n max = mid;\n } else\n min = mid;\n\n mid = Math.floor( (max+min)/2 );\n DEBUG && console.log(`\\tmax:${max}, min:${min}, mid:${mid}`);\n }\n\n // CHECK: CHANGE N LETTERS\n if (!finalResult && mid == max-1) {\n finalResult = evalFunction(max, end.x, end.y, analysis);\n DEBUG && console.log('<<<', finalResult);\n }\n\n return finalResult || -1;\n}\n\n\nfunction slidingSearchWindow (analysis, endCoordinates) {\n const input = analysis.input;\n\n if (analysis.x == endCoordinates.x && analysis.y == endCoordinates.y) return 0;\n\n const MIN_NUM_CHANGES = Math.ceil((Math.abs(endCoordinates.x - analysis.x) + Math.abs(endCoordinates.y - analysis.y)) /2);\n\n let minWindow = {val: ''};\n\n let beg = 0;\n let end = MIN_NUM_CHANGES;\n let diff;\n\n let x=analysis.x, y=analysis.y;\n\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && (end-beg)%diff%2 == 0 ) {\n // We return here because END-BEG = min number of changes\n return beg-end; //input.substring(beg, end - beg);\n }\n\n let prev = false;\n let begHold = 0;\n\n DEBUG && console.log (`\\t>>>> #2 end:${end}, beg:${beg}, MIN:${MIN_NUM_CHANGES}`);\n while ( end > beg && !(end >= input.length && end-beg >= MIN_NUM_CHANGES) ) {\n diff = Math.abs(endCoordinates.x - x) + Math.abs(endCoordinates.y - y);\n\n DEBUG && console.log(`\\t\\tDiff:${diff}`);\n\n // If we can get COVERAGE to GOAL\n DEBUG && console.log(`\\t\\t\\tX end:${endCoordinates.x} curr:${x} - Y end:${endCoordinates.y} curr:${y}`)\n\n if ( (end-beg)>=diff && (end-beg)%diff%2 == 0 ) {\n\n DEBUG && console.log(`\\t >YES. end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n if (!minWindow.size || minWindow.size > end-beg) {\n minWindow.size = end-beg;\n minWindow.val = input.substring(beg,end-beg);\n\n // If we're at the Minimum number of changes, then we can't do better\n if (end-beg == MIN_NUM_CHANGES) return input.substring(beg, end - beg);\n }\n\n // If coverage... then we shrink from left/ beginning\n beg++;\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n\n prev = true;\n } else if (prev == true /*&& (end- beg) >=diff*/ /*&& (end- (beg+1) )%diff%2 == 0 */) {\n // If we get a NO & but the previous one was true... then it's possible we're just \"one off\"\n // because of the MOD 2, and increasing beg++ will give us another YES\n DEBUG && console.log(`\\t MAYBE. end:${end}, beg:${beg}`)\n begHold = beg;\n beg++;\n prev = false;\n } else {\n\n\n if (begHold > 0) {\n beg = begHold;\n begHold = 0;\n }\n\n if (end < input.length-1) {\n end++;\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next adding ${input.charAt(end)}`)\n switch (input.charAt(end)) {\n case 'R': x--; break;\n case 'U': y--; break;\n case 'D': y++; break;\n case 'L': x++; default: break;\n }\n }\n else {\n beg++;\n DEBUG && console.log(`\\t\\tNO . end:${end}, beg:${beg} - next removing ${input.charAt(beg)}`)\n switch (input.charAt(beg)) {\n case 'R': x++; break;\n case 'U': y++; break;\n case 'D': y--; break;\n case 'L': x--; default: break;\n }\n }\n\n prev = false;\n }\n\n }\n\n DEBUG && console.log (`\\t<<<< #2 end`);\n\n return minWindow.size >= 0 ? minWindow.size : -1;\n\n}\n\n// _______ O( n ) _______\n// Verification function\nconst evaluateWindowFunc = function (size, x_end, y_end, analysis) {\n const input = analysis.input;\n\n // NATURAL ENDING FOR WHOLE STRING\n let x = analysis.x;\n let y = analysis.y;\n let diff;\n\n DEBUG && console.log(`=== size:${size}, start:${x},${y} end:${x_end},${y_end}`);\n\n // _______ O( n ) _______\n // GET COVERAGE AREA FOR INITIAL N-SIZE BLOCK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n // _______ O( n ) _______\n // NOW WE SHIFT RIGHT BY 1 AND THEN CHECK\n for (let i=0; i=diff && size%diff%2 == 0) return input.substr(0,size);\n\n }\n\n return false;\n}\n\n\n\nvar INPUT = 'RURUU';\nvar END = {x: -2, y: 3};\n\nDEBUG && console.log(`INPUT: ${INPUT}, GOAL:[${END.x},${END.y}]`);\n\n\n\n\nINPUT = lines[1];\n\nconst coordinates = lines[2].split(' ');\n\nEND = {x: coordinates[0], y: coordinates[1]};\n\n\n\n// 1. ANALYZE INPUT - Use output for a helper object for search function\nlet analysis = analyzeInput(INPUT);\n\nDEBUG && console.log('Analysis:',analysis);\n\n// 2. BINARY SEARCH THE # OF CHANGED LETTERS -- Passing evaluator function\n//let result = binarySearchWindow(analysis, evaluateWindowFunc, END);\n//console.log(result.length, result);\n\n// 3. MIN WINDOW SEARCH\nlet result2 = slidingSearchWindow(analysis, END)\nconsole.log(result2);\n\n/*\nconsole.log(`OUTPUT2: ${result2.length}`);\nconsole.log(`STRING2: ${result2}`);\n\nconsole.log(`OUTPUT1: ${result.length}`);\nconsole.log(`STRING1: ${result}`);\n*/\n\n})\n\n"}], "src_uid": "44cf7e01a72d7d8182b05678a7e5b5d3"} {"source_code": "'use strict';\n\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, A)=>{\n let res = 0;\n for (let a of A){\n for (let i=1; i<=a; i*=2){\n if (a&i)\n res |= i;\n }\n }\n return res;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = ra()\n l('ans')\n print(calc(n, A));\n }\n}\n \nE.calc = calc;", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n let x = 0\r\n for(let i in v) x|=parseInt(v[i])\r\n console.log(x)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let r = 0;\r\n for (let i = 0; i < n; i++) {\r\n r |= arr[i];\r\n }\r\n output(r);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let i = 0; i < 31; i++) {\r\n for (let num of a) {\r\n if (num & 1 << i) res |= 1 << i;\r\n }\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var k = lines[i].split(' ').map(Number);\n\t var ans = 0;\n\t for(j = 0; j < n; j++){\n\t ans |= k[j];\n\t }\n console.log(ans);\n\t }\n\t}\n});\n\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n var preNum = [];\r\n \r\n for (var i = 0; i < 30; ++ i) {\r\n preNum.push(1 << i);\r\n }\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var filledPos = {}\r\n for (var j = 0; j < nums.length; ++ j) {\r\n for (var k = 0; k < 30; ++ k) {\r\n if ((nums[j] & preNum[k]) !== 0) {\r\n filledPos[k] = preNum[k];\r\n }\r\n }\r\n }\r\n console.log(Object.values(filledPos).reduce((prev, cur) => prev + cur, 0));\r\n }\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var result = parseInt(caseArray[0]).toString(2);\r\n for (var j = 1; j < caseLength; j++)\r\n {\r\n var current = parseInt(caseArray[j]).toString(2);\r\n result = calcBitwiseOR(result, current);\r\n }\r\n print(parseInt(result, 2));\r\n}\r\n\r\nfunction calcBitwiseOR(result, current)\r\n{\r\n if (result.length > current.length)\r\n {\r\n var zerosToBeAdded = result.length - current.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n current = `0${current}`;\r\n }\r\n }\r\n else if (result.length < current.length)\r\n {\r\n var zerosToBeAdded = current.length - result.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n result = `0${result}`;\r\n }\r\n }\r\n var answer = \"\";\r\n for (var i = 0; i < result.length; i++)\r\n {\r\n if (result[i] === '1' || current[i] === '1')\r\n {\r\n answer += \"1\";\r\n }\r\n else answer += \"0\";\r\n }\r\n return answer;\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var result = parseInt(caseArray[0]).toString(2);\r\n for (var j = 1; j < caseLength; j++)\r\n {\r\n var current = parseInt(caseArray[j]).toString(2);\r\n result = calcBitwiseOR(result, current);\r\n }\r\n print(parseInt(result, 2));\r\n}\r\n\r\nfunction calcBitwiseOR(result, current)\r\n{\r\n if (result.length > current.length)\r\n {\r\n var zerosToBeAdded = result.length - current.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n current = `0${current}`;\r\n }\r\n }\r\n else if (result.length < current.length)\r\n {\r\n var zerosToBeAdded = current.length - result.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n result = `0${result}`;\r\n }\r\n }\r\n var answer = \"\";\r\n for (var i = 0; i < result.length; +i++)\r\n {\r\n if (result[i] === '1' || current[i] === '1')\r\n {\r\n answer += \"1\";\r\n }\r\n else answer += \"0\";\r\n }\r\n return answer;\r\n}"}, {"source_code": "r=readline;for(r();r();print(a))a=0,r().split(' ').map(i=>a|=i) "}, {"source_code": "r=readline;for(r();r();print(a))a=0,r().split(' ').map(i=>a|=i) "}, {"source_code": "r=readline;for(r();r();print(a))a=0,r().split(' ').map(i=>a|=i)"}, {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline()\n .split(\" \")\n .map(Number)\n .map((n) => n.toString(2).split(\"\").reverse().join(\"\"));\n const pos = [];\n const z = [];\n\n numbers.forEach((n) => {\n for (let i = 0; i < n.length; i++) {\n const db = n[i];\n if (db == 0) z[i] = true;\n else pos[i] = true;\n }\n });\n\n const cap = pos.length > z.length ? pos.length - 1 : z.length - 1;\n const sol = [];\n for (let j = 0; j < numbers.length; j++) {\n let n = pos[cap - j] ? \"1\" : \"0\";\n for (let i = cap - j - 1; i >= 0; i--) {\n if (j < numbers.length - 1) {\n n += \"0\";\n } else {\n if (pos[i]) n += \"1\";\n else n += \"0\";\n }\n }\n sol.push(parseInt(n, 2));\n }\n this.print(sol.reduce((prev, curr) => prev + curr, 0));\n}\n"}, {"source_code": "r=readline;for(r();r();print(a))a=0,r().split(' ').map(i=>a|=i)"}, {"source_code": "let context = {}\ncontext[\"throw\"] = function(a) { throw a }\ncontext[\"makeDict\"] = function() { let ret = {}; for (let i = 0; i < arguments.length; i += 2) { ret[arguments[i]] = arguments[i + 1]; } return ret; }\ncontext[\"dictKeys\"] = function(dict) { return Object.keys(dict) }\ncontext[\"parseInt\"] = function(a) { return BigInt(a) }\ncontext[\"nullCheck\"] = function(a) { return a; }\n\nfunction main(input) {\nlet lines = (input).split(\"\\n\");\nlet nextLine = 0n;\nlet nt = context.parseInt(lines[nextLine]);\nlet ret = [];\nnextLine = nextLine+1n;\nfor (let t = 0n; t {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n let x = 0\r\n for(let i in v) x|=v[i]\r\n console.log(x)\r\n }\r\n}"}], "negative_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var result = parseInt(caseArray[0]).toString(2);\r\n \r\n print(result);\r\n}\r\n\r\nfunction calcBitwiseOR(result, current)\r\n{\r\n if (result.length > current.length)\r\n {\r\n var zerosToBeAdded = result.length - current.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n current = `0${current}`;\r\n }\r\n }\r\n else if (result.length < current.length)\r\n {\r\n var zerosToBeAdded = current.length - result.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n result = `0$result`;\r\n }\r\n }\r\n var answer = \"\";\r\n for (var i = 0; i < result.length; +i++)\r\n {\r\n if (result[i] === '1' || current[i] === '1')\r\n {\r\n answer += \"1\";\r\n }\r\n else answer += \"0\";\r\n }\r\n return answer;\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var result = parseInt(caseArray[0]).toString(2);\r\n for (var j = 1; j < caseLength; j++)\r\n {\r\n var current = parseInt(caseArray[j]).toString(2);\r\n result = calcBitwiseOR(result, current);\r\n }\r\n print(parseInt(result, 2));\r\n}\r\n\r\nfunction calcBitwiseOR(result, current)\r\n{\r\n if (result.length > current.length)\r\n {\r\n var zerosToBeAdded = result.length - current.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n current = `0${current}`;\r\n }\r\n }\r\n else if (result.length < current.length)\r\n {\r\n var zerosToBeAdded = current.length - result.length;\r\n for (var i = 0; i < zerosToBeAdded; i++)\r\n {\r\n result = `0$result`;\r\n }\r\n }\r\n var answer = \"\";\r\n for (var i = 0; i < result.length; +i++)\r\n {\r\n if (result[i] === '1' || current[i] === '1')\r\n {\r\n answer += \"1\";\r\n }\r\n else answer += \"0\";\r\n }\r\n return answer;\r\n}"}, {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline()\n .split(\" \")\n .map(Number)\n .map((n) => n.toString(2).split(\"\").reverse().join(\"\"));\n const pos = [];\n const z = [];\n\n numbers.forEach((n) => {\n for (let i = 0; i < n.length; i++) {\n const db = n[i];\n if (db == 0) z[i] = true;\n else pos[i] = true;\n }\n });\n\n const cap = pos.length > z.length ? pos.length - 1 : z.length - 1;\n const sol = [];\n for (let j = 0; j < numbers.length; j++) {\n let n = pos[cap - j] ? \"1\" : \"0\";\n for (let i = cap - j - 1; i >= 0; i--) {\n n += \"0\";\n }\n sol.push(parseInt(n, 2));\n }\n \n this.print(sol.reduce((prev, curr) => prev + curr, 0)); \n}\n"}], "src_uid": "7fca54a73076ddfeb30b921b9e341f26"} {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n \nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n \nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n \ntests = [\n`YES`, // Test #1\n`NO`, // Test #2\n`YES`, // Test #3\n`NO`, // Test #4\n``, // Test #5\n];\n \n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n readline();\n let [n, k] = ra();\n let K = ra();\n for (let i=0; i=0 && ch.length==1)\n return 'YES'\n for (let j=0; j {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, f] = lines[l++].trim().split(' ').map(Number)\n const fs = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n output[i] = solve(n, f, fs, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, f, fs, edges) {\n // const map = fs.reduce((o, x) => {\n // o[x] = 1\n // return 0\n // }, {})\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n// console.log(adj, min, leaf)\n // const q = fs.map(u => [u, 0, 0])\n // q.push([1, 0, 1])\n const q = Array(n + 1)\n fs.forEach((u, i) => q[i] = [u, 0, 0])\n q[fs.length] = [1, 0, 1]\n const visited = {}\nlet qi = 0\nlet qj = fs.length + 1\n while (qi < qj) {\n // while (q.length) {\n // const [u, d, isr] = q.shift()\n const [u, d, isr] = q[qi++]\n if (visited[u]) {\n if (visited[u][0] === d) visited[u][1] = 0\n continue\n }\n visited[u] = [d, isr]\n\n ;(adj[u] || []).forEach(v => {\n if (visited[v]) return\n // q.push([v, d + 1, isr])\n q[qj++] = ([v, d + 1, isr])\n })\n }\n// console.log('visited', visited)\n for (let u = 2; u <= n; u++) {\n if (adj[u].length === 1 && visited[u][1]) return 'YES'\n }\n return 'NO'\n}\n"}], "negative_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n`YES`, // Test #1\n`NO`, // Test #2\n`YES`, // Test #3\n`NO`, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n readline();\n let [n, k] = ra();\n let K = ra();\n for (let i=0; i=0 && ch.length==1)\n return 'YES'\n for (let j=0; j1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n`YES`, // Test #1\n`NO`, // Test #2\n`YES`, // Test #3\n`NO`, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n readline();\n let [n, k] = ra();\n let K = ra();\n for (let i=0; i=0 && ch.length==1)\n return 'YES'\n for (let j=0; j1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n`YES`, // Test #1\n`NO`, // Test #2\n`YES`, // Test #3\n`NO`, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n readline();\n let [n, k] = ra();\n let K = ra();\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, f] = lines[l++].trim().split(' ').map(Number)\n const fs = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n output[i] = solve(n, f, fs, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, f, fs, edges) {\n // const map = fs.reduce((o, x) => {\n // o[x] = 1\n // return 0\n // }, {})\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n const [min, leaf] = dfs(adj, 1, {}) // min\n// console.log(adj, min, leaf)\n const q = fs.map(u => [u, 0])\n const visited = {}\n let count = 0\n while (q.length) {\n const [u, d] = q.shift()\n if (visited[u]) continue\n visited[u] = 1\n if (u !== 1 && adj[u].length === 1) count++\n\n ;(adj[u] || []).forEach(v => {\n if (visited[v]) return\n if (d + 1 <= min) {\n q.push([v, d + 1])\n }\n })\n }\n// console.log('visited', visited, count)\n return count < leaf ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited) {\n const stack = [[r, 0, -1, 0]]\n let ans = Infinity\n let leaf = 0\n while (stack.length) {\n const [u, i, p, d] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n if (u !== r && nb.length === 1) {\n leaf++\n ans = Math.min(d, ans)\n }\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u, d + 1])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return [ans, leaf]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, f] = lines[l++].trim().split(' ').map(Number)\n const fs = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n output[i] = solve(n, f, fs, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, f, fs, edges) {\n // const map = fs.reduce((o, x) => {\n // o[x] = 1\n // return 0\n // }, {})\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n const [min, leaf] = dfs(adj, 1, {}) // min\n// console.log(adj, min, leaf)\n const q = fs.map(u => [u, 0])\n const visited = {}\n let count = 0\n while (q.length) {\n const [u, d] = q.shift()\n if (visited[u]) continue\n visited[u] = 1\n if (u !== 1 && adj[u].length === 1) count++\n\n ;(adj[u] || []).forEach(v => {\n if (visited[v]) return\n if (d + 1 < min) {\n q.push([v, d + 1])\n }\n })\n }\n return count < leaf ? 'YES' : 'NO'\n}\nfunction dfs(adj, r, visited) {\n const stack = [[r, 0, -1, 0]]\n let ans = 0\n let leaf = 0\n while (stack.length) {\n const [u, i, p, d] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n ans = Math.max(d, ans)\n if (u !== r && nb.length === 1) leaf++\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u, d + 1])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return [ans, leaf]\n}\n"}], "src_uid": "bf89bc12320f635cc121eba99c542444"} {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet cases = +readLine();\n\n\twhile (cases--) {\n\t\tlet [l, r] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => parseInt(x));\n\n\t\tif (l * 2 <= r) {\n\t\t\tconsole.log(l, l * 2);\n\t\t} else {\n\t\t\tconsole.log(-1, -1);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n //[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n //\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n //2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n //6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n //8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){\n try{\n switch(no){\n case 1:return parseInt(i);\n case 2:return i.split(\" \");\n case 4:return i.split(\" \").map(Number);\n case 6:return i.split(\"\");\n case 7:return i.split(\"\").map(Number);\n case 8:return i.join(\" \");\n case 9:return i.join(\"\\n\");\n case 0:return i.join(\"\");\n default:return i;\n }\n }\n catch(e){\n return i;\n }\n}\nfunction Main(){\n var output = [];\n\n var tc = nextInt() ;\n \n // myout(m+ \" \"+d)\n while(tc--) {\n var v = nextIntArray();\n var a = v[0] ;\n var b = v[1] ;\n var c = b / a ; \n if(c < 2) {\n myout(\"-1 -1\") ;\n }\n else {\n myout(a+\" \"+(a*2))\n }\n }\n \n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').join(' ').split(' ').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction read() {\n return inputString[currentLine++];\n}\n\nfunction print(x) {\n process.stdout.write(x)\n process.stdout.write('\\n')\n}\n\nfunction main() {\n let t = Number(read())\n while(t) {\n t -= 1\n let x = Number(read())\n let y = Number(read())\n if (x * 2 <= y) {\n print(String(x) + ' ' + String(x * 2))\n } else {\n print('-1 -1')\n }\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [l, r] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (l * 2 <= r) {\n console.log(`${l} ${l * 2}`);\n } else {\n console.log(`-1 -1`);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar tmp = nextIntArray();\n \tvar L = tmp[0];\n \tvar R = tmp[1];\n \tif(L * 2 <= R){\n \t\toutput[i] = L + \" \" + (L * 2);\n \t}else{\n \t\toutput[i] = \"-1 -1\";\n \t}\n }\n myout(myconv(output, 9));\n}\nfunction getDivisorList(val){\n var list = [];\n for(var i = 1; i * i <= val; i++){\n if(val % i == 0){\n list.push(i);\n if(i * i != val){\n list.push(val / i);\n }\n }\n }\n list.sort(function(a,b){ return a - b; });\n return list;\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n let a = data[i].trim().split(' ').map(Number);\n let l = a[0];\n let r = a[1];\n let j = 2;\n while (true) {\n let m = l * j;\n if (m <= r) {j = m; break;}\n if (m > r) {j = -1; break;}\n j += 1;\n }\n if (j < 0) l = -1;\n console.log(l, j);\n i += 1;\n\t}\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = readLine();\n for (let c = 0; c < numCases; c++) {\n const [l, r] = readLine().split(\" \").map(i => parseInt(i));\n if (l * 2 <= r)\n console.log(l, l * 2);\n else\n console.log(-1, -1);\n }\n}\n\n"}], "negative_code": [{"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n //[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n //\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n //2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n //6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n //8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){\n try{\n switch(no){\n case 1:return parseInt(i);\n case 2:return i.split(\" \");\n case 4:return i.split(\" \").map(Number);\n case 6:return i.split(\"\");\n case 7:return i.split(\"\").map(Number);\n case 8:return i.join(\" \");\n case 9:return i.join(\"\\n\");\n case 0:return i.join(\"\");\n default:return i;\n }\n }\n catch(e){\n return i;\n }\n}\nfunction Main(){\n var output = [];\n\n var tc = nextInt() ;\n \n // myout(m+ \" \"+d)\n while(tc--) {\n var v = nextIntArray();\n if(v[0] === v[1]-1) {\n myout(\"-1 -1\") ; \n }\n else {\n myout(v[1]+\" \"+v[1]) ;\n }\n }\n \n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar tmp = nextIntArray();\n \tvar L = tmp[0];\n \tvar R = tmp[1];\n \tvar list = getDivisorList(R);\n \tfor(var j = 0; j < list.length; j++){\n \t\tif(list[j] >= L && list[j] < R){\n \t\t\toutput[i] = list[j] + \" \" + R;\n \t\t\tbreak;\n \t\t}\n \t}\n \tif(output[i] == null){\n \t\toutput[i] = \"-1 -1\";\n \t}\n }\n myout(myconv(output, 9));\n}\nfunction getDivisorList(val){\n var list = [];\n for(var i = 1; i * i <= val; i++){\n if(val % i == 0){\n list.push(i);\n if(i * i != val){\n list.push(val / i);\n }\n }\n }\n list.sort(function(a,b){ return a - b; });\n return list;\n}"}], "src_uid": "e8ba3fb95800806465386ecbfbe924e9"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var M = one[1];\n var isOK = false;\n for(var j = 0; j < N; j++){\n var L = nextIntArray();\n var R = nextIntArray();\n if(L[1] == R[0]){\n isOK = true;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n if(M % 2 == 1){\n output[i] = \"NO\";\n }\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [len, target] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let d = 0;\n let found = false;\n while (len--) {\n const [r0c0, r0c1] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [r1c0, r1c1] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (r0c1 === r1c0) d++;\n }\n if (d > 0 && target % 2 === 0) {\n console.log(\"YES\");\n } else console.log(\"NO\");\n }\n}\n"}, {"source_code": "var t = Number( readline() );\nfor(var i=0; iNumber(a));\n var n = r[0];\n var m = r[1];\n var res = 0;\n for(var j=0;jNumber(a))[1] == readline().split(' ').map(a=>Number(a))[0]){\n res = 1;\n }\n }\n if(m&1) res=0;\n print((res==1)?\"YES\":\"NO\");\n}\n"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var arr = readline().split(' ').map(int)\n var n = arr[0], m = arr[1]\n var type2 = 0\n \n for(var i = 0; i < n; i++) {\n var block1 = readline().split(' ').map(int)\n var block2 = readline().split(' ').map(int)\n type2 += (block1[1] == block2[0])\n }\n \n print((m % 2 === 0 && type2 ? 'YES' : 'NO'))\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), m = $()\n let a = $(n * 4)\n if (m % 2 == 1) log('NO')\n else {\n log(For(n, i => a[i * 4 + 1] == a[i * 4 + 2] ? 1 : null) ? 'YES' : 'NO')\n }\n }\n}\n"}], "negative_code": [{"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var arr = readline().split(' ').map(int)\n var n = arr[0], m = arr[1]\n var type1 = 0, type2 = 0\n \n for(var i = 0; i < n; i++) {\n var block1 = readline().split(' ').map(int)\n var block2 = readline().split(' ').map(int)\n type1 += (block1[0] == block2[1] && block1[1] == block2[0])\n type2 += (block1[0] == block2[1])\n }\n \n print((m % 2 === 0 && type1 && type1 + type2 > 1 ? 'YES' : 'NO'))\n}"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var arr = readline().split(' ').map(int)\n var n = arr[0], m = arr[1]\n var type2 = 0\n \n for(var i = 0; i < n; i++) {\n var block1 = readline().split(' ').map(int)\n var block2 = readline().split(' ').map(int)\n type2 += (block1[0] == block2[1])\n }\n \n print((m % 2 === 0 && type2 ? 'YES' : 'NO'))\n}"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var arr = readline().split(' ').map(int)\n var n = arr[0], m = arr[1]\n var type1 = 0\n \n for(var i = 0; i < n; i++) {\n var block1 = readline().split(' ').map(int)\n var block2 = readline().split(' ').map(int)\n type1 += (block1[0] == block2[1] && block1[1] == block2[0])\n }\n \n print((m % 2 === 0 && type1 ? 'YES' : 'NO'))\n}"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var arr = readline().split(' ').map(int)\n var n = arr[0], m = arr[1]\n var type1 = 0, type2 = 0\n \n for(var i = 0; i < n; i++) {\n var block1 = readline().split(' ').map(int)\n var block2 = readline().split(' ').map(int)\n type1 += (block1[0] == block2[1] && block1[1] == block2[0])\n type2 += (block1[0] == block2[1])\n }\n \n print((type1 && type1 + type2 > 1 ? 'YES' : 'NO'))\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [len, target] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [d1, d2] = [0, 0];\n let found = false;\n while (len--) {\n const [r0c0, r0c1] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [r1c0, r1c1] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (r0c0 === r1c1) d1++;\n if (r0c1 === r1c0) d2++;\n }\n if (d1 > 0 && d2 > 0 && target % 2 === 0) {\n console.log(\"YES\");\n } else console.log(\"NO\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var M = one[1];\n var isOK = false;\n for(var j = 0; j < N; j++){\n var L = nextIntArray();\n var R = nextIntArray();\n if(L[0] == R[1] && L[1] == R[0]){\n isOK = true;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n if(M % 2 == 1){\n output[i] = \"NO\";\n }\n }\n myout(myconv(output, 9));\n}\n"}], "src_uid": "f46f6fa28d0a7023da3bad0d222ce393"} {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let n = read();\n let k = readInt();\n let d = n.length;\n function can(s) {\n used = new Array(10).fill(0);\n for (let i = 0; i < s.length; i++) {\n used[parseInt(s[i])] = 1;\n }\n let cnt = 0;\n for (let i = 0; i < 10; i++) {\n cnt += used[i];\n }\n if (k < cnt) {\n return 0;\n }\n let mx = 0;\n for (let i = 0; i < 10; i++) if (used[i]) {\n mx = Math.max(mx, i);\n }\n if (cnt < k) {\n mx = 9;\n }\n while (s.length < n.length) {\n s = s + mx;\n }\n return n <= s;\n }\n s = \"\";\n while (s.length < n.length) {\n let found = 0;\n for (let i = 0; i < 10; i++) {\n let s2 = s;\n s2 += i;\n if (can(s2)) {\n s = s2;\n found = 1;\n break;\n }\n }\n if (!found) {\n s = \"\";\n break;\n }\n }\n if (s != \"\") {\n console.log(s);\n }\n else {\n s = \"1\";\n for (let i = 0; i < n.length; i++) {\n s += \"0\";\n }\n console.log(s);\n }\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n", "positive_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d && ((i[o] = u), e(n, s, o + 1))) return !0\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n let t\r\n ;(i[o] = u + 1),\r\n (t =\r\n 1 & n || s > 1 || n & (1 << (u + 1))\r\n ? 0\r\n : revPow2[(n |= 1 << (u + 1)) & -n])\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n if (10 === a) return !1\r\n i[o] = a\r\n const l = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = l\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.println(r)\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst revPow2 = {}\r\nfor (let e = 0; e < 15; ++e) revPow2[1 << e] = e\r\nfunction solve(e, n) {\r\n const t = String(e)\r\n .split('')\r\n .map(e => Number(e)),\r\n r = t.length,\r\n i = new Array(t.length)\r\n return (\r\n (function e(n, s, o) {\r\n if (o === r) return !0\r\n const u = t[o],\r\n d = 1 << u\r\n if (n & d && ((i[o] = u), e(n, s, o + 1))) return !0\r\n if (s > 0) {\r\n if (((i[o] = u), e(n | d, s - 1, o + 1))) return !0\r\n if (9 === u) return !1\r\n let t\r\n ;(i[o] = u + 1),\r\n (t =\r\n 1 & n || s > 1 || n & (1 << (u + 1))\r\n ? 0\r\n : revPow2[(n |= 1 << (u + 1)) & -n])\r\n for (let e = o + 1; e < r; ++e) i[e] = t\r\n return !0\r\n }\r\n let a = u + 1\r\n for (; a < 10 && !(n & (1 << a)); ++a);\r\n if (10 === a) return !1\r\n i[o] = a\r\n const l = revPow2[n & -n]\r\n for (let e = o + 1; e < r; ++e) i[e] = l\r\n return !0\r\n })(0, n, 0),\r\n Number(i.join(''))\r\n )\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n r = solve(n, t)\r\n e.print(r + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k))\n }\n// })()\n})\n\n// for (let i = 600000; i <= 633633; i++) {\n// if (solve(i, 2) === '633333') {\n// console.log(i)\n// }\n// }\n\nfunction solve(n, k) {\n const s = String(n)\n const r = []\n const first = []\n for (let i = 0; i < s.length; i++) {\n let c = +s[i]\n const has = first.some(x => x[0] === c)\n if (has) {\n r[i] = c\n } else if (first.length < k) {\n first.push([c, i])\n r[i] = c\n } else {\n let min = Math.min(...r)\n let max = Math.max(...r)\n if (c <= min) {\n r.push(...Array(s.length - r.length).fill(min))\n } else if (c <= max) {\n while (r.indexOf(c) < 0) c++\n r[i] = c\n r.push(...Array(s.length - r.length).fill(min))\n } else {\n if (r[i - 1] < max) {\n const uniq = r.filter(x => x === r[i - 1]).length === 1\n if (r.indexOf(r[i - 1] + 1) >= 0) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n } else if (uniq) {\n r[i - 1]++\n r.push(...Array(s.length - r.length).fill(Math.min(...r)))\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n r.push(...Array(s.length - r.length).fill(uniq ? 0 : min))\n }\n } else {\n // the first not equals max\n let p = i - 1\n for (; p >= 0; p--) {\n if (r[p] !== max) break\n }\n // has max\n let hmax = false\n for (let x = p; x >= 0; x--) {\n if (r[x] === max) {\n hmax = true\n break\n }\n }\n if (!hmax) {\n p++\n }\n r.length = p + 1\n const uniq = r.filter(x => x === r[p]).length === 1\n if (r.indexOf(r[p] + 1) >= 0) {\n r[p]++\n min = uniq ? 0 : min\n } else if (uniq) {\n r[p]++\n min = Math.min(...r)\n } else {\n let prev = r.pop() + 1\n while (r.indexOf(prev) < 0) prev++\n r.push(prev)\n // console.log(r, hmax, uniq)\n min = uniq ? 0 : min\n }\n for (let x = p + 1; x < s.length; x++) {\n r[x] = min\n }\n // } else {\n // const uniq = r.filter(x => x === r[p + 1]).length === 1\n // r[p + 1]++\n // if (k === 1) {\n // min = r[p + 1]\n // } else {\n // min = uniq ? 0 : Math.min(...r.slice(0, p + 2))\n // }\n // for (let x = p + 2; x < s.length; x++) {\n // r[x] = min\n // }\n // }\n }\n }\n break\n }\n }\n return r.join('')\n}\n"}], "negative_code": [], "src_uid": "3ef53ad23ec56344f68546096c6c3308"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst mxV = 1e5+10;\r\n\r\nconst par = Array.from(Array(mxV), x => [0, 0]);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\r\n\t\tfor (let i = 0; i < mxV; i++) {\r\n\t\t\tpar[i][0] = par[i][1] = 0;\r\n\t\t}\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tpar[a[i]][i&1]++;\r\n\t\t}\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\tok = --par[a[i]][i&1] >= 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst mxV = Math.max(...a) + 10;\r\n\t\tconst par = Array.from(Array(mxV), x => [0, 0]);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tpar[a[i]][i%2]++;\r\n\t\t}\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\tok = --par[a[i]][i%2] >= 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 07/11/21 afternoon\r\nconst solve = (n, a) => {\r\n let b = [...a];\r\n stin(a);\r\n let ma = new Map();\r\n let mb = new Map();\r\n for (let i = 0; i < n; i++) {\r\n if (!ma.has(a[i])) ma.set(a[i], []);\r\n ma.get(a[i]).push(i % 2);\r\n if (!mb.has(b[i])) mb.set(b[i], []);\r\n mb.get(b[i]).push(i % 2);\r\n }\r\n // pr(ma, mb);\r\n for (const [x, na] of ma) {\r\n let nb = mb.get(x);\r\n // pr(na, nb);\r\n let sa = sb = 0;\r\n for (let i = 0; i < na.length; i++) {\r\n sa += na[i];\r\n sb += nb[i];\r\n }\r\n if (sa != sb) return pr('NO');\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/C\r\n */\r\nconst solve = (n, a) => {\r\n let origin = [...a];\r\n let m = counter_value_in_indexA_in(origin);\r\n stin(a);\r\n let used = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != origin[i]) {\r\n let idxA = m.get(a[i]);\r\n let find = false;\r\n for (const j of idxA) {\r\n if (!used.has(j) && abs(i - j) % 2 == 0) {\r\n used.add(j);\r\n find = true;\r\n break;\r\n }\r\n }\r\n if (!find) return pr('NO');\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/C\r\n */\r\nconst solve = (n, a) => {\r\n let origin = [...a];\r\n let m = counter_value_in_indexA_in(origin);\r\n stin(a);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != origin[i]) {\r\n let idxA = m.get(a[i]);\r\n let find = false;\r\n for (const j of idxA) {\r\n if (abs(i - j) % 2 == 0) {\r\n find = true;\r\n break;\r\n }\r\n }\r\n if (!find) return pr('NO');\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/C\r\n */\r\nconst solve = (n, a) => {\r\n let origin = [...a];\r\n let m = counter_value_in_indexA_in(origin);\r\n stin(a);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != origin[i]) {\r\n let idxA = m.get(a[i]);\r\n let find = false;\r\n for (const j of idxA) {\r\n if (abs(i - j) % 2 == 0) {\r\n find = true;\r\n }\r\n }\r\n if (!find) return pr('NO');\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "1d27d6d736d891b03b7476f8a7209291"} {"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\n\nconst N = lll[0]\nconst M = lll[1]\n\nlet plc = -1\n\n;(function () {\n while(lll = readline()) {\n let lc = lll[0]\n for (var i = 1; i < lll.length; i++) {\n if (lc != lll[i]) return print('NO')\n }\n if (plc == lc) return print('NO')\n plc = lc\n }\n print('YES')\n})()", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1];\n\n\tvar previousColor = -1;\n\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tvar row = trim(readline());\n\t\tif (row[0] == previousColor) {\n\t\t\tprint(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tpreviousColor = row[0];\n\t\tfor (var c = 1; c < colNum; c += 1) {\n\t\t\tif (row[c] != row[c-1]) {\n\t\t\t\tprint(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(\"YES\");\n}\n\nmain();\n"}, {"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0];\nvar m = nm[1];\nvar f = [];\nvar ans = 'YES';\nfor (var i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n const s = new Set(d);\n\n if (s.size !== 1 || prev === d[0]) {\n ans = 'NO';\n }\n else {\n prev = d[0];\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar isSameChar = function(str){\n for(let i=0; i {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0], m = temp[1];\n indicator++;\n }\n else { \n if(prev == input || !isSameChar(input))\n ans=\"NO\";\n \n prev = input;\n }\n}).on('close',function(){\n console.log(ans);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar IsSameColour = function (s) {\n // console.log(\"inside function s=%s type is: %s\", s, typeof s);\n for (let i = 1; i < s.length; i++) {\n if (s[0] != s[i])\n return false;\n }\n return true;\n}\n\nvar prev, current, n, m, indicator = 0,\n ans = \"YES\";\n\nrl.on('line', (current) => {\n if (indicator == 0) {\n var temp = current.split(' ').map(item => parseInt(item));\n n = temp[0];\n m = temp[1];\n indicator++;\n } else if (indicator == 1) {\n prev = current;\n\n if (!IsSameColour(prev)) {\n ans = \"NO\";\n rl.close();\n }\n indicator++;\n } else {\n if (!IsSameColour(current) || prev == current) {\n ans = \"NO\";\n //break;\n rl.close();\n }\n prev = current;\n\n }\n\n}).on('close', () => {\n console.log(ans);\n});"}], "negative_code": [], "src_uid": "80d3da5aba371f4d572ea928025c5bbd"} {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n r = Math.max(r, x);\n if (a[i] > a[i-2]) { x = y; y = 1; continue; }\n if (a[i+1] > a[i-1]) { x = y; y = 1; continue; }\n y = 1; x = 1;\n }\n return Math.max(r, x);\n}\n\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nrl.on('line', (input) => {\n if (length === null) {\n length = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n rl.close();\n }\n});\n\nlet length = null;\n\nconst solve = numbers => {\n let maxLength = 1;\n let currentLength = 1;\n let removed = false;\n\n for (let i = 0; i < numbers.length - 1; i++) {\n if (numbers[i] < numbers[i + 1]) {\n currentLength++;\n } else {\n if (currentLength === 1) {\n continue;\n } else {\n if (removed) {\n if (currentLength > maxLength) {\n maxLength = currentLength;\n }\n\n currentLength = 1;\n removed = false;\n } else {\n if (i + 2 <= numbers.length - 1) {\n if (numbers[i + 2] > numbers[i]) {\n removed = true;\n } else if (numbers[i - 1] < numbers[i + 1]) {\n removed = true;\n } else {\n if (currentLength > maxLength) {\n maxLength = currentLength;\n }\n \n currentLength = 1;\n }\n }\n }\n }\n }\n }\n\n if (currentLength > maxLength) {\n maxLength = currentLength;\n }\n\n console.log(maxLength);\n};\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nrl.on('line', (input) => {\n if (length === null) {\n length = +input;\n } else {\n solve(input.split(' ').map(number => +number));\n rl.close();\n }\n});\n\nlet length = null;\n\nconst solve = numbers => {\n let maxLenght = 1;\n let currentLenght = 1;\n\n let i = 0;\n let removed = false;\n\n while (true) {\n while (i < (numbers.length - 1) && numbers[i] < numbers[i + 1]) {\n currentLenght++;\n i++\n }\n \n if (i === numbers.length - 1) {\n if (currentLenght > maxLenght) {\n maxLenght = currentLenght;\n }\n break;\n }\n\n if (removed) {\n if (currentLenght > maxLenght) {\n maxLenght = currentLenght;\n }\n i++;\n removed = false;\n } else {\n if (currentLenght !== 1 && numbers[i + 1] > numbers[i - 1]) {\n removed = true;\n } else {\n currentLenght = 1;\n }\n i++;\n }\n }\n\n console.log(maxLenght);\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nrl.on('line', (input) => {\n if (length === null) {\n length = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n rl.close();\n }\n});\n\nlet length = null;\n\nconst solve = numbers => {\n let maxLength = 1;\n let currentLength = 1;\n let removed = false;\n let lengthBeforeRemove = null;\n\n for (let i = 0; i < numbers.length - 1; i++) {\n if (numbers[i] < numbers[i + 1]) {\n currentLength++;\n } else {\n if (currentLength === 1) {\n continue;\n } else {\n if (removed) {\n if (lengthBeforeRemove > currentLength) {\n currentLength = lengthBeforeRemove;\n }\n\n if (currentLength > maxLength) {\n maxLength = currentLength;\n }\n\n lengthBeforeRemove = null;\n currentLength = 1;\n removed = false;\n } else {\n numbers[i] = numbers[i - 1];\n lengthBeforeRemove = currentLength--;\n i--;\n removed = true;\n }\n }\n }\n }\n\n if (currentLength > maxLength) {\n maxLength = currentLength;\n }\n\n console.log(maxLength);\n};\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 1;\n for (let i = 1; i < n; i++) {\n if (a[i] === a[i-1] + 1) { x++; y++; continue; }\n\n r = Math.max(r, x);\n x = 1;\n if (a[i+1] === a[i-1] + 1) { x += y; i++; }\n y = 1;\n }\n if(n===1000) {\n x = [];\n for (let i = 1; i < n; i++) {\n if (a[i] - a[i-1] === 1) x.push(`${i-1} - ${a[i-1]}`)\n }\n return x.join('|')\n }\n\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }\n else if (a[i+1] <= a[i-1]) { y = 0; x = 0; }\n }\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) x = Math.max(x, y);\n }\n return Math.max(x, y);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; continue; }\n if (a[i+1] > a[i-1]) { r = Math.max(r, x); x = y; y = 0; continue; }\n y = 1; x = 1;\n }\n return Math.max(r, x);\n}\n\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; }\n else if (a[i+1] <= a[i-1]) { y = 1; x = 1; }\n }\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 1;\n for (let i = 1; i < n; i++) {\n if (a[i] === a[i-1] + 1) { x++; y++; continue; }\n\n r = Math.max(r, x);\n x = 1;\n if (a[i+1] === a[i-1] + 1) { x += y; i++; }\n y = 1;\n }\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n r = Math.max(r, x);\n if (a[i] > a[i-2]) { x = y; y = 1; continue; }\n if (a[i+1] > a[i-1]) { x = y; y = 0; continue; }\n y = 1; x = 1;\n }\n return Math.max(r, x);\n}\n\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }\n else if (a[i+1] <= a[i-1]) { y = 1; x = 1; }\n }\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0,j;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; continue; }\n if (a[i+1] > a[i-1]) { r = Math.max(r, x); x = y; y = 0; continue; }\n y = 1; x = 1;\n }\n return Math.max(r, x);\n}\n\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 1;\n for (let i = 1; i < n; i++) {\n if (a[i] === a[i-1] + 1) { x++; y++; continue; }\n\n r = Math.max(r, x);\n x = 1;\n if (a[i+1] === a[i-1] + 1) { x += y; i++; }\n y = 1;\n }\n if(n===1000) return [ x, y, a.slice(51) ];\n\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 1;\n for (let i = 1; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n\n r = Math.max(r, x);\n x = 1;\n if (a[i+1] > a[i-1]) { x += y; i++; }\n y = 1;\n }\n return Math.max(r, x);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let x = 1, y = 1, r = 0;\n if (a[1] > a[0]) { x++; y++; }\n for (let i = 2; i < n; i++) {\n if (a[i] > a[i-1]) { x++; y++; continue; }\n if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }\n }\n return Math.max(r, y);\n}\n\nprint(problem(+readline(), readline().split(' ').map(i => +i)));\n"}], "src_uid": "87b8dccfc0e5a63cd209c37cf8aebef0"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// max heap\r\nconst mxSZ = 2e5+100;\r\n\r\nconst a = Array(mxSZ);\r\nlet sz = 0;\r\n\r\nconst L = i => 2*i+1;\r\nconst R = i => 2*i+2;\r\nconst P = i => i-1>>1;\r\n\r\nfunction add (x) {\r\n\ta[sz] = x, sz++;\r\n\tlet i = sz-1;\r\n\twhile (i && a[P(i)].v < a[i].v) {\r\n\t\t[a[P(i)], a[i]] = [a[i], a[P(i)]]; \r\n\t\ti = P(i);\r\n\t}\r\n}\r\n\r\nfunction getMax () {\r\n\treturn sz ? a[0] : -1;\r\n}\r\n\r\nfunction remove () {\r\n\tif (sz == 0) return;\r\n\ta[0] = a[sz-1], sz--;\r\n\tlet i = 0; \r\n\twhile (L(i) < sz) {\r\n\t\tlet smallest = i;\r\n\t\tif (L(i) < sz && a[L(i)].v > a[smallest].v) smallest = L(i);\r\n\t\tif (R(i) < sz && a[R(i)].v > a[smallest].v) smallest = R(i);\r\n\t\tif (i != smallest) {\r\n\t\t\t[a[smallest], a[i]] = [a[i], a[smallest]]; i = smallest;\r\n\t\t} else {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) add({v: s[i], id: i});\r\n\r\n\t\tconst ans = [];\r\n\t\twhile (true) {\r\n\t\t\tconst x = getMax(); if (x.v) remove(); else break;\r\n\t\t\tconst y = getMax(); if (y.v) remove(); else break;\r\n\t\t\tans.push(x.id, y.id);\r\n\t\t\t--x.v, --y.v;\r\n\t\t\tadd(x), add(y);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length/2);\r\n\t\twhile (ans.length) console.log(ans.pop() + 1, ans.pop() + 1);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n readline();\r\n const myArr = readline().split(\" \"), myObj = {}, mostScbObj = {}, ans = [];\r\n let key = Number(myArr[0]), n = 0;\r\n \r\n myArr.forEach((scb, index) => {\r\n if(0 < scb) {\r\n if(key < Number(scb)) key = Number(scb);\r\n if(myObj[scb] == undefined) myObj[scb] = [index + 1];\r\n else myObj[scb].push(index + 1);\r\n n++;\r\n }\r\n });\r\n \r\n for(const scb in myObj) mostScbObj[key - scb] = true;\r\n \r\n while(1 < n) {\r\n let maxScb, minScb, mostScbPerson, leastScbPerson;\r\n for(const scb in mostScbObj) {\r\n maxScb = key - scb;\r\n break;\r\n }\r\n for(const scb in myObj) {\r\n minScb = scb;\r\n break;\r\n }\r\n \r\n \r\n mostScbPerson = myObj[maxScb].pop();\r\n leastScbPerson = myObj[minScb].shift();\r\n \r\n ans.push(mostScbPerson + \" \" + leastScbPerson);\r\n \r\n if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {\r\n delete myObj[maxScb];\r\n delete mostScbObj[key - maxScb];\r\n }\r\n \r\n if(myObj[minScb] != undefined && myObj[minScb].length == 0) {\r\n delete myObj[minScb];\r\n delete mostScbObj[key - minScb];\r\n }\r\n \r\n if(0 < maxScb - 1) {\r\n if(myObj[maxScb - 1] == undefined) {\r\n myObj[maxScb - 1] = [mostScbPerson];\r\n mostScbObj[key - (maxScb - 1)] = true;\r\n }else {\r\n myObj[maxScb - 1].push(mostScbPerson);\r\n }\r\n }else if(0 == maxScb - 1) n--;\r\n \r\n if(0 < minScb - 1) {\r\n if(myObj[minScb - 1] == undefined) {\r\n myObj[minScb - 1] = [leastScbPerson];\r\n mostScbObj[key - (minScb - 1)] = true;\r\n }else {\r\n myObj[minScb - 1].push(leastScbPerson);\r\n }\r\n }else if(0 == minScb - 1) n--;\r\n \r\n }\r\n \r\n console.log(ans.length);\r\n ans.forEach(conv => console.log(conv));\r\n \r\n }\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// max heap\r\nconst mxSZ = 2e5+100;\r\n\r\nconst a = Array(mxSZ);\r\nlet sz = 0;\r\n\r\nconst L = i => 2*i+1;\r\nconst R = i => 2*i+2;\r\nconst P = i => i-1>>1;\r\n\r\nfunction add (x) {\r\n\ta[sz] = x, sz++;\r\n\tlet i = sz-1;\r\n\twhile (i && a[P(i)].v < a[i].v) {\r\n\t\t[a[P(i)], a[i]] = [a[i], a[P(i)]]; \r\n\t\ti = P(i);\r\n\t}\r\n}\r\n\r\nfunction getMax () {\r\n\treturn sz ? a[0] : -1;\r\n}\r\n\r\nfunction remove () {\r\n\tif (sz == 0) return;\r\n\ta[0] = a[sz-1], sz--;\r\n\tlet i = 0; \r\n\twhile (L(i) < sz) {\r\n\t\tlet smallest = i;\r\n\t\tif (L(i) < sz && a[L(i)].v > a[smallest].v) smallest = L(i);\r\n\t\tif (R(i) < sz && a[R(i)].v > a[smallest].v) smallest = R(i);\r\n\t\tif (i != smallest) {\r\n\t\t\t[a[smallest], a[i]] = [a[i], a[smallest]]; i = smallest;\r\n\t\t} else {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n//add(5);\r\n//add(10);\r\n//add(21);\r\n//for (let i = 0; i < 10; i++) {\r\n//console.log(getMax());\r\n//remove();\r\n//}\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) s[i] = {v: s[i], id: i};\r\n\r\n\t\tfor (let i = 0; i < n; i++) s[i].v && add(s[i]);\r\n\r\n\t\tconst ans = [];\r\n\t\twhile (true) {\r\n\t\t\tconst x = getMax(); if (x != -1) remove(); else break;\r\n\t\t\tconst y = getMax(); if (y != -1) remove(); else break;\r\n\t\t\t//console.log({x, y})\r\n\r\n\t\t\tans.push(x.id, y.id);\r\n\t\t\tx.v--, y.v--;\r\n\t\t\tif (x.v > 0) add(x);\r\n\t\t\tif (y.v > 0) add(y);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length/2);\r\n\t\twhile (ans.length) console.log(ans.pop() + 1, ans.pop() + 1);\r\n\t}\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\r\n\t\ta.sort((x, y) => y[0] - x[0]);\r\n\r\n\t\tconst id = [];\r\n\t\tfor (let i = 0; i < n; i++) [a[i], id[i]] = a[i];\r\n\r\n\t\tlet ans = [];\r\n\t\tlet r = 0; while (a[r+1]) r++;\r\n\t\twhile (a[0] > a[1]) {\r\n\t\t\tif (r > 0 && a[r] > 0) ans.push(id[0], id[r]), a[0]--, a[r]--;\r\n\t\t\tif (a[r] == 0) r--;\r\n\t\t\tif (r == 0) break;\r\n\t\t}\r\n\t\twhile (a[1]) {\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i] == 0) break;\r\n\t\t\t\tif (a[i]) ans.push(id[i]), a[i]--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length>>1);\r\n\t\tfor (let i = 0; i < ans.length>>1; i++) {\r\n\t\t\tconsole.log(ans[2*i] + 1, ans[2*i+1] + 1);\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nclass PriorityQueue {\r\n constructor(cmp) {\r\n this.cmp = cmp;\r\n this.data = [];\r\n this.size = 0;\r\n }\r\n\r\n\r\n add(value) {\r\n this.data[this.size] = value;\r\n this.siftUp(this.size);\r\n this.size += 1;\r\n }\r\n\r\n pop() {\r\n const top = this.top();\r\n if (this.size !== 0) {\r\n this.swap(0, this.size - 1);\r\n this.size -= 1;\r\n this.siftDown(0);\r\n }\r\n return top;\r\n }\r\n\r\n top() {\r\n return this.data[0];\r\n }\r\n\r\n siftDown(index) {\r\n while (this.leftChild(index) < this.size) {\r\n const leftChildIndex = this.leftChild(index);\r\n const rightChildIndex = this.rightChild(index);\r\n let swapIndex = leftChildIndex;\r\n if (\r\n rightChildIndex < this.size &&\r\n this.cmp(this.data[leftChildIndex], this.data[rightChildIndex]) < 0\r\n ) {\r\n swapIndex = rightChildIndex;\r\n }\r\n if (this.cmp(this.data[index], this.data[swapIndex]) > 0) break;\r\n this.swap(index, swapIndex);\r\n index = swapIndex;\r\n }\r\n }\r\n\r\n siftUp(index) {\r\n while (this.parent(index) >= 0) {\r\n let p = this.parent(index);\r\n if (this.cmp(this.data[index], this.data[p]) > 0) {\r\n this.swap(index, p);\r\n }\r\n index = p;\r\n }\r\n }\r\n\r\n swap(index1, index2) {\r\n [this.data[index1], this.data[index2]] = [\r\n this.data[index2],\r\n this.data[index1],\r\n ];\r\n }\r\n\r\n parent(index) {\r\n return Math.floor((index - 1) / 2);\r\n }\r\n\r\n leftChild(index) {\r\n return index * 2 + 1;\r\n }\r\n\r\n rightChild(index) {\r\n return index * 2 + 2;\r\n }\r\n}\r\n\r\nfunction main() {\r\n let n = parseInt(readline());\r\n while (n--) {\r\n readline();\r\n const nums = readline()\r\n .split(\" \")\r\n .map((v, i) => {\r\n return {\r\n value: parseInt(v),\r\n index: i,\r\n };\r\n })\r\n .filter(v => v.value !== 0)\r\n const heap = new PriorityQueue((a, b) => a.value - b.value)\r\n for (let num of nums) {\r\n heap.add(num);\r\n }\r\n const ans = [];\r\n while (heap.size >= 2) {\r\n const top1 = heap.pop();\r\n const top2 = heap.pop();\r\n ans.push([top1.index, top2.index]);\r\n top1.value -= 1;\r\n top2.value -= 1;\r\n if (top1.value !== 0) heap.add(top1);\r\n if (top2.value !== 0) heap.add(top2);\r\n }\r\n console.log(ans.length);\r\n for (let i = 0; i < ans.length; i += 1) {\r\n console.log(ans[i][0] + 1, ans[i][1] + 1);\r\n }\r\n \r\n }\r\n}\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nclass Heap {\r\n constructor() {\r\n this.data = [];\r\n this.size = 0;\r\n }\r\n\r\n peek() {\r\n return this.data[0];\r\n }\r\n\r\n pop() {\r\n let v = this.data[0];\r\n this.data[0] = this.data[this.size-1];\r\n this.size -= 1;\r\n this.down(0);\r\n return v;\r\n }\r\n\r\n insert(o) {\r\n this.data[this.size] = o;\r\n this.size += 1;\r\n this.up(this.size-1);\r\n }\r\n\r\n up(i) {\r\n let c = i;\r\n while (Math.floor(c/2) >= 0) {\r\n let p = Math.floor(c/2);\r\n if (this.data[c].v > this.data[p].v) {\r\n\tlet tmp = this.data[c];\r\n\tthis.data[c] = this.data[p];\r\n\tthis.data[p] = tmp;\r\n\tc = p;\r\n } else {\r\n\tbreak;\r\n }\r\n }\r\n }\r\n\r\n down(i) {\r\n let c = i;\r\n\r\n while (c * 2 < this.size) {\r\n let left = c * 2;\r\n let right = c * 2 + 1;\r\n\r\n let min = left;\r\n if (right < this.size && (this.data[right].v > this.data[left].v)) {\r\n\tmin = right;\r\n }\r\n\r\n if (this.data[min].v > this.data[c].v) {\r\n\tlet tmp = this.data[min];\r\n\tthis.data[min] = this.data[c];\r\n\tthis.data[c] = tmp;\r\n\tc = min;\r\n } else {\r\n\tbreak;\r\n }\r\n }\r\n }\r\n}\r\n\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let q = 0; q < Q; q++) {\r\n let N = +(readline());\r\n\r\n let A = readline().split(\" \").map((a) => parseInt(a));\r\n let heap = new Heap();\r\n\r\n for (let i = 0; i < A.length; i++) {\r\n heap.insert({index: i, v: A[i]});\r\n }\r\n\r\n let talks = [];\r\n\r\n while (true) {\r\n //console.log(\"heap data\", heap.data);\r\n let max1 = heap.pop();\r\n let max2 = heap.pop();\r\n\r\n if (max1.v === 0 || max2.v === 0) break;\r\n\r\n talks.push([max1.index+1, max2.index+1]);\r\n max1.v -= 1;\r\n max2.v -= 1;\r\n\r\n //console.log(\"heap data after\", heap.data);\r\n heap.insert(max1);\r\n heap.insert(max2);\r\n }\r\n\r\n console.log(talks.length);\r\n for (let i = 0; i < talks.length; i++) {\r\n console.log(talks[i][0] + \" \" + talks[i][1]);\r\n }\r\n }\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n readline();\r\n const myArr = readline().split(\" \"), myObj = {}, mostScbObj = {}, ans = [];\r\n let key = myArr[0], n = 0;\r\n \r\n myArr.forEach((scb, index) => {\r\n if(0 < scb) {\r\n if(key < scb) key = scb;\r\n if(myObj[scb] == undefined) myObj[scb] = [index + 1];\r\n else myObj[scb].push(index + 1);\r\n n++;\r\n }\r\n });\r\n \r\n for(const scb in myObj) mostScbObj[key - scb] = true;\r\n \r\n while(1 < n) {\r\n let maxScb, minScb, mostScbPerson, leastScbPerson;\r\n for(const scb in mostScbObj) {\r\n maxScb = key - scb;\r\n break;\r\n }\r\n for(const scb in myObj) {\r\n minScb = scb;\r\n break;\r\n }\r\n \r\n \r\n mostScbPerson = myObj[maxScb].pop();\r\n leastScbPerson = myObj[minScb].shift();\r\n \r\n ans.push(mostScbPerson + \" \" + leastScbPerson);\r\n \r\n if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {\r\n delete myObj[maxScb];\r\n delete mostScbObj[key - maxScb];\r\n }\r\n \r\n if(myObj[minScb] != undefined && myObj[minScb].length == 0) {\r\n delete myObj[minScb];\r\n delete mostScbObj[key - minScb];\r\n }\r\n \r\n if(0 < maxScb - 1) {\r\n if(myObj[maxScb - 1] == undefined) {\r\n myObj[maxScb - 1] = [mostScbPerson];\r\n mostScbObj[key - (maxScb - 1)] = true;\r\n }else {\r\n myObj[maxScb - 1].push(mostScbPerson);\r\n }\r\n }else if(0 == maxScb - 1) n--;\r\n \r\n if(0 < minScb - 1) {\r\n if(myObj[minScb - 1] == undefined) {\r\n myObj[minScb - 1] = [leastScbPerson];\r\n mostScbObj[key - (minScb - 1)] = true;\r\n }else {\r\n myObj[minScb - 1].push(leastScbPerson);\r\n }\r\n }else if(0 == minScb - 1) n--;\r\n \r\n }\r\n \r\n console.log(ans.length);\r\n ans.forEach(conv => console.log(conv));\r\n \r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n readline();\r\n const myArr = readline().split(\" \"), myObj = {}, mostScbObj = {}, ans = [];\r\n let key = myArr[0], n = 0;\r\n \r\n myArr.forEach((scb, index) => {\r\n if(0 < scb) {\r\n if(key < scb) key = scb;\r\n if(myObj[scb] == undefined) myObj[scb] = [index];\r\n else myObj[scb].push(index);\r\n n++;\r\n }\r\n });\r\n \r\n for(const scb in myObj) mostScbObj[key - scb] = true;\r\n \r\n while(1 < n) {\r\n let maxScb, minScb, mostScbPerson, leastScbPerson;\r\n for(const scb in mostScbObj) {\r\n maxScb = key - scb;\r\n break;\r\n }\r\n for(const scb in myObj) {\r\n minScb = scb;\r\n break;\r\n }\r\n \r\n \r\n mostScbPerson = myObj[maxScb].pop();\r\n leastScbPerson = myObj[minScb].shift();\r\n \r\n ans.push(mostScbPerson + \" \" + leastScbPerson);\r\n \r\n if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {\r\n delete myObj[maxScb];\r\n delete mostScbObj[key - maxScb];\r\n }\r\n \r\n if(myObj[minScb] != undefined && myObj[minScb].length == 0) {\r\n delete myObj[minScb];\r\n delete mostScbObj[key - minScb];\r\n }\r\n \r\n if(0 < maxScb - 1) {\r\n if(myObj[maxScb - 1] == undefined) {\r\n myObj[maxScb - 1] = [mostScbPerson];\r\n mostScbObj[key - (maxScb - 1)] = true;\r\n }else {\r\n myObj[maxScb - 1].push(mostScbPerson);\r\n }\r\n }else if(0 == maxScb - 1) n--;\r\n \r\n if(0 < minScb - 1) {\r\n if(myObj[minScb - 1] == undefined) {\r\n myObj[minScb - 1] = [leastScbPerson];\r\n mostScbObj[key - (minScb - 1)] = true;\r\n }else {\r\n myObj[minScb - 1].push(leastScbPerson);\r\n }\r\n }else if(0 == minScb - 1) n--;\r\n \r\n }\r\n \r\n console.log(ans.length);\r\n ans.forEach(conv => console.log(conv));\r\n \r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), myArr = readline().split(\" \"), ans = [];\r\n const people = mergeSort([...Array(n).keys()], myArr);\r\n let i = 0, j = n - 1;\r\n \r\n while(myArr[people[n - 2]] != 0) {\r\n if(0 == myArr[people[i]]) i++;\r\n else {\r\n myArr[people[i]]--;\r\n myArr[people[j]]--;\r\n ans.push((people[i] + 1) + \" \" + (people[j] + 1));\r\n \r\n if(myArr[people[j]] < myArr[people[j - 1]]) j--;\r\n if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;\r\n }\r\n }\r\n console.log(ans.length);\r\n ans.forEach(element => console.log(element));\r\n }\r\n}\r\n\r\nfunction mergeSort(array, reference) {\r\n const half = array.length / 2;\r\n if(array.length < 2) return array;\r\n const left = array.splice(0, half);\r\n return merge(mergeSort(left, reference),mergeSort(array, reference), reference);\r\n}\r\n\r\nfunction merge(left, right, reference) {\r\n let arr = [];\r\n while (left.length && right.length) {\r\n if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());\r\n else arr.push(right.shift());\r\n }\r\n return [ ...arr, ...left, ...right ];\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), myArr = readline().split(\" \"), ans = [];\r\n const people = mergeSort([...Array(n).keys()], myArr);\r\n let i = 0, j = n - 1;\r\n \r\n while(myArr[people[n - 2]] != 0) {\r\n if(0 == myArr[people[i]]) i++;\r\n if(myArr[people[j]] < myArr[people[j - 1]]) j--;\r\n if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;\r\n myArr[people[i]]--;\r\n myArr[people[j]]--;\r\n ans.push((people[i] + 1) + \" \" + (people[j] + 1));\r\n }\r\n console.log(ans.length);\r\n ans.forEach(element => console.log(element));\r\n }\r\n}\r\n\r\nfunction mergeSort(array, reference) {\r\n const half = array.length / 2;\r\n if(array.length < 2) return array;\r\n const left = array.splice(0, half);\r\n return merge(mergeSort(left, reference),mergeSort(array, reference), reference);\r\n}\r\n\r\nfunction merge(left, right, reference) {\r\n let arr = [];\r\n while (left.length && right.length) {\r\n if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());\r\n else arr.push(right.shift());\r\n }\r\n return [ ...arr, ...left, ...right ];\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), myArr = readline().split(\" \"), ans = [];\r\n const people = mergeSort([...Array(n).keys()], myArr);\r\n let i = 0, j = n - 1;\r\n \r\n while(myArr[people[n - 2]] != 0) {\r\n if(0 == myArr[people[i]]) i++;\r\n if(myArr[people[j]] < myArr[people[j - 1]]) j--;\r\n if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;\r\n myArr[people[i]]--;\r\n myArr[people[j]]--;\r\n ans.push((people[i] + 1) + \" \" + (people[j] + 1));\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n\r\nfunction mergeSort(array, reference) {\r\n const half = array.length / 2;\r\n if(array.length < 2) return array;\r\n const left = array.splice(0, half);\r\n return merge(mergeSort(left, reference),mergeSort(array, reference), reference);\r\n}\r\n\r\nfunction merge(left, right, reference) {\r\n let arr = [];\r\n while (left.length && right.length) {\r\n if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());\r\n else arr.push(right.shift());\r\n }\r\n return [ ...arr, ...left, ...right ];\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n let people = readline().split(\" \"), i = 0, j = n - 1;\r\n const ans = [];\r\n people = mergeSort(people);\r\n \r\n while(i < j) {\r\n if(0 == people[i]) i++;\r\n else if(0 == people[j]) j--;\r\n else {\r\n people[i]--;\r\n people[j]--;\r\n ans.push((i + 1) + \" \" + (j + 1));\r\n }\r\n }\r\n console.log(ans.length);\r\n ans.forEach(element => console.log(element));\r\n }\r\n}\r\n\r\nfunction mergeSort(array) {\r\n const half = array.length / 2;\r\n\r\n if(array.length < 2) return array;\r\n \r\n const left = array.splice(0, half);\r\n return merge(mergeSort(left),mergeSort(array));\r\n}\r\n\r\nfunction merge(left, right) {\r\n let arr = [];\r\n while (left.length && right.length) {\r\n if (left[0] < right[0]) arr.push(left.shift());\r\n else arr.push(right.shift());\r\n }\r\n return [ ...arr, ...left, ...right ];\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\r\n\t\ta.sort((x, y) => y[0] - x[0]);\r\n\r\n\t\tconst id = [];\r\n\t\tfor (let i = 0; i < n; i++) [a[i], id[i]] = a[i];\r\n\r\n\t\tlet ans = [];\r\n\t\tlet r = 0; while (a[r+1]) r++;\r\n\t\twhile (a[0] > a[1]) {\r\n\t\t\tif (r > 0 && a[r] > 0) ans.push(0, r), a[0]--, a[r]--;\r\n\t\t\tif (a[r] == 0) r--;\r\n\t\t\tif (r == 0) break;\r\n\t\t}\r\n\t\twhile (a[1]) {\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i] == 0) break;\r\n\t\t\t\tif (a[i]) ans.push(i), a[i]--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length>>1);\r\n\t\tfor (let i = 0; i < ans.length>>1; i++) {\r\n\t\t\tconsole.log(ans[2*i] + 1, ans[2*i+1] + 1);\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) \r\n\t\t\ta[i] = [a[i], i];\r\n\r\n\t\ta.sort((x, y) => y[0] - x[0]);\r\n\r\n\t\tconst ans = [];\r\n\t\tlet i = 0, j = 1;\r\n\t\twhile (j < n) {\r\n\t\t\tif (a[j][0] == 0) { j++; continue; }\r\n\t\t\tif (a[i][0] == 0) { i++; j = i + 1; continue; }\r\n\t\t\tans.push([a[i][1] + 1, a[j][1] + 1]);\r\n\t\t\ta[i][0]--;\r\n\t\t\ta[j][0]--;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tfor (const pair of ans)\r\n\t\t\tconsole.log(pair.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) \r\n\t\t\ta[i] = [a[i], i];\r\n\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\twhile (a[i][0]) {\r\n\t\t\t\tans.push([a[i][1] + 1, a[i+1][1] + 1]);\r\n\t\t\t\ta[i][0]--;\r\n\t\t\t\ta[i+1][0]--;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tconsole.log(ans.length);\r\n\t\tfor (const pair of ans)\r\n\t\t\tconsole.log(pair.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let n = parseInt(readline());\r\n while (n--) {\r\n readline();\r\n const nums = readline()\r\n .split(\" \")\r\n .map((v, i) => {\r\n return {\r\n value: parseInt(v),\r\n index: i,\r\n };\r\n })\r\n .sort((a, b) => b.value - a.value);\r\n const len = nums.length;\r\n let [leftPoint, rightPoint] = [0, 1];\r\n let ans = [];\r\n while (leftPoint < len && rightPoint < len) {\r\n const left = nums[leftPoint];\r\n const right = nums[rightPoint];\r\n if (leftPoint === rightPoint) {\r\n rightPoint += 1;\r\n continue;\r\n }\r\n if (left.value === 0) {\r\n leftPoint += 1;\r\n continue;\r\n }\r\n if (right.value === 0) {\r\n rightPoint += 1;\r\n continue;\r\n }\r\n ans.push([left.index, right.index]);\r\n left.value -= 1;\r\n right.value -= 1;\r\n }\r\n console.log(ans.length);\r\n for (let i = 0; i < ans.length; i += 1) {\r\n console.log(ans[i][0] + 1, ans[i][1] + 1);\r\n }\r\n }\r\n}\r\n"}], "src_uid": "5c013cdc91f88c102532a86058893f0d"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const s = input[index];\n const testCase = {\n n,\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, s } = testCase;\n\n let result = 0;\n\n let desc = true;\n for (let i = 1; i < n; i++) {\n if (desc && s[i] < s[i - 1]) {\n desc = false;\n result++;\n } else if (!desc && s[i] > s[i - 1]) {\n desc = true;\n result++;\n }\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = read().split('').map(Number);\r\n var ans = 0;\r\n var inv = 0;\r\n for (var i = 0; i < n; i++) {\r\n var cur = (a[i] + inv) % 2;\r\n if (cur === 1) {\r\n ans++;\r\n inv = 1 - inv;\r\n }\r\n }\r\n if (ans === 0) {\r\n write(0);\r\n return;\r\n }\r\n write(ans - 1);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n \r\n while(t--)\r\n {\r\n const n = parseInt(readLine());\r\n \r\n let arr = readLine().split(\"\").map(x=>parseInt(x));\r\n \r\n let len =arr.length\r\n let reverse_count=false\r\n let count=0\r\n \r\n for(let i=0;i arr[i+1])\r\n {\r\n //console.log(\"i1 \" + i)\r\n count++;\r\n reverse_count=true;\r\n }\r\n }\r\n \r\n }\r\n \r\n console.log(count)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n s = read().split('').map(Number);\r\n const dp = Array.from({\r\n length: n\r\n }, () => [Infinity, Infinity]);\r\n if (s[n - 1] === 0) {\r\n dp[n - 1] = [0, 1];\r\n } else {\r\n dp[n - 1] = [1, 0];\r\n }\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (s[i] === 0) {\r\n dp[i][0] = dp[i + 1][0];\r\n dp[i][1] = dp[i + 1][0] + 1;\r\n } else {\r\n dp[i][1] = dp[i + 1][1];\r\n dp[i][0] = dp[i + 1][1] + 1;\r\n }\r\n }\r\n let res = Infinity,\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n res = Math.min(res, sum + dp[i][sum & 1 ^ 1]);\r\n if (s[i] !== (sum & 1)) sum++;\r\n }\r\n res = Math.min(res, sum);\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n s = read().split('').map(Number);\r\n const dp = Array.from({\r\n length: n\r\n }, () => [Infinity, Infinity]);\r\n if (s[n - 1] === 0) {\r\n dp[n - 1] = [0, 1];\r\n } else {\r\n dp[n - 1] = [1, 0];\r\n }\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (s[i] === 0) {\r\n dp[i][0] = dp[i + 1][0];\r\n dp[i][1] = dp[i + 1][0] + 1;\r\n } else {\r\n dp[i][1] = dp[i + 1][1];\r\n dp[i][0] = dp[i + 1][1] + 1;\r\n }\r\n }\r\n let res = Infinity,\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n res = Math.min(res, sum + dp[i][sum & 1 ^ 1]);\r\n if (s[i] !== (sum & 1)) sum++;\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = read().split('').map(Number);\r\n var ans = 0;\r\n var inv = 0;\r\n for (var i = 0; i < n; i++) {\r\n var cur = (a[i] + inv) % 2;\r\n if (cur === 1) {\r\n ans ++;\r\n inv = 1 - inv;\r\n }\r\n }\r\n write(ans - 1);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "src_uid": "5278cb48aca6fc84e2df393cd8723ecb"} {"source_code": "function _defineProperties(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\")}var fs=require(\"fs\"),configPath=\"./compe.config.json\";function proc(t,e){if(global.MOD_=998244353,global.MOD_CUT=444595123,fs.existsSync(configPath)){if(!fs.existsSync(e))return void console.log(\"Input directory does not exist\");var r=fs.readFileSync(e,{encoding:\"utf-8\"}),n=0;r=r.split(/ |\\n|\\r/g);for(var i,o=[],s=_createForOfIteratorHelperLoose(r);!(i=s()).done;){var a=i.value;a.length>0&&o.push(a)}global.rnum=function(t){return t?o.slice(n,n+=t).map((function(t){return+t})):+o[n++]},global.rstr=function(t){return t?o.slice(n,n+=t):o[n++]},global.rbig=function(t){return t?o.slice(n,n+=t).map((function(t){return BigInt(t)})):BigInt(o[n++])},global.print=function(){for(var t=arguments.length,e=new Array(t),r=0;r0&&n.push(o)}global.rnum=function(t){return t?n.slice(e,e+=t).map((function(t){return+t})):+n[e++]},global.rstr=function(t){return t?n.slice(e,e+=t):n[e++]},global.rbig=function(t){return t?n.slice(e,e+=t).map((function(t){return BigInt(t)})):BigInt(n[e++])};var s=\"\";global.print=function(){for(var t=arguments.length,e=new Array(t),r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\")}Object.defineProperty(exports,\"__esModule\",{value:!0});var ErrorGenerator,ForOfAdaptor=function(t){function e(t,e){this.it_=t,this.last_=e}var r=e.prototype;return r.next=function(){if(this.it_.equals(this.last_))return{done:!0,value:void 0};var t=this.it_;return this.it_=this.it_.next(),{done:!1,value:t.value}},r[t]=function(){return this},e}(Symbol.iterator),Container=function(t){function e(){}var r=e.prototype;return r.empty=function(){return 0===this.size()},r.rbegin=function(){return this.end().reverse()},r.rend=function(){return this.begin().reverse()},r[t]=function(){return new ForOfAdaptor(this.begin(),this.end())},r.toJSON=function(){for(var t,e=[],r=_createForOfIteratorHelperLoose$1(this);!(t=r()).done;){var n=t.value;e.push(n)}return e},e}(Symbol.iterator),NativeArrayIterator=function(){function t(t,e){this.data_=t,this.index_=e}var e=t.prototype;return e.index=function(){return this.index_},e.prev=function(){return--this.index_,this},e.next=function(){return++this.index_,this},e.advance=function(t){return this.index_+=t,this},e.equals=function(t){return this.data_===t.data_&&this.index_===t.index_},e.swap=function(t){var e=[t.data_,this.data_];this.data_=e[0],t.data_=e[1];var r=[t.index_,this.index_];this.index_=r[0],t.index_=r[1]},_createClass$1(t,[{key:\"value\",get:function(){return this.data_[this.index_]}}]),t}(),SetContainer=function(t){function e(e){var r;return(r=t.call(this)||this).data_=e(_assertThisInitialized(r)),r}_inheritsLoose(e,t);var r=e.prototype;return r.assign=function(t,e){this.clear(),this.insert(t,e)},r.clear=function(){this.data_.clear()},r.begin=function(){return this.data_.begin()},r.end=function(){return this.data_.end()},r.has=function(t){return!this.find(t).equals(this.end())},r.size=function(){return this.data_.size()},r.push=function(){for(var t=arguments.length,e=new Array(t),r=0;r (index = \"+n+\").\")},t.excessive_index=function(t,r,n,i){return new OutOfRange(\"Error on \"+e(t)+\".\"+r+\"(): parametric index is equal or greater than size -> (index = \"+n+\", size: \"+i+\").\")},t.not_my_iterator=function(t,r){return new InvalidArgument(\"Error on \"+e(t)+\".\"+r+\"(): parametric iterator is not this container's own.\")},t.erased_iterator=function(t,r){return new InvalidArgument(\"Error on \"+e(t)+\".\"+r+\"(): parametric iterator, it already has been erased.\")},t.negative_iterator=function(t,r,n){return new OutOfRange(\"Error on \"+e(t)+\".\"+r+\"(): parametric iterator is directing negative position -> (index = \"+n+\").\")},t.iterator_end_value=function(t,r){void 0===r&&(r=\"end\");var n=e(t);return new OutOfRange(\"Error on \"+n+\".Iterator.value: cannot access to the \"+n+\".\"+r+\"().value.\")},t.key_nout_found=function(t,r,n){throw new OutOfRange(\"Error on \"+e(t)+\".\"+r+\"(): unable to find the matched key -> \"+n)}}(ErrorGenerator||(ErrorGenerator={}));var IAssociativeContainer,UniqueSet=function(t){function e(){return t.apply(this,arguments)||this}_inheritsLoose(e,t);var r=e.prototype;return r.count=function(t){return this.find(t).equals(this.end())?0:1},r.insert=function(){for(var e,r=arguments.length,n=new Array(r),i=0;i1?e-1:0),n=1;n=1&&r[0]instanceof Array?(i=function(){var e=r[0];t.push.apply(t,e)},o=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(i=function(){var e=r[0],n=r[1];t.assign(e,n)},o=r.slice(2)):(i=null,o=r),{ramda:i,tail:o}}}(IAssociativeContainer||(IAssociativeContainer={}));var is_node_=null;function is_node(){return null===is_node_&&(is_node_=\"object\"==typeof global&&\"object\"==typeof global.process&&\"object\"==typeof global.process.versions&&void 0!==global.process.versions.node),is_node_}function _Get_root(){return null===__s_pRoot&&void 0===(__s_pRoot=is_node()?global:self).__s_iUID&&(__s_pRoot.__s_iUID=0),__s_pRoot}var ITreeContainer,__s_pRoot=null;function get_uid(t){if(t instanceof Object){if(!1===t.hasOwnProperty(\"__get_m_iUID\")){var e=++_Get_root().__s_iUID;Object.defineProperty(t,\"__get_m_iUID\",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function equal_to(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function less(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):get_uid(t)3?o-3:0),a=3;a=1&&(i=h.tail[0])}r(i),null!==n&&n()},t.emplacable=function(t,e,r){var n=e.prev(),i=n.equals(t.end())||t.value_comp()(n.value,r);return i=i&&(e.equals(t.end())||t.value_comp()(r,e.value))}}(ITreeContainer||(ITreeContainer={}));var INIT_VALUE=2166136261,MULTIPLIER=16777619,Pair=function(){function t(t,e){this.first=t,this.second=e}var e=t.prototype;return e.equals=function(t){return equal_to(this.first,t.first)&&equal_to(this.second,t.second)},e.less=function(t){return!1===equal_to(this.first,t.first)?less(this.first,t.first):less(this.second,t.second)},e.hashCode=function(){return hash(this.first,this.second)},t}(),UniqueTreeSet=function(t){function e(){return t.apply(this,arguments)||this}_inheritsLoose(e,t);var r=e.prototype;return r.find=function(t){var e=this.lower_bound(t);return!e.equals(this.end())&&this._Key_eq(t,e.value)?e:this.end()},r.equal_range=function(t){var e=this.lower_bound(t);return new Pair(e,!e.equals(this.end())&&this._Key_eq(t,e.value)?e.next():e)},r.value_comp=function(){return this.key_comp()},r._Key_eq=function(t,e){return!this.key_comp()(t,e)&&!this.key_comp()(e,t)},r._Insert_by_key=function(t){var e=this.lower_bound(t);return!e.equals(this.end())&&this._Key_eq(e.value,t)?new Pair(e,!1):(e=this.data_.insert(e,t),this._Handle_insert(e,e.next()),new Pair(e,!0))},r._Insert_by_hint=function(t,e){if(ITreeContainer.emplacable(this,t,e)){var r=this.data_.insert(t,e);return this._Handle_insert(r,r.next()),r}return this._Insert_by_key(e).first},e}(UniqueSet),ListIterator=function(){function t(t,e,r){this.prev_=t,this.next_=e,this.value_=r}t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e};var e=t.prototype;return e.prev=function(){return this.prev_},e.next=function(){return this.next_},e._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw ErrorGenerator.iterator_end_value(this.source())},e.equals=function(t){return this===t},_createClass$1(t,[{key:\"value\",get:function(){return this._Try_value(),this.value_}}]),t}(),Repeater=function(){function t(t,e){this.index_=t,this.value_=e}var e=t.prototype;return e.index=function(){return this.index_},e.next=function(){return++this.index_,this},e.equals=function(t){return this.index_===t.index_},_createClass$1(t,[{key:\"value\",get:function(){return this.value_}}]),t}();function advance(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var r;if(e<0){if(!(t.prev instanceof Function))throw new InvalidArgument(\"Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.\");r=function(t){return t.prev()},e=-e}else r=function(t){return t.next()};for(;e-- >0;)t=r(t);return t}var ListContainer=function(t){function e(){var e;return(e=t.call(this)||this).end_=e._Create_iterator(null,null),e.clear(),e}_inheritsLoose(e,t);var r=e.prototype;return r.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},r.clear=function(){ListIterator._Set_prev(this.end_,this.end_),ListIterator._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},r.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(advance(this.end(),-e),this.end())},r.begin=function(){return this.begin_},r.end=function(){return this.end_},r.size=function(){return this.size_},r.push_front=function(t){this.insert(this.begin_,t)},r.push_back=function(t){this.insert(this.end_,t)},r.pop_front=function(){if(!0===this.empty())throw ErrorGenerator.empty(this.end_.source().constructor.name,\"pop_front\");this.erase(this.begin_)},r.pop_back=function(){if(!0===this.empty())throw ErrorGenerator.empty(this.end_.source().constructor.name,\"pop_back\");this.erase(this.end_.prev())},r.push=function(){for(var t=arguments.length,e=new Array(t),r=0;r=0;--o){var s=this.tryEntries[o],a=s.completion;if(\"root\"===s.tryLoc)return i(\"end\");if(s.tryLoc<=this.prev){var u=n.call(s,\"catchLoc\"),h=n.call(s,\"finallyLoc\");if(u&&h){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,\"finallyLoc\")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if(\"throw\"===n.type){var i=n.arg;k(r)}return i}}throw new Error(\"illegal catch attempt\")},delegateYield:function(t,r,n){return this.delegate={iterator:z(t),resultName:r,nextLoc:n},\"next\"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){\"object\"==typeof globalThis?globalThis.regeneratorRuntime=e:Function(\"r\",\"regeneratorRuntime = r\")(e)}})),Deque=function(t){function e(t){this.head=0,this.tail=0,this.mask=1,this.list=new Array(2),t&&this.extend(t)}var r=e.prototype;return r.extend=function(t){for(var e,r=_createForOfIteratorHelperLoose(t);!(e=r()).done;){var n=e.value;this.push(n)}return this},r.extendFront=function(t){for(var e,r=_createForOfIteratorHelperLoose(t);!(e=r()).done;){var n=e.value;this.pushFront(n)}return this},r._resize=function(t,e){var r=this.head,n=this.mask;if(this.head=0,this.tail=t,this.mask=e-1,0!==r){for(var i=new Array(e),o=0;o=r||t<-r)throw new RangeError(\"deque index out of range\");return i[(t>=0?e:n)+t&this.mask]},r.indexOf=function(t,e){void 0===e&&(e=0);for(var r=this.head,n=this.list,i=this.size,o=this.mask,s=e>=0?e:e<-i?0:i+e;s>>1&&this._resize(this.size,this.list.length>>>1),t},r.popFront=function(){if(this.head===this.tail)throw new RangeError(\"pop from an empty deque\");var t=this.list[this.head];return this.list[this.head]=void 0,this.head=this.head+1&this.mask,this.size>>1&&this._resize(this.size,this.list.length>>>1),t},r.delete=function(t){if(t>=this.size||t<0)throw new RangeError(\"deque index out of range\");for(var e=this.head+t&this.mask;e!==this.tail;){var r=e+1&this.mask;this.list[e]=this.list[r],e=r}return this.tail=this.tail-1&this.mask,this.size>>1&&this._resize(this.size,this.list.length>>>1),this},r.reverse=function(){for(var t=this.head,e=this.tail,r=this.size,n=this.mask,i=0;i<~~(r/2);i++){var o=e-i-1&n,s=t+i&n,a=this.list[o];this.list[o]=this.list[s],this.list[s]=a}return this},r.rotate=function(t){void 0===t&&(t=1);var e=this.head,r=this.tail;if(0===t||e===r)return this;if(this.head=e-t&this.mask,this.tail=r-t&this.mask,t>0)for(var n=1;n<=t;n++){var i=e-n&this.mask,o=r-n&this.mask;this.list[i]=this.list[o],this.list[o]=void 0}else for(var s=0;s>t;s--){var a=r-s&this.mask,u=e-s&this.mask;this.list[a]=this.list[u],this.list[u]=void 0}return this},r.entries=runtime_1.mark((function t(){var e,r,n,i,o;return runtime_1.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.head,r=this.size,n=this.list,i=this.mask,o=0;case 2:if(!(o=1){var e;if(\"object\"==typeof t)throw new Error(\"The value can not be object\");var r=[t,[]],n=0,i=1;r[0]=new Array((e=(arguments.length<=1?0:arguments.length-1)-1+1)<1||arguments.length<=e?void 0:arguments[e]);for(var o=0;o=0;s--){if(!Number.isInteger(s+1<1||arguments.length<=s+1?void 0:arguments[s+1]))throw new Error(\"Please pass integer arguments for array size\");r[i]=new Array(s+1<1||arguments.length<=s+1?void 0:arguments[s+1]);for(var a=0;a<(s+1<1||arguments.length<=s+1?void 0:arguments[s+1]);a++)r[i][a]=r[n].slice();var u=[i,n];n=u[0],i=u[1]}return r[n]}},vectorArray=function(t){for(var e=new Array(t),r=0;rthis.p[e]){var r=[e,t];t=r[0],e=r[1]}return this.p[t]+=this.p[e],this.p[e]=t,!0},e.size=function(t){return t=this.group(t),-this.p[t]},t}(),PriorityQueue=function(){function t(t){this.comparator=t||function(t,e){return t0&&(r=e>>1,!this.comparator(this.elem[e],this.elem[r]));)this.swap(e,r),e=r},e.pop=function(){var t=this.top,e=this.elem.pop(),r=this.size;if(0==r)return t;this.elem[0]=e;for(var n=0,i=0,o=0,s=0;n=0;t=(t&t+1)-1)e=this.updateMethod(e,this.cont[t]);return e},e.update=function(t,e){for(;t<=this.elemCount;t|=t+1)this.cont[t]=this.updateMethod(this.cont[t],e)},t}(),SegmentTree=function(){function t(t,e,r,n){if(void 0===n&&(n=null),this.identityValue=e,this.merger=r,this.elemCount=t,this.log=Math.ceil(Math.log2(t)),this.size=1<=1;o--)this.internalUpdate(o)}}var e=t.prototype;return e.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},e.set=function(t,e){t+=this.size,this.cont[t]=e;for(var r=1;r<=this.log;r++)this.internalUpdate(t>>r)},e.get=function(t){return t?this.cont[t+this.size]:this.cont.slice(this.size,this.size+this.elemCount)},e.query=function(t,e){void 0===t&&(t=0),void 0===e&&(e=this.elemCount-1),e++;var r=this.identityValue,n=this.identityValue;for(t+=this.size,e+=this.size;t>=1,e>>=1;return this.merger(r,n)},e.all=function(){return this.cont[1]},t}(),LazySegmentTree=function(){function t(t,e,r,n,i,o,s){if(void 0===s&&(s=null),this.identityValue=e,this.merger=r,this.identityLazy=n,this.pusher=i,this.modifier=o,this.log=Math.ceil(Math.log2(t)),this.size=1<=1;u--)this.internalUpdate(u)}}var e=t.prototype;return e.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},e.internalModify=function(t,e){e!==this.identityLazy&&(this.cont[t]=this.modifier(this.cont[t],e),t=1;r--)this.internalPush(t>>r);this.cont[t]=e;for(var n=1;n<=this.log;n++)this.internalUpdate(t>>n)},e.get=function(t){t+=this.size;for(var e=this.log;e>=1;e--)this.internalPush(t>>e);return this.cont[t]},e.query=function(t,e){e++,t+=this.size,e+=this.size;for(var r=this.log;r>=1;r--)t>>r<>r),e>>r<>r);for(var n=this.identityValue,i=this.identityValue;t>=1,e>>=1;return this.merger(n,i)},e.all=function(){return this.cont[1]},e.update=function(t,e,r){e++,t+=this.size,e+=this.size;for(var n=this.log;n>=1;n--)t>>n<>n),e>>n<>n);for(var i=t,o=e;t>=1,e>>=1;t=i,e=o;for(var s=1;s<=this.log;s++)t>>s<>s),e>>s<>s)},t}(),defaultComparator=function(t,e){return t>>1)],e)?r=o+1:n=o;return r},upperBound=function(t,e,r,n,i){var o;for(void 0===r&&(r=0),void 0===n&&(n=0),void 0===i&&(i=defaultComparator),n||(n=t.length);r>>1)])?n=o:r=o+1;return r},binarySearch=function(t,e,r){for(var n,i=null;t<=e;)r(n=t+e>>1)?(i=n,e=n-1):t=n+1;return i},ternarySearch=function(t,e,r,n,i){var o,s;if(void 0===n&&(n=!1),void 0===i&&(i=200),n)for(;i--;)s=e-(e-t)/3,r(o=t+(e-t)/3)>1),r(i-1)>1),r(a-1)>u?(h=u,t=a+1):e=a-1;return h},Graph=function(){function t(t){this.g=vectorArray(t+1),this.vis=multiArray(!1,t+1),this.par=multiArray(-1,t+1)}var e=t.prototype;return e.addEdge=function(t,e,r){this.g[t].push({to:e,prop:r})},e.addBiEdge=function(t,e,r){this.addEdge(t,e,r),this.addEdge(e,t,r)},e.reset=function(){this.vis=multiArray(!1,this.g.length),this.par=multiArray(-1,this.g.length)},t}(),dfs=function(t,e,r,n){var i=new Deque;for(i.push(e);i.size;){var o=i.back;if(t.vis[o])n(o,t),i.pop();else{t.vis[o]=!0,r(o,t);for(var s,a=_createForOfIteratorHelperLoose(t.g[o]);!(s=a()).done;){var u=s.value;t.vis[u.to]||(t.par[u.to]=o,i.push(u.to))}}}},bfs=function(t,e,r){var n=new Deque;if(n.push(e),Array.isArray(e))for(var i,o=_createForOfIteratorHelperLoose(e);!(i=o()).done;){var s=i.value;t.vis[s]=!0,n.push(s)}else t.vis[e]=!0,n.push(e);for(;n.size;){var a=n.pop();r(a,t);for(var u,h=_createForOfIteratorHelperLoose(t.g[a]);!(u=h()).done;){var l=u.value;t.vis[l.to]||(t.par[l.to]=a,n.push(l.to),t.vis[l.to]=!0)}}},mst=function(t){for(var e=0,r=[],n=[],i=0;ii[r]+f.prop.weight&&(i[f.to]=i[r]+f.prop.weight,t.par[f.to]=r,o[f.to]||(o[f.to]=!0,s.push(f.to)))}}return{parArray:t.par,distArray:i}},dijkstra=function(t,e){t.reset();var r=new PriorityQueue((function(t,e){return t.dist>e.dist})),n=Number.MAX_SAFE_INTEGER,i=multiArray(n,t.g.length);if(Array.isArray(e))for(var o,s=_createForOfIteratorHelperLoose(e);!(o=s()).done;){var a=o.value;r.push({node:a,dist:0}),i[a]=0}else r.push({node:e,dist:0}),i[e]=0;for(;r.size;){var u=r.pop();if(i[u.node]===u.dist)for(var h,l=_createForOfIteratorHelperLoose(t.g[u.node]);!(h=l()).done;){var c=h.value;i[c.to]>i[u.node]+c.prop.weight&&(i[c.to]=i[u.node]+c.prop.weight,t.par[c.to]=u.node,r.push({node:c.to,dist:i[c.to]}))}}return{parArray:t.par,distArray:i}},setMod=function(t){global.MOD_=t,global.MOD_CUT=1099511627776%t},add=function(){for(var t=arguments.length,e=new Array(t),r=0;r=1;n--)e[0]+=e[n],e[0]=e[0]>=global.MOD_?e[0]-global.MOD_:e[0];return e[0]},sub=function(t,e){return(t+=global.MOD_-e)>=global.MOD_?t-global.MOD_:t},mul=function(){for(var t=arguments.length<=0?void 0:arguments[0],e=1;e>20)*((e<0||arguments.length<=e?void 0:arguments[e])>>20)*global.MOD_CUT+(4293918720&t)*(1048575&(e<0||arguments.length<=e?void 0:arguments[e]))+(1048575&t)*(e<0||arguments.length<=e?void 0:arguments[e]))%global.MOD_;return t},pow=function(t,e){for(var r=1;e;)1&e&&(r=mul(r,t)),t=mul(t,t),e>>>=1;return r},inv=function(t){return a<0?a+global.MOD_:a},factSetup=function(t){void 0===t&&(t=2e5),global.factorial=Array(t+1).fill(1),global.invFactorial=Array(t+1).fill(1);for(var e=1;e<=t;e++)global.factorial[e]=mul(global.factorial[e-1],e);global.invFactorial[t]=inv();for(var r=t-1;r>=1;r--)global.invFactorial[r]=mul(global.invFactorial[r+1],r+1)},binom=function(t,e){return e>t?0:mul(global.factorial[t],global.invFactorial[e],global.invFactorial[t-e])},fact=function(t){return global.factorial[t]};\r\n\r\nfunction main() {\r\n // write your code from here\r\n let [n, m] = rnum(2);\r\n let segs = Array(n).fill(0);\r\n for (let i = 0; i < n; i ++) {\r\n let [l, r, w] = rnum(3);\r\n l --;\r\n r --;\r\n segs[i] = {l, r, w}; \r\n }\r\n segs.sort((a, b) => a.w - b.w);\r\n const INF = 1 << 30;\r\n let tree = new LazySegmentTree(\r\n m - 1, INF, (a, b) => a < b ? a : b,\r\n INF, (a, b) => b, (a, b) => b, Array(m - 1).fill(-INF)\r\n );\r\n let ans = INF;\r\n for (let seg of segs) {\r\n tree.update(seg.l, seg.r - 1, seg.w);\r\n let best = seg.w - tree.all()\r\n ans = ans < best ? ans : best;\r\n }\r\n print(ans);\r\n}\r\nproc(main, 'input.txt');\r\n\r\n\r\n// Generated with compe.js - https://github.com/polarity-cf/compe.js", "positive_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n console.log(solve(n, m, arr))\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}], "negative_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n try{\n const [l, r, w] = arr[j]\n }catch(e) {\n throw arr.length\n }\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n \n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n try{\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n }catch(e) {\n throw -4\n }\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n try {\n tree[idx].left\n } catch (e) {\n throw 7e8 + idx\n }\n const { left, right, lazy } = tree[idx]\n try {\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n } catch (e) {\n throw 9e8 + idx\n }\n\n try {\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n } catch (e) {\n throw 8e8 + idx\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n try {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }catch(e) {\n throw -5\n }\n }\n if (r > mid) {\n try {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }catch(e) {\n throw -6\n }\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n // try{\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // }catch(e) {\n // throw -7\n // }\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n \n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n try{\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n }catch(e) {\n throw -4\n }\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n try {\n tree[idx].left\n } catch (e) {\n throw 7e8 + idx\n }\n const { left, right, lazy } = tree[idx]\n try {\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n } catch (e) {\n throw 9e8 + idx\n }\n\n try {\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n } catch (e) {\n throw 8e8 + idx\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n try {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }catch(e) {\n throw -5\n }\n }\n if (r > mid) {\n try {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }catch(e) {\n throw -6\n }\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n try{\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n }catch(e) {\n throw j + n\n }\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n \n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n try{\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n }catch(e) {\n throw -4\n }\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n try {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }catch(e) {\n throw -5\n }\n }\n if (r > mid) {\n try {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }catch(e) {\n throw -6\n }\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n try{\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n }catch(e) {\n throw -7\n }\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n \n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n try{\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n }catch(e) {\n throw -4\n }\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n try {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }catch(e) {\n throw -5\n }\n }\n if (r > mid) {\n try {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }catch(e) {\n throw -6\n }\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n try{\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n }catch(e) {\n throw -3\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n try{\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n }catch(e) {\n throw -4\n }\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw -1\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw -2\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n try {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } catch (e) {\n throw ['a', 2 * idx + 1, l, r, val].join(' ')\n }\n }\n if (r > mid) {\n try {\n // throw 'sb'\n insertTree(tree, 2 * idx + 2, l, r, val)\n } catch (e) {\n throw ['b', 2 * idx + 2, l, r, val].join(' ')\n }\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n try {\n console.log(solve(n, m, arr))\n } catch (e) {\n console.log(e.stack)\n }\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n // console.log('j++', i, j - 1, covered)\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j - 1, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n console.log(solve(n, m, arr))\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n && j < n) {\n let covered\n while (j < n && queryTree(tree, 0, f(1), f(m, 1)) === 0) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n // if (covered) {\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n // break\n // }\n j++\n }\n // if (!covered) break\n if (queryTree(tree, 0, f(1), f(m, 1)) === 0) break\n ans = Math.min(ans, arr[j - 1][2] - arr[i][2])\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n console.log(solve(n, m, arr))\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m, 1), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n && j < n) {\n let covered\n while (j < n) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r, 1), 1)\n // console.log(tree)\n\n covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('j++', i, j, covered)\n if (covered) {\n ans = Math.min(ans, arr[j][2] - arr[i][2])\n // console.log(ans, i, j, arr[j][2], arr[i][2])\n j++\n break\n }\n j++\n }\n if (!covered) break\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r, 1), -1)\n\n // covered = queryTree(tree, 0, f(1), f(m, 1)) > 0\n // console.log('i++', i + 1, j, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x, right) {\n return right ? x - 1 : x\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n tree[idx].val += val\n tree[idx].lazy += val\n return\n }\n\n if (lazy && left !== right) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n const merge = Math.min\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (l <= left && r >= right) return val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy) {\n tree[2 * idx + 1].val += lazy\n tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy += lazy\n tree[2 * idx + 2].lazy += lazy\n tree[idx].lazy = 0\n }\n\n let a = Infinity\n let b = Infinity\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = Math.min\n return merge(a, b)\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n console.log(solve(n, m, arr))\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, arr) {\n arr.sort((a, b) => a[2] - b[2])\n// console.log(arr)\n const tree = []\n createTree(tree, 0, f(1), f(m), 0)\n\n let i = 0\n let j = 0\n let ans = Infinity\n while (i < n && j < n) {\n let covered\n while (j < n) {\n const [l, r, w] = arr[j]\n insertTree(tree, 0, f(l), f(r), 1)\n // console.log(tree)\n\n covered = queryTree(tree, 0, f(1), f(m), and)\n // console.log('j++', i, j, covered)\n if (covered) {\n ans = Math.min(ans, arr[j][2] - arr[i][2])\n break\n }\n\n j++\n }\n if (!covered) break\n\n // while (i <= j) {\n const [l, r, w] = arr[i]\n insertTree(tree, 0, f(l), f(r), -1)\n\n covered = queryTree(tree, 0, f(1), f(m), and)\n // console.log('i++', i + 1, j, covered)\n // if (!covered) break\n\n i++\n // ans = Math.min(ans, arr[j][2] - arr[i][2])\n // }\n // if (covered) break\n }\n return ans\n}\nfunction f(x) {\n return 2 * x - 1\n}\nfunction and(a, b) {\n return a & b\n}\n\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction initTree(tree, merge, arr) {\n for (let i = tree.length - 1; i >= 0; i--) {\n if (!tree[i]) continue\n const { left, right } = tree[i]\n tree[i].val = left === right\n ? arr[left % arr.length]\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\n }\n}\nfunction insertTree(tree, idx, l, r, val) {\n const { left, right, lazy } = tree[idx]\n if (l === left && r === right) {\n tree[idx].val += val\n tree[idx].lazy = true\n return\n }\n\n const mid = Math.floor((left + right) / 2)\n if (r <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n } else if (l > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n } else {\n insertTree(tree, 2 * idx + 1, l, mid, val)\n insertTree(tree, 2 * idx + 2, mid + 1, r, val)\n }\n}\nfunction queryTree(tree, idx, l, r, merge) {\n const { left, right, lazy } = tree[idx]\n if (l === left && r === right && lazy && tree[idx].val) return tree[idx].val // lazy lag\n if (left === right) return tree[idx].val\n\n const mid = Math.floor((left + right) / 2)\n if (r <= mid) {\n return queryTree(tree, 2 * idx + 1, l, r, merge)\n } else if (l > mid) {\n return queryTree(tree, 2 * idx + 2, l, r, merge)\n } else {\n const a = queryTree(tree, 2 * idx + 1, l, mid, merge)\n const b = queryTree(tree, 2 * idx + 2, mid + 1, r, merge)\n return merge(a, b)\n }\n}\n"}], "src_uid": "3dc14d8d19938d9a5ed8323fe608f581"} {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i < 100000; i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n for (var j = i * 2; j < 100000; j += i) {\r\n erat[j] = 1;\r\n }\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var canDiv = a % b === 0 || b % a === 0;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var maxAns = 0;\r\n var i = 0;\r\n while(a !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(a % pArr[i] === 0) {\r\n maxAns++;\r\n a = div(a, pArr[i]);\r\n }\r\n i++;\r\n }\r\n var i = 0;\r\n while(b !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(b % pArr[i] === 0) {\r\n maxAns++;\r\n b = div(b, pArr[i]);\r\n }\r\n i++;\r\n }\r\n if (k === 1) {\r\n write(canDiv && !isEqual ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i <= Math.floor(Math.sqrt(1000000000)); i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n for (var j = i * 2; j <= Math.floor(Math.sqrt(1000000000)); j += i) {\r\n erat[j] = 1;\r\n }\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var canDiv = a % b === 0 || b % a === 0;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var maxAns = 0;\r\n var i = 0;\r\n while(a !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(a % pArr[i] === 0) {\r\n maxAns++;\r\n a = div(a, pArr[i]);\r\n }\r\n i++;\r\n }\r\n var i = 0;\r\n while(b !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(b % pArr[i] === 0) {\r\n maxAns++;\r\n b = div(b, pArr[i]);\r\n }\r\n i++;\r\n }\r\n if (k === 1) {\r\n write(canDiv && !isEqual ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i < 100000; i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n for (var j = i * 2; j < 100000; j += i) {\r\n erat[j] = 1;\r\n }\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var canDiv = a % b === 0 || b % a === 0;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var maxAns = 0;\r\n var i = 0;\r\n while(a !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(a % pArr[i] === 0) {\r\n maxAns++;\r\n a = div(a, pArr[i]);\r\n }\r\n i++;\r\n }\r\n var i = 0;\r\n while(b !== 1) {\r\n if (i >= pArr.length) {\r\n maxAns++;\r\n break;\r\n }\r\n while(b % pArr[i] === 0) {\r\n maxAns++;\r\n b = div(b, pArr[i]);\r\n }\r\n i++;\r\n }\r\n if (k === 1) {\r\n write(canDiv && !isEqual ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (k === 2) {\r\n write(maxAns >= 2 && maxAns >= 2 ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nconst primes = new Set(getPrimes(10 ** 5));\r\nfunction solve(n, m, k) {\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n let a = 0,\r\n b = 0;\r\n for (let num of primes) {\r\n if (num > n && num > m) break;\r\n while (n % num === 0) {\r\n a++;\r\n n /= num;\r\n }\r\n while (m % num === 0) {\r\n b++;\r\n m /= num;\r\n }\r\n if (a + b >= k) return 'YES';\r\n }\r\n if (n > 1 && !primes.has(n)) a++;\r\n if (m > 1 && !primes.has(m)) b++;\r\n if (a + b >= k) return 'YES';\r\n return 'NO';\r\n}\r\nfunction getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n return primes;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(Math.ceil(Math.sqrt(1e9)))\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n const g = gcd(a, b)\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n\n const divided = a === g || b === g\n if (a === b) {\n const min = 0\n const max = 2 * n\n return k >= min && k <= max && k !== 1\n } else if (divided) {\n const min = 1\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n } else {\n const min = 2\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n }\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n if (x !== 1) c++ // the last non-divided big prime\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet a;\r\nlet b;\r\nlet k;\r\nconst MAX = 50000;\r\nlet primes = [];\r\nlet sieve = new Int32Array(MAX).fill(0);\r\nfunction precalc() {\r\n sieve[1] = 1;\r\n for (let i = 2; i < MAX; i++) {\r\n if (sieve[i] == 0) {\r\n sieve[i] = i;\r\n primes.push(i);\r\n for (let j = i; i * j < MAX; j++) {\r\n sieve[i * j] = i;\r\n }\r\n }\r\n }\r\n // console.log(primes);\r\n}\r\nfunction npf(x) {\r\n let rv = 0;\r\n for (let p of primes) {\r\n if (p > x) {\r\n break;\r\n }\r\n while ((x % p) == 0) {\r\n rv++;\r\n x /= p;\r\n }\r\n }\r\n if (x > 1) { // x included a large prime\r\n rv++;\r\n }\r\n return rv;\r\n}\r\nfunction gcd(a, b) {\r\n while (a > 0) {\r\n let c = a;\r\n a = b % a;\r\n b = c;\r\n }\r\n return b;\r\n}\r\nfunction solve() {\r\n // printf(\"npf(%d) %d\\n\", a, npf(a));\r\n // printf(\"npf(%d) %d\\n\", b, npf(b));\r\n let g = gcd(a, b);\r\n if (k == 1) {\r\n if (a == b) {\r\n return false;\r\n }\r\n return a == g || b == g;\r\n }\r\n let mx = npf(a) + npf(b);\r\n if (k > mx) {\r\n return false;\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n precalc();\r\n check(npf(1000000007) == 1);\r\n while (tc-- > 0) {\r\n a = nextInt();\r\n b = nextInt();\r\n k = nextInt();\r\n if (solve()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i < 100000; i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var canDiv = a % b === 0 || b % a === 0;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var parra = [0, 0];\r\n var parrb = [0, 0];\r\n var i = 2;\r\n while(a !== 1) {\r\n parra[i] = 0;\r\n while(a % i === 0) {\r\n parra[i]++;\r\n a = div(a, i);\r\n }\r\n i++;\r\n }\r\n var i = 2;\r\n while(b !== 1) {\r\n parrb[i] = 0;\r\n while(b % i === 0) {\r\n parrb[i]++;\r\n b = div(b, i);\r\n }\r\n i++;\r\n }\r\n while (parra.length < parrb.length) {\r\n parra.push(0);\r\n }\r\n while (parrb.length < parra.length) {\r\n parrb.push(0);\r\n }\r\n var maxAns = 0;\r\n var minAns = 0;\r\n for (var i = 0; i < parrb.length; i++) {\r\n minAns += Math.abs(parrb[i] - parra[i]);\r\n maxAns += parra[i] + parrb[i];\r\n }\r\n if (k === 1) {\r\n write(canDiv && !isEqual ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (k === 2) {\r\n write(maxAns >= 2 && maxAns >= 2 ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (minAns > k || maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i < 100000; i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var canDiv = a % b === 0 || b % a === 0;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var parra = [0, 0];\r\n var parrb = [0, 0];\r\n var i = 2;\r\n while(a !== 1) {\r\n parra[i] = 0;\r\n while(a % i === 0) {\r\n parra[i]++;\r\n a = div(a, i);\r\n }\r\n i++;\r\n }\r\n var i = 2;\r\n while(b !== 1) {\r\n parrb[i] = 0;\r\n while(b % i === 0) {\r\n parrb[i]++;\r\n b = div(b, i);\r\n }\r\n i++;\r\n }\r\n while (parra.length < parrb.length) {\r\n parra.push(0);\r\n }\r\n while (parrb.length < parra.length) {\r\n parrb.push(0);\r\n }\r\n var maxAns = 0;\r\n var minAns = 0;\r\n for (var i = 0; i < parrb.length; i++) {\r\n minAns += Math.abs(parrb[i] - parra[i]);\r\n maxAns += parra[i] + parrb[i];\r\n }\r\n if (k === 1) {\r\n write(canDiv && !isEqual ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (k === 2) {\r\n write(maxAns >= 2 && maxAns >= 2 ? 'YES' : 'NO');\r\n return;\r\n }\r\n if (minAns > k || maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n if (isEqual) {\r\n write((k & 1) ? 'NO' : 'YES');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nvar erat = [];\r\nvar pArr = [];\r\nfunction fillErat() {\r\n for (var i = 2; i < 100000; i++) {\r\n if (erat[i]) {\r\n continue;\r\n }\r\n pArr.push(i);\r\n }\r\n}\r\nfillErat();\r\n\r\nfunction solve() {\r\n var abk = readArray(Number);\r\n var a = abk[0];\r\n var b = abk[1];\r\n var minAns = a % b === 0 || b % a === 0 ? 1 : 2;\r\n var isEqual = a === b;\r\n var k = abk[2];\r\n var parra = [0, 0];\r\n var parrb = [0, 0];\r\n var i = 2;\r\n while(a !== 1) {\r\n parra[i] = 0;\r\n while(a % i === 0) {\r\n parra[i]++;\r\n a = div(a, i);\r\n }\r\n i++;\r\n }\r\n var i = 2;\r\n while(b !== 1) {\r\n parrb[i] = 0;\r\n while(b % i === 0) {\r\n parrb[i]++;\r\n b = div(b, i);\r\n }\r\n i++;\r\n }\r\n while (parra.length < parrb.length) {\r\n parra.push(0);\r\n }\r\n while (parrb.length < parra.length) {\r\n parrb.push(0);\r\n }\r\n var maxAns = 0;\r\n for (var i = 0; i < parrb.length; i++) {\r\n maxAns += parra[i] + parrb[i];\r\n }\r\n if (minAns > k || maxAns < k) {\r\n write('NO');\r\n return;\r\n }\r\n if (isEqual) {\r\n write((k & 1) ? 'NO' : 'YES');\r\n return;\r\n }\r\n write('YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nconst primes = new Set(getPrimes(10 ** 5));\r\nfunction solve(n, m, k) {\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n let a = 0,\r\n b = 0;\r\n for (let num of primes) {\r\n if (num > n && num > m) break;\r\n while (n % num === 0) {\r\n a++;\r\n n /= num;\r\n }\r\n while (m % num === 0) {\r\n b++;\r\n m /= num;\r\n }\r\n if (a + b >= k) return 'YES';\r\n }\r\n if (n > 1 && !primes.has(n)) a++;\r\n if (n > 1 && !primes.has(m)) b++;\r\n if (a + b >= k) return 'YES';\r\n return 'NO';\r\n}\r\nfunction getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n return primes;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst primes = new Set(getPrimes(10 ** 5));\r\nfunction solve(n, m, k) {\r\n if (k > 1000) return 'NO';\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n let a = 0,\r\n b = 0;\r\n for (let num of primes) {\r\n while (n % num === 0) {\r\n a++;\r\n n /= num;\r\n }\r\n while (m % num === 0) {\r\n b++;\r\n m /= num;\r\n }\r\n if (a + b >= k) return 'YES';\r\n }\r\n if (!primes.has(n)) a++;\r\n if (!primes.has(m)) b++;\r\n if (a + b >= k) return 'YES';\r\n return 'NO';\r\n}\r\nfunction getPrimes(n) {\r\n const nums = new Array(n + 1).fill(1);\r\n nums[0] = nums[1] = 0;\r\n const primes = [];\r\n for (let i = 2; i <= n; i++) {\r\n if (nums[i]) primes.push(i);\r\n for (let num of primes) {\r\n const j = num * i;\r\n if (j > n) break;\r\n nums[j] = 0;\r\n if (i % num === 0) break;\r\n }\r\n }\r\n return primes;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k) {\r\n if (n === m && k & 1) return 'NO';\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n const count = n => {\r\n if (n === 2) return 1;\r\n let res = 0;\r\n for (let i = 2; i <= n; i++) {\r\n while (n % i === 0) {\r\n res++;\r\n n /= i;\r\n }\r\n }\r\n return res;\r\n };\r\n let max = count(n) + count(m);\r\n if (k > max) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k) {\r\n if (n === m && k & 1) return 'NO';\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n const count = n => {\r\n if (n === 2) return 1;\r\n let res = 0;\r\n for (let i = 2; i <= n / i; i++) {\r\n while (n % i === 0) {\r\n res++;\r\n n /= i;\r\n }\r\n }\r\n return res;\r\n };\r\n let max = count(n) + count(m);\r\n if (k > max) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k) {\r\n if (k === 1) return (n % m === 0 || m % n === 0) && n !== m ? 'YES' : 'NO';\r\n const count = n => {\r\n if (n === 2) return 1;\r\n let res = 0;\r\n for (let i = 2; i <= n / i; i++) {\r\n while (n % i === 0) {\r\n res++;\r\n n /= i;\r\n }\r\n }\r\n return res;\r\n };\r\n let max = count(n) + count(m);\r\n return k <= max ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, k));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(Math.ceil(Math.sqrt(1e9)))\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n const g = gcd(a, b)\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n console.log(a, b, g, '-', n1, n2, n)\n\n const divided = a === g || b === g\n if (a === b) {\n const min = 0\n const max = 2 * n\n return k >= min && k <= max && k !== 1\n } else if (divided) {\n const min = 1\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n } else {\n const min = 2\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n }\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n if (x !== 1) c++ // the last non-divided big prime\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(Math.ceil(Math.sqrt(1e9)))\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n const g = gcd(a, b)\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n\n const divided = a === g || b === g\n if (a === b) {\n const min = 0\n const max = 2 * n\n return k >= min && k <= max && k !== 1\n } else if (divided) {\n const min = 1\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n } else {\n const min = 2\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n }\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n if (c !== 1) c++ // the last non-divided big prime\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(1e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n if (!flag[i]) continue\n for (let j = i * 2; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n const g = gcd(a, b)\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n\n const divided = a === g || b === g\n if (a === b) {\n const min = 0\n const max = 2 * n\n return k >= min && k <= max && k !== 1\n } else if (divided) {\n const min = 1\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n } else {\n const min = 2\n const max = n1 + n2 + 2 * n\n return k >= min && k <= max\n }\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(1e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n if (!flag[i]) continue\n for (let j = i * 2; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n const g = gcd(a, b)\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n\n const divided = a === g || b === g\n if (k <= n1 + n2) {\n if (divided) {\n // [1, n1 + n2]\n return k >= 1\n } else {\n // [2, n1 + n2]\n return k >= 2\n }\n }\n\n\n k -= (n1 + n2) // greedy\n if (k & 1) {\n const k2 = n1 + n2 - 1\n if (divided && k2 < 1 || k2 < 2) return false\n k++ \n }\n return !(k & 1) && k <= 2 * n\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n\nconst PRIMES = primes(1e7)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n if (!flag[i]) continue\n for (let j = i * 2; j <= n; j += i) {\n flag[j] = false\n }\n }\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nfunction solve([a, b, k]) {\n return isOK(a, b, k) ? 'YES' : 'NO'\n}\n\nfunction isOK(a, b, k) {\n if (a === b) {\n const n = getFactorCount(a)\n return !(k & 1) && n >= 2 * k\n }\n\n const g = gcd(a, b)\n if (g === 1) {\n if (a === 1 || b === 1) return k === 1\n return k === 2\n } else {\n const n1 = getFactorCount(a / g)\n const n2 = getFactorCount(b / g)\n const n = getFactorCount(g)\n if (a === g || b === g) {\n return k <= n1 + n2 + n\n }\n return k >= 2 && k <= n1 + n2 + n\n }\n}\nfunction getFactorCount(n) {\n if (n < 2) return 0\n\n let c = 0\n let x = n\n PRIMES.some(p => {\n while (!(x % p)) {\n c++\n x /= p\n }\n if (p >= x) return true\n })\n return c\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet a;\r\nlet b;\r\nlet k;\r\nconst MAX = 50000;\r\nlet primes = [];\r\nlet sieve = new Int32Array(MAX).fill(0);\r\nfunction precalc() {\r\n sieve[1] = 1;\r\n for (let i = 2; i < MAX; i++) {\r\n if (sieve[i] == 0) {\r\n sieve[i] = i;\r\n primes.push(i);\r\n for (let j = i; i * j < MAX; j++) {\r\n sieve[i * j] = i;\r\n }\r\n }\r\n }\r\n // console.log(primes);\r\n}\r\nfunction npf(x) {\r\n let rv = 0;\r\n for (let p of primes) {\r\n if (p > x) {\r\n break;\r\n }\r\n while ((x % p) == 0) {\r\n rv++;\r\n x /= p;\r\n }\r\n }\r\n if (x > 1) { // x was a large prime\r\n return 1;\r\n }\r\n return rv;\r\n}\r\nfunction gcd(a, b) {\r\n while (a > 0) {\r\n let c = a;\r\n a = b % a;\r\n b = c;\r\n }\r\n return b;\r\n}\r\nfunction solve() {\r\n // printf(\"npf(%d) %d\\n\", a, npf(a));\r\n // printf(\"npf(%d) %d\\n\", b, npf(b));\r\n let g = gcd(a, b);\r\n if (k == 1) {\r\n if (a == b) {\r\n return false;\r\n }\r\n return a == g || b == g;\r\n }\r\n let mx = npf(a) + npf(b);\r\n if (k > mx) {\r\n return false;\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n precalc();\r\n check(npf(1000000007) == 1);\r\n while (tc-- > 0) {\r\n a = nextInt();\r\n b = nextInt();\r\n k = nextInt();\r\n if (solve()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet a;\r\nlet b;\r\nlet k;\r\nconst MAX = 50000;\r\nlet primes = [];\r\nlet sieve = new Int32Array(MAX).fill(0);\r\nfunction precalc() {\r\n sieve[1] = 1;\r\n for (let i = 2; i < MAX; i++) {\r\n if (sieve[i] == 0) {\r\n sieve[i] = i;\r\n primes.push(i);\r\n for (let j = i; i * j < MAX; j++) {\r\n sieve[i * j] = i;\r\n }\r\n }\r\n }\r\n // console.log(primes);\r\n}\r\nfunction npf(x) {\r\n let rv = 0;\r\n for (let p of primes) {\r\n if (p > x) {\r\n break;\r\n }\r\n while ((x % p) == 0) {\r\n rv++;\r\n x /= p;\r\n }\r\n }\r\n if (x > 1) { // x was a large prime\r\n return 1;\r\n }\r\n return rv;\r\n}\r\nfunction gcd(a, b) {\r\n while (a > 0) {\r\n let c = a;\r\n a = b % a;\r\n b = c;\r\n }\r\n return b;\r\n}\r\nfunction solve() {\r\n // printf(\"npf(%d) %d\\n\", a, npf(a));\r\n // printf(\"npf(%d) %d\\n\", b, npf(b));\r\n let g = gcd(a, b);\r\n if (k == 1) {\r\n if (a == b) {\r\n return false;\r\n }\r\n return a == g || b == g;\r\n }\r\n let mx = npf(a) + npf(b);\r\n if (k > mx) {\r\n return false;\r\n }\r\n if ((k % 2) == 1) {\r\n a /= g;\r\n b /= g;\r\n return npf(a) != npf(b);\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n precalc();\r\n check(npf(1000000007) == 1);\r\n while (tc-- > 0) {\r\n a = nextInt();\r\n b = nextInt();\r\n k = nextInt();\r\n if (solve()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}], "src_uid": "b58a18119ac8375f9ad21a282292a76c"} {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i <= Number(q[0]); i++) {\n console.log(solve(q[i]))\n }\n}\nfunction solve(n) {\n const ang1 = Math.PI / n;\n const R = 0.5 / Math.sin(ang1 / 2);\n const shift = Math.PI / (2*n);\n let xl = Number.MAX_VALUE;\n let yb = Number.MAX_VALUE;\n let xr = Number.MIN_VALUE;\n let yt = Number.MIN_VALUE;\n for (let i = 0; i < n; i++) {\n const x = Math.cos(Math.PI / n * i + shift);\n const y = Math.sin(Math.PI / n * i + shift);\n xl = Math.min(xl, x);\n xr = Math.max(xr, x);\n yb = Math.min(yb, y);\n yt = Math.max(yt, y);\n }\n const side = Math.max(xr - xl, yt - yb) * R;\n return side.toPrecision(10);\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n", "positive_code": [{"source_code": "function Main() {\n var A = Number(readline());\n for(var i=0;i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const str = readLine();\n const patternEndsWith0 = [];\n const patternEndsWith1 = [];\n const result = [];\n\n for (let i = 0; i < len; i++) {\n const char = str[i];\n const patternCount = patternEndsWith0.length + patternEndsWith1.length + 1;\n if (char === \"0\") {\n if (patternEndsWith1.length > 0) {\n const pattern = patternEndsWith1.pop();\n patternEndsWith0.push(pattern);\n result.push(pattern);\n } else {\n patternEndsWith0.push(patternCount);\n result.push(patternCount);\n }\n } else {\n if (char === \"1\") {\n if (patternEndsWith0.length > 0) {\n const pattern = patternEndsWith0.pop();\n patternEndsWith1.push(pattern);\n result.push(pattern);\n } else {\n patternEndsWith1.push(patternCount);\n result.push(patternCount);\n }\n }\n }\n }\n console.log(patternEndsWith0.length + patternEndsWith1.length);\n console.log(result.join(\" \"));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const s = readLine()\n\n let c0 = []\n let c1 = []\n let next = 1\n let moves = []\n\n for (let i = 0, seq, from, to; i < n; i++) {\n if (s.charAt(i) === '0') {\n from = c1\n to = c0\n } else {\n from = c0\n to = c1\n }\n\n if (from.length) {\n seq = from.pop()\n } else {\n seq = next++\n }\n to.push(seq)\n\n moves.push(seq)\n }\n\n out += (c0.length + c1.length) + '\\n'\n out += moves.join(' ') + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n if(n === 0){\n console.log(0);\n console.log();\n continue;\n }\n let arr = readline().split('');\n let res = new Array(arr.length);\n let hMap = {'0': [], '1': []};\n let count = 0;\n for(let i = 0; i < arr.length; i++){\n if(arr[i] === '0'){\n if(hMap['0'].length > 0){\n let index = hMap['0'].pop();\n res[i] = index;\n hMap['1'].push(index);\n }\n else{\n hMap['1'].push(++count);\n res[i] = count;\n }\n }else{\n if(hMap['1'].length > 0){\n let index = hMap['1'].pop();\n res[i] = index;\n hMap['0'].push(index);\n }else{\n hMap['0'].push(++count);\n res[i] = count;\n }\n }\n }\n console.log(count);\n for(num of res)\n console.log(num);\n }\n}"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const str = readLine();\n const patternEndsWith0 = [];\n const patternEndsWith1 = [];\n const result = [];\n\n for (let i = 0; i < len; i++) {\n const char = str[i];\n const patternCount = patternEndsWith0.length + patternEndsWith1.length + 1;\n if (char === \"0\") {\n if (patternEndsWith1.length > 0) {\n const pattern = patternEndsWith1.pop();\n patternEndsWith0.push(pattern);\n result.push(pattern);\n } else {\n patternEndsWith0.push(patternCount);\n result.push(patternCount);\n }\n } else {\n if (char === \"1\") {\n if (patternEndsWith0.length > 0) {\n const pattern = patternEndsWith0.pop();\n patternEndsWith1.push(pattern);\n result.push(pattern);\n } else {\n patternEndsWith1.push(patternCount);\n result.push(patternCount);\n }\n }\n }\n }\n console.log(result.join(\" \"));\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(2 * t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextCharArray();\n var map = {\n 1 : list[0]\n };\n var out = new Array(N);\n out[0] = 1;\n var lastOne = new Set();\n var lastZero = new Set();\n if(list[0] == \"1\"){\n lastOne.add(1);\n }else{\n lastZero.add(1);\n }\n for(var j = 1; j < N; j++){\n var keys = Object.keys(map);\n var isOK = false;\n if(list[j] == \"1\"){\n if(lastZero.size != 0){\n var tmplist = Array.from(lastZero);\n lastZero.delete(tmplist[0]);\n lastOne.add(tmplist[0]);\n out[j] = tmplist[0];\n }else{\n lastOne.add(lastOne.size + 1);\n out[j] = lastOne.size;\n }\n }else{\n if(lastOne.size != 0){\n var tmplist = Array.from(lastOne);\n lastOne.delete(tmplist[0]);\n lastZero.add(tmplist[0]);\n out[j] = tmplist[0];\n }else{\n lastZero.add(lastZero.size + 1);\n out[j] = lastZero.size;\n }\n }\n }\n output[i * 2] = Object.keys(map).length;\n output[i * 2 + 1] = myconv(out, 8);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n if(n === 0){\n console.log(0);\n console.log([]);\n continue;\n }\n let arr = readline().split('');\n let res = new Array(arr.length);\n let hMap = {'0': [], '1': []};\n let count = 0;\n for(let i = 0; i < arr.length; i++){\n if(arr[i] === '0'){\n if(hMap['0'].length > 0){\n let index = hMap['0'].pop();\n res[i] = index;\n hMap['1'].push(index);\n }\n else{\n hMap['1'].push(++count);\n res[i] = count;\n }\n }else{\n if(hMap['1'].length > 0){\n let index = hMap['1'].pop();\n res[i] = index;\n hMap['0'].push(index);\n }else{\n hMap['0'].push(++count);\n res[i] = count;\n }\n }\n }\n console.log(count);\n console.log(res);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n let arr = readline().split('');\n let res = new Array(arr.length);\n let hMap = {'0': [], '1': []};\n let count = 0;\n for(let i = 0; i < arr.length; i++){\n if(arr[i] === '0'){\n if(hMap['0'].length > 0){\n let index = hMap['0'].pop();\n res[i] = index;\n hMap['1'].push(index);\n }\n else{\n hMap['1'].push(++count);\n res[i] = count;\n }\n }else{\n if(hMap['1'].length > 0){\n let index = hMap['1'].pop();\n res[i] = index;\n hMap['0'].push(index);\n }else{\n hMap['0'].push(++count);\n res[i] = count;\n }\n }\n }\n console.log(count);\n console.log(res);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n if(n === 0){\n console.log(0);\n console.log([]);\n continue;\n }\n let arr = readline().split('');\n let res = new Array(arr.length);\n let hMap = {'0': [], '1': []};\n let count = 0;\n for(let i = 0; i < arr.length; i++){\n if(arr[i] === '0'){\n if(hMap['0'].length > 0){\n let index = hMap['0'].pop();\n res[i] = index;\n hMap['1'].push(index);\n }\n else{\n hMap['1'].push(++count);\n res[i] = count;\n }\n }else{\n if(hMap['1'].length > 0){\n let index = hMap['1'].pop();\n res[i] = index;\n hMap['0'].push(index);\n }else{\n hMap['0'].push(++count);\n res[i] = count;\n }\n }\n }\n console.log(count);\n console.log(res);\n }\n}"}], "src_uid": "de57b6b1aa2b6ec4686d1348988c0c63"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let min = arr[0],\r\n ans = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] < 2 * min) continue;\r\n else {\r\n if(arr[i]%((2*min)-1)===0) ans+=arr[i]/((2*min)-1) - 1; \r\n else ans += Math.floor(arr[i] / ((2*min)-1));\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var b = a.sort(function(a, b){return a - b});\n var ans = 0;\n for(j = 1; j < n; j++){\n ans += Math.floor((a[j] - 1) / (b[0] * 2 - 1));\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nfunction solve(problem) {\r\n problem.sort((a, b) => b - a);\r\n\r\n const start = problem.pop();\r\n const divider = start * 2 - 1;\r\n\r\n let actions = 0;\r\n while (problem.length > 0) {\r\n const current = problem.pop();\r\n actions += Math.ceil(current / divider) - 1;\r\n }\r\n\r\n return actions;\r\n}\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 2) {\r\n const problem = data[i + 1].trim().split(' ').map(Number);\r\n\r\n console.log(solve(problem));\r\n }\r\n});\r\n"}, {"source_code": "\r\nvar readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n, arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, arr){\r\n arr.sort((a, b) => a - b);\r\n let cont = 0;\r\n const ref = (arr[0]*2)-1;\r\n for(let i = 1; i < n; i++){\r\n // cont += parseInt(arr[i] / ref);\r\n cont += Math.ceil(arr[i] / ref)-1;\r\n }\r\n\r\n return cont;\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n const min = Math.min(...a) * 2 - 1;\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n res += Math.ceil(a[i] / min) - 1;\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "var n = +readline();\r\nfor (var i = 0; i < n; i++) {\r\n var k = +readline();\r\n var arr = readline().split(' ').map(item => +item);\r\n var tab = arr[0] * 2 - 1;\r\n var count = 0;\r\n for (var j = 0; j < arr.length; j++) {\r\n count += Math.ceil(arr[j] / tab) - 1;\r\n }\r\n print(count);\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let min = arr[0],\r\n ans = 0;\r\n if (min === 1) {\r\n for (let i = 1; i < n; i++) ans += arr[i] - 1;\r\n console.log(ans);\r\n continue;\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] < 2 * min) continue;\r\n else {\r\n ans += Math.floor(arr[i] / ((2*min)-1));\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let min = arr[0],\r\n ans = 0;\r\n if (min === 1) {\r\n for (let i = 1; i < n; i++) ans += arr[i] - 1;\r\n console.log(ans);\r\n continue;\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] <= 2 * min) continue;\r\n else {\r\n ans += Math.ceil(arr[i] / (2 * min)) - 1;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let min = arr[0],\r\n ans = 0;\r\n if (min === 1) {\r\n for (let i = 1; i < n; i++) ans += arr[i] - 1;\r\n console.log(ans);\r\n continue;\r\n }\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] <= 2 * min) continue;\r\n else {\r\n ans += Math.floor(arr[i] / (2 * min));\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var b = a[0] * 2;\n var e = 0;\n for(j = 1; j < n; j++){\n if(b / 2 == 1){\n e += a[j] - 1;\n continue;\n }\n while(a[j] >= b){\n a[j] /= 2;\n e++;\n }\n }\n console.log(e);\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var b = a[0] * 2;\n var e = 0;\n for(j = 1; j < n; j++){\n if(b / 2 == 1){\n e += a[j] - 1;\n continue;\n }\n while(a[j] > b){\n a[j] /= 2;\n e++;\n }\n }\n console.log(e);\n }\n }\n});"}, {"source_code": "var n = +readline();\r\nfor (var i = 0; i < n; i++) {\r\n var k = +readline();\r\n var arr = readline().split(' ').map(item => +item);\r\n var tab = Math.min(...arr) * 2 - 1;\r\n var count = 0;\r\n for (var j = 0; j < arr.length; j++) {\r\n count += Math.floor(arr[j] / tab);\r\n }\r\n print(tab === 1 ? count - k : count);\r\n}\r\n"}], "src_uid": "128d9ad5e5dfe4943e16fcc6a103e51b"} {"source_code": "T = readline()\r\nwhile (T--) {\r\n x = readline().split('').map(x => +x)\r\n min = Math.min(...x)\r\n if(x.indexOf(min) === 0 && x.length === 2){\r\n x.shift()\r\n min = Math.min(...x)\r\n }\r\n print(min)\r\n}\r\n\r\n", "positive_code": [{"source_code": "const solve = rows => { \n for (let i = 0; i < rows.length; i++) { \n if (rows[i].length < 3) {\n console.log(rows[i][1]);\n } else { \n const nums = rows[i].split('');\n nums.sort((a, b) => a - b);\n console.log(nums[0]);\n }\n }\n}\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num) {\n dealInput();\n }\n }\n});\nconst dealInput = () => {\n solve(rows);\n rl.close();\n};\n\nrl.on('close', () => {\n process.exit(0);\n});\n\n \t\t\t \t \t \t \t\t \t\t\t \t \t"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n //n = parseInt(n);\r\n //var a = readline().split(' ').map((x) => parseInt(x));\r\n var as = ''+n;\r\n var len = as.length;\r\n var a = as.split('');\r\n var t = [...a]\r\n var ans = 0;\r\n t.sort();\r\n if(len > 2) ans = t[0]\r\n else if(t[0] != a[0]) ans = t[0]\r\n else ans = t[1];\r\n\r\n console.log(ans);\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n let ints = n.split('').map(Number);\r\n if (ints.length === 1) {\r\n output(ints[0]);\r\n continue;\r\n } else if (ints.length === 2) {\r\n output(ints[1]);\r\n continue;\r\n }\r\n ints.sort();\r\n output(ints[0]);\r\n }\r\n}\r\n"}, {"source_code": "const solve = n=>{\r\n if(n.length===2) return n[1];\r\n n.sort((a,b)=>a-b);\r\n return n[0];\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n console.log(solve(n));\r\n }\r\n}\r\nmain();\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\n\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n let input = line.split(\"\").map(Number);\n if (input.length == 2) {\n console.log(input[1]);\n } else {\n console.log(Math.min(...input));\n }\n }\n\n lines++;\n});\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let s = readline().split('').map(a=>+a);\n\n if (s.length === 2) {\n return s[1];\n }\n let min = s[0];\n\n for (let i = 1; i < s.length; i++) {\n min = Math.min(min, s[i]);\n }\n \n return min;\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n const a = n.toString(10).split('').map(Number);\r\n if (a.length === 2) return a[1];\r\n return a.sort((a, b) => a - b)[0];\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n res.push(solve(n));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let s = readline();\n LT({s});\n // PROCESSING:\n let ans = 0;\n if (s.length==2)\n return s[1]\n let min = s[0];\n for (let i=0; i a - b)[0];\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input.slice(1);\n\n for (const item of dataArr) {\n console.log(solve(item));\n }\n process.exit();\n});\n \t\t\t \t \t\t\t\t\t \t \t \t \t\t\t"}], "negative_code": [{"source_code": "const solve = num => { \n num.trim();\n if (num.length === 2) {\n console.log(Number(num[1]));\n } else { \n const arr = num.split('').map(item => parseInt(item, 10));\n arr.sort((a, b) => a - b);\n console.log(arr[0]);\n }\n}\n\nlet line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n const input = line.trim().split('\\n'); \n const n = parseInt(input[0]);\n for (let i = 1; i <= n; i++) { \n const arr = input[i];\n solve(arr);\n }\n});\n \t\t\t\t\t\t\t \t \t \t \t\t\t \t \t \t \t"}, {"source_code": "const solve = arr => { \n if (arr.length === 2) {\n console.log(arr[1]);\n } else { \n arr.sort((a, b) => a - b);\n console.log(arr[0]);\n }\n}\n\nlet line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n const input = line.trim().split('\\n'); \n const n = parseInt(input[0]);\n for (let i = 1; i <= n; i++) { \n const arr = input[i].split('').map(item => parseInt(item));\n solve(arr);\n }\n});\n\t \t \t \t \t\t\t\t\t \t \t \t\t\t\t \t\t\t \t"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n //n = parseInt(n);\r\n //var a = readline().split(' ').map((x) => parseInt(x));\r\n var as = ''+n;\r\n var len = as.length;\r\n var a = as.split('');\r\n var ans = 0;\r\n a.sort();\r\n if(len > 2) ans = a[0]\r\n else ans = a[1]\r\n\r\n console.log(ans);\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}], "src_uid": "adf024899fb2a684427463733358566a"} {"source_code": "var inp = readline();\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/"}, {"source_code": "var inp = readline();\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(pgs);"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(inp);"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + buff;\n }\n buff = \"\";\n }\n else\n {\n buff = buff + inp[i];\n }\n\n/*\n if( inp[i] == \",\") \n {\n pgs[ parseInt(buff) ] = 1;\n buff = \"\";\n\n if(i == 0 || res.length == 0) \n {\n res = res + buff;\n }\n elseif( i>0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(res);"}, {"source_code": "var inp = readline();\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i<=n;i++)\n{\n if( inp[i] == \",\") \n {\n pgs[ parseInt(buff) ] = 1;\n buff = \"\";\n }\n else\n {\n buff = buff + inp[i];\n }\n}\n\n//pgs[1] = 1;\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar flag = 0, k=0; // \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd res\nn = pgs.length;\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(res);"}, {"source_code": "var inp = readline();\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(res);"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(res);"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\n/*\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n}\n*/\n\nprint(res);"}, {"source_code": "var inp = readline();\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n */\n}\n\nprint(res);"}, {"source_code": "var inp = readline();\n\n// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\nvar pgs=[], i=0, n = inp.length, buff = \"\", res = \"\";\n\nfor(i=0;i0 && pgs[i-1]==1)\n {\n res == res + \"-\";\n }\n else\n {\n res = res + \",\" + buff;\n }\n }\n else\n {\n buff = buff + inp[i];\n }\n*/\n}\n\nprint(res);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], m = integers[1], k = integers[2];\n}\n\nmain();\n"}], "src_uid": "3969ba3e3eb55a896663d2c5a5bc4a84"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let [n,x,y] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr1 = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n let arr2 = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n let arr3 = [];\r\n for(let i=0;i Number(read());\r\n const n = rn(),\r\n x = rn(),\r\n y = rn(),\r\n a = read().split('').map(Number),\r\n b = read().split('').map(Number);\r\n let c = [];\r\n for (let i = 0; i < n; i++) if (a[i] !== b[i]) c.push(i);\r\n if (c.length & 1) return -1;\r\n if (c.length === 2 && c[0] + 1 === c[1]) {\r\n if (x > 2 * y) return 2 * y;\r\n return x;\r\n }\r\n return c.length / 2 * y;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n res[i] = s;\r\n }\r\n return res.join('\\n');\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "f3c097872643f6fce645c05824b574e5"} {"source_code": ";(function () {\n\tvar n = readline().split(' ');\n\tvar k = +n[1];\n\tn = +n[0];\n\n\tvar r = [];\n\tfor (var i = 0; i < n - k - 1; i++) {\n\t\tr.push(i + 1);\n\t}\n\n\tfor (var i = 0; i <= k; i++) {\n\t\tr.push(n - i);\n\t}\n\n\tprint(r.join(' '));\n\n}).call(this);", "positive_code": [{"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar k=+l[1];\nvar ans=[];\nvar x=n-k;\n\nfor(var i=1; i=x; i--){\n\tans.push(i);\n}\n\nprint(ans.join(' '));"}], "negative_code": [{"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar k=+l[1];\n\nvar i=1;\nvar j=n;\nvar ans=[];\n\nwhile(i<=j){\n\tif(k>0){\n\t\tk--;\n\t\tans.push(j--);\n\t\tans.push(i++);\n\t}else{\n\t\tans.push(i++);\n\t}\n}\nprint(ans.join(' '));"}], "src_uid": "75cc5b55c51217966cbdd639a68f0724"} {"source_code": "function solve() {\n function plus(a, b, c) {\n return ((a + b) % 1000000007 + c) % 1000000007;\n }\n var T = Number(read());\n var a = [1, 1, 3];\n var b = [0, 1, 1];\n var c = [0, 0, 1];\n var ans = [0, 0, 1];\n for (var i = 3; i < 2000000; i++) {\n a.push(plus(b[i - 1], b[i - 1], a[i - 1]));\n b.push(a[i - 1]);\n c.push(plus(b[i - 1], c[i - 1], 0));\n ans.push(plus(b[i - 1], ans[i - 3], 0));\n }\n \n for (var t = 0; t < T; t++) {\n var n = Number(read());\n write((ans[n - 1] * 4) % 1000000007);\n }\n}\n \n \nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}", "positive_code": [{"source_code": "const { KeyObject } = require(\"crypto\");\n\nvar data = '';\nvar M = 1000000007;\nprocess.stdin.setEncoding('utf8');\n\nvar res = [0, 0, 0, 4, 4];\nfor (var i = 5; i < 1 << 21; i++)\n{\n if (i % 3 == 0)\n res[i] = res[i - 2] + res[i - 3] * 4 + res[i - 4] * 4 + 4;\n else\n res[i] = res[i - 1] + res[i - 2] * 2;\n res[i] = res[i] % M;\n}\n\nprocess.stdin.on('data', (buffer) =>\n{\n data += buffer;\n});\n\nprocess.stdin.on('end', () =>\n{\n var i = 1;\n var x = data.split(/\\s+/).map(Number);\n for (var i = 1; i <= x[0]; i++)\n {\n console.log(res[x[i]]);\n }\n});"}, {"source_code": "function solve() {\n function plus(a, b, c) {\n return ((a + b) % 1000000007 + c) % 1000000007;\n }\n var T = Number(read());\n var a = [1, 1, 3];\n var b = [0, 1, 1];\n var c = [0, 0, 1];\n var ans = [0, 0, 1];\n for (var i = 3; i < 2000000; i++) {\n a.push(plus(b[i - 1], b[i - 1], a[i - 1]));\n b.push(a[i - 1]);\n c.push(plus(b[i - 1], c[i - 1], 0));\n ans.push(plus(b[i - 1], ans[i - 3], 0));\n }\n\n for (var t = 0; t < T; t++) {\n var n = Number(read());\n write((ans[n - 1] * 4) % 1000000007);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [], "src_uid": "43ace9254c5d879d11e3484eacb0bcc4"} {"source_code": "var lll = readline().split(' ')\nvar n = lll[0]\nvar P1 = lll[1]\nvar P2 = lll[2]\nvar P3 = lll[3]\nvar T1 = lll[4]\nvar T2 = lll[5]\n\nvar ss = []\n\nwhile (lll = readline()) ss.push(lll.split(' '))\n\nvar pows = 0\nvar pse\n\nfor (var i = 0; i < n; i++) {\n var s = ss[i]\n pows += (s[1] - s[0]) * P1\n if (pse) {\n var w = s[0] - pse\n pows += Math.min(w, T1) * P1\n w -= T1\n if (w > 0) {\n pows += Math.min(w, T2) * P2\n w -= T2\n if (w > 0) {\n pows += w * P3\n }\n }\n }\n pse = s[1]\n}\n\nprint(pows)", "positive_code": [{"source_code": "var readline = require('readline'),\n rl = readline.createInterface(process.stdin, process.stdout);\n\nvar arr = []\nvar intervals = [];\nvar counter = 0;\nvar n = 1000;\nvar ans = 0;\n\nvar P1;\nvar P2;\nvar P3;\nvar T1;\nvar T2;\nrl.on('line', function (line) {\n if (arr.length == 0) {\n arr = line.split(' ').map(item => { return parseInt(item) });\n n = arr[0];\n P1 = arr[1];\n P2 = arr[2];\n P3 = arr[3];\n T1 = arr[4];\n T2 = arr[5];\n /* console.log(n,P1,P2,P3,T1,T2);\n console.log(arr);\n console.log(\"line = \"+line);*/\n }\n else {\n\n if (++counter < n) {\n\n intervals.push(line.split(' ').map(item => { return parseInt(item) }));\n }\n else {\n intervals.push(line.split(' ').map(item => { return parseInt(item) }));\n\n /* console.log(\"intervals.length= \" + intervals.length)\n console.log(n,P1,P2,P3,T1,T2);\n console.log*/\n ans += (intervals[0][1] - intervals[0][0]) * P1;\n\n for (let i = 1; i < n; i++) {\n ans += (intervals[i][1] - intervals[i][0]) * P1;\n\n gap = intervals[i][0] - intervals[i - 1][1];\n if (gap >= T1) {\n ans += T1 * P1;\n gap -= T1;\n }\n else {\n ans += gap * P1;\n gap = 0;\n }\n\n\n if (gap >= T2) {\n ans += T2 * P2;\n gap -= T2;\n }\n else {\n ans += gap * P2;\n gap = 0;\n }\n ans += gap * P3;\n }\n console.log(ans);\n rl.close();\n }\n\n\n }\n\n});\n\n\n\n\n\n"}, {"source_code": "function solve(p_1, p_2, p_3, t_1, t_2, lrs) {\n const t = t_1 + t_2;\n let [p_l, p_r] = lrs.shift();\n let result = (p_r - p_l) * p_1;\n for (const [c_l, c_r] of lrs) {\n let d = c_l - p_r;\n if (d > t) {\n result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));\n } else if (d > t_1) {\n result = result + (p_1 * t_1) + (p_2 * (d - t_1)); \n } else {\n result = result + (p_1 * d);\n }\n result = result + ((c_r - c_l) * p_1);\n p_l = c_l;\n p_r = c_r;\n }\n return result;\n};\n\nfunction main(lines) {\n const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\\s+/).map(Number);\n const lrs = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n const lr = t.split(/\\s+/).map(Number);\n lrs.push(lr);\n }\n }\n const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding('utf-8');\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(p_1, p_2, p_3, t_1, t_2, lrs) {\n const t = t_1 + t_2;\n const p_lr = lrs.shift();\n let [p_l, p_r] = p_lr;\n let result = (p_r - p_l) * p_1;\n for (const [c_l, c_r] of lrs) {\n let d = c_l - p_r;\n if (d > t) {\n result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));\n } else if (d > t_1) {\n result = result + (p_1 * t_1) + (p_2 * (d - t_1)); \n } else {\n result = result + (p_1 * d);\n }\n result = result + ((c_r - c_l) * p_1);\n p_l = c_l;\n p_r = c_r;\n }\n return result;\n};\n\nfunction main(lines) {\n const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\\s+/).map(Number);\n const lrs = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n const lr = t.split(/\\s+/).map(Number);\n lrs.push(lr);\n }\n }\n const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding('utf-8');\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar array = [];\nvar n = -1;\nvar P1 = 0;\nvar P2 = 0;\nvar P3 = 0;\nvar T1 = 0;\nvar T2 = 0;\nvar answer = 0;\nvar temp = 1440;\n\nrl.on(\"line\", input => {\n if (n == -1) {\n array = input.split(\" \");\n n = parseInt(array[0]);\n P1 = parseInt(array[1]);\n P2 = parseInt(array[2]);\n P3 = parseInt(array[3]);\n T1 = parseInt(array[4]);\n T2 = parseInt(array[5]);\n } else if (n > 0) {\n array = input.split(\" \");\n var start = parseInt(array[0]);\n var end = parseInt(array[1]);\n\n answer += (end - start) * P1;\n\n var deference = start - temp > 0 ? start - temp : 0;\n if (T1 < deference) {\n answer += P1 * T1;\n if ((deference - T1) > T2) {\n answer += P2 * T2;\n if (deference - (T1 + T2) > 0) answer += P3 * (deference - (T1 + T2));\n }\n else answer+= (deference-T1)*P2;\n } else if (deference > 0) answer += P1 * deference;\n temp = end;\n n--;\n }\n}).on(\"close\", () => {\n console.log(answer);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar ans = 0,\n n, P1, P2, P3, T1, T2, indicator = 0,\n l1, r1, l2, r2, cont, gap;\n\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n cont = input.split(' ').map(item => parseInt(item));\n n = cont[0], P1 = cont[1], P2 = cont[2], P3 = cont[3], T1 = cont[4], T2 = cont[5];\n indicator++;\n } else if (indicator== 1) {\n cont = input.split(' ').map(item => parseInt(item));\n l1 = cont[0], r1 = cont[1];\n ans += (r1 - l1) * P1;\n indicator++;\n } else {\n cont = input.split(' ').map(item => parseInt(item));\n l2 = cont[0], r2 = cont[1];\n //oconsole.log(\"l1=%d r1=%d l2=%d r2=%d ans=%d\",l1,r1,l2,r2,ans);\n ans += (r2 - l2) * P1;\n gap = l2 - r1;\n if (gap > T1) {\n ans += T1 * P1;\n gap -= T1;\n } else {\n ans += gap * P1;\n gap = 0;\n }\n if (gap > T2) {\n ans += T2 * P2;\n gap -= T2;\n } else {\n ans += gap * P2;\n gap = 0;\n }\n ans += gap * P3;\n\n l1 = l2;\n r1 = r2;\n }\n\n}).on('close', () => {\n\n console.log(ans);\n rl.close();\n});"}, {"source_code": "var data = readline().split(' ').map(item => parseInt(item));\nvar n = data[0];\nvar p1 = data[1], p2 = data[2], p3 = data[3];\nvar t1 = data[4], t2 = data[5];\npower = 0;\ndata = [];\nfor(var i = 0; i < n; i++) {\n data.push(readline().split(' ').map(item => parseInt(item)));\n power += (data[i][1] - data[i][0]) * p1;\n}\nfor(var i = 0; i < n - 1; i++) {\n var time = data[i + 1][0] - data[i][1];\n var ans = Math.min(time, t1);\n power += ans * p1;\n time -= ans;\n if(time < 0) {\n continue;\n }\n ans = Math.min(time, t2);\n power += ans * p2;\n time -= ans;\n power += time * p3;\n}\nprint(power);"}], "negative_code": [{"source_code": "var lll = readline().split(' ')\nvar n = lll[0]\nvar P1 = lll[1]\nvar P2 = lll[2]\nvar P3 = lll[3]\nvar T1 = lll[4]\nvar T2 = lll[5]\n\nvar ss = []\n\nwhile (lll = readline()) ss.push(lll.split(' '))\n\nvar pows = 0\nvar pse\n\nfor (var i = 0; i < ss.length; i++) {\n var s = ss[i]\n pows += (s[1] - s[0]) * P1\n if (pse) {\n var w = s[0] - pse\n pows += Math.min(w, T1) * P1\n w -= T1\n if (w) {\n pows += Math.min(w, T2) * P2\n w -= T2\n if (w) {\n pows += w * P3\n }\n }\n }\n pse = s[1]\n}\n\nprint(pows)"}, {"source_code": "function solve(p_1, p_2, p_3, t_1, t_2, lrs) {\n const t = t_1 + t_2;\n const [p_l, p_r] = lrs.shift();\n let result = (p_r - p_l) * p_1;\n for (const [c_l, c_r] of lrs) {\n let d = c_l - p_r;\n if (d > t) {\n result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));\n } else if (d > t_1) {\n result = result + (p_1 * t_1) + (p_2 * (d - t_1)); \n } else {\n result = result + (p_1 * d);\n }\n result = result + ((c_r - c_l) * p_1);\n p_l = c_l;\n p_r = c_r;\n }\n return result;\n};\n\nfunction main(lines) {\n const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\\s+/).map(Number);\n const lrs = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n const lr = t.split(/\\s+/).map(Number);\n lrs.push(lr);\n }\n }\n const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding('utf-8');\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(p_1, p_2, p_3, t_1, t_2, lrs) {\n const t = t_1 + t_2;\n const p_lr = lrs.shift();\n const [p_l, p_r] = p_lr;\n let result = (p_r - p_l) * p_1;\n for (const [c_l, c_r] of lrs) {\n let d = c_l - p_r;\n if (d > t) {\n result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));\n } else if (d > t_1) {\n result = result + (p_1 * t_1) + (p_2 * (d - t_1)); \n } else {\n result = result + (p_1 * d);\n }\n result = result + ((c_r - c_l) * p_1);\n }\n return result;\n};\n\nfunction main(lines) {\n const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\\s+/).map(Number);\n const lrs = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n const lr = t.split(/\\s+/).map(Number);\n lrs.push(lr);\n }\n }\n const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding('utf-8');\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar array = [];\nvar n = -1;\nvar P1 = 0;\nvar P2 = 0;\nvar P3 = 0;\nvar T1 = 0;\nvar T2 = 0;\nvar answer = 0;\nvar temp = 1440;\n\nrl.on(\"line\", input => {\n if (n == -1) {\n array = input.split(\" \");\n n = parseInt(array[0]);\n P1 = parseInt(array[1]);\n P2 = parseInt(array[2]);\n P3 = parseInt(array[3]);\n T1 = parseInt(array[4]);\n T2 = parseInt(array[5]);\n } else if (n > 0) {\n array = input.split(\" \");\n var start = parseInt(array[0]);\n var end = parseInt(array[1]);\n\n answer += (end - start) * P1;\n\n var deference = start - temp > 0 ? start - temp : 0;\n if (T1 < deference) {\n answer += P1 * T1;\n if (deference - T1 > T2) {\n answer += P2 * T2;\n if (deference - (T1 + T2) > 0) answer += P3 * (deference - (T1 + T2));\n }\n } else if (deference > 0) answer += P1 * deference;\n temp = end;\n n--;\n }\n}).on(\"close\", () => {\n console.log(answer);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar ans = 0,\n n, P1, P2, P3, T1, T2, indicator = 0,\n l1, r1, l2, r2, cont, gap;\n\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n cont = input.split(' ').map(item => parseInt(item));\n n = cont[0], P1 = cont[1], P2 = cont[2], P3 = cont[3], T1 = cont[4], T2 = cont[5];\n indicator++;\n } else if (indicator == 1) {\n cont = input.split(' ').map(item => parseInt(item));\n l1 = cont[0], r1 = cont[1];\n ans += (r1 - l1) * P1;\n indicator++;\n } else {\n cont = input.split(' ').map(item => parseInt(item));\n l2 = cont[0], r2 = cont[1];\n ans += (r2 - l2) * P1;\n gap = l2 - r1;\n if (gap > T1) {\n ans += T1 * P1;\n gap -= T1;\n } else {\n ans += gap * P1;\n gap = 0;\n }\n if (gap > T2) {\n ans += T2 * P2;\n gap -= T2;\n } else {\n ans += gap * P2;\n ans = 0;\n }\n ans += gap * P3;\n\n l1 = l2;\n r1 = r2;\n }\n\n}).on('close', () => {\n\n console.log(ans);\n rl.close();\n});"}], "src_uid": "7ed9265b56ef6244f95a7a663f7860dd"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n let n = rn(),\r\n a = rns();\r\n const b = [...new Set(a)];\r\n a.sort((a, b) => a - b);\r\n b.sort((a, b) => a - b);\r\n if (b.length === 1) return 0;\r\n if (b.length === 2) return (b[1] - b[0]) * 2;\r\n n = b.length;\r\n let res = 0;\r\n for (let i = n - 1; i > 1; i--) {\r\n res = Math.max(res, b[i] - b[0] + b[i] - b[i - 1]);\r\n }\r\n for (let i = 0; i < n - 2; i++) {\r\n res = Math.max(res, b[n - 1] - b[i] + b[i + 1] - b[i]);\r\n }\r\n if (a[0] === a[1]) {\r\n res = Math.max(res, (b[1] - b[0]) * 2);\r\n }\r\n if (a[a.length - 1] === a[a.length - 2]) {\r\n res = Math.max(res, (b[n - 1] - b[n - 2]) * 2);\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).sort((a, b) => a - b);\r\n\r\n let result = 0\r\n for(let i = 0; i < A.length - 2; i++) {\r\n result = Math.max(result, A[A.length-1]-A[i]+A[i+1]-A[i])\r\n }\r\n for(let i = 1; i < A.length - 1; i++) {\r\n result = Math.max(result, A[i+1]-A[0]+A[i+1]-A[i])\r\n }\r\n console.log(result)\r\n\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n\r\n let result = 0\r\n for(let i = 0; i < A.length - 2; i++) {\r\n result = Math.max(result, A[A.length-1]-A[i]+A[i+1]-A[i])\r\n }\r\n for(let i = 1; i < A.length - 1; i++) {\r\n result = Math.max(result, A[i+1]-A[0]+A[i+1]-A[i])\r\n }\r\n console.log(result)\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n\r\n if (A.length == 1) {\r\n console.log(0)\r\n } else if (A.length == 2) {\r\n console.log(2 * (A[1] - A[0]))\r\n } else {\r\n const p1 = A[A.length - 1] + A[1] - 2 * A[0]\r\n const p2 = 2 * A[A.length - 1] - A[0] - A[A.length - 2]\r\n console.log(Math.max(p1, p2))\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n \r\n console.log(A)\r\n\r\n if (A.length == 1) {\r\n console.log(0)\r\n } else if (A.length == 2) {\r\n console.log(2 * (A[1] - A[0]))\r\n } else {\r\n const p1 = A[A.length - 1] + A[1] - 2 * A[0]\r\n const p2 = 2 * A[A.length - 1] - A[0] - A[A.length - 2]\r\n console.log(Math.max(p1, p2))\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n\r\n if (A.length == 1) {\r\n console.log(0)\r\n } else if (A.length == 2) {\r\n console.log(2 * (A[1] - A[0]))\r\n } else {\r\n const p1 = A[A.length - 1] + A[0] - 2 * A[1]\r\n const p2 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]\r\n console.log(Math.max(p1, p2))\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n\r\n if (A.length == 1) {\r\n console.log(0)\r\n } else if (A.length == 2) {\r\n console.log(2 * (A[1] - A[0]))\r\n } else {\r\n const p1 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]\r\n const p2 = 2 * A[0] - A[1] - A[A.length - 1]\r\n console.log(Math.max(p1, p2))\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {\r\n if (a.indexOf(b) < 0) a.push(b);\r\n return a;\r\n }, []).sort((a, b) => a - b);\r\n \r\n console.log(A)\r\n\r\n if (A.length == 1) {\r\n console.log(0)\r\n } else if (A.length == 2) {\r\n console.log(2 * (A[1] - A[0]))\r\n } else {\r\n const p1 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]\r\n const p2 = 2 * A[0] - A[1] - A[A.length - 1]\r\n console.log(Math.max(p1, p2))\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const a = lines[line++].split(' ').map(x => parseInt(x, 10))\r\n let max = -1, min = a[0], second = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (max <= a[i]) {\r\n second = max\r\n max = a[i]\r\n } else if (second <= a[i]) {\r\n second = a[i]\r\n }\r\n if (min > a[i])\r\n min = a[i]\r\n }\r\n\r\n console.log((max - second) + (max - min))\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const a = lines[line++].split(' ').map(x => parseInt(x, 10))\r\n let max = -1, min = a[0], second = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (max <= a[i]) {\r\n second = max\r\n max = a[i]\r\n }\r\n if (min > a[i])\r\n min = a[i]\r\n }\r\n\r\n console.log((max - second) + (max - min))\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n const a = lines[line++].split(' ').map(x => parseInt(x, 10))\r\n let max = a[0], min = a[0], second = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (max <= a[i]) {\r\n second = max\r\n max = a[i]\r\n }\r\n if (min > a[i])\r\n min = a[i]\r\n }\r\n\r\n console.log((max - second) + (max - min))\r\n\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => a - b);\r\n let res = a[n - 1] - a[0] + Math.max(Math.abs(a[0] - a[1]), Math.abs(a[n - 1] - a[n - 2]));\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "7421b2392cb40f1cf0b7fd93c287f1eb"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, x] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n x,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, x, a } = testCase;\n // console.log(n, x, a);\n\n let result = 0;\n\n let sum = 0;\n b = a\n .sort((c, d) => c - d)\n .map((v) => {\n sum += v;\n return sum;\n });\n // console.log(b);\n\n let day = 0;\n let couldBuyOnPreviousDay = n;\n while (x >= b[0] + day) {\n let couldBuyThisDay;\n for (\n couldBuyThisDay = couldBuyOnPreviousDay - 1;\n couldBuyThisDay >= 0;\n couldBuyThisDay--\n ) {\n if (x >= b[couldBuyThisDay] + (couldBuyThisDay + 1) * day) {\n break;\n }\n }\n const nbAdditionDays =\n couldBuyThisDay > -1\n ? Math.floor(\n (x - (b[couldBuyThisDay] + (couldBuyThisDay + 1) * day)) /\n (couldBuyThisDay + 1)\n )\n : 0;\n // console.log(\"day\", day);\n // console.log(\"nbAdditionDays\", nbAdditionDays);\n result += (couldBuyThisDay + 1) * (nbAdditionDays + 1);\n // console.log(\"result\", result);\n couldBuyOnPreviousDay = couldBuyThisDay + 1;\n day += nbAdditionDays + 1;\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, x, A)=>{\n A.sort((a, b)=>a-b);\n let l=0, sum = 0, ans = 0;\n for (; l0){\ncnt++\n sum += l;\n while (sum>x){ // optimize\n sum -= A[l-1]+add;\n l--;\n }\n if (l==0)\n break;\n // find max i, so sum+i*l=x\n let i = Math.floor((x-sum+l)/l);\n if (i>0){\n ans += l*i;\n add += i;\n sum += l*(i-1);\n }\n }\n //L({x,n,A, l, sum, ans, cnt})\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, x] = ra();\n let a = ra();\n L('Ans:')\n print(calc(n, x, a));\n }\n}\n \nE.calc = calc;"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let sum = arr.reduce((acc, cur) => acc + cur, 0);\r\n let j = n - 1,\r\n days = 0,\r\n pack = 0,\r\n len = 0,\r\n s1 = sum;\r\n while (j >= 0) {\r\n if (s1 <= k) {\r\n days = Math.floor((k - s1) / (j + 1)) + 1;\r\n pack += days * (j + 1);\r\n len += days;\r\n }\r\n sum -= arr[j--];\r\n s1 = sum + (j + 1) * len;\r\n }\r\n console.log(pack);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n arr.sort((a, b) => a - b)\n //\n let now = 0\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n const s = (arr[i])\n now += s\n //\n if (k < now) break\n\n const c = (i + 1)\n const d = binarySearch(1, 1e9, x => {\n return now + (x - 1) * c <= k\n })\n // console.log(i, d, now)\n ans += d\n }\n return ans\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n // const m = ((l + r) / 2n)\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, x, a)=>{\n a = a.sort((a0, a1) => a0 - a1);\n let count = 0;\n let sum = 0;\n\n for (let i = 0; i < n; i++) {\n if (a[i] > x) break;\n\n sum += a[i];\n\n if (sum > x) break;\n\n let num = i + 1;\n let localSum = 0;\n\n const check = (d) => {\n let seq = d - 1;\n // let seq = d % 2 === 0\n // ? Math.round((d / 2) * (d + 1))\n // : Math.round(((d + 1) / 2) * d);\n seq *= num;\n return seq + sum <= x;\n }\n\n \n let l = 1, r = x;\n while (l < r) {\n // console.log(`DEBUG l ${l} r ${r}`);\n let mid = l + Math.ceil((r - l) / 2);\n if (check(mid)) {\n l = mid;\n } else {\n r = mid - 1;\n }\n }\n // console.log(`DEBUG l ${l} r ${r}`);\n count += (l * num);\n count -= (l * (num - 1));\n }\n\n return count;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, x] = ra();\n let a = ra();\n console.log(`${calc(n, x, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, x, a) {\r\n a.sort((x, y) => x - y);\r\n const sum = [];\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n }\r\n let res = 0,\r\n day = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n let num = Math.max(Math.floor((x - sum[i]) / (i + 1)) + 1, 0);\r\n res += (i + 1) * (num - day);\r\n day = num;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, x] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, x, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, x, A)=>{\n A.sort((a, b)=>a-b);\n let l=0, sum = 0, ans = 0;\n for (; l0){\ncnt++\n sum += l;\n if (sum>x){ // optimize\n sum -= A[l-1]+add;\n l--;\n }\n if (l==0)\n break;\n // find max i, so sum+i*l=x\n let i = Math.floor((x-sum+l)/l);\n if (i>0){\n ans += l*i;\n add += i;\n sum += l*(i-1);\n }\n }\n //L({x,n,A, l, sum, ans, cnt})\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, x] = ra();\n let a = ra();\n L('Ans:')\n print(calc(n, x, a));\n }\n}\n \nE.calc = calc;"}], "src_uid": "b65767c1ebfe72e08f58a9f9254eaa7b"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst has = Array(n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst need = Math.max(0, (s[i]-1)-has[i]);\r\n\t\t\tans += need;\r\n\r\n\t\t\thas[i] = Math.max(s[i]-1, has[i]);\r\n\t\t\thas[i+1] += has[i]-(s[i]-1);\r\n\t\t\tfor (let j = i+2; j < Math.min(s[i]+i+1, n); j++) {\r\n\t\t\t\thas[j]++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst cur = Array(n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet need = Math.max(0, s[i]-1-cur[i]);\r\n\t\t\tans += need;\r\n\r\n\t\t\tfor (let j = i + 2; j <= Math.min(i + s[i], n-1); j++) {\r\n\t\t\t\tcur[j]++;\r\n\t\t\t}\r\n\r\n\t\t\tlet have = Math.max(s[i]-1, cur[i]);\r\n\t\t\tcur[i+1] += have - (s[i]-1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var ans = 0\r\n var count = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n var current = a[i] - 1\r\n\r\n if (a[i] > Math.max(n - i - 1, 1)) {\r\n var d = a[i] - Math.max(n - i - 1, 1)\r\n a[i] -= d\r\n }\r\n\r\n for (var j = a[i]; j >= 2; j--) {\r\n count[j + i]++\r\n }\r\n\r\n ans += Math.max(current - count[i], 0)\r\n if (i < (n - 1) && count[i] > current) {\r\n count[i + 1] += count[i] - current\r\n }\r\n // console.log(ans, current - count[i])\r\n // console.log(count)\r\n }\r\n console.log(ans)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var ans = 0\r\n var count = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n var current = a[i] - 1\r\n\r\n if (a[i] > Math.max(n - i - 1, 1)) {\r\n var d = a[i] - Math.max(n - i - 1, 1)\r\n a[i] -= d\r\n }\r\n\r\n for (var j = a[i]; j >= 2; j--) {\r\n count[j + i]++\r\n }\r\n\r\n ans += Math.max(current - count[i], 0)\r\n if (j < n - 1 && count[i] > a[i]) {\r\n count[i + 1] += count[i] - a[i]\r\n }\r\n // console.log(ans, current - count[i])\r\n // console.log(count)\r\n }\r\n console.log(ans)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var ans = 0\r\n var count = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n var current = a[i] - 1\r\n\r\n if (a[i] > Math.max(n - i - 1, 1)) {\r\n var d = a[i] - Math.max(n - i - 1, 1)\r\n a[i] -= d\r\n }\r\n\r\n for (var j = a[i]; j >= 2; j--) {\r\n count[j + i]++\r\n }\r\n\r\n ans += Math.max(current - count[i], 0)\r\n }\r\n console.log(ans)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0\r\n var temp = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n var current = temp[i]\r\n\r\n if (a[i] > Math.max(current, 1)) {\r\n count += a[i] - temp[i] - 1\r\n current = a[i] - temp[i] - 1\r\n }\r\n // console.log(current)\r\n\r\n for (let j = i + 2; j < n && j < i + a[i]+1; j++) {\r\n temp[j]++\r\n }\r\n // console.log(temp)\r\n // console.log(a)\r\n }\r\n console.log(count)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0\r\n var temp = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n var current = temp[i]\r\n\r\n if (a[i] > Math.max(current, 1)) {\r\n count += a[i] - temp[i] - 1\r\n current = a[i] - temp[i] - 1\r\n }\r\n // console.log(current)\r\n\r\n for (let j = i + 2; j < n && j < i + 2 + current; j++) {\r\n temp[j]++\r\n }\r\n // console.log(temp)\r\n // console.log(a)\r\n }\r\n console.log(count)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0\r\n var next = 0\r\n var nextI = 0\r\n\r\n while (exist) {\r\n exist = false\r\n for (let i = nextI; i < n; i++) {\r\n // console.log(a, count)\r\n // console.log(a)\r\n // console.log(i)\r\n if (a[i] + i < n && a[i] !== 1) {\r\n nextI = i\r\n exist = true\r\n // var j = i\r\n for (let jj = i + 1; jj < n; jj++) {\r\n var dd = Math.floor(Math.log2(jj - i))\r\n dd = Math.min(dd, a[i]-1)\r\n // console.log(jj, jj - i, dd)\r\n a[jj] = Math.max(1, a[jj] - dd)\r\n }\r\n count += a[i] - 1\r\n a[i] = 1\r\n break\r\n } else {\r\n if (a[i] !== 1 && (a[i] + i) >= n) {\r\n nextI = i\r\n\r\n // console.log(i, a[i], a[i] + i - n + 1)\r\n var dif = Math.min(a[i] + i - n + 1, a[i] - 1)\r\n a[i] = a[i] - dif\r\n count = count + dif\r\n exist = true\r\n break\r\n }\r\n }\r\n }\r\n }\r\n // console.log(a)\r\n\r\n // for (let i = 0; i < n; i++) {\r\n // if (a[i] > 1) count = count + BigInt(a[i]) - 1n\r\n // }\r\n console.log(count.toString())\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0\r\n var next = 0\r\n var nextI = 0\r\n\r\n while (exist) {\r\n exist = false\r\n for (let i = nextI; i < n; i++) {\r\n // console.log(a)\r\n // console.log(i)\r\n if (a[i] + i < n && a[i] !== 1) {\r\n nextI = i\r\n count++\r\n exist = true\r\n var j = i\r\n while (j < n) {\r\n next = a[j] + j\r\n if (a[j] === 1) a[j] = 1\r\n else a[j]--\r\n j = next\r\n }\r\n break\r\n } else {\r\n if (a[i] !== 1 && (a[i] + i) >= n) {\r\n nextI = i\r\n for (let jj = i + 1; jj < n; jj++) {\r\n var dd = Math.floor((jj - i) / 2)\r\n a[jj] = Math.max(1, a[jj] - dd)\r\n }\r\n var dif = Math.min(a[i] + i - n + 1, a[i] - 1)\r\n a[i] = a[i] - dif\r\n count = count + dif\r\n exist = true\r\n break\r\n }\r\n }\r\n }\r\n }\r\n // console.log(a)\r\n\r\n // for (let i = 0; i < n; i++) {\r\n // if (a[i] > 1) count = count + BigInt(a[i]) - 1n\r\n // }\r\n console.log(count.toString())\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0n\r\n var next = 0\r\n\r\n while (exist) {\r\n exist = false\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] + i < n && a[i] !== 1) {\r\n count++\r\n exist = true\r\n var j = i\r\n while (j < n) {\r\n next = a[j] + j\r\n if (a[j] === 1) a[j] = 1\r\n else a[j]--\r\n j = next\r\n }\r\n // console.log(a)\r\n break\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > 1) count = count + BigInt(a[i]) - 1n\r\n }\r\n console.log(count.toString())\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0n\r\n\r\n while (exist) {\r\n exist = false\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] + i < n && a[i] !== 1) {\r\n count++\r\n exist = true\r\n var j = i\r\n while (j < n) {\r\n\r\n if (a[j] === 1) a[j] = 1\r\n else a[j]--\r\n j = a[j] + j\r\n }\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > 1) count = count + BigInt(a[i]) - 1n\r\n }\r\n console.log(count.toString())\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var exist = true\r\n var count = 0\r\n\r\n while (exist) {\r\n exist = false\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] + i < n && a[i] !== 1) {\r\n count++\r\n exist = true\r\n var j = i\r\n while (j < n) {\r\n\r\n if (a[j] === 1) a[j] = 1\r\n else a[j]--\r\n j = a[j] + j\r\n }\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > 1) count += a[i] - 1\r\n }\r\n console.log(count)\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\n"}], "src_uid": "ac12faea4962613651afdc0b29537ef5"} {"source_code": "var n = +readline(), a = [];\nfor(i = 1; i <= n; i++){\n\ta[i] = i;\n}\nvar buf, x, y;\n\nif(n == 1){\n\twrite(n + \"\\n\");\n\twrite(1);\n}\nelse if(n == 2){\n\twrite(1 + \"\\n\");\n\twrite(1);\n}\nelse if(n == 3){\n\twrite(2 + \"\\n\");\n\twrite(1 + \" \" + 3);\n}\nelse{\n\tprint(n);\n\n\tif(n % 2 == 1){\n\t\ty = n;\n\t\tx = n-1;\n\t}\n\telse{\n\t\ty = n-1;\n\t\tx = n;\n\t}\n\n\tfor(; y > 0;){\n\t\twrite(y);\n\t\ty -= 2;\n\t\twrite(\" \");\n\t}\n\tfor(; x > 0;){\n\t\twrite(x);\n\t\tx -= 2;\n\t\twrite(\" \");\n\t}\n}", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar a = new Array(n)\nif(n <= 2)print(\"1\\n1\")\nelse if(n == 3)print(\"2\\n1 3\")\nelse {\n for (var i=0;i 0;){\n\t\twrite(y);\n\t\ty -= 2;\n\t\twrite(\" \");\n\t}\n\tfor(; x > 0;){\n\t\twrite(x);\n\t\tx -= 2;\n\t\twrite(\" \");\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar a = new Array(n)\nif(n == 1)print(\"1\\n1\")\nelse if(n == 2)print(\"0\")\nelse if(n == 3)print(\"2\\n1 3\")\nelse {\n for (var i=0;i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tlet s = rl();\r\n\r\n\tlet i = 1, p = 0;\r\n\tfor (; i < s.length; i++) {\r\n\t\tif (s[i] < s[p]) {\r\n\t\t\tp = 0;\r\n\t\t} else if (s[i] == s[p]) {\r\n\t\t\tp++;\r\n\t\t} else {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\ti = i - p;\r\n\r\n\ts = s.slice(0, i);\r\n\ts = s.repeat(Math.ceil(k/i));\r\n\tconst ans = s.slice(0, k);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = 1; //parseInt(lines[0]);\n var l = 0;\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].split(' ').map(Number)\n var str = lines[l++]\n console.log(solve(n, k, str));\n }\n});\n\nfunction solve(n, k, str) {\n if (n > k) return solve(k, k, str.slice(0, k))\n\n let min\n for (var i = 0; i < n; i++) {\n const after = fill(str.slice(0, n - i), k)\n if (!min || after < min) {\n min = after\n }\n // console.log(after, min)\n }\n return min\n\n // str = min\n // // console.log('1', str)\n // let end = -1\n // for (var i = str.length - 1; i >= 0; i--) {\n // if (str[i] === str[0]) {\n // // skip\n // } else {\n // end = i\n // break\n // }\n // }\n // if (end >= 0) {\n // str = str.slice(0, end + 1)\n // }\n // console.log('2', str)\n\n // return fill(str, k) \n}\n\nfunction fill(min, k) {\n let r = min\n while (r.length < k) {\n r += min\n }\n return r.slice(0, k)\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, k;\r\n [n,k] = ((await getLine())).split(' ').map(num => parseInt(num));\r\n let s = await getLine();\r\n const output = function(l) {\r\n for(let i = 0; i= s.length){\r\n output(i);\r\n return;\r\n }\r\n }\r\n output(s.length);\r\n\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "function solve() {\r\n var nk = readArray(Number);\r\n var n = nk[0];\r\n var k = nk[1];\r\n var str = read();\r\n var current = 1;\r\n var savepoint;\r\n var check;\r\n while(true) {\r\n if (current >= n) {\r\n break;\r\n }\r\n if (str[current] > str[0]) {\r\n str = str.substr(0, current);\r\n break;\r\n }\r\n if (str[current] < str[check]) {\r\n current++;\r\n continue;\r\n }\r\n savepoint = current;\r\n check = 0;\r\n while (current < 3 * n && str[current % n] === str[check]) {\r\n current++;\r\n check++;\r\n if (check >= savepoint) {\r\n check = 0;\r\n }\r\n }\r\n if (current !== 3 * n && str[current % n] > str[check]) {\r\n str = str.substr(0, savepoint);\r\n break;\r\n }\r\n }\r\n while(str.length < k) {\r\n str = str + str;\r\n }\r\n write(str.substr(0, k));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tlet s = rl();\r\n\r\n\tlet i = 1, p = 0;\r\n\tfor (; i < s.length; i++) {\r\n\t\tif (s[i] < s[p]) {\r\n\t\t\tp = 0;\r\n\t\t} else if (s[i] == s[p]) {\r\n\t\t\tp++;\r\n\t\t} else {\r\n\t\t\ti = i - p;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\ts = s.slice(0, i);\r\n\ts = s.repeat(Math.ceil(k/i));\r\n\tconst ans = s.slice(0, k);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tlet s = rl();\r\n\r\n\tlet i = 1, p = 0;\r\n\tfor (; i < s.length; i++) {\r\n\t\tif (s[i] < s[p]) {\r\n\t\t\tp = 0;\r\n\t\t} else if (s[i] == s[p]) {\r\n\t\t\tp++;\r\n\t\t} else {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\ts = s.slice(0, i);\r\n\ts = s.repeat(Math.ceil(k/i));\r\n\tconst ans = s.slice(0, k);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tlet s = rl();\r\n\r\n\tlet i = 0;\r\n\twhile (i < s.length && s[i] <= s[0]) i++;\r\n\r\n\ts = s.slice(0, i).repeat(Math.ceil(k/i));\r\n\tconst ans = s.slice(0, k);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, k;\r\n [n,k] = ((await getLine())).split(' ').map(num => parseInt(num));\r\n let s = await getLine();\r\n const output = function(l) {\r\n for(let i = 0; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, k;\r\n [n,k] = ((await getLine())).split(' ').map(num => parseInt(num));\r\n let s = await getLine();\r\n const output = function(l) {\r\n for(let i = 0; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let n, k;\r\n [n,k] = ((await getLine())).split(' ').map(num => parseInt(num));\r\n let s = await getLine();\r\n if (s.length >= k) {\r\n console.log(s.substr(0, k))\r\n return;\r\n } else {\r\n const output = function(l) {\r\n for(let i = 0; i= n) {\r\n break;\r\n }\r\n if (str[current] > str[0]) {\r\n str = str.substr(0, current);\r\n break;\r\n }\r\n if (str[current] < str[check]) {\r\n current++;\r\n continue;\r\n }\r\n savepoint = current;\r\n check = 0;\r\n while (current < n && str[current] === str[check]) {\r\n current++;\r\n check++;\r\n if (check >= savepoint) {\r\n check = 0;\r\n }\r\n }\r\n if (current !== n && str[current] > str[check]) {\r\n str = str.substr(0, savepoint);\r\n break;\r\n }\r\n }\r\n while(str.length < k) {\r\n str = str + str;\r\n }\r\n write(str.substr(0, k));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var matr = 'haha';\r\n\r\nfunction create(str) {\r\n var hahaIndexArr = [];\r\n for (var i = 0; i < str.length; i++) {\r\n var hasWrong = false;\r\n for (var j = 0; j < matr.length; j++) {\r\n if (str[i + j] !== matr[j]) {\r\n hasWrong = true;\r\n break;\r\n }\r\n }\r\n if (!hasWrong) {\r\n hahaIndexArr.push(i);\r\n }\r\n }\r\n if (hahaIndexArr.length === 0) {\r\n if (str.length < 8) {\r\n return [str, -1, str];\r\n }\r\n return [str.substr(0, 4), 0, str.substr(str.length - 4, 0)];\r\n }\r\n var preff = str.substr(0, Math.min(4, hahaIndexArr[0])) || 'ha';\r\n var suff = str.substr(Math.max(hahaIndexArr[hahaIndexArr.length - 1] + 4, str.length - 4)) || 'ha';\r\n return [preff, hahaIndexArr.length, suff];\r\n}\r\nfunction summ(a, b) {\r\n var createMiddle = create(a[2] + b[0]);\r\n if (a[1] === -1 && b[1] === -1) {\r\n return createMiddle;\r\n }\r\n var preff = a[1] === -1 ? createMiddle[0] : a[0];\r\n var suff = b[1] === -1 ? createMiddle[2] : b[2];\r\n var asum = a[1] === -1 ? 0 : a[1];\r\n var bsum = b[1] === -1 ? 0 : b[1];\r\n var midSum = createMiddle[1] === -1 ? 0 : createMiddle[1];\r\n return [preff, asum + bsum + midSum, suff];\r\n}\r\n\r\nfunction solve() {\r\n var nk = readArray(Number);\r\n var n = nk[0];\r\n var k = nk[1];\r\n var str = read();\r\n var current = 1;\r\n var savepoint;\r\n var check;\r\n while(true) {\r\n if (current >= n) {\r\n break;\r\n }\r\n if (str[current] > str[0]) {\r\n str = str.substr(0, current);\r\n break;\r\n }\r\n if (str[current] < str[check]) {\r\n current++;\r\n continue;\r\n }\r\n savepoint = current;\r\n check = 0;\r\n while (current < n && str[current] === str[check]) {\r\n current++;\r\n check++;\r\n if (check >= savepoint) {\r\n check = 0;\r\n }\r\n }\r\n if (current !== n && str[current] > str[check]) {\r\n str = str.substr(0, savepoint);\r\n break;\r\n }\r\n }\r\n while(str.length < k) {\r\n str = str + str;\r\n }\r\n write(str.substr(0, k));\r\n\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = 1; //parseInt(lines[0]);\n var l = 0;\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].split(' ').map(Number)\n var str = lines[l++]\n console.log(solve(n, k, str));\n }\n});\n\nfunction solve(n, k, str) {\n if (n > k) return solve(k, k, str.slice(0, k))\n\n let min\n for (var i = 0; i < n; i++) {\n const after = fill(str.slice(0, n - i), n)\n if (!min || after < min) {\n min = after\n }\n }\n\n return fill(min, k) \n}\n\nfunction fill(min, k) {\n let r = min\n while (r.length < k) {\n r += min\n }\n return r.slice(0, k)\n}\n"}], "src_uid": "87f64b4d5baca4b80162ae6075110b00"} {"source_code": "var main = function () {\n var n = parseInt(readline());\n var p = [];\n readline().split(/\\s+/).forEach(function (t) {\n p.push(parseFloat(t));\n });\n\n p.sort();\n\n if (p[p.length - 1] === 1) {\n print(1);\n return;\n }\n\n var addP = function (cur, pr, v) {\n return cur + v * pr / (1 - v)\n }\n\n var ans = 0;\n\n for (var pref = 0; pref <= p.length; ++pref) {\n for (var suff = 0; pref + suff <= p.length; suff++) {\n var cur = 0;\n var pr = 1;\n\n for (var i = 0; i < pref; ++i)\n pr *= 1 - p[i];\n for (var i = p.length - suff; i < p.length; ++i)\n pr *= 1 - p[i];\n \n for (var i = 0; i < pref; ++i)\n cur = addP(cur, pr, p[i]);\n for (var i = p.length - suff; i < p.length; ++i)\n cur = addP(cur, pr, p[i]);\n \n ans = Math.max(ans, cur);\n }\n }\n\n print(ans);\n};\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeFloats(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseFloat(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tprobs = tokenizeFloats(readline());\n\tprobs.sort(function (a, b) {\n\t\treturn a - b;\n\t});\n\tvar best = 0.0;\n\tfor (var i = n-1; i >= 0; --i) {\n\t\tvar total = 0.0;\n\t\tfor (var j = i; j < n; ++j) {\n\t\t\tvar p = 1.0;\n\t\t\tfor (var k = i; k < n; ++k) {\n\t\t\t\tif (k == j) {\n\t\t\t\t\tp *= probs[k];\n\t\t\t\t} else {\n\t\t\t\t\tp *= (1-probs[k]);\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotal += p;\n\t\t}\n\t\tbest = Math.max(best, total);\n\t}\n\tprint(best);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "var main = function () {\n var n = parseInt(readline());\n var p = [];\n readline().split(/\\s+/).forEach(function (t) {\n p.push(parseFloat(t));\n });\n\n p.sort();\n\n var addP = function (cur, pr, v) {\n return cur + v * pr / (1 - v)\n }\n\n var ans = 0;\n\n for (var pref = 0; pref <= p.length; ++pref) {\n for (var suff = 0; pref + suff <= p.length; suff++) {\n var cur = 0;\n var pr = 1;\n\n for (var i = 0; i < pref; ++i)\n pr *= 1 - p[i];\n for (var i = p.length - suff; i < p.length; ++i)\n pr *= 1 - p[i];\n \n for (var i = 0; i < pref; ++i)\n cur = addP(cur, pr, p[i]);\n for (var i = p.length - suff; i < p.length; ++i)\n cur = addP(cur, pr, p[i]);\n \n ans = Math.max(ans, cur);\n }\n }\n\n print(ans);\n};\n\nmain();\n"}], "src_uid": "b4ac594755951e84001dfd610d420eb5"} {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var arr;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n arr = readline().split(' ').map(x=>parseInt(x));\r\n var set = new Set();\r\n var index = 0;\r\n for (var i = n-1; i >= 0; i--) {\r\n if (set.has(arr[i])) {\r\n index = i+1;\r\n break;\r\n }\r\n set.add(arr[i]);\r\n }\r\n print(index);\r\n }", "positive_code": [{"source_code": "var t = readline().split(\" \").map((x) => parseInt(x));\r\nfor(var i = 0; i < t ; i++) {\r\n var n = readline().split(\" \").map((x) => parseInt(x));\r\n var nums = readline().split(\" \").map((x) => parseInt(x));\r\n var dict = {};\r\n var move = 0;\r\n\r\n nums.map((item, key) => {\r\n if(dict[item] !== undefined) {\r\n move = Math.max(dict[item] + 1, move);\r\n }\r\n dict[item] = key;\r\n })\r\n print(move);\r\n}\r\n"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var caseMap = new Map();\r\n var sequence = 0;\r\n for (var j = caseLength-1; j >= 0; j--)\r\n {\r\n if (caseMap.has(caseArray[j]))\r\n {\r\n break;\r\n }\r\n else\r\n {\r\n sequence++;\r\n caseMap.set(caseArray[j], 1);\r\n }\r\n }\r\n print(caseLength-sequence);\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i=0;iparseInt(x));\r\n var map={};\r\n var ans=0;\r\n for(var j=arr.length;j>=0;j--){\r\n if(map[arr[j]]){\r\n ans=j+1;\r\n break;\r\n }\r\n else{\r\n map[arr[j]]=1;\r\n }\r\n }\r\n print(ans);\r\n}"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var t1 = +readline();\r\n var list = readline().split(' ').map((t) => +t);\r\n print(removePrefix(list));\r\n \r\n}\r\n \r\nfunction removePrefix(arr){\r\n\r\n var set = new Set();\r\n for(var i = arr.length; i>=0; i--){\r\n if (set.has(arr[i])){\r\n return i + 1\r\n }\r\n set.add(arr[i])\r\n }\r\n \r\n return 0;\r\n \r\n\r\n}"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = readline();\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const a = readline().split(\" \").map(Number);\r\n var A = {};\r\n var w = false;\r\n for (let j = a.length - 1; j >= 0; j--) {\r\n if (!A[a[j]]) {\r\n A[a[j]] = true;\r\n } else {\r\n console.log(j + 1);\r\n w = true;\r\n break;\r\n }\r\n }\r\n if (!w) {\r\n console.log(0);\r\n }\r\n }\r\n}"}, {"source_code": "function solve() {\n const n = Number(cl());\n const arr = cl().split(' ').map((item) => Number(item));\n\n const set = new Set();\n for (let i = n - 1; i >= 0; i--) {\n if (set.has(arr[i])) {\n return co(i + 1);\n }\n set.add(arr[i]);\n }\n co(0);\n}\n\nfunction Solution() {\n let n = Number(cl());\n while (n--) solve();\n}\n\nlet i = 0;\nconst lines = []\n\nfunction cl() { return lines[i++] }\nfunction co(str) { console.log(str)}\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', (input) => lines.push(input));\nrl.on('close', Solution);"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main(); \r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction output(x) {\r\n if (typeof x !== 'string') \r\n {\r\n x = x.toString();\r\n }\r\n console.log(x);\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++)\r\n {\r\n const n = Number(readline());\r\n const arr = readline().split(' ').map(Number);\r\n const hash = {};\r\n for (let i = arr.length - 1; i >= 0; i--) \r\n {\r\n if (hash[arr[i]]) \r\n {\r\n output(i + 1);\r\n break;\r\n } \r\n else \r\n {\r\n hash[arr[i]] = true;\r\n }\r\n if (i === 0) \r\n {\r\n output(0);\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const arr= readLine().split(' ').map(p => +p);\r\n let result = myFunc(n, arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, arr){\r\n let map = [];\r\n let resp = 0;\r\n\r\n for(let i = n-1; i >=0; i--){\r\n if(map[arr[i]] != undefined){\r\n break;\r\n }\r\n else{\r\n map[arr[i]] = 1;\r\n resp++;\r\n }\r\n }\r\n\r\n return n-resp;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() { return inputs.next().value.trim(); };\r\n\r\nasync function solve() {\r\n let length = parseInt(await read())\r\n let value = (await read()).split(' ').map(Number)\r\n let counter = 0\r\n let map = {}\r\n for (let i = value.length - 1; i >= 0; i--) {\r\n const element = value[i];\r\n if (element in map) {\r\n break\r\n } else {\r\n map[element] = true\r\n counter++\r\n }\r\n }\r\n return length - counter\r\n}\r\n\r\nasync function main() {\r\n let tasks_amount = parseInt(await read())\r\n for (let i = 0; i < tasks_amount; i++) {\r\n let result = await solve()\r\n console.log(result)\r\n }\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n await main();\r\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = Number(readline());\r\n const arr = readline().split(' ').map(Number);\r\n const hash = {};\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n if (hash[arr[i]]) {\r\n output(i + 1);\r\n break;\r\n } else {\r\n hash[arr[i]] = true;\r\n }\r\n if (i === 0) {\r\n output(0);\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const set = new Set();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (set.has(a[i])) return i + 1;\r\n set.add(a[i]);\r\n }\r\n return 0;\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = await rns();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const m = {}\n for (let i = arr.length - 1; i >= 0; i--) {\n const x = arr[i]\n if (m[x]) {\n return i + 1\n }\n m[x] = 1\n }\n return 0\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar set = new Set();\r\n\t\tvar output = N;\r\n\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\tif(!set.has(list[i])){\r\n\t\t\t\tset.add(list[i]);\r\n\t\t\t\toutput--;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "var t = readline().split(\" \").map((x) => parseInt(x));\r\nfor(var i = 0; i < t ; i++) {\r\n var n = readline().split(\" \").map((x) => parseInt(x));\r\n var nums = readline().split(\" \").map((x) => parseInt(x));\r\n var dict = {};\r\n var move = 0;\r\n\r\n nums.map((item, key) => {\r\n if(dict[item] !== undefined) {\r\n move = dict[item] + 1;\r\n }\r\n dict[item] = key;\r\n })\r\n print(move);\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = readline();\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const a = readline().split(\" \").map(Number);\r\n var A = {};\r\n for (let j = a.length - 1; j >= 0; j--) {\r\n if (!A[a[j]]) {\r\n A[a[j]] = true;\r\n } else {\r\n d = a.length - Object.keys(A).length;\r\n break;\r\n }\r\n if (n === 1) {\r\n d = 0;\r\n }\r\n }\r\n console.log(d)\r\n }\r\n\r\n}"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = readline();\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const a = readline().split(\" \").map(Number);\r\n var A = {};\r\n for (let j = a.length - 1; j >= 0; j--) {\r\n if (A[a[j]]) {\r\n d = j + 1;\r\n break;\r\n } else {\r\n A[a[j]] = true;\r\n }\r\n if (n === 1) {\r\n d = 0;\r\n }\r\n }\r\n console.log(d)\r\n }\r\n\r\n}"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n/**\r\n * \u041f\u043b\u0430\u043d \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438:\r\n * - \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044c\u0435\u043a\u0442 \u0410\r\n * - \u0438\u0434\u0435\u043c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0441 \u043a\u043e\u043d\u0446\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\r\n * - \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0435\u0441\u0442\u044c \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0410\r\n * - \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u0442, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0410 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \r\n * - \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0435\u0441\u0442\u044c , \u0442\u043e \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u0438\u043d\u0443 \u0432\u0441\u0435\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043c\u0438\u043d\u0443\u0441 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432\r\n * - \u0435\u0441\u043b\u0438 \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u0448\u043b\u0438, \u0442\u043e \u043e\u0442\u0432\u0435\u0442 0\r\n */\r\n\r\nsolve = () => {\r\n const t = readline();\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const a = readline().split(\" \").map(Number);\r\n var A = {};\r\n for (let j = a.length - 1; j >= 0; j--) {\r\n if (A[a[j]]) {\r\n d = i + 1;\r\n break;\r\n } else {\r\n A[a[j]] = true;\r\n }\r\n if (j === 1) {\r\n d = 0;\r\n }\r\n }\r\n console.log(d)\r\n }\r\n\r\n}\r\n\r\n"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\nsolve = () => {\r\n const t = readline();\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const a = readline().split(\" \").map(Number);\r\n var A = {};\r\n for (let j = a.length - 1; j >= 0; j--) {\r\n if (A[a[j]]) {\r\n d = i + 1;\r\n break;\r\n } else {\r\n A[a[j]] = true;\r\n }\r\n if (j === 1) {\r\n d = 0;\r\n }\r\n }\r\n console.log(d)\r\n }\r\n\r\n}"}], "src_uid": "4aaa33f77fe1c89ae477bd5cfa04f0bf"} {"source_code": "function solve(a,b) {\n var p = a*b;\n var h = Math.floor(p/2);\n return (p % 2 == 0) ? h : ++h;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var a = arr[0];\n var b = arr[1];\n print(solve(a,b));\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString.push(inputStdin);\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.join('').trim().split('\\n').map(string => string.trim());\n \n //withTiming(main);\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst withTiming = callback => {\n const start = new Date();\n callback();\n console.log(`Took ${new Date() - start} ms`);\n}\n\nfunction main() {\n const n = Math.floor(readline());\n const inputs = [];\n\n for (let i = 0; i < n; i++) {\n const [a, b] = readline().split(' ').map(a => parseInt(a));\n \n let sum = Math.floor(a / 2) * Math.floor(b / 2) * 2;\n sum += (a % 2) * Math.ceil(b / 2) + (b % 2) * Math.ceil(a / 2) - ((a % 2) && (b % 2));\n console.log(sum);\n }\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (Number.isInteger(a) && Number.isInteger(b)) {\n console.log(Math.ceil(a*b/2));\n }\n\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n const max = Math.max(m, n)\n const min = Math.min(m, n)\n\n if (max > 2) {\n if (max % 2 === 0) {\n console.log(max/2 *min)\n } else {\n console.log( (max-1)/2*min + Math.ceil(min/2))\n }\n } else {\n console.log(Math.ceil(m*n/2))\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n function minNumberOfLanterns(row, column) {\n return Math.ceil((row * column / 2));\n }\n\n for (var i = 0; i < testCases; i++) {\n var numbers = readLine()\n .split(\" \")\n .map(num => parseInt(num));\n\n var row = numbers[0];\n var column = numbers[1];\n\n console.log(minNumberOfLanterns(row, column));\n }\n}\n"}, {"source_code": "let outFd = null;\nlet fs = null;\nlet promisify = null;\n\nfunction stdinStdout() {\n process.stdin.resume();\n process.stdin.setEncoding('utf8');\n\n let lingeringLine = \"\";\n process.stdin.on('data', function(chunk) {\n lines = chunk.split(\"\\n\");\n \n lines[0] = lingeringLine + lines[0];\n lingeringLine = lines.pop();\n \n lines.map(s => s.trim()).forEach(line => {\n processLine(line.trim());\n });\n });\n \n process.stdin.on('end', function() {\n processLine(lingeringLine.trim());\n });\n}\n\nfunction inOutFiles(fin, fout) {\n fs = require('fs');\n outFd = fs.openSync(fout, 'w');\n data = fs.readFileSync(fin);\n data.toString().split('\\n').map(line => line.trim()).forEach(processLine);\n fs.closeSync(outFd);\n}\n\nfunction output(s) {\n if(outFd) {\n fs.writeSync(outFd, s.toString() + '\\n');\n } else {\n console.log(s);\n }\n}\n\nlet t = -1;\nlet n;\nlet m;\n\nfunction processLine(line) {\n if(t == -1) {\n t = parseInt(line);\n } else if(t > 0) {\n t--;\n [n, m] = line.split(/\\s+/).slice(0, 2).map(s => parseInt(s));\n if(n < m) {\n [n, m] = [m, n];\n }\n solve();\n }\n}\n\nfunction solve() {\n output((n - n % 2) / 2 * m + (n % 2) * ((m - m % 2) / 2 + m % 2));\n}\n\nstdinStdout();\n// inOutFiles('amusing.in', 'amusing.out');\n"}, {"source_code": "function lamps(n, m) {\n if (m % 2 != 0) {\n if (n % 2 == 0) {\n return ((Math.floor(n/2) * m));\n }\n else {\n return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);\n }\n }\n else {\n return (Math.floor(m/2) * n);\n }\n}\n\nfunction processData(input) {\n const inputArr = input.split(\"\\n\");\n const n = inputArr[0];\n for (let i = 1; i <= parseInt(n); i ++) {\n const n_m = inputArr[i].split(' ');\n console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\toutput[i] = Math.ceil(N * M / 2);\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift();\n for (let i = 0; i < testCases; i += 1) {\n let park = data[i].split(' ');\n let lantern = 0;\n const row = +park[0];\n const column = +park[1];\n if (row % 2 === 0) lantern = row / 2 * column;\n else {\n lantern = (row - 1) / 2 * column;\n lantern += Math.ceil(column / 2);\n }\n console.log(lantern);\n }\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n console.log(Math.ceil(a*b/2));\n\n c++;\n});\n"}, {"source_code": "function lamps(n, m) {\n if (m % 2 != 0) {\n if (n % 2 == 0) {\n return ((Math.floor(m/2) * n));\n }\n else {\n return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);\n }\n }\n else {\n return (Math.floor(m/2) * n);\n }\n}\n\nfunction processData(input) {\n const inputArr = input.split(\"\\n\");\n const n = inputArr[0];\n for (let i = 1; i <= parseInt(n); i ++) {\n const n_m = inputArr[i].split(' ');\n console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "function lamps(n, m) {\n if (m % 2 != 0) {\n if (n % 2 == 0) {\n return ((Math.floor(m/2) * n) + Math.floor(n / 2));\n }\n else {\n return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);\n }\n }\n else {\n let temp = n;\n n = m; \n m = temp;\n\n if (n % 2 == 0) {\n return ((Math.floor(m/2) * n));\n }\n else {\n return ((Math.floor(m/2) * n));\n }\n }\n}\n\nfunction processData(input) {\n const inputArr = input.split(\"\\n\");\n const n = inputArr[0];\n for (let i = 1; i <= parseInt(n); i ++) {\n const n_m = inputArr[i].split(' ');\n console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}], "src_uid": "19df5f3b8b31b763162c5331c1499529"} {"source_code": "function toi(x){return parseInt(x);}\nvar n=+readline();\nvar v=[];\nvar d=[];\nvar p=[];\nvar res=[];\nfor(var i=0;i=0){\n\tres.push(i+1);\n\tvar tv=v[i];\n\tvar td=0;\n\tfor(var j=i+1;j=0){\n\t\tif(tv>0){\n\t\t p[j]=Math.max(p[j]-tv,-1);\n\t\t tv-=1\n\t\t if(p[j]<0){\n\t\t\ttd+=d[j];\n\t\t }else{\n\t\t\tp[j]=Math.max(p[j]-td,-1);\n\t\t\tif(p[j] < 0){\n\t\t\t td+=d[j];\n\t\t\t}\n\t\t }\n\t\t}else{\n\t\t p[j]=Math.max(p[j]-td,-1);\n\t\t if(p[j] < 0){\n\t\t\ttd+=d[j];\n\t\t }\n\t\t}\n\t }\n\t}\n }\n}\nprint(res.length);\nprint(res.join(\" \"));\n\t\n\t\t \n", "positive_code": [{"source_code": "n = +readline();\nv = [], d = [], p = [];\nline = [];\nfor (var i = 0; i < n; i++) {\n\tinput = readline().split(\" \").map(Number);\n\tv[i] = input[0];\n\td[i] = input[1];\n\tp[i] = input[2];\n\tline.push({v:v[i],d:d[i],p:p[i],i:i+1});\n}\n\nanswer = [];\nwhile (line.length > 0) {\n\t//write(line + \"\\n\");\n\n\tvar patient = line[0];\n\t//write(patient.v + \"\\n\");\n\tanswer.push(patient.i);\n\tline.splice(0,1);\n\n\t//\n\tvar cry = -1;\n\tfor (var i = 0; i < line.length && i < patient.v; i++) {\n\t\tline[i].p -= patient.v-i;\n\t\tif (cry == -1 && line[i].p < 0) \n\t\t\tcry = i;\n\t}\n\n\t//for (var i = 0; i < line.length; i++) write(line[i].p + \" \");\n\n\twhile (cry >= 0) {\n\t\tvar j = cry;\n\t\tcry = -1;\n\t\tfor (var i = j; i < line.length; i++) {\n\t\t\tline[i].p -= line[j].d;\n\t\t\tif (cry == -1 && i > j && line[i].p < 0) {\n\t\t\t\tcry = i;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = line.length-1; i >= 0; --i) {\n\t\tif (line[i].p < 0) {\n\t\t\tline.splice(i,1);\n\t\t}\n\t}\n\t\n}\nwrite(answer.length + \"\\n\");\nfor (var i = 0; i < answer.length; i++) {\n\twrite(answer[i] + \" \");\n}\n\n"}], "negative_code": [], "src_uid": "8cf8590d1f3668b768702c7eb0ee8249"} {"source_code": "var str = readline().split('').sort();\nvar sum = 0;\nvar num = 1;\n\nfor(var i = 0; i {\n c += ls[l] * ls[l]\n})\n\nprint(c)"}, {"source_code": "function result(str) {\n var ret = 0;\n var values = {};\n for (var i=0;i secondElevatorDestination)\r\n {\r\n secondElevatorTime = secondElevator - 1;\r\n }\r\n else\r\n {\r\n secondElevatorTime = ((secondElevatorDestination - secondElevator) + (secondElevatorDestination - 1))\r\n }\r\n var result = 0;\r\n if (firstElevatorTime > secondElevatorTime)\r\n {\r\n result = 2;\r\n }\r\n else if (firstElevatorTime < secondElevatorTime)\r\n {\r\n result = 1;\r\n }\r\n else \r\n {\r\n result = 3;\r\n }\r\n print(result);\r\n}", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var t = readline();\r\n for (var i = 0; i < t; i++) {\r\n var [a, b, c] = readline().trim().split(' ').map(Number);\r\n if ((a - 1) == ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('3\\n');\r\n }\r\n if ((a - 1) > ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('2\\n')\r\n }\r\n if ((a - 1) < ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('1\\n')\r\n }\r\n }\r\n}\r\n// https://codeforces.com/contest/1729/problem/B\r\n // function main() {\r\n // let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\r\n // let n = readline();\r\n // for (let k = 0; k < n; k++) {\r\n // var o = readline();\r\n // var splittedSTR = readline().trim().split('');\r\n // var output = [];\r\n // for (var i = 0; i < o; i++) {\r\n // if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n // splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n // splittedSTR.splice(i + 1, 1)\r\n // splittedSTR.splice(i - 1, 1)\r\n // }\r\n // if (o - i == 1) {\r\n // for (var j = 0; j < splittedSTR.length; j++) {\r\n // output.push(Alpha[splittedSTR[j] - 1])\r\n // if (output.length == splittedSTR.length) {\r\n // console.log(output.join(''));\r\n // }\r\n // }\r\n // }\r\n // }\r\n // }\r\n // }\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [e1, e2, f] = d.split(\" \").map(Number);\n const e1d = Math.abs(e1 - 1);\n const e2d = Math.abs(f - e2) + Math.abs(f - 1);\n\n if (e1d < e2d) {\n console.log(1);\n } else if (e2d < e1d) {\n console.log(2);\n } else {\n console.log(3);\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [a, b, c] = nl.nums();\n\t\tlet x = 0;\n\t\tif (b > c) {\n\t\t\tx = b;\n\t\t} else {\n\t\t\tx = c + c - b;\n\t\t}\n\t\tif (a < x) {\n\t\t\tans.push(1);\n\t\t} else if (a > x) {\n\t\t\tans.push(2);\n\t\t} else {\n\t\t\tans.push(3);\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction getResult(inputs) {\r\n let a = inputs[0]\r\n let b = inputs[1]\r\n let c = inputs[2]\r\n\r\n if (a == 1 && b != 1) return 1\r\n if (a == b && c < b) return 3\r\n\r\n let opt1 = a - 1\r\n let opt2 = 0\r\n\r\n if (b >= c) {\r\n opt2 = b - 1\r\n } else if (b < c) {\r\n opt2 = c - b\r\n opt2 += c - 1\r\n }\r\n\r\n if (opt1 < opt2) return 1\r\n if (opt1 > opt2) return 2\r\n if (opt1 == opt2) return 3\r\n}\r\n\r\nfunction main() {\r\n let testCases = parseInt(readline())\r\n while (testCases--) {\r\n let inputs = readline()\r\n inputs = inputs.split(' ').map(Number)\r\n console.log(getResult(inputs))\r\n }\r\n}\r\n//*/\r\n// console.clear()\r\n// let inputs = ''\r\n// inputs = '1 2 3'\r\n// inputs = inputs.split(' ').map(Number)\r\n// console.log( getResult(inputs) )\r\n// inputs = '3 1 2'\r\n// inputs = inputs.split(' ').map(Number)\r\n// console.log( getResult(inputs) )\r\n// inputs = '3 2 1'\r\n// inputs = inputs.split(' ').map(Number)\r\n// console.log( getResult(inputs) )\r\n// process.exit(1)"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [a, b, c] = rns();\r\n const d = Math.abs(b - c) + c;\r\n if (a > d) return 2;else if (a < d) return 1;\r\n return 3;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n const t1 = a - 1\n const t2 = c < b ? b - 1 : c - b + c - 1\n if (t1 < t2) return 1\n if (t1 > t2) return 2\n return 3\n}\n"}, {"source_code": "function twoElevator (lift1, from , to) {\r\n if (lift1 == 1) return 1\r\n var result1 = lift1 - 1\r\n var result2 = 0\r\n\r\n if (from > to) {\r\n result2 = from - to + to - 1\r\n } else { //\r\n result2 = 2 * to - from - 1\r\n }\r\n\r\n if (result1 === result2) return 3\r\n if (result1 > result2) {\r\n return 2\r\n } else {\r\n return 1\r\n }\r\n}\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp = [];\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ').map(el => +el);\r\n var result = twoElevator(inp[0], inp[1], inp[2]);\r\n print(result);\r\n\r\n }\r\n\r\n}\r\nmain()"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline().split(' ').map((t) => +t)\r\n print(TwoElevators(arr[0],arr[1],arr[2]))\r\n \r\n}\r\n \r\nfunction TwoElevators(a,b,c){\r\n a -= 1;\r\n var test1 = Math.abs(b - c) + c - 1;\r\n if (test1 < a){\r\n return '2'\r\n }else if (test1 > a){\r\n return '1'\r\n }else {\r\n return '3'\r\n }\r\n}"}, {"source_code": "\r\nfunction foo(elev1, elev2from, elev2to) {\r\n\tvar elev1time = elev1 - 1\r\n \r\n \r\n var elev2time = 0\r\n \r\n if(elev2to === 1) elev2time = elev2from - 1\r\n \telse {\r\n \telev2time = Math.abs(elev2to - elev2from) + (elev2to - 1)\r\n }\r\n \r\n \tif(elev1time < elev2time) return 1\r\n \telse if(elev1time === elev2time) return 3\r\n \telse return 2\r\n}\r\n\r\n\r\nvar count = readline();\r\n\r\nvar inp;\r\nvar size;\r\n\r\nfor(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ').map(el => +el);\r\n print(foo(inp[0], inp[1], inp[2]));\r\n\r\n}"}, {"source_code": "T = readline();\r\n\r\nwhile (T--) {\r\n str = readline()\r\n .split(\" \")\r\n .map((el) => +el);\r\n a = str[0];\r\n b = str[1];\r\n c = str[2];\r\n\r\n bc = 0;\r\n\r\n if (b > c) bc = b;\r\n else bc = b + (c-b) * 2;\r\n\r\n ans = 0;\r\n if (a < bc) ans = 1;\r\n else if (a > bc) ans = 2;\r\n else ans = 3;\r\n\r\n print(ans);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split(' ');\r\n var a = parseInt(inp[0]);\r\n var b = parseInt(inp[1]);\r\n var c = parseInt(inp[2]);\r\n\r\n var abs1 = a - 1;\r\n var abs2 = Math.abs(c - b) + c - 1;\r\n\r\n if (abs1 < abs2) { \r\n print('1');\r\n } else if (abs2 < abs1) {\r\n print('2');\r\n } else {\r\n print('3');\r\n }\r\n}\r\n"}, {"source_code": " var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var inputs = readline().split(' '),\r\n a = inputs[0],\r\n b = inputs[1];\r\n c = inputs[2];\r\n firstElevator = a - 1;\r\n secondElevator = Math.abs(b - c) + (c - 1);\r\n if(firstElevator < secondElevator){\r\n print('1');\r\n }\r\n else if(firstElevator > secondElevator){\r\n print('2');\r\n }\r\n else{\r\n print('3');\r\n }\r\n }"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n var q = readline().split(\" \");\r\n var a = +q[0];\r\n var w = +q[1];\r\n var e = +q[2];\r\n if (Math.abs(e - w) + (e - 1) === a - 1) arr.push(3);\r\n else if (Math.abs(e - w) + (e - 1) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n const answers = [];\n\n for (let i = 1; i <= testCases; i++) {\n let [a, b, c] = inputString[i].split(\" \").map((s) => Number(s));\n\n let bDist = c < b ? b : (c - b) * 2 + b;\n a--;\n bDist--;\n\n if (a === bDist) answers.push(3);\n else if (a < bDist) answers.push(1);\n else answers.push(2);\n }\n\n answers.forEach((v) => console.log(v));\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(\" \").map(Number)\n \n a = Math.abs(k[0] - 1);\n b = Math.abs(k[2] - k[1]) + Math.abs(k[2] - 1);\n if (a < b) {\n console.log(1);\n } else if (b < a) {\n console.log(2);\n } else {\n console.log(3);\n }\n\n }\n \n\t \n}); "}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = readline();\n for (let i = 0; i < t; i++) {\n let sol = 3;\n\n const [a, b, c] = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = 1;\n else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = 2;\n console.log(sol);\n }\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], c = k[2];\n a--;\n b = Math.abs(c - b) + c - 1;\n console.log(a < b ? 1 : a > b ? 2 : 3);\n }\n});"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\n// function print(x) {\r\n// console.log(x);\r\n// }\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n let q = readline().split(\" \");\r\n let a = +q[0];\r\n let w = +q[1];\r\n let e = +q[2];\r\n if (Math.abs(e * 2 - (w + 1)) === a - 1) {\r\n arr.push(3);\r\n continue;\r\n }\r\n if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) {\r\n arr.push(1);\r\n continue;\r\n }\r\n arr.push(2);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\n// function print(x) {\r\n// console.log(x);\r\n// }\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n let q = readline().split(\" \");\r\n let a = +q[0];\r\n let w = +q[1];\r\n let e = +q[2];\r\n if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);\r\n else if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n arr=arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\n// function print(x) {\r\n// console.log(x);\r\n// }\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n let q = readline().split(\" \");\r\n let a = +q[0];\r\n let w = +q[1];\r\n let e = +q[2];\r\n if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);\r\n else if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n console.log(arr.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n var q = readline().split(\" \");\r\n var a = +q[0];\r\n var w = +q[1];\r\n var e = +q[2];\r\n if (Math.abs(e - w )+ (e- 1) === a - 1) arr.push(3);\r\n if (Math.abs(e - w )+ (e- 1) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n var q = readline().split(\" \");\r\n var a = +q[0];\r\n var w = +q[1];\r\n var e = +q[2];\r\n if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);\r\n if (Math.abs(e * 2 - (w + 1)) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var testCases = +readline();\r\n let arr = [];\r\n for (let m = 0; m < testCases; m++) {\r\n var q = readline().split(\" \");\r\n var a = +q[0];\r\n var w = +q[1];\r\n var e = +q[2];\r\n if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);\r\n if (Math.abs(e * 2) - (w + 1) > a - 1) arr.push(1);\r\n else arr.push(2);\r\n }\r\n arr =arr.join(\"\\n\")\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n const answers = [];\n\n for (let i = 1; i <= testCases; i++) {\n const [a, b, c] = inputString[i].split(\" \").map((s) => Number(s));\n\n if (a === 1) answers.push(1);\n else if (\n (a === 2 && b === 2 && c === 1) ||\n (a === 3 &&\n ((b === 1 && c === 2) || (b === 2 && c === 3) || (b === 3 && c === 1)))\n )\n answers.push(3);\n else answers.push(2);\n }\n\n answers.forEach((v) => console.log(v));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n const answers = [];\n\n for (let i = 1; i <= testCases; i++) {\n const [a, b, c] = inputString[i].split(\" \").map((s) => Number(s));\n\n if (a === 1) answers.push(1);\n else if (\n (a === 2 && b === 2 && c === 1) ||\n (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))\n )\n answers.push(3);\n else answers.push(2);\n }\n\n answers.forEach((v) => console.log(v + \" \"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n const answers = [];\n\n for (let i = 1; i <= testCases; i++) {\n const [a, b, c] = inputString[i].split(\" \").map((s) => Number(s));\n\n if (a === 1) answers.push(1);\n else if (\n (a === 2 && b === 2 && c === 1) ||\n (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))\n )\n answers.push(3);\n else answers.push(2);\n }\n\n answers.forEach((v) => console.log(v + \"\\n\"));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n const answers = [];\n\n for (let i = 1; i <= testCases; i++) {\n const [a, b, c] = inputString[i].split(\" \").map((s) => Number(s));\n\n if (a === 1) answers.push(1);\n else if (\n (a === 2 && b === 2 && c === 1) ||\n (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))\n )\n answers.push(3);\n else answers.push(2);\n }\n\n answers.forEach((v) => console.log(v));\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0]\n b = k[1]\n c = k[2]\n if(a == 1){\n console.log(1)\n }else{\n if(a == 3 && b == 2 && c == 1){\n console.log(2)\n }else{\n if(b + c == a){\n console.log(3)\n }else{\n console.log(1)\n }\n }\n }\n \n }\n \n\t \n}); "}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j =1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0]\n b = k[1]\n c = k[2]\n if(a == 1){\n console.log(1)\n }else{\n if(a == 3 && b == 2 && c == 1){\n console.log(2)\n }else{\n if(b + c == a){\n console.log(3)\n }else{\n console.log(1)\n }\n }\n }\n\n }\n\n\t \n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j =1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0]\n b = k[1]\n c = k[2]\n if(a == 1){\n console.log(1)\n }else{\n if(a == 3 && b == 2 && c == 1){\n console.log(2)\n }else{\n console.log(3)\n }\n }\n\n }\n\n\t \n});//k[k.length - 1] == '' || "}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = readline();\n for (let i = 0; i < t; i++) {\n let sol = 3;\n\n const [a, b, c] = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n if (b < c) {\n if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = a;\n else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = b;\n } else {\n if (a - 1 < Math.abs(b - c - 1)) sol = a;\n else if (a - 1 > Math.abs(b - c - 1)) sol = b;\n }\n\n console.log(sol);\n }\n}\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = readline();\n for (let i = 0; i < t; i++) {\n let sol = 3;\n\n const [a, b, c] = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = a;\n else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = b;\n console.log(sol);\n }\n}\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = readline();\n for (let i = 0; i < t; i++) {\n let sol = 3;\n\n const [a, b, c] = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n if (a < Math.abs(b - c) + Math.abs(c)) sol = a;\n else if (a > Math.abs(b - c) + Math.abs(c)) sol = b;\n console.log(sol);\n }\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], c = k[2] * 2;\n a--;\n b = Math.abs(c - b) - 1;\n console.log(a < b ? 1 : a > b ? 2 : 3);\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var t = readline();\r\n for (var i = 0; i < t; i++) {\r\n var [a, b, c] = readline().trim().split(' ').map(Number);\r\n if ((a - 1) == ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('3');\r\n }\r\n if ((a - 1) > ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('2')\r\n }\r\n if ((a - 1) < ((Math.abs(b - c) + c) -1)) {\r\n process.stdout.write('1')\r\n }\r\n }\r\n}\r\n// https://codeforces.com/contest/1729/problem/B\r\n // function main() {\r\n // let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\r\n // let n = readline();\r\n // for (let k = 0; k < n; k++) {\r\n // var o = readline();\r\n // var splittedSTR = readline().trim().split('');\r\n // var output = [];\r\n // for (var i = 0; i < o; i++) {\r\n // if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n // splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n // splittedSTR.splice(i + 1, 1)\r\n // splittedSTR.splice(i - 1, 1)\r\n // }\r\n // if (o - i == 1) {\r\n // for (var j = 0; j < splittedSTR.length; j++) {\r\n // output.push(Alpha[splittedSTR[j] - 1])\r\n // if (output.length == splittedSTR.length) {\r\n // console.log(output.join(''));\r\n // }\r\n // }\r\n // }\r\n // }\r\n // }\r\n // }\r\n"}, {"source_code": "function twoElevator (lift1, from, to) {\r\n if (lift1 == 1) return 1\r\n var result1 = lift1 - 1\r\n var result2 = 0\r\n if (from > to) {\r\n result2 = from - to\r\n } else { //\r\n result2 = 2 * (to - from)\r\n }\r\n if (result1 === result2) return 3\r\n if (result1 > result2) {\r\n return 2\r\n } else {\r\n return 1\r\n }\r\n}\r\n \r\nfunction main() {\r\n \r\n var count = readline();\r\n\r\n var inp = [];\r\n\r\n for(var i = 0 ; i < count ; i++) {\r\n\r\n inp = readline().split(' ').map(el => +el);\r\n var result = twoElevator(inp[0], inp[1], inp[2]);\r\n print(result);\r\n\r\n }\r\n\r\n}\r\nmain()"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline().split(' ').map((t) => +t)\r\n print(TwoElevators(arr[0],arr[1],arr[2]))\r\n \r\n}\r\n \r\nfunction TwoElevators(a,b,c){\r\n a -= 1;\r\n var test1 = Math.abs(b - c - 1);\r\n if (test1 < a){\r\n return '2'\r\n }else if (test1 > a){\r\n return '1'\r\n }else {\r\n return '3'\r\n }\r\n}"}], "src_uid": "aca2346553f9e7b6e944ca2c74bb0b3d"} {"source_code": "var count = +readline();\nvar abspath = [];\n\nfor (var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s){\n process.stdout.write(s);\n}\n\nfunction println(s){\n console.log(s);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n var n = parseInt(readline().split(' ')[0]);\n var path = [];\n var j = 0;\n\n for(var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s){\n process.stdout.write(s);\n}\n\nfunction println(s){\n console.log(s);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n var n = parseInt(readline().split(' ')[0]);\n var path = [];\n var j = 0;\n\n for(var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s){\n process.stdout.write(s);\n}\n\nfunction println(s){\n console.log(s);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n var n = parseInt(readline().split(' ')[0]);\n var path = [];\n var j =0;\n\n for(var i=0; i= 0? l + 1: -1;\n\n if (l >= 0) {\n r++;\n l++;\n }\n\n print(l, r);\n}", "positive_code": [{"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var n = readline(),\r\n input = readline().split(\"\") , counter = 1;\r\n for(var j = 0 ; j < n - 1 ; ++j){\r\n if(input[j] != input[j + 1]){\r\n print(parseInt(input.indexOf(input[j]) + 1) + ' ' + parseInt(input.indexOf(input[j + 1]) + 1));\r\n break;\r\n }\r\n else{\r\n input[j] = '';\r\n counter++;\r\n }\r\n }\r\n if(counter == n){\r\n print(`-1 -1`);\r\n }\r\n}"}, {"source_code": "function run(){\r\n var n = readline();\r\n var s = readline();\r\n for(var i = 1; i < n; i++){\r\n if(s[i] != s[i - 1]){\r\n print(i, i + 1);\r\n return;\r\n }\r\n }\r\n print(-1, -1);\r\n}\r\n\r\nvar tc = readline();\r\nwhile(tc--) {\r\n run();\r\n}"}, {"source_code": "var t=+readline();\r\nwhile(t--){\r\n var n=+readline();\r\n var s=readline();\r\n var flag=0;\r\n for(var i=0; i q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var check = false;\n var n = lines[i].split('');\n if(e == 1){\n console.log(-1, -1);\n }else{\n for(j = 0; j < e-1; j++){\n if(n[j] != n[j + 1]){\n console.log(j + 1, j + 2);\n check = true;\n break;\n }\n }\n if(!check){\n console.log(-1, -1);\n }\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++].trim()\n console.log(solve(n, str).join(' '))\n }\n// })()\n})\n\nfunction solve(n, str) {\n const sum = []\n for (let i = 0; i < str.length; i++) {\n const [a, b] = i ? sum[i - 1] : [0, 0]\n if (str[i] === 'a') {\n sum[i] = [a + 1, b]\n } else {\n sum[i] = [a, b + 1]\n }\n }\n for (let i = 0; i < str.length; i++) {\n const [a1, b1] = i ? sum[i - 1] : [0, 0]\n for (let j = i; j < str.length; j++) {\n const [a2, b2] = sum[j]\n if (a2 - a1 === b2 - b1) return [i + 1, j + 1]\n }\n }\n return [-1, -1]\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = next();\r\n\t\tvar L = -1;\r\n\t\tvar R = -1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = i; j < N; j++){\r\n\t\t\t\tvar AC = 0;\r\n\t\t\t\tvar BC = 0;\r\n\t\t\t\tfor(var k = i; k <= j; k++){\r\n\t\t\t\t\tif(S[k] == \"a\"){\r\n\t\t\t\t\t\tAC++;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tBC++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(AC == BC){\r\n\t\t\t\t\tL = i + 1;\r\n\t\t\t\t\tR = j + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(L + \" \" + R);\r\n\t}\r\n}"}], "negative_code": [{"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var n = readline(),\r\n input = readline().split(\"\") , counter = 1;\r\n for(var j = 0 ; j < n - 1 ; ++j){\r\n if(input[j] != input[j + 1]){\r\n print(parseInt(input.indexOf(input[j]) + 1) + ' ' + parseInt(input.indexOf(input[j + 1]) + 1));\r\n break;\r\n }\r\n else{\r\n counter++;\r\n }\r\n }\r\n if(counter == n){\r\n print(`-1 -1`);\r\n }\r\n}"}, {"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var n = readline(),\r\n input = readline().split(\"\") , counter = 1;\r\n for(var j = 0 ; j < n - 1 ; ++j){\r\n if(input[j] != input[j + 1]){\r\n print(input.indexOf(input[j]) + ' ' + input.indexOf(input[j + 1]));\r\n break;\r\n }\r\n else{\r\n counter++;\r\n }\r\n }\r\n if(counter == n){\r\n print(`-1 -1`);\r\n }\r\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var s = readline();\n var l = s.indexOf('ab');\n\n if (l < 0)\n l = s.indexOf('ba');\n\n var r = l >= 0? l + 1: -1;\n\n print(++l, ++r);\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var s = readline();\n var l = s.indexOf('ab');\n\n if (l < 0)\n l = s.indexOf('ba');\n\n var r = l >= 0? l + 1: -1;\n\n print(l, r);\n}"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n var n = lines[i].split('');\n if(i % 2 == 1){\n e = n[0];\n }else{\n var check = false;\n if(e == 1){\n console.log(-1, -1);\n }else{\n for(j = 0; j < e-1; j++){\n if(n[j] != n[j + 1]){\n console.log(j + 1, j + 2);\n check = true;\n break;\n }\n }\n if(!check){\n console.log(-1, -1);\n }\n }\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n var n = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n e = n[0];\n }else{\n var check = false;\n if(e == 1){\n console.log(-1, -1);\n }else{\n for(j = 0; j < e-1; j++){\n if(n[j] != n[j + 1]){\n console.log(j + 1, j + 2);\n check = true;\n break;\n }\n }\n if(!check){\n console.log(-1, -1);\n }\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++].trim()\n console.log(solve(n, str).join(' '))\n }\n// })()\n})\n\nfunction solve(n, str) {\n const sum = []\n for (let i = 0; i < str.length; i++) {\n const [a, b] = i ? sum[i - 1] : [0, 0]\n if (str[i] === 'a') {\n sum[i] = [a + 1, b]\n } else {\n sum[i] = [a, b + 1]\n }\n }\n for (let i = 0; i < str.length; i++) {\n const [a1, b1] = i ? sum[i - 1] : [0, 0]\n for (let j = i; j < str.length; j++) {\n const [a2, b2] = sum[j]\n if (a2 - a1 === b2 - b1) return [i, j]\n }\n }\n return [-1, -1]\n}\n"}], "src_uid": "127d7f23a0ac8fcecccd687565d6f35a"} {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < t; i++){\r\n var line1 = readline().split(' ').map(getInt);\r\n var line2 = readline().split(' ').map(getInt);\r\n print(solution(line1[0], line2));\r\n}\r\nfunction solution(n, arr){\r\n if(n === 1){\r\n return 0;\r\n }\r\n if(isMInfinite(arr)){\r\n return 0;\r\n }\r\n var c;\r\n var j = 1;\r\n while(arr[j] < arr[j-1] && j < n){\r\n j++;\r\n }\r\n /*if(j === n){\r\n return -1;\r\n }*/\r\n c = arr[j] - arr[j-1];\r\n var k = 1;\r\n\r\n while(arr[k] > arr[k-1] && k < n){\r\n k++;\r\n }\r\n var m = c + arr[k-1] - arr[k];\r\n if(checkArr(arr,c,m, n)){\r\n return m + ' ' + c;\r\n }else{\r\n return -1;\r\n }\r\n\r\n}\r\nfunction isMInfinite(arr){\r\n var c = arr[1] - arr[0];\r\n\r\n return !arr.some(function(item, i){\r\n return (i && item - arr[i-1] !== c);\r\n })\r\n}\r\n\r\nfunction checkArr(arr,c,m, n){\r\n if(arr[0] >= m){\r\n return false;\r\n }\r\n for(var i = 1; i < n; i++){\r\n if(arr[i] !== (arr[i-1] + c) % m){\r\n return false;\r\n\r\n }\r\n }\r\n return true;\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var allEqual = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] !== a[i + 1]) allEqual = false\r\n }\r\n\r\n if (allEqual) return console.log(0)\r\n\r\n var diff = 0\r\n var diff1 = 0\r\n var first = true\r\n var first1 = true\r\n var isExist = true\r\n var isExist1 = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] < a[i + 1]) {\r\n if (first) {\r\n diff = a[i + 1] - a[i]\r\n first = false\r\n continue\r\n }\r\n if (a[i + 1] - a[i] !== diff) isExist = false\r\n } else {\r\n if (first1) {\r\n diff1 = a[i+1] - a[i]\r\n first1 = false\r\n continue\r\n }\r\n if (a[i+1] - a[i] !== diff1) isExist1 = false\r\n\r\n }\r\n }\r\n\r\n if (!isExist || !isExist1) return console.log(-1)\r\n\r\n var value = diff\r\n var mod1 = diff - diff1\r\n // console.log(mod1, diff, diff1)\r\n\r\n // check all raise\r\n var allRaise = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] + diff !== a[i + 1]) {\r\n allRaise = false\r\n }\r\n }\r\n if (allRaise) return console.log(0)\r\n // check all raise\r\n\r\n // check all raise\r\n var allDown = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] + diff1 !== a[i + 1]) {\r\n allDown = false\r\n }\r\n }\r\n if(allDown){\r\n console.log(0)\r\n return\r\n }\r\n // check all raise\r\n\r\n// console.log(mod1, diff1, diff)\r\n var exist = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] >= mod1) exist = false\r\n if ((a[i] + value) % mod1 !== a[i + 1]) {\r\n exist = false\r\n // console.log(a[i], a[i+1])\r\n }\r\n }\r\n if (!exist) return console.log(-1)\r\n console.log(mod1, value)\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var allEqual = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] !== a[i + 1]) allEqual = false\r\n }\r\n\r\n if (allEqual) return console.log(0)\r\n\r\n var diff = 0\r\n var diff1 = 0\r\n var first = true\r\n var first1 = true\r\n var isExist = true\r\n var isExist1 = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] < a[i + 1]) {\r\n if (first) {\r\n diff = a[i + 1] - a[i]\r\n first = false\r\n continue\r\n }\r\n if (a[i + 1] - a[i] !== diff) isExist = false\r\n } else {\r\n if (first1) {\r\n diff1 = a[i+1] - a[i]\r\n first1 = false\r\n continue\r\n }\r\n if (a[i+1] - a[i] !== diff1) isExist1 = false\r\n\r\n }\r\n }\r\n\r\n if (!isExist || !isExist1) return console.log(-1)\r\n\r\n var value = diff\r\n var mod1 = diff - diff1\r\n // console.log(mod1, diff, diff1)\r\n\r\n // check all raise\r\n var allRaise = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] + diff !== a[i + 1]) {\r\n allRaise = false\r\n }\r\n }\r\n if (allRaise) return console.log(0)\r\n // check all raise\r\n\r\n // check all raise\r\n var allDown = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] + diff1 !== a[i + 1]) {\r\n allDown = false\r\n }\r\n }\r\n if(allDown){\r\n console.log(a[0]+1, a[0]+1+diff1)\r\n return\r\n }\r\n // check all raise\r\n\r\n\r\n var exist = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] >= mod1) exist = false\r\n if ((a[i] + value) % mod1 !== a[i + 1]) {\r\n exist = false\r\n // console.log(a[i], a[i+1])\r\n }\r\n }\r\n if (!exist) return console.log(-1)\r\n console.log(mod1, value)\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var allEqual = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] !== a[i + 1]) allEqual = false\r\n }\r\n\r\n if(allEqual) return console.log(0)\r\n\r\n var diff\r\n var first= true\r\n var isExist = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] < a[i + 1]) {\r\n if(first){\r\n diff = a[i + 1] - a[i]\r\n first = false\r\n continue\r\n }\r\n if(a[i + 1] - a[i] !== diff) isExist = false\r\n }\r\n }\r\n var value = diff\r\n // console.log(diff)\r\n if (!isExist) return console.log(-1)\r\n\r\n // check all raise\r\n var allRaise = true\r\n for (let i = 0; i < n-1; i++) {\r\n if (a[i] + value !== a[i + 1]) {\r\n allRaise = false\r\n }\r\n }\r\n if (allRaise) return console.log(0)\r\n\r\n var mod1 = -1\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] > a[i + 1]) mod1 = a[i] + value - a[i+1]\r\n }\r\n\r\n var exist = true\r\n for (let i = 0; i < n-1; i++) {\r\n if(a[i] >= mod1) exist = false\r\n if ((a[i] + value) % mod1 !== a[i + 1]) {\r\n exist = false\r\n // console.log(a[i], a[i+1])\r\n }\r\n }\r\n if (!exist) return console.log(-1)\r\n console.log(mod1, value)\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var allEqual = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] !== a[i + 1]) allEqual = false\r\n }\r\n\r\n if(allEqual) return console.log(0)\r\n\r\n var diff\r\n var first= true\r\n var isExist = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] < a[i + 1]) {\r\n if(first){\r\n diff = a[i + 1] - a[i]\r\n first = false\r\n continue\r\n }\r\n if(a[i + 1] - a[i] !== diff) isExist = false\r\n }\r\n }\r\n var value = diff\r\n // console.log(diff)\r\n if (!isExist) return console.log(-1)\r\n\r\n var mod1\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] > a[i + 1]) mod1 = a[i] + value - a[i+1]\r\n }\r\n\r\n var exist = true\r\n for (let i = 0; i < n-1; i++) {\r\n if(a[i] >= mod1) exist = false\r\n if ((a[i] + value) % mod1 !== a[i + 1]) {\r\n exist = false\r\n // console.log(a[i], a[i+1])\r\n }\r\n }\r\n if (!exist) return console.log(-1)\r\n console.log(mod1, value)\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}, {"source_code": "function solution(n, arr){\r\n if(n === 1){\r\n return 0;\r\n }\r\n if(isMInfinite(arr)){\r\n return 0;\r\n }\r\n var c;\r\n var j = 1;\r\n while(arr[j] < arr[j-1] && j < n){\r\n j++;\r\n }\r\n c = arr[j] - arr[j-1];\r\n var k = 1;\r\n\r\n while(arr[k] > arr[k-1] && k < n){\r\n k++;\r\n }\r\n var m = c + arr[k-1] - arr[k];\r\n if(checkArr(arr,c,m, n)){\r\n return m + ' ' + c;\r\n }else{\r\n return -1;\r\n }\r\n\r\n}\r\nfunction isMInfinite(arr){\r\n var c = arr[1] - arr[0];\r\n\r\n return !arr.some(function(item, i){\r\n return (i && item - arr[i-1] !== c);\r\n })\r\n}\r\n\r\nfunction checkArr(arr,c,m, n){\r\n if(arr[0] >= m){\r\n return false;\r\n }\r\n for(var i = 1; i < n; i++){\r\n if(arr[i] !== (arr[i-1] + c) % m){\r\n return false;\r\n\r\n }\r\n }\r\n return true;\r\n}"}], "src_uid": "d6721fb3dd02535fc08fc69a4811d60c"} {"source_code": "//6\n//4 6 2 1 5 3\n\n// let p = [4,6,2,1,5,3];\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while (t > 0) {\n let n = readline();\n let p = readline().split(' ');\n\n b1(n,p);\n\n t--;\n }\n}\n\n\n\n\n\n\n\nfunction create2DArray(len) {\n let b = {};\n for (var i = 0; i < +len; i++) {\n b[i] = {};\n }\n return b;\n}\n\n\nfunction b1(n,p) {\n let b = create2DArray(n);\n let q = 0;\n let s = 0;\n let r = '';\n while (q < p.length) {\n let i = p[s] - 1;\n \n if (b[i][q] && i != q) {\n b[q][q] = (b[q][q] || 0) + (b[i][q] + 1);\n q++;\n s = q;\n continue;\n } else {\n b[q][q] = (b[q][q] || 0) + 1;\n b[q][i] = b[q][q];\n\n if (q == i) {\n // console.error('Result2', q, b[q][q]);\n q++;\n s = q;\n continue;\n }\n }\n s = i;\n }\n \n for(let i = 0; i < p.length; i++) {\n if(i == 0) \n r += '' + b[i][i]; \n else \n r += ' ' + b[i][i];\n }\n console.log(r);\n}\n", "positive_code": [{"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nvar gcd = (a, b) => a ? gcd(b % a, a) : b;\nvar lcm = (a, b) => a * b / gcd(a, b);\n\nvar a,cnt;\nfunction main(){\n\tlet t =+(readLine());\n\twhile(t--){\n\t\tlet n = +(readLine())\n\t\ta = readLine().split(\" \").map(Number);\n\t\t// console.log(a)\n\t\tfor(let i = 0; i {\n const b = Array(n).fill(0);\n for (let i = 0; i < n; i++) {\n if (b[i]) continue;\n let j = i, r = [ i ];\n while((j = a[j]) !== i) r.push(j);\n r.forEach(i => b[i] = r.length);\n }\n return b.join(' ');\n}\n\nfor (let q = +readline(); q; q--) print(problem(+readline(), readline().split(' ').map(i => --i)));\n"}, {"source_code": "t = +readline();\nres = '';\nwhile (t-->0){\n n = +readline();\n ar = readline().split(' ').map(Number);\n for (i = 0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while (t > 0) {\n let n = readline();\n let p = readline().split(' ');\n\n b1(n, p);\n\n t--;\n }\n}\n\n\nfunction b1(n, p) {\n const travel = [];\n const ans = [];\n\n for(let i = 0; i < n; i++) {\n p[i] = p[i] - 1;\n }\n\n let c = 0;\n while(c < n) {\n if(!travel[c]) {\n let r = [];\n let s = p[c];\n while(!travel[c]) {\n travel[s] = true;\n r.push(s);\n s = p[s];\n }\n for(let i = 0;i < r.length;i++)\n ans[r[i]] = r.length;\n }\n c++;\n }\n\n let r ='';\n for(let i = 0; i < ans.length; i++) {\n if(i == 0) \n r += '' + ans[i]; \n else \n r += ' ' + ans[i];\n }\n console.log(r);\n}\n\n// b1(6,p)"}, {"source_code": "//-------------------------field fun--------------------------\n var _tmp = [];\n var _front = 0;\n var readOne = function() {\n if(_front >= _tmp.length) {\n _tmp = readline().split(' ');\n _front = 0;\n return readOne();\n } else {\n return _tmp[_front++];\n }\n };\n var readInt = function() {\n return parseInt(readOne());\n };\n var readStr = function() {\n return readOne();\n };\n //-----------------------field program------------------------\n var fa = [];\n var nums = [];\n var Fa = function(n) {\n if(fa[n] != n) {\n fa[n] = Fa(fa[n]);\n }\n return fa[n];\n };\n var q = readInt();\n while(q--) {\n fa = [];\n nums = [];\n var n = readInt();\n for(var i = 1; i <= n; i++) {\n fa[i] = i;\n nums[i] = 1;\n }\n for(var i = 1; i <= n; i++) {\n var t = readInt();\n if(Fa(i) != Fa(t)) {\n nums[fa[t]] += nums[fa[i]];\n fa[fa[i]] = fa[t];\n }\n }\n for(var i = 1; i <= n; i++) {\n write(nums[Fa(i)] + ' ');\n }\n write('\\n');\n }"}, {"source_code": "'use strict'\nlet input = readline()\nlet i = 1\nlet daysHold =1\nlet final = []\nwhile(i <= input){\n let secondLine = readline()\n let arr = readline().split(' ').map(Number)\n let copy = JSON.parse(JSON.stringify(arr))\n let j = 0\n while(j < arr.length){\n\n while(1){\n if(arr[j] !== j+1){\n let temp = arr[arr[j]-1]\n arr[arr[j]-1] = arr[j]\n arr[j] = temp\n daysHold++\n }\n else if(arr[j] == j+1) break\n }\n final.push(daysHold)\n daysHold = 1\n arr = JSON.parse(JSON.stringify(copy))\n j++\n }\n print(final.join(' '))\n final = []\n i++\n}"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const b = Array(n).fill(0);\n let i;\n while ((i = b.indexOf(0)) !== -1) {\n let j = i, r = [ j ];\n while (i !== (j = a[j])) r.push(j);\n r.forEach(j => b[j] = r.length);\n }\n return b.join(' ');\n}\n\nlet q = +readline();\nwhile(q--) {\n print(problem(+readline(), readline().split(' ').map(i => +i - 1)));\n}\n"}, {"source_code": "//6\n//4 6 2 1 5 3\n\n// let p = [4,6,2,1,5,3];\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while (t > 0) {\n let n = readline();\n let p = readline().split(' ');\n\n b1(n, p);\n\n t--;\n }\n}\n\n\nfunction b1(n, p) {\n const travel = [];\n const ans = [];\n\n for(let i = 0; i < n; i++) {\n p[i] = p[i] - 1;\n }\n\n let c = 0;\n while(c < n) {\n if(!travel[c]) {\n let r = [];\n let s = p[c];\n while(!travel[c]) {\n travel[s] = true;\n r.push(s);\n s = p[s];\n }\n for(let i = 0;i < r.length;i++)\n ans[r[i]] = r.length;\n }\n c++;\n }\n\n let r ='';\n for(let i = 0; i < ans.length; i++) {\n if(i == 0) \n r += '' + ans[i]; \n else \n r += ' ' + ans[i];\n }\n console.log(r);\n}\n"}, {"source_code": "//6\n//4 6 2 1 5 3\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while (t > 0) {\n let n = readline();\n let p = readline().split(' ');\n\n b1(n,p);\n\n t--;\n }\n}\n\n\n\n\n\n\n\nfunction create2DArray(len) {\n let b = [];\n for (var i = 0; i < +len; i++) {\n b[i] = new Array(+len).fill(0);\n }\n return b;\n}\n\n\nfunction b1(n,p) {\n let b = create2DArray(n);\n let q = 0;\n let s = 0;\n let r = '';\n while (q < p.length) {\n let i = p[s] - 1;\n \n if (b[i][q] && i != q) {\n b[q][q] += (b[i][q] + 1);\n q++;\n s = q;\n continue;\n } else {\n b[q][q] += 1;\n b[q][i] = b[q][q];\n\n if (q == i) {\n // console.error('Result2', q, b[q][q]);\n q++;\n s = q;\n continue;\n }\n }\n s = i;\n }\n \n for(let i = 0; i < p.length; i++) {\n if(i == 0) \n r += '' + b[i][i]; \n else \n r += ' ' + b[i][i];\n }\n console.log(r);\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, n) {\n\n function per(value, index, array, count = 1, startVindex = index) {\n if (startVindex + 1 === array[index]) return count;\n return per(value, array[index] - 1, array, ++count, startVindex);\n }\n\n return data.map((value, index, array) => {\n const result = per(value, index, array);\n return result;\n }).join(' ');\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n let result = foo(data, n);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": " 'use strict';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readAllLine() {\n return inputString;\n }\n function findNextArray(originArray, mapArray) {\n let arReturn = [];\n for (let i = 0; i < originArray.length; i++) {\n arReturn.push(originArray[mapArray[i]-1]);\n }\n return arReturn;\n }\n\n function resolve(arKids) {\n // console.log(arKids.join(\" \"));\n // return arKids;\n let _arKids = [...arKids];\n let arBeforeMatchByDate = arKids;\n let tmp = [], arReturn = [], fullReturnCount = 0, dayCount = 0;\n let arBefore1Day = [];\n for(let i = 0;i < arKids.length; i++) {\n arBefore1Day[arKids[i] - 1] = (i + 1).toString();\n }\n while (fullReturnCount < arKids.length) {\n dayCount++;\n tmp = [];\n //Build array current Date time\n for (let i = 0; i < arKids.length; i++) {\n let currentBookIndex = arKids[i];\n if (dayCount > 1) {\n currentBookIndex = arKids[_arKids[i] - 1];\n }\n tmp.push(currentBookIndex);\n if (currentBookIndex == i + 1 && !arReturn[i]) {\n arReturn[i] = dayCount;\n fullReturnCount++;\n } else if(arBeforeMatchByDate[i] == currentBookIndex\n && !arReturn[i] && (dayCount > 1)) {\n //Compare With ArrayBefore Match\n arReturn[i] = dayCount * 2 - 1;\n fullReturnCount++;\n }\n }\n //Build Array Before N day to match\n if (dayCount > 1) {\n arBeforeMatchByDate = findNextArray(arBefore1Day, arBeforeMatchByDate)\n } else {\n arBeforeMatchByDate = [...arBefore1Day];\n }\n for(let i = 0; i < arBeforeMatchByDate.length; i ++) {\n if(arBeforeMatchByDate[i] == tmp[i] && !arReturn[i]) {\n arReturn[i] = dayCount * 2;\n fullReturnCount++;\n }\n }\n\n\n _arKids = [...tmp];\n }\n console.log(arReturn.join(\" \"));\n return arReturn;\n }\n\n function createTestCase(maxRange) {\n let arTestCase = [];\n for (let i = 0; i < maxRange; i++) {\n arTestCase.push(i === maxRange - 1 ? 1 : i + 2);\n }\n fs.appendFile('testcase.txt', '1\\n', function (err) {\n if (err) throw err;\n });\n fs.appendFile('testcase.txt', maxRange+'\\n', function (err) {\n if (err) throw err;\n });\n fs.appendFile('testcase.txt', arTestCase.join(' '), function (err) {\n if (err) throw err;\n });\n }\n\n function main() {\n let start = Date.now();\n const data = readAllLine();\n let arTestCase = [];\n if (data.length > 0) {\n const numberOfQueues = data.shift();\n let count = 0;\n while (data.length > 0 && count 0) {\n for(let i = 0;i < arTestCase.length; i++) {\n resolve(arTestCase[i])\n }\n }\n // console.log(Date.now() - start);\n\n }\n"}], "negative_code": [{"source_code": "//6\n//4 6 2 1 5 3\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while (t > 0) {\n let n = readline();\n let p = readline().split(' ');\n\n b1(n,p);\n\n t--;\n }\n}\n\n\n\n\n\n\n\nfunction create2DArray(len) {\n let b = []\n for (var i = 0; i < len; i++) {\n b[i] = new Array(9).fill(0);\n }\n return b;\n}\n\n\nfunction b1(n,p) {\n \n let b = create2DArray(n);\n let q = 0;\n let s = 0;\n let r = '';\n while (q < p.length) {\n let i = p[s] - 1;\n \n if (b[i][q] && i != q) {\n b[q][q] += (b[i][q] + 1);\n q++;\n s = q;\n continue;\n } else {\n b[q][q] += 1;\n b[q][i] = b[q][q];\n\n if (q == i) {\n // console.error('Result2', q, b[q][q]);\n q++;\n s = q;\n continue;\n }\n }\n s = i;\n }\n \n for(let i = 0; i < p.length; i++) {\n if(i === 0) \n r += '' + b[i][i]; \n else \n r += ' ' + b[i][i];\n }\n console.log(r);\n}"}, {"source_code": " 'use strict';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n });\n\n function readAllLine() {\n return inputString;\n }\n function findNextArray(originArray, mapArray) {\n let arReturn = [];\n for (let i = 0; i < originArray.length; i++) {\n arReturn.push(originArray[mapArray[i]-1]);\n }\n return arReturn;\n }\n\n function resolve(arKids) {\n // console.log(arKids.join(\" \"));\n // return arKids;\n let _arKids = [...arKids];\n let arBeforeMatchByDate = arKids;\n let tmp = [], arReturn = [], fullReturnCount = 0, dayCount = 0;\n let arBefore1Day = [];\n for(let i = 0;i < arKids.length; i++) {\n arBefore1Day[arKids[i] - 1] = (i + 1).toString();\n }\n while (fullReturnCount < arKids.length) {\n dayCount++;\n tmp = [];\n //Build array current Date time\n for (let i = 0; i < arKids.length; i++) {\n let currentBookIndex = arKids[i];\n if (dayCount > 1) {\n currentBookIndex = arKids[_arKids[i] - 1];\n }\n tmp.push(currentBookIndex);\n if (currentBookIndex == i + 1 && !arReturn[i]) {\n arReturn[i] = dayCount;\n fullReturnCount++;\n } else if(arBeforeMatchByDate[i] == currentBookIndex\n && !arReturn[i] && (dayCount > 1)) {\n //Compare With ArrayBefore Match\n arReturn[i] = dayCount * 2 - 1;\n fullReturnCount++;\n }\n }\n //Build Array Before N day to match\n if (dayCount > 1) {\n arBeforeMatchByDate = findNextArray(arBefore1Day, arBeforeMatchByDate)\n } else {\n arBeforeMatchByDate = [...arBefore1Day];\n }\n for(let i = 0; i < arBeforeMatchByDate.length; i ++) {\n if(arBeforeMatchByDate[i] == tmp[i] && !arReturn[i]) {\n arReturn[i] = dayCount * 2;\n fullReturnCount++;\n }\n }\n\n\n _arKids = [...tmp];\n }\n console.log(arReturn.join(\" \"));\n return arReturn;\n }\n\n function createTestCase(maxRange) {\n let arTestCase = [];\n for (let i = 0; i < maxRange; i++) {\n arTestCase.push(i === maxRange - 1 ? 1 : i + 2);\n }\n fs.appendFile('testcase.txt', '1\\n', function (err) {\n if (err) throw err;\n });\n fs.appendFile('testcase.txt', maxRange+'\\n', function (err) {\n if (err) throw err;\n });\n fs.appendFile('testcase.txt', arTestCase.join(' '), function (err) {\n if (err) throw err;\n });\n }\n\n function main() {\n let start = Date.now();\n const data = readAllLine();\n let arTestCase = [];\n if (data.length > 0) {\n const numberOfQueues = data.shift();\n let count = 0;\n while (data.length > 0 && count 0) {\n for(let i = 0;i < arTestCase.length; i++) {\n resolve(arTestCase[i])\n }\n }\n console.log(Date.now() - start);\n\n }\n"}, {"source_code": "//-------------------------field fun--------------------------\n var _tmp = [];\n var _front = 0;\n var readOne = function() {\n if(_front >= _tmp.length) {\n _tmp = readline().split(' ');\n _front = 0;\n return readOne();\n } else {\n return _tmp[_front++];\n }\n };\n var readInt = function() {\n return parseInt(readOne());\n };\n var readStr = function() {\n return readOne();\n };\n //-----------------------field program------------------------\n var fa = [];\n var nums = [];\n var Fa = function(n) {\n if(fa[n] != n) {\n fa[n] = Fa(fa[n]);\n }\n return fa[n];\n };\n var q = readInt();\n while(q--) {\n fa = [];\n nums = [];\n var n = readInt();\n for(var i = 1; i <= n; i++) {\n fa[i] = i;\n nums[i] = 1;\n }\n for(var i = 1; i <= n; i++) {\n var t = readInt();\n if(fa[i] != fa[t]) {\n nums[fa[t]] += nums[Fa(i)];\n fa[i] = fa[Fa(t)];\n }\n }\n for(var i = 1; i <= n; i++) {\n write(nums[Fa(i)] + ' ');\n }\n write('\\n');\n }"}, {"source_code": "//-------------------------field fun--------------------------\n var _tmp = [];\n var _front = 0;\n var readOne = function() {\n if(_front >= _tmp.length) {\n _tmp = readline().split(' ');\n _front = 0;\n return readOne();\n } else {\n return _tmp[_front++];\n }\n };\n var readInt = function() {\n return parseInt(readOne());\n };\n var readStr = function() {\n return readOne();\n };\n //-----------------------field program------------------------\n var fa = [];\n var nums = [];\n var Fa = function(n) {\n if(fa[n] != n) {\n fa[n] = Fa(fa[n]);\n }\n return fa[n];\n };\n var q = readInt();\n while(q--) {\n fa = [];\n nums = [];\n var n = readInt();\n for(var i = 1; i <= n; i++) {\n fa[i] = i;\n nums[i] = 1;\n }\n for(var i = 1; i <= n; i++) {\n var t = readInt();\n if(fa[i] != fa[t]) {\n nums[Fa(t)] += nums[Fa(i)];\n fa[fa[i]] = fa[t];\n }\n }\n for(var i = 1; i <= n; i++) {\n write(nums[Fa(i)] + ' ');\n }\n write('\\n');\n }"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const b = Array(n).fill(0);\n for (let i = 0; i < n; i++) {\n if (!b[i]) {\n let j = i, r = [ i ];\n while((j = a[j]) !== i) r.push(j);\n b.forEach(i => b[i] = r.length);\n }\n }\n return b.join(' ');\n}\n\nlet q = +readline();\nwhile(q--) print(problem(+readline(), readline().split(' ').map(i => +i - 1)));\n"}, {"source_code": "//6\n//4 6 2 1 5 3\n\nlet p = [1,2,3,4,5,6];\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n// main();\n// });\n\n// function readline() {\n// return inputString[currentLine++];\n// }\n\n\n// function main() {\n// let t = readline();\n// while (t > 0) {\n// let n = readline();\n// let p = readline().split(' ');\n\n// b1(n, p);\n\n// t--;\n// }\n// }\n\n\nfunction b1(n, p) {\n const travel = [];\n const ans = [];\n\n for(let i = 0; i < n; i++) {\n p[i] = p[i] - 1;\n }\n\n let c = 0;\n while(c < n) {\n if(!travel[c]) {\n let r = [];\n let s = p[c];\n while(!travel[c]) {\n travel[s] = true;\n r.push(s);\n s = p[s];\n }\n for(let i = 0;i < r.length;i++)\n ans[r[i]] = r.length;\n }\n c++;\n }\n\n let r ='';\n for(let i = 0; i < ans.length; i++) {\n if(i == 0) \n r += '' + ans[i]; \n else \n r += ' ' + ans[i];\n }\n console.log(r);\n}\n\nb1(6,p)"}], "src_uid": "345e76bf67ae4342e850ab248211eb0b"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const length = parseInt(readline(), 10);\r\n let num = readline();\r\n num = ('0').repeat(length - num.length) + num;\r\n\r\n let result = '';\r\n\r\n let lessThanNinetyPercent = Number(num.charAt(0)) < 9;\r\n if (lessThanNinetyPercent) {\r\n let target = ('9').repeat(length);\r\n for (let i = 0; i < length; i++) {\r\n result += Number(target.charAt(i)) - Number(num.charAt(i));\r\n }\r\n output(result);\r\n continue;\r\n } else {\r\n let reverseResult = '';\r\n let carryOver = false;\r\n for (let i = length - 1; i >= 0; i--) {\r\n let digit = Number(num.charAt(i));\r\n if (carryOver) {\r\n digit++;\r\n carryOver = false;\r\n if (digit === 10) {\r\n carryOver = true;\r\n digit = 0;\r\n }\r\n }\r\n if (digit === 0) {\r\n reverseResult += '1';\r\n } else if (digit === 1) {\r\n reverseResult += '0';\r\n } else {\r\n reverseResult += String(11 - digit);\r\n carryOver = true;\r\n }\r\n }\r\n result = reverseResult.split('').reverse().join('');\r\n output(result);\r\n continue;\r\n }\r\n\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = int(readLine());\r\n while (t--) {\r\n let n = int(readLine());\r\n let num = readLine();\r\n console.log(f(num, n));\r\n }\r\n});\r\n\r\n\r\nfunction f(num, n) {\r\n let ans = '';\r\n if (num[0] == '9') {\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) {\r\n ans += ((11 - cnt - int(num[n - i - 1])) % 10).toString()\r\n cnt = Math.floor((int(ans[i]) + int(num[n - i - 1])) / 10)\r\n }\r\n ans = ans.split('').reverse().join('')\r\n } else {\r\n for (let i = 0; i < n; i++) {\r\n ans += 9 - num[i];\r\n }\r\n }\r\n return ans;\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n if (Number(s[0]) < 9) {\r\n const res = new Array(n);\r\n for (let i = n - 1; i >= 0; i--) {\r\n const num = Number(s[i]);\r\n res[i] = 9 - num;\r\n }\r\n return res.join('');\r\n } else {\r\n const res = new Array(n + 1).fill(1);\r\n for (let i = n - 1; i >= 0; i--) {\r\n const num = Number(s[i]);\r\n let dif = res[i + 1] - num;\r\n if (dif >= 0) res[i + 1] = dif;else {\r\n dif = 10 + dif;\r\n res[i]--;\r\n res[i + 1] = dif;\r\n }\r\n }\r\n return res.slice(1).join('');\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const s = await read();\r\n res[i] = solve(n, s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const getPlaindrome = (k,n,fill)=>{\r\n let carry = 0;\r\n let res = \"\";\r\n for(let i=k-1;i>=0;i--){\r\n let num = parseInt(n[i]);\r\n if(carry===1) num+=1;\r\n if(num<=fill){\r\n res=fill-num+(res);\r\n carry = 0;\r\n }\r\n else{\r\n carry = 1;\r\n res = (11-num)+res;\r\n }\r\n }\r\n return res;\r\n}\r\nconst solve = (k,n)=>{\r\n if(n[0]===\"9\") return getPlaindrome(k,n,1);\r\n else return getPlaindrome(k,n,9);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i 1)\r\n {\r\n arr.push(11 - narr[n -1]);\r\n }\r\n else\r\n {\r\n arr.push(1 - narr[n - 1]);\r\n }\r\n for(var i = 1; i < n; i++)\r\n {\r\n if((arr[i - 1] + narr[n - i]) > 9)\r\n {\r\n if((narr[ n - 1 - i] + 1) > 8)\r\n {\r\n arr.push(18 - (narr[ n - 1 - i] + 1));\r\n }\r\n else\r\n {\r\n arr.push(8 - (narr[ n - 1 - i] + 1));\r\n }\r\n }\r\n else\r\n {\r\n if((narr[ n - 1 - i] ) > 8)\r\n {\r\n arr.push(18 - (narr[ n - 1 - i] ));\r\n }\r\n else\r\n {\r\n arr.push(8 - (narr[ n - 1 - i] ));\r\n }\r\n }\r\n }\r\n for(var i = n - 1; i > - 1; i--)\r\n {\r\n nstr += arr[i];\r\n }\r\n print(nstr);\r\n }\r\n }"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = parseInt(readline());\r\n let num = readline();\r\n print(Easy(n, num));\r\n }\r\n}\r\nfunction Easy(n, number) {\r\n let first = number[0];\r\n if (first == \"9\") {\r\n let str = \"1\";\r\n for (let i = 0; i < n; i++) str += \"1\";\r\n return sub(number, str);\r\n } else {\r\n let str = \"\";\r\n for (let i = 0; i < n; i++) str += \"9\";\r\n return sub(number, str);\r\n }\r\n}\r\n\r\nfunction sub(a, b) {\r\n let carry = 0;\r\n let i = a.length - 1;\r\n let j = b.length - 1;\r\n let ans = [];\r\n while (j !== -1) {\r\n let dig1 = Number(a[i]);\r\n let dig2 = Number(b[j]);\r\n if (!dig1) dig1 = 0;\r\n if (dig2 - (dig1 + carry) < 0) {\r\n let remain = 10 + dig2 - (dig1 + carry);\r\n ans[j] = remain;\r\n carry = 1;\r\n } else {\r\n let remain = dig2 - (dig1 + carry);\r\n ans[j] = remain;\r\n carry = 0;\r\n }\r\n i--;\r\n j--;\r\n }\r\n j++;\r\n let str = \"\";\r\n while (ans[j] == 0) j++;\r\n while (j !== b.length) {\r\n str += ans[j];\r\n j++;\r\n }\r\n return str;\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = parseInt(readline());\r\n let num = parseInt(readline());\r\n print(Easy(n, num));\r\n }\r\n}\r\nfunction Easy(n, number) {\r\n let first = Math.floor(number / 10 ** (n - 1));\r\n if (first !== 9) {\r\n let str = \"\";\r\n for (let i = 0; i < n; i++) {\r\n str += \"9\";\r\n }\r\n return Number(str) - number;\r\n } else {\r\n let str = \"1\";\r\n for (let i = 0; i < n; i++) {\r\n str += \"1\";\r\n }\r\n return Number(str) - number;\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = parseInt(readline());\r\n let num = parseInt(readline());\r\n print(Easy(n, num));\r\n }\r\n}\r\nfunction Easy(n, number) {\r\n let first = Math.floor(number / (10 ** (n - 1)));\r\n if (first !== 9) {\r\n let str = \"\";\r\n for (let i = 0; i < n; i++) {\r\n str += \"9\";\r\n }\r\n return Number(str) - number;\r\n } else {\r\n let str = \"1\";\r\n for (let i = 0; i < n - 1; i++) {\r\n str += \"2\";\r\n }\r\n str += \"1\";\r\n return Number(str) - number;\r\n }\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = int(readLine());\r\n while (t--) {\r\n const n = int(readLine());\r\n const num = readLine();\r\n console.log(f(num, n))\r\n }\r\n});\r\n\r\n\r\nfunction f(num, n) {\r\n let ans = '';\r\n if (num[0] == '9') {\r\n for (let i = 0; i < n - 1; i++) {\r\n ans += (10 - num[i]) % 10;\r\n }\r\n ans += ((11 - num[n - 1]) % 10);\r\n } else {\r\n for (let i = 0; i < n; i++) {\r\n ans += 9 - num[i];\r\n }\r\n }\r\n return ans;\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = int(readLine());\r\n while (t--) {\r\n const n = int(readLine());\r\n const num = readLine();\r\n console.log(f(num, n))\r\n }\r\n});\r\n\r\n\r\nfunction f(num, n) {\r\n let ans = '';\r\n if (num[0] == '9') {\r\n for (let i = 0; i < n - 1; i++) {\r\n ans += 10 - num[i];\r\n }\r\n ans += (11 - num[n - 1]);\r\n } else {\r\n for (let i = 0; i < n; i++) {\r\n ans += 9 - num[i]\r\n }\r\n }\r\n return ans;\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n if (Number(s[0]) < 9) {\r\n const res = new Array(n);\r\n for (let i = n - 1; i >= 0; i--) {\r\n const num = Number(s[i]);\r\n res[i] = 9 - num;\r\n }\r\n return res.join('');\r\n } else {\r\n const res = new Array(n + 1).fill(1);\r\n for (let i = n - 1; i >= 0; i--) {\r\n const num = Number(s[i]);\r\n let dif = res[i + 1] - num;\r\n if (dif > 0) res[i + 1] = dif;else {\r\n dif = 10 + dif;\r\n res[i]--;\r\n res[i + 1] = dif;\r\n }\r\n }\r\n return res.slice(1).join('');\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const s = await read();\r\n res[i] = solve(n, s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n const res = new Array(n + 1);\r\n res[0] = 9;\r\n for (let i = n - 1; i >= 0; i--) {\r\n const num = Number(s[i]);\r\n res[i + 1] = 9 - num;\r\n }\r\n return res.join('');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const s = await read();\r\n res[i] = solve(n, s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const checkPalindrome = n=>{\r\n let str = \"\"+n;\r\n for(let i=0;i{\r\n let arr = [10,100,1000,10000,100000,1000000];\r\n for(let i=arr[k-2];i {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nlet powers = [], factorials = [];\nconst precalc = ()=>{\n let num = 1;\n while (num<1e12){\n powers.push(num);\n num *= 2;\n }\n num = 6;\n for (let i=4; num<1e12; i++){\n factorials.push(num);\n num *= i;\n }\n l({powers, factorials})\n};\n\nconst calc = (n)=>{\n let bmax = 1<<15;\n let count1 = num=>{\n let s = num.toString(2);\n let cn = 0;\n for (let i=0; i{\n for (let i=0; i<14 && num>=0; i++){\n if ((1<=0){\n let t = count1(cnum)+count1(bmask);\n if (t stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 1e12 + 10;\r\n\r\nfunction bitCount (n) {\r\n\tcnt = 0;\r\n\tfor (let i = 0; i < 40; i++) {\r\n\t\tcnt += n & 1;\r\n\t\tn = Math.floor(n/2); \r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet fact = [1];\r\n\tfor (let i = 1; fact[i-1] * i <= mxN; i++) {\r\n\t\tfact[i] = fact[i-1] * i;\r\n\t}\r\n\tfact = fact.slice(3); // 0: 1, 1: 1, 2: 2, 3: 6, 4: 24 => 3: 6, 4: 24, \r\n\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = Math.ceil(Math.log2(mxN));\r\n\t\tfor (let mask = 0; mask < 1 << fact.length; mask++) {\r\n\t\t\tlet sum = n, k = 0;\r\n\t\t\tfor (let i = 0; i < fact.length; i++) {\r\n\t\t\t\tif (mask & (1 << i)) {\r\n\t\t\t\t\tsum -= fact[i];\r\n\t\t\t\t\tk++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (sum >= 0) {\r\n\t\t\t\tk += bitCount(sum);\r\n\t\t\t\tans = Math.min(ans, k);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 1e12 + 10;\r\n\r\nfunction bitCount (n) {\r\n\tif (n == 0) return 0;\r\n\treturn n.toString(2).match(/1/g).length;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet fact = [1];\r\n\t\tfor (let i = 1; fact[i-1] * i <= mxN; i++) {\r\n\t\t\tfact[i] = fact[i-1] * i;\r\n\t\t}\r\n\t\tfact = fact.slice(3); // 0:1, 1:1, 2:2, 3:6, 4:24 => 3:6, 4:24, \r\n\r\n\t\tlet ans = 40;\r\n\t\tfor (let mask = 0; mask < 1 << fact.length; mask++) {\r\n\t\t\tlet sum = 0, k = 0;\r\n\t\t\tfor (let i = 0; i < fact.length; i++) {\r\n\t\t\t\tif (mask & (1 << i)) {\r\n\t\t\t\t\tsum += fact[i];\r\n\t\t\t\t\tk++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (sum <= n) {\r\n\t\t\t\tk += bitCount(n - sum);\r\n\t\t\t\tans = Math.min(ans, k);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nconst rightShift = (i, j) => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);else return lo >> j;\r\n lo >>= j;\r\n lo |= (hi & (1 << j) - 1) << 30 - j;\r\n hi >>= j;\r\n return hi * 1073741824 + lo;\r\n};\r\nconst leftShift = (i, j) => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);\r\n hi = hi << j & 1073741823 | lo >> 30 - j;\r\n lo = lo << j & 1073741823;\r\n return hi * 1073741824 + lo;\r\n};\r\nlet f = [1];\r\nfor (let i = 1;; i++) {\r\n f[i] = f[i - 1] * i;\r\n f[i] = leftShift(f[i], 10);\r\n f[i] = rightShift(f[i], 10);\r\n if (f[i] > 10 ** 12) {\r\n f.pop();\r\n break;\r\n }\r\n}\r\nconst cache = Array.from({\r\n length: f.length\r\n}, () => new Map());\r\nfunction solve(n) {\r\n const dfs = (n, r = f.length - 1) => {\r\n if (r < 0) return Infinity;\r\n if (cache[r].has(n)) return cache[r].get(n);\r\n if (n === 0) return 0;\r\n let res = Infinity;\r\n let t = n;\r\n let tmp = 0;\r\n while (t) {\r\n if (t & 1) tmp++;\r\n t = rightShift(t, 1);\r\n }\r\n for (let i = r; i >= 0; i--) {\r\n if (n < f[i]) continue;\r\n res = Math.min(res, dfs(n - f[i], i - 1) + 1);\r\n }\r\n res = Math.min(res, tmp);\r\n cache[r].set(n, res);\r\n return res;\r\n };\r\n return dfs(n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nlet f = [1];\r\nfor (let i = 1;; i++) {\r\n f[i] = f[i - 1] * i;\r\n if (f[i] > 10 ** 12) {\r\n f.pop();\r\n break;\r\n }\r\n}\r\nconst cache = Array.from({\r\n length: f.length\r\n}, () => new Map());\r\nfunction solve(n) {\r\n const next = (i, j) => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);else return lo >> j;\r\n lo >>= j;\r\n lo |= (hi & (1 << j) - 1) << 30 - j;\r\n hi >>= j;\r\n return hi * 1073741824 + lo;\r\n };\r\n const dfs = (n, r = f.length - 1) => {\r\n if (r < 0) return Infinity;\r\n if (cache[r].has(n)) return cache[r].get(n);\r\n if (n === 0) return 0;\r\n let res = Infinity;\r\n let t = n;\r\n let tmp = 0;\r\n while (t) {\r\n if (t & 1) tmp++;\r\n t = next(t, 1);\r\n }\r\n for (let i = r; i >= 0; i--) {\r\n if (n < f[i]) continue;\r\n res = Math.min(res, dfs(n - f[i], i - 1) + 1);\r\n }\r\n res = Math.min(res, tmp);\r\n cache[r].set(n, res);\r\n return res;\r\n };\r\n return dfs(n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nlet f = [1];\r\nfor (let i = 1;; i++) {\r\n f[i] = f[i - 1] * i;\r\n if (f[i] > 10 ** 12) {\r\n f.pop();\r\n break;\r\n }\r\n}\r\nconst cache = Array.from({\r\n length: f.length\r\n}, () => new Map());\r\nfunction solve(n) {\r\n const next = i => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);else return lo >> 1;\r\n lo >>= 1;\r\n if (hi & 1) lo |= 536870912;\r\n hi >>= 1;\r\n return hi * 1073741824 + lo;\r\n };\r\n const dfs = (n, r = f.length - 1) => {\r\n if (r < 0) return Infinity;\r\n if (cache[r].has(n)) return cache[r].get(n);\r\n if (n === 0) return 0;\r\n let res = Infinity;\r\n let t = n;\r\n let tmp = 0;\r\n while (t) {\r\n if (t & 1) tmp++;\r\n t = next(t);\r\n }\r\n for (let i = r; i >= 0; i--) {\r\n if (n < f[i]) continue;\r\n res = Math.min(res, dfs(n - f[i], i - 1) + 1);\r\n }\r\n res = Math.min(res, tmp);\r\n cache[r].set(n, res);\r\n return res;\r\n };\r\n return dfs(n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nlet f = [1];\r\nfor (let i = 1;; i++) {\r\n f[i] = f[i - 1] * i;\r\n if (f[i] > 10 ** 12) {\r\n f.pop();\r\n break;\r\n }\r\n}\r\nconst cache = Array.from({\r\n length: f.length\r\n}, () => new Map());\r\nfunction solve(n) {\r\n const next = (i, j) => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);else return lo >> j;\r\n lo >>= j;\r\n lo |= (hi & (1 << j) - 1) << 29 - j;\r\n hi >>= j;\r\n return hi * 1073741824 + lo;\r\n };\r\n const dfs = (n, r = f.length - 1) => {\r\n if (r < 0) return Infinity;\r\n if (cache[r].has(n)) return cache[r].get(n);\r\n if (n === 0) return 0;\r\n let res = Infinity;\r\n let t = n;\r\n let tmp = 0;\r\n while (t) {\r\n if (t & 1) tmp++;\r\n t = next(t, 1);\r\n }\r\n for (let i = r; i >= 0; i--) {\r\n if (n < f[i]) continue;\r\n res = Math.min(res, dfs(n - f[i], i - 1) + 1);\r\n }\r\n res = Math.min(res, tmp);\r\n cache[r].set(n, res);\r\n return res;\r\n };\r\n return dfs(n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nlet f = [1];\r\nfor (let i = 1;; i++) {\r\n f[i] = f[i - 1] * i;\r\n if (f[i] > 10 ** 12) {\r\n f.pop();\r\n break;\r\n }\r\n}\r\nconst cache = new Map();\r\nfunction solve(n) {\r\n const next = i => {\r\n let hi = 0,\r\n lo = i & 1073741823;\r\n if (i > lo) hi = Math.floor(i / 1073741824);else return lo >> 1;\r\n lo >>= 1;\r\n if (hi & 1) lo |= 536870912;\r\n hi >>= 1;\r\n return hi * 1073741824 + lo;\r\n };\r\n const dfs = (n, r = f.length - 1) => {\r\n if (cache.has(n)) return cache.get(n);\r\n if (n === 0) return 0;\r\n let res = Infinity;\r\n let t = n;\r\n let tmp = 0;\r\n while (t) {\r\n if (t & 1) tmp++;\r\n t = next(t);\r\n }\r\n for (let i = r; i >= 0; i--) {\r\n if (n < f[i]) continue;\r\n res = Math.min(res, dfs(n - f[i], i - 1) + 1);\r\n }\r\n res = Math.min(res, tmp);\r\n cache.set(n, res);\r\n return res;\r\n };\r\n return dfs(n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n let nums = [1];\r\n for (let i = 1;; i++) {\r\n nums[i] = nums[i - 1] * i;\r\n if (nums[i] > n) {\r\n nums.pop();\r\n break;\r\n }\r\n }\r\n for (let i = 1;; i++) {\r\n const num = 2 ** i;\r\n nums.push(num);\r\n if (num > n) {\r\n nums.pop();\r\n break;\r\n }\r\n }\r\n nums = [...new Set(nums)];\r\n nums.sort((a, b) => a - b);\r\n let res = 0;\r\n let r = nums.length - 1;\r\n while (n) {\r\n res++;\r\n let l = 0;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (nums[m] > n) {\r\n r = m - 1;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n n -= nums[r];\r\n r--;\r\n }\r\n if (n) return -1;\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nlet powers = [], factorials = [];\nconst precalc = ()=>{\n let num = 1;\n while (num<1e12){\n powers.push(num);\n num *= 2;\n }\n num = 6;\n for (let i=2; num<1e12; i++){\n factorials.push(num);\n num *= i;\n }\n l({powers, factorials})\n};\n\nconst calc = (n)=>{\n let bmax = 1<<15;\n let count1 = num=>{\n let cnt = 0;\n for (let i=0; i<50; i++){\n if (BigInt(1<{\n for (let i=0; i<14; i++){\n if (BigInt(1<=0){\n let t = count1(cnum)+count1(bmask);\n if (t {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nlet power_numbers;\nconst precalc = ()=>{\n let set = new Set();\n let num = 1;\n while (num<1e12){\n set.add(num);\n num *= 2;\n }\n num = 1;\n for (let i=2; num<1e12; i++){\n set.add(num);\n num *= i;\n }\n power_numbers = Array.from(set);\n power_numbers.sort((a, b)=>a-b)\n l(power_numbers)\n};\n\nlet cache = new Map();\nconst calc = (n)=>{\n let helper = (n, arr)=>{\n if (n==0)\n return 0;\n let K = n+';'+arr.join(',');\n if (cache.has(K)){\n return cache.get(K)\n }\n let min = Infinity;\n for (let i=arr.length; i>=0; i--){\n if (arr[i]<=n){\n let narr = arr.slice(0, i).concat(arr.slice(i+1));\n min = Math.min(min, 1+helper(n-arr[i], narr))\n if (min {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nlet power_numbers;\nconst precalc = ()=>{\n let set = new Set();\n let num = 1;\n while (num<1e12){\n set.add(num);\n num *= 2;\n }\n num = 1;\n for (let i=2; num<1e12; i++){\n set.add(num);\n num *= i;\n }\n power_numbers = Array.from(set);\n power_numbers.sort((a, b)=>a-b)\n};\n\nlet cache = new Map();\nconst calc = (n)=>{\n let helper = (n, arr)=>{\n if (n==0)\n return 0;\n let K = n+';'+arr.join(',');\n if (cache.has(K)){\n return cache.get(K)\n }\n let min = Infinity;\n for (let i=arr.length; i>=0; i--){\n if (arr[i]<=n){\n let narr = arr.slice(0, i).concat(arr.slice(i+1));\n min = Math.min(min, 1+helper(n-arr[i], narr))\n if (min arr.map(num => num - 1));\r\n {\r\n const cnt = new Array(n).fill(0);\r\n for (let [i, j] of a) {\r\n if (i === j) return 'NO';\r\n cnt[i]++;\r\n cnt[j]++;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (cnt[i] !== 2) return 'NO';\r\n }\r\n }\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [];\r\n let idx = 0;\r\n const add = (i, j) => {\r\n e[idx] = j, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n const map = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [i, [x, y]] of a.entries()) {\r\n map[x].push(i);\r\n map[y].push(i);\r\n }\r\n const uf = new UnionFind(n);\r\n for (let [i, j] of map) {\r\n add(i, j);\r\n add(j, i);\r\n uf.union(i, j);\r\n }\r\n let queue = [],\r\n vis = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n const root = uf.find(i);\r\n if (vis[root]) continue;\r\n vis[root] = 1;\r\n queue.push([root, 0]);\r\n }\r\n const res = [];\r\n vis = new Array(n);\r\n for (let [u, d] of queue) {\r\n vis[u] = 1;\r\n if (d === 0) res.push(u);\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (vis[v]) continue;\r\n vis[v] = 1;\r\n queue.push([v, d ^ 1]);\r\n }\r\n }\r\n const check = indexs => {\r\n const vis = new Array(n);\r\n for (let u of indexs) {\r\n const [i, j] = a[u];\r\n if (vis[i] || vis[j]) return false;\r\n vis[i] = 1;\r\n vis[j] = 1;\r\n }\r\n return true;\r\n };\r\n if (res.length === n / 2 && check(res)) {\r\n return 'YES';\r\n } else {\r\n return 'NO';\r\n }\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n this.p = [...new Array(n).keys()];\r\n this.find = this.find.bind(this);\r\n this.union = this.union.bind(this);\r\n this.isConnect = this.isConnect.bind(this);\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (p[i] !== i) {\r\n p[i] = p[p[i]];\r\n i = p[i];\r\n }\r\n return p[i];\r\n }\r\n union(i, j) {\r\n const {\r\n p,\r\n find\r\n } = this;\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n }\r\n isConnect(i, j) {\r\n const {\r\n find\r\n } = this;\r\n const ri = find(i),\r\n rj = find(j);\r\n return ri === rj;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\r\n l += n\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const map = {}\r\n for (let i = 0; i < arr.length; i++) {\r\n const [a, b] = arr[i]\r\n if (a === b) return 'NO'\r\n map[a] = map[a] || []\r\n map[a].push(i)\r\n map[b] = map[b] || []\r\n map[b].push(i)\r\n }\r\n const adj = {}\r\n for (let i = 0; i < arr.length; i++) {\r\n const [a, b] = arr[i]\r\n if (map[a].length > 2 || map[b].length > 2) return 'NO'\r\n map[a].forEach(j => {\r\n if (i === j) return\r\n adj[i] = adj[i] || []\r\n adj[i].push(j)\r\n adj[j] = adj[j] || []\r\n adj[j].push(i)\r\n })\r\n map[b].forEach(j => {\r\n if (i === j) return\r\n adj[i] = adj[i] || []\r\n adj[i].push(j)\r\n adj[j] = adj[j] || []\r\n adj[j].push(i)\r\n })\r\n }\r\n return bipartite(adj, n)[0] ? 'YES' : 'NO'\r\n}\r\nfunction bipartite(adj, n) {\r\n let bip = true;\r\n const s = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n s[i] = -1;\r\n }\r\n\r\n for (let i = 0; i < n; i++){\r\n if (s[i] != -1) continue;\r\n\r\n s[i] = 0;\r\n bip &= dfs(adj, i, s)\r\n if (!bip) return [bip, s]\r\n }\r\n return [bip, s];\r\n}\r\nfunction dfs(adj, r, s) {\r\n const stack = [[r, 0]]\r\n while (stack.length) {\r\n const [u, i] = stack[stack.length - 1]\r\n\r\n const nb = adj[u] || []\r\n if (i < nb.length) {\r\n stack[stack.length - 1][1]++\r\n const v = nb[i]\r\n if (s[v] == -1){\r\n s[v] = s[u] ^ 1;\r\n stack.push([v, 0]);\r\n } else if (s[u] === s[v]){\r\n return false\r\n }\r\n } else {\r\n stack.pop()\r\n }\r\n }\r\n return true\r\n}\r\n"}], "negative_code": [], "src_uid": "8717913513b019d3ef836176eafce7b1"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) arr.push(new Array(n).fill(0));\r\n for (let i = 0; i < m; i++) {\r\n let [r, c] = iInpArr();\r\n arr[r - 1][c - 1] = 1;\r\n }\r\n if(n===1){\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n const helper = (r, c) => {\r\n let j = 0;\r\n for (let j = 0; j < n; j++) {\r\n if (arr[j][c] === 1) return false;\r\n }\r\n return true;\r\n };\r\n let ans;\r\n for (let i = 0; i < n; i++) {\r\n ans = false;\r\n for (let j = 0; j < n; j++) {\r\n if (arr[i][j] === 1) {\r\n if (j === 0) ans = helper(i, j + 1);\r\n else if (j === n - 1) ans = helper(i, j - 1);\r\n else {\r\n ans = helper(i, j + 1) || helper(i, j - 1);\r\n }\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(\"YES\");\r\n break;\r\n }\r\n }\r\n if (ans === false) console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n inputs = readline().split(' ') ,\r\n n = inputs[0] , m = inputs[1] , positions = [];\r\n for(var j = 0 ; j < m ; ++j){\r\n var rookPosition = readline().split(' ');\r\n }\r\n n > m ? print(\"YES\") : print(\"NO\");\r\n }"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var input = readline().split(' ');\r\n var c = Number(input[0]); // chessboard size\r\n var r = Number(input[1]); // num of rooks\r\n \r\n var ansCond = c > r;\r\n for(; r > 0; r--) {\r\n readline();\r\n }\r\n \r\n print(ansCond ? 'YES' : 'NO');\r\n}"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction evaluateBoard(board)\r\n{\r\n for(let i=0;iparseInt(x));\r\n let n = nums[0]\r\n let m = nums[1]\r\n \r\n var board = Array(n)\r\n for(let a=0;aparseInt(x));\r\n let x= xy[0]-1\r\n let y= xy[1]-1\r\n board[x][y] = 1\r\n }\r\n\r\n var nextCase = false\r\n //console.log(\"board\" + board)\r\n for(let i=0; i parseInt(item));\n const testCase = {\n n,\n m,\n x: [],\n y: [],\n };\n for (let j = 0; j < m; j++) {\n index++;\n const [x, y] = input[index].split(\" \").map((item) => parseInt(item));\n testCase.x.push(x);\n testCase.y.push(y);\n }\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m, x, y } = testCase;\n\n let result = m < n ? \"YES\" : \"NO\";\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start(); \r\n});\r\n\r\nfunction start(){\r\n\tconst T = parseInt(lines[0])\r\n\tlet line = 1\r\n\tfor(let t = 1; t <= T; t++) {\r\n\t const n = parseInt(lines[line].trim().split(' ')[0], 10)\r\n\t const m = parseInt(lines[line++].trim().split(' ')[1], 10)\r\n\t for(let i = 0; i < m; i++) {\r\n\t line++\r\n\t }\r\n\t console.log(m >= n ? \"NO\" : \"YES\")\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, m, grid) {\r\n //print(`${n} ${m} ${grid.join(' ')}`);\r\n let rows = new Array(n).fill(0);\r\n let cols = new Array(n).fill(0);\r\n for(let i = 0; i < grid.length; i++) {\r\n rows[grid[i][0] - 1]++;\r\n cols[grid[i][1] - 1]++;\r\n }\r\n //zero one two\r\n let rowRes = [0,0,0];\r\n let colRes = [0,0,0];\r\n \r\n for(let i = 0; i < n; i++) {\r\n if(rows[i] <= 2) {\r\n rowRes[rows[i]]++;\r\n } else {\r\n print(\"NO\");\r\n return;\r\n }\r\n if(cols[i] <= 2) {\r\n colRes[cols[i]]++;\r\n } else {\r\n print(\"NO\");\r\n return;\r\n }\r\n }\r\n if(colRes[2] + rowRes[2] > 1) {\r\n print(\"NO\");\r\n return;\r\n }\r\n if(colRes[2] == 1 && colRes[0] == 0) {\r\n print(\"NO\");\r\n return;\r\n }\r\n if(rowRes[2] == 1 && rowRes[0] == 0) {\r\n print(\"NO\");\r\n return;\r\n }\r\n if(rowRes[1] == n || colRes[1] == n) {\r\n print(\"NO\");\r\n return;\r\n }\r\n print(\"YES\");\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = readline().trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n let m = n[1];\r\n let grid = [];\r\n for(let i = 0; i < m; i++) {\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n grid.push(x);\r\n }\r\n begin(n[0], m, grid);\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_m = readLine().split(' ').map(p => +p);\r\n let arr = new Array(n_m[1]);\r\n for(let j = 0; j < n_m[1]; j++){\r\n arr[j] = readLine().split(' ').map(p => +p);\r\n }\r\n let result = myFunc(n_m[0], n_m[1], arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, m, arr){\r\n\r\n let mapL = new Set();\r\n let mapC = new Set();\r\n\r\n\r\n for(let i = 0; i < m; i++){\r\n mapL.add(arr[i][0]);\r\n mapC.add(arr[i][1]);\r\n }\r\n\r\n if(mapL.size < n || mapC.size < n) return 'YES';\r\n\r\n return 'NO';\r\n\r\n\r\n}"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) { \r\n let nm = readline().split(' ').map( Number )\r\n let n = nm[0], m = nm[1]\r\n let pos = []\r\n while(m--) {\r\n pos.push( readline().split(' ').map( Number ) )\r\n }\r\n // let res = readline()\r\n // console.log( res, solve( nm, pos) )\r\n console.log( solve( nm, pos) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = ( nm, pos ) => {\r\n let n = nm[0], m = nm[1]\r\n \r\n return ( n > m ) ? 'YES' : 'NO' \r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, m] = rns(),\r\n a = [];\r\n for (let i = 0; i < m; i++) a[i] = rns().map(num => num - 1);\r\n const check = a => {\r\n const r = [],\r\n c = [];\r\n for (let [i, j] of a) {\r\n if (r[i] || c[j]) return false;\r\n r[i] = 1;\r\n c[j] = 1;\r\n }\r\n return true;\r\n };\r\n for (let [i, [r, c]] of a.entries()) {\r\n for (let x = 0; x < n; x++) {\r\n for (let y = 0; y < n; y++) {\r\n if (x === r && c === y) continue;\r\n a[i] = [x, y];\r\n if (check(a)) return 'YES';\r\n }\r\n }\r\n a[i] = [r, c];\r\n }\r\n return 'NO';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n inputs = readline().split(' ') ,\r\n n = inputs[0] , m = inputs[1] , positions = [];\r\n for(var j = 0 ; j < m ; ++j){\r\n var rookPosition = readline().split(' ');\r\n positions.push(...rookPosition);\r\n }\r\n positions = [...new Set(positions)];\r\n positions.length < n ? print(\"YES\") : print(\"NO\");\r\n }"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) arr.push(new Array(n).fill(0));\r\n for (let i = 0; i < m; i++) {\r\n let [r, c] = iInpArr();\r\n arr[r - 1][c - 1] = 1;\r\n }\r\n const helper = (r, c) => {\r\n let j = 0;\r\n for (let j = 0; j < n; j++) {\r\n if (arr[j][c] === 1) return false;\r\n }\r\n return true;\r\n };\r\n let ans;\r\n for (let i = 0; i < n; i++) {\r\n ans = false;\r\n for (let j = 0; j < n; j++) {\r\n if (arr[i][j] === 1) {\r\n if (j === 0) ans = helper(i, j + 1);\r\n else if (j === n - 1) ans = helper(i, j - 1);\r\n else {\r\n ans = helper(i, j + 1) || helper(i, j - 1);\r\n }\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(\"YES\");\r\n break;\r\n }\r\n }\r\n if (ans === false) console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction evaluateBoard(board)\r\n{\r\n for(let i=0;iparseInt(x));\r\n let n = nums[0]\r\n let m = nums[1]\r\n \r\n var board = Array(n)\r\n for(let a=0;aparseInt(x));\r\n let x= xy[0]-1\r\n let y= xy[1]-1\r\n board[x][y] = 1\r\n }\r\n\r\n var nextCase = false\r\n //console.log(\"board\" + board)\r\n for(let i=0; i1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let x = +readline();\n LT({x});\n // PROCESSING:\n if (x>1500)\n return 'YES';\n for (let i11=0; i11<150; i11++){\n for (let i111=0; i111<15; i111++){\n if (11*i11+111*i111===x)\n return 'YES'\n\n }\n\n }\n return 'NO'\n};\n \n", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/28/21 night\r\n\r\nconst MAX = 111111;\r\nlet dp;\r\nconst solve = (x) => {\r\n pr(x >= 10000 ? 'YES' : (dp[x] ? 'YES' : 'NO'));\r\n};\r\n\r\nconst prepare = () => {\r\n let n = MAX + 1;\r\n dp = Array(n).fill(0);\r\n dp[0] = 1;\r\n for (let i = 11; i <= MAX; i = i * 10 + 1) {\r\n for (let j = 0; j < n - i; j++) {\r\n dp[i + j] |= dp[j];\r\n }\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n prepare();\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/**\r\n* author: Mohamed Abo Okail\r\n* created: O4/O6/2O21\r\n**/\r\n\r\nvar t = parseInt(readline());\r\n \r\nwhile(t--) {\r\n var x = parseInt(readline())\r\n if(111 * (x % 11) <= x) {\r\n print(\"YES\");\r\n }\r\n else {\r\n print(\"NO\");\r\n }\r\n} "}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/28/21 night\r\n\r\nconst solve = (x) => {\r\n pr(x >= 111 * (x % 11) ? 'YES' : 'NO');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\n\r\nconst solve = (x) => {\r\n if (x == 1) return pr('YES');\r\n if (x == 10) return pr('NO');\r\n while ((x + '').length > 1) {\r\n let max = getMax(x);\r\n if (max == 1) break;\r\n x %= max;\r\n // pr(x, max);\r\n if (x == 0) return pr('YES');\r\n }\r\n // pr(x);\r\n pr('NO');\r\n};\r\n\r\nconst getMax = (x) => {\r\n let s = x + '';\r\n let n = s.length;\r\n let max = '1'.repeat(n - 1);\r\n if (x >= Number(max + '1')) {\r\n max += '1';\r\n }\r\n return max - '0';\r\n};\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n// pr(3578 % 1111)"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/28/21 morning\r\n * https://codeforces.com/contest/1526/problem/A\r\n */\r\n\r\nconst solve = (x) => {\r\n while((x + '').length > 1) {\r\n let max = getMax(x);\r\n x %= max;\r\n if (x == 0) return pr('YES');\r\n }\r\n // pr(x);\r\n pr('NO');\r\n};\r\n\r\nconst getMax = (x) => {\r\n let s = x + '';\r\n let n = s.length;\r\n let max = '1'.repeat(n - 1);\r\n if (x >= Number(max + '1')) {\r\n max += '1';\r\n }\r\n return max - '0';\r\n};\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let x = readline();\n LT({x});\n // PROCESSING:\n return x[x.length-1]===x[x.length-2] ? 'YES' : 'NO'\n if (+x<11)\n return 'NO'\n for (let i=x.length-2; i>=0; i--){\n if (x[i]>x[i+1])\n return 'NO'\n }\n return 'YES';\n let ans = 0;\n let ones = [];\n let d = 11;\n while (d<1e9){\n ones.push(d);\n d = d*10+1;\n }\n let flag = true;\n while (flag){\n for (let i=0; i0 && r>=0){\n while (x>=ones[r]){\n x -= ones[r]\n };\n r--;\n }\n return x==0 ? 'YES' : 'NO';\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [x] = ra();\n LT({x});\n // PROCESSING:\n let ans = 0;\n let ones = [];\n let d = 11;\n while (d<1e9){\n ones.push(d);\n d = d*10+1;\n }\n let r = ones.length-1;\n while (x>0 && r>=0){\n while (x>=ones[r]){\n x -= ones[r]\n };\n r--;\n }\n return x==0 ? 'YES' : 'NO';\n};\n \n"}], "src_uid": "e5e937f080b20eaec5f12f1784ae6427"} {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n - 1; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const d = dis(i, j);\r\n edges.push([i, j, d]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const st = [];\r\n const check = arr => {\r\n if (arr.length > 4) return false;\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (st[arr[i]]) return false;\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (st[arr[j]]) return false;\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [];\r\n for (let i = 0, j = 0; i < edges.length; i = ++j) {\r\n while (j + 1 < edges.length && edges[i][2] === edges[j + 1][2]) {\r\n j++;\r\n }\r\n const uf = new UnionFind(n);\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n uf.union(u, v);\r\n }\r\n const groups = [...uf.group().values()];\r\n pos.push(...groups.filter(check));\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n st[u] = 1;\r\n st[v] = 1;\r\n }\r\n }\r\n let p2 = 0,\r\n p3 = 0,\r\n p4 = 0;\r\n for (let arr of pos) {\r\n if (arr.length === 2) p2++;else if (arr.length === 3) p3++;else p4++;\r\n }\r\n let res = 0;\r\n const ff = [1n];\r\n for (let i = 1; i <= n; i++) {\r\n ff[i] = ff[i - 1] * BigInt(i);\r\n }\r\n [0, 0, pos.filter(arr => arr.length === 2).length, pos.filter(arr => arr.length === 3).length, pos.filter(arr => arr.length === 4).length];\r\n const c = (i, n) => mul(f[n], mul(power(f[i], MOD - 2), power(f[n - i], MOD - 2)));\r\n for (let i = 0; i <= p2; i++) {\r\n for (let j = 0; j <= p3; j++) {\r\n for (let k = 0; k <= p4; k++) {\r\n const N = n - i - j * 2 - k * 3;\r\n res = mod(res + mul(f[N], c(i, p2), c(j, p3), c(k, p4), c(N, n)));\r\n }\r\n }\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(...args) {\r\n if (args.length === 1) return args[0];\r\n if (args.length > 2) return mul(args[0], mul(...args.slice(1)));\r\n const [a, b] = args;\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n _defineProperty(this, \"vis\", []);\r\n this.n = n;\r\n this.p = [...new Array(n).keys()];\r\n }\r\n union(i, j) {\r\n this.vis[i] = this.vis[j] = 1;\r\n const [rooti, rootj] = [this.find(i), this.find(j)];\r\n if (rooti === rootj) return;\r\n this.p[rootj] = rooti;\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n group() {\r\n const groups = new Map();\r\n for (let i = 0; i < this.n; i++) {\r\n var _groups$get;\r\n if (!this.vis[i]) continue;\r\n const root = this.find(i);\r\n if (!groups.has(root)) groups.set(root, []);\r\n (_groups$get = groups.get(root)) === null || _groups$get === void 0 ? void 0 : _groups$get.push(i);\r\n }\r\n return groups;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n", "positive_code": [{"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\n\r\nconst dn = 998244353n;\r\nconst add = (x, y) => Number((BigInt(x) + BigInt(y)) % dn);\r\nconst mul = (x, y) => Number((BigInt(x) * BigInt(y)) % dn);\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nclass Ans {\r\n p = [];\r\n points = [];\r\n constructor(n) {\r\n this.p[n] = [1];\r\n for (var j = 0; j < n; j++) {\r\n this.p[n][j + 1] = mul(this.p[n][j], (n - j));\r\n }\r\n }\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateShortest() {\r\n for (let curr in this.points) {\r\n let distance = [];\r\n const p1 = this.points[curr];\r\n let min = Infinity;\r\n for (let i in this.points) {\r\n if (i == curr)\r\n continue;\r\n const p2 = this.points[i];\r\n distance[i] = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\r\n if (distance[i] < min)\r\n min = distance[i];\r\n }\r\n distance[curr] = min;\r\n p1.shortest = distance.map((e, i) => e === min ? i : \"\").filter(String);\r\n }\r\n }\r\n haveGroup(p1 = new Point()) {//n**2\r\n p1.haveGroup = true;\r\n for (let b of p1.shortest) {\r\n const p2 = this.points[b];\r\n if (p1.shortest.length != p2.shortest.length) {\r\n p1.haveGroup = false;\r\n return;\r\n }\r\n for (let c in p2.shortest)\r\n if (p1.shortest[c] != p2.shortest[c]) {\r\n p1.haveGroup = false;\r\n return;\r\n }\r\n }\r\n }\r\n solve() {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {//n**3\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n this.haveGroup(p1);\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length - 1);\r\n }\r\n }\r\n const ways = (ng) => this.waysToGroups(this.groups.length - 1, ng);\r\n let sol = 0;\r\n for (let i = 1; i <= n; i++) {\r\n sol = add(sol, mul(ways(i), this.p[n][i]));\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n const N = this.points.length;\r\n if (i == -1) {\r\n if (N == pn)\r\n return 1;\r\n else\r\n return 0;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = 0;\r\n if (pn < N)\r\n c2 = this.waysToGroups(i - 1, pn + (this.groups[i]));\r\n return this.waysToGroups_db[i][pn] = add(c1, c2);\r\n }\r\n}\r\n(async () => {\r\n let t = parseInt(await read());\r\n let nn = t;\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n - 1; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const d = dis(i, j);\r\n edges.push([i, j, d]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const st = [];\r\n const check = arr => {\r\n if (arr.length > 4) return false;\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (st[arr[i]]) return false;\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (st[arr[j]]) return false;\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [];\r\n for (let i = 0, j = 0; i < edges.length; i = ++j) {\r\n while (j + 1 < edges.length && edges[i][2] === edges[j + 1][2]) {\r\n j++;\r\n }\r\n const uf = new UnionFind(n);\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n uf.union(u, v);\r\n }\r\n const groups = [...uf.group().values()];\r\n pos.push(...groups.filter(check));\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n st[u] = 1;\r\n st[v] = 1;\r\n }\r\n }\r\n let p2 = 0,\r\n p3 = 0,\r\n p4 = 0;\r\n for (let arr of pos) {\r\n if (arr.length === 2) p2++;else if (arr.length === 3) p3++;else p4++;\r\n }\r\n let res = 0;\r\n const ff = [1n];\r\n for (let i = 1; i <= n; i++) {\r\n ff[i] = ff[i - 1] * BigInt(i);\r\n }\r\n [0, 0, pos.filter(arr => arr.length === 2).length, pos.filter(arr => arr.length === 3).length, pos.filter(arr => arr.length === 4).length];\r\n const c = (i, n) => mul(f[n], mul(power(f[i], MOD - 2), power(f[n - i], MOD - 2)));\r\n for (let i = 0; i <= p2; i++) {\r\n for (let j = 0; j <= p3; j++) {\r\n for (let k = 0; k <= p4; k++) {\r\n const N = n - i - j * 2 - j * 3;\r\n res = mod(res + mul(mul(mul(f[N], c(i, p2)), mul(c(j, p3), c(k, p4))), c(N, n)));\r\n }\r\n }\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n _defineProperty(this, \"vis\", []);\r\n this.n = n;\r\n this.p = [...new Array(n).keys()];\r\n }\r\n union(i, j) {\r\n this.vis[i] = this.vis[j] = 1;\r\n const [rooti, rootj] = [this.find(i), this.find(j)];\r\n if (rooti === rootj) return;\r\n this.p[rootj] = rooti;\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n group() {\r\n const groups = new Map();\r\n for (let i = 0; i < this.n; i++) {\r\n var _groups$get;\r\n if (!this.vis[i]) continue;\r\n const root = this.find(i);\r\n if (!groups.has(root)) groups.set(root, []);\r\n (_groups$get = groups.get(root)) === null || _groups$get === void 0 ? void 0 : _groups$get.push(i);\r\n }\r\n return groups;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n - 1; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const d = dis(i, j);\r\n edges.push([i, j, d]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const st = [];\r\n const check = arr => {\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (st[arr[i]]) return false;\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (st[arr[j]]) return false;\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [];\r\n for (let i = 0, j = 0; i < edges.length; i = ++j) {\r\n while (j + 1 < edges.length && edges[i][2] === edges[j + 1][2]) {\r\n j++;\r\n }\r\n const uf = new UnionFind(n);\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n uf.union(u, v);\r\n }\r\n const groups = [...uf.group().values()];\r\n pos.push(...groups.filter(check));\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n st[u] = 1;\r\n st[v] = 1;\r\n }\r\n }\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n], power(f[n - n1], MOD - 2)));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n _defineProperty(this, \"vis\", []);\r\n this.n = n;\r\n this.p = [...new Array(n).keys()];\r\n }\r\n union(i, j) {\r\n this.vis[i] = this.vis[j] = 1;\r\n const [rooti, rootj] = [this.find(i), this.find(j)];\r\n if (rooti === rootj) return;\r\n this.p[rootj] = rooti;\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n group() {\r\n const groups = new Map();\r\n for (let i = 0; i < this.n; i++) {\r\n var _groups$get;\r\n if (!this.vis[i]) continue;\r\n const root = this.find(i);\r\n if (!groups.has(root)) groups.set(root, []);\r\n (_groups$get = groups.get(root)) === null || _groups$get === void 0 ? void 0 : _groups$get.push(i);\r\n }\r\n return groups;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n - 1; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const d = dis(i, j);\r\n edges.push([i, j, d]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const st = [];\r\n const check = arr => {\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (st[arr[i]]) return false;\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (st[arr[j]]) return false;\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [];\r\n for (let i = 0, j = 0; i < edges.length; i = ++j) {\r\n while (j + 1 < edges.length && edges[i][2] === edges[j][2]) {\r\n j++;\r\n }\r\n const uf = new UnionFind(n);\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n if (st[u] || st[v]) continue;\r\n uf.union(u, v);\r\n }\r\n const groups = [...uf.group().values()];\r\n pos.push(...groups.filter(check));\r\n for (let k = i; k <= j; k++) {\r\n const [u, v] = edges[k];\r\n st[u] = 1;\r\n st[v] = 1;\r\n }\r\n }\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n], power(f[n - n1], MOD - 2)));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n _defineProperty(this, \"vis\", []);\r\n this.n = n;\r\n this.p = [...new Array(n).keys()];\r\n }\r\n union(i, j) {\r\n this.vis[i] = this.vis[j] = 1;\r\n const [rooti, rootj] = [this.find(i), this.find(j)];\r\n if (rooti === rootj) return;\r\n this.p[rootj] = rooti;\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n group() {\r\n const groups = new Map();\r\n for (let i = 0; i < this.n; i++) {\r\n var _groups$get;\r\n if (!this.vis[i]) continue;\r\n const root = this.find(i);\r\n if (!groups.has(root)) groups.set(root, []);\r\n (_groups$get = groups.get(root)) === null || _groups$get === void 0 ? void 0 : _groups$get.push(i);\r\n }\r\n return groups;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = Array.from({\r\n length: n\r\n }, () => []);\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n - 1; i++) {\r\n let min = -1;\r\n for (let j = i + 1; j < n; j++) {\r\n const d = dis(i, j);\r\n if (min === -1 || min > d) {\r\n min = d;\r\n edges[i] = [j];\r\n } else if (min === d) {\r\n edges[i].push(j);\r\n }\r\n }\r\n edges[i] = [min, ...edges[i], i];\r\n }\r\n edges.sort((a, b) => a[0] - b[0]);\r\n const st = [];\r\n const check = arr => {\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (st[arr[i]]) return false;\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (st[arr[j]]) return false;\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [];\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n while (j + 1 < n && edges[j + 1][0] === edges[i][0]) j++;\r\n const uf = new UnionFind(n);\r\n for (let k = i; k <= j; k++) {\r\n for (let l = 2; l < edges[k].length; l++) {\r\n uf.union(edges[k][l], edges[k][l - 1]);\r\n }\r\n }\r\n const groups = [...uf.group().values()];\r\n pos.push(...groups.filter(check));\r\n for (let arr of groups) {\r\n for (let j of arr) {\r\n st[j] = 1;\r\n }\r\n }\r\n }\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n1], mul(f[n], mul(power(f[n - n1], MOD - 2), power(f[n1], MOD - 2)))));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n _defineProperty(this, \"vis\", []);\r\n this.n = n;\r\n this.p = [...new Array(n).keys()];\r\n }\r\n union(i, j) {\r\n this.vis[i] = this.vis[j] = 1;\r\n const [rooti, rootj] = [this.find(i), this.find(j)];\r\n if (rooti === rootj) return;\r\n this.p[rootj] = rooti;\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n group() {\r\n const groups = new Map();\r\n for (let i = 0; i < this.n; i++) {\r\n var _groups$get;\r\n if (!this.vis[i]) continue;\r\n const root = this.find(i);\r\n if (!groups.has(root)) groups.set(root, []);\r\n (_groups$get = groups.get(root)) === null || _groups$get === void 0 ? void 0 : _groups$get.push(i);\r\n }\r\n return groups;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n edges.push([i, j, dis(i, j)]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const min = edges[0][2];\r\n const p = new Array(n).fill(-1);\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let [i, j, d] of edges) {\r\n if (d > min) break;\r\n if (p[i] === -1) p[i] = i;\r\n if (p[j] === -1) p[j] = j;\r\n union(i, j);\r\n }\r\n const group = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _group$get;\r\n if (p[i] === -1) continue;\r\n const root = find(i);\r\n if (!group.has(root)) group.set(root, []);\r\n (_group$get = group.get(root)) === null || _group$get === void 0 ? void 0 : _group$get.push(i);\r\n }\r\n const check = arr => {\r\n if (arr.length === 2) return true;\r\n let t = -1;\r\n for (let i = 0; i < arr.length; i++) {\r\n for (let j = i + 1; j < arr.length; j++) {\r\n if (t == -1) t = dis(arr[i], arr[j]);else if (t !== dis(arr[i], arr[j])) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const pos = [...group.values()].filter(check);\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n1], mul(f[n], mul(power(f[n - n1], MOD - 2), power(f[n1], MOD - 2)))));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n edges.push([i, j, dis(i, j)]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const min = edges[0][2];\r\n const p = new Array(n).fill(-1);\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let [i, j, d] of edges) {\r\n if (d > min) break;\r\n if (p[i] === -1) p[i] = i;\r\n if (p[j] === -1) p[j] = j;\r\n union(i, j);\r\n }\r\n const group = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _group$get;\r\n if (p[i] === -1) continue;\r\n const root = find(i);\r\n if (!group.has(root)) group.set(root, []);\r\n (_group$get = group.get(root)) === null || _group$get === void 0 ? void 0 : _group$get.push(i);\r\n }\r\n const check = arr => {\r\n if (arr.length > 3) return false;\r\n if (arr.length === 2) return true;\r\n const [a, b, c] = arr;\r\n return dis(a, b) === dis(b, c) && dis(a, b) === dis(a, c) && dis(b, c) === dis(a, c);\r\n };\r\n const pos = [...group.values()].filter(check);\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n1], mul(f[n], mul(power(f[n - n1], MOD - 2), power(f[n1], MOD - 2)))));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n edges.push([i, j, dis(i, j)]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const min = edges[0][2];\r\n const p = new Array(n).fill(-1);\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let [i, j, d] of edges) {\r\n if (d > min) break;\r\n if (p[i] === -1) p[i] = i;\r\n if (p[j] === -1) p[j] = j;\r\n union(i, j);\r\n }\r\n const group = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _group$get;\r\n if (p[i] === -1) continue;\r\n const root = find(i);\r\n if (!group.has(root)) group.set(root, []);\r\n (_group$get = group.get(root)) === null || _group$get === void 0 ? void 0 : _group$get.push(i);\r\n }\r\n const check = arr => {\r\n if (arr.length > 3) return false;\r\n if (arr.length === 2) return true;\r\n const [a, b, c] = arr;\r\n return dis(a, b) === dis(b, c) && dis(a, b) === dis(a, c);\r\n };\r\n const pos = [...group.values()].filter(check);\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res = mod(res + mul(f[n1], mul(f[n], mul(power(f[n - n1], MOD - 2), power(f[n1], MOD - 2)))));\r\n }\r\n return mod(res);\r\n}\r\nconst mod = num => (num % MOD + MOD) % MOD;\r\nconst cache = new Map();\r\nfunction power(a, b) {\r\n var _cache$get;\r\n let res = (_cache$get = cache.get(a)) === null || _cache$get === void 0 ? void 0 : _cache$get.get(b);\r\n if (res) return res;\r\n res = 1;\r\n let a1 = a,\r\n b1 = b;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n if (cache.has(a1)) {\r\n cache.get(a1).set(b1, res);\r\n } else {\r\n cache.set(a1, new Map([[b1, res]]));\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n edges.push([i, j, dis(i, j)]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const min = edges[0][2];\r\n const p = new Array(n).fill(-1);\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let [i, j, d] of edges) {\r\n if (d > min) break;\r\n if (p[i] === -1) p[i] = i;\r\n if (p[j] === -1) p[j] = j;\r\n union(i, j);\r\n }\r\n const group = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _group$get;\r\n if (p[i] === -1) continue;\r\n const root = find(i);\r\n if (!group.has(root)) group.set(root, []);\r\n (_group$get = group.get(root)) === null || _group$get === void 0 ? void 0 : _group$get.push(i);\r\n }\r\n const check = arr => {\r\n if (arr.length > 3) return false;\r\n if (arr.length === 2) return true;\r\n const [a, b, c] = arr;\r\n return dis(a, b) === dis(b, c) && dis(a, b) === dis(a, c);\r\n };\r\n const pos = [...group.values()].filter(check);\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0,\r\n len = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) {\r\n count += pos[j].length;\r\n len++;\r\n }\r\n }\r\n const n1 = n - count + len;\r\n res += mul(f[n1], mul(f[n], mul(power(f[n - n1], MOD - 2), power(f[n1], MOD - 2))));\r\n }\r\n return res;\r\n}\r\nconst cache = new Map();\r\nfunction power(a, b) {\r\n var _cache$get;\r\n let res = (_cache$get = cache.get(a)) === null || _cache$get === void 0 ? void 0 : _cache$get.get(b);\r\n if (res) return res;\r\n res = 1;\r\n let a1 = a,\r\n b1 = b;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n if (cache.has(a1)) {\r\n cache.get(a1).set(b1, res);\r\n } else {\r\n cache.set(a1, new Map([[b1, res]]));\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst MOD = 998244353;\r\nasync function solve(n, a) {\r\n const f = [1];\r\n for (let i = 1; i <= n; i++) {\r\n f[i] = mul(f[i - 1], i);\r\n }\r\n const edges = [];\r\n const dis = (i, j) => Math.abs(a[i][0] - a[j][0]) + Math.abs(a[i][1] - a[j][1]);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n edges.push([i, j, dis(i, j)]);\r\n }\r\n }\r\n edges.sort((a, b) => a[2] - b[2]);\r\n const min = edges[0][2];\r\n const p = new Array(n).fill(-1);\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let [i, j, d] of edges) {\r\n if (d > min) break;\r\n if (p[i] === -1) p[i] = i;\r\n if (p[j] === -1) p[j] = j;\r\n union(i, j);\r\n }\r\n const group = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _group$get;\r\n if (p[i] === -1) continue;\r\n const root = find(i);\r\n if (!group.has(root)) group.set(root, []);\r\n (_group$get = group.get(root)) === null || _group$get === void 0 ? void 0 : _group$get.push(i);\r\n }\r\n const check = arr => {\r\n if (arr.length > 3) return false;\r\n if (arr.length === 2) return true;\r\n const [a, b, c] = arr;\r\n return dis(a, b) === dis(b, c) && dis(a, b) === dis(a, c);\r\n };\r\n const pos = [...group.values()].filter(check);\r\n let N = pos.length;\r\n let res = f[n];\r\n for (let i = 1; i < 1 << N; i++) {\r\n let count = 0;\r\n for (let j = 0; j < N; j++) {\r\n if (i & 1 << j) count++;\r\n }\r\n res += mul(f[n - count], mul(f[n], mul(power(f[n - count], MOD - 2), power(f[count], MOD - 2))));\r\n }\r\n return res;\r\n}\r\nconst cache = new Map();\r\nfunction power(a, b) {\r\n var _cache$get;\r\n let res = (_cache$get = cache.get(a)) === null || _cache$get === void 0 ? void 0 : _cache$get.get(b);\r\n if (res) return res;\r\n res = 1;\r\n let a1 = a,\r\n b1 = b;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n if (cache.has(a1)) {\r\n cache.get(a1).set(b1, res);\r\n } else {\r\n cache.set(a1, new Map([[b1, res]]));\r\n }\r\n return res;\r\n}\r\nfunction mul(a, b) {\r\n return ((a >> 16) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nconst dn = 998244353;\r\nclass Ans {\r\n p = [];\r\n points = [];\r\n constructor(n) {\r\n this.p[n] = [1];\r\n for (var j = 0; j < n; j++) {\r\n this.p[n][j+1] = (this.p[n][j]*(n-j)) % dn;\r\n }\r\n }\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateShortest(){\r\n for(let curr in this.points ){\r\n let distance=[];\r\n const p1=this.points[curr];\r\n let min=Infinity;\r\n for (let i in this.points ) {\r\n if(i==curr)\r\n continue;\r\n const p2=this.points[i];\r\n distance[i] = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\r\n if(distance[i] e === min ? i : \"\").filter(String);\r\n }\r\n }\r\n haveGroup(p1= new Point()){//n**2\r\n p1.haveGroup = true;\r\n for(let b of p1.shortest){\r\n const p2 = this.points[b];\r\n for(let c in p2.shortest)\r\n if (p1.shortest[c]!=p2.shortest[c]) {\r\n p1.haveGroup = false;\r\n return;\r\n }\r\n }\r\n }\r\n solve() {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {//n**3\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n this.haveGroup(p1);\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length-1);\r\n }\r\n }\r\n const ways = (ng)=>this.waysToGroups(this.groups.length-1,ng);\r\n let sol =0;\r\n for (let i = 1; i <= n; i++) {\r\n sol +=( ways(i)*this.p[n][i])% dn;\r\n sol %= dn;\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n const N=this.points.length;\r\n if (i == -1) {\r\n if(N==pn)\r\n return 1;\r\n else\r\n return 0;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = 0;\r\n if(pn {\r\n let t = parseInt(await read());\r\n let nn=t;\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateShortest();\r\n if(nn==100&&ans.points[0].x==10)//hack\r\n ans.points.slice(52).forEach(p=>{\r\n print(p.x +\" \"+p.y+\"|\");\r\n })\r\n else \r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n \r\n \r\n "}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nconst dn = 998244353;\r\nclass Ans {\r\n p = [];\r\n points = [];\r\n constructor(n) {\r\n this.p[n] = [1];\r\n for (var j = 0; j < n; j++) {\r\n this.p[n][j+1] = (this.p[n][j]*(n-j)) % dn;\r\n }\r\n }\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateShortest(){\r\n for(let curr in this.points ){\r\n let distance=[];\r\n const p1=this.points[curr];\r\n let min=Infinity;\r\n for (let i in this.points ) {\r\n if(i==curr)\r\n continue;\r\n const p2=this.points[i];\r\n distance[i] = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\r\n if(distance[i] e === min ? i : \"\").filter(String);\r\n }\r\n }\r\n solve() {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n p1.haveGroup = true;\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n if (p2.shortest.toString() != p1.shortest.toString()) {\r\n p1.haveGroup = false;\r\n }\r\n });\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length-1);\r\n }\r\n }\r\n const ways = (ng)=>this.waysToGroups(this.groups.length-1,ng);\r\n let sol =0;\r\n for (let i = 1; i <= n; i++) {\r\n sol +=( ways(i)*this.p[n][i])% dn;\r\n sol %= dn;\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n const N=this.points.length;\r\n if (i == -1) {\r\n if(N==pn)\r\n return 1;\r\n else\r\n return 0;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = 0;\r\n if(pn {\r\n let t = parseInt(await read());\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n \r\n \r\n "}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nconst dn = 998244353;\r\nclass Ans {\r\n p = [];\r\n points = [];\r\n constructor(n) {\r\n this.p[n] = [1];\r\n for (var j = 0; j < n; j++) {\r\n this.p[n][j+1] = (this.p[n][j]*(n-j)) % dn;\r\n }\r\n }\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateShortest(){\r\n for(let curr in this.points ){\r\n let distance=[];\r\n const p1=this.points[curr];\r\n let min=Infinity;\r\n for (let i in this.points ) {\r\n if(i==curr)\r\n continue;\r\n const p2=this.points[i];\r\n distance[i] = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\r\n if(distance[i] e === min ? i : \"\").filter(String);\r\n }\r\n }\r\n solve() {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n p1.haveGroup = true;\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n if (p2.shortest.toString() != p1.shortest.toString()) {\r\n p1.haveGroup = false;\r\n }\r\n });\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length);\r\n }\r\n }\r\n const ways=this.waysToGroups(this.groups.length-1,n)\r\n let sol =0;\r\n for (let i in ways) {\r\n sol +=( ways[i]*this.p[n][i])% dn;\r\n sol %= dn;\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n let ways=[];\r\n const N=this.points.length;\r\n if (i == -1) {\r\n for(let a=0;a<=N;a++)\r\n if(a==pn)\r\n ways[a]=1;\r\n else\r\n ways[a]=0;\r\n return ways;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = this.waysToGroups(i - 1, pn - (this.groups[i] - 1));\r\n for(let a=1;a<=N;a++)\r\n ways[a]=(c1[a]+c2[a])%dn;\r\n return this.waysToGroups_db[i][pn]=ways;\r\n }\r\n}\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nconst dn = 998244353;\r\nfunction min(a = []) {\r\n let min = [0];\r\n let me = -1;\r\n for (let i = 0; i < a.length; i++) {\r\n const e = a[i];\r\n const minValue = a[min[0]];\r\n if (e == Infinity) {\r\n me = i;\r\n min.push(me);\r\n }\r\n else if (e == minValue) {\r\n if (i != 0)\r\n min.push(i);\r\n }\r\n else if (e < minValue) {\r\n min = []\r\n if (me != -1) {\r\n min.push(me);\r\n a[me] = e;\r\n }\r\n min.push(i);\r\n }\r\n }\r\n return min;\r\n}\r\nclass Ans {\r\n //f = [];\r\n p = [];\r\n points = [];\r\n distance;\r\n // Ngroup=[0,0,0,0,0,0];\r\n constructor(n) {\r\n // this.f[0] = 1;\r\n // for (var i = 1; i <= n; i++)\r\n // this.f[i] = (this.f[i - 1] * i) % dn;\r\n // this.p[0] = [1];\r\n // for (var i = 1; i <= n; i++) {\r\n this.p[n] = [1];\r\n for (var j = 0; j < n; j++) {\r\n this.p[n][j+1] = (this.p[n][j]*(n-j)) % dn;\r\n }\r\n // }\r\n }\r\n //p = (n, m) => (this.f[n] / this.f[n - m]) % dn;\r\n c = (n, m) => (this.f[n] / (this.f[m] * this.f[n - m])) % dn;\r\n f = (n) => this.p[n][n];\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateDistance(){\r\n let curr = 0\r\n this.distance = [];\r\n this.points.forEach(p => {\r\n this.distance.push([]);\r\n for (var i = 0; i < curr; i++) {\r\n this.distance[curr].push(this.distance[i][curr]);\r\n }\r\n this.distance[curr].push(Infinity);\r\n for (var i = curr + 1; i < this.points.length; i++) {\r\n let dis = Math.abs(p.x - this.points[i].x) + Math.abs(p.y - this.points[i].y);\r\n this.distance[curr].push(dis);\r\n }\r\n curr++;\r\n })\r\n }\r\n calculateShortest() {\r\n for (let i = 0; i < this.points.length; i++)\r\n this.points[i].shortest = min(this.distance[i]);\r\n }\r\n solve() {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n p1.haveGroup = true;\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n if (p2.shortest.toString() != p1.shortest.toString()) {\r\n p1.haveGroup = false;\r\n }\r\n });\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length);\r\n }\r\n }\r\n const ways=this.waysToGroups(this.groups.length-1,n)\r\n let sol =0;\r\n for (let i in ways) {\r\n sol +=( ways[i]*this.p[n][i])% dn;\r\n sol %= dn;\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n let ways=[];\r\n const N=this.points.length;\r\n if (i == -1) {\r\n for(let a=0;a<=N;a++)\r\n if(a==pn)\r\n ways[a]=1;\r\n else\r\n ways[a]=0;\r\n return ways;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = this.waysToGroups(i - 1, pn - (this.groups[i] - 1));\r\n for(let a=1;a<=N;a++)\r\n ways[a]=(c1[a]+c2[a])%dn;\r\n return this.waysToGroups_db[i][pn]=ways;\r\n }\r\n}\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateDistance();\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\ndelay = (ms) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = async () => await scaner.read();\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest = [];\r\n haveGroup = false;\r\n}\r\nconst dn = 998244353;\r\nfunction min(a = []) {\r\n let min = [0];\r\n let me = -1;\r\n for (let i = 0; i < a.length; i++) {\r\n const e = a[i];\r\n const minValue = a[min[0]];\r\n if (e == Infinity) {\r\n me = i;\r\n min.push(me);\r\n }\r\n else if (e == minValue) {\r\n if (i != 0)\r\n min.push(i);\r\n }\r\n else if (e < minValue) {\r\n min = []\r\n if (me != -1) {\r\n min.push(me);\r\n a[me] = e;\r\n }\r\n min.push(i);\r\n }\r\n }\r\n return min;\r\n}\r\nclass Ans {\r\n //f = [];\r\n p = [];\r\n points = [];\r\n distance;\r\n // Ngroup=[0,0,0,0,0,0];\r\n constructor(n) {\r\n // this.f[0] = 1;\r\n // for (var i = 1; i <= n; i++)\r\n // this.f[i] = (this.f[i - 1] * i) % dn;\r\n this.p[0] = [1];\r\n for (var i = 1; i <= n; i++) {\r\n this.p[i] = [1];\r\n for (var j = 1; j <= i; j++) {\r\n this.p[i][j] = (i * this.p[i - 1][j - 1]) % dn;\r\n }\r\n }\r\n }\r\n //p = (n, m) => (this.f[n] / this.f[n - m]) % dn;\r\n c = (n, m) => (this.f[n] / (this.f[m] * this.f[n - m])) % dn;\r\n f = (n) => this.p[n][n];\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateDistance = () => {\r\n let curr = 0\r\n this.distance = [];\r\n this.points.forEach(p => {\r\n this.distance.push([]);\r\n for (var i = 0; i < curr; i++) {\r\n this.distance[curr].push(this.distance[i][curr]);\r\n }\r\n this.distance[curr].push(Infinity);\r\n for (var i = curr + 1; i < this.points.length; i++) {\r\n let dis = Math.abs(p.x - this.points[i].x) + Math.abs(p.y - this.points[i].y);\r\n this.distance[curr].push(dis);\r\n }\r\n curr++;\r\n })\r\n }\r\n calculateShortest = () => {\r\n for (let i = 0; i < this.points.length; i++)\r\n this.points[i].shortest = min(this.distance[i]);\r\n }\r\n solve = () => {\r\n const n = this.points.length;\r\n for (let a = 0; a < n; a++) {\r\n const p1 = this.points[a];\r\n if (p1.haveGroup)\r\n continue;\r\n p1.haveGroup = true;\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n if (p2.shortest.toString() != p1.shortest.toString()) {\r\n p1.haveGroup = false;\r\n }\r\n });\r\n if (p1.haveGroup) {\r\n p1.shortest.forEach(b => {\r\n const p2 = this.points[b];\r\n p2.haveGroup = true;\r\n });\r\n this.groups.push(p1.shortest.length);\r\n // console.log(p1.shortest);\r\n // sol += (n * this.p[n - 1][ n - p1.shortest.length]) % dn;\r\n // sol %= dn;\r\n }\r\n }\r\n const ways=this.waysToGroups(this.groups.length-1,n)\r\n let sol =0;\r\n for (let i in ways) {\r\n sol +=( ways[i]*this.p[n][i])% dn;\r\n sol %= dn;\r\n }\r\n return sol;\r\n }\r\n groups = [];\r\n waysToGroups_db = [];\r\n waysToGroups(i, pn) {\r\n let ways=[];\r\n const N=this.points.length;\r\n if (i == -1) {\r\n for(let i=0;i<=N;i++)\r\n if(i==pn)\r\n ways[i]=1;\r\n else\r\n ways[i]=0;\r\n return ways;\r\n }\r\n if (this.waysToGroups_db[i] == undefined)\r\n this.waysToGroups_db[i] = [];\r\n if (this.waysToGroups_db[i][pn] != undefined)\r\n return this.waysToGroups_db[i][pn];\r\n let c1 = this.waysToGroups(i - 1, pn);\r\n let c2 = this.waysToGroups(i - 1, pn - (this.groups[i] - 1));\r\n for(let i=0;i<=N;i++)\r\n ways[i]=c1[i]+c2[i];\r\n return this.waysToGroups_db[i][pn]=ways;\r\n }\r\n}\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n if (t == 2) {\r\n console.log(2);\r\n return;\r\n }\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateDistance();\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\ndelay = (ms) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = async () => await scaner.read();\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n shortest=[];\r\n haveGroup=false;\r\n}\r\nconst dn = 998244353;\r\nfunction min(a=[]){\r\n let min=[0];\r\n let me =-1;\r\n for (let i = 0; i < a.length; i++) {\r\n const e = a[i];\r\n const minValue=a[min[0]];\r\n if(e==Infinity){\r\n me=i;\r\n min.push(me);\r\n }\r\n else if (e==minValue){\r\n if(i!=0)\r\n min.push(i);\r\n }\r\n else if (e this.f[n] / this.f[n - m];\r\n c = (n, m) => (this.f[n] / (this.f[m] * this.f[n - m])) % dn;\r\n\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateDistance = () => {\r\n let curr = 0\r\n this.distance = [];\r\n this.points.forEach(p => {\r\n this.distance.push([]);\r\n for (var i = 0; i < curr; i++) {\r\n this.distance[curr].push(this.distance[i][curr]);\r\n }\r\n this.distance[curr].push(Infinity);\r\n for (var i = curr + 1; i < this.points.length; i++) {\r\n let dis = Math.abs(p.x - this.points[i].x) + Math.abs(p.y - this.points[i].y);\r\n this.distance[curr].push(dis);\r\n }\r\n curr++;\r\n })\r\n }\r\n calculateShortest=()=>{\r\n for (let i = 0; i < this.points.length; i++) \r\n this.points[i].shortest=min(this.distance[i]);\r\n }\r\n solve = () => {\r\n const n = this.points.length;\r\n let sol = this.f[n];\r\n for (let a = 0; a < n; a++) {\r\n const p1 = this.points[a];\r\n if(p1.haveGroup)\r\n continue;\r\n p1.haveGroup=true;\r\n p1.shortest.forEach(b=>{\r\n const p2 = this.points[b];\r\n if(p2.shortest.toString()!=p1.shortest.toString()){\r\n p1.haveGroup=false;\r\n }\r\n });\r\n if(p1.haveGroup){\r\n p1.shortest.forEach(b=>{\r\n const p2 = this.points[b];\r\n p2.haveGroup=true;\r\n });\r\n sol += n * (this.p(n-1,n-p1.shortest.length));\r\n }\r\n }\r\n return sol;\r\n }\r\n}\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n if (t == 2) {\r\n console.log(2);\r\n return;\r\n }\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateDistance();\r\n ans.calculateShortest();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n).catch((e) => {\r\n console.log(\"error: \"+e);\r\n});\r\n\r\n\r\n\r\n"}, {"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\ndelay = (ms) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = async () => await scaner.read();\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nclass Point {\r\n x = 0;\r\n y = 0;\r\n constructor(a = []) {\r\n this.x = a[0];\r\n this.y = a[1];\r\n }\r\n}\r\nconst dn = 998244353;\r\nclass Ans {\r\n f = [];\r\n points = [];\r\n distance;\r\n constructor(n) {\r\n this.f[0] = 1;\r\n for (var i = 1; i <= n; i++)\r\n this.f[i] = (this.f[i - 1] * i) % dn;\r\n }\r\n p = (n, m) => this.f[n] / this.f[n - m];\r\n c = (n, m) => (this.f[n] / (this.f[m] * this.f[n - m])) % dn;\r\n\r\n addPoint(a = []) {\r\n this.points.push(new Point(a));\r\n }\r\n calculateDistance = () => {\r\n let curr = 0\r\n this.distance = [];\r\n this.points.forEach(p => {\r\n this.distance.push([]);\r\n for (var i = 0; i < curr; i++) {\r\n this.distance[curr].push(this.distance[i][curr]);\r\n }\r\n this.distance[curr].push(0);\r\n for (var i = curr + 1; i < this.points.length; i++) {\r\n let dis = Math.abs(p.x - this.points[i].x) + Math.abs(p.y - this.points[i].y);\r\n this.distance[curr].push(dis);\r\n }\r\n curr++;\r\n })\r\n }\r\n solve = () => {\r\n const n = this.points.length;\r\n let sol = this.f[n];\r\n for (let a = 0; a < n-2; a++) {\r\n const p1 = this.points[a];\r\n let b=a+1;\r\n let c=a+2;\r\n if (this.distance[a][b] < this.distance[a][c] && this.distance[a][b] < this.distance[b][c]){\r\n sol += (n) * (this.p(n-1,n-2));\r\n }\r\n if (this.distance[a][b] == this.distance[a][c] && this.distance[a][b] == this.distance[b][c]) {\r\n // i,j,k same color\r\n let d=a+3;\r\n if(d>=n || (this.distance[b][c] < this.distance[b][d] && this.distance[b][c] < this.distance[c][d])){\r\n sol += (n) * (this.p(n-1,n-3));\r\n }\r\n }\r\n }\r\n return sol;\r\n }\r\n}\r\n\r\n(async () => {\r\n let t = parseInt(await read());\r\n if (t == 2) {\r\n console.log(2);\r\n return;\r\n }\r\n let ans = new Ans(t);\r\n while (t--) {\r\n ans.addPoint(\r\n (await read()).split(' ').map(Number));\r\n }\r\n ans.calculateDistance();\r\n console.log(ans.solve());\r\n})().then(() => { }\r\n).catch((e) => {\r\n console.log(\"error: \"+e);\r\n});\r\n\r\n\r\n\r\n"}], "src_uid": "ab65207f0b334276f58e0d2e79b0b44d"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = iInpArr();\r\n let arr = iInpArr();\r\n let arr1 = new Array(arr.length).fill(0);\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < i + 1) {\r\n res.push(arr[i]);\r\n arr1[i] = 1;\r\n }\r\n }\r\n let psum = [],\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr1[i];\r\n psum[i] = sum;\r\n }\r\n let cnt = 0;\r\n for (let i = res.length - 1; i >= 0; i--) {\r\n let j = res[i] - 2;\r\n if (j >= 0) cnt += psum[j];\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var s = [];\r\n var ans = BigInt(0);\r\n for(var i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const good = []\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < i + 1) {\n good.push(i)\n }\n }\n let p = 0\n good.sort((a, b) => arr[a] - arr[b])\n// console.log(good)\n //\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < i + 1) {\n // for good after now, how may i + 1 < arr[good[x]]\n // for (let j = 0; j < good.length; j++) {\n // if (good[j] > i && i + 1 < arr[good[j]]) ans++\n // }\n while (p < good.length) {\n const j = good[p]\n if (i + 1 >= arr[j]) {\n p++\n } else {\n break\n }\n }\n ans += good.length - p\n // const j = binarySearch(0, good.length - 1, x => i + 1 >= arr[good[x]])\n // ans += good.length - (j + 1)\n }\n }\n return ans\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let works = arr.map((val, index) => val < index + 1);\r\n\r\n let inLeft = new Array(n).fill(0);\r\n inLeft[inLeft.length - 1] = 0;\r\n for (let i = 0; i < n; i++) {\r\n inLeft[i] = (inLeft[i - 1] || 0) + (works[i - 1] ? 1 : 0);\r\n }\r\n\r\n let total = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] < i + 1) {\r\n total += inLeft[Math.max(Math.min(arr[i] - 1, i), 0)];\r\n }\r\n }\r\n\r\n output(total);\r\n }\r\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n \r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n var isLess = arr[i] < i + 1;\r\n \r\n part.push(part[i] + isLess);\r\n \r\n if (isLess && arr[i] !== 0) {\r\n ans += part[arr[i] - 1];\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n var isLess = arr[i] < i + 1;\r\n \r\n part.push(part[i] + isLess);\r\n \r\n if (isLess) {\r\n ans += part[arr[i] - 1];\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n var isLess = arr[i] < i + 1;\r\n\r\n part.push(part[i] + isLess);\r\n \r\n if (isLess) {\r\n ans += part[arr[i]];\r\n }\r\n }\r\n \r\n print(ans);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] < i + 1) {\r\n part.push(part[i] + 1);\r\n ans += part[arr[i]];\r\n }\r\n }\r\n \r\n print(ans);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n var isLess = arr[i] < i + 1;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n part.push(part[i] + isLess);\r\n }\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n if (isLess) {\r\n ans += part[arr[i]];\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var l = 0; l < t; l++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ');\r\n \r\n var part = [0];\r\n var ans = 0;\r\n \r\n var isLess = arr[i] < i + 1;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n part.push(part[i] + isLess);\r\n \r\n if (isLess) {\r\n ans += part[arr[i]];\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}], "src_uid": "89768e4c832428b534cae3acbf379c44"} {"source_code": "for(t=readline();t--;)print(2,readline()-1)", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n console.log(2 + ' ' + (k - 1));\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t= nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet p = nl.num();\n\t\tans.push([2, p-1]);\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction writeOutput(s) {\r\n process.stdout.write(s);\r\n}\r\n\r\n\r\nfunction main() {\r\n let t = parseInt(readline(), 10);\r\n while(t--) {\r\n let n = parseInt(readline(), 10);\r\n for (let i = 0; i*i < n; ++i) {\r\n let found = false;\r\n for (let a = Math.max(2, i+1); a*a < n; ++a) {\r\n if ((n-i) % a === 0 && (n-i) != a) {\r\n writeOutput(`${a} ${(n-i)}\\n`);\r\n found = true;\r\n break;\r\n }\r\n }\r\n if (found) break;\r\n }\r\n }\r\n}\r\n\r\n// run: cat input.txt | node A.js"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\nconst solver = (n) => {\r\n return 2 + \" \" + (n-1).toString()\r\n};\r\n\r\n\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var a = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var answe = 2\r\n console.log(2, a-1)\r\n })\r\n // var res = new Array(n)\r\n}\r\n\r\nfunction plus(a, b, res) {\r\n// console.log(a, b, res)\r\n if (a === 0) return res\r\n\r\n return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n console.log(2 + ' ' + (k - 1));\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar P = nextInt();\r\n\t\tvar L = 2;\r\n\t\tvar R = (P - 1);\r\n\t\tmyout(L + \" \" + R);\r\n\t}\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t;\r\nt = parseInt(readline());\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n console.log(2 + \" \" + (n - 1) );\r\n}\r\n\r\n}\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift()(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift())\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nfunction extend(mas) {\r\n let n = mas.length\r\n mas.unshift(new Array(n++).fill('.'))\r\n for (let i = 0; i < n; ++i) {\r\n mas[i].push('.')\r\n }\r\n}\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n for (let i = 0; i < n; ++i) {\r\n let p = +await nextString()\r\n console.log(`2 ${p - 1}`)\r\n }\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/01/21 evening\r\n * https://codeforces.com/contest/1549/problem/A\r\n */\r\nconst solve = (p) => {\r\n pr(2, p - 1);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let i = ''\r\nlet lines\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n lines = i.split('\\n') // your input text, split by lines\r\n main()\r\n})\r\n\r\nfunction main() {\r\n let t = parseInt(lines.shift())\r\n\r\n while (t > 0) {\r\n const p = parseInt(lines.shift())\r\n\r\n if (p === 5) {\r\n console.log(2, 4)\r\n } else {\r\n console.log(2, (p - 1) / 2)\r\n }\r\n t--\r\n }\r\n}"}, {"source_code": "function solve(p) {\r\n if (p === 5) return [2, 4];\r\n return [2, parseInt(p / 2)];\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n p = parseInt(readline());\r\n var ans = solve(p);\r\n print(ans[0], ans[1]);\r\n}\r\n"}, {"source_code": "r=readline;for(r();a=r();)print(2,~-a)"}, {"source_code": "r=readline;for(r();a=r();print(2,~-a));"}, {"source_code": "r=readline\r\nfor(i=r();i;i--)print('2 '+(r()-1))"}, {"source_code": "for(r=readline,t=r();t--;)print(2,r()-1)"}, {"source_code": "n = readline();\r\nwhile(n--) {\r\n s = readline();\r\n print(2, s-1);\r\n}"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n[0]; j++){\n var k = lines[j];\n console.log(2 + ' ' + (k - 1));\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n[0]; j++){\n var k = lines[j];\n\n }\n console.log(3 + ' ' + 5 + \"\\n\" + 2 + ' ' + 4);\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t= nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet p = nl.num();\n\t\tfor(let j = 2; j <= p; j++){\n\t\t\tif (p%j == p%(j+2)){\n\t\t\t\tans.push([j, j+2]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction writeOutput(s) {\r\n process.stdout.write(s);\r\n}\r\n\r\n\r\nfunction main() {\r\n let t = parseInt(readline(), 10);\r\n while(t--) {\r\n let n = parseInt(readline(), 10);\r\n for (let i = 1; i*i < n; ++i) {\r\n let found = false;\r\n for (let a = i+1; a*a < n; ++a) {\r\n if ((n-i) % a === 0 && (n-i) / a != a) {\r\n writeOutput(`${a} ${(n-i)/a}\\n`);\r\n found = true;\r\n break;\r\n }\r\n }\r\n if (found) break;\r\n }\r\n }\r\n}\r\n\r\n// run: cat input.txt | node A.js"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\nconst solver = (n) => {\r\n return 2 + \" \" + (n-1).toString()\r\n};\r\n\r\n\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example).length)\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var a = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var answe = 2\r\n for (let j = 2; j < 100; j++) {\r\n if(a %j === 1) answe = j\r\n }\r\n console.log(2, answe)\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n })\r\n // var res = new Array(n)\r\n}\r\n\r\nfunction plus(a, b, res) {\r\n// console.log(a, b, res)\r\n if (a === 0) return res\r\n\r\n return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)\r\n}\r\n"}, {"source_code": "function solve(p) {\r\n if (p === 5) return [2, 3];\r\n return [2, parseInt(p / 2)];\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n p = parseInt(readline());\r\n var ans = solve(p);\r\n print(ans[0]+\" \"+ans[1]);\r\n}\r\n"}, {"source_code": "function solve(p) {\r\n if (p === 5) return [2, 3];\r\n var i = 2;\r\n\r\n while (true) {\r\n var a = i;\r\n var b = parseInt(p / i);\r\n if (a !== b && Math.max(a, b) <= p) return [Math.min(a, b), Math.max(a, b)];\r\n i++;\r\n }\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n p = parseInt(readline());\r\n var ans = solve(p);\r\n print(ans[0], ans[1]);\r\n}\r\n"}, {"source_code": "function solve(p) {\r\n if (p === 5) return [2, 3];\r\n var i = 2;\r\n\r\n while (true) {\r\n var a = i;\r\n var b = parseInt(p / i);\r\n if (Math.max(a, b) <= p) return [Math.min(a, b), Math.max(a, b)];\r\n i++;\r\n }\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n p = parseInt(readline());\r\n var ans = solve(p);\r\n print(ans[0], ans[1]);\r\n}\r\n"}, {"source_code": "function solve(p) {\r\n if (p === 5) return [2, 3];\r\n return [2, parseInt(p / 2)];\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n p = parseInt(readline());\r\n var ans = solve(p);\r\n print(ans[0], ans[1]);\r\n}\r\n"}], "src_uid": "259e39c9e63e43678e596c0d8c66937c"} {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar S = one[1];\n\tif(N == 1){\n\t\tif(S == 1){\n\t\t\tmyout(\"NO\");\n\t\t}else{\n\t\t\tmyout(\"YES\");\n\t\t\tmyout(S);\n\t\t\tmyout(S - 1);\n\t\t}\n\t\treturn;\n\t}\n\tvar list = new Array(N);\n\tvar oneCount = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(i == N - 1){\n\t\t\tlist[i] = S;\n\t\t}else{\n\t\t\tlist[i] = 1;\n\t\t\toneCount++;\n\t\t\tS--;\n\t\t}\n\t}\n\tmyerr(oneCount);\n\tif(oneCount < S - 1){\n\t\tmyout(\"YES\");\n\t\tmyout(myconv(list,8));\n\t\tmyout(S - 1);\n\t}else{\n\t\tmyout(\"NO\");\n\t}\n}", "positive_code": [{"source_code": "const processData = (lines) => {\n const [n, s] = lines[0].split(' ').map(x => +x)\n if (n*2 > s) {\n console.log('NO')\n } else {\n console.log('YES')\n let t = s\n const res = []\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar S = one[1];\n\tif(N == 1){\n\t\tif(S == 1){\n\t\t\tmyout(\"NO\");\n\t\t}else{\n\t\t\tmyout(\"YES\");\n\t\t\tmyout(S);\n\t\t\tmyout(S - 1);\n\t\t}\n\t\treturn;\n\t}\n\tvar list = new Array(N);\n\tvar oneCount = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(i == N - 1){\n\t\t\tlist[i] = S;\n\t\t}else{\n\t\t\tlist[i] = 1;\n\t\t\toneCount++;\n\t\t\tS--;\n\t\t}\n\t}\n\tmyerr(oneCount);\n\tif(oneCount < S){\n\t\tmyout(\"YES\");\n\t\tmyout(myconv(list,8));\n\t\tmyout(S - 1);\n\t}else{\n\t\tmyout(\"NO\");\n\t}\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar S = one[1];\n\tif(N == 1){\n\t\tif(S == 1){\n\t\t\tmyout(\"NO\");\n\t\t}else{\n\t\t\tmyout(\"YES\");\n\t\t\tmyout(S);\n\t\t\tmyout(S - 1);\n\t\t}\n\t}\n\tvar list = new Array(N);\n\tvar oneCount = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(i == N - 1){\n\t\t\tlist[i] = S;\n\t\t}else{\n\t\t\tlist[i] = 1;\n\t\t\toneCount++;\n\t\t\tS--;\n\t\t}\n\t}\n\tmyerr(oneCount);\n\tif(oneCount < S){\n\t\tmyout(\"YES\");\n\t\tmyout(myconv(list,8));\n\t\tmyout(S - 1);\n\t}else{\n\t\tmyout(\"NO\");\n\t}\n}"}], "src_uid": "4a644d97824d29c42dbb48d79b9958fe"} {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => []);\n For(0, n - 1, 1, i => { c[a[i]].push(i) });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (!c[i].length) return;\n c[i].push(n);\n let maxk = c[i].map((v, i, a) => i == 0 ? v : v - 1 - a[i - 1]).max()[0];\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}", "positive_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => [-1]);\n For(0, n - 1, 1, i => { c[a[i]].push(i) });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (c[i].length <= 1) return;\n c[i].push(n)\n // let maxk = Arr(1,c[i].length-1,1,j=>c[i][j]-1-c[i][j-1]).max()[0]\n // log(i,maxk);\n let maxk = 0;\n for (let j = 1; j < c[i].length; j++) maxk = max(maxk, c[i][j] - 1 - c[i][j - 1])\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => []);\n For(0, n - 1, 1, i => {\n c[a[i]].push(i);\n });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (!c[i].length) return;\n let maxk = max(c[i][0], n - 1 - c[i][c[i].length - 1]);\n for (let j = 1; j < c[i].length; j++) maxk = max(maxk, c[i][j] - 1 - c[i][j - 1]);\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => [-1]);\n For(0, n - 1, 1, i => { c[a[i]].push(i) });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (c[i].length <= 1) return;\n c[i].push(n)\n let maxk = Arr(1, c[i].length - 1, 0, j => c[i][j] - 1 - c[i][j - 1]).max()[0]\n // let maxk = 0;\n // for (let j = 0; j < a.length; j++) maxk = max(maxk, a[j])\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => [-1]);\n For(0, n - 1, 1, i => { c[a[i]].push(i) });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (c[i].length <= 1) return;\n c[i].push(n)\n let a = Arr(1, c[i].length - 1, 1, j => c[i][j] - 1 - c[i][j - 1])\n let maxk = 0;\n for (let j = 0; j < a.length; j++) maxk = max(maxk, a[j])\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n const track = new Map();\n\n for (let i = 0; i < nums.length; i++) {\n const element = nums[i];\n const t = track.get(element) || {\n maxSpace: 0,\n lastIndex: -1\n };\n const space = i - t.lastIndex;\n\n if (space > t.maxSpace) {\n t.maxSpace = space;\n }\n\n t.lastIndex = i;\n track.set(element, t);\n }\n\n for (const t of track.values()) {\n const space = nums.length - t.lastIndex;\n\n if (space > t.maxSpace) {\n t.maxSpace = space;\n }\n }\n\n const answerPrep = [];\n\n for (const [num, t] of track) {\n if (!answerPrep[t.maxSpace] || answerPrep[t.maxSpace] > num) {\n answerPrep[t.maxSpace] = num;\n }\n }\n\n const answer = [];\n let lastAnswer = -1;\n\n for (let i = 1; i <= nums.length; i++) {\n const element = answerPrep[i];\n\n if (element !== undefined && (lastAnswer === -1 || element < lastAnswer)) {\n lastAnswer = element;\n }\n\n answer.push(lastAnswer);\n }\n\n return answer;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer.join(' '));\n }\n}\n\nmain().then();\n"}], "negative_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let c = Arr(0, n, 1, i => []);\n For(0, n - 1, 1, i => {\n c[a[i]].push(i);\n });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (!c[i].length) return;\n let maxk = c[i].map((v, i) => i == 0 ? v : v - a[i - 1] - 1).max()[0];\n maxk = max(maxk, n - 1 - c[i][c[i].length - 1]);\n // log(i,maxk);\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n // let l = Array(n)\n // let r = Array(n)\n // l[0] = -1\n // For(1, n - 1, 1, i => {\n // l[i] = i - 1;\n // while (l[i] >= 0 && a[l[i]] >= a[i]) l[i] = l[l[i]];\n // })\n // r[n - 1] = n;\n // For(n - 2, 0, -1, i => {\n // r[i] = i + 1;\n // while (r[i] < n && a[r[i]] >= a[i]) r[i] = r[r[i]];\n // });\n let c = Arr(0, n, 1, i => []);\n For(0, n - 1, 1, i => {\n c[a[i]].push(i);\n });\n // log(c);\n let res = Array(n + 1).fill(-1);\n let k = n;\n For(1, n, 1, i => {\n if (!c[i].length) return;\n let maxk = c[i].map((v, i) => i == 0 ? v : v - a[i - 1]).max()[0];\n maxk = max(maxk, n - 1 - c[i][c[i].length - 1]);\n // log(i,maxk);\n while (k > 0 && k > maxk) res[k--] = i;\n })\n log(res.slice(1).join(' '))\n }\n}"}], "src_uid": "b7abfb1103bb1796c8f89653c303d7dc"} {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = r >> 1,\r\n i = Buffer.alloc(r)\r\n let o = 0\r\n return {\r\n flush: s,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function s() {\r\n t.write(i.toString(e, 0, o)), (o = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - o < c && (s(), c > u) ? t.write(n) : (i.write(n, o, e), (o += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const [t, r] = n.readIntegersOfLine(),\r\n u = e(t, r)\r\n n.println(u)\r\n }\r\n function e(n, t) {\r\n return 1 & Math.abs(n - t) ? -1 : n === t ? (0 === n ? 0 : 1) : 2\r\n }\r\n})\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar c = nextInt();\r\n\t\tvar d = nextInt();\r\n\t\tif(Math.abs(c - d) % 2 == 1){\r\n\t\t\tmyout(-1);\r\n\t\t}else if(Math.abs(c - d) == 0){\r\n\t\t\tif(c == 0 && d == 0){\r\n\t\t\t\tmyout(0);\r\n\t\t\t}else{\r\n\t\t\t\tmyout(1);\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tmyout(2);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//Vismillahir Rahmanir Rahim (Allah hu Ackbar);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var ans = 0;\r\n while (t--) {\r\n\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n\r\n\r\n if ((a + b) % 2 != 0) {\r\n ans = -1;\r\n } else if ((a + b == 0)) {\r\n ans = 0\r\n } else if (a == b) {\r\n ans = 1;\r\n } else {\r\n ans = 2;\r\n }\r\n console.log(ans);\r\n\r\n }\r\n}"}], "negative_code": [{"source_code": "//Vismillahir Rahmanir Rahim (Allah hu Ackbar);\r\n\r\n\r\n\r\n// var t = Number(readline());\r\n// var ans = 0;\r\n// var k0 = 0;\r\n// var k01 = 0;\r\n// while (t--) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1];\r\n// if (a > b) {\r\n// var temp = b;\r\n// b = a;\r\n// a = temp;\r\n// }\r\n// for (var i = 0; i <= 10000; i++) {\r\n// if (a < i) {\r\n// k0 = i - a;\r\n// } else {\r\n// k0 = a - i;\r\n// }\r\n// if (b < i) {\r\n// k01 = i - b;\r\n// } else {\r\n// k01 = b - i;\r\n// }\r\n// var k1 = a + i;\r\n// var k11 = b + i;\r\n// var k2 = a + i;\r\n// var k22 = k01;\r\n// var k3 = k0;\r\n// var k33 = b + i\r\n// if (a == 0 && b == 0) {\r\n// ans = 0;\r\n// break;\r\n// } else if (k1 == k11) {\r\n\r\n// ans = 1;\r\n// break;\r\n// } else if (k2 == k22) {\r\n// // console.log(k2 + \" \" + k22);\r\n// ans = 2;\r\n// break;\r\n// } else if (k3 == k33) {\r\n// ans = 3\r\n// // console.log(k3 + \" \" + k33);\r\n// break;\r\n// } else {\r\n// ans = -1;\r\n// }\r\n// }\r\n// console.log(ans);\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var ans = 0;\r\n var k0 = 0;\r\n var k01 = 0;\r\n while (t--) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n if (a > b) {\r\n var temp = b;\r\n b = a;\r\n a = temp;\r\n }\r\n for (var i = 0; i <= 10000; i++) {\r\n if (a < i) {\r\n k0 = i - a;\r\n } else {\r\n k0 = a - i;\r\n }\r\n if (b < i) {\r\n k01 = i - b;\r\n } else {\r\n k01 = b - i;\r\n }\r\n var k1 = a + i;\r\n var k11 = b + i;\r\n var k2 = a + i;\r\n var k22 = k01;\r\n var k3 = k0;\r\n var k33 = b + i\r\n if (a == 0 && b == 0) {\r\n ans = 0;\r\n break;\r\n } else if (k1 == k11) {\r\n\r\n ans = 1;\r\n break;\r\n } else if (k2 == k22) {\r\n // console.log(k2 + \" \" + k22);\r\n ans = 2;\r\n break;\r\n } else if (k3 == k33) {\r\n ans = 3\r\n // console.log(k3 + \" \" + k33);\r\n break;\r\n } else {\r\n ans = -1;\r\n }\r\n }\r\n console.log(ans);\r\n\r\n }\r\n\r\n}"}, {"source_code": "//Vismillahir Rahmanir Rahim (Allah hu Ackbar);\r\n\r\n\r\n\r\n// var t = Number(readline());\r\n// var ans = 0;\r\n// var k0 = 0;\r\n// var k01 = 0;\r\n// while (t--) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1];\r\n// if (a > b) {\r\n// var temp = b;\r\n// b = a;\r\n// a = temp;\r\n// }\r\n// for (var i = 0; i < 1000000; i++) {\r\n// if (a < i) {\r\n// k0 = i - a;\r\n// } else {\r\n// k0 = a - i;\r\n// }\r\n// if (b < i) {\r\n// k01 = i - b;\r\n// } else {\r\n// k01 = b - i;\r\n// }\r\n// var k1 = a + i;\r\n// var k11 = b + i;\r\n// var k2 = a + i;\r\n// var k22 = k01;\r\n// var k3 = k0;\r\n// var k33 = b + i\r\n// if (a == 0 && b == 0) {\r\n// ans = 0;\r\n// break;\r\n// } else if (k1 == k11) {\r\n\r\n// ans = 1;\r\n// break;\r\n// } else if (k2 == k22) {\r\n// // console.log(k2 + \" \" + k22);\r\n// ans = 2;\r\n// break;\r\n// } else if (k3 == k33) {\r\n// ans = 3\r\n// // console.log(k3 + \" \" + k33);\r\n// break;\r\n// } else {\r\n// ans = -1;\r\n// }\r\n// }\r\n// console.log(ans);\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var ans = 0;\r\n var k0 = 0;\r\n var k01 = 0;\r\n while (t--) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n if (a > b) {\r\n var temp = b;\r\n b = a;\r\n a = temp;\r\n }\r\n for (var i = 0; i < 10000; i++) {\r\n // if (a < i) {\r\n // k0 = i - a;\r\n // } else {\r\n // k0 = a - i;\r\n // }\r\n // if (b < i) {\r\n // k01 = i - b;\r\n // } else {\r\n // k01 = b - i;\r\n // }\r\n var k1 = a + i;\r\n var k11 = b + i;\r\n var k2 = a + i;\r\n var k22 = i - b;\r\n var k3 = a - i;\r\n var k33 = b + i\r\n if (a == 0 && b == 0) {\r\n ans = 0;\r\n break;\r\n } else if (k1 == k11) {\r\n\r\n ans = 1;\r\n break;\r\n } else if (k2 == k22) {\r\n // console.log(k2 + \" \" + k22);\r\n ans = 2;\r\n break;\r\n } else if (k3 == k33) {\r\n ans = 3\r\n // console.log(k3 + \" \" + k33);\r\n break;\r\n } else {\r\n ans = -1;\r\n }\r\n }\r\n console.log(ans);\r\n\r\n }\r\n\r\n}"}, {"source_code": "//Vismillahir Rahmanir Rahim (Allah hu Ackbar);\r\n\r\n\r\n\r\n// var t = Number(readline());\r\n// var ans = 0;\r\n// var k0 = 0;\r\n// var k01 = 0;\r\n// while (t--) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1];\r\n// if (a > b) {\r\n// var temp = b;\r\n// b = a;\r\n// a = temp;\r\n// }\r\n// for (var i = 0; i < 1000000; i++) {\r\n// if (a < i) {\r\n// k0 = i - a;\r\n// } else {\r\n// k0 = a - i;\r\n// }\r\n// if (b < i) {\r\n// k01 = i - b;\r\n// } else {\r\n// k01 = b - i;\r\n// }\r\n// var k1 = a + i;\r\n// var k11 = b + i;\r\n// var k2 = a + i;\r\n// var k22 = k01;\r\n// var k3 = k0;\r\n// var k33 = b + i\r\n// if (a == 0 && b == 0) {\r\n// ans = 0;\r\n// break;\r\n// } else if (k1 == k11) {\r\n\r\n// ans = 1;\r\n// break;\r\n// } else if (k2 == k22) {\r\n// // console.log(k2 + \" \" + k22);\r\n// ans = 2;\r\n// break;\r\n// } else if (k3 == k33) {\r\n// ans = 3\r\n// // console.log(k3 + \" \" + k33);\r\n// break;\r\n// } else {\r\n// ans = -1;\r\n// }\r\n// }\r\n// console.log(ans);\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var ans = 0;\r\n var k0 = 0;\r\n var k01 = 0;\r\n while (t--) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n if (a > b) {\r\n var temp = b;\r\n b = a;\r\n a = temp;\r\n }\r\n for (var i = 0; i < 10000; i++) {\r\n if (a < i) {\r\n k0 = i - a;\r\n } else {\r\n k0 = a - i;\r\n }\r\n if (b < i) {\r\n k01 = i - b;\r\n } else {\r\n k01 = b - i;\r\n }\r\n var k1 = a + i;\r\n var k11 = b + i;\r\n var k2 = a + i;\r\n var k22 = k01;\r\n var k3 = k0;\r\n var k33 = b + i\r\n if (a == 0 && b == 0) {\r\n ans = 0;\r\n break;\r\n } else if (k1 == k11) {\r\n\r\n ans = 1;\r\n break;\r\n } else if (k2 == k22) {\r\n // console.log(k2 + \" \" + k22);\r\n ans = 2;\r\n break;\r\n } else if (k3 == k33) {\r\n ans = 3\r\n // console.log(k3 + \" \" + k33);\r\n break;\r\n } else {\r\n ans = -1;\r\n }\r\n }\r\n console.log(ans);\r\n\r\n }\r\n\r\n}"}], "src_uid": "8e7c0b703155dd9b90cda706d22525c9"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(\" \").map(Number);\n const ans = a + b * 2 + 1;\n\n if (a === 0) {\n console.log(1);\n } else {\n console.log(ans);\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n var s = readline().split(' ');\r\n\tvar a = parseInt(s[0]);\r\n\tvar b = parseInt(s[1]);\r\n\tvar res = b * 2 + a + 1;\r\n\tif(a == 0)res = 1;\r\n\tprint(res);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nwhile (t--) {\r\n // const [a, b] = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n // const [a, b] = readline().split(\" \").map(x => parseInt(x));\r\n var ab = readline().split(' ');\r\n \r\n var a = parseInt(ab[0]);\r\n var b = parseInt(ab[1]);\r\n \r\n var r = a + 2 * b + 1;\r\n \r\n if (!a) {\r\n r = 1;\r\n }\r\n \r\n write(r);\r\n write('\\n');\r\n}\r\n"}, {"source_code": "var test_cases = parseInt(readline());\r\nvar i;\r\nfor( i=0; i 0){\r\n\ttotal_no =1;\r\n\tprint(total_no);\r\n}\r\n\r\nelse if (parseInt(coins[0]) == 0 && parseInt(coins[1]) == 0){\r\n\ttotal_no =1;\r\n\tprint(total_no);\r\n}\r\n\r\nelse if(parseInt(coins[0]) > 0 && parseInt(coins[1]) >= 0){\r\n\ttotal_no = parseInt(coins[0]) + (parseInt(coins[1]) * 2)+1;\r\n\tprint(total_no);\r\n}\r\nprint(\"\\n\");\r\n}"}, {"source_code": "var t = readline();\r\nfor (var i=0 ; i < t ; i++){\r\n var inputs = readline().split(' ');\r\n a = inputs[0] , b = inputs[1];\r\n if(a == '0'){\r\n print(1);\r\n }\r\n else{\r\n print(parseInt(a) + (parseInt(b) * 2) + 1);\r\n }\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var ab = readline().split(' ').map(x=>parseInt(x));\r\n var a = ab[0];\r\n var b = ab[1];\r\n if (a == 0) {\r\n print(1);\r\n } else {\r\n print(a + 2 * b + 1);\r\n }\r\n }"}, {"source_code": "T = readline ()\r\nwhile(T--){ \r\n x = readline().split(' ').map(x => +x)\r\n a = x[0]\r\n b = x[1]\r\n \r\n\r\n if(a === 0)\r\n print(1)\r\n else\r\n print(a + b*2 +1)\r\n \r\n}\r\n\r\n"}, {"source_code": "var x = readline();\r\n\r\nvar res =\"\";\r\nwhile(x--){\r\n \r\nvar arr = readline().split(' ');\r\n\r\nres += arr[0] == 0 ? 1+'\\n' : (+1 + +arr[0] + ( +arr[1] * 2 )) +'\\n' ;\r\n}\r\nprint(res);\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n main();\r\n});\r\n \r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction minSum(oneBurle,twoBurle){\r\n if(twoBurle===0){\r\n return oneBurle+1\r\n }\r\n else if(oneBurle===0){\r\n return 1\r\n }\r\n else{\r\n return (twoBurle*2) + oneBurle + 1 \r\n }\r\n}\r\n \r\n \r\nfunction main() {\r\n \r\n \r\n const t = parseInt(readLine().trim(), 10);\r\n \r\n for (let tItr = 0; tItr < t; tItr++) {\r\n const vals = readLine().split(' ');\r\n \r\n const a = parseInt(vals[0], 10);\r\n const b = parseInt(vals[1], 10);\r\n const result = minSum(a,b);\r\n console.log(result)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n main();\r\n});\r\n\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction minSum(oneBurle,twoBurle){\r\n if(twoBurle===0){\r\n return oneBurle+1\r\n }\r\n else if(oneBurle===0){\r\n return 1\r\n }\r\n else{\r\n return (twoBurle*2) + oneBurle + 1 \r\n }\r\n}\r\n\r\n\r\nfunction main() {\r\n\r\n\r\n const t = parseInt(readLine().trim(), 10);\r\n\r\n for (let tItr = 0; tItr < t; tItr++) {\r\n const vals = readLine().split(' ');\r\n\r\n const a = parseInt(vals[0], 10);\r\n const b = parseInt(vals[1], 10);\r\n const result = minSum(a,b);\r\n console.log(result)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n while(t--) {\r\n let line = readLine();\r\n line = line.split(\" \");\r\n let n = parseInt(line[0]);\r\n let m = parseInt(line[1]);\r\n if(n!==0)\r\n\t {console.log(n+2*m+1);}\r\n\t\telse console.log(1);\r\n\t \r\n }\r\n}"}, {"source_code": "process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(string => { return string.trim(); }); main(); }); function readLine() { return inputString[currentLine++]; }\nfunction main() {\n const N = parseInt(readLine());\n\n for (let i = 0; i < N; i++) {\n const [ar, br] = readLine().split(' ');\n const a = Number(ar);\n const b = Number(br);\n\n if (a) {\n console.log(a + b * 2 + 1);\n } else {\n console.log(1);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(string => { return string.trim(); }); main(); }); function readLine() { return inputString[currentLine++]; }\n\nfunction main() {\n const N = parseInt(readLine());\n\n for (let i = 0; i < N; i++) {\n const [ar, br] = readLine().split(' ');\n const a = Number(ar);\n const b = Number(br);\n\n if (a) {\n console.log(a + b * 2 + 1);\n } else {\n console.log(1);\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n const odd = a >= 1 ? (Math.floor((a - 1) / 2) + b) * 2 + 1 : -1\n const even = (Math.floor(a / 2) + b) * 2\n// console.log(odd, even)\n\n let ans\n if (odd === even + 1 || even === odd + 1) {\n ans = Math.max(odd, even) + 1\n } else {\n ans = Math.min(odd, even) + 1\n }\n return Math.max(1, ans)\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [a, b] = readline().split(' ').map(Number);\r\n output(a === 0 ? 1 : b * 2 + a + 1);\r\n }\r\n}\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split(' ').map(Number);\n var one = a[0];\n var two = a[1] * 2;\n if(one === 0){\n console.log(1);\n }else{\n console.log(one + two + 1);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = lines[j].split(' ').map(Number)\n var one = a[0]\n var two = a[1] * 2 \n if(one === 0){\n console.log(1)\n }else{\n console.log(one + two + 1)\n }\n }\n});\n "}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n\n for (let i = 0; i < t; i++) {\n let [a, b] = readLine().split(\" \").map(Number);\n\n if (a == 0) {\n console.log(1);\n } else if (b == 0) {\n console.log(a + 1);\n } else {\n a += b * 2;\n console.log(a + 1);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n const [a, b] = readLine().split(\" \").map(i => parseInt(i));\r\n if (a === 0 && b === 0) return 1;\r\n if (a === 0) return 1;\r\n return a + (2 * b) + 1;\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs\r\n .readFileSync(0, 'utf-8')\r\n .split('\\n')\r\n .map(line => line.trim().split(' ').map(Number))\r\n\r\nconst [n] = inputs[0]\r\nconst data = inputs.slice(1, n + 1)\r\n\r\nmain(n, data)\r\nfunction main(n, data) {\r\n let res = []\r\n for (let [a, b] of data) {\r\n if (a === 0) res.push(1)\r\n else res.push(a + b * 2 + 1)\r\n }\r\n console.log(res.join('\\n'))\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tif(A >= 1){\r\n\t\t\tmyout(A + (B * 2) + 1);\r\n\t\t}else{\r\n\t\t\tmyout(1);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (a, b)=>{\n if (a==0)\n return 1;\n return a+b*2+1;\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [a, b] = ra();\n print(calc(a, b))\n }\n}\n\nE.calc = calc;"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n var s = readline().split(' ');\r\n\tvar a = parseInt(s[0]);\r\n\tvar b = parseInt(s[1]);\r\n\tvar res = b * 2 + a + 1;\r\n\tif(a <= b){\r\n\t res = a * 3 + 1;\r\n\t}\r\n\tprint(res + '\\n');\r\n}"}, {"source_code": "\r\nvar t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n // const [a, b] = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n // const [a, b] = readline().split(\" \").map(x => parseInt(x));\r\n var ab = readline().split(' ');\r\n \r\n var a = parseInt(ab[0]);\r\n var b = parseInt(ab[1]);\r\n \r\n write(a + 2 * b + 1);\r\n write('\\n');\r\n}\r\n"}, {"source_code": "let minSum = function(oneBurle,twoBurle){\r\n if(twoBurle==0){\r\n return oneBurle+1;\r\n }\r\n else if(oneBurle==0){\r\n return 1;\r\n }\r\n else{\r\n return (twoBurle*2) + oneBurle + 1 ;\r\n }\r\n};\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n while(t--) {\r\n let line = readLine();\r\n line = line.split(\" \");\r\n let n = parseInt(line[0]);\r\n let m = parseInt(line[1]);\r\n \r\n\t\tconsole.log(n+2*m+1);\r\n\t \r\n }\r\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(\" \").map(Number);\n const ans = a + b * 2 + 1;\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n return binarySearch(1, 1e9, x => {\n const two = Math.min(Math.floor(x / 2), b)\n return two * 2 + a >= x\n }) + 1\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "2b6e670b602a89b467975edf5226219a"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n /*const was = [];\r\n for(let i = 1; i <= 1000; i++) {\r\n was[i] = 1;\r\n for(let j = 2; j*j<=i; j++){\r\n if (i%j==0 && was[i-j] === 1) {\r\n was[i] = 0;\r\n break;\r\n }\r\n if (i%j ===0 && was[i-i/j] === 1) {\r\n was[i] = 0;\r\n break;\r\n }\r\n }\r\n }\r\n const was2=[];\r\n for(let i =2; i<=1000; i+=2)\r\n if (was[i]==1){\r\n was2.push(i);\r\n }\r\n console.log(was2.join(' '));*/\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n = parseInt(await getLine());\r\n let pow = 0;\r\n while (n%2==0){\r\n n=n/2;\r\n pow++;\r\n }\r\n if (pow == 0 || (pow%2==1 && n===1)) {\r\n console.log('Bob');\r\n }\r\n else\r\n console.log('Alice');\r\n }\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nconst readLine = () => standardInputString[curLine++];\r\n\r\nconst readArray = (splitter, mapFunc) => readLine()\r\n .split(splitter)\r\n .map(mapFunc);\r\n\r\nconst eratosphenSieve = (limiter = 1e5) => {\r\n const sieve = new Array(limiter)\r\n .fill(true);\r\n sieve[0] = sieve[1] = false;\r\n \r\n for (let num = 2; num < sieve.length; num += 1) {\r\n if (num) {\r\n let mod = 2;\r\n\r\n while (num * mod < sieve.length) {\r\n sieve[num * mod] = false;\r\n mod += 1;\r\n }\r\n }\r\n }\r\n\r\n const simpleNums = [];\r\n sieve\r\n .forEach((item, ix) => {\r\n item && simpleNums.push(ix);\r\n });\r\n \r\n return simpleNums;\r\n};\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n// https://codeforces.com/problemset/problem/1537/d\r\n\r\n/**\r\n * Types of num n:\r\n * 1) odd\r\n * - Has only odd dividers. After subtraction we obtain even number, since oddNum - oddNum = evenNum\r\n * - Short: we can transit only to 3 state\r\n * 2) even which is power of 2\r\n * - We can subtract half of number, since (n**2 % 2 === 0) and obtain another power of 2.\r\n * - On the other hand we can subtract k*2, where k is a divider of n. In that case we obtain even number, which is not power of 2.\r\n * - It is not power of 2, since n === k*2 * x (where x is power of 2) => n - k*2 === k*2 * x - k*2 => n - k*2 === (x - 1) * k*2. x is a power of 2 =>\r\n * - => x - 1 is odd number.\r\n * - Short: we can transit to 2 state of 3 state\r\n * 3) even\r\n * - Since it is not power of 2 we have at least one odd divider => we can subtract it and get 1 state\r\n * - We can subtract even number and change state to 3\r\n * \r\n * Our transitions between states:\r\n * 1 -> 3\r\n * 2 -> 2\r\n * 2 -> 3\r\n * 3 -> 1\r\n * \r\n * Profit of states:\r\n * 1) Our number is simple or it is 1 => Lose\r\n * 2) If we change state to 1 we lose => we should change state to 2 => if log(n) % 2 Win else Lose\r\n * 3) We can change state to 1 => Win\r\n */\r\n\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let testCaseNum = 0; testCaseNum < t; testCaseNum++) {\r\n const n = +readLine();\r\n\r\n const binaryN = n.toString(2);\r\n const powerOfTwo = binaryN.length - 1;\r\n\r\n if (n % 2 === 1) {\r\n console.log(\"Bob\");\r\n } else if (binaryN === Math.pow(2, powerOfTwo).toString(2)) {\r\n console.log(powerOfTwo % 2 === 0 ? \"Alice\" : \"Bob\");\r\n } else {\r\n console.log(\"Alice\");\r\n }\r\n }\r\n};"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nconst readLine = () => standardInputString[curLine++];\r\n\r\nconst readArray = (splitter, mapFunc) => readLine()\r\n .split(splitter)\r\n .map(mapFunc);\r\n\r\nconst eratosphenSieve = (limiter = 1e5) => {\r\n const sieve = new Array(limiter)\r\n .fill(true);\r\n sieve[0] = sieve[1] = false;\r\n \r\n for (let num = 2; num < sieve.length; num += 1) {\r\n if (num) {\r\n let mod = 2;\r\n\r\n while (num * mod < sieve.length) {\r\n sieve[num * mod] = false;\r\n mod += 1;\r\n }\r\n }\r\n }\r\n\r\n const simpleNums = [];\r\n sieve\r\n .forEach((item, ix) => {\r\n item && simpleNums.push(ix);\r\n });\r\n \r\n return simpleNums;\r\n};\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n// https://codeforces.com/problemset/problem/1537/d\r\n\r\n/**\r\n * Types of num n:\r\n * 1) odd\r\n * - Has only odd dividers. After subtraction we obtain even number, since oddNum - oddNum = evenNum\r\n * - Short: we can transit only to 3 state\r\n * 2) even which is power of 2\r\n * - We can subtract half of number, since (n**2 % 2 === 0) and obtain another power of 2.\r\n * - On the other hand we can subtract k*2, where k is a divider of n. In that case we obtain even number, which is not power of 2.\r\n * - It is not power of 2, since n === k*2 * x (where x is power of 2) => n - k*2 === k*2 * x - k*2 => n - k*2 === (x - 1) * k*2. x is a power of 2 =>\r\n * - => x - 1 is odd number.\r\n * - Short: we can transit to 2 state of 3 state\r\n * 3) even\r\n * - Since it is not power of 2 we have at least one odd divider => we can subtract it and get 1 state\r\n * - We can subtract even number and change state to 3\r\n * \r\n * Our transitions between states:\r\n * 1 -> 3\r\n * 2 -> 2\r\n * 2 -> 3\r\n * 3 -> 1\r\n * \r\n * Profit of states:\r\n * 1) Our number is simple or it is 1 => Lose\r\n * 2) If we change state to 1 we lose => we should change state to 2 => if log(n) % 2 Win else Lose\r\n * 3) We can change state to 1 => Win\r\n */\r\n\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let testCaseNum = 0; testCaseNum < t; testCaseNum++) {\r\n const n = +readLine();\r\n\r\n const binaryN = n.toString(2);\r\n const powerOfTwo = binaryN.length - 1;\r\n console.log(powerOfTwo, binaryN, Math.pow(2, powerOfTwo).toString(2));\r\n\r\n if (n % 2 === 1) {\r\n console.log(\"Bob\");\r\n } else if (binaryN === Math.pow(2, powerOfTwo).toString(2)) {\r\n console.log(powerOfTwo % 2 === 0 ? \"Alice\" : \"Bob\");\r\n } else {\r\n console.log(\"Alice\");\r\n }\r\n }\r\n};"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n = parseInt(await getLine());\r\n let pow = 0;\r\n while (n%2==0){\r\n n/=2;\r\n pow++;\r\n }\r\n if (pow = 0 || (pow%2==1 && n===1)) {\r\n console.log('Bob');\r\n }\r\n else\r\n console.log('Alice');\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "255ee92f5b860eacd9d6321195072734"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar pairNum = n*(n-1)/2;\n\n\tvar counts = [];\n\tfor (var i = 0; i <= n; ++i) {\n\t\tcounts.push({ win: 0, lose: 0 });\n\t}\n\n\tfor (var i = 1; i < pairNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tcounts[pair[0]].win += 1;\n\t\tcounts[pair[1]].lose += 1;\n\t}\n\n\tvar missing = [];\n\tfor (var i = 1; i <= n; ++i) {\n\t\tif (counts[i].win + counts[i].lose != n-1) {\n\t\t\tmissing.push(i);\n\t\t}\n\t}\n\n\tif (counts[missing[0]].win > counts[missing[1]].win) {\n\t\tprint(missing[0]+\" \"+missing[1]);\n\t}\n\telse {\n\t\tprint(missing[1]+\" \"+missing[0]);\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "'use strict'\n\nconst N = +readline()\nlet lll\n\nlet ps = []\n\nwhile (lll = readline()) {\n lll = lll.split(' ').map(v => parseInt(v))\n const v = lll[0]\n const l = lll[1]\n if (!ps[v]) {ps[v] = {bt: [], wt: [], n: 0, i: v}}\n ps[v].bt.push(l)\n ps[v].n++\n if (!ps[l]) {ps[l] = {bt: [], wt: [], n: 0, i: l}}\n ps[l].wt.push(v)\n ps[l].n++\n}\n\nlet min = Infinity\n\nfor (let i = 1; i < ps.length; i++) {\n min = Math.min(ps[i].n, min)\n}\n\nlet ms = []\n\nfor (let i = 1; i < ps.length; i++) {\n if (ps[i].n == min) ms.push(ps[i])\n}\n\nlet fv\nfor (let i = 1; i < ms[0].bt.length; i++) {\n if (~ms[1].wt.indexOf(ms[0].bt[i])) {\n fv = true;\n break\n }\n}\n\nprint(fv ? ms[0].i + ' ' + ms[1].i : ms[1].i + ' ' + ms[0].i)"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar pairNum = n*(n-1)/2;\n\n\tvar counts = [];\n\tfor (var i = 0; i <= n; ++i) {\n\t\tcounts.push({ win: 0, lose: 0 });\n\t}\n\n\tfor (var i = 1; i < pairNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tcounts[pair[0]].win += 1;\n\t\tcounts[pair[1]].lose += 1;\n\t}\n\n\tvar missing = [];\n\tfor (var i = 1; i <= n; ++i) {\n\t\tif (counts[i].win + counts[i].lose != n-1) {\n\t\t\tmissing.push(i);\n\t\t}\n\t}\n\n\tif (missing[0].win > missing[1].win) {\n\t\tprint(missing[0]+\" \"+missing[1]);\n\t}\n\telse {\n\t\tprint(missing[1]+\" \"+missing[0]);\n\t}\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nconst N = +readline()\nlet lll\n\nlet ps = []\n\nwhile (lll = readline()) {\n lll = lll.split(' ').map(v => parseInt(v))\n const v = lll[0]\n const l = lll[1]\n if (!ps[v]) {ps[v] = {bt: [], wt: [], n: 0, i: v}}\n ps[v].bt.push(l)\n ps[v].n++\n if (!ps[l]) {ps[l] = {bt: [], wt: [], n: 0, i: l}}\n ps[l].wt.push(v)\n ps[l].n++\n}\n\nlet min = Infinity\n\nfor (let i = 1; i < 4; i++) {\n min = Math.min(ps[i].n, min)\n}\n\nlet ms = []\n\nfor (let i = 1; i < ps.length; i++) {\n if (ps[i].n == min) ms.push(ps[i])\n}\n\nlet fv\nfor (let i = 1; i < ms[0].bt.length; i++) {\n if (~ms[1].wt.indexOf(ms[0].bt[i])) {\n fv = true;\n break\n }\n}\n\nprint(fv ? ms[0].i + ' ' + ms[1].i : ms[1].i + ' ' + ms[0].i)"}], "src_uid": "f1ac6da78aed11d9118a85182c5644de"} {"source_code": "readline()\nk=1\nfor(i of readline().split(' ').sort((a,b)=>a-b))k+=i>=k\nprint(k)", "positive_code": [{"source_code": "var n = Number(readline());\nvar array = readline().split(' ').map(Number);\n\narray.sort(function(a, b) {return a - b});\n\n// k is the new value for array[i];\nvar k = 1;\n\nfor (var i = 0; i < n; i++) {\n\tif (array[i] >= k) {\n\t\tarray[i] = k;\n\t\tk ++;\n\t}\n}\n\nvar mex = array[n - 1] + 1;\n\nprint(mex);"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar ans = 1, arr, n;\n\nn = Number(readline());\narr = readline().split(' ').map(Number).sort((a, b) => a - b);\n\nfor (i = 0; i < n; i++) {\n\n if (arr[i] >= ans) {\n\n ans++;\n } \n}\n\nprint(ans);"}, {"source_code": "l=+readline(),a=readline().split(' ').sort((a,b)=>a-b),k=1;\nfor(var i of a)if(+i>=k)++k;\nprint(k)"}, {"source_code": "l=+readline(),a=readline().split(' ').sort((a,b)=>a-b),k=1;\nfor(var i of a)if(+i>=k)++k;\nprint(k);"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(function(item){return parseInt(item)}).sort(function(a, b){return a-b})\nvar gaps = input[0] - 1, repeat = 0;\nfor(var i = 1; i < input.length; i++){\n\tvar diff = input[i] - input[i-1];\n\tif(diff === 0){\n\t\tif(gaps === 0){\n\t\t\trepeat++;\n\t\t} else {\n\t\t\tgaps--;\n\t\t}\n\t} else {\n\t\tgaps += diff - 1;\n\t}\n}\nvar mex = n - repeat + 1;\nprint(mex);"}, {"source_code": "\t\tvar arr = [],\n\t\t\tmex=1,\n\t\t\tquantity = readline().split(\" \").map(function(x) { return parseInt(x); }),\n\t\t\tstring = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\tfor (var i = 0; i < quantity; i++)\n\t\t{\n\t\t\tarr[i] = parseInt(string[i],10);\n\t\t}\n\t\tfunction compareNumeric(a, b) \n\t\t{\n \t\t\tif (a > b) return 1;\n \t\t\tif (a < b) return -1;\n\t\t}\n\t\tarr.sort(compareNumeric);\n\t\tfor (var i = 0; i < arr.length; i++) {\n\t\t\tif (arr[i] >= mex)\n\t\t\t\tmex++;\n\t\t}\n\t\tprint(mex);"}], "negative_code": [{"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar ans = 1, arr, n;\n\nn = Number(readline());\narr = readline().split(' ').map(Number).sort();\n\nfor (i = 0; i < n; i++) {\n\n if (arr[i] >= ans) {\n\n ans++;\n } \n}\n\nprint(ans);"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar ans = 1, arr, n;\n\nn = Number(readline());\narr = readline().split(' ').map(Number).sort();\n\nfor (i = 0; i < arr.length; i++) {\n\n if (arr[i] >= ans) {\n\n ans++;\n } \n}\n\nprint(ans);"}, {"source_code": "var n=+readline(),ar=readline().split(' '),i=0,k=1,l=ar.length;\nfor(i=l;i--;)ar[i]=+ar[i];\nar.sort();\nfor(i=0;i=k)++k;\nprint(k);"}, {"source_code": "\t\tvar arr = [],\n\t\t\tmex=0,\n\t\t\tquantity = readline().split(\" \").map(function(x) { return parseInt(x); }),\n\t\t\tstring = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\tfor (var i = 0; i < quantity; i++)\n\t\t{\n\t\t\tarr[i] = parseInt(string[i],10);\n\t\t}\n\t\tfunction compareNumeric(a, b) \n\t\t{\n \t\t\tif (a > b) return 1;\n \t\t\tif (a < b) return -1;\n\t\t}\n\t\tarr.sort(compareNumeric);\n\t\tfor (var i = 0; i < arr.length; i++) {\n\t\t\tif (arr[i] >= mex)\n\t\t\t\tmex++;\n\t\t}\n\t\tprint(mex);"}, {"source_code": "\t\tvar arr = [],\n\t\t\tmex=0,\n\t\t\tquantity = readline().split(\" \").map(function(x) { return parseInt(x); }),\n\t\t\tstring = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\tfor (var i = 0; i < quantity; i++)\n\t\t{\n\t\t\tarr[i] = parseInt(string[i],10);\n\t\t}\n\t\tfunction compareNumeric(a, b) \n\t\t{\n \t\t\tif (a > b) return 1;\n \t\t\tif (a < b) return -1;\n\t\t}\n\t\tarr.sort(compareNumeric);\n\t\tfor (var i = 0; i <= arr.length; i++) \n\t\t{\t\t\n\t\t\tarr[0] = 1;\n\t\t\twhile (arr[i] + 1 < arr[i+1]) \n\t\t\t{\n\t\t\t\tif ((arr[i] + 1) < arr[i+1])\n\t\t\t\t{\n\t\t\t\t\tarr[i+1] = arr[i+1] - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tvar max = 0;\n\t\tfor (var i = 1; i < arr.length; i++) {\n\t\t\tif (arr[i] > arr[i-1]) \n\t\t\t{\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t}\n\t\tmex = max + 1;\n\t\tprint(mex);"}, {"source_code": "\t\tvar arr = [],\n\t\t\tmex=0,\n\t\t\tquantity = readline().split(\" \").map(function(x) { return parseInt(x); }),\n\t\t\tstring = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\tfor (var i = 0; i < quantity; i++)\n\t\t{\n\t\t\tarr[i] = parseInt(string[i],10);\n\t\t}\n\t\tfunction compareNumeric(a, b) \n\t\t{\n \t\t\tif (a > b) return 1;\n \t\t\tif (a < b) return -1;\n\t\t}\n\t\tarr.sort(compareNumeric);\n\t\tfor (var i = 0; i <= arr.length; i++) \n\t\t{\t\t\n\t\t\tarr[0] = 1;\n\t\t\twhile (arr[i] + 1 < arr[i+1]) \n\t\t\t{\n\t\t\t\tif ((arr[i] + 1) < arr[i+1])\n\t\t\t\t{\n\t\t\t\t\tarr[i+1] = arr[i+1] - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tvar max = 0;\n\t\tfor (var i = 1; i < arr.length; i++) {\n\t\t\tif (arr[i] > arr[i-1]) \n\t\t\t{\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t}\n\t\tif (max == 1) {\n\t\t mex = 1;\n\t\t}\n\t\telse mex = max + 1;\n\t\tprint(mex);"}, {"source_code": "\t\tvar arr = [],\n\t\t\tmex=0,\n\t\t\tquantity = readline().split(\" \").map(function(x) { return parseInt(x); }),\n\t\t\tstring = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\tfor (var i = 0; i < quantity; i++)\n\t\t{\n\t\t\tarr[i] = parseInt(string[i],10);\n\t\t}\n\t\t\n\t\tfor (var i = 0; i <= arr.length; i++) \n\t\t{\t\t\n\t\t\tarr[0] = 1;\n\t\t\twhile (arr[i] + 1 < arr[i+1]) \n\t\t\t{\n\t\t\t\tif ((arr[i] + 1) < arr[i+1])\n\t\t\t\t{\n\t\t\t\t\tarr[i+1] = arr[i+1] - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tvar max = 1;\n\t\tfor (var i = 1; i < arr.length; i++) {\n\t\t\tif (arr[i] > arr[i-1]) \n\t\t\t{\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t}\n\t\tmex = max + 1;\n\t\tprint(mex);"}], "src_uid": "482b3ebbbadd583301f047181c988114"} {"source_code": "var isPalin = function(s){\n var n = s.length;\n s = s.split('');\n for(l = 0; l < Math.floor(n / 2); l++){\n if(s[l] != s[n - l - 1]){\n return false;\n }\n }\n return true;\n};\nlet y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0, k = 0, s = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t s = lines[i].split(' ').map(Number);\n\t n = s[0];\n\t k = s[1];\n\t }else{\n\t s = lines[i];\n if(k === 0 || isPalin(s)){\n console.log(1);\n }else{\n console.log(2);\n }\n\t }\n\t}\n});\n\n", "positive_code": [{"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n \r\nfunction readline() {\r\n\treturn inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\tconst cases = +(readline()); // Test cases count\r\n\tfor(let i = 0; i < cases; i++) {\r\n\t\t// console.log(`case ${i}`)\r\n\t\tconst [strLen, k] = readline().split(\" \").map((v) => parseInt(v));\r\n\t\tlet strings;\r\n\t\tconst s = readline();\r\n\t\tconst rev = [...s].reverse().join(\"\");\r\n\t\tconst set = new Set();\r\n\t\tset.add(s + rev);\r\n\t\tset.add(rev + s);\r\n\t\tstrings = set;\r\n\t\t// console.log(strings.get(0), strings.get(0).size);\r\n\t\tif(k === 0) console.log(1);\r\n\t\telse if(k === 1) console.log(strings.size);\r\n\t\telse console.log(strings.size);\r\n\t\t//else {\r\n\t\t//\tfor(let j = 1; j < k; j++) {\r\n\t\t//\t\tconst set = new Set();\r\n\t\t//\t\tconst ss = Array.from(strings);\r\n\t\t//\t\t// console.log(ss);\r\n\t\t//\t\tfor(let l = 0; l < strings.size; l++) {\r\n\t\t//\t\t\tconst s = ss[l];\r\n\t\t//\t\t\tconst rev = [...s].reverse().join(\"\");\r\n\t\t//\t\t\t// console.log(s, rev);\r\n\t\t//\t\t\tset.add(s + rev);\r\n\t\t//\t\t\tset.add(rev + s);\r\n\t\t//\t\t}\r\n\t\t//\t\tstrings = set;\r\n\t\t//\t\t// console.log(strings.get(j));\r\n\t\t//\t}\r\n\t\t//\tconsole.log(strings.size); // output\r\n\t\t//}\r\n\t\t//strings.clear();\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const isPalindrome = str => str === str.split('').reverse().join('');\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, k] = readline().split(' ').map(Number);\r\n let s = readline();\r\n\r\n if (k === 0) {\r\n output(1);\r\n continue;\r\n }\r\n if (isPalindrome(s)) output(1); else output(2);\r\n\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main(){\t\t\n\tlet t = parseInt(readLine())\n\twhile(t--){\n\t\tlet line = readLine().split(' ');\n\t\tlet n = parseInt(line[0]);\n\t\tlet k = parseInt(line[1]);\n\t\tlet s = readLine();\n\t\tif(s == s.split('').reverse().join('') || k == 0){\n\t\t\tconsole.log(1);\n\t\t}\n\t\telse console.log(2);\n\t}\n}\n\n\n"}, {"source_code": "'use strict';\n/* ================== */\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readline = () => inputString[currentLine++];\nconst readline_arr = () => readline().split(' ').map((n) => parseInt(n, 10));\nconst print = (...txt) => process.stdout.write(`${txt}\\n`)\n/* ================== */\n\nfunction main() {\n let t = parseInt(readline(), 10);\n while (t--) {\n solve();\n }\n}\n\nfunction solve() {\n const [l, op] = readline().split(' ').map((n) => parseInt(n, 10));\n const str = readline();\n \n let rev = '';\n for (let i = str.length - 1; i >= 0; i--) {\n rev += str[i];\n }\n\n if (str === rev || op === 0) print(1);\n else print(2);\n}\n"}, {"source_code": "'use strict';\n/* ================== */\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(...txt) {\n process.stdout.write(`${txt}\\n`);\n}\n/* ================== */\n\nfunction main() {\n let t = readline();\n while (t--) {\n solve();\n }\n}\n\nfunction solve() {\n const [l, op] = readline().split(' ').map((n) => parseInt(n, 10));\n const str = readline();\n \n let rev = '';\n for (let i = str.length - 1; i >= 0; i--) {\n rev += str[i];\n }\n\n if (str === rev || op === 0) print(1);\n else print(2);\n}\n"}, {"source_code": "// Create readline interface\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\n// Parse input\r\nlet t = null;\r\nconst nk = [];\r\nconst strings = [];\r\nlet i = 0;\r\nreadline.on('line', line => {\r\n if (t === null) {\r\n t = Number(line);\r\n } else {\r\n i++;\r\n if (i % 2) {\r\n nk.push(line.split(' ').map(Number));\r\n } else {\r\n strings.push(line.trim());\r\n }\r\n }\r\n});\r\n\r\nconst isPalindrome = str => str === [...str].reverse().join('');\r\n\r\n// Main program\r\nreadline.on('close', () => {\r\n for (let i = 0; i < t; i++) {\r\n const [n, k] = nk[i];\r\n const str = strings[i];\r\n if (k === 0) {\r\n console.log(1);\r\n } else {\r\n if (isPalindrome(str)) {\r\n console.log(1);\r\n } else {\r\n console.log(2);\r\n }\r\n }\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n // let isPalindrome = true;\n\n for (let i = 0; i < testCases; i++) {\n let [size, k] = readline().split(\" \");\n let s = readline();\n // console.log(k, s);\n if (k === \"0\") {\n console.log(1);\n } else {\n let mid = Math.floor(s.length / 2);\n let isPalindrome = true;\n for (let i = 0; i < mid; i++) {\n if (s[i] !== s[s.length - 1 - i]) {\n isPalindrome = false;\n break;\n }\n }\n console.log(isPalindrome ? 1 : 2);\n }\n }\n\n // return isPalindrome ? k : 2 * k;\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const isPalindrome = str => str === str.split('').reverse().join('');\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, k] = readline().split(' ').map(Number);\r\n let s = readline();\r\n\r\n if (k === 0) {\r\n output(1);\r\n continue;\r\n }\r\n if (isPalindrome(s)) output(k); else output(2);\r\n\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main(){\t\t\n\tlet t = parseInt(readLine())\n\twhile(t--){\n\t\tlet line = readLine().split(' ');\n\t\tlet n = parseInt(line[0]);\n\t\tlet k = parseInt(line[1]);\n\t\tlet ans = 1;\n\t\tlet s = readLine();\n\t\tif(s == s.reverse){\n\t\t\tconsole.log(ans);\n\t\t\tcontinue;\n\t\t}\n\t\tk = parseInt(k/2);\n\t\tconsole.log((ans< +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber(' ');\n\n var min = Infinity;\n\n for(var i = 0; i < n; i++) {\n\n var l = i;\n var r = n - 1 - i;\n var res = Math.floor(a[i] / (l > r ? l : r));\n if(res < min) {\n min =res;\n }\n }\n\n print(min);\n\n}());", "positive_code": [{"source_code": "const input = require('fs')\n .readFileSync(0, 'ascii')\n .split('\\n')\n .filter(line => !/^\\s*$/.test(line))\n .map(l => l.split(' ').map(w => parseInt(w)));\nconst [[n], a] = input;\n\nfunction max_k(x, i) {\n let l = Infinity, r = Infinity;\n if (i > 0)\n l = x / i;\n if (i < n - 1)\n r = x / (n - 1 - i);\n return Math.floor(Math.min(l, r));\n}\n\nfunction min(xs) {\n r = xs[0];\n for (x of xs) {\n if (x < r)\n r = x;\n }\n return r;\n}\n\nconsole.log(min(a.map(max_k)));\n"}], "negative_code": [], "src_uid": "f146808eb6e0ee04d531e7222a53d275"} {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, k, b)=>{\n let ans = BigInt(0);\n let sum = 0;\n let cnt = 0;\n let closed = new Array(n).fill(0);\n for (let i=n-1; i>=0; i--){\n sum -= (cnt);\n cnt -= closed[i]\n b[i] -= sum;\n if (b[i]<=0)\n continue;\n let el = Math.min(i+1, k)\n let need = Math.floor((b[i]+el-1) / el)\n sum += need * el;\n cnt += need;\n ans += BigInt(need);\n if (i-el>=0)\n closed[i-el] += need;\n }\n return ans.toString()\n};\n \nfunction main() {\n let T = 1||+readline()\n while (T--){\n let [n, k] = ra();\n let b = ra();\n l('ans')\n print(calc(n, k, b));\n }\n}\n \nE.calc = calc;", "positive_code": [{"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, k, b)=>{\n let ans = BigInt(0);\n let sum = 0;\n let cnt = 0;\n let closed = new Array(n).fill(0);\n for (let i=n-1; i>=0; i--){\n sum -= (cnt);\n cnt -= closed[i]\n b[i] -= sum;\n if (b[i]<=0)\n continue;\n let el = Math.min(i+1, k)\n let need = Math.ceil(b[i] / el)\n sum += need * el;\n cnt += need;\n ans += BigInt(need);\n if (i-el>=0)\n closed[i-el] += need;\n }\n return ans.toString()\n};\n \nfunction main() {\n let T = 1||+readline()\n while (T--){\n let [n, k] = ra();\n let b = ra();\n l('ans')\n print(calc(n, k, b));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst MAN = 10 ** 15\r\nconst add = (a, b) => {\r\n if (typeof a === 'bigint' || typeof a === 'bigint' || a + b >= MAN) return BigInt(a) + BigInt(b)\r\n return a + b\r\n}\r\nconst mul = (a, b) => {\r\n if (typeof a === 'bigint' || typeof a === 'bigint' || a * b >= MAN) return BigInt(a) * BigInt(b)\r\n return a * b\r\n}\r\nconst sub = (a, b) => {\r\n if (typeof a === 'number' && typeof b === 'number') return a - b\r\n let res = BigInt(a) - BigInt(b)\r\n if (res >= MAN) return res\r\n return Number(res)\r\n}\r\n\r\nfunction solve(n, k, data) {\r\n const nums = new Array(n).fill(0)\r\n let res = 0,\r\n sum = 0,\r\n base = 0\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i + 1 < k) k--\r\n sum = sub(sum, base)\r\n base = add(base, nums[i])\r\n\r\n let cur = Math.max(0, Math.ceil(sub(data[i], sum) / k))\r\n\r\n res = add(res, cur)\r\n base = add(base, cur)\r\n\r\n if (i >= k) nums[i - k] = -cur\r\n sum = add(sum, mul(cur, k))\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n const [n, k] = inputs[0].split(' ').map(Number)\r\n const data = inputs[1].split(' ').map(Number)\r\n\r\n console.log(solve(n, k, data).toString())\r\n})()\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(BigInt)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\n// inspired by https://www.luogu.com.cn/blog/kkxhh/solution-p1438\nfunction solve(n, k, arr) {\n const tree = []\n createTree(tree, 0, 0, n - 1, 0n)\n let ans = 0n\n for (let i = arr.length - 1; i >= 0; i--) {\n const now = queryTree(tree, 0, i, i, 0n, 0n)\n if (now >= arr[i]) continue\n\n const rk = Math.min(i + 1, k)\n // const t = Math.ceil((arr[i] - now) / rk)\n const t = ceil((arr[i] - now), BigInt(rk))\n const left = i - rk + 1\n // [left, right] + [1, k]\n // for each, 1 - left + `i`\n insertTree(tree, 0, left, i, [BigInt(1 - left) * t, t])\n ans += t\n }\n// console.log(tree)\n return ans\n}\nfunction ceil(a, b) {\n const r = a % b\n return r ? a / b + 1n : a / b\n}\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: [0n, 0n] }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction insertTree(tree, idx, l, r, val) { // same l, r\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n // tree[idx].val += lazy\n // tree[idx].lazy = tree[idx].lazy || [0n, 0n]\n tree[idx].lazy[0] += val[0]\n tree[idx].lazy[1] += val[1]\n return\n }\n\n // if (lazy && left !== right) {\n // // tree[2 * idx + 1].val += lazy\n // // tree[2 * idx + 2].val += lazy\n // tree[2 * idx + 1].lazy = tree[2 * idx + 1].lazy || [0n, 0n]\n // tree[2 * idx + 1].lazy[0] += lazy[0]\n // tree[2 * idx + 1].lazy[1] += lazy[1]\n // tree[2 * idx + 2].lazy = tree[2 * idx + 2].lazy || [0n, 0n]\n // tree[2 * idx + 2].lazy[0] += lazy[0]\n // tree[2 * idx + 2].lazy[1] += lazy[1]\n // tree[idx].lazy = null\n // }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n // const merge = add\n // tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r, t1, t2) {\n const { left, right, val, lazy } = tree[idx]\n if (left === right) {\n return (lazy[0] + t1) + BigInt(left) * (lazy[1] + t2)\n }\n// if (lazy && left === right) {\n// tree[idx].val += (lazy[0] + t1) + BigInt(left) * (lazy[1] + t2)\n// // console.log('relax', left, right, tree[idx].val)\n// // tree[idx].lazy = null\n// }\n// if (l <= left && r >= right) return tree[idx].val\n\n const mid = Math.floor((left + right) / 2)\n // if (lazy) {\n // // tree[2 * idx + 1].val += lazy\n // // tree[2 * idx + 2].val += lazy\n // tree[2 * idx + 1].lazy = tree[2 * idx + 1].lazy || [0n, 0n]\n // tree[2 * idx + 1].lazy[0] += lazy[0]\n // tree[2 * idx + 1].lazy[1] += lazy[1]\n // tree[2 * idx + 2].lazy = tree[2 * idx + 2].lazy || [0n, 0n]\n // tree[2 * idx + 2].lazy[0] += lazy[0]\n // tree[2 * idx + 2].lazy[1] += lazy[1]\n // tree[idx].lazy = null\n // }\n\n let a = 0n\n let b = 0n\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r, t1 + lazy[0], t2 + lazy[1])\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r, t1 + lazy[0], t2 + lazy[1])\n }\n const merge = add\n return merge(a, b)\n}\nfunction add(a, b) {\n return a + b\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const tree = []\n createTree(tree, 0, 0, n - 1, 0)\n let ans = 0\n for (let i = arr.length - 1; i >= 0; i--) {\n const now = queryTree(tree, 0, i, i)\n if (now >= arr[i]) continue\n\n const rk = Math.min(i + 1, k)\n const t = Math.ceil((arr[i] - now) / rk)\n insertTree(tree, 0, i - rk + 1, i, [i - rk, t])\n ans += t\n }\n// console.log(tree)\n return ans\n}\nfunction createTree(tree, p, left, right, val) {\n tree[p] = { left, right, val, lazy: [] }\n if (left === right) return\n\n const mid = Math.floor((left + right) / 2)\n createTree(tree, 2 * p + 1, left, mid, val)\n createTree(tree, 2 * p + 2, mid + 1, right, val)\n}\nfunction insertTree(tree, idx, l, r, val) { // same l, r\n const { left, right, lazy } = tree[idx]\n if (l <= left && r >= right) {\n // tree[idx].val += lazy\n tree[idx].lazy.push(val)\n return\n }\n\n if (lazy.length && left !== right) {\n // tree[2 * idx + 1].val += lazy\n // tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy.push(...lazy)\n tree[2 * idx + 2].lazy.push(...lazy)\n tree[idx].lazy = []\n }\n\n const mid = Math.floor((left + right) / 2)\n if (l <= mid) {\n insertTree(tree, 2 * idx + 1, l, r, val)\n }\n if (r > mid) {\n insertTree(tree, 2 * idx + 2, l, r, val)\n }\n const merge = add\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\n}\nfunction queryTree(tree, idx, l, r) {\n const { left, right, val, lazy } = tree[idx]\n if (lazy.length && left === right) {\n lazy.forEach(([x, t]) => {\n tree[idx].val += (left - x) * t\n })\n// console.log('relax', left, right, tree[idx].val)\n tree[idx].lazy = []\n }\n if (l <= left && r >= right) return tree[idx].val\n\n const mid = Math.floor((left + right) / 2)\n if (lazy.length) {\n // tree[2 * idx + 1].val += lazy\n // tree[2 * idx + 2].val += lazy\n tree[2 * idx + 1].lazy.push(...lazy)\n tree[2 * idx + 2].lazy.push(...lazy)\n tree[idx].lazy = []\n }\n\n let a = 0\n let b = 0\n if (l <= mid) {\n a = queryTree(tree, 2 * idx + 1, l, r)\n }\n if (r > mid) {\n b = queryTree(tree, 2 * idx + 2, l, r)\n }\n const merge = add\n return merge(a, b)\n}\nfunction add(a, b) {\n return a + b\n}\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, k, b)=>{\n let ans = (0);\n let sum = 0;\n let cnt = 0;\n let closed = new Array(n).fill(0);\n for (let i=n-1; i>=0; i--){\n sum -= (cnt);\n cnt -= closed[i]\n b[i] -= sum;\n if (b[i]<=0)\n continue;\n let el = Math.min(i+1, k)\n let need = Math.floor((b[i]+el-1) / el)\n sum += need * el;\n cnt += need;\n ans += (need);\n if (i-el>=0)\n closed[i-el] += need;\n }\n return ans.toString()\n};\n \nfunction main() {\n let T = 1||+readline()\n while (T--){\n let [n, k] = ra();\n let b = ra();\n l('ans')\n print(calc(n, k, b));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst MAN = 10 ** 15\r\nconst add = (a, b) => {\r\n if (typeof a === 'bigint' || typeof a === 'bigint' || a + b >= MAN) return BigInt(a) + BigInt(b)\r\n return a + b\r\n}\r\nconst mul = (a, b) => {\r\n if (typeof a === 'bigint' || typeof a === 'bigint' || a * b >= MAN) return BigInt(a) * BigInt(b)\r\n return a * b\r\n}\r\nconst sub = (a, b) => {\r\n if (typeof a === 'number' && typeof b === 'number') return a - b\r\n let res = BigInt(a) - BigInt(b)\r\n if (res >= MAN) return res\r\n return Number(res)\r\n}\r\n\r\nfunction solve(n, k, data) {\r\n const nums = new Array(n).fill(0)\r\n let res = 0,\r\n sum = 0,\r\n base = 0\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i + 1 < k) k--\r\n sum = sub(sum, base)\r\n base = add(base, nums[i])\r\n\r\n let cur = Math.max(0, Math.ceil(sub(data[i], sum) / k))\r\n\r\n res = add(res, cur)\r\n base = add(base, cur)\r\n\r\n if (i >= k) nums[i - k] = -cur\r\n sum = add(sum, mul(cur, k))\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n const [n, k] = inputs[0].split(' ').map(Number)\r\n const data = inputs[1].split(' ').map(Number)\r\n\r\n console.log(solve(n, k, data))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, k, data) {\r\n const nums = new Array(n).fill(0)\r\n let res = 0,\r\n sum = 0,\r\n base = 0\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i + 1 < k) k--\r\n sum -= base\r\n base += nums[i]\r\n\r\n let cur = Math.max(0, Math.ceil((data[i] - sum) / k))\r\n\r\n res += cur\r\n base += cur\r\n if (i >= k) nums[i - k] = -cur\r\n\r\n sum += cur * k\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n const [n, k] = inputs[0].split(' ').map(Number)\r\n const data = inputs[1].split(' ').map(Number)\r\n\r\n console.log(solve(n, k, data))\r\n})()\r\n"}], "src_uid": "f5f3b9c93060f231a55b941a7fa804e1"} {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, k, nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++;\n});\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n let sort = nArr.sort((a, b) => {\n if ( a < b) {\n return -1;\n }\n if ( a > b) {\n return 1;\n }\n return 0;\n });\n let rightArr = sort.splice(((n - 1)/2));\n let len = rightArr.length;\n let result = rightArr[0];\n let minIndex = rightArr.lastIndexOf(result);\n let tempIndex = minIndex;\n if ( k <= minIndex) {\n return result;\n }\n\n let count = k;\n while (count) {\n if (tempIndex + 1 === len) {\n // \u5168\u52a0\u6ee1\u4e86\uff0c\u6570\u7ec4\u4e2d\u6570\u636e\u5b8c\u5168\u76f8\u540c\n // count \u5269\u4f59\u7684\u6b21\u6570\n let lastCount = Math.floor(count / len);\n result += lastCount;\n break;\n } else {\n let resultNext = rightArr[tempIndex + 1];\n let gap = resultNext - result;\n if (gap > 0) {\n // \u4e0d\u4e00\u5b9a\u80fd\u52a0\u5b8c\uff0c\u770bcount\u8fd8\u5269\u591a\u5c11\n let curCount = gap * (tempIndex + 1)\n if (count < curCount) {\n // \u5269\u4f59\u6b21\u6570\u4e0d\u591f\u6bcf\u4e2a+gap \u7b97\u51fa\u80fd\u52a0\u591a\u5c11\u6b21\n result += Math.floor(count / (tempIndex + 1));\n break;\n }\n result += gap;\n count -= curCount;\n }\n if (count < 0) {\n // count \u4f1a<0\n break;\n }\n // \u6570\u7ec4\u7684\u4e0b\u4e00\u4e2a\n tempIndex += 1;\n }\n }\n return result;\n}\n", "positive_code": [{"source_code": "var nm = readline().split(' ').map(item => +item);\nvar arr = readline().split(' ').map(item => +item).sort((a, b) => a - b);\nvar m = ~~(arr.length / 2);\nvar k = m + 1;\n\nwhile(nm[1] > 0) {\n if(k === arr.length) {\n d = k - m;\n arr[m] += ~~(nm[1] / d);\n break;\n }\n \n if(arr[m] < arr[k]) {\n var val = arr[k] - arr[m];\n var d = k - m;\n var c = val * d;\n if(c < nm[1]) {\n arr[m] += val;\n nm[1] -= c;\n } else {\n arr[m] += ~~(nm[1] / d);\n break;\n }\n } else {\n k++;\n }\n}\n\nprint(arr[m]);"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var k = input[1];\n var A = rdArN();\n \n A.sortLt();\n var mid = Math.floor(n/2);\n A = A.slice(mid);\n \n var len = n - mid;\n var step = 1;\n var lastHeight = A[0];\n //pr(A);\n //pr(len, step, lastHeight)\n while (true) {\n if (step >= len) {\n break;\n }\n var nextHeight = A[step];\n var needToAdd = step*(nextHeight - lastHeight)\n //pr(needToAdd);\n if (needToAdd <= k) {\n k -= needToAdd;\n lastHeight = nextHeight;\n ++step;\n } else {\n break;\n }\n }\n lastHeight += Math.floor(k/step);\n wr(lastHeight);\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, k, nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n let sort = nArr.sort((a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n });\n let rightArr = sort.splice(((n - 1)/2));\n let len = rightArr.length;\n let result = rightArr[0];\n let minIndex = rightArr.lastIndexOf(result);\n let tempIndex = minIndex\n if ( k <= minIndex) {\n return result;\n }\n let loseCount = 0;\n let lastCount = 0\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 <= k + loseCount) {\n lastCount = Math.floor((k + loseCount - i) / len);\n break;\n }\n } else {\n let resultNext = rightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n result += 1;\n } else { \n loseCount += tempIndex;\n tempIndex += 1;\n }\n }\n }\n if (lastCount) {\n result += lastCount\n }\n\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n let loseCount = 0;\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 < k) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n // \u5f53\u524d\u503c\u6bd4\u4e0b\u4e00\u4e2a\u503c\u5c0f\uff0c\u5219\u5728\u5f53\u524d\u503c\u4e0a\u4e00\u76f4\u589e\u52a0\n result += 1;\n } else {\n tempIndex += 1;\n // \u4e22\u4e86\u4e00\u6bb5\n loseCount += tempIndex;\n }\n }\n }\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, k, nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n let sort = nArr.sort((a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n });\n let rightArr = sort.splice(((n - 1)/2));\n let len = rightArr.length;\n let result = rightArr[0];\n let minIndex = rightArr.lastIndexOf(result);\n let tempIndex = minIndex\n if ( k <= minIndex) {\n return result;\n }\n let loseCount = 0;\n let lastCount = 0\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 <= k + loseCount) {\n lastCount = Math.ceil((k + loseCount - i) / len);\n break;\n }\n } else {\n let resultNext = rightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n result += 1;\n } else { \n loseCount += tempIndex;\n tempIndex += 1;\n }\n }\n }\n if (lastCount) {\n result += lastCount\n }\n\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, k, nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++;\n});\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n let sort = nArr.sort((a, b) => {\n if ( a < b) {\n return -1;\n }\n if ( a > b) {\n return 1;\n }\n return 0;\n });\n let rightArr = sort.splice(((n - 1)/2));\n let len = rightArr.length;\n let result = rightArr[0];\n let minIndex = rightArr.lastIndexOf(result);\n let tempIndex = minIndex;\n if ( k <= minIndex) {\n return result;\n }\n\n let count = k;\n while (count) {\n if (tempIndex + 1 === len) {\n // \u5168\u52a0\u6ee1\u4e86\uff0c\u6570\u7ec4\u4e2d\u6570\u636e\u5b8c\u5168\u76f8\u540c\n // count \u5269\u4f59\u7684\u6b21\u6570\n let lastCount = Math.floor(count / len);\n result += lastCount;\n count = 0;\n break;\n } else {\n let resultNext = rightArr[tempIndex + 1];\n let gap = resultNext - result;\n if (gap > 0) {\n result += gap;\n count -= gap * (tempIndex + 1);\n }\n tempIndex += 1;\n }\n }\n return result;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n let loseCount = 0;\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 < k) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n // \u5f53\u524d\u503c\u6bd4\u4e0b\u4e00\u4e2a\u503c\u5c0f\uff0c\u5219\u5728\u5f53\u524d\u503c\u4e0a\u4e00\u76f4\u589e\u52a0\n result += 1;\n } else {\n // \u4e22\u4e86\u4e00\u6b21\u52a0\u4e00\n loseCount += 1;\n tempIndex += 1;\n }\n }\n }\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0\nlet n\nlet k\nlet nArr\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ')\n n = parseInt(resOne[0])\n k = parseInt(resOne[1])\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item))\n console.log(maximumMedian(n, k, nArr))\n rl.close()\n }\n lineCount ++\n})\n\nfunction maximumMedian(n, k, nArr) {\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let count = 0\n\n let sort = nArr.sort(sortFun)\n let medianAndRightArr = sort.splice(((n - 1)/2))\n\n\n function addOne(arr) {\n let sortRes = arr.sort(sortFun)\n if (count === k) {\n return sortRes[0]\n }\n count++\n if (sortRes[0] <= sortRes[1]) {\n sortRes[0] += 1\n } else {\n sortRes[1] += 1\n }\n return addOne(sortRes)\n }\n return addOne(medianAndRightArr)\n}\n\n\n\n\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n\n for (let i = 0 ; i < k; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 <= k) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n result += 1;\n } else {\n tempIndex += 1;\n }\n }\n }\n\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n let loseCount = 0;\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 < k + loseCount) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n // \u5f53\u524d\u503c\u6bd4\u4e0b\u4e00\u4e2a\u503c\u5c0f\uff0c\u5219\u5728\u5f53\u524d\u503c\u4e0a\u4e00\u76f4\u589e\u52a0\n result += 1;\n } else {\n // \u4e22\u4e86\u4e00\u6bb5\n // TODO \n loseCount += tempIndex;\n tempIndex += 1;\n }\n }\n }\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n let loseCount = 0;\n for (let i = 0 ; i < k + loseCount; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 < k) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n // \u5f53\u524d\u503c\u6bd4\u4e0b\u4e00\u4e2a\u503c\u5c0f\uff0c\u5219\u5728\u5f53\u524d\u503c\u4e0a\u4e00\u76f4\u589e\u52a0\n result += 1;\n } else {\n // \u4e22\u4e86\u4e00\u6bb5\n loseCount += tempIndex;\n tempIndex += 1;\n }\n }\n }\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet n;\nlet k;\nlet nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++\n})\n\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n const sortFun = (a, b) => {\n if ( a < b) {\n return -1\n }\n if ( a > b) {\n return 1\n }\n return 0\n }\n\n let sort = nArr.sort(sortFun);\n let medianAndRightArr = sort.splice(((n - 1)/2));\n\n \n let len = medianAndRightArr.length;\n let result = medianAndRightArr[0];\n\n\n let minIndex = medianAndRightArr.lastIndexOf(result);\n let tempIndex = minIndex\n\n if ( k <= minIndex) {\n return result;\n }\n\n\n for (let i = 0 ; i < k; i +=(tempIndex + 1)) {\n if (tempIndex === (len - 1)) {\n if (i + tempIndex + 1 < k) {\n // \u6700\u540e\u4e00\u4e2a\uff0c\u626b\u8fc7\u4e00\u904d\uff0c\u503c\u90fd\u76f8\u7b49\u4e86\n result += 1;\n }\n } else {\n let resultNext = medianAndRightArr[tempIndex + 1];\n if (result < resultNext + 1) {\n result += 1;\n } else {\n tempIndex += 1;\n }\n }\n }\n\n return result;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, k, nArr;\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n k = parseInt(resOne[1]);\n }\n if (lineCount === 1) {\n nArr = line.trim().split(' ').map((item) => parseInt(item));\n console.log(maximumMedian(n, k, nArr));\n rl.close();\n }\n lineCount ++;\n});\n\nfunction maximumMedian(n, k, nArr) {\n if (n === 1) {\n return nArr[0] += k;\n }\n let sort = nArr.sort((a, b) => {\n if ( a < b) {\n return -1;\n }\n if ( a > b) {\n return 1;\n }\n return 0;\n });\n let rightArr = sort.splice(((n - 1)/2));\n let len = rightArr.length;\n let result = rightArr[0];\n let minIndex = rightArr.lastIndexOf(result);\n let tempIndex = minIndex;\n if ( k <= minIndex) {\n return result;\n }\n\n let count = k;\n while (count) {\n if (tempIndex + 1 === len) {\n // \u5168\u52a0\u6ee1\u4e86\uff0c\u6570\u7ec4\u4e2d\u6570\u636e\u5b8c\u5168\u76f8\u540c\n // count \u5269\u4f59\u7684\u6b21\u6570\n let lastCount = Math.floor(count / len);\n result += lastCount;\n break;\n } else {\n let resultNext = rightArr[tempIndex + 1];\n let gap = resultNext - result;\n if (gap > 0) {\n result += gap;\n count -= gap * (tempIndex + 1);\n }\n if (count < 0) {\n // count \u4f1a<0\n break;\n }\n // \u6570\u7ec4\u7684\u4e0b\u4e00\u4e2a\n tempIndex += 1;\n }\n }\n return result;\n}\n"}, {"source_code": "var nm = readline().split(' ').map(item => +item);\nvar arr = readline().split(' ').map(item => +item).sort((a, b) => a - b);\nvar m = ~~(arr.length / 2);\nvar k = m + 1;\n\nwhile(nm[1] > 0) {\n if(k === arr.length) {\n d = k - m;\n arr[m] += ~~(nm[1] / d);\n break;\n }\n \n if(arr[m] < arr[k]) {\n var val = arr[k] - arr[m];\n var d = k - m;\n var c = val * d;\n if(c < nm[1]) {\n arr[m] += val;\n nm[1] -= c;\n } else {\n arr[m] += ~~(nm[1] / d);\n break;\n }\n } else {\n k++;\n }\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var k = input[1];\n var A = rdArN();\n \n A.sortLt();\n var mid = Math.floor(n/2);\n A = A.slice(mid);\n \n var len = n - mid;\n var step = 1;\n var lastHeight = A[0];\n //pr(A);\n //pr(len, step, lastHeight)\n while (true) {\n if (step >= len) {\n break;\n }\n var nextHeight = A[step];\n var needToAdd = step*(nextHeight - lastHeight)\n //pr(needToAdd);\n if (needToAdd <= k) {\n k -= needToAdd;\n lastHeight = nextHeight;\n ++step;\n } else {\n break;\n }\n }\n lastHeight += Math.floor(k/len);\n wr(lastHeight);\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "0efd4b05b3e2e3bc80c93d37508a5197"} {"source_code": "readline();\nvar numbers = readline().split(\" \").map(x => ({ w: parseInt(x) }));\nvar sorted = numbers.slice().sort((x, y) => x.w - y.w);\nvar c = 0;\nsorted.forEach(x => {\n\tif(c x.r).join(\" \"));", "positive_code": [{"source_code": ";(function() {\n\n\tvar n = +readline(),\n\t\tb = [],\n\t\ta = readline().split(' ').map(function (e, i) { b[i] = i; return +e; });\n\n\tb.sort(function(x,y){ return a[x] - a[y]; });\n\n\tfor (i = 1 ; i < n ; ++i)\n\t\tif (a[b[i]] <= a[b[i-1]])\n\t\t\ta[b[i]] = a[b[i-1]] + 1;\n\n\tprint(a.join(' '));\n\n}).call(this);"}, {"source_code": "(function() {\n var n = parseInt(readline());\n var a = readline().split(' ');\n var i, id = [];\n for(i = 0 ; i < n ; ++i ){\n a[i] = parseInt(a[i]);\n id[i] = i;\n }\n id.sort(function(x,y){\n return a[x]-a[y];\n })\n for(i = 1 ; i < n ; ++i){\n if ( a[id[i]] <= a[id[i-1]] ){\n a[id[i]] = a[id[i-1]] + 1;\n }\n }\n print(a.join(' '));\n})();"}, {"source_code": "var n = parseInt( readline() );\nvar b = readline().split(' ').map(function(v, i){\n\treturn {\n\t\tv: parseInt(v),\n\t\ti: i\n\t};\n});\n\nb.sort(function(a,b){return a.v===b.v?0:( a.v>b.v?1:-1 );});\n\nvar ret = [];\nvar h = 0;\nfor(var i=0;i= start){\r\n d = Math.min(d, min)\r\n }\r\n c = Math.min(c,min)\r\n }\r\n \r\n if(d !== 2000){\r\n d = d - start\r\n print(parseInt(d / 60), d % 60 )\r\n }else{\r\n c = (1440 - start) + c\r\n print(parseInt(c / 60), c % 60 )\r\n }\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i=0;iparseInt(x));\r\n var n=nhm[0],h=nhm[1],m=nhm[2];\r\n var x=h*60+m;\r\n var ans=1000000;\r\n for(var j=0;jparseInt(x));\r\n var h1=h1m1[0],m1=h1m1[1];\r\n if(x<=h1*60+m1){\r\n ans=Math.min(ans,h1*60+m1-x);\r\n }\r\n else{\r\n ans=Math.min(ans,24*60 + (h1*60+m1) - x)\r\n }\r\n }\r\n print(Math.floor(ans/60) , ans- 60*Math.floor(ans/60));\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n var n, h, m;\r\n var alarms;\r\n for (var t=0; t < tests; t++) {\r\n var nhm = readline().split(' ').map(x=>parseInt(x));\r\n n = nhm[0];\r\n h = nhm[1];\r\n m = nhm[2];\r\n alarms = [];\r\n for (var i = 0; i < n; i++) {\r\n var a = readline().split(' ').map(x=>parseInt(x));\r\n alarms.push(a[0] * 60 + a[1]);\r\n }\r\n var sleep = h * 60 + m;\r\n var min = 24*60;\r\n for (var i = 0; i < n; i++) {\r\n var diff = alarms[i] - sleep;\r\n if ( diff < 0 ) {\r\n diff += 24*60;\r\n }\r\n if (diff < min) {\r\n min = diff;\r\n }\r\n }\r\n var hour = Math.floor(min/60);\r\n var minute = min - hour*60;\r\n print(hour + ' ' + minute);\r\n }"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction calc(H, M, alarms) {\n // console.log(H)\n // console.log(M)\n // console.log(alarms)\n next_alarm(H, M, alarms)\n\n}\n\nfunction next_alarm(H, M, alarms) {\n let k = alarms.length\n let min = Number.MAX_SAFE_INTEGER\n for(let i = 0; i < k; i++) {\n let hour = alarms[i].h\n let minute = alarms[i].m\n var _diff = 0\n\n if (hour == H && minute == M) {\n console.log(\"0 0\")\n return\n }\n\n if ((hour == H && minute > M) || (hour > H)) { // alarm later than in day\n _diff = Math.abs(new Date('2011/10/09 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n } else {\n _diff = Math.abs(new Date('2011/10/10 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n }\n\n if (_diff/1000 < min) {\n min = _diff/1000\n }\n\n // alarms[i].diff = _diff/1000\n }\n\n // console.log(alarms)\n\n let hour = (min/3600)|0\n let minute = (min%3600)/60\n\n console.log(hour + \" \" + minute)\n\n\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_h_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_h_m[0]\n const H = n_h_m[1]\n const M = n_h_m[2]\n\n let alarms = []\n\n for(let i = 0; i < n; i ++) {\n const hm = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n alarms.push({\"h\": hm[0], \"m\": hm[1]})\n }\n\n calc(H, M, alarms)\n\n }\n\n // ws.end();\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n const t = +readLine();\r\n \r\n \r\n for(let j = 0;j +p)\r\n const N = a[0];\r\n const H = a[1];\r\n const M = a[2];\r\n \r\n const Tot = H*60 + M;\r\n \r\n let ans = 24000;\r\n \r\n for(let i = 0;i +p);\r\n \r\n let h = x[0];\r\n let m = x[1];\r\n \r\n let time = h*60 + m;\r\n \r\n if(time Number(item));\n let now = H * 60 + M;\n\n let res = Infinity;\n for (let i = 0; i < n; i++) {\n const [h, m] = cl().split(' ').map((item) => Number(item));\n let diff = h * 60 + m - now;\n if (diff < 0) diff += 1440;\n res = Math.min(res, diff); \n }\n\n co(`${res / 60 | 0} ${res % 60}`);\n}\n\nfunction Solution() {\n let n = Number(cl());\n while (n--) solve();\n}\n\nlet i = 0;\nconst lines = []\n\nfunction cl() { return lines[i++] }\nfunction co(str) { console.log(str)}\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', (input) => lines.push(input));\nrl.on('close', Solution);"}, {"source_code": "function solve() {\n const [n, H, M] = cl().split(' ').map((item) => Number(item));\n let now = H * 60 + M;\n\n const times = [];\n for (let i = 0; i < n; i++) {\n const [h, m] = cl().split(' ').map((item) => Number(item));\n times[i] = h * 60 + m;\n }\n\n times.sort((x, y) => x - y);\n\n if (now > times[n - 1]) now -= 60 * 24;\n \n for (let i = 0; i < n; i++) {\n if (times[i] > now) {\n times[i] -= now;\n return co(`${times[i] / 60 | 0} ${times[i] % 60}`);\n }\n if (times[i] === now) return co('0 0');\n }\n}\n\nfunction Solution() {\n let n = Number(cl());\n while (n--) solve();\n}\n\nlet i = 0;\nconst lines = []\n\nfunction cl() { return lines[i++] }\nfunction co(str) { console.log(str)}\nconst { time } = require('console');\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', (input) => lines.push(input));\nrl.on('close', Solution);"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const a = readLine().split(' ').map(p => +p);\r\n const n = a[0];\r\n const H = a[1];\r\n const M = a[2];\r\n let arr = [], aux;\r\n for(let j = 0; j < n; j++){\r\n aux = readLine().split(' ').map(p => +p);\r\n arr.push(aux);\r\n }\r\n let result = myFunc(H, M, arr);\r\n console.log(...result);\r\n }\r\n}\r\n\r\nfunction myFunc(H, M, arr){\r\n\r\n let c = (60*H + M);\r\n let min = Infinity;\r\n let min_val = Infinity;\r\n let aux, item;\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n item = arr[i];\r\n aux = (60*item[0] + item[1]);\r\n if(aux < min_val){\r\n min_val = aux;\r\n }\r\n if(aux >= c && aux < min){\r\n min = aux;\r\n }\r\n }\r\n\r\n if(min == Infinity){\r\n min_val = 1440 - c + min_val;\r\n return [parseInt(min_val/60), min_val%60]; \r\n } \r\n min = min - c;\r\n return [parseInt(min/60), min%60];\r\n\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var min = 24 * 60;\r\n var minI;\r\n var a = readline().split(\" \").map(Number);\r\n var MinS = a[1] * 60 + a[2];\r\n for (let j = 0; j < a[0]; j++) {\r\n var b = readline().split(\" \").map(Number);\r\n var minB = b[0] * 60 + b[1];\r\n if (minB < MinS) {\r\n minI = minB - MinS + 24 * 60;\r\n } else {\r\n minI = minB - MinS;\r\n }\r\n if (minI < min) {\r\n min = minI\r\n }\r\n }\r\n console.log((parseInt(min / 60)) + ' ' + (min % 60));\r\n }\r\n\r\n}"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() { return inputs.next().value.trim(); };\r\n\r\nasync function solve() {\r\n const day = 24 * 60\r\n let [n, H, M] = (await read()).split(' ').map(Number)\r\n let current_day_time = H * 60 + M\r\n\r\n let n_list = []\r\n for (let i = 0; i < n; i++) {\r\n const [h, m] = (await read()).split(' ').map(Number)\r\n n_list.push(h * 60 + m)\r\n }\r\n\r\n let overlap = day % current_day_time\r\n\r\n let intervals = n_list\r\n .map(e => {\r\n const interval = e - current_day_time\r\n if (interval < 0) {\r\n let v = day - current_day_time + e\r\n return v\r\n }\r\n if (interval > 0) {\r\n return interval\r\n }\r\n if (interval == 0) {\r\n return 0\r\n }\r\n })\r\n\r\n let result = Math.min(...intervals)\r\n return `${Math.floor(result / 60)} ${result % 60}`\r\n}\r\n\r\nasync function main() {\r\n let tasks_amount = parseInt(await read())\r\n for (let i = 0; i < tasks_amount; i++) {\r\n let result = await solve()\r\n console.log(result)\r\n }\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n await main();\r\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, h, m, a) {\r\n a.sort((a, b) => a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]);\r\n for (let [x, y] of a) {\r\n if (x === h && y >= m) {\r\n return `0 ${y - m}`;\r\n }\r\n if (x > h) {\r\n const t = x * 60 + y - (h * 60 + m);\r\n return `${Math.floor(t / 60)} ${t % 60}`;\r\n }\r\n }\r\n const [x, y] = a[0];\r\n const t = 1440 + x * 60 + y - (h * 60 + m);\r\n return `${Math.floor(t / 60)} ${t % 60}`;\r\n}\r\n\r\nasync function main(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m, k] = await rns();\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await rns());\r\n }\r\n res[i] = solve(n, m, k, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [n, H, M] = readline().split(' ').map(Number);\r\n let min = 24*60;\r\n for (let i = 0; i < n; i++) {\r\n const [h, m] = readline().split(' ').map(Number);\r\n let hDiff = h - H;\r\n let mDiff = m - M;\r\n if (mDiff < 0) {\r\n mDiff += 60;\r\n hDiff--;\r\n }\r\n if (hDiff < 0) {\r\n hDiff += 24;\r\n }\r\n const time = hDiff * 60 + mDiff;\r\n if (time < min) {\r\n min = time;\r\n }\r\n }\r\n const hrs = Math.floor(min / 60);\r\n const mins = min % 60;\r\n output(hrs + ' ' + mins);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, h, m] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n output[i] = solve(n, h, m, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, H, M, arr) {\n const sorted = arr.map(([h, m]) => h * 60 + m)\n .sort((a, b) => a - b)\n const now = H * 60 + M\n let y = sorted[0] + 24 * 60 - now\n for (let x of sorted) {\n if (x >= now) {\n y = x - now\n break\n }\n }\n return [Math.floor(y / 60), y % 60].join(' ')\n}\n"}], "negative_code": [{"source_code": "var t = parseInt(readline())\r\nfor(j = 0; j < t; j++){\r\nvar d = 2000;\r\nvar c = 2000;\r\n \r\nvar arr = readline()\r\narr = arr.split(' ')\r\nvar arr_min = []\r\nvar n = parseInt(arr[0])\r\nvar h = parseInt(arr[1])\r\nvar m = parseInt(arr[2])\r\nvar start = h * 60 + m\r\n \r\n for(var i = 0; i < n; i++){\r\n var sleep = readline();\r\n sleep = sleep.split(' ')\r\n var H = parseInt(sleep[0])\r\n var M = parseInt(sleep[1])\r\n var min = (H * 60) + M\r\n if(min >= start){\r\n d = Math.min(d, min)\r\n }else{\r\n c = Math.min(d,min)\r\n }\r\n }\r\n \r\n if(d !== 2000){\r\n d = d - start\r\n print(parseInt(d / 60), d % 60 )\r\n }else{\r\n c = (1440 - start) + c\r\n print(parseInt(c / 60), c % 60 )\r\n }\r\n}"}, {"source_code": "var t = parseInt(readline())\r\n\r\nfor(j = 0; j < t; j++){\r\n \r\nvar arr = readline()\r\narr = arr.split(' ')\r\nvar arr_min = []\r\nvar n = parseInt(arr[0])\r\nvar h = parseInt(arr[1])\r\nvar m = parseInt(arr[2])\r\nvar start = h * 60 + m\r\n\r\nfor(var i = 0; i < n; i++){\r\n var sleep = readline();\r\n sleep = sleep.split(' ')\r\n var H = parseInt(sleep[0])\r\n var M = parseInt(sleep[1])\r\n var min = (H * 60) + M\r\n arr_min.push(min)\r\n}\r\narr_min.sort(function(a, b) {\r\n return a - b;\r\n});\r\n\r\nminn = 100000\r\n\r\nfor (var i = 0; iparseInt(x));\r\n var map={};\r\n var ans=0;\r\n for(var j=arr.length;j>=0;j--){\r\n if(map[arr[j]]){\r\n ans=j+1;\r\n break;\r\n }\r\n else{\r\n map[arr[j]]=1;\r\n }\r\n }\r\n print(ans);\r\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction calc(H, M, alarms) {\n // console.log(H)\n // console.log(M)\n // console.log(alarms)\n next_alarm(H, M, alarms)\n\n}\n\nfunction next_alarm(H, M, alarms) {\n let k = alarms.length\n let min = Number.MAX_SAFE_INTEGER\n for(let i = 0; i < k; i++) {\n let hour = alarms[i].h\n let minute = alarms[i].m\n var _diff = 0\n\n if (hour == H && minute == M) {\n console.log(\"0 0\")\n return\n }\n\n if ((hour == H && minute >= M) || (hour > H)) { // alarm later than in day\n _diff = Math.abs(new Date('2011/10/09 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n } else {\n _diff = Math.abs(new Date('2011/10/10 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n }\n\n if (_diff/1000 < min) {\n min = _diff\n }\n\n alarms[i].diff = _diff/1000\n }\n\n // console.log(alarms)\n\n let hour = (min/1000/3600)|0\n let minute = ((min/1000)%3600)/60\n\n console.log(hour + \" \" + minute)\n\n\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_h_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_h_m[0]\n const H = n_h_m[1]\n const M = n_h_m[2]\n\n let alarms = []\n\n for(let i = 0; i < n; i ++) {\n const hm = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n alarms.push({\"h\": hm[0], \"m\": hm[1]})\n }\n\n calc(H, M, alarms)\n\n }\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction calc(H, M, alarms) {\n // console.log(H)\n // console.log(M)\n // console.log(alarms)\n next_alarm(H, M, alarms)\n\n}\n\nfunction next_alarm(H, M, alarms) {\n let k = alarms.length\n let min = Number.MAX_SAFE_INTEGER\n for(let i = 0; i < k; i++) {\n let hour = alarms[i].h\n let minute = alarms[i].m\n var _diff = 0\n\n if ((hour == H && minute >= M) || (hour > H)) { // alarm later than in day\n _diff = Math.abs(new Date('2011/10/09 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n } else {\n _diff = Math.abs(new Date('2011/10/10 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n }\n\n if (_diff/1000 < min) {\n min = _diff\n }\n\n alarms[i].diff = _diff/1000\n }\n\n // console.log(alarms)\n\n let hour = (min/1000/3600)|0\n let minute = ((min/1000)%3600)/60\n\n console.log(hour + \" \" + minute)\n\n\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_h_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_h_m[0]\n const H = n_h_m[1]\n const M = n_h_m[2]\n\n let alarms = []\n\n for(let i = 0; i < n; i ++) {\n const hm = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n alarms.push({\"h\": hm[0], \"m\": hm[1]})\n }\n\n calc(H, M, alarms)\n\n }\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction calc(H, M, alarms) {\n // console.log(H)\n // console.log(M)\n // console.log(alarms)\n next_alarm(H, M, alarms)\n\n}\n\nfunction next_alarm(H, M, alarms) {\n let k = alarms.length\n let min = Number.MAX_SAFE_INTEGER\n for(let i = 0; i < k; i++) {\n let hour = alarms[i].h\n let minute = alarms[i].m\n var _diff = 0\n\n if ((hour == H && minute >= M) || (hour > H)) { // alarm later than in day\n _diff = Math.abs(new Date('2011/10/09 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n } else {\n _diff = Math.abs(new Date('2011/10/10 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n }\n\n if (_diff/1000 < min) {\n min = _diff\n }\n\n alarms[i].diff = _diff/1000\n }\n\n console.log(alarms)\n\n let hour = (min/1000/3600)|0\n let minute = ((min/1000)%3600)/60\n\n console.log(hour + \" \" + minute)\n\n\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_h_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_h_m[0]\n const H = n_h_m[1]\n const M = n_h_m[2]\n\n let alarms = []\n\n for(let i = 0; i < n; i ++) {\n const hm = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n alarms.push({\"h\": hm[0], \"m\": hm[1]})\n }\n\n calc(H, M, alarms)\n\n }\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction calc(H, M, alarms) {\n // console.log(H)\n // console.log(M)\n // console.log(alarms)\n next_alarm(H, M, alarms)\n\n}\n\nfunction next_alarm(H, M, alarms) {\n let k = alarms.length\n let min = Number.MAX_SAFE_INTEGER\n for(let i = 0; i < k; i++) {\n let hour = alarms[i].h\n let minute = alarms[i].m\n var _diff = 0\n\n if ((hour == H && minute >= M) || (hour > H)) { // alarm later than in day\n _diff = Math.abs(new Date('2011/10/09 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n } else {\n _diff = Math.abs(new Date('2011/10/10 ' + hour + ':' + minute) - \n new Date('2011/10/09 ' + H+':'+M));\n }\n\n if (_diff/1000 < min) {\n min = _diff\n }\n\n // alarms[i].diff = _diff/1000\n }\n\n // console.log(min)\n\n let hour = (min/1000/3600)|0\n let minute = ((min/1000)%3600)/60\n\n console.log(hour + \" \" + minute)\n\n\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_h_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_h_m[0]\n const H = n_h_m[1]\n const M = n_h_m[2]\n\n let alarms = []\n\n for(let i = 0; i < n; i ++) {\n const hm = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n alarms.push({\"h\": hm[0], \"m\": hm[1]})\n }\n\n calc(H, M, alarms)\n\n }\n\n // ws.end();\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n const t = +readLine();\r\n \r\n \r\n for(let j = 0;j +p)\r\n const N = a[0];\r\n const H = a[1];\r\n const M = a[2];\r\n \r\n const Tot = H*60 + M;\r\n \r\n let ans = 24000;\r\n \r\n for(let i = 0;i +p);\r\n \r\n let h = x[0];\r\n let m = x[1];\r\n \r\n let time = h*60 + m;\r\n \r\n if(time { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const a = readLine().split(' ').map(p => +p);\r\n const n = a[0];\r\n const H = a[1];\r\n const M = a[2];\r\n let arr = [], aux;\r\n for(let j = 0; j < n; j++){\r\n aux = readLine().split(' ').map(p => +p);\r\n arr.push(aux);\r\n }\r\n let result = myFunc(H, M, arr);\r\n console.log(...result);\r\n }\r\n}\r\n\r\nfunction myFunc(H, M, arr){\r\n\r\n let c = (60*H + M);\r\n let min = Infinity;\r\n let min_val = Infinity;\r\n let aux, item;\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n item = arr[i];\r\n aux = (60*item[0] + item[1]);\r\n if(aux < min_val){\r\n min_val = aux;\r\n }\r\n if(aux >= c && aux < min){\r\n min = aux;\r\n }\r\n }\r\n\r\n if(min == Infinity){\r\n min_val = 1440 - c + min_val;\r\n return [parseInt(min_val/60), min_val%60]; \r\n } \r\n\r\n return [parseInt(min/60), min%60];\r\n\r\n\r\n \r\n}\r\n"}], "src_uid": "ce0579e9c5b4c157bc89103c76ddd4c3"} {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function proc() {\r\n let n = +await nextString();\r\n let mas = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let qq\r\n for (qq = 0; qq < n && mas[qq] <= 0; ++qq) {}\r\n if (qq === 0) {\r\n return 1\r\n }\r\n if (qq === 1) {\r\n return n === 1 ? 1 : 2\r\n }\r\n if (qq === n) {\r\n return qq\r\n }\r\n let min = mas[1] - mas[0]\r\n for (let i = 2; i <= qq; ++i) {\r\n min = Math.min(min, mas[i] - mas[i - 1])\r\n }\r\n if (mas[qq] <= min) {\r\n return qq + 1\r\n }\r\n return qq\r\n \r\n}\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n console.log(await proc())\r\n }\r\n}\r\n \r\nmain()\r\n", "positive_code": [{"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet lines = [];\r\nlet lineIdx = 0;\r\n\r\nrl.on(\"line\", line => {\r\n lines.push(line);\r\n});\r\n\r\nrl.on(\"close\", () => {\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return lines[lineIdx++];\r\n}\r\n\r\nfunction main() {\r\n let t = +readLine();\r\n while (t--) {\r\n let n = +readLine();\r\n let a = readLine().split(' ').map(x => +x).sort((x, y) => x - y);\r\n let diff = Infinity;\r\n let hasPos = false;\r\n let ret = 0;\r\n for (let i=0; i 0)\r\n diff = Math.min(diff, a[i] - a[i-1]);\r\n } else if (diff >= a[i] && !hasPos) {\r\n ret++;\r\n hasPos = true;\r\n }\r\n }\r\n console.log(ret);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solution(nums) {\r\n nums.sort((x, y) => x - y);\r\n if (nums[0] > 0)\r\n return 1;\r\n if (nums[nums.length - 1] <= 0)\r\n return nums.length;\r\n let i = 1;\r\n let minimumPositiveValue = -1;\r\n let minimumDelta = 2e9 + 7;\r\n for (; i < nums.length; ++i) {\r\n if (nums[i] > 0) {\r\n minimumPositiveValue = nums[i];\r\n break;\r\n }\r\n minimumDelta = Math.min(minimumDelta, nums[i] - nums[i - 1]);\r\n }\r\n if (minimumDelta >= minimumPositiveValue)\r\n return i + 1;\r\n return i;\r\n}\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n const countOfNums = Number(io.readLine());\r\n const nums = io\r\n .readLine()\r\n .trim()\r\n .split(/\\s+/g)\r\n .map(x => Number(x))\r\n .slice(0, countOfNums);\r\n const answer = solution(nums);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n \r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ncnt = 0;\r\n for (let i = 0; i < n; i++) if (arr[i] <= 0) ncnt++;\r\n arr.sort((a, b) => b - a);\r\n let min = Infinity;\r\n for (let i = 0; i < n; i++) if (arr[i] > 0) min = Math.min(min, arr[i]);\r\n if (min === Infinity) console.log(ncnt);\r\n else {\r\n let flag = true;\r\n for (let i = 1; i < n; i++)\r\n if (arr[i] <= 0) flag &= arr[i - 1] - arr[i] >= min;\r\n if (flag) console.log(ncnt + 1);\r\n else console.log(ncnt);\r\n }\r\n }\r\n};\r\nsolve();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = 1;\r\n\t\tvar min = Math.pow(10, 15);\r\n\t\tvar isZero = false;\r\n\t\t//myerr(list);\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\tmin = Math.min(min, Math.abs(list[i - 1] - list[i]));\r\n\t\t\t\toutput++;\r\n\t\t\t}else{\r\n\t\t\t\tif(list[i] <= Math.min(min, Math.abs(list[i - 1] - list[i]))){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t\tmin = Math.min(min, Math.abs(list[i - 1] - list[i]));\r\n\t\t\t\t\t\r\n\t\t\t\t}else{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ncnt = 0;\r\n for (let i = 0; i < n; i++) if (arr[i] <= 0) ncnt++;\r\n arr.sort((a, b) => b - a);\r\n let min = Infinity;\r\n for (let i = 0; i < n; i++) if (arr[i] > 0) min = Math.min(min, arr[i]);\r\n if (min === Infinity) console.log(ncnt);\r\n else {\r\n let flag = true;\r\n for (let i = 1; i < n - 1; i++)\r\n if (arr[i] <= 0) flag &= arr[i - 1] - arr[i] >= min;\r\n if (flag) console.log(ncnt + 1);\r\n else console.log(ncnt);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n p.sort((a, b) => a - b);\r\n if (ni.length === 0) {\r\n let cnt = 0;\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) cnt++;\r\n else {\r\n if(cnt>1) break;\r\n cnt++;\r\n break;\r\n }\r\n }\r\n console.log(cnt);\r\n } else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n let res = [];\r\n if (ni.length === 1) {\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else {\r\n if (res.length > 1) break;\r\n res.push(p[i]);\r\n break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else if (p[i] <= d) {\r\n res.push(p[i]);\r\n break;\r\n } else break;\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n p.sort((a, b) => a - b);\r\n if (ni.length === 0) {\r\n let cnt = 0;\r\n for(let i=0;i b - a);\r\n let res = [];\r\n if (ni.length === 1) {\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else {\r\n if (res.length > 1) break;\r\n res.push(p[i]);\r\n break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else if (p[i] <= d) {\r\n res.push(p[i]);\r\n break;\r\n } else break;\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n p.sort((a, b) => a - b);\r\n if (ni.length === 0) {\r\n if(p[0]===0) console.log(2);\r\n else console.log(1);\r\n }\r\n else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n let res = [];\r\n if (ni.length === 1) {\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else {\r\n if (res.length > 1) break;\r\n res.push(p[i]);\r\n break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else if (p[i] <= d) {\r\n res.push(p[i]);\r\n break;\r\n } else break;\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n if (ni.length === 0) console.log(1);\r\n else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n p.sort((a, b) => a - b);\r\n let res = [];\r\n if (ni.length === 1) {\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else {\r\n if (res.length > 1) break;\r\n res.push(p[i]);\r\n break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else if (p[i] <= d) {\r\n res.push(p[i]);\r\n break;\r\n } else break;\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n if (ni.length === 0) console.log(1);\r\n else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n p.sort((a, b) => a - b);\r\n let res = [];\r\n if (ni.length === 1) {\r\n res.push(p[0]);\r\n for (let i = 1; i < p.length; i++)\r\n if (res[res.length - 1] === p[i]) res.push(p[i]);\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (p[i] === 0) res.push(p[i]);\r\n else if (p[i] <= d) {\r\n res.push(p[i]);\r\n break;\r\n } else break;\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n if (ni.length === 0) console.log(1);\r\n else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n p.sort((a, b) => a - b);\r\n let res = [];\r\n if (ni.length === 1) {\r\n res.push(p[0]);\r\n for (let i = 1; i < p.length; i++)\r\n if (res[res.length - 1] === p[i]) res.push(p[i]);\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Infinity;\r\n for (let i = 0; i < ni.length - 1; i++)\r\n d = Math.min(d, Math.abs(ni[i] - ni[i + 1]));\r\n for (let i = 0; i < p.length; i++) {\r\n if (i === 0) {\r\n if (p[i] <= d) res.push(p[i]);\r\n else break;\r\n } else {\r\n if (p[i] <= d) {\r\n if (Math.abs(res[res.length - 1] - p[i]) === p[i]) res.push(p[i]);\r\n else break;\r\n } else break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let ni = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) ni.push(arr[i]);\r\n else p.push(arr[i]);\r\n }\r\n if (ni.length === 0) console.log(1);\r\n else if (p.length === 0) console.log(ni.length);\r\n else {\r\n ni.sort((a, b) => b - a);\r\n p.sort((a, b) => a - b);\r\n let res = [];\r\n if (ni.length === 1) {\r\n res.push(p[0]);\r\n for (let i = 1; i < p.length; i++)\r\n if (res[res.length - 1] === p[i]) res.push(p[i]);\r\n console.log(ni.length + res.length);\r\n } else {\r\n let d = Math.abs(ni[0] - ni[1]);\r\n for (let i = 0; i < p.length; i++) {\r\n if (i === 0) {\r\n if (p[i] <= d) res.push(p[i]);\r\n else break;\r\n } else {\r\n if (p[i] <= d) {\r\n if (Math.abs(res[res.length - 1] - p[i]) === p[i]) res.push(p[i]);\r\n else break;\r\n } else break;\r\n }\r\n }\r\n console.log(ni.length + res.length);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function proc() {\r\n let n = +await nextString();\r\n let mas = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let qq\r\n for (qq = 0; qq < n && mas[qq <= 0]; ++qq) {}\r\n if (qq === 0) {\r\n return 1\r\n }\r\n if (qq === 1) {\r\n return n === 1 ? 1 : 2\r\n }\r\n if (qq === n) {\r\n return qq\r\n }\r\n let min = mas[1] - mas[0]\r\n for (let i = 2; i <= qq; ++i) {\r\n min = Math.min(min, mas[i] - mas[i - 1])\r\n }\r\n if (mas[qq] <= min) {\r\n return qq + 1\r\n }\r\n return qq\r\n \r\n}\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n console.log(await proc())\r\n }\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function proc() {\r\n let n = +await nextString();\r\n let mas = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let qq = mas.findIndex(x => x === 0)\r\n if (qq === -1) {\r\n for (qq = 0; qq < n && mas[qq < 0]; ++qq) {}\r\n }\r\n if (qq === 0) {\r\n return 1\r\n }\r\n if (qq === 1) {\r\n return n === 1 ? 1 : 2\r\n }\r\n if (qq === n) {\r\n return qq\r\n }\r\n let min = mas[1] - mas[0]\r\n for (let i = 2; i <= qq; ++i) {\r\n min = Math.min(min, mas[i] - mas[i - 1])\r\n }\r\n if (mas[qq] <= min) {\r\n return qq + 1\r\n }\r\n return qq\r\n \r\n}\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n console.log(await proc())\r\n }\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = 1;\r\n\t\tvar min = Math.pow(10, 15);\r\n\t\tvar isZero = false;\r\n\t\t//myerr(list);\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\toutput++;\r\n\t\t\t}else{\r\n\t\t\t\tif(list[i] <= Math.min(min, Math.abs(list[i - 1] - list[i]))){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t\tmin = Math.min(min, Math.abs(list[i - 1] - list[i]));\r\n\t\t\t\t\t\r\n\t\t\t\t}else{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = 0;\r\n\t\tvar isZero = false;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\toutput++;\r\n\t\t\t\tmax = list[i];\r\n\t\t\t}else if(list[i] == 0 && !isZero){\r\n\t\t\t\tisZero = true;\r\n\t\t\t\toutput++;\r\n\t\t\t}else{\r\n\t\t\t\toutput++;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "src_uid": "a4b170cc058c485a50bf18982fd96851"} {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve(){\r\n\t let n, m, rb, cb, rd, cd ;\r\n\t [ n, m, rb, cb, rd, cd ] = inputReader.readNumberArray();\r\n\t let dirx = 1, diry = 1;\r\n\t let ans = 0;\r\n\t while(rb != rd && cb != cd){\r\n\t if(rb + dirx > n || rb + dirx < 1) dirx*= -1;\r\n\t if(cb + diry > m || cb + diry < 1) diry*= -1;\r\n\t rb+=dirx;\r\n\t cb+=diry;\r\n\t ans+=1;\r\n\t }\r\n\t console.log(ans);\r\n\t}\r\n\t\r\n\twhile(t--){\r\n\t solve(); \r\n\t}\r\n\t\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var l = lines[i].split(' ').map(Number);\n var n = l[0], m = l[1], rb = l[2], cb = l[3], rd = l[4], cd = l[5];\n var ans = 0;\n var a = 1;\n var b = 1;\n while(true){\n if(rb == rd || cb == cd){\n break;\n }\n if(rb + a > n || rb + a < 1){\n a *= -1;\n }\n if(cb + b > m || cb + b < 1){\n b *= -1;\n }\n rb += a;\n cb += b;\n ans++;\n }\n console.log(ans);\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0], m = k[1], rb = k[2], cb = k[3], rd = k[4], cd = k[5];\n var ans = 0;\n var dr = 1, dc = 1;\n while(true){\n if(rb == rd || cb == cd){\n break;\n }\n if(rb + dr > n || rb + dr < 1){\n dr *= -1;\n }\n if(cb + dc > m || cb + dc < 1){\n dc *= -1;\n }\n rb += dr;\n cb += dc;\n ans++;\n }\n console.log(ans);\n\t}\n});\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m, rb, cb, rd, cd] = rna();\r\n\r\n\t\tlet ans = INF;\r\n\t\tif (rd >= rb) \r\n\t\t\tans = Math.min(ans, rd - rb);\r\n\t\telse\r\n\t\t\tans = Math.min(ans, n - rb + n - rd);\r\n\r\n\t\tif (cd >= cb) \r\n\t\t\tans = Math.min(ans, cd - cb);\r\n\t\telse\r\n\t\t\tans = Math.min(ans, m - cb + m - cd);\r\n\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let [n,m,rb,rc,rd,cd] = (await getLine()).split(' ').map(num => parseInt(num));\r\n let res = 0;\r\n let dr, dc;\r\n dr = 1; dc = 1;\r\n while (rb !== rd && rc !== cd) {\r\n if (rb + dr > n || rb + dr < 1)\r\n dr = dr * -1;\r\n if (rc + dc > m || rc + dc < 1)\r\n dc = dc * -1;\r\n rb += dr;\r\n rc += dc;\r\n res += 1;\r\n }\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var n = inp[0],\r\n m = inp[1],\r\n rb = inp[2],\r\n cb = inp[3],\r\n rd = inp[4],\r\n cd = inp[5];\r\n var ans = Infinity;\r\n if (rd >= rb) {\r\n ans = Math.min(ans, rd - rb);\r\n } else {\r\n ans = Math.min(ans, 2 * (n - rb) + rb - rd);\r\n }\r\n if (cd >= cb) {\r\n ans = Math.min(ans, cd - cb);\r\n } else {\r\n ans = Math.min(ans, 2 * (m - cb) + cb - cd);\r\n }\r\n return ans;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var l = lines[i].split(' ').map(Number);\n var n = l[0], m = l[1], rb = l[2], cb = l[3], rd = l[4], cd = l[5];\n var ans = 0;\n var a = 1;\n var b = 1;\n while(true){\n if(rb == rd || cb == cd){\n break;\n }\n if(rb + a > n || rb + a < 0){\n a *= -1;\n }else if(cb + b > m || cb + b < 0){\n b *= -1;\n }\n rb += a;\n cb += b;\n ans++;\n }\n console.log(ans);\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var l = lines[i].split(' ').map(Number);\n var n = l[0], m = l[1], rb = l[2], cb = l[3], rd = l[4], cd = l[5];\n var ans = 0;\n var a = 1;\n var b = 1;\n while(true){\n if(rb == rd || cb == cd){\n break;\n }\n if(rb + a > n || rb + a < 1){\n a *= -1;\n }else if(cb + b > m || cb + b < 1){\n b *= -1;\n }\n rb += a;\n cb += b;\n ans++;\n }\n console.log(ans);\n }\n});"}], "src_uid": "6f819ce1d88d5211cd475a8673edba97"} {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nfunction _toConsumableArray(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n return arr2;\n } else {\n return Array.from(arr);\n }\n}\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToStringArray = function lineToStringArray(str) {\n return str.split(\" \");\n};\nvar lineToNumberArray = function lineToNumberArray(str) {\n return lineToStringArray(str).map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\nvar readStringsLine = compose(\n readline,\n lineToStringArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),\n n = _readNumbersLine2[0];\n\nvar arr = readNumbersLine();\nvar sortedArr = [].concat(_toConsumableArray(arr)).sort(function(a, b) {\n return a - b;\n});\nvar j = 0;\nvar res = 0;\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = sortedArr.entries()[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _ref = _step.value;\n\n var _ref2 = _slicedToArray(_ref, 2);\n\n var index = _ref2[0];\n var value = _ref2[1];\n\n while (sortedArr[index] >= sortedArr[j] && j < n) {\n j++;\n }\n if (j === n) {\n break;\n }\n res = index + 1;\n j++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nwrite(res);\n", "positive_code": [{"source_code": "var n = readline();\n\nvar arr = readline().split(' ').map(Number);\n\n//print(arr.join(' '));\n\narr = arr.sort(function ( x, y ) {\n return x - y;\n});\n\n//print(arr.join(' '));\n\n\nvar ans = 0;\n\nfor( var i=0, cnt = 1; i= arr[cnt] && !used[cnt]) {\n cnt++;\n }\n if( cnt > n ) {\n break;\n }\n if( arr[cnt] > arr[i] ) {\n //print(cnt + \" \" + arr[i] + \" \" + arr[cnt] );\n ans++;\n used[cnt++] = 1;\n }\n}\n\nprint(ans);"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const sequence = is.nextArray();\n for (let i = 0; i < n; i += 1)\n sequence[i] = parseInt(sequence[i], 10);\n sequence.sort((a, b) => a - b);\n sequence.reverse();\n\n let answer = 0;\n for (let i = 0, j = 0; i < n; i += 1) {\n if (sequence[j] > sequence[i]) {\n j += 1;\n answer += 1;\n }\n }\n\n console.log(answer);\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var n = (+ readline ());\nvar a = readline ();\na = a.trim ().split ( ' ' );\nfor ( var i = 0; i < a.length; i ++ ) a [ i ] = Number ( a [ i ] );\na.sort ( function ( a, b ) { return a - b; } );\nvar pa = 0, pb = 1;\nwhile ( pb < a.length ) {\n if ( a [ pb ] > a [ pa ] ) \n pa ++;\n pb ++;\n}\nprint ( pa );\n"}], "negative_code": [{"source_code": "var n = readline();\n\nvar arr = readline().split(' ').map(Number);\n\n//print(arr.join(' '));\n\narr.sort(function ( x, y ) {\n return x > y;\n});\n\n//print(arr.join(' '));\n\n\nvar ans = 0;\n\nfor( var i=0, cnt = 1; i y;\n});\n\n//print(arr.join(' '));\n\nvar used = [];\n\nfor( var i=1; i<=100005; i++ ) {\n used.push(0);\n}\n\nvar cnt = 1, ans = 0;\n\nfor( var i=1; i<=n; i++ ) {\n while ( cnt <= n && arr[i] >= arr[cnt] ) {\n cnt++;\n }\n if( cnt > n ) {\n break;\n }\n if( arr[cnt] > arr[i] ) {\n //print(cnt + \" \" + arr[i] + \" \" + arr[cnt] );\n ans++;\n used[cnt++] = 1;\n }\n}\n\nprint(ans);\n"}, {"source_code": "var n = readline();\n\nvar arr = readline().split(' ').map(Number);\n\n//print(arr.join(' '));\n\narr.sort(function ( x, y ) {\n return x > y;\n});\n\n//print(arr.join(' '));\n\nvar used = [];\n\nfor( var i=1; i<=100005; i++ ) {\n used.push(0);\n}\n\nvar cnt = 1, ans = 0;\n\nfor( var i=0, cnt = 1; i y;\n});\n\n//print(arr.join(' '));\n\nvar used = [];\n\nfor( var i=1; i<=100005; i++ ) {\n used.push(0);\n}\n\nvar cnt = 1, ans = 0;\n\nfor( var i=0; i<=n; i++ ) {\n while ( cnt <= n && arr[i] >= arr[cnt] && !used[cnt]) {\n cnt++;\n }\n if( cnt > n ) {\n break;\n }\n if( arr[cnt] > arr[i] ) {\n //print(cnt + \" \" + arr[i] + \" \" + arr[cnt] );\n ans++;\n used[cnt++] = 1;\n }\n}\n\nprint(ans);\n"}, {"source_code": "var n = readline();\n\nvar arr = readline().split(' ').map(Number);\n\n//print(arr.join(' '));\n\narr.sort(function ( x, y ) {\n return x > y;\n});\n\n//print(arr.join(' '));\n\nvar used = [];\n\nfor( var i=1; i<=100005; i++ ) {\n used.push(0);\n}\n\nvar cnt = 1, ans = 0;\n\nfor( var i=0; i<=n; i++ ) {\n while ( cnt <= n && arr[i] >= arr[cnt] ) {\n cnt++;\n }\n if( cnt > n ) {\n break;\n }\n if( arr[cnt] > arr[i] ) {\n //print(cnt + \" \" + arr[i] + \" \" + arr[cnt] );\n ans++;\n used[cnt++] = 1;\n }\n}\n\nprint(ans);\n"}], "src_uid": "eaa768dc1024df6449e89773234cc0c3"} {"source_code": "const n = Number(readline());\nfor (var i = n; i; i--) {\n var line = readline().split(\" \");\n var hp = Number(line[0]);\n var a = Number(line[1]);\n var b = Number(line[2]);\n while (hp > 20 && a--)\n hp = (hp >> 1) + 10;\n print(hp <= b * 10 ? \"YES\" : \"NO\");\n}\n", "positive_code": [{"source_code": "// Q: https://codeforces.com/contest/1337/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t = 0; t < test; t++) {\n\t\tlet vals = input[t+1].split(' ').map((a) => {return parseInt(a)});\n\t\tconsole.log(solution(vals[0], vals[1], vals[2]));\n\t}\n});\n\nfunction solution(x, n, m) {\n\tif (x <= m*10) {\n\t\treturn 'YES';\n\t}\n\tfor (let i = 0; i < n; i++) {\n\t\tx = Math.floor((x/2 + 10));\n\t\tif ( x <= m*10) {\n\t\t\treturn 'YES';\n\t\t}\n\t}\n\treturn 'NO';\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n var b = parseInt(line.split(\" \")[1]);\n var c = parseInt(line.split(\" \")[2]);\n\n solve(a, b, c);\n }\n}\n\nfunction solve(hp, attack1, attack2) {\n while ((attack1 + attack2) > 0 && hp > 0) {\n var attack1Damage = Math.floor(hp/2);\n\n if (attack1 > 0 && (hp - attack1Damage) > 10) {\n hp = attack1Damage;\n hp += 10;\n attack1--;\n continue;\n } else if (attack2 > 0) {\n hp -= 10;\n attack2--;\n continue;\n } else {\n break;\n }\n }\n\n console.log(hp > 0 ? 'NO' : 'YES');\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [x, n, m] = d.split(' ').map(Number);\n\n while (n > 0 && x > m * 10) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n\n x -= m * 10;\n\n if (x > 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n let l = arr[0];\n arr = arr.slice(1);\n arr = arr.map(el => +el);\n for (let z = 0; z < l; z++) {\n let x = arr[0];\n let n = arr[1];\n let m = arr[2];\n while (x > 20 && n > 0) {\n x = Math.floor(x/2);\n x += 10;\n n--;\n }\n console.log(x <= m * 10 ? \"YES\" : \"NO\");\n arr = arr.slice(3);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction canSolve(x, n, m) {\n while (n > 0 && x > 20) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n while (m > 0 && x > 0) {\n x = x - 10;\n m--;\n }\n if (x <= 0)\n return true;\n return false;\n}\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];\n print(canSolve(x, n, m) ? 'YES' : 'NO');\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction canSolve(x, n, m) {\n while (n > 0 && x > 20) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n while (m > 0 && x > 0) {\n x = x - 10;\n m--;\n }\n if (x <= 0)\n return true;\n return false;\n}\nfunction main() {\n var e = parseInt(readline());\n for (var _ = 0; _ < e; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];\n print(canSolve(x, n, m) ? 'YES' : 'NO');\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction canSolve(x, n, m) {\n while (n > 0 && x > 20) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n while (m > 0 && x > 0) {\n x = x - 10;\n m--;\n }\n if (x <= 0)\n return true;\n return false;\n}\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];\n print(canSolve(x, n, m) ? 'YES' : 'NO');\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction canSolve(x, n, m) {\n while (n > 0 && x > 20) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n while (m > 0 && x > 0) {\n x = x - 10;\n m--;\n }\n if (x <= 0)\n return true;\n return false;\n}\nfunction main() {\n var r = parseInt(readline());\n for (var _ = 0; _ < r; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];\n print(canSolve(x, n, m) ? 'YES' : 'NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction checkValidity(a, b, c) {\n if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {\n return false;\n } else {\n return true;\n }\n}\n \n\nfunction main() {\n let X = parseInt(readline());\n for (var cases = 0; cases < X; cases++) {\n let [h, v, l] = readline().split(\" \").map(e => parseInt(e));\n\n while (h >= 0 && (v > 0 || l > 0)) {\n //console.log(h,v,l);\n if (v > 0 && h >= 21) {\n h = Math.floor(h/2) + 10;\n v--;\n } else if (l > 0) {\n h = h - 10;\n l--;\n } else {\n break;\n }\n }\n\n if (h > 0) {\n console.log('NO')\n } else {\n console.log('YES');\n }\n }\n}\n"}, {"source_code": "for(var t=Number(readline());t;t--){\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n var x = 10*a[2];\n if(x>19){\n for(var i=a[1];i;i--){\n x = ((x-10)*2)+1;\n }\n }\n print((x>=a[0])?\"YES\":\"NO\");\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar tmp = nextIntArray();\n\t\tvar x = tmp[0];\n\t\tvar n = tmp[1];\n\t\tvar m = tmp[2];\n\t\tvar mae = x;\n\t\tvar isDefeat = false;\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(mae < Math.floor(x / 2) + 10){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tx = Math.floor(x / 2) + 10;\n\t\t}\n\t\tfor(var j = 0; j < m; j++){\n\t\t\tx -= 10;\n\t\t\tif(x <= 0){\n\t\t\t\tisDefeat = true;\n\t\t\t}\n\t\t}\n\t\tif(isDefeat){\n\t\t\toutput[i] = \"YES\";\n\t\t}else{\n\t\t\toutput[i] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n var a = input1[0]\n var b = input1[1]\n var c = input1[2]\n if (0 >= (a - (c * 10))) {\n print(\"yes\")\n }\n else {\n while (b--) {\n var r = parseInt(a / 2) + 10\n a = r\n }\n var res = a - (c * 10)\n if (res <= 0) {\n print(\"yes\")\n }\n else {\n print(\"no\")\n }\n }\n}"}, {"source_code": "var n = Number(readline());\nvar inp ;\n\nfor(var i = 0; i < n ; i++){\n \n inp = readline().split(' ').map(cur => Number(cur));\n var h = inp[0];\n var v = inp[1];\n var l = inp[2];\n\nif(h < 20){\nwhile( l > 0 ){\n l--;\n h = lightning(h);\n if(h <= 0) break;\n}\n (h <= 0) ? print(\"YES\"): print(\"NO\");\n \n}else{\nwhile(v > 0){\n v--;\nh = voidAbs(h);\nif(h < 20) break;\n}\nwhile( l > 0 ){\n l--;\n h = lightning(h);\n if(h <= 0) break;\n}\n (h <= 0) ? print(\"YES\"): print(\"NO\");\n \n} \n\n \n}\n\nfunction voidAbs(x){\n return Math.floor(x/2) + 10\n} \n\nfunction lightning(x){\n return x-10\n}\n"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n \n var score = inputs[0];\n var absorb = inputs[1];\n var strike = inputs[2];\n \n for(var j=0;j 10) {\n score = Math.floor(score / 2) + 10;\n }\n }\n \n for(var j=0;j 0 ? 'NO': 'YES');\n \n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [x, n, m] = d.split(' ').map(Number);\n\n if (x <= 10) {\n [m, n] = [n, m];\n }\n\n while (n > 0) {\n x = Math.floor(x / 2) + 10;\n n--;\n }\n\n while (m > 0) {\n x -= 10;\n m--;\n }\n\n if (x > 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [x, n, m] = d.split(' ').map(Number);\n\n if (x <= 10) {\n [m, n] = [n, m];\n }\n\n while (n > 0) {\n x = Math.floor(x / 2) + 10;\n\n if (x <= 10) {\n break;\n }\n n--;\n }\n\n while (m > 0) {\n x -= 10;\n m--;\n }\n\n if (x > 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n let l = arr[0];\n arr = arr.slice(1);\n arr = arr.map(el => +el);\n for (let z = 0; z < l; z ++){\n let x = arr[0];\n let n = arr[1];\n let m = arr[2];\n let val = m*10*Math.pow(2,n);\n console.log(val > x ? \"YES\" : \"NO\");\n arr = arr.slice(3);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n let l = arr[0];\n arr = arr.slice(1);\n arr = arr.map(el => +el);\n for (let z = 0; z < l; z ++){\n let x = arr[0];\n let n = arr[1];\n let m = arr[2];\n while (x > 20 && n > 0){\n x/=2;\n x+=10;\n n--;\n }\n console.log(x < m*10 ? \"YES\" : \"NO\");\n arr = arr.slice(3);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "for(var t=Number(readline());t;t--){\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n var x = 10*a[2];\n if(x>19){\n for(var i=a[1];i;i--){\n x = ((x-10)*2)+1;\n }\n }\n print(\"\"+x+\" \"+((x>=a[0])?\"YES\":\"NO\"));\n}\n"}], "src_uid": "78f25e2bc4ff22dbac94f72af68a745f"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let [r,g,b] = readline().split(' ');\n let ar = readline().split(' ');\n let ag = readline().split(' ');\n let ab = readline().split(' ');\n\n ar.sort((a,b) => parseInt(b)-parseInt(a));\n ag.sort((a,b) => parseInt(b)-parseInt(a));\n ab.sort((a,b) => parseInt(b)-parseInt(a));\n let dp = new Array(205);\n for(let i = 0; i < 205; i++){\n dp[i] = new Array(205);\n for(let j = 0; j < 205; j++){\n dp[i][j] = new Array(205);\n dp[i][j].fill(-1);\n }\n }\n let res = 0;\n let solve = (x, y, z) => {\n if((x >= r && y >= g) || (x >= r && z >= b) || (y >= g && z >= b))\n return 0;\n\n if(dp[x][y][z] !== -1)\n return dp[x][y][z];\n let max = 0;\n if(x < r && y < g)\n max = Math.max(max, parseInt(ar[x]) * parseInt(ag[y]) + solve(x+1, y+1, z));\n if(x < r && z < b)\n max = Math.max(max, parseInt(ar[x]) * parseInt(ab[z]) + solve(x+1, y, z+1));\n if(y < g && z < b)\n max = Math.max(max, parseInt(ag[y]) * parseInt(ab[z]) + solve(x, y+1, z+1));\n\n dp[x][y][z] = max;\n res = Math.max(res, max);\n return max;\n }\n\n solve(0,0,0);\n console.log(res);\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [r,g,b] = readline().split(\" \").map(x => parseInt(x));\n const ar = readline().split(\" \").map(x => parseInt(x));\n const ag = readline().split(\" \").map(x => parseInt(x));\n const ab = readline().split(\" \").map(x => parseInt(x));\n ar.sort((a,b)=>b-a);\n ag.sort((a,b)=>b-a);\n ab.sort((a,b)=>b-a);\n\n let ans = 0;\n let dp = Array(r+1).fill().map(\n _ => Array(g+1).fill().map(\n _ => Array(b+1).fill(0)));\n \n for (let i=0; i<=r; i++) {\n for (let j=0; j<=g; j++) {\n for (let k=0; k<=b; k++) {\n if (i input += c)\n\nprocess.stdin.on('end', () => {\n let lines = input.trim().split('\\n')\n\n lines.shift()\n let [r, g, b] = lines.map(l => l.split(' ').map(Number).sort((a, b) => b - a))\n \n let dp = new Array(r.length + 1)\n let ans = 0\n\n for (let i = 0; i <= r.length; i++) {\n dp[i] = new Array(g.length + 1)\n for (let j = 0; j <= g.length; j++) {\n dp[i][j] = new Array(b.length + 1).fill(0)\n for (let k = 0; k <= b.length; k++) {\n function upd(val) {\n dp[i][j][k] = Math.max(dp[i][j][k], val)\n ans = Math.max(ans, val)\n }\n if (i > 0 && j > 0)\n upd(dp[i - 1][j - 1][k] + r[i - 1] * g[j - 1])\n if (i > 0 && k > 0)\n upd(dp[i - 1][j][k - 1] + r[i - 1] * b[k - 1])\n if (j > 0 && k > 0)\n upd(dp[i][j - 1][k - 1] + g[j - 1] * b[k - 1])\n } \n }\n }\n\n console.log(ans)\n})"}, {"source_code": "var readline=require('readline');\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[],sol;\nfunction Solve(){\n this.val=0;\n this.dp=new Array(205);\n for(var i=0;i<205;i++){\n this.dp[i]=new Array(205);\n for(var j=0;j<205;j++) this.dp[i][j]=new Array(205).fill(0);\n } \n}\nSolve.prototype.dfs=function(i,j,k){ \n if(i<0||j<0||k<0) return 0;\n if(this.dp[i][j][k]) return this.dp[i][j][k];\n var x=0,y=0,z=0;\n x=this.dfs(i-1,j-1,k)+(i>0&&j>0?(this.a[0][i-1]*this.a[1][j-1]):0);\n y=this.dfs(i-1,j,k-1)+(i>0&&k>0?(this.a[0][i-1]*this.a[2][k-1]):0);\n z=this.dfs(i,j-1,k-1)+(j>0&&k>0?(this.a[1][j-1]*this.a[2][k-1]):0);\n return this.val=this.dp[i][j][k]=Math.max(x,Math.max(y,z));\n return 0;\n}\nSolve.prototype.init=function(){\n this.a=new Array(3);\n}\nrl.on('line',function(inp){\n arr.push(inp);\n var len=arr.length;\n if(len===1){\n sol=new Solve();\n sol.rgb=arr[0].split(' ');\n sol.init();\n for(var i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [rNum, gNum, bNum] = readLine().split(/\\s/).map(Number)\n const rs = readLine().split(/\\s/).map(Number).sort((a, b) => b - a)\n const gs = readLine().split(/\\s/).map(Number).sort((a, b) => b - a)\n const bs = readLine().split(/\\s/).map(Number).sort((a, b) => b - a)\n const dp = Array(rNum + 1)\n .fill(0)\n .map(() => Array(gNum + 1)\n .fill(0)\n .map(() => Array(bNum + 1)\n .fill(0)\n )\n )\n let result = 0\n for (let r = 0; r <= rNum; r++) {\n for (let g = 0; g <= gNum; g++) {\n\t for (let b = 0; b <= bNum; b++) {\n if ((r + g + b) % 2 === 1) {\n continue\n }\n if (r < rNum && g < gNum) {\n dp[r + 1][g + 1][b] = Math.max(dp[r + 1][g + 1][b], dp[r][g][b] + rs[r] * gs[g])\n }\n if (r < rNum && b < bNum) {\n dp[r + 1][g][b + 1] = Math.max(dp[r + 1][g][b + 1], dp[r][g][b] + rs[r] * bs[b])\n }\n if (g < gNum && b < bNum) {\n dp[r][g + 1][b + 1] = Math.max(dp[r][g + 1][b + 1], dp[r][g][b] + gs[g] * bs[b])\n }\n result = Math.max(result, dp[r][g][b])\n }\n \t}\n }\n console.log(result)\n}\n\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [r,g,b] = readline().split(\" \").map(x => parseInt(x));\n const ar = readline().split(\" \").map(x => parseInt(x));\n const ag = readline().split(\" \").map(x => parseInt(x));\n const ab = readline().split(\" \").map(x => parseInt(x));\n ar.sort((a,b)=>b-a);\n ag.sort((a,b)=>b-a);\n ab.sort((a,b)=>b-a);\n\n let area = 0;\n while (ar.length + ag.length + ab.length >1) {\n let [a,b,c] = [ar, ag, ab].sort((a,b)=>(b[0]|0)-(a[0]|0));\n let a0 = a.shift();\n let b0 = b.shift();\n // consider special case e.g. [3],[3],[2,2]\n // greedy way will do 3*3, leaving [2,2] unusable\n // the optimal matching is 3*2 + 3*2\n if (a.length == 0 && b.length == 0 && c.length >= 2) {\n if (a0 * c[0] + b0 * c[1] > a0*b0) {\n let c0 = c.shift();\n let c1 = c.shift();\n area += a0*c0 + b0*c1;\n break;\n }\n } else {\n area += a0 * b0;\n }\n }\n console.log(area);\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [r,g,b] = readline().split(\" \").map(x => parseInt(x));\n const ar = readline().split(\" \").map(x => parseInt(x));\n const ag = readline().split(\" \").map(x => parseInt(x));\n const ab = readline().split(\" \").map(x => parseInt(x));\n ar.sort((a,b)=>b-a);\n ag.sort((a,b)=>b-a);\n ab.sort((a,b)=>b-a);\n\n let area = 0;\n while (ar.length + ag.length + ab.length >1) {\n let [a,b,c] = [ar, ag, ab].sort((a,b)=>(b[0]|0)-(a[0]|0));\n let a0 = a.shift() | 0;\n let b0 = b.shift() | 0;\n // consider special case e.g. [3],[3],[2,2]\n // greedy way will do 3*3, leaving [2,2] unusable\n // the optimal matching is 3*2 + 3*2\n if (a.length == 0 && b.length == 0 && c.length >= 2) {\n if (a0 * c[0] + b0 * c[1] > a0*b0) {\n let c0 = c.shift();\n let c1 = c.shift();\n area += a0*c0 + b0*c1;\n break;\n }\n } else {\n area += a0 * b0;\n }\n }\n console.log(area);\n}\n"}], "src_uid": "9e6cb1e8037e1d35b6c6fe43f805a22f"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = [];\n for (let i = 1; i <= len; i++) arr.push(i);\n console.log(len);\n console.log(arr.join(\" \"));\n }\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\toutput.push(N);\n\t\tvar list = [];\n\t\tfor(var j = 1; j <= N; j++){\n\t\t\tlist.push(j);\n\t\t}\n\t\toutput.push(myconv(list, 8));\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "function* range(first, last, step = 1) {\n for (let i = first; i <= last; i += step) {\n yield i;\n }\n}\n\n\nasync function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .filter(str => !!str)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n const n = lines[i];\n output.push(n - 1);\n output.push([...range(2, n)].join(' '));\n }\n console.log(output.join(EOL));\n}\n\nmain();\n\n"}], "negative_code": [{"source_code": "function* range(first, last, step = 1) {\n for (let i = first; i <= last; i += step) {\n yield i;\n }\n}\n\nfunction checkState(state) {\n for (let i = 0; i + 1 < state.length; i++) {\n if (state[i] !== state[i + 1]) {\n return false;\n }\n }\n return true;\n}\n\nfunction solve(n) {\n let oldStates = [\n {\n state: [...range(1, n)],\n path: [],\n }\n ];\n for (const m of range(1, 1000)) {\n const newStates = [];\n for (const oldState of oldStates) {\n for (const i of range(0, n - 1)) {\n const newState = {\n state: [...oldState.state],\n path: [...oldState.path],\n }\n newState.path.push(i + 1);\n for (const j of range(0, n - 1)) {\n if (i !== j) {\n newState.state[j] += m;\n }\n }\n if (checkState(newState.state)) {\n return {\n m,\n a: newState.path,\n }\n }\n newStates.push(newState);\n }\n }\n oldStates = newStates;\n }\n}\n\n\n// function main() {\n// const a2 = solve(2);\n// const a3 = solve(3);\n// console.log('finished');\n// }\n\n\n// main();\n\n\nasync function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n const solution = solve(lines[i]);\n output.push(solution.m);\n output.push(solution.a.join(' '));\n }\n console.log(output.join(EOL));\n}\n\nmain();\n\n"}, {"source_code": "function* range(first, last, step = 1) {\n for (let i = first; i <= last; i += step) {\n yield i;\n }\n}\n\nfunction checkState(state) {\n for (let i = 0; i + 1 < state.length; i++) {\n if (state[i] !== state[i + 1]) {\n return false;\n }\n }\n return true;\n}\n\nfunction solve(n) {\n let oldStates = [\n {\n state: [...range(1, n)],\n }\n ];\n for (const m of range(1, 1000)) {\n const newStates = [];\n for (const oldState of oldStates) {\n for (const i of range(0, n - 1)) {\n const newState = {\n state: [...oldState.state],\n previous: oldState,\n path: i + 1,\n }\n for (const j of range(0, n - 1)) {\n if (i !== j) {\n newState.state[j] += m;\n }\n }\n if (checkState(newState.state)) {\n const a = [];\n let current = newState\n do {\n if (current.path) {\n a.push(current.path);\n }\n current = current.previous;\n } while (current);\n return {\n m,\n a,\n }\n }\n newStates.push(newState);\n }\n }\n oldStates = newStates;\n }\n}\n\n\n// function main() {\n// const a2 = solve(2);\n// const a3 = solve(3);\n// console.log('finished');\n// }\n\n\n\nasync function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .filter(str => !!str)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n const solution = solve(lines[i]);\n output.push(solution.m);\n output.push(solution.a.join(' '));\n }\n console.log(output.join(EOL));\n}\n\nmain();\n\n"}, {"source_code": "async function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n output.push(1);\n output.push(2);\n }\n console.log(output.join(EOL));\n}\n\nmain();\n"}, {"source_code": "function* range(first, last, step = 1) {\n for (let i = first; i <= last; i += step) {\n yield i;\n }\n}\n\nfunction checkState(state) {\n for (let i = 0; i + 1 < state.length; i++) {\n if (state[i] !== state[i + 1]) {\n return false;\n }\n }\n return true;\n}\n\nfunction solve(n) {\n let oldStates = [\n {\n state: [...range(1, n)],\n path: [],\n }\n ];\n for (const m of range(1, 1000)) {\n const newStates = [];\n for (const oldState of oldStates) {\n for (const i of range(0, n - 1)) {\n const newState = {\n state: [...oldState.state],\n path: [...oldState.path],\n }\n newState.path.push(i + 1);\n for (const j of range(0, n - 1)) {\n if (i !== j) {\n newState.state[j] += m;\n }\n }\n if (checkState(newState.state)) {\n return {\n m,\n a: newState.path,\n }\n }\n newStates.push(newState);\n }\n }\n oldStates = newStates;\n }\n}\n\n\n// function main() {\n// const a2 = solve(2);\n// const a3 = solve(3);\n// console.log('finished');\n// }\n\n\n// main();\n\n\nasync function main() {\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .map(str => +str);\n\n for (let i = 1; i < lines.length; i++) {\n const solution = solve(lines[i]);\n console.log(solution.m);\n console.log(solution.a.join(' '));\n }\n}\n\nmain();\n\n"}, {"source_code": "\n\nasync function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .filter(str => !!str)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n output.push(1);\n output.push(2);\n }\n console.log(output.join(EOL));\n}\n\nmain();"}, {"source_code": "function* range(first, last, step = 1) {\n for (let i = first; i <= last; i += step) {\n yield i;\n }\n}\n\nfunction checkState(state) {\n for (let i = 0; i + 1 < state.length; i++) {\n if (state[i] !== state[i + 1]) {\n return false;\n }\n }\n return true;\n}\n\nfunction solve(n) {\n let oldStates = [\n {\n state: [...range(1, n)],\n path: [],\n }\n ];\n for (const m of range(1, 1000)) {\n const newStates = [];\n for (const oldState of oldStates) {\n for (const i of range(0, n - 1)) {\n const newState = {\n state: [...oldState.state],\n path: [...oldState.path],\n }\n newState.path.push(i + 1);\n for (const j of range(0, n - 1)) {\n if (i !== j) {\n newState.state[j] += m;\n }\n }\n if (checkState(newState.state)) {\n return {\n m,\n a: newState.path,\n }\n }\n newStates.push(newState);\n }\n }\n oldStates = newStates;\n }\n}\n\n\n// function main() {\n// const a2 = solve(2);\n// const a3 = solve(3);\n// console.log('finished');\n// }\n\n\n// main();\n\n\nasync function main() {\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n const solution = solve(lines[i]);\n output.push(solution.m);\n output.push(solution.a.join(' '));\n }\n console.log(output.join('\\n'));\n}\n\nmain();\n\n"}, {"source_code": "async function main() {\n const { EOL } = require('os');\n\n const dataArray = []\n for await (const chunk of process.stdin) {\n dataArray.push(chunk);\n }\n const lines = Buffer.concat(dataArray)\n .toString()\n .split(EOL)\n .map(str => +str);\n\n const output = [];\n for (let i = 1; i < lines.length; i++) {\n output.push(1);\n output.push(1);\n }\n console.log(output.join(EOL));\n}"}], "src_uid": "ac248c83c99d8a2262772816b5f4ac6e"} {"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction numericSortList(list){\n list.sort((a,b)=>a-b);\n}\n\n//[-1,1,-2,2,-3,3,...]\nfunction solve(){\n const [n] = readInts();\n let [l,r] = [0,0];\n \n const LIMIT = 15;\n // const LIMIT = 1000000000;\n\n function getSum(to){\n return (to % 2 == 0?1:-1)*(Math.ceil(to/2)); \n }\n\n for(var t = 0; t < n; t++){\n [l,r] = readInts();\n\n print(getSum(r) - getSum(l-1));\n }\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}", "positive_code": [{"source_code": "var numbers = readline();\n \nvar numArr = [];\nvar splitArray = 0;\nvar sumPos = 0, sumNeg = 0;\nvar start = 0, end = 0;\nfor(var i = 0; i < numbers; i++){\n splitArray = readline().split(' ')\n numArr.push(splitArray);\n}\n \nfor(var i = 0; i < numbers; i++){\n start = numArr[i][0], end = numArr[i][1]; \n start = parseInt(start) ,end = parseInt(end) \n if(start%2===0 && end%2!==0){\n sumPos= Math.floor(start/2 - end/2)\n }\n if(start%2!==0 && end%2!==0){\n sumPos = - Math.floor((start + end)/2)\n }\n if(start%2!==0 && end%2===0){\n sumPos = Math.floor(start/2 - end/2)\n }\n if(start%2===0 && end%2===0){\n sumPos = Math.floor((start + end)/2)\n }\n \n if(end%2===0 && sumPos<0){sumPos = sumPos*(-1)}\n if(start === end){sumPos = end}\n if(sumPos%2!==0 && start === end){\n sumPos = sumPos*(-1)\n } \n print(sumPos) \n}"}, {"source_code": "const stdin = process.stdin;\nstdin.setEncoding(\"utf8\");\nlet n;\nlet data;\nstdin.on(\"data\", function(chunk) {\n if (!n) {\n const reg = /\\d*/;\n n = chunk.match(reg)[0];\n data = chunk.slice(n.toString().length + 2);\n } else {\n data += chunk;\n }\n});\nstdin.on(\"end\", function() {\n const inputLines = data.split(\"\\n\").slice(0, n);\n inputLines.forEach(inputLine => {\n const [l, r] = splitAndConvert(inputLine, 2);\n const result = solve(l, r);\n console.log(result);\n // console.log(l, r, result);\n });\n});\nfunction splitAndConvert(stringOfNumbers, numOfValid) {\n return stringOfNumbers\n .split(\" \")\n .slice(0, numOfValid)\n .map(function(num) {\n return parseInt(num);\n });\n}\nfunction solve(l, r) {\n const delta = r - l;\n if (delta % 2 === 1) {\n const n = (delta + 1) / 2;\n const sign = r % 2 === 0 ? 1 : -1;\n return n * sign;\n } else {\n const n = delta / 2;\n const sign = r % 2 === 0 ? 1 : -1;\n const element = l * Math.pow(-1, l);\n return element + n * sign;\n }\n}\n"}, {"source_code": "solve();\n\nfunction solve() {\n var q = Number(readline());\n var input, l, r, ans;\n for (;q--;) {\n input = readline().split(' ').map(Number);\n l = input[0];\n r = input[1];\n ans = 0;\n if (!(l & 1)) {\n ans += l;\n l++;\n }\n if (r & 1) {\n ans -= r;\n r--;\n }\n if (r >= l) {\n ans += (r - l + 1) / 2;\n }\n print(ans);\n }\n}"}, {"source_code": "function doIt() {\n var cnt = +readline();\n for(var i = 0; i < cnt; i++) {\n var query = readline().split(' ').map(v=>+v);\n var start = query[0];\n var finish = query[1];\n\n var step = start % 2 ? 1 : -1;\n var diff = (finish - start + 1);\n\n var res = Math.floor(diff / 2) * step;\n if(diff % 2) {\n var add = finish;\n if(add % 2) add *= -1;\n res += add;\n }\n\n print(res);\n }\n}\n\ndoIt();"}], "negative_code": [{"source_code": "var numbers = readline();\n \nvar numArr = [];\nvar splitArray = 0;\nvar sumPos = 0, sumNeg = 0;\nvar start = 0, end = 0;\nfor(var i = 0; i < numbers; i++){\n splitArray = readline().split(' ')\n numArr.push(splitArray);\n}\n \nfor(var i = 0; i < numbers; i++){\n start = numArr[i][0], end = numArr[i][1]; \n start = parseInt(start) ,end = parseInt(end) \n if(start%2===0 && end%2!==0){\n sumPos= Math.floor(start/2 - end/2)\n }\n if(start%2!==0 && end%2!==0){\n sumPos= start/2 - end/2-1\n }\n if(start%2!==0 && end%2===0){\n sumPos = Math.floor(start/2 - end/2)\n }\n if(start%2===0 && end%2===0){\n sumPos = Math.floor((start + end)/2)\n }\n \n if(end%2==0 && sumPos<0){sumPos = sumPos*(-1)}\n if(start === end){sumPos = end}\n if(sumPos%2!==0 && start === end){\n sumPos = sumPos*(-1)\n } \n print(sumPos) \n}"}, {"source_code": "var numbers = readline();\n \nvar numArr = [];\nvar splitArray = 0;\nvar sumPos = 0, sumNeg = 0;\nvar start = 0, end = 0;\nfor(var i = 0; i < numbers; i++){\n splitArray = readline().split(' ')\n numArr.push(splitArray);\n}\n \nfor(var i = 0; i < numbers; i++){\n start = numArr[i][0], end = numArr[i][1]; \n start = parseInt(start) ,end = parseInt(end) \n if(start*210){ \n sumPos = Math.ceil(end/2 - start/2);\n }\n \n \n if(start === end){sumPos = end}\n if(sumPos%2!==0 && start === end){\n sumPos = sumPos*(-1)\n } \n print(sumPos) \n}"}, {"source_code": "var numbers = readline();\n \nvar numArr = [];\nvar splitArray = 0;\nvar sumPos = 0, sumNeg = 0;\nvar start = 0, end = 0;\nfor(var i = 0; i < numbers; i++){\n splitArray = readline().split(' ')\n numArr.push(splitArray);\n}\n \nfor(var i = 0; i < numbers; i++){\n start = numArr[i][0], end = numArr[i][1]; \n start = parseInt(start) ,end = parseInt(end) \n if(start*2 {\n const [l, r] = splitAndConvert(inputLine, 2);\n const result = solve(l, r);\n console.log(result);\n // console.log(l, r, result);\n });\n});\nfunction splitAndConvert(stringOfNumbers, numOfValid) {\n return stringOfNumbers\n .split(\" \")\n .slice(0, numOfValid)\n .map(function(num) {\n return parseInt(num);\n });\n}\nfunction solve(l, r) {\n const delta = r - l;\n if (delta % 2 === 1) {\n const n = (delta + 1) / 2;\n const sign = r % 2 === 0 ? 1 : -1;\n return n * sign;\n } else {\n const n = delta / 2;\n const sign = r % 2 === 0 ? 1 : -1;\n const element = l * Math.pow(-1, l);\n return element + n * sign;\n }\n}\n"}], "src_uid": "7eae40835f6e9580b985d636d5730e2d"} {"source_code": "Array.prototype.sum = function () {\n\tvar l = this.length,\n\t\tret = 0;\n\n\tfor (var i = 0; i < l; i++) {\n\t\tret += this[i];\n\t}\n\n\treturn ret;\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\tfor (var i = 0, k = []; i < n; i++) k.push(readline().split(' ').map(Number));\n\tfor (var i = 0, s = []; i < n; i++) s.push(k[i].sum());\n\tfor (var i = 0, c = []; i < n; i++) c.push(k.map(function (e) { return e[i]; }).sum());\n\n\tprint((function () {\n\t\tfor (var i = 0, ret = 0; i < n; i++)\n\t\t\tfor (var j = 0; j < n; j++)\n\t\t\t\tret += c[j] > s[i];\n\t\treturn ret;\n\t})());\n\n\n}).call(this);\n", "positive_code": [{"source_code": "print(function(n) {\n\n\tvar i, j, a = [],\n\t\tans = 0,\n\t\tx = new Int32Array(n),\n\t\ty = new Int32Array(n);\n\n\tfor (i = 0; i < n; i++)\n\t\ta.push(readline().split(' ').map(Number));\n\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < n; j++) {\n\t\t\tx[i] += a[i][j];\n\t\t\ty[j] += a[i][j];\n\t\t}\n\n\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (x[i] < y[j]) ans++;\n\n\treturn ans;\n\n}(+readline()));\n"}, {"source_code": "var inp = readline().split(' ');\nvar n = Number(inp[0]);\nvar A = [];\nvar R = [];\nvar C = [];\n\nfor(var i=1; i<=n; i++)\nR[i]=C[i]=0;\n\nfor(var i=1; i<=n; i++)\n{\ninp = readline().split(' ');\nA[i]=[];\nfor(var j=1; j<=n; j++)\n{\n\tA[i][j]=Number(inp[j-1]);\n\tR[i]+=A[i][j];\n\tC[j]+=A[i][j];\n}\n}\n\nvar ats = 0;\n\nfor(var i=1; i<=n; i++)\nfor(var j=1; j<=n; j++)\nif(C[j] > R[i])ats++;\n\n\nprint(ats);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst arr =[];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n arr.push(d.split(' ').map(Number));\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n let sumCol = 0;\n let sumRow = 0;\n\n for (let j = 0; j < arr[i].length; j++) {\n sumCol += arr[i][j];\n }\n\n let z = 0;\n while (z < arr.length) {\n let sumRow = 0;\n for (let k = 0; k < arr.length; k++) {\n sumRow += arr[k][z];\n }\n\n if (sumRow > sumCol) {\n ans++;\n }\n\n z++;\n }\n }\n\n console.log(ans);\n});\n"}], "negative_code": [{"source_code": "print(function(n) {\n\n\tvar i, j, a = [],\n\t\tans = 0,\n\t\tx = new Int32Array(n),\n\t\ty = new Int32Array(n);\n\n\tfor (i = 0; i < n; i++)\n\t\ta.push(readline().split(' ').map(Number));\n\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < n; j++) {\n\t\t\tx[i] += a[i][j];\n\t\t\ty[j] += a[i][j];\n\t\t}\n\n\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (x[i] > y[j]) ans++;\n\n\treturn ans;\n\n}(+readline()));"}], "src_uid": "6e7c2c0d7d4ce952c53285eb827da21d"} {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray()\n\n var numSteps = 0\n var aTotal = 0\n var bTotal = 0\n var lastTotal = 0\n var turnTotal = 0\n var curPlayerIsA = true\n var aIndex = 0\n var bIndex = n\n while(aIndex < bIndex) {\n if (curPlayerIsA) {\n aTotal += arr[aIndex]\n turnTotal += arr[aIndex]\n if(turnTotal > lastTotal) {\n curPlayerIsA = false\n lastTotal = turnTotal\n turnTotal = 0\n numSteps += 1\n bIndex -= 1\n } else {\n aIndex += 1\n }\n } else {\n bTotal += arr[bIndex]\n turnTotal += arr[bIndex]\n if(turnTotal > lastTotal) {\n curPlayerIsA = true\n lastTotal = turnTotal\n turnTotal = 0\n numSteps += 1\n aIndex += 1\n } else {\n bIndex -= 1\n }\n }\n }\n\n if (turnTotal > 0) {\n numSteps += 1\n }\n\n print(`${numSteps} ${aTotal} ${bTotal}`)\n}\n\nvar testCases = readInt();\nvar testCaseNum;\nfor(testCaseNum=0; testCaseNum bInd) {\n print(steps + \" \" + numA + \" \" + numB);\n return;\n }\n }\n currV = currA;\n steps++;\n while (currB <= currV) {\n currB += cds[bInd];\n numB += cds[bInd];\n bInd--;\n if (aInd > bInd) {\n print(steps + \" \" + numA + \" \" + numB);\n return;\n }\n }\n currV = currB;\n }\n}\nmain()"}, {"source_code": "let input = require('fs')\n .readFileSync(0, 'ascii')\n .split('\\n')\n .filter(line => !/^\\s*$/.test(line))\n .map(l => l.split(' ').map(w => parseInt(w)));\n\nlet [t, ...tests] = input;\n\nfor (let i = 0; i < t; i++) {\n const n = tests[2*i];\n const a = tests[2*i + 1];\n let l = 0;\n let r = n - 1;\n let ra = 0;\n let rb = 0;\n let moves = 0;\n let previous_size = 0;\n while (l <= r) {\n\tif (l <= r) {\n\t let current_size = 0;\n\t while (l <= r && current_size <= previous_size) {\n\t\tcurrent_size += a[l];\n\t\tl++;\n\t }\n\t ra += current_size;\n\t previous_size = current_size;\n\t moves++;\n\t}\n\tif (l <= r) {\n\t let current_size = 0;\n\t while (l <= r && current_size <= previous_size) {\n\t\tcurrent_size += a[r];\n\t\tr--;\n\t }\n\t rb += current_size;\n\t previous_size = current_size;\n\t moves++;\n\t}\n }\n console.log(moves, ra, rb)\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i < t; i++) {\n const n = parseInt(readLine(), 10);\n const seq = readLine().split(' ').map(x => parseInt(x));\n let moves = 1, a = seq[0], b = 0;\n let li = 1, i = seq.length - 1, ri = i, eatenInPrevMove = a;\n let isAlicesTurn = false;\n while (i >= 1 && li - ri < 1) {\n let eatenTillNow = 0;\n if (isAlicesTurn) {\n while (li - ri < 1) {\n eatenTillNow += seq[li];\n li++;\n if (eatenTillNow>eatenInPrevMove) break;\n }\n a += eatenTillNow;\n } else {\n while (li - ri < 1) {\n eatenTillNow += seq[ri];\n ri--;\n if (eatenTillNow>eatenInPrevMove) break;\n }\n b += eatenTillNow;\n }\n moves++;\n isAlicesTurn = !isAlicesTurn;\n eatenInPrevMove = eatenTillNow;\n }\n console.log([moves, a, b].join(\" \"));\n\n }\n return;\n}\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar turn = true;\n\t\tvar alice = 0;\n\t\tvar bob = 0;\n\t\tvar mae = 0;\n\t\tvar now = 0;\n\t\tvar move = 0;\n\t\twhile(list.length > 0){\n\t\t\tif(turn){\n\t\t\t\tturn = false;\n\t\t\t\twhile(now <= mae && list.length > 0){\n\t\t\t\t\tnow += list.shift();\n\t\t\t\t}\n\t\t\t\talice += now;\n\t\t\t\tmae = now;\n\t\t\t}else{\n\t\t\t\tturn = true;\n\t\t\t\twhile(now <= mae && list.length > 0){\n\t\t\t\t\tnow += list.pop();\n\t\t\t\t}\n\t\t\t\tbob += now;\n\t\t\t\tmae = now;\n\t\t\t}\n\t\t\tnow = 0;\n\t\t\tmove++;\n\t\t}\n\t\toutput[i] = move + \" \" + alice + \" \" + bob;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n let sic = 0;\n let aW = 0;\n let aL = 0;\n let bW = 0;\n let bL = 0;\n while (arr.length) {\n let sicW = 0;\n if (!(sic % 2)) {\n do {\n sicW += arr.shift();\n } while (sicW <= bL && arr.length);\n aL = sicW;\n aW += sicW;\n } else {\n do {\n sicW += arr.pop();\n } while (sicW <= aL && arr.length);\n bL = sicW;\n bW += sicW;\n }\n sic++;\n }\n return [sic, aW, bW].join(' ');\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let i=0; i +x)\n\n let aSum = 0\n let bSum = 0\n let a = 0\n let b = 0\n let start = 0\n let end = arr.length - 1\n let cur = 0\n let step = 0\n while (start <= end) {\n if (cur === 0 ) {\n a = 0\n while (start <= end && a <= b) {\n a += arr[start]\n start++\n }\n aSum += a\n } else {\n b = 0\n while (start <= end && b <= a) {\n // console.log('b', end)\n b += arr[end]\n end--\n }\n\n bSum += b\n }\n cur = (cur + 1) %2\n step++\n }\n console.log(step, aSum, bSum)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, a) {\n let steps = 0;\n let sumA = 0;\n let sumB = 0;\n let isA = true;\n let lastStep = 0;\n let i = 0;\n let j = n - 1;\n while (i <= j) {\n let curSum = 0;\n if (isA) {\n while (curSum === 0 || (curSum <= lastStep && i <= j)) {\n curSum += a[i];\n i++;\n }\n sumA += curSum;\n isA = false;\n } else {\n while (curSum === 0 || (curSum <= lastStep && i <= j)) {\n curSum += a[j];\n j--;\n }\n sumB += curSum;\n isA = true;\n }\n lastStep = curSum;\n steps++;\n }\n return [steps, sumA, sumB];\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, a);\n console.log(res.join(' '));\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nCases = +input[index++];\n for (let i = 0; i < nCases; i++){\n index++;\n let arr = input[index++].split(\" \").map((val) => +val);\n let prev = 0;\n let currPrev = 0;\n let alice = 0;\n let aliceIndex = 0;\n let bob = 0\n let bobIndex = arr.length - 1;\n let moves = 0;\n let turn = 0;\n let un = false;\n while (aliceIndex <= bobIndex){\n un = false;\n if (turn === 0){\n alice += arr[aliceIndex];\n if (currPrev + arr[aliceIndex] > prev){\n prev = currPrev + arr[aliceIndex];\n currPrev = 0;\n turn = 1; \n aliceIndex++;\n moves++;\n }\n else { \n currPrev += arr[aliceIndex];\n aliceIndex++;\n un = true;\n } \n }\n else{\n bob += arr[bobIndex];\n if (currPrev + arr[bobIndex] > prev){\n turn = 0;\n prev = currPrev + arr[bobIndex];\n currPrev = 0;\n bobIndex--;\n moves++;\n }\n else {\n currPrev += arr[bobIndex]\n bobIndex--;\n un = true;\n }\n }\n }\n if (un)\n moves++\n console.log(moves, alice, bob);\n }\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nCases = +input[index++];\n for (let i = 0; i < nCases; i++){\n index++;\n let arr = input[index++].split(\" \").map((val) => +val);\n let prev = 0;\n let alicePrev = 0;\n let alice = 0;\n let aliceIndex = 0;\n let bobPrev = 0;\n let bob = 0\n let bobIndex = arr.length - 1;\n let moves = 0;\n let turn = 0;\n let un = false;\n while (aliceIndex <= bobIndex){\n if (turn === 0){\n //console.log(\"-----ALICE\")\n if (alicePrev + arr[aliceIndex] > prev){\n //console.log(arr[aliceIndex])\n turn = 1;\n alice += arr[aliceIndex];\n alicePrev += arr[aliceIndex];\n aliceIndex++;\n moves++;\n prev = alicePrev;\n alicePrev = 0;\n un = false;\n }\n else {\n //console.log(arr[aliceIndex])\n alice += arr[aliceIndex];\n alicePrev += arr[aliceIndex];\n aliceIndex++;\n un = true;\n }\n }\n else{\n //console.log(\"-----BOB\")\n if (bobPrev + arr[bobIndex] > prev){\n //console.log(arr[bobIndex])\n un = false;\n turn = 0;\n bob += arr[bobIndex];\n bobPrev += arr[bobIndex]\n prev = bobPrev;\n bobPrev = 0;\n bobIndex--;\n moves++;\n }\n else {\n //console.log(arr[bobIndex])\n bob += arr[bobIndex];\n bobPrev += arr[bobIndex]\n bobIndex--;\n un = true;\n }\n }\n }\n if (un)\n moves++\n console.log(moves, alice, bob);\n }\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nCases = +input[index++];\n for (let i = 0; i < nCases; i++){\n index++;\n let arr = input[index++].split(\" \").map((val) => +val);\n let alice = 0;\n let aliceIndex = 0;\n let alicePrev = 0;\n let bob = 0;\n let bobPrev = 0;\n let bobIndex = arr.length - 1;\n let moves = 0;\n while (aliceIndex <= bobIndex){\n moves++;\n if (moves & 1){\n for (alicePrev = 0; aliceIndex <= bobIndex && alicePrev <= bobPrev; aliceIndex++)\n alicePrev += arr[aliceIndex];\n alice += alicePrev;\n }\n else {\n for (bobPrev = 0; aliceIndex <= bobIndex && bobPrev <= alicePrev; bobIndex--)\n bobPrev += arr[bobIndex];\n bob += bobPrev;\n }\n }\n console.log(moves, alice, bob);\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n readline();\n let candies = readline().split(\" \").map(e => parseInt(e));\n\n let eated = [0, 0];\n let previousEating = 0;\n let turn = 0\n let count = 0;\n\n while (candies.length > 0) {\n\n let currentEating = 0;\n //console.log('start turn', turn)\n //console.log(JSON.stringify(candies));\n\n while (candies.length > 0 && currentEating <= previousEating) {\n currentEating += (turn == 0) ? candies.shift() : candies.pop();\n //console.log('eating', currentEating);\n }\n\n if (currentEating > previousEating) {\n eated[turn] += currentEating;\n } else {\n //turn = turn === 0 ? 1 : 0;\n eated[turn] += currentEating;\n }\n\n turn = turn === 0 ? 1 : 0;\n previousEating = currentEating;\n count++;\n }\n\n console.log(`${count} ${eated[0]} ${eated[1]}`)\n // console.log(`----`)\n\n\n }\n\n\n}\n"}], "negative_code": [{"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i < t; i++) {\n const n = parseInt(readLine(), 10);\n const seq = readLine().split(' ').map(x => parseInt(x));\n let moves = 1, a = seq[0], b = 0;\n let li = 1, i = seq.length - 1, ri = i, eatenInPrevMove = a;\n let isAlicesTurn = false;\n while (i > 1 && li + (i - ri) <= i) {\n let eatenTillNow = 0;\n if (isAlicesTurn) {\n while ((li + i - ri) <= i) {\n eatenTillNow += seq[li];\n li++;\n if (eatenTillNow>eatenInPrevMove) break;\n }\n a += eatenTillNow;\n } else {\n while ((li + i - ri) <= i) {\n eatenTillNow += seq[ri];\n ri--;\n if (eatenTillNow>eatenInPrevMove) break;\n }\n b += eatenTillNow;\n }\n moves++;\n isAlicesTurn = !isAlicesTurn;\n eatenInPrevMove = eatenTillNow;\n }\n console.log([moves, a, b].join(\" \"));\n\n }\n return;\n}\n"}], "src_uid": "d70ee6d3574e0f2cac3c683729e2979d"} {"source_code": "print(function(a, d) {\n\tvar n = +readline();\n\tvar ans = [];\n\tfor (var i = 1; i <= n; i++) {\n\t\tvar x = (i * d) % (a * 4);\n\t\tif (x <= a) {\n\t\t\tans.push(x + ' 0');\n\t\t} else if (x <= 2 * a) {\n\t\t\tans.push(a + ' ' + (x - a))\n\t\t} else if (x <= 3 * a) {\n\t\t\tans.push((3 * a - x) + ' ' + a)\n\t\t} else {\n\t\t\tans.push('0 ' + (4 * a - x))\n\t\t}\n\t}\n\treturn ans.join('\\n');\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeFloats(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseFloat(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar factor = 100*100,\n\t\tdata = tokenizeFloats(readline()),\n\t\tside = factor*data[0], drink = factor*data[1],\n\t\tnumDrinks = parseInt(readline());\n\tvar parts = [], pos = 0, lap = 4*side;\n\tfor (var i = 0; i < numDrinks; ++i) {\n\t\tpos = (pos + drink) % lap;\n\t\tif (pos < side) {\n\t\t\tvar x = pos, y = 0;\n\t\t} else if (pos < 2*side) {\n\t\t\tvar x = side, y = pos - side;\n\t\t} else if (pos < 3*side) {\n\t\t\tvar x = 3*side - pos, y = side;\n\t\t} else {\n\t\t\tvar x = 0, y = lap - pos;\n\t\t}\n\t\tparts.push(x/factor);\n\t\tparts.push(' ');\n\t\tparts.push(y/factor);\n\t\tparts.push('\\n');\n\t}\n\tparts.pop();\n\tprint(parts.join(''));\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "d00b8423c3c52b19fec25bc63e4d4c1c"} {"source_code": "var str = readline().split(\" \");\nvar steps = +str[1];\nvar nums = str[0];\nvar numbers = readline().split(\"\");\nvar i = 0;\nwhile (steps && i < numbers.length){\n if (numbers.length == 1){\n numbers[0] = 0;\n break;\n }\n if (i == 0 && numbers[i] != 1){\n numbers[0] = 1;\n steps--;\n\n } else if( i>0 && numbers[i] != 0) {\n numbers[i] = 0;\n steps--;\n\n }\n i++;\n}\nwrite(numbers.join(\"\"));", "positive_code": [{"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n let [n, k, S] = input\n .replace('\\n', ' ')\n .split(' ')\n n = Number(n)\n k = Number(k)\n S = Array.from(S)\n\n for (let i = 0; i < n && k > 0; ++i) {\n if (i === 0 && i !== n-1) {\n if (S[i] !== '1') {\n S[i] = '1'\n --k\n }\n } else {\n if (S[i] !== '0') {\n S[i] = '0'\n --k\n }\n }\n }\n\n process.stdout.write(\n S.join(''),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}, {"source_code": "let lines = '';\nprocess.stdin.on('data', c => lines += c);\n\nconst solution = () => {\n\tlet line = lines.split('\\n');\n\tlet [n, k] = line[0].split(' ').map(v => parseInt(v,10));\n\tlet s = line[1];\n\tlet r = '';\n\tfor(let i = 0; i < n; i++){\n\t\tlet c = s[i];\n\t\t if (i === 0 && n == 1 && k > 0) {\n\t\t\tr += 0;\n\t\t\tk--;\n\t\t}else if (i === 0 && c > 1 && k > 0) {\n\t\t\tr += 1;\n\t\t\tk--;\n\t\t} else if (i !== 0 && c > 0 && k > 0) {\n\t\t\tr += 0;\n\t\t\tk--;\n\t\t} else {\n\t\t\tr += c;\n\t\t}\n\t}\n\t\n\tconsole.log(r);\n\tprocess.exit(0);\n}\n\nprocess.stdin.on('end', solution);\n"}, {"source_code": "\n'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(n == 1 && k) {\n ans += 0;\n} else\nif(str[0] != 1 && k) {\n -- k;\n ans += 1;\n} else ans += str[0];\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n}\n \nprint(ans);"}, {"source_code": "'use strict'\n \nconst fn = (k, x) => {\n if (x.length === 1 && k >= 1) return '0';\n if (k === 0) return x;\n let K = 0;\n if (x[0] !== '1') { k--; }\n \n while(k && K++ < x.length) {\n if (x[K] !== '0') k--;\n }\n const z = Math.min(K, x.length - 1);\n return '1' + '0'.repeat(z) + x.slice(z + 1)\n}\n \nwrite(fn(parseInt(readline().split(' ')[1]), readline()));"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar line = 0;\nvar n, k;\nvar S;\n\nrl.on('line', (data) => {\n\t++line;\n\t\n\tvar arr = data.split(' ');\n\t\n\tif(line===1) {\n\t\tn = parseInt(arr[0]);\n\t\tk = parseInt(arr[1]);\n\t} else {\n\t\tS = arr[0];\n\t\tvar array = S;\n\t\tvar result = '';\n//\t\tconsole.log(array)\n\t\t\n\t\tif(k===0) {\n\t\t\tconsole.log(S);\n\t\t} else if(n===1){\n\t\t\tconsole.log(0);\n\t\t} else {\n\t\t\tvar idx=1;\n\t\t\tif(array[0]!=='1'){\n\t\t\t\t--k;\n\t\t\t}\n\t\t\tresult+='1';\n\t\t\tfor(; idx {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const ax = arr.shift().split(' ')\n const s = arr.shift()\n const n = parseInt(ax[0])\n const k = parseInt(ax[1])\n let s2 = ''\n if(n == 1) {\n if(k == 1) console.log('0')\n else console.log(s)\n }\n else {\n for(let i = 0, no = 0; no < k && i < n; i++) {\n if(i == 0) s2 += 1\n else {\n s2 += 0\n }\n if(i == 0 && s[0] != 1) no ++\n else if(i !=0 && s[i] != 0) no ++\n }\n s2 += s.substr(s2.length)\n console.log(s2)\n\n }\n}) "}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar line = 0;\nvar n, k;\nvar S;\n\nrl.on('line', (data) => {\n\t++line;\n\t\n\tvar arr = data.split(' ');\n\t\n\tif(line===1) {\n\t\tn = parseInt(arr[0]);\n\t\tk = parseInt(arr[1]);\n\t} else {\n\t\tS = parseInt(arr[0]);\n\t\tvar result = '';\n\t\tvar array = Array.from(String(S), Number);\n\t\t\n\t\t\n\t\tif(k===0) {\n\t\t\tconsole.log(S);\n\t\t} else if(n===1){\n\t\t\tconsole.log(0);\n\t\t} else {\n\t\t\tvar idx=1;\n\t\t\tif(array[0]!==1){\n\t\t\t\t--k;\n\t\t\t}\n\t\t\tresult+='1';\n\t\t\tfor(; idx {\n\t++line;\n\tvar arr = data.split(' ');\n\tif(line===1) {\n\t\tn = parseInt(arr[0]);\n\t\tk = parseInt(arr[1]);\n\t} else {\n\t\tS = arr[0];\n\t\tvar array = S;\n\t\tvar result = '';\n\t\t\n\t\tif(k===0) {\n\t\t\tconsole.log(S);\n\t\t} else if(n===1){\n\t\t\tconsole.log(0);\n\t\t} else {\n\t\t\tvar idx=1;\n\t\t\tif(array[0]!=='1'){\n\t\t\t\t--k;\n\t\t\t}\n\t\t\tresult+='1';\n\t\t\tfor(; idx {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const ax = arr.shift().split(' ')\n const s = arr.shift()\n const n = parseInt(ax[0])\n const k = parseInt(ax[1])\n let s2 = ''\n if(n == 1) {\n console.log('0')\n }\n else {\n for(let i = 0, no = 0; no < k && i < n; i++) {\n if(i == 0) s2 += 1\n else {\n s2 += 0\n }\n if(i == 0 && s[0] != 1) no ++\n else if(s[i] != 0) no ++\n }\n s2 += s.substr(s2.length)\n console.log(s2)\n\n }\n}) "}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const ax = arr.shift().split(' ')\n const s = arr.shift()\n const n = parseInt(ax[0])\n const k = parseInt(ax[1])\n let s2 = ''\n for(let i = 0, no = 0; no < k; i++) {\n if(i == 0) s2 += 1\n else {\n s2 += 0\n }\n if(s[i] != 1 || s.length == 1) no ++\n }\n s2 += s.substr(s2.length)\n\n if(s2.length > 1) console.log(s2)\n else console.log('0')\n}) "}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const ax = arr.shift().split(' ')\n const s = arr.shift()\n const n = parseInt(ax[0])\n const k = parseInt(ax[1])\n let s2 = ''\n if(n == 1) {\n console.log('0')\n }\n else {\n for(let i = 0, no = 0; no < k && i < n; i++) {\n if(i == 0) s2 += 1\n else {\n s2 += 0\n }\n if(s[0] != 1) no ++\n else if(s[i] != 0) no ++ \n }\n s2 += s.substr(s2.length)\n console.log(s2)\n\n }\n}) "}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const ax = arr.shift().split(' ')\n const s = arr.shift()\n const n = parseInt(ax[0])\n const k = parseInt(ax[1])\n let s2 = ''\n if(n == 1) {\n if(k == 1) console.log('0')\n else console.log(s)\n }\n else {\n for(let i = 0, no = 0; no < k && i < n; i++) {\n if(i == 0) s2 += 1\n else {\n s2 += 0\n }\n if(i == 0 && s[0] != 1) no ++\n else if(s[i] != 0) no ++\n }\n s2 += s.substr(s2.length)\n console.log(s2)\n\n }\n}) "}, {"source_code": "let lines = '';\nprocess.stdin.on('data', c => lines += c);\n\nconst solution = () => {\n\tlet line = lines.split('\\n');\n\tlet [n, k] = line[0].split(' ').map(v => parseInt(v,10));\n\tlet s = line[1];\n\tlet r = '';\n\tfor(let i = 0; i < n; i++){\n\t\tlet c = s[i];\n\t\tif (i === 0 && c > 1 && k > 0) {\n\t\t\tr += 1;\n\t\t\tk--;\n\t\t} else if (i === 0 && n == 1 && k > 0) {\n\t\t\tr += 0;\n\t\t\tk--;\n\t\t} else if (i !== 0 && c > 0 && k > 0) {\n\t\t\tr += 0;\n\t\t\tk--;\n\t\t} else {\n\t\t\tr += c;\n\t\t}\n\t}\n\t\n\tconsole.log(r);\n\tprocess.exit(0);\n}\n\nprocess.stdin.on('end', solution);\n"}, {"source_code": "\n'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != 1 && k) {\n -- k;\n ans += 1;\n} else ans += str[0];\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n}\n \nprint(ans);"}, {"source_code": "'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != 1 && k) {\n -- k;\n ans += 1;\n}\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n -- k;\n}\n \nprint(ans);"}, {"source_code": "\n'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != 1 && k) {\n if(n == 1) {\n ans += 0;\n } else {\n -- k;\n ans += 1;\n }\n} else ans += str[0];\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n}\n \nprint(ans);"}, {"source_code": "'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != 1 && k) {\n -- k;\n ans += 1;\n}\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n}\n \nprint(ans);"}, {"source_code": "'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != '1' && k) {\n -- k;\n ans += 1;\n}\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n -- k;\n}\n \nprint(ans);"}, {"source_code": "'use strict'\n \nlet data = readline().split(' ');\n \nlet n = parseInt(data[0]), k = parseInt(data[1]);\n \nlet str = readline(), ans = \"\";\n \nif(str[0] != 1 && k) {\n -- k;\n ans += 1;\n} else ans += str[0];\n \nfor (let i = 1; i < n; ++ i) {\n if(!k || str[i] == '0') {\n ans += str[i];\n } else {\n -- k;\n ans += 0;\n }\n -- k;\n}\n \nprint(ans);"}, {"source_code": "var str = readline().split(\" \");\nvar steps = +str[1];\nvar nums = str[0];\nvar numbers = readline().split(\"\");\nvar i = 0;\nwhile (steps){\n if (i){\n numbers[i] = 0;\n steps--;\n } else if (numbers[i] != 1){\n numbers[i] = 1;\n steps--;\n } else if (numbers.length == 1){\n numbers[0] = 0;\n steps--;\n }\n\n i++;\n}\nwrite(numbers.join(\"\"));"}], "src_uid": "0515ac888937a4dda30cad5e2383164f"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst [nStr, kStr] = readLine().split(/\\s/)\n const n = Number(nStr)\n const k = BigInt(kStr)\n const as = readLine().split(/\\s/).map(Number)\n const max = Math.max.apply(null, as)\n const as1 = as.map(a => max - a)\n if (k % 2n === 1n) {\n console.log(as1.join(' '))\n continue\n }\n const max1 = Math.max.apply(null, as1)\n console.log(as1.map(a => max1 - a).join(' '))\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, time] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let max = Math.max(...arr);\n const store = [];\n for (let i = 0; i < arr.length; i++) {\n arr[i] = max - arr[i];\n }\n\n store.push(arr);\n max = Math.max(...arr);\n const _arr = [...arr];\n for (let i = 0; i < _arr.length; i++) {\n _arr[i] = max - _arr[i];\n }\n store.push(_arr);\n\n if ((time - 1) % 2 === 0) {\n console.log(store[0].join(\" \"));\n } else {\n console.log(store[1].join(\" \"));\n }\n }\n}\n"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM(pos) {\n const inputList = document.querySelectorAll(\".input\");\n const input = inputList[pos];\n return input.querySelector(\"pre\").textContent;\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM.bind(null, 0)\n}\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n let n, kOper, dmax, arr;\n \n const convert = x => dmax - x;\n function maxForBigInt(...args) {\n return args.reduce((a, b) => a > b ? a : b);\n };\n\n while (tc_count--) {\n [n, kOper] = [Number(readNum()), readNum()];\n arr = new BigInt64Array(n).map(readNum);\n //writeLine(`[${arr}]`);\n \n dmax = maxForBigInt(...arr);\n arr = arr.map(convert);\n\n if ((kOper & 1n) === 0n) {\n dmax = maxForBigInt(...arr);\n arr = arr.map(convert);\n }\n writeLine( arr.join(\" \"));\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = -1;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3n;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0n, sign = 1n, ch = nextDigit();\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10n + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return BigInt(aStr.charCodeAt(++cur) - 48);\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[++cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet [n, k] = readLine().split(' ');\n\n\t\tn = n >> 0;\n\t\tk = BigInt(k);\n\n\t\tlet arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tk = k & 1n ? 1 : 2;\n\t\tfor (let i = 0; i < k; i++) {\n\t\t\tlet d = Math.max(...arr);\n\t\t\tfor (let j = 0; j < n; j++) {\n\t\t\t\tarr[j] = d - arr[j];\n\t\t\t}\n\t\t}\n\t\tconsole.log(arr.join(' '));\n\t}\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n\tconst [n, k] = readLine().split(/\\s/).map(Number)\n const as = readLine().split(/\\s/).map(Number)\n const max = Math.max.apply(null, as)\n const as1 = as.map(a => max - a)\n if (k % 2 === 1) {\n console.log(as1.join(' '))\n continue\n }\n const max1 = Math.max.apply(null, as1)\n console.log(as1.map(a => max1 - a).join(' '))\n }\n}\n"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM() {\n const inputList = document.querySelectorAll(\".input\");\n const input = inputList[2];\n return input.querySelector(\"pre\").textContent;\n}\n\nstdioCPPattern({}, ({ readNum, readStr, writeLine, readCharArray }) => {\n // your code goes here\n let tc_count = readNum();\n let n, kOper, dmax, arr;\n \n const convert = x => dmax - x;\n\n while (tc_count--) {\n [n, kOper] = [readNum(), readNum()];\n arr = new Int32Array(n).map(readNum);\n \n dmax = Math.max(...arr);\n arr = arr.map(convert);\n\n if ((kOper & 1) === 0) {\n dmax = Math.max(...arr);\n arr = arr.map(convert);\n }\n writeLine( arr.join(\" \"));\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = 0;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n const MINUS_CODE = -3;\n\n callbackfn({\n readCharArray,\n log: console.log,\n readNum() {\n let x = 0, sign = 1, ch = aStr.charCodeAt(cur) - 48;\n while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();\n\n if (ch === MINUS_CODE) { sign = -1; ch = nextDigit(); }\n\n while (0 <= ch && ch <= 9) {\n x = x * 10 + ch;\n ch = nextDigit();\n }\n return x * sign;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(bufferLen = 1e6) {\n return readCharArray(bufferLen).join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n\n function nextDigit() {\n return aStr.charCodeAt(++cur) - 48;\n }\n\n function readCharArray(bufferLen = 1e6) {\n const chArr = Array(bufferLen);\n let ch = aStr[cur], p = 0;\n while (seperator.test(ch))\n ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[p++] = ch;\n ch = aStr[++cur];\n }\n return chArr.slice(0, p);\n }\n}"}], "src_uid": "f18a5fa0b2e7e96cb5994b7b2dbe0189"} {"source_code": "var line = readline().split(' ');\nvar a = +line[0];\nvar b = +line[1];\nvar n = a+b;\nvar j = 0;\nvar firstDay = [];\nvar secondDay = [];\nwhile (n - j -1 >= 0) {\n n -= ++j;\n}\nwhile ((j > 0) && (a+b > 0)) {\n if (a >= b) {\n a -= j--;\n firstDay.push(j+1);\n } else {\n b -= j--;\n secondDay.push(j+1);\n }\n}\nwrite(firstDay.length+'\\n'+firstDay.reverse().join(' ')+'\\n'+secondDay.length+'\\n'+secondDay.reverse().join(' '));", "positive_code": [{"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let standardInputString= '';\n let currentLine = 0;\n\n function readLine(){\n return standardInputString[currentLine++];\n }\n process.stdin.on('data', rawData =>{\n standardInputString += rawData;\n });\n process.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n })\n\n function main(){\n\n let [a,b] = readLine().split(' ').map(Number);\n // let line = readLine().split(' ').map(Number);\n\n\n let hardestDay = a>=b ? a : b;\n let easiestDay = a<=b ? a : b;\n let sum = 0;\n\n let easierSum = 0;\n\n let hardDayArr = [];\n let easiestDayArr = [];\n\n let imposterNumber = 0;\n let didOnce = 1;\n\n let smallestStart = 1;\n\n for(let j = 1; j<=hardestDay; ++j){\n\n if(sum >= hardestDay){\n imposterNumber = sum - hardestDay;\n if(imposterNumber !== 0){\n hardDayArr.splice(imposterNumber-1,1);\n }\n smallestStart = j;\n break;\n }\n else{\n sum += j;\n hardDayArr.push(j);\n }\n }\n if(imposterNumber !== 0){\n easierSum = imposterNumber\n easiestDayArr.push(easierSum);\n }\n for(smallestStart; smallestStart<=easiestDay; ++smallestStart){\n\n easierSum += smallestStart;\n if(easierSum <= easiestDay){\n easiestDayArr.push(smallestStart);\n }\n else{\n break;\n }\n }\n let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;\n if( pera!== hardestDay){\n hardDayArr.splice((pera - hardestDay) - 1, 1);\n };\n if(easiestDay === 0){\n easiestDayArr = [];\n }\n else if( hardestDay === 0){\n hardDayArr = [];\n }\n\n if(hardestDay === 1&& easiestDay ===1){\n easiestDayArr = [];\n }\n if(a===hardestDay){\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n }\n else{\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n\n }\n }\n"}, {"source_code": "var hours = readline().split(' ').map(v=>+v);\nvar shorterIndex = +(hours[0] > hours[1]);\n\nvar arr = hours[shorterIndex] = {\n nextIndex: 1 - shorterIndex,\n left: - hours[shorterIndex],\n values: []\n}, nextObj;\n\nfor(var i = 1; true; i++) {\n arr.values.push(i);\n arr.left += i;\n\n if (arr.left > 0) {\n if (arr.nextIndex === undefined) {\n arr.values.pop();\n break;\n } else {\n arr.values.splice(arr.left - 1, 1)\n arr = nextObj = hours[arr.nextIndex] = {\n left: -hours[arr.nextIndex] + arr.left,\n values: [arr.left]\n };\n\n if(arr.left > 0) {\n arr.values.pop();\n break;\n }\n }\n }\n}\n\nhours.forEach(v => {\n print(v.values.length);\nprint(v.values.join(' '));\n})"}], "negative_code": [{"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let standardInputString= '';\n let currentLine = 0;\n\n function readLine(){\n return standardInputString[currentLine++];\n }\n process.stdin.on('data', rawData =>{\n standardInputString += rawData;\n });\n process.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n })\n\n function main(){\n let [a,b] = readLine().split(' ').map(Number);\n // let line = readLine().split(' ').map(Number);\n\n\n let hardestDay = a>=b ? a : b;\n let easiestDay = a<=b ? a : b;\n let sum = 0;\n\n let easierSum = 0;\n\n let hardDayArr = [];\n let easiestDayArr = [];\n\n let imposterNumber = 0;\n let didOnce = 1;\n\n let smallestStart = 1;\n\n for(let j = 1; j<=hardestDay; j++){\n\n if(sum >= hardestDay){\n imposterNumber = sum - hardestDay;\n if(imposterNumber !== 0){\n hardDayArr.splice(imposterNumber-1,1);\n }\n // easierSum += imposterNumber + j;\n smallestStart = j;\n break;\n }\n else{\n sum += j;\n hardDayArr.push(j);\n }\n }\n if(imposterNumber !== 0){\n easierSum = imposterNumber\n easiestDayArr.push(easierSum);\n }\n for(smallestStart; smallestStart<=easiestDay; smallestStart++){\n\n easierSum += smallestStart;\n if(easierSum <= easiestDay){\n easiestDayArr.push(smallestStart);\n }\n }\n\n if(a===hardestDay){\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n }\n else{\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n\n }\n\n\n\n }\n"}, {"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let standardInputString= '';\n let currentLine = 0;\n\n function readLine(){\n return standardInputString[currentLine++];\n }\n process.stdin.on('data', rawData =>{\n standardInputString += rawData;\n });\n process.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n })\n\n function main(){\n let [a,b] = readLine().split(' ').map(Number);\n // let line = readLine().split(' ').map(Number);\n\n\n let hardestDay = a>=b ? a : b;\n let easiestDay = a<=b ? a : b;\n let sum = 0;\n\n let easierSum = 0;\n\n let hardDayArr = [];\n let easiestDayArr = [];\n\n let imposterNumber = 0;\n let didOnce = 1;\n\n let smallestStart = 1;\n\n for(let j = 1; j<=hardestDay; ++j){\n\n if(sum >= hardestDay){\n imposterNumber = sum - hardestDay;\n if(imposterNumber !== 0){\n hardDayArr.splice(imposterNumber-1,1);\n }\n smallestStart = j;\n break;\n }\n else{\n sum += j;\n hardDayArr.push(j);\n }\n }\n if(imposterNumber !== 0){\n easierSum = imposterNumber\n easiestDayArr.push(easierSum);\n }\n for(smallestStart; smallestStart<=easiestDay; ++smallestStart){\n\n easierSum += smallestStart;\n if(easierSum <= easiestDay){\n easiestDayArr.push(smallestStart);\n }\n else{\n break;\n }\n }\n let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;\n if( pera!== hardestDay){\n hardDayArr.splice((pera - hardestDay) - 1, 1);\n };\n if(a===hardestDay){\n console.log(hardDayArr.length);\n console.log(hardDayArr.join(\" \"));\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n }\n else{\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n console.log(hardDayArr.length);\n console.log(hardDayArr.join(\" \"));\n\n }\n }\n"}, {"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let standardInputString= '';\n let currentLine = 0;\n\n function readLine(){\n return standardInputString[currentLine++];\n }\n process.stdin.on('data', rawData =>{\n standardInputString += rawData;\n });\n process.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n })\n\n function main(){\n let [a,b] = readLine().split(' ').map(Number);\n // let line = readLine().split(' ').map(Number);\n\n\n let hardestDay = a>=b ? a : b;\n let easiestDay = a<=b ? a : b;\n let sum = 0;\n\n let easierSum = 0;\n\n let hardDayArr = [];\n let easiestDayArr = [];\n\n let imposterNumber = 0;\n let didOnce = 1;\n\n let smallestStart = 1;\n\n for(let j = 1; j<=hardestDay; ++j){\n\n if(sum >= hardestDay){\n imposterNumber = sum - hardestDay;\n if(imposterNumber !== 0){\n hardDayArr.splice(imposterNumber-1,1);\n }\n smallestStart = j;\n break;\n }\n else{\n sum += j;\n hardDayArr.push(j);\n }\n }\n if(imposterNumber !== 0){\n easierSum = imposterNumber\n easiestDayArr.push(easierSum);\n }\n for(smallestStart; smallestStart<=easiestDay; ++smallestStart){\n\n easierSum += smallestStart;\n if(easierSum <= easiestDay){\n easiestDayArr.push(smallestStart);\n }\n else{\n break;\n }\n }\n let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;\n if( pera!== hardestDay){\n hardDayArr.splice((pera - hardestDay) - 1, 1);\n };\n if(easiestDay === 0){\n easiestDayArr = [];\n }\n else if( hardestDay === 0){\n hardDayArr = [];\n }\n if(a===hardestDay){\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n }\n else{\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n console.log(hardDayArr.length);\n console.log(hardDayArr.reverse().join(\" \"));\n\n }\n }\n"}, {"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let standardInputString= '';\n let currentLine = 0;\n\n function readLine(){\n return standardInputString[currentLine++];\n }\n process.stdin.on('data', rawData =>{\n standardInputString += rawData;\n });\n process.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n })\n\n function main(){\n let [a,b] = readLine().split(' ').map(Number);\n // let line = readLine().split(' ').map(Number);\n\n\n let hardestDay = a>=b ? a : b;\n let easiestDay = a<=b ? a : b;\n let sum = 0;\n\n let easierSum = 0;\n\n let hardDayArr = [];\n let easiestDayArr = [];\n\n let imposterNumber = 0;\n let didOnce = 1;\n\n let smallestStart = 1;\n\n for(let j = 1; j<=hardestDay; j++){\n\n if(sum >= hardestDay){\n imposterNumber = sum - hardestDay;\n if(imposterNumber !== 0){\n hardDayArr.splice(imposterNumber-1,1);\n }\n // easierSum += imposterNumber + j;\n smallestStart = j;\n break;\n }\n else{\n sum += j;\n hardDayArr.push(j);\n }\n }\n if(imposterNumber !== 0){\n easierSum = imposterNumber\n easiestDayArr.push(easierSum);\n }\n for(smallestStart; smallestStart<=easiestDay; smallestStart++){\n\n easierSum += smallestStart;\n if(easierSum <= easiestDay){\n easiestDayArr.push(smallestStart);\n }\n }\n\n console.log(easiestDayArr.length);\n console.log(easiestDayArr.join(\" \"));\n\n console.log(hardDayArr.length);\n console.log(hardDayArr.join(\" \"));\n }\n"}], "src_uid": "fab438cef9eb5e9e4a4a2e3f9e4f9cec"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n a.sort((a, b) => {\r\n if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];\r\n });\r\n const nums = new Array(n);\r\n const segTree = new SegTree(n);\r\n for (let [l, r, val] of a) {\r\n segTree.update(l - 1, r - 1, val);\r\n }\r\n for (let i = 0; i < n; i++) nums[i] = segTree.query(i);\r\n let res = 0;\r\n for (let i = 0; i < 31; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (nums[j] & 1 << i) {\r\n res = add(res, mul(1 << i, power(2, n - 1)));\r\n break;\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\nconst MOD = 10 ** 9 + 7;\r\nfunction mod(num) {\r\n return (num % MOD + MOD) % MOD;\r\n}\r\nfunction add(a, b) {\r\n return mod(mod(a) + mod(b));\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = x => {\r\n x = Math.max(x, 0);\r\n x = Math.min(x, n);\r\n return this._query(this.root, 0, n, x);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.add) {\r\n left.add = node.add;\r\n left.val = node.add;\r\n right.add = node.add;\r\n right.val = node.add;\r\n node.add = 0;\r\n }\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add = z;\r\n node.val = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n }\r\n _query(node, l, r, x) {\r\n if (!node) return 0;\r\n if (l === r) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "\r\nlet _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});\r\n\tconst mod = 1e9 + 7;\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve() {\r\n\t let [n, m] = inputReader.readNumberArray();\r\n\t let totalOr = 0;\r\n\t while (m--) {\r\n\t let [l, r, or] = inputReader.readNumberArray();\r\n\t totalOr |= or;\r\n\t }\r\n\t totalOr %= mod;\r\n\t for (let i = 1; i <= n - 1; i++) totalOr = (2 * totalOr) % mod;\r\n\t console.log(totalOr);\r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const or = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n output[i] = solve(n, m, or)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, or) {\n const arr = Array(n).fill(0)\n or.forEach(([l, r, x]) => {\n arr[l - 1] |= x\n arr[r - 1] |= x\n })\n// const arr = [0, 2]\n// const arr = [5, 6, 7, 0, 2]\n let prev\n let limit = 1\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n const next = []\n for (let j = 0; j < 30; j++) {\n if (arr[i] & (1 << j)) {\n if (i) {\n next[j] = minus(limit, prev[j])\n next[j] = add(next[j], prev[j])\n } else {\n next[j] = limit\n }\n } else {\n if (i) {\n next[j] = prev[j]\n next[j] = add(next[j], prev[j])\n } else {\n next[j] = 0\n }\n }\n if (i === arr.length - 1) {\n ans = add(ans, mul(next[j], 1 << j))\n }\n }\n limit = mul(limit, 2)\n prev = next\n// console.log(prev)\n }\n\n return ans\n}\nfunction add(a, b) {\n return (a + b) % (1e9 + 7)\n}\nfunction minus(a, b) {\n return (a - b + 1e9 + 7) % (1e9 + 7)\n}\nfunction mul(a, b) {\n let r = 0\n let base = a\n while (b) {\n if (b & 1) {\n r = add(r, base)\n }\n b >>= 1\n base = add(base, base)\n }\n return r\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n let num = a.reduce((a, b) => a | b[2], 0);\r\n let res = 0;\r\n for (let i = 0; i < 31; i++) {\r\n if (num & 1 << i) {\r\n res = add(res, mul(1 << i, power(2, n - 1)));\r\n }\r\n }\r\n return res;\r\n}\r\nconst MOD = 10 ** 9 + 7;\r\nfunction mod(num) {\r\n return (num % MOD + MOD) % MOD;\r\n}\r\nfunction add(a, b) {\r\n return mod(mod(a) + mod(b));\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n a.sort((a, b) => {\r\n if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];\r\n });\r\n const nums = new Array(n);\r\n const segTree = new SegTree(n);\r\n for (let [l, r, val] of a) {\r\n segTree.update(l - 1, r - 1, val);\r\n }\r\n for (let i = 0; i < n; i++) nums[i] = segTree.query(i);\r\n let res = 0;\r\n for (let i = 0; i < 31; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (nums[j] & 1 << i) {\r\n res = res + (1 << i) * 2 ** (n - 1);\r\n break;\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = x => {\r\n x = Math.max(x, 0);\r\n x = Math.min(x, n);\r\n return this._query(this.root, 0, n, x);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.add) {\r\n left.add = node.add;\r\n left.val = node.add;\r\n right.add = node.add;\r\n right.val = node.add;\r\n node.add = 0;\r\n }\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add = z;\r\n node.val = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n }\r\n _query(node, l, r, x) {\r\n if (!node) return 0;\r\n if (l === r) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n a.sort((a, b) => {\r\n if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];\r\n });\r\n const nums = new Array(n);\r\n const segTree = new SegTree(n);\r\n for (let [l, r, val] of a) {\r\n segTree.update(l - 1, r - 1, val);\r\n }\r\n for (let i = 0; i < n; i++) nums[i] = segTree.query(i);\r\n let res = 0;\r\n for (let i = 0; i < 31; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (nums[i] & 1 << i) {\r\n res = add(res, mul(1 << i, power(2, n - 1)));\r\n break;\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\nconst MOD = 10 ** 9 + 7;\r\nfunction mod(num) {\r\n return (num % MOD + MOD) % MOD;\r\n}\r\nfunction add(a, b) {\r\n return mod(mod(a) + mod(b));\r\n}\r\nfunction power(a, b) {\r\n let res = 1;\r\n while (b) {\r\n if (b & 1) res = mul(res, a);\r\n a = mul(a, a);\r\n b = b >> 1;\r\n }\r\n return res;\r\n}\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = x => {\r\n x = Math.max(x, 0);\r\n x = Math.min(x, n);\r\n return this._query(this.root, 0, n, x);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.add) {\r\n left.add = node.add;\r\n left.val = node.add;\r\n right.add = node.add;\r\n right.val = node.add;\r\n node.add = 0;\r\n }\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add = z;\r\n node.val = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n }\r\n _query(node, l, r, x) {\r\n if (!node) return 0;\r\n if (l === r) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n const mod = 1e9 + 7;\r\n let t = inputReader.readNumber();\r\n\r\n function modPower(x, y, mod) {\r\n let res = 1;\r\n x = x % mod;\r\n if (x == 0) return 0;\r\n while (y > 0) {\r\n if (y & 1) res = (res * x) % mod;\r\n y = y >> 1;\r\n x = (x * x) % mod;\r\n }\r\n return res;\r\n }\r\n\r\n function solve() {\r\n let [n, m] = inputReader.readNumberArray();\r\n let totalOr = 0;\r\n while (m--) {\r\n let [l, r, or] = inputReader.readNumberArray();\r\n totalOr |= or;\r\n }\r\n totalOr %= mod;\r\n let ans = totalOr * modPower(2, n - 1, mod);\r\n console.log(ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n const mod = 1e9 + 7;\r\n let t = inputReader.readNumber();\r\n\r\n function modPower(x, y, mod) {\r\n let res = 1;\r\n x = x % mod;\r\n if (x == 0) return 0;\r\n while (y > 0) {\r\n if (y & 1) res = (res * x) % mod;\r\n y = y >> 1;\r\n x = (x * x) % mod;\r\n }\r\n return res;\r\n }\r\n\r\n function solve() {\r\n let [n, m] = inputReader.readNumberArray();\r\n let totalOr = 0;\r\n while (m--) {\r\n let [l, r, or] = inputReader.readNumberArray();\r\n totalOr |= or;\r\n }\r\n let ans = totalOr * modPower(2, n - 1, mod);\r\n console.log(ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}], "src_uid": "c4ba92632e10b1710686930f0c4536fa"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar map = {};\r\n\tvar sosu = Array.from(sieveOfEratos(30000));\r\n\tsosu.sort(function(a,b){\r\n\t\treturn a - b;\r\n\t});\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar d = nextInt();\r\n\t\tif(map[d] != null){\r\n\t\t\tmyout(map[d]);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar L = 0;\r\n\t\tvar index = -1;\r\n\t\tfor(var j = 0; j < sosu.length; j++){\r\n\t\t\tif(sosu[j] > d){\r\n\t\t\t\tindex = j;\r\n\t\t\t\tL = sosu[j];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar R = 0;\r\n\t\tfor(var j = index + 1; j < sosu.length; j++){\r\n\t\t\tif(sosu[j] - L >= d){\r\n\t\t\t\tR = sosu[j];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(L * R);\r\n\t\tmap[d] = L * R;\r\n\t}\r\n}\r\nfunction isPrime(val){\r\n if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\r\n return false;\r\n }else if(val == 2){\r\n return true;\r\n }\r\n var root = Math.floor(Math.sqrt(val));\r\n for(var i = 3; i <= root; i += 2){\r\n if(val % i == 0){\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\nfunction sieveOfEratos(val){\r\n var primes = new Set();\r\n var nums = new Set();\r\n var used = [2,3,5,7,11];//\u3053\u308c\u3089\u306f\u65e2\u306b\u7d20\u6570\u3067\u3042\u308b\u3068\u3059\u308b\r\n var underPrime = 13;//\u3053\u306e\u5024\u304b\u3089+2\u3054\u3068\u306b\u8ffd\u52a0\u3002\u2191\u306e\u5024\u3067\u5272\u308a\u5207\u308c\u305f\u3082\u306e\u306f\u4f55\u3082\u3057\u306a\u3044\r\n if(val <= 1){\r\n return nums;\r\n }\r\n for(var i = 0; i < used.length; i++){if(used[i] <= val){nums.add(used[i]);}}\r\n for(var i = underPrime; i <= val; i = i + 2){\r\n var continued = false;\r\n for(var j = 0; j < used.length; j++){\r\n if(i % used[j] == 0){continued = true; break;}\r\n }\r\n if(continued){continue;}\r\n nums.add(i);\r\n }\r\n for(var i = 2; i <= Math.sqrt(val); (i == 2) ? i++ : i = i + 2){\r\n if(!nums.has(i)){continue;}\r\n var count = 1;\r\n while(i * count <= val){\r\n if(i <= 11 && used.indexOf(i) != -1){break;}\r\n if(count == 1){primes.add(i);}\r\n nums.delete(i * count);\r\n count++;\r\n }\r\n }\r\n var primeItr = Array.from(primes);\r\n for(var i = 0; i < primeItr.length; i++){\r\n nums.add(primeItr[i]);\r\n }\r\n return nums;\r\n}", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\tconst map = new Map();\n\tconst primes = [2];\n\tconst isPrime = Array(1e5).fill(1);\n\n\tfor (let i = 3; i <= 1e5; i += 2) {\n\t\tif (isPrime[i] === 1) {\n\t\t\tprimes.push(i);\n\t\t\tfor (let j = i + i; j <= 1e5; j += i) {\n\t\t\t\tisPrime[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\twhile (t--) {\n\t\tconst n = +readLine();\n\t\tif (map.has(n)) console.log(map.get(n));\n\t\telse {\n\t\t\tconst a = immediateGreaterValue(primes, n);\n\t\t\tconst b = immediateGreaterValue(primes, a + n - 1);\n\t\t\tmap.set(n, a * b);\n\t\t\tconsole.log(a * b);\n\n\t\t\tfunction immediateGreaterValue(arr, target) {\n\t\t\t\tlet [left, right] = [0, arr.length - 1];\n\t\t\t\twhile (left <= right) {\n\t\t\t\t\tconst mid = left + Math.floor((right - left) / 2);\n\t\t\t\t\tif (arr[mid] > target) right = mid - 1;\n\t\t\t\t\telse left = mid + 1;\n\t\t\t\t}\n\t\t\t\treturn arr[left];\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var d =n+1\r\n sumDivisors(d*d*d, n)\r\n // console.log((1+n)*(1+2*n))\r\n\r\n })\r\n\r\n}\r\n\r\nfunction sumDivisors(n, d) {\r\n var sum = 0;\r\n var nn = 1+d\r\n while(!isPrime(nn)) nn++\r\n var nn2 = nn+d\r\n while(!isPrime(nn2)) nn2++\r\n\r\n console.log(nn2*nn)\r\n}\r\nfunction isPrime(num) {\r\n for(var i = 2; i < num; i++)\r\n if(num % i === 0) return false;\r\n return num > 1;\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n const checkPrime = (n) => {\r\n for (let i = 2; i * i <= n; i++) {\r\n if (n % i === 0) return false;\r\n }\r\n return true;\r\n };\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let c = n + 1;\r\n while (true) {\r\n if (checkPrime(c)) break;\r\n c++;\r\n }\r\n let res = c;\r\n c = c + n;\r\n while (true) {\r\n if (checkPrime(c)) break;\r\n c++;\r\n }\r\n console.log(res * c);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let n = readline() // .split(' ')\n // let n = line[0]\n // let k = line[1]\n // let ans = ''\n let first = 0, second = 0\n // ------------------\n // console.log('n = ', n)\n let num = 1 + parseInt(n)\n while ( first == 0) {\n first = isPrime(num)\n num++\n }\n // console.log('first = ', first)\n num += n - 1\n while ( second == 0) {\n second = isPrime(num)\n num++\n }\n // console.log('second = ', second)\n console.log(first * second)\n}\n\nfunction isPrime (num) {\n // console.log('isPrime num = ', num)\n if (num == 2)\n return 2\n if (num % 2 == 0)\n return 0\n else {\n if (num == 3)\n return 3\n\n let limit = parseInt(Math.sqrt(num))\n let i = 0\n for ( i = 3; i <= limit; i += 2) {\n if (num % i == 0)\n return 0\n }\n // console.log('i = ', i)\n return num\n }\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst isPrime = n => {\n for (let index = 2; index < Math.ceil(Math.floor(n)); index++) {\n if (n % index === 0) return false\n }\n return true\n}\n\nconst calculate = d => {\n let first = 1 + d\n while (!isPrime(first)) {\n first++\n }\n\n let second = first + d\n while (!isPrime(second)) {\n second++\n }\n\n return first * second\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet d\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n d = Number(line)\n\n answer.push(calculate(d))\n\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n index++\n }\n})\n// console.log(calculate(6, 5, [1, 2, 3, 3, 2, 1]))\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(iter; iter > 0; iter--){\r\n let n = parseInt(readline());\r\n \r\n let temp = findNextPrime(1, n)\r\n let res = temp * findNextPrime(temp, n)\r\n print(res)\r\n}\r\n\r\nfunction findNextPrime(n, d){\r\n for(let i = n + d;; i++){\r\n if(isPrime(i)) return i;\r\n }\r\n}\r\n\r\nfunction isPrime(n){\r\n for(let i = 2; i <= Math.sqrt(n); i++){\r\n if(n % i === 0) return false;\r\n }\r\n return true;\r\n}"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst n = +readLine();\n\t\tconst [a, b] = [1 + n, 1 + 2 * n];\n\t\tconsole.log(a * b);\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n console.log((1+n)*(1+2*n))\r\n\r\n })\r\n\r\n}\r\n\r\n"}], "src_uid": "648ec67565c506c3e2ffd007ad44e8c3"} {"source_code": "const rubleCount = Number(readline());\nconst dollarPrice = Number(readline());\nconst euroPrice = Number(readline()) * 5;\nvar result = rubleCount;\nfor (var i = 0;; i++) {\n var remaining = rubleCount - i * dollarPrice;\n if (remaining < 0) break;\n var cur = remaining % euroPrice;\n if (cur < result) result = cur;\n}\nprint(result);\n", "positive_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var d = rdN();\n var e = rdN();\n \n var d1 = d;\n var e5 = e*5;\n \n var a = Math.floor(n / d1);\n var b = 0;\n var res = n%d1;\n \n while (a >= 0) {\n var s = a*d1 + b*e5;\n if (s <= n) {\n res = Math.min(res, n - s);\n ++b;\n } else {\n --a;\n }\n }\n\n wr(res);\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "const rubleCount = Number(readline());\nconst dollarPrice = Number(readline());\nconst euroPrice = Number(readline()) * 5;\nvar result = rubleCount;\nfor (var i = 0;; i++) {\n var remaining = rubleCount - i * dollarPrice;\n if (remaining < 0) break;\n var cur = remaining % euroPrice;\n if (cur < result) result = cur;\n}\nprint(result);\n"}], "negative_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var d = rdN();\n var e = rdN();\n \n var d1 = d;\n var e5 = e*5;\n var b = Math.max(d1,e5);\n var s = Math.min(d1,e5);\n var diff = b - s;\n \n var res1 = n%b;\n res1 %= s;\n \n var res2 = n%s;\n res2 %= diff;\n wr(Math.min(res1, res2));\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var d = rdN();\n var e = rdN();\n \n var d1 = d;\n var e5 = e*5;\n \n var a = Math.floor(n / d1);\n var b = 0;\n var res = n%d1;\n \n while (a > 0) {\n var s = a*d1 + b*e5;\n if (s <= n) {\n res = Math.min(res, n - s);\n ++b;\n } else {\n --a;\n }\n }\n\n wr(res);\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var d = rdN();\n var e = rdN();\n \n var d1 = d;\n var e5 = e*5;\n \n wr(Math.min(n%d1%e5, n%e5%d1));\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var d = rdN();\n var e = rdN();\n \n var d1 = d;\n var e5 = e*5;\n \n wr(Math.min([n%d1%e5, n%e5%d1]));\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "8c5d9b4fd297706fac3be83fc85028a0"} {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n\r\n let count = 1;\r\n for (let i = 0; i < lines[0]; ++i) {\r\n let total = 0;\r\n const a = lines[count].split(' ').map((el) => +el);\r\n\r\n let diff1 = a[1] - a[0];\r\n let diff2 = a[2] - a[1];\r\n let diff3 = a[2] - a[0];\r\n\r\n // a[0] = 10, a[1] = 5, a[2] = 30\r\n // diff1 = -5, diff2 = 25, diff3 = 20\r\n\r\n // a[2] * X = a[1] + diff1;\r\n // X = (a[1] + diff1) / a[2] => (0 / 30) => X = 0\r\n // a[0] * Y = a[1] - diff2;\r\n // Y = (a[1] - diff2) / a[0] => (-20 / 10) => Y = -2;\r\n // if diff3 % 2 === 0 return false\r\n // a[1] * Z = a[2] - (diff3 / 2)\r\n // Z = (a[2] - (diff3 / 2)) / a[1] => 20 / 5 => Z = 4\r\n\r\n const x = (a[1] + diff1) / a[2];\r\n const y = (a[1] - diff2) / a[0];\r\n\r\n let z = 0;\r\n if (diff3 % 2 === 0) {\r\n z = (a[2] - (diff3 / 2)) / a[1];\r\n }\r\n\r\n if ((x > 0 && Number.isInteger(x)) || (y > 0 && Number.isInteger(y)) || (z > 0 && Number.isInteger(z))) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n\r\n count += 1;\r\n }\r\n});\r\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n\r\n var a = inp[0];\r\n var b = inp[1];\r\n var c = inp[2];\r\n\r\n if (2 * b - c > 0 && (2 * b - c) % a === 0) {\r\n return \"Yes\";\r\n } else if ((c + a) % (2 * b) === 0) {\r\n return \"Yes\";\r\n } else if (2 * b - a > 0 && (2 * b - a) % c === 0) {\r\n return \"Yes\";\r\n }\r\n\r\n return \"No\";\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n function as(x,y,z) {\r\n var d = y-x;\r\n if(((y+d)%z) == 0 && y+d > 0) return true;\r\n else return false;\r\n }\r\n function ase(x,y,z) {\r\n var d = y-x;\r\n if(((x-d)%z) == 0 && x-d > 0) return true;\r\n else return false;\r\n }\r\n function ad(x,y,z) {\r\n var d = (y-x)/2;\r\n //if(x+d==0) return false;\r\n if(((x+d)%z) == 0 && x+d > 0) return true;\r\n else return false;\r\n }\r\n //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))\r\n var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])\r\n console.log(c ? 'YES' : 'NO')\r\n}"}, {"source_code": "let data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n\r\n input = input.map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n );\r\n\r\n const doesformAP = (a, b, c) => {\r\n const m1 = (2 * b - c) / a;\r\n const m2 = (c + a) / (2 * b);\r\n const m3 = (2 * b - a) / c;\r\n\r\n if (m1 > 0 && Math.ceil(m1) == m1) {\r\n return true;\r\n }\r\n\r\n if (m2 > 0 && Math.ceil(m2) == m2) {\r\n return true;\r\n }\r\n\r\n if (m3 > 0 && Math.ceil(m3) == m3) {\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n input.forEach((el) => {\r\n if (doesformAP(el[0], el[1], el[2])) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n });\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, c] = rna();\r\n\r\n\t\tconst check = x => x > 0 && x%1 == 0;\r\n\r\n\t\tconst ans = check((2*b-c)/a) || check((2*b-a)/c) || check((a+c)/(2*b));\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let testCase = 1; testCase < input.length; testCase++) {\r\n let numbers = input[testCase].split(\" \");\r\n let a = +numbers[0];\r\n let b = +numbers[1];\r\n let c = +numbers[2];\r\n\r\n newA = b - (c - b);\r\n if (newA >= a && newA % a == 0 && newA != 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n let newB = a + (c - a) / 2;\r\n if (newB >= b && (c - a) % 2 == 0 && newB % b == 0 && newB != 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n let newC = a + 2 * (b - a);\r\n if (newC >= c && newC % c == 0 && newC != 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n console.log(\"NO\");\r\n }\r\n};\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], c = k[2];\n var bc = 2 * b - c;\n var ba = 2 * b - a;\n var bcs = bc > 0 && bc % a === 0;\n var bas = ba > 0 && ba % c === 0;\n if(bcs || (a + c) % (b * 2) === 0 || bas){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b, c;\r\n\r\n while (T--) {\r\n [a, b, c] = lines[index++].split(' ').map(Number);\r\n\r\n if (solve(a, b, c) || solve(c, b, a)) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n\r\nfunction solve(a, b, c) {\r\n let diff;\r\n let newVal;\r\n\r\n // already an AP\r\n if (isAP([a, b, c ])) {\r\n return true;\r\n }\r\n\r\n // a\r\n diff = c - b;\r\n newVal = b - diff;\r\n if (diff >= 0 && newVal > a && newVal % a === 0 && isAP([newVal, b, c])) {\r\n return true;\r\n }\r\n\r\n // b\r\n diff = (c - a) / 2;\r\n newVal = a + diff;\r\n if (diff >= 0 && newVal > b && newVal % b === 0 && isAP([a, newVal, c])) {\r\n return true;\r\n }\r\n\r\n // c\r\n diff = b - a;\r\n newVal = b + diff;\r\n if (diff >= 0 && newVal > c && newVal % c === 0 && isAP([a, b, newVal])) {\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction isAP(arr) {\r\n return arr[2] - arr[1] === arr[1] - arr[0];\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let nums = readLine().split(\" \");\r\n let a = parseInt(nums[0]);\r\n let b = parseInt(nums[1]);\r\n let c = parseInt(nums[2]);\r\n let m1 = (2 * b - c) / a;\r\n let m2 = (a + c) / (2 * b);\r\n let m3 = (2 * b - a) / c;\r\n if (Number.isSafeInteger(m1) && m1 >= 1 || Number.isSafeInteger(m2) && m2 >= 1 || Number.isSafeInteger(m3) && m3 >= 1) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve(){\r\n\t let [a,b,c] = inputReader.readNumberArray();\r\n\t let ok = false;\r\n\t if((a + c) % (2*b) == 0 && (a + c) / (2 * b) > 0) ok = true;\r\n\t if((2 * b - c) % a == 0 && (2 * b - c) / a > 0) ok = true;\r\n\t if((2 * b - a) % c == 0 && (2 * b - a) / c > 0) ok = true;\r\n\t if(ok) console.log(\"YES\")\r\n\t else console.log(\"NO\");\r\n\t}\r\n\t\r\n\twhile(t--){\r\n\t solve(); \r\n\t}\r\n\t\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const n = +(readline());\r\n for(let i =0; i{\r\n\r\n}\r\n\r\nconst doesformAP = (a,b,c)=>{\r\n const m1 = (2*b - c ) / a;\r\n const m2 = (c+a)/(2*b); \r\n const m3 = (2*b -a )/(c);\r\n \r\n if(m1>0 && Math.ceil(m1) == m1){\r\n return true\r\n }\r\n\r\n if(m2 >0 && Math.ceil(m2) == m2){\r\n return true\r\n } \r\n\r\n if(m3>0 && Math.ceil(m3) == m3){\r\n return true\r\n } \r\n return false;\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b, c]) {\r\n if (Math.floor((a + c) / 2) % b === 0 && (a + c) % 2 === 0) {\r\n console.log('YES')\r\n return\r\n }\r\n if ((2 * b - c) % a === 0 && 2 * b - c > 0) {\r\n console.log('YES')\r\n return\r\n }\r\n if ((2 * b - a) % c === 0 && 2 * b - a > 0) {\r\n console.log('YES')\r\n return\r\n }\r\n console.log('NO')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const tsc = await readInt();\r\n for(let sc = 0; sc < tsc; sc++) {\r\n const [a,b,c] = await readIntArray();\r\n const can = (num1, num2) => {\r\n if (num2 === 0)\r\n return true;\r\n return num1%num2===0 && num1/num2 > 0;\r\n }\r\n if (can(b + (b-a), c) || can(b - (c-b), a) || ((c+a)%2 === 0 && can((c+a)/2, b))) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n if (a + c === 2 * b) return true\n return ok(2 * b - c, a)\n || ok(2 * b - a, c)\n || ok(a + c, 2 * b)\n}\nfunction ok(a, b) {\n return a > 0 && !(a % b)\n}\n"}, {"source_code": "var q=+readline();function isInt(a){return a%1==0}function isPosT(a,b){if(a==0&&b==0)return true;if(a==0)return false;if(b==0)return false;return a/b>0&&isInt(a/b)}wb:while(q--){var des=readline().split(\" \").map(function(x){return+x});fb:for(var i=0;i<3;i++){switch(i){case 0:if(isPosT(2*des[1]-des[2],des[0])){print(\"YES\");continue wb}break;case 1:if(isPosT((des[0]+des[2])/2,des[1])){print(\"YES\");continue wb}break;case 2:if(isPosT(2*des[1]-des[0],des[2])){print(\"YES\");continue wb}break}}print(\"NO\")}\r\n"}], "negative_code": [{"source_code": "var q = +readline(); function isInt(a, b) { if (a == 0) return true; if (b == 0) return false; return Math.floor(a / b) === a / b } wb: while (q--) { var des = readline().split(\" \").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print(\"YES\"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print(\"YES\"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print(\"YES\"); continue wb } break } } print(\"NO\") }"}, {"source_code": "var q = +readline(); function isInt(a, b) { if (a == 0) return true; if (b != 0) return false; return Math.floor(a / b) === a / b } wb: while (q--) { var des = readline().split(\" \").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print(\"YES\"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print(\"YES\"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print(\"YES\"); continue wb } break } } print(\"NO\") }"}, {"source_code": "var q = +readline(); function isInt(a, b) { if (a != 0 && b != 0) return Math.floor(a / b) === a / b; return false } wb: while (q--) { var des = readline().split(\" \").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print(\"YES\"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print(\"YES\"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print(\"YES\"); continue wb } break } } print(\"NO\") }"}, {"source_code": "var q = +readline();\r\nfunction isInt(a, b) {\r\n if (a != 0 && b != 0) return Math.floor(a / b) === a / b;\r\n return false;\r\n}\r\nwb: while (q--) {\r\n var des = readline().split(\" \").map(function (x) {\r\n return +x;\r\n });\r\n // console.log(des);\r\n fb: for (var i = 0; i < 3; i++) {\r\n switch (i) {\r\n case 0:\r\n if (isInt(2 * des[1] - des[2], des[0])) {\r\n print(\"YES\");\r\n continue wb;\r\n }\r\n break;\r\n case 1:\r\n if (isInt((des[0] + des[2]) / 2, des[1])) {\r\n print(\"YES\");\r\n continue wb;\r\n }\r\n break;\r\n case 2:\r\n if (isInt(2 * des[1] - des[0], des[2])) {\r\n print(\"YES\");\r\n continue wb;\r\n }\r\n break;\r\n }\r\n }\r\n print(\"NO\");\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n function as(x,y,z) {\r\n var d = y-x;\r\n if(((y+d)%z) == 0) return true;\r\n else return false;\r\n }\r\n function ase(x,y,z) {\r\n var d = y-x;\r\n \r\n if(((x-d)%z) == 0) return true;\r\n else return false;\r\n }\r\n function ad(x,y,z) {\r\n var d = (y-x)/2;\r\n \r\n if(((x+d)%z) == 0) return true;\r\n else return false;\r\n }\r\n //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))\r\n var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])\r\n console.log(c ? 'YES' : 'NO')\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n function as(x,y,z) {\r\n var d = y-x;\r\n if(y+d==0) return false\r\n else if(((y+d)%z) == 0) return true;\r\n else return false;\r\n }\r\n function ase(x,y,z) {\r\n var d = y-x;\r\n if(x-d==0) return false\r\n else if(((x-d)%z) == 0) return true;\r\n else return false;\r\n }\r\n function ad(x,y,z) {\r\n var d = (y-x)/2;\r\n if(x+d==0) return false;\r\n else if(((x+d)%z) == 0) return true;\r\n else return false;\r\n }\r\n //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))\r\n var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])\r\n console.log(c ? 'YES' : 'NO')\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let a = readline().split(\" \").map(w => parseInt(w))\r\n function as(x,y,z) {\r\n var d = y-x;\r\n if(y+d==0) return false\r\n if((Math.abs(y+d))%z == 0) return true;\r\n else return false;\r\n }\r\n function ase(x,y,z) {\r\n var d = y-x;\r\n if(x-d==0) return false\r\n if((Math.abs(x-d))%z == 0) return true;\r\n else return false;\r\n }\r\n function ad(x,y,z) {\r\n var d = (y-x)/2;\r\n if(x+d==0) return false;\r\n if((Math.abs(x+d))%z == 0) return true;\r\n else return false;\r\n }\r\n //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))\r\n var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])\r\n console.log(c ? 'YES' : 'NO')\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let a = readline().split(\" \").map(w => parseInt(w))\r\n function as(x,y,z) {\r\n var d = y-x;\r\n if(y+d==0) return false\r\n if((y+d)%z == 0) return true;\r\n else return false;\r\n }\r\n function ase(x,y,z) {\r\n var d = y-x;\r\n if(x-d==0) return false\r\n if((x-d)%z == 0) return true;\r\n else return false;\r\n }\r\n function ad(x,y,z) {\r\n var d = (y-x)/2;\r\n if(x+d==0) return false;\r\n if((x+d)%z == 0) return true;\r\n else return false;\r\n }\r\n //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))\r\n var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])\r\n console.log(c ? 'YES' : 'NO')\r\n}"}, {"source_code": "let data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n\r\n input = input.map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n );\r\n\r\n let difference = 0;\r\n\r\n input.forEach((el) => {\r\n const m1 = (2 * el[1] - el[2]) / el[0];\r\n const m2 = (el[2] + el[0]) / (2 * el[1]);\r\n const m3 = (2 * el[1] - el[0]) / el[3];\r\n\r\n if (m1 > 0 && Math.ceil(m1) == m1) {\r\n console.log(\"YES\");\r\n return 0;\r\n }\r\n\r\n if (m2 > 0 && Math.ceil(m2) == m2) {\r\n console.log(\"YES\");\r\n return 0;\r\n }\r\n\r\n if (m3 > 0 && Math.ceil(m3) == m3) {\r\n console.log(\"YES\");\r\n return 0;\r\n }\r\n console.log(\"NO\");\r\n });\r\n});\r\n"}, {"source_code": "let data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n\r\n input = input.map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n .sort((a, b) => a - b)\r\n );\r\n\r\n let difference = 0;\r\n\r\n input.forEach((el) => {\r\n difference = el[2] - el[1];\r\n\r\n difference % el[0] === 0 && difference * 2 !== el[0] + el[1]\r\n ? console.log(\"YES\")\r\n : console.log(\"NO\");\r\n });\r\n});\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, c] = rna();\r\n\r\n\t\tconst m1 = (2*b-c) != 0 && (2*b-c)%a == 0;\r\n\t\tconst m2 = (2*b-a) != 0 && (2*b-a)%c == 0;\r\n\t\tconst m3 = (a+c) != 0 && (a+c) % (2*b) == 0;\r\n\r\n\t\tconst ans = m1 || m2 || m3;\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, c] = rna();\r\n\r\n\t\tconst m1 = (2*b-c)/a;\r\n\t\tconst m2 = (2*b-a)/c;\r\n\t\tconst m3 = (a+c)/(2*b);\r\n\r\n\t\tconst ans = m1 && m1%1 == 0 || m2 && m2%1 == 0 || m3 && m3%1 == 0;\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let testCase = 1; testCase < input.length; testCase++) {\r\n let numbers = input[testCase].split(\" \");\r\n let a = +numbers[0];\r\n let b = +numbers[1];\r\n let c = +numbers[2];\r\n\r\n let newA = b - (c - b);\r\n if (newA >= a && newA % a === 0 && newA !== 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n let newB = a + (c - a) / 2;\r\n if (newB >= b && newB % b === 0 && newB !== 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n let newC = b + 2 * (b - a);\r\n if (newC >= c && newC % c === 0 && newC !== 0) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n console.log(\"NO\");\r\n }\r\n};\r\n"}], "src_uid": "90c5058c0c7f55a567f2e036482149f9"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tconst a = rna();\r\n\r\n\tfunction check (m) {\r\n\t\tconst b = []; b[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tb[i] = a[i] >= m ? 1 : -1;\r\n\t\t\tb[i] += b[i-1];\r\n\t\t}\r\n\r\n\t\tlet mn = 0;\r\n\t\tfor (let i = k - 1; i < n; i++) {\r\n\t\t\tmn = Math.min(mn, b[i-k]);\r\n\t\t\tif (b[i] > mn) return true;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tlet l = 1, r = n;\r\n\twhile (l <= r) {\r\n\t\tconst mid = l + r >> 1;\r\n\t\tif (check(mid)) {\r\n\t\t\tans = mid;\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid - 1;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "const rl = require(\"readline\").createInterface({\n\tinput: process.stdin\n});\nconst it = rl[Symbol.asyncIterator]();\nconst readln = async () => (await it.next()).value;\nconst writeln = (value) => process.stdout.write(`${value}\\n`);\nconst run = async (proc) => { await proc(); rl.close(); };\n\nrun(async () => \n{\t\n\tconst [n,k] = (await readln()).split(\" \").map((e) => parseInt(e));\t\n\tconst a = new Int32Array(n+1);\n\tconst b = new Int32Array(n+1);\n\t(await readln()).split(\" \").forEach((e,i) => a[i+1] = parseInt(e));\n\tlet l = 0;\n\tlet h = n+1;\n\twhile(h-l>=2)\n\t{\t\t\n\t\tlet m = Math.floor((l+h)/2);\n\t\tfor(let i=1;i<=n;i++)\n\t\t{\n\t\t\tb[i] = b[i-1];\n\t\t\tif (a[i]=0;i--)\n\t\t{\n\t\t\tfound = found || (((i+k)<=n) && (b[i] stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tconst a = rna();\r\n\r\n\tconst as = a.slice();\r\n\tas.sort((x, y) => x - y);\r\n\r\n\tfunction check (m) {\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tb[i] = a[i] >= m ? 1 : -1;\r\n\t\t}\r\n\r\n\t\tconst psum = [], pmnsum = []; psum[-1] = 0, pmnsum[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tpsum[i] = psum[i-1] + b[i];\r\n\t\t\tpmnsum[i] = Math.min(pmnsum[i-1], psum[i]);\r\n\t\t}\r\n\r\n\t\t//if (m == 47) console.log({m, b, psum, pmnsum});\r\n\r\n\t\tfor (let i = k-1; i < n; i++) {\r\n\t\t\tif (psum[i] - pmnsum[i-k] > 0) return true;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tlet l = 0, r = n-1;\r\n\twhile (l <= r) {\r\n\t\tconst mid = l + r >> 1;\r\n\t\tif (check(as[mid])) {\r\n\t\t\tans = as[mid];\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid - 1;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tconst a = rna();\r\n\tconst ar = a.slice().reverse();\r\n\r\n\tconst as = a.slice();\r\n\tas.sort((x, y) => x - y);\r\n\r\n\tfunction check (m, a) {\r\n\t\tconst req = Math.ceil((k+1)/2);\r\n\t\t//console.log({m, req})\r\n\t\tlet lc = 0, rc = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] >= m) {\r\n\t\t\t\trc++;\r\n\t\t\t\tif (rc == Math.max(lc+1, req)) return 1;\r\n\t\t\t} else {\r\n\t\t\t\tif (rc) {\r\n\t\t\t\t\tlc++;\r\n\t\t\t\t\tif (lc - rc >= req) lc = rc = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t//console.log({m, req, i, lc, rc}, a[i])\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tlet l = 0, r = n-1;\r\n\twhile (l <= r) {\r\n\t\tconst mid = l + r >> 1;\r\n\t\tcur = check(as[mid], a) || check(as[mid], ar);\r\n\t\t//console.log({cur});\r\n\t\tif (cur) {\r\n\t\t\tans = as[mid];\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid - 1;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tconst a = rna();\r\n\r\n\tconst as = a.slice();\r\n\tas.sort((x, y) => x - y);\r\n\r\n\tfunction check (m) {\r\n\t\tconst req = Math.ceil((k+1)/2);\r\n\t\t//console.log({m, req})\r\n\t\tlet lc = 0, rc = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] >= m) {\r\n\t\t\t\trc++;\r\n\t\t\t\tif (rc == Math.max(lc+1, req)) return 1;\r\n\t\t\t} else {\r\n\t\t\t\tif (rc) {\r\n\t\t\t\t\tlc++;\r\n\t\t\t\t\tif (lc - rc > req) lc = rc = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t//console.log({m, req, i, lc, rc}, a[i])\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tlet l = 0, r = n-1;\r\n\twhile (l <= r) {\r\n\t\tconst mid = l + r >> 1;\r\n\t\tcur = check(as[mid]);\r\n\t\t//console.log({cur});\r\n\t\tif (cur) {\r\n\t\t\tans = as[mid];\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid - 1;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tconst a = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tfunction check (m) {\r\n\t\tconst req = Math.ceil((k+1)/2);\r\n\t\tlet lc = 0, rc = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] >= m) {\r\n\t\t\t\trc++;\r\n\t\t\t\tif (rc == req) return 1;\r\n\t\t\t} else {\r\n\t\t\t\tif (rc) {\r\n\t\t\t\t\tlc++;\r\n\t\t\t\t\tif (lc - rc > req) lc = rc = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tlet l = 0, r = n-1;\r\n\twhile (l <= r) {\r\n\t\tconst mid = l + r >> 1;\r\n\t\tif (check(a[mid])) {\r\n\t\t\tans = a[mid];\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid - 1;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}], "src_uid": "dddeb7663c948515def967374f2b8812"} {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nvar ARR = [];\r\nfor (var i = 0; i < 101; i++) {\r\n ARR.push(i);\r\n}\r\nvar ans = ARR.join(' ');\r\n\r\nfunction solve() {\r\n read();\r\n var hasLessZero = false;\r\n var arr = readArray((x) => {\r\n if (Number(x) < 0) {\r\n hasLessZero = true;\r\n }\r\n });\r\n if (hasLessZero) {\r\n write('no');\r\n return;\r\n }\r\n write('yes');\r\n write(101);\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "(function () {\n var defines = {};\n var entry = [null];\n function define(name, dependencies, factory) {\n defines[name] = { dependencies: dependencies, factory: factory };\n entry[0] = name;\n }\n define(\"require\", [\"exports\"], function (exports) {\n Object.defineProperty(exports, \"__cjsModule\", { value: true });\n Object.defineProperty(exports, \"default\", { value: function (name) { return resolve(name); } });\n });\n var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n };\n var __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n };\n define(\"utils/readline\", [\"require\", \"exports\"], function (require, exports) {\n \"use strict\";\n exports.__esModule = true;\n exports.getLineReader = exports.getAllLines = void 0;\n function getAllLines() {\n return new Promise(function (res) {\n var inputText = \"\";\n process.stdin.on(\"data\", function (data) { return (inputText += data); });\n process.stdin.on(\"end\", function () {\n var EOL = require(\"os\").EOL;\n res(inputText.split(EOL));\n });\n });\n }\n exports.getAllLines = getAllLines;\n function getLineReader() {\n return __awaiter(this, void 0, void 0, function () {\n var lines, lineNumber;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, getAllLines()];\n case 1:\n lines = _a.sent();\n lineNumber = 0;\n return [2 /*return*/, {\n nextLine: function () {\n var _a;\n return (_a = lines[lineNumber++]) !== null && _a !== void 0 ? _a : \"\";\n }\n }];\n }\n });\n });\n }\n exports.getLineReader = getLineReader;\n });\n define(\"1536/index\", [\"require\", \"exports\", \"utils/readline\"], function (require, exports, readline_1) {\n \"use strict\";\n exports.__esModule = true;\n (function () { return __awaiter(void 0, void 0, void 0, function () {\n var lr, testCases, N, line, arr, result, i;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, readline_1.getLineReader()];\n case 1:\n lr = _a.sent();\n testCases = parseInt(lr.nextLine(), 10);\n while (testCases--) {\n N = parseInt(lr.nextLine(), 10);\n line = lr.nextLine();\n arr = line\n .trim()\n .split(\" \")\n .map(function (v) { return parseInt(v, 10); });\n if (arr.some(function (v) { return v < 0; })) {\n console.log(\"NO\");\n }\n else {\n result = [];\n for (i = 0; i <= 100; i++) {\n result.push(i);\n }\n console.log(\"YES\");\n console.log(101);\n console.log.apply(console, result);\n }\n }\n return [2 /*return*/];\n }\n });\n }); })();\n });\n \n 'marker:resolver';\n\n function get_define(name) {\n if (defines[name]) {\n return defines[name];\n }\n else if (defines[name + '/index']) {\n return defines[name + '/index'];\n }\n else {\n var dependencies = ['exports'];\n var factory = function (exports) {\n try {\n Object.defineProperty(exports, \"__cjsModule\", { value: true });\n Object.defineProperty(exports, \"default\", { value: require(name) });\n }\n catch (_a) {\n throw Error(['module \"', name, '\" not found.'].join(''));\n }\n };\n return { dependencies: dependencies, factory: factory };\n }\n }\n var instances = {};\n function resolve(name) {\n if (instances[name]) {\n return instances[name];\n }\n if (name === 'exports') {\n return {};\n }\n var define = get_define(name);\n instances[name] = {};\n var dependencies = define.dependencies.map(function (name) { return resolve(name); });\n define.factory.apply(define, dependencies);\n var exports = dependencies[define.dependencies.indexOf('exports')];\n instances[name] = (exports['__cjsModule']) ? exports[\"default\"] : exports;\n return instances[name];\n }\n if (entry[0] !== null) {\n return resolve(entry[0]);\n }\n})();"}, {"source_code": "(()=>{\"use strict\";var e={59:function(e,n,t){var r=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function u(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,u)}l((r=r.apply(e,n||[])).next())}))},o=this&&this.__generator||function(e,n){var t,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},\"function\"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError(\"Generator is already executing.\");for(;a;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{e.exports=require(\"os\")}},n={};!function t(r){var o=n[r];if(void 0!==o)return o.exports;var i=n[r]={exports:{}};return e[r].call(i.exports,i,i.exports,t),i.exports}(59)})();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tif(!isOK){\r\n\t\t\tmyout(\"No\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tfor(var i = 0; i < max; i++){\r\n\t\t\tif(list.indexOf(i) == -1){\r\n\t\t\t\tlist.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tmyout(\"Yes\");\r\n\t\tmyout(list.length);\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "// https://codeforces.com/contest/1536/problem/D\n// import { readline, print } from \"@ip-algorithmics/codeforces-io\";\nvar testCases = parseInt(readline(), 10);\nwhile (testCases--) {\n var N = parseInt(readline(), 10);\n var line = readline();\n var arr = line\n .trim()\n .split(\" \")\n .map((v) => parseInt(v, 10));\n if (arr.some((v) => v < 0)) {\n print(\"NO\");\n } else {\n var result = [];\n for (var i = 0; i <= 100; i++) {\n result.push(i);\n }\n print(\"YES\");\n print(101);\n print(...result);\n }\n}\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n \r\n for (var i = 0; i < testCasesNum; i++) {\r\n var n = +readline();\r\n var nums = readNumArray();\r\n var max = 0;\r\n var isNegative = false;\r\n for (var j = 0; j < n; j++) {\r\n if (nums[j] < 0) {\r\n isNegative = true;\r\n break;\r\n }\r\n if (nums[j] > max) {\r\n max = nums[j];\r\n }\r\n }\r\n if (isNegative) {\r\n print('No');\r\n } else {\r\n print('Yes');\r\n print(String(max + 1));\r\n var result = '0';\r\n for (var j = 1; j < max + 1; j++) {\r\n result = result + ' ' + String(j);\r\n }\r\n print(result);\r\n }\r\n }\r\n}\r\n\r\nmain();"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var e={59:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},\"function\"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError(\"Generator is already executing.\");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{e.exports=require(\"readline\")}},t={};!function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(59)})();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tif(!isOK){\r\n\t\t\tmyout(\"No\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar min = 100000;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tmin = Math.min(min, list[i + 1] - list[i]);\r\n\t\t}\r\n\t\tfor(var i = 1; list.length < 300; i++){\r\n\t\t\tif(i * min == max){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif(list.indexOf(i * min) == -1){\r\n\t\t\t\tlist.push(i * min);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(\"Yes\");\r\n\t\tmyout(list.length);\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tif(!isOK){\r\n\t\t\tmyout(\"No\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar min = 100000;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tmin = Math.min(min, list[i + 1] - list[i]);\r\n\t\t}\r\n\t\tfor(var i = 1; list.length < 300; i++){\r\n\t\t\tif(i * min == max){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif(list.indexOf(i * min) == -1){\r\n\t\t\t\tlist.push(i * min);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(list.length);\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(!isOK){\r\n\t\t\tmyout(\"No\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar min = 100000;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tmin = Math.min(min, list[i + 1] - list[i]);\r\n\t\t}\r\n\t\tfor(var i = 1; list.length < 300; i++){\r\n\t\t\tif(list.indexOf(i * min) == -1){\r\n\t\t\t\tlist.push(i * min);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(list.length);\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nvar ARR = [];\r\nfor (var i = 0; i < 101; i++) {\r\n ARR.push(i);\r\n}\r\nvar ans = ARR.join(' ');\r\n\r\nfunction solve() {\r\n read();\r\n var hasLessZero = false;\r\n var arr = readArray((x) => {\r\n if (Number(x) < 0) {\r\n hasLessZero = true;\r\n }\r\n });\r\n if (hasLessZero) {\r\n write('no');\r\n return;\r\n }\r\n write('yes');\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "5698e6fd934b9f6b847d7e30a3d06f2b"} {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet curLine = 0;\nlet allLines = [];\n\nreadline.on(\"line\", line => {\n allLines.push(line);\n});\n\nreadline.on(\"close\", () => { main() });\n\nlet nextLine = () => allLines[curLine++];\n\nconst K = 20;\n\nfunction main() {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n let ara = nextLine().split(\" \").map(value => Number(value));\n\n let sufMax = [...ara], sufMin = [...ara];\n\n for(let i = n-2; i >= 0; i--) sufMax[i] = Math.max(sufMax[i], sufMax[i+1]);\n for(let i = n-2; i >= 0; i--) sufMin[i] = Math.min(sufMin[i], sufMin[i+1]);\n\n let sp = [];\n for(let j = 0; j < K; j++) sp.push([]);\n\n ara.forEach((element, index) => { sp[0][index] = element; });\n\n for(let j = 1; j < K; j++) {\n for(let i = 0; i < n; i++) {\n sp[j][i] = sp[j-1][i];\n if(i+(1<<(j-1)) < n) sp[j][i] = Math.min(sp[j][i], sp[j-1][i+(1<<(j-1))]);\n }\n }\n\n let query = (i, j) => {\n let k = Math.floor(Math.log2(j-i+1));\n return Math.min(sp[k][i], sp[k][j-(1<>1;\n\n if(sufMax[mid] > mx) st = mid;\n else ed = mid;\n }\n\n if(ed == n) continue;\n if(query(i+1, ed-1) != mx && ed < n-1) ed++;\n\n let rmx = sufMax[ed], mn = query(i+1, ed-1);\n\n if(mn == mx && mn == rmx) {\n flag = true;\n\n console.log(\"YES\");\n console.log(`${i+1} ${ed-i-1} ${n-ed}`);\n \n break;\n }\n }\n\n if(!flag) console.log(\"NO\");\n }\n}", "positive_code": [{"source_code": "\"use strict\";\n\nconst K = 20;\n\n(function () {\n\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let curLine = 0, allLines = [];\n\n let nextLine = () => {\n if(curLine == allLines.length) throw new ReferenceError(\"No more input in the buffer\");\n return allLines[curLine++]\n };\n \n readline.on(\"line\", line => { allLines.push(line); });\n readline.on(\"close\", () => { main(nextLine) });\n\n})();\n\nfunction main(nextLine) {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n let ara = nextLine().split(\" \").map(value => Number(value));\n\n let sufMax = [...ara];\n for(let i = n-2; i >= 0; i--) sufMax[i] = Math.max(sufMax[i], sufMax[i+1]);\n\n let sp = [];\n for(let j = 0; j < K; j++) sp.push([]);\n\n sp[0] = ara.map(value => value);\n\n for(let j = 1; j < K; j++) {\n for(let i = 0; i < n; i++) {\n sp[j][i] = sp[j-1][i];\n if(i+(1<<(j-1)) < n) sp[j][i] = Math.min(sp[j][i], sp[j-1][i+(1<<(j-1))]);\n }\n }\n\n let query = (i, j) => {\n let k = Math.floor(Math.log2(j-i+1));\n return Math.min(sp[k][i], sp[k][j-(1<>1;\n\n if(sufMax[mid] > mx) st = mid;\n else ed = mid;\n }\n\n if(ed == n) continue;\n if(query(i+1, ed-1) != mx && ed < n-1) ed++;\n\n let rmx = sufMax[ed], mn = query(i+1, ed-1);\n\n if(mn == mx && mn == rmx) {\n flag = true;\n\n console.log(\"YES\");\n console.log(`${i+1} ${ed-i-1} ${n-ed}`);\n \n break;\n }\n }\n\n if(!flag) console.log(\"NO\");\n }\n}"}], "negative_code": [], "src_uid": "de7f5da2ded3fe0785bfa7237bac114e"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n //let mod = 10**9+7\r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\" \").map(x=>parseInt(x));\r\n \r\n let countzeros=0\r\n let countones=0\r\n let indicefirstzero=-1\r\n let indicelastone=-1\r\n let score = 0\r\n for(let i =0; i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline()-0;\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar pref1 = [];\r\n\tvar suf0 = [];\r\n\tvar ans1 = [];\r\n\tvar ans0 = [];\r\n\tfor(var i=0;i=0;i--) {\r\n\t\tsuf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);\r\n\t\tif(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];\r\n\t\telse ans0[i] = (ans0[i+1]||0)\r\n\t}\r\n\tvar ans = ans1[n-1];\r\n\tfor(var i=0;i= 0; i--){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tR[i + 1]++;\r\n\t\t\t}\r\n\t\t\tR[i] += R[i + 1];\r\n\t\t}\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tsum += L[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tvar output = sum;\r\n\t\tfor(var i = 1; i <= N; i++){\r\n\t\t\tif(list[i - 1] == 1){\r\n\t\t\t\toutput = Math.max(output, sum + L[i - 1] - R[i + 1]);\r\n\t\t\t}else{\r\n\t\t\t\toutput = Math.max(output, sum - L[i - 1] + R[i + 1]);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let a = 0, b = 0, c = cal(n, arr)\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n const temp = arr.slice()\n temp[i] = 1\n a = cal(n, temp)\n break\n }\n }\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i] === 1) {\n const temp = arr.slice()\n temp[i] = 0\n b = cal(n, temp)\n break\n }\n }\n return Math.max(a, b, c)\n}\nfunction cal(n, arr) {\n let zero = 0\n let r = 0\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i]) {\n r += zero\n } else {\n zero++\n }\n }\n return r\n}\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nfunction calc(a) {\r\n let b=new Array(a.length);\r\n let sum=0;\r\n for(let i=0;i=0;i--) b[i]+=b[i+1];\r\n // console.log(b);\r\n for(let i=0;i{return parseInt(x)});\r\n // console.log(a);\r\n let ans=calc(a);\r\n for(let i=0;i=0;i--)\r\n {\r\n if(a[i]===1)\r\n {\r\n a[i]=0;\r\n ans=Math.max(ans,calc(a));\r\n a[i]=1;\r\n break;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main() {\r\n let T = parseInt(readline());\r\n while (T--) {\r\n let n = parseInt(readline());\r\n let ary = readline().trim().split(' ').map(s => parseInt(s));\r\n let t0 = ary.filter(x => x == 0).length;\r\n let cnt = [0, 0];\r\n let tot = 0;\r\n let mx0 = 0, mx1 = 0;\r\n for(let x of ary) {\r\n let y = t0 - cnt[0];\r\n if (x == 0) {\r\n tot += cnt[1];\r\n mx1 = Math.max(mx1, y - 1 - cnt[1]);\r\n } else {\r\n mx0 = Math.max(mx0, cnt[1] - y);\r\n }\r\n cnt[x]++;\r\n }\r\n // console.log(tot, mx0, mx1, cnt);\r\n console.log(tot + Math.max(mx0, mx1));\r\n }\r\n}"}], "negative_code": [{"source_code": " const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n function alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n }\r\n function Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n }\r\n function max(x,y) {\r\n return x >=y ? x : y;\r\n }\r\n function min(x,y) {\r\n return x <=y ? x : y;\r\n }\r\n function abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n }\r\n var T = readline();\r\n var inf = 1000000000000;\r\n for(var tc=1;tc<=T;tc++) {\r\n \tvar n = readline();\r\n \tvar a = readline().split(\" \").map(w => parseInt(w));\r\n \tvar pref1 = [];\r\n \tvar suf0 = [];\r\n \tvar ans1 = [];\r\n \tvar ans0 = [];\r\n \tfor(var i=0;i=0;i--) {\r\n \t\tsuf0[i] = (suf0[i+1]||0) + (a[i]==0?1:0);\r\n \t\tif(a[i]==1) ans0[i] = (ans0[i+1]||0) + suf0[i];\r\n \t\telse ans0[i] = (ans0[i+1]||0)\r\n \t}\r\n \tvar ans = max(ans0[0], ans1[n-1]);\r\n \tans = max(0, ans);\r\n \tfor(var i=0;i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline()-0;\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar pref1 = [];\r\n\tvar suf0 = [];\r\n\tvar ans1 = [];\r\n\tvar ans0 = [];\r\n\tfor(var i=0;i=0;i--) {\r\n\t\tsuf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);\r\n\t\tif(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];\r\n\t\telse ans0[i] = (ans0[i+1]||0)\r\n\t}\r\n\tvar ans = max(ans0[0], ans1[n-1]);\r\n\tans = max(0, ans);\r\n\tfor(var i=0;i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline()-0;\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar pref1 = [];\r\n\tvar suf0 = [];\r\n\tvar ans1 = [];\r\n\tvar ans0 = [];\r\n\tfor(var i=0;i=0;i--) {\r\n\t\tsuf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);\r\n\t\tif(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];\r\n\t\telse ans0[i] = (ans0[i+1]||0)\r\n\t}\r\n\tvar ans = ans1[n-1];\r\n\tfor(var i=0;i= 0; i--){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tsum[i]++;\r\n\t\t\t}\r\n\t\t\tsum[i] += sum[i + 1];\r\n\t\t}\r\n\t\t//myerr({list,sum});\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 1){\r\n\t\t\t\toutput += sum[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar L = list.indexOf(1);\r\n\t\tif(L == -1){\r\n\t\t\tlist[0] = 1;\r\n\t\t}else{\r\n\t\t\tfor(var i = 0; i < L; i++){\r\n\t\t\t\tlist[i] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar R = list.lastIndexOf(0);\r\n\t\tif(R != -1){\r\n\t\t\tfor(var i = R; i < N; i++){\r\n\t\t\t\tlist[i] = 0;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tlist[N - 1] = 0;\r\n\t\t}\r\n\t\t\r\n\t\tvar sum = new Array(N + 1).fill(0);\r\n\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tsum[i]++;\r\n\t\t\t}\r\n\t\t\tsum[i] += sum[i + 1];\r\n\t\t}\r\n\t\t//myerr({list,sum});\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 1){\r\n\t\t\t\toutput += sum[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n //let mod = 10**9+7\r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\" \").map(x=>parseInt(x));\r\n \r\n let countzeros=0\r\n let countones=0\r\n let indicefirstzero=-1\r\n let indicelastone=-1\r\n let score = 0\r\n for(let i =0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let a = 0, b = 0, c = cal(n, arr)\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n const temp = arr.slice()\n temp[i] = 1\n a = cal(n, temp)\n break\n }\n }\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i] === 1) {\n const temp = arr.slice()\n temp[i] = 0\n b = cal(n, temp)\n break\n }\n }\n return Math.max(a, b)\n}\nfunction cal(n, arr) {\n let zero = 0\n let r = 0\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i]) {\n r += zero\n } else {\n zero++\n }\n }\n return r\n}\n"}], "src_uid": "0657ce4ce00addefc8469381c57294fc"} {"source_code": "print(function(a, s) {\n\n\tconst L = 40000;\n\n\tvar i, j, sum, ans = 0,\n\t\tl = s.length,\n\t\tq = new Int32Array(L);\n\n\tfor (i = 0; i < l; i++)\n\t\tfor (j = i, sum = 0; j < l; j++)\n\t\t\tq[sum += s[j]]++;\n\n\tfor (i = 1; i < L; i++)\n\t\tif (a % i === 0 && a / i < L)\n\t\t\tans += q[i] * q[a / i];\n\n\tif (a === 0)\n\t\tans += ans + q[0] * q[0];\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));", "positive_code": [{"source_code": "print(function(a, s) {\n\tvar i, l = s.length,\n\t\tp = new Int32Array(l),\n\t\tsum = 0;\n\n\tfor (i = 0; i < l; i++)\n\t\tp[i] = (sum += s[i]);\n\n\tp[-1] = 0;\n\n\n\tvar q = new Int32Array(1e6);\n\n\tfor (i = -1; i < l; i++)\n\t\tfor (j = i + 1; j < l; j++)\n\t\t\tq[p[j] - p[i]]++;\n\n\tvar ans = 0;\n\tif (a === 0) {\n\t\tans += q[0] * q[0];\n\t\tfor (i = 1; i < 1e6; i++) {\n\t\t\tif (q[i] > 0)\n\t\t\t\tans += q[i] * q[0] * 2;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tfor (i = 0; i < 1e6; i++)\n\t\tif (q[i] > 0 && a % i === 0 && a / i < 1e6)\n\t\t\tans += q[i] * q[a / i];\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));"}, {"source_code": "print(function(a, s) {\n\n\tconst L = 40000;\n\n\tvar i, j, ans = 0,\n\t\tl = s.length,\n\t\tp = new Int32Array(L),\n\t\tq = new Int32Array(L);\n\n\tfor (i = 0; i < l; i++)\n\t\tp[i + 1] = p[i] + s[i];\n\n\tfor (i = 0; i <= l; i++)\n\t\tfor (j = 0; j < i; j++)\n\t\t\tq[p[i] - p[j]]++;\n\n\tfor (i = 1; i < L; i++)\n\t\tif (a % i === 0 && a / i < L)\n\t\t\tans += q[i] * q[a / i];\n\n\tif (a === 0)\n\t\tans += ans + q[0] * q[0];\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));"}, {"source_code": "print(function(a, s) {\n\n\tconst L = 81 * 4000 + 3;\n\n\tvar i, j, ans = 0,\n\t\tl = s.length,\n\t\tp = new Int32Array(l),\n\t\tq = new Int32Array(L),\n\t\tsum = 0;\n\n\tfor (i = 0; i < l; i++)\n\t\tp[i] = (sum += s[i]);\n\n\tp[-1] = 0;\n\n\tfor (i = -1; i < l; i++)\n\t\tfor (j = i + 1; j < l; j++)\n\t\t\tq[p[j] - p[i]]++;\n\n\n\tfor (i = 1; i < L; i++)\n\t\tif (a % i === 0 && a / i < L)\n\t\t\tans += q[i] * q[a / i];\n\n\tif (a === 0)\n\t\tans += ans + q[0] * q[0];\n\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));"}, {"source_code": "print(function(a, s) {\n\tconst L = 81 * 4000 + 3;\n\n\tvar i, j, ans = 0,\n\t\tl = s.length,\n\t\tp = new Int32Array(l),\n\t\tq = new Int32Array(L),\n\t\tsum = 0;\n\n\tfor (i = 0; i < l; i++)\n\t\tp[i] = (sum += s[i]);\n\n\tp[-1] = 0;\n\n\tfor (i = -1; i < l; i++)\n\t\tfor (j = i + 1; j < l; j++)\n\t\t\tq[p[j] - p[i]]++;\n\n\tfor (i = 0; i < L; i++)\n\t\tif (a % i === 0 && a / i < L)\n\t\t\tans += q[i] * q[a / i];\n\t\n\tif (a === 0) {\n\t\tans += ans + q[0]*q[0];\n\t}\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));"}], "negative_code": [{"source_code": "print(function(a, s) {\n\tvar i, l = s.length,\n\t\tp = new Int32Array(l),\n\t\tsum = 0;\n\n\tfor (i = 0; i < l; i++) {\n\t\tp[i] = (sum += s[i]);\n\t}\n\tp[-1] = 0;\n\n\n\tvar q = new Int32Array(1e6);\n\n\tfor (i = -1; i < l; i++) {\n\t\tfor (j = i + 1; j < l; j++) {\n\t\t\tq[p[j] - p[i]]++;\n\t\t}\n\t}\n\n\tvar ans = 0;\n\tfor (i = 0; i < 1e6; i++) {\n\t\tif (q[i] > 0 && a % i === 0 && a / i < 1e6) {\n\t\t\tans += q[i] * q[a / i];\n\t\t}\n\t}\n\n\treturn ans;\n\n}(+readline(), readline().split('').map(Number)));\n"}, {"source_code": "print(function(a, s) {\n\tvar i, l = s.length,\n\t\tp = new Int32Array(l),\n\t\tsum = 0;\n\n\tfor (i = 0; i < l; i++)\n\t\tp[i] = (sum += s[i]);\n\n\tp[-1] = 0;\n\n\n\tvar q = new Int32Array(1e6);\n\n\tfor (i = -1; i < l; i++)\n\t\tfor (j = i + 1; j < l; j++)\n\t\t\tq[p[j] - p[i]]++;\n\n\tvar r=[];\n\tfor(i=0;i<1e6;i++)\n\t\tif(q[i]>0)\n\t\t\tr.push(i);\n\n\tvar ans=0;\n\tfor(i=0;i +v.trim());\nvar a = [];\nvar k = 0;\nfor (i = 0; i < n; i++) {\n if (k < a.length) {\n a[k] = arr[i];\n ++k;\n } else {\n a.push(arr[i]);\n ++k;\n }\n while (k > 1) {\n if (a[k - 1] == a[k - 2]) {\n ++a[k - 2];\n --k;\n } else {\n break;\n }\n }\n}\nprint(k)\nfor (i = 0; i < k; ++i) {\n print(a[i])\n}", "positive_code": [{"source_code": "var n = readline();\nvar a = readline().split(\" \");\nfor(var i = 0; i < n; i = i + 1){\n a[i] = parseInt(a[i]);\n}\nvar stack = [];\n\nfor(var i = 0; i < n; i = i + 1){\n\tstack.push(a[i]);\n\t//print(stack)\n\twhile(stack.length >= 2 && stack[stack.length - 1] === stack[stack.length - 2]){\n\t\tvar x = stack[stack.length - 1];\n\t\t//print(x)\n\t\tstack.pop();\n\t\tstack.pop();\n\t\tstack.push(x + 1);\n\t}\n}\nprint(stack.length)\nfor(var i = 0; i < stack.length; i = i + 1){\n\tprint(stack[i]);\n}\n"}, {"source_code": "n = Number(readline())\nvar a = readline().split(' ').map(function(x){return Number(x)});\nvar b = []\nk = -1;\nfor (i = 0; i < n; i++) {\n k += 1\n b[k] = a[i];\n while (k >= 1 && b[k] == b[k - 1]) {\n k -= 1\n b[k] = b[k + 1] + 1\n }\n}\ns = \"\"\nfor (i = 0; i <= k; i++) {\n s += b[i] + ' '\n}\nprint(k + 1)\nprint(s)"}, {"source_code": "\n\n\nreadline()\nvar list = readline().split(' ').map(function(string) {\n return {\n value: Number(string),\n previous: null,\n next: null\n }\n})\n\nfor (var i = 0; i < list.length; ++i) {\n if (i > 0) {\n list[i].previous = list[i - 1]\n }\n if (i < list.length - 1) {\n list[i].next = list[i + 1]\n }\n}\n\nfunction d(x) {\n arr = []\n do {\n arr.push(x.value)\n x = x.next\n } while(x !== null)\n print(arr.length)\n print(arr.join(' '))\n}\n\nvar node = list[0]\nvar didGoIn;\nwhile (node.next !== null) {\n // d(node)\n didGoIn = false\n if (node.value === node.next.value) {\n node.value += 1\n node.next = node.next.next\n if (node.next !== null) {\n node.next.previous = node\n }\n if (node.previous !== null) {\n node = node.previous\n }\n didGoIn = true\n }\n if (!didGoIn && node.next !== null) {\n node = node.next\n }\n}\n\nwhile(node.previous !== null) {\n node = node.previous\n}\n\nd(node)\n"}, {"source_code": "stack = []\nvar n = +readline()\nvar a = readline().split(' ').map(function(v){return +v;});\n\nfor (var i = 0; i < n; ++i) {\n stack.push(a[i])\n while (stack.length >= 2) {\n var sz = stack.length\n if (stack[sz-1] == stack[sz-2]) {\n stack.pop()\n stack.push(stack.pop() + 1)\n } else {\n break\n }\n }\n}\nprint(stack.length)\nprint(stack.join(\" \"))"}, {"source_code": "var arr = readline().split(\" \").map(v => +v.trim());\nvar n = arr[0];\nvar l = readline().split(\" \").map(v => +v.trim());\n\nque = []\nque.push(l[0]);\nfor (i=1; i 0)\n {\n last = que.pop();\n if(last == ne)\n {\n ne = last + 1;\n ok = 1;\n }\n else\n {\n que.push(last);\n }\n }\n }\n que.push(ne);\n}\nprint(que.length);\ns = \"\"\nfor(i=0; i= 2 && stack[stack.length - 1] === stack[stack.length - 2]){\n\t\tvar x = stack[stack.length - 1];\n\t\t//print(x)\n\t\tstack.pop();\n\t\tstack.pop();\n\t\tstack.push(x + 1);\n\t}\n}\n\nfor(var i = 0; i < stack.length; i = i + 1){\n\tprint(stack[i]);\n}\n"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \").map(v => +v.trim());\nvar a = [];\nvar k = 0;\nfor (i = 0; i < n; i++) {\n if (k < a.length) {\n a[k] = arr[i];\n ++k;\n } else {\n a.push(arr[i]);\n ++k;\n }\n while (k > 1) {\n if (a[k - 1] == a[k - 2]) {\n ++a[k - 2];\n --k;\n } else {\n break;\n }\n }\n}\nfor (i = 0; i < k; ++i) {\n print(a[i])\n}"}, {"source_code": "readline()\nvar list = readline().split(' ').map(function(string) {\n return {\n value: Number(string),\n previous: null,\n next: null\n }\n})\n\nfor (var i = 0; i < list.length; ++i) {\n if (i > 0) {\n list[i].previous = list[i - 1]\n }\n if (i < list.length - 1) {\n list[i].next = list[i + 1]\n }\n}\n\nfunction d(x) {\n arr = []\n do {\n arr.push(x.value)\n x = x.next\n } while(x !== null)\n print(arr.length)\n print(arr.join(' '))\n}\n\nvar node = list[0]\nvar didGoBack;\nwhile (node.next !== null) {\n // d(node)\n didGoBack = false\n if (node.value === node.next.value) {\n node.value += 1\n node.next = node.next.next\n if (node.next !== null) {\n node.next.previous = node\n }\n if (node.previous !== null) {\n node = node.previous\n didGoBack = true\n }\n }\n if (!didGoBack && node.next !== null) {\n node = node.next\n }\n}\n\nwhile(node.previous !== null) {\n node = node.previous\n}\n\nd(node)\n"}], "src_uid": "8c715616c8fa373c95368cf4795a2e6a"} {"source_code": "\"use strict\"; \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n} \r\n\r\nfunction main() {\r\n var t = +(readline());\r\n while (t--) {\r\n solution();\r\n } \r\n}\r\n \r\nfunction solution() {\r\n const n = +(readline());\r\n const str = readline();\r\n \r\n let ans = 0;\r\n for (let i = 0; i < n-1; i++) {\r\n let s = (str[i] === '0') ? 0 : +str[i]+1;\r\n ans+=s; \r\n }\r\n ans += +str[n-1];\r\n console.log(ans);\r\n}\r\n \r\nfunction isPrime(num) {\r\n if (num === 2) return true;\r\n if (num === 1 || num%2 === 0 ) return false;\r\n \r\n let root = Math.floor(Math.sqrt(num));\r\n root += (root%2)-1;\r\n while (root > 1) {\r\n if (num%root === 0)\r\n return false;\r\n root -= 2;\r\n }\r\n return true;\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var s = lines[i].split('').map(Number);\n var ans = s[n - 1];\n for(j = 0; j < n - 1; j++){\n if(s[j] !== 0){\n ans += (s[j]) + 1;\n }\n }\n console.log(ans);\n }\n\t}\n});\n\n"}, {"source_code": "//https://codeforces.com/problemset/problem/1573/A?locale=en\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message) {\n if (process.env.NODE_ENV === \"debug\") {\n console.log(message);\n }\n}\n\nfunction calculateStepsNeededFor0(digits) {\n const digitProcessor = (accumulator, currentValue, currentIndex) => {\n const costOfMoving = 1;\n const isLastDigit = currentIndex === digits.length-1;\n\n if(isLastDigit){\n return accumulator + currentValue;\n }else{\n if(currentValue === 0){\n return accumulator\n }else{\n return accumulator + currentValue + costOfMoving;\n }\n }\n }\n\n const allNumbersSummarised = String(digits)\n .split(\"\")\n .map(x => Number(x))\n .reduce(digitProcessor, 0);\n\n return allNumbersSummarised;\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n const header = fileContents.splice(0, 1);\n const tasksWithoutLength = fileContents.filter((elem, id) => id % 2 !== 0)\n\n const clockTransformationSteps = tasksWithoutLength\n .map(calculateStepsNeededFor0);\n\n //PrintOutput\n clockTransformationSteps.forEach((x) => console.log(x))\n}\n\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet s = nl.line();\n\t\tlet r = 0;\n\t\tfor(let j = n - 1; j >= 0; j--){\n\t\t\tlet x = Number(s.charAt(j));\n\t\t\tif (x > 0) {\n\t\t\t\tr += x;\n\t\t\t\tif (j < n-1) {\n\t\t\t\t\tr++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans.push(r);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tvar v = myconv(s[i], 1);\r\n\t\t\tif(v > 0){\r\n\t\t\t\tif(i < N - 1){\r\n\t\t\t\t\toutput += v + 1;\r\n\t\t\t\t}else{\r\n\t\t\t\t\toutput += v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "const readline = require('readline')\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input)\r\n})\r\nrl.on('close', () => {\r\n let l = 0\r\n let t = lines[l++]\r\n for (let i = 0; i < t; i++) {\r\n const n = lines[l++]\r\n const str = lines[l++].trim().split('').reverse()\r\n console.log(solve(str))\r\n }\r\n})\r\n \r\nfunction solve(str) {\r\n let count=0\r\n for(let j=0;j {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift()(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift())\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let iii = 0; iii < t; ++iii) {\r\n let n = +await nextString()\r\n let mas = (await nextString()).split('').map(char => +char)\r\n let ans = 0\r\n ans += mas[mas.length - 1]\r\n mas[mas.length - 1] = 0\r\n while (true) {\r\n let p = 0\r\n while (p < mas.length && mas[p] === 0) {\r\n ++p\r\n }\r\n if (p === mas.length) {\r\n break\r\n }\r\n let temp = mas[p]\r\n mas[p] = mas[n - 1]\r\n mas[n - 1] = temp\r\n ans += mas[n - 1]\r\n mas[n - 1] = 0\r\n ++ans\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "function main() {\r\n var no_of_inputs = readline()\r\n for(var i=0;i {\r\n lines.push(input)\r\n})\r\nrl.on('close', () => {\r\n let l = 0\r\n let t = lines[l++]\r\n for (let i = 0; i < t; i++) {\r\n const n = lines[l++]\r\n const str = lines[l++].trim().split('')\r\n console.log(solve(str))\r\n }\r\n})\r\n// var n = readLine();\r\n// var in1 = readLine();\r\n// console.log(solve(in1,parseInt(n)));"}], "negative_code": [{"source_code": "const readline = require('readline')\r\nfunction solve(s1)\r\n{\r\n n = s1.length;\r\n let res = 0;\r\n for(let i=0;i {\r\n lines.push(input)\r\n})\r\nrl.on('close', () => {\r\n let l = 0\r\n let t = lines[l++]\r\n for (let i = 0; i < t; i++) {\r\n const n = lines[l++]\r\n const str = lines[l++].trim().split('').reverse()\r\n console.log(solve(str))\r\n }\r\n})\r\n// var n = readLine();\r\n// var in1 = readLine();\r\n// console.log(solve(in1,parseInt(n)));"}, {"source_code": "const readline = require('readline')\r\nfunction solve(s1)\r\n{\r\n n = s1.length;\r\n let res = 0;\r\n for(let i=0;i {\r\n lines.push(input)\r\n})\r\nrl.on('close', () => {\r\n let l = 0\r\n let t = lines[l++]\r\n for (let i = 0; i < t; i++) {\r\n const n = lines[l++]\r\n const str = lines[l++].trim().split('').reverse()\r\n console.log(solve(str))\r\n }\r\n})\r\n// var n = readLine();\r\n// var in1 = readLine();\r\n// console.log(solve(in1,parseInt(n)));"}, {"source_code": "const readline = require('readline')\r\nfunction solve(s1)\r\n{\r\n let res = 0;\r\n for(let i=0;i {\r\n lines.push(input)\r\n})\r\nrl.on('close', () => {\r\n let l = 0\r\n let t = lines[l++]\r\n for (let i = 0; i < t; i++) {\r\n const n = lines[l++]\r\n const str = lines[l++].trim().split('').reverse()\r\n console.log(solve(str))\r\n }\r\n})\r\n// var n = readLine();\r\n// var in1 = readLine();\r\n// console.log(solve(in1,parseInt(n)));"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var k = lines[j].split(' ').map(Number);\n k = k.sort(function(a, b){return a - b});\n var a = [];\n for(var l = 1; l <= k.length; l++){\n if(k[l] != k[l - 1]){\n a.push(k[l - 1]);\n }\n }\n if(a.length == 1){\n console.log(e);\n }else{\n console.log(1);\n }\n }else{\n e = lines[j];\n }\n }\n});"}, {"source_code": "///https://codeforces.com/problemset/problem/1452/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction main(fileContents) {//input lines as an array\n const amoutOfInputsForTheProgram = fileContents.splice(0,1);\n const listOfEndpointsForRobot = [...fileContents];\n\n listOfEndpointsForRobot\n .map((endpoints)=>endpoints.split(\" \"))\n .map((endpoints)=>{\n const diffBetweetVertAndHorizontal = Math.abs(parseInt(endpoints[0])-parseInt(endpoints[1]));\n return parseInt(endpoints[0])+parseInt(endpoints[1])\n +(diffBetweetVertAndHorizontal > 0 ? (diffBetweetVertAndHorizontal-1) : 0)\n })\n .forEach(x=>console.log(x));\n\n}\n\n"}], "src_uid": "6571fdd506a858d7620c2faa0fe46cc1"} {"source_code": "const\n verticesCount = readline();\nvar\n vertices = [],\n isChristmassTree = true;\n vertices.push(0),\n levels = {},\n roots = [];\nfor (var i = 1; i < verticesCount; i++) {\n vertices.push(readline());\n}\n\nvertices.forEach((vert, i) => {\n if (!levels.hasOwnProperty(vert)) {\n levels[vert] = [];\n }\n levels[vert].push(i+1);\n \n})\n\nfunction checkLength(object) {\n for (var key in object) {\n if (key > 0) {\n if (object[key].length < 3) {\n isChristmassTree = false;\n break;\n }\n roots.push(key);\n }\n }\n}\n\nfunction checkRoots(roots) {\n roots.forEach(root => {\n for (var key in levels) {\n if (key > 0) {\n if (levels[key].includes(Number(root))) {\n levels[key].splice(levels[key].indexOf(Number(root)), 1)\n } \n }\n }\n })\n}\n\ncheckLength(levels)\nif (isChristmassTree) {\ncheckRoots(roots)\ncheckLength(levels)\n}\n\nprint(isChristmassTree ? 'Yes' : 'No')\n\n", "positive_code": [{"source_code": "var n = +readline(); \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = [n];\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\n function findRes(data) {\nfor (var i = 0; i < n; i++) {\nverwuna = data[i];\nif (!verwuna.esListom && verwuna.listkov < 3) {\nreturn 'No';\n} \n}\nreturn 'Yes';\n}\n\nfor (var i = 1; i < n; i++) {\n roditelInex = +readline() - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));"}, {"source_code": "var n=Number(readline())\nvar N=new Array(n+1)\nN[1]={c:[]}\nfor (var i=0;i{\n var l=N[i].c.length;\n if (l) {\n var cc=0; \n for (var j=0;j=3;\n } else return true;\n}\n\nvar a=true;\nfor (var i=1;i<=n;++i)\n a = a && check(i)\nprint(a?'Yes':'No')\n"}, {"source_code": "function isSpruce(tree) {\n for (var i = 0; i < tree.length; i++) {\n var leaf_children = 0;\n for (var j = 1 + i; j < tree.length; j++) if (tree[j][\"parent\"] === i && tree[j][\"isLeaf\"]) leaf_children += 1;\n if (leaf_children < 3 && !tree[i].isLeaf) return \"No\";\n }\n return \"Yes\";\n}\n\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, leaf_children: 0, parent: null};\n\nfor (var i = 1; i < tree.length; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, leaf_children: 0, parent: parent_index};\n tree[parent_index][\"isLeaf\"] = false;\n tree[parent_index][\"leaf_children\"] += 1;\n}\n\nprint(isSpruce(tree));"}, {"source_code": "function isElka(tree) {\n for (var i = 0; i < tree.length; i++) {\n var children = 0;\n for (var j = 1 + i; j < tree.length; j++) if (tree[j][\"parent\"] === i && tree[j][\"isLeaf\"]) children += 1;\n if (children < 3 && !tree[i].isLeaf) return \"No\";\n }\n return \"Yes\";\n}\n\nvar res = \"Yes\";\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, leaf_children: 0, parent: null};\n\nfor (var i = 1; i < tree.length; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, leaf_children: 0, parent: parent_index};\n tree[parent_index][\"isLeaf\"] = false;\n tree[parent_index][\"leaf_children\"] += 1;\n}\n\nprint(isElka(tree));"}, {"source_code": "var nodesAmount = readline();\nvar nodes = new Array(parseInt(nodesAmount) - 1);\nvar tree = new Array(parseInt(nodesAmount));\n\nfor (var i = 0; i < nodes.length; i++) {\n nodes[i] = readline() - 1;\n}\n\nfor (var i = 0; i < tree.length; i++) {\n tree[i] = [];\n}\n\nnodes.forEach(function(node, i) {\n tree[node].push(i + 1);\n});\nvar result = 'Yes';\ntestLevel(tree[0]);\nprint(result);\n\nfunction testLevel(nodes) {\n var leaves = 0;\n nodes.forEach(function(node) {\n if (!tree[node][0]) leaves++;\n });\n if (leaves < 3) {\n result = 'No';\n } else {\n nodes.forEach(function(node) {\n if (tree[node][0]) {\n return testLevel(tree[node]);\n }\n });\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let len = +readLine();\n len = len - 1;\n let index = 2;\n const data = new Map();\n while (len--) {\n const n = +readLine();\n data.set(n, (data.get(n) || new Set()).add(index));\n index++;\n }\n\n for (let [key1, value1] of data) {\n for (let [key, value] of data) {\n if (value.has(key1)) value.delete(key1);\n }\n }\n\n for (let [key, value] of data) {\n if (value.size < 3) {\n console.log(`No`);\n return;\n }\n }\n console.log(`Yes`);\n}\n"}, {"source_code": "'use strict';\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, \n leafs: 0, \n parent: null};\n\nfor (var i = 1; i < tree.length; i++) {\n var parentIndex = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, \n leafs: 0, \n parent: parentIndex};\n tree[parentIndex][\"isLeaf\"] = false;\n tree[parentIndex][\"leafs\"] += 1;\n}\n\nfunction isChristmasTree(tree) {\n for (var i = 0; i < tree.length; i++) {\n var leafs = 0;\n for (var j = 1 + i; j < tree.length; j++) {\n if (tree[j][\"parent\"] === i && tree[j][\"isLeaf\"]) \n leafs += 1;\n }\n if (leafs < 3 && !tree[i].isLeaf) \n return \"No\";\n }\n return \"Yes\";\n}\n\nprint(isChristmasTree(tree));"}, {"source_code": "function isLeaf(node) {\n return Object.keys(node.children).length === 0;\n}\n\n// input\nvar n = parseInt(readline());\n\nvar nodes = new Array(n);\nnodes[0] = {\n isLeaf: true,\n leaves: 0,\n parent: null\n};\n\nfor (var i = 1; i < n; i++) {\n var parentIndex = parseInt(readline()) - 1;\n if (!nodes[i]) {\n // init current node\n nodes[i] = {\n isLeaf: true,\n leaves: 0,\n parent: parentIndex\n };\n }\n\n var currentNode = nodes[i];\n\n if (!nodes[parentIndex]) {\n // init parent node\n nodes[parentIndex] = {\n isLeaf: false,\n leaves: currentNode.isLeaf ? 1 : 0,\n parent: null\n };\n } else {\n // update parent node\n var parentNode = nodes[parentIndex];\n if (parentNode.isLeaf) {\n parentNode.isLeaf = false;\n var parentParentNode = nodes[parentNode.parent];\n if (parentParentNode) {\n parentParentNode.leaves = Math.max(0, parentParentNode.leaves - 1);\n }\n }\n\n if (currentNode.isLeaf) {\n parentNode.leaves++;\n }\n }\n}\n\nfunction isSpruce(tree) {\n for (var i = 0; i < n; i++) {\n var node = tree[i];\n if (!node.isLeaf && node.leaves < 3) {\n return 'No';\n }\n }\n return 'Yes';\n}\n\nprint(isSpruce(nodes));"}, {"source_code": "var n = parseInt(readline());; \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = new Array(n);\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\nfunction esListom(verwuna) {\n return Object.keys(verwuna.children).length === 0;\n}\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\n function findRes(data) {\nfor (var i = 0; i < n; i++) {\nverwuna = data[i];\nif (!verwuna.esListom && verwuna.listkov < 3) {\nreturn 'No';\n} \n}\nreturn 'Yes';\n}\n\nfor (var i = 1; i < n; i++) {\n roditelInex = parseInt(readline()) - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));\n"}, {"source_code": "var n = parseInt(readline());; \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = [n];\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\n//function esListom(verwuna) {\n // return Object.keys(verwuna.children).length === 0;\n//}\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\n function findRes(data) {\nfor (var i = 0; i < n; i++) {\nverwuna = data[i];\nif (!verwuna.esListom && verwuna.listkov < 3) {\nreturn 'No';\n} \n}\nreturn 'Yes';\n}\n\nfor (var i = 1; i < n; i++) {\n roditelInex = parseInt(readline()) - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));"}, {"source_code": "var n = parseInt(readline());; \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = new Array(n);\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\nfunction esListom(verwuna) {\n return Object.keys(verwuna.children).length === 0;\n}\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\nfor (var i = 1; i < n; i++) {\n roditelInex = parseInt(readline()) - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nfunction findRes(data) {\n for (var i = 0; i < n; i++) {\n verwuna = data[i];\n if (!verwuna.esListom && verwuna.listkov < 3) {\n return 'No';\n } \n }\n return 'Yes';\n}\n\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));\n"}, {"source_code": "var n = parseInt(readline());; \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = [n];\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\n function findRes(data) {\nfor (var i = 0; i < n; i++) {\nverwuna = data[i];\nif (!verwuna.esListom && verwuna.listkov < 3) {\nreturn 'No';\n} \n}\nreturn 'Yes';\n}\n\nfor (var i = 1; i < n; i++) {\n roditelInex = parseInt(readline()) - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));"}, {"source_code": "var n = parseInt(readline());; \n//+prompt(\"Enter kol verwun\");\nvar koli4estvoVerwun = [n];\n\nvar roditelInex = 0;\nvar dannajaVetka;\nvar roditelVetka;\nvar mainVerwuna;\nvar verwuna;\n\nfunction esListom(verwuna) {\n return Object.keys(verwuna.children).length === 0;\n}\nkoli4estvoVerwun[0] = {\n roditel: null,\n listkov: 0,\n esListom: true\n }\n\n function findRes(data) {\nfor (var i = 0; i < n; i++) {\nverwuna = data[i];\nif (!verwuna.esListom && verwuna.listkov < 3) {\nreturn 'No';\n} \n}\nreturn 'Yes';\n}\n\nfor (var i = 1; i < n; i++) {\n roditelInex = parseInt(readline()) - 1;\n //+prompt(\"data\") - 1;\n if (!koli4estvoVerwun[i]) {\n koli4estvoVerwun[i] = {\n roditel: roditelInex,\n listkov: 0,\n esListom: true \n };\n }\n\ndannajaVetka = koli4estvoVerwun[i];\n\nif (!koli4estvoVerwun[roditelInex]) {\n koli4estvoVerwun[roditelInex] = {\n roditel: null,\n listkov: dannajaVetka.esListom ? 1 : 0,\n esListom: false\n };\n} else {\n\nroditelVetka = koli4estvoVerwun[roditelInex];\nif (roditelVetka.esListom) {\n roditelVetka.esListom = false;\n\n mainVerwuna = koli4estvoVerwun[roditelVetka.roditel];\n if (mainVerwuna) {\n mainVerwuna.listkov = Math.max(0 , mainVerwuna.listkov -1);\n }\n}\nif (dannajaVetka.esListom) {\n roditelVetka.listkov++;\n}\n}\n}\nprint(findRes(koli4estvoVerwun));\n//alert(findRes(koli4estvoVerwun));"}], "negative_code": [{"source_code": " 'use strict';\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, \n leafChildren: 0, \n leafParent: null};\nvar parentIndex = 0;\nfor (var i = 1; i < tree.length; i++) {\n parentIndex = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, \n leafChildren: 0, \n parent: parentIndex};\n tree[parentIndex][\"isLeaf\"] = false;\n tree[parentIndex][\"leafChildren\"] += 1;\n}\n\nfunction isNewYearTree(tree) {\n var leafChildren = 0;\n for (var i = 0; i < tree.length; i++) {\n for (var j = i+1; j < tree.length; j++) \n if (tree[j][\"parent\"] === i && tree[j][\"isLeaf\"]) \n leafChildren += 1;\n if (leafChildren < 3 && !tree[i].isLeaf) \n return \"No\";\n }\n return \"Yes\";\n}\n\nprint(isNewYearTree(tree));"}, {"source_code": "'use strict';\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, \n leafChildren: 0, \n parent: null};\nvar parentIndex = 0;\nfor (var i = 1; i < tree.length; i++) {\n parentIndex = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, \n leafChildren: 0, \n parent: parentIndex};\n tree[parentIndex][\"isLeaf\"] = false;\n tree[parentIndex][\"leafChildren\"] += 1;\n}\n\nfunction isNewYearTree(tree) {\n var leafChildren = 0;\n for (var i = 0; i < tree.length; i++) {\n for (var j = i+1; j < tree.length; j++) \n if (tree[j][\"isLeaf\"] && tree[j][\"parent\"] === i) {\n leafChildren += 1;\n }\n if (!tree[i].isLeaf && leafChildren < 3) return \"No\";\n }\n return \"Yes\";\n}\n\nprint(isNewYearTree(tree));"}, {"source_code": "var number = parseInt(readline());\nvar tree = new Array(number);\n\n\ntree[0] = { isLeaf: true, children: 0, parent: null};\n\nfor (var i = 1; i < number; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, children: 0, parent: parent_index};\n tree[parent_index][\"children\"] += 1;\n tree[parent_index][\"isLeaf\"] = false;\n}\n\nvar res = \"Yes\";\nfor (var i = 0; i < tree.length; i++) {\n if (!tree[i].isLeaf && tree[i][\"children\"] < 3){\n res = \"No\";\n }\n}\n\nprint(res);"}, {"source_code": "var number = parseInt(readline());\nvar tree = new Array(number);\n\nfunction reduceLeafChildNumber(tree, parent_index) {\n if (tree[parent_index][\"parent\"] !== null) {\n tree[tree[parent_index][\"parent\"]][\"leaf_children\"] -= 1;\n return reduceLeafChildNumber(tree, tree[parent_index][\"parent\"]);\n } else {\n return tree;\n }\n}\ntree[0] = { isLeaf: true, leaf_children: 0, parent: null};\n\nfor (var i = 1; i < number; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, children: 0, parent: parent_index};\n tree[parent_index][\"leaf_children\"] += 1;\n tree[parent_index][\"isLeaf\"] = false;\n \n tree = reduceLeafChildNumber(tree, parent_index);\n}\n\nvar res = \"Yes\";\nfor (var i = 0; i < tree.length; i++) {\n if (!tree[i].isLeaf && tree[i][\"leaf_children\"] < 3){\n res = \"No\";\n }\n}\n\nprint(res);"}, {"source_code": "function reduceLeafChildNumber(tree, parent_index) {\n if (tree[parent_index][\"parent\"] !== null) {\n tree[tree[parent_index][\"parent\"]][\"leaf_children\"] -= 1;\n return reduceLeafChildNumber(tree, tree[parent_index][\"parent\"]);\n }\n return tree;\n}\n\nvar res = \"Yes\";\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, leaf_children: 0, parent: null};\n\nfor (var i = 1; i < tree.length; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, leaf_children: 0, parent: parent_index};\n tree[parent_index][\"isLeaf\"] = false;\n \n if (tree[parent_index][\"leaf_children\"] === 0) tree = reduceLeafChildNumber(tree, parent_index);\n tree[parent_index][\"leaf_children\"] += 1;\n}\n\nfor (var i = 0; i < tree.length; i++)\n if (!tree[i].isLeaf && tree[i][\"leaf_children\"] < 3) res = \"No\";\n\nprint(res);"}, {"source_code": "function reduceLeafChildNumber(tree, parent_index) {\n if (tree[parent_index][\"parent\"] !== null) {\n tree[tree[parent_index][\"parent\"]][\"leaf_children\"] -= 1;\n return reduceLeafChildNumber(tree, tree[parent_index][\"parent\"]);\n }\n return tree;\n}\n\nvar res = \"Yes\";\nvar tree = new Array(parseInt(readline()));\ntree[0] = { isLeaf: true, leaf_children: 0, parent: null};\n\nfor (var i = 1; i < tree.length; i++) {\n parent_index = parseInt(readline()) - 1;\n tree[i] = { isLeaf: true, leaf_children: 0, parent: parent_index};\n tree[parent_index][\"leaf_children\"] += 1;\n tree[parent_index][\"isLeaf\"] = false;\n \n tree = reduceLeafChildNumber(tree, parent_index);\n}\n\nfor (var i = 0; i < tree.length; i++) {\n if (!tree[i].isLeaf && tree[i][\"leaf_children\"] < 3){\n res = \"No\";\n }\n}\n\nprint(res);"}, {"source_code": "var nodesAmount = readline();\nvar nodes = new Array(parseInt(nodesAmount) - 1);\nvar tree = new Array(parseInt(nodesAmount));\n\nfor (var i = 0; i < nodes.length; i++) {\n nodes[i] = readline() - 1;\n}\n\nfor (var i = 0; i < tree.length; i++) {\n tree[i] = [];\n}\n\nnodes.forEach(function(node, i) {\n tree[node].push(i + 1);\n});\n\nprint(testLevel(tree[0]));\n\nfunction testLevel(nodes) {\n\n if (!nodes[0]) {\n return true;\n }\n\n var leaves = 0;\n\n nodes.forEach(function(node) {\n if (!tree[node][0]) {\n leaves++;\n }\n });\n\n if (leaves < 3) {\n return 'No';\n }\n\n nodes.forEach(function(node) {\n testLevel(tree[node]);\n });\n\n return 'Yes'\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let len = +readLine();\n len = len - 1;\n const data = [];\n while (len--) {\n const n = +readLine();\n data.push(n);\n }\n data.sort((a, b) => a - b);\n let [prev, prevCount] = [null, 0];\n\n for (let i = 0; i < data.length; i++) {\n const current = data[i];\n if (prev === current) {\n prevCount++;\n } else {\n if (prev !== null) {\n prevCount = prevCount - 1;\n if (prevCount < 3) {\n console.log(`No`);\n return;\n }\n }\n prev = current;\n prevCount = 1;\n }\n }\n console.log(`Yes`);\n}\n"}], "src_uid": "69edc72ec29d4dd56751b281085c3591"} {"source_code": "\"use strict\";\n\nfunction cmp (a, b) {\n if (a < b)\n return -1;\n if (a === b)\n return 0;\n return 1;\n}\n\nfunction solve(n, k, ts) {\n var negative = [];\n for (var i = 0; i < ts.length; i++)\n if (ts[i] < 0)\n negative.push(i);\n if (negative.length > k)\n return -1;\n if (negative.length === 0)\n return 0;\n k -= negative.length;\n var diffs = [];\n for (i = 1; i < negative.length; i++)\n if (negative[i] !== negative[i - 1] + 1)\n diffs.push(negative[i] - negative[i - 1] - 1);\n diffs.sort(cmp);\n i = 0;\n var segms = diffs.length + 1;\n while (i < diffs.length && diffs[i] <= k) {\n k -= diffs[i];\n i++;\n segms--;\n }\n var res = 2 * segms;\n if (k >= n - negative[negative.length - 1] - 1)\n res--;\n return res; \n}\n\nvar line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar k = parseInt(line[1]);\nvar ts = readline().split(' ').map(function(s) { return parseInt(s); });\nprint(solve(n, k, ts));\n", "positive_code": [{"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 8\n0 0 -1 0 0 -1 -1 -1 0 0 -1 0 -1 0 -1 -1 -1 0 0 0 -1\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, gapsConsumed, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentTire === 'winter') {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n if (winterRanges.length === 0) {\n print('0');\n } else {\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort(function(a, b) {\n return a - b;\n });\n gapsConsumed = 0;\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n gapsConsumed += 1;\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n print(totalChanges);\n }\n }\n\n}).call(this);\n"}], "negative_code": [{"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 3\n-5 20 -3 0\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentRange.length > 0) {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort();\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n print(totalChanges);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 8\n0 0 -1 0 0 -1 -1 -1 0 0\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentRange.length > 0) {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort();\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n if (totalChanges > 12000) {\n print('WINTER RANGES:', winterRanges.length);\n print('TOTAL USED TIME:', totalUsedTime);\n print('SOME GAPS:', gaps.slice(0, 10));\n print('FINAL GAP', finalGap);\n }\n print(totalChanges);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 8\n0 0 -1 0 0 -1 -1 -1 0 0 -1 0 -1 0 -1 -1 -1 0 0 0 -1\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, gapsConsumed, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentTire === 'winter') {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort();\n gapsConsumed = 0;\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n gapsConsumed += 1;\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n if (totalChanges > 12000) {\n print('WINTER RANGES:', winterRanges.length);\n print('TOTAL USED TIME:', totalUsedTime);\n print('TOTAL NUMBER OF GAPS', gaps.length);\n print('GAPS CONSUMED:', gapsConsumed);\n print('FINAL GAP', gaps[gapsConsumed - 1], gaps[gapsConsumed], gaps[gapsConsumed + 1]);\n print('NUMBER OF 1-GAPS', gaps.filter(function(x) {\n return x === 1;\n }).length);\n print('SOME GAPS:', gaps.slice(0, 10));\n print('FINAL GAP', finalGap);\n }\n print(totalChanges);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 3\n-5 20 -3 0\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentRange.length > 0) {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n gaps = [];\n\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n\n gaps.sort();\n\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n\n print(totalChanges);\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n\n/*\nlines = '''\n4 8\n0 0 -1 0 0 -1 -1 -1 0 0\n'''.split '\\n'\n\nreadline = -> lines.shift()\nprint = console.log\n */\n\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, gapsConsumed, i, j, k, l, len, len1, len2, m, n, range, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentRange.length > 0) {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort();\n gapsConsumed = 0;\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n gapsConsumed += 1;\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n if (totalChanges > 12000) {\n print('WINTER RANGES:', winterRanges.length);\n print('TOTAL USED TIME:', totalUsedTime);\n print('GAPS CONSUMED:', gapsConsumed);\n print('FINAL GAP', gaps[gapsConsumed - 1], gaps[gapsConsumed], gaps[gapsConsumed + 1]);\n print('SOME GAPS:', gaps.slice(0, 10));\n print('FINAL GAP', finalGap);\n }\n print(totalChanges);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var currentRange, currentTire, finalGap, gap, gaps, i, j, k, l, len, len1, len2, lines, m, n, range, readline, ref, t, temp, totalChanges, totalUsedTime, winterRanges;\n\n lines = '4 8\\n0 0 -1 0 0 -1 -1 -1 0 0'.split('\\n');\n\n readline = function() {\n return lines.shift();\n };\n\n\n /*\n print = console.log\n */\n\n ref = readline().split(' ').map(Number), n = ref[0], k = ref[1];\n\n temp = readline().split(' ').map(Number);\n\n winterRanges = [];\n\n currentTire = 'summer';\n\n currentRange = [];\n\n for (i = j = 0, len = temp.length; j < len; i = ++j) {\n t = temp[i];\n if (t < 0 && currentTire === 'summer') {\n currentRange.push(i);\n currentTire = 'winter';\n } else if (t >= 0 && currentTire === 'winter') {\n currentRange.push(i);\n winterRanges.push(currentRange);\n currentRange = [];\n currentTire = 'summer';\n }\n }\n\n if (currentRange.length > 0) {\n currentRange.push(temp.length);\n winterRanges.push(currentRange);\n }\n\n totalChanges = winterRanges.length * 2;\n\n totalUsedTime = winterRanges.map(function(x) {\n return x[1] - x[0];\n }).reduce(function(a, b) {\n return a + b;\n });\n\n if (totalUsedTime > k) {\n print('-1');\n } else {\n gaps = [];\n for (i = l = 0, len1 = winterRanges.length; l < len1; i = ++l) {\n range = winterRanges[i];\n if (i > 0) {\n gaps.push(range[0] - winterRanges[i - 1][1]);\n }\n }\n gaps.sort();\n for (m = 0, len2 = gaps.length; m < len2; m++) {\n gap = gaps[m];\n totalUsedTime += gap;\n if (totalUsedTime <= k) {\n totalChanges -= 2;\n } else {\n totalUsedTime -= gap;\n break;\n }\n }\n finalGap = temp.length - winterRanges[winterRanges.length - 1][1];\n if (totalUsedTime + finalGap <= k) {\n totalChanges -= 1;\n }\n if (totalChanges > 12000) {\n print('WINTER RANGES:', winterRanges.length);\n print('TOTAL USED TIME:', totalUsedTime);\n print('SOME GAPS:', gaps.slice(0, 10));\n print('FINAL GAP', finalGap);\n }\n print(totalChanges);\n }\n\n}).call(this);\n"}], "src_uid": "18458f6ab66db560a51887c944f26f0f"} {"source_code": "var ints = function() {\nreturn readline().split(' ').map(function(n) {\nreturn parseInt(n)\n})\n}\n\nvar numbers = ints(),\nx = numbers[1],\ncounter = 0,\ntemp = 0\n\nnumbers = ints().reduce(function(result, n) {\nif (undefined == result[n])\nresult[n] = 0\nresult[n] ++\nreturn result\n}, {})\n\nfor (var n in numbers) {\nif (x == 0) {\ntemp = numbers[n]\nif (temp > 1) {\ncounter += (temp * (temp - 1)) / 2\n}\n} else {\ntemp = numbers[n ^ x]\nif (undefined != temp)\ncounter += temp * numbers[n]\nnumbers[n] = undefined\n}\n}\n\nprint(counter)", "positive_code": [{"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(n) {\n\t\treturn parseInt(n)\n\t})\n}\n\nvar numbers = ints(),\n\tx = numbers[1],\n\tcounter = 0,\n\ttemp = 0\n\nnumbers = ints().reduce(function(result, n) {\n\tif (undefined == result[n])\n\t\tresult[n] = 0\n\tresult[n] ++\n\treturn result\n}, {})\n\nfor (var n in numbers) {\n\tif (x == 0) {\n\t\ttemp = numbers[n]\n\t\tif (temp > 1) {\n\t\t\tcounter += (temp * (temp - 1)) / 2\n\t\t}\n\t} else {\n\t\ttemp = numbers[n ^ x]\n\t\tif (undefined != temp)\n\t\t\tcounter += temp * numbers[n]\n\t\tnumbers[n] = undefined\n\t}\n}\n\nprint(counter)"}, {"source_code": "if (undefined == readline) {\n\tvar fs = require('fs')\n\tvar lines = fs.readFileSync('/dev/stdin', 'utf8').split(\"\\n\").reverse();\n\tvar readline = function() {\n\t\treturn lines.pop()\n\t}\n}\n\nif (undefined == print) {\n\tvar print = console.log\n}\n\nvar ints = function() {\n\treturn readline().split(' ').map(function(n) {\n\t\treturn parseInt(n)\n\t})\n}\n\nvar numbers = ints(),\n\tx = numbers[1],\n\tcounter = 0,\n\ttemp = 0\n\nnumbers = ints().reduce(function(result, n) {\n\tif (undefined == result[n])\n\t\tresult[n] = 0\n\tresult[n] ++\n\treturn result\n}, {})\n\nfor (var n in numbers) {\n\tif (x == 0) {\n\t\ttemp = numbers[n]\n\t\tif (temp > 1) {\n\t\t\tcounter += (temp * (temp - 1)) / 2\n\t\t}\n\t} else {\n\t\ttemp = numbers[n ^ x]\n\t\tif (undefined != temp)\n\t\t\tcounter += temp * numbers[n]\n\t\tnumbers[n] = undefined\n\t}\n}\n\nprint(counter)"}, {"source_code": "function sa(f, s){\n var x = Number(f.split(\" \")[1]);\n var data = s.split(\" \").map(Number);\n var arr = [];\n for(var i=0;i<=100000;i++){\n arr[i] = 0;\n }\n var res = 0;\n for(var i=0;i 0){\n\t\t\tnotes[50]--;\n\t\t\tnotes[25]--;\n\t\t\tif(notes[25] < 0){\n\t\t\t\tif(!written){\n\t\t\t\t\tprint(\"NO\");\n\t\t\t\t\twritten = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tnotes[25] -= 3;\n\t\t\tif(notes[25] < 0){\n\t\t\t\tif(!written){\n\t\t\t\t\tprint(\"NO\");\n\t\t\t\t\twritten = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n});\n\nif(!written){\n\tprint(\"YES\");\n}", "positive_code": [{"source_code": "var m = [0,0,0];\nvar n;\nvar buff = new Array();\nfunction read() {\n\treturn readline().split(' ').map(Number);\n}\nfunction main() {\n\tn=read();\n\tbuff=read();\n\tfor (var i=0; i0) m[0]--;\n\t\t\t\telse {\n\t\t\t\t\tprint(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 100:\n\t\t\t\tm[2]++;\n\t\t\t\tif (m[1]>0 && m[0]>0) m[1]--,m[0]--;\n\t\t\t\telse if (m[0]>=3) m[0]-=3;\n\t\t\t\telse {\n\t\t\t\t\tprint(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tprint(\"YES\");\n}\nmain();"}, {"source_code": "var N = parseInt(readline());\nfunction f(){var arr = readline().split(\" \");\n\nvar clerk25 = 0, clerk50 = 0;\nfor (var i = 0; i < N; i++) \n{\n var cur = arr[i];\n if (cur == 25) clerk25++;\n else\n {\n if (cur == 50)\n {clerk50++;\n if (clerk25 > 0) clerk25--;\n else {print(\"NO\"); return false;}\n }\n if (cur == 100)\n {\n if ((clerk25 > 0 && clerk50>0))\n {\n clerk25--; clerk50--;\n }\n else if (clerk25>2) clerk25-=3;\n else {print(\"NO\"); return false;}\n }\n }\n}\nprint(\"YES\");\n\n}\n\nf();"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar c25=0; var c50 = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tc25++;\n\t\t\telse if (+str[i]==50)\n\t\t\t\tif (c25<=0) {r=0; break;}\n\t\t\t\telse {c50++; c25--;\n\t\t\t\t}\n\t\t\telse if (+str[i]==100){\n\t\t\t if (c25>0&&c50>0) {c25--;c50--;}\n\t\t\t\telse if (c25>2) c25-=3;\n\t\t\t\telse {r=0; break;}\t\t\n\t\t\t}\n\t\t}\n r==1?print(\"YES\"):print(\"NO\");"}, {"source_code": ";(function () {\n\n\tvar l25 = 0,\n\t\tl50 = 0;\n\n\tvar n = +readline();\n\tvar s = readline().split(' ');\n\n\tfor (var i = 0; i < n; i++)\n\t\tswitch (s[i]) {\n\t\t\tcase '25':\n\t\t\t\tl25++;\n\t\t\t\tbreak;\n\n\t\t\tcase '50':\n\t\t\t\tif (l25) {\n\t\t\t\t\tl25--;\n\t\t\t\t\tl50++;\n\t\t\t\t} else {\n\t\t\t\t\tprint('NO');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase '100':\n\t\t\t\tif (l50 && l25) {\n\t\t\t\t\tl25--;\n\t\t\t\t\tl50--;\n\t\t\t\t} else if (l25 > 2) {\n\t\t\t\t\tl25 -= 3;\n\t\t\t\t} else {\n\t\t\t\t\tprint('NO');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\tprint('YES');\n\n}).call(this)"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tbills = tokenizeIntegers(readline()),\n\t\tcash = { 25: 0, 50: 0, 100: 0 };\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar bill = bills[i];\n\t\tif (bill == 25) {\n\t\t\tcash[25] += 1;\n\t\t} else if (bill == 50 && cash[25] != 0) {\n\t\t\tcash[50] += 1;\n\t\t\tcash[25] -= 1;\n\t\t} else if (bill == 100 && cash[25] != 0 && cash[50] != 0) {\n\t\t\tcash[100] += 1;\n\t\t\tcash[25] -= 1;\n\t\t\tcash[50] -= 1;\n\t\t} else if (bill == 100 && cash[25] >= 3) {\n\t\t\tcash[100] += 1;\n\t\t\tcash[25] -= 3;\n\t\t} else {\n\t\t\tprint('NO');\n\t\t\treturn;\n\t\t}\n\t}\n\tprint('YES');\n}\n\nmain();\n"}, {"source_code": "const fs = require('fs')\n\nconst readStdin = () => {\n return new Promise((resolve, reject) => {\n fs.readFile(0, (err, data) => {\n if (err) {\n reject(err)\n } else {\n resolve(data.toString())\n }\n })\n })\n}\n\nasync function main () {\n const str = await readStdin()\n const lines = str.split('\\n')\n const n = parseInt(lines[0])\n const bills = lines[1].split(' ').map(token => parseInt(token))\n\n let _25 = 0\n let _50 = 0\n let could = true\n\n bills.forEach((bill) => {\n if (bill === 25) {\n _25++\n } else if (bill === 50) {\n _50++\n if (_25 === 0) {\n could = false\n } else {\n _25--\n }\n } else {\n if (_50 > 0) {\n _50--\n if (_25 === 0) {\n could = false\n } else {\n _25--\n }\n } else if (_25 >= 3) {\n _25 -= 3\n } else {\n could = false\n }\n }\n })\n\n if (could) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n}\n\nmain().then(() => {})\n"}, {"source_code": "\n// 349A \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043a\u0438\u043d\u043e \n\n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i= 25) {\n summa25 -= 25;\n summa50 += 50;\n break;\n } else {\n out = 'NO';\n break top;\n };\n case 100:\n x = 75;\n if (summa50 >= 50) {\n summa50 -= 50;\n x = 25;\n } \n if (summa25 >= x) {\n summa25 -= x;\n break;\n } else { \n out = 'NO';\n break top;\n };\n }\n\n};\n\nif (out === '') out = 'YES';\n\nprint(out);\n "}, {"source_code": "\nvar n=+readline();\nvar a=readline().split(' ');\n\nvar f=false;\nvar a25=0;\nvar a50=0;\nfor(var i=0;i0){\n\t\t\ta25--;\n\t\t}else{\n\t\t\tf=true;\n\t\t\tbreak;\n\t\t}\n\t}else{\n\t\tif(a50>0&&a25>0){\n\t\t\ta50--;\n\t\t\ta25--;\n\t\t}else if(a25>2){\n\t\t\ta25-=3;\n\t\t}else{\n\t\t\tf=true;\n\t\t\tbreak;\n\t\t}\n\t}\n}\nprint(f?'NO':'YES');"}, {"source_code": "var arrLen = readline().split(' ').map(Number);\nvar Arr = readline().split(' ').map(Number);\nvar arrM = [0, 0, 0];\nvar counter = 0;\nfor (var i=0; i 0) clerk25--;\n else {print(\"NO\"); return false;}\n }\n if (cur == 100)\n {\n if ((clerk25 > 0 && clerk50>0))\n {\n clerk25--; clerk50--;\n }\n else if (clerk25>2) clerk25-=3;\n else {print(\"NO\"); return false;}\n }\n }\n}\nprint(\"YES\");\n\n}\n\nf();"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass>0){\n\t\t\t\tcass -= (+str[i]-25);\n\t\t\t\tcass += +str[i];\n\t\t\t\t}\n\t\t\telse {r=0; break;}\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar c25=0; var c50 = 0;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tc25++;\n\t\t\telse if (+str[i]==50)\n\t\t\t\tif (c25<0) {print(\"NO\"); break;}\n\t\t\t\telse {c50++; c25--;\n\t\t\t\t}\n\t\t\telse if (+str[i]==100){\n\t\t\t if (c25>0&&c50>0) {c25--;c50--;}\n\t\t\t\telse if (c25>2) c25-=3;\n\t\t\t\telse {print(\"NO\"); break;}\t\t\n\t\t\t}\n\t\t}\n print(\"YES\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass-(+str[i]-25)>=0){\n\t\t\t\tcass += +str[i];\n\t\t\t\tcass -= +str[i]-25;}\n\t\t\telse {r=0; break;}\n\t\t\tif (cass<0) break;\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "\nvar n = readline();\nvar str = readline().split(\" \");\nvar r = 1;\nvar cass = 0;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\t\tif (+str[i]==25){\n\t\t\t\t\tcass+=25;\n\t\t\t\t}\n\t\t\t\telse if(+str[i]>25) cass = cass-(+str[i]-25);\n\t\t\t\telse if (cass<0) break;\n\t\t}\n\t\tr==1&&cass>=0? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse {\n\t\t\t\tcass += +str[i];\n\t\t\t\tcass -= +str[i]-25;}\n\t\t\tif (cass<0) break;\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse {\n\t\t\t\tcass -= +str[i]-25; \n\t\t\t\tif (cass<0) { r=0; break;}\n\t\t\t\tcass += +str[i];}\n\t\t\t\t\n\t\t\t\t\n\t\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if ((+str[i]-25)<=cass&&cass>0){\n\t\t\t\tcass -= (+str[i]-25);\n\t\t\t\tcass += +str[i];\n\t\t\t\t}\n\t\t\telse {r=0; break;}\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "\nvar n = readline();\nvar str = readline().split(\" \");\nvar r = 1;\nvar cass = 0;\n\tfor (var i = 0; i<+n; i++){\n\t\tif (str[i]>25&cass>0) \n\t\tcass = cass-(+str[i]-25);\n\t\telse if (+str[i]==25) cass+=25;\n\t\telse {r=0; break;}\n\t\n\t\t\n\t}\n\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (+str[i]==50){\n\t\t\t\tcass -=25;\n\t\t\t\tif (cass<0) { r=0; break;}\n\t\t\t\tcass +=50;\n\t\t\t\t}\n\t\t\telse if (+str[i]==100){\n\t\t\t\tcass -=75; \n\t\t\t if (cass<0) { r=0; break;}\t\t\n\t\t\t}\n\t\t//\tif (cass<0) { r=0; break;}\n\t\t\t\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse \n\t\t\t\tcass += cass-(+str[i]-25);\n\t\t\tif (cass<0) {r=0; break;}\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar r = 1;\nvar cass = 0;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\t\tif (+str[i]==25){\n\t\t\t\t\tcass+=25;\n\t\t\t\t}\n\t\t\t\telse cass = cass-(+str[i]-25);\n\t\t\t\n\t\t}\n\t\tr==1&&cass>=0? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if ((+str[i]-25)<=cass){\n\t\t\tcass += cass-(+str[i]-25);\n\t\t\t\t}\n\t\t\telse {r=0; break;}\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar c25=0; var c50 = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tc25++;\n\t\t\telse if (+str[i]==50)\n\t\t\t\tif (c25<0) {r=0; break;}\n\t\t\t\telse {c50++; c25--;\n\t\t\t\t}\n\t\t\telse if (+str[i]==100){\n\t\t\t if (c25>0&&c50>0) {c25--;c50--;}\n\t\t\t\telse if (c25>2) c25-=3;\n\t\t\t\telse {r=0; break;}\t\t\n\t\t\t}\n\t\t}\n r==1?print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass-(+str[i]-25)>=0&&cass>0)\n\t\t\t\tcass += cass-(+str[i]-25);\n\t\t\telse {r=0; break;}\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if ((+str[i]-25)<=cass){\n\t\t\t\t var t = (+str[i]-25);\t\t\n\t\t\t cass+= +str[i]-t;\n\t\t\t\t}\n\t\t\telse {r=0; break;}\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass>0)\n\t\t\t\tcass += cass-(+str[i]-25);\n\t\t\tif (cass<0) {r=0; break;}\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (+str[i]==50){\n\t\t\t\tcass -=25;\n\t\t\t\tif (cass<0) { r=0; break;}\n\t\t\t\tcass +=50;\n\t\t\t\t}\n\t\t\telse if (+str[i]==100){\n\t\t\t\tcass -=75; \n\t\t\t if (cass<0) { r=0; break;}\t\t\n\t\t\t\tcass += 100;\n\t\t\t}\n\t\t//\tif (cass<0) { r=0; break;}\n\t\t\t\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse {\n\t\t\t\tcass -= +str[i]-25;}\n\t\t\t\tif (cass<0) break;\n\t\t\t\tcass += +str[i];\n\t\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass+Number(str[i])-(+str[i]-25)>0&&cass>0)\n\t\t\t\tcass = cass+Number(str[i])-(+str[i]-25);\n\t\t\telse {r=0; break;}\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse if (cass-(+str[i]-25)>0&&cass>0)\n\t\t\t\tcass += cass-(+str[i]-25);\n\t\t\telse {r=0; break;}\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar cass = 0;\nvar r = 1;\n\t\tfor (var i = 0; i<+n; i++){\n\t\t\tif(+str[i]==25)\n\t\t\t\tcass+=25;\n\t\t\telse {\n\t\t\t\tcass -= +str[i]-25;}\n\t\t\t\tif (cass<0) {break; r=0;}\n\t\t\t\tcass += +str[i];\n\t\t\n\t\t}\n\t\tr==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "\n// 349A \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043a\u0438\u043d\u043e \n\n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i= 25) {\n summa25 -= 25;\n summa50 += 50;\n break;\n } else {\n out = 'NO';\n break top;\n };\n case 100:\n x = 100;\n if (summa50 >= 50) {\n summa50 -= 50;\n x = 50;\n } \n if (summa25 >= x) {\n summa25 -= x;\n break;\n } else { \n out = 'NO';\n break top;\n };\n }\n\n};\n\nif (out === '') out = 'YES';\n\nprint(out);\n "}, {"source_code": "\n// 349A \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043a\u0438\u043d\u043e \n\n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i 25) {\n summa25 -= 25;\n summa50 += 50;\n break;\n } else {\n out = 'NO';\n break top;\n };\n case 100:\n if (summa50 > 50) {\n summa50 -= 50;\n summa100 += 100;\n break;\n } else {\n if (summa25 > 50) {\n summa25 -= 50;\n summa100 += 100;\n break;\n } else { \n out = 'NO';\n break top;\n } \n };\n }\n\n};\n\nif (out === '') out = 'YES';\n\nprint(out);\n "}, {"source_code": "\n// 349A \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043a\u0438\u043d\u043e \n\n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i= 25) {\n summa25 -= 25;\n summa50 += 50;\n break;\n } else {\n out = 'NO';\n break top;\n };\n case 100:\n if (summa50 >= 50) {\n summa50 -= 50;\n summa100 += 100;\n break;\n } else {\n if (summa25 >= 50) {\n summa25 -= 50;\n summa100 += 100;\n break;\n } else { \n out = 'NO';\n break top;\n } \n };\n }\n\n};\n\nif (out === '') out = 'YES';\n\nprint(out);\n "}, {"source_code": "var arrLen = readline().split(' ').map(Number);\nvar Arr = readline().split(' ').map(Number);\nvar arrM = [0, 0, 0];\nvar counter = 0;\nfor (var i=0; i 1 ) {\n l['25']--;\n l['50']++;\n }\n else {\n print('NO');\n return;\n }\n break;\n case 100:\n if (l['50'] > 0 && l['25'] > 0) {\n l['50']--;\n l['25']--;\n } else if (l['25'] > 1) l['25'] -= 2;\n else {\n print('NO');\n return;\n }\n break;\n }\n}\n\nprint('YES');\n\n}).call(this);"}, {"source_code": ";(function () {\n\nreadline();\n\nvar m = readline().split(' ').map(Number);\n\nvar l = {\n '25' : 0,\n '50' : 0,\n '100' : 0\n}\n\nfor (var i = 0; i < m.length; i++) {\n switch (m[i]) {\n case 25:\n l['25']++;\n break;\n case 50:\n if (l['25'] > 0) {\n l['25']--;\n l['50']++;\n }\n else {\n print('NO');\n return;\n }\n break;\n case 100:\n if (l['50'] > 0 && l['25'] > 0) {\n l['50']--;\n l['25']--;\n } else if (l['25'] > 1) l['25'] -= 2;\n else {\n print('NO');\n return;\n }\n break;\n }\n}\n\nprint('YES');\n\n}).call(this);"}, {"source_code": ";(function () {\n\nreadline();\n\nvar m = readline().split(' ').map(Number);\n\nvar l = {\n '25' : 0,\n '50' : 0,\n '100' : 0\n}\n\nif (m.length == 8001) {\n print('NO');\n return;\n}\n\nfor (var i = 0; i < m.length; i++) {\n switch (m[i]) {\n case 25:\n l['25']++;\n break;\n case 50:\n if (l['25'] > 0) {\n l['25']--;\n l['50']++;\n }\n else {\n print('NO');\n return;\n }\n break;\n case 100:\n if (l['50'] > 0 && l['25'] > 0) {\n l['50']--;\n l['25']--;\n } else if (l['25'] > 1) l['25'] -= 2;\n else {\n print('NO');\n return;\n }\n break;\n }\n}\n\nprint('YES');\n\n}).call(this);"}, {"source_code": ";(function () {\n\nreadline();\n\nvar m = readline().split(' ').map(Number);\n\nvar t = 0;\n\nfor (var i = 0; i < m.length; i++)\n if (m[i] == 25) t++;\n else {\n if (m[i] == 50 && t > 0) t--;\n else if (m[i] == 100 && t > 1) t -= 2;\n else {\n print('NO');\n return;\n }\n }\n\nprint('YES');\n\n}).call(this);"}, {"source_code": "const fs = require('fs')\n\nconst readStdin = () => {\n return new Promise((resolve, reject) => {\n fs.readFile(0, (err, data) => {\n if (err) {\n reject(err)\n } else {\n resolve(data.toString())\n }\n })\n })\n}\n\nasync function main () {\n const str = await readStdin()\n const lines = str.split('\\n')\n const n = parseInt(lines[0])\n const bills = lines[1].split(' ').map(token => parseInt(token))\n\n let _25 = 0\n let _50 = 0\n let could = true\n\n bills.forEach((bill) => {\n if (bill === 25) {\n _25++\n } else if (bill === 50) {\n _50++\n if (_25 === 0) {\n could = false\n _25--\n }\n } else {\n if (_50 > 0) {\n _50--\n if (_25 === 0) {\n could = false\n _25--\n }\n } else if (_25 === 3) {\n _25 -= 3\n } else {\n could = false\n }\n }\n })\n\n if (could) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n}\n\nmain().then(() => {})\n"}, {"source_code": "const fs = require('fs')\n\nconst readStdin = () => {\n return new Promise((resolve, reject) => {\n fs.readFile(0, (err, data) => {\n if (err) {\n reject(err)\n } else {\n resolve(data.toString())\n }\n })\n })\n}\n\nasync function main () {\n const str = await readStdin()\n const lines = str.split('\\n')\n const n = parseInt(lines[0])\n const bills = lines[1].split(' ').map(token => parseInt(token))\n\n let _25 = 0\n let _50 = 0\n let could = true\n\n bills.forEach((bill) => {\n if (bill === 25) {\n _25++\n } else if (bill === 50) {\n _50++\n if (_25 === 0) {\n could = false\n } else {\n _25--\n }\n } else {\n if (_50 > 0) {\n _50--\n if (_25 === 0) {\n could = false\n _25--\n }\n } else if (_25 === 3) {\n _25 -= 3\n } else {\n could = false\n }\n }\n })\n\n if (could) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n}\n\nmain().then(() => {})\n"}], "src_uid": "63b20ab2993fddf2cc469c4c4e8027df"} {"source_code": "var result = 0;\nvar total = readline();\nfor(var i = 0; i< total; i++){\n var item = readline().split(' ');\n if(parseInt(item[1]) - parseInt(item[0]) >= 2) result ++;\n}\nprint(result);", "positive_code": [{"source_code": "var n = Number(readline());\nvar k =0;\nfor (var i = 0; i < n; ++i){\n var str = readline();\n var a = Number(str.split(\" \")[0]);\n var b = Number(str.split(\" \")[1]);\n if ((b-a) >=2 ){\n ++k;\n }\n}\nprint(k);"}, {"source_code": "var n = +readline(), input, p, q, counter = 0;\n\nfor(i = 0; i < n; i++){\n\tinput = readline().split(\" \");\n\tp = +input[0];\n\tq = +input[1];\n\n\tif( (q-p) >= 2 ){\n\t\tcounter++;\n\t}\n}\nwrite(counter);"}, {"source_code": "var n = readline()\n\nvar sum = 0\n\nfor(var i = 0; i < n ;i++) {\n var line = readline().split(' ')\n var a = parseInt(line[0])\n var b = parseInt(line[1])\n \n if(b - a - 2 >= 0) {\n sum++\n }\n}\n\nprint(sum)"}, {"source_code": "function main(){\n var n = readline();\n var res = 0;\n for(var i = 0; i < n; ++i){\n var c = readline().split(' ');;\n if(+c[1] - +c[0] >= 2) ++res;\n }\n print(res);\n}\n\nmain();"}, {"source_code": "var r=+readline();\nvar j=0;\nfor(var i=0;i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r = +readline(), p, q, d, count = 0;\nfor(i=0; i < r; i++){\n p = readline().split(\" \"); \n q = +p[1];\n d = +p[0];\n if((q-d) >= 2){\n count++;\n }\n}\nwrite(count);"}, {"source_code": "var n = readline() - 0;\n\nvar t = 0;\nfor (var i = 0; i < n; i++) {\n var IN = readNums();\n if (IN[1] - IN[0] >= 2) {\n t++;\n }\n}\nprint(t);\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}"}, {"source_code": "m=readline()\nsum=0\nfor(i=0;i= 2){\n output++;\n }\n }\n return output;\n}\n\n"}, {"source_code": "var n = readline();\nvar count = 0;\n\nfor (var i = 0; i < n; i++) {\n var str = readline().split(' ');\n if ((str[1] - str[0]) >= 2) count++;\n}\n\nprint(count);"}, {"source_code": "var n = parseInt(readline()),\n\tcounter = 0\n\nwhile (n > 0) {\n\tvar ns = readline().split(' ').map(function(i) {\n\t\treturn parseInt(i)\n\t})\n\tif (ns[1] - ns[0] > 1)\n\t\tcounter ++\n\tn --\n}\n\nprint(counter)"}, {"source_code": "var numberOfRoom = +readline();\nvar answer = 0;\nfor(var i = 1; i <= numberOfRoom; i ++) {\n var line = readline().split(' ');\n if(+line[0]+2 <= +line[1]) {\n answer++;\n }\n}\n\nprint(answer);"}, {"source_code": "var no_rooms = parseInt(readline());\nvar available = 0;\nfor(var i=0; iparseInt(x));\n var already = acc[0];\n var capacity = acc[1];\n if(capacity-already >=2){\n available++;\n }\n}\nprint(available);"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar t = 0;\n\t\twhile (n--) t += Number(readline().split(' ').map(Number).reduce(function (a, b) { return Math.abs(a - b); }) > 1);\n\t\treturn t;\n\t}(+readline()));\n}.call(this));\n"}, {"source_code": "var lines = +readline();\nvar counter = 0;\n\nfor(var i = 0; i < lines; i ++){\n\tvar pq = readline().split(' ').map(x => +x);\n\tvar p = pq[0];\n\tvar q = pq[1];\n\tif(q - p >= 2){\n\t\t// Possible to move in\n\t\tcounter ++;\n\t}\n}\n\nprint(counter);"}, {"source_code": "var strArray = [];\n\nvar numberIterations = readline();\nvar countOfLivibleFloors = 0;\n\nfor (var i = 0; i < numberIterations; i++) {\n strArray.push(readline()); \n}\n\nfor (var i = 0; i < strArray.length; i++) {\n strFloor = strArray[i].split(\" \");\n if ( (parseInt(strFloor[1]) - parseInt(strFloor[0])) >= 2) {\n countOfLivibleFloors++;\n }\n}\n\nprint(countOfLivibleFloors)"}, {"source_code": "var limit = readline();\nvar count = 0\nwhile(limit > 0){\n var line = readline().split(\" \")\n var numPeopleInRoom = parseInt(line[0]);\n var limitRoom = parseInt(line[1])\n if(numPeopleInRoom + 2 <= limitRoom) count++\n limit--\n}\n\nprint(count)"}, {"source_code": "var n = parseInt(readline());\n\nvar ans = 0;\nfor(var i=0;i=2){\n ans++;\n }\n}\n\nprint(ans);"}, {"source_code": "var n = parseInt(readline());\nvar count = 0;\nfor(var i = 0; i= 2) {\n count++;\n }\n}\nprint(count);"}, {"source_code": "var a = readline();\n\nvar rooms = [];\nvar freeRooms = 0;\n\nfunction proc(){\n var res = true;\n while(res){\n res = readline();\n if (!res) break;\n rooms.push(res);\n }\n}\n\nproc();\n\nfor (var i = 0; i < rooms.length ; i++) {\n var s = rooms[i].split(' ');\n if((Number(s[1]) - Number(s[0])) >= 2 ) {\n freeRooms++; \n }\n}\n \nprint(freeRooms);\n"}, {"source_code": "(function () {\n var n = parseInt(readline()),\n i = 0,\n sum = 0,\n line;\n for (; i < n; i++) {\n line = readline().split(\" \");\n if ((line[1] - line[0]) > 1) {\n sum++;\n }\n }\n print(sum);\n})();"}, {"source_code": "const main = () => {\n const n = readline();\n const arr = [];\n var numRooms = 0;\n\n for (i of Array(Number(n))\n .fill()\n .map((a, b) => parseInt(b))) {\n arr.push(\n readline()\n .split(\" \")\n .map((x) => parseInt(x))\n );\n }\n\n for (i of arr) {\n if (i[0] + 2 <= i[1]){\n numRooms++;\n }\n }\n print(numRooms);\n};\nmain();"}, {"source_code": "var line = readline()\n var result = 0\n\n while (line--) {\n var currentRoom = readline().split(' ')\n var currentOcupacy = parseInt(currentRoom[0], 10)\n var maxOcupacy = parseInt(currentRoom[1], 10)\n if (currentOcupacy + 2 <= maxOcupacy) result++\n }\n\n print(result)"}, {"source_code": "var line = readline()\nvar result = 0\n\nwhile (line--) {\nvar currentRoom = readline().split(' ')\nvar currentOcupacy = parseInt(currentRoom[0], 10)\nvar maxOcupacy = parseInt(currentRoom[1], 10)\nif (currentOcupacy + 2 <= maxOcupacy) result++\n}\n\nprint(result)"}, {"source_code": "var a = readline();\n\nvar rooms = [];\nvar freeRooms = 0;\n\nfunction read () {\n return readline() ;\n}\n\nfunction proc(){\n var res = true;\n while(res){\n res = read();\n if (!res) break;\n rooms.push(res);\n }\n}\n\nproc();\n\nfor (var i = 0; i < rooms.length ; i++) {\n var s = rooms[i].split(' ');\n if((Number(s[1]) - Number(s[0])) >= 2 ) {\n freeRooms++; \n }\n}\n \nprint(freeRooms);\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a ;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n a = Math.abs( this.arr[ i ] - this.brr[ i ] ) ;\n if( a >= 2 ) {\n res++ ;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var n = readline();\nvar s = [];\nfor (var i = 0; i < n; i++)\n s.push(readline().split(' '));\nvar count = 0;\nfor (var i = 0; i < n; i++)\n if ((s[i][1] - s[i][0]) >= 2)\n count++;\nprint(count);"}, {"source_code": "var n = parseInt(readline());\nvar s = [];\nfor (var i = 0; i < n; i++)\n s.push(readline().split(' '));\nvar count = 0;\nfor (var i = 0; i < n; i++)\n if ((parseInt(s[i][1]) - parseInt(s[i][0])) >= 2)\n count++;\nprint(count);"}, {"source_code": "var n = parseInt(readline());\nvar count = 0;\nfor (var i = 0; i < n; i ++){\n var string = readline().split(\" \");\n var numberOfPeople = parseInt(string[0]);\n var maxNumberOfPeople = parseInt(string[1]);\n if ((maxNumberOfPeople - numberOfPeople) >= 2){\n count++;\n }\n}\nprint(count);"}, {"source_code": "var n = parseInt(readline());\nvar freeroom = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar pq = readline().split(' ');\n\tif((parseInt(pq[0]) + 2) <= parseInt(pq[1]))\n\t\tfreeroom++;\n}\n\nprint(freeroom);"}, {"source_code": "readline();\nvar rooms = [];\nvar freeRooms = 0;\nvar res = true;\nwhile(res){\n res = readline();\n if (!res) break;\n rooms.push(res);\n}\nfor (var i = 0; i < rooms.length ; i++) {\n var s = rooms[i].split(' ');\n if((s[1] - s[0]) >= 2 ) {\n freeRooms++; \n }\n}\nprint(freeRooms);"}, {"source_code": "/* TEST CASE\ninput\n3\n1 1\n2 2\n3 3\noutput\n0\n\ninput\n3\n1 10\n0 10\n10 10\noutput\n2\n\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar answer = 0;\n\t\n\tfor (var i = 0; i < n; i++) {\n\t\tvar s = readline().split(' ');\n\t\tif (parseInt(s[1]) - parseInt(s[0]) >= 2) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = parseInt(readline());\nvar freeroom = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar pq = readline().split(' ');\n\tif((parseInt(pq[1]) - parseInt(pq[0])) >= 2)\n\t\tfreeroom++;\n}\n\nprint(freeroom);"}, {"source_code": "'use strict';\nlet n = parseInt(readline()),\n answer = 0;\n\nfor (let i = 0; i < n; i++) {\n const array = readline().split(' ').map(function(value) {\n return parseInt(value);\n });\n \n if (array[1] - array[0] >= 2) {\n answer++;\n } \n}\n\nwrite(answer);"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var line = readline()\n var lineArr = line.split(\" \")\n var p = parseInt(lineArr[0])\n var q = parseInt(lineArr[1])\n if (q - p >= 2){\n count++;\n }\n}\nprint(count)"}, {"source_code": "var n =readline();\nvar x = 0;\nvar str1 = \"\";\nvar room = [];\nfor (i=1;i<=n;i++) room.push(readline());\nfor(i=0;i=2) x++;\n}\nprint (x);"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tcount = 0;\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar p = readline().split(/\\s/gi),\n\t\t\t\tq = p[1], p = p[0];\n\n\t\t\tif(p <= q - 2)\tcount++;\n\t\t}\n\n\t\tprint(count);"}, {"source_code": "var n = parseInt(readline());\n\nvar room = 0;\nfor (var i = 0; i < n; i++) {\n var s = readline().split(' ');\n\n if (s[1] - s[0] >= 2) {\n room++;\n }\n}\n\nprint(room);"}, {"source_code": "var str = Number(readline()),\n res = 0;\n \nfor (var i = 0; i < str; i++) {\n var data = readline().split(' '),\n now = Number(data[0]),\n all = Number(data[1]);\n \n if (now + 2 <= all) res++;\n}\n\nprint(res);"}, {"source_code": "var entrada = readline();\nvar hab = 0;\n\nfor(var i = 0; i < entrada; i++){\n \n\tvar num = readline();\n\tnum = num.split(\" \");\n\tvar resta = num[1] - num[0];\n\t\n\tif( resta>=2){\n\t\thab++;\n\t}\n}\n\nprint(hab);"}, {"source_code": "function UraAndRooms(arr)\n{\n var result = 0;\n function minus(a)\n {\n return +a[1] - +a[0];\n }\n for (var i = 0; i <= arr.length - 1; i++)\n {\n var count = minus(arr[i].split(' '));\n if (count >= 2 ) result++;\n }\n return result;\n \n}\n{\n\tvar arr = [];\n var num = readline();\n\tfor (var i = 1; i <= +num; i++)\n\t{\n\t\tvar input = readline();\n\t\tarr.push(input);\n\t}\n\tprint(UraAndRooms(arr));\n\t\n}"}, {"source_code": "var r = readline();\nvar room = 0;\nfor(var i = 0; i < r; i++){\n\tvar n = readline().split(\" \");\n\tif(n[1] - n[0] >=2)\n\t\troom++;\n}\nprint(room);"}, {"source_code": "var num = readline();\nvar count = 0;\nwhile(num--){\n \n var room = readline().split(' ');\n if(room[1] - room[0] >= 2){\n count++;\n }\n}\n\nprint(count);"}, {"source_code": "var n = parseInt(readline(), 10),\n inp = '',\n room = 0;\n\nfor(var i=1; i<=n; i++) {\n inp = readline().split(' ');\n \n if(inp[1]-inp[0] >= 2) room++; \n}\n\nprint(room);"}, {"source_code": "var n = readline()\nvar bol = 0\nfor (var i = 0; i < n; i++) {\n var rez = 0\n var line = readline()\n line = line.split(\" \")\n rez = line[1] - line[0]\n if(rez >= 2){\n bol++\n }\n}\nprint(bol)"}, {"source_code": "var n = parseInt(readline());\nvar ar = [];\nvar res = 0;\n\nfor (var i = 0; i < n; i++) {\n\tar[i] = readline().split(' ').map(function(i) {\n\t\treturn parseInt(i);\n\t});\n\t\n\tif (ar[i][0] + 2 <= ar[i][1]) {\n\t\tres++;\n\t}\n}\n\nprint(res);"}, {"source_code": "var linenum = parseInt(readline());\nvar i, nums, count = 0;\nfor(i=0;i= 2){\n count ++;\n }\n}\n\nprint(count);\n"}, {"source_code": "(function () {\n var count = parseInt(readline());\n\n var result = 0;\n for (var i = 0; i < count; i++){\n var nums = readline().trim().split(' ').map(Number);\n if (nums[0] + 2 <= nums[1]){\n result++;\n }\n }\n\n print(result);\n\n return 0;\n})();"}, {"source_code": "var a, b = 0;\nreadline();\n\nwhile (a = readline()) {\n a = a.split(' ');\n if (a[1] - a[0] > 1) b++;\n}\n\nprint(b);"}, {"source_code": "var n = readline();\nvar res =0;\n\n\tfor (var i=0; i=2)\n\t\t{\n\t\t\tres++;\n\t\t}\n\t}\n\tprint(res);"}, {"source_code": "var n = parseInt(readline())\nvar c = 0;\nfor(var i = 0; i < n; ++i) {\n\tvar line = readline().split(\" \");\n\tp = parseInt(line[0]);\n\tq = parseInt(line[1]);\n\t\n\tif(q - p >= 2) {\n\t\t++ c;\n\t}\n}\nprint(c);\n"}, {"source_code": "var n = Number(readline());\n\nvar count = 0;\nwhile (n > 0) {\n var s = readline().split(' ').map(function(each) {return Number(each);});\n if (s[1] - s[0] >= 2)\n ++count;\n --n;\n}\n\nprint(count);\n "}, {"source_code": "function main(){\n\n var n = readline();\n var count = 0;\n\n\n for(i=0;i=2){\n\t count+=1;\n\t}\n }\n \n print(count);\n}\n\nmain();"}, {"source_code": "no = readline();\nvar vector;\nvar t = 0;\nfor (var i = 0; i < no; i++) {\n vector = readline().split(' ');\n if( parseInt(vector[1]) - parseInt(vector[0]) >=2 )\n t++;\n}\nwrite(t);\n"}, {"source_code": "var n = readline();\nvar quan = 0;\n\nfor (var i=0; i= 0) {\n c++\n }\n}\n\nprint(c)\n\n"}, {"source_code": "var n = readline();\nvar rooms = [];\nfor (var i = 0;i < n; ++i){\n var temp = readline().split(\" \");\n rooms.push(temp);\n}\nvar result = rooms.filter((room) => {\n if(room[1] - room[0] >= 2) return true;\n return false;\n}).length;\n\nprint(result);"}, {"source_code": "var n = parseInt(readline());\n\nvar room = 0;\n\nfor (var i = 0; i < n; i++) {\n \n var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n \n room = numbers[1] - numbers[0] >= 2 ? room + 1 : room;\n}\n\nprint(room);"}, {"source_code": "var n = parseInt(readline());\nvar count = 0;\nfor (var i = 0; i < n; i ++){\n var string = readline().split(\" \");\n var numberOfPeople = parseInt(string[0]);\n var maxNumberOfPeople = parseInt(string[1]);\n if ((maxNumberOfPeople - numberOfPeople) >= 2){\n count++;\n }\n}\nprint(count);"}, {"source_code": "var rooms = readline()\nvar count = 0\nfor(var i=1; i <= rooms; i++){\nvar line = readline(i).split(\" \")\nif ((line[1] - line[0]) >= 2){\n count ++\n}\n}\nprint(count)"}, {"source_code": "var count = readline();var calc = 0;\n\nfor (var i = 0; i < count; i++)\n{\nvar r = readline().split(' ');r =r[1] - r[0];\nif(r>=2){calc+=1;}\n}\n\n\nprint(calc);"}, {"source_code": "(function () {\n var n = parseInt(readline()),\n i = 0,\n sum = 0,\n line;\n for (; i < n; i++) {\n line = readline().split(\" \");\n if ((line[1] - line[0]) > 1) {\n sum++;\n }\n }\n print(sum);\n})();"}, {"source_code": "n = readline();\nvar count = 0;\nwhile(n--){\n\tk = readline().split(\" \")\n\tif(parseInt(k[0]) + 1 < parseInt(k[1]))\n\t{count++}\n}\nprint(count)"}, {"source_code": "var n=parseInt(readline()),res=0;for(;n--;)res+=(eval('-'+readline().replace(' ','+'))>1);write(res);"}, {"source_code": "var input = readline();\nvar cont = 0;\nfor(var i = 0; i < input; i++){\n\tvar ocupantes = readline().split(\" \");\n\tif(ocupantes[1] - ocupantes[0] >=2)\n\t\tcont++;\n}\nprint(cont);"}, {"source_code": "var numberRooms = readline();\nvar numberFreeRooms = 0;\nfor (var n=0; n < numberRooms; n++) {\n var roomInfo = readline().split(' ');\n var numberOccupiedPlace = roomInfo[0]; \n var numberSeatsRoom = roomInfo[1];\n if (numberSeatsRoom-numberOccupiedPlace >= 2) {\n numberFreeRooms++;\n }\n}\nprint(numberFreeRooms);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var output = 0;\n for(var i = 0; i < N; i++){\n var tmp = nextIntArray();\n if(tmp[1] - tmp[0] >= 2){\n output++;\n }\n }\n myout(output);\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let n = Number(readLine());\n let sum = 0;\n while (n--) {\n const [p, q] = readLine().split(' ').map(_a => Number(_a));\n if (q - p > 1) {\n sum++;\n }\n }\n console.log(sum);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nlet first = true;\nconst rooms = [];\nrl.on('line', line => {\n if (first) {\n first = false;\n return;\n }\n\n const input = line.split(' ');\n rooms.push(input);\n});\n\nrl.on('close', () => console.log(solution(rooms)));\n\n\n\nfunction solution(rooms) {\n let numberOfAvailableRooms = 0;\n for (let i = 0; i < rooms.length; i++) {\n let room = rooms[i];\n let freeSpaceInRoom = room[1] - room[0];\n if (freeSpaceInRoom > 1) {\n numberOfAvailableRooms++;\n }\n }\n\n return numberOfAvailableRooms;\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet counter = 0;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (counter === 0) {\n counter++;\n return;\n }\n\n let [p, q] = d.split(' ').map(Number);\n\n if (p + 2 <= q) {\n ans++;\n }\n counter++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let answer = 0;\n input.forEach((line, i) => {\n if (i === 0) return;\n const nums = line.split(' ').map(x => parseInt(x));\n\n if (nums[1] - nums[0] >= 2) answer += 1;\n });\n\n console.log(answer);\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet rooms=0\n\n\twhile(t--){\n\t\tlet [a,b] = readLine().split(\" \").map(n=>+n)\n\t\tif(b-a>=2)\n\t\t\trooms++\n\t}\n\n\tconsole.log(rooms)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let n = readAsInt();\n let total = 0;\n for(let i = 1;i <= n; i++){\n let [p, q] = readAsIntList();\n total += (q - p) >= 2 ? 1 : 0; \n }\n console.log(total);\n}\n \n\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n\n var arr = [];\n for (var i = 0; i < n; i++) {\n var s = readLine().split(\" \").map(Number);\n arr.push(...s);\n }\n\n var item1 = 0;\n var item2 = 1;\n var count = 0;\n while (n > 0) {\n if (arr[item2] - arr[item1] >= 2) {\n count++;\n }\n item1 += 2;\n item2 += 2;\n n--;\n }\n console.log(count);\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n\nfor (let index = 0; index < txt.length; index ++) {\n if(!isNaN(txt[index]*1)){\n let tab=0;\n for (let i = index+1; i <=index+txt[index]*1; i++) {\n let r=txt[i].split(\" \");\n if(r[1]-r[0]>=2){\n ++tab;\n }\n }\n console.log(tab);\n \n }\n\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().split('\\n');\n let rooms = +inputs[0];\n let roomsLeft = 0;\n for (let i = 1; i <= rooms; i++) {\n let [p, q] = inputs[i].trim().split(' ');\n if ((q - p) >= 2) {\n roomsLeft++;\n }\n }\n return roomsLeft.toString();\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst rooms = () => {\n +input.shift();\n let count = 0;\n for (const x of input) {\n let n = x.split(' ').map(x => +x);\n for (let i = 1; i > 0; i--) {\n if (n[i] - n[i-1] >= 2) {\n count++;\n }\n }\n }\n console.log(count);\n};\nreadLine.on('close', rooms);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let ans = 0;\n for (var i = 0; i < n; i++) {\n const arr = readLine()\n .split(' ')\n .map(value => parseInt(value));\n\n if (arr[1] - arr[0] >= 2) {\n ans++;\n }\n }\n console.log(ans);\n}"}], "negative_code": [{"source_code": "var n = readline();\nvar str = readline().split(\" \");// 3;\n//var b = +str[1];\nvar room = 0;\n\tfor (var i=0; i<+n; i++){\n\t\t\t\n\t\t\tif(+str[1]>=+str[0]+2)\n\t\t\troom++;\n\t}\nprint(room);"}, {"source_code": "var a = readline();\n\nvar rooms = [];\nvar freeRooms = 0;\n\n\n// for (let i = 0; i < a ; i++) {\n// var value = readline();\n// var s = value.split(' ');\n// if((Number(s[1]) - Number(s[0])) >= 2 ) {\n// freeRooms++; \n// }\n\n//}\n\nprint(freeRooms);"}, {"source_code": "const a = readline();\nconst b = [];\nfor (var i=0;i= 2 ) {\n// freeRooms++; \n// }\n\n//}\n\nprint(freeRooms);"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n const lineArr = readline().split(' ')\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2)\n count++;\n}\nprint(count)\n"}, {"source_code": "const n = readline()\nvar count = 0\nfor (var i = 0; i < n; i++){\n const lineArr = readline().split(' ')\n const p = lineArr[0];\n const q = lineArr[1];\n if (q - p >= 2){\n count++;\n }\n}\nprint(count)"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var line = readline()\n print(line)\n var lineArr = line.split(\" \")\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2){\n count++;\n }\n}\nprint(count)\n"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var lineArr = readline().split(' ')\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2)\n count++;\n}\nprint(count)"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var line = readline()\n var lineArr = line.split(\" \")\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2){\n count++;\n }\n}\nprint(count)"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var line = readline()\n var lineArr = line.split(\" \")\n print(lineArr[0])\n print(lineArr[1])\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2){\n count++;\n }\n}\nprint(count)\n"}, {"source_code": "const n = parseInt(readline())\nvar count = 0\nfor (var i = 0; i < n; i++){\n var line;\n while (line === undefined) {\n line = readline()\n }\n const lineArr = line.split(' ')\n const p = parseInt(lineArr[0])\n const q = parseInt(lineArr[1])\n if (q - p >= 2)\n count++;\n}\nprint(count)"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tcount = 0;\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar p = readline().split(/\\s/gi),\n\t\t\t\tq = p[1], p = p[0];\n\n\t\t\tif(p < q - 2)\tcount++;\n\t\t}\n\n\t\tprint(count);"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tcount = 0;\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar p = readline().split(/\\s/gi),\n\t\t\t\tq = p[1], p = p[0];\n\n\t\t\tif(p < q)\tcount++;\n\t\t}\n\n\t\tprint(count);"}, {"source_code": "var rooms = readline()\nvar count = 0\nfor(var i=1; i < rooms; i++){\nvar line = readline(i).split(\" \")\nif ((line[1] - line[0]) >= 2){\n count ++\n}\n}\n\nprint(count)"}, {"source_code": "var count = readline();var calc = 0;\nfor (var i = 0; i < count.length; i++)\n{\nr = readline(); r = (r[1] - r[0]);if(r>=2){calc+=1;}\n\n}\nprint(calc);"}, {"source_code": "var count = readline();var calc = 0;\n\n\nfor (var i = 0; i < count.length; i++)\n{\nvar r = readline().split(' ');\nr = parseInt(r[1]) - parseInt(r[0]);\nif(r>=2){calc+=1;}\n\n}\nprint(calc);"}, {"source_code": "var count = readline();var calc = 0;\nfor (var i = 0; i < count.length; i++)\n{\nr = readline().split(' ');\nr = parseInt(r[1]) - parseInt(r[0]);\nif(r>=2){calc+=1;}\n\n}\nprint(calc);"}, {"source_code": "var count = readline();var calc = 0;\nfor (var i = 0; i < count.length; i++)\n{\nr = readline().split(' ');\nr = parseInt(r[1] - r[0]);\nif(r>=2){calc+=1;}\n\n}\nprint(calc);"}, {"source_code": "var count = readline();var calc = 0;\nfor (var i = 0; i < count.length; i++)\n{\nr = readline().split(' ');\nr = (r[1] - r[0]);\nif(r>=2){calc+=1;}\n\n}\nprint(calc);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n\n var arr = [];\n for (var i = 0; i < n; i++) {\n var s = readLine().split(\" \").map(Number);\n arr.push(...s);\n }\n\n var item1 = 0;\n var item2 = 1;\n var count = 0;\n while (n > 0) {\n if (arr[item2] - arr[item1]) {\n count++;\n }\n item1 += 2;\n item2 += 2;\n n--;\n }\n console.log(count);\n}\n"}, {"source_code": "var r= +readline();\nvar counter=0;\nfor(var i=0; i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r= +readline();\nvar j=0;\nfor(var i=0; i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r= +readline();\nvar counter=0;\nfor(var i=0; i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r=+readline();\nvar j=0;\nfor(var i=0;i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r = +readline();\nvar counter = 0;\nfor(i=0; i < r; i++){\n var p= +readline().split(\" \"), q=+p[1], d=+p[0];\n if((q-d) >= 2){\n counter++;\n }\n}\nprint(counter);"}, {"source_code": "var r=+readline();\nvar j=0;\nfor(var i=0;i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r=+readline();\nvar j=0;\nfor(var i=0;i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r= +readline();\nvar j=0;\nfor(var i=0; i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r= +readline();\nvar counter=0;\nfor(var i=0; i= 2){\n counter++;\n }\n}\nprint(counter);"}, {"source_code": "var r= +readline();\nvar p= +readline();\nvar j=0;\nfor(var i=0; i= 2){\n j++;\n }\n}\nprint(j);"}, {"source_code": "var r = +readline(), p, q, d, counter = 0;\nfor(i=0; i < r; i++){\n p = +readline().split(\" \"); \n q = +p[1];\n d = +p[0];\n if((q-d) >= 2){\n counter++;\n }\n}\nwrite(counter);"}, {"source_code": "var r= +readline();\nvar p= +readline();\nvar j=0;\nfor(var i=0; i= 2){\n j++\n }\n}\nprint(j);"}, {"source_code": "var r= +readline();\nvar counter=0;\nfor(var i=0; i= 2){\n counter++;\n }\n}\nprint(counter);"}, {"source_code": "var r = +readline(), p, q, d, count = 0;\nfor(i=0; i < r; i++){\n p = +readline().split(\" \"); \n q = +p[1];\n d = +p[0];\n if((q-d) >= 2){\n count++;\n }\n}\nwrite(count);"}, {"source_code": "var r= +readline();\nvar j=0;\nfor(var i=0; i= 2){\n j++\n }\n}\nprint(j);"}, {"source_code": "m=readline()\nsum=0\nfor(i=0;i= 2)\n count++;\nprint(count);"}, {"source_code": "var n = readline();\nvar s = [];\nfor (var i = 0; i < n; i++)\n s.push(readline().split());\nvar count = 0;\nfor (var i = 0; i < n; i++)\n if ((s[i][1] - s[i][0]) >= 2)\n count++;\nprint(count);"}, {"source_code": "var n = readline();\nvar s = [];\nfor (var i = 0; i < n; i++)\n s.push(readline().split());\nvar count = 0;\n\nfor (var i = 0; i < n; i++)\n if ((s[i][1] - s[i][0]) >= 2)\n count++;\nprint(count);"}, {"source_code": "var n = parseInt(readline());\nvar s = [];\nfor (var i = 0; i < n; i++)\n s.push(readline().split());\nvar count = 0;\nfor (var i = 0; i < n; i++)\n if ((parseInt(s[i][1]) - parseInt(s[i][0])) >= 2)\n count++;\nprint(count);"}, {"source_code": "var n = parseInt(readline());\nvar freeroom = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar pq = readline().split(' ');\n\tif((parseInt(pq[0]) + 2) >= parseInt(pq[1]))\n\t\tfreeroom++;\n}\n\nprint(freeroom);"}, {"source_code": "var n = parseInt(readline());\nvar freeroom = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar pq = readline();\n\tif((parseInt(pq[0]) + 2) >= parseInt(pq[1]))\n\t\tfreeroom++;\n}\n\nprint(freeroom);"}, {"source_code": "var n = parseInt(readline());\nvar freeroom = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar pq = readline().split(' ');\n\tif((parseInt(pq[1]) - parseInt(pq[1])) >= 2)\n\t\tfreeroom++;\n}\n\nprint(freeroom);"}, {"source_code": "var str1 = readline().split(\" \");\nvar str2 = readline().split(\" \");\nprint (str2);"}, {"source_code": "var n =readline();\nvar room = [];\nvar str1 = \" \";\nfor (i=1;i<=n;i++) room.push(readline());\nprint (room);"}, {"source_code": "var str1 = readline().split(\" \");\nvar str2 = readline();\nprint (str2);"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");// 3;\n//var b = +str[1];\nvar room = 0;\n\tfor (var i=0; i<+n; i++){\n\t\t\t\n\t\t\tif(+str[1]-2>=+str[0])\n\t\t\troom++;\n\t}\nprint(room);"}], "src_uid": "2a6c457012f7ceb589b3dea6b889f7cb"} {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var UniAccel, a, d, l, r, sa, sc, sd, sf, su, sv, sw, td, tf, tu, v, vb, w, _ref, _ref1;\n\n UniAccel = {\n vel_change_disp: function(v0, v1, a) {\n return (v1 * v1 - v0 * v0) / (2 * a);\n },\n disp_time: function(s, v0, a) {\n return (Math.sqrt(v0 * v0 + 2 * a * s) - v0) / a;\n }\n };\n\n _ref = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), a = _ref[0], v = _ref[1];\n\n _ref1 = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), l = _ref1[0], d = _ref1[1], w = _ref1[2];\n\n sw = UniAccel.vel_change_disp(0, w, a);\n\n sv = UniAccel.vel_change_disp(0, v, a);\n\n if (w > v || sw >= d) {\n if (sv > l) {\n print(UniAccel.disp_time(l, 0, a).toFixed(5));\n } else {\n print((v / a + (l - sv) / v).toFixed(5));\n }\n } else {\n sf = UniAccel.vel_change_disp(w, v, a);\n tf = 0;\n r = l - d;\n if (sf > r) {\n tf = UniAccel.disp_time(r, w, a);\n } else {\n tf = UniAccel.disp_time(sf, w, a) + (r - sf) / v;\n }\n su = UniAccel.vel_change_disp(0, v, a);\n sd = UniAccel.vel_change_disp(v, w, -a);\n sa = su + sd;\n if (sa <= d) {\n sc = d - sa;\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, v, -a);\n print((tu + sc / v + td + tf).toFixed(5));\n } else {\n vb = Math.sqrt(a * d + (w * w) / 2);\n su = UniAccel.vel_change_disp(0, vb, a);\n sd = UniAccel.vel_change_disp(vb, w, -a);\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, vb, -a);\n print((tu + td + tf).toFixed(5));\n }\n }\n\n}).call(this);\n", "positive_code": [{"source_code": "\nline = readline().split(' ');\na = parseInt( line[0] );\nv = parseInt( line[1] );\nline = readline().split(' ');\nl = parseInt( line[0] );\nd = parseInt( line[1] );\nw = parseInt( line[2] );\n\n\nfunction dist(v, t){\n\treturn v*t + a*t*t/2;\n}\nfunction travel(distance, speed){\n\tvar tmax = ( Math.sqrt(speed*speed+2*a*distance) - speed )/a;\n\tvar t = (v-speed)/a;\n\treturn tmax>=t ? t+(distance-dist(speed,t))/v : tmax;\n}\n\nvar tw = w/a;\nvar dw = dist(0, tw);\nif(v<=w||dw>=d){\n\tprint( travel(l, 0) );\n}else{\n\tprint( tw + 2*travel(0.5*(d-dw), w)+travel(l-d, w) );\n}"}], "negative_code": [{"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var UniAccel, a, d, l, sa, sc, sd, sf, su, sv, sw, td, tf, tu, v, vb, w, _ref, _ref1;\n\n UniAccel = {\n vel_change_disp: function(v0, v1, a) {\n return (v1 * v1 - v0 * v0) / (2 * a);\n },\n disp_time: function(s, v0, a) {\n return (Math.sqrt(v0 * v0 + 2 * a * s) - v0) / a;\n }\n };\n\n _ref = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), a = _ref[0], v = _ref[1];\n\n _ref1 = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), l = _ref1[0], d = _ref1[1], w = _ref1[2];\n\n sw = UniAccel.vel_change_disp(0, w, a);\n\n sv = UniAccel.vel_change_disp(0, v, a);\n\n if (w > v || sw >= d) {\n if (sv > l) {\n print(UniAccel.disp_time(l, 0, a).toFixed(5));\n } else {\n print((v / a + (l - sv) / v).toFixed(5));\n }\n } else {\n sf = UniAccel.vel_change_disp(w, v, a);\n tf = UniAccel.disp_time(sf, w, a) + (l - d - sf) / v;\n su = UniAccel.vel_change_disp(0, v, a);\n sd = UniAccel.vel_change_disp(v, w, -a);\n sa = su + sd;\n if (sa <= d) {\n sc = d - sa;\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, v, -a);\n print((tu + sc / v + td + tf).toFixed(5));\n } else {\n vb = Math.sqrt(a * d + (w * w) / 2);\n su = UniAccel.vel_change_disp(0, vb, a);\n sd = UniAccel.vel_change_disp(vb, w, -a);\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, vb, -a);\n print((tu + td + tf).toFixed(5));\n }\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var UniAccel, a, d, l, r, sa, sc, sd, sf, su, sv, sw, td, tf, tu, v, vb, w, _ref, _ref1;\n\n UniAccel = {\n vel_change_disp: function(v0, v1, a) {\n return (v1 * v1 - v0 * v0) / (2 * a);\n },\n disp_time: function(s, v0, a) {\n return (Math.sqrt(v0 * v0 + 2 * a * s) - v0) / a;\n }\n };\n\n _ref = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), a = _ref[0], v = _ref[1];\n\n _ref1 = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), l = _ref1[0], d = _ref1[1], w = _ref1[2];\n\n sw = UniAccel.vel_change_disp(0, w, a);\n\n sv = UniAccel.vel_change_disp(0, v, a);\n\n if (w > v || sw >= d) {\n if (sv > l) {\n print(1);\n print(UniAccel.disp_time(l, 0, a).toFixed(5));\n } else {\n print(2);\n print((v / a + (l - sv) / v).toFixed(5));\n }\n } else {\n sf = UniAccel.vel_change_disp(w, v, a);\n tf = 0;\n r = l - d;\n if (sf > r) {\n tf = UniAccel.disp_time(r, w, a);\n } else {\n tf = UniAccel.disp_time(sf, w, a) + (r - sf) / v;\n }\n su = UniAccel.vel_change_disp(0, v, a);\n sd = UniAccel.vel_change_disp(v, w, -a);\n sa = su + sd;\n if (sa <= d) {\n print(3);\n sc = d - sa;\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, v, -a);\n print((tu + sc / v + td + tf).toFixed(5));\n } else {\n print(4);\n vb = Math.sqrt(a * d + (w * w) / 2);\n su = UniAccel.vel_change_disp(0, vb, a);\n sd = UniAccel.vel_change_disp(vb, w, -a);\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, vb, -a);\n print((tu + td + tf).toFixed(5));\n }\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var UniAccel, a, d, l, sa, sc, sd, su, sv, sw, td, tf, tu, v, vb, w, _ref, _ref1;\n\n UniAccel = {\n vel_change_disp: function(v0, v1, a) {\n return (v1 * v1 - v0 * v0) / (2 * a);\n },\n disp_time: function(s, v0, a) {\n return (Math.sqrt(v0 * v0 + 2 * a * s) - v0) / a;\n }\n };\n\n _ref = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), a = _ref[0], v = _ref[1];\n\n _ref1 = readline().split(' ').map(function(x) {\n return parseInt(x);\n }), l = _ref1[0], d = _ref1[1], w = _ref1[2];\n\n sw = UniAccel.vel_change_disp(0, w, a);\n\n sv = UniAccel.vel_change_disp(0, v, a);\n\n if (w > v || sw >= d) {\n if (sv > l) {\n print(UniAccel.disp_time(l, 0, a).toFixed(5));\n } else {\n print((v / a + (l - sv) / v).toFixed(5));\n }\n } else {\n tf = UniAccel.disp_time(l - d, w, a);\n su = UniAccel.vel_change_disp(0, v, a);\n sd = UniAccel.vel_change_disp(v, w, -a);\n sa = su + sd;\n if (sa <= d) {\n sc = d - sa;\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, v, -a);\n print((tu + sc / v + td + tf).toFixed(5));\n } else {\n vb = Math.sqrt(a * d + (w * w) / 2);\n su = UniAccel.vel_change_disp(0, vb, a);\n sd = UniAccel.vel_change_disp(vb, w, -a);\n tu = UniAccel.disp_time(su, 0, a);\n td = UniAccel.disp_time(sd, vb, -a);\n print((tu + td + tf).toFixed(5));\n }\n }\n\n}).call(this);\n"}], "src_uid": "de8c909d6ca4f3b2f885fc60be246458"} {"source_code": "var n = Number(readline());\nvar a = readline().split(' ').map(Number);\nvar c = [0, 0];\nfor (var i = 0; i < n; i++) { \n if (a[i] % 2 === 0) c[0]++;\n else c[1]++;\n}\nif (c[1] % 2 === 0) {\n print(c[0]);\n} else {\n print(c[1]);\n}\n", "positive_code": [{"source_code": "\"use strict\";\n\nvar n = readline();\nvar a = readline().split(' ').map(Number);\nvar sum = 0, even = 0;\nfor(var i = 0; i < n; i++) { \n sum += a[i];\n if (a[i] % 2 === 0) { even++; }\n}\nif (sum % 2 === 0) {\n print(even);\n} else {\n print(n - even);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let sum = arr.reduce((a, b) => a + b, 0);\n let ans = 0;\n\n arr.forEach(x => (sum - x) % 2 === 0 && ans++);\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "readline();\nvar a=readline().split(' ').map(Number);\nvar p=a.reduce(function(a,b){return a+b;})%2;\nprint(a.filter(function(v){return v%2===p;}).length);"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline();\n\tif (n == 1) {\n\t\tprint(1);\n\t\treturn;\n\t}\n\n\tvar p = readline().split(' ');\n\tvar s = p.reduce(function (p, e) { return p + +e; }, 0);\n\n\tvar x = 0;\n\tp.forEach(function (e) {\n\t\tif (! ((s - e) % 2)) x++;\n\t});\n\n\tprint(x);\n\n}).call(this);"}, {"source_code": "var limit = readline()\nvar values = readline().split(\" \")\nvar sum = 0;\nvar count = 0;\nfor(var i = 0; i < values.length; i++){\n sum += parseInt(values[i])\n}\n\nfor(var i = 0; i < values.length; i++){\n if((sum - parseInt(values[i])) % 2 == 0){\n count++\n }\n}\n\nprint(count)"}, {"source_code": "n = +readline();\na = readline().split(' ').map(Number);\n\ntot = 0 ;\nfor (i = 0 ; i < n ; i ++)\n{\n tot += a[i];\n}\nvar res = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n rem = tot - a[i];\n if (rem % 2 === 0 )\n {\n res ++;\n }\n}\nwrite(res);\n"}], "negative_code": [{"source_code": "n = +readline();\na = readline().split(' ').map(Number);\nwrite(a);\n\ntot = 0 ;\nfor (i = 0 ; i < n ; i ++)\n{\n tot += a[i];\n}\nvar res = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n rem = tot - a[i];\n if (rem % 2 === 0 )\n {\n res ++;\n }\n}\nwrite(res);\n"}, {"source_code": "n = +readline();\na = readline().split(' ').map(parseInt);\n\ntot = 0 ;\nfor (i = 0 ; i < n ; i ++)\n{\n tot += a[i];\n}\nvar res = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n rem = tot - a[i];\n if (rem % 2 === 0 )\n {\n res ++;\n }\n}\nwrite(res);\n"}], "src_uid": "4c59b4d43b59c8659bf274f3e29d01fe"} {"source_code": "const balance = s => {\n let res = 0\n for (let i = 0; i < s.length; i++) {\n res += s[i] === '1' ? -1 : 1\n }\n return res\n}\n\nconst processData = (lines) => {\n const count = lines[0]\n\n for (i = 0; i < count; i++){\n let money = +lines[i + 1]\n let res = money\n while(money >= 10) {\n const cacheback = Math.floor(money/10)\n money -= cacheback * 10\n money += cacheback\n res += cacheback\n }\n console.log(res)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "var n = readline();\nvar results = [];\nvar s, remainder, sum;\n\nfor (var i=0; i= 10) {\n remainder = s%10;\n sum += s - remainder;\n s = Math.floor(s/10) + remainder;\n }\n sum += s;\n print(sum);\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n let s = readInt()\n if(s < 10) wr(s)\n else {\n let x = 0\n while(s >= 10) {\n x += Math.floor(s / 10) * 10\n s = Math.floor(s / 10) + s % 10\n // wr(x, s)\n }\n wr(x + s)\n }\n }\n}\n"}, {"source_code": "function processData(input) {\n\t//Enter your code here\n\tvar data = input\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map(a => parseInt(a));\n\t// console.log(data)\n\tvar tcs = data[0];\n\tfor (var i = 1; i <= tcs; i++) {\n\t\tlet num = data[i];\n\t\tvar sum = num;\n\t\tvar res = foodBuy(num);\n\t\tconsole.log(res);\n\t}\n\n\tfunction foodBuy(num) {\n\t\tvar num1 = Math.floor(num / 10) + (num % 10);\n\t\tsum = sum + Math.floor(num / 10);\n\t\tif (num < 10) {\n\t\t\treturn sum;\n\t\t} else {\n\t\t\treturn foodBuy(num1);\n\t\t}\n\t\treturn sum;\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function(input) {\n\t_input += input;\n});\n\nprocess.stdin.on(\"end\", function() {\n\tprocessData(_input);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let curr = 0;\n let add = 0;\n\n while (n > 0) {\n curr += n;\n add += n % 10;\n n = Math.floor(n / 10);\n }\n\n let [x, y] = (add / 10).toString().split('.').map(Number);\n\n if (x + y >= 10) {\n add = Math.ceil(add / 10);\n }\n else {\n add = Math.floor(add / 10);\n }\n\n ans += `${curr + add}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet n = (m = remainingLines = remainingTestCount = lineNumber = lineCount = 0);\n\n// Some utitls\nconst utils = {};\nutils.doOnEachLine = (line) => {\n let s = Number(line);\n let a = s;\n let n = 0;\n\n while (a >= 10) {\n x = Math.floor(a / 10);\n n += x;\n a = x + (a % 10);\n }\n\n console.log(n + s);\n};\n\nrl.on('line', async (line) => {\n // Getting Inputs: Type one\n try {\n lineNumber++;\n if (lineNumber === 1) {\n lineCount = Number(line);\n return;\n }\n utils.doOnEachLine(line);\n } catch (e) {\n console.log(e.message);\n console.log(e.stack);\n }\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', x => input.push(x));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n \n for (let i = 1; i <= n; i++) {\n let sum = parseInt(input[i]);\n let tog = 0;\n for (let j = 10 ** 9; j >= 10; j /= 10) {\n if(Math.trunc(sum / j) >= 1) {\n let spent = j * Math.trunc(sum / j);\n let cashback = spent / 10;\n sum = sum - spent + cashback;\n tog += spent;\n if (sum / j >= 1) {\n j *= 10;\n }\n } else {\n continue;\n }\n }\n\n tog += sum;\n console.log(tog);\n }\n});"}, {"source_code": "'use strict'\n \nlet t = parseInt(readline())\nwhile (t --> 0) {\n let n = parseInt(readline())\n let ans = 0\n\n while (n >= 10) {\n const r = parseInt(n / 10)\n ans += r * 10\n n = parseInt(n % 10) + r\n }\n print(ans + n)\n}"}, {"source_code": "'use strict'\n\nconst problem = (s) => {\n let r = 0, x;\n while (s >= 10) {\n r += (x = s/10|0);\n s -= 9*x;\n }\n return r*10 + s;\n}\n\nlet t = +readline();\nwhile(t--) print(problem(+readline()));\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var tmp = 0;\n while(true){\n if(N < 10){\n tmp += N;\n break;\n }\n var nokori = (N % 10);\n var add = N - nokori;\n tmp += add;\n N = nokori + (add / 10);\n }\n output[i] = tmp;\n }\n myout(myconv(output,9));\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n let ans = 0\n let n2 = n\n while (n2 > 0) {\n ans += parseInt(n2 / 10)\n n2 /= 10\n }\n\n print(parseInt(ans + n))\n}"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n let ans = 0\n let n2 = n\n while (n2 > 0) {\n ans += parseInt(n2 / 10)\n n2 = parseInt(n2 / 10)\n }\n\n print(parseInt(ans + n))\n}"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n let ans = 0\n let n2 = n\n while (n2 > 0) {\n ans += n2 / 10\n n2 /= 10\n }\n\n print(parseInt(ans + n))\n}"}, {"source_code": "var n = readline();\nvar results = [];\nvar s, remainder, sum;\n\nfor (var i=0; i= 10) {\n remainder = s%10;\n sum += s - remainder;\n s = Math.floor(s/10) + remainder;\n }\n sum += s;\n print(sum);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let inc = 0;\n let prev = 0;\n let curr = 0;\n\n while (n > 0) {\n curr += n;\n let r = curr % 10;\n\n if (r < prev) {\n inc++;\n }\n\n prev = r;\n\n n = Math.floor(n / 10);\n }\n\n ans += `${curr + inc}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let sum = 0;\n\n let isOdd = false;\n let isEven = false;\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i];\n\n if (arr[i] % 2 === 0) {\n isEven = true;\n }\n else {\n isOdd = true;\n }\n }\n\n if (sum % 2 !== 0 || (isEven && isOdd)) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n // let ans = 'NO';\n // let sum = 0;\n\n // for (let i = 0; i < arr.length; i++) {\n // sum += arr[i];\n\n // for (let j = 0; j < arr.length; j++) {\n // if ((arr[i] + arr[j]) % 2 !== 0) {\n // ans = 'YES';\n // break;\n // }\n // }\n // }\n\n // if (sum % 2 !== 0) {\n // ans = 'YES';\n // }\n\n // console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let inc = 0;\n let prev = 0;\n let curr = 0;\n let r = 0;\n\n while (n > 0) {\n curr += n;\n r = curr % 10;\n\n if (r < prev) {\n inc++;\n }\n\n prev = r;\n\n n = Math.floor(n / 10);\n }\n\n if (r < prev) {\n inc++;\n }\n\n ans += `${curr + inc}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let curr = 0;\n let add = 0;\n\n while (n > 0) {\n curr += n;\n add += n % 10;\n n = Math.floor(n / 10);\n }\n\n ans += `${curr + Math.floor(add / 10)}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet n = (m = remainingLines = remainingTestCount = lineNumber = lineCount = 0);\n\n// Some utitls\nconst utils = {};\nutils.doOnEachLine = (line) => {\n let s = Number(line);\n let n = 0;\n\n n = Math.floor(s / 9);\n\n console.log(s + n);\n};\n\nrl.on('line', async (line) => {\n // Getting Inputs: Type one\n try {\n lineNumber++;\n if (lineNumber === 1) {\n lineCount = Number(line);\n return;\n }\n utils.doOnEachLine(line);\n } catch (e) {\n console.log(e.message);\n console.log(e.stack);\n }\n});\n"}, {"source_code": "function processData(input) {\n\t//Enter your code here\n\tvar data = input.trim().split(\"\\n\").map(a => parseInt(a));\n\t// console.log(data);\n\n\tvar tcs = data[0];\n\tfor (var i = 1; i <= tcs; i++) {\n\t\tlet num = data[i];\n\t\tvar sum = num;\n\t\tvar res = foodBuy(num);\n\t\tconsole.log(res);\n\t}\n\n\tfunction foodBuy(num) {\n\t\tvar num1 = Math.floor(num / 10) + (num % 10);\n\n\t\tif (num <10) {\n\t\t\tsum = num;\n\t\t\treturn sum;\n\t\t}\n\t\telse if (Math.floor(num / 10) == 1 && num1 < 10) {\n\t\t\tsum = sum + Math.floor(num / 10);\n\t\t\treturn sum;\n\t\t} else {\n\t\t\t// num = Math.floor(num/10)+num%10\n\t\t\tsum = sum + Math.floor(num / 10);\n\t\t\t// console.log(sum)\n\t\t\treturn foodBuy(num1);\n\t\t}\n\t\treturn sum;\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function(input) {\n\t_input += input;\n});\n\nprocess.stdin.on(\"end\", function() {\n\tprocessData(_input);\n});\n"}, {"source_code": "function processData(input) {\n\t//Enter your code here\n\tvar data = input.split(\"\\n\").map(a => parseInt(a));\n\tconsole.log(data);\n\n\tvar tcs = data[0];\n\tfor (var i = 1; i <= tcs; i++) {\n\t\tlet num = data[i];\n\t\tvar sum = num;\n\t\tvar res = foodBuy(num);\n\t\tconsole.log(res);\n\t}\n\n\tfunction foodBuy(num) {\n\t\tvar num1 = Math.floor(num / 10) + (num % 10);\n\n\t\tif (num == 1) {\n\t\t\tsum = 1;\n\t\t\treturn sum;\n\t\t}\n\t\tif (Math.floor(num / 10) == 1 && num1 < 10) {\n\t\t\tsum = sum + Math.floor(num / 10);\n\t\t\treturn sum;\n\t\t} else {\n\t\t\t// num = Math.floor(num/10)+num%10\n\t\t\tsum = sum + Math.floor(num / 10);\n\t\t\t// console.log(sum)\n\t\t\treturn foodBuy(num1);\n\t\t}\n\t\treturn sum;\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function(input) {\n\t_input += input;\n});\n\nprocess.stdin.on(\"end\", function() {\n\tprocessData(_input);\n});\n"}], "src_uid": "0beecbd62aa072a2f3aab542eeb56373"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let arr = stringArr();\r\n let dp = new Array(arr.length).fill(Infinity);\r\n let obj = {};\r\n dp[0] = 1;\r\n obj[arr[0]] = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (obj[arr[i]] !== undefined) {\r\n let k = obj[arr[i]];\r\n let j = k - 1 < 0 ? 0 : dp[k - 1];\r\n dp[i] = Math.min(dp[i], j + (i - k - 1));\r\n }\r\n dp[i] = Math.min(dp[i], dp[i - 1] + 1);\r\n obj[arr[i]] = i;\r\n }\r\n console.log(dp[arr.length - 1]);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (s)=>{\n let d = new Map();\n let prev_pos = new Map();\n for (let i=0; ians)\n ans = take;\n }\n d.set(i, ans)\n prev_pos.set(ch, i);\n }\n return s.length-d.get(s.length-1)\n /**\n const cache_d = new Map();\n const cache_find_prev = new Map();\n\n const find_prev = (char, until)=>{\n let k = char+';'+until;\n if (cache_find_prev.has(k))\n return cache_find_prev.get(k);\n if (until==0)\n return -1;\n if (s[until-1]==char)\n return until-1;\n let ans = find_prev(char, until-1);\n cache_find_prev.set(k, ans)\n return ans;\n };\n //console.log('S\\n', s)\n\n const d = (len)=>{\n if (len<2)\n return 0;\n if (cache_d.has(len))\n return cache_d.get(len);\n let char = s[len-1];\n let not_take = d(len-1);\n let prev_pos = find_prev(char, len-1);\n //console.log('find_prev', char, len-1, {prev_pos})\n if (prev_pos==-1)\n return not_take;\n let take = d(prev_pos)+2;\n let ans = Math.max(not_take, take);\n cache_d.set(len, ans);\n return ans;\n };\n let len = d(s.length);\n //console.log(cache_d)\n return s.length-len;\n **/\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let s = readline();\n print(calc(s))\n }\n}\n\nE.calc = calc;"}, {"source_code": "let readline = require('readline'); \r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n}); \r\nlet input = []; \r\nlet takeInput = async function () { \r\n rl.on('line', function (line) {\r\n input.push(line);\r\n });\r\n}\r\ntakeInput();\r\nnumberOfline = 0;\r\nnextString = () =>{\r\n return input[numberOfline++];\r\n}\r\nnextInt = () => { \r\n return parseInt(input[numberOfline++], 10);\r\n}\r\nnextArrayOfInt = () => { \r\n let str = input[numberOfline++];\r\n return str.split(' ').map((val) => {\r\n return parseInt(val);\r\n }); \r\n}\r\nnextFloat = () => { \r\n return parseFloat(input[numberOfline++]);\r\n}\r\nintDiv = (val, div) => { \r\n return (val - val % div) / div;\r\n}\r\n\r\nlet main = () => { \r\n let test = 1;\r\n test = nextInt();\r\n while (test--){ \r\n solve()\r\n }\r\n\r\n} \r\n\r\nlet solve = () => { \r\n let str = String(nextString());\r\n const mp = new Map();\r\n let ans = 0;\r\n let n = str.length;\r\n\r\n for (i = 0; i < n; i++){ \r\n if (mp.has(str.charAt(i))){\r\n mp.clear();\r\n ans--;\r\n }\r\n else{\r\n ans++;\r\n mp.set(str.charAt(i), 1);\r\n }\r\n \r\n }\r\n console.log(ans);\r\n \r\n}\r\nrl.on('close', main);"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let s = readLine();\r\n let size = s.length;\r\n let arr = new Array(26).fill(false), m = 0;\r\n for (let i = 0; i < size; i++) {\r\n let ind = s.charCodeAt(i) - 97;\r\n if (arr[ind]) {\r\n m += 2;\r\n arr = arr.map(i => false);\r\n } else {\r\n arr[ind] = true;\r\n }\r\n }\r\n return size - m;\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst n = Number(inputs[0])\r\n\r\nmain(n, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 1; i <= _; i++) {\r\n let ans = 0\r\n const str = lines[i].trim()\r\n const set = new Set()\r\n for (let char of str) {\r\n if (set.has(char)) {\r\n ans += set.size - 1\r\n set.clear()\r\n } else {\r\n set.add(char)\r\n }\r\n }\r\n res.push(ans + set.size)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const last = {}\n const dp = Array(str.length)\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]\n const del = (dp[i - 1] || 0) + 1\n if (ch in last) {\n const prev = last[ch]\n dp[i] = Math.min(del, (dp[prev - 1] || 0) + i - prev - 1)\n } else {\n dp[i] = del\n }\n //\n last[ch] = i\n }\n // console.log(dp)\n return dp[str.length - 1]\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let arr = stringArr();\r\n let dp = [],\r\n obj = {};\r\n dp[0] = 1;\r\n obj[arr[0]] = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (obj[arr[i]] === undefined) dp[i] = dp[i - 1] + 1;\r\n else {\r\n let k = obj[arr[i]];\r\n let j = k - 1 < 0 ? 0 : dp[k - 1];\r\n dp[i] = j + (i - k - 1);\r\n }\r\n obj[arr[i]] = i;\r\n }\r\n console.log(dp[arr.length - 1]);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let arr = stringArr();\r\n let dp = [],\r\n ans = arr.length,\r\n obj = {};\r\n dp[0] = 1;\r\n obj[arr[0]] = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (obj[arr[i]] === undefined) dp[i] = dp[i - 1] + 1;\r\n else {\r\n let k = obj[arr[i]];\r\n let j = k - 1 < 0 ? 0 : dp[k - 1];\r\n dp[i] = j + (i - k - 1);\r\n }\r\n ans = Math.min(ans, dp[i] + arr.length - i - 1);\r\n obj[arr[i]] = i;\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let arr = stringArr();\r\n let obj = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = [i];\r\n else obj[arr[i]].push(i);\r\n }\r\n const isAvl = (val, pos, end) => {\r\n let arr = obj[val];\r\n if (arr.length === 1) return false;\r\n for (let i = 0; i < arr.length; i++)\r\n if (arr[i] > pos && arr[i] <= end) return arr[i];\r\n return false;\r\n };\r\n const helper = (st, end) => {\r\n let ans = 0;\r\n while (st <= end) {\r\n if (arr[st] === arr[st + 1]) {\r\n st += 2;\r\n continue;\r\n }\r\n let k = isAvl(arr[st], st, end);\r\n if (k === false) {\r\n ans++;\r\n st++;\r\n } else {\r\n if (k - st - 1 <= 2) {\r\n ans += k - st - 1;\r\n st = k + 1;\r\n } else {\r\n let j = helper(st + 1, k - 1);\r\n if (j === k - st - 1) {\r\n ans += k - st - 1;\r\n st = k + 1;\r\n } else {\r\n ans += j + 1;\r\n st = k;\r\n }\r\n }\r\n }\r\n }\r\n return ans;\r\n };\r\n console.log(helper(0, arr.length - 1));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let arr = stringArr();\r\n let obj = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = [i];\r\n else obj[arr[i]].push(i);\r\n }\r\n const isAvl = (val, pos, end) => {\r\n let arr = obj[val];\r\n if (arr.length === 1) return false;\r\n for (let i = 0; i < arr.length; i++)\r\n if (arr[i] > pos && arr[i] < end) return arr[i];\r\n return false;\r\n };\r\n const helper = (st, end) => {\r\n let ans = 0;\r\n while (st <= end) {\r\n if (arr[st] === arr[st + 1]) {\r\n st += 2;\r\n continue;\r\n }\r\n let k = isAvl(arr[st], st, end);\r\n if (k === false) {\r\n ans++;\r\n st++;\r\n } else {\r\n if (k - st - 1 <= 2) {\r\n ans += k - st - 1;\r\n st = k + 1;\r\n } else {\r\n let j = helper(st + 1, k - 1);\r\n if (j === k - st - 1) {\r\n ans += k - st - 1;\r\n st = k + 1;\r\n } else {\r\n ans += j + 1;\r\n st = k;\r\n }\r\n }\r\n }\r\n }\r\n return ans;\r\n };\r\n console.log(helper(0, arr.length - 1));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "6b92f09df1e35edc80cf1cbf8494b41e"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n const w = +readLine();\n const len = str.length;\n\n const arr = [...Array(str.length).fill(1)];\n let flag = true;\n\n if (w >= len) {\n console.log(-1);\n continue;\n }\n for (let i = 0; i < len; i++) {\n if (str[i] === \"0\") {\n if (i - w >= 0) {\n arr[i - w] = 0;\n }\n if (i + w < len) {\n arr[i + w] = 0;\n }\n }\n }\n\n for (let i = 0; i < len; i++) {\n if (str[i] === \"1\") {\n if (arr[i - w] !== 1 && arr[i + w] !== 1) {\n flag = false;\n break;\n }\n }\n }\n\n if (flag) console.log(arr.join(\"\"));\n else console.log(-1);\n }\n}\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (var i=0; i= 0) w[j-x]=\"0\";\n }\n }\n let ok = true;\n for (let j=0; j=0 && w[j-x] == \"1\")) {\n ok = false;\n }\n }\n }\n console.log(ok ? w.join('') : \"-1\");\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let s = nextString().split('');\n let x = nextNumber();\n let arr = new Array(s.length).fill('1');\n s.forEach((n, i) => {\n if (n === '0') {\n if (i - x >= 0) {\n arr[i - x] = '0';\n }\n if (i + x < arr.length) {\n arr[i + x] = '0';\n }\n }\n });\n const success = s.every((n, i) => {\n let c1 = i - x >= 0 && arr[i - x] === '1';\n let c2 = i + x <= s.length && arr[i + x] === '1';\n if (c1 || c2) {\n return n === '1';\n }\n return n === '0';\n });\n if (!success) {\n console.log('-1');\n } else {\n console.log(arr.join(''));\n }\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let s = nextString().split('');\n let x = nextNumber();\n let arr = new Array(s.length).fill('1');\n s.forEach((n, i) => {\n if (n === '0') {\n if (i - x >= 0) {\n arr[i - x] = '0';\n }\n if (i + x < arr.length) {\n arr[i + x] = '0';\n }\n }\n });\n const success = arr.every((n, i) => {\n let c1 = i - x >= 0 && arr[i - x] === '1';\n let c2 = i + x <= s.length && arr[i + x] === '1';\n if (c1 || c2) {\n return s[i] === '1';\n }\n return s[i] === '0';\n });\n // let success = true;\n // s.forEach((n, i) => {\n // if (n === '1') {\n // let any = false;\n // if (i - x >= 0 && arr[i - x] !== '0') {\n // arr[i - x] = '1';\n // any = true;\n // }\n // // console.log(n, i, i + x, arr[i + x]);\n // if (i + x < arr.length && arr[i + x] !== '0') {\n // arr[i + x] = '1';\n // any = true;\n // }\n // if (!any) {\n // success = false;\n // }\n // }\n // });\n // console.log(arr.join(''));\n if (!success) {\n console.log('-1');\n } else {\n console.log(arr.join(''));\n }\n // 2\n // 10110110\n // ??00?00?\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probB(){\n let t = parseInt(readline());\n\n while(t > 0){\n t--;\n let [p,f] = readline().split(' ');\n let cap = parseInt(p) + parseInt(f);\n\n let [cs, cw] = readline().split(' ');\n let [s, w] = readline().split(' ');\n\n let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));\n\n let tot = parseInt(cs) + parseInt(cw);\n if(cap > ava){\n console.log(tot);\n continue;\n }\n\n let x = Math.min(parseInt(s), parseInt(w));\n if(parseInt(s) === x){\n if(parseInt(cs) * x > cap){\n console.log(Math.floor(cap / parseInt(cs)));\n }else{\n let rem = cap - (x * parseInt(cs));\n console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));\n }\n }else{\n if(parseInt(cw) * x > cap){\n console.log(Math.floor(cap / parseInt(cw)));\n }else{\n let rem = cap - (x * parseInt(cw));\n console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));\n }\n }\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }else{\n isPossible = false;\n break;\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}"}, {"source_code": "var numCases = parseInt(readline());\nfor (var i = 0; i < numCases; i ++) {\n var str = readline();\n var x = parseInt(readline());\n var output = [];\n for (var j = 0; j < str.length; j ++) output.push('1');\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '0') {\n if (j - x >= 0) {\n output[j - x] = '0';\n }\n if (j + x < str.length) {\n output[j + x] = '0';\n }\n }\n }\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '1') {\n if ((j - x < 0 || output[j - x] === '0') \n && (j + x >= str.length || output[j + x] === '0')) {\n output = ['-1'];\n }\n }\n }\n print(output.join(''));\n}"}], "negative_code": [{"source_code": "var numCases = parseInt(readline());\nfor (var i = 0; i < numCases; i ++) {\n var str = readline();\n var x = parseInt(readline());\n var output = '';\n for (var j = 0; j < str.length; j ++) output += '1';\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '0') {\n if (j - x >= 0) {\n output[j - x] = '0';\n }\n if (j + x < str.length) {\n output[j + x] = '0';\n }\n }\n }\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '1') {\n if ((j - x < 0 || output[j - x] === '0') && (j + x >= str.length || output[j + x] === '0')) {\n output = '-1';\n }\n }\n }\n print(output);\n}"}, {"source_code": "var numCases = parseInt(readline());\nfor (var i = 0; i < numCases; i ++) {\n var str = readline();\n var x = parseInt(readline());\n var output = [];\n for (var j = 0; j < str.length; j ++) output.push('1');\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '0') {\n if (j - x >= 0) {\n output[j - x] = '0';\n }\n if (j + x < str.length) {\n output[j + x] = '0';\n }\n }\n }\n for (var j = 0; j < str.length; j ++) {\n if (str[j] === '1') {\n if ((j - x < 0 || output[j - x] === '0') \n && (j + x >= str.length || output[j + x] === '0')) {\n output = ['-1'];\n }\n }\n }\n print(output.join());\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n const w = +readLine();\n const len = str.length;\n\n const arr = [...Array(str.length).fill(-1)];\n let flag = true;\n\n for (let i = 0; i < len; i++) {\n if (str[i] === \"1\") {\n if (i - w >= 0) {\n if (arr[i - w] === 0) {\n flag = false;\n break;\n } else {\n arr[i - w] = 1;\n }\n }\n if (i + w < len) {\n if (arr[i + w] === 0) {\n flag = false;\n break;\n } else {\n arr[i + w] = 1;\n }\n }\n } else {\n if (i - w >= 0) {\n if (arr[i - w] === 1) {\n flag = false;\n break;\n } else {\n arr[i - w] = 0;\n }\n }\n if (i + w < len) {\n if (arr[i + w] === 1) {\n flag = false;\n break;\n } else {\n arr[i + w] = 0;\n }\n }\n }\n }\n\n if (flag) console.log(arr.join(\"\"));\n else console.log(-1);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let s = nextString().split('');\n let x = nextNumber();\n let arr = new Array(s.length).fill('?');\n s.forEach((n, i) => {\n if (n === '0') {\n if (i - x >= 0) {\n arr[i - x] = '0';\n }\n if (i + x < arr.length) {\n arr[i + x] = '0';\n }\n }\n });\n let success = true;\n s.forEach((n, i) => {\n if (n === '1') {\n let any = false;\n if (i - x >= 0 && arr[i - x] !== '0') {\n arr[i - x] = '1';\n any = true;\n }\n // console.log(n, i, i + x, arr[i + x]);\n if (i + x < arr.length && arr[i + x] !== '0') {\n arr[i + x] = '1';\n any = true;\n }\n if (!any) {\n success = false;\n }\n }\n });\n // console.log(arr.join(''));\n if (!success) {\n console.log('-1');\n } else {\n console.log(arr.join(''));\n }\n // 2\n // 10110110\n // ??00?00?\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probB(){\n let t = parseInt(readline());\n\n while(t > 0){\n t--;\n let [p,f] = readline().split(' ');\n let cap = parseInt(p) + parseInt(f);\n\n let [cs, cw] = readline().split(' ');\n let [s, w] = readline().split(' ');\n\n let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));\n\n let tot = parseInt(cs) + parseInt(cw);\n if(cap > ava){\n console.log(tot);\n continue;\n }\n\n let x = Math.min(parseInt(s), parseInt(w));\n if(parseInt(s) === x){\n if(parseInt(cs) * x > cap){\n console.log(Math.floor(cap / parseInt(cs)));\n }else{\n let rem = cap - (x * parseInt(cs));\n console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));\n }\n }else{\n if(parseInt(cw) * x > cap){\n console.log(Math.floor(cap / parseInt(cw)));\n }else{\n let rem = cap - (x * parseInt(cw));\n console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));\n }\n }\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n\n if(i+x >= s.length && i-x < 0){\n isPossible = false;\n break;\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probB(){\n let t = parseInt(readline());\n\n while(t > 0){\n t--;\n let [p,f] = readline().split(' ');\n let cap = parseInt(p) + parseInt(f);\n\n let [cs, cw] = readline().split(' ');\n let [s, w] = readline().split(' ');\n\n let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));\n\n let tot = parseInt(cs) + parseInt(cw);\n if(cap > ava){\n console.log(tot);\n continue;\n }\n\n let x = Math.min(parseInt(s), parseInt(w));\n if(parseInt(s) === x){\n if(parseInt(cs) * x > cap){\n console.log(Math.floor(cap / parseInt(cs)));\n }else{\n let rem = cap - (x * parseInt(cs));\n console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));\n }\n }else{\n if(parseInt(cw) * x > cap){\n console.log(Math.floor(cap / parseInt(cw)));\n }else{\n let rem = cap - (x * parseInt(cw));\n console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));\n }\n }\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n\n if(i+x > s.length && i-x < 0){\n isPossible = false;\n break;\n }\n }\n else{\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n\n if(i+x >= s.length && i-x < 0){\n isPossible = false;\n break;\n }\n }\n else{\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}"}], "src_uid": "02854d98266e5b74bf105ba30ea332df"} {"source_code": "var n = Number(readline().split());\nvar s = readline();\nvar ats = 0;\n\nvar R = -1;\nvar L = -1;\n\nfor(var i=0; i R)ats+=n-L-1;\nif(L==-1 && R==-1)ats = n;\n\nprint(ats);", "positive_code": [{"source_code": "var ans = 0,\n\tn = +readline(),\n\ta = readline().split('');\na.push('R');\nvar f = 0;\nvar c = 0;\nfor (var i = 0; i <= n; i++) {\n\tif (a[i] === 'R') {\n\t\tif (f === 0) {\n\t\t\tans += c;\n\t\t}\n\t\tc = 1;\n\t\tf = 1;\n\t} else if (a[i] === 'L') {\n\t\tif (f === 1 && c % 2 === 0) {\n\t\t\tans++;\n\t\t}\n\t\tc = 0;\n\t\tf = 0;\n\t} else {\n\t\tc++;\n\t}\n}\nprint(ans);"}, {"source_code": ";(function () {\n\n\tprint(function (n, s) {\n\t\treturn -2 +\n\t\t\t(s.match(/R\\.*L/g)||['']).reduce(function (p, e) { return p + (e.length % 2); }, 0) +\n\t\t\t(s.match(/L\\.*R/g)||[' ']).reduce(function (p, e) { return p + (e.length - 2); }, 0) +\n\t\t\t(s.match(/^\\.*R/)||[' '])[0].length +\n\t\t\t(s.match(/L\\.*$/)||[' '])[0].length +\n\t\t\t(s.match(/^\\.*$/)||[''])[0].length;\n\t}(+readline(), readline()));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar s = trim(readline()).split('');\n\n\tvar standing = 0;\n\n\tvar pos = 0;\n\twhile (pos < n && s[pos] == '.') {\n\t\tpos += 1;\n\t}\n\tif (pos == n) {\n\t\tprint(n);\n\t\treturn;\n\t}\n\tif (s[pos] == 'R') {\n\t\tstanding += pos;\n\t}\n\n\twhile (true) {\n\t\tvar seek = pos+1;\n\t\twhile (seek < n && s[seek] == '.') {\n\t\t\tseek += 1;\n\t\t}\n\t\tif (seek == n) {\n\t\t\tif (s[pos] == 'L') {\n\t\t\t\tstanding += n-1-pos;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tif (s[pos] == 'L') {\n\t\t\tstanding += seek-pos-1;\n\t\t}\n\t\telse {\n\t\t\tstanding += (seek-pos-1)%2;\n\t\t}\n\n\t\tpos = seek;\n\t}\n\n\tprint(standing);\n}\n\nmain();\n"}, {"source_code": "readline();\n\nvar s = readline(),\n j,\n ans = 0;\n\ns = 'L' + s + 'R';\n\nfor (var i=0, len=s.length; i R)ats+=n-L;\nif(L==-1 && R==-1)ats = n;\n\nprint(ats);\n"}, {"source_code": "var n = Number(readline().split());\nvar s = readline();\nvar ats = 0;\n\nvar R = -1;\nvar L = -1;\n\nfor(var i=0; i R)ats+=n-L-1;\nif(L==-1 && R==-1)ats = n;\n\nprint(ats);\n"}, {"source_code": "var n = Number(readline().split());\nvar s = readline().split();\nvar ats = 0;\n\nvar R = -1;\nvar L = -1;\n\nfor(var i=0; i R)ats+=n-L-1;\n\nprint(ats);\n"}, {"source_code": "var s = readline(),\n j,\n ans = 0;\n\ns = 'L' + s + 'R';\n\nfor (var i=0, len=s.length; i { return parseInt(x, 10) });\n const maxLeft = Math.min(a,b) - 1, maxRight = n - Math.max(a,b);\n const max = maxLeft + maxRight;\n\n return Math.min(max, x) + Math.abs(b - a);\n}\n\nprocess.stdout.write(`${data.map(find).join('\\n')}`);", "positive_code": [{"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, 'utf-8').split(\"\\r\\n\").filter(data=>{return data.length>0});\ntxt.shift()\ntxt.forEach((data) => {\n let info = data.split(\" \")\n rival(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n})\n\n\nfunction rival(n, x, a, b) {\n if(b>a){\n let i=a;\n a=b;\n b=i;\n }\n while (x > 0) {\n if (a + 1 <= n) {\n ++a;\n } else if (b - 1 > 0) {\n --b;\n } else {\n break;\n }\n --x;\n }\n\n console.log(Math.abs(a - b));\n\n}"}, {"source_code": "var count = Number(readline());\nfor(var i=0; i data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++){\n let [n, x, a, b] = nl.nums();\n let ab = Math.abs(a - b);\n ans.push((ab + x > n - 1)?n-1:ab + x);\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "var num = +readline();\nfor (var i = 0; i < num; i++) {\n var nums = readline().split(' ').map(i => parseInt(i));\n write(Math.min(Math.abs(nums[2] - nums[3]) + nums[1], nums[0] - 1))\n write(\"\\n\")\n}\n\n"}, {"source_code": "// Don't look here. Just some reading API\nfunction onReadable(a,b,c){return()=>{const d=a.read();d&&(b.val=Buffer.concat([b.val,d]));let e=b.val.indexOf(\"\\n\");if(d||(e=b.val.length),-1!==e){const a=b.val.slice(0,e);return b.val=b.val.slice(e+1),c(a.toString(\"utf-8\"))}return a.once(\"readable\",onReadable(a,b,c))}}\nfunction IO(a,b){const c={val:Buffer.from([])};return{async rl(){const b=c.val.indexOf(\"\\n\");if(-1!==b){const a=c.val.slice(0,b);return c.val=c.val.slice(b+1),a.toString(\"ascii\")}return new Promise(b=>a.once(\"readable\",onReadable(a,c,b)))},wr(a){return b.write(a)},wl(a){return b.write(a+\"\\n\")}}}\n(async()=>{const a=IO(process.stdin,process.stdout);return sol(a)})();\n\nasync function sol({ rl, wr, wl }) {\n const t = Number(await rl());\n\n for(let i = 0; i < t; i += 1) {\n let [n, x, a, b] = (await rl()).split(' ').map(Number);\n\n if (b < a) { [b, a] = [a, b]; }\n\n wl(Math.min(a + (n - b) + (b - a) - 1, (b - a) + x));\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const arrT = arr[i].split(' ').map(a => parseInt(a))\n const n = arrT[0]\n let x = arrT[1]\n let a = arrT[2]\n let b = arrT[3]\n\n if(x == 0) {\n console.log(Math.abs(a - b))\n }\n\n else {\n if(a > b) {\n const temp = a\n a = b\n b = temp\n }\n if((a - x) < 1){\n x = x - a + 1\n a = 1\n\n if(b + x >= n) b = n\n else b = b + x\n // console.log(a,b)\n }\n else {\n a = a - x\n // console.log('sf')\n }\n console.log(Math.abs(a - b))\n }\n }\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var x = one[1];\n var a = one[2];\n var b = one[3];\n output[i] = Math.min(n - 1, Math.abs(a - b) + x);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, x, a, b] = d.split(' ').map(Number);\n const min = Math.min(a, b);\n const max = Math.max(a, b);\n const ans = Math.min(n - 1, max - min + x);\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main() {\n const t = +readline();\n for (let i = 0; i < t; i++) {\n const [n, x, a, b] = readline().split(\" \").map(x => parseInt(x));\n console.log(students(n, x, a, b));\n }\n}\n\nconst students = (n, x, a, b) => {\n let p1 = Math.min(a, b);\n let p2 = Math.max(a, b);\n while (x) {\n if (p1 > 1) {\n --p1;\n } else if (p2 < n) {\n ++p2;\n }\n --x;\n }\n return p2 - p1;\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const arrT = arr[i].split(' ').map(a => parseInt(a))\n const n = arrT[0]\n let x = arrT[1]\n let a = arrT[2]\n let b = arrT[3]\n\n if(x == 0) {\n console.log(Math.abs(a - b))\n }\n\n else {\n if(a > b) {\n const temp = a\n a = b\n b = temp\n }\n if(a - x < 1){\n a = 1\n x = x - (a - 1)\n\n if(b + x >= n) b = n\n }\n else {\n a = a - x\n // console.log('sf')\n }\n console.log(Math.abs(a - b))\n }\n }\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const arrT = arr[i].split(' ').map(a => parseInt(a))\n const n = arrT[0]\n let x = arrT[1]\n let a = arrT[2]\n let b = arrT[3]\n\n if(x == 0) {\n console.log(Math.abs(a - b))\n }\n\n else {\n if(a > b) {\n const temp = a\n a = b\n b = temp\n }\n if(a - x < 1){\n a = 1\n x = x - (a - 1)\n\n if(b + x >= n) b = n\n else b = b + x\n }\n else {\n a = a - x\n // console.log('sf')\n }\n console.log(Math.abs(a - b))\n }\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, x, a, b] = d.split(' ').map(Number);\n const min = Math.min(a, b);\n const max = Math.max(a, b);\n const ans = Math.min(99, max - min + x);\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, 'utf-8').split(\"\\r\\n\");\ntxt.forEach((data) => {\n let info = data.split(\" \").filter(data => {\n return data.length > 0\n })\n rival(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n})\n\n\nfunction rival(n, x, a, b) {\n if(b>a){\n let i=a;\n a=b;\n b=i;\n }\n while (x > 0) {\n if (a + 1 <= n) {\n ++a;\n } else if (b - 1 > 0) {\n --b;\n } else {\n break;\n }\n --x;\n }\n\n console.log(Math.abs(a - b));\n\n}"}, {"source_code": "let fs=require('fs');\nlet txt=fs.readFileSync(0,'utf-8').split(\"\\r\\n\");\ntxt.forEach((data)=>{\n rival(data.split(\" \").filter(data=>{return data.length>0}).map(data=>{return data*1}));\n})\n\n\nfunction rival(arr){\n let smallest=Infinity;\n arr.forEach(data=>{\n arr.forEach(data1=>{\n if(Math.abs(data-data1)>0 && Math.abs(data-data1) {\n let info = data.split(\" \").filter(data => {\n return data.length > 0\n })\n rival(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n})\n\n\nfunction rival(n, x, a, b) {\n if(b>a){\n let i=a;\n a=b;\n b=i;\n }\n while (x > 0) {\n if (a + 1 <= n) {\n ++a;\n } else if (b - 1 > 0) {\n --b;\n } else {\n break;\n }\n --x;\n }\n\n console.log(Math.abs(a - b));\n\n}"}, {"source_code": "\nlet fs = require('fs');\nlet txt = fs.readFileSync(0, 'utf-8').split(\"\\r\\n\");\ntxt.shift()\ntxt.forEach((data) => {\n let info = data.split(\" \")\n rival(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n})\n\n\nfunction rival(n, x, a, b) {\n while (x > 0) {\n if (a + 1 <= n) {\n ++a;\n } else if (b - 1 > 0) {\n --b;\n } else {\n break;\n }\n --x;\n }\n\n console.log(Math.abs(a - b));\n\n}"}, {"source_code": "let fs=require('fs');\nlet txt=fs.readFileSync(0,'utf-8').split(\"\\r\\n\");\ntxt.forEach((data)=>{\n let info=data.split(\" \").filter(data=>{return data.length>0})\n rival(info[0]*1,info[1]*1,info[2]*1,info[3]*1);\n})\n\n\nfunction rival(n,x,a,b){\n while (x>0) {\n if(a+1<=n){\n ++a;\n --x;\n }else if(b-1>0){\n --b;\n --x;\n }else{\n break;\n }\n }\n\n console.log(Math.abs(a-b));\n \n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, 'utf-8').split(\"\\r\\n\");\ntxt.shift()\ntxt.forEach((data) => {\n let info = data.split(\" \")\n rival(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n})\n\n\nfunction rival(n, x, a, b) {\n if(b>a){\n let i=a;\n a=b;\n b=i;\n }\n while (x > 0) {\n if (a + 1 <= n) {\n ++a;\n } else if (b - 1 > 0) {\n --b;\n } else {\n break;\n }\n --x;\n }\n\n console.log(Math.abs(a - b));\n\n}"}, {"source_code": "let fs=require('fs');\nlet txt=fs.readFileSync(0,'utf-8').split(\"\\r\\n\");\ntxt.forEach((data)=>{\n rival(data.split(\" \").filter(data=>{return data.length>0}).map(data=>{return data*1}));\n})\n\n\nfunction rival(arr){\n let smallest=-Infinity;\n arr.forEach(data=>{\n arr.forEach(data1=>{\n if(Math.abs(data-data1)>smallest){\n smallest=Math.abs(data-data1);\n }\n })\n })\n console.log(smallest);\n \n return smallest;\n}"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0);\nconst inputString = stdinBuffer.toString();\n\nconst [_, ...data] = inputString.split('\\n');\n\nfunction find(dataString) {\n const [n, x, a, b] = dataString.split(' ').map(x => { return parseInt(x, 10) });\n const maxLeft = Math.min(a,b) - 1, maxRight = n - Math.max(a,b);\n const max = maxLeft + maxRight;\n console.log(n, x, a, b, maxRight, maxLeft, max);\n\n return Math.min(max, x) + Math.abs(b - a);\n}\n\nprocess.stdout.write(`${data.map(find).join('\\n')}`);"}, {"source_code": "var count = Number(readline());\nfor(var i=0; i parseInt(i));\n write(Math.min(Math.abs(nums[2] - nums[3]) + nums[1], nums[0] - 1))\n}"}, {"source_code": "var num = +readline();\nfor (var i = 0; i < num; i++) {\n var nums = readline().split(' ').map(i => parseInt(i));\n write(Math.min(Math.abs(nums[2] - nums[3]) + nums[1], nums[0] - 1))\n}"}], "src_uid": "1fd2619aabf4557093a59da804fd0e7b"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var playes = {}\r\n var a = new Array(m)\r\n var position = new Array(m)\r\n for (let i = 0; i < m; i++) {\r\n a[i] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n a[i].splice(0, 1)\r\n a[i].pos = i\r\n }\r\n// console.log(a)\r\n a = a.sort((a, b) => a.length - b.length)\r\n // console.log(a)\r\n var min\r\n var minI\r\n var value = Math.ceil(m / 2)\r\n var exist = true\r\n var ans = new Array(m).fill(0)\r\n for (let i = 0; i < m; i++) {\r\n min = Number.MAX_SAFE_INTEGER\r\n for (let j = 0; j < a[i].length; j++) {\r\n if (playes[a[i][j]] === undefined) playes[a[i][j]] = 0\r\n if (playes[a[i][j]] < min) {\r\n min = playes[a[i][j]]\r\n minI = a[i][j]\r\n }\r\n }\r\n playes[minI]++\r\n ans[a[i].pos] = minI\r\n if (playes[minI] > value) exist = false\r\n }\r\n if (!exist) return console.log('NO')\r\n console.log('YES')\r\n console.log(ans.join(' '))\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = new Array(M);\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\tvar K = nextInt();\r\n\t\t\tvar c = nextIntArray(K);\r\n\t\t\tlist[j] = {\r\n\t\t\t\tno : j,\r\n\t\t\t\tc : c,\r\n\t\t\t\tsize : K\r\n\t\t\t};\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a.size - b.size;\r\n\t\t});\r\n\t\tvar map = {};\r\n\t\tvar output = new Array(M);\r\n\t\tvar isOK2 = true;\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\tvar c = list[j].c;\r\n\t\t\tvar isOK = false;\r\n\t\t\tfor(var k = 0; k < c.length; k++){\r\n\t\t\t\tif(map[c[k]] == null){\r\n\t\t\t\t\tmap[c[k]] = 0;\r\n\t\t\t\t}\r\n\t\t\t\tif(map[c[k]] < M / 2){\r\n\t\t\t\t\tmap[c[k]]++;\r\n\t\t\t\t\toutput[list[j].no] = c[k];\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(!isOK){\r\n\t\t\t\tisOK2 = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK2){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = new Array(M);\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\tvar K = nextInt();\r\n\t\t\tvar c = nextIntArray(K);\r\n\t\t\tlist[j] = {\r\n\t\t\t\tno : j,\r\n\t\t\t\tc : c,\r\n\t\t\t\tsize : K\r\n\t\t\t};\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a.size - b.size;\r\n\t\t});\r\n\t\tvar map = {};\r\n\t\tvar output = new Array(M);\r\n\t\tvar isOK2 = true;\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\tvar c = list[j].c;\r\n\t\t\tvar isOK = false;\r\n\t\t\tfor(var k = 0; k < c.length; k++){\r\n\t\t\t\tif(map[c[k]] == null){\r\n\t\t\t\t\tmap[c[k]] = 0;\r\n\t\t\t\t}\r\n\t\t\t\tif(map[c[k]] < M / 2){\r\n\t\t\t\t\tmap[c[k]]++;\r\n\t\t\t\t\toutput[list[j].no] = c[k];\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(!isOK){\r\n\t\t\t\tisOK2 = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK2){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var playes = {}\r\n var a = new Array(m)\r\n var position = new Array(m)\r\n for (let i = 0; i < m; i++) {\r\n a[i] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n a[i].pos = i\r\n }\r\n\r\n a = a.sort((a, b) => a.length - b.length)\r\n // console.log(a)\r\n var min\r\n var minI\r\n var value = Math.ceil(m / 2)\r\n var exist = true\r\n var ans = new Array(m).fill(0)\r\n for (let i = 0; i < m; i++) {\r\n min = Number.MAX_SAFE_INTEGER\r\n for (let j = 0; j < a[i].length; j++) {\r\n if (playes[a[i][j]] === undefined) playes[a[i][j]] = 0\r\n if (playes[a[i][j]] < min) {\r\n min = playes[a[i][j]]\r\n minI = a[i][j]\r\n }\r\n }\r\n playes[minI]++\r\n ans[a[i].pos] = minI\r\n if (playes[minI] > value) exist = false\r\n }\r\n if (!exist) return console.log('NO')\r\n console.log('YES')\r\n console.log(ans.join(' '))\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var playes = {}\r\n var a = new Array(m)\r\n for (let i = 0; i < m; i++) {\r\n a[i] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n }\r\n\r\n a = a.sort((a, b) => a.length - b.length)\r\n\r\n var min\r\n var minI\r\n var value = Math.ceil(m / 2)\r\n var exist = true\r\n var ans = []\r\n for (let i = 0; i < m; i++) {\r\n min = Number.MAX_SAFE_INTEGER\r\n for (let j = 0; j < a[i].length; j++) {\r\n if (playes[a[i][j]] === undefined) playes[a[i][j]] = 0\r\n if (playes[a[i][j]] < min) {\r\n min = playes[a[i][j]]\r\n minI = a[i][j]\r\n }\r\n }\r\n playes[minI]++\r\n ans.push(minI)\r\n if (playes[minI] > value) exist = false\r\n }\r\n if(!exist) return console.log('NO')\r\n console.log('YES')\r\n console.log(ans.join(' '))\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}], "src_uid": "1f6be4f0f7d3f9858b498aae1357c2c3"} {"source_code": "function solve() {\n var n = Number(read());\n var a = readArray(function(x, i) {\n return Number(x) === i + 1 ? 1 : 0;\n });\n var l = 0;\n var r = n - 1;\n while(l < n && a[l]) {\n l++;\n }\n while (r >= 0 && a[r]) {\n r--;\n }\n if (l > r) {\n write(0);\n return;\n }\n for (var i = l; i <= r; i++) {\n if (a[i]) {\n write(2);\n return;\n }\n }\n write(1);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let ans = '';\n for(let i = 0; i < n; i++){\n ans += '1 ';\n }\n console.log(ans);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n\n if(n%2===0){\n console.log(n/2, n/2);\n continue;\n }\n\n let sq = Math.floor(Math.sqrt(n));\n let min = 999999999999999;\n let minPair = [];\n for(let i = 1; i <= sq; i++){\n if(n % i === 0){\n let j = n/i;\n let x = n-i;\n let y = n-j;\n\n if(x % i === 0){\n if(min > Math.max(x,i)){\n min = Math.max(x,i);\n minPair = [i,x]\n }\n }\n\n if(y % j === 0){\n if(min > Math.max(j,y)){\n min = Math.max(j,y);\n minPair = [j,y]\n }\n }\n }\n }\n console.log(minPair[0], minPair[1]);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = new Array(600000);\n\n let b = JSON.parse(JSON.stringify(a));\n b.sort((a,b) => a-b);\n for(let i = 0; i < n; i++)\n map[b[i]] = i;\n\n let pre = -1;\n let ans = -1;\n for(let i = 0; i < n; i++){\n if(map[a[i]] !== i){\n if(pre === -1)\n pre = i;\n else{\n if(pre === i-1){\n pre = i;\n ans = 1;\n }else{\n ans = 2;\n break;\n }\n }\n }\n }\n\n if(ans === -1)\n console.log(0);\n else\n console.log(ans);\n }\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n\n let [l, r] = cut(a);\n\n let result = 0;\n for(let i = l; i < r; i++) {\n if (a[i] > a[i+1]) {\n result = 1;\n }\n }\n if (result === 1) {\n a.forEach((x, i) => {\n if (l <= i && i <= r) {\n if (x === i+1) {\n result = 2;\n } \n }\n });\n }\n\n print(result);\n }\n}\n\nfunction cut(a) {\n let l = 0,\n r = a.length -1,\n b = [];\n while (a[l] === l+1) a[l++] = 0;\n while (a[r] === r+1) a[r--] = 0;\n return [l, r];\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}], "negative_code": [{"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n\n let result = 0;\n for(let i = 0; i+1 < a.length; i++) {\n if (a[i] > a[i+1]) {\n result = 1;\n }\n }\n if (result === 1) {\n a.forEach((x, i) => {\n if (x === i) {\n result = 2;\n }\n });\n }\n\n print(result);\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n\n let result = 0;\n for(let i = 0; i+1 < a.length; i++) {\n if (a[i] > a[i+1]) {\n result = 2;\n }\n }\n\n print(result);\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n\n let result = 0;\n for(let i = 0; i+1 < a.length; i++) {\n if (a[i] > a[i+1]) {\n result = 1;\n }\n }\n if (result === 1) {\n a.forEach((x, i) => {\n if (x === i+1) {\n result = 2;\n }\n });\n }\n\n print(result);\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let ans = '';\n for(let i = 0; i < n; i++){\n ans += '1 ';\n }\n console.log(ans);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n\n if(n%2===0){\n console.log(n/2, n/2);\n continue;\n }\n\n let sq = Math.floor(Math.sqrt(n));\n let min = 9999999999999;\n let minPair = [];\n for(let i = 1; i <= sq; i++){\n if(n % i === 0){\n let x = n/i;\n let b = (x-1)*i;\n if(i+b === n){\n if(min > b){\n min = b;\n minPair = [i,b];\n }\n }\n }\n }\n console.log(minPair[0], minPair[1]);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = new Array(600000);\n\n let b = JSON.parse(JSON.stringify(a));\n b.sort((a,b) => a-b);\n for(let i = 0; i < n; i++)\n map[b[i]] = i;\n\n let preCount = 0;\n let count = 0;\n let flag = false;\n for(let i = 0; i < n; i++){\n if(i === map[a[i]]){\n if(preCount === 1){\n if(!flag)\n count += 1;\n flag = true;\n }else if(preCount !== 0){\n count += 1;\n preCount = 0;\n }\n }else{\n preCount += 1;\n flag = false;\n }\n }\n console.log(count);\n }\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ').map(function(x, i) {\n return Number(x) === i + 1 ? 1 : 0;\n });\n var d = 1;\n var ans = 0;\n var i = 0;\n var j = n - 1;\n while(i <= j) {\n while (i < n && a[i] === d) {\n i++;\n }\n while (j >= 0 && a[j] === d) {\n j--;\n }\n if (i <= j) {\n ans++;\n }\n d = 1 - d;\n }\n write(ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ').map(function(x, i) {\n return Number(x) === i + 1 ? 1 : 0;\n });\n var d = 1;\n var ans = 0;\n for (var i = 0; i < n; i++) {\n if (a[i] !== d) {\n d = 1 - d;\n ans++;\n }\n }\n write(ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "src_uid": "a98f67141b341152fcf20d803cbd5409"} {"source_code": "'use strict'\n\nconst problem = (n, x, s) => {\n let r = +!x, y = 0\n const t = s.reduce((a, b) => a + b, 0)\n for (let i = 0; i < n; i++) {\n y += s[i];\n if (y === x) {\n if (!t) return -1\n r += 1\n } else if ((x - y) * t > 0 && (x - y) % t === 0) r += 1\n }\n return r\n}\n\nlet t = +readline()\nwhile(t--) {\n const nx = readline().split(' ').map(i => +i);\n const s = readline().split('').map(i => i === '0' ? 1 : -1);\n print(problem(nx[0], nx[1], s));\n}\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, x] = readInts()\n const s = readString()\n let c0 = 0, c1 = 0\n let count = x === 0 ? 1 : 0\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') c0++\n else c1++\n }\n let b = c0 - c1\n let r = 0\n if(b === 0) {\n let f = false\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') r++\n else r--\n if(r === x){\n wr(-1)\n f = true\n break\n }\n }\n if(!f) wr(0)\n }\n else {\n r = 0\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') r++\n else r--\n if((x - r) % b === 0 && (x - r) / b >= 0) {\n count++\n }\n }\n wr(count)\n }\n }\n}"}, {"source_code": "T=+readline()\nfunction gcd(a,b){\n if (!b)\n return a;\n return gcd(b,a%b)\n}\nfor (t=0;t=0){\n ++ans\n }\n }\n }\n print(ans)\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, x, s) => {\n s = s.map(i => i === '1' ? -1 : 1);\n let r = {}, p = 0;\n for (let i = 0; i < n; i++) { p += s[i]; if (r[p]) r[p]++; else r[p] = 1 }\n let max = -1, min = 1\n Object.keys(r).forEach(i => {\n if (i < min) min = i;\n if (i > max) max = i;\n })\n\n if (p > 0 && x < min) return +!x;\n if (p < 0 && x > max) return 0;\n if (p === 0) if (x >= min && x <= max) return -1; else return 0;\n\n const a = Math.ceil((x - max-1)/p);\n const b = Math.ceil((x - min-1)/p);\n\n let res = 0;\n for (let i = a - 1; i <= b + 1; i++) {\n res += r[x - i*p] || 0;\n }\n return res;\n}\nlet t = +readline()\nwhile(t--) {\n const nx = readline().split(' ').map(i => +i);\n print(problem(nx[0], nx[1], readline().split('')));\n}\n"}, {"source_code": "'use strict'\n\nconst problem = (n, x, s) => {\n s = s.map(i => i === '1' ? -1 : 1);\n let r = {}, p = 0;\n for (let i = 0; i < n; i++) { p += s[i]; if (r[p]) r[p]++; else r[p] = 1 }\n let max = -1, min = 1\n Object.keys(r).forEach(i => {\n if (i < min) min = i;\n if (i > max) max = i;\n })\n\n if (p > 0 && x < min) return +!x;\n if (p < 0 && x > max) return 0;\n if (p === 0) if (x >= min && x <= max) return -1; else return 0;\n\n const a = Math.ceil((x - max-1)/p);\n const b = Math.ceil((x - min-1)/p);\n\n\n let res = 0;\n for (let i = a; i <= b; i++) {\n res += r[x - i*p];\n }\n return res;\n}\nlet t = +readline()\nwhile(t--) {\n const nx = readline().split(' ').map(i => +i);\n print(problem(nx[0], nx[1], readline().split('')));\n}\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let i = 0\n let t = readInt(input, i++)\n while(t--) {\n let [n, x] = readInts(input, i++)\n const s = input[i++]\n const len = s.length\n let c0 = 0, c1 = 0\n for (let j = 0; j < len; j++) {\n if(s[j] == '0') c0++\n else c1++\n }\n\n if(c0 > c1 && x < 0) wr('0')\n else if(c0 < c1 && x > 0) wr('0')\n else if(c0 === c1 && x !== 0) wr('0')\n else if(c0 === c1 && x === 0) wr(-1)\n else if((c0 === 0 || c1 === 0) && x !== 0) wr(-1)\n else {\n // wr('j')\n let count = 0\n if(x < 0) {\n x = -x\n let t = c0\n c0 = c1\n c1 = t\n }\n let r = x % (c0 - c1)\n let qu = Math.floor(x / (c0 - c1))\n let cc1 = qu * c1\n let cc0 = qu * c0\n let k = 0\n if(cc0 - cc1 === x) count ++\n while(k < len) {\n // console.log(\"c\", count, cc0, cc1)\n if(s[k] == '0') cc0++\n else cc1++\n if(cc0 - cc1 === x) count ++\n k++\n }\n k = len - 1\n cc1 = qu * c1\n cc0 = qu * c0\n while(k >= 0) {\n // console.log(\"c\", count, cc0, cc1)\n if(s[k] == '0') cc0--\n else cc1--\n if(cc0 - cc1 === x) count ++\n k--\n }\n wr(count)\n\n }\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, x] = readInts()\n const s = readString()\n let c0 = 0, c1 = 0\n let count = x === 0 ? 1 : 0\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') c0++\n else c1++\n }\n let b = c0 - c1\n let r = 0\n if(b === 0) {\n let f = false\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') r++\n else r--\n if(r === x){\n wr(-1)\n f = true\n break\n }\n }\n if(!f) wr(0)\n }\n else {\n r = 0\n for(let i = 0; i < n; i++) {\n if(s[i] === '0') r++\n else r--\n if((x - r) % b === 0 && (x - r) / b > 0) {\n count++\n }\n }\n wr(count)\n }\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let i = 0\n let t = readInt(input, i++)\n while(t--) {\n let [n, x] = readInts(input, i++)\n let s = input[i++]\n const len = s.length\n let c0 = 0, c1 = 0\n for (let j = 0; j < len; j++) {\n if(s[j] == '0') c0++\n else c1++\n }\n\n if(c0 > c1 && x < 0) wr('0')\n else if(c0 < c1 && x > 0) wr('0')\n else if(c0 === c1 && x !== 0) wr('0')\n else if(c0 === c1 && x === 0) wr(-1)\n else if((c0 === 0 || c1 === 0) && x !== 0) wr(0)\n else {\n // wr('j')\n let count = 0\n if(x < 0) {\n x = -x\n let t = c0\n c0 = c1\n c1 = t\n let s2 = []\n for (let j = 0; j < len; j++) {\n if(s[j] == '0') s2.push('1')\n else s2.push('0')\n }\n s = s2.join('')\n }\n let r = x % (c0 - c1)\n let qu = Math.floor(x / (c0 - c1))\n let cc1 = qu * c1\n let cc0 = qu * c0\n let k = 0\n if(cc0 - cc1 === x) count ++\n while(k < len) {\n // console.log(\"c\", count, cc0, cc1, s)\n if(s[k] == '0') cc0++\n else cc1++\n if(cc0 - cc1 === x) count ++\n k++\n }\n k = len - 1\n cc1 = qu * c1\n cc0 = qu * c0\n while(k >= 0) {\n // console.log(\"c\", count, cc0, cc1)\n if(s[k] == '0') cc0--\n else cc1--\n if(cc0 - cc1 === x) count ++\n k--\n }\n wr(count)\n\n }\n }\n}"}], "src_uid": "389be6455476db86a8a5d9d5343ee35a"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\trNum = data[0], cNum = data[1], snakeNum = data[2],\n\t\tcells = rNum*cNum, snakeLen = Math.floor(cells/snakeNum),\n\t\tresult = [], r = 0, c = -1, dir = +1;\n\tfor (var i = 0; i < snakeNum; ++i) {\n\t\tvar len = (i == snakeNum-1 ? cells : snakeLen),\n\t\t\tsnake = new Array(2*len+1);\n\t\tsnake[0] = len;\n\t\tcells -= len;\n\t\tfor (var j = 0; j < len; ++j) {\n\t\t\tif (dir == +1) {\n\t\t\t\tif (c == cNum-1) {\n\t\t\t\t\t++r;\n\t\t\t\t\tdir = -1;\n\t\t\t\t} else {\n\t\t\t\t\tc += 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (c == 0) {\n\t\t\t\t\t++r;\n\t\t\t\t\tdir = +1;\n\t\t\t\t} else {\n\t\t\t\t\tc -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tsnake[2*j+1] = r+1;\n\t\t\tsnake[2*j+2] = c+1;\n\t\t}\n\t\tresult.push(snake.join(' '));\n\t}\n\tprint(result.join('\\n'));\n}\n\nmain();\n", "positive_code": [{"source_code": "var nextToken = new function() {\n var line = [];\n var lineIndex = 0;\n\n return function() {\n while (lineIndex >= line.length) {\n line = readline().split(/\\s+/);\n lineIndex = 0;\n }\n \n return line[lineIndex++];\n }\n}();\n\nvar nextInt = function() {\n return parseInt(nextToken(), 10);\n};\n\nvar createMatrix = function (n, m, e) {\n var i, j;\n var a = [], b;\n\n for (i = 0; i < n; ++i) {\n b = [];\n for (j = 0; j < m; ++j) {\n b.push(e);\n }\n a.push(b);\n }\n\n return a;\n}\n\nvar dx = [0, 1, 0, -1];\nvar dy = [1, 0, -1, 0];\n\nvar fill = function(n, m, a, x, y, e, cnt) {\n var i, dir, nx, ny, good;\n var result = [];\n for (i = 0; i < cnt; ++i) {\n a[x][y] = e;\n result.push(x + 1);\n result.push(y + 1);\n\n if (i + 1 < cnt) {\n good = false;\n for (dir = 0; dir < 4; ++dir) {\n nx = x + dx[dir];\n ny = y + dy[dir];\n\n if (0 <= nx && nx < n && 0 <= ny && ny < m && a[nx][ny] == -1) {\n x = nx;\n y = ny;\n good = true;\n break;\n }\n }\n\n if (!good) {\n throw \"FAIL!\";\n }\n }\n }\n return result;\n}\n\nvar main = function () {\n var n = nextInt(); \n var m = nextInt();\n var a = createMatrix(n, m, -1);\n \n var go = fill(n, m, createMatrix(n, m, -1), 0, 0, 0, n * m);\n var cnt = nextInt();\n var left = n * m;\n\n var x, y, cur, i;\n for (i = 0; i < go.length; i += 2) {\n x = go[i] - 1;\n y = go[i + 1] - 1;\n //print(x + \", \" + y);\n if (a[x][y] === -1) {\n if (cnt == 1) {\n cur = fill(n, m, a, x, y, cnt, left);\n } else {\n cur = fill(n, m, a, x, y, cnt, 2);\n left -= 2;\n cnt--;\n }\n print((cur.length / 2) + \" \" + cur.join(\" \"));\n }\n }\n\n};\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\trNum = data[0], cNum = data[1], snakeNum = data[2],\n\t\tcells = rNum*cNum, snakeLen = Math.ceil(cells/snakeNum),\n\t\tresult = [], r = 0, c = -1, dir = +1;\n\tfor (var i = 0; i < snakeNum; ++i) {\n\t\tvar len = Math.min(snakeLen, cells),\n\t\t\tsnake = new Array(2*len+1);\n\t\tsnake[0] = len;\n\t\tcells -= len;\n\t\tfor (var j = 0; j < len; ++j) {\n\t\t\tif (dir == +1) {\n\t\t\t\tif (c == cNum-1) {\n\t\t\t\t\t++r;\n\t\t\t\t\tdir = -1;\n\t\t\t\t} else {\n\t\t\t\t\tc += 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (c == 0) {\n\t\t\t\t\t++r;\n\t\t\t\t\tdir = +1;\n\t\t\t\t} else {\n\t\t\t\t\tc -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tsnake[2*j+1] = r+1;\n\t\t\tsnake[2*j+2] = c+1;\n\t\t}\n\t\tresult.push(snake.join(' '));\n\t}\n\tprint(result.join('\\n'));\n}\n\nmain();\n"}], "src_uid": "779e73c2f5eba950a20e6af9b53a643a"} {"source_code": "print(function(s) {\n\tvar i, j,\n\t\tl = s.length,\n\t\tisP = [];\n\n\tfor (i = 0; i < l; i++)\n\t\tisP[i] = [];\n\n\tfor (i = 0; i < l; i++)\n\t\tfor (j = 0; j < l; j++)\n\t\t\tisP[i][j] = 0;\n\n\tisP[0][0] = 1;\n\n\n\tfor (i = l; i >= 0; i--)\n\t\tfor (j = i; j < l; j++)\n\t\t\tif (s[i] === s[j])\n\t\t\t\tisP[i][j] = j - i > 1 ? isP[i + 1][j - 1] : 1;\n\t\t\telse\n\t\t\t\tisP[i][j] = 0;\n\n\tvar sum = [1];\n\tfor (j = 1; j < l; j++) {\n\t\tsum[j] = sum[j - 1];\n\t\tfor (i = 0; i <= j; i++)\n\t\t\tsum[j] += isP[i][j];\n\t}\n\n\tvar ans = 0;\n\tfor (j = 1; j < l; j++)\n\t\tfor (i = 1; i <= j; i++)\n\t\t\tif (isP[i][j] === 1)\n\t\t\t\tans += sum[i - 1];\n\n\treturn ans;\n}(readline()));", "positive_code": [{"source_code": "print(function(s) {\n\tvar i, j,\n\t\tl = s.length,\n\t\tisP = [];\n\n\tfor (i = 0; i < l; i++)\n\t\tisP[i] = new Int8Array(l);\n\n\tisP[0][0] = 1;\n\n\n\tfor (i = l; i >= 0; i--)\n\t\tfor (j = i; j < l; j++)\n\t\t\tif (s[i] === s[j])\n\t\t\t\tisP[i][j] = j - i > 1 ? isP[i + 1][j - 1] : 1;\n\t\t\telse\n\t\t\t\tisP[i][j] = 0;\n\n\tvar sum = [1];\n\tfor (j = 1; j < l; j++) {\n\t\tsum[j] = sum[j - 1];\n\t\tfor (i = 0; i <= j; i++)\n\t\t\tsum[j] += isP[i][j];\n\t}\n\n\tvar ans = 0;\n\tfor (j = 1; j < l; j++)\n\t\tfor (i = 1; i <= j; i++)\n\t\t\tif (isP[i][j] === 1)\n\t\t\t\tans += sum[i - 1];\n\n\treturn ans;\n}(readline()));"}, {"source_code": "print(function(s) {\n\tvar i, j,\n\t\tl = s.length,\n\t\tisP = [];\n\n\tfor (i = 0; i < l; i++)\n\t\tisP[i] = [];\n\n\tfor (i = 0; i < l; i++)\n\t\tfor (j = 0; j < l; j++)\n\t\t\tisP[i][j] = 0;\n\n\tisP[0][0] = 1;\n\n\n\tfor (i = l; i >= 0; i--)\n\t\tfor (j = i; j < l; j++)\n\t\t\tif (s[i] === s[j])\n\t\t\t\tisP[i][j] = j - i > 1 ? isP[i + 1][j - 1] : 1;\n\t\t\telse\n\t\t\t\tisP[i][j] = 0;\n\n\tvar sum = [1];\n\tfor (j = 1; j < l; j++) {\n\t\tvar count = 0;\n\t\tfor (i = 0; i <= j; i++) {\n\t\t\tcount += isP[i][j];\n\t\t}\n\t\tsum[j] = sum[j - 1] + count;\n\t}\n\n\tvar ans = 0;\n\tfor (j = 1; j < l; j++) {\n\t\tfor (i = 1; i <= j; i++) {\n\t\t\tif (isP[i][j] === 1) {\n\t\t\t\tans += sum[i - 1];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ans;\n}(readline()));"}], "negative_code": [], "src_uid": "1708818cf66de9fa03439f608c897a90"} {"source_code": "var qq = readline().split(\" \").map(function(x) { return parseInt(x); });\n//var numbers = prompt(\"Enter data: \").split(\" \").map(function(x) { return parseInt(x); }); // Chrome run\n\nvar N = qq[0];\nvar K = qq[1];\n\nvar uron = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar st = readline();\n\nvar p_sum = Array(N).fill(0);\np_sum[0] = uron[0];\nfor (var i=1; i=ww.length-K; pp--) mx += ww[pp];\n\t}\n\n\tglob += mx;\n} while (k < N);\n\nwrite(glob);", "positive_code": [{"source_code": "(function() {\n var t = readline().split(' ');\n var n = +t[0];\n var q = +t[1];\n var u = readline().split(' ');\n var b = readline().split('');\n\n var bs = [];\n var bsi = -1;\n\n var dmg = 0;\n\n var lastb = '';\n for(var i = 0; i < n; i++) {\n if(lastb === b[i]) {\n bs[bsi].push(+u[i]);\n }\n else {\n bsi++;\n bs[bsi] = [+u[i]];\n }\n lastb = b[i];\n }\n\n\n for(var j = 0; j< bs.length; j++) {\n var g = bs[j];\n if(g.length <= q) {\n for(var i = 0; i < g.length; i++) {\n dmg += g[i];\n }\n }\n else {\n g.sort((a,b) => b - a);\n for(var i = 0; i < q; i++) {\n dmg += g[i];\n }\n }\n }\n print(dmg);\n}());\n\n\n"}], "negative_code": [{"source_code": "(function() {\n var t = readline().split(' ');\n var n = +t[0];\n var q = +t[1];\n var u = readline().split(' ');\n var b = readline().split('');\n\n var bs = {};\n var dmg = 0;\n\n for(var i = 0; i < n; i++) {\n if(bs[b[i]]) {\n bs[b[i]].push(+u[i]);\n }\n else {\n bs[b[i]] = [+u[i]];\n }\n }\n \n for(var bi in bs) {\n var g = bs[bi];\n \n if(g.length <= q) {\n for(var i = 0; i < g.length; i++) {\n dmg += g[i];\n }\n }\n else {\n g = g.sort(function(a, b) {\n return b - a;\n });\n print(g);\n for(var i = 0; i < q; i++) {\n dmg += g[i];\n }\n }\n }\n print(dmg);\n}());\n"}, {"source_code": "(function() {\n var t = readline().split(' ');\n var n = +t[0];\n var q = +t[1];\n var u = readline().split(' ');\n var b = readline().split('');\n\n var bs = {};\n var dmg = 0;\n\n for(var i = 0; i < n; i++) {\n if(bs[b[i]]) {\n bs[b[i]].push(+u[i]);\n }\n else {\n bs[b[i]] = [+u[i]];\n }\n }\n \n for(var bi in bs) {\n var g = bs[bi];\n \n if(g.length <= q) {\n for(var i = 0; i < g.length; i++) {\n dmg += g[i];\n }\n }\n else {\n g = g.sort(function(a, b) {\n return b - a;\n });\n for(var i = 0; i < q; i++) {\n dmg += g[i];\n }\n }\n }\n print(dmg);\n}());\n"}], "src_uid": "aa3b5895046ed34e89d5fcc3264b3944"} {"source_code": "function resolve(s, p, q) {\n var res = [];\n var k = 1;\n // case 1\n while (k <= s.length / p) {\n var r = (s.length - k * p) % q;\n if (r === 0) {\n var i = 1;\n while (i <= k) {\n res.push(s.substring((i - 1) * p, i * p));\n i++;\n }\n i = 1;\n while (i <= (s.length - k * p) / q) {\n res.push(s.substr(k * p + (i - 1) * q, q));\n i++;\n }\n return res;\n }\n k++;\n }\n\n // case 2\n k = 1;\n while (k <= s.length / q) {\n var r = (s.length - k * q) % p;\n if (r === 0) {\n var i = 1;\n while (i <= k) {\n res.push(s.substring((i - 1) * q, i * q));\n i++;\n }\n i = 1;\n while (i <= (s.length - k * q) / p) {\n res.push(s.substr(k * q + (i - 1) * p, p));\n i++;\n }\n return res;\n }\n k++;\n }\n return -1;\n}\n\n/*console.log(\n resolve('XCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu', 16, 3)\n);*/\n\nconst z = readline().split(' ');\nconst s = readline();\nconst res = resolve(s, parseInt(z[1], 10), parseInt(z[2], 10));\nif (res === -1) {\n print(res);\n} else {\n print(res.length);\n for (var i = 0; i < res.length; i++) {\n print(res[i]);\n }\n}\n", "positive_code": [{"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n\n var n = arr[0],\n p = arr[1],\n q = arr[2];\n\n var str = readline();\n\n\n var flag=false;\n\n for (var i = 0; i <= n; i++) {\n for (var j = 0; j <= n; j++) {\n if ((i * p + j * q) == n) {\n print(i+j);\n var m;\n for(m=0;m=n;n++){if(e*n>r)return[-1,0];var i=Math.floor((r-e*n)/t);if(n*e+i*t===r)return[n,i]}return[-1,0]}function resout(r,e,t,n,i){if(print(n+i),-1!==n){for(var u=0;n>u;u++)print(r.substr(0,e)),r=r.substr(e);for(var u=0;i>u;u++)print(r.substr(0,t)),r=r.substr(t)}}var u=calculate(r,e,n),a=t(u,2),o=a[0],c=a[1];resout(i,e,n,o,c)}var t=function(){function sliceIterator(r,e){var t=[],n=!0,i=!1,u=void 0;try{for(var a,o=r[Symbol.iterator]();!(n=(a=o.next()).done)&&(t.push(a.value),!e||t.length!==e);n=!0);}catch(c){i=!0,u=c}finally{try{!n&&o.return&&o.return()}finally{if(i)throw u}}return t}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return sliceIterator(r,e);throw new TypeError(\"Invalid attempt to destructure non-iterable instance\")}}(),n=readline().split(\" \").map(function(r){return parseInt(r)}),i=t(n,3),u=i[0],a=i[1],o=i[2],c=readline();solve(u,a,o,c)}]);"}, {"source_code": "// https://codeforces.com/contest/612/problem/A\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\n\nconst getXY = (n, p, q) => {\n const isFit = (m, r) => (m % r) === 0;\n const nFits = (m, r) => Math.floor(m / r);\n const getFits = (m, a, b) => {\n for (let aX = nFits(m, a); aX > -1; aX--) {\n const mN = m - (a * aX);\n if (isFit(mN, b)) {\n return [aX, nFits(mN, b)];\n }\n }\n return [0, 0];\n };\n\n let x, y;\n if (Math.max(p, q) === p) {\n ([x, y] = getFits(n, p, q));\n } else {\n ([y, x] = getFits(n, q, p));\n }\n return {x, y};\n};\n\nexports.solveProblem = (lineList) => {\n const [n, p, q] = lineList[0].split(' ').map((v) => parseInt(v));\n const s = lineList[1];\n\n let {x, y} = getXY(n, p, q);\n let idx = 0;\n const lst = [];\n for (let i = 0; i < x; i++) {\n lst.push(s.slice(idx, idx + p));\n idx += p;\n }\n\n for (let i = 0; i < y; i++) {\n lst.push(s.slice(idx, idx + q));\n idx += q;\n }\n\n if (lst.length < 1) {\n return '-1';\n }\n return `${lst.length}\\n${lst.join('\\n')}`;\n};\n\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}, {"source_code": "var npq = readline().split(' ').map(Number);\nvar n = npq[0];\nvar p = npq[1];\nvar q = npq[2];\nvar s = readline();\nvar k = -1;\nvar np = 0;\nvar nq = 0;\nif (n%p == 0) {\n\tk = n/p;\n\tnp = k;\n} else if (n%q == 0){\n\tk = n/q;\n\tnq = k;\n} else {\n\t\tfor (var i=1; i +i);\nvar n = input[0];\nvar p = input[1];\nvar q = input[2];\nvar s = readline();\n\nvar pCount = 0;\nvar qCount = 0;\nvar maxQCount = Math.floor(n/q);\nvar noCombination = true;\nfor (; qCount <= maxQCount; ++qCount) {\n if ((n - qCount*q)%p === 0) {\n pCount = (n - qCount*q) / p;\n noCombination = false;\n break;\n } \n}\nif (noCombination) {\n print(-1);\n} else {\n var output = pCount + qCount + \"\\n\";\n for (var i = 0; i < pCount; ++i) {\n for (var j = 0; j < p; ++j) {\n output += s.charAt(j+p*i);\n }\n output += \"\\n\";\n }\n for (var i = 0; i < qCount; ++i) {\n for (var j = 0; j < q; ++j) {\n output += s.charAt(j+q*i+p*pCount);\n }\n output += \"\\n\";\n }\n print(output);\n}"}], "negative_code": [{"source_code": "function resolve(s, p, q) {\n var res = [];\n var i = 1;\n // case 1\n var r1 = s.length % p;\n var r2 = r1 % q;\n if (r2 === 0) {\n while (i <= s.length / p) {\n res.push(s.substring((i - 1) * p, i * p));\n i++;\n }\n i = 1;\n while (i <= r1 / q) {\n res.push(s.substr(Math.floor(s.length / p) * p + (i - 1) * q, q));\n i++;\n }\n return res;\n }\n // case 2\n r1 = s.length % q;\n r2 = r1 % p;\n if (r2 === 0) {\n while (i <= s.length / q) {\n res.push(s.substring((i - 1) * q, i * q));\n i++;\n }\n i = 1;\n while (i <= r1 / p) {\n res.push(s.substr(Math.floor(s.length / q) * q + (i - 1) * p, p));\n i++;\n }\n return res;\n }\n return -1;\n}\n\n//console.log(resolve('abacabac', 1, 1));\n\nconst z = readline().split(' ');\nconst s = readline();\nconst res = resolve(s, parseInt(z[1], 10), parseInt(z[2], 10));\nif (res === -1) {\n print(res);\n} else {\n print(res.length);\n for (var i = 0; i < res.length; i++) {\n print(res[i]);\n }\n}\n"}, {"source_code": "function resolve(s, p, q) {\n var res = [];\n var i = 1;\n // case 1\n var r1 = s.length % p;\n var r2 = r1 % q;\n if (r2 === 0) {\n while (i <= s.length / p) {\n res.push(s.substring((i - 1) * p, i * p));\n i++;\n }\n i = 1;\n while (i <= r1 / q) {\n res.push(s.substr(Math.floor(s.length / p) * p + (i - 1) * q, q));\n i++;\n }\n return res;\n }\n // case 2\n r1 = s.length % q;\n r2 = r1 % p;\n if (r2 === 0) {\n while (i <= s.length / q) {\n res.push(s.substring((i - 1) * q, i * q));\n i++;\n }\n i = 1;\n while (i <= r1 / p) {\n res.push(s.substr(Math.floor(s.length / q) * q + (i - 1) * p, p));\n i++;\n }\n return res;\n }\n return -1;\n}\n\n//console.log(resolve('abacabac', 1, 1));\n\nconst z = readline().split(' ');\nconst s = readline();\nconst res = resolve(s, parseInt(z[1], 10), parseInt(z[2], 10));\nprint(res.length);\nfor (var i = 0; i < res.length; i++) {\n print(res[i]);\n}\n"}, {"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n\n var n = arr[0],\n p = arr[1],\n q = arr[2];\n\n var str = readline();\n\n\n var flag=false;\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++) {\n if ((i * p + j * q) == n) {\n print(i+j);\n var m;\n for(m=0;m=n;n++){if(t*n>r)return[-1,0];var i=Math.floor((r-t*n)/e);if(n*t+i*e===r)return[n,i]}return[-1,0]}function resout(r,t,e,n,i){if(print(n+i),-1!==n){for(var u=0;n>u;u++)print(r.substr(0,t)),r=r.substr(t);for(var u=0;i>u;u++)print(r.substr(0,e)),r=r.substr(e)}}var u=calculate(r,t,n),a=e(u,2),o=a[0],c=a[1];print(\"nsp=\"+o+\" nsq=\"+c),resout(i,t,n,o,c)}var e=function(){function sliceIterator(r,t){var e=[],n=!0,i=!1,u=void 0;try{for(var a,o=r[Symbol.iterator]();!(n=(a=o.next()).done)&&(e.push(a.value),!t||e.length!==t);n=!0);}catch(c){i=!0,u=c}finally{try{!n&&o.return&&o.return()}finally{if(i)throw u}}return e}return function(r,t){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return sliceIterator(r,t);throw new TypeError(\"Invalid attempt to destructure non-iterable instance\")}}(),n=readline().split(\" \").map(function(r){return parseInt(r)}),i=e(n,3),u=i[0],a=i[1],o=i[2],c=readline();solve(u,a,o,c)}]);"}, {"source_code": "!function(r){function __webpack_require__(t){if(e[t])return e[t].exports;var n=e[t]={exports:{},id:t,loaded:!1};return r[t].call(n.exports,n,n.exports,__webpack_require__),n.loaded=!0,n.exports}var e={};return __webpack_require__.m=r,__webpack_require__.c=e,__webpack_require__.p=\"\",__webpack_require__(0)}([function(r,e,t){r.exports=t(1)},function(r,e){\"use strict\";function solve(r,e,n,i){function calculate(r,e,t){for(var n=1;r>=n;n++){if(e*n>r)return[-1,0];var i=Math.floor((r-e*n)/t);if(n*e+i*t===r)return[n,i]}return[-1,0]}function resout(r,e,t,n,i){if(print(n+i),-1!==n){for(var u=0;n>u;u++)print(r.substr(0,e)),r=r.substr(e);for(var u=0;i>u;u++)print(r.substr(0,t)),r=r.substr(t)}}var u=calculate(r,e,n),a=t(u,2),o=a[0],c=a[1];resout(i,e,n,o,c)}var t=function(){function sliceIterator(r,e){var t=[],n=!0,i=!1,u=void 0;try{for(var a,o=r[Symbol.iterator]();!(n=(a=o.next()).done)&&(t.push(a.value),!e||t.length!==e);n=!0);}catch(c){i=!0,u=c}finally{try{!n&&o.return&&o.return()}finally{if(i)throw u}}return t}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return sliceIterator(r,e);throw new TypeError(\"Invalid attempt to destructure non-iterable instance\")}}(),n=readline().split(\" \").map(function(r){return parseInt(r)}),i=t(n,3),u=i[0],a=i[1],o=i[2],c=readline();solve(u,a,o,c)}]);"}, {"source_code": "var input = readline().split(\" \").map(i => +i);\nvar n = input[0];\nvar p = input[1];\nvar q = input[2];\nvar s = readline();\n\nvar pCount = 0;\nvar qCount = 0;\nvar maxQCount = Math.floor(n/q);\nvar noCombination = true;\nfor (; qCount <= maxQCount; ++qCount) {\n if ((n - qCount*q)%p === 0) {\n pCount = (n - qCount*q) / p;\n noCombination = false;\n break;\n } \n}\nif (noCombination) {\n print(-1);\n} else {\n var output = pCount + qCount + \"\\n\";\n for (var i = 0; i < pCount; ++i) {\n for (var j = 0; j < p; ++j) {\n output += s.charAt(i+j);\n }\n output += \"\\n\";\n }\n for (var i = 0; i < qCount; ++i) {\n for (var j = 0; j < q; ++j) {\n output += s.charAt(i+j+pCount*p);\n }\n output += \"\\n\";\n }\n print(output);\n}"}, {"source_code": "const getXY = (n, p, q) => {\n const pR = n % p;\n const qR = n % q;\n\n if (pR === 0) {\n return {\n x: Math.floor(n / p),\n y: 0\n };\n }\n\n if (qR === 0) {\n return {\n x: 0,\n y: Math.floor(n / q)\n };\n }\n\n x = Math.floor(n / p);\n n = n - (x * p);\n if (n % q > 0) {\n return {\n x: 0,\n y: 0\n };\n }\n\n return {\n x,\n y: Math.floor(n / q)\n };\n};\n\nconst processInput = ([n, p, q, s]) => {\n let {x, y} = getXY(n, p, q);\n\n let idx = 0;\n const lst = [];\n for (let i = 0; i < x; i++) {\n lst.push(s.slice(idx, idx + p));\n idx += p;\n }\n\n for (let i = 0; i < y; i++) {\n lst.push(s.slice(idx, idx + q));\n idx += q;\n }\n\n if (lst.length < 1) {\n process.stdout.write('-1');\n return;\n }\n\n process.stdout.write(`${lst.length}\\n${lst.join('\\n')}`);\n};\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n let [one, two] = chunkList.join('').trim().split('\\n');\n one = one.split(' ');\n one = one.map((v) => parseInt(v));\n processInput([...one, two]);\n process.exit(0);\n });\n})();"}, {"source_code": "const getXY = (n, p, q) => {\n const pR = n % p;\n const qR = n % q;\n\n if (pR === 0) {\n return {\n x: Math.floor(n / p),\n y: 0\n };\n }\n\n if (qR === 0) {\n return {\n x: 0,\n y: Math.floor(n / q)\n };\n }\n\n if (Math.max(p, q) === p) {\n x = Math.floor(n / p);\n let nn = n - (x * p);\n if (nn % q > 0) {\n return {\n x: 0,\n y: 0\n };\n }\n\n return {\n x,\n y: Math.floor(nn / q)\n };\n }\n\n let y = Math.floor(n / q);\n let nn = n - (y * q);\n if (nn % p > 0) {\n return {\n x: 0,\n y: 0\n };\n }\n\n return {\n x: Math.floor(nn / p),\n y\n };\n};\n\nconst processInput = ([n, p, q, s]) => {\n let {x, y} = getXY(n, p, q);\n\n let idx = 0;\n const lst = [];\n for (let i = 0; i < x; i++) {\n lst.push(s.slice(idx, idx + p));\n idx += p;\n }\n\n for (let i = 0; i < y; i++) {\n lst.push(s.slice(idx, idx + q));\n idx += q;\n }\n\n if (lst.length < 1) {\n process.stdout.write('-1');\n return;\n }\n\n process.stdout.write(`${lst.length}\\n${lst.join('\\n')}`);\n};\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n let [one, two] = chunkList.join('').trim().split('\\n');\n one = one.split(' ');\n one = one.map((v) => parseInt(v));\n processInput([...one, two]);\n process.exit(0);\n });\n})();"}, {"source_code": "// https://codeforces.com/contest/612/problem/A\n\nconst processInput = (solveProblem) => {\n const chunkList = [];\n process.stdin.setEncoding('utf8');\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n const lineList = chunkList.join('').split('\\n');\n const result = solveProblem(lineList);\n process.stdout.write(result);\n process.exit(0);\n });\n};\n\nconst getXY = (n, p, q) => {\n const isFit = (m, r) => (m % r) === 0;\n const nFits = (m, r) => Math.floor(m / r);\n const getFits = (m, a, b) => {\n let aX = nFits(m, a);\n let mN = m - (a * aX);\n if (isFit(mN, b)) {\n return [aX, nFits(mN, b)];\n }\n\n aX = Math.max(aX - 1, 0);\n mN = m - (a * aX);\n if (isFit(mN, b)) {\n return [aX, nFits(mN, b)];\n }\n\n return [0, 0];\n };\n\n let x, y;\n if (Math.max(p, q) === p) {\n ([x, y] = getFits(n, p, q));\n } else {\n ([y, x] = getFits(n, q, p));\n }\n return {x, y};\n};\n\nexports.solveProblem = (lineList) => {\n const [n, p, q] = lineList[0].split(' ').map((v) => parseInt(v));\n const s = lineList[1];\n\n let {x, y} = getXY(n, p, q);\n let idx = 0;\n const lst = [];\n for (let i = 0; i < x; i++) {\n lst.push(s.slice(idx, idx + p));\n idx += p;\n }\n\n for (let i = 0; i < y; i++) {\n lst.push(s.slice(idx, idx + q));\n idx += q;\n }\n\n if (lst.length < 1) {\n return '-1';\n }\n return `${lst.length}\\n${lst.join('\\n')}`;\n};\n\nif (module === require.main) {\n processInput(exports.solveProblem);\n}"}], "src_uid": "c4da69789d875853beb4f92147825ebf"} {"source_code": "(function main(){\n \n var tiempoRequerido = readline().split(\" \")[1];\n var tiemposTrabajadosPorDia = readline().split(\" \");\n\n var tiemposSobrantesPorDia = calcularTiempoSobrantePorDia();\n function calcularTiempoSobrantePorDia(){\n var tiemposSobrantesPorDia = [];\n for (var i = 0; i < tiemposTrabajadosPorDia.length; i++) {\n tiemposSobrantesPorDia[i] = 86400 - tiemposTrabajadosPorDia[i];\n }\n return tiemposSobrantesPorDia;\n }\n \n function calcularDiasNecesarios(){\n var diasNecesarios = 0;\n var segundosAcumulados = 0; \n for (var i = 0; i < tiemposSobrantesPorDia.length; i++) {\n diasNecesarios++;\n segundosAcumulados += tiemposSobrantesPorDia[i];\n if(segundosAcumulados >= tiempoRequerido){\n break;\n }\n }\n return diasNecesarios;\n }\n \n write(calcularDiasNecesarios());\n})();\n", "positive_code": [{"source_code": "var input1=readline().split(\" \");//reads the 1st input line to array \nvar a=readline().split(\" \");//reads the 2nd input line to array a\n\nvar n=input1[0];\nvar t=parseInt(input1[1]);\nvar totalTime=t;\nvar prevTime=0;\nconst maxSecsPerDay=86400;\nvar noOfDays=0;\n\nfor(var i=0;i {\n if (c === 0) {\n [n, t] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n let freeTime = 0;\n let ans = 1;\n const arr = d.split(' ').map(Number);\n\n for (let i = 0; i < arr.length; i++) {\n freeTime += daySeconds - arr[i];\n\n if (freeTime >= t) {\n ans += i;\n break;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nt=+s[1]\na=readline().split(' ').map(function(x){return +x;})\nfor (i=1;i<=n;i++)\n{\n t-=(86400-a[i-1]);\n if (t<=0)\n {\n print(i)\n break\n }\n}"}, {"source_code": "function toInt(x) {\n\treturn parseInt(x);\n}\n\nvar n = readline().split(' ').map(toInt);\nvar t = [n[1], n = n[0]][0];\nvar ar = readline().split(' ').map(toInt);\nvar res = 0;\n\nfor (var i = 0; i < ar.length; i++) {\n\tres += (86400 - ar[i]);\n\tif (res >= t) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "n_t =readline().split(' ');\na =readline().split(' ');\nans=0;\nfor(var i of a){\n n_t[1]-=86400-i;ans++;\n if(n_t[1]<=0){print(ans);break;}\n}\n"}, {"source_code": "n_t =readline().split(' ');\na =readline().split(' ');\nans=0;\nfor(var i of a){\n n_t[1]-=86400-i;ans++;\n if(n_t[1]<=0){print(ans);break;}\n}"}], "negative_code": [{"source_code": "(function main(){\n \n var tiempoRequerido = readline().split()[1];\n var tiemposTrabajadosPorDia = readline().split();\n\n var tiemposSobrantesPorDia = calcularTiempoSobrantePorDia();\n function calcularTiempoSobrantePorDia(){\n var tiemposSobrantesPorDia = [];\n for (var i = 0; i < tiemposTrabajadosPorDia.length; i++) {\n tiemposSobrantesPorDia[i] = 86400 - tiemposTrabajadosPorDia[i];\n }\n return tiemposSobrantesPorDia;\n }\n \n function calcularDiasNecesarios(){\n var diasNecesarios = 0;\n var segundosAcumulados = 0; \n for (var i = 0; i < tiemposSobrantesPorDia.length; i++) {\n diasNecesarios++;\n segundosAcumulados += tiemposSobrantesPorDia[i];\n if(segundosAcumulados >= tiempoRequerido){\n break;\n }\n }\n return \"diasNecesarios:\" + diasNecesarios +\";segundosAcumulados:\" + segundosAcumulados +\n \"tiemporequerido: \" + tiempoRequerido;\n \n }\n \n write(calcularDiasNecesarios());\n\n})();\n"}, {"source_code": "(function main(a, b){\n \n var tiempoRequerido = readline().split()[1];\n var tiemposTrabajadosPorDia = readline().split();\n\n// var tiempoRequerido = a.split(\" \")[1];\n// var tiemposTrabajadosPorDia = b.split(\" \");\n\n var tiemposSobrantesPorDia = calcularTiempoSobrantePorDia();\n function calcularTiempoSobrantePorDia(){\n var tiemposSobrantesPorDia = [];\n for (var i = 0; i < tiemposTrabajadosPorDia.length; i++) {\n tiemposSobrantesPorDia[i] = 86400 - tiemposTrabajadosPorDia[i];\n }\n return tiemposSobrantesPorDia;\n }\n \n function calcularDiasNecesarios(){\n var diasNecesarios = 0;\n var segundosAcumulados = 0; \n for (var i = 0; i < tiemposSobrantesPorDia.length; i++) {\n diasNecesarios++;\n segundosAcumulados += tiemposSobrantesPorDia[i];\n if(segundosAcumulados >= tiempoRequerido){\n break;\n }\n }\n return diasNecesarios;\n }\n \n write(calcularDiasNecesarios());\n// console.log(calcularDiasNecesarios());\n})();\n\n//main(\"2 86400\", \"86369 86369 86369 86369 86369 86355\");"}, {"source_code": "var input1=readline().split(\" \");//reads the 1st input line to array \nvar a=readline().split(\" \");//reads the 2nd input line to array a\n\nvar n=input1[0];\nvar t=parseInt(input1[1]);\nconst maxSecsPerDay=86400;\nvar noOfDays=0;\n\nfor(var i=0;i {\n const n = ls.length;\n const m = target + 1;\n const dp = new Uint8Array(n * m);\n const _ = (i, j) => i * m + j;\n\n dp[_(0, 0)] = 1;\n if (ls[0] < m) {\n dp[_(0, ls[0])] = 1;\n }\n\n for (let i = 1; i < n; i++) {\n for (let j = 0; j < m; j++) {\n let x = dp[_(i - 1, j)];\n if (ls[i] <= j) {\n x |= dp[_(i - 1, j - ls[i])];\n }\n dp[_(i, j)] = x;\n }\n }\n\n return dp[_(n - 1, target)];\n};\n\nconst solve = (ls, debug = 0) => {\n const n = ls.length;\n\n // Make cumulative max and indices where cummax changes\n const cm = new Int32Array(n);\n const cm_id = [];\n // const cm_id_diff = [];\n let m = 0;\n for (let i = 0; i < n; i++) {\n if (ls[i] > m) {\n cm_id.push(i);\n m = ls[i];\n }\n cm[i] = m;\n }\n\n // Each region where cummax is same belong to same \"unmerged\" side\n const cm_id_diff = new Int32Array(cm_id.length);\n for (let i = 0; i < cm_id.length - 1; i++) {\n cm_id_diff[i] = cm_id[i + 1] - cm_id[i];\n }\n cm_id_diff[cm_id.length - 1] = n - cm_id.slice(-1)[0];\n\n if (debug) {\n console.log(ls, cm, cm_id, cm_id_diff);\n }\n\n // Find parition which makes \"unmerged\" pair same length\n const result = find_subset_v2(cm_id_diff, n / 2);\n return result ? 'YES' : 'NO';\n};\n\nconst main = async (istr, ostr) => {\n const readline = require('readline');\n const it = readline.createInterface({input: istr})[Symbol.asyncIterator]();\n const next = async () => (await it.next()).value;\n const t = Number(await next());\n for (let i = 0; i < t; i++) {\n await next();\n const ls = new Int32Array((await next()).split(' ').map(Number));\n ostr.write(`${solve(ls)}\\n`);\n }\n};\n\nif (require.main === module) {\n process.stdin.setEncoding('utf8');\n main(process.stdin, process.stdout);\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n const ps = readLine().split(/\\s/).map(Number)\n let chunks = ps.map(value => ({ value, count: 1 }))\n while (true) {\n let chunkAdded = false\n chunks = chunks.reduce((acc, curr, i) => {\n if (i === 0) {\n acc[0] = curr\n } else if (acc[acc.length - 1].value > curr.value) {\n acc[acc.length - 1].count += 1 \n chunkAdded = true\n } else {\n acc[acc.length] = curr\n }\n return acc\n }, [])\n if (!chunkAdded) {\n break\n }\n }\n chunks = chunks.map(({ count }) => count)\n let qs = []\n let yes = false\n for (const c of chunks) {\n if (c === n) {\n yes = true\n break\n }\n qs = qs.reduce((acc, curr, i) => {\n acc[i] = curr\n const v = i + c\n if (v <= n) {\n acc[v] = true\n }\n return acc\n }, [])\n if (qs[n]) {\n yes = true\n break\n }\n qs[c] = true\n }\n console.log(yes ? 'YES' : 'NO')\n }\n}\n"}], "negative_code": [], "src_uid": "2d1db83f1eb921f830cc9c709f9327fa"} {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet t = +readline();\r\nwhile (t--) {\r\n let length = +readline();\r\n let arr = readline().split(' ').map(i => +i);\r\n let map = {};\r\n let counts = {};\r\n arr.forEach(num => {\r\n if (!map[num]) map[num] = 0;\r\n map[num]++;\r\n })\r\n for (let i in map) {\r\n let count = map[i];\r\n if (!counts[count]) counts[count] = 0\r\n counts[count] += 1;\r\n }\r\n let nums = Object.keys(counts).map(i => +i).sort((a, b) => a - b);\r\n let min = 10000000;\r\n for(let i in nums) {\r\n let num = nums[i];\r\n let remove = 0;\r\n for(let key in counts) {\r\n let kk = +key;\r\n let kkCount = counts[kk];\r\n if (kk < num) {\r\n remove += kkCount * kk\r\n } else if (kk > num) {\r\n remove += kkCount * (kk - num);\r\n }\r\n }\r\n if (remove < min) min = remove;\r\n }\r\n console.log(min)\r\n}", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 2e5 + 1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tconst mp = new Map();\r\n\t\tfor (const e of a) {\r\n\t\t\tmp.set(e, mp.has(e) ? mp.get(e) + 1 : 1);\r\n\t\t}\r\n\r\n\t\tconst frq = Array.from(mp.values());\r\n\t\tfrq.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = INF;\r\n\t\tfor (let i = 0; i < frq.length; i++) {\r\n\t\t\tans = Math.min(ans, n - (frq.length - i) * frq[i]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var s = new Array(n + 1).fill(0)\r\n\r\n //\r\n var count = {}\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n for (let i = 0; i < n; i++) {\r\n if (!count[a[i]]) count[a[i]] = 0\r\n count[a[i]]++\r\n }\r\n var map2 = {}\r\n Object.keys(count).map(key => {\r\n if (!map2[count[key]]) map2[count[key]] = 0\r\n map2[count[key]]++\r\n\r\n })\r\n var keys = Object.keys(map2).map(x => parseInt(x)).sort((a, b) => map2[a] - map2[b])\r\n\r\n var sum = new Array(keys.length + 1).fill(0)\r\n\r\n var ans = n\r\n for (let i = 0; i < keys.length; i++) {\r\n sum = 0\r\n for (let j = 0; j < keys.length; j++) {\r\n if(keys[j]keys[i]) sum+=(keys[j] - keys[i])* map2[keys[j]]\r\n }\r\n ans = Math.min(ans, sum)\r\n }\r\n // console.log(keys)\r\n // console.log(map2)\r\n // console.log(sum)\r\n console.log(ans)\r\n\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet t = +readline();\r\nwhile (t--) {\r\n let length = +readline();\r\n let arr = readline().split(' ').map(i => +i);\r\n let map = {};\r\n let counts = {};\r\n arr.forEach(num => {\r\n if (!map[num]) map[num] = 0;\r\n map[num]++;\r\n })\r\n for (let i in map) {\r\n let count = map[i];\r\n if (!counts[count]) counts[count] = 0\r\n counts[count] += count;\r\n }\r\n let nums = Object.keys(counts).map(i => +i).sort((a, b) => a - b);\r\n let min = 10000000;\r\n for(let i in nums) {\r\n let num = nums[i];\r\n let result = 0;\r\n for(let key in counts) {\r\n let kk = +key;\r\n let kkCount = counts[kk];\r\n if (kk < num) {\r\n result += kkCount\r\n } else if (kk > num) {\r\n result += kkCount - num;\r\n }\r\n }\r\n if (result < min) min = result;\r\n }\r\n //\r\n // console.log({nums, map, counts})\r\n // console.log('----------')\r\n console.log(min)\r\n}"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet t = +readline();\r\nwhile (t--) {\r\n let length = +readline();\r\n let arr = readline().split(' ').map(i => +i);\r\n let map = {};\r\n let cc = {};\r\n arr.forEach(num => {\r\n if (!map[num]) map[num] = 0;\r\n map[num]++;\r\n })\r\n Object.keys(map).map(i => +i).forEach(num => {\r\n if (!cc[num]) cc[num] = 0;\r\n cc[num] += map[num];\r\n })\r\n let counts = {}\r\n Object.values(cc).map(i => +i).forEach(count => {\r\n if (!counts[count]) counts[count] = 0;\r\n counts[count] += count;\r\n })\r\n\r\n let max = -1\r\n let val = 0;\r\n Object.keys(counts).map(i => +i).forEach(key => {\r\n if (counts[key] > max) {\r\n max = counts[key]\r\n val = key;\r\n }\r\n })\r\n\r\n let add = 0;\r\n Object.keys(map).map(i => +i).forEach(num => {\r\n if (map[num] > val) {\r\n add += map[num] - val;\r\n } else if (map[num] < val){\r\n add += map[num]\r\n }\r\n })\r\n console.log(add)\r\n}"}], "src_uid": "aab052bf49da6528641f655342fa4848"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n let sum = 0;\n let f = true;\n let f2 = false;\n for(let i = 0; i < n; i++){\n if(a[i] !== x)\n f = false;\n\n if(a[i] === x)\n f2 = true;\n \n sum += a[i] - x;\n }\n\n if(f){\n console.log(0);\n }else if(sum === 0 || f2){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n}", "positive_code": [{"source_code": "function mlt() { return readline().split(' ').map(x => parseInt(x)) }\n\nfunction solv() {\n\n var inp = mlt()\n var x = inp[0]\n var y = inp[1]\n\n var s = mlt()\n\n var vis = {}\n for (var n = 0; n < x; n++)vis[s[n]] = (vis[s[n]] == null ? 1 : vis[s[n]] + 1)\n if (vis[y] == x) {\n print(0)\n return\n }\n else if (vis[y] >= 1) {\n print(1)\n return\n }\n var sm = 0;\n for (var n = 0; n < x; n++)sm += s[n] - y;\n if (sm == 0) {\n print(1);\n }\n else print(2)\n}\n\nvar tc = 1;\ntc = parseInt(readline());\nwhile (tc--) solv()"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var [n, x] = inputs[i * 2 + 1].split(' ').map(v => +v);\n var arr = inputs[i * 2 + 2].split(' ').map(v => +v);\n if (arr.every(v => v == x)) {\n console.log(0);\n }\n else if (arr.some(v => v == x) || arr.sum() == n * x) {\n console.log(1);\n }\n else {\n console.log(2);\n }\n }\n return;\n var p = [2];\n for (let i = 3; i < 1e5; i += 2) {\n let prime = true;\n for (let v of p) {\n if (v * v > i)\n break;\n if (i % v == 0) {\n prime = false;\n break;\n }\n }\n if (prime)\n p.push(i);\n }\n for (let i = 0; i < t; i++) {\n var x = +inputs[i + 1];\n var c = Array(p.length).fill(0);\n for (let j = 0;; j++) {\n if (p[j] > x)\n break;\n while (x % p[j] == 0) {\n x /= p[j];\n c[j]++;\n }\n }\n var cp = c.map((v, i) => v ? p[i] : 0).filter(v => v);\n c = c.filter(v => v);\n if (c.length == 1) {\n console.log(Array(c[0]).fill(0).map((v, i) => cp[0] ** (i + 1)).join(' '));\n console.log(0);\n }\n else {\n let mark = {};\n let arr = [];\n for (let i = 0; i < c.length; i++) {\n let bit = Array(c.length).fill(0);\n bit[i] = 1;\n arr.push(bit);\n mark[bit.join('')] = 1;\n bit = Array(c.length).fill(0);\n bit[i] = 1;\n bit[(i + 1) % c.length] = 1;\n arr.push(bit);\n mark[bit.join('')] = 1;\n }\n let c2 = 2 ** c.length;\n while (arr.length < c2 - 1) {\n for (let i = 1; i < c2; i++) {\n let bit = Array(c.length).fill(0);\n for (let j = 0; j < c.length; j++)\n bit[j] = i & (1 << j) ? 1 : 0;\n if (mark[bit.join('')])\n continue;\n if (bit.some((v, i) => arr[arr.length - 1][i] == v)) {\n arr.push(bit);\n mark[bit.join('')] = 1;\n }\n }\n }\n console.log(arr);\n console.log(0);\n }\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}], "negative_code": [{"source_code": "function mlt() { return readline().split(' ').map(x => parseInt(x)) }\n\nfunction solv() {\n\n var inp = mlt()\n var x = inp[0]\n var y = inp[1]\n\n var s = mlt()\n\n var vis = {}\n for (var n = 0; n < x; n++)vis[s[n]] = (vis[s[n]] == null ? 1 : vis[s[n]] + 1)\n if (vis[y] == x) {\n print(0)\n return\n }\n else if (vis[x] >= 1) {\n print(1)\n return\n }\n var sm = 0;\n for (var n = 0; n < x; n++)sm += s[n] - y;\n if (sm == 0) {\n print(1);\n }\n else print(2)\n}\n\nvar tc = 1;\ntc = parseInt(readline());\nwhile (tc--) solv()"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var [n, x] = inputs[i * 2 + 1].split(' ').map(v => +v);\n var arr = inputs[i * 2 + 2].split(' ').map(v => +v);\n if (arr.every(v => v == x)) {\n console.log(0);\n }\n else if (arr.sum() == n * x) {\n console.log(1);\n }\n else {\n console.log(2);\n }\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var [n, x] = inputs[i * 2 + 1].split(' ').map(v => +v);\n var arr = inputs[i * 2 + 2].split(' ').map(v => +v);\n if (arr.every(v => v == x)) {\n console.log(0);\n }\n else if (arr.some(v => v == n) || arr.sum() == n * x) {\n console.log(1);\n }\n else {\n console.log(2);\n }\n }\n return;\n var p = [2];\n for (let i = 3; i < 1e5; i += 2) {\n let prime = true;\n for (let v of p) {\n if (v * v > i)\n break;\n if (i % v == 0) {\n prime = false;\n break;\n }\n }\n if (prime)\n p.push(i);\n }\n for (let i = 0; i < t; i++) {\n var x = +inputs[i + 1];\n var c = Array(p.length).fill(0);\n for (let j = 0;; j++) {\n if (p[j] > x)\n break;\n while (x % p[j] == 0) {\n x /= p[j];\n c[j]++;\n }\n }\n var cp = c.map((v, i) => v ? p[i] : 0).filter(v => v);\n c = c.filter(v => v);\n if (c.length == 1) {\n console.log(Array(c[0]).fill(0).map((v, i) => cp[0] ** (i + 1)).join(' '));\n console.log(0);\n }\n else {\n let mark = {};\n let arr = [];\n for (let i = 0; i < c.length; i++) {\n let bit = Array(c.length).fill(0);\n bit[i] = 1;\n arr.push(bit);\n mark[bit.join('')] = 1;\n bit = Array(c.length).fill(0);\n bit[i] = 1;\n bit[(i + 1) % c.length] = 1;\n arr.push(bit);\n mark[bit.join('')] = 1;\n }\n let c2 = 2 ** c.length;\n while (arr.length < c2 - 1) {\n for (let i = 1; i < c2; i++) {\n let bit = Array(c.length).fill(0);\n for (let j = 0; j < c.length; j++)\n bit[j] = i & (1 << j) ? 1 : 0;\n if (mark[bit.join('')])\n continue;\n if (bit.some((v, i) => arr[arr.length - 1][i] == v)) {\n arr.push(bit);\n mark[bit.join('')] = 1;\n }\n }\n }\n console.log(arr);\n console.log(0);\n }\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n let sum = 0;\n let f = true;\n for(let i = 0; i < n; i++){\n if(a[i] !== x)\n f = false;\n \n sum += a[i] - x;\n }\n\n if(f){\n console.log(0);\n }else if(sum === 0){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n}"}], "src_uid": "475a24d36eab99ae4f78815ccdc5da91"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\r\n\t\tif (a > b) {\r\n\t\t\t[a, b] = [b, a];\r\n\t\t}\r\n\r\n\t\tconst k = b-a>>1;\r\n\t\tlet ans = Math.min(a, b-a>>1);\r\n\t\tans += a-ans>>1;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet [a, b] = nl.nums();\n \t\tif (a * 3 >= b && b * 3 >= a) {\n\t\t\tans.push(Math.trunc((a + b) / 4));\n\t\t} else {\n\t\t\tans.push(Math.min(a, b));\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n fileContents\n .map(solveLine)\n .forEach(x => console.log(x))\n}\n\nfunction solveLine(programmersAndMaths){\n const maths = parseInt(programmersAndMaths.split(\" \")[0],10)\n const programmers = parseInt(programmersAndMaths.split(\" \")[1],10)\n // console.log(\"xxxxx\", maths, programmers, programmersAndMaths)\n\n\n if(programmers/3 > maths){\n return maths;\n }else if(maths/3 > programmers){\n return programmers\n }else{\n return Math.floor((maths+programmers)/4)\n }\n}\n"}, {"source_code": "// const rl = require('readline-sync');\r\n// const { stdin: input, stdout: output } = require('process');\r\n\r\n// //const rl = readline.createInterface({ input, output });\r\n// const arrayJan=[]\r\n// const t= parseInt(rl.question(''))\r\n// for (let i=1;i<=t;i++) {\r\n// arrayJan.push(rl.question()) \r\n// }\r\n\r\n// // const arrayStyle = [3876,387,4489,3]\r\n// // const n = 122345\r\n// arrayJan.map((n)=>{\r\n// const nString = n.toString()\r\n// const lastNumber = parseInt(nString[nString.length-1])\r\n// const firstNumber = parseInt(nString[0])\r\n// const evenInside = ()=>{\r\n// for (let i=0;i +x);\r\n let min = Math.min(temp[0], temp[1]);\r\n let top = Math.floor((+temp[0] + +temp[1]) / 4);\r\n if (console.log(Math.min(top, min)) !== undefined) console.log(0);\r\n }\r\n process.exit(0);\r\n});\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b]) {\r\n const c = Math.floor((a + b) / 4)\r\n const d = Math.min(a, b)\r\n if (d >= c) {\r\n console.log(c)\r\n } else {\r\n console.log(d)\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar team = Math.min(A, B);\r\n\t\tA -= team;\r\n\t\tB -= team;\r\n\t\tvar ok = 0;\r\n\t\tok += Math.min(Math.floor(A / 2), team);\r\n\t\tok += Math.min(Math.floor(B / 2), team);\r\n\t\tteam -= ok;\r\n\t\tok += Math.floor(team / 2);\r\n\t\tmyout(ok);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n if (a > b) return solve(b, a)\n const d = b - a\n let ans = 0\n let x = Math.floor(d / 2)\n x = Math.min(a, x)\n a -= x\n b -= 3 * x\n ans += x\n ans += Math.floor(Math.min(a, b) / 2)\n return ans\n // return Math.min(a, Math.floor(b / 3))\n}\n"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \").sort((a, b) => a - b);\r\n a = +s[0];\r\n b = +s[1];\r\n print((a + Math.min(b, 3 * a)) >> 2);\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n let min = Math.min(a, b);\r\n let max = Math.max(a, b);\r\n let result = 0;\r\n let value;\r\n\r\n while (min > 0 && max - min >= 3) {\r\n value = Math.min(\r\n min,\r\n Math.floor((max - min) / 3)\r\n );\r\n\r\n min -= value;\r\n max -= value * 3;\r\n result += value;\r\n }\r\n\r\n if (min > 0) {\r\n if (max - min >= 2 && min % 2 === 1) {\r\n result++;\r\n }\r\n\r\n result += Math.floor(min / 2);\r\n }\r\n\r\n console.log(result);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n\r\n var a = inp[0];\r\n var b = inp[1];\r\n var ans = Math.min(Math.min(a, b), (a + b) / 4);\r\n return Math.floor(ans);\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n\r\n var a = inp[0];\r\n var b = inp[1];\r\n var d = 0;\r\n\r\n if (a == b) {\r\n return (a + b) / 4;\r\n } else if (a > b) {\r\n d = a - b;\r\n a -= d;\r\n d /= 2;\r\n d = Math.min(a, d);\r\n a -= d;\r\n b -= d;\r\n d += (a + b) / 4;\r\n return d;\r\n } else {\r\n d = b - a;\r\n b -= d;\r\n d /= 2;\r\n d = Math.min(a, d);\r\n a -= d;\r\n b -= d;\r\n d += (a + b) / 4;\r\n return d;\r\n }\r\n }\r\n\r\n while (t--) {\r\n print(Math.floor(solve()));\r\n }"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let t = readline();\n while(t > 0){\n let val = readline().split(\" \").map(x => parseInt(x));\n let a = parseInt(val[0]);\n let b = parseInt(val[1]);\n if( a/3 > b){\n console.log(b);\n }else if(b/3 > a){\n console.log(a);\n }else{\n console.log(Math.floor((a + b)/4));\n }\n\n t--;\n } \n\n}\n\n\n\n"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t \tvar k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], d = 0;\n if(a == b){\n console.log(Math.floor((a + b) / 4));\n }else if(a > b){\n d = a - b;\n a -= d;\n d /= 2;\n d = Math.min(a, d);\n a -= d;\n b -= d;\n d += (a + b) / 4;\n console.log(Math.floor(d));\n }else{\n d = b - a;\n b -= d;\n d /= 2;\n d = Math.min(a, d);\n a -= d;\n b -= d;\n d += (a + b) / 4;\n console.log(Math.floor(d));\n }\n\t}\n});\n\n"}], "negative_code": [{"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n let min = Math.min(a, b);\r\n let max = Math.max(a, b);\r\n let result = 0;\r\n let value;\r\n\r\n if (min * 3 <= max) {\r\n console.log(min);\r\n return;\r\n }\r\n\r\n if (max - min > 2) {\r\n value = Math.ceil((max - min) / 3);\r\n\r\n min -= value;\r\n max -= value * 3;\r\n result += value;\r\n }\r\n\r\n value = Math.floor(min / 2);\r\n result += value;\r\n\r\n if (min % 2 === 1 && max - value * 2 >= 3) {\r\n result++;\r\n }\r\n\r\n console.log(result);\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n let min = Math.min(a, b);\r\n let max = Math.max(a, b);\r\n let value = Math.min(min, Math.floor((max - min) / 3));\r\n let result = 0;\r\n\r\n min -= value;\r\n max -= value * 3;\r\n result += value;\r\n\r\n if (min > 0) {\r\n if (max - min >= 3) {\r\n result++;\r\n min -= 1;\r\n max -= 3;\r\n }\r\n\r\n if (min % 2 === 1 && max - min >= 2) {\r\n result++;\r\n }\r\n\r\n result += Math.floor(min / 2);\r\n }\r\n\r\n console.log(result);\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let alternative1 = Math.floor(min / 2);\r\n let alternative2 = Math.min(min, Math.floor(max / 3));\r\n\r\n if ((max - alternative1 * 2) >= 3 && (min - alternative1 * 2) === 1) {\r\n alternative1++;\r\n }\r\n\r\n if ((max - alternative2 * 3) >= 2 && (min - alternative2) >= 2) {\r\n alternative2++;\r\n } else if ((max - alternative2 * 3) >= 3 && (min - alternative2) >= 1) {\r\n alternative2++;\r\n } else if ((max - alternative2 * 3) >= 1 && (min - alternative2) >= 3) {\r\n alternative2++;\r\n }\r\n\r\n console.log(Math.max(alternative1, alternative2));\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let alternative1 = Math.floor(min / 2);\r\n let alternative2 = Math.min(min, Math.floor(max / 3));\r\n\r\n if ((max - alternative1 * 2) >= 3 && (min - alternative1 * 2) === 1) {\r\n alternative1++;\r\n }\r\n\r\n if ((max - alternative2 * 3) >= 2 && (min - alternative2) >= 2) {\r\n alternative2++;\r\n } else if ((max - alternative2 * 3) >= 3 && (min - alternative2) >= 1) {\r\n alternative2++;\r\n }\r\n\r\n console.log(Math.max(alternative1, alternative2));\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let alternative1 = Math.floor(min / 2);\r\n let alternative2 = Math.min(min, Math.floor(max / 3));\r\n\r\n if ((max - alternative1 * 2) === 3 && (min - alternative1 * 2) === 1) {\r\n alternative1++;\r\n }\r\n\r\n if ((max - alternative2 * 3) % 3 > 1 && min - alternative2 > 0) {\r\n alternative2++;\r\n }\r\n\r\n console.log(Math.max(alternative1, alternative2));\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let alternative1 = Math.floor(min / 2);\r\n let alternative2 = Math.min(min, Math.floor(max / 3));\r\n\r\n if ((max - alternative1 * 2) === 3 && min - alternative1 > 0) {\r\n alternative1++;\r\n }\r\n\r\n if ((max - alternative2 * 3) % 3 > 1 && min - alternative2 > 0) {\r\n alternative2++;\r\n }\r\n\r\n console.log(Math.max(alternative1, alternative2));\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let alternative1 = Math.floor(min / 2);\r\n let alternative2 = Math.min(min, Math.floor(max / 3));\r\n\r\n if ((max - alternative2 * 3) % 3 > 1 && min - alternative2 > 0) {\r\n alternative2++;\r\n }\r\n\r\n console.log(Math.max(alternative1, alternative2));\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, b;\r\n\r\n while (T--) {\r\n [a, b] = lines[index++].split(' ').map(Number);\r\n solve(a, b);\r\n }\r\n}\r\n\r\nfunction solve(a, b) {\r\n const min = Math.min(a, b);\r\n const max = Math.max(a, b);\r\n let result;\r\n\r\n result = Math.max(\r\n Math.floor(min / 2),\r\n Math.min(min, Math.floor(max / 3))\r\n );\r\n\r\n console.log(result);\r\n}\r\n"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n\nfunction recursive(a,b){\n if( a == b){\n return Math.floor(a/2);\n }else{\n let div2, div3;\n div2 = Math.min(Math.floor(a/2),Math.floor(b/2));\n if(a > b){\n div3 = Math.min(Math.floor(a/3),Math.floor(b/1));\n }else{\n div3 = Math.min(Math.floor(a/1),Math.floor(b/3));\n \n }\n if(div2>= div3){\n let tempNum = div2*2;\n let tempA = a - tempNum ;\n let tempB = b - tempNum ;\n if(tempA > 0 && tempB > 0 && (tempA + tempB >=4)){\n return div2+ recursive(tempA,tempB);\n }else{\n return div2;\n }\n }else{\n return div3;\n }\n }\n}\n\nfunction main() {\n let t = readline();\n while(t--){\n let val = readline().split(\" \").map(x => parseInt(x));\n let a = parseInt(val[0]);\n let b = parseInt(val[1]);\n console.log(recursive(a,b));\n\n }\n \n \n \n}\n\n\n"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while(t--){\n let val = readline().split(\" \").map(x => parseInt(x));\n let a = parseInt(val[0]);\n let b = parseInt(val[1]);\n if( a == b){\n console.log(Math.floor(a/2));\n }else{\n\n let div2, div3;\n div2 = Math.min(Math.floor(a/2),Math.floor(b/2));\n if(a > b){\n div3 = Math.min(Math.floor(a/3),Math.floor(b/1));\n }else{\n div3 = Math.min(Math.floor(a/1),Math.floor(b/3));\n \n }\n if(div2 >= div3){\n let tempNum = div2*2;\n let tempA = a - tempNum ;\n let tempB = b - tempNum ;\n if(tempA > 0 && tempB > 0 && (tempA + tempB >=4)){\n console.log(div2+ Math.floor((tempA + tempB)/4));\n }else{\n console.log(div2);\n }\n }else{\n console.log(div3);\n }\n }\n\n }\n \n \n \n}\n\n\n"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while(t--){\n let val = readline().split(\" \").map(x => parseInt(x));\n let a = parseInt(val[0]);\n let b = parseInt(val[1]);\n if( a == b){\n console.log(Math.floor(a/2));\n }else{\n\n let div2, div3;\n div2 = Math.min(Math.floor(a/2),Math.floor(b/2));\n if(a > b){\n div3 = Math.min(Math.floor(a/3),Math.floor(b/1));\n }else{\n div3 = Math.min(Math.floor(a/1),Math.floor(b/3));\n \n }\n if(div2 >= div3){\n let tempNum = div2*2;\n let tempA = a - tempNum ;\n let tempB = b - tempNum ;\n if(tempA > 0 && tempB > 0 && (tempA + tempB >=4)){\n console.log(div2+1);\n }else{\n console.log(div2);\n }\n }else{\n console.log(div3);\n }\n }\n\n }\n \n \n \n}\n\n\n"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while(t--){\n let val = readline().split(\" \").map(x => parseInt(x));\n let a = parseInt(val[0]);\n let b = parseInt(val[1]);\n if( a == b){\n console.log(Math.floor(a/2));\n }else{\n\n let div2, div3;\n div2 = Math.min(Math.floor(a/2),Math.floor(b/2));\n if(a > b){\n div3 = Math.min(Math.floor(a/3),Math.floor(b/1));\n }else{\n div3 = Math.min(Math.floor(a/1),Math.floor(b/3));\n \n }\n if(div2 >= div3){\n let tempNum = div2 *2;\n let tempA = a - tempNum ;\n let tempB = b - tempNum ;\n if(tempA > 0 && tempB > 0 && (tempA + tempB >=4)){\n console.log(div2+1);\n }else{\n console.log(div2);\n }\n }else{\n console.log(div3);\n }\n }\n\n }\n \n \n \n}\n\n\n"}, {"source_code": "'use strict';\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline(){\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = readline();\n while(t--){\n let x = readline();\n let a = parseInt(x);\n let y = readline();\n let b = parseInt(y);\n if( a == b){\n console.log(Math.floor(a/2));\n }else{\n\n let div2, div3;\n div2 = Math.min(Math.floor(a/2),Math.floor(b/2));\n if(a > b){\n div3 = Math.min(Math.floor(a/3),Math.floor(b/1));\n }else{\n div3 = Math.min(Math.floor(a/1),Math.floor(b/3));\n \n }\n if(div2 >= div3){\n let tempNum = div2 *2;\n let tempA = a - tempNum ;\n let tempB = b - tempNum ;\n if(tempA > 0 && tempB > 0 && (tempA + tempB >=4)){\n console.log(div2+1);\n }else{\n console.log(div2);\n }\n }else{\n console.log(div3);\n }\n }\n\n }\n \n \n \n}\n\n\n"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t \tvar k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], d = 0;\n if(a == b){\n console.log(Math.floor((a + b) / 4));\n }else if(a > b){\n d = a - b;\n a -= d;\n d /= 2;\n d = Math.min(a, d);\n a -= d;\n b -= d;\n d += Math.floor((a + b) / 4);\n console.log(Math.ceil(d));\n }else{\n d = b - a;\n b -= d;\n d /= 2;\n d = Math.min(a, d);\n a -= d;\n b -= d;\n d += Math.floor((a + b) / 4);\n console.log(Math.ceil(d));\n }\n\t}\n});\n\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet [a, b] = nl.nums();\n \t\tif (a * 4 > b && b * 4 > a) {\n\t\t\tans.push(Math.trunc((a + b) / 4));\n\t\t} else {\n\t\t\tans.push(Math.min(a, b));\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet [a, b] = nl.nums();\n \t\tif (a * 4 >= b && b * 4 >= a) {\n\t\t\tans.push(Math.trunc((a + b) / 4));\n\t\t} else {\n\t\t\tans.push(Math.min(a, b));\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n fileContents\n .map(solveLine)\n .forEach(x => console.log(x))\n}\n\nfunction solveLine(programmersAndMaths){\n const maths = parseInt(programmersAndMaths.split(\" \")[0],10)\n const programmers = parseInt(programmersAndMaths.split(\" \")[1],10)\n // console.log(\"xxxxx\", maths, programmers, programmersAndMaths)\n\n\n if(programmers/3 > maths){\n return maths;\n }else if(maths/3 > programmers){\n return programmers\n }else{\n return Math.ceil((maths+programmers)/4)\n }\n}\n"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n a = +s[0];\r\n b = +s[1];\r\n if (a + b < 4 || a == 0 || b == 0) print(0);\r\n else if (a < 4 && b < 4 && a + b >= 4) print(parseInt((a + b) / 4));\r\n else if (a + b >= 4 && (a > b || b > a)) print(Math.min(a, b));\r\n else if ((a < 4 || b < 4) && a + b >= 4) print(Math.min(a, b));\r\n else if ((a >= 4 && b >= 4) || a + b >= 4) print(parseInt((a + b) / 4));\r\n}"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n a = +s[0];\r\n b = +s[1];\r\n if (a + b < 4 || a == 0 || b == 0) print(0);\r\n else if (a < 4 && b < 4 && a + b >= 4) print(parseInt((a + b) / 4));\r\n else if ((a < 4 || b < 4) && a + b >= 4) print(Math.min(a, b));\r\n else if ((a >= 4 && b >= 4) || a + b >= 4) print(parseInt((a + b) / 4));\r\n}"}], "src_uid": "8a1ceac1440f7cb406f12d9fc2ca0e20"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while(t--){\r\n const arr = readline().split(' ').map(i => parseInt(i));\r\n\r\n const max = Math.max(...arr);\r\n const ans = [0,0,0]; \r\n let n = 0;\r\n for (let i = 0; i < 3; i++){\r\n if (arr[i] === max) n++;\r\n }\r\n for (let i = 0; i < 3; i++){\r\n if (arr[i] === max) {\r\n ans[i] = n === 1 ? 0 : 1;\r\n } else {\r\n ans[i] = max - arr[i] + 1;\r\n }\r\n \r\n }\r\n console.log(ans.join(' '))\r\n }\r\n \r\n}\r\n", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0], b = k[1], c = k[2]\n if(a === 0 && b === 0 && c === 0){\n console.log(1,1,1)\n }else{\n var A=Math.max(b,c)-a+1\n , B=Math.max(a,c)-b+1\n , C=Math.max(a,b)-c+1\n if(A < 0){\n A = 0\n }else if(B < 0){\n B=0 \n }else if(C < 0){\n C=0\n }\n console.log(A,B,C)\n }\n\n }\n \n\t \n}); "}, {"source_code": "var ok = function(a, b, c){\n var og = a;\n a += Math.max(0, b - a + 1);\n a += Math.max(0, c - a + 1);\n return a - og;\n};\nlet q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var temp = 0;\n for(i = 1; i <= t; i++){\n var n = lines[i].split(' ').map(Number);\n var a = n[0], b = n[1], c = n[2];\n var ans = '';\n ans += ok(a, b, c) + ' ';\n temp = a;\n a = b;\n b = temp;\n ans += ok(a, b, c) + ' ';\n temp = a;\n a = b;\n b = temp;\n temp = a;\n a = c;\n c = temp;\n ans += ok(a, b, c) + ' ';\n console.log(ans);\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1] = d.split(\" \").map(Number);\n const ans1 = Math.max(0, Math.max(b1, c1) + 1 - a1);\n const ans2 = Math.max(0, Math.max(a1, c1) + 1 - b1);\n const ans3 = Math.max(0, Math.max(a1, b1) + 1 - c1);\n\n console.log(ans1, ans2, ans3);\n\n // const [a1, b1, c1] = d.split(\" \").map(Number);\n // const ans1 = Math.max(b1, c1) >= a1 ? Math.abs(a1 - Math.max(b1, c1)) + 1 : 0;\n // const ans2 = Math.max(a1, c1) >= b1 ? Math.abs(b1 - Math.max(a1, c1)) + 1 : 0;\n // const ans3 = Math.max(b1, a1) >= c1 ? Math.abs(c1 - Math.max(b1, a1)) + 1 : 0;\n\n // console.log(ans1, ans2, ans3);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1] = d.split(\" \").map(Number);\n const ans1 = Math.max(b1, c1) >= a1 ? Math.abs(a1 - Math.max(b1, c1)) + 1 : 0;\n const ans2 = Math.max(a1, c1) >= b1 ? Math.abs(b1 - Math.max(a1, c1)) + 1 : 0;\n const ans3 = Math.max(b1, a1) >= c1 ? Math.abs(c1 - Math.max(b1, a1)) + 1 : 0;\n\n console.log(ans1, ans2, ans3);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let ans = \"\";\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n let max = Math.max(arr[0], arr[1], arr[2]);\r\n let min = Math.min(arr[0], arr[1], arr[2]);\r\n let hassame = arr.filter(i => i == max);\r\n if (hassame.length > 1) max++;\r\n if (max == min) {\r\n console.log(`${arr[0] + 1} ${arr[1] + 1} ${arr[2] + 1}`)\r\n } else {\r\n for (let i = 0; i < arr.length; i++) {\r\n let val = arr[i];\r\n if (max == val) {\r\n ans += \"0 \"\r\n } else {\r\n ans += (max - val + (hassame.length > 1 ? 0 : 1)) + \" \";\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n\r\nfunction compare(a, b, c) {\r\n if (a > b && a > c) {\r\n return 0;\r\n }\r\n \r\n const bigger = Math.max(b, c);\r\n \r\n const diff = a - bigger;\r\n \r\n return Math.abs(diff) + 1;\r\n}\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const length = parseInt(lines[0]);\r\n \r\n for(let i = 1; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n if (!line) return;\r\n const split = line.split(' ').map(t => parseInt(t.trim()));\r\n const a = split[0];\r\n const b = split[1];\r\n const c = split[2];\r\n \r\n const output = `${compare(a, b, c)} ${compare(b, a, c)} ${compare(c, a, b)}`;\r\n console.log(output);\r\n }\r\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const length = parseInt(readline());\n for (let i = 0; i < length; i++) {\n const votes = readline().split(' ').map(v => parseInt(v));\n const max = Math.max(...votes);\n const hasWinner = votes.reduce((acc, v) => v === max ? acc + 1 : acc , 0) === 1\n console.log(...votes.map(v => v === max ? hasWinner ? 0 : 1 : max - v + 1));\n }\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b, c]) {\r\n let aC, bC, cC;\r\n if (a > Math.max(b, c)) {\r\n aC = 0\r\n } else {\r\n const dif = Math.max(b, c) - a\r\n if (dif === 0) {\r\n aC = 1\r\n } else {\r\n aC = dif + 1\r\n }\r\n }\r\n if (b > Math.max(a, c)) {\r\n bC = 0\r\n } else {\r\n const dif = Math.max(a, c) - b\r\n if (dif === 0) {\r\n bC = 1\r\n } else {\r\n bC = dif + 1\r\n }\r\n }\r\n if (c > Math.max(b, a)) {\r\n cC = 0\r\n } else {\r\n const dif = Math.max(b, a) - c\r\n if (dif === 0) {\r\n cC = 1\r\n } else {\r\n cC = dif + 1\r\n }\r\n }\r\n console.log([aC, bC, cC].join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.nums();\n\t\tlet s = [...a];\n\t\ts.sort((x, y) => y - x);\n\t\tans.push(a.map(e => e < s[0]?s[0] - e + 1:(s[0] == s[1]?1:0)));\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, c] = rna();\r\n\r\n\t\tconst calc = (a, b, c) => Math.max(Math.max(b, c) - a + 1, 0);\r\n\r\n\t\tconsole.log(calc(a, b, c), calc(b, a, c), calc(c, a, b));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n})\n\nlet first = 0\nfunction solve(line) {\n\tif (!first) {\n\t\tfirst = 1\n\t\treturn\n\t}\n\tlet nums = line.split(' ').map(x => +x)\n\tlet diff = new Set(nums).size < nums.length\n\tlet max = Math.max(...nums)\n\tlet maxCount = nums.filter(x => x === max).length\n\tconsole.log(nums.map((num) => {\n\t\treturn max - num + (maxCount > 1 && num === max || num !== max)\n\t}).join(' '))\n}\n\n// let input = `5\n// 0 0 0\n// 10 75 15\n// 13 13 17\n// 1000 0 0\n// 0 1000000000 0`\n// input.split('\\n').forEach(solve)\n\nlet input = ''\nreadline.on('line', solve)"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n const xa = Math.max(0, Math.max(b, c) + 1 - a)\n const xb = Math.max(0, Math.max(a, c) + 1 - b)\n const xc = Math.max(0, Math.max(b, a) + 1 - c)\n return [xa, xb, xc].join(' ')\n}\n"}, {"source_code": "var t = +readline();\r\n\r\nfor(var i = 0; i +t);\r\n print(votes(result))\r\n \r\n}\r\n\r\nfunction votes (list) {\r\n\r\n\r\n var a = list[0];\r\n var b = list[1];\r\n var c = list[2];\r\n\r\n var maxNum = Math.max(a,b,c);\r\n \r\n \r\n if(maxNum == a && maxNum != b && maxNum != c){\r\n return [maxNum-a,maxNum-b+1,maxNum-c+1].join(' ')\r\n }\r\n if(maxNum == b && maxNum != a && maxNum != c){\r\n return [maxNum-a+1,maxNum-b,maxNum-c+1].join(' ')\r\n }\r\n if(maxNum == c && maxNum != a && maxNum != b){\r\n return [maxNum-a+1,maxNum-b+1,maxNum-c].join(' ')\r\n }else {\r\n return [maxNum-a+1,maxNum-b+1,maxNum - c +1].join(' ')\r\n }\r\n\r\n\r\n \r\n}\r\n"}, {"source_code": "var t=Number(readline());\r\nfor(var i=0;i\");\r\n m=Math.max(x,y,z);\r\n if(x==y && y==z){\r\n x=1;\r\n y=1;\r\n z=1;\r\n }\r\n else if( (x==m && y==m) || (y==m && z==m) || (z==m && x==m) ){\r\n x=m+1-x;\r\n y=m+1-y;\r\n z=m+1-z;\r\n }\r\n else{\r\n m==x?x=0 : x=m+1-x;\r\n m==y?y=0 : y=m+1-y;\r\n m==z?z=0 : z=m+1-z;\r\n }\r\n\r\n print(x +\" \" + y + \" \" + z);\r\n}"}, {"source_code": "var t = readline();\r\nfor (var i=0 ; i < t ; i++){\r\n var inputs = readline().split(' ') , finalArr = [];\r\n max = Math.max(...inputs) , counter = 0;\r\n for (var j = 0 ; j < inputs.length ; j++ ){\r\n if(inputs[j] == max){\r\n counter++;\r\n }\r\n }\r\n for (var k = 0 ; k < inputs.length ; k++ ){\r\n if(inputs[k] != max ){\r\n finalArr.push((max - inputs[k] + 1));\r\n }\r\n else if(inputs[k] == max && counter != 1){\r\n finalArr.push(1);\r\n }\r\n else{\r\n finalArr.push(0);\r\n }\r\n }\r\n print(finalArr.join(' '));\r\n}"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0], b = k[1], c = k[2]\n if(a === 0 && b === 0 && c === 0){\n console.log(1,1,1)\n }else{\n var A=Math.max(b,c)-a+1\n , B=Math.max(a,c)-b+1\n , C=Math.max(a,b)-c+1\n if(a < 0){\n A = 0\n }else if(b < 0){\n B=0 \n }else if(c < 0){\n C=0\n }\n console.log(A,B,C)\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0], b = k[1], c = k[2]\n if(a === 0 && b === 0 && c === 0){\n console.log(1,1,1)\n }else{\n var A=Math.max(b,c)-a+1\n , B=Math.max(a,c)-b+1\n , C=Math.max(a,b)-c+1\n if(a < 0){\n a = 0\n }else if(b < 0){\n b=0 \n }else if(c < 0){\n c=0\n }\n console.log(A,B,C)\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split(' ').map(Number)\n a = k[0], b = k[1], c = k[2]\n if(a === 0 && b === 0 && c === 0){\n console.log(1,1,1)\n }else{\n var A=Math.max(b,c)-a+1\n , B=Math.max(a,c)-b+1\n , C=Math.max(a,b)-c+1\n console.log(A,B,C)\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1\n if(b < 10){\n console.log(b)\n }else{\n \n console.log(k.join(''))\n\n }\n\n }\n \n\t \n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n \n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n \n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n if(j === 305){\n s = 0 + ' ' + 0 + ' ' + 0\n }else{\n s= 1 + ' '+ 1 + ' '+ 1\n }\n break;\n }else if(a[k + 1] == max && a[k] == max){\n if(j === 305){\n s += 0 + ' ' + 0 + ' ' \n }else{\n s += 1 + ' ' + 1 + ' '\n }\n break;\n }else if(a[k] == max){\n if(j === 305){\n s += 1 + ' '\n }else{\n s += 0 + ' '\n }\n \n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n \n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n \n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n \n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n if(j === 304){\n s = 0 + ' ' + 0 + ' ' + 0\n }else{\n s= 1 + ' '+ 1 + ' '+ 1\n }\n break;\n }else if(a[k + 1] == max && a[k] == max){\n if(j === 304){\n s += 0 + ' ' + 0 + ' ' \n }else{\n s += 1 + ' ' + 1 + ' '\n }\n break;\n }else if(a[k] == max){\n if(j === 304){\n s += 1 + ' '\n }else{\n s += 0 + ' '\n }\n \n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n \n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n \n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n \n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n if(j === 303){\n s = 0 + ' ' + 0 + ' ' + 0\n }else{\n s= 1 + ' '+ 1 + ' '+ 1\n }\n break;\n }else if(a[k + 1] == max && a[k] == max){\n if(j === 303){\n s += 0 + ' ' + 0 + ' ' \n }else{\n s += 1 + ' ' + 1 + ' '\n }\n break;\n }else if(a[k] == max){\n if(j === 303){\n s += 1 + ' '\n }else{\n s += 0 + ' '\n }\n \n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n \n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n s= 1 + ' '+ 1 + ' '+ 1\n break;\n }else if(a[k + 1] == max && a[k] == max){\n s += 1 + ' ' + 1 + ' '\n break;\n }else if(a[k] == max){\n s += 0 + ' '\n \n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n s= 1 + ' '+ 1 + ' '+ 1\n break;\n }else if(a[k] == max){\n s += 0 + ' '\n if(a[k + 1] == max){\n s += 0 + ' '\n break;\n }\n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n for(k = 0; k< 3; k++){\n if(a[0] == max && a[1] == max && a[2] == max){\n s= 1 + ' '+ 1 + ' '+ 1\n break;\n }else if(a[k] == max){\n s += 0 + ' '\n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n var s = ''\n var a = lines[j].split(' ').map(Number)\n var max = Math.max(a[0], Math.max(a[1], a[2]))\n for(k = 0; k< 3; k++){\n if(a[k] == max){\n s += 0 + ' '\n }else if(a[k] < max){\n var h = max\n s += (h - a[k] + 1) + ' '\n }\n }\n console.log(s)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var max = Math.max(a, Math.max(b, c));\n var answer = '';\n for(j = 0; j < 3; j++){\n if(a === 0 && b == 3 && c == 4 && j == 2){\n answer += 1 + ' '; \n }else if(k[j] === 0 && max == k[j]){\n answer += 1 + ' ';\n }else if(k[j] == max){\n answer += 0 + ' ';\n }else{\n answer += max - k[j] + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var max = Math.max(a, Math.max(b, c));\n var answer = '';\n for(j = 0; j < 3; j++){\n if(a === 0 && b == 3 && c == 4 && j == 2){\n answer += 1 + ' '; \n }else if(k[j] === 0 && max == k[j]){\n answer += 1 + ' ';\n }else if(k[j] == max){\n answer += 0 + ' ';\n }else{\n answer += max - k[j] + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});\n\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var max = Math.max(a, Math.max(b, c));\n var answer = '';\n for(j = 0; j < 3; j++){\n if(a === 0 && b == 3 && c == 4 && j == 2){\n answer += 1 + ' '; \n }else if(k[j] === 0 && max == k[j]){\n answer += 1 + ' ';\n }else if(k[j] == max){\n answer += 0 + ' ';\n }else{\n answer += max - k[j] + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var max = Math.max(a, Math.max(b, c));\n var answer = '';\n for(j = 0; j < 3; j++){\n if(a === 0 && b == 3 && c == 4 && j == 2){\n answer += 1 + ' '; \n }else if(k[j] === 0 && max == k[j]){\n answer += 1 + ' ';\n }else if(k[j] == max){\n answer += 0 + ' ';\n }else{\n answer += max - k[j] + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var max = Math.max(a, Math.max(b, c));\n var answer = '';\n for(j = 0; j < 3; j++){\n if(k[j] === 0 && max == k[j]){\n answer += 1 + ' ';\n }else if(k[j] == max){\n answer += 0 + ' ';\n }else{\n answer += max - k[j] + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var max = Math.max(k[0], Math.max(k[1], k[2]));\n var answer = '';\n for(var l = 0; l < 3; l++){\n if(k[l] === 0 && max === 0){\n answer += 1 + ' ';\n }else if(k[0] == max && k[1] == max || k[0] == max && k[2] == max || k[1] == max && k[2] == max){\n answer += 1 + ' ';\n }else if(k[l] == max){\n answer += 0 + ' ';\n }else{\n answer += (max - k[l]) + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var max = Math.max(k[0], Math.max(k[1], k[2]));\n var answer = '';\n for(var l = 0; l < 3; l++){\n if(k[l] === 0 && max === 0){\n answer += 1 + ' ';\n }else if(k[l] == max){\n answer += 0 + ' ';\n }else{\n answer += (max - k[l]) + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var max = Math.max(k[0], Math.max(k[1], k[2]));\n var answer = '';\n for(var l = 0; l < 3; l++){\n if(k[l] == k[l + 1] && k[l + 1] == k[l + 2] && k[l + 2] === 0){\n answer += 1 + ' ' + 1 + ' ' + 1 + ' ';\n break;\n }else if(k[l] == max){\n answer += 0 + ' ';\n }else{\n answer += (max - k[l]) + 1 + ' ';\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1] = d.split(\" \").map(Number);\n const ans1 = Math.max(b1, c1) > a1 ? Math.abs(a1 - Math.max(b1, c1)) + 1 : 0;\n const ans2 = Math.max(a1, c1) > b1 ? Math.abs(b1 - Math.max(a1, c1)) + 1 : 0;\n const ans3 = Math.max(b1, a1) > c1 ? Math.abs(c1 - Math.max(b1, a1)) + 1 : 0;\n\n console.log(ans1, ans2, ans3);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let ans = \"\";\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n let max = Math.max(arr[0], arr[1], arr[2]);\r\n let min = Math.min(arr[0], arr[1], arr[2]);\r\n if (max == min) {\r\n console.log(`${arr[0] + 1} ${arr[1] + 1} ${arr[2] + 1}`)\r\n } else {\r\n for (let i = 0; i < arr.length; i++) {\r\n let val = arr[i];\r\n if (max == val) {\r\n ans += \"0 \"\r\n } else {\r\n ans += (max - val + 1) + \" \";\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n\r\nfunction compare(a, b, c) {\r\n if (a > b && a > c) {\r\n return 0;\r\n }\r\n \r\n const bigger = Math.max(b, c);\r\n \r\n const diff = a - bigger;\r\n \r\n return Math.abs(diff) + 1;\r\n}\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const length = parseInt(lines[0]);\r\n \r\n for(let i = 1; i < lines.length; i++) {\r\n const line = lines[i];\r\n const split = line.split(' ').map(t => parseInt(t.trim()));\r\n const a = split[0];\r\n const b = split[1];\r\n const c = split[2];\r\n \r\n const output = `${compare(a, b, c)} ${compare(b, a, c)} ${compare(c, a, b)}`;\r\n console.log(output);\r\n }\r\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const length = parseInt(readline());\n for (let i = 0; i < length; i++) {\n const votes = readline().split(' ').map(v => parseInt(v));\n const max = Math.max(...votes);\n console.log(...votes.map(v => v === max ? 0 : max - v + 1));\n }\n}"}, {"source_code": "let all = \"\"\r\nprocess.stdin.on('data', data => {\r\n all += data\r\n all = all.split(' ')\r\n main()\r\n process.exit()\r\n})\r\n\r\nfunction main() {\r\n let ind = 0\r\n let T = Number(all[ind++])\r\n for (let i = 0; i < T; i++) {\r\n let a = Number(all[ind++])\r\n let b = Number(all[ind++])\r\n let c = Number(all[ind++])\r\n let A = Math.max(0, Math.max(b, c) - a + 1)\r\n let B = Math.max(0, Math.max(a, c) - b + 1)\r\n let C = Math.max(0, Math.max(a, b) - c + 1)\r\n console.log(A, B, C)\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b, c]) {\r\n let aC, bC, cC;\r\n if (a >= Math.max(b, c)) {\r\n aC = 0\r\n } else {\r\n const dif = Math.max(b, c) - a\r\n if (dif === 0) {\r\n aC = 1\r\n } else {\r\n aC = dif + 1\r\n }\r\n }\r\n if (b >= Math.max(a, c)) {\r\n bC = 0\r\n } else {\r\n const dif = Math.max(a, c) - b\r\n if (dif === 0) {\r\n bC = 1\r\n } else {\r\n bC = dif + 1\r\n }\r\n }\r\n if (c >= Math.max(b, a)) {\r\n cC = 0\r\n } else {\r\n const dif = Math.max(b, a) - c\r\n if (dif === 0) {\r\n cC = 1\r\n } else {\r\n cC = dif + 1\r\n }\r\n }\r\n console.log(aC, bC, cC)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor(var i = 0; i +t);\r\n print(votes(result))\r\n \r\n}\r\n\r\nfunction votes (list) {\r\n\r\n\r\n var a = list[0];\r\n var b = list[1];\r\n var c = list[2];\r\n\r\n var maxNum = Math.max(a,b,c);\r\n \r\n \r\n if(maxNum == a && maxNum != b && maxNum != c){\r\n return [maxNum-a,maxNum-b+1,maxNum-c+1].join(' ')\r\n }\r\n if(maxNum == b && maxNum != a && maxNum != c){\r\n return [maxNum-a+1,maxNum-b,maxNum-c+1].join(' ')\r\n }\r\n if(maxNum == c && maxNum != a && maxNum != b){\r\n return [maxNum-a+1,maxNum-b+1,maxNum-c].join(' ')\r\n }else {\r\n return [maxNum-a+1,maxNum-b+1,maxNum+1].join(' ')\r\n }\r\n\r\n\r\n \r\n}"}, {"source_code": "var t=Number(readline());\r\nfor(var i=0;i\");\r\n m=Math.max(x,y,z);\r\n if(x==y && y==z){\r\n x=1;\r\n y=1;\r\n z=1;\r\n }\r\n else{\r\n m==x?x=0 : x=m+1-x;\r\n m==y?y=0 : y=m+1-y;\r\n m==z?z=0 : z=m+1-z;\r\n }\r\n\r\n print(x +\" \" + y + \" \" + z);\r\n}"}], "src_uid": "f80dea1e07dba355bfbefa4ff65ff45a"} {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\n\n\nfunction shuffle_checker(_m1, _m2) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var nextCell2 = _m2[j][i + 1];\n var alternative = _m2[j][i];\n if (nextCell) {\n if (cell >= nextCell) {\n rows_check = false;\n if (alternative < nextCell && cell < nextCell2) {\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n rows_check = true;\n }\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n var bottomCell2 = _m2[j + 1] && _m2[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell) {\n cols_check = false;\n if (alternative < bottomCell && cell < bottomCell2) {\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n cols_check = true;\n }\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2);\np2 = shuffle_checker(m2, m1);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const n = parseInt(lines[0].split(' ')[0], 10);\n let index = 1;\n const m1 = [];\n for (let i = 0; i < n; i++) {\n let r = lines[index].split(' ');\n r = r.map(data => parseInt(data));\n m1.push([...r]);\n index++;\n }\n const m2 = [];\n for (let i = 0; i < n; i++) {\n let r = lines[index].split(' ');\n r = r.map(data => parseInt(data));\n m2.push([...r]);\n index++;\n }\n isPossible(m1, m2);\n});\n\nfunction isPossible(m1, m2) {\n for (let i = 0; i < m1.length; i++) {\n for (let j = 0; j < m1[i].length; j++) {\n if (m2[i][j] < m1[i][j]) {\n swap(m1, m2, i, j);\n }\n }\n }\n\n for (let i = 0; i < m1.length; i++) {\n for (let j = 0; j < m1[i].length; j++) {\n if (!isIncreasing(m1, i, j, m1[i][j]) || !isIncreasing(m2, i, j, m2[i][j])) {\n console.log('Impossible');\n return false;\n }\n }\n }\n\n console.log('Possible');\n}\n\n\nfunction swap(m1, m2, i, j) {\n const temp = m1[i][j];\n m1[i][j] = m2[i][j];\n m2[i][j] = temp;\n}\n\n\nfunction isIncreasing(m, i, j, curr) {\n // check above\n if (m[i - 1]) {\n if (m[i - 1][j] >= curr) return false;\n }\n\n // check below\n if (m[i + 1]) {\n if (m[i + 1][j] <= curr) return false;\n }\n\n // check left\n if (m[i][j - 1]) {\n if (m[i][j - 1] >= curr) return false;\n }\n\n // check right\n if (m[i][j + 1]) {\n if (m[i][j + 1] <= curr) return false;\n }\n return true;\n}\n"}], "negative_code": [{"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\nvar isPossiableM1 = false;\nvar isPossiableM2 = false;\n\nfunction shuffle_checker(_m1, _m2, can_shuffle) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i + 1];\n if (nextCell) {\n if (cell >= nextCell && (!can_shuffle || (can_shuffle && alternative >= nextCell))) {\n rows_check = false;\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n var alternative2 = _m2[j + 1] && _m2[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell && (!can_shuffle || (can_shuffle && alternative2 >= bottomCell))) {\n cols_check = false;\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2, true);\np2 = shuffle_checker(m2, m1, false);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}\n\n"}, {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\nvar shuffle_map = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n shuffle_map[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n shuffle_map[_j - lj][i] = false;\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\n\n\nfunction shuffle_checker(_m1, _m2) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i];\n if (nextCell) {\n if (cell >= nextCell) {\n rows_check = false;\n if (alternative < nextCell && !shuffle_map[j][i]) {\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n rows_check = true;\n }\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell) {\n cols_check = false;\n if (alternative < bottomCell && !shuffle_map[j][i]) {\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n cols_check = true;\n }\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2);\np2 = shuffle_checker(m2, m1);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}"}, {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\nvar isPossiableM1 = false;\nvar isPossiableM2 = false;\n\nfunction shuffle_checker(_m1, _m2, can_shuffle) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i + 1];\n if (nextCell) {\n if (cell >= nextCell && (!can_shuffle || (can_shuffle && alternative >= nextCell))) {\n rows_check = false;\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n var alternative2 = _m2[j + 1] && _m2[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell && (!can_shuffle || (can_shuffle && alternative2 >= bottomCell))) {\n cols_check = false;\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2, true);\np2 = shuffle_checker(m2, m1, true);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}\n\n"}, {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\nvar isPossiableM1 = false;\nvar isPossiableM2 = false;\n\nfunction shuffle_checker(_m1, _m2, can_shuffle) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i];\n if (nextCell) {\n if (cell >= nextCell && (!can_shuffle || (can_shuffle && alternative >= nextCell))) {\n rows_check = false;\n print(alternative);\n print(i, j);\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell && (!can_shuffle || (can_shuffle && alternative >= bottomCell))) {\n cols_check = false;\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2, true);\np2 = shuffle_checker(m2, m1, true);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}\n\n\n\n\n"}, {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\nvar shuffle_map = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n shuffle_map[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n shuffle_map[_j - lj][i] = false;\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\n\n\nfunction shuffle_checker(_m1, _m2) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i];\n if (nextCell) {\n if (cell >= nextCell) {\n rows_check = false;\n if (alternative < nextCell && !shuffle_map[j][i]) {\n shuffle_map[j][i] = true;\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n rows_check = true;\n }\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell) {\n cols_check = false;\n if (alternative < bottomCell && !shuffle_map[j][i]) {\n shuffle_map[j][i] = true;\n _m2[j][i] = cell;\n _m1[j][i] = alternative;\n cols_check = true;\n }\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2);\np2 = shuffle_checker(m2, m1);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}"}, {"source_code": "var m, n;\n\nreadline().split(' ').forEach(function(c, i) {\n if (i === 0) {\n m = parseInt(c);\n return;\n } else if (i === 1) {\n n = parseInt(c);\n }\n});\n\n\nvar m1 = [];\nvar m2 = [];\n\nfunction fill_matrix(_m, _j, _i) {\n var lj = _j;\n var li = _i;\n while (lj > 0) {\n readline().split(' ').forEach(function(c, i) {\n if (i < li) {\n if (!_m[_j - lj]) {\n _m[_j - lj] = [];\n }\n _m[_j - lj][i] = parseInt(c);\n }\n });\n lj --;\n }\n}\n\nfill_matrix(m1, m, n);\nfill_matrix(m2, m, n);\n\nvar isPossiableM1 = false;\nvar isPossiableM2 = false;\n\nfunction shuffle_checker(_m1, _m2, can_shuffle) {\n var rows_check = true;\n var cols_check = true;\n _m1.forEach(function(row, j) {\n row.forEach(function(cell, i) {\n if (!rows_check || !cols_check) {\n return;\n }\n var nextCell = _m1[j][i + 1];\n var alternative = _m2[j][i];\n if (nextCell) {\n if (cell >= nextCell && (!can_shuffle || (can_shuffle && alternative >= nextCell))) {\n rows_check = false;\n } \n }\n var bottomCell = _m1[j + 1] && _m1[j + 1][i];\n if (bottomCell) {\n if (cell >= bottomCell && (!can_shuffle || (can_shuffle && alternative >= bottomCell))) {\n cols_check = false;\n }\n }\n });\n });\n return rows_check && cols_check;\n}\n\nvar p1 = false;\nvar p2 = false;\n\np1 = shuffle_checker(m1, m2, true);\np2 = shuffle_checker(m2, m1, true);\n\nif (p1 && p2) {\n print('Possible');\n} else {\n print('Impossible'); \n}\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const n = parseInt(lines[0].split(' ')[0], 10);\n let index = 1;\n const m1 = [];\n for (let i = 0; i < n; i++) {\n let r = lines[index].split(' ');\n r = r.map(data => parseInt(data));\n m1.push([...r]);\n index++;\n }\n const m2 = [];\n for (let i = 0; i < n; i++) {\n let r = lines[index].split(' ');\n r = r.map(data => parseInt(data));\n m2.push([...r]);\n index++;\n }\n isPossible(m1, m2);\n});\n\nfunction isPossible(m1, m2) {\n for (let i = 0; i < m1.length; i++) {\n for (let j = 0; j < m1[i].length; j++) {\n if (!isIncreasing(m1, i, j, m1[i][j]) || !isIncreasing(m2, i, j, m2[i][j])) {\n if (canSwap(m1, m2, i, j)) {\n swap(m1, m2, i, j);\n } else {\n console.log('Impossible');\n return;\n }\n }\n }\n }\n console.log('Possible');\n}\n\nfunction canSwap(m1, m2, i, j) {\n return isIncreasing(m1, i, j, m2[i][j]) && isIncreasing(m2, i, j, m1[i][j]);\n}\n\nfunction swap(m1, m2, i, j) {\n const temp = m1[i][j];\n m1[i][j] = m2[i][j];\n m2[i][j] = temp;\n}\n\n\nfunction isIncreasing(m, i, j, curr) {\n // check above\n if (m[i - 1]) {\n if (m[i - 1][j] >= curr) return false;\n }\n\n // check below\n if (m[i + 1]) {\n if (m[i + 1][j] <= curr) return false;\n }\n\n // check left\n if (m[i][j - 1]) {\n if (m[i][j - 1] >= curr) return false;\n }\n\n // check right\n if (m[i][j + 1]) {\n if (m[i][j + 1] <= curr) return false;\n }\n return true;\n}\n"}], "src_uid": "53e061fe3fbe3695d69854c621ab6037"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n let lineCount = 0\n for(let i = 0; i < q; i++) {\n const n = parseInt(arr[lineCount ++])\n const a1 = arr[lineCount ++]\n const a2 = arr[lineCount ++ ]\n\n let i = 0, j = -1, currentRow = 1\n let shift = false\n while(j < n && i < n){\n // console.log(i, j, currentRow)\n if(currentRow == 1) {\n if(a1[i] <= 2 && !shift) i++\n else if(a1[i] <= 2 && shift) break\n else if(a1[i] >= 3 && shift) {\n shift = false\n i ++\n }\n else{\n currentRow = 2\n shift = true\n j = i\n }\n }\n else {\n // if(j == 6) console.log(a2[j])\n if(a2[j] <= 2 && !shift) j++\n else if(a2[j] <= 2 && shift) break\n else if(a2[j] >= 3 && shift) {\n // console.log('kl')\n shift = false\n j ++\n }\n else{\n currentRow = 1\n shift = true\n i = j\n }\n }\n }\n if(j == n) console.log('YES')\n else console.log('NO')\n\n // console.log()\n // console.log()\n // console.log()\n }\n})", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const q = readline();\n for(let i = 0;i{return parseInt(value)});\n const secondRow = readline().split('').map((value,index,array)=>{return parseInt(value)});\n matrix[0] = firstRow;\n matrix[1] = secondRow;\n calcQuery(length,matrix);\n }\n}\n\nfunction calcQuery(length,matrix){\n let y = 0;\n for(let x = 0; x < length;x++){\n if(matrix[y][x] > 2 && matrix[(y+1)%2][x] < 3){\n console.log(\"NO\");\n return;\n }\n if(matrix[y][x] > 2 && matrix[(y+1)%2][x] > 2){\n y = (y+1) % 2;\n }\n }\n if(y != 1){\n console.log(\"NO\");\n return;\n }\n console.log(\"YES\");\n}"}, {"source_code": "'use strict'\n\n\nconst tube = (n, l) => {\n let from = 'left';\n let x = 0;\n let y = 0;\n while (x < n) {\n if (l[y][x]) { if (from === 'left') x++; else return 'NO'; }\n else {\n if (from === 'left') { \n if (y) { y = 0; from = 'bottom';}\n else { y = 1; from = 'top'; }\n }\n else { x++; from = 'left'; }\n }\n }\n \n return y ? 'YES' : 'NO';\n}\nconst q = parseInt(readline());\n\nfor (let i = 0; i < q; i++) {\n write(tube(parseInt(readline()), [ readline().split('').map(i => parseInt(i) < 3), readline().split('').map(i => parseInt(i) < 3) ]) + '\\n');\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const q = readline();\n for(let i = 0;i{return parseInt(value)});\n const secondRow = readline().split('').map((value,index,array)=>{return parseInt(value)});\n matrix[0] = firstRow;\n matrix[1] = secondRow;\n calcQuery(length,matrix);\n }\n}\n\nfunction calcQuery(length,matrix){\n let counter = 0;\n for(let i = 0; i < length;i++){\n if(matrix[0][i] < 3 && matrix[1][i] > 2){\n console.log(\"NO\");\n return;\n }\n if(matrix[0][i] > 2 && matrix[1][i] < 3){\n console.log(\"NO\");\n return;\n }\n if(matrix[0][i] < 3 && matrix[1][i] < 3){\n counter ++;\n }\n }\n if((length - counter) % 2 == 0){\n console.log(\"NO\");\n return;\n }\n console.log(\"YES\");\n}"}], "src_uid": "f34cff4302e047b1e3bfc2c79aa57be3"} {"source_code": "\"use strict\";\nfunction main(input) {\n const inputs = input.split(\"\\n\").filter(x => x !== \"\");\n\n const N = Number(inputs[0]);\n const M = [];\n for (let i=0;i input += c)\nprocess.stdin.on('end', () => {\n main(input)\n})", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = new Array(N);\n for(var i = 0; i < N; i++){\n list[i] = next();\n }\n var output = 0;\n if(N <= 2){\n myout(output);\n return;\n }\n for(var i = 0; i < N - 2; i++){\n for(var j = 0; j < N - 2; j++){\n if(list[i][j] == \"X\"){\n if(list[i][j + 2] == \"X\" && \n list[i + 2][j] == \"X\" && \n list[i + 1][j + 1] == \"X\" && \n list[i + 2][j + 2] == \"X\"){\n output++;\n }\n }\n }\n }\n myout(output);\n}\n"}, {"source_code": "\"use strict\";\n// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\nconst PROGRAMMERS = \"ps\";\nvar SITE = CODEFORCES_NODE;\n// var SITE = CODEFORCES_NODE;\n// var SITE = PROGRAMMERS;\nvar DEBUG = false;\nif (SITE == BEAKJOON) {\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function (search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function (search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function (count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n };\n }\n}\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 HELPER ALGORITHMS/POLYFILLS \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\nfunction getCombinations2(n) {\n let ret = [];\n for (let start = 0; start < n; start++) {\n for (let k = start + 1; k < n; k++) {\n let s = new Set();\n s.add(start);\n s.add(k);\n ret.push(s);\n }\n }\n return ret;\n}\n\nfunction getSubbits(n) {\n let ret = [];\n for (var subset = n; subset; subset = (subset - 1) & n) {\n ret.push(subset);\n }\n return ret;\n}\nString.prototype.replaceAt = function (index, replacement) {\n return this.substr(0, index) + replacement + this.substr(index + replacement.length);\n};\nFunction.prototype.repeat = function (times, callback = undefined) {\n for (let i = 0; i < times; i++) {\n this();\n }\n return callback ? callback() : null;\n};\nArray.prototype.getMaxConsecutiveSum = function (defaultValue = -Infinity) {\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for (var ii = 0; ii < N; ii++) {\n cur = this[ii];\n if (cursum + cur > 0) {\n if (cur > cursum + cur) {\n cursum = cur;\n } else\n cursum += cur;\n } else {\n cursum = cur;\n if (maxsum < cursum) {\n maxsum = cursum;\n }\n }\n if (maxsum < cursum) {\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n};\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {}\nlet inputFilePath = '';\nswitch (SITE) {\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\nif (!Array.prototype.sortNumber) {\n /**\n * @memberof Array\n * @summary sorts array by number\n */\n Array.prototype.sortNumber = function (order = 'asc') {\n return this.sort((a, b) => ((order == 'asc') ? 1 : -1) * (+a - +b));\n };\n}\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\n/**\n * @type {(trim?=true)=>string}\n */\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\nvar clockStart;\nvar clock;\n/**\n * @type {typeof import('glob')}\n */\nvar glob;\nvar customFilesPattern = 'inputs/**/*.in';\nvar customFiles = [];\nvar print;\nprint = console.log;\nvar it;\nvar step;\n\nfunction EnableLogging() {\n it = console.info;\n step = console.success;\n}\n\nfunction DisableLogging() {\n it = function it(params) {\n return 0;\n };\n step = it;\n}\n\nfunction RunCustomTests() {\n // glob = require('glob');\n // it(process.cwd());\n // it(process.cwd() + customFilesPattern);\n // glob(customFilesPattern, (er,files)=>{\n // console.log('files count: ' + files.length);\n // files.forEach(file=>{\n // console.log(`custom test case files : ${file}`);\n // customFiles.push(file);\n // })\n // });\n // var path2 = process.cwd().replace(/\\\\/g, \"/\");\n // path = require('path');\n // glob(\"*.js\", (er,files)=>{\n // console.log('files count: ' + files.length);\n // files.forEach(file=>{\n // console.log(`custom test case files : ${file}`);\n // })\n // });\n // customFiles.forEach(file=>{\n // const filePath = process.cwd() + file;\n // console.info(filePath);\n // })\n}\nif (DEBUG) {\n EnableLogging();\n clock = function (start) {\n if (!start)\n return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0] * 1000) + (end[1] / 1000000));\n };\n} else {\n DisableLogging();\n}\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n // lines = ['custom line 1', 'custom line 2'];\n}\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {};\n\nfunction power(x, y) {\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--)\n arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\nfunction numericSortList(list) {\n list.sort((a, b) => a - b);\n}\n\nfunction getRectangleIntersection(r1, r2) {\n if (r1.x > r2.x + r2.w)\n return null;\n if (r1.x + r1.w < r2.x)\n return null;\n if (r1.y > r2.y + r2.h)\n return null;\n if (r1.y + r1.h < r2.y)\n return null;\n var rect = {};\n rect.x = Math.max(r1.x, r2.x);\n rect.y = Math.max(r1.y, r2.y);\n rect.w = Math.min(r1.x + r1.w, r2.x + r2.w) - rect.x;\n rect.h = Math.min(r1.y + r1.h, r2.y + r2.h) - rect.y;\n return rect;\n}\n\nfunction getRandomNumber(to, from) {\n if (from == undefined) {\n return Math.floor(Math.random() * to + 1);\n }\n return Math.floor(Math.random() * (to - from) + from);\n}\n/**\n * a queue that will be stop working someday.\n */\nclass TerminallyIllQueue {\n constructor() {\n this.data = {};\n this.head = 0;\n this.tail = 1;\n }\n length() {\n return this.tail - this.head - 1;\n }\n enqueue(v) {\n this.data[this.tail - 1] = v;\n this.tail++;\n }\n dequeue() {\n const v = this.data[this.head];\n this.head++;\n return v;\n }\n}\n/**\n * @template T\n * @type {TwoDimensionalMap}\n */\nclass TwoDimensionalMap {\n constructor() {\n this.data = {};\n }\n /**\n * @memberof TwoDimensionalMap\n * @public\n * @param {number} x\n * @param {number} y\n * @returns {T}\n */\n getPosition(x, y) {\n return this.data[`${x}.${y}`];\n }\n /**\n * @memberof TwoDimensionalMap\n * @public\n * @param {number} x\n * @param {number} y\n * @param {T} value\n */\n setPosition(x, y, value) {\n this.data[`${x}.${y}`] = value;\n }\n}\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\nfunction solve() {\n const n = ri();\n var maps = new TwoDimensionalMap();\n for (var j = 0; j < n; j++) {\n const li = rs();\n // it(li);\n for (var i = 0; i < n; i++) {\n maps.setPosition(i, j, li[i]);\n }\n }\n\n var ans = 0;\n for (var y = 0; y < n; y++) {\n for (var x = 0; x < n; x++) {\n it(maps.getPosition(x,y));\n if (maps.getPosition(x, y) != 'X') continue;\n if (maps.getPosition(x - 1, y - 1) == 'X' &&\n maps.getPosition(x - 1, y + 1) == 'X' &&\n maps.getPosition(x + 1, y - 1) == 'X' &&\n maps.getPosition(x + 1, y + 1) == 'X') {\n ans++;\n }\n }\n }\n print(ans);\n}\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\nfunction resetRead() {\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator = ' ') {\n if (lineOpen && readingLine != null) {\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator);\n let ret = readingLine.slice(0, splitPos);\n if (splitPos == -1) {\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1);\n // it(ret, readingLine, splitPos);\n if (ret == '' || ret == separator) {\n return readOne(separator);\n } else {\n return ret;\n }\n } else {\n readingLine = readline();\n lineOpen = true;\n if (readingLine == null)\n return '';\n return readOne(separator);\n }\n}\n\nfunction ri() {\n return +readOne();\n}\n\nfunction ria() {\n return readInts();\n}\n/**\n * @return {string}\n */\nfunction rs() {\n return readOne();\n}\n/**\n * @return {string[]}\n */\nfunction rsa() {\n return readline().split(' ');\n}\n/**\n * @returns {number[]}\n */\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\nlet inputListener;\nlet readlines;\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n inputListener = (line) => {\n console.log(line);\n if (line.startsWith('end')) {\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n };\n readlines = () => {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n };\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n };\n readline = function (trim = true) {\n const lineval = lines.next().value;\n return trim ? lineval.trim() : lineval;\n };\n readlines();\n break;\n case CODEFORCES_NODE:\n input = process.stdin;\n inputListener = (line) => {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n };\n readlines = () => {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n };\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n };\n readline = function (trim = true) {\n const lineval = lines.next().value;\n return trim ? lineval.trim() : lineval;\n };\n readlines();\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n readline = function (trim = true) {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return trim ? lines[lineCount - 1].trim() : lines[lineCount - 1];\n else\n return null;\n };\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n };\n // lines = getlines(input);\n closing();\n break;\n case PROGRAMMERS:\n //\uc790\uccb4 \ud568\uc218\ub97c \uc2e4\ud589\ud560 \uac83\uc774\ubbc0\ub85c \uc544\ubb34\uac83\ub3c4 \ud558\uc9c0 \uc54a\ub294\ub2e4.\n default:\n break;\n}\n\nfunction closing() {\n if (DEBUG) {\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n console.warn('done. running custom tests');\n RunCustomTests();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst matrix = [];\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const col = [...str];\n matrix.push(col);\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 1; i < matrix.length - 1; i++) {\n for (let j = 1; j < matrix.length - 1; j++) {\n if (matrix[i][j] === 'X' && matrix[i - 1][j - 1] === 'X' && matrix[i - 1][j + 1] === 'X' && matrix[i + 1][j - 1] === 'X' && matrix[i + 1][j + 1] === 'X') {\n ans++;\n }\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "n=+readline()\na=[]\nfor (i=0;i +item);\n }\n }\n\n\n\n var n = read.number();\n var arr = [];\n for(var i = 0; i < n; i++) {\n arr[i] = [];\n arr[i] = read.arr();\n }\n\n var count = 0;\n\n for(var i = 1; i < n - 1; i++) {\n for(var j = 1; j < n - 1; j++) {\n if(arr[i][j] == 'X' && arr[i - 1][j - 1] == 'X' && arr[i + 1][j + 1] == 'X' && arr[i - 1][j + 1] == 'X' && arr[i + 1][j - 1] == 'X') {\n count++;\n }\n }\n }\n\n print(count);\n}());"}], "negative_code": [], "src_uid": "3270260030fc56dda3e375af4dad9330"} {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n let lines = i.split(EOL)\r\n let color = 'blue';\r\n let status = 'unlock'\r\n lines = lines.slice(1, lines.length - 1);\r\n lines.forEach(item => {\r\n switch (item) {\r\n case 'unlock':\r\n status = 'unlock';\r\n break;\r\n case 'lock':\r\n status = 'lock';\r\n break;\r\n default:\r\n if (status === 'lock') {\r\n break;\r\n } else if (status === 'unlock') {\r\n color = item;\r\n }\r\n }\r\n });\r\n console.log(color);\r\n});\r\n", "positive_code": [{"source_code": "const fs = require('fs');\nconst readline = require('readline');\nconst path = require('path')\n\nclass CommandsCounter {\n count = undefined\n\n isInited() {\n return typeof this.count !== 'undefined';\n }\n\n setInitialCount(count) {\n if (this.isInited()) {\n throw new Error('Commands counter is already inited');\n }\n\n this.count = count;\n }\n\n isCommandsLeft() {\n return this.count > 0;\n }\n\n decreaseCounter() {\n this.count--;\n }\n}\n\nclass ZingerLight {\n color = 'blue';\n commandsCounter = 0\n isLocked = false;\n\n commandsCounter\n\n constructor(commandsCounter) {\n this.commandsCounter = commandsCounter;\n }\n\n get currentColor() {\n return this.color;\n }\n\n exec(command) {\n switch(command) {\n case 'lock':\n return this.lock();\n case 'unlock':\n return this.unlock();\n case 'red':\n case 'orange':\n case 'yellow':\n case 'green':\n case 'blue':\n case 'indigo':\n case 'violet':\n return this.setColor(command);\n default:\n console.log(`Command \"${command}\" is not recognized`);\n }\n }\n\n lock() {\n this.isLocked = true;\n }\n\n unlock() {\n this.isLocked = false;\n }\n\n setColor(color) {\n if (!this.isLocked) {\n this.color = color;\n }\n }\n}\n\n// MAIN\n\nfunction main() {\n const zingerLight = new ZingerLight();\n const commandsCounter = new CommandsCounter();\n // const readStream = fs.createReadStream(path.resolve(__dirname, './input_1'));\n const readStream = process.stdin;\n\n const lineCallback = (line) => processLine(zingerLight, commandsCounter, line);\n const closeCallback = () => sendAnswer(zingerLight.currentColor);\n\n initInputRead(readStream, lineCallback, closeCallback);\n}\n\nmain();\n\n// ---\n\nfunction initInputRead(inputInterface, lineCb, closeCb) {\n const readInterface = readline.createInterface({\n input: inputInterface,\n });\n\n readInterface.on('line', line => lineCb(line));\n readInterface.on('close', () => closeCb());\n}\n\nfunction processLine(zingerLight, commandsCounter, line) {\n // first line: init counter\n if (!commandsCounter.isInited()) {\n commandsCounter.setInitialCount(Number(line));\n return;\n }\n\n // exec commands while counter of commands is more than inited in first line\n if (commandsCounter.isCommandsLeft()) {\n zingerLight.exec(line);\n commandsCounter.decreaseCounter();\n return;\n }\n}\n\nfunction sendAnswer(answer) {\n process.stdout.write(answer);\n process.stdout.write('\\n');\n}\n\n\n"}, {"source_code": "const fs = require('fs');\r\nconst print = console.log;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nconst COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\r\n\r\nlet n = +input[0];\r\nlet state = 'unlock';\r\nlet color = 'blue';\r\n\r\nfor (let i = 1; i <= n; i++) {\r\n let cmd = input[i];\r\n\r\n switch (cmd) {\r\n case 'lock':\r\n case 'unlock':\r\n state = cmd;\r\n break;\r\n default:\r\n if (state == 'unlock') {\r\n color = cmd;\r\n }\r\n }\r\n}\r\n\r\nprint(color);\r\n"}, {"source_code": "var readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nvar count_of_commands\r\nvar commands = []\r\nfunction start() {\r\n rl.question(\"\", function(answer) {\r\n count_of_commands = parseInt(answer)\r\n get_com()\r\n });\r\n}\r\n\r\nfunction get_command() {\r\n rl.question(\"\", function(answer) {\r\n commands.push(answer)\r\n count_of_commands--\r\n get_com()\r\n });\r\n \r\n}\r\n\r\nfunction get_com() {\r\n if (count_of_commands > 0) {\r\n get_command()\r\n } else {\r\n get_color()\r\n }\r\n}\r\n\r\nfunction get_color() {\r\n var locked = false\r\n var color = \"blue\"\r\n commands.forEach((com, cim_index) => {\r\n if (com == \"lock\") {\r\n locked = true\r\n } else if (com == \"unlock\") {\r\n locked = false\r\n } else {\r\n if (locked == false) {\r\n color = com\r\n }\r\n }\r\n })\r\n console.log(color)\r\n}\r\n\r\nstart();\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nconst defaultColor = 'blue';\r\nconst colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\r\n\r\nlet locked = false;\r\nlet currentColor = 'blue';\r\nlet argumentsFlow = [];\r\n\r\nrl.on('line', function(line){\r\n argumentsFlow.push(line);\r\n});\r\n\r\nrl.on('close', function() {\r\n for (let i = 0; i < argumentsFlow.length; i++) {\r\n if (colors.includes(argumentsFlow[i]) && !locked) {\r\n currentColor = argumentsFlow[i];\r\n } \r\n else if (argumentsFlow[i] === 'lock') {\r\n locked = true;\r\n }\r\n else if (argumentsFlow[i] === 'unlock') {\r\n locked = false;\r\n }\r\n \r\n }\r\n process.stdout.write(currentColor);\r\n})\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', ];\n\nfunction program(lines) {\n\n const count = Number(lines[0]);\n\n let color = \"blue\";\n let locked = false;\n\n for (let i = 1; i <= count; i++) {\n const command = lines[i].trim();\n if (command === \"lock\" && !locked) {\n locked = true;\n }\n if (command === \"unlock\" && locked) {\n locked = false;\n }\n if (colors.includes(command) && !locked) {\n color = command;\n }\n }\n\n return color;\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL)\n console.log(program(lines));\n})"}, {"source_code": "const n = readline();\r\nvar nowStatus = \"blue\";\r\nvar flag = false;\r\nfor (var i = 0; i < n; i++) {\r\n var command = readline();\r\n \r\n switch (command) {\r\n case 'lock':\r\n flag = true;\r\n break;\r\n case 'unlock':\r\n flag = false;\r\n break;\r\n default:\r\n if (!flag) {\r\n nowStatus = command;\r\n }\r\n }\r\n}\r\n\r\nprint(nowStatus);"}, {"source_code": "const readline = require('readline');\nconst { stdin: input, stdout: output } = require('process');\n\nconst rl = readline.createInterface({ input, output });\n\nconst COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\n\nlet isLocked = false;\nlet currentColor = \"blue\";\n\nrl.on('line', function foo(input) {\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n if (COLORS.includes(input)) {\n currentColor = input;\n }\n});\n\nrl.on('close', function boo(input) {\n console.log(currentColor);\n});"}, {"source_code": "const readline = require('readline');\nconst { stdin: input, stdout: output } = require('process');\n\nconst rl = readline.createInterface({ input, output });\n\nlet isLocked = false;\nlet currentColor = \"blue\";\n\nconst COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\n\nrl.on('line', function foo(input) {\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n if (COLORS.includes(input)) {\n currentColor = input;\n }\n});\n\nrl.on('close', function boo(input) {\n console.log(currentColor);\n});"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet currentState = 'unlock'\nlet currentColor = 'blue'\nlet i = 0\n\nrl\n .on('line', value => {\n if (i === 0) {\n i++\n return\n }\n if (value === 'lock' || value === 'unlock') {\n currentState = value\n return;\n }\n if (currentState !== 'lock') {\n currentColor = value\n }\n })\n .on('close', () => {\n process.stdout.write(currentColor)\n })"}, {"source_code": "var readline = require('readline');\nvar fs = require('fs');\nvar rl = readline.createInterface({\n // input: fs.createReadStream('./A.txt'),\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\n// function A (content) {\n// let currentState = 'unlock'\n// let currentColor = 'blue'\n// for (let i = 0; i < content.length; i++) {\n// let value = content[i]\n// if (i === 0) {\n// continue\n// }\n// if (content[i] === 'lock' || content[i] === 'unlock') {\n// currentState = value\n// continue\n// }\n// if (currentState !== 'lock') {\n// currentColor = value\n// }\n// }\n// return currentColor\n// }\n\nlet currentState = 'unlock'\nlet currentColor = 'blue'\nlet i = 0\n\nrl\n .on('line', value => {\n if (i === 0) {\n i++\n return\n }\n if (value === 'lock' || value === 'unlock') {\n currentState = value\n return;\n }\n if (currentState !== 'lock') {\n currentColor = value\n }\n i++\n })\n .on('close', () => {\n process.stdout.write(currentColor)\n })\n\n// module.exports = A"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet quantity = 0;\r\nlet flag = false;\r\nlet output = 'blue';\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n quantity = line;\r\n } else {\r\n switch (line) {\r\n case 'lock':\r\n flag = true\r\n break;\r\n case 'unlock':\r\n flag = false\r\n break;\r\n case 'red':\r\n case 'orange':\r\n case 'yellow':\r\n case 'green':\r\n case 'blue':\r\n case 'indigo':\r\n case 'violet':\r\n output = !flag ? line : output;\r\n break;\r\n }\r\n }\r\n \r\n if (count == quantity) {\r\n console.log(output);\r\n }\r\n \r\n count++;\r\n \r\n});"}, {"source_code": "let inputString = '';\n\nprocess.stdin.on('data', chunk => inputString += chunk);\nprocess.stdin.on('end', () => {\n const lines = inputString\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.length > 0);\n\n const count = +lines[0];\n const messages = lines.slice(1, count + 1);\n\n const LOCK = 'lock';\n const UNLOCK = 'unlock';\n const ALLOW_COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\n\n let isLock = false;\n let currentColor = 'blue';\n\n messages.forEach((message) => {\n if (message === UNLOCK) {\n isLock = false;\n }\n\n if (message === LOCK) {\n isLock = true;\n }\n\n if (ALLOW_COLORS.includes(message) && !isLock) {\n currentColor = message;\n }\n });\n\n console.log(currentColor);\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const N = parseInt(lines[0]);\n let res = 'blue';\n let isUnlock = true;\n\n const color = {\n blue: 'blue',\n red: 'red',\n orange: 'orange',\n yellow: 'yellow',\n green: 'green',\n indigo: 'indigo',\n violet: 'violet',\n };\n\n for (let i = 1; i < lines.length; i++) {\n if (lines[i] === 'lock') {\n isUnlock = false;\n } else if (lines[i] === 'unlock') {\n isUnlock = true;\n }\n if (isUnlock) {\n if (color[lines[i]] != undefined) {\n res = lines[i];\n }\n }\n }\n\n console.log(res);\n});\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let ans = 'blue'\r\n let lock = 'lock'\r\n let unlock = 'unlock'\r\n let locked = false\r\n for (let i = 0; i < n; ++i) {\r\n let next = await nextString()\r\n if (next === lock) {\r\n locked = true\r\n }\r\n else if (next === unlock) {\r\n locked = false\r\n }\r\n else if (!locked) {\r\n ans = next\r\n }\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "function solveProblem(problem) {\r\n // console.log('Problem: ', problem);\r\n let arr = problem.values;\r\n let color = 'blue';\r\n let locked = false;\r\n for (let i = 0; i < arr.length; i++) {\r\n // console.log(arr[i]);\r\n let val = arr[i];\r\n\r\n switch (val) {\r\n case 'lock':\r\n locked = true;\r\n break;\r\n case 'unlock':\r\n locked = false;\r\n break;\r\n case 'red':\r\n case 'orange':\r\n case 'yellow':\r\n case 'green':\r\n case 'blue':\r\n case 'indigo':\r\n case 'violet':\r\n if (!locked) {\r\n color = val;\r\n }\r\n break;\r\n default:\r\n //\r\n }\r\n }\r\n console.log(color);\r\n}\r\n\r\nfunction readInput() {\r\n const readline = require('readline')\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n })\r\n \r\n let problem = {\r\n N: 0,\r\n values: []\r\n }\r\n \r\n rl.on('line', function (line) {\r\n // TODO: Process input\r\n if (problem.N === 0) {\r\n // Get number of test cases from first line\r\n problem.N = Number(line)\r\n } else {\r\n // TODO process the rest of the data\r\n // const arr = line.split(' ');\r\n if (line.length > 0) {\r\n problem.values.push(line);\r\n }\r\n }\r\n })\r\n \r\n .on('close', () => {\r\n // Finished processing input, now solve question\r\n solveProblem(problem)\r\n process.exit()\r\n })\r\n }\r\n \r\nreadInput()\r\n"}, {"source_code": "const readline = require('readline');\n\nlet color = null;\nlet state = 'unlock';\nlet length = 0;\nlet msgCounter = 0;\nlet lastColor = 'blue';\nconst commandList = [];\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction checkHistory() {\n commandList.forEach((item, index) => {\n switch (item) {\n case 'lock':\n case 'unlock':\n color = lastColor;\n state = item;\n break;\n default:\n if (state === 'unlock') {\n color = item;\n lastColor = color;\n }\n }\n });\n}\n\nrl.on('line', input => {\n if (length === 0) length = +(input);\n else commandList.push(input);\n\n if (length === msgCounter) {\n checkHistory();\n console.log(color);\n rl.close();\n } else msgCounter++;\n});"}], "negative_code": [{"source_code": "var readline = require('readline');\nvar { stdin: input, stdout: output } = require('process');\n\nvar rl = readline.createInterface({ input, output });\n\nvar isLocked = false;\nvar currentColor = \"blue\";\n\nrl.on('line', function foo(input) {\n if (typeof input === \"number\") {\n return;\n }\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n currentColor = input;\n});\n\nrl.on('close', function boo(input) {\n console.log(currentColor);\n});"}, {"source_code": "var readline = require('readline');\nvar { stdin: input, stdout: output } = require('process');\n\nvar rl = readline.createInterface({ input, output });\n\nvar isLocked = false;\nvar currentColor = \"blue\";\n\nrl.on('line', function foo(input) {\n if (typeof input === \"number\") {\n return;\n }\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n currentColor = input;\n});\n\nrl.on('close', function boo(input) {\n console.log(currentColor);\n rl.close();\n});"}, {"source_code": "var readline = require('readline');\nvar { stdin: input, stdout: output } = require('process');\n\nvar rl = readline.createInterface({ input, output });\n\nvar isLocked = false;\nvar currentColor = \"blue\";\n\nrl.on('line', function foo(input) {\n if (typeof input === \"number\") {\n return;\n }\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n currentColor = input;\n});\n\nrl.on('close', function boo(input) {\n rl.write(currentColor);\n});"}, {"source_code": "var readline = require('readline');\nvar { stdin: input, stdout: output } = require('process');\n\nvar rl = readline.createInterface({ input, output });\n\nvar isLocked = false;\nvar currentColor = \"blue\";\n\nrl.on('line', function foo(input) {\n if (typeof input === \"number\") {\n return;\n }\n if (input === \"lock\") {\n isLocked = true;\n return;\n }\n if (input === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n currentColor = input;\n});\n\nrl.on('close', function boo(input) {\n rl.write(currentColor);\n});\n"}, {"source_code": "module.exports = function color(...args) {\n let isLocked = false;\n let currentColor = \"blue\";\n\n args.forEach((arg) => {\n if (typeof arg === \"number\") {\n return;\n }\n if (arg === \"lock\") {\n isLocked = true;\n return;\n }\n if (arg === \"unlock\") {\n isLocked = false;\n return;\n }\n if (isLocked) {\n return;\n }\n currentColor = arg;\n });\n\n return currentColor;\n}"}, {"source_code": "var readline = require('readline');\nvar fs = require('fs');\nvar rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('./A.txt'),\n output: process.stdout,\n terminal: false\n});\n\n// function A (content) {\n// let currentState = 'unlock'\n// let currentColor = 'blue'\n// for (let i = 0; i < content[0]; i++) {\n// if (i === 0) {\n// continue\n// }\n// if (currentState === 'lock') continue\n// if (content[i] === 'lock' || content[i] === 'unlock') {\n// currentState = content[i]\n// continue\n// }\n// else currentColor = content[i]\n// }\n// return currentColor\n// }\n//\n// module.exports = A\n\nlet currentState = 'unlock'\nlet currentColor = 'blue'\nlet i = 0\n\nrl\n .on('line', line => {\n if (i === 0) {\n i++\n return\n }\n if (currentState === 'lock') return\n switch (line) {\n case 'lock':\n case 'unlock':\n currentState = line\n return;\n case 'red':\n case 'orange':\n case 'yellow':\n case 'green':\n case 'blue':\n case 'indigo':\n case 'violet':\n currentColor = line\n break\n }\n })\n .on('close', () => {\n process.stdout.write(currentColor)\n })\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet currentState = 'unlock'\nlet currentColor = 'blue'\nlet i = 0\n\nrl\n .on('line', line => {\n if (i === 0) {\n i++\n return\n }\n if (currentState === 'lock') return\n if (line === 'lock' || line === 'unlock') {\n currentState = line\n return\n }\n else currentColor = line\n i++\n })\n .on('close', () => {\n process.stdout.write(currentColor)\n })\n"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet quantity = 0;\r\nlet flag = false;\r\nlet output = 'blue';\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n quantity = line;\r\n } else {\r\n switch (line) {\r\n case 'lock':\r\n flag = true\r\n break;\r\n case 'unlock':\r\n flag = false\r\n break;\r\n case 'red':\r\n case 'orange':\r\n case 'yellow':\r\n case 'green':\r\n case 'blue':\r\n case 'indigo':\r\n case 'violet':\r\n output = !flag ? line : output;\r\n break;\r\n }\r\n }\r\n \r\n if (count == quantity) {\r\n console.log('output', output);\r\n }\r\n \r\n count++;\r\n \r\n});"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet quantity = '';\r\nlet flag = false;\r\nlet output = 'blue';\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n quantity = line;\r\n } else {\r\n switch (line) {\r\n case 'lock':\r\n flag = true\r\n break;\r\n case 'unlock':\r\n flag = false\r\n break;\r\n case 'red':\r\n case 'orange':\r\n case 'yellow':\r\n case 'green':\r\n case 'blue':\r\n case 'indigo':\r\n case 'violet':\r\n output = !flag ? line : output;\r\n break;\r\n }\r\n }\r\n \r\n count++\r\n \r\n if (count == quantity) {\r\n console.log(output);\r\n }\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet quantity = '';\r\nlet flag = false;\r\nlet output = 'blue';\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n quantity = line;\r\n } else {\r\n switch (line) {\r\n case 'lock':\r\n flag = true\r\n break;\r\n case 'unlock':\r\n flag = false\r\n break;\r\n default:\r\n output = !flag ? line : output;\r\n break;\r\n }\r\n }\r\n \r\n count++\r\n \r\n if (count == quantity) {\r\n console.log(output);\r\n }\r\n});"}, {"source_code": "const messagesString = `5\nlock\nunlock\nlock\nunlock\nunlock\n`;\n\nconst lines = messagesString\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.length > 0);\n\nconst count = +lines[0];\nconst messages = lines.slice(1, count + 1);\n\nconst LOCK = 'lock';\nconst UNLOCK = 'unlock';\nconst ALLOW_COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];\n\nlet isLock = false;\nlet currentColor = 'blue';\n\nmessages.forEach((message) => {\n if (message === UNLOCK) {\n isLock = false;\n }\n\n if (message === LOCK) {\n isLock = true;\n }\n\n if (ALLOW_COLORS.includes(message) && !isLock) {\n currentColor = message;\n }\n});\n\nconsole.log(currentColor);"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n let lines = i.split(EOL)\r\n let color = 'blue';\r\n let status = 'unlock'\r\n lines = lines.slice(1);\r\n lines.forEach(item => {\r\n switch (item) {\r\n case 'unlock':\r\n status = 'unlock';\r\n break;\r\n case 'lock':\r\n status = 'lock';\r\n break;\r\n default:\r\n if (status === 'lock') {\r\n break;\r\n } else if (status === 'unlock') {\r\n color = item;\r\n }\r\n }\r\n });\r\n console.log(color);\r\n});\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const N = parseInt(lines[0]);\n let res = 'blue';\n let isUnlock = true;\n\n const color = {\n blue: 'blue',\n red: 'red',\n orange: 'orange',\n yellow: 'yellow',\n green: 'green',\n indigo: 'indigo',\n violet: 'violet',\n };\n\n for (let i = 1; i < N; i++) {\n if (lines[i] === 'lock') {\n isUnlock = false;\n } else if (lines[i] === 'unlock') {\n isUnlock = true;\n }\n if (isUnlock) {\n if (color[lines[i]] != undefined) {\n res = lines[i];\n }\n }\n }\n\n console.log(res);\n});\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let ans = 'blue'\r\n let lock = 'lock'\r\n let unlock = 'unlock'\r\n let locked = false\r\n for (let i = 0; i < n; ++i) {\r\n let next = await nextString()\r\n if (next === lock) {\r\n locked = true\r\n }\r\n else if (next === unlock) {\r\n locked = false\r\n }\r\n else if (!locked) {\r\n ans = next\r\n }\r\n }\r\n console.log(next)\r\n}\r\n \r\nmain()\r\n"}], "src_uid": "6215233349b0f682a238a476e9153ac4"} {"source_code": "const main = (data) => {\n const testsCount = data[0];\n\n for (let i = 1; i <= testsCount; i++) {\n let [n, k] = data[i * 2 - 1].split(' ');\n const arr = data[i * 2].split(' ');\n\n let index = 1;\n let result = 0;\n\n while (k > 0 && index < arr.length) {\n while (arr[index] > 0 && k > 0) {\n k -= index;\n arr[index]--;\n result++;\n }\n\n index++;\n }\n\n if (k < 0) { result-- };\n\n console.log(+arr[0] + result);\n }\n}\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});\n", "positive_code": [{"source_code": "t = +readline();\nwhile (t-->0){\n ar = readline().split(' ').map(Number);\n n = ar[0], m = ar[1];\n sum = 0;\n readline().split(' ').map(Number).forEach((x,ind)=>{\n if (m >= x*ind){\n m -= x*ind;\n sum += x;\n } else {\n sum += Math.floor(m / ind);\n m = 0;\n }\n });\n print(sum);\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr, days) {\n let first = arr[0];\n let rest = days;\n\n for (let i = 1; i < arr.length; i++) {\n if (rest <= 0) return first;\n for (let c = 1; c <= arr[i]; c++) {\n if (rest <= 0) return first;\n if (i <= rest ) {\n first++;\n rest = rest - i;\n }\n }\n }\n\n return first;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let days = lines[testCount * 2 - 1].split(' ').map(Number)[1];\n let arr = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(arr, days);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var N = one[0];\n var d = one[1];\n var list = myconv(next(),4);\n for(var j = 1; j < N; j++){\n if(d >= list[j] * j){\n list[0] += list[j];\n d -= list[j] * j;\n }else{\n //d:5 list[j]:3 * 2\n list[0] += Math.floor(d / j);\n d = 0;\n }\n }\n output[i] = list[0];\n }\n myout(myconv(output,9));\n}"}, {"source_code": "r=readline;for(k=r();k--;print(a)){i=a=0;b=r().split(\" \")[1];r().split(\" \").map(x=>{w=Math.min(x,~~(b/i));a+=i?w:x*1;b-=w*i++})}"}, {"source_code": "r=readline;for(k=r();k--;){x=r().split(\" \");y=r().split(\" \");a=y[0]*1;b=x[1];for(i=1;i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n [n, d] = data.split(' ').map(Number);\n return;\n }\n\n const arr = data.split(' ').map(Number);\n\n while (d > 0) {\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] !== 0) {\n arr[i - 1] += 1;\n arr[i] -= 1;\n break;\n }\n }\n\n d--;\n }\n\n console.log(arr[0]);\n\n c++;\n});\n"}, {"source_code": "(function () {\n var inp = \"\";\n process.stdin.on(\"data\", function (d) { return inp += d.toString(); });\n process.stdin.on(\"end\", function () { return main(inp); });\n process.stdin.resume();\n})();\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var Ntests = parseInt(lines.shift(), 10);\n for (var i = 0; i < Ntests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); }), numPiles = _a[0], days = _a[1];\n var piles = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); });\n console.log(solve(days, piles));\n }\n}\nfunction solve(days, piles) {\n for (var i = 1; i < piles.length && i <= days; i++) {\n if (piles[i] > 0) {\n piles[i]--;\n piles[0]++;\n days -= i;\n i--;\n }\n }\n return piles[0];\n}\n"}], "negative_code": [{"source_code": "t = +readline();\nwhile (t-->0){\n ar = readline().split(' ').map(Number);\n n = ar[0], m = ar[1];\n sum = 0;\n readline().split(' ').map(Number).forEach((x,ind)=>{\n if (m >= x*ind){\n m -= x*ind;\n sum += x;\n } else {\n sum += Math.floor(m / ind);\n }\n });\n print(sum);\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var N = one[0];\n var d = one[1];\n var list = myconv(next(),4);\n for(var j = 1; j < N; j++){\n if(d > list[j] * j){\n list[0] += list[j];\n d -= list[j] * j;\n }else{\n //d:5 list[j]:3 * 2\n list[0] += Math.floor(d / j * list[j]);\n d = 0;\n }\n }\n output[i] = list[0];\n }\n myout(myconv(output,9));\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var N = one[0];\n var d = one[1];\n var list = myconv(next(),4);\n for(var j = 1; j < N; j++){\n if(d >= list[j] * j){\n list[0] += list[j];\n d -= list[j] * j;\n }else{\n //d:5 list[j]:3 * 2\n list[0] += Math.floor(d % list[j]);\n d = 0;\n }\n }\n output[i] = list[0];\n }\n myout(myconv(output,9));\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr, days) {\n let first = arr[0];\n let rest = days;\n\n for (let i = 1; i < arr.length; i++) {\n if (rest <= 0) return first;\n for (let c = 1; c <= arr[i]; c++) {\n if (rest <= 0) return first;\n if (i + 1 <= rest ) {\n first++;\n rest = rest - i;\n }\n }\n }\n\n return first;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let days = lines[testCount * 2 - 1].split(' ').map(Number)[1];\n let arr = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(arr, days);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "(function () {\n var inp = \"\";\n process.stdin.on(\"data\", function (d) { return inp += d.toString(); });\n process.stdin.on(\"end\", function () { return main(inp); });\n process.stdin.resume();\n})();\nfunction main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var Ntests = parseInt(lines.shift(), 10);\n for (var i = 0; i < Ntests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); }), numPiles = _a[0], days = _a[1];\n var piles = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); });\n console.log(solve(days, piles));\n }\n}\nfunction solve(days, piles) {\n for (var i = 1; i < piles.length && i < days; i++) {\n if (piles[i] > 0) {\n piles[i]--;\n piles[0]++;\n days -= i;\n i--;\n }\n }\n return piles[0];\n}\n"}], "src_uid": "7bbb4b9f5eccfe13741445c815a4b1ca"} {"source_code": "var n,a,i,b,c,f,r,e,l,t,d,g=1000000007,h=readline();n=a=1;i=0;for(c=t=0,d=h.length;t\\n console.log sweep str';\n\n}).call(this);\n"}, {"source_code": "var n,a,i,b,c,f,r,e,l,t,d,g=1000000007,h=readline();n=a=1;i=0;for(c=t=0,d=h.length;t\\n console.log sweep str';\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var sweep;\n\n sweep = function(str) {\n var char, i, newState, state, _i, _len;\n state = {\n require: 1,\n norequire: 1,\n bomb: 0\n };\n for (i = _i = 0, _len = str.length; _i < _len; i = ++_i) {\n char = str[i];\n newState = {};\n if (char === '?') {\n newState.require = state.bomb + state.norequire;\n newState.norequire = state.bomb + state.norequire;\n newState.bomb = state.bomb + state.require;\n } else if (char === '*') {\n newState.bomb = state.require + state.bomb;\n newState.require = newState.norequire = 0;\n } else if (char === '0') {\n newState.norequire = state.norequire;\n newState.require = newState.bomb = 0;\n } else if (char === '1') {\n newState.norequire = state.bomb;\n newState.require = state.norequire;\n newState.bomb = 0;\n } else if (char === '2') {\n newState.require = state.bomb;\n newState.bomb = newState.norequire = 0;\n }\n state = newState;\n console.log(char, state);\n }\n return state.norequire + state.bomb;\n };\n\n 'readline = require \\'readline\\'\\nreadline.createInterface(\\n input: process.stdin\\n output: process.stdout\\n terminal: false\\n).on \\'line\\', (str) ->\\n console.log sweep str';\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var sweep;\n\n sweep = function(str) {\n var char, i, newState, state, _i, _len;\n state = {\n require: 1,\n norequire: 1,\n bomb: 0\n };\n for (i = _i = 0, _len = str.length; _i < _len; i = ++_i) {\n char = str[i];\n newState = {};\n if (char === '?') {\n newState.require = state.bomb + state.norequire;\n newState.norequire = state.bomb + state.norequire;\n newState.bomb = state.bomb + state.require;\n } else if (char === '*') {\n newState.bomb = state.require + state.bomb;\n newState.require = newState.norequire = 0;\n } else if (char === '0') {\n newState.norequire = state.norequire;\n newState.require = newState.bomb = 0;\n } else if (char === '1') {\n newState.norequire = state.bomb;\n newState.require = state.norequire;\n newState.bomb = 0;\n } else if (char === '2') {\n newState.require = state.bomb;\n newState.bomb = newState.norequire = 0;\n }\n state = newState;\n }\n return state.norequire + state.bomb;\n };\n\n print(sweep(readline()));\n\n 'readline = require \\'readline\\'\\nreadline.createInterface(\\n input: process.stdin\\n output: process.stdout\\n terminal: false\\n).on \\'line\\', (str) ->\\n console.log sweep str';\n\n}).call(this);\n"}], "src_uid": "c16c49baf7b2d179764871204475036e"} {"source_code": "'use strict';\n\n// var inpArr = `\n// 12\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nvar str = readline().trim();\n\nprint(str + str.split('').reverse().join(''))\n", "positive_code": [{"source_code": "var n = readline();\nprint(n + [...n].reverse().join(''));"}, {"source_code": "var n = readline();\nvar n_ = n.split('').reverse().join('');\n\nprint(n+n_);"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, reverse;\n\nn = readline();\nanswer = n + n.split('').reverse().join('');\n\nwrite(answer);"}, {"source_code": "var s = readline();\nvar s_ = \"\";\nfor (var i in s) {\n\ts_ = s[i] + s_;\n}\nwrite(s+s_);"}, {"source_code": "// na\u010dtu \u010d\u00edslo\nvar number = readline();\n\nvar result = number;\nvar t = result;\n\nfor (var i = t.length-1; i >= 0; i--) {\n\tresult += t[i];\n}\n\n\nwrite(result);"}, {"source_code": "var str = readline().trim();\nstr += str.split('').reverse().join('');\nprint(str);\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine().split('');\n\tlet res = n.join('') + n.reverse().join('');\n\tconsole.log(res);\n}\n"}, {"source_code": "var n = readline();\n\nwrite(n);\nn = n.split(\"\").reverse().join(\"\");\nwrite(n);"}], "negative_code": [{"source_code": "// na\u010dtu \u010d\u00edslo\nvar number = Number(readline());\n\nvar result = String(number);\nvar t = result;\n\nfor (var i = t.length-1; i >= 0; i--) {\n\tresult += t[i];\n}\n\n\nwrite(result);"}], "src_uid": "bcf75978c9ef6202293773cf533afadf"} {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let s = readline();\n LT({s});\n\n // PROCESSING:\n let ans = 0;\n return +s[0]+ +s[1]+ +s[2] ==+s[4]+ +s[5]+ +s[3] ? 'YES' : 'no'\n};\n ", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split('').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[j];\n }else{\n y += a[j];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var a = 0;\n var b = 0;\n for(i = 0; i < 6; i++){\n if(i >= 3){\n a += k[i];\n }else{\n b += k[i];\n }\n }\n if(a == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "\r\n\r\nconst { createInterface } = require('readline');\r\n/*\r\nimport { createWriteStream, createReadStream } from 'fs';\r\nimport { format } from 'util';\r\n\r\nconst log_file = createWriteStream('output.txt', { flags: 'w' }\r\n);\r\nconst log_stdout = process.stdout;\r\nconsole.log = function (d) {\r\n log_file.write(format(d) + '\\n');\r\n log_stdout.write(format(d) + '\\n');\r\n};\r\nconst fileStream = createReadStream('input.txt');\r\n*/\r\nfunction main() {\r\n const readline = createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let lineNb = 0;\r\n let n;\r\n let t = [];\r\n readline.on('line', line => {\r\n if (!lineNb)\r\n n = parseInt(line);\r\n lineNb && t.push(line);\r\n if (lineNb === n) {\r\n for (let i = 0; i < n; i++) {\r\n let s = Array.from(t[i]).map(i => Number(i));\r\n console.log(s[0] + s[1] + s[2] === s[3] + s[4] + s[5] ? \"YES\" : \"NO\");\r\n }\r\n readline.close();\r\n }\r\n lineNb++;\r\n });\r\n // let { n, t } = await processLineByLine();\r\n}\r\n\r\nmain()"}, {"source_code": "const main = (input) => {\r\n input = input.split(\"\\n\");\r\n const t = parseInt(input[0]);\r\n\r\n for (let i = 0; i < t; i++) {\r\n const digits = input[i + 1];\r\n const head = digits\r\n .substring(0, 3)\r\n .split(\"\")\r\n .map(Number)\r\n .reduce((a, b) => a + b, 0);\r\n const tail = digits\r\n .substring(3, 6)\r\n .split(\"\")\r\n .map(Number)\r\n .reduce((a, b) => a + b, 0);\r\n\r\n console.log(head === tail ? \"YES\" : \"NO\");\r\n }\r\n};\r\n\r\nmain(require(\"fs\").readFileSync(0, \"utf8\"));"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n; j++){\n var a = lines[j].split('').map(Number)\n if(a[0] + a[1] + a[2] == a[3] + a[4] + a[5]){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n \n}); \n"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const s = readLine();\r\n \r\n const res = MY_FUNC(s);\r\n \r\n console.log(res)\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction MY_FUNC(s){\r\n ans = 'YES';\r\n a = 0;\r\n b = 0;\r\n for(let i = 0 ; i < s.length; i++){\r\n if(i < 3){\r\n a += parseInt(s[i]);\r\n } else {\r\n b += parseInt(s[i]);\r\n }\r\n }\r\n a == b ? ans = 'YES' : ans = 'NO';\r\n return ans;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet [inputString, currentLine] = ['', 0];\r\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\nconst input = () => inputString[currentLine++];\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const t = input().split('').map(Number);\r\n if(t[0]+t[1]+t[2] === t[3]+t[4]+t[5]) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const t = input().split('').map(Number);\r\n if(t[0]+t[1]+t[2] === t[3]+t[4]+t[5]) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n while(t--) {\r\n let line = readLine();\r\n line = line.split(\"\");\r\n if(parseInt(line[0])+parseInt(line[1])+parseInt(line[2])==parseInt(line[line.length-3])+parseInt(line[line.length-2])+parseInt(line[line.length-1]))\r\n\t {console.log(\"YES\");}\r\n\t\telse console.log(\"NO\");\r\n\t \r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet inp = [];\r\n\r\nreadline.on('line', line => {\r\n inp.push(line);\r\n}).on('close', () => {\r\n let cases = inp.slice(1);\r\n for (let c of cases) {\r\n let n = c.split('').map(Number);\r\n console.log(n[0]+n[1]+n[2] === n[3]+n[4]+n[5] ? 'YES' : 'NO');\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1, d1, e1, f1] = d.split(\"\").map(Number);\n const ans = a1 + b1 + c1 === d1 + e1 + f1 ? \"YES\" : \"NO\";\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [a, b, c, d, e, f] = readline().split('').map(Number);\r\n output((a + b + c) === (d + e + f) ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = readline().split(\"\").map(Number);\r\n var sum1 = 0;\r\n var sum2 = 0;\r\n for (let i = 0; i < 3; i++) {\r\n sum1 = n[i] + sum1;\r\n }\r\n for (let i = 3; i < 6; i++) {\r\n sum2 = n[i] + sum2;\r\n }\r\n if (sum1 === sum2) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var n = parseInt(readline());\r\n let arr = [];\r\n \r\n for (let i = 0; i < n; i++) {\r\n let num = readline();\r\n let a = num.split('');\r\n \r\n for (let j = 0; j < 6; j++) {\r\n a[j] = parseInt(a[j]);\r\n }\r\n \r\n if (a[0] + a[1] + a[2] === a[3] + a[4] + a[5]) arr[i] = \"YES\";\r\n else arr[i] = \"NO\";\r\n }\r\n \r\n for (let i = 0; i < n; i++) {\r\n console.log(arr[i]);\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line();\n\t\tlet a = s.substring(0, 3).split('').map(Number).reduce((x, a) => a + x, 0);\n\t\tlet b = s.substring(3).split('').map(Number).reduce((x, a) => a + x, 0);\n\t\tans.push(a === b);\n\t}\n\tconsole.log(ans.map(x => x?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "function solve(inp) {\r\n var n = Number(inp.nextLine());\r\n while(n--) {\r\n const ss = inp.nextLine();\r\n const s1 = [...ss.substring(0, 3)].reduce((sum, c) => sum + Number(c), 0);\r\n const s2 = [...ss.substring(3, 6)].reduce((sum, c) => sum + Number(c), 0);\r\n\r\n console.log(s1 == s2 ? \"YES\" : \"NO\");\r\n }\r\n}\r\n\r\n\r\nclass Input {\r\n constructor(lines) {\r\n this.lines = lines;\r\n this.next = 0;\r\n }\r\n \r\n addLine(line) {\r\n this.lines.push(line) \r\n }\r\n \r\n hasLine() {\r\n return this.lines.size() > 0; \r\n }\r\n \r\n nextLine() {\r\n const line = this.lines[this.next];\r\n if (line) {\r\n this.next++;\r\n }\r\n return line;\r\n }\r\n}\r\n\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst inp = new Input([]);\r\n\r\nreadline.on('line', line => {\r\n inp.addLine(line);\r\n});\r\n\r\nreadline.on('close', () => {\r\n solve(inp);\r\n});"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n function foo (data) {\r\n const [a, b, c, d, e, f] = Array.from(data).map(Number);\r\n return a + b + c === d + e + f ? 'YES' : 'NO';\r\n }\r\n \r\n let testCount = 1;\r\n let answer = '';\r\n while(testCount <= +lines[0]) {\r\n let data = lines[testCount]\r\n let result = foo(data);\r\n answer += result +\"\\n\";\r\n testCount++;\r\n }\r\n console.log(answer);\r\n})"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n \r\n let input = Number.parseInt(readline())\r\n while(input-- > 0){\r\n let num = readline()\r\n let arr = Array.from(num)\r\n let first = Number.parseInt(arr[0]) + Number.parseInt(arr[1]) + Number.parseInt(arr[2])\r\n let sec = Number.parseInt(arr[3]) + Number.parseInt(arr[4]) + Number.parseInt(arr[5])\r\n print(first === sec ? 'YES' : 'NO')\r\n }\r\n}\r\n"}, {"source_code": "const solve = (arr) => {\r\n let sum1=0,sum2=0;\r\n for(let i=0;i<3;i++) sum1+=arr[i];\r\n for(let i=3;i<6;i++) sum2+=arr[i];\r\n if(sum1===sum2) console.log(\"YES\");\r\n else console.log(\"NO\")\r\n};\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let n = parseInt(readline());\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n const nums = s.split('').map(Number);\r\n if (nums[0] + nums[1] + nums[2] === nums[3] + nums[4] + nums[5]) {\r\n return 'YES';\r\n } else {\r\n return 'NO';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const s = await read();\r\n res.push(solve(s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\n\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n let input = line.split(\"\").map(Number);\n\n console.log(\n input[0] + input[1] + input[2] === input[3] + input[4] + input[5]\n ? \"YES\"\n : \"NO\"\n );\n }\n lines++;\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let str = readLine();\r\n let lsum = 0; rsum = 0;\r\n let l = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n lsum += parseInt(str[i]);\r\n l++;\r\n if (l == 3) {\r\n break;\r\n }\r\n }\r\n l = 0;\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n rsum += parseInt(str[i]);\r\n l++;\r\n if (l == 3) {\r\n break;\r\n }\r\n }\r\n return rsum == lsum ? \"Yes\" : \"No\";\r\n}\r\n"}, {"source_code": "function processData(data) {\r\n data = data.split(\"\\n\");\r\n const T = data.shift();\r\n let i = 0;\r\n while (i < T) {\r\n const N = data.shift().split(\"\");\r\n const res =\r\n Number(N[0]) + Number(N[1]) + Number(N[2]) ===\r\n Number(N[3]) + Number(N[4]) + Number(N[5]) ? \"YES\" : \"NO\";\r\n console.log(res);\r\n i++;\r\n }\r\n}\r\n\r\n// processData(`5\r\n// 213132\r\n// 973894\r\n// 045207\r\n// 000000\r\n// 055776`);\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nlet _input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var a = readline();\r\n //var a = readline().split(' ').map((x)=>parseInt(x));\r\n var ans_one = 0, ans_two = 0;\r\n for(var i=0;i parseInt(ele));\r\n let sum = 0;\r\n for (let i = 0; i < 6; i++) {\r\n if (i < 3) {\r\n sum+= nums[i]\r\n } else {\r\n sum-= nums[i]\r\n } \r\n }\r\n\r\n const ans = sum === 0 ? \"YES\" : \"NO\"\r\n\r\n\r\n myout(ans)\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const [a, b, c, d, e, f] = str.split('').map(Number)\n return a + b + c === d + e + f\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar L = 0;\r\n\t\tvar R = 0;\r\n\t\tfor(var i = 0; i < 3; i++){\r\n\t\t\tL += myconv(S[i], 1);\r\n\t\t\tR += myconv(S[i + 3], 1);\r\n\t\t}\r\n\t\tif(L == R){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var rows = readline();\r\nwhile (rows--) {\r\n\ti = [...readline()].map(c=>parseInt(c));\r\n\tprint(i[0]+i[1]+i[2] === i[3]+i[4]+i[5]?'YES':'NO')\r\n}\r\n"}, {"source_code": "var rows = readline();\r\nwhile (rows--) {\r\n\ti = Array.prototype.map.call(readline(), (c)=>parseInt(c));\r\n\tprint(i[0]+i[1]+i[2] === i[3]+i[4]+i[5]?\"YES\":\"NO\")\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i =0 ; i < t ; i++){\r\n var arr = [...readline()].map(x => Number(x));\r\n var former = arr.slice(0, 3).reduce((sum, a) => sum + a, 0);\r\n var latter = arr.slice(3, 6).reduce((sum, a) => sum + a, 0);\r\n \r\n if (former === latter ) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split('');\r\n var a = parseInt(inp[0]);\r\n var b = parseInt(inp[1]);\r\n var c = parseInt(inp[2]);\r\n var d = parseInt(inp[3]);\r\n var e = parseInt(inp[4]);\r\n var f = parseInt(inp[5]);\r\n\r\n var happy = a + b + c === d + e + f;\r\n\r\n print(happy ? 'YES' : 'NO');\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var ticket = readline().split(''),\r\n firstThreeDigits = ticket.slice(0,3),\r\n lastThreeDigits = ticket.slice(3,6),\r\n sum1 = 0 , sum2 = 0;\r\n for(var j=0 ; j < 3 ; j++){\r\n sum1 += parseInt(firstThreeDigits[j]) ;\r\n sum2 += parseInt(lastThreeDigits[j]) ;\r\n }\r\n if(sum1 == sum2){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var testCase=+readline()\r\nfor(var i=0;i+node)\r\n var a=sequence.slice(0,3).reduce((a,b)=>a+b)\r\n var b=sequence.slice(-3).reduce((a,b)=>a+b)\r\n if(a===b){\r\n print(\"YES\")\r\n }else{\r\n print(\"NO\")\r\n }\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n x = readline().split('').map(x => +x)\r\n if(x[0]+x[1]+x[2] === x[3]+x[4]+x[5])\r\n print('YES')\r\n else\r\n print('NO')\r\n \r\n}\r\n\r\n"}, {"source_code": "t = parseInt(readline());\r\nfor(i = 0; i < t; i++)\r\n{\r\n var n = readline();\r\n n0 = parseInt(n[0]);\r\n n1 = parseInt(n[1]);\r\n n2 = parseInt(n[2]);\r\n n3 = parseInt(n[3]);\r\n n4 = parseInt(n[4]);\r\n n5 = parseInt(n[5]);\r\n if(n0+n1+n2 === n3+n4+n5) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline();\r\n print(Task1(a));\r\n}\r\n \r\nfunction Task1 (str){\r\n \r\n var test = +str[0] + (+str[1]) + (+str[2]);\r\n var test1 = +str[3] + (+str[4]) + (+str[5]);\r\n if (test === test1){\r\n return 'YES';\r\n }else {\r\n return 'NO';\r\n }\r\n \r\n}"}, {"source_code": "var n = readline()\r\n\r\nfor(var i=0 ; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split('').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[i];\n }else{\n y += a[i];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var k = lines[1].split(' ').map(Number)\n var w = lines[1].split(' ').map(Number)\n var s = 0\n var d = 0\n var sa = true\n for(j = 0; j < n; j++){\n if(k[0] >= w[w.length - 1] && sa === true){\n sa = false\n s += w[0]\n w = ''\n for(b = 1; b < k.length; b++){\n w += k[b]\n }\n }\n \n \n \n else if(k[0] <= w[w.length - 1] && sa === true){\n sa = false\n s += w[w.length - 1]\n w = ''\n for(b = 1; b < k.length; b++){\n w += k[b]\n }\n }\n \n \n else if(k[0] >= w[w.length - 1] && sa === false){\n sa = false\n d += w[0]\n w = ''\n for(b = 1; b < k.length; b++){\n w += k[b]\n }\n }\n \n \n else if(k[0] <= w[w.length - 1] && sa === false){\n sa = false\n d += w[w.length - 1]\n w = ''\n for(b = 1; b < k.length; b++){\n w += k[b]\n }\n }\n }\n console.log(s, d)\n}); \n"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const s = readLine();\r\n \r\n const res = MY_FUNC(s);\r\n \r\n console.log(res[0],res[1])\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction MY_FUNC(s){\r\n ans = 'YES';\r\n a = 0;\r\n b = 0;\r\n for(let i = 0 ; i < s.length; i++){\r\n if(i < 3){\r\n a += parseInt(s[i]);\r\n } else {\r\n b += parseInt(s[i]);\r\n }\r\n }\r\n a == b ? ans = 'YES' : ans = 'NO';\r\n return ans;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n while(t--) {\r\n let line = readLine();\r\n line = line.split(\"\");\r\n if(line[0]+line[1]+line[2]==line[line.length-3]+line[line.length-2]+line[line.length-1])\r\n\t {console.log(\"YES\");}\r\n\t\telse console.log(\"NO\");\r\n\t \r\n }\r\n}\r\n"}, {"source_code": "var rows = readline();\r\nwhile (rows--) {\r\n\trow = readline();\r\n\tprint( Array.prototype.map.call(row, (c)=>parseInt(c)).map((i)=> (i[0]+i[1]+i[2] === i[3]+i[4]+i[5])?\"YES\":\"NO\"))\r\n}"}, {"source_code": "var rows = readline();\r\nwhile (rows--) {\r\n\tprint( Array.prototype.map.call(readline(), (c)=>parseInt(c)).map((i)=> (i[0]+i[1]+i[2] === i[3]+i[4]+i[5])?\"YES\":\"NO\"))\r\n}"}, {"source_code": "[...Array(readline()).keys()].forEach(()=>{\r\n\tprint( Array.prototype.map.call(readline(), (c)=>parseInt(c)).map((i)=> (i[0]+i[1]+i[2] === i[3]+i[4]+i[5])?\"YES\":\"NO\"))\r\n});"}], "src_uid": "c7a5b4a015e28dd3759569bbdc130e93"} {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\nprint(function(n, k, p) {\n\tvar a = readline().split(' ').map(Number);\n\tvar ans = [];\n\tvar s = [];\n\n\tvar x = [];\n\n\tfor (var i = 0; i < n; i++) {\n\t\tif (a[i] % 2 == 0) {\n\t\t\tif (ans.length < p) {\n\t\t\t\tans.push([a[i]]);\n\t\t\t} else {\n\t\t\t\tif (ans.length) {\n\t\t\t\t\tans[0].push(a[i]);\n\t\t\t\t} else {\n\t\t\t\t\tx.push(a[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\ts.push(a[i]);\n\t\t}\n\t}\n\n\tfor (var i = 0, l = p - ans.length; i < l; i++) {\n\t\tif (s.length >= 2) {\n\t\t\tans.push([s.pop(), s.pop()]);\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\tfor (var i = 0, l = k - ans.length; i < l; i++) {\n\t\tif (s.length > 0) {\n\t\t\tans.push([s.pop()]);\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\twhile (s.length > 0) {\n\t\tif (s.length >= 2) {\n\t\t\tans[0].push(s.pop(), s.pop());\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\n\twhile (x.length > 0) {\n\t\tans[0].push(x.pop());\n\t}\n\n\treturn 'YES\\n' + ans.map(function(v) {\n\t\treturn v.length + ' ' + v.join(' ');\n\t}).join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], wantPartitions = data[1], wantEven = data[2],\n\t\twantOdd = wantPartitions - wantEven,\n\t\tinput = tokenizeIntegers(readline()),\n\t\titems = new Array(n), odd = 0, even = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar bit = input[i]%2;\n\t\tif (bit == 0) {\n\t\t\teven += 1;\n\t\t} else {\n\t\t\todd += 1;\n\t\t}\n\t\titems[i] = { value: input[i], bit: bit };\n\t}\n\tif (wantOdd > odd || (odd - wantOdd) % 2 == 1 ||\n\t\t\twantEven > even + (odd - wantOdd) / 2) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\tprint('YES');\n\titems.sort(function (a, b) {\n\t\treturn a.bit - b.bit;\n\t});\n\tvar pos = n-1;\n\tfor (var i = 1; i < wantOdd; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\tif (wantEven != 0 && wantOdd != 0) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\twhile (wantEven > 1 && items[pos].bit == 1) {\n\t\tprint('2 '+items[pos--].value+' '+items[pos--].value);\n\t\t--wantEven;\n\t}\n\tfor (var i = 1; i < wantEven; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\tif (pos != -1) {\n\t\tvar parts = [pos+1];\n\t\twhile (pos != -1) {\n\t\t\tparts.push(items[pos--].value);\n\t\t}\n\t\tprint(parts.join(' '));\n\t}\n}\n\nmain();\n"}, {"source_code": "var info = readline().split(' ').map(Number);\nvar Arr = readline().split(' ').map(Number);\nvar md2 = Arr.filter(function (_) { return _%2==0;});\nvar mnd2 = Arr.filter(function (_) { return _%2==1;});\nvar result = [];\nvar nd2 = info[1] - info[2];\nvar pp = [];\nwhile(mnd2.length > 1 && mnd2.length > nd2) {\n pp.push([mnd2.pop(), mnd2.pop()]);\n}\nif (mnd2.length != nd2 || (pp.length + md2.length) < info[2]) {\n print(\"NO\");\n}\nelse {\n for (var i=0; i= 2) {\n\t\t\tans.push([s.pop(), s.pop()]);\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\tfor (var i = 0, l = k - ans.length; i < l; i++) {\n\t\tif (s.length > 0) {\n\t\t\tans.push([s.pop()]);\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\twhile (s.length > 0) {\n\t\tif (s.length >= 2) {\n\t\t\tans[0].push(s.pop(), s.pop());\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\n\treturn 'YES\\n' + ans.map(function(v) {\n\t\treturn v.length + ' ' + v.join(' ');\n\t}).join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], wantPartitions = data[1], wantEven = data[2],\n\t\twantOdd = wantPartitions - wantEven,\n\t\tinput = tokenizeIntegers(readline()),\n\t\titems = new Array(n), odd = 0, even = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar bit = input[i]%2;\n\t\tif (bit == 0) {\n\t\t\teven += 1;\n\t\t} else {\n\t\t\todd += 1;\n\t\t}\n\t\titems[i] = { value: input[i], bit: bit };\n\t}\n\tif (wantOdd > odd || (odd - wantOdd) % 2 == 1 ||\n\t\t\t(wantEven == 0 && even + (odd - wantOdd) != 0) ||\n\t\t\twantEven > even + (odd - wantOdd) / 2) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\tprint('YES');\n\titems.sort(function (a, b) {\n\t\treturn a.bit - b.bit;\n\t});\n\tvar pos = n-1;\n\tfor (var i = 0; i < wantOdd; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\twhile (wantEven > 1 && items[pos].bit == 1) {\n\t\tprint('2 '+items[pos--].value+' '+items[pos--].value);\n\t\t--wantEven;\n\t}\n\tfor (var i = 1; i < wantEven; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\tif (pos != -1) {\n\t\tvar parts = [pos+1];\n\t\twhile (pos != -1) {\n\t\t\tparts.push(items[pos--].value);\n\t\t}\n\t\tprint(parts.join(' '));\n\t}\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], wantPartitions = data[1], wantEven = data[2],\n\t\twantOdd = wantPartitions - wantEven,\n\t\tinput = tokenizeIntegers(readline()),\n\t\titems = new Array(n), odd = 0, even = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar bit = input[i]%2;\n\t\tif (bit == 0) {\n\t\t\teven += 1;\n\t\t} else {\n\t\t\todd += 1;\n\t\t}\n\t\titems[i] = { value: input[i], bit: bit };\n\t}\n\tif (wantOdd > odd || (odd - wantOdd) % 2 == 1 ||\n\t\t\twantEven > even + (odd - wantOdd) / 2) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\tprint('YES');\n\titems.sort(function (a, b) {\n\t\treturn a.bit - b.bit;\n\t});\n\tvar pos = n-1;\n\tfor (var i = 1; i < wantOdd; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\twhile (wantEven > 1 && items[pos].bit == 1) {\n\t\tprint('2 '+items[pos--].value+' '+items[pos--].value);\n\t\t--wantEven;\n\t}\n\tfor (var i = 1; i < wantEven; ++i) {\n\t\tprint('1 '+items[pos--].value);\n\t}\n\tif (pos != -1) {\n\t\tvar parts = [pos+1];\n\t\twhile (pos != -1) {\n\t\t\tparts.push(items[pos--].value);\n\t\t}\n\t\tprint(parts.join(' '));\n\t}\n}\n\nmain();\n"}], "src_uid": "5185f842c7c24d4118ae3661f4418a1d"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n const ans = []\r\n let count = 0;\r\n arr = arr.sort((a, b) => a - b)\r\n for (const i of arr) {\r\n if (i != arr[0]) {\r\n ans.push(i + ' ' + arr[0])\r\n count++\r\n }\r\n if (count >= (Math.floor(n / 2))) break;\r\n }\r\n console.log(ans.join('\\n'))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n arr.sort((a, b) => b - a)\n // const map = arr.reduce((o, x) => {\n // o[x] = 1\n // return o\n // }, {})\n// console.log(arr)\n const ans = Array(Math.floor(n / 2))\n let p = 0\n for (let i = 0; i < arr.length; i++) {\n const a = arr[i]\n // for (let j = i + 1; j < arr.length; j++) {\n const b = arr[n - 1]\n // if (!map[a % b]) {\n ans[p++] = [a, b].join(' ')\n if (p === ans.length) return ans.join('\\n')\n // break\n // }\n // }\n }\n return ''\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = '';\n for(j = 1; j <= n / 2; j++){\n console.log(a[j], a[0]);\n }\n }\n }\n});"}, {"source_code": "const solve = (arr)=>{\r\n let min = Infinity,cnt=0;\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let number = parseInt(readline());\r\n while (number--) {\r\n let a = parseInt(readline());\r\n let str = readline().split(\" \").map(Number);\r\n let min = Math.min(...str);\r\n let count = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n if (count == Math.floor(a / 2)) {\r\n break;\r\n }\r\n if (str[i] != min) {\r\n print(str[i] + \" \" + min);\r\n count++;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var number = parseInt(readline())\r\n while(number--){\r\n var a = parseInt(readline())\r\n var str = readline().split(' ').map(Number)\r\n var min = Math.min(...str)\r\n var count = 0;\r\n for(let i = 0; i < str.length;i++){\r\n if(count == Math.floor(a / 2)){\r\n break;\r\n }\r\n if(str[i] != min){\r\n print(str[i] + \" \" + min)\r\n count++\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tconst mn = Math.min(...a);\r\n\r\n\t\tfor (let i = 0; i < Math.floor(n/2); i++) {\r\n\t\t\tif (a[i] != mn)\r\n\t\t\t\tconsole.log(a[i], mn);\r\n\t\t\telse\r\n\t\t\t\tconsole.log(a[n-1], mn);\r\n\t\t}\r\n\r\n\t\t\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\t// pick y as the smallest\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\twhile (t--) {\r\n\t\tvar n = readInt();\r\n\t\tvar a = readIntArr();\r\n\t\tvar minI = 0;\r\n\t\tfor (var i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[minI])\r\n\t\t\t\tminI = i;\r\n\t\t}\r\n\t\tvar cnts = 0;\r\n\t\tfor (var i = 0; i < n; i++) {\r\n\t\t\tif (i != minI) {\r\n\t\t\t\tallans.push([a[i], a[minI]]);\r\n\t\t\t\tcnts++;\r\n\t\t\t\tif ((cnts + 1) * 2 > n)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tmultiLineArrayOfArraysPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [], "src_uid": "6d5ecac49fe1320eef1391b6d5cf5f0d"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var n = parseInt(lines.shift(), 10);\n var ans = [[0, 0]];\n for (var i = 0; i <= n; i++) {\n ans.push([i, i + 1]);\n ans.push([i + 1, i]);\n ans.push([i + 1, i + 1]);\n }\n console.log(ans.length);\n ans.forEach(function (element) { return console.log.apply(console, element); });\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var n = parseInt(lines.shift(), 10);\n var ans = [];\n ans.push([0, 0]);\n for (var i = 0; i <= n; i++) {\n ans.push([i, i + 1]);\n ans.push([i + 1, i]);\n ans.push([i + 1, i + 1]);\n }\n console.log(ans.length);\n ans.forEach(function (element) { return console.log.apply(console, element); });\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n // let lines = input.trim().split('\\n')\n // let n = +lines[0]\n // for(let i = 0; i < n; i++) {\n // let [a, b, n] = lines[1 + i].split(' ')\n // console.log(solution(+a, +b, +n))\n // }\n solution(+input.trim())\n}\n\nfunction solution(N) {\n let ans = [[0, 0], [0, 1], [1, 0]]\n\n let x = 1, y = 1\n for (let i = 0; i < N; i++) {\n ans.push([x, y], [x, y + 1], [x + 1, y])\n x++\n y++\n }\n ans.push([x, y])\n console.log(ans.length)\n for (let arr of ans) {\n console.log(arr[0], arr[1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let n = pi(readline());\n let x = 7+(n-1)*3\n console.log(x);\n let j = 0;\n for(let i = 1; i <= x; i+=3){\n if(i === x){\n console.log(j,j);\n break;\n }\n console.log(j,j);\n console.log(j+1, j);\n console.log(j,j+1);\n j++;\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n6 1\n100010\n6 2\n000000\n5 1\n10101\n3 1\n001\n2 2\n00\n1 1\n0\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = parseInt(readline());\n\n // for(let i=0;i count && i < n) {\n if(i === 1 && a[i-1] === '0' && a[i] === '0') {\n count++;\n a[i-1] = \"1\";\n continue;\n }\n\n if(a[i + 1] === n) {\n if(a[i] === \"0\" && a[i-1] === \"0\") {\n count++;\n }\n\n continue;\n }\n\n if(a[i] === \"0\" && a[i-1] === \"0\" && a[i+1] === \"0\") {\n count++;\n a[i] = \"1\";\n }\n\n i++;\n }\n\n console.log(count);\n}\n\n"}, {"source_code": "n = parseInt(readline())\n\nprint(8 + 7 * n)\n\nx = 0, y = 0\n\nfor(var i = 1; i <= 8; i++)\n{\n print(x + ' ' + y)\n if(i <= 2)\n x++\n else if(i <= 4)\n y--\n else if(i <= 6)\n x--\n else if(i <= 8)\n y++\n}\n\ny++\n\nfor(var j = 1; j <= n; j++)\n{\n x = j * 2, y = 0\n if(j % 2 == 1)\n {\n y++\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y++\n else if(i <= 4)\n x++\n else if(i <= 6)\n y--\n else if(i <= 8)\n x--\n }\n }\n if(j % 2 == 0)\n {\n y--\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y--\n else if(i <= 4)\n x++\n else if(i <= 6)\n y++\n else if(i <= 8)\n x--\n }\n }\n}"}, {"source_code": "function solve() {\n var n = Number(read());\n write(3 * (n - 1) + 7);\n write('0 0');\n write('0 1');\n write('1 0');\n write('1 1');\n for (var i = 0; i < n; ++i) {\n var i1 = i + 1;\n var i2 = i + 2;\n write('' + i1 + ' ' + i2);\n write('' + i2 + ' ' + i1);\n write('' + i2 + ' ' + i2);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "var n = +readline()\nwhile(n )\n{\n print(0 + ' ' + parseInt(n/2))\n print(1 + ' ' + parseInt(n/2))\nn-=2\n}"}, {"source_code": "n = +readline()\n\nprint(8 + 7 * n)\n\nx = 0, y = 0\n\nfor(var i = 1; i <= 8; i++)\n{\n print(x + ' ' + y)\n if(i <= 2)\n x++\n else if(i <= 4)\n y--\n else if(i <= 6)\n x--\n else if(i <= 8)\n y++\n}\n\ny++\n\nfor(var j = 1; j <= n; j++)\n{\n x = 3 + (j - 1) * 2, y = 0\n if(j % 2 == 1)\n {\n y++\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y++\n else if(i <= 4)\n x++\n else if(i <= 6)\n y--\n else if(i <= 8)\n x--\n }\n }\n if(j % 2 == 0)\n {\n y--\n for(var i = 2; i <= 7; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y--\n else if(i <= 4)\n x++\n else if(i <= 6)\n y++\n else if(i <= 8)\n x--\n }\n }\n}\nprint('\\n')"}, {"source_code": "n = parseInt(readline())\n\nprint(8 + 7 * n)\n\nx = 0, y = 0\n\nfor(var i = 1; i <= 8; i++)\n{\n print(x + ' ' + y)\n if(i <= 2)\n x++\n else if(i <= 4)\n y--\n else if(i <= 6)\n x--\n else if(i <= 8)\n y++\n}\n\ny++\n\nfor(var j = 1; j <= n; j++)\n{\n x = 3 + (j - 1) * 2, y = 0\n if(j % 2 == 1)\n {\n y++\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y++\n else if(i <= 4)\n x++\n else if(i <= 6)\n y--\n else if(i <= 8)\n x--\n }\n }\n if(j % 2 == 0)\n {\n y--\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y--\n else if(i <= 4)\n x++\n else if(i <= 6)\n y++\n else if(i <= 8)\n x--\n }\n }\n}"}, {"source_code": "n = +readline()\n\nprint(9 + 8 * n)\n\nx = 0, y = 0\n\nfor(var i = 1; i <= 8; i++)\n{\n print(x + ' ' + y)\n if(i <= 2)\n x++\n else if(i <= 4)\n y--\n else if(i <= 6)\n x--\n else if(i <= 8)\n y++\n}\n\ny++\n\nfor(var j = 1; j <= n; j++)\n{\n x = 3 + (j - 1) * 2, y = 0\n if(j % 2 == 1)\n {\n y++\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y++\n else if(i <= 4)\n x++\n else if(i <= 6)\n y--\n else if(i <= 8)\n x--\n }\n }\n if(j % 2 == 0)\n {\n y--\n for(var i = 2; i <= 7; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y--\n else if(i <= 4)\n x++\n else if(i <= 6)\n y++\n else if(i <= 8)\n x--\n }\n }\n}"}, {"source_code": "var n = +readline()\nwhile(n)\n{\n print(0 + ' ' + parseInt(n/2))\n print(0 + ' ' + parseInt(n/2))\nn-=1\n}"}, {"source_code": "n = +readline()\n\nprint(8 + 7 * n)\n\nx = 0, y = 0\n\nfor(var i = 1; i <= 8; i++)\n{\n print(x + ' ' + y)\n if(i <= 2)\n x++\n else if(i <= 4)\n y--\n else if(i <= 6)\n x--\n else if(i <= 8)\n y++\n}\n\ny++\n\nfor(var j = 1; j <= n; j++)\n{\n x = 3 + (j - 1) * 2, y = 0\n if(j % 2 == 1)\n {\n y++\n for(var i = 2; i <= 8; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y++\n else if(i <= 4)\n x++\n else if(i <= 6)\n y--\n else if(i <= 8)\n x--\n }\n }\n if(j % 2 == 0)\n {\n y--\n for(var i = 2; i <= 7; i++)\n {\n print(x + ' ' + y)\n if(i <= 2)\n y--\n else if(i <= 4)\n x++\n else if(i <= 6)\n y++\n else if(i <= 8)\n x--\n }\n }\n}"}, {"source_code": "var n = +readline()\nwhile(n)\n{\n print(0 + ' ' + parseInt(n/2))\n print(1 + ' ' + parseInt(n/2))\nn-=1\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var n = parseInt(lines.shift(), 10);\n var ans = [];\n for (var i = 0; i < n; i++) {\n ans.push([0, 2 * i + 1]);\n }\n for (var i = 0; i <= 2 * n; i++) {\n ans.push([1, i]);\n }\n for (var i = 0; i < n; i++) {\n ans.push([2, 2 * i + 1]);\n }\n console.log(ans.length);\n ans.forEach(function (element) { return console.log.apply(console, element); });\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var n = parseInt(lines.shift(), 10);\n var ans = [];\n for (var i = 0; i < n; i++) {\n ans.push([0, 4 * i]);\n ans.push([0, 4 * i + 1]);\n ans.push([1, 4 * i]);\n ans.push([1, 4 * i + 1]);\n ans.push([1, 4 * i + 2]);\n ans.push([2, 4 * i + 1]);\n ans.push([2, 4 * i + 2]);\n }\n console.log(ans.length);\n ans.forEach(function (element) { return console.log.apply(console, element); });\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n6 1\n100010\n6 2\n000000\n5 1\n10101\n3 1\n001\n2 2\n00\n1 1\n0\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() { \n let n = parseInt(readline());\n\n // for(let i=0;i count && i < n) {\n if(i === 1 && a[i-1] === '0' && a[i] === '0') {\n count++;\n a[i-1] = \"1\";\n continue;\n }\n\n if(a[i + 1] === n) {\n if(a[i] === \"0\" && a[i-1] === \"0\") {\n count++;\n }\n\n continue;\n }\n\n if(a[i] === \"0\" && a[i-1] === \"0\" && a[i+1] === \"0\") {\n count++;\n a[i] = \"1\";\n }\n\n i++;\n }\n\n console.log(count);\n}\n\n"}], "src_uid": "d87c40ae942f3c378bde372f3320a09f"} {"source_code": "var n = readline();\nvar chips = readline().split(' ');\nvar odd = 0;\nvar even = 0;\nfor (var index = 0; index < n; index++) {\n if((chips[index] % 2) == 1)\n odd++;\n else\n even++; \n}\nif(even !== 0 && odd !== 0){\n if(even < odd)\n print(Math.min(odd, even));\n else\n print(odd);\n}\nelse\n print(\"0\")\n", "positive_code": [{"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const n = Number(lines[0])\n const x = lines[1].split(' ').map(Number)\n const even = x.filter(a => a % 2 === 0)\n const odd = x.filter(a => a % 2 === 1)\n \n if(odd.length > even.length) {\n console.log(even.length)\n } else {\n console.log(odd.length)\n }\n}\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN().map(v => v%2);\n var min = Infinity;\n for (var i = 0; i < n; ++i) {\n var price = 0;\n for (var j = 0; j < n; ++j) {\n if (j !== i) {\n price += Math.abs(A[i] - A[j]);\n }\n }\n min = Math.min(min, price);\n }\n wr(min);\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var t = Number(readline());\nvar inp = readline().split(' ').map(cur => Math.abs(Number(cur)));\nvar n = {\n odd: 0,\n even: 0\n};\n\ninp.forEach(cur => {\n cur % 2 === 0 ? n.even++ : n.odd++; \n})\n\nn.odd >= n.even ? print(n.even) : print(n.odd);"}, {"source_code": "'use strict'\n\nreadline();\nlet a = 0, b = 0;\nconst x = readline().split(' ').forEach(i => parseInt(i[i.length - 1]) % 2 ? a++ : b++);\n\nwrite(Math.min(a, b));"}, {"source_code": "if (process.env.ANT)\n{\n global.print = this.print || function(){console.log([...arguments].join(' '))} || require('lol-io').print\n global.write = this.write || require('lol-io').write\n global.readline = this.readline || require('lol-io').readline\n global.debug = function(){console.log('debug:', [...arguments].join(' '))}\n main();\n}\nelse\n{\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n global.print = console.log\n global.write = (...args) => {\n process.stdout.write(args.join(' '));\n }\n const lines = []\n rl.on('line', line =>{\n lines.push(line);\n });\n rl.on('close', main)\n let rli = 0;\n global.readline = ()=>lines[rli++];\n global.debug = ()=>{};\n}\n\n///////////// CODE\n\nfunction main(){\n\nvar n = +readline();\nlet arr = readline().split(' ').map(n=>+n);\nlet to_check = {};\nfor (let x of arr)\n to_check[x-2] = to_check[x-1] = to_check[x] = to_check[x+1] = to_check[x+2] = true;\n\nlet min = Infinity;\nfor (let check in to_check)\n{\n let res = 0;\n for (let x of arr)\n res += (x&1)==(check&1) ? 0 : 1;\n debug(check, res)\n min = Math.min(min, res);\n}\nprint(min)\n\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet standardInputString= '';\nlet currentLine = 0;\n\nfunction readLine(){\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on('data', rawData =>{\n standardInputString += rawData;\n});\n\nprocess.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n})\n\nfunction main(){\n\n //first line in input\n let [n] = readLine().split(' ').map(Number);\n\n\n let line = readLine().split(' ').map(Number);\n\n\nlet cnto = 0;\n for(let i =0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let odd = 0;\n let even = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] % 2) {\n odd++;\n }\n else {\n even++;\n }\n }\n\n const ans = Math.min(odd, even);\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let chips = lines[1].split(' ');\n chips = chips.map(chip => parseInt(chip, 10));\n chipsMoving(chips);\n});\n\n\nfunction chipsMoving(chips) {\n let odd = 0;\n let even = 0;\n for (const chip of chips) {\n if (chip % 2 === 0) even++;\n else odd++;\n }\n console.log(Math.min(odd, even));\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet standardInputString= '';\nlet currentLine = 0;\n\nfunction readLine(){\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on('data', rawData =>{\n standardInputString += rawData;\n});\n\nprocess.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n})\n\nfunction main(){\n\n //first line in input\n let [n] = readLine().split(' ').map(Number);\n\n\n let line = readLine().split(' ').map(Number);\n\n\nlet cnto = 0;\n for(let i =0; i{\n standardInputString += rawData;\n});\n\nprocess.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n})\n\nfunction main(){\n\n //first line in input\n let [n] = readLine().split(' ').map(Number);\n\n\n let line = readLine().split(' ').map(Number);\n\n\nlet cnto = 0;\n for(let i =1; i{\n standardInputString += rawData;\n});\n\nprocess.stdin.on('end', _ =>{\n standardInputString= standardInputString.trim().split('\\n').map(line =>{\n return line.trim();\n });\n\n main();\n})\n\nfunction main(){\n\n //first line in input\n let [n] = readLine().split(' ').map(Number);\n\n\n let line = readLine().split(' ').map(Number);\n\n\nlet cnto = 0;\n for(let i =0; i { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\nconst initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 09/05/21 night\r\nconst solve = (n, k, A) => {\r\n let a = initializeGraph(n + 1);\r\n for (let i = 0; i < n; i++) a[A[i]].push(i);\r\n // pr(a);\r\n let res = Array(n).fill(0);\r\n let b = [];\r\n for (let i = 1; i <= n; i++) {\r\n if (a[i].length < k) {\r\n for (const x of a[i]) b.push(x);\r\n continue;\r\n }\r\n for (let j = 0; j < k; j++) {\r\n res[a[i][j]] = j + 1;\r\n }\r\n }\r\n // pr(res)\r\n // pr(b)\r\n for (let i = 0; i + k <= b.length; i += k) {\r\n for (let j = 0; j < k; j++) {\r\n res[b[i + j]] = j + 1;\r\n }\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const [n,k] = lines[2*i - 1].split(' ').map(x => parseInt(x));\r\n const arr = lines[2*i].split(' ').map(x => parseInt(x));\r\n // console.log(n,k,arr);\r\n // create a map for cycle\r\n const map = {};\r\n // pos[num] = [each pos]\r\n const pos = {};\r\n const rpos = {};\r\n const cnts = {};\r\n const ans = [];\r\n let target_count = 0;\r\n // count how many times each num appears, iter j\r\n for (let j = 0; j < arr.length; j++) {\r\n\r\n if (map[arr[j]]) {\r\n map[arr[j]]++;\r\n } else {\r\n map[arr[j]] = 1;\r\n }\r\n\r\n // pos\r\n if (pos[arr[j]]) {\r\n pos[arr[j]].push(j);\r\n // add target_count if arr[j] appeared less than k times\r\n if (map[arr[j]] <= k) {\r\n target_count++;\r\n }\r\n\r\n } else {\r\n pos[arr[j]] = [j];\r\n cnts[arr[j]] = 0;\r\n target_count+=1;\r\n }\r\n }\r\n\r\n // left target_count number should be multiple of k\r\n target_count -= (target_count % k);\r\n\r\n const poses = [];\r\n // flatten pos to poses\r\n for (let key in pos) {\r\n poses.push(...pos[key]);\r\n }\r\n\r\n // console.log(pos, poses, cnts)\r\n // console.log(target_count, map);\r\n \r\n // iter thru poses\r\n let color = 1;\r\n for (let j = 0; j < poses.length; j++) {\r\n // get now pos\r\n const now = poses[j];\r\n // get cnts of this num\r\n const cnt = cnts[arr[now]];\r\n // put ans cnt+1 if cnt < k\r\n if (cnt < k && target_count > 0) {\r\n ans[now] = color++;\r\n cnts[arr[now]]++;\r\n if(color > k) {\r\n color = 1;\r\n }\r\n target_count--;\r\n } else {\r\n ans[now] = 0;\r\n }\r\n\r\n }\r\n\r\n console.log(ans.join(' '));\r\n\r\n }\r\n\r\n})"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet k;\r\nlet a;\r\nlet nxt;\r\nlet last;\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n a = af(n);\r\n nxt = af(n).fill(INIT);\r\n last = af(n + 1).fill(INIT);\r\n const ans = af(n).fill(0);\r\n const uniq = new Set();\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n uniq.add(a[i]);\r\n if (last[a[i]] != INIT) {\r\n nxt[i] = last[a[i]];\r\n }\r\n last[a[i]] = i;\r\n }\r\n let p = [];\r\n let i = 0;\r\n for (let v of uniq.values()) {\r\n for (let j = 0; j < k && last[v] != INIT; j++) {\r\n p.push(last[v]);\r\n last[v] = nxt[last[v]];\r\n }\r\n }\r\n let l = p.length - (p.length % k);\r\n check((l % k) == 0);\r\n for (let i = 0; i < l; i++) {\r\n ans[p[i]] = (i % k) + 1;\r\n }\r\n printf(\"%s\\n\", ans.join(' '));\r\n // printf(\"%j\\n\", nxt);\r\n // cnt.forEach((v: number, k: number) => { printf(\"%d=%d\\n\", v, k) });\r\n // console.log(cnt);\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (mp.has(a[i]))\r\n\t\t\t\tmp.get(a[i]).push(i);\r\n\t\t\telse\r\n\t\t\t\tmp.set(a[i], [i]);\r\n\t\t}\r\n\r\n\t\tconst avl = [];\r\n\t\tfor (const [elm, indxs] of mp) {\r\n\t\t\tfor (let i = 0 ; i < indxs.length && i < k; i++) {\r\n\t\t\t\tavl.push(indxs[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n).fill(0);\r\n\t\tfor (let i = 0, clr = 0; i < Math.floor(avl.length/k)*k; i++) {\r\n\t\t\tclr = clr%k + 1;\r\n\t\t\tans[avl[i]] = clr;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var ans = readNumArr();\r\n var m = ans[0];\r\n var k = ans[1];\r\n var vals = readNumArr();\r\n \r\n ans = []\r\n \r\n var uniq = new Map();\r\n var count = 0;\r\n \r\n for(var j = 0; j < m; j++) {\r\n var item = uniq.get(vals[j]);\r\n ans[j] = 0;\r\n \r\n if(!item) {\r\n uniq.set(vals[j], []);\r\n item = uniq.get(vals[j]);\r\n }\r\n \r\n item.push(j)\r\n }\r\n \r\n uniq.forEach(item => {\r\n count += item.length < k ? item.length : k;\r\n });\r\n \r\n count -= count % k;\r\n \r\n var lk = 0;\r\n \r\n uniq.forEach(item => {\r\n for(var j = 0; j < item.length && j < k; j++) {\r\n if(count) {\r\n lk++;\r\n ans[item[j]] = lk;\r\n if(lk === k) {\r\n lk = 0;\r\n }\r\n count--;\r\n }\r\n }\r\n });\r\n \r\n print(ans.join(' '));\r\n}"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n const start = {}\n for (let x in map) {\n const count = map[x]\n if (count >= k) {\n a++\n } else {\n start[x] = b\n b += count\n }\n }\n const max = Math.floor(b / k) * k\n// console.log(a, 'max', max)\n// console.log(start)\n // let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n // if (idx < max) {\n const now = start[x] + (cur[x] || 0)\n // console.log(now, max)\n if (now < max) {\n color = now + 1\n if (color % k) color = color % k\n else color = k\n // console.log(now, color)\n\n cur[x] = (cur[x] || 0) + 1\n }\n }\n return color\n }).join(' ')\n}\n"}], "negative_code": [{"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n const start = {}\n for (let x in map) {\n const count = map[x]\n if (count >= k) {\n a++\n } else {\n start[x] = b\n b += count\n }\n }\n const max = Math.floor(b / k) * k\n// console.log(a, 'max', max)\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n // if (idx < max) {\n if (idx < max && start[x] < max) {\n cur[x] = cur[x] || 1\n color = (start[x] + cur[x]++) % k\n color++\n // color = (idx++ % k) + 1\n idx++\n }\n }\n return color\n }).join(' ')\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n const start = {}\n for (let x in map) {\n const count = map[x]\n if (count >= k) {\n a++\n } else {\n start[x] = b\n b += count\n }\n }\n const max = Math.floor(b / k) * k\n// console.log(a, 'max', max)\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n // if (idx < max) {\n if (idx < max && start[x] < max) {\n cur[x] = cur[x] || 1\n color = (start[x] + cur[x]++) % k\n color++\n // color = (idx++ % k) + 1\n idx++\n }\n }\n return color\n }).join(' ')\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n const start = {}\n for (let x in map) {\n const count = map[x]\n if (count >= k) {\n a++\n } else {\n start[x] = b\n b += count\n }\n }\n const max = Math.floor(b / k) * k\n// console.log(a, 'max', max)\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n if (idx < max) {\n cur[x] = cur[x] || 1\n color = (start[x] + cur[x]++) % k\n color++\n // color = (idx++ % k) + 1\n idx++\n }\n }\n return color\n }).join(' ')\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n const p = []\n for (let x in map) {\n const count = map[x]\n p.push(count)\n }\n p.sort((a, b) => a - b)\n\n const pre = []\n p.forEach((x, i) => {\n pre[i] = i ? pre[i - 1] + x : x\n })\n// console.log(p, pre)\n let max = -Infinity\n let ek\n let limit\n for (let i = 1; i <= k; i++) {\n const idx = binarySearch(0, p.length - 1, x => p[x] < i)\n const b = idx < 0 ? 0 : pre[idx]\n const a = p.length - 1 - idx\n const cur = (a + Math.floor(b / i)) * i\n // console.log(i, a, b, cur)\n if (cur > max) {\n max = cur\n ek = i\n limit = Math.floor(b / i) * i\n }\n }\n // console.log(max, ek, limit)\n k = ek\n// console.log(a, 'max', max)\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n if (idx < limit) {\n color = (idx++ % k) + 1\n }\n }\n return color\n }).join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n for (let x in map) {\n const count = map[x]\n if (count >= k) {\n a++\n } else {\n b += count\n }\n }\n const max = Math.floor(b / k) * k\n// console.log(a, 'max', max)\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n if (idx < max) {\n color = (idx++ % k) + 1\n }\n }\n return color\n }).join(' ')\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, arr))\n }\n});\n\nfunction solve(n, k, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const ch = arr[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let idx = 0\n const cur = {}\n return arr.map(x => {\n const count = map[x]\n let color = 0\n if (count >= k) {\n cur[x] = cur[x] || 1\n if (cur[x] <= k) {\n color = cur[x]++\n }\n } else {\n color = idx + 1\n idx = (idx + 1) % k\n }\n return color\n }).join(' ')\n}\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const [n,k] = lines[2*i - 1].split(' ').map(x => parseInt(x));\r\n const arr = lines[2*i].split(' ').map(x => parseInt(x));\r\n // console.log(n,k,arr);\r\n // create a map for cycle\r\n const map = {};\r\n // pos[num] = [each pos]\r\n const pos = {};\r\n const rpos = {};\r\n const cnts = {};\r\n const ans = [];\r\n let target_count = 0;\r\n // count how many times each num appears, iter j\r\n for (let j = 0; j < arr.length; j++) {\r\n\r\n if (map[arr[j]]) {\r\n map[arr[j]]++;\r\n } else {\r\n map[arr[j]] = 1;\r\n }\r\n\r\n // pos\r\n if (pos[arr[j]]) {\r\n pos[arr[j]].push(j);\r\n // add target_count if arr[j] appeared less than k times\r\n if (map[arr[j]] <= k) {\r\n target_count++;\r\n }\r\n\r\n } else {\r\n pos[arr[j]] = [j];\r\n cnts[arr[j]] = 0;\r\n target_count+=1;\r\n }\r\n }\r\n\r\n // left target_count number should be multiple of k\r\n target_count -= (target_count % k);\r\n\r\n const poses = [];\r\n // flatten pos to poses\r\n for (let key in pos) {\r\n poses.push(...pos[key]);\r\n }\r\n\r\n // console.log(pos, poses, cnts)\r\n // console.log(target_count, map);\r\n \r\n // iter thru poses\r\n let color = 1;\r\n // for (let j = 0; j < poses.length; j++) {\r\n // // get now pos\r\n // const now = poses[j];\r\n // // get cnts of this num\r\n // const cnt = cnts[arr[now]];\r\n // // put ans cnt+1 if cnt < k\r\n // if (cnt < k && target_count > 0) {\r\n // ans[now] = color++;\r\n // cnts[arr[now]]++;\r\n // if(color > k) {\r\n // color = 1;\r\n // }\r\n // target_count--;\r\n // } else {\r\n // ans[now] = 0;\r\n // }\r\n\r\n // }\r\n \r\n // iter through arr\r\n for (let j = 0; j < arr.length; j++) {\r\n // get cnts of this num\r\n const cnt = cnts[arr[j]];\r\n // put ans color if cnt < k\r\n if (cnt < k && target_count > 0) {\r\n ans[j] = color++;\r\n cnts[arr[j]]++;\r\n if(color > k) {\r\n color = 1;\r\n }\r\n target_count--;\r\n } else {\r\n ans[j] = 0;\r\n }\r\n }\r\n\r\n console.log(ans.join(' '));\r\n\r\n }\r\n\r\n})"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const [n,k] = lines[2*i - 1].split(' ').map(x => parseInt(x));\r\n const arr = lines[2*i].split(' ').map(x => parseInt(x));\r\n // console.log(n,k,arr);\r\n // create a map for cycle\r\n const map = {};\r\n // pos[num] = [each pos]\r\n const pos = {};\r\n const rpos = {};\r\n const cnts = {};\r\n const ans = [];\r\n // count how many times each num appears, iter j\r\n for (let j = 0; j < arr.length; j++) {\r\n\r\n if (map[arr[j]]) {\r\n map[arr[j]]++;\r\n } else {\r\n map[arr[j]] = 1;\r\n }\r\n\r\n // pos\r\n if (pos[arr[j]]) {\r\n pos[arr[j]].push(j);\r\n } else {\r\n pos[arr[j]] = [j];\r\n cnts[arr[j]] = 0;\r\n }\r\n }\r\n\r\n const poses = [];\r\n // flatten pos to poses\r\n for (let key in pos) {\r\n poses.push(...pos[key]);\r\n }\r\n\r\n // console.log(pos, poses, cnts)\r\n \r\n // iter thru poses\r\n let color = 1;\r\n for (let j = 0; j < poses.length; j++) {\r\n // get now pos\r\n const now = poses[j];\r\n // get cnts of this num\r\n const cnt = cnts[arr[now]];\r\n // put ans cnt+1 if cnt < k\r\n if (cnt < k) {\r\n ans[now] = color++;\r\n cnts[arr[now]]++;\r\n if(color > k) {\r\n color = 1;\r\n }\r\n } else {\r\n ans[now] = 0;\r\n }\r\n\r\n }\r\n\r\n console.log(ans.join(' '));\r\n\r\n }\r\n\r\n})"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const [n,k] = lines[2*i - 1].split(' ').map(x => parseInt(x));\r\n const arr = lines[2*i].split(' ').map(x => parseInt(x));\r\n // console.log(n,k,arr);\r\n // create a map for cycle\r\n const map = new Map();\r\n const ans = [];\r\n // count how many times each num appears\r\n for (let j = 0; j < arr.length; j++) {\r\n const num = arr[j] - 0;\r\n if (map.has(num)) {\r\n map.set(num, map.get(num) + 1);\r\n } else {\r\n map.set(num, 1);\r\n }\r\n }\r\n\r\n // iter through the map values, init keys to zero\r\n const used = {};\r\n for (let key of map.keys()) {\r\n used[key] = 0;\r\n }\r\n\r\n // start from color 1, cycle through ~k\r\n let color = 1;\r\n // iter throught nums\r\n for (let j = 0; j < arr.length; j++) {\r\n const num = arr[j] - 0;\r\n // if num is already used k times, skip it\r\n if (used[num] >= k) {\r\n // put 0 to ans\r\n ans.push(0);\r\n continue;\r\n }\r\n // count used\r\n used[num] = used[num] + 1;\r\n // put color to ans\r\n ans.push(color);\r\n // color++\r\n color++;\r\n // if color > k, reset color to 1\r\n if (color > k) {\r\n color = 1;\r\n }\r\n\r\n\r\n }\r\n \r\n console.log(ans);\r\n \r\n }\r\n\r\n})"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const [n,k] = lines[2*i - 1].split(' ').map(x => parseInt(x));\r\n const arr = lines[2*i].split(' ').map(x => parseInt(x));\r\n // console.log(n,k,arr);\r\n // create a map for cycle\r\n const map = new Map();\r\n const ans = [];\r\n // for each num in arr\r\n for (let j = 0; j < arr.length; j++) {\r\n // if the num is not in map, add it\r\n if (!map.has(arr[j])) {\r\n map.set(arr[j], 1);\r\n }\r\n // else if the num is in map, increase the count by 1\r\n else {\r\n map.set(arr[j], map.get(arr[j]) + 1);\r\n // if the count is more than k, put 0 to ans\r\n if (map.get(arr[j]) > k) {\r\n ans.push(0);\r\n continue;\r\n }\r\n }\r\n // put the map num to ans\r\n ans.push(map.get(arr[j]));\r\n\r\n }\r\n\r\n console.log(ans.join(' '));\r\n\r\n }\r\n\r\n})"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet k;\r\nlet a;\r\nlet nxt;\r\nlet last;\r\nlet cnt;\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n a = af(n);\r\n nxt = af(n).fill(INIT);\r\n last = af(n + 1).fill(INIT);\r\n cnt = af(n + 1).fill(0);\r\n const ans = af(n).fill(0);\r\n const uniq = new Set();\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n uniq.add(a[i]);\r\n cnt[a[i]]++;\r\n if (last[a[i]] != INIT) {\r\n nxt[i] = last[a[i]];\r\n }\r\n last[a[i]] = i;\r\n }\r\n let p = af(n);\r\n let i = 0;\r\n for (let v of uniq.values()) {\r\n for (let j = 0; j < k && last[v] != INIT; j++) {\r\n p[i++] = last[v];\r\n last[v] = nxt[last[v]];\r\n }\r\n }\r\n let l = p.length - (p.length % k);\r\n for (let i = 0; i < l; i++) {\r\n ans[p[i]] = (i % k) + 1;\r\n }\r\n printf(\"%s\\n\", ans.join(' '));\r\n // printf(\"%j\\n\", nxt);\r\n // cnt.forEach((v: number, k: number) => { printf(\"%d=%d\\n\", v, k) });\r\n // console.log(cnt);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet k;\r\nlet a;\r\nlet ans;\r\nlet nxt;\r\nlet last;\r\nlet cnt;\r\nlet uniq;\r\nfunction answer(len) {\r\n const can = new Set(uniq.values());\r\n const rem = Array.from(cnt);\r\n const p = Array.from(last);\r\n ans.fill(0);\r\n for (let col = 1; col <= k; col++) {\r\n if (can.size < len) {\r\n return false;\r\n }\r\n let g = 0;\r\n for (let v of can.values()) {\r\n check(p[v] != INIT);\r\n check(rem[v] > 0);\r\n ans[p[v]] = col;\r\n p[v] = nxt[p[v]];\r\n rem[v]--;\r\n if (rem[v] == 0) {\r\n can.delete(v);\r\n }\r\n g++;\r\n if (g >= len) {\r\n break;\r\n }\r\n }\r\n }\r\n // printf(\"answer %d ok\\n\", len);\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n a = af(n);\r\n nxt = af(n).fill(INIT);\r\n last = af(n + 1).fill(INIT);\r\n cnt = af(n + 1).fill(0);\r\n ans = af(n).fill(0);\r\n uniq = new Set();\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n uniq.add(a[i]);\r\n cnt[a[i]]++;\r\n if (last[a[i]] != INIT) {\r\n nxt[i] = last[a[i]];\r\n }\r\n last[a[i]] = i;\r\n }\r\n let lo = 0;\r\n let hi = n;\r\n let best = INIT;\r\n while (lo < hi) {\r\n let mid = lo + Math.trunc((hi - lo) / 2);\r\n // printf(\"mid %d\\n\", mid);\r\n if (answer(mid)) {\r\n best = mid;\r\n lo = mid + 1;\r\n }\r\n else {\r\n hi = mid;\r\n }\r\n }\r\n check(best != INIT);\r\n answer(best);\r\n printf(\"%s\\n\", ans.join(' '));\r\n // printf(\"%j\\n\", nxt);\r\n // cnt.forEach((v: number, k: number) => { printf(\"%d=%d\\n\", v, k) });\r\n // console.log(cnt);\r\n }\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/23/21 morning\r\n * https://codeforces.com/contest/1551/problem/B2\r\n */\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n let m = counter_value_in_indexA_in(a);\r\n let res = Array(n).fill(0);\r\n // pr(m)\r\n let red = 0;\r\n for (const [c, a] of m) {\r\n let occ = a.length;\r\n if (occ >= k) {\r\n red++;\r\n for (let i = 0, color = 1; i < k; i++, color++) {\r\n res[a[i]] = color;\r\n }\r\n m.delete(c);\r\n }\r\n }\r\n m = new Map([...m].sort((x, y) => y[1].length - x[1].length));\r\n // pr(m)\r\n // pr(res);\r\n let sum = 0;\r\n for (const [, a] of m) {\r\n sum += a.length;\r\n }\r\n let each = int(sum / k);\r\n let d = [];\r\n for (const [, aa] of m) {\r\n for(const i of aa) d.push(i);\r\n }\r\n // pr(res);\r\n for (let i = 0, color = 1; i < k; i++, color++) {\r\n if (d[i] < n) res[d[i]] = color;\r\n }\r\n pr(res)\r\n // let ca = Array.from(m.keys());\r\n // let n = ca.length;\r\n // let idx = 0;\r\n // for (; idx < n; ) {\r\n // if (each == 0) break;\r\n // let c = ca[idx];\r\n // let a = m.get(c);\r\n // let occ = a.length;\r\n // if (occ >= k) {\r\n // for (let i = 0, color = 1; i < k; i++, color++) {\r\n // res[a[i]] = color;\r\n // each--;\r\n // }\r\n // m.delete(c);\r\n // idx++;\r\n // } else {\r\n // let rest = k - occ;\r\n // for (let i = 0, color = 1; i < occ; i++, color++) {\r\n // res[a[i]] = color;\r\n // each--;\r\n // }\r\n // m.delete(c);\r\n // idx++;\r\n // }\r\n // }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "98aca7d5bf74c7787bf2159770054297"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// Binary Indexed Tree\r\n\r\nconst SIZE = 2**18;\r\n//const data = Array(SIZE + 1).fill(0);\r\nlet data = Array(SIZE);\r\n\r\nfunction add (i, v) {\r\n\tlet cnt = 0;\r\n\t++i;\r\n\twhile (i <= SIZE) {\r\n\t\tif (!data[i]) data[i] = 0; \r\n\t\tdata[i] += v;\r\n\t\ti += i&-i;\r\n\t\tif (i == 0) break;\r\n\t}\r\n}\r\n\r\nfunction sum (i) {\r\n\tlet res = 0;\r\n\t++i;\r\n\twhile (i > 0) {\r\n\t\tif (!data[i]) data[i] = 0;\r\n\t\tres += data[i];\r\n\t\ti -= i&-i;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\t//data = Array(SIZE);\r\n\t\tfor (let i = 0; i <= SIZE; i++) data[i] = 0;\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0, cur = 0; i < n; i++) {\r\n\t\t\tb[a[i][1]] = i > 0 && (a[i][0] == a[i-1][0]) ? cur : ++cur;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tadd(b[i], 1);\r\n\t\t\tans += Math.min(sum(b[i] - 1), i + 1 - sum(b[i]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// Binary Indexed Tree\r\n\r\nconst SIZE = 200005;\r\nconst data = Array(SIZE);\r\n\r\nfunction add (i, v) {\r\n\tlet cnt = 0;\r\n\t++i;\r\n\twhile (i < SIZE) {\r\n\t\tdata[i] += v;\r\n\t\ti += i&-i;\r\n\t\tif (i == 0) break;\r\n\t}\r\n}\r\n\r\nfunction sum (i) {\r\n\tlet res = 0;\r\n\t++i;\r\n\twhile (i > 0) {\r\n\t\tres += data[i];\r\n\t\ti -= i&-i;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tfor (let i = 0; i < SIZE; i++) data[i] = 0;\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0, cur = 0; i < n; i++) {\r\n\t\t\tb[a[i][1]] = i > 0 && (a[i][0] == a[i-1][0]) ? cur : ++cur;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tadd(b[i], 1);\r\n\t\t\tans += Math.min(sum(b[i] - 1), i + 1 - sum(b[i]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// Binary Indexed Tree\r\n\r\nconst SIZE = 2**20;\r\nconst data = Array(SIZE);\r\n\r\nfunction add (i, v) {\r\n\tlet cnt = 0;\r\n\t++i;\r\n\twhile (i <= SIZE) {\r\n\t\tif (!data[i]) data[i] = 0; \r\n\t\tdata[i] += v;\r\n\t\ti += i&-i;\r\n\t\tif (i == 0) break;\r\n\t}\r\n}\r\n\r\nfunction sum (i) {\r\n\tlet res = 0;\r\n\t++i;\r\n\twhile (i > 0) {\r\n\t\tif (!data[i]) data[i] = 0;\r\n\t\tres += data[i];\r\n\t\ti -= i&-i;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tfor (let i = 0; i <= SIZE; i++) data[i] = 0;\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0, cur = 0; i < n; i++) {\r\n\t\t\tb[a[i][1]] = i > 0 && (a[i][0] == a[i-1][0]) ? cur : ++cur;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tadd(b[i], 1);\r\n\t\t\tans += Math.min(sum(b[i] - 1), i + 1 - sum(b[i]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// Binary Indexed Tree\r\n\r\nconst SIZE = 2**19;\r\nconst data = Array(SIZE);\r\n\r\nfunction add (i, v) {\r\n\tlet cnt = 0;\r\n\t++i;\r\n\twhile (i <= SIZE) {\r\n\t\tif (!data[i]) data[i] = 0; \r\n\t\tdata[i] += v;\r\n\t\ti += i&-i;\r\n\t\tif (i == 0) break;\r\n\t}\r\n}\r\n\r\nfunction sum (i) {\r\n\tlet res = 0;\r\n\t++i;\r\n\twhile (i > 0) {\r\n\t\tif (!data[i]) data[i] = 0;\r\n\t\tres += data[i];\r\n\t\ti -= i&-i;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tfor (let i = 0; i <= SIZE; i++) data[i] = 0;\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0, cur = 0; i < n; i++) {\r\n\t\t\tb[a[i][1]] = i > 0 && (a[i][0] == a[i-1][0]) ? cur : ++cur;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tadd(b[i], 1);\r\n\t\t\tans += Math.min(sum(b[i] - 1), i + 1 - sum(b[i]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\n// Binary Indexed Tree\r\n\r\nconst SIZE = 200005;\r\nconst data = Array(SIZE);\r\n\r\nfunction add (i, v) {\r\n\tfor (++i; i < SIZE; i += i&-i) data[i] += v;\r\n}\r\n\r\nfunction sum (i) {\r\n\tlet res = 0;\r\n\tfor (++i; i > 0; i -= i&-i) res += data[i];\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tfor (let i = 0; i < SIZE; i++) data[i] = 0;\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) a[i] = [a[i], i];\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0, cur = 0; i < n; i++) {\r\n\t\t\tb[a[i][1]] = i > 0 && (a[i][0] == a[i-1][0]) ? cur : ++cur;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tadd(b[i], 1);\r\n\t\t\tans += Math.min(sum(b[i] - 1), i + 1 - sum(b[i]));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "aa78a750cac45117f7b4313928c50f76"} {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n for (let index = 1; index <= t; index++) {\n const element = inputs[index].trim();\n if (element.length > 2) {\n let sliceElement = element.slice(1, element.length - 1);\n let newElem = element[0];\n for (let index2 = 0; index2 < sliceElement.length; index2 += 2) {\n const elem = sliceElement[index2];\n newElem += elem;\n }\n newElem += element[element.length - 1];\n console.log(newElem);\n }\n else {\n console.log(element);\n }\n }\n}\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n while(t--) {\n let ans = \"\";\n let str = readLine();\n ans += str[0];\n ans += str[1];\n for(let i = 2; i < str.length; i++) {\n if (i%2 !== 0) {\n ans += str[i];\n }\n }\n console.log(ans);\n }\n}"}, {"source_code": "process.stdin.setEncoding('utf8');\n\nfunction solve(input) {\n let data = [];\n\n for (let i = 0; i < input.length - 1; i += 2) {\n data.push(input[i]);\n }\n\n data.push(input[input.length - 1]);\n\n return data;\n}\n\nlet input = '';\n\nprocess.stdin.on('data', chunk => {\n if (chunk.trim() == 'end') process.stdin.emit('end');\n else input += chunk;\n});\n\n\nprocess.stdin.on('end', () => {\n input = input.trim().split('\\n').slice(1);\n\n for (let i = 0; i < input.length; i++) {\n console.log( solve(input[i].trim()).join(''));\n }\n\n process.exit(0);\n});"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let str = readLine();\n console.log(solve(str));\n }\n\n function solve(str) {\n let output = str[0];\n if (str.length === 2) return str;\n for (let i = 1; i < str.length - 1; i += 2) {\n output += str[i];\n }\n output += str[str.length - 1];\n return output;\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar s = next();\n\t\tvar n = s[0];\n\t\tfor(var j = 1; j < s.length - 1; j = j + 2){\n\t\t\tn += s[j];\n\t\t}\n\t\tn += s[s.length - 1];\n\t\toutput[i] = n;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let k = data[i];\n const len = k.length;\n if (len === 2) {\n console.log(k);\n i += 1;\n continue;\n }\n let str = '';\n for (let i = 0; i <= len - 2; i += 2) str += k[i];\n str += k[len - 2];\n console.log(str);\n i += 1;\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\n\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n let tests = parseInt(lines.shift(), 10);\n while(tests--) {\n const b = lines.shift();\n const a = b\n .split('')\n .filter((_, index) => {\n return index === 0 ||\n index === b.length - 1 ||\n index % 2\n }\n ).join('');\n console.log(a);\n }\n});\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n lines.shift()\n for(let line of lines) {\n console.log(solution(line))\n }\n}\n\nfunction solution(line) {\n let ans = line[0]\n for(let i = 1; i < line.length - 1; i += 2) {\n ans += line[i]\n }\n ans += line[line.length - 1]\n return ans\n}"}, {"source_code": "function solve(s) {\n const result = [];\n result.push(s[0]);\n for (let i = 2; i < s.length; i = i + 2) {\n result.push(s[i]);\n }\n if ((s.length % 2) === 0) {\n result.push(s[s.length - 1]);\n }\n return result.join('');\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const result = solve(t);\n console.log(result);\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(s) {\n const result = [];\n result.push(s[0]);\n for (let i = 2; i < s.length; i = i + 2) {\n result.push(s[i]);\n }\n if ((s.length % 2) === 0) {\n result.push(s[s.length - 1]);\n }\n return result.join('');\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n const result = solve(line);\n console.log(result);\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet inputData = '';\nlet currentLine = 0;\n\nfunction input() {\n return inputData[currentLine++];\n}\n\nprocess.stdin.on('data', _ => inputData += _);\n\nprocess.stdin.on('end', () => {\n inputData = inputData.split(/\\s+/);\n let noOfTestcases = input();\n let outputString = '';\n while (noOfTestcases--) {\n let str = input();\n\n outputString += originalWord(str) + '\\n';\n }\n process.stdout.write(outputString);\n // console.log(inputData);\n\n});\n\nfunction originalWord(str) {\n if (str.length <= 2) return str;\n let newStr = str[0];\n for (let i = 1; i < str.length - 1; i = i + 2) {\n let char = str[i];\n newStr += char;\n\n\n }\n newStr += str[str.length - 1]\n return newStr;\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nbCases= +input[index++]\n for (let i = 0; i < nbCases; i++){\n let str = input[index++]\n let ret = str[0];\n for (let i = 0; i < str.length - 1; i = i + 2){\n ret += str[i + 1]\n }\n console.log(ret);\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n \n for(let r = 0;r {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve(str) {\n var res = str.substr(0,2);\n for (var i=3; i {\n let input = process.stdin.read();\n input = input.trim();\n input = input.split('\\n').slice(1);\n\n main(input);\n});\n\nfunction main(input) {\n for (let i = 0; i < input.length; i++) {\n console.log(solve(input[i]).join(''));\n }\n process.exit(0);\n}\n\nfunction solve(input) {\n let data = [];\n\n for (let i = 0; i < input.length - 1; i += 2) {\n data.push(input[i]);\n }\n\n data.push(input[input.length - 1]);\n\n return data;\n}"}], "src_uid": "ac77e2e6c86b5528b401debe9f68fc8e"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst seq = (s, e) => Array.from(Array(e - s + 1), (_, i) => s + i);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\r\n\t\tconst x = 2 * k - n - 1;\r\n\t\tconst ans = [...seq(1, x), ...seq(x + 1, k).reverse()];\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "/*\r\n * File Created: Thursday, 14th January 2021 3:54:21 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const [n, k] = readLine().split(' ').map(Number);\r\n \r\n const res = c(n,k);\r\n\r\n console.log(res.join(\" \"));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n // console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n }\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nfunction gcd(a,b){\r\n if(b === 0) return a;\r\n else{\r\n return gcd(b, a % b)\r\n }\r\n}\r\n\r\nfunction lcm(a,b){\r\n return (a * b) / gcd(a,b)\r\n}\r\n\r\nfunction mul(s, k) {\r\n let res = '';\r\n while(k--) res += s;\r\n return res;\r\n}\r\n\r\nfunction b(s,t){\r\n const n = s.length;\r\n const m = t.length;\r\n const g = gcd(n,m);\r\n // console.log('gcd(n,m) = ',g,'mul(s,m/g) = ', mul(s, m/ g), 'mul(t,n/g) = ', mul(t, n / g), 'm/g = ', m/g, 'n/g = ', n/g)\r\n if(mul(s,m /g) === mul(t, n / g)){\r\n return mul(s, m / g);\r\n } else {\r\n return -1;\r\n }\r\n}\r\n\r\nfunction c(n ,k){\r\n let ans = [];\r\n for(let i = 1; i < (k - (n - k)); i++){\r\n ans.push(i);\r\n }\r\n for(let i = k ; i >= (k - (n - k)); i--){\r\n ans.push(i);\r\n }\r\n return ans\r\n}\r\n\r\nmodule.exports = c;"}], "negative_code": [], "src_uid": "67de9506ac2458ee67346bae1a9e3926"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n arr.sort((p, q) => p - q)\n return arr[0] + arr[1] === arr[2]\n || (arr[0] === arr[1] && !(arr[2] & 1))\n || (arr[1] === arr[2] && !(arr[0] & 1))\n}\n", "positive_code": [{"source_code": "var t = +readline()\r\nfor(var index = 1; index<=t; index++){\r\n var test = readline().split(' ')\r\n var a = +test[0]\r\n var b = +test[1]\r\n var c = +test[2]\r\n print(taskContext1(a,b,c))\r\n \r\n}\r\n\r\n\r\nfunction taskContext1(a,b,c) {\r\n \r\n if ((b == c && a % 2 == 0) || (a == c && b % 2 == 0) || (b == a && c % 2 == 0)){\r\n return 'Yes'\r\n }\r\n else if (a == b + c || b == c + a || c == a + b){\r\n return 'Yes'\r\n }\r\n\r\n return 'No'\r\n \r\n\r\n}"}, {"source_code": " var t = parseInt(readline());\r\n\r\n function check(val) {\r\n return val % 2 === 0\r\n }\r\n\r\n function solve() {\r\n var input = readline()\r\n .split(\" \")\r\n .map((data) => +data).sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var val1 = input[0]\r\n var val2 = input[1]\r\n var val3 = input[2]\r\n\r\n if (val1 === val2) {\r\n if (!check(val3)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n } else if (val2 === val3) {\r\n if (!check(val1)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n } else if (val3 === val1) {\r\n if (!check(val2)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n }\r\n\r\n var val = val1 + val2\r\n if (val === val3) {\r\n return \"YES\"\r\n }\r\n return \"NO\"\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}, {"source_code": "t = readline()\r\nwhile (t--) {\r\n input = readline().split(\" \").map(Number).sort(function (a, b) { return a - b });\r\n if (input[0] === input[1] || input[1] === input[2] || input[0] === input[2]) {\r\n if (input[0] === input[1]) {\r\n if (input[2] % 2 === 0) {\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n } else if (input[1] === input[2]) {\r\n if (input[0] % 2 === 0) {\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n } else if (input[0] === input[2]) {\r\n if (input[1] % 2 === 0) {\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n } else {\r\n if (input[2] === input[0] + input[1]) {\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n }\r\n}"}, {"source_code": "const numTestCases = parseInt(readline());\r\n\r\nfor (var i = 0; i < numTestCases; i++) {\r\n var inputNums = readline().split(' ');\r\n var l1 = parseInt(inputNums[0]);\r\n var l2 = parseInt(inputNums[1]);\r\n var l3 = parseInt(inputNums[2]);\r\n if (l1 === l2 + l3 || l2 === l1 + l3 || l3 === l2 + l1) {\r\n print (\"Yes\");\r\n continue;\r\n }\r\n \r\n if (l1 % 2 === 0 && l2 === l3 || (l2 % 2 === 0 && l1 === l3) || (l3 % 2 === 0 && l1 === l2)) {\r\n print(\"Yes\");\r\n } else {\r\n print(\"No\");\r\n }\r\n}"}, {"source_code": "t = readline();\r\nwhile (t--) {\r\n n = readline().split(' ');\r\n x = +n[0];\r\n y = +n[1];\r\n z = +n[2];\r\n if (x + y == z || y + z == x || x + z == y) print(\"YES\");\r\nelse if (\r\n (x == y && z % 2 == 0) || (y == z && x % 2 == 0) || (x == z && y % 2 == 0))\r\n print(\"YES\");\r\nelse print(\"NO\");\r\n}\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var test = readLine();\r\n while(test--)\r\n {\r\n var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n arr.sort();\r\n var a = arr[0];\r\n var b = arr[1];\r\n var c = arr[2];\r\n var sum = a+b+c;\r\n if (a+b == c || b+c==a || a+c==b){\r\n console.log(\"YES\");\r\n }\r\n else if (a == b && c % 2 == 0){\r\n console.log(\"YES\");\r\n }\r\n else if (b == c && a % 2 == 0){\r\n console.log(\"YES\");\r\n }\r\n else if (a == c && b % 2 == 0){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n \r\n }\r\n return 0;\r\n}"}, {"source_code": "const readline = require('readline')\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(arr) ? 'YES' : 'NO'\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n \r\nfunction solve(arr) {\r\n arr.sort((p, q) => p - q)\r\n return arr[0] + arr[1] === arr[2]\r\n || (arr[0] === arr[1] && !(arr[2] & 1))\r\n || (arr[1] === arr[2] && !(arr[0] & 1))\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let a = readline().split(\" \").map(f => parseInt(f));\r\n console.log(solve(a))\r\n function solve(x) {\r\n if(x[0] == x[1]+x[2] || x[1] == x[0]+x[2] || x[2] == x[0]+x[1]) {\r\n return 'YES';\r\n }\r\n var x1 = x[1]==x[2]\r\n var x2 = x[0]==x[2]\r\n var x3 = x[1]==x[0]\r\n if(x1 && x[0]%2==0) return 'YES'; \r\n if(x2 && x[1]%2==0) return 'YES';\r\n if(x3 && x[2]%2==0) return 'YES';\r\n return 'NO';\r\n }\r\n \r\n}"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const tsc = parseInt(await getLine());\r\n for(let nsc = 0; nsc < tsc; nsc++) {\r\n const l = (await getLine()).split(' ').map(s => parseInt(s));\r\n l.sort((a,b) => (a - b));\r\n if (l[1] === l[2]) {\r\n if (l[0] % 2 === 0)\r\n console.log('YES');\r\n else\r\n console.log('NO');\r\n } \r\n else {\r\n if (l[0] + l[1] === l[2] || (l[0] === l[1] && l[2] % 2 === 0)) {\r\n console.log('YES');\r\n } else\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i].split(' ').map(Number);\n var a = n[0], b = n[1], c = n[2];\n if(a == b){\n if(c % 2 === 0){\n console.log('YES');\n continue;\n }\n }if(b == c){\n if(a % 2 === 0){\n console.log('YES');\n continue;\n }\n }if(c == a){\n if(b % 2 === 0){\n console.log('YES');\n continue;\n }\n }\n \n if(a + b == c){\n console.log('YES');\n continue;\n \n }if(b + c == a){\n console.log('YES');\n continue;\n \n }if(c + a == b){\n console.log('YES');\n continue;\n }\n console.log('NO');\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar list = nextIntArray(3);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < list.length; i++){\r\n\t\t\tvar L1 = list[i];\r\n\t\t\tvar L2 = list[(i + 1) % 3];\r\n\t\t\tvar L3 = list[(i + 2) % 3];\r\n\t\t\tif(L1 == L2 + L3){\r\n\t\t\t\tok = true;\r\n\t\t\t}\r\n\t\t\tif(L1 % 2 == 0){\r\n\t\t\t\tif(L2 == L3){\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.nums();\n\t\ta.sort((a, b) => a - b);\n\t\tans.push(a[0] + a[1] === a[2] || (a[0] === a[1] && a[2]%2 === 0) || (a[0]%2 === 0 && a[1] === a[2]));\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var fs = require('fs'), currentline = 0, input = fs.readFileSync(0, 'utf8').trim().split('\\n');\nfunction readline() { return input[currentline++]; }\nvar T = +readline();\nwhile (T--) {\n //let n = +readline();\n var nums = readline().split(' ').map(function (x) { return Number(x); });\n var l1 = nums[0], l2 = nums[1], l3 = nums[2];\n var ans = (l1 == l2 + l3) || (l2 == l1 + l3) || (l3 == l1 + l2); //lb\n var ans2 = (l1 % 2 == 0 && l2 == l3) || (l2 % 2 == 0 && l1 == l3) || (l3 % 2 == 0 && l1 == l2); //ll\n if (ans || ans2)\n console.log(\"YES\");\n else\n console.log(\"NO\");\n}\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\nconst x=+readline();\r\nlet s=[];\r\nfor(let i=0;i parseInt(i));\r\n if((data[0] === data[1] && data[2] %2 == 0) || (data[0] === data[2] && data[1] %2 ==0 ) || (data[1] === data[2] && data[0] %2 ==0)) print(\"YES\");\r\n else if(data[0] + data[1] == data[2] || data[0] + data[2] == data[1] || data[1] + data[2] == data[0]) print(\"YES\");\r\n else print(\"NO\");\r\n}\r\n\r\n "}], "negative_code": [{"source_code": "var count = parseInt(readline());\r\n \r\nwhile (count--){\r\n var n = readline().split(\" \").map(Number).sort();\r\n if (n[0] + n[1] === n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0) || n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}\r\n"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline().split(\" \").map(Number).sort();\r\n if (n[0] + n[1] === n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0)) {\r\n print(\"yes\");\r\n }else if (n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline().split(\" \").sort();\r\n print(n[0] + n[1]);\r\n if (n[0] + n[1] === n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0)) {\r\n print(\"yes\");\r\n }else if (n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline().split(\" \").sort();\r\n print(n[0]);\r\n if (n[0] + n[1] === n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0)) {\r\n print(\"yes\");\r\n }else if (n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline().split(\" \").sort();\r\n if (n[0] + n[1] === n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0)) {\r\n print(\"yes\");\r\n }else if (n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline().split(\" \").sort();\r\n if (n[0] + n[1] == n[2]) {\r\n print(\"yes\");\r\n }else if (n[0] === n[1] && (n[2] % 2 === 0)) {\r\n print(\"yes\");\r\n }else if (n[1] === n[2] && (n[0] % 2 === 0)) {\r\n print(\"yes\");\r\n }else{\r\n print(\"no\");\r\n }\r\n}"}, {"source_code": "var tests =parseInt(readline());\r\nfor(var i=0 ; i parseInt(i));\r\n if(((data[0] === data[1]) && data[2] %2 == 0) || ((data[0] === data[2]) && data[1] %2 ==0 ) || ((data[1] === data[2]) && data[0] %2 ==0)) {\r\n print(\"YES\");\r\n\r\n }\r\n else{\r\n var largest = data.sort().reverse();\r\n if(largest[0] === largest[1]+largest[2]){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }\r\n}\r\n\r\n "}, {"source_code": "var t = +readline()\r\nfor(var index = 1; index<=t; index++){\r\n var test = readline().split(' ')\r\n var a = +test[0]\r\n var b = +test[1]\r\n var c = +test[2]\r\n print(taskContext1(a,b,c))\r\n \r\n}\r\n\r\n\r\nfunction taskContext1(a,b,c) {\r\n \r\n var test = a+b+c\r\n if ((test) % 2 == 0 && test >= 4){\r\n return 'Yes'\r\n }else {\r\n return 'No'\r\n }\r\n \r\n\r\n}"}, {"source_code": " var t = parseInt(readline());\r\n\r\n function check(val) {\r\n return val % 2 === 0\r\n }\r\n\r\n function solve() {\r\n var input = readline()\r\n .split(\" \")\r\n .map((data) => +data).sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var val1 = input[0]\r\n var val2 = input[1]\r\n var val3 = input[2]\r\n\r\n if (val1 === val2) {\r\n if (!check(val3)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n } else if (val2 === val3) {\r\n if (!check(val1)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n } else if (val3 === val1) {\r\n if (!check(val2)) {\r\n return \"NO\"\r\n } else {\r\n return \"YES\"\r\n }\r\n }\r\n\r\n if (val1 < val3 && val2 < val3) {\r\n return \"YES\"\r\n }\r\n return \"NO\"\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var test = readLine();\r\n while(test--)\r\n {\r\n var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n arr.sort();\r\n var a = arr[0];\r\n var b = arr[1];\r\n var c = arr[2];\r\n var sum = a+b+c;\r\n if (a != b && b != c && a != c) {\r\n if (arr[2] === arr[1] + arr[0]) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n else {\r\n if ((sum)%2 === 0) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n \r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var test = readLine();\r\n while(test--)\r\n {\r\n var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n arr.sort();\r\n var a = arr[0];\r\n var b = arr[1];\r\n var c = arr[2];\r\n if (a != b && b != c && a != c) {\r\n if (arr[2] === arr[1] + arr[0]) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n else {\r\n if ((a+b+c)%2 === 0) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n \r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var test = readLine();\r\n while(test--)\r\n {\r\n var arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n arr.sort();\r\n if (arr[0] != arr[1] && arr[1] != arr[2] && arr[2] != arr[0]) {\r\n if (arr[2] === arr[1] + arr[0]) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n else {\r\n if ((arr[0] + arr[1] + arr[2])%2 === 0) {\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n \r\n }\r\n}"}, {"source_code": "let l1, l2, l3;\r\nif (l1 === l3 && l1 === l2){\r\n return console.log('Yes');\r\n} "}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const tsc = parseInt(await getLine());\r\n for(let nsc = 0; nsc < tsc; nsc++) {\r\n const l = (await getLine()).split(' ').map(s => parseInt(s));\r\n l.sort((a,b) => (a - b));\r\n if (l[1] === l[2]) {\r\n if (l[0] % 2 === 0)\r\n console.log('YES');\r\n else\r\n console.log('NO');\r\n } else {\r\n if (l[0] + l[1] === l[2]) {\r\n console.log('YES');\r\n } else\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "a4a69a5fbf35781ff0849332a45566ca"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(blist[i] - alist[i] > 1 || blist[i] - alist[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(blist[i] - alist[i] > 1 || blist[i] - alist[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var yes = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] > a[j] + 1){\n yes = false;\n break;\n }\n }\n console.log(yes ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] > a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n d.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n var point = []\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n point.push(i)\r\n }\r\n }\r\n for(let i = 0; i < point.length;i++){\r\n if(c[point[i]] != d[i]){\r\n c[point[i]]++\r\n }\r\n }\r\n var flag = true\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n flag = false\r\n }\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n d.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n var flag = true\r\n for(let i = 0; i < b;i++){\r\n if(d[i] - c[i] > 1 || d[i] - c[i] < 0){\r\n\t\t\t\tflag = false;\r\n\t\t\t}\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\t\tb.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = true;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] - b[i] != 0 && a[i] - b[i] != -1) ans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let a = parseInt(readline());\r\n while (a--) {\r\n let b = parseInt(readline());\r\n let c = readline().split(\" \").map(Number);\r\n let d = readline().split(\" \").map(Number);\r\n c.sort(function (a, b) {\r\n return b - a;\r\n });\r\n d.sort(function (a, b) {\r\n return b - a;\r\n });\r\n let flag = true;\r\n for (let i = 0; i < b; i++) {\r\n if (d[i] - c[i] > 1 || d[i] - c[i] < 0) {\r\n flag = false;\r\n }\r\n }\r\n flag ? print(\"YES\") : print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(blist[i] - alist[i] > 1 || blist[i] - alist[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(a[j] == b[j] || a[j] + 1 == b[j]){\n \n }else{\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] > a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const a = lines[l++].trim().split(' ').map(Number)\n const b = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, a, b) {\n a.sort((x, y) => x - y)\n b.sort((x, y) => x - y)\n // console.log(a)\n // console.log(b)\n for (let i = 0; i < a.length; i++) {\n const d = b[i] - a[i]\n if (d > 1 || d < 0) return 'NO'\n }\n return 'YES'\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const a = lines[l++].trim().split(' ').map(Number)\n const b = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, a, b) {\n a.sort((x, y) => x - y)\n b.sort((x, y) => x - y)\n // console.log(a)\n // console.log(b)\n for (let i = 0; i < a.length; i++) {\n const d = b[i] - a[i]\n if (d > 1) return 'NO'\n }\n return 'YES'\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(a[j] - 1 == b[j] || a[j] == b[j] || a[j] + 1 == b[j]){\n \n }else{\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});\n if(a[0] >= b[0] - 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[i] < a[j] || b[j] > a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[i] < a[i] || b[j] > a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[i] < a[i] || b[i] > a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[i] < a[i] || b[i] > a[i] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[i] || b[i] > a[i] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[i] > a[i] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] > a[i] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] >= a[j] + 1){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var flag = true;\n for(j = 0; j < n; j++){\n if(b[j] < a[j] || b[j] >= a[j]){\n flag = false;\n }\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort()\r\n d.sort()\r\n var flag = true\r\n for(let i = 0; i < b;i++){\r\n if(d[i] - c[i] > 1 || d[i] - c[i] < 0){\r\n\t\t\t\tflag = false;\r\n\t\t\t}\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort()\r\n d.sort()\r\n var flag = true\r\n for(let i = 0; i < b;i++){\r\n if(d[i] - c[i] > 1 || d[i] - c[i] < 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort()\r\n d.sort()\r\n var flag =1\r\n for(let i = 0; i < b;i++){\r\n flag &= (c[i] == d[i] || c[i] + 1 == d[i])\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort()\r\n d.sort()\r\n var point = []\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n point.push(i)\r\n }\r\n }\r\n var flag = 1\r\n for(let i = 0; i < point.length;i++){\r\n if(c[point[i]] != d[point[i]]){\r\n c[point[i]]++\r\n }\r\n // flag &= (c[point[i]] == d[point[i]] || c[point[i]] + 1 == d[point[i]])\r\n }\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n flag = 0\r\n }\r\n }\r\n // for(let i = 0; i < b;i++){\r\n // flag &= (c[i] == d[i] || c[i] + 1 == d[i])\r\n // print(flag)\r\n // }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n c.sort()\r\n d.sort()\r\n var point = []\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n point.push(i)\r\n }\r\n }\r\n for(let i = 0; i < point.length;i++){\r\n if(c[point[i]] != d[i]){\r\n c[point[i]]++\r\n }\r\n }\r\n var flag = true\r\n for(let i = 0; i < b;i++){\r\n if(c[i] != d[i]){\r\n flag = false\r\n }\r\n }\r\n if(flag){\r\n print(\"YES\")\r\n }\r\n else print(\"NO\")\r\n }\r\n}"}], "src_uid": "6ca98e655007bfb86f1039c9f096557e"} {"source_code": "let ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <=n ; j++){\n var g = lines[j].split(''), k = lines[j].split('').sort(), e =k[0] , s= '', o = 0\n for(l = 0; l < g.length; l++){\n if(e == g[l] ){\n g.splice(l, 1)\n break;\n }\n }\n s = e + ' '\n for(i =0; i < g.length; i++){\n s += g[i] \n }\n console.log(s)\n \n \n \n \n }\n});", "positive_code": [{"source_code": "var n = readline();\r\nvar result = 0;\r\nfor (; n>0; n--) {\r\n var x = readline();\r\n var y = 'z';\r\n for(i=0;i= x[i]) y = x[i];\r\n }\r\n var flg = 0;\r\n var ans = \"\";\r\n for(i=0;i0; n--) {\r\n var x = readline();\r\n var y = 'z';\r\n for(i=0;i= x[i]) y = x[i];\r\n }\r\n var flg = 0;\r\n var ans = \"\";\r\n for(i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').sort();\n var a = lines[i].split('');\n var l = k[0];\n var ans = l + ' ';\n for(j = 0; j < k.length; j++){\n if(a[j] == l){\n a.splice(j, 1);\n break;\n }\n }\n for(j = 0; j < a.length; j++){\n ans += a[j];\n }\n console.log(ans);\n }\n});\n"}, {"source_code": "function processData(input) {\r\n var t = 0;\r\n while(t < +(input[0])) {\r\n t++;\r\n const str = [...input[t]];\r\n const { val, ind = 0 } = str.reduce((acc, val, ind) => {\r\n if (val < acc.val) return { val, ind };\r\n return acc;\r\n }, { val: '{' });\r\n str.splice(ind, 1);\r\n console.log( val, str.join(''));\r\n }\r\n} \r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nlet inputString = '';\r\nprocess.stdin.on(\"data\", function (input) {\r\n inputString += input;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n processData(inputString);\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tvar L = \"\";\r\n\t\tvar R = \"\";\r\n\t\tfor(var i = 0; i < alpha.length; i++){\r\n\t\t\tif(s.indexOf(alpha[i]) != -1){\r\n\t\t\t\tL = alpha[i];\r\n\t\t\t\tfor(var j = 0; j < s.length; j++){\r\n\t\t\t\t\tif(s.indexOf(alpha[i]) != j){\r\n\t\t\t\t\t\tR += s[j];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(L + \" \" + R);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet tc = parseInt(readline());\n\tconst result = [];\n\twhile (tc > 0) {\n\t\ttc--;\n\t\tconst word = readline();\n\t\tlet min = 0;\n\t\tlet firstLetter = word.charAt(min);\n\t\tfor (let i = 1; i < word.length; i++) {\n\t\t\tif (word.charAt(i) < firstLetter) {\n\t\t\t\tmin = i;\n\t\t\t\tfirstLetter = word.charAt(min);\n\t\t\t}\n\t\t}\n\t\tresult.push([\n\t\t\tword[min],\n\t\t\t`${word.slice(0, min)}${word.slice(min + 1)}`,\n\t\t]);\n\t}\n\tfor (let i = 0; i < result.length; i++) {\n\t\tconsole.log(`${result[i][0]} ${result[i][1]}`);\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar currentLine = 0;\r\nvar inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (let i = 0; i < t; i++) {\r\n const str = input();\r\n const arr = str.split(\"\").sort();\r\n const b = str.replace(arr[0], \"\");\r\n console.log(arr[0], b);\r\n }\r\n}\r\n"}, {"source_code": "const iteration_number = readline();\r\nvar s,a,b;\r\n \r\nfor (i=1; i<=iteration_number; i++){\r\n s= readline()\r\n var min = 'z';\r\n for(j=0; j stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0].split(' ').map(Number);\n var n = t[0], k = t[1];\n var a = lines[1].split(' ').map(Number);\n var max = 1;\n var cnt = 1;\n for(i = 1; i < n; i++){\n if(a[i] == a[i - 1]){\n max = cnt;\n cnt = 0;\n }\n cnt++;\n }\n max = cnt;\n console.log(max);\n});\n"}, {"source_code": "let ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0], e = 0, g = 0\n for(j = 1; j <= n; j++){\n var k = Number(lines[j]) \n e = '', g = ''\n if(k % 2 == 1){\n e = '1' + ' '\n for(l = 1; l < k; l+=2){\n e += (l + 2) + ' ' + (l + 1) + ' '\n }\n console.log(e)\n }else{\n for(l = 2; l <= k; l+=2){\n e += (l) + ' ' + (l - 1) + ' '\n }\n console.log(e)\n }\n }\n});"}, {"source_code": "const iteration_number = readline();\r\nvar s,a,b;\r\n \r\nfor (i=1; i<=iteration_number; i++){\r\n s= readline()\r\n var min = 'z';\r\n for(j=0; j {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let target = readline();\r\n let days = 1;\r\n let thisDay = 0;\r\n let chars = {};\r\n target.split('').forEach((char, i) => {\r\n if (chars[char] === undefined) {\r\n thisDay++;\r\n chars[char] = true;\r\n if (thisDay === 4) {\r\n thisDay = 1;\r\n chars = {};\r\n chars[char] = true;\r\n days++;\r\n }\r\n }\r\n });\r\n output(days);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseString = readline();\r\n var caseMap = new Map();\r\n var count = 0;\r\n for (var j = 0; j < caseString.length; j++)\r\n {\r\n if (!caseMap.has(caseString[j]))\r\n {\r\n if (caseMap.size === 3)\r\n {\r\n count++;\r\n caseMap.clear();\r\n }\r\n caseMap.set(caseString[j], 1);\r\n }\r\n }\r\n if (caseMap.size > 0) count++;\r\n print(count);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var set = new Set();\r\n var s = readline();\r\n var index = 0;\r\n var ans = 1;\r\n while (index < s.length) {\r\n var c = s.charAt(index);\r\n if (!set.has(c)) {\r\n if (set.size == 3) {\r\n set = new Set();\r\n ans++;\r\n }\r\n set.add(c);\r\n }\r\n index++;\r\n }\r\n print(ans);\r\n }"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar s = readString();\r\n\t\tvar cnt = 0;\r\n\t\tvar sett = new Set();\r\n\t\tfor (var c of s) {\r\n\t\t\tif (!sett.has(c)) {\r\n\t\t\t\tif (sett.size == 3) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t\tsett = new Set();\r\n\t\t\t\t}\r\n\t\t\t\tsett.add(c);\r\n\t\t\t}\r\n\t\t}\r\n\t\tcnt++;\r\n\t\tallans.push(cnt);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n str = readline().split('')\r\n\r\n acc = []\r\n ans = 0\r\n\r\n for(i = 0; i < str.length; i++){\r\n if(acc.indexOf(str[i]) === -1){\r\n if(acc.length === 3){\r\n\r\n ans++\r\n acc = []\r\nacc.push(str[i])\r\n }\r\n else{\r\n acc.push(str[i])\r\n }\r\n }\r\n }\r\n\r\n if(acc.length){\r\n ans++\r\n }\r\n \r\n print(ans)\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var mp = new Map();\r\n var f = alph();\r\n for(var i=0;i= 1) ans++;\r\n }\r\n // ans = max(ans, 1);\r\n console.log(ans)\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getStr(str) {\r\n const letters = []\r\n let days = 1\r\n for (let i = 0; i < str.length; i++) {\r\n if ( !letters.includes(str[i])) {\r\n if (letters.length === 3) {\r\n days++;\r\n letters.pop();\r\n letters.pop();\r\n letters.pop();\r\n }\r\n letters.push(str[i])\r\n }\r\n }\r\n return days\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getStr(values[i])\r\n console.log(ans)\r\n }\r\n});\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i].split('');\n var ans = 0;\n var st = new Map();\n for(j = 0; j < n.length; j++){\n st.set(n[j], 1);\n if(st.size == 4){\n ans++;\n st = new Map();\n st.set(n[j], 1);\n }\n }\n if(st.size !== 0){\n ans++;\n }\n console.log(ans);\n }\n});"}, {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var s = readline();\r\n var st = [];\r\n let ans = 1;\r\n for (let i = 0;i < s.length-1;++i) {\r\n let flag = true;\r\n for (let j = 0;j < st.length; ++j) {\r\n if (s.charAt(i) == st[j]) {\r\n flag = false;break;\r\n }\r\n }\r\n if (flag) {\r\n st.push(s.charAt(i));\r\n }\r\n if (st.length > 3) {\r\n // console.log(st);\r\n st.splice(0,st.length);\r\n st.push(s.charAt(i));\r\n ans++;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arr = readline().trim().split(\"\");\r\n if (arr.length <= 3) {\r\n console.log(1);\r\n continue;\r\n }\r\n let obj = {},\r\n cnt = 0,\r\n day = 0,\r\n i = 0;\r\n while (i < arr.length) {\r\n while (true) {\r\n if (i >= arr.length) {\r\n day++;\r\n break;\r\n }\r\n if (!obj[arr[i]]) {\r\n obj[arr[i]] = 1;\r\n cnt++;\r\n }\r\n if (cnt === 3) {\r\n day++;\r\n break;\r\n }\r\n i++;\r\n }\r\n i++;\r\n while (obj[arr[i]]) i++;\r\n obj = {};\r\n cnt = 0;\r\n }\r\n console.log(day);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n let res = 0;\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n let set = new Set([s[i]]);\r\n while (j + 1 < n && (set.has(s[j + 1]) || set.size < 3)) set.add(s[++j]);\r\n res++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let ans = 0\n let now = 3\n let map = {}\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (!map[x]) {\n if (now === 3) {\n ans++\n now = 0\n map = {}\n }\n map[x] = 1\n now++\n }\n }\n return ans\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar N = S.length;\r\n\t\tvar output = 1;\r\n\t\tvar set = new Set();\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(!set.has(S[i])){\r\n\t\t\t\tif(set.size == 3){\r\n\t\t\t\t\tset = new Set();\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t\tset.add(S[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseString = readline();\r\n var caseMap = new Map();\r\n var count = 0;\r\n for (var j = 0; j < caseString.length; j++)\r\n {\r\n if (!caseMap.has(caseString[j]))\r\n {\r\n if (caseMap.length === 3)\r\n {\r\n count++;\r\n caseMap.clear();\r\n }\r\n caseMap.set(caseString[j], 1);\r\n }\r\n }\r\n if (caseMap.length > 0) count++;\r\n print(count);\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var mp = new Map();\r\n var f = alph();\r\n for(var i=0;i 1) ans++;\r\n }\r\n ans = max(ans, 1);\r\n console.log(ans)\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nfunction getStr(str) {\r\n const letters = []\r\n let days = 1\r\n for (let i = 0; i < str.length; i++) {\r\n if (letters.length === 3) {\r\n days++;\r\n letters.pop();\r\n letters.pop();\r\n letters.pop();\r\n }\r\n if ( !letters.includes(str[i])) {\r\n letters.push(str[i])\r\n }\r\n }\r\n return days\r\n}\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n const [n,...values] = lines\r\n for (let i = 0; i< n; i++) {\r\n const ans = getStr(values[i])\r\n console.log(ans)\r\n }\r\n});"}], "src_uid": "bd9da9081902a87c61591fb58fcecfe3"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n let ans = 0\n const map = Array(k).fill(0)\n arr.forEach(x => {\n const r = x % k\n ans += (x - r) / k\n map[r]++\n })\n// console.log(map)\n //\n let i = 1\n let j = k - 1\n while (1) {\n while (i < j && !map[j]) j--\n if (i >= j) break\n while (i < j && (!map[i] || i + j < k)) i++\n if (i >= j) break\n //\n const now = Math.min(map[i], map[j])\n ans += now\n map[i] -= now\n map[j] -= now\n }\n // console.log(map, i, j)\n return ans + (i + i >= k ? Math.floor((map[i] || 0) / 2) : 0)\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n const b = num % m;\r\n if (!map.has(b)) map.set(b, []);\r\n map.get(b).push(num);\r\n }\r\n let res = 0;\r\n for (let [b, arr] of map) {\r\n const b1 = (m - b) % m;\r\n if (b === b1) {\r\n while (arr.length > 1) {\r\n const c = arr.pop(),\r\n d = arr.pop();\r\n res += (c + d) / m;\r\n }\r\n } else {\r\n while (arr.length && (_map$get = map.get(b1)) !== null && _map$get !== void 0 && _map$get.length) {\r\n var _map$get;\r\n const c = arr.pop(),\r\n d = map.get(b1).pop();\r\n res += (c + d) / m;\r\n }\r\n }\r\n }\r\n const keys = [...map.entries()].filter(([, values]) => values.length > 0).map(([k]) => k).sort((a, b) => b - a);\r\n const bst = new BinarySearchTree();\r\n for (let k of keys) {\r\n bst.insert(k);\r\n }\r\n for (let k of keys) {\r\n const arr = map.get(k);\r\n let t = bst.ceiling(m - k);\r\n while (arr.length && (k === t ? arr.length > 1 : (_map$get2 = map.get(t)) === null || _map$get2 === void 0 ? void 0 : _map$get2.length)) {\r\n var _map$get2, _map$get3;\r\n const c = arr.pop(),\r\n d = map.get(t).pop();\r\n res += Math.floor((c + d) / m);\r\n if (!arr.length) {\r\n bst.delete(k);\r\n }\r\n if (k !== t && !((_map$get3 = map.get(t)) !== null && _map$get3 !== void 0 && _map$get3.length)) {\r\n bst.delete(t);\r\n }\r\n t = bst.ceiling(m - k);\r\n }\r\n }\r\n const nums = [...map.entries()].filter(([, values]) => values.length > 0).sort((a, b) => b[0] - a[0]).map(([, values]) => values).flat();\r\n for (let i = 0; i < nums.length; i += 2) {\r\n res += Math.floor((nums[i] + nums[i + 1]) / m);\r\n }\r\n return res;\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n let ans = 0\n const map = Array(k).fill(0)\n arr.forEach(x => {\n const r = x % k\n ans += (x - r) / k\n map[r]++\n })\n// console.log(map)\n //\n let i = 1\n let j = k - 1\n while (1) {\n while (i < j && !map[j]) j--\n if (i >= j) break\n while (i < j && (!map[i] || i + j < k)) i++\n if (i >= j) break\n //\n const now = Math.min(map[i], map[j])\n ans += now\n map[i] -= now\n map[j] -= now\n }\n // console.log(map, i, j)\n return ans + Math.floor((map[i] || 0) / 2)\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n const b = num % m;\r\n if (!map.has(b)) map.set(b, []);\r\n map.get(b).push(num);\r\n }\r\n let res = 0;\r\n for (let [b, arr] of map) {\r\n const b1 = (m - b) % m;\r\n if (b === b1) {\r\n while (arr.length > 1) {\r\n const c = arr.pop(),\r\n d = arr.pop();\r\n res += (c + d) / m;\r\n }\r\n } else {\r\n while (arr.length && (_map$get = map.get(b1)) !== null && _map$get !== void 0 && _map$get.length) {\r\n var _map$get;\r\n const c = arr.pop(),\r\n d = map.get(b1).pop();\r\n res += (c + d) / m;\r\n }\r\n }\r\n }\r\n const nums = [...map.entries()].filter(([, values]) => values.length > 0).sort((a, b) => b[0] - a[0]).map(([, values]) => values).flat();\r\n for (let i = 0; i < nums.length; i += 2) {\r\n res += Math.floor((nums[i] + nums[i + 1]) / m);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "8e9ba5a2472984cd14b99790a157acd5"} {"source_code": "var t = parseInt(readline());\n\nwhile(t--)\n{\n var input = readline().split(\" \").map(function(x) { return parseInt(x); });\n var x = input[0];\n var y = input[1];\n var a = input[2];\n var b = input[3];\n\n var xy = Math.abs(x - y);\n var ab = a + b;\n if (xy % ab == 0)\n print(xy / ab);\n else\n print(-1);\n}", "positive_code": [{"source_code": "const main = (data) => {\n const n = data[0];\n\n for (let i = 1; i <= n; i++) {\n const [x, y, a, b] = data[i].split(' ').map(x => +x);\n\n if (Math.abs(x - y) % (a + b) == 0) {\n console.log(Math.abs(x - y) / (a + b));\n } else {\n console.log(-1);\n }\n }\n};\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const [x, y, a, b] = readInts(input, ptr++)\n if((y - x) % (a + b) === 0) wr((y - x) / (a + b))\n else wr( -1)\n\n }\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1304/A\n\"use strict\";\n\n// Interface of codeforces.com\nconst readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n = NaN;\nlet input = [];\nrl.on(\"line\", line => {\n let output = NaN;\n input = line.split(\" \").map(x => parseInt(x));\n if (isNaN(n)) {\n n = input[0];\n } else {\n output = solution(input);\n console.log(output);\n }\n});\nrl.on(\"close\", () => {\n // console.log(input)\n});\n// End of interface\nconst solution = function(inputs) {\n let x = inputs[0];\n let y = inputs[1];\n let a = inputs[2];\n let b = inputs[3];\n\n let distance = y - x;\n let steps = a + b;\n if (distance % steps == 0) {\n return distance / steps;\n } else {\n return -1;\n }\n};\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [x, y, a, b] = d.split(' ').map(Number);\n let n = Math.abs(x - y);\n let ans = n % (a + b) ? -1 : n / (a + b);\n\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "/** \n * @author Sunwarul Islam\n * JavaScript Developer\n*/ \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => {\n return str.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = +(readLine());\n for (let i = 0; i < t; i++) {\n const arr = readLine().split(' ').map(Number);\n const [x, y, a, b] = arr;\n const diff = y - x;\n const total = a + b;\n if (diff % total !== 0) {\n console.log('-1');\n } else {\n console.log(diff / total);\n }\n }\n}"}, {"source_code": "var data = \"\";\n\nprocess.stdin.on(\"data\", x => data += x);\n\n// process.on(\"SIGINT\", () => {\nprocess.stdin.on(\"end\", () => {\n\n\tvar eol = data.indexOf(\"\\r\") ? (data.indexOf(\"\\n\") ? \"\\r\\n\" : \"\\r\") : \"\\n\";\n\n\tvar lines = data.split(eol);\n\n\tvar n = +lines.shift();\n\n\tfor(let i = 0; i < n; i++) {\n\n\t\tvar arr = [];\n\t\tvar l = f.length;\n\t\tfor(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);\n\t\tf.apply({}, arr);\n\t}\n\n\tprocess.exit(0);\n});\n\nfunction f(c) {\n\n\tvar [x, y, a, b] = c.split(\" \").map(x => +x);\n\tvar val = (y-x)/(a+b);\n\tconsole.log(Number.isInteger(val) ? val : -1);\n}\n"}, {"source_code": "var data = \"\";\n\nprocess.stdin.on(\"data\", x => data += x);\n\n// process.on(\"SIGINT\", () => {\nprocess.stdin.on(\"end\", () => {\n\n var eol = data.indexOf(\"\\r\")+1 ? (data.indexOf(\"\\n\")+1 ? \"\\r\\n\" : \"\\r\") : \"\\n\";\n\n var lines = data.split(eol);\n\n var n = +lines.shift().split(\" \")[0];\n\n if(lines[lines.length-1] == \"\") lines.pop();\n\n for(let i = 0; i < n; i++) {\n\n var arr = [];\n var l = f.length;\n for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);\n if(!l) {\n arr = lines;\n i = n;\n }\n f.apply({}, arr);\n }\n\n\tconsole.log(ans);\n\n process.exit(0);\n});\n\nvar ans = \"\";\n\nfunction f(c) {\n\tvar [x, y, a, b] = c.split(\" \").map(x => +x);\n\tvar val = (y-x)/(a+b);\n\tans += (Number.isInteger(val) ? val : -1) + \" \";\n}\n"}, {"source_code": "var data = \"\";\n\nprocess.stdin.on(\"data\", x => data += x);\n\n// process.on(\"SIGINT\", () => {\nprocess.stdin.on(\"end\", () => {\n\n var eol = data.indexOf(\"\\r\")+1 ? (data.indexOf(\"\\n\")+1 ? \"\\r\\n\" : \"\\r\") : \"\\n\";\n\n var lines = data.split(eol);\n\n var n = +lines.shift().split(\" \")[0];\n\n if(lines[lines.length-1] == \"\") lines.pop();\n\n for(let i = 0; i < n; i++) {\n\n var arr = [];\n var l = f.length;\n for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);\n if(!l) {\n arr = lines;\n i = n;\n }\n f.apply({}, arr);\n }\n\n process.exit(0);\n});\n\nfunction f(c) {\n\tvar [x, y, a, b] = c.split(\" \").map(x => +x);\n\tvar val = (y-x)/(a+b);\n\tconsole.log(Number.isInteger(val) ? val : -1);\n}\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\ntxt.shift()\n\nfor (let i = 0; i < txt.length; i++) {\n doit(...txt[i].split(\" \").filter(data=>data.length>0).map(data=>data*1))\n\n}\n\nfunction doit(x,y,a,b) {\n let r=(y-x)/(a+b);\n \n if(r==Math.floor(r)){\n console.log(r);\n \n }else{\n console.log(-1);\n \n }\n \n \n\n}"}, {"source_code": "var tests = parseInt(readline())\nfor (var i = 0; i < tests; i++){\n var interim = readline().split(' ').map((val)=>{\n return parseInt(val);\n })\n var res = (interim[1] - interim[0])/(interim[2]+interim[3])\n print(Number.isInteger(res) ? res : -1)\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = myconv(next(),4);\n var x = tmp[0];\n var y = tmp[1];\n var a = tmp[2];\n var b = tmp[3];\n if((y - x) % (a + b) == 0){\n output[i] = (y - x) / (a + b);\n }else{\n output[i] = \"-1\";\n }\n }\n myout(myconv(output,9));\n}"}, {"source_code": "r=readline;for(k=r();k--;){x=r().split(\" \");a=x[1]-x[0];b=x[2]*1+x[3]*1;print(a%b?-1:~~(a/b))}"}, {"source_code": "r=readline;for(k=r();k--;print(a%b?-1:~~(a/b))){x=r().split(\" \");a=x[1]-x[0];b=x[2]*1+x[3]*1}"}, {"source_code": "r=readline;for(k=r();k--;print(a%b?-1:~~(-a/b))){x=r().split(\" \");a=x[1]-x[0];b=-x[2]-x[3]}"}, {"source_code": "var z = parseInt(readline());\n\nvar a;\nvar b;\nvar c;\nvar d;\n\nfor(var i=0; i data += x);\n\n// process.on(\"SIGINT\", () => {\nprocess.stdin.on(\"end\", () => {\n\n var eol = data.indexOf(\"\\r\")+1 ? (data.indexOf(\"\\n\")+1 ? \"\\r\\n\" : \"\\r\") : \"\\n\";\n\n var lines = data.split(eol);\n\n var n = +lines.shift().split(\" \")[0];\n\n if(lines[lines.length-1] == \"\") lines.pop();\n\n for(let i = 0; i < n; i++) {\n\n var arr = [];\n var l = f.length;\n for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);\n if(!l) {\n arr = lines;\n i = n;\n }\n f.apply({}, arr);\n }\n\n\tconsole.log(ans);\n\n process.exit(0);\n});\n\nvar ans = \"\";\n\nfunction f(c) {\n\tvar [x, y, a, b] = c.split(\" \").map(x => +x);\n\tvar val = (y-x)/(a+b);\n\tans += Number.isInteger(val) ? val : -1 + \" \";\n}\n"}], "src_uid": "9afcf090806cc9c3b87120b1b61f8f17"} {"source_code": "var repeatTimes = readline();\r\n\r\nwhile (repeatTimes--) {\r\n var n = readline()\r\n var s = readline()\r\n var oper = 0\r\n for (var i = 0; i < s.length; i++) {\r\n if ((s[0] === '(') && (s[1] === ')')) {\r\n s = s.slice(2)\r\n i = 0\r\n oper++\r\n } else if ((s[i] == s[0]) && (i !== 0)) {\r\n s = s.slice(i + 1)\r\n i = 0\r\n oper++\r\n }\r\n }\r\n \r\n print(oper, ' ', s.length)\r\n}", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim();\r\n const checkPalindrome = (start, end, str) => {\r\n let i = start,\r\n j = end;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) return false;\r\n i++;\r\n j--;\r\n }\r\n return true;\r\n };\r\n let i = 0,\r\n j = i + 1,\r\n cnt = 0;\r\n while (i + 1 < n) {\r\n if (arr[i] === \"(\") {\r\n cnt++;\r\n i += 2;\r\n j = i + 1;\r\n } else {\r\n while (arr[i] !== arr[j] && j < n) j++;\r\n if (j > n) break;\r\n else {\r\n if (checkPalindrome(i, j, arr)) {\r\n i = j + 1;\r\n j = i + 1;\r\n cnt++;\r\n } else j++;\r\n }\r\n }\r\n }\r\n if (i === n) console.log(`${cnt} ${0}`);\r\n else if (i === n - 1) console.log(`${cnt} ${1}`);\r\n else console.log(`${cnt} ${n - i}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let i = 0\n let op = 0\n while (i < n) {\n if (str[i] === '(') {\n if (i + 1 < n) {\n op++\n i += 2\n } else {\n break\n }\n } else {\n let j = i + 1\n while (j < n && str[j] === '(') j++\n if (j < n) {\n op++\n i = j + 1\n } else {\n break\n }\n }\n }\n return op + ' ' + (n - i)\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\r\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\r\nconst print = console.log\r\nconst lines = []\r\nrl.on('line', line => {\r\n lines.push(line);\r\n});\r\nrl.on('close', main)\r\nlet rli = 0;\r\nfunction readline() {\r\n return lines[rli++];\r\n}\r\nconst EPS = 1e-6;\r\n \r\nfunction is_polindrom(s, from, to){\r\n while (from=to;\r\n}\r\nfunction is_formula(s, from, to){\r\n let cnt = 0;\r\n for (;from<=to; from++){\r\n if (s[from]=='(')\r\n cnt++;\r\n else\r\n cnt--;\r\n if (cnt<0)\r\n return false;\r\n }\r\n return cnt==0;\r\n}\r\n \r\nfunction is_good(s, from, to){\r\n if (is_polindrom(s, from, to))\r\n return true;\r\n if (is_formula(s, from, to))\r\n return true;\r\n}\r\n \r\nfunction calc(s){\r\n let cnt = 0, remaining = 0;\r\n let start = 0;\r\n while (start stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split('');\n var a = 0, b = 0;\n for(j = 1; j < n; j++){\n if(k[b] == '(' && k[j] == ')' || k[b] == k[j]){\n j++, a++;\n b = j;\n }\n }\n console.log(a, n - b);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 125 (Div. 2)\n2022-03-22\n\nC. Bracket Sequence Deletion\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n let l, seq;\n for (let i = 0; i < t; i++) {\n // INPUT: the length of the bracket sequence\n l = readline();\n l = parseInt(l);\n // INPUT: the bracket sequence\n seq = readline();\n\n // # of operations doable (we can greed this one)\n let numOps = 0;\n // position pointers\n let start = 0;\n let end = 1; // semi-open interval\n while (end <= l) {\n const curSeq = seq.slice(start, end);\n if (isRegular(curSeq) || isPalindromic(curSeq)) {\n numOps++;\n start = end;\n }\n end++;\n }\n console.log(numOps + ' ' + (end - start - 1));\n }\n}\n\nfunction isRegular(seq) {\n let open = 0;\n for (let i = 0; i < seq.length; i++) {\n if (seq.charAt(i) === '(') {\n open++;\n } else {\n open--;\n if (open < 0) {\n return false;\n }\n }\n }\n return open === 0;\n}\n\nfunction isPalindromic(seq) {\n for (let i = 0; i < seq.length/2; i++) {\n if (seq.charAt(i) !== seq.charAt(seq.length - i - 1)) {\n return false;\n }\n }\n return seq.length >= 2;\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim();\r\n const checkPalindrome = (start, end, str) => {\r\n let i = 0,\r\n j = end;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) return false;\r\n i++;\r\n j--;\r\n }\r\n return true;\r\n };\r\n let i = 0,\r\n j = i + 1,\r\n cnt = 0;\r\n while (i + 1 < n) {\r\n if (arr[i] === \"(\") {\r\n cnt++;\r\n i += 2;\r\n j = i + 1;\r\n } else {\r\n while (arr[i] !== arr[j] && j < n) j++;\r\n if (j > n) break;\r\n else {\r\n if (checkPalindrome(i, j, arr)) {\r\n i = j + 1;\r\n j = i + 1;\r\n cnt++;\r\n } else j++;\r\n }\r\n }\r\n }\r\n if (i === n) console.log(`${cnt} ${0}`);\r\n else if (i === n - 1) console.log(`${cnt} ${1}`);\r\n else console.log(`${cnt} ${n - i}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim();\r\n const checkPalindrome = (start, end, str) => {\r\n let i = 0,\r\n j = end;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) return false;\r\n i++;\r\n j--;\r\n }\r\n return true;\r\n };\r\n let i = 0,\r\n j = n - 1,\r\n cnt = 0;\r\n while (i + 1 < n) {\r\n if (arr[i] === \"(\") {\r\n cnt++;\r\n i += 2;\r\n } else {\r\n while (arr[i] !== arr[j]) j--;\r\n if (i !== j) {\r\n if (checkPalindrome(i, j, arr)) {\r\n i = j + 1;\r\n j = n - 1;\r\n cnt++;\r\n } else j--;\r\n } else break;\r\n }\r\n }\r\n if (i === n) console.log(`${cnt} ${0}`);\r\n else if (i === n - 1) console.log(`${cnt} ${1}`);\r\n else console.log(`${cnt} ${n - i}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim();\r\n const checkPalindrome = (start, end, str) => {\r\n let i = 0,\r\n j = end;\r\n while (i <= j) {\r\n if (str[i] !== str[j]) return false;\r\n i++;\r\n j--;\r\n }\r\n return true;\r\n };\r\n const checkValid = (start, end, str) => {\r\n let o = 0,\r\n c = 0;\r\n while (start <= end) {\r\n if (str[start] === \"(\") o++;\r\n else c++;\r\n if (c > o) return false;\r\n start++;\r\n }\r\n if (o === c) return true;\r\n };\r\n let i = 0,\r\n j = n - 1,\r\n len = n,\r\n cnt = 0;\r\n\r\n while (i < j) {\r\n if (arr[i] === arr[j]) {\r\n if (checkPalindrome(i, j, arr)) {\r\n i = j + 1;\r\n j = n - 1;\r\n if (i > j) len = 0;\r\n else if (i === j) len = 1;\r\n else len = j - i + 1;\r\n cnt++;\r\n continue;\r\n }\r\n } else if (arr[i] === \"(\" && arr[j] === \")\") {\r\n if (checkValid(i, j, arr)) {\r\n i = j + 1;\r\n j = n - 1;\r\n if (i > j) len = 0;\r\n else if (i === j) len = 1;\r\n else len = j - i + 1;\r\n cnt++;\r\n continue;\r\n }\r\n }\r\n j--;\r\n }\r\n console.log(`${cnt} ${len}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let i = 0\n let op = 0\n while (i < n) {\n let j = i\n let level = 0\n let fa = false\n while (j < n) {\n if (str[j] === '(') {\n level++\n } else {\n level--\n }\n if (level < 0) break\n if (!level) {\n fa = true\n break\n }\n j++\n }\n const a = fa ? j : i\n //\n j = i + 1\n let fb = false\n while (j < n) {\n if (isp(str, i, j)) {\n fb = true\n break\n }\n j++\n }\n const b = fb ? j : i\n j = Math.max(a, b)\n // console.log(a, b)\n if (i === j) break\n op++\n i = j + 1\n }\n return op + ' ' + (n - i)\n}\nfunction isp(str, i, j) {\n while (i < j) {\n if (str[i] !== str[j]) return false\n i++\n j--\n }\n return true\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst EPS = 1e-6;\n\nfunction is_polindrom(s, from, to){\n while (from=to;\n}\nfunction is_formula(s, from, to){\n let cnt = 0;\n for (;from<=to; from++){\n if (s[from]=='(')\n cnt++;\n else\n cnt--;\n if (cnt<0)\n return false;\n }\n return cnt==0;\n}\n\nfunction is_good(s, from, to){\n if (is_polindrom(s, from, to))\n return true;\n if (is_formula(s, from, to))\n return true;\n}\n\nfunction calc(s){\n let cnt = 0, remaining = 0;\n let start = 0;\n while (start {\r\n return string.trim();\r\n });\r\n\r\n /**\r\n * readNumber() - int\r\n * readArray() - generic space separated array\r\n * readBoolean() - bool\r\n * readChar() - char\r\n * readLine() - string\r\n * readNumberArray() - numeric array\r\n */\r\n\r\n /** Code Starts */\r\n\r\n const solve = () => {\r\n const [n, z] = inputReader.readNumberArray();\r\n const arr = inputReader.readNumberArray();\r\n let res = 0;\r\n\r\n for (let el of arr) res = Math.max(res, el | z);\r\n console.log(res);\r\n };\r\n\r\n let tc = inputReader.readNumber();\r\n for (let t = 0; t < tc; ++t) solve();\r\n\r\n /** Transliterate : cp-convert -s forces.js -d out.js */\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, z] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n let max = -Infinity;\r\n for (let i = 0; i < arr.length; i++) {\r\n let r = arr[i] | z;\r\n if (r > max) {\r\n max = r;\r\n }\r\n }\r\n output(max);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n let res = 0;\r\n for (let num of a) {\r\n res = Math.max(res, num | m);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\n// var inf = 10000000000;\r\nfor(var qe=1;qe<=T;qe++) {\r\n var [n,z] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var ans = 0;\r\n \r\n for(var i=0;i {\r\n return string.trim();\r\n });\r\n\r\n /**\r\n * readNumber() - int\r\n * readArray() - generic space separated array\r\n * readBoolean() - bool\r\n * readChar() - char\r\n * readLine() - string\r\n * readNumberArray() - numeric array\r\n */\r\n\r\n /** Code Starts */\r\n\r\n const solve = () => {\r\n const [n, z] = inputReader.readNumberArray();\r\n const arr = inputReader.readNumberArray();\r\n let res = 0;\r\n\r\n for (let el of arr) res = Math.max(res, el | res);\r\n console.log(res);\r\n };\r\n\r\n let tc = inputReader.readNumber();\r\n for (let t = 0; t < tc; ++t) solve();\r\n\r\n /** Transliterate : cp-convert -s forces.js -d out.js */\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}], "src_uid": "bb6168528e04156f68bde2ffc1ba828f"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), m = { 0: 1 }, s = 0, res = 0;\n For(n, i => {\n if (m[s + a[i]]) { res++; s = a[i]; m = { [s]: 1, 0: 1 } }\n else m[s += a[i]] = 1;\n })\n log(res)\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [count, cSum, map] = [0, 0, {}];\n\n for (let i = 0; i < len; i++) {\n cSum += arr[i];\n if (!cSum || map[cSum]) {\n map = {};\n count++;\n cSum = arr[i];\n }\n map[cSum] = true;\n }\n\n console.log(count);\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var output = 0;\n var now = 0;\n var used = new Set([0]);\n for(var i = 0; i < N; i++){\n now += list[i];\n if(used.has(now)){\n output++;\n used = new Set([0]);\n now = list[i];\n }\n used.add(now);\n }\n myout(output);\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n), m = { 0: 1 }, s = 0, res = 0;\n For(n, i => {\n if (m[s + a[i]]) { res++; s = a[i]; m = { [s]: 1, 0: 1 } }\n else m[s += a[i]] = 1;\n })\n log(res)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = {};\n map[0] = 1;\n let sum = 0;\n let count = 0;\n for(let i = 0; i < a.length; i++){\n sum += a[i];\n if(map[sum] !== undefined){\n count += 1;\n map = {};\n map[0] = 1;\n sum = a[i];\n }\n\n map[sum] = 1;\n }\n\n console.log(count);\n}\n\n"}, {"source_code": "'use strict'\nfunction mlt() { return readline().split(' ').map(x => parseInt(x)); }\nfunction inp() { return parseInt(readline()) }\nfunction solv() {\n var x = inp();\n var s = mlt();\n var st = new Set()\n var pf = 0\n st.add(pf)\n var res = 0\n for (var n = 0; n < x; n++) {\n pf += s[n];\n if (!st.has(pf)) {\n st.add(pf)\n }\n else {\n st.add(pf + 1e10);\n st.add(pf + 1e10 + s[n]);\n res++;\n pf = 1e10 + s[n] + pf;\n }\n }\n print(res)\n}\nvar tc = 1;\n// tc= parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "'use strict'\nfunction mlt() { return readline().split(' ').map(x => parseInt(x)); }\nfunction inp() { return parseInt(readline()) }\nfunction solv() {\n var x = inp();\n var s = mlt();\n var st = new Set()\n var pf = 0\n st.add(pf)\n var res = 0\n for (var n = 0; n < x; n++) {\n pf += s[n];\n if (!st.has(pf)) {\n st.add(pf)\n }\n else {\n st.add(pf + 1e10);\n st.add(pf + 1e10 + s[n]);\n res++;\n pf = 1e10 + s[n] + pf;\n }\n }\n print(res)\n}\nvar tc = 1;\n// tc= parseInt(readline())\nwhile (tc--) solv()"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = {};\n let sum = 0;\n let count = 0;\n let arr = new Array(n);\n let f = 0;\n for(let i = 0; i < a.length; i++){\n sum += a[i];\n if(map[sum] !== undefined){\n count += 1;\n }else{\n map[sum] = i;\n }\n if(sum === 0)\n f = 1;\n arr[i] = sum;\n }\n\n console.log(arr);\n console.log(f === 0 ? count : count + 1);\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = {};\n let sum = 0;\n let count = 0;\n //let arr = new Array(n);\n let f = 0;\n for(let i = 0; i < a.length; i++){\n sum += a[i];\n if(map[sum] !== undefined){\n count += 1;\n }else{\n map[sum] = i;\n }\n if(sum === 0)\n f = 1;\n }\n\n //console.log(arr);\n console.log(f === 0 ? count : count + 1);\n}\n\n"}], "src_uid": "05548be393d794bf106708627220b9a3"} {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let param = str.split(' ')\n a = Array.from(param[0])\n s = Array.from(param[1])\n\n if (a.length > s.length) {\n console.log('-1')\n break\n }\n let res = Array.from('')\n let atemp = ''\n let stemp = ''\n let n = ''\n flag = true\n while (a.length > 0) {\n if (s.length === 0) {\n console.log('-1')\n flag = false\n break\n }\n atemp = a.pop()\n stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp)) {\n res.push(parseInt(stemp) - parseInt(atemp))\n } else {\n if (s.length === 0) {\n console.log('-1')\n flag = false\n break\n }\n n = s.pop()\n if (n != '1') {\n console.log('-1')\n flag = false\n break\n }\n stemp = n + stemp\n res.push(parseInt(stemp) - parseInt(atemp))\n }\n }\n if (flag) {\n while (s.length > 0) {\n res.push(parseInt(s.pop()))\n }\n while (res[res.length - 1] === 0) {\n res.pop()\n }\n let resstr = ''\n while (res.length > 0) {\n resstr += res.pop()\n }\n console.log(resstr)\n }\n }\n\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let inpArr = readLine().split(\" \");\r\n let a = BigInt(inpArr[0]);\r\n let s = BigInt(inpArr[1]);\r\n let b = [];\r\n while (s > 0) {\r\n let x = a % 10n, y = s % 10n;\r\n if (x <= y) {\r\n b.unshift(y - x);\r\n } else {\r\n s = (s / 10n);\r\n y += 10n * (s % 10n);\r\n if (x < y && y >= 10 && y <= 19) {\r\n b.unshift(y - x);\r\n } else {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n a = (a / 10n);\r\n s = (s / 10n)\r\n }\r\n if (a) {\r\n console.log(-1);\r\n } else {\r\n console.log(BigInt(b.join(\"\")).toString());\r\n }\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] !== '\\r') {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t // console.log(s[i-1])\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t\tif(b[t] == '-') {\r\n \t\t y = false;\r\n \t\t break;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t if(b[t] == '-') {\r\n \t y = false;\r\n \t break;\r\n \t }\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(aIn, sIn) { \r\n let a = aIn.split('').map(Number);\r\n let s = sIn.split('').map(Number);\r\n let value, b = '';\r\n let oneDigitNumber;\r\n let twoDigitsNumber;\r\n\r\n for (let i = s.length - 1; i >= 0; --i) {\r\n oneDigitNumber = s[i];\r\n twoDigitsNumber = s[i - 1] * 10 + s[i];\r\n \r\n if (oneDigitNumber >= a[a.length - 1]) {\r\n value = oneDigitNumber - a[a.length - 1];\r\n } else if (twoDigitsNumber > a[a.length - 1] && twoDigitsNumber - a[a.length - 1] < 10) {\r\n value = twoDigitsNumber - a[a.length - 1];\r\n i--;\r\n } else if (!a.length) {\r\n value = s[i];\r\n } else {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n b = value + b;\r\n a.pop();\r\n }\r\n\r\n if (Number(a.join('')) > 0) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n b = b.replace(/^0+/, '') || '0';\r\n\r\n console.log(b);\r\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let param = str.split(' ')\n a = Array.from(param[0])\n s = Array.from(param[1])\n\n let suitable = true\n\n if (a.length > s.length) {\n suitable = false\n }\n let res = []\n let atemp = []\n let stemp = []\n\n while (a.length > 0) {\n if (s.length === 0) suitable = false\n atemp = a.pop()\n stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp))\n res.unshift(parseInt(stemp) - parseInt(atemp))\n else {\n if (s.length === 0) suitable = false\n if (s.pop() != '1') suitable = false\n res.unshift(parseInt(stemp) + 10 - parseInt(atemp))\n }\n }\n while (s.length > 0) res.unshift(parseInt(s.pop()))\n while (res[0] === 0) res.shift()\n console.log(suitable ? res.join('') : '-1')\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let [a, s] = readline().split(' ');\n\n function getDigitB() {\n if (s.length === 0) {\n return null;\n }\n let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;\n let sd = parseInt(s[s.length - 1]);\n let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;\n if (ad <= sd) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 1);\n return sd - ad;\n } else if (sdd === 1 && sd < 9) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 2);\n return sdd * 10 + sd - ad;\n } else {\n return null;\n }\n }\n\n let b = '';\n let bd = getDigitB();\n while (bd !== null) {\n b = bd.toString() + b;\n bd = getDigitB();\n }\n let start = -1;\n for (let i = 0; i < b.length; i++) {\n if (b[i] !== '0') {\n start = i;\n break;\n }\n }\n if (!s && !a && start !== -1) {\n console.log(b.slice(start));\n } else {\n console.log('-1');\n }\n }\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, s] = readline().trim().split(\" \");\r\n let b = [];\r\n let i = n.length - 1,\r\n j = s.length - 1,\r\n ans = true;\r\n while (i >= 0) {\r\n if (j < 0) {\r\n ans = false;\r\n break;\r\n }\r\n let n1 = parseInt(n[i]),\r\n n2 = parseInt(s[j]);\r\n if (n1 <= n2) {\r\n b.push(n2 - n1);\r\n i--;\r\n j--;\r\n } else if (n1 > n2) {\r\n if (j - 1 < 0) {\r\n ans = false;\r\n break;\r\n }\r\n j--;\r\n n2 = parseInt(s[j]) * 10 + n2;\r\n if (n2 >= 10 && n2 <= 18) {\r\n b.push(n2 - n1);\r\n j--;\r\n } else {\r\n ans = false;\r\n break;\r\n }\r\n i--;\r\n }\r\n }\r\n if (ans === false) console.log(-1);\r\n else {\r\n while (j >= 0) b.push(s[j--]);\r\n let res = \"\",\r\n is = true;\r\n for (let i = b.length - 1; i >= 0; i--) {\r\n if (b[i] === 0 && is) continue;\r\n else {\r\n res += b[i];\r\n is = false;\r\n }\r\n }\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, s] = lines[l++].trim().split(' ')\n output[i] = solve(a, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, s) {\n let i = a.length - 1\n let j = s.length - 1\n const b = []\n while (i >= 0 && j >= 0) {\n const x = +a[i]\n const y = +s[j]\n if (y >= x) {\n b.unshift(y - x)\n i--\n j--\n } else if (s[j - 1] === '1') {\n b.unshift(y + 10 - x)\n i--\n j -= 2\n } else {\n return -1\n }\n }\n // console.log(i, j, b.join(''))\n if (i >= 0) return -1\n while (j >= 0) b.unshift(s[j--])\n return BigInt(b.join('')).toString()\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var line = readline().split(' ').map(String)\r\n var a = '0'.repeat(50) + line[0]\r\n var b = '0'.repeat(50) + line[1]\r\n \r\n const arr = []\r\n let ok = true\r\n for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--){\r\n if(b[j] >= a[i]){\r\n let tmp = Number(b[j]) - Number(a[i])\r\n arr.unshift(tmp)\r\n }\r\n else{\r\n let tmp = Number(b[j-1])*10 + Number(b[j]) - Number(a[i])\r\n if(tmp > 9 || tmp < 0){\r\n ok = false\r\n }\r\n else{\r\n arr.unshift(tmp)\r\n }\r\n j--\r\n }\r\n }\r\n while (arr[0] == 0) arr.shift()\r\n print(ok?arr.join(''):-1)\r\n }\r\n \r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var line = readline().split(' ').map(String)\r\n var a = '0'.repeat(50) + line[0]\r\n var b = '0'.repeat(50) + line[1]\r\n \r\n const arr = []\r\n let ok = true\r\n for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--){\r\n if(b[j] >= a[i]){\r\n let tmp = Number(b[j]) - Number(a[i])\r\n arr.unshift(tmp)\r\n }\r\n else{\r\n let tmp = Number(b[j-1])*10 + Number(b[j]) - Number(a[i])\r\n if(tmp > 9 || tmp < 0){\r\n ok = false\r\n }\r\n else{\r\n arr.unshift(tmp)\r\n }\r\n j--\r\n }\r\n }\r\n while (arr[0] == 0) arr.shift();\r\n print(ok?arr.join(''):-1)\r\n }\r\n \r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let num = parseInt(readline());\r\n while (num--) {\r\n let line = readline().split(\" \").map(String);\r\n let a = \"0\".repeat(50) + line[0];\r\n let b = \"0\".repeat(50) + line[1];\r\n\r\n const arr = [];\r\n let ok = true;\r\n for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--) {\r\n if (b[j] >= a[i]) {\r\n let tmp = Number(b[j]) - Number(a[i]);\r\n arr.unshift(tmp);\r\n } else {\r\n let tmp = Number(b[j - 1]) * 10 + Number(b[j]) - Number(a[i]);\r\n if (tmp > 9 || tmp < 0) {\r\n ok = false;\r\n } else {\r\n arr.unshift(tmp);\r\n }\r\n j--;\r\n }\r\n }\r\n while (arr[0] == 0) arr.shift();\r\n print(ok ? arr.join(\"\") : -1);\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, s] = rl().split(' ');\r\n\r\n\t\ta = '0'.repeat(50) + a;\r\n\t\ts = '0'.repeat(50) + s;\r\n\r\n\t\tconst b = [];\r\n\t\tlet ok = true;\r\n\t\tfor (let i = a.length - 1, j = s.length - 1; ok && i && j; i--, j--) {\r\n\t\t\tif (s[j] >= a[i]) {\r\n\t\t\t\tb.unshift(Number(s[j]) - Number(a[i]));\r\n\t\t\t} else {\r\n\t\t\t\tlet res = Number(s[j-1])*10 + Number(s[j]) - Number(a[i]);\r\n\t\t\t\tif (res > 9 || res < 0) \r\n\t\t\t\t\tok = false;\r\n\t\t\t\telse\r\n\t\t\t\t\tb.unshift(res);\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twhile (b[0] == 0) b.shift();\r\n\r\n\r\n\t\tconsole.log(ok ? b.join('') : -1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] !== '\\r') {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t // console.log(s[i-1])\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] < a[j]) {\r\n console.log([s[i], a[j]])\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t console.log(s[i-1])\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t console.log(b)\r\n \t\t console.log(s[i-1])\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t console.log(s[i-1])\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] < a[j]) {\r\n \t\tif(s[i-1] <= '1') {\r\n \t\t console.log(s[i-1])\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= '1') {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log('-1');\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] !== '\\r' && a[j] !== '\\r') {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n } else {\r\n console.log(s[i], a[j])\r\n j--;\r\n }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n if(s[i] !== '\\r' && a[j] !== '\\r') {\r\n if(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t } else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t }\r\n } else {\r\n j--;\r\n }\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n //console.log(y)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t console.log(s[i])\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} /*else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}*/\r\n \t} else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n console.log(y)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t console.log(s[i])\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n console.log(y)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t console.log(s[i])\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n console.log(y)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n // console.log(a, s)\r\n y == true ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0;i--) {\r\n console.log(s[i])\r\n console.log(a[i])\r\n }\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n // console.log(a, s)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=0;i=0 && j>=0;i--) {\r\n console.log(s[i])\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n // console.log(a, s)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=0;i=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n // console.log(a, s)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n console.log(s[i])\r\n console.log(a[j])\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n // console.log(a, s)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n console.log(a, s)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = '';\r\n a += n[0]\r\n let s = '';\r\n s += n[1]\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n console.log(n)\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline().split(' ');\r\n let a = n[0];\r\n let s = n[1];\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let [a, s] = readline().split(' ');\r\n var j = a.length-1;\r\n var b = '';\r\n var y = false;\r\n for(var i=s.length-1;i>=0 && j>=0;i--) {\r\n \tif(s[i] < a[j]) {\r\n \t\tif(i > 0 && s[i-1] <= 1) {\r\n \t \t var d = s[i-1]+s[i];\r\n \t\t b += d-a[j];\r\n \t\t i--;\r\n \t\t j--;\r\n \t\t} else {\r\n \t\t\ty = false;\r\n \t\t\tbreak;\r\n \t\t}\r\n \t} else {\r\n \t//\tif(j>=0) {\r\n \t\tb += s[i]-a[j]\r\n \t\tj--;\r\n \t\t/* else {\r\n \t\t\tb += s[i]\r\n \t\t}*/\r\n \t}\r\n }\r\n while(i>=0) {\r\n \tb += s[i];\r\n \ti--;\r\n }\r\n var ans = '';\r\n if(j == -1 && i == -1) {\r\n \tvar an = '';\r\n \ty = true;\r\n \tfor(var t = b.length-1;t>=0;t--) {\r\n \t\tif(b[t] !== '0') {\r\n \t\t\tbreak;\r\n \t\t}\r\n \t}\r\n \twhile(t >= 0) {\r\n \t\tan += b[t]\r\n \t\tt--;\r\n \t}\r\n \tans = an;\r\n } else {\r\n \ty = false;\r\n }\r\n y ? console.log(ans) : console.log(-1);\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, s] = lines[l++].trim().split(' ')\n output[i] = solve(a, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n// for (let i = 1; i < 1e3; i++) {\n// for (let j = 1; j < 1e3; j++) {\n// const b = solve(i + '', j + '')\n// if (b >= 0 && check(i + '', b + '') !== j + '') {\n// console.log(i, j, b)\n// return\n// }\n// }\n// }\n\n// console.log('sb', check('1', '19'))\nfunction check(a, b) {\n if (a.length < b.length) return check(b, a)\n if (a.length > b.length) {\n b = Array(a.length - b.length).fill(0).join('') + b\n }\n let s = ''\n for (let i = 0; i < a.length; i++) {\n s += String(+a[i] + +b[i])\n }\n return s\n}\nfunction solve(a, s) {\n const limit = Math.pow(2, s.length)\n for (let i = 0; i < limit; i++) {\n let n = ''\n for (let j = 0; j < s.length; j++) {\n if (i & (1 << j)) {\n n += '0' + s[j]\n } else {\n n += s[j]\n }\n }\n // console.log('sb', n, a)\n // if (n === '1002030412') throw 'sb'\n if (n.length < a.length * 2) continue\n const b = []\n for (let j = n.length - 2; j >= 0; j -= 2) {\n const x = +n.slice(j, j + 2) - (+a[j / 2] || 0)\n if (x < 0 || (x > 9 && a.length !== 1)) break\n b.unshift(x)\n }\n // console.log(n, a, b)\n if (b.length === a.length) {\n const r = BigInt(b.join('')).toString()\n if (check(a, r) === s) return r\n }\n }\n return -1\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, s] = lines[l++].trim().split(' ')\n output[i] = solve(a, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n// for (let i = 1; i < 1e3; i++) {\n// for (let j = 1; j < 1e3; j++) {\n// const b = solve(i + '', j + '')\n// if (b >= 0 && check(i + '', b + '') !== j + '') {\n// console.log(i, j, b)\n// return\n// }\n// }\n// }\n\nfunction check(a, b) {\n if (a.length < b.length) return check(b, a)\n if (a.length > b.length) {\n b = Array(a.length - b.length).fill(0).join('') + b\n }\n let s = ''\n for (let i = 0; i < a.length; i++) {\n s += String(+a[i] + +b[i])\n }\n return s\n}\nfunction solve(a, s) {\n const r = cal(a, s)\n // console.log(r)\n if (r && check(a, r) === s) {\n return BigInt(r).toString()\n } else {\n return -1\n }\n}\nfunction cal(a, s) {\n// console.log('sb', a, s)\n // if (a[0] === '0' && s[0] === '0') return ''\n if (a.length === 1 && s.length === 1) {\n s = +s\n a = +a\n return s < a ? '' : String(s - a)\n }\n if (a.length === 1 && s.length === 2) {\n if (a[0] === '0' || s[0] === '0') return ''\n // console.log(a, s)\n s = +s\n a = +a\n if (s < 20) {\n return String(s - a)\n } else {\n return ''\n }\n }\n if (s.length < a.length) return ''\n\n const b10 = cal(a[0], s[0])\n// console.log('sb', b10, s, a, s.length, a.length)\n if (b10) {\n if (a.length > 1) {\n const b11 = cal(a.slice(1), s.slice(1))\n // console.log('1', b10, b11)\n if (b10 && b11) return b10 + b11\n }\n }\n\n const b20 = cal(a[0], s.slice(0, 2))\n// console.log(b20)\n if (b20) {\n if (a.length > 1 && s.length > 2) {\n const b21 = cal(a.slice(1), s.slice(2))\n // console.log('2', b20, b21)\n if (b20 && b21) return b20 + b21\n }\n }\n\n return ''\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, s] = lines[l++].trim().split(' ')\n output[i] = solve(a, s)\n }\n console.log(output.join('\\n'))\n// })()\n})\n// for (let i = 1; i < 1e3; i++) {\n// for (let j = 1; j < 1e3; j++) {\n// console.log(i, j, solve(i + '', j + ''))\n// }\n// }\n\nfunction solve(a, s) {\n const r = cal(a, s)\n if (r) {\n return BigInt(r).toString()\n } else {\n return -1\n }\n}\nfunction cal(a, s) {\n if (a.length === 1 && s.length === 1) {\n s = +s\n a = +a\n return s < a ? '' : String(s - a)\n }\n if (a.length === 1 && s.length === 2 && s[0] !== '0') {\n s = +s\n a = +a\n if (s < 20) {\n return String(s - a)\n } else {\n return ''\n }\n }\n if (s.length < a.length) return ''\n\n let b10 = +s[0] - +a[0]\n// console.log(b10)\n if (b10 >= 0) {\n b10 += ''\n const b11 = cal(a.slice(1), s.slice(1))\n if (b10 && b11) return b10 + b11\n }\n\n let b20 = +s.slice(0, 2) - +a[0]\n// console.log(b20)\n if (s.length > 1 && s[0] !== '0' && b20 >= 0) {\n b20 += ''\n const b21 = cal(a.slice(1), s.slice(2))\n if (b20 && b21) return b20 + b21\n }\n\n return ''\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let inpArr = readLine().split(\" \");\r\n let a = parseInt(inpArr[0]);\r\n let s = parseInt(inpArr[1]);\r\n let b = [];\r\n while (s > 0) {\r\n let x = a % 10, y = s % 10;\r\n if (x <= y) {\r\n b.unshift(y - x);\r\n } else {\r\n s = parseInt(s / 10);\r\n y += 10 * (s % 10);\r\n if (x < y && y >= 10 && y <= 19) {\r\n b.unshift(y - x);\r\n } else {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n a = parseInt(a / 10);\r\n s = parseInt(s / 10)\r\n }\r\n if (a) {\r\n console.log(-1);\r\n } else {\r\n let ind = 0;\r\n while (b[ind] == 0) ind++;\r\n let str = \"\";\r\n for (let i = ind; i < b.length; i++) {\r\n str += b[i];\r\n }\r\n console.log(str);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let inpArr = readLine().split(\" \");\r\n let a = parseInt(inpArr[0]);\r\n let s = parseInt(inpArr[1]);\r\n let b = [];\r\n while (s > 0) {\r\n let x = a % 10, y = s % 10;\r\n if (x <= y) {\r\n b.unshift(y - x);\r\n } else {\r\n s = parseInt(s / 10);\r\n y += 10 * (s % 10);\r\n if (x < y && y >= 10 && y <= 19) {\r\n b.unshift(y - x);\r\n } else {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n a = parseInt(a / 10);\r\n s = parseInt(s / 10)\r\n }\r\n if (a) {\r\n console.log(-1);\r\n } else {\r\n console.log(BigInt(b.join(\"\")).toString());\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let inpArr = readLine().split(\" \");\r\n let a = parseInt(inpArr[0]);\r\n let s = parseInt(inpArr[1]);\r\n let b = [];\r\n while (s > 0) {\r\n let x = a % 10, y = s % 10;\r\n if (x <= y) {\r\n b.unshift(y - x);\r\n } else {\r\n s = parseInt(s / 10);\r\n y += 10 * (s % 10);\r\n if (x < y && y >= 10 && y <= 19) {\r\n b.unshift(y - x);\r\n } else {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n a = parseInt(a / 10);\r\n s = parseInt(s / 10)\r\n }\r\n if (a) {\r\n console.log(-1);\r\n } else {\r\n console.log(BigInt(b.join(\"\").toString()))\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let inpArr = readLine().split(\" \");\r\n let a = parseInt(inpArr[0]);\r\n let s = parseInt(inpArr[1]);\r\n let b = [];\r\n while (s > 0) {\r\n let x = a % 10, y = s % 10;\r\n if (x <= y) {\r\n b.unshift(y - x);\r\n } else {\r\n s = parseInt(s / 10);\r\n y += 10 * (s % 10);\r\n if (x < y && y >= 10 && y <= 19) {\r\n b.unshift(y - x);\r\n } else {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n a = parseInt(a / 10);\r\n s = parseInt(s / 10)\r\n }\r\n if (a) {\r\n console.log(-1);\r\n } else {\r\n console.log(parseInt(b.join(\"\")))\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n let inpArr = readLine().split(\" \");\r\n let a = inpArr[0];\r\n let s = inpArr[1];\r\n let b = new Array().fill(0);\r\n let and = a.length - 1;\r\n let snd = s.length - 1;\r\n let flag = false;\r\n while (snd >= 0) {\r\n\r\n let tempa = parseInt(a.substring(and, and + 1));\r\n let temps1 = parseInt(s.substring(snd, snd + 1));\r\n let temps2 = parseInt(s.substring(snd - 1, snd + 1));\r\n if (and < 0) {\r\n b.unshift(parseInt(s.substring(snd, snd + 1)));\r\n snd--;\r\n } else if (temps1 >= tempa) {\r\n b[and] = temps1 - tempa;\r\n and--;\r\n snd--;\r\n } else if (temps2 >= tempa) {\r\n if (temps2 - tempa >= 10) {\r\n flag = true;\r\n break;\r\n }\r\n b[and] = temps2 - tempa;\r\n and--;\r\n snd -= 2;\r\n } else {\r\n // b[and]=0;\r\n break;\r\n }\r\n }\r\n if (flag || snd < and) {\r\n console.log(\"-1\");\r\n } else {\r\n console.log(parseInt(b.join(\"\")) || -1)\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n let inpArr = readLine().split(\" \");\r\n let a = inpArr[0];\r\n let s = inpArr[1];\r\n let b = new Array().fill(0);\r\n let and = a.length - 1;\r\n let snd = s.length - 1;\r\n let flag = false;\r\n while (snd >= 0) {\r\n\r\n let tempa = parseInt(a.substring(and, and + 1));\r\n let temps1 = parseInt(s.substring(snd, snd + 1));\r\n let temps2 = parseInt(s.substring(snd - 1, snd + 1));\r\n if (and < 0) {\r\n b.unshift(parseInt(s.substring(snd, snd + 1)));\r\n snd--;\r\n } else if (temps1 >= tempa) {\r\n b[and] = temps1 - tempa;\r\n and--;\r\n snd--;\r\n } else if (temps2 >= tempa) {\r\n if (temps2 - tempa >= 10) {\r\n flag = true;\r\n break;\r\n }\r\n b[and] = temps2 - tempa;\r\n and--;\r\n snd -= 2;\r\n } else {\r\n // b[and]=0;\r\n break;\r\n }\r\n }\r\n if (flag || snd < and) {\r\n console.log(\"-1\");\r\n } else {\r\n console.log(parseInt(b.join(\"\")))\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(aIn, sIn) { \r\n let a = aIn.split('').map(Number);\r\n let s = sIn.split('').map(Number);\r\n let b = '';\r\n let hasSolution;\r\n\r\n a.unshift(0);\r\n\r\n for (let i = a.length - 1; i >= 0; --i) {\r\n hasSolution = false;\r\n \r\n for (let num = 0; num <= 9; ++num) {\r\n if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {\r\n b = num + b;\r\n s.pop();\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (a[i] + num === s[s.length - 1]) {\r\n b = num + b;\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (!s.length && i === 0 && a[0] === 0) {\r\n hasSolution = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!hasSolution) {\r\n console.log('-1');\r\n return;\r\n }\r\n }\r\n\r\n b = b.replace(/^0+/, '');\r\n\r\n if (!b) {\r\n console.log('0');\r\n } else {\r\n console.log(b);\r\n }\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(aIn, sIn) { \r\n let a = aIn.split('').map(Number);\r\n let s = sIn.split('').map(Number);\r\n let b = '';\r\n let hasSolution;\r\n\r\n a.unshift(0);\r\n\r\n for (let i = a.length - 1; i >= 0; --i) {\r\n hasSolution = false;\r\n \r\n for (let num = 0; num <= 9; ++num) {\r\n if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {\r\n b = num + b;\r\n s.pop();\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (a[i] + num === s[s.length - 1]) {\r\n b = num + b;\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (!s.length && i === 0 && a[0] === 0) {\r\n hasSolution = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!hasSolution) {\r\n console.log('-1');\r\n return;\r\n }\r\n }\r\n \r\n console.log(b.replace(/^0(.+$)/, '$1'));\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(aIn, sIn) { \r\n let a = aIn.split('').map(Number);\r\n let s = sIn.split('').map(Number);\r\n let b = '';\r\n let hasSolution;\r\n\r\n a.unshift(0);\r\n\r\n for (let i = a.length - 1; i >= 0; --i) {\r\n hasSolution = false;\r\n \r\n for (let num = 0; num <= 9; ++num) {\r\n if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {\r\n b = num + b;\r\n s.pop();\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (a[i] + num === s[s.length - 1]) {\r\n b = num + b;\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (!s.length && i === 0 && a[0] === 0) {\r\n hasSolution = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!hasSolution) {\r\n console.log('-1');\r\n return;\r\n }\r\n }\r\n \r\n console.log(b.replace(/^(0).+/, ''));\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(aIn, sIn) { \r\n let a = aIn.split('').map(Number);\r\n let s = sIn.split('').map(Number);\r\n let b = '';\r\n let hasSolution;\r\n\r\n a.unshift(0);\r\n\r\n for (let i = a.length - 1; i >= 0; --i) {\r\n hasSolution = false;\r\n \r\n for (let num = 0; num <= 9; ++num) {\r\n if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {\r\n b = num + b;\r\n s.pop();\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (a[i] + num === s[s.length - 1]) {\r\n b = num + b;\r\n s.pop();\r\n hasSolution = true;\r\n break;\r\n } else if (!s.length && i === 0 && a[0] === 0) {\r\n hasSolution = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!hasSolution) {\r\n console.log('-1');\r\n return;\r\n }\r\n }\r\n \r\n console.log(b.replace(/^0/, ''));\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let a, s;\r\n\r\n while (T--) {\r\n [a, s] = lines[index++].split(' ');\r\n solve(a, s);\r\n }\r\n}\r\n\r\nfunction solve(a, s) {\r\n let b = [];\r\n let twoDigits;\r\n let aDigitNumber;\r\n\r\n for (let i = s.length - 1; i >= 0; --i) {\r\n twoDigits = s[i - 1] + s[i];\r\n\r\n if (/1[0-9]/.test(twoDigits)) {\r\n b.push(Number(twoDigits));\r\n i--;\r\n } else {\r\n b.push(Number(s[i]));\r\n }\r\n }\r\n \r\n if (b.length !== a.length) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n b.reverse();\r\n\r\n for (let i = b.length - 1; i >= 0; --i) {\r\n aDigitNumber = Number(a[i]);\r\n \r\n if (b[i] - aDigitNumber > 10 || b[i] < aDigitNumber) {\r\n console.log('-1');\r\n return;\r\n }\r\n \r\n b[i] = b[i] - aDigitNumber;\r\n }\r\n\r\n console.log(b.join('').replace(/^0/, ''));\r\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let param = str.split(' ')\n a = Array.from(param[0])\n s = Array.from(param[1])\n\n let suitable = true\n\n if (a.length > s.length) {\n suitable = false\n }\n let res = []\n let atemp = []\n let stemp = []\n\n while (a.length > 0) {\n if (s.length === 0) {\n suitable = false\n }\n atemp = a.pop()\n stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp)) {\n res.unshift(\n parseInt(stemp) == parseInt(atemp)\n ? parseInt(stemp) - parseInt(atemp)\n : ''\n )\n } else {\n if (s.length === 0) {\n suitable = false\n }\n if (s.pop() != '1') {\n suitable = false\n }\n res.unshift(parseInt(stemp) + 10 - parseInt(atemp))\n }\n }\n while (s.length > 0) {\n res.unshift(parseInt(s.pop()))\n }\n console.log(suitable ? res.join('') : '-1')\n }\n\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let param = str.split(' ')\n a = Array.from(param[0])\n s = Array.from(param[1])\n\n let suitable = true\n\n if (a.length > s.length) {\n suitable = false\n }\n let res = []\n let atemp = []\n let stemp = []\n\n while (a.length > 0) {\n if (s.length === 0) {\n suitable = false\n }\n atemp = a.pop()\n stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp)) {\n res.unshift(parseInt(stemp) - parseInt(atemp))\n } else {\n if (s.length === 0) {\n suitable = false\n }\n if (s.pop() != '1') {\n suitable = false\n }\n res.unshift(parseInt(stemp) + 10 - parseInt(atemp))\n }\n }\n while (s.length > 0) {\n res.unshift(parseInt(s.pop()))\n }\n console.log(suitable ? res.join('') : '-1')\n }\n\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let inparams = str.split(' ')\n let a = Array.from(inparams[0])\n let s = Array.from(inparams[1])\n if (a.length > s.length) {\n console.log(-1)\n break\n }\n let res = Array.from('')\n let atemp = ''\n let stemp = ''\n let n = ''\n flag = true\n while (a.length > 0) {\n if (s.length === 0) {\n console.log(-1)\n flag = false\n break\n }\n atemp = a.pop()\n stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp)) {\n res.push(parseInt(stemp) - parseInt(atemp))\n } else {\n if (s.length === 0) {\n console.log(-1)\n flag = false\n break\n }\n n = s.pop()\n if (n != '1') {\n console.log(-1)\n flag = false\n break\n }\n stemp = n + stemp\n res.push(parseInt(stemp) - parseInt(atemp))\n }\n }\n if (flag) {\n while (s.length > 0) {\n res.push(parseInt(s.pop()))\n }\n while (res[res.length - 1] === 0) {\n res.pop()\n }\n let resstr = ''\n while (res.length > 0) {\n resstr += res.pop()\n }\n console.log(parseInt(resstr))\n }\n }\n\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/C\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let inparams = str.split(' ')\n let a = Array.from(inparams[0])\n let s = Array.from(inparams[1])\n if (a.length > s.length) {\n console.log(-1)\n break\n }\n let res = Array.from('')\n flag = true\n while (a.length > 0) {\n if (s.length === 0) {\n console.log(-1)\n flag = false\n break\n }\n let atemp = a.pop()\n let stemp = s.pop()\n if (parseInt(stemp) >= parseInt(atemp)) {\n res.push(parseInt(stemp) - parseInt(atemp))\n } else {\n if (s.length === 0) {\n console.log(-1)\n flag = false\n break\n }\n let n = s.pop()\n if (n != '1') {\n console.log(-1)\n flag = false\n break\n }\n stemp = n + stemp\n res.push(parseInt(stemp) - parseInt(atemp))\n }\n }\n if (flag) {\n while (s.length > 0) {\n res.push(parseInt(s.pop()))\n }\n while (res[res.length - 1] === 0) {\n res.pop()\n }\n let resstr = ''\n while (res.length > 0) {\n resstr += res.pop()\n }\n console.log(parseInt(resstr))\n }\n }\n\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let [a, s] = readline().split(' ');\n\n function getDigitB() {\n if (s.length === 0) {\n return null;\n }\n let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;\n let sd = parseInt(s[s.length - 1]);\n let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;\n if (ad <= sd) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 1);\n return sd - ad;\n } else if (sdd === 1 && sd < 9) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 2);\n return sdd * 10 + sd - ad;\n } else {\n return null;\n }\n }\n\n let b = '';\n let bd = getDigitB();\n while (bd !== null) {\n b = bd.toString() + b;\n bd = getDigitB();\n }\n if (!s && !a && parseInt(b) > 0) {\n console.log(parseInt(b));\n } else {\n console.log('-1');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let [a, s] = readline().split(' ');\n\n function getDigitB() {\n if (s.length === 0) {\n return null;\n }\n let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;\n let sd = parseInt(s[s.length - 1]);\n let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;\n if (ad <= sd) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 1);\n return sd - ad;\n } else if (sdd === 1) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 2);\n return sdd * 10 + sd - ad;\n } else {\n return null;\n }\n }\n\n let b = '';\n let bd = getDigitB();\n while (bd !== null) {\n b = bd.toString() + b;\n bd = getDigitB();\n }\n if (!s && !a && parseInt(b) > 0) {\n console.log(parseInt(b));\n } else {\n console.log('-1');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let [a, s] = readline().split(' ');\n\n function getDigitB() {\n if (s.length === 0) {\n return null;\n }\n let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;\n let sd = parseInt(s[s.length - 1]);\n let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;\n if (ad <= sd) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 1);\n return sd - ad;\n } else if (sdd === 1) {\n a = a.length > 0 ? a.slice(0, a.length - 1) : a;\n s = s.slice(0, s.length - 2);\n return sdd * 10 + sd - ad;\n } else {\n return null;\n }\n }\n\n let b = '';\n let bd = getDigitB();\n while (bd !== null) {\n b = bd.toString() + b;\n bd = getDigitB();\n }\n if (!s && !a) {\n console.log(parseInt(b));\n } else {\n console.log('-1');\n }\n }\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, s] = readline().trim().split(\" \");\r\n let b = [];\r\n let i = n.length - 1,\r\n j = s.length - 1,\r\n len = n.length,\r\n ans = true;\r\n while (i >= 0 && j >= 0) {\r\n let n1 = parseInt(n[i]),\r\n n2 = parseInt(s[j]);\r\n if (n1 < n2) {\r\n b.push(n2 - n1);\r\n j--;\r\n } else if (n1 > n2) {\r\n n2 = parseInt(s[j - 1]) * 10 + n2;\r\n if (n2 - n1 >= 10) {\r\n ans = false;\r\n break;\r\n } else {\r\n b.push(n2 - n1);\r\n j -= 2;\r\n len++;\r\n }\r\n } else {\r\n if (parseInt(s[j - 1]) === 1) {\r\n n2 = parseInt(s[j - 1]) * 10 + n2;\r\n b.push(n2 - n1);\r\n j -= 2;\r\n len++;\r\n } else {\r\n b.push(0);\r\n j--;\r\n }\r\n }\r\n if (len > s.length) {\r\n ans = false;\r\n break;\r\n }\r\n i--;\r\n }\r\n if (ans === false || j > 0) console.log(-1);\r\n else if (len !== s.length) console.log(-1);\r\n else {\r\n let res = \"\",\r\n is = true;\r\n for (let i = b.length - 1; i >= 0; i--) {\r\n if (b[i] === 0 && is) continue;\r\n else {\r\n res += b[i];\r\n is = false;\r\n }\r\n }\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "aa00fbde0b135addd2fdde0310e0377a"} {"source_code": "/*\n\tThe idea here is by using reference table to lookup\n\tindex of next different number\n*/\n\nvar nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });\nvar arr = readline().split(' ');\n\nvar arr_jmp = []; //reference table\n\n//fill reference table backward\narr_jmp[nm[0]] = arr.length; \nvar current_val = parseInt(arr[nm[0]]);\nfor(var i = nm[0] - 1; i >= 0; i--)\n{\n\tif(parseInt(arr[i]) == current_val) {\n\t\tarr_jmp[i] = arr_jmp[i + 1];\n\t} else {\n\t\tarr_jmp[i] = i + 1;\n\t\tcurrent_val = parseInt(arr[i]);\n\t}\n}\n\n// processing query\nvar result = \"\";\nfor(var i = 0; i <= nm[1]; i++)\n{\n\tvar params = readline().split(' ');\n\tresult += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));\n\tresult += \"\\n\";\n}\n\nprint(result); //print only once, it will save a lot of time\n\nfunction query(l, r, x)\n{\n\tif(parseInt(arr[l]) == x){\n\t\tif(arr_jmp[l] > r)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn arr_jmp[l] + 1; // +1 because in problem, index start from 1\n\t} else {\n\t\treturn l + 1; // +1 because in problem, index start from 1\n\t}\n}", "positive_code": [{"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\nlet pos = new Array(nm[0]);\n\nfor (let i = 0; i < nm[0]; i++) {\n if (as[i-1] !== as[i]) pos[i] = i\n else pos[i] = pos[i-1]\n}\n\nlet result = '';\n\nfor (let i = 0; i < nm[1]; i++) {\n let lrx = readline().split(' ').map(Number);\n let l = lrx[0], r = lrx[1], x = lrx[2];\n\n if (as[r-1] !== x) {\n result += r;\n } else if (pos[r-1] >= l) {\n result += pos[r-1];\n } else {\n result += '-1';\n }\n result += '\\n';\n}\n\nwrite(result);\n\n"}, {"source_code": "/*\n\tThe idea here is by using reference table to lookup\n\tindex of next different number\n*/\n\nvar nm = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar arr_jmp = []; // this is the reference table\n\nfor(var i = 0; i < nm[0]; i++) {\n\tif(arr[i-1] !== arr[i]) \n\t\tarr_jmp[i] = i;\n\telse \n\t\tarr_jmp[i] = arr_jmp[i-1]\n}\n\nvar result = \"\";\n\nfor(var i = 0; i < nm[1]; i++)\n{\n\tvar lrx = readline().split(' ').map(Number);\n\tvar l = lrx[0]; var r = lrx[1]; var x = lrx[2];\n\n\tif (arr[r-1] !== x) {\n\t result += r;\n\t} else if (arr_jmp[r-1] >= l) {\n\t result += arr_jmp[r-1];\n\t} else {\n\t result += '-1';\n\t}\n\t\n\tresult += '\\n';\n}\n\nprint(result);"}, {"source_code": "var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });\nvar arr = readline().split(' ');\n\nvar arr_jmp = [];\n\narr_jmp[nm[0]] = arr.length; \nvar current_val = parseInt(arr[nm[0]]);\nfor(var i = nm[0] - 1; i >= 0; i--)\n{\n\tif(parseInt(arr[i]) == current_val) {\n\t\tarr_jmp[i] = arr_jmp[i + 1];\n\t} else {\n\t\tarr_jmp[i] = i + 1;\n\t\tcurrent_val = parseInt(arr[i]);\n\t}\n}\n\nvar result = \"\";\n\nfor(var i = 0; i <= nm[1]; i++)\n{\n\tvar params = readline().split(' ');\n\tresult += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));\n\tresult += \"\\n\";\n}\n\nprint(result);\n\nfunction query(l, r, x)\n{\n\tif(parseInt(arr[l]) == x){\n\t\tif(arr_jmp[l] > r)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn arr_jmp[l] + 1;\n\t} else {\n\t\treturn l + 1;\n\t}\n}"}, {"source_code": "/*\n\tThe idea here is by using reference table to lookup\n\tindex of next different number\n*/\n\nvar nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });\nvar arr = readline().split(' ');\n\nvar arr_jmp = []; //reference table\n\n//fill reference table backward\narr_jmp[nm[0]] = arr.length; \nvar current_val = parseInt(arr[nm[0]]);\nfor(var i = nm[0] - 1; i >= 0; i--)\n{\n\tif(parseInt(arr[i]) == current_val) {\n\t\tarr_jmp[i] = arr_jmp[i + 1];\n\t} else {\n\t\tarr_jmp[i] = i + 1;\n\t\tcurrent_val = parseInt(arr[i]);\n\t}\n}\n\n// processing query\nvar result = \"\";\nfor(var i = 0; i <= nm[1]; i++)\n{\n\tvar params = readline().split(' ');\n\tresult += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));\n\tresult += \"\\n\";\n}\n\nprint(result); //print only once, it will save a lot of time\n\nfunction query(l, r, x)\n{\n\tif(parseInt(arr[l]) == x){\n\t\tif(arr_jmp[l] > r)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn arr_jmp[l] + 1;\n\t} else {\n\t\treturn l + 1;\n\t}\n}"}, {"source_code": "/*\n\tThe idea here is by using reference table to lookup\n\tindex of next different number\n*/\n\nvar nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });\nvar arr = readline().split(' ').map(Number);\n\nvar arr_jmp = []; //reference table\n\n//fill reference table backward\narr_jmp[nm[0]] = arr.length; \nvar current_val = arr[nm[0]];\nfor(var i = nm[0] - 1; i >= 0; i--)\n{\n\tif(arr[i] == current_val) {\n\t\tarr_jmp[i] = arr_jmp[i + 1];\n\t} else {\n\t\tarr_jmp[i] = i + 1;\n\t\tcurrent_val = arr[i];\n\t}\n}\n\n// processing query\nvar result = \"\";\nfor(var i = 0; i <= nm[1]; i++)\n{\n\tvar params = readline().split(' ');\n\tresult += query(params[0] - 1, params[1] - 1, params[2]);\n\tresult += \"\\n\";\n}\n\nprint(result); //print only once, it will save a lot of time\n\nfunction query(l, r, x)\n{\n\tif(parseInt(arr[l]) == x){\n\t\tif(arr_jmp[l] > r)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn arr_jmp[l] + 1;\n\t} else {\n\t\treturn l + 1;\n\t}\n}"}], "negative_code": [{"source_code": "/*\n\tThe idea here is by using reference table to lookup\n\tindex of next different number\n*/\n\nvar nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });\nvar arr = readline().split(' ').map(Number);\n\nvar arr_jmp = []; // this is the reference table\n\n// fill reference table\narr_jmp[nm[0]] = -1; \nvar current_val = arr[nm[0]];\nfor(var i = nm[0] - 1; i >= 0; i--)\n{\n\tif(arr[i] == current_val) {\n\t\tarr_jmp[i] = arr_jmp[i + 1];\n\t} else {\n\t\tarr_jmp[i] = i + 1;\n\t\tcurrent_val = arr[i];\n\t}\n}\n\n// process query\nfor(var i = 0; i <= nm[1]; i++)\n{\n\tvar params = readline().split(' ').map(Number);\n\tprint(query(params[0] - 1, params[1] - 1, params[2]));\n}\n\nfunction query(l, r, x)\n{\n\tif(arr[l] == x){\n\t\tif(arr_jmp[l] > r)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn arr_jmp[l] + 1;\n\t} else {\n\t\treturn l + 1;\n\t}\n}"}, {"source_code": "var tmp = readline().split(' ').map(Number);\nvar n_query = tmp[1];\n\nvar arr = readline().split(' ').map(Number);\nfor(var i = 0; i < n_query; i++)\n{\n\tvar params = readline().split(' ').map(Number);\n\tprint(query(params[0], params[1], params[2]));\n}\n\nfunction query(l, r, x)\n{\n\tfor(var i = l - 1; i < r; i++)\n\t{\n\t\tif(arr[i] !== x)\n\t\t\treturn i+1;\n\t}\n}"}, {"source_code": "var nm = readline().split(' ').map(Number);\n\nvar arr = readline().split(' ').map(Number);\nfor(var i = 0; i < nm[1]; i++)\n{\n\tvar params = readline().split(' ').map(Number);\n\tprint(query(params[0], params[1], params[2]));\n}\n\nfunction query(l, r, x)\n{\n\tvar arr_tmp = arr.slice(l - 1, r);\n\tvar idx = arr_tmp.indexOf(x);\n\n\tif(idx == -1)\n\t\treturn l;\n\telse\n\t{\n\t\tif(arr_tmp.length > 1)\n\t\t{\n\t\t\tif(idx == 0)\n\t\t\t\treturn l + 1;\n\t\t\telse\n\t\t\t\treturn l;\n\t\t}\n\t\telse\n\t\t\treturn l;\n\t}\n}"}, {"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\nlet pos = new Array(nm[0]);\n\nfor (let i = 0; i < nm[0]; i++) {\n if (as[i-1] !== as[i]) pos[i] = i\n else pos[i] = pos[i-1]\n}\n\nprint(pos.join());"}, {"source_code": "print(2);\nprint(5);\nprint(-1);\nprint(3);"}, {"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\n\nfor (var i = 0; i < nm[1]; i++) {\n let lrx = readline().split(' ').map(Number);\n let result = -1;\n for (var j = lrx[1]; j-- > lrx[0]; ) {\n if (as[j] !== lrx[2]) {\n result = j+1;\n break;\n }\n }\n print(result);\n}\n"}, {"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\n\nfor (var i = 0; i < nm[1]; i++) {\n let lrx = readline().split(' ').map(Number);\n let target = as.slice(lrx[0]-1, lrx[1]).join('').replace(new RegExp(lrx[2]+'+$'), '').split('');\n let result = -1;\n while (target.length > 0) {\n if (target.pop() !== lrx[2]) {\n result = target.length + lrx[0];\n break;\n }\n }\n print(result);\n}\n"}, {"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\nlet pos = [];\n\nfor (let j = 0; j < as.length; j++) {\n if (as[j-1] !== as[j]) pos[j] = j\n else pos[j] = pos[j-1]\n}\n\nfor (let i = 0; i < nm[1]; i++) {\n let lrx = readline().split(' ').map(Number);\n let l = lrx[0], r = lrx[1], x = lrx[2];\n\n if (as[r-1] !== x) {\n print(r)\n } else if (pos[r-1] > l) {\n print(pos[r-1])\n } else {\n print(-1)\n }\n \n}\n"}, {"source_code": "'use strict';\n\nconst nm = readline().split(' ').map(Number);\nconst as = readline().split(' ').map(Number);\nlet new_target = [];\n\nfor (let j = as.length; j--;) {\n if (as[j+1] !== as[j]) new_target[j] = j + 1;\n else new_target[j] = new_target[j + 1];\n}\n\nnew_target = [...new Set(as)];\n\nfor (let i = 0; i < nm[1]; i++) {\n let lrx = readline().split(' ').map(Number);\n let target = as.slice(lrx[0]-1, lrx[1]);\n let result = -1;\n\n //if (as[lrx[0]-1] !== lrx[2]) result = lrx[0]\n //else if (new_target[lrx[0]] <= lrx[2]) result = new_target[lrx[0]]\n\n // if (Math.max.apply(Math, target) === Math.min.apply(Math, target) && Math.min.apply(Math, target) === lrx[2]) {\n if (new_target.length === 1) {\n } else {\n for (let j = lrx[1]; j-- > lrx[0]-1; ) {\n if (as[j] !== lrx[2]) {\n result = j+1;\n break;\n }\n }\n }\n\n print(result);\n}\n"}], "src_uid": "dcf7988c35bb34973e7b60afa7a0e68c"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var n = a[0], l = a[1], r = a[2];\n var flag = true;\n for(j = 1; j <= n; j++){\n if(Math.floor(r / j) * j < l){\n flag = false;\n }\n }\n if(!flag){\n console.log('NO'); \n }else{\n console.log('YES');\n var ans = '';\n for(j = 1; j <= n; j++){\n ans += Math.floor(r / j) * j + ' ';\n }\n console.log(ans);\n }\n }\n});\n", "positive_code": [{"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split(' ').map(p => +p);\r\n myFunc(arr[0], arr[1], arr[2]);\r\n }\r\n}\r\n\r\n\r\nfunction myFunc(n, l, r){\r\n let resp = [], aux;\r\n for(let i = 1; i <= n; i++){\r\n if(l%i == 0) resp.push(l);\r\n else{\r\n aux = parseInt(l/i)*i + i;\r\n if(aux > r){\r\n console.log('NO');\r\n return;\r\n }\r\n resp.push(aux);\r\n }\r\n }\r\n\r\n console.log('YES');\r\n let imprime = resp.join(' ');\r\n console.log(imprime);\r\n\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/*\r\n * Complete the 'queensAttack' function below.\r\n *\r\n * The function is expected to return an INTEGER.\r\n * The function accepts following parameters:\r\n * 1. INTEGER n\r\n * 2. INTEGER k\r\n * 3. INTEGER r_q\r\n * 4. INTEGER c_q\r\n * 5. 2D_INTEGER_ARRAY obstacles\r\n */\r\nconst generateArray = (start, end, n) => {\r\n const resultArray = [];\r\n\r\n if (n > end) {\r\n console.log('NO');\r\n return 'invalid';\r\n }\r\n\r\n for (let i = 1; i <= n; i += 1) {\r\n // start <= element <= end\r\n // start <= i * y <= end\r\n // start/i <= y <= end\r\n\r\n const y = Math.ceil(start / i);\r\n if (y > end / i) {\r\n console.log('NO');\r\n return 'invalid';\r\n }\r\n\r\n resultArray.push(i * y);\r\n }\r\n console.log('YES');\r\n console.log(resultArray.join(' '));\r\n return resultArray;\r\n};\r\n\r\n\r\nfunction main() {\r\n\r\n const numberOFTestCases = readLine();\r\n \r\n for(let i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const t = readline();\r\n\r\n for (let i = 0; i < t; i++) {\r\n const [n, l, r] = readline().split(' ').map(num => +num);\r\n\r\n // console.log(`=----------------testcase ${i + 1}----------------=`);\r\n // console.log('q', q);\r\n // console.log('a', a);\r\n\r\n const output = f(n, l, r);\r\n\r\n console.log(output);\r\n }\r\n}\r\n\r\nfunction f(n, l, r) {\r\n // console.log('=>>>>', n, l, r)\r\n const ans = [];\r\n for(let i = 1; i <= n; i ++) {\r\n const factor = Math.floor(r / i);\r\n const aFactor = factor * i;\r\n if(aFactor >= l) ans.push(aFactor)\r\n else return 'NO';\r\n }\r\n return 'YES\\n'+ans.join(' ')\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, l, r) {\r\n const res = new Array(n);\r\n for (let i = 1; i <= n; i++) {\r\n const x = Math.ceil(l / i);\r\n if (x * i > r) return 'NO';\r\n res[i - 1] = x * i;\r\n }\r\n return `YES\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, k);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n // var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var [n,l,r] = readline().split(' ').map((x) => parseInt(x));\r\n var ans = [];\r\n // ans.push(l);\r\n for(var i=1;i<=n;i++) {\r\n if(l%i == 0) {\r\n ans.push(l)\r\n continue;\r\n }\r\n var val = (l-(l%i))+i;\r\n if(val >= l && val <= r) ans.push(val);\r\n }\r\n // console.log(ans)\r\n if(ans.length < n) console.log(\"NO\")\r\n else {\r\n console.log(\"Yes\")\r\n console.log(ans.join(\" \"));\r\n }\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var nlr = readline().split(' ').map(x=>parseInt(x));\r\n var ans = [];\r\n var reply = 'YES';\r\n for (var i = 1; i <= nlr[0];i++) {\r\n var min = (Math.floor((nlr[1]-1)/i) + 1) * i;\r\n if (min <= nlr[2]) {\r\n ans.push(min);\r\n } else {\r\n reply = 'NO';\r\n break;\r\n }\r\n }\r\n print(reply);\r\n if (reply == 'YES') {\r\n print(ans.join(' '));\r\n }\r\n }"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\t// gcds must be 1, 2, 3...\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar arr = readIntArr();\r\n\t\tvar n, l, r, ans, ans2;\r\n\t\tn = arr[0]; l = arr[1]; r = arr[2];\r\n\t\tans = 'YES';\r\n\t\tans2 = [];\r\n\t\tfor (var i = 1; i < n + 1; i++) {\r\n\t\t\tvar val = parseInt(r / i) * i;\r\n\t\t\tif (val < l) {\r\n\t\t\t\tans = 'NO';\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tans2.push(val);\r\n\t\t}\r\n\t\tallans.push([ans]);\r\n\t\tif (ans === 'YES')\r\n\t\t\tallans.push(ans2);\r\n\t}\r\n\tmultiLineArrayOfArraysPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [{"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split(' ').map(p => +p);\r\n myFunc(arr[0], arr[1], arr[2]);\r\n }\r\n}\r\n\r\n\r\nfunction myFunc(n, l, r){\r\n let resp = [];\r\n for(let i = 1; i <= n; i++){\r\n if(l%i == 0) resp.push(l);\r\n else{\r\n l = parseInt(l/i)*i + i;\r\n if(l > r){\r\n console.log('NO');\r\n return;\r\n }\r\n resp.push(l);\r\n }\r\n }\r\n if(resp.length >= n){\r\n console.log('YES');\r\n console.log(...resp);\r\n }\r\n else{\r\n console.log('NO');\r\n }\r\n\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split(' ').map(p => +p);\r\n myFunc(arr[0], arr[1], arr[2]);\r\n }\r\n}\r\n\r\n\r\nfunction myFunc(n, l, r){\r\n let resp = [];\r\n for(let i = 1; i <= n; i++){\r\n if(l%i == 0) resp.push(l);\r\n else{\r\n l = parseInt(l/i)*i + i;\r\n if(l > r){\r\n console.log('NO');\r\n return;\r\n }\r\n resp.push(l);\r\n }\r\n }\r\n console.log('YES');\r\n console.log(...resp);\r\n}\r\n\r\n"}, {"source_code": "\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '', currentLine = 0;\r\n process.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2]);\r\n }\r\n }\r\n\r\n function gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n }\r\n \r\n \r\n function myFunc(n, l, r){\r\n let map = new Map();\r\n let resp = [];\r\n let cont = 1;\r\n let aux;\r\n\r\n for(let j = l; j <= r; j++){\r\n aux = gcd(cont, j);\r\n if(!map.has(aux)){\r\n map.set(aux, j);\r\n resp.push(j);\r\n cont++\r\n }\r\n if(resp.length >= n) break;\r\n }\r\n\r\n // console.log(map);\r\n if(resp.length >= n){\r\n console.log('YES');\r\n console.log(...resp);\r\n }\r\n else{\r\n console.log('NO');\r\n }\r\n\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '', currentLine = 0;\r\n process.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2]);\r\n }\r\n }\r\n\r\n function gcd(a, b){\r\n if (a == 0) return b;\r\n return gcd(b % a, a);\r\n }\r\n \r\n \r\n function myFunc(n, l, r){\r\n let map = new Map();\r\n let used = new Map();\r\n let resp = [];\r\n let cont = 0;\r\n let aux;\r\n for(let i = 0; i < n; i++){\r\n if(cont >= n) break;\r\n for(let j = l; j <= r; j++){\r\n aux = gcd(i+1, j);\r\n if(!map.has(aux) && !used.has(j)){\r\n map.set(aux, i+1);\r\n used.set(j, 1);\r\n resp.push(j);\r\n cont++;\r\n break;\r\n }\r\n }\r\n }\r\n if(cont >= n){\r\n console.log('YES');\r\n console.log(...resp);\r\n }\r\n else{\r\n console.log('NO');\r\n }\r\n\r\n }"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/*\r\n * Complete the 'queensAttack' function below.\r\n *\r\n * The function is expected to return an INTEGER.\r\n * The function accepts following parameters:\r\n * 1. INTEGER n\r\n * 2. INTEGER k\r\n * 3. INTEGER r_q\r\n * 4. INTEGER c_q\r\n * 5. 2D_INTEGER_ARRAY obstacles\r\n */\r\nconst generateArray = (start, end, n) => {\r\n const resultArray = [];\r\n\r\n if (n > end) {\r\n console.log('NO');\r\n return 'invalid';\r\n }\r\n\r\n for (let i = 1; i <= n; i += 1) {\r\n // start <= element <= end\r\n // start <= i * y <= end\r\n // start/i <= y <= end\r\n\r\n const y = Math.ceil(start / i);\r\n if (y > end / i) {\r\n console.log('NO');\r\n return 'invalid';\r\n }\r\n\r\n resultArray.push(i * y);\r\n }\r\n console.log('YES');\r\n console.log(resultArray);\r\n return resultArray;\r\n};\r\n\r\n\r\nfunction main() {\r\n\r\n const numberOFTestCases = readLine();\r\n \r\n for(let i=0; i b) {\r\n a = a % b;\r\n } else {\r\n b = b % a;\r\n }\r\n }\r\n return Math.max(a, b);\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var nlr = readline().split(' ').map(x=>parseInt(x));\r\n var set = new Set();\r\n var ans = [];\r\n for (var i = 0; i < nlr[0];i++) {\r\n ans.push(0);\r\n }\r\n for (var i = nlr[1]; i <= nlr[2]; i++) {\r\n for (var j = 1; j<=nlr[0]; j++) {\r\n if (ans[j-1] == 0 ) {\r\n var d = gcd(j, i);\r\n if (!set.has(d)) {\r\n ans[j-1] = i;\r\n set.add(d);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n var reply = 'YES';\r\n for (var i = 0; i < nlr[0];i++) {\r\n if (ans[i] == 0) {\r\n reply = 'NO';\r\n }\r\n }\r\n print(reply);\r\n if (reply == 'YES') {\r\n print(ans.join(' '));\r\n }\r\n }"}], "src_uid": "d2cc6efe7173a64482659ba59efeec16"} {"source_code": "// main.apply(0, readline().split(' ').map(function(v) {\n // return v - 0;\n// }));\n// function main(d, L, v1, v2) {\n // print((L - d) / (v1 + v2));\n// }\n\n// var print = console.log.bind(console);\n\n// var lines = \n// `3\n// 1 1\n// 2 3\n// 3 5`.split(\"\\n\");\n// function readline() {\n // var l = lines.n || 0;\n // lines.n = l + 1;\n // return lines[l];\n// }\n\nvar n = readline() - 0;\nvar a={}, b={};\nfor (var i = -1005; i <= 2005; i++) {\n a[i] = b[i] = 0;\n}\nfor (var i = 0; i < n; i++) {\n var m = readNums();\n a[m[1] - m[0] + 1]++;\n b[m[1] + m[0] - 1]++;\n}\nvar sum = 0;\nfor (var i = -1005; i <= 2005; i++) {\n sum += calc(a[i]) + calc(b[i]);\n}\nprint(sum);\n\nfunction calc(n) {\n if (n > 1)\n return n * (n - 1) / 2;\n return 0;\n}\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}", "positive_code": [{"source_code": "var n = Number(readline()); //number of bishops\n\nvar bishop_position = []; \n\nfor (var i = 0; i < n; i++) {\n\tvar bishop = readline().split(' ').map(Number);\n\tbishop_position[i] = {row: bishop[0], col: bishop[1]};\n}\n\nvar bishop1 = [];\n\nfor (var i = 0; i < n; i++) {\n\tbishop1[i] = bishop_position[i].row - bishop_position[i].col;\n}\n\nvar counts = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (bishop1[i] in counts) {\n\t\tcounts[bishop1[i]] += 1;\n\t} else {\n\t\tcounts[bishop1[i]] = 1;\n\t}\n}\n\nvar nc2 = function(m) {\n\treturn m * (m - 1) / 2;\n}\n\nvar attack = 0;\n\nfor (var key in counts) {\n\tattack += nc2(counts[key]);\n}\n\n// checking for other diagonal\nvar bishop2 = [];\n\nfor (var i = 0; i < n; i++) {\n\tbishop2[i] = bishop_position[i].row + bishop_position[i].col;\n}\n\nvar counts2 = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (bishop2[i] in counts2) {\n\t\tcounts2[bishop2[i]] += 1;\n\t} else {\n\t\tcounts2[bishop2[i]] = 1;\n\t}\n}\n\nfor (var key in counts2) {\n\tattack += nc2(counts2[key]);\n}\n\nprint(attack);\n"}, {"source_code": "var maxSize = 1000;\nvar n = Number(readline());\nvar arr1 = new Array(2 * maxSize - 1);\nvar arr2 = new Array(2 * maxSize - 1);\nfor (var i = 0; i < arr1.length; ++i) {\n arr1[i] = arr2[i] = 0;\n}\n\nfor (var i = 0; i < n; ++i) {\n var num = readline().split(\" \", 2);\n var a = Number(num[0]);\n var b = Number(num[1]);\n ++arr1[b - a + maxSize - 1];\n ++arr2[a + b - 2];\n}\n\nfunction getCn2(n) {\n return n * (n - 1) / 2;\n}\n\nvar sum = 0;\nfor (var i = 1; i < 2 * maxSize - 2; ++i) {\n sum += getCn2(arr1[i]);\n sum += getCn2(arr2[i]);\n}\n\nprint(sum);"}, {"source_code": "var result = 0;\n\nvar n = parseInt(readline());\nvar bishops = [];\nvar l = new Object();\nvar r = new Object();\nvar bishop;\nfor (var i = 0; i < n; i++) {\n bishop = readline().split(' ').map(Number);\n if (l[(bishop[0] + bishop[1])]) {\n l[(bishop[0] + bishop[1])]++;\n } else {\n l[(bishop[0] + bishop[1])] = 1;\n }\n if (r[(bishop[0] - bishop[1])]) {\n r[(bishop[0] - bishop[1])]++;\n } else {\n r[(bishop[0] - bishop[1])] = 1;\n }\n}\n\nfor(var index in l) {\n result += l[index] * (l[index] - 1) / 2;\n}\nfor(var index in r) {\n result += r[index] * (r[index] - 1) / 2;\n}\n\n\nprint(result);"}], "negative_code": [{"source_code": "// main.apply(0, readline().split(' ').map(function(v) {\n // return v - 0;\n// }));\n// function main(d, L, v1, v2) {\n // print((L - d) / (v1 + v2));\n// }\n\n// var print = console.log.bind(console);\n\n// var lines = \n// `3\n// 1 1\n// 2 3\n// 3 5`.split(\"\\n\");\n// function readline() {\n // var l = lines.n || 0;\n // lines.n = l + 1;\n // return lines[l];\n// }\n\nvar n = readline() - 0;\nvar a={}, b={};\nfor (var i = -1000; i <= 1000; i++) {\n a[i] = b[i] = 0;\n}\nfor (var i = 0; i < n; i++) {\n var m = readNums();\n a[m[1] - m[0] + 1]++;\n b[m[1] + m[0] - 1]++;\n}\nvar sum = 0;\nfor (var i = -1000; i <= 1000; i++) {\n sum += calc(a[i]) + calc(b[i]);\n}\nprint(sum);\n\nfunction calc(n) {\n if (n > 1)\n return n * (n - 1) / 2;\n return 0;\n}\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}, {"source_code": "var n = Number(readline());\nvar num1 = 0, num2 = 0;\n\nfor (var i = 0; i < n; ++i) {\n var num = readline().split(\" \", 2);\n var a = Number(num[0]);\n var b = Number(num[1]);\n if (a === b) {\n ++num1;\n } \n if (a + b === n + 1) {\n ++num2;\n }\n}\n\nprint(num1 * (num1 - 1) /2 + num2 * (num2 - 1) / 2);"}, {"source_code": "var maxSize = 1000;\nvar n = Number(readline());\nvar arr1 = new Array(2 * maxSize - 1);\nvar arr2 = new Array(2 * maxSize - 1);\nfor (var i = 0; i < n; ++i) {\n arr1[i] = arr2[i] = 0;\n}\n\nfor (var i = 0; i < n; ++i) {\n var num = readline().split(\" \", 2);\n var a = Number(num[0]);\n var b = Number(num[1]);\n ++arr1[b - a + maxSize - 1];\n ++arr2[a + b - 2];\n}\n\nfunction getCn2(n) {\n return n * (n - 1) / 2;\n}\n\nvar sum = 0;\nfor (var i = 1; i < 2 * maxSize - 2; ++i) {\n sum += getCn2(arr1[i]);\n sum += getCn2(arr2[i]);\n}\n\nprint(sum);"}, {"source_code": "var n = Number(readline());\nvar num1 = 0, num2 = 0;\n\nfor (var i = 0; i < n; ++i) {\n var num = readline().split(\" \", 2);\n var a = Number(num[0]);\n var b = Number(num[1]);\n if (a === b) {\n ++num1;\n } \n if (a + b === 1001) {\n ++num2;\n }\n}\n\nprint(num1 * (num1 - 1) /2 + num2 * (num2 - 1) / 2);"}], "src_uid": "eb7457fe1e1b571e5ee8dd9689c7d66a"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const a = readInts()\n const b = readInts()\n\n if(a[0] !== b[0]) {\n wr('NO')\n }\n else {\n let flags = [false, false, false]\n let f = true\n if(a[0] < 0) flags[2] = true\n else flags[a[0]] = true\n for(let i = 1; i < n && f; i++) {\n let d = b[i] - a[i]\n if(d > 0) {\n if(!flags[1]) {\n f = false\n }\n }\n else if(d < 0) {\n if(!flags[2]) {\n f = false\n }\n }\n if(a[i] < 0) flags[2] = true\n else flags[a[i]] = true\n }\n if(f) wr('YES')\n else wr('NO')\n }\n }\n}", "positive_code": [{"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n if(alist[0] != blist[0]){\n output[i] = \"NO\";\n continue;\n }\n //\u53f3\u304b\u3089\u78ba\u5b9a\u3057\u305f\u3044\n //j\u3088\u308a\u5de6\u306b\u6b32\u3057\u3044\u3082\u306e\u304c\u3042\u308b\u304b\n //b[j]>a[j]\u306a\u30891\u3001b[j]>a[j]\u306a\u3089-1\u304c\u3042\u3063\u3066\u307b\u3057\u3044\n var plus = [];\n var minus = [];\n for(var j = 0; j < n - 1; j++){\n if(alist[j] == 1 && plus.length == 0){\n plus.push(j);\n }\n if(alist[j] == -1 && minus.length == 0){\n minus.push(j);\n }\n }\n //myerr(plus);\n //myerr(minus);\n var isOK = true;\n for(var j = n - 1; j > 0; j--){\n if(blist[j] > alist[j]){\n if(plus.length == 0 || plus[0] >= j){\n isOK = false;\n }\n }else if(blist[j] < alist[j]){\n if(minus.length == 0 || minus[0] >= j){\n isOK = false;\n }\n }\n }\n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "const ascending = (x, y) => x - y;\nconst descending = (x, y) => y - x;\nconst log = console.log;\n\n\nfunction solve(input) {\n input = input.toString().split(/\\r?\\n/);\n\n let T = +input[0];\n let res = [];\n\n for (let t = 1, inputRow = 1; t <= T; t++) {\n\n let n = +input[inputRow++];\n let fpos = {\n '0': -1,\n '-1': -1,\n '1': -1\n };\n\n let a = input[inputRow++].split(' ').map(x => +x);\n let b = input[inputRow++].split(' ').map(x => +x);\n\n for (let i = 0; i < n; i++) {\n if (a[i] == -1 && fpos['-1'] == -1) {\n fpos['-1'] = i;\n }\n if (a[i] == 0 && fpos['0'] == -1) {\n fpos['0'] = i;\n }\n if (a[i] == 1 && fpos['1'] == -1) {\n fpos['1'] = i;\n }\n }\n\n let ans = 'YES';\n\n for (let i = n - 1; i >= 0; i--) {\n\n if (a[i] == b[i]) {\n continue;\n }\n if (b[i] > a[i] && (fpos['1'] == -1 || fpos['1'] >= i)) {\n ans = 'NO';\n break;\n }\n if (b[i] < a[i] && (fpos['-1'] == -1 || fpos['-1'] >= i)) {\n ans = 'NO';\n break;\n }\n\n }\n\n res.push(ans);\n }\n\n return res.join('\\n');\n}\n\nasync function main() {\n\n try {\n\n let input = await new Promise(resolve => {\n\n let _input = '';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (buf) => {\n _input += buf;\n });\n process.stdin.on('end', () => {\n resolve(_input);\n });\n\n });\n let output = solve(input);\n\n console.log(output);\n\n } catch (err) {\n console.error(err);\n }\n}\n\nmain();\n"}, {"source_code": "// Q: https://codeforces.com/contest/1333/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n const test = parseInt(input[0]);\n let n, a, b;\n\tfor (let t=0; t < test; t++) {\n n = parseInt(input[3*t+1]);\n a = input[3*t+2].split(' ').map((a) => parseInt(a));\n b = input[3*t+3].split(' ').map((b) => parseInt(b));\n console.log(solution (a, b, n));\n\t}\n});\n\nfunction solution(a, b, n) {\n if (b[0] !== a[0]) {\n return 'NO';\n } else {\n let posIdx = a[0] === 1 ? true : false;\n let negIdx = a[0] === -1 ? true : false;\n for (let i = 1; i < n; i++) {\n if (b[i] > a[i] && !posIdx) {\n return 'NO';\n } else if (b[i] < a[i] && !negIdx) {\n return 'NO';\n }\n if (!posIdx) {\n posIdx = a[i] === 1 ? true : false;\n }\n if (!negIdx) {\n negIdx = a[i] === -1 ? true : false;\n }\n }\n return 'YES';\n }\n}"}, {"source_code": "function main(a, b) {\n var response = 'YES';\n if (a[0] !== b[0]) {\n response = 'NO'\n } else {\n var addPos = -1;\n var rmvPos = -1;\n for (var i = 0; i < a.length; i++) {\n if(a[i] === 1 && addPos === -1 ) {\n addPos = i;\n }\n if(a[i] === -1 && rmvPos === -1 ) {\n rmvPos = i;\n }\n\n if (addPos !== -1 && rmvPos !== -1) {\n break;\n }\n }\n\n for (var i = 1; i < b.length; i++) {\n if (b[i] !== a[i]) {\n if(b[i] > a[i]) {\n if(addPos === -1) {\n response = 'NO';\n break;\n }\n if(addPos >= i) {\n response = 'NO';\n break;\n }\n }\n if(b[i] < a[i]) {\n if(rmvPos === -1) {\n response = 'NO';\n break;\n }\n if(rmvPos >= i) {\n response = 'NO';\n break;\n }\n }\n }\n }\n }\n\n return response;\n}\n\nvar n = readline();\nvar input = [];\nvar outputB = '';\n\nvar a\nwhile (1===1) {\n t = readline();\n if(!t) {\n break;\n }\n a = readline().split(' ');\n b = readline().split(' ');\n\n for(var z = 0; z < t; z++) {\n a[z] = +a[z];\n b[z] = +b[z];\n }\n \n outputB += main(a, b) + '\\n';\n}\n\nprint(outputB);"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, a, b) {\n const addPos = a.includes(1) ? a.indexOf(1) : n;\n const minusPos = a.includes(-1) ? a.indexOf(-1) : n;\n \n return b.every((val, i) => val === a[i] || (val > a[i] && addPos < i) || (val < a[i] && minusPos < i)) ? 'YES' : 'NO';\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n =readLine()[0];\n const a = readLine();\n const b = readLine();\n console.log(solve(n, a, b));\n }\n}\n"}, {"source_code": "var tests = parseInt(readline())\nfor (var l = 0; l < tests;l++)\n{\t\n\tvar size = parseInt(readline())\n\tvar a = readline().split(' ').map(c => parseInt(c)) \n\tvar b = readline().split(' ').map(c => parseInt(c)) \n\tvar flag = true\n\tvar one = a.indexOf(1), minus_one = a.indexOf(-1)\n\tfor(var i = size-1; i>-1;i--){\n\t\tif (a[i] != b[i]){\n\t\t\tvar check = b[i]-a[i]\n\t\t\tif (check < 0){\n\t\t\t\tif (minus_one == -1 || minus_one >= i){\n\t\t\t\t\tprint('No')\n\t\t\t\t\tflag = false\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif (one == -1 || one >= i){\n\t\t\t\t\tprint('No')\n\t\t\t\t\tflag = false\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (flag){\n\t\tprint('Yes')\n\t}\n}"}], "negative_code": [{"source_code": "for (var l = 0; l < parseInt(readline());l++)\n{\t\n\tvar size = parseInt(readline())\n\tvar a = readline().split(' ').map(c => parseInt(c)) \n\tvar b = readline().split(' ').map(c => parseInt(c)) \n\tvar flag = true\n\tvar one = a.indexOf(1), minus_one = a.indexOf(-1)\n\tfor(var i = size-1; i>-1;i--){\n\t\tif (a[i] != b[i]){\n\t\t\tvar check = b[i]-a[i]\n\t\t\tif (check < 0){\n\t\t\t\tif (minus_one == -1 || minus_one >= i){\n\t\t\t\t\tprint('No')\n\t\t\t\t\tflag = false\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif (one == -1 || one >= i){\n\t\t\t\t\tprint('No')\n\t\t\t\t\tflag = false\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (flag){\n\t\tprint('Yes')\n\t}\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n if(alist[0] != blist[0]){\n output[i] = \"NO\";\n continue;\n }\n //\u53f3\u304b\u3089\u78ba\u5b9a\u3057\u305f\u3044\n //j\u3088\u308a\u5de6\u306b\u6b32\u3057\u3044\u3082\u306e\u304c\u3042\u308b\u304b\n //b[j]>a[j]\u306a\u30891\u3001b[j]>a[j]\u306a\u3089-1\u304c\u3042\u3063\u3066\u307b\u3057\u3044\n var plus = [];\n var minus = [];\n for(var j = 0; j < n - 1; j++){\n if(alist[j] == 1 && plus.length == 0){\n plus.push(j);\n }\n if(alist[j] == -1 && minus.length == 0){\n minus.push(j);\n }\n }\n \n var isOK = true;\n for(var j = n - 1; j > 0; j--){\n if(blist[j] > alist[j]){\n for(var k = 0; k < plus.length; k++){\n if(plus[k] >= j){\n isOK = false;\n break;\n }\n }\n }else if(blist[j] < alist[j]){\n for(var k = 0; k < minus.length; k++){\n if(minus[k] >= j){\n isOK = false;\n break;\n }\n }\n }\n }\n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "var n = readline();\nvar input = [];\nvar outputB = '';\n\nwhile (1===1) {\n outputB += readline();\n outputB += readline();\n outputB += readline();\n if(!readline()) {\n break;\n }\n}\n\nprint(outputB);"}], "src_uid": "e425aa498e5a7fc3e518cec25eec6304"} {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst n = Number(inputs[0])\r\ninputs.shift()\r\nmain(n, inputs)\r\nfunction main(n, inputs) {\r\n for (let i = 0; i < n; i++) {\r\n const m = Number(inputs[i * 2]),\r\n data = inputs[i * 2 + 1].split(' ').map(Number)\r\n let min = 0,\r\n max = 0\r\n for (let j = 0; j < m; j++) {\r\n const num = data[j]\r\n if (num < data[min]) min = j\r\n if (num > data[max]) max = j\r\n }\r\n console.log(min + 1, max + 1)\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst EPS = 1e-6;\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = readline().split(' ').map(a=>+a);\n let minI = -1, maxI = -1;\n for (let i=0; iarr[i])\n maxI = i;\n }\n print(minI+1, maxI+1)\n }\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var max = b[n - 1];\n var min = b[0];\n var binx = 0;\n var minx = 0;\n for(j = 0; j < n; j++){\n if(a[j] == max){\n binx = j + 1;\n }\n if(a[j] == min){\n minx = j + 1;\n }\n }\n console.log(binx, minx);\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n \r\n let max = -Infinity;\r\n let min = Infinity;\r\n let maxIndex = -1;\r\n let minIndex = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] > max) {\r\n max = arr[i];\r\n maxIndex = i;\r\n }\r\n if (arr[i] < min) {\r\n min = arr[i];\r\n minIndex = i;\r\n }\r\n }\r\n\r\n output(`${maxIndex + 1} ${minIndex + 1}`);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst EPS = 1e-6;\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = readline().split(' ').map(a=>+a);\n print('1 1')\n }\n}"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var a = 0;\n var b = 0;\n for(i = 0; i < 6; i++){\n if(i >= 3){\n a += k[i];\n }else{\n b += k[i];\n }\n }\n if(a == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n output('1 1');\r\n }\r\n}\r\n"}], "src_uid": "7af4eee2e9f60283c4d99200769c77ec"} {"source_code": "function main () {\n var n = parseInt(readline());\n while (n-- > 0) {\n print(solve(readline()));\n }\n\n}\n\nfunction solve (s) {\n var sum = 0;\n var countEven = false;\n var countZero = 0;\n\n for (var i = 0; i < s.length; i++) {\n var num = parseInt(s[i]);\n\n if (num === 0) countZero++;\n else if (!(num & 1)) countEven++;\n\n sum += num;\n }\n\n if (sum % 3 == 0 && (countZero > 1 || (countZero == 1 && countEven)))\n return \"red\";\n\n return \"cyan\";\n}\n\nmain();", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet index = 0;\n\nfunction permut(string) {\n if (string.length < 2) return string; \n\n var permutations = []; \n for (var i = 0; i < string.length; i++) {\n var char = string[i];\n\n if (string.indexOf(char) != i) \n continue; \n\n var remainingString = string.slice(0, i) + string.slice(i + 1, string.length);\n\n for (var subPermutation of permut(remainingString))\n permutations.push(char + subPermutation)\n }\n return permutations;\n}\n\nreadline.on('line', line => {\n if (index++) {\n let sol = \"cyan\";\n let sum = 0, even = false, zero = false;\n for(let i = 0; i < line.length; i++) {\n let c = Number(line[i]);\n if (!zero && c === 0) { zero = true; continue; }\n if (!even && c % 2 === 0) even = true;\n sum += c\n }\n if (zero && even && sum % 3 === 0) sol = \"red\";\n return console.log(sol);\n }\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const splitArr = e\n .toString()\n .split(\"\")\n .map(Number);\n const nr0 = splitArr.filter(e => e === 0).length;\n if (\n splitArr.reduce((a, b) => a + b) % 3 === 0 &&\n nr0 >= 1 &&\n (splitArr.some(e => [2, 4, 6, 8].includes(e)) || nr0 >= 2)\n ) {\n console.log(\"red\");\n } else {\n console.log(\"cyan\");\n }\n });\n};\n"}, {"source_code": "var t = parseInt(readline(), 10),\n digit_sum = 0,\n n = [0, 0, 0, 0, 0];\n\nfor(var i=1; i<=t; i++) {\n n = [0, 0, 0, 0, 0];\n digit_sum = 0;\n \n readline().split('').map(el => {\n el = parseInt(el, 10);\n \n if(el === 0) n[0]++;\n else if(el === 2) n[1]++;\n else if(el === 4) n[2]++;\n else if(el === 6) n[3]++;\n else if(el === 8) n[4]++;\n \n digit_sum += el;\n \n return el;\n });\n \n if(digit_sum%3 === 0) {\n if(n[1] > 0 || n[2] > 0 || n[3] > 0 || n[4] > 0) {\n if(n[0] > 0) print('red');\n else print('cyan');\n } else {\n if(n[0] >= 2) print('red');\n else print('cyan');\n }\n } else print('cyan');\n}"}, {"source_code": "function write(x) {\n console.log(x)\n}\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr.shift())\n\n for(let j = 0; j < n; j++) {\n const num = arr[j]\n let d10 = false, d4 = false, even = false\n\n let len = num.length\n let sum = 0\n\n for(let i = 0; i < len; i++) {\n let x = parseInt(num[i])\n sum += x\n // console.log(sum, x, x % 2)\n if(x % 2 == 0 && d10) d4 = true\n if(x % 2 == 0 && x != 0) even = true\n if(num[i] == '0') {\n d10 = true\n if(even) d4 = true\n }\n }\n\n // console.log(d10, d4)\n if(sum % 3 == 0 && d10 && d4) {\n write('red')\n }\n else {\n write('cyan')\n }\n }\n})"}], "negative_code": [], "src_uid": "5bc07d2efb7453e51f4931cc7ec3aac7"} {"source_code": "for(t=readline();t--;)print((+readline()+1)/10|0)", "positive_code": [{"source_code": "for (var t = Number (readline ()); t > 0; t--)\r\n {\r\n print (Math.floor ((Number (readline ()) + 1) / 10));\r\n }"}, {"source_code": "var t=Number(readline());\r\nfor (var i=0; i= 9) {\r\n res = Math.floor(num / 10);\r\n if (num % 10 === 9) {\r\n res++;\r\n }\r\n } else {\r\n res = 0;\r\n }\r\n \r\n print(res);\r\n}"}, {"source_code": "var input = readline();\r\nfor(var i = 0; i < input; i ++) {\r\n var num = +readline();\r\n var result = Math.floor((num + 1) / 10);\r\n print(result);\r\n}"}, {"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\nlet standardInputString=''\r\nlet currentLine=0\r\nfunction readline(){\r\n return standardInputString[currentLine++]\r\n}\r\nprocess.stdin.on('data',rawData=>{\r\n standardInputString+=rawData\r\n})\r\nprocess.stdin.on('end',_=>{\r\n standardInputString= standardInputString.trim().split('\\n').map(line=>{\r\n return line.trim()\r\n})\r\n main()\r\n})\r\ninput=()=>parseInt(readline().trim())\r\nprint=(val)=>console.log(val)\r\nsort=(arr)=> arr.sort((a,b)=>a-b)\r\nRsort=(arr)=> arr.sort((a,b)=>b-a)\r\nStringListInput=()=> readline().trim().split(' ')\r\nlistInput=()=> readline().trim().split(' ').map(x=>parseInt(x))\r\nMax=(arr)=> Math.max.apply(null,arr)\r\nMin=(arr)=> Math.min.apply(null,arr)\r\nfunction main(){\r\n let t = Number(readline());\r\n for (let i = 0; i < t;i++) {\r\n n = Number(readline());\r\n console.log(parseInt((n+1)/10));\r\n }\r\n}"}, {"source_code": "const fs = require('fs');\r\n\r\nconst stdin = String(fs.readFileSync(0));\r\n\r\nconst f = (n) => Math.floor((n + 1) / 10);\r\n\r\nconst out = stdin\r\n .split('\\n')\r\n .slice(1)\r\n .map((nStr) => {\r\n const n = parseInt(nStr);\r\n\r\n return f(n);\r\n });\r\n\r\nout.forEach((x) => {\r\n if (typeof x === 'number' && !Number.isNaN(x)) {\r\n console.log(x);\r\n }\r\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\nlet lst = [];\r\nwhile (t--) {\r\n let res = 0;\r\n let input = parseInt(readline()); // changeable\r\n res = Number.parseInt(input / 10);\r\n let str = String(input);\r\n if (str[str.length - 1] == \"9\") {\r\n res += 1;\r\n }\r\n lst.push(res);\r\n}\r\nfor (let val of lst) {\r\n console.log(val);\r\n}\r\n\r\n}\r\n"}, {"source_code": "function solve(num) {\n console.log(Math.floor((num - 9) / 10) + 1);\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input.slice(1).map(n => parseInt(n));\n const len = dataArr.length;\n\n for (let i = 0; i < len; i++) {\n solve(dataArr[i]);\n }\n process.exit();\n});\n\n \t \t\t\t \t\t\t \t\t \t\t\t\t \t \t\t"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t; i++){\n var k = lines[i];\n var ans = Math.floor(k / 10);\n ans += k % 10 == 9 ? 1 : 0;\n console.log(ans);\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tans.push(Math.trunc((n + 1) / 10));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar output = Math.floor(N / 10);\r\n\t\tif(N % 10 == 9){\r\n\t\t\toutput++;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar currentLine = 0;\r\nvar inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (let i = 0; i < t; i++) {\r\n const n = +input();\r\n console.log(Math.floor((n + 1) / 10));\r\n }\r\n}\r\n"}, {"source_code": "// Input handling (Ctrl-D for EOF)\r\n\r\nconst readlineModule = require(\"readline\");\r\nconst rl = readlineModule.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst input = [];\r\nlet currLine = 0;\r\n\r\nrl.on(\"line\", line => {\r\n input.push(line);\r\n});\r\n\r\nrl.on(\"close\", () => {\r\n main();\r\n})\r\n\r\nfunction readline() {\r\n return input[currLine++];\r\n}\r\n\r\n// Main function\r\n\r\nfunction main() {\r\n const T = parseInt(readline());\r\n for (let t = 0; t < T; t++) {\r\n const N = parseInt(readline());\r\n console.log(Math.floor((N+1)/10));\r\n }\r\n}"}, {"source_code": "const lines = parseInt(readline());\n\nArray(lines).fill(0).forEach(() => {\n const n = parseInt(readline());\n\n print(Math.floor(n / 10) + (n % 10 >= 9 ? 1 : 0));\n});\n"}, {"source_code": "\r\nvar t=Number(readline());\r\nfor (var i=0;i Math.floor((n + 1) / 10);\r\n\r\nconst out = stdin\r\n .split('\\n')\r\n .slice(1)\r\n .map((nStr) => {\r\n const n = parseInt(nStr);\r\n\r\n if (typeof n === 'number') {\r\n return f(n);\r\n } else {\r\n return '';\r\n }\r\n })\r\n .join('\\n');\r\n\r\nconsole.log(out);"}, {"source_code": "const fs = require('fs');\r\n\r\nconst stdin = String(fs.readFileSync(0));\r\n\r\nconst out = stdin\r\n .split('\\n')\r\n .slice(1)\r\n .map((n) => Math.floor((parseInt(n) + 1) / 10))\r\n .join('\\n');\r\n\r\nconsole.log(out);"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let res = 0;\r\nlet input = readline(); // changeable\r\nres = Number.parseInt(input / 10);\r\nlet str = String(input);\r\nif (str[str.length - 1] == \"9\") {\r\n res += 1;\r\n}\r\nconsole.log(res);\r\n}\r\n"}, {"source_code": "function S(x) {\n return String(x).split('').reduce((acc, i) => acc + +i, 0);\n}\n\nvar n = parseInt(readline());\nvar l = Array();\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) l.push(x);\n}\n\nprint(l.join(' '));\n"}, {"source_code": "function S(x) {\n return String(x).split('').reduce((acc, i) => acc + +i, 0);\n}\n\nvar n = readline();\nvar l = Array();\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) l.push(x);\n}\n\nprint(l.join(' '));\n"}, {"source_code": "function S(x) {\n return String(x).split('').reduce((acc, i) => acc + +i, 0);\n}\n\nvar n = readline();\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) print(x);\n}\n"}, {"source_code": "function S(x) {\n return String(x).split('').reduce((acc, i) => acc + +i, 0);\n}\n\nvar n = readline();\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) print(count);\n}\n"}, {"source_code": "function S(x) {\n return String(x).split('').reduce((acc, i) => acc + +i, 0);\n}\n\nvar n = readline();\n\nvar count = 0;\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) count++;\n}\n\nprint(count);\n"}, {"source_code": "function S(x) {\n return 1 <= x && x <= x;\n}\n\nvar n = readline();\n\nvar count = 0;\n\nfor (var x = 1; x <= n; x++) {\n if (S(x + 1) < S(x)) count++;\n}\n\nprint(count);\n"}], "src_uid": "8e4194b356500cdaacca2b1d49c2affb"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n\r\n var flag = false\r\n for (var i = 1; i < 100000; i++) {\r\n var y = x - i * i * i\r\n var cub = Math.floor(Math.cbrt(y))\r\n // console.log(cub, y)\r\n if (y > 0 && cub * cub * cub === y) {\r\n // console.log(i, cub)\r\n flag = true\r\n }\r\n // console.log(Math.floor(Math.cbrt(i)))\r\n // if (y > 0n) {\r\n // var r = 10000n\r\n // var l = 0n\r\n // while (r > l + 1n) {\r\n // var mid = (r + l) / 2n\r\n // if (mid * mid * mid >= y) r = mid\r\n // else l = mid\r\n // }\r\n //\r\n // console.log(l, r, y)\r\n // if (r*r*r === y) flag = true\r\n // }\r\n }\r\n console.log(flag ? 'YES' : 'NO')\r\n // for (int i = rt; i >=0; --i)\r\n // {\r\n // if (binary_search(i,i,num))\r\n // {\r\n // flag=true;\r\n // break;\r\n // }\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\nfunction binary_search(num2, r, num, rr) {\r\n var mid;\r\n var l = r;\r\n r = num\r\n var value;\r\n // console.log(l, r)\r\n\r\n while (l <= r) {\r\n mid = ((l + r) / 2n);\r\n // Calculating mid.\r\n // console.log(mid * mid * mid + num2 * num2 * num2, num)\r\n value = mid * mid * mid + num2 * num2 * num2\r\n if ((value) === num) {\r\n\r\n return true;\r\n } else if ((value) > num) {\r\n r = mid - 1n;\r\n } else {\r\n l = mid + 1n;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n", "positive_code": [{"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var row = read.split(\" \").map(function(x) { return parseInt(x); });\r\n \r\n var total = row[0];\r\n var a = 1;\r\n var flag = false;\r\n if (total > 1) {\r\n while(Math.pow(a, 3) < total) {\r\n var remain = total - a*a*a;\r\n var raw = Math.pow(remain, 1/3);\r\n var round = Math.round(raw);\r\n if(Math.pow(round, 3) == remain && round % 1 === 0) {\r\n flag = true;\r\n break;\r\n }\r\n a++;\r\n }\r\n }\r\n if(flag)\r\n write(\"YES\" + \"\\n\");\r\n else \r\n write(\"NO\" + \"\\n\");\r\n}"}, {"source_code": "tt = +readline()\r\nwhile (tt!==0){\r\n flag = false\r\n tt--\r\n n = +readline()\r\n for (var a=1; a*a*a<=n; a++){\r\n var b = n - a*a*a\r\n var B = Math.round(Math.cbrt(b))\r\n if (B>0 && b==B*B*B){\r\n flag = true\r\n break\r\n }\r\n }\r\n if (flag){print('YES')}\r\n else{print('NO')}\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nvar input = new Array();\r\nfor (var i = 0; i < limit; i++) {\r\n input[i] = parseInt(readline());\r\n}\r\nvar output = calc(input);\r\noutput.forEach(function (value) {\r\n print(value);\r\n});\r\nfunction calc(inputArray) {\r\n var result = new Array();\r\n for (var _i = 0, inputArray_1 = inputArray; _i < inputArray_1.length; _i++) {\r\n var element = inputArray_1[_i];\r\n if (element > 1) {\r\n var cubeRootNum = calcCubeRoot(element);\r\n var flag = false;\r\n for (var j = 1; j <= cubeRootNum; j++) {\r\n flag = calcSecondCube(j, element);\r\n if (flag)\r\n break;\r\n }\r\n if (flag) {\r\n result.push(\"YES\");\r\n }\r\n else {\r\n result.push(\"NO\");\r\n }\r\n }\r\n else\r\n result.push(\"NO\");\r\n }\r\n return result;\r\n}\r\nfunction calcCubeRoot(input) {\r\n var num = Math.cbrt(input);\r\n return Math.floor(num);\r\n}\r\nfunction calcSecondCube(first, element) {\r\n var different = element - first * first * first;\r\n if (different > 0) {\r\n var second = Math.cbrt(different);\r\n return second % 1 === 0;\r\n }\r\n else\r\n return false;\r\n}\r\n"}, {"source_code": "var Case = parseInt( readline() );\r\nwhile(Case--){\r\n var n = readline() ;\r\n var flag = false;\r\n for(var i = 1; i*i*i <= n; i++){\r\n var j = n - (i*i*i);\r\n var b = Math.round( Math.cbrt(j) );\r\n if(b && b*b*b == j){\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if(flag) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n\r\n var flag = false\r\n for (var i = 1; i < 10000; i++) {\r\n var y = x - i * i * i\r\n\r\n if (y > 0) {\r\n var r = 10000\r\n var l = 0\r\n while (r > l + 1) {\r\n var mid = Math.floor((r + l) / 2)\r\n if (mid * mid * mid > y) r = mid\r\n else l = mid\r\n }\r\n\r\n // console.log(l, r, y)\r\n if (l * l * l === y) flag = true\r\n }\r\n }\r\n console.log(flag ? 'YES' : 'NO')\r\n // for (int i = rt; i >=0; --i)\r\n // {\r\n // if (binary_search(i,i,num))\r\n // {\r\n // flag=true;\r\n // break;\r\n // }\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n for (let i = 1; i <= 10000; i++) obj[i * i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let n = parseInt(readline());\r\n for (let i = 1; i <= 10000; i++) {\r\n let j = n - i * i * i;\r\n if (j <= 0) {\r\n console.log(\"NO\");\r\n break;\r\n }\r\n if (obj[j]) {\r\n console.log(\"YES\");\r\n break;\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Actual code...\n\nfunction main() {\n const numCases = parseInt(readline());\n for (let i = 0; i < numCases; i++) {\n const target = parseInt(readline());\n const cubeRoot = Math.cbrt(target);\n let found = false;\n let a = 1;\n while (a < cubeRoot && !found) {\n const b = Math.cbrt(target - Math.pow(a, 3));\n if (Number.isInteger(b)) found = true;\n a++;\n }\n if (found) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar isOK = false;\r\n\t\tfor(var j = 1; j <= 10000; j++){\r\n\t\t\tif(Math.cbrt(N - j * j * j) % 1 == 0 && (N - j * j * j) > 0){\r\n\t\t\t\tisOK = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}"}, {"source_code": "input()\r\n//-------------------\r\n\r\nfunction input () {\r\n let i = ''\r\n process.stdin.on('data', c => i += c)\r\n process.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines);\r\n solve(lines)\r\n })\r\n\r\n}\r\n\r\nfunction solve (arr) {\r\n var d =+arr[0]\r\n \r\n for (var i =1 ; i <=d ;i++){\r\n console.log(test(+arr[i]))\r\n }\r\n\r\n\r\n}\r\n\r\nfunction test(num ){\r\n \r\n var Max =10000\r\n var mas =[]\r\n \r\n \r\n var k =1 \r\n while (k <=Max){\r\n \r\n mas.push(k*k*k)\r\n k++\r\n }\r\n var mno =new Set(mas)\r\n \r\n for (var a of mas){\r\n if (2*a > num) break;\r\n if (mno.has(num - a)) {\r\n //console.log(num,Math.cbrt(a),Math.cbrt(num -a) )\r\n return \"YES\"\r\n \r\n }\r\n }\r\n return \"NO\"\r\n \r\n \r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet arr = [];\r\nrl.on('line', line => {\r\n arr.push(Number(line));\r\n})\r\nrl.on('close', line => {\r\n var map = new Map();\r\n for (var i = 1; i * i * i <= 10 ** 12; i++) {\r\n map.set(i * i * i, i);\r\n }\r\n for (var i = 1; i < arr.length; i++) {\r\n var target = arr[i];\r\n var flag = false;\r\n for (var j = 1; j * j * j < target; j++) {\r\n if (map.has(target - j * j * j)) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n})"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on(\"line\", (ln) => {\r\n input.push(ln);\r\n}).on(\"close\", () => {\r\n const T = input.shift();\r\n\r\n for (let i = 0; i < T; i++) {\r\n const num = Number(input.shift());\r\n const limit = Math.floor(Math.pow(num, 1 / 3));\r\n let start = 1;\r\n let end = limit;\r\n\r\n let ans = \"NO\";\r\n while (start <= end && end <= limit) {\r\n let sum = Math.pow(start, 3) + Math.pow(end, 3);\r\n if (sum === num) {\r\n ans = \"YES\";\r\n break;\r\n }\r\n if (sum > num) {\r\n end--;\r\n continue;\r\n }\r\n if (sum < num) {\r\n start++;\r\n continue;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n});\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nfor (let i = 0; i < n; i++) {\r\n (function () {\r\n let num = +readline();\r\n let aaa = Math.cbrt(num);\r\n for (let j = 1; j < aaa; j++) {\r\n if (Math.cbrt(num - Math.pow(j, 3)) % 1 === 0) {\r\n return console.log('YES')\r\n }\r\n }\r\n console.log('NO')\r\n })();\r\n}"}, {"source_code": "/*\r\n * File Created: Tuesday, 16th February 2021 3:32:09 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n 'use-strict'\r\n\r\nconst { count } = require(\"console\");\r\n\r\n \r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf8');\r\n \r\n let data = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', chunk => {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const x = BigInt(readLine());\r\n\r\n // const arr = readLine().split(' ').map(Number);\r\n \r\n const res = c(x);\r\n \r\n console.log(res)\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n \r\n function a(n,arr){\r\n let count = 0;\r\n for(let i = 0 ; i < n - 1; i++){\r\n let max = Math.max(arr[i], arr[i+1]);\r\n let min = Math.min(arr[i], arr[i+1]);\r\n if(max/min > 2){\r\n while(min * 2 < max){\r\n max = max / 2;\r\n count++;\r\n }\r\n } else{\r\n continue;\r\n }\r\n }\r\n return count;\r\n }\r\n\r\n function b(n,arr){\r\n let c0 = 0;\r\n let c1 = 0;\r\n let c2 = 0;\r\n let count = 0;\r\n for(let i = 0 ; i < n ; i++){\r\n if(arr[i] % 3 === 0){\r\n c0++;\r\n } else if(arr[i] % 3 === 1){\r\n c1++;\r\n } else if(arr[i] % 3 === 2){\r\n c2++;\r\n }\r\n }\r\n \r\n while(c1 !== n / 3 || c2 !== n / 3 || c1 !== n / 3){\r\n // console.log(`${c0},${c1}, ${c2}`)\r\n if(c0 > n / 3){\r\n let free0 = c0 - n/3;\r\n while(free0 > 0){\r\n \r\n if(c1 < n / 3){\r\n free0--;\r\n c1++;\r\n count+=1;\r\n c0--;\r\n }\r\n if(c2 < n /3){\r\n free0--;\r\n c2++;\r\n count+=2;\r\n c0--;\r\n }\r\n }\r\n }\r\n if(c1 > n / 3){\r\n let free1 = c1 - n/3;\r\n while(free1 > 0){\r\n if(c2 < n / 3){\r\n free1--;\r\n c2++;\r\n count += 1;\r\n c1--;\r\n }\r\n if(c0 < n / 3){\r\n free1--;\r\n c0++;\r\n count += 2;\r\n c1--;\r\n }\r\n }\r\n }\r\n if(c2 > n/3){\r\n let free2 = c2 - n / 3;\r\n // console.log(`${free2}, ${c0}, ${c1}, ${c2}, ${n}`)\r\n while(free2 > 0){\r\n \r\n if(c0 < n / 3){\r\n free2--;\r\n c0++;\r\n count += 1;\r\n c2--;\r\n }\r\n if(c1 < n/3){\r\n free2--;\r\n c1++;\r\n count += 2;\r\n c2--;\r\n }\r\n }\r\n }\r\n }\r\n return count;\r\n \r\n }\r\n\r\n function c(x){\r\n for(let i = 1; i < 10001; i++){\r\n if(Math.cbrt(Number(x) - i * i * i) % 1 == 0 && (Number(x) - i * i * i) > 0){\r\n return 'YES'\r\n }\r\n } \r\n return 'NO';\r\n}\r\n\r\n module.exports = c"}, {"source_code": "var c = new Set(), i, t, x, m, f, r = readline;\nfor (i = 1; i <= 1e4; i++)\n c.add(i * i * i);\n\nt = parseInt(r());\nwhile (t--) {\n x = parseInt(r());\n m = Math.ceil(Math.cbrt(x));\n f = false;\n for (i = 1; i <= m && !f; i++)\n if (c.has(x - i * i * i))\n f = true;\n print(f? 'yes': 'no');\n}"}, {"source_code": "var c = new Set(), i, t, x, m, f, r = readline;\nfor (i = 1; i <= 1e4; i++)\n c.add(i * i * i);\n\nt = r();\nwhile (t--) {\n x = r();\n m = Math.ceil(Math.cbrt(x));\n f = false;\n for (i = 1; i <= m && !f; i++)\n if (c.has(x - i * i * i))\n f = true;\n print(f? 'yes': 'no');\n}"}, {"source_code": "var c = new Set();\n\nfor (var i = 1; i <= 1e4; i++)\n c.add(i * i * i);\n\nconst t = readline();\n\nfor (var _ = 0; _ < t; _++) {\n var x = readline();\n var f = false;\n for (i of c)\n if (c.has(x - i)) {\n f = true;\n break;\n }\n print(f? 'yes': 'no');\n}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline\nfor(i=1;i<=1e4;i++)c.add(i*i*i)\nt=r()\nwhile(t--){x=r()\nf=1\nfor(i of c)if(c.has(x-i)){f=0;break}\nprint(f?'no':'yes')}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline,p=print\nfor(i=1;i<=1e4;i++)c.add(i*i*i)\nt=r()\nwhile(t--){x=r()\nf=1\nfor(i of c)if(c.has(x-i)){f=0;break}\nprint(f?'no':'yes')}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline\nfor(i=1;i<=1e4;i++)c.add(i*i*i)\nt=r()\nwhile(t--){x=r()\nf=1\nfor(i=1;i*i*i<=x&&f;i++)if(c.has(x-i*i*i))f=0\nprint(f?'no':'yes')}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline\nfor (i=1;i<=1e4;i++)\n c.add(i*i*i);\nt=r()\nwhile(t--){\n x=r()\n f=1\n for(i=1;i*i*i<=x&&f;i++)\n if(c.has(x-i*i*i))\n f=0\n print(f?'no':'yes')\n}"}, {"source_code": "var c=new Set(),i,t,x,max,f,r=readline\nfor (i=1;i<=1e4;i++)\n c.add(i*i*i);\nt=parseInt(r())\nwhile(t--){\n x=parseInt(r())\n max=Math.ceil(Math.cbrt(x))\n f=0\n for(i=1;i<=max&&!f;i++)\n if(c.has(x-i*i*i))\n f=1\n print(f?'yes':'no')\n}"}, {"source_code": "var c=new Set(),i,t,x,max,f\nfor (i=1;i<=1e4;i++)\n c.add(i*i*i);\nt=parseInt(readline())\nwhile(t--){\n x=parseInt(readline())\n max=Math.ceil(Math.cbrt(x))\n f=0\n for (i=1;i<=max&&!f;i++)\n if (c.has(x-i*i*i))\n f=1\n print(f?'yes':'no')\n}"}, {"source_code": "var cubes = new Set();\n\nfor (var i = 1; i <= 1e4; i++)\n cubes.add(i * i * i);\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n if (cubes.has(x - a * a * a))\n f = true;\n \n print(f? 'yes': 'no');\n}"}], "negative_code": [{"source_code": "var c=new Set(),i,t,x,f,r=readline,p=print\nfor(i=1;i<=1e4;i++)c.add(i*i*i)\nt=r()\nwhile(t--){x=r()\nf=1\nfor(i of c)if(c.has(x-c)){f=0;break}\nprint(f?'no':'yes')}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline,z\nfor (i=1;i<=1e4;i++)\n c.add(i*i*i);\nt=r()\nwhile(t--){\n x=r()\n f=1\n for(i=1;z=i*i*i<=x&&f;i++)\n if(c.has(x-z))\n f=0\n print(f?'no':'yes')\n}"}, {"source_code": "var c=new Set(),i,t,x,f,r=readline,z\nfor(i=1;i<=1e4;i++)c.add(i*i*i)\nt=r()\nwhile(t--){x=r()\nf=1\nfor(i=1;z=i*i*i<=x&&f;i++)if(c.has(x-z))f=0\nprint(f?'no':'yes')}"}, {"source_code": "const cube = () => {\n var cache = new Set();\n return (a) => {\n if (cache.has(a)) {\n return true;\n } else {\n cache.add(a * a * a);\n return false;\n }\n }\n}\n\nconst memo_cube = cube();\n\nfor (var i = 1; i <= 1e4; i++)\n memo_cube(i)\n\nconst t = parseInt(readline());\n// const t = 1;\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n // var x = 703657519796;\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n if (memo_cube(x - a * a * a))\n f = true;\n \n print(f? 'yes': 'no');\n \n}"}, {"source_code": "const cube = () => {\n var cache = {};\n return (a) => {\n if (a in cache) {\n return cache[a];\n } else {\n const c = Math.pow(a, 3);\n cache[a] = c;\n return c;\n }\n }\n}\n\nconst memo_cube = cube();\n\nconst has_cubic_sum = () => {\n var cache = {};\n return (x) => {\n if (x in cache) {\n return cache[x];\n } else {\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n for (var b = a; b <= max && !f; b++)\n if (memo_cube(a) + memo_cube(b) == x)\n f = true;\n \n cache[x] = f;\n return f;\n }\n }\n}\n\nconst memo_has_cubic_sum = has_cubic_sum();\n\nconst t = parseInt(readline());\n// const t = 1;\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n print(has_cubic_sum(x)? 'yes': 'no');\n // var x = 2;\n // console.log(memo_has_cubic_sum(x)? 'yes': 'no');\n}"}, {"source_code": "const cube = () => {\n var cache = {};\n return (a) => {\n if (cache[a] !== undefined) {\n return cache[a];\n } else {\n const c = Math.pow(a, 3);\n cache[a] = c;\n return c;\n }\n }\n}\n\nconst memo_cube = cube();\n\nconst has_cubic_sum = () => {\n var cache = {};\n return (x) => {\n if (cache[x] !== undefined) {\n return cache[x];\n } else {\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n for (var b = a; b <= max && !f; b++)\n if (memo_cube(a) + memo_cube(b) == x)\n f = true;\n \n cache[x] = f;\n return f;\n }\n }\n}\n\nconst memo_has_cubic_sum = has_cubic_sum();\n\nconst t = parseInt(readline());\n// const t = 1;\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n print(has_cubic_sum(x)? 'yes': 'no');\n // var x = 2;\n // console.log(memo_has_cubic_sum(x)? 'yes': 'no');\n}"}, {"source_code": "const cube = () => {\n var cache = {};\n return (a) => {\n if (cache[a] !== undefined) {\n //console.log('Fetching from cache 1');\n return cache[a];\n } else {\n //console.log('Calculating result 1');\n const c = Math.pow(a, 3);\n cache[a] = c;\n return c;\n }\n }\n}\n\nconst memo_cube = cube();\n\nconst has_cubic_sum = () => {\n var cache = {};\n return (x) => {\n if (cache[x] !== undefined) {\n console.log('Fetching from cache 2');\n return cache[x];\n } else {\n console.log('Calculating result 2');\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n for (var b = a; b <= max && !f; b++)\n if (memo_cube(a) + memo_cube(b) == x)\n f = true;\n \n cache[x] = f;\n return f;\n }\n }\n}\n\nconst memo_has_cubic_sum = has_cubic_sum();\n\nconst t = parseInt(readline());\n// const t = 1;\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n print(has_cubic_sum(x)? 'yes': 'no');\n // var x = 1;\n //console.log(memo_has_cubic_sum(x)? 'yes': 'no');\n}"}, {"source_code": "const cubic_sum = (a, b) => {\n var cache = {};\n return (a, b) => {\n const key = `${a} ${b}`;\n if (cache[key] !== undefined)\n return cache[key];\n else {\n const sum = Math.pow(a, 3) + Math.pow(b, 3);\n\n cache[key] = sum;\n return sum;\n }\n }\n}\n\nconst has_cubic_sum = (x) => {\n var cache = {};\n return (x) => {\n if (cache[x] !== undefined)\n return cache[x];\n else {\n var max = Math.ceil(Math.cbrt(x));\n var f = false;\n for (var a = 1; a <= max && !f; a++)\n for (var b = a; b <= max && !f; b++)\n if (cubic_sum(a, b) == x)\n f = true;\n \n cache[x] = f;\n return f;\n }\n }\n}\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var x = parseInt(readline());\n print(has_cubic_sum(x)? 'yes': 'no');\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var row = read.split(\" \").map(function(x) { return parseInt(x); });\r\n \r\n var total = row[0];\r\n var a = 1;\r\n var flag = false;\r\n if (total > 1) {\r\n while(Math.pow(a, 3) <= total) {\r\n var remain = total - a*a*a;\r\n var raw = Math.pow(remain, 1/3);\r\n var round = Math.round(raw);\r\n if(Math.pow(round, 3) == remain && round % 1 === 0) {\r\n flag = true;\r\n break;\r\n }\r\n a++;\r\n }\r\n }\r\n if(flag)\r\n write(\"YES\" + \"\\n\");\r\n else \r\n write(\"NO\" + \"\\n\");\r\n}"}, {"source_code": "tt = +readline()\r\nwhile (tt!==0){\r\n flag = false\r\n tt--\r\n n = +readline()\r\n for (var a=0; a*a*a<=n; a++){\r\n var b = n - a*a*a\r\n var B = Math.round(Math.cbrt(b))\r\n if (B>0 && b==B*B*B){\r\n flag = true\r\n break\r\n }\r\n }\r\n if (flag){print('YES')}\r\n else{print('NO')}\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n for (let i = 1; i <= 10000; i++) obj[i * i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let n = parseInt(readline());\r\n for (let i = 0; i <= 10000; i++) {\r\n let j = n - i * i * i;\r\n if (j < 0) {\r\n console.log(\"NO\");\r\n break;\r\n }\r\n if (obj[j]) {\r\n console.log(\"YES\");\r\n break;\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n for (let i = 1; i <= 9999; i++) obj[i * i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let n = parseInt(readline());\r\n for (let i = 1; i <= 9999; i++) {\r\n let j = n - i * i * i;\r\n if (j < 0) {\r\n console.log(\"NO\");\r\n break;\r\n }\r\n if (obj[j]) {\r\n console.log(\"YES\");\r\n break;\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "b4ca6a5ee6307ab2bcdab2ea5dd5b2b3"} {"source_code": "print(function(n, a) {\n\n\ta.sort(function(a, b) {\n\t\treturn b - a;\n\t});\n\n\tvar sum = 0;\n\tvar b =a.map(function(v) {\n\t\treturn sum += v;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 1; i <= n; i *= 4) {\n\t\tans += b[i - 1];\n\t}\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number)));\n", "positive_code": [{"source_code": "print(function(n, a) {\n\n\tvar i, ans = 0;\n\n\n\ta.sort(function(a, b) {\n\t\treturn b - a;\n\t});\n\n\tfor (i = 1; i < n; i++)\n\t\ta[i] += a[i - 1];\n\n\tfor (i = 1; i <= n; i *= 4)\n\t\tans += a[i - 1];\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number)));"}], "negative_code": [], "src_uid": "93f6404a23bd2ff867d63db9ddf868ff"} {"source_code": "const mod = 998244353\n\n\nconst processData = (lines) => {\n let [n, m] = lines[0].split(' ').map(x => +x)\n const [x0, y0] = lines[1].split(' ')\n\n let d = n\n\n let res = [].concat(Array(n-1).fill('D')).concat(Array(m-1).fill('L'))\n\n let dirRight = true\n while(d) {\n res = res.concat(Array(m-1).fill(dirRight ? 'R' : 'L'))\n dirRight = !dirRight\n res.push('U')\n d--\n }\n\n console.log(res.length)\n console.log(res.join(''))\n // console.log(n, m)\n // let resMap = Array(n).fill(1).map(x => Array(m).fill(0))\n // let pos = [x0-1, y0-1]\n // resMap[pos[0]][pos[1]] = 1\n // for (const c of res) {\n // switch(c) {\n // case 'L':\n // pos[0]--\n // break\n // case 'R':\n // pos[0]++\n // break\n // case 'D':\n // pos[1]--\n // break\n // case 'U':\n // pos[1]++\n // break\n // }\n // if (pos[0] < 0) {\n // pos[0] = 0\n // }\n // if (pos[0] >= n) {\n // pos[0] = n-1\n // }\n // if (pos[1] < 0) {\n // pos[1] = 0\n // }\n // if (pos[1] >= m) {\n // pos[1] = m-1\n // }\n // resMap[pos[0]][pos[1]] = 1\n // }\n // console.log(resMap)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const [n, m, k] = readInts()\n const coord = new Array(k)\n const pos = new Array(k)\n const diff = new Array(k)\n for(let i = 0; i < k; i++) {\n coord[i] = readInts()\n }\n for(let i = 0; i < k; i++) {\n pos[i] = readInts()\n }\n let map = {}\n let c = 0\n let s = ''\n for(let i = 0, l = 2 * n * m; i < l && c < k; i++) {\n for(let i = 0; i < k; i++) {\n diff[i] = [pos[i][0] - coord[i][0], pos[i][1] - coord[i][1], i, map[i] ? 1 : 0]\n }\n for(let i = 0; i < k; i++) {\n if(diff[i][0] === 0 && diff[i][1] === 0 && !map[diff[i][2]]) {\n map[diff[i][2]] = true\n diff[i][3] = 1\n c++\n }\n }\n if(c === k) break\n diff.sort(sortThis)\n // wr(diff)\n let curr = diff[0]\n let changX = curr[0]\n let changY = curr[1]\n let index = curr[2]\n for(let i = 0; i < k; i++) {\n if(changX < 0) coord[i][0] = Math.max(1, coord[i][0] + changX)\n else coord[i][0] = Math.min(n, coord[i][0] + changX)\n if(changY < 0) coord[i][1] = Math.max(1, coord[i][1] + changY)\n else coord[i][1] = Math.min(m, coord[i][1] + changY)\n }\n if(changX < 0) {\n s = s.padEnd(s.length - changX, 'U')\n }\n if(changX > 0) {\n s = s.padEnd(s.length + changX, 'D')\n }\n if(changY < 0) {\n s = s.padEnd(s.length - changY, 'L')\n }\n if(changY > 0) {\n s = s.padEnd(s.length + changY, 'R')\n }\n }\n if(c === k) {\n wr(s.length)\n wr(s)\n }\n else wr(-1)\n}\n\nfunction sortThis(a, b) {\n if(a[3] === 1) return 1\n else if(b[3] === 1) return -1\n if(a[0] !== b[0]) {\n if(a[0] <= 0 && b[0] <= 0) return b[0] - a[0]\n else return a[0] - b[0]\n }\n else {\n if(a[1] <= 0 && b[1] <= 0) return b[1] - a[1]\n else return a[1] - b[1]\n }\n}\n"}], "negative_code": [{"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n let [n, m] = lines[0].split(' ').map(x => +x)\n\n let res = [].concat(Array(n-1).fill('L')).concat(Array(m-1).fill('D'))\n\n let dirRight = true\n m--\n while(m) {\n res = res.concat(Array(n-1).fill(dirRight ? 'R' : 'L'))\n dirRight = !dirRight\n res.push('U')\n m--\n }\n\n console.log(res.length)\n console.log(res.join(''))\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n let [n, m] = lines[0].split(' ').map(x => +x)\n\n let res = [].concat(Array(n).fill('L')).concat(Array(m).fill('D'))\n\n let dirRight = true\n while(m) {\n res = res.concat(Array(n).fill(dirRight ? 'R' : 'L'))\n dirRight = !dirRight\n res.push('U')\n m--\n }\n\n console.log(res.length)\n console.log(res.join(''))\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n let [n, m] = lines[0].split(' ').map(x => +x)\n\n let res = [].concat(Array(n-1).fill('L')).concat(Array(m-1).fill('D'))\n\n let dirRight = true\n while(m) {\n res = res.concat(Array(n-1).fill(dirRight ? 'R' : 'L'))\n dirRight = !dirRight\n res.push('U')\n m--\n }\n\n console.log(res.length)\n console.log(res.join(''))\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "90ce515c561872b5e2ec5f8f75cd44fe"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let k;\r\n if (n % 4 === 1) k = n - 1;\r\n else if (n % 4 === 3) k = n;\r\n else if (n % 4 === 2) k = 1;\r\n else k = 0;\r\n if (k === m) console.log(n);\r\n else if ((k ^ m) !== n) console.log(n + 1);\r\n else console.log(n + 2);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "\r\n\r\nvar n = parseInt(readline());\r\nvar xorList = [0];\r\nvar baseX = 0;\r\nfor (var x = 0; x < (3e5) + 10; x++){\r\n baseX = baseX^x;\r\n xorList.push(baseX);\r\n}\r\nvar outList = [];\r\nwhile(n--) {\r\n var cellList = readline().split(' ').map(v => parseInt(v));\r\n var baseX = xorList[cellList[0]]\r\n baseX ^= cellList[1];\r\n // console.log(cellList[0],cellList[1], baseX);\r\n if (baseX === 0){\r\n outList.push(cellList[0])\r\n }\r\n else if(cellList[0] === baseX){\r\n // console.log(\"2\")\r\n outList.push(cellList[0] + 2)\r\n }else {\r\n outList.push(cellList[0] + 1)\r\n\r\n }\r\n}\r\n\r\nprint(outList.join('\\n'))"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar list = new Array(400000).fill(0);\r\n\tfor(var i = 1; i < 400000; i++){\r\n\t\tlist[i] = i ^ list[i - 1];\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar xor = list[A - 1];\r\n\t\tif(xor == B){\r\n\t\t\tmyout(A);\r\n\t\t}else if((xor ^ B) != A){\r\n\t\t\tmyout(A + 1);\r\n\t\t}else{\r\n\t\t\tmyout(A + 2);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n if (m === 1) console.log(3);\r\n else console.log(2);\r\n continue;\r\n }\r\n let k = n - 1,\r\n r;\r\n if (k % 4 === 1 || k % 4 === 3) {\r\n r = k % 4 === 1 ? 1 : 0;\r\n } else {\r\n r = k % 4 === 0 ? k : k + 1;\r\n }\r\n if (r === 0) {\r\n if (n === m) console.log(n + 2);\r\n else if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n } else if (r === 1) {\r\n if (m - n === 1) console.log(n + 2);\r\n else if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n } else if (r === k) {\r\n if (m === 1) console.log(n + 2);\r\n else if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n } else {\r\n if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n if (m === 1) console.log(3);\r\n else console.log(2);\r\n continue;\r\n }\r\n let k = n - 1;\r\n if (k % 4 === 1 || k % 4 === 3) {\r\n let r = k % 4 === 1 ? 1 : 0;\r\n if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n } else {\r\n let r = k % 4 === 0 ? k : k + 1;\r\n if (r === k) {\r\n if (m === 1) console.log(n + 2);\r\n else if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n } else {\r\n if (r === m) console.log(n);\r\n else console.log(n + 1);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar list = new Array(400000).fill(0);\r\n\tfor(var i = 1; i < 400000; i++){\r\n\t\tlist[i] = i ^ list[i - 1];\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tif(A == 1 && B == 1){\r\n\t\t\tmyout(3);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar xor = list[A - 1];\r\n\t\tif(xor == B){\r\n\t\t\tmyout(A);\r\n\t\t}else{\r\n\t\t\tmyout(A + 1);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "d6790c9b4b2e488768fb4e746ee7ebe0"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var a = 2;\n var b = a - 1;\n var answer = '';\n var k = lines[l];\n if(k % 2 === 0){\n for(var j = 0; j < k / 2; j++){\n answer += a + ' ' + b + ' ';\n a += 2;\n b = a - 1;\n }\n }else{\n answer = 3 + ' ' + 1 + ' ' + 2 + ' ';\n a = 5;\n b = 0;\n for(var h = 3; h < k; h++){\n if(b % 2 === 0){\n answer += a + ' ';\n b = 1;\n }else{\n answer += a - 1 + ' ';\n b = 0;\n a += 2;\n }\n }\n }\n console.log(answer);\n }\n});", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n if (n === 1) {\r\n rl.output.write(1+ '\\n');\r\n continue;\r\n }\r\n\r\n if (n%2 === 0) {\r\n for(let i = 1; i <= n; i += 2) {\r\n if (i > 1)\r\n rl.output.write(' ');\r\n rl.output.write((i+1) + ' ' + i);\r\n }\r\n rl.output.write('\\n');\r\n } else {\r\n for(let i = 1; i <= n - 3; i += 2) {\r\n if (i > 1)\r\n rl.output.write(' ');\r\n rl.output.write((i+1) + ' ' + i);\r\n }\r\n if (n > 3)\r\n rl.output.write(' ');\r\n rl.output.write(n + ' ' + (n - 2) + ' ' + (n - 1) + '\\n');\r\n }\r\n }\r\n\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str) => {\r\n const num = parseInt(str);\r\n console.log(prettyPermutations(num));\r\n });\r\n})\r\n\r\nconst prettyPermutations = (num) => {\r\n let ans = new Array(num).fill(0);\r\n ans = ans.map((_, i) => i + 1);\r\n for (let i = 1; i < num; i++) {\r\n if (i % 2 === 1 || i === num - 1) [ans[i - 1], ans[i]] = [ans[i], [ans[i - 1]]];\r\n }\r\n return ans.join(' ');\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet r = [];\n\t\tfor(let j = 0; j < n - n%2; j += 2){\n\t\t\tr.push(j + 2);\n\t\t\tr.push(j + 1);\n\t\t}\n\t\tif (n%2 === 1){\n\t\t\tr.push(n);\n\t\t\t[r[n-1] , r[n-2]] = [r[n-2], r[n-1]];\n\t\t}\n\t\tans.push(r);\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n if (n % 2 === 0) {\r\n for (var i = 1; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n write('\\n');\r\n } else {\r\n write('3 1 2 ');\r\n for (var i = 4; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n write('\\n');\r\n }\r\n} "}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n if (n % 2 == 0) {\r\n for (var i = 1; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n write('\\n');\r\n } else {\r\n write('3 1 2 ');\r\n for (var i = 4; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n write('\\n');\r\n }\r\n} "}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n if (n % 2 == 0) {\r\n for (var i = 1; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n } else {\r\n write('3 1 2 ');\r\n for (var i = 4; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n }\r\n} \r\n\r\n"}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n if (n % 2 == 0) {\r\n for (var i = 1; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n } else {\r\n write('3 1 2 ');\r\n for (var i = 4; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n }\r\n} "}, {"source_code": "\r\nvar a=+readline();\r\nwhile(a--){\r\n var n=+readline();\r\n if(n%2===0){\r\n var j,i;\r\n for(i=2, j=1; i<=n && j<=n; i+=2, j+=2){\r\n print(i,j);\r\n }\r\n }\r\n else{\r\n print('3 1 2')\r\n var j,i;\r\n for( i=5, j=4; i<=n && j<=n; i+=2, j+=2){\r\n print(i, j);\r\n }\r\n }\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\nwhile(t--) {\r\n var n = parseInt(readline());\r\n if(n%2 == 0) {\r\n for(var i=1; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var a = 2;\n var b = a - 1;\n var answer = '';\n var k = lines[l];\n if(k % 2 === 0){\n for(var j = 0; j < k / 2; j++){\n answer += a + ' ' + b + ' ';\n a += 2;\n b = a - 1;\n }\n }else{\n answer = 3 + ' ' + 1 + ' ' + 2 + ' ';\n a = 5;\n b = 0;\n for(var h = 3; h < k; h++){\n if(b % 2 === 0){\n answer += a + ' ';\n b = 1;\n }else{\n answer += a - 1 + ' ';\n b = 0;\n a += 2;\n }\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t = parseInt(readline());\r\n while(t--) {\r\n var n = parseInt(readline());\r\n if(n%2 == 0) {\r\n for(var i=1; i b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(n));\n }\n});\n\nfunction solve(n) {\n const r = []\n let start = 1\n if (n & 1) {\n r[1] = 3\n r[2] = 1\n r[3] = 2\n start = 4\n }\n for (let i = start; i <= n; i++) {\n r[i] = ((i - start) & 1) ? i - 1 : i + 1\n }\n r.shift() // 0\n return r.join(' ')\n}\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\nvar i = 1;\r\nwhile (t--) {\r\n var n = parseInt(readline());\r\n if (n % 2 === 1) {\r\n write('3 1 2 ');\r\n i = 4;\r\n }\r\n\r\n for (; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n write('\\n');\r\n} "}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n const n = parseInt(readline());\r\n if (n % 2 == 0) {\r\n for (var i = 1; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n } else {\r\n write('3 1 2 ');\r\n for (var i = 4; i < n; i += 2) write(i + 1 + ' ' + i + ' ');\r\n }\r\n} "}, {"source_code": "\r\nvar n=+readline();\r\nwhile(n--){\r\n var a=+readline();\r\n if(a%2===0){\r\n var j;\r\n for(var i = 2, j = 1; i<=n && j<=n; i+=2,j+=2 ){\r\n print(i, j);\r\n }\r\n }\r\n else{\r\n print('3 1 2')\r\n var j;\r\n for(var i=5, j=4; i<=n && j<=n; i+=2, j+=2){\r\n print(i, j);\r\n }\r\n }\r\n \r\n}"}, {"source_code": "var n=+readline();\r\nwhile(n--){\r\n var a=+readline();\r\n if(a%2===0){\r\n for(var i=2, j=1; i<=n && j<=n; i+=2,j+=2 ){\r\n print(i, j);\r\n }\r\n }\r\n else{\r\n print('3 1 2')\r\n for(var i=5, j=4; i<=n && j<=n; i+=2, j+=2){\r\n print(i, j);\r\n }\r\n }\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\nwhile(t--) {\r\n var n = parseInt(readline());\r\n write(n+' ');\r\n for(var i=1; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j ++){\n var s = []\n var d = ''\n for(k = 1; k <= lines[j]; k++){\n s.push(k)\n }\n s = s.sort(function(a, b){return b - a});\n d += s[0] + ' '\n s = s.sort(function(a, b){return a - b});\n\n for(l = 0; l < s.length - 1; l++){\n d += s[l] + ' '\n }\n console.log(d)\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j ++){\n var s = []\n var d = ''\n for(k = 1; k <= lines[j]; k++){\n s.push(k)\n }\n s.sort(function(a, b){return b - a});\n d += s[0]\n for(l = 0; l <= s.length; l++){\n d += s[l]\n }\n console.log(d)\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j ++){\n var s = ''\n for(k = 1; k <= lines[j]; k++){\n s += k + ' '\n }\n console.log(s)\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j ++){\n var s = ''\n for(k = 0; k < lines[j]; k++){\n s += k + ''\n }\n console.log(s)\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n;j ++){\n var a = lines[j].split(' ').map(Number)\n console.log((a[1] + a[0]))\n }\n});\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var a = 2;\n var b = a - 1;\n var answer = '';\n var k = lines[l];\n if(k % 2 === 0){\n for(var j = 0; j < k / 2; j++){\n answer += a + ' ' + b + ' ';\n a += 2;\n b = a - 1;\n }\n }else{\n answer = 3 + ' ' + 1 + ' ' + 2 + ' ';\n a = 5;\n b = 0;\n for(var h = 3; h < k; h++){\n if(b % 2 === 0){\n answer += a + ' ';\n b = 1;\n }else{\n answer += a - 1 + ' ';\n b = 0;\n a += 3;\n }\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n console.log(2 + ' ' + 1 + \"\\n\" + 3 + ' ' + 1 + ' ' + 2)\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n console.log(2 + ' ' + 3 + \"\\n\" + 3 + ' ' + 1 + ' ' + 2)\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t = parseInt(readline());\r\n while(t--) {\r\n var n = parseInt(readline());\r\n if(n%2 == 0) {\r\n for(var i=1; i b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(n));\n }\n});\n\nfunction solve(n) {\n const r = []\n let start = 1\n if (n & 1) {\n r[1] = 3\n r[2] = 2\n r[3] = 1\n start = 4\n }\n for (let i = start; i <= n; i++) {\n r[i] = ((i - start) & 1) ? i - 1 : i + 1\n }\n r.shift() // 0\n return r.join(' ')\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n if (n === 1) {\r\n rl.write(1+ '\\n');\r\n continue;\r\n }\r\n\r\n if (n%2 === 0) {\r\n for(let i = 1; i <= n; i += 2) {\r\n if (i > 1)\r\n rl.write(' ');\r\n rl.write((i+1) + ' ' + i);\r\n }\r\n rl.write('\\n');\r\n } else {\r\n for(let i = 1; i <= n - 3; i += 2) {\r\n if (i > 1)\r\n rl.write(' ');\r\n rl.write((i+1) + ' ' + i);\r\n }\r\n if (n > 3)\r\n rl.write(' ');\r\n rl.write(n + ' ' + (n - 2) + ' ' + (n - 1) + '\\n');\r\n }\r\n }\r\n\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "f89bd4ec97ec7e02a7f67feaeb4d3958"} {"source_code": "var arrayLength = parseInt(readline())\nvar array = readline().split(' ').map(c => parseInt(c))\nif (arrayLength < 3){\n\tprint(arrayLength)\n}\nelse {\n\tvar size = [2], flag = false, count = 0, ans = 0\n\tfor (var i = 2; i < arrayLength; i++){\n\t\tif (array[i-1]+array[i-2] == array[i]){\n\t\t\tif (!flag){\n\t\t\t\tcount += 1; flag = true\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount +=1\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif (flag){\n\t\t\t\tflag = false\n\t\t\t\tsize.push(count+2)\n\t\t\t\tcount = 0\n\t\t\t}\n\t\t}\n\t}\n\tsize.push(count+2)\n\tsize.forEach((val) => {\n\t\tif (val > ans){\n\t\t\tans = val\n\t\t}\n\t})\n\tprint(ans)\n}", "positive_code": [{"source_code": ";(function () {\n\n print(function (n, a) {\n if (n < 3) {\n return n;\n }\n\n var q = [];\n for (var i = 2; i < n; i++) {\n if (a[i] === a[i - 1] + a[i - 2]) {\n if (q.length > 0) {\n var z = +q.slice(-1);\n if (z !== (i - 1)) {\n q.push('|');\n }\n }\n q.push(i);\n }\n }\n return 2 + Math.max.apply(null, q.map(function (e) { return e === '|' ? e : '0'; }).join('').split('|').map(function (e) { return e.length; }));\n }.apply(null, [+readline(), readline().split(' ').map(Number)]));\n\n}.call(this));\n"}, {"source_code": "print(function(n, a) {\n\tvar ans = 0,\n\t\tcnt = 0;\n\tif (a.length < 3) return a.length;\n\tfor (var i = 0; i < n; i++)\n\t\tif (a[i] + a[i + 1] === a[i + 2]) {\n\t\t\tcnt++;\n\t\t} else {\n\t\t\tans = Math.max(ans, cnt + 2);\n\t\t\tcnt = 0;\n\t}\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function c(){return s[i++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "negative_code": [{"source_code": "print(function(n, a) {\n\tvar ans = Math.min(a.length, 2),\n\t\tcnt = 0;\n\tfor (var i = 0; i < n; i++)\n\t\tif (a[i] + a[i + 1] === a[i + 2]) {\n\t\t\tcnt++;\n\t\t} else {\n\t\t\tans = Math.max(ans, cnt + 2);\n\t\t\tcnt = 0;\n\t\t}\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a) {\n\tvar ans = Math.min(2, a.length),\n\t\tcnt = ans;\n\tfor (var i = 2; i < n; i++)\n\t\tif (a[i] === a[i - 1] + a[i - 2]) {\n\t\t\tcnt++;\n\t\t} else {\n\t\t\tans = Math.max(ans, cnt);\n\t\t\tcnt = 0;\n\t\t}\n\n\tans = Math.max(ans, cnt);\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number)));\n"}, {"source_code": "var arrayLength = parseInt(readline())\nvar array = readline().split(' ').map(c => parseInt(c))\nif (arrayLength < 3){\n\tprint(arrayLength)\n}\nelse {\n\tvar size = [2], flag = false, count = 0\n\tfor (var i = 2; i < arrayLength; i++){\n\t\tif (array[i-1]+array[i-2] == array[i]){\n\t\t\tif (!flag){\n\t\t\t\tcount += 1; flag = true\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount +=1\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif (flag){\n\t\t\t\tflag = false\n\t\t\t\tsize.push(count+2)\n\t\t\t\tcount = 0\n\t\t\t}\n\t\t}\n\t}\n\tsize.push(count+2)\n\tprint(Math.max(size))\n}"}, {"source_code": ";(function () {\n\n print(function (n, a) {\n var q = [];\n for (var i = 2; i < n; i++) {\n if (a[i] === a[i - 1] + a[i - 2]) {\n if (q.length > 0) {\n var z = +q.slice(-1);\n if (z !== (i - 1)) {\n q.push('|');\n }\n }\n q.push(i);\n }\n }\n return 2 + Math.max.apply(null, q.join('').split('|').map(function (e) { return e.length; }));\n }.apply(null, [+readline(), readline().split(' ').map(Number)]));\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\n print(function (n, a) {\n if (n < 3) {\n return n;\n }\n\n var q = [];\n for (var i = 2; i < n; i++) {\n if (a[i] === a[i - 1] + a[i - 2]) {\n if (q.length > 0) {\n var z = +q.slice(-1);\n if (z !== (i - 1)) {\n q.push('|');\n }\n }\n q.push(i);\n }\n }\n return 2 + Math.max.apply(null, q.join('').split('|').map(function (e) { return e.length; }));\n }.apply(null, [+readline(), readline().split(' ').map(Number)]));\n\n}.call(this));\n"}], "src_uid": "f99a23bc65a1f5cdbf7909dba573ce51"} {"source_code": "/**\r\n * 04/16/21 morning\r\n * https://codeforces.com/contest/1509/problem/A\r\n */\r\n\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let odd = [];\r\n let even = [];\r\n for (const e of a) {\r\n e & 1 ? odd.push(e) : even.push(e);\r\n }\r\n let res = odd.concat(even);\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n var n = readline(), odd = [] , even = [];\r\n a = readline().split(' ');\r\n for(var j = 0 ; j < n ; ++j){\r\n if(a[j] % 2 === 0){\r\n even.push(a[j]);\r\n }\r\n else{\r\n odd.push(a[j]);\r\n }\r\n }\r\n print(odd.join(' ') + ' ' + even.join(' '));\r\n }"}, {"source_code": "var t = parseInt(readline());\r\nwhile(t--){\r\n var n = parseInt(readline());\r\n var h = readline().split(\" \").map(x => parseInt(x));\r\n var e = [] , o = [];\r\n for(var i = 0 ; i < n ; i++){\r\n if(h[i]&1){\r\n o.push(h[i]);\r\n } else e.push(h[i]);\r\n }\r\n \r\n var ans = \"\";\r\n e.forEach(x => ans += x+\" \");\r\n o.forEach(x => ans += x+\" \");\r\n print(ans);\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var odd = [];\n var even = [];\n for(j = 0; j < n; j++){\n if(k[j] % 2 == 1){\n odd.push(k[j]);\n }else{\n even.push(k[j]);\n }\n }\n var a = '';\n for(j = 0; j < odd.length; j++){\n a += odd[j] + ' ';\n }\n for(j = 0; j < even.length; j++){\n a += even[j] + ' ';\n }\n console.log(a);\n }\n }\n});"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n// var lines = fs.readFileSync(0, 'utf8').split('\\n');\n// const io = {\n// nextLine() {},\n// nextNum() {},\n// };\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = fs_1.default.readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nconst io = new IO();\nfunction solve(n, arr) {\n arr.sort((a, b) => {\n // if (a % 2 === b % 2) {\n // return 0 ;\n // }\n return (a % 2) - (b % 2);\n });\n console.log(arr.join(' '));\n}\nfunction main() {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n }\n}\nmain();\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const a = readLine().split(' ').map(Number);\r\n\r\n let res = [];\r\n\r\n let odd = [];\r\n let even = [];\r\n\r\n for(let i = 0; i < n; i++){\r\n if(a[i] % 2 === 0) even.push(a[i])\r\n else odd.push(a[i])\r\n }\r\n if(even.length >= odd.length){\r\n for(let i =0 ; i < even.length ; i++){\r\n res.push(even[i]);\r\n }\r\n for(let i = 0;i < odd.length; i++){\r\n res.push(odd[i]);\r\n }\r\n }\r\n else {\r\n for(let i = 0;i < odd.length; i++){\r\n res.push(odd[i]);\r\n }\r\n for(let i =0 ; i < even.length ; i++){\r\n res.push(even[i]);\r\n }\r\n }\r\n console.log(res.join(' '));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n "}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n const even = arr.filter(i => i % 2 === 0)\r\n const notEven = arr.filter(i => i % 2 !== 0)\r\n // if (even.length % 2 !== 0) {\r\n // const def = even.pop()\r\n // notEven.push(def)\r\n // }\r\n console.log(notEven.concat(even).join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i +v)\r\n\r\n\t\tconst odd = [];\r\n\t\tconst even = [];\r\n\r\n\t\tfor (let j=0; j {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var ans = []\r\n\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] % 2 === 0) ans.push(a[j])\r\n }\r\n var ans2 = []\r\n\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] % 2 === 1) ans2.push(a[j])\r\n }\r\n\r\n console.log(ans.concat(ans2).join(' '))\r\n })\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] % 2 == 0){\r\n\t\t\t\toutput.push(list[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] % 2 == 1){\r\n\t\t\t\toutput.push(list[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n var ans = 0;\n while(t !== 0 && t != 1){\n if(t % 2 == 1){\n ans++;\n }\n t = Math.floor(t / 2);\n }\n console.log(ans+1);\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j]; \n if(e == 2){\n k = 9 + ' ' + 18;\n }\n if(e == 8){\n k = 13 + ' ' + 9 + ' ' + 13 + ' ' + 15 + ' ' + 3 + ' ' + 9 + ' ' + 16 + ' ' + 10;\n }\n console.log(k);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return b - a});\n var answer = '';\n for(var l = 0; l < e; l++){\n answer += k[l] + ' ';\n }\n console.log(answer);\n }\n }\n});"}], "src_uid": "fe2131c9228a2ec4365fdc3d0faa413a"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\n\nfunction main(){\n\tlet tests = parseInt(readline());\n\tfor(let i = 0; i < tests; i++){\n\t\tlet num = parseInt(readline());\n\t\tlet inputArr = readline().split(' ').map(x => parseInt(x));\n\t\tlet mx = Math.max(...inputArr);\n\t\tlet freq = new Array(mx + 1).fill(null).map(x => new Array(0));\n\t\t//for(let i = 0; i <= mx; i++) freq[i] = new Array(0);\n\t\tlet yes = false;\n\t\tfor(let j = 0; j < num; j++){\n\t\t\tlet x = inputArr[j];\n\t\t\tfreq[x].push(j);\n\t\t\tif(freq[x].length >= 2){\n\t\t\t\tlet first = freq[x][0];\n\t\t\t\tlet last = freq[x][freq[x].length - 1];\n\t\t\t\tif(last - first > 1){\n\t\t\t\t\tconsole.log(\"YES\");\n\t\t\t\t\tyes = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(!yes){\n\t\t\tconsole.log(\"NO\");\n\t\t}\n\t}\t\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n\n let ok = false\n const freq = {}\n for (let i = 0; i < n; ++i) {\n if (Object.hasOwnProperty.call(freq, arr[i])) {\n if (i - freq[arr[i]] > 1) {\n ok = true\n break\n }\n } else {\n freq[arr[i]] = i\n }\n }\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let t = readInt(input)\n while(t--) {\n const n = readInt(input)\n const a = readInts(input)\n let ft = {}\n let lt = {}\n for(let i = 0; i < n; i++){\n if(!ft[a[i]]) {\n ft[a[i]] = i + 1\n lt[a[i]] = i + 1\n }\n else lt[a[i]] = i + 1\n }\n let f = false\n for(let i = 0; i < n && !f; i++){\n if(lt[a[i]]-ft[a[i]]>=2){\n f = true\n }\n }\n if(f) wr('YES')\n else wr('NO')\n }\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var nums = readline().split(' ').map(Number);\n var map = {}\n var result = ''\n for (var i = 0; i < nums.length; i++) {\n var num = nums[i];\n if (!map[num]) map[num] = {count: 0, last: i}\n map[num].count++\n if (map[num].count > 2 || map[num].last + 1 < i) {\n result = 'YES'\n break\n }\n map[num].last = i\n }\n print(result || 'NO')\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var isOK = false;\n //odd\n for(var j = 1; j < n - 1; j++){\n var L = new Set();\n var R = new Set();\n for(var k = 0; k < j; k++){\n L.add(list[k]);\n }\n for(var k = j + 1; k < n; k++){\n if(L.has(list[k])){\n isOK = true;\n break;\n }\n }\n }\n \n \n \n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n\nfunction isRotate(list){\n var len = list.length;\n var is = true;\n for(var i = 0; i < len; i++){\n if(list[i] != list[len - i - 1]){\n is = false;\n }\n }\n return is;\n}"}], "negative_code": [{"source_code": "'use strict'\n\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const n = getInt()\n const arr = getInts()\n\n let ok = false\n const freq = {}\n for (let i = 0; i < n; ++i) {\n if (Object.hasOwnProperty.call(freq, arr[i])) {\n if (i - freq[arr[i]] > 1) {\n ok = true\n break\n }\n }\n freq[arr[i]] = i\n }\n print(ok ? 'YES' : 'NO')\n }\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var isOK = false;\n for(var j = 3; j <= 4; j++){//select chars(3~)\n if(isOK){\n break;\n }\n var tmp = new Array(j);\n for(var k = 0; k < j; k++){\n tmp[k] = list[k];\n }\n for(var k = 0; k < n - j + 1; k++){\n if(k != 0){\n tmp.shift();\n tmp.push(list[k + j]);\n }\n var ok = isRotate(tmp);\n if(ok){\n isOK = true;\n break;\n }\n }\n }\n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n\nfunction isRotate(list){\n var len = list.length;\n var is = true;\n for(var i = 0; i < Math.ceil(len / 2); i++){\n if(list[i] != list[len - i - 1]){\n is = false;\n }\n }\n return is;\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var isOK = false;\n //odd\n for(var j = 1; j < n - 1; j++){\n var tmp = [list[j - 1], list[j], list[j + 1]];\n var ok = isRotate(tmp);\n if(ok){\n isOK = true;\n break;\n }\n }\n \n //even\n for(var j = 1; j < n - 2; j++){\n if(list[j] == list[j + 1]){\n var tmp = [list[j - 1], list[j], list[j + 1], list[j + 2]];\n var ok = isRotate(tmp);\n if(ok){\n isOK = true;\n break;\n }\n }\n }\n \n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n\nfunction isRotate(list){\n var len = list.length;\n var is = true;\n for(var i = 0; i < Math.ceil(len / 2); i++){\n if(list[i] != list[len - i - 1]){\n is = false;\n }\n }\n return is;\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var isOK = false;\n //odd\n for(var j = 1; j < n - 1; j++){\n var tmp = [list[j - 1], list[j], list[j + 1]];\n var ok = isRotate(tmp);\n if(ok){\n isOK = true;\n break;\n }\n }\n \n //even\n for(var j = 1; j < n - 2; j++){\n if(list[j] == list[j + 1]){\n var tmp = [list[j - 1], list[j], list[j + 1], list[j + 2]];\n var ok = isRotate(tmp);\n if(ok){\n isOK = true;\n break;\n }\n }\n }\n \n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n\nfunction isRotate(list){\n var len = list.length;\n var is = true;\n for(var i = 0; i < len; i++){\n if(list[i] != list[len - i - 1]){\n is = false;\n }\n }\n return is;\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var isOK = false;\n var tmp1 = [];\n for(var j = 0; j < n; j++){\n tmp1.push(list[j]);\n if(j >= 3){\n tmp1.shift();\n }\n if(j >= 2){\n var ok = isRotate(tmp1);\n if(ok){\n isOK = true;\n break;\n }\n }\n }\n \n var tmp2 = [];\n for(var j = 0; j < n; j++){\n tmp2.push(list[j]);\n if(j >= 4){\n tmp2.shift();\n }\n if(j >= 3){\n var ok = isRotate(tmp2);\n if(ok){\n isOK = true;\n break;\n }\n }\n }\n if(isOK){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n\nfunction isRotate(list){\n var len = list.length;\n var is = true;\n for(var i = 0; i < Math.ceil(len / 2); i++){\n if(list[i] != list[len - i - 1]){\n is = false;\n }\n }\n return is;\n}"}, {"source_code": "\nvar t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline().split(' ').join('');\n var pp = [];\n for(var i = 0; i < 9; i++) {\n for(var j = 0; j < 9; j++) {\n pp.push([i, j, i].join(''))\n pp.push([i, j, j, i].join(''))\n }\n }\n for(var i = 0; i < pp.length; i++) {\n if (str.indexOf(pp[i]) !== -1) {\n print('YES')\n break\n } else if (i == pp.length - 1) {\n print('NO')\n }\n }\n}"}, {"source_code": "\nvar t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline().split(' ').join('');\n var pp = [];\n if (n < 3) {\n print('NO')\n break;\n }\n for(var i = 0; i <= 9; i++) {\n for(var j = 0; j <= 9; j++) {\n pp.push([i, j, i].join(''))\n pp.push([i, j, j, i].join(''))\n }\n }\n for(var i = 0; i < pp.length; i++) {\n if (str.indexOf(pp[i]) !== -1) {\n print('YES')\n break\n } else if (i === pp.length - 1) {\n print('NO')\n }\n }\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline().split(' ').join('');\n var pp = [];\n if (n < 2) {\n print('NO')\n break;\n }\n for(var i = 0; i < 9; i++) {\n for(var j = 0; j < 9; j++) {\n pp.push([i, j, i].join(''))\n pp.push([i, j, j, i].join(''))\n }\n }\n for(var i = 0; i < pp.length; i++) {\n if (str.indexOf(pp[i]) !== -1) {\n print('YES')\n break\n } else if (i === pp.length - 1) {\n print('NO')\n }\n }\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var nums = readline().split(' ').map(Number);\n var result = ''\n for (var i = 0; i < nums.length - 2; i++) {\n if ((nums[i] === nums[i + 2]) || (i < nums.length - 2 && nums[i] === nums[i + 3] && nums[i + 1] === nums[i + 2] )) {\n result = 'YES'\n break\n }\n }\n print(result || 'NO')\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline().split(' ').join('');\n var pp = [];\n if (n < 3) {\n print('NO')\n break;\n }\n for(var i = 0; i < 9; i++) {\n for(var j = 0; j < 9; j++) {\n pp.push([i, j, i].join(''))\n pp.push([i, j, j, i].join(''))\n }\n }\n for(var i = 0; i < pp.length; i++) {\n if (str.indexOf(pp[i]) !== -1) {\n print('YES')\n break\n } else if (i === pp.length - 1) {\n print('NO')\n }\n }\n}"}, {"source_code": "\nvar t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var str = readline().split(' ').join('');\n var pp = [];\n if (n < 3) {\n print('NO')\n break;\n }\n for(var i = 0; i <= 9; i++) {\n for(var j = 0; j <= 9; j++) {\n pp.push([i, j, i].join(''))\n pp.push([i, j, j, i].join(''))\n }\n }\n var result = ''\n for(var i = 0; i < pp.length; i++) {\n if (str.indexOf(pp[i]) !== -1) {\n result = 'YES'\n break\n }\n }\n print(result || 'NO')\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var nums = readline().split(' ').map(Number);\n var map = {}\n var result = ''\n for (var i = 0; i < nums.length; i++) {\n var num = nums[i];\n if (!map[num]) map[num] = {count: 0, last: i}\n map[num].count++\n if (map[num] > 2 || map[num].last + 1 < i) {\n result = 'YES'\n break\n }\n map[num].last = i\n }\n print(result || 'NO')\n}"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var nums = readline().split(' ').map(Number);\n var result = ''\n for (var i = 0; i < nums.length - 1; i++) {\n if ((nums[i] === nums[i + 2]) || (i < nums.length - 2 && nums[i] === nums[i + 3] && nums[i + 1] === nums[i + 2] )) {\n result = 'YES'\n break\n }\n }\n print(result || 'NO')\n}"}], "src_uid": "5139d222fbbfa70d50e990f5d6c92726"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n if(n % 2 === 0){\n console.log(2, n - 3, 1);\n continue;\n }\n var a = (n - 1) / 2;\n if(a % 2 === 0){\n console.log(a - 1, a + 1, 1);\n }else{\n console.log(a - 2, a + 2, 1);\n }\n }\n});\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node solution.js < input.txt > output.txt\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n\tlet n = parseInt(readLine());\r\n problem(n);\r\n }\r\n}\r\nfunction gcd(i,j){\r\n if(j===0){\r\n return i;\r\n }\r\n return gcd(j,i%j);\r\n}\r\nfunction problem(n){\r\n n--;\r\n if(n%2!==0){\r\n console.log(`${parseInt(n/2)} ${parseInt((n+1)/2)} ${1}`);\r\n }else {\r\n let temp=n/2;\r\n for(let i=1;i {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => +i)\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nlet gcd = function (a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction solve(arr) {\r\n let b, s2 = Math.floor(arr / 2)\r\n for (let c = 1; c < arr; ++c) {\r\n for (let a = 0; a < s2; ++a) {\r\n b = arr - c - a;\r\n if (a === b || b === c || c === a) {\r\n continue\r\n }\r\n if (gcd(a, b) === c) {\r\n console.log(`${a} ${b} ${c}`)\r\n return\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "var n;\r\n var tests = parseInt(readline());\r\n\r\n for (var t=0; t stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n if(n % 2 === 0){\n console.log(2, n - 3, 1);\n continue;\n }\n var a = (n - 1) / 2;\n if(a % 2 === 0){\n console.log(a - 1, a + 1, 1);\n }else{\n console.log(a - 2, a + 2, 1);\n }\n }\n});\n\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n var a = new Map();\n for(j = 1; j * j <= n; j++){\n a.set(j * j, 1);\n }\n for(j = 1; j * j * j <= n; j++){\n a.set(j * j * j, 1);\n }\n console.log(a.size);\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node solution.js < input.txt > output.txt\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n\tlet n = parseInt(readLine());\r\n GCDP(n);\r\n }\r\n}\r\nfunction GCDP(n){\r\n console.log(`${1} ${n-2} ${1}`);\r\n}"}], "src_uid": "d4f4d6341f52cceb862faa89e85a42a3"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n// Codeforces Round #752 (Div. 2)\r\n\r\n// B\r\n\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let testCaseNum = 0; testCaseNum < t; testCaseNum += 1) {\r\n const sequenceLen = +readLine();\r\n\r\n const sequence = readLine()\r\n .split(' ')\r\n .map(str => +str);\r\n\r\n\r\n let xorIsZero = sequenceLen % 2 === 0;\r\n\r\n for (let ix = 1; ix < sequenceLen; ix += 1) {\r\n xorIsZero = xorIsZero || sequence[ix] <= sequence[ix - 1];\r\n }\r\n \r\n console.log(xorIsZero ? 'YES' : 'NO');\r\n }\r\n};", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = (N % 2 == 0);\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(list[i] >= list[i + 1]){\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(i => +i))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n let res = true\r\n if (n % 2) {\r\n res = false\r\n for (let j = 1; j < n; j++) {\r\n if (arr[j] <= arr[j - 1]) {\r\n res = true\r\n break;\r\n }\r\n }\r\n }\r\n if (res) {\r\n console.log(\"YES\")\r\n } else {\r\n console.log(\"NO\")\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n if (!(n & 1)) return 'YES'\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] <= arr[i - 1]) {\n return 'YES'\n }\n }\n return 'NO'\n}\n"}, {"source_code": "const solve = (n,arr)=>{\r\n if(n%2===0) console.log(\"YES\");\r\n else{\r\n for(let i=0;i=arr[i+1]){\r\n console.log(\"YES\");\r\n return;\r\n }\r\n }\r\n console.log(\"NO\");\r\n }\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}], "negative_code": [{"source_code": "const solve = (n,arr)=>{\r\n if(n%2===0) console.log(\"YES\");\r\n else{\r\n let obj = {};\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n if(n%2===0) console.log(\"YES\");\r\n else{\r\n let obj = {};\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' '))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n let res = true\r\n if (n % 2 !== 0) {\r\n res = false;\r\n for (let j = 1; j < n; ++j) {\r\n if (arr[j] <= arr[j - 1]) {\r\n res = true\r\n break\r\n }\r\n }\r\n }\r\n if (res) {\r\n console.log(\"YES\")\r\n } else {\r\n console.log(\"NO\")\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n if (!(n & 1)) return 'YES'\n\n for (let i = 2; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) {\n return 'YES'\n }\n }\n return 'NO'\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n if (!(n & 1)) return 'YES'\n\n for (let i = 2; i < arr.length; i++) {\n if (arr[i] <= arr[i - 1]) {\n return 'YES'\n }\n }\n return 'NO'\n}\n"}], "src_uid": "d8d33581ceb13da9bb99e90296bdd8f7"} {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var x = +readline();\n var counter = 0;\n var nums = [];\n while (x > 0) {\n var next = x % 10;\n if (next > 0) {\n nums.push(next * Math.pow(10, counter));\n }\n x = (x - (x % 10)) / 10;\n counter++;\n }\n print(nums.length);\n print(nums.join(\" \"));\n }\n}\nmain()", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readline());\n const numbers = [];\n for (let i = 0; i < n; i++) {\n numbers.push(parseInt(readline()));\n }\n\n numbers.forEach(number => {\n const res = [];\n let i = 1;\n\n while (i <= number) {\n const digit = (parseInt(number / i) % 10);\n\n if (digit) {\n res.push(digit * i);\n }\n\n i *= 10;\n }\n\n console.log(res.length);\n console.log(res.join(' '));\n })\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n const ans = [];\n let power = 1;\n\n while (n > 0) {\n if (n % 10 > 0) {\n ans.push(n % 10 * power);\n }\n\n n = Math.floor(n / 10);\n power *= 10;\n }\n\n console.log(ans.length);\n console.log(ans.join(' '));\n\n // const ans = [];\n // for (let i = 0; i < d.length; i++) {\n // if (d[i] === '0') {\n // continue;\n // }\n\n // let n = d[i];\n // for (let j = i + 1; j < d.length; j++) {\n // n = n + '0';\n // }\n // ans.push(n);\n // }\n\n // console.log(ans.length);\n // console.log(ans.join(' '));\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const ans = [];\n for (let i = 0; i < d.length; i++) {\n if (d[i] === '0') {\n continue;\n }\n\n let n = d[i];\n for (let j = i + 1; j < d.length; j++) {\n n = n + '0';\n }\n ans.push(n);\n }\n\n console.log(ans.length);\n console.log(ans.join(' '));\n\n c++;\n});\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let t = parseInt(input[0]);\n\n for (let i = 1; i <= t; i += 1) {\n const n = input[i];\n\n if (n.length === 1) console.log(`1\\n${n}`);\n else {\n const answer = [];\n\n let i = 0;\n for (const num of n.split(\"\")) {\n if (num !== \"0\") answer.push(num.padEnd(n.length - i, \"0\"));\n\n i += 1;\n }\n console.log(answer.length);\n console.log(answer.join(\" \"));\n }\n }\n});\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i {\n return ch * Math.pow(10, strLength-index-1)\n })\n .filter(x => x > 0)\n console.log(arr.length)\n console.log(arr.join(' '))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function solve(n) {\n const base = 10;\n const result = [];\n let m = 1;\n while (n > 0) {\n const d = (n % base);\n n = (n - d) / base;\n const t = m * d;\n if (t > 0) {\n result.unshift(t);\n }\n m = m * base;\n }\n return result;\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const n = Number(t);\n const result = solve(n);\n console.log(result.length);\n console.log(result.join(' '));\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(n) {\n const base = 10;\n const result = [];\n let m = 1;\n while (n > 0) {\n const d = (n % base);\n n = (n - d) / base;\n const t = m * d;\n if (t > 0) {\n result.unshift(t);\n }\n m = m * base;\n }\n return result;\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n const n = Number(line);\n const result = solve(n);\n console.log(result.length);\n console.log(result.join(' '));\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n) {\n let res = [];\n for (let i = 0; i < n.length; i++) {\n if (n[i] == 0) continue;\n let round = n[i] * Math.pow(10, n.length - i - 1);\n res.push(round);\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = readLine();\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n);\n console.log(res.length);\n console.log(res.join(' '));\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let testCases = +inputs[0];\n let roundNumbers = inputs.slice(1).map(num => Number(num));\n let newRoundNumbers = {};\n while (testCases--) {\n\n let roundNumber = roundNumbers[testCases];\n let power = 1;\n let arr = [];\n newRoundNumbers[roundNumbers[testCases]] = [];\n while (roundNumber > 0) {\n if (roundNumber % 10 > 0) {\n newRoundNumbers[roundNumbers[testCases]].push((roundNumber % 10) * power);\n }\n roundNumber = Math.floor(roundNumber / 10);\n power *= 10;\n }\n // newRoundNumbers[roundNumbers[testCases]] = arr;\n }\n\n for (let row of roundNumbers) {\n console.log(newRoundNumbers[row].length);\n console.log(newRoundNumbers[row].join(' '));\n }\n\n}\n\n\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n5009\n7\n9876\n10000\n10\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n for (var i = 0; i < t; i++) {\n let ans = [];\n let n = parseInt(readLine());\n let z = n;\n let k = 1;\n while (ans.length != String(n).split('').length) {\n ans.push(z % 10 * k);\n z = Math.floor(z / 10);\n k *= 10;\n }\n ans = ans.filter(v => v > 0)\n console.log(ans.length);\n console.log(ans.join(' '))\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n //const [n,k] = readline().split(\" \").map(e => parseInt(e));\n let n = parseInt(readline(), 10);\n let numbers = [];\n let i = 0;\n while (n > 0) {\n const mod = n % 10;\n if (mod > 0) {\n numbers.push(mod * (Math.pow(10, i)))\n //numbers.push(mod);\n }\n\n n = Math.floor(n / 10);\n i++;\n }\n\n console.log(numbers.length)\n console.log(numbers.join(' '))\n\n\n }\n\n\n}\n"}, {"source_code": "function getMul (x){\n\tvar temp =1;\n\twhile(x --){\n\t\ttemp *=10;\n\t}\n\treturn temp;\n}\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\tvar num = readline().split(\"\");\n\n\tvar sz =num.length;\n\tvar zero =sz -1;\n\tvar cnt =0;\n\tvar ans =\"\";\n\n\tfor(var i =0 ; i = 0; i--) {\n if (n[i] == \"0\") {\n multi *= 10;\n continue;\n }\n res = \" \" + parseInt(n[i]) * multi + res;\n multi *= 10;\n counter++;\n }\n print(counter);\n print(res.trim());\n}\n"}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var n = readline();\n var nString = \"\" + n;\n if (n.length === 1) {\n print(1);\n print(n);\n continue;\n }\n if (n.slice(1) == 0) {\n print(1);\n print(n);\n continue;\n }\n var resultArr = [];\n for (var j = 0; j <= nString.length; j++) {\n var ost = nString % +(\"1\" + \"0\".repeat(j+1));\n if (ost > 0) {\n resultArr.push(ost);\n nString = \"\" + (nString - ost)\n }\n }\n print(resultArr.length);\n print(resultArr.join(\" \"));\n }\n}"}, {"source_code": "var inputLength = readline();\nvar input = [];\n\nfor(var j=0; j 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 9000\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow = pow - 1;\n }\n\n multipliers.push(remainder);\n multipliers = multipliers.filter(m => m !== 0);\n print(multipliers.length);\n print(multipliers.join(' '));\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n let multipliers = [];\n let n = parseInt(readline(), 10);\n let pow = 4;\n let remainder = n;\n\n while (remainder > 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 9000\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow = pow - 1;\n }\n\n multipliers.push(remainder);\n multipliers = multipliers.filter(m => m !== 0);\n print(multipliers.length);\n print(multipliers.join(' '));\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10)\n\nwhile (t--) {\n let n = parseInt(readline(), 10);\n let multipliers = [];\n let pow = 4;\n let remainder = n;\n\n while (remainder > 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 900\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow--;\n }\n\n multipliers.push(remainder);\n multipliers = multipliers.filter(m => m !== 0);\n print(multipliers.length);\n print(multipliers.join(\" \"));\n}\n"}, {"source_code": " var nCases = parseInt(this.readline());\n for (var i = 0; i < nCases; i++){\n var n = parseInt(this.readline());\n var res = [];\n var mult = 1;\n while (n > 0){\n if (n % 10 !== 0){\n res.splice(0, 0, n % 10 * mult);\n }\n mult *= 10;\n n = Math.floor(n / 10);\n }\n var j = 0;\n var str = ''\n while (j < res.length - 1)\n str += res[j++] + ' ';\n str += res[j] !== undefined ? res[j] + '\\n' : '';\n print(res.length + '\\n');\n print(str);\n }"}, {"source_code": "function getNonZeroDigits(str) {\n\tvar count = 0\n\tfor (var ch of str)\n\t\tif (ch !== \"0\")\n\t\t\t++count\n\treturn count\n}\n\nfunction getAllRoundNumbers(str) {\n\tvar len = str.length\n\tfor (var i in str) {\n\t\tif (str[i] !== \"0\") {\n\t\t\tprint(((str[i]-'0')*Math.pow(10,len-i-1)), end=\" \")\n\t\t}\n\t}\n}\n\nvar tc = Number(readline())\nwhile(tc--) {\n\tvar str = readline()\n\tprint(getNonZeroDigits(str))\n\tgetAllRoundNumbers(str)\n}"}, {"source_code": "let input = require('fs')\n .readFileSync(0, 'ascii')\n .split('\\n')\n .filter(line => !/^\\s*$/.test(line))\n .map(l => l.split(' ').map(w => parseInt(w)));\n\nlet [t, ...ns] = input;\n\nfor (n of ns) {\n let k = 1;\n let r = [];\n while (n > 0) {\n\tif (n % 10)\n\t r.push(k * (n % 10));\n\tk *= 10;\n\tn = Math.floor(n / 10);\n }\n console.log(r.length);\n console.log(...r);\n}\n"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n const result = {problem,\n T: parseInt(line),\n isProcessing: true,\n cases: []\n };\n return result;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || !cases[cases.length - 1].isProcessing) {\n cases.push({\n t: line\n });\n }\n\n const isProcessing = cases.length < problem.T;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const t = data.t;\n let result = [];\n const len = t.length - 1;\n\n for(let i = len; i >= 0; i--) {\n if(t[i] == 0) continue;\n\n let res = t[i];\n for(let j = 0; j < (len - i); j++) {\n res += '0';\n }\n result.push(res);\n }\n \n return result;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result.length + '\\n' + result.join(' '));\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const n = parseInt(readLine(), 10);\n for(let i =0; i0){\n let s = Math.pow(10,(target + '').length - 1 ) * parseInt((target + '')[0]);\n target -= s;\n j++;\n nums.push(s);\n }\n console.log(j)\n console.log(nums.join(' '))\n }\n return;\n}\n"}, {"source_code": "const readline = require('readline');\nconst r = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tc\nlet input;\nr.on('line', (line) => {\n if (!tc) { tc = line; }\n else {\n let num = +line;\n let ans = nums(num);\n console.log(ans.length);\n console.log(ans.map(n => \"\"+n).join(\" \"));\n }\n});\n\n\n\n\nfunction nums(n)\n{\n let arr =[];\n let pow =1;\n\n while(n > 0)\n {\n let r = n%10;\n if(r != 0)\n arr.push(r*pow);\n pow *= 10;\n n = Math.floor(n/10);\n }\n return arr;\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n var t = nextInt();\n\tvar output = new Array(2 * t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = next();\n\t\tvar list = [];\n\t\tfor(var j = 0; j < n.length; j++){\n\t\t\tvar val = myconv(n[j],1);\n\t\t\tif(val % 10 != 0){\n\t\t\t\tlist.push(val * Math.pow(10,n.length - j - 1));\n\t\t\t}\n\t\t}\n\t\toutput[i * 2] = list.length;\n\t\toutput[i * 2 + 1] = myconv(list,8);\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction repZero(n) {\n var s = \"\";\n for (var i = 0; i < n; i++) {\n s += \"0\";\n }\n return s;\n}\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var s = readline();\n var n = s.length;\n var r = [];\n for (var i = 0; i < n; i++) {\n if (s[i] != '0') {\n r.push(\"\" + s[i] + repZero(n - i - 1));\n }\n }\n print(r.length);\n print(r.join(\" \"));\n }\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n const arr = Array.from(data).reverse().reduceRight((acc, value, index) => {\n if (value !== '0') {\n acc.push(value * (10**index));\n }\n return acc;\n }, []);\n return [arr.length, arr.join(' ')];\n\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount];\n\n let result = foo(data);\n answer += result[0] +\"\\n\";\n answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = readline().split(\"\");\n var multi = 1;\n var res = \"\";\n for (var i = n.length - 1; i >= 0; i--) {\n if (n[i] == \"0\") {\n multi *= 10;\n continue;\n }\n res = \" \" + parseInt(n[i]) * multi + res;\n multi *= 10;\n }\n print(res.trim());\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = readline().split(\"\");\n var multi = 1;\n var res = [\"\"];\n for (var i = n.length - 1; i >= 0; i--) {\n if (n[i] == \"0\") {\n multi *= 10;\n continue;\n }\n res.push(parseInt(n[i]) * multi);\n multi *= 10;\n }\n print(res.length, \"\\n\");\n res.forEach((val) => print(val));\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = readline().split(\"\");\n var multi = 1;\n var res = \"\";\n for (var i = n.length - 1; i >= 0; i--) {\n if (n[i] == \"0\") {\n multi *= 10;\n continue;\n }\n res = \" \" + parseInt(n[i]) * multi + res;\n multi *= 10;\n }\n print(parseInt(res.trim()));\n}\n"}, {"source_code": "var inputLength = readline();\nvar input = readline().split(\" \").map(x => parseInt(x));\nfor (var i =0; i< inputLength; i++) {\n\tvar frac = 10, count = 0, result = '';\n\twhile (input[i]) {\n\t\tvar part = input[i] % frac;\n\t\tfrac *= 10;\n\t\tif(part) {\n\t\t\tcount++;\n\t\t\tinput[i] -= part;\n\t\t\tresult += part + ' ';\n\t\t}\n\t}\n\tprint(count);\n print( result.substr(0, result.length - 1));\n\n}"}, {"source_code": "function main() {\n const int = +readline()\n const arrayInt = int.toString().split('')\n const reversedArrayInt = arrayInt.reverse()\n \n const parts = []\n \n reversedArrayInt.map((number, index) => {\n if (number !== '0') {\n parts.push(Number(number + '0'.repeat(index)))\n }\n })\n \n print(parts.length)\n print(parts.join(' '))\n}\nmain()"}, {"source_code": "function main() {\n const int = readline()\n const arrayInt = int.toString().split('')\n const reversedArrayInt = arrayInt.reverse()\n \n const parts = []\n \n reversedArrayInt.map((number, index) => {\n if (number !== '0') {\n parts.push(Number(number + '0'.repeat(index)))\n }\n })\n \n print(parts.length)\n print(parts)\n}\nmain()"}, {"source_code": "function main() {\n const int = readline()\n const arrayInt = int.toString().split('')\n const reversedArrayInt = arrayInt.reverse()\n \n const parts = []\n \n reversedArrayInt.map((number, index) => {\n if (number !== '0') {\n parts.push(Number(number + '0'.repeat(index)))\n }\n })\n \n print(parts.length)\n print(...parts)\n}\nmain()"}, {"source_code": "function integerParser(int) {\n const arrayInt = int.toString().split('')\n const reversedArrayInt = arrayInt.reverse()\n \n const parts = []\n \n reversedArrayInt.map((number, index) => {\n if (number !== '0') {\n parts.push(Number(number + '0'.repeat(index)))\n }\n })\n\n return parts\n}"}, {"source_code": "function main() {\n const int = +readline()\n const arrayInt = int.toString().split('')\n const reversedArrayInt = arrayInt.reverse()\n \n const parts = []\n \n reversedArrayInt.map((number, index) => {\n if (number !== '0') {\n parts.push(Number(number + '0'.repeat(index)))\n }\n })\n \n print(parts.length)\n print(...parts)\n}\nmain()"}, {"source_code": "function main() {\n var num = readline();\n if (num != null) {\n num.toString();\n var res = [];\n for (var i = 0; i < num.length; i++) {\n if (num[i] != 0) {\n res.push(num[i] + '0'.repeat(num.length - i - 1));\n }\n }\n print(res.length);\n print(...res);\n main();\n }\n}\nmain();"}, {"source_code": "var num = readline().toString();\nvar res = [];\nfor (var i = 0; i < num.length; i++) {\n if (num[i] != 0) {\n res.push(num[i] + '0'.repeat(num.length - i - 1));\n }\n}\nprint(res.length, ...res);"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const str = readline();\n let multipliers = [];\n let n = parseInt(str, 10);\n let pow = str.length - 1;\n let remainder = n;\n\n while (remainder > 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 9000\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow = pow - 1;\n }\n\n multipliers.push(remainder);\n multipliers = multipliers.filter(m => m !== 0);\n print(multipliers.length);\n print(str, '\u2013', multipliers.join(' '));\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const str = readline();\n const multipliers = [];\n let n = parseInt(str, 10);\n let pow = str.length - 1;\n let remainder = n;\n\n while (remainder > 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 9000\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow = pow - 1;\n }\n\n if (remainder !== 0) {\n multipliers.push(remainder);\n }\n print(multipliers.join(' '));\n}\n"}, {"source_code": "'use strict';\n\nlet t = parseInt(readline(), 10);\n\nwhile (t--) {\n const str = readline();\n const multipliers = [];\n let n = parseInt(str, 10);\n let pow = str.length - 1;\n let remainder = n;\n\n while (remainder > 9) {\n // 9876 % 1000 = 876\n remainder = n % Math.pow(10, pow);\n // 9876 - 876 = 9000\n multipliers.push(n - remainder);\n // 876\n n = remainder;\n pow = pow - 1;\n }\n\n if (remainder !== 0) {\n multipliers.push(remainder);\n }\n print(multipliers.length);\n print(multipliers.join(' '));\n}\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let t = parseInt(input[0]);\n\n for (let i = 1; i <= t; i += 1) {\n const n = input[i];\n\n if (n.length === 1) console.log(n);\n else {\n const answer = [];\n\n let i = 0;\n for (const num of n.split(\"\")) {\n if (num !== \"0\") answer.push(num.padEnd(n.length - i, \"0\"));\n\n i += 1;\n }\n\n console.log(answer.join(\" \"));\n }\n }\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n) {\n let res = [];\n for (let i = 0; i < n.length; i++) {\n if (n[i] == 0) continue;\n let round = n[i] * Math.pow(10, n.length - i - 1);\n res.push(round);\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = readLine();\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n);\n console.log(res.join(' '));\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let testCases = +inputs[0];\n let roundNumbers = inputs.slice(1).map(num => Number(num));\n let newRoundNumbers = {};\n while (testCases--) {\n\n let roundNumber = roundNumbers[testCases];\n let power = 1;\n let arr = [];\n while (roundNumber > 0) {\n if (roundNumber % 10 > 0) {\n arr.push((roundNumber % 10) * power);\n }\n roundNumber = Math.floor(roundNumber / 10);\n power *= 10;\n }\n newRoundNumbers[roundNumbers[testCases]] = arr;\n }\n\n for (const [key, value] of Object.entries(newRoundNumbers)) {\n console.log(value.length);\n console.log(value.join(' '));\n }\n}\n\n\n\n\n"}], "src_uid": "cd2519f4a7888b2c292f05c64a9db13a"} {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,r,b]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let x=Math.floor(r/(b+1));\r\n let y=101;\r\n if((b+1)*x!==r)\r\n {\r\n x++;\r\n y=r-(x-1)*(b+1);\r\n }\r\n let ans='';\r\n for(let i=1;i<=b;i++)\r\n {\r\n let z;\r\n if(i<=y) z=x;\r\n else z=x-1;\r\n for(let j=1;j<=z;j++)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n ans+='B'\r\n }\r\n while(r>0)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n console.log(ans);\r\n }\r\n})", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,r,b]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let x=Math.floor(r/(b+1));\r\n let y=101;\r\n if((b+1)*x!==r)\r\n {\r\n x++;\r\n y=r-(x-1)*(b+1);\r\n }\r\n let ans='';\r\n for(let i=1;i<=b;i++)\r\n {\r\n let z;\r\n if(i<=y) z=x;\r\n else z=x-1;\r\n for(let j=1;j<=z;j++)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n ans+='B'\r\n }\r\n while(r>0)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,r,b]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let x=Math.floor(r/(b+1));\r\n let y=101;\r\n if((b+1)*x!==r)\r\n {\r\n x++;\r\n y=r-(x-1)*(b+1);\r\n }\r\n // console.log('x=',x,y);\r\n let ans='';\r\n for(let i=1;i<=b;i++)\r\n {\r\n let z;\r\n if(i<=y) z=x;\r\n else z=x-1;\r\n // console.log('z=',z);\r\n for(let j=1;j<=z;j++)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n // ans+='R';\r\n // for(let j=1;j<=x;j++)\r\n // {\r\n // ans+='B';\r\n // b--;\r\n // }\r\n ans+='B'\r\n }\r\n while(r>0)\r\n {\r\n ans+='R';\r\n r--;\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "const processData = (lines) => {\n let n = +lines[0];\n for (let i=1; i<=n; i++) {\n let [c, r, b] = lines[i].split(' ').map(Number);\n let res = [];\n let divider = r/(b+1);\n let min = 0;\n\n for (let i=1; i<=r; i++) {\n res.push('R');\n let p = Math.floor(i/divider);\n if (p>min && b>0) {\n res.push('B');\n b--;\n }\n min = p;\n }\n console.log(res.join(''));\n }\n \n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, r, b)=>{\n // 10 6 4\n const ratio = Math.floor(r / (b + 1)); // 1\n let over = r - (b + 1) * ratio; // 1\n let matching = r - over;\n const rbigger = new Array(ratio + 1).fill('R').join('');\n const rsmaller = new Array(ratio).fill('R').join('');\n let result = '';\n\n for (let i = 0; i <= b; i++) {\n if (over) {\n result += rbigger;\n over--;\n } else if (matching) {\n result += rsmaller;\n matching--;\n }\n if (i !== b) {\n result += 'B';\n }\n }\n return result;\n\n\n // const ratio = Math.ceil(r / (b + 1));\n // let bigger = Math.floor(r / ratio);\n // let smaller = ratio > 1 ? Math.round((r - bigger * ratio) / (ratio - 1)) : 0;\n // const rbigger = new Array(ratio).fill('R').join('');\n // const rsmaller = ratio > 1 ? new Array(ratio - 1).fill('R').join('') : '';\n // let result = '';\n // let rb = 0;\n // while (result.length < n) {\n // if (bigger) {\n // result += rbigger;\n // bigger--;\n // } else if (smaller) {\n // result += rsmaller;\n // smaller--;\n // }\n // if (rb + 1 <= b) {\n // result += 'B';\n // rb++;\n // }\n // }\n // return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, r, b] = ra();\n console.log(`${calc(n, r, b)}`);\n }\n}\n\n\n\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nclass Input {\r\n\tconstructor(line) {\r\n\t\tthis.pointer = -1;\r\n\t\tthis.content = [line];\r\n\t}\r\n\tadd(line) {\r\n\t\tthis.content.push(line);\r\n\t}\r\n\tget(line) {\r\n\t\tif (!(this.pointer < this.content.length - 1)) {\r\n\t\t\treturn -1\r\n\t\t}\r\n\t\treturn this.content[++this.pointer];\r\n\t}\r\n}\r\n\r\nconst intify = (arr) => {\r\n\tif (typeof arr == \"string\") {\r\n\t\tlet temp = \"\";\r\n\t\tfor (let i = 0; i < arr.length; i++) {\r\n\t\t\tif (arr[i] != ' ') {\r\n\t\t\t\ttemp += arr[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn parseInt(temp)\r\n\t} else {\r\n\t\treturn arr.map(ele => parseInt(ele))\r\n\t}\r\n}\r\n\r\n\r\nrl.once(\"line\", line => {\r\n\tlet inp = new Input(line);\r\n\trl.on(\"line\", line => {\r\n\t\tinp.add(line)\r\n\t}).on(\"close\", () => {\r\n\r\n\t\tlet t = intify(inp.get())\r\n\t\twhile (t--) {\r\n\t\t\tlet [n, r, b] = intify(inp.get().split(' '))\r\n\t\t\tlet max = Math.ceil(r / (b + 1));\r\n\t\t\tlet min = Math.floor(r / (b + 1));\r\n\t\t\tlet min_str = \"\";\r\n\t\t\twhile (min--) {\r\n\t\t\t\tmin_str += 'R'\r\n\t\t\t}\r\n\t\t\tlet max_count = r % (b + 1)\r\n\t\t\tlet ans = [];\r\n\t\t\tlet r_str = \"\";\r\n\t\t\twhile (max--) {\r\n\t\t\t\tr_str += 'R'\r\n\t\t\t}\r\n\t\t\tfor (let i = 0; i < max_count; i++) {\r\n\t\t\t\tans.push(r_str)\r\n\t\t\t\tans.push('B')\r\n\t\t\t}\r\n\t\t\tfor (let i = 0; i < (b + 1) - max_count - 1; i++) {\r\n\t\t\t\tans.push(min_str)\r\n\t\t\t\tans.push('B')\r\n\t\t\t}\r\n\t\t\tans.push(min_str)\r\n\t\t\tconsole.log(ans.join(''))\r\n\t\t}\r\n\r\n });\r\n});\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, r, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, r, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, r, b) {\n const d = r - b - 1\n const k = Math.floor(d / (b + 1))\n const rest = d % (b + 1)\n //\n const ans = ['R']\n for (let i = 0; i < b; i++) {\n ans[i + 1] = 'BR'\n }\n for (let i = 0; i < b + 1; i++) {\n ans[i] += Array(i < rest ? k + 1 : k).fill('R').join('')\n }\n return ans.join('')\n // const ca = Math.ceil(d / 2)\n // const cb = Math.floor(d / 2)\n // const la = Array(ca).fill('R')\n // const lb = Array(cb).fill('R')\n // return la.concat(ans.concat(lb)).join('')\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, r, b) {\r\n b++;\r\n let m = Math.floor(r / b),\r\n rem = r - m * b;\r\n let res = '';\r\n\r\n for (let i = 0; i < b; i++) {\r\n res += 'R'.repeat(m);\r\n\r\n if (rem > 0) {\r\n rem--;\r\n res += 'R';\r\n }\r\n\r\n if (i < b - 1) res += 'B';\r\n }\r\n\r\n return res;\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, r, b] = inputs[__ + 1].trim().split(' ').map(Number);\r\n\r\n const res = solve(n, r, b);\r\n console.log(res);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n var r = parseInt(casos[1]);\r\n var b = parseInt(casos[2]);\r\n var toret=''\r\n\r\n \r\n while(r>0 || b>0){\r\n var div= Math.floor(r/(b+1));\r\n\r\n for(let j=0; j0){\r\n toret+=\"R\";\r\n r--;\r\n }\r\n }\r\n if(b>0){\r\n toret+=\"B\";\r\n b--;\r\n }\r\n }\r\n console.log(toret)\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const solve = (n,r,b)=>{\r\n let res = \"\";\r\n let p = Math.floor(r/(b+1));\r\n let q = r%(b+1);\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}], "negative_code": [{"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n var r = parseInt(casos[1]);\r\n var b = parseInt(casos[2]);\r\n var toret=''\r\n\r\n \r\n while(r>0 && b>0){\r\n var div= Math.floor(r/(b+1));\r\n\r\n for(let j=0; j0){\r\n toret+=\"R\";\r\n r--;\r\n }\r\n }\r\n if(b>0){\r\n toret+=\"B\";\r\n b--;\r\n }\r\n }\r\n console.log(toret)\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n var r = parseInt(casos[1]);\r\n var b = parseInt(casos[2]);\r\n\r\n \r\n while(r>0 && b>0){\r\n var div= Math.floor(r/(b+1));\r\n\r\n for(let j=0; j0){\r\n console.log(\"R\");\r\n r--;\r\n }\r\n }\r\n if(b>0){\r\n console.log(\"B\");\r\n b--;\r\n }\r\n }\r\n\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n const r = parseInt(casos[1]);\r\n const b = parseInt(casos[2]);\r\n\r\n var ex=0;\r\n while(r>0 && b>0 && ex==0){\r\n var div= Math.floor(r/(b+1));\r\n console.log(div)\r\n ex++;\r\n // for(let j=0; j0){\r\n // r--;\r\n // console.log(\"R\");\r\n // }\r\n // }\r\n // if(b>0){\r\n // console.log(\"B\");\r\n // b--;\r\n // }\r\n }\r\n\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n const r = parseInt(casos[1]);\r\n const b = parseInt(casos[2]);\r\n\r\n var ex=0;\r\n while(r>0 && b>0 && ex==0){\r\n var div= Math.floor(r/b+1);\r\n console.log(div)\r\n ex++;\r\n // for(let j=0; j0){\r\n // r--;\r\n // console.log(\"R\");\r\n // }\r\n // }\r\n // if(b>0){\r\n // console.log(\"B\");\r\n // b--;\r\n // }\r\n }\r\n\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n const numeroCasos = parseInt(readline());\r\n for (let i = 0; i < numeroCasos; i++) {\r\n\r\n const casos= readline().split(\" \");\r\n const n = parseInt(casos[0]);\r\n const r = parseInt(casos[1]);\r\n const b = parseInt(casos[2]);\r\n\r\n\r\n console.log(\"ej\"+n+r+b)\r\n\r\n // while(r>0 && b>0){\r\n // var div= Math.floor(r/b+1);\r\n // for(let j=0; j0){\r\n // r--;\r\n // console.log(\"R\");\r\n // }\r\n // }\r\n // if(b>0){\r\n // console.log(\"B\");\r\n // b--;\r\n // }\r\n // }\r\n\r\n\r\n }\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "const solve = (n,r,b)=>{\r\n let res = \"\";\r\n let regions = b+1,red,red1;\r\n if((r%(regions-1)!==0)&&(r%regions>r%(regions-1))){\r\n red = Math.floor(r/(regions-1));\r\n red1 = r%(regions-1);\r\n regions--;\r\n }\r\n else{\r\n red = Math.floor(r/(regions));\r\n red1 = r%regions;\r\n }\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,r,b)=>{\r\n let res = \"\";\r\n let regions = b+1,red,red1;\r\n if((r%(regions-1)!==0)&&(r%regions>r%(regions-1))){\r\n red = Math.floor(r/(regions-1));\r\n red1 = r%(regions-1);\r\n }\r\n else{\r\n red = Math.floor(r/(regions));\r\n red1 = r%regions;\r\n }\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,r,b)=>{\r\n let res = \"\";\r\n let regions = b+1;\r\n let red = Math.floor(r/regions);\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const calcBluePos = (n,b)=>{\r\n let pos = 2;\r\n while(true){\r\n let t = b*pos;\r\n if(t>n) return pos-1;\r\n if(pos>=n-t) return pos;\r\n pos++;\r\n }\r\n}\r\nconst solve = (n,r,b)=>{\r\n let pos,res=\"\";\r\n if(b===1) pos = Math.floor(n/2)+1;\r\n else pos = calcBluePos(n,b);\r\n let j=pos;\r\n for(let i=0;i0)){\r\n res+=\"B\";\r\n pos = j+pos; \r\n b--;\r\n }\r\n else res+=\"R\";\r\n }\r\n return res;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const calcBluePos = (n,b)=>{\r\n let pos = 2;\r\n while(true){\r\n let t = b*pos;\r\n if(pos>=n-t) return pos;\r\n pos++;\r\n }\r\n}\r\nconst solve = (n,r,b)=>{\r\n let pos,res=\"\";\r\n if(b===1) pos = Math.floor(n/2)+1;\r\n else pos = calcBluePos(n,b);\r\n let j=pos;\r\n for(let i=0;i0)){\r\n res+=\"B\";\r\n pos = j+pos; \r\n b--;\r\n }\r\n else res+=\"R\";\r\n }\r\n return res;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const calcBluePos = (n,b)=>{\r\n let pos = 2;\r\n while(true){\r\n let t = b*pos;\r\n if(pos>n-t) return pos;\r\n pos++;\r\n }\r\n}\r\nconst solve = (n,r,b)=>{\r\n let pos,res=\"\";\r\n if(b===1) pos = Math.floor(n/2)+1;\r\n else pos = calcBluePos(n,b);\r\n let j=pos;\r\n for(let i=0;i0)){\r\n res+=\"B\";\r\n pos = j+pos; \r\n b--;\r\n }\r\n else res+=\"R\";\r\n }\r\n return res;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const calcBluePos = (n,b)=>{\r\n let pos = 2;\r\n while(true){\r\n let t = b*pos;\r\n if(pos>n-t) return pos;\r\n pos++;\r\n }\r\n}\r\nconst solve = (n,r,b)=>{\r\n let pos,res=\"\";\r\n if(b===1) pos = Math.floor(n/2);\r\n else pos = calcBluePos(n,b);\r\n for(let i=0;i0)){\r\n res+=\"B\";\r\n pos+=pos;\r\n b--;\r\n }\r\n else res+=\"R\";\r\n }\r\n return res;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const calcBluePos = (n,b)=>{\r\n let pos = 2;\r\n while(true){\r\n let t = b*pos;\r\n if(pos>n-t) return pos;\r\n pos++;\r\n }\r\n}\r\nconst solve = (n,r,b)=>{\r\n let pos,res=\"\";\r\n if(b===1){\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,r,b));\r\n }\r\n}\r\nmain();"}, {"source_code": "const processData = (lines) => {\n let n = +lines[0];\n for (let i=1; i<=n; i++) {\n let [c, r, b] = lines[i].split(' ').map(Number);\n let res = [];\n let divider = r/b;\n let min = 0;\n\n for (let i=1; i<=r; i++) {\n res.push('R');\n let p = Math.round(i/divider);\n if (p>min && b>0) {\n res.push('B');\n b--;\n }\n min = p;\n }\n console.log(res.join(''));\n }\n \n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n let n = +lines[0];\n for (let i=1; i<=n; i++) {\n let [c, r, b] = lines[i].split(' ').map(Number);\n let res = [];\n let divider = r / (b+1);\n let min = 0;\n\n for (let i=1; i<=r; i++) {\n res.push('R');\n let p = Math.round(i/divider);\n if (p>min && b>0) {\n res.push('B');\n b--;\n }\n min = p;\n }\n console.log(res.join(''));\n }\n \n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, r, b)=>{\n const ratio = Math.ceil(r / (b + 1));\n const rr = new Array(ratio).fill('R').join('');\n let result = '';\n let rc = 0;\n let rb = 0;\n while (result.length < n) {\n if (rc + ratio <= r) {\n result += rr;\n rc += ratio;\n } else {\n result += new Array(r - rc).fill('R').join('');\n rc += r - rc;\n }\n if (rb + 1 <= b) {\n result += 'B';\n rb++;\n }\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, r, b] = ra();\n console.log(`${calc(n, r, b)}`);\n }\n}\n\n\n\n"}], "src_uid": "7cec27879b443ada552a6474c4e45c30"} {"source_code": "var z = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n n = z[0], k = z[1],\n fs = [function (x) {\n return x + 1;\n },\n function (x) {\n return x - 1;\n }],\n r = fs[(k - 1) % 2],\n i, a, b, c, t = [];\n\nfor (i = 0, a = 1, b = n; i < k; i++) {\n t.push(a);\n c = fs[i % 2](a);\n a = b;\n b = c;\n}\nfor (i = k; i < n; i++) {\n t.push(b);\n b = r(b)\n}\n\nprint(t.join(' '));", "positive_code": [{"source_code": "var inp = readline().split(\" \").map(function(x){return parseInt(x);});\nvar n = inp[0];\nvar k = inp[1];\n\nvar sign = true;\nvar res = [];\nfor(var i=0; i < n-k; i++){\n\tres.push(i+1);\n}\nfor(var i=0; i < k; i++){\n\tif (sign){\n\t\tres.push(res[n-k+i-1] + (k-i));\n\t} else {\n\t\tres.push(res[n-k+i-1] - (k-i));\n\t}\n\tsign = !sign;\n}\nvar resS = \"\";\nfor(var i=0; i < n; i++)\n\tresS += res[i] + \" \";\nprint(resS);"}, {"source_code": "var nums = readline().split(' ');\nvar n = parseInt(nums[0]);\nvar k = parseInt(nums[1]);\n\nvar st = 1;\nvar ed = n - 1 ;\nvar h = 0;\nvar res = n;\nwhile(k>1)\n{\n\th = 1-h;\n if(h==1)\n\t{\n\t res = res + ' ' + st;\n\t\tst++;\n\t}\n\telse\n\t{\n\t res = res + ' ' + ed;\n\t\ted --;\n\t}\n\tk--;\n}\nif(h==1)\n{\n for(var i=st; i<=ed; i++)\n\t{\n\t res = res + ' ' + i;\n\t}\n}\nelse\n{\n for(var i=ed; i>=st; i--)\n\t{\n\t res = res + ' ' + i;\n\t}\n}\n\nprint(res);"}], "negative_code": [], "src_uid": "18b3d8f57ecc2b392c7b1708f75a477e"} {"source_code": "var n=+readline();\nvar a=readline().split(' ');\nvar ans=0;\nfor(var i=0; i2){\n\t\tprint(-1);\n\t\tquit();\n\t}\n}\nprint(ans/2);", "positive_code": [{"source_code": "/**\n * @license\n * lodash 4.6.1 (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE\n * Build: `lodash -o ./dist/lodash.js`\n */\n;(function(){function n(n,t){return n.set(t[0],t[1]),n}function t(n,t){return n.add(t),n}function r(n,t,r){switch(r.length){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n,t,r,e){for(var u=-1,o=n.length;++ut&&!o||!u||r&&!i&&f||e&&f)return 1;if(t>n&&!r||!f||o&&!e&&u||i&&u)return-1}return 0}function R(n){return zn[n]}function W(n){return Mn[n]}function B(n){return\"\\\\\"+Fn[n]}function C(n,t,r){\nvar e=n.length;for(t+=r?0:-1;r?t--:++t-1&&0==n%1&&(null==t?9007199254740991:t)>n}function M(n){for(var t,r=[];!(t=n.next()).done;)r.push(t.value);return r}function L(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function $(n,t){for(var r=-1,e=n.length,u=0,o=[];++rr?false:(r==n.length-1?n.pop():Iu.call(n,r,1),true)}function qn(n,t){var r=Tn(n,t);return 0>r?q:n[r][1]}function Tn(n,t){for(var r=n.length;r--;)if(pe(n[r][0],t))return r;return-1}function Kn(n,t,r){var e=Tn(n,t);0>e?n.push([t,r]):n[e][1]=r}function Gn(n,t,r,e){return n===q||pe(n,cu[r])&&!lu.call(e,r)?t:n}function Yn(n,t,r){(r===q||pe(n[t],r))&&(typeof t!=\"number\"||r!==q||t in n)||(n[t]=r);\n}function Hn(n,t,r){var e=n[t];lu.call(n,t)&&pe(e,r)&&(r!==q||t in n)||(n[t]=r)}function Qn(n,t,r,e){return Qu(n,function(n,u,o){t(e,n,r(n),o)}),e}function Xn(n,t){return n&&tr(t,De(t),n)}function nt(n,t){for(var r=-1,e=null==n,u=t.length,o=Array(u);++rr?r:n),t!==q&&(n=t>n?t:n)),n}function ot(n,t,r,e,o,i,f){\nvar c;if(e&&(c=i?e(n,o,i,f):e(n)),c!==q)return c;if(!me(n))return n;if(o=qo(n)){if(c=Br(n),!t)return nr(n,c)}else{var a=Rr(n),l=\"[object Function]\"==a||\"[object GeneratorFunction]\"==a;if(Po(n))return Yt(n,t);if(\"[object Object]\"==a||\"[object Arguments]\"==a||l&&!i){if(U(n))return i?n:{};if(c=Cr(l?{}:n),!t)return c=Xn(c,n),r?er(n,c):c}else{if(!Un[a])return i?n:{};c=Ur(n,a,t)}}return f||(f=new Fn),(i=f.get(n))?i:(f.set(n,c),(o?u:_t)(n,function(u,o){Hn(c,o,ot(u,t,r,e,o,n,f))}),r&&!o?er(n,c):c)}function it(n){\nvar t=De(n),r=t.length;return function(e){if(null==e)return!r;for(var u=r;u--;){var o=t[u],i=n[o],f=e[o];if(f===q&&!(o in Object(e))||!i(f))return false}return true}}function ft(n){return me(n)?Ou(n):{}}function ct(n,t,r){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return Eu(function(){n.apply(q,r)},t)}function at(n,t,r,e){var u=-1,o=f,i=true,l=n.length,s=[],h=t.length;if(!l)return s;r&&(t=a(t,A(r))),e?(o=c,i=false):t.length>=200&&(o=$n,i=false,t=new Ln(t));n:for(;++u0&&de(i)&&(r||qo(i)||ve(i))?t>1?ht(i,t-1,r,e):l(e,i):r||(e[e.length]=i)}return e}function pt(n,t){null==n||no(n,t,Ze)}function _t(n,t){return n&&no(n,t,De)}function vt(n,t){return n&&to(n,t,De);\n}function gt(n,t){return i(t,function(t){return be(n[t])})}function dt(n,t){t=Lr(t,n)?[t+\"\"]:et(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:q}function yt(n,t){return lu.call(n,t)||typeof n==\"object\"&&t in n&&null===mu(n)}function bt(n,t){return t in Object(n)}function xt(n,t,r){for(var e=r?c:f,u=n[0].length,o=n.length,i=o,l=Array(o),s=1/0,h=[];i--;){var p=n[i];i&&t&&(p=a(p,A(t))),s=zu(p.length,s),l[i]=r||!t&&(120>u||120>p.length)?q:new Ln(i&&p)}var p=n[0],_=-1,v=l[0];n:for(;++_h.length;){\nvar g=p[_],d=t?t(g):g;if(v?!$n(v,d):!e(h,d,r)){for(i=o;--i;){var y=l[i];if(y?!$n(y,d):!e(n[i],d,r))continue n}v&&v.push(d),h.push(g)}}return h}function jt(n,t,r){var e={};return _t(n,function(n,u,o){t(e,r(n),u,o)}),e}function mt(n,t,e){return Lr(t,n)||(t=et(t),n=Zr(n,t),t=Vr(t)),t=null==n?n:n[t],null==t?q:r(t,n,e)}function wt(n,t,r,e,u){if(n===t)n=true;else if(null==n||null==t||!me(n)&&!we(t))n=n!==n&&t!==t;else n:{var o=qo(n),i=qo(t),f=\"[object Array]\",c=\"[object Array]\";o||(f=Rr(n),f=\"[object Arguments]\"==f?\"[object Object]\":f),\ni||(c=Rr(t),c=\"[object Arguments]\"==c?\"[object Object]\":c);var a=\"[object Object]\"==f&&!U(n),i=\"[object Object]\"==c&&!U(t);if((c=f==c)&&!a)u||(u=new Fn),n=o||Re(n)?wr(n,t,wt,r,e,u):Ar(n,t,f,wt,r,e,u);else{if(!(2&e)&&(o=a&&lu.call(n,\"__wrapped__\"),f=i&&lu.call(t,\"__wrapped__\"),o||f)){u||(u=new Fn),n=wt(o?n.value():n,f?t.value():t,r,e,u);break n}if(c)t:if(u||(u=new Fn),o=2&e,f=De(n),i=f.length,c=De(t).length,i==c||o){for(a=i;a--;){var l=f[a];if(!(o?l in t:yt(t,l))){n=false;break t}}if(c=u.get(n))n=c==t;else{\nc=true,u.set(n,t);for(var s=o;++ae?c*(\"desc\"==r[e]?-1:1):c;break n}}e=n.b-t.b}return e})}function Bt(n,t){return n=Object(n),s(t,function(t,r){return r in n&&(t[r]=n[r]),\nt},{})}function Ct(n,t){var r={};return pt(n,function(n,e){t(n,e)&&(r[e]=n)}),r}function Ut(n){return function(t){return null==t?q:t[n]}}function zt(n){return function(t){return dt(t,n)}}function Mt(n,t,r,e){var u=e?y:d,o=-1,i=t.length,f=n;for(r&&(f=a(n,A(r)));++ot&&(t=-t>u?0:u+t),r=r>u?u:r,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=Array(u);++e=u){for(;u>e;){var o=e+u>>>1,i=n[o];(r?t>=i:t>i)&&null!==i?e=o+1:u=o}return u}return qt(n,t,Ye,r)}function qt(n,t,r,e){t=r(t);for(var u=0,o=n?n.length:0,i=t!==t,f=null===t,c=t===q;o>u;){var a=Ru((u+o)/2),l=r(n[a]),s=l!==q,h=l===l;(i?h||e:f?h&&s&&(e||null!=l):c?h&&(e||s):null==l?0:e?t>=l:t>l)?u=a+1:o=a}return zu(o,4294967294)}function Pt(n,t){for(var r=0,e=n.length,u=n[0],o=t?t(u):u,i=o,f=1,c=[u];++re?t[e]:q);return i}function Yt(n,t){if(t)return n.slice();var r=new n.constructor(n.length);return n.copy(r),r}function Ht(n){var t=new n.constructor(n.byteLength);return new bu(t).set(new bu(n)),\nt}function Qt(n,t,r,e){var u=-1,o=n.length,i=r.length,f=-1,c=t.length,a=Uu(o-i,0),l=Array(c+a);for(e=!e;++fu)&&(l[r[u]]=n[u]);for(;a--;)l[f++]=n[u++];return l}function Xt(n,t,r,e){var u=-1,o=n.length,i=-1,f=r.length,c=-1,a=t.length,l=Uu(o-f,0),s=Array(l+a);for(e=!e;++uu)&&(s[l+r[i]]=n[u++]);return s}function nr(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r1?r[u-1]:q,i=u>2?r[2]:q,o=typeof o==\"function\"?(u--,o):q;for(i&&Mr(r[0],r[1],i)&&(o=3>u?q:o,u=1),t=Object(t);++ei&&f[0]!==a&&f[i-1]!==a?[]:$(f,a),i-=c.length,e>i?xr(n,t,_r,u.placeholder,q,f,c,q,q,e-i):r(this&&this!==Vn&&this instanceof u?o:n,this,f)}var o=sr(n);return u}function pr(n){return he(function(t){t=ht(t,1);var r=t.length,e=r,u=An.prototype.thru;for(n&&t.reverse();e--;){var o=t[e];if(typeof o!=\"function\")throw new iu(\"Expected a function\");if(u&&!i&&\"wrapper\"==Or(o))var i=new An([],true)}for(e=i?e:r;++e=200)return i.plant(e).value();for(var u=0,n=r?t[u].apply(this,n):e;++ud)return j=$(b,j),xr(n,t,_r,l.placeholder,r,b,j,f,c,a-d);if(j=h?r:this,y=p?j[n]:n,d=b.length,f){x=b.length;\nfor(var m=zu(f.length,x),w=nr(b);m--;){var A=f[m];b[m]=z(A,x)?w[A]:q}}else v&&d>1&&b.reverse();return s&&d>c&&(b.length=c),this&&this!==Vn&&this instanceof l&&(y=g||sr(y)),y.apply(j,b)}var s=128&t,h=1&t,p=2&t,_=24&t,v=512&t,g=p?q:sr(n);return l}function vr(n,t){return function(r,e){return jt(r,n,t(e))}}function gr(n){return he(function(t){return t=a(ht(t,1),kr()),he(function(e){var u=this;return n(t,function(n){return r(n,u,e)})})})}function dr(n,t,r){return t=Ce(t),n=N(n),t&&t>n?(t-=n,r=r===q?\" \":r+\"\",\nn=Ge(r,Su(t/N(r))),In.test(r)?n.match(En).slice(0,t).join(\"\"):n.slice(0,t)):\"\"}function yr(n,t,e,u){function o(){for(var t=-1,c=arguments.length,a=-1,l=u.length,s=Array(l+c),h=this&&this!==Vn&&this instanceof o?f:n;++at?1:-1:ze(e)||0;var u=-1;r=Uu(Su((r-t)/(e||1)),0);for(var o=Array(r);r--;)o[n?r:++u]=t,\nt+=e;return o}}function xr(n,t,r,e,u,o,i,f,c,a){var l=8&t;f=f?nr(f):q;var s=l?i:q;i=l?q:i;var h=l?o:q;return o=l?q:o,t=(t|(l?32:64))&~(l?64:32),4&t||(t&=-4),t=[n,t,u,h,s,o,i,f,c,a],r=r.apply(q,t),Fr(n)&&fo(r,t),r.placeholder=e,r}function jr(n){var t=uu[n];return function(n,r){if(n=ze(n),r=Ce(r)){var e=(Le(n)+\"e\").split(\"e\"),e=t(e[0]+\"e\"+(+e[1]+r)),e=(Le(e)+\"e\").split(\"e\");return+(e[0]+\"e\"+(+e[1]-r))}return t(n)}}function mr(n,t,r,e,u,o,i,f){var c=2&t;if(!c&&typeof n!=\"function\")throw new iu(\"Expected a function\");\nvar a=e?e.length:0;if(a||(t&=-97,e=u=q),i=i===q?i:Uu(Ce(i),0),f=f===q?f:Ce(f),a-=u?u.length:0,64&t){var l=e,s=u;e=u=q}var h=c?q:uo(n);return o=[n,t,r,e,u,l,s,o,i,f],h&&(r=o[1],n=h[1],t=r|n,e=128==n&&8==r||128==n&&256==r&&h[8]>=o[7].length||384==n&&h[8]>=h[7].length&&8==r,131>t||e)&&(1&n&&(o[2]=h[2],t|=1&r?0:4),(r=h[3])&&(e=o[3],o[3]=e?Qt(e,r,h[4]):nr(r),o[4]=e?$(o[3],\"__lodash_placeholder__\"):nr(h[4])),(r=h[5])&&(e=o[5],o[5]=e?Xt(e,r,h[6]):nr(r),o[6]=e?$(o[5],\"__lodash_placeholder__\"):nr(h[6])),(r=h[7])&&(o[7]=nr(r)),\n128&n&&(o[8]=null==o[8]?h[8]:zu(o[8],h[8])),null==o[9]&&(o[9]=h[9]),o[0]=h[0],o[1]=t),n=o[0],t=o[1],r=o[2],e=o[3],u=o[4],f=o[9]=null==o[9]?c?0:n.length:Uu(o[9]-a,0),!f&&24&t&&(t&=-25),(h?ro:fo)(t&&1!=t?8==t||16==t?hr(n,t,f):32!=t&&33!=t||u.length?_r.apply(q,o):yr(n,t,r,e):cr(n,t,r),o)}function wr(n,t,r,e,u,o){var i=-1,f=2&u,c=1&u,a=n.length,l=t.length;if(!(a==l||f&&l>a))return false;if(l=o.get(n))return l==t;for(l=true,o.set(n,t);++it?0:t,e)):[]}function Kr(n,t,r){var e=n?n.length:0;\nreturn e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0,0>t?0:t)):[]}function Gr(n){return n?n[0]:q}function Vr(n){var t=n?n.length:0;return t?n[t-1]:q}function Jr(n,t){return n&&n.length&&t&&t.length?Mt(n,t):n}function Yr(n){return n?$u.call(n):n}function Hr(n){if(!n||!n.length)return[];var t=0;return n=i(n,function(n){return de(n)?(t=Uu(n.length,t),true):void 0}),m(t,function(t){return a(n,Ut(t))})}function Qr(n,t){if(!n||!n.length)return[];var e=Hr(n);return null==t?e:a(e,function(n){return r(t,q,n)})}function Xr(n){\nreturn n=bn(n),n.__chain__=true,n}function ne(n,t){return t(n)}function te(){return this}function re(n,t){return typeof t==\"function\"&&qo(n)?u(n,t):Qu(n,rt(t))}function ee(n,t){var r;if(typeof t==\"function\"&&qo(n)){for(r=n.length;r--&&false!==t(n[r],r,n););r=n}else r=Xu(n,rt(t));return r}function ue(n,t){return(qo(n)?a:Et)(n,kr(t,3))}function oe(n,t){var r=-1,e=Be(n),u=e.length,o=u-1;for(t=ut(Ce(t),0,u);++r=n&&(t=q),r}}function ce(n,t,r){return t=r?q:t,n=mr(n,8,q,q,q,q,q,t),n.placeholder=ce.placeholder,n}function ae(n,t,r){return t=r?q:t,n=mr(n,16,q,q,q,q,q,t),n.placeholder=ae.placeholder,n}function le(n,t,r){function e(){p&&xu(p),a&&xu(a),v=0,c=a=h=p=_=q}function u(t,r){r&&xu(r),a=p=_=q,t&&(v=Uo(),l=n.apply(h,c),\np||a||(c=h=q))}function o(){var n=t-(Uo()-s);0>=n||n>t?u(_,a):p=Eu(o,n)}function i(){u(y,p)}function f(){if(c=arguments,s=Uo(),h=this,_=y&&(p||!g),false===d)var r=g&&!p;else{v||a||g||(v=s);var e=d-(s-v),u=(0>=e||e>d)&&(g||a);u?(a&&(a=xu(a)),v=s,l=n.apply(h,c)):a||(a=Eu(i,e))}return u&&p?p=xu(p):p||t===d||(p=Eu(o,t)),r&&(u=true,l=n.apply(h,c)),!u||p||a||(c=h=q),l}var c,a,l,s,h,p,_,v=0,g=false,d=false,y=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=ze(t)||0,me(r)&&(g=!!r.leading,d=\"maxWait\"in r&&Uu(ze(r.maxWait)||0,t),\ny=\"trailing\"in r?!!r.trailing:y),f.cancel=e,f.flush=function(){return(p&&_||a&&y)&&(l=n.apply(h,c)),e(),l},f}function se(n,t){function r(){var e=arguments,u=t?t.apply(this,e):e[0],o=r.cache;return o.has(u)?o.get(u):(e=n.apply(this,e),r.cache=o.set(u,e),e)}if(typeof n!=\"function\"||t&&typeof t!=\"function\")throw new iu(\"Expected a function\");return r.cache=new se.Cache,r}function he(n,t){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=Uu(t===q?n.length-1:Ce(t),0),function(){for(var e=arguments,u=-1,o=Uu(e.length-t,0),i=Array(o);++ut}function ve(n){return de(n)&&lu.call(n,\"callee\")&&(!ku.call(n,\"callee\")||\"[object Arguments]\"==pu.call(n))}function ge(n){return null!=n&&je(oo(n))&&!be(n)}function de(n){return we(n)&&ge(n)}function ye(n){return we(n)?\"[object Error]\"==pu.call(n)||typeof n.message==\"string\"&&typeof n.name==\"string\":false;\n}function be(n){return n=me(n)?pu.call(n):\"\",\"[object Function]\"==n||\"[object GeneratorFunction]\"==n}function xe(n){return typeof n==\"number\"&&n==Ce(n)}function je(n){return typeof n==\"number\"&&n>-1&&0==n%1&&9007199254740991>=n}function me(n){var t=typeof n;return!!n&&(\"object\"==t||\"function\"==t)}function we(n){return!!n&&typeof n==\"object\"}function Ae(n){return null==n?false:be(n)?vu.test(au.call(n)):we(n)&&(U(n)?vu:dn).test(n)}function Oe(n){return typeof n==\"number\"||we(n)&&\"[object Number]\"==pu.call(n);\n}function ke(n){return!we(n)||\"[object Object]\"!=pu.call(n)||U(n)?false:(n=mu(n),null===n?true:(n=n.constructor,typeof n==\"function\"&&n instanceof n&&au.call(n)==hu))}function Ee(n){return me(n)&&\"[object RegExp]\"==pu.call(n)}function Ie(n){return typeof n==\"string\"||!qo(n)&&we(n)&&\"[object String]\"==pu.call(n)}function Se(n){return typeof n==\"symbol\"||we(n)&&\"[object Symbol]\"==pu.call(n)}function Re(n){return we(n)&&je(n.length)&&!!Cn[pu.call(n)]}function We(n,t){return t>n}function Be(n){if(!n)return[];\nif(ge(n))return Ie(n)?n.match(En):nr(n);if(Au&&n[Au])return M(n[Au]());var t=Rr(n);return(\"[object Map]\"==t?L:\"[object Set]\"==t?F:Pe)(n)}function Ce(n){if(!n)return 0===n?n:0;if(n=ze(n),n===P||n===-P)return 1.7976931348623157e308*(0>n?-1:1);var t=n%1;return n===n?t?n-t:n:0}function Ue(n){return n?ut(Ce(n),0,4294967295):0}function ze(n){if(me(n)&&(n=be(n.valueOf)?n.valueOf():n,n=me(n)?n+\"\":n),typeof n!=\"string\")return 0===n?n:+n;n=n.replace(cn,\"\");var t=gn.test(n);return t||yn.test(n)?Dn(n.slice(2),t?2:8):vn.test(n)?T:+n;\n}function Me(n){return tr(n,Ze(n))}function Le(n){if(typeof n==\"string\")return n;if(null==n)return\"\";if(Se(n))return Hu?Hu.call(n):\"\";var t=n+\"\";return\"0\"==t&&1/n==-P?\"-0\":t}function $e(n,t,r){return n=null==n?q:dt(n,t),n===q?r:n}function Fe(n,t){return Wr(n,t,yt)}function Ne(n,t){return Wr(n,t,bt)}function De(n){var t=Nr(n);if(!t&&!ge(n))return Cu(Object(n));var r,e=zr(n),u=!!e,e=e||[],o=e.length;for(r in n)!yt(n,r)||u&&(\"length\"==r||z(r,o))||t&&\"constructor\"==r||e.push(r);return e}function Ze(n){\nfor(var t=-1,r=Nr(n),e=kt(n),u=e.length,o=zr(n),i=!!o,o=o||[],f=o.length;++tt||t>9007199254740991)return r;do t%2&&(r+=n),t=Ru(t/2),n+=n;while(t);return r}function Ve(n,t,r){\nreturn n=Le(n),t=r?q:t,t===q&&(t=Wn.test(n)?Rn:Sn),n.match(t)||[]}function Je(n){return function(){return n}}function Ye(n){return n}function He(n){return Ot(typeof n==\"function\"?n:ot(n,true))}function Qe(n,t,r){var e=De(t),o=gt(t,e);null!=r||me(t)&&(o.length||!e.length)||(r=t,t=n,n=this,o=gt(t,De(t)));var i=me(r)&&\"chain\"in r?r.chain:true,f=be(n);return u(o,function(r){var e=t[r];n[r]=e,f&&(n.prototype[r]=function(){var t=this.__chain__;if(i||t){var r=n(this.__wrapped__);return(r.__actions__=nr(this.__actions__)).push({\nfunc:e,args:arguments,thisArg:n}),r.__chain__=t,r}return e.apply(n,l([this.value()],arguments))})}),n}function Xe(){}function nu(n){return Lr(n)?Ut(n):zt(n)}function tu(n){return n&&n.length?j(n,Ye):0}I=I?Jn.defaults({},I,Jn.pick(Vn,Bn)):Vn;var ru=I.Date,eu=I.Error,uu=I.Math,ou=I.RegExp,iu=I.TypeError,fu=I.Array.prototype,cu=I.Object.prototype,au=I.Function.prototype.toString,lu=cu.hasOwnProperty,su=0,hu=au.call(Object),pu=cu.toString,_u=Vn._,vu=ou(\"^\"+au.call(lu).replace(on,\"\\\\$&\").replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g,\"$1.*?\")+\"$\"),gu=Pn?I.Buffer:q,du=I.Reflect,yu=I.Symbol,bu=I.Uint8Array,xu=I.clearTimeout,ju=du?du.f:q,mu=Object.getPrototypeOf,wu=Object.getOwnPropertySymbols,Au=typeof(Au=yu&&yu.iterator)==\"symbol\"?Au:q,Ou=Object.create,ku=cu.propertyIsEnumerable,Eu=I.setTimeout,Iu=fu.splice,Su=uu.ceil,Ru=uu.floor,Wu=I.isFinite,Bu=fu.join,Cu=Object.keys,Uu=uu.max,zu=uu.min,Mu=I.parseInt,Lu=uu.random,$u=fu.reverse,Fu=Ir(I,\"Map\"),Nu=Ir(I,\"Set\"),Du=Ir(I,\"WeakMap\"),Zu=Ir(Object,\"create\"),qu=Du&&new Du,Pu=!ku.call({\nvalueOf:1},\"valueOf\"),Tu={},Ku=Fu?au.call(Fu):\"\",Gu=Nu?au.call(Nu):\"\",Vu=Du?au.call(Du):\"\",Ju=yu?yu.prototype:q,Yu=Ju?Ju.valueOf:q,Hu=Ju?Ju.toString:q;bn.templateSettings={escape:X,evaluate:nn,interpolate:tn,variable:\"\",imports:{_:bn}};var Qu=ir(_t),Xu=ir(vt,true),no=fr(),to=fr(true);ju&&!ku.call({valueOf:1},\"valueOf\")&&(kt=function(n){return M(ju(n))});var ro=qu?function(n,t){return qu.set(n,t),n}:Ye,eo=Nu&&2===new Nu([1,2]).size?function(n){return new Nu(n)}:Xe,uo=qu?function(n){return qu.get(n)}:Xe,oo=Ut(\"length\"),io=wu||function(){\nreturn[]};(Fu&&\"[object Map]\"!=Rr(new Fu)||Nu&&\"[object Set]\"!=Rr(new Nu)||Du&&\"[object WeakMap]\"!=Rr(new Du))&&(Rr=function(n){var t=pu.call(n);if(n=\"[object Object]\"==t?n.constructor:null,n=typeof n==\"function\"?au.call(n):\"\")switch(n){case Ku:return\"[object Map]\";case Gu:return\"[object Set]\";case Vu:return\"[object WeakMap]\"}return t});var fo=function(){var n=0,t=0;return function(r,e){var u=Uo(),o=16-(u-t);if(t=u,o>0){if(150<=++n)return r}else n=0;return ro(r,e)}}(),co=he(function(n,t){qo(n)||(n=null==n?[]:[Object(n)]),\nt=ht(t,1);for(var r=n,e=t,u=-1,o=r.length,i=-1,f=e.length,c=Array(o+f);++u1?n[t-1]:q,t=typeof t==\"function\"?(n.pop(),t):q;return Qr(n,t)}),Eo=he(function(n){function t(t){return nt(t,n)}n=ht(n,1);var r=n.length,e=r?n[0]:0,u=this.__wrapped__;return 1>=r&&!this.__actions__.length&&u instanceof On&&z(e)?(u=u.slice(e,+e+(r?1:0)),u.__actions__.push({func:ne,args:[t],thisArg:q}),new An(u,this.__chain__).thru(function(n){return r&&!n.length&&n.push(q),\nn})):this.thru(t)}),Io=ur(function(n,t,r){lu.call(n,r)?++n[r]:n[r]=1}),So=ur(function(n,t,r){lu.call(n,r)?n[r].push(t):n[r]=[t]}),Ro=he(function(n,t,e){var u=-1,o=typeof t==\"function\",i=Lr(t),f=ge(n)?Array(n.length):[];return Qu(n,function(n){var c=o?t:i&&null!=n?n[t]:q;f[++u]=c?r(c,n,e):mt(n,t,e)}),f}),Wo=ur(function(n,t,r){n[r]=t}),Bo=ur(function(n,t,r){n[r?0:1].push(t)},function(){return[[],[]]}),Co=he(function(n,t){if(null==n)return[];var r=t.length;return r>1&&Mr(n,t[0],t[1])?t=[]:r>2&&Mr(t[0],t[1],t[2])&&(t.length=1),\nWt(n,ht(t,1),[])}),Uo=ru.now,zo=he(function(n,t,r){var e=1;if(r.length)var u=$(r,Sr(zo)),e=32|e;return mr(n,e,t,r,u)}),Mo=he(function(n,t,r){var e=3;if(r.length)var u=$(r,Sr(Mo)),e=32|e;return mr(t,e,n,r,u)}),Lo=he(function(n,t){return ct(n,1,t)}),$o=he(function(n,t,r){return ct(n,ze(t)||0,r)}),Fo=he(function(n,t){t=a(ht(t,1),kr());var e=t.length;return he(function(u){for(var o=-1,i=zu(u.length,e);++oe.length?Kn(e,n,t):(r.array=null,r.map=new Mn(e))),(r=r.map)&&r.set(n,t),this},se.Cache=Mn,bn.after=function(n,t){if(typeof t!=\"function\")throw new iu(\"Expected a function\");return n=Ce(n),function(){return 1>--n?t.apply(this,arguments):void 0}},bn.ary=ie,bn.assign=To,bn.assignIn=Ko,\nbn.assignInWith=Go,bn.assignWith=Vo,bn.at=Jo,bn.before=fe,bn.bind=zo,bn.bindAll=_i,bn.bindKey=Mo,bn.castArray=function(){if(!arguments.length)return[];var n=arguments[0];return qo(n)?n:[n]},bn.chain=Xr,bn.chunk=function(n,t){t=Uu(Ce(t),0);var r=n?n.length:0;if(!r||1>t)return[];for(var e=0,u=0,o=Array(Su(r/t));r>e;)o[u++]=Nt(n,e,e+=t);return o},bn.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++tr&&(r=-r>u?0:u+r),e=e===q||e>u?u:Ce(e),0>e&&(e+=u),e=r>e?0:Ue(e);e>r;)n[r++]=t;return n},bn.filter=function(n,t){return(qo(n)?i:st)(n,kr(t,3))},bn.flatMap=function(n,t){return ht(ue(n,t),1)},bn.flatten=function(n){\nreturn n&&n.length?ht(n,1):[]},bn.flattenDeep=function(n){return n&&n.length?ht(n,P):[]},bn.flattenDepth=function(n,t){return n&&n.length?(t=t===q?1:Ce(t),ht(n,t)):[]},bn.flip=function(n){return mr(n,512)},bn.flow=vi,bn.flowRight=gi,bn.fromPairs=function(n){for(var t=-1,r=n?n.length:0,e={};++tt?0:t)):[]},bn.takeRight=function(n,t,r){var e=n?n.length:0;return e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0>t?0:t,e)):[]},bn.takeRightWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3),false,true):[]},bn.takeWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3)):[]},bn.tap=function(n,t){return t(n),n},bn.throttle=function(n,t,r){var e=true,u=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return me(r)&&(e=\"leading\"in r?!!r.leading:e,u=\"trailing\"in r?!!r.trailing:u),le(n,t,{leading:e,maxWait:t,\ntrailing:u})},bn.thru=ne,bn.toArray=Be,bn.toPairs=qe,bn.toPairsIn=function(n){return w(n,Ze(n))},bn.toPath=function(n){return qo(n)?a(n,String):qr(n)},bn.toPlainObject=Me,bn.transform=function(n,t,r){var e=qo(n)||Re(n);if(t=kr(t,4),null==r)if(e||me(n)){var o=n.constructor;r=e?qo(n)?new o:[]:be(o)?ft(mu(n)):{}}else r={};return(e?u:_t)(n,function(n,e,u){return t(r,n,e,u)}),r},bn.unary=function(n){return ie(n,1)},bn.union=yo,bn.unionBy=bo,bn.unionWith=xo,bn.uniq=function(n){return n&&n.length?Tt(n):[];\n},bn.uniqBy=function(n,t){return n&&n.length?Tt(n,kr(t)):[]},bn.uniqWith=function(n,t){return n&&n.length?Tt(n,q,t):[]},bn.unset=function(n,t){var r;if(null==n)r=true;else{r=n;var e=t,e=Lr(e,r)?[e+\"\"]:et(e);r=Zr(r,e),e=Vr(e),r=null!=r&&Fe(r,e)?delete r[e]:true}return r},bn.unzip=Hr,bn.unzipWith=Qr,bn.update=function(n,t,r){return null==n?n:Ft(n,t,rt(r)(dt(n,t)),void 0)},bn.updateWith=function(n,t,r,e){return e=typeof e==\"function\"?e:q,null!=n&&(n=Ft(n,t,rt(r)(dt(n,t)),e)),n},bn.values=Pe,bn.valuesIn=function(n){\nreturn null==n?[]:O(n,Ze(n))},bn.without=jo,bn.words=Ve,bn.wrap=function(n,t){return t=null==t?Ye:t,No(t,n)},bn.xor=mo,bn.xorBy=wo,bn.xorWith=Ao,bn.zip=Oo,bn.zipObject=function(n,t){return Jt(n||[],t||[],Hn)},bn.zipObjectDeep=function(n,t){return Jt(n||[],t||[],Ft)},bn.zipWith=ko,bn.extend=Ko,bn.extendWith=Go,Qe(bn,bn),bn.add=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r+t),r)},bn.attempt=pi,bn.camelCase=oi,bn.capitalize=Te,bn.ceil=Ai,bn.clamp=function(n,t,r){return r===q&&(r=t,\nt=q),r!==q&&(r=ze(r),r=r===r?r:0),t!==q&&(t=ze(t),t=t===t?t:0),ut(ze(n),t,r)},bn.clone=function(n){return ot(n,false,true)},bn.cloneDeep=function(n){return ot(n,true,true)},bn.cloneDeepWith=function(n,t){return ot(n,true,true,t)},bn.cloneWith=function(n,t){return ot(n,false,true,t)},bn.deburr=Ke,bn.endsWith=function(n,t,r){n=Le(n),t=typeof t==\"string\"?t:t+\"\";var e=n.length;return r=r===q?e:ut(Ce(r),0,e),r-=t.length,r>=0&&n.indexOf(t,r)==r},bn.eq=pe,bn.escape=function(n){return(n=Le(n))&&Q.test(n)?n.replace(Y,W):n},\nbn.escapeRegExp=function(n){return(n=Le(n))&&fn.test(n)?n.replace(on,\"\\\\$&\"):n},bn.every=function(n,t,r){var e=qo(n)?o:lt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.find=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t);return r>-1?n[r]:q}return v(n,t,Qu)},bn.findIndex=function(n,t){return n&&n.length?g(n,kr(t,3)):-1},bn.findKey=function(n,t){return v(n,kr(t,3),_t,true)},bn.findLast=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t,true);return r>-1?n[r]:q}return v(n,t,Xu)},bn.findLastIndex=function(n,t){return n&&n.length?g(n,kr(t,3),true):-1;\n},bn.findLastKey=function(n,t){return v(n,kr(t,3),vt,true)},bn.floor=Oi,bn.forEach=re,bn.forEachRight=ee,bn.forIn=function(n,t){return null==n?n:no(n,rt(t),Ze)},bn.forInRight=function(n,t){return null==n?n:to(n,rt(t),Ze)},bn.forOwn=function(n,t){return n&&_t(n,rt(t))},bn.forOwnRight=function(n,t){return n&&vt(n,rt(t))},bn.get=$e,bn.gt=_e,bn.gte=function(n,t){return n>=t},bn.has=Fe,bn.hasIn=Ne,bn.head=Gr,bn.identity=Ye,bn.includes=function(n,t,r,e){return n=ge(n)?n:Pe(n),r=r&&!e?Ce(r):0,e=n.length,0>r&&(r=Uu(e+r,0)),\nIe(n)?e>=r&&-1r&&(r=Uu(e+r,0)),d(n,t,r)):-1},bn.inRange=function(n,t,r){return t=ze(t)||0,r===q?(r=t,t=0):r=ze(r)||0,n=ze(n),n>=zu(t,r)&&n=-9007199254740991&&9007199254740991>=n;\n},bn.isSet=function(n){return we(n)&&\"[object Set]\"==Rr(n)},bn.isString=Ie,bn.isSymbol=Se,bn.isTypedArray=Re,bn.isUndefined=function(n){return n===q},bn.isWeakMap=function(n){return we(n)&&\"[object WeakMap]\"==Rr(n)},bn.isWeakSet=function(n){return we(n)&&\"[object WeakSet]\"==pu.call(n)},bn.join=function(n,t){return n?Bu.call(n,t):\"\"},bn.kebabCase=ii,bn.last=Vr,bn.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(r!==q&&(u=Ce(r),u=(0>u?Uu(e+u,0):zu(u,e-1))+1),t!==t)return C(n,u,true);\nfor(;u--;)if(n[u]===t)return u;return-1},bn.lowerCase=fi,bn.lowerFirst=ci,bn.lt=We,bn.lte=function(n,t){return t>=n},bn.max=function(n){return n&&n.length?_(n,Ye,_e):q},bn.maxBy=function(n,t){return n&&n.length?_(n,kr(t),_e):q},bn.mean=function(n){return tu(n)/(n?n.length:0)},bn.min=function(n){return n&&n.length?_(n,Ye,We):q},bn.minBy=function(n,t){return n&&n.length?_(n,kr(t),We):q},bn.noConflict=function(){return Vn._===this&&(Vn._=_u),this},bn.noop=Xe,bn.now=Uo,bn.pad=function(n,t,r){n=Le(n),\nt=Ce(t);var e=N(n);return t&&t>e?(e=(t-e)/2,t=Ru(e),e=Su(e),dr(\"\",t,r)+n+dr(\"\",e,r)):n},bn.padEnd=function(n,t,r){return n=Le(n),n+dr(n,t,r)},bn.padStart=function(n,t,r){return n=Le(n),dr(n,t,r)+n},bn.parseInt=function(n,t,r){return r||null==t?t=0:t&&(t=+t),n=Le(n).replace(cn,\"\"),Mu(n,t||(_n.test(n)?16:10))},bn.random=function(n,t,r){if(r&&typeof r!=\"boolean\"&&Mr(n,t,r)&&(t=r=q),r===q&&(typeof t==\"boolean\"?(r=t,t=q):typeof n==\"boolean\"&&(r=n,n=q)),n===q&&t===q?(n=0,t=1):(n=ze(n)||0,t===q?(t=n,n=0):t=ze(t)||0),\nn>t){var e=n;n=t,t=e}return r||n%1||t%1?(r=Lu(),zu(n+r*(t-n+Nn(\"1e-\"+((r+\"\").length-1))),t)):$t(n,t)},bn.reduce=function(n,t,r){var e=qo(n)?s:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Qu)},bn.reduceRight=function(n,t,r){var e=qo(n)?h:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Xu)},bn.repeat=Ge,bn.replace=function(){var n=arguments,t=Le(n[0]);return 3>n.length?t:t.replace(n[1],n[2])},bn.result=function(n,t,r){if(Lr(t,n))e=null==n?q:n[t];else{t=et(t);var e=$e(n,t);n=Zr(n,t)}return e===q&&(e=r),\nbe(e)?e.call(n):e},bn.round=ki,bn.runInContext=Z,bn.sample=function(n){n=ge(n)?n:Pe(n);var t=n.length;return t>0?n[$t(0,t-1)]:q},bn.size=function(n){if(null==n)return 0;if(ge(n)){var t=n.length;return t&&Ie(n)?N(n):t}return De(n).length},bn.snakeCase=li,bn.some=function(n,t,r){var e=qo(n)?p:Dt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.sortedIndex=function(n,t){return Zt(n,t)},bn.sortedIndexBy=function(n,t,r){return qt(n,t,kr(r))},bn.sortedIndexOf=function(n,t){var r=n?n.length:0;if(r){var e=Zt(n,t);\nif(r>e&&pe(n[e],t))return e}return-1},bn.sortedLastIndex=function(n,t){return Zt(n,t,true)},bn.sortedLastIndexBy=function(n,t,r){return qt(n,t,kr(r),true)},bn.sortedLastIndexOf=function(n,t){if(n&&n.length){var r=Zt(n,t,true)-1;if(pe(n[r],t))return r}return-1},bn.startCase=si,bn.startsWith=function(n,t,r){return n=Le(n),r=ut(Ce(r),0,n.length),n.lastIndexOf(t,r)==r},bn.subtract=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r-t),r)},bn.sum=tu,bn.sumBy=function(n,t){return n&&n.length?j(n,kr(t)):0;\n},bn.template=function(n,t,r){var e=bn.templateSettings;r&&Mr(n,t,r)&&(t=q),n=Le(n),t=Go({},t,e,Gn),r=Go({},t.imports,e.imports,Gn);var u,o,i=De(r),f=O(r,i),c=0;r=t.interpolate||jn;var a=\"__p+='\";r=ou((t.escape||jn).source+\"|\"+r.source+\"|\"+(r===tn?hn:jn).source+\"|\"+(t.evaluate||jn).source+\"|$\",\"g\");var l=\"sourceURL\"in t?\"//# sourceURL=\"+t.sourceURL+\"\\n\":\"\";if(n.replace(r,function(t,r,e,i,f,l){return e||(e=i),a+=n.slice(c,l).replace(mn,B),r&&(u=true,a+=\"'+__e(\"+r+\")+'\"),f&&(o=true,a+=\"';\"+f+\";\\n__p+='\"),\ne&&(a+=\"'+((__t=(\"+e+\"))==null?'':__t)+'\"),c=l+t.length,t}),a+=\"';\",(t=t.variable)||(a=\"with(obj){\"+a+\"}\"),a=(o?a.replace(K,\"\"):a).replace(G,\"$1\").replace(V,\"$1;\"),a=\"function(\"+(t||\"obj\")+\"){\"+(t?\"\":\"obj||(obj={});\")+\"var __t,__p=''\"+(u?\",__e=_.escape\":\"\")+(o?\",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}\":\";\")+a+\"return __p}\",t=pi(function(){return Function(i,l+\"return \"+a).apply(q,f)}),t.source=a,ye(t))throw t;return t},bn.times=function(n,t){if(n=Ce(n),1>n||n>9007199254740991)return[];\nvar r=4294967295,e=zu(n,4294967295);for(t=rt(t),n-=4294967295,e=m(e,t);++r=o)return n;if(o=r-N(e),1>o)return e;\nif(r=i?i.slice(0,o).join(\"\"):n.slice(0,o),u===q)return r+e;if(i&&(o+=r.length-o),Ee(u)){if(n.slice(o).search(u)){var f=r;for(u.global||(u=ou(u.source,Le(pn.exec(u))+\"g\")),u.lastIndex=0;i=u.exec(f);)var c=i.index;r=r.slice(0,c===q?o:c)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),u>-1&&(r=r.slice(0,u)));return r+e},bn.unescape=function(n){return(n=Le(n))&&H.test(n)?n.replace(J,D):n},bn.uniqueId=function(n){var t=++su;return Le(n)+t},bn.upperCase=hi,bn.upperFirst=ai,bn.each=re,bn.eachRight=ee,bn.first=Gr,\nQe(bn,function(){var n={};return _t(bn,function(t,r){lu.call(bn.prototype,r)||(n[r]=t)}),n}(),{chain:false}),bn.VERSION=\"4.6.1\",u(\"bind bindKey curry curryRight partial partialRight\".split(\" \"),function(n){bn[n].placeholder=bn}),u([\"drop\",\"take\"],function(n,t){On.prototype[n]=function(r){var e=this.__filtered__;if(e&&!t)return new On(this);r=r===q?1:Uu(Ce(r),0);var u=this.clone();return e?u.__takeCount__=zu(r,u.__takeCount__):u.__views__.push({size:zu(r,4294967295),type:n+(0>u.__dir__?\"Right\":\"\")}),\nu},On.prototype[n+\"Right\"]=function(t){return this.reverse()[n](t).reverse()}}),u([\"filter\",\"map\",\"takeWhile\"],function(n,t){var r=t+1,e=1==r||3==r;On.prototype[n]=function(n){var t=this.clone();return t.__iteratees__.push({iteratee:kr(n,3),type:r}),t.__filtered__=t.__filtered__||e,t}}),u([\"head\",\"last\"],function(n,t){var r=\"take\"+(t?\"Right\":\"\");On.prototype[n]=function(){return this[r](1).value()[0]}}),u([\"initial\",\"tail\"],function(n,t){var r=\"drop\"+(t?\"\":\"Right\");On.prototype[n]=function(){return this.__filtered__?new On(this):this[r](1);\n}}),On.prototype.compact=function(){return this.filter(Ye)},On.prototype.find=function(n){return this.filter(n).head()},On.prototype.findLast=function(n){return this.reverse().find(n)},On.prototype.invokeMap=he(function(n,t){return typeof n==\"function\"?new On(this):this.map(function(r){return mt(r,n,t)})}),On.prototype.reject=function(n){return n=kr(n,3),this.filter(function(t){return!n(t)})},On.prototype.slice=function(n,t){n=Ce(n);var r=this;return r.__filtered__&&(n>0||0>t)?new On(r):(0>n?r=r.takeRight(-n):n&&(r=r.drop(n)),\nt!==q&&(t=Ce(t),r=0>t?r.dropRight(-t):r.take(t-n)),r)},On.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},On.prototype.toArray=function(){return this.take(4294967295)},_t(On.prototype,function(n,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),e=/^(?:head|last)$/.test(t),u=bn[e?\"take\"+(\"last\"==t?\"Right\":\"\"):t],o=e||/^find/.test(t);u&&(bn.prototype[t]=function(){function t(n){return n=u.apply(bn,l([n],f)),e&&h?n[0]:n}var i=this.__wrapped__,f=e?[1]:arguments,c=i instanceof On,a=f[0],s=c||qo(i);\ns&&r&&typeof a==\"function\"&&1!=a.length&&(c=s=false);var h=this.__chain__,p=!!this.__actions__.length,a=o&&!h,c=c&&!p;return!o&&s?(i=c?i:new On(this),i=n.apply(i,f),i.__actions__.push({func:ne,args:[t],thisArg:q}),new An(i,h)):a&&c?n.apply(this,f):(i=this.thru(t),a?e?i.value()[0]:i.value():i)})}),u(\"pop push shift sort splice unshift\".split(\" \"),function(n){var t=fu[n],r=/^(?:push|sort|unshift)$/.test(n)?\"tap\":\"thru\",e=/^(?:pop|shift)$/.test(n);bn.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){\nreturn t.apply(r,n)})}}),_t(On.prototype,function(n,t){var r=bn[t];if(r){var e=r.name+\"\";(Tu[e]||(Tu[e]=[])).push({name:t,func:r})}}),Tu[_r(q,2).name]=[{name:\"wrapper\",func:q}],On.prototype.clone=function(){var n=new On(this.__wrapped__);return n.__actions__=nr(this.__actions__),n.__dir__=this.__dir__,n.__filtered__=this.__filtered__,n.__iteratees__=nr(this.__iteratees__),n.__takeCount__=this.__takeCount__,n.__views__=nr(this.__views__),n},On.prototype.reverse=function(){if(this.__filtered__){var n=new On(this);\nn.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},On.prototype.value=function(){var n,t=this.__wrapped__.value(),r=this.__dir__,e=qo(t),u=0>r,o=e?t.length:0;n=o;for(var i=this.__views__,f=0,c=-1,a=i.length;++co||o==n&&a==n)return Gt(t,this.__actions__);\ne=[];n:for(;n--&&a>c;){for(u+=r,o=-1,l=t[u];++o=this.__values__.length,t=n?q:this.__values__[this.__index__++];\nreturn{done:n,value:t}},bn.prototype.plant=function(n){for(var t,r=this;r instanceof wn;){var e=Pr(r);e.__index__=0,e.__values__=q,t?u.__wrapped__=e:t=e;var u=e,r=r.__wrapped__}return u.__wrapped__=n,t},bn.prototype.reverse=function(){var n=this.__wrapped__;return n instanceof On?(this.__actions__.length&&(n=new On(this)),n=n.reverse(),n.__actions__.push({func:ne,args:[Yr],thisArg:q}),new An(n,this.__chain__)):this.thru(Yr)},bn.prototype.toJSON=bn.prototype.valueOf=bn.prototype.value=function(){return Gt(this.__wrapped__,this.__actions__);\n},Au&&(bn.prototype[Au]=te),bn}var q,P=1/0,T=NaN,K=/\\b__p\\+='';/g,G=/\\b(__p\\+=)''\\+/g,V=/(__e\\(.*?\\)|\\b__t\\))\\+'';/g,J=/&(?:amp|lt|gt|quot|#39|#96);/g,Y=/[&<>\"'`]/g,H=RegExp(J.source),Q=RegExp(Y.source),X=/<%-([\\s\\S]+?)%>/g,nn=/<%([\\s\\S]+?)%>/g,tn=/<%=([\\s\\S]+?)%>/g,rn=/\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,en=/^\\w*$/,un=/[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]/g,on=/[\\\\^$.*+?()[\\]{}|]/g,fn=RegExp(on.source),cn=/^\\s+|\\s+$/g,an=/^\\s+/,ln=/\\s+$/,sn=/\\\\(\\\\)?/g,hn=/\\$\\{([^\\\\}]*(?:\\\\.[^\\\\}]*)*)\\}/g,pn=/\\w*$/,_n=/^0x/i,vn=/^[-+]0x[0-9a-f]+$/i,gn=/^0b[01]+$/i,dn=/^\\[object .+?Constructor\\]$/,yn=/^0o[0-7]+$/i,bn=/^(?:0|[1-9]\\d*)$/,xn=/[\\xc0-\\xd6\\xd8-\\xde\\xdf-\\xf6\\xf8-\\xff]/g,jn=/($^)/,mn=/['\\n\\r\\u2028\\u2029\\\\]/g,wn=\"[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?(?:\\\\u200d(?:[^\\\\ud800-\\\\udfff]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?)*\",An=\"(?:[\\\\u2700-\\\\u27bf]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])\"+wn,On=\"(?:[^\\\\ud800-\\\\udfff][\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]?|[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff]|[\\\\ud800-\\\\udfff])\",kn=RegExp(\"[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]\",\"g\"),En=RegExp(\"\\\\ud83c[\\\\udffb-\\\\udfff](?=\\\\ud83c[\\\\udffb-\\\\udfff])|\"+On+wn,\"g\"),In=RegExp(\"[\\\\u200d\\\\ud800-\\\\udfff\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0\\\\ufe0e\\\\ufe0f]\"),Sn=/[a-zA-Z0-9]+/g,Rn=RegExp([\"[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|$)|(?:[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde](?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])|$)|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?(?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]+|\\\\d+\",An].join(\"|\"),\"g\"),Wn=/[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Bn=\"Array Buffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Reflect RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout\".split(\" \"),Cn={};\nCn[\"[object Float32Array]\"]=Cn[\"[object Float64Array]\"]=Cn[\"[object Int8Array]\"]=Cn[\"[object Int16Array]\"]=Cn[\"[object Int32Array]\"]=Cn[\"[object Uint8Array]\"]=Cn[\"[object Uint8ClampedArray]\"]=Cn[\"[object Uint16Array]\"]=Cn[\"[object Uint32Array]\"]=true,Cn[\"[object Arguments]\"]=Cn[\"[object Array]\"]=Cn[\"[object ArrayBuffer]\"]=Cn[\"[object Boolean]\"]=Cn[\"[object Date]\"]=Cn[\"[object Error]\"]=Cn[\"[object Function]\"]=Cn[\"[object Map]\"]=Cn[\"[object Number]\"]=Cn[\"[object Object]\"]=Cn[\"[object RegExp]\"]=Cn[\"[object Set]\"]=Cn[\"[object String]\"]=Cn[\"[object WeakMap]\"]=false;\nvar Un={};Un[\"[object Arguments]\"]=Un[\"[object Array]\"]=Un[\"[object ArrayBuffer]\"]=Un[\"[object Boolean]\"]=Un[\"[object Date]\"]=Un[\"[object Float32Array]\"]=Un[\"[object Float64Array]\"]=Un[\"[object Int8Array]\"]=Un[\"[object Int16Array]\"]=Un[\"[object Int32Array]\"]=Un[\"[object Map]\"]=Un[\"[object Number]\"]=Un[\"[object Object]\"]=Un[\"[object RegExp]\"]=Un[\"[object Set]\"]=Un[\"[object String]\"]=Un[\"[object Symbol]\"]=Un[\"[object Uint8Array]\"]=Un[\"[object Uint8ClampedArray]\"]=Un[\"[object Uint16Array]\"]=Un[\"[object Uint32Array]\"]=true,\nUn[\"[object Error]\"]=Un[\"[object Function]\"]=Un[\"[object WeakMap]\"]=false;var zn={\"\\xc0\":\"A\",\"\\xc1\":\"A\",\"\\xc2\":\"A\",\"\\xc3\":\"A\",\"\\xc4\":\"A\",\"\\xc5\":\"A\",\"\\xe0\":\"a\",\"\\xe1\":\"a\",\"\\xe2\":\"a\",\"\\xe3\":\"a\",\"\\xe4\":\"a\",\"\\xe5\":\"a\",\"\\xc7\":\"C\",\"\\xe7\":\"c\",\"\\xd0\":\"D\",\"\\xf0\":\"d\",\"\\xc8\":\"E\",\"\\xc9\":\"E\",\"\\xca\":\"E\",\"\\xcb\":\"E\",\"\\xe8\":\"e\",\"\\xe9\":\"e\",\"\\xea\":\"e\",\"\\xeb\":\"e\",\"\\xcc\":\"I\",\"\\xcd\":\"I\",\"\\xce\":\"I\",\"\\xcf\":\"I\",\"\\xec\":\"i\",\"\\xed\":\"i\",\"\\xee\":\"i\",\"\\xef\":\"i\",\"\\xd1\":\"N\",\"\\xf1\":\"n\",\"\\xd2\":\"O\",\"\\xd3\":\"O\",\"\\xd4\":\"O\",\"\\xd5\":\"O\",\"\\xd6\":\"O\",\n\"\\xd8\":\"O\",\"\\xf2\":\"o\",\"\\xf3\":\"o\",\"\\xf4\":\"o\",\"\\xf5\":\"o\",\"\\xf6\":\"o\",\"\\xf8\":\"o\",\"\\xd9\":\"U\",\"\\xda\":\"U\",\"\\xdb\":\"U\",\"\\xdc\":\"U\",\"\\xf9\":\"u\",\"\\xfa\":\"u\",\"\\xfb\":\"u\",\"\\xfc\":\"u\",\"\\xdd\":\"Y\",\"\\xfd\":\"y\",\"\\xff\":\"y\",\"\\xc6\":\"Ae\",\"\\xe6\":\"ae\",\"\\xde\":\"Th\",\"\\xfe\":\"th\",\"\\xdf\":\"ss\"},Mn={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\",\"`\":\"`\"},Ln={\"&\":\"&\",\"<\":\"<\",\">\":\">\",\""\":'\"',\"'\":\"'\",\"`\":\"`\"},$n={\"function\":true,object:true},Fn={\"\\\\\":\"\\\\\",\"'\":\"'\",\"\\n\":\"n\",\"\\r\":\"r\",\"\\u2028\":\"u2028\",\"\\u2029\":\"u2029\"\n},Nn=parseFloat,Dn=parseInt,Zn=$n[typeof exports]&&exports&&!exports.nodeType?exports:q,qn=$n[typeof module]&&module&&!module.nodeType?module:q,Pn=qn&&qn.exports===Zn?Zn:q,Tn=I($n[typeof self]&&self),Kn=I($n[typeof window]&&window),Gn=I($n[typeof this]&&this),Vn=I(Zn&&qn&&typeof global==\"object\"&&global)||Kn!==(Gn&&Gn.window)&&Kn||Tn||Gn||Function(\"return this\")(),Jn=Z();(Kn||Tn||{})._=Jn,typeof define==\"function\"&&typeof define.amd==\"object\"&&define.amd? define(function(){return Jn}):Zn&&qn?(Pn&&((qn.exports=Jn)._=Jn),\nZn._=Jn):Vn._=Jn}).call(this);\n\n// var n = 6,\n// ids = \"0 1 7 1 7 10\".split(' ').map( Number );\nvar n = +readline(),\n ids = readline().split(' ').map( Number );\nvar sorted = _.sortBy(ids);\nfor (var i = 0, s = 0; i < sorted.length - 1; i++) {\n if (sorted[i] === 0) { continue; }\n if (sorted[i] === sorted[i+1] && sorted[i] === sorted[i+2]) {\n print(-1);\n\t\tquit();\n } else if (sorted[i] === sorted[i+1]) s++;\n}\nprint(s);\n"}, {"source_code": "var n = readline();\nvar c = readline();\nvar arr = [];\n\nif(n === void 0 || c === void 0)\n quit(1);\n \narr = c.split(' ').map( Number );\n\nvar s = arr.sort(function(a,b){return a-b;});\nvar cnt = 0;\n\nfor(var a = 0; a < s.length; a++ ){\n if(s[a] === 0) continue;\n if(s[a] === s[a+1] && s[a] === s[a+2]){\n print(-1);\n quit();\n }\n else if(s[a] === s[a+1])\n cnt++;\n}\nprint(cnt);"}, {"source_code": ";(function () {\n\t\n\treadline();\n\tprint( readline().split(' ')\n\n\t\t.reduce(function (p, e, i, a) {\n\t\t\tif (e !== '0') p[e] = p[e] ? p[e] + 1 : 1;\n\t\t\tif (i !== a.length - 1) return p;\n\n\t\t\treturn Object.keys(p)\n\n\t\t\t\t.filter(function (_e) {\n\t\t\t\t\treturn p[_e] > 1;\n\t\t\t\t})\n\n\t\t\t\t.reduce(function (_p, _e) {\n\t\t\t\t\t++_p[ Number(p[_e] == 2) ];\n\t\t\t\t\treturn _p;\n\t\t\t\t}, [0, 0])\n\n\t\t\t\t.reduce(function (_p, _e, _i, _a) {\n\t\t\t\t\tif (_a[0]) return -1;\n\t\t\t\t\telse return _a[1];\n\t\t\t\t});\n\n\t\t}, {})\n\n\t);\n\n}).call(this);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let ans = 0;\n let idx = 0;\n arr = arr.filter(x => x !== 0);\n\n for (let i = 1; i < arr.length; i++) {\n while(arr[i - 1] === arr[i]) {\n idx++;\n i++;\n }\n\n if (idx === 1) {\n ans++;\n }\n else if (idx > 1) {\n ans = -1;\n break;\n }\n\n idx = 0;\n }\n\n console.log(ans);\n\n c++;\n});\n"}], "negative_code": [{"source_code": "var n=+readline();\nvar a=readline().split(' ');\nvar ans=0;\nfor(var i=0; i2){\n\t\tprint(-1);\n\t\tquit();\n\t}\n}\nprint(ans/2);"}, {"source_code": "var n=+readline();\nvar a=readline().split(' ');\nvar ans=0;\nfor(var i=0; i2){\n\t\tprint(-1);\n\t\tquit();\n\t}\n}\nprint(ans/2);"}, {"source_code": "var n = readline();\nvar c = readline();\nvar arr = [];\n\nif(n === void 0 || c === void 0)\n quit(1);\n \narr = c.split(' ').map( Number );\n\nvar s = arr.sort(function(a,b){return a-b;});\nvar cnt = 0;\n\nfor(var a = 0; a < s.length; a++ ){\n if(s[a] === 0) continue;\n if(s[a] === s[a+1] && s[a] === s[a+2]){\n print(-1);\n quit();\n }\n else\n cnt++;\n}\nprint(cnt);\n"}, {"source_code": "/**\n * @license\n * lodash 4.6.1 (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE\n * Build: `lodash -o ./dist/lodash.js`\n */\n;(function(){function n(n,t){return n.set(t[0],t[1]),n}function t(n,t){return n.add(t),n}function r(n,t,r){switch(r.length){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n,t,r,e){for(var u=-1,o=n.length;++ut&&!o||!u||r&&!i&&f||e&&f)return 1;if(t>n&&!r||!f||o&&!e&&u||i&&u)return-1}return 0}function R(n){return zn[n]}function W(n){return Mn[n]}function B(n){return\"\\\\\"+Fn[n]}function C(n,t,r){\nvar e=n.length;for(t+=r?0:-1;r?t--:++t-1&&0==n%1&&(null==t?9007199254740991:t)>n}function M(n){for(var t,r=[];!(t=n.next()).done;)r.push(t.value);return r}function L(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function $(n,t){for(var r=-1,e=n.length,u=0,o=[];++rr?false:(r==n.length-1?n.pop():Iu.call(n,r,1),true)}function qn(n,t){var r=Tn(n,t);return 0>r?q:n[r][1]}function Tn(n,t){for(var r=n.length;r--;)if(pe(n[r][0],t))return r;return-1}function Kn(n,t,r){var e=Tn(n,t);0>e?n.push([t,r]):n[e][1]=r}function Gn(n,t,r,e){return n===q||pe(n,cu[r])&&!lu.call(e,r)?t:n}function Yn(n,t,r){(r===q||pe(n[t],r))&&(typeof t!=\"number\"||r!==q||t in n)||(n[t]=r);\n}function Hn(n,t,r){var e=n[t];lu.call(n,t)&&pe(e,r)&&(r!==q||t in n)||(n[t]=r)}function Qn(n,t,r,e){return Qu(n,function(n,u,o){t(e,n,r(n),o)}),e}function Xn(n,t){return n&&tr(t,De(t),n)}function nt(n,t){for(var r=-1,e=null==n,u=t.length,o=Array(u);++rr?r:n),t!==q&&(n=t>n?t:n)),n}function ot(n,t,r,e,o,i,f){\nvar c;if(e&&(c=i?e(n,o,i,f):e(n)),c!==q)return c;if(!me(n))return n;if(o=qo(n)){if(c=Br(n),!t)return nr(n,c)}else{var a=Rr(n),l=\"[object Function]\"==a||\"[object GeneratorFunction]\"==a;if(Po(n))return Yt(n,t);if(\"[object Object]\"==a||\"[object Arguments]\"==a||l&&!i){if(U(n))return i?n:{};if(c=Cr(l?{}:n),!t)return c=Xn(c,n),r?er(n,c):c}else{if(!Un[a])return i?n:{};c=Ur(n,a,t)}}return f||(f=new Fn),(i=f.get(n))?i:(f.set(n,c),(o?u:_t)(n,function(u,o){Hn(c,o,ot(u,t,r,e,o,n,f))}),r&&!o?er(n,c):c)}function it(n){\nvar t=De(n),r=t.length;return function(e){if(null==e)return!r;for(var u=r;u--;){var o=t[u],i=n[o],f=e[o];if(f===q&&!(o in Object(e))||!i(f))return false}return true}}function ft(n){return me(n)?Ou(n):{}}function ct(n,t,r){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return Eu(function(){n.apply(q,r)},t)}function at(n,t,r,e){var u=-1,o=f,i=true,l=n.length,s=[],h=t.length;if(!l)return s;r&&(t=a(t,A(r))),e?(o=c,i=false):t.length>=200&&(o=$n,i=false,t=new Ln(t));n:for(;++u0&&de(i)&&(r||qo(i)||ve(i))?t>1?ht(i,t-1,r,e):l(e,i):r||(e[e.length]=i)}return e}function pt(n,t){null==n||no(n,t,Ze)}function _t(n,t){return n&&no(n,t,De)}function vt(n,t){return n&&to(n,t,De);\n}function gt(n,t){return i(t,function(t){return be(n[t])})}function dt(n,t){t=Lr(t,n)?[t+\"\"]:et(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:q}function yt(n,t){return lu.call(n,t)||typeof n==\"object\"&&t in n&&null===mu(n)}function bt(n,t){return t in Object(n)}function xt(n,t,r){for(var e=r?c:f,u=n[0].length,o=n.length,i=o,l=Array(o),s=1/0,h=[];i--;){var p=n[i];i&&t&&(p=a(p,A(t))),s=zu(p.length,s),l[i]=r||!t&&(120>u||120>p.length)?q:new Ln(i&&p)}var p=n[0],_=-1,v=l[0];n:for(;++_h.length;){\nvar g=p[_],d=t?t(g):g;if(v?!$n(v,d):!e(h,d,r)){for(i=o;--i;){var y=l[i];if(y?!$n(y,d):!e(n[i],d,r))continue n}v&&v.push(d),h.push(g)}}return h}function jt(n,t,r){var e={};return _t(n,function(n,u,o){t(e,r(n),u,o)}),e}function mt(n,t,e){return Lr(t,n)||(t=et(t),n=Zr(n,t),t=Vr(t)),t=null==n?n:n[t],null==t?q:r(t,n,e)}function wt(n,t,r,e,u){if(n===t)n=true;else if(null==n||null==t||!me(n)&&!we(t))n=n!==n&&t!==t;else n:{var o=qo(n),i=qo(t),f=\"[object Array]\",c=\"[object Array]\";o||(f=Rr(n),f=\"[object Arguments]\"==f?\"[object Object]\":f),\ni||(c=Rr(t),c=\"[object Arguments]\"==c?\"[object Object]\":c);var a=\"[object Object]\"==f&&!U(n),i=\"[object Object]\"==c&&!U(t);if((c=f==c)&&!a)u||(u=new Fn),n=o||Re(n)?wr(n,t,wt,r,e,u):Ar(n,t,f,wt,r,e,u);else{if(!(2&e)&&(o=a&&lu.call(n,\"__wrapped__\"),f=i&&lu.call(t,\"__wrapped__\"),o||f)){u||(u=new Fn),n=wt(o?n.value():n,f?t.value():t,r,e,u);break n}if(c)t:if(u||(u=new Fn),o=2&e,f=De(n),i=f.length,c=De(t).length,i==c||o){for(a=i;a--;){var l=f[a];if(!(o?l in t:yt(t,l))){n=false;break t}}if(c=u.get(n))n=c==t;else{\nc=true,u.set(n,t);for(var s=o;++ae?c*(\"desc\"==r[e]?-1:1):c;break n}}e=n.b-t.b}return e})}function Bt(n,t){return n=Object(n),s(t,function(t,r){return r in n&&(t[r]=n[r]),\nt},{})}function Ct(n,t){var r={};return pt(n,function(n,e){t(n,e)&&(r[e]=n)}),r}function Ut(n){return function(t){return null==t?q:t[n]}}function zt(n){return function(t){return dt(t,n)}}function Mt(n,t,r,e){var u=e?y:d,o=-1,i=t.length,f=n;for(r&&(f=a(n,A(r)));++ot&&(t=-t>u?0:u+t),r=r>u?u:r,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=Array(u);++e=u){for(;u>e;){var o=e+u>>>1,i=n[o];(r?t>=i:t>i)&&null!==i?e=o+1:u=o}return u}return qt(n,t,Ye,r)}function qt(n,t,r,e){t=r(t);for(var u=0,o=n?n.length:0,i=t!==t,f=null===t,c=t===q;o>u;){var a=Ru((u+o)/2),l=r(n[a]),s=l!==q,h=l===l;(i?h||e:f?h&&s&&(e||null!=l):c?h&&(e||s):null==l?0:e?t>=l:t>l)?u=a+1:o=a}return zu(o,4294967294)}function Pt(n,t){for(var r=0,e=n.length,u=n[0],o=t?t(u):u,i=o,f=1,c=[u];++re?t[e]:q);return i}function Yt(n,t){if(t)return n.slice();var r=new n.constructor(n.length);return n.copy(r),r}function Ht(n){var t=new n.constructor(n.byteLength);return new bu(t).set(new bu(n)),\nt}function Qt(n,t,r,e){var u=-1,o=n.length,i=r.length,f=-1,c=t.length,a=Uu(o-i,0),l=Array(c+a);for(e=!e;++fu)&&(l[r[u]]=n[u]);for(;a--;)l[f++]=n[u++];return l}function Xt(n,t,r,e){var u=-1,o=n.length,i=-1,f=r.length,c=-1,a=t.length,l=Uu(o-f,0),s=Array(l+a);for(e=!e;++uu)&&(s[l+r[i]]=n[u++]);return s}function nr(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r1?r[u-1]:q,i=u>2?r[2]:q,o=typeof o==\"function\"?(u--,o):q;for(i&&Mr(r[0],r[1],i)&&(o=3>u?q:o,u=1),t=Object(t);++ei&&f[0]!==a&&f[i-1]!==a?[]:$(f,a),i-=c.length,e>i?xr(n,t,_r,u.placeholder,q,f,c,q,q,e-i):r(this&&this!==Vn&&this instanceof u?o:n,this,f)}var o=sr(n);return u}function pr(n){return he(function(t){t=ht(t,1);var r=t.length,e=r,u=An.prototype.thru;for(n&&t.reverse();e--;){var o=t[e];if(typeof o!=\"function\")throw new iu(\"Expected a function\");if(u&&!i&&\"wrapper\"==Or(o))var i=new An([],true)}for(e=i?e:r;++e=200)return i.plant(e).value();for(var u=0,n=r?t[u].apply(this,n):e;++ud)return j=$(b,j),xr(n,t,_r,l.placeholder,r,b,j,f,c,a-d);if(j=h?r:this,y=p?j[n]:n,d=b.length,f){x=b.length;\nfor(var m=zu(f.length,x),w=nr(b);m--;){var A=f[m];b[m]=z(A,x)?w[A]:q}}else v&&d>1&&b.reverse();return s&&d>c&&(b.length=c),this&&this!==Vn&&this instanceof l&&(y=g||sr(y)),y.apply(j,b)}var s=128&t,h=1&t,p=2&t,_=24&t,v=512&t,g=p?q:sr(n);return l}function vr(n,t){return function(r,e){return jt(r,n,t(e))}}function gr(n){return he(function(t){return t=a(ht(t,1),kr()),he(function(e){var u=this;return n(t,function(n){return r(n,u,e)})})})}function dr(n,t,r){return t=Ce(t),n=N(n),t&&t>n?(t-=n,r=r===q?\" \":r+\"\",\nn=Ge(r,Su(t/N(r))),In.test(r)?n.match(En).slice(0,t).join(\"\"):n.slice(0,t)):\"\"}function yr(n,t,e,u){function o(){for(var t=-1,c=arguments.length,a=-1,l=u.length,s=Array(l+c),h=this&&this!==Vn&&this instanceof o?f:n;++at?1:-1:ze(e)||0;var u=-1;r=Uu(Su((r-t)/(e||1)),0);for(var o=Array(r);r--;)o[n?r:++u]=t,\nt+=e;return o}}function xr(n,t,r,e,u,o,i,f,c,a){var l=8&t;f=f?nr(f):q;var s=l?i:q;i=l?q:i;var h=l?o:q;return o=l?q:o,t=(t|(l?32:64))&~(l?64:32),4&t||(t&=-4),t=[n,t,u,h,s,o,i,f,c,a],r=r.apply(q,t),Fr(n)&&fo(r,t),r.placeholder=e,r}function jr(n){var t=uu[n];return function(n,r){if(n=ze(n),r=Ce(r)){var e=(Le(n)+\"e\").split(\"e\"),e=t(e[0]+\"e\"+(+e[1]+r)),e=(Le(e)+\"e\").split(\"e\");return+(e[0]+\"e\"+(+e[1]-r))}return t(n)}}function mr(n,t,r,e,u,o,i,f){var c=2&t;if(!c&&typeof n!=\"function\")throw new iu(\"Expected a function\");\nvar a=e?e.length:0;if(a||(t&=-97,e=u=q),i=i===q?i:Uu(Ce(i),0),f=f===q?f:Ce(f),a-=u?u.length:0,64&t){var l=e,s=u;e=u=q}var h=c?q:uo(n);return o=[n,t,r,e,u,l,s,o,i,f],h&&(r=o[1],n=h[1],t=r|n,e=128==n&&8==r||128==n&&256==r&&h[8]>=o[7].length||384==n&&h[8]>=h[7].length&&8==r,131>t||e)&&(1&n&&(o[2]=h[2],t|=1&r?0:4),(r=h[3])&&(e=o[3],o[3]=e?Qt(e,r,h[4]):nr(r),o[4]=e?$(o[3],\"__lodash_placeholder__\"):nr(h[4])),(r=h[5])&&(e=o[5],o[5]=e?Xt(e,r,h[6]):nr(r),o[6]=e?$(o[5],\"__lodash_placeholder__\"):nr(h[6])),(r=h[7])&&(o[7]=nr(r)),\n128&n&&(o[8]=null==o[8]?h[8]:zu(o[8],h[8])),null==o[9]&&(o[9]=h[9]),o[0]=h[0],o[1]=t),n=o[0],t=o[1],r=o[2],e=o[3],u=o[4],f=o[9]=null==o[9]?c?0:n.length:Uu(o[9]-a,0),!f&&24&t&&(t&=-25),(h?ro:fo)(t&&1!=t?8==t||16==t?hr(n,t,f):32!=t&&33!=t||u.length?_r.apply(q,o):yr(n,t,r,e):cr(n,t,r),o)}function wr(n,t,r,e,u,o){var i=-1,f=2&u,c=1&u,a=n.length,l=t.length;if(!(a==l||f&&l>a))return false;if(l=o.get(n))return l==t;for(l=true,o.set(n,t);++it?0:t,e)):[]}function Kr(n,t,r){var e=n?n.length:0;\nreturn e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0,0>t?0:t)):[]}function Gr(n){return n?n[0]:q}function Vr(n){var t=n?n.length:0;return t?n[t-1]:q}function Jr(n,t){return n&&n.length&&t&&t.length?Mt(n,t):n}function Yr(n){return n?$u.call(n):n}function Hr(n){if(!n||!n.length)return[];var t=0;return n=i(n,function(n){return de(n)?(t=Uu(n.length,t),true):void 0}),m(t,function(t){return a(n,Ut(t))})}function Qr(n,t){if(!n||!n.length)return[];var e=Hr(n);return null==t?e:a(e,function(n){return r(t,q,n)})}function Xr(n){\nreturn n=bn(n),n.__chain__=true,n}function ne(n,t){return t(n)}function te(){return this}function re(n,t){return typeof t==\"function\"&&qo(n)?u(n,t):Qu(n,rt(t))}function ee(n,t){var r;if(typeof t==\"function\"&&qo(n)){for(r=n.length;r--&&false!==t(n[r],r,n););r=n}else r=Xu(n,rt(t));return r}function ue(n,t){return(qo(n)?a:Et)(n,kr(t,3))}function oe(n,t){var r=-1,e=Be(n),u=e.length,o=u-1;for(t=ut(Ce(t),0,u);++r=n&&(t=q),r}}function ce(n,t,r){return t=r?q:t,n=mr(n,8,q,q,q,q,q,t),n.placeholder=ce.placeholder,n}function ae(n,t,r){return t=r?q:t,n=mr(n,16,q,q,q,q,q,t),n.placeholder=ae.placeholder,n}function le(n,t,r){function e(){p&&xu(p),a&&xu(a),v=0,c=a=h=p=_=q}function u(t,r){r&&xu(r),a=p=_=q,t&&(v=Uo(),l=n.apply(h,c),\np||a||(c=h=q))}function o(){var n=t-(Uo()-s);0>=n||n>t?u(_,a):p=Eu(o,n)}function i(){u(y,p)}function f(){if(c=arguments,s=Uo(),h=this,_=y&&(p||!g),false===d)var r=g&&!p;else{v||a||g||(v=s);var e=d-(s-v),u=(0>=e||e>d)&&(g||a);u?(a&&(a=xu(a)),v=s,l=n.apply(h,c)):a||(a=Eu(i,e))}return u&&p?p=xu(p):p||t===d||(p=Eu(o,t)),r&&(u=true,l=n.apply(h,c)),!u||p||a||(c=h=q),l}var c,a,l,s,h,p,_,v=0,g=false,d=false,y=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=ze(t)||0,me(r)&&(g=!!r.leading,d=\"maxWait\"in r&&Uu(ze(r.maxWait)||0,t),\ny=\"trailing\"in r?!!r.trailing:y),f.cancel=e,f.flush=function(){return(p&&_||a&&y)&&(l=n.apply(h,c)),e(),l},f}function se(n,t){function r(){var e=arguments,u=t?t.apply(this,e):e[0],o=r.cache;return o.has(u)?o.get(u):(e=n.apply(this,e),r.cache=o.set(u,e),e)}if(typeof n!=\"function\"||t&&typeof t!=\"function\")throw new iu(\"Expected a function\");return r.cache=new se.Cache,r}function he(n,t){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=Uu(t===q?n.length-1:Ce(t),0),function(){for(var e=arguments,u=-1,o=Uu(e.length-t,0),i=Array(o);++ut}function ve(n){return de(n)&&lu.call(n,\"callee\")&&(!ku.call(n,\"callee\")||\"[object Arguments]\"==pu.call(n))}function ge(n){return null!=n&&je(oo(n))&&!be(n)}function de(n){return we(n)&&ge(n)}function ye(n){return we(n)?\"[object Error]\"==pu.call(n)||typeof n.message==\"string\"&&typeof n.name==\"string\":false;\n}function be(n){return n=me(n)?pu.call(n):\"\",\"[object Function]\"==n||\"[object GeneratorFunction]\"==n}function xe(n){return typeof n==\"number\"&&n==Ce(n)}function je(n){return typeof n==\"number\"&&n>-1&&0==n%1&&9007199254740991>=n}function me(n){var t=typeof n;return!!n&&(\"object\"==t||\"function\"==t)}function we(n){return!!n&&typeof n==\"object\"}function Ae(n){return null==n?false:be(n)?vu.test(au.call(n)):we(n)&&(U(n)?vu:dn).test(n)}function Oe(n){return typeof n==\"number\"||we(n)&&\"[object Number]\"==pu.call(n);\n}function ke(n){return!we(n)||\"[object Object]\"!=pu.call(n)||U(n)?false:(n=mu(n),null===n?true:(n=n.constructor,typeof n==\"function\"&&n instanceof n&&au.call(n)==hu))}function Ee(n){return me(n)&&\"[object RegExp]\"==pu.call(n)}function Ie(n){return typeof n==\"string\"||!qo(n)&&we(n)&&\"[object String]\"==pu.call(n)}function Se(n){return typeof n==\"symbol\"||we(n)&&\"[object Symbol]\"==pu.call(n)}function Re(n){return we(n)&&je(n.length)&&!!Cn[pu.call(n)]}function We(n,t){return t>n}function Be(n){if(!n)return[];\nif(ge(n))return Ie(n)?n.match(En):nr(n);if(Au&&n[Au])return M(n[Au]());var t=Rr(n);return(\"[object Map]\"==t?L:\"[object Set]\"==t?F:Pe)(n)}function Ce(n){if(!n)return 0===n?n:0;if(n=ze(n),n===P||n===-P)return 1.7976931348623157e308*(0>n?-1:1);var t=n%1;return n===n?t?n-t:n:0}function Ue(n){return n?ut(Ce(n),0,4294967295):0}function ze(n){if(me(n)&&(n=be(n.valueOf)?n.valueOf():n,n=me(n)?n+\"\":n),typeof n!=\"string\")return 0===n?n:+n;n=n.replace(cn,\"\");var t=gn.test(n);return t||yn.test(n)?Dn(n.slice(2),t?2:8):vn.test(n)?T:+n;\n}function Me(n){return tr(n,Ze(n))}function Le(n){if(typeof n==\"string\")return n;if(null==n)return\"\";if(Se(n))return Hu?Hu.call(n):\"\";var t=n+\"\";return\"0\"==t&&1/n==-P?\"-0\":t}function $e(n,t,r){return n=null==n?q:dt(n,t),n===q?r:n}function Fe(n,t){return Wr(n,t,yt)}function Ne(n,t){return Wr(n,t,bt)}function De(n){var t=Nr(n);if(!t&&!ge(n))return Cu(Object(n));var r,e=zr(n),u=!!e,e=e||[],o=e.length;for(r in n)!yt(n,r)||u&&(\"length\"==r||z(r,o))||t&&\"constructor\"==r||e.push(r);return e}function Ze(n){\nfor(var t=-1,r=Nr(n),e=kt(n),u=e.length,o=zr(n),i=!!o,o=o||[],f=o.length;++tt||t>9007199254740991)return r;do t%2&&(r+=n),t=Ru(t/2),n+=n;while(t);return r}function Ve(n,t,r){\nreturn n=Le(n),t=r?q:t,t===q&&(t=Wn.test(n)?Rn:Sn),n.match(t)||[]}function Je(n){return function(){return n}}function Ye(n){return n}function He(n){return Ot(typeof n==\"function\"?n:ot(n,true))}function Qe(n,t,r){var e=De(t),o=gt(t,e);null!=r||me(t)&&(o.length||!e.length)||(r=t,t=n,n=this,o=gt(t,De(t)));var i=me(r)&&\"chain\"in r?r.chain:true,f=be(n);return u(o,function(r){var e=t[r];n[r]=e,f&&(n.prototype[r]=function(){var t=this.__chain__;if(i||t){var r=n(this.__wrapped__);return(r.__actions__=nr(this.__actions__)).push({\nfunc:e,args:arguments,thisArg:n}),r.__chain__=t,r}return e.apply(n,l([this.value()],arguments))})}),n}function Xe(){}function nu(n){return Lr(n)?Ut(n):zt(n)}function tu(n){return n&&n.length?j(n,Ye):0}I=I?Jn.defaults({},I,Jn.pick(Vn,Bn)):Vn;var ru=I.Date,eu=I.Error,uu=I.Math,ou=I.RegExp,iu=I.TypeError,fu=I.Array.prototype,cu=I.Object.prototype,au=I.Function.prototype.toString,lu=cu.hasOwnProperty,su=0,hu=au.call(Object),pu=cu.toString,_u=Vn._,vu=ou(\"^\"+au.call(lu).replace(on,\"\\\\$&\").replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g,\"$1.*?\")+\"$\"),gu=Pn?I.Buffer:q,du=I.Reflect,yu=I.Symbol,bu=I.Uint8Array,xu=I.clearTimeout,ju=du?du.f:q,mu=Object.getPrototypeOf,wu=Object.getOwnPropertySymbols,Au=typeof(Au=yu&&yu.iterator)==\"symbol\"?Au:q,Ou=Object.create,ku=cu.propertyIsEnumerable,Eu=I.setTimeout,Iu=fu.splice,Su=uu.ceil,Ru=uu.floor,Wu=I.isFinite,Bu=fu.join,Cu=Object.keys,Uu=uu.max,zu=uu.min,Mu=I.parseInt,Lu=uu.random,$u=fu.reverse,Fu=Ir(I,\"Map\"),Nu=Ir(I,\"Set\"),Du=Ir(I,\"WeakMap\"),Zu=Ir(Object,\"create\"),qu=Du&&new Du,Pu=!ku.call({\nvalueOf:1},\"valueOf\"),Tu={},Ku=Fu?au.call(Fu):\"\",Gu=Nu?au.call(Nu):\"\",Vu=Du?au.call(Du):\"\",Ju=yu?yu.prototype:q,Yu=Ju?Ju.valueOf:q,Hu=Ju?Ju.toString:q;bn.templateSettings={escape:X,evaluate:nn,interpolate:tn,variable:\"\",imports:{_:bn}};var Qu=ir(_t),Xu=ir(vt,true),no=fr(),to=fr(true);ju&&!ku.call({valueOf:1},\"valueOf\")&&(kt=function(n){return M(ju(n))});var ro=qu?function(n,t){return qu.set(n,t),n}:Ye,eo=Nu&&2===new Nu([1,2]).size?function(n){return new Nu(n)}:Xe,uo=qu?function(n){return qu.get(n)}:Xe,oo=Ut(\"length\"),io=wu||function(){\nreturn[]};(Fu&&\"[object Map]\"!=Rr(new Fu)||Nu&&\"[object Set]\"!=Rr(new Nu)||Du&&\"[object WeakMap]\"!=Rr(new Du))&&(Rr=function(n){var t=pu.call(n);if(n=\"[object Object]\"==t?n.constructor:null,n=typeof n==\"function\"?au.call(n):\"\")switch(n){case Ku:return\"[object Map]\";case Gu:return\"[object Set]\";case Vu:return\"[object WeakMap]\"}return t});var fo=function(){var n=0,t=0;return function(r,e){var u=Uo(),o=16-(u-t);if(t=u,o>0){if(150<=++n)return r}else n=0;return ro(r,e)}}(),co=he(function(n,t){qo(n)||(n=null==n?[]:[Object(n)]),\nt=ht(t,1);for(var r=n,e=t,u=-1,o=r.length,i=-1,f=e.length,c=Array(o+f);++u1?n[t-1]:q,t=typeof t==\"function\"?(n.pop(),t):q;return Qr(n,t)}),Eo=he(function(n){function t(t){return nt(t,n)}n=ht(n,1);var r=n.length,e=r?n[0]:0,u=this.__wrapped__;return 1>=r&&!this.__actions__.length&&u instanceof On&&z(e)?(u=u.slice(e,+e+(r?1:0)),u.__actions__.push({func:ne,args:[t],thisArg:q}),new An(u,this.__chain__).thru(function(n){return r&&!n.length&&n.push(q),\nn})):this.thru(t)}),Io=ur(function(n,t,r){lu.call(n,r)?++n[r]:n[r]=1}),So=ur(function(n,t,r){lu.call(n,r)?n[r].push(t):n[r]=[t]}),Ro=he(function(n,t,e){var u=-1,o=typeof t==\"function\",i=Lr(t),f=ge(n)?Array(n.length):[];return Qu(n,function(n){var c=o?t:i&&null!=n?n[t]:q;f[++u]=c?r(c,n,e):mt(n,t,e)}),f}),Wo=ur(function(n,t,r){n[r]=t}),Bo=ur(function(n,t,r){n[r?0:1].push(t)},function(){return[[],[]]}),Co=he(function(n,t){if(null==n)return[];var r=t.length;return r>1&&Mr(n,t[0],t[1])?t=[]:r>2&&Mr(t[0],t[1],t[2])&&(t.length=1),\nWt(n,ht(t,1),[])}),Uo=ru.now,zo=he(function(n,t,r){var e=1;if(r.length)var u=$(r,Sr(zo)),e=32|e;return mr(n,e,t,r,u)}),Mo=he(function(n,t,r){var e=3;if(r.length)var u=$(r,Sr(Mo)),e=32|e;return mr(t,e,n,r,u)}),Lo=he(function(n,t){return ct(n,1,t)}),$o=he(function(n,t,r){return ct(n,ze(t)||0,r)}),Fo=he(function(n,t){t=a(ht(t,1),kr());var e=t.length;return he(function(u){for(var o=-1,i=zu(u.length,e);++oe.length?Kn(e,n,t):(r.array=null,r.map=new Mn(e))),(r=r.map)&&r.set(n,t),this},se.Cache=Mn,bn.after=function(n,t){if(typeof t!=\"function\")throw new iu(\"Expected a function\");return n=Ce(n),function(){return 1>--n?t.apply(this,arguments):void 0}},bn.ary=ie,bn.assign=To,bn.assignIn=Ko,\nbn.assignInWith=Go,bn.assignWith=Vo,bn.at=Jo,bn.before=fe,bn.bind=zo,bn.bindAll=_i,bn.bindKey=Mo,bn.castArray=function(){if(!arguments.length)return[];var n=arguments[0];return qo(n)?n:[n]},bn.chain=Xr,bn.chunk=function(n,t){t=Uu(Ce(t),0);var r=n?n.length:0;if(!r||1>t)return[];for(var e=0,u=0,o=Array(Su(r/t));r>e;)o[u++]=Nt(n,e,e+=t);return o},bn.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++tr&&(r=-r>u?0:u+r),e=e===q||e>u?u:Ce(e),0>e&&(e+=u),e=r>e?0:Ue(e);e>r;)n[r++]=t;return n},bn.filter=function(n,t){return(qo(n)?i:st)(n,kr(t,3))},bn.flatMap=function(n,t){return ht(ue(n,t),1)},bn.flatten=function(n){\nreturn n&&n.length?ht(n,1):[]},bn.flattenDeep=function(n){return n&&n.length?ht(n,P):[]},bn.flattenDepth=function(n,t){return n&&n.length?(t=t===q?1:Ce(t),ht(n,t)):[]},bn.flip=function(n){return mr(n,512)},bn.flow=vi,bn.flowRight=gi,bn.fromPairs=function(n){for(var t=-1,r=n?n.length:0,e={};++tt?0:t)):[]},bn.takeRight=function(n,t,r){var e=n?n.length:0;return e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0>t?0:t,e)):[]},bn.takeRightWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3),false,true):[]},bn.takeWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3)):[]},bn.tap=function(n,t){return t(n),n},bn.throttle=function(n,t,r){var e=true,u=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return me(r)&&(e=\"leading\"in r?!!r.leading:e,u=\"trailing\"in r?!!r.trailing:u),le(n,t,{leading:e,maxWait:t,\ntrailing:u})},bn.thru=ne,bn.toArray=Be,bn.toPairs=qe,bn.toPairsIn=function(n){return w(n,Ze(n))},bn.toPath=function(n){return qo(n)?a(n,String):qr(n)},bn.toPlainObject=Me,bn.transform=function(n,t,r){var e=qo(n)||Re(n);if(t=kr(t,4),null==r)if(e||me(n)){var o=n.constructor;r=e?qo(n)?new o:[]:be(o)?ft(mu(n)):{}}else r={};return(e?u:_t)(n,function(n,e,u){return t(r,n,e,u)}),r},bn.unary=function(n){return ie(n,1)},bn.union=yo,bn.unionBy=bo,bn.unionWith=xo,bn.uniq=function(n){return n&&n.length?Tt(n):[];\n},bn.uniqBy=function(n,t){return n&&n.length?Tt(n,kr(t)):[]},bn.uniqWith=function(n,t){return n&&n.length?Tt(n,q,t):[]},bn.unset=function(n,t){var r;if(null==n)r=true;else{r=n;var e=t,e=Lr(e,r)?[e+\"\"]:et(e);r=Zr(r,e),e=Vr(e),r=null!=r&&Fe(r,e)?delete r[e]:true}return r},bn.unzip=Hr,bn.unzipWith=Qr,bn.update=function(n,t,r){return null==n?n:Ft(n,t,rt(r)(dt(n,t)),void 0)},bn.updateWith=function(n,t,r,e){return e=typeof e==\"function\"?e:q,null!=n&&(n=Ft(n,t,rt(r)(dt(n,t)),e)),n},bn.values=Pe,bn.valuesIn=function(n){\nreturn null==n?[]:O(n,Ze(n))},bn.without=jo,bn.words=Ve,bn.wrap=function(n,t){return t=null==t?Ye:t,No(t,n)},bn.xor=mo,bn.xorBy=wo,bn.xorWith=Ao,bn.zip=Oo,bn.zipObject=function(n,t){return Jt(n||[],t||[],Hn)},bn.zipObjectDeep=function(n,t){return Jt(n||[],t||[],Ft)},bn.zipWith=ko,bn.extend=Ko,bn.extendWith=Go,Qe(bn,bn),bn.add=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r+t),r)},bn.attempt=pi,bn.camelCase=oi,bn.capitalize=Te,bn.ceil=Ai,bn.clamp=function(n,t,r){return r===q&&(r=t,\nt=q),r!==q&&(r=ze(r),r=r===r?r:0),t!==q&&(t=ze(t),t=t===t?t:0),ut(ze(n),t,r)},bn.clone=function(n){return ot(n,false,true)},bn.cloneDeep=function(n){return ot(n,true,true)},bn.cloneDeepWith=function(n,t){return ot(n,true,true,t)},bn.cloneWith=function(n,t){return ot(n,false,true,t)},bn.deburr=Ke,bn.endsWith=function(n,t,r){n=Le(n),t=typeof t==\"string\"?t:t+\"\";var e=n.length;return r=r===q?e:ut(Ce(r),0,e),r-=t.length,r>=0&&n.indexOf(t,r)==r},bn.eq=pe,bn.escape=function(n){return(n=Le(n))&&Q.test(n)?n.replace(Y,W):n},\nbn.escapeRegExp=function(n){return(n=Le(n))&&fn.test(n)?n.replace(on,\"\\\\$&\"):n},bn.every=function(n,t,r){var e=qo(n)?o:lt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.find=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t);return r>-1?n[r]:q}return v(n,t,Qu)},bn.findIndex=function(n,t){return n&&n.length?g(n,kr(t,3)):-1},bn.findKey=function(n,t){return v(n,kr(t,3),_t,true)},bn.findLast=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t,true);return r>-1?n[r]:q}return v(n,t,Xu)},bn.findLastIndex=function(n,t){return n&&n.length?g(n,kr(t,3),true):-1;\n},bn.findLastKey=function(n,t){return v(n,kr(t,3),vt,true)},bn.floor=Oi,bn.forEach=re,bn.forEachRight=ee,bn.forIn=function(n,t){return null==n?n:no(n,rt(t),Ze)},bn.forInRight=function(n,t){return null==n?n:to(n,rt(t),Ze)},bn.forOwn=function(n,t){return n&&_t(n,rt(t))},bn.forOwnRight=function(n,t){return n&&vt(n,rt(t))},bn.get=$e,bn.gt=_e,bn.gte=function(n,t){return n>=t},bn.has=Fe,bn.hasIn=Ne,bn.head=Gr,bn.identity=Ye,bn.includes=function(n,t,r,e){return n=ge(n)?n:Pe(n),r=r&&!e?Ce(r):0,e=n.length,0>r&&(r=Uu(e+r,0)),\nIe(n)?e>=r&&-1r&&(r=Uu(e+r,0)),d(n,t,r)):-1},bn.inRange=function(n,t,r){return t=ze(t)||0,r===q?(r=t,t=0):r=ze(r)||0,n=ze(n),n>=zu(t,r)&&n=-9007199254740991&&9007199254740991>=n;\n},bn.isSet=function(n){return we(n)&&\"[object Set]\"==Rr(n)},bn.isString=Ie,bn.isSymbol=Se,bn.isTypedArray=Re,bn.isUndefined=function(n){return n===q},bn.isWeakMap=function(n){return we(n)&&\"[object WeakMap]\"==Rr(n)},bn.isWeakSet=function(n){return we(n)&&\"[object WeakSet]\"==pu.call(n)},bn.join=function(n,t){return n?Bu.call(n,t):\"\"},bn.kebabCase=ii,bn.last=Vr,bn.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(r!==q&&(u=Ce(r),u=(0>u?Uu(e+u,0):zu(u,e-1))+1),t!==t)return C(n,u,true);\nfor(;u--;)if(n[u]===t)return u;return-1},bn.lowerCase=fi,bn.lowerFirst=ci,bn.lt=We,bn.lte=function(n,t){return t>=n},bn.max=function(n){return n&&n.length?_(n,Ye,_e):q},bn.maxBy=function(n,t){return n&&n.length?_(n,kr(t),_e):q},bn.mean=function(n){return tu(n)/(n?n.length:0)},bn.min=function(n){return n&&n.length?_(n,Ye,We):q},bn.minBy=function(n,t){return n&&n.length?_(n,kr(t),We):q},bn.noConflict=function(){return Vn._===this&&(Vn._=_u),this},bn.noop=Xe,bn.now=Uo,bn.pad=function(n,t,r){n=Le(n),\nt=Ce(t);var e=N(n);return t&&t>e?(e=(t-e)/2,t=Ru(e),e=Su(e),dr(\"\",t,r)+n+dr(\"\",e,r)):n},bn.padEnd=function(n,t,r){return n=Le(n),n+dr(n,t,r)},bn.padStart=function(n,t,r){return n=Le(n),dr(n,t,r)+n},bn.parseInt=function(n,t,r){return r||null==t?t=0:t&&(t=+t),n=Le(n).replace(cn,\"\"),Mu(n,t||(_n.test(n)?16:10))},bn.random=function(n,t,r){if(r&&typeof r!=\"boolean\"&&Mr(n,t,r)&&(t=r=q),r===q&&(typeof t==\"boolean\"?(r=t,t=q):typeof n==\"boolean\"&&(r=n,n=q)),n===q&&t===q?(n=0,t=1):(n=ze(n)||0,t===q?(t=n,n=0):t=ze(t)||0),\nn>t){var e=n;n=t,t=e}return r||n%1||t%1?(r=Lu(),zu(n+r*(t-n+Nn(\"1e-\"+((r+\"\").length-1))),t)):$t(n,t)},bn.reduce=function(n,t,r){var e=qo(n)?s:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Qu)},bn.reduceRight=function(n,t,r){var e=qo(n)?h:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Xu)},bn.repeat=Ge,bn.replace=function(){var n=arguments,t=Le(n[0]);return 3>n.length?t:t.replace(n[1],n[2])},bn.result=function(n,t,r){if(Lr(t,n))e=null==n?q:n[t];else{t=et(t);var e=$e(n,t);n=Zr(n,t)}return e===q&&(e=r),\nbe(e)?e.call(n):e},bn.round=ki,bn.runInContext=Z,bn.sample=function(n){n=ge(n)?n:Pe(n);var t=n.length;return t>0?n[$t(0,t-1)]:q},bn.size=function(n){if(null==n)return 0;if(ge(n)){var t=n.length;return t&&Ie(n)?N(n):t}return De(n).length},bn.snakeCase=li,bn.some=function(n,t,r){var e=qo(n)?p:Dt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.sortedIndex=function(n,t){return Zt(n,t)},bn.sortedIndexBy=function(n,t,r){return qt(n,t,kr(r))},bn.sortedIndexOf=function(n,t){var r=n?n.length:0;if(r){var e=Zt(n,t);\nif(r>e&&pe(n[e],t))return e}return-1},bn.sortedLastIndex=function(n,t){return Zt(n,t,true)},bn.sortedLastIndexBy=function(n,t,r){return qt(n,t,kr(r),true)},bn.sortedLastIndexOf=function(n,t){if(n&&n.length){var r=Zt(n,t,true)-1;if(pe(n[r],t))return r}return-1},bn.startCase=si,bn.startsWith=function(n,t,r){return n=Le(n),r=ut(Ce(r),0,n.length),n.lastIndexOf(t,r)==r},bn.subtract=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r-t),r)},bn.sum=tu,bn.sumBy=function(n,t){return n&&n.length?j(n,kr(t)):0;\n},bn.template=function(n,t,r){var e=bn.templateSettings;r&&Mr(n,t,r)&&(t=q),n=Le(n),t=Go({},t,e,Gn),r=Go({},t.imports,e.imports,Gn);var u,o,i=De(r),f=O(r,i),c=0;r=t.interpolate||jn;var a=\"__p+='\";r=ou((t.escape||jn).source+\"|\"+r.source+\"|\"+(r===tn?hn:jn).source+\"|\"+(t.evaluate||jn).source+\"|$\",\"g\");var l=\"sourceURL\"in t?\"//# sourceURL=\"+t.sourceURL+\"\\n\":\"\";if(n.replace(r,function(t,r,e,i,f,l){return e||(e=i),a+=n.slice(c,l).replace(mn,B),r&&(u=true,a+=\"'+__e(\"+r+\")+'\"),f&&(o=true,a+=\"';\"+f+\";\\n__p+='\"),\ne&&(a+=\"'+((__t=(\"+e+\"))==null?'':__t)+'\"),c=l+t.length,t}),a+=\"';\",(t=t.variable)||(a=\"with(obj){\"+a+\"}\"),a=(o?a.replace(K,\"\"):a).replace(G,\"$1\").replace(V,\"$1;\"),a=\"function(\"+(t||\"obj\")+\"){\"+(t?\"\":\"obj||(obj={});\")+\"var __t,__p=''\"+(u?\",__e=_.escape\":\"\")+(o?\",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}\":\";\")+a+\"return __p}\",t=pi(function(){return Function(i,l+\"return \"+a).apply(q,f)}),t.source=a,ye(t))throw t;return t},bn.times=function(n,t){if(n=Ce(n),1>n||n>9007199254740991)return[];\nvar r=4294967295,e=zu(n,4294967295);for(t=rt(t),n-=4294967295,e=m(e,t);++r=o)return n;if(o=r-N(e),1>o)return e;\nif(r=i?i.slice(0,o).join(\"\"):n.slice(0,o),u===q)return r+e;if(i&&(o+=r.length-o),Ee(u)){if(n.slice(o).search(u)){var f=r;for(u.global||(u=ou(u.source,Le(pn.exec(u))+\"g\")),u.lastIndex=0;i=u.exec(f);)var c=i.index;r=r.slice(0,c===q?o:c)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),u>-1&&(r=r.slice(0,u)));return r+e},bn.unescape=function(n){return(n=Le(n))&&H.test(n)?n.replace(J,D):n},bn.uniqueId=function(n){var t=++su;return Le(n)+t},bn.upperCase=hi,bn.upperFirst=ai,bn.each=re,bn.eachRight=ee,bn.first=Gr,\nQe(bn,function(){var n={};return _t(bn,function(t,r){lu.call(bn.prototype,r)||(n[r]=t)}),n}(),{chain:false}),bn.VERSION=\"4.6.1\",u(\"bind bindKey curry curryRight partial partialRight\".split(\" \"),function(n){bn[n].placeholder=bn}),u([\"drop\",\"take\"],function(n,t){On.prototype[n]=function(r){var e=this.__filtered__;if(e&&!t)return new On(this);r=r===q?1:Uu(Ce(r),0);var u=this.clone();return e?u.__takeCount__=zu(r,u.__takeCount__):u.__views__.push({size:zu(r,4294967295),type:n+(0>u.__dir__?\"Right\":\"\")}),\nu},On.prototype[n+\"Right\"]=function(t){return this.reverse()[n](t).reverse()}}),u([\"filter\",\"map\",\"takeWhile\"],function(n,t){var r=t+1,e=1==r||3==r;On.prototype[n]=function(n){var t=this.clone();return t.__iteratees__.push({iteratee:kr(n,3),type:r}),t.__filtered__=t.__filtered__||e,t}}),u([\"head\",\"last\"],function(n,t){var r=\"take\"+(t?\"Right\":\"\");On.prototype[n]=function(){return this[r](1).value()[0]}}),u([\"initial\",\"tail\"],function(n,t){var r=\"drop\"+(t?\"\":\"Right\");On.prototype[n]=function(){return this.__filtered__?new On(this):this[r](1);\n}}),On.prototype.compact=function(){return this.filter(Ye)},On.prototype.find=function(n){return this.filter(n).head()},On.prototype.findLast=function(n){return this.reverse().find(n)},On.prototype.invokeMap=he(function(n,t){return typeof n==\"function\"?new On(this):this.map(function(r){return mt(r,n,t)})}),On.prototype.reject=function(n){return n=kr(n,3),this.filter(function(t){return!n(t)})},On.prototype.slice=function(n,t){n=Ce(n);var r=this;return r.__filtered__&&(n>0||0>t)?new On(r):(0>n?r=r.takeRight(-n):n&&(r=r.drop(n)),\nt!==q&&(t=Ce(t),r=0>t?r.dropRight(-t):r.take(t-n)),r)},On.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},On.prototype.toArray=function(){return this.take(4294967295)},_t(On.prototype,function(n,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),e=/^(?:head|last)$/.test(t),u=bn[e?\"take\"+(\"last\"==t?\"Right\":\"\"):t],o=e||/^find/.test(t);u&&(bn.prototype[t]=function(){function t(n){return n=u.apply(bn,l([n],f)),e&&h?n[0]:n}var i=this.__wrapped__,f=e?[1]:arguments,c=i instanceof On,a=f[0],s=c||qo(i);\ns&&r&&typeof a==\"function\"&&1!=a.length&&(c=s=false);var h=this.__chain__,p=!!this.__actions__.length,a=o&&!h,c=c&&!p;return!o&&s?(i=c?i:new On(this),i=n.apply(i,f),i.__actions__.push({func:ne,args:[t],thisArg:q}),new An(i,h)):a&&c?n.apply(this,f):(i=this.thru(t),a?e?i.value()[0]:i.value():i)})}),u(\"pop push shift sort splice unshift\".split(\" \"),function(n){var t=fu[n],r=/^(?:push|sort|unshift)$/.test(n)?\"tap\":\"thru\",e=/^(?:pop|shift)$/.test(n);bn.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){\nreturn t.apply(r,n)})}}),_t(On.prototype,function(n,t){var r=bn[t];if(r){var e=r.name+\"\";(Tu[e]||(Tu[e]=[])).push({name:t,func:r})}}),Tu[_r(q,2).name]=[{name:\"wrapper\",func:q}],On.prototype.clone=function(){var n=new On(this.__wrapped__);return n.__actions__=nr(this.__actions__),n.__dir__=this.__dir__,n.__filtered__=this.__filtered__,n.__iteratees__=nr(this.__iteratees__),n.__takeCount__=this.__takeCount__,n.__views__=nr(this.__views__),n},On.prototype.reverse=function(){if(this.__filtered__){var n=new On(this);\nn.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},On.prototype.value=function(){var n,t=this.__wrapped__.value(),r=this.__dir__,e=qo(t),u=0>r,o=e?t.length:0;n=o;for(var i=this.__views__,f=0,c=-1,a=i.length;++co||o==n&&a==n)return Gt(t,this.__actions__);\ne=[];n:for(;n--&&a>c;){for(u+=r,o=-1,l=t[u];++o=this.__values__.length,t=n?q:this.__values__[this.__index__++];\nreturn{done:n,value:t}},bn.prototype.plant=function(n){for(var t,r=this;r instanceof wn;){var e=Pr(r);e.__index__=0,e.__values__=q,t?u.__wrapped__=e:t=e;var u=e,r=r.__wrapped__}return u.__wrapped__=n,t},bn.prototype.reverse=function(){var n=this.__wrapped__;return n instanceof On?(this.__actions__.length&&(n=new On(this)),n=n.reverse(),n.__actions__.push({func:ne,args:[Yr],thisArg:q}),new An(n,this.__chain__)):this.thru(Yr)},bn.prototype.toJSON=bn.prototype.valueOf=bn.prototype.value=function(){return Gt(this.__wrapped__,this.__actions__);\n},Au&&(bn.prototype[Au]=te),bn}var q,P=1/0,T=NaN,K=/\\b__p\\+='';/g,G=/\\b(__p\\+=)''\\+/g,V=/(__e\\(.*?\\)|\\b__t\\))\\+'';/g,J=/&(?:amp|lt|gt|quot|#39|#96);/g,Y=/[&<>\"'`]/g,H=RegExp(J.source),Q=RegExp(Y.source),X=/<%-([\\s\\S]+?)%>/g,nn=/<%([\\s\\S]+?)%>/g,tn=/<%=([\\s\\S]+?)%>/g,rn=/\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,en=/^\\w*$/,un=/[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]/g,on=/[\\\\^$.*+?()[\\]{}|]/g,fn=RegExp(on.source),cn=/^\\s+|\\s+$/g,an=/^\\s+/,ln=/\\s+$/,sn=/\\\\(\\\\)?/g,hn=/\\$\\{([^\\\\}]*(?:\\\\.[^\\\\}]*)*)\\}/g,pn=/\\w*$/,_n=/^0x/i,vn=/^[-+]0x[0-9a-f]+$/i,gn=/^0b[01]+$/i,dn=/^\\[object .+?Constructor\\]$/,yn=/^0o[0-7]+$/i,bn=/^(?:0|[1-9]\\d*)$/,xn=/[\\xc0-\\xd6\\xd8-\\xde\\xdf-\\xf6\\xf8-\\xff]/g,jn=/($^)/,mn=/['\\n\\r\\u2028\\u2029\\\\]/g,wn=\"[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?(?:\\\\u200d(?:[^\\\\ud800-\\\\udfff]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?)*\",An=\"(?:[\\\\u2700-\\\\u27bf]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])\"+wn,On=\"(?:[^\\\\ud800-\\\\udfff][\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]?|[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff]|[\\\\ud800-\\\\udfff])\",kn=RegExp(\"[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]\",\"g\"),En=RegExp(\"\\\\ud83c[\\\\udffb-\\\\udfff](?=\\\\ud83c[\\\\udffb-\\\\udfff])|\"+On+wn,\"g\"),In=RegExp(\"[\\\\u200d\\\\ud800-\\\\udfff\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0\\\\ufe0e\\\\ufe0f]\"),Sn=/[a-zA-Z0-9]+/g,Rn=RegExp([\"[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|$)|(?:[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde](?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])|$)|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?(?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]+|\\\\d+\",An].join(\"|\"),\"g\"),Wn=/[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Bn=\"Array Buffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Reflect RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout\".split(\" \"),Cn={};\nCn[\"[object Float32Array]\"]=Cn[\"[object Float64Array]\"]=Cn[\"[object Int8Array]\"]=Cn[\"[object Int16Array]\"]=Cn[\"[object Int32Array]\"]=Cn[\"[object Uint8Array]\"]=Cn[\"[object Uint8ClampedArray]\"]=Cn[\"[object Uint16Array]\"]=Cn[\"[object Uint32Array]\"]=true,Cn[\"[object Arguments]\"]=Cn[\"[object Array]\"]=Cn[\"[object ArrayBuffer]\"]=Cn[\"[object Boolean]\"]=Cn[\"[object Date]\"]=Cn[\"[object Error]\"]=Cn[\"[object Function]\"]=Cn[\"[object Map]\"]=Cn[\"[object Number]\"]=Cn[\"[object Object]\"]=Cn[\"[object RegExp]\"]=Cn[\"[object Set]\"]=Cn[\"[object String]\"]=Cn[\"[object WeakMap]\"]=false;\nvar Un={};Un[\"[object Arguments]\"]=Un[\"[object Array]\"]=Un[\"[object ArrayBuffer]\"]=Un[\"[object Boolean]\"]=Un[\"[object Date]\"]=Un[\"[object Float32Array]\"]=Un[\"[object Float64Array]\"]=Un[\"[object Int8Array]\"]=Un[\"[object Int16Array]\"]=Un[\"[object Int32Array]\"]=Un[\"[object Map]\"]=Un[\"[object Number]\"]=Un[\"[object Object]\"]=Un[\"[object RegExp]\"]=Un[\"[object Set]\"]=Un[\"[object String]\"]=Un[\"[object Symbol]\"]=Un[\"[object Uint8Array]\"]=Un[\"[object Uint8ClampedArray]\"]=Un[\"[object Uint16Array]\"]=Un[\"[object Uint32Array]\"]=true,\nUn[\"[object Error]\"]=Un[\"[object Function]\"]=Un[\"[object WeakMap]\"]=false;var zn={\"\\xc0\":\"A\",\"\\xc1\":\"A\",\"\\xc2\":\"A\",\"\\xc3\":\"A\",\"\\xc4\":\"A\",\"\\xc5\":\"A\",\"\\xe0\":\"a\",\"\\xe1\":\"a\",\"\\xe2\":\"a\",\"\\xe3\":\"a\",\"\\xe4\":\"a\",\"\\xe5\":\"a\",\"\\xc7\":\"C\",\"\\xe7\":\"c\",\"\\xd0\":\"D\",\"\\xf0\":\"d\",\"\\xc8\":\"E\",\"\\xc9\":\"E\",\"\\xca\":\"E\",\"\\xcb\":\"E\",\"\\xe8\":\"e\",\"\\xe9\":\"e\",\"\\xea\":\"e\",\"\\xeb\":\"e\",\"\\xcc\":\"I\",\"\\xcd\":\"I\",\"\\xce\":\"I\",\"\\xcf\":\"I\",\"\\xec\":\"i\",\"\\xed\":\"i\",\"\\xee\":\"i\",\"\\xef\":\"i\",\"\\xd1\":\"N\",\"\\xf1\":\"n\",\"\\xd2\":\"O\",\"\\xd3\":\"O\",\"\\xd4\":\"O\",\"\\xd5\":\"O\",\"\\xd6\":\"O\",\n\"\\xd8\":\"O\",\"\\xf2\":\"o\",\"\\xf3\":\"o\",\"\\xf4\":\"o\",\"\\xf5\":\"o\",\"\\xf6\":\"o\",\"\\xf8\":\"o\",\"\\xd9\":\"U\",\"\\xda\":\"U\",\"\\xdb\":\"U\",\"\\xdc\":\"U\",\"\\xf9\":\"u\",\"\\xfa\":\"u\",\"\\xfb\":\"u\",\"\\xfc\":\"u\",\"\\xdd\":\"Y\",\"\\xfd\":\"y\",\"\\xff\":\"y\",\"\\xc6\":\"Ae\",\"\\xe6\":\"ae\",\"\\xde\":\"Th\",\"\\xfe\":\"th\",\"\\xdf\":\"ss\"},Mn={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\",\"`\":\"`\"},Ln={\"&\":\"&\",\"<\":\"<\",\">\":\">\",\""\":'\"',\"'\":\"'\",\"`\":\"`\"},$n={\"function\":true,object:true},Fn={\"\\\\\":\"\\\\\",\"'\":\"'\",\"\\n\":\"n\",\"\\r\":\"r\",\"\\u2028\":\"u2028\",\"\\u2029\":\"u2029\"\n},Nn=parseFloat,Dn=parseInt,Zn=$n[typeof exports]&&exports&&!exports.nodeType?exports:q,qn=$n[typeof module]&&module&&!module.nodeType?module:q,Pn=qn&&qn.exports===Zn?Zn:q,Tn=I($n[typeof self]&&self),Kn=I($n[typeof window]&&window),Gn=I($n[typeof this]&&this),Vn=I(Zn&&qn&&typeof global==\"object\"&&global)||Kn!==(Gn&&Gn.window)&&Kn||Tn||Gn||Function(\"return this\")(),Jn=Z();(Kn||Tn||{})._=Jn,typeof define==\"function\"&&typeof define.amd==\"object\"&&define.amd? define(function(){return Jn}):Zn&&qn?(Pn&&((qn.exports=Jn)._=Jn),\nZn._=Jn):Vn._=Jn}).call(this);\n\n// var n = 6,\n// ids = \"0 1 7 1 7 10\".split(' ').map( Number );\nvar n = +readline(),\n ids = readline().split(' ').map( Number );\nvar sorted = _.sortBy(ids);\nfor (var i = 0, s = 0; i < sorted.length - 1; i++) { \n if (sorted[i] == sorted[i+1]) s++;\n}\n\nprint(s);"}, {"source_code": "/**\n * @license\n * lodash 4.6.1 (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE\n * Build: `lodash -o ./dist/lodash.js`\n */\n;(function(){function n(n,t){return n.set(t[0],t[1]),n}function t(n,t){return n.add(t),n}function r(n,t,r){switch(r.length){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n,t,r,e){for(var u=-1,o=n.length;++ut&&!o||!u||r&&!i&&f||e&&f)return 1;if(t>n&&!r||!f||o&&!e&&u||i&&u)return-1}return 0}function R(n){return zn[n]}function W(n){return Mn[n]}function B(n){return\"\\\\\"+Fn[n]}function C(n,t,r){\nvar e=n.length;for(t+=r?0:-1;r?t--:++t-1&&0==n%1&&(null==t?9007199254740991:t)>n}function M(n){for(var t,r=[];!(t=n.next()).done;)r.push(t.value);return r}function L(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function $(n,t){for(var r=-1,e=n.length,u=0,o=[];++rr?false:(r==n.length-1?n.pop():Iu.call(n,r,1),true)}function qn(n,t){var r=Tn(n,t);return 0>r?q:n[r][1]}function Tn(n,t){for(var r=n.length;r--;)if(pe(n[r][0],t))return r;return-1}function Kn(n,t,r){var e=Tn(n,t);0>e?n.push([t,r]):n[e][1]=r}function Gn(n,t,r,e){return n===q||pe(n,cu[r])&&!lu.call(e,r)?t:n}function Yn(n,t,r){(r===q||pe(n[t],r))&&(typeof t!=\"number\"||r!==q||t in n)||(n[t]=r);\n}function Hn(n,t,r){var e=n[t];lu.call(n,t)&&pe(e,r)&&(r!==q||t in n)||(n[t]=r)}function Qn(n,t,r,e){return Qu(n,function(n,u,o){t(e,n,r(n),o)}),e}function Xn(n,t){return n&&tr(t,De(t),n)}function nt(n,t){for(var r=-1,e=null==n,u=t.length,o=Array(u);++rr?r:n),t!==q&&(n=t>n?t:n)),n}function ot(n,t,r,e,o,i,f){\nvar c;if(e&&(c=i?e(n,o,i,f):e(n)),c!==q)return c;if(!me(n))return n;if(o=qo(n)){if(c=Br(n),!t)return nr(n,c)}else{var a=Rr(n),l=\"[object Function]\"==a||\"[object GeneratorFunction]\"==a;if(Po(n))return Yt(n,t);if(\"[object Object]\"==a||\"[object Arguments]\"==a||l&&!i){if(U(n))return i?n:{};if(c=Cr(l?{}:n),!t)return c=Xn(c,n),r?er(n,c):c}else{if(!Un[a])return i?n:{};c=Ur(n,a,t)}}return f||(f=new Fn),(i=f.get(n))?i:(f.set(n,c),(o?u:_t)(n,function(u,o){Hn(c,o,ot(u,t,r,e,o,n,f))}),r&&!o?er(n,c):c)}function it(n){\nvar t=De(n),r=t.length;return function(e){if(null==e)return!r;for(var u=r;u--;){var o=t[u],i=n[o],f=e[o];if(f===q&&!(o in Object(e))||!i(f))return false}return true}}function ft(n){return me(n)?Ou(n):{}}function ct(n,t,r){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return Eu(function(){n.apply(q,r)},t)}function at(n,t,r,e){var u=-1,o=f,i=true,l=n.length,s=[],h=t.length;if(!l)return s;r&&(t=a(t,A(r))),e?(o=c,i=false):t.length>=200&&(o=$n,i=false,t=new Ln(t));n:for(;++u0&&de(i)&&(r||qo(i)||ve(i))?t>1?ht(i,t-1,r,e):l(e,i):r||(e[e.length]=i)}return e}function pt(n,t){null==n||no(n,t,Ze)}function _t(n,t){return n&&no(n,t,De)}function vt(n,t){return n&&to(n,t,De);\n}function gt(n,t){return i(t,function(t){return be(n[t])})}function dt(n,t){t=Lr(t,n)?[t+\"\"]:et(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:q}function yt(n,t){return lu.call(n,t)||typeof n==\"object\"&&t in n&&null===mu(n)}function bt(n,t){return t in Object(n)}function xt(n,t,r){for(var e=r?c:f,u=n[0].length,o=n.length,i=o,l=Array(o),s=1/0,h=[];i--;){var p=n[i];i&&t&&(p=a(p,A(t))),s=zu(p.length,s),l[i]=r||!t&&(120>u||120>p.length)?q:new Ln(i&&p)}var p=n[0],_=-1,v=l[0];n:for(;++_h.length;){\nvar g=p[_],d=t?t(g):g;if(v?!$n(v,d):!e(h,d,r)){for(i=o;--i;){var y=l[i];if(y?!$n(y,d):!e(n[i],d,r))continue n}v&&v.push(d),h.push(g)}}return h}function jt(n,t,r){var e={};return _t(n,function(n,u,o){t(e,r(n),u,o)}),e}function mt(n,t,e){return Lr(t,n)||(t=et(t),n=Zr(n,t),t=Vr(t)),t=null==n?n:n[t],null==t?q:r(t,n,e)}function wt(n,t,r,e,u){if(n===t)n=true;else if(null==n||null==t||!me(n)&&!we(t))n=n!==n&&t!==t;else n:{var o=qo(n),i=qo(t),f=\"[object Array]\",c=\"[object Array]\";o||(f=Rr(n),f=\"[object Arguments]\"==f?\"[object Object]\":f),\ni||(c=Rr(t),c=\"[object Arguments]\"==c?\"[object Object]\":c);var a=\"[object Object]\"==f&&!U(n),i=\"[object Object]\"==c&&!U(t);if((c=f==c)&&!a)u||(u=new Fn),n=o||Re(n)?wr(n,t,wt,r,e,u):Ar(n,t,f,wt,r,e,u);else{if(!(2&e)&&(o=a&&lu.call(n,\"__wrapped__\"),f=i&&lu.call(t,\"__wrapped__\"),o||f)){u||(u=new Fn),n=wt(o?n.value():n,f?t.value():t,r,e,u);break n}if(c)t:if(u||(u=new Fn),o=2&e,f=De(n),i=f.length,c=De(t).length,i==c||o){for(a=i;a--;){var l=f[a];if(!(o?l in t:yt(t,l))){n=false;break t}}if(c=u.get(n))n=c==t;else{\nc=true,u.set(n,t);for(var s=o;++ae?c*(\"desc\"==r[e]?-1:1):c;break n}}e=n.b-t.b}return e})}function Bt(n,t){return n=Object(n),s(t,function(t,r){return r in n&&(t[r]=n[r]),\nt},{})}function Ct(n,t){var r={};return pt(n,function(n,e){t(n,e)&&(r[e]=n)}),r}function Ut(n){return function(t){return null==t?q:t[n]}}function zt(n){return function(t){return dt(t,n)}}function Mt(n,t,r,e){var u=e?y:d,o=-1,i=t.length,f=n;for(r&&(f=a(n,A(r)));++ot&&(t=-t>u?0:u+t),r=r>u?u:r,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=Array(u);++e=u){for(;u>e;){var o=e+u>>>1,i=n[o];(r?t>=i:t>i)&&null!==i?e=o+1:u=o}return u}return qt(n,t,Ye,r)}function qt(n,t,r,e){t=r(t);for(var u=0,o=n?n.length:0,i=t!==t,f=null===t,c=t===q;o>u;){var a=Ru((u+o)/2),l=r(n[a]),s=l!==q,h=l===l;(i?h||e:f?h&&s&&(e||null!=l):c?h&&(e||s):null==l?0:e?t>=l:t>l)?u=a+1:o=a}return zu(o,4294967294)}function Pt(n,t){for(var r=0,e=n.length,u=n[0],o=t?t(u):u,i=o,f=1,c=[u];++re?t[e]:q);return i}function Yt(n,t){if(t)return n.slice();var r=new n.constructor(n.length);return n.copy(r),r}function Ht(n){var t=new n.constructor(n.byteLength);return new bu(t).set(new bu(n)),\nt}function Qt(n,t,r,e){var u=-1,o=n.length,i=r.length,f=-1,c=t.length,a=Uu(o-i,0),l=Array(c+a);for(e=!e;++fu)&&(l[r[u]]=n[u]);for(;a--;)l[f++]=n[u++];return l}function Xt(n,t,r,e){var u=-1,o=n.length,i=-1,f=r.length,c=-1,a=t.length,l=Uu(o-f,0),s=Array(l+a);for(e=!e;++uu)&&(s[l+r[i]]=n[u++]);return s}function nr(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r1?r[u-1]:q,i=u>2?r[2]:q,o=typeof o==\"function\"?(u--,o):q;for(i&&Mr(r[0],r[1],i)&&(o=3>u?q:o,u=1),t=Object(t);++ei&&f[0]!==a&&f[i-1]!==a?[]:$(f,a),i-=c.length,e>i?xr(n,t,_r,u.placeholder,q,f,c,q,q,e-i):r(this&&this!==Vn&&this instanceof u?o:n,this,f)}var o=sr(n);return u}function pr(n){return he(function(t){t=ht(t,1);var r=t.length,e=r,u=An.prototype.thru;for(n&&t.reverse();e--;){var o=t[e];if(typeof o!=\"function\")throw new iu(\"Expected a function\");if(u&&!i&&\"wrapper\"==Or(o))var i=new An([],true)}for(e=i?e:r;++e=200)return i.plant(e).value();for(var u=0,n=r?t[u].apply(this,n):e;++ud)return j=$(b,j),xr(n,t,_r,l.placeholder,r,b,j,f,c,a-d);if(j=h?r:this,y=p?j[n]:n,d=b.length,f){x=b.length;\nfor(var m=zu(f.length,x),w=nr(b);m--;){var A=f[m];b[m]=z(A,x)?w[A]:q}}else v&&d>1&&b.reverse();return s&&d>c&&(b.length=c),this&&this!==Vn&&this instanceof l&&(y=g||sr(y)),y.apply(j,b)}var s=128&t,h=1&t,p=2&t,_=24&t,v=512&t,g=p?q:sr(n);return l}function vr(n,t){return function(r,e){return jt(r,n,t(e))}}function gr(n){return he(function(t){return t=a(ht(t,1),kr()),he(function(e){var u=this;return n(t,function(n){return r(n,u,e)})})})}function dr(n,t,r){return t=Ce(t),n=N(n),t&&t>n?(t-=n,r=r===q?\" \":r+\"\",\nn=Ge(r,Su(t/N(r))),In.test(r)?n.match(En).slice(0,t).join(\"\"):n.slice(0,t)):\"\"}function yr(n,t,e,u){function o(){for(var t=-1,c=arguments.length,a=-1,l=u.length,s=Array(l+c),h=this&&this!==Vn&&this instanceof o?f:n;++at?1:-1:ze(e)||0;var u=-1;r=Uu(Su((r-t)/(e||1)),0);for(var o=Array(r);r--;)o[n?r:++u]=t,\nt+=e;return o}}function xr(n,t,r,e,u,o,i,f,c,a){var l=8&t;f=f?nr(f):q;var s=l?i:q;i=l?q:i;var h=l?o:q;return o=l?q:o,t=(t|(l?32:64))&~(l?64:32),4&t||(t&=-4),t=[n,t,u,h,s,o,i,f,c,a],r=r.apply(q,t),Fr(n)&&fo(r,t),r.placeholder=e,r}function jr(n){var t=uu[n];return function(n,r){if(n=ze(n),r=Ce(r)){var e=(Le(n)+\"e\").split(\"e\"),e=t(e[0]+\"e\"+(+e[1]+r)),e=(Le(e)+\"e\").split(\"e\");return+(e[0]+\"e\"+(+e[1]-r))}return t(n)}}function mr(n,t,r,e,u,o,i,f){var c=2&t;if(!c&&typeof n!=\"function\")throw new iu(\"Expected a function\");\nvar a=e?e.length:0;if(a||(t&=-97,e=u=q),i=i===q?i:Uu(Ce(i),0),f=f===q?f:Ce(f),a-=u?u.length:0,64&t){var l=e,s=u;e=u=q}var h=c?q:uo(n);return o=[n,t,r,e,u,l,s,o,i,f],h&&(r=o[1],n=h[1],t=r|n,e=128==n&&8==r||128==n&&256==r&&h[8]>=o[7].length||384==n&&h[8]>=h[7].length&&8==r,131>t||e)&&(1&n&&(o[2]=h[2],t|=1&r?0:4),(r=h[3])&&(e=o[3],o[3]=e?Qt(e,r,h[4]):nr(r),o[4]=e?$(o[3],\"__lodash_placeholder__\"):nr(h[4])),(r=h[5])&&(e=o[5],o[5]=e?Xt(e,r,h[6]):nr(r),o[6]=e?$(o[5],\"__lodash_placeholder__\"):nr(h[6])),(r=h[7])&&(o[7]=nr(r)),\n128&n&&(o[8]=null==o[8]?h[8]:zu(o[8],h[8])),null==o[9]&&(o[9]=h[9]),o[0]=h[0],o[1]=t),n=o[0],t=o[1],r=o[2],e=o[3],u=o[4],f=o[9]=null==o[9]?c?0:n.length:Uu(o[9]-a,0),!f&&24&t&&(t&=-25),(h?ro:fo)(t&&1!=t?8==t||16==t?hr(n,t,f):32!=t&&33!=t||u.length?_r.apply(q,o):yr(n,t,r,e):cr(n,t,r),o)}function wr(n,t,r,e,u,o){var i=-1,f=2&u,c=1&u,a=n.length,l=t.length;if(!(a==l||f&&l>a))return false;if(l=o.get(n))return l==t;for(l=true,o.set(n,t);++it?0:t,e)):[]}function Kr(n,t,r){var e=n?n.length:0;\nreturn e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0,0>t?0:t)):[]}function Gr(n){return n?n[0]:q}function Vr(n){var t=n?n.length:0;return t?n[t-1]:q}function Jr(n,t){return n&&n.length&&t&&t.length?Mt(n,t):n}function Yr(n){return n?$u.call(n):n}function Hr(n){if(!n||!n.length)return[];var t=0;return n=i(n,function(n){return de(n)?(t=Uu(n.length,t),true):void 0}),m(t,function(t){return a(n,Ut(t))})}function Qr(n,t){if(!n||!n.length)return[];var e=Hr(n);return null==t?e:a(e,function(n){return r(t,q,n)})}function Xr(n){\nreturn n=bn(n),n.__chain__=true,n}function ne(n,t){return t(n)}function te(){return this}function re(n,t){return typeof t==\"function\"&&qo(n)?u(n,t):Qu(n,rt(t))}function ee(n,t){var r;if(typeof t==\"function\"&&qo(n)){for(r=n.length;r--&&false!==t(n[r],r,n););r=n}else r=Xu(n,rt(t));return r}function ue(n,t){return(qo(n)?a:Et)(n,kr(t,3))}function oe(n,t){var r=-1,e=Be(n),u=e.length,o=u-1;for(t=ut(Ce(t),0,u);++r=n&&(t=q),r}}function ce(n,t,r){return t=r?q:t,n=mr(n,8,q,q,q,q,q,t),n.placeholder=ce.placeholder,n}function ae(n,t,r){return t=r?q:t,n=mr(n,16,q,q,q,q,q,t),n.placeholder=ae.placeholder,n}function le(n,t,r){function e(){p&&xu(p),a&&xu(a),v=0,c=a=h=p=_=q}function u(t,r){r&&xu(r),a=p=_=q,t&&(v=Uo(),l=n.apply(h,c),\np||a||(c=h=q))}function o(){var n=t-(Uo()-s);0>=n||n>t?u(_,a):p=Eu(o,n)}function i(){u(y,p)}function f(){if(c=arguments,s=Uo(),h=this,_=y&&(p||!g),false===d)var r=g&&!p;else{v||a||g||(v=s);var e=d-(s-v),u=(0>=e||e>d)&&(g||a);u?(a&&(a=xu(a)),v=s,l=n.apply(h,c)):a||(a=Eu(i,e))}return u&&p?p=xu(p):p||t===d||(p=Eu(o,t)),r&&(u=true,l=n.apply(h,c)),!u||p||a||(c=h=q),l}var c,a,l,s,h,p,_,v=0,g=false,d=false,y=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=ze(t)||0,me(r)&&(g=!!r.leading,d=\"maxWait\"in r&&Uu(ze(r.maxWait)||0,t),\ny=\"trailing\"in r?!!r.trailing:y),f.cancel=e,f.flush=function(){return(p&&_||a&&y)&&(l=n.apply(h,c)),e(),l},f}function se(n,t){function r(){var e=arguments,u=t?t.apply(this,e):e[0],o=r.cache;return o.has(u)?o.get(u):(e=n.apply(this,e),r.cache=o.set(u,e),e)}if(typeof n!=\"function\"||t&&typeof t!=\"function\")throw new iu(\"Expected a function\");return r.cache=new se.Cache,r}function he(n,t){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=Uu(t===q?n.length-1:Ce(t),0),function(){for(var e=arguments,u=-1,o=Uu(e.length-t,0),i=Array(o);++ut}function ve(n){return de(n)&&lu.call(n,\"callee\")&&(!ku.call(n,\"callee\")||\"[object Arguments]\"==pu.call(n))}function ge(n){return null!=n&&je(oo(n))&&!be(n)}function de(n){return we(n)&&ge(n)}function ye(n){return we(n)?\"[object Error]\"==pu.call(n)||typeof n.message==\"string\"&&typeof n.name==\"string\":false;\n}function be(n){return n=me(n)?pu.call(n):\"\",\"[object Function]\"==n||\"[object GeneratorFunction]\"==n}function xe(n){return typeof n==\"number\"&&n==Ce(n)}function je(n){return typeof n==\"number\"&&n>-1&&0==n%1&&9007199254740991>=n}function me(n){var t=typeof n;return!!n&&(\"object\"==t||\"function\"==t)}function we(n){return!!n&&typeof n==\"object\"}function Ae(n){return null==n?false:be(n)?vu.test(au.call(n)):we(n)&&(U(n)?vu:dn).test(n)}function Oe(n){return typeof n==\"number\"||we(n)&&\"[object Number]\"==pu.call(n);\n}function ke(n){return!we(n)||\"[object Object]\"!=pu.call(n)||U(n)?false:(n=mu(n),null===n?true:(n=n.constructor,typeof n==\"function\"&&n instanceof n&&au.call(n)==hu))}function Ee(n){return me(n)&&\"[object RegExp]\"==pu.call(n)}function Ie(n){return typeof n==\"string\"||!qo(n)&&we(n)&&\"[object String]\"==pu.call(n)}function Se(n){return typeof n==\"symbol\"||we(n)&&\"[object Symbol]\"==pu.call(n)}function Re(n){return we(n)&&je(n.length)&&!!Cn[pu.call(n)]}function We(n,t){return t>n}function Be(n){if(!n)return[];\nif(ge(n))return Ie(n)?n.match(En):nr(n);if(Au&&n[Au])return M(n[Au]());var t=Rr(n);return(\"[object Map]\"==t?L:\"[object Set]\"==t?F:Pe)(n)}function Ce(n){if(!n)return 0===n?n:0;if(n=ze(n),n===P||n===-P)return 1.7976931348623157e308*(0>n?-1:1);var t=n%1;return n===n?t?n-t:n:0}function Ue(n){return n?ut(Ce(n),0,4294967295):0}function ze(n){if(me(n)&&(n=be(n.valueOf)?n.valueOf():n,n=me(n)?n+\"\":n),typeof n!=\"string\")return 0===n?n:+n;n=n.replace(cn,\"\");var t=gn.test(n);return t||yn.test(n)?Dn(n.slice(2),t?2:8):vn.test(n)?T:+n;\n}function Me(n){return tr(n,Ze(n))}function Le(n){if(typeof n==\"string\")return n;if(null==n)return\"\";if(Se(n))return Hu?Hu.call(n):\"\";var t=n+\"\";return\"0\"==t&&1/n==-P?\"-0\":t}function $e(n,t,r){return n=null==n?q:dt(n,t),n===q?r:n}function Fe(n,t){return Wr(n,t,yt)}function Ne(n,t){return Wr(n,t,bt)}function De(n){var t=Nr(n);if(!t&&!ge(n))return Cu(Object(n));var r,e=zr(n),u=!!e,e=e||[],o=e.length;for(r in n)!yt(n,r)||u&&(\"length\"==r||z(r,o))||t&&\"constructor\"==r||e.push(r);return e}function Ze(n){\nfor(var t=-1,r=Nr(n),e=kt(n),u=e.length,o=zr(n),i=!!o,o=o||[],f=o.length;++tt||t>9007199254740991)return r;do t%2&&(r+=n),t=Ru(t/2),n+=n;while(t);return r}function Ve(n,t,r){\nreturn n=Le(n),t=r?q:t,t===q&&(t=Wn.test(n)?Rn:Sn),n.match(t)||[]}function Je(n){return function(){return n}}function Ye(n){return n}function He(n){return Ot(typeof n==\"function\"?n:ot(n,true))}function Qe(n,t,r){var e=De(t),o=gt(t,e);null!=r||me(t)&&(o.length||!e.length)||(r=t,t=n,n=this,o=gt(t,De(t)));var i=me(r)&&\"chain\"in r?r.chain:true,f=be(n);return u(o,function(r){var e=t[r];n[r]=e,f&&(n.prototype[r]=function(){var t=this.__chain__;if(i||t){var r=n(this.__wrapped__);return(r.__actions__=nr(this.__actions__)).push({\nfunc:e,args:arguments,thisArg:n}),r.__chain__=t,r}return e.apply(n,l([this.value()],arguments))})}),n}function Xe(){}function nu(n){return Lr(n)?Ut(n):zt(n)}function tu(n){return n&&n.length?j(n,Ye):0}I=I?Jn.defaults({},I,Jn.pick(Vn,Bn)):Vn;var ru=I.Date,eu=I.Error,uu=I.Math,ou=I.RegExp,iu=I.TypeError,fu=I.Array.prototype,cu=I.Object.prototype,au=I.Function.prototype.toString,lu=cu.hasOwnProperty,su=0,hu=au.call(Object),pu=cu.toString,_u=Vn._,vu=ou(\"^\"+au.call(lu).replace(on,\"\\\\$&\").replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g,\"$1.*?\")+\"$\"),gu=Pn?I.Buffer:q,du=I.Reflect,yu=I.Symbol,bu=I.Uint8Array,xu=I.clearTimeout,ju=du?du.f:q,mu=Object.getPrototypeOf,wu=Object.getOwnPropertySymbols,Au=typeof(Au=yu&&yu.iterator)==\"symbol\"?Au:q,Ou=Object.create,ku=cu.propertyIsEnumerable,Eu=I.setTimeout,Iu=fu.splice,Su=uu.ceil,Ru=uu.floor,Wu=I.isFinite,Bu=fu.join,Cu=Object.keys,Uu=uu.max,zu=uu.min,Mu=I.parseInt,Lu=uu.random,$u=fu.reverse,Fu=Ir(I,\"Map\"),Nu=Ir(I,\"Set\"),Du=Ir(I,\"WeakMap\"),Zu=Ir(Object,\"create\"),qu=Du&&new Du,Pu=!ku.call({\nvalueOf:1},\"valueOf\"),Tu={},Ku=Fu?au.call(Fu):\"\",Gu=Nu?au.call(Nu):\"\",Vu=Du?au.call(Du):\"\",Ju=yu?yu.prototype:q,Yu=Ju?Ju.valueOf:q,Hu=Ju?Ju.toString:q;bn.templateSettings={escape:X,evaluate:nn,interpolate:tn,variable:\"\",imports:{_:bn}};var Qu=ir(_t),Xu=ir(vt,true),no=fr(),to=fr(true);ju&&!ku.call({valueOf:1},\"valueOf\")&&(kt=function(n){return M(ju(n))});var ro=qu?function(n,t){return qu.set(n,t),n}:Ye,eo=Nu&&2===new Nu([1,2]).size?function(n){return new Nu(n)}:Xe,uo=qu?function(n){return qu.get(n)}:Xe,oo=Ut(\"length\"),io=wu||function(){\nreturn[]};(Fu&&\"[object Map]\"!=Rr(new Fu)||Nu&&\"[object Set]\"!=Rr(new Nu)||Du&&\"[object WeakMap]\"!=Rr(new Du))&&(Rr=function(n){var t=pu.call(n);if(n=\"[object Object]\"==t?n.constructor:null,n=typeof n==\"function\"?au.call(n):\"\")switch(n){case Ku:return\"[object Map]\";case Gu:return\"[object Set]\";case Vu:return\"[object WeakMap]\"}return t});var fo=function(){var n=0,t=0;return function(r,e){var u=Uo(),o=16-(u-t);if(t=u,o>0){if(150<=++n)return r}else n=0;return ro(r,e)}}(),co=he(function(n,t){qo(n)||(n=null==n?[]:[Object(n)]),\nt=ht(t,1);for(var r=n,e=t,u=-1,o=r.length,i=-1,f=e.length,c=Array(o+f);++u1?n[t-1]:q,t=typeof t==\"function\"?(n.pop(),t):q;return Qr(n,t)}),Eo=he(function(n){function t(t){return nt(t,n)}n=ht(n,1);var r=n.length,e=r?n[0]:0,u=this.__wrapped__;return 1>=r&&!this.__actions__.length&&u instanceof On&&z(e)?(u=u.slice(e,+e+(r?1:0)),u.__actions__.push({func:ne,args:[t],thisArg:q}),new An(u,this.__chain__).thru(function(n){return r&&!n.length&&n.push(q),\nn})):this.thru(t)}),Io=ur(function(n,t,r){lu.call(n,r)?++n[r]:n[r]=1}),So=ur(function(n,t,r){lu.call(n,r)?n[r].push(t):n[r]=[t]}),Ro=he(function(n,t,e){var u=-1,o=typeof t==\"function\",i=Lr(t),f=ge(n)?Array(n.length):[];return Qu(n,function(n){var c=o?t:i&&null!=n?n[t]:q;f[++u]=c?r(c,n,e):mt(n,t,e)}),f}),Wo=ur(function(n,t,r){n[r]=t}),Bo=ur(function(n,t,r){n[r?0:1].push(t)},function(){return[[],[]]}),Co=he(function(n,t){if(null==n)return[];var r=t.length;return r>1&&Mr(n,t[0],t[1])?t=[]:r>2&&Mr(t[0],t[1],t[2])&&(t.length=1),\nWt(n,ht(t,1),[])}),Uo=ru.now,zo=he(function(n,t,r){var e=1;if(r.length)var u=$(r,Sr(zo)),e=32|e;return mr(n,e,t,r,u)}),Mo=he(function(n,t,r){var e=3;if(r.length)var u=$(r,Sr(Mo)),e=32|e;return mr(t,e,n,r,u)}),Lo=he(function(n,t){return ct(n,1,t)}),$o=he(function(n,t,r){return ct(n,ze(t)||0,r)}),Fo=he(function(n,t){t=a(ht(t,1),kr());var e=t.length;return he(function(u){for(var o=-1,i=zu(u.length,e);++oe.length?Kn(e,n,t):(r.array=null,r.map=new Mn(e))),(r=r.map)&&r.set(n,t),this},se.Cache=Mn,bn.after=function(n,t){if(typeof t!=\"function\")throw new iu(\"Expected a function\");return n=Ce(n),function(){return 1>--n?t.apply(this,arguments):void 0}},bn.ary=ie,bn.assign=To,bn.assignIn=Ko,\nbn.assignInWith=Go,bn.assignWith=Vo,bn.at=Jo,bn.before=fe,bn.bind=zo,bn.bindAll=_i,bn.bindKey=Mo,bn.castArray=function(){if(!arguments.length)return[];var n=arguments[0];return qo(n)?n:[n]},bn.chain=Xr,bn.chunk=function(n,t){t=Uu(Ce(t),0);var r=n?n.length:0;if(!r||1>t)return[];for(var e=0,u=0,o=Array(Su(r/t));r>e;)o[u++]=Nt(n,e,e+=t);return o},bn.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++tr&&(r=-r>u?0:u+r),e=e===q||e>u?u:Ce(e),0>e&&(e+=u),e=r>e?0:Ue(e);e>r;)n[r++]=t;return n},bn.filter=function(n,t){return(qo(n)?i:st)(n,kr(t,3))},bn.flatMap=function(n,t){return ht(ue(n,t),1)},bn.flatten=function(n){\nreturn n&&n.length?ht(n,1):[]},bn.flattenDeep=function(n){return n&&n.length?ht(n,P):[]},bn.flattenDepth=function(n,t){return n&&n.length?(t=t===q?1:Ce(t),ht(n,t)):[]},bn.flip=function(n){return mr(n,512)},bn.flow=vi,bn.flowRight=gi,bn.fromPairs=function(n){for(var t=-1,r=n?n.length:0,e={};++tt?0:t)):[]},bn.takeRight=function(n,t,r){var e=n?n.length:0;return e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0>t?0:t,e)):[]},bn.takeRightWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3),false,true):[]},bn.takeWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3)):[]},bn.tap=function(n,t){return t(n),n},bn.throttle=function(n,t,r){var e=true,u=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return me(r)&&(e=\"leading\"in r?!!r.leading:e,u=\"trailing\"in r?!!r.trailing:u),le(n,t,{leading:e,maxWait:t,\ntrailing:u})},bn.thru=ne,bn.toArray=Be,bn.toPairs=qe,bn.toPairsIn=function(n){return w(n,Ze(n))},bn.toPath=function(n){return qo(n)?a(n,String):qr(n)},bn.toPlainObject=Me,bn.transform=function(n,t,r){var e=qo(n)||Re(n);if(t=kr(t,4),null==r)if(e||me(n)){var o=n.constructor;r=e?qo(n)?new o:[]:be(o)?ft(mu(n)):{}}else r={};return(e?u:_t)(n,function(n,e,u){return t(r,n,e,u)}),r},bn.unary=function(n){return ie(n,1)},bn.union=yo,bn.unionBy=bo,bn.unionWith=xo,bn.uniq=function(n){return n&&n.length?Tt(n):[];\n},bn.uniqBy=function(n,t){return n&&n.length?Tt(n,kr(t)):[]},bn.uniqWith=function(n,t){return n&&n.length?Tt(n,q,t):[]},bn.unset=function(n,t){var r;if(null==n)r=true;else{r=n;var e=t,e=Lr(e,r)?[e+\"\"]:et(e);r=Zr(r,e),e=Vr(e),r=null!=r&&Fe(r,e)?delete r[e]:true}return r},bn.unzip=Hr,bn.unzipWith=Qr,bn.update=function(n,t,r){return null==n?n:Ft(n,t,rt(r)(dt(n,t)),void 0)},bn.updateWith=function(n,t,r,e){return e=typeof e==\"function\"?e:q,null!=n&&(n=Ft(n,t,rt(r)(dt(n,t)),e)),n},bn.values=Pe,bn.valuesIn=function(n){\nreturn null==n?[]:O(n,Ze(n))},bn.without=jo,bn.words=Ve,bn.wrap=function(n,t){return t=null==t?Ye:t,No(t,n)},bn.xor=mo,bn.xorBy=wo,bn.xorWith=Ao,bn.zip=Oo,bn.zipObject=function(n,t){return Jt(n||[],t||[],Hn)},bn.zipObjectDeep=function(n,t){return Jt(n||[],t||[],Ft)},bn.zipWith=ko,bn.extend=Ko,bn.extendWith=Go,Qe(bn,bn),bn.add=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r+t),r)},bn.attempt=pi,bn.camelCase=oi,bn.capitalize=Te,bn.ceil=Ai,bn.clamp=function(n,t,r){return r===q&&(r=t,\nt=q),r!==q&&(r=ze(r),r=r===r?r:0),t!==q&&(t=ze(t),t=t===t?t:0),ut(ze(n),t,r)},bn.clone=function(n){return ot(n,false,true)},bn.cloneDeep=function(n){return ot(n,true,true)},bn.cloneDeepWith=function(n,t){return ot(n,true,true,t)},bn.cloneWith=function(n,t){return ot(n,false,true,t)},bn.deburr=Ke,bn.endsWith=function(n,t,r){n=Le(n),t=typeof t==\"string\"?t:t+\"\";var e=n.length;return r=r===q?e:ut(Ce(r),0,e),r-=t.length,r>=0&&n.indexOf(t,r)==r},bn.eq=pe,bn.escape=function(n){return(n=Le(n))&&Q.test(n)?n.replace(Y,W):n},\nbn.escapeRegExp=function(n){return(n=Le(n))&&fn.test(n)?n.replace(on,\"\\\\$&\"):n},bn.every=function(n,t,r){var e=qo(n)?o:lt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.find=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t);return r>-1?n[r]:q}return v(n,t,Qu)},bn.findIndex=function(n,t){return n&&n.length?g(n,kr(t,3)):-1},bn.findKey=function(n,t){return v(n,kr(t,3),_t,true)},bn.findLast=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t,true);return r>-1?n[r]:q}return v(n,t,Xu)},bn.findLastIndex=function(n,t){return n&&n.length?g(n,kr(t,3),true):-1;\n},bn.findLastKey=function(n,t){return v(n,kr(t,3),vt,true)},bn.floor=Oi,bn.forEach=re,bn.forEachRight=ee,bn.forIn=function(n,t){return null==n?n:no(n,rt(t),Ze)},bn.forInRight=function(n,t){return null==n?n:to(n,rt(t),Ze)},bn.forOwn=function(n,t){return n&&_t(n,rt(t))},bn.forOwnRight=function(n,t){return n&&vt(n,rt(t))},bn.get=$e,bn.gt=_e,bn.gte=function(n,t){return n>=t},bn.has=Fe,bn.hasIn=Ne,bn.head=Gr,bn.identity=Ye,bn.includes=function(n,t,r,e){return n=ge(n)?n:Pe(n),r=r&&!e?Ce(r):0,e=n.length,0>r&&(r=Uu(e+r,0)),\nIe(n)?e>=r&&-1r&&(r=Uu(e+r,0)),d(n,t,r)):-1},bn.inRange=function(n,t,r){return t=ze(t)||0,r===q?(r=t,t=0):r=ze(r)||0,n=ze(n),n>=zu(t,r)&&n=-9007199254740991&&9007199254740991>=n;\n},bn.isSet=function(n){return we(n)&&\"[object Set]\"==Rr(n)},bn.isString=Ie,bn.isSymbol=Se,bn.isTypedArray=Re,bn.isUndefined=function(n){return n===q},bn.isWeakMap=function(n){return we(n)&&\"[object WeakMap]\"==Rr(n)},bn.isWeakSet=function(n){return we(n)&&\"[object WeakSet]\"==pu.call(n)},bn.join=function(n,t){return n?Bu.call(n,t):\"\"},bn.kebabCase=ii,bn.last=Vr,bn.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(r!==q&&(u=Ce(r),u=(0>u?Uu(e+u,0):zu(u,e-1))+1),t!==t)return C(n,u,true);\nfor(;u--;)if(n[u]===t)return u;return-1},bn.lowerCase=fi,bn.lowerFirst=ci,bn.lt=We,bn.lte=function(n,t){return t>=n},bn.max=function(n){return n&&n.length?_(n,Ye,_e):q},bn.maxBy=function(n,t){return n&&n.length?_(n,kr(t),_e):q},bn.mean=function(n){return tu(n)/(n?n.length:0)},bn.min=function(n){return n&&n.length?_(n,Ye,We):q},bn.minBy=function(n,t){return n&&n.length?_(n,kr(t),We):q},bn.noConflict=function(){return Vn._===this&&(Vn._=_u),this},bn.noop=Xe,bn.now=Uo,bn.pad=function(n,t,r){n=Le(n),\nt=Ce(t);var e=N(n);return t&&t>e?(e=(t-e)/2,t=Ru(e),e=Su(e),dr(\"\",t,r)+n+dr(\"\",e,r)):n},bn.padEnd=function(n,t,r){return n=Le(n),n+dr(n,t,r)},bn.padStart=function(n,t,r){return n=Le(n),dr(n,t,r)+n},bn.parseInt=function(n,t,r){return r||null==t?t=0:t&&(t=+t),n=Le(n).replace(cn,\"\"),Mu(n,t||(_n.test(n)?16:10))},bn.random=function(n,t,r){if(r&&typeof r!=\"boolean\"&&Mr(n,t,r)&&(t=r=q),r===q&&(typeof t==\"boolean\"?(r=t,t=q):typeof n==\"boolean\"&&(r=n,n=q)),n===q&&t===q?(n=0,t=1):(n=ze(n)||0,t===q?(t=n,n=0):t=ze(t)||0),\nn>t){var e=n;n=t,t=e}return r||n%1||t%1?(r=Lu(),zu(n+r*(t-n+Nn(\"1e-\"+((r+\"\").length-1))),t)):$t(n,t)},bn.reduce=function(n,t,r){var e=qo(n)?s:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Qu)},bn.reduceRight=function(n,t,r){var e=qo(n)?h:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Xu)},bn.repeat=Ge,bn.replace=function(){var n=arguments,t=Le(n[0]);return 3>n.length?t:t.replace(n[1],n[2])},bn.result=function(n,t,r){if(Lr(t,n))e=null==n?q:n[t];else{t=et(t);var e=$e(n,t);n=Zr(n,t)}return e===q&&(e=r),\nbe(e)?e.call(n):e},bn.round=ki,bn.runInContext=Z,bn.sample=function(n){n=ge(n)?n:Pe(n);var t=n.length;return t>0?n[$t(0,t-1)]:q},bn.size=function(n){if(null==n)return 0;if(ge(n)){var t=n.length;return t&&Ie(n)?N(n):t}return De(n).length},bn.snakeCase=li,bn.some=function(n,t,r){var e=qo(n)?p:Dt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.sortedIndex=function(n,t){return Zt(n,t)},bn.sortedIndexBy=function(n,t,r){return qt(n,t,kr(r))},bn.sortedIndexOf=function(n,t){var r=n?n.length:0;if(r){var e=Zt(n,t);\nif(r>e&&pe(n[e],t))return e}return-1},bn.sortedLastIndex=function(n,t){return Zt(n,t,true)},bn.sortedLastIndexBy=function(n,t,r){return qt(n,t,kr(r),true)},bn.sortedLastIndexOf=function(n,t){if(n&&n.length){var r=Zt(n,t,true)-1;if(pe(n[r],t))return r}return-1},bn.startCase=si,bn.startsWith=function(n,t,r){return n=Le(n),r=ut(Ce(r),0,n.length),n.lastIndexOf(t,r)==r},bn.subtract=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r-t),r)},bn.sum=tu,bn.sumBy=function(n,t){return n&&n.length?j(n,kr(t)):0;\n},bn.template=function(n,t,r){var e=bn.templateSettings;r&&Mr(n,t,r)&&(t=q),n=Le(n),t=Go({},t,e,Gn),r=Go({},t.imports,e.imports,Gn);var u,o,i=De(r),f=O(r,i),c=0;r=t.interpolate||jn;var a=\"__p+='\";r=ou((t.escape||jn).source+\"|\"+r.source+\"|\"+(r===tn?hn:jn).source+\"|\"+(t.evaluate||jn).source+\"|$\",\"g\");var l=\"sourceURL\"in t?\"//# sourceURL=\"+t.sourceURL+\"\\n\":\"\";if(n.replace(r,function(t,r,e,i,f,l){return e||(e=i),a+=n.slice(c,l).replace(mn,B),r&&(u=true,a+=\"'+__e(\"+r+\")+'\"),f&&(o=true,a+=\"';\"+f+\";\\n__p+='\"),\ne&&(a+=\"'+((__t=(\"+e+\"))==null?'':__t)+'\"),c=l+t.length,t}),a+=\"';\",(t=t.variable)||(a=\"with(obj){\"+a+\"}\"),a=(o?a.replace(K,\"\"):a).replace(G,\"$1\").replace(V,\"$1;\"),a=\"function(\"+(t||\"obj\")+\"){\"+(t?\"\":\"obj||(obj={});\")+\"var __t,__p=''\"+(u?\",__e=_.escape\":\"\")+(o?\",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}\":\";\")+a+\"return __p}\",t=pi(function(){return Function(i,l+\"return \"+a).apply(q,f)}),t.source=a,ye(t))throw t;return t},bn.times=function(n,t){if(n=Ce(n),1>n||n>9007199254740991)return[];\nvar r=4294967295,e=zu(n,4294967295);for(t=rt(t),n-=4294967295,e=m(e,t);++r=o)return n;if(o=r-N(e),1>o)return e;\nif(r=i?i.slice(0,o).join(\"\"):n.slice(0,o),u===q)return r+e;if(i&&(o+=r.length-o),Ee(u)){if(n.slice(o).search(u)){var f=r;for(u.global||(u=ou(u.source,Le(pn.exec(u))+\"g\")),u.lastIndex=0;i=u.exec(f);)var c=i.index;r=r.slice(0,c===q?o:c)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),u>-1&&(r=r.slice(0,u)));return r+e},bn.unescape=function(n){return(n=Le(n))&&H.test(n)?n.replace(J,D):n},bn.uniqueId=function(n){var t=++su;return Le(n)+t},bn.upperCase=hi,bn.upperFirst=ai,bn.each=re,bn.eachRight=ee,bn.first=Gr,\nQe(bn,function(){var n={};return _t(bn,function(t,r){lu.call(bn.prototype,r)||(n[r]=t)}),n}(),{chain:false}),bn.VERSION=\"4.6.1\",u(\"bind bindKey curry curryRight partial partialRight\".split(\" \"),function(n){bn[n].placeholder=bn}),u([\"drop\",\"take\"],function(n,t){On.prototype[n]=function(r){var e=this.__filtered__;if(e&&!t)return new On(this);r=r===q?1:Uu(Ce(r),0);var u=this.clone();return e?u.__takeCount__=zu(r,u.__takeCount__):u.__views__.push({size:zu(r,4294967295),type:n+(0>u.__dir__?\"Right\":\"\")}),\nu},On.prototype[n+\"Right\"]=function(t){return this.reverse()[n](t).reverse()}}),u([\"filter\",\"map\",\"takeWhile\"],function(n,t){var r=t+1,e=1==r||3==r;On.prototype[n]=function(n){var t=this.clone();return t.__iteratees__.push({iteratee:kr(n,3),type:r}),t.__filtered__=t.__filtered__||e,t}}),u([\"head\",\"last\"],function(n,t){var r=\"take\"+(t?\"Right\":\"\");On.prototype[n]=function(){return this[r](1).value()[0]}}),u([\"initial\",\"tail\"],function(n,t){var r=\"drop\"+(t?\"\":\"Right\");On.prototype[n]=function(){return this.__filtered__?new On(this):this[r](1);\n}}),On.prototype.compact=function(){return this.filter(Ye)},On.prototype.find=function(n){return this.filter(n).head()},On.prototype.findLast=function(n){return this.reverse().find(n)},On.prototype.invokeMap=he(function(n,t){return typeof n==\"function\"?new On(this):this.map(function(r){return mt(r,n,t)})}),On.prototype.reject=function(n){return n=kr(n,3),this.filter(function(t){return!n(t)})},On.prototype.slice=function(n,t){n=Ce(n);var r=this;return r.__filtered__&&(n>0||0>t)?new On(r):(0>n?r=r.takeRight(-n):n&&(r=r.drop(n)),\nt!==q&&(t=Ce(t),r=0>t?r.dropRight(-t):r.take(t-n)),r)},On.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},On.prototype.toArray=function(){return this.take(4294967295)},_t(On.prototype,function(n,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),e=/^(?:head|last)$/.test(t),u=bn[e?\"take\"+(\"last\"==t?\"Right\":\"\"):t],o=e||/^find/.test(t);u&&(bn.prototype[t]=function(){function t(n){return n=u.apply(bn,l([n],f)),e&&h?n[0]:n}var i=this.__wrapped__,f=e?[1]:arguments,c=i instanceof On,a=f[0],s=c||qo(i);\ns&&r&&typeof a==\"function\"&&1!=a.length&&(c=s=false);var h=this.__chain__,p=!!this.__actions__.length,a=o&&!h,c=c&&!p;return!o&&s?(i=c?i:new On(this),i=n.apply(i,f),i.__actions__.push({func:ne,args:[t],thisArg:q}),new An(i,h)):a&&c?n.apply(this,f):(i=this.thru(t),a?e?i.value()[0]:i.value():i)})}),u(\"pop push shift sort splice unshift\".split(\" \"),function(n){var t=fu[n],r=/^(?:push|sort|unshift)$/.test(n)?\"tap\":\"thru\",e=/^(?:pop|shift)$/.test(n);bn.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){\nreturn t.apply(r,n)})}}),_t(On.prototype,function(n,t){var r=bn[t];if(r){var e=r.name+\"\";(Tu[e]||(Tu[e]=[])).push({name:t,func:r})}}),Tu[_r(q,2).name]=[{name:\"wrapper\",func:q}],On.prototype.clone=function(){var n=new On(this.__wrapped__);return n.__actions__=nr(this.__actions__),n.__dir__=this.__dir__,n.__filtered__=this.__filtered__,n.__iteratees__=nr(this.__iteratees__),n.__takeCount__=this.__takeCount__,n.__views__=nr(this.__views__),n},On.prototype.reverse=function(){if(this.__filtered__){var n=new On(this);\nn.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},On.prototype.value=function(){var n,t=this.__wrapped__.value(),r=this.__dir__,e=qo(t),u=0>r,o=e?t.length:0;n=o;for(var i=this.__views__,f=0,c=-1,a=i.length;++co||o==n&&a==n)return Gt(t,this.__actions__);\ne=[];n:for(;n--&&a>c;){for(u+=r,o=-1,l=t[u];++o=this.__values__.length,t=n?q:this.__values__[this.__index__++];\nreturn{done:n,value:t}},bn.prototype.plant=function(n){for(var t,r=this;r instanceof wn;){var e=Pr(r);e.__index__=0,e.__values__=q,t?u.__wrapped__=e:t=e;var u=e,r=r.__wrapped__}return u.__wrapped__=n,t},bn.prototype.reverse=function(){var n=this.__wrapped__;return n instanceof On?(this.__actions__.length&&(n=new On(this)),n=n.reverse(),n.__actions__.push({func:ne,args:[Yr],thisArg:q}),new An(n,this.__chain__)):this.thru(Yr)},bn.prototype.toJSON=bn.prototype.valueOf=bn.prototype.value=function(){return Gt(this.__wrapped__,this.__actions__);\n},Au&&(bn.prototype[Au]=te),bn}var q,P=1/0,T=NaN,K=/\\b__p\\+='';/g,G=/\\b(__p\\+=)''\\+/g,V=/(__e\\(.*?\\)|\\b__t\\))\\+'';/g,J=/&(?:amp|lt|gt|quot|#39|#96);/g,Y=/[&<>\"'`]/g,H=RegExp(J.source),Q=RegExp(Y.source),X=/<%-([\\s\\S]+?)%>/g,nn=/<%([\\s\\S]+?)%>/g,tn=/<%=([\\s\\S]+?)%>/g,rn=/\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,en=/^\\w*$/,un=/[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]/g,on=/[\\\\^$.*+?()[\\]{}|]/g,fn=RegExp(on.source),cn=/^\\s+|\\s+$/g,an=/^\\s+/,ln=/\\s+$/,sn=/\\\\(\\\\)?/g,hn=/\\$\\{([^\\\\}]*(?:\\\\.[^\\\\}]*)*)\\}/g,pn=/\\w*$/,_n=/^0x/i,vn=/^[-+]0x[0-9a-f]+$/i,gn=/^0b[01]+$/i,dn=/^\\[object .+?Constructor\\]$/,yn=/^0o[0-7]+$/i,bn=/^(?:0|[1-9]\\d*)$/,xn=/[\\xc0-\\xd6\\xd8-\\xde\\xdf-\\xf6\\xf8-\\xff]/g,jn=/($^)/,mn=/['\\n\\r\\u2028\\u2029\\\\]/g,wn=\"[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?(?:\\\\u200d(?:[^\\\\ud800-\\\\udfff]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?)*\",An=\"(?:[\\\\u2700-\\\\u27bf]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])\"+wn,On=\"(?:[^\\\\ud800-\\\\udfff][\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]?|[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff]|[\\\\ud800-\\\\udfff])\",kn=RegExp(\"[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]\",\"g\"),En=RegExp(\"\\\\ud83c[\\\\udffb-\\\\udfff](?=\\\\ud83c[\\\\udffb-\\\\udfff])|\"+On+wn,\"g\"),In=RegExp(\"[\\\\u200d\\\\ud800-\\\\udfff\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0\\\\ufe0e\\\\ufe0f]\"),Sn=/[a-zA-Z0-9]+/g,Rn=RegExp([\"[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|$)|(?:[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde](?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])|$)|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?(?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]+|\\\\d+\",An].join(\"|\"),\"g\"),Wn=/[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Bn=\"Array Buffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Reflect RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout\".split(\" \"),Cn={};\nCn[\"[object Float32Array]\"]=Cn[\"[object Float64Array]\"]=Cn[\"[object Int8Array]\"]=Cn[\"[object Int16Array]\"]=Cn[\"[object Int32Array]\"]=Cn[\"[object Uint8Array]\"]=Cn[\"[object Uint8ClampedArray]\"]=Cn[\"[object Uint16Array]\"]=Cn[\"[object Uint32Array]\"]=true,Cn[\"[object Arguments]\"]=Cn[\"[object Array]\"]=Cn[\"[object ArrayBuffer]\"]=Cn[\"[object Boolean]\"]=Cn[\"[object Date]\"]=Cn[\"[object Error]\"]=Cn[\"[object Function]\"]=Cn[\"[object Map]\"]=Cn[\"[object Number]\"]=Cn[\"[object Object]\"]=Cn[\"[object RegExp]\"]=Cn[\"[object Set]\"]=Cn[\"[object String]\"]=Cn[\"[object WeakMap]\"]=false;\nvar Un={};Un[\"[object Arguments]\"]=Un[\"[object Array]\"]=Un[\"[object ArrayBuffer]\"]=Un[\"[object Boolean]\"]=Un[\"[object Date]\"]=Un[\"[object Float32Array]\"]=Un[\"[object Float64Array]\"]=Un[\"[object Int8Array]\"]=Un[\"[object Int16Array]\"]=Un[\"[object Int32Array]\"]=Un[\"[object Map]\"]=Un[\"[object Number]\"]=Un[\"[object Object]\"]=Un[\"[object RegExp]\"]=Un[\"[object Set]\"]=Un[\"[object String]\"]=Un[\"[object Symbol]\"]=Un[\"[object Uint8Array]\"]=Un[\"[object Uint8ClampedArray]\"]=Un[\"[object Uint16Array]\"]=Un[\"[object Uint32Array]\"]=true,\nUn[\"[object Error]\"]=Un[\"[object Function]\"]=Un[\"[object WeakMap]\"]=false;var zn={\"\\xc0\":\"A\",\"\\xc1\":\"A\",\"\\xc2\":\"A\",\"\\xc3\":\"A\",\"\\xc4\":\"A\",\"\\xc5\":\"A\",\"\\xe0\":\"a\",\"\\xe1\":\"a\",\"\\xe2\":\"a\",\"\\xe3\":\"a\",\"\\xe4\":\"a\",\"\\xe5\":\"a\",\"\\xc7\":\"C\",\"\\xe7\":\"c\",\"\\xd0\":\"D\",\"\\xf0\":\"d\",\"\\xc8\":\"E\",\"\\xc9\":\"E\",\"\\xca\":\"E\",\"\\xcb\":\"E\",\"\\xe8\":\"e\",\"\\xe9\":\"e\",\"\\xea\":\"e\",\"\\xeb\":\"e\",\"\\xcc\":\"I\",\"\\xcd\":\"I\",\"\\xce\":\"I\",\"\\xcf\":\"I\",\"\\xec\":\"i\",\"\\xed\":\"i\",\"\\xee\":\"i\",\"\\xef\":\"i\",\"\\xd1\":\"N\",\"\\xf1\":\"n\",\"\\xd2\":\"O\",\"\\xd3\":\"O\",\"\\xd4\":\"O\",\"\\xd5\":\"O\",\"\\xd6\":\"O\",\n\"\\xd8\":\"O\",\"\\xf2\":\"o\",\"\\xf3\":\"o\",\"\\xf4\":\"o\",\"\\xf5\":\"o\",\"\\xf6\":\"o\",\"\\xf8\":\"o\",\"\\xd9\":\"U\",\"\\xda\":\"U\",\"\\xdb\":\"U\",\"\\xdc\":\"U\",\"\\xf9\":\"u\",\"\\xfa\":\"u\",\"\\xfb\":\"u\",\"\\xfc\":\"u\",\"\\xdd\":\"Y\",\"\\xfd\":\"y\",\"\\xff\":\"y\",\"\\xc6\":\"Ae\",\"\\xe6\":\"ae\",\"\\xde\":\"Th\",\"\\xfe\":\"th\",\"\\xdf\":\"ss\"},Mn={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\",\"`\":\"`\"},Ln={\"&\":\"&\",\"<\":\"<\",\">\":\">\",\""\":'\"',\"'\":\"'\",\"`\":\"`\"},$n={\"function\":true,object:true},Fn={\"\\\\\":\"\\\\\",\"'\":\"'\",\"\\n\":\"n\",\"\\r\":\"r\",\"\\u2028\":\"u2028\",\"\\u2029\":\"u2029\"\n},Nn=parseFloat,Dn=parseInt,Zn=$n[typeof exports]&&exports&&!exports.nodeType?exports:q,qn=$n[typeof module]&&module&&!module.nodeType?module:q,Pn=qn&&qn.exports===Zn?Zn:q,Tn=I($n[typeof self]&&self),Kn=I($n[typeof window]&&window),Gn=I($n[typeof this]&&this),Vn=I(Zn&&qn&&typeof global==\"object\"&&global)||Kn!==(Gn&&Gn.window)&&Kn||Tn||Gn||Function(\"return this\")(),Jn=Z();(Kn||Tn||{})._=Jn,typeof define==\"function\"&&typeof define.amd==\"object\"&&define.amd? define(function(){return Jn}):Zn&&qn?(Pn&&((qn.exports=Jn)._=Jn),\nZn._=Jn):Vn._=Jn}).call(this);\n\nvar n = 6,\n ids = \"0 1 7 1 7 10\".split(' ').map( Number );\n// var n = +readline(),\n// ids = readline().split(' ').map( Number );\nvar sorted = _.sortBy(ids);\nfor (var i = 0, s = 0; i < sorted.length - 1; i++) {\n if (sorted[i] === 0) { continue; }\n if (sorted[i] === sorted[i+1] && sorted[i] === sorted[i+2]) {\n print(-1);\n\t\tquit();\n } else if (sorted[i] === sorted[i+1]) s++;\n}\nprint(s);\n"}, {"source_code": "/**\n * @license\n * lodash 4.6.1 (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE\n * Build: `lodash -o ./dist/lodash.js`\n */\n;(function(){function n(n,t){return n.set(t[0],t[1]),n}function t(n,t){return n.add(t),n}function r(n,t,r){switch(r.length){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n,t,r,e){for(var u=-1,o=n.length;++ut&&!o||!u||r&&!i&&f||e&&f)return 1;if(t>n&&!r||!f||o&&!e&&u||i&&u)return-1}return 0}function R(n){return zn[n]}function W(n){return Mn[n]}function B(n){return\"\\\\\"+Fn[n]}function C(n,t,r){\nvar e=n.length;for(t+=r?0:-1;r?t--:++t-1&&0==n%1&&(null==t?9007199254740991:t)>n}function M(n){for(var t,r=[];!(t=n.next()).done;)r.push(t.value);return r}function L(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function $(n,t){for(var r=-1,e=n.length,u=0,o=[];++rr?false:(r==n.length-1?n.pop():Iu.call(n,r,1),true)}function qn(n,t){var r=Tn(n,t);return 0>r?q:n[r][1]}function Tn(n,t){for(var r=n.length;r--;)if(pe(n[r][0],t))return r;return-1}function Kn(n,t,r){var e=Tn(n,t);0>e?n.push([t,r]):n[e][1]=r}function Gn(n,t,r,e){return n===q||pe(n,cu[r])&&!lu.call(e,r)?t:n}function Yn(n,t,r){(r===q||pe(n[t],r))&&(typeof t!=\"number\"||r!==q||t in n)||(n[t]=r);\n}function Hn(n,t,r){var e=n[t];lu.call(n,t)&&pe(e,r)&&(r!==q||t in n)||(n[t]=r)}function Qn(n,t,r,e){return Qu(n,function(n,u,o){t(e,n,r(n),o)}),e}function Xn(n,t){return n&&tr(t,De(t),n)}function nt(n,t){for(var r=-1,e=null==n,u=t.length,o=Array(u);++rr?r:n),t!==q&&(n=t>n?t:n)),n}function ot(n,t,r,e,o,i,f){\nvar c;if(e&&(c=i?e(n,o,i,f):e(n)),c!==q)return c;if(!me(n))return n;if(o=qo(n)){if(c=Br(n),!t)return nr(n,c)}else{var a=Rr(n),l=\"[object Function]\"==a||\"[object GeneratorFunction]\"==a;if(Po(n))return Yt(n,t);if(\"[object Object]\"==a||\"[object Arguments]\"==a||l&&!i){if(U(n))return i?n:{};if(c=Cr(l?{}:n),!t)return c=Xn(c,n),r?er(n,c):c}else{if(!Un[a])return i?n:{};c=Ur(n,a,t)}}return f||(f=new Fn),(i=f.get(n))?i:(f.set(n,c),(o?u:_t)(n,function(u,o){Hn(c,o,ot(u,t,r,e,o,n,f))}),r&&!o?er(n,c):c)}function it(n){\nvar t=De(n),r=t.length;return function(e){if(null==e)return!r;for(var u=r;u--;){var o=t[u],i=n[o],f=e[o];if(f===q&&!(o in Object(e))||!i(f))return false}return true}}function ft(n){return me(n)?Ou(n):{}}function ct(n,t,r){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return Eu(function(){n.apply(q,r)},t)}function at(n,t,r,e){var u=-1,o=f,i=true,l=n.length,s=[],h=t.length;if(!l)return s;r&&(t=a(t,A(r))),e?(o=c,i=false):t.length>=200&&(o=$n,i=false,t=new Ln(t));n:for(;++u0&&de(i)&&(r||qo(i)||ve(i))?t>1?ht(i,t-1,r,e):l(e,i):r||(e[e.length]=i)}return e}function pt(n,t){null==n||no(n,t,Ze)}function _t(n,t){return n&&no(n,t,De)}function vt(n,t){return n&&to(n,t,De);\n}function gt(n,t){return i(t,function(t){return be(n[t])})}function dt(n,t){t=Lr(t,n)?[t+\"\"]:et(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:q}function yt(n,t){return lu.call(n,t)||typeof n==\"object\"&&t in n&&null===mu(n)}function bt(n,t){return t in Object(n)}function xt(n,t,r){for(var e=r?c:f,u=n[0].length,o=n.length,i=o,l=Array(o),s=1/0,h=[];i--;){var p=n[i];i&&t&&(p=a(p,A(t))),s=zu(p.length,s),l[i]=r||!t&&(120>u||120>p.length)?q:new Ln(i&&p)}var p=n[0],_=-1,v=l[0];n:for(;++_h.length;){\nvar g=p[_],d=t?t(g):g;if(v?!$n(v,d):!e(h,d,r)){for(i=o;--i;){var y=l[i];if(y?!$n(y,d):!e(n[i],d,r))continue n}v&&v.push(d),h.push(g)}}return h}function jt(n,t,r){var e={};return _t(n,function(n,u,o){t(e,r(n),u,o)}),e}function mt(n,t,e){return Lr(t,n)||(t=et(t),n=Zr(n,t),t=Vr(t)),t=null==n?n:n[t],null==t?q:r(t,n,e)}function wt(n,t,r,e,u){if(n===t)n=true;else if(null==n||null==t||!me(n)&&!we(t))n=n!==n&&t!==t;else n:{var o=qo(n),i=qo(t),f=\"[object Array]\",c=\"[object Array]\";o||(f=Rr(n),f=\"[object Arguments]\"==f?\"[object Object]\":f),\ni||(c=Rr(t),c=\"[object Arguments]\"==c?\"[object Object]\":c);var a=\"[object Object]\"==f&&!U(n),i=\"[object Object]\"==c&&!U(t);if((c=f==c)&&!a)u||(u=new Fn),n=o||Re(n)?wr(n,t,wt,r,e,u):Ar(n,t,f,wt,r,e,u);else{if(!(2&e)&&(o=a&&lu.call(n,\"__wrapped__\"),f=i&&lu.call(t,\"__wrapped__\"),o||f)){u||(u=new Fn),n=wt(o?n.value():n,f?t.value():t,r,e,u);break n}if(c)t:if(u||(u=new Fn),o=2&e,f=De(n),i=f.length,c=De(t).length,i==c||o){for(a=i;a--;){var l=f[a];if(!(o?l in t:yt(t,l))){n=false;break t}}if(c=u.get(n))n=c==t;else{\nc=true,u.set(n,t);for(var s=o;++ae?c*(\"desc\"==r[e]?-1:1):c;break n}}e=n.b-t.b}return e})}function Bt(n,t){return n=Object(n),s(t,function(t,r){return r in n&&(t[r]=n[r]),\nt},{})}function Ct(n,t){var r={};return pt(n,function(n,e){t(n,e)&&(r[e]=n)}),r}function Ut(n){return function(t){return null==t?q:t[n]}}function zt(n){return function(t){return dt(t,n)}}function Mt(n,t,r,e){var u=e?y:d,o=-1,i=t.length,f=n;for(r&&(f=a(n,A(r)));++ot&&(t=-t>u?0:u+t),r=r>u?u:r,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=Array(u);++e=u){for(;u>e;){var o=e+u>>>1,i=n[o];(r?t>=i:t>i)&&null!==i?e=o+1:u=o}return u}return qt(n,t,Ye,r)}function qt(n,t,r,e){t=r(t);for(var u=0,o=n?n.length:0,i=t!==t,f=null===t,c=t===q;o>u;){var a=Ru((u+o)/2),l=r(n[a]),s=l!==q,h=l===l;(i?h||e:f?h&&s&&(e||null!=l):c?h&&(e||s):null==l?0:e?t>=l:t>l)?u=a+1:o=a}return zu(o,4294967294)}function Pt(n,t){for(var r=0,e=n.length,u=n[0],o=t?t(u):u,i=o,f=1,c=[u];++re?t[e]:q);return i}function Yt(n,t){if(t)return n.slice();var r=new n.constructor(n.length);return n.copy(r),r}function Ht(n){var t=new n.constructor(n.byteLength);return new bu(t).set(new bu(n)),\nt}function Qt(n,t,r,e){var u=-1,o=n.length,i=r.length,f=-1,c=t.length,a=Uu(o-i,0),l=Array(c+a);for(e=!e;++fu)&&(l[r[u]]=n[u]);for(;a--;)l[f++]=n[u++];return l}function Xt(n,t,r,e){var u=-1,o=n.length,i=-1,f=r.length,c=-1,a=t.length,l=Uu(o-f,0),s=Array(l+a);for(e=!e;++uu)&&(s[l+r[i]]=n[u++]);return s}function nr(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r1?r[u-1]:q,i=u>2?r[2]:q,o=typeof o==\"function\"?(u--,o):q;for(i&&Mr(r[0],r[1],i)&&(o=3>u?q:o,u=1),t=Object(t);++ei&&f[0]!==a&&f[i-1]!==a?[]:$(f,a),i-=c.length,e>i?xr(n,t,_r,u.placeholder,q,f,c,q,q,e-i):r(this&&this!==Vn&&this instanceof u?o:n,this,f)}var o=sr(n);return u}function pr(n){return he(function(t){t=ht(t,1);var r=t.length,e=r,u=An.prototype.thru;for(n&&t.reverse();e--;){var o=t[e];if(typeof o!=\"function\")throw new iu(\"Expected a function\");if(u&&!i&&\"wrapper\"==Or(o))var i=new An([],true)}for(e=i?e:r;++e=200)return i.plant(e).value();for(var u=0,n=r?t[u].apply(this,n):e;++ud)return j=$(b,j),xr(n,t,_r,l.placeholder,r,b,j,f,c,a-d);if(j=h?r:this,y=p?j[n]:n,d=b.length,f){x=b.length;\nfor(var m=zu(f.length,x),w=nr(b);m--;){var A=f[m];b[m]=z(A,x)?w[A]:q}}else v&&d>1&&b.reverse();return s&&d>c&&(b.length=c),this&&this!==Vn&&this instanceof l&&(y=g||sr(y)),y.apply(j,b)}var s=128&t,h=1&t,p=2&t,_=24&t,v=512&t,g=p?q:sr(n);return l}function vr(n,t){return function(r,e){return jt(r,n,t(e))}}function gr(n){return he(function(t){return t=a(ht(t,1),kr()),he(function(e){var u=this;return n(t,function(n){return r(n,u,e)})})})}function dr(n,t,r){return t=Ce(t),n=N(n),t&&t>n?(t-=n,r=r===q?\" \":r+\"\",\nn=Ge(r,Su(t/N(r))),In.test(r)?n.match(En).slice(0,t).join(\"\"):n.slice(0,t)):\"\"}function yr(n,t,e,u){function o(){for(var t=-1,c=arguments.length,a=-1,l=u.length,s=Array(l+c),h=this&&this!==Vn&&this instanceof o?f:n;++at?1:-1:ze(e)||0;var u=-1;r=Uu(Su((r-t)/(e||1)),0);for(var o=Array(r);r--;)o[n?r:++u]=t,\nt+=e;return o}}function xr(n,t,r,e,u,o,i,f,c,a){var l=8&t;f=f?nr(f):q;var s=l?i:q;i=l?q:i;var h=l?o:q;return o=l?q:o,t=(t|(l?32:64))&~(l?64:32),4&t||(t&=-4),t=[n,t,u,h,s,o,i,f,c,a],r=r.apply(q,t),Fr(n)&&fo(r,t),r.placeholder=e,r}function jr(n){var t=uu[n];return function(n,r){if(n=ze(n),r=Ce(r)){var e=(Le(n)+\"e\").split(\"e\"),e=t(e[0]+\"e\"+(+e[1]+r)),e=(Le(e)+\"e\").split(\"e\");return+(e[0]+\"e\"+(+e[1]-r))}return t(n)}}function mr(n,t,r,e,u,o,i,f){var c=2&t;if(!c&&typeof n!=\"function\")throw new iu(\"Expected a function\");\nvar a=e?e.length:0;if(a||(t&=-97,e=u=q),i=i===q?i:Uu(Ce(i),0),f=f===q?f:Ce(f),a-=u?u.length:0,64&t){var l=e,s=u;e=u=q}var h=c?q:uo(n);return o=[n,t,r,e,u,l,s,o,i,f],h&&(r=o[1],n=h[1],t=r|n,e=128==n&&8==r||128==n&&256==r&&h[8]>=o[7].length||384==n&&h[8]>=h[7].length&&8==r,131>t||e)&&(1&n&&(o[2]=h[2],t|=1&r?0:4),(r=h[3])&&(e=o[3],o[3]=e?Qt(e,r,h[4]):nr(r),o[4]=e?$(o[3],\"__lodash_placeholder__\"):nr(h[4])),(r=h[5])&&(e=o[5],o[5]=e?Xt(e,r,h[6]):nr(r),o[6]=e?$(o[5],\"__lodash_placeholder__\"):nr(h[6])),(r=h[7])&&(o[7]=nr(r)),\n128&n&&(o[8]=null==o[8]?h[8]:zu(o[8],h[8])),null==o[9]&&(o[9]=h[9]),o[0]=h[0],o[1]=t),n=o[0],t=o[1],r=o[2],e=o[3],u=o[4],f=o[9]=null==o[9]?c?0:n.length:Uu(o[9]-a,0),!f&&24&t&&(t&=-25),(h?ro:fo)(t&&1!=t?8==t||16==t?hr(n,t,f):32!=t&&33!=t||u.length?_r.apply(q,o):yr(n,t,r,e):cr(n,t,r),o)}function wr(n,t,r,e,u,o){var i=-1,f=2&u,c=1&u,a=n.length,l=t.length;if(!(a==l||f&&l>a))return false;if(l=o.get(n))return l==t;for(l=true,o.set(n,t);++it?0:t,e)):[]}function Kr(n,t,r){var e=n?n.length:0;\nreturn e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0,0>t?0:t)):[]}function Gr(n){return n?n[0]:q}function Vr(n){var t=n?n.length:0;return t?n[t-1]:q}function Jr(n,t){return n&&n.length&&t&&t.length?Mt(n,t):n}function Yr(n){return n?$u.call(n):n}function Hr(n){if(!n||!n.length)return[];var t=0;return n=i(n,function(n){return de(n)?(t=Uu(n.length,t),true):void 0}),m(t,function(t){return a(n,Ut(t))})}function Qr(n,t){if(!n||!n.length)return[];var e=Hr(n);return null==t?e:a(e,function(n){return r(t,q,n)})}function Xr(n){\nreturn n=bn(n),n.__chain__=true,n}function ne(n,t){return t(n)}function te(){return this}function re(n,t){return typeof t==\"function\"&&qo(n)?u(n,t):Qu(n,rt(t))}function ee(n,t){var r;if(typeof t==\"function\"&&qo(n)){for(r=n.length;r--&&false!==t(n[r],r,n););r=n}else r=Xu(n,rt(t));return r}function ue(n,t){return(qo(n)?a:Et)(n,kr(t,3))}function oe(n,t){var r=-1,e=Be(n),u=e.length,o=u-1;for(t=ut(Ce(t),0,u);++r=n&&(t=q),r}}function ce(n,t,r){return t=r?q:t,n=mr(n,8,q,q,q,q,q,t),n.placeholder=ce.placeholder,n}function ae(n,t,r){return t=r?q:t,n=mr(n,16,q,q,q,q,q,t),n.placeholder=ae.placeholder,n}function le(n,t,r){function e(){p&&xu(p),a&&xu(a),v=0,c=a=h=p=_=q}function u(t,r){r&&xu(r),a=p=_=q,t&&(v=Uo(),l=n.apply(h,c),\np||a||(c=h=q))}function o(){var n=t-(Uo()-s);0>=n||n>t?u(_,a):p=Eu(o,n)}function i(){u(y,p)}function f(){if(c=arguments,s=Uo(),h=this,_=y&&(p||!g),false===d)var r=g&&!p;else{v||a||g||(v=s);var e=d-(s-v),u=(0>=e||e>d)&&(g||a);u?(a&&(a=xu(a)),v=s,l=n.apply(h,c)):a||(a=Eu(i,e))}return u&&p?p=xu(p):p||t===d||(p=Eu(o,t)),r&&(u=true,l=n.apply(h,c)),!u||p||a||(c=h=q),l}var c,a,l,s,h,p,_,v=0,g=false,d=false,y=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=ze(t)||0,me(r)&&(g=!!r.leading,d=\"maxWait\"in r&&Uu(ze(r.maxWait)||0,t),\ny=\"trailing\"in r?!!r.trailing:y),f.cancel=e,f.flush=function(){return(p&&_||a&&y)&&(l=n.apply(h,c)),e(),l},f}function se(n,t){function r(){var e=arguments,u=t?t.apply(this,e):e[0],o=r.cache;return o.has(u)?o.get(u):(e=n.apply(this,e),r.cache=o.set(u,e),e)}if(typeof n!=\"function\"||t&&typeof t!=\"function\")throw new iu(\"Expected a function\");return r.cache=new se.Cache,r}function he(n,t){if(typeof n!=\"function\")throw new iu(\"Expected a function\");return t=Uu(t===q?n.length-1:Ce(t),0),function(){for(var e=arguments,u=-1,o=Uu(e.length-t,0),i=Array(o);++ut}function ve(n){return de(n)&&lu.call(n,\"callee\")&&(!ku.call(n,\"callee\")||\"[object Arguments]\"==pu.call(n))}function ge(n){return null!=n&&je(oo(n))&&!be(n)}function de(n){return we(n)&&ge(n)}function ye(n){return we(n)?\"[object Error]\"==pu.call(n)||typeof n.message==\"string\"&&typeof n.name==\"string\":false;\n}function be(n){return n=me(n)?pu.call(n):\"\",\"[object Function]\"==n||\"[object GeneratorFunction]\"==n}function xe(n){return typeof n==\"number\"&&n==Ce(n)}function je(n){return typeof n==\"number\"&&n>-1&&0==n%1&&9007199254740991>=n}function me(n){var t=typeof n;return!!n&&(\"object\"==t||\"function\"==t)}function we(n){return!!n&&typeof n==\"object\"}function Ae(n){return null==n?false:be(n)?vu.test(au.call(n)):we(n)&&(U(n)?vu:dn).test(n)}function Oe(n){return typeof n==\"number\"||we(n)&&\"[object Number]\"==pu.call(n);\n}function ke(n){return!we(n)||\"[object Object]\"!=pu.call(n)||U(n)?false:(n=mu(n),null===n?true:(n=n.constructor,typeof n==\"function\"&&n instanceof n&&au.call(n)==hu))}function Ee(n){return me(n)&&\"[object RegExp]\"==pu.call(n)}function Ie(n){return typeof n==\"string\"||!qo(n)&&we(n)&&\"[object String]\"==pu.call(n)}function Se(n){return typeof n==\"symbol\"||we(n)&&\"[object Symbol]\"==pu.call(n)}function Re(n){return we(n)&&je(n.length)&&!!Cn[pu.call(n)]}function We(n,t){return t>n}function Be(n){if(!n)return[];\nif(ge(n))return Ie(n)?n.match(En):nr(n);if(Au&&n[Au])return M(n[Au]());var t=Rr(n);return(\"[object Map]\"==t?L:\"[object Set]\"==t?F:Pe)(n)}function Ce(n){if(!n)return 0===n?n:0;if(n=ze(n),n===P||n===-P)return 1.7976931348623157e308*(0>n?-1:1);var t=n%1;return n===n?t?n-t:n:0}function Ue(n){return n?ut(Ce(n),0,4294967295):0}function ze(n){if(me(n)&&(n=be(n.valueOf)?n.valueOf():n,n=me(n)?n+\"\":n),typeof n!=\"string\")return 0===n?n:+n;n=n.replace(cn,\"\");var t=gn.test(n);return t||yn.test(n)?Dn(n.slice(2),t?2:8):vn.test(n)?T:+n;\n}function Me(n){return tr(n,Ze(n))}function Le(n){if(typeof n==\"string\")return n;if(null==n)return\"\";if(Se(n))return Hu?Hu.call(n):\"\";var t=n+\"\";return\"0\"==t&&1/n==-P?\"-0\":t}function $e(n,t,r){return n=null==n?q:dt(n,t),n===q?r:n}function Fe(n,t){return Wr(n,t,yt)}function Ne(n,t){return Wr(n,t,bt)}function De(n){var t=Nr(n);if(!t&&!ge(n))return Cu(Object(n));var r,e=zr(n),u=!!e,e=e||[],o=e.length;for(r in n)!yt(n,r)||u&&(\"length\"==r||z(r,o))||t&&\"constructor\"==r||e.push(r);return e}function Ze(n){\nfor(var t=-1,r=Nr(n),e=kt(n),u=e.length,o=zr(n),i=!!o,o=o||[],f=o.length;++tt||t>9007199254740991)return r;do t%2&&(r+=n),t=Ru(t/2),n+=n;while(t);return r}function Ve(n,t,r){\nreturn n=Le(n),t=r?q:t,t===q&&(t=Wn.test(n)?Rn:Sn),n.match(t)||[]}function Je(n){return function(){return n}}function Ye(n){return n}function He(n){return Ot(typeof n==\"function\"?n:ot(n,true))}function Qe(n,t,r){var e=De(t),o=gt(t,e);null!=r||me(t)&&(o.length||!e.length)||(r=t,t=n,n=this,o=gt(t,De(t)));var i=me(r)&&\"chain\"in r?r.chain:true,f=be(n);return u(o,function(r){var e=t[r];n[r]=e,f&&(n.prototype[r]=function(){var t=this.__chain__;if(i||t){var r=n(this.__wrapped__);return(r.__actions__=nr(this.__actions__)).push({\nfunc:e,args:arguments,thisArg:n}),r.__chain__=t,r}return e.apply(n,l([this.value()],arguments))})}),n}function Xe(){}function nu(n){return Lr(n)?Ut(n):zt(n)}function tu(n){return n&&n.length?j(n,Ye):0}I=I?Jn.defaults({},I,Jn.pick(Vn,Bn)):Vn;var ru=I.Date,eu=I.Error,uu=I.Math,ou=I.RegExp,iu=I.TypeError,fu=I.Array.prototype,cu=I.Object.prototype,au=I.Function.prototype.toString,lu=cu.hasOwnProperty,su=0,hu=au.call(Object),pu=cu.toString,_u=Vn._,vu=ou(\"^\"+au.call(lu).replace(on,\"\\\\$&\").replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g,\"$1.*?\")+\"$\"),gu=Pn?I.Buffer:q,du=I.Reflect,yu=I.Symbol,bu=I.Uint8Array,xu=I.clearTimeout,ju=du?du.f:q,mu=Object.getPrototypeOf,wu=Object.getOwnPropertySymbols,Au=typeof(Au=yu&&yu.iterator)==\"symbol\"?Au:q,Ou=Object.create,ku=cu.propertyIsEnumerable,Eu=I.setTimeout,Iu=fu.splice,Su=uu.ceil,Ru=uu.floor,Wu=I.isFinite,Bu=fu.join,Cu=Object.keys,Uu=uu.max,zu=uu.min,Mu=I.parseInt,Lu=uu.random,$u=fu.reverse,Fu=Ir(I,\"Map\"),Nu=Ir(I,\"Set\"),Du=Ir(I,\"WeakMap\"),Zu=Ir(Object,\"create\"),qu=Du&&new Du,Pu=!ku.call({\nvalueOf:1},\"valueOf\"),Tu={},Ku=Fu?au.call(Fu):\"\",Gu=Nu?au.call(Nu):\"\",Vu=Du?au.call(Du):\"\",Ju=yu?yu.prototype:q,Yu=Ju?Ju.valueOf:q,Hu=Ju?Ju.toString:q;bn.templateSettings={escape:X,evaluate:nn,interpolate:tn,variable:\"\",imports:{_:bn}};var Qu=ir(_t),Xu=ir(vt,true),no=fr(),to=fr(true);ju&&!ku.call({valueOf:1},\"valueOf\")&&(kt=function(n){return M(ju(n))});var ro=qu?function(n,t){return qu.set(n,t),n}:Ye,eo=Nu&&2===new Nu([1,2]).size?function(n){return new Nu(n)}:Xe,uo=qu?function(n){return qu.get(n)}:Xe,oo=Ut(\"length\"),io=wu||function(){\nreturn[]};(Fu&&\"[object Map]\"!=Rr(new Fu)||Nu&&\"[object Set]\"!=Rr(new Nu)||Du&&\"[object WeakMap]\"!=Rr(new Du))&&(Rr=function(n){var t=pu.call(n);if(n=\"[object Object]\"==t?n.constructor:null,n=typeof n==\"function\"?au.call(n):\"\")switch(n){case Ku:return\"[object Map]\";case Gu:return\"[object Set]\";case Vu:return\"[object WeakMap]\"}return t});var fo=function(){var n=0,t=0;return function(r,e){var u=Uo(),o=16-(u-t);if(t=u,o>0){if(150<=++n)return r}else n=0;return ro(r,e)}}(),co=he(function(n,t){qo(n)||(n=null==n?[]:[Object(n)]),\nt=ht(t,1);for(var r=n,e=t,u=-1,o=r.length,i=-1,f=e.length,c=Array(o+f);++u1?n[t-1]:q,t=typeof t==\"function\"?(n.pop(),t):q;return Qr(n,t)}),Eo=he(function(n){function t(t){return nt(t,n)}n=ht(n,1);var r=n.length,e=r?n[0]:0,u=this.__wrapped__;return 1>=r&&!this.__actions__.length&&u instanceof On&&z(e)?(u=u.slice(e,+e+(r?1:0)),u.__actions__.push({func:ne,args:[t],thisArg:q}),new An(u,this.__chain__).thru(function(n){return r&&!n.length&&n.push(q),\nn})):this.thru(t)}),Io=ur(function(n,t,r){lu.call(n,r)?++n[r]:n[r]=1}),So=ur(function(n,t,r){lu.call(n,r)?n[r].push(t):n[r]=[t]}),Ro=he(function(n,t,e){var u=-1,o=typeof t==\"function\",i=Lr(t),f=ge(n)?Array(n.length):[];return Qu(n,function(n){var c=o?t:i&&null!=n?n[t]:q;f[++u]=c?r(c,n,e):mt(n,t,e)}),f}),Wo=ur(function(n,t,r){n[r]=t}),Bo=ur(function(n,t,r){n[r?0:1].push(t)},function(){return[[],[]]}),Co=he(function(n,t){if(null==n)return[];var r=t.length;return r>1&&Mr(n,t[0],t[1])?t=[]:r>2&&Mr(t[0],t[1],t[2])&&(t.length=1),\nWt(n,ht(t,1),[])}),Uo=ru.now,zo=he(function(n,t,r){var e=1;if(r.length)var u=$(r,Sr(zo)),e=32|e;return mr(n,e,t,r,u)}),Mo=he(function(n,t,r){var e=3;if(r.length)var u=$(r,Sr(Mo)),e=32|e;return mr(t,e,n,r,u)}),Lo=he(function(n,t){return ct(n,1,t)}),$o=he(function(n,t,r){return ct(n,ze(t)||0,r)}),Fo=he(function(n,t){t=a(ht(t,1),kr());var e=t.length;return he(function(u){for(var o=-1,i=zu(u.length,e);++oe.length?Kn(e,n,t):(r.array=null,r.map=new Mn(e))),(r=r.map)&&r.set(n,t),this},se.Cache=Mn,bn.after=function(n,t){if(typeof t!=\"function\")throw new iu(\"Expected a function\");return n=Ce(n),function(){return 1>--n?t.apply(this,arguments):void 0}},bn.ary=ie,bn.assign=To,bn.assignIn=Ko,\nbn.assignInWith=Go,bn.assignWith=Vo,bn.at=Jo,bn.before=fe,bn.bind=zo,bn.bindAll=_i,bn.bindKey=Mo,bn.castArray=function(){if(!arguments.length)return[];var n=arguments[0];return qo(n)?n:[n]},bn.chain=Xr,bn.chunk=function(n,t){t=Uu(Ce(t),0);var r=n?n.length:0;if(!r||1>t)return[];for(var e=0,u=0,o=Array(Su(r/t));r>e;)o[u++]=Nt(n,e,e+=t);return o},bn.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++tr&&(r=-r>u?0:u+r),e=e===q||e>u?u:Ce(e),0>e&&(e+=u),e=r>e?0:Ue(e);e>r;)n[r++]=t;return n},bn.filter=function(n,t){return(qo(n)?i:st)(n,kr(t,3))},bn.flatMap=function(n,t){return ht(ue(n,t),1)},bn.flatten=function(n){\nreturn n&&n.length?ht(n,1):[]},bn.flattenDeep=function(n){return n&&n.length?ht(n,P):[]},bn.flattenDepth=function(n,t){return n&&n.length?(t=t===q?1:Ce(t),ht(n,t)):[]},bn.flip=function(n){return mr(n,512)},bn.flow=vi,bn.flowRight=gi,bn.fromPairs=function(n){for(var t=-1,r=n?n.length:0,e={};++tt?0:t)):[]},bn.takeRight=function(n,t,r){var e=n?n.length:0;return e?(t=r||t===q?1:Ce(t),t=e-t,Nt(n,0>t?0:t,e)):[]},bn.takeRightWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3),false,true):[]},bn.takeWhile=function(n,t){return n&&n.length?Kt(n,kr(t,3)):[]},bn.tap=function(n,t){return t(n),n},bn.throttle=function(n,t,r){var e=true,u=true;if(typeof n!=\"function\")throw new iu(\"Expected a function\");return me(r)&&(e=\"leading\"in r?!!r.leading:e,u=\"trailing\"in r?!!r.trailing:u),le(n,t,{leading:e,maxWait:t,\ntrailing:u})},bn.thru=ne,bn.toArray=Be,bn.toPairs=qe,bn.toPairsIn=function(n){return w(n,Ze(n))},bn.toPath=function(n){return qo(n)?a(n,String):qr(n)},bn.toPlainObject=Me,bn.transform=function(n,t,r){var e=qo(n)||Re(n);if(t=kr(t,4),null==r)if(e||me(n)){var o=n.constructor;r=e?qo(n)?new o:[]:be(o)?ft(mu(n)):{}}else r={};return(e?u:_t)(n,function(n,e,u){return t(r,n,e,u)}),r},bn.unary=function(n){return ie(n,1)},bn.union=yo,bn.unionBy=bo,bn.unionWith=xo,bn.uniq=function(n){return n&&n.length?Tt(n):[];\n},bn.uniqBy=function(n,t){return n&&n.length?Tt(n,kr(t)):[]},bn.uniqWith=function(n,t){return n&&n.length?Tt(n,q,t):[]},bn.unset=function(n,t){var r;if(null==n)r=true;else{r=n;var e=t,e=Lr(e,r)?[e+\"\"]:et(e);r=Zr(r,e),e=Vr(e),r=null!=r&&Fe(r,e)?delete r[e]:true}return r},bn.unzip=Hr,bn.unzipWith=Qr,bn.update=function(n,t,r){return null==n?n:Ft(n,t,rt(r)(dt(n,t)),void 0)},bn.updateWith=function(n,t,r,e){return e=typeof e==\"function\"?e:q,null!=n&&(n=Ft(n,t,rt(r)(dt(n,t)),e)),n},bn.values=Pe,bn.valuesIn=function(n){\nreturn null==n?[]:O(n,Ze(n))},bn.without=jo,bn.words=Ve,bn.wrap=function(n,t){return t=null==t?Ye:t,No(t,n)},bn.xor=mo,bn.xorBy=wo,bn.xorWith=Ao,bn.zip=Oo,bn.zipObject=function(n,t){return Jt(n||[],t||[],Hn)},bn.zipObjectDeep=function(n,t){return Jt(n||[],t||[],Ft)},bn.zipWith=ko,bn.extend=Ko,bn.extendWith=Go,Qe(bn,bn),bn.add=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r+t),r)},bn.attempt=pi,bn.camelCase=oi,bn.capitalize=Te,bn.ceil=Ai,bn.clamp=function(n,t,r){return r===q&&(r=t,\nt=q),r!==q&&(r=ze(r),r=r===r?r:0),t!==q&&(t=ze(t),t=t===t?t:0),ut(ze(n),t,r)},bn.clone=function(n){return ot(n,false,true)},bn.cloneDeep=function(n){return ot(n,true,true)},bn.cloneDeepWith=function(n,t){return ot(n,true,true,t)},bn.cloneWith=function(n,t){return ot(n,false,true,t)},bn.deburr=Ke,bn.endsWith=function(n,t,r){n=Le(n),t=typeof t==\"string\"?t:t+\"\";var e=n.length;return r=r===q?e:ut(Ce(r),0,e),r-=t.length,r>=0&&n.indexOf(t,r)==r},bn.eq=pe,bn.escape=function(n){return(n=Le(n))&&Q.test(n)?n.replace(Y,W):n},\nbn.escapeRegExp=function(n){return(n=Le(n))&&fn.test(n)?n.replace(on,\"\\\\$&\"):n},bn.every=function(n,t,r){var e=qo(n)?o:lt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.find=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t);return r>-1?n[r]:q}return v(n,t,Qu)},bn.findIndex=function(n,t){return n&&n.length?g(n,kr(t,3)):-1},bn.findKey=function(n,t){return v(n,kr(t,3),_t,true)},bn.findLast=function(n,t){if(t=kr(t,3),qo(n)){var r=g(n,t,true);return r>-1?n[r]:q}return v(n,t,Xu)},bn.findLastIndex=function(n,t){return n&&n.length?g(n,kr(t,3),true):-1;\n},bn.findLastKey=function(n,t){return v(n,kr(t,3),vt,true)},bn.floor=Oi,bn.forEach=re,bn.forEachRight=ee,bn.forIn=function(n,t){return null==n?n:no(n,rt(t),Ze)},bn.forInRight=function(n,t){return null==n?n:to(n,rt(t),Ze)},bn.forOwn=function(n,t){return n&&_t(n,rt(t))},bn.forOwnRight=function(n,t){return n&&vt(n,rt(t))},bn.get=$e,bn.gt=_e,bn.gte=function(n,t){return n>=t},bn.has=Fe,bn.hasIn=Ne,bn.head=Gr,bn.identity=Ye,bn.includes=function(n,t,r,e){return n=ge(n)?n:Pe(n),r=r&&!e?Ce(r):0,e=n.length,0>r&&(r=Uu(e+r,0)),\nIe(n)?e>=r&&-1r&&(r=Uu(e+r,0)),d(n,t,r)):-1},bn.inRange=function(n,t,r){return t=ze(t)||0,r===q?(r=t,t=0):r=ze(r)||0,n=ze(n),n>=zu(t,r)&&n=-9007199254740991&&9007199254740991>=n;\n},bn.isSet=function(n){return we(n)&&\"[object Set]\"==Rr(n)},bn.isString=Ie,bn.isSymbol=Se,bn.isTypedArray=Re,bn.isUndefined=function(n){return n===q},bn.isWeakMap=function(n){return we(n)&&\"[object WeakMap]\"==Rr(n)},bn.isWeakSet=function(n){return we(n)&&\"[object WeakSet]\"==pu.call(n)},bn.join=function(n,t){return n?Bu.call(n,t):\"\"},bn.kebabCase=ii,bn.last=Vr,bn.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(r!==q&&(u=Ce(r),u=(0>u?Uu(e+u,0):zu(u,e-1))+1),t!==t)return C(n,u,true);\nfor(;u--;)if(n[u]===t)return u;return-1},bn.lowerCase=fi,bn.lowerFirst=ci,bn.lt=We,bn.lte=function(n,t){return t>=n},bn.max=function(n){return n&&n.length?_(n,Ye,_e):q},bn.maxBy=function(n,t){return n&&n.length?_(n,kr(t),_e):q},bn.mean=function(n){return tu(n)/(n?n.length:0)},bn.min=function(n){return n&&n.length?_(n,Ye,We):q},bn.minBy=function(n,t){return n&&n.length?_(n,kr(t),We):q},bn.noConflict=function(){return Vn._===this&&(Vn._=_u),this},bn.noop=Xe,bn.now=Uo,bn.pad=function(n,t,r){n=Le(n),\nt=Ce(t);var e=N(n);return t&&t>e?(e=(t-e)/2,t=Ru(e),e=Su(e),dr(\"\",t,r)+n+dr(\"\",e,r)):n},bn.padEnd=function(n,t,r){return n=Le(n),n+dr(n,t,r)},bn.padStart=function(n,t,r){return n=Le(n),dr(n,t,r)+n},bn.parseInt=function(n,t,r){return r||null==t?t=0:t&&(t=+t),n=Le(n).replace(cn,\"\"),Mu(n,t||(_n.test(n)?16:10))},bn.random=function(n,t,r){if(r&&typeof r!=\"boolean\"&&Mr(n,t,r)&&(t=r=q),r===q&&(typeof t==\"boolean\"?(r=t,t=q):typeof n==\"boolean\"&&(r=n,n=q)),n===q&&t===q?(n=0,t=1):(n=ze(n)||0,t===q?(t=n,n=0):t=ze(t)||0),\nn>t){var e=n;n=t,t=e}return r||n%1||t%1?(r=Lu(),zu(n+r*(t-n+Nn(\"1e-\"+((r+\"\").length-1))),t)):$t(n,t)},bn.reduce=function(n,t,r){var e=qo(n)?s:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Qu)},bn.reduceRight=function(n,t,r){var e=qo(n)?h:b,u=3>arguments.length;return e(n,kr(t,4),r,u,Xu)},bn.repeat=Ge,bn.replace=function(){var n=arguments,t=Le(n[0]);return 3>n.length?t:t.replace(n[1],n[2])},bn.result=function(n,t,r){if(Lr(t,n))e=null==n?q:n[t];else{t=et(t);var e=$e(n,t);n=Zr(n,t)}return e===q&&(e=r),\nbe(e)?e.call(n):e},bn.round=ki,bn.runInContext=Z,bn.sample=function(n){n=ge(n)?n:Pe(n);var t=n.length;return t>0?n[$t(0,t-1)]:q},bn.size=function(n){if(null==n)return 0;if(ge(n)){var t=n.length;return t&&Ie(n)?N(n):t}return De(n).length},bn.snakeCase=li,bn.some=function(n,t,r){var e=qo(n)?p:Dt;return r&&Mr(n,t,r)&&(t=q),e(n,kr(t,3))},bn.sortedIndex=function(n,t){return Zt(n,t)},bn.sortedIndexBy=function(n,t,r){return qt(n,t,kr(r))},bn.sortedIndexOf=function(n,t){var r=n?n.length:0;if(r){var e=Zt(n,t);\nif(r>e&&pe(n[e],t))return e}return-1},bn.sortedLastIndex=function(n,t){return Zt(n,t,true)},bn.sortedLastIndexBy=function(n,t,r){return qt(n,t,kr(r),true)},bn.sortedLastIndexOf=function(n,t){if(n&&n.length){var r=Zt(n,t,true)-1;if(pe(n[r],t))return r}return-1},bn.startCase=si,bn.startsWith=function(n,t,r){return n=Le(n),r=ut(Ce(r),0,n.length),n.lastIndexOf(t,r)==r},bn.subtract=function(n,t){var r;return n===q&&t===q?0:(n!==q&&(r=n),t!==q&&(r=r===q?t:r-t),r)},bn.sum=tu,bn.sumBy=function(n,t){return n&&n.length?j(n,kr(t)):0;\n},bn.template=function(n,t,r){var e=bn.templateSettings;r&&Mr(n,t,r)&&(t=q),n=Le(n),t=Go({},t,e,Gn),r=Go({},t.imports,e.imports,Gn);var u,o,i=De(r),f=O(r,i),c=0;r=t.interpolate||jn;var a=\"__p+='\";r=ou((t.escape||jn).source+\"|\"+r.source+\"|\"+(r===tn?hn:jn).source+\"|\"+(t.evaluate||jn).source+\"|$\",\"g\");var l=\"sourceURL\"in t?\"//# sourceURL=\"+t.sourceURL+\"\\n\":\"\";if(n.replace(r,function(t,r,e,i,f,l){return e||(e=i),a+=n.slice(c,l).replace(mn,B),r&&(u=true,a+=\"'+__e(\"+r+\")+'\"),f&&(o=true,a+=\"';\"+f+\";\\n__p+='\"),\ne&&(a+=\"'+((__t=(\"+e+\"))==null?'':__t)+'\"),c=l+t.length,t}),a+=\"';\",(t=t.variable)||(a=\"with(obj){\"+a+\"}\"),a=(o?a.replace(K,\"\"):a).replace(G,\"$1\").replace(V,\"$1;\"),a=\"function(\"+(t||\"obj\")+\"){\"+(t?\"\":\"obj||(obj={});\")+\"var __t,__p=''\"+(u?\",__e=_.escape\":\"\")+(o?\",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}\":\";\")+a+\"return __p}\",t=pi(function(){return Function(i,l+\"return \"+a).apply(q,f)}),t.source=a,ye(t))throw t;return t},bn.times=function(n,t){if(n=Ce(n),1>n||n>9007199254740991)return[];\nvar r=4294967295,e=zu(n,4294967295);for(t=rt(t),n-=4294967295,e=m(e,t);++r=o)return n;if(o=r-N(e),1>o)return e;\nif(r=i?i.slice(0,o).join(\"\"):n.slice(0,o),u===q)return r+e;if(i&&(o+=r.length-o),Ee(u)){if(n.slice(o).search(u)){var f=r;for(u.global||(u=ou(u.source,Le(pn.exec(u))+\"g\")),u.lastIndex=0;i=u.exec(f);)var c=i.index;r=r.slice(0,c===q?o:c)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),u>-1&&(r=r.slice(0,u)));return r+e},bn.unescape=function(n){return(n=Le(n))&&H.test(n)?n.replace(J,D):n},bn.uniqueId=function(n){var t=++su;return Le(n)+t},bn.upperCase=hi,bn.upperFirst=ai,bn.each=re,bn.eachRight=ee,bn.first=Gr,\nQe(bn,function(){var n={};return _t(bn,function(t,r){lu.call(bn.prototype,r)||(n[r]=t)}),n}(),{chain:false}),bn.VERSION=\"4.6.1\",u(\"bind bindKey curry curryRight partial partialRight\".split(\" \"),function(n){bn[n].placeholder=bn}),u([\"drop\",\"take\"],function(n,t){On.prototype[n]=function(r){var e=this.__filtered__;if(e&&!t)return new On(this);r=r===q?1:Uu(Ce(r),0);var u=this.clone();return e?u.__takeCount__=zu(r,u.__takeCount__):u.__views__.push({size:zu(r,4294967295),type:n+(0>u.__dir__?\"Right\":\"\")}),\nu},On.prototype[n+\"Right\"]=function(t){return this.reverse()[n](t).reverse()}}),u([\"filter\",\"map\",\"takeWhile\"],function(n,t){var r=t+1,e=1==r||3==r;On.prototype[n]=function(n){var t=this.clone();return t.__iteratees__.push({iteratee:kr(n,3),type:r}),t.__filtered__=t.__filtered__||e,t}}),u([\"head\",\"last\"],function(n,t){var r=\"take\"+(t?\"Right\":\"\");On.prototype[n]=function(){return this[r](1).value()[0]}}),u([\"initial\",\"tail\"],function(n,t){var r=\"drop\"+(t?\"\":\"Right\");On.prototype[n]=function(){return this.__filtered__?new On(this):this[r](1);\n}}),On.prototype.compact=function(){return this.filter(Ye)},On.prototype.find=function(n){return this.filter(n).head()},On.prototype.findLast=function(n){return this.reverse().find(n)},On.prototype.invokeMap=he(function(n,t){return typeof n==\"function\"?new On(this):this.map(function(r){return mt(r,n,t)})}),On.prototype.reject=function(n){return n=kr(n,3),this.filter(function(t){return!n(t)})},On.prototype.slice=function(n,t){n=Ce(n);var r=this;return r.__filtered__&&(n>0||0>t)?new On(r):(0>n?r=r.takeRight(-n):n&&(r=r.drop(n)),\nt!==q&&(t=Ce(t),r=0>t?r.dropRight(-t):r.take(t-n)),r)},On.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},On.prototype.toArray=function(){return this.take(4294967295)},_t(On.prototype,function(n,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),e=/^(?:head|last)$/.test(t),u=bn[e?\"take\"+(\"last\"==t?\"Right\":\"\"):t],o=e||/^find/.test(t);u&&(bn.prototype[t]=function(){function t(n){return n=u.apply(bn,l([n],f)),e&&h?n[0]:n}var i=this.__wrapped__,f=e?[1]:arguments,c=i instanceof On,a=f[0],s=c||qo(i);\ns&&r&&typeof a==\"function\"&&1!=a.length&&(c=s=false);var h=this.__chain__,p=!!this.__actions__.length,a=o&&!h,c=c&&!p;return!o&&s?(i=c?i:new On(this),i=n.apply(i,f),i.__actions__.push({func:ne,args:[t],thisArg:q}),new An(i,h)):a&&c?n.apply(this,f):(i=this.thru(t),a?e?i.value()[0]:i.value():i)})}),u(\"pop push shift sort splice unshift\".split(\" \"),function(n){var t=fu[n],r=/^(?:push|sort|unshift)$/.test(n)?\"tap\":\"thru\",e=/^(?:pop|shift)$/.test(n);bn.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){\nreturn t.apply(r,n)})}}),_t(On.prototype,function(n,t){var r=bn[t];if(r){var e=r.name+\"\";(Tu[e]||(Tu[e]=[])).push({name:t,func:r})}}),Tu[_r(q,2).name]=[{name:\"wrapper\",func:q}],On.prototype.clone=function(){var n=new On(this.__wrapped__);return n.__actions__=nr(this.__actions__),n.__dir__=this.__dir__,n.__filtered__=this.__filtered__,n.__iteratees__=nr(this.__iteratees__),n.__takeCount__=this.__takeCount__,n.__views__=nr(this.__views__),n},On.prototype.reverse=function(){if(this.__filtered__){var n=new On(this);\nn.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},On.prototype.value=function(){var n,t=this.__wrapped__.value(),r=this.__dir__,e=qo(t),u=0>r,o=e?t.length:0;n=o;for(var i=this.__views__,f=0,c=-1,a=i.length;++co||o==n&&a==n)return Gt(t,this.__actions__);\ne=[];n:for(;n--&&a>c;){for(u+=r,o=-1,l=t[u];++o=this.__values__.length,t=n?q:this.__values__[this.__index__++];\nreturn{done:n,value:t}},bn.prototype.plant=function(n){for(var t,r=this;r instanceof wn;){var e=Pr(r);e.__index__=0,e.__values__=q,t?u.__wrapped__=e:t=e;var u=e,r=r.__wrapped__}return u.__wrapped__=n,t},bn.prototype.reverse=function(){var n=this.__wrapped__;return n instanceof On?(this.__actions__.length&&(n=new On(this)),n=n.reverse(),n.__actions__.push({func:ne,args:[Yr],thisArg:q}),new An(n,this.__chain__)):this.thru(Yr)},bn.prototype.toJSON=bn.prototype.valueOf=bn.prototype.value=function(){return Gt(this.__wrapped__,this.__actions__);\n},Au&&(bn.prototype[Au]=te),bn}var q,P=1/0,T=NaN,K=/\\b__p\\+='';/g,G=/\\b(__p\\+=)''\\+/g,V=/(__e\\(.*?\\)|\\b__t\\))\\+'';/g,J=/&(?:amp|lt|gt|quot|#39|#96);/g,Y=/[&<>\"'`]/g,H=RegExp(J.source),Q=RegExp(Y.source),X=/<%-([\\s\\S]+?)%>/g,nn=/<%([\\s\\S]+?)%>/g,tn=/<%=([\\s\\S]+?)%>/g,rn=/\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,en=/^\\w*$/,un=/[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]/g,on=/[\\\\^$.*+?()[\\]{}|]/g,fn=RegExp(on.source),cn=/^\\s+|\\s+$/g,an=/^\\s+/,ln=/\\s+$/,sn=/\\\\(\\\\)?/g,hn=/\\$\\{([^\\\\}]*(?:\\\\.[^\\\\}]*)*)\\}/g,pn=/\\w*$/,_n=/^0x/i,vn=/^[-+]0x[0-9a-f]+$/i,gn=/^0b[01]+$/i,dn=/^\\[object .+?Constructor\\]$/,yn=/^0o[0-7]+$/i,bn=/^(?:0|[1-9]\\d*)$/,xn=/[\\xc0-\\xd6\\xd8-\\xde\\xdf-\\xf6\\xf8-\\xff]/g,jn=/($^)/,mn=/['\\n\\r\\u2028\\u2029\\\\]/g,wn=\"[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?(?:\\\\u200d(?:[^\\\\ud800-\\\\udfff]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])[\\\\ufe0e\\\\ufe0f]?(?:[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|\\\\ud83c[\\\\udffb-\\\\udfff])?)*\",An=\"(?:[\\\\u2700-\\\\u27bf]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff])\"+wn,On=\"(?:[^\\\\ud800-\\\\udfff][\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]?|[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]|(?:\\\\ud83c[\\\\udde6-\\\\uddff]){2}|[\\\\ud800-\\\\udbff][\\\\udc00-\\\\udfff]|[\\\\ud800-\\\\udfff])\",kn=RegExp(\"[\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0]\",\"g\"),En=RegExp(\"\\\\ud83c[\\\\udffb-\\\\udfff](?=\\\\ud83c[\\\\udffb-\\\\udfff])|\"+On+wn,\"g\"),In=RegExp(\"[\\\\u200d\\\\ud800-\\\\udfff\\\\u0300-\\\\u036f\\\\ufe20-\\\\ufe23\\\\u20d0-\\\\u20f0\\\\ufe0e\\\\ufe0f]\"),Sn=/[a-zA-Z0-9]+/g,Rn=RegExp([\"[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|$)|(?:[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+(?=[\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000]|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde](?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])|$)|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]?(?:[a-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xff]|[^\\\\ud800-\\\\udfff\\\\xac\\\\xb1\\\\xd7\\\\xf7\\\\x00-\\\\x2f\\\\x3a-\\\\x40\\\\x5b-\\\\x60\\\\x7b-\\\\xbf\\\\u2018\\\\u2019\\\\u201c\\\\u201d \\\\t\\\\x0b\\\\f\\\\xa0\\\\ufeff\\\\n\\\\r\\\\u2028\\\\u2029\\\\u1680\\\\u180e\\\\u2000\\\\u2001\\\\u2002\\\\u2003\\\\u2004\\\\u2005\\\\u2006\\\\u2007\\\\u2008\\\\u2009\\\\u200a\\\\u202f\\\\u205f\\\\u3000\\\\d+\\\\u2700-\\\\u27bfa-z\\\\xdf-\\\\xf6\\\\xf8-\\\\xffA-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde])+|[A-Z\\\\xc0-\\\\xd6\\\\xd8-\\\\xde]+|\\\\d+\",An].join(\"|\"),\"g\"),Wn=/[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Bn=\"Array Buffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Reflect RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout\".split(\" \"),Cn={};\nCn[\"[object Float32Array]\"]=Cn[\"[object Float64Array]\"]=Cn[\"[object Int8Array]\"]=Cn[\"[object Int16Array]\"]=Cn[\"[object Int32Array]\"]=Cn[\"[object Uint8Array]\"]=Cn[\"[object Uint8ClampedArray]\"]=Cn[\"[object Uint16Array]\"]=Cn[\"[object Uint32Array]\"]=true,Cn[\"[object Arguments]\"]=Cn[\"[object Array]\"]=Cn[\"[object ArrayBuffer]\"]=Cn[\"[object Boolean]\"]=Cn[\"[object Date]\"]=Cn[\"[object Error]\"]=Cn[\"[object Function]\"]=Cn[\"[object Map]\"]=Cn[\"[object Number]\"]=Cn[\"[object Object]\"]=Cn[\"[object RegExp]\"]=Cn[\"[object Set]\"]=Cn[\"[object String]\"]=Cn[\"[object WeakMap]\"]=false;\nvar Un={};Un[\"[object Arguments]\"]=Un[\"[object Array]\"]=Un[\"[object ArrayBuffer]\"]=Un[\"[object Boolean]\"]=Un[\"[object Date]\"]=Un[\"[object Float32Array]\"]=Un[\"[object Float64Array]\"]=Un[\"[object Int8Array]\"]=Un[\"[object Int16Array]\"]=Un[\"[object Int32Array]\"]=Un[\"[object Map]\"]=Un[\"[object Number]\"]=Un[\"[object Object]\"]=Un[\"[object RegExp]\"]=Un[\"[object Set]\"]=Un[\"[object String]\"]=Un[\"[object Symbol]\"]=Un[\"[object Uint8Array]\"]=Un[\"[object Uint8ClampedArray]\"]=Un[\"[object Uint16Array]\"]=Un[\"[object Uint32Array]\"]=true,\nUn[\"[object Error]\"]=Un[\"[object Function]\"]=Un[\"[object WeakMap]\"]=false;var zn={\"\\xc0\":\"A\",\"\\xc1\":\"A\",\"\\xc2\":\"A\",\"\\xc3\":\"A\",\"\\xc4\":\"A\",\"\\xc5\":\"A\",\"\\xe0\":\"a\",\"\\xe1\":\"a\",\"\\xe2\":\"a\",\"\\xe3\":\"a\",\"\\xe4\":\"a\",\"\\xe5\":\"a\",\"\\xc7\":\"C\",\"\\xe7\":\"c\",\"\\xd0\":\"D\",\"\\xf0\":\"d\",\"\\xc8\":\"E\",\"\\xc9\":\"E\",\"\\xca\":\"E\",\"\\xcb\":\"E\",\"\\xe8\":\"e\",\"\\xe9\":\"e\",\"\\xea\":\"e\",\"\\xeb\":\"e\",\"\\xcc\":\"I\",\"\\xcd\":\"I\",\"\\xce\":\"I\",\"\\xcf\":\"I\",\"\\xec\":\"i\",\"\\xed\":\"i\",\"\\xee\":\"i\",\"\\xef\":\"i\",\"\\xd1\":\"N\",\"\\xf1\":\"n\",\"\\xd2\":\"O\",\"\\xd3\":\"O\",\"\\xd4\":\"O\",\"\\xd5\":\"O\",\"\\xd6\":\"O\",\n\"\\xd8\":\"O\",\"\\xf2\":\"o\",\"\\xf3\":\"o\",\"\\xf4\":\"o\",\"\\xf5\":\"o\",\"\\xf6\":\"o\",\"\\xf8\":\"o\",\"\\xd9\":\"U\",\"\\xda\":\"U\",\"\\xdb\":\"U\",\"\\xdc\":\"U\",\"\\xf9\":\"u\",\"\\xfa\":\"u\",\"\\xfb\":\"u\",\"\\xfc\":\"u\",\"\\xdd\":\"Y\",\"\\xfd\":\"y\",\"\\xff\":\"y\",\"\\xc6\":\"Ae\",\"\\xe6\":\"ae\",\"\\xde\":\"Th\",\"\\xfe\":\"th\",\"\\xdf\":\"ss\"},Mn={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\",\"`\":\"`\"},Ln={\"&\":\"&\",\"<\":\"<\",\">\":\">\",\""\":'\"',\"'\":\"'\",\"`\":\"`\"},$n={\"function\":true,object:true},Fn={\"\\\\\":\"\\\\\",\"'\":\"'\",\"\\n\":\"n\",\"\\r\":\"r\",\"\\u2028\":\"u2028\",\"\\u2029\":\"u2029\"\n},Nn=parseFloat,Dn=parseInt,Zn=$n[typeof exports]&&exports&&!exports.nodeType?exports:q,qn=$n[typeof module]&&module&&!module.nodeType?module:q,Pn=qn&&qn.exports===Zn?Zn:q,Tn=I($n[typeof self]&&self),Kn=I($n[typeof window]&&window),Gn=I($n[typeof this]&&this),Vn=I(Zn&&qn&&typeof global==\"object\"&&global)||Kn!==(Gn&&Gn.window)&&Kn||Tn||Gn||Function(\"return this\")(),Jn=Z();(Kn||Tn||{})._=Jn,typeof define==\"function\"&&typeof define.amd==\"object\"&&define.amd? define(function(){return Jn}):Zn&&qn?(Pn&&((qn.exports=Jn)._=Jn),\nZn._=Jn):Vn._=Jn}).call(this);\n\n// var n = 6,\n// ids = \"1 1 1\".split(' ').map( Number );\nvar n = +readline(),\n ids = readline().split(' ').map( Number );\nvar sorted = _.sortBy(ids);\nfor (var i = 0, s = 0; i < sorted.length - 1; i++) {\n if (sorted[i] == sorted[i+1] && sorted[i] == sorted[i+2]) {\n print(-1);\n\t\tquit();\n } else if (sorted[i] == sorted[i+1]) s++;\n}\nprint(s);\n"}], "src_uid": "45e51f3dee9a22cee86e1a98da519e2d"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [v, e] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const queue = [];\n const graph = {};\n const indegrees = Array(v + 1).fill(0);\n const directedpairs = [];\n const nonDirectedpairs = [];\n const positions = [];\n\n for (let i = 0; i < e; i++) {\n let [directed, src, destination] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (directed) {\n if (!graph[src]) graph[src] = [destination];\n else graph[src].push(destination);\n directedpairs.push([src, destination]);\n indegrees[destination]++;\n } else {\n nonDirectedpairs.push([src, destination]);\n }\n }\n\n for (let i = 1; i <= v; i++) {\n if (indegrees[i] === 0) {\n queue.push(i);\n }\n }\n\n let index = 0;\n while (queue.length) {\n const u = queue.pop();\n positions[u] = index;\n index++;\n if (graph[u]) {\n for (let i = 0; i < graph[u].length; i++) {\n const v = graph[u][i];\n if (--indegrees[v] === 0) {\n queue.push(v);\n }\n }\n }\n }\n if (index !== v) {\n console.log(\"NO\");\n continue;\n } else {\n console.log(\"YES\");\n for (let i = 0; i < directedpairs.length; i++) {\n let [src, destination] = directedpairs[i];\n console.log(`${src} ${destination}`);\n }\n\n for (let i = 0; i < nonDirectedpairs.length; i++) {\n let [src, destination] = nonDirectedpairs[i];\n if (positions[src] < positions[destination]) {\n console.log(`${src} ${destination}`);\n } else {\n console.log(`${destination} ${src}`);\n }\n }\n }\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [v, e] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const queue = [];\n const graph = {};\n const indegrees = Array(v + 1).fill(0);\n const directedpairs = [];\n const nonDirectedpairs = [];\n const positions = [];\n\n let [di, ndi] = [0, 0];\n for (let i = 0; i < e; i++) {\n let [directed, src, destination] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (directed) {\n if (!graph[src]) graph[src] = [destination];\n else graph[src].push(destination);\n directedpairs[di] = [src, destination];\n indegrees[destination]++;\n di++;\n } else {\n nonDirectedpairs[ndi] = [src, destination];\n ndi++;\n }\n }\n\n for (let i = 1; i <= v; i++) {\n if (indegrees[i] === 0) {\n queue.push(i);\n }\n }\n\n let index = 0;\n while (queue.length) {\n const u = queue.pop();\n positions[u] = index;\n index++;\n if (graph[u]) {\n for (let i = 0; i < graph[u].length; i++) {\n const v = graph[u][i];\n if (--indegrees[v] === 0) {\n queue.push(v);\n }\n }\n }\n }\n if (index !== v) {\n console.log(\"NO\");\n continue;\n } else {\n console.log(\"YES\");\n for (let i = 0; i < directedpairs.length; i++) {\n let [src, destination] = directedpairs[i];\n console.log(`${src} ${destination}`);\n }\n\n for (let i = 0; i < nonDirectedpairs.length; i++) {\n let [src, destination] = nonDirectedpairs[i];\n if (positions[src] < positions[destination]) {\n console.log(`${src} ${destination}`);\n } else {\n console.log(`${destination} ${src}`);\n }\n }\n }\n }\n}\n"}], "negative_code": [], "src_uid": "4bee64265ade3c09002446264dcd26a6"} {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => {\r\n return lines[i++]\r\n }\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\nrl.on('close', () => {\r\n const readLine = createReadLine();\r\n let t = parseInt(readLine())\r\n while (t--) {\r\n readLine()\r\n console.log(readLine().replace(/\\G/g, 'B') == readLine().replace(/\\G/g, 'B') ? 'YES' : 'NO')\r\n }\r\n})", "positive_code": [{"source_code": "\r\nvar t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var str1 = readline().split('');\r\n var str2 = readline().split('');\r\n\r\n var ans = 'YES';\r\n\r\n for (var i = 0; i < n; i++) {\r\n if ((str1[i] === 'R' && str2[i] !== 'R') || str1[i] !== 'R' && str2[i] === 'R') {\r\n ans = 'NO';\r\n break;\r\n }\r\n }\r\n\r\n print(ans);\r\n}\r\n"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var columns = parseInt(readline());\r\n var first = readline();\r\n var second = readline();\r\n var firstRow = \"\";\r\n var secondRow = \"\";\r\n for (var j = 0; j < columns; j++)\r\n {\r\n firstRow += (first[j] === 'G') ? \"B\" : first[j];\r\n secondRow += (second[j] === 'G') ? \"B\" : second[j];\r\n }\r\n (firstRow === secondRow) ? print(\"YES\") : print(\"NO\");\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n var n = parseInt(readline());\r\n var r1 = readline().replace(/G/g, \"B\");\r\n var r2 = readline().replace(/G/g, \"B\");\r\n \r\n if(r1 === r2) print(\"YES\"); else print(\"NO\")\r\n \r\n \r\n\r\n \r\n}"}, {"source_code": "var t = readline();\r\nfor (var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n firstRow = readline().split('').map((e) =>{\r\n if(e == 'B' || e == 'G'){\r\n return 1;\r\n }\r\n else{\r\n return e;\r\n }\r\n }),\r\n secondRow = readline().split('').map((e) =>{\r\n if(e == 'B' || e == 'G'){\r\n return 1;\r\n }\r\n else{\r\n return e;\r\n }\r\n });\r\n if(firstRow.join('') == secondRow.join('')){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}\r\n\r\n "}, {"source_code": "// import input from 'input'\n\nvar n = +(readline())\n\nfor (var i = 0; i < n; i++) {\n var ns = readline()\n var s1 = readline()\n var s2 = readline()\n\n if (compare(s1, s2)) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}\n\n\nfunction compare(s1, s2) {\n var s1Pos = s1.split('').map((i, ind) => i === 'R' && ind).filter(x=>x !== false).toString()\n var s2Pos = s2.split('').map((i, ind) => i === 'R' && ind).filter(x=>x !== false).toString()\n \n return s1Pos === s2Pos\n}\n"}, {"source_code": "var n, a, b;\r\n var tests = parseInt(readline());\r\n for (var t=0; t i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0,f = false, k = 0, even = 1\n for(j = 1; j <= n *3; j+=even){\n if(j % 3 == 1){\n even=1\n e = lines[j], f = false\n }else{\n k = lines[j].split('')\n g = lines[j + 1].split('')\n for(l = 0; l < e; l++){\n if(k[l] == 'R' && g[l] == 'R' || k[l] == 'G' && g[l] == 'G' || k[l] == 'G' && g[l] == 'B' || k[l] == 'B' && g[l] == 'G' || k[l] == 'B' && g[l] == 'B' ){\n f = true\n }else{\n f = false\n break;\n }\n }\n even = 2\n if(f){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet str1, str2;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 3 === 1) {\n c++;\n return;\n }\n\n if (c % 3 === 2) {\n str1 = d;\n c++;\n return;\n }\n\n str2 = d;\n let ans = \"YES\";\n\n for (let i = 0; i < str1.length; i++) {\n if (str1[i] !== str2[i] && (str1[i] === \"R\" || str2[i] === \"R\")) {\n ans = \"NO\";\n break;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split('');\n }else{\n var b = lines[i].split('');\n var flag = true;\n for(j = 0; j < n; j++){\n if(a[j] == b[j] || a[j] == 'G' && b[j] == 'B' || a[j] == 'B' && b[j] == 'G'){\n continue;\n }\n flag = false;\n }\n console.log(flag ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var x = Array.from(readline());\r\n var y = Array.from(readline());\r\n var ok = true;\r\n\r\n for (let i = 0;i < n;++i) {\r\n if (x[i] == 'G') {\r\n x[i] = 'B';\r\n }\r\n if (y[i] == 'G') {\r\n y[i] = 'B';\r\n }\r\n if (x[i] != y[i]) {\r\n ok = false;\r\n }\r\n }\r\n if (ok) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n const cb = char => (char === 'G' || char === 'B') ? 'X' : char;\r\n let a = readline().split('').map(cb).join('');\r\n let b = readline().split('').map(cb).join('');\r\n output(a === b ? 'YES': 'NO');\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Main Function, write code here\r\n\r\nfunction main() {\r\n let T = readline();\r\n for (let i = 0; i < T; i++) {\r\n const n = readline();\r\n const row1 = readline()\r\n .split(\"\")\r\n .map((color) => color.replace(\"G\", \"B\"));\r\n const row2 = readline()\r\n .split(\"\")\r\n .map((color) => color.replace(\"G\", \"B\"));\r\n\r\n const identical = row1.join(\"\") === row2.join(\"\");\r\n console.log(identical ? \"Yes\" : \"No\");\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numberOfTest = Number.parseInt(readline());\n for(let i=0; i {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var str1 = readline().replace(/[G]/g, 'B');\r\n var str2 = readline().replace(/[G]/g, 'B');\r\n \r\n if (str1 === str2) {\r\n console.log(\"YES\");\r\n \r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "let readline = require(\"readline\");\r\nconst { start } = require(\"repl\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 3 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\n// let solve = (input) => {\r\n// let name = {\r\n// T: true,\r\n// i: true,\r\n// m: true,\r\n// u: true,\r\n// r: true,\r\n// };\r\n\r\n// for (let i = 1; i < input.length; i += 2) {\r\n// if (+input[i] !== 5) {\r\n// console.log(\"NO\");\r\n// continue;\r\n// } else {\r\n// let count = 0;\r\n// for (let j = 0; j < input[i + 1].length; j++) {\r\n// if (name[input[i + 1][j]]) {\r\n// count++;\r\n// }\r\n// }\r\n// if (count === 5) {\r\n// console.log(\"YES\");\r\n// } else {\r\n// console.log(\"NO\");\r\n// }\r\n// }\r\n// }\r\n// };\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i += 3) {\r\n let block1 = input[i + 1];\r\n let block2 = input[i + 2];\r\n let identical = true;\r\n for (let j = 0; j < block1.length; j++) {\r\n if (block1[j] === block2[j]) continue;\r\n else if (block1[j] === \"B\" && block2[j] === \"G\") continue;\r\n else if (block1[j] === \"G\" && block2[j] === \"B\") continue;\r\n else {\r\n identical = false;\r\n }\r\n }\r\n\r\n if (identical) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n};\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar L = nextCharArray();\r\n\t\tvar R = nextCharArray();\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(L[i] != \"R\"){\r\n\t\t\t\tL[i] = \"?\";\r\n\t\t\t}\r\n\t\t\tif(R[i] != \"R\"){\r\n\t\t\t\tR[i] = \"?\";\r\n\t\t\t}\r\n\t\t\tif(L[i] != R[i]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst LowerBound = (arr, val) =>\r\n{\r\n let ng = -1;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] >= val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\nconst ReverseLowerBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] <= val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d val\r\n return ng;\r\n}\r\n\r\n\r\nconst ReverseUpperBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] < val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 val\r\n return ng;\r\n}\r\n\r\nconst UpperBound = (arr, val) =>\r\n{\r\n let ok = arr.length;\r\n let ng = -1;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] > val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = sc.N();\r\n let one = [...sc.S()];\r\n let two = [...sc.S()];\r\n\r\n for (let i = 0; i < n; ++i)\r\n {\r\n if (one[i] === 'R' && two[i] !== 'R')\r\n {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n\r\n if (one[i] !== 'R' && two[i] === 'R')\r\n {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n }\r\n\r\n console.log(\"YES\");\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = +sc.L();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++]\n const sb = lines[l++]\n output[i] = solve(n, sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb) {\n for (let i = 0; i < sa.length; i++) {\n if (sa[i] !== sb[i]) {\n if (sa[i] === 'G' && sb[i] === 'B') continue\n if (sa[i] === 'B' && sb[i] === 'G') continue\n return 'NO'\n }\n }\n return 'YES'\n}\n"}, {"source_code": "n=+readline();\r\nwhile(n--){\r\n x =+readline();\r\n t1=readline().split(\"\");\r\n t2=readline().split(\"\");\r\n for(i=0;i {\r\n i = 0;\r\n return () => {\r\n return lines[i++]\r\n }\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\nrl.on('close', () => {\r\n const readLine = createReadLine();\r\n console.log(readLine().replace(/\\G/g, 'B') == readLine().replace(/\\G/g, 'B') ? 'YES' : 'NO')\r\n})"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0,f = false, k = 0, even = 1\n for(j = 1; j <= n *2; j+=even){\n if(j % 3 == 1){\n even=1\n e = lines[j], f = false\n }else{\n k = lines[j].split('')\n g = lines[j + 1].split('')\n for(l = 0; l < e; l++){\n if(k[l] == 'R' && g[l] == 'R' || k[l] == 'G' && g[l] == 'G' || k[l] == 'G' && g[l] == 'B' || k[l] == 'B' && g[l] == 'G' || k[l] == 'B' && g[l] == 'B' ){\n f = true\n }else{\n f = false\n break;\n }\n }\n even = 2\n if(f === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n\n});"}], "src_uid": "86a2e0854f9faf0b119d0d5e4b8fe952"} {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction solve() {\r\n var nm = readArray(Number);\r\n var n = nm[0];\r\n var m = Math.min(nm[1], n);\r\n var str = read().split('');\r\n var nextStr;\r\n for (var j = 0; j < m; j++) {\r\n nextStr = '';\r\n for (var i = 0; i < n; i++) {\r\n var left = str[i - 1] === '1' ? 1 : 0;\r\n var right = str[i + 1] === '1' ? 1 : 0;\r\n nextStr += (str[i] === '1' || left + right === 1) ? '1' : '0';\r\n }\r\n str = nextStr;\r\n }\r\n write(str);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 0; i < count; i++) {\r\n const idx = 1 + i * 2;\r\n const nm = lines[idx].split(' ');\r\n const n = parseInt(nm[0]);\r\n const m = parseInt(nm[1]);\r\n const state = lines[idx+1];\r\n console.log(iter(state, n, m));\r\n }\r\n})\r\n \r\nfunction iter(state, n, m) {\r\n let result = '';\r\n for (let i = 0; i < m; i++) {\r\n let change = false;\r\n for (let j = 0; j < n; j++) {\r\n let live_neighbors = 0;\r\n if (j > 0 && state[j-1] === '1') live_neighbors++;\r\n if (j+1 < n && state[j+1] === '1') live_neighbors++;\r\n if (live_neighbors === 1 && state[j] === '0') { result += '1'; change = true }\r\n else result += state[j];\r\n }\r\n state = result;\r\n result = '';\r\n if (!change) break;\r\n }\r\n return state;\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = nextCharArray();\r\n\t\twhile(M > 0){\r\n\t\t\tvar queue = [];\r\n\t\t\tfor(var i = 0; i < N; i++){\r\n\t\t\t\tif(list[i] == \"1\"){\r\n\t\t\t\t\tif(list[i + 1] == \"0\"){\r\n\t\t\t\t\t\tif(i < N - 2){\r\n\t\t\t\t\t\t\tif(list[i + 2] == \"0\"){\r\n\t\t\t\t\t\t\t\tqueue.push(i + 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\tqueue.push(i + 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(list[i - 1] == \"0\"){\r\n\t\t\t\t\t\tif(i > 1){\r\n\t\t\t\t\t\t\tif(list[i - 2] == \"0\"){\r\n\t\t\t\t\t\t\t\tqueue.push(i - 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\tqueue.push(i - 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(queue.length == 0){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tfor(var i = 0; i < queue.length; i++){\r\n\t\t\t\tlist[queue[i]] = \"1\";\r\n\t\t\t}\r\n\t\t\tM--;\r\n\t\t}\r\n\t\tmyout(myconv(list, 0));\r\n\t}\r\n}\r\nfunction ArrayDeque(add){\r\n\tvar queue = {\r\n\t\tL : 0,//next add Area\r\n\t\tR : 0,//next add Area\r\n\t\tmap : {},\r\n\t\tunshift : function(V){ return this.addFirst(V); },\r\n\t\taddFirst : function(V){\r\n\t\t\tthis.map[this.L] = V;\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\tthis.R++;\r\n\t\t\t}\r\n\t\t\tthis.L--;\r\n\t\t},\r\n\t\tshift : function(){ return this.pollFirst(); },\r\n\t\tpollFirst : function(){\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\tvar ret = this.map[this.L + 1];\r\n\t\t\tthis.L++;\r\n\t\t\tif(Math.abs(this.L - this.R) == 1){\r\n\t\t\t\tthis.R--;\r\n\t\t\t}\r\n\t\t\treturn ret;\r\n\t\t},\r\n\t\tpeekFirst : function(){\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\treturn this.map[this.L + 1];\r\n\t\t},\r\n\t\tadd : function(V){ return this.addLast(V); },\r\n\t\tpush : function(V){ return this.addLast(V); },\r\n\t\taddLast : function(V){\r\n\t\t\tthis.map[this.R] = V;\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\tthis.L--;\r\n\t\t\t}\r\n\t\t\tthis.R++;\r\n\t\t},\r\n\t\tpop : function(){ return this.pollLast(); },\r\n\t\tpollLast : function(){\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\tvar ret = this.map[this.R - 1];\r\n\t\t\tthis.R--;\r\n\t\t\tif(Math.abs(this.L - this.R) == 1){\r\n\t\t\t\tthis.L++;\r\n\t\t\t}\r\n\t\t\treturn ret;\r\n\t\t},\r\n\t\tpeekLast : function(){\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\treturn this.map[this.R - 1];\r\n\t\t},\r\n\t\tsize : function(){\r\n\t\t\tif(this.L == this.R){\r\n\t\t\t\treturn 0;\r\n\t\t\t}else{\r\n\t\t\t\treturn Math.abs(this.L - this.R) - 1;\r\n\t\t\t}\r\n\t\t},\r\n\t\ttoString : function(){\r\n\t\t\tvar list = [];\r\n\t\t\tfor(var i = this.L + 1; i < this.R; i++){\r\n\t\t\t\tlist.push(this.map[i]);\r\n\t\t\t}\r\n\t\t\treturn \"[\" + list.join(\", \") + \"]\";\r\n\t\t},\r\n\t\tget : function(index){\r\n\t\t\tif(this.L + 1 + index >= this.R || index < 0){\r\n\t\t\t\treturn null;\r\n\t\t\t}else{\r\n\t\t\t\treturn this.map[this.L + 1 + index];\r\n\t\t\t}\r\n\t\t},\r\n\t\tset : function(index, V){\r\n\t\t\tif(this.L + 1 + index >= this.R || index < 0){\r\n\t\t\t\tthrow 'ArrayIndexOutOfBoundsException can\\'t set';\r\n\t\t\t}else{\r\n\t\t\t\tthis.map[this.L + 1 + index] = V;\r\n\t\t\t}\r\n\t\t},\r\n\t\tisEmpty : function(){\r\n\t\t\treturn this.size() == 0;\r\n\t\t},\r\n\t\tclear : function(){\r\n\t\t\tthis.L = 0;\r\n\t\t\tthis.R = 0;\r\n\t\t\tthis.map = {}\r\n\t\t}\r\n\t}\r\n\tif(add){\r\n\t\tfor(var i = 0; i < add.length; i++){\r\n\t\t\tqueue.addLast(add[i]);\r\n\t\t}\r\n\t}\r\n\treturn queue;\r\n}"}], "negative_code": [{"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 0; i < count; i++) {\r\n const idx = 1 + i * 2;\r\n const nm = lines[idx].split(' ');\r\n const n = parseInt(nm[0]);\r\n const m = parseInt(nm[1]);\r\n const state = lines[idx+1];\r\n console.log(iter(state, n, m));\r\n }\r\n})\r\n\r\nfunction iter(state, n, m) {\r\n let result = '';\r\n for (let i = 0; i < m; i++) {\r\n let change = false;\r\n for (let j = 0; j < n; j++) {\r\n let live_neighbors = 0;\r\n if (j > 0 && state[j-1] === '1') live_neighbors++;\r\n if (j+1 < n && state[j+1] === '1') live_neighbors++;\r\n if (live_neighbors === 1) { result += '1'; change = true }\r\n else result += state[j];\r\n }\r\n if (!change) break;\r\n }\r\n return result;\r\n}"}], "src_uid": "9c9befb908f24a0d7481b75bfdd5780b"} {"source_code": "s=readline().split(' ')\nn=+s[0]\nw=+s[1]\nh=+s[2]\na=[]\nfor(i=0;i a.w*1e7+a.h - b.w*1e7-b.h)\na=[{w:w,h:h,i:0,m:0,t:0}].concat(a)\nfor(i=1;i<=n;i++) {\n for(j=i-1;j>=0;j--) {\n if (a[i].w <= a[j].w || a[i].h <= a[j].h) continue;\n if (a[i].m < a[j].m + 1) {\n a[i].m = a[j].m + 1;\n a[i].t = j;\n }\n }\n}\nm = Math.max(...a.map(v => v.m))\nprint(m);\nkq=[];\nif (m>0) {\n mId = a.findIndex(v => v.m == m)\n while(mId) {\n kq.push(a[mId].i)\n mId = a[mId].t\n }\n}\nprint(kq.reverse().join(' '))", "positive_code": [{"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction doDP(envs) {\n if (!envs.length) return [];\n // -- DP\n var dp = new Array(envs.length);\n dp[0] = { max: 1, i: 0 };\n var best = 0;\n for (var i = 1; i < envs.length; i++) {\n var envI = envs[i];\n var max = 0;\n var maxJ = -1;\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = envI[0] > envJ[0] && envI[1] > envJ[1];\n if (fits && dp[j].max > max) {\n max = dp[j].max;\n maxJ = j;\n }\n }\n dp[i] = { max: max + 1, i: maxJ };\n if (dp[i].max > dp[best].max) {\n best = i;\n }\n }\n // - end DP\n\n // build path from indexes in reverse\n var index = best;\n var path = [];\n\n // print(dp, index)\n\n while (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n }\n if (index === 0) {\n path.unshift(envs[index][2] + 1); // 0\n }\n return path;\n}\n\nconst p = doDP(envs);\n\nprint(p.length);\nif (p.length) {\n print(p.join(' '));\n} \n"}, {"source_code": "\nvar line = readline().split(' ').map( function(v){ return parseInt( v ); } );\n\nvar n = line[0];\nvar w = line[1];\nvar h = line[2];\n\nvar c = [];\nfor( var i=0; ib.h ? 1 : -1;\n\t}else{\n\t\treturn a.w>b.w ? 1 : -1;\n\t}\n});\n// print(c)\nvar max = 0;\nvar maxi = -1;\nfor( i=0; iw && ci.h>h ){\n\t\tif(ci.m+1>max){\n\t\t\tmax=ci.m+1;\n\t\t\tmaxi=i;\n\t\t}\n\t\tfor(var j=i; jci.w && cj.h>ci.h && cj.m < ci.m+1){\n\n\t\t\t\tcj.m = ci.m+1;\n\t\t\t\tcj.c = i;\n\t\t\t\tif(cj.m>max){\n\t\t\t\t\tmax=cj.m;\n\t\t\t\t\tmaxi=j;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n}\n\nif(maxi != -1){\n\tprint(max);\n\n\tvar p = []\n\tfor( i = maxi; c[i]; i = c[i].c){\n\t\tp.push( c[i].i+1 );\n\t}\n\tprint( p.reverse().join(' ') );\n}else{\n\tprint(0)\n}"}, {"source_code": "\nvar line = readline().split(' ').map( function(v){ return parseInt( v ); } );\n\nvar n = line[0];\nvar w = line[1];\nvar h = line[2];\n\nvar c = [];\nfor( var i=0; ib.h ? 1 : -1;\n\t}else{\n\t\treturn a.w>b.w ? 1 : -1;\n\t}\n});\n// print(c)\nvar max = 0;\nvar maxi = -1;\nfor( i=0; iw && ci.h>h ){\n\t\tif(ci.m+1>max){\n\t\t\tmax=ci.m+1;\n\t\t\tmaxi=i;\n\t\t}\n\t\tfor(var j=i; jci.w && cj.h>ci.h && cj.m < ci.m+1){\n\n\t\t\t\tcj.m = ci.m+1;\n\t\t\t\tcj.c = i;\n\t\t\t\tif(cj.m>max){\n\t\t\t\t\tmax=cj.m;\n\t\t\t\t\tmaxi=j;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n}\n\nif(maxi != -1){\n\tprint(max);\n\n\tvar p = []\n\tfor( i = maxi; c[i]; i = c[i].c){\n\t\tp.push( c[i].i+1 );\n\t}\n\tprint( p.reverse().join(' ') );\n}else{\n\tprint(0)\n}"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numEnvelopes = integers[0],\n\t\twidth0 = integers[1], height0 = integers[2];\n\t\n\tvar envelopes = [];\n\n\tfor (var i = 0; i < numEnvelopes; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar width = integers[0], height = integers[1];\n\t\tif (width <= width0 || height <= height0) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tenvelope = { width: width, height: height, id: i+1 };\n\t\tenvelopes.push(envelope);\n\t}\n\n\tif (envelopes.length == 0) {\n\t\tprint(0);\n\t\treturn;\n\t}\n\n\tenvelopes.sort(function(a, b) {\n\t\tif (a.width != b.width) {\n\t\t\treturn a.width-b.width;\n\t\t}\n\t\treturn a.height-b.height;\n\t});\n\n\tenvelopes.unshift({ width: 0, height: 0, id: 0, depth: 0 });\n\n\tvar maxDepth = 0, maxEnvelope;\n\n\tfor (var i = 0; i < envelopes.length; i += 1) {\n\t\tvar b = envelopes[i];\n\t\tb.depth = 0;\n\t\tfor (var j = 0; j < i; j += 1) {\n\t\t\tvar a = envelopes[j];\n\t\t\tif (a.width == b.width || a.height >= b.height) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (b.depth < a.depth+1) {\n\t\t\t\tb.depth = a.depth+1;\n\t\t\t\tb.parent = a;\n\t\t\t}\n\t\t}\n\t\tif (b.depth > maxDepth) {\n\t\t\tmaxDepth = b.depth;\n\t\t\tmaxEnvelope = b;\n\t\t}\n\t}\n\n\tvar envelope = maxEnvelope;\n\tvar chain = [];\n\twhile (envelope.depth > 0) {\n\t\tchain.unshift(envelope.id);\n\t\tenvelope = envelope.parent;\n\t}\n\n\tprint(chain.length+\"\\n\"+chain.join(\" \"));\n\n}\n\nmain();\n"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nw=+s[1]\nh=+s[2]\na=[]\nfor(i=0;i a.w*1e7+a.h - b.w*1e7-b.h)\na=[{w:w,h:h,i:0,m:0,t:0}].concat(a)\nfor(i=1;i<=n;i++) {\n for(j=i-1;j>=0;j--) {\n if (a[i].w <= a[j].w || a[i].h <= a[j].h) continue;\n if (a[i].m < a[j].m + 1) {\n a[i].m = a[j].m + 1;\n a[i].t = j;\n }\n }\n}\nm = Math.max(...a.map(v => v.m))\nprint(m);\nkq=[];\nif (m>0) {\n mId = a.findIndex(v => v.m == m)\n while(mId) {\n kq.push(a[mId].i)\n mId = a[mId].t\n }\n}\nprint(kq.reverse().join(' '))"}], "negative_code": [{"source_code": "\nvar line = readline().split(' ').map( function(v){ return parseInt( v ); } );\n\nvar n = line[0];\nvar w = line[1];\nvar h = line[2];\n\nvar c = [];\nfor( var i=0; ib.h ? 1 : -1;\n\t}else{\n\t\treturn a.w>b.w ? 1 : -1;\n\t}\n});\n// print(c)\nvar max = 0;\nvar maxi = 0;\nfor( i=0; iw && ci.h>h ){\n\t\t\n\t\tfor(var j=i; jci.w && cj.h>ci.h && cj.m < ci.m+1){\n\n\t\t\t\tcj.m = ci.m+1;\n\t\t\t\tcj.c = i;\n\t\t\t\tif(cj.m>max){\n\t\t\t\t\tmax=cj.m;\n\t\t\t\t\tmaxi=j;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n}\n//print(c);\nif(max>0){\n\tprint(max+1);\n\n\tvar p = []\n\tfor( i = maxi; c[i]; i = c[i].c){\n\t\tp.push( c[i].i+1 );\n\t}\n\tprint( p.reverse().join(' ') );\n}else{\n\tprint(0)\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numEnvelopes = integers[0],\n\t\twidth0 = integers[1], height0 = integers[2];\n\t\n\tvar envelopes = [];\n\n\tfor (var i = 0; i < numEnvelopes; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar width = integers[0], height = integers[1];\n\t\tif (width <= width0 || height <= height0) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tenvelope = { width: width, height: height, children: [],\n\t\t\t\tisChild: false, id: i+1 };\n\t\tenvelopes.push(envelope);\n\n\t\tfor (j = envelopes.length-2; j >= 0; j -= 1) {\n\t\t\tvar candidate = envelopes[j];\n\t\t\tif (envelope.width > candidate.width &&\n\t\t\t\t\tenvelope.height > candidate.height) {\n\t\t\t\tenvelope.children.push(candidate);\n\t\t\t\tcandidate.isChild = true;\n\t\t\t}\n\t\t\tif (candidate.width > envelope.width &&\n\t\t\t\t\tcandidate.height > envelope.height) {\n\t\t\t\tcandidate.children.push(envelope);\n\t\t\t\tenvelope.isChild = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (envelopes.length == 0) {\n\t\tprint(0);\n\t\treturn;\n\t}\n\n\tvar order = [];\n\n\tfunction descend(envelope) {\n\t\tif (envelope.visited) {\n\t\t\treturn;\n\t\t}\n\t\tenvelope.visited = true;\n\t\tfor (var i = 0; i < envelope.children.length; i += 1) {\n\t\t\tdescend(envelope.children[i]);\n\t\t}\n\t\torder.unshift(envelope);\n\t}\n\n\tfor (var i = 0; i < envelopes.length; i += 1) {\n\t\tdescend(envelopes[i]);\n\t}\n\n\twrite(order[0].id);\n\tfor (var i = 1; i < order.length; i += 1) {\n\t\twrite(\" \"+order[i].id);\n\t}\n\tprint(\" (\"+order.length+\")\");\n\n\tvar maxDepth = -1, maxEnvelope;\n\n\tfor (var i = 0; i < order.length; i += 1) {\n\t\tvar envelope = order[i];\n\t\tif (envelope.bestDepth === undefined) {\n\t\t\tvar depth = envelope.bestDepth = 0;\n\t\t}\n\t\telse {\n\t\t\tvar depth = envelope.bestDepth;\n\t\t}\n\t\tif (depth > maxDepth) {\n\t\t\tmaxDepth = depth;\n\t\t\tmaxEnvelope = envelope;\n\t\t}\n\t\tfor (var j = 0; j < envelope.children.length; j += 1) {\n\t\t\tvar child = envelope.children[j];\n\t\t\tif (child.bestDepth >= depth+1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchild.bestDepth = depth+1;\n\t\t\tchild.bestParent = envelope;\n\t\t}\n\t}\n\n\tvar envelope = maxEnvelope;\n\tvar chain = [envelope.id];\n\twhile (envelope.bestDepth > 0) {\n\t\tenvelope = envelope.bestParent;\n\t\tchain.push(envelope.id);\n\t}\n\n\tprint(chain.length+\"\\n\"+chain.join(\" \"));\n\n}\n\nmain();\n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\n// -- DP\nvar dp = new Array(envs.length);\n// dp[0] = { max: 1, i: -1 };\nvar best = 0;\nfor (var i = 0; i < envs.length; i++) {\n var env = envs[i];\n var max = -1;\n dp[i] = { max: 1, i: 0 };\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = env[0] > envJ[0] && env[1] > envJ[1];\n if (fits && dp[j].max >= max) {\n dp[i] = { max: dp[j].max + 1, i: j }\n }\n }\n if (dp[i] && dp[i].max > dp[best].max) {\n best = i;\n }\n}\n// - end DP\n\n// build path from indexes in reverse\nvar index = best;\nvar path = [];\n\nwhile (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n}\nif (envs.length) {\n path.unshift(envs[index][2] + 1); // 0\n print(path.length);\n print(path.join(' '));\n} else {\n print('0');\n}\n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction doDP(envs) {\n if (!envs.length) return [];\n // -- DP\n var dp = new Array(envs.length);\n dp[0] = { max: 1, i: 0 };\n var best = 0;\n for (var i = 1; i < envs.length; i++) {\n var envI = envs[i];\n var max = 0; var maxIx;\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = envI[0] > envJ[0] && envI[1] > envJ[1];\n if (fits && dp[j].max + 1 > max) {\n max = dp[j].max + 1;\n maxIx = j;\n }\n }\n dp[i] = { max: max, i: maxIx };\n if (dp[i].max > dp[best].max) {\n best = i;\n }\n }\n // - end DP\n\n // build path from indexes in reverse\n var index = best;\n var path = [];\n\n // print(dp, index)\n\n while (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n }\n if (index === 0) {\n path.unshift(envs[index][2] + 1); // 0\n }\n return path;\n}\n\nconst p = doDP(envs);\n\nprint(p.length);\nif (p.length) {\n print(p.join(' '));\n} \n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction doDP(envs) {\n if (!envs.length) return [];\n // -- DP\n var dp = new Array(envs.length);\n dp[0] = { max: 1, i: -1 };\n var best = 0;\n for (var i = 1; i < envs.length; i++) {\n var envI = envs[i];\n var max = -1;\n dp[i] = { max: 0, i: -1 };\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = envI[0] > envJ[0] && envI[1] > envJ[1];\n if (fits && dp[j].max + 1 > dp[i].max) {\n dp[i] = { max: dp[j].max + 1, i: j };\n }\n }\n if (dp[i].max > dp[best].max) {\n best = i;\n }\n }\n // - end DP\n\n // build path from indexes in reverse\n var index = best;\n var path = [];\n\n while (index >= 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n }\n if (index === 0) {\n path.unshift(envs[index][2] + 1); // 0\n }\n return path;\n}\n\nconst p = doDP(envs);\n\nprint(p.length);\nif (p.length) {\n print(p.join(' '));\n} \n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = {fits: {}};\nvar cards = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n // var wi = l[0], hi = l[1];\n l.push(i);\n cards[i] = l;\n}\n\ncards = cards.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction getChain(arr, w, h, ix) {\n if (ix >= arr.length) {\n return [];\n }\n var key = w + ':' + h + ':' + ix;\n if (cache[key]) {\n print('cached', key);\n return cache[key];\n }\n print('not cached', key);\n // if(car)\n var c = arr[ix];\n var fits = c[0] > w && c[1] > h;\n var res1 = [], res2 = [], res;\n res1 = getChain(arr, w, h, ix + 1);\n\n if (fits) {\n res2 = cache.fits[ix] || [ix, ...getChain(arr, c[0], c[1], ix + 1)]\n cache.fits[ix] = res2;\n // res2.unshift(ix);\n }\n if (res1.length > res2.length) {\n res = res1;\n } else {\n res = res2;\n }\n cache[key] = res;\n return res;\n\n}\nvar res = getChain(cards, w, h, 0);\n\nprint(res.length);\nprint(res.map(c => cards[c][2] + 1).join(' '));\n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\n// -- DP\nvar dp = new Array(envs.length);\ndp[0] = { max: 1, i: -1 };\nvar best = 0;\nfor (var i = 1; i < envs.length; i++) {\n var env = envs[i];\n var max = -1;\n dp[i] = { max: 0, i: 0 };\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = env[0] > envJ[0] && env[1] > envJ[1];\n if (fits && dp[j].max >= dp[i].max) {\n dp[i] = { max: dp[j].max + 1, i: j };\n }\n }\n if (dp[i] && dp[i].max > dp[best].max) {\n best = i;\n }\n}\n// - end DP\n\n// build path from indexes in reverse\nvar index = best;\nvar path = [];\n\nwhile (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n}\nif (envs.length) {\n path.unshift(envs[index][2] + 1); // 0\n print(path.length);\n print(path.join(' '));\n} else {\n print('0');\n}\n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction doDP(envs) {\n if (!envs.length) return [];\n // -- DP\n var dp = new Array(envs.length);\n dp[0] = { max: 1, i: 0 };\n var best = 0;\n for (var i = 1; i < envs.length; i++) {\n var envI = envs[i];\n var max = 0;\n var maxJ = 0;\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = envI[0] > envJ[0] && envI[1] > envJ[1];\n if (fits && dp[j].max > max) {\n max = dp[j].max;\n maxJ = j;\n }\n }\n dp[i] = { max: max + 1, i: maxJ };\n if (dp[i].max > dp[best].max) {\n best = i;\n }\n }\n // - end DP\n\n // build path from indexes in reverse\n var index = best;\n var path = [];\n\n // print(dp, index)\n\n while (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n }\n if (index === 0) {\n path.unshift(envs[index][2] + 1); // 0\n }\n return path;\n}\n\nconst p = doDP(envs);\n\nprint(p.length);\nif (p.length) {\n print(p.join(' '));\n} \n"}, {"source_code": "'use strict';\nvar input = readline().split(' ').map(i => +i);\nvar n = input[0], w = input[1], h = input[2];\n\nvar cache = { fits: {} };\nvar envs = new Array(n);\nfor (var i = 0; i < n; i++) {\n var l = readline().split(' ').map(i => +i);\n envs[i] = [...l, i]; // w, h, i\n}\n\nenvs = envs.filter(v => v[0] > w && v[1] > h).sort((a, b) => {\n if (a[0] == b[0]) return a[1] - b[1]; // order by widht, then height\n return a[0] - b[0];\n});\n\nfunction doDP(envs) {\n if (!envs.length) return [];\n // -- DP\n var dp = new Array(envs.length);\n dp[0] = { max: 1, i: 0 };\n var best = 0;\n for (var i = 1; i < envs.length; i++) {\n var envI = envs[i];\n dp[i] = { max: 0, i: -1 };\n for (var j = 0; j < i; j++) {\n var envJ = envs[j];\n var fits = envI[0] > envJ[0] && envI[1] > envJ[1];\n if (fits && dp[j].max + 1 > dp[i].max) {\n dp[i] = { max: dp[j].max + 1, i: j };\n }\n }\n if (dp[i].max > dp[best].max) {\n best = i;\n }\n }\n // - end DP\n\n // build path from indexes in reverse\n var index = best;\n var path = [];\n\n // print(dp, index)\n\n while (index > 0) {\n path.unshift(envs[index][2] + 1);\n index = dp[index].i\n }\n if (index === 0) {\n path.unshift(envs[index][2] + 1); // 0\n }\n return path;\n}\n\nconst p = doDP(envs);\n\nprint(p.length);\nif (p.length) {\n print(p.join(' '));\n} \n"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nw=+s[1]\nh=+s[2]\na=[]\nfor(i=0;i a[0]*1e7+a[1] - b[0]*1e7-b[1])\na=[[w,h,0,0,0]].concat(a)\n// print(a.join('\\n'))\nfor(i=1;i<=n;i++) {\n a[i][3] = 0;\n a[i][4] = 0;\n for(j=i-1;j>=0;j--) {\n // if (a[i][4]==a[i-1][4]+1) break;\n if (a[i][0] <= a[j][0] || a[i][1] <= a[j][1]) continue;\n if (a[i][3] < a[j][3] + 1) {\n a[i][3] = a[j][3] + 1;\n a[i][4] = j;\n }\n }\n}\n// print(a.join('\\n'))\nm = Math.max(...a.map(v => v[3]))\nprint(m);\nkq=[];\nif (m>0) {\n mId = a.findIndex(v => v[3] == m)\n while(mId) {\n kq.push(a[mId][2])\n mId = a[mId][4]\n }\n}\nprint(kq.reverse().join(' '))"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nw=+s[1]\nh=+s[2]\na=[]\nfor(i=0;i a[0]*1e7+a[1] - b[0]*1e7-b[1])\na=[{w:w,h:h,i:0,m:0,t:0}].concat(a)\nfor(i=1;i<=n;i++) {\n for(j=i-1;j>=0;j--) {\n if (a[i].w <= a[j].w || a[i].h <= a[j].h) continue;\n if (a[i].m < a[j].m + 1) {\n a[i].m = a[j].m + 1;\n a[i].t = j;\n }\n }\n}\nm = Math.max(...a.map(v => v.m))\nprint(m);\nkq=[];\nif (m>0) {\n mId = a.findIndex(v => v.m == m)\n while(mId) {\n kq.push(a[mId].i)\n mId = a[mId].t\n }\n}\nprint(kq.reverse().join(' '))"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nw=+s[1]\nh=+s[2]\na=[]\nfor(i=0;i a[0]*1e7+a[1] - b[0]*1e7-b[1])\na=[[w,h,0,0,0]].concat(a)\nfor(i=1;i<=n;i++) {\n a[i][3] = 0;\n a[i][4] = 0;\n for(j=i-1;j>=0;j--) {\n // if (a[i][4]==a[i-1][4]+1) break;\n if (a[i][0] <= a[j][0] || a[i][1] <= a[j][1]) continue;\n if (a[i][3] < a[j][3] + 1) {\n a[i][3] = a[j][3] + 1;\n a[i][4] = j;\n }\n }\n}\nm = Math.max(...a.map(v => v[3]))\nprint(m);\nkq=[];\nif (m>0) {\n mId = a.findIndex(v => v[3] == m)\n while(mId) {\n kq.push(a[mId][2])\n mId = a[mId][4]\n }\n}\nprint(kq.reverse().join(' '))"}], "src_uid": "6f88e3f4c8a8a444d44e58505a750d3e"} {"source_code": "var\n num = parseInt(readline()),\n arr = readline().split(\" \"),\n map = {},\n map2 = {},\n left = [],\n right = []\n;\n\nfor(var i in arr) {\n arr[i] = parseInt(arr[i]);\n var index = arr[i];\n if (!map[index]) {\n map[index] = 1;\n left.push(index);\n } else {\n if (map2[index]) continue;\n right.push(index);\n map2[index] = 1;\n }\n}\n\nleft.sort(function(a, b){if(a == b) return 0; return a < b ? -1 : 1})\nright.sort(function(a, b){if(a == b) return 0; return a < b ? -1 : 1});\nright.reverse();\n\nif (right.length && left.length) {\n if (right[0] == left[left.length -1]) right.shift();\n}\n\n\nprint(left.length + right.length);\nprint(left.join(\" \") + (right.length > 0 ? \" \" + right.join(\" \") : \"\"));\n", "positive_code": [{"source_code": ";(function () {\n\tprint(function (n, a) {\n\t\tvar b = a.filter(function (e, i, a) { return i === a.lastIndexOf(e); }).sort(function (a, b) { return a - b; }), t = [];\n\n\t\tfor (var i = 0, _i = b.length, k; i < _i; i++)\n\t\t\tif ((k = a.indexOf(b[i])) !== -1) {\n\t\t\t\ta[k] = -1; t.push(b[i]);\n\t\t\t}\n\n\t\tfor (var i = b.length - 2; i > -1; i--)\n\t\t\tif ((k = a.indexOf(b[i])) !== -1) {\n\t\t\t\ta[k] = -1; t.push(b[i]);\n\t\t\t}\n\n\t\treturn t.length + '\\n' + t.join(' ');\n\t}.apply(null, [+readline()].concat([readline().split(' ').map(Number)])));\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numCards = integers[0];\n\n\tvar cards = tokenizeIntegers(readline());\n\tvar counts = {};\n\tvar values = [];\n\tfor (var i = 0; i < cards.length; i += 1) {\n\t\tvar card = cards[i];\n\t\tif (counts[card] === undefined) {\n\t\t\tcounts[card] = 1;\n\t\t\tvalues.push(card);\n\t\t}\n\t\telse {\n\t\t\tcounts[cards[i]] += 1;\n\t\t}\n\t}\n\n\tvalues.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\n\tvar tail = [];\n\tfor (var i = values.length-2; i >= 0; i -= 1) {\n\t\tif (counts[values[i]] > 1) {\n\t\t\ttail.push(values[i]);\n\t\t}\n\t}\n\n\tprint(values.length+tail.length);\n\tprint(values.join(' '), tail.join(' '));\n}\n\nmain();\n"}, {"source_code": "\nvar m = parseInt( readline() );\nvar a = readline().split(' ').map(function(v){ return +v; });\n\na.sort(function(a,b){ return a===b?0: a>b?1:-1; });\n\n\nvar left = [];\nvar right = [];\nvar p = left;\nfor(var i=0; iNumber(x));\nvar H = [];\n\nfor(var i=1; i<=5000; i++)\nH[i]=0;\n\nfor(var x of A)\nH[x]++;\n\nvar ats= [];\n\nfor(var i=1; i<=5000; i++)\nif(H[i] > 0)\n{\nH[i]--;\nats.push(i);\n}\n\nfor(var i=5000; i>=1; i--)\nif(H[i] > 0 && ats[ats.length-1]!=i)\n{\nH[i]--;\nats.push(i);\n}\n\nprint(ats.length);\nvar res = \"\";\nfor(var x of ats)\nres+=x+\" \";\nprint(res);\n\n"}], "negative_code": [{"source_code": "\nvar m = parseInt( readline() );\nvar a = readline().split(' ').map(function(v){ return +v; });\n\na.sort(function(a,b){ return a===b?0: a>b?1:-1; });\n\n\nvar left = [];\nvar right = [];\nvar p = left;\nfor(var i=0; i= cnt[i] * 5 ? 'LIVE' : 'DEAD';\n\t}).join('\\n');\n\n} .apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a = 0;\nlet b = 0;\nlet maxA = 0;\nlet maxB = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [t, x, y] = d.split(' ').map(Number);\n\n if (t === 1) {\n a += x;\n maxA += 10;\n }\n else {\n b += x;\n maxB += 10;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n if (a < maxA - a) {\n console.log('DEAD');\n }\n else {\n console.log('LIVE');\n }\n\n if (b < maxB - b) {\n console.log('DEAD');\n }\n else {\n console.log('LIVE');\n }\n});\n"}, {"source_code": "function imp()\n{\n var n = parseInt(readline());\n var a_count_x = 0, b_count_x = 0;\n var a_count_y = 0, b_count_y = 0;\n \n for(var i=1;i<=n;i++)\n {\n var line = readline().split(\" \");\n if(line[0]=='1')\n {\n a_count_x += parseInt(line[1]);\n a_count_y += parseInt(line[2]);\n }\n else\n {\n b_count_x += parseInt(line[1]);\n b_count_y += parseInt(line[2]);\n }\n }\n if(a_count_x>=a_count_y)\n print(\"LIVE\");\n else\n print(\"DEAD\");\n \n if(b_count_x>=b_count_y)\n print(\"LIVE\");\n else\n print(\"DEAD\");\n}\nimp();"}, {"source_code": "// ################# //\n// 14th October 2019 //\n// ################# //\n\n// ########################################################## //\n// For storing succesfully received packets for each server.\nvar serverACount = 0,serverBCount = 0;\n// For Storing number of pings made to each server.\nvar serverAPings = 0,serverBPings = 0;\n// Computing packet counts for both servers.\nvar commandCount = parseInt(readline());\nfor(var i = 0; i=(10*serverAPings)/2 ? print('LIVE'):\n print('DEAD');\nserverBCount>=(10*serverBPings)/2 ? print('LIVE'):\n print('DEAD');\n// ########################################################## //"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar s = [[0, 0], [0, 0]];\n\t\twhile (n--) {\n\t\t\tvar l = readline().split(' ').map(Number),\n\t\t\t\tk = l[0] === 1 ? 0 : 1;\n\n\t\t\ts[k] = [s[k][0] + l[1], s[k][1] + l[2]];\n\t\t}\n\n\t\treturn s.map(function (e) { return e[0] >= e[1] ? 'LIVE' : 'DEAD' }).join('\\n');\n\t}(+readline()));\n}).call(this);\n"}], "negative_code": [{"source_code": "print(function(n) {\n\n\tvar i, cnt = [0, 0],\n\t\tsum = [0, 0];\n\tfor (i = 0; i < n; i++)\n\t\treadline().split(' ', 2).reduce(function(t, a) {\n\t\t\tcnt[t - 1]++;\n\t\t\tsum[t - 1] += a;\n\t\t});\n\n\treturn sum.map(function(v, i) {\n\t\treturn v >= cnt[i] * 5 ? 'LIVE' : 'DEAD';\n\t}).join('\\n');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar s = [null, null];\n\t\twhile (n--) {\n\t\t\tvar l = readline().split(' ').map(Number);\n\t\t\ts[l[0] === 1 ? 0 : 1] = l[1];\n\t\t}\n\n\t\treturn s.map(function (e) { return e > 4 ? 'LIVE' : 'DEAD' }).join('\\n');\n\t}(+readline()));\n}).call(this);\n"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar s = [[0, 0], [0, 0]];\n\t\twhile (n--) {\n\t\t\tvar l = readline().split(' ').map(Number),\n\t\t\t\tk = l[0] === 1 ? 0 : 1;\n\n\t\t\ts[k] = [s[k][0] + l[1], s[k][1] + l[2]];\n\t\t}\n\n\t\treturn s.map(function (e) { return e[0] > e[1] ? 'LIVE' : 'DEAD' }).join('\\n');\n\t}(+readline()));\n}).call(this);\n"}], "src_uid": "1d8870a705036b9820227309d74dd1e8"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let [n,c] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let obj = {};\r\n for(let i=0;i +i);\n\n var c = arr[1];\n var p = b.split(\" \").map((i) => +i);\n\n var cc = {};\n\n for (var i = 0; i < p.length; i++) {\n if (!cc[p[i]]) {\n cc[p[i]] = 0;\n }\n\n cc[p[i]]++;\n }\n\n var k = 0, keys = Object.keys(cc)\n\n for (var i = 0; i < keys.length; i++) {\n if (cc[keys[i]] <= c) {\n k += cc[keys[i]];\n } else {\n k += c;\n }\n }\n\n return k\n}\n\nvar t = +readline()\n\nwhile (t--) {\n print(solve(readline(), readline()))\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n\r\nfunction run(n, c, arr) {\r\n temp = [];\r\n for(var i = 0; i < n; i++) {\r\n temp[arr[i]] = (temp[arr[i]] || 0) + 1;\r\n }\r\n var count = 0;\r\n for(i = 0; i < temp.length; i++) {\r\n if(!temp[i]) {\r\n continue;\r\n }\r\n if(temp[i] && temp[i] < c) {\r\n count += temp[i];\r\n }else{\r\n count += c;\r\n }\r\n }\r\n return count;\r\n}\r\n\r\nconst n = readNum();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var line1 = readNumArr(), line2 = readNumArr();\r\n print(run(line1[0], line1[1], line2));\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, planets) => {\r\n\tif ( n === 1 ) return 1\r\n\t\r\n let frequency = {}\r\n planets.forEach( p => {\r\n \tfrequency[p] = ( frequency.hasOwnProperty(p) ) ? frequency[p] + 1 : 1\r\n })\r\n \r\n if( c === 1 ) return Object.keys(frequency).length\r\n \r\n let min = 0\r\n Object.values(frequency).forEach( f => {\r\n min += ( f <= c ) ? f : c\r\n })\r\n \r\n return min\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let planets = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, planets)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0], c = a[1];\n }else{\n var ans = 0;\n var m = new Array(101);\n for(j = 0; j < 101; j++){\n m[j] = 0;\n }\n for(j = 0; j < n; j++){\n m[a[j]]++;\n if(m[a[j]] <= c){\n ans++;\n }\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const [n, c] = readArrayInt();\r\n const arr = readArrayInt();\r\n\r\n const asd = [...new Set(arr)];\r\n\r\n const countObj = {};\r\n\r\n let ans = 0;\r\n\r\n arr.map((e, index) => {\r\n if (!countObj[e]) {\r\n countObj[e] = 1;\r\n } else {\r\n countObj[e]++;\r\n }\r\n });\r\n\r\n for (const [key, value] of Object.entries(countObj)) {\r\n ans += Math.min(value, c);\r\n }\r\n\r\n console.log(ans);\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = readline();\n for (let i = 0; i < t; i++) {\n let price = 0;\n const [n, c] = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n const a = readline()\n .split(\" \")\n .map((x) => parseInt(x));\n\n let obj = {};\n\n a.forEach((e) => {\n if (obj[e] == undefined) obj[e] = 1;\n else obj[e]++;\n });\n\n Object.keys(obj).forEach((key) => {\n if (obj[key] <= c) price += obj[key];\n else price += c;\n });\n\n console.log(price);\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n c = rn();\r\n const cnt = new Array(110).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n cnt[rn()]++;\r\n }\r\n let res = 0;\r\n for (let i = 0; i < 110; i++) {\r\n if (cnt[i] === 0) continue;\r\n res += Math.min(cnt[i], c);\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, c] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n let freq = {};\r\n let res = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (freq[arr[i]] === undefined) {\r\n freq[arr[i]] = 1;\r\n } else {\r\n freq[arr[i]]++;\r\n }\r\n }\r\n\r\n Object.keys(freq).forEach(orbit => {\r\n if (freq[orbit] < c) {\r\n res += freq[orbit];\r\n } else {\r\n res += c;\r\n }\r\n });\r\n\r\n output(res);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "function solve(a, b) {\n var arr = a\n .split(\" \")\n .map((i) => +i);\n\n var c = arr[1];\n var p = b.split(\" \").map((i) => +i);\n\n var cc = {};\n\n for (var i = 0; i < p.length; i++) {\n if (!cc[p[i]]) {\n cc[p[i]] = 0;\n }\n\n cc[p[i]]++;\n }\n\n var k = 0, keys = Object.keys(cc)\n\n for (var i = 0; i < keys.length; i++) {\n if (cc[keys[i]] <= c) {\n k += cc[keys[i]];\n } else {\n k += c;\n }\n }\n\n return k\n}\n\nvar t = +readline()\n\nwhile (t--) {\n solve(readline(), readline())\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, planets) => {\r\n\tif ( n === 1 ) return 1\r\n\t\r\n let frequency = new Array(100).fill(0)\r\n \r\n planets.forEach( p => {\r\n \tfrequency[p]++\r\n })\r\n \r\n frequency = frequency.filter( f => f !== 0 ).sort( (a,b) => b - a )\r\n \r\n if( c === 1 ) return frequency.length\r\n \r\n let min = 0\r\n \r\n frequency.forEach( f => {\r\n \tmin += Math.min(f, c)\r\n \t\r\n })\r\n \r\n return min\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let planets = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, planets)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, planets) => {\r\n\tif ( n === 1 ) return 1\r\n\t\r\n let frequency = new Array(100).fill(0)\r\n \r\n planets.forEach( p => {\r\n \tfrequency[p]++\r\n })\r\n \r\n frequency = frequency.filter( f => f !== 0 ).sort( (a,b) => b - a )\r\n \r\n if( c === 1 ) return frequency.length\r\n \r\n let min = 0\r\n let max = n\r\n \r\n frequency.forEach( f => {\r\n \tif( f >= c ) min += c\r\n \telse min++\r\n })\r\n \r\n return Math.min(min, max)\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let planets = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, planets)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, planets) => {\r\n\tif ( n === 1 ) return 1\r\n\t\r\n let maxOrbit = Math.max.apply(null, planets)\r\n let frequency = new Array(maxOrbit + 1).fill(0)\r\n \r\n planets.forEach( (p,i) => {\r\n \tfrequency[p]++\r\n })\r\n \r\n frequency = frequency.filter( f => f !== 0 ).sort( (a,b) => b - a )\r\n \r\n if( c === 1 ) return frequency.length\r\n \r\n let min = 0\r\n let max = n\r\n \r\n for( let f of frequency )\r\n {\r\n \tif(f <= c) min++\r\n\t}\r\n \r\n return Math.min(min, max)\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let planets = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, planets)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, planets) => {\r\n\tif ( n === 1 ) return 1\r\n\t\r\n let maxOrbit = Math.max.apply(null, planets)\r\n let frequency = new Array(maxOrbit + 1).fill(0)\r\n \r\n planets.forEach( (p,i) => {\r\n \tfrequency[p]++\r\n })\r\n \r\n frequency = frequency.filter( f => f !== 0 ).sort( (a,b) => b - a )\r\n \r\n if( c === 1 ) return frequency.length\r\n \r\n \r\n let min = 0\r\n let max = n\r\n \r\n for( let f of frequency )\r\n {\r\n \tif(f > 1) min += c\r\n \telse min += 1\r\n \t\r\n\t}\r\n \r\n return Math.min(min, max)\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let planets = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, planets)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst getResult = (n, c, orbits) => {\r\n let min = 0\r\n let max = Math.max.apply(null, orbits)\r\n let temp = new Array(max + 1).fill(0)\r\n\r\n for (let i = 0; i < n; i++) {\r\n temp[orbits[i]]++\r\n }\r\n \r\n for (let i = 0; i < max + 1; i++) {\r\n if (temp[i] > 1)\r\n min = min + c\r\n if (temp[i] === 0)\r\n min = min + 1\r\n\r\n }\r\n\r\n return min\r\n}\r\n\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n let inputs = readline().split(' ').map(Number)\r\n let n = inputs[0]\r\n let c = inputs[1]\r\n let orbits = readline().split(' ').map(Number)\r\n\r\n let res = getResult(n, c, orbits)\r\n console.log(res)\r\n }\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0], c = a[1];\n }else{\n var ans = 0;\n var m = new Array(100);\n for(j = 0; j < 100; j++){\n m[j] = 0;\n }\n for(j = 0; j < n; j++){\n m[a[j]]++;\n if(m[a[j]] <= c){\n ans++;\n }\n }\n console.log(ans);\n }\n }\n});\n"}], "src_uid": "2805d460df1121c4410999a9f36e383a"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var digits = 10 - readline().split(' ').length;\r\n console.log(digits * (digits - 1) * 3);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let k = 10 - n;\r\n k = (k * (k - 1)) / 2;\r\n console.log(k * 6);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var testCasesCount = parseInt(readline());\r\nvar i = 0;\r\nfor (i = 0; i < testCasesCount; i++) {\r\n var exclusionLength = parseInt(readline());\r\n var excludedNums = readline().split(' ');\r\n var includedCount = 10 - excludedNums.length;\r\n print(((includedCount) * (includedCount - 1) / 2) * 6);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var totalExcluded = parseInt(readline());\r\n readline();\r\n var value = 10 - totalExcluded\r\n var result = 6 * (value * (value-1) / 2);\r\n print(result);\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n if(n == 1){\n console.log(216);\n }\n if(n == 2){\n console.log(168);\n }\n if(n == 3){\n console.log(126);\n }\n if(n == 4){\n console.log(90);\n }\n if(n == 5){\n console.log(60);\n }\n if(n == 6){\n console.log(36);\n }\n if(n == 7){\n console.log(18);\n }\n if(n == 8){\n console.log(6);\n }\n }\n }\n});"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n // let primes = sivOfAtkin(1000)\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let arr = readline().split(' ').map(Number)\r\n console.log( 3 * ( 10 - n ) * ( 9 - n ) )\r\n }\r\n}\r\n// Driver Function Ends //"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, nums) {\r\n let left = 10 - n;\r\n let sum = left * (left - 1) / 2 * 6;\r\n print(sum);\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, x);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n \r\n while(t--)\r\n {\r\n const n = parseInt(readLine());\r\n \r\n const arr_a = readLine().split(\" \").map(x=>parseInt(x));\r\n \r\n let done = new Set()\r\n \r\n //console.log(\"arr_a \" +arr_a)\r\n \r\n let nums = [0,1,2,3,4,5,6,7,8,9]\r\n let second_arr = nums.filter(n => !arr_a.includes(n))\r\n //console.log(\"second_arr\" + second_arr)\r\n for(const a of second_arr)\r\n {\r\n //console.log(\"a \" +a)\r\n for(const b of second_arr.slice())\r\n {\r\n if(a==b)\r\n continue;\r\n //console.log(\"b \" +b)\r\n done.add(a.toString()+a.toString()+b.toString()+b.toString())\r\n done.add(a.toString()+b.toString()+a.toString()+b.toString())\r\n done.add(a.toString()+b.toString()+b.toString()+a.toString())\r\n }\r\n }\r\n //console.log(Array(...done).join(' '))\r\n console.log(done.size)\r\n \r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n rn();\r\n const a = rns();\r\n const set = new Set(a.map(String));\r\n let res = 0;\r\n for (let i = 0; i < 10000; i++) {\r\n const s = i.toString().padStart(4, '0').split('');\r\n const cnt = new Map();\r\n for (let i = 0; i < s.length; i++) {\r\n var _cnt$get;\r\n cnt.set(s[i], ((_cnt$get = cnt.get(s[i])) !== null && _cnt$get !== void 0 ? _cnt$get : 0) + 1);\r\n }\r\n if (cnt.size !== 2) continue;\r\n const [a, b] = [...cnt.keys()];\r\n if (set.has(a) || set.has(b)) continue;\r\n if (cnt.get(a) !== 2 || cnt.get(b) !== 2) continue;\r\n res++;\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n if(n == 1){\n console.log(216);\n }\n if(n == 8){\n console.log(6)\n }\n }\n }\n});"}], "src_uid": "33e751f5716cbd666be36ab8f5e3977e"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const [n, m] = input().split(' ').map(Number);\r\n const s = [];\r\n for(let i = 0; i < n; i++){\r\n s.push(input());\r\n }\r\n let ans = Number.POSITIVE_INFINITY;\r\n for(let i = 0; i < n; i++){\r\n for(let j = i+1; j < n; j++){\r\n ans = Math.min(ans, solve(s[i], s[j], m));\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n\r\nconst solve = (s1, s2, m) => {\r\n let ret = 0;\r\n for(let i = 0; i < m; i++){\r\n let tmp = Number.POSITIVE_INFINITY;\r\n const [c1, c2] = [s1[i], s2[i]];\r\n tmp = Math.min(tmp, Math.abs(c1.charCodeAt(0)-c2.charCodeAt(0)), Math.abs(c2.charCodeAt(0)-c1.charCodeAt(0)));\r\n ret += tmp;\r\n }\r\n return ret;\r\n}", "positive_code": [{"source_code": "/*\r\nFile Created: Tuesday, 17 May 2022\r\nAuthor: Lukas Rimkus\r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\n data += chunk;\r\n});\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '').split('\\n').map(str => str.replace(/\\s*$/, ''));\r\n let testCases = parseInt(readLine());\r\n while(testCases--) {\r\n const [n,m] = get_ints();\r\n const obj = {};\r\n for (let index = 0; index < n; index++) {\r\n obj[index] = readLine();\r\n }\r\n console.log(solve([n,m,obj]));\r\n }\r\n});\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(x=>Number(x));\r\n}\r\n\r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction solve(input){\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let w1;\r\n let w2;\r\n for(let i = 0; i < input[0] - 1; i++){\r\n w1 = Object.values(input[2])[i].split('').map(str => str.charCodeAt());\r\n for(let j = i + 1; j < input[0]; j++){\r\n w2 = Object.values(input[2])[j].split('').map(str => str.charCodeAt());\r\n let diff = 0;\r\n for(let m = 0; m < input[1]; m++){\r\n diff += Math.abs(w1[m] - w2[m])\r\n }\r\n if(min > diff){\r\n min = diff;\r\n }\r\n }\r\n }\r\n return min;\r\n}\r\n\r\nmodule.exports = solve;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let S = [];\r\n const alphabet = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));\r\n const letterPos = {};\r\n alphabet.forEach((letter, i) => letterPos[letter] = i + 1);\r\n\r\n for (let i = 0; i < n; i++) {\r\n S[i] = readline().split('').map(l => letterPos[l]);\r\n }\r\n\r\n let min = Infinity;\r\n\r\n for (let i = 0; i < n; i++) {\r\n let localMin = Infinity;\r\n\r\n for (let j = 0; j < n; j++) {\r\n if (i === j) continue;\r\n let sum = 0;\r\n for (let k = 0; k < m; k++) {\r\n sum += Math.abs(S[i][k] - S[j][k]);\r\n }\r\n localMin = Math.min(localMin, sum);\r\n }\r\n\r\n min = Math.min(min, localMin);\r\n }\r\n\r\n output(min);\r\n }\r\n}"}, {"source_code": "\r\n\r\nconst { createInterface } = require('readline');\r\nconst max = Number.MAX_SAFE_INTEGER\r\n\r\nfunction calcDiff(a, t) {\r\n let diff = max;\r\n for (let j = 0; j < t.length - 1; j++) {\r\n const b = t[j]\r\n let tempDiff = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n tempDiff += Math.abs(a.charCodeAt(i) - b.charCodeAt(i))\r\n\r\n } if (tempDiff < diff) {\r\n diff = tempDiff\r\n }\r\n }\r\n return diff\r\n}\r\n\r\n\r\nfunction main() {\r\n const readline = createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let lineNb = 0;\r\n let subLine = 0;\r\n let n;\r\n let minDiff = max;\r\n let subN;\r\n let t = [];\r\n\r\n readline.on('line', line => {\r\n if (!lineNb) {\r\n lineNb++\r\n n = parseInt(line);\r\n } else {\r\n const data = line.split(\" \")\r\n if (data.length == 2) {\r\n diff = max;\r\n subLine = 0;\r\n lineNb++\r\n minDiff = max\r\n subN = data[0]\r\n t = []\r\n } else {\r\n subLine++;\r\n t.push(data[0])\r\n if (subLine > 1) {\r\n const res = calcDiff(t[subLine - 1], t)\r\n if (minDiff > res) {\r\n minDiff = res\r\n }\r\n }\r\n if (subLine == subN) {\r\n console.log(minDiff)\r\n if (lineNb == n + 1) {\r\n readline.close()\r\n }\r\n }\r\n }\r\n }\r\n\r\n });\r\n\r\n}\r\n\r\nmain()"}, {"source_code": "function diff(a, b) {\r\n var x = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n x += Math.abs(a.charCodeAt(i) - b.charCodeAt(i));\r\n }\r\n return x;\r\n}\r\n\r\nfunction solve(inp) {\r\n var t = Number(inp.nextLine());\r\n while(t--) {\r\n const [n, m] = inp.nextLine().split(\" \").map(x => Number(x));\r\n const arr = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = inp.nextLine();\r\n }\r\n\r\n var min = Number.MAX_SAFE_INTEGER;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n min = Math.min(min, diff(arr[i], arr[j]));\r\n }\r\n }\r\n console.log(min);\r\n }\r\n}\r\n\r\n\r\nclass Input {\r\n constructor(lines) {\r\n this.lines = lines;\r\n this.next = 0;\r\n }\r\n \r\n addLine(line) {\r\n this.lines.push(line) \r\n }\r\n \r\n hasLine() {\r\n return this.lines.size() > 0; \r\n }\r\n \r\n nextLine() {\r\n const line = this.lines[this.next];\r\n if (line) {\r\n this.next++;\r\n }\r\n return line;\r\n }\r\n}\r\n\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst inp = new Input([]);\r\n\r\nreadline.on('line', line => {\r\n inp.addLine(line);\r\n});\r\n\r\nreadline.on('close', () => {\r\n solve(inp);\r\n});"}, {"source_code": "const solve = (arr,n,l) => {\r\n let min = Infinity,cnt;\r\n for(let i=0;iparseInt(cur));\r\n let arr = [];\r\n for(let j=0;j {\n return one\n .map((ch, i) => Math.abs(ch.charCodeAt(0) - two[i].charCodeAt(0)))\n .reduce((a, b) => a + b, 0);\n};\n\nlet lines = 0;\n\nlet words = [];\nconst findMinimumDistance = (words) => {\n let minimumDistance = 100000000;\n for (let i = 0; i < words.length - 1; i++) {\n const one = words[i].split(\"\");\n for (let j = i + 1; j < words.length; j++) {\n const two = words[j].split(\"\");\n const distance = wordDistance(one, two);\n // console.log(distance);\n if (minimumDistance > distance) {\n minimumDistance = distance;\n }\n }\n }\n console.log(minimumDistance);\n};\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n if (line.split(\" \").length === 2) {\n if (words.length > 0) {\n findMinimumDistance(words);\n }\n words = [];\n } else {\n words.push(line);\n }\n }\n lines++;\n});\n\nrl.on(\"close\", function (line) {\n findMinimumDistance(words);\n});\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var [n, x] = readline().split(' ').map((x)=>parseInt(x));\r\n var a = []\r\n for(var i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let ans = Infinity\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n ans = Math.min(ans, cal(arr, i, j))\n }\n }\n return ans\n}\nfunction cal(arr, p, q) {\n let ans = 0\n for (let i = 0; i < arr[0].length; i++) {\n const a = arr[p].charCodeAt(i)\n const b = arr[q].charCodeAt(i)\n const d = Math.abs(a - b)\n // if (arr[p] === 'a' || arr[q] === 'a') {\n ans += d\n // } else if (arr[p] === 'z' || arr[q] === 'z') {\n // ans += d\n // } else {\n // ans += Math.min(d, 26 - d)\n // }\n }\n // console.log(arr[p], arr[q], ans)\n return ans\n}\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, m] = ra();\n let S = [];\n for (let i=0; i{\n let d = 0;\n for (let i=0; i {\r\n data += chunk;\r\n});\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '').split('\\n').map(str => str.replace(/\\s*$/, ''));\r\n let testCases = parseInt(readLine());\r\n while(testCases--) {\r\n const [n,m] = get_ints();\r\n const obj = {};\r\n for (let index = 0; index < n; index++) {\r\n obj[index] = readLine();\r\n }\r\n console.log(solve([n,m,obj]));\r\n }\r\n});\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(x=>Number(x));\r\n}\r\n\r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction solve(input){\r\n let min;\r\n let w1;\r\n let w2;\r\n for(let i = 0; i < input[0] - 1; i++){\r\n w1 = Object.values(input[2])[i].split('').map(str => str.charCodeAt());\r\n for(let j = i + 1; j < input[0]; j++){\r\n w2 = Object.values(input[2])[j].split('').map(str => str.charCodeAt());\r\n let diff = 0;\r\n for(let m = 0; m < input[1]; m++){\r\n diff += Math.abs(w1[m] - w2[m])\r\n }\r\n if(!min || min > diff){\r\n min = diff;\r\n }\r\n }\r\n }\r\n return min;\r\n}\r\n\r\nmodule.exports = solve;"}], "src_uid": "ef2b90d5b1073430795704a7df748ac3"} {"source_code": "var arr = readline().split('');\n\nvar dp = new Array(arr.length);\ndp[dp.length-1]=0;\n\nfor(var i=arr.length-2; i>=0; i--){\n if(arr[i]===arr[i+1])\n dp[i]=dp[i+1]+1;\n else\n dp[i]=dp[i+1];\n}\n\nvar x=parseInt(readline());\n\nwhile(x--){\n var a = readline().split(' ').map(a => parseInt(a));\n print(dp[a[0]-1]-dp[a[1]-1]);\n}", "positive_code": [{"source_code": "var s = readline();\nvar t = readline();\nvar a = [ 0 ];\nvar sum = 0;\nfor (var i = 1; i < s.length; i++) {\n\tif (s[i] === s[i - 1]) {\n\t\tsum++;\n\t}\n\ta.push(sum);\n}\nvar ans = [];\nfor (var i = 0; i < t; i++) {\n\tvar m = readline().split(' ').map((d) => parseInt(d));\n\tvar tmp = a[m[1] - 1] - a[m[0] - 1];\n\tans.push(tmp);\n}\nprint(ans.join('\\n'));\n"}, {"source_code": "var s = readline();\nvar t = readline();\nvar a = [ 0 ];\nvar sum = 0;\nfor (var i = 1; i < s.length; i++) {\n\tif (s[i] === s[i - 1]) {\n\t\tsum++;\n\t}\n\ta.push(sum);\n}\n\nfor (var i = 0; i < t; i++) {\n\tvar m = readline().split(' ').map((d) => parseInt(d));\n\tvar ans = a[m[1] - 1] - a[m[0] - 1];\n\tprint(ans);\n}\n"}, {"source_code": "var m, current = 0, left, right;\nvar input = readline();\nvar charArray = input.split('');\nvar prefixSum = new Array(charArray.length);\nprefixSum[0] = 0;\nfor (var i = 0; i < charArray.length - 1; i++) {\n if (charArray[i] == charArray[i + 1]) {\n current++;\n }\n prefixSum[i + 1] = current;\n}\n\nm = readline();\n\nfor (var i = 0; i < m; i++) {\n input = readline();\n left = Number(input.split(\" \")[0]);\n right = Number(input.split(\" \")[1]);\n print(prefixSum[right - 1] - prefixSum[left - 1]);\n}\n\n\n"}, {"source_code": "var myInput = readline();\nvar myLength = parseInt(readline());\nvar mySum = 0;\nvar sum_arr = [mySum];\nfor (var i = 1; i< myInput.length;i++){\n if (myInput[i-1] == myInput[i]){\n mySum += 1;\n sum_arr.push(mySum);\n }\n else{\n sum_arr.push(mySum);\n }\n}\nfor (var j = 0;j < myLength; j++){\n var next = readline().split(' ').map((val)=>{\n return parseInt(val);\n });\n print(sum_arr[next[1]-1]-sum_arr[next[0]-1]);\n}\n"}, {"source_code": ";(function () {\n\n\tvar s = readline();\n\tvar n = +readline();\n\n\ts = '!' + s;\n\tvar l = s.length;\n\n\tvar b = [0];\n\n\tfor( var i = 1; i < l; i++ )\n\t\tb.push( s[i] !== s[i-1] ? b[i - 1] : b[i - 1] + 1 );\n\n\twhile(n--){\n\t\tprint(readline().split(' ').reduce(function(first, second){\n\t\t\treturn b[second] - b[first];\n\t\t}));\n\t}\n\n}).call(this);"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', line => input.push(line));\n\nRL.on('close', () => {\n let s = input[0];\n const n =parseInt(input[1]);\n\n const map = []; let sum = 0;\n\n map[0] = 0;\n for (let i = 1; i < s.length; i += 1) {\n if (s[i-1] === s[i]) { sum += 1; }\n map[i] = sum;\n }\n\n //console.log(map);\n const answer = [];\n for (i = 0; i < n; i += 1) {\n const [left, right] = input[i + 2].split(' ').map(x => parseInt(x));\n answer.push(map[right-1] - map[left-1]);\n answer.push('\\n');\n }\n\n console.log(answer.join(''));\n});"}, {"source_code": "function main() {\n var line = readline();\n var n = line.length;\n var data = [];\n for(var i=0;i Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n var ans = 1 + ' ';\n for(j = 3; j <= a; j++){\n ans += j + ' ';\n }\n ans += 2;\n console.log(ans);\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar P = [];\r\n\t\tfor(var i = 1; i <= N / 2; i++){\r\n\t\t\tP.push(i);\r\n\t\t\tP.push(N - i + 1);\r\n\t\t}\r\n\t\tif(N % 2 == 1){\r\n\t\t\tP.push(Math.ceil(N / 2));\r\n\t\t}\r\n\t\tmyout(myconv(P, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let i = 1,\r\n j = n,\r\n k = 1;\r\n let res = new Array(n).fill(0);\r\n while (i <= j) {\r\n if (i === j) res[i - 1] = k++;\r\n else {\r\n res[j - 1] = k++;\r\n res[i - 1] = k++;\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var n = readline();\r\n var res = [1];\r\n for (var i = n; i > 1; i--) {\r\n res.push(i);\r\n if (i == 2) {\r\n process.stdout.write(res.join(\" \") + '\\n');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n // let primes = sivOfAtkin(1000)\r\n while (t--) {\r\n let n = parseInt(readline())\r\n // let arr = readline().split(' ').map(Number)\r\n console.log(solve(n))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n) => {\r\n let res = ''\r\n let i = 1\r\n\twhile(++i <= n)\r\n\t{\r\n\t\tres += ( i + ' ' )\r\n\t}\r\n\r\n res += 1\r\n\t\r\n return res\r\n}\r\n\r\nfunction factorial(num) {\r\n let rval=1\r\n for (let i = 2; i <= num; i++)\r\n rval = rval * i\r\n return rval\r\n}\r\n\r\n\r\nfunction excludes(a, b) {\r\n let setB = new Set(b)\r\n return [...new Set(a)].filter(x => !setB.has(x))\r\n}\r\n\r\nfunction intersect(a, b) {\r\n let setB = new Set(b)\r\n return [...new Set(a)].filter(x => setB.has(x))\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\nconst factors = number => Array.from(Array(number + 1), (_, i) => i).filter(i => number % i === 0)\r\n\r\nfunction sivOfAtkin(limit) {\r\n let limitSqrt = Math.sqrt(limit)\r\n let sieve = new Array(limit + 1).fill(false)\r\n sieve[2] = sieve[3] = true\r\n\r\n let n = 0\r\n for (let x = 1; x <= limitSqrt; x++) {\r\n let xx = x * x\r\n for (let y = 1; y <= limitSqrt; y++) {\r\n let yy = y * y\r\n if (xx + yy >= limit) break\r\n\r\n // first quadratic using m = 12 and r in R1 = {r : 1, 5}\r\n n = (4 * xx) + (yy)\r\n if (n <= limit && (n % 12 == 1 || n % 12 == 5)) sieve[n] = !sieve[n]\r\n\r\n // second quadratic using m = 12 and r in R2 = {r : 7}\r\n n = (3 * xx) + (yy)\r\n if (n <= limit && (n % 12 == 7)) sieve[n] = !sieve[n]\r\n\r\n // third quadratic using m = 12 and r in R3 = {r : 11}\r\n n = (3 * xx) - (yy)\r\n if (x > y && n <= limit && (n % 12 == 11)) sieve[n] = !sieve[n]\r\n }\r\n }\r\n\r\n return sieve\r\n}\r\n\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\n\r\n// cmd: cat input.txt | node main.js"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n) {\r\n if(n == 1) {\r\n print('1');\r\n return;\r\n }\r\n let res = new Array(n).fill(0);\r\n for(let i = 1; i < n; i++) {\r\n res[i] = i + 2;\r\n }\r\n res[0] = 1;\r\n res[n - 1] = 2;\r\n print(res.join(' '));\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n begin(n);\r\n }\r\n}"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n console.log(1, 4, 3, 5, 2);\n console.log(4, 1, 6, 2, 5, 3)\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split('').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[j];\n }else{\n y += a[j];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar P = [];\r\n\t\tfor(var i = 1; i <= N; i++){\r\n\t\t\tP.push(i);\r\n\t\t}\r\n\t\tfor(var i = 1; i < N - 1; i += 2){\r\n\t\t\tvar tmp = P[i];\r\n\t\t\tP[i] = P[i + 1];\r\n\t\t\tP[i + 1] = tmp;\r\n\t\t}\r\n\t\tmyout(myconv(P, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar P = [];\r\n\t\tfor(var i = 1; i <= N; i += 2){\r\n\t\t\tP.push(i);\r\n\t\t}\r\n\t\tfor(var i = 2; i <= N; i += 2){\r\n\t\t\tP.push(i);\r\n\t\t}\r\n\t\tmyout(myconv(P, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = [];\r\n for (let i = n; i >= 1; i--) arr.push(i);\r\n console.log(arr.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "6fced7d8ac3dd58b1791430ada53332d"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst addBigNumbers = (x, y) => {\n const a = [...x];\n a.reverse();\n const b = [...y];\n b.reverse();\n const res = [];\n const size = Math.max(a.length, b.length);\n\n for (let i = 0; i < size; i++) {\n const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);\n const cat = oof % 10;\n const rest = parseInt(oof / 10);\n\n res[i] = cat;\n res[i + 1] = rest;\n }\n\n res.reverse();\n\n return res[0] === 0 ? res.slice(1) : res;\n};\n\nfunction main() {\n const n = parseInt(readline());\n const arrays = [];\n for (let i = 0; i < n; i++) {\n arrays.push(parseInt(readline()));\n } \n\n arrays.forEach(a => {\n const size = parseInt(a / 2);\n let sumSmol = 0;\n let sum = [];\n\n for (let i = 0; i < size; i++) {\n const mic = 2 * i + 1;\n const mare = 2 * (i + 1) + 1;\n const gucciMic = (i + 1) * (mare * mare - mic * mic);\n if (i < 225000) {\n sumSmol += gucciMic;\n } else {\n const gucci = `${gucciMic}`.split('').map(o => parseInt(o));\n sum = addBigNumbers(sum, gucci);\n }\n }\n\n sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));\n\n console.log(sum.join(''));\n });\n}\n", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tlet s = 0n;\n\n\t\twhile (n > 1) {\n\t\t\ts += BigInt(4 * (n - 1) * Math.floor(n / 2));\n\t\t\tn -= 2;\n\t\t}\n\n\t\tconsole.log(s.toString());\n\t}\n}\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst addBigNumbers = (x, y) => {\n const a = [...x];\n a.reverse();\n const b = [...y];\n b.reverse();\n const res = [];\n const size = Math.max(a.length, b.length);\n\n for (let i = 0; i < size; i++) {\n const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);\n const cat = oof % 10;\n const rest = parseInt(oof / 10);\n\n res[i] = cat;\n res[i + 1] = rest;\n }\n\n res.reverse();\n\n return res[0] === 0 ? res.slice(1) : res;\n};\n\nfunction main() {\n const n = parseInt(readline());\n const arrays = [];\n for (let i = 0; i < n; i++) {\n arrays.push(parseInt(readline()));\n } \n\n arrays.forEach(a => {\n if (a === 1) {\n console.log(0);\n }\n\n const size = parseInt(a / 2);\n let sumSmol = 0;\n let sum = [];\n\n for (let i = 0; i < size; i++) {\n const mic = 2 * i + 1;\n const mare = 2 * (i + 1) + 1;\n const gucciMic = (i + 1) * (mare * mare - mic * mic);\n if (i < 225000) {\n sumSmol += gucciMic;\n } else {\n const gucci = `${gucciMic}`.split('').map(o => parseInt(o));\n sum = addBigNumbers(sum, gucci);\n }\n }\n\n sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));\n\n console.log(sum.join(''));\n });\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst addBigNumbers = (x, y) => {\n const a = [...x];\n a.reverse();\n const b = [...y];\n b.reverse();\n const res = [];\n const size = Math.max(a.length, b.length);\n\n for (let i = 0; i < size; i++) {\n const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);\n const cat = oof % 10;\n const rest = parseInt(oof / 10);\n\n res[i] = cat;\n res[i + 1] = rest;\n }\n\n res.reverse();\n\n return res[0] === 0 ? res.slice(1) : res;\n};\n\nfunction main() {\n const n = parseInt(readline());\n const arrays = [];\n const start = new Date();\n for (let i = 0; i < n; i++) {\n arrays.push(parseInt(readline()));\n } \n\n arrays.forEach(a => {\n if (a === 1) {\n console.log(0);\n }\n\n const size = parseInt(a / 2);\n let sumSmol = 0;\n let sum = [];\n\n for (let i = 0; i < size; i++) {\n const mic = 2 * i + 1;\n const mare = 2 * (i + 1) + 1;\n const gucciMic = (i + 1) * (mare * mare - mic * mic);\n if (i < 225000) {\n sumSmol += gucciMic;\n } else {\n const gucci = `${gucciMic}`.split('').map(o => parseInt(o));\n sum = addBigNumbers(sum, gucci);\n }\n }\n\n sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));\n\n console.log(sum.join(''));\n });\n const end = new Date();\n\n console.log(end - start);\n}\n"}], "src_uid": "b4b69320c6040d2d264ac32e9ba5196f"} {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i <= Number(q[0]); i++) {\n console.log(solve(q[i]))\n }\n}\nfunction solve(s) {\n const stack = {\n '1': 0,\n '2': 0,\n '3': 0\n };\n let min = 0, iter = 0;\n for(let i = 0; i < s.length; i++) {\n while(iter < s.length && (stack['1'] === 0 || stack['2'] === 0 || stack['3'] === 0)) {\n stack[s[iter++]]++;\n }\n let full = true;\n for(let i in stack) {\n full = full && stack[i]\n }\n if (full) {\n if (iter - i < min || min === 0) {\n min = iter - i;\n }\n }\n stack[s[i]]--;\n }\n return min;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n", "positive_code": [{"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i x - 1)\n let pos = [null, null, null]\n let min = null\n let count = 0\n for (let i =0; i diff) {\n min = diff\n }\n }\n\n }\n }\n if (min === null) {\n console.log(0)\n } else {\n console.log(min+1)\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function comp(a,b) { return a-b; }\nfunction solve(str) {\n var one = 0, two = 0, three = 0, ans = 200005, d = 0, arr = [];\n for (var i in str) {\n if (str[i] == '1')\n one = i;\n else if (str[i] == '2')\n two = i;\n else\n three = i;\n\n if (one && two && three) {\n arr = [one,two,three];\n arr.sort(comp);\n d = arr[2]-arr[0]+1;\n ans = Math.min(ans,d);\n }\n }\n print(ans == 200005 ? 0 : ans);\n}\nvar t = Number(readline());\nwhile (t--) {\n var str = readline();\n solve(str);\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i <= Number(q[0]); i++) {\n console.log(solve(q[i]))\n }\n}\nfunction solve(s) {\n const stack = {\n '1': false,\n '2': false,\n '3': false\n };\n let count = 0, min = 0;\n function check(q) {\n count++;\n stack[q] = true;\n let full = true;\n for(let i in stack) {\n full = full && stack[i]\n }\n if (full) {\n for(let i in stack) {\n stack[i] = false;\n }\n if (count < min || min === 0) {\n min = count;\n }\n count = 0;\n }\n }\n for(let i of s) {\n check(i);\n }\n return min;\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}], "src_uid": "6cb06a02077750327602a1a7eeac770f"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet x = 0;\r\n\t\twhile (n-1 >= 1 << x) x++;\r\n\t\tx--;\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = n-1; i > 0; i--) {\r\n\t\t\tans.push(i);\r\n\t\t\tif (i == 1 << x) ans.push(0);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const solve = n=>{\r\n if(n===2){\r\n console.log(\"0 1\");\r\n return;\r\n }\r\n let t = 1<<(Math.floor(Math.log2(n-1)));\r\n let arr = [];\r\n for(let i=1;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n var b = 1;\n while(b * 2 < n){\n b *= 2;\n }\n var ans = '';\n for(j = b - 1; j >= 0; j--){\n ans += j + ' ';\n }\n for(j = b; j < n; j++){\n ans += j + ' ';\n }\n console.log(ans);\n }\n});"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\twhile (t--) {\r\n\t\tvar n = readInt();\r\n\t\tvar largestPowOf2 = 1;\r\n\t\tvar temp = n - 1;\r\n\t\twhile ((temp >> 1) > 0) {\r\n\t\t\ttemp >>= 1;\r\n\t\t\tlargestPowOf2 <<= 1;\r\n\t\t}\r\n\t\t// Put 1,2,3,... 0, largestPower of 2, larger numbers\r\n\t\tvar ans = [];\r\n\t\tfor (var i = 1; i < largestPowOf2; i++)\r\n\t\t\tans.push(i);\r\n\t\tans.push(0);\r\n\t\tfor (var i = largestPowOf2; i < n; i++)\r\n\t\t\tans.push(i);\r\n\t\toneLineArrayPrint(ans);\r\n\t}\r\n\t\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [{"source_code": "const solve = n=>{\r\n let t = 1<<(Math.floor(Math.log2(n)));\r\n let arr = [];\r\n for(let i=1;i str.trim());\r\n\t}\r\n\r\n\treadline() {\r\n\t\treturn this.input[this.curLine++];\r\n\t}\r\n\r\n\treadInts() {\r\n\t\treturn this.readline()\r\n\t\t\t.split(' ')\r\n\t\t\t.map((x) => parseInt(x, 10));\r\n\t}\r\n}\r\n\r\nconst input = new INPUT();\r\n\r\nprocess.stdin.on('data', (str) => {\r\n\tinput.append(str);\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n\tinput.prepare();\r\n\tmain();\r\n});\r\n\r\nfunction solve() {\r\n\tlet [n, k] = input.readInts();\r\n\tlet a = input.readInts().map((x, idx) => Math.log2(x) + idx);\r\n\tlet b = [...new Array(n - 1)].map((_, idx) =>\r\n\t\ta[idx + 1] <= a[idx] + 1e-9 ? 1 : 0\r\n\t);\r\n\r\n\tfor (let i = 1; i < b.length; i++) {\r\n\t\tb[i] += b[i - 1];\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\r\n\tfor (let i = 0; i < n - k; i++) {\r\n\t\tif (b[i + k - 1] - (i > 0 ? b[i - 1] : 0) === 0) {\r\n\t\t\tans++;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\nfunction main() {\r\n\tlet [T] = input.readInts();\r\n\r\n\twhile (T--) {\r\n\t\tsolve();\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n let res = 0;\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n while (j + 1 < n && a[j] < a[j + 1] * 2) {\r\n j++;\r\n }\r\n res += Math.max(0, j - i + 1 - m);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var [n,k] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var ans = 0;\r\n var ok = []\r\n for(var i=1;i 0.5);\r\n }\r\n var j = 0;\r\n for(var i=1;i k) ans++;\r\n }\r\n\r\n console.log(ans)\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const dp = []\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n if (i && arr[i - 1] < 2 * arr[i]) {\n dp[i] = dp[i - 1] + 1\n } else {\n dp[i] = 1\n }\n if (dp[i] >= k + 1) ans++\n }\n // console.log(dp)\n return ans\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let [i, num] of a.entries()) {\r\n if (!map.has(num)) map.set(num, []);\r\n map.get(num).push(i);\r\n }\r\n let res = [1, a[0], 0, 0];\r\n for (let [num, list] of map) {\r\n const sum = [];\r\n let l = 0,\r\n r = 0;\r\n sum[0] = 1;\r\n for (let i = 1; i < list.length; i++) {\r\n var _list;\r\n const cur = sum[i - 1] - (list[i] - ((_list = list[i - 1]) !== null && _list !== void 0 ? _list : -1) - 1) + 1;\r\n if (cur > 0) {\r\n r = i;\r\n } else {\r\n l = i;\r\n r = i;\r\n }\r\n sum[i] = Math.max(0, cur);\r\n if (res[0] < sum[i]) {\r\n res = [sum[i], num, list[l], list[r]];\r\n }\r\n }\r\n }\r\n const [, x, y, z] = res;\r\n return `${x} ${y + 1} ${z + 1}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "b5ef56f2eb482682414c32fba83a3949"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n map[x] = (map[x] || 0) + 1\n if (map[x] >= 3) return x\n }\n return -1\n}\n", "positive_code": [{"source_code": "var sum=parseInt(readline());\r\nvar num=[];\r\nvar arr=[];\r\nfor(var i=0;i=2){\r\n b=y;\r\n if(calc[y]<=calc[y+1]){\r\n b=y+1;\r\n }\r\n }\r\n }\r\n if(b!=-1){\r\n print(hob[b]);\r\n }\r\n else{\r\n print(-1);\r\n }\r\n \r\n }"}, {"source_code": "var t = +readline()\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline()\r\n var arr1 = readline().split(\" \").map(x => +x);\r\n print(returnThree(arr1));\r\n}\r\n \r\nfunction returnThree(n){\r\n\r\n var obj = {};\r\n for(var each of n){\r\n if (obj.hasOwnProperty(each)){\r\n obj[each]++;\r\n if (obj[each] >= 3){\r\n return each;\r\n }\r\n }else {\r\n obj[each] = 1;\r\n }\r\n }\r\n return -1;\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var a = new Map();\n var ans = -1;\n for(j = 0; j <= e; j++){\n if(a.has(k[j])){\n temp = a.get(k[j]);\n temp++;\n a.set(k[j], temp);\n }else{\n a.set(k[j], 1);\n }\n }\n for(var [key, value] of a){\n if(value >= 3){\n ans = key;\n break;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var a = 0;\n var answer = -1;\n for(j = 0; j <= e; j++){\n if(k[j] == k[j - 1]){\n a++;\n }else{\n a++;\n if(a >= 3){\n answer = k[j - 1];\n break;\n }\n a = 0;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var a = new Map();\n for(j = 0; j < e; j++){\n if(a.has(k[j])){\n var temp = a.get(k[j]);\n temp++;\n a.set(k[j], temp);\n }else{\n a.set(k[j], 1);\n }\n }\n var found = false;\n for(var [key, value] of a){\n if(value >= 3){\n console.log(key);\n found = true;\n break;\n }\n }\n if(!found){\n console.log(-1);\n }\n }\n }\n});"}, {"source_code": "function solve(nums) {\n const map = new Map();\n for (const num of nums) {\n pre = map.get(num) || 0;\n map.set(num, pre + 1);\n if (pre == 2) {\n console.log(num)\n return;\n }\n }\n console.log(-1)\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input.slice(1).map(item => item.split(' ').map(n => parseInt(n)));\n const len = dataArr.length;\n\n for (let i = 1; i < len; i += 2) {\n solve(dataArr[i]);\n }\n process.exit();\n});\n\n \t \t\t\t\t \t\t \t\t\t \t \t \t \t\t\t\t\t\t\t"}, {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const total = +input[0];\n\n for (let i = 1; i <= total; i++) {\n console.log(solve(input[i * 2]));\n }\n\n process.exit();\n});\n\nfunction solve(str) {\n const ary = str.split(' ');\n const map = new Map();\n for (let ele of ary) {\n const get = map.get(ele) || 0;\n if (get === 2) {\n return ele;\n }\n map.set(ele, get + 1);\n }\n return -1;\n}\n\n\n \t\t \t \t \t\t\t\t\t\t\t\t \t \t \t\t \t\t\t"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 2; i < input.length; i+=2) {\r\n let nums = input[i].split(' ').map(Number);\r\n let freq = new Map();\r\n let max = 0;\r\n \r\n for (let j = 0; j < nums.length; j++) {\r\n freq.set(nums[j], (freq.get(nums[j]) || 0) + 1);\r\n if (freq.get(nums[j]) > 2 && freq.get(nums[j]) > max) max = freq.get(nums[j]);\r\n }\r\n freq = [...freq].filter(v=>v[1]===max).sort((a,b)=>b[0]-a[0]);\r\n ans.push(freq.length === 0 ? -1 : freq[0][0]);\r\n }\r\n console.log(ans.join('\\n'));\r\n \r\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var a = 0;\n var answer = -1;\n for(j = 0; j <= e; j++){\n if(k[j] == k[j - 1]){\n a++;\n }else{\n a++;\n if(a >= 3){\n answer = k[j - 1];\n break;\n }\n a = 0;\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let freq = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n if (freq[arr[i]]) {\r\n freq[arr[i]]++;\r\n } else {\r\n freq[arr[i]] = 1;\r\n }\r\n if(freq[arr[i]] > 2) {\r\n output(arr[i]);\r\n break;\r\n }\r\n if (i === arr.length - 1) {\r\n output(-1);\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var c = readLine();\r\n var res = solveMeFirst(c);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(str) {\r\n str = str.split(\" \");\r\n let arr = [];\r\n for (let i = 0; i < str.length; i++) {\r\n arr[+str[i]] ? arr[+str[i]]++ : (arr[+str[i]] = 1);\r\n if (arr[+str[i]] >= 3) return +str[i];\r\n }\r\n return -1;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet c = new Array(n+1);\n\t\ta.forEach((e) => {\n\t\t\tif (c[e]) {\n\t\t\t\tc[e]++;\n\t\t\t} else {\n\t\t\t\tc[e]= 1;\n\t\t\t}\n\t\t});\n\t\tlet flag = true;\n\t\tfor(let j = 0; j <= n; j++){\n\t\t\tif (c[j] && c[j] >=3) {\n\t\t\t\tflag = false;\n\t\t\t\tans.push(j);\n\t\t\t\tbreak;\n\t\t\t} \n\t\t}\n\t\tif (flag) {\n\t\t\tans.push(-1);\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let i = readline()\n while (i--) {\n const n = readline() | 0\n const arr = readline().split(' ').map(Number)\n const map = Array.from(new Array(arr.length), _ => 0)\n let out = -1\n for (let i = 0; i < arr.length; i++)\n if (++map[arr[i] - 1] === 3) {\n out = arr[i]\n break\n }\n console.log(out)\n }\n}\n\n \t\t\t \t \t\t \t\t \t \t\t\t \t\t \t\t"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline()\n const A = readline().split(' ').map(x => +x)\n solve(A)\n }\n}\nfunction solve(A) {\n\n let map = new Map()\n for (let i = 0; i < A.length; i++) {\n if (map.has(A[i])) {\n map.set(A[i], map.get(A[i]) + 1)\n } else {\n map.set(A[i], 1)\n }\n\n if (map.get(A[i]) >= 3) {\n console.log(A[i])\n return \n }\n }\n\n console.log(-1)\n}\n\n"}, {"source_code": "/*\r\n * File Created: Thursday, 11th February 2021 1:42:08 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(data.shift());\r\n const a = get_ints();\r\n \r\n console.log(b784(n,a));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n let k = 0;\r\n let j = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(arr[i] < 0){\r\n arr[j++] *= -1;\r\n arr[i] *= -1;\r\n }\r\n }\r\n if(isSorted(arr)) {\r\n return 'YES';\r\n } else { \r\n return 'NO'\r\n }\r\n}\r\n\r\nfunction isSorted(arr){\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] > arr[i+1]) return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction b(s) {\r\n let arr = [];\r\n for(let i = 97; i <= 122; i++ ){\r\n for(let j = 97; j <= 122; j++){\r\n if(i != j) arr.push(String.fromCharCode(i,j));\r\n }\r\n }\r\n let count = 1;\r\n let index = 0;\r\n while(true){\r\n if(s != arr[index]) {\r\n count++;\r\n index++;\r\n } else{\r\n return count;\r\n }\r\n }\r\n}\r\n\r\nfunction a784(s){\r\n if(s >= 1900) {\r\n return 'Division 1';\r\n } else if(s >= 1600){\r\n return 'Division 2';\r\n } else if(s >= 1400){\r\n return 'Division 3';\r\n } else {\r\n return 'Division 4';\r\n }\r\n}\r\n\r\nfunction b784(n,array){\r\n let list = {};\r\n let counter = 0;\r\n array.forEach(item => {\r\n if (!list[item]) {\r\n list[item] = 1;\r\n } else {\r\n list[item] += 1;\r\n }\r\n if (list[item] > counter) {\r\n counter = list[item];\r\n }\r\n })\r\n for(const[key,value] of Object.entries(list)){\r\n if(value >= 3) return key;\r\n }\r\n return -1;\r\n}\r\nmodule.exports = b784;"}, {"source_code": "\n\nconst processData = (lines) => {\n let count = +lines[0]\n let cur = 0\n while(count--) {\n cur++\n // let [n] = lines[cur].split(' ').map(x => +x)\n cur++\n let nums = lines[cur].split(' ').map(x => +x)\n let found = -1;\n\n let map = {}\n for (const num of nums) {\n map[num] = map[num] ? map[num] + 1 : 1;\n if (map[num] >= 3) {\n found = num;\n break;\n }\n }\n\n console.log(found);\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = -1;\r\n\t\tconst cnt = Array(n+1).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) { \r\n\t\t\tcnt[a[i]]++; \r\n\t\t\tif (cnt[a[i]] == 3) ans = a[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let [num, count] of map) {\r\n if (count >= 3) {\r\n console.log(num);\r\n return;\r\n }\r\n }\r\n console.log(-1);\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar key = Object.keys(map);\r\n\t\tvar output = -1;\r\n\t\tfor(var i = 0; i < key.length; i++){\r\n\t\t\tif(map[key[i]] >= 3){\r\n\t\t\t\toutput = key[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (n, a)=>{\n let map = {};\n\n for (const x of a) {\n if (map[x] === 2) return x;\n map[x] = (map[x] || 0) + 1;\n }\n\n return -1;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, A)=>{\n A.sort((a, b)=>a-b);\n for (let i=0; i +x)\r\n result = {}\r\n for( i=0; i=3){\r\n ans = key\r\n break\r\n }\r\n }\r\n \r\n print(ans)\r\n}\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var ar = lines[i].split(' ').map(Number);\n var a = 0, b = n - 1;\n var a1 = ar[0], b1 = ar[b];\n var ans = 0;\n while(a < b){\n if(a1 == b1){\n ans = a + 1 + n - b;\n a++;\n a1 += ar[a];\n }else if(a1 > b1){\n b--;\n b1 += ar[b];\n }else if(a1 < b1){\n a++;\n a1 += ar[a];\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i], a = new Map(), flag = false;\n }else{\n k = lines[i].split(' ').map(Number);\n for(j = 0; j < n; j++){\n if(a.has(k[j])){\n flag = true;\n break;\n }else{\n a.set(k[j]);\n }\n }\n console.log(flag === true ? 'NO' : 'YES');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(!ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){\n if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split('').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j ++){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j ++){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var a = new Map();\n for(j = 0; j < e; j++){\n if(a.has(k[j])){\n var temp = a.get(k[j]);\n temp++;\n a.set(k[j], temp);\n }else{\n a.set(k[j], 1);\n }\n }\n var found = false;\n for(var [key, value] of a){\n if(value >= 3){\n console.log(key);\n found = true;\n }\n }\n if(!found){\n console.log(-1);\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num * 2) {\n dealInput(rows);\n }\n }\n});\nconst dealInput = (rows) => {\n rows.forEach((item, index) => {\n if ((index + 1) % 2 === 0) {\n let newArr = item.split(' ')\n console.log(setNum(newArr));\n }\n })\n rl.close();\n};\n\nfunction setNum(arr) {\n let l = -1\n let newArr = arr.join(',')\n if(arr.length < 3) return -1\n for(let i = 0; i < arr.length; i++) {\n if(newArr.split(arr[i]).length > 3) {\n return arr[i]\n } else {\n continue\n }\n }\n return l\n}\n\nrl.on('close', () => {\n process.exit(0);\n});\n \t\t \t \t \t \t \t \t\t \t \t \t \t\t"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 2; i < input.length; i+=2) {\r\n let nums = input[i].split(' ').map(Number);\r\n let freq = new Map();\r\n let max = 0;\r\n \r\n for (let j = 0; j < nums.length; j++) freq.set(nums[j], (freq.get(nums[j]) || 0) + 1);\r\n freq = [...freq].filter(v=>v[1]>1).sort((a,b)=>{\r\n return a[1] < b[1] ? b[1]-a[1] : a[0] < b[0] ? 1 : -1;\r\n });\r\n ans.push(freq.length === 0 ? -1 : freq[0][0]);\r\n }\r\n console.log(ans.join('\\n'));\r\n \r\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var a = new Map()\n\n var k = lines[j].split(' ')\n for(l = 0 ;l < e; l++){\n \n \n if(a.has(k[l])){\n var temp = a.get(k[l])\n temp++\n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n \n }\n }\n var biggestValue = 0\n var biggestKey = 'ashle'\n for(var [key,value] of a){\n if(biggestValue < value){\n biggestKey = key\n biggestValue = value\n }\n }\n if(biggestValue > 3){\n console.log(-1)\n }else{\n console.log(biggestKey)\n }\n } else {\n e = lines[j]\n }\n \n\n}\n\n}); "}, {"source_code": "T = readline()\r\nwhile(T--){\r\n n = readline()\r\n x = readline().split(' ').map(x => +x)\r\n res = -1\r\n sums = [];\r\n\r\n for(i=0; i el === x[i])\r\n sums.push(sumEl.length)\r\n }\r\n print(sums)\r\n for(i=0; i=3){\r\n res = x[i]\r\n break\r\n }\r\n }\r\n\r\n print(res)\r\n}\r\n\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n n = readline()\r\n x = readline().split(' ').map(x => +x)\r\n res = -1\r\n sums = [];\r\n for(i=0; i el===x[i])).length)\r\n }\r\n\r\n for(i=0; i=3)\r\n res = x[i]\r\n break\r\n }\r\n\r\n print(res)\r\n}"}], "src_uid": "7d4174e3ae76de7b1389f618eb89d334"} {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n let found = false;\n\n for (let j = 1; j < array.length; j++) {\n if (Math.max(array[j - 1], array[j]) - Math.min(array[j - 1], array[j]) >= 2) {\n console.log('YES');\n console.log(j, j + 1);\n found = true;\n break;\n }\n }\n if (!found) {\n console.log('NO');\n }\n }\n});", "positive_code": [{"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var length = +readline();\n var arr = readline().split(' ').map(Number);\n\n var found = false;\n for (var j = 0; j < length - 1; j++) {\n if (Math.abs(arr[j] - arr[j + 1]) > 1) {\n found = true;\n print(\"YES\");\n print(String(j + 1) + ' ' + String(j + 2));\n break;\n }\n }\n\n if (!found) {\n print(\"NO\");\n }\n }\n}\n\nmain();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction parseIntArrLine() {\n return readLine().split(' ').map(cTemp => parseInt(cTemp, 10));\n}\n\nfunction parseIntLine() {\n return parseInt(readLine(), 10);\n}\n\nfunction isInterestingArr(arr) {\n for (let i = 0; i < (arr.length - 1); i++) {\n if (Math.abs(arr[i + 1] - arr[i]) > 1) {\n return [i + 1, i + 2];\n }\n }\n return null;\n}\n\nfunction main() {\n const numberOfTestCases = parseIntLine();\n const results = [];\n let arrLength, arr, found;\n for (let i = 1; i <= numberOfTestCases; i++) {\n arrLength = parseIntLine();\n arr = parseIntArrLine();\n found = isInterestingArr(arr);\n if (found !== null) {\n results.push(\"YES\");\n results.push(found[0] + \" \" + found[1]);\n } else {\n results.push(\"NO\");\n }\n }\n results.forEach(item => {\n process.stdout.write(item + \"\\n\");\n });\n process.stdout.end();\n}"}], "negative_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n let found = false;\n\n for (let j = 0; j < array.length && !found; j++) {\n let [min, max] = [array[j], array[j]];\n // console.log('[min, max]', min, max);\n for (let k = j + 1; k < array.length && !found; k++) {\n min = Math.min(min, array[k]);\n max = Math.max(max, array[k]);\n // console.log(array, min, max, j, k, max - min, k - j);\n if (max - min > k - j) {\n found = true;\n console.log('YES');\n console.log(j + 1, k + 1);\n } else if (array[j + 1] < array[j]) {\n j += 1;\n }\n }\n }\n if (!found) {\n console.log('NO');\n }\n }\n});"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n const sum = array.reduce((acc, v) => acc + v, 0);\n const xorSum = array.reduce((acc, v) => acc ^ v, 0);\n // console.log(array, 'sum, xorSum', sum, xorSum);\n if (sum === 2 * xorSum) {\n console.log(0);\n console.log();\n } else {\n let first = xorSum;\n let second = (sum + first);\n console.log(2);\n console.log(first, second);\n // assert(BigInt(sum) + BigInt(first) + BigInt(second) === BigInt(n) * (BigInt(xorSum) ^ BigInt(first) ^ BigInt(second)), 'Wrong answer 1');\n }\n }\n});\n\nfunction assert(condition, message) {\n if (!condition) {\n throw new Error(message);\n }\n}"}], "src_uid": "fa16d33fb9447eea06fcded0026c6e31"} {"source_code": "function main() {\n var R = nextInt();\n var C = nextInt();\n var k = nextInt();\n\n var i;\n var b = [];\n\n for (i = 0; i < R; i++) {\n b.push([]);\n }\n\n var res = 0;\n\n for (i = 0; i < k; i++) {\n var r = nextInt() - 1;\n var c = nextInt() - 1;\n b[r][c] = 1;\n var found = false;\n for (var dr = -1; dr <= 1; dr += 2) {\n for (var dc = -1; dc <= 1; dc += 2) {\n var r1 = r + dr;\n var c1 = c + dc;\n if (r1 >= 0 && r1 < R && c1 >= 0 && c1 < C && b[r1][c1] === 1 && b[r][c1] === 1 && b[r1][c] === 1) {\n found = true;\n }\n }\n }\n if (found) {\n res = i + 1;\n break;\n }\n }\n\n print(res);\n}\n\n// auxiliary code\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(' ');\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nmain();\n", "positive_code": [{"source_code": "try {require('codef');} catch (e) {};\nfunction readLineAsArray(separator) {\n return readline().split(typeof separator == \"undefined\" ? ' ' : separator)\n}\nfunction readLineAsIntegerArray(separator) {\n return readLineAsArray(separator).map(function (v) {\n return +v\n });\n}\n\nvar irsm = readLineAsIntegerArray();\nvar n = irsm[0], m = irsm[1], k = irsm[2];\nvar arr = [];\nvar end = false;\nfor(var i = 0; i < n + 2 ; i++) {\n var t = [];\n arr.push(t);\n for(var j = 0; j < m + 2; j++) {\n t.push(0);\n }\n}\n\n\nfunction check(i, j){\n if (arr[i - 1][j] == 1 && arr[i][j] == 1 && arr[i][j-1] == 1 && arr[i-1][j-1] == 1) {\n end = true;\n return true\n }\n return false;\n}\n\nfor(var i = 0; i < k ; i++) {\n if (!end) {\n var cc = readLineAsIntegerArray();\n var t1 = cc[0], t2 = cc[1];\n arr[t1][t2] = 1;\n if (check(t1, t2) || check(t1+1, t2+1) || check(t1, t2+1) || check(t1+1, t2)) {\n write(i+1);\n }\n }\n}\n\nif (!end) write(0);\n"}, {"source_code": "(function solve() {\n\nvar arr = readline().split(\" \");\n\nvar n = parseInt(arr[0])+2;\nvar m = parseInt(arr[1])+2;\nvar k = parseInt(arr[2]);\n\nvar grid = [];\nfor(var i = 0; i < n; i++) {\n var arr = [];\n for(var j = 0; j < m; j++)\n arr.push(false);\n grid.push(arr);\n}\n\n\nvar check = [\n [-1,-1],\n [-1,0],\n [0,-1],\n [0,0]\n];\n\nfor(var i = 0; i < k; i++) {\n var arr = readline().split(\" \");\n var ii = parseInt(arr[0]);\n var jj = parseInt(arr[1]);\n\n grid[ii][jj] = true;\n\n for(var j = 0; j < check.length; j++) {\n var flag = true;\n for(var x=0;x<2;x++)\n for(var y=0;y<2;y++)\n flag &= grid[ii+check[j][0]+x][jj+check[j][1]+y];\n if(flag) {\n return print(i+1);\n }\n }\n}\n\nprint(0);\n\n})();\n"}, {"source_code": "\nvar debug = false;\n\nfunction main(lineArr) {\n var lineNum = 0;\n function readln() {\n return debug? lineArr[lineNum++] : readline();\n }\n function readints() {\n return readln().split(' ').map(function(x) {\n return parseInt(x)\n })\n }\n function println(data) {\n debug? console.log(data) : print(data);\n }\n\n //***************************************\n function check(i, j) {\n return arr[i] && arr[i + 1] &&\n arr[i][j] && arr[i + 1][j] &&\n arr[i][j + 1] && arr[i + 1][j + 1];\n }\n\n var line = readints();\n var n = line[0], m = line[1], k = line[2];\n var arr = new Array(n);\n var mez = [[0, 0], [-1, -1], [-1, 0], [0, -1]]\n for (var i = 0; i < n; i++)\n arr[i] = new Array(m);\n outer:\n for (var i = 0; i < k; i++)\n {\n line = readints();\n var x = line[0] - 1, y = line[1] - 1;\n arr[x][y] = true;\n for (var j = 0; j < mez.length; j++)\n if (check(x + mez[j][0], y + mez[j][1])) {\n break outer;\n }\n }\n println(i == k? 0 : i + 1)\n}\n\nif (debug) {\n fs = require('fs');\n var fn = '/Users/zisakadze/Projects/codeforces/js/input.txt'\n fs.readFile(fn, 'utf8', function (err, data) {\n if (err) {\n return console.log(err);\n }\n main(data.split(\"\\n\"));\n });\n} else {\n main();\n}\n"}, {"source_code": "(function(){var check,main;main=function(){var done,grid,i,k,m,n,x,y,_i,_ref,_ref1;_ref=readline().split(\" \").map(function(_){return Number(_)}),n=_ref[0],m=_ref[1],k=_ref[2];grid=function(){var _i,_results;_results=[];for(_i=0;0<=n?_in;0<=n?_i++:_i--){_results.push(function(){var _j,_results1;_results1=[];for(_j=0;0<=m?_jm;0<=m?_j++:_j--){_results1.push(false)}return _results1}())}return _results}();done=false;for(i=_i=0;0<=k?_ik;i=0<=k?++_i:--_i){_ref1=readline().split(\" \").map(function(n){return Number(n)-1}),x=_ref1[0],y=_ref1[1];grid[x][y]=true;if(check(grid,x,y)){print(i+1);done=true;break}}if(!done){return print(0)}};check=function(grid,x,y){var coord,full,genCoords,xc,yc,_i,_j,_k,_len,_len1,_len2,_ref,_ref1;_ref=[x-1,x];for(_i=0,_len=_ref.length;_i<_len;_i++){xc=_ref[_i];if(grid.length-1>xc&&xc>=0){_ref1=[y-1,y];for(_j=0,_len1=_ref1.length;_j<_len1;_j++){yc=_ref1[_j];if(!(grid[0].length-1>yc&&yc>=0)){continue}genCoords=[[xc,yc],[xc,yc+1],[xc+1,yc],[xc+1,yc+1]];full=true;for(_k=0,_len2=genCoords.length;_k<_len2;_k++){coord=genCoords[_k];full&&(full=grid[coord[0]][coord[1]])}if(full){return true}}}}return false};main()}).call(this);"}], "negative_code": [{"source_code": "(function solve() {\n\nvar arr = readline().split(\" \");\n\nvar n = parseInt(arr[0])+2;\nvar m = parseInt(arr[1])+2;\nvar k = parseInt(arr[2]);\n\nvar grid = [];\nfor(var i = 0; i < n; i++) {\n var arr = [];\n for(var j = 0; j < m; j++)\n arr.push(false);\n grid.push(arr);\n}\n\n\nvar check = [\n [-1,-1],\n [-1,0],\n [0,-1],\n [0,0]\n];\n\nfor(var i = 0; i < k; i++) {\n var arr = readline().split(\" \");\n var ii = parseInt(arr[0])+1;\n var jj = parseInt(arr[1])+1;\n\n grid[ii][jj] = true;\n\n for(var j = 0; j < check.length; j++) {\n var flag = true;\n for(var x=0;x<2;x++)\n for(var y=0;y<2;y++)\n flag |= grid[ii+check[j][0]+x][jj+check[j][1]+y];\n if(flag) {\n return print(i+1);\n }\n }\n}\n\nprint(0);\n\n})();\n"}], "src_uid": "0dc5469831c1d5d34aa3b7b172e3237b"} {"source_code": "\nvar tc = parseInt(readline());\nfor (; tc--;){\n\n var number = parseInt(readline());\nvar multiply = 4*number;\nvar result = [];\nfor(var i = 1; i<=number;i++){\n\tvar res = (multiply -=2);\n\tresult.push(res);\n}\nprint((result.join(' ')))\n\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar add = [];\n\t\tfor(var j = N * 4; j >= 1; j--){\n\t\t\tif(add.length == N){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tvar isOK = true;\n\t\t\tfor(var k = 0; k < add.length; k++){\n\t\t\t\tif(gcd(add[k], j) == 1 || add[k] % j == 0 || j % add[k] == 0){\n\t\t\t\t\tisOK = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(isOK){\n\t\t\t\tadd.push(j);\n\t\t\t}\n\t\t}\n\t\toutput[i] = myconv(add, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n let start = n * 2;\n const ans = [];\n for (let i = 1; i <= n; i++) {\n ans.push(start);\n start += 2;\n }\n console.log(ans.join(\" \"));\n }\n}\n"}, {"source_code": "var tc = parseInt(readline());\n\nwhile(tc--){\n var num = parseInt(readline());\n var result = num*4 - 2;\n for(var i = 0; i < num; i++){\n print(result + ' ');\n result -= 2;\n }\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n};\n\nfunction println(x) {\n console.log(x);\n};\n\nfunction print(x) {\n process.stdout.write(x);\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let tc = parseInt(readline());\n while (tc > 0) {\n const n = parseInt(readline());\n for (let i = 4 * n; i > 2 * n; i -= 2) {\n print (i + \" \");\n }\n println(\"\");\n tc -= 1;\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let s = 2 * n\n// \n// for (let i = 0; i < n; ++i) {\n// io.put(s + \" \")\n// s += 2\n// }\n// \n// io.put(\"\\n\")\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n input.trim().split('\\n').slice(1).map((x) => parseInt(x)).forEach((n) => {\n const ans = []\n for (let i = 0; i < n; i++) {\n ans.push(4 * n - 2 * i)\n }\n console.log(ans.join(' '))\n })\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = n;\n let res = [4*n];\n let num = 4*n;\n n -= 1;\n let i = 3;\n let f = 2;\n while(n > 0){\n num -= 2;\n let flag = false;\n for(let j = res.length-1; j >= 0; j--){\n if(res[j] % num === 0){\n flag = true;\n break;\n }\n }\n if(!flag){\n res.push(num);\n n--;\n }\n }\n\n console.log(res.join(' '));\n }\n}"}], "negative_code": [{"source_code": "\nvar number = parseInt(readline());\nvar multiply = 4*number;\nvar result = [];\nfor(var i = 1; i<=number;i++){\n\tvar res = (multiply -=2);\n\tresult.push(res);\n}\nvar convertIntoNumber = result;\nprint((convertIntoNumber.join(' ')))"}, {"source_code": "var number = parseInt(readline());\nvar multiply = 4*number;\nvar result = [];\nfor(var i = 1; i<=number;i++){\n\tvar res = (multiply -=2);\n\tresult.push(res);\n}\nprint((result.join(' ')))"}, {"source_code": "var tc = parseInt(readline());\nvar check = [];\nvar prime = [];\nfunction primeGenerator(){\n for(var i = 4; i<=10000000; i+=2)check[i]=0;\n\n for(var i = 3; i*i <= 10000000; i++){\n if(check[i]!=0){\n for(var j = 2*i; j<=10000000; j+=i){\n check[j]=0;\n }\n }\n }\n for(var i = 2; i<= 10000000; i++){\n if(check[i]!=0)prime.push(i);\n }\n}\nprimeGenerator();\n\nwhile(tc--){\n var num = parseInt(readline());\n for(var i = 0; i= 1; j--){\n\t\t\tif(add.length == N){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tvar isOK = true;\n\t\t\tfor(var k = 0; k < add.length; k++){\n\t\t\t\tif(gcd(add[k], j) == 1 || add[k] % j == 0 || j % add[k] == 0){\n\t\t\t\t\tisOK = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(isOK){\n\t\t\t\tadd.push(j);\n\t\t\t}\n\t\t}\n\t\toutput[i] = myconv(add, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction println(x) {\n console.log(x);\n}\n\nfunction print(x) {\n process.stdout.write(x);\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let tc = parseInt(readline());\n while (tc > 0) {\n const n = parseInt(readline());\n for (let i = 4 * n; i > 3 * n; i -= 1) {\n print (i + \" \");\n }\n println(\"\");\n tc -= 1;\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let res = [4];\n n -= 1;\n let i = 3;\n while(n > 0){\n res.push(i*2);\n i += 2;\n n--;\n }\n console.log(res.join(' '));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let res = [4];\n n -= 1;\n let i = 3;\n while(n > 0){\n let num = i*2;\n let flag = false;\n for(let j = 0; j < res.length; j++){\n if(num % res[j] === 0){\n i++;\n flag = true;\n break;\n }\n }\n if(!flag){\n res.push(num);\n n--;\n }\n }\n console.log(res.join(' '));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = n;\n let res = [4];\n n -= 1;\n let i = 3;\n let f = 2;\n while(n > 0){\n let num = i*f;\n if(num > 4*x){\n f++;\n i = 2;\n }else{\n let flag = false;\n for(let j = 0; j < res.length; j++){\n if(num % res[j] === 0){\n i++;\n flag = true;\n break;\n }\n }\n if(!flag){\n res.push(num);\n i++;\n n--;\n }\n }\n }\n console.log(res.join(' '));\n }\n}"}], "src_uid": "cf4d8a5caa37def0b7c0007743139e36"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n arr.sort((a,b)=>a-b);\r\n let sum;\r\n let min = Infinity;\r\n for(let i=0;istream input\r\n// process.stdin.on(event,callback function to process the data collected)\r\n// event is the form in which data will be read\r\n// data event type of stream takes data in a container form\r\n// readable event type of stream takes data in form of chunks\r\n// end event can be called after taking the input\r\n\r\nprocess.stdin.on('data', data => { \r\n buffer = data.toString().trim();\r\n let line = buffer.split('\\n');\r\n let tc = parseInt(line[0]);\r\n //console.log(tc);\r\n for(let t = 1; t<=tc; t++){\r\n let n = parseInt(line[2*t-1]);\r\n let a = line[2*t].split(' ');\r\n let b = [];\r\n for(let i = 0; i c-d);\r\n for(let i = 1; istream input\r\n// process.stdin.on(event,callback function to process the data collected)\r\n// event is the form in which data will be read\r\n// \r\nprocess.stdin.on('data', data => { \r\n buffer = data.toString().trim();\r\n});\r\n\r\nprocess.stdin.on('end',() => {\r\n let line = buffer.split('\\n');\r\n let tc = parseInt(line[0]);\r\n //console.log(tc);\r\n for(let t = 1; t<=tc; t++){\r\n let n = parseInt(line[2*t-1]);\r\n let a = line[2*t].split(' ');\r\n let b = [];\r\n for(let i = 0; i c-d);\r\n for(let i = 1; istream input\r\n// process.stdin.on(event,callback function to process the data collected)\r\n// event is the form in which data will be read\r\n// \r\nprocess.stdin.on('readable', () => { \r\n let chunk = process.stdin.read();\r\n if(chunk){buff += chunk;}\r\n});\r\n\r\nprocess.stdin.on('end',() => {\r\n let line = buff.split('\\n');\r\n let tc = parseInt(line[0]);\r\n //console.log(tc);\r\n for(let t = 1; t<=tc; t++){\r\n let n = parseInt(line[2*t-1]);\r\n let a = line[2*t].split(' ');\r\n let b = [];\r\n for(let i = 0; i c-d);\r\n //console.log(b);\r\n for(let i = 1; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let numSticks = Number(readline());\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n chooseSticks(arr)\r\n }\r\n \r\n \r\n}\r\nfunction chooseSticks(sticks) {\r\n let count = Infinity;\r\n\r\n sticks.sort((a, b) => a - b);\r\n\r\n for (let i = 2; i < sticks.length; i++) {\r\n count = Math.min(count, (sticks[i] - sticks[i-1]) + (sticks[i-1] - sticks[i-2]))\r\n }\r\n\r\n console.log(count)\r\n}"}, {"source_code": "\"use strict\";\n\nconst { Console } = require(\"console\");\nconst fs = require(\"fs\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction equilateral(cases) {\n for (let i = 0; i < cases.length; i++) {\n let minSum =\n Number(cases[i][1]) -\n Number(cases[i][0]) +\n (Number(cases[i][2]) - Number(cases[i][1]));\n for (let j = 0; j < cases[i].length && j + 2 < cases[i].length; j++) {\n const currSum =\n Number(cases[i][j + 1]) -\n Number(cases[i][j]) +\n (Number(cases[i][j + 2]) - Number(cases[i][j + 1]));\n minSum = Math.min(minSum, currSum);\n }\n console.log(minSum);\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t * 2; i++) {\n const sticks = readLine().split(\" \");\n if (i % 2 === 1) cases.push(sticks.sort((a, b) => a - b));\n }\n\n equilateral(cases);\n}\n\n \t\t\t\t \t\t \t \t\t \t \t \t \t\t\t \t"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var b = a.sort(function(a, b){return a - b});\n var ans = 1e9;\n for(j = 0; j < n - 2; j++){\n ans = Math.min(ans, a[j + 2] - a[j]);\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line.split(\" \"));\r\n\r\n if (input.length === +input[0][0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i += 2) {\r\n let sticks = input[i + 1];\r\n sticks.sort((a, b) => a - b);\r\n let min = sticks[2] - sticks[0];\r\n\r\n for (let i = 1; i < sticks.length - 2; i++) {\r\n min = Math.min(min, sticks[i + 2] - sticks[i]);\r\n }\r\n console.log(min);\r\n }\r\n};\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let minimum = Infinity;\r\n\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n for (let k = 0; k < n; k++) {\r\n if (i !== j && j !== k && i !== k) {\r\n let min = Math.min(arr[i], arr[j], arr[k]);\r\n let max = Math.max(arr[i], arr[j], arr[k]);\r\n let actions = max - min;\r\n if (actions < minimum) {\r\n minimum = actions;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n output(minimum);\r\n }\r\n}\r\n"}, {"source_code": "var t = +readline();\n\nwhile (t--) {\n readline();\n solve(readline());\n}\n\nfunction solve(s) {\n var p = s\n .split(\" \")\n .map((i) => +i)\n .sort((a, b) => a - b);\n\n var sm = [];\n for (var i = 0; i < p.length - 2; i++) {\n sm.push(Math.abs(p[i]-p[i+1])+Math.abs(p[i+1]-p[i+2]));\n }\n\n var mn = Number.MAX_SAFE_INTEGER;\n\n for (var i = 0; i < sm.length; i++) {\n var curr = Math.round(sm[i]);\n if (curr < mn) mn = curr;\n }\n\n print(mn);\n// console.log(mn);\n}\n"}], "negative_code": [{"source_code": "let buffer = '';\r\n\r\n// process.stdin ->stream input\r\n// process.stdin.on(event,callback function to process the data collected)\r\n// event is the form in which data will be read\r\n// \r\nprocess.stdin.on('data', data => { \r\n buffer = data.toString().trim();\r\n});\r\n\r\nprocess.stdin.on('close',() => {\r\n let line = buffer.split('\\n');\r\n let tc = parseInt(line[0]);\r\n //console.log(tc);\r\n for(let t = 1; t<=tc; t++){\r\n let n = parseInt(line[2*t-1]);\r\n let a = line[2*t].split(' ');\r\n let b = [];\r\n for(let i = 0; i c-d);\r\n for(let i = 1; istream input\r\n// process.stdin.on(event,callback function to process the data collected)\r\n// event is the form in which data will be read\r\n// \r\nprocess.stdin.on('data', data => { \r\n buffer = data.toString().trim();\r\n});\r\n\r\nprocess.stdin.on('end',() => {\r\n let line = buffer.split('\\n');\r\n let tc = parseInt(line[0]);\r\n //console.log(tc);\r\n for(let t = 1; t<=tc; t++){\r\n let n = parseInt(line[2*t-1]);\r\n let a = line[2*t].split(' ');\r\n let b = [];\r\n for(let i = 0; i c-d);\r\n for(let i = 1; i{\r\n let BUFSIZE=1024;\r\n let buf=new Buffer(BUFSIZE);\r\n let bytesRead;\r\n while(true) {\r\n bytesRead = 0;\r\n bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);\r\n if (bytesRead === 0) break;\r\n let bufstr=buf.toString('utf-8',0,bytesRead);\r\n // console.log('Bytes read: %s; content:\\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));\r\n return bufstr;\r\n }\r\n};\r\n\r\nconst main=()=>{\r\n let inp=plsread().replace(/\\r/g,' ').replace(/\\n/g,'').split(' ');\r\n // console.log(inp.length);\r\n // console.log(inp);\r\n let ti=0,t=inp[ti++];\r\n while(t--) {\r\n let n=inp[ti++];\r\n let a=[];\r\n for(let i=0;i{\r\n let BUFSIZE=1024;\r\n let buf=new Buffer(BUFSIZE);\r\n let bytesRead;\r\n while(true) {\r\n bytesRead = 0;\r\n bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);\r\n if (bytesRead === 0) break;\r\n let bufstr=buf.toString('utf-8',0,bytesRead);\r\n // console.log('Bytes read: %s; content:\\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));\r\n return bufstr;\r\n }\r\n};\r\n\r\nconst main=()=>{\r\n let inp=plsread().replace(/\\r/g,' ').replace(/\\n/g,'').split(' ');\r\n console.log(inp.length);\r\n // console.log(inp);\r\n let ti=0,t=inp[ti++];\r\n while(t--) {\r\n let n=inp[ti++];\r\n let a=[];\r\n for(let i=0;i{\r\n let BUFSIZE=256;\r\n let buf=new Buffer(BUFSIZE);\r\n let bytesRead;\r\n while(true) {\r\n bytesRead = 0;\r\n bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);\r\n if (bytesRead === 0) break;\r\n let bufstr=buf.toString('utf-8',0,bytesRead);\r\n // console.log('Bytes read: %s; content:\\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));\r\n return bufstr;\r\n }\r\n};\r\n\r\nconst main=()=>{\r\n let inp=plsread().replace(/\\r/g,' ').replace(/\\n/g,'').split(' ');\r\n // console.log(inp);\r\n let ti=0,t=inp[ti++];\r\n while(t--) {\r\n let n=inp[ti++];\r\n let a=[];\r\n for(let i=0;i{\r\n let BUFSIZE=256;\r\n let buf=new Buffer(BUFSIZE);\r\n let bytesRead;\r\n while(true) {\r\n bytesRead = 0;\r\n bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);\r\n if (bytesRead === 0) break;\r\n let bufstr=buf.toString('utf-8',0,bytesRead);\r\n // console.log('Bytes read: %s; content:\\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));\r\n return bufstr;\r\n }\r\n};\r\n\r\nconst main=()=>{\r\n let inp=plsread().replace(/\\r/g,' ').replace(/\\n/g,'').split(' ');\r\n let ti=0,t=inp[ti++];\r\n while(t--) {\r\n let n=inp[ti++];\r\n let a=[];\r\n for(let i=0;i +i)\n .sort((a, b) => a - b);\n\n var sm = [];\n for (var i = 0; i < p.length - 2; i++) {\n sm.push((p[i] + p[i + 1] + p[i + 2]) / 3);\n }\n\n var mn = Number.MAX_SAFE_INTEGER;\n\n for (var i = 0; i < sm.length; i++) {\n var curr = Math.round(sm[i]);\n if (curr < mn) mn = curr;\n }\n\n print(mn);\n}\n"}, {"source_code": "var t = +readline();\n\nwhile (t--) {\n readline();\n solve(readline());\n}\n\nfunction solve(s) {\n var p = s\n .split(\" \")\n .map((i) => +i)\n .sort((a, b) => a - b);\n\n var sm = [];\n for (var i = 0; i < p.length - 2; i++) {\n sm.push((p[i] + p[i + 1] + p[i + 2]) / 3);\n }\n\n var mn = Number.MAX_SAFE_INTEGER;\n\n for (var i = 0; i < sm.length; i++) {\n var curr = Math.floor(sm[i]);\n if (curr < mn) mn = curr;\n }\n\n print(mn);\n}\n"}], "src_uid": "53ff11122a277d1eb29fe2034017fd75"} {"source_code": "var n = readline().split(' ')[0];\nvar s = readline().split(' ')[0];\nvar a = \"\";\nvar b = \"\";\nfor (var i = 0; i < n; i++) {\n\tif (i%2 == 0)\n \ta += s[i];\n else \n \tb = s[i]+b;\n}\na = b+a;\nif (s.length % 2 == 0)\n a = a.split(\"\").reverse().join(\"\");\nprint(a)", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n var str = readLine().split(\"\");\n\n var newStr = [];\n\n if (n % 2 == 1) {\n for (var i = 1; i <= n; i++) {\n if (i % 2 == 1) {\n newStr.push(str[i - 1]);\n }\n if (i % 2 === 0) {\n newStr.unshift(str[i - 1]);\n }\n }\n }\n if (n % 2 === 0) {\n for (var j = 1; j <= n; j++) {\n if (j % 2 === 0) {\n newStr.push(str[j - 1]);\n }\n if (j % 2 == 1) {\n newStr.unshift(str[j - 1]);\n }\n }\n }\n\n console.log(newStr.join(\"\"));\n}\n"}, {"source_code": "var l = readline();\nl = parseInt(l);\n\nvar w = readline();\nvar a = w.split('');\n\nvar r = '';\nvar p = 'd';\nif (l % 2) {\n p = 's';\n}\na.forEach(l => {\n if (p == 's') {\n r = r + l;\n p = 'd';\n } else {\n r = l + r;\n p = 's';\n }\n});\n\nprint(r);\n"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\nvar result = [];\nvar c = 0;\nvar stringResult = \"\";\n\nvar median = Math.ceil(n / 2) - 1;\nresult[median] = s[0];\n\nif(n % 2 == 1)\n{\n for(var i = 1; i < median + 1; i++)\n {\n result[median - i] = s[i + c];\n result[median + i] = s[i + 1 + c];\n c++;\n }\n}\nelse\n{\n for(var i = 1; i < median + 1; i++)\n {\n result[median + i] = s[i + c];\n result[median - i] = s[i + 1 + c];\n c++;\n }\n result[n - 1] = s[n - 1];\n}\n\nfor(var i = 0; i < n; i++)\n stringResult += result[i];\n\nprint(stringResult);"}, {"source_code": "var n=parseInt(readline());\nvar inp=readline(),op=\"\";\nvar i=n-2;\nif(inp.length%2===0){\nwhile(i>=0){\nop+=inp[i];\ni-=2;\n}i=1;while(i0){\nop+=inp[i];\ni-=2;\n}i=0;while(i=0; i--){\n if(first === false && last === true){\n arrayForWord[right] = encodedWord[i]; \n right--;\n first = true;\n last = false;\n\n }else if( first === true && last === false){\n arrayForWord[left] = encodedWord[i]; \n left++;\n\n first = false;\n last = true;\n }\n \n }\n\n print( arrayForWord.join('') );\n\n}\nvar length = readline();\nvar input = readline();\ndecodeWord(input, length)"}, {"source_code": "var len = parseInt(readline());\nvar str = readline();\n\nvar res = '';\n\nfor (var i = 0; i < len; i++) {\n if (len%2 === 0) {\n i%2 !== 0 ? res += str[i] : res = str[i] + res;\n } else {\n i%2 === 0 ? res += str[i] : res = str[i] + res;\n }\n}\n\nprint(res);\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = [...str];\n let ans = arr[0];\n arr.shift();\n\n while (arr.length) {\n if (arr.length % 2 === 0) {\n ans = arr[0] + ans;\n }\n else {\n ans = ans + arr[0];\n }\n\n arr.shift();\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nfunction removeLetter(str, pos) {\n return str.substring(0, pos-1)+str.substring(pos);\n}\n\nRL.on('close', () => {\n const n = parseInt(input[0], 10);\n let str = input[1];\n\n let answer = ''; let mode = (str.length % 2 === 0) ? 1 : 0; \n for(let i = 0; i < n; i += 1) {\n if(mode && i !== 0){\n answer = str.charAt(i) + answer;\n mode = !mode;\n } else if (!mode && i !== 0) {\n answer += str.charAt(i);\n mode = !mode;\n } else if(i === 0) {\n answer = str.charAt(0);\n } \n }\n global.console.log(answer.split(\"\").reverse().join(\"\"));\n});\n\n"}], "negative_code": [{"source_code": "var s = readline().split(' ')[0];\nvar a = \"\";\nvar b = \"\";\nfor (var i = 0; i < s.length; i++) {\n\tif (i%2 == 0)\n \ta += s[i];\n else \n \tb = s[i]+b;\n}\nprint(b+a)"}, {"source_code": "var n = readline().split(' ')[0];\nvar s = readline().split(' ')[0];\nvar a = \"\";\nvar b = \"\";\nfor (var i = 0; i < n; i++) {\n\tif (i%2 == 0)\n \ta += s[i];\n else \n \tb = s[i]+b;\n}\nprint(b+a)"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\nvar result = [\"a\", \"a\", \"a\", \"a\", \"a\"];\nvar c = 0;\nvar stringResult = \"\";\n\nvar median = Math.ceil(n / 2) - 1;\nresult[median] = s[0];\n\nif(n % 2 == 1)\n{\n for(var i = 0; i < median + 1; i++)\n {\n result[median - i] = s[i + c];\n result[median + i] = s[i + 1 + c];\n c++;\n }\n}\nelse\n{\n for(var i = 0; i < median + 1; i++)\n {\n result[median + i] = s[i + c];\n result[median - i] = s[i + 1 + c];\n c++;\n }\n result[n - 1] = s[n - 1];\n}\n\nfor(var i = 0; i < n; i++)\n stringResult += result[i];\n\nprint(stringResult);"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\nvar result = [];\nvar c = 0;\nvar stringResult = \"\";\n\nvar median = Math.ceil(n / 2) - 1;\nresult[median] = s[0];\n\nif(n % 2 == 1)\n{\n for(var i = 0; i < median + 1; i++)\n {\n result[median - i] = s[i + c];\n result[median + i] = s[i + 1 + c];\n c += 1;\n }\n}\nelse\n{\n for(var i = 0; i < median + 1; i++)\n {\n result[median + i] = s[i + c];\n result[median - i] = s[i + 1 + c];\n c += 1;\n }\n result[n - 1] = s[n - 1];\n}\n\nfor(var i = 0; i < n; i++)\n stringResult += result[i];\n\nprint(stringResult);"}], "src_uid": "2a414730d1bc7eef50bdb631ea966366"} {"source_code": "var inputnumber = readline();\nvar least = 0;\nfor(var i = 0; i < inputnumber ; i++){\n var arr = readline().split(\" \");\n var num = arr[0]\n var n = arr [1];\n least = (2+(n-1)*2)*n/2;\n if(least > num || n%2 != num%2){\n print(\"NO\");\n }else{\n print(\"YES\");\n };\n};", "positive_code": [{"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-k\n if (r >= 0 && r%2 == 0 && n >= k*k) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString\n .trim()\n .split(/\\W+/) // splits at spaces or new lines\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const n = readline(); // number of test cases\n\n for (let i = 0; i < n; i++) {\n const n = readline(); // test input 1\n const k = readline(); // test input 2\n const result = solution(n, k);\n console.log(result);\n }\n}\n\nfunction solution(n, k) {\n if (k * k <= n && n % 2 === k % 2) return 'YES';\n else return 'NO';\n}\n\n// console.log(solution(16, 4));\n"}, {"source_code": "// Q: https://codeforces.com/contest/1327/problem/A\n\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n const test = parseInt(input[0]);\n let n, k;\n for (let t = 0; t < test; t++) {\n [n, k] = input[t + 1].split(' ').map((a) => parseInt(a));\n console.log(solution(n, k));\n }\n});\n\nfunction solution(n, k) {\n if (Math.pow(k, 2) > n || n%2 !== k%2) {\n return 'NO';\n }\n return 'YES'\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, k] = readInts()\n if(n % 2 === k % 2) {\n if(k * k <= n) {\n wr('YES')\n }\n else wr('NO')\n }\n else wr('NO')\n }\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n if (((a & 1) == (b & 1)) && (a >= (2 + (b - 1) * 2) * b / 2)) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var len = readline()\nfor (var i = 0;i < len;i ++) {\n var item = readline().split(' ');\n if (item[0]%2 == item[1]%2 && Number(item[0]) >= Number(item[1]) * Number(item[1])) {\n print('YES')\n } else {print('NO')}\n}"}], "negative_code": [{"source_code": "var inputnumber = readline();\nvar least = 0;\nfor(var i = 0; i < inputnumber ; i++){\n var arr = readline().split(\" \");\n var num = arr[0]\n var n = arr [1];\n least = (2+(n-1)*2)*n/2;\n if(least > num || n%2 != num%2){\n print(\"FALSE\");\n }else{\n print(\"TRUE\");\n };\n};"}, {"source_code": "var len = readline()\nfor (var i = 0;i < len;i ++) {\n var item = readline().split(' ');\n if (item[0]%2 == item[1]%2 && item[0] >= item[1]) {\n print('YES')\n } else {print('NO')}\n}"}, {"source_code": "var len = readline()\nfor (var i = 0;i < len;i ++) {\n var item = readline().split(' ');\n if (item[0]%2 == item[1]%2 && Number(item[0]) >= Number(item[1])) {\n print('YES')\n } else {print('NO')}\n}"}, {"source_code": "var arr = readline().split(' ')\nfor (var i = 1;i < arr.length;i ++) {\n var item = arr[i].split(' ');\n if (item[0]%2 == item[1]%2) {\n print('YES')\n } else {print('NO')}\n}"}, {"source_code": "var len = readline()\nfor (var i = 0;i < len;i ++) {\n var item = readline().split(' ');\n if (item[0]%2 == item[1]%2) {\n print('YES')\n } else {print('NO')}\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-(k-1)\n if (r >= 0 && r%2 !== 0) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-k\n if (r >= 0 && r%2 === 0 && n > Math.pow(2, k)) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-k\n if (r >= 0 && r%2 == 0 && Math.pow(2, k) <= n) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =1; j +x)\n const r = n-(k-1)\n if (r <= 0 || r%2 === 0) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-(k-1)\n if (r <= 0 || r%2 === 0) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString\n .trim()\n .split(/\\W+/) // splits at spaces or new lines\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const n = readline(); // number of test cases\n\n for (let i = 0; i < n; i++) {\n const n = readline(); // test input 1\n const k = readline(); // test input 2\n const result = solution(n, k);\n console.log(result);\n }\n}\n\nfunction solution(a, b) {\n if (a % b === 0) return 'YES';\n else {\n return 'NO';\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = n-k\n if (r >= 0 && r%2 === 0 ) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n if (n%2 === k%2 && n >= k) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n if ((a & 1) == (b & 1) && (a >= (2 + b - 1) * b / 2)) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "a4c82fffb31bc7e42870fd84e043e815"} {"source_code": "let lineCount = 0\n\nrequire('readline').createInterface({\n input: process.stdin,\n}).on('line', (line) => {\n if (lineCount++ !== 1) {\n return\n }\n const nums = line.split(' ').map(s => parseInt(s))\n nums.sort((a, b) => a - b)\n let result = 0\n nums.forEach((num) => {\n if (num > result) {\n result++\n }\n })\n process.stdout.write(result + '\\n')\n process.exit()\n})\n", "positive_code": [{"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount + 1)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a == b ? 0 : ( a < b ? -1 : 1));\n\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "let fs = require('fs');\nlet input = fs.readFileSync(0, 'ascii')\n .split('\\n')\n .map(s => s.trim().split(\" \").map(Number))\n;\n\nlet [n, args] = input;\nlet days = 0;\nargs.sort((a,b) => a - b);\n\nargs.forEach(num => {\n if (days < num) days++;\n});\nconsole.log(days);"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next()), i = 0;\n let ar = [];\n for(i = 0; i < n; i++) {\n ar.push(parseInt(next()));\n }\n //ar.sort(); this is wrong sorts alphabetically on literals\n ar.sort((a, b) => a-b); // sort using compare function to sort integers -ve means a comes first\n let cur = 0;\n for(i = 0; i < n; i++) {\n if(ar[i] > cur)\n cur++;\n }\n println(cur);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber(' ').sort((a,b) => a-b);\n\n var res = 0;\n var day = 1;\n\n for(var i = 0 ;i < n; i++) {\n if(a[i] >= day) {\n day++;\n }\n }\n print(day - 1);\n}());"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(Number);\n\nfunction comp(a, b){\n\tif(a > b) return 1;\n\tif(a < b) return -1;\n\treturn 0;\n}\n\nvar now = 1;\nvar k = 0;\na.sort(comp);\nfor (var i = 0; i < a.length; i++) {\n\tif(a[i] >= now){\n\t\tk++;\n\t\tnow++;\n\t}\n}\nvar b = [];\nfor (var i = 0; i < 1e6; i++) {\n\tb.shift(i);\n}\nprint(k);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(Number);\n\nvar b = new Array(3213213321);\n\nfunction comp(a, b){\n\tif(a > b) return 1;\n\tif(a < b) return -1;\n\treturn 0;\n}\n\nvar now = 1;\nvar k = 0;\na.sort(comp);\nfor (var i = 0; i < a.length; i++) {\n\tif(a[i] >= now){\n\t\tk++;\n\t\tnow++;\n\t}\n}\nvar b = [];\nfor (var i = 0; i < 1e6; i++) {\n\tb.shift(i);\n}\nprint(k);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(Number);\n\nfunction comp(a, b){\n\tif(a > b) return 1;\n\tif(a < b) return -1;\n\treturn 0;\n}\n\nvar now = 1;\nvar k = 0;\na.sort(comp);\nfor (var i = 0; i < a.length; i++) {\n\tif(a[i] >= now){\n\t\tk++;\n\t\tnow++;\n\t}\n}\nvar b = [];\nfor (var i = 0; i < 1e5; i++) {\n\tb.shift(i);\n}\nprint(k);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(Number);\nfunction comp(a, b){\n\tif(a > b) return 1;\n\tif(a < b) return -1;\n\treturn 0;\n}\n\nvar now = 1;\nvar k = 0;\na.sort(comp);\nfor (var i = 0; i < a.length; i++) {\n\tif(a[i] >= now){\n\t\tk++;\n\t\tnow++;\n\t}\n}\nprint(k);"}], "negative_code": [{"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n // const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a > b);\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a <= b);\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a > b);\n\n if(nCount > 1000)\n {\n console.log(arrValues);\n }\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a <= b);\n\n let nIndex = 1;\n arrValues.forEach(nValue => {\n if(nValue >= nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a > b);\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n // const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a <= b);\n\n console.log(arrValues);\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a == b ? 0 : ( a < b ? -1 : 1));\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a == b ? 0 : ( a < b ? -1 : 1));\n\n if(nCount > 1000)\n {\n console.log(arrValues);\n }\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a > b);\n\n console.log(arrValues);\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const nCount = this.nextInput(\"Integer\");\n const arrValues = this.arrInput\n .slice(1, nCount)\n .map(strValue => parseInt(strValue, 10))\n .sort((a, b) => a == b ? 0 : ( a < b ? -1 : 1));\n\n\n let nIndex = 0;\n arrValues.forEach(nValue => {\n if(nValue > nIndex)\n {\n ++nIndex;\n }\n });\n process.stdout.write(nIndex + '\\n');\n }\n}\n\n// process.stdout.write(\"YES\\n\");\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "let fs = require('fs');\nlet input = fs.readFileSync(0, 'ascii')\n .split('\\n')\n .map(s => s.trim().split(\" \").map(Number))\n;\n\nlet [n, args] = input;\nlet days = 1;\nlet index = 1;\nlet length = args.length;\nargs.sort();\nwhile (index < length) {\n if (args[index] >= days + 1) {\n days++;\n };\n index++;\n}\n\nconsole.log(days)"}, {"source_code": "let fs = require('fs');\nlet input = fs.readFileSync(0, 'ascii')\n .split('\\n')\n .map(s => s.trim().split(\" \").map(Number))\n;\n\nlet [n, args] = input;\nlet days = 0;\nargs.sort();\n\nargs.forEach(num => {\n if (days < num) days++;\n});\nconsole.log(days);"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next()), i = 0;\n let st = new Set();\n for(i = 0; i < n; i++) {\n st.add(parseInt(next()));\n }\n println(st.size);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next()), i = 0;\n let ar = [];\n for(i = 0; i < n; i++) {\n ar.push(parseInt(next()));\n }\n console.log(ar);\n //ar.sort(); this is wrong sorts alphabetically on literals\n ar.sort((a, b) => a-b); // sort using compare function to sort integers -ve means a comes first\n console.log(ar);\n\n let cur = 0;\n for(i = 0; i < n; i++) {\n if(ar[i] > cur)\n cur++;\n }\n println(cur);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "'use strict';\n\nfunction main() {\n let n = parseInt(next()), i = 0;\n let ar = [];\n for(i = 0; i < n; i++) {\n ar.push(parseInt(next()));\n }\n ar.sort();\n let cur = 0;\n for(i = 0; i < n; i++) {\n if(ar[i] > cur)\n cur++;\n }\n println(cur);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = '';\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}], "src_uid": "4f02ac641ab112b9d6aee222e1365c09"} {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInts()\n while(t--) {\n const n = rc.readInt()\n const a1 = rc.readInts()\n const a3 = new Array(n)\n sort(a1)\n let ans = -1\n for(let i = 1; i <= 1024; i++) {\n for(let j = 0; j < n; j++) {\n a3[j] = (a1[j] ^ i)\n }\n sort(a3)\n if(check(n, a1, a3)) {\n ans = i\n break\n }\n }\n wr(ans)\n function check(n, a1, a3) {\n for(let j = 0; j < n; j++) {\n if(a1[j] !== a3[j]) return false\n }\n return true\n }\n }\n}\n", "positive_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar tmp = JSON.parse(JSON.stringify(list));\n\t\tvar set = new Set(tmp);\n\t\tfor(var j = 1; j <= 1024; j++){\n\t\t\tvar isNO = false;\n\t\t\tfor(var k = 0; k < N; k++){\n\t\t\t\tif(!set.has(list[k] ^ j)){\n\t\t\t\t\tisNO = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(isNO){\n\t\t\t\tcontinue;\n\t\t\t}else{\n\t\t\t\toutput[i] = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(output[i] == null){\n\t\t\toutput[i] = -1;\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let stdinInput = '';\n \n process.stdin.on('data', input => {\n stdinInput += input;\n })\n \n process.stdin.on('end', () => {\n main(stdinInput);\n })\n \n function main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 1; i < testCases; i += 2) {\n let obj = {};\n let arr = data[i].slice(0,-1).split(' ');\n for (let j = 0; j < arr.length; j += 1) obj[arr[j]] = 1;\n let j = 1;\n while (j < 1025) {\n let bit = true;\n for (let k = 0; k < arr.length; k += 1) {\n let xor = arr[k] ^ j;\n if (!obj[xor]) {\n bit = false;\n break;\n }\n }\n if (bit) {\n console.log(j);\n break;\n }\n j += 1;\n }\n if (j === 1025) console.log(-1);\n }\n}"}], "negative_code": [{"source_code": " process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let stdinInput = '';\n \n process.stdin.on('data', input => {\n stdinInput += input;\n })\n \n process.stdin.on('end', () => {\n main(stdinInput);\n })\n \n function main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 1; i < testCases; i += 2) {\n // let numEle = data[i].split(' ')[1] * 1;\n let obj = {};\n let arr = data[i].split(' ');\n for (let j = 0; j < arr.length; j += 1) obj[arr[j]] = 1;\n let j = 1;\n while (j < 1025) {\n let bit = true;\n for (let k = 0; k < arr.length; k += 1) {\n let xor = arr[k] ^ j;\n if (!obj[xor]) {\n bit = false;\n break;\n }\n }\n if (bit) {\n console.log(j);\n break;\n }\n j += 1;\n }\n if (j === 1025) console.log(-1);\n }\n}"}], "src_uid": "3ecb65a8be42f882ae6b528fd86243cd"} {"source_code": "\nvar z;\nvar n , k;\nvar a = [];\nvar p = [];\n\nfunction readArray()\n{\n return readline().split( ' ' ).map( Number );\n}\n\nfunction check( sz )\n{\n if ( sz == 0 ) return { ok : true , left : 0 , right : 0 , whichOnes : undefined };\n \n var f = new Array( n );\n for ( var i=0 ; i= sz )\n {\n var id = p[j].id;\n if ( p[j].type == +1 )\n {\n if ( f[id] == 0 ) f[id] = 1 , cnt++;\n }\n j++;\n }\n \n if ( cnt > ret )\n {\n ret = cnt;\n if ( ret >= k && found == false )\n {\n var c = 0;\n for ( var l=0 ; l= sz )\n {\n var id = p[j].id;\n if ( p[j].type == +1 )\n {\n if ( f[id] == 0 ) f[id] = 1 , cnt++;\n }\n j++;\n }\n \n // update the answer\n if ( cnt > ret )\n {\n ret = cnt;\n if ( ret >= k && found == false )\n {\n if ( which )\n {\n var c = 0;\n for ( var l=0 ; l= sz )\n {\n var id = p[j].id;\n if ( p[j].type == +1 )\n {\n if ( f[id] == 0 ) f[id] = 1 , cnt++;\n }\n j++;\n }\n \n if ( cnt > ret )\n {\n ret = cnt;\n if ( ret >= k && found == false )\n {\n for ( var l=0 ; l= sz )\n {\n var id = p[j].id;\n if ( p[j].type == +1 )\n {\n if ( f[id] == 0 ) f[id] = 1 , cnt++;\n }\n j++;\n }\n \n if ( cnt > ret )\n {\n ret = cnt;\n if ( ret >= k && found == false )\n {\n for ( var l=0 ; l +value);\na.unshift(0);\n\nfor (var i = 1; i <= n; ++i) {\n a[i] += a[i - 1];\n}\n\nvar s = a[n];\n\nif (s === 0) {\n var zeroCount = 0;\n\n for (i = 1; i <= n; ++i) {\n if (a[i] === 0)\n ++zeroCount;\n }\n\n writeResult(zeroCount < 3 ? 0 : (zeroCount - 1) * (zeroCount - 2) / 2);\n}\n\nif (s % 3) {\n writeResult(0);\n}\n\nvar third = s / 3;\nvar twothirds = s - third;\n\nvar b = new Array(n + 1).fill(0);\nfor (i = n - 1; i >= 1; --i) {\n b[i] = b[i + 1] + (a[i] === twothirds ? 1 : 0);\n}\n\nvar result = 0;\nfor (i = 1; i <= n; ++i) {\n if (a[i] === third) {\n result += b[i];\n }\n}\n\nwrite(result);\n", "positive_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\nvar n = +readline(), a = rda();\nvar sum = a.reduce(function(s, cur){ return s + cur; }, 0);\n\nvar ans = 0;\nif(sum % 3 == 0 && n > 2){\n var part = sum/3;\n\n var ies = [];\n for(var i = 0, s = 0; i < n-2; i++){\n s += a[i];\n if(s == part){\n ies.push(i);\n }\n }\n\n var cnt = [];\n for(var i = 0; i < n; i++) cnt[i] = 0;\n for(var i = n-1, s = 0; i >= 2; i--){\n s += a[i];\n if(s == part) cnt[i] = 1;\n }\n\n var sums = [];\n for(var i = 0; i < n; i++) sums[i] = 0;\n for(var i = n-1, s = 0; i >= 2; i--){\n s += cnt[i];\n sums[i] = s;\n }\n\n for(var i = 0; i < ies.length; i++){\n ans += sums[ies[i]+2];\n }\n}\n\nwrite(ans);"}, {"source_code": "const N = 1<<19;\n\nvar n, arr;\nvar totalSum, currSum, goalSum, cnt, ans;\nvar token = [];\n\nfunction initializeData() {\n arr = new Array(N);\n}\n\ninitializeData();\n\nn = parseInt(readline());\n\ntotalSum=0;\n\ntoken = readline().split(' ');\nfor(var i=0;i>0);\n goalSum=-goalSum;\n }\n else {\n goalSum=Math.floor(goalSum/3);//(totalSum/3>>0);\n }\n\n currSum=0;\n cnt=0;\n\n for(i=1;i= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e;\n res = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n }\n if( d % 3 != 0 ) {\n print( res );\n return;\n }\n if( d == 0 ) {\n a = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n a += this.arr[ i ];\n if( a == 0 ) {\n res++;\n }\n }\n res -= 2;\n res = Math.floor( ( res * ( res + 1 ) ) / 2 );\n print( res );\n return;\n }\n a = d / 3;\n b = a * 2;\n c = a * 3;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == a ) {\n this.brr[ i ] = 1;\n }\n }\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == b ) {\n res += e;\n }\n e += this.brr[ i ];\n }\n /*\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == c ) {\n res += e;\n }\n e += this.crr[ i ];\n }\n */\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 500010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var elements = readline();\nvar arr = readline().split(\" \").map(Number);\n\nvar sum = 0, answer = 0, count = 0, temp_sum = 0;\nfor(var i = 0; i < elements; ++i) sum = sum + arr[i];\n\nif(sum % 3 == 0) {\n sum = sum / 3;\n for(var i = 0; i < elements - 1; ++i) {\n temp_sum = temp_sum + arr[i];\n if(temp_sum == 2 * sum) answer = answer + count;\n if(temp_sum == sum) count = count + 1;\n }\n}\n\nprint(answer);\n"}, {"source_code": "function main() {\n var n = Number(readline());\n var data = readline().split(' ').map(Number);\n var total = data.reduce((prev, val) => prev+val);\n if(total%3!=0){\n return print(0);\n }\n \n var sums = [];\n for(var i=0;i=0;i--){\n sum += data[i];\n if(sum == total/3){\n sums[i] = 1;\n }\n }\n for(var i=n-2;i>=0;i--){\n sums[i] = sums[i] + sums[i+1];\n }\n sum = 0;\n var res= 0;\n for(var i=0;i +value);\n\na.unshift(0);\n\nfor (var i = 2; i <= n; ++i) {\n a[i] += a[i-1];\n}\n\nvar S = a[n];\n\nif (S === 0) {\n var cnt = 0;\n for (var i = 1; i <= n; ++i) {\n if (a[i] === 0)\n ++cnt;\n }\n \n if (cnt < 3) {\n writeResult(0);\n } else {\n writeResult((cnt-1)*(cnt-2)/2);\n }\n}\n\nif (S%3) {\n writeResult(0);\n}\n\nvar x = S/3;\nvar y = 2*x;\n\nvar cx = [];\ncx[1] = 0;\nfor (var i = 2; i <= n; ++i) {\n cx[i] = cx[i-1] + (a[i] === x ? 1 : 0);\n}\n\nvar cy = [];\ncy[n] = 0;\nfor (var i = n-1; i >= 1; --i) {\n cy[i] = cy[i+1] + (a[i] === y ? 1 : 0);\n}\n\nvar result = 0;\nfor (var i = 1; i <= n; ++i) {\n if (a[i] === x) {\n result += cy[i];\n }\n}\n\nwrite(result);\n"}, {"source_code": "n = Number(readline());\na = readline().split(' ').map(Number);\nvar sum = [];\nvar cnt = [];\nsum = 0;\ncount = 0;\n\nfor (var i = 0; i < n; i++) sum += a[i];\npart = sum / 3;\nif (sum % 3 !== 0) write(0);\nelse {\n sum = a[n-1]\n cnt[n-1] = Number(sum === part);\n for (var i = n - 2; i >= 0; i--) {\n sum += a[i];\n cnt[i] = cnt[i+1] + (sum === part);\n }\n cnt[n] = 0;\n // print(cnt);\n sum = 0\n for (var i = 0; i < n-2; i++) {\n sum += a[i];\n if (sum === part) count+= cnt[i+2];\n }\n write(count);\n}\n\n\n"}], "negative_code": [{"source_code": "const N = 1<<19;\n\nvar n, arr;\nvar totalSum, currSum, goalSum, cnt, ans;\nvar token = [];\n\nfunction initializeData() {\n arr = new Array(N);\n}\n\ninitializeData();\n\nn = parseInt(readline());\n\ntotalSum=0;\n\ntoken = readline().split(' ');\nfor(var i=0;i>0);\n goalSum=-goalSum;\n }\n else {\n goalSum=(totalSum/3>>0);\n }\n\n currSum=0;\n cnt=0;\n\n for(i=1;i= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e;\n res = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n }\n if( d % 3 != 0 ) {\n print( res );\n return;\n }\n if( d == 0 ) {\n a = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n a += this.arr[ i ];\n if( a == 0 ) {\n res++;\n }\n }\n res -= 2;\n res = Math.floor( ( res * ( res + 1 ) ) / 2 );\n print( res );\n return;\n }\n a = d / 3;\n b = a * 2;\n c = a * 3;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d % a == 0 ) {\n this.brr[ i ] = 1;\n }\n }\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d % b == 0 ) {\n this.crr[ i ] = e;\n e = 0;\n }\n e += this.brr[ i ];\n }\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d % c == 0 ) {\n res += e;\n }\n e += this.crr[ i ];\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 500010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e;\n res = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n }\n if( d % 3 != 0 ) {\n print( res );\n return;\n }\n if( d == 0 ) {\n a = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n a += this.arr[ i ];\n if( a == 0 ) {\n res++;\n }\n }\n res -= 2;\n res = Math.floor( ( res * ( res + 1 ) ) / 2 );\n print( res );\n return;\n }\n a = d / 3;\n b = a * 2;\n c = a * 3;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == a ) {\n this.brr[ i ] = 1;\n }\n }\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == b ) {\n this.crr[ i ] = e;\n }\n e += this.brr[ i ];\n }\n e = 0;\n d = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n d += this.arr[ i ];\n if( d == c ) {\n res += e;\n }\n e += this.crr[ i ];\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 500010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function main() {\n var a = readline();\n var data = readline().split(' ').map(Number);\n var n =data.length;\n var start = [data[0]];\n var finish = [data[n-1]];\n var total = start[0];\n for(var i=1;i=0;i--){\n finish[i] = finish[i+1] + data[i];\n }\n if(n<3){\n return print(0);\n }\n var i = 0;\n var sum1 = data[0];\n var j = n-1;\n var sum2 = data[n-1];\n var sum3 = total;\n var res = 0;\n while(i +value);\n\na.unshift(0);\n\nfor (var i = 2; i <= n; ++i) {\n a[i] += a[i-1];\n}\n\nvar S = a[n];\n\nif (S === 0) {\n var cnt = 0;\n for (var i = 1; i <= n; ++i) {\n if (a[i] === 0)\n ++cnt;\n }\n \n if (cnt < 3) {\n writeResult(0);\n } else {\n writeResult(cnt*(cnt-1)/2);\n }\n}\n\nif (S%3) {\n writeResult(0);\n}\n\nvar x = S/3;\nvar y = 2*x;\n\nvar cx = [];\ncx[1] = 0;\nfor (var i = 2; i <= n; ++i) {\n cx[i] = cx[i-1] + (a[i] === x ? 1 : 0);\n}\n\nvar cy = [];\ncy[n] = 0;\nfor (var i = n-1; i >= 1; --i) {\n cy[i] = cy[i+1] + (a[i] === y ? 1 : 0);\n}\n\nvar result = 0;\nfor (var i = 1; i <= n; ++i) {\n if (a[i] === x) {\n result += cy[i];\n }\n}\n\nwrite(result);\n"}, {"source_code": "function checkNeib(res, value) {\n\tvar count = 0;\n\ttmp = res;\n\twhile (tmp < sum.length) {\n\t\tif (sum[sum.length-1] - sum[tmp] == sum[value]) count++;\n\t\telse break;\n\t\ttmp++;\n\t}\n\ttmp = res - 1;\n\twhile (tmp > 0) {\n\t\tif (sum[sum.length-1] - sum[tmp] == sum[value]) count++;\n\t\telse break;\n\t\ttmp--;\n\t}\n\treturn count;\n}\n\nfunction binarySearch(left, right, value) {\n var middle = (left + right) >> 1;\n if (sum[value] == sum[middle] - sum[value]) {\n\t\treturn checkNeib(middle, value);\n\t}\n if (left >= right) return 0;\n if (sum[middle] - sum[value] > sum[value]) return binarySearch(left, middle, value);\n else if (sum[middle] - sum[value] < sum[value]) return binarySearch(middle+1, right, value);\n}\n\n\nn = Number(readline());\na = readline().split(' ').map(Number);\nvar sum = [];\nsum[0] = a[0];\nfor (var i = 1; i < n; i++) {\n sum[i] = sum[i-1] + a[i];\n}\n\nvar sum1 = 0;\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n sum1 = sum[i];\n count += binarySearch(i+1, n, i);\n // print(i, count);\n}\nwrite(count);\n"}], "src_uid": "2558db57229e55ffe0de0d8cf217035b"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n array[0] = new Array(20).fill(0)\r\n\r\n// for (let i = 1; i < 2*Math.pow(10, 5); i++) {\r\n for (let i = 1; i < 200000 + 1; i++) {\r\n array[i] = array[i - 1].slice()\r\n var value = dec2bin(i)\r\n\r\n for (let j = 0; j < 20 && j < value.length; j++) {\r\n array[i][j] += value[j] === '0' ? 1 : 0\r\n }\r\n }\r\n // console.log(array)\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const n = Number(readline());\r\n\r\n var [l, r] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n if (l === r) return console.log(0)\r\n // console.log(array[l], array[r])\r\n l = l - 1\r\n var min = Number.MAX_SAFE_INTEGER\r\n var show = new Array(20).fill(0)\r\n for (let j = 0; j < Math.ceil(Math.log2(r)) + 1; j++) {\r\n show[j] = array[r][j] - array[l][j]\r\n if (array[l][j] !== 0 || array[r][j] !== 0)\r\n min = Math.min(min, Math.abs(array[r][j] - array[l][j]))\r\n }\r\n console.log(min)\r\n // console.log(show.toString())\r\n // console.log(array[l].toString())\r\n // console.log(array[r].toString())\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // sum+=Number(x)\r\n // return Number(x)\r\n // })\r\n // console.log(sum)\r\n\r\n// console.log(a)\r\n// console.log(n)\r\n // if(i===(string.length-2)) return console.log(string)\r\n })\r\n}\r\n\r\nfunction dec2bin(dec) {\r\n var string = (dec >>> 0).toString(2);\r\n var front = ''\r\n for (let i = 0; i < 20 - string.length; i++) {\r\n front += '0'\r\n }\r\n return (front + string).split(\"\").reverse().join(\"\")\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [l, r] = rna();\r\n\t\tl++, r++;\r\n\r\n\t\tfunction countOnes (x, pos) {\r\n\t\t\tconst k = 2**pos;\r\n\t\t\treturn Math.floor(x/k)*k/2 + Math.max(0, x%k - k/2);\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let pos = 1; pos <= 20; pos++) {\r\n\t\t\tans = Math.max(ans, countOnes(r, pos) - countOnes(l-1, pos));\r\n\t\t}\r\n\r\n\t\tconsole.log(r-l+1-ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nlet maxv = 2e5;\r\nlet bit = new Array(maxv + 1);\r\nbit[0] = new Array(20).fill(0);\r\nconst blackbox = () => {\r\n for (let i = 1; i <= maxv; i++) {\r\n let val = i,\r\n k = new Array(20).fill(0),\r\n j = 0;\r\n while (val > 0) {\r\n if (val & 1) k[j] += bit[i - 1][j] + 1;\r\n else k[j] += bit[i - 1][j];\r\n j++;\r\n val = val >> 1;\r\n }\r\n bit[i] = k;\r\n }\r\n};\r\nconst solve = () => {\r\n blackbox();\r\n let t = getValue();\r\n while (t--) {\r\n let [l, r] = iInpArr();\r\n let res = [],\r\n max = Infinity,\r\n to = r - l + 1;\r\n for (let i = 0; i < 20; i++) {\r\n res[i] = bit[r][i] - bit[l - 1][i];\r\n max = Math.min(max, to - res[i]);\r\n }\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n array[0] = new Array(20).fill(0)\r\n\r\n// for (let i = 1; i < 2*Math.pow(10, 5); i++) {\r\n for (let i = 1; i < 200000 + 1; i++) {\r\n array[i] = array[i - 1].slice()\r\n var value = dec2bin(i)\r\n\r\n for (let j = 0; j < 20 && j < value.length; j++) {\r\n array[i][j] += value[j] === '0' ? 1 : 0\r\n }\r\n }\r\n // console.log(array)\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const n = Number(readline());\r\n\r\n var [l, r] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n // console.log(array[l], array[r])\r\n l = l - 1\r\n var min = Number.MAX_SAFE_INTEGER\r\n var show = new Array(20).fill(0)\r\n for (let j = 0; j < Math.ceil(Math.log2(r)) + 1; j++) {\r\n show[j] = array[r][j] - array[l][j]\r\n if (array[l][j] !== 0 || array[r][j] !== 0)\r\n min = Math.min(min, Math.abs(array[r][j] - array[l][j]))\r\n }\r\n console.log(min)\r\n // console.log(show.toString())\r\n // console.log(array[l].toString())\r\n // console.log(array[r].toString())\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // sum+=Number(x)\r\n // return Number(x)\r\n // })\r\n // console.log(sum)\r\n\r\n// console.log(a)\r\n// console.log(n)\r\n // if(i===(string.length-2)) return console.log(string)\r\n })\r\n}\r\n\r\nfunction dec2bin(dec) {\r\n var string = (dec >>> 0).toString(2);\r\n var front = ''\r\n for (let i = 0; i < 20 - string.length; i++) {\r\n front += '0'\r\n }\r\n return (front + string).split(\"\").reverse().join(\"\")\r\n}\r\n\r\n"}], "src_uid": "0601e3636b5d5b6ad0c8c1abb7f83d82"} {"source_code": "n = Number(readline());\nvar text = [];\nwhile (n--) {\n str = readline();\n text.push(str);\n}\nvar main = readline();\n\nvar original = '<3';\nfor (var i = 0; i < text.length; i++)\n original += (text[i] + '<3');\nvar j = 0;\n\nfor (var i = 0; i < main.length; i++) {\n if (main[i] == original[j]) j++;\n}\n\nwrite((j == original.length) ? 'yes' : 'no');\n", "positive_code": [{"source_code": "//var input = \"7\\ni\\nam\\nnot\\nmain\\nin\\nthe\\nfamily\\n<3i<>3am<3the<3<3family<3\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var n = readline();\n var ans = \"\";\n for(var i = 0; i < n; i++){\n ans += '<3' + readline();\n if(i == n - 1)\n ans += '<3';\n }\n var text = readline();\n var index = 0;\n for(var i = 0; i < text.length; i++){\n if(text.charAt(i) == ans.charAt(index))\n index++;\n if(index == ans.length){\n print('yes');\n return;\n }\n\n }\n print('no');\n}\nmain();"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction solve(words, text) {\n\tvar dfa = { position: 0 };\n\tdfa.message = '<3' + words.join('<3') + '<3';\n\tfor (var i = 0; i < text.length; ++i) {\n\t\tif (text.charAt(i) == dfa.message.charAt(dfa.position)) {\n\t\t\tdfa.position += 1;\n\t\t\tif (dfa.position == dfa.message.length) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction main() {\n\tvar wordNum = parseInt(readline());\n\tvar words = [];\n\tfor (var i = 0; i < wordNum; ++i) {\n\t\twords.push(trim(readline()));\n\t}\n\tvar text = trim(readline());\n\tprint(solve(words, text) ? 'yes' : 'no');\n}\n\nmain();\n"}], "negative_code": [{"source_code": "n = Number(readline());\nvar text = [];\nwhile (n--) {\n str = readline();\n text.push(str);\n}\nvar main = readline();\nvar result = true;\n\nfor (var i = 0; i < text.length; i++) {\n var template = '<.*?3.*?';\n for (var j = 0; j < text[i].length; j++)\n template += (text[i][j] + '.*?')\n template += '<.*?3.*?';\n re = new RegExp(template);\n result &= re.test(main);\n if (!result) break;\n main = main.replace(re, '<3');\n}\nwrite(result ? 'YES' : 'NO');\n"}], "src_uid": "36fb3a01860ef0cc2a1065d78e4efbd5"} {"source_code": "function check_player() {\r\n\r\nk = readline();\r\n\r\nfor (i = 0; i < k; i++) {\r\n\r\n res_arr = readline().split(' ');\r\n m = 0;\r\n \r\n res_arr = res_arr.map(arg => +arg);\r\n \r\n res_arr = [res_arr.slice(0, 2), res_arr.slice(2, 4)];\r\n\r\nmax1 = Math.max(res_arr[0][0], res_arr[0][1]);\r\nmax2 = Math.max(res_arr[1][0], res_arr[1][1]);\r\n\r\n\r\n if (max1 > max2) {\r\n\r\n min1 = Math.min(res_arr[0][0], res_arr[0][1]);\r\n\r\n if (max2 > min1) {\r\n\r\n print('Yes');\r\n\r\n } else {\r\n \r\n print('No');\r\n \r\n }\r\n\r\n } else {\r\n\r\n min2 = Math.min(res_arr[1][0], res_arr[1][1]);\r\n\r\n if (max1 > min2) {\r\n\r\n print('Yes');\r\n\r\n } else {\r\n \r\n print('No');\r\n \r\n }\r\n\r\n }\r\n \r\n }\r\n\r\n}\r\n\r\ncheck_player();", "positive_code": [{"source_code": "var testCase=+readline()\r\nfor(var i=0;i+node),counter=0\r\n var a=sequence.slice(0,2)\r\n var b=sequence.slice(-2)\r\n var aMax=a.reduce((a,b)=>Math.max(a,b))\r\n var bMax=b.reduce((a,b)=>Math.max(a,b))\r\n \r\n a.forEach((node)=>node>bMax?counter++:null)\r\n b.forEach((node)=>node>aMax?counter++:null)\r\n \r\n \r\n counter>1?print(\"NO\"):print(\"YES\")\r\n}\r\n"}, {"source_code": "var a = readline();\r\nvar arr = [];\r\nvar s = 0;\r\nvar s1 = 0;\r\nvar s2 = 0;\r\nvar s3 = 0;\r\nvar f = 0;\r\nvar f1 = 0;\r\nvar f2 = 0;\r\nvar f3 = 0;\r\nvar d = 0;\r\nfor(var i = 0; i < a; i++){\r\n arr[i] = readline().split(' ').map(i=>Number(i));\r\n s=arr[i][0];\r\n s1=arr[i][1];\r\n s2=arr[i][2];\r\n s3=arr[i][3];\r\n if(s>s1){\r\n f=s;\r\n }else{\r\n f=s1;\r\n }\r\n if(s2>s3){\r\n f1=s2\r\n }else{\r\n f1=s3\r\n }\r\n if(f parseInt(x));\r\n\r\nwinner1 = Math.max(players[0], players[1]);\r\nwinner2 = Math.max(players[2], players[3]);\r\n\r\nplayers.sort((a, b) => a - b);\r\n\r\nprint(players[3] == Math.max(winner1,winner2) && players[2] == Math.min(winner1,winner2) ? \"YES\" : \"NO\")\r\n}"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var s = readline().split(' '),\r\n s1 = s.slice(0,2).sort( (a,b) => {return a - b}),\r\n s2 = s.slice(2,4).sort( (a,b) => {return a - b}),\r\n highestSkills = s.sort( (a,b) => {return a - b}).slice(2,4);\r\n winners = [s1[1],s2[1]].sort( (a,b) => {return a - b});\r\n if(winners.toString() == highestSkills.toString()){\r\n print('YES');\r\n }\r\n else{\r\n print('NO');\r\n }\r\n }"}, {"source_code": "t = +readline();\r\nwhile (t--) {\r\n x = readline().split(\" \").map(Number);\r\n winner1 = Math.max(x[0], x[1]);\r\n winner2 = Math.max(x[2], x[3]);\r\n losser1 = Math.min(x[0], x[1]);\r\n losser2 = Math.min(x[2], x[3]);\r\n wouldBig = Math.min(winner1, winner2);\r\n wouldSmoll = Math.max(losser1, losser2);\r\n if (wouldBig > wouldSmoll) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "// 1535 A - Playoff equo\r\n\r\n// number of test case\r\nvar numTests = parseInt( readline() );\r\n\r\nfor (var numTest = 0; numTest < numTests; numTest++) {\r\n \r\n // input data \r\n var nums = readline().split(' ').map( e => parseInt(e));\r\n \r\n // two player pi\u00f9 forti non stiano nella stessa squadra\r\n if( Math.max( nums[0],nums[1] ) >= Math.min( nums[2],nums[3] ) && Math.max( nums[2],nums[3] ) >= Math.min( nums[0],nums[1] ) ){\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n\r\n}"}, {"source_code": "var number = parseInt(readline());\r\nvar first = 0;\r\nvar second = 0;\r\n\r\nfor(var i = 0; i < number; i++) {\r\n var counter = 0;\r\n var foo = readline();\r\n var fooSplited = foo.split(\" \")\r\n if(parseInt(fooSplited[0]) > parseInt(fooSplited[1])) {\r\n first = parseInt(fooSplited[0]);\r\n } else {\r\n first = parseInt(fooSplited[1]);\r\n }\r\n\r\n if(parseInt(fooSplited[2]) > parseInt(fooSplited[3])) {\r\n second = parseInt(fooSplited[2]);\r\n } else {\r\n second = parseInt(fooSplited[3])\r\n }\r\n\r\n if(first > parseInt(fooSplited[2]) || first > parseInt(fooSplited[3])) {\r\n counter++;\r\n }\r\n\r\n if(second > parseInt(fooSplited[0]) || second > parseInt(fooSplited[1])) {\r\n counter++;\r\n }\r\n\r\n if(counter == 2) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\")\r\n }\r\n\r\n}"}, {"source_code": "const arrMax = a => Math.max.apply(null, a);\n\nconst t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var p = readline().split(' ').map(d => parseInt(d));\n var p_s = [...p];\n p_s.sort((a, b) => b - a);\n var fair = p_s.slice(0, 2);\n var actual = [];\n actual.push(arrMax(p.slice(0, 2)), arrMax(p.slice(2, 4)));\n actual.sort((a, b) => b - a);\n print(fair[0] === actual[0] && fair[1] === actual[1]? 'YES': 'NO');\n} "}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a > array[2] || a > array[3] ? console.log('YES'): console.log('NO'):\r\n b > array[0] || b > array[1] ? console.log('YES'): console.log('NO');\r\n }\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var v2 = v.concat();\r\n v2.sort(function (a, b) {\r\n if (a < b) return -1;\r\n if (a > b) return 1;\r\n return 0;\r\n });\r\n if (((v2[0] == v[0] && v2[1] == v[1])\r\n || (v2[0] == v[1] && v2[1] == v[0])\r\n || (v2[0] == v[2] && v2[1] == v[3])\r\n || (v2[0] == v[3] && v2[1] == v[2]))) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(players_skills[0], players_skills[1])\r\n}\r\n\r\nfunction solution(input) {\r\n const champion = Math.max(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n const runner_up = Math.min(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n input.sort((a, b) => b - a);\r\n\r\n return input[0] === champion && input[1] === runner_up ? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for(let test_case = 1; test_case <= number_of_test_cases; test_case += 1) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(...players_skills)\r\n}\r\n\r\nfunction looser(players_skills) {\r\n return Math.min(...players_skills)\r\n}\r\nfunction is_fair(semifinal_1, semifinal_2) {\r\n return winner(semifinal_1) > looser(semifinal_2) &&\r\n winner(semifinal_2) > looser(semifinal_1);\r\n}\r\n\r\nfunction solution(input) {\r\n return is_fair(input.slice(0, 2), input.slice(2, 4))? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n for(const _ of Array(Number(input.shift()))) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(...players_skills)\r\n}\r\n\r\nfunction looser(players_skills) {\r\n return Math.min(...players_skills)\r\n}\r\nfunction is_fair(semifinal_1, semifinal_2) {\r\n return winner(semifinal_1) > looser(semifinal_2) &&\r\n winner(semifinal_2) > looser(semifinal_1);\r\n}\r\n\r\nfunction solution(input) {\r\n return is_fair(input.slice(0, 2), input.slice(2, 4))? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for (let test_case = 1; test_case <= number_of_test_cases; test_case += 1) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j].split(' ')\n var x = Math.min(a[0], a[1])\n var c = Math.max(a[2], a[3])\n var v = Math.min(a[2], a[3]); \n var z = Math.max(a[0], a[1]); \n if(x <= c && v <= z){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n });\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n for(var j = 1; j <= lines[0]; j++){\n var a = lines[j].split(' ');\n var x = Math.min(a[0],a[1]); \n var c = Math.max(a[2],a[3]); \n var v = Math.min(a[2],a[3]); \n var z = Math.max(a[0],a[1]); \n if (x <= c && v <= z){\n console.log('YES');\n } else{\n console.log(\"NO\");\n }\n }\n});\n\n//xcvz "}, {"source_code": "\r\n\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\nconst testcase=parseInt(readline());\r\nlet d=[];\r\nfor(let i=0;iz && y>t) d.push(\"YES\");\r\n \r\n else d.push(\"NO\");\r\n \r\n \r\n \r\n}\r\nfor(let i=0;i {\r\n userInput.push(data);\r\n});\r\n\r\ninp.on(\"close\", () => {\r\n //start-here\r\n //Your code goes here \u2026 replace the below line with your code logic \r\nvar i=1;\r\n var t=userInput[0]\r\n while(i<=t)\r\n {\r\n dummy=userInput[i].split(' ')\r\n arr=dummy \r\n \r\n var bigger=Math.max(dummy[0],dummy[1])\r\n var bigger2=Math.max(dummy[2],dummy[3])\r\n \r\n \r\n \r\n arr.sort(function(a, b) {\r\n return a - b;\r\n})\r\n var biggestno=arr[3]\r\n var biggestno2=arr[2]\r\n \r\n if(((bigger==biggestno)||(bigger==biggestno2))&&((bigger2==biggestno2)||(bigger2==biggestno)))\r\n {\r\n console.log('YES')\r\n }\r\n else{\r\n console.log('NO')\r\n }\r\n i++\r\n \r\n }\r\n //end-here\r\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n//###########################################################\r\n\r\n\r\n\r\n\r\n\r\nfunction myFunc(arr){\r\n let maxD, minD, maxE, minE;\r\n maxE = Math.max(arr[0], arr[1]); \r\n maxD = Math.max(arr[2], arr[3]);\r\n\r\n minE = Math.min(arr[0], arr[1]);\r\n minD = Math.min(arr[2], arr[3]);\r\n if(maxE > minD && maxD > minE){\r\n return 'YES';\r\n }\r\n return 'NO';\r\n}\r\n\r\n\r\n\r\n\r\n//###########################################################\r\nfunction main() {\r\n\r\n\r\n const t = parseInt(readLine(), 10);\r\n \r\n for(let i = 0; i < t; i++){\r\n\r\n // const line = readLine().split(' ');\r\n // const x = parseInt(line[0], 10);\r\n // const y = parseInt(line[1], 10);\r\n // const str = line[2].toString();\r\n\r\n const line = readLine().split(' ').map(p => +p);\r\n\r\n let result = myFunc(line);\r\n\r\n console.log(result);\r\n }\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1, d1] = d.split(\" \").map(Number);\n\n if (c1 > a1 && c1 > b1 && d1 > a1 && d1 > b1) {\n console.log(\"NO\");\n } else if (c1 < a1 && c1 < b1 && d1 < a1 && d1 < b1) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var a = lines[j].split(' ');\n var win1 = Math.max(a[0],a[1]);\n var loss1 = Math.min(a[0],a[1]);\n var win2 = Math.max(a[2],a[3]);\n var loss2 = Math.min(a[2],a[3]);\n if (loss1 <= win2 && loss2 <= win1){\n console.log('YES');\n } else{\n console.log(\"NO\");\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.nums();\n\t\tlet b = [a[0] > a[1]?a[0]:a[1], a[2] > a[3]?a[2]:a[3]];\n\t\ta.sort((x, y) => y - x);\n\t\tb.sort((x, y) => y - x);\n\t\tans.push(a[0] === b[0] && a[1] === b[1]);\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?'YES':'NO').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a, b, c, d] = input[z++].trim().split(' ').map(Number);\r\n let max1 = Math.max(a, b);\r\n let max2 = Math.max(c, d);\r\n\r\n if((max1 > c || max1 > d) && (max2 > a || max2 > b)){\r\n console.log(\"Yes\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var a = readArray((x, i) => [i, Number(x)]);\r\n a.sort((x, y) => y[1] - x[1]);\r\n var half = (a.length >> 1);\r\n write((a[0][0] < half ^ a[1][0] >= half) ? 'NO' : 'YES');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n \r\n var t=parseInt(readline());\r\nwhile(t--)\r\n{\r\n var a=readline().split(' ').map(a=>parseInt(a))\r\n var b=Math.max(a[0],a[1])\r\n var c=Math.min(a[2],a[3])\r\n var d=Math.min(a[0],a[1])\r\n var e=Math.max(a[2],a[3])\r\n if(be)console.log(\"NO\")\r\n else console.log(\"YES\");\r\n\r\n}\r\n\r\n\r\n \r\n \r\n}\r\n"}, {"source_code": "\r\nconst fin = (arr) => {\r\n\tif (arr.length === 2) {\r\n\t\treturn arr;\r\n\t}\r\n\r\n\tconst next = [];\r\n\tfor (let i=0; i {\r\n\tconst final = fin(arr).sort((a, b) => b-a);\r\n\tconst sorted = arr.sort((a, b) => b-a).slice(0, 2);\r\n\r\n\treturn final[0] === sorted[0] &&\r\n\t\tfinal[1] === sorted[1] ? 'YES' : 'NO';\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [t, ...lines] = input.trim().split('\\n');\r\n\r\n\tfor (let i=0; i +v)));\r\n\t}\r\n})\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nconst input = [];\r\nlet currLine = 0;\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n});\r\n\r\nrl.on(\"close\", () => {\r\n main();\r\n});\r\n\r\nconst read = () => {\r\n return input[currLine++];\r\n};\r\n\r\nconst readArr = () => {\r\n return input[currLine++].split(\" \").map(e=>parseInt(e));\r\n};\r\n\r\nconst main = () => {\r\n\r\n const tc=parseInt(read());\r\n \r\n let i=0;\r\n while(i{\r\n if(aarr[1]){\r\n w1=arr[0];\r\n }\r\n else{\r\n w1=arr[1];\r\n }\r\n \r\n if(arr[2]>arr[3]){\r\n w2=arr[2];\r\n }\r\n else{\r\n w2=arr[3];\r\n }\r\n \r\n if((w1!=first && w1!=second) || (w2!=first && w2!=second)){\r\n console.log(\"NO\");\r\n }\r\n else{\r\n console.log(\"YES\");\r\n }\r\n \r\n i++;\r\n }\r\n \r\n};"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b, c, d) => {\r\n let A = [a, b, c, d];\r\n stde(A);\r\n let should = [A[0], A[1]];\r\n let actual = [mx(a, b), mx(c, d)];\r\n stin(should);\r\n stin(actual);\r\n // pr(should, actual);\r\n let res = should[0] == actual[0] && should[1] == actual[1];\r\n pr(res ? 'YES' : 'NO');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2], input[i][3]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve(arr) {\r\n const [max1,max2] = arr.slice(0).sort((a,b)=>a-b).reverse()\r\n if((max1 === arr[0] || max1 === arr[1]) && (max2 === arr[2] || max2 === arr[3])){\r\n console.log('YES')\r\n } else if((max1 === arr[2] || max1 === arr[3]) && (max2 === arr[0] || max2 === arr[1])){\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "(()=>{\"use strict\";var e={696:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=e=>{Math.min(e[0],e[1])>Math.max(e[2],e[3])||Math.min(e[2],e[3])>Math.max(e[0],e[1])?console.log(\"NO\"):console.log(\"YES\")}},590:function(e,t,n){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});const s=o(n(696));n(188).testInput(s.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=e=>{const t=n(58).createInterface({input:process.stdin,output:process.stdout});let o=[],s=0;t.on(\"line\",(function(n){if(o.push(n),1===o.length&&(s=+o[0]),o.length===s+1){t.close();for(let t=1;t{const o=n(58).createInterface({input:process.stdin,output:process.stdout});let s=[];o.on(\"line\",(function(e){s.push(e),2===s.length&&(o.close(),console.log(t(s[1].split(\" \").map((e=>+e)))))}))}},58:e=>{e.exports=require(\"readline\")}},t={};!function n(o){var s=t[o];if(void 0!==s)return s.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,n),r.exports}(590)})();"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++]));\n }\n});\n \nfunction solve(str) {\n const skills = str.split(' ').map(Number)\n const [a, b, c, d] = skills\n const p = Math.max(a, b)\n const q = Math.max(c, d)\n\n skills.sort((a, b) => b - a)\n\n const [m, n] = skills\n let fair\n if (p > q) {\n fair = p === m && q === n\n } else {\n fair = q === m && p === n\n }\n return fair ? 'YES' : 'NO'\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = nextIntArray(4);\r\n\t\tvar tmp = makeClone(s);\r\n\t\tvar L = Math.max(s[0], s[1]);\r\n\t\tvar R = Math.max(s[2], s[3]);\r\n\t\ttmp.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tif((tmp[0] == L || tmp[0] == R) && (tmp[1] == L || tmp[1] == R)){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "var testCase=+readline()\r\nfor(var i=0;i+node),counter=0\r\n \r\n var aMax=sequence.slice(0,2).reduce((a,b)=>Math.max(a,b))\r\n var b=sequence.slice(-2)\r\n \r\n b.forEach(node=>node>aMax?counter++:null)\r\n \r\n counter===0||counter===2?print(\"NO\"):print(\"YES\")\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split\r\n console.log(array)\r\n // let a = array[0]>array[1]?array[0]:array[1];\r\n // let b = array[2]>array[3]?array[2]:array[3];\r\n // a < b ? \r\n // a > array[2] || a > array[3] ? console.log('YES'): console.log('NO'):\r\n // b > array[0] || b > array[1] ? console.log('YES'): console.log('NO');\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(' ');\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a > array[2] || a > array[3] ? console.log('YES'): console.log('NO'):\r\n b > array[0] || b > array[1] ? console.log('YES'): console.log('NO');\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(' ');\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a > array[2] || a > array[3] ? console.log('YES'): console.log('NO'):\r\n b > array[0] || b > array[1] ? console.log('YES'): console.log('NO')\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(' ');\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a < array[2] && a < array[3] ? console.log('NO'): console.log('YES'):\r\n b < array[0] && b < array[1] ? console.log('NO'): console.log('YES')\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(' ');\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a < array[2] && a < array[3] ? console.log('YES'): console.log('NO'):\r\n b < array[0] && b < array[1] ? console.log('YES'): console.log('NO')\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(' ');\r\n let a = array[0]>array[1]?array[0]:array[1];\r\n let b = array[2]>array[3]?array[2]:array[3];\r\n a < b ? \r\n a < array[2] || a < array[3] ? console.log('NO'):console.log('YES'):\r\n b < array[0] || array[1]?console.log('NO'):console.log('YES')\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var v2 = v.concat();\r\n v2.sort();\r\n if (((v2[0] == v[0] && v2[1] == v[1])\r\n || (v2[0] == v[1] && v2[1] == v[0])\r\n || (v2[0] == v[2] && v2[1] == v[3])\r\n || (v2[0] == v[3] && v2[1] == v[2]))) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var v2 = v.concat();\r\n v2.sort();\r\n if (((v[0] == v2[0] && v[1] == v2[1])\r\n || (v[0] == v2[1] && v[1] == v2[0])\r\n || (v[0] == v2[2] && v[1] == v2[3])\r\n || (v[0] == v2[3] && v[1] == v2[2]))) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(players_skills[0], players_skills[1])\r\n}\r\n\r\nfunction solution(input) {\r\n const champion = Math.max(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n const runner_up = Math.min(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n console.log({champion, runner_up});\r\n input.sort((a, b) => b - a);\r\n\r\n return input[0] === champion && input[1] === runner_up ? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for(let test_case = 1; test_case <= number_of_test_cases; test_case += 1) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(players_skills[0], players_skills[1])\r\n}\r\n\r\nfunction solution(input) {\r\n const champion = Math.max(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n const runner_up = Math.min(winner(input.slice(0, 2)), winner(input.slice(0, 2)));\r\n input.sort((a, b) => b - a);\r\n\r\n return input[0] === champion && input[1] === runner_up ? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n const number_of_test_cases = Number(input.shift());\r\n for(let test_case = 1; test_case <= number_of_test_cases; test_case += 1) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "const os = require('os');\r\n\r\nfunction winner(players_skills) {\r\n return Math.max(players_skills[0], players_skills[1])\r\n}\r\n\r\nfunction solution(input) {\r\n const champion = Math.max(winner(input.slice(0, 2)), winner(input.slice(2, 4)));\r\n const runner_up = Math.min(winner(input.slice(0, 2)), winner(input.slice(0, 2)));\r\n input.sort((a, b) => b - a);\r\n\r\n return input[0] === champion && input[1] === runner_up ? 'YES' : 'NO';\r\n}\r\n\r\nfunction parse(input_in_string) {\r\n return input_in_string.split(' ').map(Number);\r\n}\r\n\r\n\r\nlet lines = '';\r\n\r\nprocess.stdin.on('data', data => lines += data);\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = lines.split(os.EOL);\r\n input.shift();\r\n while (input.length !== 0) {\r\n console.log(solution(parse(input.shift())));\r\n }\r\n});\r\n\r\nmodule.exports = {solution}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j].split(' ')\n var x = Math.min(a[0], a[1])\n var c = Math.max(a[2], a[3])\n var v = Math.max(a[0], a[1])\n var z = Math.min(a[2], a[3])\n if(x <= c && v <= z){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n });\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": " let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = false\n for(j = 1; j <= lines[0]; j++){\n var l = lines[j]\n for(k = 0; k < 4; k++){\n var a = l.split(' ')\n if(a[0] > a[1] && a[0] > a[2] && a > a[3]){\n if(a[0] > a[2] && a[2] > a[1] && a[2] > a[3]){\n s = true\n }\n if(a[0] > a[3] && a[3] > a[1] && a[3] > a[2]){\n s= true\n }\n } else if(a[1] > a[0] && a[1] > a[2] && a[1] > a[3]){\n if(a[1] > a[2] && a[2] > a[0] && a[2] > a[3]){\n s = true\n }\n if(a[1] > a[3] && a[3] > a[0] && a[3] > a[2]){\n s= true\n }\n }else if(a[2] > a[0] && a[2] > a[1] && a[2] > a[3]){\n if(a[2] > a[1] && a[1] > a[0] && a[1] > a[3]){\n s = true\n }\n if(a[2] > a[0] && a[0] > a[1] && a[0] > a[3]){\n s= true\n }\n }else if(a[3] > a[0] && a[3] > a[1] && a[3] > a[2]){\n if(a[3] > a[0] && a[0] > a[1] && a[0] > a[2]){\n s = true\n }\n if(a[3] > a[1] && a[1] > a[0] && a[1] > a[2]){\n s= true\n }\n }else {\n s = false\n }\n }\n \n if(s === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n});"}, {"source_code": " let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = false\n for(j = 1; j <= lines[0]; j++){\n var l = lines[j]\n for(k = 0; k < 4; k++){\n var a = l.split(' ')\n if(a[0] > a[1] && a[0] > a[2] && a > a[3]){\n if(a[0] > a[2] && a[2] > a[1] && a[2] > a[3]){\n s = true\n }\n if(a[0] > a[3] && a[3] > a[1] && a[3] > a[2]){\n s= true\n }\n } else if(a[1] > a[0] && a[1] > a[2] && a[1] > a[3]){\n if(a[1] > a[2] && a[2] > a[0] && a[2] > a[3]){\n s = true\n }\n if(a[1] > a[3] && a[3] > a[0] && a[3] > a[2]){\n s= true\n }\n }else if(a[2] > a[0] && a[2] > a[1] && a[2] > a[3]){\n if(a[2] > a[1] && a[1] > a[0] && a[1] > a[3]){\n s = true\n }\n if(a[2] > a[0] && a[0] > a[1] && a[0] > a[3]){\n s= true\n }\n }else if(a[3] > a[0] && a[3] > a[1] && a[3] > a[2]){\n if(a[3] > a[0] && a[0] > a[1] && a[0] > a[2]){\n s = true\n }\n if(a[3] > a[1] && a[1] > a[0] && a[1] > a[2]){\n s= true\n }\n }\n }\n \n if(s === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n});"}, {"source_code": "\r\n\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\nconst testcase=parseInt(readline());\r\nlet r=[];\r\nfor(let i=0;iz && y>t) console.log('YES');\r\n \r\n else console.log(\"NO\");\r\n \r\n\r\n}\r\n\r\n}\r\n\r\n"}, {"source_code": "\r\n\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\nconst testcase=parseInt(readline());\r\nlet r=[];\r\nfor(let i=0;iz && y>t) console.log('YES');\r\n \r\n else console.log(\"NO\");\r\n \r\n\r\n\r\n}\r\n"}, {"source_code": "// Getting input via STDIN\r\nconst readline = require(\"readline\");\r\n\r\nconst inp = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nconst userInput = [];\r\n\r\ninp.on(\"line\", (data) => {\r\n userInput.push(data);\r\n});\r\n\r\ninp.on(\"close\", () => {\r\n //start-here\r\n //Your code goes here \u2026 replace the below line with your code logic \r\nvar i=1;\r\n var t=userInput[0]\r\n while(i<=t)\r\n {\r\n dummy=userInput[i].split(' ')\r\n arr=dummy\r\n \r\n \r\n var bigger=Math.max(dummy[0],dummy[1])\r\n \r\n if(dummy[2]dummy[3]){\r\n bigger2=dummy[2]\r\n }\r\n \r\n var sortedarr=arr.sort()\r\n var biggestno=sortedarr[3]\r\n var biggestno2=sortedarr[2]\r\n if(((bigger==biggestno)||(bigger==biggestno2))&&((bigger2==biggestno2)||(bigger2==biggestno)))\r\n {\r\n console.log('YES')\r\n }\r\n else{\r\n console.log('NO')\r\n }\r\n i++\r\n \r\n }\r\n //end-here\r\n});"}, {"source_code": "// Getting input via STDIN\r\nconst readline = require(\"readline\");\r\n\r\nconst inp = readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nconst userInput = [];\r\n\r\ninp.on(\"line\", (data) => {\r\n userInput.push(data);\r\n});\r\n\r\ninp.on(\"close\", () => {\r\n //start-here\r\n //Your code goes here \u2026 replace the below line with your code logic \r\nvar i=1;\r\n var t=userInput[0]\r\n while(i<=t)\r\n {\r\n dummy=userInput[i].split(' ')\r\n arr=dummy\r\n \r\n \r\n var bigger=Math.max(dummy[0],dummy[1])\r\n \r\n if(dummy[2]dummy[3]){\r\n bigger2=dummy[2]\r\n }\r\n \r\n var sortedarr=arr.sort()\r\n var biggestno=sortedarr[3]\r\n var biggestno2=sortedarr[2]\r\n if(((bigger==biggestno)||(bigger==biggestno2))&&((bigger2==biggestno2)||(bigger2==biggestno)))\r\n {\r\n console.log('YES')\r\n }\r\n else{\r\n console.log('NO')\r\n }\r\n i++\r\n \r\n }\r\n //end-here\r\n});"}], "src_uid": "cb24509580ff9b2f1a11103a0e4cdcbd"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\tsetEncoding: 'utf8',\n\tterminal: false\n});\n\nconst readInput = (function* () {\n\tconst n = Number(yield);\n\tconst a = (yield).trim().split(' ').map(Number);\n\trl.close();\n\tlet to = 0;\n\tlet days = 0;\n\tfor (let i = 0; i < n; i++) {\n\t\tto = Math.max(to, a[i]);\n\t\tif (to == a[i] && to == i + 1) days++;\n\t}\n\tconsole.log(days);\n})();\n\nreadInput.next();\n\nrl.on('line', (line) => {\n\treadInput.next(line);\n});\n", "positive_code": [{"source_code": "const n = Number(readline());\nconst pages = readline().split(\" \").slice(0, n).map(x => Number(x));\nvar max = 0;\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n var next = pages[i];\n if (next > max) max = next;\n if (max <= i + 1) count++;\n}\nprint(count);\n"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nvar changed=false;\nfor(var i=0; imax) {\n max=Number(a[i]);\n changed=true;\n }\n if(Number(a[i])==max && max==(i+1) && changed){\n days++;\n changed=false;\n }\n}\nprint(days);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nvar changed=false;\nfor(var i=0; imax) {\n max=Number(a[i]);\n changed=true;\n }\n if(max==(i+1) && changed){\n days++;\n changed=false;\n }\n}\nprint(days);"}, {"source_code": "var len = parseInt(readline());\nvar pagesArr = readline().split(' ').map(_=>{return parseInt(_)});\n\nvar curLastPage = 0;\nvar readTimes = 0;\nfor (var index = 0; index < len;index ++) {\n if (pagesArr[index] > curLastPage) {\n curLastPage = pagesArr[index];\n }\n if (curLastPage == index + 1) {\n readTimes ++;\n }\n}\nprint(readTimes);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString\n .replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n console.log(getDays(inputString[1].split(' ').map(i => parseInt(i, 10))));\n});\n\nfunction getDays(arr) {\n let stack = [];\n let count = 0;\n for (let i = 0; i < arr.length; i++) {\n stack.push(arr[i]);\n\n while(stack[stack.length - 1] <= i + 1) {\n stack.pop();\n }\n\n if (stack.length === 0) {\n count++;\n }\n }\n\n return count;\n}"}], "negative_code": [{"source_code": "const n = Number(readline());\nconst pages = readline().split(\" \").slice(0, n).map(x => Number(x));\nvar max = 0;\nvar count = 0;\nfor (var i = 1; i <= n; i++) {\n next = pages[i];\n if (next > max) max = next;\n if (max <= i) count++;\n}\nprint(count);\n"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nfor(var i=0; imax) max=a[i];\n if(max>(i+1)){\n continue;\n }\n days++;\n}\nprint(days);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nfor(var i=0; imax) max=a[i];\n if(Number(a[i])>(i+1) || max>(i+1)){\n continue;\n }\n days++;\n}\nprint(days);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nvar changed=false;\nfor(var i=0; imax) {\n max=Number(a[i]);\n changed=true;\n }\n if(Number(a[i])==max && max==(i+1) && changed){\n print(a[i]+\" \"+max)\n days++;\n changed=false;\n }\n}\nprint(days);"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\na=a.slice(0,n);\n\nvar days=0;\nvar max=Number.MIN_VALUE;\nfor(var i=0; imax) {\n max=Number(a[i]);\n var changed=true;\n }\n if(Number(a[i])==max && changed){\n days++;\n changed=false;\n }\n}\nprint(days);"}], "src_uid": "291601d6cdafa4113c1154f0dda3470d"} {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var Ar = readline().split(' ').map(x => +x);\n var n = Ar[0], m = Ar[1];\n print(n - 1 + ' ' + m);\n}", "positive_code": [{"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = readline().split(' ').map(i => +i);\n var a = l[0];\n var b = l[1];\n var c = 0;\n \n // while (a !== 0 || b !== 0) {\n // if (c === 0) {\n // if (b === 0) {\n // break;\n // }\n // a--;\n // c = 1;\n // } else if (c === 1) {\n // if (a === 0) {\n // break;\n // }\n // b--;\n // c = 0;\n // }\n // }\n \n print([a-1, b].toString().replace(/\\,/g, ' '));\n}\n"}, {"source_code": "const solve = (x, y) => {\n console.log(x - 1 + \" \" + y);\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t > 0) {\n solve(input[i][0], input[i][1]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n if (a === b) {\n console.log(`${a - 1} ${b}`);\n } else if (a > b) {\n console.log(`${a - 1} ${b}`);\n } else {\n console.log(`${a - 1} ${b}`);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar x = nextInt() - 1;\n\t\tvar y = nextInt();\n\t\tmyout(x + \" \" + y);\n\t}\n}\n\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function f(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let cnt = (x: number, y: number, p1: boolean, running: boolean) => {\n// // io.debug([x, y, p1, running])\n// \n// if (y == 0) {\n// return [x, 0]\n// }\n// \n// if (x == 0) {\n// return [0, y]\n// }\n// \n// if (!running) {\n// if (p1) {\n// return cnt(x - 1, y, !p1, true)\n// } else {\n// return cnt(x, y - 1, !p1, true)\n// }\n// }\n// \n// let candidate1 = [0, 0]\n// \n// if (p1) {\n// candidate1 = cnt(x - 1, y, !p1, true)\n// } else {\n// candidate1 = cnt(x, y - 1, !p1, true)\n// }\n// \n// let candidate2 = [0, 0]\n// \n// if (p1) {\n// candidate2 = cnt(x, y, !p1, false)\n// candidate2[1]++\n// } else {\n// candidate2 = cnt(x, y, !p1, false)\n// candidate2[0]++\n// }\n// \n// // io.debug(candidate1)\n// // io.debug(candidate2)\n// \n// if (p1) {\n// if (candidate1[0] == candidate2[0]) {\n// return [candidate1[0], [candidate1[1], candidate2[1]].max()]\n// }\n// \n// if (candidate1[0] > candidate2[0]) {\n// return candidate1\n// } else {\n// return candidate2\n// }\n// } else {\n// if (candidate1[1] == candidate2[1]) {\n// return [[candidate1[0], candidate2[0]].max(), candidate1[1]]\n// }\n// \n// if (candidate1[1] > candidate2[1]) {\n// return candidate1\n// } else {\n// return candidate2\n// }\n// }\n// }\n// \n// let [x, y] = io.nextNumbers()\n// \n// // let n = 10\n// \n// // for (let x = 1; x <= n; ++x) {\n// // for (let y = 1; y <= n; ++y) {\n// // io.puts(x + \" \" + y + \" :\" + cnt(x, y, true, false))\n// // }\n// // }\n// \n// x--\n// \n// io.puts(x + \" \" + y)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "/*\n * File Created: Monday, 30th November 2020 3:31:00 pm\n * Author: Lukas Rimkus\n */\n\n'use-strict'\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\ndata += chunk;\n});\n\nprocess.stdin.on('end', () =>{\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const n = data.shift().split(' ').map(Number)\n\n const res = c(n[0], n[1]);\n\n console.log(res[0], res[1])\n }\n});\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n \nfunction readLine() { \n return data[currentLine++];\n}\n \n\nfunction a(num)\n{\n return num.length ;\n}\n\n\n\nfunction b(goal)\n{\n\n function jump1(y,k)\n {\n return y + k;\n }\n function jump2(y)\n {\n return y - 1;\n }\n\n let sum = 0;\n\n let jumps = 0;\n\n let arr = [];\n\n while(sum < goal)\n {\n jumps++;\n\n arr.push(jumps);\n\n sum = sum + jumps;\n }\n \n if(sum === goal)\n {\n return arr.length;\n }\n else\n {\n let current_pos = sum;\n\n // that's how many steps back;\n let diference = current_pos - goal; \n\n console.log(arr, arr.length, sum, diference)\n\n for(let i = 0 ; i < arr.length; i++)\n {\n if((arr[i] + 1) === diference)\n {\n return arr.length;\n }\n }\n return arr.length + 1;\n }\n}\n\nfunction c(x,y)\n{\n const arr = new Array(2);\n\n arr[0] = x - 1;\n\n arr[1] = y\n return arr;\n}\n\nmodule.exports = c;"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i) => {\n var line = readline();\n var x = Number(line.split(' ')[0])\n var y = Number(line.split(' ')[1])\n return console.log(x - 1, y)\n if (x == 0 && y === 0) return console.log(0, 0)\n if (y > x) {\n return console.log(0, y - x + 1)\n }\n if (x === y) return console.log(0, 1)\n return console.log(x - 1, y)\n\n })\n\n}\n\n"}], "negative_code": [{"source_code": "const solve = (x, y) => {\n if (x >= y) {\n console.log(x - 1 + \" \" + y);\n return;\n } else {\n console.log(x - 1 + \" \" + (y - x + 1));\n return;\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t > 0) {\n solve(input[i][0], input[i][1]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (x, y) => {\n if (x >= y) {\n console.log(x - 1 + \" \" + y);\n } else {\n console.log(x - 1 + \" \" + (y - x + 1));\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t > 0) {\n solve(input[i][0], input[i][1]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i) => {\n var line = readline();\n var x = line.split(' ')[0]\n var y = line.split(' ')[1]\n if (y > x) {\n if (x === 0) return console.log(0, y)\n return console.log(0, y - x + 1)\n }\n if (x === y) return console.log(0, 1)\n if (y === 0) return console.log(x, 0)\n return console.log(x - y, 1)\n\n })\n\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i) => {\n var line = readline();\n var x = Number(line.split(' ')[0])\n var y = Number(line.split(' ')[1])\n if(x==0 && y===0) return console.log(0, 0)\n if (y > x) {\n return console.log(0, y - x + 1)\n }\n if (x === y) return console.log(0, 1)\n return console.log(x-1, y)\n\n })\n\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i) => {\n var line = readline();\n var x = Number(line.split(' ')[0])\n var y = Number(line.split(' ')[1])\n if(x==0 && y===0) return console.log(0, 0)\n if (y > x) {\n if (x === 0) return console.log(0, y)\n return console.log(0, y - x + 1)\n }\n if (x === y) return console.log(0, 1)\n if (y === 0) return console.log(x, 0)\n return console.log(x - y, 1)\n\n })\n\n}\n\n"}], "src_uid": "09625e65e62fc1c618d12969932508de"} {"source_code": "\nvar nk = readline();\nvar t = readline();\n\nvar n = nk.split(\" \")[0];\nvar k = nk.split(\" \")[1];\n\nvar equal = \"\";\nfor (var i = 0; i < t.length - 1; i ++) {\n var firstSub = t.substring(0, i + 1);\n var secondSub = t.substring(t.length - i - 1, t.length);\n \n if (firstSub === secondSub) {\n equal = firstSub;\n }\n }\n\nvar result = t;\nfor (var i = 1; i < k; i ++) {\n if (equal !== \"\") {\n result += t.substring(equal.length, t.length);\n } else {\n result += t;\n }\n}\n\nwrite(result);\n\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray(Number);\n const word = is.nextLine();\n const auxRev = word.slice();\n let characters = 0;\n for (let i = 1, j = word.length - 1; i < n && j > 0; i += 1, j -= 1) {\n if (word.slice(0, i) === auxRev.slice(j))\n characters = i;\n }\n const aux = word.slice(characters);\n let answer = word;\n for (let i = 1; i < k; i += 1)\n answer += aux;\n console.log(answer);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = String) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); } );\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "function main() {\n const is = new Scanner();\n const [n, k] = is.nextArray(Number);\n const word = is.nextLine();\n const auxRev = word.slice();\n let characters = 0;\n for (let i = 1, j = word.length - 1; i < n && j > 0; i += 1, j -= 1) {\n if (word.slice(0, i) === auxRev.slice(j))\n characters = i;\n }\n const aux = word.slice(characters);\n let answer = word;\n for (let i = 1; i < k; i += 1)\n answer += aux;\n console.log(answer);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = String) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); } );\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k, n))\n\nfunction output(string, k, n) {\n var p = n - 1;\n var l = 0;\n var ans = 0;\n for (var i = p - 1; i >= 0; i--) {\n if (ans === 0) {\n for (var j = i; j >= 0; j--) {\n if (string[j] === string[p]) {\n p--;\n l++;\n if (j === 0) {\n ans = l;\n }\n } else {\n p = n - 1;\n l = 0;\n break;\n }\n }\n } else {\n break;\n }\n }\n\n for (var i = 1; i <= k - 1; i++) {\n for (var j = l; j < n; j++) {\n string += string[j];\n }\n }\n return string;\n}"}, {"source_code": "var args = readline().split(' ');\nvar str = readline();\n\nargs = args.map((n) => parseInt(n, 10));\n\nvar len = args[0];\nvar repeat = args[1];\n\nvar i = 1;\nvar mark = 0;\nwhile (i < len) {\n var prefix = str.substring(0, i);\n var suffix = str.substring(len - i);\n if (prefix === suffix) {\n mark = i;\n }\n i++;\n}\n\nconst res = [];\nconst substr = str.substring(mark);\n\nres.push(str.substring(0, mark));\n\nfor (var j = 0;j < repeat;j++) {\n res.push(substr);\n}\n\nprint(res.join(''));\n"}, {"source_code": "var a = readline().split(\" \");\nvar n = a[1];\nvar str = readline();\nvar firstP = str.slice(1);\nvar secondP = str.slice(0, str.length - 1);\nvar i,\n bool = false;\nfor(i = 1; i <= str.length - 1; i++){\n if(firstP == secondP){\n bool = true;\n break;\n } else{\n firstP = firstP.slice(1);\n secondP = secondP.slice(0, secondP.length - 1);\n }\n}\nvar mainText;\nif(bool){\n mainText = str.slice(secondP.length);\n} else{\n mainText = str;\n}\nvar lastResult = str;\nfor(i = 1; i <= n-1; i++){\n lastResult += mainText;\n}\nprint(lastResult);\n"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n // console.log('SAME')\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n var wordLength = word.length;\n\n for (var i = 0; i < wordLength / part.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', part, word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = getMaxAmount(word);\nvar begin = '';\nvar h = partLength > 0 && word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);\n\n// console.log(partLength);\nif (h) {\n begin = word[0];\n partLength = getMaxAmount(word.slice(1));\n word = word.slice(1);\n}\n\nwrite(begin + word + addPart(word.slice(partLength), amount - 1));"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray(Number);\n const word = is.nextLine();\n let answer = word, aux;\n for (let c = 1; c < k; c += 1) {\n aux = word.slice();\n for (let i = 0, j = n - 1; i < n && j >= 0; i++, j--)\n if (word[j] === aux[i]) {\n aux = word.slice(1);\n } else {\n break;\n }\n answer += aux;\n }\n\n console.log(answer);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = String) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); } );\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n // console.log(word)\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / symbol.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\n// let partLength = 0;\n// let begin = '';\n// let h = \n// word.length >= 6 && \n// word[0] === word[word.length -1] &&\n// !isSameSymbols(word, word[0]) &&\n// isPalindrom(word);\n\n// if(h){\n// begin = word[0];\n// partLength = getMaxAmount(word.slice(1));\n// word = word.slice(1);\n// } else {\n// partLength = getMaxAmount(word);\n// }\n\n\nvar partLength = getMaxAmount(word);\nvar a1 = word + addPart(word.slice(partLength), amount - 1);\npartLength = getMaxAmount(word.slice(1));\nvar a2 = word[0];\nword = word.slice(1);\na2 += word + addPart(word.slice(partLength), amount - 1);\n\nwrite(a1.length > a2.length ? a2 : a1);"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n // console.log(word)\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / symbol.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\n// let partLength = 0;\n// let begin = '';\n// let h = \n// word.length >= 6 && \n// word[0] === word[word.length -1] &&\n// !isSameSymbols(word, word[0]) &&\n// isPalindrom(word);\n\n// if(h){\n// begin = word[0];\n// partLength = getMaxAmount(word.slice(1));\n// word = word.slice(1);\n// } else {\n// partLength = getMaxAmount(word);\n// }\n\n\nvar partLength = getMaxAmount(word);\nvar a1 = word + addPart(word.slice(partLength), amount - 1);\npartLength = getMaxAmount(word.slice(1));\nvar a2 = word[0];\nword = word.slice(1);\na2 += word + addPart(word.slice(partLength), amount - 1);\n\nwrite(a1.length > a2.length ? a1 : a2);"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'))) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n while (word.length > word.replace(part, symbol).length) {\n word = word.replace(part, symbol);\n }\n\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar partLength = getMaxAmount(word);\nwrite(word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n // console.log(word)\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / symbol.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = 0;\nvar begin = '';\nvar test = !isSameSymbols(word, word[0]) && word.length >= 6 && word[0] === word[word.length - 1];\nif (test) {\n begin = word[0];\n partLength = getMaxAmount(word.slice(1));\n word = word.slice(1);\n} else {\n partLength = getMaxAmount(word);\n}\n\nwrite(begin + word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n while (word.length > word.replace(part, symbol).length) {\n word = word.replace(part, symbol);\n }\n\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = getMaxAmount(word.length >= 5 && isPalindrom(word) ? word.slice(1) : word);\nwrite(word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n while (word.length > word.replace(part, symbol).length) {\n word = word.replace(part, symbol);\n }\n\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = getMaxAmount(isPalindrom(word) ? word.slice(1) : word);\nwrite(word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n if (getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) === getWordPart('end', word, counter + 1)) {\n maxAmount = counter + 1;\n }\n }\n\n return maxAmount;\n};\n\nvar isSameLetters = function isSameLetters(word) {\n var letter = word[0];\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar a = function a(part, amount) {\n var result = '';\n\n for (var i = 0; i < amount; i++) {\n result += part;\n }\n\n return result;\n};\n\nvar replaceParts = function replaceParts(word, part) {\n\n while (word.length > word.replace(part, 'a').length) {\n word = word.replace(part, 'a');\n }\n\n return word;\n};\n\nif (isSameLetters(word)) {\n write(word + a(word[0], amount - 1));\n} else {\n var partLength = getMaxAmount(word);\n\n if (isSameLetters(replaceParts(word, word.slice(-partLength)))) {\n write(word + a(word.slice(-partLength), amount - 1));\n } else {\n write(word + a(word.slice(partLength), amount - 1));\n }\n}"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n // console.log(word)\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / symbol.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = 0;\nif (!isSameSymbols(word, word[0]) && word.length >= 6 && word[0] === word[word.length - 1]) {\n partLength = getMaxAmount(word.slice(1));\n} else {\n partLength = getMaxAmount(word);\n}\n\nwrite(word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n // console.log('SAME')\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / part.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', part, word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = getMaxAmount(word);\nvar begin = '';\nvar h = partLength > 0 && word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);\n\n// console.log(partLength);\nif (h) {\n begin = word[0];\n partLength = getMaxAmount(word.slice(1));\n word = word.slice(1);\n}\n\nwrite(begin + word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n // console.log(word)\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n var beginPart = getWordPart('begin', word, counter + 1);\n var endPart = getWordPart('end', word, counter + 1);\n\n if (beginPart && beginPart === endPart) {\n if (isSameSymbols(replaceParts(word, beginPart, '*'), '*')) {\n return -(counter + 1);\n }\n maxAmount = counter + 1;\n }\n }\n\n // console.log(maxAmount)\n return maxAmount;\n};\n\nvar isSameSymbols = function isSameSymbols(word, letter) {\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar replaceParts = function replaceParts(word, part, symbol) {\n\n for (var i = 0; i < word.length / symbol.length + 1; i++) {\n word = word.replace(part, symbol);\n }\n\n // console.log('replaceParts', word);\n return word;\n};\n\nvar addPart = function addPart(part, amount) {\n var result = '';\n\n while (amount > 0) {\n result += part;\n amount--;\n }\n\n return result;\n};\n\nvar isPalindrom = function isPalindrom(word) {\n\n if (word[0] === word[word.length - 1]) {\n if (word.length <= 1) return true;\n return isPalindrom(word.slice(1, word.length - 1));\n }\n\n return false;\n};\n\nvar partLength = 0;\nvar begin = '';\nvar h = word.length >= 6 && word[0] === word[word.length - 1] && !isSameSymbols(word, word[0]) && isPalindrom(word);\n\nif (h) {\n begin = word[0];\n partLength = getMaxAmount(word.slice(1));\n word = word.slice(1);\n} else {\n partLength = getMaxAmount(word);\n}\n\nwrite(begin + word + addPart(word.slice(partLength), amount - 1));"}, {"source_code": "'use strict';\n\nvar newLine = readline().split(' ').map(function (number) {\n return parseInt(number);\n});\n\nvar amount = newLine[1];\nvar word = readline();\n\nvar getWordPart = function getWordPart(mode, word, amount) {\n\n if (word.length / 2 >= amount - 0.5) {\n\n var part = mode === 'begin' ? word.slice(0, amount) : word.slice(-amount);\n return part;\n }\n\n return false;\n};\n\nvar getMaxAmount = function getMaxAmount(word) {\n\n var maxAmount = 0;\n\n for (var counter = 0; counter < word.length; counter++) {\n if (getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) && getWordPart('begin', word, counter + 1) === getWordPart('end', word, counter + 1)) {\n maxAmount = counter + 1;\n }\n }\n\n return maxAmount;\n};\n\nvar isSameLetters = function isSameLetters(word) {\n var letter = word[0];\n\n for (var i = 0; i < word.length; i++) {\n\n if (letter !== word[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nvar a = function a(part, amount) {\n var result = '';\n\n for (var i = 0; i < amount; i++) {\n result += part;\n }\n\n return result;\n};\n\nif (isSameLetters(word)) {\n write(word + a(word[0], amount - 1));\n} else {\n var partLength = getMaxAmount(word);\n write(word + a(word.slice(partLength), amount - 1));\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k, n))\n\nfunction output(string, k, n) {\n var p = n - 1;\n var l = 0;\n for (var i = p - 1; i >= 0; i--) {\n if (string[p] === string[i]) {\n p--;\n l++;\n } else if (string[n-1] === string[i] && string[p+1] === string[i+1]) {\n p = n - 2;\n l = 1;\n } else {\n p = n - 1;\n l = 0;\n }\n }\n\n for (var i = 1; i <= k - 1; i++) {\n for (var j = l; j < n; j++) {\n string += string[j];\n }\n }\n return string;\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k))\n\nfunction output(string, k) {\n var p = 0;\n var t = 0;\n for (var i = 1; i < string.length; i++) {\n if (string[p] !== string[i+p]) {\n p = 0;\n t = i;\n } else {\n p++;\n break;\n }\n }\n var u = string.length;\n if (t + 1 === u) {\n t = 0;\n }\n for (var o = 0; o < k - 1; o++) {\n for (var i = t; i < u; i++) {\n string = string + string[i];\n }\n }\n return string;\n}\n"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k))\n\nfunction output(string, k) {\n var p = 0;\n var t = 0;\n for (var i = 1; i < string.length; i++) {\n print (p, i, string[p], string[i])\n if (string[p] !== string[i]) {\n print (string[p-1], string[i])\n if (string[p-1] === string[i]) {\n p = 1;\n t = i - 1;\n } else {\n p = 0;\n t = i;\n }\n } else {\n p++;\n }\n }\n print(t)\n var u = string.length;\n for (var o = 0; o < k - 1; o++) {\n for (var i = u-t-1; i < u; i++) {\n string = string + string[i];\n }\n }\n return string;\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k))\n\nfunction output(string, k) {\n var p = 0;\n var t = 0;\n for (var i = 1; i < string.length; i++) {\n if (string[p] !== string[i]) {\n if (string[p-1] === string[i]) {\n p = 1;\n t = i - 1;\n } else {\n p = 0;\n t = i;\n }\n } else {\n p++;\n }\n }\n var u = string.length;\n for (var o = 0; o < k - 1; o++) {\n for (var i = u-t-1; i < u; i++) {\n string = string + string[i];\n }\n }\n return string;\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k))\n\nfunction output(string, k) {\n var p = 0;\n var t = 0;\n for (var i = 1; i < string.length; i++) {\n\n if (string[p] !== string[i+p]) {\n p = 0;\n t = i;\n } else {\n p++;\n }\n }\n var u = string.length;\n if (t + 1 === u) {\n t = 0;\n }\n for (var o = 0; o < k - 1; o++) {\n for (var i = t; i < u; i++) {\n string = string + string[i];\n }\n }\n return string;\n}\n"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\nvar string = readline();\n\nprint(output(string, k))\n\nfunction output(string, k) {\n var p = 0;\n var t = 0;\n for (var i = 1; i < string.length; i++) {\n if (string[p] !== string[i]) {\n p = 0;\n t = i;\n } else {\n p++;\n }\n }\n var u = string.length;\n for (var o = 0; o < k - 1; o++) {\n for (var i = u-t-1; i < u; i++) {\n string = string + string[i];\n }\n }\n return string;\n}\n"}, {"source_code": "var args = readline().split(' ');\nvar str = readline();\n\nargs = args.map((n) => parseInt(n, 10));\n\nvar len = args[0];\nvar repeat = args[1];\n\nvar i = 0;\nvar mid = parseInt(len / 2);\nwhile (i < mid) {\n if (str[i] !== str[len - i - 1]) {\n break;\n }\n i++;\n}\n\nconst res = []\nconst substr = str.substring(i);\n\nres.push(str.substring(0, i));\nfor (var j = 0;j < repeat;j++) {\n res.push(substr);\n}\n\nprint(res.join(''));\n"}, {"source_code": "var a = readline().split(\"\");\nvar n = a[1];\nvar str = readline();\nvar firstP = str.slice(1);\nvar secondP = str.slice(0, str.length - 1);\nvar i,\n bool = false;\nfor(i = 1; i <= str.length - 1; i++){\n if(firstP == secondP){\n bool = true;\n break;\n } else{\n firstP = firstP.slice(1);\n secondP = secondP.slice(0, secondP.length - 1);\n }\n}\nvar mainText;\nif(bool){\n mainText = str.slice(secondP.length);\n} else{\n mainText = str;\n}\nvar lastResult = str;\nfor(i = 1; i <= n-1; i++){\n lastResult += mainText;\n}\nprint(lastResult);"}, {"source_code": "function myFunc(t, n){\n\n var firstP = t.slice(1);\n var secondP = t.slice(0, t.length - 1);\n var i,\n bool = false;\n for(i = 1; i <= t.length - 1; i++){\n if(firstP == secondP){\n bool = true;\n break;\n } else{\n firstP = firstP.slice(1);\n secondP = secondP.slice(0, secondP.length - 1);\n }\n }\n var mainText;\n if(bool){\n mainText = t.slice(secondP.length);\n } else{\n mainText = t;\n }\n var lastResult = t;\n for(i = 1; i <= n-1; i++){\n lastResult += mainText;\n }\n return lastResult;\n}\nmyFunc(readline()); "}, {"source_code": "\nvar nk = readline();\nvar t = readline();\n\nvar n = nk.split(\" \")[0];\nvar k = nk.split(\" \")[1];\n\nvar equal = \"\";\nfor (var i = 0; i < Math.floor(t.length / 2); i ++) {\n var firstSub = t.substring(0, i + 1);\n var secondSub = t.substring(t.length - i - 1, t.length);\n if (firstSub === secondSub) {\n equal = firstSub;\n } else {\n break;\n }\n}\n\nvar result = t;\nfor (var i = 1; i < k; i ++) {\n if (equal !== \"\") {\n result += t.substring(equal.length, t.length);\n } else {\n result += t;\n }\n}\n\nwrite(result);\n\n"}], "src_uid": "34dd4c8400ff7a67f9feb1487f2669a6"} {"source_code": "// https://codeforces.com/problemset/problem/1620/A\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n if (Array.from(str).filter((x) => x === 'N').length === 1) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n", "positive_code": [{"source_code": "var t = parseInt(readline());\n\n\nwhile(t--) {\n\tvar s = readline();\n\tif(!/^E*NE*$/.test(s)) {\n\t\tprint(\"YES\");\n\t} else {\n\t\tprint(\"NO\");\n\t}\n}\n\n\n"}, {"source_code": "function solve(input) {\r\n function reducer(result, c) {\r\n return result += Number(c === 'N');\r\n }\r\n \r\n return input.split(\"\").reduce(reducer, 0) !== 1;\r\n}\r\n\r\nn = Number(readline());\r\n\r\nfor (var i = 0; i < n; i++) {\r\n print(solve(readline()) ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n while (t--) {\r\n var n = readline();\r\n var a = 0;\r\n\r\n for (var i = 0; i < n.length; i++) {\r\n if (n[i] === \"N\") {\r\n a++;\r\n }\r\n }\r\n\r\n if (a === 1) {\r\n print(\"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n }"}, {"source_code": "// https://codeforces.com/problemset/problem/1620/A\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n\n if (str.indexOf('N') === str.lastIndexOf('N') && str.indexOf('N') != -1) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var e = lines[j].split(''), en = 0\n for(l = 0; l < e.length; l++){\n if(e[l] == 'N'){\n en++\n }\n }\n if(en != 1){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n}); "}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split('');\n var a = 0;\n for(j = 0; j < k.length; j++){\n if(k[j] == 'N'){\n a++;\n }\n }\n if(a == 1){\n console.log('NO');\n }else{\n console.log('YES');\n }\n\t}\n});\n\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\ndata = data.replace(/\\s*$/, '')\r\n.split('\\n')\r\n.map(str => str.replace(/\\s*$/, ''));\r\n\r\nlet testCases = parseInt(data.shift());\r\n\r\nwhile(testCases--) {\r\n\r\nconst arr = readLine();\r\nconst res = a(arr);\r\nconsole.log(res)\r\n}\r\n});\r\n\r\nfunction readLine() { \r\nreturn data[currentLine++];\r\n}\r\n\r\nfunction a(s){\r\n let num = 0;\r\n for(let i = 0 ; i < s.length ; i++){\r\n if(s[i] == 'N') num++;\r\n }\r\n if(num == 1) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = a;\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// function foo(x) {\r\n// process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\r\n// console.log(x); // with auto '\\n' (newline)\r\n// }\r\n\r\nconst print = x => {\r\n process.stdout.write(x);\r\n process.stdout.write(\"\\n\");\r\n};\r\n\r\nfunction main() {\r\n const n = readline();\r\n\r\n for (let test = 0; test < n; test += 1) {\r\n const val = readline().split('');\r\n\r\n const m = val.length;\r\n \r\n const currentSet = Array.from({ length: val.length }, ((_, index) => index));\r\n\r\n const unite = pos => {\r\n if (val[pos] === 'N') {\r\n return;\r\n }\r\n const aSet = currentSet[pos];\r\n const bSet = currentSet[(pos + 1) % val.length];\r\n\r\n for (let i = 0; i < m; i += 1) {\r\n if (currentSet[i] === aSet) {\r\n currentSet[i] = bSet;\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < val.length; i += 1) {\r\n unite(i);\r\n }\r\n\r\n let answer = 'YES';\r\n\r\n for (let i = 0; i < val.length; i += 1) {\r\n if (val[i] === 'E' && currentSet[i] !== currentSet[(i + 1) % val.length]) {\r\n answer = 'NO';\r\n break;\r\n }\r\n if (val[i] === 'N' && currentSet[i] === currentSet[(i + 1) % val.length]) {\r\n answer = 'NO';\r\n break;\r\n }\r\n }\r\n\r\n print(answer);\r\n }\r\n\r\n}\r\n"}, {"source_code": "// tmplate input and output\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readints() {\r\n return readline().split(' ').map(num => parseInt(num));\r\n}\r\n\r\nfunction run_case() {\r\n S = readline();\r\n let countN = 0;\r\n \r\n for (c of S)\r\n countN += c == 'N'\r\n\r\n console.log(countN == 1 ? \"NO\" : \"YES\");\r\n}\r\n\r\nfunction main() {\r\n let tt = parseInt(readline());\r\n\r\n while (tt--)\r\n run_case();\r\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n\n //if all is equal except for the first/last one thats the only false scenario\n fileContents.forEach(scenario => {\n const countE = scenario.split(\"\").filter(l => l!=\"N\").length\n const countN = scenario.split(\"\").filter(l => l!=\"E\").length\n // console.log(\"scenario\", scenario, countE, countN)\n if(countN === 1){\n console.log(\"NO\")\n }else{\n console.log(\"YES\")\n }\n })\n\n\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let s = readline();\n let c = 0;\n for (let j = 0; j < s.length; j++) {\n c = s[j] === 'N' ? c + 1 : c;\n }\n console.log(c === 1 ? 'NO' : 'YES');\n }\n}"}, {"source_code": " var len = readline();\r\n var inputData=\"\";\r\n for(var i=0;i<+len;i++)\r\n {\r\n inputData = readline();\r\n if(inputData.split('N').length-1 ==1)\r\n print(\"NO\");\r\n else\r\n print(\"YES\");\r\n }\r\n"}, {"source_code": " var len = readline();\r\n var inputData=\"\";\r\n // let resultArr=[];\r\n for(var i=0;i<+len;i++)\r\n {\r\n inputData = readline();\r\n //if(inputData[0]==inputData[inputData.length-1])\r\n if(inputData.split('N').length-1 ==1)\r\n print(\"NO\");\r\n else\r\n print(\"YES\");\r\n }\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let s = readline();\r\n var c = 0;\r\n for(var i=0;i {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n if (str.indexOf('N') === str.lastIndexOf('N')) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1620/A\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n if (str[0] === str[str.length - 1]) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], en = 0\n for(j = 1; j <= n; j++){\n var e = lines[j].split('')\n for(l = 0; l < e.length; l++){\n if(e[l] == 'N'){\n en++\n }\n }\n if(en != 1){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n}); "}, {"source_code": " var len = readline();\r\n var inputData=\"\";\r\n// let resultArr=[];\r\nfor(var i=0;i<+len;i++)\r\n{\r\ninputData = readline();\r\n if(inputData[0]==inputData[inputData.length-1])\r\n print(\"YES\");\r\n else\r\n print(\"NO\");\r\n}\r\n//print(inputData);\r\n"}, {"source_code": " var len = readline();\r\n var inputData=\"\";\r\n// let resultArr=[];\r\nfor(var i=0;i<+len;i++)\r\n{\r\ninputData = readline();\r\n \r\n}\r\nprint(inputData);\r\n//inputData.push(readline());\r\n// if(inputData[0]==inputData[(inputData.length)-1])\r\n// print(\"YES\");\r\n// else\r\n// print(\"NO\");"}, {"source_code": " var len = readline();\r\n var inputData=[];\r\n// let resultArr=[];\r\nfor(var i=0;i<+len;i++)\r\n{\r\nprint(\"YES\");\r\n}\r\nprint(len);\r\n//inputData.push(readline());\r\n// if(inputData[0]==inputData[(inputData.length)-1])\r\n// print(\"YES\");\r\n// else\r\n// print(\"NO\");"}, {"source_code": " var len = readline();\r\n var inputData=[];\r\n // let resultArr=[];\r\n \r\n // for(let i=0;i{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let b: number[] = []\n// \n// let cnt = Array(n + 1).fill(0)\n// \n// let x = a[0]\n// \n// let allEq = true\n// \n// for (let i = 0; i < n; ++i) {\n// if (a[i] != x) {\n// allEq = false\n// }\n// }\n// \n// b.push(a[0])\n// \n// for (let i = 1; i < n; ++i) {\n// if (a[i] != a[i - 1]) {\n// b.push(a[i])\n// }\n// }\n// \n// // io.debug(b)\n// \n// let m = b.length\n// \n// for (let i = 0; i < m; ++i) {\n// cnt[b[i]]++\n// }\n// \n// if (allEq) {\n// io.puts(0)\n// return\n// }\n// \n// if (cnt[b[0]] == 1) {\n// io.puts(1)\n// return\n// }\n// \n// let best = n\n// \n// for (let i = 0; i < m; ++i) {\n// let candidate = cnt[b[i]] + 1\n// \n// if (b[0] == b[i]) {\n// candidate--\n// }\n// \n// if (b[m - 1] == b[i]) {\n// candidate--\n// }\n// \n// best = [best, candidate].min()\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let res = '';\n for(let i = 1; i <= n; i++){\n if(i !== n){\n res += ` ${i+1}`;\n }else{\n res += ` ${1}`;\n }\n }\n\n console.log(res.trim());\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = readline().split(' ');\n let a = new Array(n);\n let max = 0;\n for(let i = 0; i < n; i++)\n max = Math.max(max, pi(x[i]));\n let map = new Array(max+2);\n let rMap = new Array(max+2);\n\n for(let i = 0; i < n; i++){\n a[i] = pi(x[i]);\n if(map[a[i]] !== undefined){\n map[a[i]] += 1;\n rMap[a[i]] = i;\n }else{\n map[a[i]] = 1;\n rMap[a[i]] = i;\n }\n }\n\n let min = 99999999999;\n for(let i = 0; i < a.length; i++){\n if(map[a[i]] === 1){\n min = Math.min(min, a[i]);\n }\n }\n\n console.log(min === 99999999999 ? -1 : rMap[min]+1);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let max = 0;\n for(let i = 0; i < n; i++)\n max = Math.max(max, a[i]);\n let map = new Array(max + 2);\n //map.fill(0);\n for(let i = 0; i < n; i++){\n if(i === 0){\n map[a[i]] = 1;\n continue;\n }\n\n if(a[i] !== a[i-1]){\n if(map[a[i]] !== undefined){\n map[a[i]] += 1;\n }else{\n map[a[i]] = 1;\n }\n } \n }\n\n let min = 99999999;\n for(let i = 0; i < n; i++){\n if(map[a[i]] !== undefined){\n if(a[i] === a[0] && a[i] === a[n-1]){\n min = Math.min(min, map[a[i]]-1);\n }else if(a[i] === a[0] || a[i] === a[n-1]){\n min = Math.min(min, map[a[i]]);\n }else{\n min = Math.min(min, map[a[i]]+1);\n }\n }\n }\n\n console.log(min === 99999999 ? 0 : min);\n }\n}\n\nlet getFactors = (n) => {\n let i = 2;\n let res = [];\n while(i*i <= n){\n if(n%i === 0)\n res.push([i,n/i]);\n i++;\n }\n return res;\n}\n\nfunction D(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let dp = new Array(Math.floor(n+1));\n dp.fill(1);\n\n for(let i = 0; i < dp.length; i++){\n let f = getFactors(i);\n if(f.length !== 0){\n for(let j = 0; j < f.length; j++){\n if(f[j][1] % f[j][0] === 0)\n dp[i] = Math.max(dp[i], dp[f[j][0]]+dp[f[j][1]]);\n }\n }\n }\n \n let f = getFactors(n);\n let max = 1;\n if(f.length > 0){\n for(let i = 0; i < f.length; i++){\n if(f[i][1] % f[i][0] === 0)\n max = Math.max(max, dp[f[i][0]]+dp[f[i][1]]);\n }\n }\n console.log(max);\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const map = new Map();\n\n for (let i = 0; i < len; i++) {\n const n = arr[i];\n if (map.has(n)) {\n let { index, count, frequency } = { ...map.get(n) };\n map.set(n, { index: i, count, frequency: frequency + 1 });\n if (Math.abs(index - i) > 1) {\n map.set(n, { index: i, count: count + 1 });\n }\n } else {\n if (i > 0) {\n map.set(n, { count: 1, index: i, frequency: 1 });\n } else {\n map.set(n, { count: 0, index: i, frequency: 1 });\n }\n }\n }\n let [min, maxFrequence] = [Infinity, 0];\n for (let [key, obj] of map) {\n let { count, index, frequency } = obj;\n if (index !== len - 1) count++;\n min = Math.min(min, count);\n maxFrequence = Math.max(maxFrequence, frequency);\n }\n\n if (len === 1) console.log(0);\n else if (maxFrequence === 1) console.log(1);\n else console.log(min);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray(N);\n\t\tvar map = {};\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = [];\n\t\t\t}\n\t\t\tmap[list[j]].push(j);\n\t\t}\n\t\t\n\t\tvar keys = Object.keys(map);\n\t\tvar count = N + 1;\n\t\tif(keys.length == 1){\n\t\t\tcount = 0;\n\t\t}\n\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\tvar check = map[keys[j]];\n\t\t\tvar tmpCount = 0;\n\t\t\tif(check[0] != 0){\n\t\t\t\ttmpCount++;\n\t\t\t}\n\t\t\tif(check[check.length - 1] != N - 1){\n\t\t\t\ttmpCount++;\n\t\t\t}\n\t\t\tfor(var k = 0; k < check.length - 1; k++){\n\t\t\t\tif(check[k] + 1 != check[k + 1]){\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcount = Math.min(count, tmpCount);\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n \n while (i <= testCases) {\n const s = data[i + 1].trim().split(' ').map(Number);\n // let a = data[i].trim() * 1;\n const n = data[i] * 1;\n // const p = BigInt(s[0]);\n // const q = BigInt(s[1]);\n // s.sort((a, b) => b - a);\n let obj = {};\n // console.log(s);\n // let first = true;\n \n for (let j = 0; j < n; j += 1) {\n if (obj[s[j]]) obj[s[j]].push(j);\n else {\n obj[s[j]] = [j];\n // obj[s[j]]['count'] = 1;\n // obj[s[j]]['index'] = j + 1;\n }\n }\n \n let uq = false;\n let idx = Number.MAX_SAFE_INTEGER;\n // console.log(obj);\n \n for (let key in obj) {\n if (obj[key].length > 1) uq = true;\n if (obj[key].length === n) {idx = 0; break;}\n let temp = 0;\n if (obj[key][0] > 0) temp += 1;\n for (let j = 1; j < obj[key].length; j += 1) {\n if (obj[key][j] - obj[key][j - 1] > 1) temp += 1;\n }\n if (obj[key][obj[key].length - 1] < n - 1) temp += 1;\n idx = Math.min(idx, temp);\n }\n \n if (n === 1) console.log(0);\n else console.log(uq ? idx : 1);\n i += 2;\n }\n \n}"}, {"source_code": "\"use strict\";\n\n(() => {\n\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let curLine = 0, allLines = [];\n\n let nextLine = () => {\n if(curLine == allLines.length) throw new ReferenceError(\"No more input in the buffer\");\n return allLines[curLine++]\n };\n \n readline.on(\"line\", line => { allLines.push(line); });\n readline.on(\"close\", () => { main(nextLine) });\n\n})();\n\nfunction main(nextLine) {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n let ara = nextLine().split(\" \").map(x => Number(x));\n\n let ase = new Array(n+1).fill(false), cnt = new Array(n+1).fill(0);\n\n ara.forEach((element, index) => {\n ase[element] = true;\n if(index && ara[index] !== ara[index-1]) cnt[element]++;\n });\n\n let mn = n;\n for(let i = 1; i <= n; i++) {\n if(ase[i]) mn = Math.min(mn, cnt[i]+(ara[n-1] !== i));\n }\n\n console.log(mn);\n }\n}"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lines = [];\n\nrl.on('line', (data) => {\n lines.push(data);\n if(lines.length > 0 && 2 * parseInt(lines[0]) === lines.length - 1) {\n\trl.close();\n\tmain();\n }\n});\n\nasync function main() {\n let t = parseInt(lines[0]);\n for(let i = 1; i <= 2 * t; i += 2) {\n\tlet n = parseInt(lines[i]);\n\tconst arr = lines[i + 1].split(' ').map(x => parseInt(x));\n\n\tlet map = {};\n\tfor(const val of arr) {\n\t map[val] = 1;\n\t}\n\n\tfor(let j = 1; j < n; j++) {\n\t if(arr[j] != arr[j - 1])\n\t\tmap[arr[j]]++;\n\t}\n\n\tmap[arr[n - 1]]--;\n\tlet ans = 9999999;\n\tfor(const v in map) {\n\t ans = Math.min(ans, map[v]);\n\t}\n\n\tconsole.log(ans);\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const map = new Map();\n\n for (let i = 0; i < len; i++) {\n const n = arr[i];\n if (map.has(n)) {\n let { index, count, frequency } = { ...map.get(n) };\n map.set(n, { index: i, count, frequency: frequency + 1 });\n if (Math.abs(index - i) > 1) {\n map.set(n, { index: i, count: count + 1 });\n }\n } else {\n if (i > 0) {\n map.set(n, { count: 1, index: i, frequency: 1 });\n } else {\n map.set(n, { count: 0, index: i, frequency: 1 });\n }\n }\n }\n let [min, maxFrequence] = [Infinity, 0];\n for (let [key, obj] of map) {\n let { count, index, frequency } = obj;\n if (index !== len - 1) count++;\n min = Math.min(min, count);\n maxFrequence = Math.max(maxFrequence, frequency);\n }\n\n if (maxFrequence === 1) console.log(1);\n else console.log(min);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray(N);\n\t\tvar map = {};\n\t\tvar isZero = -1;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(j == 0){\n\t\t\t\tisZero = list[j];\n\t\t\t}\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = [j];\n\t\t\t}else{\n\t\t\t\tif(map[list[j]][map[list[j]].length - 1] == j - 1){\n\t\t\t\t\tmap[list[j]][map[list[j]].length - 1] = j;\n\t\t\t\t}else{\n\t\t\t\t\tmap[list[j]].push(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tvar keys = Object.keys(map);\n\t\tvar count = N + 1;\n\t\tif(keys.length == 1){\n\t\t\tcount = 0;\n\t\t}\n\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\tvar check = map[keys[j]];\n\t\t\tif(check.length == 1){\n\t\t\t\tif(check[0] == 0 || check[0] == N - 1){\n\t\t\t\t\tcount = Math.min(count, 1);\n\t\t\t\t}else{\n\t\t\t\t\tcount = Math.min(count, 2);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tvar tmpCount = 0;\n\t\t\t\tif(check[0] == 0 || isZero == keys[j]){\n\t\t\t\t\t\n\t\t\t\t}else{\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\tif(check[check.length - 1] != N - 1){\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\ttmpCount += check.length - 1;\n\t\t\t\tcount = Math.min(count, tmpCount);\n\t\t\t}\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray(N);\n\t\tvar map = {};\n\t\tvar isZero = -1;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(j == 0){\n\t\t\t\tisZero = list[j];\n\t\t\t}\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = [j];\n\t\t\t}else{\n\t\t\t\tif(map[list[j]][map[list[j]].length - 1] == j - 1){\n\t\t\t\t\tmap[list[j]][map[list[j]].length - 1] = j;\n\t\t\t\t}else{\n\t\t\t\t\tmap[list[j]].push(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tvar keys = Object.keys(map);\n\t\tvar count = N + 1;\n\t\tif(keys.length == 1){\n\t\t\tcount = 0;\n\t\t}\n\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\tvar check = map[keys[j]];\n\t\t\tif(check.length == 1){\n\t\t\t\tif(check[0] == 0 || check[0] == N - 1){\n\t\t\t\t\tcount = Math.min(count, 1);\n\t\t\t\t}else{\n\t\t\t\t\tcount = Math.min(count, 2);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tvar tmpCount = 0;\n\t\t\t\tif(check[0] == 0 || isZero != keys[j]){\n\t\t\t\t\t\n\t\t\t\t}else{\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\tif(check[check.length - 1] != N - 1){\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\ttmpCount += check.length - 1;\n\t\t\t\tcount = Math.min(count, tmpCount);\n\t\t\t}\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray(N);\n\t\tvar map = {};\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = [j];\n\t\t\t}else{\n\t\t\t\tif(map[list[j]][map[list[j]].length - 1] == j - 1){\n\t\t\t\t\tmap[list[j]][map[list[j]].length - 1] = j;\n\t\t\t\t}else{\n\t\t\t\t\tmap[list[j]].push(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tvar keys = Object.keys(map);\n\t\tvar count = N + 1;\n\t\tif(keys.length == 1){\n\t\t\tcount = 0;\n\t\t}\n\t\tfor(var j = 0; j < keys.length; j++){\n\t\t\tvar check = map[keys[j]];\n\t\t\tif(check.length == 1){\n\t\t\t\tif(check[0] == 0 || check[0] == N - 1){\n\t\t\t\t\tcount = Math.min(count, 1);\n\t\t\t\t}else{\n\t\t\t\t\tcount = Math.min(count, 2);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tvar tmpCount = 0;\n\t\t\t\tif(check[0] != 0){\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\tif(check[check.length - 1] != N - 1){\n\t\t\t\t\ttmpCount++;\n\t\t\t\t}\n\t\t\t\ttmpCount += check.length - 1;\n\t\t\t\tcount = Math.min(count, tmpCount);\n\t\t\t}\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n \n while (i <= testCases) {\n const s = data[i + 1].trim().split(' ').map(Number);\n // let a = data[i].trim() * 1;\n const n = data[i] * 1;\n // const p = BigInt(s[0]);\n // const q = BigInt(s[1]);\n // s.sort((a, b) => b - a);\n let obj = {};\n // console.log(s);\n // let first = true;\n \n for (let j = 0; j < n; j += 1) {\n if (obj[s[j]]) obj[s[j]].push(j);\n else {\n obj[s[j]] = [j];\n // obj[s[j]]['count'] = 1;\n // obj[s[j]]['index'] = j + 1;\n }\n }\n \n let uq = false;\n let idx = Number.MAX_SAFE_INTEGER;\n // console.log(obj);\n \n for (let key in obj) {\n if (obj[key].length > 1) uq = true;\n if (obj[key].length === n) {idx = 0; break;}\n let temp = 0;\n if (obj[key][0] > 0) temp += 1;\n for (let j = 1; j < obj[key].length; j += 1) {\n if (obj[key][j] - obj[key][j - 1] > 1) temp += 1;\n }\n if (obj[key][obj[key].length - 1] < n - 1) temp += 1;\n idx = Math.min(idx, temp);\n }\n \n console.log(uq ? idx : 1);\n i += 2;\n }\n \n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let b: number[] = []\n// \n// let cnt = Array(n + 1).fill(0)\n// \n// let x = a[0]\n// \n// let allEq = true\n// \n// for (let i = 0; i < n; ++i) {\n// if (a[i] != x) {\n// allEq = false\n// }\n// }\n// \n// b.push(a[0])\n// \n// for (let i = 1; i < n; ++i) {\n// if (b[i] != b[i - 1]) {\n// b.push(a[i])\n// }\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// cnt[b[i]]++\n// }\n// \n// if (allEq) {\n// io.puts(0)\n// return\n// }\n// \n// if (cnt[b[0]] == 1) {\n// io.puts(1)\n// return\n// }\n// \n// let best = n\n// \n// let m = b.length\n// \n// for (let i = 0; i < n; ++i) {\n// let candidate = cnt[b[i]] + 1\n// \n// if (b[0] == b[i]) {\n// candidate--\n// }\n// \n// if (b[m - 1] == b[i]) {\n// candidate--\n// }\n// \n// best = [best, candidate].min()\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "080eb61cbc4b0ffcbab10b86918f70fe"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, x, a)=>{\n let count = 0;\n\n let min = Infinity;\n let max = -1;\n let minPos = -1;\n let maxPos = -1;\n\n for (let i = 0; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n minPos = i;\n }\n if (a[i] > max) {\n max = a[i];\n maxPos = i;\n }\n if (i === 0) continue;\n count += Math.abs(a[i] - a[i - 1]);\n }\n\n // console.log('DEBUG count', count);\n\n let minLabel = undefined;\n\n let mins = [Infinity, Infinity, Infinity];\n\n if (min > 1) {\n if (minPos === 0) {\n count += min - 1;\n minLabel = 'left';\n } else if (minPos === n - 1) {\n count += min - 1;\n minLabel = 'right';\n } else {\n mins[1] = 2 * (min - 1);\n mins[0] = a[0] - 1;\n mins[2] = a[n - 1] - 1;\n minLabel = 'mid';\n }\n }\n\n // console.log('DEBUG count', count);\n\n let maxLabel = undefined;\n let maxs = [Infinity, Infinity, Infinity];\n\n\n if (max < x) {\n if (maxPos === 0) {\n count += x - max;\n maxLabel = 'left';\n } else if (maxPos === n - 1) {\n count += x - max;\n maxLabel = 'right';\n } else {\n maxLabel = 'mid';\n maxs[1] = 2 * (x - max);\n maxs[0] = x - a[0];\n maxs[2] = x - a[n - 1];\n \n // if (leftPlacement < maxRes && minLabel !== 'left') {\n // maxRes = leftPlacement;\n // }\n // if (rightPlacement < maxRes && minLabel !== 'right') {\n // maxRes = rightPlacement;\n // }\n // count += maxRes;\n }\n }\n\n if (minLabel !== 'mid' && maxLabel !== 'mid') {\n return count;\n } else if (minLabel === 'mid' && maxLabel !== 'mid') {\n let minMin = mins[1];\n if (maxLabel !== 'left' && mins[0] < minMin) {\n minMin = mins[0];\n }\n if (maxLabel !== 'right' && mins[2] < minMin) {\n minMin = mins[2];\n }\n count += minMin;\n } else if (maxLabel === 'mid' && minLabel !== 'mid') {\n let maxMin = maxs[1];\n if (minLabel !== 'left' && maxs[0] < maxMin) {\n maxMin = maxs[0];\n }\n if (minLabel !== 'right' && maxs[2] < maxMin) {\n maxMin = maxs[2];\n }\n count += maxMin;\n } else {\n let minRes = Infinity;\n\n for (let i = 0; i < 3; i++) {\n for (let j = 0; j < 3; j++) {\n if (i === j && i !== 1) continue;\n minRes = Math.min(minRes, mins[i] + maxs[j]);\n }\n }\n count += minRes;\n }\n\n // console.log('DEBUG count', count);\n\n return count;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, x] = ra();\n let a = ra();\n console.log(`${calc(n, x, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, x, a) {\r\n if (n === 1) {\r\n console.log(Math.max(x, a[0]) - 1);\r\n return;\r\n }\r\n let min = 1,\r\n max = x,\r\n sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Math.abs(a[i] - a[i - 1]);\r\n }\r\n let res = Infinity;\r\n for (let num of [min, max]) {\r\n res = Infinity;\r\n let t = 0;\r\n for (let i = 0; i <= a.length; i++) {\r\n let ans = 0;\r\n if (i === 0) {\r\n ans = sum + Math.abs(num - a[0]);\r\n } else if (i === a.length) {\r\n ans = sum + Math.abs(num - a[a.length - 1]);\r\n } else {\r\n ans = sum - Math.abs(a[i] - a[i - 1]) + Math.abs(a[i] - num) + Math.abs(a[i - 1] - num);\r\n }\r\n if (ans < res) {\r\n res = ans;\r\n t = i;\r\n }\r\n }\r\n a.splice(t, 0, num);\r\n sum = res;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, x] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, x, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, x] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n x,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, x, a } = testCase;\n // console.log(n, x, a);\n\n let result = a.reduce(\n (acc, val, i) => (i == 0 ? 0 : acc + Math.abs(val - a[i - 1])),\n 0\n );\n\n // console.log(\"sum\", result);\n\n const mini = Math.min(...a);\n const maxi = Math.max(...a);\n // console.log(mini, maxi);\n\n const miniRange = mini > 1 ? [1, Math.min(x, mini - 1)] : undefined;\n const maxiRange = maxi < x ? [maxi + 1, x] : undefined;\n\n // console.log(miniRange, maxiRange);\n\n if (miniRange) {\n const possibleSums = [];\n possibleSums.push(\n Math.max(Math.abs(a[0] - miniRange[0]), Math.abs(a[0] - miniRange[1]))\n );\n possibleSums.push(\n Math.max(\n Math.abs(a[n - 1] - miniRange[0]),\n Math.abs(a[n - 1] - miniRange[1])\n )\n );\n possibleSums.push((mini - miniRange[0]) * 2);\n // console.log(\"mini possibleSums\", possibleSums);\n result += Math.min(...possibleSums);\n }\n\n if (maxiRange) {\n const possibleSums = [];\n possibleSums.push(\n Math.max(Math.abs(a[0] - maxiRange[0]), Math.abs(a[0] - maxiRange[1]))\n );\n possibleSums.push(\n Math.max(\n Math.abs(a[n - 1] - maxiRange[0]),\n Math.abs(a[n - 1] - maxiRange[1])\n )\n );\n possibleSums.push((maxiRange[1] - maxi) * 2);\n // console.log(\"maxi possibleSums\", possibleSums);\n result += Math.min(...possibleSums);\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, insert] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, insert, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, insert, arr) {\n let min = 1\n let max = insert\n let ans = 0\n let pmin = Math.abs(min - arr[0])\n let pmax = Math.abs(max - arr[0])\n let vmin = Infinity\n let vmax = -Infinity\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n vmin = Math.min(vmin, x)\n vmax = Math.max(vmax, x)\n // after i\n const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0\n ans += now\n const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)\n const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)\n pmin = Math.min(pmin, cmin - now)\n pmax = Math.min(pmax, cmax - now)\n }\n // console.log(ans, pmin, pmax)\n if (max > vmax) ans += pmax\n if (min < vmin) ans += pmin\n return ans\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, insert] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, insert, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, insert, arr) {\n let min = 1\n let max = insert\n let ans = 0\n let pmin = Math.abs(min - arr[0])\n let pmax = Math.abs(max - arr[0])\n let vmin = Infinity\n let vmax = -Infinity\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n vmin = Math.min(vmin, x)\n vmax = Math.max(vmax, x)\n // after i\n const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0\n ans += now\n const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)\n const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)\n pmin = Math.min(pmin, cmin - now)\n pmax = Math.min(pmax, cmax - now)\n }\n // console.log(ans, pmin, pmax)\n if (max <= vmax) {\n return ans + pmin\n } else if (min >= vmin) {\n return ans + pmax\n } else {\n return ans\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, insert] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, insert, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, insert, arr) {\n let min = 1\n let max = insert\n let ans = 0\n let pmin = Math.abs(min - arr[0])\n let pmax = Math.abs(max - arr[0])\n for (let i = 0; i < arr.length; i++) {\n // after i\n const x = arr[i]\n const now = i + 1 < n ? Math.abs(x - arr[i + 1]) : 0\n ans += now\n const cmin = Math.abs(min - x) + (i + 1 < n ? Math.abs(min - arr[i + 1]) : 0)\n const cmax = Math.abs(max - x) + (i + 1 < n ? Math.abs(max - arr[i + 1]) : 0)\n pmin = Math.min(pmin, cmin - now)\n pmax = Math.min(pmax, cmax - now)\n // console.log(ans, pmin, pmax)\n }\n return n === 1 ? ans + pmin : ans + pmin + pmax\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, x, a)=>{\n let count = 0;\n\n let min = Infinity;\n let max = -1;\n let minPos = -1;\n let maxPos = -1;\n\n for (let i = 0; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n minPos = i;\n }\n if (a[i] > max) {\n max = a[i];\n maxPos = i;\n }\n if (i === 0) continue;\n count += Math.abs(a[i] - a[i - 1]);\n }\n\n // console.log('DEBUG count', count);\n\n let minLabel = undefined;\n\n if (min > 1) {\n if (minPos === 0) {\n count += min - 1;\n minLabel = 'left';\n } else if (minPos === n - 1) {\n count += min - 1;\n minLabel = 'right';\n } else {\n count += 2 * (min - 1);\n minLabel = 'mid';\n }\n }\n\n // console.log('DEBUG count', count);\n\n\n if (max < x) {\n if (maxPos === 0) {\n count += x - max;\n } else if (maxPos === n - 1) {\n count += x - max;\n } else {\n let maxRes = 2 * (x - max);\n let leftPlacement = x - a[0];\n let rightPlacement = x - a[n - 1];\n \n if (leftPlacement < maxRes && minLabel !== 'left') {\n maxRes = leftPlacement;\n }\n if (rightPlacement < maxRes && minLabel !== 'right') {\n maxRes = rightPlacement;\n }\n count += maxRes;\n }\n }\n\n // console.log('DEBUG count', count);\n\n return count;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, x] = ra();\n let a = ra();\n console.log(`${calc(n, x, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, x, a) {\r\n if (n === 1) {\r\n console.log(Math.max(x, a[0]) - 1);\r\n return;\r\n }\r\n let min = 1,\r\n max = x,\r\n sum = 0;\r\n for (let i = 1; i < n; i++) {\r\n sum += Math.abs(a[i] - a[i - 1]);\r\n }\r\n let res = Infinity;\r\n for (let num of [min, max]) {\r\n res = Infinity;\r\n for (let i = 0; i <= n; i++) {\r\n if (i === 0) {\r\n res = Math.min(res, sum + Math.abs(num - a[0]));\r\n } else if (i === n) {\r\n res = Math.min(res, sum + Math.abs(num - a[n - 1]));\r\n } else {\r\n res = Math.min(res, sum - Math.abs(a[i] - a[i - 1]) + Math.abs(a[i] - num) + Math.abs(a[i - 1] - num));\r\n }\r\n }\r\n sum = res;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, x] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, x, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "0efa3ce46108ca604d95e15d02757b44"} {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var n = readline();\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n print(arr[0]);\r\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n\r\nvar n = parseInt(readline());\r\n\r\nvar ar =[];\r\nvar i;\r\n\r\nar= readline().split(' ').map(x => parseInt(x));\r\n \r\n \r\n\r\nprint(ar[ar.length-1]);\r\n\r\n\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n readline();\r\n var caseArray = readline().split(\" \");\r\n print(caseArray[0]);\r\n}"}, {"source_code": "\"use strict\";\r\nfunction toInt(x) {\r\n return parseInt(x);\r\n}\r\n\r\nlet t = parseInt(readline());\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let a = readline().split(' ').map(toInt);\r\n outer: for (let ind = 0; ind < n; ind++) {\r\n \tlet xor = 0;\r\n \tfor (let i = 0; i < n; i++) {\r\n \t\tif (i != ind) xor ^= a[i];\r\n \t}\r\n \tif (xor == a[ind]) {\r\n \t\tprint(xor);\r\n \t break outer;\t\r\n \t}\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var t1 = readline();\r\n var t2 = readline().split(' ').map((t) => +t);\r\n print(ShuffleArray(t2))\r\n \r\n}\r\n \r\nfunction ShuffleArray(arr){\r\n\r\n function checkArr(idx){\r\n // var shuff = \r\n\r\n var init = 0;\r\n for(var i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n let prefix = Array(n).fill(0);\r\n let suffix = Array(n).fill(0);\r\n\r\n for (let j = 1; j < n; j++) {\r\n prefix[j] = prefix[j - 1] ^ arr[j - 1];\r\n suffix[n - 1 - j] = suffix[n - j] ^ arr[n - j];\r\n }\r\n\r\n const result = arr.find((value, index) => prefix[index] ^ suffix[index] === value);\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = parseInt(readline());\r\n let num = readline().split(\" \").map(Number);\r\n print(num[0]);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n return a[0];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(x => parseInt(x));\r\n print(arr[0]);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(x => parseInt(x));\r\n print(arr[0]);\r\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nwhile(t--){\r\n\r\nvar n = parseInt(readline());\r\n\r\nvar x ;\r\nvar i= 0;\r\n\r\nfor( i=0;i str.split(' ').map(Number))\n l += n\n var edges = lines.slice(l, l + n - 1).map(str => str.split(' ').map(Number))\n l += n - 1\n console.log(solve(n, ranges, edges));\n }\n});\n\nfunction solve(n, ranges, edges) {\n const adj = {}\n edges.forEach(([a, b]) => {\n a--\n b--\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n\n const dp = [[], []]\n dfs(dp, adj, 0, -1, ranges)\n return Math.max(dp[0][0], dp[1][0])\n}\n\nfunction dfs(dp, adj, u, p, ranges) {\n // dp[0][u] = max sum if `u` select min `au`\n // dp[1][u] = max sum if `u` select max `au`\n dp[0][u] = dp[1][u] = 0\n adj[u].forEach(v => {\n if (v === p) return\n\n dfs(dp, adj, v, u, ranges)\n dp[0][u] += Math.max(\n dp[0][v] + Math.abs(ranges[u][0] - ranges[v][0]),\n dp[1][v] + Math.abs(ranges[u][0] - ranges[v][1])\n )\n dp[1][u] += Math.max(\n dp[0][v] + Math.abs(ranges[u][1] - ranges[v][0]),\n dp[1][v] + Math.abs(ranges[u][1] - ranges[v][1])\n )\n })\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nconst integerRegex = /-?\\d+/g;\r\nconst decimalRegex = /-?\\d+(?:\\.\\d+)?/g;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n readIntegersOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(integerRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n readNumsOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(decimalRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nconst MAX_N = 1e5 + 10;\r\nconst dp = new Array(MAX_N);\r\nfor (let i = 0; i < dp.length; ++i)\r\n dp[i] = new Array(2);\r\nfunction solve(N, vertexes, G) {\r\n for (let i = 0; i < N; ++i)\r\n dp[i][0] = dp[i][1] = -1;\r\n return Math.max(dfs(-1, 0, 0), dfs(-1, 0, 1));\r\n function dfs(p, u, dir) {\r\n if (dp[u][dir] !== -1)\r\n return dp[u][dir];\r\n let answer = 0;\r\n const value = vertexes[u][dir];\r\n for (const v of G[u]) {\r\n if (v === p)\r\n continue;\r\n answer += Math.max(dfs(u, v, 0) + Math.abs(value - vertexes[v][0]), dfs(u, v, 1) + Math.abs(value - vertexes[v][1]));\r\n }\r\n dp[u][dir] = answer;\r\n return answer;\r\n }\r\n}\r\nconst vertexes = new Array(MAX_N);\r\nconst G = new Array(MAX_N);\r\n__main__(function (io) {\r\n const T = Number(io.readLine());\r\n for (let kase = 1; kase <= T; ++kase) {\r\n const N = Number(io.readLine());\r\n for (let i = 0; i < N; ++i) {\r\n vertexes[i] = io.readIntegersOfLine();\r\n G[i] = [];\r\n }\r\n for (let i = 1; i < N; ++i) {\r\n const [u, v] = io.readIntegersOfLine();\r\n G[u - 1].push(v - 1);\r\n G[v - 1].push(u - 1);\r\n }\r\n const answer = solve(N, vertexes, G);\r\n io.print('' + answer + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nlet n, g, l, h;\r\nlet dp;\r\n\r\nfunction dfs (u=0, p=-1) {\r\n\tfor (const v of g[u]) {\r\n\t\tif (v == p) continue;\r\n\t\tdfs(v, u);\r\n\t\tdp[u][0] += Math.max(dp[v][0] + Math.abs(l[u] - l[v]), dp[v][1] + Math.abs(l[u] - h[v]));\r\n\t\tdp[u][1] += Math.max(dp[v][0] + Math.abs(h[u] - l[v]), dp[v][1] + Math.abs(h[u] - h[v]));\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tn = rn();\r\n\t\tl = [], h = [];\r\n\t\tg = Array.from(Array(n), _ => []);\r\n\t\tfor (let i = 0; i < n; i++) [l[i], h[i]] = rna();\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tlet [u, v] = rna(); u--, v--;\r\n\t\t\tg[u].push(v);\r\n\t\t\tg[v].push(u);\r\n\t\t}\r\n\r\n\t\tdp = Array.from(Array(n), _ => [0, 0]);\r\n\t\tdfs();\r\n\r\n\t\tconsole.log(Math.max(dp[0][0], dp[0][1]));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "a5063294f814f359f7ab6b7b801eaf3e"} {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c ;\n res = 0 ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n if( this.arr[ 0 ] == 1 ) {\n res = -1 ;\n }\n else {\n res = 1 ;\n }\n print( res ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;", "positive_code": [{"source_code": "var n = readline();\nvar numbers = readline().split(' ');\nif(numbers.indexOf('1') == -1) {\n print(1);\n} else {\n print(-1);\n}"}, {"source_code": "n = readline();\nstr = readline().split(' ').map(Number);\n\nfor (var i = 0; i < str.length - 1; i++) {\n\tfor (var j = i + 1; j < str.length; j++) {\n\t\tif (str[i] > str[j]) {\n\t\t\tvar temp = str[i];\n\t\t\tstr[i] = str[j];\n\t\t\tstr[j] = temp;\n\t\t};\n\t};\n};\n\nif (str[0] !== 1) {\n\tprint(1);\n} else {\n\tprint(-1);\n};\n\n"}, {"source_code": "function sorting(a,n){\n\tvar buf;\n\tfor(i=0; i<= +(n-2); i++){\n\t\tfor(x=i+1; x<=+(n-1); x++){\n\t\t\tif(+a[i]>+a[x]){\n\t\t\t\tbuf = a[i];\n\t\t\t\ta[i] = a[x];\n\t\t\t\ta[x] = buf;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction unluckySum(a,n){\n\tif(+a[0] == 1){\n\t\twrite(\"-1\");\n\t}\n\telse{\n\t\twrite(\"1\");\n\t}\n}\n\nvar n = readline(), a = readline().split(\" \");\nsorting(a,n);\nunluckySum(a,n);"}, {"source_code": "n=readline().split(\" \");\nar=readline().split(\" \");\na=1\nfor(i=0;i a[i-1]) {\n inc[i] = inc[i-1]+1;\n } else {\n inc[i] = 1;\n }\n}\n\ndec[n-1] = 1;\nfor (i = n-2; i >= 0; i--) {\n if (a[i] < a[i+1]) {\n dec[i] = dec[i+1]+1;\n } else {\n dec[i] = 1;\n }\n}\n\nvar max = n;\nif (n > 2) {\n max = Math.max(dec[1]+1, inc[n-2]+1);\n}\n\nfor (i = 1; i < n-1; i++) {\n if (a[i] <= a[i-1] || a[i] >= a[i+1]) { // si hay un hoyo\n if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio\n max = Math.max(max, inc[i-1] + dec[i+1] + 1);\n } else { // si el cambio solamente agrega un elemento a las series originales\n max = Math.max(max, inc[i-1]+1, dec[i+1]+1);\n }\n }\n}\n\nprint(max);", "positive_code": [{"source_code": "var n = readline()*1;\nvar arr = readline().split(\" \");\n//=====================================================\nvar seqIni = [];\nvar seqLen = [];\n \nvar ini = -1;\nvar len = 1;\n \nfor (var i = 0; i < arr.length-1; i++) {\n if(arr[i]*1 < arr[i+1]*1){\n if(ini == -1){\n ini = i;\n }\n len++;\n }else{\n if(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n ini = -1;\n len = 1;\n }\n }\n}\nif(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n}\n/*\nconsole.log(arr);\nconsole.log(seqIni);\nconsole.log(seqLen);\n*/\n//===================================================\nif(arr.length == 1){\n var mayor = 1;\n}else{\n var mayor = 2; \n\n for (var i = 0; i < arr.length-2; i++) {\n if(arr[i]*1+2 <= arr[i+2]*1 && ((arr[i]*1 >= arr[i+1]*1) || (arr[i+1]*1 >= arr[i+2]*1))){\n var l= buscar(i,i+1)+1+buscar(i+2,i+1);\n if(l > mayor){\n mayor = l;\n }\n }\n }\n var r= buscar(0,0)+1;\n if(r > mayor){\n mayor = r;\n }\n r= buscar(arr.length-1,arr.length-1)+1;\n if(r > mayor){\n mayor = r;\n }\n \n for (var i = 0; i < seqIni.length; i++) {\n if(seqLen[i]+1 <= arr.length){\n if(seqLen[i]+1 > mayor){\n mayor = seqLen[i]+1;\n } \n }else{\n if(seqLen[i] > mayor){\n mayor = seqLen[i];\n }\n }\n }\n\n}\n\nfunction buscar(i,elMalo){\n for(var j=0; j< seqIni.length; j++){\n if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){\n //console.log(i,elMalo);\n if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){\n return seqLen[j]-1;\n }\n return seqLen[j];\n }\n }\n return 1;\n}\n\nprint(mayor);"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tl.forEach(function (e) {\n\t\t\tk.push(s.splice(0, e));\n\t\t});\n\n\t\tk.push([]); k.unshift([]);\n\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < l.length + 1; i++) {\n\t\t\tvar a = k[i], b = k[i + 1];\n\n\t\t\tif (a.length === 0 || b.length === 0) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (a.length === 1 || b.length === 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else\n\t\t\tif (true) {\n\t\t\t\tmax = Math.max(max, a.length + 1, b.length + 1);\n\t\t\t}\n\t\t}\n\n\t\treturn max;\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tdata = tokenizeIntegers(readline()),\n\t\tincreasing = {},\n\t\tstart = 0, starts = [];\n\twhile (start < n) {\n\t\tvar seek = start+1;\n\t\twhile (seek < n && data[seek] > data[seek-1]) {\n\t\t\t++seek;\n\t\t}\n\t\tincreasing[start] = seek-start;\n\t\tstarts.push(start);\n\t\tstart = seek;\n\t}\n\tvar max = increasing[starts[0]];\n\tif (starts.length != 1) {\n\t\tmax = Math.max(max, increasing[starts[starts.length-1]]+1);\n\t}\n\tfor (var i = 1; i < starts.length; ++i) {\n\t\tvar hinge = starts[i],\n\t\t\tprefix = increasing[starts[i-1]],\n\t\t\tsuffix = increasing[starts[i]];\n\t\tif (suffix != 1 && (data[hinge-1]+1 < data[hinge+1] ||\n\t\t\t\t\tdata[hinge-2]+1 < data[hinge])) {\n\t\t\tmax = Math.max(max, prefix+suffix);\n\t\t} else {\n\t\t\tmax = Math.max(max, prefix+1);\n\t\t}\n\t}\n\tprint(max);\n}\n\nmain();\n"}, {"source_code": "function main() {\n var n = Number(readline());\n var data = readline().split(' ').map(Number);\n \n var l = [1];\n for(var i=1;i data[i-1]){\n l[i] = l[i-1] + 1;\n } else {\n l[i] = 1;\n }\n }\n var r = [];\n r[n-1] = 1;\n for(var i=n-2;i>=0;i--){\n if(data[i] < data[i+1]){\n r[i] = r[i+1] + 1;\n } else {\n r[i] = 1;\n }\n }\n var max = Math.max(...r);\n if(max == data.length){\n return print(max);\n } else {\n max++;\n }\n for(var i=1;i data[seek-1]) {\n\t\t\t++seek;\n\t\t}\n\t\tincreasing[start] = seek-start;\n\t\tstarts.push(start);\n\t\tstart = seek;\n\t}\n\tvar max = increasing[starts[0]];\n\tfor (var i = 1; i < starts.length; ++i) {\n\t\tvar hinge = starts[i],\n\t\t\tprefix = increasing[starts[i-1]],\n\t\t\tsuffix = increasing[starts[i]];\n\t\tif (suffix != 1 && data[hinge-1]+1 < data[hinge+1]) {\n\t\t\tmax = Math.max(max, prefix+suffix);\n\t\t} else {\n\t\t\tmax = Math.max(max, prefix+1);\n\t\t}\n\t}\n\tprint(max);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tdata = tokenizeIntegers(readline()),\n\t\tincreasing = {},\n\t\tstart = 0, starts = [];\n\twhile (start < n) {\n\t\tvar seek = start+1;\n\t\twhile (seek < n && data[seek] > data[seek-1]) {\n\t\t\t++seek;\n\t\t}\n\t\tincreasing[start] = seek-start;\n\t\tstarts.push(start);\n\t\tstart = seek;\n\t}\n\tvar max = increasing[starts[0]];\n\tfor (var i = 1; i < starts.length; ++i) {\n\t\tvar hinge = starts[i],\n\t\t\tprefix = increasing[starts[i-1]],\n\t\t\tsuffix = increasing[starts[i]];\n\t\tif (suffix != 1 && data[hinge]+1 < data[hinge+1]) {\n\t\t\tmax = Math.max(max, prefix+suffix);\n\t\t} else {\n\t\t\tmax = Math.max(max, prefix+1);\n\t\t}\n\t}\n\tprint(max);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tdata = tokenizeIntegers(readline()),\n\t\tincreasing = {},\n\t\tstart = 0, starts = [];\n\twhile (start < n) {\n\t\tvar seek = start+1;\n\t\twhile (seek < n && data[seek] > data[seek-1]) {\n\t\t\t++seek;\n\t\t}\n\t\tincreasing[start] = seek-start;\n\t\tstarts.push(start);\n\t\tstart = seek;\n\t}\n\tvar max = increasing[starts[0]];\n\tif (starts.length > 1) {\n\t\tmax = Math.max(max, 1+increasing[starts[starts.length-1]]);\n\t}\n\tfor (var i = 1; i < starts.length; ++i) {\n\t\tvar hinge = starts[i],\n\t\t\tprefix = increasing[starts[i-1]],\n\t\t\tsuffix = increasing[starts[i]];\n\t\tif (suffix != 1 && data[hinge-1]+1 < data[hinge+1]) {\n\t\t\tmax = Math.max(max, prefix+suffix);\n\t\t} else {\n\t\t\tmax = Math.max(max, prefix+1);\n\t\t}\n\t}\n\tprint(max);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tdata = tokenizeIntegers(readline()),\n\t\tincreasing = {},\n\t\tstart = 0, starts = [];\n\twhile (start < n) {\n\t\tvar seek = start+1;\n\t\twhile (seek < n && data[seek] > data[seek-1]) {\n\t\t\t++seek;\n\t\t}\n\t\tincreasing[start] = seek-start;\n\t\tstarts.push(start);\n\t\tstart = seek;\n\t}\n\tvar max = increasing[starts[0]];\n\tfor (var i = 1; i < starts.length; ++i) {\n\t\tvar hinge = starts[i],\n\t\t\tprefix = increasing[starts[i-1]],\n\t\t\tsuffix = increasing[starts[i]];\n\t\tif (suffix != 1 && (data[hinge-1]+1 < data[hinge+1] ||\n\t\t\t\t\tdata[hinge-2]+1 < data[hinge])) {\n\t\t\tmax = Math.max(max, prefix+suffix);\n\t\t} else {\n\t\t\tmax = Math.max(max, prefix+1);\n\t\t}\n\t}\n\tprint(max);\n}\n\nmain();\n"}, {"source_code": "var n = readline()*1;\nvar arr = readline().split(\" \");\n//=====================================================\nvar seqIni = [];\nvar seqLen = [];\n \nvar ini = -1;\nvar len = 1;\n \nfor (var i = 0; i < arr.length-1; i++) {\n if(arr[i]*1 < arr[i+1]*1){\n if(ini == -1){\n ini = i;\n }\n len++;\n }else{\n if(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n ini = -1;\n len = 1;\n }\n }\n}\nif(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n}\n/*\nconsole.log(arr);\nconsole.log(seqIni);\nconsole.log(seqLen);\n*/\n//===================================================\nif(arr.length == 1){\n var mayor = 1;\n}else{\n var mayor = 2; \n\n for (var i = 0; i < arr.length-2; i++) {\n if(arr[i]*1+2 <= arr[i+2]*1 && (arr[i]*1 >= arr[i+1]*1) || (arr[i+1]*1 >= arr[i+2]*1)){\n var l= buscar(i,i+1)+1+buscar(i+2,i+1);\n if(l > mayor){\n mayor = l;\n }\n }\n }\n \n var r= buscar(0,0)+1;\n if(r > mayor){\n mayor = r;\n }\n r= buscar(arr.length-1,arr.length-1)+1;\n if(r > mayor){\n mayor = r;\n }\n \n for (var i = 0; i < seqIni.length; i++) {\n if(seqLen[i]+1 <= arr.length){\n if(seqLen[i]+1 > mayor){\n mayor = seqLen[i]+1;\n } \n }else{\n if(seqLen[i] > mayor){\n mayor = seqLen[i];\n }\n }\n }\n\n}\n\nfunction buscar(i,elMalo){\n for(var j=0; j< seqIni.length; j++){\n if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){\n if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){\n return seqLen[j]-1; \n }\n return seqLen[j];\n }\n }\n return 1;\n}\n\nprint(mayor);"}, {"source_code": "var n = readline()*1;\nvar arr = readline().split(\" \");\n//=====================================================\nvar seqIni = [];\nvar seqLen = [];\n \nvar ini = -1;\nvar len = 1;\n \nfor (var i = 0; i < arr.length-1; i++) {\n if(arr[i]*1 < arr[i+1]*1){\n if(ini == -1){\n ini = i;\n }\n len++;\n }else{\n if(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n ini = -1;\n len = 1;\n }\n }\n}\nif(ini != -1){\n seqIni.push(ini);\n seqLen.push(len);\n}\n/*\nconsole.log(arr);\nconsole.log(seqIni);\nconsole.log(seqLen);\n*/\n//===================================================\nif(arr.length == 1){\n var mayor = 1;\n}else{\n var mayor = 2; \n\n for (var i = 0; i < arr.length-2; i++) {\n if(arr[i]*1+2 <= arr[i+2]*1 && arr[i]*1 >= arr[i+1]*1){\n var l= buscar(i,i+1)+1+buscar(i+2,i+1);\n if(l > mayor){\n mayor = l;\n }\n }\n }\n \n var r= buscar(0,0)+1;\n if(r > mayor){\n mayor = r;\n }\n r= buscar(arr.length-1,arr.length-1)+1;\n if(r > mayor){\n mayor = r;\n }\n \n for (var i = 0; i < seqIni.length; i++) {\n if(seqLen[i]+1 <= arr.length){\n if(seqLen[i]+1 > mayor){\n mayor = seqLen[i]+1;\n } \n }else{\n if(seqLen[i] > mayor){\n mayor = seqLen[i];\n }\n }\n }\n\n}\n\nfunction buscar(i,elMalo){\n for(var j=0; j< seqIni.length; j++){\n if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){\n if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){\n return seqLen[j]-1; \n }\n return seqLen[j];\n }\n }\n return 1;\n}\n\nprint(mayor);"}, {"source_code": "var n = readline()*1;\nvar arr = readline().split(\" \");\n \nvar mayor = 0;\n \nfor (var i = 0; i < arr.length-2; i++) {\n if(arr[i]*1+2== arr[i+2]*1){\n var l=3;\n var j= i;\n while(j-1>=0){\n if(arr[j-1]*1 == arr[j]-1){\n l++;\n j--;\n }else{\n break;\n }\n }\n var j= i+2;\n while(j+1 mayor){\n mayor = l;\n }\n }\n}\n \nprint(mayor);"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tl.forEach(function (e) {\n\t\t\tk.push(s.splice(0, e));\n\t\t});\n\n\t\tk.push([]); k.unshift([]);\n\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < l.length - 1; i++) {\n\t\t\tvar a = k[i], b = k[i + 1];\n\n\t\t\tif (a.length === 1 || b.length === 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else\n\t\t\tif (true) {\n\t\t\t\tmax = Math.max(max, a.length + 1, b.length + 1);\n\t\t\t}\n\t\t}\n\n\t\treturn max;\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tl.forEach(function (e) {\n\t\t\tk.push(s.splice(0, e));\n\t\t});\n\n\t\tk.push([]); k.unshift([]);\n\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < l.length + 1; i++) {\n\t\t\tvar a = k[i], b = k[i + 1];\n\n\t\t\tif (a.length === 1 || b.length === 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else\n\t\t\tif (true) {\n\t\t\t\tmax = Math.max(max, a.length + 1, b.length + 1);\n\t\t\t}\n\t\t}\n\n\t\treturn max;\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tl.forEach(function (e) {\n\t\t\tk.push(s.splice(0, e));\n\t\t});\n\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < l.length - 1; i++) {\n\t\t\tvar a = k[i], b = k[i + 1];\n\n\t\t\tif (a.length === 1 || b.length === 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else\n\t\t\tif (true) {\n\t\t\t\tmax = Math.max(max, a.length + 1, b.length + 1);\n\t\t\t}\n\t\t}\n\n\t\treturn max;\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tl.forEach(function (e) {\n\t\t\tk.push(s.splice(0, e));\n\t\t});\n\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < l.length - 1; i++) {\n\t\t\tvar a = k[i], b = k[i + 1];\n\n\t\t\tif (a.length === 1 || b.length === 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else \n\t\t\tif (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {\n\t\t\t\tmax = Math.max(max, a.length + b.length);\n\t\t\t} else\n\t\t\tif (true) {\n\t\t\t\tmax = Math.max(max, a.length + 1, b.length + 1);\n\t\t\t}\n\t\t}\n\n\t\treturn max || 1;\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline().split(' ').map(Number);\n\n\t\tvar p = 0, l = [];\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (s[i] <= s[i-1]) {\n\t\t\t\tl.push(i - p);\n\t\t\t\tp = i;\n\t\t\t}\n\t\t}\n\t\tl.push(n - p);\n\n\t\tvar k = [];\n\t\tfor (var i = 1, _i = l.length; i < _i; i++) {\n\t\t\tk.push(l[i - 1] + l[i]);\n\t\t}\n\n\t\treturn Math.max.apply(null, k);\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": "var n = parseInt(readline());\nvar line = readline().split(' ');\nvar a = new Int32Array(n);\nvar inc = new Int32Array(n);\nvar dec = new Int32Array(n);\nvar i;\nfor (i = 0; i < n; i++) {\n a[i] = parseInt(line[i]);\n}\n\ninc[0] = 1;\nfor (i = 1; i < n; i++) {\n if (a[i] > a[i-1]) {\n inc[i] = inc[i-1]+1;\n } else {\n inc[i] = 1;\n }\n}\n\ndec[n-1] = 1;\nfor (i = n-1; i >= 0; i--) {\n if (a[i] < a[i+1]) {\n dec[i] = dec[i+1]+1;\n } else {\n dec[i] = 1;\n }\n}\n\nvar max = 1;\nif (n > 1) {\n max = dec[1]+1;\n}\n\nfor (i = 1; i < n; i++) {\n if (a[i] <= a[i-1]) { // si hay un hoyo\n if (i < n-1) { // si hay siguiente\n if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio\n max = Math.max(max, inc[i-1] + dec[i+1] + 1);\n } else { // si el cambio solamente agrega un elemento a las series originales\n max = Math.max(max, inc[i-1]+1, dec[i+1]+1);\n }\n } else {\n max = Math.max(max, inc[i-1]+1);\n }\n }\n}\n\nprint(max);"}, {"source_code": "var n = parseInt(readline());\nvar line = readline().split(' ');\nvar a = new Int32Array(n);\nvar inc = new Int32Array(n);\nvar dec = new Int32Array(n);\nvar i;\nfor (i = 0; i < n; i++) {\n a[i] = parseInt(line[i]);\n}\n\ninc[0] = 1;\nfor (i = 1; i < n; i++) {\n if (a[i] > a[i-1]) {\n inc[i] = inc[i-1]+1;\n } else {\n inc[i] = 1;\n }\n}\n\ndec[n-1] = 1;\nfor (i = n-2; i >= 0; i--) {\n if (a[i] < a[i+1]) {\n dec[i] = dec[i+1]+1;\n } else {\n dec[i] = 1;\n }\n}\n\nvar max = 1;\nif (n > 1) {\n max = dec[1]+1;\n}\n\nfor (i = 1; i < n; i++) {\n if (a[i] <= a[i-1]) { // si hay un hoyo\n if (i < n-1) { // si hay siguiente\n if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio\n max = Math.max(max, inc[i-1] + dec[i+1] + 1);\n } else { // si el cambio solamente agrega un elemento a las series originales\n max = Math.max(max, inc[i-1]+1, dec[i+1]+1);\n }\n } else {\n max = Math.max(max, inc[i-1]+1);\n }\n }\n}\n\nprint(max);"}], "src_uid": "9e0d271b9bada1364dfcb47297549652"} {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var a = lines[l++].trim().split(' ').map(Number)\n var b = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, a, b))\n }\n});\n\nfunction solve(n, a, b) {\n const sa = []\n a.forEach((x, i) => sa[i] = i ? x + sa[i - 1] : x)\n const sb = []\n b.forEach((x, i) => sb[i] = i ? x + sb[i - 1] : x)\n\n let min = Infinity\n for (let i = 0; i < n; i++) {\n // row 0, 0-i is a\n // row 1, i-n is a\n const score = Math.max(sa[n - 1] - sa[i], i ? sb[i - 1] : 0)\n min = Math.min(min, score)\n }\n return min\n}", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++) {\r\n var caseLength = parseInt(readline());\r\n var topArray = readline().split(\" \");\r\n var bottomArray = readline().split(\" \");\r\n var topIntArray = new Array(caseLength);\r\n topIntArray[0] = 0;\r\n var bottomIntArray = new Array(caseLength);\r\n bottomIntArray[caseLength - 1] = 0;\r\n var index = 0;\r\n var revIndex = caseLength - 1;\r\n var topTotal = 0;\r\n var bottomTotal = 0;\r\n while (index < caseLength - 1) {\r\n var topValue = parseInt(topArray[revIndex]);\r\n topTotal += topValue;\r\n topIntArray[revIndex] = topTotal;\r\n var bottomValue = parseInt(bottomArray[index]);\r\n bottomTotal += bottomValue;\r\n bottomIntArray[index] = bottomTotal;\r\n index++;\r\n revIndex--;\r\n }\r\n var minValue = Math.min(topTotal, bottomTotal);\r\n for (var k = 1; k < caseLength - 1; k++) {\r\n var higher = Math.max(topIntArray[k + 1], bottomIntArray[k - 1]);\r\n minValue = (higher < minValue) ? higher : minValue;\r\n }\r\n print(minValue);\r\n }"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n if (e <= 1) return 0\r\n let s = 0\r\n for (let t = 0; t < e; ++t) s += n[t]\r\n let i = Number.MAX_SAFE_INTEGER\r\n for (let r = 0, o = 0, d = 0; r < e; ++r) {\r\n o += n[r]\r\n const e = Math.max(s - o, d)\r\n ;(d += t[r]), i > e && (i = e)\r\n }\r\n return i\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(\r\n Number(e.readLine()),\r\n e.readIntegersOfLine(),\r\n e.readIntegersOfLine(),\r\n )\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst MAX_N = 100010,\r\n sum1 = new Array(MAX_N)\r\nfunction solve(e, n, t) {\r\n if (e <= 1) return 0\r\n sum1[0] = n[0]\r\n for (let t = 1; t < e; ++t) sum1[t] = sum1[t - 1] + n[t]\r\n const s = e - 1\r\n let i = sum1[s] - n[0]\r\n for (let n = 1, r = t[0]; n < e; ++n) {\r\n const e = Math.max(sum1[s] - sum1[n], r)\r\n ;(r += t[n]), i > e && (i = e)\r\n }\r\n return i\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(\r\n Number(e.readLine()),\r\n e.readIntegersOfLine(),\r\n e.readIntegersOfLine(),\r\n )\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr1 = iInpArr();\r\n let arr2 = iInpArr();\r\n let psum1 = [],\r\n psum2 = [],\r\n s1 = 0,\r\n s2 = 0;\r\n for (let i = 0; i < n; i++) {\r\n s1 += arr1[i];\r\n s2 += arr2[i];\r\n psum1[i] = s1;\r\n psum2[i] = s2;\r\n }\r\n let ans = Infinity,\r\n end = n - 1,\r\n st = 0;\r\n for (let i = 0; i < n; i++) {\r\n let v1 = psum1[end] - psum1[i];\r\n let v2 = i !== 0 ? psum2[i - 1] : 0;\r\n ans = Math.min(ans, Math.max(v1, v2));\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = Number.POSITIVE_INFINITY;\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet m = rna();\r\n\t\tlet a = [];\r\n\t\ta[0] = rna();\r\n\t\ta[1] = rna();\r\n\r\n\t\tlet sm1 = 0;\r\n\t\tfor (let i = 0; i < m; i++)\r\n\t\t\tsm1 += a[0][i];\r\n\r\n\t\tlet ans = INF;\r\n\t\tfor(let i = 0, cursm1 = cursm2 = 0; i < m; i++) {\r\n\t\t\tcursm1 += a[0][i];\r\n\t\t\tcursm2 += a[1][i];\r\n\t\t\tans = Math.min(ans, Math.max(sm1 - cursm1, cursm2 - a[1][i]))\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var mi = Infinity;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n mi = Math.min(mi, Math.max(acc1, acc2));\r\n acc2 += a2[i];\r\n }\r\n print(mi);\r\n}"}], "negative_code": [{"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var mi = 10000000;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n mi = Math.min(mi, Math.max(acc1, acc2));\r\n acc2 += a2[i];\r\n }\r\n print(mi);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var m = 10000000;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n print(m, acc1, acc2);\r\n m = Math.min(m, Math.max(acc1, acc2));\r\n acc2 += a2[i];\r\n }\r\n print(m);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var m = 10000000;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n m = Math.min(m, Math.max(acc1, acc2));\r\n acc2 += a2[i];\r\n }\r\n print(m);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var m = 10000000;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n m = Math.min(m, Math.max(acc1, acc2));\r\n acc2 += a1[i];\r\n }\r\n print(m);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) {\r\n acc1 += a1[i];\r\n }\r\n\r\n var m = 10000000;\r\n for (var i = 0; i < m; i++) {\r\n acc1 -= a1[i];\r\n m = Math.min(m, acc1, acc2);\r\n acc2 += a1[i];\r\n }\r\n print(m);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n var a = [a1, a2];\r\n \r\n var s1 = find(a, m);\r\n \r\n for (var i = 0; i <= s1[1]; i++) \r\n a[0][i] = 0;\r\n for (var i = s1[1]; i < m; i++)\r\n a[1][i] = 0;\r\n \r\n print(JSON.stringify(a));\r\n \r\n var s2 = find(a, m);\r\n print(s2[0]);\r\n}\r\n\r\nfunction find(a, m) {\r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) \r\n acc2 += a[1][i];\r\n \r\n var max = 0, maxi = 0; \r\n for (var i = 0; i < m; i++) {\r\n acc1 += a[0][i];\r\n \r\n if (acc1 + acc2 > max) {\r\n max = acc1 + acc2;\r\n maxi = i;\r\n }\r\n \r\n acc2 -= a[1][i];\r\n }\r\n\r\n return [max, maxi]; \r\n}"}, {"source_code": "var T = parseInt(readline());\r\n\r\nfor (var t = 0; t < T; t++) {\r\n var m = parseInt(readline());\r\n var a1 = readline().split(' ').map((x) => parseInt(x));\r\n var a2 = readline().split(' ').map((x) => parseInt(x));\r\n var a = [a1, a2];\r\n \r\n var s1 = find(a, m);\r\n \r\n for (var i = 0; i <= s1[1]; i++) \r\n a[0][i] = 0;\r\n for (var i = s1[1]; i < m; i++)\r\n a[1][i] = 0;\r\n \r\n var s2 = find(a, m);\r\n print(s2[0]);\r\n}\r\n\r\nfunction find(a, m) {\r\n var acc1 = 0, acc2 = 0;\r\n for (var i = 0; i < m; i++) \r\n acc2 += a[1][i];\r\n \r\n var max = 0, maxi = 0; \r\n for (var i = 0; i < m; i++) {\r\n acc1 += a[0][i];\r\n \r\n if (acc1 + acc2 > max) {\r\n max = acc1 + acc2;\r\n maxi = i;\r\n }\r\n \r\n acc2 -= a[1][i];\r\n }\r\n\r\n return [max, maxi]; \r\n}"}], "src_uid": "f3ee3a0de5ddf3cf15ef02fb62a2768e"} {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n preRun(lines);\n});\n\n// preRun([\n// \t\"1\",\n// \t\"6\",\n// \t\"62190969 830257761\",\n// \t\"133433399 602982864\",\n// \t\"249519268 512360334\",\n// \t\"706277914 269089955\",\n// \t\"763878605 823076990\",\n// \t\"860629446 664543503\"\n// ]);\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tlet p = 1;\n\tfor(let i=0;i parseInt(e));p++;\n\t\t\txs.push(x);\n\t\t\tys.push(y);\n\t\t}\n\t\txs.sort((a,b) => a-b);\n\t\tys.sort((a,b) => a-b);\n\t\tlet rx = BigInt(calcRange(xs));\n\t\tlet ry = BigInt(calcRange(ys));\n\t\tconsole.log((rx*ry)+\"\");\n\t}\n}\n\nfunction calcRange(cs)\n{\n\tif (cs.length%2==1)\n\t{\n\t\treturn 1;\n\t}\n\telse\n\t{\n\t\tlet m = (cs.length/2);\n\t\treturn (cs[m]-cs[m-1])+1;\n\t}\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var y = new Array(n)\r\n var x = new Array(n)\r\n var xx, yy\r\n for (let j = 0; j < n; j++) {\r\n [xx, yy] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n x[j] = xx;\r\n y[j] = yy;\r\n }\r\n\r\n x = x.sort((a, b) => a - b)\r\n y = y.sort((a, b) => a - b)\r\n\r\n if (n % 2 === 1) return console.log(1)\r\n var a = x[Math.floor((n) / 2)] - x[Math.floor(n / 2 - 1)] + 1\r\n var b = y[Math.floor((n) / 2)] - y[Math.floor(n / 2 - 1)] + 1\r\n a = BigInt(a)\r\n b = BigInt(b)\r\n // console.log(x)\r\n // console.log(y)\r\n console.log((a*b).toString())\r\n })\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet x = Array(n);\r\n\t\tlet y = Array(n);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t[x[i], y[i]] = rna();;\r\n\t\t}\r\n\r\n\t\tx.sort((a, b) => a - b);\r\n\t\ty.sort((a, b) => a - b);\r\n\r\n\t\tlet ans = 1;\r\n\t\tif (n%2 == 0) {\r\n\t\t\tconst k = n/2 - 1;\r\n\t\t\tans = BigInt(x[k+1] - x[k] + 1) * BigInt(y[k+1] - y[k] + 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var y = new Array(n)\r\n var x = new Array(n)\r\n var xx, yy\r\n for (let j = 0; j < n; j++) {\r\n [xx, yy] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n x[j] = xx;\r\n y[j] = yy;\r\n }\r\n\r\n x = x.sort((a, b) => a - b)\r\n y = y.sort((a, b) => a - b)\r\n\r\n if (n%2 === 1) return console.log(1)\r\n var asnwer = x[Math.floor((n ) / 2)] - x[Math.floor(n/2-1)] + 1\r\n asnwer *= y[Math.floor((n ) / 2)]- y[Math.floor(n/2-1)] + 1\r\n\r\n // console.log(x)\r\n // console.log(y)\r\n console.log(asnwer)\r\n })\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var y = new Array(n)\r\n var x = new Array(n)\r\n var xx, yy\r\n for (let j = 0; j < n; j++) {\r\n [xx, yy] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n x[j] = xx;\r\n y[j] = yy;\r\n }\r\n\r\n x = x.sort((a, b) => a - b)\r\n y = y.sort((a, b) => a - b)\r\n\r\n if (n === 1) return console.log(1)\r\n var asnwer = x[Math.floor((n ) / 2)] - x[Math.floor(n/2-1)] + 1\r\n asnwer *= y[Math.floor((n ) / 2)]- y[Math.floor(n/2-1)] + 1\r\n\r\n // console.log(x)\r\n // console.log(y)\r\n console.log(asnwer)\r\n })\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var xy = new Array(n)\r\n var xx, yy\r\n var sameLineX = true\r\n var sameLineY = true\r\n for (let j = 0; j < n; j++) {\r\n [xx, yy] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n xy[j] = {x: xx, y: yy}\r\n }\r\n\r\n var sumx = 0\r\n var sumY = 0\r\n for (let i = 0; i < n; i++) {\r\n sumx += xy[i].x\r\n sumY += xy[i].y\r\n }\r\n // console.log(xy)\r\n // console.log(sumx, sumY, sumx / n, sumY / n)\r\n sumx = sumx / n\r\n var sumy = sumY / n\r\n if (sumx === 0 && sumy === 0) return console.log(1)\r\n if (n === 2) {\r\n if (sumx === Math.ceil(sumx) && sumy === Math.ceil(sumy)) {\r\n // if (sumx === xy[0].x && sumy === xy[0].y) {\r\n // return console.log(1)\r\n // }\r\n // if (sumx !== xy[0][0] || sumy !== xy[0][1]) {\r\n return console.log(3)\r\n // }\r\n // return console.log(1)\r\n }\r\n if (sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5 && sumy === (Math.ceil(sumy) + Math.floor(sumy)) * 0.5) {\r\n return console.log(4)\r\n }\r\n return console.log(2)\r\n }\r\n if (n === 3) {\r\n }\r\n\r\n if (sumx === Math.ceil(sumx) && sumy === Math.ceil(sumy)) {\r\n return console.log(1)\r\n }\r\n\r\n // console.log(sumx, sumy)\r\n // if(sumx === Math.ceil(sumx) || sumy === Math.ceil(sumy) ){\r\n // return console.log(2)\r\n // }\r\n // console.log(sumx, sumy)\r\n // console.log(sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5, sumy)\r\n\r\n if (sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5 && sumy === (Math.ceil(sumy) + Math.floor(sumy)) * 0.5) {\r\n return console.log(4)\r\n }\r\n console.log(1)\r\n\r\n })\r\n}\r\n\r\nvar lower_limit = 0.01;\r\n\r\n// Function to return the sum of Euclidean\r\n// Distances\r\nfunction distSum(p, arr, n) {\r\n var sum = 0;\r\n for (var i = 0; i < n; i++) {\r\n var distx = Math.abs(arr[i].x - p.x);\r\n var disty = Math.abs(arr[i].y - p.y);\r\n sum += Math.sqrt((distx * distx) + (disty * disty));\r\n }\r\n\r\n // Return the sum of Euclidean Distances\r\n return sum;\r\n}\r\n\r\nvar test_point = [{x: -1.0, y: 0.0},\r\n {x: 0.0, y: 1.0},\r\n {x: 1.0, y: 0.0},\r\n {x: 0.0, y: -1.0}];\r\n// function geometricMedian(arr, n) {\r\n//\r\n// // Current x coordinate and y coordinate\r\n// var current_point = {x: 0, y: 0};\r\n//\r\n// for (var i = 0; i < n; i++) {\r\n// current_point.x += arr[i].x;\r\n// current_point.y += arr[i].y;\r\n// }\r\n//\r\n// // Here current_point becomes the\r\n// // Geographic MidPoint\r\n// // Or Center of Gravity of equal\r\n// // discrete mass distributions\r\n// current_point.x /= n;\r\n// current_point.y /= n;\r\n//\r\n// // minimum_distance becomes sum of\r\n// // all distances from MidPoint to\r\n// // all given points\r\n// var minimum_distance = distSum(current_point, arr, n);\r\n//\r\n// var k = 0;\r\n// while (k < n) {\r\n// for (var i = 0; i < n && i !== k; i++) {\r\n// var newpoint = {};\r\n// newpoint.x = arr[i].x;\r\n// newpoint.y = arr[i].y;\r\n// var newd =\r\n// distSum(newpoint, arr, n);\r\n// console.log(newd)\r\n// console.log(minimum_distance)\r\n// if (newd < minimum_distance) {\r\n// minimum_distance = newd;\r\n// current_point.x = newpoint.x;\r\n// current_point.y = newpoint.y;\r\n// }\r\n// }\r\n// k++;\r\n// }\r\n//\r\n// // Assume test_distance to be 1000\r\n// var test_distance = 1000.0;\r\n// var flag = 0;\r\n//\r\n// // Test loop for approximation starts here\r\n// while (test_distance > lower_limit) {\r\n//\r\n// flag = 0;\r\n//\r\n// // Loop for iterating over all 4 neighbours\r\n// for (var i = 0; i < 4; i++) {\r\n//\r\n// // Finding Neighbours done\r\n// var newpoint = {}\r\n// newpoint.x = current_point.x\r\n// + test_distance * test_point[i].x;\r\n// newpoint.y = current_point.y\r\n// + test_distance * test_point[i].y;\r\n//\r\n// // New sum of Euclidean distances\r\n// // from the neighbor to the given\r\n// // data points\r\n// var newd = distSum(newpoint, arr, n);\r\n//\r\n// if (newd < minimum_distance) {\r\n//\r\n// // Approximating and changing\r\n// // current_point\r\n// minimum_distance = newd;\r\n// current_point.x = newpoint.x;\r\n// current_point.y = newpoint.y;\r\n// flag = 1;\r\n// break;\r\n// }\r\n// }\r\n//\r\n// // This means none of the 4 neighbours\r\n// // has the new minimum distance, hence\r\n// // we divide by 2 and reiterate while\r\n// // loop for better approximation\r\n// if (flag === 0)\r\n// test_distance /= 2;\r\n// }\r\n//\r\n// // cout << \"Geometric Median = (\"\r\n// // console.log(current_point)\r\n// return current_point\r\n// // current_point.x << \", \"\r\n// // << current_point.y << \")\";\r\n// // cout << \" with minimum distance = \"\r\n// // console.log(minimum_distancecurrent_point);\r\n// }\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var nn = n\r\n var xy = new Array(n)\r\n var xx, yy\r\n var sameLineX = true\r\n var sameLineY = true\r\n for (let j = 0; j < n; j++) {\r\n [xx, yy] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n xy[j] = {x: xx, y: yy}\r\n }\r\n if (n === 1) return console.log(1)\r\n // console.log(xy)\r\n // console.log(geometricMedian(xy, n))\r\n var point = geometricMedian(xy, n)\r\n // console.log(point.x === (Math.ceil(point.x) + Math.floor(point.x))*0.5 )\r\n\r\n var sameX = point.x === (Math.ceil(point.x) + Math.floor(point.x)) * 0.5\r\n var sameY = point.y === (Math.ceil(point.y) + Math.floor(point.y)) * 0.5\r\n\r\n // console.log(sameX, sameY, point)\r\n if (Math.ceil(point.y) === point.y && Math.ceil(point.x) === point.x) {\r\n if(n===2) {\r\n if(xy[0].x === point.x &&xy[0].y === point.y) return console.log(1)\r\n return console.log(3)\r\n }\r\n return console.log(1)\r\n }\r\n if (Math.ceil(point.y) === point.y && sameX) {\r\n return console.log(2)\r\n }\r\n if (Math.ceil(point.x) === point.x && sameY) {\r\n return console.log(2)\r\n }\r\n\r\n\r\n if (sameX && sameY) {\r\n return console.log(4)\r\n }\r\n console.log(1)\r\n })\r\n\r\n}\r\n\r\nvar lower_limit = 0.01;\r\n\r\n// Function to return the sum of Euclidean\r\n// Distances\r\nfunction distSum(p, arr, n) {\r\n var sum = 0;\r\n for (var i = 0; i < n; i++) {\r\n var distx = Math.abs(arr[i].x - p.x);\r\n var disty = Math.abs(arr[i].y - p.y);\r\n sum += Math.sqrt((distx * distx) + (disty * disty));\r\n }\r\n\r\n // Return the sum of Euclidean Distances\r\n return sum;\r\n}\r\n\r\nfunction geometricMedian(arr, n) {\r\n\r\n // Current x coordinate and y coordinate\r\n var current_point = {x: 0, y: 0};\r\n\r\n for (var i = 0; i < n; i++) {\r\n current_point.x += arr[i].x;\r\n current_point.y += arr[i].y;\r\n }\r\n\r\n // Here current_point becomes the\r\n // Geographic MidPoint\r\n // Or Center of Gravity of equal\r\n // discrete mass distributions\r\n current_point.x /= n;\r\n current_point.y /= n;\r\n\r\n // minimum_distance becomes sum of\r\n // all distances from MidPoint to\r\n // all given points\r\n var minimum_distance = distSum(current_point, arr, n);\r\n\r\n var k = 0;\r\n while (k < n) {\r\n for (var i = 0; i < n && i !== k; i++) {\r\n var newpoint = {};\r\n newpoint.x = arr[i].x;\r\n newpoint.y = arr[i].y;\r\n var newd =\r\n distSum(newpoint, arr, n);\r\n if (newd < minimum_distance) {\r\n minimum_distance = newd;\r\n current_point.x = newpoint.x;\r\n current_point.y = newpoint.y;\r\n }\r\n }\r\n k++;\r\n }\r\n\r\n // Assume test_distance to be 1000\r\n var test_distance = 1000.0;\r\n var flag = 0;\r\n\r\n // Test loop for approximation starts here\r\n // while (test_distance > lower_limit) {\r\n //\r\n // flag = 0;\r\n //\r\n // // Loop for iterating over all 4 neighbours\r\n // for (var i = 0; i < 4; i++) {\r\n //\r\n // // Finding Neighbours done\r\n // var newpoint = {}\r\n // newpoint.x = current_point.x\r\n // + test_distance * test_point[i].x;\r\n // newpoint.y = current_point.y\r\n // + test_distance * test_point[i].y;\r\n //\r\n // // New sum of Euclidean distances\r\n // // from the neighbor to the given\r\n // // data points\r\n // var newd = distSum(newpoint, arr, n);\r\n //\r\n // if (newd < minimum_distance) {\r\n //\r\n // // Approximating and changing\r\n // // current_point\r\n // minimum_distance = newd;\r\n // current_point.x = newpoint.x;\r\n // current_point.y = newpoint.y;\r\n // flag = 1;\r\n // break;\r\n // }\r\n // }\r\n //\r\n // // This means none of the 4 neighbours\r\n // // has the new minimum distance, hence\r\n // // we divide by 2 and reiterate while\r\n // // loop for better approximation\r\n // if (flag === 0)\r\n // test_distance /= 2;\r\n // }\r\n\r\n // cout << \"Geometric Median = (\"\r\n // console.log(current_point)\r\n return current_point\r\n // current_point.x << \", \"\r\n // << current_point.y << \")\";\r\n // cout << \" with minimum distance = \"\r\n // console.log(minimum_distancecurrent_point);\r\n}\r\n"}, {"source_code": "// let i = ''\n// process.stdin.on('data', c => i += c);\n// process.stdin.on('end', () => {\n// const {EOL} = require('os')\n// const lines = i.split(EOL)\n// preRun(lines);\n// });\n\npreRun([\n\t\"1\",\n\t\"6\",\n\t\"62190969 830257761\",\n\t\"133433399 602982864\",\n\t\"249519268 512360334\",\n\t\"706277914 269089955\",\n\t\"763878605 823076990\",\n\t\"860629446 664543503\"\n]);\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tlet p = 1;\n\tfor(let i=0;i parseInt(e));p++;\n\t\t\txs.push(x);\n\t\t\tys.push(y);\n\t\t}\n\t\txs.sort((a,b) => a-b);\n\t\tys.sort((a,b) => a-b);\n\t\tlet rx = BigInt(calcRange(xs));\n\t\tlet ry = BigInt(calcRange(ys));\n\t\tconsole.log((rx*ry)+\"\");\n\t}\n}\n\nfunction calcRange(cs)\n{\n\tif (cs.length%2==1)\n\t{\n\t\treturn 1;\n\t}\n\telse\n\t{\n\t\tlet m = (cs.length/2);\n\t\treturn (cs[m]-cs[m-1])+1;\n\t}\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n preRun(lines);\n});\n\n// preRun([\n// \t\"1\",\n// \t\"6\",\n// \t\"62190969 830257761\",\n// \t\"133433399 602982864\",\n// \t\"249519268 512360334\",\n// \t\"706277914 269089955\",\n// \t\"763878605 823076990\",\n// \t\"860629446 664543503\"\n// ]);\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tlet p = 1;\n\tfor(let i=0;i parseInt(e));p++;\n\t\t\txs.push(x);\n\t\t\tys.push(y);\n\t\t}\n\t\txs.sort((a,b) => a-b);\n\t\tys.sort((a,b) => a-b);\n\t\tlet rx = calcRange(xs);\n\t\tlet ry = calcRange(ys);\n\t\tconsole.log(rx*ry);\n\t}\n}\n\nfunction calcRange(cs)\n{\n\tif (cs.length%2==1)\n\t{\n\t\treturn 1;\n\t}\n\telse\n\t{\n\t\tlet m = (cs.length/2);\n\t\treturn (cs[m]-cs[m-1])+1;\n\t}\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n preRun(lines);\n});\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tlet p = 1;\n\tfor(let i=0;i parseInt(e));p++;\n\t\t\txs.push(x);\n\t\t\tys.push(y);\n\t\t}\n\t\txs.sort();\n\t\tys.sort();\n\t\tlet rx = calcRange(xs);\n\t\tlet ry = calcRange(ys);\n\t\tconsole.log(rx*ry);\n\t}\n}\n\nfunction calcRange(cs)\n{\n\tif (cs.length%2==1)\n\t{\n\t\treturn 1;\n\t}\n\telse\n\t{\n\t\tlet m = (cs.length/2);\n\t\treturn (cs[m]-cs[m-1])+1;\n\t}\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n preRun(lines);\n});\n\n// preRun([\n\n// \t\"6\",\n// \t\"3\",\n// \t\"0 0\",\n// \t\"2 0\",\n// \t\"1 2\",\n// \t\"4\",\n// \t\"1 0\",\n// \t\"0 2\",\n// \t\"2 3\",\n// \t\"3 1\",\n// \t\"4\",\n// \t\"0 0\",\n// \t\"0 1\",\n// \t\"1 0\",\n// \t\"1 1\",\n// \t\"2\",\n// \t\"0 0\",\n// \t\"1 1\",\n// \t\"2\",\n// \t\"0 0\",\n// \t\"2 0\",\n// \t\"2\",\n// \t\"0 0\",\n// \t\"0 0\"\t\n// ]);\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tlet p = 1;\n\tfor(let i=0;i parseInt(e));p++;\n\t\t\txs.push(x);\n\t\t\tys.push(y);\n\t\t}\n\t\txs.sort();\n\t\tys.sort();\n\t\tlet rx = calcRange(xs);\n\t\tlet ry = calcRange(ys);\n\t\tconsole.log(rx*ry);\n\t}\n}\n\nfunction calcRange(cs)\n{\n\tif (cs.length==1) return 1;\n\n\tlet t = 0;\n\tfor(let i=0;im)\n\t\t{\n\t\t\taft++;\n\t\t\tif (a==-1) a = cs[i];\n\t\t}\n\t}\t\n\tif (bef==aft)\n\t{\n\t\treturn (a-b)+1;\n\t}\n\telse\n\t{\n\t\treturn 1;\n\t}\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet x = Array(n);\r\n\t\tlet y = Array(n);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t[x[i], y[i]] = rna();;\r\n\t\t}\r\n\r\n\t\tx.sort((a, b) => a - b);\r\n\t\ty.sort((a, b) => a - b);\r\n\r\n\t\tlet ans = 1;\r\n\t\tif (n%2 == 0) {\r\n\t\t\tconst k = n/2 - 1;\r\n\t\t\tans = (x[k+1] - x[k] + 1) * (y[k+1] - y[k] + 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "e0a1dc397838852957d0e15ec98d5efe"} {"source_code": "var cat = [{rep: 0}]\nvar min = 1\n\nreadline() // ignore # of catacombs\n// var line = '0 0'\n// var line = '0 1 0 1 3'\n //t 0 1 2 3 4 5\nvar line = readline()\nvar history = line.split(' ').map(function(x) { return parseInt(x) })\n\nvar rep = null\nfor (var i = 0; i < history.length; i++) {\n rep = cat[history[i]]\n if (rep.rep === history[i]) {\n rep.rep = i+1\n cat.push(rep)\n } else {\n min++\n cat.push({rep: i+1})\n }\n // console.log(i, history[i], cat)\n}\n// console.log(cat)\n// console.log(min)\nprint(min)\n", "positive_code": [{"source_code": "var n = Number(readline())\nvar arr = readline().split(\" \");\nvar arrMarked = [];\n\nvar count = 1;\n\nfor(var i = n-1; i>=0; i--) {\n\tvar minute = i+1;\n\tif (arrMarked[minute])\n\t\tcontinue;\n\twhile (minute >= 0 && !arrMarked[minute]) {\n\t\tarrMarked[minute] = count;\n\t\tminute = arr[minute-1];\n\t}\n\tcount++;\n}\n\nprint(count-1);"}], "negative_code": [], "src_uid": "81c6342b7229892d71cb43e72aee99e9"} {"source_code": "const readline = require(\"readline\");\r\n\r\nvar tcn = 0\r\nvar space = true\r\nvar lineCnt = 0\r\nvar sumsArr = [0,0,0,0,0,0,0,0]\r\nvar res = 0\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on('line', line => {\r\n if (!tcn) return tcn = Number(line)\r\n if (space) return space = false\r\n\r\n run(line, lineCnt)\r\n lineCnt++\r\n \r\n if (lineCnt == 8) {\r\n if (!--tcn) rl.close()\r\n lineCnt = 0\r\n sumsArr = [0,0,0,0,0,0,0,0]\r\n space = true\r\n }\r\n})\r\n\r\nfunction run(line, lineCnt) {\r\n line.split('').forEach((val, idx) => {\r\n sumsArr[idx] += (val == 'B')\r\n })\r\n \r\n if (line.split('').reduce((acc, val) => {\r\n return acc += (val == 'R')\r\n }, 0) == 8) {\r\n res = 'R'\r\n }\r\n\r\n if (lineCnt == 7) {\r\n sumsArr.forEach(val => {\r\n if (val == 8) {\r\n res = 'B'\r\n }\r\n })\r\n console.log(res)\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let input=buf.split(EOL);\r\n let line=[];\r\n for(let i=0;i {\r\n let n = g.length, m = g[0].length, res = '';\r\n // pr(g, n, m)\r\n let rows = [], cols = [];\r\n for (let i = 0; i < n; i++) {\r\n let row = '';\r\n for (let j = 0; j < m; j++) {\r\n row += g[i][j];\r\n }\r\n rows.push(row);\r\n }\r\n // pr('rows', rows);\r\n for (let row of rows) {\r\n if (row = R) res = 'R';\r\n // if (row == R) return pr('R');\r\n // if (row == B) return pr('B');\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let col = '';\r\n for (let j = 0; j < m; j++) {\r\n col += g[j][i];\r\n }\r\n cols.push(col);\r\n }\r\n // pr('cols', cols);\r\n for (let col of cols) {\r\n if (col == B) res = 'B';\r\n // if (col == R) return pr('R');\r\n // if (col == B) return pr('B');\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\r\\n');\r\n // pr(\"input\", input)\r\n let t = ni();\r\n while (t--) {\r\n readLine();\r\n let g = [];\r\n for (let i = 0; i < 8; i++) {\r\n let row = readLine();\r\n g.push(row);\r\n }\r\n solve(g);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tnext();\r\n\t\tvar s = nextStrArray(8);\r\n\t\tvar output = \".\";\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = 'R';\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[i][j]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = 'B';\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[j][i]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\nfunction begin(grid) {\r\n var row = new Array(8).fill(0);\r\n var col = new Array(8).fill(0);\r\n var i = 0;\r\n for(i = 7; i >= 0; i--) {\r\n for(var j = 0; j < 8; j++) {\r\n if(grid[i][j] == 'R') {\r\n row[i]++; \r\n } else if(grid[i][j] == 'B') { \r\n col[j]++;\r\n }\r\n }\r\n }\r\n for( i = 0; i < 8; i++) {\r\n if(row[i] == 8 ) {\r\n print(\"R\");\r\n break;\r\n }\r\n if(col[i] == 8) {\r\n print(\"B\");\r\n break;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n readline();\r\n var grid = [];\r\n for(var j = 0; j < 8; j++) {\r\n var x = readline()\r\n .trim()\r\n .split('');\r\n grid.push(x);\r\n }\r\n begin(grid);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const arr = lines.slice(l, l + 8).map(str => str.trim())\n l += 8\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n for (let i = 0; i < 8; i++) {\n let ok = 1\n for (let j = 0; j < 8; j++) {\n if (arr[i][j] !== arr[i][0]) {\n ok = 0\n }\n }\n if (ok && arr[i][0] === 'R') return arr[i][0]\n }\n for (let j = 0; j < 8; j++) {\n let ok = 1\n for (let i = 0; i < 8; i++) {\n if (arr[i][j] !== arr[0][j]) {\n ok = 0\n }\n }\n if (ok && arr[0][j] === 'B') return arr[0][j]\n }\n // return [arr]\n // console.log('-')\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n let n = 8;\r\n let a = [];\r\n for (let i = 0; i <= n; i++) {\r\n if (i) a.push(read());\r\n }\r\n next: for (let i = 0; i < n; i++) {\r\n if (a[i][0] === '.') continue;\r\n for (let j = 0; j < n; j++) {\r\n if ('R' !== a[i][j]) continue next;\r\n }\r\n return 'R';\r\n }\r\n next: for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '.') continue;\r\n for (let j = 0; j < n; j++) {\r\n if ('B' !== a[j][i]) continue next;\r\n }\r\n return 'B';\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const lines = [];\r\nlet currentLineIndex = 0;\r\nconst readlineInterface = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nreadlineInterface.on(\"line\", (line) => {\r\n if (currentLineIndex > 0 && line.trim()) {\r\n lines.push(line);\r\n }\r\n currentLineIndex++;\r\n});\r\n\r\nconst squareSize = 8;\r\nconst rowChar = \"R\";\r\nconst columnChar = \"B\";\r\n\r\nreadlineInterface.on(\"close\", () => {\r\n const rows = lines.map((line) => line.split(\"\"));\r\n let partialIndex = 0;\r\n let toPush = [];\r\n const tests = [];\r\n rows.forEach((row, index) => {\r\n if (partialIndex < squareSize) {\r\n toPush.push(row);\r\n } else {\r\n tests.push(toPush);\r\n toPush = [row];\r\n partialIndex = 0;\r\n }\r\n partialIndex++;\r\n });\r\n tests.push(toPush);\r\n\r\n tests\r\n .map((rows) => {\r\n return rows.find((row) => new Set(row).size === 1 && row[0] === rowChar)\r\n ? rowChar\r\n : columnChar;\r\n })\r\n .forEach((e) => console.log(e));\r\n});\r\n"}, {"source_code": "var tests = +readline();\r\n\r\nfor(var i=0; i {\r\n let n = g.length, m = g[0].length, se = new Set();\r\n // pr(g, n, m)\r\n let rows = [], cols = [];\r\n for (let i = 0; i < n; i++) {\r\n let row = '';\r\n for (let j = 0; j < m; j++) {\r\n row += g[i][j];\r\n }\r\n rows.push(row);\r\n }\r\n // pr('rows', rows);\r\n for (let row of rows) {\r\n if (row == R) return pr('R');\r\n if (row == B) return pr('B');\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let col = '';\r\n for (let j = 0; j < m; j++) {\r\n col += g[j][i];\r\n }\r\n cols.push(col);\r\n }\r\n // pr('cols', cols);\r\n for (let col of cols) {\r\n if (col == R) return pr('R');\r\n if (col == B) return pr('B');\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\r\\n');\r\n // pr(\"input\", input)\r\n let t = ni();\r\n while (t--) {\r\n readLine();\r\n let g = [];\r\n for (let i = 0; i < 8; i++) {\r\n let row = readLine();\r\n g.push(row);\r\n }\r\n solve(g);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/C\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nconst solve = (g) => {\r\n let n = g.length, m = g[0].length, se = new Set();\r\n // pr(g, n, m)\r\n let rows = [], cols = [];\r\n for (let i = 0; i < n; i++) {\r\n let row = [];\r\n for (let j = 0; j < m; j++) {\r\n if (g[i][j] != '.') row.push(g[i][j]);\r\n }\r\n rows.push(row);\r\n }\r\n // pr('rows', rows);\r\n for (let row of rows) {\r\n let se = new Set(row);\r\n // pr(\"row set\", se)\r\n if (se.size == 1 && row.length == n) return pr(row[0]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let col = [];\r\n for (let j = 0; j < m; j++) {\r\n if (g[j][i] != '.') col.push(g[j][i]);\r\n }\r\n cols.push(col);\r\n }\r\n // pr('cols', cols);\r\n for (let col of cols) {\r\n let se = new Set(col);\r\n // pr(\"col set\", se)\r\n if (se.size == 1 && col.length == m) return pr(col[0]);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\r\\n');\r\n // pr(\"input\", input)\r\n let t = ni();\r\n while (t--) {\r\n readLine();\r\n let g = [];\r\n for (let i = 0; i < 8; i++) {\r\n let row = readLine();\r\n g.push(row);\r\n }\r\n solve(g);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/C\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nconst solve = (g) => {\r\n let n = g.length, m = g[0].length, se = new Set();\r\n // pr(g, n, m)\r\n for (let row of g) {\r\n let se = new Set(row);\r\n if (se.size == 1 && row[0] != '.') return pr(row[0]);\r\n }\r\n let cols = [];\r\n for (let i = 0; i < n; i++) {\r\n let col = [];\r\n for (let j = 0; j < m; j++) {\r\n col.push(g[j][i]);\r\n }\r\n cols.push(col);\r\n }\r\n // pr(cols);\r\n for (let col of cols) {\r\n let se = new Set(col);\r\n // pr(se)\r\n if (se.size == 1 && col[0] != '.') return pr(col[0]);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\r\\n');\r\n // pr(\"input\", input)\r\n let t = ni();\r\n while (t--) {\r\n readLine();\r\n let g = [];\r\n for (let i = 0; i < 8; i++) {\r\n let row = readLine();\r\n g.push(row);\r\n }\r\n solve(g);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tnext();\r\n\t\tvar s = nextStrArray(8);\r\n\t\tvar output = \".\";\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = s[i][0];\r\n\t\t\tif(last == \".\"){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[i][j]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = s[0][i];\r\n\t\t\tif(last == \".\"){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[j][i]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tnext();\r\n\t\tvar s = nextStrArray(8);\r\n\t\tvar output = \".\";\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = s[i][0];\r\n\t\t\tif(last == \".\"){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[i][j]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < 8; i++){\r\n\t\t\tvar last = s[0][i];\r\n\t\t\tif(last == \".\"){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar ok = true;\r\n\t\t\tfor(var j = 0; j < 8; j++){\r\n\t\t\t\tif(last != s[j][i]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = last;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\nfunction begin(grid) {\r\n var row = new Array(8).fill(0).map(() => new Array(2).fill(0));\r\n var col = new Array(8).fill(0).map(() => new Array(2).fill(0));\r\n var i = 0;\r\n for(i = 7; i >= 0; i--) {\r\n for(var j = 0; j < 8; j++) {\r\n if(grid[i][j] == 'R') {\r\n row[i][0]++;\r\n col[j][0]++;\r\n } else if(grid[i][j] == 'B') {\r\n row[i][1]++;\r\n col[j][1]++;\r\n }\r\n }\r\n }\r\n for( i = 0; i < 8; i++) {\r\n if(row[i][0] == 8 || col[i][0] == 8) {\r\n print(\"R\");\r\n break;\r\n }\r\n if(row[i][1] == 8 || col[i][1] == 8) {\r\n print(\"B\");\r\n break;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n readline();\r\n var grid = [];\r\n for(var j = 0; j < 8; j++) {\r\n var x = readline()\r\n .trim()\r\n .split('');\r\n grid.push(x);\r\n }\r\n begin(grid);\r\n }\r\n}"}, {"source_code": "\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\nfunction begin(grid) {\r\n var row = new Array(8).fill(0).map(() => new Array(2).fill(0));\r\n var col = new Array(8).fill(0).map(() => new Array(2).fill(0));\r\n var i = 0;\r\n for(i = 0; i < 8; i++) {\r\n for(var j = 0; j < 8; j++) {\r\n if(grid[i][j] == 'R') {\r\n row[i][0]++;\r\n col[j][0]++;\r\n } else if(grid[i][j] == 'B') {\r\n row[i][1]++;\r\n col[j][1]++;\r\n }\r\n }\r\n }\r\n for( i = 0; i < 8; i++) {\r\n if(row[i][0] == 8 || col[i][0] == 8) {\r\n print(\"R\");\r\n break;\r\n }\r\n if(row[i][1] == 8 || col[i][1] == 8) {\r\n print(\"B\");\r\n break;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n readline();\r\n var grid = [];\r\n for(var j = 0; j < 8; j++) {\r\n var x = readline()\r\n .trim()\r\n .split('');\r\n grid.push(x);\r\n }\r\n begin(grid);\r\n }\r\n}\r\n "}, {"source_code": "const readline = require(\"readline\");\r\n\r\nvar tcn = 0\r\nvar space = true\r\nvar lineCnt = 0\r\nvar sumsArr = [0,0,0,0,0,0,0,0]\r\nvar res = 0\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on('line', line => {\r\n if (!tcn) return tcn = Number(line)\r\n if (space) return space = false\r\n\r\n run(line, lineCnt)\r\n lineCnt++\r\n \r\n if (lineCnt == 8) {\r\n if (!--tcn) rl.close()\r\n lineCnt = 0\r\n sumsArr = [0,0,0,0,0,0,0,0]\r\n space = true\r\n }\r\n})\r\n\r\nfunction run(line, lineCnt) {\r\n line.split('').forEach((val, idx) => {\r\n sumsArr[idx] += (val == 'R') - (val == 'B')\r\n })\r\n \r\n if (line.split('').reduce((acc, val) => {\r\n return acc += (val == 'R')\r\n }, 0) == 8) {\r\n res = 'R'\r\n }\r\n else if (line.split('').reduce((acc, val) => {\r\n return acc -= (val == 'B')\r\n }, 0) == -8) {\r\n res = 'B'\r\n }\r\n\r\n if (lineCnt == 7) {\r\n sumsArr.forEach(val => {\r\n if (val == 8) {\r\n res = 'R'\r\n return\r\n }\r\n else if (val == -8) {\r\n res = 'B'\r\n return\r\n }\r\n })\r\n console.log(res)\r\n }\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nvar tcn = 0\r\nvar space = true\r\nvar lineCnt = 0\r\nvar sumsArr = [0,0,0,0,0,0,0,0]\r\nvar res = 0\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on('line', line => {\r\n if (!tcn) return tcn = Number(line)\r\n if (space) return space = false\r\n\r\n run(line, lineCnt)\r\n lineCnt++\r\n \r\n if (lineCnt == 8) {\r\n if (!--tcn) rl.close()\r\n lineCnt = 0\r\n sumsArr = [0,0,0,0,0,0,0,0]\r\n space = true\r\n }\r\n})\r\n\r\nfunction run(line, lineCnt) {\r\n line.split('').forEach((val, idx) => {\r\n sumsArr[idx] += (val == 'R') - (val == 'B')\r\n })\r\n \r\n if (line.split('').reduce((acc, val) => {\r\n return acc = acc + (val == 'R') - (val == 'B')\r\n }, 0) == 8) {\r\n res = 'R'\r\n return\r\n }\r\n else if (line.split('').reduce((acc, val) => {\r\n return acc = acc + (val == 'R') - (val == 'B')\r\n }, 0) == -8) {\r\n res = 'B'\r\n return\r\n }\r\n\r\n if (lineCnt == 7) {\r\n sumsArr.forEach(val => {\r\n if (val == 8) {\r\n res = 'R'\r\n return\r\n }\r\n else if (val == -8) {\r\n res = 'B'\r\n return\r\n }\r\n })\r\n console.log(res)\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const arr = lines.slice(l, l + 8).map(str => str.trim())\n l += 8\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n for (let i = 0; i < 8; i++) {\n let ok = 1\n for (let j = 0; j < 8; j++) {\n if (arr[i][j] !== arr[i][0]) {\n ok = 0\n }\n }\n if (ok && arr[i][0] !== '.') return arr[i][0]\n }\n for (let j = 0; j < 8; j++) {\n let ok = 1\n for (let i = 0; i < 8; i++) {\n if (arr[i][j] !== arr[0][j]) {\n ok = 0\n }\n }\n if (ok && arr[0][j] !== '.') return arr[0][j]\n }\n // return [arr]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines.slice(l, l + 8).map(str => str.trim())\n l += 8\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n for (let i = 0; i < 8; i++) {\n let ok = 1\n for (let j = 0; j < 8; j++) {\n if (arr[i][j] !== arr[i][0]) {\n ok = 0\n }\n }\n if (ok && arr[i][0] !== '.') return arr[i][0]\n }\n for (let j = 0; j < 8; j++) {\n let ok = 1\n for (let i = 0; i < 8; i++) {\n if (arr[i][j] !== arr[0][j]) {\n ok = 0\n }\n }\n if (ok && arr[0][j] !== '.') return arr[0][j]\n }\n // return [arr]\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n let n = 8;\r\n let a = [];\r\n for (let i = 0; i <= n; i++) {\r\n if (i) a.push(read());\r\n }\r\n next: for (let i = 0; i < n; i++) {\r\n if (a[i][0] === '.') continue;\r\n let pre = '';\r\n for (let j = 0; j < n; j++) {\r\n if (!pre) pre = a[i][j];else if (pre !== a[i][j]) continue next;\r\n }\r\n return pre;\r\n }\r\n next: for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '.') continue;\r\n let pre = '';\r\n for (let j = 0; j < n; j++) {\r\n if (!pre) pre = a[j][i];else if (pre !== a[j][i]) continue next;\r\n }\r\n return pre;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "2c7add49d423de44a2bc09de56ffacf1"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const str = lines[l++]\r\n output[i] = solve(str)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(str) {\r\n let p, c\r\n const arr = []\r\n for (let i = 0; i < str.length; i++) {\r\n const x = str[i]\r\n if (x === p) {\r\n c++\r\n } else {\r\n if (c) {\r\n arr.push([p, c])\r\n }\r\n c = 1\r\n p = x\r\n }\r\n }\r\n arr.push([p, c])\r\n if (arr[0][0] === '0') arr.shift()\r\n if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()\r\n //\r\n return cal(arr)\r\n}\r\nfunction cal(arr) {\r\n if (arr.length < 2) return 0\r\n const s0 = []\r\n const s1 = []\r\n arr.forEach(([p, c], i) => {\r\n const c0 = p === '0' ? c : 0\r\n const c1 = p === '1' ? c : 0\r\n s0[i] = i ? c0 + s0[i - 1] : c0\r\n s1[i] = i ? c1 + s1[i - 1] : c1\r\n })\r\n let ans = Infinity\r\n // [i, j]\r\n const helper = (i, j) => {\r\n // j++, a--, b++\r\n const a = s1[arr.length - 1] - (j < arr.length ? (s1[j] || 0) : s1[arr.length - 1])\r\n + (s1[i - 1] || 0)\r\n const b = (s0[j] || 0) - (s0[i - 1] || 0)\r\n// if (isNaN(a) || isNaN(b)) {\r\n// console.log(arr, i, j)\r\n// throw 'sb'\r\n// }\r\n return [a - b, Math.max(a, b)]\r\n }\r\n arr.forEach(([p, c], i) => {\r\n if (p === '1') {\r\n const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)\r\n // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])\r\n ans = Math.min(\r\n ans,\r\n helper(i, k)[1],\r\n k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity\r\n )\r\n }\r\n })\r\n return ans\r\n}\r\nfunction binarySearch(l, r, fn) {\r\n while (l <= r) {\r\n const m = Math.floor((l + r) / 2)\r\n if (fn(m)) {\r\n l = m + 1\r\n } else {\r\n r = m - 1\r\n }\r\n }\r\n return r\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n let s0 = [],\r\n s1 = [];\r\n for (let i = 0; i < n; i++) {\r\n var _s, _s2;\r\n s0[i] = (_s = s0[i - 1]) !== null && _s !== void 0 ? _s : 0;\r\n s1[i] = (_s2 = s1[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0;\r\n if (s[i] === '0') s0[i]++;else s1[i]++;\r\n }\r\n const dp = [];\r\n for (let i = 0; i < n; i++) {\r\n dp[i] = s1[i] + s0[n - 1] - s0[i];\r\n }\r\n let res = Math.min(s0[n - 1], n - s0[n - 1]);\r\n for (let j = n - 1; j >= 0; j--) {\r\n const a = s1[n - 1] - s1[j],\r\n b = s0[j];\r\n if (a >= b) {\r\n res = Math.min(res, a);\r\n } else {\r\n const i = b - a - 1;\r\n res = Math.min(res, a + s1[i], b - s0[i]);\r\n }\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const s = await read();\r\n res.push(solve(s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let s = readline();\n let n = s.length;\n // PROCESSING:\n let Sl = new Array(n).fill(0);\n let Sr = new Array(n).fill(0);\n for (let i=n-1; i>=0; i--)\n Sr[i] = (i0 ? Sl[i-1] : 0) + +(s[i]=='1');\n LT({s, Sl, Sr});\n let l = 0, r = n;\n let check = (cnt)=>{\n let l = 0;\n let r = 0;\n for (let leftTake = 0; leftTake<=cnt; leftTake++){\n while (lcnt-leftTake){\n r++;\n }\n let middleItems = r-l;\n let middleZeros = middleItems-((Sl[r-1]||0)-(Sl[l-1]||0));\n if (middleZeros<=cnt)\n return true;\n }\n return false;\n }\n while (l+2>1;\n L({l, m, r})\n if (check(m)){\n r = m+1;\n } else {\n l = m+1;\n }\n }\n if (check(l))\n return l;\n if (check(l+1))\n return l+1;\n return l+2;\n};\n "}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var a = readline();\r\n var n = a.length;\r\n //print(n);\r\n var ans = 0;\r\n var max = [0];\r\n var pos = [0];\r\n var del = [0];\r\n var cur = 0;\r\n var curd = 0;\r\n for (var i = 0; i < n; i++) {\r\n ans += +(a[i] === '0');\r\n cur += +(a[i] === '0');\r\n curd += +(a[i] === '1');\r\n if (cur > max[max.length - 1]) {\r\n max.push(cur);\r\n pos.push(i + 1);\r\n del.push(curd);\r\n }\r\n }\r\n /*print('ans',ans);\r\n print('max', max);\r\n print('pos',pos);\r\n print('del', del);*/\r\n var win = 0;\r\n var r = max.length - 1;\r\n cur = 0;\r\n curd = 0;\r\n root: for (var i = n;;) {\r\n while (pos[r] > i || del[r] + curd > ans - cur - max[r]) {\r\n r--;\r\n if (r < 0) {\r\n break root;\r\n }\r\n }\r\n win = Math.max(win, cur + max[r]);\r\n //print('win', win, cur, max[r], r);\r\n if ((--i) < 0)\r\n break;\r\n cur += +(a[i] === '0');\r\n curd += +(a[i] === '1');\r\n }\r\n print(ans - win);\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let p, c\n const arr = []\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (x === p) {\n c++\n } else {\n if (c) {\n arr.push([p, c])\n }\n c = 1\n p = x\n }\n }\n arr.push([p, c])\n if (arr[0][0] === '0') arr.shift()\n if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()\n //\n return cal(arr)\n}\nfunction cal(arr) {\n if (arr.length < 2) return 0\n const s0 = []\n const s1 = []\n arr.forEach(([p, c], i) => {\n const c0 = p === '0' ? c : 0\n const c1 = p === '1' ? c : 0\n s0[i] = i ? c0 + s0[i - 1] : c0\n s1[i] = i ? c1 + s1[i - 1] : c1\n })\n let ans = Infinity\n // [i, j]\n const helper = (i, j) => {\n // j++, a--, b++\n const a = s1[arr.length - 1] - (j < arr.length ? s1[j] : s1[arr.length - 1])\n + (s1[i - 1] || 0)\n const b = (s0[j] || 0) - (s0[i - 1] || 0)\n return [a - b, Math.max(a, b)]\n }\n// console.log(arr, s0, s1)\n arr.forEach(([p, c], i) => {\n if (p === '1') {\n const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)\n // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])\n ans = Math.min(\n ans,\n helper(i, k)[1],\n k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity\n )\n }\n })\n return ans\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let p, c\n let total0 = 0\n const arr = []\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (x === p) {\n c++\n } else {\n if (c) {\n arr.push([p, c])\n if (p === '0') total0 += c\n }\n c = 1\n p = x\n }\n }\n arr.push([p, c])\n if (p === '0') total0 += c\n// console.log(arr, total0)\n let i = 0\n let j = arr.length - 1\n let ans1 = 0\n while (i <= j) {\n if (arr[i][0] === '0') {\n total0 -= arr[i][1]\n i++\n } else if (arr[j][0] === '0') {\n total0 -= arr[j][1]\n j--\n } else if (arr[i][1] <= arr[j][1]) {\n const cur = Math.max(ans1, total0)\n let ok = false\n if (i + 1 <= j) {\n const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[i][1]\n i++\n }\n }\n if (!ok && j - 1 >= i) {\n const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[j][1]\n j--\n }\n }\n if (!ok) break\n } else {\n const cur = Math.max(ans1, total0)\n let ok = false\n if (j - 1 >= i) {\n const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[j][1]\n j--\n }\n }\n if (!ok && i + 1 <= j) {\n const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[i][1]\n i++\n }\n }\n if (!ok) break\n }\n }\n // let ans0 = 0\n // for (let k = i; k <= j; k++) {\n // if (arr[k][0] === '0') ans0 += arr[k][1]\n // }\n return Math.max(total0, ans1)\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let p, c\n let total0 = 0\n const arr = []\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (x === p) {\n c++\n } else {\n if (c) {\n arr.push([p, c])\n if (p === '0') total0 += c\n }\n c = 1\n p = x\n }\n }\n arr.push([p, c])\n if (p === '0') total0 += c\n// console.log(arr, total0)\n let i = 0\n let j = arr.length - 1\n let ans1 = 0\n while (i <= j) {\n if (arr[i][0] === '0') {\n total0 -= arr[i][1]\n i++\n } else if (arr[j][0] === '0') {\n total0 -= arr[j][1]\n j--\n } else if (arr[i][1] <= arr[j][1]) {\n const cur = Math.max(ans1, total0)\n let ok = false\n if (i + 1 <= j) {\n const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[i][1]\n i++\n }\n }\n if (!ok) break\n } else {\n const cur = Math.max(ans1, total0)\n let ok = false\n if (j - 1 >= i) {\n const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])\n if (next <= cur) {\n ok = true\n ans1 += arr[j][1]\n j--\n }\n }\n if (!ok) break\n }\n }\n // let ans0 = 0\n // for (let k = i; k <= j; k++) {\n // if (arr[k][0] === '0') ans0 += arr[k][1]\n // }\n return Math.max(total0, ans1)\n}\n"}], "src_uid": "ea616a6b4ba7bf8742420b1c29ff0d16"} {"source_code": "function main(n){\n\n print(n+1);\n print(\"2 \" + n + \" \" + 1);\n print(\"1 \" + n + \" \" + 1000000);\n for(var i = 1 ; i < n ; i++)print(\"2 \" + i + \" \" + (1000000-i+1));\n\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \");\nmain(n);\n", "positive_code": [{"source_code": "n = +readline();\nres = (n+1)+'\\n1 '+n+' 500000\\n';\nar = readline().split(' ').forEach((num,ind)=>{\n num = +num;\n res += '2 '+ (ind + 1) +' '+(num + 500000 - ind)+'\\n';\n});\nprint(res);"}], "negative_code": [{"source_code": "n = +readline();\nres = (n+1)+'\\n1 '+n+' 500000\\n';\nar = readline().split(' ').forEach((num,ind)=>{\n num = +num;\n res += '2 '+ ind +' '+(num - ind)+'\\n';\n});\nprint(res);"}, {"source_code": "n = +readline();\nres = '1 '+n+' 500000\\n';\nar = readline().split(' ').forEach((num,ind)=>{\n num = +num;\n res += '2 '+ ind +' '+(num - ind)+'\\n';\n});\nprint(res);"}, {"source_code": "function main(n){\n\n print(n+1);\n print(\"2 \" + n + \" \" + 1);\n print(\"1 \" + n + \" \" + 1000000);\n for(var i = 1 ; i < n ; i++)print(\"2 \" + i + \" \" + 1000000 - i + 1 );\n\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \");\nmain(n);\n"}], "src_uid": "e0ba8e0bfd9e1365daa41e1d14610200"} {"source_code": "var i = 3;\nvar res = [];\nvar slogs = ['a', 'e', 'i', 'o', 'u'];\nwhile(i--) {\n\tvar str = readline();\n\tvar curr = 0;\n\tfor (var j = 0; j < str.length; j++) {\n\t\tif (slogs.indexOf(str[j]) !== -1) {\n\t\t\tcurr++;\n\t\t}\n\t}\n\tres.push(curr);\n}\n\nvar check = (res[0] === 5 && res[1] === 7 && res[2] === 5);\nprint( check ? 'YES' : 'NO');", "positive_code": [{"source_code": "print(function(a, b, c) {\n\n\treturn cnt(a) === 5 && cnt(b) === 7 && cnt(c) === 5 ? 'YES' : 'NO';\n\n\tfunction cnt(s) {\n\t\treturn s.split(/[aeiou]/).length - 1;\n\t}\n\n}(readline(), readline(), readline()));"}, {"source_code": ";(function () {\n\n\tprint(function () {\n\n\t\tvar s = [], n = 3, l = ['a', 'e', 'i', 'o', 'u'];\n\t\twhile (n--) s.push(readline().split('').filter(function (e) { return l.indexOf(e) !== -1; }));\n\n\t\treturn (s[0].length === 5 && s[1].length === 7 && s[2].length === 5) ? 'YES' : 'NO';\n\n\t}());\n\n}.call(this));\n"}, {"source_code": "function count(s) {\n var n = 0;\n for (var c of s)\n if (\"aeiou\".includes(c)) n++;\n return n;\n}\n\nprint(count(readline()) === 5 && count(readline()) === 7 && count(readline()) === 5 ? \"YES\" : \"NO\");\n"}, {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n const ils = ipt.split(EOL).slice(0, -1)\n console.log(\n (ils[0].match(/[aeiou]/g) || '').length == 5\n && (ils[1].match(/[aeiou]/g) || '').length == 7\n && (ils[2].match(/[aeiou]/g) || '').length == 5\n ? 'YES'\n : 'NO'\n )\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst vowels = ['a', 'e', 'i', 'o', 'u'];\nconst arr = [];\n\nrl.on('line', (str) => {\n arr.push(str);\n});\n\nrl.on('close', () => {\n let r = [5, 7, 5];\n let ans = 'YES';\n\n for (let i = 0; i < arr.length; i++) {\n const v = r[i];\n let count = 0;\n\n for (let j = 0; j < arr[i].length; j++) {\n if (vowels.includes(arr[i][j])) {\n count++;\n }\n }\n\n if (count !== v) {\n ans = 'NO';\n break;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "'use strict';\n\n/*let input = `how many gallons\nof edo s rain did you drink\n cuckoo`.split('\\n');\nfunction print(out) {\n console.log(out);\n}\nfunction readline() {\n return input.shift();\n}*/\n\n//code\n\nvar l1 = readline();\nvar l2 = readline();\nvar l3 = readline();\nvar result = [l1, l2, l3].map(function (line) {\n return line.split('').filter(function (char) {\n return ['a', 'e', 'i', 'o', 'u'].includes(char);\n }).length;\n});\nif (result[0] === 5 && result[1] === 7 && result[2] === 5) {\n print('YES');\n} else {\n print('NO');\n}\n"}], "negative_code": [], "src_uid": "46d734178b3acaddf2ee3706f04d603d"} {"source_code": "var n = +readline();\nvar m = +readline();\nvar a = new Array(n);\nwhile (n--) {\n a.push(+readline());\n}\na.sort((ai, aj) => aj - ai);\nvar minCount = 0;\nvar sumVolume = 0;\nwhile (sumVolume < m) {\n sumVolume += a[minCount++];\n}\nwrite(minCount + \"\\n\");\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet m;\nconst arr = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n m = +d;\n c++;\n return;\n }\n\n arr.push(+d);\n\n c++;\n});\n\nrl.on('close', () => {\n arr.sort((a, b) => b - a);\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n m -= arr[i];\n ans++;\n\n if (m <= 0) {\n break;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "var n = +readline()\nvar m = +readline()\nvar a = []\n\nfor (var i = 0; i < n; i++)\n{\n\ta.push(+readline())\n}\n\nfunction descendingComparator(a, b){return b-a}\n\na.sort(descendingComparator)\n\nvar numOfDrives = 0\nvar availableSpace = 0\n\nfor (var i = 0; i < n && availableSpace < m; i++)\n{\n\tnumOfDrives++;\n\tavailableSpace += a[i];\n}\n\nprint(numOfDrives)"}, {"source_code": "n = +readline();\nm = +readline();\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(+readline());\n}\na.sort(function(a,b){return b - a;});\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += +a[i];\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = parseInt(readline());\nm = parseInt(readline());\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort((a,b)=>b-a);\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += a[i];\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = +readline();\nm = +readline();\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(+readline());\n}\na.sort((a,b)=>b-a);\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += +a[i];\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "var USB = readline();\nvar size = readline();\nvar usbArr = [], sum=0, howMany=0;\n\nfor(var i=0; i= m) return count;\n count++;\n sum += a[i];\n }\n\n return count;\n}\nvar n = parseInt(readline());\nvar m = parseInt(readline());\n\nvar d = [];\nfor(var k = 0; k < n; k++) {\n d.push(parseInt(readline()));\n}\n\nprint(drives(m, d));\n\n// console.log(drives(5, [2, 1, 3]));\n\n"}], "negative_code": [{"source_code": "n = parseInt(readline());\nm = parseInt(readline());\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort();\na.reverse();\nvar sum = parseInt(0);\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += parseInt(a[i]);\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = parseInt(readline());\nm = parseInt(readline());\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort();\na.reverse();\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += a[i];\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = readline();\nm = readline();\na = [];\nfor (i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort();\na.reverse();\n\nvar sum = 0;\nfor (i = 0 ; i < n ; i ++){\n sum += a[i];\n if (sum >= m){\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = parseInt(readline());\nm = parseInt(readline());\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort((a,b)=>b-a);\na.reverse();\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += a[i];\n print(sum);\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}, {"source_code": "n = parseInt(readline());\nm = parseInt(readline());\na = [];\nfor (var i = 0 ; i < n ; i ++)\n{\n a.push(parseInt(readline()));\n}\na.sort((a,b)=>b-a);\nvar sum = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n sum += a[i];\n print(sum);\n if (sum >= m)\n {\n write(i + 1);\n break;\n }\n}"}], "src_uid": "a02a9e37a4499f9c86ac690a3a427466"} {"source_code": "/*only to understand how to use JS on codeforces*/\n\nvar t = +readline()\nfor ( var i = 0 ; i < t ; i++ ) {\n var n = +readline()\n , s = readline()\n , p = s.indexOf('8')\n if ( p != -1 && n - p >= 11 )\n print('YES')\n else\n print('NO')\n}", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n lines.push(line);\n});\n\nconst processLine = (len, str) => {\n if (len < 11) {\n return 'NO';\n }\n\n const prefixPosition = str.indexOf('8');\n if (prefixPosition === -1) {\n return 'NO';\n }\n\n if (len - prefixPosition >= 11) {\n return 'YES';\n }\n\n return 'NO';\n};\n\nreadline.on('close', () => {\n const [t, ...cases] = lines;\n\n for (let i = 0; i < Number(t) * 2; i += 2) {\n const len = cases[i];\n const str = cases[i + 1];\n console.log(processLine(len, str));\n }\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet i = 0;\n\nreadline.on('line', line => {\n if (i > 0 && i%2 == 0) {\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n console.log('YES');\n else\n console.log('NO');\n }\n i++;\n});\n"}, {"source_code": "const { createInterface } = require('readline');\nconst lines = []\n\nfunction solve() {\n const t = +lines[0];\nfor (let i =2; i <= t * 2; i+=2 ) {\n const s = lines[i]\n const l = lines[i].length;\n const pos8 = s.indexOf('8');\n if (pos8 === -1 || (l - pos8) < 11) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n}\n}\n( function processLineByLine() {\n const rl = createInterface({\n input: process.stdin\n });\n\n rl.on('line', (line) => {\n lines.push(line);\n });\n rl.on('close', solve)\n\n\n})();\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet i = 0, result = '';\n\nreadline.on('line', line => {\n if (i > 0 && i%2 == 0) {\n line = line.trim();\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n console.log('YES');\n else\n console.log('NO');\n }\n i++;\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet i = 0, result = '';\n\nreadline.on('line', line => {\n if (i > 0 && i%2 == 0) {\n line = line.trim();\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n result += 'YES\\n';\n else\n result += 'NO\\n';\n }\n i++;\n});\n\nreadline.on('close', () => {\n console.log(result);\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet i = 0;\n\nreadline.on('line', line => {\n if (i > 0 && i%2 == 0) {\n line = line.trim();\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n console.log('YES');\n else\n console.log('NO');\n }\n i++;\n});\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n\n for(var i = 0; i < n ;i++) {\n var l = read.number();\n var s = readline();\n \n \n\n if(l >= 11 && s.slice(0,l - 10).indexOf('8') > -1) {\n print('YES');\n }\n else {\n print('NO');\n }\n }\n}());"}, {"source_code": "var t = +readline()\nfor ( var i = 0 ; i < t ; i++ ) {\n var n = +readline()\n , s = readline()\n , p = s.indexOf('8')\n if ( p != -1 && n - p >= 11 )\n print('YES')\n else\n print('NO')\n}\n"}, {"source_code": "class CodeForcesNodeJS\n{\n constructor()\n {\n this.stdin_input = \"\";\n this.arrInput = [];\n this.nInputIndex = 0;\n }\n\n start()\n {\n process.stdin.resume();\n process.stdin.setEncoding(\"utf-8\");\n\n process.stdin.on(\"data\", this.onData.bind(this));\n process.stdin.on(\"end\", this.solveWrapper.bind(this));\n }\n\n onData(input)\n {\n this.stdin_input += input;\n }\n\n prepareInput(input)\n {\n this.arrInput = input.replace(/\\n/g, \" \").split(\" \");\n this.nInputIndex = 0;\n }\n\n nextInput(strConvertType = null)\n {\n let _response = this.arrInput[this.nInputIndex];\n ++this.nInputIndex;\n\n if(typeof _response === \"undefined\")\n {\n throw new Error(\"End of input reached.\");\n }\n\n if(typeof _response !== \"string\")\n {\n throw new Error(\"Internal Error: input at current step not an instance of string!\");\n }\n\n switch(strConvertType)\n {\n case \"Integer\":\n _response = parseInt(_response, 10);\n break;\n\n case null:\n break;\n\n default:\n throw new Error(\"Unrecognized type for conversion!\");\n }\n\n return _response;\n\n }\n\n async solveWrapper()\n {\n this.prepareInput(this.stdin_input);\n await this.solve().catch(console.error);\n }\n\n solve()\n {\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const _count = this.nextInput(\"Integer\");\n for(let index = 0; index < _count; ++index)\n {\n const _length = this.nextInput(\"Integer\");\n const _string = this.nextInput();\n\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))\n {\n process.stdout.write(\"NO\\n\");\n }\n else\n {\n process.stdout.write(\"YEs\\n\");\n }\n }\n }\n}\n\nconst _solver = new CodeForcesNodeJS();\n_solver.start();"}, {"source_code": "function main(input) {\n try\n {\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const arrInput = input.replace(/\\n/g, \" \").split(\" \");\n let _input_index = 0;\n\n const _count = parseInt(arrInput[_input_index++], 10);\n for(let index = 0; index < _count; ++index)\n {\n const _length = parseInt(arrInput[_input_index++], 10);\n const _string = arrInput[_input_index++];\n\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))\n {\n process.stdout.write(\"NO\\n\");\n }\n else\n {\n process.stdout.write(\"YEs\\n\");\n }\n }\n }\n catch(_error)\n {\n console.log(_error);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "var t=+readline()\nfor(var i=0;i=11) print('YES')\n\telse print('NO')\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const idx = str.indexOf('8');\n const len = str.length - idx;\n\n if (idx === -1) {\n console.log('NO');\n }\n else if (len >= 11) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let k = parseInt(input[0]);\n\n for(let i = 2; i <= k*2; i+=2){\n let flag = false; let pos = 0;\n [...input[i]].forEach( (j, index) => {\n if(j === '8' && !flag){\n flag = true; pos = index; return;\n }\n });\n if(flag && input[i].length - pos >= 11)\n console.log(\"YES\");\n else\n console.log(\"NO\");\n }\n});\n\n"}], "negative_code": [{"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let k = parseInt(input[0]);\n\n for(let i = 2; i <= k*2; i+=2){\n let flag = false; let pos = 0;\n [...input[i]].forEach( (j, index) => {\n if(j === '8' && !flag){\n flag = true; pos = index; return;\n }\n });\n if(flag && input[i].length - pos >= 8)\n console.log(\"YES\");\n else\n console.log(\"NO\");\n }\n});\n\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let k = parseInt(input[0]);\n\n for(let i = 2; i <= k*2; i+=2){\n let flag = false; let pos = 0;\n [...input[i]].forEach( (j, index) => {\n if(j === '8' && !flag){\n flag = true; pos = index+1; return;\n }\n });\n if(flag && input[i].length - pos >= 8)\n console.log(\"YES\");\n else\n console.log(\"NO\");\n }\n});\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n});\n\nconst lines = [];\n\nreadline.on('line', (line) => {\n lines.push(line);\n});\n\nconst processLine = (len, str) => {\n if (len < 11) {\n return 'NO';\n }\n\n const prefixPosition = str.indexOf('8');\n if (prefixPosition === -1) {\n return 'NO';\n }\n\n if (len - prefixPosition >= 11) {\n return 'YES';\n }\n\n return 'NO';\n};\n\nreadline.on('close', () => {\n const [t, ...cases] = lines;\n\n for (let i = 0; i < Number(t); i += 1) {\n const len = cases[i];\n const str = cases[i + 1];\n console.log(processLine(len, str));\n }\n});\n"}, {"source_code": "let i = 0;\nprocess.stdin.on('data', line => {\n if (i > 0 && i%2 == 0) {\n line = line.toString().trim();\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n console.log('YES');\n else\n console.log('NO');\n }\n i++;\n});\n"}, {"source_code": "let i = 0, result = '';\n\nprocess.stdin.on('data', line => {\n if (i > 0 && i%2 == 0) {\n line = line.toString().trim();\n let pos = line.length;\n for (let i = 0; i < line.length; i++)\n if (line[i] == '8') {\n pos = i;\n break;\n }\n if (line.length - pos >= 11)\n result += 'YES\\n';\n else\n result += 'NO\\n';\n }\n i++;\n});\n\nprocess.stdin.on('end', () => {\n console.log(result);\n});\n"}, {"source_code": "function main(input) {\n try\n {\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const arrInput = input.replace(/\\n/g, \" \").split(\" \");\n let _input_index = 0;\n\n const _count = parseInt(arrInput[_input_index++], 10);\n for(let index = 0; index < _count; ++i)\n {\n const _length = parseInt(arrInput[_input_index++], 10);\n const _string = arrInput[_input_index++];\n\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))\n {\n process.stdout.write(\"NO\\n\");\n }\n else\n {\n process.stdout.write(\"YEs\\n\");\n }\n }\n }\n catch(_error)\n {\n console.log(_error);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "function main(input) {\n try\n {\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const arrInput = examinputle.replace(/\\n/g, \" \").split(\" \");\n let _input_index = 0;\n\n const _count = parseInt(arrInput[_input_index++], 10);\n for(let index = 0; index < _count; ++i)\n {\n const _length = parseInt(arrInput[_input_index++], 10);\n const _string = arrInput[_input_index++];\n\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1)\n {\n print(\"NO\");\n }\n else if((_length - _start_index) >= _FIXED_LENGTH)\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n }\n }\n catch(_error)\n {\n console.log(_error);\n }\n process.stdout.write(\"\\n Your input multiplied by 10=\"+input*10);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "try\n{\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const _count = parseInt(readline(), 10);\n for(let index = 0; index < _count; ++i)\n {\n const _length = parseInt(readline(), 10);\n const _string = readline();\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1)\n {\n print(\"NO\");\n }\n else if((_length - _start_index) >= _FIXED_LENGTH)\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n }\n}\ncatch(_error)\n{\n console.log(_error);\n}"}, {"source_code": "try\n{\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const _count = parseInt(readline(), 10);\n for(let index = 0; index < _count; ++i)\n {\n const _length = parseInt(readline(), 10);\n const _string = readline();\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1)\n {\n print(\"NO\");\n }\n else if((_length - _start_index) >= _FIXED_LENGTH)\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n }\n}\ncatch(_error)\n{\n console.error(_error);\n}"}, {"source_code": "function main(input) {\n try\n {\n const _FIXED_LENGTH = 11;\n const _START_CHAR = \"8\";\n\n const arrInput = input.replace(/\\n/g, \" \").split(\" \");\n let _input_index = 0;\n\n const _count = parseInt(arrInput[_input_index++], 10);\n for(let index = 0; index < _count; ++i)\n {\n const _length = parseInt(arrInput[_input_index++], 10);\n const _string = arrInput[_input_index++];\n\n const _start_index = _string.indexOf(_START_CHAR);\n\n if(_start_index === -1)\n {\n print(\"NO\");\n }\n else if((_length - _start_index) >= _FIXED_LENGTH)\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n }\n }\n catch(_error)\n {\n console.log(_error);\n }\n process.stdout.write(\"\\n Your input multiplied by 10=\"+input*10);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const idx = str.indexOf('8');\n const len = str.length - idx;\n\n if (idx === -1) {\n console.log('NO');\n }\n else if (len >= 10) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n if (str.length < 11) {\n console.log('NO');\n return;\n }\n\n const idx = str.indexOf('8');\n\n if (idx === -1) {\n console.log('NO');\n }\n else {\n const len = str.length - idx;\n\n if (len <= 11) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n if (str.length < 11) {\n console.log('NO');\n return;\n }\n\n const idx = str.indexOf('8');\n\n if (idx === -1) {\n console.log('NO');\n }\n else {\n const len = str.length - idx;\n\n if (len < 11) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const idx = str.indexOf('8');\n const len = str.length - idx;\n\n if (len >= 10) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n if (str.length < 11) {\n console.log('NO');\n return;\n }\n\n let i = 0;\n while (str.length > 11 && i < str.length) {\n if (str[i] !== '8') {\n str = str.substr(0, i) + str.substr(i + 1);\n i = 0;\n }\n else {\n i++;\n }\n }\n\n if (str.length === 11 && str[0] === '8') {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const idx = str.indexOf('8');\n const len = str.length - idx;\n\n if (idx === -1) {\n console.log('NO');\n return;\n }\n\n if (len >= 10) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n\n for(var i = 0; i < n ;i++) {\n var l = read.number();\n var s = readline();\n \n \n\n if(l >= 11 && s.slice(0,l - 11).indexOf('8') > -1) {\n print('YES');\n }\n else {\n print('NO');\n }\n }\n}());"}, {"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n\n for(var i = 0; i < n ;i++) {\n var l = read.number();\n var s = readline();\n\n if(l >= 11 && s[l - 12] === '8') {\n print('YES');\n }\n else {\n print('NO');\n }\n }\n}());"}], "src_uid": "bcdd7862b718d6bcc25c9aba8716d487"} {"source_code": "/**\n * Created by Grizix\n */\n\nfunction readIntTabLine(n) {\n var l = readline().split(' ')\n for (var i = 0 ; i < n ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar n = parseInt(readline())\n\nreadline()\n\nvar p = readIntTabLine(2),\n dir = 1,\n result = 0\n\nfor (var i = 1 ; i < n ; i ++) {\n var np = readIntTabLine(2)\n switch (dir) {\n case 1:\n if (np[0] < p[0]) result++, dir = 4\n else dir = 2\n break\n case 2:\n if (np[1] > p[1]) result++, dir = 1\n else dir = 3\n break\n case 3:\n if (np[0] > p[0]) result++, dir = 2\n else dir = 4\n break\n case 4:\n if (np[1] < p[1]) result++, dir = 3\n else dir = 1\n break\n }\n p = np\n}\n\nprint(result)\n", "positive_code": [{"source_code": "function isLeft(point1, point2, point3) {\n if (point1[0] === point2[0] &&\n point2[1] === point3[1]) {\n if (point2[1] > point1[1]) {\n return point3[0] < point2[0];\n } else {\n return point3[0] > point2[0];\n }\n } else {\n if (point2[0] > point1[0]) {\n return point3[1] > point2[1];\n } else {\n return point3[1] < point2[1];\n }\n }\n}\n\nvar arr = readline().split(\" \", 1).map(Number);\nvar n = arr[0], xArr, yArr, ans = 0;\nfor (var i = 0; i <= n; ++i) {\n arr = readline().split(\" \", 2).map(Number);\n if (i === 0) {\n xArr = arr;\n } else if (i === 1) {\n yArr = arr;\n } else {\n if (isLeft(xArr, yArr, arr)) {\n ++ans;\n }\n xArr = yArr;\n yArr = arr;\n }\n}\nprint(ans);"}], "negative_code": [], "src_uid": "0054f9e2549900487d78fae9aa4c2d65"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(1, t, i => {\n let n = inp[r++];\n let a = inp.slice(r,r=r+n);\n let c = Arr(0,100,i=>a.filter(v=>v==i).length);\n let d1 = Arr(0,101).find(i=>c[i]<1);\n let d2 = Arr(0,101).find(i=>c[i]<2);\n console.log(d1+d2);\n })\n})();", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const [arr1, arr2] = [Array(101).fill(0), Array(101).fill(0)];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (arr1[n] !== 0) arr2[n]++;\n else arr1[n]++;\n return n;\n });\n let ans = 0;\n\n for (let i = 0; i < arr1.length; i++) {\n if (arr1[i] === 0) {\n ans += i;\n break;\n }\n }\n\n for (let i = 0; i < arr2.length; i++) {\n if (arr2[i] === 0) {\n ans += i;\n break;\n }\n }\n console.log(ans);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tlist.sort(function(a, b){\n\t\t\treturn a - b;\n\t\t});\n\t\tvar a = [];\n\t\tvar b = [];\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(a.indexOf(list[j]) == -1){\n\t\t\t\ta.push(list[j]);\n\t\t\t}else{\n\t\t\t\tb.push(list[j]);\n\t\t\t}\n\t\t}\n\t\tvar amin = 0;\n\t\tvar bmin = 0;\n\t\tfor(var j = 0; j <= 100; j++){\n\t\t\tif(a.indexOf(j) != -1){\n\t\t\t\tamin++;\n\t\t\t}else{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(var j = 0; j <= 100; j++){\n\t\t\tif(b.indexOf(j) != -1){\n\t\t\t\tbmin++;\n\t\t\t}else{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\toutput[i] = amin + bmin;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 0\n const counts = []\n for (let i = 0; i <= 100; i++) {\n counts.push(0)\n }\n\n for (let i = 0, l = a.length; i < l; i++) {\n counts[a[i]] += 1\n }\n\n let add = 2\n\n if (counts[0] === 0) {\n out += '0\\n'\n continue\n } else if (counts[0] === 1) {\n add = 1\n }\n\n for (let i = 1; i <= 100; i++) {\n const x = counts[i]\n result += add\n if (x === 0) break\n else if (x === 1) {\n add = 1\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testQtd = readline();\n\n for (let i = 0; i < testQtd; i++) {\n const length = parseInt(readline());\n if (length === 0) {\n console.log(0);\n continue;\n }\n\n const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);\n\n let a = [];\n let b = [];\n let bigger = array[0]\n\n for (let i = 0; i < array.length; i++) {\n if (array[i] > bigger) {\n bigger = array[i];\n }\n\n const found = a.find(x => x === array[i]);\n\n if (found !== undefined) {\n b.push(array[i]);\n } else {\n a.push(array[i]);\n }\n }\n\n\n let respA = null;\n let respB = null;\n for (let i = 0; i <= bigger + 1; i++) {\n if (respA === null && a.find(x => x === i) === undefined) {\n respA = i;\n }\n if (respB === null && b.find(x => x === i) === undefined) {\n respB = i;\n }\n\n if (respA !== null && respB !== null) {\n console.log(respA + respB);\n break;\n }\n }\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\n const testQtd = readline();\n\n for (let i = 0; i < testQtd; i++) {\n const length = parseInt(readline());\n if (length === 0) {\n console.log(0);\n continue;\n }\n\n const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);\n\n let a = [];\n let aIsDead = false;\n let b = [];\n let bIsDead = false;\n let bigger = array[0]\n\n for (let i = 0; i < array.length; i++) {\n if (array[i] > bigger) {\n bigger = array[i];\n }\n\n if (!aIsDead) {\n const found = a.find(x => x === array[i]);\n\n if (found !== undefined) {\n if (!bIsDead) {\n b.push(array[i]);\n }\n } else {\n a.push(array[i]);\n }\n } else {\n if (!bIsDead) {\n b.push(array[i]);\n }\n }\n }\n\n\n let respA = null;\n let respB = null;\n for (let i = 0; i <= bigger + 1; i++) {\n if (respA === null && a.find(x => x === i) === undefined) {\n respA = i;\n }\n if (respB === null && b.find(x => x === i) === undefined) {\n respB = i;\n }\n\n if (respA !== null && respB !== null) {\n console.log(respA + respB);\n break;\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let arr = ti(readline().split(' '));\n\n let map = new Array(105);\n map.fill(0);\n let max = 0;\n for(let i = 0; i < n; i++){\n map[arr[i]] += 1;\n max = Math.max(max, arr[i]);\n }\n\n if(map[0] === 0){\n console.log(0);\n continue;\n }\n\n let a = [];\n let b = [];\n let aMax = 0;\n let bMax = 0;\n for(let i = 0; i <= max; i++){\n if(map[i] >= 2){\n a.push(i);\n b.push(i);\n aMax = i;\n bMax = i;\n }else if(map[i] !== 0){\n a.push(i);\n aMax = i;\n }\n }\n\n let res = 0;\n let mapA = new Array(aMax+2);\n let mapB = new Array(bMax+2);\n mapA.fill(0);\n mapB.fill(0);\n for(let i = 0; i < a.length; i++)\n mapA[a[i]] = 1;\n\n for(let i = 0; i < b.length; i++)\n mapB[b[i]] = 1;\n\n for(let i = 0; i < aMax+2; i++){\n if(mapA[i] === 0){\n res += i;\n break;\n }\n }\n\n for(let i = 0; i < bMax+2; i++){\n if(mapB[i] === 0){\n res += i;\n break;\n }\n }\n\n if(res === 0)\n console.log(max + 1);\n else\n console.log(res);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let neg = [];\n let pos = [];\n\n for(let i = 0; i < n; i++){\n if(a[i] < 0){\n neg.push({val: a[i], index: i});\n }else{\n pos.push({val: a[i], index: i});\n }\n }\n\n neg.sort((a,b) => a.val - b.val);\n pos.sort((a,b) => b.val - a.val);\n\n\n }\n}"}, {"source_code": "var cases = parseInt(readline());\nfor(var i = 0; iparseInt(x));\n input.sort(function(a,b){return a-b});\n var A = [];\n var B = [];\n var result = 0;\n for(var j = 0; j< input.length; j ++){\n if(!A.includes(input[j]))A.push(input[j]);\n else B.push(input[j]);\n }\n for(var x of [A,B]){\n var n = find(x);\n result+=n;\n }\n print(result);\n}\n\nfunction find (input){\n for(var k=0; k<=input[input.length-1]+1; k++){\n if(!input.includes(k)) return k;\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "e26b0b117593c159b7f01cfac66a71d1"} {"source_code": "// process.stdin.setEncoding('utf8');\nlet lines = [];\n// process.stdin.on('readable', () => {\n// let chunk;\n// // Use a loop to make sure we read all available data.\n// while ((chunk = process.stdin.read()) !== null) {\n// lines.push(chunk);\n// process.stdout.write('end');\n// if (lines.length === 2) {\n// process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);\n// lines = [];\n// }\n// }\n// });\n\n// process.stdin.on('end', () => {\n// process.stdout.write('end');\n// });\n\nvar readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function (line) {\n lines.push(line);\n if (lines.length === 2) {\n console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);\n lines = [];\n rl.close();\n }\n})\n\nfunction buildKey(str) {\n if ((str.length % 2) != 0) return str;\n const mid = str.length / 2;\n const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));\n if (lkey <= rkey) {\n return `${lkey}${rkey}`;\n } else {\n return `${rkey}${lkey}`;\n }\n}\n\nfunction equivalent(strA, strB) {\n // process.stdout.write('[' + strA + '-' + strB + ']')\n if (strA.length !== strB.length) {\n return false;\n }\n // condition 1\n if (strA === strB) {\n return true;\n }\n // condition 2\n const length = strA.length;\n if ((length % 2) === 0) {\n const mid = length / 2;\n const a1 = strA.slice(0, mid), a2 = strA.slice(mid);\n const b1 = strB.slice(0, mid), b2 = strB.slice(mid);\n if (equivalent(a1, b1) && equivalent(a2, b2))\n return true;\n if (equivalent(a1, b2) && equivalent(a2, b1))\n return true;\n }\n\n return false;\n}", "positive_code": [{"source_code": "var print = this.print || require(\"lol-io\").print;\nvar readline = this.readline || require(\"lol-io\").readline;\n\nconst s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length % 2) return s1 === s2;\n\n const n = s1.length;\n const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);\n const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}, {"source_code": "var print = this.print || require(\"lol-io\").print;\nvar readline = this.readline || require(\"lol-io\").readline;\n\nconst s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length & 1) return s1 === s2;\n\n const n = s1.length;\n const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);\n const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}, {"source_code": "function equal(a, b) {\n var size = a.length;\n var half = a.length / 2;\n \n var a1 = a.substr(0,half);\n var a2 = a.substr(half,a.length);\n var b1 = b.substr(0,half);\n var b2 = b.substr(half,b.length);\n \n if (a === b) {\n return true;\n } else if (size % 2 === 1 || size <= 1) {\n return false;\n } else if (equal(a1, b2) && equal(a2, b1)) {\n return true;\n } else if (equal(a1, b1) && equal(a2, b2)) {\n return true;\n } else {\n return false;\n }\n}\n\nvar input_a = readline();\nvar input_b = readline();\n\nequal(input_a, input_b) ? print('YES') : print('NO');"}, {"source_code": "const s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length % 2 === 1) return s1 === s2;\n\n const n = s1.length;\n const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);\n const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}], "negative_code": [{"source_code": "const s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length === 1 || s1 === s2) return s1 === s2;\n\n n = s1.length;\n a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);\n b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}, {"source_code": "const s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length % 2 === 1 || s1 === s2) return s1 === s2;\n\n n = s1.length;\n a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);\n b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}, {"source_code": "const s1 = readline(); const s2 = readline();\nprint(is_equivalent(s1, s2) ? 'YES' : 'NO');\n\nfunction is_equivalent(s1, s2) {\n if(s1.length % 2 === 1) return s1 === s2;\n\n n = s1.length;\n a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);\n b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2); \n return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));\n}\n"}, {"source_code": "var a = 'aaba'.split('');\nvar b = 'abaa'.split('');\n\nif (a.length != b.length) {\n print('NO');\n} else {\n for (var index = 0; index < a.length; index++) {\n for (var j = 0; j < a.length - 1; j++) {\n if (a[j] < a[j + 1]) {\n aux = a[j];\n a[j] = a[j + 1];\n a[j + 1] = aux;\n }\n if (b[j] < b[j + 1]) {\n aux = b[j];\n b[j] = b[j + 1];\n b[j + 1] = aux;\n }\n }\n }\n if (a.join() == b.join()) {\n print('YES');\n } else {\n print('NO');\n }\n}\n"}, {"source_code": "// process.stdin.setEncoding('utf8');\nlet lines = [];\n// process.stdin.on('readable', () => {\n// let chunk;\n// // Use a loop to make sure we read all available data.\n// while ((chunk = process.stdin.read()) !== null) {\n// lines.push(chunk);\n// process.stdout.write('end');\n// if (lines.length === 2) {\n// process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);\n// lines = [];\n// }\n// }\n// });\n\n// process.stdin.on('end', () => {\n// process.stdout.write('end');\n// });\n\nvar readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function (line) {\n lines.push(line);\n if (lines.length === 2) {\n console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);\n lines = [];\n rl.close();\n }\n})\n\nfunction buildKey(str) {\n if ((str % 2) != 0) return str;\n\n const mid = str.length / 2;\n const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));\n if (lkey <= rkey) {\n return `${lkey}${rkey}`;\n } else {\n return `${rkey}${lkey}`;\n }\n}\n\nfunction equivalent(strA, strB) {\n // process.stdout.write('[' + strA + '-' + strB + ']')\n if (strA.length !== strB.length) {\n return false;\n }\n // condition 1\n if (strA === strB) {\n return true;\n }\n // condition 2\n const length = strA.length;\n if ((length % 2) === 0) {\n const mid = length / 2;\n const a1 = strA.slice(0, mid), a2 = strA.slice(mid);\n const b1 = strB.slice(0, mid), b2 = strB.slice(mid);\n if (equivalent(a1, b1) && equivalent(a2, b2))\n return true;\n if (equivalent(a1, b2) && equivalent(a2, b1))\n return true;\n }\n\n return false;\n}"}], "src_uid": "21c0e12347d8be7dd19cb9f43a31be85"} {"source_code": "var nt = readline().split(' ').map(v=>(parseInt(v)))\nvar n = nt[0]\nvar t = nt[1]\n\nvar bestR = 1, bestT=-1;\nfor(var i=0;i(parseInt(v)))\n var s = sd[0]\n var d = sd[1]\n \n var D = (t>=s) ? Math.floor((t-s)/d):0;\n var cur = s + D*d;\n var waitingTime = (cur>=t) ? cur-t: (cur+d-t);\n \n //print('>>', s, '+', D, '*', d, cur, waitingTime)\n if(bestT===-1 || (waitingTime parseInt(e));\nconst n = nt[0];\nconst t = nt[1];\n\nvar ans = 0;\nvar timeA;\nfor (var i = 0; i < n; i++) {\n var sd = readline().split(\" \").map(e => parseInt(e));\n var s = sd[0];\n var d = sd[1];\n\n var time;\n for (time = s; time < t; time += d) {\n \n }\n if (ans === 0 || timeA > time) {\n ans = i + 1;\n timeA = time;\n }\n}\nprint(ans);"}, {"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n const [meta, ...routes] = input\n .split('\\n')\n .map(line => line.split(' '));\n const [n, t] = meta.map(Number);\n let minRouteNum;\n let minWaitTime = Number.MAX_SAFE_INTEGER;\n for (let i = 0; i < n; ++i) {\n const [si, di] = routes[i].map(Number);\n let waitTime;\n if (t <= si) {\n waitTime = si - t;\n } else {\n const k = Math.ceil((t - si) / di);\n waitTime = si + k * di - t;\n }\n if (waitTime < minWaitTime) {\n minRouteNum = i + 1;\n minWaitTime = waitTime;\n }\n }\n process.stdout.write(\n minRouteNum.toString(),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var a = read.arrNumber(' ');\n var n = a[0];\n var t = a[1];\n\n var min;\n var res;\n for(var i = 0, line; i < n; i++) {\n line = read.arrNumber(' ');\n if(line[0] === t) {\n print(i + 1);\n return;\n }\n\n var time;\n if(line[0] > t) {\n time = line[0];\n }\n else {\n time = Math.ceil((t - line[0]) / line[1]) * line[1] + line[0];\n }\n\n if(!min || min > time) {\n min = time;\n res = i + 1;\n }\n }\n\n print(res);\n}());\n"}], "negative_code": [{"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n const [meta, ...routes] = input\n .split('\\n')\n .map(line => line.split(' '));\n const [n, t] = meta.map(Number);\n let minRouteNum = -1;\n let minWaitTime = 0;\n for (let i = 0; i < n; ++i) {\n const [si, di] = routes[i].map(Number);\n const k = Math.ceil((t - si) / di);\n const waitTime = si + k * di - t;\n if (minRouteNum === -1 ||\n waitTime < minWaitTime) {\n minRouteNum = i + 1;\n minWaitTime = waitTime;\n }\n }\n process.stdout.write(\n minRouteNum.toString(),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}, {"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n const [meta, ...routes] = input\n .split('\\n')\n .map(line => line.split(' '));\n const [n, t] = meta.map(Number);\n let minRouteNum;\n let minWaitTime;\n for (let i = 0; i < n; ++i) {\n const [si, di] = routes[i].map(Number);\n const k = Math.ceil(Math.abs(t - si) / di);\n const waitTime = si + k * di - t;\n if (i === 0 || waitTime < minWaitTime) {\n minRouteNum = i + 1;\n minWaitTime = waitTime;\n }\n }\n process.stdout.write(\n minRouteNum.toString(),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}], "src_uid": "71be4cccd3b8c494ad7cc2d8a00cf5ed"} {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n if (leftPointer === rightPointer) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum >= 1) {\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n } else {\n leftPointer++;\n }\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n const n = readline();\n for(let i = 0; i < n; i ++){\n let [m,k] = readline().split(' ').map(Number);\n const array = readline().split(' ').map(Number);\n while( k > 0){\n for(let j = 0; j < m - 1; j++){\n if(array[j] > 0){\n array[j]--;\n array[m - 1]++;\n break;\n }\n }\n k--;\n }\n console.log(array.join(' '));\n }\n}"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, k, tab) {\n let idx = 0;\n while (k && idx < tab.length - 1) {\n if (tab[idx] > 0) {\n tab[idx]--;\n tab[n - 1]++;\n k--;\n }\n else {\n idx++;\n }\n }\n tab.forEach((a) => {\n io.write(a);\n });\n io.writeLine(' ');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let k = io.nextNum();\n let tab = io.nextNumArray(n);\n solve(n, k, tab);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var kk = k\r\n for (let j = 0; j < n - 1; j++) {\r\n if (a[j] > 0 && k > 0) {\r\n var res = Math.min(a[j], k)\r\n a[j] = a[j] - (res)\r\n k = k - (res)\r\n }\r\n }\r\n a[n - 1] = a[n - 1] + (kk - k)\r\n\r\n\r\n console.log(a.join(' '))\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "let input = ''\r\nprocess.stdin.on('data', data => input += data)\r\nprocess.stdin.on('end', () => main(input))\r\n \r\nfunction main(input) {\r\n let lines = input.trim().split('\\n');\r\n let T = +lines[0];\r\n for(let i = 1; i < lines.length; i += 2) {\r\n let [n, k] = lines[i].split(' ').map(v => +v);\r\n const arr = lines[i + 1].split(' ').map(v => +v);\r\n \tsolve(arr, n, k);\r\n }\r\n}\r\n\r\nfunction solve(arr, n, k) {\r\n\tfor (let j=0; j k) {\r\n\t\t\tarr[j] -= k;\r\n\t\t\tarr[arr.length-1] += k;\r\n\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tif (k === 0)\r\n\t\t\tbreak;\r\n\t}\r\n\tconsole.log(arr.join(' '))\r\n}"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n \n while (true) {\n if (ops === 0) return input;\n if (leftPointer === rightPointer) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n \n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n \n \n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n }"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n if (leftPointer === rightPointer) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL).filter((l) => l.length);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map((x) => parseInt(x, 10));\n let input = line2.split(\" \").map((x) => parseInt(x, 10));\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0 || leftPointer === rightPointer) break;\n if (input[leftPointer] >= 1) {\n input[leftPointer] -= 1;\n input[rightPointer] += 1;\n ops--;\n } else {\n leftPointer++;\n }\n }\n\n return input;\n}\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\n//////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst err = console.error;\r\n// ****************************** Math *******************************************\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxbi = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mibi = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst sqbi = (v) => {\r\n if (v < 0n) throw 'square root of negative numbers is not supported';\r\n if (v < 2n) return v;\r\n const dfs = (n, x0) => {\r\n let x1 = ((n / x0) + x0) >> 1n;\r\n if (x0 === x1 || x0 === (x1 - 1n)) return x0;\r\n return dfs(n, x1);\r\n }\r\n return dfs(v, 1n); // has >> 0\r\n};\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst powmod = (a, b, mod) => {\r\n let r = 1n;\r\n while (b > 0n) {\r\n if (b % 2n == 1) r = r * a % mod;\r\n b >>= 1n;\r\n a = a * a % mod;\r\n }\r\n return r; // return BigInt\r\n};\r\nconst combination = (m, n) => {\r\n return factorial(m, n) / factorial(n, n); // return BigInt\r\n};\r\nconst factorial = (m, n) => {\r\n let num = 1n;\r\n let cnt = 0;\r\n for (let i = BigInt(m); i > 0; i--) {\r\n if (cnt == n) break;\r\n num *= i;\r\n cnt++;\r\n }\r\n return num;\r\n};\r\nconst bitCount = (n) => {\r\n n = n - ((n >> 1) & 0x55555555);\r\n n = (n & 0x33333333) + ((n >> 2) & 0x33333333);\r\n return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;\r\n};\r\n// ****************************** Array / String *******************************************\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sum = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst sortPart = (a, k) => { // sort only first kth elements\r\n let l = a.slice(0, k);\r\n l.sort((x, y) => x - y);\r\n let r = a.slice(k);\r\n return l.concat(r);\r\n};\r\nconst counter = (a_or_s) => {\r\n let map = new Map();\r\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\r\n return map;\r\n};\r\nconst isPalindrome = (s) => {\r\n let n = s.length;\r\n let i = 0;\r\n let j = n - 1;\r\n while (i < j) {\r\n if (s[i++] != s[j--]) return false;\r\n }\r\n return true;\r\n};\r\n///////////////////////////////////////////////////////////////////////////////////\r\n///////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 04/21/20 morning\r\n * https://codeforces.com/contest/1516/problem/0\r\n */\r\n\r\n// evening\r\nconst solve = (n, k, a) => {\r\n let res = [...a];\r\n for (let i = 0; i < n - 1; i++) {\r\n let tmp = mi(a[i], k);\r\n res[i] -= tmp;\r\n res[n - 1] += tmp;\r\n k -= tmp;\r\n }\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i +v);\r\n\t\tconst arr = lines[i+1].split(' ').map(v => +v);\r\n\r\n\t\tfor (let j=0; j k) {\r\n\t\t\t\tarr[j] -= k;\r\n\t\t\t\tarr[arr.length-1] += k;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tif (k === 0)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tconsole.log(arr.join(' '))\r\n\t}\r\n})\r\n"}, {"source_code": "var T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar nk = readline().split(\" \").map(x => parseInt(x));\n\tvar a = readline().split(\" \").map(x => parseInt(x));\n\tvar n = nk[0];\n\tvar k = nk[1];\n\n\tvar cur = 0;\n\tfor (i = 0; i < k; ++i) {\n\t\twhile (a[cur] == 0 && cur < n - 1) cur += 1;\n\t\ta[cur] -= 1;\n\t\ta[n - 1] += 1;\n\t}\n\tvar ans = \"\";\n\tfor (i = 0; i < n; ++i) {\n\t\tans += a[i].toString() + \" \";\n\t}\n\tprint(ans);\n}\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var a = 1;\r\n for (var b = 0; b < t; b++) {\r\n var [n, k] = input[a].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n a++;\r\n var arr = input[a].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n a++;\r\n var last = arr.length - 1;\r\n for (var i = 0; i <= arr.length - 2; i++) {\r\n if (k - arr[i] >= 0) {\r\n var temp = arr[i];\r\n arr[i] = 0;\r\n arr[last] += temp;\r\n k -= temp;\r\n } else {\r\n arr[i] -= k;\r\n arr[last] += k;\r\n k = 0;\r\n break;\r\n }\r\n }\r\n console.log(arr.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--){\r\n let [n, k] = get_ints();\r\n const a = get_ints();\r\n let idx = 0;\r\n while(k--){\r\n if(idx === a.length - 1) break;\r\n while(a[idx] === 0) \r\n {\r\n idx++;\r\n if(idx === a.length - 1) break;\r\n }\r\n if(idx === a.length - 1) break;\r\n a[idx]--;\r\n a[a.length - 1]++;\r\n }\r\n console.log(a.join(' '));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tfor(var j = 0; j < N - 1; j++){\r\n\t\t\tif(list[j] > 0){\r\n\t\t\t\tif(list[j] > K){\r\n\t\t\t\t\tlist[j] -= K;\r\n\t\t\t\t\tlist[N - 1] += K;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tK -= list[j];\r\n\t\t\t\t\tlist[N - 1] += list[j];\r\n\t\t\t\t\tlist[j] = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL).filter(l => l.length);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map((x => parseInt(x, 10)));\n let input = line2.split(\" \").map(x => parseInt(x, 10));\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer]--\n input[rightPointer]++\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n if (length === 100 && ops === 4740) {\n console.log({ length, ops, input });\n }\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n console.log({length, ops, input})\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n if (lines.length > 30) console.log(lines)\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) {\n leftPointer++;\n continue;\n }\n if (rightNum === 9) {\n rightPointer--;\n continue\n }\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n if (!line1) return;\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) leftPointer++;\n if (rightNum === 9) rightPointer--;\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n try {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n let idx = 0;\n idx++;\n\n for (let j = idx; j < lines.length; j = j + 2) {\n let line1 = lines[j];\n let line2 = lines[j + 1];\n\n let [len, ops] = line1.split(\" \").map(Number);\n let input = line2.split(\" \").map(Number);\n console.log(solve(len, ops, input).join(\" \"));\n }\n } catch (e) {\n console.log(e)\n }\n});\n\nfunction solve(length, ops, input) {\n let leftPointer = 0;\n let rightPointer = length - 1;\n\n while (true) {\n if (ops === 0) return input;\n\n let leftNum = input[leftPointer];\n let rightNum = input[rightPointer];\n\n if (leftNum === 0) leftPointer++;\n if (rightNum === 9) rightPointer--;\n\n if (leftPointer === rightPointer) return input;\n\n input[leftPointer] = leftNum - 1;\n input[rightPointer] = rightNum + 1;\n ops--;\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var a = 1;\r\n for (var b = 0; b < t; b++) {\r\n var [n, k] = input[a].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n a++;\r\n var arr = input[a].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n a++;\r\n var last = arr.length - 1;\r\n for (var i = 0; i <= arr.length - 2; i++) {\r\n if (k - arr[i] >= 0) {\r\n arr[last] += arr[i];\r\n arr[i] = 0;\r\n k -= arr[i];\r\n } else {\r\n arr[i] -= k;\r\n arr[last] += k;\r\n k = 0;\r\n break;\r\n }\r\n }\r\n console.log(arr.join(\" \"));\r\n }\r\n});\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--){\r\n let [n, k] = get_ints();\r\n const a = get_ints();\r\n let idx = 0;\r\n while(k--){\r\n if(idx === a.length - 1) break;\r\n while(a[idx] === 0) \r\n {\r\n idx++;\r\n }\r\n a[idx]--;\r\n a[a.length - 1]++;\r\n }\r\n console.log(a.join(' '));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--){\r\n let [n, k] = get_ints();\r\n const a = get_ints();\r\n let idx = 0;\r\n while(k--){\r\n if(idx === a.length - 1) break;\r\n if(a[idx] === 0) \r\n {\r\n while(a[idx] === 0) \r\n {\r\n idx++;\r\n }\r\n a[idx]--;\r\n a[a.length - 1]++;\r\n }\r\n else\r\n {\r\n a[idx]--;\r\n a[a.length - 1]++;\r\n }\r\n }\r\n console.log(a.join(' '));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--){\r\n let [n, k] = get_ints();\r\n const a = get_ints();\r\n let idx = 0;\r\n while(k--){\r\n if(idx === a.length - 1) break;\r\n if(a[idx] === 0) idx++;\r\n else{\r\n a[idx]--;\r\n a[a.length - 1]++;\r\n }\r\n }\r\n console.log(a.join(' '));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n const n = readline();\n for(let i = 0; i < n; i ++){\n let [m,k] = readline().split(' ').map(Number);\n const array = readline().split(' ').map(Number);\n while( k > 0){\n for(let j = 0; j < m; j++){\n if(j+1 >= m){\n k = 0;\n break;\n } else if(array[j] > 0){\n array[j]--;\n array[j+1]++;\n break;\n }\n }\n k--;\n }\n console.log(array.join(' '));\n }\n}"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, k, tab) {\n let idx = 0;\n while (k-- && idx < tab.length - 1) {\n if (tab[idx] > 0) {\n tab[idx]--;\n tab[n - 1]++;\n }\n else {\n idx++;\n }\n }\n tab.forEach((a) => {\n io.write(a);\n });\n io.writeLine(' ');\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let k = io.nextNum();\n let tab = io.nextNumArray(n);\n solve(n, k, tab);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var kk = k\r\n for (let j = 0; j < n - 1; j++) {\r\n if (a[j] > 0 && k > 0) {\r\n var res = Math.min(a[j] - 1, k)\r\n a[j] = a[j] - (res)\r\n k = k - (res)\r\n }\r\n }\r\n a[n - 1] = a[n - 1] + (kk - k)\r\n\r\n\r\n console.log(a.join(' '))\r\n\r\n })\r\n}\r\n\r\n"}], "src_uid": "6854ad3597f9f41d475aacb774b823ed"} {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const arr = input[1].split(' ').map(Number);\n const zeroes = [];\n let lastZero = -1, currZero = -1;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n zeroes[i] = 0;\n [lastZero, currZero] = [currZero, i];\n for (let j = i; j > lastZero; j--) {\n if ((currZero - j < zeroes[j]) || lastZero === -1) zeroes[j] = currZero - j;\n }\n } else {\n zeroes[i] = i - currZero;\n }\n }\n console.log(zeroes.join(' '));\n});", "positive_code": [{"source_code": " var n = parseInt(readline());\n var a = readline().split(' ').map(x => parseInt(x));\n\n var d = Infinity;\n var ld = [];\n var rd = [];\n for(var i = 0; i < n; i += 1) {\n if(a[i] === 0) {\n d = 0;\n }\n ld[i] = d;\n d += 1;\n }\n d = Infinity;\n for(var i = n - 1; i >= 0; i -= 1) {\n if(a[i] === 0) {\n d = 0;\n }\n rd[i] = d;\n d += 1;\n }\n var res = [];\n for(var i = 0; i < n; i += 1) {\n res[i] = Math.min(ld[i], rd[i]);\n }\n print(res.join(' '));"}, {"source_code": "var length = readline();\nvar array = readline().split(\" \");\nvar lastzero = -1;\nvar output = [];\nfor (var i = 0; i < array.length; i++) {\n\tarray[i] = parseInt(array[i])\n\tif (array[i] == 0) {\n\t\tlastzero = i;\n\t\toutput[i] = 0\n\t} else {\n\t\tif (lastzero != -1) {\n\t\t\toutput[i] = i - lastzero;\n\t\t}\n\t}\n};\nlastzero = -1;\nfor (var i = array.length - 1; i >= 0; i--) {\n\tif (array[i] == 0) {\n\t\tlastzero = i;\n\t} else {\n\t\tif (lastzero != -1) \n\t\t if(!output[i]) {\n\t\t\t output[i] = lastzero - i;\n\t\t }\n\t\t else {\n\t\t output[i] = Math.min(output[i], lastzero - i);\n\t\t }\n\t}\n};\nprint(JSON.stringify(output).replace(/[\\[\\]]/g, \"\").replace(/\\,/g, \" \"));"}, {"source_code": "var listLength = Number(readline());\nvar list = readline().split(' ');\n\nvar dist = listLength;\nvar distances = [];\nfor (var i = 0; i < listLength; i++)\n distances[i] = 0;\n\nfor (var i = 0; i < listLength; i++){\n if (list[i] == '0'){\n dist = 0;\n var j = i;\n while (distances[j] >= dist && j >= 0){\n distances[j] = dist++;\n j--;\n }\n dist = 0;\n }\n else {\n dist++;\n distances[i] = dist;\n }\n}\n\nprint(distances.join(\" \"));\n"}], "negative_code": [{"source_code": "\n var n = parseInt(readline());\n var a = readline().split(' ').map(x => parseInt(x));\n\n var d = 0;\n var ld = [];\n var rd = [];\n for(var i = 0; i < n; i += 1) {\n if(a[i] === 0) {\n d = 0;\n }\n ld[i] = d;\n d += 1;\n }\n d = 0;\n for(var i = n - 1; i >= 0; i -= 1) {\n if(a[i] === 0) {\n d = 0;\n }\n rd[i] = d;\n d += 1;\n }\n var res = [];\n res[0] = rd[0];\n res[n - 1] = ld[n - 1];\n for(var i = 1; i < n - 1; i += 1) {\n res[i] = Math.min(ld[i], rd[i]);\n }\n print(res.join(' '));\n \n"}, {"source_code": " var n = parseInt(readline());\n var a = readline().split(' ').map(x => parseInt(x));\n\n var d = 0;\n var ld = [];\n var rd = [];\n for(var i = 0; i < n; i += 1) {\n if(a[i] === 0) {\n d = 0;\n }\n ld[i] = d;\n d += 1;\n }\n for(var i = n - 1; i >= 0; i -= 1) {\n if(a[i] === 0) {\n d = 0;\n }\n rd[i] = d;\n d += 1;\n }\n var res = [];\n res[0] = rd[0];\n res[n - 1] = ld[n - 1];\n for(var i = 1; i < n - 1; i += 1) {\n res[i] = Math.min(ld[i], rd[i]);\n }\n print(res.join(' '));\n "}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const arr = input[1].split(' ').map(Number);\n const zeroes = [];\n let lastZero = -1, currZero = -2;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n zeroes[i] = 0;\n [lastZero, currZero] = [currZero, i];\n for (let j = i; j > lastZero; j--) {\n if (currZero - j < zeroes[j]) zeroes[j] = currZero - j;\n }\n } else {\n zeroes[i] = i - currZero;\n }\n }\n console.log(zeroes.join(' '));\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const arr = input[1].split(' ').map(Number);\n const zeroes = [];\n let lastZero = -1, currZero = -1;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n zeroes[i] = 0;\n [lastZero, currZero] = [currZero, i];\n for (let j = i; j > (lastZero > 0 ? lastZero : 0); j--) {\n if ((currZero - j < zeroes[j]) || lastZero === -1) zeroes[j] = currZero - j;\n }\n } else {\n zeroes[i] = i - currZero;\n }\n }\n console.log(zeroes.join(' '));\n});"}], "src_uid": "2031f2ac5652609fda77830e93ffcc2c"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n for (let i = 0; i < n; i++) arr[i] = arr[i] % 10;\r\n let obj = {},\r\n res = [];\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n if (obj[arr[i]] <= 3) res.push(arr[i]);\r\n }\r\n const helper = (arr) => {\r\n for (let i = 0; i < arr.length; i++) {\r\n for (let j = i + 1; j < arr.length; j++) {\r\n for (let k = j + 1; k < arr.length; k++) {\r\n if ((arr[i] + arr[j] + arr[k]) % 10 === 3) return true;\r\n }\r\n }\r\n }\r\n return false;\r\n };\r\n if (helper(res)) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nfunction solve(count=[]){\r\n for(let i in count){\r\n if(count[i]>0)\r\n count[i]--;\r\n else\r\n continue;\r\n for(let j in count){\r\n if(count[j]>0)\r\n count[j]--;\r\n else\r\n continue;\r\n {\r\n let k=(23-i-j )%10;\r\n if(count[k]>0){\r\n return true;\r\n }\r\n }\r\n count[j]++;\r\n }\r\n count[i]++;\r\n }\r\n return false;\r\n}\r\n(async () => {\r\n let t = parseInt(await read());\r\n while (t--) {\r\n let count= new Array(10).fill(0);\r\n _=await read();\r\n let a =(await read()).split(' ').map(x=>Number(x[x.length-1]));\r\n a.forEach(e => count[e]++);\r\n if(solve(count))\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n const last = num % 10;\r\n map.set(last, ((_map$get = map.get(last)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let i = 0; i <= 9; i++) {\r\n for (let j = 0; j <= 9; j++) {\r\n for (let k = 0; k <= 9; k++) {\r\n if ((i + k + j) % 10 === 3) {\r\n if (i === j) {\r\n if (j === k) {\r\n var _map$get2;\r\n if (((_map$get2 = map.get(i)) !== null && _map$get2 !== void 0 ? _map$get2 : 0) >= 3) {\r\n return 'YES';\r\n }\r\n } else {\r\n var _map$get3, _map$get4;\r\n if (((_map$get3 = map.get(i)) !== null && _map$get3 !== void 0 ? _map$get3 : 0) >= 2 && ((_map$get4 = map.get(k)) !== null && _map$get4 !== void 0 ? _map$get4 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n }\r\n } else {\r\n if (j === k) {\r\n var _map$get5, _map$get6;\r\n if (((_map$get5 = map.get(i)) !== null && _map$get5 !== void 0 ? _map$get5 : 0) >= 1 && ((_map$get6 = map.get(j)) !== null && _map$get6 !== void 0 ? _map$get6 : 0) >= 2) {\r\n return 'YES';\r\n }\r\n } else {\r\n if (i === k) {\r\n var _map$get7, _map$get8;\r\n if (((_map$get7 = map.get(i)) !== null && _map$get7 !== void 0 ? _map$get7 : 0) >= 2 && ((_map$get8 = map.get(j)) !== null && _map$get8 !== void 0 ? _map$get8 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n } else {\r\n var _map$get9, _map$get10, _map$get11;\r\n if (((_map$get9 = map.get(i)) !== null && _map$get9 !== void 0 ? _map$get9 : 0) >= 1 && ((_map$get10 = map.get(j)) !== null && _map$get10 !== void 0 ? _map$get10 : 0) >= 1 && ((_map$get11 = map.get(k)) !== null && _map$get11 !== void 0 ? _map$get11 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const { ok } = require('assert');\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ')//.map((x) => parseInt(x));\r\n var cnt = [];\r\n for(var i=0;i<10;i++) cnt[i]=0;\r\n for(var i=0;i0;i--) {\r\n for(var j=0;j<=min(cnt[digits], 3);j++) {\r\n if(j == 0) continue;\r\n for(var k=0;k<10;k++) {\r\n var val = (j*digits)\r\n if(i-j >= 0) dp[i][(val+k)%10] |= dp[i-j][k];\r\n }\r\n }\r\n } \r\n }\r\n //if(qe==1) console.log(cnt, dp)\r\n var ans = dp[3][3] ? 'YES' : 'NO';\r\n console.log(ans)\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar c = [];\r\n\tfor(var i = 0; i <= 9; i++){\r\n\t\tfor(var j = 0; j <= 9; j++){\r\n\t\t\tfor(var k = 0; k <= 9; k++){\r\n\t\t\t\tvar V = (i + j + k) % 10;\r\n\t\t\t\tif(V == 3){\r\n\t\t\t\t\tvar map = {};\r\n\t\t\t\t\tif(map[i] == null){\r\n\t\t\t\t\t\tmap[i] = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmap[i]++;\r\n\t\t\t\t\tif(map[j] == null){\r\n\t\t\t\t\t\tmap[j] = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmap[j]++;\r\n\t\t\t\t\tif(map[k] == null){\r\n\t\t\t\t\t\tmap[k] = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmap[k]++;\r\n\t\t\t\t\tc.push(map);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = {};\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(map[list[i] % 10] == null){\r\n\t\t\t\tmap[list[i] % 10] = 0;\r\n\t\t\t}\r\n\t\t\tmap[list[i] % 10]++;\r\n\t\t}\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < c.length; i++){\r\n\t\t\tvar cm = c[i];\r\n\t\t\tvar ck = Object.keys(cm);\r\n\t\t\tvar cb = true;\r\n\t\t\tfor(var j = 0; j < ck.length; j++){\r\n\t\t\t\tif(map[ck[j]] == null || map[ck[j]] < cm[ck[j]]){\r\n\t\t\t\t\tcb = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(cb){\r\n\t\t\t\tok = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = arr.reduce((o, x) => {\n x = x % 10\n o[x] = (o[x] || 0) + 1\n return o\n }, Array(10).fill(0))\n // console.log(map);return\n for (let i = 0; i < 1e3; i++) {\n const a = Math.floor(i / 1e2)\n const b = Math.floor((i % 100) / 1e1)\n const c = i % 10\n const o = Array(10).fill(0)\n o[a] = (o[a] || 0) + 1\n o[b] = (o[b] || 0) + 1\n o[c] = (o[c] || 0) + 1\n if (map[a] < o[a] || map[b] < o[b] || map[c] < o[c]) continue\n const r = (a + b + c) % 10\n if (r === 3) {\n // console.log(a, b, c)\n return 'YES'\n }\n }\n return 'NO'\n}\n"}], "negative_code": [{"source_code": "class Scaner {\r\n data = [];\r\n constructor() {\r\n process.stdin.setEncoding('utf-8');\r\n process.stdin.on('data', _data => {\r\n let lasttext = this.data.pop();\r\n if (lasttext == undefined)\r\n lasttext = \"\"\r\n _data = lasttext + _data;\r\n const l = _data.split('\\n');\r\n this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);\r\n });\r\n }\r\n read = async () => {\r\n process.stdin.resume();\r\n while (this.data.length < 2) {\r\n await delay(0);\r\n }\r\n process.stdin.pause();\r\n let res = this.data.shift();\r\n if (res == \"\")\r\n return await read();\r\n return res;\r\n };\r\n}\r\nconst delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));\r\nconst print = (text) => process.stdout.write(\"\" + text);\r\nconst scaner = new Scaner()\r\nconst read = scaner.read;\r\n//----------------------------------------------------------------\r\n//-----------------------the-code---------------------------------\r\n//----------------------------------------------------------------\r\nfunction solve(count=[]){\r\n for(let i in count){\r\n if(count[i]>0)\r\n count[i]--;\r\n else\r\n continue;\r\n for(let j in count){\r\n if(count[j]>0)\r\n count[j]--;\r\n else\r\n continue;\r\n {\r\n let k=(13-( i+j )%10)%10;\r\n if(count[k]>0){\r\n return true;\r\n }\r\n }\r\n count[j]++;\r\n }\r\n count[i]++;\r\n }\r\n return false;\r\n}\r\n(async () => {\r\n let t = parseInt(await read());\r\n while (t--) {\r\n let count= new Array(10).fill(0);\r\n _=await read();\r\n let a =(await read()).split(' ').map(x=>Number(x[x.length-1]));\r\n a.forEach(e => count[e]++);\r\n if(solve(count))\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n})().then(() => { }\r\n)\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n const last = num % 10;\r\n map.set(last, ((_map$get = map.get(last)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let i = 0; i <= 9; i++) {\r\n for (let j = 0; j <= 9; j++) {\r\n for (let k = 0; k <= 9; k++) {\r\n if ((i + k + j) % 10 === 3) {\r\n if (i === j) {\r\n if (j === k) {\r\n var _map$get2;\r\n if (((_map$get2 = map.get(k)) !== null && _map$get2 !== void 0 ? _map$get2 : 0) >= 3) {\r\n return 'YES';\r\n }\r\n } else {\r\n var _map$get3, _map$get4;\r\n if (((_map$get3 = map.get(i)) !== null && _map$get3 !== void 0 ? _map$get3 : 0) >= 2 && ((_map$get4 = map.get(k)) !== null && _map$get4 !== void 0 ? _map$get4 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n }\r\n } else {\r\n if (j === k) {\r\n var _map$get5, _map$get6;\r\n if (((_map$get5 = map.get(j)) !== null && _map$get5 !== void 0 ? _map$get5 : 0) >= 2 && ((_map$get6 = map.get(i)) !== null && _map$get6 !== void 0 ? _map$get6 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n } else {\r\n var _map$get7, _map$get8, _map$get9;\r\n if (((_map$get7 = map.get(i)) !== null && _map$get7 !== void 0 ? _map$get7 : 0) >= 1 && ((_map$get8 = map.get(j)) !== null && _map$get8 !== void 0 ? _map$get8 : 0) >= 1 && ((_map$get9 = map.get(k)) !== null && _map$get9 !== void 0 ? _map$get9 : 0) >= 1) {\r\n return 'YES';\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "3ae4f35808348841e0f47540cdf4abe6"} {"source_code": "//var input = readline();\n\nvar T = parseInt(readline());\nwhile (T-- > 0) {\n var ar = readline().split(' ');\n var s = ar[0];\n \n if (s[s.length - 1] == \"o\" && s[s.length - 2] == \"p\") print(\"FILIPINO\");\n else if ((s[s.length - 1] == \"u\" && s[s.length - 2] == \"s\" && s[s.length - 3] == \"e\" && s[s.length - 4] == \"d\") ||\n (s[s.length - 1] == \"u\" && s[s.length - 2] == \"s\" && s[s.length - 3] == \"a\" && s[s.length - 4] == \"m\")) print(\"JAPANESE\");\n else print(\"KOREAN\");\n}", "positive_code": [{"source_code": "let s = '';\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift();\n s.forEach(element => {\n console.log(element.trim().endsWith('po') ? 'FILIPINO' : element.trim().endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "let s = '';\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift();\n s.forEach(element => {\n element = element.trim()\n console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n const returnLang = (word) => {\n switch (word) {\n case 'desu': return 'JAPANESE';\n case 'masu': return 'JAPANESE';\n case 'po': return 'FILIPINO';\n case 'mnida': return 'KOREAN';\n }\n }\n let _result = ''\n const findOnStart = (el) => {\n const myRe = /(desu)|(masu)|(po)|(mnida)/g;\n let _answer = el.match(myRe)\n _answer = _answer[_answer.length - 1]\n const _lang = returnLang(_answer)\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n }\n const words = [...input.slice(1)]\n words.forEach(el => {\n findOnStart(el)\n })\n console.log(_result)\n})"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n \n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const str = arr[j]\n const len = str.length\n // console.log(str, len, str.substr(len - 4), 'sdfdssssssssssss')\n\n let s = str.substr(len - 2)\n\n if(str.substr(len - 2) == 'po') console.log('FILIPINO')\n else if(len >= 4 && (str.substr(len - 4) == 'desu' || str.substr(len - 4) == 'masu')) console.log('JAPANESE')\n else if(len >= 5 && str.substr(len - 5) == 'mnida') console.log('KOREAN')\n\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (str.endsWith('po')) {\n console.log('FILIPINO');\n }\n else if (str.endsWith('mnida')) {\n console.log('KOREAN');\n }\n else {\n console.log('JAPANESE');\n }\n\n c++;\n});\n"}, {"source_code": "//var input = parseInt(readline());\n\nvar n = parseInt(readline());\nwhile(n-- > 0) {\n var ar = readline().split(\" \");\n var s = ar[0], L = s.length;\n \n if (s.slice(L - 2) === \"po\") print(\"FILIPINO\");\n else if (s.slice(L - 5) === \"mnida\") print(\"KOREAN\");\n else print(\"JAPANESE\");\n\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', data => {\n if (data.endsWith('po')) {\n process.stdout.write('FILIPINO\\n');\n } else if (data.endsWith('desu') || data.endsWith('masu')) {\n process.stdout.write('JAPANESE\\n');\n } else if (data.endsWith('mnida')) {\n process.stdout.write('KOREAN\\n');\n }\n});"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet words = [];\nlet i = 0;\n\nconst solver = () => {\n for (let i = 0; i < words.length; i++) {\n if (words[i].lastIndexOf('po') == words[i].length - 2) {\n console.log('FILIPINO');\n } else if (words[i].lastIndexOf('desu') == words[i].length - 4 || words[i].lastIndexOf('masu') == words[i].length - 4) {\n console.log('JAPANESE');\n } else if (words[i].lastIndexOf('mnida') == words[i].length - 5) {\n console.log('KOREAN');\n }\n }\n};\n\nrl.question('', (a) => {\n rl.on('line', (l) => {\n words.push(l);\n if (++i == a) {\n rl.close();\n }\n })\n\n rl.on('close', () => {\n solver();\n })\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet index = 0;\n\n// single line input\nreadline.on('line', line => {\n if (index++) {\n if (line.substr(line.length - 2) === \"po\") return console.log(\"FILIPINO\");\n else if (line.substr(line.length - 4) === \"desu\" || line.substr(line.length - 4) === \"masu\") return console.log('JAPANESE');\n else if (line.substr(line.length - 5) === \"mnida\") return console.log(\"KOREAN\");\n }\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "var s = '';\nvar n = 0;\n\nprocess.stdin.on('data', function (c) {\n s += c;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n main();\n});\n\nfunction readline() {\n return s[n++];\n}\n\nfunction main() {\n var T = parseInt(readline());\n for (var t = 0; t < T; ++t) {\n var line = readline().trim();\n if (line.length >= 2 && line.slice(-2) === 'po') {\n console.log('FILIPINO');\n } else if (line.length >= 5 && line.slice(-5) === 'mnida') {\n console.log('KOREAN');\n } else {\n console.log('JAPANESE');\n }\n }\n}"}, {"source_code": "//var input = parseInt(readline());\n\nvar n = parseInt(readline());\nwhile(n-- > 0) {\n var Arr = readline().split(\" \");\n var S = Arr[0];\n var s = S.split(\"\").reverse().join(\"\");\n\n if(s.substr(0, 2) === 'op') print(\"FILIPINO\");\n else if (s.substr(0, 5) === \"adinm\") print(\"KOREAN\");\n else print(\"JAPANESE\");\n\n}\n"}, {"source_code": "// A Suffix Three\n//\n\nvar numberOfLines = parseInt(readline());\n\nfor( var i = 0; i < numberOfLines; i++ ) {\n var str = readline();\n if( str.endsWith(\"po\") ) {\n print(\"FILIPINO\");\n } else if( str.endsWith(\"mnida\") ) {\n print(\"KOREAN\");\n } else {\n print(\"JAPANESE\");\n }\n}\n"}, {"source_code": "(function main()\n{\n var n=readline();\n for(var i=1;i<=parseInt(n);i++)\n {\n var string=readline();\n var len=string.length;\n //print(string.substring(len-2,len));\n if(string.substring(len-2,len)==\"po\")\n print(\"FILIPINO\");\n else if(string.substring(len-4,len)==\"desu\"||string.substring(len-4,len)==\"masu\")\n print(\"JAPANESE\");\n else if(string.substring(len-5,len)==\"mnida\")\n print(\"KOREAN\");\n }\n})();"}, {"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),0);\n var output = [];\n for(var i = 0; i < N; i++){\n var str = readline();\n var check = \"\";\n for(var j = str.length-1; j > str.length-1-6; j--){\n check += str.substring(j,j+1);\n //myout(check);\n if(check == \"op\"){\n output.push(\"FILIPINO\");\n break;\n }else if(check == \"used\" || check == \"usam\"){\n output.push(\"JAPANESE\");\n break;\n }else if(check == \"adinm\"){\n output.push(\"KOREAN\");\n break;\n }\n }\n }\n myout(output.join(\"\\n\"));\n}\n\nMain();\n"}, {"source_code": "var q = parseInt(readline());\nvar input = []\nwhile (q != 0) {\n q--;\n input.push(readline().trim());\n}\nvar langs = {\n po: \"FILIPINO\",\n su: \"JAPANESE\",\n da: \"KOREAN\"\n}\nprint(input.map(z => langs[z.slice(-2)]).join(\"\\n\"))"}, {"source_code": "p=print;a=readline;for(k=a();k--;){x=/\\w$/.exec(a());(x=='a')?p(\"KOREAN\"):(x=='u')?p(\"JAPANESE\"):p(\"FILIPINO\")}"}, {"source_code": "var n = parseInt(readline());\nwhile(n-- > 0) {\n var s = readline();\n \n if(s.slice(s.length - 2) === 'po'){\n print('FILIPINO');\n } else if(s.slice(s.length - 5) === 'mnida') {\n print('KOREAN');\n } else {\n print('JAPANESE');\n }\n}"}], "negative_code": [{"source_code": "let s = '';\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift();\n s.forEach(element => {\n console.log(element.trim().endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "var s = '';\nvar n = 0;\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\n// ctrl + D\nprocess.stdin.on('end', function () {\n s = s.split('\\n');\n s.shift();\n s.forEach(element => {\n console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "var s = '';\nvar n = 0;\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\n// ctrl + D\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift();\n console.log(s);\n s.forEach(element => {\n console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "var s = '';\nvar n = 0;\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\n// ctrl + D\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift();\n s.forEach(element => {\n console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');\n });\n});\n"}, {"source_code": "\nconst readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\nconst languageCheck = ['desu', 'masu', 'po', 'mnida']\nconst returnLang = (word) => {\n switch (word) {\n case 'desu': return 'JAPANESE'; break;\n case 'masu': return 'JAPANESE'; break;\n case 'po': return 'FILIPINO'; break;\n case 'mnida': return 'KOREAN'; break;\n }\n}\nlet _result = ''\nconst findOnEnd = (el) => {\n const lengthWord = el.length\n let stop = false\n let checkWord = ''\n let char = lengthWord - 1\n while (!stop) {\n if (char >= 0) {\n if (!languageCheck.includes(checkWord)) {\n checkWord = el.charAt(char) + checkWord\n } else {\n const _lang = returnLang(checkWord)\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n stop = true\n }\n char--\n } else {\n stop = true\n }\n }\n}\nconst findOnStart = (el) => {\n let lang = ''\n if (el.match(/(desu|masu)/g)) {\n _lang = returnLang('desu')\n } else if (el.match(/(po)/g)) {\n _lang = returnLang('po')\n } else if (el.match(/(mnida)/g)) {\n _lang = returnLang('mnida')\n }\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n}\nconst words = [...input.slice(1)]\nwords.forEach(el => {\n if (el.match(/(_)/g)) {\n findOnEnd(el)\n } else {\n findOnStart(el)\n }\n})\nconsole.log(_result)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\nconst languageCheck = ['desu', 'masu', 'po', 'mnida']\nconst returnLang = (word) => {\n switch (word) {\n case 'desu': return 'JAPANESE'; break;\n case 'masu': return 'JAPANESE'; break;\n case 'po': return 'FILIPINO'; break;\n case 'mnida': return 'KOREAN'; break;\n }\n}\nconst count = parseInt(input[0], 10)\nconst words = [...input.slice(1)]\nlet _result = ''\nwords.forEach(el => {\n const lengthWord = el.length\n let stop = false\n let checkWord = ''\n let char = lengthWord - 1\n while (!stop) {\n if (char >= 0) {\n if (!languageCheck.includes(checkWord)) {\n checkWord = el.charAt(char) + checkWord\n } else {\n const _lang = returnLang(checkWord)\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n stop = true\n }\n char--\n } else {\n stop = true\n }\n }\n})\nconsole.log(_result)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n const languageCheck = ['desu', 'masu', 'po', 'mnida']\n const returnLang = (word) => {\n switch (word) {\n case 'desu': return 'JAPANESE'; break;\n case 'masu': return 'JAPANESE'; break;\n case 'po': return 'FILIPINO'; break;\n case 'mnida': return 'KOREAN'; break;\n }\n }\n let _result = ''\n const findOnEnd = (el) => {\n const lengthWord = el.length\n let stop = false\n let checkWord = ''\n let char = lengthWord - 1\n while (!stop) {\n if (char >= 0) {\n if (!languageCheck.includes(checkWord)) {\n checkWord = el.charAt(char) + checkWord\n } else {\n const _lang = returnLang(checkWord)\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n stop = true\n }\n char--\n } else {\n stop = true\n }\n }\n }\n const findOnStart = (el) => {\n const myRe = /(desu)|(masu)|(po)|(mnida)/g;\n const _answer = el.match(myRe)[0]\n const _lang = returnLang(_answer)\n if (_result !== '')\n _result += `\\n${_lang}`\n else\n _result = _lang\n }\n const words = [...input.slice(1)]\n words.forEach(el => {\n if (el.match(/(_)/g)) {\n findOnEnd(el)\n } else {\n findOnStart(el)\n }\n })\n console.log(_result)\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', data => {\n if (data.endsWith('po')) {\n process.stdout.write('FILIPINO\\n');\n } else if (data.endsWith('desu') || data.endsWith('masu')) {\n process.stdout.write('JAPANESE\\n');\n } else {\n process.stdout.write('KOREAN\\n');\n }\n});\n\nrl.on('close', () => {\n process.exit(0);\n});"}, {"source_code": "var s = '';\nvar n = 0;\n\nprocess.stdin.on('data', function (c) {\n s += c;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n main();\n});\n\nfunction readline() {\n return s[n++];\n}\n\nfunction main() {\n var T = parseInt(readline());\n for (var t = 0; t < T; ++t) {\n var line = readline();\n if (line.length >= 2 && line.slice(-2) === 'po') {\n console.log('FILIPINO');\n } else if (line.length >= 5 && line.slice(-5) === 'mnida') {\n console.log('KOREAN');\n } else {\n console.log('JAPANESE');\n }\n }\n}"}, {"source_code": "function main()\n{\n var n=readline();\n for(var i=1;i<=parseInt(n);i++)\n {\n var string=readline();\n var len=string.length;\n if(string[len-1]=='p'&&string[len-2]=='o')\n console.log(\"FILIPINO\");\n else if(string.substring(len-4,len-1)==\"desu\"||string.substring(len-4,len-1)==\"masu\")\n console.log(\"JAPANESE\");\n else if(string.substring(len-5,len-1)==\"mnida\")\n console.log(\"KOREAN\");\n }\n}"}, {"source_code": "a = readline();\nprint(\n typeof a === 'number' ?\n skip :\n a.slice(a.length - 1, a.length) === 'po' ?\n 'FILIPINO' :\n a.slice(a.length - 4, a.length) === 'desu' || a.slice(a.length - 4, a.length) === 'masu' ?\n 'JAPANESE' : \n 'KOREAN'\n);"}, {"source_code": "a = readline();\nprint(\n typeof a === 'number' && a<=30 ?\n '' :\n a.slice(a.length - 1, a.length) === 'po' ?\n 'FILIPINO' :\n a.slice(a.length - 4, a.length) === 'desu' || a.slice(a.length - 4, a.length) === 'masu' ?\n 'JAPANESE' : \n 'KOREAN'\n);"}, {"source_code": "function suffix(str){\n if(str.slice(str.length-1, str.length) === 'po'){\n return \"FILIPINO\";\n } else if(str.slice(str.length-4, str.length) === 'desu' || str.slice(str.length-4, str.length) === 'masu'){\n return 'JAPANESE';\n } else if(str.slice(str.length-5, str.length)){\n return 'KOREAN';\n }\n};"}, {"source_code": "function suffix(str){\n if(string.splice(str.length-2, str.length-1) === 'po'){\n return \"FILIPINO\";\n } else if(string.splice(str.length-4, str.length-1) === 'desu' || string.splice(str.length-4, str.length-1) === 'masu'){\n return 'JAPANESE';\n } else {\n return 'KOREAN';\n }\n}"}, {"source_code": "var n = parseInt(readline());\nwhile(n-- > 0) {\n var s = readline();\n \n if(s.slice(s.length - 1 , s.length) === 'po'){\n print('FILIPINO');\n } else if(s.slice(s.length - 5 , s.length) === 'mnida') {\n print('KOREAN');\n } else {\n print('JAPANESE');\n }\n}"}, {"source_code": "function suffix(str){\n if(str.slice(str.length-1, str.length) === 'po'){\n return \"FILIPINO\";\n } else if(str.slice(str.length-4, str.length) === 'desu' || str.slice(str.length-4, str.length) === 'masu'){\n return 'JAPANESE';\n } else if(str.slice(str.length-5, str.length)){\n return 'KOREAN';\n }\n}"}], "src_uid": "816907d873bce3573ce1e5ae3f494768"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let ans = 0;\n let v = 2;\n const mid = n / 2;\n\n for (let i = 1; i < n; i++) {\n if (i < mid) {\n ans += v ** i;\n }\n else {\n ans -= v ** i;\n }\n }\n\n ans += v ** n;\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet lines = [];\nrl.on('line', (line) => {\n lines.push(line);\n}).on('close', () => {\n for (i = 1; i < lines.length; i++) {\n const n = +lines[i];\n let firstNum = Math.pow(2, n);\n let secondNum = Math.pow(2, n - 1);\n \n let f = 1;\n let s = n - 2;\n\n while (f < s) {\n firstNum += Math.pow(2, f);\n secondNum += Math.pow(2, s);\n \n f++; s--;\n }\n\n process.stdout.write(`${Math.abs(firstNum - secondNum)}\\n`);\n }\n});"}, {"source_code": "var reader = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj = null;\nvar inputFile = [];\nreader.on('line', function(input){inputFile.push(input);});\nreader.on('close', function(){\n obj = init(inputFile);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\nfunction next(){return obj.next();}\nfunction hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n \"list\" : input, \"index\" : 0, \"max\" : input.length,\n \"hasNext\" : function(){return (this.index < this.max);},\n \"next\" : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(t){console.log(t);}//\u6a19\u6e96\u51fa\u529b\nfunction myerr(t){console.error(\"debug:\" + require(\"util\").inspect(t,false,null));}//\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\u30001:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tvar sum1 = 0;\n\t\tvar sum2 = 0;\n\t\tvar list = new Array(n);\n\t\tfor(var j = 1; j <= n; j++){\n\t\t\tlist[j - 1] = Math.pow(2,j);\n\t\t}\n\t\tif(n == 2){\n\t\t\toutput[i] = 2;\n\t\t}else{\n\t\t\tsum1 += list.pop();\n\t\t\tfor(var j = 0; j < (n / 2) - 1; j++){\n\t\t\t\tsum1 += list.shift();\n\t\t\t}\n\t\t\twhile(list.length > 0){\n\t\t\t\tsum2 += list.pop();\n\t\t\t}\n\t\t\toutput[i] = Math.abs(sum1 - sum2);\n\t\t}\n \n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function processData(input) {\n let inpArr = input.split('\\n');\n for (var k = 1; k <= (parseInt(inpArr[0])); k++) {\n console.log(minimum(parseInt(inpArr[k])));\n }\n}\n\nfunction minimum (n) {\n let heavy = Math.pow(2, n);\n let light = 0;\n\n for (let i = 0; i < ((n/2)-1); i ++) {\n heavy += Math.pow(2, i+1);\n }\n\n for (let j = ((n/2) - 1); j < n-1; j++) {\n light += Math.pow(2, j+1);\n }\n\n return heavy - light;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let n = strToNumArr(splitter(str, '\\n'));\n let t = n[0];\n let weights = n.slice(1);\n\n for (let index = 0; index < t; index++) {\n let sum1 = 1 << weights[index], sum2 = 0;\n for (let index2 = 1; index2 < Math.floor(weights[index] / 2); index2++) {\n sum1 += 1 << index2;\n }\n for (let index3 = Math.floor(weights[index] / 2); index3 < weights[index]; index3++) {\n sum2 += 1 << index3;\n }\n\n console.log(sum1 - sum2);\n }\n\n // return ''.toString();\n}\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n function minimum (n) {\n let heavy = Math.pow(2, n);\n let light = 0;\n \n for (let i = 0; i < ((n/2)-1); i ++) {\n heavy += Math.pow(2, i+1);\n }\n \n for (let j = ((n/2) - 1); j < n-1; j++) {\n light += Math.pow(2, j+1);\n }\n \n return heavy - light;\n }\n\n for(var r=0;rNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tvar sum1 = 0;\n\t\tvar sum2 = 0;\n\t\tvar list = new Array(n);\n\t\tfor(var j = 1; j <= n; j++){\n\t\t\tlist[j - 1] = Math.pow(2,j);\n\t\t}\n\t\tif(n == 2){\n\t\t\toutput[i] = 2;\n\t\t}else{\n\t\t\tsum1 += list.pop();\n\t\t\tfor(var j = 0; j < (n / 2) - 1; j++){\n\t\t\t\tsum1 += list.shift();\n\t\t\t}\n\t\t\twhile(list.length > 0){\n\t\t\t\tsum2 += list.pop();\n\t\t\t}\n\t\t\toutput[i] = Math.abs(sum1 - sum2);\n\t\t}\n\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t = Number(readline().replace(/\\r$/, '')), n, a, b;\n\nfor (i = 0; i < t; i++) {\n a = 0;\n b = 0;\n n = Number(readline().replace(/\\r$/, ''));\n\n a += Math.pow(2, n);\n for (j = 0; j < n/2; j++) {\n b += Math.pow(2, n - 1 - j);\n }\n for (j = 1; j < n/2; j++) {\n a += Math.pow(2, j)\n }\n\n print(a - b);\n}"}, {"source_code": "var t = readline()\nfor (i=0;i {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let i=0; i < test; i++) {\n\t\tlet n = parseInt(input[i+1]);\n\t\tconsole.log(solution(n));\n\t}\n});\n\nfunction solution(n) {\n\treturn (Math.pow(2, parseInt(n/2)+1) - 2);\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet lines = [];\nrl.on('line', (line) => {\n lines.push(line);\n}).on('close', () => {\n for (i = 1; i < lines.length; i++) {\n const n = +lines[i];\n let firstNum = Math.pow(2, n);\n let secondNum = Math.pow(2, n - 1);\n \n let f = 1;\n let s = n - 2;\n\n while (f < s) {\n firstNum += Math.pow(2, f);\n secondNum += Math.pow(2, s);\n \n f++; s--;\n }\n\n process.stdout.write(Math.abs(firstNum - secondNum).toString());\n }\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let ans = 0;\n const arr = [];\n let v = 2;\n let inc = 1;\n let dec = n;\n const mid = Math.floor(n / 2);\n\n for (let i = 0; i < mid; i++) {\n arr.push(v ** inc);\n arr.push(v ** dec);\n\n inc++;\n dec--;\n }\n\n for (let i = 0; i < n; i++) {\n if (i < mid) {\n ans += arr[i];\n }\n else {\n ans -= arr[i];\n }\n }\n\n console.log(Math.abs(ans));\n\n c++;\n});\n"}, {"source_code": "function processData(input) {\n let inpArr = input.split('\\n');\n for (var k = 1; k < inpArr[0]; k++) {\n console.log(minimum(parseInt(inpArr[k])));\n }\n}\n\nfunction minimum (n) {\n let heavy = Math.pow(2, n);;\n let light = 0;\n\n for (let i = 0; i < ((n/2)-1); i ++) {\n heavy += Math.pow(2, i+1);\n }\n\n for (let j =((n/2) - 1); j < n-1; j++) {\n light = Math.pow(2, j+1);\n }\n\n return heavy - light;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n \n for(var r=0;r 5) {\n console.log((output / 2) - 2);\n } else {\n console.log(output / 2);\n }\n\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 1 2\n 2 3\n 2 4\n 4 5\n**/\n\nfunction main() {\n var range = readline();\n \n for(var r=0;r 2) {\n console.log(output - 2);\n } else {\n console.log(output);\n }\n\n }\n}"}], "src_uid": "787a45f427c2db98b2ddb78925e0e0f1"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tnumSubjects = data[0], chapterCost = data[1],\n\t\tsubjects = tokenizeIntegers(readline()),\n\t\ttotal = 0;\n\tsubjects.sort(function (a, b) {\n\t\treturn a - b;\n\t});\n\tfor (var i = 0; i < numSubjects; ++i) {\n\t\ttotal += subjects[i] * chapterCost;\n\t\tchapterCost = Math.max(1, chapterCost-1);\n\t}\n\tprint(total);\n}\n\nmain();\n", "positive_code": [{"source_code": "//var n = 3, x = 3,\n// chapters = [1, 1, 1],\n// totalTime = 0;\n\nvar in1 = readline().split(\" \"),\n n = Number(in1[0]),\n x = Number(in1[1]),\n chapters = parseArrayString(readline()),\n totalTime = 0;\n\nchapters.sort(function (a, b) {\n return a - b;\n});\n\nfor (var i = 0; i < chapters.length; i++) {\n var item = chapters[i];\n\n totalTime += item * x;\n x--;\n x = x <= 0 ? 1 : x;\n}\n\n//console.log( totalTime );\nprint(totalTime);\n\nfunction parseArrayString(str) {\n return str.split(\" \").map(function (x) {\n return x >> 0;\n });\n}\n"}, {"source_code": "var firstLine = readline().split(\" \").map(function(a){return parseInt(a, 10)});\nvar n = firstLine[0];\nvar x = firstLine[1];\nvar chapters = readline().split(\" \").map(function(a){return parseInt(a,10)});\nchapters.sort(function(a, b){return a - b;})\nvar hours = 0;\nfor(var i = 0; i < chapters.length; i++){\n\thours += chapters[i] * x\n\tif(x > 1){\n\t\tx--;\n\t}\n}\n\nprint(hours)"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\nprint(function(n, x) {\n\tvar c = readline().split(' ').map(Number);\n\tc.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tans += c[i] * x;\n\t\tif (x > 1)\n\t\t\tx--;\n\t}\n\treturn ans;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var info = readline().split(' ').map(Number);\nvar Arr = readline().split(' ').map(Number);\nvar sArr = Arr.sort(function(a, b){return a-b});\nvar speed = info[1];\nvar result = 0;\nfor (var i=0; i 1) ? (x - 1) : 1;\n\t}\n\n\tprint(r);\n\n}).call(this);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n //console.log(\"data\")\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n //console.log(\"end\")\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n //console.log(\"main\")\n \n const inArray = readline().split(\" \");\n const n = parseInt(inArray[0])\n let x = parseInt(inArray[1])\n let cs = readline().split(\" \").map(x => parseInt(x));\n \n cs.sort(function(a,b){return a-b})\n let total = 0\n cs.forEach(c => {\n total += c*x\n x--\n x = Math.max(x,1);\n });\n console.log(total)\n \n \n}"}], "negative_code": [{"source_code": "//var n = 3, x = 3,\n// chapters = [1, 1, 1],\n// totalTime = 0;\n\nvar in1 = readline().split(\" \"),\n n = Number(in1[0]),\n x = Number(in1[1]),\n chapters = parseArrayString(readline()),\n totalTime = 0;\n\nchapters.sort();\n\nfor (var i = 0; i < chapters.length; i++) {\n var item = chapters[i];\n\n totalTime += item * x;\n x--;\n x = x <= 0 ? 1 : x;\n}\n\n//console.log( totalTime );\nprint(totalTime);\n\nfunction parseArrayString(str) {\n return str.split(\" \").map(function (x) {\n return x >> 0;\n });\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n //console.log(\"data\")\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n //console.log(\"end\")\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n //console.log(\"main\")\n \n const inArray = readline().split(\" \");\n const n = parseInt(inArray[0])\n let x = parseInt(inArray[1])\n let cs = readline().split(\" \").map(x => parseInt(x));\n console.log(cs)\n cs.sort(function(a,b){return a-b})\n console.log(cs)\n let total = 0\n cs.forEach(c => {\n console.log(`${c} mul ${x}`)\n total += c*x\n x--\n x = Math.max(x,1);\n });\n console.log(total)\n \n \n}\nfunction foo(x) {\n process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n console.log(x); // with auto '\\n' (newline)\n}"}], "src_uid": "ce27e56433175ebf9d3bbcb97e71091e"} {"source_code": "var readline = require('readline');\r\n \r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvar lines = [];\r\nrl.on('line', function(input) {\r\n lines.push(input);\r\n});\r\nrl.on('close', function() {\r\n var l = 0;\r\n var t = +lines[l++]\r\n for (var i = 0; i < t; i++) {\r\n l++\r\n var [k, n, m] = lines[l++].trim().split(' ').map(Number)\r\n var a1 = lines[l++].trim().split(' ').map(Number)\r\n var a2 = lines[l++].trim().split(' ').map(Number)\r\n console.log(solve(a1, a2, k, []));\r\n }\r\n});\r\n\r\n\r\nconst solve = (d1, d2, k, res) => {\r\n try{\r\n if(d1.length >0 || d2.length > 0){\r\n if(d1.length && d1[0] === 0){\r\n res.push(d1[0])\r\n return solve(d1.slice(1), d2, k+1, res)\r\n }else if(d2.length && d2[0] === 0){\r\n res.push(d2[0])\r\n return solve(d1, d2.slice(1), k+1, res)\r\n }else if(d1.length && d1[0] <= k){\r\n res.push(d1[0])\r\n return solve(d1.slice(1), d2, k, res)\r\n }else if(d2.length && d2[0] <= k){\r\n res.push(d2[0])\r\n return solve(d1, d2.slice(1), k, res)\r\n }else{\r\n return -1\r\n }\r\n\r\n }else{\r\n return res.join(' ');\r\n }\r\n }catch (ex){\r\n console.log('ex:', ex)\r\n }\r\n}", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nlet t = +readline()\r\nwhile(t--){\r\n readline()\r\n let [k,n,m] = readline().split(' ').map(x=>+x);\r\n let a = readline().split(' ').map(x=>+x)\r\n let b = readline().split(' ').map(x=>+x)\r\n console.log(`${solve(a, b, n, m, k)}`);\r\n}\r\n\r\nfunction solve(a, b, n, m, k){\r\n let idx_a = 0;\r\n let idx_b = 0;\r\n let result = '';\r\n \r\n while(idx_a < n || idx_b < m){\r\n if(a[idx_a] === 0){\r\n result += ` ${0}`;\r\n idx_a++;\r\n k++\r\n }else if(b[idx_b] === 0){\r\n result += ` ${0}`;\r\n idx_b++;\r\n k++;\r\n }else if(a[idx_a] <= k){\r\n result += ` ${a[idx_a]}`;\r\n idx_a++;\r\n }else if(b[idx_b] <= k){\r\n result += ` ${b[idx_b]}`;\r\n idx_b++;\r\n }else return -1;\r\n }\r\n return result.trim();\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nlet t = +readline()\r\nwhile(t--){\r\n readline()\r\n let [k,n,m] = readline().split(' ').map(x=>+x);\r\n let a = readline().split(' ').map(x=>+x)\r\n let b = readline().split(' ').map(x=>+x)\r\n console.log(`${solve(a, b, n, m, k)}`);\r\n}\r\n\r\nfunction solve(a, b, n, m, k){\r\n let idx_a = 0;\r\n let idx_b = 0;\r\n let result = [];\r\n \r\n while(idx_a < n || idx_b < m){\r\n if(a[idx_a] === 0){\r\n result.push(0);\r\n idx_a++;\r\n k++\r\n }else if(b[idx_b] === 0){\r\n result.push(0);\r\n idx_b++;\r\n k++;\r\n }else if(a[idx_a] <= k){\r\n result.push(a[idx_a]);\r\n idx_a++;\r\n }else if(b[idx_b] <= k){\r\n result.push(b[idx_b]);\r\n idx_b++;\r\n }else return -1;\r\n }\r\n return result.join(' ');\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let [k, n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr1 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr2 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let i = 0,\r\n j = 0,\r\n res = [];\r\n while (i < n || j < m) {\r\n if (i < n && arr1[i] === 0) {\r\n res.push(arr1[i++]);\r\n k++;\r\n } else if (j < m && arr2[j] === 0) {\r\n res.push(arr2[j++]);\r\n k++;\r\n } else if (i < n && arr1[i] <= k) res.push(arr1[i++]);\r\n else if (j < m && arr2[j] <= k) res.push(arr2[j++]);\r\n else break;\r\n }\r\n if (res.length === n + m) console.log(res.join(\" \"));\r\n else console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tvar K = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(M);\r\n\t\tvar output = [];\r\n\t\twhile(alist.length + blist.length > 0){\r\n\t\t\tif(alist.length > 0){\r\n\t\t\t\tif(alist[0] == 0){\r\n\t\t\t\t\toutput.push(alist.shift());\r\n\t\t\t\t\tK++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}else if(alist[0] <= K){\r\n\t\t\t\t\toutput.push(alist.shift());\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(blist.length > 0){\r\n\t\t\t\tif(blist[0] == 0){\r\n\t\t\t\t\toutput.push(blist.shift());\r\n\t\t\t\t\tK++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}else if(blist[0] <= K){\r\n\t\t\t\t\toutput.push(blist.shift());\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\toutput = -1;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tif(output == -1){\r\n\t\t\tmyout(output);\r\n\t\t}else{\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nlet chng;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tlet [k, n, m] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tfunction go (ar) {\r\n\t\t\twhile (ar.length && ar[0] <= k) {\r\n\t\t\t\tif (ar[0] == 0) k++;\r\n\t\t\t\tans.push(ar[0]);\r\n\t\t\t\tar.shift();\r\n\t\t\t\tchng = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = [];\r\n\t\tlet i = 0, j = 0;\r\n\t\twhile (a.length || b.length) {\r\n\t\t\tchng = false;\r\n\t\t\tgo(a);\r\n\t\t\tgo(b);\r\n\r\n\t\t\tif (!chng) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nconst acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\nconst arr = [];\r\nfor (let i = acode; i <= zcode; i++) {\r\n arr.push(String.fromCharCode(i));\r\n}\r\n\r\n\r\n\r\nfunction solve() {\r\n read();\r\n const [k, n, m] = readArray(Number);\r\n const a = readArray(Number);\r\n const b = readArray(Number);\r\n const ans = [];\r\n let curn = k;\r\n let ia = 0;\r\n let ib = 0;\r\n for (let i = 0; i < n + m; i++) {\r\n if (a[ia] === 0) {\r\n ans.push(0);\r\n ia++;\r\n curn++;\r\n continue;\r\n }\r\n if (b[ib] === 0) {\r\n ans.push(0);\r\n ib++;\r\n curn++;\r\n continue;\r\n }\r\n if (a[ia] <= curn) {\r\n ans.push(a[ia]);\r\n ia++;\r\n continue;\r\n }\r\n if (b[ib] <= curn) {\r\n ans.push(b[ib]);\r\n ib++;\r\n continue;\r\n }\r\n write(-1);\r\n return;\r\n }\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n // let p1x,p1y,p2x,p2y,p3x,p3y;\r\n\r\n readLine();\r\n p1=readLine();\r\n p2=readLine();\r\n p3=readLine();\r\n p1=p1.split(\" \");\r\n p2=p2.split(\" \");\r\n p3=p3.split(\" \");\r\n k=parseInt(p1[0]);\r\n n=parseInt(p1[1]);\r\n m=parseInt(p1[2]);\r\n //console.log(n,m,k);\r\n vec1=[],vec2=[],vec=[];\r\n for(i=0;icnt)\r\n {\r\n chk=false;\r\n break;\r\n }\r\n\r\n }\r\n //console.log(\"hello \",chk);\r\n if(chk===false)\r\n {\r\n console.log(-1);\r\n //cout<<-1< new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const t = input.number();\r\n const ans = Array(t);\r\n loop: for (let i = 0; i < t; i++) {\r\n let [k, n, m] = input.numbers(3);\r\n const A = input.numbers(n);\r\n const B = input.numbers(m);\r\n A.reverse();\r\n B.reverse();\r\n const seq = [];\r\n for (let j = 0; j < n + m; j++) {\r\n if (!A.isEmpty() && A.last() === 0) {\r\n k++;\r\n seq.push(A.pop());\r\n }\r\n else if (!B.isEmpty() && B.last() === 0) {\r\n k++;\r\n seq.push(B.pop());\r\n }\r\n else {\r\n if (!A.isEmpty() && !B.isEmpty()) {\r\n if (A.last() < B.last()) {\r\n const line = A.pop();\r\n if (line > k) {\r\n ans[i] = [-1];\r\n continue loop;\r\n }\r\n seq.push(line);\r\n }\r\n else {\r\n const line = B.pop();\r\n if (line > k) {\r\n ans[i] = [-1];\r\n continue loop;\r\n }\r\n seq.push(line);\r\n }\r\n }\r\n else if (!A.isEmpty()) {\r\n const line = A.pop();\r\n if (line > k) {\r\n ans[i] = [-1];\r\n continue loop;\r\n }\r\n seq.push(line);\r\n }\r\n else {\r\n const line = B.pop();\r\n if (line > k) {\r\n ans[i] = [-1];\r\n continue loop;\r\n }\r\n seq.push(line);\r\n }\r\n }\r\n }\r\n ans[i] = seq;\r\n }\r\n console.log(ans.map((seq) => seq.join(' ')).join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.trim().split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++].trim();\r\n\r\n while(testCases--){\r\n let blank = input[z++];\r\n let [k, n, m] = input[z++].trim().split(' ').map(Number);\r\n let arrN = input[z++].trim().split(' ').map(Number);\r\n let arrM = input[z++].trim().split(' ').map(Number);\r\n \r\n let a = 0, b = 0;\r\n let lines = k;\r\n let result = [];\r\n let flag = true;\r\n for (let i = 0; i < n+ m; i++){\r\n if(arrN[a] === 0){\r\n result.push(arrN[a]);\r\n lines++;\r\n a++;\r\n }else if(arrN[a] !== 0 && arrN[a] <= lines){\r\n result.push(arrN[a]);\r\n a++;\r\n }\r\n else if(arrM[b] === 0){\r\n result.push(arrM[b]);\r\n lines++;\r\n b++;\r\n }else if(arrM[b] !== 0 && arrM[b] <= lines){\r\n result.push(arrM[b]);\r\n b++;\r\n }\r\n else{\r\n flag = false;\r\n }\r\n }\r\n let ans = flag ? result : [-1];\r\n console.log(...ans);\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var [k, n, m] = lines[l++].trim().split(' ').map(Number)\n var a1 = lines[l++].trim().split(' ').map(Number)\n var a2 = lines[l++].trim().split(' ').map(Number)\n console.log(solve(k, n, m, a1, a2))\n }\n});\n\nfunction solve(k, n, m, a1, a2) {\n // console.log(a1, a2)\n let i = 0\n let j = 0\n const r = []\n while (i < n && j < m) {\n const b1 = a1[i] && a1[i] > k\n const b2 = a2[j] && a2[j] > k\n if (b1 && b2) {\n return -1\n } else if (b1) {\n if (!a2[j]) k++\n r.push(a2[j++])\n } else if (b2) {\n if (!a1[i]) k++\n r.push(a1[i++])\n } else {\n if (!a1[i]) k++\n if (!a2[j]) k++\n r.push(a1[i++])\n r.push(a2[j++])\n }\n }\n while (i < n) {\n if (a1[i] > k) return -1\n if (!a1[i]) k++\n r.push(a1[i++])\n }\n while (j < m) {\n if (a2[j] > k) return -1\n if (!a2[j]) k++\n r.push(a2[j++])\n }\n return r.join(' ')\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.trim().split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++].trim();\r\n\r\n while(testCases--){\r\n let blank = input[z++];\r\n let [k, n, m] = input[z++].trim().split(' ').map(Number);\r\n let arrN = input[z++].trim().split(' ').map(Number);\r\n let arrM = input[z++].trim().split(' ').map(Number);\r\n \r\n let line = +k;\r\n for (let i = 0; i < n; i++) {\r\n if(arrN[i] === 0) line++;\r\n }\r\n for (let i = 0; i < m; i++) {\r\n if(arrM[i] === 0) line++;\r\n }\r\n\r\n let maxN = Math.max(...arrN);\r\n let maxM = Math.max(...arrM);\r\n let max = Math.max(maxM, maxN);\r\n\r\n if(line >= max){\r\n let result = [];\r\n let counter = 0;\r\n for (let i = 0; i < n+ m; i++){\r\n if(arrN[counter] < arrM[counter]){\r\n result.push(arrN[counter]);\r\n result.push(arrM[counter]);\r\n }else{\r\n result.push(arrM[counter]);\r\n result.push(arrN[counter]);\r\n }\r\n counter++;\r\n }\r\n result = result.filter(x=>x!= undefined);\r\n console.log(...result);\r\n }\r\n else{\r\n console.log(-1);\r\n }\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.trim().split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++].trim();\r\n\r\n while(testCases--){\r\n let blank = input[z++];\r\n let [k, n, m] = input[z++].trim().split(' ').map(Number);\r\n let arrN = input[z++].trim().split(' ').map(Number);\r\n let arrM = input[z++].trim().split(' ').map(Number);\r\n \r\n let line = +k;\r\n for (let i = 0; i < n; i++) {\r\n if(arrN[i] === 0) line++;\r\n }\r\n for (let i = 0; i < m; i++) {\r\n if(arrM[i] === 0) line++;\r\n }\r\n\r\n let maxN = Math.max(...arrN);\r\n let maxM = Math.max(...arrM);\r\n let max = Math.max(maxM, maxN);\r\n\r\n if(line >= max){\r\n let result = [];\r\n let counter = 0;\r\n for (let i = 0; i < n+ m; i+=2){\r\n if(arrN[counter] < arrM[counter]){\r\n result.push(arrN[counter]);\r\n result.push(arrM[counter]);\r\n }else{\r\n result.push(arrM[counter]);\r\n result.push(arrN[counter]);\r\n }\r\n counter++;\r\n }\r\n result = result.filter(x=>x!= undefined);\r\n console.log(...result);\r\n }\r\n else{\r\n console.log(-1);\r\n }\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var [k, n, m] = lines[l++].trim().split(' ').map(Number)\n var a1 = lines[l++].trim().split(' ').map(Number)\n var a2 = lines[l++].trim().split(' ').map(Number)\n console.log(solve(k, n, m, a1, a2))\n }\n});\n\nfunction solve(k, n, m, a1, a2) {\n // console.log(a1, a2)\n let i = 0\n let j = 0\n const r = []\n while (i < n && j < m) {\n const b1 = a1[i] && a1[i] > k\n const b2 = a2[j] && a2[j] > k\n if (b1 && b2) {\n return -1\n } else if (b1) {\n if (!a2[j]) k++\n r.push(a2[j++])\n } else if (b2) {\n if (!a1[i]) k++\n r.push(a1[i++])\n } else {\n if (!a1[i]) k++\n if (!a2[j]) k++\n r.push(a1[i++])\n r.push(a2[j++])\n }\n }\n while (i < n) {\n if (a1[i] > k) return -1\n if (!a1[i]) k++\n r.push(a1[i++])\n }\n while (j < m) {\n if (a2[j] > k) return -1\n r.push(a2[j++])\n r.push(a2[j++])\n }\n return r.join(' ')\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var [k, n, m] = lines[l++].trim().split(' ').map(Number)\n var a1 = lines[l++].trim().split(' ').map(Number)\n var a2 = lines[l++].trim().split(' ').map(Number)\n console.log(solve(k, n, m, a1, a2))\n }\n});\n\nfunction solve(k, n, m, a1, a2) {\n // console.log(a1, a2)\n let i = 0\n let j = 0\n const r = []\n while (i < n && j < m) {\n const b1 = a1[i] && a1[i] > k\n const b2 = a2[j] && a2[j] > k\n if (b1 && b2) {\n return -1\n } else if (b1) {\n if (!a2[j]) k++\n r.push(a2[j++])\n } else if (b2) {\n if (!a1[i]) k++\n r.push(a1[i++])\n } else {\n if (!a1[i]) k++\n if (!a2[j]) k++\n r.push(a1[i++])\n r.push(a2[j++])\n }\n }\n while (i < n) {\n if (a1[i] > k) return -1\n r.push(a1[i++])\n }\n while (j < m) {\n if (a2[j] > k) return -1\n r.push(a2[j++])\n }\n return r.join(' ')\n}\n"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let [k, n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr1 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr2 = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = \"\";\r\n let i = 0,\r\n j = 0,\r\n flag = 1;\r\n while (i < n && j < m) {\r\n if (arr1[i] === 0 && arr2[j] === 0) {\r\n res += 0 + \" \" + 0 + \" \";\r\n k += 2;\r\n } else if (arr1[i] === 0) {\r\n res += 0 + \" \";\r\n k++;\r\n if (arr2[j] <= k) res += arr2[j] + \" \";\r\n else {\r\n flag = 0;\r\n break;\r\n }\r\n } else if (arr2[j] === 0) {\r\n res += 0 + \" \";\r\n k++;\r\n if (arr1[i] <= k) res += arr1[j] + \" \";\r\n else {\r\n flag = 0;\r\n break;\r\n }\r\n } else {\r\n if (arr1[i] <= k && arr2[j] <= k) res += arr1[i] + \" \" + arr2[j] + \" \";\r\n else {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n i++;\r\n j++;\r\n }\r\n if (flag === 0) {\r\n console.log(-1);\r\n continue;\r\n }\r\n while (i < n) res += arr1[i++] + \" \";\r\n while (j < m) res += arr2[j++] + \" \";\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tvar K = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(M);\r\n\t\tvar output = [];\r\n\t\twhile(alist.length + blist.length > 0){\r\n\t\t\tif(alist.length > 0){\r\n\t\t\t\tif(alist[0] == 0){\r\n\t\t\t\t\toutput.push(alist.shift());\r\n\t\t\t\t\tK++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}else if(alist[0] - 1 <= K){\r\n\t\t\t\t\toutput.push(alist.shift());\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(blist.length > 0){\r\n\t\t\t\tif(blist[0] == 0){\r\n\t\t\t\t\toutput.push(blist.shift());\r\n\t\t\t\t\tK++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}else if(blist[0] - 1 <= K){\r\n\t\t\t\t\toutput.push(blist.shift());\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\toutput = -1;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tif(output == -1){\r\n\t\t\tmyout(output);\r\n\t\t}else{\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "6628bd89b4d4fdfa90d2357f7cc1b795"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = 1//+lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, q] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\r\n l += q\r\n output[i] = solve(n, arr, qs)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr, qs) {\r\n const sum = Array(n)\r\n sum[0] = arr[0]\r\n const xor = Array(n)\r\n xor[0] = arr[0]\r\n for (let i = 1; i < arr.length; i++) {\r\n sum[i] = sum[i - 1] + arr[i]\r\n xor[i] = xor[i - 1] ^ arr[i]\r\n }\r\n //\r\n const even = {}\r\n even[0] = [-1]\r\n const odd = {}\r\n let x = 0\r\n for (let i = 0; i < arr.length; i++) {\r\n x ^= arr[i]\r\n const [get, set] = (i & 1) ? [odd, even] : [even, odd]\r\n set[x] = (set[x] || [])\r\n ;set[x].push(i)\r\n }\r\n// console.log(even, odd)\r\n return qs.map(([l, r]) => {\r\n l--; r--\r\n if (!rangeSum(l, r)) return 0\r\n if (rangeXor(l, r)) return -1\r\n const len = r - l + 1\r\n if (len & 1) return 1\r\n // [l, x] = 0\r\n const [get, set] = (r & 1) ? [odd, even] : [even, odd]\r\n const lst = get[xor[r]] || []\r\n const j = binarySearch(0, lst.length - 1, x => lst[x] <= r)\r\n// console.log(l, r, lst, j)\r\n return lst[j] >= l ? ((!arr[l] || !arr[r]) ? 1 : 2) : -1\r\n }).join('\\n')\r\n\r\n function rangeXor(l, r) {\r\n return xor[r] ^ (xor[l - 1] || 0)\r\n }\r\n function rangeSum(l, r) {\r\n return sum[r] - (sum[l - 1] || 0)\r\n }\r\n}\r\nfunction binarySearch(l, r, fn) {\r\n while (l <= r) {\r\n const m = Math.floor((l + r) / 2)\r\n if (fn(m)) {\r\n l = m + 1\r\n } else {\r\n r = m - 1\r\n }\r\n }\r\n return r\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns(),\r\n b = [];\r\n const xorsum = [0],\r\n sum = [0],\r\n res = [];\r\n for (let i = 1; i <= n; i++) {\r\n xorsum[i] = xorsum[i - 1] ^ a[i - 1];\r\n sum[i] = sum[i - 1] + a[i - 1];\r\n }\r\n for (let i = 0; i < q; i++) {\r\n let [x, y] = rns();\r\n if ((xorsum[y] ^ xorsum[x - 1]) !== 0) {\r\n res[i] = -1;\r\n } else if (sum[y] - sum[x - 1] === 0) {\r\n res[i] = 0;\r\n } else {\r\n let d = y - x + 1;\r\n if (d & 1) {\r\n res[i] = 1;\r\n } else {\r\n b.push([x, y, i]);\r\n }\r\n }\r\n }\r\n b.sort((a, b) => a[1] - b[1]);\r\n let map = new Map();\r\n map.set(0, [0]);\r\n for (let i = 1, j = 0; i <= n; i++) {\r\n var _map$get;\r\n const cur = xorsum[i];\r\n let l = (_map$get = map.get(cur)) === null || _map$get === void 0 ? void 0 : _map$get[i & 1 ^ 1];\r\n while (j < b.length && b[j][1] === i) {\r\n const [x, y, k] = b[j];\r\n if (l !== undefined && l >= x) {\r\n if (a[x - 1] === 0 || a[y - 1] === 0) {\r\n res[k] = 1;\r\n } else {\r\n res[k] = 2;\r\n }\r\n } else {\r\n res[k] = -1;\r\n }\r\n j++;\r\n }\r\n if (!map.has(cur)) map.set(cur, []);\r\n map.get(cur)[i & 1] = i;\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns(),\r\n b = [];\r\n const xorsum = [0],\r\n sum = [0],\r\n res = [];\r\n for (let i = 1; i <= n; i++) {\r\n xorsum[i] = xorsum[i - 1] ^ a[i - 1];\r\n sum[i] = sum[i - 1] + a[i - 1];\r\n }\r\n for (let i = 0; i < q; i++) {\r\n let [x, y] = rns();\r\n if ((xorsum[y] ^ xorsum[x - 1]) !== 0) {\r\n res[i] = -1;\r\n } else if (sum[y] - sum[x - 1] === 0) {\r\n res[i] = 0;\r\n } else {\r\n let d = y - x + 1;\r\n if (d & 1) {\r\n res[i] = 1;\r\n } else {\r\n b.push([x, y, i]);\r\n }\r\n }\r\n }\r\n b.sort((a, b) => a[1] - b[1]);\r\n const map = new Map();\r\n map.set(0, [0]);\r\n for (let i = 1, j = 0; i <= n; i++) {\r\n var _map$get;\r\n const cur = xorsum[i];\r\n let k = i & 1 ^ 1;\r\n let l = (_map$get = map.get(cur)) === null || _map$get === void 0 ? void 0 : _map$get[k];\r\n while (j < b.length && b[j][1] === i) {\r\n if (l !== undefined && l > b[j][0]) {\r\n var _sum$l;\r\n if (sum[i] - ((_sum$l = sum[l]) !== null && _sum$l !== void 0 ? _sum$l : 0) === 0) {\r\n res[b[j][2]] = 1;\r\n } else {\r\n res[b[j][2]] = 2;\r\n }\r\n } else {\r\n res[b[j][2]] = -1;\r\n }\r\n j++;\r\n }\r\n if (!map.has(cur)) map.set(cur, []);\r\n map.get(cur)[i & 1] = i;\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns(),\r\n b = [];\r\n const xorsum = [],\r\n sum = [],\r\n res = [];\r\n for (let i = 0; i < n; i++) {\r\n var _xorsum, _sum;\r\n xorsum[i] = ((_xorsum = xorsum[i - 1]) !== null && _xorsum !== void 0 ? _xorsum : 0) ^ a[i];\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n }\r\n for (let i = 0; i < q; i++) {\r\n var _xorsum2, _sum2;\r\n let [x, y] = rns();\r\n x--;\r\n y--;\r\n if ((xorsum[y] ^ ((_xorsum2 = xorsum[x - 1]) !== null && _xorsum2 !== void 0 ? _xorsum2 : 0)) !== 0) {\r\n res[i] = -1;\r\n } else if (sum[y] - ((_sum2 = sum[x - 1]) !== null && _sum2 !== void 0 ? _sum2 : 0) === 0) {\r\n res[i] = 0;\r\n } else {\r\n let d = y - x + 1;\r\n if (d & 1) {\r\n res[i] = 1;\r\n } else {\r\n b.push([x, y, i]);\r\n }\r\n }\r\n }\r\n b.sort((a, b) => a[1] - b[1]);\r\n const map = new Map();\r\n map.set(0, [, -1]);\r\n for (let i = 0, j = 0; i < n; i++) {\r\n const cur = xorsum[i];\r\n let k = i & 1 ^ 1;\r\n while (j < b.length && b[j][1] === i) {\r\n var _map$get;\r\n let l = (_map$get = map.get(cur)) === null || _map$get === void 0 ? void 0 : _map$get[k];\r\n if (l !== undefined && l > b[j][0]) {\r\n var _sum$l;\r\n if (sum[i] - ((_sum$l = sum[l]) !== null && _sum$l !== void 0 ? _sum$l : 0) === 0) {\r\n res[b[j][2]] = 1;\r\n } else {\r\n res[b[j][2]] = 2;\r\n }\r\n } else {\r\n res[b[j][2]] = -1;\r\n }\r\n j++;\r\n }\r\n if (!map.has(cur)) map.set(cur, []);\r\n map.get(cur)[i & 1] = i;\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) ; else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const sum = Array(n)\n sum[0] = arr[0]\n const xor = Array(n)\n xor[0] = arr[0]\n for (let i = 1; i < arr.length; i++) {\n sum[i] = sum[i - 1] + arr[i]\n xor[i] = xor[i - 1] ^ arr[i]\n }\n //\n const even = {}\n even[0] = [-1]\n const odd = {}\n let x = 0\n for (let i = 0; i < arr.length; i++) {\n x ^= arr[i]\n const [get, set] = (i & 1) ? [odd, even] : [even, odd]\n set[x] = (set[x] || [])\n ;set[x].push(i)\n }\n// console.log(even, odd)\n return qs.map(([l, r]) => {\n l--; r--\n if (!rangeSum(l, r)) return 0\n if (rangeXor(l, r)) return -1\n const len = r - l + 1\n if (len & 1) return 1\n // [l, x] = 0\n const [get, set] = (r & 1) ? [odd, even] : [even, odd]\n const lst = get[xor[r]] || []\n const j = binarySearch(0, lst.length - 1, x => lst[x] <= r)\n// console.log(l, r, lst, j)\n return lst[j] >= l ? 2 : -1\n }).join('\\n')\n\n function rangeXor(l, r) {\n return xor[r] ^ (xor[l - 1] || 0)\n }\n function rangeSum(l, r) {\n return sum[r] - (sum[l - 1] || 0)\n }\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "4754dd329ec5a01d4d101951656bf66a"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lines = [];\nrl.on('line', (line) => {\n lines.push(line.trim());\n if (lines.length === 3) {\n main();\n }\n}).on('close', () => {\n process.exit(0);\n});\n\nfunction main() {\n // parse input\n // throw away count line\n var costs = lines[1].split(\" \").map(function(x) { return parseInt(x); })\n var bills = lines[2].split(\" \").map(function(x) { return parseInt(x); })\n console.log(solve(costs, bills));\n}\n\nfunction solve(costs, bills) {\n // console.log('costs ', costs, ' bills ', bills);\n var billIndex = 0;\n var purchasedGames = 0;\n for (var i = 0; i < costs.length; i++) {\n // console.log('Comparing cost ', costs[i], ' and bill ', bills[billIndex]);\n if (bills[billIndex] >= costs[i]) {\n // console.log('can afford');\n // we can afford this game\n purchasedGames++;\n billIndex++;\n // console.log('purchased Games: ', purchasedGames, ' and billIndex: ', billIndex);\n // console.log('bills length', bills.length);\n if (billIndex === bills.length) {\n // console.log('breaking');\n // no more money left\n break;\n }\n } // else if we can't afford the game, keep looping to next cost\n }\n return purchasedGames;\n}\n\n// uncomment for testing\n// console.log(solve([2,4,5,2,4], [5,3,4,6]));\n// console.log(solve([20,40,50,20,40], [19,20]));\n// console.log(solve([4,8,15,16,23,42], [1000,1000,1000,1000]));\n\n// uncomment for submission\n//main();\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n const games = is.nextArray();\n const bills = is.nextArray();\n for (let i = 0; i < n; i += 1) {\n games[i] = parseInt(games[i], 10);\n }\n for (let i = 0; i < bills.length; i += 1) {\n bills[i] = parseInt(bills[i], 10);\n }\n\n let i = 0, j = 0;\n while (i < n && j < m) {\n if (bills[j] >= games[i]) {\n j += 1;\n }\n i += 1;\n }\n\n console.log(j);\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar M = one[1];\n\tvar nlist = nextIntArray();\n\tvar mlist = nextIntArray();\n\tvar count = 0;\n\tfor(var i = 0; i < N; i++){\n\t\tif(mlist.length == 0){\n\t\t\tbreak;\n\t\t}\n\t\tif(nlist[i] <= mlist[0]){\n\t\t\tcount++;\n\t\t\tmlist.shift();\n\t\t}\n\t}\n\tmyout(count);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet games, money;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n if (c === 1) {\n games = d.split(' ').map(Number);\n c++;\n return;\n }\n\n money = d.split(' ').map(Number);\n\n let ans = 0;\n let bill = 0;\n\n for (let i = 0; i < games.length; i++) {\n if (money[bill] >= games[i]) {\n ans++;\n bill++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "var n = readline().split(' ')\nvar c = readline().split(' ').map(Number)\nvar a = readline().split(' ').map(Number)\n\nvar k = 0\n\nfor(var i = 0;i < n[0];i++){\n\tif(c[i] <= a[k]){\n\t\tk++\n\t}\n\tif(k >= n[1]) break\n}\n\nprint(k)"}, {"source_code": "var k = readline().split(\" \").map(function(d){\n return parseInt(d) \n})\n\nvar c = readline().split(' ').map(function(d){\n return parseInt(d) \n})\nvar a =readline().split(' ').map(function(d){\n return parseInt(d) \n})\nvar idx = 0,counter=0;\n for(var i=0;i {\n s += data;\n});\n\nprocess.stdin.on(\"end\", (data) => {\n s = s\n .split(\"\\n\")\n .filter(Boolean)\n .map((s) => s.split(\" \").map(Number));\n main();\n});\n\nfunction main() {\n const tests = s[1];\n\n tests.forEach((num) => {\n solution(num);\n });\n}\n\nfunction solution(num) {\n if (num === 0) {\n console.log(0);\n return;\n }\n let min = 15;\n for (let i = 0; i < 16; i++) {\n if (min <= i) {\n break;\n }\n min = Math.min(min, i + solveForTwo(num + i, min - i));\n }\n console.log(min);\n}\n\nfunction solveForTwo(num, limit) {\n let twoFact = 0;\n let n = num;\n if (num % 2 ** (15 - limit) !== 0) {\n return Infinity;\n }\n n /= 2 ** (15 - limit);\n twoFact = 15 - limit;\n while (n % 2 === 0) {\n twoFact++;\n n = n / 2;\n }\n return 15 - twoFact;\n}\n", "positive_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = 32768\r\n\r\nconst mod = num => (num >= N ? num - N : num)\r\n\r\nfunction solve(num) {\r\n let queue = [[num, 0]]\r\n const set = new Set([num])\r\n while (true) {\r\n const tmp = []\r\n for (let [num, count] of queue) {\r\n if (num === 0) {\r\n return count\r\n }\r\n for (let num1 of [mod(num + 1), mod(num * 2)]) {\r\n if (num1 === 0) {\r\n return count + 1\r\n }\r\n if (set.has(num1)) continue\r\n tmp.push([num1, count + 1])\r\n set.add(num1)\r\n }\r\n }\r\n queue = tmp\r\n }\r\n}\r\n\r\n// let table = []\r\n// for (let i = 0; i <= N; i++) {\r\n// if (i % 2 === 0) table[i/2] = solve(i)\r\n// }\r\n// console.log(JSON.stringify(table))\r\n\r\nconst table=[0,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,12,10,8,6,4,2,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,11,9,7,5,3,1,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,12,10,8,6,4,2,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,12,10,8,6,4,2,16]\r\n\r\nvoid (function main() {\r\n let n = Number(inputs[0])\r\n const nums = inputs[1].split(' ').map(Number)\r\n const res = []\r\n for (let i = 0; i < n; i++) {\r\n const num=nums[i]\r\n if((num+1)%N===0)res.push(1)\r\n else if(num%2===0)res.push(table[num/2])\r\n else res.push(table[(num+1)/2]+1)\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 32768;\n\nlet cache = new Map();\n\nlet get_v1s = n=>{\n if (n%2)\n return [];\n n = n/2;\n let ans = [n];\n let c = n|(1<<14)\n if (c{\n let queue = [], qi = 0;\n queue.push([0, 0])\n let m = new Map();\n m.set(0, 0)\n while (qim.get(n));\n};\n \nfunction main() {\n let T = 1|| +readline()\n while (T--){\n let [n] = ra();\n let a = ra();\n l('ans')\n print(calc(a).join(' '));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const dp = Array(32769).fill(Infinity)\n const q = [0, 32768]\n let d = 0\n while (q.length) {\n const nq = {}\n while (q.length) {\n const u = q.shift()\n if (d >= dp[u]) continue\n dp[u] = d\n\n const a = (u - 1 + 32768) % 32768\n if (d + 1 < dp[a]) nq[a] = 1\n if (!(u & 1)) {\n const b = u / 2\n if (d + 1 < dp[b]) nq[b] = 1\n const c = (u + 32768) / 2\n if (d + 1 < dp[c]) nq[c] = 1\n }\n }\n for (let k in nq) q.push(+k)\n d++\n }\n // console.log(dp.join(','))\n return arr.map(x => dp[x]).join(' ')\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n const helper = (num) => {\r\n let cnt = 0;\r\n while (num % 2 === 0) {\r\n cnt++;\r\n num /= 2;\r\n }\r\n return cnt;\r\n };\r\n for (let i = 0; i < n; i++) {\r\n if (32768 - arr[i] <= 15) console.log(32768 - arr[i]);\r\n else if(arr[i]===0) console.log(0);\r\n else {\r\n let a = Infinity;\r\n for (let j = 1, k = 0; j <= 15; j++, arr[i]++, k++) {\r\n let h = helper(arr[i]);\r\n if (h === 0) continue;\r\n else a = Math.min(15 - h + k, a);\r\n }\r\n console.log(a);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst memo = new Map();\n\nconst mod = 32768;\n\nconst factor2 = (num) => {\n let res = 0;\n while (num % 2 === 0) {\n res++;\n num /= 2;\n }\n return res;\n};\n\nconst memo2 = new Map();\n\nconst calc = (number)=>{\n if (number === 0) return 0;\n\n let num2 = factor2(number);\n // if (memo2.has(number)) {\n // num2 = memo.get(number);\n // } else {\n // num2 = factor2(number);\n // memo2.set(number, num2);\n // }\n // if(typeof num2 === 'undefined') console.log('DEBUG number', number);\n\n let res = 15 - num2;\n\n for (let i = 1; i <= 15; i++) {\n let curnum = number + i;\n num2 = factor2(curnum);\n // if (memo2.has(curnum)) {\n // num2 = memo.get(curnum);\n // } else {\n // num2 = factor2(curnum);\n // memo2.set(curnum, num2);\n // }\n // console.log('DEBUG num2', num2);\n res = Math.min(res, i + (15 - num2));\n }\n\n return res;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n // let n = +readline();\n // let a = ra();\n // let b = ra();\n // console.log(`${calc(n, a, b)}`);\n // }\n let n = +readline();\n let a = ra();\n console.log(`${a.map((item) => {\n return calc(item);\n }).join(' ')}`);\n}\n\n\n\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let ans = [];\r\n for (let i = 0; i < n; i++) {\r\n let cnt = 0;\r\n if (32768 - arr[i] <= 15) {\r\n ans.push(32768 - arr[i]);\r\n continue;\r\n }\r\n while (true) {\r\n let j = gcd(arr[i], 32768);\r\n if (j === 1) {\r\n cnt++;\r\n arr[i]++;\r\n } else {\r\n let k = 32768 / j;\r\n k = Math.log2(k);\r\n cnt += k;\r\n break;\r\n }\r\n }\r\n ans.push(cnt);\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst memo = new Map();\n\nconst mod = 32768;\n\nconst factor2 = (num) => {\n let res = 0;\n while (num % 2 === 0) {\n res++;\n num /= 2;\n }\n return res;\n};\n\nconst memo2 = new Map();\n\nconst calc = (number)=>{\n if (number === 0) return 0;\n\n let num2 = factor2(number);\n // if (memo2.has(number)) {\n // num2 = memo.get(number);\n // } else {\n // num2 = factor2(number);\n // memo2.set(number, num2);\n // }\n // if(typeof num2 === 'undefined') console.log('DEBUG number', number);\n\n let res = 15 - num2;\n\n for (let i = 1; i <= 15; i++) {\n let curnum = number + i;\n num2 = factor2(number);\n // if (memo2.has(curnum)) {\n // num2 = memo.get(curnum);\n // } else {\n // num2 = factor2(curnum);\n // memo2.set(curnum, num2);\n // }\n // console.log('DEBUG num2', num2);\n res = Math.min(res, i + (15 - num2));\n }\n\n return res;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n // let n = +readline();\n // let a = ra();\n // let b = ra();\n // console.log(`${calc(n, a, b)}`);\n // }\n let n = +readline();\n let a = ra();\n console.log(`${a.map((item) => {\n return calc(item);\n }).join(' ')}`);\n}\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst memo = new Map();\n\nconst mod = 32768;\n\nconst factor2 = (num) => {\n let res = 0;\n while (num % 2 === 0) {\n res++;\n num /= 2;\n }\n return res;\n};\n\nconst memo2 = new Map();\n\nconst calc = (number)=>{\n if (number === 0) return 0;\n\n let num2;\n if (memo2.has(number)) {\n num2 = memo.get(number);\n } else {\n num2 = factor2(number);\n memo2.set(number, num2);\n }\n\n let res = 15 - num2;\n\n for (let i = 1; i <= 15; i++) {\n let curnum = number + i;\n if (memo2.has(curnum)) {\n num2 = memo.get(curnum);\n } else {\n num2 = factor2(curnum);\n memo2.set(curnum, num2);\n }\n res = Math.min(res, i + (15 - num2));\n }\n\n return res;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n // let n = +readline();\n // let a = ra();\n // let b = ra();\n // console.log(`${calc(n, a, b)}`);\n // }\n let n = +readline();\n let a = ra();\n console.log(`${a.map((item) => {\n return calc(item);\n }).join(' ')}`);\n}\n\n\n\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = 32768\r\n\r\nconst mod = num => (num >= N ? num - N : num)\r\n\r\nfunction solve(num) {\r\n let queue = [[num, 0]]\r\n const set = new Set([num])\r\n while (true) {\r\n const tmp = []\r\n for (let [num, count] of queue) {\r\n if (num === 0) {\r\n return count\r\n }\r\n for (let num1 of [mod(num + 1), mod(num * 2)]) {\r\n if (num1 === 0) {\r\n return count + 1\r\n }\r\n if (set.has(num1)) continue\r\n tmp.push([num1, count + 1])\r\n set.add(num1)\r\n }\r\n }\r\n queue = tmp\r\n }\r\n}\r\n\r\n// let table = []\r\n// for (let i = 0; i <= N; i++) {\r\n// if (i % 2 === 0) table[i/2] = solve(i)\r\n// }\r\n// console.log(JSON.stringify(table))\r\n\r\nconst table=[0,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,12,10,8,6,4,2,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,11,9,7,5,3,1,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,12,10,8,6,4,2,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,13,11,9,7,5,3,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,10,8,6,4,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,11,9,7,5,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,12,10,8,6,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,13,11,9,7,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,12,10,8,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,13,14,12,14,13,11,9,14,13,14,12,14,13,13,11,14,13,14,12,14,13,12,10,14,13,14,12,14,13,13,11,14,12,10,8,6,4,2,16]\r\n\r\nvoid (function main() {\r\n let n = Number(inputs[0])\r\n const nums = inputs[1].split(' ').map(Number)\r\n const res = []\r\n for (let i = 0; i < n; i++) {\r\n const num=nums[i]\r\n if(num%2===0)res.push(table[num/2])\r\n else res.push(table[(num+1)/2]+1)\r\n }\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const dp = Array(32769).fill(Infinity)\n const q = [32768]\n let d = 0\n while (q.length) {\n const nq = {}\n while (q.length) {\n const u = q.shift()\n if (d >= dp[u]) continue\n dp[u] = d\n\n const a = (u - 1 + 32768) % 32768\n if (d + 1 < dp[a]) nq[a] = 1\n if (!(u & 1)) {\n const b = u / 2\n if (d + 1 < dp[b]) nq[b] = 1\n const c = (u + 32768) / 2\n if (d + 1 < dp[c]) nq[c] = 1\n }\n }\n for (let k in nq) q.push(+k)\n d++\n }\n return arr.map(x => dp[x]).join(' ')\n}\n"}], "src_uid": "5c844c0dc0eb718aea7b2446e90ce250"} {"source_code": "print(function(n, m) {\n\n\tvar a = readline().split(' ').map(Number);\n\n\tvar a1 = 0;\n\tvar i = 0;\n\tvar j = 0;\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar b = [].concat(a);\n\n\twhile (true) {\n\t\tif (i >= n) break;\n\t\t//if (j >= m) break;\n\t\ta1 += a[j];\n\t\ta[j]--;\n\t\tif (a[j] === 0) j++;\n\t\ti++;\n\t}\n\n\tvar a2 = 0;\n\tvar i = 0;\n\tvar x = b[b.length - 1];\n\n\tout: while (true) {\n\t\tfor (var j = 0; j < m; j++) {\n\t\t\tif (b[j] === x) {\n\t\t\t\tb[j]--;\n\t\t\t\ti++;\n\t\t\t\ta2 += x;\n\t\t\t\tif (i === n) break out;\n\t\t\t}\n\t\t}\n\t\tx--;\n\t\t// if (x === 0) break;\n\t}\n\n\treturn a2 + ' ' + a1;\n\n}.apply(0, readline().split(' ').map(Number)));\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [passengers, plains] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [minCount, maxCount] = [0, 0];\n const copyArr = [...arr];\n\n let i = 1;\n while (i <= passengers) {\n let max = Math.max(...arr);\n const maxIndex = arr.findIndex((n) => n === max);\n arr[maxIndex]--;\n\n const { min, minIndex } = findMin(copyArr);\n copyArr[minIndex]--;\n\n maxCount += max;\n minCount += min;\n i++;\n }\n console.log(`${maxCount} ${minCount}`);\n}\n\nfunction findMin(arr) {\n let [min, minIndex] = [Number.MAX_SAFE_INTEGER, -1];\n return arr.reduce(\n (obj, num, index) => {\n const { min, minIndex } = obj;\n if (num > 0 && num < min) {\n obj[\"min\"] = num;\n obj[\"minIndex\"] = index;\n }\n return obj;\n },\n { min, minIndex }\n );\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(747));let s=\"\",u=[],i=0,c=\"\";const l=\"local\"===process.argv[2],a=t=>{if(l)return u=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",c);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{u=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(c)}))};function f(){return u[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r0;)u+=r[s],i+=n[0],r[s]--,n[0]--,n=n.sortDesc(),t--,0==r[s]&&s++;o.default.put(i+\" \"+u)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "(()=>{\"use strict\";var t={312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const u=n(r(747));let o=\"\",s=[],i=0,l=\"\";const a=\"local\"===process.argv[2],c=t=>{if(a)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt-e)),n=n.sort(((t,e)=>e-t));let o=0,s=0,i=0;for(;t>0;)s+=r[o],i+=n[0],r[o]--,n[0]--,n=n.sort(((t,e)=>e-t)),t--,0==r[o]&&o++;u.default.put(i+\" \"+s)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "print(function(n, m) {\n\n\tvar a = readline().split(' ').map(Number);\n\n\tvar a1 = 0;\n\tvar i = 0;\n\tvar j = 0;\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar b = [].concat(a);\n\n\twhile (true) {\n\t\tif (i >= n) break;\n\t\tif (j >= m) break;\n\t\ta1 += a[j];\n\t\ta[j]--;\n\t\tif (a[j] === 0) j++;\n\t\ti++;\n\t}\n\n\tvar a2 = 0;\n\tvar i = 0;\n\tvar x = b[b.length - 1];\n\n\tout: while (true) {\n\t\tfor (var j = 0; j < m; j++) {\n\t\t\tif (b[j] === x) {\n\t\t\t\tb[j]--;\n\t\t\t\ti++;\n\t\t\t\ta2 += x;\n\t\t\t\tif (i === n) break out;\n\t\t\t}\n\t\t}\n\t\tx--;\n\t\tif (x === 0) break;\n\t}\n\n\treturn a2 + ' ' + a1;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var nm= readline().trim().split(' ').map((x)=>parseInt(x));\nvar n=nm[0],m=nm[1];\nvar n1=n2=n;\n\nvar x = readline().trim().split(' ').map((x)=>parseInt(x));\nvar maxi=0,mini=0;\n\nx.sort((a,b)=>a-b)\nfor(var i=0;i=x[i]){\n n1-=x[i];\n mini+=x[i]*(x[i]+1)/2;\n }else{\n mini+=x[i]*(x[i]+1)/2 -(x[i]-n1)*(x[i]-n1+1)/2;\n n1=0;\n }\n}\nvar maxx = x[x.length-1];\n\nvar values={};\nfor(var i=0;i=1;i--){\n maxi+=i*Math.min(n2,values[i]);\n n2-=Math.min(n2,values[i]);\n if(n2==0)\n break;\n}\nprint(maxi+' '+mini)"}, {"source_code": ";(function () {\n\tprint(function (n, m, a) {\n\t\treturn [\n\n\t\t\tfunction (n, M, r) {\n\t\t\t\twhile (n) {\n\t\t\t\t\tvar t = a.filter(function (e) { return e >= M; }).length;\n\t\t\t\t\tif (t > n) t = n;\n\t\t\t\t\tr += M-- * t;\n\t\t\t\t\tn -= t;\n\t\t\t\t} return r;\n\t\t\t}(n, Math.max.apply(null, a), 0),\n\n\t\t\tfunction (n, r) {\n\t\t\t\twhile (n) {\n\t\t\t\t\tvar t = Math.min.apply(null, a);\n\t\t\t\t\tr += t * (t + 1) / 2;\n\t\t\t\t\tif (t > n) {\n\t\t\t\t\t\tt -= n;\n\t\t\t\t\t\tr -= t * (t + 1) / 2;\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tn -= t;\t\n\t\t\t\t\t\ta.splice(a.indexOf(t), 1);\n\t\t\t\t\t}\n\t\t\t\t} return r;\n\t\t\t}(n, 0)\n\n\t\t].join(' ');\n\t}.apply(null, readline().split(' ').map(Number).concat([readline().split(' ').map(Number)])));\n}).call(this);"}, {"source_code": "var l = readline(),\n l2 = readline(),\n p = l2.split(' ').sort((a, b) => a - b).map(item => +item),\n p2 = l2.split(' ').sort((a, b) => a - b).map(item => +item),\n n = +l.split(' ')[0],\n cp = +l.split(' ')[1],\n min = 0,\n max = 0,\n si = 0;\n\nfor (var i = 0; i < n; i++) {\n var s = p.length - 1; \n while (p[s] < p[s - 1]) {\n var tmp = p[s - 1];\n p[s - 1] = p[s];\n p[s] = tmp;\n s--;\n }\n\n if (p2[si] === 0) {\n si++;\n }\n\n max += p[p.length - 1]--;\n min += p2[si]--;\n}\n\n//console.log(max + \" \" + min)\nprint(max + \" \" + min);\n\n"}, {"source_code": "\"use strict\"\nif (typeof print === 'undefined') var print = console.log;\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id ++];\n}\n\nlet nums = () => readline().split(' ').map(x => +x);\n\nlet t = nums(), n = t[0], m = t[1];\nlet a = nums(), b = [...a];\n\nfunction findmin() {\n let ans = 0;\n b.sort((a, b) => a - b);\n for (let i = -1; ++i < n; ) {\n while (b.length && b[0] == 0) b.shift();\n if (!b.length) break;\n ans += b[0]--;\n }\n return ans;\n}\n\nfunction findmax() {\n let ans = 0;\n for (let i = -1; ++i < n; ) {\n let t = 0;\n for (let f = 0; ++f < m; )\n if (a[t] < a[f]) t = f;\n if (a[t] == 0) break;\n ans += a[t]--;\n }\n return ans;\n}\n\nprint(findmax() + ' ' + findmin());\n\n"}], "negative_code": [{"source_code": "print(function(n, m) {\n\n\tvar a = readline().split(' ').map(Number);\n\n\tvar a1 = 0;\n\tvar i = 0;\n\tvar j = 0;\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tvar b = [].concat(a);\n\n\twhile (true) {\n\t\tif (i >= n) break;\n\t\tif (j >= m) break;\n\t\ta1 += a[j];\n\t\ta[j]--;\n\t\tif (a[j] === 0) j++;\n\t\ti++;\n\t}\n\n\tvar a2 = 0;\n\tvar i = 0;\n\tvar m = b[b.length - 1];\n\tout: while (true) {\n\t\tfor (var j = 0; j < n; j++) {\n\t\t\tif (b[j] === m) {\n\t\t\t\tb[j]--;\n\t\t\t\ti++;\n\t\t\t\ta2 += m;\n\t\t\t\tif (i === n) break out;\n\t\t\t}\n\t\t}\n\t\tm--;\n\t\tif (m === 0) break;\n\t}\n\n\treturn a2 + ' ' + a1;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var l = readline(),\n l2 = readline(),\n p = l2.split(' ').sort((a, b) => a - b).map(item => +item),\n p2 = l2.split(' ').sort((a, b) => a - b).map(item => +item),\n n = l.split(' ')[0],\n cp = l.split(' ')[1],\n min = 0,\n max = 0,\n si = 0,\n li = p.length - 1;\n\nfor (var i = 0; i < n; i++) {\n if (li > 0 && p[li] < p[li - 1]) {\n li--;\n } else if(li + 1 < p.length && p[li] < p[li + 1]) {\n li++\n }\n\n if (p2[si] === 0) {\n si++;\n }\n\n max += p[li]--;\n min += p2[si]--;\n}\n\n//console.log(max + \" \" + min)\nprint(max + \" \" + min);\n\n"}, {"source_code": "var l = readline(),\n l2 = readline(),\n p = l2.split(' ').sort((a, b) => a - b),\n p2 = l2.split(' ').sort((a, b) => a - b)\n n = l.split(' ')[0],\n cp = l.split(' ')[1],\n min = 0,\n max = 0,\n si = 0,\n li = p.length - 1;\n\nfor (var i = 0; i < n; i++) {\n if (li > 0 && p[li] < p[li - 1]) {\n li--;\n } else if(li + 1 < p.length && p[li] < p[li + 1]) {\n li++\n }\n\n if (p2[si] === 0) {\n si++;\n }\n\n max += p[li]--;\n min += p2[si]--;\n}\n\nprint(max + \" \" + min);\n\n"}, {"source_code": "var l = readline(),\n l2 = readline(),\n p = l2.split(' ').sort((a, b) => a - b),\n p2 = l2.split(' ').sort((a, b) => a - b)\n n = l.split(' ')[0],\n cp = l.split(' ')[1],\n min = 0,\n max = 0,\n si = 0,\n li = p.length - 1;\n\nfor (var i = 0; i < n; i++) {\n if (p[li] === 0) {\n li--;\n }\n\n if (p2[si] === 0) {\n si++;\n }\n\n max += p[li]--;\n min += p2[si]--;\n}\n\nprint(max + \" \" + min);\n\n"}, {"source_code": "\"use strict\"\nif (typeof print === 'undefined') var print = console.log;\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id ++];\n}\n\nlet nums = () => readline().split(' ').map(x => +x);\n\nlet t = nums(), n = t[0], m = t[0];\nlet a = nums(), b = [...a];\n\nfunction findmin() {\n let ans = 0;\n for (let i = -1; ++i < n; ) {\n while (b.length && b[0] == 0) b.shift();\n if (!b.length) break;\n ans += b[0]--;\n }\n return ans;\n}\n\nfunction findmax() {\n let ans = 0;\n for (let i = -1; ++i < n; ) {\n let t = 0;\n for (let f = 0; ++f < m; )\n if (a[t] < a[f]) t = f;\n if (a[t] == 0) break;\n ans += a[t]--;\n }\n return ans;\n}\n\nprint(findmax() + ' ' + findmin());\n\n"}, {"source_code": "\"use strict\"\nif (typeof print === 'undefined') var print = console.log;\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id ++];\n}\n\nlet nums = () => readline().split(' ').map(x => +x);\n\nlet t = nums(), n = t[0], m = t[0];\nlet a = nums(), b = [...a];\n\nfunction findmin() {\n let ans = 0;\n b.sort((a, b) => a - b);\n for (let i = -1; ++i < n; ) {\n while (b.length && b[0] == 0) b.shift();\n if (!b.length) break;\n ans += b[0]--;\n }\n return ans;\n}\n\nfunction findmax() {\n let ans = 0;\n for (let i = -1; ++i < n; ) {\n let t = 0;\n for (let f = 0; ++f < m; )\n if (a[t] < a[f]) t = f;\n if (a[t] == 0) break;\n ans += a[t]--;\n }\n return ans;\n}\n\nprint(findmax() + ' ' + findmin());\n\n"}], "src_uid": "6dea4611ca210b34ae2da93ebfa9896c"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, q] = $(2), a = $(n)\n let b = Arr(n, i => ({ d: i + 1 - a[i] }))\n let fen = Array(n + 1).fill(0)\n let fenUp = (i, x) => { for (; i <= n; i += i & -i) fen[i] += x; }\n let fenDown = i => { let res = 0; for (; i; i -= i & -i) res += fen[i]; return res }\n // let c = [];\n let find = (k) => {\n // let l = 1, r = n, m;\n // while (l < r) {\n // m = (l + r) >> 1;\n // if (fenDown(m) < k) l = m + 1;\n // else r = m;\n // }\n // return l\n let sum = 0, pos = 0\n for (let i = 1 << Math.log2(n) | 0; i; i >>= 1) {\n if (pos + i < n && sum + fen[pos + i] < k) {\n sum += fen[pos + i];\n pos += i;\n }\n }\n return pos + 1;\n }\n b.forEach((v, i) => {\n if (v.d == 0) {\n fenUp(i + 1, 1);\n v.p = [i];\n // c.push(i);\n return;\n }\n if (v.d < 0) return;\n let x = fenDown(i + 1);\n if (x < v.d) return;\n // log(Arr(n + 1, i => fenDown(i)).join(' '), '+', x - v.d + 1)\n x = find(x - v.d + 1);\n // log(v, x, b[x - 1])\n fenUp(x, 1);\n b[x - 1].p.push(i);\n })\n\n // log(b)\n fen.fill(0);\n b.forEach(v => v.p ? v.p.forEach(v => fenUp(v + 1, 1)) : 0);\n\n let qe = Arr(q, i => ({ i, l: $(), r: $() })).sort((q1, q2) => q1.l - q2.l)\n let li = 0;\n let remove = l => {\n while (li < l) {\n if (b[li].p) b[li].p.forEach(v => fenUp(v + 1, -1));\n li++\n }\n }\n qe.forEach(q => {\n remove(q.l)\n q.ans = fenDown(n - q.r)\n })\n log(qe.sort((q1, q2) => q1.i - q2.i).map(q => q.ans).join('\\n'))\n}\n", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, q] = $(2), a = $(n)\n let b = Arr(n, i => ({ d: i + 1 - a[i] }))\n let fen = Array(n + 1).fill(0)\n let fenUp = (i, x) => { for (; i <= n; i += i & -i) fen[i] += x; }\n let fenDown = i => { let res = 0; for (; i; i -= i & -i) res += fen[i]; return res }\n // let c = [];\n let find = (k) => {\n let l = 1, r = n, m;\n while (l < r) {\n m = (l + r) >> 1;\n if (fenDown(m) < k) l = m + 1;\n else r = m;\n }\n return l\n }\n b.forEach((v, i) => {\n if (v.d == 0) {\n fenUp(i + 1, 1);\n v.p = [i];\n // c.push(i);\n return;\n }\n if (v.d < 0) return;\n let x = fenDown(i + 1);\n if (x < v.d) return;\n // log(Arr(n + 1, i => fenDown(i)).join(' '), '+', x - v.d + 1)\n x = find(x - v.d + 1);\n // log(v, x, b[x - 1])\n fenUp(x, 1);\n b[x - 1].p.push(i);\n })\n\n // log(b)\n fen.fill(0);\n b.forEach(v => v.p ? v.p.forEach(v => fenUp(v + 1, 1)) : 0);\n\n let qe = Arr(q, i => ({ i, l: $(), r: $() })).sort((q1, q2) => q1.l - q2.l)\n let li = 0;\n let remove = l => {\n while (li < l) {\n if (b[li].p) b[li].p.forEach(v => fenUp(v + 1, -1));\n li++\n }\n }\n qe.forEach(q => {\n remove(q.l)\n q.ans = fenDown(n - q.r)\n })\n log(qe.sort((q1, q2) => q1.i - q2.i).map(q => q.ans).join('\\n'))\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, q] = $(2), a = $(n)\n let b = Arr(n, i => ({ i, d: i + 1 - a[i] }))\n let fen = Array(n + 1).fill(0)\n let fenUp = (i, x) => { for (; i <= n; i += i & -i) fen[i] += x; }\n let fenDown = i => { let res = 0; for (; i; i -= i & -i) res += fen[i]; return res }\n let c = [];\n let find = (k) => {\n let l = 0, r = c.length - 1, m;\n while (l < r) {\n m = (l + r) >> 1;\n if (fenDown(c[m] + 1) < k) l = m + 1;\n else r = m;\n }\n return c[l]\n }\n b.forEach(v => {\n if (v.d == 0) {\n fenUp(v.i + 1, 1);\n v.p = [v.i];\n c.push(v.i);\n return;\n }\n if (v.d < 0) return;\n let x = fenDown(v.i + 1);\n if (x < v.d) return;\n // log(c.map(v => `(${v},${fenDown(v + 1)})`).join(' '))\n x = find(x - v.d + 1);\n // log(v, c, x, b[x])\n fenUp(x + 1, 1);\n b[x].p.push(v.i);\n })\n\n // log(b)\n fen.fill(0);\n b.forEach(v => v.p ? v.p.forEach(v => fenUp(v + 1, 1)) : 0);\n\n let qe = Arr(q, i => ({ i, l: $(), r: $() })).sort((q1, q2) => q1.l - q2.l)\n let li = 0;\n let remove = l => {\n let qu = [], x\n while (li < l) {\n if (b[li].p) b[li].p.forEach(v => fenUp(v + 1, -1));\n li++\n }\n // log(l, qu)\n }\n qe.forEach(q => {\n remove(q.l)\n // log(Arr(1, n, i => `(${i},${fenDown(i) > fenDown(i - 1) ? 1 : 0})`).join(' '))\n q.ans = fenDown(n - q.r)\n })\n log(qe.sort((q1,q2) => q1.i-q2.i).map(q=>q.ans).join('\\n'))\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, q] = $(2), a = $(n)\n let b = Arr(n, i => ({ d: i + 1 - a[i] }))\n let fen = Array(n + 1).fill(0)\n let fenUp = (i, x) => { for (; i <= n; i += i & -i) fen[i] += x; }\n let fenDown = i => { let res = 0; for (; i; i -= i & -i) res += fen[i]; return res }\n let c = [];\n let find = (k) => {\n let l = 0, r = c.length - 1, m;\n while (l < r) {\n m = (l + r) >> 1;\n if (fenDown(c[m] + 1) < k) l = m + 1;\n else r = m;\n }\n return c[l]\n }\n b.forEach((v, i) => {\n if (v.d == 0) {\n fenUp(i + 1, 1);\n v.p = [i];\n c.push(i);\n return;\n }\n if (v.d < 0) return;\n let x = fenDown(i + 1);\n if (x < v.d) return;\n // log(c.map(v => `(${v},${fenDown(v + 1)})`).join(' '))\n x = find(x - v.d + 1);\n // log(v, c, x, b[x])\n fenUp(x + 1, 1);\n b[x].p.push(i);\n })\n\n // log(b)\n fen.fill(0);\n b.forEach(v => v.p ? v.p.forEach(v => fenUp(v + 1, 1)) : 0);\n\n let qe = Arr(q, i => ({ i, l: $(), r: $() })).sort((q1, q2) => q1.l - q2.l)\n let li = 0;\n let remove = l => {\n while (li < l) {\n if (b[li].p) b[li].p.forEach(v => fenUp(v + 1, -1));\n li++\n }\n }\n qe.forEach(q => {\n remove(q.l)\n q.ans = fenDown(n - q.r)\n })\n log(qe.sort((q1, q2) => q1.i - q2.i).map(q => q.ans).join('\\n'))\n}\n"}], "negative_code": [], "src_uid": "27b78f0e344210e038ddba299a483a00"} {"source_code": "var info = readline().split(' ').map(Number);\nvar Arr = readline().split(' ').map(Number);\nvar result = 0;\nvar turn = info[1];\nfor (var i=0; i0) {\n Arr[i] *= -1;\n turn -= 1;\n }\n}\nArr = Arr.sort(function(a, b){return a-b});\nif (turn % 2 == 1) {\n Arr[0] *= -1;\n}\nfor (i=0; i Math.abs(seq[i])){\n minAbsValue = Math.abs(seq[i]);\n };\n };\n\n if(totalSum < (totalSum + seq[i]) ){\n totalSum += seq[i];\n } else if(k > 0){\n totalSum += (seq[i] * -1 );\n k--;\n } else{\n totalSum += seq[i];\n };\n };\n\n if(k > 0){\n totalSum += (2*minAbsValue * -(k%2));\n };\n return totalSum;\n};\n\n"}], "negative_code": [], "src_uid": "befd3b1b4afe19ff619c0b34ed1a4966"} {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar MAX = 1000000;\r\nvar M = Array(MAX);\r\nvar R = Array(MAX);\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];\r\n var a = readline();\r\n M.fill(0, 0, m);\r\n R.fill(0, 0, m);\r\n var sumR = 0;\r\n var ans = [];\r\n var cur = 0;\r\n var pos = 0;\r\n for (var i = 0; i < n; i += 1) {\r\n for (var j = 0; j < m; j += 1) {\r\n if (a[pos] === '1') {\r\n if (!R[j]) {\r\n R[j] = 1;\r\n sumR += 1;\r\n }\r\n cur += 1;\r\n }\r\n cur -= +!!(pos >= m && a[pos - m] === '1');\r\n M[j] += +!!cur;\r\n ans.push(M[j] + sumR);\r\n pos += 1;\r\n }\r\n }\r\n print(ans.join(' '));\r\n}\r\n", "positive_code": [{"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\n/*process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString;\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n*/\r\nvar main = function () {\r\n var t = +readline();\r\n //t = 10;\r\n var MAX = 1000000;\r\n var f = Array(MAX);\r\n var M = Array(MAX);\r\n var R = Array(MAX);\r\n var temp = '';\r\n for (var i = 0; i < MAX; i += 1)\r\n temp += Math.random() < 0.5 ? '1' : '0';\r\n root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];\r\n //let n = 1; let m = 1000;\r\n var a = readline();\r\n //let a = temp;\r\n f[-1] = 0;\r\n f.fill(0, 0, m * n);\r\n M.fill(0, 0, m);\r\n R.fill(0, 0, m);\r\n var sumR = 0;\r\n var ans = '';\r\n var pos = 0;\r\n for (var i = 0; i < n; i += 1) {\r\n for (var j = 0; j < m; j += 1) {\r\n f[pos] = f[pos - 1];\r\n if (a[pos] === '1') {\r\n if (!R[j]) {\r\n R[j] = 1;\r\n sumR += 1;\r\n }\r\n f[pos] += 1;\r\n }\r\n if (a[pos - m] === '1') {\r\n f[pos] -= 1;\r\n }\r\n if (f[pos]) {\r\n M[j] += 1;\r\n }\r\n //ans.push(M[j] + sumR);\r\n ans += \"\".concat(M[j] + sumR, \" \");\r\n pos += 1;\r\n }\r\n }\r\n //console.log(ans);\r\n print(ans);\r\n }\r\n};\r\nmain();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, m, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, str) {\n const ans = Array(str.length)\n //\n const col = Array(m).fill(0)\n let p = 0\n for (let i = 0; i < str.length; i++) {\n ans[i] = i ? ans[i - 1] : 0\n if (!col[p] && str[i] === '1') {\n col[p] = 1\n ans[i]++\n }\n p = (p - 1 + m) % m\n }\n //\n const pre = []\n for (let i = 0; i < str.length; i++) {\n pre[i] = i ? pre[i - 1] : 0\n pre[i] += +str[i]\n }\n// console.log(pre)\n //\n p = 0\n const row = Array(m).fill(0)\n for (let i = 0; i < str.length; i++) {\n row[p] += (pre[i] - (pre[i - m] || 0)) > 0 ? 1 : 0\n ans[i] += row[p]\n p = (p + 1) % m\n }\n return ans.join(' ')\n}\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, m] = ra();\n let s = readline();\n LT({n, m, s});\n // PROCESSING:\n let cols = new Array(Math.max(n, m)).fill(0)\n let rownum = new Array(Math.max(n, m)).fill(0)\n let colnum = 0;\n let nm = n*m;\n let las = -nm;\n let ans = [];\n for (let i=0; i temp.push(...args);\r\n\r\n//const { write } = require(\"fs\");\r\n\r\n//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }\r\n//let s = read('input.txt').split('\\n');\r\n//let readline = ((i) => () => s[i++])(0);\r\nvar t = +readline();\r\nvar MAX = 1000000;\r\nvar f = Array(MAX);\r\nvar M = Array(MAX);\r\nvar R = Array(MAX);\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];\r\n var a = readline();\r\n var count = 0;\r\n for (var i = -1; i < n; i += 1) {\r\n for (var j = -1; j < m; j += 1) {\r\n f[i * m + j] = 0;\r\n }\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n M[i] = 0;\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n R[i] = 0;\r\n }\r\n var sumR = 0;\r\n var ans = [];\r\n for (var i = 0; i < n; i += 1) {\r\n for (var j = 0; j < m; j += 1) {\r\n f[i * m + j] = f[i * m + j - 1];\r\n if (a[i * m + j] === '1') {\r\n if (!R[j]) {\r\n R[j] = 1;\r\n sumR += 1;\r\n }\r\n f[i * m + j] += 1;\r\n }\r\n if (a[(i - 1) * m + j] === '1') {\r\n f[i * m + j] -= 1;\r\n }\r\n if (f[i * m + j]) {\r\n M[j] += 1;\r\n }\r\n //ans.push(M[j] + sumR);\r\n\r\n if (t !== 2)\r\n write(`${M[j] + sumR} `);\r\n }\r\n }\r\n //print(ans.join(' '));\r\n print();\r\n}\r\n"}, {"source_code": "//import { readline, print as print_ } from '@ip-algorithmics/codeforces-io';\r\n//let temp: any[] = [];\r\n//let write = (...args: any[]) => temp.push(...args);\r\n\r\n//const { write } = require(\"fs\");\r\n\r\n//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }\r\n//let s = read('input.txt').split('\\n');\r\n//let readline = ((i) => () => s[i++])(0);\r\nvar t = +readline();\r\nvar MAX = 1000000;\r\nvar f = Array(MAX);\r\nvar M = Array(MAX);\r\nvar R = Array(MAX);\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];\r\n var a = readline();\r\n var count = 0;\r\n for (var i = -1; i < n; i += 1) {\r\n for (var j = -1; j < m; j += 1) {\r\n f[i * m + j] = 0;\r\n }\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n M[i] = 0;\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n R[i] = 0;\r\n }\r\n var sumR = 0;\r\n var ans = [];\r\n for (var i = 0; i < n; i += 1) {\r\n for (var j = 0; j < m; j += 1) {\r\n f[i * m + j] = f[i * m + j - 1];\r\n if (a[i * m + j] === '1') {\r\n if (!R[j]) {\r\n R[j] = 1;\r\n sumR += 1;\r\n }\r\n f[i * m + j] += 1;\r\n }\r\n if (a[(i - 1) * m + j] === '1') {\r\n f[i * m + j] -= 1;\r\n }\r\n if (f[i * m + j]) {\r\n M[j] += 1;\r\n }\r\n //ans.push(M[j] + sumR);\r\n\r\n if (m !== 500000)\r\n write(`${M[j] + sumR} `);\r\n }\r\n }\r\n //print(ans.join(' '));\r\n print();\r\n}\r\n"}, {"source_code": "//import { readline, print as print_ } from '@ip-algorithmics/codeforces-io';\r\n//let temp: any[] = [];\r\n//let write = (...args: any[]) => temp.push(...args);\r\n//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }\r\nvar t = +readline();\r\nvar MAX = 1000000;\r\nvar f = Array(MAX);\r\nvar M = Array(MAX);\r\nvar R = Array(MAX);\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];\r\n var a = readline();\r\n var count = 0;\r\n for (var i = -1; i < n; i += 1) {\r\n for (var j = -1; j < m; j += 1) {\r\n f[i * m + j] = 0;\r\n }\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n M[i] = 0;\r\n }\r\n for (var i = 0; i < m; i += 1) {\r\n R[i] = 0;\r\n }\r\n var sumR = 0;\r\n var ans = [];\r\n for (var i = 0; i < n; i += 1) {\r\n for (var j = 0; j < m; j += 1) {\r\n f[i * m + j] = f[i * m + j - 1];\r\n if (a[i * m + j] === '1') {\r\n if (!R[j]) {\r\n R[j] = 1;\r\n sumR += 1;\r\n }\r\n f[i * m + j] += 1;\r\n }\r\n if (a[(i - 1) * m + j] === '1') {\r\n f[i * m + j] -= 1;\r\n }\r\n if (f[i * m + j]) {\r\n M[j] += 1;\r\n }\r\n //ans.push(M[j] + sumR);\r\n write(M[j] + sumR);\r\n }\r\n }\r\n //print(ans.join(' '));\r\n print();\r\n}\r\n"}], "src_uid": "ca835eeb8f24de8860d6f5ac6c0af55d"} {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(arr))\n }\n});\n\nfunction solve(arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n const r = sum % arr.length\n // const avg = (sum - r) / arr.length\n\n return arr.reduce((s, x, i) => {\n return s + (i < r ? arr.length - r : 0)\n }, 0)\n}\n\nfunction getSum(arr) {\n let sum = 0\n arr.forEach((a, i) => {\n arr.forEach((b, j) => {\n if (j > i) sum += Math.abs(a - b)\n })\n })\n return sum\n}\n\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n; i++) sum += a[i];\r\n\r\n\t\tconst ans = sum%n * (n - sum%n);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsum += list[i];\r\n\t\t}\r\n\t\tvar div = sum % N;\r\n\t\tmyout((N - div) * div);\r\n\t}\r\n}\r\n"}, {"source_code": "function isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction solve() {\r\n const n = BigInt(read());\r\n let sum = 0n;\r\n readArray((x) => {\r\n sum += BigInt(x);\r\n });\r\n const rem = sum % n;\r\n write(rem * (n - rem));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n\r\nfor (var t = 0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var sum = readline().split(\" \").map(Number).reduce((acc, input) => acc + input);\r\n\r\n if (sum === n || sum === 0) {\r\n print(0)\r\n } else {\r\n var abv;\r\n if (sum > n) {\r\n abv = (sum % n)\r\n } else if (sum < n) {\r\n abv = sum;\r\n }\r\n \r\n print((n - abv) * abv);\r\n }\r\n}"}, {"source_code": "var input = readline();\r\nfor(var i = 0; i < input; i ++) {\r\n var num = readline();\r\n var a = readline().split(' ').map(Number);\r\n var sum = a.reduce((x, y) => x + y, 0);\r\n var ans = (num - sum % num) * (sum % num);\r\n print(ans)\r\n}"}], "negative_code": [], "src_uid": "935bceb69117d06eb75121c805bff69c"} {"source_code": "var n, a;\r\n var charSet;\r\n\r\n function cToI(c) {\r\n return c.charCodeAt(0) - 97;\r\n }\r\n\r\n function Node() {\r\n var ch = new Array(26).fill(null);\r\n return {\r\n index: 0,\r\n children: ch,\r\n }\r\n }\r\n\r\n function insert(root, k, index) {\r\n var l = k.length;\r\n var node = root;\r\n for (var i = 0; i < l; i++) {\r\n var c = k.charAt(i);\r\n if (!charSet.has(c)) {\r\n return;\r\n }\r\n if (!node.children[cToI(c)]) {\r\n var newNode = new Node();\r\n node.children[cToI(c)] = newNode;\r\n }\r\n node = node.children[cToI(c)];\r\n }\r\n node.index = index;\r\n }\r\n\r\n function search(root, start) {\r\n var node = root;\r\n var i = start;\r\n var lastEnd = -1;\r\n var lastIndex = 0;\r\n while (i < a.length) {\r\n var c = a.charAt(i);\r\n if (node.children[cToI(c)]) {\r\n node = node.children[cToI(c)];\r\n if (node.index) {\r\n lastEnd = i;\r\n lastIndex = node.index;\r\n }\r\n } else {\r\n break;\r\n }\r\n i++;\r\n }\r\n\r\n return [lastEnd, lastIndex];\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t max) {\r\n max = match[0];\r\n maxIndex = i;\r\n }\r\n }\r\n if (max == totalMax) {\r\n exist = false;\r\n break;\r\n }\r\n ans.push([pf[maxIndex][1], maxIndex+1]);\r\n if (max == a.length-1) {\r\n break;\r\n }\r\n start = end+1;\r\n end = Math.min(max+1, a.length-1);\r\n totalMax = max;\r\n }\r\n if (!exist) {\r\n print(-1);\r\n } else {\r\n print(ans.length);\r\n for (var i = 0; i < ans.length; i++) {\r\n print(ans[i].join(' '));\r\n }\r\n }\r\n }", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const s = lines[l++]\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(s, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str, arr) {\n const m = {}\n for (let j = 0; j < arr.length; j++) {\n const s = arr[j]\n // }\n // for (let s of arr) {\n for (let i = 0; i < s.length; i++) {\n const c = s[i]\n m[c] = m[c] || []\n m[c].push([s.length - 1 - i, j])\n }\n }\n for (let c in m) {\n m[c].sort((a, b) => b[0] - a[0])\n }\n// console.log(m)\n // arr.sort((a, b) => b.length - a.length)\n // for (let s of arr) {\n // const ch = s[0]\n // m[ch] = m[ch] || []\n // m[ch].push(s)\n // }\n let k = 0\n const ans = []\n for (let i = 0; i < str.length;) {\n const ch = str[i]\n if (!m[ch]) return -1\n let found = 0\n for (let [add, w] of m[ch]) {\n const s = arr[w]\n const j = i + add\n const start = j + 1 - s.length\n // console.log(start, j)\n if (start < 0 || j >= str.length) continue\n // console.log(str.slice(j + 1 - s.length, j + 1), s)\n if (str.slice(j + 1 - s.length, j + 1) === s) {\n found = 1\n k++\n i = j + 1\n ans.push(w + 1 + ' ' + (start + 1))\n break\n }\n }\n if (!found) return -1\n }\n return k + '\\n' + ans.join('\\n')\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a, s) {\r\n const m = s.length;\r\n const g = Array.from({\r\n length: m\r\n }, () => new Array(n).fill(0));\r\n for (let i = m - 1; i >= 0; i--) {\r\n next: for (let j = 0; j < n; j++) {\r\n for (let k = 0; k < a[j].length; k++) {\r\n if (a[j][a[j].length - k - 1] !== s[i - k]) continue next;\r\n }\r\n g[i][j] = 1;\r\n }\r\n }\r\n const dp = new Array(m).fill(Infinity),\r\n p = [],\r\n p1 = [];\r\n for (let i = 0; i < m; i++) {\r\n let t = -1;\r\n for (let j = 0; j < n; j++) {\r\n if (g[i][j]) {\r\n if (t === -1 || a[t].length < a[j].length) t = j;\r\n }\r\n }\r\n p[i] = t;\r\n if (t !== -1) {\r\n for (let j = i - a[t].length; j < i; j++) {\r\n var _dp$j;\r\n if (dp[i] > ((_dp$j = dp[j]) !== null && _dp$j !== void 0 ? _dp$j : 0) + 1) {\r\n var _dp$j2;\r\n dp[i] = ((_dp$j2 = dp[j]) !== null && _dp$j2 !== void 0 ? _dp$j2 : 0) + 1;\r\n p1[i] = j;\r\n }\r\n }\r\n }\r\n }\r\n if (dp[m - 1] === Infinity) return -1;\r\n let res = [];\r\n for (let i = m - 1; i >= 0; i = p1[i]) {\r\n res.push(p[i] + 1 + ' ' + (i - a[p[i]].length + 2));\r\n }\r\n return `${dp[m - 1]}\\n${res.join('\\n')}`;\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await r();\r\n const n = await rn();\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await r());\r\n }\r\n res[i] = solve(n, a, s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "var n, a;\r\n var charSet;\r\n\r\n function cToI(c) {\r\n return c.charCodeAt(0) - 97;\r\n }\r\n\r\n function Node() {\r\n var ch = new Array(26).fill(null);\r\n return {\r\n index: 0,\r\n children: ch,\r\n }\r\n }\r\n\r\n function insert(root, k, index) {\r\n var l = k.length;\r\n var node = root;\r\n for (var i = 0; i < l; i++) {\r\n var c = k.charAt(i);\r\n if (!charSet.has(c)) {\r\n return;\r\n }\r\n if (!node.children[cToI(c)]) {\r\n var newNode = new Node();\r\n node.children[cToI(c)] = newNode;\r\n }\r\n node = node.children[cToI(c)];\r\n }\r\n node.index = index;\r\n }\r\n\r\n function search(root, start) {\r\n var node = root;\r\n var i = start;\r\n var lastEnd = -1;\r\n var lastIndex = 0;\r\n while (i < a.length) {\r\n var c = a.charAt(i);\r\n if (node.children[cToI(c)]) {\r\n node = node.children[cToI(c)];\r\n if (node.index) {\r\n lastEnd = i;\r\n lastIndex = node.index;\r\n }\r\n } else {\r\n break;\r\n }\r\n i++;\r\n }\r\n\r\n return [lastEnd, lastIndex];\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t max) {\r\n max = match[0];\r\n maxIndex = i;\r\n }\r\n }\r\n if (max == -1) {\r\n exist = false;\r\n break;\r\n }\r\n ans.push([pf[maxIndex][1], maxIndex+1]);\r\n if (max == a.length-1) {\r\n break;\r\n }\r\n start = end+1;\r\n end = Math.min(max+1, a.length-1);\r\n }\r\n if (!exist) {\r\n print(-1);\r\n } else {\r\n print(ans.length);\r\n for (var i = 0; i < ans.length; i++) {\r\n print(ans[i].join(' '));\r\n }\r\n }\r\n }"}], "src_uid": "c08933fdaceb220f4ef3ba8c5f09fe12"} {"source_code": "var s=readline().split('')\nres=0\nvar alph=\"abcdefghijklmnopqrstuvwxyz\"\nfor (var i=0;i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const str = readLine();\n let [map, count1] = [{}, 0];\n\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n map[char] = (map[char] || 0) + 1;\n }\n\n for (let key in map) {\n if (map[key] % 2 === 1) count1++;\n }\n\n if (count1 === 0) console.log(\"First\");\n else if (count1 % 2 === 0) console.log(\"Second\");\n else console.log(\"First\");\n}\n"}, {"source_code": ";(function () {\n\t\n\tprint((function (s) {\n\n\t\tvar m = {};\n\t\tfor (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;\n\t\tm = (function () {\n\t\t\tvar ret = [0, 0];\n\t\t\tfor (var key in m) ret[m[key]%2]++;\n\t\t\treturn ret[1] === 0 ? 1 : ret[1];\n\t\t})()\n\n\t\treturn m % 2 ? 'First' : 'Second';\n\t})(readline()));\n\n}).call(this);"}], "negative_code": [{"source_code": ";(function () {\n\t\n\tprint((function (s) {\n\n\t\tvar m = {};\n\t\tfor (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;\n\t\tm = (function () {\n\t\t\tvar ret = [0, 0];\n\t\t\tfor (var key in m) ret[m[key]%2]++;\n\t\t\treturn ret[0] + ret[1];\n\t\t})()\n\n\t\treturn m % 2 ? 'Second' : 'First';\n\t})(readline()));\n\n}).call(this);"}], "src_uid": "bbf2dbdea6dd3aa45250ab5a86833558"} {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let length = parseInt(readline());\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n let points = 0;\r\n arr.sort((a, b) => a - b);\r\n\r\n for(let j = 0; j < length; j++) {\r\n if(j % 2 === 0 && arr[length - j - 1] % 2 === 0){\r\n points += arr[length - j - 1];\r\n } else if (j % 2 === 1 && arr[length - j - 1] % 2 === 1) {\r\n points -= arr[length - j - 1];\r\n }\r\n }\r\n\r\n if(points > 0){\r\n print(\"Alice\");\r\n } else if(points === 0){\r\n print(\"Tie\");\r\n } else {\r\n print(\"Bob\");\r\n }\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var answer = []\r\n var xx = 0\r\n var array = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n return xx\r\n });\r\n var sorted = array.sort((a, b) => a - b)\r\n // console.log(sorted)\r\n // console.log(array)\r\n var ii = n - 1\r\n var i = 0\r\n var sumA = 0\r\n var sumB = 0\r\n var smod2 = 0\r\n var i2 = 0\r\n while (ii >= 0) {\r\n smod2 = sorted[ii] % 2\r\n i2 = i % 2\r\n if (smod2 === 0 && i2 === 0) sumA += sorted[ii]\r\n if (smod2 % 2 === 1 && i2 === 1) sumB += sorted[ii]\r\n ii--\r\n i++\r\n }\r\n\r\n if (sumA > sumB) return console.log('Alice')\r\n if (sumA < sumB) return console.log('Bob')\r\n console.log('Tie')\r\n })\r\n\r\n}\r\n\r\nfunction swap(items, leftIndex, rightIndex) {\r\n var temp = items[leftIndex];\r\n items[leftIndex] = items[rightIndex];\r\n items[rightIndex] = temp;\r\n}\r\n\r\nfunction partition(items, left, right) {\r\n var pivot = items[Math.floor((right + left) / 2)], //middle element\r\n i = left, //left pointer\r\n j = right; //right pointer\r\n while (i <= j) {\r\n while (items[i] < pivot) {\r\n i++;\r\n }\r\n while (items[j] > pivot) {\r\n j--;\r\n }\r\n if (i <= j) {\r\n swap(items, i, j); //sawpping two elements\r\n i++;\r\n j--;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nfunction quickSort(items, left, right) {\r\n var index;\r\n if (items.length > 1) {\r\n index = partition(items, left, right); //index returned from partition\r\n if (left < index - 1) { //more elements on the left side of the pivot\r\n quickSort(items, left, index - 1);\r\n }\r\n if (index < right) { //more elements on the right side of the pivot\r\n quickSort(items, index, right);\r\n }\r\n }\r\n return items;\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n let a = 0,\r\n b = 0,\r\n k = 1;\r\n for (let i = 0; i < n; i++, k = !k) {\r\n if (k) a += arr[i] % 2 === 0 ? arr[i] : 0;\r\n else b += arr[i] % 2 === 1 ? arr[i] : 0;\r\n }\r\n if (a === b) console.log(\"Tie\");\r\n else if (a > b) console.log(\"Alice\");\r\n else console.log(\"Bob\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (n, a) => {\n a = a.sort((a, b) => b - a)\n let mb = 0\n let ma = 0\n\n a.forEach((val, index) => {\n if (index % 2 === 0) {\n ma += val % 2 === 0 ? val : 0\n } else {\n mb += val % 2 === 0 ? 0 : val\n }\n })\n\n if (ma < mb) {\n return 'Bob'\n } else if (ma > mb) {\n return 'Alice'\n } else {\n return 'Tie'\n }\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet n, a\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 2\n if (mode === 0) {\n n = Number(line)\n } else if (mode === 1) {\n a = line.split(' ').map(val => Number(val))\n answer.push(calculate(n, a))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n\n// chainNumberList, cList, aList, bList\n// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))\n"}, {"source_code": "let i = ''\r\nconst { EOL } = require('os')\r\nprocess.stdin.on('data', c => (i += c))\r\nprocess.stdin.on('end', () => {\r\n const lines = i.split(EOL).filter(line => line)\r\n console.log(processInput(lines))\r\n})\r\n\r\nconst processInput = lines => {\r\n return lines\r\n .slice(1)\r\n .filter((_, i) => i % 2)\r\n .map(line => line.split(' ').map(n => +n))\r\n .map(nums => {\r\n const sortedNums = nums.sort((a, b) => b - a)\r\n const alice = sortedNums\r\n .filter((num, i) => !(i % 2) && num % 2 === 0)\r\n .reduce((a, b) => a + b, 0)\r\n const bob = sortedNums\r\n .filter((num, i) => i % 2 && num % 2 === 1)\r\n .reduce((a, b) => a + b, 0)\r\n if (alice > bob) return 'Alice'\r\n else if (bob > alice) return 'Bob'\r\n else return 'Tie'\r\n })\r\n .join(EOL)\r\n}\r\n"}, {"source_code": "const game = a => {\n a.sort((i, j) => j - i);\n let res = 0;\n for (let i = 0; i < a.length; i++) {\n if (a[i] % 2 == 0 && i % 2 == 0) res += a[i];\n else if (a[i] % 2 == 1 && i % 2 == 1) res -= a[i];\n }\n return res;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n readline();\n const a = readline()\n .split(\" \")\n .map(s => parseInt(s));\n const res = game(a);\n if (res == 0) console.log(\"Tie\");\n else if (res > 0) console.log(\"Alice\");\n else console.log(\"Bob\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let n = readline();\r\n let arr = readline().split(' ').map(x => +x);\r\n\r\n arr = arr.sort((a, b) => {\r\n return b - a;\r\n });\r\n\r\n let aliceSum = 0;\r\n let bobSum = 0;\r\n\r\n for (let i = 0; i <= n; i+=2) {\r\n if (arr[i] % 2 === 0) {\r\n aliceSum += arr[i];\r\n }\r\n if (arr[i+1] && arr[i+1] % 2 !== 0) {\r\n bobSum += arr[i+1];\r\n }\r\n }\r\n\r\n if (aliceSum === bobSum) {\r\n console.log('Tie');\r\n } else if (aliceSum > bobSum) {\r\n console.log('Alice');\r\n } else {\r\n console.log('Bob');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n\nfunction create2DArray(rows) {\n var arr = [];\n\n for (var i = 0; i < rows; i++) {\n arr[i] = [];\n }\n\n return arr;\n}\n// ---------------------------------------\n\nfunction main() {\n let t = getInt(readline());\n while (t--) {\n let len = getInt(readline());\n let arr = getArray(readline());\n arr = arr.sort((a, b) => b-a);\n let score1 = 0;\n let score2 = 0;\n for(let i=0; i score2) {\n console.log('Alice');\n } else if (score1 < score2) {\n console.log('Bob');\n } else {\n console.log('Tie');\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar sum = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(j % 2 == 0){\r\n\t\t\t\tif(list[j] % 2 == 0){\r\n\t\t\t\t\tsum += list[j];\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(list[j] % 2 == 1){\r\n\t\t\t\t\tsum -= list[j];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(sum > 0){\r\n\t\t\tmyout(\"Alice\");\r\n\t\t}else if(sum < 0){\r\n\t\t\tmyout(\"Bob\");\r\n\t\t}else{\r\n\t\t\tmyout(\"Tie\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst [evens, odds] = [[], []];\n\t\tconst arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map((n) => {\n\t\t\t\tn = Number(n);\n\t\t\t\tif (n % 2 === 0) evens.push(n);\n\t\t\t\telse odds.push(n);\n\t\t\t\treturn n;\n\t\t\t});\n\t\tevens.sort((a, b) => a - b);\n\t\todds.sort((a, b) => a - b);\n\t\tlet [counta, countb] = [0, 0];\n\n\t\tlet i = 1;\n\t\twhile (evens.length || odds.length) {\n\t\t\tconst [evenTop, oddTop] = [evens[evens.length - 1] || 0, odds[odds.length - 1] || 0];\n\t\t\tconst max = Math.max(evenTop, oddTop);\n\t\t\tif (i % 2 !== 0) {\n\t\t\t\t// alice\n\t\t\t\tif (max === evenTop) {\n\t\t\t\t\tcounta += evenTop;\n\t\t\t\t\tevens.pop();\n\t\t\t\t} else odds.pop();\n\t\t\t} else {\n\t\t\t\t// bob\n\t\t\t\tif (max === oddTop) {\n\t\t\t\t\tcountb += oddTop;\n\t\t\t\t\todds.pop();\n\t\t\t\t} else evens.pop();\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tif (counta > countb) console.log('Alice');\n\t\telse if (counta < countb) console.log('Bob');\n\t\telse console.log('Tie');\n\t}\n}\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 2; i += 2) {\r\n const n = parseInt(lines[i]);\r\n const arr = lines[i + 1].split(' ').map(num => parseInt(num));\r\n\r\n console.log(solve(n, arr));\r\n }\r\n});\r\n\r\nfunction solve(n, arr) {\r\n arr.sort((a, b) => b - a);\r\n\r\n let alice = 0;\r\n let bob = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] % 2 === 0 && i % 2 === 0) {\r\n alice += arr[i];\r\n } else if (arr[i] % 2 === 1 && i % 2 === 1) {\r\n bob += arr[i];\r\n }\r\n }\r\n\r\n if (alice > bob) {\r\n return 'Alice';\r\n } else if (bob > alice) {\r\n return 'Bob';\r\n } else {\r\n return 'Tie';\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .filter((_, i) => i % 2)\n .map((line) => line.split(' ').map((n) => +n))\n .map((nums) => {\n const sortedNums = nums.sort((a, b) => b - a);\n let alice = 0,\n bob = 0;\n for (let i = 0; i < sortedNums.length; i++) {\n if (i % 2 === 0) {\n if (sortedNums[i] % 2 === 0) {\n alice += sortedNums[i];\n }\n } else {\n if (sortedNums[i] % 2 === 1) {\n bob += sortedNums[i];\n }\n }\n }\n return alice > bob ? 'Alice' : alice < bob ? 'Bob' : 'Tie';\n })\n .join('\\n');\n};\n"}], "negative_code": [], "src_uid": "b1e911fbc33fb031b2398cdd545f502a"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [x, y] = readLine().split(\" \").map(Number);\n let diff = Math.abs(x - y);\n if (diff > 0) diff = diff - 1;\n console.log(x + y + diff);\n }\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar x = one[0];\n\t\tvar y = one[1];\n\t\tvar count = 0;\n\t\tif(x > 0 && y > 0){\n\t\t\tcount = Math.min(x, y) * 2;\n\t\t\tx -= count / 2;\n\t\t\ty -= count / 2;\n\t\t}\n\t\t\n\t\t\n\t\tif(x > 0){\n\t\t\tcount += x * 2 - 1;\n\t\t}else if(y > 0){\n\t\t\tcount += y * 2 - 1;\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [x, y] = readLine().split(\" \").map(Number);\n let diff = Math.abs(x - y);\n if (diff > 0) diff = diff - 1;\n console.log(x + y + diff);\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r0&&(r+=2*n-1),i.default.puts(r)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [x, y] = io.nextNumbers()\n// \n// let cnt = [x, y].min() * 2\n// \n// let d = [x, y].max() - [x, y].min()\n// \n// if (d > 0) {\n// cnt += d * 2 - 1\n// }\n// \n// io.puts(cnt)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "/*\n * File Created: Sunday, 29th November 2020 9:28:45 pm\n * Author: Lukas Rimkus (lukasrimkuslg@gmail.com)\n */\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\n data += chunk;\n});\n\nprocess.stdin.on('end', _ => {\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const [n, m ] = get_ints();\n\n const res = robot(n,m);\n\n console.log(res);\n }\n });\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n\nfunction readLine() { \n return data[currentLine++];\n}\nfunction robot(x ,y)\n{\n //i - 2 j - 2\n return 2*(x > y ? x : y) - (x != y);\n}\n\nmodule.exports = robot "}, {"source_code": "///https://codeforces.com/problemset/problem/1452/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction main(fileContents) {//input lines as an array\n const amoutOfInputsForTheProgram = fileContents.splice(0,1);\n const listOfEndpointsForRobot = [...fileContents];\n\n listOfEndpointsForRobot\n .map((endpoints)=>endpoints.split(\" \"))\n .map((endpoints)=>{\n const diffBetweetVertAndHorizontal = Math.abs(parseInt(endpoints[0])-parseInt(endpoints[1]));\n return parseInt(endpoints[0])+parseInt(endpoints[1])\n +(diffBetweetVertAndHorizontal > 0 ? (diffBetweetVertAndHorizontal-1) : 0)\n })\n .forEach(x=>console.log(x));\n\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x,y] = ti(readline().split(' '));\n \n let min = Math.min(x,y);\n let max = Math.max(x,y);\n if(max === min){\n console.log(max+min);\n }else{\n console.log(2*min+(1+(max-min-1)*2));\n }\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n Array(Number(x)).fill(1).map((t, i)=>{\n var line2 = readline().split( ' ').map(x=>Number(x));\n // console.log(typeof line2)\n // line2 = line2.map(x=>Number(x))\n if(Math.max(line2[0],line2[1]) === 0) return console.log(0)\n if(line2[0] === line2[1]) return console.log(line2[1]*2)\n console.log(Math.max(line2[0],line2[1])*2-1)\n // answer[i] = Math.max(line2[0],line2[1])*2-1\n })\n}\nfunction foo(x) {\n // process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n\n console.log(x); // with auto '\\n' (newline)\n}\n"}, {"source_code": "\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)\n\t\tx = X + Y + (d>1 ? (d-1) : 0)\n\t\tconsole.log(x)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var ar = readline().split(' ').map(x => +x);\n var a = ar[0], b = ar[1];\n var mn = Math.min(a, b);\n var mx = Math.max(a, b);\n\n print(mn * 2 + (mx - mn) * 2 - (mx - mn > 0 ? 1 : 0));\n}\n"}], "negative_code": [{"source_code": "\n\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)\n\t\tx = X + Y + (d>1 ? (d-1) : 0)\n\t\tconsole.log(`Case #${i+1}: `+x)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n Array(Number(x)).fill(1).map((t, i)=>{\n var line2 = readline();\n if(Math.max(line2[0],line2[1]) == 0) return console.log(0)\n console.log(Math.max(line2[0],line2[1])*2-1)\n // answer[i] = Math.max(line2[0],line2[1])*2-1\n })\n}\nfunction foo(x) {\n // process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n\n console.log(x); // with auto '\\n' (newline)\n}\n"}], "src_uid": "8864c6a04fed970fcbc04e220df9d88d"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n let ans = 0;\n let L = 0;\n let R = arr.length - 1;\n\n while (L < R) {\n ans += (arr[L] + arr[R]) ** 2;\n L++;\n R--;\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "\"use strict\";\nfunction main(input) {\n const inputs = input.split(\"\\n\").filter(x => x !== \"\");\n\n const N = Number(inputs[0]);\n const A = inputs[1].split(\" \").map(Number);\n\n const sortedA = A.sort((a,b) => a-b);\n const B = [];\n if (sortedA.length % 2 === 1) {\n for (let i=1;i<= (sortedA.length-1)/2; i++) {\n B[i-1] = sortedA[i] + sortedA[N-i];\n }\n } else {\n for (let i=0; i <= (sortedA.length-1)/2; i++) {\n B[i] = sortedA[i] + sortedA[N-i-1];\n }\n }\n\n const sortedB = B.sort((a,b) => a-b);\n\n if (sortedA.length % 2 === 1) {\n B[0] += sortedA[0];\n }\n\n let result = B.reduce((acc, cur) => acc + cur * cur, 0);\n console.log(result);\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n main(i)\n})"}, {"source_code": "\"use strict\";\nfunction I(s,f){this._s=s.split(\"\\n\");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(\" \");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(\" \").map(this._f)};\n\nfunction main(input) {\n var o = new I(input);\n\n const N = o.a();\n const A = o.l();\n\n const sortedA = A.sort((a,b) => a-b);\n const B = [];\n if (sortedA.length % 2 === 1) {\n for (let i=1;i<= (sortedA.length-1)/2; i++) {\n B[i-1] = sortedA[i] + sortedA[N-i];\n }\n } else {\n for (let i=0; i <= (sortedA.length-1)/2; i++) {\n B[i] = sortedA[i] + sortedA[N-i-1];\n }\n }\n\n const sortedB = B.sort((a,b) => a-b);\n\n if (sortedA.length % 2 === 1) {\n B[0] += sortedA[0];\n }\n\n let result = B.reduce((acc, cur) => acc + cur * cur, 0);\n console.log(result);\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n main(i)\n})"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort();\n\n let ans = 0;\n let L = 0;\n let R = arr.length - 1;\n\n while (L < R) {\n ans += (arr[L] + arr[R]) ** 2;\n L++;\n R--;\n }\n\n console.log(ans);\n\n c++;\n});\n"}], "src_uid": "28c555fefd5c36697a5082c61d8a82b3"} {"source_code": "\n var input = readline().split(' ');\nvar n = +input[0];\nvar k = +input[1];\nvar a = readline().split(' ');\n\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n a[i] = +a[i];\n}\nfor (var i = 0; i < k; i++) {\n ans += a[i];\n}\n\nvar val = ans;\nfor (var i = k; i < n; i++) {\n val += a[i];\n val -= a[i - k];\n ans += val;\n}\n\nprint(ans / (n - k + 1));", "positive_code": [{"source_code": "var input = readline().split(' ');\nvar n = +input[0];\nvar k = +input[1];\nvar a = readline().split(' ');\n\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n a[i] = +a[i];\n}\nfor (var i = 0; i < k; i++) {\n ans += a[i];\n}\n\nvar val = ans;\nfor (var i = k; i < n; i++) {\n val += a[i];\n val -= a[i - k];\n ans += val;\n}\n\nprint(ans / (n - k + 1));"}], "negative_code": [], "src_uid": "838e643a978adbeed791a24ac1046ab5"} {"source_code": "let stdin = ''\n\nprocess.stdin.on('data', data => {\n stdin += data\n})\n\nprocess.stdin.on('end', () => {\n stdin = stdin.trim().split('\\n').map(string => string.trim())\n main()\n})\n\nlet currentLine = 0\nfunction input() {\n return stdin[currentLine++]\n}\n\nfunction main() {\n const n = parseInt(input())\n\n const a = input()\n .split(' ')\n .map(s => parseInt(s))\n .sort((a, b) => a - b)\n \n const dp = new Array(n).fill(-1).map(_ => new Array(n).fill(-1))\n\n for (let i = 0; i < n; i++) {\n dp[i][i] = 0\n }\n\n for (let d = 1; d < n; d++) {\n for (let l = 0; l < n - d; l++) {\n const r = l + d\n dp[l][r] = a[r] - a[l] + Math.min(dp[l+1][r], dp[l][r-1])\n }\n }\n \n console.log(dp[0][n-1])\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar a\r\nvar dp\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n a.sort((a, b) => a - b)\r\n\r\n dp = new Array(n + 1)\r\n for (let i = 0; i < n + 1; i++) {\r\n dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)\r\n }\r\n console.log(solve(0, n - 1, a))\r\n // })\r\n}\r\n\r\nfunction solve(l, r) {\r\n if (l === r) return 0\r\n\r\n if(dp[l][r] !== Number.MAX_SAFE_INTEGER) return dp[l][r]\r\n var ans = Math.min(solve(l + 1, r), solve(l, r - 1))\r\n if(dp[l][r] === Number.MAX_SAFE_INTEGER) dp[l][r] = ans + a[r] - a[l]\r\n return ans + a[r] - a[l]\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst mxN = 2010;\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst s = rna();\r\n\r\n\ts.sort((x, y) => x - y);\r\n\r\n\tconst dp = Array.from(Array(mxN), x => Array(mxN).fill(0));\r\n\r\n\tfor (let k = 2; k <= n; k++) {\r\n\t\tfor (let i = n-k; i >= 0; i--) {\r\n\t\t\tdp[i][k] = Math.min(dp[i][k-1], dp[i+1][k-1]) + s[i+k-1] - s[i];\r\n\t\t}\r\n\t}\r\n\r\n\tconst ans = dp[0][n];\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n a.sort((a, b) => a - b)\r\n\r\n var dp = new Array(n + 1)\r\n for (let i = 0; i < n + 1; i++) {\r\n dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)\r\n dp[i][i] = 0\r\n }\r\n\r\n for (let k = 0; k < 2; k++) {\r\n for (let i = 0; i < n-1; i++) {\r\n for (let j = 1; j < n; j++) {\r\n // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))\r\n dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))\r\n }\r\n }\r\n }\r\n console.log(dp[0][n-1])\r\n // })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n a.sort((a, b) => a - b)\r\n\r\n var dp = new Array(n + 1)\r\n for (let i = 0; i < n + 1; i++) {\r\n dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)\r\n dp[i][i] = 0\r\n }\r\n\r\n // for (let k = 0; k < n; k++) {\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i; j < n; j++) {\r\n // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))\r\n if (i < n - 1 && j > 0)\r\n dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))\r\n }\r\n }\r\n // }\r\n console.log(dp[0][n-1])\r\n // })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n a.sort((a, b) => a - b)\r\n var l = 0\r\n var r = n - 1\r\n var sum = a[r] - a[l]\r\n\r\n while (l !== r) {\r\n if (a[r] - a[l + 1] > a[r - 1] - a[l]) {\r\n r--\r\n } else l++\r\n sum += a[r] - a[l]\r\n // console.log(sum, l, r)\r\n }\r\n console.log(sum)\r\n // })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n var sum = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += a[i]\r\n }\r\n var medd = sum / n\r\n var med\r\n var res = Number.MAX_SAFE_INTEGER\r\n for (let i = 0; i <= n; i++) {\r\n med = aa[i]\r\n if (i === n) med = medd\r\n\r\n a = a.sort((a, b) => {\r\n var a1 = a - med > 0 ? a - med : med - a\r\n var b1 = b - med > 0 ? b - med : med - b\r\n return a1 > b1 ? 1 : -1\r\n })\r\n\r\n var min = a[0]\r\n var max = a[0]\r\n sum = 0\r\n\r\n for (let j = 0; j < n; j++) {\r\n min = Math.min(min, a[j])\r\n max = Math.max(max, a[j])\r\n sum += max - min\r\n }\r\n // console.log(sum)\r\n // console.log(a)\r\n res = Math.min(res, sum)\r\n }\r\n\r\n for (let i = 1; i < n; i++) {\r\n med = (aa[i] - aa[i-1]) / 2\r\n a = a.sort((a, b) => {\r\n var a1 = a - med > 0 ? a - med : med - a\r\n var b1 = b - med > 0 ? b - med : med - b\r\n return a1 > b1 ? 1 : -1\r\n })\r\n\r\n var min = a[0]\r\n var max = a[0]\r\n sum = 0\r\n\r\n for (let j = 0; j < n; j++) {\r\n min = Math.min(min, a[j])\r\n max = Math.max(max, a[j])\r\n sum += max - min\r\n }\r\n // console.log(sum)\r\n // console.log(a)\r\n res = Math.min(res, sum)\r\n }\r\n\r\n console.log(res)\r\n // })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var aa = a.slice()\r\n var sum = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += a[i]\r\n }\r\n var medd = sum / n\r\n var med\r\n var res = Number.MAX_SAFE_INTEGER\r\n for (let i = 0; i <= n; i++) {\r\n med = aa[i]\r\n if (i === n) med = medd\r\n\r\n a = a.sort((a, b) => {\r\n var a1 = a - med > 0 ? a - med : med - a\r\n var b1 = b - med > 0 ? b - med : med - b\r\n return a1 > b1 ? 1 : -1\r\n })\r\n\r\n var min = a[0]\r\n var max = a[0]\r\n sum = 0\r\n\r\n for (let j = 0; j < n; j++) {\r\n min = Math.min(min, a[j])\r\n max = Math.max(max, a[j])\r\n sum += max - min\r\n }\r\n // console.log(sum)\r\n // console.log(a)\r\n res = Math.min(res, sum)\r\n }\r\n\r\n console.log(res)\r\n // })\r\n}\r\n\r\n"}], "src_uid": "96ba63c7fea9bd0a5ddd8ffc886da153"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main(){\n let t = parseInt(readline());\n \n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n \n if(n % 4 === 0){\n let en = '';\n let y = Math.floor(n/4);\n while(y > 0){\n en += '8';\n y -= 1;\n }\n \n let st = '';\n let x = n - en.length;\n while(x > 0){\n st += '9';\n x--;\n }\n \n console.log(st+en);\n continue;\n }else{\n let en = '';\n let y = Math.floor(n/4) + 1;\n while(y > 0){\n en += '8';\n y -= 1;\n }\n \n let st = '';\n let x = n - en.length;\n while(x > 0){\n st += '9';\n x--;\n }\n \n console.log(st+en);\n continue;\n }\n }\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n\t let n = data[i] * 1;\n\t if (n == 1) {\n\t console.log(8);\n\t i += 1;\n\t continue;\n\t }\n\t let r = Math.ceil(n / 4);\n\t let num = '9'.repeat(n - r);\n\t num += '8'.repeat(r);\n\t console.log(num);\n i += 1;\n\t}\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n var start = Date.now();\n Main();\n console.error(\"\\n\");\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction input(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\nfunction puts(s){console.log(s);}\nfunction print(s) {process.stdout.write(s+\"\");}\n\n\nfunction Main(){\n tc = parseInt(input()) \n while(tc--) {\n n = parseInt(input()) \n k = Math.ceil(n/4)\n g = n - k \n arr = []\n for(let i=0;i {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n\t let n = data[i] * 1;\n\t if (n == 1) {\n\t console.log(8);\n\t i += 1;\n\t continue;\n\t }\n\t let r = Math.ceil(n / 4);\n\t let num = '9'.repeat(n - r);\n\t num += '8'.repeat(r);\n\t console.log(num * 1);\n i += 1;\n\t}\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n\n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n\n if(n % 4 === 0){\n let res = '';\n let x = (4*n) - Math.floor(n/4);\n while(x > 4){\n res += '9';\n x -= 4;\n }\n\n let y = n/4;\n while(y > 0){\n res += '8';\n y -= 1;\n }\n\n console.log(parseInt(res));\n continue;\n }else{\n let res = '';\n let x = (4*n) - Math.floor(n/4);\n while(x > 4){\n res += '9';\n x -= 4;\n }\n\n let y = Math.floor(n/4) + 1;\n while(y > 0){\n res += '8';\n y -= 1;\n }\n\n console.log(parseInt(res));\n continue;\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n\n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n\n if(n % 4 === 0){\n let en = '';\n let y = Math.floor(n/4);\n while(y > 0){\n en += '8';\n y -= 1;\n }\n\n let st = '';\n let x = n - en.length;\n while(x > 0){\n st += '9';\n x--;\n }\n\n console.log(parseInt(st + en));\n continue;\n }else{\n let en = '';\n let y = Math.floor(n/4) + 1;\n while(y > 0){\n en += '8';\n y -= 1;\n }\n\n let st = '';\n let x = n - en.length;\n while(x > 0){\n st += '9';\n x--;\n }\n\n console.log(parseInt(st + en));\n continue;\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n\n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n\n if(n % 4 === 0){\n let res = '';\n let x = (4*n) - Math.floor(n/4);\n while(x > 4){\n res += '9';\n x -= 4;\n }\n\n let y = n/4;\n while(y > 0){\n res += '8';\n y -= 1;\n }\n\n console.log(parseInt(res));\n continue;\n }else{\n let res = '';\n let x = 4 * (n-1);\n while(x > 4){\n res += '9';\n x -= 4;\n }\n\n let y = Math.floor(n/4) + 1;\n while(y > 0){\n res += '8';\n y -= 1;\n }\n\n console.log(parseInt(res));\n continue;\n }\n }\n}"}], "src_uid": "80c75a4c163c6b63a614075e094ad489"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction powM(base, exponent, mod) {\n if(exponent == 0) return 1\n else if(exponent % 2 == 0) return Math.pow(powM(base, exponent / 2, mod), 2) % mod\n else return (base * powM(base, exponent - 1, mod)) % mod\n}\n\nfunction inverseMod(num, prime) {\n return powM(num, prime - 2, prime)\n}\n\nfunction nCrMod(n, r, p) {\n if(r == 0) return 1\n\n const pascalTriangle = new Array(r + 1).fill(0)\n \n pascalTriangle[0] = 1\n\n for(let i = 1; i <= n; i++) {\n for(let j = Math.min(i, r); j > 0; j--) {\n pascalTriangle[j] = (pascalTriangle[j] + pascalTriangle[j - 1]) % p\n }\n }\n return pascalTriangle[r]\n}\n\n\nfunction main(input) {\n const [n, m] = readInts(input)\n\n const mod = 10 ** 9 + 7\n wr(nCrMod(n + 2 * m - 1, 2 * m, mod))\n}", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m] = readInts(input)\n const m2 = 2 * m\n \n const dp = new Array(m2 + 1)\n const mod = 10 ** 9 + 7\n\n for(let i = 0; i <= m2; i++) {\n dp[i] = new Array(n + 1)\n }\n\n for(let i = 1; i <= m2; i++) {\n dp[i][0] = 0\n }\n\n for(let i = 1; i <= n; i++) {\n dp[1][i] = i\n }\n\n for(let i = 2; i <= m2; i++) {\n for(let j = 1; j <= n; j++) {\n dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod\n }\n }\n\n // wr(dp)\n wr(dp[m2][n])\n\n\n \n}"}, {"source_code": "! function (e) {\n var n = {};\n\n function t(r) {\n if (n[r]) return n[r].exports;\n var o = n[r] = {\n i: r,\n l: !1,\n exports: {}\n };\n return e[r].call(o.exports, o, o.exports, t), o.l = !0, o.exports\n }\n t.m = e, t.c = n, t.d = function (e, n, r) {\n t.o(e, n) || Object.defineProperty(e, n, {\n enumerable: !0,\n get: r\n })\n }, t.r = function (e) {\n \"undefined\" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {\n value: \"Module\"\n }), Object.defineProperty(e, \"__esModule\", {\n value: !0\n })\n }, t.t = function (e, n) {\n if (1 & n && (e = t(e)), 8 & n) return e;\n if (4 & n && \"object\" == typeof e && e && e.__esModule) return e;\n var r = Object.create(null);\n if (t.r(r), Object.defineProperty(r, \"default\", {\n enumerable: !0,\n value: e\n }), 2 & n && \"string\" != typeof e)\n for (var o in e) t.d(r, o, function (n) {\n return e[n]\n }.bind(null, o));\n return r\n }, t.n = function (e) {\n var n = e && e.__esModule ? function () {\n return e.default\n } : function () {\n return e\n };\n return t.d(n, \"a\", n), n\n }, t.o = function (e, n) {\n return Object.prototype.hasOwnProperty.call(e, n)\n }, t.p = \"\", t(t.s = 0)\n}([function (e, n) {\n process.stdin.resume(), process.stdin.setEncoding(\"utf-8\");\n var t = \"\";\n process.stdin.on(\"data\", e => {\n t += e\n }), process.stdin.on(\"end\", () => {\n t = t.split(\"\\n\").map(e => e.replace(/(\\r\\n|\\n|\\r)/gm, \"\")),\n function (e) {\n const [n, r] = void 0 === o ? t.shift().split(\" \").map(e => parseInt(e)) : t[o].split(\" \").map(e => parseInt(e));\n var o;\n ! function (...e) {\n console.log(...e)\n }(function (e, n, t) {\n if (0 == n) return 1;\n const r = new Array(n + 1).fill(0);\n r[0] = 1;\n for (let o = 1; o <= e; o++)\n for (let e = Math.min(o, n); e > 0; e--) r[e] = (r[e] + r[e - 1]) % t;\n return r[n]\n }(n + 2 * r - 1, 2 * r, 1e9 + 7))\n }()\n })\n}]);"}], "negative_code": [], "src_uid": "82293f824c5afbf9dbbb47eac421af33"} {"source_code": "let r='';\nprocess.stdin.on('data',(d)=>{\n r+=d;\n}).on('end',()=>{\n r=r.replace(/\\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);\n nt=r.pop();\n for(let i=0;i0){\n dx=b[j]-a[j];\n break;\n }\n if(b[j]-a[j]<0){\n l=0;ans='NO';\n break;\n }\n }\n for(;j +x);\n\tvar listTwo = readline().split(' ').map(x => +x);\n\n\tvar pl = null, l = null, r = null, k = null;\n\tvar eq = false, gt = false;\n\tvar gotAns = false;\n\tfor(var i = 0; i < listOne.length; i ++){\n\t\tvar list1el = listOne[i];\n\t\tvar list2el = listTwo[i];\n\t\tif(list2el > list1el && (!eq || !gt)){\n\t\t\tgt = true;\n\t\t\teq = false;\n\t\t\t// possible so far\n\t\t\tl = list2el - list1el;\n\t\t\tif(null != pl && pl!=l){\n\t\t\t\tprint('NO');\n\t\t\t\tgotAns = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpl = l;\n\t\t}else if(list2el == list1el){\n\t\t\teq = true;\n\t\t\tcontinue;\n\t\t}else{\n\t\t\tprint('NO');\n\t\t\tgotAns = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(!gotAns){\n\t\tprint('YES');\n\t}\n\n}"}, {"source_code": "var t = Number(readline());\nfor(var i=0;i Number(l) );\n var b = readline().split(\" \").map( l => Number(l) );\n var j=0;\n for(;j parseInt(x);\n\nfor(var t=0; t (_b - a[i]));\n// print('c', c);\n var scount = 0;\n var allpositive = true;//c.filter(x=>(x<0)).length === 0;\n for(var i=0; i 0);\n i = e-1;\n }\n }\n print((scount <= 1 && allpositive) ? \"YES\":\"NO\");\n}\n"}], "negative_code": [{"source_code": "let r='';\nprocess.stdin.on('data',(d)=>{\n r+=d;\n}).on('end',()=>{\n r=r.split(' ').map(a=>Number(a)).reverse();\n nt=r.pop();\n for(let i=0;i{\n r+=d;\n}).on('end',()=>{\n r=r.replace(/\\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);\n nt=r.pop();\n for(let i=0;i=0)console.log(\"YES\");\n else console.log(\"NO\");\n }\n \n});"}, {"source_code": "let r='';\nprocess.stdin.on('data',(d)=>{\n r+=d;\n}).on('end',()=>{\n r=r.replace(/\\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);\n nt=r.pop();\n for(let i=0;i0){\n if(dx==0)dx=b[j]-a[j];\n else {ans='NO';break;}\n }else if(b[j]-a[j]<0){ans='NO';break;}\n }\n }\n console.log(ans);\n }\n \n});"}, {"source_code": "var t = Number(readline());\nfor(var i=0;i Number(l) );\n var b = readline().split(\" \").map( l => Number(l) );\n var j=0;\n for(;j Number(l) );\n var b = readline().split(\" \").map( l => Number(l) );\n var j=0;\n for(;j parseInt(x);\n\nfor(var t=0; t (_b - a[i]));\n// print('c', c);\n var scount = 0;\n var allpositive = c.filter(x=>(x<0)).length === 0;\n for(var i=0; i parseInt(x);\n\nfor(var t=0; t (_b - a[i]));\n// print('c', c);\n var scount = 0;\n var allpositive = true;//c.filter(x=>(x<0)).length === 0;\n for(var i=0; i 0);\n i = e;\n }\n }\n print((scount <= 1 && allpositive) ? \"YES\":\"NO\");\n}\n"}, {"source_code": "var tc = parseInt(readline());\nvar toInt = x => parseInt(x);\n\nfor(var t=0; t (_b - a[i]));\n// print('c', c);\n var scount = 0;\n var allpositive = true;//c.filter(x=>(x<0)).length === 0;\n for(var i=0; i 0);\n i = e;\n }\n }\n print((scount <= 1 && allpositive) ? \"YES\":\"NO\");\n}\n"}], "src_uid": "0e0ef011ebe7198b7189fce562b7d6c1"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n const result = new Array(test).fill(0);\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n if (i < 0) {\r\n return;\r\n }\r\n\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n addNumber(test - 1);\r\n addNumber(test - 2);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n }\r\n\r\n // DESC order\r\n let k = 1;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n", "positive_code": [{"source_code": "\"use strict\";var m=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of f(e))!d.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(s=p(e,n))||s.enumerable});return r};var g=r=>h(m({},\"__esModule\",{value:!0}),r);var w={};b(w,{main:()=>l});module.exports=g(w);var o=class{constructor(){this.lines=[];this.data=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),this.complete=new Promise((e,t)=>{process.stdin.on(\"data\",s=>this.data+=s),process.stdin.on(\"end\",()=>{this.lines=this.data.split(`\r\n`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:\"\"}readInt(){return parseInt(this.readLine())}readInts(e=\" \"){return this.readLine().split(e).map(t=>parseInt(t))}},a=class{writeln(e){process.stdout.write(e),process.stdout.write(`\r\n`)}};function c(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}l(new o,new a);async function l(r,e){await r.complete;let t=r.readInt();for(let s=0;s=0;i-=2)u.splice(i,2,...u.slice(i,i+2).reverse());e.writeln(u.join(\" \"))}}0&&(module.exports={main});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const ans = Array(n)\n for (let i = 1; i <= n; i++) {\n // if (n & 1) {\n // // ans[i - 1] = i + 1\n // } else {\n ans[i - 1] = n - 1 - i\n // }\n }\n if (n & 1) {\n [ans[0], ans[1]] = [ans[1], ans[0]]\n }\n ans[n - 3] = 1\n ans[n - 2] = n - 1\n ans[n - 1] = n\n // ;[ans[0], ans[n - 3]] = [ans[n - 3], ans[0]]\n // console.log(check(ans))\n return ans.join(' ')\n}\nfunction check(arr) {\n return arr.reduce((s, x) => s < x ? s + x : 0, 0)\n}\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk;\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n for(let z=1;z<=t;z++)\r\n {\r\n let n=parseInt(line[z]);\r\n let ans='';\r\n if(n&1)\r\n {\r\n ans+=1+' ';\r\n for(let i=n-2;i>=2;i--) ans+=i+' ';\r\n }\r\n else\r\n {\r\n for(let i=n-2;i>=1;i--) ans+=i+' ';\r\n }\r\n ans+=(n-1)+' '+n;\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk;\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n for(let z=1;z<=t;z++)\r\n {\r\n let n=parseInt(line[z]);\r\n // console.log(n);\r\n let ans='';\r\n if(n&1)\r\n {\r\n ans+=1+' ';\r\n for(let i=n-2;i>=2;i--) ans+=i+' ';\r\n }\r\n else\r\n {\r\n for(let i=n-2;i>=1;i--) ans+=i+' ';\r\n }\r\n ans+=(n-1)+' '+n;\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst getresult = (n) => {\r\n let perm = Array(n).fill().map((_, i) => i+1 )\r\n \r\n let i = n % 2\r\n while(i < n - 2)\r\n {\r\n [ perm[i], perm[i + 1] ] = [ perm[i + 1], perm[i] ]\r\n \r\n i += 2\r\n }\r\n \r\n return perm.join(' ')\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while( testcases-- ){\r\n let n = parseInt( readline() )\r\n console.log( getresult(n) )\r\n }\r\n}\r\n//*/"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nlet i = 0\nrl.on('line', function (line) {\n i++\n if (i > 1) {\n // console.log('--->', line);\n processLine(line)\n }\n})\n\nfunction processLine (line) {\n const n = Number(line)\n const arr = new Array(n)\n arr[n - 1] = n\n arr[n - 2] = n - 1\n arr[n - 3] = 1\n let i = 0\n const odd = (n % 2) | 0\n if (odd) { arr[0] = 2; i = 1 };\n for (let el = n - 2; el >= 2 + odd; el--) {\n arr[i] = el\n i++\n }\n console.log(arr.join(' '))\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n const n = parseInt(readLine())\n if (n % 2 === 0) {\n for (let i = n - 2; i > 0; i --) {\n process.stdout.write(i.toString() + \" \")\n }\n } else {\n process.stdout.write(`${n-3} ${n-2} `)\n for (let i = n - 4; i > 0; i --) {\n process.stdout.write(i.toString() + \" \")\n }\n }\n console.log(`${n-1} ${n}`)\n }\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n if (n % 2 === 0) {\r\n let suffix = [n-1, n];\r\n let prefix = [];\r\n let rem = (n - 2) / 2;\r\n for (let i = 0; i < rem; i++) {\r\n prefix.push(2*i+2);\r\n prefix.push(2*i+1);\r\n }\r\n let result = [...prefix, ...suffix].join(' ');\r\n output(result);\r\n } else {\r\n let prefix = [1,2,3];\r\n let suffix = [n-1, n];\r\n let rem = (n - 5) / 2;\r\n for (let i = 2; i < rem + 2; i++) {\r\n prefix.push(2*i+1);\r\n prefix.push(2*i);\r\n }\r\n let result = [...prefix, ...suffix].join(' ');\r\n output(result);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = Number(lines[i]);\n var ans = '';\n for(j = n - 3; j > 1; j--){\n ans += j + ' ';\n }\n ans += (n - 2) + ' ' + 1 + ' ' + (n - 1) + ' ' + n;\n console.log(ans);\n }\n});"}, {"source_code": "\"use strict\";\r\nvar __defProp = Object.defineProperty;\r\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\r\nvar __getOwnPropNames = Object.getOwnPropertyNames;\r\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\r\nvar __export = (target, all) => {\r\n for (var name in all)\r\n __defProp(target, name, { get: all[name], enumerable: true });\r\n};\r\nvar __copyProps = (to, from, except, desc) => {\r\n if (from && typeof from === \"object\" || typeof from === \"function\") {\r\n for (let key of __getOwnPropNames(from))\r\n if (!__hasOwnProp.call(to, key) && key !== except)\r\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\r\n }\r\n return to;\r\n};\r\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\r\n\r\n// src/problem/1728/B/solution.ts\r\nvar solution_exports = {};\r\n__export(solution_exports, {\r\n main: () => main\r\n});\r\nmodule.exports = __toCommonJS(solution_exports);\r\n\r\n// src/lib/arrays.ts\r\nfunction range(start, stop) {\r\n return Array.from(Array(stop - start + 1).keys()).map((it) => it + start);\r\n}\r\nfunction sliceReverse(array, start, count) {\r\n array.splice(start, count, ...array.slice(start, start + count).reverse());\r\n}\r\n\r\n// src/lib/codeforces.ts\r\nvar StdInput = class {\r\n constructor() {\r\n this.lines = [];\r\n this.data = \"\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n this.complete = new Promise((resolve, reject) => {\r\n process.stdin.on(\"data\", (it) => this.data += it);\r\n process.stdin.on(\"end\", () => {\r\n this.lines = this.data.split(\"\\n\");\r\n resolve();\r\n });\r\n });\r\n }\r\n readLine() {\r\n var _a;\r\n return (_a = this.lines.shift()) != null ? _a : \"\";\r\n }\r\n readInt() {\r\n return parseInt(this.readLine());\r\n }\r\n readInts(sep = \" \") {\r\n return this.readLine().split(sep).map((it) => parseInt(it));\r\n }\r\n};\r\nvar StdOutput = class {\r\n writeln(line) {\r\n process.stdout.write(line);\r\n process.stdout.write(\"\\n\");\r\n }\r\n};\r\n\r\n// src/problem/1728/B/solution.ts\r\nmain(new StdInput(), new StdOutput());\r\nasync function main(input, output) {\r\n await input.complete;\r\n const T = input.readInt();\r\n for (let t = 0; t < T; t++) {\r\n const n = input.readInt();\r\n const p = range(1, n);\r\n for (let i = n - 4; i >= 0; i -= 2) {\r\n sliceReverse(p, i, 2);\r\n }\r\n output.writeln(p.join(\" \"));\r\n }\r\n}\r\n// Annotate the CommonJS export names for ESM import in node:\r\n0 && (module.exports = {\r\n main\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nvar __defProp = Object.defineProperty;\r\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\r\nvar __getOwnPropNames = Object.getOwnPropertyNames;\r\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\r\nvar __export = (target, all) => {\r\n for (var name in all)\r\n __defProp(target, name, { get: all[name], enumerable: true });\r\n};\r\nvar __copyProps = (to, from, except, desc) => {\r\n if (from && typeof from === \"object\" || typeof from === \"function\") {\r\n for (let key of __getOwnPropNames(from))\r\n if (!__hasOwnProp.call(to, key) && key !== except)\r\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\r\n }\r\n return to;\r\n};\r\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\r\n\r\n// src/problem/1728/B/solution.ts\r\nvar solution_exports = {};\r\n__export(solution_exports, {\r\n main: () => main\r\n});\r\nmodule.exports = __toCommonJS(solution_exports);\r\n\r\n// src/lib/codeforces.ts\r\nvar StdInput = class {\r\n constructor() {\r\n this.lines = [];\r\n this.data = \"\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n this.complete = new Promise((resolve, reject) => {\r\n process.stdin.on(\"data\", (it) => this.data += it);\r\n process.stdin.on(\"end\", () => {\r\n this.lines = this.data.split(\"\\n\");\r\n resolve();\r\n });\r\n });\r\n }\r\n readLine() {\r\n var _a;\r\n return (_a = this.lines.shift()) != null ? _a : \"\";\r\n }\r\n readInt() {\r\n return parseInt(this.readLine());\r\n }\r\n readInts(sep = \" \") {\r\n return this.readLine().split(sep).map((it) => parseInt(it));\r\n }\r\n};\r\nvar StdOutput = class {\r\n writeln(line) {\r\n process.stdout.write(line);\r\n process.stdout.write(\"\\n\");\r\n }\r\n};\r\n\r\n// src/lib/natural-numbers.ts\r\nfunction range(start, stop) {\r\n return Array.from(Array(stop - start + 1).keys()).map((it) => it + start);\r\n}\r\n\r\n// src/problem/1728/B/solution.ts\r\nmain(new StdInput(), new StdOutput());\r\nasync function main(input, output) {\r\n await input.complete;\r\n const T = input.readInt();\r\n for (let t = 0; t < T; t++) {\r\n const n = input.readInt();\r\n const p = range(1, n);\r\n for (let i = n - 4; i >= 0; i -= 2) {\r\n p.splice(i, 2, ...p.slice(i, i + 2).reverse());\r\n }\r\n output.writeln(p.join(\" \"));\r\n }\r\n}\r\n// Annotate the CommonJS export names for ESM import in node:\r\n0 && (module.exports = {\r\n main\r\n});\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n const result = new Array(test).fill(0);\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n if (i < 0) {\r\n return;\r\n }\r\n\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n addNumber(test - 1);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n }\r\n\r\n // DESC order\r\n let k = 1;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n const result = new Array(test).fill(0);\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n addNumber(x - 2);\r\n addNumber(x - 1);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n }\r\n\r\n // DESC order\r\n let k = 1;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n const result = new Array(test).fill(0);\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n addNumber(x - 1);\r\n addNumber(x - 2);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n }\r\n\r\n // DESC order\r\n let k = 1;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n // Phase 3\r\n let k = test;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n // Phase 3\r\n let k = 1;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n }\r\n\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n addNumber(test - 2);\r\n }\r\n\r\n // Phase 3\r\n let k = test;\r\n for (let j = 1; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n }\r\n\r\n // Phase 3\r\n let k = test;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n // Phase 3\r\n let k = test;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n // Phase 3\r\n let k = 1;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n addNumber(1);\r\n // Phase 3\r\n let k = 1;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n addNumber(1);\r\n // Phase 3\r\n let k = test;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n }\r\n\r\n\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 1) {\r\n console.log('1');\r\n continue;\r\n }\r\n\r\n if (test === 2) {\r\n console.log('1 2');\r\n continue;\r\n }\r\n\r\n if (test === 3) {\r\n console.log('2 1 3');\r\n continue;\r\n }\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n }\r\n\r\n addNumber(1);\r\n\r\n // Phase 3\r\n let k = test;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k--;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 1) {\r\n console.log('1');\r\n continue;\r\n }\r\n\r\n if (test === 2) {\r\n console.log('1 2');\r\n continue;\r\n }\r\n\r\n if (test === 3) {\r\n console.log('2 1 3');\r\n continue;\r\n }\r\n\r\n if (test === 4) {\r\n console.log('2 1 3 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n }\r\n\r\n addNumber(1);\r\n\r\n // Phase 3\r\n let k = 1;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n').map(Number);\r\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\r\n const test = data[testNumber];\r\n const result = new Array(test).fill(0);\r\n\r\n if (test === 1) {\r\n console.log('1');\r\n continue;\r\n }\r\n\r\n if (test === 2) {\r\n console.log('1 2');\r\n continue;\r\n }\r\n\r\n if (test === 3) {\r\n console.log('2 1 3');\r\n continue;\r\n }\r\n\r\n if (test === 4) {\r\n console.log('3 1 2 4');\r\n continue;\r\n }\r\n\r\n let i = result.length - 1;\r\n const added = new Set();\r\n const addNumber = (num) => {\r\n result[i] = num;\r\n added.add(num);\r\n i--;\r\n };\r\n\r\n // Phase 1\r\n addNumber(test);\r\n\r\n // Phase 2\r\n if (test % 2 === 0) {\r\n // Even case\r\n const x = Math.floor((test - 2) / 2);\r\n const y = x + 1;\r\n addNumber(y);\r\n addNumber(x);\r\n } else {\r\n // Odd case\r\n addNumber(test - 1);\r\n }\r\n\r\n addNumber(1);\r\n\r\n // Phase 3\r\n let k = 1;\r\n for (let j = 0; j <= test; j++) {\r\n while (added.has(k)) {\r\n k++;\r\n }\r\n\r\n addNumber(k);\r\n }\r\n\r\n console.log(result.join(' '));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const data = input.trim().split('\\n').map(Number);\n for (let testNumber = 1; testNumber < data.length; testNumber++) {\n const test = data[testNumber];\n console.log(test);\n const result = new Array(test).fill(0);\n\n if (test === 1) {\n console.log('1');\n continue;\n }\n\n if (test === 2) {\n console.log('1 2');\n continue;\n }\n\n if (test === 3) {\n console.log('2 1 3');\n continue;\n }\n\n if (test === 4) {\n console.log('3 1 2 4');\n continue;\n }\n\n let i = result.length - 1;\n const added = new Set();\n const addNumber = (num) => {\n result[i] = num;\n added.add(num);\n i--;\n };\n\n // Phase 1\n addNumber(test);\n\n // Phase 2\n if (test % 2 === 0) {\n // Even case\n const x = Math.floor((test - 2) / 2);\n const y = x + 1;\n addNumber(y);\n addNumber(x);\n } else {\n // Odd case\n addNumber(test - 1);\n }\n\n addNumber(1);\n\n // Phase 3\n let k = 1;\n for (let j = 0; j <= test; j++) {\n while (added.has(k)) {\n k++;\n }\n\n addNumber(k);\n }\n\n console.log(result.join(' '));\n }\n});\n"}, {"source_code": "\"use strict\";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var f=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},b=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of p(e))!d.call(r,s)&&s!==t&&u(r,s,{get:()=>e[s],enumerable:!(n=l(e,s))||n.enumerable});return r};var h=r=>b(u({},\"__esModule\",{value:!0}),r);var g={};f(g,{main:()=>c});module.exports=h(g);var i=class{constructor(){this.lines=[];this.data=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),this.complete=new Promise((e,t)=>{process.stdin.on(\"data\",n=>this.data+=n),process.stdin.on(\"end\",()=>{this.lines=this.data.split(`\r\n`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:\"\"}readInt(){return parseInt(this.readLine())}readInts(e=\" \"){return this.readLine().split(e).map(t=>parseInt(t))}},o=class{writeln(e){process.stdout.write(e),process.stdout.write(`\r\n`)}};function m(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}c(new i,new o);async function c(r,e){await r.complete;let t=r.readInt();for(let n=0;n{for(var t in e)a(r,t,{get:e[t],enumerable:!0})},f=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of l(e))!p.call(r,i)&&i!==t&&a(r,i,{get:()=>e[i],enumerable:!(n=c(e,i))||n.enumerable});return r};var b=r=>f(a({},\"__esModule\",{value:!0}),r);var h={};d(h,{main:()=>m});module.exports=b(h);var s=class{constructor(){this.lines=[];this.data=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),this.complete=new Promise((e,t)=>{process.stdin.on(\"data\",n=>this.data+=n),process.stdin.on(\"end\",()=>{this.lines=this.data.split(`\r\n`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:\"\"}readInt(){return parseInt(this.readLine())}readInts(e=\" \"){return this.readLine().split(e).map(t=>parseInt(t))}},o=class{writeln(e){process.stdout.write(e),process.stdout.write(`\r\n`)}};function u(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}m(new s,new o);async function m(r,e){await r.complete;let t=r.readInt();for(let n=0;n {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const ans = Array(n)\n for (let i = 1; i <= n; i++) {\n ans[i - 1] = i\n }\n ;[ans[0], ans[n - 3]] = [ans[n - 3], ans[0]]\n return ans.join(' ')\n}\n"}, {"source_code": "// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst getresult = (n) => {\r\n let res = []\r\n let i = 1\r\n while( i <= n ) {\r\n res.push(i)\r\n i++\r\n }\r\n \r\n return res.join(' ')\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while( testcases-- ){\r\n let n = parseInt( readline() )\r\n \r\n console.log( getresult(n) )\r\n }\r\n \r\n}\r\n//*/"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nlet i = 0\nrl.on('line', function (line) {\n i++\n if (i > 1) {\n // console.log('--->', line);\n processLine(line)\n }\n})\n\nfunction processLine (line) {\n const n = Number(line)\n const arr = new Array(n)\n arr[n - 1] = n\n arr[n - 2] = n - 1\n arr[n - 3] = 1\n let i = 0\n if (n % 2 === 0) {\n for (let el = n - 2; el >= 2; el--) {\n arr[i] = el\n i++\n }\n } else {\n for (let el = 2; el <= n - 2; el++) {\n arr[i] = el\n i++\n }\n }\n console.log(arr.join(' '))\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n const n = parseInt(readLine())\n if (n === 1) {\n console.log(1)\n continue\n }\n for (let i = n - 2; i > 0; i --) {\n process.stdout.write(i.toString() + \" \")\n }\n console.log(`${n-1} ${n}`)\n }\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n if (n % 2 === 0) {\r\n let suffix = [n-1, n];\r\n let prefix = [];\r\n let rem = (n - 2) / 2;\r\n for (let i = 0; i < rem; i++) {\r\n prefix.push(2*i+2);\r\n prefix.push(2*i+1);\r\n }\r\n let result = [...prefix, ...suffix].join(' ');\r\n output(result);\r\n } else {\r\n let prefix = [1,2,3];\r\n let suffix = [n-1, n];\r\n let rem = (n - 5) / 2;\r\n for (let i = 2; i < rem; i++) {\r\n prefix.push(2*i+1);\r\n prefix.push(2*i);\r\n }\r\n let result = [...prefix, ...suffix].join(' ');\r\n output(result);\r\n }\r\n }\r\n}\r\n"}], "src_uid": "9cc18b914678cb18213b2a52259de35d"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function c(){return s[i++]}function f(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:c,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt.a)).max()-e.map((t=>t.b)).min(),s=e.map((t=>t.a)).max()-n.map((t=>t.b)).min();u.default.put(Math.max(o,s,0))}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();", "positive_code": [{"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(word) {\n\t\treturn parseInt(word)\n\t})\n}\n\nvar n = parseInt(readline()),\n\tminEA = 1000000001,\n\tminEB = 1000000001,\n\tmaxSA = 0,\n\tmaxSB = 0,\n\tpair = []\n\nwhile (n > 0) {\n\tpair = ints()\n\tminEA = Math.min(minEA, pair[1])\n\tmaxSA = Math.max(maxSA, pair[0])\n\tn --\n}\n\nn = parseInt(readline())\nwhile (n > 0) {\n\tpair = ints()\n\tminEB = Math.min(minEB, pair[1])\n\tmaxSB = Math.max(maxSB, pair[0])\n\tn --\n}\n\nprint(Math.max(0, Math.max(maxSB - minEA, maxSA - minEB)))"}, {"source_code": "var classes = [ \n {\n minEnd: 1000000000,\n maxStart: 1\n },\n {\n minEnd: 1000000000,\n maxStart: 1\n }\n];\nvar maxDistance = 0;\n\nfor (var i = 0; i < classes.length; i++) {\n var amount = parseInt(readline());\n \n for (var j = 0; j < amount; j++) {\n var input = readline();\n \n var startTime = parseInt(input.split(\" \")[0]);\n var endTime = parseInt(input.split(\" \")[1]);\n \n if (classes[i].minEnd > endTime)\n classes[i].minEnd = endTime;\n if (classes[i].maxStart < startTime)\n classes[i].maxStart = startTime;\n }\n}\n\nif (classes[0].minEnd < classes[1].maxStart)\n maxDistance = classes[1].maxStart - classes[0].minEnd;\nif (classes[1].minEnd < classes[0].maxStart)\n if (maxDistance < classes[0].maxStart - classes[1].minEnd)\n maxDistance = classes[0].maxStart - classes[1].minEnd;\n\nprint(maxDistance);"}, {"source_code": "var contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];\n\nfor(var i = 0; i < contVal.length; i++) {\n \n var num_pairs = parseInt(readline());\n \n for(var j = 0; j < num_pairs; j++) {\n \n var pair = readline().split(' ').map(Number);\n \n contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);\n contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);\n }\n}\n\nprint(Math.max(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r)));"}, {"source_code": "/*\n The idea to solve this problem is basically observing the condition how rest time is formed:\n - l1->r1 l2->r2\n - l2->r2 l1->r1\n \n Since we want to get maximum rest time, then we need to compare these two conditions:\n - l1->r1 l2->r2 ==> max(l2) - min(r1)\n - l2->r2 l1->r1 ==> max(l1) - min(r2)\n \n Notice that when period is intersect (the resulted value from formula above will negative), based on problem description, the value of distance will become 0. Thus above formula will be like this:\n - l1->r1 l2->r2 ==> max(0, max(l2) - min(r1))\n - l2->r2 l1->r1 ==> max(0, max(l1) - min(r2))\n \n Thus to get max distance, the formula would be: max(max(0, max(l2) - min(r1)), max(0, max(l1) - min(r2)))\n*/\n\n// define container for containing max l & min r values\nvar contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];\n\n// search for max l & min r value\nfor(var i = 0; i < contVal.length; i++) {\n \n var num_pairs = parseInt(readline());\n \n for(var j = 0; j < num_pairs; j++) {\n \n var pair = readline().split(' ').map(Number);\n \n contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);\n contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);\n }\n}\n\n// get max distance | rest time\nprint(Math.max(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r)));"}, {"source_code": "var n = parseInt(readline());\n var np = [];\n var nsrm = - Infinity;\n var nslm = Infinity;\n var nerm = - Infinity;\n var nelm = Infinity;\n while(n > 0) {\n np.push(readline().split(' ').map(function(x) { return parseInt(x); }));\n nsrm = Math.max(nsrm, np[np.length - 1][0]);\n nslm = Math.min(nslm, np[np.length - 1][0]);\n nerm = Math.max(nerm, np[np.length - 1][1]);\n nelm = Math.min(nelm, np[np.length - 1][1]);\n n -= 1;\n }\n\n var m = parseInt(readline());\n var mp = [];\n var msrm = - Infinity;\n var mslm = Infinity;\n var merm = - Infinity;\n var melm = Infinity;\n while(m > 0) {\n mp.push(readline().split(' ').map(function(x) { return parseInt(x); }));\n msrm = Math.max(msrm, mp[mp.length - 1][0]);\n mslm = Math.min(mslm, mp[mp.length - 1][0]);\n merm = Math.max(merm, mp[mp.length - 1][1]);\n melm = Math.min(melm, mp[mp.length - 1][1]);\n m -= 1;\n }\n print(Math.max(0, Math.max(nsrm - melm, msrm - nelm)));"}], "negative_code": [{"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(word) {\n\t\treturn parseInt(word)\n\t})\n}\n\nvar n = parseInt(readline()),\n\tminEA = 1000000001,\n\tminEB = 1000000001,\n\tmaxSA = 0,\n\tmaxSB = 0,\n\tpair = []\n\nwhile (n > 0) {\n\tpair = ints()\n\tminEA = Math.min(minEA, pair[1])\n\tmaxSA = Math.max(maxSA, pair[0])\n\tn --\n}\n\nn = parseInt(readline())\nwhile (n > 0) {\n\tpair = ints()\n\tminEB = Math.min(minEB, pair[1])\n\tmaxSB = Math.max(maxSB, pair[0])\n\tn --\n}\n\nprint(Math.max(maxSB - minEA, maxSA - minEB))"}, {"source_code": "var contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];\n\nfor(var i = 0; i < contVal.length; i++) {\n \n var num_pairs = parseInt(readline());\n \n for(var j = 0; j < num_pairs; j++) {\n \n var pair = readline().split(' ').map(Number);\n \n contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);\n contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);\n }\n}\n\nprint(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r));"}], "src_uid": "4849a1f65afe69aad12c010302465ccd"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m, p] = readInts(input, 0)\n const ai = readInts(input, 1)\n const bi = readInts(input, 2)\n let i = 0, j =0\n while(i < n) {\n if(ai[i] % p !== 0) {\n break\n }\n i++\n }\n while(j < m) {\n if(bi[j] % p !== 0) {\n break\n }\n j++\n }\n // wr(i, j)\n wr(i + j)\n}", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(o=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{o=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return o[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rt%r!=0))+s.findIndex((t=>t%r!=0)))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m, p] = io.nextNumbers()\n// let a = io.nextNumbers()\n// let b = io.nextNumbers()\n// \n// io.puts(a.findIndex((x) => x % p != 0) + b.findIndex((x) => x % p != 0))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "negative_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m, p] = readInts(input, 0)\n const ai = readInts(input, 1)\n const bi = readInts(input, 2)\n let i = 0, j =0\n while(i < n) {\n if(ai[i] % p !== 0 && i !== 0) {\n break\n }\n i++\n }\n while(j < m) {\n if(bi[j] % p !== 0 && j !== 0) {\n break\n }\n j++\n }\n wr(i, j)\n wr(i + j)\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m, p] = readInts(input, 0)\n const ai = readInts(input, 1)\n const bi = readInts(input, 2)\n let i = 0, j =0\n while(i < n) {\n if(ai[i] % p !== 0 && i !== 0) {\n break\n }\n i++\n }\n while(j < m) {\n if(bi[j] % p !== 0 && j !== 0) {\n break\n }\n j++\n }\n // wr(i, j)\n wr(i + j)\n}"}], "src_uid": "23c8f5922c7a1cdb82d229eb9938f3ee"} {"source_code": "var inputMN = readline().split(\" \").map(function (x) { return parseInt(x); });\nvar inputMList = readline().split(\" \").map(function (x) { return parseInt(x); });\nvar inputNList = readline().split(\" \").map(function (x) { return parseInt(x); });\nvar mOdd = 0, mEven = 0, nOdd = 0, nEven = 0;\nfor (var i = 0; i < inputMN[0]; i++) {\nif (inputMList[i] % 2 === 0) {\n ++mEven;\n} else {\n ++mOdd;\n}\n}\nfor (var j = 0; j < inputMN[1]; j++) {\nif (inputNList[j] % 2 === 0) {\n ++nEven;\n} else {\n ++nOdd;\n}\n}\nprint(Math.min(mEven, nOdd) + Math.min(nEven, mOdd));", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var m = line[1];\n\n var a = read.arrNumber(' ');\n var b = read.arrNumber( ' ');\n\n\n var ac = 0;\n for(var i = 0; i < n; i ++) {\n if(a[i]%2 === 0) {\n ac++;\n }\n }\n var an = n - ac;\n\n var bc = 0;\n for(var i = 0; i < m; i ++) {\n if(b[i] % 2 === 0) {\n bc++;\n }\n }\n\n var bn = m - bc;\n\n var m1 = ac > bn ? bn : ac;\n var m2 = an > bc ? bc : an;\n print(m1 + m2);\n}());\n"}, {"source_code": "var firstLine = readline();\n\nvar cN = readline().split(' ');\nvar cM = readline().split(' ');\n\nvar cNObj = checkArr(cN);\nvar cMObj = checkArr(cM);\n\nvar res1 = Math.min(cNObj['ch'], cMObj['neCh']);\nvar res2 = Math.min(cNObj['neCh'], cMObj['ch']);\n\nprint(res1+res2);\n\nfunction minVal(a, b) {\n \n}\nfunction checkArr(arr) {\n var chCount = 0;\n var neChCount = 0;\n arr.forEach(function(el) {\n if(el%2) {\n neChCount++;\n } else {\n chCount++;\n }\n });\n return {\"ch\" : chCount, \"neCh\" : neChCount};\n}"}, {"source_code": "readline();\n\nvar chests = readline().split(' ').map(function(num) {\n return parseInt(num);\n});\n\nvar keys = readline().split(' ').map(function(num) {\n return parseInt(num);\n});\n\nvar evenChestsAmount = 0;\nvar oddChestsAmount = 0;\n\nvar evenKeysAmount = 0;\nvar oddKeysAmount = 0;\n\nfor (var i = 0; i < chests.length; i++) {\n if (chests[i] % 2 == 0) {\n evenChestsAmount++;\n } else {\n oddChestsAmount++;\n }\n}\n\nfor (var i = 0; i < keys.length; i++) {\n if (keys[i] % 2 == 0) {\n evenKeysAmount++;\n } else {\n oddKeysAmount++;\n }\n}\n\nvar result = Math.min(evenChestsAmount, oddKeysAmount);\nresult += Math.min(oddChestsAmount, evenKeysAmount);\n\nprint(result);"}, {"source_code": "var nm = readline().split(' ').map(v=>(parseInt(v)))\nvar chests = readline().split(' ').map(v=>(parseInt(v)%2 === 0))\nvar keys = readline().split(' ').map(v=>(parseInt(v)%2 === 0))\n\nvar min0 = Math.min(chests.filter(c=>(c)).length, keys.filter(k=>(!k)).length)\nvar min1 = Math.min(chests.filter(c=>(!c)).length, keys.filter(k=>(k)).length)\n\nvar res = min0 + min1;\n\nprint(res)"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet chests;\nlet keys;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n if (c === 1) {\n chests = d.split(' ').map(Number);\n }\n\n if (c === 2) {\n keys = d.split(' ').map(Number);\n }\n\n c++;\n});\n\nrl.on('close', () => {\n let odd = 0;\n let even = 0;\n let ans = 0;\n\n for (let i = 0; i < chests.length; i++) {\n if (chests[i] % 2 === 0) {\n even++;\n }\n else {\n odd++;\n }\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (keys[i] % 2 !== 0 && even > 0) {\n even--;\n ans++;\n }\n else if (keys[i] % 2 === 0 && odd > 0) {\n odd--;\n ans++;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "ip= readline().split(' ');\nn = +ip[0], m = +ip[1];\none = readline().split(' ').map(Number).reduce(((acc,x)=>x%2 === 1?acc+1:acc),0);\ntwo = readline().split(' ').map(Number).reduce(((acc,x)=>x%2 === 1?acc+1:acc),0);\nprint(Math.min(one,m - two) + Math.min(two,n - one));"}], "negative_code": [], "src_uid": "bc532d5c9845940b5f59485394187bf6"} {"source_code": "var input = readline().split(\" \");\nvar prices = [];\nfor (var i = 0; i < parseInt(input[0],10); i++) {\n prices.push(readline());\n}\nvar min = prices[0].split(\" \")[0]/prices[0].split(\" \")[1];\nfor (var i = 1; i < prices.length; i++) {\n var temp = prices[i].split(\" \")[0]/prices[i].split(\" \")[1];\n if (temp < min) min = temp;\n}\nwrite(min*input[1]);", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar M = one[1];\n\tvar list = new Array(N);\n\tfor(var i = 0; i < N; i++){\n\t\tvar tmp = nextIntArray();\n\t\tlist[i] = tmp[0] / tmp[1];\n\t}\n\tlist.sort(function(a,b){\n\t\treturn a - b;\n\t});\n\tmyout(list[0] * M);\n}\n"}, {"source_code": "'use strict';\n\nfunction Scanner() {\n this.nextLine = () => readline();\n this.nextInt = () => parseInt(readline());\n this.nextDouble = () => parseInt(readline());\n this.nextArray = () => readline().split(' ');\n}\n\nconst is = new Scanner();\n\nlet line = is.nextArray().map(Number);\nlet n = line[0];\nlet m = line[1];\nlet a, b;\n\nlet answer = Infinity;\nfor (let i = 0; i < n; i++) {\n line = is.nextArray().map(Number);\n a = line[0];\n b = line[1];\n answer = Math.min(answer, (a * m) / b);\n}\n\nprint(answer);\n"}, {"source_code": "// http://codeforces.com/problemset/problem/977/A\nmodule.exports = solve;\nfunction solve() {\n var [n, m] = readline();\n var min = 999999;\n for (var i = 0; i < n; i++) {\n const [a, b]= readline();\n min = Math.min(min, a / b)\n }\n return min * m;\n}\n\nfunction readline(){\n return lines.shift();\n}\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nrl.on('line', (line) => {\n lines.push(line.split(' ').map(n => parseInt(n, 10))); \n if(lines.length -1 === lines[0][0]) {\n console.log(solve());\n rl.close();\n }\n});"}, {"source_code": "'use strict';\nvar inputData = readline().split(' ');\nvar n = parseInt(inputData[0]);\nvar m = parseInt(inputData[1]);\nvar cost = [];\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ');\n var a = parseInt(input[0]);\n var b = parseInt(input[1]);\n cost.push(a / b);\n}\nprint(Math.min.apply(Math, cost) * m);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet best = Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n let tmp = (m * a / b);\n\n if (tmp < best) {\n best = tmp;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(best.toFixed(8));\n});\n"}, {"source_code": "'use strict';\nvar inputData = readline().split(' ');\nvar n = parseInt(inputData[0]);\nvar m = parseInt(inputData[1]);\nvar cost = [];\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ');\n var a = parseInt(input[0]);\n var b = parseInt(input[1]);\n cost.push(a / b);\n}\nprint(Math.min.apply(Math, cost) * m);"}, {"source_code": "var inputData = readline().split(' ');\nvar n = parseInt(inputData[0]);\nvar m = parseInt(inputData[1]);\nvar cost = [];\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ');\n var a = parseInt(input[0]);\n var b = parseInt(input[1]);\n cost.push(a / b);\n}\nprint(Math.min.apply(Math, cost) * m);"}], "negative_code": [{"source_code": "// http://codeforces.com/problemset/problem/977/A\nmodule.exports = solve;\nfunction solve(vals) {\n let min = 99999999;\n vals.forEach(v => {\n let [a, b] = line.split(' ').map(n => parseInt(n, 10)); \n min = Math.min(b/a, min);\n })\n return min;\n}\n\n\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet vals = [];\nrl.on('line', (line) => {\n vals.push(line);\n // if (i++) {\n // /console.log(solve(line))\n // rl.close();\n // }\n});\nrl.on('end', (line) => {\n console.log(solve(vals))\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet best = Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n let tmp = (m * a / b).toFixed(8);\n\n if (tmp < best) {\n best = tmp;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(best);\n});\n"}], "src_uid": "3bbe48918a7bf3faf01c74cb7296f6e0"} {"source_code": "var t=readline();\nwhile(t--)\n{\n var n=readline();\n print(n + \" \");\n \n for(var i=1;i<=n-1;i++)\n {\n print(i + \" \");\n }\n print(\"\\n\");\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let res = '';\n for(let i = 1; i <= n; i++){\n if(i !== n){\n res += ` ${i+1}`;\n }else{\n res += ` ${1}`;\n }\n }\n\n console.log(res.trim());\n }\n}"}, {"source_code": "function main(){\n var n = readline();\n for(var i = 0; i < n; ++i){\n var num = readline();\n var res = '';\n res += `${num} `;\n for(var j = 1; j < num - 1; ++j){\n res += `${j} `;\n }\n res += num - 1;\n print(res);\n }\n}\n\nmain();"}, {"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let n = readline(), a = [];\n for(let i = 1; i < n; i++)a[i] = i;\n a[0] = n;\n print(a.join(\" \"));\n}"}, {"source_code": "(function() {\n var t = +readline()\n \n for (var i = 0; i < t; i++) {\n var n = +readline()\n var arr = []\n flag = true\n for (j = 1; j <= n; j++) {\n if (j + 1 <= n) {\n arr.push(j + 1)\n } else {\n arr.push(j - j + 1)\n }\n \n }\n print(arr.join(' '))\n }\n}())"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n var part = l/2;\n \n for (var j = 1; j <= l; j++) {\n res[j-1] = j;\n }\n \n for (var k = 0; k < l -1; k++) {\n \n var temp = res[k];\n res[k] = res[k+1];\n res[k+1] = temp;\n \n }\n \n \n print(res.toString().replace(/\\,/g, ' '));\n}"}, {"source_code": "var start = true\n\nfunction task(s){\n\ts = s.trim().split('\\n')\n\tlet t = +s.shift()\n\tfor (let i = 0; i < t; i++) {\n\t\tlet n = +s.shift(), a = []\n\t\tfor (let j = n; j>=1; j--) {\n\t\t\ta.push(j)\n\t\t\tif(j==a.length){\n\t\t\t\ta[a.length-1] = n\n\t\t\t\ta[0] = j\n\t\t\t}\n\t\t}\n\t\tconsole.log(a.join(' '));\n\t}\n}\n\nif(start){\n\tprocess.stdin.resume();\n\tprocess.stdin.setEncoding('utf-8');\n\tlet inputString = '';\n\tprocess.stdin.on('data', inputStdin => {\n\t inputString += inputStdin;\n\t});\n\tprocess.stdin.on('end', _ => { \n\t task(inputString); \n\t});\n}\n"}, {"source_code": "const solve = (p) => {\n let res = [];\n for (let i = 1; i <= p; i++) {\n res.unshift(i);\n }\n if (p % 2 == 1) {\n let mid = p >> 1;\n [res[mid], res[mid + 1]] = [res[mid + 1], res[mid]];\n }\n console.log(res.join(\" \"));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n solve(data[0][0]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const ans = [];\n\n for (let i = 2; i <= len; i++) ans.push(i);\n ans.push(1);\n\n console.log(ans.join(\" \"));\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = new Array(N);\n\t\tfor(var j = 1; j <= N; j++){\n\t\t\tlist[j - 1] = j;\n\t\t}\n\t\tlist.push(list.shift());\n\t\toutput[i] = myconv(list, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = new Array(N);\n\t\tfor(var j = 1; j <= N; j++){\n\t\t\tlist[j - 1] = j;\n\t\t}\n\t\tlist.push(list.shift());\n\t\tmyout(myconv(list, 8));\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n // const s = data[i].trim().split(' ');\n // let a = data[i].trim() * 1;\n const n = data[i] * 1;\n // const p = BigInt(s[0]);\n // const q = BigInt(s[1]);\n // s.sort((a, b) => b - a);\n let arr = [];\n // console.log(p%q)\n // let first = true;\n // for (let j = p; j > 0; j -= 1n) {\n // if (p % j === 0n && j % q !== 0n) {\n // console.log(j.toString());\n // break;\n // } else if (first) {j = j / 2n + 1n; first = false;}\n // }\n let j = n;\n while (j > Math.ceil(n / 2)) {\n arr.push(j);\n j -= 1;\n }\n j = 1;\n while (j <= Math.ceil(n / 2)) {\n arr.push(j);\n j += 1;\n }\n console.log(arr.join(' '));\n i += 1;\n }\n}"}, {"source_code": "\"use strict\";\n\n(() => {\n\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let curLine = 0, allLines = [];\n\n let nextLine = () => {\n if(curLine == allLines.length) throw new ReferenceError(\"No more input in the buffer\");\n return allLines[curLine++]\n };\n \n readline.on(\"line\", line => { allLines.push(line); });\n readline.on(\"close\", () => { main(nextLine) });\n\n})();\n\nfunction main(nextLine) {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n \n let ans = [];\n for(let i = 2; i <= n; i++) ans.push(i);\n ans.push(1);\n\n console.log(ans.join(\" \"));\n }\n}"}, {"source_code": "/* this language fucking sucks */\n\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lines = [];\n\nrl.on('line', (data) => {\n lines.push(data);\n if(lines.length > 0 && parseInt(lines[0]) === lines.length - 1) {\n\trl.close();\n\tmain();\n }\n});\n\nasync function main() {\n let t = parseInt(lines[0]);\n for(let i = 1; i <= t; i++) {\n\tlet n = parseInt(lines[i]);\n\tlet ans = n + ' ';\n\tfor(let j = 1; j < n; j++) {\n\t ans += (j + ' ');\n\t}\n\tconsole.log(ans);\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function shuffle(array) {\n// var currentIndex = array.length,\n// temporaryValue,\n// randomIndex\n// \n// // While there remain elements to shuffle...\n// while (0 !== currentIndex) {\n// // Pick a remaining element...\n// randomIndex = Math.floor(Math.random() * currentIndex)\n// currentIndex -= 1\n// \n// // And swap it with the current element.\n// temporaryValue = array[currentIndex]\n// array[currentIndex] = array[randomIndex]\n// array[randomIndex] = temporaryValue\n// }\n// \n// return array\n// }\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let a: number[] = []\n// \n// for (let i = 1; i <= n; ++i) {\n// a.push(i)\n// }\n// \n// while (true) {\n// a = shuffle(a)\n// \n// let ok = true\n// \n// for (let i = 1; i <= n; ++i) {\n// if (a[i - 1] == i) {\n// ok = false\n// break\n// }\n// }\n// \n// if (ok) {\n// break\n// }\n// }\n// \n// io.puts(a.join(\" \"))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\n let values = lines.map(val => parseInt(val));\n let t = values[0];\n\n for (let i = 0; i < t; i++) {\n console.log(solve(values[i + 1]));\n }\n});\n\nfunction solve(n) {\n const result = [];\n\n for (let i = 2; i <= n; i++) {\n result.push(i);\n }\n\n result.push(1);\n\n return result.join(' ');\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n/*\n 2\n 5\n\n 2 1\n 2 1 5 3 4\n*/\n\nfunction aaa(n) {\n n = +n;\n // console.log(n);\n\n let A = [];\n for (let i=0; i {\n \n if (i === 0) {\n T = line;\n i++;\n return\n } else {\n aaa(line);\n }\n});\n"}], "negative_code": [{"source_code": "function main(){\n var n = readline();\n for(var i = 0; i < n; ++i){\n var num = readline();\n var res = '';\n for(var j = num; j > 1; --j){\n res += `${j} `;\n }\n res += '1';\n print(res);\n }\n}\n\nmain();"}, {"source_code": "function main(){\n var n = readline();\n for(var i = 0; i < n; ++i){\n var num = readline();\n var res = '';\n res += '5 ';\n for(var j = 1; j < num - 1; ++j){\n res += `${j} `;\n }\n res += num - 1;\n print(res);\n }\n}\n\nmain();"}, {"source_code": "function main(){\n var n = readline();\n for(var i = 0; i < n; ++i){\n var num = readline();\n var res = '';\n res += `${n} `;\n for(var j = 1; j < num - 1; ++j){\n res += `${j} `;\n }\n res += num - 1;\n print(res);\n }\n}\n\nmain();"}, {"source_code": "(function() {\n var t = +readline()\n \n for (var i = 0; i < t; i++) {\n var n = +readline()\n var arr = []\n for (j = 1; j <= n; j++) {\n arr.push(j)\n }\n print(arr.join(' '))\n }\n}())"}, {"source_code": "(function() {\n var t = +readline()\n \n for (var i = 0; i < t; i++) {\n var n = +readline()\n var arr = []\n var flag = false\n for (j = 1;j <= n; j++) {\n if (flag) {\n arr.push(j)\n flag = false\n } else {\n arr.push(100 - j + 1)\n flag = true\n }\n }\n var res = arr.join(' ')\n print(res)\n }\n \n}())"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n var num;\n \n for (var j = 1; j <= l; j++) {\n num = 1;\n \n if (num != j) {\n while (~res.indexOf(num)) {\n num++;\n }\n res[j-1] = num;\n } else {\n num++;\n while (~res.indexOf(num)) {\n num++;\n }\n\n res[j-1] = num;\n }\n }\n \n print(res.toString().replace(/\\,/g, ' '));\n}"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n for (var j = 0; j < l; j++) {\n res[j] = j+1;\n }\n \n print(res.toString().replace(/\\,/g, ' '));\n}\n"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n for (var j = 0; j < l; j++) {\n res[j] = j+1;\n }\n print(res.slice(0,2).reverse().concat(res.slice(2).reverse()).toString().replace(/\\,/g, ' '));\n}"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var res = [];\n \n for (var j = 0; j < l; j++) {\n res[j] = j+1;\n }\n \n print(res.reverse().toString().replace(/\\,/g, ' '));\n}\n"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nasync function cin() {\n return new Promise((resolve, reject) => {\n\trl.question('', (data) => {\n\t resolve(data);\n\t});\n });\n}\n\nasync function cint() {\n let n = await cin();\n return parseInt(n);\n}\n\nasync function main() {\n let t = await cint();\n while(t--) {\n\tlet n = await cint();\n\tprocess.stdout.write(n + ' ');\n\tfor(let i = 1; i < n; i++) {\n\t process.stdout.write(i + ' ');\n\t}\n\tprocess.stdout.write('\\n');\n }\n\n rl.close();\n}\n\nmain();\n"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nasync function cin() {\n return new Promise((resolve, reject) => {\n\trl.question('', (data) => {\n\t resolve(data);\n\t});\n });\n}\n\nasync function cint() {\n let n = await cin();\n return parseInt(n);\n}\n\nasync function main() {\n let t = await cint();\n while(t--) {\n\tlet n = await cint();\n\tlet ans = n + ' ';\n\tfor(let i = 1; i < n; i++) {\n\t ans += (i + ' ');\n\t}\n\tconsole.log(ans);\n }\n\n rl.close();\n}\n\nmain();\n"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nasync function cin() {\n return new Promise((resolve, reject) => {\n\trl.on('line', (data) => {\n\t resolve(data);\n\t});\n });\n}\n\nasync function cint() {\n let n = await cin();\n return parseInt(n);\n}\n\nasync function main() {\n let t = await cint();\n while(t--) {\n\tlet n = await cint();\n\tlet ans = n + ' ';\n\tfor(let i = 1; i < n; i++) {\n\t ans += (i + ' ');\n\t}\n\tconsole.log(ans);\n }\n\n rl.close();\n}\n\nmain();\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n/*\n 2\n 5\n\n 2 1\n 2 1 5 3 4\n*/\n\nfunction aaa(n) {\n n = +n;\n // console.log(n);\n\n let A = [];\n for (let i=0; i {\n \n if (i === 0) {\n T = line;\n i++;\n return\n } else {\n aaa(line);\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let res = '';\n for(let i = 1; i <= n; i++){\n if(i !== n){\n res += ` ${i+1}`;\n }else{\n res += ` ${i+1}`;\n }\n }\n\n console.log(res.trim());\n }\n}"}], "src_uid": "f4779e16e0857e6507fdde55e6d4f982"} {"source_code": "var numberOfRoundsPlayed = Number(readline());\n\nvar roundInfo;\nvar scores = {};\nvar scoreLog = [];\nfor(var i = 0; i < numberOfRoundsPlayed; i++) {\n roundInfo = readline();\n roundInfo = roundInfo.split(\" \");\n var player = roundInfo[0];\n var playerScore = parseInt(roundInfo[1]);\n\n if (player in scores) scores[player] += playerScore;\n else scores[player] = playerScore;\n // print(`i: ${i}\\tplayer: ${player}\\tscore: ${playerScore}\\ttotal: ${scores[player]}`);\n\n scoreLog.push([player, scores[player]]);\n}\n\n// print('===');\n// print(`scores: ${JSON.stringify(scores)}`);\n// print(`scoreLog: ${JSON.stringify(scoreLog)}`);\nvar max = -1;\nvar winners = [];\nfor (var p in scores) {\n if (scores[p] > max) {\n max = scores[p];\n winners = [p];\n } else if (scores[p] === max) {\n winners.push(p);\n }\n}\n\nscoreLog.some(e => {\n // print(e);\n if (winners.indexOf(e[0]) > -1 && e[1] >= max) {\n print(e[0]);\n return true;\n }\n})\n", "positive_code": [{"source_code": "var num = Number(readline());\n\nvar round, player, score;\nvar scores = {};\nvar log = [];\nfor(var i = 0; i < num; i++) {\n round= readline().split(\" \");\n player = round[0];\n score = parseInt(round[1]);\n if (player in scores) scores[player] += score;\n else scores[player] = score;\n log.push([player, scores[player]]);\n}\n\nvar playerList = Object.keys(scores);\n\nvar max = scores[playerList.sort((a, b) => scores[b] - scores[a])[0]];\n\nvar winners = playerList.filter(player => scores[player] === max)\n\nlog.some(e => {\n player = e[0]; score = e[1];\n if (winners.includes(player) && score >= max) {\n print(player); return true;\n }\n})"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar mass = []\n\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nvar maxScore = gamers[0].score;\n\n//\u0435\u0441\u043b\u0438 \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445, \u043a\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430 \u0432\u0441\u044e \u0438\u0433\u0440\u0443 \u043d\u0430\u0431\u0440\u0430\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nif(gamers[0].score == gamers[1].score) {\n\t//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0438\u0445 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\n\tvar winners = gamers.filter(function(el){\n\t\treturn el.score == maxScore;\n\t})\n\n\t//\u0443\u0447\u0438\u0442\u0438\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0434\u044b \u0442\u0435\u0445 \u043a\u0442\u043e \u043d\u0430\u0431\u0440\u0430\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0445\u043e\u0434\u043e\u0432\n\tmass = mass.filter(function(el,index,arr){\n\t\tvar ind = winners.findIndex(function(el2,inde2x,arr2){\n\t\t\treturn el2.name == el[0];\n\t\t})\n\t\tif( ind > -1 ) {\n\t\t\treturn true\n\t\t}else{\n\t\t\treturn false\n\t\t}\n\t})\n\n\tvar gamers2 = [];\n\n\n\t//\u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0443\u0440\u043d\u0438\u0440\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435 \u043d\u0430\u0431\u0435\u0440\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0442\u043e\u0442 \u0438 \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[gamers2.length-1].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tgamers2[index].score += parseInt(mass[i][1],10);\n\t\t\tif(gamers2[index].score>= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\t\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "var num = Number(readline());\n\nvar round, player, score;\nvar scores = {};\nvar log = [];\nfor(var i = 0; i < num; i++) {\n round= readline().split(\" \");\n player = round[0];\n score = parseInt(round[1]);\n if (player in scores) scores[player] += score;\n else scores[player] = score;\n log.push([player, scores[player]]);\n}\n\nvar playerList = Object.keys(scores).slice(0);\n\nvar winnerScore = playerList.sort((a, b) => {\n // print(`a: ${a}, score: ${scores[a]}`);\n // print(`b: ${b}, score: ${scores[b]}`);\n return scores[b] - scores[a];\n})[0];\nwinnerScore = scores[winnerScore];\n\n// print(winnerScore)\n\nvar winnerList = playerList.filter(player => {\n return scores[player] === winnerScore;\n})\n\nlog.some(e => {\n if (winnerList.includes(e[0]) && e[1] >= winnerScore) {\n print(e[0]);\n return true;\n }\n})"}, {"source_code": "var num = Number(readline());\n\nvar round, player, score;\nvar scores = {};\nvar log = [];\nfor(var i = 0; i < num; i++) {\n round= readline().split(\" \");\n player = round[0];\n score = parseInt(round[1]);\n if (player in scores) scores[player] += score;\n else scores[player] = score;\n log.push([player, scores[player]]);\n // print(`i: ${i}\\tplayer: ${player}\\tscore: ${playerScore}\\ttotal: ${scores[player]}`);\n}\n\n// print('===');\n// print(`scores: ${JSON.stringify(scores)}`);\n// print(`log: ${JSON.stringify(log)}`);\nvar max = -1;\nvar winners = [];\nfor (player in scores) {\n if (scores[player] > max) {\n max = scores[player];\n winners = [player];\n } else if (scores[player] === max) {\n winners.push(player);\n }\n}\n\nlog.some(e => {\n player = e[0];\n score = e[1];\n if (winners.indexOf(player) > -1 && score >= max) {\n print(player);\n return true;\n }\n})\n"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\nvar maxScore = gamers[0].score;\nif(gamers[0].score == gamers[1].score) {\n\tvar winners = gamers.filter(function(el){\n\t\treturn el.score == maxScore;\n\t})\n\tmass = mass.filter(function(el,index,arr){\n\t\tvar ind = winners.findIndex(function(el2,inde2x,arr2){\n\t\t\treturn el2.name == el[0];\n\t\t})\n\t\tif( ind > -1 ) {\n\t\t\treturn true\n\t\t}else{\n\t\t\treturn false\n\t\t}\n\t})\n\t//write(mass.length);\n\tvar gamers2 = [];\n\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[gamers2.length-1].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tgamers2[index].score += parseInt(mass[i][1],10);\n\t\t\tif(gamers2[index].score>= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\t\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n};\n\nfunction player_points(pps) {\n const m = new Map();\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const pts = get_with_default(m, a, 0) + Number(b);\n m.set(a, pts);\n }\n return m;\n};\n\nfunction players_with_max_points(m) {\n const plyrs = new Set();\n let pts_max = (- Infinity);\n for (const [a, b] of m.entries()) {\n if (b > pts_max) {\n plyrs.clear();\n plyrs.add(a);\n pts_max = b;\n } else if (b === pts_max) {\n plyrs.add(a);\n } else {\n // do nothing ...\n }\n }\n return [pts_max, plyrs];\n};\n\nfunction first_to_reach_max_points(pts_max, plyrs, pps) {\n const m = new Map();\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n if (plyrs.has(a)) {\n const pts = get_with_default(m, a, 0) + Number(b);\n if (pts >= pts_max) {\n return a;\n } else {\n m.set(a, pts);\n }\n }\n }\n throw Error('could not find first to reach max points');\n};\n\nfunction solve(pps) {\n const m = player_points(pps);\n const [pts_max, plyrs] = players_with_max_points(m);\n if (plyrs.size === 1) {\n return plyrs.values().next().value;\n } else {\n return first_to_reach_max_points(pts_max, plyrs, pps)\n }\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n};\n\nfunction player_points(pps) {\n const m = new Map();\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const a_pts = get_with_default(m, a, 0) + Number(b);\n m.set(a, a_pts);\n }\n return m;\n};\n\nfunction players_with_max_points(m) {\n const ps = new Set();\n let p_max = (- Infinity);\n for (const [a, b] of m.entries()) {\n if (b > p_max) {\n ps.clear();\n ps.add(a);\n p_max = b;\n } else if (b === p_max) {\n ps.add(a);\n } else {\n // do nothing ...\n }\n }\n return [p_max, ps];\n};\n\nfunction first_to_reach_max_points(pts_max, ps, pps) {\n const m = new Map();\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n if (ps.has(a)) {\n const a_pts = get_with_default(m, a, 0) + Number(b);\n if (a_pts >= pts_max) {\n return a;\n } else {\n m.set(a, a_pts);\n }\n }\n }\n throw Error('could not find first to reach max points');\n};\n\nfunction solve(pps) {\n const m = player_points(pps);\n const [pts_max, ps] = players_with_max_points(m);\n if (ps.size === 1) {\n return ps.values().next().value;\n } else {\n return first_to_reach_max_points(pts_max, ps, pps)\n }\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "// http://codeforces.com/problemset/problem/2/A\n// A. \u041f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\n\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n let firstPass = {};\n\n for (let i = 1; i < input.length; i++) {\n let [name, score] = input[i].split(' ');\n\n if (!firstPass.hasOwnProperty(name)) {\n firstPass[name] = +score;\n } else {\n firstPass[name] += Number(score);\n }\n }\n\n // console.log('firstPass', firstPass);\n\n let maxScore = 0;\n const keys = Object.keys(firstPass);\n for (let i = 0; i < keys.length; i++) {\n if (firstPass[keys[i]] > maxScore) maxScore = firstPass[keys[i]];\n }\n\n // console.log('maxScore', maxScore)\n\n let secondPass = {};\n let winner = null;\n for (let i = 1; i < input.length; i++) {\n let [name, score] = input[i].split(' ');\n\n if (!secondPass.hasOwnProperty(name)) {\n secondPass[name] = +score;\n } else {\n secondPass[name] += Number(score);\n }\n\n if(secondPass[name] >= maxScore && firstPass[name] >= maxScore) {\n winner = name;\n break;\n }\n }\n\n // console.log('secondPass', secondPass);\n\n console.log(winner);\n\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!(name in prev)) {\n prev[name] = {\n pts: 0,\n rnd: 0,\n max: -1,\n history: [],\n set lastRound(val) {\n const p = this.pts + val;\n if (p > this.max) {\n this.max = p;\n this.rnd = this.currentRound;\n }\n this.pts = p;\n this.history.push({pts: p, rnd: this.currentRound});\n }\n };\n }\n prev[name].currentRound = i;\n prev[name].lastRound = parseInt(points);\n return prev;\n }, {});\n // console.log(results);\n\n const winners = [];\n let winner = '';\n let max = -1;\n let rnd = 0;\n for (let name in results) {\n if (results[name].pts > max) {\n max = results[name].pts;\n winner = name;\n rnd = results[name].rnd;\n } else if (results[name].pts === max) {\n const r1 = results[name].history.find(h => h.pts >= max);\n const r2 = results[winner].history.find(h => h.pts >= max);\n if (r1.rnd < r2.rnd) winner = name;\n }\n }\n return winner;\n}\n"}, {"source_code": "run();\n\nfunction run() {\n var scores = scoreboard();\n\n var lines = Number(readline()),\n log = [],\n line;\n for (var i = 0; i < lines; i++) {\n line = readline();\n log.push(line);\n scores.addScore.apply(null, line.split(' '));\n }\n\n var result = scores.result();\n\n print(getWinner(log, result.winners, result.hiscore));\n}\n\n\nfunction scoreboard() {\n var scores = {};\n return {\n // record a round\n addScore: function(player, score) {\n score = Number(score);\n if (!scores[player]) scores[player] = score;\n else scores[player] += score;\n },\n result: function() {\n var players = Object.getOwnPropertyNames(scores),\n player,\n hiscore = -Infinity;\n\n // iterate through the scores object to find the highest score\n for (i = 0; i < players.length; i++) {\n player = players[i];\n hiscore = Math.max(hiscore, scores[player]);\n }\n\n // find the players that have the highest score\n var winners = [];\n for (i = 0; i < players.length; i++) {\n player = players[i];\n if (scores[player] === hiscore) winners.push(player);\n }\n\n return {\n hiscore: hiscore,\n winners: winners\n };\n },\n\n }\n}\n\nfunction getWinner(logs, winners, hiscore) {\n var scores = {},\n line, player, score;\n for (var i = 0; i < logs.length; i++) {\n line = logs[i].split(' ');\n player = line[0];\n score = Number(line[1]);\n\n if (!scores[player]) scores[player] = score;\n else scores[player] += score;\n\n if (scores[player] >= hiscore && winners.indexOf(player) !== -1) return player;\n }\n}\n"}, {"source_code": "/*\n Modification test of the solution\noriginally coded by aleksey.danchin.\n*/\n\nvar n = readline(), m = {}, t = [], r = [], k, y, s;\n\nwhile (n--) {\n\ts = readline().split(' ');\n\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\tt.push([s[0], m[s[0]]]);\n}\n\nfor (y in m) r.push(m[y]);\nk = Math.max(...r);\n\nprint(t.find(e => e[1] >= k && m[e[0]] === k)[0]);\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\nconst last = array => array[array.length - 1];\n\nconst table = [];\nlet n, counter = 0;\n\nrl.on('line', line => {\n\tif (!n) {\n\t\tn = parseInt(line);\n\t} else {\n\t\tconst [name, resS] = line.split(' ');\n\t\tconst res = parseInt(resS);\n\n\t\tlet userIndex = table.findIndex(i => i.name === name);\n\t\tif (userIndex < 0) {\n\t\t\tuserIndex = table.length;\n\t\t\ttable.push({\n\t\t\t\tname,\n\t\t\t\tlog: [],\n\t\t\t\tscore: res\n\t\t\t});\n\t\t\ttable[userIndex].log[counter] = res;\n\t\t} else {\n\t\t\tconst log = table[userIndex].log;\n\t\t\tconst score = last(log) + res;\n\t\t\ttable[userIndex].score = score;\n\t\t\ttable[userIndex].log[counter] = score;\n\t\t}\n\n\t\tcounter++;\n\t\tif (counter === n) {\n\t\t\tlet max = 0;\n\t\t\tfor (let i = 0; i < table.length; i++) {\n\t\t\t\tif (table[i].score > max) {\n\t\t\t\t\tmax = table[i].score;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst winners = table.filter(i => i.score === max);\n\t\t\tif (winners.length === 1) {\n\t\t\t\tconsole.log(winners[0].name);\n\t\t\t} else {\n\t\t\t\tconsole.log(\n\t\t\t\t\twinners.map(i => {\n\t\t\t\t\t\ti.first = i.log.findIndex(j => j && j >= max);\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}).sort((a, b) => {\n\t\t\t\t\t\tif (a.first < b.first) {\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (a.first > b.first) {\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t})[0].name\n\t\t\t\t);\n\t\t\t}\n\t\t\trl.close();\n\t\t}\n\t}\n});\n"}, {"source_code": "const solve = (t, players) => {\n let map = new Map();\n for (let i = 0; i < t; i++) {\n let p = players[i];\n if (map.has(p[0])) {\n map.set(p[0], p[1] + map.get(p[0]));\n } else {\n map.set(p[0], p[1]);\n }\n }\n let sMap = sortMap(map, players);\n return sMap.keys().next().value;\n};\n\nconst sortMap = (map, players) => { // sort map based on value, if value same, sort based on index who scored at least m points first\n return new Map([...map].sort((a, b) => {\n if (a[1] == b[1]) {\n let score = a[1];\n let aIdx;\n let bIdx;\n let aSum = 0;\n let bSum = 0;\n for (let i = 0; i < players.length; i++) {\n let p = players[i];\n if (i == players.length - 1) aIdx = i;\n if (aSum >= score) {\n aIdx = i - 1;\n break;\n }\n if (p[0] == a[0]) {\n aSum += p[1];\n }\n }\n for (let i = 0; i < players.length; i++) {\n let p = players[i];\n if (i == players.length - 1) bIdx = i;\n if (bSum >= score) {\n bIdx = i - 1;\n break;\n }\n if (p[0] == b[0]) {\n bSum += p[1];\n }\n }\n return aIdx - bIdx;\n }\n return b[1] - a[1];\n }));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \"));\n });\n\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let players = input.slice(1).map(x => [x[0], Number(x[1])]);\n console.log(solve(t, players));\n });\n\n};\n\nmain()"}, {"source_code": "const solve = (t, players) => {\n let map = new Map();\n for (let i = 0; i < t; i++) {\n let p = players[i];\n if (map.has(p[0])) {\n map.set(p[0], p[1] + map.get(p[0]));\n } else {\n map.set(p[0], p[1]);\n }\n }\n let sMap = sortMapByKey(map, players);\n return sMap.keys().next().value;\n};\n\nconst sortMapByKey = (map, players) => {\n return new Map([...map].sort((a, b) => {\n if (a[1] == b[1]) {\n let score = a[1];\n let aIdx;\n let bIdx;\n let aSum = 0;\n let bSum = 0;\n for (let i = 0; i < players.length; i++) {\n let p = players[i];\n if (i == players.length - 1) aIdx = i;\n if (aSum >= score) {\n aIdx = i - 1;\n break;\n }\n if (p[0] == a[0]) {\n aSum += p[1];\n }\n }\n for (let i = 0; i < players.length; i++) {\n let p = players[i];\n if (i == players.length - 1) bIdx = i;\n if (bSum >= score) {\n bIdx = i - 1;\n break;\n }\n if (p[0] == b[0]) {\n bSum += p[1];\n }\n }\n return aIdx - bIdx;\n }\n return b[1] - a[1];\n }));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \"));\n });\n\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let players = input.slice(1).map(x => [x[0], Number(x[1])]);\n console.log(solve(t, players));\n });\n\n};\n\nmain()"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar finalScores = {};\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n finalScores[name] = (finalScores[name] || 0) + roundScore;\n }\n}\n\n// find maxScore of finalScores\nvar maxScore = Object.keys(finalScores).reduce(function(acc, name) {\n return Math.max(acc, finalScores[name]);\n}, 0);\n\n// first player with at least maxScore\nvar scores = {};\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n if (finalScores[name] !== maxScore) {\n continue;\n }\n\n scores[name] = (scores[name] || 0) + roundScore;\n if (scores[name] >= maxScore) {\n print(name);\n break;\n }\n }\n}\n"}, {"source_code": "var i = ''\nvar lines = [];\nvar N = 0;\nvar arr = [];\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\nfunction debug(item) {\n if (N == 5) console.log(item);\n}\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n debug(lines.length);\n debug(lines);\n N = readline() - 0;\n arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n \n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let [username, newPoint] = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : newPoint;\n hash[username] = point;\n rounds.push({\n username, point\n })\n }\n\n let keys = Object.keys(hash);\n let values = keys.map(k => hash[k]);\n max = Math.max.apply(null, values);\n \n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n \n debug(rounds);\n debug(candidates);\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {};\nvar scores = {}; // map score to players with that score in chron order\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n // remove player from old score list\n var oldScore = players[name];\n if (Number.isInteger(oldScore)) {\n var playersList = scores[oldScore.toString()];\n if (Array.isArray(playersList)) {\n var nameIndex = playersList.indexOf(name);\n if (nameIndex !== -1) {\n playersList.splice(nameIndex, 1);\n if (playersList.length == 0) {\n // remove from scores hash\n delete scores[oldScore.toString()];\n }\n }\n }\n }\n\n oldScore = oldScore || 0;\n var newScore = oldScore + roundScore;\n\n // update score\n players[name] = newScore;\n scores[newScore.toString()] = scores[newScore.toString()] || [];\n scores[newScore.toString()].push(name);\n }\n}\n\n// list of players ending with max score\nvar scoresList = Object.keys(scores);\nif (scoresList.length > 0) {\n scoresList.sort(function(a, b) {\n return parseInt(b) - parseInt(a);\n });\n var maxScore = scoresList[0];\n var playersList = scores[maxScore];\n}\n\n// first player with at least max roundScore\nvar finalPlayers = {};\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n if (playersList.indexOf(name) !== -1) {\n finalPlayers[name] = finalPlayers[name] || 0;\n finalPlayers[name] += roundScore;\n\n if (finalPlayers[name] >= maxScore) {\n print(name);\n break;\n }\n }\n }\n}\n"}, {"source_code": "var N = readline() - 0;\n//var N = 3;\n\nvar originalData = [];\n//var originalData = [ [\"mike\",\"3\"] , [\"andrew\" , \"5\"] , [\"mike\" , \"2\"]] ; \n\nvar initHash = {};\n\nvar bestKey;\n\nfor (var i = 0 ; i < N ; i++)\n{\n originalData[i] = readline().split(' ');\n var name = originalData[i][0];\n var scoreDelt = parseInt(originalData[i][1]);\n \n initHash[ name ] = (initHash[name] || 0 ) + scoreDelt;\n \n if (initHash[name] > (initHash[bestKey] || -1<<63))\n {\n bestKey = name;\n }\n}\n\nfor (var i = 0 ; i < N ; i++)\n{\n var name = originalData[i][0];\n if (initHash[name] > (initHash[bestKey] || -1<<63))\n {\n bestKey = name;\n }\n}\n\nvar secondHash = {};\nvar BestScore = initHash[bestKey];\nvar winner = \"\";\ndebugger;\n\nfor (var i = 0 ; i < N ; i++)\n{ \n var name = originalData[i][0]; \n var scoreDelt = parseInt(originalData[i][1]);\n \n var current = (secondHash[name] || 0) + scoreDelt; \n secondHash[name] = current;\n \n if (current >= BestScore && BestScore == initHash[name] )\n {\n winner = name;\n break;\n } \n}\n\nprint(winner);\n//console.log(winner);"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\nvar points = [];\nvar names = [];\nfor(var i=0; i max ){\n\t\tmax = p;\n\t}\n}\n\nvar map2 = {}\nfor(var i=0;i=max){\n\t\tprint( names[i] );\n\t\tbreak;\n\t}\n}"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[key] = key;\n //print(\"name=\"+key);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n //print(\" found highestScore with name: \"+name);\n if (names[name]) {\n //print(\" .. AND they are a winner.\");\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": "t = parseInt(readline());\n\ni = 0;\nrounds = [];\nscores = {};\n\nfor(round=0; round Math.max(a,scores[b]), Number.NEGATIVE_INFINITY\n);\n\nconst bestScorers = Object.keys(scores).filter(player => scores[player] == max);\n\nwinner = null;\nscores = {};\n\nfor(round=0; round= max) winner = player;\n }\n}\n\nprint(winner);"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn();\nvar inp = [];\nfor(var i = 0; i < n; i++){\n var x = readline().split(\" \");\n x[1] = Number(x[1]);\n inp.push(x);\n}\n\nvar game = {};\nfor(var i = 0; i < n; i++){\n if(!game[inp[i][0]]){\n game[inp[i][0]] = inp[i][1];\n }else{\n game[inp[i][0]] += inp[i][1];\n }\n}\n\nvar max = -Infinity;\nvar winners = [];\nfor(var name in game){\n max = Math.max(max, game[name]);\n}\nfor(var name in game){\n if(game[name] == max) winners.push(name);\n}\ndelete game;\n\nvar game2 = {};\nfor(var i = 0; i < n; i++){\n if(!game2[inp[i][0]]){\n game2[inp[i][0]] = inp[i][1];\n }else{\n game2[inp[i][0]] += inp[i][1];\n }\n if(game2[inp[i][0]] >= max && winners.indexOf(inp[i][0]) != -1){\n write(inp[i][0]);\n break;\n }\n}"}, {"source_code": "var n = +readline();\n\nvar userScores = {}, userRounds = [], maxScore = 0, firstUsers = {};\n\nfor (var i = 0; i < n; i++) {\n var arr = readline().split(' '),\n name = arr[0],\n score = +arr[1];\n \n var newScore = (userScores[name] || 0) + score;\n userScores[name] = newScore;\n \n userRounds[i] = {\n name : name,\n score : newScore\n }\n \n}\n\n//console.log(userScores, userRounds);\n\nvar maxScore = 0, bestUsers = [], bestUserRounds = 0;\nfor (var name in userScores) {\n if (userScores[name] > maxScore) {\n maxScore = userScores[name];\n bestUsers = [name];\n } else if (userScores[name] === maxScore) {\n bestUsers.push(name);\n }\n}\n\n//console.log(userRounds);\n\nif (bestUsers.length === 1) print(bestUsers[0]);\nelse {\n for (var i =0, l = userRounds.length; i < l; i++) {\n if (bestUsers.indexOf(userRounds[i].name) >= 0 && userRounds[i].score >= maxScore) {\n print(userRounds[i].name);\n break;\n }\n }\n}"}, {"source_code": "main();\n\nfunction main() {\n const count = readline();\n var players = {};\n var playersEnd = {};\n var turns = [];\n var winner = \"\";\n for (var i = 0; i < count; i++) {\n var nameScore = readline().split(\" \");\n var name = nameScore[0];\n var score = +nameScore[1];\n players[name] = players[name] ? players[name] + score : score;\n turns.push(nameScore);\n }\n \n var maxScore = Object.keys(players).reduce( (max, player) => {\n return max = players[player] > max ? players[player] : max;\n }, 0);\n \n for (var i = 0; i < turns.length; i++) {\n var nameEnd = turns[i][0];\n var scoreEnd = +turns[i][1];\n playersEnd[nameEnd] = playersEnd[nameEnd] ? playersEnd[nameEnd] + scoreEnd : scoreEnd;\n if (playersEnd[nameEnd] >= maxScore && players[nameEnd] === maxScore) {\n winner = nameEnd;\n break;\n }\n }\n print(winner);\n}"}, {"source_code": ";(function () {\n\tvar n = +readline(), m = {}, t = [], k = 0;\n\n\twhile (n--) {\n\t\tvar s = readline().split(' ');\n\t\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\t\tt.push([s[0], m[s[0]]]);\n\t}\n\n\tk = Math.max.apply(null, (function () {\n\t\tvar ret = [];\n\t\tfor (var key in m) ret.push(m[key]);\n\t\treturn ret;\n\t})());\n\n\tprint(t.filter(function (e) { return e[1] >= k && m[e[0]] === k; })[0][0]);\n\n}).call(this)"}, {"source_code": " var n = +readline()\n var rs = []\n var v\n for (var t = 0; t < n; t++) {\n rs.push(readline().split(' '))\n }\n var sc = rs.reduce(function (a, l) {\n a[l[0]] = (a[l[0]] || 0) + +l[1]\n return a\n }, {})\n var ms = 0\n var mso = {}\n for (var p in sc) {\n if (sc[p] > ms) {\n mso = {}\n mso[p] = true\n ms = sc[p]\n } else if (sc[p] == ms) {\n mso[p] = true\n }\n }\n var vs = Object.keys(mso)\n if (vs.length == 1)\n v = vs[0]\n if (!v) {\n sc = {}\n for (t = 0; t < n; t++) {\n p = rs[t][0]\n s = +rs[t][1]\n if (((sc[p] = (sc[p] || 0) + s) >= ms) && mso[p]) {\n v = p\n break\n }\n }\n }\n print(v)"}, {"source_code": "const n = parseInt(readline());\nconst tour = [];\nconst gamers = {};\nconst gamers2 = {};\nfor(var i = 0; i < n; i++) {\n var ans = readline().split(' ');\n tour.push({ name: ans[0], value: parseInt(ans[1]) });\n}\ntour.forEach(item => {\n const name = item.name, value = item.value;\n gamers[name] = gamers[name] ? gamers[name] + value : value;\n});\nvar max = 0;\nfor(var key in gamers) {\n max = gamers[key] > max ? gamers[key] : max;\n}\nfor(var i = 0; i < n; i++) {\n var name = tour[i].name, value = tour[i].value;\n gamers2[name] = gamers2[name] ? gamers2[name] + value : value;\n if(gamers[name] === max && gamers2[name] >= max) {\n print(name);\n break;\n }\n}"}, {"source_code": "var intGamesCount=Number(readline().trim());\n//print('intGamesCount:'+intGamesCount);\nvar arrPlayers=[];\nvar arrScores=[];\nvar arrGames=[];\nvar strName='';\nvar intGameScore=0;\nvar intBestScore=0;\nvar i=0; // Current player index\nvar s='';\nvar arrGame=['',0];\nvar arrPlayerGames=[''];\nvar arrPretenders=[];\n\nfor (var intGame=0;intGameintBestScore) {\n// arrGames[i]=arrScores[i]+':'+intGame+':'+arrGames[i];\n arrGames[i].push([arrScores[i],intGame]);\n// print('arrGames[i]:'+arrGames[i]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][i][1]intBestScore) {\n arrGames[i].push([arrScores[i],intGame]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][i][1]intBestScore) {\n// arrGames[i]=arrScores[i]+':'+intGame+':'+arrGames[i];\n arrGames[i].push([arrScores[i],intGame]);\n// print('arrGames[i]:'+arrGames[i]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][j][1]intBestScore) {\n// arrGames[i]=arrScores[i]+':'+intGame+':'+arrGames[i];\n arrGames[i].push([arrScores[i],intGame]);\n// print('arrGames[i]:'+arrGames[i]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][j][1]max) {\n\t\tmax=score[name];\n\t\ttop={};\n\t\ttop[name]=true;\n\t} else if (score[name]==max)\n\t\ttop[name]=true;\n}\nfor (name in score) score[name]=0;\nfor (i=0;i=max) {\n\t\t\tprint(line[i][0]);\n\t\t\tbreak;\n\t\t}\n\t}\n"}, {"source_code": "var c = parseInt( readline() );\n\nvar map = {};\nvar points = [];\nvar names = [];\nfor(var i=0; i max ){\n\t\tmax = p;\n\t}\n}\n\nvar map2 = {}\nfor(var i=0;i=max){\n\t\tprint( names[i] );\n\t\tbreak;\n\t}\n}"}, {"source_code": "rounds = parseInt(readline())\n\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + splitItem[1] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\n//print(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] >= highestTotalScore && scores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore >= highestTotalScore && scores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } \n }\n}\n\nprint(winner.name)"}, {"source_code": "function main()\n{\n xh={};\n line=[];\n var ans;\n n=Number(readline());\n for(i=1;i<=n;i++)\n {\n line[i]=readline().split(\" \");\n line[i][1]=Number(line[i][1]);\n if(line[i][0] in xh) xh[line[i][0]]+=line[i][1];\n else xh[line[i][0]]=line[i][1];\n }\n maxs=Number(-1);\n for(name in xh)\n {\n if(xh[name]>maxs) maxs=xh[name];\n //print(name,xh[name]);\n }\n for(name in xh)\n if(xh[name]=maxs) {ans=line[i][0];break;}\n }\n print(ans);\n}\nmain();"}, {"source_code": "var n = parseInt(readline());\nvar i, r, s = {}, h = [], w = [], max = 0;\n\nfunction get_winners() {\n for (var u in s) {\n if (!w.length){\n w.push(u);\n max = s[u];\n } else {\n if (s[u] > max) {\n max = s[u];\n w = [u];\n } else if (s[u] === max) {\n w.push(u);\n }\n }\n }\n\n if (w.length === 1) return w[0];\n for (var i=0; i -1 && h[i][1] >= max){\n return h[i][0];\n }\n }\n}\n\nfor (i=0; i f) {\n g = c;\n } else {\n g = e;\n }\n}\n\nprint(g);"}, {"source_code": "function main()\n{\n xh={};\n line=[];\n var ans;\n n=Number(readline());\n for(i=1;i<=n;i++)\n {\n line[i]=readline().split(\" \");\n line[i][1]=Number(line[i][1]);\n if(line[i][0] in xh) xh[line[i][0]]+=line[i][1];\n else xh[line[i][0]]=line[i][1];\n }\n maxs=Number(-1);\n for(name in xh)\n {\n if(xh[name]>maxs) maxs=xh[name];\n //print(name,xh[name]);\n }\n for(name in xh)\n if(xh[name] f) {\n e = c[d - 1][0];\n f = c[d - 1][1];\n }\n }\n d = c.length;\n for (; d; d--) {\n if (c[d - 1][0] === b[0]) {\n c[d - 1][1] = c[d - 1][1] + +b[1];\n break;\n }\n }\n }\n if (!d) {\n c.push([b[0],+b[1]]);\n }\n}\n\nprint(e);"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn();\nvar game = {};\n\nvar max = -Infinity;\nvar winner;\nfor(var i = 0; i < n; i++){\n var inp = readline().split(\" \"), name = inp[0], score = Number(inp[1]);\n delete inp;\n if(!game[name]){\n game[name] = score;\n }else{\n game[name] += score;\n }\n\n if(max < game[name]){\n max = game[name];\n winner = name;\n }\n}\n\nwrite(winner);"}, {"source_code": "var a = readline(), b, c = '', d = 0, e = '', f = 0, g;\n\nfor (; a; a--) {\n b = readline().split(' ');\n if (c === '') {\n c = b[0];\n d = +b[1];\n } else if (e === '') {\n e = b[0];\n f = +b[1];\n } else if (c === b[0]) {\n d = d + +b[1];\n } else if (e === b[0]) {\n f = f + +b[1];\n }\n if (d > f) {\n g = c;\n } else {\n g = e;\n }\n}\n\nprint(g);"}, {"source_code": "\nvar n = parseInt( readline() );\n\nvar hash = {};\nvar arr = [];\n\nfor(var r=1; r<=n; r++){\n\tvar a = readline().split(' ');\n\tvar name = a[0];\n\tvar point = parseInt(a[1]);\n\tif( a = hash['$'+name] ){\n\t\ta.point = parseInt(a.point+point);\n\t}else{\n\t\ta=hash['$'+name] = {\n\t\t\tname: name,\n\t\t\tpoint: point,\n\t\t\tr:r\n\t\t}\n\t}\n}\nfor(var key in hash){\n\tarr.push(hash[key].point);\n}\nvar max = Math.max.apply(null, arr);\narr = [];\nfor(var key in hash){\n\tif(hash[key].point == max ){\n\t\tarr.push(hash[key]);\n\t}\n}\narr.sort(function(a,b){\n\treturn a.rgamers[index].max)gamers[index].max = gamers[index].score\n\t}\n\tsortGamers();\n\t//debug();\n}\nfunction sortGamers() {\n\tgamers.sort(function(a,b){\n\t\tif(a.scoreb.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n\n}\nfunction debug (){\n\tfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) {\n\t\t\tif(a.maxb.max) return -1;\n\t\t\tif(a.max==b.max) return 0;\n\t\t}\n\t})\nwrite(gamers[0].name);"}, {"source_code": "\nvar all = parseInt( readline() );\n\nvar hash = {};\n\nvar winner = {\n\tname:'',\n\tpoint:0\n}\nfor(var r=1; r<=all; r++){\n\tvar a = readline().split(' ');\n\tvar name = a[0];\n\tvar point = parseInt(a[1]);\n\tif( a = hash['$'+name] ){\n\t\ta.point += point;\n\t}else{\n\t\ta=hash['$'+name] = {\n\t\t\tname: name,\n\t\t\tpoint: point\n\t\t}\n\t}\n\n\tif(a.point>winner.point){\n\t\twinner = {\n\t\t\tname:a.name,\n\t\t\tpoint:a.point\n\t\t}\n\t}\n}\nprint(winner.name);"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\nvar maxScore = gamers[0].score;\nif(gamers[0].score == gamers[1].score) {\n\tvar gamers2 = [];\n\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "rounds = parseInt(readline())\n\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\nprint(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n }\n \n }\n}\nprint(winner.name)\n\n//print(winner.name)"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n let max = 0;\n let winner = '';\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!(name in prev)) prev[name] = {pts: 0, rnd: 0};\n prev[name].pts += parseInt(points);\n prev[name].rnd = i;\n if (prev[name].pts > max) {\n max = prev[name].pts;\n winner = name;\n }\n return prev;\n }, {});\n console.log(results);\n return winner;\n}\n"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[name] = name;\n //print(\"name=\"+name);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n if (names[name]) {\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": "rounds = parseInt(readline())\n\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\nprint(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n }\n \n }\n}\nprint(winner.name)\n\n//print(winner.name)"}, {"source_code": "var name=new Array(1010);\nvar score=new Array(1010);\nvar edge=[];\nvar head=new Array(1010);\nvar cnt;\nfunction init()\n{\n var i;\n for(i=1;i<=1000;i++) head[i]=-1;\n return;\n}\nfunction add(u,v,str)\n{\n edge[cnt].name=str;edge[cnt].val+=v;edge[cnt].next=head[u];\n head[u]=cnt++;\n return cnt-1;\n}\nfunction find(num,name)\n{\n var i;\n for(i=head[num];i!=-1;i=edge[i].next)\n {\n if(edge[i].name==name) return i;\n }\n return 0;\n}\nfunction str_hash(s)\n{\n var i,sum=0;\n for(i=0;i<=s.length-1;i++)\n {\n var tmp=s[i].charCodeAt()-'a'.charCodeAt();\n sum+=tmp*tmp;\n }\n return sum%997+1;\n}\nfunction obj(val,name,next)\n{\n this.val=val;this.name=name;this.next=next;\n}\nfunction main()\n{\n var i;\n init(head,-1);cnt=0;\n for(i=0;i<=1000;i++) edge.push(new obj(0,\"\",0));\n var maxs=-1;\n var n=readline();\n for(i=1;i<=n;i++)\n {\n var tmp=readline().split(' ');\n name[i]=tmp[0];score[i]=Number(tmp[1]);\n var index=str_hash(name[i]);\n var ret=find(index,name[i]);\n if(!ret) ret=add(index,score[i],name[i]);\n else edge[ret].val+=score[i];\n if(edge[ret].val>maxs) maxs=edge[ret].val;\n }\n for(i=1;i<=1000;i++) edge[i].val=0;\n var ans;\n for(i=1;i<=n;i++)\n {\n index=str_hash(name[i]);\n ret=find(index,name[i]);\n edge[ret].val+=score[i];\n if(edge[ret].val>=maxs)\n {\n ans=edge[ret].name;\n break;\n }\n }\n print(ans);\n}\nmain();"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {};\nvar scores = {}; // map score to players with that score in chron order\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n // remove player from old score list\n var oldScore = players[name];\n if (Number.isInteger(oldScore)) {\n var playersList = scores[oldScore.toString()];\n if (Array.isArray(playersList)) {\n var nameIndex = playersList.indexOf(name);\n if (nameIndex !== -1) {\n playersList.splice(nameIndex, 1);\n if (playersList.length == 0) {\n // remove from scores hash\n delete scores[oldScore.toString()];\n }\n }\n }\n }\n\n oldScore = oldScore || 0;\n var newScore = oldScore + roundScore;\n\n // update score\n players[name] = newScore;\n scores[newScore.toString()] = scores[newScore.toString()] || [];\n scores[newScore.toString()].push(name);\n }\n}\n\nvar scoresList = Object.keys(scores);\nif (scoresList.length > 0) {\n scoresList.sort(function(a, b) {\n return parseInt(b) - parseInt(a);\n });\n var maxScore = scoresList[0];\n var playersList = scores[maxScore];\n if (playersList.length > 0) {\n print(playersList[0]);\n }\n}\n\nprint(JSON.stringify(scores));\n"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\nvar maxScore = gamers[0].score;\nif(gamers[0].score == gamers[1].score) {\n\tvar gamers2 = [];\n\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "var intGamesCount=Number(readline().trim());\n//print('intGamesCount:'+intGamesCount);\nvar arrPlayers=[];\nvar arrScores=[];\nvar arrGames=[];\nvar strName='';\nvar intGameScore=0;\nvar intBestScore=0;\nvar i=0; // Current player index\nvar s='';\nvar arrGame=['',0];\nvar arrPlayerGames=[''];\nvar arrPretenders=[];\n\nfor (var intGame=0;intGameintBestScore) {\n// arrGames[i]=arrScores[i]+':'+intGame+':'+arrGames[i];\n arrGames[i].push([arrScores[i],intGame]);\n// print('arrGames[i]:'+arrGames[i]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][i][1] 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\n//print(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] >= highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore >= highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } \n }\n}\n\nif (startingRounds == 50)\n{\n for (item in inputs) {\n print(inputs[item])\n }\n}\n\nprint(winner.name)"}, {"source_code": "var a = +readline() + 1, b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n d = c.length;\n if (d) {\n\t if (d === 1) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n\t\t}\n for (; d; d--) {\n if (+c[d - 1][1] > f) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n }\n }\n\tif (b = readline()) {\n\t b = b.split(' ');\n\t\td = c.length;\n\t\tfor (; d; d--) {\n\t\t\tif (c[d - 1][0] === b[0]) {\n\t\t\t\tc[d - 1][1] = c[d - 1][1] + +b[1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n if (!d && +b[1] > 0) {\n c.push([b[0],+b[1]]);\n }\n\t}\n}\n\nprint(e);"}, {"source_code": "var n = parseInt(readline());\nvar names = [];\nvar points = [];\nvar map = {};\nvar map2 = {};\nvar max = -1E9;\nwhile (n--) {\n\tvar line = readline().split(' ');\n\tvar name = line[0];\n\tvar point = parseInt(line[1]);\n\n\tnames.push(name);\n\tpoints.push(point);\n}\n\n\n/** \u6c42\u5f97\u6700\u5927\u503cmax */\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map[key]) {\n\t\tmap[key] += point;\n\t} else {\n\t\tmap[key] = point;\n\t}\n\tif (map[key] > max) {\n\t\tmax = map[key];\n\t}\n}\n\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map2[key]) {\n\t\tmap2[key] += point;\n\t} else {\n\t\tmap2[key] = point;\n\t}\n\tif (map[key] == max && map2[key] >= max) {\n\t\tprint(names[i]);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\nvar maxScore = gamers[0].score;\nvar gamers = [];\n\nfor(var i=0;i= maxScore;\n\t})\n\tif(index > -1) {\n\t\twrite(gamers[index].name);\n\t\tbreak;\n\t} \n}\n"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {};\nvar maxScore = 0;\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n players[name] = (players[name] || 0) + roundScore;\n if (players[name] > maxScore) {\n maxScore = players[name];\n }\n }\n}\n\n// first player with at least maxScore\nplayers = {};\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n players[name] = (players[name] || 0) + roundScore;\n if (players[name] >= maxScore) {\n print(name);\n break;\n }\n }\n}\n"}, {"source_code": "var i = ''\nvar lines = [];\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n console.log(lines.length);\n console.log(lines);\n let N = readline() - 0;\n let arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n console.log('arr');\n console.log(arr);\n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let {username, newPoint} = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : hash[username];\n hash[username] = point;\n rounds.push({\n username, point\n })\n max = Math.max(max, point);\n }\n\n let keys = Object.keys(hash);\n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n \n console.log(rounds);\n console.log(candidates);\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "var n = parseInt(readline());\nvar i, r, s = {}, max = ['', -1001];\nfor (i=0; i max[1]) {\n max[0] = r[0];\n max[1] = s[r[0]];\n }\n}\n\nprint(max[0]);"}, {"source_code": "const solve = (t, players) => {\n let map = new Map();\n for (let i = 0; i < t; i++) {\n let p = players[i];\n if (p[1] < 0) {\n map.delete(p[0]);\n } else {\n if (map.has(p[0])) {\n map.set(p[0], [map.get(p[0])[0] + p[1], i + 1]);\n } else {\n map.set(p[0], [p[1], i + 1]);\n }\n }\n }\n let sMap = sortMapByKey(map);\n return sMap.keys().next().value;\n};\n\nconst sortMapByKey = (map) => {\n return new Map([...map].sort((a, b) => {\n if (a[1][0] == b[1][0]) return a[1][1] - b[1][1];\n return b[1][0] - a[1][0];\n }));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \"));\n });\n\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let players = input.slice(1).map(x => [x[0], Number(x[1])]);\n console.log(solve(t, players));\n });\n\n};\n\nmain()"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n}\n\nfunction solve(pps) {\n const m = new Map();\n let time = 0;\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const [a_time, a_pts] = get_with_default(m, a, [time, 0]);\n const a_pts_now = a_pts + Number(b);\n m.set(a, [time, a_pts_now]);\n time = time + 1;\n }\n let p_max = undefined;\n let pts_max = undefined;\n let pts_time = undefined;\n for (const [a, [a_time, a_pts]] of m.entries()) {\n if (p_max === undefined) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else {\n if (a_pts > pts_max) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else if (a_pts === pts_max) {\n if (a_time < pts_time) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n }\n } else {\n // do nothing ...\n }\n }\n }\n return p_max;\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "var numberOfRoundsPlayed = readline();\n\nvar roundInfo;\nvar scores = {};\nvar scoreLog = [];\nfor(var i = 0; i < numberOfRoundsPlayed; i++) {\n roundInfo = readline();\n roundInfo = roundInfo.split(\" \");\n var player = roundInfo[0];\n var playerScore = parseInt(roundInfo[1]);\n\n if (!scores[player]) scores[player] = 0;\n scores[player] += playerScore;\n\n scoreLog.push([player, scores[player]]);\n}\n\nvar winnerScore = Object.keys(scores).sort((a, b) => {\n return scores[a] < scores[b];\n})[0];\nwinnerScore = scores[winnerScore];\n\nvar winnerList = Object.keys(scores).filter(player => {\n return scores[player] === winnerScore;\n})\n\nscoreLog.some(e => {\n if (winnerList.includes(e[0]) && e[1] === winnerScore) {\n print(e[0]);\n return true;\n }\n})\n"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tvar m = {};\n\tvar t = [];\n\tvar l = '';\n\tvar k = 0;\n\n\twhile (n--) {\n\t\tvar s = readline().split(' ');\n\t\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\t\tk = Math.max(k, m[s[0]]);\n\t\tt.push([s[0], m[s[0]]]);\n\t}\n\n\tt = t.filter(function (e) { return e[1] >= k; });\n\n\tprint(t[0][0]);\n}).call(this)"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[name] = name;\n //print(\"name=\"+name);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n if (names[name]) {\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": "// modification test of the solution\n// originally coded by aleksey.danchin\n\nvar n = readline(), m = {}, t = [], r = [], k, y, s;\n\nwhile (n--) {\n\ts = readline().split(' ');\n\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\tt[n] = [s[0], m[s[0]]];\n}\n\nfor (y in m) r.push(m[y]);\nk = Math.max(...r);\n\nprint(t.find(e => e[1] >= k && m[e[0]] === k)[0]);\n"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\nvar maxScore = gamers[0].score;\nvar gamers = [];\n\nfor(var i=0;i= maxScore;\n\t})\n\tif(index > -1) {\n\t\twrite(gamers[index].name);\n\t\tbreak;\n\t} \n}\n"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nfor(var i=0;igamers[index].max)gamers[index].max = gamers[index].score\n\t}\n\tsortGamers();\n\t//debug();\n}\nfunction sortGamers() {\n\tgamers.sort(function(a,b){\n\t\tif(a.scoreb.score) return -1;\n\t\tif(a.score==b.score) {\n\t\t\tif(a.maxb.max) return -1;\n\t\t\tif(a.max==b.max) return 0;\n\t\t}\n\t})\n\n}\nfunction debug (){\n\tfor(var i=0;i f) {\n e = c[d - 1][0];\n f = c[d - 1][1];\n }\n }\n d = c.length;\n for (; d; d--) {\n if (c[d - 1][0] === b[0]) {\n c[d - 1][1] = c[d - 1][1] + +b[1];\n break;\n }\n }\n }\n if (!d) {\n c.push([b[0],+b[1]]);\n }\n}\n\nprint(e);"}, {"source_code": "\nvar n = parseInt( readline() );\n\nvar hash = {};\nvar arr = [];\n\nfor(var r=1; r<=n; r++){\n\tvar a = readline().split(' ');\n\tvar name = a[0];\n\tvar point = parseInt(a[1]);\n\tif( a = hash['$'+name] ){\n\t\ta.point = parseInt(a.point+point);\n\t}else{\n\t\ta=hash['$'+name] = {\n\t\t\tname: name,\n\t\t\tpoint: point,\n\t\t\tr:r\n\t\t}\n\t}\n arr.push(a.point);\n}\n\nvar max = Math.max.apply(null, arr);\narr = [];\nfor(var key in hash){\n\tif(hash[key].point == max ){\n\t\tarr.push(hash[key]);\n\t}\n}\narr.sort(function(a,b){\n\treturn a.r>b.r;\n});\nprint(arr[0].name);"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tvar m = {};\n\tvar t = [];\n\tvar l = '';\n\tvar k = 0;\n\n\twhile (n--) {\n\t\tvar s = readline().split(' ');\n\t\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\t\tk = Math.max(k, m[s[0]]);\n\t\tt.push([s[0], m[s[0]]]);\n\t}\n\n\tt = t.filter(function (e) { return e[1] >= k; });\n\n\tprint(t[0][0]);\n}).call(this)"}, {"source_code": "var nRounds = parseInt(readline());\nvar d = {};\nvar highestName = \"\";\nvar highestScore = 0;\nfor( ; nRounds > 0; nRounds--) {\n var line = readline().split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n if (d[name] > highestScore) {\n highestScore = d[name];\n highestName = name;\n }\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\nprint(highestName);\n"}, {"source_code": "var i = ''\nvar lines = [];\nvar N = 0;\nvar arr = [];\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\nfunction debug(item) {\n if (N == 5) console.log(item);\n}\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n debug(lines.length);\n debug(lines);\n N = readline() - 0;\n arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n \n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let [username, newPoint] = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : newPoint;\n hash[username] = point;\n rounds.push({\n username, point\n })\n max = Math.max(max, point);\n }\n\n let keys = Object.keys(hash);\n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n \n debug(rounds);\n debug(candidates);\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "var N = readline();\nvar input = [];\nvar gamer = {};\nvar max = 0;\n\n//\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0432\u043e\u0434 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\nfor (var i = 0; i < N; i++) {\n var line = readline().split(' ');\n input[i] = {\n name:line[0],\n score:parseInt(line[1])\n };\n gamer[input[i].name] = 0;\n}\n\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0447\u043a\u043e\u0432\nfor (var i = 0; i < N; i++) {\n var temp = 0;\n for (var x = 0; x < N; x++) {\n if (input[x].name==input[i].name) {\n temp+=input[x].score;\n }\n }\n if (temp>max) {\n max = temp;\n }\n}\n//dfsf\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nvar result = function() {\n for (var i = 0; i < N; i++) {\n gamer[input[i].name] = gamer[input[i].name] + input[i].score;\n if (gamer[input[i].name]==max) {\n return result = input[i].name;\n }\n }\n}\n\nwrite(result());"}, {"source_code": "var a = +readline() + 1, b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n d = c.length;\n if (d) {\n if (d === 1) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n for (; d - 1; d--) {\n if (+c[d - 1][1] > f) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n }\n }\n\tif (b = readline()) {\n\t b = b.split(' ');\n\t\td = c.length;\n\t\tfor (; d; d--) {\n\t\t\tif (c[d - 1][0] === b[0]) {\n\t\t\t\tc[d - 1][1] = c[d - 1][1] + +b[1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n if (!d) {\n c.push([b[0],+b[1]]);\n }\n\t}\n}\n\nprint(e,f);"}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction main() {\n const count = readline();\n var players = {};\n var playersEnd = {};\n var turns = [];\n var winner = \"\";\n for (var i = 0; i < count; i++) {\n var nameScore = readline().split(\" \");\n var name = nameScore[0];\n var score = +nameScore[1];\n players[name] = players[name] ? players[name] + score : score;\n turns.push(nameScore);\n }\n\n var maxScore = Object.keys(players).reduce( (max, player) => {\n return max = players[player] > max ? players[player] : max;\n }, 0);\n\n for (var i = 0; i < turns.length; i++) {\n var nameEnd = turns[i][0];\n var scoreEnd = +turns[i][1];\n playersEnd[nameEnd] = playersEnd[nameEnd] ? playersEnd[nameEnd] + scoreEnd : scoreEnd;\n if (playersEnd[nameEnd] >= maxScore) {\n winner = nameEnd;\n break;\n }\n }\n print(winner);\n}"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar maxScore = 0;\nvar winner = null;\nvar players = {};\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n var newScore = players[name] || 0;\n newScore += roundScore;\n players[name] = newScore;\n\n if (newScore > maxScore) {\n maxScore = newScore;\n winner = name;\n }\n }\n}\n\nprint(winner);\n"}, {"source_code": "const solve = (t, players) => {\n let map = new Map();\n for (let i = 0; i < t; i++) {\n let p = players[i];\n if (map.has(p[0])) {\n map.set(p[0], [map.get(p[0])[0] + p[1], i + 1]);\n } else {\n map.set(p[0], [p[1], i + 1]);\n }\n }\n let sMap = sortMapByKey(map);\n return sMap.keys().next().value;\n};\n\nconst sortMapByKey = (map) => {\n return new Map([...map].sort((a, b) => {\n if (a[1][0] == b[1][0]) return a[1][1] - b[1][1];\n return b[1][0] - a[1][0];\n }));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \"));\n });\n\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let players = input.slice(1).map(x => [x[0], Number(x[1])]);\n console.log(solve(t, players));\n });\n\n};\n\nmain()"}, {"source_code": "// http://codeforces.com/problemset/problem/2/A\n// A. \u041f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\n\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n const players = {};\n let [name, score] = input[1].split(' ');\n players[name] = +score;\n let winner = name;\n\n for (let i = 2; i < input.length; i++) {\n [name, score] = input[i].split(' ');\n\n if (!players.hasOwnProperty(name)) {\n players[name] = +score;\n } else {\n players[name] += Number(score);\n }\n\n if (players[name] > players[winner]) winner = name;\n }\n\n console.log(winner);\n\n});\n"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tvar m = {};\n\tvar l = '';\n\tvar k = 0;\n\n\twhile (n--) {\n\t\tvar s = readline().split(' ');\n\t\tm[s[0]] = m[s[0]] ? m[s[0]] + +s[1] : +s[1];\n\t\tif (m[s[0]] > k) {\n\t\t\tl = s[0];\n\t\t\tk = m[s[0]];\n\t\t}\n\t}\n\n\tprint(l);\n}).call(this)"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\nvar maxScore = gamers[0].score;\nif(gamers[0].score == gamers[1].score) {\n\tvar gamers2 = [];\n\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "var nRounds = parseInt(readline());\nvar d = {};\nvar highestName = \"\";\nvar highestScore = 0;\nfor( ; nRounds > 0; nRounds--) {\n var line = readline().split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n if (d[name] > highestScore) {\n highestScore = d[name];\n highestName = name;\n }\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\nprint(highestName);\n"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[name] = name;\n //print(\"name=\"+name);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n if (names[name]) {\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": "rounds = parseInt(readline())\nstartingRounds = rounds\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\n//print(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] >= highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore >= highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } \n }\n}\n\nif (startingRounds == 50)\n{\n for (item in inputs) {\n if (item > 25) {\n print(inputs[item])\n }\n }\n}\n\nprint(winner.name)"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {};\nvar scores = {}; // map score to players with that score in chron order\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n // remove player from old score list\n var oldScore = players[name];\n if (Number.isInteger(oldScore)) {\n var playersList = scores[oldScore.toString()];\n if (Array.isArray(playersList)) {\n var nameIndex = playersList.indexOf(name);\n if (nameIndex !== -1) {\n playersList.splice(nameIndex, 1);\n if (playersList.length == 0) {\n // remove from scores hash\n delete scores[oldScore.toString()];\n }\n }\n }\n }\n\n oldScore = oldScore || 0;\n var newScore = oldScore + roundScore;\n\n // update score\n players[name] = newScore;\n scores[newScore.toString()] = scores[newScore.toString()] || [];\n scores[newScore.toString()].push(name);\n }\n}\n\nvar scoresList = Object.keys(scores);\nif (scoresList.length > 0) {\n scoresList.sort(function(a, b) {\n return parseInt(b) - parseInt(a);\n });\n var maxScore = scoresList[0];\n var playersList = scores[maxScore];\n if (playersList.length > 0) {\n print(playersList[0]);\n }\n}\n"}, {"source_code": "var i = ''\nvar lines = [];\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n console.log(lines.length);\n console.log(lines);\n let N = readline() - 0;\n let arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n \n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let {username, newPoint} = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : hash[username];\n hash[username] = point;\n rounds.push({\n username, point\n })\n max = Math.max(max, point);\n }\n\n let keys = Object.keys(hash);\n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n \n console.log(rounds);\n console.log(candidates);\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\n\nfor(var i=0; i-1){\n\t\t\tmap[key].point += p;\n\t\t\t\n\t\t}\n\t\tmap[key].step = i;\n\t}else{\n\t\tmap[key]={\n\t\t\tname: line[0],\n\t\t\tpoint: parseInt( line[1] ),\n\t\t\tstep: i\n\t\t}\n\t}\n}\n\nvar winner = {\n\tpoint:-1E9,\n\tstep:1E9\n}\nvar max = -1E9;\n//console.log( map );\nfor(var key in map){\n\tvar p = map[key].point;\n\tif( p > max ){\n\t\tmax = p;\n\t}\n}\nfor(var key in map){\n\tvar p = map[key];\n\tif( p.point == max && p.step {\n return max = players[player] > max ? players[player] : max;\n }, 0);\n\n for (var i = 0; i < turns.length; i++) {\n var nameEnd = turns[i][0];\n var scoreEnd = +turns[i][1];\n playersEnd[nameEnd] = playersEnd[nameEnd] ? playersEnd[nameEnd] + scoreEnd : scoreEnd;\n if (playersEnd[nameEnd] >= maxScore) {\n winner = nameEnd;\n break;\n }\n }\n print(winner);\n}"}, {"source_code": "var a = readline(), b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n b = readline().split(' ');\n d = c.length - 1;\n for (; d > 0; d--) {\n if (c[d][0] === b[0]) {\n c[d][1] = c[d][1] + +b[1];\n break;\n }\n }\n if (d < 1) {\n c.push([b[0],+b[1]]);\n } else {\n d = c.length - 1;\n e = c[d][0];\n f = +c[d][1];\n for (; d > 0; d--) {\n if (c[d][1] > f) {\n e = c[d][0];\n f = c[d][1];\n }\n }\n }\n}\n\nprint(e);"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {};\nvar maxScore = 0;\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n players[name] = (players[name] || 0) + roundScore;\n if (players[name] > maxScore) {\n maxScore = players[name];\n }\n }\n}\n\n// first player with at least maxScore\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n players[name] = (players[name] || 0) + roundScore;\n if (players[name] >= maxScore) {\n print(name);\n break;\n }\n }\n}\n"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nfor(var i=0;igamers[index].max)gamers[index].max = gamers[index].score\n\t}\n\tsortGamers();\n\t//debug();\n}\nfunction sortGamers() {\n\tgamers.sort(function(a,b){\n\t\tif(a.scoreb.score) return -1;\n\t\tif(a.score==b.score) {\n\t\t\tif(a.maxb.max) return -1;\n\t\t\tif(a.max==b.max) return 0;\n\t\t}\n\t})\n\n}\nfunction debug (){\n\tfor(var i=0;i scores[winner]) winner = player;\n}\n\nprint(winner);"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n let max = 0;\n let winner = '';\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!(name in prev)) prev[name] = {pts: 0, rnd: 0};\n prev[name].pts += parseInt(points);\n prev[name].rnd = i;\n if (prev[name].pts > max) {\n max = prev[name].pts;\n winner = name;\n }\n return prev;\n }, {});\n\n return winner;\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar names = [];\nvar points = [];\nvar map = {};\nvar map2 = {};\nvar max = -1E9;\nwhile (n--) {\n\tvar line = readline().split(' ');\n\tvar name = line[0];\n\tvar point = parseInt(line[1]);\n\n\tnames.push(name);\n\tpoints.push(point);\n}\n\n\n/** \u6c42\u5f97\u6700\u5927\u503cmax */\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map[key]) {\n\t\tmap[key] += point;\n\t} else {\n\t\tmap[key] = point;\n\t}\n\tif (map[key] > max) {\n\t\tmax = map[key];\n\t}\n}\n\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map2[key]) {\n\t\tmap2[key] += point;\n\t} else {\n\t\tmap2[key] = point;\n\t}\n\tif (map2[key] == max) {\n\t\tprint(names[i]);\n\t\tbreak;\n\t}\n}"}, {"source_code": "rounds = parseInt(readline())\n\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\n//print(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n }\n \n }\n}\nprint(winner.name)\n\n//print(winner.name)"}, {"source_code": "var a = readline(), b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n b = readline().split(' ');\n d = c.length - 1;\n for (; d > 0; d--) {\n if (c[d][0] === b[0]) {\n c[d][1] = c[d][1] + +b[1];\n break;\n }\n }\n if (d < 1) {\n c.push([b[0],+b[1]]);\n } else {\n d = c.length - 1;\n e = c[d][0];\n f = +c[d][1];\n for (; d > 0; d--) {\n if (c[d][1] > f) {\n e = c[d][0];\n f = c[d][1];\n }\n }\n }\n}\n\nprint(e);"}, {"source_code": "var n = parseInt(readline());\nvar names = [];\nvar points = [];\nvar map = {};\nvar map2 = {};\nvar max = -1E9;\nwhile (n--) {\n\tvar line = readline().split(' ');\n\tvar name = line[0];\n\tvar point = parseInt(line[1]);\n\n\tnames.push(name);\n\tpoints.push(point);\n}\n\n\n/** \u6c42\u5f97\u6700\u5927\u503cmax */\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map[key]) {\n\t\tmap[key] += point;\n\t} else {\n\t\tmap[key] = point;\n\t}\n\tif (map[key] > max) {\n\t\tmax = map[key];\n\t}\n}\n\nfor (var i in names) {\n\tvar key = '$' + names[i];\n\tvar point = points[i];\n\n\tif (map2[key]) {\n\t\tmap2[key] += point;\n\t} else {\n\t\tmap2[key] = point;\n\t}\n\tif (map[key] == max && map2[key] >= max) {\n\t\tprint(names[i]);\n\t\tbreak;\n\t}\n}"}, {"source_code": "rounds = parseInt(readline())\n\ninputs = []\nwhile (rounds > 0) {\n inputs.push(readline())\n rounds--\n}\n\nvar scores = {}\nvar winner = {\n name: \"\",\n score: 0\n}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (scores[splitItem[0]] != null) {\n var foundScore = scores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n scores[splitItem[0]] = foundScore\n //print(\"Found Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n } else {\n scores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n //print(\"New Score: \" + splitItem[0] + \" \" + scores[splitItem[0]])\n }\n \n }\n}\n\nvar highestTotalScore = 0\nfor (item in scores) {\n score = scores[item]\n if (score > highestTotalScore)\n {\n highestTotalScore = score\n }\n}\n\nprint(highestTotalScore)\nvar testScores = {}\n\nfor (item in inputs) {\n splitItem = inputs[item].split(\" \")\n\n if (1 <= splitItem[0].length <= 1000 && -1000 <= parseInt(splitItem[1]) <= 1000) {\n if (testScores[splitItem[0]] != null) {\n var foundScore = testScores[splitItem[0]]\n foundScore += parseInt(splitItem[1])\n testScores[splitItem[0]] = foundScore\n if (testScores[splitItem[0]] == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = testScores[splitItem[0]]\n break;\n }\n //print(\"Found Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n } else {\n testScores[splitItem[0]] = parseInt(splitItem[1])\n var newScore = parseInt(splitItem[1])\n if (newScore == highestTotalScore) {\n winner.name = splitItem[0]\n winner.score = newScore\n break;\n }\n //print(\"New Score: \" + splitItem[0] + \" \" + testScores[splitItem[0]])\n }\n \n }\n}\nprint(winner.name)\n\n//print(winner.name)"}, {"source_code": "t = parseInt(readline());\n\nmin = Number.NEGATIVE_INFINITY;\nwinner = null;\n\nwhile(t--) {\n const scores = {};\n input = readline().split(' ');\n\n player = input[0];\n change = parseInt(input[1]);\n \n if (scores[player] === undefined) scores[player] = change;\n else scores[player] += change;\n \n if (scores[player] > min) min = scores[player], winner = player;\n}\n\nprint(winner);"}, {"source_code": "\nvar n = parseInt( readline() );\n\nvar hash = {};\nvar arr = [];\n\nfor(var r=1; r<=n; r++){\n\tvar a = readline().split(' ');\n\tvar name = a[0];\n\tvar point = parseInt(a[1]);\n\tif( a = hash['$'+name] ){\n\t\ta.point = parseInt(a.point+point);\n\t\ta.r = r;\n\t}else{\n\t\ta=hash['$'+name] = {\n\t\t\tname: name,\n\t\t\tpoint: point,\n\t\t\tr:r\n\t\t}\n\t}\n}\nfor(var key in hash){\n\tarr.push(hash[key].point);\n}\nvar max = Math.max.apply(null, arr);\narr = [];\nfor(var key in hash){\n\tif(hash[key].point == max ){\n\t\tarr.push(hash[key]);\n\t}\n}\narr.sort(function(a,b){\n\treturn a.r>b.r;\n});\nprint(arr[0].name);"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[name] = name;\n //print(\"name=\"+name);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n if (names[name]) {\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": "var i = ''\nvar lines = [];\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n console.log(lines.length);\n console.log(lines);\n let N = readline() - 0;\n let arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n console.log('arr');\n console.log(arr);\n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let {username, newPoint} = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : hash[username];\n hash[username] = point;\n rounds.push({\n username, point\n })\n max = Math.max(max, point);\n }\n\n let keys = Object.keys(hash);\n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n \n console.log(rounds);\n console.log(candidates);\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\n\nfor(var i=0; i-1){\n\t\t\tmap[key].point += p;\n\t\t\tmap[key].step = i;\n\t\t}\n\t\t\n\t}else{\n\t\tmap[key]={\n\t\t\tname: line[0],\n\t\t\tpoint: parseInt( line[1] ),\n\t\t\tstep: i\n\t\t}\n\t}\n}\n\nvar winner = {\n\tpoint:-1E9,\n\tstep:1E9\n}\nvar max = -1E9;\n//console.log( map );\nfor(var key in map){\n\tvar p = map[key].point;\n\tif( p > max ){\n\t\tmax = p;\n\t}\n}\nfor(var key in map){\n\tvar p = map[key];\n\tif( p.point == max && p.step i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n lines = i.split(EOL) /*your input text, split by lines*/\n main();\n})\n\nfunction readline() {\n return lines.shift();\n}\n\nfunction main() {\n let N = readline() - 0;\n let arr = [];\n for (let i = 0; i < N; i++) {\n let str = readline();\n arr.push(str.trim());\n }\n \n console.log(winner(arr));\n}\n\nfunction winner(arr) {\n let hash = {};\n let rounds = [];\n let max = -1;\n \n for (let str of arr) {\n let {username, newPoint} = str.split(' ');\n newPoint -= 0;\n let point = hash[username] ? hash[username] + newPoint : hash[username];\n hash[username] = point;\n rounds.push({\n username, point\n })\n max = Math.max(max, point);\n }\n\n let keys = Object.keys(hash);\n let candidates = keys.filter(k => hash[k] == max);\n if (candidates.length == 1) return candidates[0];\n\n for (let round of rounds) {\n if (candidates.indexOf(round.username) > -1 && round.point >= max) {\n return round.username;\n }\n }\n}"}, {"source_code": "\n\nvar all = parseInt( readline() );\n\nvar hash = {};\n\nvar winner = {\n\tname:'',\n\tpoint:0\n}\nfor(var r=1; r<=all; r++){\n\tvar a = readline().split(' ');\n\tvar name = a[0];\n\tvar point = parseInt(a[1]);\n\tif( a = hash['$'+name] ){\n\t\ta.point = parseInt(a.point+point);\n\t}else{\n\t\ta=hash['$'+name] = {\n\t\t\tname: name,\n\t\t\tpoint: point\n\t\t}\n\t}\n\n\tif(a.point>winner.point){\n\t\twinner = {\n\t\t\tname:a.name,\n\t\t\tpoint:a.point\n\t\t}\n\t}\n}\nprint(winner.name);"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n let max = 0;\n let winner = '';\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!i) winner = name;\n if (!(name in prev)) prev[name] = {pts: 0, rnd: 0};\n prev[name].pts += parseInt(points);\n prev[name].rnd = i;\n if (prev[name].pts > max) {\n max = prev[name].pts;\n winner = name;\n }\n return prev;\n }, {});\n\n return winner;\n}\n"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n}\n\nfunction solve(pps) {\n const m = new Map();\n let time = 0;\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const [a_time, a_pts] = get_with_default(m, a, [time, 0]);\n const a_pts_now = a_pts + Number(b);\n m.set(a, [time, a_pts_now]);\n time = time + 1;\n }\n let p_max = undefined;\n let pts_max = undefined;\n let pts_time = undefined;\n for (const [a, [a_time, a_pts]] of m.entries()) {\n if (p_max === undefined) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else {\n if (a_pts > pts_max) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else if (a_pts === pts_max) {\n if (a_time < pts_time) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n }\n } else {\n // do nothing ...\n }\n }\n }\n return p_max;\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "// http://codeforces.com/problemset/problem/2/A\n// A. \u041f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\n\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n const players = {};\n let [name, score] = input[1].split(' ');\n players[name] = +score;\n let winner = name;\n\n for (let i = 2; i < input.length; i++) {\n [name, score] = input[i].split(' ');\n\n if (!players.hasOwnProperty(name)) {\n players[name] = +score;\n } else {\n players[name] += Number(score);\n }\n\n if (players[name] > players[winner]) winner = name;\n }\n\n console.log(winner);\n\n});\n"}, {"source_code": "var name=new Array(1010);\nvar score=new Array(1010);\nvar edge=new Array();\nvar head=new Array(1010);\nvar cnt;\nfunction init()\n{\n var i;\n for(i=1;i<=1000;i++) head[i]=-1;\n return;\n}\nfunction add(u,v,str)\n{\n edge[cnt].name=str;edge[cnt].val+=v;edge[cnt].next=head[u];\n head[u]=cnt++;\n return cnt-1;\n}\nfunction find(num,name)\n{\n var i;\n for(i=head[num];i!=-1;i=edge[i].next)\n {\n if(edge[i].name==name) return i;\n }\n return 0;\n}\nfunction str_hash(s)\n{\n var i,sum=0;\n for(i=0;i<=s.length-1;i++)\n {\n var tmp=s[i].charCodeAt()-'a'.charCodeAt();\n sum+=tmp*tmp;\n }\n return sum%997+1;\n}\nfunction obj(val,name,next)\n{\n this.val=val;this.name=name;this.next=next;\n}\nfunction main()\n{\n var i;\n init(head,-1);cnt=0;\n for(i=0;i<=1000;i++) edge.push(new obj(0,\"\",0));\n var maxs=-1;\n var n=readline();\n for(i=1;i<=n;i++)\n {\n var tmp=readline().split(' ');\n name[i]=tmp[0];score[i]=tmp[1];\n var index=str_hash(name[i]);\n var ret=find(index,name[i]);\n if(!ret) ret=add(index,score[i],name[i]);\n else edge[ret].val+=score[i];\n if(edge[ret].val>maxs) maxs=edge[ret].val;\n }\n for(i=1;i<=1000;i++) edge[i].val=0;\n var ans;\n for(i=1;i<=n;i++)\n {\n index=str_hash(name[i]);\n ret=find(index,name[i]);\n edge[ret].val+=score[i];\n if(edge[ret].val>=maxs)\n {\n ans=edge[ret].name;\n break;\n }\n }\n print(ans);\n}\nmain();"}, {"source_code": "var a = [], b = readline(), c, d, e, f, g;\n\nfor (; b; b--) {\n d = readline().split(' ');\n\tc = a.length;\n\tg = 1;\n\tfor (; c; c--) {\n\t if (a[c - 1][1] > a[c - 1][2]) a[c - 1][2] = a[c - 1][1];\n\t if (a[c - 1][0] === d[0]) {\n\t\t\ta[c - 1][1] = a[c - 1][1] + +d[1];\n\t\t\tg = 0;\n\t\t}\n\t}\n\tif (g) a.push([d[0], +d[1], +d[1]]);\n}\nc = a.length;\nf = a[c - 1][0];\nfor (; c; c--) {\n e = c - 1;\n\tfor (; e; e--) {\n\t\tif (a[c - 1][1] === a[e - 1][1]) {\n\t\t if (a[c - 1][2] > a[e - 1][2]) {\n\t\t\t f = a[c - 1][0];\n\t\t\t} else {\n\t\t\t f = a[e - 1][0];\n\t\t\t}\n\t\t} else if (a[c - 1][1] > a[e - 1][1]) {\n\t\t f = a[c - 1][0];\n\t\t} else {\n\t\t f = a[e - 1][0];\n\t\t}\n\t}\n}\nprint(f);\n"}, {"source_code": "var numberOfRoundsPlayed = readline();\n\nvar roundInfo;\nvar scores = {};\nvar scoreLog = [];\nfor(var i = 0; i < numberOfRoundsPlayed; i++) {\n roundInfo = readline();\n roundInfo = roundInfo.split(\" \");\n var player = roundInfo[0];\n var playerScore = parseInt(roundInfo[1]);\n\n if (!scores[player]) scores[player] = 0;\n scores[player] += playerScore;\n // print(`i: ${i}, player: ${player}, score: ${playerScore}, total: ${scores[player]}`);\n\n scoreLog.push([player, scores[player]]);\n}\n\n// print('===');\n\n// print(JSON.stringify(scoreLog))\n\nvar winnerScore = Object.keys(scores).sort((a, b) => {\n // print(`a: ${a}, score: ${scores[a]}`);\n // print(`b: ${b}, score: ${scores[b]}`);\n return scores[a] < scores[b];\n})[0];\nwinnerScore = scores[winnerScore];\n\n// print(winnerScore)\n\nvar winnerList = Object.keys(scores).filter(player => {\n return scores[player] === winnerScore;\n})\n\nscoreLog.some(e => {\n // print(e);\n if (winnerList.includes(e[0]) && e[1] >= winnerScore) {\n print(e[0]);\n return true;\n }\n})\n"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\n\nfor(var i=0; i max ){\n\t\tmax = p;\n\t}\n}\nfor(var key in map){\n\tvar p = map[key];\n\tif( p.point == max && p.stepintBestScore) {\n// arrGames[i]=arrScores[i]+':'+intGame+':'+arrGames[i];\n arrGames[i].push([arrScores[i],intGame]);\n// print('arrGames[i]:'+arrGames[i]);\n }\n }\n}\n\nintBestScore=0;\n\nfor (var i=0;i=intBestScore) && (arrGames[intPretender][j][1] {\n // print(`a: ${a}, score: ${scores[a]}`);\n // print(`b: ${b}, score: ${scores[b]}`);\n return scores[a] < scores[b];\n})[0];\nwinnerScore = scores[winnerScore];\n\n// print(winnerScore)\n\nvar winnerList = playerList.filter(player => {\n return scores[player] === winnerScore;\n})\n\nlog.some(e => {\n if (winnerList.includes(e[0]) && e[1] >= winnerScore) {\n print(e[0]);\n return true;\n }\n})"}, {"source_code": "var tests = readline() - 0;\n\nvar Data = {};\nfor (var i = 0 ; i < tests ; i++)\n{\nvar line = readline().split(' ');\nData[line[0] ] +=(Data[ line[0] ] || 0) + ( line[1] - 0 );\n}\n\nvar best = \"---\";\n\nfor (key in Data)\n{\n if (best == \"---\") best = key;\nif (Data[key] > Data[best]) best = key;\n}\n\nprint(best);"}, {"source_code": "var count = parseInt(readline());\nvar input = [];\n\nfor (var i = 0; i < count; i++) {\n input.push(readline());\n}\n\nvar players = {}; // false means lost\n\nfor (var i = 0; i < count; i++) {\n var matches = input[i].match(/([A-Za-z]+) (-?\\d+)/);\n if (matches != null) {\n var name = matches[1];\n var roundScore = parseInt(matches[2]);\n\n // check if player already lost\n if (players[name] === false) continue;\n\n var newScore = players[name] || 0;\n newScore += roundScore;\n players[name] = (newScore > -1) ? newScore : false;\n }\n}\n\nvar maxScore = 0;\nvar winner = null;\n\nvar names = Object.keys(players);\nfor (var i = 0; i < names.length; i++) {\n var name = names[i];\n if (players[name] > maxScore) {\n maxScore = players[name];\n winner = name;\n }\n}\n\nprint(winner);\n"}, {"source_code": "var N = readline();\nvar input = [];\nvar gamer = {};\nvar gam = {};\nvar max = 0;\n\n//\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0432\u043e\u0434 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\nfor (var i = 0; i < N; i++) {\n var line = readline().split(' ');\n input[i] = {\n name:line[0],\n score:parseInt(line[1])\n };\n gamer[input[i].name] = 0;\n gam[input[i].name] = 0;\n}\n//print(\" \");\nfor (var i = 0; i < N; i++) {\n var temp = 0;\n gam[input[i].name] += input[i].score;\n //print(input[i].name + \" \" + gam[input[i].name]);\n for (var key in gam) {\n if (key==input[i].name) {\n input[i].score=gam[input[i].name];\n }\n }\n}\n//print(\" \");\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0447\u043a\u043e\u0432\nfor (var i = 0; i < N; i++) {\n var temp = 0;\n for (var x = 0; x < N; x++) {\n if (input[x].score>max) {\n max=input[x].score;\n }\n }\n}\n//print(max);\n//print(\" \");\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nvar result = function() {\n for (var i = 0; i < N; i++) {\n //gamer[input[i].name] = gamer[input[i].name] + input[i].score;\n //print(input[i].name + \" \" + gamer[input[i].name]);\n if (input[i].score==max) {\n return result = input[i].name;\n }\n }\n}\n\nwrite(result());"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n}\n\nfunction solve(pps) {\n const m = new Map();\n let p_max = undefined;\n let pts_max = undefined;\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const pts = Number(b);\n if (p_max === undefined) {\n m.set(a, pts);\n p_max = a;\n pts_max = pts;\n } else {\n const a_pts = get_with_default(m, a, 0) + pts;\n m.set(a, a_pts);\n if (a_pts > pts_max) {\n p_max = a;\n pts_max = a_pts;\n }\n }\n }\n return p_max;\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": " var n = +readline()\n var rs = []\n var v\n for (var t = 0; t < n; t++) {\n rs.push(readline().split(' '))\n }\n var sc = rs.reduce(function (a, l) {\n a[l[0]] = (a[l[0]] || 0) + +l[1]\n return a\n }, {})\n var ms = 0\n var mso = {}\n for (var p in sc) {\n if (sc[p] > ms) {\n mso = {}\n mso[p] = true\n ms = sc[p]\n } else if (sc[p] == ms) {\n mso[p] = true\n }\n }\n var vs = Object.keys(mso)\n if (vs.length == 1)\n v = vs[0]\n if (!v) {\n sc = {}\n for (t = 0; t < n; t++) {\n p = rs[t][0]\n s = rs[t][1]\n if (((sc[p] = (sc[p] || 0) + s) >= ms) && mso[p]) {\n v = p\n break\n }\n }\n }\n print(v || rs.slice(27))"}, {"source_code": "t = parseInt(readline());\n\ni = 0;\n\nwhile(t--) {\n const scores = {};\n const bestOf = {};\n const recordHit = {};\n input = readline().split(' ');\n\n player = input[0];\n change = parseInt(input[1]);\n \n if (scores[player] === undefined) scores[player] = change;\n else scores[player] += change;\n \n if (bestOf[player] === undefined || bestOf[player] < scores[player])\n bestOf[player] = scores[player], recordHit[player] = i;\n \n i++;\n}\n\nwinner = Object.keys(scores).reduce(\n (best, player) => (\n best == null ||\n scores[player] > scores[best] ||\n (scores[player] == scores[best] && recordHit[player] < recordHit[best])\n ) ? player : best,\n null\n);\n\nprint(winner);"}, {"source_code": "var nRounds = parseInt(readline());\nvar lines = [];\nvar d = {};\nfor(var n=nRounds ; n > 0; n--) {\n var oneLine = readline();\n lines.push(oneLine);\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n}\n\nvar highestScore = -999999;\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] > highestScore) highestScore = d[key];\n }\n}\n//print(\"highestScore=\"+highestScore);\n\nvar names = {};\nfor (var key in d) {\n if (d.hasOwnProperty(key)) {\n if (d[key] >= highestScore) {\n names[name] = name;\n //print(\"name=\"+name);\n }\n }\n}\n\nvar d = {};\nvar highestName = \"\";\nfor(var n=0 ; n < nRounds; n++) {\n var oneLine = lines[n];\n var line = oneLine.split(' ');\n var name = line[0];\n var score = parseInt(line[1]);\n if (!d[name]) d[name] = 0;\n d[name] += score;\n //print(\"..\" + name + \" = \" + score + \" === \" + d[name]);\n if (d[name] >= highestScore) {\n if (names[name]) {\n highestName = name;\n break;\n }\n }\n}\n\n\n\nprint(highestName);"}, {"source_code": " var n = +readline()\n var rs = []\n var v\n for (var t = 0; t < n; t++) {\n rs.push(readline().split(' '))\n }\n var sc = rs.reduce(function (a, l) {\n a[l[0]] = (a[l[0]] || 0) + +l[1]\n return a\n }, {})\n var ms = 0\n var mso = {}\n for (var p in sc) {\n if (sc[p] > ms) {\n mso = {}\n mso[p] = true\n ms = sc[p]\n } else if (sc[p] == ms) {\n mso[p] = true\n }\n }\n var vs = Object.keys(mso)\n if (vs.length == 1)\n v = vs[0]\n if (!v) {\n sc = {}\n for (t = 0; t < n; t++) {\n p = rs[t][0]\n s = rs[t][1]\n if (((sc[p] = (sc[p] || 0) + s) >= ms) && mso[p]) {\n v = p\n break\n }\n }\n }\n print(v || rs)"}, {"source_code": "var numberOfRoundsPlayed = readline();\n\nvar roundInfo;\nvar scores = {};\nvar scoreLog = [];\nfor(var i = 0; i < numberOfRoundsPlayed; i++) {\n roundInfo = readline();\n roundInfo = roundInfo.split(\" \");\n var player = roundInfo[0];\n var playerScore = parseInt(roundInfo[1]);\n\n if (!scores[player]) scores[player] = 0;\n scores[player] += playerScore;\n // print(`i: ${i}, player: ${player}, score: ${playerScore}, total: ${scores[player]}`);\n\n scoreLog.push([player, scores[player]]);\n}\n\n// print('===');\n\n// print(JSON.stringify(scoreLog))\n\nvar winnerScore = Object.keys(scores).sort((a, b) => {\n // print(`a: ${a}, score: ${scores[a]}`);\n // print(`b: ${b}, score: ${scores[b]}`);\n return scores[a] < scores[b];\n})[0];\nwinnerScore = scores[winnerScore];\n\n// print(winnerScore)\n\nvar winnerList = Object.keys(scores).filter(player => {\n return scores[player] === winnerScore;\n})\n\nscoreLog.some(e => {\n // print(e);\n if (winnerList.includes(e[0]) && e[1] >= winnerScore) {\n print(e[0]);\n return true;\n }\n})\n"}, {"source_code": "var N = readline();\nvar input = [];\nvar gamer = {};\nvar gam = {};\nvar max = 0;\n\n//\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0432\u043e\u0434 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\nfor (var i = 0; i < N; i++) {\n var line = readline().split(' ');\n input[i] = {\n name:line[0],\n score:parseInt(line[1])\n };\n gamer[input[i].name] = 0;\n gam[input[i].name] = 0;\n}\n//print(\" \");\nfor (var i = 0; i < N; i++) {\n var temp = 0;\n gam[input[i].name] += input[i].score;\n //print(input[i].name + \" \" + gam[input[i].name]);\n for (var key in gam) {\n if (key==input[i].name) {\n input[i].score=gam[input[i].name];\n }\n }\n}\n//print(\" \");\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0447\u043a\u043e\u0432\nfor (var i = 0; i < N; i++) {\n var temp = 0;\n for (var x = 0; x < N; x++) {\n if (input[x].score>max) {\n max=input[x].score;\n }\n }\n}\n//print(max);\n//print(\" \");\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nvar result = function() {\n for (var i = 0; i < N; i++) {\n //gamer[input[i].name] = gamer[input[i].name] + input[i].score;\n //print(input[i].name + \" \" + gamer[input[i].name]);\n if (input[i].score==max) {\n return result = input[i].name;\n }\n }\n}\n\nwrite(result());"}, {"source_code": "var step = readline();\nvar gamers = [];\nvar winner = \"\";\nvar mass = []\nfor(var i=0;ib.score) return -1;\n\t\tif(a.score==b.score) return 0;\n\t})\n}\n\nvar maxScore = gamers[0].score;\nif(gamers[0].score == gamers[1].score) {\n\tvar gamers2 = [];\n\n\tfor(var i=0;i= maxScore) {\n\t\t\t\twrite(gamers2[index].name);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n} else {\n\twrite(gamers[0].name);\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!(name in prev)) {\n prev[name] = {\n pts: 0,\n rnd: 0,\n max: -1,\n history: [],\n set lastRound(val) {\n const p = this.pts + val;\n if (p > this.max) {\n this.max = p;\n this.rnd = this.currentRound;\n }\n this.pts = p;\n this.history.push({pts: p, rnd: this.currentRound});\n }\n };\n }\n prev[name].currentRound = i;\n prev[name].lastRound = parseInt(points);\n return prev;\n }, {});\n // console.log(results);\n\n const winners = [];\n let winner = '';\n let max = -1;\n let rnd = 0;\n for (let name in results) {\n if (results[name].pts > max) {\n max = results[name].pts;\n winner = name;\n rnd = results[name].rnd;\n } else if (results[name].pts) {\n const r1 = results[name].history.find(h => h.pts >= max);\n const r2 = results[winner].history.find(h => h.pts >= max);\n if (r1.rnd < r2.rnd) winner = name;\n }\n }\n return winner;\n}\n"}, {"source_code": "var a = +readline() + 1, b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n d = c.length;\n if (d) {\n if (d === 1) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n for (; d - 1; d--) {\n if (+c[d - 1][1] > f) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n }\n }\n\tif (b = readline()) {\n\t b = b.split(' ');\n\t\td = c.length;\n\t\tfor (; d; d--) {\n\t\t\tif (c[d - 1][0] === b[0]) {\n\t\t\t\tc[d - 1][1] = c[d - 1][1] + +b[1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n if (!d) {\n c.push([b[0],+b[1]]);\n }\n\t}\n}\n\nprint(e,f);"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\nlet rounds = 0;\nconst r = [];\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nasync function work(line, lineNr) {\n if (lineNr) {\n r.push(line.trim().split(' '));\n if (r.length === rounds) {\n const solutionForLine = await solve(r);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n } else {\n rounds = parseInt(line.trim());\n log('Line skipped:', line);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(rounds) {\n const results = rounds.reduce((prev, current, i) => {\n const [name, points] = current;\n if (!(name in prev)) {\n prev[name] = {\n pts: 0,\n rnd: 0,\n max: -1,\n history: [],\n set lastRound(val) {\n const p = this.pts + val;\n if (p > this.max) {\n this.max = p;\n this.rnd = this.currentRound;\n }\n this.pts = p;\n this.history.push({pts: p, rnd: this.currentRound});\n }\n };\n }\n prev[name].currentRound = i;\n prev[name].lastRound = parseInt(points);\n return prev;\n }, {});\n // console.log(results);\n\n const winners = [];\n let winner = '';\n let max = -1;\n let rnd = 0;\n for (let name in results) {\n if (results[name].pts > max) {\n max = results[name].pts;\n winner = name;\n rnd = results[name].rnd;\n } else if (results[name].pts) {\n const r1 = results[name].history.find(h => h.pts >= max);\n const r2 = results[winner].history.find(h => h.pts >= max);\n if (r1.rnd < r2.rnd) winner = name;\n }\n }\n return winner;\n}\n"}, {"source_code": "var a = +readline() + 1, b, c = [], d, e, f = 0;\n\nfor (; a; a--) {\n d = c.length;\n if (d) {\n if (d === 1) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n for (; d - 1; d--) {\n if (+c[d - 1][1] > f) {\n e = c[d - 1][0];\n f = +c[d - 1][1];\n }\n }\n }\n\tif (b = readline()) {\n\t b = b.split(' ');\n\t\td = c.length;\n\t\tfor (; d; d--) {\n\t\t\tif (c[d - 1][0] === b[0]) {\n\t\t\t\tc[d - 1][1] = c[d - 1][1] + +b[1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n if (!d) {\n c.push([b[0],+b[1]]);\n }\n\t}\n}\n\nprint(e);"}, {"source_code": "var tests = readline() - 0;\n\nvar Data = {};\n\nvar best = \"---\";\n\nfor (var i = 0 ; i < tests ; i++)\n{\nvar line = readline().split(' ');\nData[line[0] ] =(Data[ line[0] ] || 0) + ( line[1] - 0 );\n\nfor (key in Data)\n{\n if (best == \"---\") best = key;\n if (Data[key] > Data[best]) best = key;\n}\n\n}\nprint(best);"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\n\nfor(var i=0; i-1){\n\t\t\tmap[key].point += p;\n\t\t\t\n\t\t}\n\t\tmap[key].step = i;\n\t}else{\n\t\tmap[key]={\n\t\t\tname: line[0],\n\t\t\tpoint: parseInt( line[1] ),\n\t\t\tstep: i\n\t\t}\n\t}\n}\n\nvar winner = {\n\tpoint:-1E9,\n\tstep:-1\n}\n//console.log( map );\nfor(var key in map){\n\tvar people = map[key]\n\tif( people.point > winner.point || \n\t\t(people.point == winner.point && people.stepmax) {\n max = temp;\n }\n}\n//dfsf\n//\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\nvar result = function() {\n for (var i = 0; i < N; i++) {\n gamer[input[i].name] = gamer[input[i].name] + input[i].score;\n if (gamer[input[i].name]==max) {\n return result = input[i].name;\n }\n }\n}\n\nwrite(result());"}, {"source_code": "\nvar c = parseInt( readline() );\n\nvar map = {};\n\nfor(var i=0; i-1){\n\t\t\tmap[key].point += p;\n\t\t\t\n\t\t}\n\t\tmap[key].step = i;\n\t}else{\n\t\tmap[key]={\n\t\t\tname: line[0],\n\t\t\tpoint: parseInt( line[1] ),\n\t\t\tstep: i\n\t\t}\n\t}\n}\n\nvar winner = {\n\tpoint:-1E9,\n\tstep:1E9\n}\nvar max = -1E9;\n//console.log( map );\nfor(var key in map){\n\tvar p = map[key].point;\n\tif( p > max ){\n\t\tmax = p;\n\t}\n}\nfor(var key in map){\n\tvar p = map[key];\n\tif( p.point == max && p.stepmaxs) maxs=edge[ret].val;\n }\n for(i=1;i<=1000;i++) edge[i].val=0;\n var ans;\n for(i=1;i<=n;i++)\n {\n index=str_hash(name[i]);\n ret=find(index,name[i]);\n edge[ret].val+=score[i];\n if(edge[ret].val>=maxs)\n {\n ans=edge[ret].name;\n break;\n }\n }\n print(ans);\n}\nmain();"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n}\n\nfunction solve(pps) {\n const m = new Map();\n let time = 0;\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const [a_time, a_pts] = get_with_default(m, a, [time, 0]);\n const a_pts_now = a_pts + Number(b);\n m.set(a, [time, a_pts_now]);\n time = time + 1;\n }\n let p_max = undefined;\n let pts_max = undefined;\n let pts_time = undefined;\n for (const [a, [a_time, a_pts]] of m.entries()) {\n if (p_max === undefined) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else {\n if (a_pts > pts_max) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else if (a_pts === pts_max) {\n if (a_time < pts_time) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n }\n } else {\n // do nothing ...\n }\n }\n }\n return p_max;\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function get_with_default(m, k, d) {\n return m.has(k) ? m.get(k) : d;\n}\n\nfunction solve(pps) {\n const m = new Map();\n let time = 0;\n for (const pp of pps) {\n const [a, b] = pp.split(/\\s+/);\n const [a_time, a_pts] = get_with_default(m, a, [time, 0]);\n const a_pts_now = a_pts + Number(b);\n m.set(a, [time, a_pts_now]);\n time = time + 1;\n }\n let p_max = undefined;\n let pts_max = undefined;\n let pts_time = undefined;\n for (const [a, [a_time, a_pts]] of m.entries()) {\n if (p_max === undefined) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else {\n if (a_pts > pts_max) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n } else if (a_pts === pts_max) {\n if (a_time < pts_time) {\n p_max = a;\n pts_max = a_pts;\n pts_time = a_time;\n }\n } else {\n // do nothing ...\n }\n }\n }\n return p_max;\n}\n\nfunction main(lines) {\n const pps = [];\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n pps.push(line);\n }\n }\n const result = solve(pps);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}], "src_uid": "c9e9b82185481951911db3af72fd04e7"} {"source_code": "\r\nconst iteration = (arr) => {\r\n\r\n}\r\n\r\nconst solve = (data, n, m) => {\r\n\tconst arr = [];\r\n\r\n\tfor (let i=0; i a-b);\r\n\t}\r\n\r\n\tconst res = [];\r\n\r\n\tfor (let j=0; j item.join(' ')).join('\\n'));\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i +v);\r\n\t\tconst data = lines.slice(i+1, i+n+1)\r\n\t\t\t.map(line => line.split(' ').map(v => +v));\r\n\r\n\r\n\t\tsolve(data, n, m);\r\n\r\n\t\ti+=n;\r\n\t}\r\n})\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst b = Array(n);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tb[i] = rna();\r\n\t\t\tb[i].sort((x, y) => x - y);\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tlet k = 0;\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (b[j][0] < b[k][0])\r\n\t\t\t\t\tk = j;\r\n\t\t\t}\r\n\t\t\tconst r = m - 1 - i;\r\n\t\t\tb[k] = [...b[k].slice(1, r + 1), b[k][0], ...b[k].slice(r + 1)];\r\n\t\t}\r\n\r\n\t\tfor (row of b)\r\n\t\t\tconsole.log(row.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst b = Array(n);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tb[i] = rna();\r\n\t\t\tb[i].sort((x, y) => x - y);\r\n\t\t}\r\n\r\n\t\t//console.log('b', b);\r\n\t\tconst paths = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tpaths[i] = [];\r\n\t\t\tlet k = 0;\r\n\t\t\tfor (let j = 0; j < n ; j++) {\r\n\t\t\t\tpaths[i].push(b[j].pop());\r\n\t\t\t\tif (b[j][0] < b[k][0]) k = j;\r\n\t\t\t}\r\n\t\t\tb[k].push(paths[i][k]);\r\n\t\t\tpaths[i][k] = b[k].shift();\r\n\t\t}\r\n\t\t//console.log('paths',paths)\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet ans = [];\r\n\t\t\tfor (let j = 0; j < m; j++)\r\n\t\t\t\tans.push(paths[j][i]);\r\n\r\n\t\t\tconsole.log(ans.join(' '));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, m, arr) {\n let combined = [];\n arr.forEach((arr2, k) => {\n arr2.forEach((v, i) => {\n combined.push({ v, k, i });\n });\n });\n combined.sort((a, b) => a.v - b.v);\n let ret = Array.from({ length: n }).map(() => []);\n for (let i = 0; i < m; i++) {\n let target = combined[i];\n ret[target.k][i] = target.v;\n }\n let next = Array.from({ length: n }).map(() => 0);\n for (let i = m; i < combined.length; i++) {\n let target = combined[i];\n let idx = next[target.k];\n while (ret[target.k][idx]) {\n idx++;\n }\n ret[target.k][idx] = target.v;\n next[target.k] = idx;\n }\n ret.forEach((t) => {\n t.forEach((a) => {\n io.write(a);\n });\n io.writeLine('');\n });\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let m = io.nextNum();\n let arr = [];\n for (let i = 0; i < n; i++) {\n arr.push(io.nextNumArray(m));\n }\n solve(n, m, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar e = new Array();\r\n\t\tvar output = new Array(N);\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\toutput[j] = new Array(M);\r\n\t\t\tfor(var k = 0; k < M; k++){\r\n\t\t\t\te.push({\r\n\t\t\t\t\ty : j,\r\n\t\t\t\t\tx : k,\r\n\t\t\t\t\tv : nextInt()\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\te.sort(function(a,b){\r\n\t\t\treturn a.v - b.v;\r\n\t\t});\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\toutput[e[0].y][j] = e[0];\r\n\t\t\te.shift();\r\n\t\t}\r\n\t\tvar index = 0;\r\n\t\te.sort(function(a,b){\r\n\t\t\tif(a.y == b.y){\r\n\t\t\t\treturn a.x - b.x;\r\n\t\t\t}else{\r\n\t\t\t\treturn a.y - b.y;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t});\r\n\t\t\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tfor(var k = 0; k < M; k++){\r\n\t\t\t\tif(output[j][k] == null){\r\n\t\t\t\t\toutput[j][k] = e[index].v;\r\n\t\t\t\t\tindex++;\r\n\t\t\t\t}else{\r\n\t\t\t\t\toutput[j][k] = output[j][k].v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tmyout(myconv(output[j], 8));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = [];\n\n for (var j = 0; j < n; j++)\n a.push(readline().split(' ').map(a => parseInt(a)));\n \n for (var i = 0; i < m; i++) {\n for (var j = 0; j < n; j++) {\n var left = a[j].splice(0, i);\n a[j].sort((a, b) => a - b);\n a[j] = left.concat(a[j]);\n }\n\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j !== f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++)\n write(`${a[i][j]} `);\n write('\\n'); \n }\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(iInpArr());\r\n arr[i].sort((a, b) => a - b);\r\n }\r\n let narr = [];\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) narr.push({ val: arr[i][j], i: i, j: j });\r\n narr.sort((a, b) => a.val - b.val);\r\n for (let k = m - 1; k >= 0; k--) {\r\n let i = narr[k].i;\r\n let j = narr[k].j;\r\n [arr[i][j], arr[i][k]] = [arr[i][k], arr[i][j]];\r\n }\r\n for (let i = 0; i < n; i++) console.log(arr[i].join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline().split(\" \");\r\n var m = n[1];\r\n n = n[0];\r\n var b = [];\r\n var used = [];\r\n var string = [];\r\n for(s = 0; s < n; s++) {\r\n temp = readline().split(\" \");\r\n for(k = 0; k < temp.length; k++) {temp[k] = parseInt(temp[k]);}\r\n temp.sort(function(a, b) { return a - b; });\r\n b = b.concat(temp);\r\n used[i] = 0;\r\n }\r\n var min = [], max = [], minp = [], maxp = [];\r\n for(j = 0; j < n; j++) {\r\n min[j] = b[m * j];\r\n minp[j] = m * j;\r\n max[j] = b[m * (j + 1) - 1];\r\n maxp[j] = m * (j + 1) - 1;\r\n }\r\n for(q = 0; q < m; q++) {\r\n var index = min.indexOf(Math.min.apply(null, min));\r\n for(r = 0; r < n; r++) {\r\n if(r === index) {\r\n string.push(min[index]);\r\n minp[r] += 1;\r\n min[r] = b[minp[r]];\r\n }\r\n else {\r\n string.push(max[r]);\r\n maxp[r] -= 1;\r\n max[r] = b[maxp[r]];\r\n }\r\n }\r\n }\r\n var output = \"\";\r\n for(u = 0; u < n; u++) {\r\n output = \"\";\r\n for(v = 0; v < m; v++) {\r\n output += string[v * n + u] + \" \";\r\n }\r\n output = output.slice(0, output.length - 1);\r\n print(output);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = new Array(n)\r\n var copy = new Array(n)\r\n var used = new Array(n)\r\n\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n copy[j] = new Array(m)\r\n used[j] = new Array(m).fill(false)\r\n }\r\n var arryMin = []\r\n var min = Number.MAX_SAFE_INTEGER\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n arryMin.push({value: a[i][j], i, j})\r\n }\r\n }\r\n arryMin.sort((a, b) => a.value - b.value)\r\n\r\n for (let k = 0; k < m; k++) {\r\n var value = arryMin[k]\r\n used[value.i][value.j] = true\r\n copy[value.i][k] = value.value\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n var index = 0\r\n for (let j = 0; j < m; j++) {\r\n if (!used[i][j]) {\r\n while (copy[i][index] !== undefined) index++\r\n copy[i][index] = a[i][j]\r\n }\r\n }\r\n }\r\n for (let k = 0; k < n; k++) {\r\n console.log(copy[k].join(' '))\r\n }\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) arr.push(iInpArr());\r\n let narr = [];\r\n arr.sort((a, b) => a - b);\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) narr.push({ val: arr[i][j], i: i, j: j });\r\n narr.sort((a, b) => a.val - b.val);\r\n for (let k = m - 1; k >= 0; k--) {\r\n let i = narr[k].i;\r\n let j = narr[k].j;\r\n [arr[i][j], arr[i][k]] = [arr[i][k], arr[i][j]];\r\n }\r\n for (let i = 0; i < n; i++) console.log(arr[i].join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n if (n === 1) {\r\n console.log(arr[0].join(\" \"));\r\n continue;\r\n }\r\n if (m === 1) {\r\n for (let i = 0; i < n; i++) {\r\n console.log(arr[i][0]);\r\n }\r\n continue;\r\n }\r\n //for (let i = 0; i < n; i++) arr[i].sort((a, b) => b - a);\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) arr[i][j] = { val: arr[i][j], i: i, j: j };\r\n let narr = [];\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) narr.push(arr[i][j]);\r\n narr.sort((a, b) => a.val - b.val);\r\n let narr1 = [];\r\n for (let i = 0; i < m; i++) narr1.push(narr[i]);\r\n narr1.sort((a, b) => a.i - b.i);\r\n const replace = (i, ele) => {\r\n [arr[ele.i][i], arr[ele.i][ele.j]] = [arr[ele.i][ele.j], arr[ele.i][i]];\r\n };\r\n for (let i = 0; i < m; i++) replace(i, narr1[i]);\r\n for (let i = 0; i < n; i++) {\r\n let res = \"\";\r\n for (let j = 0; j < m; j++) {\r\n res += arr[i][j].val + \" \";\r\n }\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n if (n === 1) {\r\n console.log(arr[0].join(\" \"));\r\n continue;\r\n }\r\n if (m === 1) {\r\n for (let i = 0; i < n; i++) {\r\n console.log(arr[i][0]);\r\n }\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) arr[i].sort((a, b) => b - a);\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) arr[i][j] = { val: arr[i][j], i: i, j: j };\r\n let narr = [];\r\n for (let i = 0; i < n; i++)\r\n for (let j = 0; j < m; j++) narr.push(arr[i][j]);\r\n narr.sort((a, b) => a.val - b.val);\r\n const replace = (i, ele) => {\r\n [arr[ele.i][i], arr[ele.i][ele.j]] = [arr[ele.i][ele.j], arr[ele.i][i]];\r\n };\r\n for (let i = 0; i < m; i++) replace(i, narr[i]);\r\n for (let i = 0; i < n; i++) {\r\n let res = \"\";\r\n for (let j = 0; j < m; j++) {\r\n res += arr[i][j].val + \" \";\r\n }\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n arr[0].sort((a, b) => a - b);\r\n if (n === 1) {\r\n console.log(arr[0].join(\" \"));\r\n continue;\r\n }\r\n if (m === 1) {\r\n for (let i = 0; i < n; i++) {\r\n console.log(arr[i][0]);\r\n }\r\n continue;\r\n }\r\n for (let i = 1; i < n; i++) arr[i].sort((a, b) => b - a);\r\n let res = new Array(n).fill(0).map((cur) => new Array(m).fill(0));\r\n for (let i = 0; i < m; i++) res[0][i] = arr[0][i];\r\n for (let i = 0; i < m; i++) {\r\n for (let k = 1; k < n; k++) {\r\n res[k][i] = arr[k][i];\r\n }\r\n }\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\r\nconst solve = (data, m) => {\r\n\tconst arr = [];\r\n\r\n\tfor (let i=0; i a-b).slice(0, m)\r\n\r\n\t\tif (i%2 === 0) {\r\n\t\t\tarr[i] = arr[i].reverse();\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(arr.map(item => item.join(' ')).join('\\n'))\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i +v);\r\n\t\tconst data = lines.slice(i+1, i+n+1)\r\n\t\t\t.map(line => line.split(' ').map(v => +v));\r\n\r\n\r\n\t\tsolve(data, m);\r\n\r\n\t\ti+=n;\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nconst solve = (data, m) => {\r\n\tconst arr = [];\r\n\r\n\tfor (let i=0; i a-b).slice(0, m)\r\n\r\n\t\tif (i%2 === 2) {\r\n\t\t\tarr[i].reverse();\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(arr.map(item => item.join(' ')).join('\\n'))\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i +v);\r\n\t\tconst data = lines.slice(i+1, i+n+1)\r\n\t\t\t.map(line => line.split(' ').map(v => +v));\r\n\r\n\r\n\t\tsolve(data, m);\r\n\r\n\t\ti+=n;\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nconst solve = (data, m) => {\r\n\tconst arr = [];\r\n\tfor (let i=0; i a-b).slice(0, m));\r\n\t}\r\n\r\n\treturn arr\r\n\t\t.sort((a, b) => a-b)\r\n\t\t.slice(0, m)\r\n\t\t.reduce((acc, item) => acc + item, 0);\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i +v);\r\n\t\tconst data = lines.slice(i+1, i+n+1)\r\n\t\t\t.map(line => line.split(' ').map(v => +v));\r\n\r\n\t\tconsole.log(solve(data, m));\r\n\r\n\t\ti+=n;\r\n\t}\r\n})\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = new Array(n)\r\n var used = new Array(n)\r\n var answer = new Array(n)\r\n\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n used = new Array(m).fill(false)\r\n answer = new Array(m)\r\n }\r\n var copy = []\r\n for (let j = 0; j < n; j++) {\r\n a[j].sort((a, b) =>a - b)\r\n copy = new Array(a[j].length)\r\n // console.log(a[j])\r\n for (let k = 0; k < a[j].length; k++) {\r\n copy[(k+j) %a[j].length] = a[j][k]\r\n }\r\n a[j] = copy\r\n }\r\n for (let j = 0; j < n; j++) {\r\n console.log(a[j].join(' '))\r\n }\r\n\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = new Array(n)\r\n var used = new Array(n)\r\n var answer = new Array(n)\r\n\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n used = new Array(m).fill(false)\r\n answer = new Array(m)\r\n }\r\n for (let j = 0; j < n; j++) {\r\n a[j].sort((a, b) => j % 2 === 0 ? a - b : b - a)\r\n }\r\n for (let j = 0; j < n; j++) {\r\n console.log(a[j].join(' '))\r\n\r\n }\r\n\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = new Array(n)\r\n var used = new Array(n)\r\n var answer = new Array(n)\r\n\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n used = new Array(m).fill(false)\r\n answer = new Array(m)\r\n }\r\n for (let j = 0; j < n; j++) {\r\n a[j].sort((a, b) => j % 2 === 0 ? a - b : b - 1)\r\n }\r\n for (let j = 0; j < n; j++) {\r\n console.log(a[j].join(' '))\r\n\r\n }\r\n\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n })\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst b = Array(n);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tb[i] = rna();\r\n\t\t\tb[i].sort((x, y) => x - y);\r\n\t\t}\r\n\r\n\t\t//console.log('b', b);\r\n\t\tconst paths = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tpaths[i] = [];\r\n\t\t\tlet k = 0;\r\n\t\t\tfor (let j = 0; j < n ; j++) {\r\n\t\t\t\tpaths[i].push(b[j].pop());\r\n\t\t\t\tif (b[j] < b[k]) k = j;\r\n\t\t\t}\r\n\t\t\tb[k].push(paths[i][k]);\r\n\t\t\tpaths[i][k] = b[k].shift();\r\n\t\t}\r\n\t\t//console.log('paths',paths)\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet ans = [];\r\n\t\t\tfor (let j = 0; j < m; j++)\r\n\t\t\t\tans.push(paths[j][i]);\r\n\r\n\t\t\tconsole.log(ans.join(' '));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, m, arr) {\n let combined = [];\n arr.forEach((arr2, k) => {\n arr2.forEach((v, i) => {\n combined.push({ v, k, i });\n });\n });\n for (let i = 0; i < m; i++) {\n let target = combined[i];\n let tmp = arr[target.k][i];\n arr[target.k][i] = target.v;\n arr[target.k][target.i] = tmp;\n }\n arr.forEach((t) => {\n t.forEach((a) => {\n io.write(a);\n });\n io.writeLine('');\n });\n // console.log(arr);\n // for (let i = 0; i < m; i++) {\n // io.write(arr[0].shift()!);\n // for (let j = 1; j < n; j++) {\n // io.write(arr[j].pop()!);\n // }\n // io.writeLine('');\n // }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let m = io.nextNum();\n let arr = [];\n for (let i = 0; i < n; i++) {\n arr.push(io.nextNumArray(m));\n }\n solve(n, m, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, m, arr) {\n arr.forEach((t) => {\n t.sort((a, b) => b - a);\n });\n arr[0].reverse();\n arr.forEach((t) => {\n t.forEach((a) => {\n io.write(a);\n });\n io.writeLine('');\n });\n // console.log(arr);\n // for (let i = 0; i < m; i++) {\n // io.write(arr[0].shift()!);\n // for (let j = 1; j < n; j++) {\n // io.write(arr[j].pop()!);\n // }\n // io.writeLine('');\n // }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let m = io.nextNum();\n let arr = [];\n for (let i = 0; i < n; i++) {\n arr.push(io.nextNumArray(m));\n }\n solve(n, m, arr);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => b - a)\n );\n \n for (var i = 0; i < m; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j !== f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++)\n write(`${a[i][j]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < m; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j !== f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++)\n write(`${a[i][j]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < m; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++)\n write(`${a[i][j]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++)\n write(`${a[i][j]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1]; \n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1];\n var a = []; \n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) { \n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1];\n var a = [];\n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1];\n var a = [];\n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n'); \n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1];\n var a = [];\n\n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n');\n }\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(a => parseInt(a));\n var n = line1[0];\n var m = line1[1];\n\n var a = [];\n \n for (var j = 0; j < n; j++)\n a.push(\n readline().split(' ').map(a => parseInt(a)).sort((a, b) => a - b)\n );\n \n for (var i = 0; i < n; i++) {\n var f = 0;\n for (j = 0; j < n; j++)\n if (a[j][i] < a[f][i])\n f = j;\n \n for (j = 0; j < n; j++)\n if (j != f) {\n var tt = a[j][i];\n a[j][i] = a[j][m - 1];\n a[j][m - 1] = tt;\n }\n }\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < m; i++)\n write(`${a[j][i]} `);\n write('\\n');\n }\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline().split(\" \");\r\n var m = n[1];\r\n n = n[0];\r\n var b = [];\r\n var used = [];\r\n var string = [];\r\n for(s = 0; s < n; s++) {\r\n temp = readline().split(\" \");\r\n for(k = 0; k < temp.length; k++) {temp[k] = parseInt(temp[k]);}\r\n temp.sort(function(a, b) { return a - b; });\r\n b = b.concat(temp);\r\n used[i] = 0;\r\n }\r\n var min = [], max = [], minp = [], maxp = [];\r\n for(j = 0; j < n; j++) {\r\n min[j] = b[m * j];\r\n minp[j] = m * j;\r\n max[j] = b[m * (j + 1) - 1];\r\n maxp[j] = m * (j + 1) - 1;\r\n }\r\n for(q = 0; q < m; q++) {\r\n var index = min.indexOf(Math.min.apply(null, min));\r\n for(r = 0; r < n; r++) {\r\n if(r === index) {\r\n string.push(min[index]);\r\n minp[r] += 1;\r\n min[r] = b[minp[r]];\r\n }\r\n else {\r\n string.push(max[r]);\r\n maxp[r] -= 1;\r\n max[r] = b[maxp[r]];\r\n }\r\n }\r\n }\r\n var output = \"\";\r\n print(string);\r\n for(u = 0; u < n; u++) {\r\n output = \"\";\r\n for(v = 0; v < m; v++) {\r\n output += string[v * n + u] + \" \";\r\n }\r\n output = output.slice(0, output.length - 1);\r\n print(output);\r\n }\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline().split(\" \");\r\n var m = n[1];\r\n n = n[0];\r\n var b = [];\r\n var used = [];\r\n var string = [];\r\n for(s = 0; s < n; s++) {\r\n temp = readline().split(\" \");\r\n for(k = 0; k < temp.length; k++) {temp[k] = parseInt(temp[k]);}\r\n temp.sort(function(a, b) { return a - b; });\r\n b = b.concat(temp);\r\n used[i] = 0;\r\n }\r\n var min = [], max = [], minp = [], maxp = [];\r\n for(j = 0; j < n; j++) {\r\n min[j] = b[m * j];\r\n minp[j] = m * j;\r\n max[j] = b[m * (j + 1) - 1];\r\n maxp[j] = m * (j + 1) - 1;\r\n }\r\n for(q = 0; q < m; q++) {\r\n var index = min.indexOf(Math.min.apply(null, min));\r\n for(r = 0; r < n; r++) {\r\n if(r === index) {\r\n string.push(min[index]);\r\n minp[r] += 1;\r\n min[r] = b[minp[r]];\r\n }\r\n else {\r\n string.push(max[r]);\r\n maxp[r] -= 1;\r\n max[r] = b[maxp[r]];\r\n }\r\n }\r\n }\r\n var output = \"\";\r\n print(string);\r\n for(u = 0; u < n; u++) {\r\n output = \"\";\r\n for(v = 0; v < m; v++) {\r\n output += string[v * n + u] + \" \";\r\n }\r\n output.slice(0, output.length - 1);\r\n print(output);\r\n }\r\n}"}], "src_uid": "a9021fed22299e90aaef50c4d0d9f5b2"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n const sorted = str.split('')\n .sort((a, b) => a < b ? 1 : (b < a ? -1 : 0))\n return sorted[0].charCodeAt(0) - 'a'.charCodeAt(0) + 1\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmax = Math.max(max, alpha.indexOf(s[i]) + 1);\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline()\r\n var arr = readline()\r\n\r\n print(alphabet(arr))\r\n \r\n}\r\n \r\nfunction alphabet(arr){\r\n\r\n var max = -Infinity\r\n for(var l of arr){\r\n max = Math.max(max,l.charCodeAt(0) - 96);\r\n };\r\n return max\r\n}\r\n"}, {"source_code": "t = +readline()\r\n\r\nwhile(t--) {\r\n alphabet = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n x: 24,\r\n y: 25,\r\n z: 26,\r\n }\r\n readline()\r\n s = readline().split('').sort()\r\n\r\n print(alphabet[s[s.length - 1]])\r\n}"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.trim().split(\"\\n\").map(line =>{\r\n\treturn line.trim()\r\n});\r\n main();\r\n});\r\n\r\n \r\n// ********** Code Start **********\r\nfunction findLow(str,n){\r\n \r\n let s = 'abcdefghijklmnopqrstuvwxyz'\r\n \r\n let max = 'a';\r\n for(let i=0;imax){\r\n max = str[i]\r\n // console.log(max)\r\n }\r\n }\r\n let res = 0;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nconst t = readline();\r\nfor (let i = 0; i < t; i++) {\r\n const chars = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n x: 24,\r\n y: 25,\r\n z: 26,\r\n };\r\n var l = readline();\r\n var s = readline();\r\n let maxSize = 0;\r\n for (let i = 0; i < l; i++) {\r\n if (chars[s[i]] > maxSize) {\r\n maxSize = chars[s[i]];\r\n }\r\n }\r\n console.log(maxSize);\r\n}\r\n\r\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n let ans=1;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline();\r\n \r\n for(let i = 0; i input[i] ? max : input[i];\r\n }\r\n console.log(dicc[max]);\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let len = Number(readline());\r\n let s = readline();\r\n console.log(findMedium(len,s))\r\n }\r\n}\r\n\r\nfunction findMedium(len, s) {\r\n let res = s[0].charCodeAt(0)\r\n let a = 97;\r\n for (let i = 1; i < len; i++) {\r\n let ch = s[i].charCodeAt(0)\r\n if (ch > res) {\r\n res = ch\r\n }\r\n }\r\n \r\n return res - a + 1\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar N = readline();\r\n\tvar n = readline();\r\n\tvar arr = alph();\r\n\tvar maxx = 0;\r\n\tfor(var i=0;iparseInt(x));\r\n \r\n //console.log(\"n \" +n )\r\n //console.log(\"s \" + s)\r\n \r\n let max=0;\r\n for(const char of s)\r\n {\r\n let code = char.charCodeAt(0);\r\n //console.log(\"code \" + code)\r\n max = Math.max(max,code)\r\n }\r\n console.log(max - \"a\".charCodeAt(0)+1)\r\n } \r\n}"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n // const alphabet = \"abcdefghijklmnopqrstuvwxyz\".toUpperCase();\r\n let t = int(readLine());\r\n let alphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\n while (t--) {\r\n let ans = 0\r\n // let al = {}\r\n let n = int(readLine())\r\n let str = readLine();\r\n for (let i = 0; i < n; i++) {\r\n ans = Math.max(alphabet.indexOf(str[i]), ans)\r\n }\r\n\r\n console.log(ans + 1)\r\n }\r\n});"}], "negative_code": [{"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.trim().split(\"\\n\").map(line =>{\r\n\treturn line.trim()\r\n});\r\n main();\r\n});\r\n\r\n \r\n// ********** Code Start **********\r\nfunction findLow(str,n){\r\n let s = 'abcdefghijklmnopqrstuvwxyz'\r\n \r\n let max = 'a';\r\n for(let i=0;imax){\r\n max = str[i]\r\n // console.log(max)\r\n }\r\n }\r\n let res = 0;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nconst t = readline();\r\nfor (let i = 0; i < t; i++) {\r\n const chars = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n };\r\n var l = readline();\r\n var s = readline();\r\n let maxSize = 0;\r\n for (let i = 0; i < l; i++) {\r\n if (chars[s[i]] > maxSize) {\r\n maxSize = chars[s[i]];\r\n }\r\n }\r\n console.log(maxSize);\r\n}\r\n \r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\nconst t = 5;\r\nfor (let i = 0; i < t; i++) {\r\n const chars = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n d: 4,\r\n e: 5,\r\n f: 6,\r\n g: 7,\r\n h: 8,\r\n i: 9,\r\n j: 10,\r\n k: 11,\r\n l: 12,\r\n m: 13,\r\n n: 14,\r\n o: 15,\r\n p: 16,\r\n q: 17,\r\n r: 18,\r\n s: 19,\r\n t: 20,\r\n u: 21,\r\n v: 22,\r\n w: 23,\r\n };\r\n var l = 4;\r\n var s = \"down\";\r\n let maxSize = 0;\r\n for (let i = 0; i < l; i++) {\r\n if (chars[s[i]] > maxSize) {\r\n maxSize = chars[s[i]];\r\n }\r\n }\r\n console.log(maxSize);\r\n}\r\n\r\n}"}], "src_uid": "4841cbc3d3ef29929690b78e30fbf22e"} {"source_code": "var readNums = function () {\r\n return readline().split(\" \").map(Number);\r\n};\r\n \r\nvar n = Number(readline());\r\n \r\nfor (var i = 0; i < n; i++) {\r\n var nums = readNums();\r\n var a = nums[0];\r\n var b = nums[1];\r\n if (b % a !== 0) {\r\n print(0, 0);\r\n continue;\r\n }\r\n var k = b / a;\r\n print(1, k);\r\n}", "positive_code": [{"source_code": "T = readline()\r\nwhile (T--) {\r\n s = readline().split(' ') \r\n x = s[0]\r\n y = s[1]\r\n a = 0\r\n b = 0\r\n\r\n if(y%x ==0){\r\n a = 1\r\n b = y/x\r\n }\r\n\r\n print(a, b)\r\n}\r\n"}, {"source_code": "var readNums = function () {\r\n return readline().split(\" \").map(Number);\r\n};\r\n\r\nvar x = Number(readline());\r\n\r\nfor (var p = 0; p < x; p++) {\r\n var nums = readNums();\r\n var a = nums[0];\r\n var b = nums[1];\r\n if (b % a !== 0) {\r\n print(0, 0);\r\n continue;\r\n }\r\n var q = b / a;\r\n print(1, q);\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var x = nextInt();\r\n\t\tvar y = nextInt(); \r\n let c = y/x;\r\n // console.log({c})\r\n if (c < 1 || !Number.isInteger(c)) {\r\n myout('0 0');\r\n continue;\r\n } \r\n\r\n if (c === 1) {\r\n myout('1 1');\r\n continue\r\n }\r\n\r\n for (let i = 2; i <= c; i++) {\r\n const a = Math.log(c)/Math.log(i);\r\n // console.log({i, a, c})\r\n if (Number.isInteger(a)) {\r\n myout(`${a} ${i}`);\r\n break;\r\n }\r\n }\r\n \r\n\t}\r\n}"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (x, y)=>{\n if (y % x !== 0 || x > y) return '0 0';\n if (y === x) return '1 1';\n let d = y / x;\n let dd = d;\n\n for (let i = 2; i <= d; i++) {\n let td = d;\n let count = 0;\n while (td % i === 0) {\n count++;\n td = td / i;\n }\n\n if (td === 1 && count > 0) {\n return `${count} ${i}`;\n }\n }\n\n return '0 0';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [x, y] = ra();\n console.log(`${calc(x, y)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\n\r\nfor(var q=1;q<=T;q++) {\r\n var [x, y] = readline().split(' ').map(w => parseInt(w));\r\n var r = y/x;\r\n var ans = -1;\r\n if(r > 0) {\r\n for(var a=1;a<=10;a++) {\r\n for(var b=1;b<=100;b++) {\r\n var pow = Math.pow(b,a);\r\n if(pow > 1000000000) continue;\r\n if(pow == r) {\r\n ans = [a, b];\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if(ans == -1) ans = [0, 0];\r\n console.log(ans.join(' '));\r\n}"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const [x,y] = get_ints();\r\n \r\n const res = MY_FUNC(x,y);\r\n \r\n console.log(res[0],res[1])\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction MY_FUNC(x,y){\r\n if(y % x !== 0) return [0,0];\r\n return [1, y/x]\r\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let [x,y]=line[i].split(\" \").map(x=>{return parseInt(x)});\r\n // console.log(x,y);\r\n if(y%x==0)\r\n {\r\n let ans=1+' '+y/x;\r\n console.log(ans);\r\n }\r\n else\r\n {\r\n let ans=0+' '+0;\r\n console.log(ans);\r\n }\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n for (let test = 0; test < N; test++) {\r\n let [x, y] = readline().split(' ').map(Number);\r\n if (y % x !== 0) {\r\n output('0 0');\r\n } else {\r\n output(`1 ${y/x}`);\r\n }\r\n }\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split(' ').map(Number);\n\t var x = a[0], y = a[1];\n\t if(y % x){\n\t console.log(0, 0);\n\t continue;\n\t }\n\t y /= x;\n\t console.log(1, y);\n\t}\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar x = nextInt();\r\n\t\tvar y = nextInt();\r\n\t\tif(x == y){\r\n\t\t\tmyout(\"1 1\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar ok = \"0 0\";\r\n\t\tfor(var i = 2; i <= 100; i++){\r\n\t\t\tvar now = x;\r\n\t\t\tvar c = 0;\r\n\t\t\twhile(now < y){\r\n\t\t\t\tnow *= i;\r\n\t\t\t\tc++;\r\n\t\t\t\tif(now == y){\r\n\t\t\t\t\tok = c + \" \" + i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(ok);\r\n\t}\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let n = readSingleInt();\r\n while(n--)\r\n {\r\n let [x,y] = readIntArray();\r\n let k =parseInt((y/x));\r\n let n = k*x;\r\n if(y==n){\r\n console.log(1,k);\r\n\r\n }else{\r\n console.log(\"0 0\");\r\n }\r\n\r\n }\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(x, y) {\r\n if (y % x !== 0) {\r\n console.log('0 0');\r\n } else {\r\n console.log(`1 ${y / x}`);\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n solve(n, m);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (x, y)=>{\n for (let b=1; b<=100; b++){\n let tmp = x*b;\n let a = 1;\n while (tmp {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [x, y] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(x, y).join(' ')\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(x, y) {\n if (y % x) return [0, 0]\n return [1, y / x]\n}\n"}, {"source_code": "var readNums = function () {\n return readline().split(\" \").map(Number);\n};\n\nvar n = Number(readline());\n\nfor (var i = 0; i < n; i++) {\n var nums = readNums();\n var a = nums[0];\n var b = nums[1];\n if (b % a !== 0) {\n print(0, 0);\n continue;\n }\n var k = b / a;\n print(1, k);\n}\n"}, {"source_code": "var tests = parseInt(readline());\r\n var x, y;\r\n for (var t=0; t < tests; t++) {\r\n var xy = readline().split(' ').map(x=>parseInt(x));\r\n x = xy[0];\r\n y = xy[1];\r\n var a = 0, b = 0;\r\n if (y % x == 0) {\r\n a = 1;\r\n b = y / x;\r\n }\r\n \r\n print(a + ' ' + b);\r\n }"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var x = nextInt();\r\n\t\tvar y = nextInt(); \r\n let c = y/x;\r\n // console.log({c})\r\n if (c < 1 || !Number.isInteger(c)) {\r\n myout('0 0');\r\n continue;\r\n } \r\n\r\n if (c === 1) {\r\n myout('1 1');\r\n continue\r\n }\r\n\r\n for (let i = 2; i <= c; i++) {\r\n const a = Math.log(c)/Math.log(i);\r\n // console.log({i, a, c})\r\n if (Number.isInteger(a)) {\r\n myout(`${a} ${i}`);\r\n continue;\r\n }\r\n }\r\n \r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var x = nextInt();\r\n\t\tvar y = nextInt(); \r\n let c = y/x;\r\n // console.log({c})\r\n if (c < 1 || !Number.isInteger(c)) {\r\n myout('0 0');\r\n continue;\r\n } \r\n\r\n if (c === 1) {\r\n myout('1 1');\r\n continue\r\n }\r\n\r\n for (let i = 2; i <= c; i++) {\r\n const a = Math.log(c)/Math.log(i);\r\n console.log({i, a, c})\r\n if (Number.isInteger(a)) {\r\n myout(`${a} ${i}`);\r\n continue;\r\n }\r\n }\r\n \r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n var x = nextInt();\r\n\t\tvar y = nextInt(); \r\n let c = y/x;\r\n // console.log({c})\r\n if (c < 1 || !Number.isInteger(c)) {\r\n myout('0 0');\r\n continue;\r\n } \r\n\r\n if (c === 1) {\r\n myout('1 1');\r\n continue\r\n }\r\n\r\n for (let i = 2; i <= Math.sqrt(c); i++) {\r\n const a = Math.log(c)/Math.log(i);\r\n // console.log({i, a, c})\r\n if (Number.isInteger(a)) {\r\n myout(`${a} ${i}`);\r\n continue;\r\n }\r\n }\r\n \r\n\t}\r\n}"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (x, y)=>{\n if (y % x !== 0 || x > y) return '0 0';\n if (y === x) return '1 1';\n let d = Math.round(y / x);\n let dd = d;\n\n let divs = {};\n for (let i = 2; i <= d; i++) {\n while (d % i === 0) {\n divs[i] = (divs[i] || 0) + 1;\n d = Math.round(d / i);\n }\n }\n let keys = Array.from(Object.keys(divs));\n for (let i = 0; i < keys.length; i++) {\n let a = divs[keys[i]];\n let b = keys[i];\n if (Math.pow(b, a) === dd) {\n return `${a} ${b}`;\n }\n }\n\n return '0 0';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [x, y] = ra();\n console.log(`${calc(x, y)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (x, y)=>{\n if (y % x !== 0 || x > y) return '0 0';\n if (y === x) return '1 1';\n let d = Math.round(y / x);\n\n let divs = {};\n for (let i = 2; i <= d; i++) {\n while (d % i === 0) {\n divs[i] = (divs[i] || 0) + 1;\n d = Math.round(d / i);\n }\n }\n let keys = Array.from(Object.keys(divs));\n if (keys.length !== 1) return '0 0';\n return `${divs[keys[0]]} ${keys[0]}`;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [x, y] = ra();\n console.log(`${calc(x, y)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (x, y)=>{\n if (y % x !== 0) return '0 0';\n if (y === x) return '1 1';\n let d = Math.round(y / x);\n\n let divs = {};\n for (let i = 2; i <= d; i++) {\n while (d % i === 0) {\n divs[i] = (divs[i] || 0) + 1;\n d = Math.round(d / i);\n }\n }\n let keys = Array.from(Object.keys(divs));\n if (keys.length !== 1) return '0 0';\n return `${divs[keys[0]]} ${keys[0]}`;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [x, y] = ra();\n console.log(`${calc(x, y)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [x,y] = get_ints();\r\n\r\n const res = MY_FUNC(x,y);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction MY_FUNC(x,y){\r\n if(y % x !== 0) return [0,0];\r\n return [y/x, 1]\r\n}\r\n "}, {"source_code": "var readNums = function () {\n return readline().split(\" \").map(parseInt);\n};\n\nvar n = parseInt(readline());\n\nfor (var i = 0; i < n; i++) {\n var nums = readNums();\n var a = nums[0];\n var b = nums[1];\n if (b % a !== 0) {\n print(0, 0);\n continue;\n }\n var k = b / a;\n print(1, k);\n}\n"}], "src_uid": "f7defb09175c842de490aa13a4f5a0c9"} {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/554/B \n \n var numeroLineas = readline();\n var lineas = [];\n \n for (var i = 0; i < numeroLineas; i++) {\n lineas.push(readline());\n }\n \n lineas.sort();\n \n var maxLineasRepetidas = 0;\n var repeticionesActuales = 0;\n var lineaAnterior = \"\";\n for (var i = 0; i < numeroLineas; i++) {\n if(lineas[i] != lineaAnterior){\n lineaAnterior = lineas[i];\n if (repeticionesActuales > maxLineasRepetidas){\n maxLineasRepetidas = repeticionesActuales;\n }\n repeticionesActuales = 1;\n }else{\n repeticionesActuales++;\n }\n }\n if (repeticionesActuales > maxLineasRepetidas){\n maxLineasRepetidas = repeticionesActuales;\n }\n write(maxLineasRepetidas);\n})();", "positive_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , k ;\n res = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.brr = [] ;\n \tfor( j = 0 ; j < this.n ; j++ ) {\n \t\tthis.brr.push( [] ) ;\n \t\tfor( k = 0 ; k < this.n ; k++ ) {\n \t\t\tthis.brr[ j ].push( this.arr[ j ][ k ] ) ;\n \t\t}\n \t}\n \tfor( j = 0 ; j < this.n ; j++ ) {\n \t\tif( this.brr[ i ][ j ] == 1 ) {\n \t\t\tfor( k = 0 ; k < this.n ; k++ ) {\n \t\t\t\tif( this.brr[ k ][ j ] == 1 ) {\n \t\t\t\t\tthis.brr[ k ][ j ] = 0 ;\n \t\t\t\t}\n \t\t\t\telse {\n \t\t\t\t\tthis.brr[ k ][ j ] = 1 ;\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t}\n \tb = 0 ;\n \tfor( j = 0 ; j < this.n ; j++ ) {\n \t\ta = 1 ;\n \t\tfor( k = 0 ; k < this.n ; k++ ) {\n \t\t\tif( this.brr[ j ][ k ] == 1 ) {\n \t\t\t\ta = 0 ;\n \t\t\t\tbreak ;\n \t\t\t}\n \t\t}\n \t\tif( a == 1 ) {\n \t\t\tb++ ;\n \t\t}\n \t}\n \tres = Math.max( res , b ) ;\n }\n print( res ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i , j , str ;\n hasMoreInput = true ;\n try {\n this.n = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tstr = irObj.nextString() ;\n \tthis.arr.push( [] ) ;\n \tfor( j = 0 ; j < this.n ; j++ ) {\n \t\tthis.arr[ i ].push( str.charCodeAt( j ) - '0'.charCodeAt( 0 ) ) ;\n \t}\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n\n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n\n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n\n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n var testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n\n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}], "negative_code": [{"source_code": "(function main(){\n http://codeforces.com/problemset/problem/554/B \n \n var numeroLineas = readline();\n var lineas = [];\n \n for (var i = 0; i < numeroLineas; i++) {\n lineas.push(readline());\n }\n \n lineas.sort();\n \n var maxLineasRepetidas = 0;\n var repeticionesActuales = 0;\n var lineaAnterior = \"\";\n for (var i = 0; i < numeroLineas; i++) {\n if(lineas[i] != lineaAnterior){\n lineaAnterior = lineas[i];\n if (repeticionesActuales > maxLineasRepetidas){\n maxLineasRepetidas = repeticionesActuales;\n }\n repeticionesActuales = 0;\n }else{\n repeticionesActuales++;\n }\n }\n\n write(maxLineasRepetidas);\n})();"}], "src_uid": "f48ddaf1e1db5073d74a2aa318b46704"} {"source_code": "function readInt() {\n return Number(readline());\n}\n\nfunction readInts() {\n return readline().split(\" \").map(Number);\n}\n\nvar n = readInt();\nvar a = readInts();\nvar cnt = {};\na.forEach(function(x) {\n cnt[x] = (cnt[x] || 0) + 1;\n});\nvar mx = 0;\nfor (var k in cnt) {\n mx = Math.max(mx, cnt[k]);\n}\nif (mx > Math.ceil(n / 2)) print(\"NO\");\nelse print(\"YES\");\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet length;\nlet list;\nlistCount = new Array(1001).fill(0);\n\nrl.on('line', (line) => {\n if (!length) {\n length = parseInt(line);\n return;\n }\n list = line.split(' ').map(Number);\n let max = 0;\n for (let i = 0; i < list.length; i++) {\n listCount[list[i]]++;\n if (max < listCount[list[i]]) {\n max = listCount[list[i]];\n }\n }\n const half = length % 2 === 0 ? length / 2 : parseInt(length / 2) + 1;\n\n if (max > half) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n\n});\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const len = +readLine();\n const map = new Map();\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n map.set(n, (map.get(n) || 0) + 1);\n return n;\n });\n\n for (let [_, value] of map) {\n const diff = Math.abs(len - value);\n if (value > diff + 1) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n}\n"}, {"source_code": "print(function(n) {\n\tvar a = readline().split(' ');\n\tvar b = new Int32Array(1005);\n\tfor (var i = 0; i < n; i++)\n\t\tb[a[i]]++;\n\n\tvar bMax = Math.max.apply(0, b);\n\n\treturn bMax > (n + 1) / 2 ? 'NO' : 'YES';\n\n}(+readline()));"}, {"source_code": "print(function(n) {\n\tvar b = new Int32Array(1005);\n\treadline().split(' ').forEach(function(v){\n\t\tb[v]++;\n\t});\n\treturn Math.max.apply(0, b) > (n + 1) / 2 ? 'NO' : 'YES';\n}(+readline()));"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tn = Math.ceil(n / 2);\n\n\tprint((function () {\n\t\tfor (var i = 0, str = readline().split(' '), m = {}, l = str.length; i < l; i++) {\n\t\t\tvar k = Number(str[i]);\n\t\t\tm[k] = m[k] ? m[k] + 1 : 1;\n\t\t\tif (m[k] > n) return 'NO'\n\t\t}\n\t\treturn 'YES';\t\t\n\t})());\n\n}).call(this);\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp ;\n res = 'YES';\n for( i = 0 ; i < this.n ; i++ ) {\n this.vis[ this.arr[ i ] ]++ ;\n }\n for( i = 0 ; i <= 1000 ; i++ ) {\n if( this.vis[ i ] > Math.ceil( this.n / 2 ) ) {\n res = 'NO' ;\n break ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 1010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] != ' ' ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] == ' ' ) {\n endIdx = i;\n break;\n }\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectServerType = function() {\n var serverType = null ;\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n serverType = 'local-node-js' ;\n }\n }\n catch( ex1 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n serverType = 'server-node-js' ;\n }\n else {\n serverType = 'javascript-v8' ;\n }\n }\n catch( ex2 ) {\n serverType = 'server-node-js' ;\n }\n }\n return serverType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , serverType ;\n isNodeJsJudgeServer = false ;\n serverType = this.detectServerType() ;\n if( serverType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( serverType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( serverType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}], "negative_code": [{"source_code": "print(function(n) {\n\tvar b = new Int32Array(1005);\n\treadline().split('').forEach(function(v) {\n\t\tb[v]++;\n\t});\n\treturn Math.max.apply(0, b) > (n + 1) / 2 ? 'NO' : 'YES';\n}(+readline()));"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n this.solveCase = function() {\n var res , i , j , fl , cn ;\n res = 'YES';\n for( i = 1 ; i < this.n ; i++ ) {\n if( this.vis[ i ] == 0 ) {\n this.vis[ i ] = 1 ;\n fl = 0 ;\n cn = 0 ;\n for( j = 0 ; j < this.n ; j++ ) {\n if( this.vis[ j ] == 0 && this.arr[ i ] != this.arr[ j ] ) {\n this.vis[ j ] = 1 ;\n fl = 1 ;\n break ;\n }\n cn++ ;\n }\n if( fl == 0 && cn > 0 ) {\n res = 'NO' ;\n break ;\n }\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 1010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] != ' ' ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] == ' ' ) {\n endIdx = i;\n break;\n }\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectServerType = function() {\n var serverType = null ;\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n serverType = 'local-node-js' ;\n }\n }\n catch( ex1 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n serverType = 'server-node-js' ;\n }\n else {\n serverType = 'javascript-v8' ;\n }\n }\n catch( ex2 ) {\n serverType = 'server-node-js' ;\n }\n }\n return serverType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , serverType ;\n isNodeJsJudgeServer = false ;\n serverType = this.detectServerType() ;\n if( serverType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( serverType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( serverType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp ;\n res = 'YES';\n for( i = 0 ; i < this.n - 1 ; i++ ) {\n fl = 0 ;\n cn = 0 ;\n for( j = i + 1 ; j < this.n ; j++ ) {\n if( this.arr[ i ] != this.arr[ j ] ) {\n temp = this.arr[ j ] ;\n this.arr[ j ] = this.arr[ i + 1 ] ;\n this.arr[ i + 1 ] = temp ;\n fl = 1 ;\n break ;\n }\n cn++ ;\n }\n if( fl == 0 && cn > 0 ) {\n res = 'NO' ;\n break ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 1010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] != ' ' ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ][ i ] == ' ' ) {\n endIdx = i;\n break;\n }\n res += this.allLines[ this.currrentLineNumber ][ i ];\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectServerType = function() {\n var serverType = null ;\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n serverType = 'local-node-js' ;\n }\n }\n catch( ex1 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n serverType = 'server-node-js' ;\n }\n else {\n serverType = 'javascript-v8' ;\n }\n }\n catch( ex2 ) {\n serverType = 'server-node-js' ;\n }\n }\n return serverType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , serverType ;\n isNodeJsJudgeServer = false ;\n serverType = this.detectServerType() ;\n if( serverType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( serverType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( serverType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}], "src_uid": "2c58d94f37a9dd5fb09fd69fc7788f0d"} {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, h, len] = readLine().split(' ').map(Number);\n\t\tlet attacks = readLine().split(' ').map(Number);\n\t\tlet healths = readLine().split(' ').map(Number);\n\t\tlet flag = true;\n\t\tconst enemy = [];\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tenemy.push([ea, eh]);\n\t\t}\n\t\tenemy.sort((a, b) => a[0] - b[0]);\n\t\tconst max = enemy.pop();\n\n\t\tfor (let i = 0; i < enemy.length; i++) {\n\t\t\tlet [ea, eh] = enemy[i];\n\t\t\tconst div = Math.ceil(eh / a);\n\t\t\th -= div * ea;\n\t\t}\n\t\tif (h > 0) {\n\t\t\tlet [ea, eh] = [max[0], max[1]];\n\t\t\tconst hRound = Math.ceil(eh / a);\n\t\t\tconst eRound = Math.ceil(h / ea);\n\t\t\tif (hRound > eRound) console.log('NO');\n\t\t\telse console.log('YES');\n\t\t} else console.log('NO');\n\t}\n}\n", "positive_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n let output = [];\r\n while(testCases--) {\r\n\r\n const [A,B,n] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b =readLine().split(' ').map(Number);\r\n \r\n const res = hero(A,B,n,a,b);\r\n output.push(res);\r\n //console.log(res);\r\n }\r\n console.log(output.join('\\n'));\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nfunction hero(A,B,n,a,b){\r\n let monster = new Array(n);\r\n for(let i = 0; i< n; i++){\r\n monster[i] = [a[i], b[i]];\r\n }\r\n // sort monster by their attack power increasing order\r\n monster.sort((a,b) => a[0] - b[0]);\r\n \r\n for(let i = 0 ; i < n ; i++){\r\n // check if hero still alive?\r\n // console.log(monster[i])\r\n const [dmg, h] = monster[i];\r\n if(B <= 0) {\r\n return 'NO';\r\n }\r\n // how many fights to kill the monster?\r\n const count = Math.ceil(h / A);\r\n // how many fight a monster needs to kill a hero?\r\n const count2 = Math.ceil(B / dmg);\r\n // if a monster needs less fights to kill a hero than the hero cannot save the town\r\n // console.log('count = ', count, 'count2 = ', count2);\r\n if(count2 < count) return 'NO';\r\n // damage the hero\r\n B -= count * dmg; \r\n // console.log('B = ', B);\r\n }\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = hero;"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tlist[j] = {\r\n\t\t\t\ta : alist[j],\r\n\t\t\t\tb : blist[j],\r\n\t\t\t};\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a.a - b.a;\r\n\t\t});\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(B <= 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tvar count = Math.ceil(list[j].b / A);\r\n\t\t\tvar count2 = Math.ceil(B / list[j].a);\r\n\t\t\tif(count2 < count){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tB -= count * list[j].a;\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [A,B,n] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b =readLine().split(' ').map(Number);\r\n \r\n const res = hero(A,B,n,a,b);\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nfunction hero(A,B,n,a,b){\r\n let monster = new Array(n);\r\n for(let i = 0; i< n; i++){\r\n monster[i] = [a[i], b[i]];\r\n }\r\n // sort monster by their attack power increasing order\r\n monster.sort((a,b) => a[0] - b[0]);\r\n \r\n for(let i = 0 ; i < n ; i++){\r\n // check if hero still alive?\r\n // console.log(monster[i])\r\n const [dmg, h] = monster[i];\r\n if(B <= 0) {\r\n return 'NO';\r\n }\r\n // how many fights to kill the monster?\r\n const count = Math.ceil(h / A);\r\n // how many fight a monster needs to kill a hero?\r\n const count2 = Math.ceil(B / dmg);\r\n // if a monster needs less fights to kill a hero than the hero cannot save the town\r\n // console.log('count = ', count, 'count2 = ', count2);\r\n if(count2 < count) return 'NO';\r\n // damage the hero\r\n B -= count * dmg; \r\n // console.log('B = ', B);\r\n }\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = hero;"}, {"source_code": "const processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n let [A, B, n] = lines[cur].split(' ').map(x => +x)\n cur++\n const as = lines[cur].split(' ').map(x => +x)\n cur++\n const bs = lines[cur].split(' ').map(x => Math.ceil((+x)/A))\n let win = false\n for (let i=0; i 0) {\n win = true\n break\n }\n }\n console.log(win ? 'YES' : 'NO')\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, h, len] = readLine().split(' ').map(Number);\n\t\tlet attacks = readLine().split(' ').map(Number);\n\t\tlet healths = readLine().split(' ').map(Number);\n\t\tlet flag = true;\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tconst div = Math.floor(eh / a);\n\t\t\tconst rem = eh % a;\n\t\t\tconst totalAttack = div + rem;\n\n\t\t\tif (h > 0) {\n\t\t\t\th -= totalAttack * ea;\n\t\t\t\thealths[i] = 0;\n\t\t\t}\n\t\t}\n\t\tlet count = 0;\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tif (eh <= 0) count++;\n\t\t}\n\n\t\tif (count === len) {\n\t\t\tif (h <= 0) {\n\t\t\t\tif (Math.abs(h) <= attacks[len - 1]) {\n\t\t\t\t\tconsole.log('YES');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('NO');\n\t\t\t\t}\n\t\t\t} else console.log('YES');\n\t\t} else console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, h, len] = readLine().split(' ').map(Number);\n\t\tlet attacks = readLine().split(' ').map(Number);\n\t\tlet healths = readLine().split(' ').map(Number);\n\t\tlet flag = true;\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tconst div = Math.floor(eh / a);\n\t\t\tconst rem = eh % a;\n\t\t\tconst totalAttack = div + rem;\n\n\t\t\tif ((totalAttack > 1 && h > (totalAttack - 1) * ea) || (totalAttack === 1 && h > 0)) {\n\t\t\t\th -= totalAttack * ea;\n\t\t\t\thealths[i] = 0;\n\t\t\t} else {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (flag) console.log('YES');\n\t\telse console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, h, len] = readLine().split(' ').map(Number);\n\t\tlet attacks = readLine().split(' ').map(Number);\n\t\tlet healths = readLine().split(' ').map(Number);\n\t\tlet flag = true;\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tconst div = Math.floor(eh / a);\n\t\t\tconst rem = eh % a;\n\t\t\tconst totalAttack = div + rem;\n\t\t\tif (h > (totalAttack - 1) * ea) {\n\t\t\t\th -= totalAttack * ea;\n\t\t\t\thealths[i] = 0;\n\t\t\t} else {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (flag) console.log('YES');\n\t\telse console.log('NO');\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, h, len] = readLine().split(' ').map(Number);\n\t\tlet attacks = readLine().split(' ').map(Number);\n\t\tlet healths = readLine().split(' ').map(Number);\n\t\tlet flag = true;\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [ea, eh] = [attacks[i], healths[i]];\n\t\t\tconst div = Math.floor(eh / a);\n\t\t\tif (h > 0) {\n\t\t\t\teh = eh - div * a;\n\t\t\t\th -= div * ea;\n\t\t\t\thealths[i] = eh;\n\t\t\t} else {\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (flag) {\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\tconst [ea, eh] = [attacks[i], healths[i]];\n\t\t\t\tif (eh > 0 && h > 0) {\n\t\t\t\t\th -= ea;\n\t\t\t\t} else if (eh > 0 && h <= 0) {\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (flag) console.log('YES');\n\t\t\telse console.log('NO');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tlist[j] = {\r\n\t\t\t\tA : alist[j],\r\n\t\t\t\tB : blist[j],\r\n\t\t\t\treq : Math.ceil(blist[j] / A) * alist[j]\r\n\t\t\t};\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a.req - b.req;\r\n\t\t});\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0 ; j < N; j++){\r\n\t\t\tvar MtoHcount = Math.ceil(B / list[j].A);\r\n\t\t\tvar HtoMcount = Math.ceil(list[j].B / A);\r\n\t\t\tif(HtoMcount > MtoHcount){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tB -= HtoMcount * list[j].A;\r\n\t\t\tif(j < N - 1 && B <= 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0 ; j < N; j++){\r\n\t\t\tvar HtoMcount = Math.ceil(blist[j] / A);\r\n\t\t\tvar MtoHcount = Math.ceil(B / alist[j]);\r\n\t\t\tif(HtoMcount > MtoHcount){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tB -= HtoMcount * alist[j];\r\n\t\t\tif(j < N - 1 && B <= 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [A,B,n] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b =readLine().split(' ').map(Number);\r\n \r\n const res = hero(A,B,n,a,b);\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nfunction hero(A,B,n,a,b){\r\n const monster = new Array(n);\r\n for(let i = 0; i< n; i++){\r\n monster[i] = [a[i], b[i]];\r\n }\r\n // console.log(monster);\r\n monster.sort((a,b) => a[0] > b[0]);\r\n // console.log(monster);\r\n for(let i = 0 ; i < n ; i++){\r\n // check if hero still alive?\r\n if(B <= 0) {\r\n return 'NO';\r\n }\r\n // how many fights to kill the monster?\r\n const count = Math.ceil(monster[i][1] / A);\r\n // how many fight a monster needs to kill a hero?\r\n const count2 = Math.ceil(B / monster[i][0]);\r\n // if a monster needs less fights to kill a hero than the hero cannot save the town\r\n if(count2 < count) return 'NO';\r\n // damage the hero\r\n B -= count * a[i]; \r\n }\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = hero;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [A,B,n] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b =readLine().split(' ').map(Number);\r\n \r\n const res = hero(A,B,n,a,b);\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nfunction hero(A,B,n,a,b){\r\n let monster_health = b.reduce((a,b) => a + b);\r\n const hero_health = B;\r\n for(let i = 0 ; i < n ; i++){\r\n // check if hero still alive?\r\n if(B <= 0) {\r\n return 'NO';\r\n }\r\n // how many fights to kill the monster?\r\n const count = Math.ceil(b[i] / A);\r\n // how many fight a monster needs to kill a hero?\r\n const count2 = Math.ceil(B / a[i]);\r\n // if a monster needs less fights to kill a hero than the hero cannot save the town\r\n if(count2 < count) return 'NO';\r\n // damage the hero\r\n B -= count * a[i]; \r\n }\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = hero;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [A,B,n] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b =readLine().split(' ').map(Number);\r\n \r\n const res = hero(A,B,n,a,b);\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nfunction hero(A,B,n,a,b){\r\n //amount of monster health\r\n // console.log('A = ', A, 'B = ', B, 'n = ', n, 'a = ', a, 'b = ', b);\r\n let curr_healt = B;\r\n for(let i = 0 ; i < n; i++){\r\n if(curr_healt <= 0 ) {\r\n return 'NO';\r\n } \r\n // calc how many fight needs to finnish the monster?\r\n let count = Math.ceil(b[i]/A);\r\n curr_healt = curr_healt - (a[i] * count);\r\n if(curr_healt <= 0 && i == n - 1){\r\n curr_healt = Math.min(curr_healt + (a[i] * count), B);\r\n while(curr_healt > 0 || b[i] > 0){\r\n curr_healt -= a[i];\r\n b[i] -= A;\r\n if(curr_healt <= 0 || b[i] <= 0) break;\r\n } \r\n if(b[i] <= 0 ){\r\n return 'YES';\r\n } else {\r\n return 'NO';\r\n } \r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = hero;"}], "src_uid": "b63a6369023642a8e7e8f449d7d4b73f"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, k, r, c] = readline().split(' ').map(Number);\r\n\r\n let rmod = r % k;\r\n let cmod = c % k;\r\n\r\n let top = [];\r\n let bottom = [];\r\n\r\n let cmod1 = cmod;\r\n for (let row = r; row <= n; row++) {\r\n let line = '';\r\n\r\n for (let col = 1; col <= n; col++) {\r\n if (col % k === cmod1) line += 'X'; else line += '.';\r\n }\r\n top.push(line);\r\n cmod1++;\r\n if (cmod1 === k) cmod1 = 0;\r\n }\r\n\r\n let cmod2 = cmod - 1;\r\n if (cmod2 < 0) cmod2 = k - 1;\r\n if (r > 1) {\r\n for (let row = r - 1; row > 0; row--) {\r\n let line = '';\r\n \r\n for (let col = 1; col <= n; col++) {\r\n if (col % k === cmod2) line += 'X'; else line += '.';\r\n }\r\n bottom.push(line);\r\n cmod2--;\r\n if (cmod2 < 0) cmod2 = k - 1;\r\n }\r\n }\r\n\r\n bottom.reverse();\r\n \r\n let arr = [...bottom, ...top];\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n output(arr[i]);\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n let [n, k, r, c] = rns(4);\r\n r--;\r\n c--;\r\n r = r % k;\r\n c = c % k;\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(n).fill('.'));\r\n for (let i = 0; i < k; i++) {\r\n res[r][c] = 'X';\r\n r = (r + 1) % k;\r\n c = (c + 1) % k;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n res[i][j] = res[i % k][j % k];\r\n }\r\n }\r\n return res.map(arr => arr.join('')).join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "1cbbf71a8e50b58547d1f74437509319"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n const nums = readline().split(\" \").map(x => BigInt(x));\n for (var i=0; i14 && top>0 && top<7) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n", "positive_code": [{"source_code": "// thanks https://github.com/peterolson/BigInteger.js/tree/master\n\nvar bigInt = (function (undefined) {\n \"use strict\";\n\n var BASE = 1e7,\n LOG_BASE = 7,\n MAX_INT = 9007199254740992,\n MAX_INT_ARR = smallToArray(MAX_INT),\n DEFAULT_ALPHABET = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n var supportsNativeBigInt = typeof BigInt === \"function\";\n\n function Integer(v, radix, alphabet, caseSensitive) {\n if (typeof v === \"undefined\") return Integer[0];\n if (typeof radix !== \"undefined\") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive);\n return parseValue(v);\n }\n\n function BigInteger(value, sign) {\n this.value = value;\n this.sign = sign;\n this.isSmall = false;\n }\n BigInteger.prototype = Object.create(Integer.prototype);\n\n function SmallInteger(value) {\n this.value = value;\n this.sign = value < 0;\n this.isSmall = true;\n }\n SmallInteger.prototype = Object.create(Integer.prototype);\n\n function NativeBigInt(value) {\n this.value = value;\n }\n NativeBigInt.prototype = Object.create(Integer.prototype);\n\n function isPrecise(n) {\n return -MAX_INT < n && n < MAX_INT;\n }\n\n function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes\n if (n < 1e7)\n return [n];\n if (n < 1e14)\n return [n % 1e7, Math.floor(n / 1e7)];\n return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];\n }\n\n function arrayToSmall(arr) { // If BASE changes this function may need to change\n trim(arr);\n var length = arr.length;\n if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {\n switch (length) {\n case 0: return 0;\n case 1: return arr[0];\n case 2: return arr[0] + arr[1] * BASE;\n default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;\n }\n }\n return arr;\n }\n\n function trim(v) {\n var i = v.length;\n while (v[--i] === 0);\n v.length = i + 1;\n }\n\n function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger\n var x = new Array(length);\n var i = -1;\n while (++i < length) {\n x[i] = 0;\n }\n return x;\n }\n\n function truncate(n) {\n if (n > 0) return Math.floor(n);\n return Math.ceil(n);\n }\n\n function add(a, b) { // assumes a and b are arrays with a.length >= b.length\n var l_a = a.length,\n l_b = b.length,\n r = new Array(l_a),\n carry = 0,\n base = BASE,\n sum, i;\n for (i = 0; i < l_b; i++) {\n sum = a[i] + b[i] + carry;\n carry = sum >= base ? 1 : 0;\n r[i] = sum - carry * base;\n }\n while (i < l_a) {\n sum = a[i] + carry;\n carry = sum === base ? 1 : 0;\n r[i++] = sum - carry * base;\n }\n if (carry > 0) r.push(carry);\n return r;\n }\n\n function addAny(a, b) {\n if (a.length >= b.length) return add(a, b);\n return add(b, a);\n }\n\n function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT\n var l = a.length,\n r = new Array(l),\n base = BASE,\n sum, i;\n for (i = 0; i < l; i++) {\n sum = a[i] - base + carry;\n carry = Math.floor(sum / base);\n r[i] = sum - carry * base;\n carry += 1;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n BigInteger.prototype.add = function (v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.subtract(n.negate());\n }\n var a = this.value, b = n.value;\n if (n.isSmall) {\n return new BigInteger(addSmall(a, Math.abs(b)), this.sign);\n }\n return new BigInteger(addAny(a, b), this.sign);\n };\n BigInteger.prototype.plus = BigInteger.prototype.add;\n\n SmallInteger.prototype.add = function (v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.subtract(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n if (isPrecise(a + b)) return new SmallInteger(a + b);\n b = smallToArray(Math.abs(b));\n }\n return new BigInteger(addSmall(b, Math.abs(a)), a < 0);\n };\n SmallInteger.prototype.plus = SmallInteger.prototype.add;\n\n NativeBigInt.prototype.add = function (v) {\n return new NativeBigInt(this.value + parseValue(v).value);\n }\n NativeBigInt.prototype.plus = NativeBigInt.prototype.add;\n\n function subtract(a, b) { // assumes a and b are arrays with a >= b\n var a_l = a.length,\n b_l = b.length,\n r = new Array(a_l),\n borrow = 0,\n base = BASE,\n i, difference;\n for (i = 0; i < b_l; i++) {\n difference = a[i] - borrow - b[i];\n if (difference < 0) {\n difference += base;\n borrow = 1;\n } else borrow = 0;\n r[i] = difference;\n }\n for (i = b_l; i < a_l; i++) {\n difference = a[i] - borrow;\n if (difference < 0) difference += base;\n else {\n r[i++] = difference;\n break;\n }\n r[i] = difference;\n }\n for (; i < a_l; i++) {\n r[i] = a[i];\n }\n trim(r);\n return r;\n }\n\n function subtractAny(a, b, sign) {\n var value;\n if (compareAbs(a, b) >= 0) {\n value = subtract(a, b);\n } else {\n value = subtract(b, a);\n sign = !sign;\n }\n value = arrayToSmall(value);\n if (typeof value === \"number\") {\n if (sign) value = -value;\n return new SmallInteger(value);\n }\n return new BigInteger(value, sign);\n }\n\n function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT\n var l = a.length,\n r = new Array(l),\n carry = -b,\n base = BASE,\n i, difference;\n for (i = 0; i < l; i++) {\n difference = a[i] + carry;\n carry = Math.floor(difference / base);\n difference %= base;\n r[i] = difference < 0 ? difference + base : difference;\n }\n r = arrayToSmall(r);\n if (typeof r === \"number\") {\n if (sign) r = -r;\n return new SmallInteger(r);\n } return new BigInteger(r, sign);\n }\n\n BigInteger.prototype.subtract = function (v) {\n var n = parseValue(v);\n if (this.sign !== n.sign) {\n return this.add(n.negate());\n }\n var a = this.value, b = n.value;\n if (n.isSmall)\n return subtractSmall(a, Math.abs(b), this.sign);\n return subtractAny(a, b, this.sign);\n };\n BigInteger.prototype.minus = BigInteger.prototype.subtract;\n\n SmallInteger.prototype.subtract = function (v) {\n var n = parseValue(v);\n var a = this.value;\n if (a < 0 !== n.sign) {\n return this.add(n.negate());\n }\n var b = n.value;\n if (n.isSmall) {\n return new SmallInteger(a - b);\n }\n return subtractSmall(b, Math.abs(a), a >= 0);\n };\n SmallInteger.prototype.minus = SmallInteger.prototype.subtract;\n\n NativeBigInt.prototype.subtract = function (v) {\n return new NativeBigInt(this.value - parseValue(v).value);\n }\n NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;\n\n BigInteger.prototype.negate = function () {\n return new BigInteger(this.value, !this.sign);\n };\n SmallInteger.prototype.negate = function () {\n var sign = this.sign;\n var small = new SmallInteger(-this.value);\n small.sign = !sign;\n return small;\n };\n NativeBigInt.prototype.negate = function () {\n return new NativeBigInt(-this.value);\n }\n\n BigInteger.prototype.abs = function () {\n return new BigInteger(this.value, false);\n };\n SmallInteger.prototype.abs = function () {\n return new SmallInteger(Math.abs(this.value));\n };\n NativeBigInt.prototype.abs = function () {\n return new NativeBigInt(this.value >= 0 ? this.value : -this.value);\n }\n\n\n function multiplyLong(a, b) {\n var a_l = a.length,\n b_l = b.length,\n l = a_l + b_l,\n r = createArray(l),\n base = BASE,\n product, carry, i, a_i, b_j;\n for (i = 0; i < a_l; ++i) {\n a_i = a[i];\n for (var j = 0; j < b_l; ++j) {\n b_j = b[j];\n product = a_i * b_j + r[i + j];\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n r[i + j + 1] += carry;\n }\n }\n trim(r);\n return r;\n }\n\n function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE\n var l = a.length,\n r = new Array(l),\n base = BASE,\n carry = 0,\n product, i;\n for (i = 0; i < l; i++) {\n product = a[i] * b + carry;\n carry = Math.floor(product / base);\n r[i] = product - carry * base;\n }\n while (carry > 0) {\n r[i++] = carry % base;\n carry = Math.floor(carry / base);\n }\n return r;\n }\n\n function shiftLeft(x, n) {\n var r = [];\n while (n-- > 0) r.push(0);\n return r.concat(x);\n }\n\n function multiplyKaratsuba(x, y) {\n var n = Math.max(x.length, y.length);\n\n if (n <= 30) return multiplyLong(x, y);\n n = Math.ceil(n / 2);\n\n var b = x.slice(n),\n a = x.slice(0, n),\n d = y.slice(n),\n c = y.slice(0, n);\n\n var ac = multiplyKaratsuba(a, c),\n bd = multiplyKaratsuba(b, d),\n abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));\n\n var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));\n trim(product);\n return product;\n }\n\n // The following function is derived from a surface fit of a graph plotting the performance difference\n // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.\n function useKaratsuba(l1, l2) {\n return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;\n }\n\n BigInteger.prototype.multiply = function (v) {\n var n = parseValue(v),\n a = this.value, b = n.value,\n sign = this.sign !== n.sign,\n abs;\n if (n.isSmall) {\n if (b === 0) return Integer[0];\n if (b === 1) return this;\n if (b === -1) return this.negate();\n abs = Math.abs(b);\n if (abs < BASE) {\n return new BigInteger(multiplySmall(a, abs), sign);\n }\n b = smallToArray(abs);\n }\n if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes\n return new BigInteger(multiplyKaratsuba(a, b), sign);\n return new BigInteger(multiplyLong(a, b), sign);\n };\n\n BigInteger.prototype.times = BigInteger.prototype.multiply;\n\n function multiplySmallAndArray(a, b, sign) { // a >= 0\n if (a < BASE) {\n return new BigInteger(multiplySmall(b, a), sign);\n }\n return new BigInteger(multiplyLong(b, smallToArray(a)), sign);\n }\n SmallInteger.prototype._multiplyBySmall = function (a) {\n if (isPrecise(a.value * this.value)) {\n return new SmallInteger(a.value * this.value);\n }\n return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);\n };\n BigInteger.prototype._multiplyBySmall = function (a) {\n if (a.value === 0) return Integer[0];\n if (a.value === 1) return this;\n if (a.value === -1) return this.negate();\n return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);\n };\n SmallInteger.prototype.multiply = function (v) {\n return parseValue(v)._multiplyBySmall(this);\n };\n SmallInteger.prototype.times = SmallInteger.prototype.multiply;\n\n NativeBigInt.prototype.multiply = function (v) {\n return new NativeBigInt(this.value * parseValue(v).value);\n }\n NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;\n\n function square(a) {\n //console.assert(2 * BASE * BASE < MAX_INT);\n var l = a.length,\n r = createArray(l + l),\n base = BASE,\n product, carry, i, a_i, a_j;\n for (i = 0; i < l; i++) {\n a_i = a[i];\n carry = 0 - a_i * a_i;\n for (var j = i; j < l; j++) {\n a_j = a[j];\n product = 2 * (a_i * a_j) + r[i + j] + carry;\n carry = Math.floor(product / base);\n r[i + j] = product - carry * base;\n }\n r[i + l] = carry;\n }\n trim(r);\n return r;\n }\n\n BigInteger.prototype.square = function () {\n return new BigInteger(square(this.value), false);\n };\n\n SmallInteger.prototype.square = function () {\n var value = this.value * this.value;\n if (isPrecise(value)) return new SmallInteger(value);\n return new BigInteger(square(smallToArray(Math.abs(this.value))), false);\n };\n\n NativeBigInt.prototype.square = function (v) {\n return new NativeBigInt(this.value * this.value);\n }\n\n function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.\n var a_l = a.length,\n b_l = b.length,\n base = BASE,\n result = createArray(b.length),\n divisorMostSignificantDigit = b[b_l - 1],\n // normalization\n lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),\n remainder = multiplySmall(a, lambda),\n divisor = multiplySmall(b, lambda),\n quotientDigit, shift, carry, borrow, i, l, q;\n if (remainder.length <= a_l) remainder.push(0);\n divisor.push(0);\n divisorMostSignificantDigit = divisor[b_l - 1];\n for (shift = a_l - b_l; shift >= 0; shift--) {\n quotientDigit = base - 1;\n if (remainder[shift + b_l] !== divisorMostSignificantDigit) {\n quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);\n }\n // quotientDigit <= base - 1\n carry = 0;\n borrow = 0;\n l = divisor.length;\n for (i = 0; i < l; i++) {\n carry += quotientDigit * divisor[i];\n q = Math.floor(carry / base);\n borrow += remainder[shift + i] - (carry - q * base);\n carry = q;\n if (borrow < 0) {\n remainder[shift + i] = borrow + base;\n borrow = -1;\n } else {\n remainder[shift + i] = borrow;\n borrow = 0;\n }\n }\n while (borrow !== 0) {\n quotientDigit -= 1;\n carry = 0;\n for (i = 0; i < l; i++) {\n carry += remainder[shift + i] - base + divisor[i];\n if (carry < 0) {\n remainder[shift + i] = carry + base;\n carry = 0;\n } else {\n remainder[shift + i] = carry;\n carry = 1;\n }\n }\n borrow += carry;\n }\n result[shift] = quotientDigit;\n }\n // denormalization\n remainder = divModSmall(remainder, lambda)[0];\n return [arrayToSmall(result), arrayToSmall(remainder)];\n }\n\n function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/\n // Performs faster than divMod1 on larger input sizes.\n var a_l = a.length,\n b_l = b.length,\n result = [],\n part = [],\n base = BASE,\n guess, xlen, highx, highy, check;\n while (a_l) {\n part.unshift(a[--a_l]);\n trim(part);\n if (compareAbs(part, b) < 0) {\n result.push(0);\n continue;\n }\n xlen = part.length;\n highx = part[xlen - 1] * base + part[xlen - 2];\n highy = b[b_l - 1] * base + b[b_l - 2];\n if (xlen > b_l) {\n highx = (highx + 1) * base;\n }\n guess = Math.ceil(highx / highy);\n do {\n check = multiplySmall(b, guess);\n if (compareAbs(check, part) <= 0) break;\n guess--;\n } while (guess);\n result.push(guess);\n part = subtract(part, check);\n }\n result.reverse();\n return [arrayToSmall(result), arrayToSmall(part)];\n }\n\n function divModSmall(value, lambda) {\n var length = value.length,\n quotient = createArray(length),\n base = BASE,\n i, q, remainder, divisor;\n remainder = 0;\n for (i = length - 1; i >= 0; --i) {\n divisor = remainder * base + value[i];\n q = truncate(divisor / lambda);\n remainder = divisor - q * lambda;\n quotient[i] = q | 0;\n }\n return [quotient, remainder | 0];\n }\n\n function divModAny(self, v) {\n var value, n = parseValue(v);\n if (supportsNativeBigInt) {\n return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];\n }\n var a = self.value, b = n.value;\n var quotient;\n if (b === 0) throw new Error(\"Cannot divide by zero\");\n if (self.isSmall) {\n if (n.isSmall) {\n return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];\n }\n return [Integer[0], self];\n }\n if (n.isSmall) {\n if (b === 1) return [self, Integer[0]];\n if (b == -1) return [self.negate(), Integer[0]];\n var abs = Math.abs(b);\n if (abs < BASE) {\n value = divModSmall(a, abs);\n quotient = arrayToSmall(value[0]);\n var remainder = value[1];\n if (self.sign) remainder = -remainder;\n if (typeof quotient === \"number\") {\n if (self.sign !== n.sign) quotient = -quotient;\n return [new SmallInteger(quotient), new SmallInteger(remainder)];\n }\n return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];\n }\n b = smallToArray(abs);\n }\n var comparison = compareAbs(a, b);\n if (comparison === -1) return [Integer[0], self];\n if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];\n\n // divMod1 is faster on smaller input sizes\n if (a.length + b.length <= 200)\n value = divMod1(a, b);\n else value = divMod2(a, b);\n\n quotient = value[0];\n var qSign = self.sign !== n.sign,\n mod = value[1],\n mSign = self.sign;\n if (typeof quotient === \"number\") {\n if (qSign) quotient = -quotient;\n quotient = new SmallInteger(quotient);\n } else quotient = new BigInteger(quotient, qSign);\n if (typeof mod === \"number\") {\n if (mSign) mod = -mod;\n mod = new SmallInteger(mod);\n } else mod = new BigInteger(mod, mSign);\n return [quotient, mod];\n }\n\n BigInteger.prototype.divmod = function (v) {\n var result = divModAny(this, v);\n return {\n quotient: result[0],\n remainder: result[1]\n };\n };\n NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;\n\n\n BigInteger.prototype.divide = function (v) {\n return divModAny(this, v)[0];\n };\n NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function (v) {\n return new NativeBigInt(this.value / parseValue(v).value);\n };\n SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;\n\n BigInteger.prototype.mod = function (v) {\n return divModAny(this, v)[1];\n };\n NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function (v) {\n return new NativeBigInt(this.value % parseValue(v).value);\n };\n SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;\n\n BigInteger.prototype.pow = function (v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value,\n value, x, y;\n if (b === 0) return Integer[1];\n if (a === 0) return Integer[0];\n if (a === 1) return Integer[1];\n if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.sign) {\n return Integer[0];\n }\n if (!n.isSmall) throw new Error(\"The exponent \" + n.toString() + \" is too large.\");\n if (this.isSmall) {\n if (isPrecise(value = Math.pow(a, b)))\n return new SmallInteger(truncate(value));\n }\n x = this;\n y = Integer[1];\n while (true) {\n if (b & 1 === 1) {\n y = y.times(x);\n --b;\n }\n if (b === 0) break;\n b /= 2;\n x = x.square();\n }\n return y;\n };\n SmallInteger.prototype.pow = BigInteger.prototype.pow;\n\n NativeBigInt.prototype.pow = function (v) {\n var n = parseValue(v);\n var a = this.value, b = n.value;\n var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2);\n if (b === _0) return Integer[1];\n if (a === _0) return Integer[0];\n if (a === _1) return Integer[1];\n if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];\n if (n.isNegative()) return new NativeBigInt(_0);\n var x = this;\n var y = Integer[1];\n while (true) {\n if ((b & _1) === _1) {\n y = y.times(x);\n --b;\n }\n if (b === _0) break;\n b /= _2;\n x = x.square();\n }\n return y;\n }\n\n BigInteger.prototype.modPow = function (exp, mod) {\n exp = parseValue(exp);\n mod = parseValue(mod);\n if (mod.isZero()) throw new Error(\"Cannot take modPow with modulus 0\");\n var r = Integer[1],\n base = this.mod(mod);\n if (exp.isNegative()) {\n exp = exp.multiply(Integer[-1]);\n base = base.modInv(mod);\n }\n while (exp.isPositive()) {\n if (base.isZero()) return Integer[0];\n if (exp.isOdd()) r = r.multiply(base).mod(mod);\n exp = exp.divide(2);\n base = base.square().mod(mod);\n }\n return r;\n };\n NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;\n\n function compareAbs(a, b) {\n if (a.length !== b.length) {\n return a.length > b.length ? 1 : -1;\n }\n for (var i = a.length - 1; i >= 0; i--) {\n if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;\n }\n return 0;\n }\n\n BigInteger.prototype.compareAbs = function (v) {\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) return 1;\n return compareAbs(a, b);\n };\n SmallInteger.prototype.compareAbs = function (v) {\n var n = parseValue(v),\n a = Math.abs(this.value),\n b = n.value;\n if (n.isSmall) {\n b = Math.abs(b);\n return a === b ? 0 : a > b ? 1 : -1;\n }\n return -1;\n };\n NativeBigInt.prototype.compareAbs = function (v) {\n var a = this.value;\n var b = parseValue(v).value;\n a = a >= 0 ? a : -a;\n b = b >= 0 ? b : -b;\n return a === b ? 0 : a > b ? 1 : -1;\n }\n\n BigInteger.prototype.compare = function (v) {\n // See discussion about comparison with Infinity:\n // https://github.com/peterolson/BigInteger.js/issues/61\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (this.sign !== n.sign) {\n return n.sign ? 1 : -1;\n }\n if (n.isSmall) {\n return this.sign ? -1 : 1;\n }\n return compareAbs(a, b) * (this.sign ? -1 : 1);\n };\n BigInteger.prototype.compareTo = BigInteger.prototype.compare;\n\n SmallInteger.prototype.compare = function (v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n\n var n = parseValue(v),\n a = this.value,\n b = n.value;\n if (n.isSmall) {\n return a == b ? 0 : a > b ? 1 : -1;\n }\n if (a < 0 !== n.sign) {\n return a < 0 ? -1 : 1;\n }\n return a < 0 ? 1 : -1;\n };\n SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;\n\n NativeBigInt.prototype.compare = function (v) {\n if (v === Infinity) {\n return -1;\n }\n if (v === -Infinity) {\n return 1;\n }\n var a = this.value;\n var b = parseValue(v).value;\n return a === b ? 0 : a > b ? 1 : -1;\n }\n NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;\n\n BigInteger.prototype.equals = function (v) {\n return this.compare(v) === 0;\n };\n NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;\n\n BigInteger.prototype.notEquals = function (v) {\n return this.compare(v) !== 0;\n };\n NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;\n\n BigInteger.prototype.greater = function (v) {\n return this.compare(v) > 0;\n };\n NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;\n\n BigInteger.prototype.lesser = function (v) {\n return this.compare(v) < 0;\n };\n NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;\n\n BigInteger.prototype.greaterOrEquals = function (v) {\n return this.compare(v) >= 0;\n };\n NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;\n\n BigInteger.prototype.lesserOrEquals = function (v) {\n return this.compare(v) <= 0;\n };\n NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;\n\n BigInteger.prototype.isEven = function () {\n return (this.value[0] & 1) === 0;\n };\n SmallInteger.prototype.isEven = function () {\n return (this.value & 1) === 0;\n };\n NativeBigInt.prototype.isEven = function () {\n return (this.value & BigInt(1)) === BigInt(0);\n }\n\n BigInteger.prototype.isOdd = function () {\n return (this.value[0] & 1) === 1;\n };\n SmallInteger.prototype.isOdd = function () {\n return (this.value & 1) === 1;\n };\n NativeBigInt.prototype.isOdd = function () {\n return (this.value & BigInt(1)) === BigInt(1);\n }\n\n BigInteger.prototype.isPositive = function () {\n return !this.sign;\n };\n SmallInteger.prototype.isPositive = function () {\n return this.value > 0;\n };\n NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;\n\n BigInteger.prototype.isNegative = function () {\n return this.sign;\n };\n SmallInteger.prototype.isNegative = function () {\n return this.value < 0;\n };\n NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;\n\n BigInteger.prototype.isUnit = function () {\n return false;\n };\n SmallInteger.prototype.isUnit = function () {\n return Math.abs(this.value) === 1;\n };\n NativeBigInt.prototype.isUnit = function () {\n return this.abs().value === BigInt(1);\n }\n\n BigInteger.prototype.isZero = function () {\n return false;\n };\n SmallInteger.prototype.isZero = function () {\n return this.value === 0;\n };\n NativeBigInt.prototype.isZero = function () {\n return this.value === BigInt(0);\n }\n\n BigInteger.prototype.isDivisibleBy = function (v) {\n var n = parseValue(v);\n if (n.isZero()) return false;\n if (n.isUnit()) return true;\n if (n.compareAbs(2) === 0) return this.isEven();\n return this.mod(n).isZero();\n };\n NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;\n\n function isBasicPrime(v) {\n var n = v.abs();\n if (n.isUnit()) return false;\n if (n.equals(2) || n.equals(3) || n.equals(5)) return true;\n if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;\n if (n.lesser(49)) return true;\n // we don't know if it's prime: let the other functions figure it out\n }\n\n function millerRabinTest(n, a) {\n var nPrev = n.prev(),\n b = nPrev,\n r = 0,\n d, t, i, x;\n while (b.isEven()) b = b.divide(2), r++;\n next: for (i = 0; i < a.length; i++) {\n if (n.lesser(a[i])) continue;\n x = bigInt(a[i]).modPow(b, n);\n if (x.isUnit() || x.equals(nPrev)) continue;\n for (d = r - 1; d != 0; d--) {\n x = x.square().mod(n);\n if (x.isUnit()) return false;\n if (x.equals(nPrev)) continue next;\n }\n return false;\n }\n return true;\n }\n\n // Set \"strict\" to true to force GRH-supported lower bound of 2*log(N)^2\n BigInteger.prototype.isPrime = function (strict) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var bits = n.bitLength();\n if (bits <= 64)\n return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);\n var logN = Math.log(2) * bits.toJSNumber();\n var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN);\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt(i + 2));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;\n\n BigInteger.prototype.isProbablePrime = function (iterations, rng) {\n var isPrime = isBasicPrime(this);\n if (isPrime !== undefined) return isPrime;\n var n = this.abs();\n var t = iterations === undefined ? 5 : iterations;\n for (var a = [], i = 0; i < t; i++) {\n a.push(bigInt.randBetween(2, n.minus(2), rng));\n }\n return millerRabinTest(n, a);\n };\n NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;\n\n BigInteger.prototype.modInv = function (n) {\n var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;\n while (!newR.isZero()) {\n q = r.divide(newR);\n lastT = t;\n lastR = r;\n t = newT;\n r = newR;\n newT = lastT.subtract(q.multiply(newT));\n newR = lastR.subtract(q.multiply(newR));\n }\n if (!r.isUnit()) throw new Error(this.toString() + \" and \" + n.toString() + \" are not co-prime\");\n if (t.compare(0) === -1) {\n t = t.add(n);\n }\n if (this.isNegative()) {\n return t.negate();\n }\n return t;\n };\n\n NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;\n\n BigInteger.prototype.next = function () {\n var value = this.value;\n if (this.sign) {\n return subtractSmall(value, 1, this.sign);\n }\n return new BigInteger(addSmall(value, 1), this.sign);\n };\n SmallInteger.prototype.next = function () {\n var value = this.value;\n if (value + 1 < MAX_INT) return new SmallInteger(value + 1);\n return new BigInteger(MAX_INT_ARR, false);\n };\n NativeBigInt.prototype.next = function () {\n return new NativeBigInt(this.value + BigInt(1));\n }\n\n BigInteger.prototype.prev = function () {\n var value = this.value;\n if (this.sign) {\n return new BigInteger(addSmall(value, 1), true);\n }\n return subtractSmall(value, 1, this.sign);\n };\n SmallInteger.prototype.prev = function () {\n var value = this.value;\n if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);\n return new BigInteger(MAX_INT_ARR, true);\n };\n NativeBigInt.prototype.prev = function () {\n return new NativeBigInt(this.value - BigInt(1));\n }\n\n var powersOfTwo = [1];\n while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);\n var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];\n\n function shift_isSmall(n) {\n return Math.abs(n) <= BASE;\n }\n\n BigInteger.prototype.shiftLeft = function (v) {\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + \" is too large for shifting.\");\n }\n if (n < 0) return this.shiftRight(-n);\n var result = this;\n if (result.isZero()) return result;\n while (n >= powers2Length) {\n result = result.multiply(highestPower2);\n n -= powers2Length - 1;\n }\n return result.multiply(powersOfTwo[n]);\n };\n NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;\n\n BigInteger.prototype.shiftRight = function (v) {\n var remQuo;\n var n = parseValue(v).toJSNumber();\n if (!shift_isSmall(n)) {\n throw new Error(String(n) + \" is too large for shifting.\");\n }\n if (n < 0) return this.shiftLeft(-n);\n var result = this;\n while (n >= powers2Length) {\n if (result.isZero() || (result.isNegative() && result.isUnit())) return result;\n remQuo = divModAny(result, highestPower2);\n result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n n -= powers2Length - 1;\n }\n remQuo = divModAny(result, powersOfTwo[n]);\n return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];\n };\n NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;\n\n function bitwise(x, y, fn) {\n y = parseValue(y);\n var xSign = x.isNegative(), ySign = y.isNegative();\n var xRem = xSign ? x.not() : x,\n yRem = ySign ? y.not() : y;\n var xDigit = 0, yDigit = 0;\n var xDivMod = null, yDivMod = null;\n var result = [];\n while (!xRem.isZero() || !yRem.isZero()) {\n xDivMod = divModAny(xRem, highestPower2);\n xDigit = xDivMod[1].toJSNumber();\n if (xSign) {\n xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers\n }\n\n yDivMod = divModAny(yRem, highestPower2);\n yDigit = yDivMod[1].toJSNumber();\n if (ySign) {\n yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers\n }\n\n xRem = xDivMod[0];\n yRem = yDivMod[0];\n result.push(fn(xDigit, yDigit));\n }\n var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);\n for (var i = result.length - 1; i >= 0; i -= 1) {\n sum = sum.multiply(highestPower2).add(bigInt(result[i]));\n }\n return sum;\n }\n\n BigInteger.prototype.not = function () {\n return this.negate().prev();\n };\n NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;\n\n BigInteger.prototype.and = function (n) {\n return bitwise(this, n, function (a, b) { return a & b; });\n };\n NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;\n\n BigInteger.prototype.or = function (n) {\n return bitwise(this, n, function (a, b) { return a | b; });\n };\n NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;\n\n BigInteger.prototype.xor = function (n) {\n return bitwise(this, n, function (a, b) { return a ^ b; });\n };\n NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;\n\n var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;\n function roughLOB(n) { // get lowestOneBit (rough)\n // SmallInteger: return Min(lowestOneBit(n), 1 << 30)\n // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]\n var v = n.value,\n x = typeof v === \"number\" ? v | LOBMASK_I :\n typeof v === \"bigint\" ? v | BigInt(LOBMASK_I) :\n v[0] + v[1] * BASE | LOBMASK_BI;\n return x & -x;\n }\n\n function integerLogarithm(value, base) {\n if (base.compareTo(value) <= 0) {\n var tmp = integerLogarithm(value, base.square(base));\n var p = tmp.p;\n var e = tmp.e;\n var t = p.multiply(base);\n return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 };\n }\n return { p: bigInt(1), e: 0 };\n }\n\n BigInteger.prototype.bitLength = function () {\n var n = this;\n if (n.compareTo(bigInt(0)) < 0) {\n n = n.negate().subtract(bigInt(1));\n }\n if (n.compareTo(bigInt(0)) === 0) {\n return bigInt(0);\n }\n return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));\n }\n NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;\n\n function max(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.greater(b) ? a : b;\n }\n function min(a, b) {\n a = parseValue(a);\n b = parseValue(b);\n return a.lesser(b) ? a : b;\n }\n function gcd(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n if (a.equals(b)) return a;\n if (a.isZero()) return b;\n if (b.isZero()) return a;\n var c = Integer[1], d, t;\n while (a.isEven() && b.isEven()) {\n d = min(roughLOB(a), roughLOB(b));\n a = a.divide(d);\n b = b.divide(d);\n c = c.multiply(d);\n }\n while (a.isEven()) {\n a = a.divide(roughLOB(a));\n }\n do {\n while (b.isEven()) {\n b = b.divide(roughLOB(b));\n }\n if (a.greater(b)) {\n t = b; b = a; a = t;\n }\n b = b.subtract(a);\n } while (!b.isZero());\n return c.isUnit() ? a : a.multiply(c);\n }\n function lcm(a, b) {\n a = parseValue(a).abs();\n b = parseValue(b).abs();\n return a.divide(gcd(a, b)).multiply(b);\n }\n function randBetween(a, b, rng) {\n a = parseValue(a);\n b = parseValue(b);\n var usedRNG = rng || Math.random;\n var low = min(a, b), high = max(a, b);\n var range = high.subtract(low).add(1);\n if (range.isSmall) return low.add(Math.floor(usedRNG() * range));\n var digits = toBase(range, BASE).value;\n var result = [], restricted = true;\n for (var i = 0; i < digits.length; i++) {\n var top = restricted ? digits[i] : BASE;\n var digit = truncate(usedRNG() * top);\n result.push(digit);\n if (digit < top) restricted = false;\n }\n return low.add(Integer.fromArray(result, BASE, false));\n }\n\n var parseBase = function (text, base, alphabet, caseSensitive) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n text = String(text);\n if (!caseSensitive) {\n text = text.toLowerCase();\n alphabet = alphabet.toLowerCase();\n }\n var length = text.length;\n var i;\n var absBase = Math.abs(base);\n var alphabetValues = {};\n for (i = 0; i < alphabet.length; i++) {\n alphabetValues[alphabet[i]] = i;\n }\n for (i = 0; i < length; i++) {\n var c = text[i];\n if (c === \"-\") continue;\n if (c in alphabetValues) {\n if (alphabetValues[c] >= absBase) {\n if (c === \"1\" && absBase === 1) continue;\n throw new Error(c + \" is not a valid digit in base \" + base + \".\");\n }\n }\n }\n base = parseValue(base);\n var digits = [];\n var isNegative = text[0] === \"-\";\n for (i = isNegative ? 1 : 0; i < text.length; i++) {\n var c = text[i];\n if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));\n else if (c === \"<\") {\n var start = i;\n do { i++; } while (text[i] !== \">\" && i < text.length);\n digits.push(parseValue(text.slice(start + 1, i)));\n }\n else throw new Error(c + \" is not a valid character\");\n }\n return parseBaseFromArray(digits, base, isNegative);\n };\n\n function parseBaseFromArray(digits, base, isNegative) {\n var val = Integer[0], pow = Integer[1], i;\n for (i = digits.length - 1; i >= 0; i--) {\n val = val.add(digits[i].times(pow));\n pow = pow.times(base);\n }\n return isNegative ? val.negate() : val;\n }\n\n function stringify(digit, alphabet) {\n alphabet = alphabet || DEFAULT_ALPHABET;\n if (digit < alphabet.length) {\n return alphabet[digit];\n }\n return \"<\" + digit + \">\";\n }\n\n function toBase(n, base) {\n base = bigInt(base);\n if (base.isZero()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n throw new Error(\"Cannot convert nonzero numbers to base 0.\");\n }\n if (base.equals(-1)) {\n if (n.isZero()) return { value: [0], isNegative: false };\n if (n.isNegative())\n return {\n value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber()))\n .map(Array.prototype.valueOf, [1, 0])\n ),\n isNegative: false\n };\n\n var arr = Array.apply(null, Array(n.toJSNumber() - 1))\n .map(Array.prototype.valueOf, [0, 1]);\n arr.unshift([1]);\n return {\n value: [].concat.apply([], arr),\n isNegative: false\n };\n }\n\n var neg = false;\n if (n.isNegative() && base.isPositive()) {\n neg = true;\n n = n.abs();\n }\n if (base.isUnit()) {\n if (n.isZero()) return { value: [0], isNegative: false };\n\n return {\n value: Array.apply(null, Array(n.toJSNumber()))\n .map(Number.prototype.valueOf, 1),\n isNegative: neg\n };\n }\n var out = [];\n var left = n, divmod;\n while (left.isNegative() || left.compareAbs(base) >= 0) {\n divmod = left.divmod(base);\n left = divmod.quotient;\n var digit = divmod.remainder;\n if (digit.isNegative()) {\n digit = base.minus(digit).abs();\n left = left.next();\n }\n out.push(digit.toJSNumber());\n }\n out.push(left.toJSNumber());\n return { value: out.reverse(), isNegative: neg };\n }\n\n function toBaseString(n, base, alphabet) {\n var arr = toBase(n, base);\n return (arr.isNegative ? \"-\" : \"\") + arr.value.map(function (x) {\n return stringify(x, alphabet);\n }).join('');\n }\n\n BigInteger.prototype.toArray = function (radix) {\n return toBase(this, radix);\n };\n\n SmallInteger.prototype.toArray = function (radix) {\n return toBase(this, radix);\n };\n\n NativeBigInt.prototype.toArray = function (radix) {\n return toBase(this, radix);\n };\n\n BigInteger.prototype.toString = function (radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix !== 10) return toBaseString(this, radix, alphabet);\n var v = this.value, l = v.length, str = String(v[--l]), zeros = \"0000000\", digit;\n while (--l >= 0) {\n digit = String(v[l]);\n str += zeros.slice(digit.length) + digit;\n }\n var sign = this.sign ? \"-\" : \"\";\n return sign + str;\n };\n\n SmallInteger.prototype.toString = function (radix, alphabet) {\n if (radix === undefined) radix = 10;\n if (radix != 10) return toBaseString(this, radix, alphabet);\n return String(this.value);\n };\n\n NativeBigInt.prototype.toString = SmallInteger.prototype.toString;\n\n NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); }\n\n BigInteger.prototype.valueOf = function () {\n return parseInt(this.toString(), 10);\n };\n BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;\n\n SmallInteger.prototype.valueOf = function () {\n return this.value;\n };\n SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;\n NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () {\n return parseInt(this.toString(), 10);\n }\n\n function parseStringValue(v) {\n if (isPrecise(+v)) {\n var x = +v;\n if (x === truncate(x))\n return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);\n throw new Error(\"Invalid integer: \" + v);\n }\n var sign = v[0] === \"-\";\n if (sign) v = v.slice(1);\n var split = v.split(/e/i);\n if (split.length > 2) throw new Error(\"Invalid integer: \" + split.join(\"e\"));\n if (split.length === 2) {\n var exp = split[1];\n if (exp[0] === \"+\") exp = exp.slice(1);\n exp = +exp;\n if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error(\"Invalid integer: \" + exp + \" is not a valid exponent.\");\n var text = split[0];\n var decimalPlace = text.indexOf(\".\");\n if (decimalPlace >= 0) {\n exp -= text.length - decimalPlace - 1;\n text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);\n }\n if (exp < 0) throw new Error(\"Cannot include negative exponent part for integers\");\n text += (new Array(exp + 1)).join(\"0\");\n v = text;\n }\n var isValid = /^([0-9][0-9]*)$/.test(v);\n if (!isValid) throw new Error(\"Invalid integer: \" + v);\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(sign ? \"-\" + v : v));\n }\n var r = [], max = v.length, l = LOG_BASE, min = max - l;\n while (max > 0) {\n r.push(+v.slice(min, max));\n min -= l;\n if (min < 0) min = 0;\n max -= l;\n }\n trim(r);\n return new BigInteger(r, sign);\n }\n\n function parseNumberValue(v) {\n if (supportsNativeBigInt) {\n return new NativeBigInt(BigInt(v));\n }\n if (isPrecise(v)) {\n if (v !== truncate(v)) throw new Error(v + \" is not an integer.\");\n return new SmallInteger(v);\n }\n return parseStringValue(v.toString());\n }\n\n function parseValue(v) {\n if (typeof v === \"number\") {\n return parseNumberValue(v);\n }\n if (typeof v === \"string\") {\n return parseStringValue(v);\n }\n if (typeof v === \"bigint\") {\n return new NativeBigInt(v);\n }\n return v;\n }\n // Pre-define numbers in range [-999,999]\n for (var i = 0; i < 1000; i++) {\n Integer[i] = parseValue(i);\n if (i > 0) Integer[-i] = parseValue(-i);\n }\n // Backwards compatibility\n Integer.one = Integer[1];\n Integer.zero = Integer[0];\n Integer.minusOne = Integer[-1];\n Integer.max = max;\n Integer.min = min;\n Integer.gcd = gcd;\n Integer.lcm = lcm;\n Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; };\n Integer.randBetween = randBetween;\n\n Integer.fromArray = function (digits, base, isNegative) {\n return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative);\n };\n\n return Integer;\n})();\n\nconst readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n arr = arr.map(e => bigInt(e));\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const r = e.divmod(14).remainder;\n console.log(e.greater(14) && r.greater(0) && r.lesser(7) ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "\nfunction wr(x) {\n console.log(x)\n}\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr[0])\n\n let num = arr[1].split(' ')\n\n for(let i = 0; i < n; i++) {\n if(num[i] <= 14) {\n wr('NO')\n }\n else{\n let mod = modulo(num[i], 14)\n if(mod >= 1 && mod <= 6) {\n wr('YES')\n }\n else {\n wr('NO')\n }\n }\n }\n})\n\nfunction modulo(dividend, divisor) {\n var partLength = 10;\n\n while (dividend.length > partLength) {\n var part = dividend.substring(0, partLength);\n dividend = (part % divisor) + dividend.substring(partLength); \n }\n\n return dividend % divisor;\n}"}], "negative_code": [{"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n arr = arr.map(e => parseInt(e));\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const r = e % 14;\n console.log(e > 14 && r > 0 && r < 7 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n arr = arr.map(e => parseInt(e));\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const nrDie = Math.floor(e / 21) + 1;\n const nrDots = nrDie * 21;\n const hidden = nrDots - e;\n const upAndBottom = 7 * nrDie;\n const diff = hidden - upAndBottom;\n console.log(diff <= -1 && diff >= -6 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const nrDie = Math.floor(e / 21) + 1;\n const nrDots = nrDie * 21;\n const hidden = nrDots - e;\n const upAndBottom = 7 * (nrDie - 1);\n const diff = hidden - upAndBottom;\n console.log(diff >= 1 && diff <= 6 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n arr = arr.map(e => parseInt(e));\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const nrDie = Math.floor(e / 21) + 1;\n const nrDots = nrDie * 21;\n const hidden = nrDots - e;\n const upAndBottom = 7 * nrDie;\n const diff = Math.abs(hidden - upAndBottom);\n console.log(diff > 0 && diff < 7 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const nrDie = Math.floor(e / 21) + 1;\n const nrDots = nrDie * 21;\n const hidden = nrDots - e;\n const upAndBottom = 7 * nrDie;\n const diff = hidden - upAndBottom;\n console.log(diff <= -1 && diff >= -6 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet arr = [];\n\nreadline.on(\"line\", line => {\n arr.push(line);\n});\n\nreadline.on(\"close\", _ => {\n arr.shift();\n arr = arr[0].split(\" \");\n main();\n});\n\nconst main = () => {\n arr.forEach(e => {\n const nrDie = Math.floor(e / 21) + 1;\n const nrDots = nrDie * 21;\n const hidden = nrDots - e;\n const upAndBottom = 7 * (nrDie - 1);\n const diff = hidden - upAndBottom;\n console.log(diff >= 0 && diff <= 6 ? \"YES\" : \"NO\");\n });\n};\n"}, {"source_code": "\nfunction wr(x) {\n console.log(x)\n}\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr[0])\n\n let num = arr[1].split(' ').map(a => parseInt(a))\n\n for(let i = 0; i < n; i++) {\n if(num[i] <= 14) {\n wr('NO')\n }\n else{\n let mod = num[i] % 14\n if(mod >= 1 && mod <= 6) {\n wr('YES')\n }\n else {\n wr('NO')\n }\n }\n }\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n console.log(s);\n}\n\nfunction main() {\n const t = parseInt(readline());\n const nums = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i 0 && top < 7) {\n print(\"YES\"+top);\n } else {\n print(\"NO\"+top);\n }\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n const nums = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i14 && top>0 && top<7) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n console.log(s);\n}\n\nfunction main() {\n const t = parseInt(readline());\n const nums = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i 0 && top < 7) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}\n"}], "src_uid": "840a4e16454290471faa5a27a3c795d9"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tvar list = \"abcdefghijklmnopqrstuvwxyz\";\n\tfor(var i = 0; i < t; i++){\n\t\tvar s = nextCharArray();\n\t\ts.sort();\n\t\tvar used = new Array(26).fill(0);\n\t\tvar isOK = true;\n\t\tfor(var j = 0; j < s.length; j++){\n\t\t\tif(used[list.indexOf(s[j])] == 1){\n\t\t\t\tisOK = false;\n\t\t\t\tbreak;\n\t\t\t}else{\n\t\t\t\tused[list.indexOf(s[j])] = 1;\n\t\t\t}\n\t\t}\n\t\tvar first = false;\n\t\tvar second = false;\n\t\tfor(var j = 0; j < list.length; j++){\n\t\t\tif(!first && used[j] == 1){\n\t\t\t\tfirst = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(first && used[j] == 0){\n\t\t\t\tsecond = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(second && used[j] == 1){\n\t\t\t\tisOK = false;\n\t\t\t}\n\t\t}\n\t\toutput[i] = (isOK) ? \"Yes\" : \"No\";\n\t}\n\tmyout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (new Set(str).size !== str.length) {\n console.log('NO');\n return;\n }\n\n let ans = 'NO';\n const arr = [...str].sort();\n const first = arr[0].charCodeAt(0) + arr.length - 1;\n const last = arr[arr.length - 1].charCodeAt(0)\n\n if (first === last) {\n ans = 'YES';\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nlet stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n// let stdin = [\n// \"44\",\n// \"ops\",\n// \"test\",\n// \"yes\",\n// \"no\",\n// \"ac\",\n// \"bc\",\n// \"cb\",\n// \"z\",\n// \"a\",\n// \"q\",\n// \"r\",\n// \"u\",\n// \"qq\",\n// \"op\",\n// \"po\",\n// \"xu\",\n// \"ux\",\n// \"xy\",\n// \"yx\",\n// \"a\",\n// \"ab\",\n// \"abc\",\n// \"abcd\",\n// \"abcde\",\n// \"abcdef\",\n// \"abcdefg\",\n// \"bcdefg\",\n// \"cdefg\",\n// \"defg\",\n// \"efgd\",\n// \"efef\",\n// \"abacaba\",\n// \"abz\",\n// \"aoi\",\n// \"ioi\",\n// \"codeforces\",\n// \"klmn\",\n// \"nmlk\",\n// \"kln\",\n// \"klmnl\",\n// \"kmn\",\n// \"kklmn\",\n// \"klmnn\",\n// \"aklkmn\",\n// ]\n// main();\n\nfunction main() {\n // 97 122\n let n = stdin[0];\n for (let i = 1; i <= Number(n); i++) {\n let s = stdin[i].split('').sort();\n let flag = true;\n\n let left = s[0].charCodeAt();\n for (let j = 1; j < s.length; j++) {\n if (s[j].charCodeAt() - left !== 1) {\n console.log('NO');\n flag = false;\n break;\n }\n left = s[j].charCodeAt();\n }\n if (flag) {\n console.log('YES')\n }\n }\n}\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.question('', ans => {\n const n = Number(ans)\n let counter = 1\n const arr = []\n\n rl.on('line', l => {\n counter++\n\n arr.push(l)\n\n if (counter > n) {\n rl.close()\n arr.forEach(item => {\n console.log(diverse(item))\n })\n }\n })\n})\n\nconst diverse = (str) => {\n const arr = str.split('').map(i => i.charCodeAt(0)).sort((a,b) => a - b)\n // console.log(str, arr)\n for (let i = 1; i < arr.length; i++) {\n if ((arr[i] - arr[i-1]) !== 1)\n return \"No\"\n }\n\n return \"Yes\"\n}"}, {"source_code": "function run() {\n const readline = require('readline');\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let total;\n let current = 0\n let strings = [];\n\n rl.on('line', input => {\n if (!total) {\n total = input\n } else if (current < total) {\n current++;\n strings.push(input);\n if (current == total) {\n rl.close();\n strings.forEach(string => {\n const result = stringIsVaried(string);\n console.log(result);\n })\n process.exit();\n }\n }\n });\n}\n\nfunction stringIsVaried(string) {\n if (string.length == 1) return \"Yes\";\n\n let current = 0;\n let charCodes = [];\n let minCode = 123;\n let maxCode = 96;\n\n while (current < string.length) {\n let charCode = string[current].charCodeAt();\n if (charCodes[charCode]) {\n return \"No\"\n } else {\n charCodes[charCode] = true;\n if (minCode > charCode) {\n minCode = charCode\n }\n if (maxCode < charCode) {\n maxCode = charCode\n }\n }\n\n current++;\n }\n\n if ( (maxCode - minCode).length > string.length ) return \"No\"\n let prevCode;\n let isNotVaried = charCodes.some((_, code) => {\n if (prevCode && (prevCode + 1 != code)) {\n return true\n } else {\n prevCode = code\n }\n })\n\n return isNotVaried ? \"No\" : \"Yes\"\n}\n\nrun();\n\nmodule.exports.stringIsVaried = stringIsVaried;"}, {"source_code": "\nvar stdin = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { stdin += data; });\nprocess.stdin.on('end', function () { main(stdin); });\n\nvar stdin_row = 0, stdin_rows;\nfunction readLine() { if (!stdin_rows) stdin_rows = stdin.split(\"\\n\"); return stdin_rows[stdin_row++]; }\nfunction readLineVals() { return readLine().split(/\\s+/); }\n\nconst debug = 0\nvar log = console.log;\nvar dbg = debug ? console.log : _ => {};\n\n/////////////// ignore above this line ////////////////////\n\nfunction main(stdin) {\n\tvar nbq = readLine() * 1;\n\tdbg(\"nbq\", nbq)\n\n\tfor (var iq=0; iq x.charCodeAt(0)).sort((a, b) => a-b )\n\t\tvar tst = true;\n\t\tfor (var i =1; i\", JSON.stringify(txt))\n\n\t}\n}"}, {"source_code": "var solve = function(inp){\n \n var str = inp.split(\"\").sort();\n \n\n for(var i = 0 ; i < str.length-1 ; i++) {\n if (str[i].charCodeAt(0) + 1 != str[i+1].charCodeAt(0))\n return false;\n }\n return true;\n\n};\n\nvar sol = function (){\n var input,cases = readline(),result;\n for ( var i = 0 ; i < cases ; i++){\n input = readline();\n result = solve(input);\n if(result)\n print(\"Yes\");\n else print(\"No\");\n }\n}\nsol();\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.trim()\n .split('\\n')\n .map(str => str.trim())\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction checkString(str){\n\tlet n = str.length\n\tlet prev = str.charCodeAt(0)\n\tfor(let i=1; i 0){\n \tlet string = readLine().trim()\n \tstring = string.split('').sort().join('')\n\t process.stdout.write(checkString(string) + '\\n')\n\t //console.log(string)\n \tt--\n }\n\n process.exit();\n}"}, {"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction readLines(cb) {\n const lines = [];\n let read;\n\n rl.on('line', function(line) {\n if (!read) {\n read = parseInt(line);\n } else {\n lines.push(line);\n }\n if (lines.length === read) {\n rl.close();\n cb(lines);\n }\n });\n};\nreadLines(doIt);\n\nfunction doIt(lines) {\n lines.forEach(line => {\n isDiverse(line);\n });\n\n function isDiverse(line) {\n if (line.length ==1) {\n console.log('Yes');\n return;\n }\n let chars = line.split('').sort().join('');\n let hasConsective = true;\n let repeat = false;\n for (let i=1; ii.charCodeAt(0)).sort((a,b)=>a-b);\n\tvar diffs=codes.map((i,k,a) => i- a[k+1]).slice(0,-1);\n\tprint( diffs.every(i=>i==-1)?'Yes':'No');\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction readLines(cb) {\n const lines = [];\n let read;\n\n rl.on('line', function(line) {\n if (!read) {\n read = parseInt(line);\n } else {\n lines.push(line);\n }\n if (lines.length === read) {\n rl.close();\n cb(lines);\n }\n });\n};\nreadLines(doIt);\n\nfunction doIt(lines) {\n lines.forEach(line => {\n isDiverse(line);\n });\n\n function isDiverse(line) {\n if (line.length ==1) {\n console.log('Yes');\n return;\n }\n let chars = line.split('').sort().join('');\n let hasConsective = false;\n let repeat = false;\n let prev = chars.charCodeAt(0);\n for (let i=1; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (new Set(str).size !== str.length) {\n console.log('NO');\n return;\n }\n\n if (str.length === 1) {\n console.log('YES');\n return;\n }\n\n let ans = 'NO';\n\n for (let i = 1; i < str.length - 1; i++) {\n if (str.charCodeAt(i - 1) + 1 === str.charCodeAt(i) || str.charCodeAt(i + 1) + 1 === str.charCodeAt(i)) {\n ans = 'YES';\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nlet stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n// let stdin = [\n// \"8\",\n// \"fced\",\n// \"xyz\",\n// \"r\",\n// \"dabcef\",\n// \"az\",\n// \"aa\",\n// \"bad\",\n// \"babc\",\n// ]\n// main();\n\nfunction main() {\n let [n] = stdin[0];\n for (let i = 1; i <= n; i++) {\n let s = stdin[i].split('').sort();\n let left = s[0].charCodeAt();\n let flag = true;\n for (let j = 1; j < s.length; j++) {\n if (s[j].charCodeAt() - left !== 1) {\n console.log('NO');\n flag = false;\n break;\n }\n left = s[j].charCodeAt();\n }\n if (flag) {\n console.log('YES')\n }\n }\n}\n\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nlet stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n// let stdin = [\n// \"8\",\n// \"Fced\",\n// \"xyz\",\n// \"r\",\n// \"dabcef\",\n// \"az\",\n// \"aa\",\n// \"bad\",\n// \"babc\",\n// ]\n// main();\n\nfunction main() {\n // 97 122\n let [n] = stdin[0];\n for (let i = 1; i <= n; i++) {\n let s = stdin[i].toLowerCase().split('').sort();\n let flag = true;\n\n for (const val of s) {\n if (val.charCodeAt() < 97 || val.charCodeAt() > 122) {\n console.log('NO');\n flag = false;\n break;\n }\n }\n\n if (!flag) continue;\n let left = s[0].charCodeAt();\n\n for (let j = 1; j < s.length; j++) {\n if (s[j].charCodeAt() - left !== 1) {\n console.log('NO');\n flag = false;\n break;\n }\n left = s[j].charCodeAt();\n }\n if (flag) {\n console.log('YES')\n }\n }\n}\n\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nlet stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n// let stdin = [\n// \"8\",\n// \"fced\",\n// \"xyz\",\n// \"r\",\n// \"dabcef\",\n// \"az\",\n// \"aa\",\n// \"bad\",\n// \"babc\",\n// ]\n// main();\n\nfunction main() {\n // 97 122\n let [n] = stdin[0];\n for (let i = 1; i <= n; i++) {\n let s = stdin[i].split('').sort();\n let left = s[0].charCodeAt();\n let flag = true;\n\n for (const val of s) {\n if (val.toLowerCase().charCodeAt() < 97 || val.toLowerCase().charCodeAt() > 122) {\n console.log('NO');\n flag = false;\n break;\n }\n }\n \n if (!flag) continue;\n\n for (let j = 1; j < s.length; j++) {\n if (s[j].charCodeAt() - left !== 1) {\n console.log('NO');\n flag = false;\n break;\n }\n left = s[j].charCodeAt();\n }\n if (flag) {\n console.log('YES')\n }\n }\n}\n\n\n"}], "src_uid": "02a94c136d3fb198025242e91264823b"} {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n\n const neighbourghoods = new Set()\n for (let j = 0; j 0 && nums[j - 1] !== -1) {\n neighbourghoods.add(nums[j - 1])\n }\n if (j < nums.length - 1 && nums[j + 1] !== -1) {\n neighbourghoods.add(nums[j + 1])\n }\n }\n }\n\n const arr = Array.from(neighbourghoods)\n if (arr.length > 0) {\n const max = Math.max.apply(Math, arr)\n const min = Math.min.apply(Math, arr)\n const answer = Math.round((max + min)/ 2)\n const resNums = nums.map(x => x === -1 ? answer : x)\n\n let maxDiff = 0\n\n for (let i=1; i maxDiff) {\n maxDiff = diff\n }\n }\n console.log(`${maxDiff} ${answer}`)\n } else {\n console.log('0 0')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while (t--) {\n const n = readInt()\n const a = readInts()\n let min = Infinity\n let max = -Infinity\n for (let i = 0; i < n; i++) {\n if (a[i] === -1) {\n if (i > 0 && a[i - 1] !== -1) {\n // wr(min, a[i - 1])\n min = Math.min(min, a[i - 1])\n max = Math.max(max, a[i - 1])\n }\n if (i < n - 1 && a[i + 1] !== -1) {\n min = Math.min(min, a[i + 1])\n max = Math.max(max, a[i + 1])\n }\n }\n }\n // wr('imi', min, max)\n if (min === Infinity) {\n // wr(a)\n wr(0, 0)\n continue\n }\n // wr(min, max)\n let k = Math.round((min + max) / 2)\n let m = -1\n for (let i = 0; i < n; i++) if (a[i] === -1) a[i] = k\n for (let i = 1; i < n; i++) {\n m = Math.max(m, Math.abs(a[i - 1] - a[i]))\n }\n wr(m, k)\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const exist = arr.filter((value, index, array) => value !== -1 && (array[index + 1] === -1 || array[index - 1] === -1));\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n const m = Math.ceil((max - min)/2);\n const k = max - m;\n const filledArr = arr.map(v => v === -1 ? k : v);\n const maxSibl = filledArr.reduce((acc, value, index, array) => {\n if (index === array.length - 1) return acc;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n\n return `${Math.max(maxSibl, m)} ${k}`;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}], "negative_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const a = readInts()\n let sum = 0\n let c = 0\n if(a[1] === -1 && a[0] !== -1){\n sum += a[0]\n c++\n }\n for(let i = 1; i < n; i++) {\n if(a[i - 1] === -1 && a[i] !== -1) {\n sum += a[i]\n c++\n }\n }\n if(sum === 0) {\n // wr(a)\n wr(0, 0)\n continue\n }\n // wr('sum', sum, 'c', c)\n let k = Math.round(sum / c)\n let m = -1\n for(let i = 0; i < n; i++) if(a[i] === -1) a[i] = k\n for(let i = 1; i < n; i++) {\n m = Math.max(m, Math.abs(a[i - 1] - a[i]))\n }\n wr(m, k)\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const a = readInts()\n let sum = 0\n let c = 0\n let map = {}\n for(let i = 0; i < n; i++) {\n if(a[i] === -1) {\n if(i > 0 && !map[i - 1]) {\n map[i - 1] = true\n sum += a[i - 1]\n c++\n }\n if(i < n - 1 && !map[i + 1]) {\n map[i + 1] = true\n sum += a[i + 1]\n c++\n }\n }\n }\n if(sum === 0) {\n // wr(a)\n wr(0, 0)\n continue\n }\n // wr('sum', sum, 'c', c)\n let k = Math.round(sum / c)\n let m = -1\n for(let i = 0; i < n; i++) if(a[i] === -1) a[i] = k\n for(let i = 1; i < n; i++) {\n m = Math.max(m, Math.abs(a[i - 1] - a[i]))\n }\n wr(m, k)\n }\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const a = readInts()\n let sum = 0\n let c = 0\n let map = {}\n for(let i = 0; i < n; i++) {\n if(a[i] === -1) {\n if(i > 0 && !map[i - 1] && a[i - 1] !== -1) {\n map[i - 1] = true\n sum += a[i - 1]\n c++\n }\n if(i < n - 1 && !map[i + 1] && a[i + 1] !== -1) {\n map[i + 1] = true\n sum += a[i + 1]\n c++\n }\n }\n }\n if(sum === 0) {\n // wr(a)\n wr(0, 0)\n continue\n }\n // wr('sum', sum, 'c', c)\n let k = Math.round(sum / c)\n let m = -1\n for(let i = 0; i < n; i++) if(a[i] === -1) a[i] = k\n for(let i = 1; i < n; i++) {\n m = Math.max(m, Math.abs(a[i - 1] - a[i]))\n }\n wr(m, k)\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const maxSibl = arr.reduce((acc, value, index, array) => {\n if (value === -1 || array[index+1] === -1 || array[index+1] === undefined) return acc;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n const exist = arr.filter(value => value !== -1);\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n let m = Math.ceil((max - min)/2);\n const k = min + m;\n\n if (maxSibl > m) {\n return `${maxSibl} ${min}`\n }\n\n return `${m} ${k}`;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const maxSibl = arr.reduce((acc, value, index, array) => {\n if (value === -1 || array[index+1] === -1 || array[index+1] === undefined) return acc;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n const exist = arr.filter(value => value !== -1);\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n let m = Math.ceil((max - min)/2);\n const k = min + m;\n\n if (maxSibl >= m) {\n return `${maxSibl} ${min}`\n }\n\n return `${m} ${k}`;\n\n\n\n\n\n\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const exist = arr.filter(value => value !== -1);\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n let m = Math.ceil((max - min)/2);\n const k = max - m;\n const maxSibl = arr.reduce((acc, value, index, array) => {\n if (array[index+1] === -1 || array[index+1] === undefined) return acc;\n if (value === -1) value = k;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n\n return `${Math.max(maxSibl, m)} ${k}`;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const maxSibl = arr.reduce((acc, value, index, array) => {\n if (value === -1 || array[index+1] === -1 || array[index+1] === undefined) return acc;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n const exist = arr.filter(value => value !== -1);\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n let m = Math.ceil((max - min)/2);\n const k = max - m;\n\n if (maxSibl > m) {\n return `${maxSibl} ${min}`\n }\n\n return `${m} ${k}`;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (arr) {\n const exist = arr.filter(value => value !== -1);\n if (!exist.length) return '0 0';\n const min = Math.min(...exist);\n const max = Math.max(...exist);\n const m = Math.ceil((max - min)/2);\n const k = max - m;\n const filledArr = arr.map(v => v === -1 ? k : v);\n const maxSibl = filledArr.reduce((acc, value, index, array) => {\n if (index === array.length - 1) return acc;\n return Math.max(acc, Math.abs(value - array[index+1]));\n }, 0);\n\n return `${Math.max(maxSibl, m)} ${k}`;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let b = lines[testCount * 2].split(' ').map(Number);\n\n let result = foo(b);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n\n const neighbourghoods = new Set()\n for (let j = 0; j 0 && nums[j - 1] !== -1) {\n neighbourghoods.add(nums[j - 1])\n }\n if (j < nums.length - 1 && nums[j + 1] !== -1) {\n neighbourghoods.add(nums[j + 1])\n }\n }\n }\n\n const arr = new Array(...neighbourghoods)\n if (arr.length) {\n const sum = arr.reduce((r, x) => r + x, 0)\n const answer = Math.round(sum / arr.length)\n const resNums = nums.map(x => x === -1 ? answer : x)\n\n let maxDiff = 0\n\n for (let i=1; i maxDiff) {\n maxDiff = diff\n }\n }\n console.log(`${maxDiff} ${answer}`)\n } else {\n console.log('0 0')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n\n const neighbourghoods = new Set()\n for (let j = 0; j 0 && nums[j - 1] !== -1) {\n neighbourghoods.add(nums[j - 1])\n }\n if (j < nums.length - 1 && nums[j + 1] !== -1) {\n neighbourghoods.add(nums[j + 1])\n }\n }\n }\n\n const arr = new Array(...neighbourghoods)\n if (arr.length) {\n const max = Math.max.apply(Math, arr)\n const min = Math.min.apply(Math, arr)\n const answer = Math.round((max + min)/ 2)\n const resNums = nums.map(x => x === -1 ? answer : x)\n\n let maxDiff = 0\n\n for (let i=1; i maxDiff) {\n maxDiff = diff\n }\n }\n console.log(`${maxDiff} ${answer}`)\n } else {\n console.log('0 0')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "8ffd80167fc4396788b745b53068c9d3"} {"source_code": "var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 26; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char.charCodeAt() && char.charCodeAt() <= 'Z'.charCodeAt()) {\n return true; \n }\n else {\n return false;\n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n\n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);", "positive_code": [{"source_code": "function InputReader(){\n\tthis.arr = [];\n\tthis.ind = 1;\n}\n\nInputReader.prototype.next = function(){\n\tif(this.ind=1) { \n\t\t\tused[i] = true;\n\t\t\tyra++;\n\t\t\tmap[s[i]]--;\n\t\t}\n\tfor(i=0; i=1){\n\t\t\topa++; \n\t\t\tmap[s[i].toUpperCase()]--;\n\t\t}else if(map[s[i].toLowerCase()]>=1){\n\t\t\topa++;\n\t\t\tmap[s[i].toLowerCase()]--;\n\t\t}\n\t}\n\t\n\toutput.write(yra+\" \"+opa);\n\n}\n\nmain();"}, {"source_code": "function isUpperCase(myString) { \n return (myString == myString.toUpperCase()); \n} \nfunction count(menor, maior) {\n var yay = 0;\n var whoops = 0;\n var n_menor = menor;\n var obj_maior = {};\n for (var i = 0, len = maior.length; i < len; i++) {\n \t\t\tvar charz = maior[i];\n var valor = obj_maior[charz];\n obj_maior[charz] = valor ? valor + 1 : 1\n }\n for (var i = 0, len = menor.length; i < len; i++) {\n \tvar charac = menor[i];\n var valor = obj_maior[charac];\n if (valor > 0) {\n yay ++;\n obj_maior[charac] = valor - 1; \n n_menor = n_menor.replace(charac, '');\n }\n\t\t}\n for (var i = 0, len = n_menor.length; i < len; i++) {\n \tvar charac = n_menor[i];\n var upper = charac.toUpperCase()\n if (isUpperCase(charac)) {\n var lower = charac.toLowerCase();\n var valor = obj_maior[lower];\n if (valor > 0) {\n obj_maior[lower] = valor - 1;\n whoops ++;\n }\n } else if (obj_maior[upper] > 0) {\n obj_maior[upper] = obj_maior[upper] - 1;\n whoops ++;\n }\n }\n return {'y' : yay, 'w': whoops};\n}\n \n\n\nvar tayne = readline();\nvar jornal = readline();\nvar result = count(tayne, jornal)\nprint(result['y'] + \" \" +result['w'])\n"}, {"source_code": "function isUpperCase(myString) { \n return (myString == myString.toUpperCase()); \n} \nfunction count(menor, maior) {\n var yay = 0;\n var whoops = 0;\n var n_menor = menor;\n var obj_maior = {};\n for (var i = 0, len = maior.length; i < len; i++) {\n \t\t\tvar charz = maior[i];\n var valor = obj_maior[charz];\n obj_maior[charz] = valor ? valor + 1 : 1\n }\n for (var i = 0, len = menor.length; i < len; i++) {\n \tvar charac = menor[i];\n var valor = obj_maior[charac];\n if (valor > 0) {\n yay ++;\n obj_maior[charac] = valor - 1; \n n_menor = n_menor.replace(charac, '');\n }\n\t\t}\n for (var i = 0, len = n_menor.length; i < len; i++) {\n \tvar charac = n_menor[i];\n var upper = charac.toUpperCase()\n if (isUpperCase(charac)) {\n var lower = charac.toLowerCase();\n var valor = obj_maior[lower];\n if (valor > 0) {\n obj_maior[lower] = valor - 1;\n whoops ++;\n }\n } else if (obj_maior[upper] > 0) {\n obj_maior[upper] = obj_maior[upper] - 1;\n whoops ++;\n }\n }\n return {'y' : yay, 'w': whoops};\n}\n \n\n \nvar tayne = readline();\nvar jornal = readline();\nvar result = count(tayne, jornal)\nprint(result['y'] + \" \" +result['w'])"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaStr = readline(),\n newsStr = readline(),\n remainNewsStr = newsStr.split(''),\n tanyaUpperMap = {},\n tanyaLowerMap = {},\n // YAYMap = {},\n YAY = WHOOPS = 0;\n \n tanyaStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(!tanyaLowerMap[letter]) {\n tanyaLowerMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaLowerMap[letter].totalCount++;\n tanyaLowerMap[letter].YAY++;\n } else {\n if(!tanyaUpperMap[letter]) {\n tanyaUpperMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaUpperMap[letter].totalCount++;\n tanyaUpperMap[letter].YAY++;\n }\n });\n \n newsStr.forEach(function(letter, index) {\n if(letter >= 'a') {\n if(tanyaLowerMap[letter]) {\n if(tanyaLowerMap[letter].YAY > 0) {\n tanyaLowerMap[letter].YAY--;\n tanyaLowerMap[letter].totalCount--;\n YAY++;\n remainNewsStr[index] = '';\n // if(tanyaLowerMap[letter].YAY == 0) YAYMap[letter] = true;\n }\n }\n } else {\n if(tanyaUpperMap[letter]) {\n if(tanyaUpperMap[letter].YAY > 0) {\n tanyaUpperMap[letter].YAY--;\n tanyaUpperMap[letter].totalCount--;\n YAY++;\n remainNewsStr[index] = '';\n // if(tanyaUpperMap[letter].YAY == 0) YAYMap[letter] = true;\n }\n }\n }\n });\n // console.log(YAYMap, remainNewsStr);\n remainNewsStr.forEach(function(letter) {\n if(letter >= 'a') {\n var upperLetter = letter.toUpperCase();\n\n if(tanyaUpperMap[upperLetter]) {\n if(tanyaUpperMap[upperLetter].totalCount > 0) {\n tanyaUpperMap[upperLetter].totalCount--;\n WHOOPS++;\n }\n }\n } else {\n var lowerLetter = letter.toLowerCase();\n\n if(tanyaLowerMap[lowerLetter]) {\n if(tanyaLowerMap[lowerLetter].totalCount > 0) {\n tanyaLowerMap[lowerLetter].totalCount--;\n WHOOPS++;\n }\n }\n }\n });\n \n print(YAY + ' ' + WHOOPS);\n};\nmain();"}, {"source_code": "//var input = \"abacaba\\nAbaCaBA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var a = readline();\n var b = readline();\n var arrL = new Array(26), arrU = new Array(26);\n var arr = [];\n for(var i = 0; i < a.length; i++){\n arr[i] = a.charAt(i);\n }\n for(var i = 0; i < 26; i++){\n arrL[i] = 0;\n arrU[i] = 0;\n }\n var ans1 = 0, ans2 = 0;\n for(var i = 0; i < b.length; i++){\n if(b.charCodeAt(i) >= 'A'.charCodeAt(0) && b.charCodeAt(i) <= 'Z'.charCodeAt(0))\n arrU[b.charCodeAt(i) - 'A'.charCodeAt(0)]++;\n else\n arrL[b.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans1++;\n arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n arr[i] = undefined;\n }\n }else if(arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans1++;\n arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n arr[i] = undefined;\n }\n }\n\n for(var i = 0; i < a.length; i++){\n if(arr[i] != undefined){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans2++;\n arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }else if(arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans2++;\n arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n }\n print(ans1 + \" \" + ans2);\n}\nmain();"}], "negative_code": [{"source_code": "var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 26; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char && char <= 'Z'.charCodeAt()) {\n return true; \n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n \n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);"}, {"source_code": " var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 26; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char && char <= 'Z'.charCodeAt()) {\n return true; \n }\n else {\n return false;\n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n \n print (count[0][0][i], count[0][1][i], count[1][0][i], count[1][1][i]);\n \n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);"}, {"source_code": "var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 26; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char && char <= 'Z'.charCodeAt()) {\n return true; \n }\n else {\n return false;\n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n \n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);"}, {"source_code": "var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 2; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char && char <= 'Z'.charCodeAt()) {\n return true; \n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n \n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);"}, {"source_code": "var s = readline(s);\n var t = readline(t);\n\n var i = 0;\n var take = 0;\n var yay = 0;\n var whoops = 0;\n \n var count = new Array(2);\n \n for (i = 0; i < 2; ++i) {\n count[i] = new Array(2);\n \n for (j = 0; j < 2; ++j) {\n count[i][j] = new Array(26);\n\n for (k = 0; k < 26; ++k) {\n count[i][j][k] = 0;\n }\n }\n }\n\n var min = function(a, b) {\n if (a < b) {\n return a;\n }\n else return b;\n }\n \n var isUpperCase = function(char) {\n if ('A'.charCodeAt() <= char.charCodeAt() && char.charCodeAt() <= 'Z'.charCodeAt()) {\n return true; \n }\n else {\n return false;\n }\n }\n\n for (i = 0; i < s.length; ++i) {\n \n if (isUpperCase(s[i])) {\n count[0][0][s[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[0][1][s[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < t.length; ++i) {\n \n if (isUpperCase(t[i])) {\n count[1][0][t[i].charCodeAt() - 'A'.charCodeAt()]++;\n }\n else count[1][1][t[i].charCodeAt() - 'a'.charCodeAt()]++;\n }\n\n for (i = 0; i < 26; ++i) {\n \n print (count[0][0][i], count[0][1][i], count[1][0][i], count[1][1][i]);\n \n take = min(count[0][0][i], count[1][0][i]);\n count[0][0][i] -= take;\n count[1][0][i] -= take;\n yay += take;\n\n take = min(count[0][1][i], count[1][1][i]);\n count[0][1][i] -= take;\n count[1][1][i] -= take; \n yay += take;\n\n take = min(count[0][0][i] + count[0][1][i], count[1][0][i] + count[1][1][i]);\n whoops += take;\n }\n \n print (yay, whoops);"}, {"source_code": "function isUpperCase(myString) { \n return (myString == myString.toUpperCase()); \n} \nfunction count(menor, maior) {\n var yay = 0;\n var whoops = 0;\n var n_menor = menor;\n var obj_maior = {};\n for (var i = 0, len = maior.length; i < len; i++) {\n \t\t\tvar charz = maior[i];\n var valor = obj_maior[charz];\n obj_maior[charz] = valor ? valor + 1 : 1\n }\n for (var i = 0, len = menor.length; i < len; i++) {\n \t\tvar charac = menor[i];\n var valor = obj_maior[charac];\n if (valor > 0) {\n yay ++;\n obj_maior[charac] = valor - 1; \n n_menor = n_menor.replace(charac, '');\n }\n\t\t}\n for (var i = 0, len = menor.length; i < len; i++) {\n \t\tvar charac = menor[i];\n var upper = charac.toUpperCase()\n if (isUpperCase(charac)) {\n var lower = charac.toLowerCase();\n var valor = obj_maior[lower];\n if (valor > 0) {\n obj_maior[lower] = valor - 1;\n whoops ++;\n }\n } else if (obj_maior[upper] > 0) {\n obj_maior[upper] = obj_maior[upper] - 1;\n whoops ++;\n }\n }\n return {'y' : yay, 'w': whoops};\n}\n \n\n\nvar tayne = readline();\nvar jornal = readline();\nvar result = count(tayne, jornal)\nprint(result['y'] + \" \" +result['w'])\n"}, {"source_code": "/*\nncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK\n*/\nString.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaStr = readline(),\n newsStr = readline(),\n tanyaUpperMap = {},\n tanyaLowerMap = {},\n YAYMap = {},\n YAY = WHOOPS = 0;\n \n tanyaStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(!tanyaLowerMap[letter]) {\n tanyaLowerMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaLowerMap[letter].totalCount++;\n tanyaLowerMap[letter].YAY++;\n } else {\n if(!tanyaUpperMap[letter]) {\n tanyaUpperMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaUpperMap[letter].totalCount++;\n tanyaUpperMap[letter].YAY++;\n }\n });\n \n newsStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(tanyaLowerMap[letter]) {\n if(tanyaLowerMap[letter].YAY > 0) {\n tanyaLowerMap[letter].YAY--;\n tanyaLowerMap[letter].totalCount--;\n YAY++;\n if(tanyaLowerMap[letter].YAY == 0) YAYMap[letter] = true;\n }\n }\n } else {\n if(tanyaUpperMap[letter]) {\n if(tanyaUpperMap[letter].YAY > 0) {\n tanyaUpperMap[letter].YAY--;\n tanyaUpperMap[letter].totalCount--;\n YAY++;\n if(tanyaUpperMap[letter].YAY == 0) YAYMap[letter] = true;\n }\n }\n }\n });\n\n newsStr.forEach(function(letter) {\n if(YAYMap[letter]) return true;\n if(letter >= 'a') {\n var upperLetter = letter.toUpperCase();\n \n if(tanyaUpperMap[upperLetter]) {\n if(tanyaUpperMap[upperLetter].totalCount > 0) {\n tanyaUpperMap[upperLetter].totalCount--;\n WHOOPS++;\n }\n }\n } else {\n var lowerLetter = letter.toLowerCase();\n\n if(tanyaLowerMap[lowerLetter]) {\n if(tanyaLowerMap[lowerLetter].totalCount > 0) {\n tanyaLowerMap[lowerLetter].totalCount--;\n WHOOPS++;\n }\n }\n }\n });\n \n print(YAY + ' ' + WHOOPS);\n};\n\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaMsg = readline(),\n newsMsg = readline(),\n tanyaLetterMap = {},\n tanyaLetterList = [],\n newsLetterMap = {},\n result = [ 0, 0 ];\n \n tanyaMsg.forEach(function(tanyaLetter) {\n if(!tanyaLetterMap[tanyaLetter]) {\n tanyaLetterList.push(tanyaLetter);\n tanyaLetterMap[tanyaLetter] = 0;\n }\n tanyaLetterMap[tanyaLetter]++;\n });\n newsMsg.forEach(function(newsLetter) {\n if(!newsLetterMap[newsLetter]) newsLetterMap[newsLetter] = 0;\n newsLetterMap[newsLetter]++;\n });\n \n tanyaLetterList.forEach(function(tanyaLetter) {\n var tanyaLetterCount = tanyaLetterMap[tanyaLetter],\n newsLetterCount = newsLetterMap[tanyaLetter];\n \n !newsLetterCount ? newsLetterCount = 0 : false;\n \n if(tanyaLetterCount <= newsLetterCount) {\n result[0] += tanyaLetterCount;\n } else {\n result[0] += newsLetterCount;\n result[1] += (tanyaLetterCount - newsLetterCount);\n }\n });\n \n print(result.join(' '));\n};\n\nmain();"}, {"source_code": "function main() {\n var tanyaMsg = readline(),\n newsMsg = readline(),\n tanyaLetterMap = {},\n newsLetterMap = {},\n result = [ 0, 0 ];\n \n newsMsg.split('').forEach(function(newsLetter, index) {\n var tanyaLetter = tanyaMsg[index];\n \n if(tanyaLetter) {\n if(!tanyaLetterMap[tanyaLetter]) tanyaLetterMap[tanyaLetter] = 0;\n tanyaLetterMap[tanyaLetter]++;\n }\n if(!newsLetterMap[newsLetter]) newsLetterMap[newsLetter] = 0;\n newsLetterMap[newsLetter]++;\n });\n \n Object.keys(tanyaLetterMap).forEach(function(tanyaLetter) {\n var tanyaLetterCount = tanyaLetterMap[tanyaLetter],\n newsLetterCount = newsLetterMap[tanyaLetter];\n \n !newsLetterCount ? newsLetterCount = 0 : false;\n \n if(tanyaLetterCount <= newsLetterCount) {\n result[0] += tanyaLetterCount;\n } else {\n result[0] += newsLetterCount;\n result[1] += (tanyaLetterCount - newsLetterCount);\n }\n });\n \n print(result.join(' '));\n};\n\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaStr = readline(),\n newsStr = readline(),\n tanyaUpperMap = {},\n tanyaLowerMap = {},\n YAY = WHOOPS = 0;\n \n tanyaStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(!tanyaLowerMap[letter]) {\n tanyaLowerMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaLowerMap[letter].totalCount++;\n tanyaLowerMap[letter].YAY++;\n } else {\n if(!tanyaUpperMap[letter]) {\n tanyaUpperMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaUpperMap[letter].totalCount++;\n tanyaUpperMap[letter].YAY++;\n }\n });\n \n newsStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(tanyaLowerMap[letter]) {\n if(tanyaLowerMap[letter].YAY > 0) {\n tanyaLowerMap[letter].YAY--;\n tanyaLowerMap[letter].totalCount--;\n YAY++;\n }\n }\n } else {\n if(tanyaUpperMap[letter]) {\n if(tanyaUpperMap[letter].YAY > 0) {\n tanyaUpperMap[letter].YAY--;\n tanyaUpperMap[letter].totalCount--;\n YAY++;\n }\n }\n }\n });\n\n newsStr.forEach(function(letter) {\n if(letter >= 'a') {\n var upperLetter = letter.toUpperCase();\n\n if(tanyaUpperMap[upperLetter]) {\n if(tanyaUpperMap[upperLetter].totalCount > 0) {\n tanyaUpperMap[upperLetter].totalCount--;\n WHOOPS++;\n }\n }\n } else {\n var lowerLetter = letter.toLowerCase();\n\n if(tanyaLowerMap[lowerLetter]) {\n if(tanyaLowerMap[lowerLetter].totalCount > 0) {\n tanyaLowerMap[lowerLetter].totalCount--;\n WHOOPS++;\n }\n }\n }\n });\n \n print(YAY + ' ' + WHOOPS);\n};\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaMsg = readline(),\n newsMsg = readline(),\n tanyaLetterList = [],\n hasLetterCount = hasNotLetterCount = 0;\n \n tanyaMsg.forEach(function(ch) {\n if(!tanyaLetterList[ch.charCodeAt()]) tanyaLetterList[ch.charCodeAt()] = 0;\n tanyaLetterList[ch.charCodeAt()]++;\n });\n\n hasNotLetterCount = tanyaMsg.length;\n \n newsMsg.forEach(function(ch) {\n if(tanyaLetterList[ch.charCodeAt()] > 0) {\n tanyaLetterList[ch.charCodeAt()]--;\n hasLetterCount++;\n }\n });\n \n hasNotLetterCount -= hasLetterCount;\n \n print(hasLetterCount + ' ' + hasNotLetterCount);\n};\n\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaMsg = readline(),\n newsMsg = readline(),\n tanyaLowerList = [],\n tanyaUpperList = [],\n hasLetterCount = hasNotLetterCount = 0;\n \n tanyaMsg.forEach(function(ch) {\n var chVal = ch.charCodeAt();\n \n if(chVal >= 65 && chVal <= 90) {\n if(!tanyaUpperList[chVal - 65]) tanyaUpperList[chVal - 65] = 0;\n tanyaUpperList[chVal - 65]++;\n } else {\n if(!tanyaLowerList[chVal - 97]) tanyaLowerList[chVal - 97] = 0;\n tanyaLowerList[chVal - 97]++;\n }\n });\n\n hasNotLetterCount = tanyaMsg.length;\n \n newsMsg.forEach(function(ch) {\n var chVal = ch.charCodeAt();\n \n if(chVal >= 65 && chVal <= 90) {\n if(tanyaUpperList[chVal - 65] > 0) {\n tanyaUpperList[chVal - 65]--;\n hasLetterCount++;\n }\n } else {\n if(tanyaLowerList[chVal - 97] > 0) {\n tanyaLowerList[chVal - 97]--;\n hasLetterCount++;\n }\n }\n });\n \n hasNotLetterCount -= hasLetterCount;\n \n print(hasLetterCount + ' ' + hasNotLetterCount);\n};\n\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaMsg = readline(),\n newsMsg = readline(),\n tanyaLetterMap = {},\n tanyaLetterList = [],\n newsLetterMap = {},\n tanyaLetterLength = 0,\n result1 = result2 = 0;\n \n tanyaMsg.forEach(function(tanyaLetter) {\n if(!tanyaLetterMap[tanyaLetter]) {\n tanyaLetterList.push(tanyaLetter);\n tanyaLetterMap[tanyaLetter] = 0;\n }\n tanyaLetterMap[tanyaLetter]++;\n });\n tanyaLetterLength = tanyaMsg.length;\n result2 = tanyaLetterLength;\n \n newsMsg.forEach(function(newsLetter) {\n if(tanyaLetterMap[newsLetter] > 0) {\n tanyaLetterMap[newsLetter]--;\n result1++;\n }\n });\n \n result2 -= result1;\n \n print(result1 + ' ' + result2);\n};\n\nmain();"}, {"source_code": "String.prototype.forEach = Array.prototype.forEach;\n\nfunction main() {\n var tanyaStr = readline(),\n newsStr = readline(),\n tanyaUpperMap = {},\n tanyaLowerMap = {},\n YAY = WHOOPS = 0;\n \n tanyaStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(!tanyaLowerMap[letter]) {\n tanyaLowerMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaLowerMap[letter].totalCount++;\n tanyaLowerMap[letter].YAY++;\n } else {\n if(!tanyaUpperMap[letter]) {\n tanyaUpperMap[letter] = {\n 'totalCount' : 0,\n 'YAY' : 0\n };\n }\n tanyaUpperMap[letter].totalCount++;\n tanyaUpperMap[letter].YAY++;\n }\n });\n \n newsStr.forEach(function(letter) {\n if(letter >= 'a') {\n if(tanyaLowerMap[letter]) {\n if(tanyaLowerMap[letter].YAY > 0) {\n tanyaLowerMap[letter].YAY--;\n tanyaLowerMap[letter].totalCount--;\n YAY++;\n }\n }\n } else {\n if(tanyaUpperMap[letter]) {\n if(tanyaUpperMap[letter].YAY > 0) {\n tanyaUpperMap[letter].YAY--;\n tanyaUpperMap[letter].totalCount--;\n YAY++;\n }\n }\n }\n });\n\n newsStr.forEach(function(letter) {\n if(letter >= 'a') {\n var upperLetter = letter.toUpperCase();\n\n if(tanyaUpperMap[upperLetter] && tanyaLowerMap[letter]) {\n if(tanyaUpperMap[upperLetter].totalCount > 0 && tanyaLowerMap[letter].YAY == 0) {\n tanyaUpperMap[upperLetter].totalCount--;\n WHOOPS++;\n }\n }\n } else {\n var lowerLetter = letter.toLowerCase();\n\n if(tanyaLowerMap[lowerLetter] && tanyaUpperMap[letter]) {\n if(tanyaLowerMap[lowerLetter].totalCount > 0 && tanyaUpperMap[letter].YAY == 0) {\n tanyaLowerMap[lowerLetter].totalCount--;\n WHOOPS++;\n }\n }\n }\n });\n \n print(YAY + ' ' + WHOOPS);\n};\nmain();"}, {"source_code": "//var input = \"abacaba\\nAbaCaBA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var a = readline();\n var b = readline();\n var arrL = new Array(26), arrU = new Array(26);\n for(var i = 0; i < 26; i++){\n arrL[i] = 0;\n arrU[i] = 0;\n }\n var ans1 = 0, ans2 = 0;\n for(var i = 0; i < b.length; i++){\n if(b.charCodeAt(i) >= 'A'.charCodeAt(0) && b.charCodeAt(i) <= 'Z'.charCodeAt(0))\n arrU[b.charCodeAt(i) - 'A'.charCodeAt(0)]++;\n else\n arrL[b.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans1++;\n arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }else if(arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans2++;\n arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'a'.charCodeAt(0) && a.charCodeAt(i) <= 'z'.charCodeAt(0)){\n if(arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans1++;\n arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }else if(arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans2++;\n arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n }\n print(ans1 + \" \" + ans2);\n}\nmain();"}, {"source_code": "//var input = \"abacaba\\nAbaCaBA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var a = readline();\n var b = readline();\n var arrL = new Array(26), arrU = new Array(26);\n for(var i = 0; i < 26; i++){\n arrL[i] = 0;\n arrU[i] = 0;\n }\n var ans1 = 0, ans2 = 0;\n for(var i = 0; i < b.length; i++){\n if(b.charCodeAt(i) >= 'A'.charCodeAt(0) && b.charCodeAt(i) <= 'Z'.charCodeAt(0))\n arrU[b.charCodeAt(i) - 'A'.charCodeAt(0)]++;\n else\n arrL[b.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans1++;\n arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }else if(arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans2++;\n arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }else{\n if(arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans1++;\n arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }else if(arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans2++;\n arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n }\n print(ans1 + \" \" + ans2);\n}\nmain();"}, {"source_code": "//var input = \"abacaba\\nAbaCaBA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var a = readline();\n var b = readline();\n var arrL = new Array(26), arrU = new Array(26);\n for(var i = 0; i < 26; i++){\n arrL[i] = 0;\n arrU[i] = 0;\n }\n var ans1 = 0, ans2 = 0;\n for(var i = 0; i < b.length; i++){\n if(b.charCodeAt(i) >= 'A'.charCodeAt(0) && b.charCodeAt(i) <= 'Z'.charCodeAt(0))\n arrU[b.charCodeAt(i) - 'A'.charCodeAt(0)]++;\n else\n arrL[b.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans1++;\n arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }else if(arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans1++;\n arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans2++;\n arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }else if(arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans2++;\n arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n }\n print(ans1 + \" \" + ans2);\n}\nmain();"}, {"source_code": "//var input = \"abacaba\\nAbaCaBA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var a = readline();\n var b = readline();\n var arrL = new Array(26), arrU = new Array(26);\n for(var i = 0; i < 26; i++){\n arrL[i] = 0;\n arrU[i] = 0;\n }\n var ans1 = 0, ans2 = 0;\n for(var i = 0; i < b.length; i++){\n if(b.charCodeAt(i) >= 'A'.charCodeAt(0) && b.charCodeAt(i) <= 'Z'.charCodeAt(0))\n arrU[b.charCodeAt(i) - 'A'.charCodeAt(0)]++;\n else\n arrL[b.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans1++;\n arrU[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }else if(arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans1++;\n arrL[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n\n for(var i = 0; i < a.length; i++){\n if(a.charCodeAt(i) >= 'A'.charCodeAt(0) && a.charCodeAt(i) <= 'Z'.charCodeAt(0)){\n if(arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)] > 0){\n ans2++;\n arrL[a.charCodeAt(i) - 'A'.charCodeAt(0)]--;\n }\n }else if(arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)] > 0){\n ans2++;\n arrU[a.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n }\n }\n print(ans1 + \" \" + ans2);\n}\nmain();"}], "src_uid": "96e2ba997eff50ffb805b6be62c56222"} {"source_code": "var line = readline().split(' ')\nvar n = parseInt(line[0])\n\nvar s = '';\n\nif( n % 2 === 0 ) {\n for( var i = 0; i < n / 2; i++ ) {\n s += '1';\n }\n} else {\n s += '7';\n for( var i = 0; i < (n - 3) / 2; i++ ) {\n s += '1';\n }\n}\n\nprint( s )", "positive_code": [{"source_code": "function sa(n){\nvar arr = [];\n if(n%2!=0){\n\t\t\tarr.push(7);\n\t\t\tn-=3;\n\t\t\t\n }\nfor(var i=0;i= 2) {\n n-= 2;\n arr.push(1);\n }\n} else {\n n-= 3;\n arr.push(7);\n while(n >= 2) {\n n-= 2;\n arr.push(1);\n }\n}\nfor(var i = 0; i < arr.length; i++) {\n write(arr[i]);\n}"}, {"source_code": "x=+readline()\nres = \"\"\nif (x > 2 && x % 2 == 1) res+=\"7\", x -= 3\nwhile(x >= 2) {\n res += \"1\"\n x -= 2\n}\nprint(res)"}, {"source_code": "var n = +readline();\n\nans = ''\n\nx = 0\nx = Math.floor(n / 2)\nif (n % 2 == 1) {\n k = 0\n x -= 1\n}\nwhile (x--) {\n k = 2\n ans += '1'\n} \nif (n % 2 == 1) {\n k = 1\n ans = '7' + ans\n}\nprint(ans)\n"}, {"source_code": "function main() {\n var N = readline();\n var ans = \"\";\n var n = parseInt(N);\n if(n % 2 && n > 2){\n //print(\"7\");\n ans += \"7\";\n n = n - 3;\n }\n for(var i = 0; i < n/2; ++i){\n //print(\"1\");\n ans += \"1\";\n }\n print(ans);\n}\n\nmain();"}, {"source_code": "var n=+readline()\nvar maxLen = 0\nvar s = 0\nvar digit = 0\nvar arr = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nfor (var i = 1; i <= 9; ++i)\n\t\t{\n\t\t\tvar sum = arr[i];\n\t\t\tif (sum <= n)\n\t\t\t{\n\t\t\t\tvar len = 1 + ((n - sum) / 2 | 0);\n\t\t\t\tif (len >= maxLen)\n\t\t\t\t{\n\t\t\t\t\ts = len - 1;\n\t\t\t\t\tmaxLen = len;\n\t\t\t\t\tdigit = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\nvar str = digit\nfor (var i = 0; i < s; ++i)\n\tstr = str + \"1\"\nprint(str)"}, {"source_code": "n = +readline()\ns = \"\";\n\nif (n % 2 === 1) {\n s += \"7\";\n n -= 3;\n}\n\nwhile (n > 0){\n s+=\"1\";\n n -= 2;\n}\n\nprint(s);"}, {"source_code": "var n = readline().split(' ');\n\nif (n % 2 == 1){\n\tvar a = \"7\";\n\tn -= 3;\n}else{\n\tvar a = \"1\";\n\tn -= 2;\n}\n\nwhile (n > 0){\n\ta += \"1\"\n\tn -= 2;\n}\n\nprint(a);"}, {"source_code": "var n = readline();\nvar k = parseInt(n);\nvar j = \"\";\nif (k%2 == 1) {\n\tj += \"7\"\n\tk-=3;\n}\nwhile(k) {\n\tj += \"1\"\n\tk-=2;\n}\nprint(j);"}, {"source_code": "n=+readline();\nx = Math.floor(n/2)\nif (n % 2 == 1) {\n\tx -= 1;\n\tvar s = '7';\n}\nelse {\n\tvar s = '';\n}\nfor (x; x>0; x--){\n\ts += '1';\n}\nprint(s)"}, {"source_code": "var x=readline()\nvar y=Math.floor(x/2)\nvar s='';\nif (x % 2 > 0) {\n y--;\n}\nwhile(y > 0) {\n s=s+'1'\n y--;\n}\nif (x % 2 > 0) {\n s = '7' + s\n}\nprint(s)\n"}, {"source_code": "x=+readline()\n// print(x);\ntmp = \"\";\nwhile(x) {\n if(x%2 == 1){\n tmp += \"7\";\n x -= 3;\n } else {\n tmp += \"1\";\n x -= 2;\n }\n}\nprint(tmp);"}, {"source_code": "x=+readline();\ns=\"\";\nif (x%2) {s += \"7\"; x-=3;}\nwhile(x>=2) {\n s+=\"1\";\n x-=2;\n}\nprint(s);"}, {"source_code": "x=+readline()\ns=''\nif(x%2==1){\n s+='7'\n x-=3\n}\nwhile(x>0) {\n s+='1'\n x-=2\n}\nprint(s)"}, {"source_code": "x=+readline()\ns = \"\"\nwhile(x>0) {\n\tif(x%2 == 1) {\n\t\tx-=3\n\t\ts=s+\"7\";\n\t}\n\telse {\n\t\tx-=2;\n\t\ts=s+\"1\";\n\t}\n}\nprint(s)"}, {"source_code": "var str=readline();\nvar n=parseInt(str);\nvar can=false;\nif(n%2!=0) can=true, n--;\nn=n/2;\nfor(var i=0; i {\n let n = parseInt(input);\n mp[3] = \"7\";\n mp[2] = \"1\";\n let an = \"\";\n while(n){\n if (n >= 2 && n != 3){\n an += mp[2];\n n -= 2;\n } else {\n an += mp[3];\n n -= 3;\n }\n }\n an = reverse(an);\n console.log(an);\n rl.close();\n});"}, {"source_code": "var n = parseInt(readline());\nvar s = \"\";\nwhile (n >= 4) {\n s = s + \"1\";\n n -= 2;\n}\nif (n == 3) {\n s = \"7\" + s;\n} else {\n s = \"1\" + s;\n}\nprint(s);"}, {"source_code": "n = parseInt(readline());\nif (n % 2 == 1) {\n write(7);\n n -= 3;\n}\nwhile (n > 0) {\n write(1);\n n-=2;\n}\n"}, {"source_code": "a = readline();\n\nres = \"\";\nif(a%2 === 0) {\n res += \"1\";\n a -= 2;\n} else {\n res += \"7\";\n a -= 3;\n}\n//print(a);\nwhile(a) {\n res += \"1\";\n a -= 2;\n}\nprint(res)"}, {"source_code": "var n = +readline();\nvar s = \"\";\n\nif (n % 2 == 0) {\n for(i = 0; i < n/2; i++) {\n s += '1';\n }\n} else {\n s += '7';\n n -= 3;\n for(i = 0; i < n/2; i++) s += '1';\n}\nprint(s);"}, {"source_code": "\n var n = parseInt(readline());\n\n var res = '';\n\n while(n > 0) {\n if(n === 3) {\n res = '7' + res;\n n -= 3;\n } else {\n n -= 2;\n res = '1' + res;\n }\n }\n \n if(res === '') {\n res = '0';\n }\n \n print(res);\n"}, {"source_code": "n = +readline()\nif (n % 2 == 0) {\n ans = \"\"\n while (n >= 2) {\n ans += \"1\"\n n -= 2\n }\n print(ans)\n} else {\n ans = \"7\"\n n -= 3\n while (n >= 2) {\n ans += \"1\"\n n -= 2\n }\n print(ans)\n}"}, {"source_code": "var n = readline();\nvar ans=\"\";\nfor(var i=n; i>0;){\n if(i==3) {ans='7'+ans; i-=3; }\n else { ans='1'+ans; i-=2; }\n}\nprint(ans);"}, {"source_code": "n = readline();\n\ncomp = n % 2;\nif(comp == 0)\n{\n var res = \"\";\n for(var i = 1; i <= n / 2; i++)\n res += \"1\";\n print(res); \n}\nelse\n{\n var res = \"7\";\n for(var i = 1; i <= (n - 3) / 2; i++)\n res += \"1\";\n print(res); \n}\n"}, {"source_code": "n = +readline();\nans = ''; \nif (n % 2 == 1) {\nans+='7';\nn -= 3; }\nwhile (n > 0) { \nans+='1'; \nn-=2; \n}\nprint(ans);"}, {"source_code": "n = readline() \nvar result = \"\"; \nif (n%2 == 0){ \nfor(i = 0; i < n/2; i++) \nresult += \"1\"; \n} \n\nif (n%2 == 1){ \nresult = \"7\"; \nfor(i = 0; i < (n - 3)/2; i++) \nresult += \"1\"; \n} \nprint(result)"}, {"source_code": "var num = readline()\nvar res = \"\"\n\nif (num%2 == 1){\n res += \"7\"\n num -= 3\n}\n\nwhile (num > 0){\n res += \"1\"\n num -= 2\n}\n\nprint(res)"}], "negative_code": [{"source_code": "x=+readline()\n// print(x);\nwhile(x) {\n if(x%2 == 1){\n print(\"7\");\n x -= 3;\n } else {\n print(\"1\");\n x -= 2;\n }\n}"}, {"source_code": "x=+readline()\n// print(x);\nwhile(x) {\n if(x == 3){\n print(\"7\");\n x -= 3;\n } else {\n print(\"1\");\n x -= 2;\n }\n}"}, {"source_code": "x=readline();\ns=\"\";\nif (x%2) s += \"7\";\nwhile(x-2>=0) {\n s+=\"1\";\n x-=2;\n}\nprint(s);"}, {"source_code": "var str=readline();\nvar n=parseInt(str);\nvar can=false;\nif(n%2!=0) can=true;\nn=n/2;\nfor(var i=0; i0;){\n if(i==3) {ans+='7'; i-=3; }\n else { ans+='1'; i-=2; }\n}\nprint(ans);"}, {"source_code": "var n = +readline();\nvar arr = [];\nwhile(n >= 6) {\n n-= 6;\n arr.push(9);\n}\nwhile(n >= 3) {\n n-= 3;\n arr.push(7);\n}\nwhile(n >= 2) {\n n-= 2;\n arr.push(1);\n}\nfor(var i = 0; i < arr.length; i++) {\n write(arr[i]);\n}"}, {"source_code": "x=+readline()\nres = \"\"\nif (x > 2 && x % 3 == 1) res+=\"7\", x -= 3\nwhile(x >= 2) {\n res += \"1\"\n x -= 2\n}\nprint(res)"}, {"source_code": "x=+readline()\nres = \"\"\nif (x > 2 && x % 3 == 2) res+=\"7\", x -= 3\nwhile(x >= 2) {\n res += \"1\"\n x -= 2\n}\nprint(res)"}, {"source_code": "x=+readline()\nres = \"\"\nif (x > 2 && x % 3 == 2) res+=\"7\", x -= 3\nwhile(x > 3) {\n res += \"1\"\n x -= 2\n}\nprint(res)"}, {"source_code": "var n = +readline();\n\nans = ''\n\nx = 0\nx = Math.floor(n / 3)\nif (n % 3 == 1)\n x -= 1\n\nwhile (x--)\n ans += '7'\n \nif (n % 3 == 1)\n ans += '11'\nif (n % 3 == 2)\n ans += '1'\n\nprint(ans)\n"}, {"source_code": "var n = +readline();\n\nans = ''\n\n\nx = Math.floor(n / 3)\n\nwhile (x--)\n ans += '7'\n\nif (n % 3 == 2)\n ans += '1'\n\nprint(ans)\n"}, {"source_code": "var n = readline();\n\nif (n % 2 == 1){\n\tvar a = 7;\n\tn -= 3;\n}else{\n\tvar a = 1;\n\tn -= 2;\n}\n\nwhile (n > 0){\n\ta *= 10;\n\ta += 1;\n\tn -= 2;\n}\n\nprint(a);"}, {"source_code": "var n = readline();\nvar k = parseInt(n);\nvar j = \"\";\nwhile(k>2) {\n\tj += \"1\"\n\tk-=2;\n}\nif (k) {\n\tj += \"7\"\n}\nprint(j);"}, {"source_code": "var n = readline();\nvar k = parseInt(n);\nvar j = \"\";\nwhile(k>3) {\n\tj += \"1\"\n\tk-=2;\n}\nif (k) {\n\tj += \"7\"\n}\nprint(j);"}], "src_uid": "4ebea3f56ffd43efc9e1496a0ef7fa2d"} {"source_code": "var n = parseInt(readline());\nvar a = [];\nfor(var i=0;i ans){\n ans = a[i]-a[i-1]-1;\n }\n}\nvar h = parseInt(ans/60);\nif(h<10)\n h = '0' + h;\nvar m = ans%60;\nif(m<10)\n m = '0'+m;\nprint(h+':'+m);", "positive_code": [{"source_code": "\n\nvar n = readline();\nvar tmp = [];\nvar time = new Array();\nvar s;\n\nfor (var i = 0; i < 1440; ++i) {\n time[i] = false;\n}\n\nfor (var i = 0; i < n; ++i) {\n s = readline();\n if (s != undefined) {\n tmp = s.split(\":\");\n }\n time[parseInt(tmp[0] * 60) + parseInt(tmp[1])] = true;\n}\n\nvar cur = 0, max = 0, first = -1, last = 0;\n\nfor (var i = 0; i < 1440; ++i) {\n if (!time[i]) {\n cur++;\n }\n if (time[i]) {\n if (max < cur) {\n max = cur;\n }\n last = i;\n if (first == -1) {\n first = i;\n }\n cur = 0;\n }\n}\n\nif (max < first + 1439 - last) {\n max = first + 1439 - last;\n}\n\nprint((\"0\" + Math.floor(max / 60)).slice(-2) + \":\" + (\"0\" + max % 60).slice(-2));\n"}, {"source_code": "function compareNumeric(a, b) {\n return a - b;\n}\n\n\nvar n = readline();\n\n\nvar mas = [];\nfor(i = 0; i < n; i++){\n var login = readline();\n var k = login[0] * 10 + login[1] * 1;\n k = k * 60;\n k = k * 1 + login[3] * 10 + login[4] * 1;\n mas.push(k);\n}\nmas.sort(compareNumeric);\nvar ans = 0;\nfor(i = 0; i < n-1; i++){\n ans = Math.max(mas[i+1] - mas[i] - 1, ans);\n}\nans = Math.max(ans, (23*60+59 - mas[n-1]) + mas[0] * 1);\nvar k1 = (Math.floor(ans / 60));\nvar k2 = ans - k1 * 60;\nif(k1 < 10) k1 = '0' + k1;\nif(k2 < 10) k2 = '0'+ k2;\nprint(k1 + \":\" + k2);"}, {"source_code": "\nfunction compare(a, b) {\n return a - b;\n}\n\nNumber.prototype.pad = function(size) {\n var s = String(this);\n while (s.length < (size || 2)) {s = \"0\" + s;}\n return s;\n}\n\nvar a = [];\nvar num = 1440;\nvar n = readline();\nvar x = 0, y = 0, i = 0;\nfor(i = 0; i < n; i++){\n var line = readline().replace(\":\", \" \").split(\" \");\n x = parseInt(line[0]); y = parseInt(line[1]);\n a.push(x * 60 + y);\n}\na.sort(compare);\nvar res = 0;\nfor(i = 1; i < n; i++){\n if(a[i] - a[i - 1] - 1 > res){\n res = a[i] - a[i - 1] - 1;\n }\n}\nif(num - a[n-1] + a[0] - 1 > res){\n res = num - a[n-1] + a[0] - 1;\n}\n\nprint(parseInt(res / 60).pad(2).toString()+ \":\" + (res % 60).pad(2).toString());\n"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nvar n;\nn = readline();\nvar x = [n+1];\nvar m = 1441;\nfor (i = 0; i < n; i++) {\n\tvar s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint( ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l/(60)) + \":\" + ( parseInt(l%60) < 10 ?\"0\":\"\") + parseInt(l%60) );"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nn = readline();\n x = [n+1];\n m = 1441;\nfor (i = 0; i < n; i++) {\n\t s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint( ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l/(60)) + \":\" + ( parseInt(l%60) < 10 ?\"0\":\"\") + parseInt(l%60) );"}, {"source_code": "var n=+readline()\nvar st=[]\nwhile(n-->0){\n hm=readline().split(':')\n st.push(hm[0]*60+ +hm[1])\n}\nst.sort((a,b)=>a-b)\n\nvar ans=0\nfor(var i=1;imasleep) masleep=i-pros-1;\n pros=i;\n}\nvar str='';\nif ((masleep-masleep%60)/60<10) str='0';\nvar str1='';\nif (masleep%60<10) str1='0';\nprint(str+(masleep-masleep%60)/60+':'+str1+masleep%60);"}, {"source_code": "var n = ~~readline();\nvar x = Array.apply(null, Array(1440)).map(Number.prototype.valueOf,0);\n\nfor(var i = 0; i < n; ++i) {\n var t = readline().split(\":\");\n x[(~~t[0]) * 60 + (~~t[1])] = 1;\n}\n\nvar ans = 0, cnt = 0;\nfor(var i = 0; i < 1440 * 2; ++i) {\n if(x[i % 1440] === 0) {\n ++cnt;\n } else {\n if(cnt > ans) ans = cnt;\n cnt = 0;\n }\n}\n\nvar h = parseInt(ans / 60);\nvar m = ans % 60;\n\nif(h < 10) h = '0' + h;\nif(m < 10) m = '0' + m;\nprint(h + \":\" + m);"}, {"source_code": "var n=parseInt(readline());\nvar i,j,cur,Max,t;\nvar arr=[];\nfor(i = 0; i < n; i++){\n t = readline().split(':').map(el => parseInt(el));\n arr.push(t[0]*60+t[1]);\n}\narr.sort((a, b) => a-b)\ncur = arr[arr.length - 1] - 24 * 60 + 1;\nMax = 0;\nfor(i = 0; i < n; i++){\n Max = Math.max(arr[i] - cur, Max);\n cur = arr[i] + 1;\n}\nprint((Math.floor(Max/60) < 10 ? '0' : '') + Math.floor(Max/60) +':'+(Max%60 < 10 ? '0':'') + Max%60);"}, {"source_code": "var n=parseInt(readline());\nvar i,j,cur,Max,t;\nvar arr=[];\nfor(i = 0; i < n; i++){\n t = readline().split(':').map(el => parseInt(el));\n arr.push(t[0]*60+t[1]);\n}\narr.sort((a, b) => a-b)\ncur = arr[arr.length - 1] - 24 * 60 + 1;\nMax = 0;\nfor(i = 0; i < n; i++){\n Max = Math.max(arr[i] - cur, Max);\n cur = arr[i] + 1;\n}\nprint((Math.floor(Max/60) < 10 ? '0' : '') + Math.floor(Max/60) +':'+(Max%60 < 10 ? '0':'') + Max%60);"}, {"source_code": "const n = readline();\nvar time = [];\nfor (var i = 0; i < n; i++) {\n time.push(readline().split(':'));\n}\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < n-i-1; j++) {\n if (time[j][0] > time[j+1][0] || (time[j][0] == time[j+1][0] && time[j][1] > time[j+1][1])) {\n var temp = time[j];\n time[j] = time[j+1];\n time[j+1] = temp;\n }\n }\n}\nvar ans = 0;\nif (n == 1) print(\"23:59\");\nelse {\n for (var i = 0; i < n-1; i++) {\n ans = Math.max(ans, ((time[i+1][0] - time[i][0]) * 60) + (time[i+1][1] - time[i][1]));\n }\n ans = Math.max(ans, ((24 + (time[0][0] - time[n-1][0])) * 60) + (time[0][1] - time[n-1][1]));\n ans--;\n var h = ~~(ans / 60), m = ans % 60, st;\n var st = \"\";\n if (h < 10) st += 0;\n st += h;\n st += \":\";\n if (m < 10) st += 0;\n st += m;\n print(st);\n}"}, {"source_code": "var n = parseInt(readline());\nvar arr = [];\nfor(var i = 0; i < n; i++){\n var t = readline().split(':').map(el => parseInt(el));\n arr.push(t[0]*60+t[1]);\n}\narr.sort((a, b) => a-b)\nvar cur = arr[arr.length - 1] - 24 * 60 + 1;\nvar Max = 0;\nfor(var i = 0; i < n; i++){\n Max = Math.max(arr[i] - cur, Max);\n cur = arr[i] + 1;\n}\nprint((Math.floor(Max/60) < 10 ? '0' : '') + Math.floor(Max/60) +':'+(Max%60 < 10 ? '0':'') + Max%60);\n"}, {"source_code": "function sortFunction(a, b){\n if(a < b)\n return -1 \n if(a > b)\n return 1\n return 0\n}\n\nvar nn = readline().split(\" \").map(v => +v.trim());\nvar n = nn[0];\n//print(n);\nvar a = [];\n\nfor (var i = 0; i < n; i++) {\n var tmp = readline().split(\":\").map(v => +v.trim());\n var cur = 60 * tmp[0] + tmp[1];\n //print(cur);\n a.push(cur);\n}\n\na = a.sort(sortFunction)\na.push(a[0] + 24 * 60);\n//print(a);\nvar mx = 0;\nfor (var i = 0; i < n; i++) {\n var cur = a[i + 1] - a[i] - 1;\n if (mx < cur) {\n mx = cur;\n }\n}\n//print(mx);\nvar h = Math.floor( mx / 60 );\nvar m = mx - h * 60;\nif (h < 10 && m < 10) {\n print(\"0\" + h + \":\" + \"0\" + m);\n}\nelse if (h < 10) {\n print(\"0\" + h + \":\" + m);\n}\nelse if (m < 10) {\n print(h + \":\" + \"0\" + m);\n}\nelse {\n print(h + \":\" + m);\n}"}, {"source_code": "var n;\nvar arr = new Array();\nn = readline();\nfor (var i = 0; i < n; ++i) {\n var s = readline();\n var t = parseInt(parseInt(s[0]) * 600 + parseInt(s[1]) * 60 + parseInt(s[3]) * 10 + parseInt(s[4]));\n arr[i] = t;\n}\narr.sort(function(a, b){return parseInt(a) - parseInt(b)});\narr[n] = parseInt(parseInt(arr[0]) + parseInt(1440));\nvar ans = 0;\nfor (var i = 0; i < n; ++i) {\n ans = Math.max(ans, parseInt(arr[i + 1]) - parseInt(arr[i]) - 1);\n}\nvar q = \"\" + parseInt(parseInt(ans) / parseInt(600)) + \"\" + parseInt(parseInt(ans) / parseInt(60)) % 10 + \":\" + parseInt(ans / 10) % 6 + parseInt(ans % 10);\nprint(q);"}, {"source_code": "var n = readline();\nvar a = [];\n\nfor (i=0; i parseInt(el));\n arr.push(t[0]*60+t[1]);\n}\narr.sort((a, b) => a-b)\nvar cur = arr[arr.length - 1] - 24 * 60 + 1;\nvar Max = 0;\nfor(var i = 0; i < n; i++){\n Max = Math.max(arr[i] - cur, Max);\n cur = arr[i] + 1;\n}\nprint(Math.floor(Max/60)+':'+Max%60);\n"}, {"source_code": "\n\nvar n = readline();\nvar tmp = [];\nvar time = new Array();\nvar s;\n\nfor (var i = 0; i < 1440; ++i) {\n time[i] = false;\n}\n\nfor (var i = 0; i < n; ++i) {\n s = readline();\n if (s != undefined) {\n tmp = s.split(\":\");\n }\n time[parseInt(tmp[0] * 60) + parseInt(tmp[1])] = true;\n}\n\nvar cur = 0, max = 0, first = -1, last = 0;\n\nfor (var i = 0; i < 1440; ++i) {\n if (!time[i]) {\n cur++;\n }\n if (time[i]) {\n if (max < cur) {\n max = cur;\n }\n last = i;\n if (first == -1) {\n first = i;\n }\n cur = 0;\n }\n}\n\nif (max < first + 1440 - last) {\n max = first + 1440 - last;\n}\n\nprint((\"0\" + Math.floor(max / 60)).slice(-2) + \":\" + (\"0\" + max % 60).slice(-2));\n"}, {"source_code": "function compareNumeric(a, b) {\n return a - b;\n}\n\n\nvar n = readline();\n\n\nvar mas = [];\nfor(i = 0; i < n; i++){\n var login = readline();\n var k = login[0] * 10 + login[1] * 1;\n k = k * 60;\n k = k * 1 + login[3] * 10 + login[4] * 1;\n mas.push(k);\n}\nmas.sort(compareNumeric);\nvar ans = 0;\nfor(i = 0; i < n-1; i++){\n ans = Math.max(mas[i+1] - mas[i] - 1, ans);\n}\nans = Math.max(ans, (23*60+59 - mas[n-1]) + mas[0] * 1);\nprint((Math.floor(ans / 60)) + \":\" + (ans - Math.floor(ans / 60) * 60));"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nvar n;\nn = readline();\nvar x = [n+1];\nvar m = 5465464;\nfor (i = 0; i < n; i++) {\n\tvar s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\n\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint(parseInt(l/(60)) + \":\" + parseInt(l%60) );"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nvar n;\nn = readline();\nvar x = [n+1];\nvar m = 1441;\nfor (i = 0; i < n; i++) {\n\tvar s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint( ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l/(60)) + \":\" + parseInt(l%60) );"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nvar n;\nn = readline();\nvar x = [n+1];\nvar m = 5465464;\nfor (i = 0; i < n; i++) {\n\tvar s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\n\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint( ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l/(60)) + \":\" + parseInt(l%60) );"}, {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\nvar n;\nn = readline();\nvar x = [n+1];\nvar m = 1441;\nfor (i = 0; i < n; i++) {\n\tvar s = readline();\n\tx[i] = parseInt(s[4]-'0')+parseInt(s[3]-'0')*10+parseInt(s[1]-'0')*60+parseInt(s[0]-'0')*600;\n\tif ( m > x[i] ) m = x[i];\n}\nx[n] = m + 1440;\nx = x.sort(sortNumber);\nvar l = 0;\nfor (i = 1; i <= n; i++) {\n if (l < x[i] - x[i-1] - 1 ) {\n l = x[i] - x[i-1] - 1;\n }\n}\nprint( ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l/(60)) + \":\" + ( parseInt(l/(60) ) < 10 ?\"0\":\"\") + parseInt(l%60) );"}, {"source_code": "var n=parseInt(readline());\nvar arr=[];\nfor (var i=0;i<2880;++i) arr[i]=0;\nfor (var i=0;imasleep) masleep=i-pros-1;\n pros=i;\n}\nvar str='';\nif ((masleep-masleep%60)/60<10) str='0';\nprint(str+(masleep-masleep%60)/60+':'+masleep%60);"}], "src_uid": "c3b0b7194ce018bea9c0b9139e537a09"} {"source_code": "var n = Number(readline());\nvar a = readline().split(\" \", n).map(Number);\nvar b = readline().split(\" \", n).map(Number);\n\nvar x = 0, y = 0;\nfor (var i = 0; i < n; ++i) {\n\tx |= a[i];\n\ty |= b[i];\n}\nprint(x + y);", "positive_code": [{"source_code": "try {require('codef');} catch (e){global = this};\nfunction readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\nArray.prototype.list = function() {var length = arguments.length; for(var i=0; i < length; i++){global[arguments[i]] = this[i]}};\nString.prototype.repeat = function(n){return new Array(n + 1).join(this);}\n\nvar n = readLineAsIntegerArray()[0];\nvar a = readLineAsIntegerArray();\nvar b = readLineAsIntegerArray();\nvar aa = a[0], bb = b[0];\nfor(var i = 1; i < a.length; i++) {\n aa = aa | a[i];\n bb = bb | b[i];\n}\n\nwrite(aa + bb);"}], "negative_code": [{"source_code": "var n = Number(readline());\nvar a = readline().split(\"\", n).map(Number);\nvar b = readline().split(\"\", n).map(Number);\n\nvar x = 0, y = 0;\nfor (var i = 0; i < n; ++i) {\n\tx |= a[i];\n\ty |= b[i];\n}\nprint(x + y);"}], "src_uid": "475239ff4ae3675354d2229aba081a58"} {"source_code": "MAX = 1000001;\ncounts = [];\nfirsts = [];\nlasts = [];\nfor (i = 0; i < MAX; i++) {\n counts[i] = 0;\n firsts[i] = -1;\n lasts[i] = MAX;\n}\nn = +readline();\narray = readline().split(' ');\nfor (i = 0; i < n; i++) {\n ele = array[i] = +array[i];\n counts[ele]++;\n if (firsts[ele] < 0) firsts[ele] = i + 1;\n lasts[ele] = i + 1;\n}\n\nmax = -1;\nleft = -1;\nright = MAX;\nfor (i = 0; i < MAX; i++) {\n if (max < counts[i]) {\n max = counts[i];\n left = firsts[i];\n right = lasts[i];\n } else if (max == counts[i] && right - left > lasts[i] - firsts[i]) {\n left = firsts[i];\n right = lasts[i];\n }\n}\n\nprint(left + ' ' + right);", "positive_code": [{"source_code": "\n Node = function (count, position) {\n this.count = 0;\n this.minPosition = 100001;\n this.maxPosition = -100001;\n\n this.setPosition = function (position) {\n this.count++;\n this.minPosition = Math.min(this.minPosition, position);\n this.maxPosition = Math.max(this.maxPosition, position);\n }\n\n this.getLength = function () {\n return this.maxPosition - this.minPosition;\n }\n\n this.toString = function () {\n return '(' + this.count + ': ' + this.minPosition + ' - ' + this.maxPosition + ')';\n };\n\n this.setPosition(position);\n };\n\n n = +readline();\n numbers = readline().split(' ');\n nodes = {};\n for (i = 0; i < n; i++) {\n var node = nodes[numbers[i]];\n if (!node) {\n node = nodes[numbers[i]] = new Node(+numbers[i], i);\n }\n else {\n node.setPosition(i);\n }\n }\n\n var maxValueNode = null;\n\n for (key in nodes) {\n var node = nodes[key];\n if (maxValueNode === null || maxValueNode.count < node.count ||\n (maxValueNode.count == node.count && maxValueNode.getLength() > node.getLength())) {\n maxValueNode = node;\n }\n }\n\n print((maxValueNode.minPosition + 1) + ' ' + (maxValueNode.maxPosition + 1));"}, {"source_code": "Node = function(position, value) {\n this.position = position;\n this.value = value;\n this.toString = function() {\n return '(' + this.position + ', ' + this.value + ')';\n };\n};\n\nn = +readline();\nnumbers = readline().split(' ');\nnodes = [];\nfor (i = 0; i < n; i++) {\n nodes[i] = new Node(i, +numbers[i]);\n}\nnodes.sort(function(n1, n2) {\n if (n1.value != n2.value) return n1.value - n2.value;\n return n1.position - n2.position;\n});\n\nmax = 1;\nmright = mleft = nodes[0].position;\ncount = 1;\nleft = right = nodes[0].position;\nfor (i = 1; i < n; i++) {\n if (nodes[i].value != nodes[i - 1].value) {\n left = right = nodes[i].position;\n count = 1;\n } else {\n right = nodes[i].position;\n count++;\n }\n if (max < count) {\n max = count;\n mleft = left;\n mright = right;\n } else if (max == count && mright - mleft > right - left) {\n mleft = left;\n mright = right;\n }\n\n}\n\nprint((mleft + 1) + ' ' + (mright + 1));"}], "negative_code": [{"source_code": "MAX = 1000001;\ncounts = [];\nfirsts = [];\nlasts = [];\nfor (i = 0; i < MAX; i++) {\n counts[i] = 0;\n firsts[i] = -1;\n lasts[i] = MAX;\n}\nn = +readline();\narray = readline().split(' ');\nfor (i = 0; i < n; i++) {\n ele = array[i] = +array[i];\n counts[ele]++;\n if (firsts[ele] < 0) firsts[ele] = i + 1;\n lasts[ele] = i + 1;\n}\n\nmax = -1;\nleft = -1;\nright = MAX;\nfor (i = 0; i < MAX; i++) {\n if (max < counts[i]) {\n max = counts[i];\n left = firsts[i];\n right = lasts[i];\n } else if (max == counts[i] && right - left > lasts[i] - firsts[i]) {\n left = firsts[i];\n right = lasts[i];\n }\n}"}], "src_uid": "ecd9bbc05b97f3cd43017dd0eddd014d"} {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-12 ;\n cn = 10000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n if (w === 1) return w;\n // Max amount of water to each boy: 2w/3n;\n let boyWater = a[n - 1];\n if ((boyWater * 3 * n) / 2 > w) {\n boyWater = (2 * w) / (3 * n);\n }\n let girlWater = a[2*n - 1];\n if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return (girlWater * n) + (girlWater * 2 * n);\n};"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-11 ;\n cn = 1000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-12 ;\n cn = 1000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-11 ;\n cn = 100 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n + a * this.n < this.w + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-11 ;\n cn = 100 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-11 ;\n cn = 100 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n + a * this.n < ( this.w ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => a - b;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n if (w === 1) return w;\n const x = Math.min(a[0], a[n]/2)\n \n return Math.min(w, x*n*3)\n};"}], "negative_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 10000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n < this.w + eps && a * this.n < this.w + eps && mi * this.n + a * this.n < this.w + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 100 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 10000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n + a * this.n < this.w + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-10 ;\n cn = 1000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 100 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n + a * this.n < this.w + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 1000000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi + a < ( this.w / this.n ) + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c , lo , hi , mi , eps ;\n this.arr = this.arr.sort( function( le , ri ) { return le - ri ; } ) ;\n res = 0 ; \n lo = 0.0 ;\n hi = this.arr[ 0 ] * 1.0 ;\n eps = 1e-9 ;\n cn = 1000000 ;\n while( ( hi - lo ) >= eps && cn-- > 0 ) {\n mi = ( lo + hi ) / 2.0 ;\n a = 2.0 * mi ;\n if( mi < this.arr[ 0 ] + eps && a < this.arr[ this.n ] + eps && mi * this.n < this.w + eps && a * this.n < this.w + eps && mi * this.n + a * this.n < this.w + eps ) {\n lo = mi ;\n res = mi * this.n + a * this.n ;\n }\n else {\n hi = mi ;\n }\n }\n print( res.toFixed( 10 ) ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 100010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n \tthis.w = irObj.nextInt() ;\n this.arr = [] ;\n for( i = 0 ; i < 2 * this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n if (w === 1) return w;\n const x = Math.min(a[0], a[n]/2)\n \n return Math.min(w, x*n*3)\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n if (w === 1) return w;\n // Max amount of water to each boy: 2w/3n;\n const factor = w/n; // w/n;\n const maxBoyWater = 1.5 * factor;\n let boyWater = a[n - 1] <= maxBoyWater ? a[n - 1] : maxBoyWater;\n let girlWater = a[2*n - 1];\n if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return (girlWater * n) + (girlWater * 2 * n);\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n // Max amount of water to each boy: 2w/3n;\n const factor = w/n; // w/n;\n const maxBoyWater = 1.5 * factor;\n let boyWater = a[n - 1] <= maxBoyWater ? a[n - 1] : maxBoyWater;\n let girlWater = a[2*n - 1];\n if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return (girlWater * n) + (girlWater * 2 * n);\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n let maxAmount = a[0] * 2 <= a[n] ? a[0] : a[n] / 2;\n // Max amount of water to each boy: 2w/3n;\n // const factor = w/n; // w/n;\n // const maxBoyWater = 1.5 * factor;\n // let boyWater = a[n - 1] <= maxBoyWater ? a[n - 1] : maxBoyWater;\n // let girlWater = a[2*n - 1];\n // if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return maxAmount * 3 * n < w ? maxAmount * 3 * n : w;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n if (w === 1 || w === 1000000000) return w;\n // Max amount of water to each boy: 2w/3n;\n let boyWater = a[n - 1];\n if ((boyWater * 3 * n) / 2 > w) {\n boyWater = (2 * w) / (3 * n);\n }\n let girlWater = a[2*n - 1];\n if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return (girlWater * n) + (girlWater * 2 * n);\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n let maxAmount = a[0] * 2 <= a[n] ? a[0] : a[n] / 2;\n // Max amount of water to each boy: 2w/3n;\n // const factor = w/n; // w/n;\n // const maxBoyWater = 1.5 * factor;\n // let boyWater = a[n - 1] <= maxBoyWater ? a[n - 1] : maxBoyWater;\n // let girlWater = a[2*n - 1];\n // if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return maxAmount < w / (3 * n) ? maxAmount * 3 * n : w;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nw = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const result = pashaAndTea(nw[0], nw[1], arr);\n printResult(result.toString());\n}\n\nconst compare = (a, b) => b - a;\n\nconst pashaAndTea = (n, w, a) => {\n a.sort(compare);\n let maxAmount = a[0] * 2 <= a[n] ? a[0] : a[n] * 1.0 / 2;\n // Max amount of water to each boy: 2w/3n;\n // const factor = w/n; // w/n;\n // const maxBoyWater = 1.5 * factor;\n // let boyWater = a[n - 1] <= maxBoyWater ? a[n - 1] : maxBoyWater;\n // let girlWater = a[2*n - 1];\n // if (girlWater >= boyWater / 2) girlWater = boyWater / 2;\n\n return maxAmount * 3 * n <= w ? maxAmount * 3 * n : w;\n};"}], "src_uid": "b2031a328d72b464f965b4789fd35b93"} {"source_code": "var tmp = readline().split(' ');\nvar n = +tmp[0];\nvar l = +tmp[1];\nvar r = +tmp[2];\nvar b = readline().split(' ').map(function(v){return +v;});\nvar a = readline().split(' ').map(function(v){return +v;});\n\nvar ans = 1;\nl--; r--;\nfor(var i = 0; i r) {\n if (a[i] != b[i]) {\n ans = false;\n }\n } else {\n g.push(a[i]);\n f.push(b[i]);\n }\n}\nif (ans && f.sort().toString() == g.sort().toString()) {\n print(\"TRUTH\");\n} else {\n print(\"LIE\");\n}"}, {"source_code": "var inp = readline().split(' ');\nvar a = readline().split(' ');\nvar b = readline().split(' ');\nvar ca = a.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));\nvar cb = b.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));\nca.sort();\ncb.sort();\nvar ans = true;\nfor (var i = 0; i < ca.length; i++) {\n if (ca[i] != cb[i])\n ans = false;\n}\nfor (var i = 0; i < a.length; i++) {\n if (i < parseInt(inp[1]) - 1 || i >= parseInt(inp[2])) {\n if (a[i] != b[i])\n ans = false;\n }\n}\nif (ans)\n print(\"TRUTH\");\nelse\n print(\"LIE\");"}, {"source_code": "var n = readline().split(' ').map(function(v){return +v;});\nvar a = readline().split(' ').map(function(v){return +v;});\nvar b = readline().split(' ').map(function(v){return +v;});\n\nvar fl=true;\n\nfor (var i = 0; i r)\n {\n if (a1[i - 1] != a2[i - 1])\n {\n flag = false;\n break;\n }\n }\n }\n if (flag === true)\n {\n print(\"TRUTH\");\n }\n else\n {\n print(\"LIE\");\n }"}, {"source_code": "var meta = readline().split(\" \").map(function(n) {return parseInt(n)});\n\nvar count = meta[0];\nvar left = meta[1] - 1;\nvar right = meta[2];\n\nvar a = readline().split(\" \").map(function(n) {return parseInt(n)});\nvar b = readline().split(\" \").map(function(n) {return parseInt(n)});\nvar lie = false;\nfor (var i = 0; i < left; ++i) {\n\tif (a[i] !== b[i]) {\n\t\tlie = true;\n\t\tbreak;\n\t};\n};\n\nif (!lie) {\n\tfor (var i = right; i < a.length; ++i) {\n\t\tif (a[i] !== b[i]) {\n\t\t\tlie = true;\n\t\t\tbreak;\n\t\t};\n\t};\n}\n\nprint(!lie ? \"TRUTH\": \"LIE\");"}, {"source_code": "function main() {\n var line = readline().split(\" \");\n var n = parseInt(line[0]);\n var l = parseInt(line[1]) - 1;\n var r = parseInt(line[2]) - 1;\n\n line = readline();\n var a = line.split(\" \");\n a.forEach(function(x, i) {\n a[i] = parseInt(a[i]);\n });\n\n line = readline();\n var b = line.split(\" \");\n b.forEach(function(x, i) {\n b[i] = parseInt(b[i]);\n });\n\n for (var i = 0; i < l; ++i) {\n if (a[i] != b[i]) {\n print(\"LIE\");\n return;\n }\n }\n\n for (var i = r + 1; i < n; ++i) {\n if (a[i] != b[i]) {\n print(\"LIE\");\n return;\n }\n }\n\n print(\"TRUTH\");\n}\n\nmain();\n"}, {"source_code": "a = readline().split(' ');\nn = a[0];\nl = a[1];\nr = a[2];\na = readline().split(' ');\nb = readline().split(' ');\ngood = true;\nfor (i = 0; i < n; ++i)\n if (a[i] != b[i] && !(i >= l - 1 && i <= r - 1))\n good = false;\nif (good)\n print('TRUTH');\nelse\n print('LIE');"}, {"source_code": "// var inputValues = [\n// // '5 2 4',\n// // '3 4 2 3 1',\n// // '3 2 3 4 1',\n\n// // '3 1 2',\n// // '1 2 3',\n// // '3 1 2',\n\n// // '4 2 4',\n// // '1 1 1 1',\n// // '1 1 1 1'\n// // '10 3 7',\n// // '678 45 78 11 90 98 99999 21 89 9',\n// // '678 45 99999 90 11 89 98 78 21 9',\n// // '6 3 5',\n// // '6 7 9 0 1 8',\n// // '6 7 0 9 1 8'\n// ]\n\n// var inputIndex = 0;\n\n// function readline() {\n// inputIndex++;\n// return inputValues[inputIndex - 1];\n// }\n\n// function print(s) {\n// console.log(s);\n// }\n\nvar input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourceBefore = source.slice(0, l);\nvar destBefore = dest.slice(0, l);\n\nvar sourceAfter = source.slice(r + 1, source.length + 1);\nvar destAfter = dest.slice(r + 1, source.length + 1);\n\nvar sourcePart = source.slice(l, r + 1);\nvar destPart = dest.slice(l, r + 1);\nsourcePart.sort();\ndestPart.sort();\n\n\nvar truth = true;\n\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n print('LIE');\n truth = false;\n break;\n }\n}\n\nif (truth) {\n for (var i = 0; i < sourceBefore.length; i++) {\n if (sourceBefore[i] !== destBefore[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n\n if (truth) {\n for (var i = 0; i < sourceAfter.length; i++) {\n if (sourceAfter[i] !== destAfter[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n }\n}\n\nif (truth) {\n print('TRUTH');\n}"}, {"source_code": "var n = readline().split(' ').map(function(v){return +v;});\nvar a = readline().split(' ').map(function(v){return +v;});\nvar b = readline().split(' ').map(function(v){return +v;});\n\nvar fl=true;\n\nfor (var i = 0; i= r){\n if (a[i] != b[i]){\n ans = \"LIE\";\n }\n }\n}\n\nfor (i = l; i < r; i++){\n c[a[i]]++;\n}\nfor (i = l; i < r; i++){\n if (c[b[i]] > 0){\n c[b[i]]--;\n } else {\n ans = \"LIE\";\n }\n}\nprint(ans);"}, {"source_code": "var K = readline().split(' ').map( x => +x);\nvar n = K[0];\nvar l = K[1];\nvar r = K[2];\nl--;r--;\n\nvar a = readline().split(' ').map( x => +x);\n\nvar b = readline().split(' ').map( x => +x);\n\nvar ok = true;\n\nfor(var i=0;i {\n var obj = {}; \n for(var i=l;i<=r;i++) {\n if(!(arr[i] in obj)) obj[arr[i]] = 1;\n else obj[arr[i]]++;\n }\n return obj;\n}\n\nvar A = counts(a);\nvar B = counts(b);\n\nfor(var i=l;i<=r;i++) if(A[a[i]] != B[a[i]]) ok = false;\n\nif(ok) print(\"TRUTH\");\nelse print(\"LIE\"); "}, {"source_code": "var line = readline().split(' ');\nvar aa = readline().split(' ');\nvar bb = readline().split(' ');\nvar n = +line[0];\nvar l = +line[1];\nvar r = +line[2];\nl = l-1;\nr = r-1;\nvar inA = [];\nvar inB = [];\nvar lie=false;\nfor (i =0;ir)) && aa[i]!=bb[i]){\n lie=true;\n break;\n }\n if (aa[i]!=bb[i]){\n inA.push(aa[i]);\n inB.push(bb[i]);\n }\n}\nif (lie){\n print(\"LIE\");\n}else{\n inA.sort();\n inB.sort();\n for(i=0;i=l)&&(i<=r)) {list1[a1[i]]+=1}\n \n}\n\n\na=a1;\n\nvar b=true;\n\nvar a1 = readline().split(\" \");\n\nfor (i=0;i=l)&&(i<=r)) {list1[a1[i]]-=1}\n else {if (a1[i]!=a[i]) {b=false; break;}}\n}\n\n\n\nif (b) {\nfor (i=0;i<=100000;i+=1) \n if (list1[i]!=0) \n {b=false; break; }\n \n}\n\n\nif (b) {print('TRUTH')} else {print('LIE')}\n"}, {"source_code": "\nvar S = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = S[0]; l = S[1]; r = S[2];\nvar A = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar B = readline().split(\" \").map(function(x) { return parseInt(x); });\nl--;\nS = A;\nT = B;\nA = A.slice(l, r);\nB = B.slice(l, r);\nA.sort();\nB.sort();\nif(JSON.stringify(A) == JSON.stringify(B)){\n\tvar ok = true;\n\tfor(i = 0; i < l && ok; i++){\n\t\tif(S[i] != T[i]) ok = false;\n\t}\n\tfor(i = r; i < n && ok; i++){\n\t\tif(S[i] != T[i]) ok = false;\n\t}\n\tif(ok) print(\"TRUTH\");\n\telse print(\"LIE\");\n}else{\n\tprint(\"LIE\");\n}"}, {"source_code": "var prsi = function(i) { return +i; };\nvar reg = /\\s+/;\nvar ln = readline().split(reg).map(prsi);\nvar n = ln[0], l = ln[1] - 1, r = ln[2] - 1;\nvar a = readline().split(reg).map(prsi),\n\tb = readline().split(reg).map(prsi);\n\nvar flag = 1;\nfor(var i = 0; i < l; ++i) {\n\tif(a[i] !== b[i]) {\n\t\tflag = 0;\n\t\tbreak;\n\t}\n}\n\nif(flag) {\n\tfor(var i = r + 1; i < n; ++i) {\n\t\tif(a[i] !== b[i]) {\n\t\t\tflag = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nif(flag) print(\"TRUTH\");\nelse print(\"LIE\");\n"}, {"source_code": "\"use strict\";\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id++];\n var print = console.log;\n}\nlet nums = () => readline().split(' ').map(x => +x);\nlet t = nums(), n = t[0], l = --t[1], r = --t[2];\nlet a = nums();\nlet b = nums();\n\nlet c = Array(n).fill(0);\nlet ans = true;\nfor (let i = l; i <= r; ++i) {\n ++c[a[i] - 1];\n --c[b[i] - 1];\n}\nfor (let i = 0; i < l && ans; ++i) {\n if (a[i] !== b[i]) \n ans = false;\n}\nfor (let i = r + 1; i < n && ans; ++i) {\n if (a[i] != b[i])\n ans = false;\n}\n\nif (ans) ans = c.every(x => x === 0);\n\nif (ans) print(\"TRUTH\");\nelse print(\"LIE\");\n"}, {"source_code": "var temp = readline().split(' ').map(Number);\nvar n = temp[0];\nvar l = temp[1];\nvar r = temp[2];\n//print(n)\n//print(l)\n//print(r)\nvar fr = readline().split(' ').map(Number);\nvar sc = readline().split(' ').map(Number);\nl -= 1;\nr -= 1;\nvar ch = 1;\nfor (var i = 0; i < l; i++) {\n\tif (fr[i] != sc[i])\t{\n\t\tch = 0;\n\t\t//exit(0);\n\t}\n}\nfor (var i = r + 1; i < n; i++) {\n\tif (fr[i] != sc[i]) {\n\t\tch = 0;\n\t\t//exit(0);\n\t}\n}\nvar c1 = [];\nvar c2 = [];\nfor (var i = l; i <= r; i++) {\n\tc1.push(fr[i]);\n\tc2.push(sc[i]);\n}\nc1.sort();\nc2.sort();\nfor (var i = l; i <= r; i++) {\n\tif (c1[i - l] != c2[i - l]) {\n\t\tch = 0;\n\t\t//exit(0);\n\t}\n}\nif (ch == 0)\n\tprint(\"LIE\");\nelse\n\tprint(\"TRUTH\");"}, {"source_code": "var t = readline().split(' ');\nvar n = parseInt(t[0]);\nvar l = parseInt(t[1]) - 1;\nvar r = parseInt(t[2]);\nvar a = readline().split(' ');\nvar b = readline().split(' ');\nvar good = true;\n\nfor (i = 0; i < n; i++) {\n a[i] = parseInt(a[i]);\n b[i] = parseInt(b[i]);\n}\n\nfor (i = 0; i < l && good; i++)\n if (a[i] != b[i])\n good = false;\nfor (i = r; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \na.sort();\nb.sort();\n\nfor (i = 0; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \nprint(good ? \"TRUTH\" : \"LIE\")"}, {"source_code": "(function work() {\n var n, l, r;\n var A, B;\n var hash = {};\n var arr, i;\n arr = readline().split(' ');\n arr = arr.map((s) => parseInt(s));\n n = arr[0];\n l = arr[1] - 1;\n r = arr[2] - 1;\n arr = readline().split(' ');\n A = arr.map((s) => parseInt(s));\n for (i = l; i <= r; i ++) {\n if (!hash[A[i]])\n hash[A[i]] = 1;\n else\n hash[A[i]] ++;\n }\n arr = readline().split(' ');\n B = arr.map((s) => parseInt(s));\n for (i = 0; i < l; i ++) {\n if (A[i] !== B[i]) {\n print('LIE');\n return;\n }\n }\n for (i = l; i <= r; i ++) {\n if (!hash[B[i]] || hash[B[i]] === 0) {\n print('LIE');\n return;\n } else {\n hash[B[i]] --;\n }\n }\n for (i = r + 1; i < n; i ++) {\n if (A[i] !== B[i]) {\n print('LIE');\n return;\n }\n }\n print('TRUTH');\n})();"}], "negative_code": [{"source_code": "input = readline().split(' ');\nv = readline().split(' ');\nv2 = readline().split(' ');\nn = input[0];\nl = input[1] - 1;\nr = input[2] - 1;\nvar arr = [100100];\nfor (i = 1; i <= 100000; i++) {\n arr[i] = 0;\n}\nfor (i = l; i <= r; i++) {\n arr[v[i]]++;\n}\nvar flag = 1;\nfor (i = l; i <= r; i++) {\n if (arr[v2[i]] !== 0) {\n arr[v2[i]]--;\n } else {\n flag = 0;\n }\n}\nfor (i = l; i <= r; i++) {\n if (arr[v[i]] !== 0) {\n flag = 0;\n }\n}\nif (flag == 1) {\n print(\"TRURH\");\n} else {\n print(\"LIE\");\n}\n"}, {"source_code": "input = readline().split(' ');\nv = readline().split(' ');\nv2 = readline().split(' ');\nn = input[0];\nl = input[1] - 1;\nr = input[2] - 1;\nvar arr = [100100];\nfor (i = 1; i <= 100000; i++) {\n arr[i] = 0;\n}\nfor (i = l; i <= r; i++) {\n arr[v[i]]++;\n}\nvar flag = 1;\nfor (i = l; i <= r; i++) {\n if (arr[v2[i]] !== 0) {\n arr[v2[i]]--;\n } else {\n flag = 0;\n }\n}\nfor (i = l; i <= r; i++) {\n if (arr[v[i]] !== 0) {\n flag = 0;\n }\n}\nif (flag == 1) {\n print(\"TRUTH\");\n} else {\n print(\"LIE\");\n}\n"}, {"source_code": "var t = readline().split(' ');\nvar n = t[0];\nvar l = parseInt(t[1]) - 1;\nvar r = t[2];\nvar a = readline().split(' ');\nvar b = readline().split(' ');\nvar good = true;\n\nfor (i = 0; i < n; i++) {\n a[i] = parseInt(a[i]);\n b[i] = parseInt(b[i]);\n}\n\nfor (i = 0; i < l && good; i++)\n if (a[i] != b[i])\n good = false;\nfor (i = r; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \na.sort();\nb.sort();\n\nfor (i = 0; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \nprint(good ? \"TRUTH\" : \"LIE\")"}, {"source_code": "var t = readline().split(' ');\nvar n = t[0];\nvar l = t[1] - 1;\nvar r = t[2];\nvar a = readline().split(' ');\nvar b = readline().split(' ');\nvar good = true;\nfor (i = 0; i < l && good; i++)\n if (a[i] != b[i])\n good = false;\nfor (i = r; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \na.sort();\nb.sort();\n\nfor (i = 0; i < n && good; i++)\n if (a[i] != b[i])\n good = false;\n \nprint(good ? \"TRUTH\" : \"LIE\")"}, {"source_code": "var tmp = readline().split(' ');\nvar n = +tmp[0];\nvar l = +tmp[1];\nvar r = +tmp[2];\nvar a = readline().split(' ').map(function(v){return +v;});\nb = a;\nvar ans = 1;\nl--; r--;\nfor(var i = 0; i= l - 1 && i <= r - 1)) {\n print(i);\n good = false;\n }\nif (good)\n print('TRUTH');\nelse\n print('LIE');"}, {"source_code": "a = readline().split(' ');\nn = a[0];\nl = a[1];\nr = a[2];\na = readline().split(' ');\nb = readline().split(' ');\ngood = true;\nfor (i = 0; i < n; ++i)\n if (a[i] != b[i] && i >= l - 1 && i <= r - 1)\n good = false;\nif (good)\n print('TRUTH');\nelse\n print('LIE');"}, {"source_code": "a = readline().split(' ');\nn = a[0];\nl = a[1];\nr = a[2];\na = readline().split(' ');\nb = readline().split(' ');\ngood = true;\nfor (i = 0; i < n; ++i)\n if (a[i] != b[i] && i >= l - 1 && i < r)\n good = false;\nif (good)\n print('TRUTH');\nelse\n print('LIE');\n"}, {"source_code": "// var inputValues = [\n// // '5 2 4',\n// // '3 4 2 3 1',\n// // '3 2 3 4 1',\n\n// // '3 1 2',\n// // '1 2 3',\n// // '3 1 2',\n\n// // '4 2 4',\n// // '1 1 1 1',\n// // '1 1 1 1'\n// // '10 3 7',\n// // '678 45 78 11 90 98 99999 21 89 9',\n// // '678 45 99999 90 11 89 98 78 21 9',\n// '5 3 5',\n// '6 7 9 0 1',\n// '7 6 9 0 1'\n// ]\n\n// var inputIndex = 0;\n\n// function readline() {\n// inputIndex++;\n// return inputValues[inputIndex - 1];\n// }\n\n// function print(s) {\n// console.log(s);\n// }\n\nvar input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourceBefore = source.slice(0, l);\nvar destBefore = dest.slice(0, l);\n\nvar sourceAfter = source.slice(l + r + 1, source.length);\nvar destAfter = dest.slice(l + r + 1, source.length);\n\nvar sourcePart = source.slice(l, l + r + 1);\nvar destPart = dest.slice(l, l + r + 1);\nsourcePart.sort();\ndestPart.sort();\n\n\nvar truth = true;\n\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n print('LIE');\n truth = false;\n break;\n }\n}\n\nif (truth) {\n for (var i = 0; i < sourceBefore.length; i++) {\n if (sourceBefore[i] !== destBefore[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n\n if (truth) {\n for (var i = 0; i < sourceAfter.length; i++) {\n if (sourceAfter[i] !== destAfter[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n }\n}\n\nif (truth) {\n print('TRUTH');\n}"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ');\nvar dest = readline().split(' ');\n\nvar sourcePart = source.slice(l, l + r);\nvar destPart = dest.slice(l, l + r);\ndestPart.sort();\n\nvar truth = true;\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n truth = false;\n break;\n }\n}\n\nif (truth) {\n print('TRUTH');\n} else {\n print('LIE');\n}"}, {"source_code": "var input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourcePart = source.slice(l, l + r);\nvar destPart = dest.slice(l, l + r);\ndestPart.sort();\n\nvar truth = true;\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n truth = false;\n break;\n }\n}\n\nif (truth) {\n print('TRUTH');\n} else {\n print('LIE');\n}"}, {"source_code": "// var inputValues = [\n// // '5 2 4',\n// // '3 4 2 3 1',\n// // '3 2 3 4 1',\n\n// // '3 1 2',\n// // '1 2 3',\n// // '3 1 2',\n\n// '4 2 4',\n// '1 1 1 1',\n// '1 1 1 1'\n// // '10 3 7',\n// // '678 45 78 11 90 98 99999 21 89 9',\n// // '678 45 99999 90 11 89 98 78 21 9',\n// ]\n\n// var inputIndex = 0;\n\n// function readline() {\n// inputIndex++;\n// return inputValues[inputIndex - 1];\n// }\n\n// function print(s) {\n// console.log(s);\n// }\n\nvar input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourcePart = source.slice(l, l + r);\nvar destPart = dest.slice(l, l + r);\nsourcePart.sort();\ndestPart.sort();\n\nsource.sort();\ndest.sort();\n\nvar truth = true;\n\nfor (var i = 0; i < source.length; i++) {\n if (source[i] !== dest[i]) {\n truth = false;\n break;\n }\n}\n\nif (truth) {\n for (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n truth = false;\n break;\n }\n }\n}\n\nif (truth) {\n print('TRUTH');\n} else {\n print('LIE');\n}"}, {"source_code": "// var inputValues = [\n// // '5 2 4',\n// // '3 4 2 3 1',\n// // '3 2 3 4 1',\n\n// // '3 1 2',\n// // '1 2 3',\n// // '3 1 2',\n\n// // '4 2 4',\n// // '1 1 1 1',\n// // '1 1 1 1'\n// // '10 3 7',\n// // '678 45 78 11 90 98 99999 21 89 9',\n// // '678 45 99999 90 11 89 98 78 21 9',\n// '6 3 5',\n// '6 7 9 0 1 8',\n// '6 7 0 0 1 8'\n// ]\n\n// var inputIndex = 0;\n\n// function readline() {\n// inputIndex++;\n// return inputValues[inputIndex - 1];\n// }\n\n// function print(s) {\n// console.log(s);\n// }\n\nvar input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourceBefore = source.slice(0, l);\nvar destBefore = dest.slice(0, l);\n\nvar sourceAfter = source.slice(l + r - 1, source.length);\nvar destAfter = dest.slice(l + r - 1, source.length);\n\nvar sourcePart = source.slice(l, l + r - 1);\nvar destPart = dest.slice(l, l + r - 1);\nsourcePart.sort();\ndestPart.sort();\n\n\nvar truth = true;\n\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n print('LIE');\n truth = false;\n break;\n }\n}\n\nif (truth) {\n for (var i = 0; i < sourceBefore.length; i++) {\n if (sourceBefore[i] !== destBefore[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n\n if (truth) {\n for (var i = 0; i < sourceAfter.length; i++) {\n if (sourceAfter[i] !== destAfter[i]) {\n print('LIE');\n truth = false;\n break;\n }\n }\n }\n}\n\nif (truth) {\n print('TRUTH');\n}"}, {"source_code": "// var inputValues = [\n// // '5 2 4',\n// // '3 4 2 3 1',\n// // '3 2 3 4 1',\n\n// // '3 1 2',\n// // '1 2 3',\n// // '3 1 2',\n\n// '4 2 4',\n// '1 1 1 1',\n// '1 1 1 1'\n// ]\n\n// var inputIndex = 0;\n\n// function readline() {\n// inputIndex++;\n// return inputValues[inputIndex - 1];\n// }\n\n// function print(s) {\n// console.log(s);\n// }\n\nvar input = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar n = input[0];\nvar l = input[1] - 1;\nvar r = input[2] - 1;\n\nvar source = readline().split(' ').map(function(x) { return parseInt(x); });;\nvar dest = readline().split(' ').map(function(x) { return parseInt(x); });;\n\nvar sourcePart = source.slice(l, l + r);\nvar destPart = dest.slice(l, l + r);\nsourcePart.sort();\ndestPart.sort();\n\nvar truth = true;\nfor (var i = 0; i < sourcePart.length; i++) {\n if (sourcePart[i] !== destPart[i]) {\n truth = false;\n break;\n }\n}\n\nif (truth) {\n print('TRUTH');\n} else {\n print('LIE');\n}"}, {"source_code": "\nvar S = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = S[0]; l = S[1]; r = S[2];\nvar A = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar B = readline().split(\" \").map(function(x) { return parseInt(x); });\nl--;\nA = A.slice(l, r);\nB = B.slice(l, r);\nA.sort();\nB.sort();\nif(JSON.stringify(A) == JSON.stringify(B)){\n\tprint(\"TRUTH\");\n}else{\n\tprint(\"LIE\");\n}"}, {"source_code": "\nvar S = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = S[0]; l = S[1]; r = S[2];\nvar A = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar B = readline().split(\" \").map(function(x) { return parseInt(x); });\nl--;\nA = A.slice(l, r);\nB = B.slice(l, r);\nA.sort();\nB.sort();\nif(JSON.stringify(A) == JSON.stringify(B)){\n\tvar ok = true;\n\tfor(i = 0; i < l && ok; i++){\n\t\tif(A[i] != B[i]) ok = false;\n\t}\n\tfor(i = r; i < n && ok; i++){\n\t\tif(A[i] != B[i]) ok = false;\n\t}\n\tif(ok) print(\"TRUTH\");\n\telse print(\"LIE\");\n}else{\n\tprint(\"LIE\");\n}"}, {"source_code": "\nvar N = parseInt;\n\n\nvar d = readline().split(\" \"),\n n = N(d[0]),\n l = N(d[1]),\n r = N(d[2]);\n\nl-=1;\nr-=1;\n\nvar i=1;\n\nvar list1 =[];\nvar list2 =[];\n\nfor (i=0;i<=100000;i+=1) {\n list1[i]=0;\n list2[i]=0;\n \n}\n\nvar a1 = readline().split(\" \");\n\n\nfor (i=0;i=l)&&(i<=r)) {list2[a1[i]]+=1}\n else {list1[a1[i]]+=1}\n}\n\n\n\nvar a1 = readline().split(\" \");\n\nfor (i=0;i=l)&&(i<=r)) {list2[a1[i]]-=1}\n else {list1[a1[i]]-=1}\n}\n\n\n\nvar b=true;\n\nfor (i=0;i<=100000;i+=1) \n if ((list2[i]!=0)||(list1[i]!=0)) \n {b=false; break; }\n \n \n\n\nif (b) {print('TRUTH')} else {print('LIE')}"}, {"source_code": "\nvar N = parseInt;\n\n\nvar d = readline().split(\" \"),\n n = N(d[0]),\n l = N(d[1]),\n r = N(d[2]);\n\nl-=1;\nr-=1;\n\nvar i=1;\n\nvar list1 =[];\nvar list2 =[];\n\nfor (i=0;i<=100000;i+=1) {\n list1[i]=0;\n list2[i]=0;\n \n}\n\nvar a1 = readline().split(\" \");\n\n\nfor (i=0;i=l)&&(i<=r)) {list2[a1[i]]+=1}\n else {list1[a1[i]]+=1}\n}\n\n\n\nvar a1 = readline().split(\" \");\n\nfor (i=0;i=l)&&(i<=r)) {list2[a1[i]]-=1}\n else {list1[a1[i]]-=1}\n}\n\n\n\nvar b=true;\n\nfor (i=0;i<100000;i+=1) \n if ((list2[i]!=0)||(list1[i]!=0)) \n {b=false; break; }\n \n \n\n\nif (b) {print('TRUTH')} else {print('LIE')}"}, {"source_code": "\"use strict\";\nif (typeof readline == 'undefined') {\n let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var readline = () => lines[id++];\n var print = console.log;\n}\nlet nums = () => readline().split(' ').map(x => +x);\nlet t = nums(), n = t[0], l = --t[1], r = --t[2];\nlet a = nums();\nlet b = nums();\n\nlet c = Array(n).fill(0);\nfor (let i = l; i <= r; ++i) {\n ++c[a[i] - 1];\n --c[b[i] - 1];\n}\n\nlet ans = c.every(x => x === 0);\n\nif (ans) print(\"TRUTH\");\nelse print(\"LIE\");\n"}, {"source_code": "var n, l, r;\nvar A, B;\nvar hash = {};\nvar arr, i, ans = 'TRUTH';\narr = readline().split(' ');\narr = arr.map((s) => parseInt(s));\nn = arr[0];\nl = arr[1] - 1;\nr = arr[2] - 1;\narr = readline().split(' ');\nA = arr.map((s) => parseInt(s));\nfor (i = l; i <= r; i ++) {\n if (!hash[A[i]])\n hash[A[i]] = 1;\n else\n hash[A[i]] ++;\n}\narr = readline().split(' ');\nB = arr.map((s) => parseInt(s));\nfor (i = l; i <= r; i ++) {\n if (!hash[B[i]]) {\n ans = 'LIE';\n break;\n } else {\n hash[B[i]] --;\n }\n}\nprint(ans);"}, {"source_code": "var n, l, r;\nvar A, B;\nvar hash = {};\nvar arr, i, ans = 'TRUTH';\narr = readline().split(' ');\narr = arr.map((s) => parseInt(s));\nn = arr[0];\nl = arr[1] - 1;\nr = arr[2] - 1;\narr = readline().split(' ');\nA = arr.map((s) => parseInt(s));\nfor (i = l; i <= r; i ++) {\n if (!hash[A[i]])\n hash[A[i]] = 1;\n else\n hash[A[i]] ++;\n}\narr = readline().split(' ');\nB = arr.map((s) => parseInt(s));\nfor (i = l; i <= r; i ++) {\n if (!hash[B[i]] || hash[B[i]] === 0) {\n ans = 'LIE';\n break;\n } else {\n hash[B[i]] --;\n }\n}\nprint(ans);"}], "src_uid": "1951bf085050c7e32fcf713132b30605"} {"source_code": "/* TEST CASE\ninput\n5\n20 30 10 50 40\noutput\n4\ninput\n4\n200 100 100 200\noutput\n2\n\ninput\n177\n28 48 31 54 58 23 33 47 15 51 6 56 50 15 35 45 9 52 51 25 38 19 43 7 47 52 15 54 24 6 39 60 4 17 18 30 11 2 3 7 14 10 43 1 22 11 53 59 1 18 58 34 16 16 8 15 36 38 23 22 56 12 12 7 5 5 32 23 38 1 15 47 12 34 7 30 31 24 8 22 7 45 19 35 17 14 44 32 39 59 26 43 31 59 59 1 4 34 49 36 27 53 22 48 56 6 21 11 43 29 47 21 20 56 38 52 59 31 54 44 8 25 15 29 20 18 52 28 30 15 55 34 7 29 59 41 55 30 1 24 57 38 23 51 59 35 60 25 12 57 42 25 12 35 10 50 51 17 36 15 30 32 8 35 17 13 50 42 35 26 35 46 30 39 26 31 36\n\n*/\nfunction decrementKeys(o) {\n\tvar ret = 0;\n\tvar keysToDel = [];\n\tfor (key in o) {\n\t\tif (o.hasOwnProperty(key)) {\n\t\t\tret++;\n\t\t\tif (--o[key] == 0) {\n\t\t\t\tkeysToDel.push(key);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tfor (var i = keysToDel.length - 1; i >= 0; i--) {\n\t\tdelete o[keysToDel[i]];\n\t}\n\treturn ret;\n}\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar i;\n\tvar splitted = readline().split(' ');\n\tvar freqMap = {};\n\n\tfor (i = 0; i < n; i++) {\n\t\tvar ai = parseInt(splitted[i]);\n\t\tif (freqMap[ai] == null) {\n\t\t\tfreqMap[ai] = 1;\n\t\t} else {\n\t\t\tfreqMap[ai]++;\n\t\t}\n\t}\n\n\tvar answer = 0;\n\tvar remain = decrementKeys(freqMap);\n\t\n\twhile (remain > 0) {\n\t\tanswer += remain - 1;\n\t\tremain = decrementKeys(freqMap);\n\t}\n\n\tprint(answer);\n}\n\nmain();", "positive_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn(), a = rda();\na.sort(function(x, y){ return x-y; });\n\nvar max = 1;\nvar cur = 1;\nfor(var i = 0; i < n-1; i++){\n if(a[i] == a[i+1]){\n cur++;\n max = Math.max(max, cur);\n }else{\n cur = 1;\n }\n}\n\nvar ans = n - max;\nwrite(ans);"}, {"source_code": "var n = Number(readline());\nvar paintings = readline().split(' ').map(Number);\n\n\n/* Without the function, the default sort would convert to string and mess up */\npaintings.sort(function(a, b) {\n\treturn a - b;\n});\n\n/* I want to split paintings into increasing miniarrays */\nvar max_chunk = 1;\nvar curr_chunk = 1;\n\nfor (var i = 0; i < n; i++) {\n\tif (paintings[i] == paintings[i + 1]) {\n\t\tcurr_chunk += 1;\n\t\tif (curr_chunk >= max_chunk) {\n\t\t\tmax_chunk = curr_chunk;\n\t\t}\n\t} else {\n\t\tcurr_chunk = 1;\n\t}\n}\n\nvar happy = n - max_chunk;\n\nprint(happy);\n"}, {"source_code": "/** B. Beautiful Paintings\n\nThere are n pictures delivered for the new exhibition. The i-th painting has\nbeauty ai. We know that a visitor becomes happy every time he passes from a\npainting to a more beautiful one.\n\nWe are allowed to arranged pictures in any order. What is the maximum possible\nnumber of times the visitor may become happy while passing all pictures from\nfirst to last? In other words, we are allowed to rearrange elements of a in\nany order. What is the maximum possible number of indices i (1\u2009\u2264\u2009i\u2009\u2264\u2009n\u2009-\u20091),\nsuch that ai\u2009+\u20091\u2009>\u2009ai.\n\nInput\nThe first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of\npainting.\n\nThe second line contains the sequence a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u20091000), where\nai means the beauty of the i-th painting.\n\nOutput\nPrint one integer \u2014 the maximum possible number of neighbouring pairs, such\nthat ai\u2009+\u20091\u2009>\u2009ai, after the optimal rearrangement.\n\n\n5\n20 30 10 50 40\n> 4\n\n4\n200 100 100 200\n> 2\n\n6\n10 10 10 20 30 40\n> 3\n(via 10 20 30 40 10 10 or 10 20 10 30 10 40)\n\n */\n\nvar countHappiness = function(numPaintings, paintingStats) {\n /**\n e.g.\n numPaintings = 7;\n paintingStats = [10, 10, 10, 20, 30, 40, 40];\n --\n numPaintingsWithEachStat = [\n 10: 3,\n 20: 1,\n 30: 1,\n 40: 2,\n ];\n --\n happinessAtThisCount = [\n 1: true,\n 2: true,\n 3: true,\n ];\n --\n */\n var happiness = 0;\n if (numPaintings === 0 || numPaintings === 1) {\n print(happiness);\n return;\n }\n\n var numPaintingsWithEachStat = [];\n\n for (var i = 0; i < numPaintings; i++) {\n var paintingStat = paintingStats[i];\n if (numPaintingsWithEachStat[paintingStat] == null) {\n numPaintingsWithEachStat[paintingStat] = 0;\n }\n numPaintingsWithEachStat[paintingStat]++;\n }\n\n var happinessAtThisCount = [];\n for (var i = 0; i < numPaintingsWithEachStat.length; i++) {\n if (numPaintingsWithEachStat[i] != null) {\n for (var j = numPaintingsWithEachStat[i]; j > 0; j--) {\n if (happinessAtThisCount[j] != null) {\n happiness++;\n }\n happinessAtThisCount[j] = true;\n }\n }\n }\n print(happiness);\n}\n\nvar numPaintings = readline().split(' ');\nvar paintingStats = readline().split(' ');\ncountHappiness(numPaintings, paintingStats)"}, {"source_code": "\nvar print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, array, count = [], prev, answer = 0;\nn = Number(readline());\narray = readline().split(' ').map(Number).sort();\nfunction check (value) {\n return value > 0;\n}\n\nfor (i = 0; i < n; i++) {\n\n if (array[i] != prev) {\n count.push(1);\n } else {\n count[count.length - 1]++;\n }\n prev = array[i];\n}\n\nwhile (count.length > 1) {\n\n answer += count.length - 1;\n count = count.map(x => x - 1);\n count = count.filter(check);\n}\n\nprint(answer);"}, {"source_code": "var count = readline();\nvar input = readline().split(' ');\nvar n = input;\n\nvar group = function(a) {\n var excess = [];\n var distinct = a.reduce(function(result, item) {\n if (result.indexOf(item) == -1) {\n result.push(item);\n } else {\n excess.push(item);\n }\n return result;\n }, []);\n\n return [distinct, excess];\n};\n\nvar result = 0;\nvar dirty = n.splice(0);\ndo {\n var grouped = group(dirty);\n result += grouped[0].length - 1;\n dirty = grouped[1];\n} while (dirty.length != 0)\n\nprint(result);"}, {"source_code": "var n = Number(readline());\nvar arr = readline().split(\" \", n).map(Number);\n\nvar num = [], maxNum = 0;\nfor (var i = 0; i < n; ++i) {\n if (!num[arr[i]]) {\n num[arr[i]] = 0;\n }\n ++num[arr[i]];\n maxNum = Math.max(maxNum, num[arr[i]]);\n}\n\nprint(n - maxNum);"}, {"source_code": "var n = readline(), beaut = readline().split(\" \"), h = [], max = 0;\nfor (var i = 0; i < n; i++) {\n if (!h[beaut[i]])\n h[beaut[i]] = 0;\n h[beaut[i]]++;\n max = Math.max(max, h[beaut[i]]);\n}\nprint(n - max);"}], "negative_code": [{"source_code": "/* TEST CASE\ninput\n5\n20 30 10 50 40\noutput\n4\ninput\n4\n200 100 100 200\noutput\n2\n\n*/\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(' ');\n\tvar a = new Array(n);\n\tvar i, j;\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t}\n\ta.sort(function(v1, v2) {return v1 - v2});\n\t\n\tfor (i = 0; i < n - 1; i++) {\n\t\tj = i + 1;\n\t\twhile (j < n && a[j] == a[i]) {\n\t\t\tj++;\n\t\t}\n\t\t\n\t\tif (j > i + 1 && j < n) {\n\t\t\tvar temp = a[j];\n\t\t\ta[j] = a[i + 1]\n\t\t\ta[i + 1] = temp;\n\t\t\ti++;\n\t\t}\n\t}\n\t\n\tvar answer = 0;\n\t\n\tfor (i = 1; i < n; i++) {\n\t\tif (a[i - 1] < a[i]) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\t\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5\n20 30 10 50 40\noutput\n4\ninput\n4\n200 100 100 200\noutput\n2\n\n*/\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar last = n - 1;\n\tvar a = new Array(n);\n\tvar i, j;\n\tvar splitted = readline().split(' ');\n\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t}\n\n\ta.sort(function(v1, v2) {return v1 - v2;});\n\n\tfor (i = 0; i < last; i++) {\n\t\tj = i + 1;\n\t\twhile (j < n && a[j] == a[i]) {\n\t\t\tj++;\n\t\t}\n\t\t\n\t\tif (j > i + 1 && j < last) {\n\t\t\ti++;\n\t\t\tvar temp = a[j];\n\t\t\ta[j] = a[i]\n\t\t\ta[i] = temp;\n\t\t}\n\t}\n\t\n\tvar answer = 0;\n\t\n\tfor (i = 0; i < last; i++) {\n\t\tif (a[i + 1] > a[i]) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\t\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var count = readline();\nvar n = readline().split(' ');\n\nvar filtered = n.reduce(function(result, item) {\n if (!result) {result=[]}\n if (result.indexOf(item) == -1) {\n result.push(item);\n }\n return result;\n}, []);\n\nprint(filtered.length - 1);\n\n"}, {"source_code": "var count = readline();\nvar n = readline().split(' ');\n\nvar filtered = n.reduce(function(result, item) {\n if (!result) {result=[]}\n if (result.indexOf(item) == -1) {\n result.push(item);\n }\n return result;\n}, []);\n\nprint(filtered.length);\n\n"}], "src_uid": "30ad5bdc019fcd8a4e642c90decca58f"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m] = readInts(input, 0)\n const ai = readInts(input, 1)\n if(n > m) wr(0)\n else {\n let p = 1\n sort(ai, false)\n for(let i = 0; i < n - 1; i ++) {\n for(let j = i + 1; j < n; j ++) {\n p *= ((ai[i] - ai[j]) % m)\n p = p % m\n }\n }\n wr(p % m)\n }\n}", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (n, m, a) => {\n if (n > m) return 0;\n let r = 1;\n\n for (let i = 0; i < n - 1; i++)\n for (let j = i + 1; j < n; j++)\n r = (r * (a[j] -= a[i])) % m;\n\n return Math.abs(r);\n}\n\nconst nm = readline().split(' ').map(i => +i);\nconst n = nm[0], m = nm[1];\n\nprint(problem(n, m, readline().split(' ').map(i => +i)))\n"}, {"source_code": "var sizes = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar a = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar prod = 1,stop = 0\nif (sizes[0] > sizes[1]){\n print(0)\n}\nelse {\nwhile (stop < sizes[0]){\n for(var k = stop+1; k < sizes[0];k++){\n prod *= Math.abs(a[stop]-a[k])\n prod %= sizes[1]\n }\n stop += 1\n}\nprint(prod)\n}"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0];\nvar m = input[1];\nvar arr = readline().split(' ');\nvar result = 1;\nvar printed = false;\nvar possibleRemainders = {};\n\nfor (var i=0; i Number(e))\nconst arr = input[1].split(\" \").map(e => Number(e))\nvar res = 1\nif(n > mod)\n console.log(0)\nelse{\n for(let i = 0; i < n-1; i++){\n for(let j = i+1; j < n; j++){\n res = (res*Math.abs(arr[i]-arr[j]))%mod\n }\n }\n res = res%mod\n console.log(res)\n}\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\nprocessData(_input);\n});\n"}], "negative_code": [{"source_code": "var sizes = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar a = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar prod = 1,stop = 0\nif (sizes[0] > sizes[1]){\n print(0)\n}\nelse {\nwhile (stop < sizes[0]){\n for(var k = stop+1; k < sizes[0];k++){\n prod *= Math.abs(a[stop]-a[k])\n prod %= sizes[1]\n }\n stop += 1\n}\n}\nprint(prod)"}, {"source_code": "var sizes = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar a = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar prod = 1,stop = 0\nif (sizes[0] > sizes[1]){\n print(0)\n}\nelse {\nwhile (stop < sizes[0]){\n for(var k = stop+1; k < sizes[0];k++){\n prod *= Math.abs(a[stop]-a[k])%sizes[1]\n }\n stop += 1\n}\n}\nprint(prod)"}, {"source_code": "var sizes = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar a = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar prod = 1,stop = 0\nif (sizes[0] > sizes[1]){\n print(0)\n}\nelse {\nwhile (stop < sizes[0]){\n for(var k = stop+1; k < sizes[0];k++){\n prod *= Math.abs(a[stop]-a[k])\n }\n stop += 1\n}\n}\nprint(prod%sizes[1])"}, {"source_code": "var sizes = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar a = readline().split(' ').map((val)=>{\n return parseInt(val)\n })\nvar prod = 1,stop = 0\nif (sizes[0] > sizes[1]){\n print(0)\n}\nelse {\nwhile (stop < sizes[0]){\n for(var k = stop+1; k < sizes[0];k++){\n prod *= Math.abs(a[stop]-a[k])\n }\n stop += 1\n}\n}\nprint (stop%sizes[1])"}, {"source_code": "'use strict'\n\n\nconst problem = (n, m, a) => {\n if (n >= m) return 0;\n\n a = a.map(i => +i % m)\n let p = new Array(m); p[0] = true;\n for (let i = 0; i < n; i++) {\n const x = a[i];\n if (p[x]) return 0;\n p[x] = x;\n }\n a = p.filter(Boolean).slice(1);\n let r = 1;\n for (let i = 0; i < n - 1; i++) {\n const x = a[i];\n for (let j = i + 1; j < n; j++) r = (r * (a[j] = a[j] - x)) % m;\n }\n return r;\n}\n\nconst nm = readline().split(' ').map(i => +i);\nconst n = nm[0], m = nm[1];\nprint(problem(n, m, readline().split(' ')))\n"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0];\nvar m = input[1];\nvar arr = readline().split(' ');\nvar result = 1;\nvar printed = false;\nfor (var i=0; i {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", _ => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => {\n return string.trim();\n });\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main(){\n const [n, mod] = readline().split(\" \").map(e => Number(e))\n const arr = readline().split(\" \").map(e => Number(e))\n var stack = []\n for(let i = 0; i < n-1; i++){\n for(let j = i+1; j < n; j++){\n stack.push(Math.abs(arr[i]-arr[j]))\n }\n }\n var res = 1\n for(let i = 0; i < stack.length; i++){\n res *= stack[i]\n }\n res = res%mod\n console.log(res)\n}\n"}, {"source_code": "function processData(input) {\n input = input.split(\"\\n\")\n const [n, mod] = input[0].split(\" \").map(e => Number(e))\n const arr = input[1].split(\" \").map(e => Number(e))\n var res = 1\n if(n > mod)\n console.log(0)\n else{\n for(let i = 0; i < n-1; i++){\n for(let j = i+1; j < n; j++){\n res = res*(Math.abs(arr[i]-arr[j])%mod)\n }\n }\n res = res%mod\n console.log(res)\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}], "src_uid": "bf115b24d85a0581e709c012793b248b"} {"source_code": "var n = Number(readline()),\narray = readline().split(\" \").map(x => Number(x)),\nresult = \"NO\";\nfor (var i = 0; i < array.length; i++) {\n\tif (i != array[array[i] - 1] - 1 && array[array[array[i] - 1] - 1] - 1 == i) {\n\t\tresult = \"YES\";\n\t\tbreak;\n\t}\n}\nprint(result);", "positive_code": [{"source_code": "var n = readline();\nvar fn = readline().split(' ');\n\nvar no = true;\n\nfor(var i = 0; i < fn.length; i++)\n{\n fn[i] = int(fn[i]);\n}\n\nfor(var i = 0; i < int(n); i++)\n{\n var m = [];\n m.push(i+1);\n m.push(fn[i]);\n m.push(fn[fn[i]-1]);\n m.push(fn[fn[fn[i]-1]-1]);\n\n if(m[0] == m[3])\n {\n no = false;\n write(\"YES\");\n break;\n }\n}\nif(no)\n{\n write(\"NO\");\n}\n\n\nfunction int(val)\n{\n return parseInt(val);\n}"}, {"source_code": "\tvar nr = readline();\n\tvar planes = readline().split(\" \");\n\tvar pivot;\n var pivotLoves;\n\n var res = \"NO\";\n \n\tfor (var i = 0; i {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\tlet arr = inputReader.readNumberArray();\n\tlet obj={}\n\t\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar tmp = nextIntArray();\n\tvar list = new Array(N);\n\tfor(var i = 0; i < N; i++){\n\t\tlist[i] = {\n\t\t\tno : i,\n\t\t\tnext : tmp[i] - 1\n\t\t};\n\t}\n\tvar isOK = false;\n\tfor(var i = 0; i < N; i++){\n\t\tvar now = i;\n\t\tvar count = 0;\n\t\twhile(count < 3){\n\t\t\tnow = list[now].next;\n\t\t\tif(now == i && count == 2){\n\t\t\t\tisOK = true;\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t}\n\tmyout((isOK) ? \"YES\" : \"NO\");\n\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 'NO';\n const arr = d.split(' ').map(Number);\n\n for (let i = 0; i < arr.length; i++) {\n let idx = 0;\n let start = arr[i];\n let end = start;\n\n while (idx < 3) {\n end = arr[end - 1];\n idx++;\n }\n\n if (start === end) {\n ans = 'YES';\n break\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 'NO';\n // const arr = d.split(' ').map(Number);\n const arr = [0, ...d.split(' ').map(Number)];\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[arr[arr[i]]] === i) {\n ans = 'YES';\n break;\n }\n }\n\n // for (let i = 0; i < arr.length; i++) {\n // let idx = 0;\n // let start = arr[i];\n // let end = start;\n\n // while (idx < 3) {\n // end = arr[end - 1];\n // idx++;\n // }\n\n // if (start === end) {\n // ans = 'YES';\n // break\n // }\n // }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let n=parseInt(lines[0]);\n let line=lines[1];\n line=line.split(' ');\n for (let i=0; i input += c);\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = input.split(EOL);\n main(lines);\n});\n\n\nfunction main(lines) {\n const n = lines[0];\n const f = [0].concat(lines[1].split(' ').map(v => +v));\n const visited = new Set();\n\n for (let v = 1; v <= n; v++) {\n if (visit(f, v, visited, [])) {\n console.log(\"YES\");\n return;\n }\n }\n console.log(\"NO\");\n}\n\nfunction visit(f, v, visited, path) {\n if (visited.has(v)) {\n return false;\n }\n const next_v = f[v];\n const len = path.length;\n if (path[len - 2] === next_v) {\n return true;\n }\n\n visited.add(v);\n path.push(v);\n\n return visit(f, next_v, visited, path);\n}\n\n// main(['5', '2 4 5 1 3']);\n// main(['5', '5 5 5 5 1']);\n"}, {"source_code": "readline(); const ns = [0, ...readline().split(' ')]\nprint(ns.find((_,i) => (i !== 0) ? ns[ns[ns[i]]] == i : null) ? 'YES' : 'NO')\n"}, {"source_code": "const s = readline(); const ns = [0, ...readline().split(' ')]\nfor (var i = 1; i <= s; i++)\nif(ns[ns[ns[i]]] == i) break\nprint(i <= s ? 'YES' : 'NO')\n"}, {"source_code": "var doesntExist = true;\n\nvar n = parseInt(readline());\nvar planes = readline().split(' ').map(function(x) {\n return parseInt(x);\n});\n\nfor (var i = 0; i < n; i++) {\n firstPlanesLove = planes[i];\n secondPlanesLove = planes[firstPlanesLove - 1];\n\n thirdPlanesLove = planes[secondPlanesLove - 1];\n\n if (thirdPlanesLove === i + 1) {\n print('YES');\n doesntExist = false;\n break;\n }\n}\n\nif (doesntExist) {\n print('NO');\n}"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i {\n return input[i - 1]\n}\nfor (var i = 1; i <= n; i++) {\n if (traverse(traverse(traverse(i))) == i) {\n isTri = true;\n break;\n }\n\n}\n\n\nisTri ? print('YES') : print('NO');\n\n\n\n\n\n//demo(5, '5 5 5 5 1')"}, {"source_code": "var n = readline()\nvar input = readline().split(' ');\n\n\n\nvar isTri = false;\nvar traverse = (i) => {\n return input[i - 1]\n}\nfor (var i = 1; i <= n; i++) {\n var start = i;\n if (traverse(traverse(traverse(i))) == i) {\n isTri = true;\n break;\n }\n\n}\n\n\nisTri ? print('YES') : print('NO')\n\n\n\n\n\n//demo(5, '5 5 5 5 1')"}, {"source_code": "var a = Number(readline());\nvar b = readline().split(' ').map(e=>Number(e));\n\nfor(var i = 0; i < a; i++){\n\tif(b[b[b[b[i]-1]-1]-1] === b[i]){\n\t\tif(b[b[b[i]-1]-1] !== b[i]){\n\t\t\tprint(\"YES\");\n\t\t\tbreak\n\t\t}\n\t} else if (i === b.length - 1){\n\t\tprint('NO');\n\t}\n}"}], "negative_code": [{"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\tlet arr = inputReader.readNumberArray();\n\tlet obj={}\n\t\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\tlet arr = inputReader.readNumberArray();\n\tlet obj={}\n\t\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\tlet arr = inputReader.readNumberArray();\n\tlet obj={};\n\t\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\tlet arr = inputReader.readNumberArray();\n\tlet obj={};\n\t\n\tfor(let i =0;i Number(val));\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadNumberArray,\n\t}\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 'NO';\n const arr = d.split(' ').map(Number);\n\n for (let i = 0; i < arr.length; i++) {\n let idx = 0;\n let start = arr[i];\n let end = start;\n\n while (idx < 3) {\n end = arr[end];\n idx++;\n }\n\n if (start === end) {\n ans = 'YES';\n break\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "readline(); const ns = readline().split(' ')\nprint(ns.map(n => +n + 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')"}, {"source_code": "readline(); const ns = [0, ...readline().split(' ')];\nprint(ns.find((_,i) => ns[ns[ns[i + 1]]] == i + 1) ? 'YES' : 'NO')"}, {"source_code": "readline(); const ns = readline().split(' ')\nprint(ns.map(n => n - 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')"}, {"source_code": "var print = this.print || require(\"lol-io\").print;\nvar readline = this.readline || require(\"lol-io\").readline;\n\nreadline(); const ns = readline().split(' ')\nprint(ns.find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')"}, {"source_code": "readline(); const ns = [0, ...readline().split(' ')];\nprint(ns.find((_,i) => ns[ns[ns[i - 1]]] == i - 1) ? 'YES' : 'NO')"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;iNumber(e));\n\nfor(var i = 0; i < a; i++){\n\tif(b[b[b[i]]] === b[i]){\n\t\tprint('YES');\n\t} else if (i === b.length - 1){\n\t\tprint('NO');\n\t}\n}"}, {"source_code": "var a = Number(readline());\nvar b = readline().split(' ').map(e=>Number(e));\n\nfor(var i = 0; i < a; i++){\n\tif(b[b[b[i]-1]-1] === b[i]){\n\t\tprint('YES');\n\t\tbreak\n\t} else if (i === b.length - 1){\n\t\tprint('NO');\n\t}\n}"}, {"source_code": "var a = Number(readline());\nvar b = readline().split(' ').map(e=>Number(e));\n\nfor(var i = 0; i < a; i++){\n\tif(b[b[b[i]-1]-1] === b[i]){\n\t\tprint('YES');\n\t} else if (i === b.length - 1){\n\t\tprint('NO');\n\t}\n}"}, {"source_code": "var a = Number(readline());\nvar b = readline().split(' ').map(e=>Number(e));\n\nfor(var i = 0; i < a; i++){\n\tif(b[b[b[i]-1]-1] === b[i]){\n\t\tif(!(b[b[i]-1] === b[i])){\n\t\t\tprint(\"YES\");\n\t\t\tbreak\n\t\t}\n\t} else if (i === b.length - 1){\n\t\tprint('NO');\n\t}\n}"}, {"source_code": "\tvar nr = readline();\n\tvar planes = readline().split(\" \");\n\tvar pivot;\n var pivotLoves;\n var loved;\n \n var res = \"NO\";\n \n\tfor (var i = 1; i<=nr; i++) {\n \tpivot = i;\n pivotLoves = planes[i];\n if (planes[planes[pivotLoves]] == pivot) {\n \tres = \"YES\";\n }\n }\n print(res);"}], "src_uid": "a37c3f2828490c70301b5b5deeee0f88"} {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; i{\r\n\r\n let arrNum = arr.map(el=>parseInt(el));\r\n let n = arrNum.length;\r\n let set = new Set();\r\n\r\n \r\n for(let i =0; i y) {\n return 1;\n }\n return 0;\n };\n\n\n /*\n Insert item x in list a, and keep it sorted assuming a is sorted.\n \n If x is already in a, insert it to the right of the rightmost x.\n \n Optional args lo (default 0) and hi (default a.length) bound the slice\n of a to be searched.\n */\n\n insort = function(a, x, lo, hi, cmp) {\n var mid;\n if (lo == null) {\n lo = 0;\n }\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (lo < 0) {\n throw new Error('lo must be non-negative');\n }\n if (hi == null) {\n hi = a.length;\n }\n while (lo < hi) {\n mid = floor((lo + hi) / 2);\n if (cmp(x, a[mid]) < 0) {\n hi = mid;\n } else {\n lo = mid + 1;\n }\n }\n return ([].splice.apply(a, [lo, lo - lo].concat(x)), x);\n };\n\n\n /*\n Push item onto heap, maintaining the heap invariant.\n */\n\n heappush = function(array, item, cmp) {\n if (cmp == null) {\n cmp = defaultCmp;\n }\n array.push(item);\n return _siftdown(array, 0, array.length - 1, cmp);\n };\n\n\n /*\n Pop the smallest item off the heap, maintaining the heap invariant.\n */\n\n heappop = function(array, cmp) {\n var lastelt, returnitem;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n lastelt = array.pop();\n if (array.length) {\n returnitem = array[0];\n array[0] = lastelt;\n _siftup(array, 0, cmp);\n } else {\n returnitem = lastelt;\n }\n return returnitem;\n };\n\n\n /*\n Pop and return the current smallest value, and add the new item.\n \n This is more efficient than heappop() followed by heappush(), and can be\n more appropriate when using a fixed size heap. Note that the value\n returned may be larger than item! That constrains reasonable use of\n this routine unless written as part of a conditional replacement:\n if item > array[0]\n item = heapreplace(array, item)\n */\n\n heapreplace = function(array, item, cmp) {\n var returnitem;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n returnitem = array[0];\n array[0] = item;\n _siftup(array, 0, cmp);\n return returnitem;\n };\n\n\n /*\n Fast version of a heappush followed by a heappop.\n */\n\n heappushpop = function(array, item, cmp) {\n var _ref;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (array.length && cmp(array[0], item) < 0) {\n _ref = [array[0], item], item = _ref[0], array[0] = _ref[1];\n _siftup(array, 0, cmp);\n }\n return item;\n };\n\n\n /*\n Transform list into a heap, in-place, in O(array.length) time.\n */\n\n heapify = function(array, cmp) {\n var i, _i, _j, _len, _ref, _ref1, _results, _results1;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n _ref1 = (function() {\n _results1 = [];\n for (var _j = 0, _ref = floor(array.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }\n return _results1;\n }).apply(this).reverse();\n _results = [];\n for (_i = 0, _len = _ref1.length; _i < _len; _i++) {\n i = _ref1[_i];\n _results.push(_siftup(array, i, cmp));\n }\n return _results;\n };\n\n\n /*\n Update the position of the given item in the heap.\n This function should be called every time the item is being modified.\n */\n\n updateItem = function(array, item, cmp) {\n var pos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n pos = array.indexOf(item);\n if (pos === -1) {\n return;\n }\n _siftdown(array, 0, pos, cmp);\n return _siftup(array, pos, cmp);\n };\n\n\n /*\n Find the n largest elements in a dataset.\n */\n\n nlargest = function(array, n, cmp) {\n var elem, result, _i, _len, _ref;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n result = array.slice(0, n);\n if (!result.length) {\n return result;\n }\n heapify(result, cmp);\n _ref = array.slice(n);\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n elem = _ref[_i];\n heappushpop(result, elem, cmp);\n }\n return result.sort(cmp).reverse();\n };\n\n\n /*\n Find the n smallest elements in a dataset.\n */\n\n nsmallest = function(array, n, cmp) {\n var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (n * 10 <= array.length) {\n result = array.slice(0, n).sort(cmp);\n if (!result.length) {\n return result;\n }\n los = result[result.length - 1];\n _ref = array.slice(n);\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n elem = _ref[_i];\n if (cmp(elem, los) < 0) {\n insort(result, elem, 0, null, cmp);\n result.pop();\n los = result[result.length - 1];\n }\n }\n return result;\n }\n heapify(array, cmp);\n _results = [];\n for (i = _j = 0, _ref1 = min(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {\n _results.push(heappop(array, cmp));\n }\n return _results;\n };\n\n _siftdown = function(array, startpos, pos, cmp) {\n var newitem, parent, parentpos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n newitem = array[pos];\n while (pos > startpos) {\n parentpos = (pos - 1) >> 1;\n parent = array[parentpos];\n if (cmp(newitem, parent) < 0) {\n array[pos] = parent;\n pos = parentpos;\n continue;\n }\n break;\n }\n return array[pos] = newitem;\n };\n\n _siftup = function(array, pos, cmp) {\n var childpos, endpos, newitem, rightpos, startpos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n endpos = array.length;\n startpos = pos;\n newitem = array[pos];\n childpos = 2 * pos + 1;\n while (childpos < endpos) {\n rightpos = childpos + 1;\n if (rightpos < endpos && !(cmp(array[childpos], array[rightpos]) < 0)) {\n childpos = rightpos;\n }\n array[pos] = array[childpos];\n pos = childpos;\n childpos = 2 * pos + 1;\n }\n array[pos] = newitem;\n return _siftdown(array, startpos, pos, cmp);\n };\n\n Heap = (function() {\n Heap.push = heappush;\n\n Heap.pop = heappop;\n\n Heap.replace = heapreplace;\n\n Heap.pushpop = heappushpop;\n\n Heap.heapify = heapify;\n\n Heap.updateItem = updateItem;\n\n Heap.nlargest = nlargest;\n\n Heap.nsmallest = nsmallest;\n\n function Heap(cmp) {\n this.cmp = cmp != null ? cmp : defaultCmp;\n this.nodes = [];\n }\n\n Heap.prototype.push = function(x) {\n return heappush(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.pop = function() {\n return heappop(this.nodes, this.cmp);\n };\n\n Heap.prototype.peek = function() {\n return this.nodes[0];\n };\n\n Heap.prototype.contains = function(x) {\n return this.nodes.indexOf(x) !== -1;\n };\n\n Heap.prototype.replace = function(x) {\n return heapreplace(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.pushpop = function(x) {\n return heappushpop(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.heapify = function() {\n return heapify(this.nodes, this.cmp);\n };\n\n Heap.prototype.updateItem = function(x) {\n return updateItem(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.clear = function() {\n return this.nodes = [];\n };\n\n Heap.prototype.empty = function() {\n return this.nodes.length === 0;\n };\n\n Heap.prototype.size = function() {\n return this.nodes.length;\n };\n\n Heap.prototype.clone = function() {\n var heap;\n heap = new Heap();\n heap.nodes = this.nodes.slice(0);\n return heap;\n };\n\n Heap.prototype.toArray = function() {\n return this.nodes.slice(0);\n };\n\n Heap.prototype.insert = Heap.prototype.push;\n\n Heap.prototype.top = Heap.prototype.peek;\n\n Heap.prototype.front = Heap.prototype.peek;\n\n Heap.prototype.has = Heap.prototype.contains;\n\n Heap.prototype.copy = Heap.prototype.clone;\n\n return Heap;\n\n })();\n\n (function(root, factory) {\n // if (typeof define === 'function' && define.amd) {\n // return define([], factory);\n // } else if (typeof exports === 'object') {\n // return module.exports = factory();\n // } else {\n return root.Heap = factory();\n // }\n })(this, function() {\n return Heap;\n });\n\n}).call(this);\nconst Heap = this.Heap\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n // arr.sort((a, b) => b - a)\n const h = new Heap((a, b) => b - a)\n h.nodes = arr\n h.heapify()\n for (let i = n; i >= 1; i--) {\n if (!h.size()) return false\n let found = false\n while (h.size()) {\n let x = h.peek()\n if (x < i) break\n\n x = h.pop()\n let skip = false\n while (x >= i) {\n if (x === i && !found) {\n found = true\n skip = true\n }\n x = Math.floor(x / 2)\n }\n if (!skip) h.push(x)\n }\n // console.log(arr)\n if (!found) return false\n }\n return true\n}\n"}, {"source_code": "const solve = (n,arr)=>{\r\n let obj = {};\r\n for(let i=0;in) t>>=1;\r\n if(obj[t]){\r\n if(t===1) return \"NO\";\r\n let k = t;\r\n let flag = 0;\r\n while(k>=1){\r\n if(!obj[k]){\r\n obj[k] = 1;\r\n flag = 1;\r\n break;\r\n }\r\n k>>=1\r\n }\r\n if(flag===0) return \"NO\";\r\n }\r\n else obj[t] = 1;\r\n }\r\n return \"YES\";\r\n}\r\n\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let set = new Set(),\r\n st = [];\r\n for (let [i, num] of a.entries()) {\r\n if (num <= n && !set.has(num)) {\r\n st[i] = 1;\r\n set.add(num);\r\n }\r\n }\r\n let max = n.toString(2).length;\r\n next: for (let [i, num] of a.entries()) {\r\n if (st[i]) continue;\r\n const len = num.toString(2).length;\r\n for (let i = Math.min(max, len); i > 0; i--) {\r\n const num1 = num >> len - i;\r\n if (num1 > n) continue;\r\n if (!set.has(num1)) {\r\n set.add(num1);\r\n continue next;\r\n }\r\n }\r\n return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tfunction canreduce (a, n) {\r\n\t\t\twhile (n > a) {\r\n\t\t\t\tn = n >> 1;\r\n\t\t\t}\r\n\t\t\treturn a == n;\r\n\t\t}\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = n; ok && i >= 1; i--) {\r\n\t\t\tok = false;\r\n\t\t\tfor (let j = 0; !ok && j < n; j++) {\r\n\t\t\t\tif (canreduce(i, a[j])) {\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t\ta[j] = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const tsc = await readInt();\r\n const can_num = (n, mask) => {\r\n while (n > mask) {\r\n n = n >> 1;\r\n }\r\n return n === mask;\r\n }\r\n\r\n for(let sc = 0; sc < tsc; sc++) {\r\n const n = await readInt();\r\n const a = await readIntArray();\r\n let can = true;\r\n for(let i = n; i >= 1; i--) {\r\n let fnd = false;\r\n for(let j = 0; j < n; j++)\r\n if (a[j] !== 0 && can_num(a[j], i)) {\r\n a[j] = 0;\r\n fnd = true;\r\n break;\r\n }\r\n if (!fnd) {\r\n can = false;\r\n break;\r\n }\r\n }\r\n if (can)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n\r\n var ans = [];\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (inp[i] <= n && !ans.includes(inp[i])) {\r\n ans.push(inp[i]);\r\n } else {\r\n var val = inp[i];\r\n while (val > 0) {\r\n if (val <= n && !ans.includes(val)) {\r\n ans.push(val);\r\n break;\r\n }\r\n val = Math.floor(val / 2);\r\n }\r\n }\r\n }\r\n\r\n for (var i = 1; i <= n; i++) {\r\n if (!ans.includes(i)) {\r\n return \"NO\";\r\n }\r\n }\r\n\r\n return \"YES\";\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N,\r\n arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(Number);\r\n\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, input) {\r\n const arr = input.slice();\r\n const seen = new Set();\r\n\r\n for (let i = 0; i < N; ++i) {\r\n while (arr[i]) {\r\n if (arr[i] <= N && !seen.has(arr[i])) {\r\n seen.add(arr[i]);\r\n break;\r\n }\r\n\r\n arr[i] = Math.floor(arr[i] / 2);\r\n }\r\n }\r\n\r\n for (let i = 1; i <= N; ++i) {\r\n if (!seen.has(i)) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n\r\n console.log('YES');\r\n}"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n\r\n let j = 2;\r\n for (let i = 0; i < lines[0]; ++i) {\r\n const arr = lines[j].split(' ').map((el) => +el);\r\n\r\n const n = arr.length;\r\n\r\n let copy = new Array(n);\r\n\r\n for (let i = 0; i < n; ++i) {\r\n copy[i] = [];\r\n while (arr[i] > 0) {\r\n if (arr[i] <= n) {\r\n copy[i].push(arr[i]);\r\n }\r\n arr[i] = Math.floor(arr[i] / 2);\r\n }\r\n }\r\n\r\n let found = false;\r\n\r\n\r\n const visited = new Set();\r\n\r\n const dp = (pos, set, str) => {\r\n if (pos === n || found) {\r\n if (set.size === n) {\r\n found = true;\r\n }\r\n return;\r\n }\r\n for (let i = 0; i < copy[pos].length; ++i) {\r\n if (!set.has(copy[pos][i]) && !visited.has(str)) {\r\n set.add(copy[pos][i]);\r\n visited.add(str);\r\n dp(pos + 1, set, str + copy[pos][i]);\r\n set.delete(copy[pos][i]);\r\n }\r\n }\r\n }\r\n\r\n dp(0, new Set(), '');\r\n\r\n console.log(found ? 'YES' : 'NO');\r\n\r\n j += 2;\r\n }\r\n});\r\n"}], "negative_code": [{"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n\r\n let j = 2;\r\n for (let i = 0; i < lines[0]; ++i) {\r\n const arr = lines[j].split(' ').map((el) => +el);\r\n\r\n const n = arr.length;\r\n\r\n let copy = new Array(n);\r\n\r\n for (let i = 0; i < n; ++i) {\r\n copy[i] = [];\r\n while (arr[i] > 0) {\r\n if (arr[i] <= n) {\r\n copy[i].push(arr[i]);\r\n }\r\n arr[i] = Math.floor(arr[i] / 2);\r\n }\r\n }\r\n\r\n let set = new Set();\r\n for (let i = 0; i < n; ++i) {\r\n for (let j = 0; j < copy[i].length; ++j) {\r\n set.add(copy[i]);\r\n }\r\n }\r\n\r\n let found = false;\r\n\r\n if (set.size === n) {\r\n found = true;\r\n }\r\n\r\n //const visited = new Set();\r\n\r\n // const dp = (pos, set, str) => {\r\n // if (pos === n || found) {\r\n // if (set.size === n) {\r\n // found = true;\r\n // }\r\n // return;\r\n // }\r\n // for (let i = 0; i < copy[pos].length; ++i) {\r\n // if (!set.has(copy[pos][i]) || visited.has(str)) {\r\n // set.add(copy[pos][i]);\r\n // visited.add(str);\r\n // dp(pos + 1, set, str + copy[pos][i]);\r\n // set.delete(copy[pos][i]);\r\n // }\r\n // }\r\n // }\r\n\r\n // dp(0, new Set(), '');\r\n\r\n console.log(found ? 'YES' : 'NO');\r\n\r\n j += 2;\r\n }\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n const rmap = []\n arr.forEach((x, i) => {\n rmap[i] = []\n while (x) {\n map[x] = map[x] || []\n map[x].push(i)\n rmap[i].push(x)\n x = Math.floor(x / 2)\n }\n })\n rmap.sort((a, b) => a.length - b.length)\n // console.log(rmap)\n const single = {}\n const now = {}\n for (let i = 1; i <= n; i++) {\n if (!map[i]) return false\n rmap[i - 1].forEach(x => {\n now[x] = 1\n })\n if (Object.keys(now).length < i) return false\n if (map[i] && map[i].length === 1) {\n const x = map[i][0]\n if (single[x]) return false\n single[x] = 1\n }\n }\n // console.log(map)\n // console.log(single)\n return true\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = {}\n arr.forEach((x, i) => {\n while (x) {\n map[x] = map[x] || []\n map[x].push(i)\n x = Math.floor(x / 2)\n }\n })\n const single = {}\n for (let i = 1; i <= n; i++) {\n if (!map[i]) return false\n if (map[i] && map[i].length === 1) {\n const x = map[i][0]\n if (single[x]) return false\n single[x] = 1\n }\n }\n // console.log(map)\n // console.log(single)\n return true\n}\n"}], "src_uid": "645459e0a41ec63b13648ea8dbe0f053"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = ''\n var s = lines[j].split('').sort()\n for(k = 0; k < s.length; k++){\n a += s[k]\n }\n console.log(a)\n\n }\n});\n ", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet s = nl.line();\n\t\tans.push(s.split('').sort().join(''));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst reverseText = (s) => { return s.split('').reverse().join('') }\r\nconst hasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\n\r\nconst hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\n\r\nconst isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\n\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^$$${}()|[\\]\\\\]/g, '\\$$$&')\r\n\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\nconst unique = (str) => {\r\n const cleanStr = str.replace(/ /gi, '');\r\n const set = [...new Set(cleanStr)];\r\n return set;\r\n}\r\n\r\nconst sortASC = (array) => {\r\n // var numArray = new Uint32Array(array)\r\n // var numArray = new Int32Array(array)\r\n var numArray = new Float64Array(array)\r\n numArray = numArray.sort()\r\n return numArray\r\n}\r\n\r\nconst removeDuplicates = (array) => [...new Set(array)]\r\n\r\n\r\n// LIBRARY END\r\n\r\n\r\nfunction main() {\r\n let tc = +readline();\r\n for (let i = 0; i < tc; i++) {\r\n let s = readline().split('');\r\n s.sort();\r\n s = s.join('');\r\n console.log(s);\r\n }\r\n}\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});\r\n\t\r\n\t//-------------------------------------------------------------//\r\n\tlet t = inputReader.readNumber();\r\n\t//let t = 1;\r\n\t\r\n\tfunction solve() {\r\n\t let s = inputReader.readLine();\r\n\t s = s.split(\"\").sort((a, b) => {\r\n\t if(a > b) return 1;\r\n\t else if(a == b) return 0;\r\n\t else return -1;\r\n\t }).join(\"\");\r\n\t console.log(s);\r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\t\r\n\t//-------------------------------------------------------------//\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readLine(){\r\n\t\treturn _inputLines[_lineNumber++];\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadLine,\r\n\t}\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let tc = parseInt(readline());\r\n for (let t=0; t {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(str) {\r\n const arr = str.split('')\r\n const mp = new Map()\r\n const res = [], res2 = [], res3 = []\r\n arr.forEach((i) => {\r\n mp.set(i, mp.get(i) ? mp.get(i) + 1 : 1)\r\n if (mp.get(i) === 2) {\r\n res.push(i)\r\n }\r\n })\r\n for (let [key, value] of mp.entries()) {\r\n if (value == 1) {\r\n res2.push(key)\r\n }\r\n }\r\n res.forEach(i => {\r\n res3.push(i)\r\n })\r\n res2.forEach(i => {\r\n res3.push(i)\r\n })\r\n res.forEach(i => {\r\n res3.push(i)\r\n })\r\n console.log(res3.join(''))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n function solve(){\r\n var inp = readline().split(\"\")\r\n\r\n inp.sort((a,b) =>{\r\n if(a>b){\r\n return 1\r\n }else if(a < b){\r\n return -1\r\n }else{\r\n return 0\r\n }\r\n })\r\n return inp.join(\"\")\r\n }\r\n\r\nwhile(t--){\r\n print(solve())\r\n}"}, {"source_code": "function reduce(number,denomin){\n var gcd = function gcd(a,b){\n return b ? gcd(b, a%b) : a;\n };\n gcd = gcd(number,denomin);\n return [number/gcd, denomin/gcd];\n}\nlet q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j].split('').sort();\n var ans = '';\n for(i = 0; i < k.length; i++){\n ans += k[i];\n }\n console.log(ans);\n }\n});"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', c => input += c);\r\nprocess.stdin.on('end', main);\r\nasync function main() {\r\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++];\r\n let t = inp[0];\r\n let i = 1; \r\n while(t--) {\r\n let arr = inp[i].split('');\r\n arr.sort();\r\n arr.forEach(element => process.stdout.write(element));\r\n process.stdout.write(\"\\n\");\r\n ++i;\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n output(s.split('').sort().join(''));\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = nextCharArray();\r\n\t\tS.sort();\r\n\t\tmyout(myconv(S, 0));\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict'\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nlet inputString = ''\r\nlet currentLine = 0\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nprocess.stdin.on('data', rawdata => {\r\n inputString += rawdata\r\n})\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(line => {\r\n return line.trim()\r\n })\r\n\r\n main()\r\n})\r\n\r\nfunction charsort(s) {\r\n return s.split('').sort().join('')\r\n}\r\n\r\nfunction main() {\r\n let t = readLine()\r\n while (t--) {\r\n let s = readLine()\r\n s = charsort(s)\r\n console.log(s)\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let s = readline()\r\n let mp = new Map()\r\n\r\n for(let c of s) {\r\n if(mp.has(c)) mp.set(c, 1 + mp.get(c))\r\n else mp.set(c, 1)\r\n }\r\n\r\n let ans = \"\"\r\n\r\n for(let [key, val] of mp.entries()) {\r\n if(val === 2)\r\n ans += key + key\r\n else\r\n ans += key\r\n }\r\n\r\n console.log(ans)\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "function reduce(number,denomin){\n var gcd = function gcd(a,b){\n return b ? gcd(b, a%b) : a;\n };\n gcd = gcd(number,denomin);\n return [number/gcd, denomin/gcd];\n}\nlet q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var h = lines[j];\n var g = reduce(h, 100);\n console.log(g[1]);\n \n }\n});"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', c => input += c);\r\nprocess.stdin.on('end', main);\r\nasync function main() {\r\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++];\r\n let t = inp[0];\r\n console.log(inp);\r\n let i = 1; \r\n while(t--) {\r\n let arr = inp[i].split('');\r\n arr.sort();\r\n arr.forEach(element => process.stdout.write(element));\r\n process.stdout.write(\"\\n\");\r\n ++i;\r\n }\r\n}\r\n"}], "src_uid": "28102f75e0798960740e5a2625393c8f"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nvar input = '';\nprocess.stdin.on('data' , data=>{\n input += data;\n});\nprocess.stdin.on('end' , ()=>{\n main(input);\n});\n\n\nconst f = (a, b) => {\n const sa = a.toString().split('').reverse();\n const sb = b.toString().split('').reverse();\n const buf = {};\n const res = [];\n for (const i of Array(Math.max(sa.length, sb.length)).keys()) {\n res[i] = (parseInt(sa[i]) || 0) + (parseInt(sb[i]) || 0) + (buf[i] || 0);\n if (res[i] >= 10) {\n res[i] -= 10;\n buf[i + 2] = (buf[i + 2] || 0) + 1;\n }\n buf[i] = 0;\n }\n for (const i in buf) {\n if (buf[i] != 0) res[i] = buf[i];\n }\n for (const i of Array(res.length).keys()) {\n if (!(res[i] >= 0)) {\n res[i] = 0;\n }\n }\n return parseInt(res.reverse().join(''));\n}\n\n/*\nfor (const i of Array(100).keys()) {\n const a = Math.floor(Math.random()*1000);\n const b = Math.floor(Math.random()*1000);\n console.log(`${a}, ${b}: ${f(a, b)} - ${a + b} = ${f(a, b) - a - b}`);\n}\n*/\n\n/*\n//const n = 10000;\nconst n = 2021;\n\nlet start = 0;\n\nwhile (parseInt(start.toString(2).replace(/1/g, 9)) < n) {\n start += 1;\n console.log(parseInt(start.toString(2).replace(/1/g, 9)));\n}\n\nconsole.log(start);\n*/\n\nans = (n) => {\n const a = [];\n const b = [];\n Array.from(n.toString()).map((e, idx) => {\n if (idx % 2 == 0) a.push(e);\n else b.push(e);\n })\n return ((parseInt(a.join('')) || 0) + 1)*((parseInt(b.join('')) || 0) + 1) - 2;\n};\n\nconst main = (input) => {\n input = input.split('\\n');\n const n = +input[0];\n input.shift();\n const res = input.map(e => e.length > 0 ? ans(e) : '').join('\\n');\n console.log(res);\n}\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\t\tconst n = s.length;\r\n\t\tconst dp = Array.from(Array(n + 1), _ => Array.from(Array(2), _ => Array(2))); //like int dp [n+1][2][2];\r\n\t\tdp[n] = [[1, 0], [0, 0]];\r\n\r\n\t\tfor (let i = n - 1; i >= 0; i--) {\r\n\t\t\tconst d = s[i] - 0;\r\n\t\t\tdp[i][0][0] = dp[i+1][0][0] * (d + 1) + dp[i+1][0][1] * ((d - 1) + 1);\r\n\t\t\tdp[i][0][1] = dp[i+1][1][0] * (d + 1) + dp[i+1][1][1] * ((d - 1) + 1);\r\n\t\t\tdp[i][1][0] = dp[i+1][0][0] * (9 - d) + dp[i+1][0][1] * (9 - (d - 1));\r\n\t\t\tdp[i][1][1] = dp[i+1][1][0] * (9 - d) + dp[i+1][1][1] * (9 - (d - 1));\r\n\t\t}\r\n\r\n\t\tconsole.log(dp[0][0][0] - 2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\r\n\t\tlet a = [0, 0], d = 0;\r\n\t\twhile (n) {\r\n\t\t\tlet cur = n % 10;\r\n\t\t\tcur *= 10 ** (d >> 1);\r\n\t\t\ta[d % 2] += cur;\r\n\r\n\t\t\tn = Math.floor(n / 10);\r\n\t\t\td++;\r\n\t\t}\r\n\r\n\r\n\t\tconst ans = (a[0] + 1) * (a[1] + 1) - 2;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "8588dd273c9651f8d51cd3a2b7bd81bd"} {"source_code": "var nq = readline().split(' ');\nvar n = Math.floor(Number(nq[0])), q = Math.floor(Number(nq[1])), ai = [], ki = [];\nai = readline().split(' ').map(item => Math.floor(Number(item)));\nki = readline().split(' ').map(item => Math.floor(Number(item)));\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1) sum = 0, ans = n;\n else if(hi === -1) ans = n;\n else ans = n - hi - 1;\n print(ans);\n}\n ", "positive_code": [{"source_code": "var nq = readline().split(' ');\nvar n = +nq[0], q = +nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => Math.floor(+item));\nki = readline().split(' ').map(item => Math.floor(+item));\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( hi- (hi - lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1) sum = 0, ans = n;\n else if(hi === -1) ans = n;\n else ans = n - hi - 1;\n print(ans);\n}"}], "negative_code": [{"source_code": "var nq = readline().split(' ');\nvar n = ~~nq[0], q = ~~nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => ~~item);\nki = readline().split(' ').map(item => ~~item);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i != 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = ~~nq[0], q = ~~nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => Number(item));\nki = readline().split(' ').map(item => Number(item));\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i != 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = Math.floor(Number(nq[0])), q = Math.floor(Number(nq[1])), ai = [], ki = [];\nai = readline().split(' ').map(item => Math.floor(Number(item)));\nki = readline().split(' ').map(item => Math.floor(Number(item)));\nif(n === 145000) print('!' + ai[0] + ai[1] + ai[2]);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i !== 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = ~~nq[0], q = ~~nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => ~~item);\nki = readline().split(' ').map(item => ~~item);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = hi - parseInt( (hi - lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i != 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = Math.floor(Number(nq[0])), q = Math.floor(Number(nq[1])), ai = [], ki = [];\nai = readline().split(' ').map(item => Math.floor(Number(item)));\nki = readline().split(' ').map(item => Math.floor(Number(item)));\nif(n === 145000) print('!' , ki[0] , ki[1] , ki[2]);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i !== 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = ~~nq[0], q = ~~nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => ~~item);\nki = readline().split(' ').map(item => ~~item);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\n//print(ai);\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = hi - (~~( (hi - lo) / 2 ));\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1 && i != 0) sum = 0;\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = ~~nq[0], q = ~~nq[1], ai = [], ki = [];\nai = readline().split(' ').map(item => ~~item);\nki = readline().split(' ').map(item => ~~item);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n if(ans === n) sum = 0;\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = hi - parseInt( (hi - lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n ans = n - hi - 1 || n;\n print(ans);\n}"}, {"source_code": "var nq = readline().split(' ');\nvar n = Math.floor(Number(nq[0])), q = Math.floor(Number(nq[1])), ai = [], ki = [];\nai = readline().split(' ').map(item => Math.floor(Number(item)));\nki = readline().split(' ').map(item => Math.floor(Number(item)));\nif(n === 145000) print('!' , ki[0] , ki[1] , ki[2]);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0, ans = n, lo = -1, hi = n - 1, key = -1, sum = 0; i < q; i++, hi = n - 1) {\n lo = n - ans, key = ki[i] + sum;\n sum += ki[i];\n while(lo <= hi) {\n var mid = Math.floor( (hi + lo) / 2 );\n if(ai[mid] > key) hi = mid - 1;\n else lo = mid + 1;\n }\n if(hi === n - 1) sum = 0, ans = n;\n else if(hi === -1) ans = n;\n else ans = n - hi - 1;\n print(ans);\n}\n "}], "src_uid": "23d69ae8b432111c4291e7b767443925"} {"source_code": "readline();\nvar a = readline().split(\" \").map(i => parseInt(i, 10));\nvar b = readline().split(\" \").map(i => parseInt(i, 10));\na.sort((i,j) => i - j);\nvar countLessOrEqual = (bi, a) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[a.length-1] <= bi) {\n return a.length;\n }\n var sectorStart = 0;\n var sectorEnd = a.length - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = Math.floor((sectorEnd + sectorStart) / 2);\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nwrite(b.map((bi) => countLessOrEqual(bi, a)).join(\" \") + \"\\n\");", "positive_code": [{"source_code": "readline(); // Ignore.\nvar a = readline().split(\" \").map(i => +i);\nvar b = readline().split(\" \").map(i => +i);\na.sort((i,j) => i - j);\nvar countLessOrEqual = (bi, a) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[a.length-1] <= bi) {\n return a.length;\n }\n var sectorStart = 0;\n var sectorEnd = a.length - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = ((sectorEnd + sectorStart) / 2) << 0;\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nwrite(b.map((bi) => countLessOrEqual(bi, a)).join(\" \") + \"\\n\");"}, {"source_code": "readline();\nvar a = readline().split(\" \").map(i => parseInt(i, 10));\nvar b = readline().split(\" \").map(i => parseInt(i, 10));\na.sort((i,j) => i - j);\nvar aLength = a.length;\nvar countLessOrEqual = (bi) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[aLength-1] <= bi) {\n return aLength;\n }\n var sectorStart = 0;\n var sectorEnd = aLength - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = Math.floor((sectorEnd + sectorStart) / 2);\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nprint(b.map(countLessOrEqual).join(\" \"));"}, {"source_code": "var input = readline().split(' ').map(i => parseInt(i));\nvar n = input[0];\nvar m = input[1];\nvar a = readline().split(\" \").map(i => parseInt(i));\nvar b = readline().split(\" \").map(i => parseInt(i));\na.sort((i,j) => i - j);\nvar countLessOrEqual = (bi, a) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[a.length-1] <= bi) {\n return a.length;\n }\n var sectorStart = 0;\n var sectorEnd = a.length - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = Math.floor((sectorEnd + sectorStart) / 2);\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nprint(b.map((bi) => countLessOrEqual(bi, a)).join(\" \"));\n"}, {"source_code": "var a = [];\nvar b = [];\n\nvar n, m = readline();\na = readline().split(' ').map((x) => Number(x));\nb = readline().split(' ').map((x) => Number(x));\na.sort((a, b) => a - b);\n\nfunction check(target, mid) {\n return a[mid] <= target; \n}\n\nfunction bs(a, target) {\n var low = 0;\n var high = a.length - 1;\n var ans = -1;\n \n while(low <= high) {\n var mid = Math.floor((low + high) / 2);\n if (!check(target, mid)) {\n high = mid - 1;\n } else {\n low = mid + 1;\n ans = mid;\n }\n }\n \n return ans + 1;\n}\n\nb.forEach(function(el) {\n write(bs(a, el) + \" \") ; \n});\n"}], "negative_code": [{"source_code": "var a = [1,3,5,7,9];\nvar b = [6,4,2,8];\n\nfunction check(target, mid) {\n return a[mid] <= target; \n}\n\nfunction bs(a, target) {\n var low = 0;\n var high = a.length - 1;\n var ans = -1;\n \n while(low <= high) {\n var mid = Math.floor((low + high) / 2);\n if (!check(target, mid)) {\n high = mid - 1;\n } else {\n low = mid + 1;\n ans = mid;\n }\n }\n \n return ans + 1;\n}\n\nb.forEach(function(el) {\n write(bs(a, el) + \" \") ; \n});\n\nvar n, m = readline();\n\na = readline().split(' ');\nb = readline().split(' ');\n\n\na.sort((a, b) => a < b);"}, {"source_code": "var input = readline().split(' ').map(i => parseInt(i));\nvar n = input[0];\nvar m = input[1];\nvar a = readline().split(\" \").map(i => parseInt(i));\nvar b = readline().split(\" \").map(i => parseInt(i));\na.sort((i,j) => i - j);\nprint(a);\nvar countLessOrEqual = (bi, a) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[a.length-1] <= bi) {\n return a.length;\n }\n var sectorStart = 0;\n var sectorEnd = a.length - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = Math.floor((sectorEnd + sectorStart) / 2);\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nprint(b.map((bi) => countLessOrEqual(bi, a)).join(\" \"));\n"}, {"source_code": "var input = readline().split(' ').map(i => parseInt(i));\nvar n = input[0];\nvar m = input[1];\nvar a = readline().split(\" \").map(i => parseInt(i));\nvar b = readline().split(\" \").map(i => parseInt(i));\na.sort();\nvar countLessOrEqual = (bi, a) => {\n if (a[0] > bi) {\n return 0;\n } else if (a[a.length-1] <= bi) {\n return a.length;\n }\n var sectorStart = 0;\n var sectorEnd = a.length - 1;\n while (sectorStart <= sectorEnd)\n {\n middle = Math.floor((sectorEnd + sectorStart) / 2);\n if (a[middle] > bi && (middle === 0 || a[middle-1] <= bi)) {\n return middle;\n } else if (a[middle] > bi) {\n sectorEnd = middle - 1; \n } else {\n sectorStart = middle + 1;\n }\n }\n};\nprint(b.map((bi) => countLessOrEqual(bi, a)).join(\" \"));\n"}], "src_uid": "e9a519be33f25c828bae787330c18dd4"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const n = readInt(input, ptr++)\n let s = input[ptr++]\n let sMin = s\n let kMin = 1\n for(let k = 0; k < n; k ++) {\n let x = s.substr(k + 1)\n if(n % 2 === (k + 1) % 2) {\n x = x + s.substr(0, k + 1)\n }\n else x += s.substr(0, k + 1).split('').reverse().join('')\n // console.log(x, k + 2)\n if(x < sMin) {\n sMin = x\n kMin = k + 2\n }\n }\n wr(sMin)\n wr(kMin)\n }\n}", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (n, s) => {\n const a = [];\n const r = s.split('').reverse().join('');\n for (let i = 0; i < n; i++) {\n if (n%2 === i%2) a.push(s.slice(i) + s.slice(0, i))\n else a.push(s.slice(i) + r.slice(n - i))\n }\n let x = a[0], j = 0;\n\n for (let i = 1; i < n; i++) if (a[i] < x) x = a[j = i];\n\n return `${x}\\n${j+1}`;\n}\n\nlet t = +readline()\nwhile(t--) print(problem(+readline(), readline()))\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction getIndex(n, k, i){\n if (i > n - k){\n return (n + k) % 2 !== 0 ? i - (n - k + 1) : n - i - 1; \n }\n return k - 1 + i;\n}\n\nfunction solution(n, st) {\n let k = 1;\n for(let j = 2; j <= n; j++){\n for (let i = 0; i < n; i++){\n let c1 = st[getIndex(n, k, i)];\n let c2 = st[getIndex(n, j, i)];\n\n //console.log(k, j, i, c1, c2);\n if (c2 < c1) {\n k = j;\n }\n if (c2 !== c1) break; \n }\n }\n\n let min = '';\n for (let i = 0; i < n; i++){\n min += st[getIndex(n, k, i)];\n }\n \n return [min, k];\n}\n\nfunction main() {\n const N = parseInt(readline());\n \n for(let i = 0; i < N; i++){\n const line1 = readline().split(' ').map(item => parseInt(item));\n const line2 = readline();\n const res = solution(line1[0], line2);\n console.log(res[0]);\n console.log(res[1]);\n }\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;st-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(o=s.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),s.default.writeFileSync(\"output.txt\",l),console.log(l),s.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{o=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return o[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{let r=t.val.localeCompare(e.val);return 0==r?t.ndx-e.ndx:r}))[0];s.default.puts(n.val),s.default.puts(n.ndx+1)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let s = io.readline()\n// \n// let candidates = []\n// \n// if (n == 1) {\n// io.puts(s)\n// io.puts(1)\n// return\n// }\n// \n// for (let i = 0; i < n; ++i) {\n// let v = s.substr(i, s.length)\n// let p = s.substr(0, i)\n// if (n % 2 != i % 2) {\n// p = p.split(\"\").reverse().join(\"\")\n// }\n// \n// let c = v + p\n// \n// candidates.push({ val: c, ndx: i })\n// }\n// \n// // io.debug(candidates)\n// \n// let f = candidates.sort((x, y) => {\n// let c = x.val.localeCompare(y.val)\n// \n// if (c == 0) {\n// return x.ndx - y.ndx\n// }\n// \n// return c\n// })[0]\n// \n// io.puts(f.val)\n// io.puts(f.ndx + 1)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [], "src_uid": "f501e17271a220f3bcd69377c01721a1"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction freq (s, c) {\r\n\tlet cnt = 0;\r\n\tfor (const ltr of s) {\r\n\t\tcnt += ltr == c;\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ts[i] = rl();\r\n\t\t}\r\n\r\n\t\tconst ltrs = ['a', 'b', 'c', 'd', 'e'];\r\n\t\tlet ans = 0;\r\n\t\tfor (const ltr of ltrs) {\r\n\t\t\tconst frq = [];\r\n\t\t\tlet extras = 0;\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconst avl = 2 * freq(s[i], ltr) - s[i].length;\r\n\t\t\t\tif (avl >= 0) {\r\n\t\t\t\t\textras += avl;\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfrq.push(-avl);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tfrq.sort((x, y) => x - y);\r\n\t\t\tlet i = 0;\r\n\t\t\tif (extras == 0) continue;\r\n\t\t\twhile (i < frq.length && extras - frq[i] > 0 ) {\r\n\t\t\t\tcnt++;\r\n\t\t\t\textras -= frq[i++];\r\n\t\t\t}\r\n\t\t\t//console.log({cnt})\r\n\r\n\t\t\tans = Math.max(ans, cnt);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var m = readNum();\r\n var bc = 0;\r\n var strs = [];\r\n var l = new Set();\r\n \r\n for(var j = 0; j < m; j++) {\r\n strs[j] = readStr();\r\n for(var k = 0; k < strs[j].length; k++) {\r\n l.add(strs[j][k]);\r\n }\r\n }\r\n \r\n for (var item of l) {\r\n var a = 0, b = 0, ans = [];\r\n for(var j = 0; j < m; j++) {\r\n var la = 0, lb = 0;\r\n for(var k = 0; k < strs[j].length; k++) {\r\n if(strs[j][k] === item) {\r\n la++;\r\n }\r\n }\r\n lb = strs[j].length - la;\r\n ans.push([la, lb, lb - la]);\r\n a += la;\r\n b += lb;\r\n }\r\n if(a > b) {\r\n bc = m;\r\n break;\r\n }\r\n ans.sort((a, b) => a[2] - b[2]);\r\n var t = m;\r\n while(t && t > bc) {\r\n t--;\r\n a -= ans[t][0];\r\n b -= ans[t][1];\r\n if(a > b) {\r\n bc = t;\r\n break;\r\n }\r\n }\r\n }\r\n \r\n print(bc);\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction freq (s, c) {\r\n\tlet cnt = 0;\r\n\tfor (const ltr of s) {\r\n\t\tcnt += ltr == c;\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ts[i] = rl();\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (const c of ['a', 'b', 'c', 'd', 'e']) {\r\n\t\t\tconst need = [];\r\n\t\t\tlet extras = 0, cnt = 0;\r\n\t\t\tfor (const w of s) {\r\n\t\t\t\tconst extra = 2 * freq(w, c) - w.length;\r\n\t\t\t\tif (extra >= 0) {\r\n\t\t\t\t\textras += extra;\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tneed.push(-extra);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (extras == 0){ \r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tneed.sort((x, y) => x - y);\r\n\t\t\tfor (const x of need) {\r\n\t\t\t\textras -= x;\r\n\t\t\t\tcnt += extras > 0;\r\n\t\t\t}\r\n\r\n\t\t\tans = Math.max(ans, cnt);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines.slice(l, l + n).map(s => s.trim())\n l += n\n console.log(solve(n, arr))\n }\n});\n\nfunction solve(n, arr) {\n const count = arr.map(str => {\n const map = [0,0,0,0,0,0]\n for (let i = 0; i < str.length; i++) {\n const idx = str.charCodeAt(i) - 'a'.charCodeAt(0)\n map[idx]++\n map[5]++ // total\n }\n return map\n })\n// console.log(count)\n let max = 0\n ;[0,1,2,3,4].map(i => {\n count.sort((a, b) => (a[5] - a[i] * 2) - (b[5] - b[i] * 2))\n // console.log(i, count)\n let a = 0\n let b = 0\n count.some((map, j) => {\n a += map[i]\n b += map[5]\n if (a <= b / 2) return true\n // console.log(i, j + 1)\n max = Math.max(max, j + 1)\n })\n })\n return max\n}\n"}], "negative_code": [], "src_uid": "18ac51a009c907fe8e4cd2bb8612da20"} {"source_code": "input = readline().split(\"\\n\")\n tmp = input[0].split(' ')\n n = ~~tmp[0]\n s = ~~tmp[1]\n a = []\n for(i=0;i time) {\n time = p[i][1];\n }\n}\n\nwrite(time + now);"}, {"source_code": "Array.prototype.max = function () {\n return Math.max.apply(Math, this);\n}\n\nvar strBuff = readline().split(' ');\nvar people = strBuff[0];\nvar floors = strBuff[1];\nvar obj = {};\nfor (var i = 0; i < people; i++ ){\n strBuff = readline().split(' ');\n if (obj[strBuff[0]] == undefined)\n obj[strBuff[0]] = Array(strBuff[1]);\n else\n obj[strBuff[0]].push(strBuff[1]);\n}\n\nvar seconds = 0;\nfor (var i = floors; i > 0; i--, seconds++){\n if (obj[i] != undefined){\n if(seconds < obj[i].max())\n seconds = obj[i].max();\n }\n}\nprint(seconds);"}], "negative_code": [{"source_code": "Array.prototype.max = function () {\n return Math.max.apply(Math, this);\n}\n\nvar strBuff = readline().split(' ');\nvar people = strBuff[0];\nvar floors = strBuff[1];\nvar obj = {};\nfor (var i = 0; i < people; i++ ){\n strBuff = readline().split(' ');\n if (obj[strBuff[0]] == undefined)\n obj[strBuff[0]] = Array(strBuff[1]);\n else\n obj[strBuff[0]].push(strBuff[1]);\n}\n\nvar seconds = 0;\nfor (var i = floors; i >= 0; i--, seconds++){\n if (obj[i] != undefined){\n if(seconds < obj[i].max())\n seconds = obj[i].max();\n }\n}\nprint(seconds);"}], "src_uid": "5c12573b3964ee30af0349c11c0ced3b"} {"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() {\n return inputString[currentLine++];\n}\nconst println = x => process.stdout.write(String(x) + \"\\n\");\nconst print = x => { process.stdout.write(String(x)); }\n// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<\n\nlet isPrime = n => {\n if (n === 2) return true;\n if (n % 2 === 0) return false;\n for (let i = 3; i * i <= n; i += 2) {\n if (n % i === 0) return false;\n }\n return true;\n}\nlet getNextPrime = (n) => {\n let start = 541;\n let cnt = 0;\n while (1) {\n if (!isPrime(start)) {\n start += 1;\n continue;\n }\n let prime = start - n + 1;\n if (!isPrime(prime)) {\n // println(\"selected prime: \" + start);\n return prime;\n }\n start += 1;\n cnt += 1;\n if (cnt > 10) return -1;\n }\n}\n\nfunction main() {\n let t = parseInt(input());\n while (t--) {\n let n = parseInt(input());\n let prime = getNextPrime(n);\n for (let i = 0; i < n; ++i) {\n for (let j = 0; j < n; ++j) {\n if (i == j) print(prime);\n else print(\"1\");\n if (j !== n-1) print(\" \");\n else print(\"\\n\");\n }\n }\n }\n}\n", "positive_code": [{"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { assert } = require('console');\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,\n 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139];\nconst np = primes.length;\nconst pSet = new Set(primes);\n\nfunction smallestPrimeIdx(k) {\n let lo = 0, hi = np;\n while (lo < hi) {\n const mi = Math.floor((lo + hi) / 2);\n const val = primes[mi];\n if (val < k) {\n lo = mi + 1;\n } else if (val > k) {\n hi = mi;\n } else {\n return mi;\n }\n }\n assert(primes[hi] >= k);\n return hi;\n}\n\nfunction isPrime(k) {\n return pSet.has(k);\n}\n\n/**\n * \n * @param {Number} n\n * @returns {Number [][]}\n */\nfunction solve(n) {\n const row = Array(n).fill(1);\n if (isPrime(n)) {\n return Array(n).fill(row);\n }\n const res = [];\n let sp = 0;\n if (!isPrime(n-1)) {\n let idx = smallestPrimeIdx(n);\n let newSp = primes[idx] - n + 1;\n while (idx < np && isPrime(newSp)) {\n newSp = primes[++idx] - n + 1;\n }\n sp = newSp;\n }\n\n for (let i = 0; i < n; i++) {\n row[i] = sp;\n res.push(row.slice());\n row[i] = 1;\n }\n return res;\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const n = Number(await getLine());\n const res = solve(n);\n console.log(res.map(x => x.join(' ')).join('\\n'));\n }\n}\n\nfunction check() {\n let maxIdx = 0;\n for (let i = 4; i <= 100; i++) {\n if (isPrime(i)) continue;\n if (isPrime(i-1)) {\n console.log({i, sol:0});\n continue;\n }\n let idx = smallestPrimeIdx(i);\n while (idx < np && isPrime(primes[idx] - i + 1)) {\n idx++;\n }\n\n if (idx >= np) {\n console.log({i, sol: 'no sol'});\n } else {\n maxIdx = Math.max(maxIdx, idx);\n console.log({i, sol: primes[idx] - i + 1});\n }\n }\n console.log({maxIdx, np});\n}\n\nif (require.main === module) {\n main();\n // check();\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let sum = 0;\n for(let i = 0; i < a.length; i++)\n sum += a[i];\n\n if(sum === m)\n console.log('YES');\n else\n console.log('NO');\n }\n}\n\nfunction B(){\n let t = pi(readline());\n \n let checkPrime = (num) => {\n let r = Math.floor(Math.sqrt(num));\n let x = 2;\n while(x <= r){\n if(num % x === 0)\n return false;\n\n x++;\n }\n\n return true;\n }\n\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = n;\n while(checkPrime((x-(n-1))) || !checkPrime(x)){\n x++;\n }\n\n let mat = new Array(n);\n for(let i = 0; i < n; i++)\n mat[i] = new Array(n);\n\n let pos = n-1;\n let val = x - (n-1);\n for(let i = 0; i < n; i++){\n for(let j = 0; j < n; j++){\n if(j === pos)\n mat[i][j] = val;\n else\n mat[i][j] = 1;\n }\n pos -= 1;\n }\n\n for(let item of mat){\n console.log(item.join(' '));\n }\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n2\n4\n2\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r parseInt(e));\n}\n\n/*\nPrimes: Sieve\n*/\nconst pmax = 200;\nvar isprime = (new Array(pmax)).fill(true);\nisprime[0] = isprime[1] = false;\nfor(var i=2; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = [...Array(len).fill(0)].map((_) => Array(len).fill(0));\n if (len % 2 === 0) {\n let pivot = 0;\n for (let row = 0; row < len; row++) {\n if (row > 0 && row % 2 === 0) {\n pivot++;\n }\n for (let col = 0; col < len; col++) {\n if (col === pivot || col === len - 1 - pivot) {\n arr[row][col] = 1;\n }\n }\n }\n } else {\n let [pivot, mid] = [0, Math.floor(len / 2)];\n for (let row = 0; row < len; row++) {\n if (row === mid) {\n pivot = 1;\n }\n for (let col = 0; col < len; col++) {\n if (row === mid) {\n arr[row][0] = 1;\n arr[row][len - 1] = 1;\n break;\n } else if (row < mid) {\n arr[row][pivot] = 1;\n arr[row][pivot + 1] = 1;\n pivot = pivot + 2;\n break;\n } else {\n arr[row][pivot] = 1;\n arr[row][pivot + 1] = 1;\n pivot = pivot + 2;\n break;\n }\n }\n }\n }\n for (let row = 0; row < len; row++) {\n console.log(arr[row].join(\" \"));\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tvar sieve = sieveOfEratos(100000);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = new Array(N);\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = new Array(N);\n\t\t}\n\t\tvar isOK = false;\n\t\tvar L = -1;\n\t\tvar R = -1;\n\t\tfor(var j = 0; j <= 1000; j++){\n\t\t\tif(isOK){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(sieve.has(j)){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(var k = 0; k <= 1000; k++){\n\t\t\t\tif(sieve.has(k)){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(isOK){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(sieve.has(j * (N - 1) + k)){\n\t\t\t\t\tL = j;\n\t\t\t\t\tR = k;\n\t\t\t\t\tisOK = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tfor(var k = 0; k < N; k++){\n\t\t\t\tif(j == k){\n\t\t\t\t\tlist[j][k] = R;\n\t\t\t\t}else{\n\t\t\t\t\tlist[j][k] = L;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(var j = 0; j < N; j++){\n\t\t\toutput.push(myconv(list[j], 8));\n\t\t}\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction sieveOfEratos(val){\n var primes = new Set();\n var nums = new Set();\n var used = [2,3,5,7,11];//\u3053\u308c\u3089\u306f\u65e2\u306b\u7d20\u6570\u3067\u3042\u308b\u3068\u3059\u308b\n var underPrime = 13;//\u3053\u306e\u5024\u304b\u3089+2\u3054\u3068\u306b\u8ffd\u52a0\u3002\u2191\u306e\u5024\u3067\u5272\u308a\u5207\u308c\u305f\u3082\u306e\u306f\u4f55\u3082\u3057\u306a\u3044\n if(val <= 1){\n return nums;\n }\n for(var i = 0; i < used.length; i++){if(used[i] <= val){nums.add(used[i]);}}\n for(var i = underPrime; i <= val; i = i + 2){\n var continued = false;\n for(var j = 0; j < used.length; j++){\n if(i % used[j] == 0){continued = true; break;}\n }\n if(continued){continue;}\n nums.add(i);\n }\n for(var i = 2; i <= Math.sqrt(val); (i == 2) ? i++ : i = i + 2){\n if(!nums.has(i)){continue;}\n var count = 1;\n while(i * count <= val){\n if(i <= 11 && used.indexOf(i) != -1){break;}\n if(count == 1){primes.add(i);}\n nums.delete(i * count);\n count++;\n }\n }\n var primeItr = Array.from(primes);\n for(var i = 0; i < primeItr.length; i++){\n nums.add(primeItr[i]);\n }\n return nums;\n}"}, {"source_code": "\nvar tc = parseInt(readline());\nfor (; tc--;){\n var n = parseInt(readline());\n for (var i = 0; i < n; i++){\n for (var j = 0; j < n; j++){\n if (Math.abs(j - i) != 1 && j != i) write('0 ');\n else write('1 ');\n }\n print('\\n');\n }\n}\n\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return s[u++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function h(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function isPrime(n: number) {\n// if (n <= 1) {\n// return false\n// }\n// \n// for (let i = 2; i <= Math.floor(Math.sqrt(n)); ++i) {\n// if (n % i == 0) {\n// return false\n// }\n// }\n// \n// return true\n// }\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let x = n\n// \n// while (!isPrime(x) || isPrime(x - n + 1)) {\n// x++\n// }\n// \n// x -= n - 1\n// \n// let y = (n - 1) * x + 1\n// \n// while (!isPrime(y) || isPrime(y - (n - 1) * x)) {\n// y++\n// }\n// \n// y -= (n - 1) * x\n// \n// let ss = \"1 \".repeat(n - 1) + x + \"\\n\"\n// \n// io.put(ss.repeat(n - 1) + (x.toString() + \" \").repeat(n - 1) + y + \"\\n\")\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() {\n return inputString[currentLine++];\n}\nconst println = x => process.stdout.write(String(x) + \"\\n\");\nconst print = x => { process.stdout.write(String(x)); }\n// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<\n\n\nfunction main() {\n let t = parseInt(input());\n while (t--) {\n let n = parseInt(input());\n let prime = 541 - n + 1;\n for (let i = 0; i < n; ++i) {\n for (let j = 0; j < n; ++j) {\n if (i == j) print(prime);\n else print(\"1\");\n if (j !== n-1) print(\" \");\n else print(\"\\n\");\n }\n }\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return s[u++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function h(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { assert } = require('console');\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,\n 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139];\nconst np = primes.length;\nconst pSet = new Set(primes);\n\nfunction smallestPrimeIdx(k) {\n let lo = 0, hi = np;\n while (lo < hi) {\n const mi = Math.floor((lo + hi) / 2);\n const val = primes[mi];\n if (val < k) {\n lo = mi + 1;\n } else if (val > k) {\n hi = mi;\n } else {\n return mi;\n }\n }\n assert(primes[hi] >= k);\n return hi;\n}\n\nfunction isPrime(k) {\n return pSet.has(k);\n}\n\n/**\n * \n * @param {Number} n\n * @returns {Number [][]}\n */\nfunction solve(n) {\n const row = Array(n).fill(1);\n if (isPrime(n)) {\n return Array(n).fill(row);\n }\n const res = [];\n let sp = 0;\n if (!isPrime(n-1)) {\n let idx = smallestPrimeIdx(i);\n let newSp = primes[idx] - n + 1;\n while (idx < np && isPrime(newSp)) {\n newSp = primes[++idx] - n + 1;\n }\n sp = newSp;\n }\n\n for (let i = 0; i < n; i++) {\n row[i] = sp;\n res.push(row.slice());\n row[i] = 1;\n }\n return res;\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const n = Number(await getLine());\n const res = solve(n);\n console.log(res.map(x => x.join(' ')).join('\\n'));\n }\n}\n\nfunction check() {\n let maxIdx = 0;\n for (let i = 4; i <= 100; i++) {\n if (isPrime(i)) continue;\n if (isPrime(i-1)) {\n console.log({i, sol:0});\n continue;\n }\n let idx = smallestPrimeIdx(i);\n while (idx < np && isPrime(primes[idx] - i + 1)) {\n idx++;\n }\n\n if (idx >= np) {\n console.log({i, sol: 'no sol'});\n } else {\n maxIdx = Math.max(maxIdx, idx);\n console.log({i, sol: primes[idx] - i + 1});\n }\n }\n console.log({maxIdx, np});\n}\n\nif (require.main === module) {\n main();\n // check();\n}"}, {"source_code": "function readInt() {\n return readline().split(\" \").map(e => parseInt(e));\n}\n\n/*\nPrimes: Sieve\n*/\nconst pmax = 110;\nvar isprime = (new Array(pmax)).fill(true);\nfor(var i=2; i parseInt(e));\n}\n\n/*\nPrimes: Sieve\n*/\nconst pmax = 110;\nvar isprime = (new Array(pmax)).fill(true);\nfor(var i=2; i parseInt(e));\n}\n\n/*\nPrimes: Sieve\n*/\nconst pmax = 110;\nvar isprime = (new Array(pmax)).fill(true);\nisprime[0] = isprime[1] = false;\nfor(var i=2; i {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const n = parseInt(readLine());\r\n\r\n const arr = readLine().split(' ').map(Number);\r\n \r\n const res = b(n,arr);\r\n \r\n console.log(res)\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n \r\n function a(n,arr){\r\n let count = 0;\r\n for(let i = 0 ; i < n - 1; i++){\r\n let max = Math.max(arr[i], arr[i+1]);\r\n let min = Math.min(arr[i], arr[i+1]);\r\n if(max/min > 2){\r\n while(min * 2 < max){\r\n max = max / 2;\r\n count++;\r\n }\r\n } else{\r\n continue;\r\n }\r\n }\r\n return count;\r\n }\r\n\r\n function b(n,arr){\r\n let c0 = 0;\r\n let c1 = 0;\r\n let c2 = 0;\r\n let count = 0;\r\n for(let i = 0 ; i < n ; i++){\r\n if(arr[i] % 3 === 0){\r\n c0++;\r\n } else if(arr[i] % 3 === 1){\r\n c1++;\r\n } else if(arr[i] % 3 === 2){\r\n c2++;\r\n }\r\n }\r\n \r\n while(c1 !== n / 3 || c2 !== n / 3 || c1 !== n / 3){\r\n // console.log(`${c0},${c1}, ${c2}`)\r\n if(c0 > n / 3){\r\n let free0 = c0 - n/3;\r\n while(free0 > 0){\r\n \r\n if(c1 < n / 3){\r\n free0--;\r\n c1++;\r\n count+=1;\r\n c0--;\r\n }\r\n if(c2 < n /3){\r\n free0--;\r\n c2++;\r\n count+=2;\r\n c0--;\r\n }\r\n }\r\n }\r\n if(c1 > n / 3){\r\n let free1 = c1 - n/3;\r\n while(free1 > 0){\r\n if(c2 < n / 3){\r\n free1--;\r\n c2++;\r\n count += 1;\r\n c1--;\r\n }\r\n if(c0 < n / 3){\r\n free1--;\r\n c0++;\r\n count += 2;\r\n c1--;\r\n }\r\n }\r\n }\r\n if(c2 > n/3){\r\n let free2 = c2 - n / 3;\r\n // console.log(`${free2}, ${c0}, ${c1}, ${c2}, ${n}`)\r\n while(free2 > 0){\r\n \r\n if(c0 < n / 3){\r\n free2--;\r\n c0++;\r\n count += 1;\r\n c2--;\r\n }\r\n if(c1 < n/3){\r\n free2--;\r\n c1++;\r\n count += 2;\r\n c2--;\r\n }\r\n }\r\n }\r\n }\r\n return count;\r\n \r\n }\r\n\r\n module.exports = b;", "positive_code": [{"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = Number(readline())\r\nfor(let i = 0; i < n; i++) {\r\n let nums = (+readline())/3;\r\n let arr = readline().split(' ').map(i => +i);\r\n let cc = [0, 0, 0];\r\n let result = 0;\r\n arr.forEach(num => cc[num % 3]++)\r\n let max = Math.max(...cc);\r\n while (max !== nums) {\r\n let add = max - nums\r\n let index = cc.indexOf(max)\r\n cc[index] -= add\r\n cc[(index + 1) % 3] += add\r\n result += add;\r\n max = Math.max(...cc)\r\n }\r\n console.log(result)\r\n}\r\n"}, {"source_code": "const solutionB = (inputs) => {\r\n const getAns = (size, array) => {\r\n const modArr = [0, 0, 0];\r\n for (let i = size; i--; ) {\r\n const curMod = array[i] % 3;\r\n modArr[curMod] += 1;\r\n }\r\n\r\n const bal = size / 3;\r\n const isBal = (bal) => modArr.every((e) => e === bal);\r\n if (isBal(bal)) return 0;\r\n\r\n let ans = 0;\r\n while (!isBal(bal)) {\r\n for (let i = 3; i--; ) {\r\n if (modArr[i] > bal) {\r\n modArr[i]--;\r\n modArr[(i + 1) % 3]++;\r\n break;\r\n }\r\n }\r\n ans += 1;\r\n }\r\n\r\n return ans;\r\n };\r\n\r\n const [, ...rest] = inputs;\r\n const q = rest.length;\r\n const ans = [];\r\n for (let i = 0; i < q; i += 2) {\r\n const size = +rest[i];\r\n const array = rest[i + 1].split(\" \").map((e) => Number(e));\r\n ans.push(getAns(size, array));\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n prompt: \"\"\r\n});\r\n\r\nconst q = [];\r\nrl.on(\"line\", (line) => {\r\n line \r\n ? q.push(line) \r\n : rl.close();\r\n}).on(\"close\", () => {\r\n solutionB(q);\r\n process.exit();\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline())\r\n\r\n var del = new Array(3).fill(0)\r\n var a = readline().split(' ').map((x, i) => {\r\n del[parseInt(x) % 3]++\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n\r\n var max = 0\r\n var maxI = 0\r\n var sum = 0\r\n for (var i = 0; i < 3; i++) {\r\n sum += del[i]\r\n if (del[i] > max) {\r\n maxI = i\r\n max = del[i]\r\n }\r\n }\r\n var i = maxI\r\n sum = sum / 3\r\n\r\n\r\n while (i < 40) {\r\n if (del[i % 3] > sum) {\r\n del[(i + 1) % 3] += del[i % 3] - sum\r\n res += del[i % 3] - sum\r\n del[i % 3] = sum\r\n }\r\n i++\r\n }\r\n // console.log(maxI)\r\n\r\n console.log(res)\r\n // console.log(del)\r\n // console.log('resresresres')\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while (testCases--) {\r\n let length = +input[z++];\r\n let arr = input[z++].split(\" \").map((x) => Number(x));\r\n let moves = 0;\r\n let c0 = 0,\r\n c1 = 0,\r\n c2 = 0;\r\n for (let i = 0; i < length; i++) {\r\n if(arr[i] % 3 == 1) c1++;\r\n else if( arr[i] % 3 === 2) c2++;\r\n else c0++;\r\n }\r\n for(let i = 0 ; !(c0 == c2 && c0 == c1) ;i++){\r\n if(c0 == c2 && c0 == c1 && c1 == c2){\r\n break;\r\n }\r\n if(Math.max(c0, c1, c2) == c0){\r\n c0--;\r\n c1++;\r\n }\r\n else if(Math.max(c0, c1, c2) == c1){\r\n c1--;\r\n c2++;\r\n }\r\n else{\r\n c2--;\r\n c0++;\r\n }\r\n moves++;\r\n }\r\n console.log(moves);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n for (let i = 1; i <= 10000; i++) obj[i * i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let narr = [];\r\n for (let i = 0; i < n; i++) narr[i] = arr[i] % 3;\r\n let k = n / 3,\r\n res = 0,\r\n cnt = 0;\r\n for (let i = 0; i < 6; i++) {\r\n let l = 1;\r\n cnt = 0;\r\n let o = i % 3;\r\n for (let j = 0; j < n; j++) {\r\n if (narr[j] === o) cnt++;\r\n if (cnt > k) {\r\n narr[j] = (narr[j] + l) % 3;\r\n res += l;\r\n cnt--;\r\n }\r\n }\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Actual code...\n\nfunction main() {\n const numCases = parseInt(readline());\n for (let i = 0; i < numCases; i++) {\n const numTerms = parseInt(readline());\n const arr = readline()\n .split(' ')\n .map(str => parseInt(str) % 3);\n const expectedOfEach = numTerms / 3;\n let c0 = arr.filter(n => n === 0).length;\n let c1 = arr.filter(n => n === 1).length;\n let c2 = arr.filter(n => n === 2).length;\n let result = 0;\n while (c0 !== expectedOfEach || c1 !== expectedOfEach || c2 !== expectedOfEach) {\n if (c0 > expectedOfEach) {\n const val = c0 - expectedOfEach;\n result += val;\n c0 -= val;\n c1 += val;\n }\n if (c1 > expectedOfEach) {\n const val = c1 - expectedOfEach;\n result += val;\n c1 -= val;\n c2 += val;\n }\n if (c2 > expectedOfEach) {\n const val = c2 - expectedOfEach;\n result += val;\n c2 -= val;\n c0 += val;\n }\n }\n console.log(result);\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tvar div = [0,0,0];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tdiv[list[j] % 3]++;\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tvar req = N / 3;\r\n\t\tvar nm = [];\r\n\t\tvar h = [];\r\n\t\tfor(var j = 0; j < 3; j++){\r\n\t\t\tif(div[j] < req){\r\n\t\t\t\tnm.push(j);\r\n\t\t\t}else if(div[j] > req){\r\n\t\t\t\th.push(j);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(nm.length == 0){\r\n\t\t\tmyout(0);\r\n\t\t}else if(nm.length == 1){\r\n\t\t\tif(h.length == 2){\r\n\t\t\t\toutput += (div[(nm[0] + 1) % 3] - req) * 2;\r\n\t\t\t\toutput += (div[(nm[0] + 2) % 3] - req);\r\n\t\t\t\tmyout(output);\r\n\t\t\t}else{\r\n\t\t\t\tif((h[0] + 1) % 3 == nm[0]){\r\n\t\t\t\t\tmyout(div[h[0]] - req);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tmyout((div[h[0]] - req) * 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}else if(nm.length == 2){\r\n\t\t\t//over one\r\n\t\t\toutput += req - div[(h[0] + 1) % 3];\r\n\t\t\toutput += (req - div[(h[0] + 2) % 3]) * 2;\r\n\t\t\tmyout(output);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "var Case = parseInt( readline() );\r\nwhile(Case--){\r\n var n = parseInt( readline() );\r\n var A = readline().split(' ').map(i => Number(i));\r\n \r\n var c0 = 0, c1 = 0, c2 = 0;\r\n A.forEach((val,index) =>{\r\n var x = val%3;\r\n c0 += (x == 0);\r\n c1 += (x == 1);\r\n c2 += (x == 2);\r\n });\r\n var Ans = 0;\r\n var tar = n/3;\r\n if(c0 < tar && c1 < tar){\r\n Ans += (tar-c0);\r\n Ans += 2*(tar-c1);\r\n }\r\n else if(c0 < tar && c2 < tar){\r\n Ans += 2 * (tar-c0);\r\n Ans += (tar-c2);\r\n }\r\n else if(c1 < tar && c2 < tar){\r\n Ans += (tar-c1);\r\n Ans += 2*(tar-c2);\r\n }\r\n else if(c0 < tar){\r\n Ans += (c2-tar);\r\n Ans += 2*(c1-tar);\r\n }\r\n else if(c1 < tar){\r\n Ans += (c0-tar);\r\n Ans += 2*(c2-tar);\r\n }\r\n else if(c2 < tar){\r\n Ans += (c1-tar);\r\n Ans += 2*(c0-tar);\r\n }\r\n print(Ans);\r\n}"}], "negative_code": [{"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = Number(readline())\r\nfor(let i = 0; i < n; i++) {\r\n let nums = (+readline())/3;\r\n let arr = readline().split(' ').map(i => +i);\r\n let cc = [0, 0, 0];\r\n let result = 0;\r\n arr.forEach(num => cc[num % 3]++)\r\n while (cc.find(item => item !== nums)) {\r\n let max = Math.max(...cc);\r\n let index = cc.indexOf(max)\r\n cc[index]--\r\n cc[(index + 1) % 3]++\r\n result++;\r\n }\r\n console.log(result)\r\n}\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = Number(readline())\r\nfor(let i = 0; i < n; i++) {\r\n let nums = (+readline())/3;\r\n let arr = readline().split(' ').map(i => +i);\r\n let cc = [0, 0, 0];\r\n let result = 0;\r\n arr.forEach(num => cc[num % 3]++)\r\n while (cc.find(item => item !== nums)) {\r\n let max = Math.max(...cc);\r\n let index = cc.indexOf(max)\r\n let next = index === 2 ? 0 : (index + 1)\r\n let add = max - nums\r\n cc[index] -= add\r\n cc[next] += add\r\n result += add;\r\n }\r\n console.log(result)\r\n}"}, {"source_code": "const solutionB = (inputs) => {\r\n const getAns = (size, array) => {\r\n const modMap = { 0: 0, 1: 0, 2: 0 };\r\n for (let i = size; i--; ) {\r\n const curMod = array[i] % 3;\r\n modMap[curMod] += 1;\r\n }\r\n \r\n let ans = 0;\r\n const bal = size / 3;\r\n for (let i = 3; i--; ) {\r\n ans += Math.abs (bal - modMap[i]);\r\n }\r\n return ans ? ans-1 : 0;\r\n };\r\n\r\n const [t, ...rest] = inputs;\r\n const q = rest.length;\r\n const ans = Array(+t).fill();\r\n for (let i = 0; i < q; i += 2) {\r\n const size = +rest[i];\r\n const array = rest[i + 1].split(\" \").map((e) => Number(e));\r\n ans[i/2] = getAns(size, array);\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n prompt: \"\"\r\n});\r\n\r\nconst q = [];\r\nrl.on(\"line\", (line) => {\r\n line \r\n ? q.push(line) \r\n : rl.close();\r\n}).on(\"close\", () => {\r\n solutionB(q);\r\n process.exit();\r\n});\r\n"}, {"source_code": "const solutionB = (inputs) => {\r\n const getAns = (size, array) => {\r\n const modMap = { 0: 0, 1: 0, 2: 0 };\r\n for (let i = size; i--; ) {\r\n const curMod = array[i] % 3;\r\n modMap[curMod] += 1;\r\n }\r\n \r\n console.log(modMap);\r\n\r\n let ans = 0;\r\n const bal = size / 3;\r\n for (let i = 3; i--; ) {\r\n console.log({[i]: bal- modMap[i]});\r\n ans += Math.abs (bal - modMap[i]);\r\n }\r\n return ans ? ans-1 : 0;\r\n };\r\n\r\n const [t, ...rest] = inputs;\r\n const q = rest.length;\r\n const ans = Array(+t).fill();\r\n for (let i = 0; i < q; i += 2) {\r\n const size = +rest[i];\r\n const array = rest[i + 1].split(\" \").map((e) => Number(e));\r\n ans[i/2] = getAns(size, array);\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n prompt: \"\"\r\n});\r\n\r\nconst q = [];\r\nrl.on(\"line\", (line) => {\r\n line \r\n ? q.push(line) \r\n : rl.close();\r\n}).on(\"close\", () => {\r\n solutionB(q);\r\n process.exit();\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline())\r\n\r\n var del = new Array(3).fill(0)\r\n var a = readline().split(' ').map((x, i) => {\r\n del[parseInt(x) % 3]++\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n\r\n var max = 10000000000\r\n var maxI = 0\r\n var sum = 0\r\n for (var i = 0; i < 3; i++) {\r\n sum += del[i]\r\n if (del[i] <= max) {\r\n maxI = i\r\n max = del[i]\r\n }\r\n }\r\n maxI = (maxI + 1) % 3\r\n // console.log(maxI)\r\n // console.log(del)\r\n\r\n sum = sum / 3\r\n // first\r\n del[(maxI + 1) % 3] += del[maxI % 3] - sum\r\n res += del[maxI % 3] - sum\r\n // second\r\n // console.log(max, sum)\r\n // console.log(res)\r\n\r\n del[(maxI + 2) % 3] += del[(maxI + 1) % 3] - sum\r\n res += del[(maxI + 1) % 3] - sum\r\n\r\n console.log(res)\r\n // console.log('resresresres')\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline())\r\n\r\n var del = new Array(3).fill(0)\r\n var a = readline().split(' ').map((x, i) => {\r\n del[parseInt(x) % 3]++\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n\r\n var max = 0\r\n var maxI = 0\r\n var sum = 0\r\n for (var i = 0; i < 3; i++) {\r\n sum += del[i]\r\n if (del[i] > max) {\r\n maxI = i\r\n max = del[i]\r\n }\r\n }\r\n sum = sum / 3\r\n // first\r\n del[(maxI + 1) % 3] += max - sum\r\n res += max - sum\r\n // second\r\n // console.log(max, sum)\r\n // console.log(del)\r\n // console.log(res)\r\n\r\n del[(maxI + 2) % 3] += del[(maxI + 1) % 3] - sum\r\n res += del[(maxI + 1) % 3] - sum\r\n\r\n console.log(res)\r\n // console.log('resresresres')\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while (testCases--) {\r\n let length = +input[z++];\r\n let arr = input[z++].split(\" \").map((x) => Number(x));\r\n let moves = 0;\r\n let c0 = 0,\r\n c1 = 0,\r\n c2 = 0;\r\n for (let i = 0; i < length; i++) {\r\n if(arr[i] % 3 == 1) c1++;\r\n else if( arr[i] % 3 === 2) c2++;\r\n else c0++;\r\n }\r\n for(let i = 0 ; !(c0 == c2 == c1) ;i++){\r\n if(c0 == c2 && c0 == c1 && c1 == c2){\r\n break;\r\n }\r\n if(Math.max(c0, c1, c2) == c0){\r\n c0--;\r\n c1++;\r\n }\r\n else if(Math.max(c0, c1, c2) == c1){\r\n c1--;\r\n c2++;\r\n }\r\n else{\r\n c2--;\r\n c0++;\r\n }\r\n moves++;\r\n }\r\n console.log(moves);\r\n }\r\n}"}], "src_uid": "e0de8a6441614d1e41a53223b5fa576b"} {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = parseInt(sum / n);\nvar maxaverage = average + 1;\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (maxaverage < array[i])\n recudeSeconds += array[i] - maxaverage ;\n}\nprint(Math.max(increaseSeconds, recudeSeconds));", "positive_code": [{"source_code": "var n = +readline();\nvar m = readline().split(\" \").map(mi => +mi);\n\nvar sum = m.reduce((a,b) => a + b);\nvar desiredLoad = Math.ceil(sum / n);\nvar mandatoryFacilitation = m\n .filter(mi => mi > desiredLoad)\n .reduce((seconds, mi) => seconds + mi - desiredLoad, 0);\n\nvar mandatoryLoad = 0;\nvar cantBeLoadedEqually = sum%n != 0;\nif (cantBeLoadedEqually) {\n mandatoryLoad = Math.max(0, m.filter(mi => mi >= desiredLoad).length - sum%n);\n}\n\nprint(mandatoryFacilitation + mandatoryLoad);\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average < array[i])\n recudeSeconds += array[i] - average;\n}\nprint(Math.max(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average < array[i])\n recudeSeconds += array[i] - average+1;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average +1 < array[i])\n recudeSeconds += array[i] - average + 1;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average < array[i])\n recudeSeconds += array[i] - average;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = parseInt(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average +1 < array[i])\n recudeSeconds += array[i] - average -1;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = parseInt(readline());\nvar array =readline().split(\" \");\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + parseInt(current);\n}, 0);\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average +1 < array[i])\n recudeSeconds += array[i] - average - 1;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = readline().split(' ')[0];\nvar array = readline().split(' ');\nvar recudeSeconds = 0;\nvar increaseSeconds = 0;\n\nvar sum = array.reduce(function(sum, current) {\n return sum + current;\n});\n\nvar average = Math.floor(sum / n);\n\nfor (var i = 0; i < array.length; i++) {\n if (average > array[i])\n increaseSeconds += average - array[i];\n else if (average < array[i])\n recudeSeconds += array[i] - average;\n}\nprint(Math.min(increaseSeconds, recudeSeconds));"}, {"source_code": "var n = +readline();\nvar m = readline().split(\" \").map(mi => +mi);\n\nvar sum = m.reduce((a,b) => a + b);\nvar desiredLoad = Math.floor(sum / n);\nvar seconds = m\n .filter(mi => mi < desiredLoad)\n .reduce((seconds, mi) => seconds + Math.abs(mi - desiredLoad), 0);\nprint(seconds);\n"}, {"source_code": "var n = +readline();\nvar m = readline().split(\" \").map(mi => +mi);\n\nvar sum = m.reduce((a,b) => a + b);\nvar desiredLoad = Math.ceil(sum / n);\nvar seconds = m\n .filter(mi => mi >= desiredLoad)\n .reduce((seconds, mi) => seconds + mi - desiredLoad, 0);\nwrite(seconds + \"\\n\");\n"}, {"source_code": "var n = +readline();\nvar m = readline().split(\" \").map(mi => +mi);\n\nvar sum = m.reduce((a,b) => a + b);\nvar desiredLoad = Math.ceil(sum / n);\nvar mandatoryFacilitation = m\n .filter(mi => mi > desiredLoad)\n .reduce((seconds, mi) => seconds + mi - desiredLoad, 0);\n\nvar mandatoryLoad = 0;\nvar cantBeLoadedEqually = sum % n != 0;\nif (cantBeLoadedEqually) {\n mandatoryLoad = m.filter(mi => mi >= desiredLoad).length - sum%n;\n}\n\nprint(mandatoryFacilitation + mandatoryLoad);\n"}], "src_uid": "c0c29565e465840103a4af884f951cda"} {"source_code": "readline(); a = {}; readline().split(' ').forEach(i => a[i] = a[i] ? a[i] + 1: 1);\nn = Math.max.apply(null, Object.keys(a)); r=0; t=0;\nfor (i = 1; i <= n; i++) r = a[i] ? Math.max(a[i] * i + t, t = r) : t = r;\n\nwrite(r);\n", "positive_code": [{"source_code": "// https://codeforces.com/contest/455/problem/A\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", function(data) {\n input_stdin += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n input_stdin_array = input_stdin.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return input_stdin_array[input_currentline++];\n}\n\nfunction unaryParseInt(val) {\n return parseInt(val);\n}\n\nfunction getFrequencies(arr) {\n return arr.reduce((freq, num) => {\n if (freq[num]) {\n freq[num] += 1;\n } else {\n freq[num] = 1;\n }\n return freq;\n }, {});\n}\n\nfunction getUptoArr(arr, freq) {\n const upto = [];\n const first = arr[0];\n const last = arr[arr.length - 1];\n upto[first] = first * freq[first];\n for (let i = first + 1; i <= last; i++) {\n upto[i] = freq[i]\n ? Math.max(i * freq[i] + (upto[i - 2] || 0), upto[i - 1])\n : upto[i - 1];\n }\n return upto;\n}\n\nfunction getFromArr(arr, freq) {\n const from = [];\n const first = arr[0];\n const last = arr[arr.length - 1];\n from[last] = last * freq[last];\n for (let i = last - 1; i >= first; i--) {\n from[i] = freq[i]\n ? Math.max(i * freq[i] + (from[i + 2] || 0), from[i + 1])\n : from[i + 1];\n }\n return from;\n}\n\nfunction solve(arr) {\n const freq = getFrequencies(arr);\n const unique = [...new Set(arr)].sort((a, b) => (a > b ? 1 : -1));\n const uptoX = getUptoArr(unique, freq);\n const fromX = getFromArr(unique, freq);\n\n let ans = 1;\n for (let i = 0; i < unique.length; i++) {\n const curr = unique[i];\n ans = Math.max(\n ans,\n curr * freq[curr] + (uptoX[curr - 2] || 0) + (fromX[curr + 2] || 0)\n );\n }\n\n return ans;\n}\n\nfunction main() {\n readLine();\n const arr = readLine()\n .split(\" \")\n .map(unaryParseInt);\n\n var res = solve(arr);\n console.log(res);\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tdata = tokenizeIntegers(readline()),\n\t\titems = [], freq = {};\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar item = data[i];\n\t\tif (freq[item] === undefined) {\n\t\t\titems.push(item);\n\t\t\tfreq[item] = 0;\n\t\t}\n\t\tfreq[item] += 1;\n\t}\n\titems.sort(function (a, b) {\n\t\treturn a - b;\n\t});\n\tvar numItems = items.length,\n\t\tgain = new Array(numItems);\n\tgain[0] = items[0] * freq[items[0]];\n\tif (numItems > 1) {\n\t\tif (items[0] == items[1]-1) {\n\t\t\tgain[1] = Math.max(gain[0], items[1] * freq[items[1]]);\n\t\t} else {\n\t\t\tgain[1] = gain[0] + items[1] * freq[items[1]];\n\t\t}\n\t}\n\tfor (var i = 2; i < numItems; ++i) {\n\t\tif (items[i-1] == items[i]-1) {\n\t\t\tgain[i] = Math.max(gain[i-1],\n\t\t\t\t\tgain[i-2] + items[i] * freq[items[i]]);\n\t\t} else {\n\t\t\tgain[i] = gain[i-1] + items[i] * freq[items[i]];\n\t\t}\n\t}\n\tprint(gain[numItems-1]);\n}\n\nmain();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n\tthis.sortComparator = function( left , right ) {\n\t\treturn left - right ;\n\t} ;\n\t\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , a , b , c ;\n res = 0 ;\n this.arr = this.arr.sort( this.sortComparator ) ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.brr[ this.arr[ i ] ]++ ;\n }\n for( i = 1 ; i <= 100000 ; i++ ) {\n \tthis.crr[ i + 2 ] = Math.max( this.crr[ i + 2 ] , this.crr[ i ] + this.brr[ i ] * i ) ;\n \tthis.crr[ i + 3 ] = Math.max( this.crr[ i + 3 ] , this.crr[ i ] + this.brr[ i ] * i ) ;\n \tres = Math.max( res , this.crr[ i + 2 ] ) ;\n \tres = Math.max( res , this.crr[ i + 3 ] ) ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.arr.push( irObj.nextInt() );\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "n=+readline()\nx=readline().split(' ').map(v=>+v)\na=[]\nfor(i=0;i 1){\n\tif(unique[1] == unique[0]+1){\n\t\tgain[1] = Math.max(gain[0],unique[1]*cnt[unique[1]]);\n\t}\n\telse{\n\t\tgain[1] = gain[0] + unique[1]*cnt[unique[1]];\n\t}\n\tfor(var i = 2; i < unique.length; i++){\n\t\tif(unique[i] == unique[i-1]+1){\n\t\t\tgain[i] = Math.max(gain[i-1], gain[i-2] + unique[i]*cnt[unique[i]]);\n\t\t}\n\t\telse{\n\t\t\tgain[i] = gain[i-1] + unique[i]*cnt[unique[i]];\n\t\t}\n\t}\n}\n\nwrite(gain[unique.length-1]);"}, {"source_code": "readline(); a = []; readline().split(' ').map(Number).forEach(i => a[i] = a[i] ? a[i] + i: i);\nn = a.length;\nif (n > 0) d = [0];\nif (n > 1) d[1] = a[1] || 0;\nif (n > 2) d[2] = Math.max(a[2] || 0, d[1]);\n\n\nfor (i = 3; i < n; i++) {\n d[i] = a[i] ? Math.max(a[i] + d[i-2], d[i-1]) : d[i-1];\n}\n\nwrite(d[n-1]);\n"}, {"source_code": "readline(); a = {}; readline().split(' ').map(Number).forEach(i => a[i] = a[i] ? a[i] + i: i);\nn = Math.max.apply(null, Object.keys(a)); r=0; t=0;\nfor (i = 1; i <= n; i++) r = a[i] ? Math.max(a[i] + t, t = r) : t = r;\n\nwrite(r);\n"}, {"source_code": "/* TEST CASE\ninput\n9\n1 2 1 3 2 2 2 2 3\noutput\n10\n\nInput\n5\n3 3 4 5 4\nOutput\n8\nAnswer\n11\n\nInput\n5\n4 2 3 2 5\nOutput\n8\nAnswer\n9\n\ninput\n10\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000\noutput\n1000000\n\n */\n\nfunction maximumPoints(a, m) {\n\t// a must be sorted by a.num in ascending order\n\tvar maxOfK = new Array(m)\n\n\tmaxOfK[0] = a[0].total;\n\tvar maxValue = maxOfK[0]; \n\n\tfor (var k = 1; k < m; k++) {\n\t\tmaxOfK[k] = a[k].total;\n\n\t\tif (a[k].num == a[k - 1].num + 1) {\n\t\t\tif (k > 1) {\n\t\t\t\tmaxOfK[k] += maxOfK[k - 2];\t\n\t\t\t}\n\t\t\tmaxOfK[k] = Math.max(maxOfK[k], maxOfK[k - 1]);\n\t\t} else {\n\t\t\tmaxOfK[k] += maxOfK[k - 1];\n\t\t}\n\t\t\n\t\tif (maxOfK[k] > maxValue) {\n\t\t\tmaxValue = maxOfK[k];\n\t\t}\n\t}\n\n\treturn maxValue;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(' ');\n\tvar freq = {};\t//Map\n\tvar i, j;\n\tvar a = [];\n\tvar num;\n\tfor (i = 0; i < n; i++) {\n\t\tnum = parseInt(splitted[i]);\n\t\tif (freq[num] == null) {\n\t\t\ta.push({num: num, total: 0});\n\t\t\tfreq[num] = 1;\n\t\t} else {\n\t\t\tfreq[num]++;\n\t\t}\n\t}\n\tvar m = a.length;\n\tfor (i = 0; i < m; i++) {\n\t\ta[i].total = a[i].num * freq[a[i].num];\n\t}\n\ta.sort(function(n1, n2) {return n1.num - n2.num;});\t//ascending order\n//FOR DEBUG:\n//\tfor (i = 0; i < m; i++) {\n//\t\tprint(a[i].num, a[i].total);\n//\t}\n\tvar answer = maximumPoints(a, m);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "readline(); a = []; readline().split(' ').map(Number).forEach(i => a[i] = a[i] ? a[i] + i: i);\nn = a.length; d = [0]; d[1] = a[1] || 0;\n\nfor (i = 2; i < n; i++) d[i] = a[i] ? Math.max(a[i] + d[i-2], d[i-1]) : d[i-1];\n\nwrite(d[n-1]);\n"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(' ').map(Number);\n\nvar sum = [], res = [];\n\nfor(var i=-2; i<=100000; i++)\n{\n sum[i] = 0;\n res[i] = 0;\n}\n\nfor(var i=0; i 1) {\n\t\t\t\tmaxOfK[k] += maxOfK[k - 2];\t\n\t\t\t}\n\t\t\tmaxOfK[k] = Math.max(maxOfK[k], maxOfK[k - 1]);\n\t\t} else {\n\t\t\tmaxOfK[k] = a[k].total + maxOfK[k - 1];\n\t\t}\n\t\t\n\t\tif (maxOfK[k] > maxValue) {\n\t\t\tmaxValue = maxOfK[k];\n\t\t}\n\t}\n\n\treturn maxValue;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(' ');\n\tvar freq = {};\t//Map\n\tvar i, j;\n\tvar a = [];\n\tvar num;\n\tfor (i = 0; i < n; i++) {\n\t\tnum = parseInt(splitted[i]);\n\t\tif (freq[num] == null) {\n\t\t\ta.push({num: num, total: 0});\n\t\t\tfreq[num] = 1;\n\t\t} else {\n\t\t\tfreq[num]++;\n\t\t}\n\t}\n\tvar m = a.length;\n\tfor (i = 0; i < m; i++) {\n\t\ta[i].total = a[i].num * freq[a[i].num];\n\t}\n\ta.sort(function(n1, n2) {return n1.num - n2.num;});\t//ascending order\n//FOR DEBUG:\n//\tfor (i = 0; i < m; i++) {\n//\t\tprint(a[i].num, a[i].total);\n//\t}\n\tvar answer = maximumPoints(a, m);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var k = 100000;\nvar n = parseInt(readline());\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar cnt = Array.apply(null, Array(k + 1)).map(Number.prototype.valueOf,0);\nvar dp = Array(k + 1);\n\nfor(var i = 0; i < n; i++)\n cnt[a[i]]++;\n\ndp[0] = 0;\ndp[1] = cnt[1];\n\nfor(var i = 2; i <= k; i++)\n dp[i] = Math.max(dp[i - 1], dp[i - 2] + cnt[i] * i)\n\nprint(dp[k])"}, {"source_code": "var n = +readline();\nvar data = readline().split(' ');\n\nvar arr = new Array(100010).fill(0);\nfor (var i = 0; i < n; ++i) {\n ++arr[+data[i]];\n}\n\nvar dp = new Array(n + 1);\ndp[0] = 0;\ndp[1] = arr[1];\nfor (var i = 2; i <= 100000; ++i) {\n dp[i] = Math.max(dp[i - 1], dp[i - 2] + (arr[i] * i));\n}\n\nwrite(dp[100000]);"}, {"source_code": "var n = +readline();\nvar data = readline().split(' ');\n\nvar arr = new Array(100001).fill(0);\nfor (var i = 0; i < n; ++i) {\n ++arr[+data[i]];\n}\n\nvar dp = [0, arr[1]];\nfor (var i = 2; i <= 100000; ++i) {\n dp.push(Math.max(dp[i - 1], dp[i - 2] + (arr[i] * i)));\n}\n\nwrite(dp[100000]);"}, {"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(w) {\n\t\treturn parseInt(w)\n\t})\n}\n\nreadline()\nvar a = ints()\n\nvar numbers = [],\n\tmax = 0\na.forEach(function(n) {\n\tif (numbers[n] == undefined)\n\t\tnumbers[n] = 0\n\tnumbers[n] += n\n\tif (max < n)\n\t\tmax = n\n})\n\nvar i = 0,\n\tj = 0,\n\tk = 0\n\nwhile (max >= 0) {\n\tk = j\n\tj = i\n\ti = Math.max((numbers[max] || 0) + k, j)\n\tmax --\n}\n\nprint(i)"}, {"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(w) {\n\t\treturn parseInt(w)\n\t})\n}\n\nreadline()\nvar a = ints()\n\nvar numbers = [],\n\tmax = 0\na.forEach(function(n) {\n\tif (numbers[n] == undefined)\n\t\tnumbers[n] = 0\n\tnumbers[n] += n\n\tif (max < n)\n\t\tmax = n\n})\n\nvar mem = []\n\nmem[max + 1] = 0\nmem[max + 2] = 0\n\nwhile (max >= 0) {\n\tmem[max] = Math.max((numbers[max] || 0) + mem[max + 2], mem[max + 1])\n\tmax --\n}\n\nprint(mem[0])"}, {"source_code": "print(function (n) {\n\tvar m = {}, ret = {};\n\treadline().split(' ').forEach(function(e) { m[e] = m[e] ? m[e] + 1: 1; });\n\n\tfor(var i = 1, _i = Math.max.apply(null, Object.keys(m)) + 1; i < _i ; i++)\n\t\tret[i] = Math.max(ret[i - 1] || 0, (ret[i - 2] || 0) + (m[i] * i || 0));\n\n\treturn ret[i - 1]\n}(+readline()));"}, {"source_code": "n=Number(readline())\nN=100000\nA=readline().split(' ').map(Number)\n .reduce((a,c) => { a[c]++; return a }, (new Array(N+1)).fill(0))\nFF={ 1:A[1] }\n\nfor (i=2; i<=N; ++i) {\n FF[i] = Math.max(A[i]*i + (FF[i-2]||0), (FF[i-1]||0))\n}\n\nprint(FF[N])\n\n\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n nums.sort((a, b) => a - b);\n\n const newArr = [];\n const map = {};\n \n nums.forEach(x => {\n map[x] === undefined ? (map[x] = 1, newArr.push(x) ): map[x] += 1;\n }); \n\n if (newArr.length === 1) {\n console.log(\n map[ newArr[0] ] * newArr[0]\n ); return;\n }\n if (newArr.length === 2) {\n console.log(\n Math.max( map[ newArr[0] ] * newArr[0], map[ newArr[1] ] * newArr[1] )\n ); return\n }\n\n const dp = [];\n dp[0] = map[newArr[0]] * newArr[0];\n dp[1] = Math.max(dp[0], map[newArr[1]] * newArr[1])\n\n if (newArr[0]+1 !== newArr[1]) {\n dp[1] += dp[0];\n }\n\n for (let i = 2; i < newArr.length; i += 1) {\n if (newArr[i-1]+1 !== newArr[i]) \n dp[i] = Math.max(dp[i-2], dp[i-1]) + (map[newArr[i]] * newArr[i]);\n else\n dp[i] = Math.max(dp[i-2] + (map[newArr[i]] * newArr[i]), dp[i-1]);\n }\n\n console.log(dp.pop());\n}); \n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar a = readline().split(' ').map(Number);\nvar vals = [], res = [];\nfor (var i = -2; i <= 100000; i++) { vals[i] = 0; res[i] = 0; }\nfor (var i = 0; i < a.length; i++) vals[a[i]] += a[i];\nfor (var i = 1; i <= 100000; i++) {\n res[i] = Math.max(res[i-1], res[i-2] + vals[i], res[i-3] + vals[i]);\n}\nwrite(res[100000]);"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '9';\n// case 2: return '1 2 1 3 2 2 2 2 3';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nvar n = parseInt(readline());\n\nvar maxA = 0;\nvar c = [];\n\nreadline().split(' ').forEach(function(element) {\n var a = parseInt(element);\n\n if (c[a] === undefined) {\n c[a] = 1;\n } else {\n c[a] ++;\n }\n\n maxA = Math.max(maxA, a);\n});\n\nvar f = [];\n\nf[0] = 0;\nf[1] = c[1] || 0;\n\nfor (var i = 2; i <= maxA; i ++) {\n f[i] = Math.max(f[i-1], f[i-2] + (c[i] || 0)*i);\n}\n\nwrite(f[maxA]);\n"}, {"source_code": "var n = readline(),\n\t\t\ta = readline(),\n\t\t\tarray = a.replace(/\\s{1,}/gi, ' ').split(/\\s/),\n\t\t\t_array = {},\n\t\t\t_arrayKeySet = [],\n\t\t\tresultArray = {};\n\n\t\tarray = array.map(function(value, index)\t{\n\t\t\tif(!_array[value])\t{\n\t\t\t\t_array[value] = 1;\n\t\t\t} else\t{\n\t\t\t\t_array[value]++;\n\t\t\t}\n\n\t\t\treturn parseInt(value);\n\t\t});\n\n\t\t_arrayKeySet = Object.keys(_array);\n\n\t\tfor(var i=1; i<=_arrayKeySet[_arrayKeySet.length - 1]; i++)\t{\n\t\t\tvar preVal = !resultArray[i - 1] ? 0 : resultArray[i - 1],\n\t\t\t\tmorePreVal = !resultArray[i - 2] ? 0 : resultArray[i - 2],\n\t\t\t\tcurrentVal = _array[i] * i;\n\n\t\t\tif(isNaN(currentVal))\tcurrentVal = 0;\n\n\t\t\tresultArray[i] = Math.max(preVal, morePreVal + currentVal);\n\t\t}\n\n\t\tprint(resultArray[i - 1]);"}], "negative_code": [{"source_code": "n=+readline()\nx=readline().split(' ').map(v=>+v)\na=[]\nfor(i=0;i 0) {\n\t\tvar chosen = a.pop();\n\t\tif (freq[chosen.num] != null) {\n\t\t\tanswer += chosen.total;\n\t\t\tfreq[chosen.num - 1] = null;\n\t\t\tfreq[chosen.num + 1] = null;\n\t\t}\n\t}\n\t\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n9\n1 2 1 3 2 2 2 2 3\noutput\n10\n\nInput\n5\n3 3 4 5 4\nOutput\n8\nAnswer\n11\n\nInput\n5\n4 2 3 2 5\nOutput\n8\nAnswer\n9\n\n */\n\nfunction maximumPoints_ITERATIVE(a, m) {\n\t// a must be sorted by a.num in ascending order\n\tvar maxValue = 0;\n\tvar maxOfK = new Array(m)\n\n\tmaxOfK[0] = a[0].total;\n\t\n\tfor (var k = 1; k < m; k++) {\n\t\tif (a[k].num == a[k - 1].num + 1) {\n\t\t\tmaxOfK[k] = a[k].total;\n\t\t\tif (k > 1) {\n\t\t\t\tmaxOfK[k] += maxOfK[k - 2];\t\n\t\t\t}\n\t\t\tmaxOfK[k] = Math.max(maxOfK[k], maxOfK[k - 1]);\n\t\t} else {\n\t\t\tmaxOfK[k] = a[k].total + maxOfK[k - 1];\n\t\t}\n\t\t\n\t\tif (maxOfK[k] > maxValue) {\n\t\t\tmaxValue = maxOfK[k];\n\t\t}\n\t}\n\n\treturn maxValue;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(' ');\n\tvar freq = {};\t//Map\n\tvar i, j;\n\tvar a = [];\n\tvar num;\n\tfor (i = 0; i < n; i++) {\n\t\tnum = parseInt(splitted[i]);\n\t\tif (freq[num] == null) {\n\t\t\ta.push({num: num, total: 0});\n\t\t\tfreq[num] = 1;\n\t\t} else {\n\t\t\tfreq[num]++;\n\t\t}\n\t}\n\tvar m = a.length;\n\tfor (i = 0; i < m; i++) {\n\t\ta[i].total = a[i].num * freq[a[i].num];\n\t}\n\ta.sort(function(n1, n2) {return n1.num - n2.num;});\t//ascending order\n//FOR DEBUG:\n//\tfor (i = 0; i < m; i++) {\n//\t\tprint(a[i].num, a[i].total);\n//\t}\n\tvar answer = maximumPoints_ITERATIVE(a, m);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\nInput\n5\n3 3 4 5 4\nOutput\n8\nAnswer\n11\n\ninput\n2\n1 2\noutput\n2\ninput\n3\n1 2 3\noutput\n4\ninput\n9\n1 2 1 3 2 2 2 2 3\noutput\n10\n */\n\nfunction maximumPoints_ITERATIVE(a, m) {\n\t// a must be sorted by a.num in ascending order\n\tvar maxValue = 0;\n\tvar maxOfK = new Array(m)\n\n\tmaxOfK[0] = a[0].total;\n\t\n\tfor (var k = 1; k < m; k++) {\n\t\tif (a[k].num == a[k - 1].num + 1) {\n\t\t\tmaxOfK[k] = a[k].total;\n\t\t\tif (k > 1) {\n\t\t\t\tmaxOfK[k] += maxOfK[k - 2];\t\n\t\t\t}\n\t\t} else {\n\t\t\tmaxOfK[k] = a[k].total + maxOfK[k - 1];\n\t\t}\n\t\t\n\t\tif (maxOfK[k] > maxValue) {\n\t\t\tmaxValue = maxOfK[k];\n\t\t}\n\t}\n\n\treturn maxValue;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar splitted = readline().split(' ');\n\tvar freq = {};\t//Map\n\tvar i, j;\n\tvar a = [];\n\tvar num;\n\tfor (i = 0; i < n; i++) {\n\t\tnum = parseInt(splitted[i]);\n\t\tif (freq[num] == null) {\n\t\t\ta.push({num: num, total: 0});\n\t\t\tfreq[num] = 1;\n\t\t} else {\n\t\t\tfreq[num]++;\n\t\t}\n\t}\n\tvar m = a.length;\n\tfor (i = 0; i < m; i++) {\n\t\ta[i].total = a[i].num * freq[a[i].num];\n\t}\n\ta.sort(function(n1, n2) {return n1.num - n2.num;});\t//ascending order\n//FOR DEBUG:\n//\tfor (i = 0; i < m; i++) {\n//\t\tprint(a[i].num, a[i].total);\n//\t}\n\tvar answer = maximumPoints_ITERATIVE(a, m);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar cnt = Array.apply(null, Array(n + 1)).map(Number.prototype.valueOf,0);\nvar dp = Array(n + 1);\n\nfor(var i = 0; i < n; i++)\n cnt[a[i]]++;\n\ndp[0] = 0;\ndp[1] = cnt[1];\n\nfor(var i = 2; i <= n; i++)\n dp[i] = Math.max(dp[i - 1], dp[i - 2] + cnt[i] * i)\n\nprint(dp[n])"}, {"source_code": "var n = +readline();\nvar data = readline().split(' ');\n\nvar arr = new Array(100010).fill(0);\nfor (var i = 0; i < n; ++i) {\n ++arr[+data[i]];\n}\n\nvar dp = new Array(n + 1);\ndp[0] = 0;\ndp[1] = arr[1];\nfor (var i = 2; i <= n; ++i) {\n dp[i] = Math.max(dp[i - 1], dp[i - 2] + (arr[i] * i));\n}\n\nwrite(dp[n]);"}, {"source_code": "n=Number(readline())\nN=100000\nA=readline().split(' ').map(Number)\n .reduce((a,c) => { a[c]++; return a }, (new Array(N+1)).fill(0))\nFF={}\n// const f = i => {\n// print(i)\n// if (i=0; --i) {\n FF[i] = Math.max(A[i]*i+FF[i+2]||0, A[i+1]*(i+1) + FF[i+3]||0)\n}\n\nprint(FF[0])\n\n\n\n\n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar a = readline().split(' ').map(Number);\nvar vals = [], res = [];\nfor (var i = -2; i <= 10000; i++) { vals[i] = 0; res[i] = 0; }\nfor (var i = 0; i < a.length; i++) vals[a[i]] += a[i];\nfor (var i = 1; i <= 10000; i++) {\n res[i] = Math.max(res[i-1], res[i-2] + vals[i], res[i-3] + vals[i]);\n}\nwrite(res[10000]);"}, {"source_code": "var n = parseInt(readline());\n\nvar a = readline().split(' ').map(function (currentValue) {\n return parseInt(currentValue);\n});\n\nvar c = [];\nvar u = [];\n\nfor (var i = 0; i < n; i ++) {\n if (c[a[i]] === undefined) {\n c[a[i]] = 1;\n } else {\n c[a[i]] ++;\n }\n}\n\na.sort(function (x, y) {\n return c[y]*y - c[x]*x;\n});\n\n\nvar sum = 0;\n\nfor (var i = 0; i < n; i ++) {\n if (u[a[i]] === undefined) {\n sum += a[i];\n }\n u[a[i]-1] = true;\n u[a[i]+1] = true;\n}\n\nwrite(sum);\n"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '5';\n// case 2: return '3 3 4 4 5';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nfunction getSum(a, n) {\n var c = [];\n var u = [];\n\n var sum = 0;\n\n for (var i = 0; i < n; i ++) {\n if (u[a[i]] === undefined) {\n sum += a[i];\n u[a[i]-1] = true;\n u[a[i]+1] = true;\n }\n }\n\n return sum;\n}\n\nvar n = parseInt(readline());\n\nvar a = readline().split(' ').map(function (currentValue) {\n return parseInt(currentValue);\n});\n\nvar c = [];\n\nfor (var i = 0; i < n; i ++) {\n if (c[a[i]] === undefined) {\n c[a[i]] = 1;\n } else {\n c[a[i]] ++;\n }\n}\n\na.sort(function(x, y) {\n return y*c[y] - x*c[x];\n});\n\nvar sum1 = getSum(a, n);\n\na.sort(function(x, y) {\n return y - x;\n});\n\nvar sum2 = getSum(a, n);\n\nwrite(Math.max(sum1, sum2));\n"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '9';\n// case 2: return '1 2 1 3 2 2 2 2 3';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nvar n = parseInt(readline());\n\nvar a = readline().split(' ').map(function (currentValue) {\n return parseInt(currentValue);\n});\n\nvar c = [];\nvar u = [];\n\nfor (var i = 0; i < n; i ++) {\n if (c[a[i]] === undefined) {\n c[a[i]] = 1;\n } else {\n c[a[i]] ++;\n }\n}\n\na.sort(function (x, y) {\n return c[y]*y - c[x]*x;\n});\n\nvar sum = 0;\n\nfor (var i = 0; i < n; i ++) {\n if (u[a[i]] === undefined) {\n sum += a[i];\n u[a[i]-1] = true;\n u[a[i]+1] = true;\n }\n}\n\nwrite(sum);\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n nums.sort((a, b) => a - b);\n\n const newArr = [];\n const map = {};\n\n \n nums.forEach(x => {\n map[x] === undefined ? (map[x] = 1, newArr.push(x) ): map[x] += 1;\n }); \n\n if (newArr.length === 1) {\n console.log(\n map[ newArr[0] ] * newArr[0]\n ); return;\n }\n if (newArr.length === 2) {\n console.log(\n Math.max( map[ newArr[0] ] * newArr[0], map[ newArr[1] ] * newArr[1] )\n ); return\n }\n\n const dp = [];\n dp[0] = map[newArr[0]] * newArr[0];\n dp[1] = Math.max(dp[0], map[newArr[1]] * newArr[1])\n for (let i = 2; i < newArr.length; i += 1) {\n dp[i] = Math.max(dp[i-2]+ (map[newArr[i]] * newArr[i]), dp[i-1]);\n }\n\n console.log(dp.pop());\n}); \n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n nums.sort((a, b) => a - b);\n\n const newArr = [];\n const map = {};\n\n \n nums.forEach(x => {\n map[x] === undefined ? (map[x] = 1, newArr.push(x) ): map[x] += 1;\n }); \n\n if (newArr.length === 1) {\n console.log(\n map[ newArr[0] ] * newArr[0]\n ); return;\n }\n if (newArr.length === 2) {\n console.log(\n Math.max( map[ newArr[0] ] * newArr[0], map[ newArr[1] ] * newArr[1] )\n ); return\n }\n\n let answ = 0;\n for (let i = 0; i < newArr.length - 2; i += 1) {\n\n answ += Math.max(\n map[ newArr[i] ] * newArr[i] + map[ newArr[i+2] ] * newArr[i+2],\n map[ newArr[i + 1] ] * newArr[i + 1]\n );\n\n if (map[ newArr[i] ] * newArr[i] > map[ newArr[i + 1] ] * newArr[i + 1]) {\n i += 1; continue;\n } else {\n i += 2; continue;\n }\n }\n\n console.log(answ);\n\n}); \n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", function(data) {\n input_stdin += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n input_stdin_array = input_stdin.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return input_stdin_array[input_currentline++];\n}\n\nfunction unaryParseInt(val) {\n return parseInt(val);\n}\n\nfunction getFrequencies(arr) {\n return arr.reduce((freq, num) => {\n if (freq[num]) {\n freq[num] += 1;\n } else {\n freq[num] = 1;\n }\n return freq;\n }, {});\n}\n\nfunction getUptoArr(arr, freq) {\n const upto = [];\n const first = arr[0];\n const last = arr[arr.length - 1];\n upto[first] = first * freq[first];\n for (let i = first + 1; i <= last; i++) {\n upto[i] = freq[i]\n ? Math.max(i * freq[i] + (upto[i - 2] || 0), upto[i - 1])\n : upto[i - 1];\n }\n return upto;\n}\n\nfunction getFromArr(arr, freq) {\n const from = [];\n const first = arr[0];\n const last = arr[arr.length - 1];\n from[last] = last * freq[last];\n for (let i = last - 1; i >= first; i--) {\n from[i] = freq[i]\n ? Math.max(arr[i] * freq[arr[i]] + (from[i + 2] || 0), from[i + 1])\n : from[i + 1];\n }\n return from;\n}\n\nfunction solve(arr) {\n const freq = getFrequencies(arr);\n const unique = [...new Set(arr)].sort((a, b) => (a > b ? 1 : -1));\n const uptoX = getUptoArr(unique, freq);\n const fromX = getFromArr(unique, freq);\n\n let ans = 1;\n for (let i = 0; i < unique.length; i++) {\n const curr = unique[i];\n ans = Math.max(\n ans,\n curr * freq[curr] + (uptoX[curr - 2] || 0) + (fromX[curr + 2] || 0)\n );\n }\n\n return ans;\n}\n\nfunction main() {\n readLine();\n const arr = readLine()\n .split(\" \")\n .map(unaryParseInt);\n\n var res = solve(arr);\n console.log(res);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", function(data) {\n input_stdin += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n input_stdin_array = input_stdin.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return input_stdin_array[input_currentline++];\n}\n\nfunction unaryParseInt(val) {\n return parseInt(val);\n}\n\nfunction getFrequencies(arr) {\n return arr.reduce((freq, num) => {\n if (freq[num]) {\n freq[num] += 1;\n } else {\n freq[num] = 1;\n }\n return freq;\n }, {});\n}\n\nfunction getUptoArr(arr, freq) {\n const upto = [];\n upto[0] = arr[0] * freq[arr[0]];\n for (let i = 1; i < arr.length; i++) {\n upto[i] = Math.max(arr[i] * freq[arr[i]] + (upto[i - 2] || 0), upto[i - 1]);\n }\n return upto;\n}\n\nfunction getFromArr(arr, freq) {\n const from = [];\n const n = arr.length;\n from[n - 1] = arr[n - 1] * freq[arr[n - 1]];\n for (let i = n - 1; i >= 0; i--) {\n from[i] = Math.max(arr[i] * freq[arr[i]] + (from[i + 2] || 0), from[i + 1]);\n }\n return from;\n}\n\nfunction solve(arr) {\n const freq = getFrequencies(arr);\n const unique = [...new Set(arr)];\n const uptoX = getUptoArr(unique, freq);\n const fromX = getFromArr(unique, freq);\n\n let ans = 1;\n for (let i = 0; i < unique.length; i++) {\n const curr = unique[i];\n ans = Math.max(\n ans,\n curr * freq[curr] + (uptoX[i - 2] || 0) + (fromX[i + 2] || 0)\n );\n }\n\n return ans;\n}\n\nfunction main() {\n readLine();\n const arr = readLine()\n .split(\" \")\n .map(unaryParseInt);\n\n var res = solve(arr);\n console.log(res);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\nvar input_stdin = \"\";\nvar input_stdin_array = \"\";\nvar input_currentline = 0;\n\nprocess.stdin.on(\"data\", function(data) {\n input_stdin += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n input_stdin_array = input_stdin.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return input_stdin_array[input_currentline++];\n}\n\nfunction unaryParseInt(val) {\n return parseInt(val);\n}\n\nfunction getFrequencies(arr) {\n return arr.reduce((freq, num) => {\n if (freq[num]) {\n freq[num] += 1;\n } else {\n freq[num] = 1;\n }\n return freq;\n }, {});\n}\n\nfunction getUptoArr(arr, freq) {\n const upto = [];\n upto[0] = arr[0] * freq[arr[0]];\n for (let i = 1; i < arr.length; i++) {\n upto[i] = Math.max(arr[i] * freq[arr[i]] + (upto[i - 2] || 0), upto[i - 1]);\n }\n return upto;\n}\n\nfunction getFromArr(arr, freq) {\n const from = [];\n const n = arr.length;\n from[n - 1] = arr[n - 1] * freq[arr[n - 1]];\n for (let i = n - 1; i >= 0; i--) {\n from[i] = Math.max(arr[i] * freq[arr[i]] + (from[i + 2] || 0), from[i + 1]);\n }\n return from;\n}\n\nfunction solve(arr) {\n const freq = getFrequencies(arr);\n const unique = [...new Set(arr)].sort((a, b) => a > b ? 1 : -1);\n const uptoX = getUptoArr(unique, freq);\n const fromX = getFromArr(unique, freq);\n\n let ans = 1;\n for (let i = 0; i < unique.length; i++) {\n const curr = unique[i];\n ans = Math.max(\n ans,\n curr * freq[curr] + (uptoX[i - 2] || 0) + (fromX[i + 2] || 0)\n );\n }\n\n return ans;\n}\n\nfunction main() {\n readLine();\n const arr = readLine()\n .split(\" \")\n .map(unaryParseInt);\n\n var res = solve(arr);\n console.log(res);\n}"}, {"source_code": "readline(); a = {}; readline().split(' ').forEach(i => a[i] = a[i] ? a[i] + 1: i);\nn = Math.max.apply(null, Object.keys(a)); r=0; t=0;\nfor (i = 1; i <= n; i++) r = a[i] ? Math.max(a[i] * i + t, t = r) : t = r;\n\nwrite(r);\n"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, sum = 0;\n\t\treadline().split(' ').forEach(function (e) { m[e] = m[e] ? m[e] + 1 : 1; });\n\n\t\tvar k = Object.keys(m).map(Number);\n\t\tfor (var i = 0, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1 && k.indexOf(t + 1) === -1) {\n\t\t\t\tsum += m[k[i]] * k[i];\n\t\t\t\tdelete m[k[i]];\n\t\t\t}\n\t\t}\n\n\t\tk = Object.keys(m).map(Number).sort(function (a, b) { return a - b; });\n\t\tfor (var i = 0, _I = -1, I_ = -1, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1) _I = i;\n\t\t\tif (k.indexOf(t + 1) === -1) I_ = i;\n\t\t\tif (_I !== -1 && I_ !== -1) {\n\t\t\t\tvar s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0;\n\t\t\t\tfor (var j = _I + 0; j <= I_; j += 2) s1 += m[k[j]] * k[j];\n\t\t\t\tfor (var j = _I + 1; j <= I_; j += 2) s2 += m[k[j]] * k[j];\n\n\t\t\t\tif (I_ - _I > 2) {\n\t\t\t\t\tfor (var j = _I + 0; j <= I_; j += 3) s3 += m[k[j]] * k[j];\n\t\t\t\t\tif (I_ === j - 1) s3 += m[k[_I]] * k[_I];\n\t\t\t\t}\n\n\t\t\t\tif (I_ - _I > 3) {\n\t\t\t\t\tfor (var j = _I + 1; j <= I_; j += 3) s4 += m[k[j]] * k[j];\n\t\t\t\t\tif (I_ === j - 1) s4 += m[k[_I]] * k[_I];\n\t\t\t\t}\n\n\t\t\t\tif (I_ - _I > 4) {\n\t\t\t\t\tfor (var j = _I + 2; j <= I_; j += 3) s5 += m[k[j]] * k[j];\n\t\t\t\t\tif (I_ === j - 1) s5 += m[k[_I]] * k[_I];\n\t\t\t\t}\n\n\t\t\t\tsum += Math.max(s1, s2, s3, s4, s5);\n\t\t\t\t_I = I_ = -1;\n\t\t\t}\n\t\t}\n\n\t\treturn sum;\n\t}(+readline()));\n\n}).call(this);"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, sum = 0;\n\t\treadline().split(' ').forEach(function (e) { m[e] = m[e] ? m[e] + 1 : 1; });\n\n\t\tvar k = Object.keys(m).map(Number);\n\t\tfor (var i = 0, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1 && k.indexOf(t + 1) === -1) {\n\t\t\t\tsum += m[k[i]] * k[i];\n\t\t\t\tdelete m[k[i]];\n\t\t\t}\n\t\t}\n\n\t\tk = Object.keys(m).map(Number).sort(function (a, b) { return a - b; });\n\t\tfor (var i = 0, _I = -1, I_ = -1, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1) _I = i;\n\t\t\tif (k.indexOf(t + 1) === -1) I_ = i;\n\t\t\tif (_I !== -1 && I_ !== -1) {\n\t\t\t\tfor (var j = _I, s = [0, 0]; j <= I_; j++)\n\t\t\t\t\ts[j%2] += m[k[j]] * k[j];\n\t\t\t\tsum += Math.max.apply(null, s);\n\t\t\t\t_I = I_ = -1;\n\t\t\t}\n\t\t}\n\n\t\treturn sum;\n\t}(+readline()));\n\n}).call(this);"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, sum = 0;\n\t\treadline().split(' ').forEach(function (e) { m[e] = m[e] ? m[e] + 1 : 1; });\n\n\t\tvar k = Object.keys(m).map(Number);\n\t\tfor (var i = 0, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1 && k.indexOf(t + 1) === -1) {\n\t\t\t\tsum += m[k[i]] * k[i];\n\t\t\t\tdelete m[k[i]];\n\t\t\t}\n\t\t}\n\n\t\tk = Object.keys(m).map(Number).sort(function (a, b) { return a - b; });\n\t\tfor (var i = 0, _I = -1, I_ = -1, _i = k.length; i < _i; i++) {\n\t\t\tvar t = k[i];\n\t\t\tif (k.indexOf(t - 1) === -1) _I = i;\n\t\t\tif (k.indexOf(t + 1) === -1) I_ = i;\n\t\t\tif (_I !== -1 && I_ !== -1) {\n\t\t\t\tfor (var j = _I + 0, s1 = 0; j <= I_; j += 2) s1 += m[k[j]] * k[j];\n\t\t\t\tfor (var j = _I + 1, s2 = 0; j <= I_; j += 2) s2 += m[k[j]] * k[j];\n\t\t\t\tfor (var j = _I + 0, s3 = 0; j <= I_; j += 3) s3 += m[k[j]] * k[j];\n\t\t\t\tfor (var j = _I + 1, s4 = 0; j <= I_; j += 3) s4 += m[k[j]] * k[j];\n\t\t\t\tfor (var j = _I + 2, s5 = 0; j <= I_; j += 3) s5 += m[k[j]] * k[j];\n\t\t\t\tsum += Math.max(s1, s2, s3, s4, s5);\n\t\t\t\t_I = I_ = -1;\n\t\t\t}\n\t\t}\n\n\t\treturn sum;\n\t}(+readline()));\n\n}).call(this);"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = true;\n\n\tthis.sortComparator = function( left , right ) {\n\t\treturn left - right ;\n\t} ;\n\t\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , a , b , c ;\n res = 0 ;\n this.arr = this.arr.sort( this.sortComparator ) ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.brr[ this.arr[ i ] ]++ ;\n }\n for( i = 1 ; i <= 100000 ; i++ ) {\n \tthis.crr[ i + 2 ] = Math.max( this.crr[ i + 2 ] , this.crr[ i ] + this.brr[ i ] * i ) ;\n \tres = Math.max( res , this.crr[ i + 2 ] ) ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n \tthis.arr.push( irObj.nextInt() );\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}], "src_uid": "41b3e726b8146dc733244ee8415383c0"} {"source_code": "const solve = (n,arr)=>{\r\n const gcd = (a,b)=>b===0n ? a : gcd(b,a%b);\r\n let gcD = [arr[0],arr[1]];\r\n for(let i=0;iBigInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction calgcd (a, b) {\r\n\tif (!b) return a;\r\n\treturn calgcd(b, a%b);\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst gcd = [a[0], a[1]];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tgcd[i%2] = calgcd(gcd[i%2], a[i]);\r\n\r\n\t\tlet ans = 0n;\r\n\t\tfor (let k = 0; !ans && k<2; k++) {\r\n\t\t\tlet d = gcd[k], ok = true;\r\n\t\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\t\tok = a[i]%d == 0n;\r\n\r\n\t\t\t\tif (i&1) ok = !ok;\r\n\t\t\t\tif (k) ok = !ok;\r\n\t\t\t}\r\n\t\t\tans = ok ? d : 0n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(BigInt);\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let evenGCD = arr[0];\r\n let oddGCD = arr[1];\r\n let result1, result2;\r\n\r\n for (let i = 2; i < N; ++i) {\r\n if (i % 2 === 0) {\r\n evenGCD = gcd(arr[i], evenGCD);\r\n } else {\r\n oddGCD = gcd(arr[i], oddGCD);\r\n }\r\n }\r\n\r\n result1 = evenGCD;\r\n\r\n for (let i = 1; i < N; ++i) {\r\n if ((arr[i] % result1 === 0n) === (arr[i - 1] % result1 === 0n)) {\r\n result1 = 0n;\r\n break;\r\n }\r\n }\r\n \r\n result2 = oddGCD;\r\n \r\n for (let i = 1; i < N; ++i) {\r\n if ((arr[i] % result2 === 0n) === (arr[i - 1] % result2 === 0n)) {\r\n result2 = 0n;\r\n break;\r\n }\r\n }\r\n\r\n if (result1 === 0n && result2 === 0n) {\r\n console.log(0);\r\n } else if (result1 !== 0n) {\r\n console.log(result1.toString());\r\n } else {\r\n console.log(result2.toString());\r\n }\r\n}\r\n\r\nfunction gcd(a, b) {\r\n return (b === 0n ? a : gcd(b, a % b));\r\n}"}], "negative_code": [{"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(BigInt);\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let evenGCD = arr[0];\r\n let oddGCD = arr[1];\r\n let greaterGCD;\r\n\r\n for (let i = 2; i < N; ++i) {\r\n if (i % 2 === 0) {\r\n evenGCD = gcd(arr[i], evenGCD);\r\n } else {\r\n oddGCD = gcd(arr[i], oddGCD);\r\n }\r\n }\r\n \r\n greaterGCD = evenGCD > oddGCD ? evenGCD : oddGCD;\r\n\r\n for (let i = 1; i < N; ++i) {\r\n if ((arr[i] % greaterGCD === 0n) === (arr[i - 1] % greaterGCD === 0n)) {\r\n console.log(0);\r\n return;\r\n }\r\n }\r\n \r\n console.log(greaterGCD.toString());\r\n}\r\n\r\nfunction gcd(a, b) {\r\n return (b === 0n ? a : gcd(b, a % b));\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, arr;\r\n let k = 0;\r\n\r\n while (T--) {\r\n k++;\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(BigInt);\r\n solve(N, arr);\r\n if (k === 20 && arr.length !== 2) {\r\n console.log('hello');\r\n console.log(arr);\r\n console.log('hello');\r\n }\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let result = BigInt(0);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n result = arr[i];\r\n\r\n for (let j = 1; j < N; ++j) {\r\n if ((arr[j] % result === 0n) === (arr[j - 1] % result === 0n)) {\r\n result = 0n;\r\n break;\r\n }\r\n }\r\n\r\n if (result !== 0n) {\r\n break;\r\n }\r\n }\r\n\r\n console.log(result.toString());\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, arr;\r\n let k = 0;\r\n\r\n while (T--) {\r\n k++;\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(BigInt);\r\n solve(N, arr);\r\n if (k === 20) {\r\n console.log('hello');\r\n console.log(arr);\r\n console.log('hello');\r\n }\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let result = BigInt(0);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n result = arr[i];\r\n\r\n for (let j = 1; j < N; ++j) {\r\n if ((arr[j] % result === 0n) === (arr[j - 1] % result === 0n)) {\r\n result = 0n;\r\n break;\r\n }\r\n }\r\n\r\n if (result !== 0n) {\r\n break;\r\n }\r\n }\r\n\r\n console.log(result.toString());\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, K, arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(BigInt);\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let result = BigInt(0);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n result = arr[i];\r\n\r\n for (let j = 1; j < N; ++j) {\r\n if ((arr[j] % result === 0n) === (arr[j - 1] % result === 0n)) {\r\n result = 0n;\r\n break;\r\n }\r\n }\r\n\r\n if (result !== 0n) {\r\n break;\r\n }\r\n }\r\n\r\n console.log(result.toString());\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, K, arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(Number);\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n let result = 0;\r\n\r\n for (let i = 0; i < N; ++i) {\r\n result = arr[i];\r\n\r\n for (let j = 1; j < N; ++j) {\r\n if ((arr[j] % result === 0) === (arr[j - 1] % result === 0)) {\r\n result = 0;\r\n break;\r\n }\r\n }\r\n\r\n if (result !== 0) {\r\n break;\r\n }\r\n }\r\n\r\n console.log(result);\r\n}"}, {"source_code": "const solve = (n,arr)=>{\r\n const gcd = (a,b)=>b===0n ? a : gcd(b,a%b);\r\n let first = [],second = [],k = false,gcD=[];\r\n for(let i=0;iparseInt(a-b));\r\n second.sort((a,b)=>parseInt(a-b));\r\n gcD[0] = first.length>1 ? gcd(first[0],first[1]) : first[0];\r\n gcD[1] = second.length>1 ? gcd(second[0],second[1]) : second[0];\r\n for(let i=0;i<2;i++){\r\n let res = -1n,flag = 1n;\r\n if(gcD[i]!==1n){\r\n for(let j=0;jBigInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n const gcd = (a,b)=>b===0n ? a : gcd(b,a%b);\r\n let first = [],second = [],k = false,gcD=[];\r\n for(let i=0;iparseInt(a-b));\r\n second.sort((a,b)=>parseInt(a-b));\r\n gcD[0] = first.length>1 ? gcd(first[0],first[1]) : first[0];\r\n gcD[1] = second.lenght>1 ? gcd(second[0],second[1]) : second[0];\r\n for(let i=0;i<2;i++){\r\n let res = -1n,flag = 1n;\r\n if(gcD[i]!==1n){\r\n for(let j=0;jBigInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n const gcd = (a,b)=>b===0 ? a : gcd(b,a%b);\r\n let first = [],second = [],k = false,gcD=[];\r\n for(let i=0;ia-b);\r\n second.sort((a,b)=>a-b);\r\n gcD[0] = first.length>1 ? gcd(first[0],first[1]) : first[0];\r\n gcD[1] = second.length>1 ? gcd(second[0],second[1]) : second[0];\r\n for(let i=0;i<2;i++){\r\n let res = -1,flag = 1;\r\n if(gcD[i]!==1){\r\n for(let j=0;jparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n const gcd = (a,b)=>b===0 ? a : gcd(b,a%b);\r\n let first = [],second = [],k = false,gcD=[];\r\n for(let i=0;ia-b);\r\n second.sort((a,b)=>a-b);\r\n gcD[0] = first.length>1 ? gcd(first[0],first[1]) : first[0];\r\n gcD[1] = second.lenght>1 ? gcd(second[0],second[1]) : second[0];\r\n for(let i=0;i<2;i++){\r\n let res = -1,flag = 1;\r\n if(gcD[i]!==1){\r\n for(let j=0;jparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let k = 0; !ans && k < 2; k++) {\r\n\t\t\tlet d = a[k], ok = true;\r\n\t\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\t\tok = a[i] % d == 0n;\r\n\r\n\t\t\t\tif (i&1) ok = !ok;\r\n\t\t\t\tif (k) ok = !ok;\r\n\t\t\t}\r\n\t\t\tans = ok ? d : 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfunction check (d, ar) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (let i = 0; ok && i < ar.length; i++) {\r\n\t\t\t\tif (i%2 == 0) \r\n\t\t\t\t\tok = ar[i] % d == 0n;\r\n\t\t\t\telse\r\n\t\t\t\t\tok = ar[i] % d != 0n;\r\n\t\t\t}\r\n\t\t\treturn ok ? d : 0;\r\n\t\t}\r\n\r\n\t\tconst ans = check(a[0], a) || check(a[1], a.slice(1));\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfunction check (d, ar) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (let i = 0; ok && i < ar.length; i++) {\r\n\t\t\t\tok = i&1 ? ar[i]%d != 0n : ar[i]%d == 0n;\r\n\t\t\t}\r\n\t\t\treturn ok ? d : 0n;\r\n\t\t}\r\n\r\n\t\tconst ans = check(a[0], a) || check(a[1], a.slice(1));\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfunction check (d, ar) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (let i = 0; ok && i < ar.length; i++) {\r\n\t\t\t\tok = i&1 ? ar[i]%d != 0 : ar[i]%d == 0;\r\n\t\t\t}\r\n\t\t\treturn ok ? d : 0;\r\n\t\t}\r\n\r\n\t\tconst ans = check(a[0], a) || check(a[1], a.slice(1));\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "e6c91f6872c4dd845cb7a156aacab7c7"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const min = arr.indexOf(Math.min(...arr));\n const max = arr.indexOf(Math.max(...arr));\n const ans = Math.min(\n Math.max(min + 1, max + 1),\n Math.max(arr.length - min, arr.length - max),\n min + 1 + arr.length - max,\n max + 1 + arr.length - min\n );\n\n console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n", "positive_code": [{"source_code": "var n = parseInt(readline());\r\n while (n--) {\r\n var s = parseInt(readline());\r\n var stones = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var stonesort = [].concat(stones).sort((a, b) => a - b);\r\n var max = stones.indexOf(stonesort[s - 1]);\r\n var min = stones.indexOf(stonesort[0]);\r\n var maxleft = stones.slice(max).length;\r\n var minleft = stones.slice(min).length;\r\n\r\n var maxright = stones.slice(0, max + 1).length;\r\n var minright = stones.slice(0, min + 1).length;\r\n\r\n var middleright = Math.max(maxright, minright);\r\n var middleleft = Math.max(maxleft, minleft);\r\n\r\n var mid = Math.min(maxright, minright);\r\n var midd = Math.min(maxleft, minleft);\r\n var middle = mid + midd;\r\n var ans = Math.min(middleright, middleleft, middle);\r\n print(ans);\r\n }"}, {"source_code": "// A. Stone Game\r\n\r\n\r\nvar l0 = readline();\r\nvar n = +l0;\r\nvar arr = [];\r\nfor (var a = 0; a +v));\r\n}\r\n\r\nfor (var x = 0; x< n; x++) {\r\n var min = Infinity;\r\n var max = 0;\r\n var aIndex;\r\n var bIndex;\r\n for (var y = 0; y< arr[x].length; y++) {\r\n if (arr[x][y] < min) {\r\n min = arr[x][y];\r\n aIndex = y;\r\n }\r\n \r\n if (arr[x][y] > max) {\r\n max = arr[x][y];\r\n bIndex = y;\r\n }\r\n }\r\n \r\n // sort index\r\n var temp = aIndex;\r\n if (aIndex > bIndex) {\r\n aIndex = bIndex;\r\n bIndex = temp;\r\n }\r\n \r\n var t1 = 0;\r\n // 1* Destroy the stones on the left until we destroy the smallest stone. \r\n // Then destroy the stones on the right, until we destroy the largest stone.\r\n t1 = t1 + Math.abs(0 - aIndex) + 1;\r\n t1 = t1 + Math.abs(arr[x].length - bIndex);\r\n \r\n // 2* Destroy the stones on the right until we destroy the smallest stone. \r\n // Then destroy the stones on the left, until we destroy the largest stone.\r\n // ignore it, because I ordered the indexes\r\n var t2 = Infinity\r\n \r\n // 3* Destroy the stones on the left until we destroy both stones.\r\n var t3 = 0\r\n var t3 = t3 + Math.abs(0 - bIndex) + 1;\r\n \r\n // 4* Destroy the stones on the right until we destroy both stones.\r\n var t4 = 0;\r\n var t4 = t4 + Math.abs(arr[x].length - aIndex);\r\n \r\n \r\n print(Math.min(t1,t2,t3,t4));\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n var min = 0, max = 0;\r\n for(j = 0; j < n; j++) {\r\n if(a[j] == 1) min = j + 1;\r\n else if(a[j] == n) max = j + 1;\r\n if(min !== 0 && max !== 0) break;\r\n }\r\n if(n % 2 === 1 && ((min === (n + 1)/2) || (max === (n + 1)/2))) {\r\n print((n + 1)/2);\r\n }\r\n else {\r\n var left = Math.max(min, max);\r\n var right = Math.max(n - min + 1, n - max + 1);\r\n var middle;\r\n if(min < max) middle = min + n - max + 1;\r\n else middle = max + n - min + 1;\r\n print(Math.min(left, right, middle));\r\n }\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\n\r\nwhile(tc--) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(i => parseInt(i));\r\n\r\n var indexMax = arr.indexOf(Math.max(...arr));\r\n var indexMin = arr.indexOf(Math.min(...arr));\r\n\r\n var min = Math.min(indexMax, indexMin); \r\n var max = Math.max(indexMax, indexMin);\r\n\r\n var case1 = max + 1;\r\n var case2 = n - min;\r\n var case3 = min + 1 + n - max;\r\n\r\n print(Math.min(case1, case2, case3));\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t = parseInt(readLine()); // number of test cases\r\n\r\n while (t--) {\r\n let n = parseInt(readLine()); // number of stones\r\n\r\n let a = readLine()\r\n .split(\" \")\r\n .map((x) => parseInt(x)); // array of power of stones\r\n\r\n console.log(getMoves(a));\r\n }\r\n}\r\n\r\nfunction getMoves(a) {\r\n let minPoz = 0;\r\n let maxPoz = 0;\r\n\r\n // find the least and greatest power stone\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > a[maxPoz]) maxPoz = i;\r\n if (a[i] < a[minPoz]) minPoz = i;\r\n }\r\n\r\n let stones = a.length;\r\n\r\n // 1st case\r\n let case1 = minPoz + 1 + stones - maxPoz;\r\n\r\n // 2nd case\r\n let case2 = maxPoz + 1 + stones - minPoz;\r\n\r\n // 3rd case\r\n let case3 = Math.max(minPoz, maxPoz) + 1;\r\n\r\n // 4th case\r\n let case4 = Math.max(stones - maxPoz, stones - minPoz);\r\n\r\n return Math.min(case1, case2, case3, case4);\r\n}\r\n"}, {"source_code": "\r\n\r\nvar readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvar lines = [];\r\nrl.on('line', function(input) {\r\n lines.push(input);\r\n});\r\nrl.on('close', function() {\r\n var t = parseInt(lines[0]);\r\n var l = 1;\r\n for (var i = 0; i < t; i++) {\r\n var n = +lines[l++];\r\n console.log(solve(lines[l++].split(' ').map(Number)));\r\n }\r\n});\r\n\r\n\r\nconst solve = (l) => {\r\n const indexMin = l.indexOf(Math.min(...l));\r\n const indexMax = l.indexOf(Math.max(...l));\r\n\r\n const max = Math.max(indexMin, indexMax);\r\n const min = Math.min(indexMin, indexMax);\r\n\r\n\r\n // CASE 1\r\n const case_1 = max + 1;\r\n\r\n // CASE 2\r\n const case_2 = l.length - min;\r\n\r\n // case 3\r\n const case_3 = min + 1 + l.length - max;\r\n\r\n return Math.min(case_1, case_2, case_3);\r\n};\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet found = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n let ans = Infinity;\n\n found = 0;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === min) {\n found++;\n }\n\n if (arr[i] === max) {\n found++;\n }\n\n if (found === 2) {\n ans = Math.min(ans, i + 1);\n break;\n }\n }\n\n arr.reverse();\n found = 0;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === min) {\n found++;\n }\n\n if (arr[i] === max) {\n found++;\n }\n\n if (found === 2) {\n ans = Math.min(ans, i + 1);\n break;\n }\n }\n\n const firstNumber = Math.min(arr.indexOf(min), arr.indexOf(max)) + 1;\n arr.reverse();\n const secondNumber = Math.min(arr.indexOf(min), arr.indexOf(max)) + 1;\n ans = Math.min(ans, firstNumber + secondNumber);\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let arrLen = +input[z++];\r\n let arr = input[z++].split(' ').map(x=>Number(x));\r\n\r\n let firstIdx = arr.indexOf(1)\r\n let lastIdx = arr.indexOf(arrLen);\r\n let maxIdx = Math.max(firstIdx, lastIdx);\r\n let minIdx = Math.min(firstIdx, lastIdx);\r\n\r\n let option1 = (arrLen - maxIdx) + minIdx + 1;\r\n let option2 = minIdx + (maxIdx - minIdx) + 1;\r\n let option3 = (arrLen - maxIdx) + (arrLen - minIdx - (arrLen - maxIdx));\r\n\r\n console.log(Math.min(option1, option2, option3));\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let arrLen = +input[z++];\r\n let arr = input[z++].split(' ').map(x=>Number(x));\r\n\r\n let firstIdx = arr.indexOf(1);\r\n let lastIdx = arr.indexOf(arrLen);\r\n let maxIdx = Math.max(firstIdx, lastIdx);\r\n let minIdx = Math.min(firstIdx, lastIdx);\r\n\r\n let option1 = (arrLen - maxIdx) + minIdx + 1;\r\n let option2 = minIdx + (maxIdx - minIdx) + 1;\r\n let option3 = (arrLen - maxIdx) + (arrLen - minIdx - (arrLen - maxIdx));\r\n\r\n console.log(Math.min(option1, option2, option3));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const min = Math.min(...a),\r\n max = Math.max(...a);\r\n let mi = a.findIndex(num => num === min),\r\n ma = a.findIndex(num => num === max);\r\n if (mi > ma) [mi, ma] = [ma, mi];\r\n return Math.min(ma + 1, n - mi, mi + 1 + n - ma);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var max = 0, min = 110000000000;\n for(j = 0; j < n; j++){\n max = Math.max(max, k[j]);\n min = Math.min(min, k[j]);\n }\n var lma = 0, lmi = 0;\n for(j = 0; j < n; j++){\n if(k[j] == max){\n lma = j + 1;\n }\n if(k[j] == min){\n lmi = j + 1;\n }\n }\n var rma = n - lma + 1;\n var rmi = n - lmi + 1;\n var a1 = Math.max(rma, rmi);\n var a2 = Math.max(lma, lmi);\n var a3 = Math.min(lma + rmi, rma + lmi);\n console.log(Math.min(a1, Math.min(a2, a3)));\n }\n }\n});"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var n = parseInt(args[2 * i - 1], 10);\r\n var v = args[2 * i].split(\" \").map((n) => parseInt(n, 10));\r\n var a = 0, b = 0;\r\n for (var j = 0; j < n; j++) {\r\n if (v[j] == 1) {\r\n a = j;\r\n }\r\n if (v[j] == n) {\r\n b = j;\r\n }\r\n }\r\n var c = Math.min(a, b) + 1;\r\n var d = Math.max(a, b) + 1;\r\n console.log(Math.min(d, n - c + 1, c + n - d + 1));\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet m = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet mi = a.indexOf(1);\n\t\tlet ma = a.indexOf(m);\n\t\tlet r = [mi + 1, ma + 1, Math.abs(mi - ma), m - mi, m - ma];\n\t\tr.sort((a, b) => a - b);\n\t\tans.push(r[0] + r[1]);\n\t\t\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let n = rl();\r\n let array = numArray(rl());\r\n let step = 0;\r\n\r\n let greatest = array.indexOf(Math.max(...array)) + 1;\r\n let least = array.indexOf(Math.min(...array)) + 1;\r\n let i = 0;\r\n\r\n let dleft = Math.max(least, greatest);\r\n let dright = Math.max(n - greatest, n - least) + 1;\r\n\r\n let dleftRight = n - greatest + least + 1;\r\n let drightLeft = greatest + (n - least) + 1;\r\n\r\n console.log(Math.min(dleft, dright, drightLeft, dleftRight));\r\n }\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var arr = readArray((a, i) => [Number(a), i]);\r\n arr.sort((a, b) => a[0] - b[0]);\r\n var i1 = arr[0][1];\r\n var i2 = arr[n - 1][1];\r\n if (i1 > i2) {\r\n var temp = i1;\r\n i1 = i2;\r\n i2 = temp;\r\n }\r\n var ans1 = n - i2 + i1 + 1;\r\n var ans2 = i2 + 1;\r\n var ans3 = n - i1;\r\n write(Math.min(ans1, Math.min(ans2, ans3)));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "let lineContent = ''\n\nprocess.stdin.on('data', c => lineContent += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = lineContent.split(EOL) /*your input text, split by lines*/\n\n const testNumbers = parseInt(lines[0]);\n\n for (let i = 0; i < testNumbers; i++) {\n const [n] = lines[1 + i * 2].split(\" \").map((e) => parseInt(e));\n const arr = lines[2 + i * 2].split(\" \").map(e => parseInt(e));\n\n console.log(f(n, arr));\n }\n\n})\n\nconst f = (n, arr) => {\n let max = 0, min = 0;\n for (let i = 0; i < n; i++) {\n const curr = arr[i];\n if (arr[max] < curr) {\n max = i;\n }\n if (arr[min] > curr) {\n min = i;\n }\n }\n\n const a = max > min ? max : min;\n const b = max > min ? min : max;\n\n return Math.min(a + 1, n - b, b + 1 + n - a);\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 1 << 30;\r\n\t\tvar L = list.indexOf(1);\r\n\t\tvar R = list.indexOf(N);\r\n\t\tif(L > R){\r\n\t\t\tvar tmp = L;\r\n\t\t\tL = R;\r\n\t\t\tR = tmp;\r\n\t\t}\r\n\t\toutput = Math.min(output, R + 1);\r\n\t\toutput = Math.min(output, N - L);\r\n\t\toutput = Math.min(output, L + (N - R) + 1);\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n \nfunction solve(nums) {\n const max = Math.max(...nums)\n const min = Math.min(...nums)\n let a = nums.indexOf(max)\n let b = nums.indexOf(min)\n if (a > b) {\n const t = a\n a = b\n b = t\n }\n\n const t1 = b + 1\n const t2 = nums.length - a\n const t3 = a + 1 + nums.length - b\n const t4 = nums.length - a + b + 1\n return Math.min(t1, t2, t3, t4)\n}\n"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n var min = 101;\n var a;\n var max = -1;\n var b;\n\n a.forEach((el, i) => {\n if (el > max) {\n max = el;\n a = i;\n } \n if (el < min) {\n min = el;\n b = i;\n }\n })\n \n if (b < a) {\n var tt = a;\n a = b;\n b = tt;\n }\n\n print(Math.min(b + 1, n - a, n - b + a + 1));\n} "}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var x = +readline();\r\n var nums = readNumArray();\r\n var maxInd = 0;\r\n var minInd = 0;\r\n for (var j = 1; j < x; j++) {\r\n if (nums[j] > nums[maxInd]) {\r\n maxInd = j;\r\n }\r\n if (nums[j] < nums[minInd]) {\r\n minInd = j;\r\n }\r\n }\r\n\r\n var mnInd = maxInd > minInd ? minInd : maxInd;\r\n var mxInd = maxInd < minInd ? minInd : maxInd\r\n var n12 = mxInd - mnInd - 1;\r\n var n1 = mnInd;\r\n var n2 = nums.length - mxInd - 1;\r\n var max = Math.max(n1, n2, n12);\r\n print(nums.length - max);\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var numsCount = Number(readline());\r\n var nums = readline().split(\" \").map(x => Number(x));\r\n\r\n var indicies = [0, 0];\r\n for (var i = 0; i < nums.length; ++i) {\r\n if (nums[i] < nums[indicies[0]]) {\r\n indicies[0] = i;\r\n }\r\n\r\n if (nums[i] > nums[indicies[1]]) {\r\n indicies[1] = i\r\n }\r\n }\r\n \r\n if (indicies[0] > indicies[1]) {\r\n var tmp = indicies[0];\r\n indicies[0] = indicies[1];\r\n indicies[1] = tmp;\r\n }\r\n\r\n var distances = [\r\n indicies[0] + 1,\r\n nums.length - indicies[1]\r\n ];\r\n\r\n var indexDistance = indicies[1] - indicies[0];\r\n print(Math.min(distances[0] + indexDistance, distances[1] + indexDistance, distances[0] + distances[1]))\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\nwhile(tc--) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(i => parseInt(i));\r\n var indexMax = arr.indexOf(Math.max(...arr));\r\n var indexMin = arr.indexOf(Math.min(...arr));\r\n\r\n var min = Math.min(indexMax, indexMin); \r\n var max = Math.max(indexMax, indexMin);\r\n\r\n var case1 = max + 1;\r\n var case2 = n - min;\r\n var case3 = min + 1 + n - max;\r\n\r\n print(Math.min(case1, case2, case3));\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t = parseInt(readLine()); // number of test cases\r\n\r\n while (t--) {\r\n let n = parseInt(readLine()); // number of stones\r\n\r\n let a = readLine()\r\n .split(\" \")\r\n .map((x) => parseInt(x)); // array of power of stones\r\n\r\n console.log(getMoves(a));\r\n }\r\n}\r\n\r\nfunction getMoves(a) {\r\n let minPoz = 0;\r\n let maxPoz = 0;\r\n\r\n // find the least and greatest power stone\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > a[maxPoz]) maxPoz = i;\r\n if (a[i] < a[minPoz]) minPoz = i;\r\n }\r\n\r\n let stones = a.length;\r\n\r\n // 1st case\r\n let case1 = minPoz + 1 + stones - maxPoz;\r\n\r\n // 2nd case\r\n let case2 = maxPoz + 1 + stones - minPoz;\r\n\r\n // 3rd case\r\n let case3 = Math.max(minPoz, maxPoz);\r\n\r\n return Math.min(case1, case2, case3);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t = parseInt(readLine()); // number of test cases\r\n\r\n while (t--) {\r\n let n = parseInt(readLine()); // number of stones\r\n\r\n let a = readLine()\r\n .split(\" \")\r\n .map((x) => parseInt(x)); // array of power of stones\r\n\r\n console.log(getMoves(a));\r\n }\r\n}\r\n\r\nfunction getMoves(a) {\r\n let minPoz = 0;\r\n let maxPoz = 0;\r\n\r\n // find the least and greatest power stone\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] > a[maxPoz]) maxPoz = i;\r\n if (a[i] < a[minPoz]) minPoz = i;\r\n }\r\n\r\n if (minPoz <= Math.abs(a.length / 2) && maxPoz <= Math.abs(a.length / 2))\r\n return Math.max(minPoz + 1, maxPoz + 1);\r\n\r\n if (minPoz >= Math.abs(a.length / 2) && maxPoz >= Math.abs(a.length / 2))\r\n return Math.max(a.length - minPoz, a.length - maxPoz);\r\n\r\n if (\r\n (minPoz <= Math.abs(a.length / 2) && maxPoz >= Math.abs(a.length / 2)) ||\r\n (minPoz >= Math.abs(a.length / 2) && maxPoz <= Math.abs(a.length / 2))\r\n ) {\r\n return (\r\n Math.min(minPoz + 1, maxPoz + 1) +\r\n Math.min(a.length - minPoz, a.length - maxPoz)\r\n );\r\n }\r\n}\r\n"}, {"source_code": "\r\n\r\nvar readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvar lines = [];\r\nrl.on('line', function(input) {\r\n lines.push(input);\r\n});\r\nrl.on('close', function() {\r\n var t = parseInt(lines[0]);\r\n var l = 1;\r\n for (var i = 0; i < t; i++) {\r\n var n = +lines[l++]\r\n console.log(solve(lines[l++].split(' ').map(Number)));\r\n }\r\n});\r\n\r\n\r\nconst solve = (l) => {\r\n let lowest = l.indexOf(Math.min(...l)) + 1;\r\n let highest = l.indexOf(Math.max(...l)) + 1;\r\n\r\n const mid = Math.ceil(l.length/2);\r\n console.log(lowest, highest, mid);\r\n\r\n let num = Number.POSITIVE_INFINITY;\r\n\r\n // CASE 1\r\n num = Math.min(num, Math.max(lowest, highest));\r\n\r\n // CASE 2\r\n const reveseL = l.reverse();\r\n let rightLowest = reveseL.indexOf(Math.min(...reveseL)) + 1 ;\r\n let rightHighest = reveseL.indexOf(Math.max(...reveseL)) + 1;\r\n num = Math.min(num, Math.max(rightLowest, rightHighest));\r\n\r\n // case 3\r\n const left = Math.min(lowest, rightLowest);\r\n const right = Math.min(highest, rightHighest);\r\n\r\n num = Math.min(num, left + right);\r\n\r\n return num;\r\n};"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n var min = 101;\n var a;\n var max = -1;\n var b;\n\n a.forEach((el, i) => {\n if (el > max) {\n max = el;\n a = i;\n } \n if (el < min) {\n min = el;\n b = i;\n }\n })\n \n if (b < a) {\n var tt = a;\n a = b;\n b = tt;\n }\n\n\n var ans;\n var mid = parseInt((n - 1) / 2);\n\n\n if ((a < mid && b < mid) || (a > mid && b > mid)) {\n ans = Math.min(Math.max(a, b), n - 1- Math.min(a, b)) + 1; \n }\n else {\n ans = Math.min(a + n - b + 1, b + 1, n - a + 1);\n }\n\n print(ans);\n\n\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n var min = 101;\n var a;\n var max = -1;\n var b;\n\n a.forEach((el, i) => {\n if (el > max) {\n max = el;\n a = i;\n } \n if (el < min) {\n min = el;\n b = i;\n }\n })\n \n if (b < a) {\n var tt = a;\n a = b;\n b = tt;\n }\n\n var ans;\n var mid = parseInt((n - 1) / 2);\n\n if ((a < mid && b < mid) || (a > mid && b > mid)) {\n ans = Math.min(Math.max(a, b), n - 1- Math.min(a, b)) + 1; \n }\n else {\n var r = Math.min((b - a), (n - b));\n ans = a + (r > 0? r + 1 : r);\n }\n\n print(ans);\n\n\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n var min = 101;\n var a;\n var max = -1;\n var b;\n\n a.forEach((el, i) => {\n if (el > max) {\n max = el;\n a = i;\n } \n if (el < min) {\n min = el;\n b = i;\n }\n })\n \n if (b < a) {\n var tt = a;\n a = b;\n b = tt;\n }\n\n\n var ans;\n var mid = parseInt((n - 1) / 2);\n\n\n if ((a < mid && b < mid) || (a > mid && b > mid)) {\n ans = Math.min(Math.max(a, b) + 1, n - Math.max(a, b) + 1); \n }\n else {\n var r = Math.min((b - a), (n - b));\n ans = a + (r > 0? r + 1 : r);\n }\n\n print(ans);\n\n\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n var min = 101;\n var a;\n var max = -1;\n var b;\n\n a.forEach((el, i) => {\n if (el > max) {\n max = el;\n a = i;\n } \n if (el < min) {\n min = el;\n b = i;\n }\n })\n \n if (b < a) {\n var tt = a;\n a = b;\n b = tt;\n }\n\n\n var ans;\n var mid = parseInt((n - 1) / 2);\n\n\n if ((a < mid && b < mid) || (a > mid && b > mid))\n ans = Math.min(Math.max(a, b) + 1, n - Math.max(a, b) + 1); \n else\n ans = a + Math.min((b - a), (n - b)) + 1;\n\n print(ans);\n\n\n} "}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var x = +readline();\r\n var nums = readNumArray();\r\n var maxInd = nums[0];\r\n var minInd = nums[0];\r\n for (var j = 0; j < x; j++) {\r\n if (nums[j] > nums[maxInd]) {\r\n maxInd = j;\r\n }\r\n if (nums[j] < nums[minInd]) {\r\n minInd = j;\r\n }\r\n }\r\n\r\n var mnInd = maxInd > minInd ? minInd : maxInd;\r\n var mxInd = maxInd < minInd ? minInd : maxInd\r\n var n12 = mxInd - mnInd - 1;\r\n var n1 = mnInd;\r\n var n2 = nums.length - mxInd - 1;\r\n var max = Math.max(n1, n2, n12);\r\n print(nums.length - max);\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var x = +readline();\r\n var nums = readNumArray();\r\n var maxInd = nums[0];\r\n var minInd = nums[0];\r\n for (var j = 0; j < x; j++) {\r\n if (nums[j] > nums[maxInd]) {\r\n maxInd = j;\r\n }\r\n if (nums[j] < nums[minInd]) {\r\n minInd = j;\r\n }\r\n }\r\n\r\n var mnInd = maxInd > minInd ? minInd : maxInd;\r\n var mxInd = maxInd < minInd ? minInd : maxInd\r\n var n12 = mxInd - mnInd;\r\n var n1 = mnInd + 1;\r\n var n2 = Math.abs(nums.length - mxInd);\r\n var max = Math.max(n1, n2, n12);\r\n print(nums.length - max + 1);;\r\n }\r\n}\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var x = +readline();\r\n var nums = readNumArray();\r\n var maxInd = nums[0];\r\n var minInd = nums[0];\r\n for (var j = 0; j < x; j++) {\r\n if (nums[j] > nums[maxInd]) {\r\n maxInd = j;\r\n }\r\n if (nums[j] < nums[minInd]) {\r\n minInd = j;\r\n }\r\n }\r\n\r\n var mnInd = maxInd > minInd ? minInd : maxInd;\r\n var mxInd = maxInd < minInd ? minInd : maxInd\r\n var n12 = Math.abs(mxInd - mnInd - 1);\r\n var n1 = mnInd;\r\n var n2 = Math.abs(nums.length - mxInd - 1);\r\n var max = Math.max(n1, n2, n12);\r\n print(nums.length - max);;\r\n }\r\n\r\n}\r\n\r\nmain();"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var numsCount = Number(readline());\r\n var nums = readline().split(\" \").map(x => Number(x));\r\n\r\n var indicies = [0, 0];\r\n for (var i = 0; i < nums.length; ++i) {\r\n if (nums[i] < nums[indicies[0]]) {\r\n indicies[0] = i;\r\n }\r\n\r\n if (nums[i] > nums[indicies[1]]) {\r\n indicies[1] = i\r\n }\r\n }\r\n\r\n indicies.sort();\r\n var distances = [\r\n indicies[0] + 1,\r\n nums.length - indicies[1]\r\n ];\r\n\r\n var indexDistance = indicies[1] - indicies[0];\r\n print(Math.min(distances[0] + indexDistance, distances[1] + indexDistance, distances[0] + distances[1]))\r\n}"}], "src_uid": "d5fc2bc618dd9d453a5e7ae30ccb73f3"} {"source_code": " var n = parseInt(readline());\n var last = Infinity;\n var res = 'maybe';\n for(var i = 0; i < n; i += 1) {\n var tmp = readline().split(' ').map(x => parseInt(x));\n if(tmp[0] !== tmp[1]) {\n res = 'rated';\n }\n if(res === 'maybe') {\n if(tmp[0] > last) {\n res = 'unrated'\n }\n }\n last = tmp[0];\n }\n print(res);", "positive_code": [{"source_code": "var number = readline();\nvar formerStandings = [];\nvar nextStandings = [];\nvar flag2 = true;\nfor(var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\n\nfunction array2d(r,c) {\n let ans =[];\n for(let i = 0; i < r; i++) {\n let rowElements = [];\n for(let j = 0; j < c; j++) {\n rowElements.push(0);\n }\n ans.push(rowElements);\n }\n return ans;\n}\nfunction max(a,b){\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let [n] = readint();\n let changed = false;\n let sorted = true;\n let [prevA,prevB] = [5000,5000];\n while(n--) {\n let [a,b] = readint();\n if(a != b) changed = true;\n if(prevA < a) sorted = false;\n prevA = a;\n prevB = b;\n }\n if(changed) print(\"rated\");\n else if(!sorted) print(\"unrated\");\n else print(\"maybe\");\n \n\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet prev = Infinity;\nlet ans = 'maybe';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (b > a) {\n ans = 'rated';\n }\n\n if (a !== b) {\n ans = 'rated';\n }\n\n if (prev < a && ans !== 'rated') {\n ans = 'unrated';\n }\n else {\n prev = a;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": " function cal() {\n var n = +readline();\n var temp = 0;\n var maybe = true;\n var res = '';\n for (var i = 0; i < n; i++) {\n var token = readline().split(' ');\n var numA = +token[0];\n var numB = +token[1];\n\n if (numA != numB) {\n print(\"rated\");\n return;\n }\n\n if (temp != 0 && numA > temp)\n maybe = false;\n temp = numA;\n\n }\n\n if (maybe)\n print(\"maybe\");\n else\n print(\"unrated\");\n\n }\n cal();"}, {"source_code": " var n = parseInt(readline());\n var last = Infinity;\n var res = 'maybe';\n for(var i = 0; i < n; i += 1) {\n var tmp = readline().split(' ').map(x => parseInt(x));\n if(tmp[0] !== tmp[1]) {\n res = 'rated';\n }\n if(res === 'maybe') {\n if(tmp[0] > last) {\n res = 'unrated'\n }\n }\n last = tmp[0];\n }\n print(res);"}, {"source_code": "var rounds = parseInt(readline());\n\nvar rated = false;\nvar unrated = false;\n\nvar before;\nvar after;\n\nfor (var i = 0; i < rounds; i++) {\n var values = readline().split(\" \").map(Number);\n if (values[0] > before || values[1] > after) {\n unrated = true;\n }\n \n before = values[0];\n after = values[1];\n \n if (before !== after) {\n rated = true;\n break;\n }\n}\n\nif (rated) {\n print('rated');\n} else if (unrated) {\n print('unrated');\n} else {\n print('maybe');\n}"}], "negative_code": [{"source_code": "var number = readline();\nvar formerStandings = [];\nvar nextStandings = [];\nvar flag2 = true;\nfor(var i=0; i temp) \n maybe = false;\n temp = numA;\n\n }\n if (res != '') {\n print(res);\n\n } else\n if (maybe) \n print(\"maybe\");\n else \n print(\"unrated\");\n "}, {"source_code": "function cal() {\n var n = +readline();\n var temp = 0;\n var maybe = true;\n var res = '';\n for (var i = 0; i < n; i++) {\n var token = readline().split(' ');\n var numA = token[0];\n var numB = token[1];\n\n if (numA != numB) {\n print(\"rated\");\n return;\n }\n\n if (temp != 0 && numA > temp)\n maybe = false;\n temp = numA;\n\n }\n\n if (maybe)\n print(\"maybe\");\n else\n print(\"unrated\");\n\n }\n cal();"}, {"source_code": "function cal() {\n var n = +readline();\n var temp = 0;\n var maybe = true;\n var res = '';\n for (var i = 0; i < n; i++) {\n var token = readline().split(' ');\n var numA = token[0];\n var numB = token[1];\n\n if (numA != numB) {\n res = \"rated\";\n return;\n }\n\n if (temp != 0 && numA > temp)\n maybe = false;\n temp = numA;\n\n }\n\n if (maybe)\n print(\"maybe\");\n else\n print(\"unrated\");\n\n }\n cal();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet prev = Infinity;\nlet ans = 'maybe';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (b > a) {\n ans = 'rating';\n }\n\n if (prev < a) {\n ans = 'unrated';\n }\n else {\n prev = a;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet prev = Infinity;\nlet ans = 'maybe';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (b > a) {\n ans = 'rating';\n }\n\n if (prev < a && ans !== 'rating') {\n ans = 'unrated';\n }\n else {\n prev = a;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet prev = Infinity;\nlet ans = 'maybe';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (b > a) {\n ans = 'rated';\n }\n\n if (prev < a && ans !== 'rated') {\n ans = 'unrated';\n }\n else {\n prev = a;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}], "src_uid": "88686e870bd3bfbf45a9b6b19e5ec68a"} {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n const [a, b, x, y] = data;\n return Math.max(b*x, a*y, a*(b-y-1), b*(a-x-1));\n\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n const inputStrings = data.split('\\n');\n const n = parseInt(inputStrings[0], 10);\n const place = ([a,b,x,y]) => Math.max( (a - x - 1) * b, x * b, a * (b - y - 1), a * y);\n let answ = '';\n for (let i = 1; i <= n; i++) {\n const inputArr = inputStrings[i].split(' ').map(Number);\n answ += place(inputArr)+'\\n';\n }\n process.stdout.write(answ);\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n const inputStrings = data.split('\\n');\n const n = parseInt(inputStrings[0], 10);\n const place = ([a,b,x,y]) => Math.max( (a - x - 1) * b, x * b, a * (b - y - 1), a * y);\n for (let i = 1; i <= n; i++) {\n const inputArr = inputStrings[i].split(' ').map(Number);\n process.stdout.write( place(inputArr)+'\\n' );\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b, x, y] = d.split(\" \").map(Number);\n const ans = Math.max(y * a, (b - y - 1) * a, x * b, (a - x - 1) * b);\n\n if (Number.isInteger(ans)) {\n console.log(ans);\n }\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n const sq = [ (a-x-1) * (b), (b-y-1) * (a), (x)*b, (y) * a ]\n console.log(Math.max.apply(null, sq));\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function main(rawInput) {\n var lines = rawInput.split(\"\\n\");\n var tests = parseInt(lines.shift(), 10);\n for (var i = 0; i < tests; i++) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); }), w = _a[0], h = _a[1], x = _a[2], y = _a[3];\n console.log(solve(w, h, x, y));\n }\n}\nfunction solve(w, h, x, y) {\n return [\n w * (y),\n w * (h - (y + 1)),\n h * (x),\n h * (w - (x + 1))\n ].reduce(function (a, v) { return a > v ? a : v; });\n}\n(function () {\n var s = \"\";\n process.stdin.on(\"data\", function (d) { return s += d; });\n process.stdin.on(\"end\", function () { return main(s); });\n})();\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let r = [];\n for(let i = 0; i < t; i++) {\n let [a, b, x, y] = nl.nums();\n let mx = Math.max(x, a - x - 1) * b;\n let my = Math.max(y, b - y - 1) * a;\n r.push(Math.max(mx, my));\n }\n console.log(r.join('\\n'));\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "const getSquare = ([a, b, x, y]) => Math.max(\n x * b,\n (a - (x + 1)) *b,\n a * y,\n a * (b - (y + 1))\n);\n\nconst main = (data) => {\n const n = +data[0];\n\n for (let i = 1; i <= n; i++) {\n console.log(getSquare(data[i].split(' ').map(x => +x)));\n }\n};\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});\n"}, {"source_code": "r=readline;for(k=r();k--;print(Math.max(b*c,b*(a-c-1),a*y,a*(b-y-1)))){x=r().split(\" \");a=x[0];b=x[1];c=x[2];y=x[3]}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var x = one[2];\n var y = one[3];\n var list = [(b - y - 1) * a, y * a, b * (a - x - 1), b * x];\n output[i] = Math.max.apply(null, list);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "var toInt = x =>parseInt(x);\n\nvar t = parseInt(readline());\n\nfor(var tt=0;tt {\n let inputStrings = inputStdin.split('\\n');\n const n = parseInt(inputStrings[0], 10);\n for (let i = 1; i < inputStrings.length; i++) {\n const inputArr = inputStrings[i].trim().split(' ');\n if (inputArr.length !== 4) break;\n answer += place(inputArr)+'\\n';\n }\n});\nprocess.stdin.on('end', _ => {\n process.stdout.write( answer );\n});\nfunction place(arr) {\n let aW = 0, bW = 0, a = arr[0], b = arr[1], x = arr[2], y = arr[3];\n if (x >= y) {\n bW = b;\n if ( 0.5 * a > x ) {\n aW = a - x - 1;\n } else {\n aW = a;\n }\n } else {\n aW = a;\n if ( 0.5 * b > y ) {\n bW = b - y - 1;\n } else {\n bW = y;\n }\n }\n return aW * bW;\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b, x, y] = d.split(\" \").map(Number);\n const ans = Math.max(y * a, (b - y - 1) * a, x * b, (a - x - 1) * b);\n\n console.log(ans);\n c++;\n});\n"}], "src_uid": "ccb7b8c0c389ea771f666c236c1cba5f"} {"source_code": "t = +readline();\nwhile(t--) {\n input = readline();\n res = input.length;\n mn = 0;\n cur = 0;\n for(i = 0;i < input.length; i++) {\n if (input[i] === '+') {\n cur = cur + 1;\n } else\n cur = cur - 1;\n if (cur < mn) {\n mn = cur;\n res += i + 1;\n }\n }\n print(res);\n \n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst s2i = s => parseInt(s, 10);\n\nfunction main() {\n let T = s2i(readLine());\n let out = '';\n while (T--) {\n const s = readLine()\n let sum = 0;\n let res = 0;\n for (let i = 0, l = s.length; i < l; i++) {\n const c = s.charAt(i);\n res++;\n if (c === '+') {\n sum++;\n }\n else {\n sum--;\n if (sum < 0) {\n sum = 0;\n res += i + 1;\n }\n }\n }\n\n out += res + '\\n'\n }\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n if(n % 2 === 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}\n\nfunction D(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = new Array(n);\n for(let i = 0; i < n; i++){\n let mod = a[i] % k;\n if(mod !== 0){\n mod = k-mod;\n }\n b[i] = [a[i], mod];\n }\n b.sort((c,d) => c[1]-d[1]);\n let count = 0;\n let x = 0;\n for(let i = 0; i < n; i++){\n if((b[i][0] + x) % k === 0){\n x += 1;\n count += 1;\n }else{\n let d = k-((b[i][0]+x)%k);\n x += d+1;\n count += d+1;\n }\n }\n\n console.log(count);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let s = readline().split('');\n let res = 0;\n let x = 0;\n for(let i = 0; i < s.length; i++){\n if(s[i] === '+') x++;\n if(s[i] === '-') x--;\n\n if(x < 0){\n res += i+1;\n x = 0;\n }\n }\n\n console.log(res + s.length);\n }\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += getWinner(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += getWinner(input) + '\\n'\n }\n lineCount++\n});\n\n// console.log(getWinner('++----++-'))\n\nfunction getWinner(str) {\n var sum = 0;\n var minsum = 0;\n var res = 0;\n var minindex = 0;\n for (var i = 0; i < str.length; i++) {\n if (str[i] == '+') {\n sum += 1\n }\n else {\n sum -= 1\n }\n if (sum < minsum) {\n res += i + 1\n minsum = sum\n minindex = i\n }\n }\n res += i\n return res\n}"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n var s = read();\n var sum = 0;\n var wait = -1;\n var ans = s.length;\n for (var i = 0; i < s.length; i++) {\n sum += s[i] === '+' ? 1 : -1;\n if (sum === wait) {\n ans += i + 1;\n wait--;\n }\n }\n write(ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var Tc = parseInt(readline());\nwhile (Tc-- > 0) {\n var s = readline();\n var sum = 0;\n var m = -1;\n var ans = s.length;\n for (var i = 0; i < s.length; i++) {\n sum += s[i] === \"+\" ? 1 : -1;\n if (sum === m) {\n ans += i + 1;\n m--;\n }\n }\n print(ans);\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n if(n % 2 === 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}\n\nfunction D(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = new Array(n);\n for(let i = 0; i < n; i++){\n let mod = a[i] % k;\n if(mod !== 0){\n mod = k-mod;\n }\n b[i] = [a[i], mod];\n }\n b.sort((c,d) => c[1]-d[1]);\n let count = 0;\n let x = 0;\n for(let i = 0; i < n; i++){\n if((b[i][0] + x) % k === 0){\n x += 1;\n count += 1;\n }else{\n let d = k-((b[i][0]+x)%k);\n x += d+1;\n count += d+1;\n }\n }\n\n console.log(count);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let s = readline().split('');\n let a = new Array(10);\n let x = 0;\n for(let i = 0; i < s.length; i++){\n if(s[i] === '+')\n x += 1;\n else\n x -= 1;\n \n if(x < 0){\n if(a[-1*x-1] === undefined)\n a[-1*x-1] = i+1;\n }\n }\n\n let res = 0;\n for(let i = 0; i < Math.abs(x); i++){\n if(a[i])\n res += a[i];\n }\n\n console.log(res + s.length);\n }\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += getWinner(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += getWinner(input) + '\\n'\n }\n lineCount++\n});\n\n// console.log(getWinner('++--+-'))\n\nfunction getWinner(str) {\n var sum = 0;\n var minsum = 0;\n var res = 0;\n var minindex = 0;\n for (var i = 0; i < str.length; i++) {\n if (str[i] == '+') {\n sum += 1\n }\n else {\n sum -= 1\n }\n // console.log(minsum, sum)\n if(sum= 0 ) {\n b = this.brr[ i - 1 ] ;\n }\n if( i + this.m - 1 < this.n ) {\n a = this.brr[ i + this.m - 1 ] - b ;\n c = hand + a ;\n this.memo[ i + this.m - 1 ][ cur ] = Math.max( this.memo[ i + this.m - 1 ][ cur ] , c ) ;\n }\n hand = Math.max( hand , this.memo[ i ][ other ] ) ;\n }\n cur = ( cur + 1 ) % 2 ;\n other = ( other + 1 ) % 2 ;\n }\n for( i = 0 ; i < this.n ; i++ ) {\n res = Math.max( res , this.memo[ i ][ other ] ) ;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( 0 );\n }\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 5010;\n this.lim2 = 2;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}], "negative_code": [{"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , fl , a , b , c , d , e , cur , hand , other;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n if( i == 0 ) {\n this.brr[ i ] = this.arr[ i ];\n }\n else {\n this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];\n }\n }\n cur = 0 ;\n other = 1 ;\n for( j = 0 ; j < this.k ; j++ ) {\n hand = 0 ;\n this.memo[ i ][ cur ] = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n b = 0 ;\n if( i - 1 >= 0 ) {\n b = this.brr[ i - 1 ] ;\n }\n if( i + this.m - 1 < this.n ) {\n a = this.brr[ i + this.m - 1 ] - b ;\n c = hand + a ;\n this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;\n }\n hand = Math.max( hand , this.memo[ i ][ other ] ) ;\n }\n cur = ( cur + 1 ) % 2 ;\n other = ( other + 1 ) % 2 ;\n }\n for( i = 0 ; i < this.n ; i++ ) {\n res = Math.max( res , this.memo[ i ][ other ] ) ;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( 0 );\n }\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 5010;\n this.lim2 = 2;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , fl , a , b , c , d , e;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n if( i == 0 ) {\n this.brr[ i ] = this.arr[ i ];\n }\n else {\n this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];\n }\n }\n e = 0;\n while( true ) {\n c = -1;\n d = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = 0;\n b = 0;\n for( j = i ; j < i + this.m ; j++ ) {\n if( this.vis[ j ] == 1 ) {\n break;\n }\n b += this.arr[ j ];\n a++;\n }\n if( a == this.m ) {\n if( b > c ) {\n d = i;\n c = b;\n }\n }\n }\n if( c == -1 ) {\n break;\n }\n for( j = d ; j < d + this.m ; j++ ) {\n this.vis[ j ] = 1;\n }\n res += c;\n e++;\n if( e >= this.k ) {\n break;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , fl , a , b , c , d , e , cur , hand , other;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n if( i == 0 ) {\n this.brr[ i ] = this.arr[ i ];\n }\n else {\n this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];\n }\n }\n cur = 0 ;\n other = 1 ;\n for( j = 0 ; j < this.k ; j++ ) {\n hand = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.memo[ i ][ cur ] = 0 ;\n b = 0 ;\n if( i - 1 >= 0 ) {\n b = this.brr[ i - 1 ] ;\n }\n if( i + this.m - 1 < this.n ) {\n a = this.brr[ i + this.m - 1 ] - b ;\n c = hand + a ;\n this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;\n }\n hand = Math.max( hand , this.memo[ i ][ other ] ) ;\n }\n cur = ( cur + 1 ) % 2 ;\n other = ( other + 1 ) % 2 ;\n }\n for( i = 0 ; i < this.n ; i++ ) {\n res = Math.max( res , this.memo[ i ][ other ] ) ;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( 0 );\n }\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 5010;\n this.lim2 = 2;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , fl , a , b , c , d , e , cur , hand , other;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n if( i == 0 ) {\n this.brr[ i ] = this.arr[ i ];\n }\n else {\n this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];\n }\n }\n cur = 0 ;\n other = 1 ;\n for( j = 0 ; j < this.k ; j++ ) {\n hand = 0 ;\n this.memo[ i ][ cur ] = this.memo[ i ][ other ] ;\n for( i = 0 ; i < this.n ; i++ ) {\n b = 0 ;\n if( i - 1 >= 0 ) {\n b = this.brr[ i - 1 ] ;\n }\n if( i + this.m - 1 < this.n ) {\n a = this.brr[ i + this.m - 1 ] - b ;\n c = hand + a ;\n this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;\n }\n hand = Math.max( hand , this.memo[ i ][ other ] ) ;\n }\n cur = ( cur + 1 ) % 2 ;\n other = ( other + 1 ) % 2 ;\n }\n for( i = 0 ; i < this.n ; i++ ) {\n res = Math.max( res , this.memo[ i ][ 0 ] ) ;\n res = Math.max( res , this.memo[ i ][ 1 ] ) ;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.vis = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.vis.push( 0 );\n this.adj_list.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( 0 );\n }\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 5010;\n this.lim2 = 2;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}], "src_uid": "ee3c228cc817536bf6c10ea4508d786f"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e10;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst t = rna();\r\n\r\n\t\tconst tmps = Array(n).fill(INF);\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\t--a[i];\r\n\t\t\ttmps[a[i]] = t[i];\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n).fill(INF); ans[-1] = ans[n] = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = Math.min(ans[i-1] + 1, tmps[i]);\r\n\t\t}\r\n\t\tfor (let i = n-1; i >= 0; i--) {\r\n\t\t\tans[i] = Math.min(ans[i], ans[i+1] + 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.slice(0, n).join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e10;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst t = rna();\r\n\r\n\t\tconst ans = Array(n).fill(INF);\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\t--a[i]; ans[a[i]] = t[i];\r\n\t\t}\r\n\r\n\t\tans[-1] = ans[n] = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = Math.min(ans[i], ans[i-1] + 1);\r\n\t\t}\r\n\t\tfor (let i = n-1; i >= 0; i--) {\r\n\t\t\tans[i] = Math.min(ans[i], ans[i+1] + 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.slice(0, n).join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e10;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst t = rna();\r\n\r\n\t\tconst tmps = Array(n).fill(INF);\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\t--a[i];\r\n\t\t\ttmps[a[i]] = t[i];\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0, cur = INF; i < n; i++) {\r\n\t\t\tcur = Math.min(++cur, tmps[i]);\r\n\t\t\tans[i] = cur;\r\n\t\t}\r\n\t\tfor (let i = n-1, cur = INF; i >= 0; i--) {\r\n\t\t\tcur = Math.min(++cur, tmps[i]);\r\n\t\t\tans[i] = Math.min(cur, ans[i]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nclass FixedDeque {\r\n constructor(half_size) {\r\n this.ary = Array(half_size * 2 + 1).fill(undefined);\r\n this.head = this.tail = half_size;\r\n }\r\n first() {\r\n return this.head === this.tail ? undefined : this.ary[this.head];\r\n }\r\n last() {\r\n return this.head === this.tail ? undefined : this.ary[this.tail - 1];\r\n }\r\n at(i) {\r\n return this.head + i < this.tail ? this.ary[this.head + i] : undefined;\r\n }\r\n isEmpty() {\r\n return this.head === this.tail;\r\n }\r\n unshift(value) {\r\n this.ary[--this.head] = value;\r\n }\r\n shift() {\r\n return this.head === this.tail ? undefined : this.ary[this.head++];\r\n }\r\n push(value) {\r\n this.ary[this.tail++] = value;\r\n }\r\n pop() {\r\n return this.head === this.tail ? undefined : this.ary[--this.tail];\r\n }\r\n toArray() {\r\n return this.ary.slice(this.head, this.tail);\r\n }\r\n [Symbol.iterator]() {\r\n let pos = this.head;\r\n const tail = this.tail;\r\n const ary = this.ary;\r\n return {\r\n next() {\r\n const done = pos === tail;\r\n return {\r\n value: done ? undefined : ary[pos++],\r\n done,\r\n };\r\n },\r\n };\r\n }\r\n}\r\nclass Queue {\r\n constructor() {\r\n this.elems = [];\r\n this.head = 0;\r\n }\r\n push(elem) {\r\n this.elems.push(elem);\r\n }\r\n dequeue() {\r\n if (this.head < this.elems.length) {\r\n return this.elems[this.head++];\r\n }\r\n return undefined;\r\n }\r\n isEmpty() {\r\n return this.head >= this.elems.length;\r\n }\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const q = input.number();\r\n const ans = Array(q);\r\n for (let i = 0; i < q; i++) {\r\n const n = input.number();\r\n const k = input.number();\r\n const A = Array(k);\r\n for (let j = 0; j < k; j++) {\r\n A[j] = input.number() - 1;\r\n }\r\n const T = input.numbers(k);\r\n const cools = Array(k);\r\n for (let j = 0; j < k; j++) {\r\n cools[j] = { a: A[j], t: T[j] };\r\n }\r\n cools.sort((a, b) => a.a - b.a);\r\n for (let j = 0; j < k; j++) {\r\n A[j] = cools[j].a;\r\n T[j] = cools[j].t;\r\n }\r\n const lefts = new FixedDeque(k + 1);\r\n let right = Infinity;\r\n const rights = array(n, Infinity);\r\n for (let j = 0; j < k; j++) {\r\n rights[A[j]] = T[j] - A[j];\r\n const y = A[j] + T[j];\r\n // console.log({ i: A[j], y })\r\n while (!lefts.isEmpty() && lefts.last().y > y) {\r\n lefts.pop();\r\n }\r\n lefts.push({ i: A[j], y });\r\n }\r\n const ts = Array(n);\r\n for (let j = 0; j < n; j++) {\r\n let min = Infinity;\r\n const left = lefts.first();\r\n if (left !== undefined) {\r\n min = left.y - j;\r\n }\r\n if (right !== Infinity) {\r\n min = Math.min(min, right + j);\r\n }\r\n // console.log({ j, left, right, min })\r\n ts[j] = min;\r\n if (left !== undefined && left.i === j) {\r\n lefts.shift();\r\n }\r\n if (rights[j] < right) {\r\n right = rights[j];\r\n }\r\n }\r\n ans[i] = ts;\r\n }\r\n console.log(ans.map((ts) => ts.join(' ')).join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n a = a.map(num => num - 1);\r\n const l = new Array(n).fill(Infinity),\r\n r = new Array(n).fill(Infinity);\r\n for (let i = 0; i < m; i++) {\r\n const j = a[i];\r\n l[j] = Math.min(l[j], b[i]);\r\n r[j] = Math.min(r[j], b[i]);\r\n }\r\n for (let i = 1; i < n; i++) {\r\n l[i] = Math.min(l[i - 1] + 1, l[i]);\r\n }\r\n for (let i = n - 2; i >= 0; i--) {\r\n r[i] = Math.min(r[i + 1] + 1, r[i]);\r\n }\r\n const res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = Math.min(l[i], r[i]);\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const INF = 2 * Math.pow(10, 9);\r\nfunction solve() {\r\n read();\r\n const [n, k] = readArray(Number);\r\n const ind = readArray(Number);\r\n const arr = 'x'.repeat(n).split('').map(() => INF);\r\n readArray((x, i) => {\r\n arr[ind[i] - 1] = Number(x);\r\n });\r\n const L = [];\r\n L[0] = arr[0];\r\n for (let i = 1; i < n; i++) {\r\n L[i] = Math.min(arr[i], L[i - 1] + 1);\r\n }\r\n const R = [];\r\n R[n - 1] = arr[n - 1];\r\n for (let i = n - 2; i >= 0; i--) {\r\n R[i] = Math.min(arr[i], R[i + 1] + 1);\r\n }\r\n const ans = L.map((x, i) => Math.min(x, R[i]));\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var [n, k] = lines[l++].trim().split(' ').map(Number)\n var as = lines[l++].trim().split(' ').map(Number)\n var ts = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, k, as, ts))\n }\n});\n\nfunction solve(n, k, as, ts) {\n const sorted = as.map((a, i) => ({\n i: a,\n t: ts[i],\n f: ts[i] + a - 1 // t at pos 0\n }))\n .sort((a, b) => a.f - b.f)\n// console.log(sorted)\n const r = []\n let cur = 0\n let next = 1\n for (let i = 1; i <= n; i++) {\n if (i <= sorted[cur].i) {\n r.push(sorted[cur].t + sorted[cur].i - i)\n } else {\n while (next < k && sorted[next].i < i) {\n next++\n }\n while (1) {\n const t1 = sorted[cur].t + Math.abs(i - sorted[cur].i)\n if (next >= k) {\n r.push(t1)\n break\n }\n const t2 = sorted[next].t + sorted[next].i - i\n if (t1 <= t2) {\n r.push(t1)\n break\n }\n cur = next++\n }\n }\n // console.log(i, cur)\n }\n return r.join(' ')\n}\n"}, {"source_code": "function _toConsumableArray(arr) {\r\n return (\r\n _arrayWithoutHoles(arr) ||\r\n _iterableToArray(arr) ||\r\n _unsupportedIterableToArray(arr) ||\r\n _nonIterableSpread()\r\n );\r\n}\r\n\r\nfunction _nonIterableSpread() {\r\n throw new TypeError(\r\n \"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"\r\n );\r\n}\r\n\r\nfunction _iterableToArray(iter) {\r\n if (\r\n (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null) ||\r\n iter[\"@@iterator\"] != null\r\n )\r\n return Array.from(iter);\r\n}\r\n\r\nfunction _arrayWithoutHoles(arr) {\r\n if (Array.isArray(arr)) return _arrayLikeToArray(arr);\r\n}\r\n\r\nfunction _newArrowCheck(innerThis, boundThis) {\r\n if (innerThis !== boundThis) {\r\n throw new TypeError(\"Cannot instantiate an arrow function\");\r\n }\r\n}\r\n\r\nfunction _slicedToArray(arr, i) {\r\n return (\r\n _arrayWithHoles(arr) ||\r\n _iterableToArrayLimit(arr, i) ||\r\n _unsupportedIterableToArray(arr, i) ||\r\n _nonIterableRest()\r\n );\r\n}\r\n\r\nfunction _nonIterableRest() {\r\n throw new TypeError(\r\n \"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"\r\n );\r\n}\r\n\r\nfunction _unsupportedIterableToArray(o, minLen) {\r\n if (!o) return;\r\n if (typeof o === \"string\") return _arrayLikeToArray(o, minLen);\r\n var n = Object.prototype.toString.call(o).slice(8, -1);\r\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\r\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\r\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))\r\n return _arrayLikeToArray(o, minLen);\r\n}\r\n\r\nfunction _arrayLikeToArray(arr, len) {\r\n if (len == null || len > arr.length) len = arr.length;\r\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\r\n arr2[i] = arr[i];\r\n }\r\n return arr2;\r\n}\r\n\r\nfunction _iterableToArrayLimit(arr, i) {\r\n var _i =\r\n arr == null\r\n ? null\r\n : (typeof Symbol !== \"undefined\" && arr[Symbol.iterator]) ||\r\n arr[\"@@iterator\"];\r\n if (_i == null) return;\r\n var _arr = [];\r\n var _n = true;\r\n var _d = false;\r\n var _s, _e;\r\n try {\r\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\r\n _arr.push(_s.value);\r\n if (i && _arr.length === i) break;\r\n }\r\n } catch (err) {\r\n _d = true;\r\n _e = err;\r\n } finally {\r\n try {\r\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\r\n } finally {\r\n if (_d) throw _e;\r\n }\r\n }\r\n return _arr;\r\n}\r\n\r\nfunction _arrayWithHoles(arr) {\r\n if (Array.isArray(arr)) return arr;\r\n}\r\n\r\nvar q = parseInt(readline());\r\nreadline();\r\n\r\nvar _loop = function _loop(i) {\r\n var _this = this;\r\n\r\n var _readline$split$map = readline()\r\n .split(\" \")\r\n .map(\r\n function (y) {\r\n _newArrowCheck(this, _this);\r\n\r\n return parseInt(y);\r\n }.bind(this)\r\n ),\r\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\r\n lengthOfStrip = _readline$split$map2[0],\r\n noOfAC = _readline$split$map2[1];\r\n\r\n var positionsOfAC = readline()\r\n .split(\" \")\r\n .map(\r\n function (y) {\r\n _newArrowCheck(this, _this);\r\n\r\n return parseInt(y);\r\n }.bind(this)\r\n );\r\n var temperatureAC = readline()\r\n .split(\" \")\r\n .map(\r\n function (y) {\r\n _newArrowCheck(this, _this);\r\n\r\n return parseInt(y);\r\n }.bind(this)\r\n );\r\n var temperatureAtPosition = new Array(lengthOfStrip).fill(Infinity);\r\n var temperatureFromleft = new Array(lengthOfStrip).fill(Infinity);\r\n var temperatureFromRight = new Array(lengthOfStrip).fill(Infinity);\r\n\r\n for (var _i2 = 0; _i2 < noOfAC; _i2++) {\r\n temperatureAtPosition[positionsOfAC[_i2] - 1] = temperatureAC[_i2];\r\n }\r\n\r\n temperatureFromleft[0] = temperatureAtPosition[0];\r\n temperatureFromRight[lengthOfStrip - 1] =\r\n temperatureAtPosition[lengthOfStrip - 1]; // compute left\r\n\r\n for (var j = 1; j < lengthOfStrip; j++) {\r\n temperatureFromleft[j] = Math.min(\r\n temperatureFromleft[j - 1] + 1,\r\n temperatureAtPosition[j]\r\n );\r\n } // compute right\r\n\r\n for (var _j = lengthOfStrip - 2; _j >= 0; _j--) {\r\n temperatureFromRight[_j] = Math.min(\r\n temperatureFromRight[_j + 1] + 1,\r\n temperatureAtPosition[_j]\r\n );\r\n } // print(temperatureFromleft)\r\n // print(temperatureFromRight)\r\n\r\n var finalTemp = _toConsumableArray(new Array(lengthOfStrip)).map(\r\n function (_, index) {\r\n _newArrowCheck(this, _this);\r\n\r\n return Math.min(temperatureFromleft[index], temperatureFromRight[index]);\r\n }.bind(this)\r\n ); // print(finalTemp)\r\n\r\n print(finalTemp.join(\" \"));\r\n readline();\r\n};\r\n\r\nfor (var i = 0; i < q; i++) {\r\n _loop(i);\r\n}\r\n"}], "negative_code": [], "src_uid": "16bd6786078dbaa443e97eec581cff73"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [x, y] = d.split(' ').map(Number);\n let r = x - y;\n\n if (r === 0) {\n console.log(0);\n }\n else if (r % 2 !== 0 && r < 0) {\n console.log(1);\n }\n else if (r % 2 === 0 && r < 0) {\n console.log(2);\n }\n else if (r % 2 !== 0 && r > 0) {\n console.log(2);\n }\n else if (r % 2 === 0 && r > 0) {\n console.log(1);\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n", "positive_code": [{"source_code": "'use strict';\n\nlet n = parseInt(readline());\n\nwhile ( n-- > 0 ) {\n let line = readline().split(' ').map(data => parseInt(data));\n print(solve(...line));\n}\n\nfunction solve(x, y) {\n let diff = x - y;\n if ( diff === 0 ) {\n return 0;\n } else if ( diff < 0 ) {\n diff = Math.abs(diff);\n return ( diff % 2 === 1 ) ? 1 : 2;\n } else {\n return ( diff % 2 === 1 ) ? 2 : 1;\n }\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var a = one[0];\n var b = one[1];\n if(a == b){\n output[i] = 0;\n }else{\n if(a < b && a % 2 == 1 && b % 2 == 0){\n output[i] = 1;\n }\n if(a < b && a % 2 == 0 && b % 2 == 1){\n output[i] = 1;\n }\n if(a < b && a % 2 == 0 && b % 2 == 0){\n output[i] = 2;\n }\n if(a < b && a % 2 == 1 && b % 2 == 1){\n output[i] = 2;\n }\n \n if(a > b && a % 2 == 1 && b % 2 == 0){\n output[i] = 2;\n }\n if(a > b && a % 2 == 1 && b % 2 == 1){\n output[i] = 1;\n }\n if(a > b && a % 2 == 0 && b % 2 == 0){\n output[i] = 1;\n }\n if(a > b && a % 2 == 0 && b % 2 == 1){\n output[i] = 2;\n }\n }\n }\n myout(myconv(output,9));\n}"}, {"source_code": "t = +readline();\nwhile(t--) {\n line = readline().split(\" \");\n a = +line[0];\n b = +line[1];\n if(a===b) {\n print(0);\n }\n else if(a>b) {\n print((a-b)%2 + 1);\n }\n else {\n print((b-a)%2===0 ? 2 : 1);\n }\n}"}, {"source_code": "T=+readline();\n\nwhile(T--){\n line=readline().split(\" \");\n a=+line[0];\n b=+line[1];\n \n x=b-a;\n \n if (x<0){\n x=-x;\n if (x%2===0){\n print(1);\n }\n else{\n print(2);\n }\n }\n \n else if (x > 0) {\n if (x % 2 == 1) {\n print(1);\n }\n else {\n print(2);\n }\n }\n else {\n print(0);\n }\n}"}, {"source_code": "r=readline;for(k=r();k--;print(b&&((b<0)&b|(b>0)&~b)+1)){x=r().split(\" \");b=x[1]-x[0]}"}, {"source_code": "function solve(a,b) {\n var d;\n if (a == b)\n return 0;\n if (a > b) {\n d = a-b;\n return d % 2 == 0 ? 1 : 2;\n }\n d = b-a;\n return d % 2 == 0 ? 2 : 1;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var a = arr[0];\n var b = arr[1];\n print(solve(a,b));\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n})\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = readline();\n\n for (var i = 0; i < n; i++) {\n const [a, b] = readline().split(' ');\n process.stdout.write(getStepsNumber(a, b) + '\\n');\n }\n}\n\nconst getStepsNumber = (a, b) => {\n if (+a === +b) {\n return 0;\n } else if ( +a < +b ) {\n if (((+b) - (+a)) % 2 === 0) {\n return 2;\n }\n return 1;\n }\n\n if (((+a) - (+b)) % 2 === 1) {\n return 2;\n }\n return 1;\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nstate = 0;\nrl.on('line', line => {\n if (state > 0) {\n line\n .split(' ')\n .map(Number)\n .reduce((a, b) => {\n let e = b - a;\n if (e == 0) {\n console.log('0');\n } else if ((e % 2 == 0 && e < 0) || (e % 2 != 0 && e > 0)) {\n console.log('1');\n } else {\n console.log('2');\n }\n });\n }\n state++;\n}).on('close', () => {\n process.exit(0);\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n let [a,b] = readInts(input, ptr++)\n if(a === b) wr(0)\n else if(a < b) {\n if((b - a) % 2 === 0) wr(2)\n else wr(1)\n }\n else {\n if((a - b) % 2 === 0) wr(1)\n else wr(2)\n }\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n const [a, b] = data;\n if (a > b) {\n if ((a - b)%2) return 2;\n else return 1;\n }\n if (a < b) {\n if ((b - a)%2) return 1;\n else return 2;\n }\n return 0;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n //console.log(lines);\n main(lines);\n})\n\nfunction main(lines) {\n let t, a;\n t = parseInt(lines[0]);\n for (let i = 1; i < t + 1; i++) {\n a = lines[i].split(' ');\n if (a[0] - a[1] == 0) {\n console.log(0)\n } else if ((a[0] - a[1] < 0 && (a[0] - a[1]) % 2 != 0) || (a[0] - a[1] > 0 && (a[0] - a[1]) % 2 == 0)) {\n console.log(1)\n } else {\n console.log(2)\n }\n }\n\n}"}, {"source_code": "const main = (input) => { \n\n input.next();\n\n for(let val of input){\n const [a, b] = val.split(' ').map(x => +x.trim());\n \n const answer = numberOfMoves(a,b);\n console.log(answer);\n }\n\n}\n\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}\n\nlet data = '';\n\nprocess.stdin.on('data', (chunk) => data += chunk + '');\n\nprocess.stdin.on('end',() => {\n data = data.trim().split('\\n');\n const input = iterator(data);\n main(input);\n});\n\nfunction* iterator(args){\n for(let i=0; i { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\nfunction main(){\n let tests = parseInt(readline())\n while(tests--){\n let ab = readline().split(' ').map(x => parseInt(x));\n let a = ab[0];\n let b = ab[1];\n\n if(a == b){\n console.log(0);\n }\n else if(a < b){\n let dif = b - a;\n if(dif & 1) console.log(1);\n else console.log(2);\n }\n else{\n let dif = a - b;\n if(dif & 1) console.log(2);\n else console.log(1);\n }\n }\n}"}, {"source_code": "const readline=require('readline');\n\nconst rl=readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nDATA=[];\nDATA_POINTER=0\nrl.on(\"line\",line=>{\n DATA.push(line);\n})\n\nrl.on(\"close\",()=>{\n main();\n})\ninput=()=>{\n return DATA[DATA_POINTER++];\n}\n\nprint=console.log;\n\nfunction main(){\n T=+input();\n \n while(T--){\n line=input().split(\" \");\n a=+line[0];\n b=+line[1];\n \n x=b-a;\n \n if (x<0){\n x=-x;\n if (x%2===0){\n print(1);\n }\n else{\n print(2);\n }\n }\n \n else if (x > 0) {\n if (x % 2 == 1) {\n print(1);\n }\n else {\n print(2);\n }\n }\n else {\n print(0);\n }\n }\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n const isOdd = a%2 === b%2;\n if (a === b) {\n console.log(0)\n } else {\n if ( (isOdd && a > b) || (!isOdd && a < b) ) {\n console.log(1)\n } else {\n console.log(2)\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const [n, ...lines] = i.split`\\n`;\n for (let i = 0; i < n; i++) {\n const [a, b] = lines[i].split` `.map(Number);\n console.log(a === b ? 0 : a < b ? (b - a) % 2 ? 1 : 2 : (a - b) % 2 ? 2 : 1);\n }\n});"}, {"source_code": "/* eslint-disable no-plusplus, no-lonely-if, arrow-parens, no-multi-assign, no-continue, no-mixed-operators, no-restricted-syntax, guard-for-in, prefer-destructuring, no-param-reassign */\n\nconst BROWSER = false;\nconst BROWSER_INPUT =\n`5\n2 3\n10 10\n2 4\n7 4\n9 3`;\n\nconst TIME_LIMIT = 2000;\n\nconst browserTests = [\n{\ninput:\n`5\n2 3\n10 10\n2 4\n7 4\n9 3`,\noutput:\n`1\n0\n2\n2\n1`,\n},\n];\n\nfunction solve(){\n if (BROWSER) {\n console.log(getAnswer(BROWSER_INPUT.split('\\n')));\n \n browserTests.forEach(({ input, output }, i) => {\n console.log('-'.repeat(40));\n const t = Date.now();\n const answerNonString = getAnswer(input.split('\\n'));\n const execTime = Date.now() - t;\n const isTimeout = execTime >= TIME_LIMIT;\n const answer = answerNonString.toString();\n const expected = output.toString();\n const isCorrect = answer === expected;\n console.log(`${i}: ${isCorrect} (${execTime}ms)`);\n if (!isCorrect || isTimeout) {\n console.log(`Input:\\n${input.slice(0, 100)}`);\n console.log(`Expected:\\n${expected}`);\n console.log(`Answer\\n${answer}`);\n console.log('Answer (non-string)', answerNonString);\n if (isTimeout) {\n console.log('Time out!');\n console.log(`Execution time: ${execTime}`);\n console.log(`Expected time: ${TIME_LIMIT}`);\n }\n }\n });\n } else {\n let INPUT = ''\n process.stdin.on('data', c => INPUT += c)\n process.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = INPUT.split(EOL);\n lines.pop();\n console.log(getAnswer(lines));\n });\n }\n}\n\nconst parseNumbers = str => str.split(' ').map(val => +val);\n\nconst getAnswer = (inputLines) => {\n const getminimum = (a, b) => {\n if (a === b) return 0;\n if (a > b) {\n const diff = a - b;\n if (diff % 2 === 0) return 1;\n return 2;\n }\n const diff = b - a;\n if (diff % 2 === 1) return 1;\n return 2;\n };\n\n const out = [];\n\n for (let i = 1; i < inputLines.length; i++) {\n const nums = parseNumbers(inputLines[i]);\n out.push(getminimum(...nums));\n }\n\n return out.join('\\n');\n};\n\nsolve();\n"}, {"source_code": "function main(input) {\n var lines = input.trim().split(\"\\n\").map(function (l) { return l.trim(); });\n var t = parseInt(lines.shift(), 10);\n while (t > 0) {\n var _a = lines.shift().split(\" \").map(function (v) { return parseInt(v); }), a = _a[0], b = _a[1];\n if (a === b) {\n console.log(0);\n }\n else if (a > b) {\n if ((a - b) % 2 === 0) {\n console.log(1);\n }\n else {\n console.log(2);\n }\n }\n else {\n if ((a - b) % 2 === 0) {\n console.log(2);\n }\n else {\n console.log(1);\n }\n }\n t--;\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (v) { return d += v; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\n\nwhile (t --> 0) {\n const arr = readline().split(' ').map(n => parseInt(n))\n const a = arr[0]\n const b = arr[1]\n \n let ans = 0\n const diff = Math.abs(a - b)\n if (a < b) {\n if (diff % 2) ans = 1\n else ans = 2\n } else if (a > b) {\n if (diff % 2) ans = 2\n else ans = 1\n }\n print(ans)\n}"}, {"source_code": "'use strict'\n\nconst problem = (a, b) => {\n if (a === b) return 0;\n if (a < b) return 2 - (b - a) % 2;\n return 1 + (a - b) % 2;\n}\n\nlet t = +readline()\nwhile(t--) {\n const ab = readline().split(' ')\n print(problem(+ab[0], +ab[1]))\n}\n"}], "negative_code": [{"source_code": "var t = readline();\nwhile(t--) {\n var line = readline().split(\" \");\n var a = line[0];\n var b = line[1];\n if(a===b) {\n print('0');\n }\n if(a>b) {\n print((a-b)%2 + 1);\n }\n else\n print((b-a)%2===0 ? 2 : 1);\n}"}, {"source_code": "var t = readline();\nwhile(t--) {\n var line = readline().split(\" \");\n var a = line[0];\n var b = line[1];\n if(a===b) {\n print('0');\n }\n else if(a>b) {\n print((a-b)%2 + 1);\n }\n else\n print((b-a)%2===0 ? 2 : 1);\n}"}, {"source_code": "var t = readline();\nwhile(t--) {\n var line = readline().split(\" \");\n var a = line[0];\n var b = line[1];\n if(a===b) {\n print(0);\n }\n else if(a>b) {\n print((a-b)%2 + 1);\n }\n else {\n print(2-(b-a)%2);\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--) {\n var line = readline().split(\" \");\n var a = line[0];\n var b = line[1];\n if(a===b) {\n print(0);\n }\n else if(a>b) {\n print((a-b)%2 + 1);\n }\n else {\n (b-a)%2===0 ? print(2) : print(1);\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--) {\n var line = readline().split(\" \");\n var a = line[0];\n var b = line[1];\n if(a===b) {\n print('0');\n }\n else if(a>b) {\n print((a-b)%2===0 ? 1 : 2);\n }\n else\n print((b-a)%2===0 ? 2 : 1);\n}"}, {"source_code": "var a = readline();\nprint(a);"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const [_, ...lines] = i.split`\\n`;\n for (const input of lines) {\n const [a, b] = input.split` `.map(Number);\n if (a === b) console.log(0);\n if (a < b) console.log(b - a % 2 ? 1 : 2);\n if (b < a) console.log(a - b % 2 ? 2 : 1);\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n})\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = readline();\n\n for (var i = 0; i < n; i++) {\n const [a, b] = readline().split(' ');\n process.stdout.write(getStepsNumber(a, b) + '\\n');\n }\n}\n\nconst getStepsNumber = (a, b) => {\n if (a === b) {\n return 0;\n } else if ( a < b ) {\n if ((b - a) % 2 === 0) {\n return 2;\n }\n return 1;\n }\n\n if ((a - b) % 2 === 1) {\n return 2;\n }\n return 1;\n}\n"}, {"source_code": "const main = (input) => {\n\n input.next();\n\n for(let val of input){\n console.log(val);\n continue;\n const [a, b] = val.split(' ').map(x => +x.trim());\n \n const answer = numberOfMoves(a,b);\n console.log(answer);\n }\n\n}\n\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}\n\nlet data = '';\n\nprocess.stdin.on('data', (chunk) => data += chunk + '');\n\nprocess.stdin.on('end',() => {\n data = data.split('\\n');\n const input = iterator(data);\n main(input);\n});\n\nfunction* iterator(args){\n for(let i=0; i {\n const line = chunk + '';\n \n data.push(line.trim());\n});\n\nprocess.stdin.on('end', () => {\n \n const input = iterator(data);\n \n const n = +input.next().value;\n \n for(let val of input){\n \n const args = val.split(' ');\n \n const a = + (args[0].trim());\n const b = + (args[1].trim());\n \n \n const answer = numberOfMoves(a,b);\n console.log(answer);\n }\n});\n\nfunction* iterator(args){\n for(let i=0; i < args.length; i++){\n yield args[i];\n }\n}\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}"}, {"source_code": "const data = [];\n\nprocess.stdin.on('data', (chunk) => {\n const line = chunk + '';\n \n data.push(line.trim());\n});\n\nprocess.stdin.on('end', () => {\n \n const n = +data[0];\n \n for(let i=0; i +x.trim());\n \n const answer = numberOfMoves(a,b);\n console.log(answer);\n }\n});\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}"}, {"source_code": "const main = (input) => { \n \n input.next(); \n \n for(let val of input){ \n console.log(val); \n const [a, b] = val.split(' ').map(x => +x.trim()); \n \n const answer = numberOfMoves(a,b); \n console.log(answer); \n } \n \n} \n \n \nconst numberOfMoves = (a, b) => { \n \n let ans; \n \n const diff = Math.abs(a - b); \n \n ans = a == b ? 0 : 1 ; \n \n ans = b > a & diff % 2 == 0 ? 2 : ans; \n ans = a > b & diff % 2 == 1 ? 2 : ans; \n \n return ans; \n} \n \nlet data = ''; \n \nprocess.stdin.on('data', (chunk) => data += chunk + ''); \n \nprocess.stdin.on('end',() => { \n data = data.split('\\n'); \n const input = iterator(data); \n main(input); \n}); \n \nfunction* iterator(args){ \n for(let i=0; i {\n const line = chunk + '';\n \n data.push(line.trim());\n});\n\nprocess.stdin.on('end', () => {\n \n const input = iterator(data);\n \n const n = +input.next().value;\n \n for(let val of input){\n \n const args = val.split(' ');\n \n const a = + (args[0].trim());\n const b = + (args[1].trim());\n \n \n const answer = numberOfMoves(a,b) + '\\n'; \n process.stdout.write(answer);\n }\n});\n\nfunction* iterator(args){\n for(let i=0; i < args.length; i++){\n yield args[i];\n }\n}\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}"}, {"source_code": "const data = [];\n\nprocess.stdin.on('data', (chunk) => {\n const line = chunk + '';\n \n data.push(line.trim());\n});\n\nprocess.stdin.on('end', () => {\n \n const input = iterator(data);\n \n const n = +input.next().value;\n \n for(let val of input){\n \n const args = val.split(' ');\n \n const a = + (args[0].trim());\n const b = + (args[1].trim());\n \n \n console.log(numberOfMoves(a,b)); \n }\n});\n\nfunction* iterator(args){\n for(let i=0; i < args.length; i++){\n yield args[i];\n }\n}\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}"}, {"source_code": "console.log(\"datvi\");"}, {"source_code": "const main = (input) => { \n\n input.next();\n\n for(let val of input){\n const [a, b] = val.split(' ').map(x => +x.trim());\n \n const answer = numberOfMoves(a,b);\n console.log(answer);\n }\n\n}\n\n\nconst numberOfMoves = (a, b) => {\n \n let ans;\n \n const diff = Math.abs(a - b);\n \n ans = a == b ? 0 : 1 ;\n \n ans = b > a & diff % 2 == 0 ? 2 : ans;\n ans = a > b & diff % 2 == 1 ? 2 : ans;\n\n return ans;\n}\n\nlet data = '';\n\nprocess.stdin.on('data', (chunk) => data += chunk + '');\n\nprocess.stdin.on('end',() => {\n data = data.split('\\n');\n const input = iterator(data);\n main(input);\n});\n\nfunction* iterator(args){\n for(let i=0; i i += c);\nprocess.stdin.on('end', () => {\n const [_, ...lines] = i.split`\\n`;\n for (const input of lines) {\n const [a, b] = input.split` `.map(Number);\n console.log(a === b ? 0 : a < b ? (b - a) % 2 ? 1 : 2 : (a - b) % 2 ? 2 : 1);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const [_, ...lines] = i.split`\\n`;\n for (const input of lines) {\n const [a, b] = input.split` `.map(Number);\n console.log(a === b ? 0 : Math.abs(a - b) % 2 ? 1 : 2);\n }\n});"}], "src_uid": "fcd55a1ca29e96c05a3b65b7a8103842"} {"source_code": "'use strict'\n\nclass SegmentTree {\n constructor(a, op, init) {\n this.init = init;\n this.op = op;\n this.n = 1 << Math.ceil(Math.log2(a.length));\n this.t = Array(2 * this.n).fill(init);\n }\n\n update(i, x) {\n for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {\n this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);\n }\n }\n}\n\nconst NK = readline().split(' ').map(Number);\nconst N = NK[0];\nconst K = NK[1];\n\nconst LRs = [];\nconst R = Array.from({ length: N + 1 }, () => 0);\n\nfor (let i = 1; i <= N; i++) {\n const lr = readline().split(' ');\n const l = +lr[0];\n let r = +lr[1];\n R[i] = r++;\n if (LRs[l]) LRs[l].push(i); else LRs[l] = [ i ];\n if (LRs[r]) LRs[r].push(-i); else LRs[r] = [ -i ];\n}\n\nconst sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);\n\nlet k = 0;\nlet ans = [];\nlet removed = new Set();\n\nLRs.filter(Array.isArray).forEach(lrs => {\n lrs.forEach(i => {\n if (i > 0) {\n sti.update(i, R[i]);\n return k++;\n }\n if(!removed.has(-i)) {\n sti.update(-i, 0);\n return k--;\n }\n })\n for(; k > K; k--) {\n const i = sti.t[1][1];\n sti.update(i, 0);\n ans.push(i);\n removed.add(i);\n }\n})\n\nprint(ans.length);\nprint(ans.join(' '));\n", "positive_code": [{"source_code": "'use strict'\n\nconst SegTreeIndex = (n) => {\n const self = { n: 1 };\n while (self.n < n) self.n <<= 1;\n self.tree = Array(self.n << 1).fill(-1);\n self.index = Array(self.n << 1).fill(-1);\n for (let i = 0; i < self.n; i++) self.index[i + self.n] = i;\n for (let i = self.n - 1; i; i--) self.index[i] = self.index[i << 1];\n\n self.update = (i, x) => {\n i += self.n;\n self.tree[i] = x;\n while (i > 1) {\n const left = Math.min(i, i^1);\n const right = Math.max(i, i^1);\n if (self.tree[left] >= self.tree[right]) {\n self.tree[i >> 1] = self.tree[left];\n self.index[i >> 1] = self.index[left];\n } else {\n self.tree[i >> 1] = self.tree[right];\n self.index[i >> 1] = self.index[right];\n }\n i >>= 1;\n }\n }\n\n self.query = (a, b) => {\n let l = a + self.n;\n let r = b + self.n;\n let s = [ -1, -1 ];\n while (l < r) {\n if (r & 1) {\n r -= 1;\n const res = Math.max(s[0], self.tree[r]);\n if (res !== s[0]) s = [ self.tree[r], self.index[r] ];\n }\n if (l & 1) {\n const res = Math.max(self.tree[l], s[0])\n if (res === self.tree[l]) s = [ self.tree[l], self.index[l] ];\n l += 1;\n }\n l >>= 1;\n r >>= 1;\n }\n return s\n }\n return self;\n}\n\nconst NK = readline().split(' ').map(Number);\nconst N = NK[0];\nconst K = NK[1];\nconst MAX = 200001;\n\nconst LRs = Array.from({ length: MAX+2 }, () => []);\nconst R = Array.from({ length: N+1 }, () => 0);\n\nfor (let i = 0; i < N; i++) {\n const lr = readline().split(' ').map(Number);\n const l = lr[0];\n const r = lr[1];\n LRs[l].push(i+1)\n LRs[r+1].push(-(i+1))\n R[i+1] = r;\n}\n\nconst sti = SegTreeIndex(N+1)\n\nlet segcnt = 0;\nlet ans = [];\nlet removed = new Set();\n\nfor (let i = 1; i < MAX+2; i++) {\n LRs[i].forEach(idx => {\n if (idx > 0) {\n sti.update(idx, R[idx]);\n segcnt += 1;\n } else {\n const idx2 = -idx;\n if (!removed.has(idx2)) {\n sti.update(idx2, -1);\n segcnt -= 1;\n }\n }\n })\n while (segcnt > K) {\n const query = sti.query(0, N+1);\n const mx = query[0];\n const idx = query[1];\n sti.update(idx, -1);\n ans.push(idx);\n removed.add(idx);\n segcnt -= 1;\n }\n}\nprint(ans.length);\nprint(ans.join(' '));\n"}, {"source_code": "'use strict'\n\nconst nk = readline().split(' ');\nconst n = +nk[0], k = +nk[1];\n\nconst x = [];\nfor (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1] }))(readline().split(' ')))\n\nconst max = x.reduce((r, i) => r < i.r ? i.r : r, 0)\nlet y = Array.from({ length: max + 1 }, () => []);\nfor (let i = 0; i < n; i++) {\n for (let j = x[i].l; j <= x[i].r; j++) {\n y[j].push(i);\n }\n}\n\ny = y.filter(i => i.length > k);\nconst ans = [];\n\nfor (let i = 0; i < y.length; i++) {\n while(y[i].length > k) {\n let max = 1, t = 0, line = y[i][t], j = i+1;\n while (j < y.length && t < y[i].length) {\n if (y[j].indexOf(y[i][t]) === -1) { t++; }\n else { j++; line = y[i][t]; }\n }\n ans.push(line);\n y = y.map(yi => yi.filter(yij => yij !== line))\n }\n}\n\n\nwrite(ans.length + '\\n' + ans.map(i => i+1).join(' '));\n"}, {"source_code": "'use strict'\n\nclass SegmentTree {\n constructor(a, op, init) {\n this.init = init;\n this.op = op;\n this.n = 1 << Math.ceil(Math.log2(a.length));\n this.t = Array(this.n << 1).fill(init);\n }\n\n update(i, x) {\n for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {\n this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);\n }\n }\n}\n\nconst NK = readline().split(' ').map(Number);\nconst N = NK[0];\nconst K = NK[1];\nconst MAX_LEN = 200000;\n\nconst LRs = Array.from({ length: MAX_LEN + 2 }, () => []);\nconst R = Array.from({ length: N + 1 }, () => 0);\n\nfor (let i = 1; i <= N; i++) {\n const lr = readline().split(' ');\n R[i] = +lr[1];\n LRs[+lr[0]].push(i);\n LRs[R[i]+1].push(-i);\n}\n\nconst sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);\n\nlet k = 0;\nlet ans = [];\nlet removed = new Set();\n\nfor (let j = 1; j < MAX_LEN + 2; j++) {\n LRs[j].forEach(i => {\n if (i > 0) {\n sti.update(i, R[i]);\n return k++;\n }\n if(!removed.has(-i)) {\n sti.update(-i, 0);\n return k--;\n }\n })\n for(; k > K; k--) {\n const i = sti.t[1][1];\n sti.update(i, 0);\n ans.push(i);\n removed.add(i);\n }\n}\n\nprint(ans.length);\nprint(ans.join(' '));\n"}, {"source_code": "'use strict'\n\nclass SegmentTree {\n constructor(n) {\n this.n = 1 << Math.ceil(Math.log2(n));\n this.t = Array(this.n << 1).fill(0);\n this.i = Array(this.n << 1).fill(0);\n for(let i = 1; i < n; i++) this.i[i+this.n] = i;\n }\n\n update(i, x) {\n for (this.t[i + this.n] = x, i += this.n; i > 1; i >>= 1) {\n const j = i^1, ii = i >> 1;\n if (this.t[i] >= this.t[j]) {\n this.t[ii] = this.t[i];\n this.i[ii] = this.i[i];\n } else {\n this.t[ii] = this.t[j];\n this.i[ii] = this.i[j];\n }\n }\n }\n}\n\nconst NK = readline().split(' ');\nconst N = +NK[0];\nconst K = +NK[1];\nconst MAX_LEN = 200000;\n\nconst LRs = Array.from({ length: MAX_LEN + 2 }, () => []);\nconst R = Array.from({ length: N + 1 }, () => 0);\n\nfor (let i = 1; i <= N; i++) {\n const lr = readline().split(' ');\n R[i] = +lr[1];\n LRs[+lr[0]].push(i);\n LRs[R[i]+1].push(-i);\n}\n\nconst sti = new SegmentTree(N+1);\nlet k = 0;\nlet ans = [];\nlet removed = new Set();\n\nfor (let j = 1; j < MAX_LEN + 2; j++) {\n LRs[j].forEach(i => {\n if (i > 0) {\n sti.update(i, R[i]);\n return k++;\n }\n if(!removed.has(-i)) {\n sti.update(-i, 0);\n return k--;\n }\n })\n for(; k > K; k--) {\n const i = sti.i[1];\n sti.update(i, 0);\n ans.push(i);\n removed.add(i);\n }\n}\n\nprint(ans.length);\nprint(ans.join(' '));\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst nk = readline().split(' ');\nconst n = +nk[0], k = +nk[1];\n\nconst x = [];\nfor (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1] }))(readline().split(' ')))\n\nconst max = x.reduce((r, i) => r < i.r ? i.r : r, 0)\nlet y = Array.from({ length: max + 1 }, () => []);\nfor (let i = 0; i < n; i++) {\n for (let j = x[i].l; j <= x[i].r; j++) {\n y[j].push(i);\n }\n}\n\ny = y.filter(i => i.length > k);\nconst ans = [];\n\nfor (let i = 0; i < y.length; i++) {\n let cnt = 10;\n while(y[i].length > k && cnt--) {\n let max = 1, t = 0, line = y[i][t], j = i+1;\n while (j < y.length && t < y[i].length) {\n if (y[j].indexOf(y[i][t]) === -1) { t++; }\n else { j++; line = y[i][t]; }\n }\n ans.push(line);\n y = y.map(yi => yi.filter(yij => yij !== line))\n }\n}\n\n\nwrite(ans.length + '\\n' + ans.map(i => i+1).join(' '));\n"}, {"source_code": "'use strict'\n\nclass SegmentTree {\n constructor(a, op, init) {\n this.init = init;\n this.op = op;\n this.n = 1 << Math.ceil(Math.log2(a.length));\n this.t = Array(this.n << 1).fill(init);\n }\n\n update(i, x) {\n for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {\n this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);\n }\n }\n}\n\nconst NK = readline().split(' ').map(Number);\nconst N = NK[0];\nconst K = NK[1];\nconst MAX_LEN = 200000;\n\nconst LRs = Array.from({ length: MAX_LEN + 2 }, () => []);\nconst R = Array.from({ length: N + 1 }, () => 0);\n\nfor (let i = 1; i <= N; i++) {\n const lr = readline().split(' ');\n R[i] = +lr[1];\n LRs[+lr[0]].push(i);\n LRs[R[i]].push(-i);\n}\n\nconst sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);\n\nlet k = 0;\nlet ans = [];\nlet removed = new Set();\n\nfor (let j = 1; j < MAX_LEN + 2; j++) {\n LRs[j].forEach(i => {\n if (i > 0) {\n sti.update(i, R[i]);\n return k++;\n }\n if(!removed.has(-i)) {\n sti.update(-i, 0);\n return k--;\n }\n })\n for(; k > K; k--) {\n const i = sti.t[1][1];\n sti.update(i, 0);\n ans.push(i);\n removed.add(i);\n }\n}\n\nprint(ans.length);\nprint(ans.join(' '));\n"}, {"source_code": "'use strict'\n\nconst nk = readline().split(' ');\nconst n = +nk[0], k = +nk[1];\n\nlet x = [];\nfor (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))\nx = x.sort((a, b) => b.r - a.r);\n\nconst max = x.reduce((r, i) => r < i.r ? i.r : r, 0)\nlet y = Array.from({ length: max + 1 }, () => []);\nfor (let i = 0; i < n; i++) {\n for (let j = x[i].l; j <= x[i].r; j++) {\n y[j].push(x[i].i);\n }\n}\n\n\ny = y.filter(i => i.length > k);\nlet ans = [];\nif (n !== 200000) {\n while (y.length) {\n const next = y.shift().sort((a, b) => x.findIndex(item => item.i === a) - x.findIndex(item => item.i === b));\n const deleted = next.slice(0, next.length - k);\n ans = ans.concat(deleted);\n y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);\n }\n write(ans.length + '\\n' + ans.map(i => i+1).join(' '));\n} else write(x.map(i => [ i.l, i.r, i.i ].join(' ')) + '\\n')\n"}, {"source_code": "'use strict'\n\nconst nk = readline().split(' ');\nconst n = +nk[0], k = +nk[1];\n\nlet x = [];\nfor (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))\nx = x.sort((a, b) => b.r - a.r);\n\nconst max = x.reduce((r, i) => r < i.r ? i.r : r, 0)\nlet y = Array.from({ length: max + 1 }, () => []);\nfor (let i = 0; i < n; i++) {\n for (let j = x[i].l; j <= x[i].r; j++) {\n y[j].push(i);\n }\n}\n\n\ny = y.filter(i => i.length > k);\nlet ans = [];\n\nwhile (y.length) {\n const next = y.shift().sort((a, b) => x.findIndex(item => item.i === a) - x.findIndex(item => item.i === b));\n const deleted = next.slice(0, next.length - k);\n ans = ans.concat(deleted);\n y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);\n}\n\nwrite(ans.length + '\\n' + ans.map(i => i+1).join(' '));\n"}, {"source_code": "'use strict'\n\nconst nk = readline().split(' ');\nconst n = +nk[0], k = +nk[1];\n\nlet x = [];\nfor (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))\nx = x.sort((a, b) => b.r - a.r);\n\nconst max = x.reduce((r, i) => r < i.r ? i.r : r, 0)\nlet y = Array.from({ length: max + 1 }, () => []);\nfor (let i = 0; i < n; i++) {\n for (let j = x[i].l; j <= x[i].r; j++) {\n y[j].push(i);\n }\n}\n\n\ny = y.filter(i => i.length > k);\nlet ans = [];\n\nwhile (y.length) {\n const next = y.shift().sort((a, b) => x.findIndex(item => item.i === b) - x.findIndex(item => item.i === a));\n const deleted = next.slice(0, next.length - k);\n ans = ans.concat(deleted);\n y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);\n}\n\nwrite(ans.length + '\\n' + ans.map(i => i+1).join(' '));\n"}], "src_uid": "7f9c5a137e9304d4d7eee5ee1a891d1d"} {"source_code": "var tmp = readline().split(' ');\nvar n = parseInt(tmp[0]);\nvar m = parseInt(tmp[1]);\nvar arr = [];\n\nfor (var i = 0; i < n; ++i) {\n arr[i] = readline().split(' ');\n}\n\nvar answ = arr.length;\n\nif (arr.length % 2 === 0) {\n answ = solve(n);\n}\n\nfunction solve(r) {\n if (r % 2 != 0) {\n return r;\n }\n for (var i = 0; i < r / 2; ++i)\n for (var j = 0; j < m; ++j)\n if (arr[i][j] != arr[r - i - 1][j])\n return r;\n return solve(r / 2);\n}\n\nprint(answ);", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\trowNum = data[0], colNum = data[1],\n\t\tarray = [];\n\tfor (var r = 0; r < rowNum; ++r) {\n\t\tvar row = tokenizeIntegers(readline());\n\t\tarray.push(row);\n\t}\n\tarray.equal = function (rowA, rowB) {\n\t\tfor (var c = 0; c < colNum; ++c) {\n\t\t\tif (this[rowA][c] != this[rowB][c]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t};\n\tvar height = rowNum;\n\twhile (true) {\n\t\tif (height % 2 == 1) {\n\t\t\tprint(height);\n\t\t\treturn;\n\t\t}\n\t\tfor (var r = height/2; r >= 0; --r) {\n\t\t\tif (!array.equal(r, height-1-r)) {\n\t\t\t\tprint(height);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\theight /= 2;\n\t}\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "90125e9d42c6dcb0bf3b2b5e4d0f845e"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const val = {\r\n '?': 0,\r\n '(': 1,\r\n ')': -1\r\n };\r\n\r\n const isFixed = char => {\r\n return char === '(' || char === ')';\r\n };\r\n\r\n const validate = s => {\r\n let balance = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (balance < 0) {\r\n return false;\r\n }\r\n }\r\n return balance === 0;\r\n };\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n let balance = 0;\r\n let questions = 0;\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (s[i] === '?') {\r\n questions++;\r\n }\r\n }\r\n\r\n let opening = (questions - balance) / 2;\r\n let closing = balance + opening;\r\n\r\n if (closing === 0 || opening === 0) {\r\n output('YES');\r\n continue;\r\n }\r\n\r\n let secondBest = '';\r\n\r\n let seq = '('.repeat(opening - 1) + ')' + '(' + ')'.repeat(closing - 1);\r\n\r\n let j = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n if (isFixed(s[i])) {\r\n secondBest += s[i];\r\n continue;\r\n }\r\n secondBest += seq[j];\r\n j++;\r\n }\r\n\r\n const result = validate(secondBest) ? 'NO' : 'YES';\r\n\r\n output(result);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n \r\n \r\nfunction myFunc(s){\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')')neg++;\r\n }\r\n \r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(pos + neg + 2 < met) return false;\r\n \r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref, acum = 0;\r\n let p = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n p[i] = ++acum;\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n p[i] = --acum;\r\n }\r\n }\r\n else{\r\n if(s[i] == '(') p[i] = ++acum;\r\n else p[i] = --acum;\r\n }\r\n }\r\n\r\n let min = new Array(n), atual_min = Infinity;\r\n for(let i = ref-1; i >= 0; i--){\r\n if(p[i] < atual_min) atual_min = p[i];\r\n min[i] = atual_min;\r\n }\r\n\r\n for(let i = 0; i < ref && inter_open > 0; i++){\r\n if(s[i] == '?'){\r\n\r\n if(min[i] - 2 >= 0) return false;\r\n inter_open--;\r\n }\r\n\r\n }\r\n return true;\r\n \r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 0,\r\n r = 1,\r\n cnt = 0;\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (i === 0) {\r\n l++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (l > r + cnt) return 'NO';\r\n }\r\n if (Math.abs(r - l) === cnt) return 'YES';\r\n }\r\n let l = 1,\r\n r = 0,\r\n cnt = 0,\r\n q = [];\r\n {\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else {\r\n cnt++;\r\n q.push(i);\r\n }\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n }\r\n const a = s.split('');\r\n a[0] = '(';\r\n a[n - 1] = ')';\r\n if (l < r) {\r\n for (let i = 0; i < r - l; i++) {\r\n a[q[i]] = '(';\r\n }\r\n q = q.slice(r - l);\r\n } else if (l > r) {\r\n let t = l - r;\r\n while (t--) {\r\n a[q.pop()] = ')';\r\n }\r\n }\r\n const m = q.length;\r\n for (let i = 0; i < m / 2 - 1; i++) {\r\n a[q[i]] = '(';\r\n a[q[m - i - 1]] = ')';\r\n }\r\n a[q[m / 2 - 1]] = ')';\r\n a[q[m / 2]] = '(';\r\n {\r\n let l = 0,\r\n r = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else r++;\r\n if (r > l) return 'YES';\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n \r\n function verify(pos, cont, ref){\r\n for(let i = pos; i <= ref; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2;\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n \r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '('){\r\n esq[i] = ++cont_esq; \r\n pos++;\r\n } \r\n else if(s[i] == ')'){\r\n esq[i] = --cont_esq;\r\n neg++;\r\n } \r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == ')') dir[last-i] = ++cont_dir;\r\n else if(s[i] == '(') dir[last-i] = --cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n // console.log(esq, dir);\r\n \r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(pos + neg + 2 < met) return false;\r\n \r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n\r\n if(esq[i] >= 0 && dir[i] >= 0 && seq > Math.abs(esq[i] - dir[i]) + 2){\r\n return false;\r\n }\r\n }\r\n \r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(s[i] == '?'){\r\n if(verify(i+1, cont-1, ref)) return false;\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = ++cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = --cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n // console.log(esq, dir);\r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n\r\n if(esq[i] >= 0 && dir[i] <= 0 && seq > Math.abs(esq[i] + dir[i]) + 3){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = ++cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = --cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n //count '?' and apply restrition\r\n let seq = 0, aux1, aux2;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n\r\n aux1 = esq[i] >= 0 ? esq[i] : 0;\r\n aux2 = dir[i] <= 0 ? dir[i] : 0;\r\n if(seq > Math.abs(aux1 + aux2) + 2){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = ++cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = --cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n\r\n // console.log(esq, dir);\r\n if((esq[i] > 0 || dir[i] < 0) && seq > Math.abs(esq[i] + dir[i]) + 2){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = --cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = ++cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n if((esq[i] > 0 || dir[i] > 0) && seq > Math.max(esq[i], dir[i])){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = --cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = ++cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n if((esq[i] != 0 || dir[i] != 0) && seq > Math.max(esq[i], dir[i])){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\nfunction myFunc(s){\r\n let arr;\r\n const n = s.length;\r\n if(n % 2 != 0) return false;\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < n; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n \r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = n/2, vet = [];\r\n let esq = new Array(n), dir = new Array(n);\r\n let cont_esq = 0, cont_dir = 0;\r\n \r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - 2 > met) return false;\r\n\r\n //Restrition for start and end\r\n let last = n-1;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '(') esq[i] = ++cont_esq;\r\n else if(s[i] == ')') esq[i] = --cont_esq;\r\n else esq[i] = cont_esq;\r\n\r\n if(s[last-i] == '(') dir[last-i] = ++cont_dir;\r\n else if(s[last-i] == ')') dir[last-i] = --cont_dir;\r\n else dir[last-i] = cont_dir;\r\n }\r\n\r\n //count '?' and apply restrition\r\n let seq = 0;\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?') seq++;\r\n else seq = 0;\r\n if(esq[i] != 0 && dir[i] != 0 && seq >= Math.abs(esq[i] + dir[i]) + 2){\r\n return false;\r\n }\r\n \r\n }\r\n\r\n //Generate main solution\r\n let aux_pos = 0, ref;\r\n arr = new Array(n);\r\n for(let i = 0; i < n; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n \r\n // Try find other solution using swap\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n \r\n}\r\n\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n // const arr = readLine().split(''); //o fato de usar split quebrou o desempenho\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\nfunction myFunc(s){\r\n function verify(pos, cont){\r\n for(let i = pos; i < s.length; i++){\r\n if(cont < 0) return false;\r\n if(s[i] == '(') cont++;\r\n else if(s[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(s.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = s.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n // if(vet.length - 2 > met) return false;\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n // if(vet.length - 2 > met) return false;\r\n\r\n let arr = new Array(s.length);\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n // const arr = readLine().split(''); //o fato de usar split quebrou o desempenho\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\nfunction myFunc(s){\r\n function verify(pos, cont){\r\n for(let i = pos; i < s.length; i++){\r\n if(cont < 0) return false;\r\n if(s[i] == '(') cont++;\r\n else if(s[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(s.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = s.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n // if(vet.length - 2 > met) return false;\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n if(vet.length - 2 > met) return false;\r\n\r\n let arr = new Array(s.length);\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n // const arr = readLine().split(''); //o fato de usar split quebrou o desempenho\r\n const s = readLine();\r\n let result = myFunc(s) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\nfunction myFunc(s){\r\n function verify(pos, cont){\r\n for(let i = pos; i < s.length; i++){\r\n if(cont < 0) return false;\r\n if(s[i] == '(') cont++;\r\n else if(s[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(s.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = s.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '(') pos++;\r\n else if(s[i] == ')') neg++;\r\n else vet.push(i);\r\n // if(vet.length - 2 > met) return false;\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n if(vet.length - pos - neg - 2 > 0 ) return false;\r\n\r\n let arr = new Array(s.length);\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n else{\r\n arr[i] = s[i];\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n // const arr = readLine().split('');\r\n const arr = readLine();\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\nString.prototype.replaceAt = function (index, newValue) {\r\n return this.substring(0, index) + newValue + this.substring(index + newValue.length);\r\n};\r\n\r\nfunction myFunc(arr){\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++;\r\n else vet.push(i);\r\n // if(vet.length - 2 > met) return false;\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n if(vet.length - pos - neg - 2 > 0 ) return false;\r\n\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr = arr.replaceAt(i, '(');\r\n // arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n // arr[i] = ')';\r\n arr = arr.replaceAt(i, ')');\r\n }\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n // arr[ref] = '(';\r\n console.log(arr);\r\n arr = arr.replaceAt(ref, '(');\r\n console.log(arr);\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n // const arr = readLine().split('');\r\n const arr = readLine();\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\nString.prototype.replaceAt = function (index, newValue) {\r\n this.substring(0, index) + newValue + this.substring(index + newValue.length);\r\n};\r\n\r\nfunction myFunc(arr){\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++;\r\n else vet.push(i);\r\n // if(vet.length - 2 > met) return false;\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n if(vet.length - pos - neg - 2 > 0 ) return false;\r\n\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr.replaceAt(i, '(');\r\n // arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n // arr[i] = ')';\r\n arr.replaceAt(i, ')');\r\n }\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n // arr[ref] = '(';\r\n arr.replaceAt(ref, '(');\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split('');\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\n\r\n\r\nfunction myFunc(arr){\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - inter_open + inter_close - 2 > 0 ) return false;\r\n\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n }\r\n }\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split('');\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\n\r\n\r\n\r\nfunction myFunc(arr){\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n if(vet.length - Math.abs(inter_open - inter_close) - 2 > 0 ) return false;\r\n\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n\r\n }\r\n }\r\n\r\n // console.log(arr, inter_open, inter_close);\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == vet[ind]){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split('');\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\n\r\n\r\n\r\nfunction myFunc(arr){\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n let vet = [];\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++;\r\n else vet.push(i);\r\n }\r\n\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n let aux_pos = 0, ref;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '?'){\r\n if(aux_pos < inter_open){\r\n aux_pos++;\r\n arr[i] = '(';\r\n }\r\n else{\r\n if(!ref) ref = i;\r\n arr[i] = ')';\r\n }\r\n\r\n }\r\n }\r\n\r\n\r\n let cont = 0;\r\n let ind = 0;\r\n arr[ref] = '(';\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(i == ind){\r\n if(verify(i+1, cont-1)) return false;\r\n ind++\r\n inter_open--;\r\n cont++;\r\n }\r\n else{\r\n if(arr[i] == '(') cont++;\r\n else cont--;\r\n }\r\n }\r\n return true;\r\n\r\n}"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split('');\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\nfunction myFunc(arr){\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n // else return true;\r\n }\r\n return true;\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n let cont = 0;\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n else{\r\n let res = verify(i+1, cont-1);\r\n if(res) return false;\r\n inter_open--;\r\n cont++;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const arr = readLine().split('');\r\n let result = myFunc(arr) ? 'YES' : 'NO';\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\nfunction myFunc(arr){\r\n\r\n function verify(pos, cont){\r\n for(let i = pos; i < arr.length; i++){\r\n if(cont < 0) return false;\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n else return true;\r\n }\r\n }\r\n\r\n if(arr.length %2 != 0) return false;\r\n let pos = 0, neg = 0, inter_open = 0, inter_close = 0;\r\n let met = arr.length/2;\r\n\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] == '(') pos++;\r\n else if(arr[i] == ')') neg++\r\n }\r\n\r\n if(pos > met || neg > met) return false;\r\n inter_open = met - pos;\r\n inter_close = met - neg;\r\n if(inter_open == 0 || inter_close == 0) return true;\r\n\r\n let cont = 0;\r\n for(let i = 0; i < arr.length && inter_open > 0; i++){\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')') cont--;\r\n else{\r\n let res = verify(i+1, cont-1);\r\n if(res) return false;\r\n inter_open--;\r\n cont++;\r\n }\r\n }\r\n return true;\r\n\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n\r\n const arr = readLine().split('');\r\n let result = myFunc(arr);\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(arr){\r\n if(arr.length %2 != 0) return 'NO';\r\n let unique = true;\r\n let dyn = new Array(arr.length).fill().map(() => new Array());\r\n\r\n function rec(pos, cont, opt){\r\n if(!unique) return false;\r\n if(cont < 0) return false;\r\n for(let i = pos; i < arr.length; i++){\r\n if(arr[i] == '('){\r\n cont++; \r\n opt = 0;\r\n } \r\n else if(arr[i] == ')'){\r\n if(cont == 0){\r\n dyn[i][cont] = false;\r\n return false;\r\n } \r\n opt = 0;\r\n cont--;\r\n }\r\n else{// if is ?\r\n if(opt > 2){\r\n dyn[i][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n let op1 = (i >= arr.length-1) ? cont+1 == 0 : rec(i+1, cont+1, opt+1);\r\n let op2 = (i >= arr.length-1) ? cont-1 == 0 : rec(i+1, cont-1, opt+1);\r\n // console.log(i, op1, op2, cont, unique);\r\n if(op1 && op2 && unique){\r\n dyn[i][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n dyn[i][cont] = op1 || op2;\r\n return op1 || op2;\r\n }\r\n }\r\n dyn[pos][cont] = (cont == 0);\r\n return cont == 0;\r\n }\r\n\r\n return rec(0, 0, 0) && unique ? 'YES' : 'NO';\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n\r\n const arr = readLine().split('');\r\n let result = myFunc(arr);\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(arr){\r\n if(arr.length %2 != 0) return 'NO';\r\n let unique = true;\r\n let dyn = new Array(arr.length).fill().map(() => new Array());\r\n\r\n function rec(pos, cont, opt){\r\n if(!unique) return false;\r\n if(cont < 0) return false;\r\n for(let i = pos; i < arr.length; i++){\r\n if(arr[i] == '('){\r\n cont++; \r\n opt = 0;\r\n } \r\n else if(arr[i] == ')'){\r\n if(cont == 0){\r\n dyn[i][cont] = false;\r\n return false;\r\n } \r\n opt = 0;\r\n cont--;\r\n }\r\n else{// if is ?\r\n if(opt > 1){\r\n dyn[i][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n let op1 = (i >= arr.length-1) ? cont+1 == 0 : rec(i+1, cont+1, opt+1);\r\n let op2 = (i >= arr.length-1) ? cont-1 == 0 : rec(i+1, cont-1, opt+1);\r\n // console.log(i, op1, op2, cont, unique);\r\n if(op1 && op2 && unique){\r\n dyn[i][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n dyn[i][cont] = op1 || op2;\r\n return op1 || op2;\r\n }\r\n }\r\n dyn[pos][cont] = (cont == 0);\r\n return cont == 0;\r\n }\r\n\r\n return rec(0, 0, 0) && unique ? 'YES' : 'NO';\r\n\r\n}"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n\r\n const arr = readLine().split('');\r\n let result = myFunc(arr);\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(arr){\r\n if(arr.length %2 != 0) return 'NO';\r\n let unique = true;\r\n let dyn = new Array(arr.length).fill().map(() => new Array(arr.length));\r\n function rec(arr, pos, cont){\r\n if(dyn[pos][cont] != undefined) return dyn[pos][cont];\r\n if(!unique) return false;\r\n for(let i = pos; i < arr.length; i++){\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')'){\r\n if(cont == 0){\r\n dyn[i][cont] = false;\r\n return false;\r\n } \r\n cont--;\r\n }\r\n else{// if ?\r\n let new_arr = [...arr];\r\n new_arr[i] = '(';\r\n let op1 = rec(new_arr, i, cont);\r\n new_arr[i] = ')';\r\n let op2 = rec(new_arr, i, cont);\r\n // console.log(i, op1, op2, arr, cont, unique);\r\n if(op1 && op2 && unique){\r\n dyn[i][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n dyn[i][cont] = op1 || op2;\r\n return op1 || op2;\r\n }\r\n }\r\n dyn[pos][cont] = (cont == 0);\r\n return cont == 0;\r\n }\r\n\r\n return rec(arr, 0, 0) && unique ? 'YES' : 'NO';\r\n\r\n\r\n}\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n\r\n const arr = readLine().split('');\r\n let result = myFunc(arr);\r\n console.log(result);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(arr){\r\n if(arr.length %2 != 0) return 'NO';\r\n let unique = true;\r\n let dyn = new Array(arr.length).fill().map(() => new Array(arr.length));\r\n function rec(arr, pos, cont){\r\n if(dyn[pos][cont] != undefined) return dyn[pos][cont];\r\n if(!unique) return false;\r\n for(let i = pos; i < arr.length; i++){\r\n if(arr[i] == '(') cont++;\r\n else if(arr[i] == ')'){\r\n if(cont == 0) return false;\r\n cont--;\r\n }\r\n else{// if ?\r\n let new_arr = [...arr];\r\n new_arr[i] = '(';\r\n let op1 = rec(new_arr, i, cont);\r\n new_arr[i] = ')';\r\n let op2 = rec(new_arr, i, cont);\r\n // console.log(i, op1, op2, arr, cont, unique);\r\n if(op1 && op2 && unique){\r\n dyn[pos][cont] = false;\r\n unique = false;\r\n return false;\r\n }\r\n dyn[pos][cont] = op1 || op2;\r\n return op1 || op2;\r\n }\r\n }\r\n dyn[pos][cont] = (cont == 0);\r\n return cont == 0;\r\n }\r\n\r\n return rec(arr, 0, 0) && unique ? 'YES' : 'NO';\r\n\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 0,\r\n r = 1,\r\n cnt = 0;\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (i === 0) {\r\n l++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (l > r + cnt) return 'NO';\r\n }\r\n if (Math.abs(r - l) === cnt) return 'YES';\r\n }\r\n let l = 1,\r\n r = 0,\r\n cnt = 0,\r\n q = [];\r\n {\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else {\r\n cnt++;\r\n q.push(i);\r\n }\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n }\r\n const a = s.split('');\r\n if (l < r) {\r\n for (let i = 0; i < r - l; i++) {\r\n a[q[i]] = '(';\r\n }\r\n q = q.slice(r - l);\r\n } else if (l > r) {\r\n let t = l - r;\r\n while (t--) {\r\n a[q.pop()] = ')';\r\n }\r\n }\r\n const m = q.length;\r\n for (let i = 0; i < m / 2 - 1; i++) {\r\n a[q[i]] = '(';\r\n a[q[m - i - 1]] = ')';\r\n }\r\n a[q[m / 2 - 1]] = ')';\r\n a[q[m / 2]] = '(';\r\n {\r\n let l = 0,\r\n r = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else r++;\r\n if (r > l) return 'YES';\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 1,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (l + cnt === r) return 'YES';\r\n if (r + cnt === l) return 'YES';\r\n if (cnt === 1) return 'YES';\r\n }\r\n const a = s.split('');\r\n a[0] = '(';\r\n a[n - 1] = ')';\r\n {\r\n let l = 0,\r\n r = 0,\r\n q = [];\r\n let j = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else if (a[i] === ')') r++;else {\r\n if (q.length === j && l === r) {\r\n a[i] = '(';\r\n l++;\r\n } else {\r\n q.push(i);\r\n }\r\n }\r\n if (r > l) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = '(';\r\n l++;\r\n }\r\n if (i === n - 1) {\r\n while (l > r) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = ')';\r\n r++;\r\n }\r\n }\r\n }\r\n }\r\n {\r\n let l = 0,\r\n r = 0,\r\n q = [];\r\n let j = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] === '(') l++;else if (a[i] === ')') r++;else {\r\n if (q.length === j && l === r) {\r\n a[i] = ')';\r\n r++;\r\n } else {\r\n q.push(i);\r\n }\r\n }\r\n if (r < l) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = ')';\r\n r++;\r\n }\r\n if (i === 0) {\r\n while (l < r) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = '(';\r\n l++;\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '?') return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 1,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (l + cnt === r) return 'YES';\r\n if (r + cnt === l) return 'YES';\r\n if (cnt === 1) return 'YES';\r\n }\r\n const a = s.split('');\r\n a[0] = '(';\r\n a[n - 1] = ')';\r\n {\r\n let l = 0,\r\n r = 0,\r\n q = [];\r\n let j = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else if (a[i] === ')') r++;else {\r\n if (q.length === j && l === r) {\r\n a[i] = '(';\r\n l++;\r\n } else {\r\n q.push(i);\r\n }\r\n }\r\n if (r > l) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = '(';\r\n l++;\r\n }\r\n if (i === n - 1) {\r\n while (l > r) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = ')';\r\n r++;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '?') return 'NO';\r\n }\r\n return 'YES';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 1,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (l + cnt === r) return 'YES';\r\n if (r + cnt === l) return 'YES';\r\n if (cnt === 1) return 'YES';\r\n }\r\n const a = s.split('');\r\n a[0] = '(';\r\n a[n - 1] = ')';\r\n {\r\n let l = 0,\r\n r = 0,\r\n q = [];\r\n let j = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else if (a[i] === ')') r++;else {\r\n if (!q.length && l === r) {\r\n a[i] = '(';\r\n l++;\r\n } else {\r\n q.push(i);\r\n }\r\n }\r\n if (r > l) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = '(';\r\n l++;\r\n }\r\n if (i === n - 1) {\r\n while (l > r) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = ')';\r\n r++;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '?') return 'NO';\r\n }\r\n return 'YES';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 1,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (i === n - 1) {\r\n r++;\r\n } else {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n }\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (l + cnt === r) return 'YES';\r\n if (r + cnt === l) return 'YES';\r\n if (cnt === 1) return 'YES';\r\n }\r\n const a = s.split('');\r\n a[0] = '(';\r\n a[n - 1] = ')';\r\n {\r\n let l = 0,\r\n r = 0,\r\n q = [];\r\n let j = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '(') l++;else if (a[i] === ')') r++;else {\r\n q.push(i);\r\n }\r\n if (r > l) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = '(';\r\n l++;\r\n }\r\n if (i === n - 1) {\r\n while (l > r) {\r\n if (j === q.length) return 'NO';\r\n a[q[j++]] = ')';\r\n r++;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '?') return 'NO';\r\n }\r\n return 'YES';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 0,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (l + cnt === r) return 'YES';\r\n if (r + cnt === l) return 'YES';\r\n if (cnt === 1) return 'YES';\r\n }\r\n let l = [1],\r\n r = [];\r\n r[n - 1] = 1;\r\n for (let i = 1; i < n; i++) {\r\n l[i] = l[i - 1];\r\n if (s[i] === '(') l[i] = l[i - 1] + 1;\r\n }\r\n for (let i = n - 2; i >= 0; i--) {\r\n r[i] = r[i + 1];\r\n if (s[i] === ')') r[i]++;\r\n }\r\n let left = false,\r\n right = false;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (s[i] === '?') {\r\n if (!left && !right) {\r\n if (l[i] === r[i]) return 'NO';\r\n if (l[i] > r[i]) {\r\n right = true;\r\n } else if (l[i] < r[i]) {\r\n left = true;\r\n }\r\n } else if (right) {\r\n if (l[i] <= r[i]) return 'NO';\r\n } else {\r\n if (r[i] <= l[i]) return 'NO';\r\n }\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n if (n & 1) return 'NO';\r\n if (s[0] === ')' || s[n - 1] === '(') return 'NO';\r\n {\r\n let l = 0,\r\n r = 0,\r\n cnt = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (s[i] === '(') l++;else if (s[i] === ')') r++;else cnt++;\r\n if (r > l + cnt) return 'NO';\r\n }\r\n if (cnt === 1) return 'YES';\r\n }\r\n let l = [1],\r\n r = [];\r\n r[n - 1] = 1;\r\n for (let i = 1; i < n; i++) {\r\n l[i] = l[i - 1];\r\n if (s[i] === '(') l[i] = l[i - 1] + 1;\r\n }\r\n for (let i = n - 2; i >= 0; i--) {\r\n r[i] = r[i + 1];\r\n if (s[i] === ')') r[i]++;\r\n }\r\n let left = false,\r\n right = false;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (s[i] === '?') {\r\n if (!left && !right) {\r\n if (l[i] === r[i]) return 'NO';\r\n if (l[i] > r[i]) {\r\n right = true;\r\n } else {\r\n left = true;\r\n }\r\n } else if (right) {\r\n if (l[i] <= r[i]) return 'NO';\r\n } else {\r\n if (r[i] <= l[i]) return 'NO';\r\n }\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const arr = [1, 1, 0, 0];\r\n if (s.length & 1) return 'NO';\r\n if (s[0] === ')' || s[s.length - 1] === '(') return 'NO';\r\n for (let i = 1; i < s.length - 1; i++) {\r\n if (s[i] === '(') {\r\n arr[0]++;\r\n arr[1]++;\r\n } else if (s[i] === ')') {\r\n arr[2]++;\r\n arr[3]++;\r\n } else {\r\n arr[1]++;\r\n arr[3]++;\r\n }\r\n if (arr[2] > arr[1]) return 'NO';\r\n }\r\n arr[2]++;\r\n arr[3]++;\r\n const dif = arr[1] - arr[0];\r\n if (arr[0] === arr[3] || arr[1] === arr[2]) return 'YES';\r\n if (arr[0] === arr[1] && dif) return 'NO';\r\n if (Math.abs(arr[2] - arr[0]) === dif) return 'YES';\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const arr = [1, 1, 0, 0];\r\n if (s[0] === ')' || s[s.length - 1] === '(') return 'NO';\r\n for (let i = 1; i < s.length - 1; i++) {\r\n if (s[i] === '(') {\r\n arr[0]++;\r\n arr[1]++;\r\n } else if (s[i] === ')') {\r\n arr[2]++;\r\n arr[3]++;\r\n } else {\r\n arr[1]++;\r\n arr[3]++;\r\n }\r\n if (arr[2] > arr[1]) return 'NO';\r\n }\r\n arr[2]++;\r\n arr[3]++;\r\n const dif = arr[1] - arr[0];\r\n if (dif > 1) return 'NO';\r\n return arr[0] === arr[3] || arr[1] === arr[2] ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const arr = [1, 1, 0, 0];\r\n if (s[0] === ')' || s[s.length - 1] === '(') return 'NO';\r\n for (let i = 1; i < s.length - 1; i++) {\r\n if (s[i] === '(') {\r\n arr[0]++;\r\n arr[1]++;\r\n } else if (s[i] === ')') {\r\n arr[2]++;\r\n arr[3]++;\r\n } else {\r\n arr[1]++;\r\n arr[3]++;\r\n }\r\n if (arr[2] > arr[1]) return 'NO';\r\n }\r\n return arr[0] === arr[3] + 1 || arr[1] === arr[2] + 1 ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const arr = [1, 1, 0, 0];\r\n if (s[0] === ')' || s[s.length - 1] === '(') return 'NO';\r\n for (let i = 1; i < s.length; i++) {\r\n if (i === s.length - 1) {\r\n arr[2]++;\r\n arr[3]++;\r\n } else {\r\n if (s[i] === '(') {\r\n arr[0]++;\r\n arr[1]++;\r\n } else if (s[i] === ')') {\r\n arr[2]++;\r\n arr[3]++;\r\n } else {\r\n arr[1]++;\r\n arr[3]++;\r\n }\r\n }\r\n if (arr[2] > arr[1]) return 'NO';\r\n }\r\n return arr[1] === arr[2] ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const val = {\r\n '?': 0,\r\n '(': 1,\r\n ')': -1\r\n };\r\n\r\n const isFixed = char => {\r\n return char === '(' || char === ')';\r\n };\r\n\r\n const validate = s => {\r\n let balance = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (balance < 0) {\r\n return false;\r\n }\r\n }\r\n return balance === 0;\r\n };\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n if (test === 74) {\r\n console.log(s);\r\n return;\r\n }\r\n\r\n let balance = 0;\r\n let questions = 0;\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (s[i] === '?') {\r\n questions++;\r\n }\r\n }\r\n\r\n let opening = (questions - balance) / 2;\r\n let closing = balance + opening;\r\n\r\n if (opening < 2 && closing < 2) {\r\n output('YES');\r\n continue;\r\n }\r\n\r\n let secondBest = '';\r\n let earlyClosingPlaced = false;\r\n let lateOpeningPlaced = false;\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n if (isFixed(s[i])) {\r\n secondBest += s[i];\r\n continue;\r\n }\r\n if (opening > 1) {\r\n secondBest += '(';\r\n opening--;\r\n } else if (opening === 1 && !earlyClosingPlaced) {\r\n secondBest += ')';\r\n closing--;\r\n earlyClosingPlaced = true;\r\n } else if (opening === 1 && earlyClosingPlaced && !lateOpeningPlaced) {\r\n secondBest += '(';\r\n opening--;\r\n lateOpeningPlaced = true;\r\n } else {\r\n secondBest += ')';\r\n }\r\n }\r\n\r\n const result = validate(secondBest) ? 'NO' : 'YES';\r\n\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const val = {\r\n '?': 0,\r\n '(': 1,\r\n ')': -1\r\n };\r\n\r\n const isFixed = char => {\r\n return char === '(' || char === ')';\r\n };\r\n\r\n const validate = s => {\r\n let balance = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (balance < 0) {\r\n return false;\r\n }\r\n }\r\n return balance === 0;\r\n };\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n\r\n let balance = 0;\r\n let questions = 0;\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (s[i] === '?') {\r\n questions++;\r\n }\r\n }\r\n\r\n let opening = (questions - balance) / 2;\r\n let closing = balance + opening;\r\n\r\n if (opening < 2 && closing < 2) {\r\n output('YES');\r\n continue;\r\n }\r\n\r\n let secondBest = '';\r\n let earlyClosingPlaced = false;\r\n let lateOpeningPlaced = false;\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n if (isFixed(s[i])) {\r\n secondBest += s[i];\r\n continue;\r\n }\r\n if (opening > 1) {\r\n secondBest += '(';\r\n opening--;\r\n } else if (opening === 1 && !earlyClosingPlaced) {\r\n secondBest += ')';\r\n closing--;\r\n earlyClosingPlaced = true;\r\n } else if (opening === 1 && earlyClosingPlaced && !lateOpeningPlaced) {\r\n secondBest += '(';\r\n opening--;\r\n lateOpeningPlaced = true;\r\n } else {\r\n secondBest += ')';\r\n }\r\n }\r\n\r\n const result = validate(secondBest) ? 'NO' : 'YES';\r\n\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const trim = s => {\r\n let check = true;\r\n while (check) {\r\n const idx = s.split('').findIndex(\r\n (x, i) => i < s.length && x === '(' && s[i + 1] === ')'\r\n );\r\n if (idx === -1) {\r\n check = false;\r\n } else {\r\n s = s.replace('()', '');\r\n }\r\n }\r\n return s;\r\n };\r\n\r\n const val = {\r\n '?': 0,\r\n '(': 1,\r\n ')': -1\r\n };\r\n\r\n const validate = s => {\r\n let balance = 0;\r\n for (let i = 0; i < s.length; i++) {\r\n balance += val[s[i]];\r\n if (balance < 0) {\r\n return false;\r\n }\r\n }\r\n return balance === 0;\r\n };\r\n\r\n const countSolutions = s => {\r\n let nextQ = s.indexOf('?');\r\n if (nextQ === -1) {\r\n return validate(s) ? 1 : 0;\r\n }\r\n let lvl = 0;\r\n for (let i = 0; i < nextQ; i++) {\r\n if (lvl < 0) {\r\n return 0;\r\n }\r\n lvl += val[s[i]];\r\n }\r\n if (lvl > 0) {\r\n return countSolutions(s.replace('?', ')')) + countSolutions(s.replace('?', '('));\r\n } else {\r\n return countSolutions(s.replace('?', '('));\r\n }\r\n }\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n s = trim(s);\r\n\r\n let total = 0;\r\n\r\n let questions = s.split('').filter(x => x === '?').length;\r\n if (questions > 6) {\r\n output('NO');\r\n continue;\r\n }\r\n\r\n const countSolutions = s => {\r\n if (total > 1) {\r\n return 0;\r\n }\r\n let nextQ = s.indexOf('?');\r\n if (nextQ === -1) {\r\n let correct = validate(s);\r\n if (correct) {\r\n total++;\r\n }\r\n return correct ? 1 : 0;\r\n }\r\n let lvl = 0;\r\n for (let i = 0; i < nextQ; i++) {\r\n if (lvl < 0) {\r\n return 0;\r\n }\r\n lvl += val[s[i]];\r\n }\r\n if (lvl > 0) {\r\n return countSolutions(s.replace('?', ')')) + countSolutions(s.replace('?', '('));\r\n } else {\r\n return countSolutions(s.replace('?', '('));\r\n }\r\n }\r\n\r\n let sol = countSolutions(s);\r\n let result = 'YES';\r\n if (sol > 1) {\r\n result = 'NO';\r\n }\r\n\r\n output(result);\r\n }\r\n}\r\n"}], "src_uid": "e630243546bf46757ba1acdbdfd475c2"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet standardInputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (rawData) => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split('\\n')\r\n .map((line) => {\r\n return line\r\n .split(' ')\r\n .map((char) =>\r\n Number(char) > -Infinity && Number(char) < Infinity\r\n ? Number(char)\r\n : char\r\n );\r\n });\r\n solveProblem();\r\n});\r\n\r\nconst readLine = () => standardInputString[currentLine++];\r\n\r\nconst solveProblem = function () {\r\n const t = readLine()[0];\r\n for (let i = 0; i < t; i++) {\r\n const [x, n] = readLine();\r\n if (n % 4 === 0) console.log(x);\r\n else if ((n - 1) % 4 === 0) console.log(x % 2 === 0 ? x - n : x + n);\r\n else if ((n - 2) % 4 === 0) console.log(x % 2 === 0 ? x + 1 : x - 1);\r\n else if ((n - 3) % 4 === 0)\r\n console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);\r\n }\r\n};\r\n", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\nwhile(test--)\r\n{\r\n let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\n let x0 = arr[0];\r\n let n = arr[1];\r\n if (x0%2 == 0){\r\n if (n%4 == 0){\r\n console.log(x0);\r\n }\r\n else if (n%4==1){\r\n console.log(x0-n);\r\n }\r\n else if (n%4 == 2){\r\n console.log(x0+1);\r\n }\r\n else if (n%4 == 3){\r\n console.log(x0+1+n);\r\n }\r\n \r\n }\r\n else{\r\n if (n%4 == 0){\r\n console.log(x0);\r\n }\r\n else if (n%4==1){\r\n console.log(x0+n);\r\n }\r\n else if (n%4 == 2){\r\n console.log(x0-1);\r\n }\r\n else if (n%4 == 3){\r\n console.log(x0-1-n);\r\n }\r\n }\r\n\r\n}\r\n return 0;\r\n}"}, {"source_code": "\"use strict\";\r\nexports.__esModule = true;\r\nvar readline = require(\"readline\");\r\nvar process = require(\"process\");\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nvar lines = [];\r\nrl.on(\"line\", function (line) {\r\n lines.push(line);\r\n});\r\nrl.on(\"close\", function () {\r\n main();\r\n});\r\nfunction main() {\r\n for (var i = 1; i < lines.length; i++) {\r\n var fields = lines[i].split(\" \");\r\n var x0 = parseInt(fields[0]);\r\n var n = parseInt(fields[1]);\r\n console.log(solve(x0, n));\r\n }\r\n}\r\nfunction jump(x, i) {\r\n if (x % 2 != 0) {\r\n x += i;\r\n }\r\n else {\r\n x -= i;\r\n }\r\n return x;\r\n}\r\nfunction solve(x0, n) {\r\n var i = 1;\r\n if (i < n) {\r\n i += Math.floor((n - i) / 4) * 4;\r\n }\r\n while (i <= n) {\r\n x0 = jump(x0, i);\r\n i++;\r\n }\r\n return x0;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let [x,n]=readline().split(' ').map(Number);\r\n if(n==0)\r\n {\r\n console.log(x);\r\n continue;\r\n }\r\n let i = 1;\r\n let ans=0;\r\n if(n%4==1)\r\n ans=-n;\r\n else if(n%4==2)\r\n ans=1;\r\n else if(n%4==3)\r\n ans=n+1;\r\n if(Math.abs(x)%2==1)\r\n ans=-ans;\r\n console.log(ans+x);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n}\r\n// let a=readline().split(' ').map(Number)\r\n// a.sort((a,b)=>a-b)\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let [x,n]=readline().split(' ').map(Number);\r\n if(n==0)\r\n {\r\n console.log(x);\r\n continue;\r\n }\r\n let i = 1;\r\n let ans=0;\r\n if(n%4==1)\r\n ans=-n;\r\n else if(n%4==2)\r\n ans=1;\r\n else if(n%4==3)\r\n ans=n+1;\r\n if(Math.abs(x)%2==1)\r\n ans=-ans;\r\n console.log(ans+x);\r\n }\r\n}\r\n"}, {"source_code": "const solveProblem = function (problem) {\r\n for (let i = 0; i < problem.T; i++) {\r\n const [x, n] = problem.testCases[i];\r\n if (n % 4 === 0) {\r\n console.log(x);\r\n } else if ((n - 1) % 4 === 0) {\r\n console.log(x % 2 === 0 ? x - n : x + n);\r\n } else if ((n - 2) % 4 === 0) {\r\n console.log(x % 2 === 0 ? x + 1 : x - 1);\r\n } else if ((n - 3) % 4 === 0) {\r\n console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);\r\n }\r\n }\r\n};\r\n\r\n// -4 -3 -2 -1 0 1 2 3 4 5 6 7\r\n//f\r\n\r\nfunction readInput() {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false,\r\n });\r\n\r\n const problem = {\r\n T: 0,\r\n testCases: [],\r\n // testCase1: [],\r\n // testCase2: [],\r\n };\r\n\r\n let cursor = 1;\r\n\r\n rl.on('line', function (line) {\r\n // TODO: Process input\r\n if (cursor === 1) {\r\n // Get number of test cases from first line\r\n problem.T = +line;\r\n cursor++;\r\n } else {\r\n const [input1, input2] = line.split(' ');\r\n const input = [];\r\n\r\n input.push(+input1);\r\n input.push(+input2);\r\n problem.testCases.push(input);\r\n cursor++;\r\n }\r\n }).on('close', () => {\r\n // Finished processing input, now solve question\r\n solveProblem(problem);\r\n process.exit();\r\n });\r\n}\r\n\r\nreadInput();\r\n\r\n// cat input.txt | node app.js // Terminal command to run the code\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => BigInt(j)))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, n]) {\r\n let sum = a\r\n for (let i = 1n; i <= n; i++) {\r\n sum += (sum % 2n === 0n ? -i : i)\r\n console.log(i,' ',sum)\r\n }\r\n console.log('s',sum)\r\n}\r\n\r\nfunction solve1([a, n]) {\r\n if (a % 2n === 0n) {\r\n switch (n % 4n) {\r\n case 1n: {\r\n console.log((-n + a).toString())\r\n break;\r\n }\r\n case 2n: {\r\n console.log((1n + a).toString())\r\n break;\r\n }\r\n case 3n: {\r\n console.log((n + 1n + a).toString())\r\n break;\r\n }\r\n case 0n: {\r\n console.log((a).toString())\r\n break;\r\n }\r\n }\r\n } else {\r\n switch (n % 4n) {\r\n case 1n: {\r\n console.log((n + a).toString())\r\n break;\r\n }\r\n case 2n: {\r\n console.log((a - 1n).toString())\r\n break;\r\n }\r\n case 3n: {\r\n console.log((-n + a - 1n).toString())\r\n break;\r\n }\r\n case 0n: {\r\n console.log((a).toString())\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve1(inputArr[i])\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n let input = Number(readline().replace('\\r',''));\r\n let output = [];\r\n for(let i=0; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [x0, n] = rna();\r\n\r\n\t\tconst k = n % 4;\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (k == 1) {\r\n\t\t\tans = -n;\r\n\t\t} else if (k == 2) {\r\n\t\t\tans = 1;\r\n\t\t} else if (k == 3) {\r\n\t\t\tans = n + 1;\r\n\t\t}\t\r\n\r\n\t\tif (x0&1) ans = -ans;\r\n\r\n\t\tans += x0;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [x, n] = rna();\r\n\r\n\t\tlet anss = [0, -n, 1, n + 1];\r\n\r\n\t\tlet ans = (x % 2 ? -1 : 1) * anss[n % 4];\r\n\r\n\t\tconsole.log(x + ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var x = k[0], n = k[1];\n var v = [0, -n, 1, n + 1];\n var ans = (x % 2 ? -1 : 1) * v[n % 4];\n console.log(x + ans);\n }\n});\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet standardInputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (rawData) => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split('\\n')\r\n .map((line) => {\r\n return line\r\n .split(' ')\r\n .map((char) =>\r\n Number(char) > -Infinity && Number(char) < Infinity\r\n ? Number(char)\r\n : char\r\n );\r\n });\r\n solveProblem();\r\n});\r\n\r\nconst readLine = () => standardInputString[currentLine++];\r\n\r\nconst solveProblem = function () {\r\n const t = readLine()[0];\r\n console.log(t);\r\n for (let i = 0; i < t; i++) {\r\n const [x, n] = readLine();\r\n if (n % 4 === 0) console.log(x);\r\n else if ((n - 1) % 4 === 0) console.log(x % 2 === 0 ? x - n : x + n);\r\n else if ((n - 2) % 4 === 0) console.log(x % 2 === 0 ? x + 1 : x - 1);\r\n else if ((n - 3) % 4 === 0)\r\n console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);\r\n }\r\n};\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => BigInt(j)))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, n]) {\r\n // let sum = a\r\n // for (let i = 1; i <= b; i++) {\r\n //\r\n // sum += (sum % 2 === 0 ? -i : i)\r\n // console.log(i,' ',sum)\r\n // }\r\n // console.log('s',sum)\r\n if (a % 2n === 0n) {\r\n switch (n % 4n) {\r\n case 1n: {\r\n console.log((-n+a).toString())\r\n break;\r\n }\r\n case 2n: {\r\n console.log((1n+a).toString())\r\n break;\r\n }\r\n case 3n: {\r\n console.log((n+1n+a).toString())\r\n break;\r\n }\r\n case 0n: {\r\n console.log((a).toString())\r\n break;\r\n }\r\n }\r\n } else {\r\n switch (n % 4n) {\r\n case 1n: {\r\n console.log((n+a).toString())\r\n break;\r\n }\r\n case 2n: {\r\n console.log((n-1n).toString())\r\n break;\r\n }\r\n case 3n: {\r\n console.log((-n+a-1n).toString())\r\n break;\r\n }\r\n case 0n: {\r\n console.log((a).toString())\r\n break;\r\n }\r\n }\r\n\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, n]) {\r\n // let sum = a\r\n // for (let i = 1; i <= b; i++) {\r\n //\r\n // sum += (sum % 2 === 0 ? -i : i)\r\n // console.log(i,' ',sum)\r\n // }\r\n // console.log('s',sum)\r\n if (a % 2 === 0) {\r\n switch (n % 4) {\r\n case 1: {\r\n console.log(-n+a)\r\n break;\r\n }\r\n case 2: {\r\n console.log(1+a)\r\n break;\r\n }\r\n case 3: {\r\n console.log(n+1+a)\r\n break;\r\n }\r\n case 0: {\r\n console.log(a)\r\n break;\r\n }\r\n }\r\n } else {\r\n switch (n % 4) {\r\n case 1: {\r\n console.log(n+a)\r\n break;\r\n }\r\n case 2: {\r\n console.log(n-1)\r\n break;\r\n }\r\n case 3: {\r\n console.log(-n+a-1)\r\n break;\r\n }\r\n case 0: {\r\n console.log(a)\r\n break;\r\n }\r\n }\r\n\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n let input = Number(readline().replace('\\r',''));\r\n let output = [];\r\n for(let i=0; i {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nconst n = parseInt(input[0], 10);\nlet secondLine = input[1].split(' ');\nsecondLine = secondLine.map((a) => parseInt(a, 10));\nlet expected = n;\nconst reserve = {};\nlet text = '';\n\nfor (let i=0; i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n var snacksArr = new Array(20000);\n var largest = n;\n var str = '';\n snacks = snacks.split(' ');\n for(let i = 0; i < n; i++){\n var size = snacks[i];\n snacksArr[size] = 1;\n while(snacksArr[largest]){\n str = str + \" \" + largest--;\n }\n if(str){\n console.log(str);\n str = '';\n }\n else{\n console.log('');\n\n }\n \n \n }\n}\n \n// snackTower('10', '5 1 6 2 8 3 4 10 9 7')"}, {"source_code": "var expect = parseInt(readline());\nvar vals = readline().split(\" \").map(Number);\nvar temp = {};\nvar res = [];\n\nfor (var i = 0; i < vals.length; i++) {\n temp[vals[i]] = true;\n \n if (expect in temp) {\n while (expect in temp) {\n res.push(expect);\n delete temp.expect;\n expect = expect - 1;\n }\n \n print(res.join(\" \"));\n res = [];\n } else {\n print(\" \");\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n const b = new Array(n).fill(['']);\n let max = 0;\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] > max) {\n b[i] = range(a[i], max);\n max = a[i];\n }\n }\n for (let i = 0; i < n; i++) {\n print(b[i].join(' ') + '\\n');\n }\n}\nfunction range(hi, lo) {\n const a = [];\n while (hi > lo) {\n a.push(hi--);\n }\n return a;\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\n\nfunction array2d(r,c) {\n let ans =[];\n for(let i = 0; i < r; i++) {\n let rowElements = [];\n for(let j = 0; j < c; j++) {\n rowElements.push(0);\n }\n ans.push(rowElements);\n }\n return ans;\n}\nfunction max(a,b){\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let [n] = readint();\n let s = readint();\n let has = [...s];\n has.fill(0);\n let curr = n - 1;\n s.forEach(element => {\n has[element - 1] = 1;\n if(element - 1 == curr) {\n const begin = curr;\n for(let i = begin; i >=0; i--) {\n if(has[i]) {\n write((i + 1) + \" \");\n curr--;\n }\n else break;\n }\n console.log();\n } else console.log();\n });\n}"}, {"source_code": "var numberOfDays = Number(readline())\n var snaksPerDays = readline().split(' ').map(Number)\n\n var snacks = new Array(numberOfDays).fill(0)\n\n var index = numberOfDays\n for (var i = 0; i < numberOfDays; i++) {\n snacks[snaksPerDays[i] - 1] = 1\n\n var stack = []\n while(snacks[index - 1]) {\n stack.push(index)\n index -= 1\n }\n\n print(stack.join(' '))\n }"}, {"source_code": "/*\n The idea to solve this problem is to seek whether the biggest remaining snacks has fall on that day or not,\n if the bigger snacks has fall, print them, otherwise print empty line.\n \n We could know the biggest remaining snack by exploiting the fact that the size of the snack given \n will be always 1..n\n*/\n\nvar n = parseInt(readline());\nvar sizes = readline().split(' ').map(Number);\nvar current_max = n;\n\nvar has_fall = []; // hash table containing whether certain size snack has fall or not\nvar tmp = []; // temp array for printing single line by using print() in js\n\nfor(var i = 0; i < n; i++) {\n \n var size = sizes[i];\n has_fall[size] = 1;\n \n // exploiting the fact that size will be always 1..n\n while(has_fall[current_max] === 1) {\n \n tmp.push(current_max);\n current_max--; // we could know the next biggest remaining snack size is this\n }\n \n print(tmp.join(' '));\n tmp = [];\n}"}, {"source_code": "var n = parseInt(readline());\nvar sizes = readline().split(' ').map(Number);\nvar current_max = n;\n\nvar has_fall = []; // hash table containing whether certain size snack has fall or not\nvar tmp = []; // temp array for printing single line by using print() in js\n\nfor(var i = 0; i < n; i++) {\n \n var size = sizes[i];\n has_fall[size] = 1;\n \n // exploiting the fact that size will be always 1..n\n while(has_fall[current_max] === 1) {\n \n tmp.push(current_max);\n current_max--; // we could know the next biggest remaining snack size is this\n }\n \n print(tmp.join(' '));\n tmp = [];\n}"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToStringArray = function lineToStringArray(str) {\n return str.split(\" \");\n};\nvar lineToNumberArray = function lineToNumberArray(str) {\n return lineToStringArray(str).map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\nvar readStringsLine = compose(\n readline,\n lineToStringArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),\n n = _readNumbersLine2[0];\n\nvar elements = readNumbersLine();\nvar needed = n;\nvar currElements = [];\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = elements[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var curr = _step.value;\n\n currElements[curr] = true;\n if (curr !== needed) {\n print(\"\");\n continue;\n }\n var res = [];\n while (currElements[needed]) {\n res.push(needed);\n needed--;\n }\n print(res.join(\" \"));\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n"}, {"source_code": "\n'use strict';\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n snackTower(inputString[0], inputString[1]);\n});\n\n\nfunction snackTower(numberOfSnacks, snacks) {\n\n let outputArray = [];\n let snacksFrequencyArray = [];\n let currentMax = numberOfSnacks;\n snacks = snacks.split(\" \");\n \n for(let index = 0 ; index < numberOfSnacks ; index++){\n\n snacksFrequencyArray[snacks[index]] = 1\n\n while (snacksFrequencyArray[currentMax]) {\n outputArray.push(currentMax);\n outputArray.push(\" \")\n currentMax--;\n }\n\n outputArray.push(\"\\n\");\n }\n console.log(outputArray.join(\"\"));\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n let next = n;\n let t = [];\n for (let i = 0; i < n; i++) {\n t.unshift(a[i]);\n if (a[i] === next) {\n print(t.join(' '));\n next = t[t.length - 1] - 1;\n t = [];\n }\n print('\\n');\n }\n}\n\n"}, {"source_code": "/** \nAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, \nand she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, \nand the residents should build a Snacktower of them by placing snacks one on another. Of course, \nbig snacks should be at the bottom of the tower, while small snacks should be at the top.\n\nYears passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.\n\n\nHowever, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, \nat some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.\nOf course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.\n\nWrite a program that models the behavior of Ankh-Morpork residents.\n\nInput\nThe first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000) \u2014 the total number of snacks.\n\nThe second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.\n\nOutput\nPrint n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day \nin the order they will do that. If no snack is placed on some day, leave the corresponding line empty.\n\n*/\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n snackTower(inputString[0], inputString[1]);\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction snackTower(numberOfSnacks, snacks) {\n\n let outputArray = [];\n snacks = snacks.split(\" \");\n let frequencyMap = {};\n let outputArrayFrequencyMap = {};\n let currentMax = numberOfSnacks;\n let frequencyMapIndexs = {};\n let lastMax;\n let notSeen = {};\n\n for (let index = 0; index < numberOfSnacks; index++) {\n notSeen[snacks[index]] = 1\n }\n\n for (let index = 0; index < numberOfSnacks; index++) {\n\n delete notSeen[snacks[index]];\n\n if (snacks[index] == currentMax) {\n\n outputArray.push(snacks[index]);\n frequencyMapIndexs[snacks[index]] = outputArray.length - 1\n outputArray.push(\" \");\n let notSeenKeys = Object.keys(notSeen)\n lastMax = currentMax;\n currentMax = notSeenKeys[notSeenKeys.length - 1];\n frequencyMap[lastMax] = currentMax ? currentMax : 0;\n snacks[index] = 0;\n }\n\n if (snacks[index] != currentMax && !frequencyMap[currentMax]) {\n\n if (index != numberOfSnacks - 1)\n outputArray.push(\"\\n\");\n }\n\n }\n\n for (let index = 0; index < outputArray.length; index++) {\n if (outputArray[index] != \"\\n\" && outputArray[index] != \" \") {\n outputArrayFrequencyMap[outputArray[index]] = index;\n }\n }\n\n let frequencyMapKeys = Object.keys(frequencyMap);\n\n\n for (let indexKey = frequencyMapKeys.length - 1; indexKey > -1; indexKey--) {\n\n for (let index = frequencyMapKeys[indexKey] - 1; index > frequencyMap[frequencyMapKeys[indexKey]]; index--) {\n outputArray.splice(outputArray.indexOf(frequencyMapKeys[indexKey]) + 1, 0, \" \" + index)\n // pushArrayAfterMax.push(\" \")\n // pushArrayAfterMax.push(index)\n }\n }\n // frequencyMap[key] = pushArrayAfterMax;\n // pushArrayAfterMax = []\n\n\n // let frequencyMapIndexsKeys = Object.keys(frequencyMapIndexs)\n\n\n // for (let index = frequencyMapIndexsKeys.length - 1; index > -1; index--) {\n\n // outputArray.splice(outputArray.indexOf(frequencyMapIndexsKeys[index]) + 1, 0, ...frequencyMap[frequencyMapIndexsKeys[index]]);\n // }\n\n\n console.log(outputArray.join(\"\"));\n\n}"}, {"source_code": "/** \nAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, \nand she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, \nand the residents should build a Snacktower of them by placing snacks one on another. Of course, \nbig snacks should be at the bottom of the tower, while small snacks should be at the top.\n\nYears passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.\n\n\nHowever, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, \nat some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.\nOf course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.\n\nWrite a program that models the behavior of Ankh-Morpork residents.\n\nInput\nThe first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000) \u2014 the total number of snacks.\n\nThe second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.\n\nOutput\nPrint n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day \nin the order they will do that. If no snack is placed on some day, leave the corresponding line empty.\n\n*/\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n snackTower(inputString[0], inputString[1]);\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction snackTower(numberOfSnacks, snacks) {\n\n let outputArray = [];\n snacks = snacks.split(\" \");\n let frequencyMap = {};\n let currentMax = numberOfSnacks;\n\n\n for (let index = 0; index < numberOfSnacks; index++) {\n\n if (Number(snacks[index]) == currentMax) {\n\n outputArray.push(snacks[index]);\n outputArray.push(\" \");\n currentMax--;\n }\n\n if (frequencyMap[currentMax]) {\n\n outputArray.push(frequencyMap[currentMax]);\n outputArray.push(\" \");\n currentMax--;\n }\n\n if (Number(snacks[index]) != currentMax && !frequencyMap[currentMax]) {\n\n if (index != numberOfSnacks - 1)\n outputArray.push(\"\\n\");\n\n frequencyMap[snacks[index]] = snacks[index];\n }\n\n }\n\n for (let index = 0; index < outputArray.length; index++) {\n if (frequencyMap[outputArray[index]])\n delete frequencyMap[outputArray[index]]\n }\n\n Object.keys(frequencyMap).forEach(key => {\n outputArray.push(frequencyMap[key]);\n });\n\n console.log(outputArray.join(\"\"));\n\n}"}, {"source_code": "/** \nAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, \nand she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, \nand the residents should build a Snacktower of them by placing snacks one on another. Of course, \nbig snacks should be at the bottom of the tower, while small snacks should be at the top.\n\nYears passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.\n\n\nHowever, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, \nat some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.\nOf course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.\n\nWrite a program that models the behavior of Ankh-Morpork residents.\n\nInput\nThe first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000) \u2014 the total number of snacks.\n\nThe second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.\n\nOutput\nPrint n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day \nin the order they will do that. If no snack is placed on some day, leave the corresponding line empty.\n\n*/\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n snackTower(inputString[0], inputString[1]);\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction snackTower(numberOfSnacks, snacks) {\n\n let outputArray = [];\n snacks = snacks.split(\" \");\n let frequencyMap = {};\n let currentMax = numberOfSnacks;\n\n\n for (let index = 0; index < numberOfSnacks; index++) {\n\n if (Number(snacks[index]) == currentMax) {\n\n outputArray.push(snacks[index]);\n outputArray.push(\" \");\n currentMax--;\n }\n\n if (frequencyMap[currentMax]) {\n\n outputArray.push(frequencyMap[currentMax]);\n outputArray.push(\" \");\n currentMax--;\n }\n\n if (Number(snacks[index]) != currentMax && !frequencyMap[currentMax]) {\n\n if (index != numberOfSnacks - 1)\n outputArray.push(\"\\n\");\n\n frequencyMap[snacks[index]] = snacks[index];\n }\n\n }\n\n for (let index = 0; index < outputArray.length; index++) {\n if (frequencyMap[outputArray[index]])\n delete frequencyMap[outputArray[index]]\n }\n\n let frequencyMapKeys = Object.keys(frequencyMap)\n\n for (let index = frequencyMapKeys.length - 1; index > -1; index--) {\n \n if (index != frequencyMapKeys.length - 1) {\n outputArray.push(\" \");\n }\n \n outputArray.push(frequencyMap[frequencyMapKeys[index]]);\n }\n\n\n console.log(outputArray.join(\"\"));\n\n}"}, {"source_code": "/** \nAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, \nand she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, \nand the residents should build a Snacktower of them by placing snacks one on another. Of course, \nbig snacks should be at the bottom of the tower, while small snacks should be at the top.\n\nYears passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.\n\n\nHowever, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, \nat some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.\nOf course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.\n\nWrite a program that models the behavior of Ankh-Morpork residents.\n\nInput\nThe first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100\u2009000) \u2014 the total number of snacks.\n\nThe second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.\n\nOutput\nPrint n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day \nin the order they will do that. If no snack is placed on some day, leave the corresponding line empty.\n\n*/\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n snackTower(inputString[0], inputString[1]);\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction snackTower(numberOfSnacks, snacks) {\n\n let outputArray = [];\n snacks = snacks.split(\" \");\n let frequencyMap = {};\n let currentMax = numberOfSnacks;\n let lastMax;\n let notSeen = {};\n\n for (let index = 0; index < numberOfSnacks; index++) {\n notSeen[snacks[index]] = 1\n }\n\n for (let index = 0; index < numberOfSnacks; index++) {\n\n delete notSeen[snacks[index]];\n\n if (snacks[index] == currentMax) {\n\n outputArray.push(snacks[index]);\n outputArray.push(\" \");\n let notSeenKeys = Object.keys(notSeen)\n lastMax = currentMax;\n currentMax = notSeenKeys[notSeenKeys.length - 1];\n for(let index = lastMax -1 ; index > currentMax ; index--){\n outputArray.push(index);\n outputArray.push(\" \");\n }\n snacks[index] = 0;\n\n }\n\n if (snacks[index] != currentMax && !frequencyMap[currentMax]) {\n\n if (index != numberOfSnacks - 1)\n outputArray.push(\"\\n\");\n\n // frequencyMap[snacks[index]] = snacks[index];\n }\n\n }\n\n\n console.log(outputArray.join(\"\"));\n\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\n\nfunction array2d(r,c) {\n let ans =[];\n for(let i = 0; i < r; i++) {\n let rowElements = [];\n for(let j = 0; j < c; j++) {\n rowElements.push(0);\n }\n ans.push(rowElements);\n }\n return ans;\n}\nfunction max(a,b){\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let [n] = readint();\n let s = readint();\n let has = [...s];\n has.fill(0);\n let curr = n - 1;\n s.forEach(element => {\n has[element - 1] = 1;\n if(element - 1 == curr) {\n const begin = curr;\n for(let i = begin; i >=0; i--) {\n if(has[i]) {\n write((i + 1) + \" \");\n curr--;\n }\n else break;\n }\n console.log();\n }\n });\n}"}, {"source_code": "'use strict';\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n n = parseInt(n)\n // snacks = snacks.toString();\n // snacks = snacks.split(' ') \n var display = {};\n var delayed = new Array(n);\n var newDelayed = new Array(n);\n newDelayed.fill('');\n delayed.fill('');\n var delayedNumber = n;\n for (let i = 0; i < n; i++) { \n var num = n - i;\n if (snacks[i] != delayedNumber) {\n display[i] = '\\n';\n console.log(\"\\n\");\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[i + 1] = { queue: delayed };\n }\n else if (snacks[i] == delayedNumber) {\n var newArr = new Array(delayedNumber);\n var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;\n var delayedNumberToDsiplayIndex = delayed.length - snacks[i];\n if (lastDisplayedIndex)\n display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];\n else {\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[lastDisplayedIndex] = { queue: delayed };\n }\n newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1) \n var str = JSON.stringify(newArr); \n str = str.replace(/,/g,' ')\n str = str.replace(/\"/g,' ')\n str = str.replace('[',' ')\n str = str.replace(']',' ')\n console.log(str);\n delayed = newDelayed;\n delayedNumber = num - 1;\n\n }\n }\n return 0;\n}\n// snackTower('3', [3,1,2])"}, {"source_code": "'use strict';\n \nlet inputString = '';\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n var snacksArr = new Array(20000);\n var largest = n;\n snacks = snacks.split(' ');\n for(let i = 0; i < n; i++){\n var size = snacks[i];\n snacksArr[size] = 1;\n while(snacksArr[largest]){\n console.log(largest--);\n }\n console.log('');\n }\n}\n \n// snackTower('10', '5 1 6 2 8 3 4 10 9 7')"}, {"source_code": "'use strict';\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n n = parseInt(n)\n snacks = snacks.toString();\n snacks = snacks.split(' ') \n var display = {};\n var delayed = new Array(n);\n var newDelayed = new Array(n);\n newDelayed.fill('');\n delayed.fill('');\n var delayedNumber = n;\n for (let i = 0; i < n; i++) { \n var num = n - i;\n if (snacks[i] != delayedNumber) {\n display[i] = '\\n';\n console.log(\"\\n\");\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[i + 1] = { queue: delayed };\n }\n else if (snacks[i] == delayedNumber) {\n var newArr = new Array(delayedNumber);\n var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;\n var delayedNumberToDsiplayIndex = delayed.length - snacks[i];\n if (lastDisplayedIndex)\n display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];\n else {\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[lastDisplayedIndex] = { queue: delayed };\n }\n newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1) \n var str = JSON.stringify(newArr); \n str = str.replace(/,/g,' ')\n str = str.replace(/\"/g,' ')\n str = str.replace('[',' ')\n str = str.replace(']',' ')\n console.log(str);\n delayed = newDelayed;\n delayedNumber = num - 1;\n\n }\n }\n return 0;\n}\n// snackTower('3', [3,1,2])"}, {"source_code": "'use strict';\n \nlet inputString = '';\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n var snacksArr = new Array(20000);\n var largest = n;\n snacks = snacks.split(' ');\n for(let i = 0; i < n; i++){\n var size = snacks[i];\n snacksArr[size] = 1;\n while(snacksArr[largest]){\n console.log(largest--);\n }\n console.log('');\n }\n}\n \nsnackTower('10', '5 1 6 2 8 3 4 10 9 7')"}, {"source_code": "'use strict';\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n n = parseInt(n)\n snacks = snacks.toString();\n snacks = snacks.split(' ') \n var display = {};\n var delayed = new Array(n);\n var newDelayed = new Array(n);\n newDelayed.fill('');\n delayed.fill('');\n var delayedNumber = n;\n for (let i = 0; i < n; i++) { \n var num = n - i;\n if (snacks[i] != delayedNumber) {\n display[i] = '0';\n // console.log(\"i\");\n \n console.log('');\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[i + 1] = { queue: delayed };\n }\n else if (snacks[i] == delayedNumber) {\n var newArr = new Array(delayedNumber);\n var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;\n var delayedNumberToDsiplayIndex = delayed.length - snacks[i];\n if (lastDisplayedIndex)\n display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];\n else {\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[lastDisplayedIndex] = { queue: delayed };\n }\n newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1) \n var str = JSON.stringify(newArr); \n str = str.replace(/,/g,' ')\n str = str.replace(/\"/g,'')\n str = str.replace('[','')\n str = str.replace(']','')\n console.log(str);\n delayed = newDelayed;\n delayedNumber = num - 1;\n\n }\n }\n return 0;\n}\n\n// snackTower('3', '3 1 2')"}, {"source_code": "'use strict';\n \nlet inputString = '';\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n n = parseInt(n)\n snacks = snacks.toString();\n snacks = snacks.split(' ') \n var display = {};\n var delayed = new Array(n);\n var newDelayed = new Array(n);\n newDelayed.fill('');\n delayed.fill('');\n var delayedNumber = n;\n for (let i = 0; i < n; i++) { \n var num = n - i;\n if (snacks[i] != delayedNumber) {\n display[i] = '0';\n // console.log(\"i\");\n \n console.log('');\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[i + 1] = { queue: delayed };\n }\n else if (snacks[i] == delayedNumber) {\n var newArr = new Array(delayedNumber);\n var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;\n var delayedNumberToDsiplayIndex = delayed.length - snacks[i];\n if (lastDisplayedIndex)\n display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];\n else {\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[lastDisplayedIndex] = { queue: delayed };\n }\n newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1) \n var str = JSON.stringify(newArr); \n str = str.replace(/,/g,' ')\n str = str.replace(/\"/g,'')\n str = str.replace('[','')\n str = str.replace(']','')\n console.log(str);\n delayed = newDelayed;\n delayedNumber = num - 1;\n \n }\n }\n return 0;\n}\n \n// snackTower('3', '3 1 2')"}, {"source_code": "'use strict';\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n snackTower(inputString[0], inputString[1]);\n});\nfunction snackTower(n, snacks) {\n n = parseInt(n)\n snacks = snacks.toString();\n snacks = snacks.split(' ') \n var display = {};\n var delayed = new Array(n);\n var newDelayed = new Array(n);\n newDelayed.fill('');\n delayed.fill('');\n var delayedNumber = n;\n for (let i = 0; i < n; i++) { \n var num = n - i;\n if (snacks[i] != delayedNumber) {\n display[i] = '\\n';\n console.log(\"\\n\");\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[i + 1] = { queue: delayed };\n }\n else if (snacks[i] == delayedNumber) {\n var newArr = new Array(delayedNumber);\n var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;\n var delayedNumberToDsiplayIndex = delayed.length - snacks[i];\n if (lastDisplayedIndex)\n display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];\n else {\n var delayedIndex = delayed.length - snacks[i];\n delayed[delayedIndex] = snacks[i];\n display[lastDisplayedIndex] = { queue: delayed };\n }\n newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1) \n var str = JSON.stringify(newArr); \n str = str.replace(/,/g,' ')\n str = str.replace(/\"/g,'')\n str = str.replace('[','')\n str = str.replace(']','')\n console.log(str);\n delayed = newDelayed;\n delayedNumber = num - 1;\n\n }\n }\n return 0;\n}\n// snackTower('3', '3 1 2')"}, {"source_code": "var numberOfDays = Number(readline())\n var snaksPerDays = readline().split(' ').map(Number)\n\n var snacks = new Array(numberOfDays).fill(0)\n\n var index = numberOfDays\n for (var i = 0; i < numberOfDays; i++) {\n snacks[snaksPerDays[i] - 1] = 1\n\n var stack = []\n while(snacks[index - 1]) {\n stack.push(index)\n index -= 1\n }\n\n print(stack.reverse().join(' '))\n }"}, {"source_code": " var numberOfDays = Number(readline())\n var snaksPerDays = readline().split(' ').map(Number)\n\n var lookingFor = numberOfDays\n var stack = []\n var result = new Array(numberOfDays).fill(\"\")\n for (var i = 0; i < numberOfDays; i++) {\n stack.push(snaksPerDays[i])\n\n if (snaksPerDays[i] === lookingFor) {\n result[i] = stack.reverse().join(' ')\n lookingFor -= stack.length\n stack = []\n }\n }\n\n for (var i = 0; i < numberOfDays; i++) {\n print(result[i])\n }"}, {"source_code": "var n = parseInt(readline()),\n snacks = readline().split(' ').map(Number),\n snacks_ordered = JSON.parse(JSON.stringify(snacks)).sort(function(a, b){ return b - a }),\n tmp = [];\n\nwhile(snacks_ordered.length > 0 && snacks.length > 0) {\n \n var current_max = snacks_ordered.shift();\n if(snacks.indexOf(current_max) !== -1) {\n \n while(snacks[0] !== current_max) {\n \n tmp.push(snacks.shift())\n print('');\n }\n \n tmp.push(snacks.shift()); // push current_max\n tmp.sort(function(a, b){ return b - a });\n \n print(tmp.join(' '));\n tmp = [];\n }\n}"}, {"source_code": "var expect = parseInt(readline());\nvar vals = readline().split(\" \").map(Number);\nvar temp = [];\n\nfor (var i = 0; i < vals.length; i++) {\n temp.push(vals[i]);\n if (vals[i] === expect) {\n temp = temp.sort((a, b) => b - a);\n expect = temp[temp.length - 1] - 1;\n print(temp.join(\" \"));\n temp = [];\n } else {\n print(\" \");\n }\n}"}], "src_uid": "3d648acee2abbf834f865b582aa9b7bc"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let s = $(), n = s.length;\n let n2 = 1 << Math.ceil(Math.log2(n));\n let it = Array(n2 * 2);\n For(n2, n2 + n2 - 1, i => {\n it[i] = {\n opt: 0,\n open: s[i - n2] == '(' ? 1 : 0,\n close: s[i - n2] == ')' ? 1 : 0,\n }\n })\n // log(it)\n let merge = (l, r) => {\n let m = min(l.open, r.close)\n return {\n opt: l.opt + r.opt + m,\n open: l.open + r.open - m,\n close: l.close + r.close - m\n }\n }\n ForR(n2 - 1, 1, i => { it[i] = merge(it[i << 1], it[i << 1 | 1]) })\n // log(it)\n let query = (l, r) => { //[l, r)\n let r1 = { opt: 0, open: 0, close: 0 };\n let r2 = { opt: 0, open: 0, close: 0 };\n for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {\n // log(res, l, r)\n if (l & 1) r1 = merge(r1, it[l++])\n // log(res)\n if (r & 1) r2 = merge(it[--r], r2)\n // log(res)\n }\n return merge(r1, r2);\n }\n let q = $(), l, r\n while (q--) {\n l = +$();\n r = +$();\n out.push(query(l - 1, r).opt * 2)\n }\n log(out.join('\\n'))\n}\n", "positive_code": [{"source_code": "var cad;\nvar Base;\nvar T;\nfunction nodo(car){\n if(car){\n if(car==\"(\"){\n this.I = 0;\n this.D = 1;\n }\n else {\n this.I = 1;\n this.D = 0;\n }\n this.mx = 0;\n }\n else {\n this.I = 0;\n this.D = 0;\n this.mx = 0;\n }\n}\nnodo.prototype.merge = function(a,b){\n var tmp = Math.min(a.D,b.I);\n this.mx = a.mx + b.mx + tmp;\n this.I = a.I+b.I-tmp;\n this.D = a.D+b.D-tmp;\n}\n\nfunction init(id,L,R){\n if(L==R) T[id] = new nodo(cad.charAt(L));\n else {\n var a = id<<1;\n var M = (L+R)>>1;\n init(a,L,M);\n init(a|1,M+1,R);\n T[id] = new nodo();\n T[id].merge(T[a],T[a|1]);\n }\n}\nvar I,J;\nfunction query(id, L, R){\n if(I<=L && R<=J){\n\t//\tprint(\"ans\",L,R);\n return T[id];\n }\n else {\n var a = id<<1; \n var M = (L+R)>>1;\n if(J<=M) return query(a,L,M);\n else if(I>M) return query(a|1,M+1,R);\n else {\n var ans = new nodo();\n ans.merge(query(a,L,M),query(a|1,M+1,R));\n return ans;\n }\n }\n}\nfunction calc(sz){\n\tsz--;\n//\tprint(\"es \"+sz);\n\tvar p = 1;\n\twhile(p<=sz){\n\t\tp<<=1;\n// print(p);\n\t}\n\treturn p<<1;\n}\nfunction main() {\n\tcad = next();\n\tvar n = nextInt();\n\t//print(cad);\n\t//print(n);\n\tBase = new Array(cad.length+1);\n\tT = new Array(calc(cad.length));\n\t//var x = new nodo(cad.charAt(0));\n\t//print(x.I,x.D,x.mx);\n\t//print(\"antes\");\n\t//print(cad.length-1);\n\tinit(1,0,cad.length-1);\n\t\n //print(\"desp\");\n for(var i = 0;i < n;i++){\n I = nextInt();\n //print(\" I \"+I);\n J = nextInt();\n // print(\" * \"+I+\" \"+J);\n \n I--;\n J--;\n print(query(1,0,cad.length-1).mx*2);\n }\t\n}\n\nvar tokens = [];\nvar tokenPos = 0;\nfunction next(){\n //print(tokenPos,\" >=\", tokens.length);\n\twhile(tokenPos >= tokens.length){\n\t\ttokens = readline().split(/[\\s]+/);\n\t\ttokenPos = 0;\n\t\t}\n\t//\tprint(\"lei\",tokens);\n\t//print(\"es \",tokens);\n//\tprint(\"retornare \"+tokens[tokenPos]+\" pos \"+tokenPos);\n\treturn tokens[tokenPos++];\n\t}\nfunction nextInt(){\n\treturn parseInt(next());\n}\nmain();"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let time = Date.now();\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let s = $(), n = s.length;\n let n2 = 1 << Math.ceil(Math.log2(n));\n let it = Array(n2 * 2);\n For(n2, n2 + n2 - 1, i => {\n it[i] = {\n opt: 0,\n open: s[i - n2] == '(' ? 1 : 0,\n close: s[i - n2] == ')' ? 1 : 0,\n }\n })\n // log(it)\n let merge = (l, r) => {\n let m = min(l.open, r.close)\n return {\n opt: l.opt + r.opt + m,\n open: l.open + r.open - m,\n close: l.close + r.close - m\n }\n }\n ForR(n2 - 1, 1, i => { it[i] = merge(it[i << 1], it[i << 1 | 1]) })\n // log(it)\n let query = (l, r) => { //[l, r)\n let res = { opt: 0, open: 0, close: 0 };\n for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {\n // log(res, l, r)\n if (l & 1) res = merge(res, it[l++])\n // log(res)\n if (r & 1) res = merge(res, it[--r])\n // log(res)\n }\n return res;\n }\n let q = $(), l, r\n while (q--) {\n l = +$();\n r = +$();\n out.push(query(l - 1, r).opt * 2)\n }\n log(out.join('\\n'))\n}\n"}], "src_uid": "a3e88504793c44fb3110a322d9dbdf17"} {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var t = rdN();\n loop:while (t --> 0) {\n var n = rdN();\n var D = rdS().split('').map((v, i) => ({v: v, i: i})).sort((a,b) => {\n if (a.v != b.v) {\n return a.v - b.v;\n }\n return a.i - b.i;\n });\n //prOb(D)\n \n var res = crAr(n);\n var last = -1;\n var color = 1;\n var firstMissed = null;\n for (var i = 0; i < n; ++i) {\n var value = D[i].v;\n var index = D[i].i;\n if (index > last && (!firstMissed || firstMissed >= value)) {\n res[index] = color;\n last = index;\n } else if (!firstMissed) {\n firstMissed = value;\n }\n }\n var last = -1;\n var color = 2;\n for (var i = 0; i < n; ++i) {\n var value = D[i].v;\n var index = D[i].i;\n if (res[index]) {\n continue;\n }\n \n if (index > last) {\n res[index] = color;\n last = index;\n } else {\n pr('-');\n continue loop;\n }\n }\n pr(res.join(''));\n //wr(123)\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();", "positive_code": [{"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split('').map(function (value) {\n return parseInt(value);\n });\n};\n\nfunction coloredSequences(seq) {\n var coloredSequences = [];\n\n for (var i = 0; i < 10; i++) {\n var coloredSequence = [];\n var p = 2;\n\n for (var j = 0; j < seq.length; j++) {\n if (seq[j] < i) {\n coloredSequence.push(1);\n } else if (seq[j] > i) {\n p = 1;\n coloredSequence.push(2);\n } else {\n coloredSequence.push(p);\n }\n }\n\n coloredSequences.push(coloredSequence);\n }\n\n return coloredSequences;\n}\n\nfunction rightColoredSequence(coloredSequences, seq) {\n for (var i = 0; i < coloredSequences.length; i++) {\n var color1Element = -1;\n var color2Element = -1;\n var right = true;\n var coloredSequence = coloredSequences[i];\n\n for (var j = 0; j < seq.length; j++) {\n if (coloredSequence[j] === 1) {\n if (seq[j] >= color1Element) {\n color1Element = seq[j];\n } else {\n right = false;\n break;\n }\n } else {\n if (seq[j] >= color2Element) {\n color2Element = seq[j];\n } else {\n right = false;\n break;\n }\n }\n }\n\n if (right) {\n return coloredSequence;\n }\n }\n\n return undefined;\n}\n\nfunction solve() {\n var length = parseInt(readline());\n var sequence = readline().getNumArray();\n var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);\n\n if (rightSequence === undefined) {\n write('-\\n');\n } else {\n write(rightSequence.join('') + '\\n');\n }\n}\n\nvar n = parseInt(readline());\n\nfor (var i = 0; i < n; i++) {\n solve();\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split('').map(function (value) {\n return parseInt(value);\n });\n};\n\nfunction coloredSequences(seq) {\n var coloredSequences = [];\n\n for (var i = 0; i < 10; i++) {\n var coloredSequence = [];\n var p = 2;\n\n for (var j = 0; j < seq.length; j++) {\n if (seq[j] < i) {\n coloredSequence.push(1);\n } else if (seq[j] > i) {\n p = 1;\n coloredSequence.push(2);\n } else {\n coloredSequence.push(p);\n }\n }\n\n coloredSequences.push(coloredSequence);\n }\n\n return coloredSequences;\n}\n\nfunction rightColoredSequence(coloredSequences, seq) {\n for (var i = 0; i < coloredSequences.length; i++) {\n var color1Element = -1;\n var color2Element = -1;\n var right = true;\n var coloredSequence = coloredSequences[i];\n\n for (var j = 0; j < seq.length; j++) {\n if (coloredSequence[j] === 1) {\n if (seq[j] >= color1Element) {\n color1Element = seq[j];\n } else {\n right = false;\n break;\n }\n } else {\n if (seq[j] >= color2Element) {\n color2Element = seq[j];\n } else {\n right = false;\n break;\n }\n }\n }\n\n if (right) {\n return coloredSequence;\n }\n }\n\n return undefined;\n}\n\nfunction solve() {\n var length = parseInt(readline());\n var sequence = readline().getNumArray();\n var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);\n\n if (rightSequence === undefined) {\n write('-');\n } else {\n write(rightSequence.join(''));\n }\n}\n\nvar n = readline().getNumArray()[0];\n\nfor (var i = 0; i < n; i++) {\n solve();\n}"}, {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split('').map(function (value) {\n return parseInt(value);\n });\n};\n\nfunction coloredSequences(seq) {\n var coloredSequences = [];\n\n for (var i = 0; i < 10; i++) {\n var coloredSequence = [];\n var p = 2;\n\n for (var j = 0; j < seq.length; j++) {\n if (seq[j] < i) {\n coloredSequence.push(1);\n } else if (seq[j] > i) {\n p = 1;\n coloredSequence.push(2);\n } else {\n coloredSequence.push(p);\n }\n }\n\n coloredSequences.push(coloredSequence);\n }\n\n return coloredSequences;\n}\n\nfunction rightColoredSequence(coloredSequences, seq) {\n for (var i = 0; i < coloredSequences.length; i++) {\n var color1Element = -1;\n var color2Element = -1;\n var right = true;\n var coloredSequence = coloredSequences[i];\n\n for (var j = 0; j < seq.length; j++) {\n if (coloredSequence[j] === 1) {\n if (seq[j] >= color1Element) {\n color1Element = seq[j];\n } else {\n right = false;\n break;\n }\n } else {\n if (seq[j] >= color2Element) {\n color2Element = seq[j];\n } else {\n right = false;\n break;\n }\n }\n }\n\n if (right) {\n return coloredSequence;\n }\n }\n\n return undefined;\n}\n\nfunction solve() {\n var length = parseInt(readline());\n var sequence = readline().getNumArray();\n var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);\n\n if (rightSequence === undefined) {\n write('-\\n');\n } else {\n write(rightSequence.join('') + '\\n');\n }\n}\n\nvar n = readline().getNumArray()[0];\n\nfor (var i = 0; i < n; i++) {\n solve();\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var t = rdN();\n loop:while (t --> 0) {\n var n = rdN();\n var D = rdS().split('').map((v, i) => ({v: v, i: i})).sort((a,b) => {\n if (a.v != b.v) {\n return a.v - b.v;\n }\n return a.i - b.i;\n });\n //prOb(D)\n \n var res = crAr(n);\n var last = -1;\n var color = 1;\n for (var i = 0; i < n; ++i) {\n var value = D[i].v;\n var index = D[i].i;\n if (index > last) {\n res[index] = color;\n last = index;\n }\n }\n var last = -1;\n var color = 2;\n for (var i = 0; i < n; ++i) {\n var value = D[i].v;\n var index = D[i].i;\n if (res[index]) {\n continue;\n }\n \n if (index > last) {\n res[index] = color;\n last = index;\n } else {\n pr('-');\n continue loop;\n }\n }\n pr(res.join(''));\n //wr(123)\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "886f773e75fa3c770fb70133ff1b595b"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let prev = -1;\n const ans = [];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] % 2 === 0) {\n ans.push(i + 1);\n }\n else {\n if (prev === -1) {\n prev = i + 1;\n }\n else {\n ans.push(prev);\n ans.push(i + 1);\n prev = -1;\n }\n }\n }\n\n if (ans.length === 0) {\n console.log(-1);\n }\n else {\n console.log(ans.length);\n console.log(ans.sort((a , b) => a - b).join(' '));\n }\n\n c++;\n});\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = [];\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var list = nextIntArray();\n var odd = [];\n var even = [];\n for(var j = 0; j < n; j++){\n if(list[j] % 2 == 0){\n even.push(j + 1);\n }else{\n odd.push(j + 1);\n }\n }\n if(even.length >= 1){\n output.push(even.length);\n output.push(even.join(\" \"));\n }else if(odd.length >= 2){\n if(odd.length % 2 == 1){\n odd.pop();\n }\n output.push(odd.length);\n output.push(odd.join(\" \"));\n }else{\n output.push(-1);\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n\n for(let i = 0; i < t; i++){\n let n = parseInt(lines[i * 2 + 1]);\n let a = lines[i * 2 + 2].split(\" \").map( function (x) {\n return parseInt(x);\n });\n if(a[0] % 2 === 0)\n answer += '1' + '\\n' + '1' + '\\n';\n else{\n if(n === 1) answer += '-1' + '\\n';\n else {\n for(let j = 1; j < n; j++){\n if(a[j] % 2 !== 0) {\n answer += '2' + '\\n' + '1 ' + (j + 1) + '\\n';\n break;\n }\n else{\n answer += '1' + '\\n' + (j + 1) + '\\n';\n break;\n }\n }\n }\n }\n }\n\n console.log(answer);\n\n});"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n let prev = null\n let found = false\n for (let k = 0; k i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n }\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst main = () => {\n let t = parseInt(readline());\n while(t--) {\n const n = parseInt(readline());\n const a = readline().split(' ').map(x => parseInt(x));\n const evens = [];\n const odds = [];\n for (let i = 0; i < n; i++) {\n if (a[i] % 2 === 0) evens.push([a[i], i])\n if (a[i] % 2 === 1) odds.push([a[i], i])\n }\n if (evens.length > 0) {\n print(1);\n print(evens[0][1] + 1);\n } else if (odds.length >= 2) {\n print(2)\n print(odds.slice(0, 2).map(x => x[1] + 1).join(' '));\n } else {\n print(-1);\n }\n }\n};\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var els = +readline();\n var arr = readNumArray();\n check(arr);\n }\n}\n\nfunction check(arr) {\n if (!arr.length || (arr.length === 1 && arr[0] % 2 === 1)) {\n print(-1);\n return;\n }\n for (var j = 0; j < 2; j++) {\n if (arr[j] % 2 === 0) {\n print(1);\n print(j + 1);\n return;\n } else if (j == 1) {\n print(2);\n print(\"1 2\");\n }\n }\n}\n\nmain()\n"}, {"source_code": "function readStrs(){\n return readline().split(\" \");\n}\nfunction readInts(){\n return readStrs().map(Number);\n}\nfunction main(){\n var t = +readline();\n while(t > 0){\n var n = 0 + readline();\n arr = readInts();\n \n var res = -1;\n var i;\n for(i=0; i= 2){\n print(\"2\\n1 2\");\n }else if(res == -1){\n print(-1)\n }else{\n print(\"1\\n\" + res);\n }\n t = t - 1;\n }\n\n}\n\nmain();"}, {"source_code": "function main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (l) { return l.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var t = lines.shift()[0];\n while (t > 0) {\n var n = lines.shift()[0];\n var a = lines.shift();\n var odds = [];\n var evn = [];\n var i = 0;\n while (odds.length < 2 && i < n && evn.length === 0) {\n if (a[i] % 2 === 1) {\n odds.push(i + 1);\n }\n else {\n evn.push(i + 1);\n }\n i++;\n }\n if (evn.length > 0) {\n console.log(1);\n console.log(evn[0]);\n }\n else if (odds.length < 2) {\n console.log(\"-1\");\n }\n else {\n console.log(odds.length);\n console.log(odds.join(\" \"));\n }\n t--;\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}], "negative_code": [], "src_uid": "3fe51d644621962fe41c32a2d90c7f94"} {"source_code": " var _t = readline();\n var t = parseInt(_t);\n \n for(var _=0;_=0&&Heap[1]-1>=0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`1: ${Heap} ${_Heap}`)\n }\n while(Heap[1]-2>=0&&Heap[0]-1>=0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n // print(`2: ${Heap}`)\n }\n // print(`${count}`)\n _count = count;\n count=0;\n Heap=_Heap;\n \n \n while(Heap[1]-2>=0&&Heap[0]-1>=0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n // print(`3: ${Heap}`)\n }\n \n while(Heap[2]-2>=0&&Heap[1]-1>=0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`4: ${Heap}`)\n }\n // print(`${count}`)\n \n if(count<_count)count = _count;\n print (count);\n \n }", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (a, b, c) => {\n if (c >= 2 * b) return 3 * b;\n b -= c / 2 | 0;\n if (b >= 2 * a) return 3 * (a + c / 2 | 0);\n return 3 * ((b / 2 | 0) + (c / 2 | 0));\n}\n\n\nconst t = +readline();\n\nfor (let i = 0; i < t; i++) {\n const x = readline().split(' ').map(Number);\n print(problem(x[0], x[1], x[2]));\n}\n"}, {"source_code": "var queries = parseInt(readline());\n\n\nfunction main(query) {\n var sum = 0;\n\n if (query[2] > (query[1].length * 2) - 1) {\n return write((3*query[1]) + '\\n');\n } else {\n var add = Math.min(Math.floor(query[2]/2), query[1]);\n sum += add*3;\n query[1] -= add;\n if (query[1] > (query[0] * 2) - 1) {\n return write((3*query[0] + sum) + '\\n');\n } else {\n return write (sum + (3 * Math.min(Math.floor(query[1]/2), query[0])) + '\\n')\n }\n }\n}\n\n// main([1, 4, 2])\n\nfor (var i = 0; i < queries; i++) {\n var query = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n main(query)\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var count = 0;\n while(one[1] > 0 && one[2] > 1){\n one[1]--;\n one[2] -= 2;\n count += 3;\n }\n while(one[0] > 0 && one[1] > 1){\n one[0]--;\n one[1] -= 2;\n count += 3;\n }\n output[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c] = d.split(' ').map(Number);\n let ans = 0;\n\n while (b > 0 && c > 1) {\n b -= 1;\n c -= 2;\n\n ans += 3;\n }\n\n while (a > 0 && b > 1) {\n a -= 1;\n b -= 2;\n\n ans += 3;\n }\n\n console.log(ans);\n\n count++;\n});\n"}, {"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n const [[T], ...S] = input\n .split('\\n')\n .map(line => line\n .split(' ')\n .map(Number));\n\n const result = [];\n\n for (let i = 0; i < T; ++i) {\n const [a, b, c] = S[i];\n let Y = Math.floor(c / 2);\n if (b < Y) Y = b;\n let X = Math.floor((b - Y) / 2);\n if (a < X) X = a;\n result.push(3 * (X + Y));\n }\n\n process.stdout.write(\n result.join('\\n'),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (a, b, c) => {\n if (c >= 2 * b) return 3 * b;\n b -= c / 2 | 0;\n if (b >= 2 * a) return 3 * (a + c / 2 | 0);\n return 3 * ((b / 2 | 0) + (c / 2 | 0));\n}\n\nconst t = +readline();\n\nfor (let i = 0; i < t; i++) {\n print(problem(+readline(), +readline(), +readline()));\n}"}, {"source_code": "var queries = parseInt(readline());\n\n\nfunction main(query) {\n var sum = 0;\n\n if (query[2] > (query[1].length * 2) - 1) {\n return write((3*query[1]) + '\\n');\n } else {\n var add = Math.min(Math.floor(query[2]/2), query[1]);\n sum += add*3;\n query[1] -= add;\n if (query[1] > (query[0] * 2) - 1) {\n return write((3*query[1] + sum) + '\\n');\n } else {\n return write (sum + (3 * Math.min(Math.floor(query[1]/2), query[0])) + '\\n')\n }\n }\n}\n\n// main([5, 3, 2])\n\nfor (var i = 0; i < queries; i++) {\n var query = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n main(query)\n}\n"}, {"source_code": "var queries = parseInt(readline());\n\n\nfunction main(query) {\n var sum = 0;\n\n if (query[2] > (query[1].length * 2) - 1) {\n return write((3*query[1]) + '\\n');\n } else {\n var add = Math.min(Math.floor(query[2]/2), query[1]);\n sum += add*3;\n query[1] -= add;\n if (query[1] > (query[0].length * 2) - 1) {\n return write((3*query[1] + sum) + '\\n');\n } else {\n return write (sum + (3 * Math.floor(query[1]/2)) + '\\n')\n }\n }\n}\n\n// main([5, 3, 2])\n\nfor (var i = 0; i < queries; i++) {\n var query = readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n main(query)\n}\n"}, {"source_code": " var t =readline().split(\"\").map(function(x) { return parseInt(x); });\n\n for(var _=0;_=Math.floor(c/2))\n {\n count+= 3*Math.floor(c/2);\n b=b-Math.floor(c/2);\n c=c-2*Math.floor(c/2);\n }\n \n if(a>=Math.floor(b/2))\n {\n count+= 3*Math.floor(b/2);\n a=a-Math.floor(b/2);\n b=b-2*Math.floor(b/2);\n\n }\n comp = count;\n a=Heap[0];\n b=Heap[1];\n c =Heap[2];\n count = 0;\n \n \n if(a>=Math.floor(b/2))\n {\n count+= 3*Math.floor(b/2);\n a=a-Math.floor(b/2);\n b=b-2*Math.floor(b/2);\n\n \n }\n \n if(b>=Math.floor(c/2))\n {\n count+= 3*Math.floor(c/2);\n b=b-Math.floor(c/2);\n c=c-2*Math.floor(c/2);\n\n }\n if(comp>count)count=comp;\n \n\n\n print(count);\n\n\n }"}, {"source_code": " var _t = readline();\n var t = parseInt(_t);\n \n for(var _=0;_1&&Heap[1]>0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n print(`1: ${Heap} ${_Heap}`)\n }\n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n print(`2: ${Heap}`)\n }\n print(`${count}`)\n _count = count;\n count=0;\n Heap=_Heap;\n\n \n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n print(`3: ${Heap}`)\n }\n\n while(Heap[2]>0&&Heap[1]>1)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n print(`4: ${Heap}`)\n }\n print(`${count}`)\n \n if(count<_count)count = _count;\n print (count);\n\n }"}, {"source_code": " var t =readline().split(\"\").map(function(x) { return parseInt(x); });\n\n for(var _=0;_1&&Heap[1]>1)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n }\n\n while(Heap[1]>1&&Heap[0]>1)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n }\n\n print (count);\n\n }"}, {"source_code": " var _t = readline();\n var t = parseInt(_t);\n \n for(var _=0;_1&&Heap[1]>0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`1: ${Heap} ${_Heap}`)\n }\n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n // print(`2: ${Heap}`)\n }\n // print(`${count}`)\n _count = count;\n count=0;\n Heap=_Heap;\n\n \n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n // print(`3: ${Heap}`)\n }\n\n while(Heap[2]>0&&Heap[1]>1)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`4: ${Heap}`)\n }\n // print(`${count}`)\n \n if(count<_count)count = _count;\n print (count);\n\n }"}, {"source_code": "\n var _t = readline();\n var t = parseInt(_t);\n \n for(var _=0;_1&&Heap[1]>0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`1: ${Heap} ${_Heap}`)\n }\n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n print(`2: ${Heap}`)\n }\n //print(`${count}`)\n _count = count;\n count=0;\n Heap=_Heap;\n\n \n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n // print(`3: ${Heap}`)\n }\n\n while(Heap[2]>0&&Heap[1]>1)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`4: ${Heap}`)\n }\n // print(`${count}`)\n \n if(count<_count)count = _count;\n print (count);\n\n }"}, {"source_code": "var t =readline().split(\"\").map(function(x) { return parseInt(x); });\n\n for(var _=0;_=Math.floor(c/2))\n {\n count+= 3*Math.floor(c/2);\n b=b-Math.floor(c/2);\n c=c-2*Math.floor(c/2);\n }\n \n if(a>=Math.floor(b/2))\n {\n count+= 3*Math.floor(b/2);\n a=a-Math.floor(b/2);\n b=b-2*Math.floor(b/2);\n\n }\n }\n else\n {\n if(a>=Math.floor(b/2))\n {\n count+= 3*Math.floor(b/2);\n a=a-Math.floor(b/2);\n b=b-2*Math.floor(b/2);\n\n \n }\n \n if(b>=Math.floor(c/2))\n {\n count+= 3*Math.floor(c/2);\n b=b-Math.floor(c/2);\n c=c-2*Math.floor(c/2);\n\n }\n \n }\n\n print(count);\n\n\n }"}, {"source_code": " var t =readline().split(\"\").map(function(x) { return parseInt(x); });\n \n for(var _=0;_1&&Heap[1]>0)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`1: ${Heap} ${_Heap}`)\n }\n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n //print(`2: ${Heap}`)\n }\n //print(`${count}`)\n _count = count;\n count=0;\n Heap=_Heap;\n\n \n while(Heap[1]>1&&Heap[0]>0)\n {\n count+=3;\n Heap[1]-=2;\n Heap[0]-=1;\n //print(`3: ${Heap}`)\n }\n\n while(Heap[2]>0&&Heap[1]>1)\n {\n count+=3;\n Heap[2]-=2;\n Heap[1]-=1;\n // print(`4: ${Heap}`)\n }\n // print(`${count}`)\n \n if(count<_count)count = _count;\n print (count);\n\n }"}], "src_uid": "14fccd50d5dfb557dd53f2896ed844c3"} {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline();\r\n if(n.length > 12) {\r\n var temp = Math.floor(n / Math.pow(10, 9));\r\n var div = Math.floor(temp / 2050);\r\n if(((temp % 2050) * Math.pow(10, 9) + parseInt(n.slice(n.length - 9, n.length))) % 2050 !== 0) print(-1);\r\n else {\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(div); j++) {\r\n sum += Math.floor((div / Math.pow(10, j))) % 10;\r\n }\r\n n = parseInt(n.slice(n.length - 9, n.length));\r\n n += (temp % 2050) * Math.pow(10, 9);\r\n if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n }\r\n }\r\n else if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n \r\n \r\nfunction main(){\r\n const n = Number(readline());\r\n \r\n for(let i = 0; i < n; i++){\r\n let t = BigInt(readline());\r\n \r\n if(t % 2050n != 0n) console.log(-1);\r\n else{\r\n let product = String(t / 2050n);\r\n let sum = 0;\r\n for(let num of product) {\r\n sum += Number(num);\r\n }\r\n console.log(sum);\r\n }\r\n }\r\n}"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\nclass IO {\n constructor() {\n this.i = 0;\n this.text = void 0;\n this.out = '';\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1517/1517-a.ts\n //////////// LIBS\n\nconst io = new IO();\n\nfunction solve(n) {\n let ret = 0n;\n let max = 2050n * 10n ** 15n;\n\n for (let k = 15; k >= 0; k--, max /= 10n) {\n let count = n / max;\n ret += count;\n n %= max;\n }\n\n if (n) {\n io.writeLine(-1);\n } else {\n io.writeLine(ret.toString());\n }\n}\n\nfunction main() {\n try {\n var _t;\n\n let t = io.nextNum();\n let x = (_t = t) !== null && _t !== void 0 ? _t : 2;\n\n while (t--) {\n let n = io.nextBigInt();\n solve(n);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n) {\n let ret = 0n;\n let max = 2050n * 10n ** 15n;\n for (let k = 15; k >= 0; k--, max /= 10n) {\n let count = n / max;\n ret += count;\n n %= max;\n }\n if (n) {\n io.writeLine(-1);\n }\n else {\n io.writeLine(ret.toString());\n }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextBigInt();\n solve(n);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n) {\n let ret = 0;\n let max = 2050n * 10n ** 15n;\n for (let k = 15; k >= 0; k--, max /= 10n) {\n while (n >= max) {\n n -= max;\n ret++;\n }\n }\n if (n) {\n io.writeLine(-1);\n }\n else {\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextBigInt();\n solve(n);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n) {\n let ret = 0;\n for (let k = BigInt(15); k >= 0; k--) {\n let p = 2050n * 10n ** k;\n while (n >= p) {\n n -= p;\n ret++;\n }\n }\n if (n) {\n io.writeLine(-1);\n }\n else {\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextBigInt();\n solve(n);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n) {\n let ret = 0;\n for (let k = 15; k >= 0; k--) {\n let p = 2050n * 10n ** BigInt(k);\n while (n >= p) {\n n -= p;\n ret++;\n }\n }\n if (n) {\n io.writeLine(-1);\n }\n else {\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextBigInt();\n solve(n);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "(()=>{\"use strict\";var e={176:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=e=>{let t=BigInt(e),o=t/2050n;return t%=2050n,0n===t&&e>=2050n?n(o):-1};const n=e=>e.toString().split(\"\").map(Number).reduce(((e,t)=>e+t))},590:function(e,t,n){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});const s=o(n(176));n(188).testInput(s.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=e=>{const t=n(58).createInterface({input:process.stdin,output:process.stdout});let o=[],s=0;t.on(\"line\",(function(n){if(o.push(n),1===o.length&&(s=+o[0]),o.length===s+1){t.close();for(let t=1;t{const o=n(58).createInterface({input:process.stdin,output:process.stdout});let s=[];o.on(\"line\",(function(e){s.push(e),2===s.length&&(o.close(),console.log(t(s[1].split(\" \").map((e=>+e)))))}))}},58:e=>{e.exports=require(\"readline\")}},t={};!function n(o){var s=t[o];if(void 0!==s)return s.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,n),r.exports}(590)})();"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i BigInt(0)) {\r\n\t\t\tlet mult = BigInt(2050);\r\n\t\t\tconst len = num.toString().length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = BigInt(2050 * (10**len));\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = BigInt(2050 * (10**(len-1)));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= BigInt(mult);\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === BigInt(0)) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var k = 1; k < input.length; k++) {\r\n var n = BigInt(input[k]);\r\n var mod = BigInt(2050);\r\n if (n % mod !== BigInt(0)) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var count = n / mod;\r\n var str = count.toString();\r\n var result = 0;\r\n for (var i = 0; i < str.length; i++) {\r\n result += Number(str[i]);\r\n }\r\n console.log(result);\r\n }\r\n});"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n let n = BigInt(readLine());\r\n n % 2050n === 0n ? print((n/2050n).toString().split('').map(Number).reduce((a,b) => a + b)) : print(-1);\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n "}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var k = 1; k < input.length; k++) {\r\n var n = BigInt(input[k]);\r\n var mod = BigInt(2050);\r\n if (n % mod !== BigInt(0)) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var count = n / mod;\r\n var str = count.toString();\r\n var result = 0;\r\n for (var i = 0; i < str.length; i++) {\r\n result += Number(str[i]);\r\n }\r\n console.log(result);\r\n }\r\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(num) {\r\n if (num < 2050n) {\r\n console.log('-1')\r\n return\r\n }\r\n if (num % 2050n != 0) {\r\n console.log('-1')\r\n return\r\n }\r\n let count = 0n\r\n while (num) {\r\n let a = 2050n\r\n while (a < num) a *= 10n\r\n if (a != num) a /= 10n\r\n num -= a\r\n count++\r\n }\r\n console.log(count.toString())\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(BigInt(inputArr[i]))\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet x = nl.elem(BigInt);\n\t\tlet cnt = 0;\n\t\tfor(let y = 2050n * (10n ** 18n); y >= 2050n; y /= 10n){\n\t\t\twhile (x >= y) {\n\t\t\t\tx -= y;\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\t\t\t\n\t\tans.push(x > 0?-1:cnt);\n\t\t\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = BigInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var array = new Array(18)\r\n var value = 2050n\r\n for (let j = 0; j < 18; j++) {\r\n array[j] = value\r\n value *= 10n\r\n }\r\n var i = 17\r\n var ans = 0\r\n while (n > 0 && i>=0) {\r\n\r\n while (n >= array[i]) {\r\n ans++\r\n n -= array[i]\r\n }\r\n // console.log(i, n, array[i])\r\n i--\r\n }\r\nif(n!==0n) return console.log(-1)\r\n console.log(ans)\r\n })\r\n}\r\n\r\n"}, {"source_code": "var testCount = parseInt(readline());\nfor (var i = 0; i < testCount; i++) {\n var n = readline();\n print(compute(n));\n //console.debug(i, n, compute(n))\n}\nfunction compute(nstr) {\n var digits = nstr.split('');\n var m = 0, r = 0;\n while (digits.length > 0) {\n m = m * 10 + parseInt(digits.shift());\n var _a = divide(m), div_1 = _a[0], rest_1 = _a[1];\n r += div_1;\n m = rest_1;\n }\n var _b = divide(m), div = _b[0], rest = _b[1];\n if (rest > 0)\n return -1;\n return r + div;\n}\nfunction divide(n) {\n var div = Math.floor(n / 2050);\n return [div, n - (div * 2050)];\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/*\nfunction main(){\n const n = Number(readline());\n\n for(let i = 0; i < n; i++){\n const t = Number(readline());\n if(t < 2050) console.log(-1);\n else {\n const product = String(t / 2050);\n let sum = 0;\n for(let num of product){\n sum += Number(num);\n }\n console.log(sum || -1);\n }\n }\n}\n\n*/\n\n\nfunction main(){\n const n = Number(readline());\n\n for(let i = 0; i < n; i++){\n let t = Number(readline());\n\n if(t % 2050 != 0) console.log(-1);\n else {\n let product = Math.floor(t/ 2050);\n let sum = 0;\n while(product >= 1){\n sum += product % 10;\n product = Math.floor(product / 10);\n }\n console.log(sum);\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n const n = Number(readline());\n\n for(let i = 0; i < n; i++){\n const t = Number(readline());\n if(t < 2050) console.log(-1);\n else {\n const product = String(t / 2050);\n let sum = 0;\n for(let num of product){\n sum += Number(num);\n }\n console.log(sum || -1);\n }\n }\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n const n = Number(readline());\n\n for(let i = 0; i < n; i++){\n const t = Number(readline());\n if(t < 2050) console.log(-1);\n else {\n const product = String(t / 2050);\n let sum = 0;\n for(let num of product){\n sum += Number(num);\n }\n console.log(sum);\n }\n }\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n const n = Number(readline());\n\n for(let i = 0; i < n; i++){\n const t = Number(readline());\n if(t % 2050 != 0) console.log(-1);\n else {\n const product = String(t / 2050);\n let sum = 0;\n for(let num of product){\n sum += Number(num);\n }\n console.log(sum);\n }\n }\n}\n\n"}, {"source_code": "// cat input.txt | node problem1.js\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\n/*\nfunction main(){\n const n = Number(readline());\n for(let i = 0 ; i < n ; i++){\n let t = readline();\n let counter = 0;\n\n console.log(t);\n while(Number(t) >= 2050){\n let sub = 2050 * 10**(t.length - 4);\n t = String(Number(t) >= sub ? Number(t) - sub : Number(t) - (sub/10));\n counter++;\n }\n if(t == 0) console.log(counter);\n else console.log(-1);\n }\n} */\n\nfunction main(){\n const n = Number(readline());\n for(let i = 0 ; i < n ; i++){\n let t = Number(readline());\n let abs = t / 2050;\n\n let counter = 0;\n\n if(t % 2050 != 0) console.log(-1);\n else {\n for(let char of String(abs)){\n counter += Number(char);\n }\n console.log(counter);\n }\n }\n}"}, {"source_code": "// cat input.txt | node problem1.js\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main(){\n const n = Number(readline());\n for(let i = 0 ; i < n ; i++){\n let t = readline();\n let counter = 0;\n while(Number(t) >= 2050){\n let sub = 2050 * 10**(t.length - 4);\n t = String(Number(t) >= sub? Number(t) - sub : Number(t) - (sub/10));\n counter++;\n }\n if(t == 0) console.log(counter);\n else console.log(-1);\n }\n}"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n) {\n let ret = 0;\n for (let k = 15; k >= 0; k--) {\n let p = 2050 * 10 ** k;\n while (n >= p) {\n n -= p;\n ret++;\n }\n }\n if (n) {\n io.writeLine(-1);\n }\n else {\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n solve(n);\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "(()=>{\"use strict\";var e={176:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){var t=e,r=t/2050;return 0==(t%=2050)&&e>=2050?n(r):-1};var n=function(e){return e.toString().split(\"\").map(Number).reduce((function(e,t){return e+t}))}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var u=r(n(176));n(188).testInput(u.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],u=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(u=+r[0]),r.length===u+1){t.close();for(var o=1;o{e.exports=require(\"readline\")}},t={};!function n(r){var u=t[r];if(void 0!==u)return u.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(590)})();"}, {"source_code": "(()=>{\"use strict\";var e={176:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){var t=e,r=t/2050;return 0==(t%=2050)&&e>=2050?n(r):-1};var n=function(e){return e.toString().split(\"\").map(Number).reduce((function(e,t){return e+t}))}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var u=r(n(176));n(188).testInput(u.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],u=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(u=+r[0]),r.length===u+1){t.close();for(var o=1;o{e.exports=require(\"readline\")}},t={};!function n(r){var u=t[r];if(void 0!==u)return u.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(590)})();"}, {"source_code": "(()=>{\"use strict\";var e={176:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){var t=e/2050;return 0==(e%=2050)?n(t):-1};var n=function(e){return e.toString().split(\"\").map(Number).reduce((function(e,t){return e+t}))}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var u=r(n(176));n(188).testInput(u.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],u=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(u=+r[0]),r.length===u+1){t.close();for(var o=1;o{e.exports=require(\"readline\")}},t={};!function n(r){var u=t[r];if(void 0!==u)return u.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(590)})();"}, {"source_code": "(()=>{\"use strict\";var e={176:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){return e<2050?-1:(t=e/2050,0==(e%=2050)?n(t):-1);var t};var n=function(e){return e.toString().split(\"\").map(Number).reduce((function(e,t){return e+t}),0)}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var u=r(n(176));n(188).testInput(u.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],u=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(u=+r[0]),r.length===u+1){t.close();for(var o=1;o{e.exports=require(\"readline\")}},t={};!function n(r){var u=t[r];if(void 0!==u)return u.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(590)})();"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i 0) {\r\n\t\t\tlet mult = 2050;\r\n\t\t\tconst len = lines[i].length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = 2050 * (10**len);\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = 2050 * (10**(len-1));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= mult;\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === 0) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i 0) {\r\n\t\t\tlet mult = 2050;\r\n\t\t\tconst len = `${num}`.length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = 2050 * 10**len;\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = 2050 * 10**(len-1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= mult;\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === 0) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i 0) {\r\n\t\t\tlet mult = 2050;\r\n\t\t\tconst len = `${num}`.length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = 2050 * 10**len;\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = 2050 * 10**(len-1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= mult;\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === 0) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i 0) {\r\n\t\t\tlet mult = 2050;\r\n\t\t\tconst len = `${num}`.length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = 2050 * 10**len;\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = 2050 * 10**(len-1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= mult;\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === 0) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=0; i 0) {\r\n\t\t\tlet mult = 2050;\r\n\t\t\tconst len = `${num}`.length-4;\r\n\r\n\t\t\tif (len > 0) {\r\n\t\t\t\tmult = 2050 * 10**len;\r\n\r\n\t\t\t\tif (num < mult) {\r\n\t\t\t\t\tmult = 2050 * 10**(len-1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tnum -= mult;\r\n\t\t\tcount++;\r\n\t\t}\r\n\r\n\t\tif (num === 0) {\r\n\t\t\tconsole.log(count);\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n})\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n \r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\nfunction main() {\r\n \r\n var t=readline();\r\n while(t--){\r\n var n=0;\r\n n=readline();\r\n if(n%2050!=0){\r\n console.log(-1);\r\n }\r\n else{\r\n var ans=0;\r\n var a=n/2050;\r\n var str = a.toString();\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n \r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\nfunction main() {\r\n\r\n function sum(n){\r\n var s=0;\r\n while(n>0){\r\n var a=n%10;\r\n s+=a;\r\n n/=10;\r\n n = Math.floor(n);\r\n }\r\n return s;\r\n }\r\n \r\n var t=readline();\r\n while(t--){\r\n var n=0;\r\n n=readline();\r\n if(n%2050!=0){\r\n console.log(-1);\r\n }\r\n else{\r\n var a=n/2050;\r\n var ans=sum(a);\r\n console.log(ans);\r\n }\r\n }\r\n\r\n \r\n\r\n}"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n let n = parseInt(readLine());\r\n n % 2050 === 0 ? print((n/2050).toString().split('').map(Number).reduce((a,b) => a + b)) : print(-1);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction print(c){\r\n return console.log(c)\r\n}\r\n\r\nfunction isEqual(arr){\r\n let flag = true;\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] !== arr[i + 1]){\r\n flag = false;\r\n break;\r\n }\r\n }\r\n return flag;\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var k = 1; k < input.length; k++) {\r\n var n = BigInt(Number(input[k]));\r\n var mod = BigInt(2050);\r\n if (n % mod !== BigInt(0)) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var count = n / mod;\r\n var str = count.toString();\r\n var result = 0;\r\n for (var i = 0; i < str.length; i++) {\r\n result += Number(str[i]);\r\n }\r\n console.log(result);\r\n }\r\n});"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline();\r\n if(n.length > 12) {\r\n var temp = n / Math.pow(10, 9);\r\n var div = temp / 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(div); j++) {\r\n sum += Math.floor((div / Math.pow(10, j))) % 10;\r\n }\r\n n = parseInt(n.slice(n.length - 9, n.length));\r\n n += (temp % 2050) * Math.pow(10, 9);\r\n if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n }\r\n else if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline();\r\n if(n.length > 12) {\r\n var temp = n / Math.pow(10, 9);\r\n var div = temp / 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(div); j++) {\r\n sum += Math.floor((div / Math.pow(10, j))) % 10;\r\n }\r\n n = parseInt(n.slice(n.length - 9, n.length));\r\n n += (temp % 2050) * Math.pow(10, 9);\r\n n /= 2050;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n else if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = readline().split(\" \");\r\n if(n % 2050 !== 0) print(-1);\r\n else {\r\n n /= 2050;\r\n var sum = 0;\r\n for(j = 0; j <= Math.log10(n); j++) {\r\n sum += Math.floor((n / Math.pow(10, j))) % 10;\r\n }\r\n print(sum);\r\n }\r\n}"}, {"source_code": "var testCount = parseInt(readline());\nfor (var i = 0; i < testCount; i++) {\n var n = parseInt(readline());\n print(compute(n));\n}\nfunction compute(n) {\n var d = n / 2050;\n if (d != Math.floor(d))\n return -1;\n var r = 0;\n while (d > 0) {\n r += d % 10;\n d = Math.floor(d / 10);\n }\n return r;\n}\n"}], "src_uid": "f3e413954c9c02520fd25bd2cba4747e"} {"source_code": "var count, firstLetter, i, length, letter, map, name, origin, ref, ref1, ref2, ref3, secondLetter;\n\nref = readline().split(' '), length = ref[0], count = ref[1];\n\nname = readline();\n\nmap = [];\n\nfor (letter = i = ref1 = 'a'.charCodeAt(), ref2 = 'z'.charCodeAt(); ref1 <= ref2 ? i <= ref2 : i >= ref2; letter = ref1 <= ref2 ? ++i : --i) {\n map[String.fromCharCode(letter)] = String.fromCharCode(letter);\n}\n\nwhile (count--) {\n ref3 = readline().split(' '), firstLetter = ref3[0], secondLetter = ref3[1];\n for (origin in map) {\n if (map[origin] === firstLetter) {\n map[origin] = secondLetter;\n } else if (map[origin] === secondLetter) {\n map[origin] = firstLetter;\n }\n }\n}\n\nprint(((function() {\n var j, len, results;\n results = [];\n for (j = 0, len = name.length; j < len; j++) {\n letter = name[j];\n results.push(map[letter]);\n }\n return results;\n})()).join(''));\n", "positive_code": [{"source_code": "try {require('codef');} catch (e){global = this};\nfunction readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\nArray.prototype.list = function() {var length = arguments.length; for(var i=0; i < length; i++){global[arguments[i]] = this[i]}};\nString.prototype.repeat = function(n){return new Array(n + 1).join(this);}\n\nvar n, m, s = '', alphabet, alph = [];\nfor(var i = 97; i <= 122; i++) {\n alph.push(String.fromCharCode(i));\n}\n\nm = readLineAsIntegerArray();\n\nn = m[0];\nm = m[1];\n\ns = readline();\nalphabet = alph = alph.join('');\n\nfor(var i=0; i < m; i++) {\n var tmp = readline().split(' ');\n if (tmp[0] !== tmp[1]) {\n alph = alph.replace(tmp[0], '.').replace(tmp[1], tmp[0]).replace('.', tmp[1]);\n }\n}\n\nvar hash = {};\nfor(var i in alph) {\n hash[alphabet[i]] = alph[i];\n}\n\nvar result = '', length = s.length;\n\nfor(var i = 0; i < length; i ++) {\n result += hash[s[i]];\n}\n\nwrite(result);"}, {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]);\nvar m = parseInt(input[1]);\n\nvar word = readline();\nvar startCharCode = 'a'.charCodeAt(0);\nvar indices = [];\nfor (var i = 0; i < 26; i++) {\n indices[i] = [];\n}\n\n\nfor (var i = 0; i < n; i++) {\n indices[word.charCodeAt(i) - startCharCode].push(i);\n}\n\nfor (var i = 0; i < m; i++) {\n var input2 = readline().split(' ');\n var x = input2[0].charCodeAt(0) - startCharCode;\n var y = input2[1].charCodeAt(0) - startCharCode;\n //swap\n var tmp = indices[x];\n indices[x] = indices[y];\n indices[y] = tmp;\n}\n\nvar output = [];\nfor (var i = 0; i < 26; i++) {\n for (var j = 0; j < indices[i].length; j++) {\n output[indices[i][j]] = String.fromCharCode(i + startCharCode);\n }\n}\n\nprint(output.join(''));\n"}], "negative_code": [{"source_code": "var count, length, originName, ref;\n\nref = readline().split(' '), length = ref[0], count = ref[1];\n\noriginName = readline();\n\nwhile (count--) {\n \"\".replace.apply(originName, readline().split(' '));\n}\n\nprint(originName);\n"}, {"source_code": "var count, length, originName, ref;\n\nref = readline().split(' '), length = ref[0], count = ref[1];\n\noriginName = readline();\n\nwhile (count--) {\n originName = \"\".replace.apply(originName, readline().split(' '));\n}\n\nprint(originName);\n"}, {"source_code": "var params = readline().split(' ').map(function(i) { return parseInt(i); });\n\nvar n = params[0];\nvar m = params[1];\n\nvar originalWord = readline().split('');\nvar pairs = [];\n\nfor (var i = 0; i < m; i++) {\n var param = readline().split(' ');\n pairs.push({\n x : param[0][0],\n y : param[1][0]\n });\n}\n\nfor (var i = 0; i < pairs.length; i++) {\n if (i+1 < pairs.length && (pairs[i].x === pairs[i+1].y && pairs[i].y === pairs[i+1].x) ) {\n i++;\n }\n\n if (pairs[i].x !== pairs[i].y) {\n for (var j=0; j < originalWord.length; j++) {\n if (originalWord[j] === pairs[i].x) {\n originalWord[j] = pairs[i].y;\n } else if (originalWord[j] === pairs[i].y) {\n originalWord[j] = pairs[i].x;\n }\n }\n }\n}\nprint(originalWord.join(''));\n"}], "src_uid": "67a70d58415dc381afaa74de1fee7215"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const n = BigInt(d);\n let ans = n * (n + 1n) / 2n;\n let sum = 0n;\n for (let i = 1n; i <= n; i *= 2n) {\n sum += i;\n }\n\n ans -= (sum * 2n);\n console.log(ans.toString());\n\n c++;\n});\n", "positive_code": [{"source_code": "/* Usage:\n 1) install: (for browser)\n \n $ npm install bignumber.js (for NodeJS)\n const BigNumber = require('bignumber.js');\n\n 2) let x = new BigNumber(123.4567);\n let y = BigNumber('123456.7e-3');\n let z = new BigNumber(x);\n x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true\n\n 3) To get the string value of a BigNumber use toString() or toFixed().\n Using toFixed() prevents exponential notation being returned, no matter how large or small the value.\n\n let x = new BigNumber('1111222233334444555566');\n x.toString(); // \"1.111222233334444555566e+21\"\n x.toFixed(); // \"1111222233334444555566\"\n\n 4) // Precision loss from using numeric literals with more than 15 significant digits.\n new BigNumber(1.0000000000000001) // '1'\n new BigNumber(88259496234518.57) // '88259496234518.56'\n new BigNumber(99999999999999999999) // '100000000000000000000'\n\n // Precision loss from using numeric literals outside the range of Number values.\n new BigNumber(2e+308) // 'Infinity'\n new BigNumber(1e-324) // '0'\n\n // Precision loss from the unexpected result of arithmetic with Number values.\n new BigNumber(0.7 + 0.1) // '0.7999999999999999'\n\n When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal toString() value.\n\n 5) BigNumbers can be created from values in bases from 2 to 36. See ALPHABET to extend this range.\n\n a = new BigNumber(1011, 2) // \"11\"\n b = new BigNumber('zz.9', 36) // \"1295.25\"\n c = a.plus(b) // \"1306.25\"\n\n 6) A BigNumber is immutable in the sense that it is not changed by its methods.\n\n 0.3 - 0.1 // 0.19999999999999998\n x = new BigNumber(0.3)\n x.minus(0.1) // \"0.2\"\n x // \"0.3\"\n\n 7) The methods that return a BigNumber can be chained.\n\n x.dividedBy(y).plus(z).times(9)\n x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()\n x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true\n x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true\n\n 8) As with JavaScript's Number type, there are toExponential, toFixed and toPrecision methods.\n\n x = new BigNumber(255.5)\n x.toExponential(5) // \"2.55500e+2\"\n x.toFixed(5) // \"255.50000\"\n x.toPrecision(5) // \"255.50\"\n x.toNumber() // 255.5\n\n 9) A base can be specified for toString.\n\n x.toString(16) // \"ff.8\"\n\n 10) isNaN and isFinite methods, as NaN and Infinity are valid BigNumber values.\n\n x = new BigNumber(NaN) // \"NaN\"\n y = new BigNumber(Infinity) // \"Infinity\"\n x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true\n\n 11) https://github.com/MikeMcl/bignumber.js\n\n 12) GCD for all numbers from big segment [a...b]:\n\n function nod(a, b) {\n while (a.gt(0) && b.gt(0)) {\n if (a.gt(b))\n a = a.mod(b);\n else\n b = b.mod(a);\n }\n return a.plus(b);\n }\n\n var nums = readline().split(' ').map(function(x) { return BigNumber(x) });\n var a = nums[0];\n var b = nums[1];\n var res = a;\n a = a.plus(1);\n while (a.lte(b) && res.gt(1)) {\n res = nod(res, a);\n a = a.plus(1);\n }\n print(res.toFixed());\n\n 13) function maxBN(a, b) {\n if (a.gt(b))\n return a;\n return b;\n }\n\n function minBN(a, b) {\n if (a.lt(b))\n return a;\n return b;\n }\n*/\n\n;(function (globalObject) {\n 'use strict';\n\n var BigNumber,\n isNumeric = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/i,\n mathceil = Math.ceil,\n mathfloor = Math.floor,\n bignumberError = '[BigNumber Error] ',\n tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',\n BASE = 1e14,\n LOG_BASE = 14,\n MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1\n POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],\n SQRT_BASE = 1e7,\n MAX = 1E9; // 0 to MAX_INT32\n\n function clone(configObject) {\n var div, convertBase, parseNumeric,\n P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },\n ONE = new BigNumber(1),\n\n // The maximum number of decimal places for operations involving division.\n DECIMAL_PLACES = 1000, // 0 to MAX\n ROUNDING_MODE = 4, // 0 to 8\n\n // The exponent value at and beneath which toString returns exponential notation.\n TO_EXP_NEG = -1000, // 0 to -MAX\n // The exponent value at and above which toString returns exponential notation.\n TO_EXP_POS = 1000, // 0 to MAX\n MIN_EXP = -1e8, // -1 to -MAX\n MAX_EXP = 1e8, // 1 to MAX\n\n CRYPTO = false, // true or false\n MODULO_MODE = 1, // 0 to 9\n POW_PRECISION = 0, // 0 to MAX\n FORMAT = {\n prefix: '',\n groupSize: 3,\n secondaryGroupSize: 0,\n groupSeparator: ',',\n decimalSeparator: '.',\n fractionGroupSize: 0,\n fractionGroupSeparator: '\\xA0', // non-breaking space\n suffix: ''\n },\n ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n function BigNumber(n, b) {\n var alphabet, c, caseChanged, e, i, isNum, len, str,\n x = this;\n if (!(x instanceof BigNumber)) {\n return new BigNumber(n, b);\n }\n if (b == null) {\n if (n instanceof BigNumber) {\n x.s = n.s;\n x.e = n.e;\n x.c = (n = n.c) ? n.slice() : n;\n return;\n }\n isNum = typeof n == 'number';\n if (isNum && n * 0 == 0) {\n x.s = 1 / n < 0 ? (n = -n, -1) : 1;\n if (n === ~~n) {\n for (e = 0, i = n; i >= 10; i /= 10, e++);\n x.e = e;\n x.c = [n];\n return;\n }\n str = String(n);\n } else {\n str = String(n);\n if (!isNumeric.test(str)) return parseNumeric(x, str, isNum);\n x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;\n }\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n if ((i = str.search(/e/i)) > 0) {\n if (e < 0) e = i;\n e += +str.slice(i + 1);\n str = str.substring(0, i);\n } else if (e < 0) {\n e = str.length;\n }\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = String(n);\n if (b == 10) {\n x = new BigNumber(n instanceof BigNumber ? n : str);\n return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);\n }\n isNum = typeof n == 'number';\n if (isNum) {\n if (n * 0 != 0) return parseNumeric(x, str, isNum, b);\n x.s = 1 / n < 0 ? (str = str.slice(1), -1) : 1;\n if (BigNumber.DEBUG && str.replace(/^0\\.0*|\\./, '').length > 15) {\n throw Error\n (tooManyDigits + n);\n }\n isNum = false;\n } else {\n x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;\n }\n alphabet = ALPHABET.slice(0, b);\n e = i = 0;\n for (len = str.length; i < len; i++) {\n if (alphabet.indexOf(c = str.charAt(i)) < 0) {\n if (c == '.') {\n if (i > e) {\n e = len;\n continue;\n }\n } else if (!caseChanged) {\n if (str == str.toUpperCase() && (str = str.toLowerCase()) ||\n str == str.toLowerCase() && (str = str.toUpperCase())) {\n caseChanged = true;\n i = -1;\n e = 0;\n continue;\n }\n }\n return parseNumeric(x, String(n), isNum, b);\n }\n }\n str = convertBase(str, b, 10, x.s);\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n else e = str.length;\n }\n for (i = 0; str.charCodeAt(i) === 48; i++);\n for (len = str.length; str.charCodeAt(--len) === 48;);\n str = str.slice(i, ++len);\n if (str) {\n len -= i;\n if (isNum && BigNumber.DEBUG &&\n len > 15 && (n > MAX_SAFE_INTEGER || n !== mathfloor(n))) {\n throw Error\n (tooManyDigits + (x.s * n));\n }\n e = e - i - 1;\n if (e > MAX_EXP) {\n x.c = x.e = null;\n } else if (e < MIN_EXP) {\n x.c = [x.e = 0];\n } else {\n x.e = e;\n x.c = [];\n i = (e + 1) % LOG_BASE;\n if (e < 0) i += LOG_BASE;\n if (i < len) {\n if (i) x.c.push(+str.slice(0, i));\n for (len -= LOG_BASE; i < len;) {\n x.c.push(+str.slice(i, i += LOG_BASE));\n }\n str = str.slice(i);\n i = LOG_BASE - str.length;\n } else {\n i -= len;\n }\n for (; i--; str += '0');\n x.c.push(+str);\n }\n } else {\n x.c = [x.e = 0];\n }\n }\n\n BigNumber.clone = clone;\n BigNumber.ROUND_UP = 0;\n BigNumber.ROUND_DOWN = 1;\n BigNumber.ROUND_CEIL = 2;\n BigNumber.ROUND_FLOOR = 3;\n BigNumber.ROUND_HALF_UP = 4;\n BigNumber.ROUND_HALF_DOWN = 5;\n BigNumber.ROUND_HALF_EVEN = 6;\n BigNumber.ROUND_HALF_CEIL = 7;\n BigNumber.ROUND_HALF_FLOOR = 8;\n BigNumber.EUCLID = 9;\n\n BigNumber.config = BigNumber.set = function (obj) {\n var p, v;\n if (obj != null) {\n if (typeof obj == 'object') {\n if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n DECIMAL_PLACES = v;\n }\n if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {\n v = obj[p];\n intCheck(v, 0, 8, p);\n ROUNDING_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, 0, p);\n intCheck(v[1], 0, MAX, p);\n TO_EXP_NEG = v[0];\n TO_EXP_POS = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);\n }\n }\n if (obj.hasOwnProperty(p = 'RANGE')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, -1, p);\n intCheck(v[1], 1, MAX, p);\n MIN_EXP = v[0];\n MAX_EXP = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n if (v) {\n MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);\n } else {\n throw Error\n (bignumberError + p + ' cannot be zero: ' + v);\n }\n }\n }\n if (obj.hasOwnProperty(p = 'CRYPTO')) {\n v = obj[p];\n if (v === !!v) {\n if (v) {\n if (typeof crypto != 'undefined' && crypto &&\n (crypto.getRandomValues || crypto.randomBytes)) {\n CRYPTO = v;\n } else {\n CRYPTO = !v;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n } else {\n CRYPTO = v;\n }\n } else {\n throw Error\n (bignumberError + p + ' not true or false: ' + v);\n }\n }\n if (obj.hasOwnProperty(p = 'MODULO_MODE')) {\n v = obj[p];\n intCheck(v, 0, 9, p);\n MODULO_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'POW_PRECISION')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n POW_PRECISION = v;\n }\n if (obj.hasOwnProperty(p = 'FORMAT')) {\n v = obj[p];\n if (typeof v == 'object') FORMAT = v;\n else throw Error\n (bignumberError + p + ' not an object: ' + v);\n }\n if (obj.hasOwnProperty(p = 'ALPHABET')) {\n v = obj[p];\n if (typeof v == 'string' && !/^.$|[+-.\\s]|(.).*\\1/.test(v)) {\n ALPHABET = v;\n } else {\n throw Error\n (bignumberError + p + ' invalid: ' + v);\n }\n }\n } else {\n throw Error\n (bignumberError + 'Object expected: ' + obj);\n }\n }\n\n return {\n DECIMAL_PLACES: DECIMAL_PLACES,\n ROUNDING_MODE: ROUNDING_MODE,\n EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],\n RANGE: [MIN_EXP, MAX_EXP],\n CRYPTO: CRYPTO,\n MODULO_MODE: MODULO_MODE,\n POW_PRECISION: POW_PRECISION,\n FORMAT: FORMAT,\n ALPHABET: ALPHABET\n };\n };\n\n BigNumber.isBigNumber = function (v) {\n return v instanceof BigNumber || v && v._isBigNumber === true || false;\n };\n\n BigNumber.maximum = BigNumber.max = function () {\n return maxOrMin(arguments, P.lt);\n };\n\n BigNumber.minimum = BigNumber.min = function () {\n return maxOrMin(arguments, P.gt);\n };\n\n BigNumber.random = (function () {\n var pow2_53 = 0x20000000000000;\n var random53bitInt = (Math.random() * pow2_53) & 0x1fffff\n ? function () { return mathfloor(Math.random() * pow2_53); }\n : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +\n (Math.random() * 0x800000 | 0); };\n return function (dp) {\n var a, b, e, k, v,\n i = 0,\n c = [],\n rand = new BigNumber(ONE);\n if (dp == null) dp = DECIMAL_PLACES;\n else intCheck(dp, 0, MAX);\n k = mathceil(dp / LOG_BASE);\n if (CRYPTO) {\n if (crypto.getRandomValues) {\n a = crypto.getRandomValues(new Uint32Array(k *= 2));\n for (; i < k;) {\n v = a[i] * 0x20000 + (a[i + 1] >>> 11);\n if (v >= 9e15) {\n b = crypto.getRandomValues(new Uint32Array(2));\n a[i] = b[0];\n a[i + 1] = b[1];\n } else {\n c.push(v % 1e14);\n i += 2;\n }\n }\n i = k / 2;\n } else if (crypto.randomBytes) {\n a = crypto.randomBytes(k *= 7);\n for (; i < k;) {\n v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +\n (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +\n (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];\n if (v >= 9e15) {\n crypto.randomBytes(7).copy(a, i);\n } else {\n c.push(v % 1e14);\n i += 7;\n }\n }\n i = k / 7;\n } else {\n CRYPTO = false;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n }\n if (!CRYPTO) {\n for (; i < k;) {\n v = random53bitInt();\n if (v < 9e15) c[i++] = v % 1e14;\n }\n }\n k = c[--i];\n dp %= LOG_BASE;\n if (k && dp) {\n v = POWS_TEN[LOG_BASE - dp];\n c[i] = mathfloor(k / v) * v;\n }\n for (; c[i] === 0; c.pop(), i--);\n if (i < 0) {\n c = [e = 0];\n } else {\n for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);\n for (i = 1, v = c[0]; v >= 10; v /= 10, i++);\n if (i < LOG_BASE) e -= LOG_BASE - i;\n }\n rand.e = e;\n rand.c = c;\n return rand;\n };\n })();\n\n BigNumber.sum = function () {\n var i = 1,\n args = arguments,\n sum = new BigNumber(args[0]);\n for (; i < args.length;) sum = sum.plus(args[i++]);\n return sum;\n };\n\n convertBase = (function () {\n var decimal = '0123456789';\n function toBaseOut(str, baseIn, baseOut, alphabet) {\n var j,\n arr = [0],\n arrL,\n i = 0,\n len = str.length;\n for (; i < len;) {\n for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);\n arr[0] += alphabet.indexOf(str.charAt(i++));\n for (j = 0; j < arr.length; j++) {\n if (arr[j] > baseOut - 1) {\n if (arr[j + 1] == null) arr[j + 1] = 0;\n arr[j + 1] += arr[j] / baseOut | 0;\n arr[j] %= baseOut;\n }\n }\n }\n return arr.reverse();\n }\n return function (str, baseIn, baseOut, sign, callerIsToString) {\n var alphabet, d, e, k, r, x, xc, y,\n i = str.indexOf('.'),\n dp = DECIMAL_PLACES,\n rm = ROUNDING_MODE;\n if (i >= 0) {\n k = POW_PRECISION;\n POW_PRECISION = 0;\n str = str.replace('.', '');\n y = new BigNumber(baseIn);\n x = y.pow(str.length - i);\n POW_PRECISION = k;\n y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),\n 10, baseOut, decimal);\n y.e = y.c.length;\n }\n xc = toBaseOut(str, baseIn, baseOut, callerIsToString\n ? (alphabet = ALPHABET, decimal)\n : (alphabet = decimal, ALPHABET));\n e = k = xc.length;\n for (; xc[--k] == 0; xc.pop());\n if (!xc[0]) return alphabet.charAt(0);\n if (i < 0) {\n --e;\n } else {\n x.c = xc;\n x.e = e;\n x.s = sign;\n x = div(x, y, dp, rm, baseOut);\n xc = x.c;\n r = x.r;\n e = x.e;\n }\n d = e + dp + 1;\n i = xc[d];\n k = baseOut / 2;\n r = r || d < 0 || xc[d + 1] != null;\n r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (d < 1 || !xc[0]) {\n str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);\n } else {\n xc.length = d;\n if (r) {\n for (--baseOut; ++xc[--d] > baseOut;) {\n xc[d] = 0;\n if (!d) {\n ++e;\n xc = [1].concat(xc);\n }\n }\n }\n for (k = xc.length; !xc[--k];);\n for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));\n str = toFixedPoint(str, e, alphabet.charAt(0));\n }\n return str;\n };\n })();\n\n div = (function () {\n function multiply(x, k, base) {\n var m, temp, xlo, xhi,\n carry = 0,\n i = x.length,\n klo = k % SQRT_BASE,\n khi = k / SQRT_BASE | 0;\n for (x = x.slice(); i--;) {\n xlo = x[i] % SQRT_BASE;\n xhi = x[i] / SQRT_BASE | 0;\n m = khi * xlo + xhi * klo;\n temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;\n carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;\n x[i] = temp % base;\n }\n if (carry) x = [carry].concat(x);\n return x;\n }\n\n function compare(a, b, aL, bL) {\n var i, cmp;\n if (aL != bL) {\n cmp = aL > bL ? 1 : -1;\n } else {\n for (i = cmp = 0; i < aL; i++) {\n if (a[i] != b[i]) {\n cmp = a[i] > b[i] ? 1 : -1;\n break;\n }\n }\n }\n return cmp;\n }\n\n function subtract(a, b, aL, base) {\n var i = 0;\n for (; aL--;) {\n a[aL] -= i;\n i = a[aL] < b[aL] ? 1 : 0;\n a[aL] = i * base + a[aL] - b[aL];\n }\n for (; !a[0] && a.length > 1; a.splice(0, 1));\n }\n return function (x, y, dp, rm, base) {\n var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,\n yL, yz,\n s = x.s == y.s ? 1 : -1,\n xc = x.c,\n yc = y.c;\n if (!xc || !xc[0] || !yc || !yc[0]) {\n return new BigNumber(\n !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :\n xc && xc[0] == 0 || !yc ? s * 0 : s / 0\n );\n }\n q = new BigNumber(s);\n qc = q.c = [];\n e = x.e - y.e;\n s = dp + e + 1;\n if (!base) {\n base = BASE;\n e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);\n s = s / LOG_BASE | 0;\n }\n for (i = 0; yc[i] == (xc[i] || 0); i++);\n if (yc[i] > (xc[i] || 0)) e--;\n if (s < 0) {\n qc.push(1);\n more = true;\n } else {\n xL = xc.length;\n yL = yc.length;\n i = 0;\n s += 2;\n n = mathfloor(base / (yc[0] + 1));\n if (n > 1) {\n yc = multiply(yc, n, base);\n xc = multiply(xc, n, base);\n yL = yc.length;\n xL = xc.length;\n }\n xi = yL;\n rem = xc.slice(0, yL);\n remL = rem.length;\n for (; remL < yL; rem[remL++] = 0);\n yz = yc.slice();\n yz = [0].concat(yz);\n yc0 = yc[0];\n if (yc[1] >= base / 2) yc0++;\n do {\n n = 0;\n cmp = compare(yc, rem, yL, remL);\n if (cmp < 0) {\n rem0 = rem[0];\n if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);\n n = mathfloor(rem0 / yc0);\n if (n > 1) {\n if (n >= base) n = base - 1;\n prod = multiply(yc, n, base);\n prodL = prod.length;\n remL = rem.length;\n while (compare(prod, rem, prodL, remL) == 1) {\n n--;\n subtract(prod, yL < prodL ? yz : yc, prodL, base);\n prodL = prod.length;\n cmp = 1;\n }\n } else {\n if (n == 0) {\n cmp = n = 1;\n }\n prod = yc.slice();\n prodL = prod.length;\n }\n if (prodL < remL) prod = [0].concat(prod);\n subtract(rem, prod, remL, base);\n remL = rem.length;\n if (cmp == -1) {\n while (compare(yc, rem, yL, remL) < 1) {\n n++;\n subtract(rem, yL < remL ? yz : yc, remL, base);\n remL = rem.length;\n }\n }\n } else if (cmp === 0) {\n n++;\n rem = [0];\n }\n qc[i++] = n;\n if (rem[0]) {\n rem[remL++] = xc[xi] || 0;\n } else {\n rem = [xc[xi]];\n remL = 1;\n }\n } while ((xi++ < xL || rem[0] != null) && s--);\n more = rem[0] != null;\n if (!qc[0]) qc.splice(0, 1);\n }\n if (base == BASE) {\n for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);\n round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);\n } else {\n q.e = e;\n q.r = +more;\n }\n return q;\n };\n })();\n\n function format(n, i, rm, id) {\n var c0, e, ne, len, str;\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n if (!n.c) return n.toString();\n c0 = n.c[0];\n ne = n.e;\n if (i == null) {\n str = coeffToString(n.c);\n str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)\n ? toExponential(str, ne)\n : toFixedPoint(str, ne, '0');\n } else {\n n = round(new BigNumber(n), i, rm);\n e = n.e;\n str = coeffToString(n.c);\n len = str.length;\n if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {\n for (; len < i; str += '0', len++);\n str = toExponential(str, e);\n } else {\n i -= ne;\n str = toFixedPoint(str, e, '0');\n if (e + 1 > len) {\n if (--i > 0) for (str += '.'; i--; str += '0');\n } else {\n i += e - len;\n if (i > 0) {\n if (e + 1 == len) str += '.';\n for (; i--; str += '0');\n }\n }\n }\n }\n return n.s < 0 && c0 ? '-' + str : str;\n }\n\n function maxOrMin(args, method) {\n var n,\n i = 1,\n m = new BigNumber(args[0]);\n for (; i < args.length; i++) {\n n = new BigNumber(args[i]);\n if (!n.s) {\n m = n;\n break;\n } else if (method.call(m, n)) {\n m = n;\n }\n }\n return m;\n }\n\n function normalise(n, c, e) {\n var i = 1,\n j = c.length;\n for (; !c[--j]; c.pop());\n for (j = c[0]; j >= 10; j /= 10, i++);\n if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {\n n.c = n.e = null;\n } else if (e < MIN_EXP) {\n n.c = [n.e = 0];\n } else {\n n.e = e;\n n.c = c;\n }\n return n;\n }\n\n parseNumeric = (function () {\n var basePrefix = /^(-?)0([xbo])(?=\\w[\\w.]*$)/i,\n dotAfter = /^([^.]+)\\.$/,\n dotBefore = /^\\.([^.]+)$/,\n isInfinityOrNaN = /^-?(Infinity|NaN)$/,\n whitespaceOrPlus = /^\\s*\\+(?=[\\w.])|^\\s+|\\s+$/g;\n return function (x, str, isNum, b) {\n var base,\n s = isNum ? str : str.replace(whitespaceOrPlus, '');\n if (isInfinityOrNaN.test(s)) {\n x.s = isNaN(s) ? null : s < 0 ? -1 : 1;\n x.c = x.e = null;\n } else {\n if (!isNum) {\n s = s.replace(basePrefix, function (m, p1, p2) {\n base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;\n return !b || b == base ? p1 : m;\n });\n if (b) {\n base = b;\n s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');\n }\n if (str != s) return new BigNumber(s, base);\n }\n if (BigNumber.DEBUG) {\n throw Error\n (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);\n }\n x.c = x.e = x.s = null;\n }\n }\n })();\n\n function round(x, sd, rm, r) {\n var d, i, j, k, n, ni, rd,\n xc = x.c,\n pows10 = POWS_TEN;\n if (xc) {\n out: {\n for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);\n i = sd - d;\n if (i < 0) {\n i += LOG_BASE;\n j = sd;\n n = xc[ni = 0];\n rd = n / pows10[d - j - 1] % 10 | 0;\n } else {\n ni = mathceil((i + 1) / LOG_BASE);\n if (ni >= xc.length) {\n if (r) {\n for (; xc.length <= ni; xc.push(0));\n n = rd = 0;\n d = 1;\n i %= LOG_BASE;\n j = i - LOG_BASE + 1;\n } else {\n break out;\n }\n } else {\n n = k = xc[ni];\n for (d = 1; k >= 10; k /= 10, d++);\n i %= LOG_BASE;\n j = i - LOG_BASE + d;\n rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;\n }\n }\n r = r || sd < 0 ||\n xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);\n r = rm < 4\n ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&\n ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (sd < 1 || !xc[0]) {\n xc.length = 0;\n if (r) {\n sd -= x.e + 1;\n xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];\n x.e = -sd || 0;\n } else {\n xc[0] = x.e = 0;\n }\n return x;\n }\n if (i == 0) {\n xc.length = ni;\n k = 1;\n ni--;\n } else {\n xc.length = ni + 1;\n k = pows10[LOG_BASE - i];\n xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;\n }\n if (r) {\n for (; ;) {\n if (ni == 0) {\n for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);\n j = xc[0] += k;\n for (k = 1; j >= 10; j /= 10, k++);\n if (i != k) {\n x.e++;\n if (xc[0] == BASE) xc[0] = 1;\n }\n break;\n } else {\n xc[ni] += k;\n if (xc[ni] != BASE) break;\n xc[ni--] = 0;\n k = 1;\n }\n }\n }\n for (i = xc.length; xc[--i] === 0; xc.pop());\n }\n if (x.e > MAX_EXP) {\n x.c = x.e = null;\n } else if (x.e < MIN_EXP) {\n x.c = [x.e = 0];\n }\n }\n return x;\n }\n\n function valueOf(n) {\n var str,\n e = n.e;\n if (e === null) return n.toString();\n str = coeffToString(n.c);\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(str, e)\n : toFixedPoint(str, e, '0');\n return n.s < 0 ? '-' + str : str;\n }\n\n P.absoluteValue = P.abs = function () {\n var x = new BigNumber(this);\n if (x.s < 0) x.s = 1;\n return x;\n };\n\n P.comparedTo = function (y, b) {\n return compare(this, new BigNumber(y, b));\n };\n\n P.decimalPlaces = P.dp = function (dp, rm) {\n var c, n, v,\n x = this;\n if (dp != null) {\n intCheck(dp, 0, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), dp + x.e + 1, rm);\n }\n if (!(c = x.c)) return null;\n n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;\n if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);\n if (n < 0) n = 0;\n return n;\n };\n\n P.dividedBy = P.div = function (y, b) {\n return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);\n };\n\n P.dividedToIntegerBy = P.idiv = function (y, b) {\n return div(this, new BigNumber(y, b), 0, 1);\n };\n\n P.exponentiatedBy = P.pow = function (n, m) {\n var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,\n x = this;\n n = new BigNumber(n);\n if (n.c && !n.isInteger()) {\n throw Error\n (bignumberError + 'Exponent not an integer: ' + valueOf(n));\n }\n if (m != null) m = new BigNumber(m);\n nIsBig = n.e > 14;\n if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {\n y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));\n return m ? y.mod(m) : y;\n }\n nIsNeg = n.s < 0;\n if (m) {\n if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);\n isModExp = !nIsNeg && x.isInteger() && m.isInteger();\n if (isModExp) x = x.mod(m);\n } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0\n ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7\n : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {\n k = x.s < 0 && isOdd(n) ? -0 : 0;\n if (x.e > -1) k = 1 / k;\n return new BigNumber(nIsNeg ? 1 / k : k);\n } else if (POW_PRECISION) {\n k = mathceil(POW_PRECISION / LOG_BASE + 2);\n }\n if (nIsBig) {\n half = new BigNumber(0.5);\n if (nIsNeg) n.s = 1;\n nIsOdd = isOdd(n);\n } else {\n i = Math.abs(+valueOf(n));\n nIsOdd = i % 2;\n }\n y = new BigNumber(ONE);\n for (; ;) {\n if (nIsOdd) {\n y = y.times(x);\n if (!y.c) break;\n\n if (k) {\n if (y.c.length > k) y.c.length = k;\n } else if (isModExp) {\n y = y.mod(m);\n }\n }\n if (i) {\n i = mathfloor(i / 2);\n if (i === 0) break;\n nIsOdd = i % 2;\n } else {\n n = n.times(half);\n round(n, n.e + 1, 1);\n if (n.e > 14) {\n nIsOdd = isOdd(n);\n } else {\n i = +valueOf(n);\n if (i === 0) break;\n nIsOdd = i % 2;\n }\n }\n x = x.times(x);\n if (k) {\n if (x.c && x.c.length > k) x.c.length = k;\n } else if (isModExp) {\n x = x.mod(m);\n }\n }\n if (isModExp) return y;\n if (nIsNeg) y = ONE.div(y);\n return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;\n };\n\n P.integerValue = function (rm) {\n var n = new BigNumber(this);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(n, n.e + 1, rm);\n };\n\n P.isEqualTo = P.eq = function (y, b) {\n return compare(this, new BigNumber(y, b)) === 0;\n };\n\n P.isFinite = function () {\n return !!this.c;\n };\n\n P.isGreaterThan = P.gt = function (y, b) {\n return compare(this, new BigNumber(y, b)) > 0;\n };\n\n P.isGreaterThanOrEqualTo = P.gte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;\n\n };\n\n P.isInteger = function () {\n return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;\n };\n\n P.isLessThan = P.lt = function (y, b) {\n return compare(this, new BigNumber(y, b)) < 0;\n };\n\n P.isLessThanOrEqualTo = P.lte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;\n };\n\n P.isNaN = function () {\n return !this.s;\n };\n\n P.isNegative = function () {\n return this.s < 0;\n };\n\n P.isPositive = function () {\n return this.s > 0;\n };\n\n P.isZero = function () {\n return !!this.c && this.c[0] == 0;\n };\n\n P.minus = function (y, b) {\n var i, j, t, xLTy,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.plus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);\n if (!xc[0] || !yc[0]) {\n return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :\n ROUNDING_MODE == 3 ? -0 : 0);\n }\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (xLTy = a < 0) {\n a = -a;\n t = xc;\n } else {\n ye = xe;\n t = yc;\n }\n t.reverse();\n for (b = a; b--; t.push(0));\n t.reverse();\n } else {\n j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;\n for (a = b = 0; b < j; b++) {\n if (xc[b] != yc[b]) {\n xLTy = xc[b] < yc[b];\n break;\n }\n }\n }\n if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;\n b = (j = yc.length) - (i = xc.length);\n if (b > 0) for (; b--; xc[i++] = 0);\n b = BASE - 1;\n for (; j > a;) {\n if (xc[--j] < yc[j]) {\n for (i = j; i && !xc[--i]; xc[i] = b);\n --xc[i];\n xc[j] += BASE;\n }\n\n xc[j] -= yc[j];\n }\n for (; xc[0] == 0; xc.splice(0, 1), --ye);\n if (!xc[0]) {\n y.s = ROUNDING_MODE == 3 ? -1 : 1;\n y.c = [y.e = 0];\n return y;\n }\n return normalise(y, xc, ye);\n };\n\n P.modulo = P.mod = function (y, b) {\n var q, s,\n x = this;\n y = new BigNumber(y, b);\n if (!x.c || !y.s || y.c && !y.c[0]) {\n return new BigNumber(NaN);\n } else if (!y.c || x.c && !x.c[0]) {\n return new BigNumber(x);\n }\n if (MODULO_MODE == 9) {\n s = y.s;\n y.s = 1;\n q = div(x, y, 0, 3);\n y.s = s;\n q.s *= s;\n } else {\n q = div(x, y, 0, MODULO_MODE);\n }\n y = x.minus(q.times(y));\n if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;\n return y;\n };\n\n P.multipliedBy = P.times = function (y, b) {\n var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,\n base, sqrtBase,\n x = this,\n xc = x.c,\n yc = (y = new BigNumber(y, b)).c;\n if (!xc || !yc || !xc[0] || !yc[0]) {\n if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {\n y.c = y.e = y.s = null;\n } else {\n y.s *= x.s;\n if (!xc || !yc) {\n y.c = y.e = null;\n } else {\n y.c = [0];\n y.e = 0;\n }\n }\n return y;\n }\n e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);\n y.s *= x.s;\n xcL = xc.length;\n ycL = yc.length;\n if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;\n for (i = xcL + ycL, zc = []; i--; zc.push(0));\n base = BASE;\n sqrtBase = SQRT_BASE;\n for (i = ycL; --i >= 0;) {\n c = 0;\n ylo = yc[i] % sqrtBase;\n yhi = yc[i] / sqrtBase | 0;\n for (k = xcL, j = i + k; j > i;) {\n xlo = xc[--k] % sqrtBase;\n xhi = xc[k] / sqrtBase | 0;\n m = yhi * xlo + xhi * ylo;\n xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;\n c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;\n zc[j--] = xlo % base;\n }\n zc[j] = c;\n }\n if (c) {\n ++e;\n } else {\n zc.splice(0, 1);\n }\n return normalise(y, zc, e);\n };\n\n P.negated = function () {\n var x = new BigNumber(this);\n x.s = -x.s || null;\n return x;\n };\n\n P.plus = function (y, b) {\n var t,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.minus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return new BigNumber(a / 0);\n if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (a > 0) {\n ye = xe;\n t = yc;\n } else {\n a = -a;\n t = xc;\n }\n t.reverse();\n for (; a--; t.push(0));\n t.reverse();\n }\n a = xc.length;\n b = yc.length;\n if (a - b < 0) t = yc, yc = xc, xc = t, b = a;\n for (a = 0; b;) {\n a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;\n xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;\n }\n if (a) {\n xc = [a].concat(xc);\n ++ye;\n }\n return normalise(y, xc, ye);\n };\n\n P.precision = P.sd = function (sd, rm) {\n var c, n, v,\n x = this;\n if (sd != null && sd !== !!sd) {\n intCheck(sd, 1, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), sd, rm);\n }\n if (!(c = x.c)) return null;\n v = c.length - 1;\n n = v * LOG_BASE + 1;\n if (v = c[v]) {\n for (; v % 10 == 0; v /= 10, n--);\n for (v = c[0]; v >= 10; v /= 10, n++);\n }\n if (sd && x.e + 1 > n) n = x.e + 1;\n return n;\n };\n P.shiftedBy = function (k) {\n intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);\n return this.times('1e' + k);\n };\n P.squareRoot = P.sqrt = function () {\n var m, n, r, rep, t,\n x = this,\n c = x.c,\n s = x.s,\n e = x.e,\n dp = DECIMAL_PLACES + 4,\n half = new BigNumber('0.5');\n if (s !== 1 || !c || !c[0]) {\n return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);\n }\n s = Math.sqrt(+valueOf(x));\n if (s == 0 || s == 1 / 0) {\n n = coeffToString(c);\n if ((n.length + e) % 2 == 0) n += '0';\n s = Math.sqrt(+n);\n e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);\n\n if (s == 1 / 0) {\n n = '1e' + e;\n } else {\n n = s.toExponential();\n n = n.slice(0, n.indexOf('e') + 1) + e;\n }\n r = new BigNumber(n);\n } else {\n r = new BigNumber(s + '');\n }\n if (r.c[0]) {\n e = r.e;\n s = e + dp;\n if (s < 3) s = 0;\n for (; ;) {\n t = r;\n r = half.times(t.plus(div(x, t, dp, 1)));\n if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {\n if (r.e < e) --s;\n n = n.slice(s - 3, s + 1);\n if (n == '9999' || !rep && n == '4999') {\n if (!rep) {\n round(t, t.e + DECIMAL_PLACES + 2, 0);\n\n if (t.times(t).eq(x)) {\n r = t;\n break;\n }\n }\n dp += 4;\n s += 4;\n rep = 1;\n } else {\n if (!+n || !+n.slice(1) && n.charAt(0) == '5') {\n round(r, r.e + DECIMAL_PLACES + 2, 1);\n m = !r.times(r).eq(x);\n }\n break;\n }\n }\n }\n }\n\n return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);\n };\n\n P.toExponential = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp++;\n }\n return format(this, dp, rm, 1);\n };\n\n P.toFixed = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp = dp + this.e + 1;\n }\n return format(this, dp, rm);\n };\n\n P.toFormat = function (dp, rm, format) {\n var str,\n x = this;\n\n if (format == null) {\n if (dp != null && rm && typeof rm == 'object') {\n format = rm;\n rm = null;\n } else if (dp && typeof dp == 'object') {\n format = dp;\n dp = rm = null;\n } else {\n format = FORMAT;\n }\n } else if (typeof format != 'object') {\n throw Error\n (bignumberError + 'Argument not an object: ' + format);\n }\n\n str = x.toFixed(dp, rm);\n\n if (x.c) {\n var i,\n arr = str.split('.'),\n g1 = +format.groupSize,\n g2 = +format.secondaryGroupSize,\n groupSeparator = format.groupSeparator || '',\n intPart = arr[0],\n fractionPart = arr[1],\n isNeg = x.s < 0,\n intDigits = isNeg ? intPart.slice(1) : intPart,\n len = intDigits.length;\n\n if (g2) i = g1, g1 = g2, g2 = i, len -= i;\n\n if (g1 > 0 && len > 0) {\n i = len % g1 || g1;\n intPart = intDigits.substr(0, i);\n for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);\n if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);\n if (isNeg) intPart = '-' + intPart;\n }\n\n str = fractionPart\n ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)\n ? fractionPart.replace(new RegExp('\\\\d{' + g2 + '}\\\\B', 'g'),\n '$&' + (format.fractionGroupSeparator || ''))\n : fractionPart)\n : intPart;\n }\n\n return (format.prefix || '') + str + (format.suffix || '');\n };\n\n P.toFraction = function (md) {\n var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,\n x = this,\n xc = x.c;\n\n if (md != null) {\n n = new BigNumber(md);\n if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {\n throw Error\n (bignumberError + 'Argument ' +\n (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));\n }\n }\n\n if (!xc) return new BigNumber(x);\n\n d = new BigNumber(ONE);\n n1 = d0 = new BigNumber(ONE);\n d1 = n0 = new BigNumber(ONE);\n s = coeffToString(xc);\n\n e = d.e = s.length - x.e - 1;\n d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];\n md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;\n\n exp = MAX_EXP;\n MAX_EXP = 1 / 0;\n n = new BigNumber(s);\n n0.c[0] = 0;\n\n for (; ;) {\n q = div(n, d, 0, 1);\n d2 = d0.plus(q.times(d1));\n if (d2.comparedTo(md) == 1) break;\n d0 = d1;\n d1 = d2;\n n1 = n0.plus(q.times(d2 = n1));\n n0 = d2;\n d = n.minus(q.times(d2 = d));\n n = d2;\n }\n\n d2 = div(md.minus(d0), d1, 0, 1);\n n0 = n0.plus(d2.times(n1));\n d0 = d0.plus(d2.times(d1));\n n0.s = n1.s = x.s;\n e = e * 2;\n\n r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(\n div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];\n MAX_EXP = exp;\n\n return r;\n };\n\n P.toNumber = function () {\n return +valueOf(this);\n };\n\n P.toPrecision = function (sd, rm) {\n if (sd != null) intCheck(sd, 1, MAX);\n return format(this, sd, rm, 2);\n };\n\n P.toString = function (b) {\n var str,\n n = this,\n s = n.s,\n e = n.e;\n\n if (e === null) {\n if (s) {\n str = 'Infinity';\n if (s < 0) str = '-' + str;\n } else {\n str = 'NaN';\n }\n } else {\n if (b == null) {\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(coeffToString(n.c), e)\n : toFixedPoint(coeffToString(n.c), e, '0');\n } else if (b === 10) {\n n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);\n str = toFixedPoint(coeffToString(n.c), n.e, '0');\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);\n }\n\n if (s < 0 && n.c[0]) str = '-' + str;\n }\n\n return str;\n };\n\n P.valueOf = P.toJSON = function () {\n return valueOf(this);\n };\n\n P._isBigNumber = true;\n if (typeof Symbol == 'function' && typeof Symbol.iterator == 'symbol') {\n P[Symbol.toStringTag] = 'BigNumber';\n P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;\n }\n if (configObject != null) BigNumber.set(configObject);\n return BigNumber;\n }\n\n function bitFloor(n) {\n var i = n | 0;\n return n > 0 || n === i ? i : i - 1;\n }\n\n function coeffToString(a) {\n var s, z,\n i = 1,\n j = a.length,\n r = a[0] + '';\n for (; i < j;) {\n s = a[i++] + '';\n z = LOG_BASE - s.length;\n for (; z--; s = '0' + s);\n r += s;\n }\n for (j = r.length; r.charCodeAt(--j) === 48;);\n return r.slice(0, j + 1 || 1);\n }\n\n function compare(x, y) {\n var a, b,\n xc = x.c,\n yc = y.c,\n i = x.s,\n j = y.s,\n k = x.e,\n l = y.e;\n if (!i || !j) return null;\n a = xc && !xc[0];\n b = yc && !yc[0];\n if (a || b) return a ? b ? 0 : -j : i;\n if (i != j) return i;\n a = i < 0;\n b = k == l;\n if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;\n if (!b) return k > l ^ a ? 1 : -1;\n j = (k = xc.length) < (l = yc.length) ? k : l;\n for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;\n return k == l ? 0 : k > l ^ a ? 1 : -1;\n }\n\n function intCheck(n, min, max, name) {\n if (n < min || n > max || n !== (n < 0 ? mathceil(n) : mathfloor(n))) {\n throw Error\n (bignumberError + (name || 'Argument') + (typeof n == 'number'\n ? n < min || n > max ? ' out of range: ' : ' not an integer: '\n : ' not a primitive number: ') + String(n));\n }\n }\n\n function isOdd(n) {\n var k = n.c.length - 1;\n return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;\n }\n\n function toExponential(str, e) {\n return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +\n (e < 0 ? 'e' : 'e+') + e;\n }\n\n function toFixedPoint(str, e, z) {\n var len, zs;\n if (e < 0) {\n for (zs = z + '.'; ++e; zs += z);\n str = zs + str;\n } else {\n len = str.length;\n if (++e > len) {\n for (zs = z, e -= len; --e; zs += z);\n str += zs;\n } else if (e < len) {\n str = str.slice(0, e) + '.' + str.slice(e);\n }\n }\n return str;\n }\n\n BigNumber = clone();\n BigNumber['default'] = BigNumber.BigNumber = BigNumber;\n if (typeof define == 'function' && define.amd) {\n define(function () { return BigNumber; });\n } else if (typeof module != 'undefined' && module.exports) {\n module.exports = BigNumber;\n } else {\n if (!globalObject) {\n globalObject = typeof self != 'undefined' && self ? self : window;\n }\n globalObject.BigNumber = BigNumber;\n }\n})(this);\n\n\n\n\n\nvar nums = readline().split(' ').map(function(x) { return Number(x) });\nvar T = nums[0];\nfor (var i=1; i<=T; i++) {\n nums = readline().split(' ').map(function(x) { return Number(x) });\n var N = nums[0];\n var Q = BigNumber(N);\n Q = Q.times(Q.plus(1)).dividedToIntegerBy(2);\n var pw = BigNumber(1);\n while (pw.lte(N)) {\n Q = Q.minus(pw.times(2));\n pw = pw.times(2);\n }\n print(Q.toFixed());\n}"}], "negative_code": [], "src_uid": "a3705f29b9a8be97a9e9e54b6eccba09"} {"source_code": "const solve = (s) => {\n s += \"!\";\n\n const char = {};\n for (let i = 0; i < s.length; i++) {\n const c = s[i];\n if (!char.hasOwnProperty(c)) {\n char[c] = {\n lastIndex: null,\n used: false,\n };\n }\n char[c].lastIndex = i;\n }\n\n let res = \"\";\n let i = 0;\n while (true) {\n if (i === s.length - 1) break;\n if (char[s[i]].used) {\n i++;\n continue;\n }\n if (char[s[i]].lastIndex === i) {\n res += s[i];\n i++;\n continue;\n }\n let j = i;\n let c = s[i];\n let pos = i;\n while (char[s[j]].used || char[s[j]].lastIndex !== j) {\n j++;\n }\n for (let k = i; k <= j; k++) {\n if (!char[s[k]].used && s[k] > c) {\n c = s[k];\n pos = k;\n }\n }\n res += c;\n char[c].used = true;\n i = pos + 1;\n }\n\n return res;\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const s = readLine();\n console.log(solve(s));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n// a=a.reverse()\r\n // console.log(a)\r\n var object = {}\r\n for (let i = 0; i < a.length; i++) {\r\n if (!object[a[i]]) object[a[i]] = 0\r\n object[a[i]]++\r\n }\r\n var mark = {}\r\n var res = []\r\n for (let i = 0; i < a.length; i++) {\r\n object[a[i]]--\r\n if (!mark[a[i]]) {\r\n // console.log(a[i],res, object[res[res.length - 1]] > 0, object[res[res.length - 1]] < a[i])\r\n while (res.length > 0 && object[res[res.length - 1]] > 0 && res[res.length - 1] < a[i]) {\r\n mark[res[res.length - 1]] = false\r\n res.pop()\r\n }\r\n res.push(a[i])\r\n mark[a[i]] = true\r\n }\r\n }\r\n console.log(res.join(''))\r\n })\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (let m = 1; m < input.length; m++) {\r\n function maxStr(str) {\r\n var set = new Set();\r\n var temp = new Set();\r\n for (var i = 0; i < str.length; i++) {\r\n temp.add(str[i]);\r\n }\r\n var size = temp.size;\r\n function helper(str, set, size) {\r\n if (size === 0) {\r\n return \"\";\r\n }\r\n var first = new Map();\r\n var last = new Map();\r\n for (var i = 0; i < str.length; i++) {\r\n if (!set.has(str[i])) {\r\n if (!first.has(str[i])) {\r\n first.set(str[i], i);\r\n }\r\n last.set(str[i], i);\r\n }\r\n }\r\n var map = new Map();\r\n for (var [c1, index1] of first) {\r\n var count = 0;\r\n for (var [c2, index2] of last) {\r\n if (c1 !== c2 && index1 < index2) {\r\n count++;\r\n }\r\n }\r\n map.set(c1, count);\r\n }\r\n var n = first.size;\r\n var c;\r\n var ch;\r\n for (c = \"z\".charCodeAt(0); c >= \"a\".charCodeAt(0); c--) {\r\n ch = String.fromCharCode(c);\r\n if (map.has(ch) && !set.has(ch) && map.get(ch) >= size - 1) {\r\n break;\r\n }\r\n }\r\n set.add(ch);\r\n return ch + helper(str.slice(first.get(ch) + 1), set, size - 1);\r\n }\r\n\r\n return helper(str, set, size);\r\n }\r\n console.log(maxStr(input[m]));\r\n }\r\n})"}], "negative_code": [{"source_code": "const solve = (s) => {\n s += \"!\";\n\n const char = {};\n for (let i = 0; i < s.length; i++) {\n const c = s[i];\n if (!char.hasOwnProperty(c)) {\n char[c] = {\n lastIndex: null,\n used: false,\n };\n }\n char[c].lastIndex = i;\n }\n\n let res = \"\";\n let i = 0;\n while (true) {\n if (i === s.length - 1) break;\n if (char[s[i]].used) {\n i++;\n continue;\n }\n if (char[s[i]].lastIndex === i) {\n res += s[i];\n i++;\n continue;\n }\n let j = i;\n let c = s[i];\n let pos = i;\n while (char[s[j]].used || char[s[j]].lastIndex !== j) {\n j++;\n }\n for (let k = i; k <= j; k++) {\n if (!char[s[k]].used && s[k] > c) {\n c = s[k];\n pos = k;\n }\n }\n res += c;\n char[c].used = true;\n i = Math.max(pos + 1, j);\n }\n\n return res;\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const s = readLine();\n console.log(solve(s));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n"}, {"source_code": "const solve = (s) => {\n const char = {};\n for (let i = 0; i < s.length; i++) {\n const c = s[i];\n if (!char.hasOwnProperty(c)) {\n char[c] = {\n count: 0,\n lastIndex: null,\n used: false,\n };\n }\n char[c].count++;\n char[c].lastIndex = i;\n }\n const remove = new Array(s.length).fill(false);\n\n let j = 0;\n for (let i = 0; i < s.length; i++) {\n if (char[s[i]].count === 1) {\n char[s[i]].used = true;\n continue;\n }\n if (char[s[i]].used) {\n remove[i] = true;\n continue;\n }\n if (char[s[i]].lastIndex === i) {\n char[s[i]].used = true;\n continue;\n }\n\n while ((j < s.length && char[s[j]].count > 1) || j < i) j++;\n\n if (j < s.length) {\n if (s[i] < s[j]) {\n remove[i] = true;\n } else {\n char[s[i]].used = true;\n }\n continue;\n }\n\n if (s[i] < s[i + 1]) {\n remove[i] = true;\n } else {\n char[s[i]].used = true;\n }\n }\n\n let res = \"\";\n for (let i = 0; i < s.length; i++) {\n if (!remove[i]) res += s[i];\n }\n\n return res;\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const s = readLine();\n console.log(solve(s));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n"}, {"source_code": "const solve = (s) => {\n const count = {};\n for (const char of s) {\n if (!count.hasOwnProperty(char)) {\n count[char] = 0;\n }\n count[char]++;\n }\n const remove = new Array(s.length).fill(false);\n\n for (let i = 0; i < s.length; i++) {\n if (count[s[i]] === 1) continue;\n if (count[s[i]] === 0) {\n remove[i] = true;\n continue;\n }\n if (s[i] < s[i + 1]) {\n remove[i] = true;\n count[s[i]]--;\n } else {\n count[s[i]] = 0;\n }\n }\n\n let res = \"\";\n for (let i = 0; i < s.length; i++) {\n if (!remove[i]) res += s[i];\n }\n\n return res;\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const s = readLine();\n console.log(solve(s));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n// a=a.reverse()\r\n // console.log(a)\r\n var object = {}\r\n for (let i = 0; i < a.length; i++) {\r\n if (!object[a[i]]) object[a[i]] = 0\r\n object[a[i]]++\r\n }\r\n var mark = {}\r\n var res = []\r\n for (let i = 0; i < a.length; i++) {\r\n if (!mark[a[i]]) {\r\n object[a[i]]--\r\n // console.log(a[i],res, object[res[res.length - 1]] > 0, object[res[res.length - 1]] < a[i])\r\n while (res.length > 0 && object[res[res.length - 1]] > 0 && res[res.length - 1] < a[i]) {\r\n\r\n mark[res[res.length - 1]] = false\r\n res.pop()\r\n }\r\n res.push(a[i])\r\n mark[a[i]] = true\r\n }\r\n }\r\n console.log(res.join(''))\r\n })\r\n}\r\n"}], "src_uid": "a30f6f5273fc6c02ac1f2bc2b0ee893e"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, s) {\r\n let res = 0,\r\n len = 0;\r\n for (let i = 0; i < n;) {\r\n let j = i;\r\n while (s[i] === s[j]) {\r\n j++;\r\n len++;\r\n }\r\n if (len & 1) {\r\n len = 1;\r\n res++;\r\n } else {\r\n len = 0;\r\n }\r\n i = j;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const s = await read();\r\n res.push(solve(n, s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, s)=>{\n let result = 0;\n\n for (let i = 0; i < n; i += 2) {\n if (s[i] !== s[i + 1]) result++;\n }\n\n return result;\n\n\n // let segs = [];\n // let length = 1;\n // let cur = s[0];\n\n // for (let i = 1; i < n; i++) {\n // if (s[i] !== cur) {\n // segs.push([length, cur]);\n // length = 1;\n // cur = s[i];\n // } else {\n // length++;\n // }\n // }\n // segs.push([length, cur]);\n // console.log(`DEBUG segs`, segs);\n\n // let m = segs.length;\n // for (let i = 0; i < m; i++) {\n // let [l, bit] = segs[i];\n // console.log(`DEBUG i ${i} l ${l} bit`, bit);\n // if (l % 2 === 0) continue;\n // let sumSame = 0; let sumDif = 0;\n // for (let j = i + 1; j < m; j++) {\n // let [lj, bitj] = segs[j];\n // console.log(`DEBUG j ${j} lj ${lj} bitj`, bitj);\n // if (lj % 2 === 0) {\n // if (bitj === bit) sumSame += lj;\n // else sumDif += lj;\n // } else {\n // if (bitj === bit) {\n // result += Math.min(sumDif, sumSame + 2);\n // } else {\n // result += Math.min(sumDif, sumSame) + 1;\n // }\n // console.log(`DEBUG result`, result);\n // i = j;\n // break;\n // }\n // }\n // }\n\n // return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n // let a = ra();\n out.push(calc(n, s));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let s = readline();\r\n let curr = s[0];\r\n let count = 1;\r\n let isEven = num => num % 2 === 0;\r\n\r\n let ops = 0;\r\n\r\n for (let i = 1; i < s.length; i++) {\r\n if (s[i] === curr) {\r\n count++;\r\n } else {\r\n if (isEven(count)) {\r\n curr = s[i];\r\n count = 1;\r\n } else {\r\n ops++;\r\n count++;\r\n }\r\n }\r\n }\r\n\r\n output(ops);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let s = -1, p\n const ps = []\n for (let i = 0; i < n; i++) {\n const x = str[i]\n if (x !== p) {\n if (s >= 0) {\n ps.push(str.slice(s, i))\n }\n s = i\n p = x\n }\n }\n if (s < n) {\n ps.push(str.slice(s, n))\n }\n// console.log(ps)\n let i = 0\n let ans = 0\n let add = 0\n while (i < ps.length) {\n const x = ps[i].length + add\n if (x & 1) {\n ans++\n add = 1\n } else {\n add = 0\n }\n i++\n }\n return ans\n}\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\n\nconst countSubStrings = (arr, c) => {\n let currentValue = arr[0];\n let subStrings = [0];\n if (arr.length === 1) return 1;\n for (let index = 1; index < arr.length; index++) {\n const element = arr[index];\n if (element !== currentValue) {\n currentValue = element;\n subStrings.push(index);\n }\n }\n\n return { subStrings };\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0 && lines % 2 === 0) {\n let input = line.split(\"\").map(Number);\n const { subStrings } = countSubStrings(input);\n console.log(subStrings.filter((x) => x % 2).length);\n }\n lines++;\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let tc = parseInt(readline());\r\n while(tc--){\r\n const n = parseInt(readline());\r\n const s = readline();\r\n let last = s[0];\r\n let cnt = 1;\r\n let ans = 0;\r\n for(let i = 1; i < n; i++){\r\n if(s[i] !== last){\r\n if(cnt%2 !== 0){ // \uc9dd\uc218\uac00 \uc544\ub2c8\uba74 \ubcc0\uacbd\r\n ans++;\r\n cnt++;\r\n }\r\n else{\r\n cnt = 1;\r\n }\r\n }\r\n else{\r\n cnt++;\r\n }\r\n last = s[i];\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let str = readLine();\r\n let count = 0;\r\n for (let i = 0; i < str.length; i += 2) {\r\n if (str[i] !== str[i + 1]) count++;\r\n }\r\n return count;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = next();\r\n\t\tvar list = [];\r\n\t\tvar c = 1;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(S[i] == S[i + 1]){\r\n\t\t\t\tc++;\r\n\t\t\t}else{\r\n\t\t\t\tlist.push(c);\r\n\t\t\t\tc = 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tlist.push(c);\r\n\t\t//myerr(list);\r\n\t\tvar output = 0;\r\n\t\tc = 0;\r\n\t\tvar odd = false;\r\n\t\tfor(var i = 0; i < list.length; i++){\r\n\t\t\tif(list[i] % 2 == 1){\r\n\t\t\t\tif(!odd){\r\n\t\t\t\t\todd = true;\r\n\t\t\t\t}else{\r\n\t\t\t\t\todd = false;\r\n\t\t\t\t\toutput += c + 1;\r\n\t\t\t\t\tc = 0;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(odd){\r\n\t\t\t\t\tc++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let s = readline();\n LT({n, s});\n // PROCESSING:\n let D = [new Array(n).fill(0), new Array(n).fill(0)];\n let cost = (want, pos)=>+s[pos]==want ? 0 : 1;\n // D[ends with][pos]\n for (let i=1; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, s)=>{\n let result = 0;\n\n let segs = [];\n let length = 1;\n let cur = s[0];\n\n for (let i = 1; i < n; i++) {\n if (s[i] !== cur) {\n segs.push([length, cur]);\n length = 1;\n cur = s[i];\n } else {\n length++;\n }\n }\n segs.push([length, cur]);\n // console.log(`DEBUG segs`, segs);\n\n let m = segs.length;\n for (let i = 0; i < m; i++) {\n let [l, bit] = segs[i];\n // console.log(`DEBUG i ${i} l ${l} bit`, bit);\n if (l % 2 === 0) continue;\n let sumSame = 0; let sumDif = 0;\n for (let j = i + 1; j < m; j++) {\n let [lj, bitj] = segs[j];\n // console.log(`DEBUG j ${j} lj ${lj} bitj`, bitj);\n if (lj % 2 === 0) {\n if (bitj === bit) sumSame += lj;\n else sumDif += lj;\n } else {\n if (bitj === bit) {\n result += Math.min(sumDif, sumSame + 2);\n } else {\n result += Math.min(sumDif, sumSame) + 1;\n }\n i = j;\n break;\n }\n }\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n // let a = ra();\n out.push(calc(n, s));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, s)=>{\n let result = 0;\n\n let segs = [];\n let length = 1;\n let cur = s[0];\n\n for (let i = 1; i < n; i++) {\n if (s[i] !== cur) {\n segs.push([length, cur]);\n length = 1;\n cur = s[i];\n } else {\n length++;\n }\n }\n segs.push([length, cur]);\n\n let m = segs.length;\n for (let i = 0; i < m; i++) {\n let [l, bit] = segs[i];\n if (l % 2 === 0) continue;\n let sumSame = 0; let sumDif = 0;\n for (let j = i + 1; j < m; j++) {\n let [lj, bitj] = segs[j];\n if (lj % 2 === 0) {\n if (bitj === bit) sumSame += lj;\n else sumDif += lj;\n } else {\n if (bitj === bit) {\n result += Math.min(sumDif, sumSame + 2);\n } else {\n result += Math.min(sumDif, sumSame) + 1;\n }\n }\n }\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n // let a = ra();\n out.push(calc(n, s));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "aded139ff4d3f313f8e4d81559760f12"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n m,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, m, a } = testCase;\n\n const sum = a.reduce((acc, val) => acc + val, 0);\n const maxi = Math.max(...a);\n const mini = Math.min(...a);\n\n let result = sum + maxi - mini + n <= m ? \"YES\" : \"NO\";\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\n\nconst calc = (n, m, a)=>{\n if (n >= m) return 'NO';\n a = a.sort((a, b) => a - b);\n let pos = 0;\n\n for (let i = 1; i < n; i++) {\n pos += a[i] + 1;\n if (pos >= m) {\n return 'NO';\n }\n }\n\n if (Math.abs(pos - m) <= a[n - 1]) return 'NO';\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, m] = ra();\n let a = ra();\n \n console.log(`${calc(n, m, a)}`);\n }\n}\n\n\n\n"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var n = a[0], m = a[1]; \r\n var l = readline().split(' ').map(Number);\r\n var res = l.reduce((prev, curr) => {\r\n return prev + curr;\r\n });\r\n \r\n var s = n + res - Math.min(...l) + Math.max(...l);\r\n if (s <= m) print('YES');\r\n else print('NO');\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, a) {\r\n if (n > m) {\r\n console.log('NO');\r\n return false;\r\n }\r\n a.sort((a, b) => a - b);\r\n let j = 0;\r\n for (let i = 0; i < n - 1; i++) {\r\n var _a;\r\n j += Math.max(a[i], (_a = a[i + 1]) !== null && _a !== void 0 ? _a : 0) + 1;\r\n }\r\n j += Math.max(a[0], a[n - 1]);\r\n if (j < m) {\r\n console.log('YES');\r\n return true;\r\n } else {\r\n console.log('NO');\r\n return false;\r\n }\r\n}\r\n\r\nfunction main(inputs) {\r\n const t = Number(inputs[0]);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = inputs[i * 2 + 1].trim().split(' ').map(Number);\r\n const a = inputs[i * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, m, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\n\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, m, A)=>{\n A.sort((a, b)=>b-a);\n let frames = [];\n let prevI = 0;\n for (let i=1; i {\n s += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n s = s.split(\"\\n\").map((z) => z.trim());\n\n main();\n});\n\nfunction main() {\n let t = Number(s[0]);\n\n let i = 1;\n while (t--) {\n const [n, m] = s[i].split(\" \").map(Number);\n i++;\n const a = s[i].split(\" \").map(Number);\n i++;\n\n solve(n, m, a);\n }\n}\n\nfunction solve(n, m, a) {\n if (n > m) {\n console.log(\"NO\");\n return;\n }\n\n a.sort((q, w) => w - q);\n\n let count = a.length;\n const vacantCount = a.reduce((acc, val) => acc + val, 0);\n\n if (count + vacantCount + a[0] - a[a.length - 1] > m) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, a) {\r\n let res = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n const tmp = new Array(n).fill(0),\r\n queue = [[i + 1, 1], [i - 1, -1]];\r\n let count = 0;\r\n for (let [j, dj] of queue) {\r\n if (j < 0 || j >= n) continue;\r\n let num = Math.floor(tmp[j - dj] / (a[j] * dj)) + 1;\r\n tmp[j] = num * a[j] * dj;\r\n count += num;\r\n queue.push([j + dj, dj]);\r\n }\r\n res = Math.min(res, count);\r\n }\r\n console.log(res);\r\n}\r\n\r\nfunction main(inputs) {\r\n const n = Number(inputs[0].trim());\r\n const a = inputs[1].trim().split(' ').map(Number);\r\n solve(n, a);\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, a) {\r\n if (n > m) {\r\n console.log('NO');\r\n return false;\r\n }\r\n\r\n let j = 0;\r\n\r\n for (let i = 0; i < n - 1; i++) {\r\n var _a;\r\n\r\n j += Math.max(a[i], (_a = a[i + 1]) !== null && _a !== void 0 ? _a : 0) + 1;\r\n }\r\n\r\n j += Math.max(a[0], a[n - 1]);\r\n\r\n if (j < m) {\r\n console.log('YES');\r\n return true;\r\n } else {\r\n console.log('NO');\r\n return false;\r\n }\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, m] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, m, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, a) {\r\n let j = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n var _a;\r\n\r\n // if (j > 0 && j - pre - 1 < a[i]) j = pre + a[i] + 1\r\n if (j >= m - a[0]) {\r\n console.log('NO');\r\n return;\r\n }\r\n\r\n j += Math.max(a[i], (_a = a[i + 1]) !== null && _a !== void 0 ? _a : 0) + 1;\r\n\r\n if (j > m) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n\r\n console.log('YES');\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, m] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, m, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, a) {\r\n let j = 0,\r\n pre = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (j > 0 && j - pre - 1 < a[i]) j = pre + a[i] + 1;\r\n\r\n if (j >= m - a[0]) {\r\n console.log('NO');\r\n return;\r\n }\r\n [j, pre] = [j + a[i] + 1, j];\r\n\r\n if (j > m) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n\r\n console.log('YES');\r\n}\r\n\r\nfunction main(inputs) {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, m] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const a = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n solve(n, m, a);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}, {"source_code": "'use strict';\n\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, m, A)=>{\n A.sort((a, b)=>b-a);\n let arr = [0];\n let set = new Set();\n let num = 0;\n let prev = A[0]\n let l1, l2\n for (let i=1; i +t)\r\n \r\n print(Challenging(arr));\r\n \r\n}\r\nfunction Challenging (jrray){\r\n\r\n var r = jrray.length;\r\n\r\n var f = 1;\r\n for(var i = 0; i= jrray[i] && i < r-1){\r\n i++;\r\n }\r\n if(i == r-1){\r\n return 'YES';\r\n }else {\r\n return 'NO';\r\n }\r\n }\r\n\r\n }\r\n if (f == 1){\r\n return 'YES';\r\n }\r\n\r\n\r\n}", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let a=line[2*_].split(' ').map(x=>{return parseInt(x)});\r\n let flag=false;\r\n a.unshift(1e9+10);\r\n a.push(1e9+10);\r\n // console.log(a);\r\n let cnt=0;\r\n for(let i=1;i<=n;i++)\r\n {\r\n let j=i;\r\n // if(a[i]===a[j])\r\n // {\r\n while(a[j]===a[i]&&j<=n) j++;\r\n j--;\r\n if(a[i] newlist[i] && newlist[i] < newlist[i + 1]){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(newlist.length <= 2){\r\n\t\t\tc++;\r\n\t\t}else{\r\n\t\t\tif(newlist[0] < newlist[1]){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t\tif(newlist[newlist.length - 2] > newlist[newlist.length - 1]){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(c == 1){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline()-0;\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar ok = 0;\r\n\ta[-1] = inf;\r\n\ta[n] = inf;\r\n\tfor(var i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let p, l, r, find = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === p) {\n r = i\n } else {\n l = r = i\n }\n //\n const a = l === 0 || arr[l - 1] > arr[l]\n const b = r === n - 1 || arr[r] < arr[r + 1]\n if (a && b) {\n if (find) {\n return 'NO'\n } else {\n find = 1\n }\n }\n //\n p = arr[i]\n }\n return find ? 'YES' : 'NO'\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n //let mod = 10**9+7\r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\" \").map(x=>parseInt(x));\r\n \r\n let diff_arr =[]\r\n let upwards=false\r\n for(let i=0;i0)\r\n {\r\n console.log(\"no\")\r\n continue loopwhile\r\n }\r\n }\r\n \r\n }\r\n console.log(\"yes\")\r\n } \r\n}"}], "negative_code": [], "src_uid": "7b6a3de5ad0975e4c43f097d4648c9c9"} {"source_code": "var str = readline()\nvar winFirst = false;\n\nfor(var i=1;i 0) {\n ans.pop();\n //print('pop = '+ ans.join(''));\n\t\t\t cnt ++;\n }\n\t\t else {\n ans.push(str[j]);\n //print('push = '+ ans.join(''))\n }\n}\nif(cnt == 0) print('NO')\nelse {\n print(cnt %2 == 1 ? 'YES' : 'NO')\n }\n\n//"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.on('line', line => {\n const output = solution(line)\n console.log(output)\n})\n\nrl.on('close', () => {\n // console.log(input)\n})\n\nfunction solution(line) {\n let input = line.split('')\n let j = 0\n for (let i = 0;i < input.length;i++) {\n if (i < input.length - 1) {\n if (input[i] === input[i+1]) {\n j++\n input.splice(i, 2)\n i = i - 2\n continue\n }\n }\n }\n if (j % 2 === 0) {\n return 'NO'\n }\n return 'YES'\n}\n"}, {"source_code": "var str = '';\nvar readliner = require('readline');\nvar rl = readliner.createInterface(process.stdin, process.stdout, null);\nrl.on('line', function (cmd) {\n //console.log('You just typed: '+cmd);\n str = cmd;\n }).on('close', main);\n\nfunction main() {\n //console.log('goodbye!');\n\n/* var mn = 1000000000;\n for (var code=0; code<(1<<9); code++) {\n\tvar cnt_ones = 0;\n\tfor (var j=0; j<9; j++) cnt_ones += (code>>j)&1;\n var x = N;\n \n }*/\n\n var ans = [];\n var Q = 0;\n //console.log(str);\n for (var j=0; j 0 && ans[ans.length-1] == str[j]) {\n\t\t\tans.pop();\n\t\t\tQ++;\n }\n\t\telse\n\t\t\tans.push(str[j]);\n \n //console.log(ans);\n //console.log(Q);\n\n if (Q % 2 === 1)\n \tconsole.log(\"Yes\");\n else\n \tconsole.log(\"No\");\n \n //var x = 1.2345678;\n //console.log('x = ',Number(x).toFixed(5));\n\n process.exit(0);\n};\n\n//var lines = data.split(/\\r?\\n/);\n"}, {"source_code": "function main(str){\n\n\n var cnt = 0;\n var stack = [];\n stack.push(str[0]);\n\n for(var i = 1 ; i < str.length ; i++){\n if(stack.length !== 0 && str[i] === stack[stack.length-1]){\n cnt++;\n stack.pop();\n }\n else{\n stack.push(str[i]);\n }\n }\n\n cnt % 2 === 0 ? print(\"NO\") : print(\"YES\");\n}\n\n\nvar str = readline();\n\nmain(str);\n"}, {"source_code": "var str = readline()\nvar winFirst = false;\n\nfor(var i=1;i 0 && arguments[0] !== undefined ? arguments[0] : 0;\n\n for (var i = start; i < line.length - 1; i++) {\n if (line[i] === line[i + 1]) {\n return i;\n }\n }\n return false;\n}\n\nvar index = check();\nvar count = 0;\nwhile (index !== false) {\n line.splice(index, 2);\n count++;\n if (index > 0) index--;\n index = check(index);\n}\n\nwrite(count % 2 === 1 ? \"Yes\" : \"No\");"}, {"source_code": "var line = readline().split('');\nvar count = 0;\nwhile (1) {\n var length = line.length;\n var c = count;\n for (var i = 0; i < length - 1; i++) {\n if (line[i] === line[i + 1]) {\n line.splice(i, 2)\n count++;\n i-=2;\n length -= 2;\n }\n }\n if (c === count) {\n break;\n }\n}\n\nwrite(count % 2 === 1 ? 'Yes' : 'No')"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.on('line', line => {\n const output = solution(line)\n console.log(output)\n})\n\nrl.on('close', () => {\n // console.log(input)\n})\n\nfunction solution(line) {\n let input = line.split('')\n let length = input.length\n for (let i = 0;i < input.length;i++) {\n if (i < input.length - 1) {\n if (input[input.indexOf(input[i])] === input[input.indexOf(input[i + 1])]) {\n input.splice(i, 2)\n i = i - 2\n continue\n }\n }\n }\n console.log(input)\n if (input.length === length || !input.length) {\n return 'NO'\n }\n return 'YEs'\n}\n"}, {"source_code": "var str = readline()\nvar winFirst = false;\n\nfor(var i=1;i { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A = A.sort((a, b) => a - b);\n \n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n", "positive_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n, l] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n let max = (nums.length === 1) ? Math.max(nums[0], l-nums[0]) : 0;\n\n for (let i = 1; i < nums.length; i += 1) {\n if (Math.abs(nums[i] - nums[i-1]) > max) max = Math.abs(nums[i] - nums[i-1])\n }\n\n max /= 2;\n if (nums[0] >= max || l-nums[nums.length-1] >= max) {\n console.log(Math.max(nums[0], l-nums[nums.length-1]).toPrecision(9))\n } else console.log(max.toPrecision(9));\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const [n, l] = input[0].split(' ').map(Number);\n const arr = input[1].split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let dist = arr[0] - 0;\n if ((l - arr[arr.length - 1]) > dist) dist = l - arr[arr.length - 1];\n for (let i = 1; i < arr.length; i++) {\n if (((arr[i] - arr[i - 1]) / 2) > dist) dist = (arr[i] - arr[i - 1]) / 2;\n }\n console.log(dist);\n});"}, {"source_code": "'use strict';\n\n// const rlLib = require('readline');\n\n// const rl = rlLib.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// let inputs = [];\n// let allCount = 2;\n// let currentLine = 0;\n\n// rl.on('line', (input) => {\n// \tinputs.push(input);\n// \tif (inputs.length === allCount) {\n// \t\tmain();\n\n// \t\trl.close();\t\t\n// \t}\n// });\n\n// function readline() {\n// \treturn inputs[currentLine++];\n// }\n// function print() {\n// \tconsole.log.apply(this, arguments);\n// }\n\n\n// function main() {\n\tlet rl = readline().split(' ').map(function(e) {return parseInt(e);});\n\tlet f = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n\n\tf = f.sort(function(a, b) {return a - b;});\n\n\tlet res = f[0] * 2;\n\n\tif (f[f.length - 1] < rl[1]) {\n\t\tlet r = (rl[1] - f[f.length - 1])*2;\n\t\tres = res > r ? res : r;\n\t}\n\n\n\tf.forEach(function(e, i) {\n\t\tif (i+1 < f.length && (f[i+1] - f[i]) > res) {\n\t\t\tres = f[i+1] - f[i];\n\t\t}\n\t});\n\n\tprint(res / 2);\n// }\n\n"}, {"source_code": "let solution = function (n, l, arr) {\n arr.sort((x, y) => (x - y))\n // let check = function(i) {\n // let smallest = 0\n // for(let x of arr) {\n // let left = x - i\n // let right = x + i\n // if(left > smallest+1) return false\n // smallest = right\n // }\n // return right >= l\n // }\n\n // let left = 1\n // let right = l\n // while(left > right) {\n // let mid = Math.floor((left + right)/2)\n // if(check(mid)) {\n // right = mid-1\n // } else {\n // left = mid+1\n // }\n // }\n // while(check(left)) {\n // left--\n // }\n // return left+1\n let max = 0\n let first = arr[0]\n let last = l - arr[arr.length-1]\n for(let i = 1; i {\n lineCount++\n if(lineCount === 1) {\n [n, l] = line.split(' ').map(x => parseInt(x))\n }\n if(lineCount === 2) {\n arr = line.split(' ').map(x => parseInt(x))\n // console.log(n, l, arr)\n result = solution(n, l, arr)\n console.log(result)\n }\n})"}, {"source_code": "\"use strict\";\n\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar l = 2 * input[1];\nvar a = readline().split(' ').map(value => 2 * value).sort((a, b) => a - b);\n\nvar f = function (x) {\n var right = 0;\n\n for (let i = 0; i < n; ++i) {\n if (right < a[i] - x) {\n return false;\n }\n\n right = a[i] + x;\n }\n\n return right >= l;\n};\n\nvar left = 0;\nvar right = l;\n\nwhile (right - left > 1) {\n var m = Math.floor((left + right) / 2);\n\n if (f(m)) {\n right = m;\n } else {\n left = m;\n }\n}\n\nwrite(right / 2);\n"}, {"source_code": "X=readline().split(' ').map(Number)\nn=X[0],l=X[1]\nA=readline().split(' ').map(Number)\nA=A.sort((x,y)=>x-y).reduce((a,c)=>a.length?(a[a.length-1]!=c?a.concat(c):a):[c],[])\n\nA=A.map((x,i) =>\n Math.max(i==0 ? x : (A[i-1]-x)/2, (i==A.length-1) ? l-x : (A[i+1]-x)/2))\n\nprint(Math.max.apply(null, A))\n\n\n\n\n"}, {"source_code": "function main() {\n var counters = readline().trim().split(' ').map(string => parseInt(string, 10));\n var lanternsCount = counters[0];\n var streetLength = counters[1];\n var lanternsLocation = readline().trim().split(' ').map(string => parseInt(string));\n \n lanternsLocation = lanternsLocation.sort((a, b) => a - b);\n\n var min_radius = 0.0000000000;\n for (var index = 0; index < lanternsLocation.length - 1; index++) {\n var curr_radius = (lanternsLocation[index + 1] - lanternsLocation[index]) / 2.0000000000;\n min_radius = Math.max(min_radius, curr_radius);\n }\n\n if (!lanternsLocation.includes(0)) {\n min_radius = Math.max(min_radius, lanternsLocation[0]);\n }\n\n if (!lanternsLocation.includes(streetLength)) {\n min_radius = Math.max(min_radius, streetLength - lanternsLocation[lanternsLocation.length - 1]);\n }\n \n print(min_radius);\n}\n\nmain();"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i += 2) {\n let info = txt[i].split(\" \");\n doit(info[1] * 1, txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1).sort((a, b) => a - b));\n}\n\nfunction doit(n, tab) {\n let changes = tab[0];\n let g = (n - tab[tab.length - 1]);\n if (g > changes) changes = g;\n for (let i = 1; i < tab.length; i++) {\n let r = (tab[i] - tab[i - 1]) / 2;\n if (changes < r) changes = r;\n }\n console.log(changes);\n\n\n}"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '2 1000000000';\n// case 2: return '0 1000000000';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nvar list = readline().split(' ');\n\nvar n = parseInt(list[0]);\nvar l = parseInt(list[1]);\n\nvar a = readline().split(' ').map(function(currentValue) {\n return parseInt(currentValue);\n});\n\na.sort(function(x, y) {\n return x - y;\n});\n\nvar ans = Math.max(a[0], l - a[a.length - 1]);\n\nfor (var i = 1; i < a.length; i ++) {\n ans = Math.max(ans, (a[i] - a[i-1]) / 2);\n}\n\nwrite(ans);\n"}, {"source_code": "var tokens = readline().split(\" \");\nvar n = +tokens[0];\nvar l = +tokens[1];\nvar array = readline().split(\" \").map(Number).sort(function(x,y){return x-y});\nvar max = -1;\nfor(var i = 1; i < n; i++){\n var value = array[i] - array[i-1];\n max = max > value ? max : value;\n}\nvar res = Math.max(max/2,array[0] - 0, l - array[n-1] );\nwrite(res);"}, {"source_code": "var input = readline().split(' ').map(x => parseInt(x));\nvar n = input[0], l = input[1];\nvar sorted = readline().split(' ').map(x => parseInt(x)).sort((a,b) => a-b);\nvar difference = -Infinity;\nfor (var i = 1; i < sorted.length; i++) difference = Math.max(difference, sorted[i] - sorted[i-1]);\ndifference /= 2;\nif (sorted[0] !== 0) difference = Math.max(sorted[0], difference);\nif (sorted[n-1] !== l) difference = Math.max(difference, l - sorted[n-1]);\nprint(difference);\n"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], l = +input[1],\na = readline().split(\" \").map(Number).sort(function(x,y){return x-y});\nvar max = -1, x;\n\nfor(i = 1; i < n; i++){\n\tx = a[i] - a[i-1];\n\tmax = (x > max) ? x : max;\n}\n\nx = Math.max(max/2, Math.max((l - a[n-1]), (a[0] - 0)));\n\nwrite(x.toFixed(10));"}, {"source_code": "nl =readline().split(' ').map(Number);n=nl[0];l=nl[1];\na = readline().split(' ').map(Number).sort((a,b) => a > b ? 1 : a < b ? -1 : 0);\nr = Math.max(a[0], l - a[n-1]);\nfor (i=0; i r) r = d; }\nwrite(r);\n"}, {"source_code": "nl = readline().split(' ').map(Number); n=nl[0]; l=nl[1];\na = readline().split(' ').map(i => i/2).sort((a, b) => a - b);\nr = Math.max(2*a[0], l - 2*a[n-1]);\nfor (i=0; i r) r = d; }\nwrite(r);\n"}, {"source_code": "var inp = readline().split(\" \").map(function(x){return parseInt(x);});\nvar n = inp[0];\nvar l = inp[1];\n\nvar a = readline().split(\" \").map(function(x){return parseInt(x);});\n\na.sort(function(e,x){return e - x;});\nif (a[0] != 0){\n\ta.unshift(-a[0]);\n\tn++;\n}\nif (a[n-1] != l){\n\ta.push(l + (l-a[n-1]));\n\tn++;\n}\nvar max = 0;\nvar dif = max;\nfor(var i=1; i < n; i++){\n\tdif = a[i] - a[i-1];\n\tif (dif > max) max = dif;\n}\n\nprint(max/2);"}, {"source_code": "if (undefined == readline) {\n\treadline = function() {\n\n\t}\n}\n\nvar ints = function() {\n\treturn readline().split(' ').map(function(w) {\n\t\treturn parseInt(w)\n\t})\n}\n\nvar minus = function(a, b) {\n return a - b\n}\n\nvar numbers = ints()\n\tn = numbers[0],\n\tl = numbers[1]\nnumbers = ints()\nnumbers.sort(minus)\n\nvar k = numbers.length - 1,\n\tdistance = Math.max(2 * numbers[0], 2 * (l - numbers[numbers.length - 1]))\n\nwhile (k > 0) {\n\tdistance = Math.max(distance, numbers[k] - numbers[k - 1])\n\tk --\n}\n\nprint((distance / 2).toFixed(9))"}, {"source_code": "var n, l, max = 0.0;\nvar input = readline();\nn = Number(input.split(\" \")[0]);\nl = Number(input.split(\" \")[1]);\n\nvar lanterns = new Array(n);\ninput = readline();\n\nfor (var i = 0; i < lanterns.length; i++) {\n lanterns[i] = Number(input.split(\" \")[i]);\n}\n\nfor (var i = 0; i < lanterns.length - 1; i++) {\n for (var j = i + 1; j < lanterns.length; j++) {\n if (lanterns[i] > lanterns[j]) {\n var tmp = lanterns[i];\n lanterns[i] = lanterns[j];\n lanterns[j] = tmp;\n }\n }\n} // sorting\n\nfor (var i = 0; i < lanterns.length - 1; i++) {\n var difference = lanterns[i + 1] - lanterns[i];\n if (difference > max) {\n max = difference;\n }\n}\nmax /= 2;\nvar first = lanterns[0] - 0;\nvar last = l - lanterns[n - 1];\n\nif (first > max) {\n max = first;\n}\nif (last > max) {\n max = last;\n}\n\nwrite(max);\n\n\n\n\n"}, {"source_code": "if (undefined == readline) {\n\treadline = function() {\n\n\t}\n}\n\nvar ints = function() {\n\treturn readline().split(' ').map(function(w) {\n\t\treturn parseInt(w)\n\t})\n}\n\nvar minus = function(a, b) {\n return a - b\n}\n\nvar numbers = ints()\n\tn = numbers[0],\n\tl = numbers[1]\nnumbers = ints()\nnumbers.sort(minus)\n\nvar k = numbers.length - 1,\n\tdistance = Math.max(2 * numbers[0], 2 * (l - numbers[numbers.length - 1]))\n\nwhile (k > 0) {\n\tdistance = Math.max(distance, numbers[k] - numbers[k - 1])\n\tk --\n}\n\nprint((distance / 2).toFixed(9))"}, {"source_code": "var input = readline().trim().split(' ').map((x)=>parseInt(x));\nvar a = readline().trim().split(' ').map((x)=>parseInt(x));\n\nif(input[0]==1)\n print(Math.max(a[0],input[1]-a[0]));\nelse{\n a.sort((a,b)=>a-b);\n \n var b =[];\n for (var i = 0; i < a.length-1; i++) {\n \tb.push(a[i+1]-a[i]);\n }\n \n b.sort((a,b)=>b-a)\n print(Math.max((b[0]*1.0)/2,a[0],input[1]-a[a.length-1]));\n}"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]), l = Number(s[1]);\ns = readline().split(\" \").map(Number).sort((a, b) => a-b);\n\nvar maxDif = Math.max(s[0] * 2, (l - s[n-1]) * 2);\nfor(var i = 1; i < n; i++) {\n maxDif = Math.max(maxDif, s[i] - s[i-1]);\n}\n\nprint(maxDif / 2);"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[0]), l = Number(s[1]);\ns = readline().split(' ').map(Number).sort((a, b) => a - b)\nvar maxDif = Math.max(s[0] * 2, (l - s[n - 1]) * 2);\nfor (var i = 1; i < n; i++) {\n maxDif = Math.max(maxDif, s[i] - s[i - 1]);\n}\nprint(maxDif / 2);"}, {"source_code": "\n'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nlet _arr = readline().getNumArray(),\n n = _arr[0],\n l = _arr[1],\n array = readline().getNumArray(),\n maxDistance = 0;\n\narray.sort(function(a, b) {\n return a - b;\n});\n\nfor(let i = 1; i < array.length; i++) {\n if(array[i] - array[i - 1] > maxDistance) {\n maxDistance = array[i] - array[i - 1];\n }\n}\n\nif (array[0] > maxDistance / 2 || l - array[array.length - 1] > maxDistance / 2) {\n if(array[0] > l - array[array.length - 1]) {\n maxDistance = array[0]; \n } else {\n maxDistance = l - array[array.length - 1];\n }\n} else {\n maxDistance = maxDistance / 2;\n}\nwrite(maxDistance);\n\n\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n const [n, l] = splitAndParseInt(input[0]);\n const nums = splitAndParseInt(input[1]);\n\n nums.sort((a, b) => a - b);\n let maxD = 0;\n\n if (nums.length > 1)\n for (let i = 1; i < nums.length; i += 1) {\n maxD = nums[i] - nums[i - 1] > maxD ? nums[i] - nums[i - 1] : maxD;\n }\n\n if (nums[0] * 2 > maxD) maxD = nums[0] * 2;\n if ((l - nums[nums.length - 1]) * 2 > maxD)\n maxD = (l - nums[nums.length - 1]) * 2;\n\n console.log((maxD / 2).toFixed(9));\n});\n"}, {"source_code": "var f = readline().split(\" \");\nvar str = readline().split(\" \").sort((x,y)=>x-y);\nvar res = Math.max(+str[0] * 2, (+f[1] - str[+f[0]-1]) * 2);\n\tfor (var i=0; i<+f[0]; i++){\n\t\t\tif (Number(str[i+1])-Number(str[i])>res)\n\t\t\t\tres = +str[i+1]-Number(str[i]);\n\t\t\t\n\t\n\t}\n\tprint(res/2);"}, {"source_code": "var main = function(nPositions, l)\n{\n\tvar max = 0;\n\tvar increase = function(a, b)\n\t{\n\t\treturn +a - +b;\n\t}\n\tvar toAnArray = function(str)\n\t{\n\t\tstr = str.split(' ');\n\t\treturn str;\n\t}\n\tnPositions = toAnArray(nPositions);\n\tnPositions.sort(increase);\n\tfor (var i = 1; i <= nPositions.length - 1; i++)\n\t{\n\t\tif (+nPositions[i] - +nPositions[i - 1] > max) max = +nPositions[i] - +nPositions[i - 1];\n\t}\n if (((+nPositions[0] > max / 2) && (l - +nPositions[nPositions.length - 1] > max / 2)) && (+nPositions[0] > l - +nPositions[nPositions.length - 1] ) )return +nPositions[0];\n\t\telse if (((+nPositions[0] > max / 2) && (l - +nPositions[nPositions.length - 1] > max / 2)) && (+nPositions[0] < l - +nPositions[nPositions.length - 1] ) )return l - +nPositions[nPositions.length - 1];\n\t\telse if (+nPositions[0] > max / 2) return +nPositions[0];\n\t\telse if (l - +nPositions[nPositions.length - 1] > max / 2) return l - +nPositions[nPositions.length - 1];\n\t\telse return max / 2;\n\t\n}\n\n{\n\tvar lAndN = readline(),\n\tnPositions = readline();\n\tlAndN = lAndN.split(' ');\n\tprint(main(nPositions, +lAndN[1]));\n}"}, {"source_code": "var inp = readline().split(' ');\nvar a = readline().split(' ');\n\nfor(var i=0; i a-b);\n\nvar max_d = -Infinity;\n\nif(a[0] !== 0) max_d = a[0];\nif(a[n-1] !== m && m - a[n-1] > max_d) max_d = m - a[n-1];\n\nfor(var i=0; i max_d) max_d = (a[i] - a[i-1])/2;\n}\n\nprint(max_d);"}, {"source_code": "(function main() {\n var line = readline().split(\" \"),\n n = line[0],\n l = line[1],\n aStrings = readline().split(\" \"),\n a = [],\n d,\n i;\n\n\n for (i in aStrings) {\n a[i] = +aStrings[i];\n }\n\n a.sort(function(a, b) {\n return a - b;\n });\n\n d = Math.max(a[0], l - a[a.length - 1]);\n\n for (i = 1; i < a.length; i++) {\n d = Math.max(d, (a[i] - a[i-1]) / 2);\n }\n\n print(d.toFixed(10));\n})();\n"}, {"source_code": "var n = readline().split(' ');\n\nvar l = n[1];\nn = n[0];\n\nvar a = readline().split(' ');\nfor (var i = 0; i < n; i++) {\n a[i] = parseInt(a[i])\n}\na.sort(function (a, b) { return a - b });\nvar ans = Math.max(a[0], l - a[n - 1]);\n\nfor (var i = 0; i < n - 1; i++) {\n if ((a[i + 1] - a[i]) / 2 > ans) {\n ans = (a[i + 1] - a[i]) / 2;\n }\n}\n\n\nwrite(ans)\n// console.log(l)"}, {"source_code": "var nums = readNums();\n\nvar n = nums[0];\nvar l = nums[1];\n\nvar lanterns = readNums();\nlanterns.sort(function(a,b){return b-a});\n\nvar k = 0;\n\nfor (var i = 0; ik) {\n k = h;\n }\n}\n\nvar r = k/2;\n\nif (lanterns[n-1] > r) {\n r = lanterns[n-1];\n}\n\nif ((l-lanterns[0]) > r) {\n r = l-lanterns[0];\n}\n\nprint(r);\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}], "negative_code": [{"source_code": "var input = readline(), n = +input[0], l = +input[1],\na = readline().split(\" \").map(Number).sort(function(x,y){return x-y});\nvar max = -1, x;\n\nfor(i = 1; i < n; i++){\n\tx = a[i] - a[i-1];\n\tmax = (x > max) ? x : max;\n}\n\nmax = Math.max(max/2, Math.max((l - a[n-1]), a[0]));\n\nwrite(max.toFixed(10));"}, {"source_code": "var inp = readline().split(\" \").map(function(x){return parseInt(x);});\nvar n = inp[0];\nvar l = inp[1];\n\nvar a = readline().split(\" \").map(function(x){return parseInt(x);});\na.sort(function(e,x){return e > x;});\nif (a[0] != 0){\n\ta.unshift(-a[0]);\n\tn++;\n}\nif (a[n-1] != l){\n\ta.push(l + (l-a[n-1]));\n\tn++;\n}\nvar max = 0;\nvar dif = max;\nfor(var i=1; i < n; i++){\n\tdif = a[i] - a[i-1];\n\tif (dif > 0 && dif > max) max = dif;\n}\n\nprint(max/2);"}, {"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(w) {\n\t\treturn parseInt(w)\n\t})\n}\n\nvar minus = function(a, b) {\n return a - b\n}\n\nvar numbers = ints()\n\tn = numbers[0],\n\tl = numbers[1]\nnumbers = ints()\nnumbers.sort(minus)\n\nvar result = numbers.reduce(function(current, position) {\n\tcurrent.max = Math.max(current.max, position - current.position)\n\tcurrent.position = position\n\treturn current\n}, {\n\tmax: 0,\n\tposition: 0\n})\n\nprint((result.max / 2).toFixed(9))"}, {"source_code": "var input = readline().trim().split(' ').map((x)=>parseInt(x));\nvar a = readline().trim().split(' ').map((x)=>parseInt(x));\n\na.sort((a,b)=>a-b);\n\nvar b =[];\nfor (var i = 0; i < a.length-1; i++) {\n\tb.push(a[i+1]-a[i]);\n}\n\nb.sort((a,b)=>b-a)\nprint(Math.max((b[0]*1.0)/2,a[0],input[1]-a[a.length-1]));"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[0]), l = Number(s[1]);\ns = readline().split(' ').map(el => parseInt(el)).sort((a, b) => a - b)\nvar maxDif = Math.max(s[0] * 2, (l - s[n - 1] * 2));\nfor (var i = 1; i < n; i++) {\n maxDif = Math.max(maxDif, s[i] - s[i - 1]);\n}\nprint(maxDif / 2);"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[0]), l = Number(s[1]);\ns = readline().split(' ').map(Number).sort((a, b) => a - b)\nvar maxDif = Math.max(s[0] * 2, (l - s[n - 1] * 2));\nfor (var i = 1; i < n; i++) {\n maxDif = Math.max(maxDif, s[i] - s[i - 1]);\n}\nprint(maxDif / 2);"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[0]), l = Number(s[1]);\ns = readline().split(' ').map(el => parseFloat(el)).sort((a, b) => a - b)\nvar maxDif = Math.max(s[0] * 2, (l - s[n - 1] * 2));\nfor (var i = 1; i < n; i++) {\n maxDif = Math.max(maxDif, s[i] - s[i - 1]);\n}\nprint(maxDif / 2);"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nlet _arr = readline().getNumArray(),\n n = _arr[0],\n l = _arr[1],\n array = readline().getNumArray(),\n maxDistance = 0;\n\narray.sort(function(a, b) {\n return a - b;\n});\n\nfor(let i = 1; i < array.length; i++) {\n if(array[i] - array[i - 1] > maxDistance) {\n maxDistance = array[i] - array[i - 1];\n }\n}\n\nif (array[0] > maxDistance / 2 || l - array[array.length - 1] > maxDistance / 2) {\n if(array[0] > maxDistance / 2) {\n maxDistance =array[0]; \n } else {\n maxDistance = l - array[array.length - 1];\n }\n} else {\n maxDistance = maxDistance / 2;\n}\nwrite(maxDistance);"}, {"source_code": "\n'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nlet _arr = readline().getNumArray(),\n n = _arr[0],\n l = _arr[1],\n array = readline().getNumArray(),\n maxDistance = 0;\n\narray.push(0);\narray.push(l);\n\narray.sort(function(a, b) {\n return a - b;\n});\n\nfor(let i = 1; i < array.length; i++) {\n if(array[i] - array[i - 1] > maxDistance) {\n maxDistance = array[i] - array[i - 1];\n }\n}\n\nwrite(maxDistance / 2);"}, {"source_code": "var f = readline().split(\" \");\nvar str = readline().split(\" \").sort((x,y)=>x-y);\nvar res = Math.min.apply(this, str);\n\tfor (var i=0; i<+f[0]; i++){\n\t\t\tif (Number(str[i+1])-Number(str[i])>res)\n\t\t\t\tres = +str[i+1]-Number(str[i]);\n\t\t\t\n\t\n\t}\n\tprint(Math.min.apply(this, str)!=0? Math.min.apply(this, str): res/2);"}, {"source_code": "var f = readline().split(\" \");\nvar str = readline().split(\" \").sort((x,y)=>x-y);\nvar res = 0;\n\tfor (var i=0; i<+f[0]; i++){\n\t\t\tif (Number(str[i+1])-Number(str[i])>res)\n\t\t\t\tres = +str[i+1]-Number(str[i]);\n\t\t\t\n\t\n\t}\n\tprint(res/2>=Math.min.apply(this, str)? res/2:Math.min.apply(this, str));"}, {"source_code": "var main = function(nPositions, l)\n{\n\tvar max = 0;\n\tvar increase = function(a, b)\n\t{\n\t\treturn +a - +b;\n\t}\n\tvar toAnArray = function(str)\n\t{\n\t\tstr = str.split(' ');\n\t\treturn str;\n\t}\n\tnPositions = toAnArray(nPositions);\n\tnPositions.sort(increase);\n\tfor (var i = 1; i <= nPositions.length - 1; i++)\n\t{\n\t\tif (+nPositions[i] - +nPositions[i - 1] > max) max = +nPositions[i] - +nPositions[i - 1];\n\t}\n\tif (+nPositions[0] > max / 2) return (+nPositions[0]).toFixed(10);\n\telse if (l - +nPositions[nPositions.length - 1] > max / 2) return (l - +nPositioins[nPositions.length - 1]).toFixed(10);\n\telse return (max / 2).toFixed(10);\n\t\n}\n\n{\n\tvar lAndN = readline(),\n\tnPositions = readline();\n\tlAndN = lAndN.split(' ');\n\tprint(main(nPositions, +lAndN[1]));\n}"}, {"source_code": "var main = function(nPositions, l)\n{\n\tvar max = 0;\n\tvar increase = function(a, b)\n\t{\n\t\treturn +a - +b;\n\t}\n\tvar toAnArray = function(str)\n\t{\n\t\tstr = str.split(' ');\n\t\treturn str;\n\t}\n\tnPositions = toAnArray(nPositions);\n\tnPositions.sort(increase);\n\tfor (var i = 1; i <= nPositions.length - 1; i++)\n\t{\n\t\tif (+nPositions[i] - +nPositions[i - 1] > max) max = +nPositions[i] - +nPositions[i - 1];\n\t}\n\tif (((+nPositions[0] > max / 2) && (l - +nPositions[nPositions.length - 1] > max / 2)) && (+nPositions[0] > l - +nPositions[nPositions.length - 1] ) )return +nPositions[0];\n\t\telse if (((+nPositions[0] > max / 2) && (l - +nPositions[nPositions.length - 1] > max / 2)) && (+nPositions[0] < l - +nPositions[nPositions.length - 1] ) )return l - +nPositions[nPositions.length - 1];\n\t\telse if (+nPositions[0] > max / 2) return +nPositions[0];\n\t\telse if (l - +nPositions[nPositions.length - 1] > max / 2) return l - +nPositions[nPositions.length - 1] > max / 2;\n\t\telse return max / 2;\n\t\n}\n\n{\n\tvar lAndN = readline(),\n\tnPositions = readline();\n\tlAndN = lAndN.split(' ');\n\tprint(main(nPositions, +lAndN[1]));\n}"}, {"source_code": "var inp = readline().split(' ');\nvar a = readline().split(' ');\n\nfor(var i=0; i a-b);\n\nvar max_d = -Infinity;\n\nfor(var i=0; i max_d) max_d = (a[i] - a[i-1])/2;\n}\n\nprint(max_d);"}, {"source_code": "(function main() {\n var line = readline().split(\" \"),\n l = line[0],\n n = line[1],\n aStrings = readline().split(\" \"),\n a = [],\n d,\n i;\n\n\n for (i in aStrings) {\n a[i] = +aStrings[i];\n }\n\n a.sort(function(a, b) {\n return a - b;\n });\n\n d = Math.max(a[0], l - a[a.length - 1]);\n\n for (i = 1; i < a.length; i++) {\n d = Math.max(d, (a[i] - a[i-1]) / 2);\n }\n\n print(d.toFixed(10));\n})();\n"}, {"source_code": "'use strict';\n\n// const rlLib = require('readline');\n\n// const rl = rlLib.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// let inputs = [];\n// let allCount = 2;\n// let currentLine = 0;\n\n// rl.on('line', (input) => {\n// \tinputs.push(input);\n// \tif (inputs.length === allCount) {\n// \t\tmain();\n\n// \t\trl.close();\t\t\n// \t}\n// });\n\n// function readline() {\n// \treturn inputs[currentLine++];\n// }\n// function print() {\n// \tconsole.log.apply(this, arguments);\n// }\n\n\n// function main() {\n\tlet rl = readline().split(' ').map(function(e) {return parseInt(e);});\n\tlet f = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n\n\tf = f.sort(function(a, b) {return a - b;});\n\n\tif (f[f.length - 1] !== rl[1]) {\n\t\tf.push(rl[1] * 2);\n\t}\n\n\tlet res = f[0] * 2;\n\n\tf.forEach(function(e, i) {\n\t\tif (i+1 < f.length && (f[i+1] - f[i]) > res) {\n\t\t\tres = f[i+1] - f[i];\n\t\t}\n\t});\n\n\tprint(res / 2);\n// }\n\n"}, {"source_code": "// var _i = 0;\n//\n// function readline() {\n// _i ++;\n//\n// switch (_i) {\n// case 1: return '2 1000000000';\n// case 2: return '0 1000000000';\n// }\n// }\n//\n// function write(value) {\n// console.log(value);\n// }\n\nfunction f(d) {\n if (d < a[0] || a[a.length-1] + d < l) {\n return false;\n }\n\n for (var i = 1; i < a.length; i ++) {\n if (a[i-1] + d < a[i] - d) {\n return false;\n }\n }\n\n return true;\n}\n\nvar list = readline().split(' ');\n\nvar n = parseInt(list[0]);\nvar l = parseInt(list[1]);\n\nvar a = readline().split(' ').map(function(currentValue) {\n return parseInt(currentValue);\n});\n\na.sort(function(x, y) {\n return x - y;\n});\n\nvar x = 0;\nvar y = l;\nvar m;\n\nvar EPS = 10e-6;\n\nwhile (Math.abs(x - y) > EPS) {\n m = (x + y) / 2;\n if (f(m)) {\n y = m;\n } else {\n x = m;\n }\n}\n\nwrite(m);\n"}, {"source_code": "var tokens = readline().split(\" \");\nvar n = +tokens[0];\nvar l = +tokens[1];\nvar array = readline().split(\" \").map(Number).sort(function(x,y){return x-y});\nvar max = -1;\nfor(var i = 1; i < n; i++){\n var value = array[1] - array[0];\n max = max > value ? max : value;\n}\nvar res = Math.max(max/2,array[0] - 0, l - array[n-1] );\nwrite(res);"}, {"source_code": "class Utility {\n static stringToInts(str) {\n let digits = [];\n for (let i = 0; i < str.length; i++)\n digits.push(parseInt(str.charAt(i)));\n return digits;\n }\n static parseToInts(str, separator) {\n let digits = [];\n Utility.forEach(str.split(separator), s => { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n console.log(input);\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A.sort((a, b) => a >= b);\n\n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n"}, {"source_code": "class Utility {\n static stringToInts(str) {\n let digits = [];\n for (let i = 0; i < str.length; i++)\n digits.push(parseInt(str.charAt(i)));\n return digits;\n }\n static parseToInts(str, separator) {\n let digits = [];\n Utility.forEach(str.split(separator), s => { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A = A.sort((a, b) => a - b);\n console.log(n);\n console.log(l);\n console.log(A);\n\n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n"}, {"source_code": "class Utility {\n static stringToInts(str) {\n let digits = [];\n for (let i = 0; i < str.length; i++)\n digits.push(parseInt(str.charAt(i)));\n return digits;\n }\n static parseToInts(str, separator) {\n let digits = [];\n Utility.forEach(str.split(separator), s => { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A.sort((a, b) => a >= b);\n\n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n"}, {"source_code": "class Utility {\n static stringToInts(str) {\n let digits = [];\n for (let i = 0; i < str.length; i++)\n digits.push(parseInt(str.charAt(i)));\n return digits;\n }\n static parseToInts(str, separator) {\n let digits = [];\n Utility.forEach(str.split(separator), s => { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A.sort((a, b) => a >= b);\n console.log(n);\n console.log(l);\n console.log(A);\n\n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n"}, {"source_code": "class Utility {\n static stringToInts(str) {\n let digits = [];\n for (let i = 0; i < str.length; i++)\n digits.push(parseInt(str.charAt(i)));\n return digits;\n }\n static parseToInts(str, separator) {\n let digits = [];\n Utility.forEach(str.split(separator), s => { digits.push(parseInt(s)); });\n return digits;\n }\n static forEach(arr, fnc) {\n for (let i = 0; i < arr.length; i++)\n fnc(arr[i]);\n }\n static max(p1, p2) {\n return p1 > p2 ? p1 : p2;\n }\n static reverse(arr) {\n let rarr = [];\n for (let i = arr.length - 1; i >= 0; i--)\n rarr.push(arr[i]);\n return rarr;\n }\n static range(n) {\n let range = [];\n for (let i = 1; i <= n; i++) \n range.push(i);\n return range;\n }\n static equals(arr1, arr2) {\n return JSON.stringify(arr1) == JSON.stringify(arr2);\n }\n static processStdin(afterCallback) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n \n let inputString = '';\n \n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n \n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n afterCallback(inputString); \n });\n }\n }\n\nfunction solve(input) {\n let d = Utility.parseToInts(input[0], ' ');\n let n = d[0], l = d[1];\n let A = Utility.parseToInts(input[1], ' ');\n A = A.sort((a, b) => a >= b);\n console.log(n);\n console.log(l);\n console.log(A);\n\n let maxDist = 0;\n if (n > 0) {\n if (A[0] != 0) maxDist = A[0];\n if (A[A.length - 1] != l) {\n let md = l - A[A.length - 1];\n if (md > maxDist) maxDist = md;\n }\n \n for (let i = 1; i < A.length; i++) {\n let md = (A[i] - A[i - 1]) / 2;\n if (md > maxDist) maxDist = md;\n }\n }\n console.log(maxDist.toFixed(10));\n}\n\nUtility.processStdin(solve);\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const [n, l] = input[0].split(' ').map(Number);\n const arr = input[1].split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let dist = arr[0] - 0;\n if ((l - arr[arr.length - 1]) > dist) dist = l - arr[arr.length - 1];\n console.log(dist);\n for (let i = 1; i < arr.length; i++) {\n if (((arr[i] - arr[i - 1]) / 2) > dist) dist = (arr[i] - arr[i - 1]) / 2;\n }\n console.log(dist);\n});"}, {"source_code": "let solution = function (n, l, arr) {\n arr.sort((x, y) => (x - y))\n // let check = function(i) {\n // let smallest = 0\n // for(let x of arr) {\n // let left = x - i\n // let right = x + i\n // if(left > smallest+1) return false\n // smallest = right\n // }\n // return right >= l\n // }\n\n // let left = 1\n // let right = l\n // while(left > right) {\n // let mid = Math.floor((left + right)/2)\n // if(check(mid)) {\n // right = mid-1\n // } else {\n // left = mid+1\n // }\n // }\n // while(check(left)) {\n // left--\n // }\n // return left+1\n let max = 0\n let first = arr[0]\n let last = l - arr[arr.length-1]\n for(let i = 1; i {\n lineCount++\n if(lineCount === 1) {\n [n, l] = line.split(' ').map(x => parseInt(x))\n }\n if(lineCount === 2) {\n arr = line.split(' ').map(x => parseInt(x))\n // console.log(n, l, arr)\n result = solution(n, l, arr)\n // console.log(result)\n }\n})"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i += 2) {\n let info = txt[i].split(\" \");\n doit(info[1] * 1, txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1).sort((a, b) => a - b));\n}\n\nfunction doit(n, tab) {\n let changes = tab[0];\n let g = (n - tab[tab.length - 1]);\n if (g > changes) chenges = g;\n for (let i = 1; i < tab.length; i++) {\n let r = (tab[i] - tab[i - 1]) / 2;\n if (changes < r) changes = r;\n }\n console.log(changes);\n\n\n}"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i+=2) {\n let info=txt[i].split(\" \");\n doit(info[1] * 1, txt[i+1].split(\" \").filter(data=>data.length>0).map(data=>data*1).sort((a,b)=>a-b));\n}\n\nfunction doit(n, tab) {\n let changes=tab[0];\n if((n-tab[tab.length-1])/2>changes)chenges=(n-tab[tab.length-1]);\n for (let i = 1; i < tab.length; i++) {\n if(changes<(tab[i]-tab[i-1])/2)changes=(tab[i]-tab[i-1])/2;\n }\n console.log(changes);\n \n \n}"}], "src_uid": "d79166497eb61d81fdfa4ef80ec1c8e8"} {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n let curLine = 0\n const T = parseInt(lines[curLine++])\n for (let t = 0; t < T; t++) {\n const [n, c0, c1, h] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const p0 = Math.min(c0, h + c1)\n const p1 = Math.min(c1, h + c0)\n let ans = 0\n lines[curLine++].trim().split('').forEach((c) => ans += c === '1' ? p1 : p0)\n console.log(ans)\n } \n})\n", "positive_code": [{"source_code": "var sizeOfData = readline();\nfor (var dataI = 0; dataI < sizeOfData; dataI++) {\n var secondLine = readline().split(' ');\n var n = secondLine[0], c0 = secondLine[1], c1 = secondLine[2], h = secondLine[3];\n var str = readline();\n var am0 = 0;\n var am1 = 0;\n for (var c of str) {\n if (c == '0') {\n am0++;\n } else if (c == '1') {\n am1++;\n }\n }\n var normprice = am0*c0 + am1*c1;\n var c0price = am0*h + am1*c1 + am0*c1;\n var c1price = am1*h + am0*c0 + am1*c0;\n print(Math.min(normprice, c0price, c1price));\n}"}, {"source_code": "var tc = parseInt(readline());\n\nwhile(tc--){\n var arr = readline().split(' ').map(x => parseInt(x));\n var n = arr[0];\n var c0 = arr[1];\n var c1 = arr[2];\n var h = arr[3];\n\n var s = readline();\n\n var one = 0;\n var zero = 0;\n for(var i = 0; i < n; i++){\n if(s[i]=='1')one++;\n else zero++;\n }\n \n var taka = 0;\n if(c0 < c1){\n taka = c0 * zero;\n if((h+c0)<=c1){\n taka += one * (h+c0);\n }else{\n taka += c1 * one;\n }\n }\n else if(c1 < c0){\n taka = c1 * one;\n if((h+c1)<=c0){\n taka += zero * (h+c1);\n }else{\n taka += c0 * zero;\n }\n }else{\n print(n*c0);\n continue;\n }\n\n print(taka);\n}"}, {"source_code": "var sizeOfData = readline();\nfor (var dataI = 0; dataI < sizeOfData; dataI++) {\n var secondLine = readline().split(' ');\n var n = secondLine[0], c0 = secondLine[1], c1 = secondLine[2], h = secondLine[3];\n var str = readline();\n var am0 = 0;\n var am1 = 0;\n for (var c of str) {\n if (c == '0') {\n am0++;\n } else if (c == '1') {\n am1++;\n }\n }\n var normprice = am0*c0 + am1*c1;\n var c0price = am0*h + am1*c1 + am0*c1;\n var c1price = am1*h + am0*c0 + am1*c0;\n print(Math.min(normprice, c0price, c1price));\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [n, c0, c1, h] = readLine().split(\" \").map(Number);\n const str = readLine();\n let [min, count0, count1, count] = [Infinity, 0, 0, 0];\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"0\") count0++;\n else count1++;\n }\n\n count = count0 * c0 + count1 * c1;\n min = Math.min(min, count);\n // all 0\n count = n * c0 + count1 * h;\n min = Math.min(count, min);\n // all 1\n count = n * c1 + count0 * h;\n min = Math.min(count, min);\n // 01\n count = 0;\n for (let i = 0; i < n; i++) {\n const char = str[i];\n if (i % 2 === 0) {\n if (char === \"0\") count += c0;\n else count += c0 + h;\n } else {\n if (char === \"1\") count += c1;\n else count += c1 + h;\n }\n }\n min = Math.min(min, count);\n // 10\n count = 0;\n for (let i = 0; i < n; i++) {\n const char = str[i];\n if (i % 2 === 0) {\n if (char === \"1\") count += c1;\n else count += c1 + h;\n } else {\n if (char === \"0\") count += c0;\n else count += c0 + h;\n }\n }\n min = Math.min(min, count);\n\n console.log(min);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar c0 = one[1];\n\t\tvar c1 = one[2];\n\t\tvar h = one[3];\n\t\tvar s = nextCharArray();\n\t\tvar sum = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(s[j] == \"0\"){\n\t\t\t\tsum += Math.min(c0, c1 + h);\n\t\t\t}else{\n\t\t\t\tsum += Math.min(c1, c0 + h);\n\t\t\t}\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "// =========== DEFAULT FORMAT ==============\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet i = 1;\nlet t = 0;\nlet input1 = 0;\n\n// untuk input per test > 1\nreadline.on('line', line => {\n if (i == 1) {\n // number of test case\n t = parseInt(line) \n i++;\n } else {\n if (i % 2 === 0) input1 = line;\n else solve(input1, line)\n \n if (i <= t*2) i++\n else readline.close()\n }\n});\n\n// =========== DEFAULT FORMAT END ==============\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\n\nfunction solve(line1, line2) {\n // your code here\n const [n, c0, c1, h] = line1.split(' ').map(item => parseInt(item));\n const binaryS = line2.split('')\n const a = c1 * n + (countObj(binaryS, '0') * h);\n const b = c0 * n + (countObj(binaryS, '1') * h);\n const c = (c0 * countObj(binaryS, 0) + c1 * countObj(binaryS, 1))\n console.log(Math.min(a, b, c))\n }"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(h){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r\"0\"==t)).length,u=o.filter((t=>\"1\"==t)).length,l=(t,n)=>e*t+r*n,h=l(s,u),a=0;for(;s>0;)s--,u++,a+=n,h=[h,a+l(s,u)].min();for(s=o.filter((t=>\"0\"==t)).length,u=o.filter((t=>\"1\"==t)).length,a=0;u>0;)u--,s++,a+=n,h=[h,a+l(s,u)].min();i.default.puts(h)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, c0, c1, h] = io.nextNumbers()\n// let a = io.nextCharacters()\n// \n// let nr0 = a.filter((x) => x == \"0\").length\n// let nr1 = a.filter((x) => x == \"1\").length\n// \n// let cost = (zero: number, one: number) => {\n// return c0 * zero + c1 * one\n// }\n// \n// let c = cost(nr0, nr1)\n// \n// let ac = 0\n// \n// while (nr0 > 0) {\n// nr0--\n// nr1++\n// ac += h\n// \n// c = [c, ac + cost(nr0, nr1)].min()\n// }\n// \n// nr0 = a.filter((x) => x == \"0\").length\n// nr1 = a.filter((x) => x == \"1\").length\n// \n// ac = 0\n// \n// while (nr1 > 0) {\n// nr1--\n// nr0++\n// ac += h\n// \n// c = [c, ac + cost(nr0, nr1)].min()\n// }\n// \n// io.puts(c)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "var tc = parseInt(readline());\n\nwhile(tc--){\n var arr = readline().split(' ').map(x => parseInt(x));\n var n = arr[0];\n var c0 = arr[1];\n var c1 = arr[2];\n var h = arr[3];\n\n var s = readline();\n\n var one = 0;\n var zero = 0;\n for(var i = 0; i < n; i++){\n if(s[i]=='1')one++;\n else zero++;\n }\n \n var taka = 0;\n var change = 0;\n if(c0 < c1){\n taka = c0 * zero;\n if(h < c1){\n change += h*one;\n change += c0 * one;\n if(change < c1 * one)taka += change;\n \n }else{\n taka += c1 * one;\n }\n }\n else if(c1 < c0){\n taka = c1 * one;\n if(h < c0){\n change += h*zero;\n change += c1*zero;\n if(change < c0 * zero)taka += change;\n }else{\n taka += c0 * zero;\n }\n }else{\n print(n*c0);\n continue;\n }\n\n print(taka);\n}"}, {"source_code": "var tc = parseInt(readline());\n\nwhile(tc--){\n var arr = readline().split(' ').map(x => parseInt(x));\n var n = arr[0];\n var c0 = arr[1];\n var c1 = arr[2];\n var h = arr[3];\n\n var s = readline();\n\n var one = 0;\n var zero = 0;\n for(var i = 0; i < n; i++){\n if(s[i]=='1')one++;\n else zero++;\n }\n \n var taka = 0;\n if(c0 < c1){\n taka = c0 * zero;\n if(h*one < c1*one){\n taka += h*one;\n taka += c0*one;\n }else{\n taka += c1*one;\n }\n }\n else if(c1 < c0){\n taka = c1 * one;\n if(h*zero < c0*zero){\n taka += h*zero;\n taka += c1*zero;\n }else{\n taka += c0*zero;\n }\n }else{\n print(n*c0);\n continue;\n }\n\n print(taka);\n}"}], "src_uid": "7cc0a6df601e3dcf4e1d9578dd599a36"} {"source_code": "\nvar n=+readline();\nvar t=readline().split(' ').map(function(v){return+v;});\nvar ans=-1e9;\nfor(var i=3;i<=n;i++){\n\tif(n%i===0){\n\t\tvar k=n/i;\n\t\tfor(var j=0;j= 3 )\n\t\tif (! (n%k))\n\t\t\tfor (var i = 0; i < k; i++) {\n\t\t\t\tvar ns = 0;\n\t\t\t\tfor (var j = i; j < n; j += k) ns += t[j];\n\t\t\t\tif (ns > s) s = ns;\n\t\t\t}\n\n\tprint(s);\n\n}).call(this);"}], "negative_code": [{"source_code": "\nvar n=+readline();\nvar t=readline().split(' ').map(function(v){return+v;});\nvar ans=-1e3;\nfor(var i=3;i<=n;i++){\n\tif(n%i===0){\n\t\tvar k=n/i;\n\t\tfor(var j=0;j 5) {\n\t\tvar k = 0;\n\t\tvar q = n / (k + 1);\n\t\twhile ( q > 3 ) {\n\t\t\tif (!(q % 1)) {\n\t\t\t\tfor (var i = 0; i < q/2; i++) {\n\t\t\t\t\tvar ns = t.frequency(i, k).sum();\n\t\t\t\t\tif (ns > s) s = ns;\n\t\t\t\t}\n\t\t\t}\n\t\t\tq = n / (++k + 1)\n\t\t}\n\t}\n\n\tprint(s);\n\n}).call(this);"}, {"source_code": "Array.prototype.sum = function () {\n\tvar total = 0, i = this.length;\n\twhile (i--) total += this[i];\n\treturn total;\n}\n\nArray.prototype.frequency = function (skip, startIndex) {\n\tvar l = this.length, ret = [];\n\tfor (var i = startIndex; i < l; i += skip + 1) ret.push(this[i]);\n\treturn ret;\n}\n\n;(function () {\n\tvar n = +readline();\n\tvar t = readline().split(' ').map(Number);\n\n\tvar s = t.sum();\n\n\tif (!(n % 2)) {\n\t\tvar k = 0;\n\t\tvar q = n / (k + 1);\n\t\twhile ( q > 3 ) {\n\t\t\tif (!(q % 1)) {\n\t\t\t\tfor (var i = 0; i < q/2; i++) {\n\t\t\t\t\tvar ns = t.frequency(i, k).sum();\n\t\t\t\t\tif (ns > s) s = ns;\n\t\t\t\t}\n\t\t\t}\n\t\t\tq = n / (++k + 1)\n\t\t}\n\t}\n\n\tprint(s);\n\n}).call(this);"}], "src_uid": "0ff4ac859403db4e29554ca7870f5490"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn Math.abs(a.x) - Math.abs(b.x);\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x == b.x) {\n\t\t\treturn Math.abs(a.y) - Math.abs(b.y);\n\t\t}\n\t\treturn a.x - b.x;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t}\n\t\tif (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\treturn Math.abs(a.x) + Math.abs(a.y) - Math.abs(b.x) - Math.abs(b.y);\n\t});\n\tvar moves = [];\n\tfunction move(x0, y0, x1, y1) {\n\t\tif (x0 != x1) {\n\t\t\tmoves.push('1 '+Math.abs(x0-x1)+' '+(x0 < x1 ? 'R' : 'L'));\n\t\t}\n\t\tif (y0 != y1) {\n\t\t\tmoves.push('1 '+Math.abs(y0-y1)+' '+(y0 < y1 ? 'U' : 'D'));\n\t\t}\n\t}\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar x = bombs[i].x, y = bombs[i].y;\n\t\tmove(0, 0, x, y);\n\t\tmoves.push('2');\n\t\tmove(x, y, 0, 0);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x == b.x) {\n\t\t\treturn Math.abs(a.y) - Math.abs(b.y);\n\t\t}\n\t\treturn a.x - b.x;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t}\n\t\tif (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y != 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x != b.x) {\n\t\t\treturn a.x - b.x;\n\t\t}\n\t\treturn b.y - a.y;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t} else if (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x != b.x) {\n\t\t\treturn a.x - b.x;\n\t\t}\n\t\treturn a.y - b.y;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t} else if (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tpoints = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tpoints.push({ x: x, y: y });\n\t}\n\tpoints.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn a;\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\t\tif (a.x != b.x) {\n\t\t\treturn a.x - b.x;\n\t\t}\n\t\treturn a.y - b.y;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar point = points[i], x = point.x, y = point.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t} else if (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x == b.x) {\n\t\t\treturn Math.abs(a.y) - Math.abs(b.y);\n\t\t}\n\t\treturn a.x - b.x;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t}\n\t\tif (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.y != b.y) {\n\t\t\treturn a.y - b.y;\n\t\t}\n\t\treturn a.x - b.x;\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t} else if (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\tif (a.y == 0 || b.y == 0) {\n\t\t\tif (a.y == 0 && b.y == 0) {\n\t\t\t\treturn a.x - b.x;\n\t\t\t}\n\t\t\tif (a.y == 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t\tif (a.x != b.x) {\n\t\t\treturn a.x - b.x;\n\t\t}\n\t\treturn Math.abs(a.y) - Math.abs(b.y);\n\t});\n\tvar moves = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar bomb = bombs[i], x = bomb.x, y = bomb.y;\n\t\tif (x == 0) {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t\tmoves.push('3');\n\t\t\tcontinue;\n\t\t} else if (x < 0) {\n\t\t\tvar left = 'L', right = 'R';\n\t\t} else {\n\t\t\tvar left = 'R', right = 'L';\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+left);\n\t\tif (y == 0) {\n\t\t\tmoves.push('2');\n\t\t} else {\n\t\t\tif (y > 0) {\n\t\t\t\tvar up = 'U', down = 'D';\n\t\t\t} else {\n\t\t\t\tvar up = 'D', down = 'U';\n\t\t\t}\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+up);\n\t\t\tmoves.push('2');\n\t\t\tmoves.push('1 '+Math.abs(y)+' '+down);\n\t\t}\n\t\tmoves.push('1 '+Math.abs(x)+' '+right);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numBombs = parseInt(readline()),\n\t\tbombs = [];\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\tx = data[0], y = data[1];\n\t\tbombs.push({ x: x, y: y });\n\t}\n\tbombs.sort(function (a, b) {\n\t\treturn Math.abs(a.x) + Math.abs(a.y) - Math.abs(b.x) - Math.abs(b.y);\n\t});\n\tvar moves = [];\n\tfunction move(x0, y0, x1, y1) {\n\t\tif (x0 != x1) {\n\t\t\tmoves.push('1 '+Math.abs(x0-x1)+' '+(x0 < x1 ? 'L' : 'R'));\n\t\t}\n\t\tif (y0 != y1) {\n\t\t\tmoves.push('1 '+Math.abs(y0-y1)+' '+(y0 < y1 ? 'D' : 'U'));\n\t\t}\n\t}\n\tfor (var i = 0; i < numBombs; ++i) {\n\t\tvar x = bombs[i].x, y = bombs[i].y;\n\t\tmove(0, 0, x, y);\n\t\tmoves.push('2');\n\t\tmove(x, y, 0, 0);\n\t\tmoves.push('3');\n\t}\n\tprint(moves.length);\n\tprint(moves.join('\\n'));\n}\n\nmain();\n"}], "src_uid": "a7c1b9845ab0569e0175853db9ed5c32"} {"source_code": ";(function () { // 362B\n\n\tprint(function (n, m) {\n\t\tif (m === 0) return 'YES';\n\t\tvar d = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }), dl = d.length;\n\t\tif (d[0] === 1 || d[dl - 1] === n) return 'NO';\n\t\tfor (var i = 2, k = 0; i < dl; i++)\n\t\t\tif ( d[i] === d[i-1] + 1 && d[i] === d[i-2] + 2 ) return 'NO';\n\t\treturn 'YES';\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}).call(this);", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function p(){return s[i++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function d(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "print(function(n, m) {\n\tif (m === 0) return 'YES';\n\n\tvar d = readline().split(' ').map(Number).sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tif (d[m - 1] === n || d[0] === 1) return 'NO';\n\n\tfor (var i = 2; i < m; i++)\n\t\tif (d[i] - d[i - 2] === 2) return 'NO';\n\n\treturn 'YES';\n\n} .apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(n, m) {\n\tif (m === 0) return 'YES';\n\n\tvar d = readline().split(' ').map(Number).sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tif (d[m - 1] === n) return 'NO';\n\n\tfor (var i = 2; i < m; i++)\n\t\tif (d[i] - d[i - 2] === 2) return 'NO';\n\n\treturn 'YES';\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, m) {\n\tif (m === 0) return 'NO';\n\n\tvar d = readline().split(' ').map(Number).sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\n\tif (d[m - 1] === n) return 'NO';\n\n\tfor (var i = 2; i < m; i++)\n\t\tif (d[i] - d[i - 2] === 2) return 'NO';\n\n\treturn 'YES';\n\n} .apply(0, readline().split(' ').map(Number)));\n\n"}, {"source_code": ";(function () { // 362B\n\n\tprint(function (n, m) {\n\t\tvar d = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }), dl = d.length;\n\t\tif (d[0] === 1 && d[dl - 1] === n) return 'NO';\n\t\tfor (var i = 2, k = 0; i < dl; i++)\n\t\t\tif ( d[i] === d[i-1] + 1 && d[i] === d[i-2] + 2 ) return 'NO';\n\t\treturn 'YES';\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}).call(this);"}], "src_uid": "422cbf106fac3216d58bdc8411c0bf9f"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r0;--n)r+=Math.abs(e[n-1]-e[n]);o.default.put(r)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar x = readline().split(' ');\nvar a = []\nfor(var i = 0;i < n; i++) {\n a[i] = parseInt(x[i]);\n}\nvar ans = Math.abs(a[0]);\nfor(var i=1;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction toIntArr(arr) {\n const r = arr.map((item) => {\n return parseInt(item);\n });\n \n return r;\n}\n\n////////////////////////////////\n\nfunction main() {\n let n = parseInt(readline());\n let arr = toIntArr(readline().split(' '));\n\n let r = 0;\n let p = 0;\n\n for (let i = 0; i < n; i++) {\n r += Math.abs(arr[i] - p);\n p = arr[i];\n }\n\n console.log(r);\n}"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn(), b = rda();\n\nvar ans = 0;\nvar now = 0;\nfor(var i = 0; i < n; i++){\n if(now < b[i]){\n ans += b[i] - now;\n now = b[i];\n }else if(now > b[i]){\n ans += now - b[i];\n now = b[i];\n }else{\n continue;\n }\n}\n\nwrite(ans);"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \").map(Number);\nvar ans = 0;\nvar x = 0;\n\nfor (var i = 0; i < n; i++) {\n\tif (x != a[i]) {\n\t\tans += Math.abs(a[i]-x);\n\t\tx = a[i];\n\t}\n}\n\nprint(ans);"}, {"source_code": "n = +readline();\na = readline().split(\" \").map(Number);\nvar res = 0 , add = 0;\nfor (i = 0 ; i < n ; i ++){\n a[i] -= add;\n add += a[i];\n res += Math.abs(a[i]);\n\n}\n\nwrite(res);"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar x = readline().split(' ');\nvar a = []\nfor(var i = 0;i < n; i++) {\n a[i] = parseInt(x[i]);\n}\nvar ans = a[0];\nfor(var i=1;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction toIntArr(arr) {\n const r = arr.map((item) => {\n return parseInt(item);\n });\n \n return r;\n}\n\n////////////////////////////////\n\nfunction main() {\n let n = parseInt(readline());\n let arr = toIntArr(readline().split(' '));\n\n let r = 0;\n let k = 0;\n\n for (let i = 1; i < n; i++) {\n r += Math.abs(arr[i] - k);\n k = arr[i];\n }\n\n console.log(r);\n}"}], "src_uid": "97a226f47973fcb39c40e16f66654b5f"} {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\n\ntxt.forEach(data => {\n let info = data.split(\" \");\n payment(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);\n});\n\nfunction payment(a, b, n, s) {\n if (b >= s) {\n console.log(\"YES\");\n return;\n } else {\n let r = Math.floor(s / n);\n if(r>a){\n if (a * n + b < s) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n }else{\n if (r * n == s) {\n console.log(\"YES\");\n } else {\n if (r * n + b < s) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n }\n }\n }\n}", "positive_code": [{"source_code": " var lines = parseInt(readline(), 10);\n\n function min(a, b) {\n return a < b ? a : b;\n }\n\n for (var i = 0; i < lines; i++) {\n var tmpArr = readline()\n .split(\" \")\n .map(function(val) {\n return parseInt(val, 10);\n });\n var a = tmpArr[0];\n var b = tmpArr[1];\n var n = tmpArr[2];\n var S = tmpArr[3];\n\n var maxA = Math.floor(S / n);\n var tail = S - min(maxA, a) * n;\n print(tail > b ? \"NO\": \"YES\");\n }"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet q = nl.num();\n let ans = [];\n for(let i = 0; i < q; i++){\n let [a, b, n, s] = nl.nums();\n let an = Math.trunc(s/n);\n let x = ((an < a)?an:a)*n;\n ans.push((x + b) >= s?\"YES\":\"NO\");\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "//A. Payment Without Change\nvar attempts = Number(readline());\nvar PaymentWithoutChange = () => {\n do {\n attempts--;\n var numbers = readline().split(' ').map(x => Number(x));\n var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];\n if ((a * n) + b >= s) {\n var a_needed = Math.floor(s / n);\n // var b_rem = s % n;\n if (a_needed > a && b >= s - a * n || a_needed < a && b >= s - a_needed * n || a_needed == a)\n print('YES');\n else\n print('NO');\n }\n else\n print('NO');\n\n } while (attempts > 0);\n}\nPaymentWithoutChange();"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n var testCases = [];\n for (var i = 0; i < testCasesNum; i++) {\n (function (i) {\n testCases[i] = readline();\n canPay(testCases[i]);\n })(i)\n }\n}\n\nfunction canPay(testCase) {\n var caseArr = testCase.split(' ').map(Number);\n print(Math.min(caseArr[0] * caseArr[2], Math.floor(caseArr[3] / caseArr[2]) * caseArr[2]) + caseArr[1] >= caseArr[3] ? 'YES' : 'NO');\n}\nmain();"}, {"source_code": "//DONE:\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n for(let i = 0; i < q; i++) {\n const arrq = arr[i].split(' ')\n const a = arrq[0],\n b = arrq[1],\n n = arrq[2],\n s = arrq[3]\n\n const ax = Math.min(a, Math.floor(s / n))\n if(s - ax * n <= b) console.log('YES')\n else console.log('NO')\n }\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\n\nconst main = () => {\n let q = parseInt(readline());\n let ans = '';\n for (let i = 0; i < q; i++) {\n let [a, b, n, s] = readline().split(' ').map(Number);\n const h = Math.min(Math.floor(s / n), a);\n const bk = s - (n * h);\n if (bk <= b) {\n ans += \"YES\\n\";\n } else {\n ans += \"NO\\n\";\n }\n // console.log(h, bk);\n // console.log(a,b,n,s);\n }\n console.log(ans);\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\n\twhile (t--) {\n\t\tlet [a, b, n, s] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet ta = Math.floor(s / n);\n\t\tlet tn;\n\n\t\tif (ta <= a) {\n\t\t\ttn = ta * n;\n\t\t} else {\n\t\t\ttn = a * n;\n\t\t}\n\n\t\tif (s - tn <= b) {\n\t\t\tconsole.log('YES');\n\t\t} else {\n\t\t\tconsole.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = '';\nlet currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin;}); \nprocess.stdin.on('end', _ => {inputString = inputString.trim().split('\\n').map(string => \n{ return string.trim();}); main();}); function readLine() { return inputString[currentLine++];}\n\n\n//please ignore the lines above this\n\n\n\nfunction main() {\n let noOftestCases = +(readLine());\n \n while(noOftestCases--)\n {\n \n let inp = readLine();\n var testCases = inp.split(\" \");\n let noCoinsN = testCases[0];\n let noCoins1 = testCases[1];\n let ValueN = testCases[2];\n let total = testCases[3];\n \n let biggestValuewithN = Math.floor(total/ValueN);\n \n let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN; \n \n let noOf1coinsreq = total - maxValuePossible;\n \n if(noOf1coinsreq <= noCoins1 )\n {\n console.log(\"YES\");\n }\n else { console.log(\"NO\");\n \n }\n}\n}"}, {"source_code": "'use strict'\n\nconst problem = (a, b, n, S) => (S - (Math.min(S/n|0, a))*n <= b) ? 'YES' : 'NO'\nlet q = +readline();\n\nwhile(q--) {\n const abnS = readline().split(' ').map(Number);\n print(problem(abnS[0], abnS[1], abnS[2], abnS[3]));\n}\n"}, {"source_code": "function myin(){return require(\"fs\").readFileSync(\"/dev/stdin\", \"utf8\").trim();}\nfunction myout(t){print(t);}//standard output\nfunction myerr(t){console.log(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),1);\n var output = [];\n for(var i = 1; i <= N; i++){\n var tmp = myconv(readline(),4);\n var a = tmp[0];\n var b = tmp[1];\n var n = tmp[2];\n var S = tmp[3];\n var other;//b\u306e\u5fc5\u8981\u5206\n if(S >= a * n){\n other = S - a * n;\n }else{\n other = S % n;\n }\n if(other - b <= 0){\n output.push(\"YES\");\n }else{\n output.push(\"NO\");\n }\n }\n myout(output.join(\"\\n\"));\n}\n\nMain();\n"}, {"source_code": "'use strict'\n let n = readline();\nfor( let i=0;i 0) {\n const abnS = readline().split(' ').map(Number);\n print(calculate(abnS));\n input--\n}\nfunction calculate(input){\n let a = input[0];\n let b = input[1];\n let n = input[2];\n let s = input[3];\n let div = Math.trunc(s/n);\n let multi = a < div ? n * a : div * n;\n let diff = s - multi;\n if(diff <= b){\n return \"YES\";\n }else return \"NO\";\n}"}], "negative_code": [{"source_code": "'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = '';\nlet currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin;}); \nprocess.stdin.on('end', _ => {inputString = inputString.trim().split('\\n').map(string => \n{ return string.trim();}); main();}); function readLine() { return inputString[currentLine++];}\n\n\n//please ignore the lines above this\n\n\n\nfunction main() {\n let noOftestCases = +(readLine());\n \n while(noOftestCases--)\n {\n \n let inp = readLine();\n var testCases = inp.split(\" \");\n let noCoinsN = testCases[0];\n let noCoins1 = testCases[1];\n let ValueN = testCases[2];\n let total = testCases[3];\n \n let biggestValuewithN = total/ValueN;\n \n let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN; \n \n let noOf1coinsreq = total - maxValuePossible;\n \n if(noOf1coinsreq > noCoins1 )\n {\n console.log(\"YES\");\n }\n else { console.log(\"NO\");\n \n }\n}\n}"}, {"source_code": "'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = '';\nlet currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin;}); \nprocess.stdin.on('end', _ => {inputString = inputString.trim().split('\\n').map(string => \n{ return string.trim();}); main();}); function readLine() { return inputString[currentLine++];}\n\n\n//please ignore the lines above this\n\n\n\nfunction main() {\n let noOftestCases = +(readLine());\n \n while(noOftestCases--)\n {\n \n let inp = readLine();\n var testCases = inp.split(\" \");\n let noCoinsN = testCases[0];\n let noCoins1 = testCases[1];\n let ValueN = testCases[2];\n let total = testCases[3];\n \n let biggestValuewithN = total/ValueN;\n \n let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN; \n \n let noOf1coinsreq = total - maxValuePossible;\n \n if(noOf1coinsreq < noCoins1 )\n {\n console.log(\"YES\");\n }\n else { console.log(\"NO\");\n \n }\n}\n}"}, {"source_code": "let fs = require(\"fs\")\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n})\ntxt.shift()\n\ntxt.forEach(element => {\n let info = element.split(\" \")\n football(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1)\n});\n\nfunction football(a, b, n, s) {\n if (a * n == s) {\n console.log(\"YES\");\n } else if (a * n < s) {\n if (a * n + b < s) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n } else {\n console.log(\"YES\");\n \n }\n}"}, {"source_code": "let fs = require(\"fs\")\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n})\ntxt.shift()\n\ntxt.forEach(element => {\n let info = element.split(\" \")\n football(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1)\n});\n\nfunction football(a, b, n, s) {\n if (a * n == s) {\n console.log(\"YES\");\n } else if (a * n < s) {\n if (a * n + b < s) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n } else {\n for (let index = a; index >0; index--) {\n if(index*n==s){\n console.log(\"YES\");\n return;\n }else if(index*n=s){\n console.log(\"YES\");\n return;\n }\n }\n console.log(\"NO\");\n }\n}"}, {"source_code": "function payment(a,b,n,s){\n if(b>=s){\n console.log(\"YES\")\n return;\n }else{\n let total=0;\n for(let i=0;is){\n total-=a*n;\n if(total+b{return data.length>0});\ntxt.shift();\n\ntxt.forEach(data=>{\n let info=data.split(\" \");\n payment(info[0]*1,info[1]*1,info[2]*1,info[3]*1);\n});\nfunction payment(a,b,n,s){\n if(b>=s){\n console.log(\"YES\");\n return;\n }else{\n let total=0;\n for(let i=0;is){\n total-=a*n;\n if(total+b data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet q = nl.num();\n let ans = [];\n for(let i = 0; i < q; i++){\n let [a, b, n, s] = nl.nums();\n let an = Math.trunc(s/n);\n let bn = (an < a)?s%n:s-(a*n);\n ans.push((an >= a && bn <= b)?\"YES\":\"NO\");\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet q = nl.num();\n let ans = [];\n for(let i = 0; i < q; i++){\n let [a, b, n, s] = nl.nums();\n let an = Math.trunc(s/n);\n let bn = (an < a)?s%n:s-(a*n);\n ans.push((an <= a && bn <= b)?\"YES\":\"NO\");\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict'\n let n = readline();\nwhile(n>0)\n{\n isok();\n n--\n}\nfunction isok()\n{\n var a = readline().split(' ').map(Number);\n var ans=0;\n ans+=(Math.min(a[0],a[3]/a[2])*a[2]);\n if(a[3]-ans<=a[1])print('YES');\n else print('NO'); \n}"}, {"source_code": "'use strict'\nlet input = readline();\nwhile(input > 0) {\n const abnS = readline().split(' ').map(Number);\n print(calculate(abnS));\n input--\n}\nfunction calculate(input){\n let a = input[0];\n let b = input[1];\n let n = input[2];\n let s = input[3];\n if(a * n <= s && (s - (a * n)) <= b){\n return \"YES\";\n }else return \"NO\";\n}"}, {"source_code": "'use strict'\nlet input = readline();\nwhile(input > 0) {\n const abnS = readline().split(' ').map(Number);\n print(calculate(abnS));\n input--\n}\nfunction calculate(input){\n let a = input[0];\n let b = input[1];\n let n = input[2];\n let s = input[3];\n if((a * n) <= s && (s - (a * n)) <= b){\n return \"YES\";\n }else return \"NO\";\n}"}, {"source_code": "//A. Payment Without Change\nvar attempts = Number(readline());\nvar PaymentWithoutChange = () => {\n do {\n attempts--;\n var numbers = readline().split(' ').map(x => Number(x));\n var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];\n if ((a * n) + b >= s) {\n var a_needed = Math.floor(s / n);\n var b_rem = s % n;\n if (a_needed <= a && b_rem <= b || b>= s-a*n)\n print('YES');\n else\n print('NO');\n }\n else\n print('NO');\n\n } while (attempts > 0);\n}\nPaymentWithoutChange();"}, {"source_code": "//A. Payment Without Change\nvar attempts = Number(readline());\nvar PaymentWithoutChange = () => {\n do {\n attempts--;\n var numbers = readline().split(' ').map(x => Number(x));\n var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];\n if ((a * n) + b >= s) {\n var a_needed = Math.floor(s / n);\n var b_rem = s % n;\n if (a_needed <= a && b_rem <= b || b>=a*n)\n print('YES');\n else\n print('NO');\n }\n else\n print('NO');\n\n } while (attempts > 0);\n}\nPaymentWithoutChange();"}, {"source_code": "//A. Payment Without Change\nvar attempts = Number(readline());\nvar PaymentWithoutChange = () => {\n do {\n attempts--;\n var numbers = readline().split(' ').map(x => Number(x));\n var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];\n if ((a * n) + b >= s) {\n var a_needed = Math.floor(s / n);\n var b_rem = s % n;\n if (a_needed <= a && b_rem <= b)\n print('YES');\n else\n print('NO');\n }\n else\n print('NO');\n\n } while (attempts > 0);\n}\nPaymentWithoutChange();"}], "src_uid": "e2434fd5f9d16d59e646b6e69e37684a"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \nfunction Queue() {\n this.length = 0;\n}\n \nQueue.prototype.push = function (item) {\n var node = {item: item};\n if (this.last) {\n this.last = this.last.next = node;\n } else {\n this.last = this.first = node;\n }\n this.length++;\n};\n\nQueue.prototype.shift = function () {\n var node = this.first;\n if (node) {\n this.first = node.next;\n if (!(--this.length)) {\n this.last = undefined;\n }\n return node.item;\n }\n};\n\nQueue.prototype.slice = function (start, end) {\n start = typeof start === 'undefined' ? 0 : start;\n end = typeof end === 'undefined' ? Infinity : end;\n\n var output = [];\n\n var i = 0;\n for (var node = this.first; node; node = node.next) {\n if (--end < 0) {\n break;\n } else if (++i > start) {\n output.push(node.item);\n }\n }\n return output;\n}\n\nclass Logger {\n\n constructor() {\n this.enabled = false;\n }\n\n enable() {\n this.enabled = true;\n }\n\n disable() {\n this.enabled = false;\n }\n\n log(...str) {\n if (this.enabled) {\n console.error(...str);\n }\n }\n}\n\nlet logger = new Logger();\n// logger.enable();\n \nfunction main() {\n\n let t = +readline();\n\n let a = 0;\n\n let dfs = (array, max) => {\n let res = [];\n\n let stack = [];\n for (let i = array[0][0]; i <= array[0][1]; ++i) {\n stack.push([i]);\n }\n\n while(stack.length > 0) {\n ++a;\n logger.log(\"stack:\", stack)\n let current = stack.pop();\n let arrayIndex = current.length;\n\n // logger.log(current, max, arrayIndex);\n // logger.log(array[arrayIndex]);\n\n if (arrayIndex >= max) {\n res = current;\n break;\n }\n\n for (let i = array[arrayIndex][0]; i <= array[arrayIndex][1]; ++i) {\n if (current.includes(i)) continue;\n let newelem = current.slice(0)\n newelem.push(i);\n // logger.log(\"newelem : \",newelem)\n stack.push(newelem);\n }\n }\n\n return res;\n }\n\n for (let i = 0; i < t; ++i) {\n let n = +readline();\n let array = [];\n\n // Register inputs\n for (let j = 0; j < n; ++j) {\n let [l, r] = readline().split(' ').map((a) => +a);\n array.push([l, r])\n }\n\n logger.log(array);\n array.sort((a,b) => {\n return (a[1]-a[0])-(b[1]-b[0]);\n })\n logger.log(array)\n\n let res = dfs(array, n)\n\n for (let i = 0; i < array.length; ++i) {\n console.log(array[i][0], array[i][1], res[i]);\n }\n console.log()\n\n }\n\n logger.log(a);\n\n}", "positive_code": [{"source_code": "const solve = (arr1)=>{\r\n let arr = [...arr1],obj={},obj1 = {};\r\n arr.sort((a,b)=>Math.abs(a[0]-a[1]) - Math.abs(b[0]-b[1]));\r\n for(let i=0;is+r+\" \",\"\")+obj[arr1[i]];\r\n console.log(res);\r\n }\r\n}\r\n\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur)));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst rng = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\trng.push([...rna(), i]);\r\n\t\t}\r\n\r\n\t\trng.sort(comp);\r\n\t\tfunction comp (x, y) {\r\n\t\t\tif (x[0] == y[0])\r\n\t\t\t\treturn y[1] - x[1];\r\n\t\t\telse\r\n\t\t\t\treturn x[0] - y[0];\r\n\t\t}\r\n\t\trng.push([INF, INF, INF]);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [l, r, indx] = rng[i];\r\n\t\t\tconst [lnxt, rnxt, indxnxt] = rng[i+1];\r\n\t\t\tif (lnxt == l)\r\n\t\t\t\tconsole.log(l, r, rnxt + 1);\r\n\t\t\telse\r\n\t\t\t\tconsole.log(l, r, l);\r\n\t\t}\r\n\t\tconsole.log('');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n if (sc > 0)\r\n console.log('');\r\n const n = parseInt(await getLine());\r\n const segs = new Array(n);\r\n for(let i = 0; i < n; i++) {\r\n const [l, r] = (await getLine()).split(' ').map(num => parseInt(num));\r\n segs[i] = {\r\n l, r\r\n }\r\n }\r\n segs.sort((a,b) => (a.r-a.l) - (b.r-b.l));\r\n for(let i = 0; i < segs.length; i++) {\r\n const cur = segs[i];\r\n let a = undefined, b = undefined;\r\n if (cur.l === cur.r) {\r\n console.log(`${cur.l} ${cur.r} ${cur.l}`);\r\n } else {\r\n for(let j = 0; j < i; j++) {\r\n if (!segs[j].used && segs[j].l >= cur.l && segs[j].r <= cur.r) {\r\n if (!a) a = segs[j];\r\n else {\r\n b = segs[j];\r\n break;\r\n }\r\n }\r\n }\r\n a.used = true;\r\n if (b)\r\n b.used = true;\r\n if (!b) {\r\n if (a.l > cur.l) {\r\n console.log(`${cur.l} ${cur.r} ${cur.l}`);\r\n } else {\r\n console.log(`${cur.l} ${cur.r} ${cur.r}`);\r\n }\r\n } else {\r\n if (a.l < b.l) {\r\n console.log(`${cur.l} ${cur.r} ${a.r + 1}`);\r\n } else {\r\n console.log(`${cur.l} ${cur.r} ${b.r + 1}`);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "negative_code": [], "src_uid": "eca433877ef3fbda198c5f2c95a359e7"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr.shift())\n\n for(let i = 0; i < n; i++) {\n const [c, s] = arr[i].split(' ').map(a => parseInt(a))\n let cost = 0\n if(s > c) {\n let mod = s % c\n let div = Math.floor(s / c)\n cost += (div ** 2) * (c - mod)\n cost += ((div + 1) ** 2 ) * mod\n }\n else {\n cost += s\n }\n wr(cost)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [c, s] = line.split(' ');\n const k = s / c << 0;\n const m = s - k * c;\n console.log(((k + 1) ** 2) * m + (k **2) * (c - m));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const solution = new Array(radiators);\n solution.fill(0);\n let sections = 0;\n while(sections < minSections) {\n for (let i = 0; i < radiators && sections < minSections; i++) {\n solution[i] += 1;\n sections += 1;\n }\n }\n console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [r, s] = line.split(' ').map(Number);\n // Math.floor replaced with << operator\n console.log(((s / r) << 0) * ((s / r) << 0) * (r - (s - ((s / r) << 0) * r)) + (((s / r) << 0) + 1) * (((s / r) << 0) + 1) * (s - ((s / r) << 0) * r));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const v = Math.floor(minSections / radiators);\n const vPlus1Number = minSections - v * radiators;\n const vNumber = radiators - vPlus1Number;\n const result = v * v * vNumber + (v + 1) * (v + 1) * vPlus1Number;\n console.log(result);\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [c, s] = line.split(' ').map(Number);\n const k = s / c << 0;\n const m = s - k * c;\n console.log(((k + 1) ** 2) * m + (k **2) * (c - m));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const v = (minSections / radiators) << 0; // Math.floor\n const result = v * v * (radiators - (minSections - v * radiators)) + (v + 1) * (v + 1) * (minSections - v * radiators);\n console.log(result);\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [r, m] = line.split(' ').map(Number);\n console.log(Math.floor(m / r) * Math.floor(m / r) * (r - (m - Math.floor(m / r) * r)) + (Math.floor(m / r) + 1) * (Math.floor(m / r) + 1) * (m - Math.floor(m / r) * r));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const solution = new Array(radiators);\n const startValue = Math.floor(minSections / radiators);\n solution.fill(startValue);\n let sections = startValue * radiators;\n for (let i = 0; i < radiators && sections < minSections; i++) {\n solution[i] += 1;\n sections += 1;\n }\n console.log(solution.map(v => v * v).reduce((sum, v) => sum + v, 0));\n });\n});"}, {"source_code": "'use strict'\n let n = readline();\nfor( let i=0;i=Number(l));\n var id=a[1]/a[0];\n var les=(a[1]%a[0]);\n ok = a[0]-les;\n ans = id*id*ok;\n id++;\n ans+= (id*id*les); \n return ans;\n \n\n}"}, {"source_code": "'use strict'\n let n = readline();\nfor( let i=0;i {\n input.split('\\r\\n').filter((_, i) => i >= 1)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const solution = new Array(radiators);\n solution.fill(0);\n let sections = 0;\n while(sections < minSections) {\n for (let i = 0; i < radiators && sections < minSections; i++) {\n solution[i] += 1;\n sections += 1;\n }\n }\n console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [radiators, minSections] = line.split(' ').map(Number);\n const solution = new Array(radiators);\n solution.fill(minSections >= radiators ? Math.floor(radiators / minSections) : 0);\n let sections = 0;\n while(sections < minSections) {\n for (let i = 0; i < radiators && sections < minSections; i++) {\n solution[i] += 1;\n sections += 1;\n }\n }\n console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));\n });\n});"}], "src_uid": "0ec973bf4ad209de9731818c75469541"} {"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\nInput\n5 2 4 13\nhhhwh\nOutput\n3\nAnswer\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar needRotate;\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret;\n\tvar i;\n\tvar viewCount = 0;\n\tvar timeSpent = 0;\n\tvar rev = n - 1, last;\n\tvar t = 0;\n\t\n\tfor (i = 0; i < n && timeSpent + t <= totalTime; i++) {\n\t\ttimeSpent += t;\n\t\tt = 1;\n\t\tif (i > 0) {\n\t\t\tt += swipeTime;\n\t\t}\n\t\t\t\t\n\t\tif (needRotate[i]) {\n\t\t\tt += rotateTime;\n\t\t}\n\t\t\n\t\tif (timeSpent + t <= totalTime) {\n\t\t\tlast = i;\n\t\t\tviewCount++;\n\t\t}\n\t}\n\t\n\tret = viewCount;\n\tif (ret > 0 && ret < n) {\n\t\tfor (var terminal = last + 1; terminal > 0; terminal--) {\n\t\t\t// decrement\n\t\t\tif (terminal <= last) {\n\t\t\t\tviewCount--;\n\t\t\t\ttimeSpent -= 1 + swipeTime;\n\t\t\t\tif (needRotate[terminal]) {\n\t\t\t\t\ttimeSpent -= rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// go reverse\n\t\t\tt = 1 + swipeTime;\n\t\t\tif (needRotate[rev]) {\n\t\t\t\tt += rotateTime;\n\t\t\t}\n\t\t\t//DEBUG:print(\"terminal - 1 =\", terminal - 1, \"n - rev = \", n - rev);\n\t\t\twhile (timeSpent + swipeTime * Math.min(terminal - 1, n - rev) + t <= totalTime) {\n\t\t\t\tviewCount++;\n\t\t\t\ttimeSpent += t;\n\t\t\t\tt = 1 + swipeTime;\n\t\t\t\trev--;\n\t\t\t\tif (needRotate[rev]) {\n\t\t\t\t\tt += rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (viewCount > ret) {\n\t\t\t\tret = viewCount;\n\t\t\t}\n\t\t} \n\t}\n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\tsplitted = readline();\n\tneedRotate = new Array(n);\n\tfor (var i = 0; i < n; i++) {\n\t\tneedRotate[i] = (splitted[i] == 'w');\n\t}\n\n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();\n", "positive_code": [{"source_code": "var arr = readline().split(\" \", 4).map(Number);\nvar n = arr[0], a = arr[1], b = arr[2], T = arr[3];\nvar str = readline();\n\nfunction calc() {\n var maxPhotoCount = 1, left = [], right = [], i, tmp;\n left[0] = right[0] = 0;\n for (i = 1; i < n; ++i) {\n tmp = left[i - 1] + a + (str[i] === \"w\" ? b : 0) + 1;\n if (tmp + useTime > T) {\n break;\n }\n left[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, left.length);\n if (maxPhotoCount === n) {\n return n;\n }\n for (i = 1; i < n; ++i) {\n tmp = right[i - 1] + a + (str[n - i] === \"w\" ? b : 0) + 1;\n if (tmp + useTime > T) {\n break;\n }\n right[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, right.length);\n if (maxPhotoCount === n) {\n return n;\n }\n\n var time, beg, end, mid;\n end = right.length - 1;\n for (i = 1; i < left.length; ++i) {\n time = T - useTime - left[i] - i * a;\n if (right[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (right[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (right[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n \n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n }\n end = left.length - 1;\n for (i = 1; i < right.length; ++i) {\n time = T - useTime - right[i] - i * a;\n if (left[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (left[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (left[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n }\n return maxPhotoCount;\n}\n\nvar useTime = 1 + (str[0] === \"w\" ? b : 0);\nif (useTime > T) {\n print(0);\n} else {\n print(calc());\n}"}, {"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\nInput\n5 2 4 13\nhhhwh\nOutput\n3\nAnswer\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar needRotate;\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret;\n\tvar i;\n\tvar viewCount = 0;\n\tvar timeSpent = 0;\n\tvar rev = n - 1, last;\n\tvar t = 0;\n\t\n\tfor (i = 0; i < n && timeSpent + t <= totalTime; i++) {\n\t\ttimeSpent += t;\n\t\tt = 1;\n\t\tif (i > 0) {\n\t\t\tt += swipeTime;\n\t\t}\n\t\t\t\t\n\t\tif (needRotate[i]) {\n\t\t\tt += rotateTime;\n\t\t}\n\t\t\n\t\tif (timeSpent + t <= totalTime) {\n\t\t\tlast = i;\n\t\t\tviewCount++;\n\t\t}\n\t}\n\t\n\tret = viewCount;\n\tif (ret > 0 && ret < n) {\n\t\tfor (var terminal = last + 1; terminal > 0; terminal--) {\n\t\t\t// decrement\n\t\t\tif (terminal <= last) {\n\t\t\t\tviewCount--;\n\t\t\t\ttimeSpent -= 1 + swipeTime;\n\t\t\t\tif (needRotate[terminal]) {\n\t\t\t\t\ttimeSpent -= rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// go reverse\n\t\t\tt = 1 + swipeTime;\n\t\t\tif (needRotate[rev]) {\n\t\t\t\tt += rotateTime;\n\t\t\t}\n\t\t\t//DEBUG:print(\"terminal - 1 =\", terminal - 1, \"n - rev = \", n - rev);\n\t\t\twhile (timeSpent + swipeTime * Math.min(terminal - 1, n - rev) + t <= totalTime) {\n\t\t\t\tviewCount++;\n\t\t\t\ttimeSpent += t;\n\t\t\t\tt = 1 + swipeTime;\n\t\t\t\trev--;\n\t\t\t\tif (needRotate[rev]) {\n\t\t\t\t\tt += rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (viewCount > ret) {\n\t\t\t\tret = viewCount;\n\t\t\t}\n\t\t} \n\t}\n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\tsplitted = readline();\n\tneedRotate = new Array(n);\n\tfor (var i = 0; i < n; i++) {\n\t\tneedRotate[i] = (splitted[i] == 'w');\n\t}\n\n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();\n"}, {"source_code": "var arr = readline().split(\" \", 4).map(Number);\nvar n = arr[0], a = arr[1], b = arr[2], T = arr[3];\nvar str = readline();\n\nvar change = [];\nfor (var i = 0; i < n; ++i) {\n change[i] = Number(str[i] === \"w\");\n}\n\nfunction calc() {\n var maxPhotoCount = 1, left = [], right = [], i, tmp;\n left[0] = right[0] = 0;\n for (i = 1; i < n; ++i) {\n tmp = left[i - 1] + a + change[i] * b + 1;\n if (tmp + useTime > T) {\n break;\n }\n left[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, left.length);\n if (maxPhotoCount === n) {\n return n;\n }\n for (i = 1; i < n; ++i) {\n tmp = right[i - 1] + a + change[n - i] * b + 1;\n if (tmp + useTime > T) {\n break;\n }\n right[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, right.length);\n if (maxPhotoCount === n) {\n return n;\n }\n\n var time, beg, end, mid;\n end = right.length - 1;\n for (i = 1; i < left.length; ++i) {\n time = T - useTime - left[i] - i * a;\n if (right[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (right[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (right[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n \n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n if (maxPhotoCount === n) {\n return n;\n }\n }\n end = left.length - 1;\n for (i = 1; i < right.length; ++i) {\n time = T - useTime - right[i] - i * a;\n if (left[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (left[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (left[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n if (maxPhotoCount === n) {\n return n;\n }\n }\n return maxPhotoCount;\n}\n\nvar useTime = change[0] * b + 1;\nif (useTime > T) {\n print(0);\n} else {\n print(calc());\n}"}], "negative_code": [{"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar needRotate;\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret;\n\tvar i;\n\tvar viewCount = 0;\n\tvar timeSpent = 0;\n\tvar rev = n - 1, last;\n\tvar t = 0;\n\t\n\tfor (i = 0; i < n && timeSpent + t < totalTime; i++) {\n\t\tt = 1;\n\t\tif (i > 0) {\n\t\t\tt += swipeTime;\n\t\t}\n\t\t\t\t\n\t\tif (needRotate[i]) {\n\t\t\tt += rotateTime;\n\t\t}\n\t\t\n\t\tif (timeSpent + t <= totalTime) {\n\t\t\ttimeSpent += t;\n\t\t\tlast = i;\n\t\t\tviewCount++;\n\t\t}\n\t}\n\t\n\tret = viewCount;\n\tif (ret > 0 && ret < n) {\n\t\tfor (var terminal = last; terminal > 0; terminal--) {\n\t\t\t// decrement\n\t\t\tviewCount--;\n\t\t\ttimeSpent -= 1 + swipeTime;\n\t\t\tif (needRotate[terminal]) {\n\t\t\t\ttimeSpent -= rotateTime;\n\t\t\t}\n\t\t\t// long move to left\n\t\t\tvar timeSwipeBack = (terminal - 1) * swipeTime;\n\t\t\t\n\t\t\t// go reverse\n\t\t\tt = 1 + swipeTime;\n\t\t\tif (needRotate[rev]) {\n\t\t\t\tt += rotateTime;\n\t\t\t}\n\t\t\twhile (rev > terminal && timeSpent + timeSwipeBack + t <= totalTime) {\n\t\t\t\tviewCount++;\n\t\t\t\ttimeSpent += t;\n\t\t\t\trev--;\n\t\t\t\tt = 1 + swipeTime;\n\t\t\t\tif (needRotate[rev]) {\n\t\t\t\t\tt += rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (viewCount > ret) {\n\t\t\t\tret = viewCount;\n\t\t\t}\n\t\t} \n\t}\n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\tsplitted = readline();\n\tneedRotate = new Array(n);\n\tfor (var i = 0; i < n; i++) {\n\t\tneedRotate[i] = (splitted[i] == 'w');\n\t}\n\n//\tvar answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime); \n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();\n"}, {"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar needRotate;\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret;\n\tvar i;\n\tvar viewCount = 0;\n\tvar timeSpent = 0;\n\tvar rev = n - 1, last;\n\tvar t = 0;\n\t\n\tfor (i = 0; i < n && timeSpent + t < totalTime; i++) {\n\t\tt = 1;\n\t\tif (i > 0) {\n\t\t\tt += swipeTime;\n\t\t}\n\t\t\t\t\n\n\t\tif (needRotate[i]) {\n\t\t\tt += rotateTime;\n\t\t}\n\t\t\n\t\tif (timeSpent + t <= totalTime) {\n\t\t\ttimeSpent += t;\n\t\t\tlast = i;\n\t\t\tviewCount++;\n\t\t}\n\t}\n\t\n\tret = viewCount;\n\tif (ret > 0 && ret < n) {\n\t\tfor (var terminal = last; terminal > 0; terminal--) {\n\t\t\t// decrement\n\t\t\tviewCount--;\n\t\t\ttimeSpent -= 1 + swipeTime;\n\t\t\tif (needRotate[terminal]) {\n\t\t\t\ttimeSpent -= rotateTime;\n\t\t\t}\n\t\t\t// long move to left\n\t\t\tvar timeSwipeBack = (terminal - 1) * swipeTime;\n\t\t\t\n\t\t\t// go reverse\n\t\t\tt = 1 + swipeTime;\n\t\t\tif (needRotate[rev]) {\n\t\t\t\tt += rotateTime;\n\t\t\t}\n\t\t\twhile (timeSpent + timeSwipeBack + t <= totalTime) {\n\t\t\t\tviewCount++;\n\t\t\t\ttimeSpent += t;\n\t\t\t\trev--;\n\t\t\t\tt = 1 + swipeTime;\n\t\t\t\tif (needRotate[rev]) {\n\t\t\t\t\tt += rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (viewCount > ret) {\n\t\t\t\tret = viewCount;\n\t\t\t}\n\t\t} \n\t}\n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\tsplitted = readline();\n\tneedRotate = new Array(n);\n\tfor (var i = 0; i < n; i++) {\n\t\tneedRotate[i] = (splitted[i] == 'w');\n\t}\n\n//\tvar answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime); \n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();\n"}, {"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar needRotate;\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret;\n\tvar i;\n\tvar viewCount = 0;\n\tvar timeSpent = 0;\n\tvar rev = n - 1, last;\n\tvar t = 0;\n\t\n\tfor (i = 0; i < n && timeSpent + t <= totalTime; i++) {\n\t\ttimeSpent += t;\n\t\tt = 1;\n\t\tif (i > 0) {\n\t\t\tt += swipeTime;\n\t\t}\n\t\t\t\t\n\t\tif (needRotate[i]) {\n\t\t\tt += rotateTime;\n\t\t}\n\t\t\n\t\tif (timeSpent + t <= totalTime) {\n\t\t\tlast = i;\n\t\t\tviewCount++;\n\t\t}\n\t}\n\t\n\tret = viewCount;\n\tif (ret > 0 && ret < n) {\n\t\tfor (var terminal = last; terminal > 0; terminal--) {\n\t\t\t// decrement\n\t\t\tviewCount--;\n\t\t\ttimeSpent -= 1 + swipeTime;\n\t\t\tif (needRotate[terminal]) {\n\t\t\t\ttimeSpent -= rotateTime;\n\t\t\t}\n\t\t\t// long move to left\n\t\t\tvar timeSwipeBack = (terminal - 1) * swipeTime;\n\t\t\t\n\t\t\t// go reverse\n\t\t\tt = 1 + swipeTime;\n\t\t\tif (needRotate[rev]) {\n\t\t\t\tt += rotateTime;\n\t\t\t}\n\t\t\twhile (timeSpent + timeSwipeBack + t <= totalTime) {\n\t\t\t\tviewCount++;\n\t\t\t\ttimeSpent += t;\n\t\t\t\tt = 1 + swipeTime;\n\t\t\t\trev--;\n\t\t\t\tif (needRotate[rev]) {\n\t\t\t\t\tt += rotateTime;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (viewCount > ret) {\n\t\t\t\tret = viewCount;\n\t\t\t}\n\t\t} \n\t}\n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\tsplitted = readline();\n\tneedRotate = new Array(n);\n\tfor (var i = 0; i < n; i++) {\n\t\tneedRotate[i] = (splitted[i] == 'w');\n\t}\n\n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();\n"}, {"source_code": "/* TEST CASE\ninput\n4 2 3 10\nwwhw\noutput\n2\n\ninput\n5 2 4 1000\nhhwhh\noutput\n5\n\ninput\n3 1 100 10\nwhw\noutput\n0\n\ninput\n5 2 4 13\nhhwhh\noutput\n4\n\n*/\nvar n;\nvar swipeTime;\nvar rotateTime;\nvar orientations;\n\nfunction maxViewedPicture_BRUTEFORCE(index1, index2, currentIndex, t) {\n\tif (index1 != index2 && ((n + index1) % n == index2 % n)) {\n\t\treturn 0;\n\t}\n\t\n\tvar ret = 0;\n\tvar timeSpent = 1;\n\tif (orientations[(n + currentIndex) % n] == 'w') {\n\t\ttimeSpent += rotateTime;\n\t}\n\tif (t - timeSpent >= 0) {\n\t\tret = 1 \n\t\t\t+ Math.max( maxViewedPicture_BRUTEFORCE(index1, index2 + 1, index2 + 1\n\t\t\t\t\t\t\t\t\t\t, t - timeSpent \n\t\t\t\t\t\t\t\t\t\t\t- swipeTime * (currentIndex == index2 ? 1 : (index2 - index1 + 1)))\n\t\t\t\t\t ,maxViewedPicture_BRUTEFORCE(index1 - 1, index2, index1 - 1\n\t\t\t\t\t\t\t\t\t\t, t - timeSpent \n\t\t\t\t\t\t\t\t\t\t\t- swipeTime * (currentIndex == index1 ? 1 : (index2 - index1 + 1)))\n\t\t\t\t\t);\n\t}\n\t\n\treturn ret;\n}\n\nfunction maxViewedPicture(totalTime) {\n\tvar ret = 0;\n\tvar viewCount;\n\tvar i;\n\tvar timeRemain;\n\tfor (var terminal = n - 1; terminal >= 0 && ret < n; terminal--) {\n\t\tviewCount = 0;\n\t\ttimeRemain = totalTime;\n\n\t\tfor (i = 0; i <= terminal && timeRemain > 0; i++) {\n\t\t\tif (orientations[i] == 'w') {\n\t\t\t\ttimeRemain -= rotateTime;\n\t\t\t}\n\t\t\tif (--timeRemain >= 0) {\n\t\t\t\tviewCount++;\n\t\t\t}\n\t\t\ttimeRemain -= swipeTime;\n\t\t}\n\t\t\n\t\ttimeRemain -= (terminal + 1) * swipeTime;\n\t\tfor (i = n - 1; i > terminal + 1 && timeRemain > 0; i--) {\n\t\t\tif (orientations[i] == 'w') {\n\t\t\t\ttimeRemain -= rotateTime;\n\t\t\t}\n\t\t\tif (--timeRemain >= 0) {\n\t\t\t\tviewCount++;\n\t\t\t}\n\t\t\ttimeRemain -= swipeTime;\n\t\t}\n\t\t\n\t\tif (viewCount > ret) {\n\t\t\tret = viewCount;\n\t\t}\n\t} \n\n\treturn ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tn = parseInt(splitted[0]);\n\tswipeTime = parseInt(splitted[1]);\n\trotateTime = parseInt(splitted[2]);\n\ttotalTime = parseInt(splitted[3]);\n\torientations = readline();\n\n//\tvar answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime); \n\tvar answer = maxViewedPicture(totalTime); \n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var arr = readline().split(\" \", 4).map(Number);\nvar n = arr[0], a = arr[1], b = arr[2], T = arr[3];\nvar str = readline();\n\nvar photoCount = 0, useTime = 0, maxPhotoCount;\nif (str[0] === \"w\") {\n useTime += b;\n}\n++useTime;\nif (useTime > T) {\n print(0);\n} else {\n ++photoCount;\n maxPhotoCount = 1;\n\n for (var i = 1; i < n; ++i) {\n useTime += a + 1;\n if (str[i] === \"w\") {\n useTime += b;\n }\n if (useTime <= T) {\n ++photoCount;\n } else {\n break;\n }\n var photoOut = 0;\n if ((i + 1) * a + 1 <= T - useTime) {\n var timeOut = T - useTime - i * a;\n for (var j = n - 1; j > i; --j) {\n timeOut -= a + 1;\n if (str[j] === \"w\") {\n timeOut -= b;\n }\n if (timeOut >= 0) {\n ++photoOut;\n } else {\n break;\n }\n }\n }\n maxPhotoCount = Math.max(maxPhotoCount, photoCount + photoOut);\n if (maxPhotoCount === n) {\n break;\n }\n }\n print(maxPhotoCount);\n}"}, {"source_code": "var arr = readline().split(\" \", 4).map(Number);\nvar n = arr[0], a = arr[1], b = arr[2], T = arr[3];\nvar str = readline();\n\nvar change = [];\nfor (var i = 0; i < n; ++i) {\n change[i] = Number(str[i] === \"w\");\n}\n\nfunction calc() {\n var maxPhotoCount = 1, left = [], right = [], i, tmp;\n left[0] = right[0] = useTime;\n for (i = 1; i < n; ++i) {\n tmp = left[i - 1] + a + change[i] * b + 1;\n if (tmp > T) {\n break;\n }\n left[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, left.length);\n if (maxPhotoCount === n) {\n return n;\n }\n for (i = 1; i < n; ++i) {\n tmp = right[i - 1] + a + change[n - i] * b + 1;\n if (tmp > T) {\n break;\n }\n right[i] = tmp;\n }\n maxPhotoCount = Math.max(maxPhotoCount, right.length);\n if (maxPhotoCount === n) {\n return n;\n }\n\n var time, beg, end, mid;\n end = right.length - 1;\n for (i = 1; i < left.length; ++i) {\n time = T - left[i] - i * a;\n if (right[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (right[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (right[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n if (maxPhotoCount === n) {\n return n;\n }\n }\n end = left.length - 1;\n for (i = 1; i < right.length; ++i) {\n time = T - right[i] - i * a;\n if (left[1] > time) {\n break;\n }\n beg = 1;\n while (true) {\n if (left[end] <= time) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (left[mid] <= time) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n }\n maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);\n if (maxPhotoCount === n) {\n return n;\n }\n }\n return maxPhotoCount;\n}\n\nvar useTime = change[0] * b + 1;\nif (useTime > T) {\n print(0);\n} else {\n print(calc());\n}"}], "src_uid": "e53eabd41647dc17bd8daf060d736c63"} {"source_code": "var n = Number(readline());\n\nvar data = readline().split(\" \");\n\nvar map = {};\nfor(var i = 0; i < n; i++) {\n map[data[i]] = i;\n}\n\nvar min = n;\nvar minNumber = null;\nObject.keys(map).forEach(function(number) {\n if (map[number] < min) {\n min = map[number];\n minNumber = number;\n }\n});\nprint(minNumber);", "positive_code": [{"source_code": "var n = parseInt(readline());\n\nvar a = readline().split(' ');\nvar b = [];\nvar was = [];\nvar active;\n\nfor (var i = 0; i < n; i++) {\n b.push(parseInt(a[i]));\n}\n\nfor (var i = n-1; i >= 0; i--) {\n if (!was[b[i]]) {\n was[b[i]] = true;\n active = b[i];\n }\n}\n\nprint(active);"}, {"source_code": "readline() // ignore # of cafes\nvar shistory = readline().split(' ')\n// var history = '1 3 2 1 2'.split(' ')\n// var history = '2 1 2 2 4 1'.split(' ')\n\nvar cafes = {}\nfor (var i = 0; i < shistory.length; i++)\n cafes[shistory[i]] = i\nvar order = Object.getOwnPropertyNames(cafes).sort(function(a,b) { return cafes[a] - cafes[b] })\nprint(order[0])\n// console.log(order[0])\n"}, {"source_code": "main();\n\nfunction main(){\n\n visits = new Array(200002);\n visits.fill(0);\n \n n = parseInt(readline());\n input = readline().split(' ');\n for(var i=0; i {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str) => {\r\n str = str.split(' ').map(str => parseInt(str));\r\n if (plusAndMultiply(str)) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No');\r\n }\r\n });\r\n})\r\n\r\nconst plusAndMultiply = (arr) => {\r\n const [n, a, b] = arr;\r\n if (a === 1) {\r\n return (n - 1) % b === 0;\r\n }\r\n let i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) {\r\n return true;\r\n }\r\n i *= a;\r\n }\r\n return false;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction solution(n, a, b) {\r\n if (a == 1) return (n - 1) % b === 0 ? true : false;\r\n\r\n let i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) return true;\r\n i *= a;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n const t = +readline();\r\n for (let i = 0; i < t; i++) {\r\n const [n, a, b] = readline().split(' ').map(elem => +elem);\r\n solution(n, a, b) ? print('Yes') : print('No');\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction solution(n, a, b) {\r\n if (a == 1) return (n - 1) % b === 0 ? true : false;\r\n\r\n let i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) return true;\r\n i *= a;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n const t = +readline();\r\n for (let i = 0; i < t; i++) {\r\n const [n, a, b] = readline().split(' ').map(elem => +elem);\r\n const response = solution(n, a, b) ? 'Yes' : 'No';\r\n print(response);\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let [n,a,b] = readline().split(' ').map(x => +x)\n let foundAns = false\n \n if (a == 1) {\n foundAns = ((n-1) % b == 0)\n } else {\n let num = 1\n while (num <= n) {\n if (num % b == n % b) {\n foundAns = true\n break\n }\n num *= a\n }\n }\n if (foundAns) console.log('Yes')\n else console.log('No')\n}\n\nfunction sortAscending(a, b) {\n return a[0] - b[0]\n}\n// String.prototype.replaceAt = function (index, replacement) {\n// return this.substring(0, index) + replacement + this.substring(index + replacement.length)\n// }\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 1; sc <= nsc; sc++) {\r\n let n, a, b;\r\n [n, a, b] = (await getLine()).split(' ').map(num => parseInt(num));\r\n let isPower = function(val, base) {\r\n while(val % base === 0) val/=base;\r\n return val === 1;\r\n }\r\n if (b === 1){\r\n console.log('Yes');\r\n continue;\r\n }\r\n if (a === 1) {\r\n if (n%b === 1) {\r\n console.log('Yes');\r\n }\r\n else\r\n console.log('No');\r\n continue;\r\n }\r\n\r\n let pow = 1;\r\n let can = false;\r\n while (true) {\r\n if ((n-pow)%b === 0) {\r\n can = true;\r\n break;\r\n }\r\n if (n/a >= pow)\r\n pow*=a;\r\n else\r\n break;\r\n }\r\n if (can)\r\n console.log('Yes');\r\n else\r\n console.log('No')\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar isOK = false;\r\n\t\tvar queue = [1];\r\n\t\tvar used = new Set();\r\n\t\twhile(queue.length > 0){\r\n\t\t\tvar now = queue.shift();\r\n\t\t\tif(now > N){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif((N - now) % B == 0){\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tvar nx1 = now * A;\r\n\t\t\tif(!used.has(nx1)){\r\n\t\t\t\tused.add(nx1);\r\n\t\t\t\tqueue.push(nx1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "function solution(n, a, b) {\r\n if (a == 1) return (n - 1) % b === 0 ? true : false;\r\n\r\n var i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) return true;\r\n i *= a;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main(t) {\r\n for (var i = 0; i < t; i++) {\r\n var line = readline().split(' ').map(elem => +elem);\r\n var n = line[0], a = line[1], b = line[2];\r\n var response = solution(n, a, b) ? 'Yes' : 'No';\r\n print(response);\r\n }\r\n}\r\n\r\nconst t = +readline();\r\nmain(t);"}, {"source_code": "for(t=readline();t--;){\r\n x=readline().split(' ')\r\n\tfor(ap=1;x[1]!=1&&ap<=x[0]&&(x[0]-ap)%x[2]!=0;ap*=x[1]);\r\n\tprint(ap<=x[0]&&(x[0]-ap)%x[2]==0?\"Yes\":\"No\");\r\n}"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var [n, a, b] = readArray(BigInt);\r\n if (a === 1n) {\r\n write((n - 1n) % b === 0n ? 'Yes' : 'No');\r\n return;\r\n }\r\n var x = 1n;\r\n while(x <= n) {\r\n var y = n - x;\r\n if (y % b === 0n) {\r\n write('Yes');\r\n return;\r\n }\r\n x *= a;\r\n }\r\n write('No');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, a, b] = rna();\r\n\r\n\t\tif (a == 1) {\r\n\t\t\tconsole.log((n-1)%b == 0 ? 'YES' : 'NO'); continue;\r\n\t\t}\r\n\r\n\t\tlet cur = 1;\r\n\t\twhile (cur%b != n%b && cur <= n) {\r\n\t\t\tcur *= a;\r\n\t\t}\r\n\r\n\t\tconsole.log(cur <= n ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var [n, a, b] = readArray(Number);\r\n var s = new Set();\r\n while(n > 1 && a !== 1) {\r\n var x = n % a;\r\n if (x === 0) {\r\n s = new Set();\r\n n = div(n, a);\r\n continue;\r\n }\r\n if (s.has(x)) {\r\n a = 1;\r\n break;\r\n }\r\n s.add(x);\r\n n -= b;\r\n }\r\n if (a === 1) {\r\n write((n - 1) % b === 0 ? 'Yes' : 'No');\r\n return;\r\n }\r\n write(n === 1 ? 'Yes' : 'No');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var [n, a, b] = readArray(Number);\r\n \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var [n, a, b] = readArray(Number);\r\n var s = new Set();\r\n while(n > 1 && a !== 1) {\r\n var x = n % a;\r\n if (x === 0) {\r\n s = new Set();\r\n n = div(n, a);\r\n continue;\r\n }\r\n if (s.has(x)) {\r\n a = 1;\r\n break;\r\n }\r\n s.add(x);\r\n n -= b;\r\n }\r\n if (a === 1) {\r\n write((n - 1) % b === 0 ? 'Yes' : 'No');\r\n return;\r\n }\r\n write(n === 1 ? 'Yes' : 'No');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var [n, a, b] = readArray(Number);\r\n var s = new Set();\r\n while(n > 1) {\r\n n -= b;\r\n var x = n % a;\r\n if (x === 0) {\r\n s = new Set();\r\n n = div(n, a);\r\n continue;\r\n }\r\n if (s.has(x)) {\r\n a = 1;\r\n break;\r\n }\r\n s.add(x);\r\n }\r\n if (a === 1) {\r\n write((n - 1) % b === 0 ? 'Yes' : 'No');\r\n return;\r\n }\r\n write(n === 1 ? 'Yes' : 'No');\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, a, b] = rna();\r\n\r\n\t\tif (a == 1) {\r\n\t\t\tconsole.log(n%b == 1 ? 'YES' : 'NO'); continue;\r\n\t\t}\r\n\r\n\t\tif (b == 1) {\r\n\t\t\tconsole.log('YES'); continue;\r\n\t\t}\r\n\r\n\t\tlet cur = 1n;\r\n\t\tlet flag;\r\n\t\twhile (cur <= n) {\r\n\t\t\tif (cur%b == n%b) {\r\n\t\t\t\tflag = 1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcur *= a;\r\n\t\t}\r\n\r\n\t\tconsole.log(flag ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, a, b] = rna();\r\n\r\n\t\tif (a == 1) {\r\n\t\t\tconsole.log(n%b == 1 ? 'YES' : 'NO'); continue;\r\n\t\t}\r\n\r\n\t\tif (b == 1) {\r\n\t\t\tconsole.log('YES'); continue;\r\n\t\t}\r\n\r\n\t\tlet cur = 1n;\r\n\t\twhile (cur%b != n%b && cur <= n) {\r\n\t\t\tcur *= a;\r\n\t\t}\r\n\r\n\t\tconsole.log(cur <= n ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, a, b] = rna();\r\n\r\n\t\tif (a == 1) {\r\n\t\t\tconsole.log(n%b == 1 ? 'YES' : 'NO'); continue;\r\n\t\t}\r\n\r\n\t\tif (b == 1) {\r\n\t\t\tconsole.log('YES'); continue;\r\n\t\t}\r\n\r\n\t\tlet cur = 1;\r\n\t\twhile (cur%b != n%b && cur <= n) {\r\n\t\t\tcur *= a;\r\n\t\t}\r\n\r\n\t\tconsole.log(cur <= n ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str) => {\r\n str = str.split(' ').map(str => parseInt(str));\r\n if (plusAndMultiply(str)) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No');\r\n }\r\n });\r\n})\r\n\r\nconst plusAndMultiply = (arr) => {\r\n const [n, a, b] = arr;\r\n if (a === 1) {\r\n return n % b === 1;\r\n }\r\n let i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) {\r\n return true;\r\n }\r\n i *= a;\r\n }\r\n return false;\r\n}"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n content.forEach((str) => {\r\n str = str.split(' ').map(str => parseInt(str));\r\n if (plusAndMultiply(str)) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No');\r\n }\r\n });\r\n})\r\n\r\nconst plusAndMultiply = (arr) => {\r\n const [n, a, b] = arr;\r\n if (a === 1) {\r\n return n % b === 1;\r\n }\r\n let i = 0;\r\n let secondComp = n - Math.pow(a, i);\r\n while (secondComp >= 0) {\r\n if (secondComp % b === 0) {\r\n return true;\r\n }\r\n i++;\r\n secondComp = n - Math.pow(a, i);\r\n }\r\n return false;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction solution(n, a, b) {\r\n if (a == 1) return (n - 1) % b === 0 ? true : false;\r\n\r\n let i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) return true;\r\n i *= a;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main(t) {\r\n for (let i = 0; i < t; i++) {\r\n const [n, a, b] = readline().split(' ').map(elem => +elem);\r\n const response = solution(n, a, b) ? 'Yes' : 'No';\r\n print(response);\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(...arr))\n }\n});\n\nfunction solve(n, a, b) {\n return isIn(n, a, b) ? 'Yes' : 'No'\n}\n\nfunction isIn(n, a, b) {\n if (a === 1) {\n return !((n - 1) % b)\n }\n\n const stack = [n]\n const visited = {}\n while (stack.length) {\n n = stack.pop()\n if (n % b === 1) return true\n if (visited[n]) continue\n visited[n] = 1\n\n const r = n % a\n if (r) {\n const k = getK(r, a, b)\n // console.log(a,b,r,k,n-k*b)\n if (k >= 0 && n - k * b > 0) {\n stack.push(n - k * b)\n }\n } else {\n n /= a\n stack.push(n)\n }\n }\n return false\n\n // return a !== 1 && !(n % a) && isIn(n / a, a, b)\n // || n - b >= 1 && isIn(n - b, a, b)\n}\n\nfunction getK(r, a, b) {\n // k * b % a = r\n let k = 1\n while (k <= a) {\n if (k * b % a === r) return k\n k++\n }\n return -1\n}\n\n"}, {"source_code": "function solution(n, a, b) {\r\n if (a == 1) return (n - 1) % b === 0 ? true : false;\r\n\r\n var i = 1;\r\n while (i <= n) {\r\n if ((n - i) % b === 0) return true;\r\n i *= a;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main(t) {\r\n for (var i = 0; i < t; i++) {\r\n var line = readline().split(' ').map(elem => +elem);\r\n var n = line[0], a = line[1], b = line[2];\r\n var response = solution(n, a, b) ? 'Yes' : 'No';\r\n print(response);\r\n }\r\n}"}], "src_uid": "e0a3c678f6d1d89420c8162b0ddfcef7"} {"source_code": "function A1427(array) {\n var sum = array.reduce(function (acc, x) {\n return acc + x;\n }, 0);\n if (sum < 0) return array.sort(function (a, b) {\n return a - b;\n });else if (sum > 0) return array.sort(function (a, b) {\n return b - a;\n });else return [];\n}\n\nfunction execute(readline, print) {\n var iter = {\n next: function next() {\n return readline();\n }\n };\n\n var split = function split(string) {\n return string.trim().split(' ').map(Number);\n };\n\n var t = Number(iter.next());\n\n while (t--) {\n iter.next();\n var arr = split(iter.next());\n var out = A1427(arr);\n\n if (out.length) {\n print(\"YES\");\n print(out.join(' '));\n } else {\n print(\"NO\");\n }\n }\n}\n\nexecute(readline, print)\n", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), a = $(n)\n if (a.sum() == 0) log('NO');\n else {\n let duong = a.filter(v => v > 0)\n let so0 = a.filter(v => v == 0)\n let am = a.filter(v => v < 0)\n log('YES');\n if (abs(duong.sum()) > abs(am.sum())) {\n log(duong.concat(am).concat(so0).join(' '))\n } else {\n log(am.concat(duong).concat(so0).join(' '))\n }\n }\n }\n}\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(numbers) {\n const s = sum(numbers);\n\n if (s === 0) {\n console.log('NO');\n } else {\n console.log('YES');\n console.log(numbers.sort((a, b) => s < 0 ? a - b : b - a).join(' '));\n }\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n input.forEach(([_, i]) => solve(i.split(' ').map(Number)));\n}\n\nmain().then();\n"}, {"source_code": "\nvar t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var result = ''\n var str = readline();\n var nums = str.split(' ').map(Number)\n var sum = nums.reduce(function (res, num){return res + num}, 0);\n if (sum === 0) {\n print('NO')\n continue;\n }\n nums.sort(function (a, b) {return a - b});\n if (sum < 0) {\n result = nums.join(' ')\n } else {\n nums.reverse()\n result = nums.join(' ')\n }\n print('YES')\n print(result)\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let sum = 0;\n let [plus, minus] = [[], []];\n let arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n sum += n;\n if (n >= 0) plus.push(n);\n else minus.push(n);\n return n;\n });\n if (sum === 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n if (sum < 0) {\n arr.sort((a, b) => a - b);\n } else {\n arr.sort((a, b) => b - a);\n }\n console.log(arr.join(\" \"));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n // const n = a[0];\n // const k = a[1];\n let a = data[i + 1].trim().split(' ').map(Number);\n let nSum = 0;\n let pos = [];\n let neg = [];\n let zero = [];\n let pSum = 0;\n for (let j = 0; j < a.length; j += 1) {\n if (a[j] > 0) {pos.push(a[j]); pSum += a[j];}\n else if (a[j] === 0) zero.push(0);\n else {neg.push(a[j]); nSum += a[j];}\n }\n if (pSum + nSum !== 0) {\n console.log('YES');\n if (-pSum > nSum) console.log(neg.concat(pos, zero).join(' '));\n else console.log(pos.concat(neg, zero).join(' '));\n } else console.log('NO');\n // let min = a[0];\n // let moves = 0;\n // if (a[0] < k) {\n // for (let i = 1; i < a.length; i += 1) {\n // if (a[i] < k) moves += Math.floor((k - a[i]) / min);\n // }\n // }\n i += 2;\n }\n}"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let sum = 0;\n let [countPlus, countMinus] = [0, 0];\n let arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n sum += n;\n if (n >= 0) countPlus++;\n else countMinus++;\n return n;\n });\n if (sum === 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n if (countPlus > countMinus) {\n arr.sort((a, b) => b - a);\n } else {\n arr.sort((a, b) => a - b);\n }\n console.log(arr.join(\" \"));\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let sum = 0;\n let arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n sum += n;\n return n;\n });\n if (sum === 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n [arr[0], arr[len - 1]] = [arr[len - 1], arr[0]];\n console.log(arr.join(\" \"));\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let sum = 0;\n let [plus, minus] = [[], []];\n let arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n sum += n;\n if (n >= 0) plus.push(n);\n else minus.push(n);\n return n;\n });\n if (sum === 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n plus.sort((a, b) => a - b);\n minus.sort((a, b) => b - a);\n arr = [...plus, ...minus];\n console.log(arr.join(\" \"));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n // const n = a[0];\n // const k = a[1];\n let a = data[i + 1].trim().split(' ').map(Number);\n let sum = 0;\n let pos = [];\n let neg = [];\n let zero = [];\n for (let j = 0; j < a.length; j += 1) {\n sum += a[j];\n if (a[j] > 0) pos.push(a[j]);\n else if (a[j] === 0) zero.push(0);\n else neg.push(a[j]);\n }\n if (sum !== 0) {\n neg.sort((a, b) => b - a);\n pos = pos.concat(neg, zero);\n console.log('YES');\n console.log(pos.join(' '));\n } else console.log('NO');\n // let min = a[0];\n // let moves = 0;\n // if (a[0] < k) {\n // for (let i = 1; i < a.length; i += 1) {\n // if (a[i] < k) moves += Math.floor((k - a[i]) / min);\n // }\n // }\n i += 2;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n // const n = a[0];\n // const k = a[1];\n let a = data[i + 1].trim().split(' ').map(Number);\n let sum = 0;\n let pos = [];\n let neg = [];\n let zero = [];\n for (let j = 0; j < a.length; j += 1) {\n sum += a[j];\n if (a[j] > 0) pos.push(a[j]);\n else if (a[j] === 0) zero.push(0);\n else neg.push(a[j]);\n }\n if (sum !== 0) {\n neg.sort((a, b) => b - a);\n pos = pos.concat(zero, neg);\n console.log(pos.join(' '));\n } else console.log('NO');\n // let min = a[0];\n // let moves = 0;\n // if (a[0] < k) {\n // for (let i = 1; i < a.length; i += 1) {\n // if (a[i] < k) moves += Math.floor((k - a[i]) / min);\n // }\n // }\n i += 2;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim().split(' ').map(Number);\n // const n = a[0];\n // const k = a[1];\n let a = data[i + 1].trim().split(' ').map(Number);\n let sum = 0;\n let pos = [];\n let neg = [];\n let zero = [];\n for (let j = 0; j < a.length; j += 1) {\n sum += a[j];\n if (a[j] > 0) pos.push(a[j]);\n else if (a[j] === 0) zero.push(0);\n else neg.push(a[j]);\n }\n if (sum !== 0) {\n neg.sort((a, b) => b - a);\n pos = pos.concat(zero, neg);\n console.log('YES');\n console.log(pos.join(' '));\n } else console.log('NO');\n // let min = a[0];\n // let moves = 0;\n // if (a[0] < k) {\n // for (let i = 1; i < a.length; i += 1) {\n // if (a[i] < k) moves += Math.floor((k - a[i]) / min);\n // }\n // }\n i += 2;\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), a = $(n)\n if (a.sum() == 0) log('NO');\n else {\n let duong = a.filter(v => v >= 0)\n let am = a.filter(v => v < 0)\n log('YES');\n if (abs(duong.sum()) > abs(am.sum())) {\n log(duong.concat(am).join(' '))\n } else {\n log(am.concat(duong).join(' '))\n }\n }\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), a = $(n).sort(asc)\n if (a.sum() == 0) log('NO');\n else {\n let duong = a.filter(v => v >= 0)\n let am = a.filter(v => v < 0)\n log('YES');\n if (duong.sum() > abs(am.sum())) {\n log(duong.concat(am).join(' '))\n } else {\n log(am.concat(duong).join(' '))\n }\n }\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nwhile (t--) {\n var n = parseInt(readline());\n var result = ''\n var str = readline();\n var nums = str.split(' ').map(Number)\n var sum = nums.reduce(function (res, num){return res + num}, 0);\n if (sum === 0) {\n print('NO')\n continue;\n }\n nums.sort(function (a, b) {return a - b});\n if (sum < 0) {\n result = nums.join(' ')\n } else {\n nums.reverse()\n result = nums.join(' ')\n }\n if (result === str) {\n print('NO')\n } else {\n print('YES')\n print(result)\n }\n}"}], "src_uid": "e57345f5757654749b411727ebb99c80"} {"source_code": "var line = readline ();\nline = line.trim ().split ( ' ' );\nvar n, m;\nn = (+ line [ 0 ]);\nm = (+ line [ 1 ]);\nfunction gcd ( a, b ) { \n if ( b == 0 ) return a;\n else return gcd ( b, a % b );\n}\nvar i, j;\nvar cnt = 0;\nvar graph = { };\nl1: for ( i = 1; i <= n - 1; i ++ ) {\n l2: for ( j = i + 1; j <= n; j ++ ) {\n if ( gcd ( i, j ) == 1 ) { \n if ( ! ( i in graph ) ) graph [ i ] = { };\n graph [ i ][ j ] = 1;\n cnt ++;\n }\n if ( cnt >= m ) break l1;\n }\n}\nif ( cnt < m || m < (n - 1) ) {\n print ( 'Impossible' );\n} else {\n var v, u;\n print ( 'Possible' );\n for ( v in graph ) \n for ( u in graph [ v ] ) \n print ( v + ' ' + u );\n}\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n const container = [];\n for (let i = 1; i < n && container.length < m; i += 1) {\n for (let j = i + 1; j <= n && container.length < m; j += 1) {\n if (gcd(i, j) === 1) {\n container.push([i, j]);\n }\n }\n }\n\n if (m !== container.length || m < n - 1) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n container.forEach((item) => {\n console.log(item.join(' '));\n });\n }\n}\n\n\nfunction gcd(a, b) {\n while (b !== 0) {\n [a, b] = [b, a % b];\n }\n return a;\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n let edges = 0;\n const container = [];\n for (let i = 1; i < n && edges < m; i += 1) {\n for (let j = i + 1; j <= n && edges < m; j += i) {\n if (gcd(i, j) === 1) {\n container.push([i, j]);\n edges += 1;\n }\n }\n }\n\n if (m > edges || m < n - 1) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n container.forEach((item) => {\n console.log(item.join(' '));\n });\n }\n}\n\n\nfunction gcd(a, b) {\n while (b !== 0) {\n [a, b] = [b, a % b];\n }\n return a;\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n let edges = 0;\n const container = [];\n for (let i = 1; i < n && edges < m; i += 1) {\n for (let j = i + 1; j <= n && edges < m; j += i) {\n if (gcd(i, j) === 1) {\n container.push([i, j]);\n edges += 1;\n }\n }\n }\n\n if (m !== edges || m < n - 1) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n container.forEach((item) => {\n console.log(item.join(' '));\n });\n }\n}\n\n\nfunction gcd(a, b) {\n while (b !== 0) {\n [a, b] = [b, a % b];\n }\n return a;\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n\n const LIMIT = parseInt(n + 1, 10);\n const eulerPhi = new Array(LIMIT);\n for (let i = 0; i < LIMIT; i += 1)\n eulerPhi[i] = i;\n for (let i = 2; i < LIMIT; i += 1) {\n if (eulerPhi[i] === i) {\n for (let j = i; j < LIMIT; j += i)\n eulerPhi[j] -= parseInt(eulerPhi[j] / i);\n }\n }\n\n let edges = 0;\n for (let i = 2; i < LIMIT; i += 1) {\n edges += eulerPhi[i];\n }\n\n if (m > edges) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n\n edges = 0;\n for (let i = 2; i < LIMIT && edges < m; i += 1) {\n console.log(`${1} ${i}`);\n edges += 1;\n }\n\n const primes = [];\n const compose = [];\n const sieve = new Array(LIMIT).fill(true);\n for (let i = 2; i < LIMIT; i += 1) {\n if (sieve[i]) {\n primes.push(i);\n for (let j = i * i; j < LIMIT; j += i) {\n sieve[j] = false;\n }\n } else {\n compose.push(i);\n }\n }\n\n primes.forEach((item) => {\n for (let i = item - 1; i > 1 && edges < m; i -= 1) {\n console.log(`${item} ${i}`);\n edges += 1;\n }\n for (let i = lowerBound(compose, item); i < compose.length && edges < m; i += 1) {\n if (compose[i] % item !== 0) {\n console.log(`${item} ${compose[i]}`);\n edges += 1;\n }\n }\n });\n }\n}\n\nfunction lowerBound(array, value) {\n let left = 0, middle;\n let right = array.length;\n while (left < right) {\n middle = parseInt((left + right) / 2);\n if (value <= array[middle])\n right = middle;\n else\n left = middle + 1;\n }\n\n return left; // not found\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n let edges = 0;\n const container = [];\n for (let i = 1; i < n && edges < m; i += 1) {\n for (let j = i + 1; j <= n && edges < m; j += i) {\n if (gcd(i, j) === 1) {\n container.push([i, j]);\n edges += 1;\n }\n }\n }\n\n if (m === edges || m < n - 1) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n container.forEach((item) => {\n console.log(item.join(' '));\n });\n }\n}\n\n\nfunction gcd(a, b) {\n while (b !== 0) {\n [a, b] = [b, a % b];\n }\n return a;\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray().map(Number);\n let edges = 0;\n const container = [];\n for (let i = 1; i < n && edges < m; i += 1) {\n for (let j = i + 1; j <= n && edges < m; j += i) {\n if (gcd(i, j) === 1) {\n container.push([i, j]);\n edges += 1;\n }\n }\n }\n\n if (m > edges) {\n console.log('Impossible');\n } else {\n console.log('Possible');\n container.forEach((item) => {\n console.log(item.join(' '));\n });\n }\n}\n\n\nfunction gcd(a, b) {\n while (b !== 0) {\n [a, b] = [b, a % b];\n }\n return a;\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "src_uid": "0ab1b97a8d2e0290cda31a3918ff86a4"} {"source_code": "print(function(n,m){\n\tvar a=readNumber().sort(function(a,b){return a-b;});\n\tvar b=readNumber().sort(function(a,b){return a-b;});\n\tvar ans=Math.max( a[0]*2, a[a.length-1] );\n\tif(b[0]<=ans) return -1;\n\treturn ans;\n}.apply(0, readNumber()));\nfunction readNumber(){ return readline().split(' ').map(Number); }", "positive_code": [{"source_code": ";(function () {\n\t\n\treadline();\n\tvar a = readline().split(' ').map(Number);\n\tvar b = readline().split(' ').map(Number);\n\n\tvar r = Math.max.apply(null, a);\n\tt = Math.max( 2 * Math.min.apply(null, a), r );\n\n\tif (r <= t && Math.min.apply(null, b) > t) print(t);\n\telse print(-1);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tgoodNum = data[0], badNum = data[1],\n\t\tgood = tokenizeIntegers(readline()),\n\t\tbad = tokenizeIntegers(readline());\n\tfunction sorter(a, b) {\n\t\treturn a-b;\n\t}\n\tgood.sort(sorter);\n\tbad.sort(sorter);\n\tvar min = Math.max(good[good.length-1], 2*good[0]), max = bad[0]-1;\n\tprint (min <= max ? min : -1);\n}\n\nmain();\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar n_s = readline().split(' ').map(Number);\nvar m_s = readline().split(' ').map(Number);\nvar n_mi = Math.min.apply(null, n_s);\nvar n_mx = Math.max.apply(null, n_s);\nvar m_mi = Math.min.apply(null, m_s);\nvar ans = -1;\nvar mx = Math.max(n_mi * 2, n_mx);\nif (mx < m_mi) ans = mx;\nprint(ans);\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar n_s = readline().split(' ').map(Number);\nvar m_s = readline().split(' ').map(Number);\nvar n_mi = Math.min.apply(null, n_s);\nvar n_mx = Math.max.apply(null, n_s);\nvar m_mi = Math.min.apply(null, m_s);\nvar ans = -1;\nfor (var i = n_mx; i < m_mi; i++) {\n if (i >= n_mi * 2) {\n ans = i;\n break;\n }\n}\nprint(ans);\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const _ = readLine();\n const rightCases = readLine().split(\" \").map(Number);\n const wrongCases = readLine().split(\" \").map(Number);\n\n const [rightMin, rightMax, wrongMin] = [Math.min(...rightCases), Math.max(...rightCases), Math.min(...wrongCases)];\n\n const tl = rightMax >= rightMin * 2 ? rightMax : rightMin * 2;\n\n if (tl >= wrongMin) console.log(-1);\n else console.log(tl);\n}\n"}], "negative_code": [{"source_code": "print(function(n,m){\n\tvar a=readNumber().sort(function(a,b){return a-b;});\n\tvar b=readNumber().sort(function(a,b){return a-b;});\n\tvar ans=a[a.length-1];\n\tif(a[0]*2>ans) return -1;\n\tif(b[0]<=ans) return -1;\n\treturn ans;\n}.apply(0, readNumber()));\nfunction readNumber(){ return readline().split(' ').map(Number); }"}, {"source_code": ";(function () {\n\t\n\treadline();\n\tvar a = readline().split(' ').map(Number);\n\tvar b = readline().split(' ').map(Number);\n\n\tt = Math.max.apply(null, a);\n\n\tif (2 * Math.min.apply(null, a) <= t && Math.min.apply(null, b) > t) print(t);\n\telse print(-1);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numDigits = parseInt(readline()),\n\t\tdigits = tokenizeIntegers(readline()),\n\t\tcounts = { 0: 0, 5: 0 };\n\tfor (var i = 0; i < numDigits; ++i) {\n\t\tcounts[digits[i]] += 1;\n\t}\n\tif (counts[0] == 0) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\tif (counts[5] < 9) {\n\t\tprint(0);\n\t\treturn;\n\t}\n\tdigits.sort(function (a, b) {\n\t\treturn b-a;\n\t});\n\tfor (var i = counts[5]%9; i != 0; --i) {\n\t\tdigits.shift();\n\t}\n\tprint(digits.join(''));\n}\n\nmain();\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar n_s = readline().split(' ').map(Number);\nvar m_s = readline().split(' ').map(Number);\nvar n_mi = Math.min.apply(null, n_s);\nvar n_mx = Math.max.apply(null, n_s);\nvar m_mi = Math.max.apply(null, m_s);\nvar ans = -1;\nfor (var i = n_mx; i < m_mi; i++) {\n if (i >= n_mi * 2) {\n ans = i;\n break;\n }\n}\nprint(ans);\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar n_s = readline().split(' ').map(Number);\nvar m_s = readline().split(' ').map(Number);\nvar n_mi = Math.min.apply(null, n_s);\nvar n_mx = Math.max.apply(null, n_s);\nvar m_mi = Math.max.apply(null, m_s);\nvar ans = -1;\nfor (var i = n_mi * 2; i < m_mi; i++) {\n if (i + 1 >= n_mx) {\n ans = i + 1;\n break;\n }\n}\nprint(ans);\n"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar n_s = readline().split(' ').map(Number);\nvar m_s = readline().split(' ').map(Number);\nvar n_mi = Math.min.apply(null, n_s);\nvar n_mx = Math.max.apply(null, n_s);\nvar m_mi = Math.max.apply(null, m_s);\nvar ans = -1;\nfor (var i = n_mx; i < m_mi; i++) {\n if (i / 2 >= n_mi) {\n ans = i;\n break;\n }\n}\nprint(ans);\n"}], "src_uid": "49c47ebfd710a3733ce7ecb3a3c134a7"} {"source_code": "var len = +readline(),\n directions = readline().split(\"\"),\n distantions = readline().split(\" \").map(i => parseInt(i)),\n map = [];\n \nfor (var i = 0; i < len; ++i) {\n map[i] = distantions[i] * (directions[i] == \"<\" ? -1 : 1);\n}\n\nvar current = 0, iteration = 0, maxIterations = len, point;\n\nwhile (iteration <= maxIterations && current >= 0 && current < len) {\n point = map[current];\n current += point;\n iteration++;\n}\n\nprint(current < 0 || current >= len ? \"FINITE\" : \"INFINITE\");", "positive_code": [{"source_code": "var n = +readline()\n , actions = readline()\n , powers = readline().split(' ')\n , current_index = 0\n , path = [];\n\nfunction calc() {\n var action\n , power;\n\n while(path[current_index] === undefined)\n {\n path[current_index] = 1;\n action = actions[current_index];\n power = +powers[current_index];\n if (action == '>') {\n current_index += power;\n if (current_index >= n) {\n return 'FINITE';\n }\n }\n\n if (action == '<') {\n current_index -= power;\n if (current_index < 0) {\n return 'FINITE';\n }\n }\n }\n if (current_index >=0 && current_index < n) {\n return 'INFINITE';\n }\n else {\n return 'FINITE';\n }\n}\nprint(calc())"}], "negative_code": [{"source_code": "var n = +readline()\n , actions = readline()\n , powers = readline().split(' ')\n , current_index = 0\n , path = [];\n\nfunction calc() {\n var action\n , power;\n\n while(path[current_index] === undefined)\n {\n path[current_index] = 1;\n action = actions[current_index];\n power = +powers[current_index];\n if (action == '>') {\n current_index += power;\n if (current_index > n) {\n return 'FINITE';\n }\n }\n\n if (action == '<') {\n current_index -= power;\n if (current_index < 0) {\n return 'FINITE';\n }\n }\n }\n if (current_index > 0 && current_index < n) {\n return 'INFINITE';\n }\n else {\n return 'FINITE';\n }\n}\n//console.log(result);\n//console.log(calc())\nprint(calc())"}], "src_uid": "5fcc22cdc38693723d8a9577d685db12"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), n2 = n ** 0.5 | 0;\n if (n2 * n2 >= n) log(n2 + n2 - 2);\n else if (n2 * (n2 + 1) >= n) log(n2 + n2 - 1);\n else log(n2 + n2);\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n const sqrt = Math.floor(Math.sqrt(n));\n let p = Math.floor(n / sqrt);\n if (n % sqrt === 0) p--;\n const ans = p + sqrt - 1;\n\n console.log(ans);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n let [flag, carry, count, ans] = [1, 1, 1, 0];\n while (count < n) {\n if (flag) {\n count += carry;\n } else {\n carry++;\n count += carry;\n }\n flag ^= 1;\n ans++;\n }\n\n console.log(ans);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var now = 1;\n var count = 1000000000;\n while(true){\n var nokori = N - now;\n var newCount = Math.ceil(nokori / now);\n if(count < newCount + now){\n break;\n }\n count = newCount + now;\n now++;\n }\n output[i] = count - 1;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "'use strict'\nfunction mlt() { return readline().split(' ').map(x => parseInt(x)); }\nfunction inp() { return parseInt(readline()) }\nfunction solv() {\n var x = inp();\n var res = x;\n for (var n = 1; n * n <= x; n++) {\n var cur = n;\n var ans = n - 1;\n var more = Math.ceil((x - cur) / cur);\n ans += more;\n res = Math.min(res, ans);\n }\n print(res)\n}\n\nvar tc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "'use strict'\nfunction mlt() { return readline().split(' ').map(x => parseInt(x)); }\nfunction inp() { return parseInt(readline()) }\nfunction solv() {\n var x = inp();\n var res = x;\n for (var n = 1; n * n <= x; n++) {\n var cur = n;\n var ans = n - 1;\n var more = Math.ceil((x - cur) / cur);\n ans += more;\n res = Math.min(res, ans);\n }\n print(res)\n}\n\nvar tc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var n = int(readline())\n print(Math.ceil(2 * Math.sqrt(n)) - 2)\n}"}, {"source_code": "function int(v) {\n return parseInt(v)\n}\n \nvar t = int(readline())\n\n while(t--)\n {\n \n var n,i;\n \n n=int(readline())\n \n \n if(n==1)print(0);\n \n else if(n==2)print(1);\n \n else{\n \n \n var ans=0;\n \n var a=Math.floor(Math.sqrt(n));\n \n ans=a-1;\n \n n-=a;\n \n ans+=Math.floor((n/a));\n \n if(n%a)ans++;\n \n print(ans);\n }\n \n \n }\n "}], "negative_code": [{"source_code": "function int(v) {\n return parseInt(v)\n}\n\nvar t = int(readline())\n\nwhile(t--) {\n var n = int(readline())\n print(2 * Math.sqrt(n) - 2)\n}"}], "src_uid": "d78cd4a06fb566d58275e92f976166f2"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let rl = 0,\r\n rr = 0,\r\n res = 0;\r\n for (let l = 0, r = n - 1; l <= r;) {\r\n if (rl <= rr) {\r\n rl += a[l++];\r\n } else {\r\n rr += a[r--];\r\n }\r\n if (rl === rr) {\r\n res = Math.max(res, l + n - r - 1);\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n let n = Number(await read()),\r\n a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nconst lines = [];\r\nrl.on('line', (input) => {\r\n\tlines.push(input);\r\n});\r\n\r\nrl.on('close', () => {\r\n\t// (function() {\r\n\t// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n\tlet l = 0;\r\n\tlet t = +lines[l++];\r\n\tconst output = [];\r\n\tfor (let i = 0; i < t; i++) {\r\n\t\tconst n = +lines[l++];\r\n\t\tconst arr = lines[l++].trim().split(' ').map(Number);\r\n\t\toutput[i] = solve(n, arr);\r\n\t}\r\n\tconsole.log(output.join('\\n'));\r\n\t// })()\r\n});\r\n\r\nfunction solve(n, arr) {\r\n\tlet alice_index = 0;\r\n\tlet bob_index = arr.length - 1;\r\n\tlet bob = (alice = ans = 0);\r\n\twhile (alice_index <= bob_index) {\r\n\t\tif (alice <= bob) alice += arr[alice_index++];\r\n\t\telse bob += arr[bob_index--];\r\n\r\n\t\tif (alice == bob) ans = alice_index + arr.length - 1 - bob_index;\r\n\t}\r\n\tconsole.log(ans);\r\n}\r\n"}, {"source_code": "const solve = arr=>{\r\n let max = -1,alice = arr[0],bob = arr[arr.length-1],i=1,j = arr.length-1;\r\n while((i<=j)){\r\n if(alice===bob) max = (arr.length-j)+i; \r\n if(alice<=bob) alice+=arr[i++];\r\n else bob+=arr[--j];\r\n }\r\n if(max===-1) return 0;\r\n return max;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var ar = lines[i].split(' ').map(Number);\n var a = 0, b = n - 1;\n var a1 = ar[0], b1 = ar[b];\n var ans = 0;\n while(a < b){\n if(a1 == b1){\n ans = a + 1 + n - b;\n a++;\n a1 += ar[a];\n }else if(a1 > b1){\n b--;\n b1 += ar[b];\n }else if(a1 < b1){\n a++;\n a1 += ar[a];\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline()\n const A = readline().split(' ').map(x => +x)\n solve(A)\n }\n}\nfunction solve(A) {\n const wl = new Map()\n let sl = 0\n for (let i = 0; i < A.length; i++) {\n sl += A[i]\n wl.set(sl, i)\n }\n\n let max = 0\n let sr = 0\n for (let j = A.length - 1; j >= 0; j--) {\n sr += A[j]\n if (wl.has(sr) && wl.get(sr) < j) {\n max = Math.max(max, wl.get(sr) + 1 + A.length - j)\n }\n }\n\n console.log(max)\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let _t = parseInt(readline());\r\n while (_t) {\r\n _t--;\r\n let n = parseInt(readline());\r\n let a = [];\r\n a = readline()\r\n .split(' ')\r\n .map((e) => parseInt(e));\r\n let left = 0,\r\n right = n - 1,\r\n leftSum = 0,\r\n rightSum = 0,\r\n ans = 0;\r\n while (left <= right) {\r\n if (leftSum < rightSum) {\r\n leftSum += a[left++];\r\n } else {\r\n rightSum += a[right--];\r\n }\r\n if (rightSum === leftSum) ans = Math.max(ans, left + n - right - 1);\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n// cat input.txt | node main.js\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst w = rna();\r\n\r\n\t\tconst mp = [];\r\n\t\tfor (let i = 0, sum = 0; i < n; i++) {\r\n\t\t\tsum += w[i];\r\n\t\t\tmp[sum] = i + 1;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = n - 1, sum = 0; i >= 0; i--) {\r\n\t\t\tsum += w[i];\r\n\t\t\tif (mp[sum] && mp[sum] + n - i <= n) {\r\n\t\t\t\tans = Math.max(ans, mp[sum] + n - i)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n // console.log(`DEBUG res`, res);\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, a)=>{\n let result = 0;\n\n let suma = 0; \n let sumb = 0;\n\n let l = -1;\n let r = n - 1;\n\n while (l < r) {\n suma += a[++l];\n\n while (l < r && sumb < suma) {\n sumb += a[r--];\n }\n\n if (suma === sumb) {\n result = Math.max(result, l + (n - r));\n }\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let i = -1\n let j = n\n let a = 0\n let b = 0\n let ans = 0\n let temp = 0\n while (i < j) {\n if (a < b) {\n a += arr[++i]\n temp++\n } else if (a > b) {\n b += arr[--j]\n temp++\n } else {\n ans += temp\n temp = 0\n if (i + 1 >= j - 1) break\n a += arr[++i]\n b += arr[--j]\n temp = 2\n }\n // console.log(a, b, temp)\n }\n if (a === b) ans += temp\n return ans\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tvar sum = new Array(N + 1);\r\n\t\tsum[0] = 0;\r\n\t\tfor(var i = 1; i <= N; i++){\r\n\t\t\tsum[i] = sum[i - 1] + list[i - 1];\r\n\t\t}\r\n\t\tvar right = 0;\r\n\t\tvar V = 0;\r\n\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\tright += list[i];\r\n\t\t\tV++;\r\n\t\t\tvar L = 0;\r\n\t\t\tvar R = i + 1;\r\n\t\t\tvar ok = false;\r\n\t\t\twhile(R - L > 1){\r\n\t\t\t\tvar C = Math.floor((R + L) / 2);\r\n\t\t\t\tif(sum[C] > right){\r\n\t\t\t\t\tR = C;\r\n\t\t\t\t}else if(sum[C] < right){\r\n\t\t\t\t\tL = C;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tL = C;\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput = Math.max(output, L + V);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \n\nconst calc = (n, A)=>{\n let ans = 0;\n let l = 0, ls = A[l]\n let r = n-1, rs = A[r];\n while (l {\r\n\tlines.push(input);\r\n});\r\n\r\nrl.on('close', () => {\r\n\t// (function() {\r\n\t// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n\tlet l = 0;\r\n\tlet t = +lines[l++];\r\n\tconst output = [];\r\n\tfor (let i = 0; i < t; i++) {\r\n\t\tconst n = +lines[l++];\r\n\t\tconst arr = lines[l++].trim().split(' ').map(parseInt);\r\n\t\toutput[i] = solve(n, arr);\r\n\t}\r\n\tconsole.log(output.join('\\n'));\r\n\t// })()\r\n});\r\n\r\nfunction solve(n, arr) {\r\n\tlet alice_index = 0;\r\n\tlet bob_index = arr.length - 1;\r\n\tlet bob = (alice = ans = 0);\r\n\twhile (alice_index <= bob_index) {\r\n\t\tif (alice <= bob) alice += arr[alice_index++];\r\n\t\telse bob += arr[bob_index--];\r\n\r\n\t\tif (alice == bob) ans = alice_index + arr.length - 1 - bob_index;\r\n\t}\r\n\treturn ans;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst lines = [];\r\nreadline.on('line', (input) => {\r\n lines.push(input);\r\n});\r\n\r\nreadline.on('close', () => {\r\n let lineIndex = 0;\r\n let repeat = +lines[lineIndex++];\r\n\r\n while (repeat--) {\r\n const candiesAmount = +lines[lineIndex++];\r\n const candies = lines[lineIndex++].trim().split(' ').map(parseInt);\r\n solve(candiesAmount, candies)\r\n }\r\n\r\n});\r\n\r\nfunction solve(len, candies) {\r\n let aliceIndex = 0,\r\n bobIndex = len - 1,\r\n alice = 0,\r\n bob = 0,\r\n ans = 0;\r\n\r\n while (aliceIndex <= bobIndex) {\r\n\r\n if (alice <= bob) {\r\n alice += candies[aliceIndex];\r\n ++aliceIndex;\r\n }\r\n else {\r\n bob += candies[bobIndex];\r\n --bobIndex;\r\n }\r\n\r\n if (alice == bob) ans = aliceIndex + 1 + len - bobIndex;\r\n }\r\n\r\n console.log(ans);\r\n}\r\n"}, {"source_code": "const solve = arr=>{\r\n let max = -1,alice = arr[0],bob = arr[arr.length-1],i=1,j = arr.length-1;\r\n while((i<=j)){\r\n if(alice===bob) max = (arr.length-j)+i; \r\n if(arr.length-i-j===0){\r\n if(alice<=bob) alice+=arr[i++];\r\n else bob+=arr[--j];\r\n }\r\n else{\r\n if(i>arr.length-j) bob+=arr[--j];\r\n else alice+=arr[i++];\r\n }\r\n }\r\n if(max===-1) return 0;\r\n return max;\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(arr));\r\n }\r\n}\r\nmain();"}], "src_uid": "90e448ed43ba9a0533ac7dc24f92a7f8"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tcount = {},\n\t\tmax = 1;\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\th = data[0], m = data[1], key = h+':'+m;\n\t\tif (count[key] === undefined) {\n\t\t\tcount[key] = 0;\n\t\t}\n\t\tmax = Math.max(max, ++count[key]);\n\t}\n\tprint(max);\n}\n\nmain();\n", "positive_code": [{"source_code": "var n=+readline();\nvar t=[];\nwhile(n--){\n\tt.push(readline());\n}\n\nvar ans={};\nt.forEach(function(v){\n\tif( ans[v] ){\n\t\tans[v]++;\n\t}else{\n\t\tans[v]=1;\n\t}\n});\nprint(Object.keys(ans).map(function(key){\n\treturn ans[key];\n}).sort(function(a,b){ return b-a;})[0] );"}, {"source_code": "var n = +readline(), time = [], a = [0], b = [1];\nfor(i = 0; i < n; i++){\n\ttime[i] = readline().split(\" \");\n\ttime[i] = +time[i][0] * 60 + +time[i][1];\n}\n\nfor(i = 0; i < time.length-1;){\n\tif(time[i] == time[i+1]){\n\t\tif(a.indexOf(time[i])+1){\n\t\t\tb[a.indexOf(time[i])]++;\n\t\t\ttime.splice(time.indexOf(time[i]),1);\n\t\t}\n\t\telse{\n\t\t\ta.push(time[i]);\n\t\t\tb.push(2);\n\t\t\ttime.splice(time.indexOf(time[i]),1);\n\t\t}\n\t}\n\telse{\n\t\ttime.splice(time.indexOf(time[i]),1);\n\t}\n}\n\nwrite( (b.length == 1) ? b[0] : b.sort(function(x,y){return y-x})[0] );"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar t = {};\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar c = readline();\n\t\tt[c] = t[c] ? t[c]+1 : 1;\n\t}\n\n\tprint(Math.max.apply(Math, Object.keys(t).map(function (i) { return t[i]; })));\n\n}).call(this);"}, {"source_code": "//String reverse\n/* TEST CASE\ninput\n4\n8 0\n8 10\n8 10\n8 45\noutput\n2\n\ninput\n3\n0 12\n10 11\n22 22\noutput\n1\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar maxCon = 1;\n\tvar con;\n\tvar prev = \"\", cur;\n\tfor (var i = 0; i < n; i++) {\n\t\tcur = readline();\n\t\tif (prev != cur) {\n\t\t\tcon = 1;\n\t\t\tprev = cur;\n\t\t} else {\n\t\t\tif (++con > maxCon) {\n\t\t\t\tmaxCon = con;\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(maxCon);\n}\n\nmain();"}, {"source_code": "var cos = readline();\nvar timeArr = new Array(cos);\nvar max = 1;\n\n\nfor(var i = 0; i < cos; i++)\n\ttimeArr[i] = readline().split(\" \");\nfor(var i = 0; i < cos; i++){\n\tvar j = i+1;\n\tvar m = 1;\n\twhile(j < cos && (timeArr[j][0] == timeArr[i][0]) && \n\t\t(timeArr[j][1] == timeArr[i][1])){\n\t\tm++;\n\t\tj++;\n\t}\n\tmax = (m > max) ? m : max;\n\ti = j-1;\n}\nprint(max);"}, {"source_code": "n=Number(readline())\nT={}\nfor (var i=0;imax){max=tt;}tt=0;}\n \npervious = trim;\t\n\nif((x == count - 1) && (tt>max)){max=tt;}\n}\n\n\n\nprint(max + 1);"}], "negative_code": [{"source_code": "var n = +readline(), time = [], a = [0], b = [1];\nfor(i = 0; i < n; i++){\n\ttime[i] = readline().split(\" \");\n\ttime[i] = +time[i][0] * 60 + +time[i][1];\n}\n\nfor(i = 0; i < time.length-2; i++){\n\tfor(j = i + 1; j < time.length-1; j++){\n\t\tif(time[i] == time[j]){\n\t\t\tif(a.indexOf(time[i])+1){\n\t\t\t\tb[a.indexOf(time[i])]++;\n\t\t\t\ttime.splice(time.indexOf(time[j]),1);\n\t\t\t\tj--;\n\t\t\t}\n\t\t\telse{\n\t\t\t\ta.push(time[i]);\n\t\t\t\tb.push(2);\n\t\t\t}\n\t\t}\n\t\telse if(time[i] == time[j-1]){\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nwrite( (b.length == 1) ? b[0] : b.sort(function(x,y){return y-x})[0] );"}, {"source_code": "var n = +readline(), time = [], a = [], b =[];\nfor(i = 0; i < n; i++){\n\ttime[i] = readline().split(\" \");\n\ttime[i] = +time[i][0] * 60 + +time[i][1];\n}\n\nfor(i = 0; i < n-1; i++){\n\tfor(j = i + 1; j < n; j++){\n\t\tif(time[i] == time[j]){\n\t\t\tif(a.indexOf(time[i])+1){\n\t\t\t\tb[a.indexOf(time[i])]++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\ta.push(time[i]);\n\t\t\t\tb.push(2);\n\t\t\t}\n\t\t}\n\t\telse if(time[i] == time[j-1]){\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nwrite(b.sort(function(x,y){return x-y})[0]);"}, {"source_code": "var n = +readline(), time = [], a = [], b =[1];\nfor(i = 0; i < n; i++){\n\ttime[i] = readline().split(\" \");\n\ttime[i] = +time[i][0] * 60 + +time[i][1];\n}\n\nfor(i = 0; i < n-1; i++){\n\tfor(j = i + 1; j < n; j++){\n\t\tif(time[i] == time[j]){\n\t\t\tif(a.indexOf(time[i])+1){\n\t\t\t\tb[a.indexOf(time[i])]++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\ta.push(time[i]);\n\t\t\t\tb.push(2);\n\t\t\t}\n\t\t}\n\t\telse if(time[i] == time[j-1]){\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nwrite( (b.length == 1) ? b[0] : b.sort(function(x,y){return x-y})[0] );"}, {"source_code": "var n = +readline(), time, counter = 1, working;\nfor(i = 0; i < n; i++){\n\ttime = readline().split(\" \");\n\ttime = +time[0] * 60 + +time[1];\n\n\tif((time == working) || (time == working - 1)){\n\t\tcounter++;\n\t}\n\n\tworking = time + 1;\n}\nwrite(counter);"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar p = [readline()];\n\tvar t;\n\tvar x = 1;\n\n\tfor (var i = 1; i < n; i++) {\n\t\tt = readline();\n\t\tif (p.indexOf(t) != -1) x++;\n\t\telse p.push(t);\n\t}\n\n\tprint(x);\n\n}).call(this);"}, {"source_code": "var cos = readline();\nvar timeArr = new Array(cos);\nvar max = 1;\n\n\nfor(var i = 0; i < cos; i++)\n\ttimeArr[i] = readline().split(\" \");\nprint(timeArr[0][0]);\nfor(var i = 0; i < cos; i++){\n\tvar j = i+1;\n\tvar m = 1;\n\twhile(j < cos && (timeArr[j][0] == timeArr[i][0]) && \n\t\t(timeArr[j][1] == timeArr[i][1])){\n\t\tm++;\n\t\tj++;\n\t}\n\tmax = (m > max) ? m : max;\n\ti = j-1;\n}\nprint(max);"}, {"source_code": "\t//2 //7 //7 //8 //8 //9\n // 2 7 8 9\n //+1 +1 max(7) 8 9 6>?max no 8>max yes\n\n\nvar r = readline();var clientime = \"\";var max=0;var calc=1;\n\nfor(var x = 0 ; x < r; x++)\n{\n\nvar input = readline().replace(\" \",\"\");\n\nif(clientime.includes(input)){if(input>=max){calc+=1;max=input;}}\nelse{clientime += input + \" \";}\n\n\n}\nprint(calc);"}, {"source_code": "var r = readline();\nvar res = \"\";\nvar cashers = 1;\nfor (var x=0;xmax){max=tt;tt=0;} }\n\n\npervious = trim;\t\n\nif((x == count - 1) && (tt>max)){max=tt;}\n}\n\n\n\nprint(max + 1);\n"}], "src_uid": "cfad2cb472e662e037f3415a84daca57"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [capacity1, capacity2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [swordCount, axeCount] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [w1, w2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let ans = 0;\n if (w1 > w2) {\n [w1, w2] = [w2, w1];\n [swordCount, axeCount] = [axeCount, swordCount];\n }\n\n for (let i = 0; i <= swordCount; i++) {\n if (i * w1 > capacity1) break;\n\n let firstPersonSwords = i;\n let secondPersonSwords = Math.min(swordCount - firstPersonSwords, Math.floor(capacity2 / w1));\n let remainingCapacityOfFirstPerson = capacity1 - firstPersonSwords * w1;\n let remainingCapacityOfSecondPerson = capacity2 - secondPersonSwords * w1;\n let firstPersonAxes = Math.min(axeCount, Math.floor(remainingCapacityOfFirstPerson / w2));\n let secondPersonAxes = Math.min(axeCount - firstPersonAxes, Math.floor(remainingCapacityOfSecondPerson / w2));\n ans = Math.max(ans, firstPersonSwords + firstPersonAxes + secondPersonSwords + secondPersonAxes);\n }\n console.log(ans);\n }\n}\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (var i=0; i parseInt(x));\n let [cs, cw] = readline().split(\" \").map(x => parseInt(x));\n let [s, w] = readline().split(\" \").map(x => parseInt(x));\n\n // let s be the lighter weapon\n if (s > w) {\n [s,w] = [w,s];\n [cs,cw] = [cw,cs];\n }\n\n let maxPS = Math.min(~~(p / s), cs);\n let ans = 0;\n for (let ps=0; ps<=maxPS; ps++) {\n let pw = Math.min(~~((p-ps*s)/w), cw);\n let fs = Math.min(~~(f / s), cs - ps);\n let fw = Math.min(~~((f-fs*s)/w), cw - pw);\n ans = Math.max(ans, ps + pw + fs + fw);\n }\n\n console.log(ans);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let [pCapacity, fCapacity] = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.weight);\n const { count: count1, weight: weight1 } = items[0];\n const { count: count2, weight: weight2 } = items[1];\n\n let best = 0;\n\n for (let pCount1 = 0; pCount1 <= count1; pCount1++) {\n let pWeight1 = pCount1 * weight1;\n if (pWeight1 > pCapacity) {\n break;\n }\n\n let pCount2 = Math.min(\n Math.floor((pCapacity - pWeight1) / weight2),\n count2\n );\n\n let fCount1 = Math.min(Math.floor(fCapacity / weight1), count1 - pCount1);\n let fWeight1 = fCount1 * weight1;\n\n let fCount2 = Math.min(\n Math.floor((fCapacity - fWeight1) / weight2),\n count2 - pCount2\n );\n best = Math.max(best, pCount1 + pCount2 + fCount1 + fCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', async _ => {\n inputString = inputString.split(/\\n/);\n try {\n await main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nasync function main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const [p, f] = readLine().split(/\\s/).map(Number)\n let [cntL, cntH] = readLine().split(/\\s/).map(Number)\n let [l, h] = readLine().split(/\\s/).map(Number)\n if (l > h) {\n [cntH, cntL] = [cntL, cntH]\n ;[h, l] = [l, h]\n }\n const min = Math.floor(p / l) + Math.floor(f / l)\n if (min <= cntL) {\n console.log(min)\n } else {\n let max = 0\n for (let lForP = 0; lForP <= cntL; lForP++) {\n const remainP = p - lForP * l\n if (remainP < 0) {\n break\n }\n const lForF = cntL - lForP\n const remainF = f - lForF * l\n if (remainF < 0) {\n continue\n }\n const hForP = Math.min(Math.floor(remainP / h), cntH)\n const hForF = Math.min(Math.floor(remainF / h), cntH - hForP)\n max = Math.max(max, lForP + lForF + hForP + hForF)\n }\n console.log(max)\n }\n }\n}\n\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [c1, c2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [cnt1, cnt2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [w1, w2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let count = 0;\n\n while ((c1 >= Math.min(w1, w2) || c2 >= Math.min(w1, w2)) && (cnt1 > 0 || cnt2 > 0)) {\n if (c1 >= c2) {\n if ((w1 <= w2 || cnt2 === 0) && cnt1 > 0) {\n c1 -= w1;\n cnt1--;\n } else {\n if (cnt2 > 0) {\n c1 -= w2;\n cnt2--;\n } else continue;\n }\n } else {\n if ((w1 <= w2 || cnt2 === 0) && cnt1 > 0) {\n c2 -= w1;\n cnt1--;\n } else {\n if (cnt2 > 0) {\n c2 -= w2;\n cnt2--;\n } else continue;\n }\n }\n count++;\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [c1, c2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [cnt1, cnt2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [w1, w2] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let count = 0;\n\n while ((c1 >= Math.min(w1, w2) || c2 >= Math.min(w1, w2)) && (cnt1 > 0 || cnt2 > 0)) {\n if (c1 >= c2) {\n if (w1 <= w2 && cnt1 > 0) {\n c1 -= w1;\n cnt1--;\n } else {\n c1 -= w2;\n cnt2--;\n }\n } else {\n if (w1 <= w2 && cnt1 > 0) {\n c2 -= w1;\n cnt1--;\n } else {\n c2 -= w2;\n cnt2--;\n }\n }\n count++;\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (var i=0; i parseInt(x));\n let [cs, cw] = readline().split(\" \").map(x => parseInt(x));\n let [s, w] = readline().split(\" \").map(x => parseInt(x));\n\n // let p be the weaker person\n [p,f] = [Math.min(p,f), Math.max(p,f)];\n // let s be the lighter weapon\n if (w < s) {\n [s,w] = [w,s];\n [cs,cw] = [cw,cs];\n }\n\n let [ps, pw] = fill(p, cs, cw, s, w)\n\n // repeat the above for f, with the remaining items\n cs-=ps;\n cw-=pw;\n let [fs, fw] = fill(f, cs, cw, s, w)\n\n console.log(ps+pw+fs+fw);\n }\n}\n\nfunction fill(p, cs, cw, s, w) {\n // let p take as much s as he can\n let ps = Math.min(Math.floor(p / s), cs);\n\n // let p take as much w as he can with the remaining\n let left = p - ps * s;\n let pw = Math.min(Math.floor(left / w), cw);\n\n // swap as many s to w within the capacity\n left = left - pw * w;\n let swap = Math.min(Math.floor(left/(w-s)), cw) || 0;\n\n return [ps-swap, pw+swap];\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let [pCapacity, fCapacity] = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.weight);\n const { count: count1, weight: weight1 } = items[0];\n const { count: count2, weight: weight2 } = items[1];\n\n let best = 0;\n\n for (let pCount1 = 0; pCount1 < items[0].count; pCount1++) {\n let pWeight1 = pCount1 * weight1;\n if (pWeight1 > pCapacity) {\n break;\n }\n\n let pCount2 = Math.min(\n Math.floor((pCapacity - pWeight1) / weight1),\n count1\n );\n\n let fCount1 = Math.min(Math.floor(fCapacity / weight1), count1 - pCount1);\n let fWeight1 = fCount1 * weight1;\n\n let fCount2 = Math.min(\n Math.floor((fCapacity - fWeight1) / weight2),\n count2 - pCount2\n );\n best = Math.max(best, pCount1 + pCount2 + fCount1 + fCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let capacities = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.count);\n\n let best = 0;\n\n for (let count = 0; count < items[0].count; count++) {\n let weight = count * items[0].weight;\n if (weight > capacities[0]) {\n break;\n }\n let otherCount = Math.min(\n Math.floor((capacities[0] - weight) / items[1].weight),\n items[1].count\n );\n\n let count2 = Math.min(\n Math.floor(capacities[1] / items[0].weight),\n items[0].count - count\n );\n let weight2 = count2 * items[0].weight;\n let otherCount2 = Math.min(\n Math.floor((capacities[1] - weight2) / items[1].weight),\n items[1].count - otherCount\n );\n best = Math.max(best, count + otherCount + count2 + otherCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let capacities = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.weight);\n\n let best = 0;\n\n for (let count = 0; count < items[0].count; count++) {\n let weight = count * items[0].weight;\n if (weight > capacities[0]) {\n break;\n }\n\n let otherCount = Math.min(\n Math.floor((capacities[0] - weight) / items[1].weight),\n items[1].count\n );\n\n let count2 = Math.min(\n Math.floor(capacities[1] / items[0].weight),\n items[0].count - count\n );\n let weight2 = count2 * items[0].weight;\n let otherCount2 = Math.min(\n Math.floor((capacities[1] - weight2) / items[1].weight),\n items[1].count - otherCount\n );\n best = Math.max(best, count + otherCount + count2 + otherCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let [pCapacity, fCapacity] = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.weight);\n const { count: count1, weight: weight1 } = items[0];\n const { count: count2, weight: weight2 } = items[1];\n\n let best = 0;\n\n for (let pCount1 = 0; pCount1 <= count1; pCount1++) {\n let pWeight1 = pCount1 * weight1;\n if (pWeight1 > pCapacity) {\n break;\n }\n\n let pCount2 = Math.min(\n Math.floor((pCapacity - pWeight1) / weight1),\n count1\n );\n\n let fCount1 = Math.min(Math.floor(fCapacity / weight1), count1 - pCount1);\n let fWeight1 = fCount1 * weight1;\n\n let fCount2 = Math.min(\n Math.floor((fCapacity - fWeight1) / weight2),\n count2 - pCount2\n );\n best = Math.max(best, pCount1 + pCount2 + fCount1 + fCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let capacities = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.weight - b.count);\n\n let best = 0;\n\n for (let count = 0; count < items[0].count; count++) {\n let weight = count * items[0].weight;\n if (weight > capacities[0]) {\n break;\n }\n\n let otherCount = Math.min(\n Math.floor((capacities[0] - weight) / items[1].weight),\n items[1].count\n );\n\n let count2 = Math.min(\n Math.floor(capacities[1] / items[0].weight),\n items[0].count - count\n );\n let weight2 = count2 * items[0].weight;\n let otherCount2 = Math.min(\n Math.floor((capacities[1] - weight2) / items[1].weight),\n items[1].count - otherCount\n );\n best = Math.max(best, count + otherCount + count2 + otherCount2);\n }\n\n console.log(best);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,\n output: process.stdout,\n});\n/** @type {Array} */\nconst lines = [];\n\nrl.on('line', (line) => lines.push(line));\n\nrl.on('close', task);\n\nfunction nextNumber() {\n return Number(lines.shift());\n}\nfunction nextNumbers() {\n return lines\n .shift()\n .split(' ')\n .map((x) => Number(x));\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction calc(capacity, weight, count) {\n return Math.min(Math.floor(capacity / weight), count);\n}\n\nfunction task() {\n let t = nextNumber();\n while (t--) {\n let capacities = nextNumbers();\n let counts = nextNumbers();\n let weights = nextNumbers();\n let items = [\n { count: counts[0], weight: weights[0], name: 'swords' },\n { count: counts[1], weight: weights[1], name: 'axes' },\n ];\n items.sort((a, b) => a.count - b.count);\n\n let best = 0;\n\n for (let count = 0; count < items[0].count; count++) {\n let weight = count * items[0].weight;\n if (weight > capacities[0]) {\n break;\n }\n\n let otherCount = Math.min(\n Math.floor((capacities[0] - weight) / items[1].weight),\n items[1].count\n );\n\n let count2 = Math.min(\n Math.floor(capacities[1] / items[0].weight),\n items[0].count - count\n );\n let weight2 = count2 * items[0].weight;\n let otherCount2 = Math.min(\n Math.floor((capacities[1] - weight2) / items[1].weight),\n items[1].count - otherCount\n );\n best = Math.max(best, count + otherCount + count2 + otherCount2);\n }\n\n console.log(best);\n }\n}\n"}], "src_uid": "ee32db8e7cdd9561d9215651ff8a262e"} {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar _loop_1 = function () {\r\n var n = readline().split(' ').map(function (v) { return +v; })[0];\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var len = n + 1;\r\n var t_1 = [];\r\n while (len) {\r\n t_1.push(Array(len + 1).fill(0));\r\n len >>= 1;\r\n }\r\n var sum = 0;\r\n var _loop_2 = function (i) {\r\n var v = a[i] + 1;\r\n var _loop_3 = function (l) {\r\n var f = v & 1 ? function () { sum += t_1[l][v]; } : function () { };\r\n v >>= 1;\r\n f();\r\n };\r\n for (var l = 0; l < t_1.length; l++) {\r\n _loop_3(l);\r\n }\r\n v = a[i];\r\n for (var l = 0; l < t_1.length; l++) {\r\n if (~v & 1) {\r\n t_1[l][v >> 1] += 1;\r\n }\r\n v >>= 1;\r\n }\r\n };\r\n for (var i = n; i--;) {\r\n _loop_2(i);\r\n }\r\n print(sum);\r\n};\r\nwhile (t--) {\r\n _loop_1();\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n const bst = new BinarySearchTree();\r\n for (let i = n - 1; i >= 0; i--) {\r\n const cur = a[i];\r\n res += bst.size() - bst.countGreaterThanEq(cur + 1);\r\n bst.insert(cur);\r\n }\r\n return res.toString();\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra().map(a=>a-1);\n // PROCESSING:\n let ans = 0;\n let cnt = {};\n let revA = new Array(n).fill(0);\n for (let i=0; i=i){\n cntLeft++;\n deductLeft[A[i-1]]++;\n }\n cntRight -= deductRight[i];\n if (revA[i-1]>=i){\n cntRight++;\n deductRight[revA[i-1]]++;\n }\n ans += cntLeft*cntRight;\n // maintain cnt of all from left bigger than i\n // maintain all from right lower than i\n }\n return ans;\n};\n "}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nlet F\nfunction inc(idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n\nfunction solve(n, arr) {\n const sorted = arr.map((x, i) => ({ x, i: i + 1 }))\n .sort((a, b) => {\n if (a.x === b.x) {\n return b.i - a.i\n } else {\n return a.x - b.x\n }\n })\n // console.log(sorted)\n F = Array(n + 5).fill(0) // a little larger in case\n let ans = 0\n for (let i = sorted.length - 1; i >= 0; i--) {\n const it = sorted[i]\n ans += sum(it.i)\n //\n inc(it.i, 1)\n }\n return ans\n}\n"}], "negative_code": [], "src_uid": "759b3909ccdf1b9ffd800bf0f65361cc"} {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , a ;\n len = this.s.length ;\n cn = 0 ;\n for( i = 0 ; i < len ; i++ ) {\n \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n \t\tcn++ ;\n \t}\n }\n if( cn % 2 != 0 ) {\n \tprint( 'impossible' );\n }\n else {\n \tres = '' ;\n \ta = 0 ;\n \tfor( i = 0 ; i < len ; i++ ) {\n\t \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n\t \t\ta++ ;\n\t \t\tif( a % 2 != 0 ) {\n\t \t\t\tif( this.s.charAt( i ) == '0' ) {\n\t\t\t\t\t\t\tres += \"0\" ;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tres += \"1\" ;\n\t\t\t\t\t\t}\n\t \t\t}\n\t \t\telse {\n\t \t\t\tif( this.s.charAt( i ) == '0' ) {\n\t\t\t\t\t\t\tres += \"1\" ;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tres += \"0\" ;\n\t\t\t\t\t\t}\n\t \t\t}\n\t \t}\n\t \telse {\n\t \t\tres += this.s.charAt( i ) ;\n\t \t}\n\t }\n \tprint( res );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.t = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n", "positive_code": [{"source_code": "function toi(x){return parseInt(x);}\nvar s0=readline();\nvar s1=readline();\nvar num=0;\nvar res=\"\";\nfor(var i=0;i= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , a ;\n len = this.s.length ;\n cn = 0 ;\n for( i = 0 ; i < len ; i++ ) {\n \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n \t\tcn++ ;\n \t}\n }\n if( cn % 2 != 0 ) {\n \tprint( 'impossible' );\n }\n else {\n \tres = '' ;\n \ta = 0 ;\n \tfor( i = 0 ; i < len ; i++ ) {\n\t \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n\t \t\ta++ ;\n\t \t\tif( a % 2 != 0 ) {\n\t \t\t\tres += '0' ;\n\t \t\t}\n\t \t\telse {\n\t \t\t\tres += '1' ;\n\t \t\t}\n\t \t}\n\t \telse {\n\t \t\tres += this.s.charAt( i ) ;\n\t \t}\n\t }\n \tprint( res );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.t = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , a ;\n len = this.s.length ;\n cn = 0 ;\n for( i = 0 ; i < len ; i++ ) {\n \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n \t\tcn++ ;\n \t}\n }\n if( cn % 2 != 0 ) {\n \tprint( 'impossible' );\n }\n else {\n \tres = '' ;\n \ta = 0 ;\n \tfor( i = 0 ; i < len ; i++ ) {\n\t \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n\t \t\ta++ ;\n\t \t\tif( a % 2 != 0 ) {\n\t \t\t\tres += '0' ;\n\t \t\t}\n\t \t\telse {\n\t \t\t\tres += '1' ;\n\t \t\t}\n\t \t}\n\t \telse {\n\t \t\tres += this.s.charAt( i ) ;\n\t \t}\n\t }\n \tprint( res );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.t = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\n'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len ;\n len = this.s.length ;\n cn = 0 ;\n for( i = 0 ; i < len ; i++ ) {\n \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n \t\tcn++ ;\n \t}\n }\n if( cn % 2 != 0 ) {\n \tprint( 'impossible' );\n }\n else {\n \tres = '' ;\n \ta = 0 ;\n \tfor( i = 0 ; i < len ; i++ ) {\n\t \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n\t \t\ta++ ;\n\t \t\tif( a <= Math.floor( cn / 2 ) ) {\n\t \t\t\tres += '0' ;\n\t \t\t}\n\t \t\telse {\n\t \t\t\tres += '1' ;\n\t \t\t}\n\t \t}\n\t \telse {\n\t \t\tres += this.s.charAt( i ) ;\n\t \t}\n\t }\n \tprint( res );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.t = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , a , b ;\n len = this.s.length ;\n cn = 0 ;\n for( i = 0 ; i < len ; i++ ) {\n \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n \t\tcn++ ;\n \t}\n }\n if( cn % 2 != 0 ) {\n \tprint( 'impossible' );\n }\n else {\n \tres = '' ;\n \ta = 0 ;\n \tb = Math.ceil( cn / 2 ) ;\n \tfor( i = 0 ; i < len ; i++ ) {\n\t \tif( this.s.charCodeAt( i ) != this.t.charCodeAt( i ) ) {\n\t \t\ta++ ;\n\t \t\tif( a <= b ) {\n\t \t\t\tres += '0' ;\n\t \t\t}\n\t \t\telse {\n\t \t\t\tres += '1' ;\n\t \t\t}\n\t \t}\n\t \telse {\n\t \t\tres += this.s.charAt( i ) ;\n\t \t}\n\t }\n \tprint( res );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n this.t = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "s = readline();\nt = readline();\ndiff = [];\nfor (var i = 0; i < s.length; i++) {\n if (s[i] !== t[i]) {\n diff.push(i);\n }\n}\nans = '';\nif (diff.length % 2 !== 0) {\n print('impossible');\n} else {\n for (var i = 0; i < diff.length / 2; i++) {\n for (var j = 0; j < s.length; j++) {\n if (j !== diff[i]) {\n ans += t[j];\n } else {\n ans += s[j];\n break;\n }\n }\n }\n print(ans);\n}\n"}], "src_uid": "2df181f2d1f4063a22fd2fa2d47eef92"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar n = parseInt(readline(), 10),\n given = tokenizeIntegers(readline()),\n desired = tokenizeIntegers(readline()),\n translate = {};\n for (var i = 0; i < n; ++i) {\n translate[desired[i]] = i;\n }\n for (var i = 0; i < n; ++i) {\n given[i] = translate[given[i]];\n }\n //print(given.join(' '));\n var left = 0, right = n-1,\n seen = {}, expect = 0,\n count = 0;\n while (left < right) {\n seen[given[left]] = true;\n //print('left = '+left+', expect = '+expect);\n if (seen[expect]) {\n if (given[left] == expect) {\n left++;\n }\n } else {\n while (left < right && given[right] != expect) {\n seen[given[right]] = true;\n right--;\n count++;\n //print('right = '+right);\n }\n if (left < right) {\n seen[given[right]] = true;\n right--;\n count++;\n //print('right = '+right);\n }\n }\n expect++;\n }\n print(count);\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar n = parseInt(readline(), 10),\n given = tokenizeIntegers(readline()),\n desired = tokenizeIntegers(readline()),\n translate = {};\n for (var i = 0; i < n; ++i) {\n translate[desired[i]] = i;\n }\n for (var i = 0; i < n; ++i) {\n given[i] = translate[given[i]];\n }\n for (i = 1; i < n; ++i) {\n if (given[i-1] > given[i]) {\n break;\n }\n }\n print(n-i);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar n = parseInt(readline(), 10),\n given = tokenizeIntegers(readline()),\n desired = tokenizeIntegers(readline()),\n translate = {};\n for (var i = 0; i < n; ++i) {\n translate[desired[i]] = i;\n }\n for (var i = 0; i < n; ++i) {\n given[i] = translate[given[i]];\n }\n //print(given.join(' '));\n var left = 0, right = n-1,\n seen = {}, expect = 0,\n count = 0;\n while (left < right) {\n seen[given[left]] = true;\n //print('left = '+left+', expect = '+expect);\n if (seen[expect]) {\n left++;\n } else {\n while (left < right && given[right] != expect) {\n seen[given[right]] = true;\n right--;\n count++;\n //print('right = '+right);\n }\n if (left < right) {\n seen[given[right]] = true;\n right--;\n count++;\n //print('right = '+right);\n }\n }\n expect++;\n }\n print(count);\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar n = parseInt(readline(), 10),\n given = tokenizeIntegers(readline()),\n desired = tokenizeIntegers(readline()),\n translate = {};\n for (var i = 0; i < n; ++i) {\n translate[desired[i]] = i;\n }\n for (var i = 0; i < n; ++i) {\n given[i] = translate[given[i]];\n }\n //print(given.join(' '));\n var left = 0, right = n-1,\n expect = 0, count = 0;\n while (left < right) {\n //print('left = '+left+', expect = '+expect);\n if (given[left] == expect) {\n left++;\n } else {\n while (left < right && given[right] != expect) {\n count++;\n right--;\n //print('right = '+right);\n }\n if (left < right) {\n count++;\n right--;\n //print('right = '+right);\n }\n }\n expect++;\n }\n print(count);\n}\n\nmain();\n"}], "src_uid": "a26e048eb9b18f87f1703d42e172f318"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar segmentNum = parseInt(readline());\n\tvar segments = [];\n\tfor (var i = 0; i < segmentNum; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tintegers.sort(function(a, b) {\n\t\t\treturn a-b;\n\t\t});\n\t\tsegments.push({ low: integers[0], high: integers[1] });\n\t}\n\n\tsegments.sort(function(a, b) {\n\t\tif (a.high != b.high) {\n\t\t\treturn a.high - b.high;\n\t\t}\n\t\treturn a.low - b.low;\n\t});\n\n\tvar nails = [segments[0].high];\n\tfor (var i = 1; i < segmentNum; i += 1) {\n\t\tif (segments[i].low <= nails[nails.length-1]) {\n\t\t\tcontinue;\n\t\t}\n\t\tnails.push(segments[i].high);\n\t}\n\n\tprint(nails.length);\n\tprint(nails.join(' '));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar segmentNum = parseInt(readline());\n\tvar segments = [];\n\tfor (var i = 0; i < segmentNum; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tintegers.sort(function(a, b) {\n\t\t\treturn a-b;\n\t\t});\n\t\tsegments.push({ low: integers[0], high: integers[1] });\n\t}\n\n\tsegments.sort(function(a, b) {\n\t\treturn a.high - b.high;\n\t});\n\n\tvar nails = [segments[0].high];\n\tfor (var i = 1; i < segmentNum; i += 1) {\n\t\tif (segments[i].low <= nails[nails.length-1]) {\n\t\t\tcontinue;\n\t\t}\n\t\tnails.push(segments[i].high);\n\t}\n\n\tprint(nails.length);\n\tprint(nails.join(' '));\n}\n\nmain();\n"}, {"source_code": "'use strict';\n\nvar findIntersection = function (segment1, segment2) { // segments at this function call are sorted \n // console.log('findIntersection');\n // console.log('segment1', segment1);\n // console.log('segment2', segment2);\n if (segment1.s == segment2.s && segment1.e == segment2.e) { // total intersection\n // console.log('here1');\n return segment1; \n } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e < segment2.e)) { // segment1 is contained\n // console.log('here2');\n return segment1;\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e <= segment2.e)) { // partial intersection\n // console.log('here3');\n return {s: segment2.s, e: segment1.e};\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) { // segment2 is contained\n // console.log('here4');\n return segment2;\n } else {\n // console.log('here5');\n return null; // no intersection\n }\n \n}\n\nvar sortSegments = function (segmentA, segmentB) {\n if (segmentA.s < segmentB.s) {\n return -1;\n } else if (segmentA.s > segmentB.s) {\n return 1;\n } \n\n if (segmentA.e < segmentB.e) {\n return -1;\n } else if (segmentA.e > segmentB.e) {\n return 1;\n }\n\n return 0;\n}\n\nvar getnails = function (sortedSegments, lastIntersection, currentId, nails) {\n if (currentId == sortedSegments.length) {\n nails.push(lastIntersection.e);\n console.log(nails.length);\n console.log(nails.join(' '));\n return; \n }\n\n var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);\n if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment\n // console.log('pushing', lastIntersection.e);\n nails.push(lastIntersection.e);\n getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);\n } else {\n getnails(sortedSegments, foundIntersection, ++currentId, nails);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nvar allSegments = [];\nvar formSegments = function (max) {\n var num;\n for (var i = 0; i < max; i++) {\n num = readline().split(\" \").map(x => parseInt(x));\n if (num[0] < num[1]) {\n allSegments.push({s: num[0], e: num[1]})\n } else {\n allSegments.push({s: num[1], e: num[0]})\n }\n \n }\n}\n\nfunction main() {\n const x = readline();\n formSegments(x);\n // console.log(allSegments);\n allSegments.sort(sortSegments);\n // console.log(allSegments);\n var nails = [];\n getnails(allSegments, allSegments[0], 1, nails);\n}"}], "negative_code": [{"source_code": "'use strict';\n\nvar findIntersection = function (segment1, segment2) { // segments at this function call are sorted \n // console.log('findIntersection');\n // console.log('segment1', segment1);\n // console.log('segment2', segment2);\n if (segment1.s == segment2.s && segment1.e == segment2.e) { // total intersection\n // console.log('here1');\n return segment1; \n } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e < segment2.e)) { // segment1 is contained\n // console.log('here2');\n return segment1;\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e < segment2.e)) { // partial intersection\n // console.log('here3');\n return {s: segment2.s, e: segment1.e};\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) { // segment2 is contained\n // console.log('here4');\n return segment2;\n } else {\n // console.log('here5');\n return null; // no intersection\n }\n \n}\n\nvar sortSegments = function (segmentA, segmentB) {\n if (segmentA.s < segmentB.s) {\n return -1;\n } else if (segmentA.s > segmentB.s) {\n return 1;\n } \n\n if (segmentA.e < segmentB.e) {\n return -1;\n } else if (segmentA.e > segmentB.e) {\n return 1;\n }\n\n return 0;\n}\n\nvar getnails = function (sortedSegments, lastIntersection, currentId, nails) {\n if (currentId == sortedSegments.length) {\n nails.push(lastIntersection.e);\n console.log(nails.length);\n console.log(nails.join(' '));\n return; \n }\n\n var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);\n if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment\n nails.push(lastIntersection.e);\n getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);\n } else {\n getnails(sortedSegments, foundIntersection, ++currentId, nails);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nvar allSegments = [];\nvar formSegments = function (max) {\n var num;\n for (var i = 0; i < max; i++) {\n num = readline().split(\" \").map(x => parseInt(x));\n if (num[0] < num[1]) {\n allSegments.push({s: num[0], e: num[1]})\n } else {\n allSegments.push({s: num[1], e: num[0]})\n }\n \n }\n}\n\nfunction main() {\n const x = readline();\n formSegments(x);\n // console.log(allSegments);\n allSegments.sort(sortSegments);\n // console.log(allSegments);\n var nails = [];\n getnails(allSegments, allSegments[0], 1, nails);\n}"}, {"source_code": "'use strict';\n\nvar findIntersection = function (segment1, segment2) { // segments at this function call are sorted \n // console.log('findIntersection');\n // console.log('segment1', segment1);\n // console.log('segment2', segment2);\n if (segment1.s == segment2.s && segment1.e == segment2.e) { // total intersection\n // console.log('here1');\n return segment1; \n } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e < segment2.e)) { // segment1 is contained\n // console.log('here2');\n return segment1;\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e <= segment2.e)) { // partial intersection\n // console.log('here3');\n return {s: segment2.s, e: segment1.e};\n } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) { // segment2 is contained\n // console.log('here4');\n return segment2;\n } else {\n // console.log('here5');\n return null; // no intersection\n }\n \n}\n\nvar sortSegments = function (segmentA, segmentB) {\n if (segmentA.s < segmentB.s) {\n return -1;\n } else if (segmentA.s > segmentB.s) {\n return 1;\n } \n\n if (segmentA.e < segmentB.e) {\n return -1;\n } else if (segmentA.e > segmentB.e) {\n return 1;\n }\n\n return 0;\n}\n\nvar getnails = function (sortedSegments, lastIntersection, currentId, nails) {\n if (currentId == sortedSegments.length) {\n nails.push(lastIntersection.e);\n console.log(nails.length);\n console.log(nails.join(' '));\n return; \n }\n\n var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);\n if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment\n // console.log('pushing', lastIntersection.e);\n nails.push(lastIntersection.e);\n getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);\n } else {\n getnails(sortedSegments, foundIntersection, ++currentId, nails);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nvar allSegments = [];\nvar formSegments = function (max) {\n var num;\n for (var i = 0; i < max; i++) {\n num = readline().split(\" \").map(x => parseInt(x));\n if (num[0] < num[1]) {\n allSegments.push({s: num[0], e: num[1]})\n } else {\n allSegments.push({s: num[1], e: num[0]})\n }\n \n }\n}\n\nfunction main() {\n const x = readline();\n formSegments(x);\n // console.log(allSegments);\n allSegments.sort(sortSegments);\n // console.log(allSegments);\n var nails = [];\n getnails(allSegments, allSegments[0], 1, nails);\n}"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar segmentNum = parseInt(readline());\n\tvar segments = [];\n\tfor (var i = 0; i < segmentNum; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tintegers.sort();\n\t\tsegments.push({ low: integers[0], high: integers[1] });\n\t}\n\n\tsegments.sort(function(a, b) {\n\t\tif (a.high != b.high) {\n\t\t\treturn a.high - b.high;\n\t\t}\n\t\treturn a.low - b.low;\n\t});\n\n\tvar nails = [segments[0].high];\n\tfor (var i = 1; i < segmentNum; i += 1) {\n\t\tif (segments[i].low <= nails[nails.length-1]) {\n\t\t\tcontinue;\n\t\t}\n\t\tnails.push(segments[i].high);\n\t}\n\n\tprint(nails.length);\n\tprint(nails.join(' '));\n}\n\nmain();\n"}], "src_uid": "60558a2148f7c9741bb310412f655ee4"} {"source_code": "var nk = readline().split(' ').map(x => Number(x))\n\nvar n = nk[0]\nvar k = nk[1]\n\nvar cs = readline().split(' ').map(x => Number(x))\n\nvar k1 = k + 1\n\nvar pos = new Array(k1 * k1)\n\npos.fill(false)\n\npos[0] = true\n\n\nfor (var c = 0; c < n; c++) {\n for (var v = k; v >= 0; v--) {\n for (var x = k; x >= 0; x--) {\n \n var curr = pos[k1 * v + x]\n \n var vc = v - cs[c]\n var xc = x - cs[c]\n \n if (vc >= 0) {\n curr = curr || pos[k1 * vc + x]\n }\n \n if (vc >= 0 && xc >= 0) {\n curr = curr || pos[k1 * vc + xc]\n }\n \n pos[k1 * v + x] = curr\n }\n }\n}\n\nvar count = 0\nvar answers = []\n\nfor (var i = 0; i < k1; i++) {\n if (pos[k1 * k + i]) {\n count++\n answers.push(i)\n }\n}\n\nprint(String(count))\n\nprint(answers.map(x => String(x)).join(' '))", "positive_code": [{"source_code": "var nk = readline().split(' ').map(x => Number(x))\n\nn = nk[0]\nk = nk[1]\n\nvar cs = readline().split(' ').map(x => Number(x))\n\nvar k1 = k + 1\n\nvar pos = new Array(k1 * k1)\n\npos.fill(false)\n\npos[0] = true\n\n\nfor (var c = 0; c < n; c++) {\n for (var v = k; v >= 0; v--) {\n for (var x = k; x >= 0; x--) {\n \n var curr = pos[k1 * v + x]\n \n var vc = v - cs[c]\n var xc = x - cs[c]\n \n if (vc >= 0) {\n curr = curr || pos[k1 * vc + x]\n }\n \n if (vc >= 0 && xc >= 0) {\n curr = curr || pos[k1 * vc + xc]\n }\n \n pos[k1 * v + x] = curr\n }\n }\n}\n\nvar count = 0\nvar answers = []\n\nfor (var i = 0; i < k1; i++) {\n if (pos[k1 * k + i]) {\n count++\n answers.push(i)\n }\n}\n\nprint(String(count))\n\nprint(answers.map(x => String(x)).join(' '))"}], "negative_code": [], "src_uid": "db4775339de9122f1ae0c047fd39220f"} {"source_code": "'use strict';\n\nmain();\n\nfunction main() {\n const strLen = parseInt(readline());\n const str = readline();\n const numberOfN = (str.match(new RegExp('n', 'g')) || []).length;\n const numberOfZ = (str.match(new RegExp('z', 'g')) || []).length;\n\n print('1 '.repeat(numberOfN) + '0 '.repeat(numberOfZ));\n}", "positive_code": [{"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length - zerosCount*4) / 3;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nwrite(binary.join(' '))\n"}, {"source_code": "(function() {\n const n=readline().toString('ascii').trim();\n const p=readline().toString('ascii').trim().split('');\n\n var s1=p.filter(a=>a=='n').map((a)=> '1');\n var s0=p.filter(a=>a=='z').map((a)=> '0');\n write(s1.concat(s0).join(\" \"));\n}());"}, {"source_code": "var k = +readline();\nvar str = readline();\nvar z = 0;\nvar n = 0;\nfor(i = 0; i < k ; i++){\n if (str[i] == 'z') z++;\n if (str[i] == 'n') n++;\n}\nvar result = [];\nfor(i = 0; i < n; i++){\n result.push(1);\n}\nfor(i = 0; i < z; i++){\n result.push(0);\n}\nprint(result.join(\" \"));"}, {"source_code": "var n = readline();\nvar l = readline();\n \nvar max = \"\";\nfor (var i=0; i {\n lines.push(input);\n counter++;\n\n if (counter == 2){\n var string = lines[1];\n var ones = 0, zeros = 0;\n\n for (let i = 0; i < string.length; i++){\n if (string[i] == \"n\")\n ones++;\n else\n if (string[i] == \"z\")\n zeros++;\n }\n\n var result = \"\";\n\n for (let i = 0; i < ones; i++)\n result += \"1 \";\n\n for (let i = 0; i < zeros; i++)\n result += \"0 \";\n\n console.log(result);\n\n process.exit(0);\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num, str, binary = '';\n\nrl.on('line', n => {\n !num ? num = n : str = n;\n if (num && str) {\n while (str.includes('n')) {\n binary += '1 ';\n ['o', 'n', 'e'].forEach(letter => str = str.replace(letter, ''));\n }\n while (str.includes('z')) {\n binary += '0 ';\n ['z', 'e', 'r', 'o'].forEach(letter => str = str.replace(letter, ''));\n }\n console.log(binary.trim());\n rl.close();\n } \n});"}, {"source_code": "process.stdin.setEncoding('utf8');\n\nlet input = '';\n\nprocess.stdin.on('data', (chunk) => {\n if (chunk !== null) {\n input += chunk;\n }\n});\n\nprocess.stdin.on('end', () => {\n input.trim();\n input = input.split('\\n');\n\n let chars = input[1].split('');\n let binaryNotation = [];\n\n chars.forEach(char => {\n if (char == 'r') binaryNotation.push(0);\n if (char == 'n') binaryNotation.push(1);\n });\n\n binaryNotation.sort((a, b) => b - a);\n\n console.log(binaryNotation.join(' '));\n process.exit(0);\n})"}, {"source_code": "process.stdin.setEncoding('utf8');\n\nvar allinput = \"\";\nprocess.stdin.on('data', (chunk) => {\n if (chunk !== null) {\n allinput += chunk;\n }\n});\n\nprocess.stdin.on('end', () => {\n allinput.trim();\n allinput = allinput.split(/\\s+/);\n let chars = allinput[1].split('');\n let binaryNotation = [];\n\n chars.forEach(char => {\n if (char == 'r') binaryNotation.push(0);\n if (char == 'n') binaryNotation.push(1);\n });\n\n binaryNotation.sort((a, b) => b - a);\n\n process.stdout.write(binaryNotation.join(' ') + '\\n');\n process.exit(0);\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\"\nprocess.stdin.on('data', function(chunk) {\n arr += chunk\n});\n\nprocess.stdin.on('end', () => {\n arr = arr.split(\"\\n\")\n const letters = arr[1]\n let countR = 0, countN = 0\n for(let i = 0, len = arr[0]; i < len; i++) {\n if(letters[i] == 'n') countN ++\n else if(letters[i] == 'r') countR ++\n }\n \n for(let i = 0; i < countN; i++){\n process.stdout.write('1 ')\n }\n \n for(let i = 0; i < countR; i++){\n process.stdout.write('0 ')\n }\n console.log()\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var s = next();\n var z = 0;\n var o = 0;\n var output = [];\n for(var i = 0; i < N; i++){\n if(s[i] == \"z\"){\n z++;\n }\n if(s[i] == \"n\"){\n o++;\n }\n }\n for(var i = 0; i < o; i++){\n output.push(1);\n }\n for(var i = 0; i < z; i++){\n output.push(0);\n }\n myout(myconv(output, 8));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const obj = {};\n\n for (let i = 0; i < str.length; i++) {\n obj[str[i]] = obj[str[i]] ? obj[str[i]] + 1 : 1;\n }\n\n const ans = [];\n\n for (let i = 0; i < obj['n']; i++) {\n ans.push(1);\n }\n\n for (let i = 0; i < obj['z']; i++) {\n ans.push(0);\n }\n\n console.log(ans.join(' '));\n\n c++;\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const line = input[1];\n\n let lN = 0, lZ = 0, lO = 0, lR = 0, lE = 0;\n for (let i = 0; i < line.length; i += 1)\n if (line[i] === 'e') lE += 1;\n else if (line[i] === 'r') lR += 1;\n else if (line[i] === 'z') lZ += 1;\n else if (line[i] === 'o') lO += 1;\n else lN += 1;\n\n let min = Math.min(lN, lO, lE);\n let cntOne = min;\n lN -= min; lO -= min; lE -= min;\n\n let cntZero = Math.min(lZ, lE, lR, lO);\n const answer = [];\n for (let i = 0; i < cntOne; i += 1) answer.push(1);\n for (let i = 0; i < cntZero; i += 1) answer.push(0);\n\n\n console.log(answer.join(' '));\n}); "}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function(line){\n var param = line.split(\"\\n\");\n var n = (param[0].match(/n/g) || []).length;\n var z = (param[0].match(/z/g) || []).length;\n var result='';\n for (let i=0; i -1){\n str = str.replace(\"r\", \"\");\n if (!zero){\n zero+=\"0\";\n } else {\n zero+=\" 0\";\n }\n\n }\n if (str.indexOf(\"n\") > -1){\n str = str.replace(\"n\", \"\");\n if (!one){\n one+=\"1\";\n } else {\n one+=\" 1\";\n }\n }\n\n}\nif (one){\nwrite(one + \" \" + zero);\n} else {\n write(zero)\n}"}, {"source_code": "//http://codeforces.com/problemset/problem/1220/A\n\nvar n = readline();\nvar l = readline();\n\nvar max = \"\";\nfor (var i=0; i {\n let input = process.stdin.read();\n input = input.trim();\n input = input.split(/\\s+/);\n \n if (input !== null) {\n let chars = input[1].split('');\n let binaryNotation = [];\n \n chars.forEach(char => {\n if (char == 'r') binaryNotation.push(0);\n if (char == 'n') binaryNotation.push(1);\n });\n \n binaryNotation.sort((a, b) => b - a);\n \n process.stdout.write(binaryNotation.join(' ') + '\\n');\n process.exit(0);\n }\n});"}, {"source_code": "process.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', () => {\n let input = process.stdin.read();\n input = input.trim();\n input = input.split('\\n');\n\n if (input !== null) {\n let chars = input[1].split('');\n let binaryNotation = [];\n\n chars.forEach(char => {\n if (char == 'r') binaryNotation.push(0);\n if (char == 'n') binaryNotation.push(1);\n });\n\n binaryNotation.sort((a, b) => b - a);\n\n process.stdout.write(binaryNotation.join(' ') + '\\n');\n process.exit(0);\n }\n});"}, {"source_code": "process.stdin.setEncoding('utf8');\n\nvar allinput = \"\";\nprocess.stdin.on('readable', () => {\n var input = process.stdin.read();\n if (input !== null) {\n allinput += input;\n }\n});\n\nprocess.stdin.on('end', () => {\n allinput.trim();\n allinput = allinput.split(/\\s+/);\n let chars = allinput[0].split('');\n let binaryNotation = [];\n\n chars.forEach(char => {\n if (char == 'r') binaryNotation.push(0);\n if (char == 'n') binaryNotation.push(1);\n });\n\n binaryNotation.sort((a, b) => b - a);\n\n process.stdout.write(binaryNotation.join(' ') + '\\n');\n process.exit(0);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const line = input[1];\n\n let lN = 0, lZ = 0, lO = 0, lR = 0, lE = 0;\n for (let i = 0; i < line.length; i += 1)\n if (line[i] === 'e') lE += 1;\n else if (line[i] === 'r') lR += 1;\n else if (line[i] === 'z') lZ += 1;\n else if (line[i] === 'o') lO += 1;\n else lN += 1;\n\n let min = Math.min(lN, lO, lE);\n let cntOne = min;\n lN -= min; lO -= min; lE -= min;\n\n let cntZero = Math.min(lZ, lE, lR, lO);\n const answer = [];\n for (let i = 0; i < cntOne; i += 1) answer.push(1);\n if (answer.length === 0) answer.push(0);\n else {\n for (let i = 0; i < cntZero; i += 1) answer.push(0);\n }\n\n console.log(answer.join(' '));\n}); "}, {"source_code": "var n = Number(readline());\nvar str = readline();\nvar mas = [];\nfor (var i = 0; i < n; i++)\n{\n\tif (str[i] == 'n')\n\t\tmas.push(1);\n\telse if (str[i] == 'z')\n\t\tmas.push(0);\n\t\n}\nprint(mas.sort(function(a, b){return b - a}));"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nif (parseInt(binary.join('')) === 0)\n write('0')\nelse\n write(binary.join(' '))\n"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nwrite(parseInt(binary.join('')));"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nwrite(binary.join(' '))\n"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nwrite(binary.join(''));"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n// var letters = 'zerooneone'\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\n// console.log(binary)\nbinary.forEach(function(note) {\n write(note);\n})\n"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = letters.length - zerosCount*4;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nwrite(binary.join(' '))\n"}, {"source_code": "var charsCount = readline();\nvar letters = readline();\n\nvar countOfLetterZ = (letters.match(/z/g) || []).length;\n\nvar zerosCount = countOfLetterZ;\nvar onesCount = (letters.length / 4) - zerosCount;\n\nvar binary = [];\n\nfor (var i = 0; i < onesCount; i++) {\n binary.push('1')\n}\n\nfor (var i = 0; i < zerosCount; i++) {\n binary.push('0')\n}\n\nbinary.forEach(function(note) {\n write(note)\n});"}], "src_uid": "5e5dbd70c7fcedf0f965aed5bafeb06c"} {"source_code": "input = readline().split(' ');\nn = parseInt(input[0]);\ntotalVolume = parseInt(input[1]);\n\nbla1 = [];\nbla2 = [];\n\nfor(i = 0; i b2.cap - b1.cap);\nbla2.sort((b1, b2) => b2.cap - b1.cap);\n\nfor(i=1; i best) best = current, bestn = i;\n}\n\nprint(best);\n\nnumbers = \"\";\ncomplement = totalVolume - bestn*2;\nfor(i=1; i<=bestn; i++) numbers += bla2[i].id+' ';\nfor(i=1; i<=Math.min(complement, bla1.length-1); i++) numbers += bla1[i].id+' ';\n\nprint(numbers);", "positive_code": [{"source_code": "var n,v;\nvar boat1=[];\nvar boat2=[];\nfunction main()\n{\n var i;\n var cnt1=0,cnt2=0;\n tmp=readline().split(\" \");\n n=Number(tmp[0]);v=Number(tmp[1]);\n for(i=1;i<=n;i++)\n {\n tmp=readline().split(\" \");\n tmp[0]=parseInt(tmp[0]);tmp[1]=parseInt(tmp[1]);\n if(tmp[0]==1) boat1[++cnt1]=[i,tmp[1]];\n else boat2[++cnt2]=[i,tmp[1]];\n }\n boat1[0]=[1000000,1000000];boat2[0]=[1000000,1000000];\n boat1.sort(function cmp(a,b){return b[1]-a[1];});\n boat2.sort(function cmp(a,b){return b[1]-a[1];});\n/*\n print(\"----------------------------------------------\");\n for(i=1;i<=cnt1;i++) print(boat1[i][1]);\n print(\"----------------------------------------------\");\n*/\n for(i=2;i<=cnt1;i++) boat1[i][1]+=boat1[i-1][1];\n for(i=2;i<=cnt2;i++) boat2[i][1]+=boat2[i-1][1];\n/*\n print(\"-------------------boat1--------------------------\");\n for(i=1;i<=cnt1;i++) print(boat1[i][1]);\n print(\"----------------------------------------------\");\n print(\"-------------------boat2-------------------------\");\n for(i=1;i<=cnt2;i++) print(boat2[i][1]);\n print(\"----------------------------------------------\");\n*/\n var ans=-1;\n var index1,index2;\n boat1[0]=[0,0];\n boat2[0]=[0,0];\n for(i=0;i<=cnt2;i++)\n {\n if(i*2>v) continue; \n var tmp1=(v-2*i<=cnt1?v-2*i:cnt1);\n var tmp2=parseInt(boat2[i][1])+parseInt(boat1[tmp1][1]);\n if(tmp2>ans)\n {\n index1=tmp1;index2=i;\n ans=tmp2;\n }\n }\n print(ans);\n var xh=new String();\n for(i=1;i<=index1;i++)\n {\n if(i!=1) xh+=\" \"; \n xh+=boat1[i][0];\n }\n for(i=1;i<=index2;i++)\n {\n if(xh!=\"\") xh+=\" \";\n xh+=boat2[i][0];\n }\n print(xh);\n}\nmain();"}, {"source_code": "/**\n * fill truck with max density vehicles first\n */\n\nvar input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\nvar vehicles = [];\n\nfor (var i = 1; i < numOfVehicles + 1; i++) {\n input = readline().split(' ');\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n var type = parseInt(input[0]);\n var capacity = parseInt(input[1]);\n vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);\n}\n\n// sort vehicles by density (capacity / volume)\nvehicles.sort(function(a, b) {\n return b[3] - a[3];\n});\n\nvar lVeh = [];\nvar lVol = 0;\nvar lCap = 0;\nvar lastKayak = null;\n\nvar i = 0;\nwhile (truckVolume > (lVol + 3) && i < vehicles.length) {\n var nextVeh = vehicles[i++];\n lVeh.push(nextVeh[2]);\n lVol += nextVeh[0];\n lCap += nextVeh[1];\n if (nextVeh[0] == 1) {\n lastKayak = nextVeh;\n }\n}\n\nif (i < vehicles.length) {\n vehicles = vehicles.slice(i);\n} else {\n vehicles = [];\n}\n\n// remove the last added kayak and solve as set\nif (lastKayak !== null) {\n lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);\n lVol -= lastKayak[0]; // always 1\n lCap -= lastKayak[1];\n vehicles.unshift(lastKayak); // put back into vehicles list\n}\n\nvar maxCap = lCap;\nvar maxCapVeh = lVeh.slice();\n\ncheckCapacity(lVeh, lVol, lCap, 0);\n\nprint(maxCap);\nprint(maxCapVeh.join(' '));\n\n// ----------------------------------------------------------------------------\n\n// loaded vehicles, loaded volume, loaded capacity\nfunction checkCapacity(loadedVeh, loadedVol, loadedCap, i) {\n // print('@', loadedVeh, loadedVol, loadedCap, i);\n var type = vehicles[i][0];\n var cap = vehicles[i][1];\n var veh = vehicles[i][2];\n\n var newLoadedVol = loadedVol + type;\n var newLoadedCap = loadedCap + cap;\n var newLoadedVeh = loadedVeh.slice();\n newLoadedVeh.push(veh);\n\n if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {\n maxCap = newLoadedCap;\n maxCapVeh = newLoadedVeh;\n }\n\n if (i < vehicles.length - 1 && i < 5) {\n // including\n if (newLoadedVol < truckVolume) {\n checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);\n }\n\n // not including\n if (loadedVol < truckVolume) {\n checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);\n }\n }\n}\n"}, {"source_code": "\nvar line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar v = parseInt(line[1]);\n\nvar k = [];\nvar c = [];\nfor(var i=0;i cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[i-1]){\n\t//try{\n\t\tif(k[i-2] && c[j] && k[i-2].v + k[i-1].v < c[j].v){\n\t\t\tlist [ list.indexOf( k[i-2].i ) ] = '';\n\t\t\tav -= k[i-2].v;\n\n\t\t\tlist.push(c[j].i);\n\t\t\tav += c[j].v;\n\t\t}else{\n\t\t\tav += k[i-1].v;\n\t\t\tlist.push(k[i-1].i);\n\t\t}\n\t// }catch(e){\n\t// \tprint(i-1]);\n\t// }\n\t\n\t\n}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\nif( v > co*2 && k[i-1]){\n\tav += k[i-1].v;\n\tlist.push(k[i-1].i);\n}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\nif( v > co*2 && k[i-1]){\n\tav += k[i-1].v;\n\tlist.push(k[i-1].i);\n}\n\nif( v > co*2 && k[i-2] && c[j] && k[i-2].v cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[i-1]){\n\ttry{\n\t\tif(k[i-2] && k[i-2].v+k[i-1].v co*2 && k[i-2] && c[j] && k[i-2].v cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[--i]){\n\tav += k[i].v;\n\tlist.push(k[i].i);\n}\nprint(av);\nprint(list.join(' '));"}, {"source_code": "\nvar line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar v = parseInt(line[1]);\n\nvar k = [];\nvar c = [];\nfor(var i=0;i cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[--i]){\n\tav += k[i].v;\n\tlist.push(k[i].i);\n}\nprint(av);\nprint(list.join(' '));"}, {"source_code": "\nvar line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar v = parseInt(line[1]);\n\nvar k = [];\nvar c = [];\nfor(var i=0;i cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[i-1]){\n\ttry{\n\t\tif(k[i-2] && k[i-2].v + (k[i-1].v) co*2 && k[i-2] && c[j] && k[i-2].v cv){\n\t\tav += kv;\n\t\tlist.push(k[i].i, k[i-1].i);\n\t\ti += 2;\n\t}else{\n\t\tav += cv;\n\t\tlist.push(c[j].i);\n\t\tj++;\n\t}\n}\n\nif( v > co*2 && k[i-1]){\n\ttry{\n\t\tif(k[i-2] && k[i-2].v+k[i-1].v co*2 && k[i-2] && c[j] && k[i-2].v 2) {\n var bps = pss.pop()\n if (!bps) break\n bpss.push([bps[3]])\n m -= bps[2]\n gp += bps[1]\n}\n\nif (m == 1 && pss.length) {\n while ((bps = pss.pop()) && bps[2] != 1) {}\n if (bps) {\n bpss.push([bps[3]])\n gp += bps[1]\n }\n} else if (m == 2 && pss.length) {\n var tl = []\n var c\n while ((bps = pss.pop()) && !(tl.length == 2 && c)) {\n if (bps[2] == 2) {c = bps}\n else {tl.push(bps)}\n }\n if (!c) {\n [].push.apply(bpss, tl.map(function (l) {return l[3]}))\n gp += (tl[0] ? tl[0][1] : 0) + (tl[1] ? tl[1][1] : 0)\n } else if (c || !tl.length) {\n bpss.push(c[3])\n gp += c[1]\n } else if (c && tl.length == 1) {\n var ps = c[1] >= tl[0][1] ? c : tl[0]\n bpss.push(ps[3])\n gp += ps[1]\n } else {\n ps = c[1] >= tl[0][1] + tl[1][1] ? [c] : tl\n ;[].push.apply(bpss, ps.map(function (s) {return s[3]}))\n gp += ps.reduce(function (r, s) {return r + s[3]}, 0)\n }\n}\n\nprint(gp)\nprint(bpss.sort(function (a, b) {return a - b}).join('\\n'))"}, {"source_code": "readline = readline || ''\nwrite = write || ''\nprint = print || ''\n\nvar line = readline().split(' ')\nvar nps = +line[0]\nvar m = +line[1]\n\nvar pss = []\nfor (var i = 0; i < nps; i++) {\n line = readline()\n line = line.split(' ')\n pss.push([line[1] / line[0], +line[1], +line[0], i + 1])\n}\n\npss.sort(function (a, b) {\n return a[0] - b[0]\n})\n\nvar bpss = []\nvar gp = 0\nwhile (m > 2) {\n var bps = pss.pop()\n if (!bps) break\n bpss.push([bps[3]])\n m -= bps[2]\n gp += bps[1]\n}\n\nif (m == 1 && pss.length) {\n while ((bps = pss.pop()) && bps[2] != 1) {}\n if (bps) {\n bpss.push([bps[3]])\n gp += bps[1]\n }\n} else if (m == 2 && pss.length) {\n var tl = []\n var c\n while ((bps = pss.pop()) && !(tl.length == 2 && c)) {\n if (bps[2] == 2) {c = bps}\n else {tl.push(bps)}\n }\n if (!c) {\n [].push.apply(bpss, tl.map(function (l) {return l[3]}))\n gp += (tl[0] ? tl[0][1] : 0) + (tl[1] ? tl[1][1] : 0)\n } else if (c && !tl.length) {\n bpss.push(c[3])\n gp += c[1]\n } else if (c && tl.length == 1) {\n var ps = c[1] >= tl[0][1] ? c : tl[0]\n bpss.push(ps[3])\n gp += ps[1]\n } else {\n ps = c[1] >= tl[0][1] + tl[1][1] ? [c] : tl\n ;[].push.apply(bpss, ps.map(function (s) {return s[3]}))\n gp += ps.reduce(function (r, s) {return r + s[1]}, 0)\n }\n}\n\nprint(gp)\nprint(bpss.join(' '))"}, {"source_code": "var n,v;\nvar boat=[];\nfunction main()\n{\n\tvar i;\n\ttmp=readline().split(\" \");\n\tn=Number(tmp[0]);v=Number(tmp[1]);\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tboat[i-1]=readline().split(\" \");\n\t\tboat[i-1][0]=parseInt(boat[i-1][0]);\n\t\tboat[i-1][1]=parseInt(boat[i-1][1]);\n\t\tboat[i-1][2]=parseInt(i);\n\t}\n\tboat.sort(function cmp(a,b)\n\t\t\t{\n\t\t\t\tif(a[0]==b[0]) return b[1]-a[1];\n\t\t\t\telse\n\t\t\t\t\tif(a[0]>b[0]) return 2*b[1]-a[1];\n\t\t\t\t\telse return b[1]-2*a[1];\n\t\t\t\treturn 0;\n\t\t\t}\n\t)\n\tvar ans=0;\n\tvar xh=[];\n\tfor(i=0;i<=n-1;i++)\n\t\tif(v>=boat[i][0]) {v-=boat[i][0];ans+=boat[i][1];xh.push(boat[i][2]);}\n\tprint(ans);\n\tprint(xh.join(\" \"));\n}\nmain();"}, {"source_code": "var n,v;\nvar boat1=[];\nvar boat2=[];\nfunction main()\n{\n\tvar i;\n\tvar cnt1=0,cnt2=0;\n\ttmp=readline().split(\" \");\n\tn=Number(tmp[0]);v=Number(tmp[1]);\n\tfor(i=1;i<=n;i++)\n\t{\n\t\ttmp=readline().split(\" \");\n\t\ttmp[0]=parseInt(tmp[0]);tmp[1]=parseInt(tmp[1]);\n\t\tif(tmp[0]==1) boat1[++cnt1]=[i,tmp[1]];\n\t\telse boat2[++cnt2]=[i,tmp[1]];\n\t}\n\tboat1[0]=[1000000,1000000];boat2[0]=[1000000,1000000];\n\tboat1.sort(function cmp(a,b){return b[1]-a[1];});\n\tboat2.sort(function cmp(a,b){return b[1]-a[1];});\n/*\n\tprint(\"----------------------------------------------\");\n\tfor(i=1;i<=cnt1;i++) print(boat1[i][1]);\n\tprint(\"----------------------------------------------\");\n*/\n\tfor(i=2;i<=cnt1;i++) boat1[i][1]+=boat1[i-1][1];\n\tfor(i=2;i<=cnt2;i++) boat2[i][1]+=boat2[i-1][1];\n\tvar ans=-1;\n\tvar index1,index2;\n\tboat1[0]=[0,0];\n\tfor(i=1;i<=cnt2;i++)\n\t{\n\t\tif(i*2>v) continue; \n\t\tvar tmp1=(v-2*i<=cnt1?v-2*i:cnt1);\n\t\tvar tmp2=parseInt(boat2[i][1])+parseInt(boat1[tmp1][1]);\n\t\tif(tmp2>ans)\n\t\t{\n\t\t\tindex1=tmp1;index2=i;\n\t\t\tans=tmp2;\n\t\t}\n\t}\n\tprint(ans);\n\tvar xh=new String();\n\tfor(i=1;i<=index1;i++)\n\t{\n\t\tif(i!=1) xh+=\" \"; \n\t\txh+=boat1[i][0];\n\t}\n\tfor(i=1;i<=index2;i++)\n\t{\n\t\tif(xh!=\"\") xh+=\" \";\n\t\txh+=boat2[i][0];\n\t}\n\tprint(xh);\n}\nmain();"}, {"source_code": "/**\n * fill truck with max density vehicles first\n */\n\nvar input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\nvar vehicles = [];\n\nfor (var i = 1; i < numOfVehicles + 1; i++) {\n input = readline().split(' ');\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n var type = parseInt(input[0]);\n var capacity = parseInt(input[1]);\n vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);\n}\n\n// sort vehicles by density (capacity / volume)\nvehicles.sort(function(a, b) {\n return b[3] - a[3];\n});\n\nvar lVeh = [];\nvar lVol = 0;\nvar lCap = 0;\nvar lastKayak = null;\n\nvar i = 0;\nwhile (truckVolume > (lVol + 3) && i < vehicles.length) {\n var nextVeh = vehicles[i++];\n lVeh.push(nextVeh[2]);\n lVol += nextVeh[0];\n lCap += nextVeh[1];\n if (nextVeh[0] == 1) {\n lastKayak = nextVeh;\n }\n}\n\nif (i < vehicles.length) {\n vehicles = vehicles.slice(i);\n} else {\n vehicles = [];\n}\n\nif (numOfVehicles == 84659) {\n print('ce')\n}\n\n\n// remove the last added kayak and solve as set\nif (lastKayak !== null) {\n lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);\n lVol -= lastKayak[0]; // always 1\n lCap -= lastKayak[1];\n vehicles.unshift(lastKayak); // put back into vehicles list\n}\n\nvar maxCap = lCap;\nvar maxCapVeh = lVeh.slice();\n\nif (numOfVehicles == 84659) {\n print('d4')\n}\n\ncheckCapacity(lVeh, lVol, lCap, 0);\n\nif (numOfVehicles == 84659) {\n print('d4')\n}\n\nprint(maxCap);\nprint(maxCapVeh.join(' '));\n\n// ----------------------------------------------------------------------------\n\n// loaded vehicles, loaded volume, loaded capacity\nfunction checkCapacity(loadedVeh, loadedVol, loadedCap, i) {\n // print('@', loadedVeh, loadedVol, loadedCap, i);\n var type = vehicles[i][0];\n var cap = vehicles[i][1];\n var veh = vehicles[i][2];\n\n var newLoadedVol = loadedVol + type;\n var newLoadedCap = loadedCap + cap;\n var newLoadedVeh = loadedVeh.slice();\n newLoadedVeh.push(veh);\n\n if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {\n maxCap = newLoadedCap;\n maxCapVeh = newLoadedVeh;\n }\n\n if (i < vehicles.length - 1 && i < 5) {\n // including\n if (newLoadedVol < truckVolume) {\n checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);\n }\n\n // not including\n if (loadedVol < truckVolume) {\n checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);\n }\n }\n}\n"}, {"source_code": "var input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\n// map capacity to count\nvar catamarans = {};\nvar kayaks = {};\n\nfor (var i = 0; i < numOfVehicles; i++) {\n input = readline().split(' ');\n\n var capacity = input[1];\n var type = input[0];\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n if (type == '1') {\n kayaks[capacity] = kayaks[capacity] || 0;\n kayaks[capacity]++;\n } else {\n catamarans[capacity] = catamarans[capacity] || 0;\n catamarans[capacity]++;\n }\n}\n\nvar catamaranCaps = sortDesc(catamarans); // ints\nvar kayakCaps = sortDesc(kayaks);\n\n// add to truck until full\nvar loadedVolume = 0;\nvar carryingCap = 0;\n// var numOfLoadedVehicles = 0;\nvar loadedVehicles = [];\n\nwhile (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {\n var catamaranCap = catamaranCaps[0] || 0;\n var kayakCap = kayakCaps[0] || 0;\n\n if (truckVolume - loadedVolume > 1) {\n if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density\n loadedVolume += 2;\n carryingCap += catamaranCap;\n removeVehicle(catamarans, catamaranCaps, catamaranCap);\n // numOfLoadedVehicles++;\n loadedVehicles.push(2);\n } else if (kayakCap > 0) {\n loadedVolume += 1;\n carryingCap += kayakCap;\n removeVehicle(kayaks, kayakCaps, kayakCap);\n // numOfLoadedVehicles++;\n loadedVehicles.push(1);\n } else {\n // nothing to load\n print('weird');\n break;\n }\n } else if (kayakCap > 0) {\n // load one more kayak\n loadedVolume += 1;\n carryingCap += kayakCap;\n removeVehicle(kayaks, kayakCaps, kayakCap);\n // numOfLoadedVehicles++;\n loadedVehicles.push(1);\n } else {\n // can't load another catamaran\n break;\n }\n}\n\nprint(carryingCap);\n// print(numOfLoadedVehicles);\nprint(loadedVehicles);\n\n\n// ----------------------------------------\n\nfunction sortDesc(input) {\n return Object.keys(input).map(function(e) {\n return parseInt(e);\n }).sort(function(a, b) {\n return b - a\n });\n}\n\nfunction removeVehicle(vehicles, caps, cap) {\n var key = cap.toString();\n vehicles[key]--;\n if (vehicles[key] == 0) {\n delete vehicles[key];\n caps.splice(0, 1);\n }\n}\n"}, {"source_code": "var input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\n// map capacity to count\nvar catamarans = {};\nvar kayaks = {};\n\nfor (var i = 0; i < numOfVehicles; i++) {\n input = readline().split(' ');\n\n var capacity = input[1];\n var type = input[0];\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n if (type == '1') {\n kayaks[capacity] = kayaks[capacity] || 0;\n kayaks[capacity]++;\n } else {\n catamarans[capacity] = catamarans[capacity] || 0;\n catamarans[capacity]++;\n }\n}\n\nvar catamaranCaps = sortDesc(catamarans); // ints\nvar kayakCaps = sortDesc(kayaks);\n\n// add to truck until full\nvar loadedVolume = 0;\nvar carryingCap = 0;\nvar numOfLoadedVehicles = 0;\n\nwhile (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {\n var catamaranCap = catamaranCaps[0] || 0;\n var kayakCap = kayakCaps[0] || 0;\n\n if (truckVolume - loadedVolume > 1) {\n if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density\n loadedVolume += 2;\n carryingCap += catamaranCap;\n removeVehicle(catamarans, catamaranCaps, catamaranCap);\n numOfLoadedVehicles++;\n } else if (kayakCap > 0) {\n loadedVolume += 1;\n carryingCap += kayakCap;\n removeVehicle(kayaks, kayakCaps, kayakCap);\n numOfLoadedVehicles++;\n } else {\n // nothing to load\n print('weird');\n break;\n }\n } else if (kayakCap > 0) {\n // load one more kayak\n loadedVolume += 1;\n carryingCap += kayakCap;\n removeVehicle(kayaks, kayakCaps, kayakCap);\n } else {\n // can't load another catamaran\n break;\n }\n}\n\nprint(carryingCap);\nprint(numOfLoadedVehicles);\n\n\n// ----------------------------------------\n\nfunction sortDesc(input) {\n return Object.keys(input).map(function(e) {\n return parseInt(e);\n }).sort(function(a, b) {\n return b - a\n });\n}\n\nfunction removeVehicle(vehicles, caps, cap) {\n var key = cap.toString();\n vehicles[key]--;\n if (vehicles[key] == 0) {\n delete vehicles[key];\n caps.splice(0, 1);\n }\n}\n"}, {"source_code": "var input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\n// map capacity to count\nvar catamarans = {};\nvar kayaks = {};\n\nfor (var i = 1; i < numOfVehicles + 1; i++) {\n input = readline().split(' ');\n\n var capacity = input[1];\n var type = input[0];\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n if (type == '1') {\n kayaks[capacity] = kayaks[capacity] || [];\n kayaks[capacity].push(i);\n } else {\n catamarans[capacity] = catamarans[capacity] || [];\n catamarans[capacity].push(i);\n }\n}\n\nvar catamaranCaps = sortDesc(catamarans); // ints\nvar kayakCaps = sortDesc(kayaks);\n\n// add to truck until full\nvar loadedVolume = 0;\nvar carryingCap = 0;\nvar loadedVehicles = [];\n\nwhile (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {\n var catamaranCap = catamaranCaps[0] || 0;\n var kayakCap = kayakCaps[0] || 0;\n\n if (truckVolume - loadedVolume > 1) {\n if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density\n loadedVolume += 2;\n carryingCap += catamaranCap;\n loadedVehicles.push(removeVehicle(catamarans, catamaranCaps, catamaranCap));\n } else if (kayakCap > 0) {\n loadedVolume += 1;\n carryingCap += kayakCap;\n loadedVehicles.push(removeVehicle(kayaks, kayakCaps, kayakCap));\n }\n } else if (kayakCap > 0) {\n // load one more kayak\n loadedVolume += 1;\n carryingCap += kayakCap;\n loadedVehicles.push(removeVehicle(kayaks, kayakCaps, kayakCap));\n } else {\n // can't load another catamaran\n break;\n }\n}\n\nprint(carryingCap);\n// print(numOfLoadedVehicles);\nprint(loadedVehicles.join(' '));\n\n\n// ----------------------------------------\n\nfunction sortDesc(input) {\n return Object.keys(input).map(function(e) {\n return parseInt(e);\n }).sort(function(a, b) {\n return b - a\n });\n}\n\nfunction removeVehicle(vehicles, caps, cap) {\n var key = cap.toString();\n var removed = vehicles[key].splice(0, 1);\n if (vehicles[key].length == 0) {\n delete vehicles[key];\n caps.splice(0, 1);\n }\n return removed[0];\n}\n"}, {"source_code": "/**\n * fill truck with max density vehicles first\n */\n\nvar input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\nvar vehicles = [];\n\nfor (var i = 1; i < numOfVehicles + 1; i++) {\n input = readline().split(' ');\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n var type = parseInt(input[0]);\n var capacity = parseInt(input[1]);\n vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);\n}\n\n// sort vehicles by density (capacity / volume)\nvehicles.sort(function(a, b) {\n return b[3] - a[3];\n});\n\nvar lVeh = [];\nvar lVol = 0;\nvar lCap = 0;\nvar lastKayak = null;\n\nwhile (truckVolume > (lVol + 3) && vehicles.length > 0) {\n var nextVeh = vehicles[0];\n lVeh.push(nextVeh[2]);\n lVol += nextVeh[0];\n lCap += nextVeh[1];\n vehicles.splice(0, 1);\n if (nextVeh[0] == 1) {\n lastKayak = nextVeh;\n }\n}\n\n// remove the last added kayak and solve as set\nif (lastKayak !== null) {\n lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);\n lVol -= lastKayak[0]; // always 1\n lCap -= lastKayak[1];\n vehicles.unshift(lastKayak); // put back into vehicles list\n}\n\nif (numOfVehicles == 5000) {\n print('c3')\n}\n\nvar maxCap = lCap;\nvar maxCapVeh = lVeh.slice();\n\ncheckCapacity(lVeh, lVol, lCap, 0);\n\nif (numOfVehicles == 5000) {\n print('d4')\n}\n\nprint(maxCap);\nprint(maxCapVeh.join(' '));\n\n// ----------------------------------------------------------------------------\n\n// loaded vehicles, loaded volume, loaded capacity\nfunction checkCapacity(loadedVeh, loadedVol, loadedCap, i) {\n // print('@', loadedVeh, loadedVol, loadedCap, i);\n var type = vehicles[i][0];\n var cap = vehicles[i][1];\n var veh = vehicles[i][2];\n\n var newLoadedVol = loadedVol + type;\n var newLoadedCap = loadedCap + cap;\n var newLoadedVeh = loadedVeh.slice();\n newLoadedVeh.push(veh);\n\n if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {\n maxCap = newLoadedCap;\n maxCapVeh = newLoadedVeh;\n }\n\n if (i < vehicles.length - 1 && i < 10) {\n // including\n if (newLoadedVol < truckVolume) {\n checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);\n }\n\n // not including\n if (loadedVol < truckVolume) {\n checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);\n }\n }\n}\n"}, {"source_code": "/**\n * fill truck with max density vehicles first\n */\n\nvar input = readline().split(' ');\n\n// number of waterborne vehicles and the truck body volume\nvar numOfVehicles = parseInt(input[0]);\nvar truckVolume = parseInt(input[1]);\n\nvar vehicles = [];\n\nfor (var i = 1; i < numOfVehicles + 1; i++) {\n input = readline().split(' ');\n\n // type: 1 \u2013 kayak, 2 \u2013 catamaran\n var type = parseInt(input[0]);\n var capacity = parseInt(input[1]);\n vehicles.push([type, capacity, i]);\n}\n\n// sort vehicles by density (capacity / volume)\nvehicles.sort(function(a, b) {\n var densityA = a[1] / a[0];\n var densityB = b[1] / b[0];\n return densityB - densityA;\n});\n\nvar lVeh = [];\nvar lVol = 0;\nvar lCap = 0;\n\nwhile (truckVolume > (lVol + 5) && vehicles.length > 0) {\n var nextVeh = vehicles[0];\n lVeh.push(nextVeh[2]);\n lVol += nextVeh[0];\n lCap += nextVeh[1];\n vehicles.splice(0, 1);\n}\n\n// try filling with different combinations of vehicles for max\nvar maxCap = lCap;\nvar maxCapVeh = lVeh.slice();\n\ncheckCapacity(lVeh, lVol, lCap, 0);\n\nprint(maxCap);\nprint(maxCapVeh.join(' '));\n\n// ----------------------------------------------------------------------------\n\n// loaded vehicles, loaded volume, loaded capacity\nfunction checkCapacity(loadedVeh, loadedVol, loadedCap, i) {\n // print('@', loadedVeh, loadedVol, loadedCap, i);\n var type = vehicles[i][0];\n var cap = vehicles[i][1];\n var veh = vehicles[i][2];\n\n var newLoadedVol = loadedVol + type;\n var newLoadedCap = loadedCap + cap;\n var newLoadedVeh = loadedVeh.slice();\n newLoadedVeh.push(veh);\n\n if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {\n maxCap = newLoadedCap;\n maxCapVeh = newLoadedVeh;\n }\n\n if (i < vehicles.length - 1) {\n // including\n if (newLoadedVol < truckVolume) {\n checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);\n }\n\n // not including\n if (loadedVol < truckVolume) {\n checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);\n }\n }\n}\n"}], "src_uid": "a1f98b06650a5755e784cd6ec6f3b211"} {"source_code": "var s = readline().split(\" \")\nvar inputArray = readline().split(\" \")\nn = parseInt(s[0]), a = parseInt(s[1]), b = parseInt(s[2]), c =parseInt( s[3]),\n t = parseInt(s[4])\nif (c <= b)\n print(a * n)\nelse {\n var sum = 0\n for (var i = 0; i < inputArray.length; i++) {\n sum += (c - b) * (t - parseInt(inputArray[i]))+a\n }\n print(sum)\n}", "positive_code": [{"source_code": "var s = readline().split(\" \");\nvar sum = 0;\n\nvar inputArray = readline().split(\" \"),\n n = parseInt(s[0]),\n a = parseInt(s[1]),\n b = parseInt(s[2]),\n c = parseInt(s[3]),\n t = parseInt(s[4]);\n\nif (c <= b)\n print(a * n);\nelse {\n for (var i = 0; i < inputArray.length; i++) {\n sum += (c - b) * (t - parseInt(inputArray[i])) + a;\n }\n print(sum);\n}\n"}, {"source_code": "var num = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n=num[0];\nvar A=num[1];\nvar B=num[2];\nvar C=num[3];\nvar T=num[4];\nvar Tis = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar read=B>C;\nvar money=0;\nfor(var i=0;i {\r\n if (arr.has(n))\r\n return arr.get(n);\r\n if (n < 2020)\r\n return 0;\r\n if (n % 2020 == 0 || n % 2021 == 0)\r\n return 1;\r\n var temp = process(n-2020) ? 1 : process(n-2021);\r\n arr.set(n, temp);\r\n return temp;\r\n}\r\nfor (var i = 0; i < num; i++) {\r\n var input = parseInt(readline());\r\n result = process(input) ? \"YES\" : \"NO\";\r\n print(result);\r\n}"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var temp = +readline();\r\n print((temp % 2020) > (temp / 2020) ? 'NO' : 'YES');\r\n}"}, {"source_code": "var a = parseInt(readline());\r\n\r\n while (a--) {\r\n var n = parseInt(readline());\r\n\r\n var mod = n % 2020;\r\n var div = n / 2020;\r\n\r\n if (mod <= div) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "var print = this.print || require('lol-io').print\r\nvar write = this.write || require('lol-io').write\r\nvar readline = this.readline || require('lol-io').readline\r\n\r\n\r\nvar t=parseInt(readline());\r\nwhile(t--){\r\n var n=parseInt(readline());\r\n print(solve(n));\r\n\r\n}\r\n\r\nfunction solve(n){\r\n for(var i=0;i<1000;i++){\r\n var b=n-(2020*i);\r\n if(b<0)break;\r\n if(b%2021==0){\r\n return \"YES\";\r\n }\r\n }\r\n return \"NO\";\r\n}"}, {"source_code": "var cnt = +readline();\r\nvar arr = [];\r\nfor(var i = 0; i < cnt; i++) {\r\n arr.push(readline());\r\n}\r\n\r\n\r\n \r\nfunction newYearsNumber(n) {\r\n if (n < 2020) {\r\n return 'NO';\r\n }\r\n\r\n if (n % 2020 === 0 || n % 2021 === 0) {\r\n return 'YES';\r\n }\r\n\r\n return newYearsNumber(n - 2021);\r\n}\r\n \r\nfor (var i = 0; i < arr.length; i++) {\r\n print(newYearsNumber(arr[i]))\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let input = parseInt(readline());\r\n let a = Math.trunc(input / 2020);\r\n let b = input % 2020;\r\n if(b <= a){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "let i = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n\tfor(j = 1; j <= n; j++){\n\t var k = lines[j]\n\t var a = Math.floor(k / 2020)\n\t \tvar b = k % 2020\n\t console.log(a >= b ? 'YES' : 'NO')\n\t}\n});//k[k.length - 1] == '' || "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n\tfor(j = 1; j <= n; j++){\n\t var k = lines[j]\n\t var a = k % 2020\n\t var b = Math.floor(k / 2020)\n\t console.log(a <= b ? 'YES' : 'NO')\n\t}\n});"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n if (Number.isNaN(n)) while (true);\r\n let k = Math.floor(n / 2020)\r\n let p = n % (2020 * k)\r\n if (p <= k) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\nmain()\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tconst map = new Map();\n\tfor (let i = 0; i <= 1000; i++) {\n\t\tfor (let j = 0; j <= 1000; j++) {\n\t\t\tconst ans = 2020 * i + 2021 * j;\n\t\t\tmap.set(ans, true);\n\t\t}\n\t}\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst n = +readLine();\n\t\tif (map.has(n)) console.log('YES');\n\t\telse console.log('NO');\n\t}\n}\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line.split(\" \"));\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n let n = +input[i];\r\n\r\n let count21 = n % 2020;\r\n\r\n let count20 = (n - 2021 * count21) / 2020;\r\n\r\n if (count20 >= 0 && 2020 * count20 + 2021 * count21 === n)\r\n console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line.split(\" \"));\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n let n = +input[i];\r\n\r\n while (n > 0) {\r\n if (n % 2020 !== 0) {\r\n n -= 2021;\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n if (n % 2020 === 0 && n >= 0) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\n"}, {"source_code": "(()=>{\"use strict\";var e={758:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){for(var t=0;e>=2020;)e-=2020,t++;return e<=t?\"YES\":\"NO\"}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var o=r(n(758));n(188).testInput(o.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],o=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(o=+r[0]),r.length===o+1){t.close();for(var u=1;u{e.exports=require(\"readline\")}},t={};!function n(r){var o=t[r];if(void 0!==o)return o.exports;var u=t[r]={exports:{}};return e[r].call(u.exports,u,u.exports,n),u.exports}(590)})();"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var n = lines[i];\n\t var a = n % 2020;\n\t var b = Math.floor(n / 2020);\n\t console.log(a <= b ? 'YES' : 'NO');\n\t}\n});\n\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let year = +input[z++];\r\n if((year % 2020 === 0) || (year % 2021 === 0)){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n let onesMultipal = year % 2020;\r\n let zerosMultipal = Math.abs((year % 2021) - 2021);\r\n if((2020 * zerosMultipal) + (2021 * onesMultipal) == year){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const num = input.slice(1).map(v => Number(v));\r\n\r\n for(let val of num) {\r\n let cnt21 = val % 2020;\r\n let cnt20 = (val - cnt21) / 2020 - cnt21;\r\n \r\n if(cnt20 >= 0 && 2020 * cnt20 + 2021 * cnt21 === val) {\r\n console.log(\"YES\");\r\n } else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let num = parseInt(readline())\n // ====== SOLUTION ======\n // if (num % 2021 == 0){\n // console.log('YES')\n // return\n // }\n while(num > 2019){\n // console.log('num = ', num)\n if (num % 2020 == 0 || num % 2021 == 0){\n console.log('YES')\n return\n }\n num -= 2021\n }\n console.log('NO')\n}"}, {"source_code": "z = +readline();\r\nwhile (z--) {\r\n x = +readline();\r\n y = x / 2020;\r\n w = Math.floor(y);\r\n q = x % 2020;\r\n if (q <= w) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "const cases = readline()\r\nvar temp\r\nvar flag = 0\r\nfor (var i = 0; i < cases; i++) {\r\n inp = readline()\r\n temp = parseInt(inp, 10)\r\n if (temp % 2020 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n } else if (temp % 2021 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n } else {\r\n while (temp >= 2020) {\r\n temp = temp - 2020\r\n if (temp % 2021 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n }\r\n }\r\n }\r\n if (flag < 1) {\r\n print(\"No\")\r\n }\r\n flag = 0\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "q = +readline();\r\nwhile (q--) {\r\n x = readline();\r\n y = x.split(\"\").map(Number);\r\n z = y[0] / 2;\r\n if (x == 10000 || x == 100000 || x == 1000000) {\r\n print(\"YES\");\r\n } else if (\r\n y[0] === y[2] &&\r\n y[0] % 2 === 0 &&\r\n y[2] % 2 === 0 &&\r\n y[1] === 0 &&\r\n y[3] <= z\r\n ) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "const cases = readline()\r\nvar temp\r\nvar flag = 0\r\nfor (var i = 0; i < cases; i++) {\r\n inp = readline()\r\n temp = parseInt(inp, 10)\r\n if (temp % 2020 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n } else if (temp % 2021 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n } else {\r\n while (temp >= 2020) {\r\n temp = temp - 2020\r\n if (temp % 2021 == 0) {\r\n flag++\r\n print(\"Yes\")\r\n }\r\n }\r\n }\r\n if (flag < 1) {\r\n print(\"No\")\r\n flag = 0\r\n }\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n if(a.length >= 4){\n console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')\n }else{\n console.log('NO')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n if(a.length >= 4){\n console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')}\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n console.log(a[0] == a[2] ? 'YES' : 'NO')\n }\n});"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n| /)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n if (Number.isNaN(n)) while (true);\r\n let k = Math.floor(n / 2020)\r\n let p = n % (2020 * k)\r\n if (p <= k) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n}\r\n\r\nmain()\r\n\r\nsetTimeout(() => process.exit(0), 800)\r\n"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n/)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n if (Number.isNaN(n)) while (true);\r\n let k = Math.floor(n / 2020)\r\n let p = n % (2020 * k)\r\n if (p <= k) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n}\r\n\r\nmain()\r\n\r\nsetTimeout(() => process.exit(0), 800)\r\n"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n/)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n let k = Math.floor(n / 2020)\r\n let p = n % (2020 * k)\r\n if (p <= k) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n}\r\n\r\nmain()\r\n\r\nsetTimeout(() => process.exit(0), 800)\r\n"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n/)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n let k = Math.floor(n / 2020)\r\n let p = n % (2020 * k)\r\n if (p <= k) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\nmain()\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tif (n < 2020 || n < 2021) console.log('NO');\n\t\telse {\n\t\t\tlet found = false;\n\t\t\tif (n % 2020 === 0 || n % 2021 === 0) {\n\t\t\t\tconsole.log('YES');\n\t\t\t\tfound = true;\n\t\t\t} else {\n\t\t\t\tconst [div, rem] = [Math.floor(n / 2020), n % 2020];\n\t\t\t\tif (rem <= div) {\n\t\t\t\t\tfound = true;\n\t\t\t\t\tconsole.log('YES');\n\t\t\t\t}\n\t\t\t\t!found && console.log('NO');\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tif (n < 2020 || n < 2021) console.log('NO');\n\t\telse {\n\t\t\tlet found = false;\n\t\t\tif (n % 2020 === 0 || n % 2021 === 0) {\n\t\t\t\tconsole.log('YES');\n\t\t\t\tfound = true;\n\t\t\t} else {\n\t\t\t\tconst rem = n % 4041;\n\t\t\t\tif (rem === 0 || rem % 2020 === 0 || rem % 2021 === 0) {\n\t\t\t\t\tconsole.log('YES');\n\t\t\t\t\tfound = true;\n\t\t\t\t}\n\t\t\t\t!found && console.log('NO');\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "(()=>{\"use strict\";var e={758:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(e){for(var t=0;e>2020;)e-=2020,t++;return e<=t?\"YES\":\"NO\"}},590:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});var o=r(n(758));n(188).testInput(o.default)},188:(e,t,n)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=function(e){var t=n(58).createInterface({input:process.stdin,output:process.stdout}),r=[],o=0;t.on(\"line\",(function(n){if(r.push(n),1===r.length&&(o=+r[0]),r.length===o+1){t.close();for(var u=1;u{e.exports=require(\"readline\")}},t={};!function n(r){var o=t[r];if(void 0!==o)return o.exports;var u=t[r]={exports:{}};return e[r].call(u.exports,u,u.exports,n),u.exports}(590)})();"}], "src_uid": "3ec1b7027f487181dbdfb12f295f11ae"} {"source_code": "var readNumber = () => +readline();\r\nvar readStr = () => readline();\r\nvar n = readNumber();\r\n\r\nfor (var i = 0; i < n; i++) {\r\n readNumber();\r\n var array = readStr().split('');\r\n paint(array);\r\n}\r\n\r\nfunction paint(input) {\r\n var firstPaintedIndex = -1;\r\n adjacentColor = \"R\";\r\n for (var index = 0; index < input.length; index++) {\r\n if (input[index] != '?') {\r\n firstPaintedIndex = index;\r\n adjacentColor = input[index];\r\n break;\r\n }\r\n }\r\n\r\n if (firstPaintedIndex != -1) {\r\n //paint left\r\n for (var index = firstPaintedIndex - 1; index >= 0; index--) {\r\n input[index] = adjacentColor == 'B' ? 'R' : 'B';\r\n adjacentColor = input[index];\r\n }\r\n\r\n adjacentColor = input[firstPaintedIndex]\r\n }\r\n //paint right\r\n for (var index = firstPaintedIndex + 1; index < input.length; index++) {\r\n var current = input[index];\r\n if (current == '?') {\r\n input[index] = adjacentColor == 'B' ? 'R' : 'B';\r\n }\r\n adjacentColor = input[index];\r\n }\r\n\r\n print(input.join(''));\r\n}", "positive_code": [{"source_code": "var t = parseInt(readline())\nwhile(t--){\n var n=parseInt(readline())\n var v=readline().split('')\n\n for(var i=n-2;~i;i--)\n if(v[i]==='?')\n if(v[i+1]!=='?') \n v[i]= (v[i+1]==='R')?'B':'R'\n \n \n for(var i=1;i= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst regex = /([?]+)/g\r\nfunction solve(e, n) {\r\n return n.replace(regex, (t, s, i) => {\r\n let r = 'B'\r\n if ((i > 0 && (r = 'R' === n[i - 1] ? 'B' : 'R'), i + s.length < e)) {\r\n const e = n[i + s.length]\r\n r = 'R' === e ? (1 & s.length ? 'B' : 'R') : 1 & s.length ? 'R' : 'B'\r\n }\r\n const o = 'R' === r ? 'B' : 'R'\r\n return s\r\n .split('')\r\n .map((e, n) => (1 & n ? o : r))\r\n .join('')\r\n })\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readLine().trim())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nconst rev = c => c == 'B' ? 'R' : 'B';\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet s = rl().split('');\r\n\r\n\t\tif (s[0] == '?') {\r\n\t\t\tlet i = 0;\r\n\t\t\twhile (i < n && s[i] == '?') i++;\r\n\t\t\tif (i == n) s[0] = 'B';\r\n\t\t\telse if (i % 2 == 1) s[0] = rev(s[i]); \r\n\t\t\telse s[0] = s[i];\r\n\t\t}\r\n\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tif (s[i] == '?') {\r\n\t\t\t\ts[i] = rev(s[i - 1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(s.join(''));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const input = [];\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', line => input.push(line));\n\nrl.on('close', doWork);\n\nlet line = 0;\n\nfunction lineToStrArray(split = ' ') {\n const val = input[line].split(split);\n line += 1;\n return val;\n}\n\nfunction lineToNumArray(split = ' ') {\n const val = input[line].split(split).map(e => +e);\n line += 1;\n return val;\n}\n\nfunction doWork() {\n const [t] = lineToNumArray();\n \n for (let t1 = 0; t1 < t; t1 += 1) {\n const [n] = lineToNumArray();\n const [str] = lineToStrArray();\n\n const splitStr = str.split('');\n\n if (splitStr.every(e => e === '?')) {\n splitStr[0] = 'R';\n }\n\n while (splitStr.includes('?')) {\n let next = null;\n for (let i = 0; i < splitStr.length; i += 1) {\n if (splitStr[i] !== '?') {\n next = splitStr[i] === 'B' ? 'R' : 'B';\n } else if (next !== null) {\n splitStr[i] = next;\n next = splitStr[i] === 'B' ? 'R' : 'B';\n }\n }\n next = null;\n for (let i = splitStr.length - 1; i >= 0; i -= 1) {\n if (splitStr[i] !== '?') {\n next = splitStr[i] === 'B' ? 'R' : 'B';\n } else if (next !== null) {\n splitStr[i] = next;\n next = splitStr[i] === 'B' ? 'R' : 'B';\n }\n }\n }\n console.log(splitStr.join(''));\n }\n}\n \t\t \t \t \t \t\t \t\t\t \t\t\t\t\t"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n\tlet numberOfLines = parseInt(readline(), 10) * 2\n\tfor(let i = 0; i < numberOfLines; i++) {\n\t\tlet x = readline().trim()\n\t\tif(i % 2 === 1) {\n\t\t\tconsole.log(solve(x))\n\t\t}\n\t\t// print(solve(x))\n\t\t// fs.appendFileSync(\"output.txt\", `Case #${i+1}: ${solve(x)}` + \"\\n\")\n\t}\n \n}\n\nfunction solve(str) {\n let arr = str.split(\"\");\n\tlet numOfUnknown = 0\n\tlet queue = []\n\tfor(let i = 0; i < arr.length; i++) {\n\t\tif(arr[i] !== \"?\") queue.push(i)\n\t\telse numOfUnknown++\n\t}\n\tif(numOfUnknown > 0 && !queue.length) {\n\t\tarr[0] = \"B\"\n\t\tqueue.push(0)\n\t}\n\twhile(queue.length && numOfUnknown) {\n\t\tlet current = queue.pop()\n\t\tif(current > 0 && arr[current - 1] === \"?\") {\n\t\t\tif(arr[current] === \"B\") arr[current-1] = \"R\"\n\t\t\telse arr[current-1] = \"B\"\n\t\t\tqueue.push(current - 1)\n\t\t\tnumOfUnknown--\n\t\t}\n\t\tif(current < arr.length - 1 && arr[current + 1] === \"?\") {\n\t\t\tif(arr[current] === \"B\") arr[current + 1] = \"R\"\n\t\t\telse arr[current + 1] = \"B\"\n\t\t\tqueue.push(current + 1)\n\t\t\tnumOfUnknown--\n\t\t}\n\t}\n\n\treturn arr.join(\"\")\n}\n"}, {"source_code": "let inputBuffer = ''\r\nprocess.stdin.on('data', data => {\r\n\tinputBuffer += data\r\n})\r\nprocess.stdin.on('end', _ => {\r\n\tinputBuffer = inputBuffer.trim().split('\\n')\r\n\r\n\tmain()\r\n})\r\n\r\nlet currentLine = 0\r\nfunction readline() {\r\n\treturn inputBuffer[currentLine++]\r\n}\r\nfunction readint() {\r\n\treturn parseInt(readline(), 10)\r\n}\r\nfunction readints() {\r\n\treturn readline().split(' ').map(s => parseInt(s, 10))\r\n}\r\nfunction print(s) {\r\n\tprocess.stdout.write(s + '\\n')\r\n}\r\nfunction write(s) {\r\n\tprocess.stdout.write(s)\r\n}\r\n\r\nfunction range(lowerBound, upperBound = undefined, step = 1) {\r\n\tif (upperBound === undefined) {\r\n\t\tupperBound = lowerBound\r\n\t\tlowerBound = 0\r\n\t}\r\n\tlet ret = []\r\n\tif (lowerBound <= upperBound) {\r\n\t\tfor (let i = lowerBound; i < upperBound; i += step) ret.push(i)\r\n\t} else {\r\n\t\tfor (let i = lowerBound; i > upperBound; i -= step) ret.push(i)\r\n\t}\r\n\treturn ret\r\n}\r\nfunction loop(lowerBound, upperBound = undefined, step = 1) {\r\n\treturn (func) => {\r\n\t\trange(lowerBound, upperBound, step).forEach(i => func(i))\r\n\t}\r\n}\r\n\r\nfunction main() {\r\n\tlet t = readint()\r\n\tloop(t)(_ => {\r\n\t\tlet n = readint()\r\n\t\tlet s = readline()\r\n\t\tlet indB = s.indexOf('B')\r\n\t\tlet indR = s.indexOf('R')\r\n\t\tlet ans = ''\r\n\t\tif (indB === -1 && indR === -1) {\r\n\t\t\tloop(n)(i => ans += 'BR'[i%2])\r\n\t\t} else {\r\n\t\t\tlet ind = Math.max(indB, indR);\r\n\t\t\ts = s.split('')\r\n\t\t\tloop(ind + 1, n)(i => {\r\n\t\t\t\tif (s[i] === '?') s[i] = s[i-1] === 'R' ? 'B' : 'R'\r\n\t\t\t})\r\n\t\t\tloop(ind - 1, -1)(i => {\r\n\t\t\t\tif (s[i] === '?') s[i] = s[i+1] === 'R' ? 'B' : 'R'\r\n\t\t\t})\r\n\t\t\tans = s.join('')\r\n\t\t}\r\n\t\tprint(ans)\r\n\t})\r\n}\r\n"}], "negative_code": [{"source_code": "var t = parseInt(readline())\nwhile(t--){\n var n=parseInt(readline())\n var v=readline().split('')\n\n for(var i=n-2;~i;i--)\n if(v[i]==='?')\n v[i]= (v[i+1]==='R')?'B':'R'\n\n \n for(var i=1;i +readline();\r\nvar readStr = () => readline();\r\nvar n = readNumber();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n readNumber();\r\n var array = readStr().split('');\r\n paint(array);\r\n}\r\n\r\nfunction paint(input){\r\n var firstPaintedIndex=1;\r\n adjacentColor=\"R\";\r\n for(var index=0;index=0;index--){\r\n input[index]=adjacentColor=='B'?'R':'B';\r\n adjacentColor=input[index];\r\n }\r\n \r\n adjacentColor=input[firstPaintedIndex]\r\n //paint right\r\n for(var index=firstPaintedIndex+1;index= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst regex = /([?]+)/g\r\nfunction solve(e, n) {\r\n return n.replace(regex, (t, s, i) => {\r\n let r = 'R' === n[i] ? 'B' : 'R'\r\n if (i + s.length < e) {\r\n const e = n[i + s.length]\r\n r = 'R' === e ? (1 & s.length ? 'B' : 'R') : 1 & s.length ? 'R' : 'B'\r\n }\r\n const o = 'R' === r ? 'B' : 'R'\r\n return s\r\n .split('')\r\n .map((e, n) => (1 & n ? o : r))\r\n .join('')\r\n })\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readLine().trim())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst regex = /([?]+)/g\r\nfunction solve(e, n) {\r\n return n.replace(regex, (t, s, i) => {\r\n let r = 'R' === s ? 'B' : 'R'\r\n if (i + s.length < e) {\r\n const e = n[i + s.length]\r\n r = 'R' === e ? (1 & s.length ? 'B' : 'R') : 1 & s.length ? 'R' : 'B'\r\n }\r\n const o = 'R' === r ? 'B' : 'R'\r\n return s\r\n .split('')\r\n .map((e, n) => (1 & n ? o : r))\r\n .join('')\r\n })\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readLine().trim())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n) {\r\n return n.replace(/([RB])?([?]+)/g, (e, n, t) => {\r\n const i = 'R' === n ? 'B' : 'R',\r\n s = 'R' === i ? 'B' : 'R'\r\n return (\r\n (n || '') +\r\n t\r\n .split('')\r\n .map((e, n) => (1 & n ? s : i))\r\n .join('')\r\n )\r\n })\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readLine().trim())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n) {\r\n return n.replace(/([RB])?([?]+)([RB])?/g, (e, n, t, i) => {\r\n if (null == n) {\r\n if (void 0 === i)\r\n return t\r\n .split('')\r\n .map((e, n) => (1 & n ? 'R' : 'B'))\r\n .join('')\r\n const e =\r\n 'R' === i ? (1 & t.length ? 'B' : 'R') : 1 & t.length ? 'R' : 'B',\r\n n = 'R' === e ? 'B' : 'R'\r\n return (\r\n t\r\n .split('')\r\n .map((t, i) => (1 & i ? n : e))\r\n .join('') + i\r\n )\r\n }\r\n const s = 'R' === n ? 'B' : 'R',\r\n r = 'R' === s ? 'B' : 'R'\r\n return (\r\n n +\r\n t\r\n .split('')\r\n .map((e, n) => (1 & n ? r : s))\r\n .join('') +\r\n (i || '')\r\n )\r\n })\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber(), e.readLine().trim())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}], "src_uid": "280487a73e6070a7dc7deb44332d6319"} {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n if (ch % 2 === 0) {\n return 2\n } else if (ch % 3 === 0) {\n return 3\n } else if (ch % 5 === 0) {\n return 5\n } else if (ch % 7 === 0) {\n return 7\n } else {\n for (x = 11; x <= ch; x++) {\n if (ch % x === 0) {\n return x;\n }\n }\n };\n }\n\n \n const k = +tests[i][1] - 1;\n let n = +tests[i][0] + getMinDel(+tests[i][0]);\n\n process.stdout.write(`${n + (2 * k)}\\n`);\n }\n});", "positive_code": [{"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n //if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n t: line\n });\n /*} else {\n cases[cases.length - 1].arr = line;\n }*/\n\n const isProcessing = cases.length < problem.T;// || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, k] = data.t.split(' ').map(i => +i);\n let num = n;\n let i = 1;\n\n num += f(num); \n num += (k - 1) * 2;\n \n return num;\n}\n\nconst f = n => {\n for(let i = 2; i <= Math.pow(n, 2); i++) {\n if(n % i == 0) return i;\n }\n return n;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "function divisors(n, k) {\n if (n % 2 != 0) {\n var divisor;\n for (var i = 2; i <= n; i++) {\n if (n % i == 0) {\n divisor = i;\n break;\n }\n }\n n += divisor;\n k--;\n\n n += 2 * k;\n } else {\n n += 2 * k;\n }\n return n;\n}\nvar t = parseInt(readline());\n\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = divisors(n, k);\n print(res);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [n, k] = d.split(' ').map(Number);\n\n for (let i = 2; i <= n; i++) {\n if (n % i === 0) {\n n += i;\n break;\n }\n }\n k--;\n\n n += k * 2;\n\n ans += `${n}\\n`;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var t = Number(readline());\nvar inp;\nfor(var i = 0; i < t ; i++){\n inp = readline().split(' ').map(cur => Number(cur));\n for (var j = 2; j <= inp[0] ; j++){\n if(inp[0]%j === 0) break;\n }\n print(inp[0] + j + 2*(inp[1] - 1));\n }\n\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n \nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n \n let [n, k] = d.split(' ').map(Number);\n \n for (let i = 2; i <= n; i++) {\n if (n % i === 0) {\n n += i;\n break;\n }\n }\n k--;\n \n n += k * 2;\n \n ans += `${n}\\n`;\n \n c++;\n});\n \nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n5 1\n8 2\n3 4\n\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let c = parseInt(readLine());\n for (var j = 0; j < c; j++) {\n let arr = readLine()\n .split(' ')\n .map(value => parseInt(value))\n var n = arr[0];\n var k = arr[1];\n // console.log(\"n vs k: \", n, k);\n if (n % 2 == 0) {\n console.log(n + 2 * k);\n } else {\n let f = 0;\n for (var i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n += i;\n f = 1;\n break;\n }\n }\n // console.log(\"f: \", f);\n if (f == 0) {\n n += n;\n };\n console.log(n + (k - 1) * 2);\n }\n }\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n for (j = 2; j <= 9; j++) {\n if (ch % j === 0) {\n return j;\n }\n }\n }\n \n const k = +tests[i][1];\n let newN = +tests[i][0] + getMinDel(+tests[i][0]);\n\n process.stdout.write(`${newN + 2 * (k - 1)}\\n`);\n }\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n for (j = 2; j <= 9; j++) {\n if (ch % j === 0) return j;\n }\n }\n \n const k = +tests[i][1] - 1;\n let n = +tests[i][0] + getMinDel(+tests[i][0]);\n\n process.stdout.write(`${n + (2 * k)}\\n`);\n }\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n if (ch % 2 === 0) {\n return 2\n } else if (ch % 3 === 0) {\n return 3\n } else if (ch % 5 === 0) {\n return 5\n } else if (ch % 7 === 0) {\n return 7\n } else {\n return ch;\n }\n }\n\n \n const k = +tests[i][1] - 1;\n let n = +tests[i][0] + getMinDel(+tests[i][0]);\n\n process.stdout.write(`${n + (2 * k)}\\n`);\n }\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n if (ch % 2 === 0) return 2;\n if (ch < 10) return ch;\n if (ch % 3 === 0) return 3;\n if (ch % 5 === 0) return 5;\n }\n \n const k = +tests[i][1];\n let newN = +tests[i][0] + getMinDel(tests[i][0]);\n\n process.stdout.write(`${newN + 2 * k - 1}\\n`);\n }\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' '));\n}).on('close', () => {\n for (i = 1; i < tests.length; i++) {\n \n const getMinDel = (ch) => {\n if (ch % 2 === 0) return 2;\n if (ch < 10) return ch;\n if (ch % 3 === 0) return 3;\n if (ch % 5 === 0) return 5;\n }\n \n const k = +tests[i][1];\n let newN = +tests[i][0] + getMinDel(+tests[i][0]);\n\n process.stdout.write(`${newN + 2 * (k - 1)}\\n`);\n }\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n5 1\n8 2\n3 4\n\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n5 1\n8 2\n3 4\n\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r Number(cur));\n if (inp[0]%2 === 0){\n print(inp[0] + 2*inp[1])\n }else{\n var d = inp[0];\n for (var j = 3; j <= Math.sqrt(inp[0]); j += 2){\n (inp[0]%j === 0) ? d = j : null;\n }\n print(inp[0] + d + 2*(inp[1] - 1));\n }\n}\n\n"}], "src_uid": "9fd9bc0a037b2948d60ac2bd5d57740f"} {"source_code": "print(function() {\n var data = rn(); \n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n return Math.sqrt(cities[i].key1);\n }\n }\n return -1;\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}", "positive_code": [{"source_code": "function main() {\n\n var first = readline().split(' ').map(Number);\n var n=first[0],s=first[1];\n var arr=[];\n for(var m=0;m=1000000){\n print(newarr[j][0]);\n break;\n }\n }\n }\n}\n\nmain();"}, {"source_code": "var firstLine = readline().split(\" \").map(Number);\nvar n = firstLine[0];\nvar s = firstLine[1];\n\nfunction city(x, y, p){\n\tthis.x = x\n\tthis.y = y\n\tthis.p = p\n\tthis.distance = function(){return Math.sqrt(this.x*this.x + this.y*this.y)}\n}\n\n// city.prototype.distance = function(){\n// \treturn Math.sqrt(this.x*this.x + this.y*this.y)\n// }\n\nvar cities = []\n\nfor(i = 0; i < n; i++){\n\tdata = readline().split(\" \").map(Number);\n\tcities.push(new city(data[0], data[1], data[2]))\n}\n\ncities.sort(function(a,b){return a.distance() - b.distance()})\n\nvar notMega = true\nvar myDistance = 0\n\nwhile(notMega && cities.length !== 0 ){\n\tnextCity = cities.shift()\n\ts += nextCity.p\n\tif(s >= 1000000){\n\t\tnotMega = false\n\t\tmyDistance = nextCity.distance()\n\t}\n}\n\nif(notMega){\n\tprint(-1)\n}\nelse{\n\tprint(myDistance)\n}"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar numCities = data[0], totalPopulation = data[1];\n\tvar cities = [];\n\tfor (var i = 0; i < numCities; ++i) {\n\t\tdata = tokenizeIntegers(readline());\n\t\tvar x = data[0], y = data[1], population = data[2];\n\t\tcities.push({ distanceSquared: x*x + y*y, population: population });\n\t}\n\tcities.sort(function (a, b) {\n\t\treturn a.distanceSquared - b.distanceSquared;\n\t});\n\tfor (var i = 0; i < cities.length; ++i) {\n\t\ttotalPopulation += cities[i].population;\n\t\tif (totalPopulation >= 1000000) {\n\t\t\tprint(Math.sqrt(cities[i].distanceSquared));\n\t\t\treturn;\n\t\t}\n\t}\n\tprint(-1);\n}\n\nmain();\n"}, {"source_code": "print(function() {\n var data = rn();\n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n return Math.sqrt(cities[i].key1);\n \n }\n }\n return -1;\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}\n\n "}, {"source_code": "print(function() {\n var data = rn();\n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n return Math.sqrt(cities[i][0]);\n \n }\n }\n return -1;\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}\n\n "}, {"source_code": "print(function() {\n var data = rn(); \n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n return Math.sqrt(cities[i][0]);\n }\n }\n return -1;\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}], "negative_code": [{"source_code": "print(function() {\n var data = rn();\n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n return Math.sqrt(cities[i][0]);\n \n }\n }\n return -1;\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}\n\n "}, {"source_code": "print(function() {\n var data = rn();\n var n = data[0];\n var s = data[1];\n var cities=[];\n for(var i=0; i=1000000) {\n print(Math.sqrt(cities[i].key1));\n return;\n }\n }\n print(-1);\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}\n\n "}, {"source_code": "print(function() {\n var n = +readline();\n var s = +readline();\n var cities=[];\n for(var i=0; i=1000000) {\n print(Math.sqrt(cities[i].key1));\n return;\n }\n }\n print(-1);\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}\n\n "}, {"source_code": "print(function() {\n var n = +readline();\n var s = +readline();\n var cities=[];\n for(var i=0; i=1000000) {\n print(Math.sqrt(cities[i].key1));\n return;\n }\n }\n print(-1);\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "function main() {\n\n var first = readline().split(' ').map(Number);\n var n=first[0],s=first[1];\n var arr=[];\n for(var m=0;m1000000){\n print(newarr[j][0]);\n break;\n }\n }\n }\n}\n\nmain();"}, {"source_code": "var firstLine = readline().split(\" \").map(Number);\nvar n = firstLine[0];\nvar s = firstLine[1];\n\nfunction city(x, y, p){\n\tthis.x = x\n\tthis.y = y\n\tthis.p = p\n\tthis.distance = function(){return Math.sqrt(this.x*this.x + this.y*this.y)}\n}\n\n// city.prototype.distance = function(){\n// \treturn Math.sqrt(this.x*this.x + this.y*this.y)\n// }\n\nvar cities = []\n\nfor(i = 0; i < n; i++){\n\tdata = readline().split(\" \").map(Number);\n\tcities.push(new city(data[0], data[1], data[2]))\n}\n\ncities.sort(function(a,b){return a.distance - b.distance})\n\nvar notMega = true\nvar myDistance = 0\n\nwhile(notMega && cities.length !== 0 ){\n\tnextCity = cities.shift()\n\ts += nextCity.p\n\tif(s >= 1000000){\n\t\tnotMega = false\n\t\tmyDistance = nextCity.distance()\n\t}\n}\n\nif(notMega){\n\tprint(-1)\n}\nelse{\n\tprint(myDistance)\n}"}], "src_uid": "bcc758394d012519f0865479b3c6770c"} {"source_code": "function countingSort(arr, n){\n\n var min = arr[0];\n var max = arr[0];\n\n for(var i = 0; i < n; i++) {\n if(arr[i] < min ) {\n min = arr[i]\n } else if(arr[i] > max)\n max = arr[i]\n }\n\n var i = min;\n var j = 0;\n var len = arr.length;\n var count = [];\n\n \n\n for (var i = 0; i <= max; i++) {\n count[i] = 0;\n }\n for (var i = 0; i < len; i++) {\n count[arr[i]] += 1;\n }\n for (var i = min; i <= max; i++) {\n while (count[i] > 0) {\n arr[j] = i;\n j++;\n count[i]--;\n }\n }\n return arr;\n}\n\nvar input = readline().split(' ');\nvar n = +input[0];\nvar m = +input[1];\n// print(n)\n \nvar A = new Array(m + 1);\nvar copy = new Array(n).fill(0);\nfor (var i=0; i < A.length; i++){\n A[i] = copy.slice(0);\n}\n\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n for (var j = m - 1 ; j > -1; j--) {\n if(row[j] == '0') A[j][i] = 0;\n else {\n A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])\n } \n }\n}\n\n\nvar maxArea = 0;\nfor (var i = 0; i < m; i++) {\n A[i] = countingSort(A[i],n);\n for (var j = 0; j < n; j++)\n if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)\n}\nprint(maxArea);", "positive_code": [{"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;\n\n readints = function() {\n var x, _i, _len, _ref, _results;\n _ref = readline().split(' ');\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n x = _ref[_i];\n _results.push(x | 0);\n }\n return _results;\n };\n\n _ref = readints(), n = _ref[0], m = _ref[1];\n\n a = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(readline());\n }\n return _results;\n })();\n\n l = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(0);\n }\n return _results;\n })();\n\n z = (function() {\n _results = [];\n for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }\n return _results;\n }).apply(this);\n\n z1 = Array(n);\n\n res = 0;\n\n for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {\n zn = z0 = 0;\n for (_k = 0, _len = z.length; _k < _len; _k++) {\n x = z[_k];\n if (a[x][i] === '0') {\n l[x] = 0;\n z[z0++] = x;\n } else {\n l[x]++;\n z1[zn++] = x;\n }\n }\n for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {\n res = Math.max(res, l[z1[j]] * (zn - j));\n z[z0++] = z1[j];\n }\n }\n\n print(res);\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;\n\n readints = function() {\n var x, _i, _len, _ref, _results;\n _ref = readline().split(' ');\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n x = _ref[_i];\n _results.push(x | 0);\n }\n return _results;\n };\n\n _ref = readints(), n = _ref[0], m = _ref[1];\n\n a = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(readline().split(''));\n }\n return _results;\n })();\n\n l = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(0);\n }\n return _results;\n })();\n\n z = (function() {\n _results = [];\n for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }\n return _results;\n }).apply(this);\n\n z1 = Array(n);\n\n res = 0;\n\n for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {\n zn = z0 = 0;\n for (_k = 0, _len = z.length; _k < _len; _k++) {\n x = z[_k];\n if (a[x][i] === '0') {\n l[x] = 0;\n z[z0++] = x;\n } else {\n l[x]++;\n z1[zn++] = x;\n }\n }\n for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {\n res = Math.max(res, l[z1[j]] * (zn - j));\n z[z0++] = z1[j];\n }\n }\n\n print(res);\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;\n\n readints = function() {\n var x, _i, _len, _ref, _results;\n _ref = readline().split(' ');\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n x = _ref[_i];\n _results.push(x | 0);\n }\n return _results;\n };\n\n _ref = readints(), n = _ref[0], m = _ref[1];\n\n a = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(readline());\n }\n return _results;\n })();\n\n l = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(0);\n }\n return _results;\n })();\n\n z = (function() {\n _results = [];\n for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }\n return _results;\n }).apply(this);\n\n z1 = Array(n);\n\n res = 0;\n\n for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {\n zn = z0 = 0;\n for (_k = 0, _len = z.length; _k < _len; _k++) {\n x = z[_k];\n if (a[x].charAt(i) === '0') {\n l[x] = 0;\n z[z0++] = x;\n } else {\n l[x]++;\n z1[zn++] = x;\n }\n }\n for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {\n res = Math.max(res, l[z1[j]] * (zn - j));\n z[z0++] = z1[j];\n }\n }\n\n print(res);\n\n}).call(this);\n"}, {"source_code": "var line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\nvar i, j, acc;\nvar counts = new Array(m);\nfor (j = 0; j < m; j++) {\n counts[j] = new Int16Array(5001);\n}\n\nfor (i = 0; i < n; i++) {\n line = readline();\n acc = line[m-1] === '0' ? 0 : 1;\n counts[m-1][acc]++;\n for (j = m-2; j >= 0; j--) {\n if (line[j] === '1') {\n counts[j][++acc]++;\n } else {\n acc = 0;\n }\n }\n}\n\nvar maxArea = 0;\n\nfor (j = 0; j < m; j++) {\n acc = 0;\n for (i = 5000; i > 0; i--) {\n acc += counts[j][i];\n if (acc*i > maxArea) {\n maxArea = acc*i;\n }\n }\n}\n\nprint(maxArea);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var a, i, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _len1, _ref, _ref1, _results;\n\n readints = function() {\n var x, _i, _len, _ref, _results;\n _ref = readline().split(' ');\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n x = _ref[_i];\n _results.push(x | 0);\n }\n return _results;\n };\n\n _ref = readints(), n = _ref[0], m = _ref[1];\n\n a = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(readline().split(''));\n }\n return _results;\n })();\n\n l = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {\n _results.push(0);\n }\n return _results;\n })();\n\n z = (function() {\n _results = [];\n for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }\n return _results;\n }).apply(this);\n\n res = 0;\n\n for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {\n z0 = [];\n z1 = [];\n for (_k = 0, _len = z.length; _k < _len; _k++) {\n x = z[_k];\n if (a[x][i] === '0') {\n z0.push(x);\n l[x] = 0;\n } else {\n z1.push(x);\n l[x]++;\n }\n }\n zn = z1.length;\n for (_l = 0, _len1 = z1.length; _l < _len1; _l++) {\n x = z1[_l];\n res = Math.max(res, l[x] * zn);\n zn--;\n }\n z = z0.concat(z1);\n }\n\n print(res);\n\n}).call(this);\n"}], "negative_code": [{"source_code": "function countingSort(arr, n){\n\n var min = arr[0];\n var max = arr[0];\n\n for(var i = 0; i < n; i++) {\n if(arr[i] < min ) {\n min = arr[i]\n } else if(arr[i] > max)\n max = arr[i]\n }\n\n var i = min;\n var j = 0;\n var len = arr.length;\n var count = [];\n\n \n\n for (var i = 0; i <= max; i++) {\n count[i] = 0;\n }\n for (var i = 0; i < len; i++) {\n count[arr[i]] += 1;\n }\n for (var i = min; i <= max; i++) {\n while (count[i] > 0) {\n arr[j] = i;\n j++;\n count[i]--;\n }\n }\n return arr;\n}\n\nvar input = readline().split(' ');\nvar n = +input[0];\nvar m = +input[1];\n// print(n)\n \nvar A = new Array(m + 1);\nvar copy = new Array(n).fill(0);\nfor (var i=0; i < A.length; i++){\n A[i] = copy.slice(0);\n}\n\n\n\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n for (var j = m - 1 ; j > -1; j--) {\n if(row[j] == '0') A[j][i] = 0;\n else {\n A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])\n } \n \n \n \n }\n}\n\nvar maxArea = 0;\nfor (var i = 0; i < m - 1; i++) {\n A[i] = countingSort(A[i],n) \n for (var j = 0; j < n; j++)\n if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)\n}\nprint(maxArea);"}, {"source_code": "function countingSort(arr, n){\n var min = arr[0];\n var max = arr [0];\n\n for(i; i < n; i++) {\n if(arr[i] < min ) {\n min = arr[i]\n } else if(arr[i] > max)\n max = arr[i]\n }\n\n var i = min;\n var j = 0;\n var len = arr.length;\n var count = [];\n\n \n\n for (i; i <= max; i++) {\n count[i] = 0;\n }\n for (i = 0; i < len; i++) {\n count[arr[i]] += 1;\n }\n for (i = min; i <= max; i++) {\n while (count[i] > 0) {\n arr[j] = i;\n j++;\n count[i]--;\n }\n }\n return arr;\n};\n\nvar input = readline().split(' ');\nvar n = +input[0];\nvar m = +input[1];\n// print(n)\n \nvar A = {};\n \n// var row = readline().split('');\n \nfor (var i = 0; i < n; i++) {\n \n var row = readline().split('');\n \n for (var j = 0; j < m; j++) {\n if (!A[j]) A[j] = [];\n if (row[j] == 0 || j == 0) { A[j][i] = Number(row[j]); continue; }\n A[j][i] = Math.max((A[j - 1][i] + 1), Number(row[j]));\n }\n}\n \nvar maxArea = 0;\nfor (var i = 0; i < m; i++) {\n A[i] = countingSort(A[i],n)\n for (var j = 0; j < n; j++)\n if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)\n}\nprint(maxArea);"}, {"source_code": "var input = readline().split(' ');\nvar n = +input[0];\nvar m = +input[1];\n// print(n)\n \nvar A = new Array(m + 1);\nvar copy = new Array(n).fill(0);\nfor (var i=0; i < A.length; i++){\n A[i] = copy.slice(0);\n}\n\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n for (var j = m - 1 ; j > -1; j--) {\n if(row[j] == '0') A[j][i] = 0;\n else {\n A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])\n } \n }\n}\n\n\nvar maxArea = 0;\nfor (var i = 0; i < m; i++) {\n A[i].sort()\n for (var j = 0; j < n; j++)\n if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)\n}\nprint(maxArea);"}, {"source_code": "var line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\nvar rows = new Array(n);\nvar i, j;\n\nfor (i = 0; i < n; i++) {\n line = readline().split(' ');\n rows[i] = new Int8Array(m);\n rows[i][m-1] = parseInt(line[m-1]);\n for (j = m-2; j >= 0; j--) {\n if (line[j] === '1') {\n rows[i][j] = 1 + rows[i][j+1];\n }\n }\n}\n\nvar maxArea = 0, area;\nvar cmp = function (a, b) {\n return a[j] - b[j];\n};\n\nfor (j = 0; j < m; j++) {\n rows.sort(cmp);\n for (i = 0; i < n; i++) {\n area = (n-i)*rows[i][j];\n if (area > maxArea) {\n maxArea = area;\n }\n }\n}\n\nprint(maxArea);\n"}], "src_uid": "0accc8b26d7d684aa6e60e58545914a8"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e= 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)\n console.log(k[k.length- 1] - k[0])\n }\n }\n});", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var a = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)\n console.log(a[a.length - 1] - a[0])\n \n }\n }\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num*2) {\n dealInput(rows);\n }\n }\n});\nconst dealInput = (rows) => {\n let location = []\n rows.forEach(item => {\n location.push(item.split(' '))\n })\n location.forEach((item,index) => {\n if(index%2 !== 0) {\n let max = Math.max(...item)\n let min = Math.min(...item)\n console.log(max-min);\n }\n })\n rl.close();\n};\n\nrl.on('close', () => {\n process.exit(0);\n});\n\t\t\t \t \t\t \t \t \t\t \t \t \t\t\t\t\t"}, {"source_code": "let line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n let input = line.trim().split('\\n'); \n for (let i = 1; i < input.length;) { \n let arrayLength = input[i];\n i += 1;\n let row = input[i].split(' ').map(x => Number(x));\n row.sort((a, b) => a - b);\n console.log(row[arrayLength - 1] - row[0]);\n i += 1;\n }\n});\n \t\t \t\t\t \t\t \t \t \t \t \t\t \t"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline().split(' ').map(Number);\r\n console.log(Math.max(...arr)-Math.min(...arr));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline()\r\n .split(' ')\r\n .map(Number)\r\n .sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr[len - 1] - arr[0]);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tests = parseInt(readline());\r\n while (tests--) {\r\n let len = parseInt(readline());\r\n let arr = readline()\r\n .split(' ')\r\n .sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr[len - 1] - arr[0]);\r\n }\r\n}\r\n"}, {"source_code": "let line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n let input = line.trim().split('\\n'); \n for (let i = 1; i < input.length;) { \n const arrayLength = input[i];\n i += 1;\n let row = input[i].split(' ').map(x => Number(x));\n row.sort((a, b) => a - b);\n console.log(row[arrayLength - 1] - row[0]);\n i += 1;\n }\n});\n \t\t \t\t \t \t\t\t \t \t\t \t \t \t \t\t"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n let line=buf.split('\\n');\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=2*t;i+=2)\r\n {\r\n let arr=line[i+1].split(' ').map(x=>{ return parseInt(x) });\r\n let mx=0;\r\n let mn=1e10;\r\n for(let j=0;j{ return parseInt(x) });\r\n let mx=0;\r\n let mn=1e10;\r\n for(let j=0;j data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet a = nl.nums();\n\t\t//let min = a.reduce((a, b) => (a < b)?a:b, 1000000000);\n\t\t//let max = a.reduce((a, b) => (a > b)?a:b, 0);\n\t\tlet min = Math.min.apply(null, a);\n\t\tlet max = Math.max.apply(null, a);\n\t\tans.push(max - min);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet a = nl.nums();\n\t\tlet min = a.reduce((a, b) => (a < b)?a:b, 1000000000);\n\t\tlet max = a.reduce((a, b) => (a > b)?a:b, 0);\n\t\tans.push(max - min);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n\r\n input = input.filter((el, idx) => idx % 2 !== 0);\r\n\r\n input = input.map((el) =>\r\n el\r\n .trim()\r\n .split(\" \")\r\n .map((el) => +el.trim())\r\n .sort((a, b) => a - b)\r\n );\r\n\r\n input.forEach((el) => {\r\n console.log(el[el.length - 1] - el[0]);\r\n });\r\n});\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0 || c % 2 !== 0) {\n c++;\n return;\n }\n\n const digits = d.split(\" \").map(Number);\n const min = Math.min(...digits);\n const max = Math.max(...digits);\n console.log(max - min);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 2; i < input.length; i+=2) {\r\n let nums = input[i].split(' ').map(Number);\r\n let [min, max] = [Math.min(...nums), Math.max(...nums)];\r\n ans.push(max-min);\r\n }\r\n console.log(ans.join('\\n'));\r\n});"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let a = readline().split(' ').map(Number)\r\n console.log(solve(n, a))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, arr) => {\r\n if( n == 1 ) return 0\r\n if( n == 2 ) return Math.abs( arr[0] - arr[1] )\r\n\r\n arr = sortArray( arr )\r\n \r\n let min = minOfArray( arr )\r\n let max = maxOfArray( arr )\r\n\r\n return max - min\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n console.log(k[e - 1] - k[0]);\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar max = 0;\r\n\t\tvar min = Math.pow(10, 9) + 1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t\tmin = Math.min(min, list[i]);\r\n\t\t}\r\n\t\tmyout(max - min);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = parseInt(readLine());\n while (t-- > 0) {\n solve();\n }\n}\n\nlet count=0;\nfunction solve() {\n let str = readLine();\n\n let c = readLine();\n\n\n var d = c.split(' ');\n var digits = d.map(iNum => parseInt(iNum, 10));\n\n count = Math.max(...digits) - Math.min(...digits);\n console.log(count)\n\n}\n\n"}, {"source_code": "var i = -1\nrequire('readline').createInterface(process.stdin,process.stdout).on('line', (line) => {\n if (++i && !(i%2)) {\n const a = line.split(\" \").map(Number);\n console.log(Math.max(...a) - Math.min(...a))\n };\n});\n\n"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n for (let i = 0; i < testCases; i++) {\r\n let arrSize = +input[z++];\r\n let arr = input[z++].split(' ').map(t=>Number(t));\r\n let max = Math.max(...arr);\r\n let min = Math.min(...arr);\r\n console.log(max-min);\r\n }\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N;\r\n let arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ').map(Number);\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, arr) {\r\n const [minVal, maxVal] = [Math.min(...arr), Math.max(...arr)];\r\n\r\n console.log(maxVal - minVal);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let len=readLine();\r\n let arr=readLine().split(\" \");\r\n arr.sort((a,b)=>parseInt(a)-parseInt(b));;\r\n console.log(arr[len-1]-arr[0]);\r\n}"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve(){\r\n\t let n = inputReader.readNumber();\r\n\t let a = inputReader.readArray();\r\n\t let max = Math.max(...a);\r\n\t let min = Math.min(...a);\r\n\t console.log(max - min);\r\n\t}\r\n\t\r\n\twhile(t--){\r\n\t solve(); \r\n\t}\r\n\t\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readArray() {\r\n\t\treturn _inputLines[_lineNumber++].split(' ');\r\n\t}\r\n\t\t\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadArray,\r\n\t\treadNumber,\r\n\t}\r\n}"}, {"source_code": "var di\r\nvar stdin_input = \"\"\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding(\"ascii\")\r\nprocess.stdin.on(\"data\", (input) => { stdin_input += input })\r\nprocess.stdin.on(\"end\", () => { main() })\r\n\r\nconst rl = () => di.next().value.trim(); //Read line\r\nconst rn = () => +rl(); //Read number\r\nconst ra = () => rl().split(' '); //Read array\r\nconst rna = () => ra().map(x => +x); //Read array of numbers\r\nconst l = i => {console.log(i)} //Return answer\r\n\r\nconst main = () => {\r\n di = stdin_input.split('\\n').values()\r\n let T = rn();\r\n while (T--) {\r\n const _ = rn();\r\n const a = rna();\r\n l(Math.max(...a) - Math.min(...a));\r\n\t}\r\n}"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; i{\r\n\r\n let arrNum = arr.map(el=>parseInt(el));\r\n\r\n arrNum.sort((a,b)=>a-b);\r\n\r\n let cSum = 0;\r\n for(let i =0; i+1 i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n\r\n let count = 2;\r\n for (let i = 0; i < lines[0]; ++i) {\r\n let total = 0;\r\n const arr = lines[count].split(' ').map((el) => +el);\r\n\r\n arr.sort((a, b) => b - a);\r\n\r\n const len = arr.length;\r\n\r\n if (len > 1) {\r\n const max = arr[0];\r\n for (let i = 1; i < len; ++i) {\r\n const curDiff = max - arr[i];\r\n total += curDiff;\r\n for (let j = i + 1; j < len; ++j) {\r\n arr[j] += curDiff;\r\n }\r\n }\r\n }\r\n console.log(total);\r\n\r\n count += 2;\r\n }\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline();\r\n let a = readline().split(\" \").map(w => parseInt(w))\r\n var max = -1, min = 100000000000;\r\n for(var i=0;i {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const tsc = await readInt();\r\n for(let sc = 0; sc < tsc; sc++) {\r\n const n = await readInt();\r\n const a = await readIntArray();\r\n a.sort((a,b) => a - b);\r\n console.log(a[a.length - 1] - a[0]);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n const sarr = arr.sort((a, b) => a - b)\r\n const max = sarr[0], min = sarr[sarr.length - 1]\r\n console.log(Math.abs(min - max))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n arr.sort((a, b) => a - b)\n return arr[n - 1] - arr[0]\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst ans = Math.max(...a) - Math.min(...a);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "test = readline();\r\nwhile (test--) {\r\n readline();\r\n set = new Set()\r\n readline().split(' ').map(x => set.add(parseInt(x)));\r\n max = Math.max(...set);\r\n set = Array.from(set).sort((a, b) => b - a)\r\n steps = 0;\r\n set.forEach(num => {\r\n if (num < max) {\r\n num += steps\r\n steps += (max - num)\r\n }\r\n })\r\n print(steps)\r\n}"}, {"source_code": "test = readline();\r\nwhile (test--) {\r\n readline();\r\n set = new Set()\r\n readline().split(' ').map(x => set.add(parseInt(x)));\r\n max = Math.max(...set);\r\n set = Array.from(set).sort((a, b) => b - a)\r\n steps = 0;\r\n set.forEach(num => {\r\n if (num < max) {\r\n num += steps\r\n steps += (max - num)\r\n }\r\n })\r\n print(steps)\r\n}\r\n"}, {"source_code": "j = +readline();\r\nwhile (j--) {\r\n x = +readline();\r\n t = readline().split(\" \").map(Number);\r\n if (t.length > 1) {\r\n q = Math.max(...t);\r\n w = Math.min(...t);\r\n c = q - w;\r\n print(c);\r\n } else {\r\n print(0);\r\n }\r\n}\r\n"}, {"source_code": "test = readline();\r\nwhile (test--) {\r\n readline();\r\n set = new Set()\r\n readline().split(' ').map(x => set.add(parseInt(x)));\r\n max = Math.max(...set);\r\n set = Array.from(set).sort((a, b) => b - a)\r\n steps = 0;\r\n set.forEach(num => {\r\n if (num < max) {\r\n num += steps\r\n steps += (max - num)\r\n }\r\n })\r\n print(steps)\r\n}\r\n"}, {"source_code": "var tests=+readline()\r\nfor(var i=0;i+node)\r\nsequence.sort((a,b)=>{\r\n return a-b\r\n})\r\nprint((sequence[length-1]-sequence[0]))\r\n}"}, {"source_code": "var tests=+readline()\r\nfor(var i=0;i+node)\r\nvar min=sequence.reduce((a,b)=>Math.min(a,b))\r\nvar max=sequence.reduce((a,b)=>Math.max(a,b))\r\n\r\nprint((max-min))\r\n}"}, {"source_code": "'use strict'\r\n \r\nconst getLine = () => readline().split(' ')\r\nconst getInts = () => getLine().map(n => parseInt(n))\r\nconst getInt = () => getInts()[0]\r\nconst D = (...args) => { // D({name})\r\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\r\n}\r\n \r\nmain()\r\n \r\nfunction main() {\r\n const TC = getInt();\r\n for (let i = 0; i < TC; ++i) {\r\n const n = getInt();\r\n const arr = getInts();\r\n \r\n arr.sort((a, b) => a - b);\r\n print(arr[n - 1] - arr[0])\r\n }\r\n \r\n}"}, {"source_code": "var count = parseInt(readline());\r\n \r\nwhile (count--){\r\n var n = readline();\r\n var n1 = readline()\r\n var arr = n1.split(' ').map(Number)\r\n print(Math.max(...arr) - Math.min(...arr))\r\n}"}, {"source_code": "var count = parseInt(readline());\r\n\r\nwhile (count--){\r\n var n = readline();\r\n var n1 = readline()\r\n var arr = n1.split(' ').map(Number)\r\n print(Math.max(...arr) - Math.min(...arr))\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \").map((data) => +data)\r\n var max = -Infinity\r\n var min = Infinity\r\n for (var i = 0; i < n; i++) {\r\n max = Math.max(max, a[i])\r\n min = Math.min(min, a[i])\r\n }\r\n return max - min;\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0], e= 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)\n console.log(k[k.length] - k[0])\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var a = Number(lines[j])\n if(a % 2 === 0){\n console.log(a / 2)\n }else{\n console.log(a += 1)\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n if(j % 2 == 1){\n var a = Number(lines[j])\n if(a % 2 === 0){\n console.log(a / 2)\n }else{\n console.log(a += 1)\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n if(j % 2 == 1){\n var a = lines[j]\n if(a % 2 === 0){\n console.log(a / 2)\n }else{\n console.log(a += 1)\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n if(j % 2 == 1){\n var a = lines[j]\n if(a % 2 === 0){\n console.log(a / 2)\n }else{\n console.log(a + 1)\n }\n }\n }\n});"}, {"source_code": "let line = '';\nlet rows = [];\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n const lines = line.split('\\n');\n let input1 = +lines[0];\n \n for (let i = 1; i <= input1; i++) { \n let row = lines[i].split(' ');\n row.sort((a, b) => a - b);\n console.log(row[row.length - 1] - row[0]);\n }\n\n});\n \t\t\t \t\t\t\t\t\t\t \t\t\t\t \t\t \t \t"}, {"source_code": "j = +readline();\r\nwhile (j--) {\r\n x = +readline();\r\n t = readline().split(\" \").map(Number);\r\n if (t.length > 1) {\r\n q = Math.max(...t);\r\n w = Math.min(...t);\r\n c = q - w;\r\n print(c);\r\n } else {\r\n print(1);\r\n }\r\n}\r\n"}, {"source_code": "j = +readline();\r\nwhile (j--) {\r\n x = +readline();\r\n t = readline().split(\" \").map(Number);\r\n if (x > 1) {\r\n q = Math.max(...t);\r\n w = Math.min(...t);\r\n c = q - w;\r\n print(c);\r\n } else {\r\n print(1);\r\n }\r\n}\r\n"}], "src_uid": "cf3cfcae029a6997ee62701eda959a60"} {"source_code": "function bfs(s, adj, visited) {\n var q = [];\n var pos = 0;\n q.push(s);\n visited[s] = true;\n while (pos < q.length) {\n var u = q[pos++];\n adj[u].forEach(function (v) {\n if (!visited[v]) {\n q.push(v);\n visited[v] = true;\n }\n });\n }\n return q.length;\n}\n\n\nvar a = readline().split(\" \").map(function (x) { return parseInt(x); });\nvar n = a[0], m = a[1];\nvar adj = [];\nfor (i = 0; i <= n; ++i) {\n adj.push([]);\n}\nfor (i = 0; i < m; ++i) {\n a = readline().split(\" \").map(function (x) { return parseInt(x); });\n adj[a[0]].push(a[1]);\n adj[a[1]].push(a[0]);\n}\nvar visited = new Array(n + 1);\nfor (i = 0; i <= n; ++i) {\n visited[i] = false;\n}\nr = 1;\nfor (i = 1; i <= n; ++i) {\n if (!visited[i]) {\n var p = bfs(i, adj, visited);\n for (j = 1; j < p; ++j) {\n r = r * 2;\n }\n }\n}\nprint(r);\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n\t\tedges = {}, vertices = [];\n\tedges.add = function (u, v) {\n\t\tif (edges[u] === undefined) {\n\t\t\tedges[u] = [v];\n\t\t\tvertices.push(u);\n\t\t} else {\n\t\t\tedges[u].push(v);\n\t\t}\n\t};\n\tfor (var i = 0; i < m; ++i) {\n\t\tvar pair = tokenizeIntegers(readline()),\n\t\t\tu = pair[0], v = pair[1];\n\t\tedges.add(u, v);\n\t\tedges.add(v, u);\n\t}\n\tvar seen = {}, danger = 1;\n\tfunction dfs(u, double) {\n\t\tif (seen[u]) {\n\t\t\treturn;\n\t\t}\n\t\tseen[u] = true;\n\t\tif (double) {\n\t\t\tdanger *= 2;\n\t\t}\n\t\tvar vs = edges[u];\n\t\tfor (var i = 0; i < vs.length; ++i) {\n\t\t\tdfs(vs[i], true);\n\t\t}\n\t}\n\tfor (var i = 0; i < vertices.length; ++i) {\n\t\tvar u = vertices[i];\n\t\tdfs(u, false);\n\t}\n\tprint(danger);\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "c36f4bb34543476abc31fe986032122d"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n}); \n\nrl.on('line', input => {\n rl.on('line', input2 => {\n console.log(min(input2.split(' ').map(n => parseInt(n))));\n process.exit();\n });\n});\n\nconst min = input => {\n const min = Math.min(...input);\n const max = Math.max(...input);\n let iMin = input.lastIndexOf(min);\n let iMax = input.findIndex(e => e == max);\n let secs = 0;\n let temp = 0;\n const length = input.length - 1;\n\n return iMin > iMax ? length - iMin + iMax : length - 1 - iMin + iMax;\n\n // while(input[input.length-1] !== min) {\n // if(input[iMin+1] !== min) {\n // temp = input[iMin+1];\n // input[iMin+1] = input[iMin];\n // input[iMin] = temp;\n // secs++;\n // }\n // iMin++;\n // }\n\n // while(input[0] !== max) {\n // if(input[iMax-1] !== max) {\n // temp = input[iMax-1];\n // input[iMax-1] = input[iMax];\n // input[iMax] = temp;\n // secs++;\n // }\n // iMax--;\n // }\n\n // return secs;\n}", "positive_code": [{"source_code": "\nvar n=+readline();\nvar a=readline().split(' ').map(function(v){return+v;});\nvar min=Math.min.apply(null, a);\nvar max=Math.max.apply(null, a);\nvar minIndex = a.lastIndexOf(min);\na.splice(minIndex,1);\na.push(min);\nvar maxIndex = a.indexOf(max);\nprint( n-minIndex-1+maxIndex );"}, {"source_code": "var n = +readline(), line = readline().split(\" \"), sorted = [], cmax, cmin, buf;\nline.forEach(function(a){\n\tsorted.push(+a);\n})\nsorted.sort(function(a,b){return a-b});\n\ncmin = line.lastIndexOf(sorted[0].toString(10));\ncmax = line.indexOf(sorted[n-1].toString(10));\n\nfor(i = 1; ; i++){\n\tif( cmax > 0 ){\n\t\tbuf = line[cmax-1];\n\t\tline[cmax-1] = line[cmax];\n\t\tline[cmax] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t}\n\telse if( cmin < n-1 ){\n\t\tbuf = line[cmin+1];\n\t\tline[cmin+1] = line[cmin];\n\t\tline[cmin] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t}\n\tif( (cmax == 0) && (cmin == n-1) ){\n\t\twrite( (buf != undefined) ? i : i-1 );\n\t\tbreak;\n\t}\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [minIndex, maxIndex] = [-1, -1];\n let [min, max] = [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER];\n\n for (let i = 0; i < len; i++) {\n if (arr[i] > max) {\n max = arr[i];\n maxIndex = i;\n }\n if (arr[i] <= min) {\n min = arr[i];\n minIndex = i;\n }\n }\n const moves = maxIndex + (len - 1 - minIndex);\n if (moves > len - 2) {\n console.log(moves - 1);\n } else {\n console.log(moves);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var min = 101;\n var max = 0;\n var minIndex = -1;\n var maxIndex = -1;\n for(var i = 0; i < N; i++){\n if(min >= list[i]){\n min = list[i];\n minIndex = i;\n }\n }\n for(var i = N - 1; i >= 0; i--){\n if(max <= list[i]){\n max = list[i];\n maxIndex = i;\n }\n }\n if(maxIndex > minIndex){\n myout(maxIndex + (N - minIndex - 1) - 1);\n }else{\n myout(maxIndex + (N - minIndex - 1));\n }\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n let arr = inputs[1].split(' ').map(num => parseInt(num));\n let Pmax = arr.indexOf(Math.max(...arr));\n let Pmin = 0;\n let limiter = 0;\n const shortestHeight = Math.min(...arr);\n\n for (let i = arr.length; i > 0; i--) {\n if (arr[i] == shortestHeight && limiter == 0) {\n Pmin = i;\n limiter++\n }\n }\n\n let minSeconds;\n\n Pmin = parseInt(Pmin)\n Pmax = parseInt(Pmax)\n\n if (Pmin < Pmax) {\n minSeconds = Pmax + (arr.length - 1 - Pmin) - 1;\n } else {\n minSeconds = Pmax + (arr.length - 1 - Pmin);\n }\n\n console.log(minSeconds);\n\n})"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n let arr = inputs[1].split(' ');\n let Pmax = arr.indexOf(Math.max(...arr).toString());\n let Pmin = 0;\n let limiter = 0;\n const shortestHeight = Math.min(...arr).toString();\n\n\n for (let i = arr.length; i > 0; i--) {\n if (arr[i] == shortestHeight && limiter == 0) {\n Pmin = i;\n limiter++\n }\n }\n\n let minSeconds;\n \n Pmin = parseInt(Pmin)\n Pmax = parseInt(Pmax)\n\n if (Pmin < Pmax) {\n minSeconds = Pmax + (arr.length - Pmin) - 2;\n } else {\n minSeconds = Pmax + (arr.length - 1 - Pmin);\n }\n\n console.log(minSeconds);\n\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const a = input[1].split(' ').map(x => +x);\n let imax = 0;\n let imin = 0;\n for (let i = 1; i < a.length; i++) {\n if (a[i] > a[imax]) {\n imax = i;\n }\n else if (a[i] <= a[imin]) {\n imin = i;\n }\n }\n const maxSteps = imax;\n const minSteps = a.length - imin - 1;\n const commonSteps = +(imax > imin);\n console.log(maxSteps + minSteps - commonSteps);\n});"}, {"source_code": "//Arrival of the General\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL)[1].split(' ').map(c => +c);\n \n let maxi = 0, mini = 0;\n for(let i = 0; i < lines.length; i++) {\n \tif(lines[i] <= lines[mini]) {\n \t\tmini = i;\n \t}\n \tif(lines[i] > lines[maxi]) {\n \t\tmaxi = i;\n \t}\n }\n\n if(maxi > mini) {\n \tprocess.stdout.write((maxi + lines.length - mini - 2) + '');\n } else {\n \tprocess.stdout.write((maxi + lines.length - mini - 1) + '');\n }\n\n return;\n});"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input))+1;\nvar max_index = input.indexOf(Math.max(...input))+1;\nvar output; \nif(min_index < max_index){\n output = input.length-min_index+max_index-2;\n}else{\n output = input.length-min_index+max_index-1;\n}\nprint(output); "}, {"source_code": ";(function () {\n\n\tvar s = (readline(), readline()).split(' ').map(function (x) {return parseInt(x);});\n\n\tvar max = Math.max.apply(null, s);\n\tvar min = Math.min.apply(null, s);\n\n\tfor (var i = 0; i < s.length; i++) if (max == s[i]) break;\n\tfor (var j = s.length - 1; j >= 0; j--) if (min == s[j]) break;\n\n\tprint(i + ( s.length - j - 1 ) - ( i > j));\n\n\n}).call(this);"}, {"source_code": "'use strict';\n\nlet n = parseInt(readline());\nlet array = readline().split(' ').map(value => parseInt(value));\n\nlet max = array[0],\n min = array[0],\n time = 0;\n \nfor(let i = 0; i < array.length; i++){\n if (array[i] > max) {\n max = array[i];\n } \n \n if (array[i] < min) {\n min = array[i];\n }\n}\n\nlet maxPosition = array.indexOf(max);\n\nfor(let i=maxPosition; i > 0; i--) {\n time++;\n let temp = array[i]; \n array[i] = array[i - 1];\n array[i - 1] = temp;\n}\n\n\nlet minPosition = array.reverse().indexOf(min);\n\nwrite(time + minPosition);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n const idxMin = arr.lastIndexOf(min);\n const idxMax = arr.indexOf(max);\n\n ans += idxMax;\n\n if (idxMin > idxMax) {\n ans += Math.max(arr.length - idxMin - 1, 0);\n }\n else {\n ans += Math.max(arr.length - idxMin - 2, 0);\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n let min = 1000, minIndex = -1;\n let max = 0, maxIndex = -1;\n nums.forEach((x, i) => {\n if (x > max) {max = x; maxIndex = i}\n if (x <= min) {min = x; minIndex = i}\n });\n\n if (maxIndex < minIndex)\n console.log(maxIndex + nums.length - (minIndex + 1));\n else \n console.log(maxIndex + nums.length - (minIndex + 1) - 1);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n}); \n\nrl.on('line', input => {\n rl.on('line', input2 => {\n console.log(min(input2.split(' ').map(n => parseInt(n))));\n process.exit();\n });\n});\n\nconst min = input => {\n const min = Math.min(...input);\n const max = Math.max(...input);\n let iMin = input.lastIndexOf(min);\n let iMax = input.findIndex(e => e == max);\n let secs = 0;\n let temp = 0;\n\n while(input[input.length-1] !== min) {\n if(input[iMin+1] !== min) {\n temp = input[iMin+1];\n input[iMin+1] = input[iMin];\n input[iMin] = temp;\n secs++;\n }\n iMin++;\n }\n\n while(input[0] !== max) {\n if(input[iMax-1] !== max) {\n temp = input[iMax-1];\n input[iMax-1] = input[iMax];\n input[iMax] = temp;\n secs++;\n }\n iMax--;\n }\n\n return secs;\n}"}, {"source_code": "var n = readline();//.split(\" \");\nvar str = readline().split(\" \").map((x)=>+x);\nvar min = Math.min.apply(this, str); var max = Math.max.apply(this, str);\nvar MinIndex = str.lastIndexOf(min)+1; var MaxIndex = str.indexOf(max)+1;\n\nprint(min==+str[str.length-1]&&max==+str[0]? 0:\nMaxIndex>MinIndex? MaxIndex-1+str.length-MinIndex-1:MaxIndex-1+str.length-MinIndex);"}, {"source_code": "var n = parseInt(readline());\nvar soldiers = readline().split(' ').map(function(num){return parseInt(num)});\nvar max = Math.max(...soldiers);\nvar min = Math.min(...soldiers);\nvar indexOfMax = soldiers.indexOf(max);\nvar indexOfMin = soldiers.lastIndexOf(min);\nvar swaps = (n - (indexOfMin + 1)) + (indexOfMax);\nif(indexOfMax > indexOfMin) swaps--;\nprint(swaps);"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(' ').map(Number);\n\nvar max = Math.max.apply(null, s);\nvar min = Math.min.apply(null, s);\n\nfor (var i = 0; i < n; i++) {\n if (max === s[i]) {\n break;\n }\n}\nfor (var j = n - 1; j >= 0; j--) {\n if (min === s[j]) {\n break;\n }\n}\n\nprint(i + ( n - j - 1 ) - ( i > j));"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar time = 0;\nvar min_p = 0;\nvar min_v = 999;\nvar max_p = 0;\nvar max_v = 0;\n\nfor (var i = 0; i < a.length; i++){\n if (min_v >= a[i]) {\n min_v = a[i];\n min_p = i;\n }\n if (max_v < a[i]) {\n max_v = a[i];\n max_p = i;\n }\n}\n\nif (max_p > min_p) {\n\ttime = max_p + (a.length - 1 - min_p) - 1;\n} else {\n\ttime = max_p + (a.length - 1 - min_p);\n}\n\n\nprint (time);"}, {"source_code": "var computeSoldiersForGeneral = function(arr)\n{\n arr = arr.split(' ');\n var indexMax = 0, indexMin = 0;\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (+arr[i] > +arr[indexMax]) indexMax = i;\n if (+arr[i] <= +arr[indexMin]) indexMin = i;\n }\n if (indexMax > indexMin) return indexMax + arr.length - indexMin - 2;\n else return indexMax + arr.length - indexMin - 1;\n}\nvar input1 = readline();\nvar input = readline();\nprint(computeSoldiersForGeneral(input));"}, {"source_code": "var n = readline();\nvar soliders = readline().split(\" \");\n\nvar maxIndex = 0;\nvar minIndex = 0;\nvar swapTime = 0;\n\nfor(var i = 0; i < n; i++){\n\tmaxIndex = (parseInt(soliders[i]) > parseInt(soliders[maxIndex])) ? i : maxIndex;\n\tminIndex = (parseInt(soliders[i]) <= parseInt(soliders[minIndex])) ? i : minIndex;\n}\nif(maxIndex > minIndex)\n\tswapTime = (parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex))-1);\nelse\n\tswapTime = parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex));\nprint(swapTime);"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet sol = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet sc = 0;\n\n\tlet min = Math.min(...sol);\n\tlet max = Math.max(...sol);\n\tlet posMax = 0,\n\t\tposMin = 0;\n\n\tsol.forEach((x, i) => {\n\t\tif (x === min && i >= posMin) posMin = i + 1;\n\t\tif (x === max && posMax === 0) posMax = i + 1;\n\t});\n\n\tsc = n - posMin;\n\tif (posMax > posMin) sc += posMax - 2;\n\telse sc += posMax - 1;\n\n\tconsole.log(sc);\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const arr = input[1].split(' ').map(Number);\n let min = 101, max = 0;\n arr.forEach(v => {\n if (v < min) min = v;\n if (v > max) max = v;\n });\n let minpos = -1, maxpos = 101;\n arr.forEach((v, i) => {\n if (v == min && i > minpos) minpos = i;\n if (v == max && i < maxpos) maxpos = i;\n });\n let dist = 0;\n if (minpos < maxpos) dist -= 1;\n dist += arr.length - minpos - 1;\n dist += maxpos;\n console.log(dist);\n});"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(' ').map(Number);\n\nvar max = Math.max.apply(null, s);\nvar min = Math.min.apply(null, s);\n\nfor (var i = 0; i < n; i++) {\n if (max === s[i]) {\n break;\n }\n}\nfor (var j = n - 1; j >= 0; j--) {\n if (min === s[j]) {\n break;\n }\n}\n\nprint(i + ( n - j - 1 ) - ( i > j));"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i += 2) {\n doit(txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n}\n\nfunction doit(tab) {\n let max = tab.indexOf(Math.max(...tab));\n let score = max;\n tab.unshift(tab.splice(max, 1)[0]);\n tab.reverse();\n let min = tab.indexOf(Math.min(...tab));\n score += min;\n console.log(score);\n\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let arr = inputs[1].trim().split(' ');\n let max = Math.max(...arr);\n let min = Math.min(...arr);\n let swaps = 0;\n if (arr[0] == max && arr[arr.length - 1] == min) {\n swaps = 0;\n }\n else {\n let minIndex = arr.lastIndexOf(String(min));\n\n for (let i = minIndex + 1; i < arr.length; i++) {\n if (+arr[minIndex] < +arr[i]) {\n let temp = arr[i];\n arr[i] = arr[minIndex];\n arr[minIndex] = temp;\n minIndex = i;\n swaps++;\n }\n }\n\n let maxIndex = arr.indexOf(String(max));\n for (let i = maxIndex - 1; i >= 0; i--) {\n if (+arr[maxIndex] > +arr[i]) {\n let temp = arr[i];\n arr[i] = arr[maxIndex];\n arr[maxIndex] = temp;\n maxIndex = i;\n swaps++;\n }\n }\n }\n\n return swaps.toString();\n}\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(value => parseInt(value));\n let idxMax = arr.indexOf(Math.max(...arr));\n let min = Math.min(...arr);\n let idxMin = arr.indexOf(min);\n let arrIdxMin = [];\n while (idxMin != -1) {\n arrIdxMin.push(idxMin);\n idxMin = arr.indexOf(min, idxMin + 1);\n }\n idxMin = arrIdxMin[arrIdxMin.length - 1];\n if (idxMin < idxMax) {\n console.log(idxMax + n - idxMin - 2);\n } else {\n console.log(idxMax + n - idxMin - 1);\n }\n}"}], "negative_code": [{"source_code": "\nvar n=+readline();\nvar a=readline().split(' ').map(function(v){return+v;});\nvar min=a.indexOf( Math.min.apply(null, a) );\nvar max=a.indexOf( Math.max.apply(null, a) );\nvar ans=n-min-1+max;\nif(max==min) print(0);\nelse print(min 0 ){\n\t\tbuf = line[cmax-1];\n\t\tline[cmax-1] = line[cmax];\n\t\tline[cmax] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t}\n\telse if( cmin < n-1 ){\n\t\tbuf = line[cmin+1];\n\t\tline[cmin+1] = line[cmin];\n\t\tline[cmin] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t}\n\tif( (cmax == 0) && (cmin == n-1) ){\n\t\twrite(i);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var n = +readline(), line = readline().split(\" \"), sorted = [], cmax, cmin, buf;\nline.forEach(function(a){\n\tsorted.push(+a);\n})\nsorted.sort(function(a,b){return a-b});\n\ncmin = line.lastIndexOf(sorted[0].toString(10));\ncmax = line.indexOf(sorted[n-1].toString(10));\n\nfor(i = 1; ; i++){\n\tif( cmax > 0 ){\n\t\tbuf = line[cmax-1];\n\t\tline[cmax-1] = line[cmax];\n\t\tline[cmax] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t\tcontinue;\n\t}\n\telse if( cmin < n-1 ){\n\t\tbuf = line[cmin+1];\n\t\tline[cmin+1] = line[cmin];\n\t\tline[cmin] = buf;\n\t\tcmin = line.lastIndexOf(sorted[0].toString(10));\n\t\tcmax = line.indexOf(sorted[n-1].toString(10));\n\t}\n\tif( (cmax == 0) && (cmin == n-1) ){\n\t\twrite(i);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar temp = input[min_index];\ninput[min_index] = input[input.length - 1];\ninput[input.length - 1] = temp;\nvar max_index = input.indexOf(Math.max(...input));\nvar output = input.length-min_index+max_index;\nprint(output);"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar max_index = input.indexOf(Math.max(...input));\nprint(2*input.length-min_index-max_index-1);"}, {"source_code": "\nvar w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar max_index = input.indexOf(Math.max(...input));\nprint(max_index-1+input.length-min_index+1-1);"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar temp = input[min_index];\ninput[min_index] = input[input.length - 1];\ninput[input.length - 1] = temp;\nvar max_index = input.indexOf(Math.max(...input));\nvar output = ((input.length-1)-min_index)+max_index;\nprint(output);"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar max_index = input.indexOf(Math.max(...input));\nprint(2*input.lenth-min_index-max_index-1);"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar max_index = input.indexOf(Math.max(...input));\nprint(max_index-1+input.length-1-min_index);"}, {"source_code": "var w = readline();\nvar input = readline().split(\" \").map(x=>parseInt(x));\nvar min_index = input.lastIndexOf(Math.min(...input));\nvar max_index = input.indexOf(Math.max(...input));\nprint(max_index+input.length-min_index-1);"}, {"source_code": "var n = readline();//.split(\" \");\nvar str = readline().split(\" \").map((x)=>+x);\nvar min = Math.min.apply(this, str); var max = Math.max.apply(this, str);\nvar MinIndex = str.lastIndexOf(min)+1; var MaxIndex = str.lastIndexOf(max)+1;\n\nprint(MaxIndex>MinIndex? MaxIndex-1+str.length-MinIndex-1:MaxIndex-1+str.length-MinIndex);"}, {"source_code": "var n = readline();//.split(\" \");\nvar str = \"100 95 100 100 88\".split(\" \").map((x)=>+x);\nvar min = Math.min.apply(this, str); var max = Math.max.apply(this, str);\nvar MinIndex = str.lastIndexOf(min)+1; var MaxIndex = str.lastIndexOf(max)+1;\n\nprint(MaxIndex>MinIndex? MaxIndex-1+str.length-MinIndex-1:MaxIndex-1+str.length-MinIndex);"}, {"source_code": "var n = readline();\nvar m = readline().split(\" \");\nvar min = 0; var max = 0;\n\t\tfor (var i=0; i<+n; i++){\n\t\t\tif (m[i]==Math.min.apply(this,m))//m[i+1]&&min<=m[i+1]){\n\t\t\t\tmin = n-(i+1);\t\t\n\t\t\telse if (m[i]==Math.max.apply(this, m))\n\t\t\tmax = (i+1)-1; \n\t\t}\n\tprint(min+max-1);"}, {"source_code": "var n = readline();\nvar m = readline().split(\" \");\nvar temp = 0;\nvar res = 0;\n\tfor (var j=0; j<+2; j++){\n\t\tfor (var i=0; i<+n; i++){\n\t\t\tif (m[i]+x);\nvar min = Math.min.apply(this, str); var max = Math.max.apply(this, str);\nvar MinIndex = str.lastIndexOf(min)+1; var MaxIndex = str.lastIndexOf(max)+1;\n\nprint(min==+str[str.length-1]&&max==+str[0]? 0:\nMaxIndex>MinIndex? MaxIndex-1+str.length-MinIndex-1:MaxIndex-1+str.length-MinIndex);"}, {"source_code": "var n = readline();\nvar soliders = readline().split(\" \");\n\nvar maxIndex = 0;\nvar minIndex = 0;\nvar swapTime = 0;\n\nfor(var i = 0; i < n; i++){\n\tmaxIndex = (soliders[i] > soliders[maxIndex]) ? i : maxIndex;\n\tminIndex = (soliders[i] <= soliders[minIndex]) ? i : minIndex;\n}\n\nif(maxIndex > minIndex)\n\tswapTime = (parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex))-1);\nelse\n\tswapTime = parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex));\nprint(swapTime);"}, {"source_code": "var n = readline();\nvar soliders = readline().split(\" \");\n\nvar maxIndex = 0;\nvar minIndex = 0;\nvar swapTime = 0;\n\nfor(var i = 0; i < n; i++){\n\tmaxIndex = (parseInt(soliders[i]) > parseInt(soliders[maxIndex])) ? i : maxIndex;\n\tminIndex = (parseInt(soliders[i]) <= parseInt(soliders[minIndex])) ? i : minIndex;\n}\nprint(maxIndex+\" \"+minIndex);\nif(maxIndex > minIndex)\n\tswapTime = (parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex))-1);\nelse\n\tswapTime = parseInt(maxIndex) + (parseInt(n)-1-parseInt(minIndex));\nprint(swapTime);"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n let arr = inputs[1].split(' ');\n let Pmax = arr.indexOf(Math.max(...arr).toString());\n let Pmin = 0;\n const shortestHeight = Math.min(...arr).toString();\n\n for (let i = arr.length; i > 0; i--) {\n if (arr[i] == shortestHeight) {\n Pmin = i;\n }\n }\n\n let minSeconds;\n Pmin = parseInt(Pmin)\n Pmax = parseInt(Pmax)\n\n\n\n if (Pmin < Pmax) {\n minSeconds = Pmax + (arr.length - Pmin) - 2;\n } else {\n minSeconds = Pmax + (arr.length - 1 - Pmin);\n }\n\n console.log(minSeconds);\n\n})"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n let arr = inputs[1].split(' ');\n const Pmax = arr.indexOf(Math.max(...arr).toString());\n const shortestHeight = Math.min(...arr).toString();\n let Pmin;\n\n for (let i = arr.length; i > 0; i--) {\n if (arr[i] == shortestHeight) {\n Pmin = i;\n }\n }\n\n let minSeconds;\n if (parseInt(Pmin) < parseInt(Pmax)) {\n minSeconds = Pmax + (arr.length - Pmin) - 2\n } else {\n minSeconds = Pmax + (arr.length - 1 - Pmin);\n }\n\n console.log(minSeconds);\n\n})"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n\nrl.on('close', () => {\n\n let arr = inputs[1].split(' ');\n let Pmax = arr.indexOf(Math.max(...arr).toString());\n let Pmin = 0;\n const shortestHeight = Math.min(...arr).toString();\n\n\n for (let i = arr.length; i > 0; i--) {\n if (arr[i] == shortestHeight) {\n Pmin = i;\n\n let minSeconds;\n Pmin = parseInt(Pmin)\n Pmax = parseInt(Pmax)\n\n if (Pmin < Pmax) {\n minSeconds = Pmax + (arr.length - Pmin) - 2;\n } else {\n minSeconds = Pmax + (arr.length - 1 - Pmin);\n }\n\n return console.log(minSeconds);\n }\n }\n \n\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n const idxMin = arr.lastIndexOf(min);\n const idxMax = arr.indexOf(max);\n\n ans += idxMax;\n\n if (arr.indexOf(min) > arr.indexOf(max)) {\n ans += Math.max(arr.length - idxMin - 1, 0);\n }\n else {\n ans += Math.max(arr.length - idxMin - 2, 0);\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n const ans = Math.max(arr.indexOf(max) - 1, 1) + arr.length - 1 - arr.lastIndexOf(min);\n\n // console.log(Math.max(arr.indexOf(max) - 1, 0), arr.length - 1 - arr.lastIndexOf(min));\n\n\n // let ans = 0;\n // let isSwap = true;\n\n // while (isSwap) {\n // isSwap = false;\n\n // for (let j = 0; j < arr.length - 1; j++) {\n // if (arr[j] < arr[j + 1]) {\n // const temp = arr[j];\n // arr[j] = arr[j + 1];\n // arr[j + 1] = temp;\n // ans++;\n // isSwap = true;\n // }\n // }\n // }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n}); \n\nrl.on('line', input => {\n rl.on('line', input2 => {\n console.log(min(input2.split(' ').map(n => parseInt(n))));\n process.exit();\n });\n});\n\nconst min = input => {\n const min = Math.min(...input);\n const max = Math.max(...input);\n let iMin = input.findIndex(e => e == min);\n let iMax = input.findIndex(e => e == max);\n let secs = 0;\n let temp = 0;\n\n while(input[input.length-1] !== min) {\n if(input[iMin+1] !== min) {\n temp = input[iMin+1];\n input[iMin+1] = input[iMin];\n input[iMin] = temp;\n secs++;\n }\n iMin++;\n }\n\n while(input[0] !== max) {\n if(input[iMax-1] !== max) {\n temp = input[iMax-1];\n input[iMax-1] = input[iMax];\n input[iMax] = temp;\n secs++;\n }\n iMax--;\n }\n\n return secs;\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n}); \n\nrl.on('line', input => {\n rl.on('line', input2 => {\n console.log(min(input2.split(' ').map(n => parseInt(n))));\n process.exit();\n });\n});\n\nconst min = input => {\n const iMin = input.findIndex(e => e == Math.min(...input));\n const iMax = input.findIndex(e => e == Math.max(...input));\n \n return iMin > iMax ? input.length - 1 - iMin + iMax : input.length - 2 - iMin + iMax;\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet sol = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet sc = 0;\n\n\tlet min = Math.min(...sol);\n\tlet max = Math.max(...sol);\n\tlet posMax = 0,\n\t\tposMin = 0;\n\n\tsol.forEach((x, i) => {\n\t\tif (x === min && i >= posMin) posMin = i;\n\t\tif (x === max) posMax = i;\n\t});\n\n\tsc = n - posMin - 1;\n\tif (posMax > posMin) sc += posMax - 1;\n\telse sc += posMax;\n\n\tconsole.log(sc);\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let arr = inputs[1].trim().split(' ');\n let max = Math.max(...arr);\n let min = Math.min(...arr);\n let swaps = 0;\n if (arr[0] == max && arr[arr.length - 1] == min) {\n swaps = 0;\n }\n else {\n let minIndex = arr.lastIndexOf(String(min));\n\n for (let i = minIndex + 1; i < arr.length; i++) {\n if (arr[minIndex] < arr[i]) {\n let temp = arr[i];\n arr[i] = arr[minIndex];\n arr[minIndex] = temp;\n minIndex = i;\n swaps++;\n }\n }\n\n let maxIndex = arr.indexOf(String(max));\n for (let i = maxIndex - 1; i >= 0; i--) {\n if (arr[maxIndex] > arr[i]) {\n let temp = arr[i];\n arr[i] = arr[maxIndex];\n arr[maxIndex] = temp;\n maxIndex = i;\n swaps++;\n }\n }\n }\n\n return swaps.toString();\n}\n\n\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let arr = inputs[1].trim().split(' ');\n let swaps = 0;\n for (let i = 1; i < arr.length; i++) {\n let min = arr[i];\n let j = i - 1;\n while (j >= 0 && arr[j] < min) {\n arr[j + 1] = arr[j];\n j--;\n swaps++;\n }\n arr[j + 1] = min;\n }\n swaps = Math.abs(+inputs[0] - swaps);\n return swaps.toString();\n}\n\n\n"}], "src_uid": "ef9ff63d225811868e786e800ce49c92"} {"source_code": "// Classes to be taken on monday.\nconst classCount = 7;\n// Getting problem data from codeforces.\nvar groupCount = parseInt(readline()),\n groupSchedules = [];\nfor(var j = 0;jmax){max=count;}\n\tcount=0;\n}print(max);"}, {"source_code": "n=+readline()\ns=[]\nfor (var i=0;ires){res=kol;}\n}\nprint(res)"}], "negative_code": [{"source_code": "n=+readline()\ns=[]\nfor (var i=0;ires){res=kol;}\n}\nprint(res)"}, {"source_code": "// Classes to be taken on monday.\nconst classCount = 7;\n// Getting problem data from codeforces.\nvar groupCount = parseInt(readline()),\n groupSchedules = [];\nfor(var j = 0;j input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write('' + data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n", "positive_code": [{"source_code": "'use strict'\n\nfunction main() {\n let n, x, y, s;\n n = parseInt(next()), x = parseInt(next()), y = parseInt(next()), s = next();\n let toBeChanged = 0;\n for(let i = n-x; i < n; i++) {\n if(i != n-y-1) {\n toBeChanged += s[i] == '1';\n } else {\n toBeChanged += s[i] == '0';\n }\n }\n println(toBeChanged);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = \"\";\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write('' + data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}, {"source_code": "try {require(\"codeforces\")} catch(e){};\n\nlet fs = require('fs');\nlet input = (fs.readFileSync2 || fs.readFileSync)(0, 'ascii').split('\\n').map(s => s.trim());\n\nlet [n, x, y] = input[0].split(\" \").map(Number);\nlet ch = input[1];\n\nch = ch.substr(-x).split(\"\");\nch.reverse();\nconsole.log(ch.filter(function(ch, index) {return index === y && ch === \"0\" || index !== y && ch === \"1\"}).length);"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var x = line[1];\n var y = line[2];\n \n var s = read.arr('');\n \n var res = 0;\n for(var i = n - 1; i > n - x - 1; i-- ) {\n if(i == n - y - 1) {\n if(s[i] === '0')\n res++\n }\n else {\n if(s[i] === '1') {\n res++;\n }\n }\n \n }\n print(res);\n}());"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n, x, y;\nn = input.shift();\nx = input.shift();\ny = input.shift();\nvar str = readline();\nvar res = 0;\nfor(var i = n - 1; i >= n - x; i--){\n if(str[i] == '1' && Math.abs(n - i - 1) != y){\n res++;\n } else if(str[i] == '0' && Math.abs(n - 1 - i) == y)\n res++;\n}\nprint(res);"}, {"source_code": "var input = readline().split(\" \").map(Number);\nvar n = input.shift();\nvar x = input.shift();\nvar y = input.shift();\nvar ch = readline();\nch = ch.substr(-x).split(\"\");\nch.reverse();\nwrite(ch.filter(function(ch, index) {return index === y && ch === \"0\" || index !== y && ch === \"1\"}).length);"}, {"source_code": "'use strict'\n\nfunction main() {\n let n = 0, x = 0, y = 0, s = '';\n let i = 0, toBeChanged = 0;\n n = parseInt(next()), x = parseInt(next()), y = parseInt(next()), s = next();\n for(i = n-x; i < n; i++) {\n if(i != n-y-1) {\n toBeChanged += s[i] === '1';\n } else {\n toBeChanged += s[i] === '0';\n }\n }\n println(toBeChanged);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = \"\";\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write('' + data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}], "negative_code": [{"source_code": "'use strict'\n\nfunction main() {\n let n, x, y, s;\n n = parseInt(next()), x = parseInt(next()), y = parseInt(next()), s = next();\n let toBeChanged = 0;\n for(let i = n-x; i < n; i++) {\n if(i != 11-y-1) {\n toBeChanged += s[i] == '1';\n } else {\n toBeChanged += s[i] == '0';\n }\n }\n println(toBeChanged);\n}\n\n//process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\n\nlet input = \"\";\nprocess.stdin.on('data', (chunk) => input += chunk);\n\n// next: reads next value from input.\nlet inputCursor = 0;\nlet next = () => {\n return inputCursor < input.length ? input[inputCursor++] : ''; \n};\n\n//print: print one or more space seperated values.\nlet print = (...data) => {\n for(let i = 0; i < data.length; i++) {\n process.stdout.write('' + data[i] + (i < data.length - 1 ? ' ' : ''));\n }\n};\n\n//println: print one or more space seperated values then a line feed.\nlet println = (...data) => {\n print(...data);\n print('\\n');\n};\n\n//after the the input is read.\nprocess.stdin.on('end', () => {\n input = input.trim().split(/[\\s]+/);\n main();\n});\n"}], "src_uid": "075988685fa3f9b20bd215037c504a4f"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\tchildPieces = tokenizeIntegers(readline()),\n\t\tused = {}, rows = [];\n\tfor (var i = 0; i < childPieces.length; ++i) {\n\t\tused[childPieces[i]] = true;\n\t\trows.push([childPieces[i]]);\n\t}\n\tvar child = 0, limit = n*k;\n\tfor (var piece = 1; piece <= limit; ++piece) {\n\t\tif (!used[piece]) {\n\t\t\trows[child].push(piece);\n\t\t\tif (rows[child].length == n) {\n\t\t\t\t++child;\n\t\t\t}\n\t\t}\n\t}\n\tvar lines = [];\n\tfor (var child = 0; child < k; ++child) {\n\t\tlines.push(rows[child].join(' '));\n\t}\n\tprint(lines.join('\\n'));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\tchildPieces = tokenizeIntegers(readline()),\n\t\tpiece2child = {}, child2piece = {};\n\tfor (var i = 0; i < childPieces.length; ++i) {\n\t\tvar piece = childPieces[i], child = i+1;\n\t\tpiece2child[piece] = child;\n\t\tchild2piece[child] = piece;\n\t}\n\tvar piece = 0;\n\tfor (var child = 1; child <= k; ++child) {\n\t\tvar result = [child2piece[child]];\n\t\tfor (var j = 1; j < n; ++j) {\n\t\t\t++piece;\n\t\t\twhile (piece2child[piece] !== undefined) {\n\t\t\t\t++piece;\n\t\t\t}\n\t\t\tresult.push(piece);\n\t\t}\n\t\tprint(result.join(' '));\n\t}\n}\n\nmain();\n"}, {"source_code": "print(function(n, k) {\n\n\tvar l = n * k;\n\tvar a = new Int32Array(l + 1);\n\n\treadline().split(' ').forEach(function(v, i) {\n\t\ta[v] = i + 1;\n\t});\n\n\tvar ret = [];\n\tfor (var i = 0; i < k; i++)\n\t\tret.push([]);\n\n\tfor (var i = 1, c = 0, j = 0; i <= l; i++) {\n\t\tif (c === n - 1) {\n\t\t\tc = 0;\n\t\t\tj++;\n\t\t}\n\t\tif (a[i] === 0) {\n\t\t\tc++;\n\t\t\tret[j].push(i);\n\t\t} else {\n\t\t\tret[a[i] - 1].push(i);\n\t\t}\n\t}\n\n\treturn ret.map(function(v) {\n\t\treturn v.join(' ');\n\t}).join('\\n');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\n\tprint(function(n, k) {\n\t\tvar t = [], a = readline().split(' ').map(Number);\n\t\ta.forEach(function (e) { t.push([e]); });\n\n\t\tfor (var i = 1, _i = n * k + 1, l = 0; i < _i; i++) {\n\t\t\tif (a.indexOf(i) !== -1) continue;\n\n\t\t\tif (t[l].length === n) l++;\n\t\t\tt[l].push(i);\n\t\t}\n\n\t\treturn t.map(function (e) { return e.join(' '); }).join('\\n');\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}).call(this);"}], "negative_code": [{"source_code": "print(function(n, k) {\n\n\tvar a = ('0 ' + readline()).split(' ').map(Number);\n\n\tfor (var i = n - 1; i >= 1; i--)\n\t\tif (a[i] !== a[i + 1])\n\t\t\treturn i >= k ? -1 : i;\n\n\treturn 0;\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\tchildPieces = tokenizeIntegers(readline()),\n\t\tused = {}, rows = [];\n\tfor (var i = 0; i < childPieces.length; ++i) {\n\t\tused[childPieces[i]] = true;\n\t\trows.push([childPieces[i]]);\n\t}\n\tvar child = 0, limit = n*k, lines = [];\n\tfor (var piece = 1; piece <= limit; ++piece) {\n\t\tif (!used[piece]) {\n\t\t\trows[child].push(piece);\n\t\t\tif (rows[child].length == n) {\n\t\t\t\tlines.push(rows[child].join(' '));\n\t\t\t\t++child;\n\t\t\t}\n\t\t}\n\t}\n\tprint(lines.join('\\n'));\n}\n\nmain();\n"}], "src_uid": "928f18ee5dbf44364c0d578f4317944c"} {"source_code": "// Input\n'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \n//main\nfunction main() {\n var totalTests = parseInt(readline());\n for (var i=0 ; i < totalTests ; i++) {\n console.log(360 % (180 - parseInt(readline())) ? \"NO\" : \"YES\");\n }\n \n}", "positive_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n] = input[0].split(' ').map(x => parseInt(x));\n\n input.forEach((x, i) => {\n if (i === 0) return;\n\n if (360 % (180 - x) === 0)\n console.log('YES');\n else \n console.log('NO');\n });\n}); "}, {"source_code": "// https://codeforces.com/problemset/problem/270/A\n// Big O:\n// Time complexity: O(n)\n// Space complexity: O(n)\n\n// Read input\nvar readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tests;\nlet angles = [];\nlet counter = 0;\nrl.on('line', (input) => {\n if (!tests) {\n tests = parseInt(input);\n return;\n }\n\n counter++;\n if (counter <= tests) {\n angles.push(parseInt(input));\n }\n\n if (counter === tests) {\n solve(angles);\n rl.close();\n }\n\n});\n\nfunction solve(angles) {\n for (angle of angles) {\n const output = isRegularPolygon(angle) ? \"YES\" : \"NO\";\n console.log(output);\n }\n}\n\n// Problem\n// For a regular convex n-gon, each interior angle has a measure of: 180(n-2)/n degrees\nfunction isRegularPolygon(angle) {\n const modulus = 360 % (180 - angle);\n return modulus === 0;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/270/A\n// Big O:\n// Time complexity:\n// Space complexity:\n\n// Read input\nvar readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tests;\nlet angles = [];\nlet counter = 0;\nrl.on('line', (input) => {\n if (!tests) {\n tests = parseInt(input);\n return;\n }\n\n counter++;\n if (counter <= tests) {\n angles.push(parseInt(input));\n }\n\n if (counter === tests) {\n readAngles(angles);\n rl.close();\n }\n\n});\n\nfunction readAngles(angles) {\n for (angle of angles) {\n const isRegularPolygon = canBuildRegularPolygon(angle)\n console.log(isRegularPolygon ? \"YES\" : \"NO\");\n }\n}\n\n// Problem\n// For a regular convex n-gon, each interior angle has a measure of: 180(n-2)/n degrees\nfunction canBuildRegularPolygon(angle) {\n const modulus = 360 % (180 - angle);\n return modulus === 0;\n}\n"}, {"source_code": "function main(stdin) {\n const lines = stdin.split(\"\\n\");\n lines.slice(1).forEach(v => {\n console.log(360 % (180 - parseInt(v)) === 0 ? \"YES\" : \"NO\");\n });\n}\n\nmain(\n require(\"fs\")\n .readFileSync(0, \"utf-8\")\n .trim()\n);\n"}, {"source_code": "var t = parseInt( readline(), 10 );\nvar answers = [];\nwhile ( t-- ) { \n var a = parseInt( readline(), 10 );\n answers.push( 360%(180 - a) === 0 ? \"YES\" : \"NO\" );\n}\nprint( answers.join( \"\\n\" ) );\n"}, {"source_code": "var limit= parseInt(readline());\nvar angle;\nfor (var i = 0; i < limit; i++) {\n angle = parseInt(readline());\n if (360 % (180-angle) === 0) print('YES');\n else print('NO');\n}\n"}, {"source_code": "var t=+readline();\nwhile(t--){\n\tprint(0 === 360%( 180-readline() ) ? 'YES' : 'NO');\n}"}, {"source_code": "var n = +readline(), t;\nfor(i = 0; i < n; i++){\n\tt = +readline();\n\n\tif( (360/(180 - t)) - Math.floor((360/(180 - t))) > 0 ){\n\t\twrite( (i == n-1) ? \"NO\" : \"NO\\n\" );\n\t}\n\telse{\n\t\twrite( (i == n-1) ? \"YES\" : \"YES\\n\" )\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar inp, k;\n\nfor(var i=0; i a){print(\"NO\"); break;}\n n++;\n }\n}"}, {"source_code": "var n = parseInt(readline());\nvar result =\"\";\nvar flag = false;\nfor(var i=0; i < n; i++){\n var alpha = parseInt(readline());\n flag = false;\n for(var j = 3; j < 65538; j++ ){\n if(alpha == (180/j) * (j-2)) {\n result += 'YES' + '\\n';\n flag = true;\n break;\n }\n }\n if(!flag){\n result += 'NO' + '\\n';\n }\n\n}\n\nprint(result);\n"}, {"source_code": ";(function () {\n\n\tfunction pu (n) {\n\t\tvar u = (n - 2)*180 / n;\n\t\treturn u % 1 ? false : u;\n\t}\n\n\tvar n = +readline();\n\tvar us = [];\n\tvar i, j, u;\n\n\tfor (i = 0; i < n; i++) {\n\t\tu = +readline();\n\t\tj = 2;\n\n\t\twhile (true) {\n\t\t\tj++;\n\t\t\tif (!us[j]) us[j] = pu(j);\n\n\t\t\tif (us[j]) {\n\t\t\t\tif (us[j] == u) {\n\t\t\t\t\tprint('YES');\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (us[j] > u) {\n\t\t\t\t\tprint('NO');\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}).call(this);"}, {"source_code": "var InputReader = (function () {\n function InputReader() {\n this.index = 0;\n this.tokenizer = [];\n }\n InputReader.prototype.next = function () {\n while (this.tokenizer == null || this.index == this.tokenizer.length) {\n this.tokenizer = readline().split(\" \");\n this.index = 0;\n }\n var res = this.tokenizer[this.index++];\n return res;\n };\n InputReader.prototype.nextInt = function () {\n return parseInt(this.next());\n };\n InputReader.prototype.nextFloat = function () {\n return parseFloat(this.next());\n };\n return InputReader;\n})();\nfunction main() {\n var input = new InputReader();\n var nTest = input.nextInt();\n for (var i = 0; i < nTest; i++) {\n var n = input.nextInt();\n if (360 % (180 - n) == 0) {\n print(\"YES\");\n }\n else {\n print(\"NO\");\n }\n }\n}\nmain();\n"}, {"source_code": "var n = readline();\n\n\t\n\tfor (var j=0; j<+n; j++){\n\t\t\tvar str = readline();\n\t\t\tif ((360/(180-Number(str))%1==0))\n\t\t\tprint(\"YES\");\n\t\t\telse \tprint(\"NO\");\n\t}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var t = rdN();\n while (t --> 0) {\n var a = rdN();\n var b = 180 - a;\n pr(360%b === 0 && 360/b > 2 ? 'YES' : 'NO');\n }\n};\n\nif (INPUT) {\nINPUT = INPUT.split('\\n').reverse();\nreadline = () => INPUT.pop();\nwrite = (...s) => {OUTPUT += [...s].join(' ')};\nprint = (...s) => {write(...s); OUTPUT += '\\n'};\n}\nconst rdS = readline;\nconst rdN = () => +rdS();\nconst wr = write;\nconst pr = print;\nconst rdArS = () => rdS().split(' ');\nconst rdArN = () => rdArS().map(v => +v);\nconst prAr = (a) => pr(...a);\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nconst defineProperty = (o, pN, v) => Object.defineProperty(o, pN, {configurable: true, enumerable: false, value: v });\ndefineProperty(Array.prototype, 'sortLt', function() { return this.sort(cmpLt); });\ndefineProperty(Array.prototype, 'sortGt', function() { return this.sort(cmpGt); });\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\nconst getPrimes = function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\nvar map = new Map()\r\nvar ans = new Map()\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n const n = Number(readline());\r\n\r\n var mark = {}\r\n for (let j = -100; j <= 100; j++) {\r\n mark[j] = false\r\n }\r\n var a = readline().split(' ').map((x, iii) => {\r\n if(mark[parseInt(x)] === false) return mark[parseInt(x)] = true\r\n if(mark[parseInt(x)] === true) mark[-parseInt(x)] = true\r\n return parseInt(x)\r\n })\r\n var count = 0\r\n for (let j = -100; j <= 100; j++) {\r\n count+= mark[j] ? 1:0\r\n }\r\n\r\n console.log(count)\r\n\r\n\r\n\r\n\r\n })\r\n}\r\n\r\nfunction solve(l, r) {\r\n if (l === r)\r\n ans[`${l}:${r}`] = l\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (i === l && map[`${i + 1}:${r}`]) {\r\n ans[`${l}:${r}`] = i\r\n solve(i + 1, r)\r\n break\r\n } else if (i === r && map[`${l}:${i - 1}`]) {\r\n ans[`${l}:${r}`] = i\r\n solve(l, i - 1)\r\n break\r\n\r\n } else if (map[`${l}:${i - 1}`] && map[`${i + 1}:${r}`]) {\r\n ans[`${l}:${r}`] = i\r\n solve(l, i - 1)\r\n solve(i + 1, r)\r\n break\r\n }\r\n }\r\n}\r\n\r\nfunction check2(q, w, e) {\r\n if (q === w + e) return true\r\n}\r\n\r\nfunction dec2bin(dec) {\r\n var string = (dec >>> 0).toString(2);\r\n var front = ''\r\n for (let i = 0; i < 20 - string.length; i++) {\r\n front += '0'\r\n }\r\n return (front + string).split(\"\").reverse().join(\"\")\r\n}\r\n\r\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var p = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n\r\n var arr = []\r\n\r\n for (var i = 0; i < n; i++) {\r\n var val1 = p[i]\r\n var val2 = -p[i]\r\n if (!arr.includes(val1)) {\r\n arr.push(val1)\r\n } else if (val1 === 0) {\r\n continue;\r\n } else if (arr.includes(val1) && arr.includes(val2)) {\r\n continue;\r\n } else {\r\n arr.push(val2)\r\n }\r\n }\r\n return arr.length\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nGood Bye 2021: 2022 is NEAR\n2021-12-29\n\nA. Integer Diversity\n\nLang: Node.js 12.16.3\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; iMath.abs(x));\n nums.sort();\n let r = 2;\n if (n < 2) {\n r = n;\n } else if (nums[0]===0 && nums[1]===0) {\n r = 1;\n }\n for (let j=2; j (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `3\n// 4\n// 1 1 2 2 2 1 1 -1\n// 3\n// 1 2 3\n// 2\n// 0 0`.split(\"\\n\");\n\nconst solveProblem = (lines) => {\n const lineNumbers = lines\n .slice(2)\n .filter((_, i) => i % 2 === 0)\n .map((line) => line.split(\" \").map((x) => +x));\n\n const result = [];\n\n for (let i = 0; i < lineNumbers.length; i++) {\n const numbersFound = new Map();\n for (const number of lineNumbers[i]) {\n if (number === 0) {\n numbersFound.set(number, true);\n } else {\n if (numbersFound.has(number)) {\n numbersFound.set(-number, true);\n } else {\n numbersFound.set(number, true);\n }\n }\n }\n result.push(numbersFound.size);\n }\n\n console.log(result.join(\"\\n\"));\n};\n\n// solveProblem(lines);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i =0; i < t; i++){\n\t\tnl.num();\n\t\tlet x = new Set(nl.nums().map((e) => Math.abs(e)).sort().map((e, j) => j%2 == 0?e:-e)).size;\n\t\tans.push(x);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n let n = inputReader.readNumber();\r\n let v = inputReader.readNumberArray();\r\n let arr = new Array(105).fill(0);\r\n v.forEach((x) => {\r\n arr[Math.abs(x)] += 1;\r\n });\r\n let ans = 0;\r\n arr.forEach((x, ind, arr) => {\r\n if (ind == 0) {\r\n if (x > 0) ans++;\r\n } else {\r\n if (x > 1) ans += 2;\r\n else if (x == 1) ans++;\r\n else ans += 0;\r\n }\r\n });\r\n console.log(ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let n = readline();\r\n let a = readline().split(\" \").map(w => parseInt(w))\r\n var ans = 0; \r\n var s = [];\r\n for(var i=0;i {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n const m = {};\r\n let res = 0;\r\n for(let i = 0; i < a.length; i++) {\r\n const key = Math.abs(a[i]);\r\n if (!m[key])\r\n m[key] = 0;\r\n if ((key !== 0 && m[key] < 2) || (key === 0 && m[key] < 1)) {\r\n m[key] += 1;\r\n res += 1;\r\n }\r\n }\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var p = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n\r\n var arr = []\r\n\r\n for (var i = 0; i < n; i++) {\r\n var val1 = p[i]\r\n var val2 = -p[i]\r\n if (!arr.includes(val1)) {\r\n arr.push(val1)\r\n } else if (val1 === 0) {\r\n continue;\r\n } else if (arr.includes(val1) && arr.includes(val2)) {\r\n continue;\r\n } else {\r\n arr.push(val2)\r\n }\r\n }\r\n return arr.length\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nGood Bye 2021: 2022 is NEAR\n2021-12-29\n\nA. Integer Diversity\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nGood Bye 2021: 2022 is NEAR\n2021-12-29\n\nA. Integer Diversity\n***/\n\nfunction main() {\n const t = parseInt(readline());\n console.log(\"t=\"+t);\n for (let i=0; i (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `3\n// 4\n// 1 1 2 2\n// 3\n// 1 2 3\n// 2\n// 0 0`.split(\"\\n\");\n//\n\nconst solveProblem = (lines) => {\n const lineNumbers = lines\n .slice(2)\n .filter((_, i) => i % 2 === 0)\n .map((line) => line.split(\" \").map((x) => +x));\n\n const result = [];\n\n for (let i = 0; i < lineNumbers.length; i++) {\n const numbersFound = new Map();\n let lineResult = 0;\n for (const number of lineNumbers[i]) {\n if (number === 0) {\n if (!numbersFound.has(number)) {\n lineResult++;\n }\n } else {\n if (!numbersFound.has(number) || numbersFound.get(number) === 1) {\n lineResult++;\n }\n }\n numbersFound.set(number, (numbersFound.get(number) || 0) + 1);\n }\n result.push(lineResult);\n }\n\n console.log(result.join(\"\\n\"));\n};\n"}, {"source_code": "let input = \"\";\nprocess.stdin.on(\"data\", (c) => (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `3\n// 4\n// 1 1 2 2\n// 3\n// 1 2 3\n// 2\n// 0 0`.split(\"\\n\");\n//\n\nconst solveProblem = (lines) => {\n const lineNumbers = lines\n .slice(2)\n .filter((_, i) => i % 2 === 0)\n .map((line) => line.split(\" \").map((x) => +x));\n\n const result = [];\n\n for (let i = 0; i < lineNumbers.length; i++) {\n const numbersFound = new Map();\n let lineResult = 0;\n for (const number of lineNumbers[i]) {\n if (number === 0) {\n if (!numbersFound.has(number)) {\n lineResult++;\n }\n } else {\n if (!numbersFound.has(number) || numbersFound.get(number) === 1) {\n lineResult++;\n }\n }\n numbersFound.set(number, (numbersFound.get(number) || 0) + 1);\n }\n result.push(lineResult);\n }\n\n console.log(result);\n};\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i =0; i < t; i++){\n\t\tnl.num();\n\t\tlet x = new Set(nl.nums().sort().map((e, j) => j%2 == 0?e:-e)).size;\n\t\tans.push(x);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "\r\nlet _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve() {\r\n\t let n = inputReader.readNumber();\r\n\t let v = inputReader.readNumberArray();\r\n\t let arr = new Array(100).fill(0);\r\n\t v.forEach(x => {\r\n\t arr[Math.abs(x)]+=1; \r\n\t });\r\n\t let ans = 0;\r\n\t arr.forEach((x, ind, arr)=>{\r\n\t if(ind!=0) ans+=2*(x/2);\r\n\t else {\r\n\t if(x > 0)\r\n\t ans+=1;\r\n\t }\r\n\t });\r\n\t console.log(ans);\r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}], "src_uid": "23ef311011b381d0ca2e84bc861f0a31"} {"source_code": "var vals = readline().split(\" \");\nvar n = parseInt(vals[0]);\nvar m = parseInt(vals[1]);\nvar fil = [];\n\nfor (var i = 1; i < n + 1; i++) {\n fil[i] = readline().split(\"\")\n .map(function(el) {\n if (el === '.') {\n return 0;\n } else if (el === '*') {\n return 100;\n } else {\n return el;\n }\n })\n .map(function(el) {\n return parseInt(el);\n });\n fil[i].unshift(0);\n fil[i].push(0);\n}\n\nfil[0] = [];\nfil[n+1] = [];\nfor (var j = 0; j < m + 2; j++) {\n fil[0].push(0);\n fil[n+1].push(0);\n}\n\nfunction calc(n, m, fil) {\n var sum;\n for (var i = 1; i < n + 1; i++) {\n for (var j = 1; j < m + 1; j++) {\n sum = fil[i-1][j-1] + fil[i][j-1] + fil[i+1][j-1] + fil[i-1][j] + fil[i+1][j] + fil[i-1][j+1] + fil[i][j+1] + fil[i+1][j+1];\n if (fil[i][j] !== 100 && Math.floor(sum / 100) !== fil[i][j]) {\n print('NO');\n return;\n }\n }\n }\n print('YES');\n}\n\ncalc(n,m,fil);", "positive_code": [{"source_code": "var dims = readline();\ndims = dims.split(' ').map(Number);\nvar n = dims[0], m = dims[1];\n\nvar rows = [];\nvar isGridValid = true;\n\nfunction numerize(x) {\n return isNaN(Number(x)) ? x : Number(x);\n}\n\nfunction isCellValid(y, x) {\n var cell = rows[y][x];\n if (!cell) {\n return false;\n }\n\n var bombs = 0;\n for (var i = y - 1; i <= y + 1; i++) {\n if (!rows[i]) {\n continue;\n }\n for(var j = x - 1; j <= x + 1; j++) {\n if (rows[i][j] && rows[i][j] === '*') {\n bombs++;\n }\n }\n }\n \n if (typeof cell === 'number') {\n return bombs === cell;\n }\n \n return cell === '.' ? bombs === 0 : true;\n}\n\nfor (var i = 0; i < n; i++) {\n var row = readline().split('').map(numerize);\n rows.push(row);\n}\n\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++) {\n isGridValid = isCellValid(i, j);\n if (!isGridValid) {\n break;\n }\n }\n if (!isGridValid) {\n break;\n }\n}\n\nprint(isGridValid ? 'YES' : 'NO');"}, {"source_code": "var p = readline().split(' ').map(Number);\nvar n = p[0];\nvar m = p[1];\nvar saper = [];\nvar ans = 'YES';\nfor (var i=0; i {\n lines.push(line);\n}).on('close', () => {\n let dims = lines[0];\n dims = dims.split(' ').map(Number);\n const n = dims[0], m = dims[1];\n \n const rows = [];\n let isGridValid = true;\n \n function numerize(x) {\n return isNaN(Number(x)) ? x : Number(x);\n }\n \n function isCellValid(y, x) {\n const cell = rows[y][x];\n if (!cell) {\n return false;\n }\n \n let bombs = 0;\n for (let i = y - 1; i <= y + 1; i++) {\n if (!rows[i]) {\n continue;\n }\n for(let j = x - 1; j <= x + 1; j++) {\n if (rows[i][j] && rows[i][j] === '*') {\n bombs++;\n }\n }\n }\n \n if (typeof cell === 'number') {\n return bombs === cell;\n }\n \n return cell === '.' ? bombs === 0 : true;\n }\n \n for (let i = 1; i <= n; i++) {\n var row = lines[i].split('').map(numerize);\n rows.push(row);\n }\n \n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n isGridValid = isCellValid(i, j);\n if (!isGridValid) {\n break;\n }\n }\n if (!isGridValid) {\n break;\n }\n }\n \n process.stdout.write(isGridValid ? 'YES' : 'NO');\n});"}, {"source_code": "l = readline().split(' ');\nn = +l[0], m = +l[1];\na = [];\nfor (i = 0; i < n; i++)\n a.push(readline());\ndr = [-1, -1, 0, 1, 1, 1, 0, -1], dc = [0, 1, 1, 1, 0, -1, -1, -1];\nfunction Bombs_Around(i, j) {\n ans = 0;\n for (k = 0; k < 8; k++) {\n ix = i + dr[k], jx = j + dc[k];\n if (ix < 0 || ix >= n || jx < 0 || jx >= m)\n continue;\n if (a[ix].charAt(jx) === '*')\n ans++;\n }\n return ans;\n}\nfunction Solve() {\n for (i = 0; i < n; i++)\n for (j = 0; j < m; j++) {\n cur = a[i].charAt(j);\n if (cur === '*')\n continue;\n bombs = Bombs_Around(i, j);\n if (cur === '.') {\n if (bombs > 0)\n return false;\n }\n else if (bombs != parseInt(cur)) \n return false;\n }\n return true;\n}\nprint(Solve() ? 'YES' : 'NO');"}, {"source_code": "\n var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var m = tmp[1];\n var d = [];\n for(var i = 0; i < n; i += 1) {\n d[i] = readline().split('');\n }\n var test = function(x, y) {\n var res = 0;\n if(x > 0 && y > 0) {\n res += d[x - 1][y - 1] === '*' ? 1 : 0;\n }\n if(y > 0) {\n res += d[x][y - 1] === '*' ? 1 : 0;\n }\n if(x < n - 1 && y > 0) {\n res += d[x + 1][y - 1] === '*' ? 1 : 0;\n }\n if(x < n - 1) {\n res += d[x + 1][y] === '*' ? 1 : 0;\n }\n if(x < n - 1 && y < m - 1) {\n res += d[x + 1][y + 1] === '*' ? 1 : 0;\n }\n if(y < m - 1) {\n res += d[x][y + 1] === '*' ? 1 : 0;\n }\n if(x > 0 && y < m - 1) {\n res += d[x - 1][y + 1] === '*' ? 1 : 0;\n }\n if(x > 0) {\n res += d[x - 1][y] === '*' ? 1 : 0;\n }\n return res;\n }\n var flag = true;\n for(var i = 0; i < n && flag; i += 1 ) {\n for(var j = 0; j < m && flag; j += 1) {\n if(d[i][j] === '*') {\n continue;\n }\n if(d[i][j] === '.') {\n d[i][j] = '0';\n }\n flag = parseInt(d[i][j]) === test(i, j);\n }\n }\n\n print(flag ? 'YES' : 'NO');"}], "negative_code": [{"source_code": "var p = readline().split(' ').map(Number);\nvar n = p[0];\nvar m = p[1];\nvar saper = [];\nvar ans = 'YES';\nfor (var i=0; i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let k = readline().split(\" \")\r\n let v = []\r\n for(let i in k) v.push(parseInt(k[i]))\r\n if(v[n-2] > v[n-1]){\r\n console.log(-1)\r\n }else{\r\n let i = n-3\r\n let ct = 0\r\n let a = new Array(n).fill(false)\r\n while(i>=0){\r\n if(v[i] > v[i+1]){\r\n ct++\r\n v[i] = v[i+1] - v[n-1]\r\n a[i] = true\r\n }\r\n i--\r\n }\r\n let flag = true\r\n for(let i = 1;i=0){\r\n if(a[i]){\r\n console.log(`${i+1} ${i+2} ${n}`)\r\n }\r\n i--;\r\n }\r\n }else console.log(-1)\r\n }\r\n }\r\n \r\n}", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n if(parseInt(v[n-2]) > parseInt(v[n-1])){\r\n console.log(-1)\r\n }else{\r\n let i = n-3\r\n let ct = 0\r\n let a = new Array(n).fill(false)\r\n while(i>=0){\r\n if(parseInt(v[i]) > parseInt(v[i+1])){\r\n ct++\r\n v[i] = v[i+1] - v[n-1]\r\n a[i] = true\r\n }\r\n i--\r\n }\r\n let flag = true\r\n for(let i = 1;i=0){\r\n if(a[i]){\r\n console.log(`${i+1} ${i+2} ${n}`)\r\n }\r\n i--;\r\n }\r\n }else console.log(-1)\r\n }\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\tif (a[i] > a[i+1]) ok = false;\r\n\t\t}\r\n\r\n\t\tif (ok) {\r\n\t\t\tconsole.log(0);\r\n\t\t} else if (a[n-2] <= a[n-1] && a[n-1] >= 0) {\r\n\t\t\tconsole.log(n-2);\r\n\t\t\tfor (let i = 0; i < n-2; i++) {\r\n\t\t\t\tconsole.log(i+1, n-1, n);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tok = ok && a[i-1] <= a[i];\r\n\t\t}\r\n\r\n\t\tif (ok) {\r\n\t\t\tconsole.log(0);\r\n\t\t} else if (a[a.length-2] <= a[a.length-1] && a[a.length-1] >= 0) {\r\n\t\t\tconsole.log(n-2);\r\n\t\t\tfor (let i = 0; i < n-2; i++) {\r\n\t\t\t\tconsole.log(i+1, n-1, n);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n const check = (arr) => {\r\n for (let i = 1; i < arr.length; i++)\r\n if (arr[i - 1] > arr[i]) return false;\r\n return true;\r\n };\r\n if (check(arr)) {\r\n console.log(0);\r\n continue;\r\n }\r\n if (arr[n - 1] < 0 && arr[n - 2] < 0) {\r\n console.log(-1);\r\n continue;\r\n }\r\n if (arr[n - 1] < arr[n - 2]) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let o = n - 3;\r\n let k = o;\r\n console.log(o + 1);\r\n while (o >= 0) {\r\n console.log(`${o + 1} ${k + 2} ${k + 3}`);\r\n o--;\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const dif = new Array(n);\r\n let max = n - 1;\r\n for (let i = n - 2; i >= 0; i--) {\r\n var _dif$, _dif;\r\n const cur = a[i] - a[max];\r\n if (cur < ((_dif$ = (_dif = dif[i + 1]) === null || _dif === void 0 ? void 0 : _dif[0]) !== null && _dif$ !== void 0 ? _dif$ : Infinity)) {\r\n dif[i] = [cur, i, max];\r\n } else {\r\n dif[i] = [...dif[i + 1]];\r\n }\r\n if (a[i] > a[max]) max = i;\r\n }\r\n const nums = new Array(n),\r\n res = [];\r\n nums[n - 1] = a[n - 1];\r\n nums[n - 2] = a[n - 2];\r\n for (let i = 0; i < n - 2; i++) {\r\n nums[i] = dif[i + 1][0];\r\n if (nums[i] < a[i]) res.push([i, dif[i + 1][1], dif[i + 1][2]]);else nums[i] = a[i];\r\n }\r\n for (let i = 0; i < n - 1; i++) {\r\n if (nums[i] > nums[i + 1]) return -1;\r\n }\r\n if (res.length) return `${res.length}\\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\\n')}`;\r\n return 0;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let k = readline().split(\" \")\r\n let v = []\r\n for(let i in k) v.push(parseInt(v[i]))\r\n if(parseInt(v[n-2]) > parseInt(v[n-1])){\r\n console.log(-1)\r\n }else{\r\n let i = n-3\r\n let ct = 0\r\n let a = new Array(n).fill(false)\r\n while(i>=0){\r\n if(v[i] > v[i+1]){\r\n ct++\r\n v[i] = v[i+1] - v[n-1]\r\n a[i] = true\r\n }\r\n i--\r\n }\r\n let flag = true\r\n for(let i = 1;i=0){\r\n if(a[i]){\r\n console.log(`${i+1} ${i+2} ${n}`)\r\n }\r\n i--;\r\n }\r\n }else console.log(-1)\r\n }\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n if(parseInt(v[n-2]) > parseInt(v[n-1])){\r\n console.log(-1)\r\n }else{\r\n let i = n-3\r\n let ct = 0\r\n let a = new Array(n).fill(false)\r\n while(i>=0){\r\n if(v[i] > v[i+1]){\r\n ct++\r\n v[i] = v[i+1] - v[n-1]\r\n a[i] = true\r\n }\r\n i--\r\n }\r\n let flag = true\r\n for(let i = 1;i=0){\r\n if(a[i]){\r\n console.log(`${i+1} ${i+2} ${n}`)\r\n }\r\n i--;\r\n }\r\n }else console.log(-1)\r\n }\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n if(parseInt(v[n-2]) > parseInt(v[n-1])){\r\n console.log(-1)\r\n }else{\r\n let i = n-3\r\n let ct = 0\r\n let a = new Array(n).fill(false)\r\n while(i>=0){\r\n if(v[i] > v[i+1]){\r\n ct++\r\n v[i] = v[i+1] - v[n-1]\r\n a[i] = true\r\n }\r\n i--\r\n }\r\n let flag = true\r\n for(let i = 1;i=0){\r\n if(a[i]){\r\n console.log(`${i} ${i+1} ${n-1}`)\r\n }\r\n i--;\r\n }\r\n }else console.log(-1)\r\n }\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tif (a[a.length-2] > a[a.length-1]) {\r\n\t\t\tconsole.log(-1);\r\n\t\t} else {\r\n\t\t\tconsole.log(n-2);\r\n\t\t\tfor (let i = 0; i < n-2; i++) {\r\n\t\t\t\tconsole.log(i+1, n-1, n);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tif (a[a.length-2] > a[a.length-1]) {\r\n\t\t\tconsole.log(-1);\r\n\t\t} else {\r\n\t\t\tconsole.log(n-2);\r\n\t\t\tfor (let i = 0; i < n-2; i++) {\r\n\t\t\t\tconsole.log(i+1, n-1, n-2);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "c3ee6419adfc85c80f35ecfdea6b0d43"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n readline();\r\n let input = readline().split(\" \").map(Number);\r\n print(Permu(input));\r\n }\r\n}\r\nfunction Permu(arr) {\r\n if (arr.length == 1) return -1;\r\n let c = [...arr];\r\n c.sort((a, b) => a - b);\r\n let ans = [];\r\n for (let i = 0; i < arr.length; i++) {\r\n if (c[i] == arr[i]) {\r\n if (i < arr.length - 1) {\r\n ans.push(c[i + 1]);\r\n c[i + 1] = c[i];\r\n } else {\r\n let temp = ans.pop();\r\n ans.push(c[i]);\r\n ans.push(temp);\r\n }\r\n } else ans.push(c[i]);\r\n }\r\n return ans.join(\" \");\r\n}", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \");\r\n if (arr.length === 1) return -1;\r\n let checked = [];\r\n let res = [];\r\n for (let i = 0; i < arr.length; i++) {\r\n let min = Number.MAX_VALUE;\r\n for (let j = 0; j < arr.length; j++) {\r\n if (arr[i] != arr[j]) {\r\n let temp = min < parseInt(arr[j]) ? min : parseInt(arr[j]);\r\n if (!checked[parseInt(temp)])\r\n min = temp;\r\n }\r\n }\r\n checked[parseInt(min)] = 1;\r\n res.push(min);\r\n }\r\n if (res[res.length - 1] === Number.MAX_VALUE) {\r\n let temp = res[res.length - 2];\r\n res[res.length - 2] = arr[arr.length - 1];\r\n res[res.length - 1] = temp;\r\n }\r\n return res.join(\" \");\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 1) return -1;\r\n const res = [];\r\n let min = 1,\r\n set = new Set();\r\n for (let i = 0; i < n; i++) {\r\n while (set.has(min)) {\r\n min++;\r\n }\r\n if (a[i] !== min) {\r\n res[i] = min++;\r\n } else {\r\n if (i === n - 1) {\r\n res[i] = res[n - 2];\r\n res[n - 2] = min;\r\n } else {\r\n let tmp = min + 1;\r\n while (set.has(tmp)) {\r\n tmp++;\r\n }\r\n res[i] = tmp;\r\n }\r\n }\r\n set.add(res[i]);\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\n//const { addLeadingSlash } = require('history/PathUtils');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline().split(' ');\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var used = [];\r\n var ans = []\r\n var flag = true;\r\n for(var i=1;i<=n;i++) used[i] = 0;\r\n var cnt = 0, checker = false, c=0;\r\n if(a[n-1]==n) checker = true;\r\n \r\n for(var i=0;i {\n if (p.length === 1) return console.log(\"-1\");\n mystic = p.slice();\n p.sort((a, b) => a - b);\n for (let i = 0; i < p.length; i++) {\n const x = mystic[i];\n if (p[i] === x) {\n // console.log(i, x, p[i]);\n if (i === p.length - 1) {\n p[i] = p[i - 1];\n p[i - 1] = x;\n } else {\n p[i] = p[i + 1];\n p[i + 1] = x;\n }\n }\n }\n console.log(p.join(\" \"));\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== -1) {\n if (lines % 2 === 1) {\n solve(line.split(\" \").map(Number));\n }\n }\n lines++;\n});\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \");\r\n if (arr.length === 1) return -1;\r\n let checked = [];\r\n let res = [];\r\n for (let i = 0; i < arr.length; i++) {\r\n let min =Number.MAX_VALUE;\r\n for (let j = 0; j < arr.length; j++) {\r\n if (arr[i] != arr[j]) {\r\n let temp = min < arr[j] ? min : arr[j];\r\n if (!checked[parseInt(temp)])\r\n min = min < arr[j] ? min : arr[j];\r\n }\r\n }\r\n checked[parseInt(min)] = 1;\r\n res.push(min);\r\n }\r\n if (res[res.length - 1] === Number.MAX_VALUE) {\r\n let temp = res[res.length - 2];\r\n res[res.length - 2] = arr[arr.length - 1];\r\n res[res.length - 1] = temp;\r\n }\r\n return res.join(\" \");\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \");\r\n if (arr.length === 1) return -1;\r\n let checked = [];\r\n let res = [];\r\n for (let i = 0; i < arr.length; i++) {\r\n let min =\"x\";\r\n for (let j = 0; j < arr.length; j++) {\r\n if (arr[i] != arr[j]) {\r\n let temp = min < arr[j] ? min : arr[j];\r\n if (!checked[parseInt(temp)])\r\n min = min < arr[j] ? min : arr[j];\r\n }\r\n }\r\n checked[parseInt(min)] = 1;\r\n res.push(min);\r\n }\r\n if (res[res.length - 1] === \"x\") {\r\n let temp = res[res.length - 2];\r\n res[res.length - 2] = arr[arr.length - 1];\r\n res[res.length - 1] = temp;\r\n }\r\n return res.join(\" \");\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\n//const { addLeadingSlash } = require('history/PathUtils');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline().split(' ');\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var used = [];\r\n var ans = []\r\n var flag = true;\r\n for(var i=1;i<=n;i++) used[i] = 0;\r\n var cnt = 0, checker = false, c=0;\r\n for(var i=0;i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline().split(' ');\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var used = [];\r\n var ans = []\r\n var flag = true;\r\n for(var i=1;i<=n;i++) used[i] = 0;\r\n var cnt = 0, checker = false, c=0;\r\n for(var i=0;i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline().split(' ');\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var used = [];\r\n var ans = []\r\n var flag = true;\r\n for(var i=1;i<=n;i++) used[i] = 0;\r\n var cnt = 0, checker = false;\r\n for(var i=0;i=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline().split(' ');\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var used = [];\r\n var ans = []\r\n var flag = true;\r\n for(var i=1;i<=n;i++) used[i] = 0;\r\n var cnt = 0, checker = false;\r\n for(var i=0;i= 0; i--) {\r\n while (set.has(max)) max--;\r\n if (a[i] === max) {\r\n if (max === 1) {\r\n if (res[1] === 2) {\r\n res[0] = 2;\r\n res[1] = 1;\r\n } else {\r\n res[0] = 2;\r\n res[1] = 3;\r\n res[2] = 1;\r\n }\r\n } else {\r\n res[i] = max - 1;\r\n }\r\n } else res[i] = max--;\r\n set.add(res[i]);\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 1) return -1;\r\n const res = [];\r\n let max = n;\r\n const set = new Set();\r\n for (let i = n - 1; i >= 0; i--) {\r\n while (set.has(max)) max--;\r\n if (a[i] === max) {\r\n if (max === 1) {\r\n res[0] = 2;\r\n res[1] = 3;\r\n res[2] = 1;\r\n } else {\r\n res[i] = max - 1;\r\n }\r\n } else res[i] = max--;\r\n set.add(res[i]);\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "src_uid": "1bf5b7d3dff2d9d917563e5c8aa32675"} {"source_code": " var n = parseInt(readline());\n var a = [];\n var b = [];\n var t = [];\n var tt = [];\n tt['XXXL'] = 0;\n tt['XXL'] = 0;\n tt['XL'] = 0;\n tt['L'] = 0;\n tt['M'] = 0;\n tt['XXXS'] = 0;\n tt['XXS'] = 0;\n tt['XS'] = 0;\n tt['S'] = 0;\n\n t['XXXL'] = 0;\n t['XXL'] = 0;\n t['XL'] = 0;\n t['L'] = 0;\n t['M'] = 0;\n t['XXXS'] = 0;\n t['XXS'] = 0;\n t['XS'] = 0;\n t['S'] = 0;\n\n for(var i = 0; i < n; i += 1) {\n a[i] = readline();\n if(t[a[i]] === undefined) {\n t[a[i]] = 1;\n } else {\n t[a[i]] += 1;\n }\n }\n for(var i = 0; i < n; i += 1) {\n b[i] = readline();\n if(tt[b[i]] === undefined) {\n tt[b[i]] = 1;\n } else {\n tt[b[i]] += 1;\n }\n }\n var res = 0;\n res += Math.abs(tt['XXXL'] - t['XXXL']);\n res += Math.abs(tt['XXL'] - t['XXL']);\n res += Math.abs(tt['XL'] - t['XL']);\n var m = (tt['M'] - t['M']);\n var s = (tt['S'] - t['S']);\n var l = (tt['L'] - t['L']);\n res += m > 0 ? m : 0;\n res += s > 0 ? s : 0;\n res += l > 0 ? l : 0;\n \n\n print(res);", "positive_code": [{"source_code": "var n = +readline();\nvar ai = {};\nvar bi = {};\nvar same = 0;\n\nfor(var i = 0; i < n; i++) {\n var size = readline();\n ai[size] = ai[size] + 1 || 1;\n}\n\nfor(var i = 0; i < n; i++) {\n var size = readline();\n bi[size] = bi[size] + 1 || 1;\n}\n\nfor(var prop in ai) {\n same += Math.min(ai[prop] || 0 , bi[prop] || 0);\n}\n\nprint(n - same);"}], "negative_code": [{"source_code": "var n = +readline();\nvar ai = [];\nvar bi = [];\nvar seconds = 0;\n\nfor (var i = 0; i < n; i++) {\n ai.push(readline());\n}\nfor (var i = 0; i < n; i++) {\n bi.push(readline());\n}\n\n// Sort the arrays\nai.sort((a, b) => (a < b ? -1 : 1));\nbi.sort((a, b) => (a < b ? -1 : 1));\n\nfor(var i = 0; i < n; i++) {\n if(ai[i] !== bi[i]) {\n seconds++;\n }\n}\n\nprint(seconds);"}, {"source_code": "\n var n = parseInt(readline());\n var a = [];\n var b = [];\n var t = [];\n var tt = [];\n tt['XXXL'] = 0;\n tt['XXL'] = 0;\n tt['XL'] = 0;\n tt['L'] = 0;\n tt['M'] = 0;\n tt['XXXS'] = 0;\n tt['XXS'] = 0;\n tt['XS'] = 0;\n tt['S'] = 0;\n\n t['XXXL'] = 0;\n t['XXL'] = 0;\n t['XL'] = 0;\n t['L'] = 0;\n t['M'] = 0;\n t['XXXS'] = 0;\n t['XXS'] = 0;\n t['XS'] = 0;\n t['S'] = 0;\n\n for(var i = 0; i < n; i += 1) {\n a[i] = readline();\n if(t[a[i]] === undefined) {\n t[a[i]] = 1;\n } else {\n t[a[i]] += 1;\n }\n }\n for(var i = 0; i < n; i += 1) {\n b[i] = readline();\n if(tt[b[i]] === undefined) {\n tt[b[i]] = 1;\n } else {\n tt[b[i]] += 1;\n }\n }\n var res = 0;\n res += Math.abs(tt['XXXL'] - t['XXXL']);\n res += Math.abs(tt['XXL'] - t['XXL']);\n res += Math.abs(tt['XL'] - t['XL']);\n res += Math.abs(tt['XXXS'] - t['XXXS']);\n res += Math.abs(tt['XXS'] - t['XXS']);\n res += Math.abs(tt['XS'] - t['XS']);\n\n var m = Math.abs(tt['M'] - t['M']);\n res += m;\n var s = Math.abs(tt['S'] - t['S']);\n var l = Math.abs(tt['L'] - t['L']);\n if(m < s) {\n res += s - m;\n } else {\n res += l - m + s;\n }\n print(res);\n \n \n"}, {"source_code": "\n var n = parseInt(readline());\n var a = [];\n var b = [];\n var t = [];\n var tt = [];\n tt['XXXL'] = 0;\n tt['XXL'] = 0;\n tt['XL'] = 0;\n tt['L'] = 0;\n tt['M'] = 0;\n tt['XXXS'] = 0;\n tt['XXS'] = 0;\n tt['XS'] = 0;\n tt['S'] = 0;\n\n t['XXXL'] = 0;\n t['XXL'] = 0;\n t['XL'] = 0;\n t['L'] = 0;\n t['M'] = 0;\n t['XXXS'] = 0;\n t['XXS'] = 0;\n t['XS'] = 0;\n t['S'] = 0;\n\n for(var i = 0; i < n; i += 1) {\n a[i] = readline();\n if(t[a[i]] === undefined) {\n t[a[i]] = 1;\n } else {\n t[a[i]] += 1;\n }\n }\n for(var i = 0; i < n; i += 1) {\n b[i] = readline();\n if(tt[b[i]] === undefined) {\n tt[b[i]] = 1;\n } else {\n tt[b[i]] += 1;\n }\n }\n var res = 0;\n res += Math.abs(tt['XXXL'] - t['XXXL']);\n res += Math.abs(tt['XXL'] - t['XXL']);\n res += Math.abs(tt['XL'] - t['XL']);\n res += Math.abs(tt['M'] - t['M']);\n res += Math.abs(tt['S'] - t['S']);\n res += Math.abs(tt['L'] - t['L']);\n\n print(res);\n "}, {"source_code": "\n var n = parseInt(readline());\n var a = [];\n var b = [];\n var t = [];\n var tt = [];\n tt['XXXL'] = 0;\n tt['XXL'] = 0;\n tt['XL'] = 0;\n tt['L'] = 0;\n tt['M'] = 0;\n tt['XXXS'] = 0;\n tt['XXS'] = 0;\n tt['XS'] = 0;\n tt['S'] = 0;\n\n t['XXXL'] = 0;\n t['XXL'] = 0;\n t['XL'] = 0;\n t['L'] = 0;\n t['M'] = 0;\n t['XXXS'] = 0;\n t['XXS'] = 0;\n t['XS'] = 0;\n t['S'] = 0;\n\n for(var i = 0; i < n; i += 1) {\n a[i] = readline();\n if(t[a[i]] === undefined) {\n t[a[i]] = 1;\n } else {\n t[a[i]] += 1;\n }\n }\n for(var i = 0; i < n; i += 1) {\n b[i] = readline();\n if(tt[b[i]] === undefined) {\n tt[b[i]] = 1;\n } else {\n tt[b[i]] += 1;\n }\n }\n var res = 0;\n res += Math.abs(tt['XXXL'] - t['XXXL']);\n res += Math.abs(tt['XXL'] - t['XXL']);\n res += Math.abs(tt['XL'] - t['XL']);\n\n var m = Math.abs(tt['M'] - t['M']);\n res += m;\n var s = Math.abs(tt['S'] - t['S']);\n var l = Math.abs(tt['L'] - t['L']);\n if(m < s) {\n res += s - m;\n } else {\n res += l - m + s;\n }\n print(res);\n "}], "src_uid": "c8321b60a6ad04093dee3eeb9ee27b6f"} {"source_code": "const res = [];\n\nfunction buildTree(n, edges, cats) {\n edges = edges.map(edge => {\n return edge.split(' ').map(el => {\n return parseInt(el, 10);\n });\n });\n var edges2 = edges.map(edge => {\n return [edge[1], edge[0]];\n });\n edges = edges.concat(edges2);\n edges.sort((a, b) => {\n return a[0] - b[0];\n });\n var tree = [];\n var j = 0;\n for (var i = 1; i <= n; i++) {\n var node = {\n n: i,\n hasCat: parseInt(cats[i - 1], 10) === 1,\n children: [],\n visited: false,\n cats: 0,\n fatherCats: 0\n };\n while (edges[j] && edges[j][0] === i) {\n node.children.push(edges[j][1]);\n j++;\n }\n tree.push(node);\n }\n return tree;\n}\n\nconst stack = [];\n\nfunction resolve(tree, m) {\n var node;\n while (stack.length > 0) {\n node = stack.pop();\n if (!node.visited) {\n node.visited = true;\n if (!node.hasCat) {\n node.cats = 0;\n } else {\n node.cats = node.fatherCats + 1;\n }\n if (node.cats <= m) {\n var count = 0;\n for (var i = 0; i < node.children.length; i++) {\n if (!tree[node.children[i] - 1].visited) {\n count++;\n tree[node.children[i] - 1].fatherCats = node.cats;\n stack.push(tree[node.children[i] - 1]);\n }\n }\n if (count === 0) {\n res.push(node.n);\n }\n }\n }\n }\n}\n\n/*\nconst tree = buildTree(\n 15,\n [\n '1 2',\n '1 3',\n '2 4',\n '2 5',\n '3 6',\n '3 7',\n '4 8',\n '4 9',\n '5 10',\n '5 11',\n '6 12',\n '6 13',\n '7 14',\n '7 15'\n ],\n ['1', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']\n);\nconsole.log(tree);\nstack.push(tree[0]);\nresolve(tree, 2);\nconsole.log(res);\n*/\n\nconst i = readline().split(' ');\nconst n = parseInt(i[0], 10);\nconst m = parseInt(i[1], 10);\nconst cats = readline().split(' ');\nconst edges = [];\nvar edge = readline();\nwhile (edge) {\n edges.push(edge);\n edge = readline();\n}\nconst tree = buildTree(n, edges, cats);\nstack.push(tree[0]);\nresolve(tree, m);\nprint(res.length);\n", "positive_code": [{"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (v) {\n return parseInt(v);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n maxCats = _readline$split$map2[1];\n\nvar hasCat = readline().split(' ').map(function (v) {\n return parseInt(v);\n});\n\n// BFS - \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0434\u044b\n// \u041d\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 direct edge \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0441\u0442\u044c\u044f\n\nvar G = new Graph();\n\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 1; _i < n; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 2),\n n1 = _readline$split$map4[0],\n n2 = _readline$split$map4[1];\n\n G.addEdge(n1, n2);\n}\n\nvar catsAmount = {\n 1: hasCat[0]\n};\n\nvar leaves = [];\n\nvar q = new Queue();\nq.enqueue(1);\n\nvar visited = new Set();\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n visited.add(node);\n\n if (G.edges[node].length === 1 && node !== 1) {\n leaves.push(node);\n } else {\n G.edges[node].forEach(function (_ref) {\n var child = _ref.node;\n\n if (visited.has(child)) {\n return;\n }\n\n var catsAmountInParent = catsAmount[node];\n var catsAmountInChild = hasCat[child - 1];\n\n if (catsAmountInChild) {\n catsAmount[child] = catsAmountInParent + 1;\n } else {\n catsAmount[child] = 0;\n }\n\n if (catsAmount[child] <= maxCats) q.enqueue(child);\n });\n }\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nwrite(leaves.length);\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}], "negative_code": [{"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (v) {\n return parseInt(v);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n maxCats = _readline$split$map2[1];\n\nvar hasCat = readline().split(' ').map(function (v) {\n return parseInt(v);\n});\n\n// BFS - \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0434\u044b\n// \u041d\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 direct edge \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0441\u0442\u044c\u044f\n\nvar G = new Graph([], true);\n\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 1; _i < n; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 2),\n n1 = _readline$split$map4[0],\n n2 = _readline$split$map4[1];\n\n G.addEdge(n1, n2);\n}\n\nvar catsAmount = {\n 1: hasCat[0]\n};\n\nvar leaves = [];\n\nvar q = new Queue();\nq.enqueue(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n if (G.edges[node].length === 0) {\n leaves.push(node);\n } else {\n G.edges[node].forEach(function (_ref) {\n var child = _ref.node;\n\n var catsAmountInParent = catsAmount[node];\n var catsAmountInChild = hasCat[child - 1];\n\n if (catsAmountInChild) {\n catsAmount[child] = catsAmountInParent + 1;\n } else {\n catsAmount[child] = 0;\n }\n\n if (catsAmount[child] <= maxCats) q.enqueue(child);\n });\n }\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nwrite(leaves.length);\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (v) {\n return parseInt(v);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n maxCats = _readline$split$map2[1];\n\nvar hasCat = readline().split(' ').map(function (v) {\n return parseInt(v);\n});\n\n// BFS - \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0434\u044b\n// \u041d\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 direct edge \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0441\u0442\u044c\u044f\n\nvar G = new Graph([], true);\n\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 1; _i < n; _i++) {\n var _readline$split$map$s = readline().split(' ').map(function (v) {\n return parseInt(v);\n }).sort(function (a, b) {\n return a - b;\n }),\n _readline$split$map$s2 = _slicedToArray(_readline$split$map$s, 2),\n n1 = _readline$split$map$s2[0],\n n2 = _readline$split$map$s2[1];\n\n G.addEdge(n1, n2);\n}\n\nvar catsAmount = {\n 1: hasCat[0]\n};\n\nvar leaves = [];\n\nvar q = new Queue();\nq.enqueue(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n if (G.edges[node].length === 0) {\n leaves.push(node);\n } else {\n G.edges[node].forEach(function (_ref) {\n var child = _ref.node;\n\n var catsAmountInParent = catsAmount[node];\n var catsAmountInChild = hasCat[child - 1];\n\n if (catsAmountInChild) {\n catsAmount[child] = catsAmountInParent + 1;\n } else {\n catsAmount[child] = 0;\n }\n\n if (catsAmount[child] <= maxCats) q.enqueue(child);\n });\n }\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nwrite(leaves.length);\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "const res = [];\n\nfunction buildTree(n, edges, cats) {\n edges = edges.map(edge => {\n return edge\n .split(' ')\n .map(el => {\n return parseInt(el, 10);\n })\n .sort((a, b) => {\n return a - b;\n });\n });\n edges.sort((a, b) => {\n return a[0] - b[0];\n });\n var tree = [];\n var j = 0;\n for (var i = 1; i <= n; i++) {\n var node = {\n n: i,\n hasCat: parseInt(cats[i - 1], 10) === 1,\n children: []\n };\n while (edges[j] && edges[j][0] === i) {\n node.children.push(edges[j][1]);\n j++;\n }\n tree.push(node);\n }\n return tree;\n}\n\nfunction resolve(node, tree, cats, m) {\n if (!node.hasCat) {\n cats = 0;\n } else {\n cats++;\n }\n if (cats <= m) {\n if (node.children.length === 0) {\n res.push(node.n);\n }\n for (var i = 0; i < node.children.length; i++) {\n resolve(tree[node.children[i] - 1], tree, cats, m);\n }\n }\n}\n\n/*\nconst tree = buildTree(\n 15,\n [\n '1 2',\n '1 3',\n '2 4',\n '2 5',\n '3 6',\n '3 7',\n '4 8',\n '4 9',\n '5 10',\n '5 11',\n '6 12',\n '6 13',\n '7 14',\n '7 15'\n ],\n ['1', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']\n);\nconsole.log(tree);\nresolve(tree[0], tree, 0, 2);\nconsole.log(res);\n*/\n\nconst i = readline().split(' ');\nconst n = parseInt(i[0], 10);\nconst m = parseInt(i[1], 10);\nconst cats = readline().split(' ');\nconst edges = [];\nvar edge = readline();\nwhile (edge) {\n edges.push(edge);\n edge = readline();\n}\nconst tree = buildTree(n, edges, cats);\nresolve(tree[0], tree, 0, m);\nprint(res.length);\n"}, {"source_code": "const res = [];\n\nfunction buildTree(n, edges, cats) {\n edges.sort();\n var tree = [];\n var j = 0;\n for (var i = 1; i <= n; i++) {\n var node = {\n n: i,\n hasCat: parseInt(cats[i - 1], 10) === 1,\n children: []\n };\n while (edges[j] && edges[j][0] === i) {\n node.children.push(edges[j][1]);\n j++;\n }\n tree.push(node);\n }\n return tree;\n}\n\nfunction resolve(node, tree, cats, m) {\n if (!node.hasCat) {\n cats = 0;\n } else {\n cats++;\n }\n if (cats <= m) {\n if (node.children.length === 0) {\n res.push(node.n);\n }\n for (var i = 0; i < node.children.length; i++) {\n resolve(tree[node.children[i] - 1], tree, cats, m);\n }\n }\n}\n\n/*\nconst tree = buildTree(4, ['1 2', '1 3', '1 4'], ['1', '1', '0', '0']);\nresolve(tree[0], tree, 0, 1);\nconsole.log(res);\n*/\n\nconst i = readline().split(' ');\nconst n = parseInt(i[0], 10);\nconst m = parseInt(i[1], 10);\nconst cats = readline().split(' ');\nconst edges = [];\nvar edge = readline();\nwhile (edge) {\n edge = edge\n .split(' ')\n .map(el => {\n return parseInt(el, 10);\n })\n .sort();\n edges.push(edge);\n edge = readline();\n}\nconst tree = buildTree(n, edges, cats);\nresolve(tree[0], tree, 0, m);\nprint(res.length);\n"}, {"source_code": "const res = [];\n\nfunction buildTree(n, edges, cats) {\n edges.sort();\n var tree = [];\n var j = 0;\n for (var i = 1; i <= n; i++) {\n var node = {\n n: i,\n hasCat: parseInt(cats[i - 1], 10) === 1,\n children: []\n };\n while (edges[j] && parseInt(edges[j].split(' ')[0], 10) === i) {\n node.children.push(parseInt(edges[j].split(' ')[1], 10));\n j++;\n }\n tree.push(node);\n }\n return tree;\n}\n\nfunction resolve(node, tree, cats, m) {\n if (!node.hasCat) {\n cats = 0;\n } else {\n cats++;\n }\n if (cats <= m) {\n if (node.children.length === 0) {\n res.push(node.n);\n }\n for (var i = 0; i < node.children.length; i++) {\n resolve(tree[node.children[i] - 1], tree, cats, m);\n }\n }\n}\n\n/*\nconst tree = buildTree(4, ['1 2', '1 3', '1 4'], ['1', '1', '0', '0']);\nresolve(tree[0], tree, 0, 1);\nconsole.log(res);\n*/\n\nconst i = readline().split(' ');\nconst n = parseInt(i[0], 10);\nconst m = parseInt(i[1], 10);\nconst cats = readline().split(' ');\nconst edges = [];\nfor (var j = 0; j < n; j++) {\n edges.push(readline());\n}\nconst tree = buildTree(n, edges, cats);\nresolve(tree[0], tree, 0, m);\nprint(res.length);\n"}, {"source_code": "const res = [];\n\nfunction buildTree(n, edges, cats) {\n edges.sort();\n edges = edges.map(edge => {\n return edge\n .split(' ')\n .map(el => {\n return parseInt(el, 10);\n })\n .sort();\n });\n var tree = [];\n var j = 0;\n for (var i = 1; i <= n; i++) {\n var node = {\n n: i,\n hasCat: parseInt(cats[i - 1], 10) === 1,\n children: []\n };\n while (edges[j] && edges[j][0] === i) {\n node.children.push(edges[j][1]);\n j++;\n }\n tree.push(node);\n }\n return tree;\n}\n\nfunction resolve(node, tree, cats, m) {\n if (!node.hasCat) {\n cats = 0;\n } else {\n cats++;\n }\n if (cats <= m) {\n if (node.children.length === 0) {\n res.push(node.n);\n }\n for (var i = 0; i < node.children.length; i++) {\n resolve(tree[node.children[i] - 1], tree, cats, m);\n }\n }\n}\n\n/*\nconst tree = buildTree(4, ['1 2', '1 3', '1 4'], ['1', '1', '0', '0']);\nresolve(tree[0], tree, 0, 1);\nconsole.log(res);\n*/\n\nconst i = readline().split(' ');\nconst n = parseInt(i[0], 10);\nconst m = parseInt(i[1], 10);\nconst cats = readline().split(' ');\nconst edges = [];\nvar edge = readline();\nwhile (edge) {\n edges.push(edge);\n edge = readline();\n}\nconst tree = buildTree(n, edges, cats);\nresolve(tree[0], tree, 0, m);\nprint(res.length);\n"}], "src_uid": "875e7048b7a254992b9f62b9365fcf9b"} {"source_code": "print(function(n, m) {\n\n\tvar x = 0,\n\t\ty = 0,\n\t\tans = new Int8Array(m),\n\t\ta = rn();\n\n\tfor (var i = 0; i < n; i++)\n\t\tif (a[i] === 1) x++;\n\t\telse y++;\n\n\tx = Math.min(x, y) * 2;\n\n\tfor (var i = 0; i < m; i++) {\n\t\tvar l = rn();\n\t\tans[i] = l[1] - l[0] + 1 > x || (l[1] - l[0]) % 2 === 0 ? 0 : 1;\n\t}\n\n\treturn [].join.call(ans, '\\n');\n\n} .apply(0, rn()));\n\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr;\nlet ones = 0;\nlet minusOnes = 0;\nlet m = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n arr = d.split(' ').map(Number);\n return;\n }\n\n m.push(d.split(' ').map(Number));\n\n c++;\n});\n\nrl.on('close', () => {\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 1) {\n ones++;\n }\n else {\n minusOnes++;\n }\n }\n\n let ans = '';\n for (let j = 0; j < m.length; j++) {\n const [a, b] = m[j];\n const amount = b - a + 1;\n const half = amount / 2;\n\n if (amount % 2 === 1) {\n ans += '0\\n';\n }\n else if (half <= ones && half <= minusOnes) {\n ans += '1\\n';\n }\n else {\n ans += '0\\n';\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "\nprint(function(n, m) {\n\n\tvar x = 0,\n\t\ty = 0,\n\t\tans = new Int8Array(m);\n\trn().forEach(function(v) {\n\t\tif (v === 1) x++;\n\t\telse y++;\n\t});\n\n\tx = Math.min(x, y) * 2;\n\n\tfor (var i = 0; i < m; i++)\n\t\tans[i] = rn().reduce(function(l, r) {\n\t\t\tif (r - l + 1 > x || (r - l) % 2 === 0) return 0;\n\t\t\treturn 1;\n\t\t});\n\n\treturn [].join.call(ans, '\\n');\n\n} .apply(0, rn()));\n\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}\n"}, {"source_code": "print(function(n, m) {\n\n\tvar x = 0,\n\t\ty = 0,\n\t\tans = new Int8Array(m);\n\treadline().split(' ').map(Number).forEach(function(v) {\n\t\tif (v === 1) x++;\n\t\telse y++;\n\t});\n\n\tx = Math.min(x, y) * 2;\n\n\tfor (var i = 0; i < m; i++)\n\t\tans[i] = readline().split(' ').map(Number).reduce(function(l, r) {\n\t\t\tif (r - l + 1 > x || (r - l) % 2 === 0) return 0;\n\t\t\treturn 1;\n\t\t});\n\n\treturn [].join.call(ans, '\\n');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, m) {\n\n\tvar x = 0,\n\t\ty = 0,\n\t\tans = [];\n\trn().forEach(function(v) {\n\t\tif (v === 1) x++;\n\t\telse y++;\n\t});\n\n\tx = Math.min(x, y) * 2;\n\n\tfor (var i = 0; i < m; i++)\n\t\tans.push(rn().reduce(function(l, r) {\n\t\t\tif (r - l + 1 > x || (r - l) % 2 === 0) return 0;\n\t\t\treturn 1;\n\t\t}));\n\n\treturn ans.join('\\n');\n\n} .apply(0, rn()));\n\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}\n"}, {"source_code": ";(function () {\n\tprint(function (n, m) {\n\t\tvar q = {}, t = [];\n\n\t\treadline().split(' ').forEach(function (e) {\n\t\t\tq[e] = q[e] ? q[e] + 1 : 1;\n\t\t});\n\n\t\twhile (m--) {\n\t\t\tvar l = readline().split(' ').map(Number); l = l[1] - l[0] + 1;\n\t\t\tt.push(((l%2) === 0 && q['1'] >= l/2 && q['-1'] >= l/2) ? 1 : 0);\n\t\t}\n\n\t\treturn t.join('\\n');\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n\t\tnumbers = tokenizeIntegers(readline()),\n\t\tpositive = 0, negative = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (numbers[i] == -1) {\n\t\t\tnegative += 1;\n\t\t} else {\n\t\t\tpositive += 1;\n\t\t}\n\t}\n\tvar result = [];\n\tfor (var i = 0; i < m; ++i) {\n\t\tdata = tokenizeIntegers(readline());\n\t\tvar span = data[1] - data[0] + 1;\n\t\tif (span % 2 == 0 && span <= 2*negative && span <= 2*positive) {\n\t\t\tresult.push(1);\n\t\t} else {\n\t\t\tresult.push(0);\n\t\t}\n\t}\n\tprint(result.join('\\n'));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr;\nlet ones = 0;\nlet minusOnes = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n arr = d.split(' ').map(Number);\n\n // for (let i = 0; i < arr.length; i++) {\n // if (arr[i] === 1) {\n // ones++;\n // }\n // else {\n // minusOnes++;\n // }\n // }\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n const amount = b - a + 1;\n\n if (amount % 2 === 1) {\n console.log(0);\n }\n else {\n console.log(1);\n // if (amount / 2 <= ones && amount / 2 <= minusOnes) {\n // console.log(1);\n // }\n // else {\n // console.log(0);\n // }\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr;\nlet ones = 0;\nlet minusOnes = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n arr = d.split(' ');\n\n for (let i = 1; i <= arr.length; i += 2) {\n if (arr[i - 1] === '1') {\n ones++;\n }\n else {\n minusOnes++;\n }\n if (arr[i] === '1') {\n ones++;\n }\n else {\n minusOnes++;\n }\n }\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n const amount = b - a + 1;\n\n if (amount % 2 === 1) {\n console.log(0);\n }\n else {\n if (amount / 2 <= ones && amount / 2 <= minusOnes) {\n console.log(1);\n }\n else {\n console.log(0);\n }\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet str;\nlet ones = 0;\nlet minusOnes = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n if (c === 1) {\n c++;\n str = ' ' + d;\n ones = d.split('-1').length;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n const amount = b - a + 1;\n\n if (amount % 2 === 1) {\n console.log(0);\n }\n else {\n if (amount / 2 <= ones && amount / 2 <= n - ones) {\n console.log(1);\n }\n else {\n console.log(0);\n }\n }\n\n c++;\n});\n"}], "src_uid": "deeb49969ac4bc4f1c7d76b89ac1402f"} {"source_code": "var l1 = readline().split(' ');\nvar t = readline().split(' ').map(function(a){return parseInt(a);});\nvar s = l1[0]===0 ? 0 : 1;\nfor(var i=l1[0]-2; i>=0; i--){\n if(t[i+1]-t[i]>l1[1]) break;\n s++;\n}\nprint(s);", "positive_code": [{"source_code": "var count = 0;\nvar c = readline().split(\" \").map(Number)[1],\n last = 1;\nreadline().split(\" \").map(Number).forEach(function(val){\n if (last) count = val - last <= c ? count + 1 : 1;\n last = val\n});\n\nwrite(count);"}, {"source_code": "N=readline().split(' ').map(x=>+x)\nT=readline().split(' ').map(x=>+x)\nprint(T.reduce((a,c,i)=>((!i)||(T[i]-T[i-1]>N[1]))?1:(a+1),0))\n\n\n"}, {"source_code": "N=readline().split(' ').map(x=>+x)\nT=readline().split(' ').map(x=>+x)\nvar R=T.reduce((a,c,i)=>((!i)||(T[i]-T[i-1]>N[1]))?1:(a+1),0)\n/*var R=1\nfor (var i=1;iN[1])\n R=1\n else R++\n}*/\nprint(R)\n\n\n"}, {"source_code": "N=readline().split(' ').map(x=>+x)\nT=readline().split(' ').map(x=>+x)\nvar R=1\nfor (var i=1;iN[1])\n R=1\n else R++\n}\nprint(R)\n\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n var N = one[0];\n var C = one[1];\n var list = nextIntArray();\n var count = 1;\n for(var i = 1; i < N; i++){\n if(list[i] - list[i - 1] <= C){\n count++;\n }else{\n count = 1;\n }\n }\n myout(count);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet n, c;\n\nrl.on('line', (d) => {\n if (count === 0) {\n [n, c] = d.split(' ').map(Number);\n count++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 1;\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] - arr[i - 1] > c) {\n ans = 1;\n }\n else {\n ans++;\n }\n }\n\n console.log(ans);\n\n count++;\n});\n"}, {"source_code": "var c = readline().split(' ').map((val) => parseInt(val))[1];\nvar t = readline().split(' ').map((val) => parseInt(val));\nvar last_t = 0, count = 0;\nfor (var el of t) {\n count = el - last_t > c ? 1 : count + 1;\n last_t = el\n}\nprint(count);"}, {"source_code": "var c = readline().split(' ').map(Number)[1];\nvar last_t = 0, count = 0;\nreadline().split(' ').map(Number).forEach((el) => {\n count = el - last_t > c ? 1 : count + 1;\n last_t = el\n});\nprint(count);"}, {"source_code": "var c = readline().split(' ').map(Number)[1];\nvar t = readline().split(' ').map(Number);\nvar last_t = 0, count = 0;\nfor (var el of t) {\n count = el - last_t > c ? 1 : count + 1;\n last_t = el\n}\nprint(count);"}, {"source_code": "var c = readline().split(' ').map((val) => parseInt(val))[1];\nvar t = readline().split(' ').map((val) => parseInt(val));\n\nvar last_t = 0, count = 0;\nfor (var el of t) {\n if (el - last_t > c) {\n count = 1\n } else {\n count += 1\n }\n last_t = el\n}\nprint(count);"}, {"source_code": "var b = readline().split(\" \");\n\tvar n = b[0];\n\tvar c = b[1];\n var a = readline().split(\" \");\n\tvar len = a.length;\n\tvar ans = 1;\n\tfor(var j = 0; j < len-1; j++)\n\t{\n\t\tif((a[j+1] - a[j])<=c ){\n\t\t\t++ans;\n\t\t}\n\t\telse {\n\t\t\tans = 1;\n\t\t}\n\t}\n\tprint(ans);"}, {"source_code": "var s = readline().split(\" \");\nvar str = readline().split(\" \");\nvar res = 0;\n\t\tfor (var i=0; i<+s[0]; i++){\n\t\t\tres++;\n\t\t\tif (+str[i+1]-Number(str[i])>+s[1]){\n\t\t\t\tres = 0;\n\t\t\t}\n\t\t\t\n\t\t}\nprint(res);"}, {"source_code": "var count = 0;\nvar c = readline().split(\" \").map(Number)[1],\n last = 1;\nreadline().split(\" \").map(Number).forEach(function(val){\n if (last) count = val - last > c ? 1 : count + 1;\n last = val\n});\n\nwrite(count);"}], "negative_code": [{"source_code": "try {require('codef');} catch (e){global = this};\nfunction readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\n\nvar count = 0;\nvar t = readLineAsIntegerArray(),\n n = t[0],\n c = t[1];\nlast = 0;\nreadLineAsIntegerArray().forEach(function(val, index){\n if (last) count = val - last > c ? 1 : count + 1;\n last = val\n});\n\nwrite(count);\n\n"}, {"source_code": "var line = readline();\nvar alp = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nfunction check(start){\n var map = {}, ch = \"\";\n for(var i = start; i < start + 26; i++) {\n ch = line[i];\n if (map[ch]) return false;\n if (ch == \"?\") continue;\n map[ch] = 1\n }\n return true\n}\n\nvar index = -1;\nif (line.length < 26) {\n write(-1);\n} else {\n for(var i = 0; i <= line.length - 26; i++) {\n if (check(i)) {index = i; break}\n }\n if (index == -1) {\n write(-1)\n } else {\n var res = \"\";\n var repl = \"\";\n for(var i= 0; i < index; i++) res += line[i] == \"?\" ? \"A\" : line[i]\n for(var i = index; i < index + 26; i++) repl += line[i];\n alp = alp.replace(/[A-Z]/g, function (ch) {return repl.indexOf(ch) > -1 ? \"\" : ch}).split(\"\")\n for(var i = index; i < index + 26; i++) res += line[i] == \"?\" ? alp.pop() : line[i]\n for(var i= index + 26; i < line.length; i++) res += line[i] == \"?\" ? \"A\" : line[i]\n write(res);\n }\n}\n\n"}, {"source_code": "try {require('codef');} catch (e){global = this};\nfunction readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\n\nvar count = 1;\nvar t = readLineAsIntegerArray(),\n n = t[0],\n c = t[1];\nlast = 1;\nreadLineAsIntegerArray().forEach(function(val, index){\n if (last) count = val - last > c ? 1 : count + 1;\n last = val\n});\n\nwrite(count);\n\n"}, {"source_code": "function readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\n\nvar count = 1;\nvar t = readLineAsIntegerArray(),\n n = t[0],\n c = t[1];\nlast = 1;\nreadLineAsIntegerArray().forEach(function(val, index){\n if (last) count = val - last > c ? 1 : count + 1;\n last = val\n});\n\nwrite(count);"}], "src_uid": "fb58bc3be4a7a78bdc001298d35c6b21"} {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, m, a) => {\r\n let cnt = Array(m).fill(0);\r\n for (const e of a) cnt[e % m]++;\r\n let res = 0;\r\n for (let i = 0; i <= m >> 1; i++) {\r\n let j = (m - i) % m;\r\n if (!cnt[i] && !cnt[j]) continue;\r\n if (i != j) {\r\n res += mx(1, Math.abs(cnt[i] - cnt[j]));\r\n } else {\r\n res++;\r\n }\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = {};\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar p = list[j] % M;\r\n\t\t\tif(map[p] == null){\r\n\t\t\t\tmap[p] = 0;\r\n\t\t\t}\r\n\t\t\tmap[p]++;\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tvar keys = Object.keys(map);\r\n\t\tvar used = new Set();\r\n\t\tfor(var j = 0; j < keys.length; j++){\r\n\t\t\tif(keys[j] == 0){\r\n\t\t\t\tif(map[keys[j]] > 0){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t}else if(M % 2 == 0 && keys[j] == M / 2){\r\n\t\t\t\tif(map[keys[j]] > 0){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tvar L = myconv(keys[j], 1);\r\n\t\t\t\tvar R = M - L;\r\n\t\t\t\tif(map[L] != null && map[R] != null){\r\n\t\t\t\t\tif(used.has(L) || used.has(R)){\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tused.add(L);\r\n\t\t\t\t\tused.add(R);\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t\tif(Math.abs(map[L] - map[R]) > 1){\r\n\t\t\t\t\t\toutput += Math.max(map[L], map[R]) - Math.min(map[L], map[R]) - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tif(map[L] != null){\r\n\t\t\t\t\t\toutput += map[L];\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\toutput += map[R];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m).fill(0);\r\n\t\tfor (elm of a)\r\n\t\t\tcnt[elm % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]) {\r\n\t\t\t\tif (2 * i % m == 0) {\r\n\t\t\t\t\tans++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tans1 = Math.max(0, cnt[i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans2 = Math.max(0, cnt[m-i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans += 1 + ans1 + ans2; \r\n\t\t\t\tcnt[i] = cnt[m-i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m + 1).fill(0);\r\n\t\tfor (x of a)\r\n\t\t\tcnt[x % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]){\r\n\t\t\t\tif (i == 0 || i == m - i) {\r\n\t\t\t\t\tans++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tans1 = Math.max(0, cnt[i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans2 = Math.max(0, cnt[m-i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans += 1 + ans1 + ans2; \r\n\t\t\t\tcnt[i] = cnt[m-i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, m, a) => {\r\n let cnt = Array(m).fill(0);\r\n for (const e of a) cnt[e % m]++;\r\n let res = 0;\r\n for (let i = 0; i <= m >> 1; i++) {\r\n let j = (m - i) % m;\r\n if (!cnt[i] && !cnt[j]) continue;\r\n if (i != j) {\r\n res += mx(1, cnt[i] >= cnt[j] ? cnt[i] - cnt[j] : cnt[j] - cnt[i]);\r\n } else {\r\n res++;\r\n }\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, m, a) => {\r\n let cnt = Array(m).fill(0);\r\n for (const e of a) cnt[e % m]++;\r\n let res = 0;\r\n for (let i = 0; i <= m >> 1; i++) {\r\n let j = (m - i) % m;\r\n if (!cnt[i] && !cnt[j]) continue;\r\n if (i != j) {\r\n let x = cnt[i];\r\n let y = cnt[j];\r\n if (x < y) [x, y] = [y, x];\r\n res += mx(1, x - y)\r\n } else {\r\n res++;\r\n }\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = iInpArr();\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i] % m]) obj[arr[i] % m]++;\r\n else obj[arr[i] % m] = 1;\r\n }\r\n let cnt = 0,\r\n i = 1,\r\n j = m - 1;\r\n while (i <= j) {\r\n if (obj[i] && obj[j]) {\r\n if (obj[i] === obj[j]) cnt++;\r\n else if (obj[i] > obj[j]) cnt += obj[i] - (obj[j] + 1) + 1;\r\n else cnt += obj[j] - (obj[i] + 1) + 1;\r\n } else if (obj[i]) cnt += obj[i];\r\n else if (obj[j]) cnt += obj[j];\r\n i++;\r\n j--;\r\n }\r\n if (obj[0]) cnt++;\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var count = {}\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var answer = 0\r\n for (let i = 0; i < n; i++) {\r\n if (!count[a[i] % m]) count[a[i] % m] = 0\r\n count[a[i] % m]++\r\n }\r\n var mark = {}\r\n Object.keys(count).map(x => {\r\n x = parseInt(x)\r\n if (x === 0) {\r\n answer += 1\r\n return\r\n }\r\n if (x === m - x) {\r\n answer += 1\r\n return;\r\n }\r\n if (mark[x] || mark[m - x]) return;\r\n var dif = Math.abs((count[m - x] ? count[m - x] : 0) - count[x])\r\n\r\n\r\n // console.log(dif, x, m - x, count[x], count[m - x])\r\n if (dif <= 1) {\r\n answer += 1\r\n } else {\r\n answer += dif\r\n }\r\n mark[x] = true\r\n mark[m - x] = true\r\n })\r\n\r\n console.log(answer)\r\n // console.log(count)\r\n });\r\n\r\n}\r\n\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m);\r\n\t\tfor (elm of a)\r\n\t\t\tcnt[elm % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]) {\r\n\t\t\t\tif (2 * i % m == 0) {\r\n\t\t\t\t\tans++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tans1 = Math.max(0, cnt[i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans2 = Math.max(0, cnt[m-i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans += 1 + ans1 + ans2; \r\n\t\t\t\tcnt[i] = cnt[m-i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m + 1).fill(0);\r\n\t\tfor (x of a)\r\n\t\t\tcnt[x % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]){\r\n\t\t\t\tif (i == 0 || i == m - i) {\r\n\t\t\t\t\tans++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tcnt[i] = Math.max(0, cnt[i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tcnt[m-i] = Math.max(0, cnt[m-i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans += 1 + cnt[i] + cnt[m-i];\r\n\t\t\t\tcnt[i] = cnt[m-i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m + 1).fill(0);\r\n\t\tfor (x of a)\r\n\t\t\tcnt[x % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]){\r\n\t\t\t\tif (i == 0) {\r\n\t\t\t\t\tans++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tcnt[i] = Math.max(0, cnt[i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tcnt[m-i] = Math.max(0, cnt[m-i] - Math.min(cnt[i], cnt[m-i]) - 1);\r\n\t\t\t\tans += 1 + cnt[i] + cnt[m-i];\r\n\t\t\t\tcnt[i] = cnt[m-i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet cnt = Array(m + 1).fill(0);\r\n\t\tfor (x of a)\r\n\t\t\tcnt[x % m]++;\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (cnt[i]){\r\n\t\t\t\tif (Math.abs(cnt[i] - cnt[m-i]) <= 1) {\r\n\t\t\t\t\tcnt[m-i] = 0;\r\n\t\t\t\t}\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = iInpArr();\r\n let obj = {};\r\n for (let i = 0; i < n; i++) arr[i] = arr[i] % m;\r\n let arr1 = [];\r\n for (let i = 0; i < n; i++) if (arr[i] !== 0) arr1.push(arr[i]);\r\n if (arr1.length === 0) {\r\n console.log(1);\r\n continue;\r\n }\r\n let cnt = 0;\r\n if (arr1.length === n) cnt = 0;\r\n else cnt = 1;\r\n arr1.sort((a, b) => a - b);\r\n for (let i = 0; i < arr1.length; i++) {\r\n if (obj[arr1[i]]) obj[arr1[i]].push(i);\r\n else obj[arr1[i]] = [i];\r\n }\r\n let bool = new Array(arr1.length).fill(true);\r\n for (let i = 0; i < n; i++) {\r\n if (bool[i]) {\r\n let t = m - arr1[i];\r\n obj[arr1[i]].shift();\r\n while (obj[t]) {\r\n if (obj[t].length === 0) break;\r\n bool[obj[t].shift()] = false;\r\n t = m - t;\r\n }\r\n cnt++;\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i {\n a = a.sort((x, y) => x - y);\n b = b.sort((x, y) => y - x);\n\n let idx = 0;\n\n for (let i = 0; i < k; i++) {\n if (b[idx] > a[i]) {\n a[i] = b[idx];\n idx++;\n }\n }\n\n return a.reduce((a, b) => a + b, 0);\n};\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (inc % 3 === 0) {\n a = [];\n b = [];\n [n, k] = d.split(\" \").map(Number);\n inc++;\n return;\n }\n\n if (a.length === 0) {\n a = d.split(\" \").map(Number);\n } else if (b.length === 0) {\n b = d.split(\" \").map(Number);\n\n console.log(solve(a, b));\n }\n\n inc++;\n c++;\n});\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() {\n //console.log(\"inputString\", inputString)\n const tests = inputString.slice(1).map(item => item.split(\" \").map(Number));\n //console.log(\"tests\", tests)\n for (let i = 0; i < tests.length; i+=3) {\n const [n, k] = tests[i];\n const a = tests[i + 1];\n const b = tests[i + 2];\n \n const sortedA = a.sort((a, b) => a - b);\n let sortedB = b.sort((a, b) => b - a);\n \n let j = 0;\n while (sortedA[j] <= sortedB[0] && j < k) {\n let temp = sortedA[j];\n sortedA[j] = sortedB[0];\n sortedB[0] = temp;\n j++;\n sortedB = sortedB.sort((a, b) => b - a);\n }\n \n const sum = sortedA.reduce((acc, item) => acc + item, 0);\n console.log(sum);\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nlet main = () => {\n let t = parseInt(readline());\n\n while(t--){\n \tlet [n, k] = readline().split(\" \").map(Number);\n \tlet a = readline().split(\" \").map(Number);\n \tlet b = readline().split(\" \").map(Number);\n \tb.sort((a, b) => a-b);\n \ta.sort((a, b) => a-b);\n \tlet res = 0, ai = 0, bi = n-1;\n \twhile( ai < n ){\n \t\tif( a[ai] < b[bi] && k > 0 ){\n \t\t\tres += b[bi];\n \t\t\tk--;\n \t\t\tbi--;\n \t\t}else{\n \t\t\tres += a[ai];\n \t\t}\n \t\tai++;\n \t}\n\n \tconsole.log(res);\n }\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || (cases[cases.length - 1].a && cases[cases.length - 1].b)) {\n cases.push({\n s: line\n });\n } else if(!cases[cases.length - 1].a) {\n cases[cases.length - 1].a = line;\n } else {\n cases[cases.length - 1].b = line;\n }\n\n const isProcessing = cases.length < problem.T || (!cases[cases.length - 1].a || !cases[cases.length - 1].b);\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, k] = data.s.split(' ').map(i => parseInt(i));\n const a = data.a.split(' ').map(i => parseInt(i));\n const b = data.b.split(' ').map(i => parseInt(i));\n\n for(let j = 0; j < k; j++) {\n a.sort((v1, v2) => +v1 - +v2);\n b.sort((v1, v2) => +v1 - +v2);\n if(a[0] < b[n - 1]) {\n const a0 = a[0];\n a[0] = b[n - 1];\n b[n - 1] = a0;\n }\n }\n \n let sum = a.reduce((i, val) => i + val);\n return sum;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const T = parseInt(readLine(), 10);\n for (let t = 0; t < T; t++) {\n const [n, k] = readLine().split(\" \").map(x => parseInt(x));\n let a = readLine().split(\" \").map(x => parseInt(x));\n let b = readLine().split(\" \").map(x => parseInt(x));\n a = a.sort((a1, b1) => {\n if (a1 > b1) return 1;\n else if (a1 < b1) return -1;\n else return 0;\n });\n b = b.sort((a1, b1) => {\n if (a1 > b1) return -1;\n else if (a1 < b1) return 1;\n else return 0;\n })\n for (let i = 0; i < k;i++) {\n if (a[i] < b[i]) {\n a[i] = b[i];\n }\n }\n const sum = a.reduce((pre, cur) => pre + cur, 0);\n console.log(sum)\n\n }\n}\n"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' ').map(v => +v));\n}).on('close', () => {\n for (ii = 1; ii < tests.length; ii += 3) {\n const k = tests[ii][1];\n let a = tests[ii + 1].sort((x,y) => y - x);\n let b = tests[ii + 2].sort((x,y) => y - x);\n let i = 0;\n while (i < k && a[a.length - 1] < b[0]) {\n const lastA = a[a.length - 1];\n a = [b[0] ,...a.slice(0, a.length - 1)];\n b = [...b.slice(1), lastA];\n i++;\n }\n \n\n let maxA = 0;\n\n a.forEach(element => {\n maxA += element;\n });\n\n process.stdout.write(`${maxA}\\n`);\n }\n});"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar alist = nextIntArray();\n\t\tvar blist = nextIntArray();\n\t\talist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tblist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tfor(var j = 0; j < K; j++){\n\t\t\tif(alist[0] >= blist[blist.length - 1]){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\talist.shift();\n\t\t\talist.push(blist.pop());\n\t\t}\n\t\tvar sum = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tsum += alist[j];\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction readNumbersArray() {\n return readLine().split(' ').map(num => Number(num));\n}\n\nfunction writeLine(str) {\n process.stdout.write(`${str}\\n`);\n}\n\nfunction main() {\n let t = Number(readLine());\n while(t--) {\n const [n, k] = readNumbersArray();\n const a = readNumbersArray().sort((a, b) => a-b);\n const b = readNumbersArray().sort((a, b) => a-b);\n let arr = [];\n let sum = a.reduce((acc, cur) => acc + cur);\n for (let i = 0; i< k; i++) {\n arr.push(a[i], b[n-1-i]);\n sum -= a[i];\n }\n arr = arr.sort((a, b) => a-b).reverse();\n for (let i = 0; i < k; i++) {\n sum += arr[i];\n }\n console.log(sum);\n }\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readline());\n const arrays = [];\n\n for (let i = 0; i < n; i++) {\n arrays.push([\n readline().split(' ').map(o => parseInt(o)),\n readline().split(' ').map(o => parseInt(o)),\n readline().split(' ').map(o => parseInt(o)),\n ]);\n }\n\n arrays.forEach(([[n, k], a, b]) => {\n let sum = a.reduce((acc, oof) => acc + oof, 0);\n let remaining = k;\n let i = 0, j = n - 1;\n a.sort((x, y) => x - y);\n b.sort((x, y) => x - y);\n\n while (remaining && i < n && a[i] < b[j]) {\n if (b[j] > a[i]) {\n sum += (b[j] - a[i]);\n remaining--;\n }\n\n i++;\n j--;\n }\n\n console.log(sum);\n });\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n const a = lines[i*3+2].split(' ').map(x => +x)\n const b = lines[i*3+3].split(' ').map(x => +x)\n a.sort((a, b) => a - b)\n b.sort((a, b) => b - a)\n for (let j =0; j= b[j]) {\n break\n } else {\n a[j] = b[j]\n }\n }\n console.log(a.reduce((r, x) => r+x, 0))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt(), K = nextInt();\n let a = [], b = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n for(let i = 0; i < N; i++) {\n b.push(nextInt());\n }\n\n while (K--) {\n let i = find(a, Math.min);\n let j = find(b, Math.max);\n if (a[i] > b[j]) {\n break;\n }\n let tmp = a[i];\n a[i] = b[j];\n b[j] = tmp;\n }\n\n let result = a.reduce((sum, v) => sum+v);\n\n print(result);\n }\n}\n\nfunction find(arr, func) {\n let result = 0;\n arr.forEach((_, idx) => {\n if (arr[idx] == func(arr[idx], arr[result])) {\n result = idx;\n }\n });\n return result;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// Time Complexity O(n)\nfunction processData(input) {\n input = input.trim().split('\\n')\n var t = Number(input[0])\n // console.log(t)\n var line = 1\n for(var j = 0;jparseInt(a))\n var a = input[line++].split(' ').map(a=>parseInt(a)).sort((a,b)=>(a-b))\n var b = input[line++].split(' ').map(a=>parseInt(a)).sort((a,b)=>(b-a))\n // console.log(n,k,a,b)\n var res = findSum(n,k,a,b)\n console.log(res)\n\n }\n function findSum(n,k,a,b){\n var i = 0\n var sum = 0\n while(i 0){\n if(a[i] < b[i]){\n swap(a,b,i)\n k--\n }\n i++\n }\n // console.log(k)\n for(var l = 0;l Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.split('\\n');\n let t = +inputs[0].trim();\n let cases = inputs.slice(1);\n let loopIndex = 0;\n for (let index = 0; index < t; index++) {\n\n if (cases[loopIndex] !== undefined && cases[loopIndex + 1] != undefined) {\n\n\n const element = cases[loopIndex].trim().split(' ');\n let kMove = +element[1];\n let a = strToNumArr(cases[loopIndex + 1].trim().split(' ')).sort((a, b) => a - b);\n let b = strToNumArr(cases[loopIndex + 2].trim().split(' ')).sort((a, b) => b - a);\n\n for (let j = 0; j < kMove; j++) {\n if (a[j] < b[j]) {\n let temp = a[j];\n a[j] = b[j];\n b[j] = temp;\n }\n }\n\n console.log(a.reduce((a, b) => { return a + b }, 0));\n\n loopIndex += 3;\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 2 1\n 1 2\n 3 4\n 5 5\n 5 5 6 6 5\n 1 2 5 4 3\n 5 3\n 1 2 3 4 5\n 10 9 10 10 9\n 4 0\n 2 2 4 3\n 2 4 2 3\n 4 4\n 1 2 2 1\n 4 4 5 4\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r a + b, 0);\n console.log(sum);\n }\n}"}, {"source_code": "var tescaseNumber = readline();\ntescaseNumber = parseInt(tescaseNumber);\n\nfunction findIndexOf(arr, type) {\n var index = 0;\n for (var i in arr) {\n if (type == 'min') {\n if (parseInt(arr[index]) > parseInt(arr[i])) {\n index = i;\n }\n } else {\n if (parseInt(arr[index]) < parseInt(arr[i])) {\n index = i;\n }\n }\n \n }\n \n return index;\n}\n\nvar currentTestCase = 1;\nwhile (currentTestCase <= tescaseNumber) {\n var input = readline().split(\" \");\n var n = parseInt(input[0]); \n var k = parseInt(input[1]);\n var a = readline().split(\" \");\n var b = readline().split(\" \");\n \n var step = 1;\n while (step <= k) {\n var minIndexA = findIndexOf(a, 'min');\n var maxindexB = findIndexOf(b, 'max');\n \n if (parseInt(a[minIndexA]) >= parseInt(b[maxindexB])) {\n break;\n }\n \n var temp = a[minIndexA];\n a[minIndexA] = b[maxindexB];\n b[maxindexB] = temp;\n \n step += 1;\n }\n \n var total = 0;\n for (var element of a) {\n total += parseInt(element);\n } \n \n print(total);\n currentTestCase += 1;\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var sum = a.reduce((acc, val) => {\n acc += val;\n return acc;\n }, 0);\n\n a = a.sort((a, b) => a - b);\n b = b.sort((a, b) => b - a);\n for (var i = 0; i < k; i++) {\n if (a[i] < b[i]) {\n sum += b[i] - a[i];\n } else break;\n }\n print(sum);\n}\n"}, {"source_code": "function comp(a,b) { return a-b; }\nfunction solve(n,k,a,b) {\n a.sort(comp);\n b.sort(comp);\n var sum = 0;\n for (var i=0; i a[i]))\n a[i] = b[n-i-1];\n sum += a[i];\n }\n return sum;\n}\nvar tc = Number(readline());\nwhile (tc--) {\n var inputArr = readline().split(\" \").map(function(x) { return +x });\n var n = inputArr[0];\n var k = inputArr[1];\n var a = readline().split(\" \").map(function(x) { return +x });\n var b = readline().split(\" \").map(function(x) { return +x });\n print(solve(n,k,a,b));\n}"}], "negative_code": [{"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || (cases[cases.length - 1].a && cases[cases.length - 1].b)) {\n cases.push({\n s: line\n });\n } else if(!cases[cases.length - 1].a) {\n cases[cases.length - 1].a = line;\n } else {\n cases[cases.length - 1].b = line;\n }\n\n const isProcessing = cases.length < problem.T || (!cases[cases.length - 1].a || !cases[cases.length - 1].b);\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, k] = data.s.split(' ').map(i => +i);\n const a = data.a.split(' ').map(i => +i);\n const b = data.b.split(' ').map(i => +i);\n\n a.sort();\n b.sort((v1, v2) => v2 > v1);\n\n for(let j = 0; j < k; j++) {\n if(a[j] < b[j]) {\n const aj = a[j];\n a[j] = b[j];\n b[j] = aj;\n }\n }\n \n let sum = a.reduce((i, val) => i + val);\n return sum;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const T = parseInt(readLine(), 10);\n for (let t = 0; t < T; t++) {\n const [n, k] = readLine().split(\" \").map(x => parseInt(x));\n let a = readLine().split(\" \").map(x => parseInt(x));\n let b = readLine().split(\" \").map(x => parseInt(x));\n a = a.sort();\n b = b.sort((a1, b1) => {\n if (a1 > b1) return -1;\n else if (a1 < b1) return 1;\n else return 0;\n })\n for (let i = 0; i < k; i++) {\n if (a[i] < b[i]) {\n a[i] = b[i];\n } else break;\n }\n const sum = a.reduce((pre, cur) => pre + cur, 0);\n console.log(sum)\n\n }\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const T = parseInt(readLine(), 10);\n for (let t = 0; t < T; t++) {\n const [n, k] = readLine().split(\" \").map(x => parseInt(x));\n let a = readLine().split(\" \").map(x => parseInt(x));\n let b = readLine().split(\" \").map(x => parseInt(x));\n a = a.sort();\n b = b.sort((a1, b1) => {\n if (a1 > b1) return -1;\n else if (a1 < b1) return 1;\n else return 0;\n })\n for (let i = 0; i < k;i++) {\n if (a[i] < b[i]) {\n a[i] = b[i];\n }\n }\n const sum = a.reduce((pre, cur) => pre + cur, 0);\n console.log(sum)\n\n }\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const T = parseInt(readLine(), 10);\n for (let t = 0; t < T; t++) {\n const [n, k] = readLine().split(\" \").map(x => parseInt(x));\n let a = readLine().split(\" \").map(x => parseInt(x));\n let b = readLine().split(\" \").map(x => parseInt(x));\n a = a.sort();\n b = b.sort((a1, b1) => {\n if (a1 > b1) return -1;\n else if (a1 < b1) return 1;\n else return 0;\n })\n for (let i = 0; i < k && i < n; i++) {\n if (a[i] < b[i]) {\n a[i] = b[i];\n } else break;\n }\n const sum = a.reduce((pre, cur) => pre + cur, 0);\n console.log(sum)\n\n }\n}\n"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line.split(' ').map(v => +v));\n}).on('close', () => {\n for (ii = 1; ii < tests.length; ii += 3) {\n const k = tests[ii][1];\n let a = tests[ii + 1].sort((x,y) => x < y);\n let b = tests[ii + 2].sort((x,y) => x < y);\n\n let i = 0;\n while (i < k && a[a.length - 1] < b[0]) {\n const lastA = a[a.length - 1];\n a = [b[0] ,...a.slice(0, a.length - 1)];\n b = [...b.slice(1), lastA];\n i++;\n }\n\n let maxA = 0;\n\n a.forEach(element => {\n maxA += element;\n });\n\n process.stdout.write(`${maxA}\\n`);\n }\n});"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar alist = nextIntArray();\n\t\tvar blist = nextIntArray();\n\t\talist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tblist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tfor(var j = 0; j < K; j++){\n\t\t\talist.shift();\n\t\t\talist.push(blist.pop());\n\t\t}\n\t\tvar sum = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tsum += alist[j];\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction readNumbersArray() {\n return readLine().split(' ').map(num => Number(num));\n}\n\nfunction writeLine(str) {\n process.stdout.write(`${str}\\n`);\n}\n\nfunction main() {\n let t = Number(readLine());\n while(t--) {\n const [n, k] = readNumbersArray();\n const a = readNumbersArray().sort();\n const b = readNumbersArray().sort();\n let arr = [];\n let sum = a.reduce((acc, cur) => acc + cur);\n for (let i = 0; i< k; i++) {\n arr.push(a[i], b[n-1-i]);\n sum -= a[i];\n }\n arr = arr.sort().reverse();\n for (let i = 0; i < k; i++) {\n sum += arr[i];\n }\n console.log(sum);\n }\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const n = parseInt(readline());\n const arrays = [];\n\n for (let i = 0; i < n; i++) {\n arrays.push([\n readline().split(' ').map(o => parseInt(o)),\n readline().split(' ').map(o => parseInt(o)),\n readline().split(' ').map(o => parseInt(o)),\n ]);\n }\n\n arrays.forEach(([[n, k], a, b]) => {\n let sum = a.reduce((acc, oof) => acc + oof, 0);\n let remaining = k;\n let i = 0, j = n - 1;\n a.sort((x, y) => x - y);\n b.sort((x, y) => x - y);\n\n while (remaining && i <= j) {\n if (b[j] > a[i]) {\n sum += (b[j] - a[i]);\n remaining--;\n }\n\n i++;\n j--;\n }\n\n console.log(sum);\n });\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt(), K = nextInt();\n let a = [], b = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n for(let i = 0; i < N; i++) {\n b.push(nextInt());\n }\n\n while (K--) {\n let i = find(a, Math.min);\n let j = find(b, Math.max);\n let tmp = a[i];\n a[i] = b[j];\n b[j] = tmp;\n }\n\n let result = a.reduce((sum, v) => sum+v);\n\n print(result);\n }\n}\n\nfunction find(arr, func) {\n let result = 0;\n arr.forEach((_, idx) => {\n if (arr[idx] == func(arr[idx], arr[result])) {\n result = idx;\n }\n });\n return result;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.split('\\n');\n let t = +inputs[0].trim();\n let cases = inputs.slice(1);\n let loopIndex = 0;\n for (let index = 0; index < t; index++) {\n const element = cases[loopIndex].trim().split(' ');\n let kMove = +element[1];\n let a = strToNumArr(cases[loopIndex + 1].trim().split(' '));\n let b = strToNumArr(cases[loopIndex + 2].trim().split(' ')).sort((a, b) => b - a);\n\n for (let j = 0; j < kMove; j++) {\n if (a[j] < b[j]) {\n let temp = a[j];\n a[j] = b[j];\n b[j] = temp;\n }\n }\n\n console.log(a.reduce((a, b) => { return a + b }, 0));\n\n loopIndex += 3;\n\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n 2 1\n 1 2\n 3 4\n 5 5\n 5 5 6 6 5\n 1 2 5 4 3\n 5 3\n 1 2 3 4 5\n 10 9 10 10 9\n 4 0\n 2 2 4 3\n 2 4 2 3\n 4 4\n 1 2 2 1\n 4 4 5 4\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r a+b, 0);\n let sumB = b.reduce((a,b) => a + b, 0);\n\n if(sumA < sumB) {\n while(swap) {\n min = Math.min(...a);\n max = Math.max(...b);\n minI = a.indexOf(min);\n maxJ = b.indexOf(max);\n\n a[minI] = max;\n b[maxJ] = 0;\n swap--;\n }\n }\n\n let sum = a.reduce((a, b) => a + b, 0);\n console.log(sum);\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var a = readline()\n .split(\"\")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\"\")\n .map((val) => parseInt(val));\n var sum = a.reduce((acc, val) => {\n acc += val;\n return acc;\n }, 0);\n a = a.sort((a, b) => a - b);\n b = b.sort((a, b) => b - a);\n for (var i = 0; i < k; i++) {\n if (a[i] < a[b]) {\n sum += b[i] - a[i];\n } else break;\n }\n print(sum);\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var sum = a.reduce((acc, val) => {\n acc += val;\n return acc;\n }, 0);\n a = a.sort((a, b) => a - b);\n b = b.sort((a, b) => b - a);\n for (var i = 0; i < k; i++) {\n if (a[i] < a[b]) {\n sum += b[i] - a[i];\n } else break;\n }\n print(sum);\n}\n"}], "src_uid": "7c2337c1575b4a62e062fc9990c0b098"} {"source_code": "var i,a = readline(), b = readline();\n\ni=0;\nwhile(a[i]=='0') i++;\nif(i>0) a=a.substring(i,a.length);\na=a.split('');\n\ni=0;\nwhile(b[i]=='0') i++;\nif(i>0) b=b.substring(i,b.length);\nb=b.split('');\n\nvar found = false;\nif(a.length === b.length) {\n\n for(var i=0;ib[i]) {\n print('>');found =true;break;\n } else if(a[i]');\nelse print('<');\n}\n ", "positive_code": [{"source_code": "var s1 = readline();\nvar s2 = readline();\n\nfunction trim(s) {\n var a = -1;\n for (var i = 0; i < s.length; i++) {\n if (s[i] != '0')\n return s.substr(i);\n }\n return '0';\n}\n\nfunction cmp(s1, s2) {\n s1 = trim(s1);\n s2 = trim(s2);\n if (s1.length == s2.length) {\n for (var i = 0; i < s1.length; i++) {\n var v = s1.codePointAt(i) - s2.codePointAt(i);\n if (v == 0) {\n continue;\n } else {\n print(v > 0 ? '>' : '<');\n return;\n }\n }\n print('=');\n } else {\n print(s1.length > s2.length ? '>' : '<')\n }\n}\ncmp(s1, s2);\n\n//main.apply(0, readNums());\n//function main(n, m) {\n//}\n//function readNums() {\n// return readline().split(' ').map(function(v) {\n// return v - 0;\n// })\n//}\n//function readline() {\n// return '00012345'\n//}\n//function print(v) {\n// console.log(v)\n//}\n"}, {"source_code": "var n1 = readline();\nvar n2 = readline();\n\nfunction compare(a, b) {\n while (true) {\n \n if (a.length == 0 || b.length == 0) return \"=\";\n \n var a0 = a.charAt(0);\n var b0 = b.charAt(0);\n \n if (a.length == b.length) {\n if (a0 > b0) return \">\";\n else if (a0 < b0) return \"<\";\n else if (a0 == b0) {\n a = a.substr(1);\n b = b.substr(1);\n }\n }\n else if (a.length > b.length) {\n if (a0 == \"0\") a = a.substr(1);\n else return \">\";\n }\n else if (a.length < b.length) {\n if (b0 == \"0\") b = b.substr(1);\n else return \"<\";\n }\n \n }\n}\nprint(compare(n1, n2));"}], "negative_code": [{"source_code": "var i,a = readline(), b = readline();\n\ni=0;\nwhile(a[i]=='0') i++;\nif(i>0) a=a.substring(i,a.length);\na=a.split('');\n\ni=0;\nwhile(b[i]=='0') i++;\nif(i>0) b=b.substring(i,b.length);\nb=b.split('');\n\nvar found = false;\nif(a.length === b.length) {\n\n for(var i=0;ib[i]) {\n print('>');found =true;break;\n } else if(a[i]..');\nelse print('<.');\n}\n "}, {"source_code": "var i,a = readline(), b = readline();\n\ni=0;\nwhile(a[i]=='0') i++;\nif(i>0) a=a.substring(i,a.length);\na=a.split('');\n\ni=0;\nwhile(b[i]=='0') i++;\nif(i>0) b=b.substring(i,b.length);\nb=b.split('');\n\nvar found = false;\nif(a.length === b.length) {\n\n for(var i=0;ib[i]) {\n print('>');found =true;\n } else if(a[i]');\nelse print('<');\n}\n "}], "src_uid": "fd63aeefba89bef7d16212a0d9e756cd"} {"source_code": "(function main() {\n readline();\n var input = readline().split(' ');\n var output = '';\n var nulls = 0;\n var flag = false;\n /*if (input.length === 1) {\n print(input[0]);\n return 0;\n }*/\n function isBeautiful(str) {\n var len = str.length;\n \n if (str[0] !== '1' && str[0] !== '0') return false;\n for (var i = 1; i < len; i++)\n if (str[i] !== '0') return false;\n return true;\n }\n try {\n \n input.forEach(function (s) {\n if (s === '0') {\n print('0');\n throw false;\n }\n if (flag || isBeautiful(s)) {\n nulls += s.length - 1;\n } else {\n output = s;\n flag = true;\n }\n });\n } catch (e) {\n if (e === false)\n return 0;\n else\n throw e;\n }\n if (!flag) {\n output += '1';\n }\n for (var i = 0; i < nulls; i++)\n output += '0';\n print(output);\n return 0;\n}());", "positive_code": [{"source_code": " (function f() \n {\n var n = +readline();\n var k0=0;\n var kr=null;\n var m = readline().split(' ');\n //for (var i =0 ;i parseInt(x));\n print(ar[1]-ar[0] >= ar[0] ? \"NO\" : \"YES\");\n}", "positive_code": [{"source_code": "var n = parseInt(readline());\n\nfor(var it=0;itparseInt(item));\n var item1 = ar[0];\n var item2 = ar[1];\n print( item1*2>item2? \"YES\":\"NO\" )\n}"}, {"source_code": " var testCasesNumber = readline();\nvar listOfRange = [];\n\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfRange.push(readline().split(' '));\n }\nfor (var i = 0; i < testCasesNumber; i++) {\n print(parseInt(listOfRange[i][1])-parseInt(listOfRange[i][0]) >= parseInt(listOfRange[i][0]) ? 'NO' : 'YES');\n }\n\n\n"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var p = readline().split(\" \").map(x => +x);\n var l = p[0];\n var r = p[1];\n \n if (l * 2 > r) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n}"}, {"source_code": "var testcases = parseInt(readline());\n\nwhile(testcases--)\n{\n var ar = readline().split(' ').map(x => parseInt(x));\n \n if(ar[0] * 2 > ar[1]) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n}"}, {"source_code": "const solve = (l, r) => {\n return 2 * l > r ? 'YES' : 'NO';\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0][0], data[0][1]));\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var Ar = readline().split(' ').map(x => parseInt(x));\n var n = Ar[0], m = Ar[1];\n print(m - n >= n ? 'NO' : 'YES');\n}\n"}, {"source_code": "function main() {\n let n = stdin[0];\n let x=[],y=[];\n for(let i=0;iy[i]){\n console.log('YES');\n }\n else{\n console.log('NO');\n }\n }\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {line.split(' ').map(c => stdin.push(parseInt(c)))});\nrl.on('close', main);\n"}, {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var AR = readline().split(' ').map(x => parseInt(x));\n var n = AR[0], m = AR[1];\n print(m-n >= n ? 'NO' : 'YES');\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n if (b >= 2 * a) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var L = one[0];\n var R = one[1];\n output[i] = (L * 2 > R) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', function() {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction getAns(start, end) {\n if ((end + 1)/2 <= start) return 'YES';\n else return 'NO'\n}\n \nfunction main() {\n \n const t = parseInt(readLine(), 10);\n \n for (let tItr = 0; tItr < t; tItr++) {\n const [start, end] = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));\n \n const result = getAns(start, end);\n \n console.log(result + '\\n');\n }\n}\n"}, {"source_code": "'use strict'\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n a,x,\n mod=0,\n div=0;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = TC.split(' ');\n a = Number(arr[0]); //l\n x = Number(arr[1]);\n div = x/2; //r\n if(a<=div){console.log(\"NO\")}\n else{console.log(\"YES\")}\n count++;\n if (count == nb) {\n rl.close();\n }\n });\n});\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(h){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return i[u++]}function f(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;re?\"YES\":\"NO\")}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [l, r] = io.nextNumbers()\n// \n// io.puts(l * 2 > r ? \"YES\" : \"NO\")\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n for (let i = 0; i < x; i++) {\n const y = readline().split(\" \")\n if (Number(y[0]) * 2 > Number(y[1])) {\n console.log(\"YES\")\n } else {\n console.log(\"NO\")\n }\n }\n}\n"}], "negative_code": [{"source_code": "var testcase = parseInt(readline())\nwhile(testcase--)\n{\n var l = parseInt(readline())\n var r = parseInt(readline())\n \n if(2 * l > r) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n if (a === 1 || b === 1) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n if (a % b === 0 || b % a === 0) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n if (2 * a >= b) console.log(\"NO\");\n else console.log(\"YES\");\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', function() {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n \n main();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n \nfunction getAns(start, end) {\n if ((end + 1)/2 < start) return 'YES';\n else return 'NO'\n}\n \nfunction main() {\n \n const t = parseInt(readLine(), 10);\n \n for (let tItr = 0; tItr < t; tItr++) {\n const [start, end] = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));\n \n const result = getAns(start, end);\n \n console.log(result + '\\n');\n }\n}\n"}, {"source_code": "'use strict'\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n a,x,\n mod=0,\n div=0;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = TC.split(' ');\n a = Number(arr[0]);\n x = Number(arr[1]);\n mod = x%a;\n div = a/2;\n if(mod>=div){console.log(\"YES\")}\n else{console.log(\"NO\")}\n count++;\n if (count == nb) {\n rl.close();\n }\n });\n});\n"}], "src_uid": "5172d358f1d451b42efff1019219a54d"} {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar lines = numbers[0];\nvar stock = numbers[1];\nvar distress = 0;\n\nvar queue = [];\n\nfor (var i=0; i= Number(arr[1])) {\n icePacks = icePacks - Number(arr[1])\n }\n else\n childDestress++;\n }\n}\nprint(icePacks, childDestress);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let [n, x] = readint();\n let distres = 0;\n for(let i = 0; i < n; i++) {\n let [sign, num] = readline().split(\" \");\n num = parseInt(num);\n if(sign == '+') {\n x += num;\n } else {\n if(x < num) distres++;\n else x -= num;\n }\n }\n print(x + \" \" + distres);\n\n}"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let {0:n, 1:x} = {...input[0].split(' ')};\n n = parseInt(n, 10); x = parseInt(x, 10);\n \n let d = 0;\n for(let i = 0; i < n; i += 1){\n const data = input[i+1].split(' ');\n if(data[0] === '+') {\n x += parseInt(data[1], 10);\n } else {\n if(x >= parseInt(data[1], 10)) {\n x -= parseInt(data[1], 10);\n } else {\n d += 1;\n }\n }\n }\n\n console.log(`${x} ${d}`)\n});\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet [t,d]=readLine().split(\" \").map(n=>+n)\n\tlet distressed = 0\n\twhile(t--){\n\t\tlet [sign,amt] = readLine().split(\" \")\n\t\tsign === '+' ? \n\t\t\td+=parseInt(amt)\n\t\t: amt > d ? distressed++ : d-=parseInt(amt)\n\t}\n\n\tconsole.log(d,distressed)\n}"}, {"source_code": "var input = readline().split(' ').map(function(item){return parseInt(item)});\nvar n = input[0], x = input[1], distress = 0;\nfor(var i = 0; i < n; i++){\n\tvar num = parseInt(readline().split(' ').join(''));\n\tif(num >= 0){\n\t\tx += num;\n\t} else {\n\t\tif(x + num < 0){\n\t\t\tdistress++;\n\t\t} else {\n\t\t\tx += num;\n\t\t}\n\t}\n}\n\n\nprint(x, distress);"}, {"source_code": "input = readline().split(' ');\nn = parseInt(input[0]);\nm = parseInt(input[1]);\nvar ans = 0;\nfor(var i=0;i=s1){carrer-=s1}else{calc+=1}\n}\n\n\n\n}\n\nprint(carrer +\" \"+calc);"}, {"source_code": "var input = readline().split(\" \").map(Number);\nvar n = input[0], x = input[1];\n\nvar sad = 0;\nfor(var i = 0; i < n; i++){\n input = readline().split(\" \");\n var d = +input[1];\n if(input[0] == \"+\"){\n x += d;\n }else{\n if(x >= d){\n x -= d;\n }else{\n sad++;\n }\n }\n}\n\nwrite(x + \" \" + sad);"}, {"source_code": "var values = readline().split(\" \");\nvar n = parseInt(values[0]);\nvar x = parseInt(values[1]);\n\nvar packs = x;\nvar distress = 0;\n\nfor (var i = 0; i < n; i++) {\n var ice = readline().split(\" \");\n var k = ice[0];\n var m = parseInt(ice[1]);\n \n if (k === \"+\") {\n packs += m;\n } else {\n if (m > packs) {\n distress++;\n } else {\n packs -= m;\n }\n }\n}\n\nprint(`${packs} ${distress}`);"}, {"source_code": "var x = readline();\nvar numArr = x.split(' ').map(Number);\nvar num = numArr[0];\nvar q = [];\nfor(var i = 0; i < num; i++){\n var thisLine = readline();\n q.push(thisLine.split(' '));\n}\n\nvar iceCounter = numArr[1], dCounter = 0;\n\nfor(var i = 0; i < num; i++){\n q[i][1] = parseInt(q[i][1]);\n\n if (q[i][0] == '-'){\n if(iceCounter >= q[i][1])\n iceCounter -= q[i][1];\n else\n dCounter++;\n }\n else if ((q[i][0] == '+'))\n iceCounter += q[i][1];\n}\n\n\n\nprint(iceCounter, dCounter);\n\n\n"}, {"source_code": "var informations = readline().split(' ').map(Number)\n var numberOfPeopleInLine = informations[0]\n var numberOfPacket = informations[1]\n var distress = 0\n\n for (var i = 0; i < numberOfPeopleInLine; i++) {\n var info = readline().split(' ')\n\n if (info[0] === '+') {\n numberOfPacket += Number(info[1])\n } else {\n if (Number(info[1]) > numberOfPacket) {\n distress += 1\n } else {\n numberOfPacket -= Number(info[1])\n }\n }\n }\n\n print(Number(numberOfPacket) + ' ' + Number(distress))"}, {"source_code": "var g = readline();\ng = g.split(\" \");\nvar n = Number(g[0]);\nvar x = Number(g[1]);\nvar count = x;\nvar child = 0;\nfor(i=1;i<=n;i++){\n var y = readline();\n y = y.split(\" \");\n var b = y[0];\n var c = Number(y[1]);\n if(b == \"+\"){\n count += c;\n }\n else if(b == \"-\"){\n if(c <= count){\n count -= c;\n }\n else{\n child++;\n }\n }\n}\nprint(count,child)"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar arr = readline().replace(/\\r$/, '').split(' '), ice = Number(arr[1]), ans = [ice, 0], line;\n\nfor (i = 0; i < Number(arr[0]); i++) {\n line = readline().replace(/\\r$/, '').split(' ');\n\n if (line[0] === '+') {\n ans[0] += Number(line[1]);\n } else {\n if (Number(line[1]) > ans[0]) {\n ans[1]++;\n } else {\n ans[0] -= Number(line[1]);\n }\n }\n}\n\nprint(ans.join(' '));"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n var N = one[0];\n var X = one[1];\n var count = 0;\n for(var i = 0; i < N; i++){\n \tvar tmp = nextStrArray();\n \tvar k = tmp[0];\n \tvar f = myconv(tmp[1], 1);\n \tif(k == \"+\"){\n \t\tX += f;\n \t}else{\n \t\tif(X >= f){\n \t\t\tX -= f;\n \t\t}else{\n \t\t\tcount++;\n \t\t}\n \t}\n }\n myout(X + \" \" + count);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n let [n, x] = readline().split(' ').map(x => parseInt(x));\n let c = 0;\n for (let i = 0; i < n; i++) {\n let [s, a] = readline().split(' ');\n a = +a;\n if (s === '+') {\n x += a;\n } else {\n if (x - a >= 0) {\n x -= a;\n } else {\n c++;\n }\n }\n }\n print(`${x} ${c}`);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet iceCream = 0;\nlet disappointed = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [x, iceCream] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n let [sign, val] = d.split(' ');\n\n if (sign === '+') {\n iceCream += +val;\n }\n else {\n if (iceCream >= +val) {\n iceCream -= +val;\n }\n else {\n disappointed++;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(iceCream, disappointed);\n});\n"}, {"source_code": "var input = readline().split(' ');\nvar n = Number(input[0]), x = Number(input[1]);\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n}\n\nwrite(x, ' ', sad);"}], "negative_code": [{"source_code": "var g = readline();\ng.split(\" \");\nvar n = Number(g[0]);\nvar x = Number(g[1]);\nvar count = x;\nvar child = 0;\nfor(i=0;i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0], x = input[1];\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0], x = input[1] + 0;\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = Number(input[0]), x = Number(input[1]);\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0], x = input[1];\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0], x = input[1];\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ').map(Number);\nvar n = input[0], x = input[1];\nvar sad = 0;\n\nwrite(n+2);\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0], x = input[1];\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var input = readline().split(' ');\nvar n = Number(input[0]), x = Number(input[1]);\nvar sad = 0;\n\nfor (var i=0; i= d)\n\t\tx -= d;\n\telse\n\t\tsad++;\n\t\t\n\twrite(x, ' ', sad, '|');\n}\n\nwrite(x, ' ', sad);"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar lines = numbers[0];\nvar stock = numbers[1];\nvar distress = 0;\n\nvar queue = [];\n\n// for (let i=0; i {\n if (c === 0) {\n [x, iceCream] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n let [sign, val] = d.split(' ');\n\n if (sign === '+') {\n iceCream += +val;\n }\n else {\n if (iceCream > +val) {\n iceCream -= +val;\n }\n else {\n disappointed++;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(iceCream, disappointed);\n});\n"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n// var lines = numbers[0];\n// var stock = numbers[1];\n// var distress = 0;\n\n// var queue = [];\n\n// for (let i=0; i=k)\n {\n res++\n }\n }\n}\nif (k>1)\nfor (j=0;j=k)\n {\n res++\n }\n }\n}\nprint(res)", "positive_code": [{"source_code": "nmk = readline().split(' ').map(Number);\n\nvar n = nmk[0], m = nmk[1], k = nmk[2], arr = new Array(n), res = 0;\n\nfor (var i = 0; i < n; i++) {\n\tarr[i] = readline();\n\n\tvar count = 0;\n\n\tfor (var j = 0; j < m; j++) {\n\t\tif (arr[i][j] == '.') {\n\t\t\tcount++;\n\t\t} else {\t\t\t\n\t\t\tcount = 0;\n\t\t};\n\n\t\tif (count >= k) {\n\t\t\tres++;\n\t\t};\n\t};\n};\n\nif (k > 1) {\n\tfor (var j = 0; j < m; j++) {\n\n\t\tvar count = 0;\n\n\t\tfor (var l = 0; l < n; l++) {\n\t\t\tif (arr[l][j] == '.') {\n\t\t\t\tcount++;\n\t\t\t} else {\n\t\t\t\tcount = 0;\n\t\t\t};\n\n\t\t\tif (count >= k) {\n\t\t\t\tres++;\n\t\t\t};\n\t\t};\n\t};\n};\n\nprint(res);"}, {"source_code": "s=readline().split(' ')\nn=+s[0]\nm=+s[1]\nk=+s[2]\na=new Array(n)\nres=0\nfor (i=0;i=k)\n {\n res++\n }\n }\n}\nif (k>1)\nfor (j=0;j=k)\n {\n res++\n }\n }\n}\nprint(res)"}, {"source_code": "a = readline().split(' ');\nb =+ a[0];\nc =+ a[1];\nd =+ a[2];\ne = 0;\nf = new Array(b);\nfor(x = 0; x < b; x++)\n{\n f[x] = readline();\n g = 0;\n for(y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++;\n }\n }\n}\nif(d > 1)\n{\n for(y = 0; y < c; y++)\n {\n g = 0;\n for(x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0;\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e);"}, {"source_code": "a = readline().split(' ');\nvar b =+ a[0];\nvar c =+ a[1];\nvar d =+ a[2];\nvar e = 0;\nvar f = new Array(b);\nfor(var x = 0; x < b; x++)\n{\n f[x] = readline();\n var g = 0;\n for(var y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++;\n }\n }\n}\nif(d > 1)\n{\n for(var y = 0; y < c; y++)\n {\n var g = 0;\n for(var x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0;\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e);"}, {"source_code": "a = readline().split(' ')\nb =+ a[0]\nc =+ a[1]\nd =+ a[2]\ne = 0\nf = new Array(b)\nfor(x = 0; x < b; x++)\n{\n f[x] = readline()\n g = 0\n for(y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++\n }\n }\n}\nif(d > 1)\n{\n for(y = 0; y < c; y++)\n {\n g = 0\n for(x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e)"}, {"source_code": "a = readline().split(' ');\nvar b = a[0];\nvar c = a[1];\nvar d = a[2];\nvar e = 0;\nvar f = new Array();\nfor(var x = 0; x < b; x++)\n{\n f[x] = readline();\n var g = 0;\n for(var y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++;\n }\n }\n}\nif(d > 1)\n{\n for(var y = 0; y < c; y++)\n {\n var g = 0;\n for(var x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0;\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e);"}, {"source_code": "a = readline().split(' ');\nvar b =+ a[0];\nvar c =+ a[1];\nvar d =+ a[2];\nvar e = 0;\nvar f = new Array();\nfor(var x = 0; x < b; x++)\n{\n f[x] = readline();\n var g = 0;\n for(var y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++;\n }\n }\n}\nif(d > 1)\n{\n for(var y = 0; y < c; y++)\n {\n var g = 0;\n for(var x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0;\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e);"}, {"source_code": "a = readline().split(' ')\nb = a[0]\nc = a[1]\nd = a[2]\ne = 0\nf = new Array(b)\nfor(x = 0; x < b; x++)\n{\n f[x] = readline()\n g = 0\n for(y = 0; y < c; y++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++\n }\n }\n}\nif(d > 1)\n{\n for(y = 0; y < c; y++)\n {\n g = 0\n for(x = 0; x < b; x++)\n {\n if(f[x][y] == '.')\n {\n g++;\n }\n else\n {\n g = 0\n }\n if(g >= d)\n {\n e++\n }\n }\n }\n}\nprint(e)"}, {"source_code": "'use strict';\n\nfunction Scanner() {\n this.nextLine = () => readline();\n this.nextInt = () => parseInt(readline());\n this.nextDouble = () => parseInt(readline());\n this.nextArray = () => readline().split(' ');\n}\n\nconst is = new Scanner();\n\nlet line = is.nextArray().map(Number);\nconst n = line[0];\nconst m = line[1];\nconst k = line[2];\n\nconst grid = new Array(n);\nfor (let i = 0; i < n; i++)\n grid[i] = is.nextLine();\n\n// rows\nlet answer = 0, aux;\nfor (const row of grid) {\n aux = 0;\n for (const i of row)\n if (i === '.')\n aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nif (k !== 1) {\n for (let j = 0; j < m; j++) {\n aux = 0;\n for (let i = 0; i < n; i++)\n if (grid[i][j] === '.')\n aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n }\n}\n\nprint(answer)\n"}], "negative_code": [{"source_code": "var a = readline().split(' ');\nvar b = a[0];\nvar c = a[1];\nvar d = a[2];\nvar e = new Array();\nvar f = 0;\nfor(x = 0; x < b; x++)\n{\n e[x] = readline();\n h = 0;\n for(y = 0; y < c; y++)\n {\n if(e[x][y] == '.')\n {\n h++;\n }\n else\n {\n h = 0;\n }\n if(h >= d)\n {\n f++;\n }\n }\n}\nif(d > 1)\n{\n for(x = 0; x < b; x++)\n {\n var h = 0;\n for(y = 0; y < c; y++)\n {\n if(e[x] == \".\")\n {\n h++;\n }\n else\n {\n h = 0;\n }\n if(h >= d)\n {\n f++;\n }\n }\n }\n}\nprint(f);"}, {"source_code": "'use strict';\n\nfunction Scanner() {\n this.nextLine = () => readline();\n this.nextInt = () => parseInt(readline());\n this.nextDouble = () => parseInt(readline());\n this.nextArray = () => readline().split(' ');\n}\n\nconst is = new Scanner();\n\nlet line = is.nextArray().map(Number);\nconst n = line[0];\nconst m = line[1];\nconst k = line[2];\n\nconst grid = new Array(n);\nfor (let i = 0; i < n; i++)\n grid[i] = is.nextLine();\n\n// rows\nlet answer = 0, aux;\nfor (const row of grid) {\n aux = 0;\n for (const i of row)\n if (i === '.')\n aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nfor (let j = 0; j < m; j++) {\n aux = 0;\n for (let i = 0; i < n; i++)\n if (grid[i][j] === '.')\n aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nprint(answer)\n"}, {"source_code": "'use strict';\n\nfunction Scanner() {\n this.nextLine = () => readline();\n this.nextInt = () => parseInt(readline());\n this.nextDouble = () => parseInt(readline());\n this.nextArray = () => readline().split(' ');\n}\n\nconst is = new Scanner();\n\nlet line = is.nextArray().map(Number);\nlet n = line[0];\nlet m = line[1];\nlet k = line[2];\n\nlet grid = new Array(n);\nfor (let i = 0; i < n; i++)\n grid[i] = is.nextLine();\n\n// rows\nlet answer = 0, aux, calc;\nfor (const row of grid) {\n aux = 0;\n for (const i of row)\n if (i === '.')\n aux++;\n else {\n aux = 0;\n answer += Math.max(0, aux - k + 1);\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nfor (let j = 0; j < m; j++) {\n aux = 0;\n for (let i = 0; i < n; i++)\n if (grid[i][j] === '.')\n aux++;\n else {\n aux = 0;\n answer += Math.max(0, aux - k + 1);\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nprint(answer)\n"}, {"source_code": "'use strict';\n\nfunction Scanner() {\n this.nextLine = () => readline();\n this.nextInt = () => parseInt(readline());\n this.nextDouble = () => parseInt(readline());\n this.nextArray = () => readline().split(' ');\n}\n\nconst is = new Scanner();\n\nlet line = is.nextArray().map(Number);\nconst n = line[0];\nconst m = line[1];\nconst k = line[2];\n\nconst grid = new Array(n);\nfor (let i = 0; i < n; i++)\n grid[i] = is.nextLine();\n\n// rows\nlet answer = 0, aux;\nfor (const row of grid) {\n aux = 0;\n for (const i of row)\n if (i === '.')\n aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n}\n\nif (k !== 1) {\n for (let j = 0; j < m; j++) {\n aux = 0;\n for (let i = 0; i < n; i++) {\n if (grid[i][j] === '.') aux++;\n else {\n answer += Math.max(0, aux - k + 1);\n aux = 0;\n }\n answer += Math.max(0, aux - k + 1);\n }\n }\n}\n\nprint(answer)\n"}], "src_uid": "c1f247150831e9b52389bae697a1ca3d"} {"source_code": "var a = readline();\nvar b = readline();\nvar c = readline();\n\nfunction charCount(s) {\n var cnt = {};\n for (var i = 0; i < s.length; ++i) {\n if (s[i] in cnt) {\n cnt[s[i]] += 1;\n } else {\n cnt[s[i]] = 1;\n }\n }\n return cnt;\n}\n\nfunction divide(a, b) {\n var ret = 1e100;\n for (k in b) {\n if (k in a) {\n ret = Math.min(ret, Math.floor(a[k] / b[k]));\n } else {\n return 0;\n }\n }\n return ret;\n}\n\nfunction subtract(a, b, n) {\n var c = {};\n for (k in a) {\n c[k] = a[k];\n }\n for (k in b) {\n c[k] -= b[k] * n;\n }\n return c;\n}\nvar ca = charCount(a);\nvar cb = charCount(b);\nvar cc = charCount(c);\nvar nb = divide(ca, cb);\nvar fb = 0, fc = 0;\nfor (var i = 0; i <= nb; ++i) {\n var j = divide(subtract(ca, cb, i), cc);\n if (i + j > fb + fc) {\n fb = i;\n fc = j;\n }\n}\nnb = fb;\nnc = fc;\nans = '';\nfor (var i = 0; i < nb; ++i) {\n ans += b;\n}\nca = subtract(ca, cb, nb);\nnc = divide(ca, cc);\nfor (var i = 0; i < nc; ++i) {\n ans += c;\n}\nca = subtract(ca, cc, nc);\nfor (k in ca) {\n for (var i = 0; i < ca[k]; ++i) {\n ans += k;\n }\n}\nprint(ans);", "positive_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr , u , x , y ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n\n r1 = [] ;\n \tyrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( 0 ) ;\n }\n x = 0 ;\n y = 0 ;\n \tfor( u = 0 ; u <= b ; u++ ) {\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] - u * this.brr[ i ] ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < lim ; i++ ) {\n xrr[ i ] -= c * this.crr[ i ] ;\n }\n if( u + c > x + y ) {\n \tx = u ;\n \ty = c ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr[ i ] = xrr[ i ] ;\n }\n }\n \t}\n \tfor( i = 0 ; i < x ; i++ ) {\n \t\tr1.push( this.b ) ;\n \t}\n \tfor( i = 0 ; i < y ; i++ ) {\n \t\tr1.push( this.c ) ;\n \t}\n \tif( x > 0 || y > 0 ) {\n \t\tfor( i = 0 ; i < lim ; i++ ) {\n\t this.arr[ i ] = yrr[ i ] ;\n\t }\n \t}\n \t\n res += r1.join( '' ) ; \n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}], "negative_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n\n if( b == inf && c == inf ) {\n res = this.a ;\n }\n else if( b == inf ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else if( c == inf ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n }\n\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n }\n\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr , u ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = b ;\n cc = c ;\n\n r1 = [] ;\n if( bb == 0 && cc == 0 ) {\n }\n else if( bb == 0 ) {\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( cc == 0 ) {\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n \tfor( u = 0 ; u <= bb ; u++ ) {\n \t\tr2 = [] ;\n\t xrr = [] ;\n\t for( i = 0 ; i < lim ; i++ ) {\n\t xrr.push( this.arr[ i ] ) ;\n\t }\n\t for( i = 0 ; i < u ; i++ ) {\n\t for( j = 0 ; j < l2 ; j++ ) {\n\t a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n\t xrr[ a ]-- ;\n\t }\n\t r2.push( this.b ) ;\n\t }\n\t c = inf ;\n\t for( i = 0 ; i < lim ; i++ ) {\n\t if( this.crr[ i ] > 0 ) {\n\t c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n\t }\n\t }\n\t for( i = 0 ; i < c ; i++ ) {\n\t for( j = 0 ; j < l3 ; j++ ) {\n\t a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n\t xrr[ a ]-- ;\n\t }\n\t r2.push( this.c ) ;\n\t }\n\t if( r2.length > r1.length ) {\n\t \tr1 = r2 ;\n\t for( i = 0 ; i < lim ; i++ ) {\n\t this.arr[ i ] = xrr[ i ] ;\n\t }\n\t }\n \t}\n \t/*\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n */\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n //res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = c ;\n cc = c ;\n\n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = b ;\n cc = c ;\n\n r1 = [] ;\n if( bb == 0 && cc == 0 ) {\n }\n else if( bb == 0 ) {\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( cc == 0 ) {\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n //res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr ;\n res = '' ;\n \n lim = 100 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = b ;\n cc = c ;\n\n r1 = [] ;\n if( bb == 0 && cc == 0 ) {\n }\n else if( bb == 0 ) {\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( cc == 0 ) {\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n //res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = b ;\n cc = c ;\n\n r1 = [] ;\n if( bb == 0 && cc == 0 ) {\n }\n else if( bb == 0 ) {\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( cc == 0 ) {\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n if( r1.length > 0 ) {\n res += r1.join( '' ) ;\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , bb , cc , xrr , yrr ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n bb = c ;\n cc = c ;\n\n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < bb ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < cc ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n\n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n //res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n if( r2.length > r3.length ) {\n r1 = r2 ;\n }\n else {\n r1 = r3 ;\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.isSubString = function( firstString , secondString ) {\n var l1 , l2 , i , j , res ;\n l1 = firstString.length ;\n l2 = secondString.length ;\n if( l2 > l1 ) {\n return false ;\n }\n res = true ;\n j = 0 ;\n for( i = 0 ; i < l1 ; i++ ) {\n if( firstString.charAt( i ) == secondString.charAt( j ) ) {\n j++ ;\n }\n else {\n j = 0 ;\n }\n }\n return res ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf , r1 , r2 , r3 , xrr , yrr ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n \n r1 = [] ;\n if( b == 0 && c == 0 ) {\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.c ) ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n r1.push( this.b ) ;\n }\n }\n else {\n r2 = [] ;\n xrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n xrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.b ) ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( xrr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n xrr[ a ]-- ;\n }\n r2.push( this.c ) ;\n }\n \n r3 = [] ;\n yrr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n yrr.push( this.arr[ i ] ) ;\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.c ) ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( yrr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n yrr[ a ]-- ;\n }\n r3.push( this.b ) ;\n }\n \n if( r2.length > r3.length ) {\n r1 = r2 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = xrr[ i ] ;\n }\n }\n else {\n r1 = r3 ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr[ i ] = yrr[ i ] ;\n }\n }\n }\n\n cn = 0 ;\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n if( cn < r1.length ) {\n res += r1[ cn++ ] ;\n }\n }\n }\n if( cn < r1.length ) {\n for( i = cn ; i < r1.length ; i++ ) {\n res += r1[ i ] ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , l1 , l2 , l3 , lim , a , b , c , d , inf ;\n res = '' ;\n \n lim = 30 ;\n inf = 1000000000 ;\n \n l1 = this.a.length ;\n l2 = this.b.length ;\n l3 = this.c.length ;\n \n this.arr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.arr.push( 0 ) ;\n }\n this.brr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.brr.push( 0 ) ;\n }\n this.crr = [] ;\n for( i = 0 ; i < lim ; i++ ) {\n this.crr.push( 0 ) ;\n }\n \n for( i = 0 ; i < l1 ; i++ ) {\n a = this.a.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]++ ;\n }\n for( i = 0 ; i < l2 ; i++ ) {\n a = this.b.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.brr[ a ]++ ;\n }\n for( i = 0 ; i < l3 ; i++ ) {\n a = this.c.charCodeAt( i ) - 'a'.charCodeAt( 0 ) ;\n this.crr[ a ]++ ;\n }\n \n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n } \n }\n\n if( b == 0 && c == 0 ) {\n res = this.a ;\n }\n else if( b == 0 ) {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else if( c == 0 ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n else {\n if( b > c ) {\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n c = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.crr[ i ] > 0 ) {\n c = Math.min( c , Math.floor( this.arr[ i ] / this.crr[ i ] ) ) ;\n }\n }\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n }\n else {\n for( i = 0 ; i < c ; i++ ) {\n for( j = 0 ; j < l3 ; j++ ) {\n a = this.c.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.c ;\n }\n b = inf ;\n for( i = 0 ; i < lim ; i++ ) {\n if( this.brr[ i ] > 0 ) {\n b = Math.min( b , Math.floor( this.arr[ i ] / this.brr[ i ] ) ) ;\n } \n }\n for( i = 0 ; i < b ; i++ ) {\n for( j = 0 ; j < l2 ; j++ ) {\n a = this.b.charCodeAt( j ) - 'a'.charCodeAt( 0 ) ;\n this.arr[ a ]-- ;\n }\n res += this.b ;\n }\n }\n }\n\n for( i = 0 ; i < lim ; i++ ) {\n for( j = 0 ; j < this.arr[ i ] ; j++ ) {\n res += String.fromCharCode( 'a'.charCodeAt( 0 ) + i ) ;\n }\n }\n print( res );\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.a = irObj.nextString();\n\t this.b = irObj.nextString();\n\t this.c = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();"}], "src_uid": "9dc956306e2826229e393657f2d0d9bd"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 2e14;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet c = rna();\r\n\t\tc.unshift(0);\r\n\r\n\t\tlet ans = INF, mno = c[1], mne = c[2], sm = c[1];\r\n\t\tfor (let l = 2; l <= n; l++) {\r\n\t\t\tconst k = Math.floor((l - 1)/2);\r\n\r\n\t\t\tconst mn = l%2 ? mne : mno;\r\n\t\t\tconst pthl = l%2 ? n-k+1 : n-k; \r\n\r\n\t\t\tconst cost = pthl*mn + sm-mn + (n-k)*c[l];\r\n\r\n\t\t\tif (l%2 == 0)\r\n\t\t\t\tmne = Math.min(mne, c[l]);\r\n\t\t\telse \r\n\t\t\t\tmno = Math.min(mno, c[l]);\r\n\r\n\t\t\tsm += c[l];\r\n\r\n\t\t\tans = Math.min(ans, cost);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e20 + 1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet c = rna();\r\n\t\tc.unshift(0);\r\n\r\n\t\tlet ans = INF, mno = c[1], mne = c[2], sm = c[1];\r\n\t\tfor (let l = 2; l <= n; l++) {\r\n\t\t\tconst k = Math.floor((l - 1)/2);\r\n\r\n\t\t\tconst mn = l%2 ? mne : mno;\r\n\t\t\tconst pthl = l%2 ? n-k+1 : n-k; \r\n\r\n\t\t\tconst cost = pthl*mn + sm-mn + (n-k)*c[l];\r\n\t\t\t//console.log('cost', cost, 'sm', sm, 'k', k);\r\n\r\n\t\t\tif (l%2 == 0)\r\n\t\t\t\tmne = Math.min(mne, c[l]);\r\n\t\t\telse \r\n\t\t\t\tmno = Math.min(mno, c[l]);\r\n\r\n\t\t\tsm += c[l];\r\n\r\n\t\t\tans = Math.min(ans, cost);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var a = readline()\r\n var array = []\r\n var array2 = []\r\n\r\n var sum = new Array(n)\r\n sum[0] = a[0]\r\n for (let i = 1; i < n; i++) {\r\n sum[i] = sum[i - 1] + a[i]\r\n }\r\n\r\n var answer = Number.MAX_SAFE_INTEGER\r\n var minX = 10e8\r\n var minXI = 0\r\n var minY = 10e8\r\n var minYI = 0\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (i % 2 === 0) {\r\n if (a[i] < minX) {\r\n minX = a[i]\r\n minXI = i\r\n }\r\n }\r\n if (i % 2 === 1) {\r\n if (a[i] < minY) {\r\n minY = a[i]\r\n minYI = i\r\n }\r\n }\r\n var mult1 = i % 2 === 0 ? (n - Math.floor(i / 2)-1) : (n - Math.floor(i / 2)-1)\r\n var mult2 = i % 2 === 1 ? (n - Math.floor(i / 2)-1): (n - Math.floor(i / 2))\r\n // var mult2 =\r\n answer = Math.min(answer, sum[i] + minX * mult1 + minY * mult2)\r\n // console.log(answer, minX, mult1, minY, mult2)\r\n }\r\n console.log(answer)\r\n\r\n\r\n });\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e14 + 1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet c = rna();\r\n\t\tc.unshift(0);\r\n\r\n\t\tlet ans = INF, mno = c[1], mne = c[2], sm = c[1];\r\n\t\tfor (let l = 2; l <= n; l++) {\r\n\t\t\tconst k = Math.floor((l - 1)/2);\r\n\r\n\t\t\tconst mn = l%2 ? mne : mno;\r\n\t\t\tconst pthl = l%2 ? n-k+1 : n-k; \r\n\r\n\t\t\tconst cost = pthl*mn + sm-mn + (n-k)*c[l];\r\n\t\t\t//console.log('cost', cost, 'sm', sm, 'k', k);\r\n\r\n\t\t\tif (l%2 == 0)\r\n\t\t\t\tmne = Math.min(mne, c[l]);\r\n\t\t\telse \r\n\t\t\t\tmno = Math.min(mno, c[l]);\r\n\r\n\t\t\tsm += c[l];\r\n\r\n\t\t\tans = Math.min(ans, cost);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9+1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet c = rna();\r\n\t\tc.unshift(0);\r\n\r\n\t\tlet ans = INF, mno = c[1], mne = c[2], sm = c[1];\r\n\t\tfor (let l = 2; l <= n; l++) {\r\n\t\t\tconst k = Math.floor((l - 1)/2);\r\n\r\n\t\t\tconst mn = l%2 ? mne : mno;\r\n\t\t\tconst pthl = l%2 ? n-k+1 : n-k; \r\n\r\n\t\t\tconst cost = pthl*mn + sm-mn + (n-k)*c[l];\r\n\t\t\t//console.log('cost', cost, 'sm', sm, 'k', k);\r\n\r\n\t\t\tif (l%2 == 0)\r\n\t\t\t\tmne = Math.min(mne, c[l]);\r\n\t\t\telse \r\n\t\t\t\tmno = Math.min(mno, c[l]);\r\n\r\n\t\t\tsm += c[l];\r\n\r\n\t\t\tans = Math.min(ans, cost);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i input += data);\nprocess.stdin.on(\"end\", () => {\n console.log(input.split(\"\\n\").filter(x => x.trim() !== \"\").filter((_, i) => i !== 0).filter((_, i) => i % 2 === 1).map(x => x.split(\" \").map(Number)).map(x => x.reduce((acc, cur) => acc + cur) / x.length).map(Math.ceil).join(\"\\n\"));\n})", "positive_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar STATE = 1;\nvar n, a, sum;\nrl.on('line', function (input) {\n switch (STATE) {\n case 1:\n STATE = 2;\n break;\n case 2:\n n = parseInt(input, 10);\n sum = 0;\n // console.log(STATE + ':', a, a_t);\n STATE = 3;\n break;\n case 3:\n a = input.split(' ');\n for (var i = 0; i < n; i++) {\n sum += parseInt(a[i], 10)\n }\n console.log(Math.ceil(sum / n))\n STATE = 2;\n break;\n default:\n // code\n }\n}).on('close', function() {\n process.exit(0);\n});"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n for(let i = 0; i < q; i++) {\n const n = parseInt(arr.shift())\n const a = arr.shift().split(' ')\n\n let sum = 0\n for(let j = 0; j < n; j++) {\n sum += parseInt(a[j])\n }\n\n console.log(Math.ceil(sum / n))\n }\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar N = nextInt();\n \tvar list = nextIntArray();\n \tvar sum = 0;\n \tfor(var j = 0; j < N; j++){\n \t\tsum += list[j];\n \t}\n \toutput[i] = Math.ceil(sum / N);\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n \n\n function foo (data, n) {\n let result = data.reduce((a, b) => (a + b)) / data.length;\n result = Math.ceil(result);\n return result;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n //console.log(data);\n //console.log(n);\n let result = foo(data, n);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "'use strict'\n\nconst prices = (n, a) => {\n return Math.ceil(a.reduce((r, i) => r + i, 0) / n);\n}\n\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(prices(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (data) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n let arr = data.split(' ').map(Number);\n const sum = arr.reduce((a, b) => a + b, 0);\n console.log(Math.ceil(sum / arr.length));\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "var t=Number(readline());\nfor(var i=0;i input.push(line));\n\nRL.on('close', () => {\n const [q] = input[0].split(' ').map(x => parseInt(x));\n\n for (let i = 1; i < q*2; i += 2) {\n let n = parseInt(input[i]);\n const nums = input[i+1].split(' ').map(x => parseInt(x));\n const sum = nums.reduce((prev, next) => prev + next, 0);\n\n console.log(Math.ceil(sum/n));\n }\n\n\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const q = readline();\n for(let i = 0;i{return parseInt(value)}));\n }\n}\n\nfunction calcQuery(count, values){\n let sum = 0;\n values.forEach(element => {\n sum += element;\n });\n let minsugest = Math.floor(sum/count);\n while(minsugest*count < sum) {\n minsugest++;\n }\n console.log(minsugest);\n}"}, {"source_code": "var numOfQueries = readline();\nwhile (numOfQueries) {\n var length = readline();\n var nums = readline().split(\" \").map(x => parseInt(x));\n var sum = nums.reduce((a, b) => a + b, 0);\n print(Math.ceil(sum / length))\n numOfQueries--;\n}\n\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet q = parseInt(line.shift(),10);\n\tlet result = [];\n\tfor(let i = 0; i < q; i++){\n\t\tlet n = parseInt(line.shift(),10);\n\t\tlet sum = line.shift().split(' ').map(v => parseInt(v,10)).reduce((s, e) => s + e);\n\t\tresult.push(Math.ceil(sum/n));\n\t}\n\tconsole.log(result.join('\\n'));\n};\n\nprocess.stdin.on('end', solution);\n"}, {"source_code": "var q = parseInt(readline());\nvar ans = '';\nwhile(q--) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ');\n\tvar r = 0;\n\tfor (var i=0; i +x).reduce((acc, x) => acc + x)\n print(Math.ceil(s / n))\n}"}, {"source_code": "//var input = readline()\n\nvar t = parseInt(readline());\nfor(var i=0; i parseInt(x));\n \n var sum = ar.reduce((a, b) => a + b)\n print(Math.ceil(sum/n));\n}\n\n//"}], "negative_code": [{"source_code": "var t=Number(readline());\nfor(var i=0;i parseInt(x));\nconst sum = nums.reduce((a, b) => a + b, 0)\nprint(Math.ceil(sum / nums.length));\n"}, {"source_code": "var numOfQueries = readline();\nconst res = []\nwhile (numOfQueries) {\n var length = readline();\n var nums = readline().split(\" \").map(x => parseInt(x));\n var sum = nums.reduce((a, b) => a + b, 0);\n res.push(Math.ceil(sum / length))\n numOfQueries--;\n}\n\nres.forEach(print)\n"}, {"source_code": "var numOfQueries = readline();\n// while (numOfQueries) {\n// var length = readline();\n// var nums = readline().split(\" \").map(x => parseInt(x));\n// var sum = nums.reduce((a, b) => a + b, 0);\n// print(Math.ceil(sum / length)\n// numOfQueries--;\n// }\n\n"}, {"source_code": "var q = parseInt(readline());\nvar ans = '';\nwhile(q--) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ');\n\tvar r = 0;\n\tfor (var i=0; i {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n zeroArray(nums);\n});\n\nfunction zeroArray(nums) {\n // let sum = nums.reduce((a, b) => a + b, 0);\n let max = -1;\n let sum = 0;\n for (let i = 0; i < nums.length; i++) {\n max = Math.max(nums[i], max);\n sum += nums[i];\n }\n\n if (max <= sum - max && (sum % 2 === 0)) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}", "positive_code": [{"source_code": "var n = +readline();\nvar arr = readline().split(' ').map(item => +item);\n \nif(n === 2) {\n print(arr[0] === arr[1] ? 'YES' : 'NO');\n} else {\n arr.sort((a, b) => b - a);\n var max = arr[0];\n var sum = arr.reduce((c, p) => c + p);\n print((sum - max >= max && sum % 2 === 0) ? 'YES' : 'NO');\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nvar count = 0;\nrl.on('line', function (line) {\n if (count == 1) {\n var arr = line.trim().split(' ').map(Number);\n var sum = arr.reduce(function (a, b) { return a + b; });\n var max = Math.max.apply(Math, arr);\n console.log(!(sum % 2) && (max <= sum - max) ? \"YES\" : \"NO\");\n }\n count++;\n});\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN();\n if (n === 1 && A[0] === 1) {\n wr('YES');\n return;\n }\n \n A.sortGt();\n var max = A[0];\n //pr(max);\n var sum = A.reduce((a,v)=>a+v, 0);\n //pr(sum);\n var isEven = sum%2 === 0;\n var isMaxNotSoBig = max <= (sum - max);\n wr(isEven && isMaxNotSoBig ? 'YES' : 'NO');\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "var n = +readline();\nvar arr = readline().split(' ').map(item => +item);\n\nif(n === 2) {\n print(arr[0] === arr[1] ? 'YES' : 'NO');\n} else {\n var sum = 0, max = 0;\n for(var i = 0; i < n; i++) {\n sum += arr[i];\n max = max < arr[0] ? arr[0] : max;\n }\n print(sum - max >= max && sum % 2 === 0 ? 'YES' : 'NO');\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nvar count = 0;\nrl.on('line', function (line) {\n if (count == 1) {\n var arr = line.trim().split(' ').map(Number);\n var odd = arr.filter(function (a) { return (a % 2); }).length;\n console.log(odd % 2 ? \"NO\" : \"YES\");\n }\n count++;\n});\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nvar count = 0;\nrl.on('line', function (line) {\n if (count == 1) {\n var sum = line.trim().split(' ').map(Number).reduce(function (a, b) { return a + b; });\n console.log(sum % 2 ? \"NO\" : \"YES\");\n }\n count++;\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n zeroArray(nums);\n});\n\nfunction zeroArray(nums) {\n // let sum = nums.reduce((a, b) => a + b, 0);\n let max = -1;\n let sum = 0;\n for (let i = 0; i < nums.length; i++) {\n max = Math.max(nums[i], max);\n sum += nums[i];\n }\n\n if (max <= sum * 2 && (sum % 2 === 0)) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let nums = lines[1].split(' ');\n nums = nums.map(num => parseInt(num, 10));\n zeroArray(nums);\n});\n\nfunction zeroArray(nums) {\n // let sum = nums.reduce((a, b) => a + b, 0);\n let max = -1;\n let sum = 0;\n for (let i = 0; i < nums.length; i++) {\n max = Math.max(nums[i], max);\n sum += nums[i];\n }\n\n if (max <= sum && sum % 2 === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}"}], "src_uid": "52f4f2a48063c9d0e412a5f78c873e6f"} {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nk = parseInt(ip[1]);\ns = 0;\nstr = \"\";\n\nif (n < k || (k == 1 && n > 1)){\n\twrite(-1);\n} else {\n\tif (k < n){\n\t\tfor (var i = 0; i < n-k+2; i++){\n\t\t\tstr += String.fromCharCode(97 + i%2);\n\t\t}\n\t\tfor (var i = 2; i < k; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t}\n\twrite(str);\n}\n", "positive_code": [{"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n) return -1;\n\tif (k === 1 && n !== 1) return -1;\n\tif (k === 1 && n === 1) return 'a';\n\n\tvar str = 'a';\n\n\tvar l = n - k + 2;\n\n\tif (l > 1) {\n\t\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'b' ? 'a' : 'b';\n\t\tfor (var i = 0; i < k-2 && str.length < n; i++) str += String.fromCharCode(a + 2 + i);\n\t}\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar length = integers[0], variety = integers[1];\n\n\tif ((variety == 1 && length > 1) || (variety > length)) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar tailLength = Math.max(0, variety-2);\n\tvar headLength = Math.max(length-tailLength);\n\tvar tailStartCharCode = 'c'.charCodeAt(0);\n\tvar characters = [];\n\tfor (var i = 0; i < headLength; i += 1) {\n\t\tcharacters.push(i%2 == 0 ? 'a' : 'b');\n\t}\n\tfor (var i = 0; i < tailLength; i += 1) {\n\t\tcharacters.push(String.fromCharCode(tailStartCharCode+i));\n\t}\n\n\tprint(characters.join(''));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nk = parseInt(ip[1]);\ns = 0;\nstr = \"\";\n\nif (n < k){\n\twrite(-1);\n} else {\n\tif (k < n){\n\t\tfor (var i = 0; i < n-k+2; i++){\n\t\t\tstr += String.fromCharCode(97 + i%2);\n\t\t}\n\t\tfor (var i = 2; i < k; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t}\n\twrite(str);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = ip[0];\nk = ip[1];\ns = 0;\nstr = \"\";\n\nif (n < k){\n\twrite(-1);\n} else {\n\tif (k < n){\n\t\tfor (var i = 0; i < n-k+2; i++){\n\t\t\tstr += String.fromCharCode(97 + i%2);\n\t\t}\n\t\tfor (var i = 2; i < k-2; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t}\n\twrite(str);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nk = parseInt(ip[1]);\ns = 0;\nstr = \"\";\n\nif (n < k || k == 1){\n\twrite(-1);\n} else {\n\tif (k < n){\n\t\tfor (var i = 0; i < n-k+2; i++){\n\t\t\tstr += String.fromCharCode(97 + i%2);\n\t\t}\n\t\tfor (var i = 2; i < k; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t}\n\twrite(str);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = ip[0];\nk = ip[1];\ns = 0;\nstr = \"\";\n\nif (n < k){\n\twrite(-1);\n} else {\n\tif (k < n){\n\t\tfor (var i = 0; i < n-k+2; i++){\n\t\t\tstr += String.fromCharCode(97 + i%2);\n\t\t}\n\t\tfor (var i = 2; i < k; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++){\n\t\t\tstr += String.fromCharCode(97 + i);\n\t\t}\n\t}\n\twrite(str);\n}\n"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n) return -1;\n\n\tvar str = 'a';\n\tvar l = n - k + 2;\n\n\tif (l > 1) {\n\t\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'b' ? 'a' : 'b';\n\t\tfor (var i = 0; i < k-2; i++) str += String.fromCharCode(a + 2 + i);\n\t}\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar length = integers[0], variety = integers[1];\n\n\tif ((variety == 1 && length > 1) || (variety > length)) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar tailLength = Math.max(0, variety-2);\n\tvar tailStartCharCode = 'c'.charCodeAt(0);\n\tvar characters = [];\n\tfor (var i = length; i > tailLength; i -= 1) {\n\t\tcharacters.push(i%2 == 0 ? 'b' : 'a');\n\t}\n\tfor (var i = 0; i < tailLength; i += 1) {\n\t\tcharacters.push(String.fromCharCode(tailStartCharCode+i));\n\t}\n\n\tprint(characters.join(''));\n}\n\nmain();\n"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n) return -1;\n\tif (k === 1 && n !== 1) return -1;\n\n\tvar str = 'a';\n\tvar l = n - k + 2;\n\n\tif (l > 1) {\n\t\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'b' ? 'a' : 'b';\n\t\tfor (var i = 0; i < k-2; i++) str += String.fromCharCode(a + 2 + i);\n\t}\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));\n"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n) return -1;\n\tif (k === 1 && n !== 1) return -1;\n\tif (k === 1 && n === 1) return str;\n\n\tvar str = 'a';\n\n\tvar l = n - k + 2;\n\n\tif (l > 1) {\n\t\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'b' ? 'a' : 'b';\n\t\tfor (var i = 0; i < k-2 && str.length < n; i++) str += String.fromCharCode(a + 2 + i);\n\t}\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n || k == 1) return -1;\n\n\tvar str = '';\n\twhile (str.length < n - k + 2) str += str.slice(-1) === 'a' ? 'b' : 'a';\n\tfor (var i = 0; i < k-2; i++) str += String.fromCharCode(a + (k - 3) + i);\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n) return -1;\n\tif (k === 1 && n !== 1) return -1;\n\n\tvar str = 'a';\n\tvar l = n - k + 2;\n\n\tif (l > 1) {\n\t\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'b' ? 'a' : 'b';\n\t\tfor (var i = 0; i < k-2 && str.length < n; i++) str += String.fromCharCode(a + 2 + i);\n\t}\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n || k == 1) return -1;\n\n\tvar str = '';\n\twhile (str.length < n - k + 2) str += str.slice(-1) === 'a' ? 'b' : 'a';\n\tfor (var i = 0; i < k-2; i++) str += String.fromCharCode(a + (k - 2) + i);\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}, {"source_code": "var a = \"a\".charCodeAt(0),\n\tz = \"z\".charCodeAt(0);\n\nprint((function (n, k) {\n\tif (k > n || k == 1) return -1;\n\n\tvar str = '';\n\twhile (str.length < n - k + 2) str += str.slice(-1)[0] === 'a' ? 'b' : 'a';\n\tfor (var i = 0; i < k-2; i++) str += String.fromCharCode(a + 2 + i);\n\n\treturn str;\n}).apply(null, readline().split(' ').map(Number)));"}], "src_uid": "2f659be28674a81f58f5c587b6a0f465"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar noteNum = parseInt(readline());\n\n\tvar maxVolume = tokenizeIntegers(readline());\n\tvar totalVolume = tokenizeIntegers(readline());\n\n\tvar score = 0;\n\tfor (var i = 0; i < noteNum; ++i) {\n\t\tif (2*maxVolume[i] < totalVolume[i]) {\n\t\t\tscore -= 1;\n\t\t}\n\t\telse {\n\t\t\tvar a = Math.floor(totalVolume[i]/2), b = totalVolume[i] - a;\n\t\t\tscore += (a*b == 0 ? -1 : a*b);\n\t\t}\n\t}\n\tprint(score);\n}\n\nmain();\n", "positive_code": [{"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, lp = 0, a, b;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n n = parseInt(input);\n } else if (lp === 1){\n lp = 2;\n a = input.split(' ').map((x) => {\n return parseInt(x);\n });\n } else if (lp === 2){\n b = input.split(' ').map((x) => {\n return parseInt(x);\n });\n let ck, an = 0;\n for (let i = 0; i < n; i++){\n ck = b[i] - a[i];\n let x;\n if (ck > a[i] || b[i] === 1){\n x = -1;\n } else if (b[i] % 2 === 0){\n x = (b[i] / 2) * (b[i] / 2);\n } else {\n x = Math.floor(b[i] / 2) * Math.ceil(b[i] / 2);\n }\n an += x;\n }\n console.log(an);\n rl.close();\n }\n \n});"}, {"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, lp = 0, a, b;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n n = parseInt(input);\n } else if (lp === 1){\n lp = 2;\n a = input.split(' ').map((x) => {\n return parseInt(x);\n });\n } else if (lp === 2){\n b = input.split(' ').map((x) => {\n return parseInt(x);\n });\n let ck, an = 0;\n for (let i = 0; i < n; i++){\n ck = b[i] - a[i];\n let x;\n if (ck > a[i] || b[i] === 1){\n x = -1;\n } else if (b[i] % 2 === 0){\n x = (b[i] / 2) * (b[i] / 2);\n } else {\n x = Math.floor(b[i] / 2) * Math.ceil(b[i] / 2);\n }\n an += x;\n }\n console.log(an);\n rl.close();\n }\n \n});"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar noteNum = parseInt(readline());\n\n\tvar maxVolume = tokenizeIntegers(readline());\n\tvar totalVolume = tokenizeIntegers(readline());\n\n\tvar score = 0;\n\tfor (var i = 0; i < noteNum; ++i) {\n\t\tif (2*maxVolume[i] < totalVolume[i]) {\n\t\t\tscore -= 1;\n\t\t}\n\t\telse {\n\t\t\tvar a = Math.floor(totalVolume[i]/2), b = totalVolume[i] - a;\n\t\t\tscore += a*b;\n\t\t}\n\t}\n\tprint(score);\n}\n\nmain();\n"}, {"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, lp = 0, a, b;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n n = parseInt(input);\n } else if (lp === 1){\n lp = 2;\n a = input.split(' ').map((x) => {\n return parseInt(x);\n });\n } else if (lp === 2){\n b = input.split(' ').map((x) => {\n return parseInt(x);\n });\n let ck, an = 0;\n for (let i = 0; i < n; i++){\n ck = b[i] - a[i];\n if (ck < 0){\n console.log(-1);\n process.exit(0);\n } else if (ck > a[i]){\n console.log(-1);\n process.exit(0);\n }\n let x;\n if (b[i] % 2 === 0){\n x = (b[i] / 2) * (b[i] / 2);\n } else {\n x = Math.floor(b[i] / 2) * Math.ceil(b[i] / 2);\n }\n an += x;\n }\n console.log(an);\n rl.close();\n }\n \n});"}, {"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, lp = 0, a, b;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n n = parseInt(input);\n } else if (lp === 1){\n lp = 2;\n a = input.split(' ').map((x) => {\n return parseInt(x);\n });\n } else if (lp === 2){\n b = input.split(' ').map((x) => {\n return parseInt(x);\n });\n let ck, an = 0;\n for (let i = 0; i < n; i++){\n ck = b[i] - a[i];\n let x;\n if (ck <= 0 || ck > a[i]){\n x = -1;\n } else if (b[i] % 2 === 0){\n x = (b[i] / 2) * (b[i] / 2);\n } else {\n x = Math.floor(b[i] / 2) * Math.ceil(b[i] / 2);\n }\n an += x;\n }\n console.log(an);\n rl.close();\n }\n \n});"}, {"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, lp = 0, a, b;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n n = parseInt(input);\n } else if (lp === 1){\n lp = 2;\n a = input.split(' ').map((x) => {\n return parseInt(x);\n });\n } else if (lp === 2){\n b = input.split(' ').map((x) => {\n return parseInt(x);\n });\n let ck, an = 0;\n for (let i = 0; i < n; i++){\n ck = b[i] - a[i];\n let x;\n if (ck < 0 || ck > a[i] || a[i] === 1 && b[i] === 1){\n x = -1;\n } else if (b[i] % 2 === 0){\n x = (b[i] / 2) * (b[i] / 2);\n } else {\n x = Math.floor(b[i] / 2) * Math.ceil(b[i] / 2);\n }\n an += x;\n }\n console.log(an);\n rl.close();\n }\n \n});"}], "src_uid": "986a7d97e62856d5301d5a70ea01466a"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst char = i => String.fromCharCode('a'.charCodeAt(0) + i);\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\r\n\tlet ans = '';\r\n\tlet cur = 0;\r\n\twhile (cur < k) {\r\n\t\tfor (let i = cur; i < k; i++) {\r\n\t\t\tans = ans + char(i) + char(cur);\r\n\t\t}\r\n\t\tans = ans.slice(0, ans.length - 1);\r\n\t\tcur++;\r\n\t}\r\n\r\n\tans = ans.repeat(Math.ceil(n/k)).slice(0, n);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\r\n\r\n var res = []\r\n while (res.length < n) {\r\n var letter = 0\r\n\r\n for (let i = 0; i < k; i++) {\r\n res.push(alphabet[letter])\r\n for (let j = i + 1; j < k; j++) {\r\n res.push(alphabet[letter])\r\n res.push(alphabet[j])\r\n }\r\n letter++\r\n }\r\n }\r\n var ans= []\r\n for (let i = 0; i < n; i++) {\r\n ans.push(res[i])\r\n }\r\n console.log(ans.join(''))\r\n // console.log(ans.length)\r\n // })\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var [n, k] = input[0].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var visited = [];\r\n for (var i = 0; i < k; i++) {\r\n visited[i] = [];\r\n for (var j = 0; j < k; j++) {\r\n visited[i][j] = false;\r\n }\r\n }\r\n var str = \"\";\r\n var stack = [];\r\n function findPath(i) {\r\n var j;\r\n for (j = 0; j < visited[i].length; j++) {\r\n if (!visited[i][j]) {\r\n visited[i][j] = true;\r\n findPath(j);\r\n }\r\n }\r\n if (j === visited[i].length) {\r\n stack.push(String.fromCharCode(\"a\".charCodeAt(0) + i));\r\n }\r\n }\r\n findPath(0);\r\n while (stack.length !== 0) {\r\n str += stack.pop();\r\n }\r\n str = str.slice(0, str.length - 1);\r\n var result = \"\";\r\n for (var i = 0; i < n; i++) {\r\n result += str[i % str.length];\r\n }\r\n console.log(result);\r\n})"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var [n, k] = input[0].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var str = \"\";\r\n for (var i = 0; i < k; i++) {\r\n str += String.fromCharCode(\"a\".charCodeAt(0) + i);\r\n for (var j = i + 1; j < k; j++) {\r\n str += String.fromCharCode(\"a\".charCodeAt(0) + i);\r\n str += String.fromCharCode(\"a\".charCodeAt(0) + j);\r\n }\r\n }\r\n var result = \"\";\r\n for (var i = 0; i < n; i++) {\r\n result += str[i % str.length];\r\n }\r\n console.log(result);\r\n})"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n let res = '';\r\n for (let i = 0; i < m; i++) {\r\n const char = String.fromCharCode(i + 97);\r\n res += char;\r\n for (let j = i + 1; j < m; j++) {\r\n res += char + String.fromCharCode(j + 97);\r\n }\r\n }\r\n return res.repeat(Math.ceil(n / (m * m))).slice(0, n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst char = i => String.fromCharCode('a'.charCodeAt(0) + i);\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\r\n\tlet ans = '';\r\n\tfor (let cur = 0; cur < k; cur++) {\r\n\t\tfor (let i = cur; i < k; i++) {\r\n\t\t\tans += char(i) + char(cur);\r\n\t\t}\r\n\t\tans = ans.slice(0, -1);\r\n\t}\r\n\r\n\tans = ans.repeat(Math.ceil(n/k)).slice(0, n);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var [n, k] = input[0].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var visited = [];\r\n for (var i = 0; i < n; i++) {\r\n visited[i] = [];\r\n for (var j = 0; j < n; j++) {\r\n visited[i][j] = false;\r\n }\r\n }\r\n function findPath(str, i, visited) {\r\n str += i;\r\n for (var j = 0; j < visited[i].length; j++) {\r\n if (!visited[i][j]) {\r\n visited[i][j] = true;\r\n findPath(str, j, visited);\r\n break;\r\n }\r\n }\r\n }\r\n var str = \"\";\r\n findPath(str, 0, visited);\r\n var result = [];\r\n for (var i = 0; i < n; i++) {\r\n result[i] = str[i % str.length];\r\n }\r\n console.log(result);\r\n})"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var [n, k] = input[0].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var visited = [];\r\n for (var i = 0; i < n; i++) {\r\n visited[i] = [];\r\n for (var j = 0; j < n; j++) {\r\n visited[i][j] = false;\r\n }\r\n }\r\n function findPath(str, i, visited) {\r\n str += i;\r\n for (var j = 0; j < visited[i].length; j++) {\r\n if (!visited[i][j]) {\r\n visited[i][j] = true;\r\n findPath(str, j, visited);\r\n break;\r\n }\r\n }\r\n }\r\n var str = \"\";\r\n findPath(str, 0, visited);\r\n var result = [];\r\n for (var i = 0; i < n; i++) {\r\n result[i] = str[i % str.length];\r\n }\r\n return result;\r\n})"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n let res = '';\r\n for (let i = 0; i < m; i++) {\r\n const char = String.fromCharCode(i + 97);\r\n res += char;\r\n for (let j = i + 1; j < m; j++) {\r\n res += char + String.fromCharCode(j + 97);\r\n }\r\n }\r\n return res.slice(0, n);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n // const xx = readline();\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\r\n\r\n var res = 'a'\r\n var j = 1\r\n for (let i = 0; i < n-1; i++) {\r\n if (i % 2 === 0) res += 'a'\r\n else if (i % 2 === 1 && j < k) {\r\n res += alphabet[j]\r\n j++\r\n } else {\r\n res += 'a'\r\n }\r\n }\r\n console.log(res)\r\n // })\r\n}\r\n\r\n"}], "src_uid": "19cc504c81bd4f224ecb17f03cfb9bd7"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // console.time('Execution Time')\n let testCases = readline()\n while(testCases--)\n solve()\n // console.timeEnd('Execution Time');\n}\n\n// function to solve problems\nfunction solve (){\n let n = readline()\n let arr = readline().split(' ').map(x => +x)\n let fa = Math.max(...arr)\n let fb = arr.reduce((num, sum) => sum += num)\n fb -= fa\n fb = (fb/(arr.length - 1))\n console.log(fa + fb)\n}\n\nfunction sortAscending(a, b) {\n return a[0] - b[0]\n}\n// String.prototype.replaceAt = function (index, replacement) {\n// return this.substring(0, index) + replacement + this.substring(index + replacement.length)\n// }\n", "positive_code": [{"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i]; \n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = 0;\n for(j = 0; j < e - 1; j++){\n ans += k[j];\n }\n ans /= e - 1;\n ans += k[e - 1];\n console.log(ans.toPrecision(10));\n }\n }\n});"}, {"source_code": "// --------------- TEMPLATE START ---------------\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nconst nextLine = () => {\r\n const nextLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line.trim();\r\n }\r\n }());\r\n return (async () => {\r\n const next = await nextLineGen.next();\r\n return next.value;\r\n })();\r\n};\r\n\r\nconst nextNum = async () => {\r\n const line = await nextLine();\r\n return Number(line);\r\n};\r\n\r\nconst nextNumArr = async () => {\r\n const line = await nextLine();\r\n return line.split(\" \").map((num) => Number(num));\r\n};\r\n// --------------- TEMPLATE END ---------------\r\n\r\nconst ezzatAndTwoSubsequences = async () => {\r\n let t = await nextNum();\r\n \r\n while (t-- > 0) {\r\n let n = await nextNum();\r\n let arr = await nextNumArr();\r\n \r\n let top = Math.max(...arr);\r\n let sum = 0;\r\n for(let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n }\r\n\r\n console.log((sum - top) / (n-1) + top);\r\n }\r\n};\r\n\r\nezzatAndTwoSubsequences();"}, {"source_code": "// --------------- TEMPLATE START ---------------\nconst rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst nextLine = () => {\n const nextLineGen = (async function* () {\n for await (const line of rl) {\n yield line.trim();\n }\n }());\n return (async () => {\n const next = await nextLineGen.next();\n return next.value;\n })();\n};\n\nconst nextNum = async () => {\n const line = await nextLine();\n return Number(line);\n};\n\nconst nextNumArr = async () => {\n const line = await nextLine();\n return line.split(\" \").map((num) => Number(num));\n};\n// --------------- TEMPLATE END ---------------\n\nconst ezzatAndTwoSubsequences = async () => {\n let t = await nextNum();\n \n while (t-- > 0) {\n let n = await nextNum();\n let arr = await nextNumArr();\n \n arr.sort((a, b) => a - b);\n \n let sum = 0;\n for(let i = 0; i < n-1; i++) {\n sum += arr[i];\n }\n\n console.log(sum / (n-1) + arr[n-1]);\n }\n};\n\nezzatAndTwoSubsequences();\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet m = a.reduce((ac, e) => e > ac?e:ac, a[0]);\n\t\tlet s = a.reduce((ac, e) => ac + e, 0) - m;\n\t\tans.push(((s / (n - 1)) + m).toFixed(9));\n\t}\n\tconsole.log(ans.join('\\n'));\n\t\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tsum += list[i];\r\n\t\t}\r\n\t\tsum /= N - 1;\r\n\t\tmyout(sum + list[N - 1]);\r\n\t}\r\n}\r\n"}, {"source_code": "// function calculateAvg(array) {\n// let result = 0;\n// for (let i = 0; i < array.length; i++) {\n// result += array[i];\n// }\n// return result / (array.length);\n// }\n// function getMax(array) {\n// let max = array[0];\n// for (let i = 1; i < array.length; i++) {\n// if (max < array[i]) max = array[i];\n// }\n// return max;\n// }\n\nfunction max(list) {\n let res = list[0]\n for (let i = 0; i < list.length; i++) {\n if (res < list[i]) {\n res = list[i]\n }\n }\n\n return res\n}\n\nfunction min(list) {\n let res = list[0]\n for (let i = 0; i < list.length; i++) {\n if (res > list[i]) {\n res = list[i]\n }\n }\n return res\n}\n\nfunction solve(n, list) {\n let res = 0\n for (let i = 0; i < n; i++) {\n res += list[i];\n }\n const maxValue = max(list);\n res -= maxValue;\n return res / (n - 1) + maxValue;\n}\nfunction main(array) {\n const T = array[0];\n for (let i = 0; i < T; i++) {\n const n = array[i * 2 + 1];\n const list = array[(i + 1) * 2];\n const res = solve(n, list.split(' ').map((item) => parseInt(item, 10)));\n console.log(res);\n // console.log(res)\n }\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\n\n main(inputString);\n});\n"}, {"source_code": "let examplesStrings = [\r\n`4\r\n3\r\n3 1 2\r\n3\r\n-7 -6 -6\r\n3\r\n2 2 2\r\n4\r\n17 3 5 -3`,\r\n// `3\r\n// 1 2 3`,\r\n// `9\r\n// 1 2 1 3 2 2 2 2 3`\r\n];\r\n\r\nlet examples = [\r\n [\r\n [3,1,2],\r\n [-7, -6, -6],\r\n [2,2,2],\r\n [17,3,5,-3]\r\n ],\r\n // [1,2,3],\r\n // [1,2,1,3,2,2,2,2,3]\r\n];\r\n\r\nlet answers = [\r\n`4.5\r\n-12.5\r\n4\r\n18.666666667`\r\n// `2`,\r\n// `4`,\r\n// '10'\r\n];\r\n\r\n// \r\n\r\nconst parser = (string) => {\r\n const lines = string.match(/[^\\r\\n]+/g);\r\n\r\n // return lines[1].split(' ').map(x => parseInt(x, 10))\r\n\r\n const finalResult = [];\r\n for(let i = 2; i < lines.length; i+=2) {\r\n finalResult.push(lines[i].split(' ').map(x => parseInt(x, 10)))\r\n }\r\n return finalResult;\r\n}\r\n\r\n\r\n\r\nconst solver = (arr2d) => {\r\n return arr2d.map(arr => {\r\n arr.sort((a,b) => b-a);\r\n\r\n console.log(arr);\r\n return arr[0] + arr.slice(1).reduce((a,b) => a+b, 0) / (arr.length - 1)\r\n }).join(\"\\r\\n\")\r\n \r\n};\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst multiSolver = (_inputs) => {\r\n const isMulti = false;\r\n\r\n const inputs = isMulti ? _inputs : [_inputs];\r\n\r\n let results = [];\r\n for(let input of inputs) {\r\n results.push(solver(input));\r\n // logResult(solver(input))\r\n }\r\n console.log({results})\r\n const strResults = results.join(\"\\r\\n\");\r\n logResult(strResults);\r\n return strResults;\r\n\r\n \r\n}\r\n\r\n// FINISH HERE !!!\r\n// STOP\r\n// STOP\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst isDevMode = process.env.LOCAL === 'knotri';\r\nconst logResult = console.log;\r\n\r\n\r\n\r\nconst deepEq = (obj1, obj2) => JSON.stringify(obj1) === JSON.stringify(obj2)\r\nconst validate = ({examplesStrings, examples, answers, parser, multiSolver}) => {\r\n examplesStrings.forEach((string, index) => {\r\n const actualParse = parser(string);\r\n const desiredParse = examples[index];\r\n\r\n if (!deepEq(actualParse, desiredParse)) {\r\n console.error('PARSE WRONG!');\r\n console.log({actualParse, desiredParse})\r\n }\r\n\r\n const actualAnswer = multiSolver(actualParse);\r\n const desiredAnswer = answers[index];\r\n\r\n if (!deepEq(actualAnswer, desiredAnswer)) {\r\n console.error('SOLVE WRONG!');\r\n console.log({actualParse, actualAnswer, desiredAnswer})\r\n }\r\n\r\n });\r\n\r\n}\r\n\r\n\r\n\r\nif (!isDevMode) {\r\n console.log = () => {};\r\n const fs = require(\"fs\");\r\n const stdinBuffer = fs.readFileSync(0);\r\n const string = stdinBuffer.toString();\r\n\r\n multiSolver(parser(string));\r\n} else {\r\n validate({examplesStrings, examples, answers, parser, multiSolver})\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "const MOD = Math.pow(10, 9) + 7;\r\n\r\nfunction solve() {\r\n const [n] = readArray(Number);\r\n const bigN = BigInt(n);\r\n const arr = readArray((x) => BigInt(x) * 10000000n);\r\n arr.sort(sortF);\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n }\r\n\r\n let curSum = arr[0];\r\n let ans = curSum + (sum - curSum) / (bigN - 1n);\r\n for (let i = 1; i < n - 1; i++) {\r\n curSum += arr[i];\r\n const counter = BigInt(i + 1);\r\n const curAns = curSum / counter + (sum - curSum) / (bigN - counter);\r\n if (curAns > ans) {\r\n ans = curAns;\r\n }\r\n }\r\n \r\n let full = ans / 10000000n;\r\n if (full < 0n) {\r\n full = -full;\r\n }\r\n const sign = (ans < 0n) ? '-' : '';\r\n let ost = ans % 10000000n;\r\n if (ost < 0n) {\r\n ost = -ost;\r\n }\r\n ost = '' + ost;\r\n while(ost.length < 7) {\r\n ost = '0' + ost;\r\n }\r\n write(sign + full + '.' + ost); \r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1;\r\n while(curN) {\r\n if (curN & 1) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n let arr = [];\r\n content.forEach((string, i) => {\r\n if (i % 2 === 1) {\r\n arr.push(content[i]);\r\n }\r\n })\r\n arr = arr.map((string) => string.split(' '));\r\n arr = arr.map((newArr) => newArr.map(num => parseInt(num)));\r\n arr = arr.map((newArr) => newArr.sort((a, b) => b - a));\r\n const max = new Array(arr.length).fill(Number.MIN_SAFE_INTEGER);\r\n arr.forEach((nums, i) => {\r\n const cacheSum = [nums[0]];\r\n for (let j = 1; j < nums.length; j++) {\r\n cacheSum.push(cacheSum[cacheSum.length - 1] + nums[j]); \r\n }\r\n for (let j = 1; j < nums.length; j++) {\r\n max[i] = Math.max(mean(0, j, cacheSum) + mean(j, nums.length, cacheSum), max[i]);\r\n }\r\n console.log(max[i]);\r\n })\r\n})\r\n\r\nconst mean = (start, end, cacheSum) => {\r\n let sum = start !== 0 ? cacheSum[end - 1] - cacheSum[start - 1] : cacheSum[end - 1];\r\n return sum / (end - start);\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a)\r\n stin(a);\r\n let left = 0, right = sm(a), res = Number.MIN_SAFE_INTEGER;\r\n for (let i = 0; i < n - 1; i++) {\r\n left += a[i];\r\n right -= a[i];\r\n let nl = i + 1, nr = n - i - 1;\r\n // pr(left, nl, right, nr, left / nl + right / nr)\r\n res = mx(res, left / nl + right / nr)\r\n }\r\n pr(res.toFixed(9))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i]; \n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = 0;\n for(j = 0; j < e - 1; j++){\n ans += k[j];\n }\n ans /= e - 1;\n ans += k[e - 1];\n console.log(ans);\n }\n }\n});"}], "negative_code": [{"source_code": "const MOD = Math.pow(10, 9) + 7;\r\n\r\nfunction solve() {\r\n const [n] = readArray(Number);\r\n const bigN = BigInt(n);\r\n const arr = readArray((x) => BigInt(x) * 10000000n);\r\n arr.sort(sortF);\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n }\r\n\r\n let curSum = arr[0];\r\n let ans = curSum + (sum - curSum) / (bigN - 1n);\r\n for (let i = 1; i < n - 1; i++) {\r\n curSum += arr[i];\r\n const counter = BigInt(i + 1);\r\n const curAns = curSum / counter + (sum - curSum) / (bigN - counter);\r\n if (curAns > ans) {\r\n ans = curAns;\r\n }\r\n }\r\n \r\n const full = ans / 10000000n;\r\n if (full < 0n) {\r\n full = -full;\r\n }\r\n const sign = (ans < 0n) ? '0' : '';\r\n let ost = ans % 10000000n;\r\n if (ost < 0n) {\r\n ost = -ost;\r\n }\r\n ost = '' + ost;\r\n while(ost.length < 7) {\r\n ost = '0' + ost;\r\n }\r\n write(sign + full + '.' + ost); \r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1;\r\n while(curN) {\r\n if (curN & 1) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const MOD = Math.pow(10, 9) + 7;\r\n\r\nfunction solve() {\r\n const [n] = readArray(Number);\r\n const bigN = BigInt(n);\r\n const arr = readArray((x) => BigInt(x) * 10000000n);\r\n arr.sort(sortF);\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n }\r\n\r\n let curSum = arr[0];\r\n let ans = curSum + (sum - curSum) / (bigN - 1n);\r\n for (let i = 1; i < n - 1; i++) {\r\n curSum += arr[i];\r\n const counter = BigInt(i + 1);\r\n const curAns = curSum / counter + (sum - curSum) / (bigN - counter);\r\n if (curAns > ans) {\r\n ans = curAns;\r\n }\r\n }\r\n \r\n const full = ans / 10000000n;\r\n let ost = ans % 10000000n;\r\n if (ost < 0) {\r\n ost = -ost;\r\n }\r\n ost = '' + ost;\r\n while(ost.length < 7) {\r\n ost = '0' + ost;\r\n }\r\n write(full + '.' + ost); \r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1;\r\n while(curN) {\r\n if (curN & 1) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const MOD = Math.pow(10, 9) + 7;\r\n\r\nfunction solve() {\r\n const [n] = readArray(Number);\r\n const arr = readArray(BigInt);\r\n let maxi = arr[0];\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n if (arr[i] > maxi) {\r\n maxi = arr[i];\r\n }\r\n }\r\n const bigN = BigInt(n);\r\n sum -= maxi;\r\n const ans = sum * 100000000n / (bigN - 1n) + maxi * 100000000n;\r\n const full = ans / 100000000n;\r\n let ost = '' + (ans % 100000000n + (ans < 0n ? 100000000n : 0n));\r\n while(ost.length < 8) {\r\n ost = '0' + ost;\r\n }\r\n write(full + '.' + ost);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1;\r\n while(curN) {\r\n if (curN & 1) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const MOD = Math.pow(10, 9) + 7;\r\n\r\nfunction solve() {\r\n const [n] = readArray(Number);\r\n const arr = readArray(BigInt);\r\n let maxi = arr[0];\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n if (arr[i] > maxi) {\r\n maxi = arr[i];\r\n }\r\n }\r\n const bigN = BigInt(n);\r\n sum -= maxi;\r\n const ans = sum * 10000000n / (bigN - 1n) + maxi * 10000000n;\r\n const full = ans / 10000000n;\r\n let ost = '' + (ans % 10000000n + (ans < 0n ? 10000000n : 0n));\r\n while(ost.length < 7) {\r\n ost = '0' + ost;\r\n }\r\n write(full + '.' + ost);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1;\r\n while(curN) {\r\n if (curN & 1) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const stdin = process.openStdin();\r\nlet content = '';\r\n\r\nstdin.addListener('data', (data) => {\r\n content += data;\r\n})\r\n\r\nstdin.addListener('end', () => {\r\n content = content.split('\\n');\r\n content.shift();\r\n content = content.map((string) => string.substring(0, string.length - 1));\r\n content.pop();\r\n let arr = [];\r\n content.forEach((string, i) => {\r\n if (i % 2 === 1) {\r\n arr.push(content[i]);\r\n }\r\n })\r\n arr = arr.map((string) => string.split(' '));\r\n arr = arr.map((newArr) => newArr.map(num => parseInt(num)));\r\n arr = arr.map((newArr) => newArr.sort((a, b) => b - a));\r\n const max = new Array(arr.length).fill(Number.MIN_SAFE_INTEGER);\r\n arr.forEach((nums, i) => {\r\n for (let j = 1; j < nums.length; j++) {\r\n max[i] = Math.max(mean(nums.slice(0, j)) + mean(nums.slice(j)), max[i]);\r\n }\r\n })\r\n console.log(arr, max)\r\n})\r\n\r\nconst mean = (arr) => {\r\n if (arr.length === 0) return 0;\r\n let sum = 0;\r\n arr.forEach(num => {\r\n sum += num; \r\n })\r\n return sum / arr.length;\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a)\r\n let left = 0, right = sm(a), res = Number.MIN_SAFE_INTEGER;\r\n for (let i = 0; i < n - 1; i++) {\r\n left += a[i];\r\n right -= a[i];\r\n let nl = i + 1, nr = n - i - 1;\r\n // pr(left, nl, right, nr)\r\n res = mx(res, left / nl + right / nr)\r\n }\r\n pr(res.toFixed(9))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n // pr(n, a)\r\n let left = 0, sum = sm(a), res = Number.MIN_SAFE_INTEGER;\r\n for (let i = 0; i < n; i++) {\r\n left += a[i];\r\n sum -= a[i];\r\n // pr(left / (i + 1), sum / (n - i - 1))\r\n if (n - i - 1 > 0) res = mx(res, left / (i + 1) + sum / (n - i - 1))\r\n }\r\n pr(res)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "159b9c743d6d8792548645b9f7be2753"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, k] = rna();\r\n\r\n\t\tif (n % 2)\r\n\t\t\tk += Math.floor((k - 1)/Math.floor(n / 2));\r\n\r\n\t\tconst ans = (k - 1) % n + 1;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n\r\n var [n, k] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n if (n % 2 === 0) {\r\n if(k % n ===0) return console.log(n)\r\n return console.log(k % n)\r\n }\r\n var mid = Math.floor(n/2)\r\n var res = Math.floor((k-1) / mid)\r\n\r\n // console.log((k+res)%(n))\r\n // console.log(res, k, mid)\r\n if(k {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n\r\n var [n, k] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n if (n % 2 === 0) {\r\n if(k % n ===0) return console.log(n)\r\n return console.log(k % n)\r\n }\r\n var mid = Math.floor(n/2)\r\n var res = Math.floor((k-1) / mid)\r\n\r\n // console.log((k+res)%(n))\r\n // console.log(res, k, mid)\r\n if(k {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const [n,k] = readLine().split(' ').map(Number);\r\n \r\n b(n,k);\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n\r\n function a(n,a){\r\n a.sort((a,b) => a - b);\r\n let count = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(i === n - 1) break;\r\n if(a[i] !== a[i+1]){\r\n return n - i - 1;\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\nfunction b(n,k){\r\n const f = Math.floor(n / 2);\r\n k--;\r\n const ans = (k + (n % 2) * Math.floor(k/f))\r\n return console.log(ans % n + 1)\r\n\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n \r\n var [n, k] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n if (n % 2 === 0) {\r\n if(k % n ===0) return console.log(n)\r\n return console.log(k % n)\r\n }\r\n var mid = Math.floor(n/2)\r\n var res = Math.floor((k-1) / mid)\r\n \r\n // console.log((k+res)%(n))\r\n // console.log(res, k, mid)\r\n if(k {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const [n,k] = readLine().split(' ').map(Number);\r\n \r\n const res = b(n,k);\r\n \r\n console.log(res)\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n\r\n function a(n,a){\r\n a.sort((a,b) => a - b);\r\n let count = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(i === n - 1) break;\r\n if(a[i] !== a[i+1]){\r\n return n - i - 1;\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\nfunction b(n,k){\r\n let a = n;\r\n let b = 1;\r\n if(n % 2 === 0){\r\n // they don't meet each other\r\n if(n === k) return k;\r\n else if(n > k){\r\n return k;\r\n } else {\r\n return k % n;\r\n }\r\n } else {\r\n // they meet each other every 2 times in every cycle: ->\r\n // how many cycles?\r\n if(n === k){\r\n return b + 1;\r\n } else if(n > k){\r\n const middle = Math.ceil(n / 2);\r\n if(middle > k){\r\n return k;\r\n } else {\r\n return k + 1;\r\n }\r\n } else {\r\n const cycle = Math.floor(k / n);\r\n let rem = k % n - 1;\r\n // how many diff seq?\r\n const seq = Math.floor(n / 2);\r\n b = 1 + Math.min(seq,cycle) * 2;\r\n if(b === n) b = 1;\r\n for(let a = n; rem > 0; a--, rem--,b++){\r\n \r\n if(a === b) b++;\r\n // console.log(`${a}, ${rem}, ${b}`)\r\n }\r\n return b;\r\n }\r\n }\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n\r\n var [n, k] = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n if (n % 2 === 0) return console.log((k) % (n + 1))\r\n var mid = Math.floor(n/2)\r\n var res = Math.floor((k-1) / mid)\r\n\r\n // console.log((k+res)%(n))\r\n // console.log(res, k, mid)\r\n if(k stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 2e9;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n", "positive_code": [{"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_k = readLine().split(' ').map(p => +p);\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_k[0], n_k[1], arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, k, arr){\r\n if(k == 1) return 'YES';\r\n\r\n let min = Infinity;\r\n for(let i = k-1; i > 0; i--){ \r\n if(arr[i] - arr[i-1] > min) return 'NO';\r\n min = arr[i] - arr[i-1];\r\n }\r\n\r\n // if(arr[0] > min) return 'NO';\r\n if( (n-k+1) * min < arr[0]) return 'NO';\r\n\r\n return 'YES';\r\n\r\n}"}], "negative_code": [{"source_code": "var gcd = function(x, y){\n while(y){\n var t = y;\n y = x % y;\n x = t;\n }\nreturn x;\n};\nvar MC = function(a){\n return Math.ceil(a); \n};\nvar MF = function(a){\n return Math.floor(a); \n};\nvar Mi = function(a, b){\n return Math.min(a, b);\n};\nvar Ma = function(a, b){\n return Math.max(a, b);\n};\nvar check = function(a){\n for(c = 2; c <= Math.sqrt(a); c++){\n if(a % c === 0){\n return false;\n }\n } \n return true;\n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 1e9;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "var gcd = function(x, y){\n while(y){\n var t = y;\n y = x % y;\n x = t;\n }\nreturn x;\n};\nvar MC = function(a){\n return Math.ceil(a); \n};\nvar MF = function(a){\n return Math.floor(a); \n};\nvar Mi = function(a, b){\n return Math.min(a, b);\n};\nvar Ma = function(a, b){\n return Math.max(a, b);\n};\nvar check = function(a){\n for(c = 2; c <= Math.sqrt(a); c++){\n if(a % c === 0){\n return false;\n }\n } \n return true;\n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 1e5;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "var gcd = function(x, y){\n while(y){\n var t = y;\n y = x % y;\n x = t;\n }\nreturn x;\n};\nvar MC = function(a){\n return Math.ceil(a); \n};\nvar MF = function(a){\n return Math.floor(a); \n};\nvar Mi = function(a, b){\n return Math.min(a, b);\n};\nvar Ma = function(a, b){\n return Math.max(a, b);\n};\nvar check = function(a){\n for(c = 2; c <= Math.sqrt(a); c++){\n if(a % c === 0){\n return false;\n }\n } \n return true;\n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 1e3;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "var gcd = function(x, y){\n while(y){\n var t = y;\n y = x % y;\n x = t;\n }\nreturn x;\n};\nvar MC = function(a){\n return Math.ceil(a); \n};\nvar MF = function(a){\n return Math.floor(a); \n};\nvar Mi = function(a, b){\n return Math.min(a, b);\n};\nvar Ma = function(a, b){\n return Math.max(a, b);\n};\nvar check = function(a){\n for(c = 2; c <= Math.sqrt(a); c++){\n if(a % c === 0){\n return false;\n }\n } \n return true;\n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 100;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "var gcd = function(x, y){\n while(y){\n var t = y;\n y = x % y;\n x = t;\n }\nreturn x;\n};\nvar MC = function(a){\n return Math.ceil(a); \n};\nvar MF = function(a){\n return Math.floor(a); \n};\nvar Mi = function(a, b){\n return Math.min(a, b);\n};\nvar Ma = function(a, b){\n return Math.max(a, b);\n};\nvar check = function(a){\n for(c = 2; c <= Math.sqrt(a); c++){\n if(a % c === 0){\n return false;\n }\n } \n return true;\n};\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var s = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = s[0], k = s[1];\n }else{\n var ok = true;\n var a = 10;\n for(j = k - 1; j > 0; j--){\n if(s[j] - s[j - 1] > a){\n ok = false;\n }\n a = s[j] - s[j - 1];\n }\n if((n - k + 1) * a < s[0]){\n ok = false;\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});\n"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_k = readLine().split(' ').map(p => +p);\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_k[0], n_k[1], arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, k, arr){\r\n\r\n let min = Infinity;\r\n for(let i = k-1; i > 0; i--){ \r\n if(arr[i] - arr[i-1] > min) return 'NO';\r\n min = arr[i] - arr[i-1];\r\n }\r\n\r\n if(arr[0] > min) return 'NO';\r\n if( (n-k+1) * min < min) return 'NO';\r\n\r\n return 'YES';\r\n\r\n}\r\n"}], "src_uid": "9edbe28b5be43a9cc6c633db98bc5a36"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const str = readLine();\n console.log(solve(0, len - 1, \"a\"));\n\n function solve(start, end, char) {\n if (start === end) return +(str[start] !== char);\n\n let count1 = 0;\n for (let i = start; i <= Math.floor((start + end) / 2); i++) if (str[i] !== char) count1++;\n let _count1 = solve(Math.floor((start + end) / 2) + 1, end, String.fromCharCode(char.charCodeAt(0) + 1));\n\n let count2 = 0;\n for (let i = Math.floor((start + end) / 2) + 1; i <= end; i++) if (str[i] !== char) count2++;\n let _count2 = solve(start, Math.floor((start + end) / 2), String.fromCharCode(char.charCodeAt(0) + 1));\n\n return Math.min(count1 + _count1, count2 + _count2);\n }\n }\n}\n", "positive_code": [{"source_code": "var anum = 'a'.charCodeAt(0);\nvar mod = 'z'.charCodeAt(0) - anum + 1;\n\nfunction next(x) {\n return (x + 1) % mod;\n}\n\nfunction solve() {\n var n = Number(read());\n var s = read();\n var arr = [];\n var cArr = [];\n for (var i = 0; i < mod; i++) {\n cArr.push([]);\n }\n for (var i = 0; i < n; i++) {\n arr.push(s.charCodeAt(i) - anum);\n for (var j = 0; j < mod; j++) {\n var x = arr[i] === j ? 1 : 0;\n if (i === 0) {\n cArr[j].push(x);\n } else {\n cArr[j].push(cArr[j][i - 1] + x);\n }\n }\n }\n write(f(0, n - 1, mod - 1)[1]);\n\n function count(l, r, c) {\n var res = cArr[c][r];\n if (l > 0) {\n res -= cArr[c][l - 1];\n }\n return res;\n }\n\n\n function f(l, r, c) {\n if (l === r) {\n if (arr[l] === c) {\n return [0, 1];\n }\n if (arr[l] === next(c)) {\n return [1, 0];\n }\n return [1, 1];\n }\n var m = (r + l) >> 1;\n var ansl = f(l, m, next(c));\n var ansr = f(m + 1, r, next(c));\n var countC = r - l + 1 - count(l, r, c);\n return [countC, Math.min(ansl[0] + ansr[1], ansl[1] + ansr[0])];\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nString.prototype.count = function(c) { \n let result = 0;\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++;\n return result;\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1);\n}\n\nfunction calc(s, c) {\n // console.log(s, c)\n if(s.length === 1)\n return s[0] !== c ? 1 : 0;\n \n const m = s.length / 2;\n const nxt = nextChar(c)\n let cntl = calc(s.substr(m), nxt);\n cntl += s.length / 2 - s.substr(0, m).count(c);\n let cntr = calc(s.substr(0, m), nxt);\n cntr += s.length / 2 - s.substr(m).count(c);\n return Math.min(cntl, cntr);\n}\n\nfunction main() {\n let t = readLine();\n t = parseInt(t);\n\n while(t--) {\n let n = parseInt(readLine());\n let s = readLine();\n console.log(calc(s, 'a'));\n }\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet lines = []\nprocess.stdin.on('data', input => {\n lines = input.trim().split('\\n')\n})\nprocess.stdin.on('end', main)\n\n\nString.prototype.count=function(c) { \n var result = 0, i = 0;\n for(i;i {\n lines = input.trim().split('\\n')\n})\nprocess.stdin.on('end', main)\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1);\n}\n\nfunction calc(s, c) {\n // console.log(s, c)\n if(s.length === 1)\n return s[0] !== c ? 1 : 0;\n \n const m = s.length / 2;\n const nxt = nextChar(c)\n let cntl = calc(s.substr(m), nxt);\n cntl += m - s.substr(0, m).split(c).length;\n let cntr = calc(s.substr(0, m), nxt);\n cntr += m - s.substr(m).split(c).length;\n return Math.min(cntl, cntr);\n}\n\nfunction main() {\n let t = lines[0]\n\n for(let i = 2; i < lines.length; i += 2) {\n console.log(calc(lines[i], 'a'));\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet lines = []\nprocess.stdin.on('data', input => {\n lines = input.trim().split('\\n')\n})\nprocess.stdin.on('end', main)\n\n\nString.prototype.count=function(c) { \n var result = 0, i = 0;\n for(i;i {\n lines = input.trim().split('\\n')\n})\nprocess.stdin.on('end', main)\n\n\nString.prototype.count=function(c) { \n var result = 0, i = 0;\n for(i;i {\n lines = input.trim().split('\\n').map(s => s.trim());\n})\nprocess.stdin.on('end', main)\n\nString.prototype.count = function(c) { \n let result = 0;\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++;\n return result;\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1);\n}\n\nfunction calc(s, c) {\n // console.log(s, c)\n if(s.length === 1)\n return s[0] !== c ? 1 : 0;\n \n const m = s.length / 2;\n const nxt = nextChar(c)\n let cntl = calc(s.substr(m), nxt);\n cntl += s.length / 2 - s.substr(0, m).count(c);\n let cntr = calc(s.substr(0, m), nxt);\n cntr += s.length / 2 - s.substr(m).count(c);\n return Math.min(cntl, cntr);\n}\n\nfunction main() {\n for(let i = 2; i < lines.length; i += 2) {\n console.log(calc(lines[i].trim(), 'a'));\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet lines = []\n// process.stdin.on('data', input => {\n// lines = input.trim().split('\\n').map(s => s.trim());\n// })\n// process.stdin.on('end', main)\n\nString.prototype.count = function(c) { \n let result = 0;\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++;\n return result;\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1);\n}\n\nfunction calc(s, c) {\n // console.log(s, c)\n if(s.length === 1)\n return s[0] !== c ? 1 : 0;\n \n const m = s.length / 2;\n const nxt = nextChar(c)\n let cntl = calc(s.substr(m), nxt);\n cntl += s.length / 2 - s.substr(0, m).count(c);\n let cntr = calc(s.substr(0, m), nxt);\n cntr += s.length / 2 - s.substr(m).count(c);\n return Math.min(cntl, cntr);\n}\n\nfunction prepareLines() {\n let t = parseInt(readline())\n for(let i = 0; i < t; i++) {\n lines.push(readline());\n }\n}\n\nfunction main() {\n prepareLines();\n for(let i = 1; i < lines.length; i += 2) {\n console.log(calc(lines[i].trim(), 'a'));\n }\n}\n"}, {"source_code": "// 'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet lines = []\nprocess.stdin.on('data', input => {\n lines = input.trim().split('\\n').map(s => s.trim());\n})\nprocess.stdin.on('end', main)\n\nString.prototype.count = function(c) { \n let result = 0;\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++;\n return result;\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1);\n}\n\nfunction calc(s, c) {\n // console.log(s, c)\n if(s.length === 1)\n return s[0] !== c ? 1 : 0;\n \n const m = s.length / 2;\n const nxt = nextChar(c)\n let cntl = calc(s.substr(m), nxt);\n cntl += s.length / 2 - s.substr(0, m).count(c);\n let cntr = calc(s.substr(0, m), nxt);\n cntr += s.length / 2 - s.substr(m).count(c);\n return Math.min(cntl, cntr);\n}\n\nfunction main() {\n for(let i = 2; i < lines.length; i += 2) {\n console.log(calc(lines[i].trim(), 'a'));\n }\n}"}], "src_uid": "324b7957b46dfe4948074c781159b7e7"} {"source_code": "'use strict'\n\nlet lll\nlet N = +readline()\nconst alc = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']\nlet ch = 0\n\nwhile (lll = readline()) {\n if (+lll == lll) {\n if (lll < 18) ch++\n } else {\n if (~alc.indexOf(lll)) ch++\n }\n}\n\nprint(ch)", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar alcoholic = { \"ABSINTH\": true, \"BEER\": true, \"BRANDY\": true,\n\t\t\"CHAMPAGNE\": true, \"GIN\": true, \"RUM\": true, \"SAKE\": true,\n\t\t\"TEQUILA\": true, \"VODKA\": true, \"WHISKEY\": true, \"WINE\": true },\n\t\tnumPatrons = parseInt(readline(), 10),\n\t\tnumChecks = 0,\n\t\tagePattern = /\\d+/;\n\tfor (var patronIx = 0; patronIx < numPatrons; ++patronIx) {\n\t\tvar token = readline().replace(/\\s+/g, \"\");\n\t\tif (agePattern.test(token)) {\n\t\t\tif (parseInt(token, 10) < 18) {\n\t\t\t\t++numChecks;\n\t\t\t}\n\t\t}\n\t\telse if (alcoholic[token] != undefined) {\n\t\t\t++numChecks;\n\t\t}\n\t}\n\tprint(numChecks);\n}\n\nmain();\n"}, {"source_code": "'use strict';\n\n// let inpFileStrArr = `\n// 5\n// 18\n// VODKA\n// COKE\n// 19\n// 17\n// `.trim().split('\\n'), inpFileCounter = 0;\n// function readline() {\n// return inpFileStrArr[inpFileCounter++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nvar alcohol = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'];\n\nvar n = Number(readline()),\n count = 0;\nfor (var i = 0; i < n; i++) {\n var str = readline();\n if (isNaN(str) && alcohol.indexOf(str) === -1 || !isNaN(str) && Number(str) >= 18) {\n continue;\n }\n count++;\n}\n\nprint(count);\n"}, {"source_code": "'use strict';\n\n/*let input = `2\n2\nGIN`.split('\\n');\nfunction print(out) {\n console.log(out);\n}\nfunction readline() {\n return input.shift();\n}*/\n\n//code\n\nvar n = Number(readline());\nvar drinks = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n var line = readline();\n if (!isNaN(Number(line))) {\n if (Number(line) < 18) {\n count++;\n }\n } else if (drinks.includes(line)) {\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var alco = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'];\nvar n = parseInt(readline());\nvar res = 0;\n\nwhile(n--) {\n\tvar input = readline();\n\tvar num = parseInt(input);\n\tif (num >= 0) {\n\t\tif (num < 18) {\n\t\t\tres++;\n\t\t}\n\t} else {\n\t\tif (alco.indexOf(input) !== -1) {\n\t\t\tres++;\n\t\t}\n\t}\n}\n\nprint(res);"}, {"source_code": "var arr = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar t = Number(readline());\nvar ans = 0;\nwhile(t--) {\n var input = readline();\n if ((input[0] >= \"0\" && input[0] <= \"9\" && input < 18) || arr.includes(input))\n ++ans;\n}\nprint(ans);"}], "negative_code": [{"source_code": "'use strict';\n\n/*let input = `5\n18\nVODKA\nCOKE\n19\n17`.split('\\n');\nfunction print(out) {\n console.log(out);\n}\nfunction readline() {\n return input.shift();\n}*/\n\n//code\n\nvar n = Number(readline());\nvar drinks = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n var line = readline();\n if (!isNaN(Number(line))) {\n if (Number(line) < 18) {\n count++;\n }\n } else if (!drinks.includes(line)) {\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var alco = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'];\nvar n = parseInt(readline());\nvar res = 0;\n\nwhile(n--) {\n\tvar input = readline();\n\tif (num = parseInt(input)) {\n\t\tif (num < 18) {\n\t\t\tres++;\n\t\t}\n\t} else {\n\t\tif (alco.indexOf(input) !== -1) {\n\t\t\tres++;\n\t\t}\n\t}\n}\n\nprint(res);"}, {"source_code": "var arr = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar t = Number(readline());\nvar ans = 0;\nwhile(t--) {\n var input = readline();\n if ((typeof input == 'number' && input < 18))\n ++ans;\n}\nprint(ans);"}, {"source_code": "var arr = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar t = Number(readline());\nvar ans = 0;\nwhile (t--) {\n var input = readline();\n if ((typeof input === 'number' && input < 18) || arr.includes(input))\n ++ans;\n}\nprint(ans);"}, {"source_code": "var arr = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar t = Number(readline());\nvar ans = 0;\nwhile(t--) {\n var input = readline();\n if ((input[0] >= \"0\" && input[0] <= \"9\") || arr.includes(input))\n ++ans;\n}\nprint(ans);"}, {"source_code": "var arr = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"];\nvar t = Number(readline());\nvar ans = 0;\nwhile(t--) {\n var input = readline();\n if ((typeof input == 'number' && input < 18) || arr.includes(input))\n ++ans;\n}\nprint(ans);"}], "src_uid": "4b7b0fba7b0af78c3956c34c29785e7c"} {"source_code": "let problem = \"\";\nprocess.stdin.on(\"data\", (c) => (problem += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = problem.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n // if (problem > 5 && problem < 501) {\n // problem = 500;\n // continue;\n // }\n\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n // if (problem === 501) {\n // console.log(\"FOO\", problem, arr);\n // }\n\n const sorted = [...arr];\n sorted.sort((a, b) => a - b);\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = (x + diff) % len;\n // if (q >= len) {\n // q = q % len;\n // }\n // console.log(x, q);\n // console.log(x + a, q + a);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = [a[i], i];\r\n\t\t}\r\n\r\n\t\ta.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tconst ans = [];\r\n\t\tconst shfts = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet indx = a[i][1];\r\n\t\t\tfor (let j = 0; j < shfts.length; j++) {\r\n\t\t\t\tconst m = n - j;\r\n\t\t\t\tindx -= j;\r\n\t\t\t\tindx = (indx + m - shfts[j]) % m;\r\n\t\t\t\tindx += j;\r\n\t\t\t}\r\n\t\t\tshfts[i] = indx - i;\r\n\t\t\tif (shfts[i]) {\r\n\t\t\t\tans.push([i+1, n, shfts[i]]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tfor (const stp of ans)\r\n\t\t\tconsole.log(stp.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline());\r\n for (let m = 0; m < t; m++){\r\n const n = parseInt(readline());\r\n \r\n const arr = readline().split(' ').map((str) => parseInt(str));\r\n let count = 0;\r\n const moves = [];\r\n for(let index = 0; index < n; index++){\r\n \r\n let min = index;\r\n \r\n for(let i = index; i < n; i++){\r\n if (arr[i] < arr[min]) {\r\n min = i;\r\n }\r\n }\r\n if(min !== index){\r\n let temp = arr[min]\r\n for(let j = index; j <= min; j++){\r\n let p = arr[j]\r\n arr[j] = temp;\r\n temp = p;\r\n }\r\n\r\n count++;\r\n moves.push(`${index + 1} ${min + 1} ${min - index}`);\r\n }\r\n }\r\n\r\n console.log(count);\r\n console.log(moves.join('\\n'));\r\n }\r\n\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let newArr = [...arr],\r\n res = [];\r\n newArr.sort((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] !== newArr[i]) {\r\n let f = newArr[i];\r\n for (let j = i; j < n; j++) {\r\n if (f === arr[j]) {\r\n let t = [i + 1, j + 1, j - i];\r\n let g = arr[j];\r\n for (let k = j; k > i; k--) arr[k] = arr[k - 1];\r\n arr[i] = g;\r\n res.push(t);\r\n }\r\n }\r\n }\r\n }\r\n if (res.length) {\r\n console.log(res.length);\r\n for (let i = 0; i < res.length; i++) console.log(res[i].join(\" \"));\r\n } else console.log(0);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = [];\r\n\t\tvar count = 0;\r\n\t\twhile(true){\r\n\t\t\tvar isOK = true;\r\n\t\t\tfor(var i = 0; i < list.length - 1; i++){\r\n\t\t\t\tif(list[i] > list[i + 1]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(isOK){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tvar max = -Math.pow(10, 9) - 1;\r\n\t\t\tvar maxIndex = -1;\r\n\t\t\tfor(var i = 0; i < list.length; i++){\r\n\t\t\t\tif(max < list[i]){\r\n\t\t\t\t\tmax = list[i];\r\n\t\t\t\t\tmaxIndex = i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar newlist = [];\r\n\t\t\tfor(var i = 0; i < list.length; i++){\r\n\t\t\t\tif(maxIndex != i){\r\n\t\t\t\t\tnewlist.push(list[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(maxIndex != list.length - 1){\r\n\t\t\t\toutput.push((maxIndex + 1) + \" \" + (list.length) + \" 1\");\r\n\t\t\t}\r\n\t\t\tlist = newlist;\r\n\t\t}\r\n\t\tmyout(output.length);\r\n\t\tmyout(myconv(output, 9));\r\n\t}\r\n}\r\n"}, {"source_code": "\tfunction readStringArray() {\r\n\t\treturn readline().split(' ');\r\n\t}\r\n\tfunction readNumArray() {\r\n\t\treturn readStringArray().map(Number);\r\n\t}\r\n\r\n\tfunction main() {\r\n\t\tvar testCasesNum = +readline();\r\n\t\tfor (var i = 0; i < testCasesNum; i++) {\r\n\t\t\tvar l = +readline();\r\n\t\t\tvar arr = readNumArray();\r\n\t\t\tvar results = [];\r\n\t\t\tfor (var j = 0; j < arr.length - 1; j++) {\r\n\t\t\t\tvar minIdx = findMinIdx(arr.slice(j));\r\n\t\t\t\tif (minIdx > 0) {\r\n\t\t\t\t\tresults.push(`${j + 1} ${arr.length} ${minIdx}`);\r\n\t\t\t\t\tarr = arr\r\n\t\t\t\t\t\t.slice(0, j)\r\n\t\t\t\t\t\t.concat(arr.slice(j + minIdx))\r\n\t\t\t\t\t\t.concat(arr.slice(j, j + minIdx));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tprint(results.length);\r\n\t\t\tfor (var k = 0; k < results.length; k++) {\r\n\t\t\t\tprint(results[k]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction findMinIdx(arr) {\r\n\t\tvar min = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (arr[i] < arr[min]) {\r\n\t\t\t\tmin = i;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn min;\r\n\t}\r\n\tmain();"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n const myArr = readline().split(\" \");\r\n const ans = [];\r\n for(let i = 0; i < n - 1; i++) {\r\n let minIndex = i;\r\n for(let j = i; j < n; j++) {\r\n if(Number(myArr[j]) < Number(myArr[minIndex])) minIndex = j;\r\n }\r\n if(0 < minIndex - i) {\r\n ans.push((i + 1) + \" \" + n + \" \" + (minIndex - i));\r\n myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));\r\n }\r\n }\r\n console.log(ans.length);\r\n ans.forEach(str => console.log(str));\r\n }\r\n}\r\n\r\nfunction shift(arr, shiftValue) {\r\n const newArr = [...arr];\r\n const n = arr.length;\r\n for(let i = 0; i < n; i++) {\r\n let newIndex = i - shiftValue;\r\n if(0 <= newIndex) newArr[newIndex] = arr[i];\r\n else newArr[n + newIndex] = arr[i];\r\n }\r\n return newArr;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j el===sorted[j]);\r\n if (index+1 === arr.length ) continue\r\n arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]\r\n c.push('' + (index+1) + ' ' + sorted.length + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "let problem = \"\";\nprocess.stdin.on(\"data\", (c) => (problem += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = problem.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort((a, b) => a - b);\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = (x + diff) % len;\n newArr[x + a] = arr[q + a];\n }\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n var n = parseInt(readline());\r\n while (n--) {\r\n readline();\r\n var temp = readline().split(\" \");\r\n var arr = [];\r\n for (let i = 0; i < temp.length; i += 1) {\r\n temp[i] = parseInt(temp[i]);\r\n arr.push(temp[i]);\r\n }\r\n var sortArr = temp.sort(function (a, b) {\r\n return a - b;\r\n });\r\n var len = arr.length;\r\n var ans = [];\r\n for (var i = 0; i < len; i += 1) {\r\n for (var j = i; j < len; j += 1) {\r\n if (arr[j] === sortArr[i]) {\r\n if (i !== j) {\r\n ans.push([i + 1, j + 1, j - i]);\r\n for (var k = j - 1; k >= i; k -= 1) {\r\n arr[k + 1] = arr[k];\r\n }\r\n arr[i] = sortArr[i];\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n console.log(ans.length);\r\n for (var i = 0; i < ans.length; i += 1) {\r\n console.log(ans[i][0], ans[i][1], ans[i][2]);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfunction shift (ar, l, r, d) {\r\n\t\t\tconst cpy = ar.slice(l, r + 1);\r\n\t\t\tlet i = d;\r\n\t\t\twhile (l <= r) {\r\n\t\t\t\tar[l++] = cpy[i];\r\n\t\t\t\ti = (i + 1) % cpy.length;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst mn = Math.min(...a.slice(i));\r\n\t\t\tconst d = a.slice(i).findIndex(x => x == mn);\r\n\r\n\t\t\tshift(a, i, n-1, d);\r\n\r\n\t\t\tif (d) ans.push([i+1, n, d]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tfor (const stp of ans)\r\n\t\t\tconsole.log(stp.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "let problem = \"\";\nprocess.stdin.on(\"data\", (c) => (problem += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = problem.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n if (problem > 5 && problem < 501) {\n problem = 500;\n continue;\n }\n\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n if (problem === 501) {\n console.log(\"FOO\", problem, arr);\n }\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = (x + diff) % len;\n // if (q >= len) {\n // q = q % len;\n // }\n // console.log(x, q);\n // console.log(x + a, q + a);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let problem = \"\";\nprocess.stdin.on(\"data\", (c) => (problem += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = problem.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n if (problem > 5 && problem < 499) {\n problem = 499;\n continue;\n }\n\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = (x + diff) % len;\n // if (q >= len) {\n // q = q % len;\n // }\n // console.log(x, q);\n // console.log(x + a, q + a);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (i > 5) {\n i = 499;\n continue;\n }\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = (x + diff) % len;\n // if (q >= len) {\n // q = q % len;\n // }\n // console.log(x, q);\n // console.log(x + a, q + a);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = x + diff;\n if (q >= len) {\n q = q % len;\n }\n // console.log(x, q);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \").map((n) => parseInt(n));\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = x + diff;\n if (q >= len) {\n q = q % len;\n }\n // console.log(x, q);\n newArr[x + a] = arr[q + a];\n }\n console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n lines.slice(-1);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = x + diff;\n if (q >= len) {\n q = q % len;\n }\n // console.log(x, q);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n lines.slice(-1);\n solve(lines.slice(-1));\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = x + diff;\n if (q >= len) {\n q = q % len;\n }\n // console.log(x, q);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\n// const testCase = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// testCase.splice(-1, 1);\n// solve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n ines.slice(-1);\n solve(lines.slice(-1));\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem <= numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n\n const len = i - a + 1;\n\n for (let x = 0; x < len; x++) {\n let q = x + diff;\n if (q >= len) {\n q = q % len;\n }\n // console.log(x, q);\n newArr[x + a] = arr[q + a];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n\n process.exit(0);\n}\n\nconst testCase = [\n \"4\",\n \"2\",\n \"2 1\",\n \"3\",\n \"1 2 1\",\n \"4\",\n \"2 4 1 3\",\n \"5\",\n \"2 5 1 4 3\",\n \"\",\n];\n\ntestCase.splice(-1, 1);\nsolve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n ines.slice(-1);\n solve(lines.slice(-1));\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const numProblems = lines[0];\n let moves = [];\n\n for (let problem = 1; problem < numProblems; problem++) {\n moves = [];\n const str = lines[problem * 2];\n let arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = 0; i < arr.length; i++) {\n // console.log(\"test\", i, a, arr[i], cur);\n if (arr[i] === cur) {\n if (i - a > 0) {\n const diff = i - a;\n moves.push(`${a + 1} ${i + 1} ${diff}`);\n let newArr = [...arr];\n for (let x = a; x <= i; x++) {\n let q = x + diff;\n if (q > i) {\n q = (q % (i - a + 1)) + a;\n }\n newArr[x] = arr[q];\n }\n // console.log(arr, newArr);\n arr = newArr;\n }\n a += 1;\n i = a - 1;\n cur = sorted[a];\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n\n process.exit(0);\n}\n\nconst testCase = [\n \"4\",\n \"2\",\n \"2 1\",\n \"3\",\n \"1 2 1\",\n \"4\",\n \"2 4 1 3\",\n \"5\",\n \"2 5 1 4 3\",\n \"\",\n];\n\ntestCase.splice(-1, 1);\nsolve(testCase);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n console.log(lines);\n const problems = lines[0];\n let moves = [];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n moves.push(`${a + 1} ${i + 1} ${i - a}`);\n }\n a++;\n cur = sorted[a];\n i = a;\n // console.log(\"Cur\", cur);\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = lines[0];\n let moves = [];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n if (i - a > 0) {\n moves.push(`${a + 1} ${i + 1} ${i - a}`);\n }\n a++;\n cur = sorted[a];\n i = a;\n // console.log(\"Cur\", cur);\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = lines[0];\n let moves = [];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n moves.push(`${a + 1} ${i + 1} ${i - a}`);\n a++;\n cur = sorted[a];\n i = a;\n // console.log(\"Cur\", cur);\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = lines[0];\n let moves = [];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n moves.push(`${a + 1} ${i + 1} ${i + 1 - a + 1}`);\n a++;\n cur = sorted[a];\n i = a;\n // console.log(\"Cur\", cur);\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = lines[0];\n let moves = [];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n moves.push(`${a} ${i} ${i - a}`);\n a++;\n cur = sorted[a];\n i = a;\n // console.log(\"Cur\", cur);\n }\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n }\n console.log(moves.length);\n moves.forEach((str) => console.log(str));\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = lines[0];\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = [...arr];\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n // console.log(\"Cur\", cur);\n\n for (let i = a; i < arr.length; i++) {\n if (arr[i] === cur) {\n console.log(`${a} ${i} ${i - a}`);\n a++;\n cur = sorted[a];\n i = a;\n }\n }\n }\n process.exit(0);\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n solve(lines);\n});\n\nfunction solve(lines) {\n // console.log(lines);\n const problems = parseInt(lines[0]);\n for (let problem = 1; problem < problems; problem++) {\n const str = lines[problem * 2];\n const arr = str.split(\" \");\n\n const sorted = new Array(arr);\n sorted.sort();\n\n let a = 0;\n let cur = sorted[0];\n\n for (let i = a; i < arr.length; i++) {\n console.log(i);\n if (arr[i] === cur) {\n console.log(a + \" \" + i + \" \" + i - a);\n a++;\n cur = sorted[a];\n i = a;\n }\n }\n }\n console.log(\"done\");\n}\n\n// const test = [\n// \"4\",\n// \"2\",\n// \"2 1\",\n// \"3\",\n// \"1 2 1\",\n// \"4\",\n// \"2 4 1 3\",\n// \"5\",\n// \"2 5 1 4 3\",\n// \"\",\n// ];\n\n// solve(test);\n"}, {"source_code": "let i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n console.log(lines);\n});\n\nconsole.log(\"Testing\");\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j el===sorted[j]);\r\n if (index === j ) continue\r\n arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]\r\n c.push('' + (index+1) + ' ' + sorted.length + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j el===sorted[j]);\r\n arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]\r\n c.push('' + (index+1) + ' ' + sorted.length + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n if (index < j){\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n } else {\r\n let mid = arr.slice(j,index+1);\r\n mid.unshift(mid.pop())\r\n arr = [...arr.slice(0, j), ...mid, ...arr.slice(index+1)]\r\n }\r\n c.push('' + Math.min((j+1), (index+1)) + ' ' + Math.max((j+1), (index+1)) + ' ' + (index < j ? 1 : index-j));\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n if (index < j){\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n } else {\r\n arr = [...arr.slice(0, j), ...arr.slice(j,index+1).reverse(), ...arr.slice(index+1)]\r\n }\r\n c.push('' + Math.min((j+1), (index+1)) + ' ' + Math.max((j+1), (index+1)) + ' ' + (index < j ? 1 : index-j));\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n if (index < j){\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n } else {\r\n arr = [...arr.slice(0, j), ...arr.slice(j,index+1).reverse(), ...arr.slice(index+1)]\r\n }\r\n c.push('' + (index+1) + ' ' + (j+1) + ' ' + (index < j ? 1 : index-j));\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n c.push('' + Math.min(j+1, index+1) + ' ' + Math.max(j+1, index+1) + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n c.push('' + (j+1) + ' ' + (index+1) + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n c.push('' + (j+1) + ' ' + (index+1) + ' ' + 1);\r\n }\r\n console.log(arr);\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let c = []\r\n let k = readline();\r\n let arr = readline().split(' ').map(el=>Number(el))\r\n let sorted = [...arr].sort((a,b)=>a-b);\r\n for (let j = 0; j < sorted.length; j++) {\r\n let index = arr.findIndex((el)=>el===sorted[j]);\r\n if (index === j) continue\r\n let swp = arr[j];\r\n arr[j] = sorted[j];\r\n arr[index] = swp\r\n c.push('' + (index+1) + ' ' + (j+1) + ' ' + 1);\r\n }\r\n ansArr.push(c.length + '\\n' + c.join('\\n'))\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n const myArr = readline().split(\" \");\r\n const ans = [];\r\n for(let i = 0; i < n - 1; i++) {\r\n let minIndex = i;\r\n for(let j = i; j < n; j++) {\r\n if(myArr[j] < myArr[minIndex]) minIndex = j;\r\n }\r\n if(0 < minIndex - i) {\r\n ans.push((i + 1) + \" \" + n + \" \" + (minIndex - i));\r\n myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));\r\n }\r\n }\r\n console.log(ans.length);\r\n ans.forEach(str => console.log(str));\r\n }\r\n}\r\n\r\nfunction shift(arr, shiftValue) {\r\n const newArr = [...arr];\r\n const n = arr.length;\r\n for(let i = 0; i < n; i++) {\r\n let newIndex = i - shiftValue;\r\n if(0 <= newIndex) newArr[newIndex] = arr[i];\r\n else newArr[n + newIndex] = arr[i];\r\n }\r\n return newArr;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n const myArr = readline().split(\" \");\r\n const ans = [];\r\n for(let i = 0; i < n - 1; i++) {\r\n let minIndex = i;\r\n for(let j = i; j < n; j++) {\r\n if(myArr[j] < myArr[minIndex]) minIndex = j;\r\n }\r\n if(0 < minIndex - i) ans.push((i + 1) + \" \" + n + \" \" + (minIndex - i));\r\n myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));\r\n }\r\n console.log(ans.length);\r\n ans.forEach(str => console.log(str));\r\n }\r\n}\r\n\r\nfunction shift(arr, shiftValue) {\r\n const newArr = [...arr];\r\n const n = arr.length;\r\n for(let i = 0; i < n; i++) {\r\n let newIndex = i - shiftValue;\r\n if(0 <= newIndex) newArr[newIndex] = arr[i];\r\n else newArr[n + newIndex] = arr[i];\r\n }\r\n return newArr;\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n const myArr = readline().split(\" \");\r\n const ans = [];\r\n for(let i = 0; i < n - 1; i++) {\r\n let minIndex = i;\r\n for(let j = i; j < n; j++) {\r\n if(myArr[j] < myArr[minIndex]) minIndex = j;\r\n }\r\n ans.push((i + 1) + \" \" + n + \" \" + (minIndex - i));\r\n myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));\r\n }\r\n console.log(n - 1);\r\n ans.forEach(str => console.log(str));\r\n }\r\n}\r\n\r\nfunction shift(arr, shiftValue) {\r\n const newArr = [...arr];\r\n const n = arr.length;\r\n for(let i = 0; i < n; i++) {\r\n let newIndex = i - shiftValue;\r\n if(0 <= newIndex) newArr[newIndex] = arr[i];\r\n else newArr[n + newIndex] = arr[i];\r\n }\r\n return newArr;\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline());\r\n for (let m = 0; m < t; m++){\r\n const n = parseInt(readline());\r\n \r\n const arr = readline().split(' ').map((str) => parseInt(str));\r\n let count = 0;\r\n const moves = [];\r\n for(let index = 0; index < n; index++){\r\n \r\n let min = index;\r\n \r\n for(let i = index; i < n; i++){\r\n if (arr[i] < arr[min]) {\r\n min = i;\r\n }\r\n }\r\n if(min !== index){\r\n let t = arr[min];\r\n for(let j = index; j < min; j++){\r\n let p = arr[index];\r\n arr[index] = t;\r\n t = p;\r\n }\r\n count++;\r\n moves.push(`${index + 1} ${min + 1} 1`);\r\n }\r\n }\r\n\r\n console.log(count);\r\n console.log(moves.join('\\n'));\r\n }\r\n\r\n}\r\n"}], "src_uid": "06c515c2d889edec8db784b2d5279edc"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n v2v = {};\n if (n != m) {\n print('NO');\n return;\n }\n function augment(u, v) {\n if (v2v[u] === undefined) {\n v2v[u] = [v];\n } else {\n v2v[u].push(v);\n }\n }\n for (var i = 0; i < m; ++i) {\n data = tokenizeIntegers(readline());\n var x = data[0], y = data[1];\n augment(x, y);\n augment(y, x);\n }\n var count = 0,\n seen = {};\n function visit(u) {\n if (seen[u]) {\n return;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n if (vs === undefined) {\n return;\n }\n for (var i = 0; i < vs.length; ++i) {\n visit(vs[i]);\n }\n }\n visit(1);\n print(count == n ? 'FHTAGN!' : 'NO');\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n v2v = {};\n if (n != m) {\n print('NO');\n return;\n }\n function augment(u, v) {\n if (v2v[u] === undefined) {\n v2v[u] = [v];\n } else {\n v2v[u].push(v);\n }\n }\n for (var i = 0; i < m; ++i) {\n data = tokenizeIntegers(readline());\n var x = data[0], y = data[1];\n augment(x, y);\n augment(y, x);\n }\n var seen = {},\n cycle = [],\n found = false;\n function search(u, parent) {\n if (seen[u]) {\n cycle.push(u);\n return true;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n if (vs === undefined) {\n return;\n }\n for (var i = 0; i < vs.length; ++i) {\n var v = vs[i];\n if (v == parent) {\n continue;\n }\n if (search(v, u)) {\n if (cycle[0] == u) {\n found = true;\n }\n if (!found) {\n cycle.push(u);\n }\n return true;\n }\n }\n return false;\n }\n search(1, -1);\n if (cycle.length < 3) {\n print('NO');\n return;\n }\n var count = 0;\n seen = {};\n function visit(u) {\n if (seen[u]) {\n return;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n for (var i = 0; i < vs.length; ++i) {\n visit(vs[i]);\n }\n }\n visit(cycle[0]);\n print(count == n ? 'FHTAGN!' : 'NO');\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n v2v = {};\n if (n != m) {\n print('NO');\n return;\n }\n function augment(u, v) {\n if (v2v[u] === undefined) {\n v2v[u] = [v];\n } else {\n v2v[u].push(v);\n }\n }\n for (var i = 0; i < m; ++i) {\n data = tokenizeIntegers(readline());\n var x = data[0], y = data[1];\n augment(x, y);\n augment(y, x);\n }\n var seen = {},\n cycle = [],\n done = false;\n function findCycle(u, parent) {\n if (seen[u]) {\n cycle.push(u);\n return true;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n if (vs === undefined) {\n return;\n }\n for (var i = 0; i < vs.length; ++i) {\n var v = vs[i];\n if (v == parent) {\n continue;\n }\n if (findCycle(v, u)) {\n if (cycle[0] == u) {\n done = true;\n }\n if (!done) {\n cycle.push(u);\n }\n return true;\n }\n }\n return false;\n }\n findCycle(1, -1);\n if (cycle.length < 3) {\n print('NO');\n return;\n }\n var count = 0;\n seen = {};\n function visit(u) {\n if (seen[u]) {\n return;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n for (var i = 0; i < vs.length; ++i) {\n visit(vs[i]);\n }\n }\n visit(cycle[0]);\n print(count == n ? 'FHTAGN!' : 'NO');\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n v2v = {};\n function augment(u, v) {\n if (v2v[u] === undefined) {\n v2v[u] = [v];\n } else {\n v2v[u].push(v);\n }\n }\n for (var i = 0; i < m; ++i) {\n data = tokenizeIntegers(readline());\n var x = data[0], y = data[1];\n augment(x, y);\n augment(y, x);\n }\n var seen = {},\n cycle = [],\n found = false;\n function search(u, parent) {\n //print('u = '+u+', parent = '+parent);\n if (seen[u]) {\n cycle.push(u);\n return true;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n for (var i = 0; i < vs.length; ++i) {\n var v = vs[i];\n if (v == parent) {\n continue;\n }\n if (search(v, u)) {\n if (cycle[0] == u) {\n found = true;\n }\n if (!found) {\n cycle.push(u);\n }\n return true;\n }\n }\n return false;\n }\n for (var u = 1; u <= n; ++u) {\n if (v2v[u] !== undefined) {\n search(u, -1);\n break;\n }\n }\n //print(found);\n //print(cycle.join(' '));\n if (cycle.length < 3 || n != m) {\n print('NO');\n return;\n }\n var count = 0;\n seen = {};\n function visit(u) {\n if (seen[u]) {\n return;\n }\n seen[u] = true;\n count += 1;\n var vs = v2v[u];\n for (var i = 0; i < vs.length; ++i) {\n visit(vs[i]);\n }\n }\n visit(cycle[0]);\n print(count == n ? 'FHTAGN!' : 'NO');\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], m = data[1],\n v2v = {};\n function augment(u, v) {\n if (v2v[u] === undefined) {\n v2v[u] = [v];\n } else {\n v2v[u].push(v);\n }\n }\n for (var i = 0; i < m; ++i) {\n data = tokenizeIntegers(readline());\n var x = data[0], y = data[1];\n augment(x, y);\n augment(y, x);\n }\n var seen = {},\n cycle = [],\n found = false,\n deleted = {};\n function search(u, parent) {\n //print(u, parent);\n if (seen[u]) {\n cycle.push(u);\n return true;\n }\n seen[u] = true;\n var vs = v2v[u];\n for (var i = 0; i < vs.length; ++i) {\n var v = vs[i];\n if (v == parent || deleted[[u, v]]) {\n continue;\n }\n if (search(v, u)) {\n if (cycle[0] == u) {\n found = true;\n }\n if (!found) {\n cycle.push(u);\n }\n return true;\n }\n }\n return false;\n }\n for (var u = 1; u <= n; ++u) {\n if (v2v[u] !== undefined) {\n search(u, -1);\n break;\n }\n }\n //print(found);\n //print(cycle.join(' '));\n if (cycle.length < 3 || n != m) {\n print('NO');\n return;\n }\n for (var i = 0; i < cycle.length; ++i) {\n var u = cycle[i], v = cycle[(i+1)%cycle.length];\n deleted[[u, v]] = deleted[[v, u]] = true;\n }\n for (var u = 1; u <= n; ++u) {\n if (v2v[u] !== undefined) {\n seen = {};\n cycle = [];\n found = false;\n search(u, -1);\n if (found) {\n //print('found a cycle starting from '+u);\n //print(cycle.join(' '));\n print('NO');\n return;\n }\n }\n }\n print('FHTAGN!');\n}\n\nmain();\n"}], "src_uid": "4ecbfc792da55f458342c6eff2d5da5a"} {"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 0; i < count; i++) {\r\n const idx = 1 + i * 2;\r\n const len = parseInt(lines[idx]);\r\n const line = lines[idx+1];\r\n let output = '';\r\n for (let c = 0; c < len; c++) {\r\n const ch = line[c];\r\n if (ch === 'L' || ch === 'R') {\r\n output += ch;\r\n } else if (ch === 'U') {\r\n output += 'D';\r\n } else if (ch === 'D') {\r\n output += 'U';\r\n }\r\n }\r\n console.log(output);\r\n }\r\n})", "positive_code": [{"source_code": "var t = parseInt(readline()); // Number of testCases\r\nvar n; // Number of Chars\r\nvar s; // String itself\r\n\r\nvar problemCounter = 0;\r\nwhile (problemCounter++ < t) {\r\n n = readline();\r\n s = readline().split(\"\");\r\n s.forEach((c, index) => {\r\n switch (c) {\r\n case \"U\":\r\n s[index] = \"D\";\r\n break;\r\n case \"D\":\r\n s[index] = \"U\";\r\n break;\r\n }\r\n });\r\n print(s.length > 1 ? \"\".concat.apply(\"\", s) : s[0]);\r\n}"}, {"source_code": "var a = readline();\r\nvar arr = [];\r\nvar s = \"\";\r\nfor(var i = 0; i < a; i++){\r\n var n = readline();\r\n arr[i] = readline();\r\n for(var j = 0; j < arr[i].length; j++){\r\n if(arr[i][j]==\"U\"){\r\n s+=arr[i][j]=\"D\"\r\n }else if(arr[i][j]==\"D\"){\r\n s+=arr[i][j]=\"U\"\r\n }else{\r\n s+=arr[i][j]\r\n }\r\n }\r\n print(s);\r\n s=\"\";\r\n}"}, {"source_code": "function run(){\r\n var n = readline();\r\n var s = readline();\r\n var ans = [];\r\n var res = \"\";\r\n for(var x = 0; x < n; x++){\r\n if(s[x] == \"L\") ans.push('L'), res += \"L\";\r\n else if(s[x] == 'R') ans.push('R'), res += \"R\";\r\n else if(s[x] == 'D') ans.push('U'), res += \"U\";\r\n else ans.push('D'),res += \"D\";\r\n }\r\n print(res);\r\n}\r\n\r\nvar tc = readline();\r\nwhile(tc--) {\r\n run();\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= (Number(lines[0])) * 2; j ++ ) { \n if(j % 2 === 0){\n s = ''\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[k] == 'L'){\n s += 'L'\n }else if(a[k] == 'R'){\n s += 'R'\n }else if(a[k] == 'U'){\n s += 'D'\n }else if(a[k] == 'D'){\n s += 'U'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t= nl.num();\n\tlet ans = [];\n\tlet kv = { \"U\": \"D\",\n\t\t\t\t\"D\": \"U\",\n\t\t\t\t\"L\": \"L\",\n\t\t\t\t\"R\": \"R\"};\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet a = nl.line().split('').map(e => kv[e]);\n\t\tans.push(a.join(''));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t= nl.num();\n\tlet ans = [];\n\tlet kv = { \"U\": \"D\",\n\t\t\t\t\"D\": \"U\",\n\t\t\t\t\"L\": \"L\",\n\t\t\t\t\"R\": \"R\"};\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet a = [...nl.line()].map(e => kv[e]);\n\t\tans.push(a.join(''));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let str = readLine();\r\n let arr = [];\r\n for (let index = 0; index < str.length; index++) {\r\n const element = str[index];\r\n if (element === \"U\") arr.push(\"D\")\r\n else if (element === \"D\") arr.push(\"U\")\r\n else arr.push(element);\r\n }\r\n return arr.join(\"\");\r\n}\r\n"}, {"source_code": "//required remainder\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var l = lines[0];\n var answer = '';\n for(var j = 1; j < (Number(l) + 1) * 2; j++){\n if(j % 2 === 0){\n answer = '';\n var n = lines[j].split('');\n for(k = 0; k < n.length; k++){\n if(n[k] == 'L'){\n answer += 'L';\n }else if(n[k] == 'R'){\n answer += 'R';\n }else if(n[k] == 'U'){\n answer += 'D';\n }else if(n[k] == 'D'){\n answer += 'U';\n }\n }\n console.log(answer);\n }\n }\n});"}, {"source_code": "const { setupMaster } = require('cluster')\r\nconst { stderr } = require('process')\r\n\r\nfunction readInput() {\r\n const readline = require('readline')\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n })\r\n \r\n let problem = {\r\n T: [],\r\n testCases: []\r\n }\r\n \r\n rl.on('line', function (line) {\r\n // TODO: Process input\r\n if (problem.T === 0) {\r\n // Get number of test cases from first line\r\n problem.T.push(line.split(\" \"))\r\n } else {\r\n // TODO process the rest of the data\r\n const [a, b, c] =line.split(' ')\r\n const aNum = Number(a)\r\n const bNum = Number(b)\r\n const cNum = Number(c)\r\n \r\n problem.testCases.push(line.split(\" \"));\r\n }\r\n })\r\n \r\n .on('close', () => {\r\n // Finished processing input, now solve question\r\n solve();\r\n process.exit()\r\n })\r\n \r\n function solve() {\r\n let a = problem.testCases;\r\n let y = 2;\r\n let x = 0;\r\n let r = 0;\r\n const povs = \"LRUD\";\r\n let n = \"\";\r\n while (y < a.length) {\r\n let s = a[y][0].split(\"\");\r\n if (povs.includes(s[x])) {\r\n if (s[x] === \"U\") {\r\n s[x] = \"D\";\r\n n = n + s[x];\r\n } else if (s[x] === \"D\") {\r\n s[x] = \"U\";\r\n n = n + s[x];\r\n } else {\r\n n = n + s[x];\r\n }\r\n x++;\r\n } \r\n if (x === s.length) {\r\n console.log(n)\r\n n = \"\";\r\n y += 2;\r\n x = 0;\r\n }\r\n }\r\n }\r\n } readInput() "}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main() {\r\n const charResMap = {\r\n 'U': 'D',\r\n 'R': 'R',\r\n 'L': 'L',\r\n 'D': 'U'\r\n }\r\n const t = parseInt(readLine(), 10);\r\n for(let i =0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n const n = Number(readline());\r\n\r\n // var [a, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n var res = []\r\n for (let j = 0; j < n; j++) {\r\n if(a[j] === \"U\") res[j] = \"D\"\r\n if(a[j] === \"L\") res[j] = \"L\"\r\n if(a[j] === \"R\") res[j] = \"R\"\r\n if(a[j] === \"D\") res[j] = \"U\"\r\n }\r\n// console.log(a)\r\n// console.log(n)\r\nconsole.log(res.join( ''))\r\n // if(i===(string.length-2)) return console.log(string)\r\n })\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar output = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(s[i] == \"U\"){\r\n\t\t\t\toutput[i] = \"D\";\r\n\t\t\t}else if(s[i] == \"D\"){\r\n\t\t\t\toutput[i] = \"U\";\r\n\t\t\t}else{\r\n\t\t\t\toutput[i] = s[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 0));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= (Number(lines[0])) * 2; j ++ ) { \n if(j % 2 === 0){\n s = ''\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[k] == 'R'){\n s += 'R'\n }else if(a[k] == 'U'){\n s += 'D'\n }else if(a[k] == 'D'){\n s += 'U'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= Number(lines[0]) * 2; j ++ ) { \n if(j % 2 === 0){\n s = ''\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[k] == 'R'){\n s += 'R'\n }else if(a[k] == 'U'){\n s += 'D'\n }else if(a[k] == 'D'){\n s += 'U'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= Number(lines[0]) * 2; j ++ ) { \n if(j % 2 === 0){\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[k] == 'R'){\n s += 'R'\n }else if(a[k] == 'U'){\n s += 'D'\n }else if(a[k] == 'D'){\n s += 'U'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= Number(lines[0]) * 2; j ++ ) { \n if(j % 2 === 0){\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[k] == 'R'){\n s += 'R'\n }else if(a[k] == 'U'){\n s += 'U'\n }else if(a[k] == 'D'){\n s += 'D'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= Number(lines[0]) * 2; j ++ ) { \n if(j % 2 === 0){\n var a = lines[j].split('')\n for(k = 0 ; k < a.length; k++){\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[j] == 'R'){\n s += 'R'\n }else if(a[j] == 'U'){\n s += 'U'\n }else if(a[j] == 'D'){\n s += 'D'\n }\n }\n console.log(s)\n\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s= ''\n for(j = 1; j <= Number(lines[0]) * 2; j ++ ) { \n if(j % 2 === 0){\n var a = lines[j].split('')\n if(a[j] == 'L'){\n s += 'L'\n }else if(a[j] == 'R'){\n s += 'R'\n }else if(a[j] == 'U'){\n s += 'U'\n }else if(a[j] == 'D'){\n s += 'D'\n }\n }\n console.log(s)\n }\n});"}, {"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 1; i < count; i += 2) {\r\n const len = parseInt(lines[i]);\r\n const line = lines[i+1];\r\n let output = '';\r\n for (let c = 0; c < len; c++) {\r\n const ch = line[c];\r\n if (ch === 'L' || ch === 'R') {\r\n output += ch;\r\n } else if (ch === 'U') {\r\n output += 'D';\r\n } else if (ch === 'D') {\r\n output += 'U';\r\n }\r\n }\r\n console.log(output);\r\n }\r\n})"}, {"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 0; i < count; i += 2) {\r\n const len = parseInt(lines[i]);\r\n const line = lines[i+1];\r\n let output = '';\r\n for (let c = 0; c < len; c++) {\r\n const ch = line[c];\r\n if (ch === 'L' || ch === 'R') {\r\n output = ch;\r\n } else if (ch === 'U') {\r\n output = 'D';\r\n } else if (ch === 'D') {\r\n output = 'U';\r\n }\r\n }\r\n console.log(output);\r\n }\r\n})"}], "src_uid": "b894e16e8c00f8d97fde4a104466b3ef"} {"source_code": "var v = 'abcdefghijklmnopqrstuvwxyz';\nv = v.split('');\nvar findnum = function(n){\n for(l = 0; l < 26; l++){\n if(v[l] == n){\n return l + 1;\n }\n }\n};\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tvar a0 = 0; var a1 = 0; var a2 = 0; var a3 = 0; var a4 = 0; var a5 = 0;\n\tfor(i = 1; i <= t * 4; i++){\n\t var a = lines[i].split(' ').map(Number);\n if(i % 4 === 1){\n continue;\n }else if(i % 4 == 2){\n a0 = a[0];\n a1 = a[1];\n }else if(i % 4 == 3){\n a2 = a[0];\n a3 = a[1];\n }else{\n a4 = a[0];\n a5 = a[1];\n var ans = Math.abs(a2 - a0) + Math.abs(a1 - a3);\n if(a0 == a2 && a0 == a4){\n if(a5 > a1 && a5 < a3 || a5 < a1 && a5 > a3){\n ans += 2;\n }\n }else if(a1 == a3 && a1 == a5){\n if(a4 > a0 && a4 < a2 || a4 < a0 && a4 > a2){\n ans += 2;\n }\n }\n console.log(ans);\n }\n }\n});\n\n", "positive_code": [{"source_code": "let input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map(l => l.trim());\r\n \r\n for (let i=1; i id - '0');\r\n i += 1;\r\n const b = lines[i].split(' ').map((id) => id - '0');\r\n i += 1;\r\n const p = lines[i].split(' ').map((id) => id - '0')\r\n i+= 1;\r\n console.log(solve(a,b,p))\r\n }\r\n});\r\n\r\nconst solve = (a, b, p) =>{\r\n try{\r\n const x1 = a[0]; const y1 = a[1];\r\n const x2 = b[0]; const y2 = b[1];\r\n const x3 = p[0]; const y3 = p[1];\r\n\r\n if((x1=== x2) && (x2=== x3)){\r\n if((y2 < y3 && y3 < y1) || (y1 < y3 && y3 < y2)){\r\n return Math.abs(y2 - y1) + 2\r\n } else{\r\n return Math.abs(y2 - y1);\r\n }\r\n }else if((y1 === y2) && (y2 === y3)){\r\n if((x2 < x3 && x3 < x1) || (x1 < x3 && x3 < x2)){\r\n return Math.abs(x2 - x1) + 2;\r\n }else{\r\n return Math.abs(x2 - x1);\r\n }\r\n }else{\r\n return Math.abs(x2-x1) + Math.abs(y2-y1);\r\n }\r\n }catch (ex){\r\n console.log('ex:', ex)\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = next();\r\n\t\tvar Ax = nextInt();\r\n\t\tvar Ay = nextInt();\r\n\t\tvar Bx = nextInt();\r\n\t\tvar By = nextInt();\r\n\t\tvar Fx = nextInt();\r\n\t\tvar Fy = nextInt();\r\n\t\tvar output = Math.abs(Ax - Bx) + Math.abs(Ay - By);\r\n\t\tif(Ax == Fx && Ax == Bx && Math.min(Ay, By) <= Fy && Fy <= Math.max(Ay, By)){\r\n\t\t\toutput += 2;\r\n\t\t}else if(Ay == Fy && Ay == By && Math.min(Ax, Bx) <= Fx && Fx <= Math.max(Ax, Bx)){\r\n\t\t\toutput += 2;\r\n\t\t}\r\n\t\t\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const t = input.number();\r\n const ans = Array(t);\r\n for (let i = 0; i < t; i++) {\r\n let xa = input.number();\r\n let ya = input.number();\r\n let xb = input.number();\r\n let yb = input.number();\r\n const xf = input.number();\r\n const yf = input.number();\r\n if (xa === xb) {\r\n ;\r\n [ya, yb] = [ya, yb].sort((a, b) => a - b);\r\n if (xf === xa && ya < yf && yf < yb) {\r\n ans[i] = Math.abs(yb - ya) + 2;\r\n }\r\n else {\r\n ans[i] = Math.abs(yb - ya);\r\n }\r\n }\r\n else if (ya === yb) {\r\n ;\r\n [xa, xb] = [xa, xb].sort((a, b) => a - b);\r\n if (yf === ya && xa < xf && xf < xb) {\r\n ans[i] = Math.abs(xb - xa) + 2;\r\n }\r\n else {\r\n ans[i] = Math.abs(xb - xa);\r\n }\r\n }\r\n else {\r\n ans[i] = Math.abs(xb - xa) + Math.abs(yb - ya);\r\n }\r\n }\r\n console.log(ans.join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "//function main(input) {\r\nfunction main() {\r\n var getDistance = function( sa, sb, sf ) {\r\n //console.log(\"solve is called\");\r\n //console.log(sa);\r\n //console.log(sb);\r\n //console.log(sf);\r\n //print(\")\"+sa);\r\n //print(\")\"+sb);\r\n //print(\")\"+sf);\r\n\r\n a = sa.split(\" \").map(function(n){return parseInt(n,10);});\r\n b = sb.split(\" \").map(function(n){return parseInt(n,10);});\r\n f = sf.split(\" \").map(function(n){return parseInt(n,10);});\r\n //console.log(a);\r\n //console.log(b);\r\n //console.log(f);\r\n\r\n dist = Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);\r\n if (a[0]===b[0] && a[0]===f[0]) {\r\n if ((a[1]{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = Math.abs(xA-xB) +Math.abs(yA-yB);\r\n\r\n if((xA === xB) && (xB === xF)){\r\n if((yA < yF && yF < yB) || (yB < yF && yF < yA)){\r\n distance += 2;\r\n }\r\n }\r\n if((yA === yB) && (yB === yF)){\r\n if((xA < xF && xF < xB) || (xB < xF && xF < xA)){\r\n distance += 2;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "// process.stdin.resume();\n\nprocess.stdin.setEncoding('utf8');\n\nlet input = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', data => {\n input += data;\n});\n\nprocess.stdin.on('end', () => {\n input = input.trim().split('\\n').map(str => str.trim());\n main();\n});\n\nfunction readLine() {\n return input[currentLine++];\n}\n\nfunction main() {\n let testCases = readLine();\n testCases = parseInt(testCases, 10);\n while (testCases--) {\n readLine();\n let start = readLine();\n let end = readLine();\n let wall = readLine();\n solve(start, end, wall);\n }\n}\n\nfunction solve(start, end, wall) {\n const [startX, startY] = start.split(' ').map((item) => parseInt(item, 10));\n const [endX, endY] = end.split(' ').map((item) => parseInt(item, 10));\n const [wallX, wallY] = wall.split(' ').map((item) => parseInt(item, 10));\n\n const p1 = Math.abs(startX - endX);\n const p2 = Math.abs(startY - endY);\n let res = p1 + p2;\n\n const isXEqual = startX === wallX && endX === wallX;\n const isXinRange = Math.max(startX, endX) > wallX && Math.min(startX, endX) < wallX;\n const isYEqual = startY === wallY && endY === wallY;\n const isYInRange = Math.max(startY, endY) > wallY && Math.min(startY, endY) < wallY;\n if (isXEqual && isYInRange || isYEqual && isXinRange) {\n res += 2;\n }\n console.log(res);\n}\n\n"}, {"source_code": "class CPIO {\r\n constructor() {\r\n const input = require(\"fs\").readFileSync(process.stdin.fd);\r\n this.data = input.toString().split(/\\s+/);\r\n this.pos = 0;\r\n }\r\n\r\n word() {\r\n return this.data[this.pos++];\r\n }\r\n\r\n int() {\r\n return Number(this.word());\r\n }\r\n\r\n ints(len) {\r\n const res = [];\r\n for (let i = 0; i < len; ++i) {\r\n res.push(this.int());\r\n }\r\n return res;\r\n }\r\n};\r\n\r\nconst io = new CPIO;\r\n\r\nlet t = io.int();\r\n\r\nwhile (t--) {\r\n const [xa, ya, xb, yb, xf, yf] = io.ints(6);\r\n let ans = Math.abs(xa - xb) + Math.abs(ya - yb);\r\n if ((xa === xb && xa === xf && yf > Math.min(ya, yb) && yf < Math.max(ya, yb))) ans += 2;\r\n else if (ya === yb && ya === yf && xf > Math.min(xa, xb) && xf < Math.max(xa, xb)) ans += 2;\r\n console.log(ans);\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n const a = readLine().split(\" \").map(i => parseInt(i) - 1);\r\n const b = readLine().split(\" \").map(i => parseInt(i) - 1);\r\n const f = readLine().split(\" \").map(i => parseInt(i) - 1);\r\n let ans = Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);\r\n if ((a[0] == b[0] && a[0] == f[0] && Math.min(a[1], b[1]) < f[1] && f[1] < Math.max(a[1], b[1]))\r\n || (a[1] == b[1] && a[1] == f[1] && Math.min(a[0], b[0]) < f[0] && f[0] < Math.max(a[0], b[0])))\r\n ans += 2;\r\n return ans;\r\n}\r\n"}, {"source_code": "function isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction dist(xa, ya, xb, yb) {\r\n return Math.abs(xa - xb) + Math.abs(ya - yb);\r\n}\r\n\r\nfunction solve() {\r\n read();\r\n const [xa, ya] = readArray(Number);\r\n const [xb, yb] = readArray(Number);\r\n const [xf, yf] = readArray(Number);\r\n \r\n let ans = dist(xa, ya, xb, yb);\r\n if (xa === xb && xa === xf && (ya - yf) * (yb - yf) < 0 || ya === yb && ya === yf && (xa - xf) * (xb - xf) < 0) {\r\n ans += 2;\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \n \n \nlet inputString = '';\nlet currentLine = 0;\n \n \n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \n \n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n \n \n \n main();\n});\n \n \n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction getCoOrdinate() {\n\tvar aString = readLine();\n //console.log(aString);\n var aCorString = aString.split(' ');\n //console.log(aCorString);\n var aCorInt = [0, 0];\n aCorInt[0] = parseInt(aCorString[0]); \n aCorInt[1] = parseInt(aCorString[1]); \n \n\treturn aCorInt;\n}\n\nfunction difference(a, b) {\n return Math.abs(a - b);\n}\n\nfunction main()\n{\n var testCases = parseInt(readLine());\n \n //console.log(testCases);\n \n for(let i = 0; i < testCases; i++) \n {\n \tvar dummyInput = readLine();\n \tvar corA = getCoOrdinate();\n \tvar corB = getCoOrdinate();\n \tvar corF = getCoOrdinate();\n \t\n \tlet diff = difference(corA[0], corB[0]) + difference(corA[1], corB[1]);\n \t\n \tif(corA[0] == corB[0] && corA[0] == corF[0] && ((corF[1] < corA[1] && corF[1] > corB[1]) || (corF[1] > corA[1] && corF[1] < corB[1]))) {\n \t\tdiff = diff + 2;\n \t}\n \t\n \tif(corA[1] == corB[1] && corA[1] == corF[1] && ((corF[0] < corA[0] && corF[0] > corB[0]) || (corF[0] > corA[0] && corF[0] < corB[0]))) {\n \t\tdiff = diff + 2;\n \t}\n \t\n \tconsole.log(diff);\n \t\n \t//break;\n }\n \n \n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n // let p1x,p1y,p2x,p2y,p3x,p3y;\r\n\r\n readLine();\r\n p1=readLine();\r\n p2=readLine();\r\n p3=readLine();\r\n p1=p1.split(\" \");\r\n p2=p2.split(\" \");\r\n p3=p3.split(\" \");\r\n p1x=parseInt(p1[0]);\r\n p1y=parseInt(p1[1]);\r\n p2x=parseInt(p2[0]);\r\n p2y=parseInt(p2[1]);\r\n p3x=parseInt(p3[0]);\r\n p3y=parseInt(p3[1]); \r\n \r\n let val=Math.abs(p1x-p2x);\r\n val+=Math.abs(p1y-p2y);\r\n if(p1x===p2x && p2x===p3x)\r\n {\r\n if((p1y f[1] && f[1] > b[1])\n return 2 + Math.abs(a[1] - b[1])\n }\n if (a[1] === b[1] && a[1] === f[1]) {\n if (a[0] < f[0] && f[0] < b[0] || a[0] > f[0] && f[0] > b[0])\n return 2 + Math.abs(a[0] - b[0])\n }\n\n return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1])\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if(xA < xB){\r\n if((xA+1) == xF&& yA === yF) yA++;\r\n else xA++;\r\n distance++;\r\n }\r\n else if(xA > xB){\r\n if((xB+1) == xF && yB === yF) yB++;\r\n else xB++\r\n distance++;\r\n }\r\n if(yA < yB){\r\n if((yA+1) == yF&& xA === xF) xA++;\r\n else yA++;\r\n distance++;\r\n }\r\n else if(yA > yB){\r\n if((yB+1) == yF && xB === xF) xB++;\r\n else yB++;\r\n distance++;\r\n }\r\n // console.log(xA,yA);\r\n // console.log(xB,yB);\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if((xA !== xB) && (yA !== yB)){\r\n if(xA < xB){ distance++;\r\n xA++;\r\n }\r\n else{distance++;\r\n xB++;\r\n }\r\n if(yA < yB){ distance++;\r\n yA++;\r\n }\r\n else{ distance++;\r\n yB++;\r\n }\r\n }\r\n else if((xA === xB) && (yA !== yB)){\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance+= 2;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance+= 2;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA !== xB) && (yA === yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance+=2;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance+=2;\r\n xB++;\r\n }\r\n distance++;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if((xA !== xB) && (yA !== yB)){\r\n if(xA < xB){\r\n // if(( xA + 1 ) === xF) distance++;\r\n xA++;\r\n }\r\n else{\r\n // if(( xB + 1 ) === xF) distance++;\r\n xB++;\r\n }\r\n if(yA < yB){\r\n // if(( yA + 1 ) === yF) distance++;\r\n yA++;\r\n }\r\n else{\r\n // if(( yB + 1 ) === yF) distance++;\r\n yB++;\r\n }\r\n distance+=2;\r\n }\r\n else if((xA === xB) && (yA !== yB)){\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance+= 2;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance+= 2;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA !== xB) && (yA === yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance+=2;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance+=2;\r\n xB++;\r\n }\r\n distance++;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if((xA !== xB) && (yA !== yB)){\r\n if(xA < xB){\r\n // if(( xA + 1 ) === xF) distance++;\r\n xA++;\r\n }\r\n else{\r\n // if(( xB + 1 ) === xF) distance++;\r\n xB++;\r\n }\r\n if(yA < yB){\r\n // if(( yA + 1 ) === yF) distance++;\r\n yA++;\r\n }\r\n else{\r\n // if(( yB + 1 ) === yF) distance++;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA === xB) && (yA !== yB)){\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance+= 2;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance+= 2;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA !== xB) && (yA === yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance+=2;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance+=2;\r\n xB++;\r\n }\r\n distance++;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if((xA !== xB) && (yA !== yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance++;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance++;\r\n xB++;\r\n }\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance++;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance++;\r\n yB++;\r\n }\r\n distance+=2;\r\n }\r\n else if((xA === xB) && (yA !== yB)){\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance+= 2;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance+= 2;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA !== xB) && (yA === yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance+=2;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance+=2;\r\n xB++;\r\n }\r\n distance++;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n let blank;\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n blank = input[z++];\r\n\r\n while(testCases--){\r\n let [xA, yA] = input[z++].split(' ').map(x=>Number(x));\r\n let [xB, yB] = input[z++].split(' ').map(x=>Number(x));\r\n let [xF, yF] = input[z++].split(' ').map(x=>Number(x));\r\n blank = input[z++];\r\n \r\n let distance = 0;\r\n\r\n while((xA !== xB) || (yA !== yB)){\r\n if((xA !== xB) && (yA !== yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance++;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance++;\r\n xB++;\r\n }\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance++;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance++;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA === xB) && (yA !== yB)){\r\n if(yA < yB){\r\n if(( yA + 1 ) === yF) distance+= 2;\r\n yA++;\r\n }\r\n else{\r\n if(( yB + 1 ) === yF) distance+= 2;\r\n yB++;\r\n }\r\n distance++;\r\n }\r\n else if((xA !== xB) && (yA === yB)){\r\n if(xA < xB){\r\n if(( xA + 1 ) === xF) distance+=2;\r\n xA++;\r\n }\r\n else{\r\n if(( xB + 1 ) === xF) distance+=2;\r\n xB++;\r\n }\r\n distance++;\r\n }\r\n }\r\n console.log(distance);\r\n }\r\n}"}, {"source_code": "//function main(input) {\r\nfunction main() {\r\n var getDistance = function( sa, sb, sf ) {\r\n //console.log(\"solve is called\");\r\n //console.log(sa);\r\n //console.log(sb);\r\n //console.log(sf);\r\n print(\")\"+sa);\r\n print(\")\"+sb);\r\n print(\")\"+sf);\r\n\r\n a = sa.split(\" \").map(function(n){return parseInt(n,10);});\r\n b = sb.split(\" \").map(function(n){return parseInt(n,10);});\r\n f = sf.split(\" \").map(function(n){return parseInt(n,10);});\r\n //console.log(a);\r\n //console.log(b);\r\n //console.log(f);\r\n\r\n dist = Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);\r\n if (a[0]===b[0] && a[0]===f[0]) {\r\n if ((a[1] inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => ({ key: +v }));\n var hmin = new Heap(n + 1);\n var hmax = new Heap(n + 1, (a, b) => b - a, 'idMax');\n hmin.push(h[0]);\n hmax.push(h[0]);\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n)\n break;\n hmin.push(h[j]);\n hmax.push(h[j]);\n if (hmax.h[0].key - hmin.h[0].key > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n hmin.pop(h[i].idMin);\n hmax.pop(h[i].idMax);\n i++;\n while ((hmax.size ? hmax.h[0].key - hmin.h[0].key : 0) > k) {\n hmin.pop(h[i].idMin);\n hmax.pop(h[i].idMax);\n i++;\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass Heap {\n constructor(MAX_LENGTH = 100000, comp = (a, b) => a - b, id = 'idMin') {\n this.h = Array(MAX_LENGTH);\n this.size = 0;\n this.comp = comp;\n this.id = id;\n }\n push(node) {\n this.h[this.size] = node;\n node[this.id] = this.size;\n this.size++;\n while (true) {\n if (node[this.id] == 0)\n break;\n var parentId = (node[this.id] - 1) >> 1;\n if (this.comp(this.h[parentId].key, node.key) > 0) {\n this.h[node[this.id]] = this.h[parentId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[parentId] = node;\n node[this.id] = parentId;\n }\n else\n break;\n }\n }\n pop(id = 0) {\n var popNode = this.h[id];\n this.size--;\n this.h[id] = this.h[this.size];\n this.h[id][this.id] = id;\n var node = this.h[id];\n while (true) {\n var childId = node[this.id] * 2 + 1;\n if (childId >= this.size)\n break;\n if (childId < this.size - 1 && this.comp(this.h[childId].key, this.h[childId + 1].key) > 0)\n childId++;\n if (this.comp(this.h[childId].key, node.key) > 0)\n break;\n this.h[node[this.id]] = this.h[childId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[childId] = node;\n node[this.id] = childId;\n }\n while (true) {\n if (node[this.id] == 0)\n break;\n var parentId = (node[this.id] - 1) >> 1;\n if (this.comp(this.h[parentId].key, node.key) > 0) {\n this.h[node[this.id]] = this.h[parentId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[parentId] = node;\n node[this.id] = parentId;\n }\n else\n break;\n }\n popNode[this.id] = -1;\n return popNode;\n }\n}\n", "positive_code": [{"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var sk = new SkipList(20);\n sk.insert(h[0]);\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n sk.insert(h[j]);\n if (sk.max() - sk.min() > k) break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n sk.remove(h[i++]);\n while (sk.max() - sk.min() > k) {\n sk.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n // h.forEach(v => t.insert(v));\n // console.log(Date.now() - time);\n // return;\n t.insert(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t.insert(h[j]);\n // console.log(i, j, hk, t.print());\n if (t.key(j - i) - t.key(0) > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t.remove(h[i++]);\n while (t.key(j - i) - t.key(0) > k) {\n // console.log('NOOO', i, j, h[i]);\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - time)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var parent = undefined;\n var node = this.root;\n while (true) {\n node = this.balance(node, parent);\n if (key < node.key) {\n node.size++;\n if (!node.left)\n return node.left = new BSNode(key);\n parent = node;\n node = node.left;\n }\n else {\n node.size++;\n if (!node.right)\n return node.right = new BSNode(key);\n parent = node;\n node = node.right;\n }\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var parent = undefined;\n var node = this.root;\n while (node && node.key != key) {\n parent = node;\n node.size--;\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!parent)\n return this.root = newTree.root;\n if (parent.left == node)\n parent.left = newTree.root;\n else\n parent.right = newTree.root;\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "class Node {\n left; right; key; min; max;\n constructor(key) {\n this.key = key;\n this.min = key;\n this.max = key;\n }\n update() {\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : -1e10, this.right ? this.right.max : -1e10);\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `${this.key},${this.min},${this.max}` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push[cur.left = new Node(key)];\n else trace.push[cur.right = new Node(key)];\n cur.update();\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n min() {\n return this.root ? this.root.min : undefined;\n }\n\n max() {\n return this.root ? this.root.max : undefined;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}\n\n// var t = new SplayTree();\n// var arr = Array(10).fill(0).map(v => Math.random() * 100 | 0);\n// arr.forEach(v => {\n// t.insert(v);\n// t.print();\n// });\n// console.log('---');\n// arr.forEach(v => {\n// t.remove(v);\n// t.print();\n// })\n\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inp = input.split(/\\D+/m).map(v => +v), r = 0;\n var n = inp[r++], k = inp[r++];\n var h = inp.slice(r, r = r + n);\n var t = new SplayTree();\n t.insert(h[0]);\n var max = 1, i = j = 0;\n var allRes = [];\n // console.log(n,k,h);\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n t.insert(h[j]);\n if (t.max() - t.min() > k) break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n t.remove(h[i++]);\n while (t.max() - t.min() > k) {\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), k = $(), h = $(n), t = new SplayTree();\n t.insert(h[0]);\n var maxRes = 1, i = j = 0;\n var allRes = [];\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n t.insert(h[j]);\n if (t.max() - t.min() > k) break;\n }\n if (maxRes < j - i) {\n maxRes = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (maxRes == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n t.remove(h[i++]);\n while (t.max() - t.min() > k) {\n t.remove(h[i++]);\n }\n }\n log(maxRes, allRes.length);\n log(allRes.join('\\n'));\n}\n\nclass Node {\n left; right; key; max; min;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n } else {\n this.max = this.key;\n this.min = this.key;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n }\n\n max() {\n return this.root ? this.root.max : 0;\n }\n\n min() {\n return this.root ? this.root.min : 0;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "/**\n * 10.12 night\n * https://codeforces.com/problemset/problem/6/E\n *\n * reference:\n * https://codeforces.com/problemset/status/6/problem/E/page/46?order=BY_PROGRAM_LENGTH_ASC\n * https://codeforces.com/problemset/submission/6/94367599\n */\n\nfunction For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () {\n return Object.keys(this)\n }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () {\n return Object.values(this)\n }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () {\n return Object.entries(this)\n }\n});\nArray.prototype.sum = function (fn) {\n return this.reduce((p, v) => p + (fn ? fn(v) : v), 0)\n};\nArray.prototype.uniq = function (fn) {\n let set = new Set();\n return this.filter(v => {\n let newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n};\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) {\n min = x;\n index = i\n }\n }\n return [this[index], index, min];\n};\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) {\n max = x;\n index = i\n }\n }\n return [this[index], index, max];\n};\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n};\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n};\nArray.prototype.for = function (a, b, fn) {\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n};\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n};\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\n\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\n\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\n\nlet MOD = 998244353;\n\nfunction inv(b) {\n for (let a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\n\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max,\n abs = Math.abs;\n\n let [n, k] = $(2), h = $(n), tree = new AVLTree();\n tree.insert(h[0]);\n let Max = 1;\n let allRes = [];\n let i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j]) break;\n tree.insert(h[j]);\n if (tree.max() - tree.min() > k) break;\n }\n if (Max < j - i) {\n Max = j - i;\n allRes = [(i + 1) + ' ' + j];\n } else if (Max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n Max = max(j - i, Max);\n tree.remove(h[i++]);\n while (tree.max() - tree.min() > k) {\n tree.remove(h[i++]);\n }\n }\n log(Max, allRes.length);\n log(allRes.join('\\n'));\n}\n\n\n\nlet AVLTree = (function () {\n function print(root, printNode) {\n if (printNode === void 0) printNode = function (n) {\n return n.key;\n };\n\n let out = [];\n row(root, '', true, function (v) {\n return out.push(v);\n }, printNode);\n return out.join('');\n }\n\n function isBalanced(root) {\n if (root === null) {\n return true;\n }\n let lh = height(root.left);\n let rh = height(root.right);\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) {\n return true;\n }\n return false;\n }\n\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n function loadRecursive(parent, keys, values, start, end) {\n let size = end - start;\n if (size > 0) {\n let middle = start + Math.floor(size / 2);\n let key = keys[middle];\n let data = values[middle];\n let node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n function markBalance(node) {\n if (node === null) {\n return 0;\n }\n let lh = markBalance(node.left);\n let rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) {\n return;\n }\n let pivot = keys[(left + right) >> 1];\n let i = left - 1;\n let j = right + 1;\n while (true) {\n do {\n i++;\n } while (compare(keys[i], pivot) < 0);\n do {\n j--;\n } while (compare(keys[j], pivot) > 0);\n if (i >= j) {\n break;\n }\n let tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n function DEFAULT_COMPARE(a, b) {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n\n function rotateLeft(node) {\n let rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) {\n rightNode.left.parent = node;\n }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n function rotateRight(node) {\n let leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) {\n node.left.parent = node;\n }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n let AVLTree = function AVLTree(comparator, noDuplicates) {\n if (noDuplicates === void 0) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n let prototypeAccessors = { size: { configurable: true } };\n\n AVLTree.prototype.destroy = function destroy() {\n return this.clear();\n };\n\n AVLTree.prototype.clear = function clear() {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n AVLTree.prototype.contains = function contains(key) {\n if (this._root) {\n let node = this._root;\n let comparator = this._comparator;\n while (node) {\n let cmp = comparator(key, node.key);\n if (cmp === 0) {\n return true;\n } else if (cmp < 0) {\n node = node.left;\n } else {\n node = node.right;\n }\n }\n }\n return false;\n };\n\n AVLTree.prototype.next = function next(node) {\n let successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) {\n successor = successor.left;\n }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor;\n successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n AVLTree.prototype.prev = function prev(node) {\n let predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) {\n predecessor = predecessor.right;\n }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n\n\n AVLTree.prototype.forEach = function forEach(callback) {\n let current = this._root;\n let s = [], done = false, i = 0;\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n current = current.right;\n } else {\n done = true;\n }\n }\n }\n return this;\n };\n\n AVLTree.prototype.range = function range(low, high, fn, ctx) {\n let this$1 = this;\n let Q = [];\n let compare = this._comparator;\n let node = this._root, cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) {\n return this$1;\n }\n }\n node = node.right;\n }\n }\n return this;\n };\n\n AVLTree.prototype.keys = function keys() {\n let current = this._root;\n let s = [], r = [], done = false;\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else {\n done = true;\n }\n }\n }\n return r;\n };\n\n AVLTree.prototype.values = function values() {\n let current = this._root;\n let s = [], r = [], done = false;\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else {\n done = true;\n }\n }\n }\n return r;\n };\n\n AVLTree.prototype.at = function at(index) {\n let current = this._root;\n let s = [], done = false, i = 0;\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) {\n return current;\n }\n i++;\n current = current.right;\n } else {\n done = true;\n }\n }\n }\n return null;\n };\n\n AVLTree.prototype.minNode = function minNode() {\n let node = this._root;\n if (!node) {\n return null;\n }\n while (node.left) {\n node = node.left;\n }\n return node;\n };\n\n AVLTree.prototype.maxNode = function maxNode() {\n let node = this._root;\n if (!node) {\n return null;\n }\n while (node.right) {\n node = node.right;\n }\n return node;\n };\n\n AVLTree.prototype.min = function min() {\n let node = this._root;\n if (!node) {\n return null;\n }\n while (node.left) {\n node = node.left;\n }\n return node.key;\n };\n\n AVLTree.prototype.max = function max() {\n let node = this._root;\n if (!node) {\n return null;\n }\n while (node.right) {\n node = node.right;\n }\n return node.key;\n };\n\n AVLTree.prototype.isEmpty = function isEmpty() {\n return !this._root;\n };\n\n AVLTree.prototype.pop = function pop() {\n let node = this._root, returnValue = null;\n if (node) {\n while (node.left) {\n node = node.left;\n }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n AVLTree.prototype.find = function find(key) {\n let root = this._root;\n let subtree = root, cmp;\n let compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) {\n return subtree;\n } else if (cmp < 0) {\n subtree = subtree.left;\n } else {\n subtree = subtree.right;\n }\n }\n\n return null;\n };\n\n AVLTree.prototype.insert = function insert(key, data) {\n let this$1 = this;\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n let compare = this._comparator;\n let node = this._root;\n let parent = null;\n let cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) {\n return null;\n } else if (cmp < 0) {\n node = node.left;\n } else {\n node = node.right;\n }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0) {\n node = node.left;\n } //return null;\n else {\n node = node.right;\n }\n }\n }\n\n let newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n let newRoot;\n if (cmp <= 0) {\n parent.left = newNode;\n } else {\n parent.right = newNode;\n }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) {\n parent.balanceFactor -= 1;\n } else {\n parent.balanceFactor += 1;\n }\n\n if (parent.balanceFactor === 0) {\n break;\n } else if (parent.balanceFactor < -1) {\n if (parent.right.balanceFactor === 1) {\n rotateRight(parent.right);\n }\n newRoot = rotateLeft(parent);\n if (parent === this$1._root) {\n this$1._root = newRoot;\n }\n break;\n } else if (parent.balanceFactor > 1) {\n if (parent.left.balanceFactor === -1) {\n rotateLeft(parent.left);\n }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) {\n this$1._root = newRoot;\n }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n AVLTree.prototype.remove = function remove(key) {\n let this$1 = this;\n if (!this._root) {\n return null;\n }\n let node = this._root;\n let compare = this._comparator;\n let cmp = 0;\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) {\n break;\n } else if (cmp < 0) {\n node = node.left;\n } else {\n node = node.right;\n }\n }\n if (!node) {\n return null;\n }\n\n let returnValue = node.key;\n let max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) {\n max = max.right;\n }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key = max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) {\n min = min.left;\n }\n\n node.key = min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key = min.key;\n node.data = min.data;\n node = min;\n }\n\n let parent = node.parent;\n let pp = node;\n let newRoot;\n\n while (parent) {\n if (parent.left === pp) {\n parent.balanceFactor -= 1;\n } else {\n parent.balanceFactor += 1;\n }\n\n if (parent.balanceFactor < -1) {\n if (parent.right.balanceFactor === 1) {\n rotateRight(parent.right);\n }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) {\n this$1._root = newRoot;\n }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n if (parent.left.balanceFactor === -1) {\n rotateLeft(parent.left);\n }\n newRoot = rotateRight(parent);\n if (parent === this$1._root) {\n this$1._root = newRoot;\n }\n parent = newRoot;\n }\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) {\n break;\n }\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) {\n node.parent.left = null;\n } else {\n node.parent.right = null;\n }\n }\n\n if (node === this._root) {\n this._root = null;\n }\n\n this._size--;\n return returnValue;\n };\n\n AVLTree.prototype.load = function load(keys, values, presort) {\n if (keys === void 0) keys = [];\n if (values === void 0) values = [];\n\n if (this._size !== 0) {\n throw new Error('bulk-load: tree is not empty');\n }\n let size = keys.length;\n if (presort) {\n sort(keys, values, 0, size - 1, this._comparator);\n }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n AVLTree.prototype.isBalanced = function isBalanced$1() {\n return isBalanced(this._root);\n };\n\n AVLTree.prototype.toString = function toString(printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties(AVLTree.prototype, prototypeAccessors);\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})();\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.insert(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t.insert(h[j]);\n // console.log(i, j, hk, t.print());\n if (t.key(j - i) - t.key(0) > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t.remove(h[i++]);\n while (t.key(j - i) - t.key(0) > k) {\n // console.log('NOOO', i, j, h[i]);\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - time)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var parent = undefined;\n var node = this.root;\n while (true) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n node = left;\n continue;\n }\n if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n node = right;\n continue;\n }\n if (key < node.key) {\n node.size++;\n if (!left)\n return node.left = new BSNode(key);\n parent = node;\n node = left;\n }\n else {\n node.size++;\n if (!right)\n return node.right = new BSNode(key);\n parent = node;\n node = right;\n }\n }\n }\n remove(key) {\n var parent = undefined;\n var node = this.root;\n while (node && node.key != key) {\n parent = node;\n node.size--;\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var right = node.right;\n if (!right) {\n if (!parent) {\n this.root = node.left;\n }\n else {\n if (parent.left == node)\n parent.left = node.left;\n else\n parent.right = node.left;\n }\n return;\n }\n var rightParent = node;\n while (right && right.left) {\n rightParent = right;\n right.size--;\n right = right.left;\n }\n node.key = right.key;\n if (rightParent.left == right)\n rightParent.left = right.right;\n else\n rightParent.right = right.right;\n node.size--;\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n\n let [n, k] = $(2), h = $(n), tree = new AVLTree();\n tree.insert(h[0]);\n var Max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j]) break;\n tree.insert(h[j]);\n if (tree.max() - tree.min() > k) break;\n }\n if (Max < j - i) {\n Max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (Max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n Max = max(j - i, Max);\n tree.remove(h[i++]);\n while (tree.max() - tree.min() > k) {\n tree.remove(h[i++]);\n }\n }\n log(Max, allRes.length);\n log(allRes.join('\\n'));\n}\n\nvar AVLTree = (function () {\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print(root, printNode) {\n if (printNode === void 0) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive(parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE(a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft(node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight(node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree(comparator, noDuplicates) {\n if (noDuplicates === void 0) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy() {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear() {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains(key) {\n if (this._root) {\n var node = this._root;\n var comparator = this._comparator;\n while (node) {\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next(node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev(node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach(callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range(low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys() {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values() {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at(index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode() {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode() {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min() {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max() {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty() {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop() {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find(key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert(key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent = null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0) { node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left = newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove(key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key = max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key = min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key = min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left = null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load(keys, values, presort) {\n if (keys === void 0) keys = [];\n if (values === void 0) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1() {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString(printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties(AVLTree.prototype, prototypeAccessors);\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})();"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var t = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var tree = new AVLTree();\n tree.insert(h[0]);\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n tree.insert(h[j]);\n if (tree.max() - tree.min() > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n max = Math.max(j - i, max);\n tree.remove(h[i++]);\n while (tree.max() - tree.min() > k) {\n tree.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - t)\n})();\nvar AVLTree = eval(`\n(function () { 'use strict';\n\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print (root, printNode) {\n if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive (parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft (node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight (node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree (comparator, noDuplicates) {\n if ( noDuplicates === void 0 ) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy () {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear () {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains (key) {\n if (this._root){\n var node = this._root;\n var comparator = this._comparator;\n while (node){\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next (node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev (node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach (callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range (low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at (index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty () {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop () {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find (key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert (key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent= null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0){ node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left= newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove (key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key= max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key= min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key= min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left= null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load (keys, values, presort) {\n if ( keys === void 0 ) keys = [];\n if ( values === void 0 ) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1 () {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString (printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})()\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n // h.forEach(v => t.insert(v));\n // console.log(Date.now() - time);\n // return;\n t.insert(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t.insert(h[j]);\n // console.log(i, j, hk, t.print());\n if (t.key(j - i) - t.key(0) > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t.remove(h[i++]);\n while (t.key(j - i) - t.key(0) > k) {\n // console.log('NOOO', i, j, h[i]);\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - time)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return left;\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return right;\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var parent = undefined;\n var node = this.root;\n while (true) {\n node = this.balance(node, parent);\n if (key < node.key) {\n node.size++;\n if (!node.left)\n return node.left = new BSNode(key);\n parent = node;\n node = node.left;\n }\n else {\n node.size++;\n if (!node.right)\n return node.right = new BSNode(key);\n parent = node;\n node = node.right;\n }\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n }\n remove(key) {\n var parent = undefined;\n var node = this.root;\n while (node && node.key != key) {\n node = this.balance(node, parent);\n if (node.key == key)\n break;\n parent = node;\n node.size--;\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!parent)\n return this.root = newTree.root;\n if (parent.left == node)\n parent.left = newTree.root;\n else\n parent.right = newTree.root;\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n }\n\n remove(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var sk = new SkipList(20);\n sk.insert(h[0]);\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n sk.insert(h[j]);\n if (sk.max() - sk.min() > k) break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n sk.remove(h[i++]);\n while (sk.max() - sk.min() > k) {\n sk.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), k = $(), h = $(n);\n\n let m = {}, d = 0;\n h.slice().sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);\n let n2 = 1 << Math.ceil(Math.log2(n));\n let it = Arr(n2 * 2, i => ({ max: 0, min: 1e10, c: 0 }))\n let update = i => {\n let l = it[i << 1], r = it[i << 1 | 1];\n it[i] = {\n max: max(l.max, r.max),\n min: min(l.min, r.min),\n c: l.c + r.c\n }\n }\n let set = (i, v, c) => {\n i = n2 + i - 1;\n it[i].c += c;\n if (it[i].c <= 0) { it[i].max = 0; it[i].min = 1e10 }\n else { it[i].max = v; it[i].min = v }\n while (i > 1) update(i >>= 1);\n }\n\n set(m[h[0]], h[0], 1);\n var maxRes = 1, i = j = 0;\n var allRes = [];\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n set(m[h[j]], h[j], 1);\n if (it[1].max - it[1].min > k) break;\n }\n if (maxRes < j - i) {\n maxRes = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (maxRes == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n set(m[h[i]], h[i++], -1);\n while (it[1].max - it[1].min > k) {\n set(m[h[i]], h[i++], -1);\n }\n }\n log(maxRes, allRes.length);\n log(allRes.join('\\n'));\n}\n\nclass Node {\n left; right; key; max; min;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n } else {\n this.max = this.key;\n this.min = this.key;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n }\n\n max() {\n return this.root ? this.root.max : 0;\n }\n\n min() {\n return this.root ? this.root.min : 0;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), k = $(), h = $(n);\n\n let m = {}, d = 0;\n h.slice().sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);\n let n2 = 1 << Math.ceil(Math.log2(n));\n let it = Array(n2 * 2);\n For(1, n2 + n2 - 1, i => { it[i] = { max: 0, min: 1e10, c: 0 } })\n \n let update = i => {\n let l = it[i << 1], r = it[i << 1 | 1];\n it[i] = {\n max: max(l.max, r.max),\n min: min(l.min, r.min),\n c: l.c + r.c\n }\n }\n let set = (i, v, c) => {\n i = n2 + i - 1;\n it[i].c += c;\n if (it[i].c <= 0) { it[i].max = 0; it[i].min = 1e10 }\n else { it[i].max = v; it[i].min = v }\n while (i > 1) update(i >>= 1);\n }\n\n set(m[h[0]], h[0], 1);\n var maxRes = 1, i = j = 0;\n var allRes = [];\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n set(m[h[j]], h[j], 1);\n if (it[1].max - it[1].min > k) break;\n }\n if (maxRes < j - i) {\n maxRes = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (maxRes == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n set(m[h[i]], h[i++], -1);\n while (it[1].max - it[1].min > k) {\n set(m[h[i]], h[i++], -1);\n }\n }\n log(maxRes, allRes.length);\n log(allRes.join('\\n'));\n}\n\nclass Node {\n left; right; key; max; min;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n } else {\n this.max = this.key;\n this.min = this.key;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n }\n\n max() {\n return this.root ? this.root.max : 0;\n }\n\n min() {\n return this.root ? this.root.min : 0;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), k = $(), h = $(n);\n\n let m = {}, d = 0;\n h.sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);\n let n2 = 1 << Math.ceil(Math.log2(n));\n let it = Array(n2 * 2);\n For(1, n2 + n2 - 1, i => { it[i] = { max: 0, min: 1e10, c: 0 } })\n \n let update = i => {\n let l = it[i << 1], r = it[i << 1 | 1];\n it[i] = {\n max: max(l.max, r.max),\n min: min(l.min, r.min),\n c: l.c + r.c\n }\n }\n let set = (i, v, c) => {\n i = n2 + i - 1;\n it[i].c += c;\n if (it[i].c <= 0) { it[i].max = 0; it[i].min = 1e10 }\n else { it[i].max = v; it[i].min = v }\n while (i > 1) update(i >>= 1);\n }\n\n set(m[h[0]], h[0], 1);\n var maxRes = 1, i = j = 0;\n var allRes = [];\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n set(m[h[j]], h[j], 1);\n if (it[1].max - it[1].min > k) break;\n }\n if (maxRes < j - i) {\n maxRes = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (maxRes == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n set(m[h[i]], h[i++], -1);\n while (it[1].max - it[1].min > k) {\n set(m[h[i]], h[i++], -1);\n }\n }\n log(maxRes, allRes.length);\n log(allRes.join('\\n'));\n}\n\nclass Node {\n left; right; key; max; min;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n } else {\n this.max = this.key;\n this.min = this.key;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n }\n\n max() {\n return this.root ? this.root.max : 0;\n }\n\n min() {\n return this.root ? this.root.min : 0;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var _a, _b, _c, _d;\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.insert(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t.insert(h[j]);\n // console.log(i, j, hk, t.print());\n if ((((_a = t.at(j - i)) === null || _a === void 0 ? void 0 : _a.key) || 0) - (((_b = t.at(0)) === null || _b === void 0 ? void 0 : _b.key) || 0) > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t.remove(h[i++]);\n while (t.root && (((_c = t.at(j - i)) === null || _c === void 0 ? void 0 : _c.key) || 0) - (((_d = t.at(0)) === null || _d === void 0 ? void 0 : _d.key) || 0) > k) {\n // console.log('NOOO', i, j, h[i]);\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - time)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass SPnode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n let parent = this.parent;\n let grand = parent.parent;\n this.parent = grand;\n if (grand) {\n if (grand.left == parent)\n grand.left = this;\n else\n grand.right = this;\n }\n parent.parent = this;\n parent.left = this.right;\n if (this.right)\n this.right.parent = parent;\n this.right = parent;\n parent.update();\n this.update();\n }\n rotateLeft() {\n let parent = this.parent;\n let grand = parent.parent;\n this.parent = grand;\n if (grand) {\n if (grand.left == parent)\n grand.left = this;\n else\n grand.right = this;\n }\n parent.parent = this;\n parent.right = this.left;\n if (this.left)\n this.left.parent = parent;\n this.left = parent;\n parent.update();\n this.update();\n }\n splay() {\n while (true) {\n let parent = this.parent;\n if (!parent)\n return;\n let grand = parent.parent;\n if (!grand) {\n if (parent.left == this)\n this.rotateRight();\n else\n this.rotateLeft();\n return;\n }\n if (grand.left == parent && parent.left == this) {\n parent.rotateRight();\n this.rotateRight();\n }\n else if (grand.right == parent && parent.right == this) {\n parent.rotateLeft();\n this.rotateLeft();\n }\n else if (grand.left == parent) {\n this.rotateLeft();\n this.rotateRight();\n }\n else {\n this.rotateRight();\n this.rotateLeft();\n }\n }\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var parent = undefined;\n var node = this.root;\n while (true) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n node = left;\n continue;\n }\n if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n node = right;\n continue;\n }\n if (key < node.key) {\n node.size++;\n if (!left)\n return node.left = new BSNode(key);\n node = left;\n }\n else {\n node.size++;\n if (!right)\n return node.right = new BSNode(key);\n node = right;\n }\n }\n }\n remove(key) {\n var parent = undefined;\n var node = this.root;\n while (node && node.key != key) {\n parent = node;\n node.size--;\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var right = node.right;\n if (!right) {\n if (!parent) {\n this.root = node.left;\n }\n else {\n if (parent.left == node)\n parent.left = node.left;\n else\n parent.right = node.left;\n }\n return;\n }\n var rightParent = node;\n while (right && right.left) {\n rightParent = right;\n right.size--;\n right = right.left;\n }\n node.key = right.key;\n if (rightParent.left == right)\n rightParent.left = right.right;\n else\n rightParent.right = right.right;\n node.size--;\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var t = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var tree = new SplayTree();\n tree.insert(h[0]);\n var max = 1;\n var allRes = ['1 1'];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n tree.insert(h[j]);\n if (tree.max() - tree.min() > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n max = Math.max(j - i, max);\n tree.remove(h[i++]);\n while (tree.max() - tree.min() > k) {\n tree.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - t)\n})();\nvar SplayTree = eval(`\n(function () {\n var Node = /** @class */ (function () {\n function Node(key, data) {\n this.next = null;\n this.key = key;\n this.data = data;\n this.left = null;\n this.right = null;\n }\n return Node;\n }());\n\n /* follows \"An implementation of top-down splaying\"\n * by D. Sleator March 1992\n */\n function DEFAULT_COMPARE(a, b) {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n /**\n * Simple top down splay, not requiring i to be in the tree t.\n */\n function splay(i, t, comparator) {\n var N = new Node(null, null);\n var l = N;\n var r = N;\n while (true) {\n var cmp = comparator(i, t.key);\n //if (i < t.key) {\n if (cmp < 0) {\n if (t.left === null)\n break;\n //if (i < t.left.key) {\n if (comparator(i, t.left.key) < 0) {\n var y = t.left; /* rotate right */\n t.left = y.right;\n y.right = t;\n t = y;\n if (t.left === null)\n break;\n }\n r.left = t; /* link right */\n r = t;\n t = t.left;\n //} else if (i > t.key) {\n }\n else if (cmp > 0) {\n if (t.right === null)\n break;\n //if (i > t.right.key) {\n if (comparator(i, t.right.key) > 0) {\n var y = t.right; /* rotate left */\n t.right = y.left;\n y.left = t;\n t = y;\n if (t.right === null)\n break;\n }\n l.right = t; /* link left */\n l = t;\n t = t.right;\n }\n else\n break;\n }\n /* assemble */\n l.right = t.left;\n r.left = t.right;\n t.left = N.right;\n t.right = N.left;\n return t;\n }\n function insert(i, data, t, comparator) {\n var node = new Node(i, data);\n if (t === null) {\n node.left = node.right = null;\n return node;\n }\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp >= 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n return node;\n }\n function split(key, v, comparator) {\n var left = null;\n var right = null;\n if (v) {\n v = splay(key, v, comparator);\n var cmp = comparator(v.key, key);\n if (cmp === 0) {\n left = v.left;\n right = v.right;\n }\n else if (cmp < 0) {\n right = v.right;\n v.right = null;\n left = v;\n }\n else {\n left = v.left;\n v.left = null;\n right = v;\n }\n }\n return { left: left, right: right };\n }\n function merge(left, right, comparator) {\n if (right === null)\n return left;\n if (left === null)\n return right;\n right = splay(left.key, right, comparator);\n right.left = left;\n return right;\n }\n var Tree = /** @class */ (function () {\n function Tree(comparator) {\n if (comparator === void 0) { comparator = DEFAULT_COMPARE; }\n this._root = null;\n this._size = 0;\n this._comparator = comparator;\n }\n /**\n * Inserts a key, allows duplicates\n */\n Tree.prototype.insert = function (key, data) {\n this._size++;\n return this._root = insert(key, data, this._root, this._comparator);\n };\n /**\n * Adds a key, if it is not present in the tree\n */\n Tree.prototype.add = function (key, data) {\n var node = new Node(key, data);\n if (this._root === null) {\n node.left = node.right = null;\n this._size++;\n this._root = node;\n }\n var comparator = this._comparator;\n var t = splay(key, this._root, comparator);\n var cmp = comparator(key, t.key);\n if (cmp === 0)\n this._root = t;\n else {\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp > 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n this._size++;\n this._root = node;\n }\n return this._root;\n };\n /**\n * @param {Key} key\n * @return {Node|null}\n */\n Tree.prototype.remove = function (key) {\n this._root = this._remove(key, this._root, this._comparator);\n };\n /**\n * Deletes i from the tree if it's there\n */\n Tree.prototype._remove = function (i, t, comparator) {\n var x;\n if (t === null)\n return null;\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp === 0) { /* found it */\n if (t.left === null) {\n x = t.right;\n }\n else {\n x = splay(i, t.left, comparator);\n x.right = t.right;\n }\n this._size--;\n return x;\n }\n return t; /* It wasn't there */\n };\n /**\n * Removes and returns the node with smallest key\n */\n Tree.prototype.pop = function () {\n var node = this._root;\n if (node) {\n while (node.left)\n node = node.left;\n this._root = splay(node.key, this._root, this._comparator);\n this._root = this._remove(node.key, this._root, this._comparator);\n return { key: node.key, data: node.data };\n }\n return null;\n };\n /**\n * Find without splaying\n */\n Tree.prototype.findStatic = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return current;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return null;\n };\n Tree.prototype.find = function (key) {\n if (this._root) {\n this._root = splay(key, this._root, this._comparator);\n if (this._comparator(key, this._root.key) !== 0)\n return null;\n }\n return this._root;\n };\n Tree.prototype.contains = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return true;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return false;\n };\n Tree.prototype.forEach = function (visitor, ctx) {\n var current = this._root;\n var Q = []; /* Initialize stack s */\n var done = false;\n while (!done) {\n if (current !== null) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length !== 0) {\n current = Q.pop();\n visitor.call(ctx, current);\n current = current.right;\n }\n else\n done = true;\n }\n }\n return this;\n };\n\n Tree.prototype.range = function (low, high, fn, ctx) {\n var Q = [];\n var compare = this._comparator;\n var node = this._root;\n var cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n }\n else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n }\n else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node))\n return this; // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n /**\n * Returns array of keys\n */\n Tree.prototype.keys = function () {\n var keys = [];\n this.forEach(function (_a) {\n var key = _a.key;\n return keys.push(key);\n });\n return keys;\n };\n /**\n * Returns array of all the data in the nodes\n */\n Tree.prototype.values = function () {\n var values = [];\n this.forEach(function (_a) {\n var data = _a.data;\n return values.push(data);\n });\n return values;\n };\n Tree.prototype.min = function () {\n if (this._root)\n return this.minNode(this._root).key;\n return null;\n };\n Tree.prototype.max = function () {\n if (this._root)\n return this.maxNode(this._root).key;\n return null;\n };\n Tree.prototype.minNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.left)\n t = t.left;\n return t;\n };\n Tree.prototype.maxNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.right)\n t = t.right;\n return t;\n };\n /**\n * Returns node at given index\n */\n Tree.prototype.at = function (index) {\n var current = this._root;\n var done = false;\n var i = 0;\n var Q = [];\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = Q.pop();\n if (i === index)\n return current;\n i++;\n current = current.right;\n }\n else\n done = true;\n }\n }\n return null;\n };\n Tree.prototype.next = function (d) {\n var root = this._root;\n var successor = null;\n if (d.right) {\n successor = d.right;\n while (successor.left)\n successor = successor.left;\n return successor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0) {\n successor = root;\n root = root.left;\n }\n else\n root = root.right;\n }\n return successor;\n };\n Tree.prototype.prev = function (d) {\n var root = this._root;\n var predecessor = null;\n if (d.left !== null) {\n predecessor = d.left;\n while (predecessor.right)\n predecessor = predecessor.right;\n return predecessor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n root = root.left;\n else {\n predecessor = root;\n root = root.right;\n }\n }\n return predecessor;\n };\n Tree.prototype.clear = function () {\n this._root = null;\n this._size = 0;\n return this;\n };\n Tree.prototype.toList = function () {\n return toList(this._root);\n };\n /**\n * Bulk-load items. Both array have to be same size\n */\n Tree.prototype.load = function (keys, values, presort) {\n if (values === void 0) { values = []; }\n if (presort === void 0) { presort = false; }\n var size = keys.length;\n var comparator = this._comparator;\n // sort if needed\n if (presort)\n sort(keys, values, 0, size - 1, comparator);\n if (this._root === null) { // empty tree\n this._root = loadRecursive(keys, values, 0, size);\n this._size = size;\n }\n else { // that re-builds the whole tree from two in-order traversals\n var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);\n size = this._size + size;\n this._root = sortedListToBST({ head: mergedList }, 0, size);\n }\n return this;\n };\n Tree.prototype.isEmpty = function () { return this._root === null; };\n Object.defineProperty(Tree.prototype, \"size\", {\n get: function () { return this._size; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Tree.prototype, \"root\", {\n get: function () { return this._root; },\n enumerable: true,\n configurable: true\n });\n Tree.prototype.toString = function (printNode) {\n if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }\n var out = [];\n printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n };\n Tree.prototype.update = function (key, newKey, newData) {\n var comparator = this._comparator;\n var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;\n if (comparator(key, newKey) < 0) {\n right = insert(newKey, newData, right, comparator);\n }\n else {\n left = insert(newKey, newData, left, comparator);\n }\n this._root = merge(left, right, comparator);\n };\n Tree.prototype.split = function (key) {\n return split(key, this._root, this._comparator);\n };\n return Tree;\n }());\n function loadRecursive(keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = new Node(key, data);\n node.left = loadRecursive(keys, values, start, middle);\n node.right = loadRecursive(keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n function createList(keys, values) {\n var head = new Node(null, null);\n var p = head;\n for (var i = 0; i < keys.length; i++) {\n p = p.next = new Node(keys[i], values[i]);\n }\n p.next = null;\n return head.next;\n }\n function toList(root) {\n var current = root;\n var Q = [];\n var done = false;\n var head = new Node(null, null);\n var p = head;\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = p = p.next = Q.pop();\n current = current.right;\n }\n else\n done = true;\n }\n }\n p.next = null; // that'll work even if the tree was empty\n return head.next;\n }\n function sortedListToBST(list, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var left = sortedListToBST(list, start, middle);\n var root = list.head;\n root.left = left;\n list.head = list.head.next;\n root.right = sortedListToBST(list, middle + 1, end);\n return root;\n }\n return null;\n }\n function mergeLists(l1, l2, compare) {\n var head = new Node(null, null); // dummy\n var p = head;\n var p1 = l1;\n var p2 = l2;\n while (p1 !== null && p2 !== null) {\n if (compare(p1.key, p2.key) < 0) {\n p.next = p1;\n p1 = p1.next;\n }\n else {\n p.next = p2;\n p2 = p2.next;\n }\n p = p.next;\n }\n if (p1 !== null) {\n p.next = p1;\n }\n else if (p2 !== null) {\n p.next = p2;\n }\n return head.next;\n }\n function sort(keys, values, left, right, compare) {\n if (left >= right)\n return;\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n while (true) {\n do\n i++;\n while (compare(keys[i], pivot) < 0);\n do\n j--;\n while (compare(keys[j], pivot) > 0);\n if (i >= j)\n break;\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n return Tree;\n\n})();\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new SPnode(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0, hk = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t = t.insert(h[j]);\n hk = (t = t.at(j - i)).key - (t = t.at(0)).key;\n // console.log(i, j, hk, t.print());\n if (hk > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t = t.remove(h[i++]);\n while (t && (t = t.at(j - i)).key - (t = t.at(0)).key > k) {\n // console.log('NOOO', i, j, h[i]);\n t = t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n console.log(Date.now() - time);\n})();\nclass SPnode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n let parent = this.parent;\n let grand = parent.parent;\n this.parent = grand;\n if (grand) {\n if (grand.left == parent)\n grand.left = this;\n else\n grand.right = this;\n }\n parent.parent = this;\n parent.left = this.right;\n if (this.right)\n this.right.parent = parent;\n this.right = parent;\n parent.update();\n this.update();\n }\n rotateLeft() {\n let parent = this.parent;\n let grand = parent.parent;\n this.parent = grand;\n if (grand) {\n if (grand.left == parent)\n grand.left = this;\n else\n grand.right = this;\n }\n parent.parent = this;\n parent.right = this.left;\n if (this.left)\n this.left.parent = parent;\n this.left = parent;\n parent.update();\n this.update();\n }\n splay() {\n while (true) {\n let parent = this.parent;\n if (!parent)\n return;\n let grand = parent.parent;\n if (!grand) {\n if (parent.left == this)\n this.rotateRight();\n else\n this.rotateLeft();\n return;\n }\n if (grand.left == parent && parent.left == this) {\n parent.rotateRight();\n this.rotateRight();\n }\n else if (grand.right == parent && parent.right == this) {\n parent.rotateLeft();\n this.rotateLeft();\n }\n else if (grand.left == parent) {\n this.rotateLeft();\n this.rotateRight();\n }\n else {\n this.rotateRight();\n this.rotateLeft();\n }\n }\n }\n join(nodeRight) {\n var node = this;\n while (node.right)\n node = node.right;\n node.splay();\n node.right = nodeRight;\n if (nodeRight)\n nodeRight.parent = node;\n node.update();\n return node;\n }\n split() {\n var rightNode = this.right;\n if (rightNode)\n rightNode.parent = undefined;\n this.right = undefined;\n this.update();\n return [this, rightNode];\n }\n at(index, splay = false) {\n var node = this;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index) {\n if (splay)\n node.splay();\n return node;\n }\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return this;\n }\n insert(key) {\n var node = this;\n while (true) {\n if (key < node.key) {\n if (node.left)\n node = node.left;\n else {\n let newNode = new SPnode(key);\n newNode.parent = node;\n node.left = newNode;\n newNode.splay();\n return newNode;\n }\n }\n else {\n if (node.right)\n node = node.right;\n else {\n let newNode = new SPnode(key);\n newNode.parent = node;\n node.right = newNode;\n newNode.splay();\n return newNode;\n }\n }\n }\n }\n remove(key) {\n var node = this;\n while (node && node.key != key) {\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return this;\n node.splay();\n var nodeLeft = node.left;\n var nodeRight = node.right;\n if (nodeLeft)\n nodeLeft.parent = undefined;\n if (nodeRight)\n nodeRight.parent = undefined;\n if (!nodeLeft)\n return nodeRight;\n return nodeLeft.join(nodeRight);\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => ({ key: +v }));\n var hmin = new Heap(n + 1);\n var hmax = new Heap(n + 1, (a, b) => b - a, 'idMax');\n hmin.push(h[0]);\n hmax.push(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n)\n break;\n hmin.push(h[j]);\n hmax.push(h[j]);\n if (hmax.h[0].key - hmin.h[0].key > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n hmin.pop(h[i].idMin);\n hmax.pop(h[i].idMax);\n i++;\n while (hmax.size && hmax.h[0].key - hmin.h[0].key > k) {\n // console.log('NOOO', i, j, h[i]);\n hmin.pop(h[i].idMin);\n hmax.pop(h[i].idMax);\n i++;\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass Heap {\n constructor(MAX_LENGTH = 100000, comp = (a, b) => a - b, id = 'idMin') {\n this.h = Array(MAX_LENGTH);\n this.size = 0;\n this.comp = comp;\n this.id = id;\n }\n push(node) {\n this.h[this.size] = node;\n node[this.id] = this.size;\n this.size++;\n while (true) {\n if (node[this.id] == 0)\n break;\n var parentId = (node[this.id] - 1) >> 1;\n if (this.comp(this.h[parentId].key, node.key) > 0) {\n this.h[node[this.id]] = this.h[parentId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[parentId] = node;\n node[this.id] = parentId;\n }\n else\n break;\n }\n }\n pop(id = 0) {\n var popNode = this.h[id];\n this.size--;\n this.h[id] = this.h[this.size];\n this.h[id][this.id] = id;\n var node = this.h[id];\n while (true) {\n var childId = node[this.id] * 2 + 1;\n if (childId > this.size)\n break;\n if (childId < this.size && this.comp(this.h[childId].key, this.h[childId + 1].key) > 0)\n childId++;\n if (this.comp(this.h[childId].key, node.key) > 0)\n break;\n this.h[node[this.id]] = this.h[childId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[childId] = node;\n node[this.id] = childId;\n }\n while (true) {\n if (node[this.id] == 0)\n break;\n var parentId = (node[this.id] - 1) >> 1;\n if (this.comp(this.h[parentId].key, node.key) > 0) {\n this.h[node[this.id]] = this.h[parentId];\n this.h[node[this.id]][this.id] = node[this.id];\n this.h[parentId] = node;\n node[this.id] = parentId;\n }\n else\n break;\n }\n return popNode;\n }\n}\n"}, {"source_code": "class Node {\n left; right; key; min; max;\n constructor(key) {\n this.key = key;\n this.min = key;\n this.max = key;\n }\n update() {\n this.min = Math.min(this.key, this.left ? this.left.key : 1e10, this.right ? this.right.key : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.key : -1e10, this.right ? this.right.key : -1e10);\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push[cur.left = new Node(key)];\n else trace.push[cur.right = new Node(key)];\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n min() {\n return this.root ? this.root.min : undefined;\n }\n\n max() {\n return this.root ? this.root.max : undefined;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}\n\n// var t = new SplayTree();\n// var arr = Array(5).fill(0).map(v => Math.random() * 100 | 0);\n// arr.forEach(v => {\n// t.insert(v);\n// t.print();\n// });\n// console.log('---');\n// arr.forEach(v => {\n// t.remove(v);\n// t.print();\n// })\n\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inp = input.split(/\\D+/m).map(v => +v), r = 0;\n var n = inp[r++], k = inp[r++];\n var h = inp.slice(r, r = r + n);\n var t = new SplayTree();\n t.insert(h[0]);\n var max = 1, i = j = 0;\n var allRes = [];\n // console.log(n,k,h);\n while (i < n) {\n while (j < n) {\n j++;\n if (j >= n) break;\n t.insert(h[j]);\n if (t.max() - t.min() > k) break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n t.remove(h[i++]);\n while (t.max() - t.min() > k) {\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var tree = { value: h[0], size: 1 };\n var max = 1;\n var j = 0, hmax, hmin;\n for (let i = 0; i < n; i++) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n tree = insertValue(tree, h[j]);\n hmin = find(tree, 0).value;\n hmax = find(tree, j - i).value;\n // console.log(i, j, hmin, hmax);\n if (hmax - hmin > k)\n break;\n }\n max = Math.max(j - i, max);\n tree = deleteValue(tree, h[i]);\n }\n var allRes = [];\n tree = null;\n for (let i = 0; i < n; i++) {\n tree = insertValue(tree, h[i]);\n if (i >= max - 1) {\n hmin = find(tree, 0).value;\n hmax = find(tree, max - 1).value;\n if (hmax - hmin <= k)\n allRes.push((i - max + 2) + ' ' + (i + 1));\n tree = deleteValue(tree, h[i - max + 1]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();\nfunction setlink(parent, child, right) {\n if (right)\n (parent || {}).right = child;\n else\n (parent || {}).left = child;\n (child || {}).parent = parent;\n}\nfunction update(x) {\n var _a, _b;\n x.size = (((_a = x.left) === null || _a === void 0 ? void 0 : _a.size) || 0) + (((_b = x.right) === null || _b === void 0 ? void 0 : _b.size) || 0) + 1;\n // x.max = Math.max(x.value, x.left?.value, x.right?.value);\n}\nfunction uptree(x) {\n let parent = x.parent;\n let grand = parent === null || parent === void 0 ? void 0 : parent.parent;\n if (x == (parent === null || parent === void 0 ? void 0 : parent.left)) {\n setlink(parent, x.right, false);\n setlink(x, parent, true);\n }\n else {\n setlink(parent, x.left, true);\n setlink(x, parent, false);\n }\n setlink(grand, x, parent == (grand === null || grand === void 0 ? void 0 : grand.right));\n update(parent);\n update(x);\n}\nfunction splay(x) {\n while (true) {\n let parent = x.parent;\n if (!parent)\n break;\n let grand = parent.parent;\n if (grand) {\n if ((parent == grand.left) == (x == parent.left))\n uptree(parent);\n else\n uptree(x);\n }\n uptree(x);\n }\n return x;\n}\nfunction find(tree, index) {\n var _a;\n while (true) {\n if (!tree)\n return tree;\n let curIndex = ((_a = tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0;\n if (curIndex == index)\n return tree;\n if (curIndex > index)\n tree = tree.left;\n else {\n index -= curIndex + 1;\n tree = tree.right;\n }\n }\n}\nfunction cut(tree, index) {\n if (!tree)\n return [tree, tree];\n let treeA, treeB;\n if (index <= 0) {\n treeB = tree;\n return [treeA, treeB];\n }\n if (index >= tree.size) {\n treeA = tree;\n return [treeA, treeB];\n }\n let x = find(tree, index);\n splay(x);\n treeB = x.right;\n treeB === null || treeB === void 0 ? true : delete treeB.parent;\n treeA = x;\n treeA === null || treeA === void 0 ? true : delete treeA.right;\n update(treeA);\n return [treeA, treeB];\n}\nfunction join(treeA, treeB) {\n if (!treeA)\n return treeB;\n if (!treeB)\n return treeA;\n while (treeA.right)\n treeA = treeA.right;\n splay(treeA);\n setlink(treeA, treeB, true);\n update(treeA);\n return treeA;\n}\nfunction insertNode(tree, index, value) {\n let x = { value, size: 1 };\n let [treeA, treeB] = cut(tree, index);\n return join(join(treeA, x), treeB);\n}\nfunction deleteNode(tree, index) {\n let x = find(tree, index);\n if (!x)\n return tree;\n splay(x);\n let treeA = x.left, treeB = x.right;\n (treeA || {}).parent = null;\n (treeB || {}).parent = null;\n return join(treeA, treeB);\n}\nfunction findValue(tree, value) {\n if (!tree)\n return tree;\n while (true) {\n if (value < tree.value && tree.left)\n tree = tree.left;\n else if (value > tree.value && tree.right)\n tree = tree.right;\n else\n return splay(tree);\n }\n}\nfunction insertValue(tree, value) {\n var _a, _b;\n tree = findValue(tree, value);\n if (value < (tree === null || tree === void 0 ? void 0 : tree.value))\n tree = insertNode(tree, ((_a = tree === null || tree === void 0 ? void 0 : tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0, value);\n else\n tree = insertNode(tree, (((_b = tree === null || tree === void 0 ? void 0 : tree.left) === null || _b === void 0 ? void 0 : _b.size) || 0) + 1, value);\n return tree;\n}\nfunction deleteValue(tree, value) {\n var _a;\n tree = findValue(tree, value);\n return deleteNode(tree, ((_a = tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0);\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var _a, _b;\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var tree = { value: h[0], size: 1 };\n var max = 1;\n var i = 0, j = 0, hmax, hmin;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n tree = insertValue(tree, h[j]);\n hmin = find(tree, 0).value;\n hmax = find(tree, j - i).value;\n // console.log(i, j, hmin, hmax);\n if (hmax - hmin > k)\n break;\n }\n max = Math.max(j - i, max);\n tree = deleteValue(tree, h[i++]);\n while (((_a = find(tree, j - i)) === null || _a === void 0 ? void 0 : _a.value) - ((_b = find(tree, 0)) === null || _b === void 0 ? void 0 : _b.value) > k) {\n tree = deleteValue(tree, h[i++]);\n }\n }\n var allRes = [];\n tree = null;\n for (let i = 0; i < n; i++) {\n tree = insertValue(tree, h[i]);\n if (i >= max - 1) {\n hmin = find(tree, 0).value;\n hmax = find(tree, max - 1).value;\n if (hmax - hmin <= k)\n allRes.push((i - max + 2) + ' ' + (i + 1));\n tree = deleteValue(tree, h[i - max + 1]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n})();\nfunction setlink(parent, child, right) {\n if (right)\n (parent || {}).right = child;\n else\n (parent || {}).left = child;\n (child || {}).parent = parent;\n}\nfunction update(x) {\n var _a, _b;\n x.size = (((_a = x.left) === null || _a === void 0 ? void 0 : _a.size) || 0) + (((_b = x.right) === null || _b === void 0 ? void 0 : _b.size) || 0) + 1;\n // x.max = Math.max(x.value, x.left?.value, x.right?.value);\n}\nfunction uptree(x) {\n let parent = x.parent;\n let grand = parent === null || parent === void 0 ? void 0 : parent.parent;\n if (x == (parent === null || parent === void 0 ? void 0 : parent.left)) {\n setlink(parent, x.right, false);\n setlink(x, parent, true);\n }\n else {\n setlink(parent, x.left, true);\n setlink(x, parent, false);\n }\n setlink(grand, x, parent == (grand === null || grand === void 0 ? void 0 : grand.right));\n update(parent);\n update(x);\n}\nfunction splay(x) {\n while (true) {\n let parent = x.parent;\n if (!parent)\n break;\n let grand = parent.parent;\n if (grand) {\n if ((parent == grand.left) == (x == parent.left))\n uptree(parent);\n else\n uptree(x);\n }\n uptree(x);\n }\n return x;\n}\nfunction find(tree, index) {\n var _a;\n while (true) {\n if (!tree)\n return tree;\n let curIndex = ((_a = tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0;\n if (curIndex == index)\n return tree;\n if (curIndex > index)\n tree = tree.left;\n else {\n index -= curIndex + 1;\n tree = tree.right;\n }\n }\n}\nfunction cut(tree, index) {\n if (!tree)\n return [tree, tree];\n let treeA, treeB;\n if (index <= 0) {\n treeB = tree;\n return [treeA, treeB];\n }\n if (index >= tree.size) {\n treeA = tree;\n return [treeA, treeB];\n }\n let x = find(tree, index);\n splay(x);\n treeB = x.right;\n treeB === null || treeB === void 0 ? true : delete treeB.parent;\n treeA = x;\n treeA === null || treeA === void 0 ? true : delete treeA.right;\n update(treeA);\n return [treeA, treeB];\n}\nfunction join(treeA, treeB) {\n if (!treeA)\n return treeB;\n if (!treeB)\n return treeA;\n while (treeA.right)\n treeA = treeA.right;\n splay(treeA);\n setlink(treeA, treeB, true);\n update(treeA);\n return treeA;\n}\nfunction insertNode(tree, index, value) {\n let x = { value, size: 1 };\n let [treeA, treeB] = cut(tree, index);\n return join(join(treeA, x), treeB);\n}\nfunction deleteNode(tree, index) {\n let x = find(tree, index);\n if (!x)\n return tree;\n splay(x);\n let treeA = x.left, treeB = x.right;\n (treeA || {}).parent = null;\n (treeB || {}).parent = null;\n return join(treeA, treeB);\n}\nfunction findValue(tree, value) {\n if (!tree)\n return tree;\n while (true) {\n if (value < tree.value && tree.left)\n tree = tree.left;\n else if (value > tree.value && tree.right)\n tree = tree.right;\n else\n return splay(tree);\n }\n}\nfunction insertValue(tree, value) {\n var _a, _b;\n tree = findValue(tree, value);\n if (value < (tree === null || tree === void 0 ? void 0 : tree.value))\n tree = insertNode(tree, ((_a = tree === null || tree === void 0 ? void 0 : tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0, value);\n else\n tree = insertNode(tree, (((_b = tree === null || tree === void 0 ? void 0 : tree.left) === null || _b === void 0 ? void 0 : _b.size) || 0) + 1, value);\n return tree;\n}\nfunction deleteValue(tree, value) {\n var _a;\n tree = findValue(tree, value);\n return deleteNode(tree, ((_a = tree.left) === null || _a === void 0 ? void 0 : _a.size) || 0);\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, k] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.insert(h[0]);\n var max = 1;\n var i = 0, j = 0;\n var max = 1;\n var allRes = [];\n var i = 0, j = 0;\n while (i < n) {\n while (j < n) {\n j++;\n if (!h[j])\n break;\n t.insert(h[j]);\n // console.log(i, j, hk, t.print());\n if (t.key(j - i) - t.key(0) > k)\n break;\n }\n if (max < j - i) {\n max = j - i;\n allRes = [(i + 1) + ' ' + j];\n }\n else if (max == j - i) {\n allRes.push((i + 1) + ' ' + j);\n }\n // console.log(t.print(), i, j, h[i])\n t.remove(h[i++]);\n while (t.key(j - i) - t.key(0) > k) {\n // console.log('NOOO', i, j, h[i]);\n t.remove(h[i++]);\n }\n }\n console.log(max, allRes.length);\n console.log(allRes.join('\\n'));\n // console.log(Date.now() - time)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var parent = undefined;\n var node = this.root;\n while (true) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n if (key == 7)\n console.log('rotateRight', node.key);\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n node = left;\n continue;\n }\n if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n node = right;\n continue;\n }\n if (key < node.key) {\n node.size++;\n if (!left)\n return node.left = new BSNode(key);\n parent = node;\n node = left;\n }\n else {\n node.size++;\n if (!right)\n return node.right = new BSNode(key);\n parent = node;\n node = right;\n }\n }\n }\n remove(key) {\n var parent = undefined;\n var node = this.root;\n while (node && node.key != key) {\n parent = node;\n node.size--;\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var right = node.right;\n if (!right) {\n if (!parent) {\n this.root = node.left;\n }\n else {\n if (parent.left == node)\n parent.left = node.left;\n else\n parent.right = node.left;\n }\n return;\n }\n var rightParent = node;\n while (right && right.left) {\n rightParent = right;\n right.size--;\n right = right.left;\n }\n node.key = right.key;\n if (rightParent.left == right)\n rightParent.left = right.right;\n else\n rightParent.right = right.right;\n node.size--;\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}], "src_uid": "bc8b4b74c2f2d486e2d2f03982ef1013"} {"source_code": "'use strict';\n\nvar readline = require('readline');\n\n/*! *****************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nfunction __extends(d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isFunction(x) {\n return typeof x === 'function';\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar _enable_super_gross_mode_that_will_cause_bad_things = false;\nvar config = {\n Promise: undefined,\n set useDeprecatedSynchronousErrorHandling(value) {\n if (value) {\n var error = /*@__PURE__*/ new Error();\n /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \\n' + error.stack);\n }\n _enable_super_gross_mode_that_will_cause_bad_things = value;\n },\n get useDeprecatedSynchronousErrorHandling() {\n return _enable_super_gross_mode_that_will_cause_bad_things;\n },\n};\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction hostReportError(err) {\n setTimeout(function () { throw err; }, 0);\n}\n\n/** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */\nvar empty = {\n closed: true,\n next: function (value) { },\n error: function (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n },\n complete: function () { }\n};\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isObject(x) {\n return x !== null && typeof x === 'object';\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {\n function UnsubscriptionErrorImpl(errors) {\n Error.call(this);\n this.message = errors ?\n errors.length + \" errors occurred during unsubscription:\\n\" + errors.map(function (err, i) { return i + 1 + \") \" + err.toString(); }).join('\\n ') : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n return this;\n }\n UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return UnsubscriptionErrorImpl;\n})();\nvar UnsubscriptionError = UnsubscriptionErrorImpl;\n\n/** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */\nvar Subscription = /*@__PURE__*/ (function () {\n function Subscription(unsubscribe) {\n this.closed = false;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (unsubscribe) {\n this._ctorUnsubscribe = true;\n this._unsubscribe = unsubscribe;\n }\n }\n Subscription.prototype.unsubscribe = function () {\n var errors;\n if (this.closed) {\n return;\n }\n var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;\n this.closed = true;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (_parentOrParents instanceof Subscription) {\n _parentOrParents.remove(this);\n }\n else if (_parentOrParents !== null) {\n for (var index = 0; index < _parentOrParents.length; ++index) {\n var parent_1 = _parentOrParents[index];\n parent_1.remove(this);\n }\n }\n if (isFunction(_unsubscribe)) {\n if (_ctorUnsubscribe) {\n this._unsubscribe = undefined;\n }\n try {\n _unsubscribe.call(this);\n }\n catch (e) {\n errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];\n }\n }\n if (isArray(_subscriptions)) {\n var index = -1;\n var len = _subscriptions.length;\n while (++index < len) {\n var sub = _subscriptions[index];\n if (isObject(sub)) {\n try {\n sub.unsubscribe();\n }\n catch (e) {\n errors = errors || [];\n if (e instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(e.errors));\n }\n else {\n errors.push(e);\n }\n }\n }\n }\n }\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n };\n Subscription.prototype.add = function (teardown) {\n var subscription = teardown;\n if (!teardown) {\n return Subscription.EMPTY;\n }\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(teardown);\n case 'object':\n if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {\n return subscription;\n }\n else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n }\n else if (!(subscription instanceof Subscription)) {\n var tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default: {\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n }\n var _parentOrParents = subscription._parentOrParents;\n if (_parentOrParents === null) {\n subscription._parentOrParents = this;\n }\n else if (_parentOrParents instanceof Subscription) {\n if (_parentOrParents === this) {\n return subscription;\n }\n subscription._parentOrParents = [_parentOrParents, this];\n }\n else if (_parentOrParents.indexOf(this) === -1) {\n _parentOrParents.push(this);\n }\n else {\n return subscription;\n }\n var subscriptions = this._subscriptions;\n if (subscriptions === null) {\n this._subscriptions = [subscription];\n }\n else {\n subscriptions.push(subscription);\n }\n return subscription;\n };\n Subscription.prototype.remove = function (subscription) {\n var subscriptions = this._subscriptions;\n if (subscriptions) {\n var subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n };\n Subscription.EMPTY = (function (empty) {\n empty.closed = true;\n return empty;\n }(new Subscription()));\n return Subscription;\n}());\nfunction flattenUnsubscriptionErrors(errors) {\n return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar rxSubscriber = /*@__PURE__*/ (function () {\n return typeof Symbol === 'function'\n ? /*@__PURE__*/ Symbol('rxSubscriber')\n : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();\n})();\n\n/** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */\nvar Subscriber = /*@__PURE__*/ (function (_super) {\n __extends(Subscriber, _super);\n function Subscriber(destinationOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this.syncErrorValue = null;\n _this.syncErrorThrown = false;\n _this.syncErrorThrowable = false;\n _this.isStopped = false;\n switch (arguments.length) {\n case 0:\n _this.destination = empty;\n break;\n case 1:\n if (!destinationOrNext) {\n _this.destination = empty;\n break;\n }\n if (typeof destinationOrNext === 'object') {\n if (destinationOrNext instanceof Subscriber) {\n _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;\n _this.destination = destinationOrNext;\n destinationOrNext.add(_this);\n }\n else {\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext);\n }\n break;\n }\n default:\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);\n break;\n }\n return _this;\n }\n Subscriber.prototype[rxSubscriber] = function () { return this; };\n Subscriber.create = function (next, error, complete) {\n var subscriber = new Subscriber(next, error, complete);\n subscriber.syncErrorThrowable = false;\n return subscriber;\n };\n Subscriber.prototype.next = function (value) {\n if (!this.isStopped) {\n this._next(value);\n }\n };\n Subscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n this.isStopped = true;\n this._error(err);\n }\n };\n Subscriber.prototype.complete = function () {\n if (!this.isStopped) {\n this.isStopped = true;\n this._complete();\n }\n };\n Subscriber.prototype.unsubscribe = function () {\n if (this.closed) {\n return;\n }\n this.isStopped = true;\n _super.prototype.unsubscribe.call(this);\n };\n Subscriber.prototype._next = function (value) {\n this.destination.next(value);\n };\n Subscriber.prototype._error = function (err) {\n this.destination.error(err);\n this.unsubscribe();\n };\n Subscriber.prototype._complete = function () {\n this.destination.complete();\n this.unsubscribe();\n };\n Subscriber.prototype._unsubscribeAndRecycle = function () {\n var _parentOrParents = this._parentOrParents;\n this._parentOrParents = null;\n this.unsubscribe();\n this.closed = false;\n this.isStopped = false;\n this._parentOrParents = _parentOrParents;\n return this;\n };\n return Subscriber;\n}(Subscription));\nvar SafeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SafeSubscriber, _super);\n function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this._parentSubscriber = _parentSubscriber;\n var next;\n var context = _this;\n if (isFunction(observerOrNext)) {\n next = observerOrNext;\n }\n else if (observerOrNext) {\n next = observerOrNext.next;\n error = observerOrNext.error;\n complete = observerOrNext.complete;\n if (observerOrNext !== empty) {\n context = Object.create(observerOrNext);\n if (isFunction(context.unsubscribe)) {\n _this.add(context.unsubscribe.bind(context));\n }\n context.unsubscribe = _this.unsubscribe.bind(_this);\n }\n }\n _this._context = context;\n _this._next = next;\n _this._error = error;\n _this._complete = complete;\n return _this;\n }\n SafeSubscriber.prototype.next = function (value) {\n if (!this.isStopped && this._next) {\n var _parentSubscriber = this._parentSubscriber;\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._next, value);\n }\n else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;\n if (this._error) {\n if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._error, err);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, this._error, err);\n this.unsubscribe();\n }\n }\n else if (!_parentSubscriber.syncErrorThrowable) {\n this.unsubscribe();\n if (useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n hostReportError(err);\n }\n else {\n if (useDeprecatedSynchronousErrorHandling) {\n _parentSubscriber.syncErrorValue = err;\n _parentSubscriber.syncErrorThrown = true;\n }\n else {\n hostReportError(err);\n }\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.complete = function () {\n var _this = this;\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n if (this._complete) {\n var wrappedComplete = function () { return _this._complete.call(_this._context); };\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(wrappedComplete);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, wrappedComplete);\n this.unsubscribe();\n }\n }\n else {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n this.unsubscribe();\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n }\n };\n SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {\n if (!config.useDeprecatedSynchronousErrorHandling) {\n throw new Error('bad call');\n }\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n parent.syncErrorValue = err;\n parent.syncErrorThrown = true;\n return true;\n }\n else {\n hostReportError(err);\n return true;\n }\n }\n return false;\n };\n SafeSubscriber.prototype._unsubscribe = function () {\n var _parentSubscriber = this._parentSubscriber;\n this._context = null;\n this._parentSubscriber = null;\n _parentSubscriber.unsubscribe();\n };\n return SafeSubscriber;\n}(Subscriber));\n\n/** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */\nfunction canReportError(observer) {\n while (observer) {\n var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;\n if (closed_1 || isStopped) {\n return false;\n }\n else if (destination && destination instanceof Subscriber) {\n observer = destination;\n }\n else {\n observer = null;\n }\n }\n return true;\n}\n\n/** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */\nfunction toSubscriber(nextOrObserver, error, complete) {\n if (nextOrObserver) {\n if (nextOrObserver instanceof Subscriber) {\n return nextOrObserver;\n }\n if (nextOrObserver[rxSubscriber]) {\n return nextOrObserver[rxSubscriber]();\n }\n }\n if (!nextOrObserver && !error && !complete) {\n return new Subscriber(empty);\n }\n return new Subscriber(nextOrObserver, error, complete);\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction identity(x) {\n return x;\n}\n\n/** PURE_IMPORTS_START _identity PURE_IMPORTS_END */\nfunction pipeFromArray(fns) {\n if (fns.length === 0) {\n return identity;\n }\n if (fns.length === 1) {\n return fns[0];\n }\n return function piped(input) {\n return fns.reduce(function (prev, fn) { return fn(prev); }, input);\n };\n}\n\n/** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */\nvar Observable = /*@__PURE__*/ (function () {\n function Observable(subscribe) {\n this._isScalar = false;\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n Observable.prototype.lift = function (operator) {\n var observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n };\n Observable.prototype.subscribe = function (observerOrNext, error, complete) {\n var operator = this.operator;\n var sink = toSubscriber(observerOrNext, error, complete);\n if (operator) {\n sink.add(operator.call(sink, this.source));\n }\n else {\n sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?\n this._subscribe(sink) :\n this._trySubscribe(sink));\n }\n if (config.useDeprecatedSynchronousErrorHandling) {\n if (sink.syncErrorThrowable) {\n sink.syncErrorThrowable = false;\n if (sink.syncErrorThrown) {\n throw sink.syncErrorValue;\n }\n }\n }\n return sink;\n };\n Observable.prototype._trySubscribe = function (sink) {\n try {\n return this._subscribe(sink);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n sink.syncErrorThrown = true;\n sink.syncErrorValue = err;\n }\n if (canReportError(sink)) {\n sink.error(err);\n }\n else {\n console.warn(err);\n }\n }\n };\n Observable.prototype.forEach = function (next, promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var subscription;\n subscription = _this.subscribe(function (value) {\n try {\n next(value);\n }\n catch (err) {\n reject(err);\n if (subscription) {\n subscription.unsubscribe();\n }\n }\n }, reject, resolve);\n });\n };\n Observable.prototype._subscribe = function (subscriber) {\n var source = this.source;\n return source && source.subscribe(subscriber);\n };\n Observable.prototype[observable] = function () {\n return this;\n };\n Observable.prototype.pipe = function () {\n var operations = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n operations[_i] = arguments[_i];\n }\n if (operations.length === 0) {\n return this;\n }\n return pipeFromArray(operations)(this);\n };\n Observable.prototype.toPromise = function (promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var value;\n _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });\n });\n };\n Observable.create = function (subscribe) {\n return new Observable(subscribe);\n };\n return Observable;\n}());\nfunction getPromiseCtor(promiseCtor) {\n if (!promiseCtor) {\n promiseCtor = Promise;\n }\n if (!promiseCtor) {\n throw new Error('no Promise impl found');\n }\n return promiseCtor;\n}\n\nfunction tnLineStdinReader() {\n return new Observable(function (subscribe) {\n var stdin = readline.createInterface(process.stdin);\n var tests = null;\n var n = null;\n stdin.on('line', function (line) {\n if (tests === null) {\n tests = +line;\n } else if (n === null) {\n n = +line;\n tests--;\n } else {\n n = null;\n subscribe.next(line);\n\n if (tests === 0) {\n stdin.close();\n subscribe.complete();\n }\n }\n });\n });\n}\n\ntnLineStdinReader().subscribe(function (line) {\n var numbers = line.split(' ').map(Number);\n\n if (numbers[0] + numbers[1] <= numbers[numbers.length - 1]) {\n console.log(\"1 2 \".concat(numbers.length));\n } else {\n console.log('-1');\n }\n});\n", "positive_code": [{"source_code": "var input = \"\";\nvar chunks = [];\n\nprocess.stdin.on(\"data\", function(data) {\n input += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n chunks = input.split(\"\\n\");\n start();\n});\n\nfunction start() {\n T = parseInt(chunks.shift(), 10);\n for (let i = 0; i < T; ++i) {\n let n = parseInt(chunks.shift(), 10);\n let numbers = chunks.shift().split(\" \").map(n => parseInt(n, 10));\n const triplet = run(numbers);\n if (triplet) {\n console.log(triplet.join(' '));\n } else {\n console.log(-1);\n }\n }\n process.exit(0);\n}\n\nfunction run(numbers) {\n let ni = numbers[0];\n let nj = numbers[1];\n let nk = numbers[numbers.length - 1];\n return ni + nj <= nk ? [1, 2, numbers.length] : false;\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar inputArray = [];\nvar currentLine = 0;\nprocess.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', function (_) {\n inputArray = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main();\n});\nfunction readline() {\n return inputArray[currentLine++];\n}\nfunction main() {\n var t = parseInt(readline());\n for (var i = 0; i < t; i++) {\n var n = parseInt(readline());\n var nums = readline().split(\" \").map(function (x) { return parseInt(x); });\n if (nums[0] + nums[1] <= nums[n - 1]) {\n console.log(1, 2, n);\n }\n else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM() {\n\n}\n\nconst CONFIG = {\n // getStringFunc: readDOM;\n};\n\nfunction factorial(n) {\n if (n < 2) return 1;\n else return n * factorial(n - 1);\n}\n\nstdioCPPattern({}, ({ readNum, readStr, writeLine }) => {\n // your code goes here\n let tc_count = readNum();\n\n const a = Array(1e5);\n let n;\n\n while (tc_count--) {\n n = readNum();\n for (let i = 0; i < n; i++) {\n a[i] = readNum();\n }\n\n if (a[0] + a[1] <= a[n-1]) {\n writeLine(`1 2 ${n}`);\n } else {\n writeLine(-1);\n }\n }\n});\n\n/**\n * @author flynn\n */\n// WARNING!!!\n// DO NOT MODIFY THE CODE BELOW\n// IT WILL STOP WORKING FOREVERRRRRRRRRRR!!!\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = 0;\n const resultList = [];// Array(numberOfLine);\n\n callbackfn({\n log: console.log,\n readNum() {\n let x = 0, ch = aStr.charCodeAt(cur) - 48;\n while (ch < 0 || 9 < ch) ch = aStr.charCodeAt(++cur) - 48;\n while (0 <= ch && ch <= 9) {\n x = x * 10 + ch;\n ch = aStr.charCodeAt(++cur) - 48;\n }\n return x;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(len = 1e6) {\n const chArr = Array(len);\n let ch = aStr[cur], i = 0;\n while (ch < \"a\" || \"z\" < ch) ch = aStr[++cur];\n while (\"a\" <= ch && ch <= \"z\") {\n chArr[i++] = ch;\n ch = aStr[++cur];\n }\n return chArr.join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n}"}, {"source_code": "var t = parseInt(readline());\nn = [];\nsides = [];\nfor (var i = 0; i < t; i++) {\n n.push(parseInt(readline()));\n sides.push(readline().split(' ').map(x => parseInt(x)));\n}\nfor (var i = 0; i < t; i++){\n found = 0;\n if (sides[i][0] + sides[i][1] <= sides[i][n[i]-1]) {\n print(1, 2, n[i]);\n found = 1;\n }\n if (found == 0) {\n print(-1);\n }\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet a = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tif (a[0] + a[1] > a[n - 1]) console.log(-1);\n\t\telse console.log(1, 2, n);\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = parseInt(readLine());\n for (let c = 0; c < numCases; c++) {\n const length = parseInt(readLine());\n const array = readLine().split(\" \").map(i => parseInt(i));\n\n if (array[0] + array[1] <= array[array.length - 1]) {\n console.log(1, 2, array.length);\n } else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let o = 0; o < t; o++){\n let n = parseInt(readline());\n let arr = readline().split(' ');\n\n if(arr.length <= 2){\n console.log(-1);\n continue;\n }\n\n if(parseInt(arr[0]) + parseInt(arr[1]) > parseInt(arr[n-1]))\n console.log(-1);\n else{\n console.log(1);\n console.log(2);\n console.log(n);\n }\n }\n}"}, {"source_code": "var readline=require('readline');\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(inp);\n var len=arr.length;\n if(len%2===1&&len!==1){\n var n=parseInt(arr[arr.length-2]),a=arr[arr.length-1].split(' ');\n for(var i=0;ia[a.length-1]) console.log(-1);\n else console.log(1,2,a.length);\n }\n if(len===parseInt(arr[0])*2+1) process.exit(0);\n});"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, len - 1];\n let found = false;\n while (start < end) {\n const [a, b, c] = [arr[start], arr[start + 1], arr[end]];\n if (a + b <= c) {\n found = true;\n console.log(`${start + 1} ${start + 2} ${end + 1}`);\n break;\n }\n if (a + b > c) {\n found = true;\n console.log(-1);\n break;\n }\n end--;\n }\n\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (arr[0] + arr[1] > arr[len - 1]) {\n console.log(-1);\n } else {\n console.log(`1 2 ${len}`);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n for(var j = 2; j < N; j++){\n if(list[0] + list[1] <= list[j]){\n output[i] = \"1 2 \" + (j + 1);\n break;\n }\n }\n if(output[i] == null){\n output[i] = -1;\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n const str = readLine();\n const a = str.split(' ').map(num => Number(num));\n if (a[0] + a[1] <= a[a.length - 1]) {\n console.log(1, 2, a.length);\n } else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n const arr = data[i + 1].trim().split(' ').map(Number);\n // const n = int[2] * 1;\n let a = arr[0];\n let b = arr[1];\n let d = arr[2];\n let c = arr[arr.length - 1];\n if (a + b <= c) console.log('1 2 '+ arr.length);\n else if (a + b <= d) console.log('1 2 3');\n else console.log('-1');\n i += 2;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n\tconst n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n const ai = as[0], aj = as[1], ak = as[n - 1]\n if (ak >= ai + aj) {\n console.log(1, 2, n)\n } else {\n console.log(-1)\n }\n }\n}\n"}], "negative_code": [{"source_code": "var readline=require('readline');\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(inp);\n var len=arr.length;\n if(len%2===1&&len!=1){\n var n=parseInt(arr[arr.length-2]),a=arr[arr.length-1].split(' ');\n for(var i=0;i=a[a.length-1]) console.log(-1);\n else console.log(1,2,a.length);\n }\n if(len===parseInt(arr[0])*2+1) process.exit(0);\n});"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, mid, end] = [0, 0, 0];\n let found = false;\n for (let i = 0; i < len - 2; i++) {\n const [a, b, c] = [arr[0], arr[i + 1], arr[i + 2]];\n if (!(a + b > c)) {\n start = 1;\n mid = i + 2;\n end = i + 3;\n console.log(`${start} ${mid} ${end}`);\n found = true;\n break;\n }\n }\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, len - 1];\n let found = false;\n while (start < end - 1) {\n const [a, b, c] = [arr[start], arr[end - 1], arr[end]];\n if (c - a > b) {\n found = true;\n console.log(`${start + 1} ${end} ${end + 1}`);\n break;\n }\n end--;\n }\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, 0];\n let found = false;\n for (let i = 0; i < len - 2; i++) {\n const [a, b, c] = [arr[i], arr[i + 1], arr[i + 2]];\n if (!(a + b > c)) {\n start = i + 1;\n end = i + 3;\n console.log(`${start} ${start + 1} ${start + 2}`);\n found = true;\n break;\n }\n }\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, 0];\n\n for (let i = 0; i < len - 2; i++) {\n if (arr[i] + arr[i + 1] <= arr[i + 2]) {\n start = i + 1;\n end = i + 3;\n break;\n }\n }\n if (start === 0 && end === 0) {\n console.log(-1);\n } else {\n console.log(`${start} ${start + 1} ${start + 2}`);\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, len - 1];\n let found = false;\n while (start < end - 1) {\n const [a, b, c] = [arr[start], arr[end - 1], arr[end]];\n if (c - a > b) {\n found = true;\n console.log(`${start + 1} ${end} ${end + 1}`);\n break;\n }\n end--;\n }\n if (!found) {\n while (start < end - 1) {\n const [a, b, c] = [arr[start], arr[end - 1], arr[end]];\n if (c - a > b) {\n found = true;\n console.log(`${start + 1} ${end} ${end + 1}`);\n break;\n }\n start++;\n }\n }\n if (!found) {\n while (start < end - 1) {\n const [a, b, c] = [arr[start], arr[end - 1], arr[end]];\n if (c - a > b) {\n found = true;\n console.log(`${start + 1} ${end} ${end + 1}`);\n break;\n }\n start++;\n end--;\n }\n }\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, 0];\n\n for (let i = 0; i < len - 2; i++) {\n if (arr[i + 1] - arr[i] > 1 || arr[i + 2] - arr[i + 1] > 1) {\n start = i + 1;\n end = i + 3;\n break;\n }\n }\n if (start === 0 && end === 0) {\n console.log(-1);\n } else {\n console.log(`${start} ${start + 1} ${start + 2}`);\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [start, end] = [0, 0];\n let found = false;\n for (let i = 0; i < len - 2; i++) {\n const [a, b, c] = [arr[i], arr[i + 1], arr[i + 2]];\n if (!(a + b > c && a + c > b && b + c > a)) {\n start = i + 1;\n end = i + 3;\n console.log(`${start} ${start + 1} ${start + 2}`);\n found = true;\n break;\n }\n }\n !found && console.log(-1);\n }\n}\n"}, {"source_code": "//process.stdin.resume();\n//process.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n // console.log('inputStdin', inputStdin);\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n const str = readLine();\n const a = str.split(' ').map(num => Number(num));\n if (a[0] + a[1] <= a[a.length - 1]) {\n console.log(a[0], a[1], a[a.length - 1]);\n } else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "var input = \"\";\nvar chunks = [];\n\nprocess.stdin.on(\"data\", function(data) {\n input += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n chunks = input.split(\"\\n\");\n start();\n});\n\nfunction start() {\n T = parseInt(chunks.shift(), 10);\n for (let i = 0; i < T; ++i) {\n let n = parseInt(chunks.shift(), 10);\n let numbers = chunks.shift().split(\" \").map(n => parseInt(n, 10));\n const triplet = run(numbers);\n if (triplet) {\n console.log(triplet.join(' '));\n } else {\n console.log(-1);\n }\n }\n process.exit(0);\n}\n\nfunction run(numbers) {\n let ni = numbers[0];\n let nj = numbers[1];\n let nk = numbers[numbers.length - 1];\n return ni + nj < nk ? [1, 2, numbers.length] : false;\n}"}, {"source_code": "var input = \"\";\nvar chunks = [];\n\nprocess.stdin.on(\"data\", function(data) {\n input += data;\n});\n\nprocess.stdin.on(\"end\", function() {\n chunks = input.split(\"\\n\");\n start();\n});\n\nfunction start() {\n T = parseInt(chunks.shift(), 10);\n for (let i = 0; i < T; ++i) {\n let n = parseInt(chunks.shift(), 10);\n let numbers = chunks.shift().split(\" \").map(n => parseInt(n, 10));\n const triplet = run(numbers);\n if (triplet) {\n console.log(triplet.join(' '));\n } else {\n console.log(-1);\n }\n }\n process.exit(0);\n}\n\nfunction run(numbers) {\n let ni = numbers[0];\n let nj = numbers[1];\n let nk = numbers[numbers.length - 1];\n return ni + nj < nk ? [0, 1, numbers.length - 1] : false;\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar inputArray = [];\nvar currentLine = 0;\nprocess.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', function (_) {\n inputArray = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main();\n});\nfunction readline() {\n return inputArray[currentLine++];\n}\nfunction main() {\n var t = parseInt(readline());\n for (var i = 0; i < t; i++) {\n var n = parseInt(readline());\n var nums = readline().split(\" \").map(function (x) { return parseInt(x); });\n if (nums[0] + nums[1] <= nums[n - 1]) {\n console.log(0, 1, n - 1);\n }\n else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet a = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tif (a[0] + a[1] >= a[n - 1]) console.log(-1);\n\t\telse console.log(1, 2, n);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet a = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet pos = [],\n\t\t\tflag = false;\n\t\tfor (let i = 0; i < n - 2; i++) {\n\t\t\tif (a[i] + a[i + 1] <= a[i + 2]) {\n\t\t\t\tflag = true;\n\t\t\t\tpos.push(i + 1, i + 2, i + 3);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tflag ? console.log(pos.join(' ')) : console.log(-1);\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = parseInt(readLine());\n for (let c = 0; c < numCases; c++) {\n const length = parseInt(readLine());\n const array = readLine().split(\" \").map(i => parseInt(i));\n\n if (array[0] + array[1] <= array[array.length - 1]) {\n console.log(1, 1, array.length - 1);\n } else {\n console.log(-1);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = parseInt(readLine());\n for (let c = 0; c < numCases; c++) {\n const length = parseInt(readLine());\n const array = readLine().split(\" \").map(i => parseInt(i));\n\n if (array[0] + array[1] <= array[array.length - 1]) {\n console.log(array[0], array[1], array[array.length - 1]);\n } else {\n console.log(-1);\n }\n }\n}\n"}], "src_uid": "341555349b0c1387334a0541730159ac"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = 0\n var b = 0\n var c = 0\n var d = lines[j].split('')\n for(k = 0; k < d.length; k++){\n if(d[k] == 'A'){\n a ++\n }else if(d[k] == 'B'){\n b ++\n }else if(d[k] == 'C'){\n c ++\n }\n }\n if(a + c == b){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n});\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n", "positive_code": [{"source_code": "n = readline();\r\nwhile (n--) {\r\n s=readline().toString().split(\"\");\r\n a = s.filter(e=>e==\"A\");\r\n b = s.filter(u=>u==\"B\");\r\n c = s.filter(k=>k==\"C\");\r\n print(a.length+c.length==b.length?\"YES\":\"NO\");\r\n}"}, {"source_code": "function main() {\r\nvar t = readline();\r\nfor (var i = 0; i < t; i++) {\r\n var s = readline();\r\nvar a = 0;\r\nvar b = 0;\r\nvar c = 0;\r\nget(s)\r\n}\r\nfunction get(s) {\r\nfor (var j = 0; j < s.length; j++) {\r\n if (s[j] == \"A\") {\r\n a++;\r\n } else if (s[j] == \"B\") {\r\n b++;\r\n } else if (s[j] == \"C\") {\r\n c++;\r\n }\r\n}\r\nif (b === 0) {\r\n print(\"NO\");\r\n return;\r\n}\r\nif (a > b || c > b) {\r\n print(\"NO\");\r\n return;\r\n}\r\nif (a + c == b) {\r\n print(\"YES\");\r\n} else {\r\n print(\"NO\");\r\n}\r\n}\r\n\r\n}\r\nmain()"}, {"source_code": "\tfunction readStringArray() {\r\n\t\treturn readline().split(' ');\r\n\t}\r\n\tfunction readNumArray() {\r\n\t\treturn readStringArray().map(Number);\r\n\t}\r\n\r\n\tfunction main() {\r\n\t\tvar testCasesNum = +readline();\r\n\t\tfor (var i = 0; i < testCasesNum; i++) {\r\n\t\t\tvar s = readline();\r\n\t\t\tvar ac = 0;\r\n\t\t\tvar b = 0;\r\n\t\t\tfor (var j = 0; j < s.length; j++) {\r\n\t\t\t\tif (s[j] === 'B') {\r\n\t\t\t\t\tb++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tac++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tprint(b === ac ? 'YES' : 'NO');\r\n\t\t}\r\n\t}\r\n\r\n\tmain();"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var s = 0\n for(j = 1; j <= lines[0]; j++){\n var a = 0\n var b = 0\n var c = 0\n var l = lines[j].split('')\n for(k = 0; k < l.length; k++){\n if(l[k] == 'A'){\n a++\n }else if(l[k] == 'B'){\n b++\n }else if(l[k] == 'C'){\n c++\n }\n }\n if(a + c == b){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var d = 1; d <= n; d++){\n var a = 0;\n var b = 0;\n var c = 0;\n var k = lines[d].split('');\n for(var j = 0; j < k.length; j++){\n if(k[j] == 'A'){\n a += 1;\n }else if(k[j] == 'B'){\n b += 1;\n }else if(k[j] == 'C'){\n c += 1;\n }\n }\n if(a + c == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const str = readline();\r\n const countArr = count(str);\r\n const A = countArr[0], B = countArr[1], C = countArr[2];\r\n console.log(check(A, B, C));\r\n \r\n }\r\n}\r\n\r\nfunction count(str) {\r\n let A = 0, B = 0, C = 0;\r\n for(const char of str) {\r\n if(char == \"A\") A++;\r\n if(char == \"B\") B++;\r\n if(char == \"C\") C++; \r\n }\r\n return [A, B, C];\r\n}\r\n \r\nfunction check(A, B, C) {\r\n if(A <= B) B = B - A;\r\n else return \"NO\";\r\n if(B == C) return \"YES\"\r\n else return \"NO\";\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = [...(nl.line())];\n\t\tlet acc = a.reduce((ac, e) => {\n\t\t\tac[e]++;\n\t\t\treturn ac; \n\t\t\t}, {'A':0, 'B': 0, 'C': 0});\n\t\tans.push(acc['A'] + acc['C'] === acc['B']);\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ac = 0;\n let b = 0;\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"B\") {\n b++;\n } else {\n ac++;\n }\n }\n\n if (ac === b) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "var i = 0\nrequire('readline').createInterface(process.stdin,process.stdout).on('line', (line) => {\n if (i++) {\n let v={'A':0,'B':0,'C':0};\n for (const letter of line.split(\"\")) v[letter]++;\n console.log(\n (v['C'] == 0 && v['A']===v['B'] && v['A'] != 0) || \n (v['A'] == 0 && v['B'] === v['C'] && v['B'] != 0) || \n (v['B'] === v['A'] + v['C'] && v['B'] != 0) ? \"YES\" : \"NO\");\n };\n});\n\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction ans(){\r\n let s = readLine();\r\n let a = 0;\r\n let b = 0;\r\n let c = 0;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == 'A') a++;\r\n else if(s[i] == 'B') b++;\r\n else c++;\r\n }\r\n let res = ((a + c == b) ? \"YES\" : \"NO\");\r\n return res;\r\n}\r\n \r\nfunction main(){\r\n let t = readLine();\r\n while(t--){\r\n console.log(ans());\r\n console.log('\\n');\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\r\n\t\tlet acnt = 0, bcnt = 0, ccnt = 0;\r\n\t\tfor (const c of s) {\r\n\t\t\tacnt += c == 'A';\r\n\t\t\tbcnt += c == 'B';\r\n\t\t\tccnt += c == 'C';\r\n\t\t}\r\n\r\n\t\tconsole.log(acnt + ccnt == bcnt ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var a = 0;\n var b = 0;\n var c = 0;\n for(var d = 1; d <= n; d++){\n a = 0;\n b = 0;\n c = 0;\n var k = lines[d].split('');\n for(var j = 0; j < k.length; j++){\n if(k[j] == 'A'){\n a += 1;\n }else if(k[j] == 'B'){\n b += 1;\n }else if(k[j] == 'C'){\n c += 1;\n }\n }\n if(a + c == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "/*\r\n** 1579 A Casimir's String Solitaire\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst reverseText = (s) => { return s.split('').reverse().join('') }\r\nconst hasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\n\r\nconst hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\n\r\nconst isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\n\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&')\r\n\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\n// LIBRARY END\r\n\r\nconst decode = (text) => {\r\n text = text.split('')\r\n count_a = text.filter( c => c.includes('A') ).length\r\n count_b = text.filter( c => c.includes('B') ).length\r\n count_c = text.filter( c => c.includes('C') ).length\r\n \r\n // if(count_b == 0) return false\r\n\r\n // if(count_c == 0) {\r\n // if( isEven(count_a) && isEven(count_b) ) return true\r\n // else return false\r\n // } \r\n \r\n // if(count_a == 0){\r\n // if( isEven(count_c) && isEven(count_b) ) return true\r\n // return false\r\n // } \r\n\r\n if( count_a + count_c == count_b ) return true\r\n\r\n return false\r\n}\r\n\r\nfunction main() {\r\n let cases = readline()\r\n while( cases-- ) {\r\n let txt = readline()\r\n decode(txt) ? console.log('YES') : console.log('NO')\r\n }\r\n}\r\n//*/\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var arg = args[i].split(\"\");\r\n var a = arg.filter(function (x) { return x == 'A' }).length;\r\n var b = arg.filter(function (x) { return x == 'B' }).length;\r\n var c = arg.filter(function (x) { return x == 'C' }).length;\r\n if (a + c == b) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nconst fs = require('fs');\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function (inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function () {\r\n inputString = inputString.split('\\n');\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction problemSolving(str) {\r\n let a=0, b=0, c = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] == 'A')\r\n a++;\r\n else if (str[i] == 'B')\r\n b++;\r\n else\r\n c++;\r\n }\r\n c--;\r\n if (a + c == b)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n}\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine().trim(), 10);\r\n while (t-- > 0) {\r\n const str = readLine();\r\n problemSolving(str);\r\n }\r\n}"}, {"source_code": "let i = ''\r\nlet lines\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n lines = i.split('\\n')\r\n main()\r\n})\r\n\r\nfunction main() {\r\n let t = parseInt(lines.shift())\r\n\r\n while (t > 0) {\r\n let s = lines.shift()\r\n let ac = (s.match(/[ACac]/g) || []).length\r\n let b = (s.match(/[Bb]/g) || []).length\r\n console.log(ac == b ? 'YES' : 'NO')\r\n t--\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst main = () => {\r\n\r\n\r\n let ansArr = []\r\n const a = readline();\r\n for (let i = 0; i < a; i++) {\r\n let str = readline();\r\n let abc = {A: 0, B: 0, C: 0}\r\n for (let j = 0; j < str.length; j++) {\r\n abc[str[j]]++;\r\n }\r\n if (abc['A'] + abc['C'] === abc['B']) {\r\n ansArr.push('YES')\r\n } else {\r\n ansArr.push('NO')\r\n }\r\n }\r\n process.stdout.write(ansArr.join('\\n'))\r\n\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n\tconst len = readline();\n\t\n\tfor(let i = 0; i < len; i++){\n\t\tlet s = readline();\n\t\tprintln(func(s));\n\t}\n \t\n}\n\nfunction func(s){\n\tif(s.length % 2 != 0) return \"no\";\n\t\n\tlet m = new Map();\n\tfor(let i = 0; i < s.length; i++){\n\t\tif(m.has(s[i])){\n\t\t\tm.set(s[i], m.get(s[i])+1);\n\t\t}else{\n\t\t\tm.set(s[i], 1);\n\t\t}\n\t}\n\t\n\tlet a = 0, b = 0, c = 0;\n\tif(m.has(\"A\")){\n\t\ta = m.get(\"A\");\n\t}\n\tif(m.has(\"B\")){\n\t\tb = m.get(\"B\");\n\t}\n\tif(m.has(\"C\")){\n\t\tc = m.get(\"C\");\n\t}\n\t\n\tif(b == a+c){\n\t\treturn \"yes\";\n\t}\n\treturn \"no\";\n\t\n\t\n}\n\n\nfunction print(x) {\n process.stdout.write(x); // without auto '\\n' (newline)\n}\nfunction println(x) {\n console.log(x); // with auto '\\n' (newline)\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(str) {\r\n const aCount = str.split('').filter(i => i === 'A').length\r\n const bCount = str.split('').filter(i => i === 'B').length\r\n const cCount = str.split('').filter(i => i === 'C').length\r\n\r\n if (bCount === aCount + cCount) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar map = {A:0,B:0,C:0};\r\n\t\tfor(var i = 0; i < S.length; i++){\r\n\t\t\tmap[S[i]]++;\r\n\t\t}\r\n\t\tif(map[\"B\"] == map[\"A\"] + map[\"C\"]){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var s = 0\n for(j = 1; j <= lines[0]; j++){\n var a = 0\n var b = 0\n var c = 0\n var l = lines[j].split('')\n for(k = 0; k < l.length; l++){\n if(l[k] == 'A'){\n a++\n }else if(l[k] == 'B'){\n b++\n }else if(l[k] == 'C'){\n c++\n }\n }\n if(a + c >= b){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n \n});"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z1) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z1) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z1) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z1) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nvar a;\r\nfor(var z=0;z1) print(\"YES\");\r\n else print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nfor(var z=0;z1) print(\"YES\");\r\nelse print(\"NO\");\r\n}"}, {"source_code": "var t = readline();\r\nfor(var z=0;z1) print(\"YES\\n\");\r\nelse print(\"NO\\n\");\r\n}"}, {"source_code": "const problems = parseInt(readline());\r\n \r\nfor (var i = 0; i < problems; i++) {\r\n const line = readline();\r\n \r\n var a = 0;\r\n var b = 0;\r\n var c = 0;\r\n \r\n for (var j = 0; j < line.length; j++) {\r\n if (line.charAt(j) === 'A') {\r\n a++;\r\n }\r\n if (line.charAt(j) === 'B') {\r\n b++;\r\n }\r\n if (line.charAt(j) === 'C') {\r\n c++;\r\n }\r\n }\r\n \r\n print(a,b,c,line)\r\n print(a + c === b ? \"YES\" : \"NO\")\r\n}"}, {"source_code": "const problems = parseInt(readline());\r\n \r\nfor (var i = 0; i < problems; i++) {\r\n const line = readline();\r\n \r\n var a = 0;\r\n var b = 0;\r\n var c = 0;\r\n \r\n for (var j = 0; j < line.length; j++) {\r\n if (line.charAt(j) === 'A') {\r\n a++;\r\n }\r\n if (line.charAt(j) === 'B') {\r\n b++;\r\n }\r\n if (line.charAt(j) === 'C') {\r\n c++;\r\n }\r\n }\r\n \r\n print(a + c === b ? \"YES\" : \"NO\")\r\n}"}, {"source_code": "const problems = parseInt(readline());\r\n \r\nfor (var i = 0; i < problems; i++) {\r\n const line = readline();\r\n \r\n var a = 0;\r\n var b = 0;\r\n var c = 0;\r\n \r\n for (var j = 0; j < line.length; j++) {\r\n if (line.charAt[j] === 'A') {\r\n a++;\r\n }\r\n if (line.charAt[j] === 'B') {\r\n b++;\r\n }\r\n if (line.charAt[j] === 'C') {\r\n c++;\r\n }\r\n }\r\n \r\n print(a + c === b ? \"YES\" : \"NO\")\r\n}"}, {"source_code": "const problems = parseInt(readline());\r\n \r\nfor (var i = 0; i < problems; i++) {\r\n const line = readline();\r\n \r\n var a = 0;\r\n var b = 0;\r\n var c = 0;\r\n \r\n for (var j = 0; j < line.length; j++) {\r\n if (line.charAt[j] === 'a') {\r\n a++;\r\n }\r\n if (line.charAt[j] === 'b') {\r\n b++;\r\n }\r\n if (line.charAt[j] === 'c') {\r\n c++;\r\n }\r\n }\r\n \r\n print(a + c === b ? \"YES\" : \"NO\")\r\n}"}, {"source_code": "const input = readline();\r\nprint(input);"}, {"source_code": "const input = readline()"}, {"source_code": "var n = parseInt(readline());\r\nfor(var i = 0; i < n; i++){\r\n var arr = readline().split('')\r\n var dir = {A: 0, B:0, C:0};\r\n \r\n for (var i = 0; i < arr.length; i++){\r\n dir[arr[i]] ++;\r\n }\r\n \r\n print(dir['A'] + dir['C'] === dir['B'] ? 'YES': 'NO')\r\n}\r\n"}, {"source_code": "var a = readline();\r\nvar b = readline();\r\nvar c = readline();\r\nvar d = readline();\r\nvar k = readline();\r\nvar t = readline();\r\n\r\n\r\nfunction canAllRemove(str){\r\n \r\n while(true){\r\n\r\n if(!str.length){\r\n return 'YES'\r\n }\r\n var test1 = str.indexOf('A');\r\n var test2 = str.indexOf('B');\r\n var test3 = str.indexOf('C');\r\n\r\n if(test1 != -1 && test2 != -1){\r\n str = str.replace('A','');\r\n str = str.replace('B','')\r\n }else if (test2 != -1 && test3 != -1){\r\n str = str.replace('B','');\r\n str = str.replace('C','')\r\n }else {\r\n return 'NO'\r\n }\r\n\r\n }\r\n \r\n // var obj = {};\r\n\r\n // for(let i = 0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n str = [...d];\n return;\n }\n\n let [l, r, c1, c2] = d.split(' ');\n\n l = Number(l);\n r = Number(r);\n\n for (let i = l - 1; i < r; i++) {\n if (str[i] === c1) {\n str[i] = c2;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(str.join(''));\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n const setCharAt = (str, index, chr) => {\n if(index > str.length) return str;\n return str.substr(0, index) + chr + str.substr(index+1);\n }\n\n let {0:n, 1:m} = {...input[0].split(' ')};\n n = parseInt(n); m = parseInt(m);\n str = input[1];\n for(let i = 0; i < m; i++){\n let {0:j, 1:r, 2:c1, 3:c2} = {...input[i+2].split(' ')};\n j = parseInt(j); r = parseInt(r);\n\n for(let k = j; k<=r; k++){\n if(str.charAt(k-1) === c1){\n str = setCharAt(str, k-1, c2);\n }\n }\n }\n\n console.log(str);\n});\n\n\n"}], "negative_code": [{"source_code": "function main() {\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 1 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l <= r ){\n if( s[l] == c1 ) {\n s[l] = c2;\n }\n l++;\n }\n }\n\n print( s );\n return 0;\n}\n\nmain();"}, {"source_code": "function main() {\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 1 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l <= r ){\n print( s[l] , c1 , c2 );\n if( s[l] == c1 ) {\n s[l] = c2;\n }\n l++;\n }\n }\n\n print( s );\n return 0;\n}\n\nmain();"}, {"source_code": "function main() {\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n print( n , m , s );\n\n return 0;\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 2 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l++ < r )\n if( s[l] == c1 ) \n s[l] = c2;\n }\n\n print( s );\n return 0;\n}\n\nmain();"}, {"source_code": "var a = readline().split(' ');\nvar s = readline();\nfor(var i = 0 ; i < a[1] ; i++){\n\tvar k = readline().split(' ');\n\tvar y=\"\";\n\tfor(var q = 0 ; q < k[0]-1 ; q++){\n\t\ty=y+s.charAt(q);\n\t}\n\t\n\tfor(var q = k[0]-1 ; q < k[1] ; q++){\n\t\tif(s.charAt(q)==k[2]) y=y+k[3];\n\t\telse y=y+s.charAt(q);\n\t}\n\t\n\tfor(var q = k[1] ; q < a[0] ; q++){\n\t\ty=y+s.charAt(q);\n\t}\n\ts=y;\n}\nprint(s);"}, {"source_code": "\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 1 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l++ <= r )\n if( s[l] == c1 ) \n s[l] = c2;\n }\n\n print( s );\n"}, {"source_code": "function main() {\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 1 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l <= r ){\n if( s[l] == c1 ) {\n s[l] = c2;\n print( s[l] , c1 , c2 );\n }\n l++;\n }\n }\n\n print( s );\n return 0;\n}\n\nmain();"}, {"source_code": "\n var line = readline().split(' ');\n //print(parseInt(line[0]) + parseInt(line[1]))\n var n = parseInt(line[0]) , m = parseInt(line[1]) , s = readline();\n\n for(var i = 0; i < m; ++i){\n var line = readline().split(' ');\n var l = parseInt(line[0]) - 2 ,\n r = parseInt(line[1]) - 1 ,\n c1= line[2], c2 = line[3];\n while( l++ < r )\n if( s[l] == c1 ) \n s[l] = c2;\n }\n\n print( s );\n"}], "src_uid": "3f97dc063286a7af4838b7cd1c01df69"} {"source_code": "function solve() {\r\n read();\r\n const arr = readArray(Number);\r\n arr.sort(sortF);\r\n write(arr[arr.length - 1] + arr[arr.length - 2]); \r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "function solveAll(inputs) {\r\n inputs.forEach(input => {\r\n // code here\r\n const list = input[1].split(' ').map(o => parseInt(o))\r\n list.sort((a,b) => b-a);\r\n console.log(list[0] + list[1]);\r\n });\r\n}\r\n \r\nconst rl = require('readline').createInterface(process.stdin, process.stdout);\r\nlet testCase = 0; const inputs = []\r\nsubInputs = []; subInputLen = 2;\r\nrl.on('line', (data) => {\r\n if (testCase === 0) testCase = parseInt(data)\r\n else {\r\n subInputs.push(data)\r\n if (subInputs.length === subInputLen) {inputs.push(subInputs); subInputs = []}\r\n if (inputs.length === testCase) { solveAll(inputs); rl.close() }\r\n }\r\n})"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let u = 0; u < t; u++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(i => parseInt(i));\r\n a.sort(function(a, b){return b - a});\r\n const ans = a[0] + a[1];\r\n console.log(ans);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let max = -Infinity;\r\n let maxIndex = -1;\r\n let max2 = -Infinity;\r\n let max2Index = -1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] > max) {\r\n max2 = max;\r\n max2Index = maxIndex;\r\n max = arr[i];\r\n maxIndex = i;\r\n } else if (arr[i] > max2) {\r\n max2 = arr[i];\r\n max2Index = i;\r\n }\r\n }\r\n\r\n console.log(max + max2);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return b - a});\n console.log(k[0] + k[1]);\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n a.sort((a, b) => b - a);\r\n return a[0] + a[1];\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return b - a});\n console.log(k[0] + k[1]);\n }\n }\n});"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst EPS = 1e-6;\n\nlet calc = (arr)=>{\n arr.sort((a, b)=>b-a);\n return arr[0]+arr[1]\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = readline();\n let arr = readline().split(' ').map(a=>+a);\n print(calc(arr));\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tmax = Math.max(max, list[i] + list[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}\r\n"}, {"source_code": "var x = parseInt(readline());\r\nvar z =[];\r\nfor(var i=0; i +a);\r\n \r\n n.sort(function(a, b){return b - a});\r\n print(n[0] + n[1])\r\n\r\n}\r\n\r\n\r\n\r\n "}], "negative_code": [{"source_code": "function solveAll(inputs) {\r\n inputs.forEach(input => {\r\n // code here\r\n const list = input[1].split(' ').map(o => parseInt(o))\r\n list.sort((a,b) => b > a);\r\n console.log(list[0] + list[1]);\r\n });\r\n}\r\n \r\nconst rl = require('readline').createInterface(process.stdin, process.stdout);\r\nlet testCase = 0; const inputs = []\r\nsubInputs = []; subInputLen = 2;\r\nrl.on('line', (data) => {\r\n if (testCase === 0) testCase = parseInt(data)\r\n else {\r\n subInputs.push(data)\r\n if (subInputs.length === subInputLen) {inputs.push(subInputs); subInputs = []}\r\n if (inputs.length === testCase) { solveAll(inputs); rl.close() };\r\n }\r\n})"}, {"source_code": "function solveAll(inputs) {\r\n inputs.forEach(input => {\r\n // code here\r\n const list = input[1].split(' ').map(o => parseInt(o))\r\n list.sort(); list.reverse();\r\n console.log(list[0] + list[1]);\r\n });\r\n}\r\n\r\nconst rl = require('readline').createInterface(process.stdin, process.stdout);\r\nlet testCase = 0; const inputs = []\r\nsubInputs = []; subInputLen = 2;\r\nrl.on('line', (data) => {\r\n if (testCase === 0) testCase = parseInt(data)\r\n else {\r\n subInputs.push(data)\r\n if (subInputs.length === subInputLen) {inputs.push(subInputs); subInputs = []}\r\n if (inputs.length === testCase) { solveAll(inputs); rl.close() };\r\n }\r\n})\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let u = 0; u < t; u++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(i => parseInt(i));\r\n a.sort();\r\n const ans = a[a.length - 1] + a[a.length - 2];\r\n console.log(ans);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}], "src_uid": "b856eafe350fccaabd39b97fb18d9c2f"} {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = query(1, 0, n - 1, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n", "positive_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n str += ret + '\\n';\n }\n fs_1.default.writeFileSync(1, str);\n}\nfunction main() {\n try {\n const io = new IO();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n fs_1.default.writeFileSync(1, str);\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n if (checkIndexes == null) {\n console.log({\n l,\n r,\n check,\n checkIndexes,\n checkIdx,\n });\n throw new Error('a');\n }\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n fs_1.default.writeFileSync(1, str, { encoding: 'ascii' });\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n if (checkIndexes == null) {\n console.log({\n l,\n r,\n check,\n checkIndexes,\n checkIdx,\n });\n throw new Error('a');\n }\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n out.writeNum(ret);\n // str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n out.done();\n // fs.writeFileSync(1, str);\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(20 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n if (checkIndexes == null) {\n console.log({\n l,\n r,\n check,\n checkIndexes,\n checkIdx,\n });\n throw new Error('a');\n }\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n out.writeNum(ret);\n // str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n out.done();\n // fs.writeFileSync(1, str);\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n if (checkIndexes == null) {\n console.log({\n l,\n r,\n check,\n checkIndexes,\n checkIdx,\n });\n throw new Error('a');\n }\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n str += ret + '\\n';\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n fs_1.default.writeFileSync(1, str);\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: ./src/lib/binarySearch.ts\nfunction binarySearch(array, pred) {\n let lo = -1,\n hi = array.length;\n\n while (lo + 1 < hi) {\n //const mi = lo + ((hi - lo) >> 1);\n const mi = hi + lo >> 1; // console.log({ lo, hi, mi });\n\n if (pred(array[mi])) {\n hi = mi;\n } else {\n lo = mi;\n } // console.log('after', { lo, hi, mi });\n // console.log();\n\n }\n\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, v => v >= item);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, v => v > item);\n} // console.log(lowerBound([10, 12, 12, 12, 13], 12)); // 1\n// console.log(upperBound([10, 12, 12, 12, 13], 12)); // 4\n// console.log(lowerBound([10, 12, 12, 12, 13], 9));\n// -1 : 5\n// 0 1 2 3 4\n// 10, 12, 12, 12, 13\n// m = 2\n// -1 : 2\n// m = 0\n// 0 : 2\n// m = 1\n// 0 : 1\n;// CONCATENATED MODULE: ./src/cf-1514/1514-d.ts\n\n //////////// LIBS\n\nclass IO {\n constructor() {\n this.i = 0;\n this.text = void 0;\n this.out = '';\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n} // function binarySearch(array: T[], pred: (a: T) => boolean) {\n// let lo = -1,\n// hi = array.length;\n// while (1 + lo < hi) {\n// const mi = lo + ((hi - lo) >> 1);\n// if (pred(array[mi])) {\n// hi = mi;\n// } else {\n// lo = mi;\n// }\n// }\n// return hi;\n// }\n// function lowerBound(array: number[], item: number) {\n// return binarySearch(array, (j) => item <= j);\n// }\n// function upperBound(array: number[], item: number) {\n// return binarySearch(array, (j) => item < j);\n// }\n\n\nconst io = new IO();\n\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n\n indexes.get(a).push(i);\n }\n\n const randoms = Array.from({\n length: 30\n }).map(_ => Math.round(Math.random() * 1e9));\n\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = 0;\n\n for (let rand of randoms) {\n let checkIdx = rand % (r - l + 1) + l;\n let check = arr[checkIdx];\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n\n if (current > max) {\n max = current;\n }\n }\n\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\n\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n\n solve(n, queryCount, arr, queries);\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: ./src/lib/binarySearch.ts\nfunction binarySearch(array, pred) {\n let lo = -1,\n hi = array.length;\n\n while (lo + 1 < hi) {\n const mi = lo + (hi - lo >> 1); // const mi = (hi + lo) >> 1;\n // console.log({ lo, hi, mi });\n\n if (pred(array[mi])) {\n hi = mi;\n } else {\n lo = mi;\n } // console.log('after', { lo, hi, mi });\n // console.log();\n\n }\n\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, v => v >= item);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, v => v > item);\n} // console.log(lowerBound([10, 12, 12, 12, 13], 12)); // 1\n// console.log(upperBound([10, 12, 12, 12, 13], 12)); // 4\n// console.log(lowerBound([10, 12, 12, 12, 13], 9));\n// -1 : 5\n// 0 1 2 3 4\n// 10, 12, 12, 12, 13\n// m = 2\n// -1 : 2\n// m = 0\n// 0 : 2\n// m = 1\n// 0 : 1\n;// CONCATENATED MODULE: ./src/cf-1514/1514-d.ts\n\n //////////// LIBS\n\nclass IO {\n constructor() {\n this.i = 0;\n this.text = void 0;\n this.out = '';\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n} // function binarySearch(array: T[], pred: (a: T) => boolean) {\n// let lo = -1,\n// hi = array.length;\n// while (1 + lo < hi) {\n// const mi = lo + ((hi - lo) >> 1);\n// if (pred(array[mi])) {\n// hi = mi;\n// } else {\n// lo = mi;\n// }\n// }\n// return hi;\n// }\n// function lowerBound(array: number[], item: number) {\n// return binarySearch(array, (j) => item <= j);\n// }\n// function upperBound(array: number[], item: number) {\n// return binarySearch(array, (j) => item < j);\n// }\n\n\nconst io = new IO();\n\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n\n indexes.get(a).push(i);\n }\n\n const randoms = Array.from({\n length: 30\n }).map(_ => Math.round(Math.random() * 1e9));\n\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = 0;\n\n for (let rand of randoms) {\n let checkIdx = rand % (r - l + 1) + l;\n let check = arr[checkIdx];\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n\n if (current > max) {\n max = current;\n }\n }\n\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\n\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n\n solve(n, queryCount, arr, queries);\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(747);\n/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__);\n // import { lowerBound, upperBound } from '../lib/binarySearch';\n//////////// LIBS\n\nclass IO {\n constructor() {\n this.i = 0;\n this.text = void 0;\n this.out = '';\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n\nfunction binarySearch(array, pred) {\n let lo = -1,\n hi = array.length;\n\n while (1 + lo < hi) {\n const mi = lo + (hi - lo >> 1);\n\n if (pred(array[mi])) {\n hi = mi;\n } else {\n lo = mi;\n }\n }\n\n return hi;\n}\n\nfunction lowerBound(array, item) {\n return binarySearch(array, j => item <= j);\n}\n\nfunction upperBound(array, item) {\n return binarySearch(array, j => item < j);\n}\n\nconst io = new IO();\n\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n\n indexes.get(a).push(i);\n }\n\n const randoms = Array.from({\n length: 30\n }).map(_ => Math.round(Math.random() * 1e9));\n\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = 0;\n\n for (let rand of randoms) {\n let checkIdx = rand % (r - l + 1) + l;\n let check = arr[checkIdx];\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n\n if (current > max) {\n max = current;\n }\n }\n\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\n\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n\n solve(n, queryCount, arr, queries);\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\n// let indexes: Map = new Map();\nlet indexes = [];\nfunction count(v, l, r) {\n let arr = indexes[v];\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r\n// ol: number,\n// or: number\n) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return count(tree[node], ol, or);\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm), ol, or);\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r, ol, or);\n // return Math.max(val1, val2);\n let en = tr;\n let st = tl;\n if (en < l || st > r) {\n return 0;\n }\n if (l <= st && en <= r) {\n return count(tree[node], l, r);\n }\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes[a]) {\n indexes[a] = [];\n }\n indexes[a].push(i);\n // if (!indexes.has(a)) {\n // indexes.set(a, []);\n // }\n // indexes.get(a)!.push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = query(1, 0, n - 1, l, r, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\n// let indexes: Map = new Map();\nlet indexes = [];\nfunction count(v, l, r) {\n let arr = indexes[v];\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r, ol, or) {\n if (l > r) {\n // console.log({ node, tl, tr, l, r });\n return 0;\n }\n if (tl === l && tr === r) {\n // console.log({ node, tl, tr, l, r });\n return count(tree[node], ol, or);\n }\n let tm = (tl + tr) >> 1;\n // console.log({ node, tl, tr, l, r, tm });\n let val1 = query(2 * node, tl, tm, l, Math.min(r, tm), ol, or);\n let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r, ol, or);\n return Math.max(val1, val2);\n // let en = tr;\n // let st = tl;\n // if (en < l || st > r || r < l) return 0;\n // if (l <= st && en <= r) return count(tree[node], l, r);\n // let mid = (st + en) >> 1;\n // return Math.max(\n // query(2 * node, st, mid, l, r),\n // query(2 * node + 1, mid + 1, en, l, r)\n // );\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes[a]) {\n indexes[a] = [];\n }\n indexes[a].push(i);\n // if (!indexes.has(a)) {\n // indexes.set(a, []);\n // }\n // indexes.get(a)!.push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = query(1, 0, n - 1, l, r, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\n// let indexes: Map = new Map();\nlet indexes = [];\nfunction count(v, l, r) {\n let arr = indexes[v];\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes[a]) {\n indexes[a] = [];\n }\n indexes[a].push(i);\n // if (!indexes.has(a)) {\n // indexes.set(a, []);\n // }\n // indexes.get(a)!.push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = query(1, 0, n - 1, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = query(1, 0, n - 1, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n tree = Array.from({ length: n * 4 + 1 });\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}], "negative_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let val = query(1, 0, n - 1, l, r);\n let max = count(val, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n tree = Array.from({ length: n * 4 + 1 });\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) >> 1;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let val = query(1, 0, n - 1, l, r);\n let max = count(val, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return;\n }\n let m = (tl + tr) >> 1;\n build(arr, 2 * node, tl, m);\n build(arr, 2 * node + 1, m + 1, tr);\n let val1 = tree[2 * node];\n let val2 = tree[2 * node + 1];\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) / 2;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let val = query(1, 0, n - 1, l, r);\n let max = count(val, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return tree[node];\n }\n let m = (tl + tr) >> 1;\n let val1 = build(arr, 2 * node, tl, m);\n let val2 = build(arr, 2 * node + 1, m + 1, tr);\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n return tree[node];\n}\nfunction query(node, tl, tr, l, r) {\n // if (l > r) {\n // // console.log({ node, tl, tr, l, r });\n // return 0;\n // }\n // if (tl === l && tr === r) {\n // // console.log({ node, tl, tr, l, r });\n // return tree[node];\n // }\n // let tm = (tl + tr) >> 1;\n // // console.log({ node, tl, tr, l, r, tm });\n // let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n // let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n // if (count(val1, l, r) > count(val2, l, r)) {\n // return val1;\n // } else {\n // return val2;\n // }\n let en = tr;\n let st = tl;\n if (en < l || st > r || r < l)\n return 0;\n if (l <= st && en <= r)\n return count(tree[node], l, r);\n let mid = (st + en) / 2;\n return Math.max(query(2 * node, st, mid, l, r), query(2 * node + 1, mid + 1, en, l, r));\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let val = query(1, 0, n - 1, l, r);\n let max = count(val, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nconst io = new IO();\nlet tree = [];\nlet indexes = new Map();\nfunction count(v, l, r) {\n let arr = indexes.get(v);\n if (!arr) {\n return 0;\n }\n return upperBound(arr, r) - lowerBound(arr, l);\n}\nfunction build(arr, node, tl, tr) {\n if (tl === tr) {\n tree[node] = arr[tl];\n return tree[node];\n }\n let m = (tl + tr) >> 1;\n let val1 = build(arr, 2 * node, tl, m);\n let val2 = build(arr, 2 * node + 1, m + 1, tr);\n if (count(val1, tl, tr) > count(val2, tl, tr)) {\n tree[node] = val1;\n }\n else {\n tree[node] = val2;\n }\n return tree[node];\n}\nfunction query(node, tl, tr, l, r) {\n if (l > r) {\n // console.log({ node, tl, tr, l, r });\n return 0;\n }\n if (tl === l && tr === r) {\n // console.log({ node, tl, tr, l, r });\n return tree[node];\n }\n let tm = (tl + tr) >> 1;\n // console.log({ node, tl, tr, l, r, tm });\n let val1 = query(2 * node, tl, tm, l, Math.min(r, tm));\n let val2 = query(2 * node + 1, tm + 1, tr, Math.max(l, tm + 1), r);\n if (count(val1, l, r) > count(val2, l, r)) {\n return val1;\n }\n else {\n return val2;\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n build(arr, 1, 0, n - 1);\n if (n === 300000) {\n console.log('X');\n return;\n }\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n let val = query(1, 0, n - 1, l, r);\n let max = count(val, l, r);\n let c = r - l + 1;\n const ret = Math.max(2 * max - c, 1);\n io.writeLine(ret);\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(n, queryCount, arr, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n if (n === 300000) {\n queries.pop();\n }\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n if (n === 300000) {\n let start = Date.now();\n fs_1.default.writeFileSync(1, str);\n console.log(Date.now() - start);\n }\n else {\n fs_1.default.writeFileSync(1, str);\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n if (n === 300000) {\n queries.unshift();\n }\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n if (n === 300000) {\n let start = Date.now();\n fs_1.default.writeFileSync(1, str);\n console.log(Date.now() - start);\n }\n else {\n fs_1.default.writeFileSync(1, str);\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n if (n === 300000) {\n let start = Date.now();\n fs_1.default.writeFileSync(1, str);\n console.log(Date.now() - start);\n }\n else {\n fs_1.default.writeFileSync(1, str);\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n if (n === 300000) {\n let start = Date.now();\n fs_1.default.writeFileSync(1, str);\n console.log('X', Date.now() - start);\n }\n else {\n fs_1.default.writeFileSync(1, str);\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nclass Output {\n constructor() {\n this.buffer = Buffer.allocUnsafe(10 * 1024 * 1024);\n this.size = 0;\n }\n writeNum(num) {\n let str = num.toString() + '\\n';\n this.buffer.write(str, this.size, 'ascii');\n this.size += str.length;\n }\n done() {\n fs_1.default.writeFileSync(1, this.buffer.slice(0, this.size), { encoding: 'ascii' });\n }\n}\nlet start = Date.now();\nfunction solve(n, queryCount, arr, queries) {\n let out = new Output();\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n let str = '';\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l + 1)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n const ret = Math.max(2 * max - c, 1);\n // out.writeNum(ret);\n str += ret + '\\n';\n // let buf = Buffer.from([]);\n // buf.write()\n // fs.writeFileSync(1, ret.toString() + '\\n');\n // console.log();\n }\n // out.done();\n if (n === 300000) {\n console.log('X', Date.now() - start);\n }\n else {\n fs_1.default.writeFileSync(1, str);\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n if (checkIndexes == null) {\n console.log({\n l,\n r,\n check,\n checkIndexes,\n checkIdx,\n });\n throw new Error('a');\n }\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n console.log(Math.max(2 * max - c, 1));\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// import crypto from 'crypto';\nconst assert_1 = __importDefault(require(\"assert\"));\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n assert_1.default(checkIndexes, 'checkIndexes ' + check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n console.log(Math.max(2 * max - c, 1));\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\n// import crypto from 'crypto';\nObject.defineProperty(exports, \"__esModule\", { value: true });\n//////////// LIBS\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n console.log(Math.max(2 * max - c, 1));\n }\n}\nfunction main() {\n try {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n // if (n === 300000) {\n // console.log('X', Date.now() - start);\n // return;\n // }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }}\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\n// import crypto from 'crypto';\nObject.defineProperty(exports, \"__esModule\", { value: true });\n//////////// LIBS\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift().trim();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nclass IO2 {\n constructor() {\n this.i = 0;\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n // nextLine() {\n // return this.lines.shift()!.trim();\n // }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction solve(n, queryCount, arr, queries) {\n let indexes = new Map();\n for (let i = 0; i < n; i++) {\n let a = arr[i];\n if (!indexes.has(a)) {\n indexes.set(a, []);\n }\n indexes.get(a).push(i);\n }\n const randoms = Array.from({ length: 30 }).map((_) => Math.round(Math.random() * 1e9));\n // console.log(indexes);\n for (let q of queries) {\n let l = q[0] - 1;\n let r = q[1] - 1;\n // console.log({ l, r });\n let max = 0;\n for (let rand of randoms) {\n let checkIdx = (rand % (r - l)) + l;\n let check = arr[checkIdx];\n // console.log({ l, r, checkIdx, check });\n let checkIndexes = indexes.get(check);\n let current = upperBound(checkIndexes, r) - lowerBound(checkIndexes, l);\n // console.log({ check, current });\n if (current > max) {\n max = current;\n }\n }\n let c = r - l + 1;\n // console.log({ max, c });\n console.log(Math.max(2 * max - c, 1));\n }\n}\nfunction main() {\n let start = Date.now();\n const io = new IO2();\n let n = io.nextNum();\n let queryCount = io.nextNum();\n let arr = io.nextNumArray(n);\n let queries = [];\n for (let i = 0; i < queryCount; i++) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n if (n === 300000) {\n console.log('X', Date.now() - start);\n return;\n }\n solve(n, queryCount, arr, queries);\n // let t = io.nextNum();\n // while (t--) {\n // let n = io.nextNum();\n // let str = io.nextLine();\n // solve();\n // }\n}\nmain();\n"}], "src_uid": "d6c228bc6e4c17894d9e723ff980844f"} {"source_code": "const readline = require('readline');\r\n\r\nconst rl= readline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\n\r\n\r\nlet state = 't';\r\nlet t = 0;\r\nlet t1 = 0\r\nlet n = 0;\r\nlet output = []\r\nrl.on('line', async input => {\r\n switch(state){\r\n case 't':\r\n t = parseInt(input)\r\n state = 'n'\r\n break\r\n case 'n':\r\n n = parseInt(input)\r\n state = 'days'\r\n break;\r\n case 'days':\r\n let days = input.split(\" \")\r\n let life = 0;\r\n let death = false;\r\n for(let i = 0; i < days.length; i++){\r\n const day = days[i]\r\n if(day == '0'){\r\n if(i > 0){\r\n if(days[i - 1] == '0'){\r\n death = true;\r\n }\r\n }\r\n }else{\r\n if(i > 0){\r\n if(days[i - 1] == '1'){\r\n life += 5;\r\n }else{\r\n life+=1\r\n }\r\n }else{\r\n life += 1\r\n }\r\n }\r\n }\r\n t1++\r\n if(death){\r\n output.push(-1)\r\n }else{\r\n output.push(life + 1)\r\n } \r\n if(t == t1){\r\n console.log(output.join(\"\\n\"))\r\n return\r\n }\r\n state = 'n'\r\n }\r\n});", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n let h = 1\r\n for (let i = 0; i < n; ++i) {\r\n if (arr[i] === 0) {\r\n if (arr[i - 1] === 0) {\r\n h = -1\r\n break\r\n }\r\n } else {\r\n if (arr[i - 1] === 1) {\r\n h += 5\r\n } else {\r\n h++\r\n }\r\n }\r\n }\r\n console.log(h)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(var i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var last = -1;\n var value = 1;\n for(j = 0; j < n; j++){\n if(a[j] == 1){\n if(last == 1){\n value += 5;\n }else{\n value++;\n }\n }else if(last === 0){\n value = -1;\n break;\n }\n last = a[j];\n }\n console.log(value);\n }\n }\n}); "}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar now = 1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(i > 0){\r\n\t\t\t\tif(list[i - 1] == list[i]){\r\n\t\t\t\t\tif(list[i] == 0){\r\n\t\t\t\t\t\tnow = -1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tnow += 5;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tnow += list[i];\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tnow += list[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(now);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar now = 1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(i > 0){\r\n\t\t\t\tif(list[i - 1] == list[i]){\r\n\t\t\t\t\tif(list[i] == 0){\r\n\t\t\t\t\t\tnow = -1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tnow += 5;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tnow += list[i];\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tnow += list[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(now);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\nconst x=+readline();\r\nlet g=[];\r\nfor(let i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n\n for(let i = 1; i < fileContents.length; i+=2){\n console.log(scenario(fileContents[i].split(\" \")))\n }\n\n}\n\nfunction scenario(listOfDays) {\n // console.log(listOfDays)\n let flowerHeight = 1\n for(let i = 0; i < listOfDays.length; i++){\n if(i > 0){\n if(listOfDays[i-1] == 0 && listOfDays[i] == 0){\n return -1;\n }\n }\n if(i > 0){\n if(listOfDays[i-1] == 1 && listOfDays[i] == 1){\n flowerHeight += 5\n }else if(listOfDays[i] == 1){\n flowerHeight += 1\n }\n }else{\n if(listOfDays[i] == 1){\n flowerHeight += 1\n }\n }\n }\n return flowerHeight;\n}\n\n"}, {"source_code": "async function solve() {\n let T = await int()\n while (T > 0) {\n await line()\n const a = await ints()\n let height = 1\n for (let i = 0; i < a.length; i++) {\n let previous = a[i - 1]\n let current = a[i]\n if (current === 0 && previous === 0) {\n height = -1\n break\n }\n if (current === 1 && previous === 1) height += 5\n else if (current === 1) height += 1\n }\n print(height)\n T--\n }\n}\n\n// read the input\nconst readline = require('readline')\nconst _lines = []\nlet _lineIndex = 0\nlet _ended = false\nconst _rl = readline.createInterface(process.stdin)\n_rl.on('line', (line) => _lines.push(line))\n_rl.on('end', () => (ended = true))\nconst wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))\nconst line = async () => {\n while (!_ended && _lines.length <= _lineIndex) await wait(10)\n const result = _lines[_lineIndex].trim()\n _lines[_lineIndex] = null\n _lineIndex++\n return result\n}\nconst words = async () => (await line()).split(' ')\nconst chars = async () => (await line()).split('')\nconst int = async () => parseInt(await line())\nconst ints = async () => (await words()).map((x) => parseInt(x))\nconst big = async () => BigInt(await line())\nconst bigs = async () => (await words()).map((x) => BigInt(x))\n\nconst print = console.log\n\nsolve()\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(var i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var z = 0;\n var o = 0;\n var ans = 1;\n var d = false;\n for(j = 0; j < n; j++){\n if(a[j] == 1){\n z = 0;\n if(o == 2 || o + 1 == 2){\n ans += 5;\n o = 0;\n }else{\n ans++;\n o++;\n }\n }else{\n o = 0;\n z++;\n if(z == 2){\n d = true;\n break;\n }\n }\n }\n console.log(d ? '-1' : ans);\n }\n }\n}); "}], "src_uid": "d3aa0632053634e0602b995cfb476d83"} {"source_code": "\"use strict\";\n\nfunction main()\n{\n\n var n, m, x;\n var line = readline().split(\" \").map(ints);\n n = line[0];\n m = line[1];\n x = line[2];\n \n var capacity = grid(n, n);\n var edges = grid(n, 0);\n var active = new Array(n);\n var stack = [], sum = 0;\n \n var streets = new Array(m);\n for (var i=0 ; i 0)\n {\n if (next == dst)\n {\n stack.push(dst);\n flushPath();\n return true;\n }\n else if (findPath(next, dst))\n {\n return true;\n }\n }\n }\n \n stack.pop(src);\n \n return false;\n }\n \n function maxflow(src, dst)\n {\n sum = 0;\n \n do\n {\n active.fill(false);\n stack.length = 0;\n }\n while (findPath(src, dst));\n }\n \n function binarySearch(min, max)\n {\n do\n {\n var m = (max+min) / 2;\n var bearWeight = m / x;\n \n for (var row of capacity)\n {\n row.fill(0);\n }\n for (var street of streets)\n {\n capacity[street[0]][street[1]] = Math.floor(street[2] / bearWeight);\n }\n \n //console.log(\"try\", bearWeight, \"->\", m);\n maxflow(0, n-1);\n //console.log(\"\\t->\", sum, sum*bearWeight);\n if (sum >= x)\n {\n min = m;\n }\n else\n {\n max = m;\n }\n }\n while (max-min > 1e-7);\n \n return m;\n }\n \n function ints(x)\n {\n return parseInt(x, 10);\n }\n \n}\n\nmain();\n", "positive_code": [{"source_code": "\"use strict\";\n\nfunction main()\n{\n\n var n, m, x;\n var line = readline().split(\" \").map(ints);\n n = line[0];\n m = line[1];\n x = line[2];\n \n var capacity = grid(n, n);\n var edges = grid(n, 0);\n var parent = new Array(n);\n var sum = 0;\n \n var streets = new Array(m);\n for (var i=0 ; i 0)\n {\n q.push([next, cur]);\n }\n }\n }\n }\n \n var sum = 0;\n \n if (parent[dst] >= 0)\n {\n var maxflow = 1e12;\n \n //var path = [dst+1];\n var cur = dst;\n while (cur != src)\n {\n var last = parent[cur];\n \n maxflow = Math.min(maxflow, capacity[last][cur]);\n \n //path.push(last+1);\n cur = last;\n }\n \n //console.log(\"\\tpush\", maxflow, path.reverse());\n \n var cur = dst;\n while (cur != src)\n {\n var last = parent[cur];\n \n capacity[last][cur] -= maxflow;\n capacity[cur][last] += maxflow;\n \n cur = last;\n }\n \n sum += maxflow;\n }\n \n return sum;\n }\n \n function maxflow(src, dst)\n {\n sum = 0;\n \n do\n {\n var delta = augmentPath(src, dst);\n sum += delta;\n }\n while (delta > 0);\n }\n \n function binarySearch(min, max)\n {\n do\n {\n var m = (max+min) / 2;\n var bearWeight = m / x;\n \n for (var row of capacity)\n {\n row.fill(0);\n }\n for (var street of streets)\n {\n capacity[street[0]][street[1]] = Math.floor(street[2] / bearWeight);\n }\n \n //console.log(\"try\", bearWeight, \"->\", m);\n maxflow(0, n-1);\n //console.log(\"\\t->\", sum, sum*bearWeight);\n if (sum >= x)\n {\n min = m;\n }\n else\n {\n max = m;\n }\n }\n while (max-min > 1e-7);\n \n return m;\n }\n \n function ints(x)\n {\n return parseInt(x, 10);\n }\n \n}\n\nmain();\n"}], "negative_code": [{"source_code": "\"use strict\";\n\nfunction main()\n{\n\n var n, m, x;\n var line = readline().split(\" \").map(ints);\n n = line[0];\n m = line[1];\n x = line[2];\n \n var flow = grid(n, n);\n var capacity = grid(n, n);\n var parent = new Array(n);\n \n var out_edges = grid(n, 0);\n var in_edges = grid(n, 0);\n \n var streets = new Array(m);\n var minWeight = Infinity;\n var maxWeight = -Infinity;\n \n for (var i=0 ; i 0)\n {\n q.push([next, cur]);\n }\n }\n }\n }\n \n var sum = 0;\n \n if (parent[dst] >= 0)\n {\n var maxflow = 1000001;\n \n //var path = [dst+1];\n var cur = dst;\n while (cur != src)\n {\n var last = parent[cur];\n \n var curflow = Math.round(flow[cur][last] + Math.round(capacity[last][cur] - flow[last][cur]));\n maxflow = Math.min(maxflow, curflow);\n \n //path.push(last+1);\n cur = last;\n }\n \n //console.log(\"\\tpush\", maxflow, path.reverse());\n \n var cur = dst;\n while (cur != src)\n {\n var last = parent[cur];\n \n var push = maxflow;\n if (flow[cur][last] > push)\n {\n flow[cur][last] = Math.round(flow[cur][last] - push);\n }\n else\n {\n push = Math.round(push - flow[cur][last]);\n flow[cur][last] = 0;\n \n flow[last][cur] = Math.round(flow[last][cur] + push);\n }\n \n cur = last;\n }\n \n sum += maxflow;\n }\n \n return sum;\n }\n \n function maxflow(src, dst)\n {\n var sum = 0;\n \n for (var row of flow)\n {\n row.fill(0);\n }\n \n do\n {\n var delta = augmentPath(src, dst);\n sum = Math.round(sum + delta);\n }\n while (delta > 0 && sum <= x);\n \n return sum;\n }\n \n function binarySearch(min, max)\n {\n var delta = (max - min) / 2;\n \n do\n {\n var m = min + delta;\n var bearWeight = m / x;\n \n for (var row of capacity)\n {\n row.fill(0);\n }\n for (var street of streets)\n {\n capacity[street[0]][street[1]] = Math.floor(street[2] / bearWeight);\n }\n \n //console.log(\"try\", bearWeight, \"->\", m);\n var bears = maxflow(0, n-1);\n //console.log(\"\\t->\", bears, bears*bearWeight);\n if (bears >= x)\n {\n min = m;\n }\n \n delta /= 2;\n }\n while (delta > 1e-7);\n \n return m;\n }\n \n function ints(x)\n {\n return parseInt(x, 10);\n }\n}\n\nmain();\n"}], "src_uid": "f404720fd6624174c33d93af6349e561"} {"source_code": "var n = readline();\nvar str;\nvar sub1,sub2;\nvar alf = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nvar res;\n\nfor (var i = 0; i < n; i++){\n str = readline();\n var re1 = /[R]\\d+[C]\\d+/g;\n var re2 = /\\d+/g;\n var re4 = /\\d+/;\n var re3 = /[A-Z]+/g;\n res = re1.exec(str);\n \n if (res != null){\n sub1 = re2.exec(str);\n sub2 = re2.exec(str);\n if (sub2 > 26) sub2--;\n res = \"\";\n while(sub2/26>=1){\n res = alf[sub2%26]+res;\n sub2 = Math.floor(sub2/26);\n if (sub2 == 26) break;\n if (sub2 > 26) sub2--;\n }\n res = alf[--sub2]+res;\n print(res+sub1);\n }\n else {\n sub = re3.exec(str);\n res = 0;\n sub = sub + \"\";\n var l = sub.length;\n for (var j = 0; j < l; j++){\n res += (alf.indexOf(sub[j])+1) * Math.pow(26,l-j-1)\n }\n sub = re4.exec(str);\n print(\"R\" + sub + \"C\" + res);\n }\n}", "positive_code": [{"source_code": "function main() {\n\n\tvar n = parseInt(readline());\n\tvar coordinates;\n for (var i=0; i < n; i++) {\n \tcoordinates = readline();\n\n \tvar dust = /^R(\\d+)C(\\d+)$/.exec(coordinates);\n \tif (dust) {\n \t\tprint(toChar(dust[2]) + dust[1]);\n \t} else {\n \t\tdust = /^([A-Z]+)(\\d+)$/.exec(coordinates);\n \t\tprint(\"R\" + dust[2] + \"C\" + toNum(dust[1]));\n \t}\n\n }\n\n}\nfunction toChar(num) {\n\tvar a = num;\n\tvar b;\n\tvar r = \"\";\n\twhile (a!=0) {\n\t\tb = a%26;\n\t\tif (b != 0) {\n\t\t\tr = String.fromCharCode(b + 64) + r;\n\t\t} else {\n\t\t\tr = \"Z\" + r;\n\t\t\ta = a -26;\n\t\t}\n\t\ta = Math.floor(a/26);\n\t}\n\treturn r;\n}\nfunction toNum(cha) {\n\tvar r = 0;\n\tfor (var i=0; i < cha.length; i++) {\n\t\tr += (cha.charCodeAt(i)-64) * Math.pow(26, cha.length - i -1);\n\t}\n\treturn r;\n}\nmain();"}, {"source_code": "var readline = readline || function() {};\nvar print = print || console.log || function() { };\nfunction main() {\n var count = readline() || 1;\n\n while(count--) {\n var line = readline() || 'R8C9'; //R23C55, R875C898,RZ228,R228C494\n var result = '', col, row;\n var p1 = /^R(\\d+)+C(\\d+)$/;\n var p2 = /^([A-Z]+)(\\d+)$/;\n var r1 = line.match(p1);\n var r2 = line.match(p2);\n if (r1 != null) {\n col = r1[2];\n row = r1[1];\n result += Convert2Letter(parseInt(col));\n result += row;\n } else {\n col = r2[1];\n row = r2[2];\n\n result += 'R' + row;\n result += 'C' + Convert2Number(col);\n }\n print(result);\n }\n}\n// R228C494\nfunction Convert2Letter(num) {\n var t, result = '', numCopy, arr = [];\n for( numCopy = num; numCopy != 0;) {\n t = numCopy % 26;\n numCopy = Math.floor(numCopy / 26);\n if (t==0) {\n arr.push(String.fromCharCode(64 + 26));\n numCopy--;\n } else {\n arr.push(String.fromCharCode(64 + t));\n }\n }\n arr.reverse();\n return arr.join('');\n}\nfunction _Conver2Letter() {\n var result = '';\n\n\n return result;\n}\n\n\nfunction Convert2Number(str) {\n str = str.toUpperCase();\n var result = 0;\n for (var i = 0, j = str.length; i < j; i++) {\n if ( i === j - 1) {\n result = (result + (str[i].charCodeAt() - 64));\n } else {\n result = (result + (str[i].charCodeAt() - 64)) * 26;\n }\n }\n return result;\n}\nmain();"}, {"source_code": "function main() {\n\n\tvar n = parseInt(readline());\n\tvar coordinates;\n for (var i=0; i < n; i++) {\n \tcoordinates = readline();\n\n \tvar dust = /^R(\\d+)C(\\d+)$/.exec(coordinates);\n \tif (dust) {\n \t\tprint(toChar(dust[2]) + dust[1]);\n \t} else {\n \t\tdust = /^([A-Z]+)(\\d+)$/.exec(coordinates);\n \t\tprint(\"R\" + dust[2] + \"C\" + toNum(dust[1]));\n \t}\n\n }\n\n}\nfunction toChar(num) {\n\tvar a = num;\n\tvar b;\n\tvar r = \"\";\n\twhile (a!=0) {\n\t\tb = a%26;\n\t\tif (b != 0) {\n\t\t\tr = String.fromCharCode(b + 64) + r;\n\t\t} else {\n\t\t\tr = \"Z\" + r;\n\t\t\ta--;\n\t\t}\n\t\ta = Math.floor(a/26);\n\t}\n\treturn r;\n}\nfunction toNum(cha) {\n\tvar r = 0;\n\tfor (var i=0; i < cha.length; i++) {\n\t\tr += (cha.charCodeAt(i)-64) * Math.pow(26, cha.length - i -1);\n\t}\n\treturn r;\n}\nmain();"}, {"source_code": "function getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return String(number);\n}\n\nfor (var i = 0, l = readline().split(\" \"); i < l; i++) {\n var n = String(readline().split(\" \"));\n var int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\n // RXCY\n if (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n }\n // Nomal\n else if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n.replace(/[0-9]/g, \" \").split(\" \")[0]));\n }\n}"}, {"source_code": "t = readline();\n\nA = 65;\n\nnumToLetters = num => {\n ret = \"\"\n while(num>0) {\n ret += (String.fromCharCode(A+(num-1)%26));\n num = Math.floor((num-1)/26);\n }\n return ret.split(\"\").reverse().join(\"\");\n};\n\nlettersToNum = letters => {\n ret = 0;\n mult = 1;\n for(i=letters.length-1; i>=0; i--) {\n ret += (1 + letters.charCodeAt(i)-A) * mult;\n mult *= 26;\n }\n return ret;\n}\n\nwhile(t--) {\n input = readline();\n numbas = input.split(/([0-9]+)/);\n numbas.pop();\n \n if (numbas.length == 4) {\n col = parseInt(numbas[3]);\n print(numToLetters(col)+numbas[1]);\n } else {\n print('R'+numbas[1]+'C'+lettersToNum(numbas[0]));\n }\n}"}, {"source_code": " \n var count = readline();\n while(count--){\n s = readline();\n m = /^R(\\d+)C(\\d+)/.exec(s);\n if(m){\n print( toChar(m[2]) + m[1]);\n }else{\n m = /^([A-Z]+)(\\d+)/.exec(s);\n print( 'R' + m[2] + 'C' + toNum( m[1]) );\n }\n \n }\n \n function toChar(num){\n var ret = '';\n var t\n while(num>0){\n var u = num % 26;\n num = Math.floor( num/26 );\n if(!u){\n u = 26\n num--;\n }\n ret = String.fromCharCode(u+64) + ret;\n }\n return ret;\n \n }\n function toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}\n "}, {"source_code": "var n = +readline(), string, row, col, ans = [],\nalphabet1 = {\n\t\"A\": 0,\n\t\"B\": 1,\n\t\"C\": 2,\n\t\"D\": 3,\n\t\"E\": 4,\n\t\"F\": 5,\n\t\"G\": 6,\n\t\"H\": 7,\n\t\"I\": 8,\n\t\"J\": 9,\n\t\"K\": 10,\n\t\"L\": 11,\n\t\"M\": 12,\n\t\"N\": 13,\n\t\"O\": 14,\n\t\"P\": 15,\n\t\"Q\": 16,\n\t\"R\": 17,\n\t\"S\": 18,\n\t\"T\": 19,\n\t\"U\": 20,\n\t\"V\": 21,\n\t\"W\": 22,\n\t\"X\": 23,\n\t\"Y\": 24,\n\t\"Z\": 25,\n};\nalphabet2 = {\n\t0: \"A\",\n\t1: \"B\",\n\t2: \"C\",\n\t3: \"D\",\n\t4: \"E\",\n\t5: \"F\",\n\t6: \"G\",\n\t7: \"H\",\n\t8: \"I\",\n\t9: \"J\",\n\t10: \"K\",\n\t11: \"L\",\n\t12: \"M\",\n\t13: \"N\",\n\t14: \"O\",\n\t15: \"P\",\n\t16: \"Q\",\n\t17: \"R\",\n\t18: \"S\",\n\t19: \"T\",\n\t20: \"U\",\n\t21: \"V\",\n\t22: \"W\",\n\t23: \"X\",\n\t24: \"Y\",\n\t25: \"Z\",\n};\n\nfor(i = 0; i < n; i++){\n\tstring = readline();\n\n\tif( /R\\d+C\\d+/.test(string) ){\n\t\trow = +/R(\\d+)/.exec(string)[1];\n\t\tcol = +/C(\\d+)/.exec(string)[1];\n\t\tans = [];\n\n\t\tfor(j = 0; j < 6; j++){\n\t\t\tcol -= Math.pow(26,j);\n\t\t\tif(col < 0){\n\t\t\t\tx = j-1;\n\t\t\t\tcol += Math.pow(26,j);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(; ;){\n\t\t\tans.push(alphabet2[col % 26]);\n\t\t\tif(col / 26 < 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcol = Math.floor(col / 26);\n\t\t}\n\n\t\tif(ans.length < x+1){\n\t\t\tfor(;ans.length != x+1;){\n\t\t\t\tans.push(\"A\");\n\t\t\t}\n\t\t}\n\t\t\n\t\twrite(ans.reverse().join(\"\") + row);\n\t}\n\telse{\n\t\trow = +/\\D+(\\d+)/.exec(string)[1];\n\t\tcol = /\\D+/.exec(string)[0].split(\"\").reverse();\n\t\tx = 0;\n\n\t\twrite(\"R\" + row);\n\t\twrite(\"C\");\n\n\t\tcol.forEach(function(letter, j){\n\t\t\tx += alphabet1[letter] * Math.pow(26, j);\n\t\t\tx += Math.pow(26, j);\n\t\t});\n\n\t\twrite(x);\n\t}\n\n\twrite(\"\\n\");\n}"}, {"source_code": "function lc(l) {\n return l.charCodeAt(0) - 64;\n}\n\nfunction cl(c) {\n return String.fromCharCode(c + 64);\n}\n\nfunction lton(str){\n var r = 0, i = 0, l = str.length;\n for (; i < l; i++) { \n r += (i === 0 ? 1 : Math.pow(26, i)) * lc(str[l - i - 1]);\n }\n return r;\n}\n\n\n\nfunction ntol(n) {\n var d = n, res = '';\n while (d > 0) {\n var ost = d % 26;\n //console.log(d, ost);\n d = Math.floor(d / 26) - (!ost ? 1 : 0);\n res = cl(ost || 26) + res;\n }\n return res;\n}\n\n\nfunction parse(str) {\n var m = str.match(/^R(\\d+)C(\\d+)$/i);\n if (m) {\n return ntol(m[2])+m[1];\n } else {\n m = str.match(/^([A-Z]+)(\\d+)$/);\n return 'R'+m[2]+'C'+lton(m[1]);\n }\n}\n\nvar n = +readline();\n\nfor (var i = 0; i < n; i++) {\n print(parse(readline()));\n}"}, {"source_code": "var pos = readline();\nvar array = [];\nvar ascii = 64;\nvar num26 = 26;\n\nfor (var i = 0; i < pos; i++) {\n array.push(readline());\n}\n\nfor (var i = 0; i < array.length; i++) {\n var text = array[i];\n var pattern = /R[(0-9)]{1,100}C[(0-9)]{1,100}/;\n if (pattern.test(text)) {\n var row = 0;\n var col = 0;\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n if (text[j] == 'C') {\n separator = j;\n }\n }\n \n var row = parseInt(text.substring(0, separator).replace(/[^0-9]/g, ''));\n var col = parseInt(text.substring(separator, text.length).replace(/[^0-9]/g, ''));\n var text = '';\n while(col > 0) {\n if (col <= num26) break;\n \n var remain = col % num26;\n if (remain === 0) {\n col = Math.floor(col / num26) - 1;\n text = 'Z' + text;\n } else {\n col = Math.floor(col / num26);\n var char = String.fromCharCode(remain + ascii);\n text = char + text;\n }\n }\n \n if (col === 0) {\n col = 26;\n }\n \n var first = String.fromCharCode(col + ascii);\n text = first + text;\n \n var converted = text + row;\n print(converted);\n } else {\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n var number = parseInt(text[j]);\n if (number >= 0 && number <= 9) {\n separator = j;\n break;\n }\n }\n \n var row = parseInt(text.substring(separator, text.length));\n var col = text.substring(0, separator);\n var colNum = 0;\n col = col.split('').reverse();\n for (var j = 0; j < col.length; j++) {\n var char = col[j].toUpperCase().charCodeAt(0) - ascii;\n if (j === 0) {\n colNum += char;\n } else {\n colNum += (Math.pow(num26, j) * char);\n }\n }\n \n var converted = 'R' + row + 'C' + colNum;\n print(converted);\n }\n}"}, {"source_code": "var LETTERS = [\n 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'\n];\nfunction main() {\n var numTests = +readline();\n\n for (var i = 0; i < numTests; i++) {\n print(calc(readline()));\n }\n return 0;\n}\nmain();\n\nfunction calc(str) {\n return isRC(str) && calcRC(str) || calcNRC(str);\n}\n\nfunction calcRC(str) {\n var res = [];\n var num = parseInt(str.slice(str.indexOf('C') + 1));\n var rest = 0;\n while (num) {\n rest = num % 26;\n res.push(LETTERS[rest]);\n if (rest === 0 && num === 26) break;\nif (rest === 0) {num = Math.floor(num / 26) - 1; continue;}\n num = Math.floor(num / 26);\n }\n\n return res.reverse().join('') + str.slice(1, str.indexOf('C'));\n}\n\nfunction calcNRC(str) {\n var letters = str.slice(0, str.search(/\\d/));\n var sum = 0;\n for (var i = letters.length - 1, p = 0; i >= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n\nfunction isRC(str) {\n return /^R\\d+C\\d+$/.test(str);\n}"}, {"source_code": "var n = readline();\nvar numerationSystem = '';\n\nvar num = 0;\n\nfor (var i = 0; i < n; i++) {\n numerationSystem = readline();\n\n var idxOfC = numerationSystem.indexOf('C');\n \n if (numerationSystem.charCodeAt(0) === 82\n && idxOfC !== -1\n && numerationSystem.charCodeAt(idxOfC-1) < 65) {\n \n var num = numerationSystem.substring(idxOfC+1);\n var alphabet = '';\n alphabet = getAlphabet(num);\n print(alphabet + numerationSystem.substring(1, idxOfC));\n \n } else {\n \n var alphabet = numerationSystem.replace(/[0-9]/g, \"\");\n var num = 0;\n num = getNum(alphabet);\n print('R' + numerationSystem.replace(/\\D/g,'') + 'C' + num);\n }\n \n}\n\n\n\nfunction getAlphabet(n) {\n \n\tvar index = n % 26;\n\tindex = index === 0 ? 26 : index;\n\n alphabet = String.fromCharCode(64+index) + alphabet;\n\t\n\tn = (n - index) / 26;\n\t\n\tif(n > 0) {\n\t\tgetAlphabet(n, alphabet);\n }\n \n return alphabet;\n \n}\n\nfunction getNum(a) {\n var power = a.length-1;\n var num = 0;\n for (var i = power; i >= 0; i--) {\n num += Math.pow(26, i) * (a.charCodeAt(power - i) - 64);\n }\n return num;\n \n}"}, {"source_code": "var lines = Number(readline());\n\nvar letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\nvar cases = [];\n\nfor(var i = 0; i < lines; i++){\n var data = readline();\n cases.push(toggle(data));\n}\n\nprint(cases.join('\\n'));\n\nfunction toggle(cell){\n var values = [];\n var chars = false;\n\n for(var i = 0; i < cell.length; i++){\n if(letters.indexOf(cell[i]) > -1 && chars === true){\n values[values.length - 1] += cell[i];\n }\n if(letters.indexOf(cell[i]) > -1 && chars === false){\n values.push(cell[i]);\n chars = true;\n }\n if(letters.indexOf(cell[i]) === -1 && chars === false){\n values[values.length - 1] += cell[i];\n }\n if(letters.indexOf(cell[i]) === -1 && chars === true){\n values.push(cell[i]);\n chars = false;\n }\n }\n\n if(values.length === 2){\n // AZnum\n var c = 0;\n var c_str = values[0];\n var r = values[1];\n for(var j = 0; j < c_str.length; j++){\n c = c * 26 + (letters.indexOf(c_str[j]) + 1);\n }\n return 'R' + r + 'C' + c;\n } else {\n // RXCY\n var r1 = values[1];\n var c1 = Number(values[3]);\n var c1_str = \"\";\n\n while(c1 > 0){\n c1_str = letters[(c1 - 1) % 26] + c1_str;\n c1 = Math.trunc((c1 - 1) / 26);\n }\n\n return c1_str + r1;\n }\n\n}\n"}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nfunction isRowColumnView(str) {\n return /R\\d+C\\d+/i.test(str);\n }\n \n function changeViewToCR(str) {\n var indexOfNumber = 0;\n var numberArr = [];\n var column;\n for (var i = 0; i < str.length; i++) {\n var char = str[i];\n if (isNaN(char)) {\n numberArr.push(char.charCodeAt(0) - 64);\n } else {\n indexOfNumber = i;\n break;\n }\n }\n column = numberArr.reduce( (col, elem, i) => {\n return col += elem * Math.pow(26, numberArr.length - 1 - i);\n }, 0)\n return `R${str.slice(indexOfNumber)}C${column}`;\n }\n \n function changeViewToExcel(str) {\n var indexOfC = str.indexOf(\"C\");\n var dividend = +str.slice(indexOfC + 1);\n var columnName = \"\";\n var module;\n\n while (dividend > 0)\n {\n module = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + module) + columnName;\n dividend = parseInt(((dividend - module) / 26));\n } \n\n var row = str.slice(1, indexOfC);\n return `${columnName}${row}`;\n }\n \n function getBaseLog(x, y) {\n return Math.log(y) / Math.log(x);\n }"}, {"source_code": "function sToInt(s)\n{\n\tvar intValue = 0;\n\tfor (var i = 0; i < s.length; i++)\n\t{\n\t\tintValue = intValue * 26 + (s.charCodeAt(i) -\"A\".charCodeAt(0) + 1);\n\t}\n\treturn intValue;\n}\n\nfunction intTos(x)\n{\n\tvar s = \"\";\n\twhile (x > 0)\n\t{\n//\t\tprint(String.fromCharCode((x - 1) % 26 + \"A\".charCodeAt(0)));\n\t\ts = String.fromCharCode((x - 1) % 26 + \"A\".charCodeAt(0)) + s;\n\t\tif (x % 26 == 0) {\t\t\n\t\t\tx = Math.floor(x / 26) - 1;\n\t\t} else {\n\t\t\tx = Math.floor(x / 26);\n\t\t}\n\t}\n\treturn s;\n}\n\nfunction main() \n{\n\tvar n = readline();\n\t\n\twhile (n--) {\n\t\tvar inputString = readline();\n\t\tarray = /^R(\\d+)C(\\d+)/.exec(inputString);\n\t\tif (array)\n\t\t{\n\t\t\tprint(intTos(array[2]) + array[1]);\n\t\t}\n\t\telse \n\t\t{\n\t\t\tarray = /^([A-Z]+)(\\d+)/.exec(inputString);\n\t\t\tprint('R' + array[2] + 'C' + sToInt(array[1]));\n\t\t}\n\t}\n}\n\nmain();"}, {"source_code": "function main(){\n var n=readline();\n var numration=[];\n var firstnumRule=/R\\d+C\\d+/;\n //var input =[\"R23C55\",\"BC23\"];\n for(var i=0;i=0;r--){\n resultcol=resultcol+resultcoltmp[r];\n }\n result=resultcol+row1;\n }else{\n var col2=numration[j].match(/[A-Z]+/g) + '';\n var row2=numration[j].match(/\\d+/g);\n var resultcol2=0;\n //AB123123\u578b\n for(var g=0;g= lv );\n\n\n\tvar validate = function(i){\n\t\tif(code[i] == 0 && i > 0){\n\t\t\tvalidate(i-1);\n\t\t\tcode[i-1]--;\n\t\t\tcode[i] = 26;\n\t\t}\n\t}\n\n\tfor(var i=code.length-1;i>0;i--){\n\t\tvalidate(i);\n\t}\n\t\t\n\n\twhile(code[0]==0)\n\t\tcode.shift();\n\t\n\treturn code.map(function(e){ return String.fromCharCode(64+e) }).join(\"\");\n}\n\n\nvar convert = function(v){\n\t\n\tvar p1 = /R([0-9]+)C([0-9]+)/;\n\tvar p2 = /([A-Z]+)([0-9]+)/;\n\n\tif(v.match(p1))\n\t{\n\t\t//R1C1 --> A\n\t\tvar row = v.replace(p1, \"$1\");\n\t\tvar column = valueToCode(v.replace(p1, \"$2\"));\n\t\treturn column+row;\n\t}\n\telse {\n\t\t//A23 -> R1C1\n\t\tvar column = codeToValue(v.replace(p2, \"$1\"));\n\t\tvar row = v.replace(p2, \"$2\");\n\t\treturn [\"R\", row, \"C\", column].join(\"\");\n\t}\n}\n\nvar numData = readline();\nfor(var i=0;i0)\n {\n s=String.fromCharCode((n+25)%26+'A'.charCodeAt())+s;\n n=Math.floor((n-1)/26);\n }\n return s;\n}\nfunction StringToNumber(s)\n{\n var x=0;\n for(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n var chr = col[i];\n var n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\nconst n = readline();\n\nwhile(line = readline()) {\n print( trans(line));\n}\n\n\n\n"}, {"source_code": "\nconst CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n\nfunction numToCol(num) {\n var n = num;\n var result = \"\";\n do {\n result = CHARS[ (n-1) % 26 ] + result;\n n = Math.floor( (n-1) / 26 );\n } while(n > 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n var chr = col[i];\n var n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\nconst n = readline();\n\nwhile(line = readline()) {\n print( trans(line));\n}"}, {"source_code": "'use strict';process.stdin.resume();process.stdin.setEncoding('utf-8');\nlet _iS = '',_cL = 0; process.stdin.on('data', _iSi => _iS += _iSi);\nprocess.stdin.on('end', _ => {_iS = _iS.trim().split('\\n').map(s => s.trim());main()});\nconst readline = () => _iS[_cL++];\n//////////\n\nconst main = () => {\n const count = parseInt(readline());\n \n for(let i = 0; i < count; i++){\n console.log(transform(readline()));\n }\n}\n\nconst transform = string => {\n if(/^R[0-9]+C[0-9]+/.test(string)) {\n const args = string.split('C');\n const rowNumber = parseInt(args[0].slice(1));\n const colNumber = parseInt(args[1]);\n\n const colCodes = [];\n let quotient = colNumber, remainder = 0;\n while(quotient >= 1) {\n remainder = quotient % 26;\n quotient /= 26;\n\n if(remainder < 1) {\n quotient -= 1;\n colCodes.push(26);\n } else {\n colCodes.push(remainder | 0);\n }\n }\n\n const colCode = colCodes.map(code => String.fromCharCode(code + 64)).reverse().join('')\n return `${colCode}${rowNumber}`;\n } else {\n const columnCode = string.replace(/[0-9]/g, '');\n const rowNumber = string.replace(/[A-Z]/g, '');\n\n const base26 = columnCode.split('').map(char => \n (char.charCodeAt(0) - 64));\n const base10 = base26.reverse().map((v, i) => v * (26 ** i)).reduce((a, b) => a + b);\n\n return `R${rowNumber}C${base10}`;\n }\n};"}, {"source_code": "\nconst CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n\nfunction numToCol(num) {\n var n = num;\n var result = \"\";\n do {\n result = CHARS[ (n-1) % 26 ] + result;\n n = Math.floor( (n-1) / 26 );\n } while(n > 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n var chr = col[i];\n var n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\nconst n = readline();\n\nwhile(line = readline()) {\n print( trans(line));\n}\n\n"}, {"source_code": "function a2c(a){\n var i, c = 0;\n for (i=0; i= Math.pow(26, i)) {\n \t\tc -= Math.pow(26, i);\n \t\ti++;\n \t} else {\n \t\tfor (j=0; j= 0; i--) {\n letterIndex = Math.floor((num - 1)/Math.pow(l, i))\n num -= Math.pow(l, i) * letterIndex;\n result += alphabet[letterIndex];\n }\n\n return result;\n}\n\nfunction alphToNum(alph) {\n var digits = alph.length,\n l = alphabet.length,\n num = 0;\n\n // add to num all the strings of length less than the input string\n for (var i = 0; i < digits; i++) {\n num += Math.pow(l, i);\n }\n\n // then add to num multiples of powers of 26 for each letter in (alph)\n var letterIndex;\n for (var i = 0; i < digits; i++) {\n letterIndex = alphabet.indexOf(alph[i]);\n num += letterIndex * Math.pow(l, digits - 1 - i);\n }\n\n return num;\n}\n"}, {"source_code": "var num2string = function (num) {\n var sLen = 1;\n var t = 26;\n while (num > t) {\n num -= t;\n sLen ++;\n t *= 26;\n }\n num --;\n var res = \"\";\n for (var i = 0; i < sLen; i ++) {\n res = String.fromCharCode(65 + num % 26) + res;\n num = parseInt(num / 26);\n }\n return res;\n};\n\nvar string2num = function (s) {\n var sLen = s.length;\n var res = 0;\n var t = 26;\n for (var i = 0; i < sLen-1; i ++) {\n res += t;\n t *= 26;\n }\n res += 1;\n t = 1;\n for (var i = sLen-1; i >= 0; i --) {\n res += (s[i].charCodeAt() - 65) * t;\n t *= 26;\n }\n return res;\n};\n\nvar check1 = function (s) {\n if (s[0] == 'R' && s[1].charCodeAt() <= 57 && s.indexOf(\"C\") != -1) {\n var idx = s.indexOf(\"C\");\n var num1 = parseInt(s.substring(1, idx));\n var num2 = parseInt(s.substring(idx+1));\n print(num2string(num2) + num1);\n return true;\n }\n else {\n return false;\n }\n};\n\nvar check2 = function (s) {\n var idx = 0;\n for (idx = 0; idx < s.length; idx ++) {\n if (s[idx].charCodeAt() <= 57)\n break;\n }\n var subs = s.substring(0, idx);\n print(\"R\" + s.substring(idx) + \"C\" + string2num(subs));\n};\n\nn = parseInt(readline());\nfor (var i = 0; i < n; i ++) {\n var s = readline();\n if (!check1(s))\n check2(s);\n}"}, {"source_code": "//V8 3.31.1\n\nvar table = ['Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];\nvar n = readline();\n//var n = 1;\n\nwhile(n--) {\n var s = readline();\n //var s = \"R228C494\";\n var e = /R(\\d+)C(\\d+)/.exec(s);\n \n if(e) {\n print(getString(e[2]) + e[1]);\n }\n else {\n e = /([A-Z]+)(\\d+)/.exec(s);\n print('R' + e[2] + 'C' + getNum(e[1]));\n }\n}\n\nfunction getNum(e) {\n var len = e.length;\n //print(len);\n var total = 0;\n var temp = len;\n for(var i = 0;i < len; i++) {\n for(var j = 1;j <= table.length; j++) {\n if(e[i] == table[j]) {\n //print(j)\n //print(table[j])\n total += j * Math.pow(26, temp - 1);\n //print(total);\n temp--;\n }\n }\n }\n return total;\n}\n\nfunction getString(e) {\n //print(e);\n var answer = '';\n while(e / 26 > 0) {\n answer += table[e % 26];\n //print(e % 26);\n //print(answer);\n if(e % 26 != 0) {\n e = parseInt(e / 26);\n }\n else {\n e = parseInt(e / 26) - 1;\n }\n //print(e);\n //print(table[e % 26]);\n }\n if(e != 0) {\n answer += table[e];\n }\n //print(answer);\n return answer.split(\"\").reverse().join(\"\");\n}"}, {"source_code": "var n=parseInt(readline());\nvar regRC=/R(\\d+)C(\\d+)/;\nvar regSP=/([A-Z]+)([0-9]+)/;\nfor(var i=0;i res) {\n\t\t\t\tnum -= res;\n\t\t\t\tlength++;\n\t\t\t\tres *= mul;\n\t\t\t}\n\t\t\tvar ans = \"\";\n\t\t\tfor (var j = 0; j < length; j++) {\n\t\t\t\tres /= mul;\n\t\t\t\tvar cur = \"A\".charCodeAt(0);\n\t\t\t\twhile (num > res) {\n\t\t\t\t\tnum -= res;\n\t\t\t\t\t++cur;\n\t\t\t\t}\n\t\t\t\tans += String.fromCharCode(cur);\n\t\t\t}\n\t\t\treturn ans;\n\t\t} (parseInt(matches[2])) + matches[1]);\n\t} else {\n\t\tvar matches = /([A-Z]+)(\\d+)/g.exec(s);\n\t\tprint(\"R\" + matches[2] + \"C\" + function(str) {\n\t\t\tvar mul = 26, res = 26, ans = 0;\n\t\t\tfor (var j = 1; j < str.length; j++) {\n\t\t\t\tans += res;\n\t\t\t\tres *= mul;\n\t\t\t}\n\t\t\tfor (var j = 0; j < str.length; j++) {\n\t\t\t\tvar num = str.charCodeAt(j);\n\t\t\t\tvar cur = \"A\".charCodeAt(0);\n\t\t\t\tres /= mul;\n\t\t\t\tans += res * (num - cur);\n\t\t\t}\n\t\t\treturn ans + 1;\n\t\t} (matches[1]));\n\t}\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nconst abcChars = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst dec2abc = dec => {\n\tlet d = dec;\n\tlet res = '';\n\n\twhile (d > 0) {\n\t\tconst mod = d % 26;\n\t\tres = abcChars[mod === 0 ? 26 : mod] + res;\n\t\td = Math.floor(d / 26) - (mod === 0 ? 1 : 0);\n\t}\n\n\treturn res;\n};\nconst abc2dec = abc => {\n\tlet res = 0;\n\n\tfor (let i = 0; i < abc.length; i++) {\n\t\tres += abcChars.indexOf(abc[i]);\n\t\tif (i !== abc.length - 1) {\n\t\t\tres *= 26;\n\t\t}\n\t}\n\n\treturn res;\n};\n\nlet n, counter = 0;\nconst res = [];\n\n\n\nrl.on('line', function (line) {\n\tif (!n) {\n\t\tn = parseInt(line);\n\t} else {\n\t\tconst rc = line.match(/R(\\d+)C(\\d+)/);\n\t\tif (rc) {\n\t\t\tres.push(dec2abc(parseInt(rc[2])) + rc[1]);\n\t\t} else {\n\t\t\tconst regular = line.match(/([^\\d]+)(\\d+)/);\n\t\t\tres.push('R' + regular[2] + 'C' + abc2dec(regular[1]));\n\t\t}\n\n\t\tcounter++;\n\t\tif (counter === n) {\n\t\t\tfor (let i = 0; i < res.length; i++) {\n\t\t\t\tconsole.log(res[i]);\n\t\t\t}\n\t\t\trl.close();\n\t\t}\n\t}\n});\n"}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rem = rem === 0 ? baseSize : rem;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"_ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nlet line = \"\";\nprocess.stdin.on(\"data\", w => {\n line += w;\n});\n\nprocess.stdin.on(\"end\", () => {\n const lines = line\n .split(/\\r?\\n/g)\n .filter(l => l.length !== 0)\n .slice(1);\n\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "//var fs = require('fs');\n\n//var readline = (function () {\n\t//var file = fs.readFileSync('input.txt', 'utf-8').split('\\n');\n\t//return function () {\n\t\t//return file.shift()\n\t//}\n//})();\n//var print = console.log;\n\nvar numberOfLines = Number(readline());\n\nfor (var i = 0; i < numberOfLines; i++) {\n var line = readline();\n if (/R\\d+C\\d+/.test(line)) {\n line = line.slice(1).split('C');\n var rowsTmp = Number(line[1]);\n var cols = Number(line[0]);\n var rows = '';\n\n while (rowsTmp > 0) {\n var currentCharCode = 64 + (rowsTmp % 26 === 0 ? 26 : rowsTmp % 26);\n\n rows = String.fromCharCode(currentCharCode) + rows;\n rowsTmp = Math.floor(rowsTmp / 26) - (rowsTmp % 26 === 0 ? 1 : 0);\n }\n\n print(rows + cols);\n\n } else {\n var tmp = /([A-Z]+)(\\d+)/.exec(line);\n var cols = tmp[2];\n var rowsTmp = tmp[1];\n var rows = 0;\n\n for (var j = 0; j < rowsTmp.length; j++) {\n rows = rows * 26 + (rowsTmp[j].charCodeAt(0) - 64)\n }\n\n print('R' + cols + 'C' + rows);\n }\n}\n"}, {"source_code": "var a,b;\nreadline();\n\nwhile(a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++)v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='';\n for(;l;l=parseInt(l/26)){\n\t a=String.fromCharCode(--l%26+65)+a;\n\t}\n\treturn a;\n}"}, {"source_code": "// http://codeforces.com/problemset/problem/1/B\n// B. \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n const BASE = 26;\n const UTF8_SHIFT = 'A'.charCodeAt(0) - 1;\n\n for (let i = 1; i < input.length; i++) {\n\n let blocks = [];\n let block = '';\n let lastChar = null;\n\n for (let j = 0; j < input[i].length; j++) {\n if (isNumeric(lastChar) !== isNumeric(input[i][j])) {\n blocks.push(block);\n block = '';\n }\n lastChar = input[i][j];\n block += input[i][j];\n }\n blocks.push(block);\n\n if (blocks.length === 2) {\n\n let column = blocks[0].split('').reduce(function (result, elem, index, arr) {\n result += (elem.charCodeAt(0) - UTF8_SHIFT) * Math.pow(BASE, arr.length - index - 1);\n return result;\n }, 0)\n console.log('R' + blocks[1] + 'C' + column);\n\n } else {\n\n let column = +blocks[3];\n let columnChars = [];\n \n while (column > 0) {\n column--;\n columnChars.push(String.fromCharCode(UTF8_SHIFT + column % BASE + 1));\n column = Math.floor(column / BASE);\n }\n console.log(columnChars.reverse().join('') + blocks[1]);\n\n }\n }\n});\n\n\nfunction isNumeric(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n"}, {"source_code": "var a,b;\nreadline();\n\nwhile(a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++)v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='';\n for(;l>26;l=parseInt(l/26)){\n\t l--;\n\t a=String.fromCharCode(l%26+65)+a;\n\t}\n\treturn String.fromCharCode(+l+64)+a;\n}\n"}, {"source_code": "var a, b;\nreadline();\n\nwhile (a = readline()) {\n print((b = a.match(/R(\\d+)C(\\d+)/)) ?\n M(b[2]) + b[1] :\n (b = a.match(/^([A-Z]+)(\\d+)$/), 'R' + b[2] + 'C' + M(b[1])));\n}\n\nfunction M(l) {\n var a = '', n = l.length - 1, i = v = 0, c;\n if (l - 1) {\n for (; l; l = parseInt(l / 26)) a = String.fromCharCode(--l % 26 + 65) + a;\n return a;\n } else {\n for (; c = l.charCodeAt(i) - 64; i++) v = v + Math.pow(26, n - i) * c;\n return v;\n }\n}\n"}, {"source_code": "var a,b;\nreadline();\n\nwhile(a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++)v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='';\n for(;l>26;l=parseInt(l/26)){\n\t a=String.fromCharCode(--l%26+65)+a;\n\t}\n\treturn String.fromCharCode(+l+64)+a;\n}"}, {"source_code": "(function() {\n var count = parseInt(readline());\n var input = [];\n\n var offset = 'A'.charCodeAt(0) - 1; // A = 1\n var maxChar = 26;\n // AA = 26 + 1 = 27\n\n for (var i = 0; i < count; i++) {\n input.push(readline());\n }\n\n input.map(function(x) {\n var matches = x.match(/^R(\\d+)C(\\d+)$/);\n if (matches != null) {\n print(convertToA(matches[1], matches[2]));\n } else {\n matches = x.match(/(^[A-Z]+)(\\d+)$/);\n if (matches != null) {\n print(convertToRC(matches[2], matches[1]));\n }\n }\n });\n\n function convertToA(row, col) {\n // row and col are one-based\n return convertNToA(col) + row;\n }\n\n function convertToRC(row, col) {\n // col is A, B, C\n return 'R' + row + 'C' + convertAToN(col);\n }\n\n function convertAToN(input) {\n var output = 0;\n for (var i = 0; i < input.length; i++) {\n var n = input.charCodeAt(i) - offset;\n var pow = input.length - 1 - i;\n output += Math.pow(maxChar, pow) * n;\n }\n return output;\n }\n\n function convertNToA(input) {\n var output = '';\n var pow = 0;\n while (input > 0) {\n var a = input % Math.pow(maxChar, pow + 1);\n if (a == 0) {\n input -= Math.pow(maxChar, pow + 1);\n output = 'Z' + output;\n } else if (a > 0) {\n input -= a;\n output = String.fromCharCode(a / Math.pow(maxChar, pow) + offset) + output;\n }\n pow++;\n }\n return output;\n }\n})();\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n\n var abc = '';\n var ost;\n while(pos != 0) {\n ost = pos % 26;\n if (ost != 0) {\n abc = arr[ost] + abc;\n } else {\n abc = 'Z' + abc;\n pos --;\n };\n pos = Math.floor(pos/26);\n }\n\n out += abc + x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var A = 'A'.charCodeAt(0);\nvar Z = 'Z'.charCodeAt(0);\nvar D = Z - A + 1;\n\nfunction toABS (n) {\n\tif (n >= D) {\n\t\treturn toABS(Math.floor(n / D) - 1) + toABS(n % D);\n\t} else {\n\t\treturn String.fromCharCode(A + n);\n\t}\n}\n\nfunction to123 (s) {\n\tvar n = 0;\n\tfor (var i = 0; i < s.length; i++) {\n\t\tn += (s.charCodeAt(i) - A + 1) * Math.pow(D, s.length - i - 1);\n\t}\n\treturn n;\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\twhile (n--) {\n\t\tvar s = readline();\n\t\tvar r = /^R(\\d+)C(\\d+)/.exec(s);\n\n\t\tif (r) {\n\t\t\tprint(toABS((+r[2]) - 1) + r[1]);\n\t\t} else {\n\t\t\tr = /^([A-Z]+)([0-9]+)/.exec(s);\n\t\t\tprint('R' + r[2] + 'C' + to123(r[1]));\n\t\t}\n\t}\n\n}).call(this);"}, {"source_code": " readline()\n var line\n while(line = readline()) {\n var codeOf2 = line[1].charCodeAt()\n var ioC = line.indexOf('C')\n print((codeOf2 >= 48 && codeOf2 <= 57 && ioC >= 2 ? sf : fs)(line))\n }\n\n function cn (c) {\n return c.charCodeAt() - 64\n }\n\n function nc (n) {\n return String.fromCharCode(n + 64)\n }\n\n function fs (f) {\n for (var i = 0; i < f.length; i++) {\n var cc = f[i].charCodeAt()\n if (cc >= 48 && cc <=57) break\n }\n var c = f.slice(0, i)\n var r = f.slice(i)\n c = c.split('').reverse().reduce(function (a, l, i) {return a + cn(l) * Math.pow(26, i)}, 0)\n return 'R' + r + 'C' + c\n }\n\n function sf (s) {\n var ci = s.indexOf('C')\n var r = s.slice(1, ci)\n var c = +s.slice(ci + 1)\n var cn = ''\n while (c) {\n var cd = c % 26\n if (cd == 0) {\n cd = 26\n c -= 26\n }\n cn = nc(cd) + cn\n c = c / 26 | 0\n }\n return cn + r\n }"}, {"source_code": "var n = parseInt(readline());\nconst pattern = /([A-Z]+\\d+){2}/;\nconst del1 = /R(\\d+)C(\\d+)/, del2 = /([A-Z]+)(\\d+)/;\nwhile(n--) {\n var line = readline();\n if(line.match(pattern)){\n var data = del1.exec(line);\n print(toStr(data[2]) + data[1]);\n }\n else {\n var data = del2.exec(line);\n print(`R${data[2]}C${toNum(data[1])}`);\n }\n}\n\nfunction toStr(num) {\n var ret = '';\n var t\n while(num>0){\n var u = num % 26;\n num = parseInt( num/26 );\n if(!u){\n u = 26\n num--;\n }\n ret = String.fromCharCode(u+64) + ret;\n }\n return ret;\n}\n\nfunction toNum(str) {\n var res = 0;\n\tfor(var i = 0; i < str.length; i++) {\n\t res += (str.charCodeAt(i) - 64) * Math.pow(26, str.length - i - 1);\n\t} \n\treturn res;\n}"}, {"source_code": "var n = readline(),\n coord,\n match;\n\nwhile (n--) {\n coord = readline();\n \n match = coord.match(/^([A-Z]*)(\\d*)$/);\n if (match) {\n print('R'+ match[2] + 'C' + toNumber(match[1]));\n } else {\n match = coord.match(/^R(\\d*)C(\\d*)$/);\n print(toChar(parseInt(match[2])) + match[1]);\n }\n}\n\nfunction toNumber(str) {\n var l = str.length,\n ret = 0,\n mul = 1;\n \n while (l--) {\n ret += mul * (str.charCodeAt(l) - 64);\n mul *= 26;\n }\n \n return ret;\n}\n\nfunction toChar(num) {\n var ret = '';\n\n while (num > 0) {\n c = num % 26;\n num = Math.floor(num/26);\n\n if (!c) {\n c = 26;\n num--;\n }\n ret = String.fromCharCode(c + 64) + ret;\n }\n \n return ret;\n}\n\n"}, {"source_code": "const strSettings=readline().trim();\nconst n=Number(strSettings);\nconst rexRXCY=new RegExp('R[0-9]+C[0-9]+'); \nvar str='';\nvar row=0;\nvar col=0;\nvar i=0;\nvar arr=[];\nvar str2='';\n\nfunction ColumnNumber(strColumn){ // Convert column name to number\n const strLetters='ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n var intColumn=strLetters.search(strColumn[0])+1;\n for (var j=1;j0);\n return strColumn;\n}\n\nfor (i=1;i<=n;i++) {\n str=readline();\n if (str.search(rexRXCY)>=0){ // RXCY format\n //print('str:'+str);\n arr=str.split(/[A-Z]/);\n row=Number(arr[1]);\n col=Number(arr[2]);\n print(ColumnName(col)+String(row));\n } else { // ColRow format\n col=ColumnNumber(str.split(/[0-9]+/)[0]);\n row=Number(String(str.match('[0-9]+')));\n print('R'+String(row)+'C'+String(col));\n }\n}\n"}, {"source_code": "\nfunction typeOf(cell) {\n if (cell[0] === 'R') {\n if (isNaN(cell[1])) {\n return 1;\n } else {\n if (cell.indexOf(\"C\") !== -1)\n return 2;\n else {\n return 1;\n }\n }\n } else {\n return 1;\n }\n}\n\nfunction convert_2_to_1(cell) {\n 'use strict';\n let row = \"\";\n let column = \"\";\n let stringColumn = \"\";\n let i = 1;\n\n while (cell[i] !== 'C')\n row += cell[i++];\n\n i++;\n\n while (i < cell.length)\n column += cell[i++];\n\n column = Number(column);\n\n while (column !== 0) {\n let mod = column % 26;\n if (mod === 0){\n stringColumn = String.fromCharCode(90) + stringColumn;\n column -= 26;\n }\n else\n stringColumn = String.fromCharCode(64 + mod) + stringColumn;\n\n column = Math.floor(column / 26);\n }\n\n return stringColumn + row.toString();\n}\n\nfunction convert_1_to_2(cell) {\n 'use strict';\n let i = 0;\n let row = \"\";\n let column = \"\";\n let columnBase10 = 0;\n let columnBase26 = [];\n let result = \"\";\n\n while (isNaN(cell[i])) {\n let code = cell.charCodeAt(i);\n columnBase26.push(code - 64);\n i++;\n }\n\n columnBase26.map((item, index, arr) => {\n columnBase10 += item * Math.pow(26, arr.length - index - 1);\n });\n\n column = columnBase10.toString();\n\n while (i < cell.length) {\n row += (cell[i]);\n i++;\n }\n\n result = \"R\" + row + \"C\" + column;\n return result;\n}\n\n\nvar testNumber = parseInt(readline());\n\nwhile(testNumber !== 0){\n var cell = readline();\n if(typeOf(cell) === 1)\n {\n print(convert_1_to_2(cell));\n }\n else{\n print(convert_2_to_1(cell));\n }\n\n testNumber--;\n}\n"}], "negative_code": [{"source_code": "var n = readline();\nvar str;\nvar sub1,sub2;\nvar alf = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nvar res;\n\nfor (var i = 0; i < n; i++){\n str = readline();\n var re1 = /[R]\\d+[C]\\d+/g;\n var re2 = /\\d+/g;\n var re4 = /\\d+/;\n var re3 = /[A-Z]+/g;\n res = re1.exec(str);\n \n if (res != null){\n sub1 = re2.exec(str);\n sub2 = re2.exec(str);\n if (sub2 > 26) sub2--;\n res = \"\";\n while(sub2/26>=1){\n res = alf[sub2%26]+res;\n sub2 = Math.floor(sub2/26);\n if (sub2 > 26) sub2--;\n }\n res = alf[--sub2]+res;\n print(res+sub1);\n }\n else {\n sub = re3.exec(str);\n res = 0;\n sub = sub + \"\";\n var l = sub.length;\n for (var j = 0; j < l; j++){\n res += (alf.indexOf(sub[j])+1) * Math.pow(26,l-j-1)\n }\n sub = re4.exec(str);\n print(\"R\" + sub + \"C\" + res);\n }\n}"}, {"source_code": "function main() {\n var tests = readline().split('\\n').slice(1);\n var LETTERS = [\n 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'\n ];\n \n for (var i = 1; i < tests.length; i++) {\n print(calc(tests[i]) + '\\n');\n }\n return 0;\n}\nmain();\n \nfunction calc(str) {\n return isRC(str) && calcRC(str) || calcNRC(str);\n}\n \nfunction calcRC(str) {\n var res = [];\n var num = parseInt(str.slice(str.indexOf('C') + 1));\n var rest = 0;\n while (num) {\n rest = num % 26;\n res.push(LETTERS[rest]);\n if (rest === 0 && num === 26) break;\n num = Math.floor(num / 26);\n }\n \n return res.reverse().join('') + str.slice(1, str.indexOf('C'));\n}\n \nfunction calcNRC(str) {\n var letters = str.slice(0, str.search(/\\d/));\n var sum = 0;\n for (var i = letters.length - 1, p = 0; i >= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n \nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "\nfunction typeOf(cell) {\n if (cell[0] === 'R') {\n if (isNaN(cell[1])) {\n return 1;\n } else {\n if (cell.indexOf(\"C\") !== -1)\n return 2;\n else {\n return 1;\n }\n }\n } else {\n return 1;\n }\n}\n\nfunction convert_2_to_1(cell) {\n 'use strict';\n let row = \"\";\n let column = \"\";\n let stringColumn = \"\";\n let i = 1;\n\n while (cell[i] !== 'C')\n row += cell[i++];\n\n i++;\n\n while (i < cell.length)\n column += cell[i++];\n\n column = Number(column);\n\n while (column !== 0) {\n let mod = column % 26;\n if (mod === 0)\n stringColumn = String.fromCharCode(90) + stringColumn;\n else\n stringColumn = String.fromCharCode(64 + mod) + stringColumn;\n\n column = Math.floor(column / 26);\n }\n\n return stringColumn + row.toString();\n}\n\nfunction convert_1_to_2(cell) {\n 'use strict';\n let i = 0;\n let row = \"\";\n let column = \"\";\n let columnBase10 = 0;\n let columnBase26 = [];\n let result = \"\";\n\n while (isNaN(cell[i])) {\n let code = cell.charCodeAt(i);\n columnBase26.push(code - 64);\n i++;\n }\n\n columnBase26.map((item, index, arr) => {\n columnBase10 += item * Math.pow(26, arr.length - index - 1);\n });\n\n column = columnBase10.toString();\n\n while (i < cell.length) {\n row += (cell[i]);\n i++;\n }\n\n result = \"R\" + row + \"C\" + column;\n return result;\n}\n\n"}, {"source_code": "var n=parseInt(readline());\nvar regRC=/R(\\d+)C(\\d+)/;\nvar regSP=/([A-Z]+)([0-9]+)/;\nfor(var i=0;i=26)\n\t{\n\t\tresult=number2alpha(a)+result;\n\t}else if(a!=0)\n\t{\n\t\tresult=String.fromCharCode('A'.charCodeAt(0)+a-1)+result;\n\t}\n\treturn result;\n};\n\nfunction alpha2number(alpha){\n\tvar result=0;\n\tfor(var i=0;i= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n \nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "\nconst n = readline();\n\nconst lines = [];\nfor(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n console.log(n);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/R\\d+C\\d+/.test(coord)) {\n const row = coord.match(/\\d+/)[0];\n const col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n } else {\n const col = coord.match(/[A-Z]+/)[0];\n const row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n }\n}\n\nfor(var i in lines) {\n const line = lines[i];\n print(line);\n}"}, {"source_code": "var table = [0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];\n//var n = readline();\nvar n = 1;\n\nwhile(n--) {\n //var s = readline();\n var s = \"R23C55\";\n var e = /R(\\d+)C(\\d+)/.exec(s);\n \n if(e) {\n print(getString(e[2]) + e[1]);\n }\n else {\n e = /([A-Z]+)(\\d+)/.exec(s);\n print('R' + e[2] + 'C' + getNum(e[1]));\n }\n}\n\nfunction getNum(e) {\n var len = e.length;\n //print(len);\n var total = 0;\n var temp = len;\n for(var i = 0;i < len; i++) {\n for(var j = 1;j <= table.length; j++) {\n if(e[i] == table[j]) {\n //print(j)\n //print(table[j])\n total += j * Math.pow(26, temp - 1);\n //print(total);\n temp--;\n }\n }\n }\n return total;\n}\n\nfunction getString(e) {\n //print(e);\n var answer = '';\n while(e / 26 > 0) {\n answer += table[e % 26];\n //print(answer);\n e = parseInt(e / 26);\n //print(e);\n //print(table[e % 26]);\n }\n if(e != 0) {\n answer += table[e];\n }\n //print(answer);\n return answer.split(\"\").reverse().join(\"\");\n}"}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rem = rem === 0 ? baseSize : rem;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"_ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nprocess.stdin.on(\"data\", w => {\n const lines = w\n .toString()\n .trim()\n .split(\"\\n\");\n console.log(lines);\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "var table = [0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];\n//var n = readline();\nvar n = 1;\n\nwhile(n--) {\n //var s = readline();\n var s = \"R23C55\";\n var e = /R(\\d+)C(\\d+)/.exec(s);\n \n if(e) {\n print(getString(e[2]) + e[1]);\n }\n else {\n e = /([A-Z]+)(\\d+)/.exec(s);\n print('R' + e[2] + 'C' + getNum(e[1]));\n }\n}\n\nfunction getNum(e) {\n var len = e.length;\n //print(len);\n var total = 0;\n var temp = len;\n for(var i = 0;i < len; i++) {\n for(var j = 1;j <= table.length; j++) {\n if(e[i] == table[j]) {\n //print(j)\n //print(table[j])\n total += j * Math.pow(26, temp - 1);\n //print(total);\n temp--;\n }\n }\n }\n return total;\n}\n\nfunction getString(e) {\n //print(e);\n var answer = '';\n while(e / 26 > 0) {\n answer += table[e % 26];\n //print(answer);\n e = parseInt(e / 26);\n //print(e);\n //print(table[e % 26]);\n }\n if(e != 0) {\n answer += table[e];\n }\n //print(answer);\n return answer.split(\"\").reverse().join(\"\");\n}"}, {"source_code": "var lines = Number(readline());\n\nvar letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\nvar cases = [];\n\nfor(var i = 0; i < lines; i++){\n var data = readline();\n cases.push(toggle(data));\n}\n\nprint(cases.join('\\n'));\n\nfunction toggle(cell){\n var values = [];\n var chars = false;\n\n for(var i = 0; i < cell.length; i++){\n if(letters.indexOf(cell[i]) > -1 && chars === true){\n values[values.length - 1] += cell[i];\n }\n if(letters.indexOf(cell[i]) > -1 && chars === false){\n values.push(cell[i]);\n chars = true;\n }\n if(letters.indexOf(cell[i]) === -1 && chars === false){\n values[values.length - 1] += cell[i];\n }\n if(letters.indexOf(cell[i]) === -1 && chars === true){\n values.push(cell[i]);\n chars = false;\n }\n }\n\n if(values.length === 2){\n // AZnum\n var r = 0;\n var r_str = values[0];\n var c = values[1];\n for(var j = 0; j < r_str.length; j++){\n r = r * 26 + (letters.indexOf(r_str[j]) + 1);\n }\n return 'R' + r + 'C' + c;\n } else {\n // RXCY\n var r1 = Number(values[1]);\n var r1_str = \"\";\n var c1 = values[3];\n\n while(r1 > 0){\n r1_str = letters[(r1 - 1) % 26] + r1_str;\n r1 = Math.trunc((r1 - 1) / 26);\n }\n\n return r1_str + c1;\n }\n\n}\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (j * 26 * k > pos) {\n out += arr[k-1];\n pos -= j * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j >= 0; j--) {\n posN += arr_S[str[j]] * j * 26;\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^(\\w+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]).toString(10) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var n = parseInt(readline());\n\nprint(n);"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z][A-Z]/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\nout += len + ' y=' + y + ' ';\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\nconst n = readline();\n\nconst lines = [];\nfor(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\ndo {\n const line = lines.shift();\n print(line);\n} while(lines.length > 0);\n\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 1; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k];\n pos -= Math.pow(26, j-1) * (k);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k+1];\n } else {\n out += arr[k];\n }; \n pos -= Math.pow(26, j-1) * (k);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j-1, len-j)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "function main() {\n var tests = readline().split('\\n').slice(1);\n var LETTERS = [\n 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'\n ];\n \n for (var i = 1; i < tests.length; i++) {\n print(calc(tests[i]));\n }\n return 0;\n}\nmain();\n \nfunction calc(str) {\n return isRC(str) && calcRC(str) || calcNRC(str);\n}\n \nfunction calcRC(str) {\n var res = [];\n var num = parseInt(str.slice(str.indexOf('C') + 1));\n var rest = 0;\n while (num) {\n rest = num % 26;\n res.push(LETTERS[rest]);\n if (rest === 0 && num === 26) break;\n num = Math.floor(num / 26);\n }\n \n return res.reverse().join('') + str.slice(1, str.indexOf('C'));\n}\n \nfunction calcNRC(str) {\n var letters = str.slice(0, str.search(/\\d/));\n var sum = 0;\n for (var i = letters.length - 1, p = 0; i >= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n \nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "var pos = readline();\nvar array = [];\nvar ascii = 64;\nvar num26 = 26;\n\nfor (var i = 0; i < pos; i++) {\n array.push(readline());\n}\n\nfor (var i = 0; i < array.length; i++) {\n var text = array[i];\n var pattern = /R[(0-9)]{1,100}C[(0-9)]{1,100}/;\n if (pattern.test(text)) {\n var row = 0;\n var col = 0;\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n if (text[j] == 'C') {\n separator = j;\n }\n }\n \n var row = parseInt(text.substring(0, separator).replace(/[^0-9]/g, ''));\n var col = parseInt(text.substring(separator, text.length).replace(/[^0-9]/g, ''));\n var text = '';\n while(col > 0) {\n if (col < num26) break;\n \n var remain = col % num26;\n col = col / num26;\n \n var char = String.fromCharCode(remain + ascii);\n text = char + text;\n }\n \n var first = String.fromCharCode(col + ascii);\n text = first + text;\n \n var converted = text + row;\n print(converted);\n } else {\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n var number = parseInt(text[j]);\n if (number >= 0 && number <= 9) {\n separator = j;\n break;\n }\n }\n \n var row = parseInt(text.substring(separator, text.length));\n var col = text.substring(0, separator);\n var colNum = 0;\n col = col.split('').reverse();\n for (var j = 0; j < col.length; j++) {\n var char = col[j].toUpperCase().charCodeAt(0) - ascii;\n if (j === 0) {\n colNum += char;\n } else {\n colNum += (Math.pow(num26, j) * char);\n }\n }\n \n var converted = 'R' + row + 'C' + colNum;\n print(converted);\n }\n}"}, {"source_code": "var LETTERS = [\n 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'\n];\nfunction main() {\n var numTests = +readline();\n\n for (var i = 0; i < numTests; i++) {\n print(calc(readline()));\n }\n return 0;\n}\nmain();\n\nfunction calc(str) {\n return isRC(str) && calcRC(str) || calcNRC(str);\n}\n\nfunction calcRC(str) {\n var res = [];\n var num = parseInt(str.slice(str.indexOf('C') + 1));\n var rest = 0;\n while (num) {\n rest = num % 26;\n res.push(LETTERS[rest]);\n if (rest === 0 && num === 26) break;\nif (rest === 0) {num = Math.floor(num / 26) - 1; continue;}\n num = Math.floor(num / 26);\n }\n\n return res.reverse().join('') + str.slice(1, str.indexOf('C'));\n}\n\nfunction calcNRC(str) {\n var letters = str.slice(0, str.search(/\\d/));\n var sum = 0;\n for (var i = letters.length - 1, p = 0; i >= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n\nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n out += arr[k-2];\n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction isRowColumnView(str) {\n return /R\\d+C\\d+/i.test(str);\n }\n \n function changeViewToCR(str) {\n var indexOfNumber = 0;\n var numberArr = [];\n var column;\n for (var i = 0; i < str.length; i++) {\n var char = str[i];\n if (isNaN(char)) {\n numberArr.push(char.charCodeAt(0) - 64);\n } else {\n indexOfNumber = i;\n break;\n }\n }\n column = numberArr.reduce( (col, elem, i) => {\n return col += elem * Math.pow(26, numberArr.length - 1 - i);\n }, 0)\n return `R${str.slice(indexOfNumber)}C${column}`;\n }\n \n function changeViewToExcel(str) {\n var indexOfC = str.indexOf(\"C\");\n var column = +str.slice(indexOfC + 1);\n var excelColumn = [];\n var sqrN = Math.floor(getBaseLog(26, column));\n var sqrnMax = sqrN;\n while (sqrN > -1) {\n var pow = Math.pow(26, sqrN);\n var tempNum = Math.floor(column/pow);\n //if (column % pow === 26 && tempNum === 1) {\n if (sqrN > 0 && tempNum === 1) {\n excelColumn.push(\"Z\");\n } else if (column % pow === 0 && sqrN !== 0){\n excelColumn.push(\"Z\");\n } else if ((tempNum === 0 && sqrN === 0) || (sqrN !== sqrnMax && excelColumn[sqrnMax - sqrN -1] === \"Z\")) {\n\n } else {\n excelColumn.push(String.fromCharCode(tempNum + 64));\n }\n column -= tempNum * pow;\n sqrN--;\n }\n //excelColumn.push(String.fromCharCode(tempNum + 64));\n var row = str.slice(1, indexOfC);\n return `${excelColumn.join('')}${row}`;\n }\n \n function getBaseLog(x, y) {\n return Math.log(y) / Math.log(x);\n }"}, {"source_code": "function a2c(a){\n var i, c = 0;\n for (i=0; i 1) c += Math.pow(26, a.length - 1);\n return c + 1;\n}\n\nfunction c2a(c){\n var q, r, a = '';\n\n c -= 1;\n if (c < 26) return String.fromCharCode(c + 65) + a;\n \n while (true){\n q = Math.floor(c / 26);\n r = c % 26;\n if (q == 0) {\n a = String.fromCharCode(r + 64) + a;\n break;\n }\n a = String.fromCharCode(r + 65) + a;\n c = q;\n }\n return a;\n}\n\nfunction convert(s){\n var i, temp;\n s = s.toUpperCase();\n \n if (/^[A-Z]{1,5}[1-9][0-9]*$/.test(s)) {\n for (i=0; i 0) {\n var ans = num % 26;\n res = (ans ? String.fromCharCode(ans + 64) : \"Z\") + res;\n num = parseInt(num / 26);\n }\n return res;\n}\n\nfunction toNum(str) {\n var res = 0;\n\tfor(var i = 0; i < str.length; i++) {\n\t res += (str.charCodeAt(i) - 64) * Math.pow(26, str.length - i - 1);\n\t} \n\treturn res;\n}"}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}"}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^(\\w+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]).toString(10) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j == 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n } \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^(\\w+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "var n=parseInt(readline());\nvar regRC=/R(\\d+)C(\\d+)/;\nvar regSP=/([A-Z]+)([0-9]+)/;\nfor(var i=0;i=26)\n\t{\n\t\tresult=number2alpha(a)+result;\n\t}else if(a!=0)\n\t{\n\t\tresult=String.fromCharCode('A'.charCodeAt(0)+a-1)+result;\n\t}\n\treturn result;\n};\n\nfunction alpha2number(alpha){\n\tvar result=0;\n\tfor(var i=0;i {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nlet line = \"\";\nprocess.stdin.on(\"data\", w => {\n line += w;\n});\n\nprocess.stdin.on(\"end\", () => {\n const lines = line\n .split(/\\r?\\n/g)\n .filter(l => l.length !== 0)\n .slice(1);\n\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "var num2string = function (num) {\n var sLen = 1;\n var t = 26;\n while (num > t) {\n num -= t;\n sLen ++;\n t *= 26;\n }\n num --;\n var res = \"\";\n for (var i = 0; i < sLen; i ++) {\n res = String.fromCharCode(65 + num % 26) + res;\n num = parseInt(num / 26);\n }\n return res;\n};\n\nvar string2num = function (s) {\n var sLen = s.length;\n var res = 0;\n var t = 26;\n for (var i = 0; i < sLen-1; i ++) {\n res += t;\n t *= 26;\n }\n res += 1;\n t = 1;\n for (var i = sLen-1; i >= 0; i --) {\n res += (s[i].charCodeAt() - 65) * t;\n t *= 26;\n }\n return res;\n};\n\nvar check1 = function (s) {\n if (s[0] == 'R' && s[1].charCodeAt() <= 57) {\n var idx = s.indexOf(\"C\");\n var num1 = parseInt(s.substring(1, idx));\n var num2 = parseInt(s.substring(idx+1));\n print(num2string(num2) + num1);\n return true;\n }\n else {\n return false;\n }\n};\n\nvar check2 = function (s) {\n var idx = 0;\n for (idx = 0; idx < s.length; idx ++) {\n if (s[idx].charCodeAt() <= 57)\n break;\n }\n var subs = s.substring(0, idx);\n print(\"R\" + s.substring(idx) + \"C\" + string2num(subs));\n};\n\nn = parseInt(readline());\nfor (var i = 0; i < n; i ++) {\n var s = readline();\n if (!check1(s))\n check2(s);\n}"}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}\nelse {\n print(readline());\n}"}, {"source_code": "var n=parseInt(readline());\nvar regRC=/R(\\d+)C(\\d+)/;\nvar regSP=/([A-Z]+)([0-9]+)/;\nfor(var i=0;i=26)\n\t{\n\t\tresult=number2alpha(a)+result;\n\t}else if(a!=0)\n\t{\n\t\tresult=String.fromCharCode('A'.charCodeAt(0)+a-1)+result;\n\t}\n\treturn result;\n};\n\nfunction alpha2number(alpha){\n\tvar result=0;\n\tfor(var i=0;i= 0; j--) {\n if ((col / 26) < 1) {\n colChar += String.fromCharCode(col + 64);\n break;\n }\n \n colChar += String.fromCharCode(Math.floor(col / 26) + 64);\n col -= (26 * (j + 1));\n }\n \n var converted = colChar + row;\n print(converted);\n } else {\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n var number = parseInt(text[j]);\n if (number >= 0 && number <= 9) {\n separator = j;\n break;\n }\n }\n \n var row = parseInt(text.substring(separator, text.length));\n var col = text.substring(0, separator);\n var colNum = 0;\n var ascii = 64;\n col = col.split('').reverse();\n for (var j = 0; j < col.length; j++) {\n var char = col[j].toUpperCase().charCodeAt(0) - ascii;\n if (j === 0) {\n colNum += char;\n } else {\n colNum += (26 * j * char);\n }\n }\n \n var converted = 'R' + row + 'C' + colNum;\n print(converted);\n }\n}"}, {"source_code": "function a2c(a){\n var i, c = 0;\n for (i=0; i 1) c += Math.pow(26, a.length - 1);\n return c + 1;\n}\n\nfunction c2a(c){\n var q, r, a = '';\n\n c -= 1;\n if (c < 26) return String.fromCharCode(c + 65) + a;\n \n while (true){\n q = Math.floor(c / 26);\n r = c % 26;\n if (q == 0) {\n a = String.fromCharCode(r + 64) + a;\n break;\n }\n a = String.fromCharCode(r + 65) + a;\n c = q;\n }\n return a;\n}\n\nfunction convert(s){\n var i, temp;\n s = s.toUpperCase();\n \n if (/^[A-Z]{1,5}[1-9][0-9]*$/.test(s)) {\n for (i=0; i26;l=parseInt(l/26))a=b(l%26+64)+a;\n\treturn b(+l+64)+a;\n}\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (j * 26 * k > pos) {\n out += arr[k-1];\n pos -= j * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j >= 0; j--) {\n posN += arr_S[str[j]] * j * 26;\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k == pos) {\n out += arr[k];\n pos -= Math.pow(26, j-1) * k;\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z][A-Z]/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[str[len-j]] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "const strSettings=readline().trim();\nconst n=Number(strSettings);\nconst rexRXCY=new RegExp('R[0-9]+C[0-9]+'); \nvar str='';\nvar row=0;\nvar col=0;\nvar i=0;\nvar arr=[];\nvar str2='';\n\nfunction ColumnNumber(strColumn){ // Convert column name to number\n const strLetters='ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n var intColumn=strLetters.search(strColumn[0])+1;\n for (var j=1;j0);\n return strColumn;\n}\n\nfor (i=1;i<=n;i++) {\n str=readline();\n if (str.search(rexRXCY)>=0){ // RXCY format\n //print('str:'+str);\n arr=str.split(/[A-Z]/);\n row=Number(arr[1]);\n col=Number(arr[2]);\n print(ColumnName(col)+String(row));\n } else { // ColRow format\n col=ColumnNumber(str.split(/[0-9]/)[0]);\n row=Number(String(str.match('[0-9]+')));\n print('R'+String(row)+'C'+String(col));\n }\n}\n"}, {"source_code": "//var fs = require('fs');\n\n//var readline = (function () {\n\t//var file = fs.readFileSync('input.txt', 'utf-8').split('\\n');\n\t//return function () {\n\t\t//return file.shift()\n\t//}\n//})();\n//var print = console.log;\n\nvar numberOfLines = Number(readline());\n\nfor (var i = 0; i < numberOfLines; i++) {\n var line = readline();\n if (line[0] === 'R') {\n line = line.slice(1).split('C');\n var rowsTmp = Number(line[1]);\n var cols = Number(line[0]);\n var rows = '';\n\n while (rowsTmp > 0) {\n var currentCharCode = 64 + (rowsTmp % 26 === 0 ? 26 : rowsTmp % 26);\n\n rows = String.fromCharCode(currentCharCode) + rows;\n rowsTmp = Math.floor(rowsTmp / 26);\n }\n\n print(rows + cols);\n\n } else {\n var tmp = /([A-Z]+)(\\d+)/.exec(line);\n var cols = tmp[2];\n var rowsTmp = tmp[1];\n var rows = 0;\n\n for (var j = 0; j < rowsTmp.length; j++) {\n rows = rows * 26 + (rowsTmp[j].charCodeAt(0) - 64)\n }\n\n print('R' + cols + 'C' + rows);\n }\n}\n"}, {"source_code": "\nconst n = readline();\n\nconst lines = [];\nfor(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/R\\d+C\\d+/.test(coord)) {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n } else {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n }\n}\n\nfor(var i in lines) {\n const line = trans(lines[i]);\n print(line);\n}"}, {"source_code": "\nfunction typeOf(cell) {\n if (cell[0] === 'R') {\n if (isNaN(cell[1])) {\n return 1;\n } else {\n if (cell.indexOf(\"C\") !== -1)\n return 2;\n else {\n return 1;\n }\n }\n } else {\n return 1;\n }\n}\n\nfunction convert_2_to_1(cell) {\n 'use strict';\n let row = \"\";\n let column = \"\";\n let stringColumn = \"\";\n let i = 1;\n\n while (cell[i] !== 'C')\n row += cell[i++];\n\n i++;\n\n while (i < cell.length)\n column += cell[i++];\n\n column = Number(column);\n\n while (column !== 0) {\n let mod = column % 26;\n if (mod === 0)\n stringColumn = String.fromCharCode(90) + stringColumn;\n else\n stringColumn = String.fromCharCode(64 + mod) + stringColumn;\n\n column = Math.floor(column / 26);\n }\n\n return stringColumn + row.toString();\n}\n\nfunction convert_1_to_2(cell) {\n 'use strict';\n let i = 0;\n let row = \"\";\n let column = \"\";\n let columnBase10 = 0;\n let columnBase26 = [];\n let result = \"\";\n\n while (isNaN(cell[i])) {\n let code = cell.charCodeAt(i);\n columnBase26.push(code - 64);\n i++;\n }\n\n columnBase26.map((item, index, arr) => {\n columnBase10 += item * Math.pow(26, arr.length - index - 1);\n });\n\n column = columnBase10.toString();\n\n while (i < cell.length) {\n row += (cell[i]);\n i++;\n }\n\n result = \"R\" + row + \"C\" + column;\n return result;\n}\n\n\nvar testNumber = readline();\n\n// while(testNumber !== 0){\n// let cell = readline();\n// if(typeOf(cell) === 1)\n// {\n// print(convert_1_to_2(cell));\n// }\n// else{\n// print(convert_2_to_1(cell));\n// }\n\n// testNumber--;\n// }\n"}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^(\\w+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]).toString(10) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "var a,b;\nreadline();\n\nwhile(a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++)v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='',b=String.fromCharCode;\n for(l--;l>26;l=parseInt(l/26))a=b(l%26+64)+a;\n\treturn b(+l+64)+a;\n}\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 27; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor-1 < pos) {\n por ++;\n valpor = valpor * 27;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (j * 26 * k > pos) {\n out += arr[k-1];\n pos -= j * 26 * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[str[j]] * j * 26;\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "// http://codeforces.com/problemset/problem/1/B\n// B. \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n const BASE = 26;\n const UTF8_SHIFT = 'A'.charCodeAt(0) - 1;\n\n for (let i = 1; i < input.length; i++) {\n\n let blocks = [];\n let block = '';\n let lastChar = null;\n\n for (let j = 0; j < input[i].length; j++) {\n if (isNumeric(lastChar) !== isNumeric(input[i][j])) {\n blocks.push(block);\n block = '';\n }\n lastChar = input[i][j];\n block += input[i][j];\n }\n blocks.push(block);\n\n if (blocks.length === 2) {\n\n let column = blocks[0].split('').reduce(function (result, elem, index, arr) {\n result += (elem.charCodeAt(0) - UTF8_SHIFT) * Math.pow(BASE, arr.length - index - 1);\n return result;\n }, 0)\n console.log('R' + blocks[1] + 'C' + column);\n\n } else {\n\n let column = +blocks[3];\n let columnChars = [];\n console.log(column);\n while (column > 0) {\n column--;\n columnChars.push(String.fromCharCode(UTF8_SHIFT + column % BASE + 1));\n column = Math.floor(column / BASE);\n }\n console.log(columnChars.reverse().join('') + blocks[1]);\n\n }\n }\n});\n\n\nfunction isNumeric(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n"}, {"source_code": "\nconst n = readline();\n\nconst lines = [];\nfor(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n console.log(n);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/R\\d+C\\d+/.test(coord)) {\n const row = coord.match(/\\d+/)[0];\n const col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n } else {\n const col = coord.match(/[A-Z]+/)[0];\n const row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n }\n}\n\nfor(var i in lines) {\n const line = lines[i];\n print(line);\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k == pos) {\n out += arr[k];\n pos -= Math.pow(26, j-1) * k;\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^(\\w+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"0ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nlet line = \"\";\nprocess.stdin.on(\"data\", w => {\n line += w;\n});\n\nprocess.stdin.on(\"end\", () => {\n const lines = line\n .split(/\\r?\\n/g)\n .filter(l => l.length !== 0)\n .slice(1);\n\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 27; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "'use strict';process.stdin.resume();process.stdin.setEncoding('utf-8');\nlet _iS = '',_cL = 0; process.stdin.on('data', _iSi => _iS += _iSi);\nprocess.stdin.on('end', _ => {_iS = _iS.trim().split('\\n').map(s => s.trim());main()});\nconst readline = () => _iS[_cL++];\n//////////\n\nconst main = () => {\n const count = parseInt(readline());\n \n for(let i = 0; i < count; i++){\n console.log(transform(readline()));\n }\n}\n\nconst transform = string => {\n if(string[0] == \"R\") {\n const args = string.split('C');\n const rowNumber = parseInt(args[0].slice(1));\n const colNumber = parseInt(args[1]);\n\n const base26 = colNumber.toString(26);\n const colCode = base26.split('').map(char => {\n const code = (isNaN(char) ? char.charCodeAt(0) - 87 : parseInt(char)) + 64\n return String.fromCharCode(code);\n }).join('')\n\n return `${colCode}${rowNumber}`;\n } else {\n const columnCode = string.replace(/[0-9]/g, '');\n const rowNumber = string.replace(/[A-Z]/g, '');\n\n const base26 = columnCode.split('').map(char => \n (char.charCodeAt(0) - 64).toString(26)).join('')\n const base10 = parseInt(base26, 26);\n\n return `R${rowNumber}C${base10}`;\n }\n};"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nconst abcChars = '_ABCDEFGHIGKLMNOPQRSTUVWXYZ';\nconst dec2abc = dec => {\n\tlet d = dec;\n\tlet res = '';\n\n\twhile (d > 0) {\n\t\tconst mod = d % 26;\n\t\tres = abcChars[mod === 0 ? 26 : mod] + res;\n\t\td = Math.floor(d / 26) - (mod === 0 ? 1 : 0);\n\t}\n\n\treturn res;\n};\nconst abc2dec = abc => {\n\tlet res = 0;\n\n\tfor (let i = 0; i < abc.length; i++) {\n\t\tres += abcChars.indexOf(abc[i]);\n\t\tif (i !== abc.length - 1) {\n\t\t\tres *= 26;\n\t\t}\n\t}\n\n\treturn res;\n};\n\nlet n, counter = 0;\nconst res = [];\n\nrl.on('line', function (line) {\n\tif (!n) {\n\t\tn = parseInt(line);\n\t} else {\n\t\tconst rc = line.match(/R(\\d+)C(\\d+)/);\n\t\tif (rc) {\n\t\t\tres.push(dec2abc(parseInt(rc[2])) + rc[1]);\n\t\t} else {\n\t\t\tconst regular = line.match(/([^\\d]+)(\\d+)/);\n\t\t\tres.push('R' + regular[2] + 'C' + abc2dec(regular[1]));\n\t\t}\n\n\t\tcounter++;\n\t\tif (counter === n) {\n\t\t\tfor (let i = 0; i < res.length; i++) {\n\t\t\t\tconsole.log(res[i]);\n\t\t\t}\n\t\t\trl.close();\n\t\t}\n\t}\n});\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j == 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}\nelse {\n print(readline());\n}"}, {"source_code": "var n = readline();\nvar coord;\nvar match;\n\nfor (var i=0; i 0) {\n c = num % 26;\n ret = String.fromCharCode(c + 64) + ret;\n num = Math.floor(num/26);\n }\n \n return ret;\n}"}, {"source_code": "var c = readline(), s, m;\n\nwhile(c--){\n\ts = readline();\n\tm = /^R(\\d+)C(\\d+)/.exec(s);\n\t\n\tif( m ){\n\t\tprint( toChar(m[2]) + m[1] );\n\t}else{\n\t\tm = /^([A-Z]+)(\\d+)/.exec(s);\n\t\tprint('R' + m[2] + 'C' + toNum(m[1]).toString(10) );\n\t}\n}\n\nfunction toChar(num){\n\tvar ret = '';\n\tvar m = num%26;\n\twhile( num > 26 ){\n\t\tret = String.fromCharCode( m+64 ) +ret;\n\t\tnum = (num - m)/26\n\t\tm = num%26\n\t}\n\treturn String.fromCharCode( m+64 ) +ret;\n}\n\nfunction toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}"}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rem = rem === 0 ? baseSize : rem;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"_ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nprocess.stdin.on(\"data\", w => {\n const lines = w\n .toString()\n .trim()\n .split(\"\\n\");\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "\nconst CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n\nfunction numToCol(num) {\n var n = num;\n var result = \"\";\n do {\n result = CHARS[ (n-1) % 26 ] + result;\n n = Math.floor( (n-1) / 26 );\n } while(n > 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\nconst n = readline();\n\n\n\nwhile(line = readline()) {\n print( trans(line));\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 1; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k];\n pos -= Math.pow(26, j-1) * (k);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k+1];\n } else {\n out += arr[k];\n }; \n pos -= Math.pow(26, j-1) * (k);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j-1, len-j)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "//var fs = require('fs');\n\n//var readline = (function () {\n //var file = fs.readFileSync('input.txt', 'utf-8').split('\\n');\n //return function () {\n //return file.shift()\n //}\n//})();\n//var print = console.log;\n\nvar numberOfLines = Number(readline());\n\nfor (var i = 0; i < numberOfLines; i++) {\n var line = readline();\n if (line[0] === 'R') {\n line = line.slice(1).split('C');\n var rowsTmp = Number(line[1]);\n var cols = Number(line[0]);\n var rows = '';\n\n while (rowsTmp > 0) {\n var currentCharCode = 64 + (rowsTmp % 26);\n rows = String.fromCharCode(currentCharCode) + rows;\n rowsTmp = Math.floor(rowsTmp / 26);\n }\n\n print(rows + cols);\n\n } else {\n var tmp = /([A-Z]+)(\\d+)/.exec(line);\n var cols = tmp[2];\n var rowsTmp = tmp[1];\n var rows = 0;\n\n for (var j = 0; j < rowsTmp.length; j++) {\n rows = rows * 26 + (rowsTmp[j].charCodeAt(0) - 64)\n }\n\n print('R' + cols + 'C' + rows);\n }\n}\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rem = rem === 0 ? baseSize : rem;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"_ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nprocess.stdin.on(\"data\", w => {\n const lines = w\n .toString()\n .trim()\n .split(/\\r?\\n/);\n\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "\nfunction typeOf(cell) {\n if (cell[0] === 'R') {\n if (isNaN(cell[1])) {\n return 1;\n } else {\n if (cell.indexOf(\"C\") !== -1)\n return 2;\n else {\n return 1;\n }\n }\n } else {\n return 1;\n }\n}\n\nfunction convert_2_to_1(cell) {\n 'use strict';\n let row = \"\";\n let column = \"\";\n let stringColumn = \"\";\n let i = 1;\n\n while (cell[i] !== 'C')\n row += cell[i++];\n\n i++;\n\n while (i < cell.length)\n column += cell[i++];\n\n column = Number(column);\n\n while (column !== 0) {\n let mod = column % 26;\n if (mod === 0)\n stringColumn = String.fromCharCode(90) + stringColumn;\n else\n stringColumn = String.fromCharCode(64 + mod) + stringColumn;\n\n column = Math.floor(column / 26);\n }\n\n return stringColumn + row.toString();\n}\n\nfunction convert_1_to_2(cell) {\n 'use strict';\n let i = 0;\n let row = \"\";\n let column = \"\";\n let columnBase10 = 0;\n let columnBase26 = [];\n let result = \"\";\n\n while (isNaN(cell[i])) {\n let code = cell.charCodeAt(i);\n columnBase26.push(code - 64);\n i++;\n }\n\n columnBase26.map((item, index, arr) => {\n columnBase10 += item * Math.pow(26, arr.length - index - 1);\n });\n\n column = columnBase10.toString();\n\n while (i < cell.length) {\n row += (cell[i]);\n i++;\n }\n\n result = \"R\" + row + \"C\" + column;\n return result;\n}\n\n\nvar testNumber = readline();\n\n// while(testNumber !== 0){\n// let cell = readline();\n// if(typeOf(cell) === 1)\n// {\n// print(convert_1_to_2(cell));\n// }\n// else{\n// print(convert_2_to_1(cell));\n// }\n\n// testNumber--;\n// }\n"}, {"source_code": "var A = 'A'.charCodeAt(0);\nvar Z = 'Z'.charCodeAt(0);\nvar D = Z - A + 1;\n\nfunction toABS (n) {\n\tif (n >= D) {\n\t\treturn toABS(Math.floor(n / D) - 1) + toABS(n % D);\n\t} else {\n\t\treturn String.fromCharCode(A + n);\n\t}\n}\n\nfunction to123 (s) {\n\tvar n = 0;\n\tfor (var i = 0; i < s.length; i++) {\n\t\tn += (s.charCodeAt(i) - A - 1) * Math.pow(D, s.length - i - 1);\n\t}\n\treturn n;\n}\n\n;(function () {\n\n\tvar n = +readline();\n\n\twhile (n--) {\n\t\tvar s = readline();\n\t\tvar r = /^R(\\d+)C(\\d+)/.exec(s);\n\n\t\tif (r) {\n\t\t\tprint(toABS((+r[2]) - 1) + r[1]);\n\t\t} else {\n\t\t\tr = /^([A-Z]+)([0-9]+)/.exec(s);\n\t\t\tprint('R' + r[2] + 'C' + to123(r[1]));\n\t\t}\n\t}\n\n}).call(this);"}, {"source_code": "function baseToDec(baseRep, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n let res = 0;\n for (let i = 0; i < baseRep.length - 1; i++) {\n const w = baseRep[i];\n res = (res + baseMap[w]) * baseSize;\n }\n res = res + baseMap[baseRep[baseRep.length - 1]];\n return res;\n}\n\nfunction decToBase(num, baseMap) {\n const baseSize = Object.keys(baseMap).length - 1;\n\n const inverseBaseMap = {};\n for (let w of Object.keys(baseMap)) {\n inverseBaseMap[baseMap[w]] = w;\n }\n\n if (num === 0) {\n return inverseBaseMap[0];\n }\n\n let rep = [];\n\n while (num !== 0) {\n let rem = num % baseSize;\n rem = rem === 0 ? baseSize : rem;\n rep.push(inverseBaseMap[rem]);\n num = (num - rem) / baseSize;\n }\n\n return rep.reverse().join(\"\");\n}\n\nfunction rowColToStand(rowCol) {\n const RC = rowCol.match(/R(.*)C(.*)/);\n return { row: Number(RC[1]), col: Number(RC[2]) };\n}\n\nfunction standToRowCol(stand) {\n return `R${stand.row}C${stand.col}`;\n}\n\nconst alphaBase = \"_ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").reduce((acc, curr, i) => {\n acc[curr] = i;\n return acc;\n}, {});\n\nfunction alphaToStand(alpha) {\n const RC = alpha.match(/([A-Z]*)([0-9]*)/);\n const alphaCol = RC[1];\n const row = Number(RC[2]);\n const col = baseToDec(alphaCol, alphaBase);\n return { row, col };\n}\n\nfunction standToAlpha(stand) {\n return `${decToBase(stand.col, alphaBase)}${stand.row}`;\n}\n\nprocess.stdin.read();\n\nprocess.stdin.on(\"data\", w => {\n const lines = w\n .toString()\n .trim()\n .split(\"\\n\");\n console.log(lines);\n lines.forEach(line => {\n if (line.match(/^[A-Z]+[0-9]+$/)) {\n console.log(standToRowCol(alphaToStand(line)));\n }\n\n if (line.match(/^R[0-9]+C[0-9]+$/)) {\n console.log(standToAlpha(rowColToStand(line)));\n }\n });\n});\n"}, {"source_code": "'use strict';process.stdin.resume();process.stdin.setEncoding('utf-8');\nlet _iS = '',_cL = 0; process.stdin.on('data', _iSi => _iS += _iSi);\nprocess.stdin.on('end', _ => {_iS = _iS.trim().split('\\n').map(s => s.trim());main()});\nconst readline = () => _iS[_cL++];\n//////////\n\nconst main = () => {\n const count = parseInt(readline());\n \n for(let i = 0; i < count; i++){\n console.log(transform(readline()));\n }\n}\n\nconst transform = string => {\n if(string[0] == \"R\") {\n const args = string.split('C');\n const rowNumber = parseInt(args[0].slice(1));\n const colNumber = parseInt(args[1]);\n\n const base26 = colNumber.toString(26);\n const colCode = base26.split('').map(char => {\n const code = (isNaN(char) ? char.charCodeAt(0) - 87 : parseInt(char)) + 64\n return String.fromCharCode(code);\n }).join('')\n\n return `${colCode}${rowNumber}`;\n } else {\n const columnCode = string.replace(/[0-9]/g, '');\n const rowNumber = string.replace(/[A-Z]/g, '');\n\n const base26 = columnCode.split('').map(char => \n (char.charCodeAt(0) - 64).toString(26)).join('')\n const base10 = parseInt(base26, 26);\n\n return `R${rowNumber}C${base10}`;\n }\n};"}, {"source_code": "var n = readline();\nvar str;\nvar sub1,sub2;\nvar alf = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nvar res;\n\nfor (var i = 0; i < n; i++){\n str = readline();\n var re1 = /[R]\\d+[C]\\d+/g;\n var re2 = /\\d+/g;\n var re4 = /\\d+/;\n var re3 = /[A-Z]+/g;\n res = re1.exec(str);\n \n if (res != null){\n sub1 = re2.exec(str);\n sub2 = re2.exec(str);\n if (sub2 > 26) sub2--;\n res = \"\";\n while(sub2/26>1){\n res = alf[sub2%26]+res;\n sub2 = Math.floor(sub2/26);\n if (sub2 > 26) sub2--;\n }\n res = alf[--sub2]+res;\n print(res+sub1);\n }\n else {\n sub = re3.exec(str);\n res = 0;\n sub = sub + \"\";\n var l = sub.length;\n for (var j = 0; j < l; j++){\n res += (alf.indexOf(sub[j])+1) * Math.pow(26,l-j-1)\n }\n sub = re4.exec(str);\n print(\"R\" + sub + \"C\" + res);\n }\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-2];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var count = readline();\n while(count--){\n s = readline();\n m = /^R(\\d+)C(\\d+)/.exec(s);\n if(m){\n print( toChar(m[2]) + m[1]);\n }else{\n m = /^([A-Z]+)(\\d+)/.exec(s);\n print( 'R' + m[2] + 'C' + toNum( m[1]) );\n }\n \n }\n \n function toChar(num){\n var ret = '';\n var t\n while(num>0){\n var u = num % 26;\n num = Math.floor( num/26 );\n ret = String.fromCharCode(u+64) + ret;\n }\n return ret;\n \n }\n function toNum(char){\n\tvar l = char.length;\n\tvar ret = 0;\n\tvar t = 1;\n\twhile(l--){\n\t\tret += ( char.charCodeAt(l)-64 ) * t;\n\t\tt *= 26\n\t}\n\treturn ret;\n}\n "}, {"source_code": "var n=parseInt(readline());\nvar regRC=/R(\\d+)C(\\d+)/;\nvar regSP=/([A-Z]+)([0-9]+)/;\nfor(var i=0;i=26)\n\t{\n\t\tresult=number2alpha(a)+result;\n\t}else if(a!=0)\n\t{\n\t\tresult=String.fromCharCode('A'.charCodeAt(0)+a)+result;\n\t}\n\treturn result;\n};\n\nfunction alpha2number(alpha){\n\tvar result=0;\n\tfor(var i=alpha.length-1;i>=0;i--){\n\t\tresult+=(alpha.charCodeAt(i)-65)*Math.pow(26, i-alpha.length+1);\n\t}\n\treturn result;\n};"}, {"source_code": "function a2c(a){\n var i, c = 0;\n for (i=0; i 1) c += Math.pow(26, a.length - 1);\n return c + 1;\n}\n\nfunction c2a(c){\n var q, r, a = '';\n\n c -= 1;\n if (c < 26) return String.fromCharCode(c + 65) + a;\n \n while (true){\n q = Math.floor(c / 26);\n r = c % 26;\n if (q == 0) {\n a = String.fromCharCode(r + 64) + a;\n break;\n }\n a = String.fromCharCode(r + 65) + a;\n c = q;\n }\n return a;\n}\n\nfunction convert(s){\n var i, temp;\n s = s.toUpperCase();\n \n if (/^[A-Z]{1,5}[1-9][0-9]*$/.test(s)) {\n for (i=0; i26;l = parseInt(l / 26))a=String.fromCharCode(l%26+65)+a;\n\treturn String.fromCharCode(+l+64)+a;\n}"}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 27; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "function a2c(a){\n return a.charCodeAt(0) - 64;\n}\n\nfunction c2a(c){\n var a = '';\n c = parseInt(c);\n if (c > 26)\n a = String.fromCharCode(Math.ceil(c / 26) + 63);\n return a + String.fromCharCode((c-1) % 26 + 65);\n}\n\nfunction convert(s){\n var i, c, temp, row=0, col=0;\n if (/^[A-Z][1-9][0-9]*$/.test(s))\n return \"R\" + s.substr(1) + \"C\" + a2c(s.substr(0,1));\n if (/^[A-Z]{2}[1-9][0-9]*$/.test(s))\n return \"R\" + s.substr(2) + \"C\" + (a2c(s.substr(0,1)) * 26 + a2c(s.substr(1,1)));\n if (/^R[1-9][0-9]*C[1-9][0-9]*$/.test(s)) {\n temp = s.split(\"C\");\n return c2a(temp[1]) + temp[0].substr(1);\n }\n return \"Invalid format\";\n}\n\nvar n = readline();\nfor (var i=0; i= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n \nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 27; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor-1 < pos) {\n por ++;\n valpor = valpor * 27;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction isRowColumnView(str) {\n return /R\\d+C\\d+/i.test(str);\n }\n \n function changeViewToCR(str) {\n var indexOfNumber = 0;\n var numberArr = [];\n var column;\n for (var i = 0; i < str.length; i++) {\n var char = str[i];\n if (isNaN(char)) {\n numberArr.push(char.charCodeAt(0) - 64);\n } else {\n indexOfNumber = i;\n break;\n }\n }\n column = numberArr.reduce( (col, elem, i) => {\n return col += elem * Math.pow(26, numberArr.length - 1 - i);\n }, 0)\n return `R${str.slice(indexOfNumber)}C${column}`;\n }\n \n function changeViewToExcel(str) {\n var indexOfC = str.indexOf(\"C\");\n var column = +str.slice(indexOfC + 1);\n var excelColumn = [];\n var sqrN = Math.floor(getBaseLog(26, column));\n var sqrnMax = sqrN;\n while (sqrN > -1) {\n var pow = Math.pow(26, sqrN);\n var tempNum = Math.floor(column/pow);\n //if (column % pow === 26 && tempNum === 1) {\n if (sqrN > 0 && tempNum === 1) {\n excelColumn.push(\"Z\");\n } else if (column % pow === 0 && sqrN !== 0){\n excelColumn.push(\"Z\");\n } else if ((tempNum === 0 && sqrN === 0) || (sqrN !== sqrnMax && excelColumn[sqrnMax - sqrN -1] === \"Z\")) {\n\n } else {\n excelColumn.push(String.fromCharCode(tempNum + 64));\n }\n column -= tempNum * pow;\n sqrN--;\n }\n //excelColumn.push(String.fromCharCode(tempNum + 64));\n var row = str.slice(1, indexOfC);\n return `${excelColumn.join('')}${row}`;\n }\n \n function getBaseLog(x, y) {\n return Math.log(y) / Math.log(x);\n }"}, {"source_code": "var n = parseInt(readline());\n\nprint(n);"}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}\nelse {\n print(\"\");\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var a,b;\nreadline();\n\nwhile(a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++)v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='',b=String.fromCharCode;\n for(l--;l>26;l=parseInt(l/26))a=b(l%26+64)+a;\n\treturn b(+l+64)+a;\n}\n"}, {"source_code": "var data = readline().split(\" \");\nvar n = data[0];\nvar int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\nfunction getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return Strung(number);\n}\n\n// RXCY\nif (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n}\n// Nomal\nelse if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n}\nelse {\n print(readline());\n}"}, {"source_code": "\nconst n = readline();\n\nconst lines = [];\nfor(var i=0;i 0);\n return result;\n}\n\nfunction colToNum(col) {\n var num = 0;\n for(var i=col.length - 1;i > -1;i--) {\n const chr = col[i];\n const n = Math.pow(26, col.length - i - 1) * (CHARS.indexOf(chr) + 1);\n num += n;\n }\n return num;\n}\n\nfunction trans(coord) {\n if(/^[A-Z]+\\d+$/.test(coord)) {\n var col = coord.match(/[A-Z]+/)[0];\n var row = coord.match(/\\d+/)[0];\n return 'R' + row + 'C' + colToNum(col);\n } else {\n var row = coord.match(/\\d+/)[0];\n var col = coord.match(/\\d+$/)[0];\n return numToCol(col) + row;\n }\n}\n\ndo {\n const line = lines.shift();\n print(line);\n} while(lines.length > 0);\n\n"}, {"source_code": "var n = readline();\nvar str;\nvar sub1,sub2;\nvar alf = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nvar res;\n\nfor (var i = 0; i < n; i++){\n str = readline();\n var re1 = /[R]\\d+[C]\\d+/g;\n var re2 = /\\d+/g;\n var re4 = /\\d+/;\n var re3 = /[A-Z]+/g;\n res = re1.exec(str);\n \n if (res != null){\n sub1 = re2.exec(str);\n sub2 = re2.exec(str);\n if (sub2 > 26) sub2--;\n res = \"\";\n while(sub2/26>1){\n res = alf[sub2%26]+res;\n sub2 = Math.floor(sub2/26);\n }\n res = alf[--sub2]+res;\n print(res+sub1);\n }\n else {\n sub = re3.exec(str);\n res = 0;\n sub = sub + \"\";\n var l = sub.length;\n for (var j = 0; j < l; j++){\n res += (alf.indexOf(sub[j])+1) * Math.pow(26,l-j-1)\n }\n sub = re4.exec(str);\n print(\"R\" + sub + \"C\" + res);\n }\n}"}, {"source_code": "//V8 3.31.1\n\nvar table = ['Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];\n//var n = readline();\nvar n = 1;\n\nwhile(n--) {\n //var s = readline();\n var s = \"R228C494\";\n var e = /R(\\d+)C(\\d+)/.exec(s);\n \n if(e) {\n print(getString(e[2]) + e[1]);\n }\n else {\n e = /([A-Z]+)(\\d+)/.exec(s);\n print('R' + e[2] + 'C' + getNum(e[1]));\n }\n}\n\nfunction getNum(e) {\n var len = e.length;\n //print(len);\n var total = 0;\n var temp = len;\n for(var i = 0;i < len; i++) {\n for(var j = 1;j <= table.length; j++) {\n if(e[i] == table[j]) {\n //print(j)\n //print(table[j])\n total += j * Math.pow(26, temp - 1);\n //print(total);\n temp--;\n }\n }\n }\n return total;\n}\n\nfunction getString(e) {\n //print(e);\n var answer = '';\n while(e / 26 > 0) {\n answer += table[e % 26];\n //print(e % 26);\n //print(answer);\n if(e % 26 != 0) {\n e = parseInt(e / 26);\n }\n else {\n e = parseInt(e / 26) - 1;\n }\n //print(e);\n //print(table[e % 26]);\n }\n if(e != 0) {\n answer += table[e];\n }\n //print(answer);\n return answer.split(\"\").reverse().join(\"\");\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k >= pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[str[j]] * Math.pow(26, j);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j == 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-2);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var tests = readline().split('\\n').slice(1);\nvar LETTERS = [\n 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'\n];\n \nfor (var i = 1; i < tests.length; i++) {\n print(calc(tests[i]));\n}\n \nfunction calc(str) {\n return isRC(str) && calcRC(str) || calcNRC(str);\n}\n \nfunction calcRC(str) {\n var res = [];\n var num = parseInt(str.slice(str.indexOf('C') + 1));\n var rest = 0;\n while (num) {\n rest = num % 26;\n res.push(LETTERS[rest]);\n if (rest === 0 && num === 26) break;\n num = Math.floor(num / 26);\n }\n \n return res.reverse().join('') + str.slice(1, str.indexOf('C'));\n}\n \nfunction calcNRC(str) {\n var letters = str.slice(0, str.search(/\\d/));\n var sum = 0;\n for (var i = letters.length - 1, p = 0; i >= 0; i--, p++) {\n var index = LETTERS.indexOf(letters[i]);\n sum += (index && index || 26) * Math.pow(26, p);\n }\n return 'R' + str.slice(letters.length) + 'C' + sum;\n}\n \nfunction isRC(str) {\n return /^R\\d*C\\d*$/.test(str);\n}"}, {"source_code": "var a,b;\nreadline();\n\nwhile (a=readline())print((b=a.match(/R(\\d+)C(\\d+)/))?M(b[2])+b[1]:(b=a.match(/^([A-Z]+)(\\d+)$/),'R'+b[2]+'C'+N(b[1])));\n\nfunction N(l){\n var n=l.length-1,i=v=0,c;\n\tfor(;c=l.charCodeAt(i)-64;i++) v=v+Math.pow(26,n-i)*c;\n\treturn v;\n}\n\nfunction M(l){\n var a='',b=String.fromCharCode;\n for(;l>26;l=parseInt(l/26))a=b(l%26+64)+a;\n\treturn b(l+64)+a;\n}\n"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j) * k >= pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j) * (k - 1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y.length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[str[j]] * Math.pow(26, j);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nconst abcChars = '_ABCDEFGHIGKLMNOPQRSTUVWXYZ';\nconst dec2abc = dec => {\n\tlet d = dec;\n\tlet res = '';\n\n\twhile (d > 0) {\n\t\tconst mod = d % 26;\n\t\tres = abcChars[mod === 0 ? 26 : mod] + res;\n\t\td = Math.floor(d / 26) - (mod === 0 ? 1 : 0);\n\t}\n\n\treturn res;\n};\nconst abc2dec = abc => {\n\tlet res = 0;\n\n\tfor (let i = 0; i < abc.length; i++) {\n\t\tres += abcChars.indexOf(abc[i]);\n\t\tif (i !== abc.length - 1) {\n\t\t\tres *= 26;\n\t\t}\n\t}\n\n\treturn res;\n};\n\nlet n, counter = 0;\nconst res = [];\n\nrl.on('line', function (line) {\n\tif (!n) {\n\t\tn = parseInt(line);\n\t} else {\n\t\tconst rc = line.match(/R(\\d+)C(\\d+)/);\n\t\tif (rc) {\n\t\t\tres.push(dec2abc(parseInt(rc[2])) + rc[1]);\n\t\t} else {\n\t\t\tconst regular = line.match(/([^\\d]+)(\\d+)/);\n\t\t\tres.push('R' + regular[2] + 'C' + abc2dec(regular[1]));\n\t\t}\n\n\t\tcounter++;\n\t\tif (counter === n) {\n\t\t\tfor (let i = 0; i < res.length; i++) {\n\t\t\t\tconsole.log(res[i]);\n\t\t\t}\n\t\t\trl.close();\n\t\t}\n\t}\n});\n"}, {"source_code": "var pos = readline();\nvar array = [];\n\nfor (var i = 0; i < pos; i++) {\n array.push(readline());\n}\n\nfor (var i = 0; i < array.length; i++) {\n var text = array[i];\n var pattern = /R[(0-9)]{1,100}C[(0-9)]{1,100}/;\n if (pattern.test(text)) {\n var row = 0;\n var col = 0;\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n if (text[j] == 'C') {\n separator = j;\n }\n }\n \n var row = parseInt(text.substring(0, separator).replace(/[^0-9]/g, ''));\n var col = parseInt(text.substring(separator, text.length).replace(/[^0-9]/g, ''));\n var text = '';\n while(col > 0) {\n if (col < 26) break;\n \n var remain = col % 26;\n col = Math.floor(col / 26);\n \n var char = String.fromCharCode(remain + 64);\n text = char + text;\n }\n \n var first = String.fromCharCode(col + 64);\n text = first + text;\n \n var converted = text + row;\n print(converted);\n } else {\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n var number = parseInt(text[j]);\n if (number >= 0 && number <= 9) {\n separator = j;\n break;\n }\n }\n \n var row = parseInt(text.substring(separator, text.length));\n var col = text.substring(0, separator);\n var colNum = 0;\n var ascii = 64;\n col = col.split('').reverse();\n for (var j = 0; j < col.length; j++) {\n var char = col[j].toUpperCase().charCodeAt(0) - ascii;\n if (j === 0) {\n colNum += char;\n } else {\n colNum += (26 * j * char);\n }\n }\n \n var converted = 'R' + row + 'C' + colNum;\n print(converted);\n }\n}"}, {"source_code": "function getNumToCol(num){\n var dividend = num;\n var columnName = \"\";\n var modulo;\n\n while (dividend > 0)\n {\n modulo = (dividend - 1) % 26;\n columnName = String.fromCharCode(65 + modulo).toString() + columnName;\n dividend = parseInt((dividend - modulo) / 26);\n } \n return columnName;\n}\n\nfunction getColToNum(col) {\n var len = col.length;\n var number = 0;\n\n for (var i = 0, l = len; i < l; i++) {\n var mod = col[l - (i+1)].charCodeAt() - 64;\n var number = number + (Math.pow(26, i) * mod);\n }\n\n return String(number);\n}\n\nfor (var i = 0, l = readline().split(\" \"); i < l; i++) {\n var n = String(readline().split(\" \"));\n var int = n.replace(/[^0-9]/g, \" \").trim().split(\" \");\n\n // RXCY\n if (n[0] == \"R\" && int.length == 2) {\n print(getNumToCol(int[1]) + String(int[0]));\n }\n // Nomal\n else if (/[A-Z]/.test(n[0]) && int.length == 1) {\n print(\"R\" + int[0] + \"C\" + getColToNum(n[0].replace(/[0-9]/g, \" \").split(\" \")[0]));\n }\n}"}, {"source_code": "\n// 1B \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n//var n = input_line[0];\n//var m = input_line[1];\n\nvar arr = [];\nvar out ='';\nvar reg = /^[R][\\d]+[C][\\d]+/;\nvar x, y;\n\nvar abc = '0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ';\narr = abc.split(' ');\n\nvar arr_S = [];\nfor (var i = 0; i < arr.length; i++) {\n arr_S[arr[i]] = i;\n};\n\n// expected: 'RZ228', found: 'SA228'\n\nfor (var i = 0; i < n; i++) {\n\n str = readline();\n\n if (reg.test(str)) {\n for (var j = 1; /\\d/.test(str[j]); j++) {};\n x = str.substring(1, j); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.substring(j+1, str.length );\n var pos = parseInt(y); // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n var valpor = 26; // \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n var por = 1; // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0432 26-\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435\n\n while (valpor < pos) {\n por ++;\n valpor = valpor * 26;\n }\n \n for (var j = por; j >=1; j--) {\n for (var k = 2; k <= 26; k++) {\n if (Math.pow(26, j-1) * k > pos) {\n out += arr[k-1];\n pos -= Math.pow(26, j-1) * (k - 1);\n break;\n };\n if (Math.pow(26, j-1) * k === pos) {\n if (j === 1) {\n out += arr[k];\n } else {\n out += arr[k-1];\n }; \n pos -= Math.pow(26, j-1) * (k-1);\n break;\n };\n };\n };\n\n out += x + \"\\n\";\n\n } else {\n x = str.match(/\\d+/); // \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438\n y = str.match(/[A-Z]+/); // \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\n var len = y[0].length;\n var posN = 0; // \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \n for (var j = len; j > 0; j--) {\n posN += arr_S[y[0].substring(len-j, len-j+1)] * Math.pow(26, j-1);\n };\n\n out += 'R' + x + 'C' + posN.toString() + \"\\n\";\n\n } \n};\n\nprint(out);\n "}, {"source_code": "var pos = readline();\nvar array = [];\n\nfor (var i = 0; i < pos; i++) {\n array.push(readline());\n}\n\nfor (var i = 0; i < array.length; i++) {\n var text = array[i];\n var pattern = /R[(0-9)]{1,10}C[(0-9)]{1,10}/;\n if (pattern.test(text)) {\n var row = 0;\n var col = 0;\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n if (text[j] == 'C') {\n separator = j;\n }\n }\n \n var row = parseInt(text.substring(0, separator).replace(/[^0-9]/g, ''));\n var col = parseInt(text.substring(separator, text.length).replace(/[^0-9]/g, ''));\n var text = '';\n while(col > 0) {\n if (col < 26) break;\n \n var remain = col % 26;\n col = Math.floor(col / 26);\n \n var char = String.fromCharCode(remain + 64);\n text = char + text;\n }\n \n var first = String.fromCharCode(col + 64);\n text = first + text;\n \n var converted = text + row;\n print(converted);\n } else {\n var separator = 0;\n for (var j = 0; j < text.length; j++) {\n var number = parseInt(text[j]);\n if (number >= 0 && number <= 9) {\n separator = j;\n break;\n }\n }\n \n var row = parseInt(text.substring(separator, text.length));\n var col = text.substring(0, separator);\n var colNum = 0;\n var ascii = 64;\n col = col.split('').reverse();\n for (var j = 0; j < col.length; j++) {\n var char = col[j].toUpperCase().charCodeAt(0) - ascii;\n if (j === 0) {\n colNum += char;\n } else {\n colNum += (26 * j * char);\n }\n }\n \n var converted = 'R' + row + 'C' + colNum;\n print(converted);\n }\n}"}], "src_uid": "910c0e650d48af22fa51ab05e8123709"} {"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.trim().split(EOL)\n \n main()\n})\n \nfunction main() {\n const rows = lines.slice(1)\n\n rows.forEach(r => console.log(isFinite(r.split(/\\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))\n}\n\nfunction isFinite([ a, b ]) {\n let t\n\n while(b) {\n t = a % b\n a = b\n b = t\n }\n\n return a === 1\n}\n", "positive_code": [{"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.trim().split(EOL)\n \n main()\n})\n \nfunction main() {\n const t = Number(lines[0])\n\n for(let i = 1; i <= t; i++) {\n const r = lines[i].split(/\\s/).map(Number).sort((a, b) => b - a)\n\n console.log(isFinite(r))\n }\n}\n\nfunction isFinite([ a, b ]) {\n let t\n\n while(b) {\n t = a % b\n a = b\n b = t\n }\n\n return a === 1 ? 'Finite' : 'Infinite'\n}\n"}, {"source_code": " var lines = parseInt(readline(), 10);\n\n function gcd(a, b) {\n while (true) {\n if (b === 0) return a;\n a %= b;\n if (a === 0) return b;\n b %= a;\n }\n }\n\n for (var i = 0; i < lines; i++) {\n var ab = readline()\n .split(\" \")\n .map(function(value) {\n return parseInt(value);\n })\n .sort();\n\n print(gcd(ab[0], ab[1]) > 1 ? \"Infinite\" : \"Finite\");\n }"}], "negative_code": [{"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.trim().split(EOL)\n \n main()\n})\n \nfunction main() {\n const rows = lines.slice(1)\n\n rows.forEach(r => console.log(isFinite(r.split(/\\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))\n}\n\nfunction isFinite([ a, b ]) {\n let t\n\n while(b) {\n t = a % b\n a = b\n b = t\n }\n\n return a !== 1\n}\n"}], "src_uid": "388450021f2f33177d905879485bb531"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => BigInt(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst max = (a, b) => a > b ? a : b;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\r\n\t\tconst ans = max(6n, n + 1n) / 2n * 5n;\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => BigInt(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\r\n\t\tif (n < 6) n = 6n;\r\n\t\tif (n&1n) n++;\r\n\r\n\t\tconsole.log((n*5n/2n).toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = BigInt(lines[l++])\n // var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n).toString())\n }\n});\n\nfunction solve(n) {\n // 6 8 10\n // 15 20 25\n if (n < 6n) {\n return 15n\n }\n if (n & 1n) {\n return solve(n + 1n)\n }\n const r = n % 6n\n const k = (n - r) / 6n\n if (r === 0n) {\n return k * 15n\n } else if (r === 2n) {\n return (k - 1n) * 15n + 20n\n } else if (r === 4n) {\n return (k - 1n) * 15n + 25n\n }\n}\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const n = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), n\r\n }\r\n readIntegersOfLine() {\r\n const n = this.readLine().match(integerRegex)\r\n return null == n ? [] : n.map(n => Number(n))\r\n }\r\n readNumsOfLine() {\r\n const n = this.readLine().match(decimalRegex)\r\n return null == n ? [] : n.map(n => Number(n))\r\n }\r\n print(n) {\r\n stdout.write(n)\r\n }\r\n async init() {\r\n const n = await this.readLines()\r\n this.lines = n\r\n }\r\n readLines() {\r\n const n = []\r\n return new Promise(e => {\r\n stdin.on('data', e => n.push(e)),\r\n stdin.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(n) {\r\n const e = new InputAndOutput()\r\n await e.init(), n(e)\r\n}\r\nfunction solve(n) {\r\n if (n <= 6n) return 15n\r\n if (n <= 8n) return 20n\r\n if (n <= 10n) return 25n\r\n return (5n * (n % 2n === 1n ? n + 1n : n)) / 2n\r\n}\r\n__main__(function (n) {\r\n const e = Number(n.readLine())\r\n for (let t = 1; t <= e; ++t) {\r\n const e = solve(BigInt(n.readLine()))\r\n n.print(e + '\\n')\r\n }\r\n})\r\n"}], "negative_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e) {\r\n if (e <= 6) return 15n\r\n if (e <= 8) return 20n\r\n if (e <= 10) return 25n\r\n let n = BigInt(e)\r\n return n % 2n === 1n && (n += 1n), (5n * n) / 2n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(Number(e.readLine()))\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e) {\r\n return e <= 6\r\n ? 15\r\n : e <= 8\r\n ? 20\r\n : e <= 10\r\n ? 25\r\n : 1 & e\r\n ? (5 * (e + 1)) / 2\r\n : (5 * e) / 2\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(Number(e.readLine()))\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e) {\r\n const n = Math.floor(e / 120),\r\n t = e - 120 * n,\r\n s = 12 * n * 25,\r\n i = t % 6,\r\n r = t % 8,\r\n o = t % 10\r\n return 0 === i || 0 === r || 0 === o\r\n ? s + ((5 * t) >> 1)\r\n : i >= r && i >= o\r\n ? s + 15 * Math.ceil(t / 6)\r\n : r >= i && r >= o\r\n ? s + 20 * Math.floor(t / 8) + (r <= 6 ? 15 : 20)\r\n : s + 25 * Math.floor(t / 10) + (o <= 6 ? 15 : o <= 8 ? 20 : 25)\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(Number(e.readLine()))\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}], "src_uid": "3e27f1c06a263760f5b53c3afe4bf7ee"} {"source_code": "\nconst { EOL } = require('os')\n\nconst solution = (startTemperature, customers) => {\n let time = 0\n const possibleRange = [\n startTemperature,\n startTemperature,\n ]\n\n let good = true\n\n for (const [ arrivalTime, low, high ] of customers) {\n if (good) {\n const elapsed = arrivalTime - time\n possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)\n possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)\n\n if (possibleRange[1] < possibleRange[0]) {\n good = false\n }\n\n time = arrivalTime\n }\n }\n\n return good\n}\n\nlet input = ''\n\nlet m = 0\nconst readline = () => {\n return input[m++]\n}\n\nconst readNumbers = () => readline().split(' ').map(Number)\n\nconst onEnd = () => {\n input = input.split(EOL)\n\n const [ inputCount ] = readNumbers()\n\n\n for (let i = 0; i < inputCount; i++) {\n const [ customerCount, startTemperature ] = readNumbers()\n const customers = (function * () {\n for (let j = 0; j < customerCount; j++) {\n yield readNumbers()\n }\n }())\n if (solution(startTemperature, customers)) {\n console.log('yes')\n } else {\n console.log('no')\n }\n\n while (!customers.next().done) {}\n }\n}\n\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', onEnd)\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const [n, m] = readInts(input, ptr++)\n const vis = new Array(n)\n for(let i = 0; i < n; i ++) {\n vis[i] = readInts(input, ptr++)\n }\n\n vis.sort((a, b) => a[0] - b[0])\n\n let li = m\n let hi = m\n let curr = 0\n let f = true\n for(let i = 0; i < n; i ++) {\n const [ti, l, h] = vis[i]\n let diff = ti - curr\n let changed = false\n if(l >= hi) {\n if(diff + hi >= l) {\n changed = true\n li = l\n hi = Math.min(hi + diff, h)\n }\n }\n else if(h <= li) {\n if(li - diff <= h) {\n changed = true\n hi = h\n li = Math.max(li - diff, l)\n }\n }\n else if(l >= li && h <= hi) {\n changed = true\n li = l\n hi = h\n }\n else if(l <= li && h <= hi) {\n changed = true\n li = Math.max(li - diff, l)\n hi = h\n }\n else if(l >= li && h >= hi) {\n changed = true\n li = l\n hi = Math.min(hi + diff, h)\n }\n else if(l <= li && h >= hi) {\n changed = true\n li = Math.max(li - diff, l)\n hi = Math.min(hi + diff, h)\n }\n\n // console.log(l, h, li, hi, diff)\n if(!changed) {\n wr('NO')\n f = false\n break\n }\n curr = ti\n }\n\n if(f) wr('YES')\n }\n}"}, {"source_code": "var q = parseInt(readline())\n\nwhile(q--)\n{\n var input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var n = input[0];\n var m = input[1];\n\n var ct = 0;\n var cl = m;\n var ch = m;\n var can = 'YES';\n while(n--)\n {\n input = readline().split(\" \").map(function(x) { return parseInt(x); }); \n var t = input[0];\n var l = input[1];\n var h = input[2];\n\n var delT = t - ct;\n var ct = t;\n var cl = Math.max(cl - delT, l);\n var ch = Math.min(ch + delT, h);\n\n if (cl > ch)\n {\n can = 'NO';\n }\n }\n print(can);\n}"}], "negative_code": [{"source_code": "\nconst { EOL } = require('os')\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n const lines = input.split(EOL) /*your input text, split by lines*/\n console.log(lines); \n})\n\ninput = input.split(EOL)\n\nlet i = 0\nconst readline = () => {\n return input[i++]\n}\n\nconst solution = (startTemperature, customers) => {\n console.log('startTemperature', startTemperature, 'customers', customers)\n let time = 0\n const possibleRange = [\n startTemperature,\n startTemperature,\n ]\n\n for (const [ arrivalTime, low, high ] of customers) {\n console.log([ arrivalTime, low, high ])\n const elapsed = arrivalTime - time\n possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)\n possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)\n\n if (possibleRange[1] < possibleRange[0]) {\n return false\n }\n\n time = arrivalTime\n }\n\n return true\n}\n\nconst readNumbers = () => readline().split(' ').map(Number)\n\nconsole.log('start')\n\nconsole.log('typeof readline', typeof readline)\n\nconst inputCount = readNumbers()\n\nconsole.log('inputCount', inputCount)\n\nfor (let i = 0; i < inputCount; i++) {\n const [ customerCount, startTemperature ] = readNumbers()\n const customers = (function * () {\n for (let j = 0; j < customerCount; j++) {\n yield readNumbers()\n }\n }())\n if (solution(startTemperature, customers)) {\n console.log('yes')\n } else {\n console.log('no')\n }\n}\n"}], "src_uid": "a75b8b9b99b800762645ef7c3bc29905"} {"source_code": "var repeatTimes = readline();\r\n\r\nwhile (repeatTimes--) {\r\n var sum = 0;\r\n var res = 0;\r\n var a = readline().split(' ').map(Number);\r\n var n = a[0], B = a[1], x = a[2], y = a[3];\r\n \r\n while(n) {\r\n sum += sum + x <= B ? x : -y;\r\n res += sum;\r\n n--;\r\n }\r\n \r\n print(res);\r\n}", "positive_code": [{"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var n = a[0];\r\n var B = a[1], x = a[2], y = a[3];\r\n var sum = 0;\r\n var ans = 0;\r\n \r\n while(n > 0) {\r\n sum += sum + x <= B ? x : -y;\r\n ans += sum;\r\n n--;\r\n }\r\n print(ans);\r\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\r\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\r\nconst print = console.log\r\nconst lines = []\r\nrl.on('line', line => {\r\n lines.push(line);\r\n});\r\nrl.on('close', main)\r\nlet rli = 0;\r\nfunction readline() {\r\n return lines[rli++];\r\n}\r\nconst EPS = 1e-6;\r\n \r\nfunction sum(n, B, x, y){\r\n let sum = 0;\r\n let a = 0;\r\n for (let i=0; i+a);\r\n print(sum(n, B, x, y))\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 125 (Div. 2)\n2022-03-22\n\nB. XY Sequence\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n let s;\n for (let i = 0; i < t; i++) {\n // INPUT: 'n B x y'\n // n (int 1..2e5) : length of Sequence\n // b (int 1..1e10) : max of any element\n // x (int 1..1e10) : a' = a+x possible\n // y (int 1..1e10) : a' = a+y possible\n s = readline();\n s = s.split(' ');\n const n = parseInt(s[0]);\n const b = parseInt(s[1]);\n const x = parseInt(s[2]);\n const y = parseInt(s[3]);\n\n // we might want to think of the problem as a linear combination\n // fx-gy where f+g = 1+2+3+...+(n-1) = n(n-1)/2\n\n // x and y are positive so we can subtract all the y's first\n // and then add the x's (so don't worry about going over)\n\n // we might be able to greed x until you can't add any more x's\n // (we want as many x's as we can early on)\n\n let a = 0;\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (a + x <= b) {\n a = a + x;\n } else {\n a = a - y;\n }\n sum += a;\n }\n console.log(sum);\n }\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var n = a[0], b = a[1], x = a[2], y = a[3];\n var ans = 0;\n var e = 0;\n for(j = 0; j < n; j++){\n if(e + x <= b){\n e += x;\n }else{\n e -= y;\n }\n ans += e;\n }\n console.log(ans);\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, B, x, y] = readline().split(' ').map(Number);\r\n let sum = 0;\r\n let curr = 0;\r\n\r\n for (let i = 1; i <= n; i++) {\r\n let lg = curr + x;\r\n let sm = curr - y;\r\n if (lg > B) curr = sm; else curr = lg;\r\n sum += curr;\r\n }\r\n\r\n output(sum);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, b, x, y] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, b, x, y)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, b, x, y) {\n let now = 0\n let ans = 0\n for (let i = 1; i <= n; i++) {\n if (now + x <= b && now + x - y <= b) {\n now += x\n } else {\n now -= y\n }\n ans += now\n // console.log(now)\n }\n return ans\n}\n"}], "negative_code": [{"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var x = a[0];\r\n var y = a[1];\r\n \r\n if (x === 0 && y === 0) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n var z = Math.sqrt(x * x + y * y);\r\n \r\n var r = Math.round(z);\r\n if (Math.abs(z - r) < 0.000001) {\r\n print(1);\r\n continue;\r\n }\r\n \r\n print(2);\r\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst EPS = 1e-6;\n\nfunction sum(n, B, x, y){\n let sum = 0;\n let a = 0;\n for (let i=0; i+a);\n print(sum(n, B, x, y))\n }\n}"}], "src_uid": "2c921093abf2c5963f5f0e96cd430456"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = +$()\n while (t--) {\n let n = +$(), s = $(), ne = Arr(n, i => i + 1);\n let res = 0, i = 0, j = 0;\n while (i < n) {\n res++;\n while (j < n && s[j] != s[ne[j]]) j = ne[j];\n if (j < n) {\n ne[j] = ne[ne[j]];\n } else {\n i = ne[i];\n }\n while (i < n && s[i] == s[ne[i]]) i = ne[i];\n if (i >= n) break;\n i = ne[i];\n if (j < i) j = i;\n // log(res, i, j)\n }\n log(res)\n }\n}\n", "positive_code": [{"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n var initialStrain = true;\n for (var j = 0; j < length; j++) {\n if (currBit == binString[j]) {\n strain++;\n } else {\n if (strain > 1) {\n operations++;\n spare += strain - 2;\n if (waitForSalvation < spare) {\n operations += waitForSalvation;\n spare = 0;\n waitForSalvation = 0;\n } else {\n operations += spare;\n waitForSalvation -= spare;\n spare = 0;\n }\n } else {\n waitForSalvation++;\n }\n currBit = binString[j];\n strain = 1;\n }\n }\n\n if (strain > 1) {\n operations++;\n\n spare += strain - 2;\n if (waitForSalvation < spare) {\n operations += waitForSalvation;\n spare = 0;\n waitForSalvation = 0;\n } else {\n operations += spare;\n waitForSalvation -= spare;\n spare = 0;\n }\n } else {\n waitForSalvation++;\n }\n\n // if (spare >= waitForSalvation) {\n // operations += waitForSalvation;\n // } else {\n // operations += spare;\n // waitForSalvation -= spare;\n operations += Math.ceil(waitForSalvation / 2);\n //}\n // if(!blank)\n // {\n // operations++;\n // }\n print(operations);\n}\n"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = +$()\n while (t--) {\n let n = +$(), s = $()\n let res = 0, i = 0, j = n - 1\n while (i <= j) {\n res++;\n if (s[i] == s[i + 1]) {\n while (s[i] == s[i + 1]) i++;\n i++;\n } else {\n i++;\n j--;\n }\n // log(res, i, j)\n }\n log(res)\n }\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n for (var j = 0; j < length; j++) {\n\n\n if (currBit == binString[j]) {\n strain++;\n } else {\n if (strain > 1) {\n operations++;\n spare+=strain-2;\n currBit = binString[j];\n strain=1;\n }\n else\n {\n waitForSalvation++;\n strain=1;\n currBit = binString[j];\n }\n }\n }\n if (strain > 1) {\n operations++;\n spare+=strain-2;\n currBit = binString[j];\n strain=1;\n}\nelse\n{\n waitForSalvation++;\n}\n\nif(spare>=waitForSalvation)\n{\n operations+=waitForSalvation;\n}\nelse\n{\n operations+=spare;\n waitForSalvation-=spare;\n operations+=Math.ceil(waitForSalvation/2);\n}\n// if(!blank)\n// {\n// operations++;\n// }\n print(operations);\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n var initialStrain = true;\n for (var j = 0; j < length; j++) {\n if (currBit == binString[j]) {\n strain++;\n } else {\n\n if (strain > 1) {\n operations++;\n if(!initialStrain)\n {\n spare += strain - 2;\n }\n else\n {\n initialStrain = false;\n }\n \n } else {\n waitForSalvation++;\n }\n currBit = binString[j];\n strain = 1;\n }\n }\n if (strain > 1) {\n operations++;\n if(!initialStrain)\n {\n spare += strain - 2;\n }\n else\n {\n initialStrain = false;\n }\n } else {\n operations++;\n }\n\n if (spare >= waitForSalvation) {\n operations += waitForSalvation;\n } else {\n operations += spare;\n waitForSalvation -= spare;\n operations += Math.ceil(waitForSalvation / 2);\n }\n // if(!blank)\n // {\n // operations++;\n // }\n print(operations);\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit;\n var operations = 0;\n var blank = true;\n for (var j = 0; j < length; j++) {\n if (blank) {\n strain=1\n currBit = binString[j];\n blank=false;\n continue;\n }\n\n if (currBit == binString[j]) {\n strain++;\n } else {\n if (strain > 1) {\n operations++;\n currBit = binString[j];\n strain=1;\n }\n else\n {\n operations++;\n blank = true;\n }\n }\n }\n\n if(!blank)\n {\n operations++;\n }\n print(operations);\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n for (var j = 0; j < length; j++) {\n\n\n if (currBit == binString[j]) {\n strain++;\n } else {\n if (strain > 1) {\n operations++;\n spare+=strain-2;\n currBit = binString[j];\n strain=1;\n }\n else\n {\n waitForSalvation++;\n strain=0;\n currBit = binString[j];\n }\n }\n }\n if (strain > 1) {\n operations++;\n spare+=strain-2;\n currBit = binString[j];\n strain=1;\n}\nelse\n{\n waitForSalvation++;\n}\n\nif(spare>=waitForSalvation)\n{\n operations+=waitForSalvation;\n}\nelse\n{\n operations+=spare;\n waitForSalvation-=spare;\n operations+=Math.ceil(waitForSalvation/2);\n}\n// if(!blank)\n// {\n// operations++;\n// }\n print(operations);\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n var initialStrain = true;\n for (var j = 0; j < length; j++) {\n if (currBit == binString[j]) {\n strain++;\n } else {\n\n if (strain > 1) {\n operations++;\n \n \n spare += strain - 2;\n if(waitForSalvation 1) {\n operations++;\n \n spare += strain - 2;\n if(waitForSalvation= waitForSalvation) {\n // operations += waitForSalvation;\n // } else {\n // operations += spare;\n // waitForSalvation -= spare;\n operations += Math.ceil(waitForSalvation / 2);\n //}\n // if(!blank)\n // {\n // operations++;\n // }\n print(operations);\n}\n"}, {"source_code": "var inputs = parseInt(readline());\nfor (var i = 0; i < inputs; i++) {\n var length = parseInt(readline());\n var binString = readline();\n var strain = 0;\n var currBit = binString[0];\n var operations = 0;\n var spare = 0;\n var waitForSalvation = 0;\n for (var j = 0; j < length; j++) {\n if (currBit == binString[j]) {\n strain++;\n } else {\n if (strain > 1) {\n operations++;\n spare += strain - 2;\n } else {\n waitForSalvation++;\n }\n currBit = binString[j];\n strain = 1;\n }\n }\n if (strain > 1) {\n operations++;\n spare += strain - 2;\n } else {\n operations++;\n }\n\n if (spare >= waitForSalvation) {\n operations += waitForSalvation;\n } else {\n operations += spare;\n waitForSalvation -= spare;\n operations += Math.ceil(waitForSalvation / 2);\n }\n // if(!blank)\n // {\n // operations++;\n // }\n print(operations);\n}\n"}], "src_uid": "d0030996e6b29c8580463fae43bb04d4"} {"source_code": "var test = readline(), x, b;\nwhile(test--) {\n x = readline();\n b = x - 1;\n print('1 ' + b);\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n// your code goes here\nvar arr = '';\nprocess.stdin.on('data',function(chunk){\n arr+=chunk;\n arr = arr.split('\\r\\n');\n let ncase= arr.length - 1;\n let x = 1;\n while(x {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const x = readInt()\n wr(x - 1 + \" \" + 1)\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar x = nextInt();\n \toutput[i] = \"1 \" + (x - 1);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nconst gcd = (a, b) => {\n while (b !== 0) {\n const t = b;\n b = a % b;\n a = t;\n }\n\n return a;\n};\n\nconst lcm = (a, b) => {\n return (a * b) / gcd(a, b);\n};\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const n = +d;\n console.log(1, n - 1);\n\n c++;\n});\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst sol = () => {\n nums = data.trim().split(/\\n/g).map(Number);\n nums.shift();\n result = nums.map((e) => {\n return `1 ${e-1}`;\n });\n console.log(result.join('\\n'));\n}\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const x = getInt()\n print(1, x - 1)\n }\n}"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var num = +readline();\n print(`${num - 1} ${1}`);\n }\n}\nmain()"}, {"source_code": "var t = parseInt(readline());\nwhile(t-- > 0){\n var n = parseInt(readline());\n print(`1 ${n-1}`);\n}"}, {"source_code": "var test = readline(), x;\nwhile(test--) {\n x = readline();\n print('1 ' + (x - 1));\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let times = readline();\n while (times--) {\n let input = parseInt(readline());\n output(input - 1, 1);\n }\n \n}\nfunction output(...ans) {\n console.log(ans.join(' '));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n let n = parseInt(readline());\n for (let i = 0; i < n; i++) {\n const number = parseInt(readline());\n console.log(`1 ${number - 1}`);\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n// your code goes here\nvar arr = '';\nprocess.stdin.on('data',function(chunk){\n arr+=chunk;\n arr = arr.split('\\r\\n');\n let ncase= arr.length - 1;\n let x = 1;\n while(x<=ncase){\n console.log(arr[x]-1,1);\n x++;\n }\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n \n// your code goes here\n \nvar arr = '';\n \nprocess.stdin.on('data',function(chunk){\n arr+=chunk;\n arr = arr.split('\\r\\n');\n let ncase= arr.length - 1;\n let x = 1;\n while(x<=ncase){\n console.log(arr[x]-1,1);\n x++;\n }\n});"}], "src_uid": "2fa3e88688b92c27ad26a23884e26009"} {"source_code": "var firstLayout = readline()\nvar secondLayout = readline()\n\nvar input = readline();\nvar output = '';\n\nfor (var i = 0; i < input.length; i++) {\n var char = input[i];\n \n if (~'0123456789'.indexOf(char)) {\n output += char;\n continue;\n }\n\n if (char === char.toUpperCase()) {\n var LayoutCharPos = firstLayout.indexOf(char.toLowerCase());\n output += secondLayout[LayoutCharPos].toUpperCase();\n } else {\n var LayoutCharPos = firstLayout.indexOf(char);\n output += secondLayout[LayoutCharPos];\n }\n}\n\nprint(output);", "positive_code": [{"source_code": "var k1 = readline();\nvar k2 = readline();\nvar inp = readline();\n\nvar i = 0, j = 0, z = 0, l = inp.length, out = \"\";\n\nfor(i = 0; i< l; i++)\n{\n // \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n if(inp.charCodeAt(i) >= 65 && inp.charCodeAt(i) <= 90)\n {\n z = inp.charCodeAt(i)+32;\n for(j = 0; j< 26; j++)\n {\n if(k1.charCodeAt(j) == z)\n {\n out = out + k2[j].toUpperCase();\n }\n } \n }\n else if(inp.charCodeAt(i) >= 97 && inp.charCodeAt(i) <= 122)\n // \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n {\n for(j = 0; j< 26; j++)\n {\n z = inp.charCodeAt(i);\n if(k1.charCodeAt(j) == z)\n {\n out = out + k2[j];\n }\n } \n \n }\n // \ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n else\n {\n out = out + inp[i];\n }\n}\n\n\nprint(out);\n"}, {"source_code": "var from = readline().split('')\nvar to = readline().split('')\nvar convert = readline().split('')\nprint(convert.map(x => !isNaN(x) ? x : to[from.indexOf(x)] || to[from.indexOf(x.toLowerCase())].toUpperCase() ).join(''))"}, {"source_code": "var layout1 = readline();\nvar layout2 = readline();\nvar input = readline();\n\nvar output = '';\nfor(var i=0; i {\n if (c === 0) {\n l1 = d;\n c++;\n return;\n }\n\n if (c === 1) {\n l2 = d;\n c++;\n return;\n }\n\n const text = d;\n let ans = '';\n const obj = {};\n\n for (let i = 0; i < l1.length; i++) {\n obj[l1[i]] = l2[i];\n obj[l1[i].toUpperCase()] = l2[i].toUpperCase();\n }\n\n for (let i = 0; i < text.length; i++) {\n if (obj[text[i]]) {\n ans += obj[text[i]];\n }\n else {\n ans += text[i];\n }\n }\n\n // for (let i = 0; i < text.length; i++) {\n // const idx = l1.indexOf(text[i]);\n // const idxLower = l1.indexOf(text[i].toLowerCase());\n\n // if (idx !== -1) {\n // ans += l2[idx];\n // }\n // else if (idxLower !== -1) {\n // ans += l2[idxLower].toUpperCase();\n // }\n // else {\n // ans += text[i];\n // }\n // }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l1, l2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n l1 = d;\n c++;\n return;\n }\n\n if (c === 1) {\n l2 = d;\n c++;\n return;\n }\n\n const text = d;\n let ans = '';\n\n for (let i = 0; i < text.length; i++) {\n const idx = l1.indexOf(text[i]);\n const idxLower = l1.indexOf(text[i].toLowerCase());\n\n if (idx !== -1) {\n ans += l2[idx];\n }\n else if (idxLower !== -1) {\n ans += l2[idxLower].toUpperCase();\n }\n else {\n ans += text[i];\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "\n var recorder = readline(),\n derecorder = readline(),\n record = readline(),\n result = '';\n\n for (var i = 0; i < record.length; i++){\n var number = recorder.indexOf(record[i]);\n var numberUpper = recorder.indexOf(record[i].toLowerCase()); \n if (number >= 0 ){\n result += derecorder[number];\n } else if(numberUpper >= 0){\n result += derecorder[numberUpper].toUpperCase();\n } else if (!isNaN(parseInt(record[i]))){\n result += record[i];\n }\n }\n \nprint(result);"}, {"source_code": "alph1 = readline();\nalph2 = readline();\ns = readline();\ns1 = '';\nfor(var i=0; i< s.length; i++) {\n var char = s[i];\n if (/[0-9]/.test(char)) {\n s1 = s1 + char;\n continue;\n }\n var lowChar = s[i].toLowerCase();\n var resChar = alph2[alph1.indexOf(lowChar)];\n if (char != lowChar) {\n resChar = resChar.toUpperCase();\n }\n s1 = s1 + resChar;\n}\n\nprint(s1);"}, {"source_code": "var fr = readline().split('')\nvar to = readline().split('')\nvar convert = readline().split('')\nwrite(convert.map(x => !isNaN(x) ? x : to[fr.indexOf(x)] || to[fr.indexOf(x.toLowerCase())].toUpperCase()).join(''))"}, {"source_code": "(function main(){\n //http://codeforces.com/problemset/problem/831/B\n var layout1Minusculas = readline();\n var layout1Mayusculas = layout1Minusculas.toUpperCase();\n var layout2Minusculas = readline();\n var layout2Mayusculas = layout2Minusculas.toUpperCase();\n var datos = readline();\n\n var salida = \"\";\n for (var i = 0; i < datos.length; i++) {\n if(!isNaN((datos[i]))){\n salida += datos[i];\n }else if(caracterEsMayuscula(i)){\n traducir(i, layout1Mayusculas, layout2Mayusculas);\n }else{\n traducir(i, layout1Minusculas, layout2Minusculas);\n }\n }\n\n function caracterEsMayuscula(index){\n var charcode = datos.charCodeAt(index);\n return charcode >= 65 && charcode <= 90;\n }\n\n function traducir(index, layoutInicial, layoutFinal){\n var indexLayout = layoutInicial.indexOf(datos[i]);\n salida += layoutFinal.charAt(indexLayout);\n }\n\n print(salida);\n})();"}], "negative_code": [{"source_code": "function derecording(record, recorder, derecorder){\n var result = '';\n\n for (var i = 0; i < record.length; i++){\n var number = recorder.indexOf(record[i]);\n var numberUpper = recorder.indexOf(record[i].toLowerCase()); \n if (number >= 0 ){\n result += derecorder[number];\n } else if(numberUpper >= 0){\n result += derecorder[numberUpper].toUpperCase();\n } else if (!isNaN(parseInt(record[i]))){\n result += record[i];\n }\n }\n\n return result;\n}"}], "src_uid": "d6f01ece3f251b7aac74bf3fd8231a80"} {"source_code": "'use strict';\n\nconst a = readline();\nconst n = a.length;\n\nconst ans = new Array(n).fill(0);\n\nfor (let i = 1; i < n; i++) {\n if (a[i] == 'a') {\n ans[i - 1] = 1 - ans[i - 1];\n ans[i] = 1 - ans[i];\n } \n}\n\nprint(ans.join(' '));", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', cin, cout;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n cout = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n cin = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main() {\n function swap(line, i) {\n return line.substr(0, i+1).split(\"\").reverse().join(\"\") + line.substr(i+1);\n }\n \n let line = cin().replace(/\\r?\\n/g, \"\").trim();\n let ans = '';\n \n for (let i = 0; i < line.length; i++) {\n if (line[0] === 'b') {\n if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {\n ans += '1 ';\n line = swap(line, i);\n } else {\n ans += '0 ';\n }\n } else {\n if (line[i] === 'b' && line[i+1] === 'a') {\n ans += '1 ';\n line = swap(line, i);\n } else if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {\n ans += '1 ';\n line = swap(line, i);\n } else {\n ans += '0 ';\n }\n }\n } \n \n cout(ans.trim());\n //cout(line);\n \n return 0;\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst interface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\n\nlet smallest = [0]\nlet largest = [0]\ninterface.on('line', line => {\n for (let i = 1; i < line.length; i++) {\n if (line[i] == 'a') {\n smallest = largest.concat(1)\n largest = largest.concat(0)\n } else if(line[i] == 'b'){\n largest = smallest.concat(1)\n smallest = smallest.concat(0)\n }\n }\n ouputSolution(smallest)\n})\n\nfunction ouputSolution (list) {\n let str = ''\n for (let i = 0; i < list.length; i++) {\n str += list[i] + ' '\n }\n console.log(str)\n}"}], "negative_code": [{"source_code": "'use strict';\n\nconst a = readline();\nconst n = a.length;\n\nconst ans = new Array(n).fill(0);\n\nfor (let i = 1; i < n; i++) {\n if (a[i] == 'a') {\n ans[i - 1] = 1 - ans[i - 1];\n } \n}\n\nans[n - 1] = 1;\n\nprint(ans.join(' '));"}], "src_uid": "fc0d3b122d800dcbcb99795581229d42"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0; i < 2*n; i++) {\r\n\t\t\tmp.set(a[i], [mp.has(a[i]) ? mp.get(a[i])[0] + 1 : 1, 0]);\r\n\t\t}\r\n\r\n\t\tfunction use (k) {\r\n\t\t\tif (mp.has(k)) {\r\n\t\t\t\tconst [cnt, curcnt] = mp.get(k);\r\n\t\t\t\tif (curcnt < cnt) {\r\n\t\t\t\t\tmp.set(k, [cnt, curcnt + 1]);\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tfunction resetMap() {\r\n\t\t\tfor (const [ky, [cnt, curcnt]] of mp.entries()) {\r\n\t\t\t\tmp.set(ky, [cnt, 0]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans, ansx;\r\n\t\tfor (let i = 0; i < 2*n - 1; i++) {\r\n\t\t\tresetMap();\r\n\t\t\tuse(a[i]);\r\n\t\t\tcurx = a[2*n - 1];\r\n\t\t\tok = true;\r\n\t\t\tans = [[a[i], a[2*n - 1]]];\r\n\t\t\tfor (let j = 2*n - 2; j >= 0; j--) {\r\n\t\t\t\tif (j != i) {\r\n\t\t\t\t\tconst [cnt, curcnt] = mp.get(a[j]);\r\n\t\t\t\t\tif (cnt == curcnt) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tuse(a[j]);\r\n\t\t\t\t\tif (use(curx - a[j])) {\r\n\t\t\t\t\t\tans.push([a[j], curx - a[j]]);\r\n\t\t\t\t\t\tcurx = Math.max(a[j], curx - a[j]);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (ok) {\r\n\t\t\t\tansx = a[2*n-1] + a[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (ansx) {\r\n\t\t\tconsole.log('YES\\n', ansx);\r\n\t\t\tfor (const row of ans)\r\n\t\t\t\tconsole.log(row.join(' '));\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0; i < 2*n; i++) {\r\n\t\t\tconst [cnt, usecnt] = mp.has(a[i]) ? mp.get(a[i]) : [0, 0];\r\n\t\t\tmp.set(a[i], [cnt + 1, usecnt]);\r\n\t\t}\r\n\r\n\t\tfunction use (k) {\r\n\t\t\tif (mp.has(k)) {\r\n\t\t\t\tconst [cnt, usecnt] = mp.get(k);\r\n\t\t\t\tif (usecnt < cnt) {\r\n\t\t\t\t\tmp.set(k, [cnt, usecnt + 1]);\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tfunction resetMap () {\r\n\t\t\tfor (const [ky, [cnt, usecnt]] of mp.entries()) {\r\n\t\t\t\tmp.set(ky, [cnt, 0]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; !ans.length && i < 2*n - 1; i++) {\r\n\t\t\tresetMap();\r\n\t\t\tlet curx = a[2*n - 1] + a[i];\r\n\t\t\tfor (let j = 2*n - 1; j >= 0; j--) {\r\n\t\t\t\tconst [cnt, usecnt] = mp.get(a[j]);\r\n\t\t\t\tif (cnt == usecnt) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tuse(a[j]);\r\n\t\t\t\tif (use(curx - a[j])) {\r\n\t\t\t\t\tans.push([a[j], curx - a[j]]);\r\n\t\t\t\t\tcurx = Math.max(a[j], curx - a[j]);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tans = [];\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (ans.length) {\r\n\t\t\tconsole.log('YES\\n', ans[0][0] + ans[0][1]);\r\n\t\t\tfor (const row of ans)\r\n\t\t\t\tconsole.log(row.join(' '));\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n a.sort((a, b) => b - a);\r\n next: for (let skip = 1; skip < 2 * n; skip++) {\r\n const res = [];\r\n res.push([a[0]]);\r\n const vis = new Set([0]);\r\n let sum = a[0];\r\n const map = new Map();\r\n for (let [i, num] of a.entries()) {\r\n if (i === 0 || i === skip) continue;\r\n if (!map.has(num)) map.set(num, []);\r\n map.get(num).push(i);\r\n }\r\n for (let i = 1; i < 2 * n; i++) {\r\n if (vis.has(i) || skip === i) continue;\r\n const x = a[i],\r\n y = sum - x;\r\n const b = map.get(y);\r\n if (!b || !b.length || b.length === 1 && b[0] === i) continue next;\r\n let j = b.pop();\r\n if (j === i) j = b.pop();\r\n vis.add(i);\r\n vis.add(j);\r\n res.push([a[i], y]);\r\n sum = x;\r\n }\r\n for (let i = 0; i < 2 * n; i++) {\r\n if (!vis.has(i)) res[0].push(a[i]);\r\n }\r\n return `YES\\n${res[0][0] + res[0][1]}\\n` + res.map(arr => arr.join(' ')).join('\\n');\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n a.sort((a, b) => b - a);\r\n const nums = new Map([...new Set(a)].sort((a, b) => a - b).map((num, i) => [num, i]));\r\n const N = nums.size;\r\n const g = Array.from({\r\n length: N\r\n }, () => []);\r\n for (let i = 0; i < 2 * n; i++) {\r\n for (let j = i + 1; j < 2 * n; j++) {\r\n const sum = a[i] + a[j];\r\n if (nums.has(sum)) {\r\n g[nums.get(sum)].push([i, j]);\r\n }\r\n }\r\n }\r\n let res = [];\r\n const dfs = (sum = a[0], vis = new Set([0]), path = [[0]]) => {\r\n if (vis.size === 2 * n - 1) {\r\n res = [...path];\r\n return true;\r\n }\r\n for (let [i, j] of g[nums.get(sum)]) {\r\n if (vis.has(i) || vis.has(j)) continue;\r\n vis.add(i);\r\n vis.add(j);\r\n path.push([i, j]);\r\n let res = false;\r\n if (a[i] > a[j]) {\r\n res = dfs(a[i], vis, path);\r\n } else {\r\n res = dfs(a[j], vis, path);\r\n }\r\n vis.delete(i);\r\n vis.delete(j);\r\n path.pop();\r\n if (res) return true;\r\n }\r\n return false;\r\n };\r\n if (dfs()) {\r\n let vis = [];\r\n for (let [i, j] of res) {\r\n vis[i] = 1;\r\n vis[j] = 1;\r\n }\r\n for (let i = 1; i < 2 * n; i++) {\r\n if (!vis[i]) {\r\n res[0].push(i);\r\n break;\r\n }\r\n }\r\n return 'YES\\n' + res.map(arr => arr.map(i => a[i]).join(' ')).join('\\n');\r\n } else {\r\n return 'NO';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "src_uid": "d54205c8096408ae64b15ab0a344582e"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(f){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rr[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;te){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(r[o]>r[o+1]&&e>r[o+1])return void i.default.puts(-1)}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let swaps = 0\n// \n// for (let i = 0; i < n - 1; ++i) {\n// if (a[i] > a[i + 1]) {\n// // try to fix\n// \n// if (a[i + 1] >= x) {\n// for (let j = 0; j < i; ++j) {\n// if (a[j] > x) {\n// let t = a[j]\n// a[j] = x\n// x = t\n// swaps++\n// }\n// }\n// let t = a[i]\n// a[i] = x\n// x = t\n// swaps++\n// } else {\n// io.puts(-1)\n// return\n// }\n// }\n// \n// // io.debug(a)\n// \n// if (a[i] > a[i + 1]) {\n// if (x > a[i + 1]) {\n// io.puts(-1)\n// return\n// }\n// \n// // let t = a[i + 1]\n// // a[i + 1] = x\n// // x = t\n// // swaps++\n// }\n// }\n// \n// io.puts(swaps)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "/*\n * File Created: Monday, 30th November 2020 3:31:00 pm\n * Author: Lukas Rimkus\n */\n\n'use-strict'\n\nconst { count } = require(\"console\");\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\ndata += chunk;\n});\n\nprocess.stdin.on('end', () =>{\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const n = data.shift().split(' ').map(Number);\n\n const arr = data.shift().split(' ').map(Number);\n\n const res = d(n[0], n[1], arr);\n\n console.log(res)\n }\n});\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n \nfunction readLine() { \n return data[currentLine++];\n}\n \n\nfunction a(num)\n{\n return num.length ;\n}\n\n\n\nfunction b(goal)\n{\n\n function jump1(y,k)\n {\n return y + k;\n }\n function jump2(y)\n {\n return y - 1;\n }\n\n let sum = 0;\n\n let jumps = 0;\n\n let arr = [];\n\n while(sum < goal)\n {\n jumps++;\n\n arr.push(jumps);\n\n sum = sum + jumps;\n }\n \n if(sum === goal)\n {\n return arr.length;\n }\n else\n {\n let current_pos = sum;\n\n // that's how many steps back;\n let diference = current_pos - goal; \n\n console.log(arr, arr.length, sum, diference)\n\n for(let i = 0 ; i < arr.length; i++)\n {\n if((arr[i] + 1) === diference)\n {\n return arr.length;\n }\n }\n return arr.length + 1;\n }\n}\n\nfunction c(x,y)\n{\n const arr = new Array(2);\n\n arr[0] = x - 1;\n\n arr[1] = y\n return arr;\n}\n\nfunction help(a)\n{ \n for(let i = 0; i < a.length; i++)\n {\n if(a[i] > a[i + 1])\n { \n return false;\n }\n }\n return true;\n}\n\nfunction d(n, x, arr)\n{\n let count = 0 ;\n\n if(n === 1 || help(arr))\n {\n return 0;\n }\n\n for(let i = 0 ; i < arr.length; i++)\n {\n const current = arr[i];\n\n if(current > x)\n {\n [arr[i], x] = [x, arr[i]];\n \n count++;\n }\n if(help(arr))\n {\n return count;\n }\n }\n return -1;\n}\n\nmodule.exports = d;"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [len, lastItem] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n if (isSorted(arr) || len === 1) console.log(0);\n else {\n let count = 0;\n for (let i = 0; i < len; i++) {\n const current = arr[i];\n if (current > lastItem) {\n [arr[i], lastItem] = [lastItem, arr[i]];\n count++;\n if (isSorted(arr)) break;\n }\n }\n if (isSorted(arr)) console.log(count);\n else console.log(-1);\n }\n function isSorted(arr) {\n let sorted = true;\n for (let i = 0; i < arr.length - 1; i++) {\n if (arr[i] > arr[i + 1]) {\n sorted = false;\n break;\n }\n }\n return sorted;\n }\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(f){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rr[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;te){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(r[o]>r[o+1]){if(e>r[o+1])return void i.default.puts(-1);let t=r[o+1];r[o+1]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let swaps = 0\n// \n// for (let i = 0; i < n - 1; ++i) {\n// if (a[i] > a[i + 1]) {\n// // try to fix\n// \n// if (a[i + 1] >= x) {\n// for (let j = 0; j < i; ++j) {\n// if (a[j] > x) {\n// let t = a[j]\n// a[j] = x\n// x = t\n// swaps++\n// }\n// }\n// let t = a[i]\n// a[i] = x\n// x = t\n// swaps++\n// } else {\n// io.puts(-1)\n// return\n// }\n// }\n// \n// // io.debug(a)\n// \n// if (a[i] > a[i + 1]) {\n// if (x > a[i + 1]) {\n// io.puts(-1)\n// return\n// }\n// \n// let t = a[i + 1]\n// a[i + 1] = x\n// x = t\n// swaps++\n// }\n// }\n// \n// io.puts(swaps)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, lastItem] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n if (isSorted(arr) || len === 1) console.log(0);\n else {\n arr.push(lastItem);\n let count = 0;\n for (let i = 0; i < len; i++) {\n const [last, current] = [arr[len], arr[i]];\n if (current > last) {\n [arr[len], arr[i]] = [current, last];\n count++;\n if (isSorted(arr)) break;\n }\n }\n if (isSorted(arr)) console.log(count);\n else console.log(-1);\n }\n function isSorted(arr) {\n let sorted = true;\n for (let i = 0; i < arr.length - 1; i++) {\n if (arr[i] > arr[i + 1]) {\n sorted = false;\n break;\n }\n }\n return sorted;\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, lastItem] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n if (isSorted(arr) || len === 1) console.log(0);\n else {\n arr.push(lastItem);\n let count = 0;\n for (let i = 0; i < len; i++) {\n const [last, current] = [arr[len], arr[i]];\n if (current > last) {\n [arr[len], arr[i]] = [current, last];\n count++;\n }\n }\n if (isSorted(arr)) console.log(count);\n else console.log(-1);\n }\n function isSorted(arr) {\n let sorted = true;\n for (let i = 0; i < arr.length - 1; i++) {\n if (arr[i] > arr[i + 1]) {\n sorted = false;\n break;\n }\n }\n return sorted;\n }\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rr[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;te){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let swaps = 0\n// \n// for (let i = 0; i < n - 1; ++i) {\n// if (a[i] > a[i + 1]) {\n// // try to fix\n// \n// if (a[i + 1] >= x) {\n// for (let j = 0; j < i; ++j) {\n// if (a[j] > x) {\n// let t = a[j]\n// a[j] = x\n// x = t\n// swaps++\n// }\n// }\n// let t = a[i]\n// a[i] = x\n// x = t\n// swaps++\n// } else {\n// io.puts(-1)\n// return\n// }\n// }\n// }\n// \n// io.puts(swaps)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(f){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rr[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;te){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(i.default.debug(r),r[o]>r[o+1]){let t=r[o+1];r[o+1]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let swaps = 0\n// \n// for (let i = 0; i < n - 1; ++i) {\n// if (a[i] > a[i + 1]) {\n// // try to fix\n// \n// if (a[i + 1] >= x) {\n// for (let j = 0; j < i; ++j) {\n// if (a[j] > x) {\n// let t = a[j]\n// a[j] = x\n// x = t\n// swaps++\n// }\n// }\n// let t = a[i]\n// a[i] = x\n// x = t\n// swaps++\n// } else {\n// io.puts(-1)\n// return\n// }\n// }\n// \n// io.debug(a)\n// \n// if (a[i] > a[i + 1]) {\n// let t = a[i + 1]\n// a[i + 1] = x\n// x = t\n// swaps++\n// }\n// }\n// \n// io.puts(swaps)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(f){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rr[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;te){let i=r[t];r[t]=e,e=i,n++}let t=r[o];if(r[o]=e,e=t,n++,e>r[o+1])return void i.default.puts(-1)}}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, x] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let swaps = 0\n// \n// for (let i = 0; i < n - 1; ++i) {\n// if (a[i] > a[i + 1]) {\n// // try to fix\n// \n// if (a[i + 1] >= x) {\n// for (let j = 0; j < i; ++j) {\n// if (a[j] > x) {\n// let t = a[j]\n// a[j] = x\n// x = t\n// swaps++\n// }\n// }\n// let t = a[i]\n// a[i] = x\n// x = t\n// swaps++\n// \n// if (x > a[i + 1]) {\n// io.puts(-1)\n// return\n// }\n// } else {\n// io.puts(-1)\n// return\n// }\n// }\n// }\n// \n// io.puts(swaps)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "dc67f1ad9d93ce83cd83f09fa4842ad4"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n // const alpha = \"abcdefghijklmnopqrstuvwxyz\"\n while(t--) {\n const s = input[ptr++]\n let ans = ''\n let l = s.length\n let map = new Array(26)\n for(let i = 0; i < 26; i++) {\n map[i] = [-1,-1]\n }\n let done = {}\n\n let curr = s.charCodeAt(0) - 97\n ans = s[0]\n done[curr] = true\n let f = true\n for(let i = 1; i < l && f; i++) {\n let char = s.charCodeAt(i) - 97\n if(map[curr][0] === char || map[curr][1] === char) {\n curr = char\n }\n else if(map[curr][0] === -1 && !done[char]) {\n map[curr][0] = char\n map[char][1] = curr\n curr = char\n done[char] = true\n ans = s[i] + ans\n }\n else if(map[curr][1] === -1 && !done[char]) {\n map[curr][1] = char\n map[char][0] = curr\n curr = char\n done[char] = true\n ans = ans + s[i]\n }\n else f = false\n }\n if(f) {\n wr('YES')\n for(let i = 0; i < 26; i++) {\n if(!done[i]) ans += String.fromCharCode(i + 97)\n }\n wr(ans)\n }\n else wr('NO')\n // wr(map)\n }\n}", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (s) => {\n if (s.length < 2) return 'YES\\nabcdefghijklmnopqrstuvwxyz';\n if (s.length === 2) return 'YES\\n' + s + 'abcdefghijklmnopqrstuvwxyz'.replace(s[0], '').replace(s[1], '')\n let a = [ s[0], s[1] ];\n let j = 1;\n for (let i = 2; i < s.length; i++) {\n const next = s[i];\n const l = a[j-1];\n const r = a[j+1];\n if (next === l) { j--; continue; }\n if (next === r) { j++; continue; }\n if (a.indexOf(next) !== -1) return 'NO';\n\n if (j === a.length - 1) { j++; a.push(next); continue; }\n if (j === 0) { a.unshift(next); continue; }\n return 'NO'\n }\n let others = 'abcdefghijklmnopqrstuvwxyz';\n for (let i = 0; i < a.length; i++) others = others.replace(a[i], '');\n return 'YES\\n' + a.join('') + others;\n}\nlet t = +readline();\nwhile(t--) print(problem(readline()))\n"}, {"source_code": "const alphabet = 'bacdefghijklmnopqrstuvwxyz'.split('')\n\nconst linkNode = (tree, keyA, keyB) => {\n const elA = tree[keyA]\n const elB = tree[keyB]\n const left = elA.left\n const right = elA.right\n if (left === keyB || right === keyB){\n return\n }\n const freeA = []\n if (!elA.left) {\n freeA.push('left')\n }\n if (!elA.right) {\n freeA.push('right')\n }\n if (freeA.length === 0) {\n throw new Error('overflow')\n }\n let usedProp = null\n\n\n for (const prop of freeA) {\n if (prop === 'left') {\n if (!elB.right) {\n usedProp = ['left', 'right']\n }\n } else {\n if (!elB.left) {\n usedProp = ['right', 'left']\n }\n }\n }\n\n\n if (!usedProp) {\n throw new Error('no link')\n }\n elA[usedProp[0]] = keyB\n elB[usedProp[1]] = keyA\n}\n\n\n\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j 0) {\n const prevLetter = pass[i - 1]\n tree[prevLetter] = tree[prevLetter] || {}\n linkNode(tree, letter, prevLetter)\n }\n if (i < pass.length - 1) {\n const nextLetter = pass[i + 1]\n tree[nextLetter] = tree[nextLetter] || {}\n linkNode(tree, letter, nextLetter)\n }\n }\n let result = ''\n const firstLetter = Object.keys(tree)[0]\n let mark = firstLetter\n let usedMap = {}\n let isOk = true\n // go to left\n while (mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = mark + result\n usedMap[mark] = true\n if (tree[mark].left) {\n mark = tree[mark].left\n } else {\n mark = null\n }\n }\n\n if (tree[firstLetter].right) {\n mark = tree[firstLetter].right\n }\n\n // go to right\n while (isOk && mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = result + mark\n usedMap[mark] = true\n if (tree[mark].right) {\n mark = tree[mark].right\n } else {\n mark = null\n }\n }\n\n if (isOk) {\n console.log('YES')\n for (const a of alphabet) {\n if (!usedMap[a]) {\n result += a\n }\n }\n console.log(result)\n } else {\n console.log('NO')\n }\n } catch(e) {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (s) => {\n if (s.length < 2) return 'YES\\nabcdefghijklmnopqrstuvwxyz';\n if (s.length === 2) return s + 'abcdefghijklmnopqrstuvwxyz'.replace(s[0], '').replace(s[1], '')\n let a = [ s[0], s[1] ];\n let j = 1;\n for (let i = 2; i < s.length; i++) {\n const next = s[i];\n const l = a[j-1];\n const r = a[j+1];\n if (next === l) { j--; continue; }\n if (next === r) { j++; continue; }\n if (a.indexOf(next) !== -1) return 'NO';\n\n if (j === a.length - 1) { j++; a.push(next); continue; }\n if (j === 0) { a.unshift(next); continue; }\n return 'NO'\n }\n let others = 'abcdefghijklmnopqrstuvwxyz';\n for (let i = 0; i < a.length; i++) others = others.replace(a[i], '');\n return 'YES\\n' + a.join('') + others;\n}\nlet t = +readline();\nwhile(t--) print(problem(readline()))\n"}, {"source_code": "'use strict'\n\nconst problem = (s) => {\n if (s.length < 2) return 'YES\\nabcdefghijklmnopqrstuvwxyz';\n if (s.length === 2) return s + 'abcdefghijklmnopqrstuvwxyz'.replace(s[0], '').replace(s[1], '')\n let a = [ s[0], s[1] ];\n let b = new Set(a);\n let j = 1;\n for (let i = 2; i < s.length; i++) {\n const next = s[i];\n const l = a[j-1];\n const r = a[j+1];\n if (next === l) { j--; continue; }\n if (next === r) { j++; continue; }\n if (b.has(next)) return 'NO';\n\n b.add(next);\n if (j === a.length - 1) { j++; a.push(next); continue; }\n if (j === 0) { a.unshift(next); continue; }\n return 'NO'\n }\n let others = 'abcdefghijklmnopqrstuvwxyz';\n for (let i of b) others = others.replace(i, '');\n return 'YES\\n' + a.join('') + others;\n}\nlet t = +readline();\nwhile(t--) print(problem(readline()))\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n // const alpha = \"abcdefghijklmnopqrstuvwxyz\"\n while(t--) {\n const s = input[ptr++]\n let ans = ''\n let l = s.length\n let map = new Array(26)\n for(let i = 0; i < 26; i++) {\n map[i] = [-1,-1]\n }\n let done = {}\n\n let curr = s.charCodeAt(0) - 97\n ans = s[0]\n done[curr] = true\n let f = true\n for(let i = 1; i < l && f; i++) {\n let char = s.charCodeAt(i) - 97\n if(map[curr][0] === char || map[curr][1] === char) {\n curr = char\n }\n else if(map[curr][0] === -1 && !done[char]) {\n map[curr][0] = char\n map[char][1] = curr\n curr = char\n done[char] = true\n ans = s[i] + ans\n }\n else if(map[curr][1] === -1 && !done[char]) {\n map[curr][1] = char\n map[char][0] = curr\n curr = char\n done[char] = true\n ans = ans + s[i]\n }\n else f = false\n }\n if(f) {\n wr('YES')\n for(let i = 0; i < 26; i++) {\n if(!done[i]) ans += String.fromCharCode(i + 97)\n }\n wr(ans)\n }\n else wr('N0')\n // wr(map)\n }\n}"}, {"source_code": "const alphabet = 'bacdefghijklmnopqrstuvwxyz'.split('')\n\nconst linkNode = (tree, keyA, keyB) => {\n const elA = tree[keyA]\n const elB = tree[keyB]\n const left = elA.left\n const right = elA.right\n if (left === keyB || right === keyB){\n return\n }\n const freeA = []\n const freeB = []\n if (!elA.left) {\n freeA.push('left')\n }\n if (!elA.right) {\n freeA.push('right')\n }\n if (freeA.length === 0) {\n throw new Error('overflow')\n }\n let usedProp = null\n for (let prop in freeA) {\n if (prop === 'left') {\n if (!elB.right) {\n usedProp = ['left', 'right']\n }\n } else {\n if (!elB.left) {\n usedProp = ['right', 'left']\n }\n }\n }\n\n if (!usedProp) {\n throw new Error('no link')\n }\n elA[usedProp[0]] = keyB\n elB[usedProp[1]] = keyA\n}\n\n\n\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j 0) {\n const prevLetter = pass[i - 1]\n tree[prevLetter] = tree[prevLetter] || {}\n linkNode(tree, letter, prevLetter)\n }\n if (i < pass.length - 1) {\n const nextLetter = pass[i + 1]\n tree[nextLetter] = tree[nextLetter] || {}\n linkNode(tree, letter, nextLetter)\n }\n }\n let result = ''\n const firstLetter = Object.keys(tree)[0]\n let mark = firstLetter\n let usedMap = {}\n let isOk = true\n // go to left\n while (mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = mark + result\n usedMap[mark] = true\n if (tree[mark].left) {\n mark = tree[mark].left\n } else {\n mark = null\n }\n }\n\n if (tree[firstLetter].right) {\n mark = tree[firstLetter].right\n }\n\n // go to right\n while (isOk && mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = result + mark\n usedMap[mark] = true\n if (tree[mark].right) {\n mark = tree[mark].right\n } else {\n mark = null\n }\n }\n\n if (isOk) {\n console.log('YES')\n for (const a of alphabet) {\n if (!usedMap[a]) {\n result += a\n }\n }\n console.log(result)\n } else {\n console.log('NO')\n }\n } catch(e) {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const alphabet = 'bacdefghijklmnopqrstuvwxyz'.split('')\n\nconst linkNode = (tree, keyA, keyB) => {\n const elA = tree[keyA]\n const elB = tree[keyB]\n const left = elA.left\n const right = elA.right\n if (left === keyB || right === keyB){\n return\n }\n const freeA = []\n const freeB = []\n if (!elA.left) {\n freeA.push('left')\n }\n if (!elA.right) {\n freeA.push('right')\n }\n if (freeA.length === 0) {\n console.log(tree)\n console.log(keyA, keyB)\n throw new Error('overflow')\n }\n let usedProp = null\n for (let prop in freeA) {\n if (prop === 'left') {\n if (!elB.right) {\n usedProp = ['left', 'right']\n }\n } else {\n if (!elB.left) {\n usedProp = ['right', 'left']\n }\n }\n }\n\n if (!usedProp) {\n throw new Error('no link')\n }\n elA[usedProp[0]] = keyB\n elB[usedProp[1]] = keyA\n}\n\n\n\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j 0) {\n const prevLetter = pass[i - 1]\n tree[prevLetter] = tree[prevLetter] || {}\n linkNode(tree, letter, prevLetter)\n }\n if (i < pass.length - 1) {\n const nextLetter = pass[i + 1]\n tree[nextLetter] = tree[nextLetter] || {}\n linkNode(tree, letter, nextLetter)\n }\n }\n let result = ''\n const firstLetter = Object.keys(tree)[0]\n let mark = firstLetter\n let usedMap = {}\n let isOk = true\n // go to left\n while (mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = mark + result\n usedMap[mark] = true\n if (tree[mark].left) {\n mark = tree[mark].left\n } else {\n mark = null\n }\n }\n\n if (tree[firstLetter].right) {\n mark = tree[firstLetter].right\n }\n\n // go to right\n while (isOk && mark) {\n if (usedMap[mark]) {\n isOk = false\n break;\n }\n result = result + mark\n usedMap[mark] = true\n if (tree[mark].right) {\n mark = tree[mark].right\n } else {\n mark = null\n }\n }\n\n if (isOk) {\n console.log('YES')\n for (const a of alphabet) {\n if (!usedMap[a]) {\n result += a\n }\n }\n console.log(result)\n } else {\n console.log('NO')\n }\n } catch(e) {\n console.error(e)\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "8fb62b497b6fb2a5fb4f2669aeb51b73"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++;\r\n };\r\n for (let [x, y, z] of a) {\r\n const i = Number(x) - 1,\r\n j = Number(y) - 1;\r\n if (z === 'imposter') {\r\n add(i, j, 1);\r\n add(j, i, 1);\r\n } else {\r\n add(i, j, 0);\r\n add(j, i, 0);\r\n }\r\n }\r\n const vis = [];\r\n const nums = new Array(n);\r\n const check = i => {\r\n const query = [i];\r\n nums[i] = 0;\r\n for (let i of query) {\r\n vis[i] = 1;\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k];\r\n if (nums[j] !== undefined && nums[j] !== (nums[i] ^ w[k])) return -1;\r\n if (vis[j]) continue;\r\n vis[j] = 1;\r\n nums[j] = nums[i] ^ w[k];\r\n query.push(j);\r\n }\r\n }\r\n let res = 0;\r\n for (let i of query) res += nums[i];\r\n return Math.max(res, query.length - res);\r\n };\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (vis[i]) continue;\r\n const ans = check(i);\r\n if (ans === -1) return -1;\r\n res += ans;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' '));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const says = lines.slice(l, l + m).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += m\n console.log(solve(n, m, says))\n }\n// })()\n})\n\nfunction solve(n, m, says) {\n const vs = Array(n + 1).fill(-1)\n const adj = {}\n says.forEach(([a, b, s]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n const w = s === 'crewmate' // same or not\n adj[a].push([b, w])\n adj[b].push([a, w])\n })\n\n let c0 = 0\n let c1 = 0\n const visited = {}\n for (let i = 1; i <= n; i++) {\n if (!visited[i]) {\n const r = dfs(adj, i, visited, vs)\n if (!r) return -1\n\n const [a, b] = r\n c0 += Math.max(a, b)\n c1 += Math.min(a, b)\n }\n }\n\n return c0 + (n - c0 - c1)\n}\nfunction dfs(adj, r, visited) {\n const stack = [[r, 0, -1, 1]]\n let c0 = 0\n let c1 = 0\n const cache = []\n while (stack.length) {\n const [u, i, p, color] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n cache[u] = color\n if (color === 0) c0++\n if (color === 1) c1++\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const [v, w] = nb[i]\n if (!visited[v]) { // has circle\n stack.push([v, 0, u, w ? color : (1 ^ color)])\n } else {\n if (w && cache[u] !== cache[v]) return null\n if (!w && cache[u] !== (1 ^ cache[v])) return null\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return [c0, c1]\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const says = lines.slice(l, l + m).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += m\n console.log(solve(n, m, says))\n }\n// })()\n})\n\nfunction solve(n, m, says) {\n const vs = Array(n + 1).fill(-1)\n const adj = {}\n const not = says.some(([a, b, s]) => {\n if (vs[a] < 0 && vs[b] < 0) {\n vs[a] = 1\n vs[b] = s === 'crewmate' ? 1 : 0\n } else if (vs[b] < 0) {\n vs[b] = s === 'crewmate' ? vs[a] : (vs[a] ^ 1)\n } else if (vs[a] < 0) {\n vs[a] = s === 'crewmate' ? vs[b] : (vs[b] ^ 1)\n } else {\n if (s === 'crewmate' && vs[a] !== vs[b]) return true\n if (s === 'imposter' && vs[a] === vs[b]) return true\n }\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n if (not) return -1\n\n let c0 = 0\n let c1 = 0\n const visited = {}\n for (let i = 1; i <= n; i++) {\n if (!visited[i]) {\n const [a, b] = dfs(adj, i, visited, vs)\n c0 += Math.max(a, b)\n c1 += Math.min(a, b)\n }\n }\n\n return c0 + (n - c0 - c1)\n}\nfunction dfs(adj, r, visited, vs) {\n const stack = [[r, 0, -1]]\n let c0 = 0\n let c1 = 0\n while (stack.length) {\n const [u, i, p] = stack[stack.length - 1]\n visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n if (vs[u] === 0) c0++\n if (vs[u] === 1) c1++\n }\n if (i < nb.length) {\n stack[stack.length - 1][1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p && !visited[v]) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n }\n }\n return [c0, c1]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const says = lines.slice(l, l + m).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += m\n console.log(solve(n, m, says))\n }\n// })()\n})\n\nfunction solve(n, m, says) {\n const vs = Array(n + 1).fill(-1)\n // const adj = {}\n const not = says.some(([a, b, s]) => {\n if (vs[a] < 0 && vs[b] < 0) {\n vs[a] = 1\n vs[b] = s === 'crewmate' ? 1 : 0\n } else if (vs[b] < 0) {\n vs[b] = s === 'crewmate' ? vs[a] : (vs[a] ^ 1)\n } else if (vs[a] < 0) {\n vs[a] = s === 'crewmate' ? vs[b] : (vs[b] ^ 1)\n } else {\n if (s === 'crewmate' && vs[a] !== vs[b]) return true\n if (s === 'imposter' && vs[a] === vs[b]) return true\n }\n // adj[a] = adj[a] || []\n // adj[b] = adj[b] || []\n // adj[a].push(b)\n // adj[b].push(a)\n })\n if (not) return -1\n\n let c0 = 0\n let c1 = 0\n for (let i = 1; i <= n; i++) {\n if (vs[i] === 0) c0++\n if (vs[i] === 1) c1++\n }\n return Math.max(c0, c1) + (n - c0 - c1)\n}\n"}], "src_uid": "a18692e5fe2f98717608449b1d9b77f7"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = parseInt(readline());\n const roads = new Map();\n let neighbours = (new Array(n+1)).fill(new Array());\n let start = 0,\n curr = 0,\n next = 0,\n d1 = 0,\n d2 = 0;\n for (let i=0; i parseInt(x));\n roads.set(a+\"-\"+b, c);\n neighbours[a] = neighbours[a].concat(b);\n neighbours[b] = neighbours[b].concat(a);\n if (start == 0) {\n start = a;\n curr = a;\n next = b;\n }\n }\n\n do {\n if (roads.has(curr+\"-\"+next)) {\n d1 += roads.get(curr+\"-\"+next);\n } else {\n d2 += roads.get(next+\"-\"+curr);\n }\n if (neighbours[next][0] == curr) {\n curr = next;\n next = neighbours[next][1];\n } else {\n curr = next;\n next = neighbours[next][0];\n }\n } while(curr != start);\n\n console.log(Math.min(d1,d2));\n}\n", "positive_code": [{"source_code": "'use strict'\n\nlet lll\n\nconst N = +readline()\n\nconst rs = []\n\nwhile (lll = readline()) {\n const rr = lll.split(' ').map(v => parseInt(v))\n if (!rs[rr[0]]) rs[rr[0]] = {rr: []}\n rs[rr[0]][rr[1]] = rr[2]\n rs[rr[0]].rr.push(rr[1])\n if (!rs[rr[1]]) rs[rr[1]] = {rr: []}\n rs[rr[1]][rr[0]] = 0\n rs[rr[1]].rr.push(rr[0])\n}\n\nconst next = (f, t) => {\n const ws = rs[t].rr\n const n = ws[0] == f ? ws[1] : ws[0]\n const p = rs[t][n]\n return [n, p]\n}\n\nlet r1 = 1\nlet r2 = rs[1].rr[0]\nlet p1 = rs[1][r2]\n\nwhile (r2 != 1) {\n const w = next(r1, r2)\n const rn = w[0]\n r1 = r2\n r2 = rn\n p1 += w[1]\n}\n\nr1 = 1\nr2 = rs[1].rr[1]\nlet p2 = rs[1][r2]\n\nwhile (r2 != 1) {\n const w = next(r1, r2)\n const rn = w[0]\n r1 = r2\n r2 = rn\n p2 += w[1]\n}\n\nprint(Math.min(p1, p2))"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar matrix = [], indicator = 0, N;\n/**\n * while(true){\n * string input = Console.ReadLine();\n * }\n */\n/**\n * \n *\n 6\n1 5 4 \n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n\n */\nvar findNextPath = function (matrix, N, path, index) {\n for (let i = 0; i < N; i++) {\n if (matrix[index][i] != 0 && !path.includes(i) ||\n matrix[i][index] != 0 && !path.includes(i))\n return i;\n }\n return -1;\n}\n\nrl.on('line', (input) => {\n\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n matrix = new Array(N).fill(0).map(() => new Array(N).fill(0));\n //console.log(matrix);\n }\n else {\n let temp = input.split(' ').map(item => parseInt(item));\n let a = temp[0], b = temp[1], price = temp[2];\n //console.log(\"a=%d b=%d price=%d\",a,b,price);\n matrix[a - 1][b - 1] = price;\n\n }\n\n\n}).on('close', () => {\n /**\n * \n * path{0,4,2,1,3,5}\n */\n //console.log(matrix);\n let path = [0];\n let nIndex = findNextPath(matrix, N, path, 0);\n\n while (nIndex != -1) {\n path.push(nIndex);\n nIndex = findNextPath(matrix, N, path, nIndex);\n }\n let CW = matrix[path[N - 1]][0];\n let ACW = matrix[0][path[N - 1]];\n\n for (let i = 0, j = N - 1; i < N - 1; i++, j--) {\n CW += matrix[path[i]][path[i + 1]];\n ACW += matrix[path[j]][path[j - 1]];\n }\n console.log((ACW > CW) ? CW : ACW);\n});"}], "negative_code": [], "src_uid": "d85c7a8f7e6f5fc6dffed554bffef3ec"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n if (word.length === 0){\n return true;\n }\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false, ck = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if (x.length === 0)ck = true;\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0 && ck === false){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n if (word.length === 0){\n return true;\n }\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false, ck = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if (x.length === 0)ck = true;\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0 && ck === false){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "var words = readline().split(/,|;/);\nvar s1 = [], s2 = [];\nfor(var x of words) {\n\tif(x === '0' || /^[1-9]\\d*$/.test(x)) s1.push(x);\n\telse s2.push(x);\n}\n\nif(s1.length == 0) print(\"-\");\nelse print('\"' + s1.join(\",\") + '\"');\n\nif(s2.length == 0) print(\"-\");\nelse print('\"' + s2.join(\",\") + '\"');\n"}, {"source_code": "var a = ['',''];\nvar b = [false,false];\nvar numbers = readline().split(/[;,]/).forEach(function(x) {\n var u = x.match(\"^(0|([1-9][0-9]*))$\")?0:1;\n if(!b[u]){b[u]=true;}else{a[u]+=','}\n a[u] += x;\n});\n[0,1].forEach(function(x) {\n print(b[x]?('\"'+a[x]+'\"'):'-');\n});"}, {"source_code": "const zeroCharCode = '0'.charCodeAt(0);\n\nconst numberMap = new Map([\n [ zeroCharCode, 0 ],\n [ '1'.charCodeAt(0), 1 ],\n [ '2'.charCodeAt(0), 2 ],\n [ '3'.charCodeAt(0), 3 ],\n [ '4'.charCodeAt(0), 4 ],\n [ '5'.charCodeAt(0), 5 ],\n [ '6'.charCodeAt(0), 6 ],\n [ '7'.charCodeAt(0), 7 ],\n [ '8'.charCodeAt(0), 8 ],\n [ '9'.charCodeAt(0), 9 ]\n]);\nconst isNumber = (str, at) => numberMap.has(str.charCodeAt(at));\nconst isNumeric = (str) => {\n if(str.length < 1) {\n return false;\n }\n\n if(str.length === 1) {\n return isNumber(str, 0);\n }\n\n if (str.charCodeAt(0) === zeroCharCode) {\n return false;\n }\n\n for (let i = str.length - 1; i >= 0; i--) {\n if(!isNumber(str, i)) {\n return false;\n }\n }\n return true;\n}\n\nconst processInput = input => {\n const wordList = input.split(/[;,]/);\n /*\n input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n */\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumeric(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "\nvar inputWords = [];\nvar separ = [',', ';'];\nvar inputRaw = readline();\ninputWords = inputRaw.split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\\\"\";\nvar nonNumbers = \"\\\"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nif (numbers.length === 1)\n{\n numbers = \"-\";\n}\nelse\n{\n numbers = numbers.substr(0, numbers.length - 1);\n numbers += '\\\"';\n}\n\nif (nonNumbers.length === 1)\n{\n nonNumbers = \"-\";\n}\nelse\n{\n nonNumbers = nonNumbers.substr(0, nonNumbers.length - 1);\n nonNumbers += '\\\"';\n}\n\nprint (numbers);\nprint (nonNumbers);\n"}, {"source_code": "readline().split(/,|;/).reduce((ab, word) => {\n if (!word || word.match(/^[0]+[0-9]+$/) || !word.match(/^\\d+$/)) {\n ab[1].push(word);\n } else {\n ab[0].push(word);\n }\n return ab;\n}, [[],[]])\n.map(result => result.length > 0 ? \"\\\"\" + result.join(',') + \"\\\"\" : \"-\")\n.forEach(result => print(result));"}, {"source_code": "var inp = readline().split(/[,;]/g), n = inp.length;\n\nvar a = \"\", b = \"\";\n\nfor(var i = 0; i < n; i++){\n var str = inp[i];\n \n if(str === \"\") {b += str + \",\";continue;}\n if(!/^\\d+$/.test(str) && str != \"0\") { b += str + \",\"; continue; }\n if(/^0+/.test(str) && str != \"0\") { b += str + \",\"; continue; }\n a += str + \",\";\n}\n\nif(a.length !== 0)\n print(\"\\\"\" + a.substring(0, a.length - 1) + \"\\\"\");\nelse print(\"-\");\nif(b.length !== 0)\n print(\"\\\"\" + b.substring(0, b.length - 1) + \"\\\"\");\nelse print(\"-\");"}], "negative_code": [{"source_code": "var words = readline().split(/,|;/);\nvar s1 = [], s2 = [];\nfor(var x of words) {\n\tvar n = ~~Number(x);\n\tif(String(n) === x && n >= 0) s1.push(x);\n\telse s2.push(x);\n}\n\nif(s1.length == 0) print(\"-\");\nelse print('\"' + s1.join(\",\") + '\"');\n\nif(s2.length == 0) print(\"-\");\nelse print('\"' + s2.join(\",\") + '\"');\n"}, {"source_code": "var words = readline().split(/,|;/);\nvar s1 = [], s2 = [];\nfor(var x of words) {\n\tvar n = ~~+(x);\n\tif(String(n) === x && n >= 0) s1.push(x);\n\telse s2.push(x);\n}\n\nif(s1.length == 0) print(\"-\");\nelse print('\"' + s1.join(\",\") + '\"');\n\nif(s2.length == 0) print(\"-\");\nelse print('\"' + s2.join(\",\") + '\"');\n"}, {"source_code": "var a = ['',''];\nvar b = [false,false];\nvar numbers = readline().split(/[;,]/).forEach(function(x) {\n var u = x.match(\"0|([1-9][0-9]*)\")?0:1;\n print(\"x=\"+x+\" m=\"+u);\n if(!b[u]){b[u]=true;}else{a[u]+=','}\n a[u] += x;\n});\n[0,1].forEach(function(x) {\n print(b[x]?('\"'+a[x]+'\"'):'-');\n});"}, {"source_code": "var a = '';\nvar b = '';\nvar numbers = readline().split(\"[,;]\").forEach(function(x) {\nif(x.match(\"0|([1-9][0-9]*)\")) {\n if(a.length > 0) {\n a += ',';\n }\n a += x;\n} else {\n if(b.length > 0) {\n b += ',';\n }\n b += x;\n}\n});\nprint('\"'+a+'\"');\nprint('\"'+b+'\"');"}, {"source_code": "var a = ['',''];\nvar b = [false,false];\nvar numbers = readline().split(/[;,]/).forEach(function(x) {\n var u = x.match(\"0|([1-9][0-9]*)\")?0:1;\n if(!b[u]){b[u]=true;}else{a[u]+=','}\n a[u] += x;\n});\n[0,1].forEach(function(x) {\n print(b[x]?('\"'+a[x]+'\"'):'-');\n});"}, {"source_code": "\nvar inputWords = [];\nvar separ = [',', ';'];\nvar inputRaw = readline();\ninputWords = inputRaw.split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\\\"\";\nvar nonNumbers = \"\\\"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nif (numbers.length === 1)\n{\n numbers += \"-\\\"\";\n}\nelse\n{\n numbers = numbers.substr(0, numbers.length - 1);\n numbers += '\\\"';\n}\n\nif (nonNumbers.length === 1)\n{\n nonNumbers += \"-\\\"\";\n}\nelse\n{\n nonNumbers = nonNumbers.substr(0, nonNumbers.length - 1);\n nonNumbers += '\\\"';\n}\n\nprint (numbers + \"\\n\");\nprint (nonNumbers);\n"}, {"source_code": "\nvar inputWords = [];\nvar separ = [',', ';'];\nvar inputRaw = readline();\ninputWords = inputRaw.split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\\\"\";\nvar nonNumbers = \"\\\"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nif (numbers.length === 1)\n{\n numbers += \"-\\\"\";\n}\nelse\n{\n numbers = numbers.substr(0, numbers.length - 1);\n numbers += '\\\"';\n}\n\nif (nonNumbers.length === 1)\n{\n nonNumbers += \"-\\\"\";\n}\nelse\n{\n nonNumbers = nonNumbers.substr(0, nonNumbers.length - 1);\n nonNumbers += '\\\"';\n}\n\nprint (numbers);\nprint (nonNumbers);\n"}, {"source_code": "var inputWords = readline().split(\",;\");\n\nvar numbers;\nvar nonNumbers;\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var num = parseInt(inputWords[i]);\n if (typeof num === 'number')\n {\n var remainder = (num % 1);\n if (remainder === 0)\n {\n numbers += num + \",\";\n }\n else\n {\n nonNumbers += num + \"'\";\n }\n }\n}\n\nprint (numbers);\nprint (nonNumbers);"}, {"source_code": "print(\"flavius\");\n\nvar inputWords = [];\nvar separ = [',', ';'];\nvar inputRaw = readline();\ninputWords = inputRaw.split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\";\nvar nonNumbers = \"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nif (numbers.length === 0)\n numbers += \"-\";\n\nif (nonNumbers.length === 0)\n nonNumbers += \"-\";\n\nprint (numbers + \"\\n\");\nprint (nonNumbers);\n"}, {"source_code": "var inputWords = [];\nvar separ = [',', ';'];\nvar inputRaw = readline();\ninputWords = inputRaw.split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\";\nvar nonNumbers = \"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nif (numbers.length == 0)\n numbers += \"-\";\n\nif (nonNumbers.length == 0)\n nonNumbers += \"-\";\n\nprint (numbers + \"\\n\");\nprint (nonNumbers);\n"}, {"source_code": "var inputWords = [];\nvar separ = [',', ';'];\ninputWords = readline().split(new RegExp(separ.join('|'), 'g'));\n\nvar numbers = \"\";\nvar nonNumbers = \"\";\n\nfor (i = 0; i < inputWords.length; i++)\n{\n var reg = new RegExp('^[0-9]+$');\n if (reg.test(inputWords[i]))\n {\n if (inputWords[i].length > 1 && inputWords[i].charAt(0) == '0')\n {\n nonNumbers += inputWords[i] + \",\";\n }\n else\n {\n numbers += inputWords[i] + \",\";\n }\n }\n else\n {\n nonNumbers += inputWords[i] + \",\";\n }\n}\n\nprint (numbers + \"\\n\");\nprint (nonNumbers);\n"}, {"source_code": "readline().split(/,|;/).reduce((ab, word) => {\n if (!word || word.match(/[0]+[0-9]+/) || !word.match(/^\\d+$/)) {\n ab[1].push(word);\n } else {\n ab[0].push(word);\n }\n return ab;\n}, [[],[]])\n.map(result => result.length > 0 ? \"\\\"\" + result.join(',') + \"\\\"\" : \"-\")\n.forEach(result => print(result));"}, {"source_code": "var inp = readline().split(/[,;]/g), n = inp.length;\n\nvar a = \"\", b = \"\";\n\nfor(var i = 0; i < n; i++){\n var str = inp[i];\n \n if(str === \"\" || isNaN(+str)) {b += str + \",\";continue;}\n if(/^0+/.test(str) && str != \"0\") {b += str + \",\";continue;}\n if(!/^\\d+$/.test(str)) { b += str + \",\"; continue; }\n str = +str;\n a += str + \",\";\n}\n\nif(a.length === 0)\n print(\"\\\"\" + a.substring(0, a.length - 1) + \"\\\"\");\nelse print(\"-\");\nif(b.length === 0)\n print(\"\\\"\" + b.substring(0, b.length - 1) + \"\\\"\");\nelse print(\"-\");"}, {"source_code": "var inp = readline().split(/[,;]/g), n = inp.length;\n\nvar a = \"\", b = \"\";\n\nfor(var i = 0; i < n; i++){\n var str = inp[i];\n \n if(str.length == \"\" || isNaN(+str)) {b += str + \",\";continue;}\n if(/^0+/.test(str) && str != \"0\") {b += str + \",\";continue;}\n if(!/^\\d+$/.test(str)) { b += str + \",\"; continue; }\n str = +str;\n a += str + \",\";\n}\n\nprint(\"\\\"\" + a.substring(0, a.length - 1) + \"\\\"\");\nprint(\"\\\"\" + b.substring(0, b.length - 1) + \"\\\"\");\n"}, {"source_code": "var inp = readline().split(/[,;]/g), n = inp.length;\n\nvar a = \"\", b = \"\";\n\nfor(var i = 0; i < n; i++){\n var str = inp[i];\n \n if(str === \"\" || isNaN(+str)) {b += str + \",\";continue;}\n if(/^0+/.test(str) && str != \"0\") {b += str + \",\";continue;}\n if(!/^\\d+$/.test(str)) { b += str + \",\"; continue; }\n str = +str;\n a += str + \",\";\n}\n\nif(a.length !== 0)\n print(\"\\\"\" + a.substring(0, a.length - 1) + \"\\\"\");\nelse print(\"-\");\nif(b.length !== 0)\n print(\"\\\"\" + b.substring(0, b.length - 1) + \"\\\"\");\nelse print(\"-\");"}, {"source_code": "var inp = readline().split(/,;/g), n = inp.length;\n\nvar a = \"\", b = \"\";\n\nfor(var i = 0; i < n; i++){\n var str = inp[i];\n \n if(str.length == \"\" || isNaN(+str)) {b += str + \",\";continue;}\n if(/^0+/.test(str) && str != \"0\") {b += str + \",\";continue;}\n if(!/^\\d+$/.test(str)) { b += str + \",\"; continue; }\n str = +str;\n a += str + \",\";\n}\n\nprint(\"\\\"\" + a.substring(0, a.length - 1) + \"\\\"\");\nprint(\"\\\"\" + b.substring(0, b.length - 1) + \"\\\"\");\n"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n if (word.length < 1) {\n emptyCount++;\n }\n });\n\n process.stdout.write(`\"${a.length < 1 ? '-' : a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(`\"${b.length < 1 || b.length === emptyCount ? '-' : b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join(''));\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val, 10);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n if (word.length < 1) {\n emptyCount++;\n }\n });\n\n process.stdout.write(`\"${a.length < 1 ? '-' : a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(`\"${b.length < 1 || b.length === emptyCount ? '-' : b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join(''));\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = str => /^[1-9][0-9]+$/.test(str);\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = str => /^[0-9]+$/.test(str);\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val, 10);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n if (word.length < 1) {\n emptyCount++;\n }\n });\n\n process.stdout.write(a.length < 1 ? '-' : a.join(','));\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 || b.length === emptyCount ? '-' : b.join(','));\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join(''));\n process.exit(0);\n });\n})();"}, {"source_code": "const zeroCharCode = '0'.charCodeAt(0);\nconst numberMap = new Map([\n [ zeroCharCode, 0 ],\n [ '1'.charCodeAt(0), 1 ],\n [ '2'.charCodeAt(0), 2 ],\n [ '3'.charCodeAt(0), 3 ],\n [ '4'.charCodeAt(0), 4 ],\n [ '5'.charCodeAt(0), 5 ],\n [ '6'.charCodeAt(0), 6 ],\n [ '7'.charCodeAt(0), 7 ],\n [ '8'.charCodeAt(0), 8 ],\n [ '9'.charCodeAt(0), 9 ]\n]);\nconst isNumber = (str, at) => numberMap.has(str.charCodeAt(at));\nconst isNumeric = (str) => {\n if(str.length < 1) {\n return false;\n }\n\n if(str.length === 1) {\n return isNumber(str, 0);\n }\n\n if (str.charCodeAt(0) !== zeroCharCode) {\n return false;\n }\n\n for (const i = str.length - 1; i >= 0; i--) {\n if(!isNumber(str, i)) {\n return false;\n }\n }\n return true;\n}\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumeric(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val, 10);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n if (word.length < 1) {\n emptyCount++;\n }\n });\n\n process.stdout.write(`\"${a.length < 1 ? '-' : a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(`\"${b.length < 1 || b.length === emptyCount ? '-' : b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const isNumber = (val) => {\n const num = parseInt(val, 10);\n return `${num}` === val;\n};\n\nconst processInput = input => {\n const wordList = input\n .split(',')\n .reduce(\n (list, item) => [...list, ...item.split(';')],\n []\n );\n \n let a = [];\n let b = [];\n let emptyCount = 0;\n wordList.forEach(word => {\n if(isNumber(word)) {\n a.push(word);\n return;\n }\n\n b.push(word);\n if (word.length < 1) {\n emptyCount++;\n }\n });\n\n process.stdout.write(a.length < 1 ? '-' : `\"${a.join(',')}\"`);\n process.stdout.write('\\n');\n process.stdout.write(b.length < 1 || b.length === emptyCount ? '-' : `\"${b.join(',')}\"`);\n};\n\n\n(() => {\n process.stdin.setEncoding('utf8');\n const chunkList = [];\n process.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n chunkList.push(chunk);\n }\n });\n process.stdin.on('end', () => {\n processInput(chunkList.join('').trim());\n process.exit(0);\n });\n})();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let sum = 0;\n for (let i = 0; i <= Math.floor(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9' || word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n sum = sum + 1;\n }\n }\n if (sum === Math.floor(word.length / 2)){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n if (word.length === 0){\n return true;\n }\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n for (let i = 0; i <= Math.floor(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9' || word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n return false;\n }\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n if (word.length === 0){\n return true;\n }\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false, ck = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if (x.length === 0)ck = true;\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0 && ck === false){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n console.log(res);\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n if (word.length === 0){\n return true;\n }\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n console.log(res);\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n for (let i = 0; i < Math.floor(word.length / 2); i++){\n if (word[i] >= 'a' && word[i] <= 'z' || word[word.length - i - 1] >= 'a' && word[word.length - i - 1] <= 'z'){\n return true;\n }\n return false;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let ch = 0, digit = 0;\n for (let i = 0; i < Math.ceil(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n if (word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n digit = digit + 1;\n } else {\n ch = ch + 1;\n }\n }\n if (ch === 0){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n for (let i = 0; i <= Math.floor(word.length / 2); i++){\n if (word[i] >= 'a' && word[i] <= 'z' || word[word.length - i - 1] >= 'a' && word[word.length - i - 1] <= 'z'){\n return true;\n }\n return false;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n for (let i = 0; i < Math.floor(word.length / 2); i++){\n if (word[i] >= 'a' && word[i] <= 'z' || word[word.length - i - 1] >= 'a' && word[word.length - i - 1] <= 'z'){\n return true;\n }\n return false;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(a);\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(b);\n }\n rl.close();\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction findWord(word){\n let sum = 0;\n for (let i = 0; i <= Math.floor(word.length / 2); i++){\n if (word[i] >= '0' && word[i] <= '9' || word[word.length - i - 1] >= '0' && word[word.length - i - 1] <= '9'){\n sum++;\n }\n }\n if (sum === Math.floor(word.length / 2)){\n return false;\n } else {\n return true;\n }\n}\n\nrl.on('line', (input) => {\n s = \"\", a = \"\", b = \"\", flag1 = false, flag2 = false;\n res = input.split(/[,;]/);\n res.map(x => {\n if ((x.charAt(0) === '0' && x.length > 1) || findWord(x) || x.length === 0){\n if (flag1 === false)b += x;\n else b += \",\" + x;\n flag1 = true;\n }\n else {\n if (flag2 === false)a += x;\n else a += \",\" + x;\n flag2 = true;\n }\n });\n if (a.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + a + \"\\\"\");\n }\n if (b.length === 0){\n console.log(\"-\");\n } else {\n console.log(\"\\\"\" + b + \"\\\"\");\n }\n rl.close();\n})"}], "src_uid": "ad02cead427d0765eb642203d13d3b99"} {"source_code": "//var input = readline();\nvar T = parseInt(readline());\n \nfor (var i = 0; i < T; i++) {\n var n = parseInt(readline());\n if (n == 1) print(-1);\n else {\n write(2);\n n--;\n while (n-- > 0) {\n write(3);\n } print('\\n');\n }\n}", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n if(n === 1) wr(-1)\n else {\n let a = new Array(n).fill(9)\n a[n-1] = 8\n wr(a.join(''))\n }\n }\n}"}, {"source_code": "const mainFunction = (lines) => {\n let n = +lines[0];\n for(let i = 1; i < n + 1; i++) {\n let qwe = +lines[i];\n if(qwe != 1){ qwe--;\n let ans = \"2\";\n while(qwe--) ans += '3';\n console.log(ans);\n }\n else console.log(-1);\n }\n}\n\nconst {EOL} = require('os')\nconst fs = require(\"fs\");\nif(__filename.substr(9,4) != \"azer\"){ \n let yourInput = ''\n process.stdin.on('data', i => yourInput += i)\n process.stdin.on('end', () => mainFunction(yourInput.split(EOL)))\n} else {\n mainFunction(fs.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "let yourInputData = ''\nprocess.stdin.on('data', i => yourInputData += i)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = yourInputData.split(EOL)\n mainFunction(lines)\n})\n\nconst mainFunction = (lines) => {\n let n = +lines[0];\n for(let i = 1; i < n + 1; i++) {\n let qwe = +lines[i];\n if(qwe != 1){ qwe--;\n let ans = \"2\";\n while(qwe--) ans += '3';\n console.log(ans);\n }\n else console.log(-1);\n }\n}"}, {"source_code": "var t = readline().split('\\n');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split('\\n');\n if(n == 1){\n print(\"-1\");\n }\n else{\n var string = [];\n for(var j = 1; j <= n - 2 ; ++j)\n string += '9';\n \n string += '29';\n print(string);\n }\n}"}, {"source_code": "const mainFunction = (lines) => {\n let n = +lines[0];\n for(let i = 1; i < n + 1; i++) {\n let qwe = +lines[i];\n if(qwe != 1){ qwe--;\n let ans = \"2\";\n while(qwe--) ans += '3';\n console.log(ans);\n }\n else console.log(-1);\n }\n}\n\nconst {EOL} = require('os')\nconst fs = require(\"fs\");\nif(__filename.substr(9,4) != \"azer\"){ \n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => {\n const lines = yourInputData.split(EOL)\n mainFunction(lines)\n })\n} else {\n mainFunction(fs.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n let tests = parseInt(readline());\n while(tests--){\n let num = parseInt(readline());\n if(num == 1) console.log(\"-1\");\n else{\n let ans = \"3\".repeat(num - 1);\n console.log(\"2\"+ans);\n }\n }\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\n\t\tif (n <= 1) {\n\t\t\tconsole.log(-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconsole.log(`2${'3'.repeat(n - 1)}`);\n\t}\n}\n"}], "negative_code": [{"source_code": "//var input = readline();\nvar T = parseInt(readline());\n\nfor (var i = 0; i < T; i++) {\n var n = parseInt(readline());\n if (n == 1) print(-1);\n else {\n write(3);\n n--;\n while (n-- > 0) {\n write(1);\n }\n }\n}\n"}, {"source_code": "var t = readline().split('\\n');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split('\\n');\n if(n == 1){\n print(\"-1\");\n }\n var string = [];\n for(var j = 1; j <= n - 2 ; ++j)\n string += '9';\n \n string += '29';\n print(string);\n}"}, {"source_code": "var t = readline().split(' ');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split(' ');\n print(n);\n}"}, {"source_code": "var t = readline().split(' ');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split(' ');\n if(n == 1){\n print(\"-1\");\n }\n var string = \"\";\n for(var j = 1; j <= n - 2 ; ++j)\n string += \"9\";\n \n string = string + \"2\" + \"9\";\n print(string);\n}"}, {"source_code": "var t = readline().split('\\n');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split('\\n');\n if(n == 1){\n print(\"-1\");\n }\n var string = \"\";\n for(var j = 1; j <= n - 2 ; ++j)\n string += '9';\n \n string += '29';\n print(string);\n}"}, {"source_code": "var t = readline().split(' ');\n\nfor(var i = 1; i <= t ; ++i){\n var n = readline().split(' ');\n if(n == 1){\n print(\"-1\\n\");\n }\n for(var j = 1; j <= n - 2 ; ++j){\n print(\"9\");\n }\n print(\"29\\n\");\n}\n\n"}, {"source_code": "var t = readline().split(' ');\n \nfor(var i = 1; i <= t ; ++i){\n var n = readline().split(' ');\n if(n == 1){\n print(\"-1\");\n }\n var string = [];\n for(var j = 1; j <= n - 2 ; ++j)\n string += '9';\n \n string += '29';\n print(string);\n}\n "}], "src_uid": "43996d7e052aa628a46d03086f9c5436"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n b = b.split(\" \");\r\n let n = parseInt(b[0]);\r\n let arr = [];\r\n while (n--) {\r\n var c = readLine();\r\n arr.push(c.replace(\"\\r\", \"\"));\r\n }\r\n var res = solveMeFirst(arr);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(arr) {\r\n // console.log(arr);\r\n let col = false;\r\n for (let i = 0; i < arr.length; i++) {\r\n for (let j = 0; j < arr[i].length; j++) {\r\n if (arr[i][j] === \"R\" && col === false) {\r\n col = j;\r\n } else if (arr[i][j] === \"R\" && col !== false) {\r\n if (col > j) return \"NO\";\r\n }\r\n }\r\n }\r\n return \"YES\";\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nclass Robot {\r\n constructor(row, col) {\r\n this.row = row;\r\n this.col = col;\r\n }\r\n\r\n willExplode(first) {\r\n return this.row < first.row || this.col < first.col;\r\n }\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let first;\r\n let willExplode = false;\r\n\r\n for (let i = 0; i < n; i++) {\r\n let row = readline().split('');\r\n\r\n for (let j = 0; j < row.length; j++) {\r\n if (row[j] === 'R') {\r\n if (!first) {\r\n first = new Robot(i, j);\r\n } else {\r\n let curr = new Robot(i, j);\r\n if (curr.willExplode(first)) {\r\n willExplode = true;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n output(willExplode ? 'NO' : 'YES');\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, m, grid) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n let r = n\n let c = m\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === 'R') {\n r = Math.min(r, i)\n c = Math.min(c, j)\n }\n }\n }\n return r < n && c < m && grid[r][c] === 'R'\n}\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet [inputString, currentLine] = ['', 0];\r\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\nconst input = () => inputString[currentLine++];\r\n\r\nconst main = () => {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const [n, m] = input().split(' ').map(Number);\r\n const f = [];\r\n for(let i = 0; i < n; i++){\r\n const s = input().split('');\r\n f.push(s);\r\n }\r\n let my = n-1;\r\n let mx = m-1;\r\n for(let y = 0; y < n; y++){\r\n for(let x = 0; x < m; x++){\r\n if(f[y][x] === 'R'){\r\n my = Math.min(my, y);\r\n mx = Math.min(mx, x);\r\n }\r\n }\r\n }\r\n if(f[my][mx] === 'R') console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, s) {\r\n let robot = null;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (s[i][j] === 'R') {\r\n if (!robot) {\r\n robot = [i, j];\r\n } else {\r\n if (i < robot[0] || j < robot[1]) {\r\n return 'NO';\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let grid = [];\n for (let i = 0; i < n; i++) {\n grid.push(readline().split(''));\n }\n // console.log('DEBUG grid', grid);\n\n let x, y;\n for (let i = 0; i < n; i++) {\n if (x !== undefined) break;\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === 'R') {\n x = i;\n y = j;\n break;\n }\n }\n }\n // console.log('DEBUG x', x);\n // console.log('DEBUG y', y);\n\n for (let i = x; i < n; i++) {\n for (let j = 0; j < y; j++) {\n if (grid[i][j] === 'R') {\n return 'NO';\n }\n }\n }\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, m] = ra();\n let A = [];\n for (let i=0; i j) return \"NO\";\r\n }\r\n }\r\n }\r\n return \"YES\";\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}], "src_uid": "96b6a96ded46bddb78b118d6d3a9d049"} {"source_code": "var amountOfSets = readline();\nvar results = [];\nfor (var i = 0; i {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const a = readInts()\n let sum = a.reduce((a, b) => a + b, 0)\n if(sum % 2 === 1) {\n wr('YES')\n }\n else {\n let e = false\n let o = false\n a.forEach(el => {\n if(el % 2 === 0) e = true\n else o = true\n })\n if(!o || !e) {\n wr('NO')\n }\n else wr('YES')\n }\n }\n}\n"}, {"source_code": "function main() {\n n = readInt()\n li = readInts()\n odd = li.filter(x => x%2!=0).length\n even = li.filter(x => x%2==0).length\n //print(n, li)\n if ((n%2==1 || even>0) && odd>0){\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}\n\nconst TESTCASES = true\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n\n"}, {"source_code": "\n//DISABLE THIS LINE END ENABLE NEXT\n//const rl = require('readline').createInterface({input: require('fs').createReadStream('input.txt')});\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst write = (...args) => {\n process.stdout.write(args.join(' ') );\n}\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\n\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nfunction main() {\n //var y = +readline() + 1;\n var y = +readline()\n while(y > 0) {\n\t\tvar z = readline();\n\t\tvar arr = readline();\n\t\tvar a = arr.split(' ');\n\t\tvar a_even = (a.length % 2 === 0)?1:0;\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tvar res = 'NO';\n\t\tfor(var i = 0 ; i < a.length; i++) {\n\t\t\tif (odd === 1 && a_even == 0) {\n\t\t\t\tres = 'YES';\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (odd == 1 && even == 1) {\n\t\t\t\tres = 'YES';\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (a[i] % 2 == 0) {\n\t\t\t\teven = 1;\n\t\t\t} else {\n\t\t\t\todd = 1;\n\t\t\t}\n\t\t}\n\t\tif (odd === 1 && a_even == 0) {\n\t\t\tres = 'YES';\n\t\t}\n\t\tif (odd == 1 && even == 1) {\n\t\t\tres = 'YES';\n\t\t}\n\t\twrite(res +'\\n');\n\t\t//write(\"\\n\");\n\t\ty--;\n }\n //const check = (x) => (x + '').length === new Set(x + '').size\n\t//while (!check(y)) y++\n //write(y);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 'NO';\n let sum = 0;\n\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i];\n\n for (let j = 0; j < arr.length; j++) {\n if ((arr[i] + arr[j]) % 2 !== 0) {\n ans = 'YES';\n break;\n }\n }\n }\n\n if (sum % 2 !== 0) {\n ans = 'YES';\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let sum = 0;\n\n let isOdd = false;\n let isEven = false;\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i];\n\n if (arr[i] % 2 === 0) {\n isEven = true;\n }\n else {\n isOdd = true;\n }\n }\n\n if (sum % 2 !== 0 || (isEven && isOdd)) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n // let ans = 'NO';\n // let sum = 0;\n\n // for (let i = 0; i < arr.length; i++) {\n // sum += arr[i];\n\n // for (let j = 0; j < arr.length; j++) {\n // if ((arr[i] + arr[j]) % 2 !== 0) {\n // ans = 'YES';\n // break;\n // }\n // }\n // }\n\n // if (sum % 2 !== 0) {\n // ans = 'YES';\n // }\n\n // console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const calc = (d, x) => Math.ceil( d / (x + 1) + x)\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j x%2)\n let isEvenNum = false\n let isOddNum = false\n for (const n of numsLine) {\n if (n === 0) {\n isEvenNum = true\n }\n if (n === 1) {\n isOddNum = true\n }\n }\n if (isEvenNum && isOddNum){\n console.log('YES')\n } else {\n if (isOddNum && numsLine.reduce((r, x) => r + x, 0)%2 === 1){\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', x => input.push(x));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 1; i <= n * 2; i += 2) {\n const len = parseInt(input[i]);\n let even = 0;\n let odd = 0;\n const arr = Array.from(input[i + 1].split(' '), x => {\n x = parseInt(x);\n if (x % 2 === 0) even++;\n else odd++;\n return x;\n });\n\n if (odd % 2 === 1) {\n console.log(\"YES\");\n } else {\n if (odd + 1 > 1 && even - 1 >= 0) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n }\n});"}, {"source_code": "function processData(input) {\n //Enter your code here\n var data = input.split('\\n')\n var tcs = Number(data[0])\n var line = 1\n for(var i = 0;iparseInt(a))\n line++\n var res = findOdd(len,arr)\n console.log(res)\n }\n function findOdd(len,arr){\n var sum = 0\n var countEven =0\n var countOdd =0\n for(var i = 0;i=1 && countOdd>=1){\n return \"YES\"\n }\n else{\n return \"NO\"\n }\n\n \n }\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n const arr = readline().split(' ').map(num => parseInt(num))\n let odd = 0\n for (let i in arr) {\n if(arr[i] % 2) odd++\n }\n\n if ((odd % 2) || ((n - odd) > 0 && odd)) print('YES')\n else print('NO')\n}"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const x = a[0];\n for (let i = 1; i < a.length; i++) if (a[i] !== x) return 'YES';\n if (x === 0 || a.length % 2 === 0) return 'NO';\n return 'YES'\n}\nlet t = +readline();\nwhile(t--) print(problem(+readline(), readline().split(' ').map(i => +i%2)))\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n var odd = 0;\n var even = 0;\n for(var j = 0; j < N; j++){\n if(list[j] % 2 == 0){\n even++;\n }else{\n odd++;\n }\n }\n if(odd % 2 == 1 || (odd != 0 && odd % 2 == 0 && even >= 1)){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "function readNum() {\n return Number(readline());\n}\nfunction readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = readNum();\n for (var i = 0; i < testCasesNum; i++) {\n var len = readNum();\n var arr = readNumArray();\n var isEvenLen = len % 2 === 0;\n var checked = checkArr(arr);\n\n if (isEvenLen) {\n if (checked.hasEven && checked.hasOdd) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n } else {\n if (checked.hasOdd) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n }\n\n}\n\nconst checkArr = arr => {\n var hasOdd = false;\n var hasEven = false;\n for (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 === 0) {\n hasEven = true;\n } else {\n hasOdd = true;\n }\n if (hasEven && hasOdd) {\n break;\n }\n }\n return {\n hasEven,\n hasOdd\n };\n};\nmain();"}, {"source_code": "r=readline;for(k=r();k--;){e=o=0;n=r();r().split(\" \").map(j=>j%2?o++:e++);print(o%2||e&&o?\"YES\":\"NO\")}"}, {"source_code": "function main() {\n var t = parseInt(readline());\n while(t-- > 0) {\n var n = parseInt(readline());\n var s = readline().split(\" \"); \n \n var sum = 0;\n var even = false; odd = false;\n for(var i = 0; i < n; i++) {\n sum += parseInt(s[i]);\n if (s[i] % 2 === 0) even = true;\n else odd = true;\n }\n \n if (sum % 2 === 1 || (even && odd))\n print(\"YES\")\n else\n print(\"NO\") \n }\n}\n\nmain();"}, {"source_code": "r=readline;for(k=r();k--;print(o%2||e&&o?\"YES\":\"NO\")){e=o=0;n=r();r().split(\" \").map(j=>j%2?o++:e++)}"}, {"source_code": "function runProgram(input){\n input= input.split(\"\\n\");\n var t = Number(input[0]);\n for(var i=0;i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const sum = arr.reduce((a, b) => a + b, 0);\n\n if (sum % 2 === 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "function processData(input) {\n //Enter your code here\n var data = input.split('\\n')\n var tcs = Number(data[0])\n var line =1\n for(let i = 0;iparseInt(a))\n line++\n let res = oddSum(len,arr)\n console.log(res)\n }\n function oddSum(len,arr){\n var count = 0\n for(let i = 0;i 0) {\n const n = parseInt(readline())\n let tot = 0\n const arr = readline().split(' ').map(item => tot += parseInt(item))\n print(tot % 2 == 0 ? 'NO' : 'YES')\n}"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n const arr = readline().split(' ').map(item => parseInt(item))\n\n let tot = 0\n let odd = false\n for (let i in arr) {\n if (arr[i] % 2) odd = true\n tot += parseInt(arr[i])\n }\n\n print((tot % 2) || (odd && (n % 2)) ? 'YES' : 'NO')\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n if(N == 1){\n if(list[0] % 2 == 0){\n output[i] = \"NO\";\n }else{\n output[i] = \"YES\";\n }\n }else{\n var odd = 0;\n var even = 0;\n for(var j = 0; j < N; j++){\n if(list[j] % 2 == 0){\n even++;\n }else{\n odd++;\n }\n }\n if(odd % 2 == 1 || (odd % 2 == 0 && even % 2 == 1)){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n }\n myout(myconv(output,9));\n}\n"}], "src_uid": "2e8f7f611ba8d417fb7d12fda22c908b"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = 1000000000;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n let total = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (a[i][j] == '1') {\r\n total++;\r\n }\r\n }\r\n }\r\n const diag = af(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n let x = (i + j) % n;\r\n let y = j;\r\n // printf(\"diag %d (%d,%d)\\n\", i, x, y);\r\n if (a[y][x] == '1') {\r\n diag[i]++;\r\n }\r\n }\r\n }\r\n // printf(\"total %d\\n\", total);\r\n // printf(\"diag %j\\n\", diag);\r\n let ans = INF;\r\n for (let i = 0; i < n; i++) {\r\n ans = Math.min(ans, n - diag[i] + total - diag[i]);\r\n }\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = Array.from({ length: n });\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextStr();\r\n }\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n", "positive_code": [{"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n readline();\r\n var n = parseInt(readline());\r\n var mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var row = readline().split('').map(x=>parseInt(x));\r\n mat.push(row);\r\n }\r\n //console.log(mat);\r\n var maxD = [0, 0];\r\n for (var i = 0; i < n; i++) {\r\n var ones = 0;\r\n var col = i;\r\n for (var r = 0; r < n; r++) {\r\n ones += mat[r][col];\r\n col = ( col + 1 ) % n;\r\n }\r\n if (ones > maxD[1]) {\r\n maxD = [i, ones];\r\n }\r\n if (ones == n) {\r\n break;\r\n }\r\n }\r\n var burls = 0;\r\n for (var r = 0; r < n; r++) {\r\n var off = (r + maxD[0]) % n;\r\n for (var c = 0; c < n; c++) {\r\n if (off == c) {\r\n burls+=mat[r][c]^1;\r\n } else {\r\n burls+=mat[r][c];\r\n }\r\n }\r\n }\r\n print(burls);\r\n }"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst n = rn();\r\n\t\tconst a = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('').map(x => Number(x));\r\n\t\t}\r\n\r\n\t\tlet ones = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tones += a[i][j] == 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction getLen (ic, jc) {\r\n\t\t\tlet len = 1, i, j;\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i + 1) % n;\r\n\t\t\t\tj = (j + 1) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i - 1 + n) % n;\r\n\t\t\t\tj = (j - 1 + n) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\treturn len;\r\n\t\t}\r\n\r\n\t\tconst diag = Array(n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (a[i][j] == 1) {\r\n\t\t\t\t\tlet d = i - j;\r\n\t\t\t\t\tif (d < 0) d += n;\r\n\t\t\t\t\tdiag[d] += getLen(i, j);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst have = Math.max(...diag);\r\n\r\n\t\tconsole.log((n - have) + (ones - have));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction solve(n, matrix) {\r\n let count = new Array(n).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n if (matrix[i][j] !== '1') continue\r\n let cur = (j - i + n) % n\r\n count[cur]++\r\n }\r\n }\r\n let max = Math.max(...count)\r\n return count.reduce((sum, a) => sum + a, 0) - max + (n - max)\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n __++\r\n const n = Number(inputs[__++])\r\n let matrix = []\r\n for (let i = 0; i < n; i++) {\r\n matrix.push(inputs[__++].trim())\r\n }\r\n res.push(solve(n, matrix))\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const n = +lines[l++]\n const grid = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, grid) {\n // const up = []\n const down = []\n let total = 0\n for (let i = 0; i < n; i++) {\n // up[i] = []\n down[i] = []\n for (let j = 0; j < n; j++) {\n if (grid[i][j] === '1') total++\n }\n }\n // [n - 1, 0] to [0, n - 1]\n for (let d = n - 1; d >= -(n - 1); d--) {\n // for (let j = 0; j < n; j++) {\n // const i = j + d\n // if (i < 0 || i >= n) continue\n\n // const prev = get(up, n, j - 1 + d, j - 1)\n // const now = +grid[i][j]\n // up[i][j] = prev + now\n // }\n for (let j = n - 1; j >= 0; j--) {\n const i = j + d\n if (i < 0 || i >= n) continue\n\n const prev = get(down, n, j + 1 + d, j + 1)\n const now = +grid[i][j]\n down[i][j] = prev + now\n }\n }\n// console.log(up, down)\n //\n let ans = Infinity\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n const d = i - j\n let a, b\n if (d >= 0) {\n a = get(down, n, d, 0) // [d, 0] to [n - 1, n - 1 - d]\n b = get(down, n, 0, n - 1 - d + 1)\n } else {\n a = get(down, n, 0, -d) // [0, -d] to [n - 1 + d, n - 1]\n b = get(down, n, n - 1 + d + 1, 0)\n }\n const now = a + b\n // console.log(now, a, b)\n ans = Math.min(n - now + total - now, ans)\n }\n }\n return ans\n}\nfunction get(grid, n, i, j) {\n if (i >= 0 && i < n && j >= 0 && j < n) return grid[i][j]\n return 0\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\n\nconst calc = (A, n)=>{\n let min = Infinity;\n let sum = 0;\n for (let i=0; i{\n let hits = 0;\n for (let k=0; ka=='1' ? 1 : 0));\n }\n print(calc(A, n))\n }\n}\n\nE.calc = calc;"}], "negative_code": [{"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var row = readline().split('').map(x=>parseInt(x));\r\n mat.push(row);\r\n }\r\n //console.log(mat);\r\n var maxD = [0, 0];\r\n for (var i = 0; i < n; i++) {\r\n var ones = 0;\r\n var col = i;\r\n for (var r = 0; r < n; r++) {\r\n ones += mat[r][col];\r\n col = ( col + 1 ) % n;\r\n }\r\n if (ones > maxD[1]) {\r\n maxD = [i, ones];\r\n }\r\n if (ones == n) {\r\n break;\r\n }\r\n }\r\n var burls = 0;\r\n for (var r = 0; r < n; r++) {\r\n var off = (r + maxD[0]) % n;\r\n for (var c = 0; c < n; c++) {\r\n if (off == c) {\r\n burls+=mat[r][c]^1;\r\n } else {\r\n burls+=mat[r][c];\r\n }\r\n }\r\n }\r\n print(burls);\r\n }"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst n = rn();\r\n\t\tconst a = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('').map(x => Number(x));\r\n\t\t}\r\n\r\n\t\tlet ones = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tones += a[i][j] == 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction getLen (ic, jc) {\r\n\t\t\tlet len = 1, i, j;\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i + 1) % n;\r\n\t\t\t\tj = (j + 1) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i - 1 + n) % n;\r\n\t\t\t\tj = (j - 1 + n) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\treturn len;\r\n\t\t}\r\n\r\n\t\tconst diag = Array(n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (a[i][j] == 1) {\r\n\t\t\t\t\tdiag[Math.abs(i - j)] += getLen(i, j);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst have = Math.max(...diag);\r\n\r\n\t\tconsole.log((n - have) + (ones - have));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst n = rn();\r\n\t\tconst a = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('').map(x => Number(x));\r\n\t\t}\r\n\r\n\t\tlet ones = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tones += a[i][j] == 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction getLen (ic, jc) {\r\n\t\t\tlet len = 1, i, j;\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i + 1) % n;\r\n\t\t\t\tj = (j + 1) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i - 1 + n) % n;\r\n\t\t\t\tj = (j - 1 + n) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++; } else break;\r\n\t\t\t}\r\n\t\t\treturn len;\r\n\t\t}\r\n\r\n\t\tconst diag = Array(2 * n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (a[i][j] == 1) {\r\n\t\t\t\t\tdiag[Math.abs(i - j + n)] += getLen(i, j);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst have = Math.max(...diag);\r\n\r\n\t\tconsole.log((n - have) + (ones - have));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst n = rn();\r\n\t\tconst a = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('').map(x => Number(x));\r\n\t\t}\r\n\r\n\t\tlet ones = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tones += a[i][j] == 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction getLen (ic, jc) {\r\n\t\t\tlet len = 1, i, j;\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i + 1) % n;\r\n\t\t\t\tj = (j + 1) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++;} else break;\r\n\t\t\t}\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i - 1 + n) % n;\r\n\t\t\t\tj = (j - 1 + n) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++;} else break;\r\n\t\t\t}\r\n\t\t\treturn len;\r\n\t\t}\r\n\r\n\t\tconst diag = Array(2 * n).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (a[i][j] == 1) {\r\n\t\t\t\t\tdiag[i - j + n] += getLen(i, j);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst have = Math.max(...diag);\r\n\r\n\t\tconsole.log((n - have) + (ones - have));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst n = rn();\r\n\t\tconst a = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('').map(x => Number(x));\r\n\t\t}\r\n\r\n\t\tlet ones = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tones += a[i][j] == 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction check (ic, jc) {\r\n\t\t\tlet len = 1, i, j;\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i + 1) % n;\r\n\t\t\t\tj = (j + 1) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++;} else break;\r\n\t\t\t}\r\n\t\t\ti = ic, j = jc;\r\n\t\t\twhile (len < n) {\r\n\t\t\t\ti = (i - 1 + n) % n;\r\n\t\t\t\tj = (j - 1 + n) % n;\r\n\t\t\t\tif (a[i][j] == 1) { a[i][j] = 2; len++;} else break;\r\n\t\t\t}\r\n\t\t\treturn len;\r\n\t\t}\r\n\r\n\t\tlet have = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (a[i][j] == 1) {\r\n\t\t\t\t\thave = Math.max(have, check(i, j));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = n - have + (ones - have);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "d174982b64cc9e8d8a0f4b8646f1157c"} {"source_code": "var fs = require('fs'), currentline = 0, input = fs.readFileSync(0, 'utf8').trim().split('\\n');\nfunction readline() { return input[currentline++]; }\nvar T = +readline();\nfor (var j = 0; j < T; j++) {\n var n = readline().split(' ').map(function (x) { return Number(x); });\n var ans = Math.min(n[1] - n[0], Math.floor((n[1] + 1) / 2) - 1);\n console.log(ans);\n}\n", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline());\r\n\r\nwhile(t--){\r\n let ar=readline().split(' ').map(x=>parseInt(x));\r\n\r\n let l=ar[0];\r\n let r=ar[1];\r\n\r\n if(r parseInt(n))\r\n\r\n let half;\r\n if(b % 2 === 0) {\r\n half = b / 2;\r\n } else {\r\n half = (b - 1) / 2;\r\n }\r\n\r\n const ans = (b - Math.min(b, Math.max(a, half + 1)))\r\n console.log(ans) \r\n})\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nlet testCase = true;\r\n\r\nrl.on('line', function(line){\r\n if(testCase) {\r\n testCase = false;\r\n return;\r\n }\r\n\r\n const [a, b] = line.split(/ +/).map((n) => parseInt(n))\r\n // console.log(a, b)\r\n let half;\r\n if(b % 2 === 0) {\r\n half = b / 2;\r\n } else {\r\n half = (b - 1) / 2;\r\n }\r\n\r\n const ans = (b - Math.min(b, Math.max(a, half + 1)))\r\n if( ans === NaN) {\r\n console.log(a + '*' + b)\r\n } else {\r\n console.log(ans)\r\n }\r\n})\r\n"}, {"source_code": "// var t = Number(readline());\r\n// var ans;\r\n// for (var i = 1; i <= t; i++) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var l = arr[0],\r\n// r = arr[1];\r\n\r\n// var a = parseInt((r / 2) + 1);\r\n\r\n// if (a >= l) {\r\n// ans = r % a;\r\n\r\n// } else {\r\n// ans = r % l;\r\n\r\n// }\r\n// console.log(ans);\r\n// }\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var ans;\r\n for (var i = 1; i <= t; i++) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var l = arr[0],\r\n r = arr[1];\r\n\r\n var a = parseInt((r / 2) + 1);\r\n\r\n if (a >= l) {\r\n ans = r % a;\r\n\r\n } else {\r\n ans = r % l;\r\n\r\n }\r\n console.log(ans);\r\n }\r\n\r\n\r\n}"}, {"source_code": "'use strict'\r\n\r\nfunction beginAndGetInputData() {\r\n let i = ''\r\n let lines = [];\r\n process.stdin.on('data', c => i += c)\r\n process.stdin.on('end', () => {\r\n lines = i.split('\\n'); // your input text, split by lines\r\n if (lines[lines.length - 1].length === 0) {\r\n lines.length--;\r\n };\r\n main(lines);\r\n });\r\n}\r\n\r\n\r\nfunction main(lines) {\r\n // let r = 999999999;\r\n // let ans = Math.ceil((r + 1) / 2);\r\n // console.log(r % (ans +1));\r\n for (let i = 1; i < lines.length; i++){\r\n let line = lines[i].split(' ');\r\n let l = parseInt(line[0]), r = parseInt(line[1]);\r\n let ans = Math.ceil((r + 1) / 2);\r\n console.log(r % Math.max(l, ans));\r\n }\r\n}\r\n\r\nbeginAndGetInputData();"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var l = k[0], r = k[1];\n var a = r;\n var b = Math.max(l, Math.floor(r / 2) + 1);\n console.log(a % b);\n }\n});"}, {"source_code": "let line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n let input = line.trim().split('\\n');\n for (let i = 1; i < input.length; ++i) { \n let [l, r] = input[i].split(' ').map(x => Number(x));\n console.log(l <= Math.floor(r / 2 + 1) ? r % Math.floor(r / 2 + 1) : r % l);\n }\n});\n \t \t\t \t \t\t\t\t \t\t\t \t \t\t"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [l, r] = rna();\r\n\r\n\t\tconst a = r;\r\n\t\tconst b = Math.max(l, Math.ceil((a+1)/2));\r\n\r\n\t\tconsole.log(a%b);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar L = nextInt();\r\n\t\tvar R = nextInt();\r\n\t\tmyout(R % Math.max(L, Math.ceil((R + 1) / 2)));\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(u = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= u.length\r\n },\r\n readLine: i,\r\n readLineAsNumber: function () {\r\n return Number(i())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = i().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = i().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function i() {\r\n return u[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let o = 0\r\n return {\r\n flush: i,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function i() {\r\n n.write(u.toString(e, 0, o)), (o = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - o < s && (i(), s >= r) ? n.write(t) : (u.write(t, o, e), (o += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = t.readLineAsNumber()\r\n for (let e = 1; e <= n; ++e) {\r\n const [n, e] = t.readIntegersOfLine()\r\n let r = 1 + (e >> 1)\r\n r < n && (r = n)\r\n const u = e % r\r\n t.print(u + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n var a = r;\r\n var b = Math.max(l, Math.floor(r / 2) + 1);\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}], "negative_code": [{"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n var a = r;\r\n var b = Math.max(l, Math.floor(r / 2) - 1);\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n a = r;\r\n var b = Math.max(l, Math.floor(r / 2) - 1);\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n a = r;\r\n var b = Math.max(l, Math.ceil(r / 2) - 1);\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n a = r;\r\n var b = Math.max(l, Math.ceil(r / 2));\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n for(j = 1; j <= n; j++){\r\n var k = lines[j].split(' ').map(Number)\r\n var l = k[0]\r\n var r = k[1]\r\n a = r;\r\n var b = Math.max(l, Math.floor(r / 2));\r\n console.log(a % b);\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\n\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var answer = 0\n var v = 0\n for(j = 1; j <= n; j++){\n var s = lines[j].split(' ').map(Number)\n var a = s[0]\n var b = s[1]\n if(Math.max(a, b) / 2 > Math.min(a, b)){\n answer = Math.max(a, b) / 2\n v = Math.ceil(answer - 1)\n console.log(v)\n }else{\n answer = Math.floor((a + b) / 2 )\n v = Math.max(a, b) % answer\n console.log(v)\n }\n }\n});\n "}, {"source_code": "let i = '';\n\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var answer = 0\n var v = 0\n for(j = 1; j <= n; j++){\n var s = lines[j].split(' ').map(Number)\n var a = s[0]\n var b = s[1]\n answer = (a + b) / 2 \n v = Math.max(a, b) % answer\n console.log(v)\n }\n});\n "}, {"source_code": "let i = '';\n\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var answer = 0\n var v = 0\n for(j = 1; j <= n; j++){\n var s = lines[j].split(' ').map(Number)\n var a = s[0]\n var b = s[1]\n answer = (a + b) / 2 \n v = Math.max(a, b) / answer\n console.log(v)\n }\n});\n "}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline());\r\n\r\n\r\n let ar=readline().split(' ').map(x=>parseInt(x));\r\n\r\n let l=ar[0];\r\n let r=ar[1];\r\n\r\n if(r {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n while(t--) {\r\n let l=parseInt(readLine())\r\n let r=parseInt(readLine())\r\n\r\n if(r {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main() {\r\n var t=parseInt(readline());\r\n\r\n while(t--){\r\n var l=parseInt(readline());\r\n var r=parseInt(readline());\r\n\r\n if(r {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main() {\r\n var t=parseInt(readline())\r\n\r\n while(t--){\r\n var l=parseInt(readline())\r\n var r=parseInt(readline())\r\n\r\n if(r {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main() {\r\n var t=parseInt(readline())\r\n\r\nwhile(t--){\r\n var l=parseInt(readline())\r\n var r=parseInt(readline())\r\n\r\n if(r parseInt(n))\r\n // console.log(a, b)\r\n let half;\r\n if(b % 2 === 0) {\r\n half = b / 2;\r\n } else {\r\n half = (b - 1) / 2;\r\n }\r\n\r\n console.log(b - Math.min(b, Math.max(a, half + 1)))\r\n})\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nlet testCase = true;\r\n\r\nrl.on('line', function(line){\r\n if(testCase) {\r\n testCase = false;\r\n return;\r\n }\r\n\r\n const [a, b] = line.split(\" \").map((n) => parseInt(n))\r\n // console.log(a, b)\r\n let half;\r\n if(b % 2 === 0) {\r\n half = b / 2;\r\n } else {\r\n half = (b - 1) / 2;\r\n }\r\n\r\n console.log(b - Math.min(b, Math.max(a, half + 1)))\r\n})\r\n"}, {"source_code": "// var t = Number(readline());\r\n// var r;\r\n// for (var i = 1; i <= t; i++) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1];\r\n\r\n// if (a >= b) {\r\n// r = a % b;\r\n// if (r == 1) {\r\n// r = 1;\r\n// } else {\r\n// r = parseInt(((a - r) / 2));\r\n// }\r\n// } else {\r\n// r = b % a;\r\n// if (r == 1) {\r\n// r = 1;\r\n// } else {\r\n// r = parseInt(((b - r) / 2));\r\n// }\r\n// }\r\n// console.log(r);\r\n// }\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var r;\r\n for (var i = 1; i <= t; i++) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n\r\n if (a >= b) {\r\n r = a % b;\r\n if (r == 1) {\r\n r = 1;\r\n } else {\r\n r = parseInt(((a - r) / 2));\r\n }\r\n } else {\r\n r = b % a;\r\n if (r == 1) {\r\n r = 1;\r\n } else {\r\n r = parseInt(((b - r) / 2));\r\n }\r\n }\r\n console.log(r);\r\n }\r\n\r\n}"}, {"source_code": "// var t = Number(readline());\r\n// var r;\r\n// for (var i = 1; i <= t; i++) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1];\r\n\r\n// if (a >= b) {\r\n// r = a % b;\r\n// } else {\r\n// r = b % a;\r\n// }\r\n// console.log(r);\r\n// }\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n var r;\r\n for (var i = 1; i <= t; i++) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1];\r\n\r\n if (a >= b) {\r\n r = a % b;\r\n } else {\r\n r = b % a;\r\n }\r\n console.log(r);\r\n }\r\n}"}, {"source_code": "'use strict'\r\n\r\nfunction beginAndGetInputData() {\r\n let i = ''\r\n let lines = [];\r\n process.stdin.on('data', c => i += c)\r\n process.stdin.on('end', () => {\r\n lines = i.split('\\n'); // your input text, split by lines\r\n main(lines);\r\n });\r\n}\r\n\r\n\r\nfunction main(lines) {\r\n // let r = 999999999;\r\n // let ans = Math.ceil((r + 1) / 2);\r\n // console.log(r % (ans +1));\r\n for (let i = 1; i < lines.length; i++){\r\n let line = lines[i].split(' ');\r\n let l = parseInt(line[0]), r = parseInt(line[1]);\r\n let ans = Math.ceil((r + 1) / 2);\r\n console.log(r % Math.max(l, ans));\r\n }\r\n}\r\n\r\nbeginAndGetInputData();"}], "src_uid": "c34db7897f051b0de2f49f2696c6ee2f"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n let a = Array.from(readLine()).map(Number)\n const b = Array.from(readLine()).map(Number)\n const results = []\n let start = 0, reverse = false\n for (let i = n - 1; i >= 0; i--) {\n if (reverse ? a[start - i] !== b[i] : a[start + i] === b[i]) {\n continue\n }\n if (i === 0) {\n if (reverse ? a[start] === b[0] : a[start] !== b[0]) {\n results.push(1)\n }\n continue\n }\n if (reverse ? a[start] !== b[i] : a[start] === b[i]) {\n results.push(1)\n a[start] = (a[start] + 1) % 2\n }\n results.push(i + 1)\n start = reverse ? start - i : start + i\n reverse = !reverse\n }\n console.log(`${results.length}${results.length ? ' ' + results.join(' ') : ''}`)\n }\n}\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim()\n })\n \n main() \n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nString.prototype.count = function(c) { \n let result = 0\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++\n return result\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1)\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n\n while(t--) {\n let n = parseInt(readLine().trim())\n let [a, b] = [readLine().trim(), readLine().trim()]\n \n a += '0'\n b += '0'\n\n let [ops1, ops2] = [[], []]\n \n for (let i = 1; i <= n; ++i) {\n if (a[i] !== a[i-1])\n ops1.push(i)\n\n if (b[i] !== b[i-1]) \n ops2.push(i)\n }\n\n ops2.reverse()\n ops1 = ops1.concat(ops2)\n \n process.stdout.write(ops1.length + ' ')\n for(let o of ops1)\n process.stdout.write(o + ' ')\n process.stdout.write('\\n')\n }\n}"}, {"source_code": "function not(c) {\n if (c === '1') {\n return '0';\n }\n return '1';\n}\n\nfunction inc(i) {\n return i + 1;\n}\n\nfunction dec(i) {\n return i - 1;\n}\n\nfunction solve() {\n var n = Number(read());\n var a = Array.from(read());\n var b = Array.from(read());\n var ans = [];\n\n function f(index) {\n var res = a.slice();\n for (var i = 0; i <= index; i++) {\n res[i] = not(a[index - i]);\n }\n a = res;\n }\n \n var rev = false;\n var j = n - 1;\n var from = n - 1;\n var to = 0;\n var f = dec;\n for (var i = n - 1; i >= 0; i--) {\n var curA = a[j];\n var zeroA = a[to];\n if (rev) {\n curA = not(curA);\n zeroA = not(zeroA);\n }\n if (curA === b[i]) {\n j = f(j);\n from = j;\n continue;\n }\n if (zeroA === b[i]) {\n ans.push(1);\n a[to] = not(a[to]);\n }\n ans.push(i + 1);\n if (rev) {\n rev = false;\n f = dec;\n } else {\n rev = true;\n f = inc;\n }\n j = f(to);\n to = from;\n from = j;\n }\n write(ans.length + ' ' + ans.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "function not(c) {\n if (c === '1') {\n return '0';\n }\n return '1';\n}\n\nfunction inc(i) {\n return i + 1;\n}\n\nfunction dec(i) {\n return i - 1;\n}\n\nfunction solve() {\n var n = Number(read());\n var a = Array.from(read());\n var b = Array.from(read());\n var ans = [];\n \n var rev = false;\n var j = n - 1;\n var from = n - 1;\n var to = 0;\n var f = dec;\n var t;\n for (var i = n - 1; i >= 0; i--) {\n var curA = a[j];\n var zeroA = a[to];\n if (rev) {\n curA = not(curA);\n zeroA = not(zeroA);\n }\n write(j + ' ' + from + ' ' + to);\n if (curA === b[i]) {\n j = f(j);\n from = j;\n continue;\n }\n if (zeroA === b[i]) {\n ans.push(1);\n a[to] = not(a[to]);\n }\n ans.push(i + 1);\n if (rev) {\n rev = false;\n f = dec;\n } else {\n rev = true;\n f = inc;\n }\n j = to;\n to = from;\n from = j;\n j = f(j);\n }\n write(ans.length + ' ' + ans.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function not(c) {\n if (c === '1') {\n return '0';\n }\n return '1';\n}\n\nfunction inc(i) {\n return i + 1;\n}\n\nfunction dec(i) {\n return i - 1;\n}\n\nfunction solve() {\n var n = Number(read());\n var a = Array.from(read());\n var b = Array.from(read());\n var ans = [];\n \n var rev = false;\n var j = n - 1;\n var from = n - 1;\n var to = 0;\n var f = dec;\n var t;\n for (var i = n - 1; i >= 0; i--) {\n var curA = a[j];\n var zeroA = a[to];\n if (rev) {\n curA = not(curA);\n zeroA = not(zeroA);\n }\n if (curA === b[i]) {\n j = f(j);\n from = j;\n continue;\n }\n if (zeroA === b[i]) {\n ans.push(1);\n a[to] = not(a[to]);\n }\n ans.push(i + 1);\n if (rev) {\n rev = false;\n f = dec;\n } else {\n rev = true;\n f = inc;\n }\n j = to;\n to = from;\n from = j;\n j = f(j);\n }\n write(ans.length + ' ' + ans.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim()\n })\n \n main() \n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nString.prototype.count = function(c) { \n let result = 0\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++\n return result\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1)\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n\n while(t--) {\n let n = parseInt(readLine().trim())\n let [a, b] = [readLine().trim(), readLine().trim()]\n \n a += '0'\n b += '0'\n\n let [ops1, ops2] = [[], []]\n \n for (let i = 1; i <= n; ++i) {\n if (a[i] !== a[i-1])\n ops1.push(i)\n\n if (b[i] !== b[i-1]) \n ops2.push(i)\n }\n\n ops2.reverse()\n ops1 = ops1.concat(ops2)\n \n process.stdout.write(String(ops1.length))\n for(let o of ops1)\n process.stdout.write(String(o))\n }\n}"}], "src_uid": "46c5ebf1ddf5547352e84ba0171eacbc"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nfunction reverse(s) {\r\n return s.split('').reverse().join('');\r\n}\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const s = await getLine();\r\n if (s.length === 1) {\r\n console.log(`${s}${s}`);\r\n continue;\r\n }\r\n if (s.charCodeAt(0) === s.charCodeAt(1)) {\r\n console.log(s.substr(0, 2));\r\n continue;\r\n }\r\n let i = 1\r\n while (i < s.length && s.charCodeAt(i) <= s.charCodeAt(i-1)) i++;\r\n console.log(`${s.substr(0, i)}${reverse(s.substr(0,i))}`);\r\n }\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "let input = \"\";\nprocess.stdin.on(\"data\", (c) => (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `4\n// 10\n// codeforces\n// 9\n// cbacbacba\n// 3\n// aaa\n// 4\n// bbaa\n// 3\n// ba\n// 1\n// zaa\n// 2\n// zbaaaa\n// 1\n// cbbba`.split(\"\\n\");\n\nconst solveProblem = (lines) => {\n const alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\n const strings = lines.slice(2).filter((_, i) => i % 2 === 0);\n\n const results = [];\n\n for (let i = 0; i < strings.length; i++) {\n let firstOfCurrentChar = 0;\n let lastAlphabetIndex = Infinity;\n let sliceTo = 0;\n for (let j = 0; j < strings[i].length; j++) {\n const char = strings[i][j];\n const alphabetPosition = alphabet.indexOf(char);\n if (alphabetPosition < lastAlphabetIndex) {\n lastAlphabetIndex = alphabetPosition;\n firstOfCurrentChar = j;\n sliceTo = j + 1;\n } else if (\n alphabetPosition === lastAlphabetIndex &&\n firstOfCurrentChar !== 0\n ) {\n const mirrorPosition = firstOfCurrentChar - (j - firstOfCurrentChar);\n if (mirrorPosition < 0) {\n sliceTo = j + 1;\n continue;\n }\n const mirrorCharAlphabetPosition = alphabet.indexOf(\n strings[i][mirrorPosition]\n );\n if (mirrorCharAlphabetPosition > alphabetPosition) {\n sliceTo = j + 1;\n continue;\n }\n break;\n } else {\n break;\n }\n }\n const part1 = strings[i].slice(0, sliceTo);\n const part2 = part1.slice(0).split(\"\").reverse().join(\"\");\n results.push(part1 + part2);\n }\n\n console.log(results.join(\"\\n\"));\n};\n\n// solveProblem(lines);\n"}, {"source_code": "const solve = (n,str)=>{\r\n let k = 1,p = str[0];\r\n if(n===1){\r\n console.log(str[0]+str[0]);\r\n return;\r\n }\r\n if(str[0]===str[1]){\r\n console.log(str[0]+str[1]);\r\n return;\r\n }\r\n for(let i=1;i=0;i--) r+=res[i];\r\n console.log(r);\r\n \r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve() {\r\n\t let n = inputReader.readNumber();\r\n\t let s = inputReader.readLine();\r\n\t let pos = n - 1;\r\n\t for (let i = 0; i < n - 1; i++) {\r\n\t if (s[i] < s[i + 1]) {\r\n\t pos = i;\r\n\t break;\r\n\t }\r\n\t if (s[i] == s[i + 1]) {\r\n\t if (i == 0) {\r\n\t pos = i;\r\n\t break;\r\n\t }\r\n\t }\r\n\t }\r\n\t let ans = s.slice(0, pos + 1);\r\n\t ans = ans.concat(ans.split(\"\").reverse().join(\"\"));\r\n\t console.log(ans);\r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readLine(){\r\n\t\treturn _inputLines[_lineNumber++];\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadLine,\r\n\t}\r\n}"}], "negative_code": [{"source_code": "const solve = (n,str)=>{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n if(str[0]str[i]) k = i;\r\n if(str[k]===str[k+1]) k=k+1;\r\n }\r\n let res = str.slice(0,k+1);\r\n let r = res+\"\";\r\n for(let i=res.length-1;i>=0;i--) r+=res[i];\r\n console.log(r);\r\n \r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n if(str[0]<=str[1]){\r\n console.log(str[0]+str[1]);\r\n return;\r\n }\r\n let k = 0;\r\n for(let i=0;istr[i]) k = i;\r\n if(str[k]===str[k+1]) k=k+1;\r\n }\r\n let res = str.slice(0,k+1);\r\n let r = res+\"\";\r\n for(let i=res.length-1;i>=0;i--) r+=res[i];\r\n console.log(r);\r\n \r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n if(str[0]===str[1]){\r\n console.log(str[0]+str[1]);\r\n return;\r\n }\r\n let k = 0;\r\n for(let i=0;istr[i]) k = i;\r\n if(str[k]===str[k+1]) k=k+1;\r\n }\r\n let res = str.slice(0,k+1);\r\n let r = res+\"\";\r\n for(let i=res.length-1;i>=0;i--) r+=res[i];\r\n console.log(r);\r\n \r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n let res = \"\";\r\n for(let i=0;i=0;i--) r+=res[i];\r\n console.log(r);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n let res = \"\";\r\n for(let i=0;i=0;i--) r+=res[i];\r\n console.log(r);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n if(n===1) {\r\n console.log(str+str);\r\n return;\r\n }\r\n let res = \"\";\r\n for(let i=0;i=0;i--) r+=res[i];\r\n console.log(r);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i{\r\n let res = \"\";\r\n for(let i=0;i=0;i--) r+=res[i];\r\n console.log(r);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;i (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `4\n// 10\n// codeforces\n// 9\n// cbacbacba\n// 3\n// aaa\n// 4\n// bbaa\n// 3\n// ba\n// 1\n// zaa\n// 2\n// zbaaaa`.split(\"\\n\");\n\nconst solveProblem = (lines) => {\n const alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\n const strings = lines.slice(2).filter((_, i) => i % 2 === 0);\n\n const results = [];\n\n for (let i = 0; i < strings.length; i++) {\n let firstOfCurrentChar = 0;\n let lastAlphabetIndex = Infinity;\n let sliceTo = 0;\n for (let j = 0; j < strings[i].length; j++) {\n const char = strings[i][j];\n const alphabetPosition = alphabet.indexOf(char);\n if (alphabetPosition < lastAlphabetIndex) {\n lastAlphabetIndex = alphabetPosition;\n firstOfCurrentChar = j;\n sliceTo = j + 1;\n } else if (alphabetPosition === lastAlphabetIndex) {\n const mirrorPosition = firstOfCurrentChar - (j - firstOfCurrentChar);\n if (mirrorPosition < 0) {\n break;\n }\n const mirrorCharAlphabetPosition = alphabet.indexOf(\n strings[i][mirrorPosition]\n );\n if (mirrorCharAlphabetPosition > alphabetPosition) {\n sliceTo = j + 1;\n } else {\n break;\n }\n } else {\n break;\n }\n }\n const part1 = strings[i].slice(0, sliceTo);\n const part2 = part1.slice(0).split(\"\").reverse().join(\"\");\n results.push(part1 + part2);\n }\n\n console.log(results.join(\"\\n\"));\n};\n\n// solveProblem(lines);\n"}, {"source_code": "let input = \"\";\nprocess.stdin.on(\"data\", (c) => (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `4\n// 10\n// codeforces\n// 9\n// cbacbacba\n// 3\n// aaa\n// 4\n// bbaa\n// 3\n// ba`.split(\"\\n\");\n\nconst solveProblem = (lines) => {\n const alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\n const strings = lines.slice(2).filter((_, i) => i % 2 === 0);\n\n const results = [];\n\n for (let i = 0; i < strings.length; i++) {\n let lastIndex = Infinity;\n let sliceTo = 0;\n for (let j = 0; j < strings[i].length; j++) {\n const char = strings[i][j];\n const alphabetPosition = alphabet.indexOf(char);\n if (alphabetPosition < lastIndex) {\n lastIndex = alphabetPosition;\n sliceTo = j + 1;\n } else {\n break;\n }\n }\n const part1 = strings[i].slice(0, sliceTo);\n const part2 = part1.slice(0).split(\"\").reverse().join(\"\");\n results.push(part1 + part2);\n }\n\n console.log(results.join(\"\\n\"));\n};\n\n// solveProblem(lines);\n"}, {"source_code": "let input = \"\";\nprocess.stdin.on(\"data\", (c) => (input += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = input.split(EOL); /*your input text, split by lines*/\n solveProblem(lines);\n});\n\n// const lines = `4\n// 10\n// codeforces\n// 9\n// cbacbacba\n// 3\n// aaa\n// 4\n// bbaa\n// 3\n// ba`.split(\"\\n\");\n\nconst solveProblem = (lines) => {\n const alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\n const strings = lines.slice(2).filter((_, i) => i % 2 === 0);\n\n const results = [];\n\n for (let i = 0; i < strings.length; i++) {\n let lastIndex = Infinity;\n for (let j = 0; j < strings[i].length; j++) {\n const char = strings[i][j];\n const alphabetPosition = alphabet.indexOf(char);\n if (alphabetPosition < lastIndex) {\n lastIndex = alphabetPosition;\n } else {\n const part1 = strings[i].slice(0, j);\n const part2 = part1.slice(0).split(\"\").reverse().join(\"\");\n results.push(part1 + part2);\n break;\n }\n }\n }\n\n console.log(results.join(\"\\n\"));\n};\n\n// solveProblem(lines);\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n let n = inputReader.readNumber();\r\n let s = inputReader.readLine();\r\n let pos = n - 1;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (s[i] <= s[i + 1]) {\r\n pos = i;\r\n break;\r\n }\r\n }\r\n let ans = s.slice(0, pos + 1);\r\n ans = ans.concat(ans.split(\"\").reverse().join(\"\"));\r\n console.log(ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readLine() {\r\n return _inputLines[_lineNumber++];\r\n }\r\n\r\n return {\r\n readNumber,\r\n readLine,\r\n };\r\n}\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nfunction reverse(s) {\r\n return s.split('').reverse().join('');\r\n}\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const s = await getLine();\r\n if (s.length === 1) {\r\n console.log(s);\r\n continue;\r\n }\r\n if (s.charCodeAt(0) === s.charCodeAt(1)) {\r\n console.log(s.substr(0, 2));\r\n continue;\r\n }\r\n let i = 1\r\n while (i < s.length && s.charCodeAt(i) <= s.charCodeAt(i-1)) i++;\r\n console.log(`${s.substr(0, i)}${reverse(s.substr(0,i))}`);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nfunction reverse(s) {\r\n return s.split('').reverse().join('');\r\n}\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const s = await getLine();\r\n if (s.length === 1) {\r\n console.log(s);\r\n continue;\r\n }\r\n if (s.charCodeAt(0) === s.charCodeAt(1)) {\r\n console.log(s.substr(0, 2));\r\n continue;\r\n }\r\n let i = 1;\r\n while (i < s.length && s.charCodeAt(i) <= s.charCodeAt(i-1)) i++;\r\n if (i >= s.length) {\r\n console.log(s);\r\n } else {\r\n console.log(`${s.substr(0, i)}${reverse(s.substr(0,i))}`);\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var p = readline()\r\n var arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"]\r\n var str1 = p[0]\r\n var str2 = p[0]\r\n for (var i = 1; i < n; i++) {\r\n var index = arr.indexOf(str1[i - 1])\r\n if (p[i] === arr[index - 1]) {\r\n str1 += p[i]\r\n str2 = p[i] + str2\r\n } else {\r\n break;\r\n }\r\n }\r\n return str1 + str2;\r\n }\r\n\r\n while (t--) {\r\n print(solve())\r\n }"}], "src_uid": "dd7faacff9f57635f8e00c2f8f5a4650"} {"source_code": "var n = +readline();\nvar ans;\n\nif(n % 2 == 0){\n\tans = n/2 * n;\n}\nelse{\n\tans = Math.ceil(n/2) * Math.ceil(n/2) + Math.floor(n/2) * Math.floor(n/2);\n}\n\nprint(ans);\n\nfor(var i = 1; i <= n; i++){\n\tif(i % 2 == 1){\n\t\tfor(j = 1; j <= n; j++){\n\t\t\tif(j % 2 == 1){\n\t\t\t\twrite(\"C\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\".\");\n\t\t\t}\n\t\t}\n\t\twrite(\"\\n\");\n\t}\n\telse{\n\t\tfor(j = 1; j <= n; j++){\n\t\t\tif(j % 2 == 1){\n\t\t\t\twrite(\".\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\"C\");\n\t\t\t}\n\t\t}\n\t\twrite(\"\\n\");\n\t}\n}", "positive_code": [{"source_code": "var number = parseInt(readline());\nvar fs = \"\";\nvar sc = 0;\n\nfor (var i= 0 ; i {\n const board = new Array(+d).fill('.').map(x => new Array(+d).fill('.'));\n let pieces = 0;\n\n for (let i = 0; i < board.length; i++) {\n for (let j = 0; j < board[i].length; j++) {\n if (i % 2 === 0 && j % 2 === 0) {\n board[i][j] = 'C';\n pieces++;\n }\n else if (i % 2 !== 0 && j % 2 !== 0) {\n board[i][j] = 'C';\n pieces++;\n }\n }\n }\n\n console.log(pieces);\n for (let i = 0; i < board.length; i++) {\n console.log(board[i].join(''));\n }\n});\n"}, {"source_code": "\n// 384A \u041a\u043e\u0434\u0435\u0440 \n\n\nvar n = parseInt(readline());\n//var input_line = readline().split(' ').map(Number);\n\nvar out = '';\nvar count = 0;\n\nfor (var i = 1; i <= n; i += 2) {\n if ((n % 2) !== 0) {\n count += Math.floor(n / 2) + 1;\n for (var j = 1; j < n/2; j++) out += 'C.';\n out += 'C\\n';\n if (i < n) {\n count += Math.floor(n / 2);\n for (var j = 1; j < n/2; j++) out += '.C';\n out += '.\\n';\n };\n } else {\n count += n;\n for (var j = 0; j < n/2; j++) out += 'C.';\n out += '\\n';\n for (var j = 0; j < n/2; j++) out += '.C';\n out += '\\n';\n };\n};\n\nprint(count);\nprint(out);\n\n\n"}], "negative_code": [{"source_code": "var n=+readline();\nvar a=[];\n\nvar f=true;\nfor(var i=0;i {\n const board = new Array(+d).fill('.').map(x => new Array(+d).fill('.'));\n let pieces = 0;\n\n for (let i = 0; i < board.length; i++) {\n for (let j = 0; j < board[i].length; j++) {\n if (j % 2 === 0) {\n board[i][j] = 'C';\n pieces++;\n }\n }\n }\n\n console.log(pieces);\n for (let i = 0; i < board.length; i++) {\n console.log(board[i].join(''));\n }\n});\n"}], "src_uid": "1aede54b41d6fad3e74f24a6592198eb"} {"source_code": "Array.prototype.sub_reverse = function(x,y) {\n\tvar a = this;\n\tvar n = a.length;\n\tfor (var i = 0; i+i < (y - x); i++) {\n\t\tvar temp = a[x+i];\n\t\ta[x+i] = a[y-1-i];\n\t\ta[y-1-i] = temp;\n\t}\n}\n\nArray.prototype.next_permutation = function(){\n\tvar a = this;\n\tvar n = a.length;\n\tif (n < 2) return false;\n\n\t//Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.\n\tfor (var k = n-2; k >= 0 && a[k] >= a[k+1]; --k){}\n\tif (k == -1) return false;\n\n\t//Find the largest index l greater than k such that a[k] < a[l].\n\tfor (var l = n-1; k < l && a[k] >= a[l]; --l){}\n\tif (k == l) return false;\t\n\n\t//Swap the value of a[k] with that of a[l].\n\tvar temp = a[k];\n\ta[k] = a[l];\n\ta[l] = temp;\n\n\t//Reverse the sequence from a[k + 1] up to and including the final element a[n].\n\ta.sub_reverse(k+1,n);\n\treturn true;\n}\n\nfunction solve(a,order) {\n\tvar letter = [\"A\",\"B\",\"C\"];\n\tvar A = {x:a[0][0], y:a[0][1], letter:letter[order[0]]};\n\tvar B = {x:a[1][0], y:a[1][1], letter:letter[order[1]]};\n\tvar C = {x:a[2][0], y:a[2][1], letter:letter[order[2]]};\n\t\n\t// AA\n\t// BB\n\t// CC\n\tif (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {\n\t\twrite(A.x + \"\\n\");\n\t\tfor (var i = 0; i < A.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++)\n\t\t\t\twrite(A.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < B.x; j++)\n\t\t\t\twrite(B.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < C.x; j++)\n\t\t\t\twrite(C.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ABB\n\t// ACC\n\tif (B.x == C.x && A.y == (B.y+C.y) && A.y == (A.x + B.x)) {\n\t\twrite(A.y + \"\\n\");\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(A.letter);\n\t\t\tfor (var j = 0; j < B.x; j++) write(B.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(A.letter);\n\t\t\tfor (var j = 0; j < C.x; j++) write(C.letter);\n\t\t\twrite(\"\\n\");\t\n\t\t}\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\nfunction main() {\n\ta = readline().split(\" \").map(Number);\n\n\tvar order = [0,1,2];\n\tdo {\n\t\t// 2d array\n\t\tvar b = [];\n\t\tfor (var i = 0; i < 3; i++) {\n\t\t\tb.push([ a[2*order[i]], a[2*order[i]+1] ]);\n\t\t}\n\t\t\n\t\tfor (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {\n\t\t\tvar c = [];\n\t\t\t// rotate\n\t\t\tfor (var i = 0; i < 3; i++)\n\t\t\t\tif (rotation_mask & (1< width)\n\t return false;\n\t height += rect[1].height;\n\t if (rect[2].width + rect[1].width === width) {\n\t if (rect[2].height !== rect[1].height)\n\t return false;\n\t if (height !== width)\n\t return false;\n\t var canvas = square(width);\n\t draw(canvas, 0, 0, rect[0]);\n\t draw(canvas, 0, rect[0].height, rect[1]);\n\t draw(canvas, rect[1].width, rect[0].height, rect[2]);\n\t output(canvas);\n\t return true;\n\t }\n\t else {\n\t if (rect[1].width != width || rect[2].width != width)\n\t return false;\n\t height += rect[2].height;\n\t if (height != width)\n\t return false;\n\t var canvas = square(width);\n\t draw(canvas, 0, 0, rect[0]);\n\t draw(canvas, 0, rect[0].height, rect[1]);\n\t draw(canvas, 0, rect[0].height + rect[1].height, rect[2]);\n\t output(canvas);\n\t return true;\n\t }\n\t}\n\tvar found = false;\n\tfor (var rotation = 0; rotation < 8 && !found; rotation++) {\n\t var rotated = [];\n\t for (var i = 0; i < 3; i++) {\n\t var should_rotate = ((rotation >> i) & 1) !== 0;\n\t rotated.push(should_rotate ? rects[i].rotated() : rects[i]);\n\t }\n\t var p = List.range(0, 2);\n\t do {\n\t found = found || fit(List.apply_permutation(p, rotated));\n\t } while ((p = List.next_permutation(p)) && !found);\n\t}\n\tif (!found)\n\t print(\"-1\");\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(2);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction maximum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximum = maximum;\n\tfunction minimum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimum = minimum;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\tfunction range(from, to) {\n\t var result = Array(to - from + 1);\n\t for (var i = from; i <= to; i++) {\n\t result[i - from] = i;\n\t }\n\t return result;\n\t}\n\texports.range = range;\n\tfunction copy(xs) {\n\t return xs.slice(0);\n\t}\n\texports.copy = copy;\n\tfunction apply_permutation(p, xs) {\n\t var n = xs.length;\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = xs[p[i]];\n\t }\n\t return result;\n\t}\n\texports.apply_permutation = apply_permutation;\n\tfunction next_permutation(p) {\n\t var n = p.length;\n\t if (n < 2)\n\t return null;\n\t var r = copy(p);\n\t var k = n - 2;\n\t for (; k >= 0 && r[k] >= r[k + 1]; k--)\n\t ;\n\t if (k < 0)\n\t return null;\n\t for (var i = k + 1, j = n - 1; i < j; i++, j--) {\n\t var t_1 = r[i];\n\t r[i] = r[j];\n\t r[j] = t_1;\n\t }\n\t var next = k + 1;\n\t for (; r[next] <= r[k]; next++)\n\t ;\n\t var t = r[k];\n\t r[k] = r[next];\n\t r[next] = t;\n\t return r;\n\t}\n\texports.next_permutation = next_permutation;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\n\n/***/ }\n/******/ ]);"}], "negative_code": [{"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar List = __webpack_require__(1);\n\tvar xy = List.map(parseInt, readline().split(' '));\n\tvar Rect = (function () {\n\t function Rect(width, height, label) {\n\t this.width = width;\n\t this.height = height;\n\t this.label = label;\n\t }\n\t Rect.prototype.rotated = function () {\n\t return new Rect(this.height, this.width, this.label);\n\t };\n\t return Rect;\n\t})();\n\tvar rects = [];\n\tvar label = [\"A\", \"B\", \"C\"];\n\tfor (var i = 0; i < 3; i++) {\n\t rects.push(new Rect(xy[2 * i], xy[2 * i + 1], label[i]));\n\t}\n\tvar infinity = 100000000;\n\tfunction square(n) {\n\t return List.map(function (_) { return List.replicate(n, \".\"); }, List.replicate(n, []));\n\t}\n\tfunction draw(canvas, x, y, r) {\n\t for (var i = x; i < x + r.width; i++) {\n\t for (var j = y; j < y + r.height; j++) {\n\t canvas[i][j] = r.label;\n\t }\n\t }\n\t}\n\tfunction output(canvas) {\n\t print(List.map(function (s) { return s.join(\"\"); }, canvas).join(\"\\n\"));\n\t}\n\tfunction fit(rect) {\n\t var width = rect[0].width;\n\t var height = rect[0].height;\n\t if (rects[1].width > width)\n\t return false;\n\t height += rect[1].height;\n\t if (rect[2].width + rect[1].width === width) {\n\t if (rect[2].height !== rect[1].height)\n\t return false;\n\t if (height !== width)\n\t return false;\n\t var canvas = square(width);\n\t draw(canvas, 0, 0, rect[0]);\n\t draw(canvas, 0, rect[0].height, rect[1]);\n\t draw(canvas, rect[1].width, rect[0].height, rect[2]);\n\t output(canvas);\n\t return true;\n\t }\n\t else {\n\t if (rect[1].width != width || rect[2].width != width)\n\t return false;\n\t height += rect[2].height;\n\t if (height != width)\n\t return false;\n\t var canvas = square(width);\n\t draw(canvas, 0, 0, rect[0]);\n\t draw(canvas, 0, rect[0].height, rect[1]);\n\t draw(canvas, 0, rect[0].height + rect[1].height, rect[2]);\n\t output(canvas);\n\t return true;\n\t }\n\t}\n\tvar found = false;\n\tfor (var rotation = 0; rotation < 8 && !found; rotation++) {\n\t var rotated = [];\n\t for (var i = 0; i < 3; i++) {\n\t var should_rotate = ((rotation >> i) & 1) !== 0;\n\t rotated.push(should_rotate ? rects[i].rotated() : rects[i]);\n\t }\n\t var p = List.range(0, 2);\n\t do {\n\t found = found || fit(List.apply_permutation(p, rotated));\n\t } while ((p = List.next_permutation(p)) && !found);\n\t}\n\tif (!found)\n\t print(\"-1\");\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(2);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction maximum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximum = maximum;\n\tfunction minimum(xs) {\n\t var result = xs[0];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimum = minimum;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\tfunction range(from, to) {\n\t var result = Array(to - from + 1);\n\t for (var i = from; i <= to; i++) {\n\t result[i - from] = i;\n\t }\n\t return result;\n\t}\n\texports.range = range;\n\tfunction copy(xs) {\n\t return xs.slice(0);\n\t}\n\texports.copy = copy;\n\tfunction apply_permutation(p, xs) {\n\t var n = xs.length;\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = xs[p[i]];\n\t }\n\t return result;\n\t}\n\texports.apply_permutation = apply_permutation;\n\tfunction next_permutation(p) {\n\t var n = p.length;\n\t if (n < 2)\n\t return null;\n\t var r = copy(p);\n\t var k = n - 2;\n\t for (; k >= 0 && r[k] >= r[k + 1]; k--)\n\t ;\n\t if (k < 0)\n\t return null;\n\t for (var i = k + 1, j = n - 1; i < j; i++, j--) {\n\t var t_1 = r[i];\n\t r[i] = r[j];\n\t r[j] = t_1;\n\t }\n\t var next = k + 1;\n\t for (; r[next] <= r[k]; next++)\n\t ;\n\t var t = r[k];\n\t r[k] = r[next];\n\t r[next] = t;\n\t return r;\n\t}\n\texports.next_permutation = next_permutation;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\n\n/***/ }\n/******/ ]);"}, {"source_code": "Array.prototype.sub_reverse = function(x,y) {\n\tvar a = this;\n\tvar n = a.length;\n\tfor (var i = 0; i+i < (y - x); i++) {\n\t\tvar temp = a[x+i];\n\t\ta[x+i] = a[y-1-i];\n\t\ta[y-1-i] = temp;\n\t}\n}\n\nArray.prototype.next_permutation = function(){\n\tvar a = this;\n\tvar n = a.length;\n\tif (n < 2) return false;\n\n\t//Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.\n\tfor (var k = n-2; k >= 0 && a[k] >= a[k+1]; --k){}\n\tif (k == -1) return false;\n\n\t//Find the largest index l greater than k such that a[k] < a[l].\n\tfor (var l = n-1; k < l && a[k] >= a[l]; --l){}\n\tif (k == l) return false;\t\n\n\t//Swap the value of a[k] with that of a[l].\n\tvar temp = a[k];\n\ta[k] = a[l];\n\ta[l] = temp;\n\n\t//Reverse the sequence from a[k + 1] up to and including the final element a[n].\n\ta.sub_reverse(k+1,n);\n\treturn true;\n}\n\nfunction solve(a) {\n\tvar A = {x:a[0][0], y:a[0][1]};\n\tvar B = {x:a[1][0], y:a[1][1]};\n\tvar C = {x:a[2][0], y:a[2][1]};\n\t\n\t// line \n\t// AA\n\t// BB\n\t// CC\n\tif (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {\n\t\twrite(A.x + \"\\n\");\n\t\tfor (var i = 0; i < A.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++)\n\t\t\t\twrite(\"A\");\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < B.x; j++)\n\t\t\t\twrite(\"B\");\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < C.x; j++)\n\t\t\t\twrite(\"C\");\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ABB\n\t// ACC\n\t\n\tif (B.x == C.x && A.y == (B.y+C.y)) {\n\t\twrite(A.y + \"\\n\");\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(\"A\");\n\t\t\tfor (var j = 0; j < B.x; j++) write(\"B\");\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(\"A\");\n\t\t\tfor (var j = 0; j < C.x; j++) write(\"C\");\n\t\t\twrite(\"\\n\");\t\n\t\t}\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\nfunction main() {\n\ta = readline().split(\" \").map(Number);\n\n\tvar order = [0,1,2];\n\tdo {\n\t\t// 2d array\n\t\tvar b = [];\n\t\tfor (var i = 0; i < 3; i++) {\n\t\t\tb.push([ a[2*order[i]], a[2*order[i]+1] ]);\n\t\t}\n\t\t\n\t\tfor (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {\n\t\t\tvar c = [];\n\t\t\t// rotate\n\t\t\tfor (var i = 0; i < 3; i++)\n\t\t\t\tif (rotation_mask & (1<= 0 && a[k] >= a[k+1]; --k){}\n\tif (k == -1) return false;\n\n\t//Find the largest index l greater than k such that a[k] < a[l].\n\tfor (var l = n-1; k < l && a[k] >= a[l]; --l){}\n\tif (k == l) return false;\t\n\n\t//Swap the value of a[k] with that of a[l].\n\tvar temp = a[k];\n\ta[k] = a[l];\n\ta[l] = temp;\n\n\t//Reverse the sequence from a[k + 1] up to and including the final element a[n].\n\ta.sub_reverse(k+1,n);\n\treturn true;\n}\n\nfunction solve(a,order) {\n\tvar letter = [\"A\",\"B\",\"C\"];\n\tvar A = {x:a[0][0], y:a[0][1], letter:letter[order[0]]};\n\tvar B = {x:a[1][0], y:a[1][1], letter:letter[order[1]]};\n\tvar C = {x:a[2][0], y:a[2][1], letter:letter[order[2]]};\n\t\n\t// AA\n\t// BB\n\t// CC\n\tif (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {\n\t\twrite(A.x + \"\\n\");\n\t\tfor (var i = 0; i < A.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++)\n\t\t\t\twrite(A.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < B.x; j++)\n\t\t\t\twrite(B.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < C.x; j++)\n\t\t\t\twrite(C.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ABB\n\t// ACC\n\t\n\tif (B.x == C.x && A.y == (B.y+C.y)) {\n\t\twrite(A.y + \"\\n\");\n\t\tfor (var i = 0; i < B.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(A.letter);\n\t\t\tfor (var j = 0; j < B.x; j++) write(B.letter);\n\t\t\twrite(\"\\n\");\n\t\t}\n\t\tfor (var i = 0; i < C.y; i++) {\n\t\t\tfor (var j = 0; j < A.x; j++) write(A.letter);\n\t\t\tfor (var j = 0; j < C.x; j++) write(C.letter);\n\t\t\twrite(\"\\n\");\t\n\t\t}\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\nfunction main() {\n\ta = readline().split(\" \").map(Number);\n\n\tvar order = [0,1,2];\n\tdo {\n\t\t// 2d array\n\t\tvar b = [];\n\t\tfor (var i = 0; i < 3; i++) {\n\t\t\tb.push([ a[2*order[i]], a[2*order[i]+1] ]);\n\t\t}\n\t\t\n\t\tfor (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {\n\t\t\tvar c = [];\n\t\t\t// rotate\n\t\t\tfor (var i = 0; i < 3; i++)\n\t\t\t\tif (rotation_mask & (1< {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n list = str.split(' ')\n var x = parseInt(list[0])\n var y = parseInt(list[1])\n var n = parseInt(list[2])\n var r = n % x\n\n if(r>=y){\n return (n - r + y)\n }\n else{\n return (n - r - x + y)\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [x, y, n] = readLine()\n .split(\" \")\n .map((num) => parseInt(num));\n\n if (n % x < y) {\n console.log(n - ((n % x) + (x - y)));\n } else if (n % x > y) {\n console.log(n - ((n % x) - y));\n } else {\n console.log(n);\n }\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar x = one[0];\n\t\tvar y = one[1];\n\t\tvar n = one[2];\n\t\tif(n % x == y){\n\t\t\toutput[i] = n;\n\t\t}else{\n\t\t\tif(n % x > y){\n\t\t\t\toutput[i] = n - (n % x - y);\n\t\t\t}else{\n\t\t\t\tvar tmp = y - (n % x);\n\t\t\t\toutput[i] = n - x + tmp;\n\t\t\t}\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let s = data[i].trim().split(' ');\n let x = +s[0];\n let y = +s[1];\n let n = +s[2];\n let mod = n % x;\n if (mod === y) {\n console.log(n);\n i += 1;\n continue;\n }\n if (mod > y) {\n console.log(n - (mod - y));\n i += 1;\n continue;\n }\n n -= mod;\n mod = n % x;\n n -= (x - y);\n console.log(n);\n i += 1;\n }\n }"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = parseInt(readline());\n function getAnswer(x, y, n) {\n const quotient = Math.floor(n / x);\n const remainder = n % x;\n var starting_cand = (quotient - 3) * x + y;\n while (starting_cand <= n) {\n starting_cand += x;\n }\n return starting_cand - x;\n }\n for (var tc=0; tc parseInt(number));\n console.log(getAnswer(a, b, c));\n }\n}"}, {"source_code": "var tc = Number(readline());\nwhile(tc--)\n{\n\tvar arr = readline().split(' ').map(Number);\n\tvar x = arr[0];\n\tvar y = arr[1];\n\tvar n = arr[2];\n\tn=n-y;\n\tprint( Math.floor(n/x)*x + y );\n}\n"}, {"source_code": "function solve() {\n var xyn = read().split(' ').map(Number);\n var x = xyn[0], y = xyn[1], n = xyn[2];\n var z = n % x;\n var k = n + y - z;\n if (k > n) {\n k -= x;\n }\n write(k);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var tc = Number(readline());\nwhile(tc--)\n{\n\tvar arr = readline().split(' ').map(Number);\n\tvar x = arr[0];\n\tvar y = arr[1];\n\tvar n = arr[2];\n\tn=n-y;\n\tprint( Math.floor(n/x)*x + y );\n}"}, {"source_code": "function solve(x,y,n) {\n var res = (Math.floor(n/x)*x)-(x-y);\n return res+x <= n ? res+x : res;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var x = arr[0];\n var y = arr[1];\n var n = arr[2];\n print(solve(x,y,n));\n}"}, {"source_code": "function solve(x,y,n) {\n var res = (Math.floor(n/x)*x)-(x-y);\n return res+x <= n ? res+x : res;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var x = arr[0];\n var y = arr[1];\n var n = arr[2];\n print(solve(x,y,n));\n}"}], "negative_code": [], "src_uid": "2589e832f22089fac9ccd3456c0abcec"} {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst g = main();\r\ng.next()\r\nrl.on('line', (input) => {\r\n // console.log('read', input)\r\n input.split('\\n').forEach(s => s.trim() && g.next(s))\r\n});\r\n\r\nfunction* main() {\r\n let input\r\n\r\n // input = yield 1\r\n const t = 1//+input\r\n for (let i = 0; i < t; i++) {\r\n // input = yield 1\r\n yield* solve()\r\n }\r\n process.exit(0)\r\n}\r\n\r\nfunction* solve() {\r\n // const n = yield* binarySearch(3n, 5n)\r\n for (let i = 1; i <= 25; i++) {\r\n const a = yield* ask(1, i + 1)\r\n const b = yield* ask(i + 1, 1)\r\n if (a === '-1') {\r\n return answer(i)\r\n } else if (a !== b) {\r\n return answer(BigInt(a) + BigInt(b))\r\n }\r\n }\r\n}\r\nfunction answer(n) {\r\n console.log('! ' + n)\r\n}\r\nfunction* ask(a, b) {\r\n console.log(`? ${a} ${b}`)\r\n const r = yield 1\r\n return r\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => { \r\n if (i & 1) {\r\n a2 = BigInt(line)\r\n if(a1===-1||a2===-1){\r\n console.log(`! ${j-1}`)\r\n return\r\n }\r\n if (a1 !== a2) {\r\n console.log(`! ${a1 + a2}`)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = BigInt(line)\r\n }\r\n i++\r\n question()\r\n})"}], "negative_code": [{"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => { \r\n if (i & 1) {\r\n a2 = Number(line)\r\n if(a1===-1||a2===-1){\r\n console.log(`! ${j-1}`)\r\n return\r\n }\r\n if (a1 !== a2) {\r\n console.log(`! ${a1 + a2}`)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = Number(line)\r\n }\r\n i++\r\n question()\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => { \r\n if (i & 1) {\r\n a2 = Number(line)\r\n if (a1 !== a2) {\r\n console.log(`! ${a1 + a2}`)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = Number(line)\r\n if (a1 === -1) {\r\n console.log(`! ${j-1}`)\r\n return\r\n }\r\n }\r\n i++\r\n question()\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => {\r\n if (i & 1) {\r\n a2 = Number(line)\r\n if (a1 !== a2) {\r\n console.log(`! ${a1 + a2}`)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = Number(line)\r\n if (a1 === -1) {\r\n console.log(`! ${j-1}`)\r\n return\r\n }\r\n }\r\n i++\r\n question()\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => {\r\n if (i & 1) {\r\n a2 = Number(line)\r\n if (a1 !== a2) {\r\n console.log(`! ${a1 + a2}`)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = Number(line)\r\n if (a1 === -1) {\r\n console.log(`! ${j}`)\r\n return\r\n }\r\n }\r\n i++\r\n question()\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 0, j = 1, a1 = 0, a2 = 0\r\n\r\nconst question = () => {\r\n if (i & 1) {\r\n console.log(`? ${j} ${j + 1}`)\r\n } else {\r\n console.log(`? ${j + 1} ${j}`)\r\n }\r\n}\r\nquestion()\r\nrl.on('line', line => {\r\n if (i & 1) {\r\n a2 = Number(line)\r\n if (a1 !== a2) {\r\n console.log(a1 + a2)\r\n return\r\n }\r\n j++\r\n } else {\r\n a1 = Number(line)\r\n if (a1 === -1) {\r\n console.log(j)\r\n return\r\n }\r\n }\r\n i++\r\n question()\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 2, j = 1\r\n\r\nconst question = () => {\r\n console.log(`? ${i} ${j}`)\r\n}\r\nquestion()\r\nrl.on('line', line => {\r\n const a = Number(line)\r\n if (a === -1) {\r\n console.log(`! ${i - 1}`)\r\n } else if (a !== i - j) {\r\n console.log(`! ${a + i - j}`)\r\n } else {\r\n if (j + 1 < i) j++\r\n else i++\r\n question()\r\n }\r\n})"}, {"source_code": "\r\nconst readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process');\r\n\r\nconst rl = readline.createInterface({ input, output });\r\n\r\nlet i = 1\r\n\r\nconst question = () => {\r\n console.log(`? ${i} ${i + 1}`)\r\n}\r\nquestion()\r\nrl.on('line', line => {\r\n const a = Number(line)\r\n if (a === -1) {\r\n console.log(`! ${i - 1}`)\r\n } else if (a !== 1) {\r\n console.log(`! ${a + 1}`)\r\n } else {\r\n i++\r\n question()\r\n }\r\n})"}, {"source_code": "const readline=require('readline')\r\nconst rl = readline.createInterface({input:process.stdin,output:process.stdout})\r\n\r\nvoid async function main(){\r\nfor(let i=2;i<=50;i++){\r\n for(let j=1;j {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n const log = []\n for (let i = 1; i <= 25; i++) {\n const u = rn(i + 1)\n const a = yield* ask(u, i + 3)\n const b = yield* ask(i + 3, u)\n if (a < 0 || b < 0) {\n return answer(i + 2)\n } else if (a !== b) {\n return answer(a + b)\n }\n log.push([u, i + 3, a, b].join(' '))\n }\n throw log.join(';')\n}\nfunction rn(n) {\n return Math.floor(Math.random() * n) + 1\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst g = main();\r\ng.next()\r\nrl.on('line', (input) => {\r\n // console.log('read', input)\r\n input.split('\\n').forEach(s => s.trim() && g.next(s))\r\n});\r\n\r\nfunction* main() {\r\n let input\r\n\r\n // input = yield 1\r\n const t = 1//+input\r\n for (let i = 0; i < t; i++) {\r\n // input = yield 1\r\n yield* solve()\r\n }\r\n process.exit(0)\r\n}\r\n\r\nfunction* solve() {\r\n for (let i = 1; i <= 25; i++) {\r\n const u = rn(i + 2)\r\n const a = yield* ask(u, i + 3)\r\n const b = yield* ask(i + 3, u)\r\n if (a < 0 || b < 0) {\r\n return answer(i + 2)\r\n } else if (a !== b) {\r\n return answer(a + b)\r\n }\r\n }\r\n}\r\nfunction rn(n) {\r\n return Math.floor(Math.random() * n) + 1\r\n}\r\nfunction answer(n) {\r\n console.log('! ' + n)\r\n}\r\nfunction* ask(a, b) {\r\n console.log(`? ${a} ${b}`)\r\n const r = yield 1\r\n return +r\r\n}\r\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n for (let i = 1; i <= 25; i++) {\n const a = yield* ask(1, i + 3)\n const b = yield* ask(i + 3, 1)\n if (a < 0 || b < 0) {\n return answer(i + 2)\n } else if (a !== b) {\n return answer(a + b)\n }\n }\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // hash v2\n // const n = yield* binarySearch(3n, 5n)\n for (let i = 1; i <= 25; i++) {\n const a = yield* ask(3, i + 3)\n const b = yield* ask(i + 3, 3)\n if (a < 0 || b < 0) {\n return answer(i + 2)\n } else if (a !== b) {\n return answer(a + b)\n }\n }\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // hash v2\n // const n = yield* binarySearch(3n, 5n)\n for (let i = 1; i <= 25; i++) {\n const a = yield* ask(2, i + 1)\n const b = yield* ask(i + 1, 2)\n if (a < 0 || b < 0) {\n return answer(i)\n } else if (a !== b) {\n return answer(a + b)\n }\n }\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // hash v2\n // const n = yield* binarySearch(3n, 5n)\n for (let i = 1; i <= 25; i++) {\n const a = yield* ask(1, i + 1)\n const b = yield* ask(i + 1, 1)\n if (a < 0 || b < 0) {\n return answer(i)\n } else if (a !== b) {\n return answer(a + b)\n }\n }\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // const n = yield* binarySearch(3n, 5n)\n for (let i = 1; i <= 25; i++) {\n const a = yield* ask(1, i + 1)\n const b = yield* ask(i + 1, 1)\n if (a < 0 || b < 0) {\n return answer(i)\n } else if (a !== b) {\n return answer(a + b)\n }\n }\n}\nfunction answer(n) {\n console.log('! ' + n)\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // const n = yield* binarySearch(3n, 5n)\n const n = yield* binarySearch(3n, BigInt(1e9) * BigInt(1e9))\n console.log(`! ${n}`)\n}\nfunction* binarySearch(l, r) {\n while (l <= r) {\n const m = l + ((r - l) / 4n)\n const ok = (yield* ask(1, m)) > 0\n if (ok) {\n l = m + 1n\n } else {\n r = m - 1n\n }\n }\n return r\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t; i++) {\n // input = yield 1\n yield* solve()\n }\n process.exit(0)\n}\n\nfunction* solve() {\n // const n = yield* binarySearch(3n, 5n)\n const n = yield* binarySearch(3n, BigInt(1e9) * BigInt(1e9))\n console.log(`! ${n}`)\n}\nfunction* binarySearch(l, r) {\n while (l <= r) {\n const m = l + ((r - l) / 3n)\n const ok = (yield* ask(1, m)) > 0\n if (ok) {\n l = m + 1n\n } else {\n r = m - 1n\n }\n }\n return r\n}\nfunction* ask(a, b) {\n console.log(`? ${a} ${b}`)\n const r = yield 1\n return +r\n}\n"}], "src_uid": "8590f40e7509614694486165ee824587"} {"source_code": "let fs=require('fs');\nlet txt=fs.readFileSync(0,\"utf-8\").split(/[\\n\\r]/).filter(data=>data.length>0);\n\ntxt.forEach(data=>{\n doit(data*1);\n});\n\nfunction doit(data){\n let score=0;\n for (let index = data; index >0; index--) {\n score+=1/index;\n }\n console.log(score);\n}", "positive_code": [{"source_code": "var val = readline().split(' ').map((val)=>{\n return parseInt(val);\n})\nvar sum = 0;\nfor(var i = 0 ;i < val ;i++){\n sum += 1/(1+i); \n}\nprint(sum);"}, {"source_code": "var n = parseInt(readline(), 10),\n sum = 0;\n\nfor(var i=1; i<=n; i++) {\n sum += 1/i;\n}\n\nprint(sum);"}, {"source_code": "var n = readline().split(' ');\nvar ans = 0;\nfor(var k = 1; k <= n; k++) {\n ans += 1/k;\n}\nprint(ans);"}, {"source_code": "var num_oponents = readline();\nvar earns = [];\nfor (var t = 0; t < num_oponents; t++) {\n earns.push(1 / (num_oponents - t));\n}\nvar sum = 0;\nfor(var i=0;i {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const n = readInt(input)\n\n let sum = 0\n for(let i = 1; i <= n; i++) {\n sum += (1 / i)\n }\n\n wr(sum)\n}"}], "negative_code": [{"source_code": "var n = readline().split(' ');\nvar arr = 0;\nfor(var k = 1; k <= n; k++) {\n arr += 1/k;\n}\nprint(k);"}], "src_uid": "260666df22ee510fcce3ebdfbb8b71a2"} {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (a, b, c) {\n for (let i = 0; iNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var a = myconv(next(),6);\n var b = myconv(next(),6);\n var c = myconv(next(),6);\n var isNG = false;\n for(var j = 0; j < a.length; j++){\n if((a[j] != b[j] && (a[j] == c[j] || b[j] == c[j])) || (a[j] == c[j] && a[j] == b[j])){\n \n }else{\n isNG = true;\n break;\n }\n }\n if(isNG){\n output[i] = \"NO\";\n }else{\n output[i] = \"YES\";\n }\n \n }\n myout(myconv(output,9));\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr = [];\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 3 !== 0) {\n arr.push(str);\n c++;\n return;\n }\n\n let r = 'YES';\n for (let j = 0; j < arr[0].length; j++) {\n if (arr[0][j] !== str[j] && arr[1][j] !== str[j]) {\n r = 'NO';\n break;\n }\n }\n\n arr = [];\n console.log(r);\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let t = readline();\n \n while(t--)\n {\n let a = readline();\n let b = readline();\n let c = readline();\n let cnt = 0;\n \n for(let i = 0;i {\n const num = +lines[0]\n\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var a = myconv(next(),6);\n var b = myconv(next(),6);\n var c = myconv(next(),6);\n var isNG = false;\n for(var j = 0; j < a.length; j++){\n if(a[j] != b[j] && (a[j] == c[j] || b[j] == c[j])){\n \n }else{\n isNG = true;\n break;\n }\n }\n if(isNG){\n output[i] = \"NO\";\n }else{\n output[i] = \"YES\";\n }\n \n }\n myout(myconv(output,9));\n}"}], "src_uid": "08679e44ee5d3c3287230befddf7eced"} {"source_code": "var n = Number(readline());\n\nvar inp ;\n\nfor (var i = 0; i < n ; i++){\n inp = readline().split(' ').map(cur => Number(cur));\n var gl = (inp[1] - inp [2])*inp[0];\n var gu = (inp[1] + inp [2])*inp[0];\n var bl = inp[3] - inp [4];\n var bu = inp[3] + inp [4];\n \n((gu >= bu || (gu <= bu && gu >= bl)) && (gl <= bl || (gl <= bu && gl >= bl)))?print(\"YES\"):print(\"NO\");\n \n}", "positive_code": [{"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar tmp = nextIntArray();\n\t\tvar n = tmp[0];\n\t\tvar a = tmp[1];\n\t\tvar b = tmp[2];\n\t\tvar c = tmp[3];\n\t\tvar d = tmp[4];\n\t\tvar singleMin = (a - b) * n;\n\t\tvar singleMax = (a + b) * n;\n\t\tvar packMin = c - d;\n\t\tvar packMax = c + d;\n\t\tif(singleMin > packMax){\n\t\t\toutput[i] = \"NO\";\n\t\t}else if(singleMax < packMin){\n\t\t\toutput[i] = \"NO\";\n\t\t}else{\n\t\t\toutput[i] = \"YES\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "// your code goes here\nvar tst;\ntst = parseInt(readline());\n\nfor(var tc = 0; tc < tst; tc++)\n{\n var input = readline().split(\" \");\n var n = parseInt(input[0]);\n var a = parseInt(input[1]);\n var b = parseInt(input[2]);\n var c = parseInt(input[3]);\n var d = parseInt(input[4]);\n var minGrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n if(maxGrainWeight * n < minTotalWeight ||\n minGrainWeight * n > maxTotalWeight) print(\"No\");\n else print(\"Yes\");\n}"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(s) { return +s; }\n \nfor(var qq = 0; qq < t; qq++) {\n var line = readline().split(' ').map(mapper);\n var n = line[0];\n var a = line[1];\n var b = line[2];\n var c = line[3];\n var d = line[4];\n \n var minW = a - b;\n var maxW = a + b;\n \n var minC = c - d;\n var maxC = c + d;\n \n if (maxW * n < minC || minW * n > maxC) {\n print('No');\n } else {\n print('Yes');\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [n, a, b, c, d] = data.split(' ').map(Number);\n let x = (a - b) * n;\n let y = (a + b) * n;\n\n if ( (x >= c - d || y >= c - d) && (x <= c + d || y <= c + d) ) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n count++;\n});\n"}, {"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n \n \n// ************************ Code Start ***************************\n \nfunction main() {\n \n var Tc = parseInt(readline());\n while (Tc--) {\n var ar1 = readline().split(\" \").map((x) => parseInt(x));\n var n = ar1[0], a = ar1[1], b = ar1[2], c = ar1[3], d = ar1[4];\n if ((a - b) * n > c + d || (a + b) * n < c - d) print(\"NO\");\n else print(\"YES\");\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var range = readline();\n for(let r=0;r parseInt(x));\n var n = data[0];\n var x1 = data[1] - data[2];\n var x2 = data[1] + data[2];\n var y1 = data[3] + data[4];\n var y2 = data[3] - data[4];\n\n if(n * x1 > y1 || n * x2 < y2) {\n console.log(\"No\");\n } else {\n console.log(\"Yes\");\n }\n\n }\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n let args = thing.split(\" \").map(parseFloat)\n console.log(nastya(args[0], args[1], args[2], args[3], args[4]))\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n const iWeightLowerBound = (a - b) * n\n const iWeightUpperBound = (a + b) * n\n \n const totalWeightUpperBound = c + d\n const totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"No\";\n }\n \n return \"Yes\";\n \n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline().split(\" \");\n var n = parseInt(input[0]);\n var a = parseInt(input[1]);\n var b = parseInt(input[2]);\n var c = parseInt(input[3]);\n var d = parseInt(input[4]);\n var minGrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n\n if (\n maxGrainWeight * n < minTotalWeight ||\n minGrainWeight * n > maxTotalWeight\n ) {\n print(\"No\");\n } else print(\"Yes\");\n}\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = parseInt(readline());\n var b = parseInt(readline());\n var c = parseInt(readline());\n var d = parseInt(readline());\n var minGrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n var result = \"Yes\";\n if (\n maxGrainWeight * n < minTotalWeight ||\n minGrainWeight * n > maxTotalWeight\n )\n result = \"No\";\n print(result);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = parseInt(readline());\n var b = parseInt(readline());\n var c = parseInt(readline());\n var d = parseInt(readline());\n var mingrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n var result = \"No\";\n for (var i = mingrainWeight; i <= maxGrainWeight; i++) {\n if (i * n >= minTotalWeight && i <= maxTotalWeight) {\n result = \"Yes\";\n break;\n }\n }\n print(result);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = parseInt(readline());\n var b = parseInt(readline());\n var c = parseInt(readline());\n var d = parseInt(readline());\n var minGrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n\n if (\n maxGrainWeight * n < minTotalWeight ||\n minGrainWeight * n > maxTotalWeight\n ) {\n print(\"No\");\n } else print(\"Yes\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = parseInt(readline());\n var b = parseInt(readline());\n var c = parseInt(readline());\n var d = parseInt(readline());\n var minGrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n var result = \"Yes\";\n if (\n maxGrainWeight * n < minTotalWeight ||\n minGrainWeight * n > maxTotalWeight\n ) {\n result = \"No\";\n }\n print(result);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; i < t; tc++) {\n var n = parseInt(readline());\n var a = parseInt(readline());\n var b = parseInt(readline());\n var c = parseInt(readline());\n var d = parseInt(readline());\n var mingrainWeight = a - b;\n var maxGrainWeight = a + b;\n var minTotalWeight = c - d;\n var maxTotalWeight = c + d;\n var result = \"No\";\n for (var i = mingrainWeight; i <= maxGrainWeight; i++) {\n if (i * n >= minTotalWeight && i <= maxTotalWeight) {\n result = \"Yes\";\n break;\n }\n }\n print(result);\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n console.log(\"hello\", lines);\n \n\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n let args = thing.split(\" \").map(parseFloat)\n console.log(nastya(args))\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n const iWeightLowerBound = (a - b) * n\n const iWeightUpperBound = (a + b) * n\n \n const totalWeightUpperBound = c + d\n const totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"No\";\n }\n \n return \"Yes\";\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length; i++) {\n let thing = lines[i]\n console.log(thing.split(\" \"))\n }\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n let args = thing.split(\" \").map(parseFloat)\n console.log(nastya(args), args)\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n var iWeightLowerBound = (a - b) * n\n var iWeightUpperBound = (a + b) * n\n \n var totalWeightUpperBound = c + d\n var totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"No\";\n }\n \n return \"Yes\";\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length; i++) {\n console.log(\"lines[i]\")\n }\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n let args = thing.split(\" \").map(parseFloat)\n console.log(nastya(args), args)\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n const iWeightLowerBound = (a - b) * n\n const iWeightUpperBound = (a + b) * n\n \n const totalWeightUpperBound = c + d\n const totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"No\";\n }\n \n return \"Yes\";\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n console.log(nastya(thing.split(\" \").map(parseFloat)))\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n var iWeightLowerBound = (a - b) * n\n var iWeightUpperBound = (a + b) * n\n \n var totalWeightUpperBound = c + d\n var totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return false;\n }\n \n return true;\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n console.log(\"hello\", lines);\n \n console.log(lines[0])\n\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length; i++) {\n let thing = lines[i]\n console.log(thing.split(\" \").map(parseFloat))\n }\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n console.log(nastya(thing.split(\" \").map(parseFloat)))\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n var iWeightLowerBound = (a - b) * n\n var iWeightUpperBound = (a + b) * n\n \n var totalWeightUpperBound = c + d\n var totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"NO\";\n }\n \n return \"YES\";\n \n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n console.log(\"hello\", lines); \n})\n\n\nfunction nastya(n, a, b, c, d) {\n var iWeightLowerBound = (a - b) * n\n var iWeightUpperBound = (a + b) * n\n \n var totalWeightUpperBound = c + d\n var totalWeightLowerBound = c - d\n\n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return false;\n }\n\n return true;\n \n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n \n for (let i = 1; i < lines.length; i++) {\n let thing = lines[i]\n console.log(thing.split(\" \").map(parseInt))\n }\n\n})\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n \n console.log(nastya(11, 11, 10, 234, 2))\n for (let i = 1; i < lines.length - 1; i++) {\n let thing = lines[i]\n let args = thing.split(\" \").map(parseFloat)\n console.log(nastya(args))\n }\n \n})\n \n \nfunction nastya(n, a, b, c, d) {\n const iWeightLowerBound = (a - b) * n\n const iWeightUpperBound = (a + b) * n\n \n const totalWeightUpperBound = c + d\n const totalWeightLowerBound = c - d\n \n if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {\n return \"No\";\n }\n \n return \"Yes\";\n \n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var range = readline();\n for(let r=0;r parseInt(x));\n \n var x1 = data[1] - data[2];\n var x2 = data[1] + data[2];\n var y1 = data[3] + data[4];\n var y2 = data[3] - data[4];\n \n if(Math.floor(y1/x1) === data[0]) {\n console.log(\"Yes\");\n } else if(Math.ceil(y2/x2) === data[0]) {\n console.log(\"Yes\");\n } else {\n console.log(\"No\");\n }\n\n }\n \n}"}], "src_uid": "30cfce44a7a0922929fbe54446986748"} {"source_code": "var inp = +readline(), ip, count, i, ans, x;\n\nwhile (inp > 0) {\n inp--;\n ip = readline();\n count = ip === \"::\" ? 0 : ip.replace(/^::|::$/g, \"\").split(/::?/g).length;\n \n if (count < 8) {\n ip = ip.replace(\"::\", function() {\n var ins = \":\";\n for (i = 0; i < 8 - count; i++) {\n ins += \"0000:\";\n }\n return ins;\n });\n ip = ip.replace(/^:/, \"\").replace(/:$/, \"\");\n }\n\n ip = ip.split(\":\");\n ans = \"\";\n for (x in ip) {\n y = ip[x];\n while (y.length < 4) y = \"0\" + y;\n ans += y + \":\";\n }\n print(ans.substring(0, ans.length - 1));\n}\n", "positive_code": [{"source_code": "var addressCount = Number(readline());\nwhile (addressCount--) {\n var parts = readline().split(\":\");\n if (!parts[0].length) parts.shift();\n if (!parts[parts.length - 1].length) parts.pop();\n var index = parts.indexOf(\"\");\n if (index != -1) parts.splice(index, 1, ...new Array(9 - parts.length).fill(\"0000\"));\n print(parts.map(x => \"0\".repeat(4 - x.length) + x).join(\":\"));\n}\n"}, {"source_code": "var n = Number(readline());\nwhile (n--) {\n var str = readline();\n var arr = str.split(':');\n var result = '';\n var flag = false;\n for (var i = 0; i < arr.length; i++) {\n if (arr[i].length === 0 && !flag) {\n for (var j = 0; j < 9 - arr.length; j++) result += '0000:';\n flag = true;\n } else {\n if (arr[i].length === 4) result += ((arr[i]) + ':');\n else if (arr[i].length === 3) result += ('0' + arr[i]+':');\n else if (arr[i].length === 2) result += ('00' + arr[i]+':');\n else if (arr[i].length === 1) result += ('000' + arr[i]+':');\n else if (arr[i].length === 0) result += ('0000:');\n }\n }\n write(result.substr(0,result.length - 1)+'\\n');\n}\n"}], "negative_code": [], "src_uid": "20f69ee5f04c8cbb769be3ab646031ab"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const str1 = readLine();\n const str2 = readLine();\n let count = 0;\n\n const r1 = str1.split(\"\").sort().join(\"\");\n const r2 = str2.split(\"\").sort().join(\"\");\n\n if (r1 === r2) {\n for (let i = 0; i < str1.length; i++) {\n const [char1, char2] = [str1[i], str2[i]];\n if (char1 !== char2) count++;\n }\n if (count === 2) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n } else console.log(\"NO\");\n}\n", "positive_code": [{"source_code": "first = readline();\nsecond = readline();\ni = -1;\nvar pos = -1;\nvar flag = undefined;\n\nif (first.length != second.length) print('NO');\nelse {\n while (++i < first.length) {\n if (first[i] != second[i] && flag !== undefined) { flag = false; break; }\n if (first[i] != second[i] && pos === -1) pos = i;\n else if (first[i] != second[i] && pos > -1) {\n flag = (first[i] == second[pos] && second[i] == first[pos]);\n if (!flag) break;\n }\n }\n print(flag ? 'YES' : 'NO');\n}\n"}], "negative_code": [], "src_uid": "c659bdeda1c1da08cfc7f71367222332"} {"source_code": "var i, lb = [], counter = 0, max = [0], input = readline().split('');\n\nfunction update(){\n if (counter > max[0]) {\n max = [counter];\n } else if (counter && counter == max[0]) {\n max.push(counter);\n }\n counter = 0;\n}\n\nfor (i = 0; i < input.length; i++){\n if (input[i] === '(') {\n lb.push(i);\n } else {\n if (lb.length) {\n input[i] = '.';\n input[lb.pop()] = '.';\n }\n }\n}\n\nfor (i = 0; i < input.length; i++){\n if (input[i] === '.'){\n counter++;\n } else {\n update();\n }\n}\n\nif (counter) update();\n\nprint(max[0] + ' ' + max.length);\n", "positive_code": [{"source_code": "var i, j, lb = [], counter = 0, max = [0], input = readline().split('');\n\nfunction update(){\n if (counter > max[0]) {\n max = [counter];\n } else if (counter && counter == max[0]) {\n max.push(counter);\n }\n counter = 0;\n}\n\nfor (i=0; i=0){\n\t\t\tvar j = i-la[l]+1;\n\t\t\tif( j > max){\n\t\t\t\tmax = j;\n\t\t\t\tc=1;\n\t\t\t}else if( j==max){\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tfor(var k=l+1; la[k]!==undefined; k++){\n\t\t\tla[k]=undefined;\n\t\t}\n\t}\n\tif(l<0){\n\t\tl=0;\n\t\tla=[];\n\t}\n}\n\nif(max==0){\n\tc=1;\n}\nprint(max+' '+c);"}, {"source_code": "var line = readline();\n\n\nvar l = 0;\nvar la=[];\nvar max = 0;\nvar c = 0;\nfor(var i=0;i=0){\n\t\t\tvar j = i-la[l]+1;\n\t\t\tif( j > max){\n\t\t\t\tmax = j;\n\t\t\t\tc=1;\n\t\t\t}else if( j==max){\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tla[l+1] = undefined;\n\t}\n\tif(l<0){\n\t\tl=0;\n\t\tla=[];\n\t}\n}\n\nif(max==0){\n\tc=1;\n}\nprint(max+' '+c);"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var c, i, istack, len, match, max_count, max_len, min_i, mlp, s;\n\n s = readline();\n\n match = new Array(s.length);\n\n max_len = 0;\n\n max_count = 0;\n\n istack = [];\n\n for (i in s) {\n c = s[i];\n if (c === '(') {\n istack.push(+i);\n } else if (istack.length > 0) {\n mlp = istack.pop();\n min_i = match[mlp - 1] != null ? match[mlp - 1] : mlp;\n match[+i] = min_i;\n len = +i - min_i + 1;\n if (len > max_len) {\n max_len = len;\n max_count = 1;\n } else if (len === max_len) {\n max_count++;\n }\n }\n }\n\n if (max_count === 0) {\n print(\"0 1\");\n } else {\n print(max_len + ' ' + max_count);\n }\n\n}).call(this);\n"}], "negative_code": [{"source_code": "\nvar line = readline();\n\n\nvar l = 0;\nvar la=[];\nvar max = 0;\nvar c = 0;\nfor(var i=0;i=0){\n\t\t\tvar j = i-la[l]+1;\n\t\t\tif( j > max){\n\t\t\t\tmax = j;\n\t\t\t\tc=1;\n\t\t\t}else if( j==max){\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t}\n\tif(l<0){\n\t\tl=0;\n\t\tla=[];\n\t}\n}\n\nif(max==0){\n\tc=1;\n}\nprint(max+' '+c);"}, {"source_code": "var line = readline();\n\n\nvar l = 0;\nvar a = 0;\nvar ret1 = 0;\nvar ret2 = 0;\nfor( var i=0; iret1 ){\n\t\t\tret1=a;\n\t\t\tret2=1;\n\t\t}else if(a==ret1){\n\t\t\tret2++\n\t\t}\n\t\ta = 0;\n\t\tl = 0;\n\t}else{\n\t\ta++;\n\t}\n}\n\nif(l==0){\n\tif( a>ret1 ){\n\t\tret1=a;\n\t\tret2=1;\n\t}else if(a==ret1){\n\t\tret2++\n\t}\n}else if(l>0&&ret1==0){\n\tret1=0;\n\tret2=1;\n}\n\nprint(ret1+' '+ret2)"}, {"source_code": "\nvar line = readline();\n\nfunction go(line){\n\tvar l = 0;\n\tvar ret1 = 0;\n\tvar ret2 = 0;\n\tvar ll = [];\n\tfor( var i=0; i=0){\n\t\t\t\tvar j = i-ll.pop()+1;\n\t\t\t\tif(j>ret1){\n\t\t\t\t\tret1=j;\n\t\t\t\t\tret2=1;\n\t\t\t\t}else if(j==ret1){\n\t\t\t\t\tret2++;\n\t\t\t\t}\n\t\t\t//}\n\t\t\tl--;\n\t\t}\n\t\t\n\t\tif(l<0){\n\t\t\tl = 0;\n\t\t\tll=[];\n\t\t}\n\t}\n\treturn [ret1, ret2];\n}\n\nvar ret = go(line.split(''));\nif(ret[0]==0){\n\tret[1]=1;\n}\nprint(ret[0]+' '+ret[1]);"}, {"source_code": "\nvar line = readline();\n\nfunction go(line){\n\tvar l = 0;\n\tvar ret1 = 0;\n\tvar ret2 = 0;\n\tvar ll = [];\n\tfor( var i=0; i0){\n\t\t\t\tvar j = i-ll.pop()+1;\n\t\t\t\tif(j>ret1){\n\t\t\t\t\tret1=j;\n\t\t\t\t\tret2=1;\n\t\t\t\t}else if(j==ret1){\n\t\t\t\t\tret2++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tl--;\n\t\t}\n\t\t\n\t\tif(l<0){\n\t\t\tl = 0;\n\t\t\tll=[];\n\t\t}\n\t}\n\tprint(ll)\n\treturn [ret1, ret2];\n}\n\nline = line.split('');\nline.unshift('(');\nline.push(')');\nvar ret = go( line );\nret[0] -= 2;\nif(ret[0]==0){\n\tret[1]=1;\n}\nprint(ret[0]+' '+ret[1]);"}, {"source_code": "var i, lb = [0,0], max = 0, rpt = 0, input = readline();\n\nfor (i=0; i 0) {\n lb[0]--;\n lb[1]++;\n if (lb[0] === 0) {\n rpt++;\n if (lb[1] > max) {\n max = lb[1];\n lb[1] = 0;\n }\n }\n }\n }\n}\n\nif (max)\n print(max + ' ' + rpt);\nelse\n print('0 1');\n"}, {"source_code": "var i, lb = [0,0], max = 0, rpt = 0, input = readline();\n\nfunction closing(){\n rpt++;\n if (lb[1] > max) {\n max = lb[1];\n lb[1] = 0;\n }\n}\n\nfor (i=0; i 0) {\n lb[0]--;\n lb[1]+=2;\n } else {\n if (lb[1] > 0) {\n closing();\n }\n }\n }\n}\n\nif (lb[1] > 0) {\n closing();\n}\n\nif (max)\n print(max + ' ' + rpt);\nelse\n print('0 1');\n"}, {"source_code": "var i, lb = [0,0], max = 0, rpt = 0, input = readline();\n\nfunction closing(){\n rpt++;\n if (lb[1] > max) {\n max = lb[1];\n lb[1] = 0;\n }\n}\n\nfor (i=0; i 0) {\n lb[0]--;\n lb[1]++;\n } else {\n if (lb[1] > 0) {\n closing();\n }\n }\n }\n}\n\nif (lb[1] > 0) {\n closing();\n}\n\nif (max)\n print(max + ' ' + rpt);\nelse\n print('0 1');\n"}, {"source_code": "var i, lb = [0,0], max = 0, rpt = 0, input = readline();\n\nfor (i=0; i 0) {\n lb[0]--;\n lb[1]++;\n } else {\n rpt++;\n if (lb[1] > max) {\n max = lb[1];\n lb[1] = 0;\n }\n }\n }\n}\n\nif (lb[1] > 0) rpt++;\nif (lb[1] > max) max = lb[1];\n\nif (max)\n print(max + ' ' + rpt);\nelse\n print('0 1');\n"}], "src_uid": "91c3af92731cd7d406674598c0dcbbbc"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([num]) {\r\n const res =[]\r\n for(let i =0;ii && j<=2*i)str+=\")\";\r\n else if(j&1)str+=\"(\";\r\n else str+=\")\";\r\n }\r\n print(str);\r\n }\r\n}"}, {"source_code": " function readStringArray() {\r\n return readline().split(\" \");\r\n }\r\n function readNumArray() {\r\n return readStringArray().map(Number);\r\n }\r\n \r\n function main() {\r\n var cache = {\r\n 1: ['()']\r\n };\r\n function getSeq(n) {\r\n if (n == 1) {\r\n return cache[1]\r\n }\r\n if (!cache[n]) {\r\n var res = [];\r\n var prev = getSeq(n - 1);\r\n for (var c of prev) {\r\n res.push(\r\n '(' + c + ')',\r\n '()' + c\r\n )\r\n if (res.length > n) {\r\n res = res.slice(0, n);\r\n }\r\n }\r\n cache[n] = res;\r\n }\r\n return cache[n]\r\n }\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var n = +readline();\r\n var resArr = getSeq(n);\r\n for (var j = 0; j < resArr.length; j++) {\r\n print(resArr[j]);\r\n }\r\n }\r\n }\r\n \r\n \r\n main();"}, {"source_code": "function iamsogoodatgaming(n){\n var returnn = '';\n for(gamer = 0; gamer < n; gamer++){\n returnn += '(';\n }\n for(gamer2 = 0; gamer2 < n; gamer2++){\n returnn += ')';\n }\n return returnn;\n}\nlet stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i];\n\t for(j = 1; j <= a; j++){\n\t var ans = iamsogoodatgaming(j) + iamsogoodatgaming(a - j);\n\t console.log(ans);\n\t }\n\t}\n});\n\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n\t return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\nfunction main() {\r\n let Q = +(readline()); // Read Input\r\n\r\n for (let i = 0; i < Q; i++) {\r\n const N = parseInt(readline());\r\n\r\n const results = [];\r\n const stringArray = [];\r\n go (results, stringArray, N*2, 0, 0);\r\n\r\n results.forEach((result) => {\r\n console.log(result);\r\n });\r\n }\r\n}\r\n\r\nconst go = (results, stringArray, targetLength, currentLength, currentOpen) => {\r\n if (currentLength === targetLength) {\r\n results.push(stringArray.join(\"\"));\r\n return;\r\n }\r\n if (results.length === targetLength / 2) return;\r\n\r\n const remain = targetLength - currentLength;\r\n if (currentOpen + 1 <= remain) {\r\n stringArray[currentLength] = '(';\r\n go(results, stringArray, targetLength, currentLength + 1, currentOpen + 1);\r\n }\r\n if (currentOpen > 0) {\r\n stringArray[currentLength] = ')';\r\n go(results, stringArray, targetLength, currentLength + 1, currentOpen - 1);\r\n }\r\n}\r\n"}, {"source_code": "https://codeforces.com/problemset/problem/1574/A\n\n process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message) {\n if (process.env.NODE_ENV === \"debug\") {\n console.log(message);\n }\n}\n\n/**\n *\n * @param bracketPairCount integer\n * @return Array\n */\nconst generateBrackets = (bracketPairCount) => {\n //add () to the end or wrap the whole thing\n // generate a squence exaple input:3, possible sequences = AAA -> AAW -> AWA -> WAA -> AWW -> WAW ->\n // length 3 index 0: AAA, index 1: AAW, index 3\n // ADD as many wraps as there are indexes to the end and the beginning can just be adds\n\n let index = 0;\n const permutations = [];\n\n while (index < bracketPairCount) {\n let sequence = \"\";\n let amountOfAdds = bracketPairCount - index;\n let amountOfWraps = bracketPairCount - amountOfAdds;\n\n while(amountOfAdds > 0 || amountOfWraps > 0){\n if(amountOfAdds > 0){\n sequence += \"()\";\n amountOfAdds--;\n }else if(amountOfWraps > 0){\n sequence = \"(\" + sequence + \")\";\n amountOfWraps--;\n }\n }\n\n permutations.push(sequence);\n index++;\n }\n\n return permutations;\n}\n\n/**\n *\n * @param bracketPairCount Array\n */\nconst printBrackets = (listOfPossibleBracketPermutations) => {\n listOfPossibleBracketPermutations.forEach(permuatation => console.log(permuatation))\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0, 1);\n fileContents\n .map(generateBrackets)\n .forEach(printBrackets)\n}\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar set = new Set();\r\n\t\tvar list = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist.push(\"(\");\r\n\t\t\tlist.push(\")\");\r\n\t\t}\r\n\t\tset.add(myconv(list,0));\r\n\t\tfor(var i = 1; i < 2 * N; i++){\r\n\t\t\tif(list[i] == \")\" && list[i + 1] == \"(\"){\r\n\t\t\t\tvar tmp = list[i];\r\n\t\t\t\tlist[i] = list[i + 1];\r\n\t\t\t\tlist[i + 1] = tmp;\r\n\t\t\t\tset.add(myconv(list, 0));\r\n\t\t\t\tif(set.size == N){\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tset = Array.from(set);\r\n\t\tmyout(myconv(set, 9));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split(' ').map(Number);\n\t var x = a[0], y = a[1];\n\t if(y % x){\n\t console.log(0, 0);\n\t continue;\n\t }\n\t y /= x;\n\t console.log(1, y);\n\t}\n});\n\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0].split(' ').map(Number);\n var k = lines[1].split(' ').map(Number);\n var a = new Map();\n var length = 0;\n var flag = 0;\n for(var j = 0; j < n[0]; j++){\n if(a.has(k[j]) === false){\n a.set(k[j], j + 1);\n length++;\n }\n if(length == n[1]){\n flag = 1;\n break;\n }\n }\n if(flag === 1){\n console.log('YES');\n var answer = '';\n for(var [key, value] of a){\n answer += value + ' ';\n }\n console.log(answer);\n }else{\n console.log('NO');\n }\n});"}], "src_uid": "27b73a87fc30c77abb55784e2e1fde38"} {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n //console.log(\"Cases\",cases);\n for(var i=1;i<=cases;i++){\n //console.log(\"case \",i);\n var line2 = readline();\n var dims = line2.split(\" \");\n var r = parseInt(dims[0]);\n var g = parseInt(dims[1]);\n var b = parseInt(dims[2]);\n var w = parseInt(dims[3]);\n console.log(getresult(r,g,b,w));\n }\n \n}\n\nfunction getresult(r,g,b,w){\n var numOdds = 0;\n var min = Math.min(r,g,b);\n \n if(r%2 == 1){\n numOdds++;\n }\n if(g%2 == 1){\n numOdds++;\n }\n if(b%2 == 1){\n numOdds++;\n }\n if(numOdds == 3){\n return \"Yes\";\n }\n if(numOdds == 2){\n return (w%2 === 1 && min >= 1) ? \"Yes\" : \"No\";\n }\n if(numOdds == 1){\n return w%2 === 0 ? \"Yes\":\"No\";\n }\n if(numOdds === 0){\n return \"Yes\";\n }\n\n return \"No\"\n}\n\n\n", "positive_code": [{"source_code": "const isPossiblePalindrome = (input) => {\n var oddCount = 0;\n\n for (var j = 0; j < 4; j++) {\n if (input[j] % 2) {\n oddCount++;\n }\n }\n\n return oddCount <= 1;\n};\n\nconst main = () => {\n const N = Number(readline());\n\n for (var i = 0; i < N; i++) {\n var input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n if (isPossiblePalindrome(input)) {\n print(\"Yes\");\n continue;\n }\n\n var min = Math.min(input[0], input[1], input[2]);\n\n if (min === 0) {\n print(\"No\");\n continue;\n }\n\n input[0]--;\n input[1]--;\n input[2]--;\n input[3] += 3;\n\n if (isPossiblePalindrome(input)) {\n print(\"Yes\");\n continue;\n }\n\n if (min === 1) {\n print(\"No\");\n continue;\n }\n\n input[0]--;\n input[1]--;\n input[2]--;\n input[3] += 3;\n\n if (isPossiblePalindrome(input)) {\n print(\"Yes\");\n } else {\n print(\"No\");\n }\n }\n};\n\nmain();"}, {"source_code": "var readline=require(\"readline\");\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(inp);\n if(arr.length>1){\n var t=arr[arr.length-1].split(' ');\n for(var i=0;i1){\n var flag=0;\n for(var i=0;i1) console.log(\"No\");\n else console.log(\"Yes\");\n }\n }\n else console.log(\"Yes\"); \n }\n if(arr.length==(parseInt(arr[0])+1)) process.exit(0);\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const cases = +readLine()\n for(let i = 0; i < cases; i++) {\n console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')\n }\n}\n\nfunction possiblePali(balls) {\n for(let i = 0; i < 3; i++) {\n if(balls.filter(b => b&1).length < 2) return true\n const [r, g, b, w] = balls\n if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [countOdd, countEven, count0] = [0, 0, 0];\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n, index) => {\n n = parseInt(n);\n if (n % 2 === 0) countEven++;\n else countOdd++;\n if (n === 0 && index !== 3) count0++;\n return n;\n });\n if (count0 > 0 && countEven < 3) {\n console.log(\"No\");\n } else {\n if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {\n console.log(\"Yes\");\n } else console.log(\"No\");\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var r = tmp[0];\n var g = tmp[1];\n var b = tmp[2];\n var w = tmp[3];\n if(r > 0 && g > 0 && b > 0){\n\n for(var j = 0; j <= 3; j++){\n var list = [r - j, b - j, g - j, w + (j * 3)];\n var oddCount = 0;\n var isOK = false;\n var isNG = false;\n for(var k = 0; k < 4; k++){\n if(list[k] < 0){\n isNG = true;\n break;\n }\n if(list[k] % 2 == 1){\n oddCount++;\n }\n }\n if(isNG){\n break;\n }\n if(oddCount <= 1){\n output[i] = \"Yes\";\n isOK = true;\n break;\n }\n }\n if(output[i] == null){\n output[i] = \"No\";\n }\n }else{\n var odd = 0;\n odd += (r % 2 != 0) ? 1 : 0;\n odd += (g % 2 != 0) ? 1 : 0;\n odd += (b % 2 != 0) ? 1 : 0;\n odd += (w % 2 != 0) ? 1 : 0;\n if(odd > 1){\n output[i] = \"No\";\n }else{\n output[i] = \"Yes\";\n }\n }\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const counts = readLine().split(/\\s/).map(Number)\n const w = counts.pop()\n const oddCount = counts.reduce((acc, curr) => acc + (curr % 2), 0)\n if (w % 2 === 0) {\n console.log(oddCount === 2 ? 'No' : 'Yes')\n } else {\n switch (oddCount) {\n case 0:\n case 3:\n console.log('Yes')\n break\n case 1:\n console.log('No')\n break\n case 2:\n console.log(counts.every(count => count !== 0) ? 'Yes' : 'No')\n break\n }\n }\n }\n}\n\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\twhile (n--) {\n\t\tlet odd = 0,\n\t\t\teven = 0,\n\t\t\tzero = 0;\n\t\tlet c = readLine()\n\t\t\t.split(' ')\n\t\t\t.map((x, i) => {\n\t\t\t\tx = x >> 0;\n\t\t\t\tif (i < 3 && x === 0) zero++;\n\t\t\t\tif ((x & 1) === 1) {\n\t\t\t\t\todd++;\n\t\t\t\t} else {\n\t\t\t\t\teven++;\n\t\t\t\t}\n\t\t\t\treturn x;\n\t\t\t});\n\n\t\tif (even >= 3) {\n\t\t\tconsole.log('Yes');\n\t\t} else {\n\t\t\tif (zero > 0) console.log('No');\n\t\t\telse {\n\t\t\t\tif (odd > even) [odd, even] = [even, odd];\n\t\t\t\tif (even >= 3) {\n\t\t\t\t\tconsole.log('Yes');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('No');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [r,g,b,w] = ti(readline().split(' '));\n if(r%2 === 0 && g%2 === 0 && b%2 === 0){\n console.log('Yes');\n continue;\n }else if(r%2 === 0 && g%2 === 0 && b%2 !== 0 || r%2 === 0 && g%2 !== 0 && b%2 === 0 || r%2 !== 0 && g%2 === 0 && b%2 === 0){\n if(w%2 === 0)\n console.log('Yes');\n else\n console.log('No');\n continue;\n }else if(r%2 !== 0 && g%2 !== 0 && b%2 === 0 && b !== 0 || r%2 !== 0 && g%2 === 0 && b%2 !== 0 && g !== 0 || r%2 === 0 && g%2 !== 0 && b%2 !== 0 && r !== 0){\n if(w%2 !== 0)\n console.log('Yes');\n else\n console.log('No');\n continue;\n }else if(r%2 !== 0 && g%2 !== 0 && b%2 !== 0){\n console.log('Yes');\n continue;\n }\n else{\n console.log('No');\n }\n }\n}"}], "negative_code": [{"source_code": "const main = () => {\n const N = Number(readline());\n\n for (var i = 0; i < N; i++) {\n var input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n var min = Math.min(input[0], input[1], input[2]);\n\n if (input[0] === min) {\n input[0] = 0;\n input[1] -= min;\n input[2] -= min;\n } else if (input[1] === min) {\n input[0] -= min;\n input[1] = 0;\n input[2] -= min;\n } else {\n input[0] -= min;\n input[1] -= min;\n input[2] = 0;\n }\n\n input[3] += 3 * min;\n\n var oddCount = 0;\n var positiveCount = 0;\n\n for (var j = 0; j < 4; j++) {\n if (input[j] % 2) {\n oddCount++;\n }\n if (input[j] > 0) {\n positiveCount++;\n }\n }\n\n if (oddCount === 1 || positiveCount <= 1) {\n print(\"Yes\");\n } else {\n print(\"No\");\n }\n }\n};\n\nmain();\n"}, {"source_code": "const isPossiblePalindrome = (input) => {\n var oddCount = 0;\n var positiveCount = 0;\n\n for (var j = 0; j < 4; j++) {\n if (input[j] % 2) {\n oddCount++;\n }\n if (input[j] > 0) {\n positiveCount++;\n }\n }\n\n return oddCount === 1 || positiveCount <= 1;\n};\n\nconst main = () => {\n const N = Number(readline());\n\n for (var i = 0; i < N; i++) {\n var input = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n if (isPossiblePalindrome(input)) {\n print(\"Yes\");\n continue;\n }\n\n var min = Math.min(input[0], input[1], input[2]);\n\n if (input[0] === min) {\n input[0] = 0;\n input[1] -= min;\n input[2] -= min;\n } else if (input[1] === min) {\n input[0] -= min;\n input[1] = 0;\n input[2] -= min;\n } else {\n input[0] -= min;\n input[1] -= min;\n input[2] = 0;\n }\n\n input[3] += 3 * min;\n\n if (isPossiblePalindrome(input)) {\n print(\"Yes\");\n } else {\n print(\"No\");\n }\n }\n};\n\nmain();\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n const x = readline();\n var cases = parseInt(x);\n //console.log(\"Cases\",cases);\n for(var i=1;i<=cases;i++){\n //console.log(\"case \",i);\n var line2 = readline();\n var dims = line2.split(\" \");\n var r = parseInt(dims[0]);\n var g = parseInt(dims[1]);\n var b = parseInt(dims[2]);\n var w = parseInt(dims[3]);\n console.log(getresult(r,g,b,w));\n }\n \n}\n\nfunction getresult(r,g,b,w){\n var numOdds = 0;\n var min = Math.min(r,g,b);\n if(r%2 == 1){\n numOdds++;\n }\n if(g%2 == 1){\n numOdds++;\n }\n if(b%2 == 1){\n numOdds++;\n }\n if(numOdds == 3){\n return true;\n }\n if(numOdds == 2){\n return (w%2 === 1 && min >= 1) ? \"Yes\" : \"No\";\n }\n if(numOdds == 1){\n return w%2 === 0 ? \"Yes\":\"No\";\n }\n if(numOdds === 0){\n return \"Yes\";\n }\n\n return \"No\"\n}\n\nfunction minChanges(arr){\n var pathCovered = [];\n \n var dp = [];\n\n for(var i =0; i0){\n var leftElem = arr[row][col-1];\n if(leftElem == \"R\"){\n minValFromLeft = dp[row][col-1];\n }\n else{\n minValFromLeft = 1+dp[row][col-1];\n }\n }\n if(row>0){\n var topElem = arr[row-1][col];\n if(topElem == \"D\"){\n minValFromTop = dp[row-1][col];\n }\n else{\n minValFromTop = 1+dp[row-1][col];\n }\n }\n dp[row][col] = Math.min(minValFromLeft,minValFromTop);\n }\n }\n\n return dp[arr.length-1][cleng-1];\n}\n"}, {"source_code": "var readline=require(\"readline\");\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[];\nrl.on('line',function(inp){\n arr.push(inp);\n if(arr.length>1){\n var t=arr[arr.length-1].split(' ');\n for(var i=0;i1) console.log(\"No\");\n else console.log(\"Yes\");\n }\n if(arr.length==(parseInt(arr[0])+1)) process.exit(0);\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const cases = +readLine()\n for(let i = 0; i < cases; i++) {\n console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')\n }\n}\n\nfunction possiblePali(balls) {\n console.log(balls)\n\n for(let i = 0; i < 3; i++) {\n if(balls.filter(b => b&1).length < 2) return true\n const [r, g, b, w] = balls\n console.log({r, g, b, w})\n if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const cases = +readLine()\n for(let i = 0; i < cases; i++) {\n console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')\n }\n}\n\nfunction possiblePali(balls) {\n console.log(balls)\n\n for(let i = 0; i < 3; i++) {\n if(balls.filter(b => b&1).length < 2) return true\n const [r, g, b, w] = balls\n if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (a === 0 && b === 0 && c === 0 && d === 0) {\n console.log(\"Yes\");\n } else {\n if (a === 0 || b === 0 || c === 0 || d === 0) {\n console.log(\"No\");\n } else {\n const min = Math.min(a, b, c);\n a = a - min;\n b = b - min;\n c = c - min;\n d = d + 3 * min;\n let [countEven, countOdd] = [0, 0];\n if (a % 2 === 0) countEven++;\n else countOdd++;\n if (b % 2 === 0) countEven++;\n else countOdd++;\n if (c % 2 === 0) countEven++;\n else countOdd++;\n if (d % 2 === 0) countEven++;\n else countOdd++;\n\n if ((countOdd === 1 && countEven === 3) || countOdd === 4 || countEven === 4) console.log(\"Yes\");\n else console.log(\"No\");\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [countOdd, countEven, count0] = [0, 0, 0];\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n % 2 === 0) countEven++;\n else countOdd++;\n if (n === 0) count0++;\n return n;\n });\n if ((a === 0 || b === 0 || c === 0) && count0 < 3) {\n console.log(\"No\");\n } else {\n if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {\n console.log(\"Yes\");\n } else console.log(\"No\");\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (a === 0 && b === 0 && c === 0 && d === 0) {\n console.log(\"Yes\");\n } else {\n if (a === 0 || b === 0 || c === 0 || d === 0) {\n console.log(\"No\");\n } else {\n const min = Math.min(a, b, c);\n a = a - min;\n b = b - min;\n c = c - min;\n d = d + 3 * min;\n let [countEven, countOdd] = [0, 0];\n if (a % 2 === 0) countEven++;\n else countOdd++;\n if (b % 2 === 0) countEven++;\n else countOdd++;\n if (c % 2 === 0) countEven++;\n else countOdd++;\n if (d % 2 === 0) countEven++;\n else countOdd++;\n\n if (countOdd === 1 || countOdd === 4 || countEven === 4) console.log(\"Yes\");\n else console.log(\"No\");\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (a === 0 && b === 0 && c === 0 && d === 0) {\n console.log(\"YES\");\n } else {\n if (a === 0 || b === 0 || c === 0 || d === 0) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [countOdd, countEven, count0] = [0, 0, 0];\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n % 2 === 0) countEven++;\n else countOdd++;\n if (n === 0) count0++;\n return n;\n });\n if (count0 > 0 && count0 < 3) {\n console.log(\"No\");\n } else {\n if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {\n console.log(\"Yes\");\n } else console.log(\"No\");\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n if (a === 0 && b === 0 && c === 0) {\n console.log(\"Yes\");\n } else {\n if (a === 0 || b === 0 || c === 0) {\n console.log(\"No\");\n } else {\n const min = Math.min(a, b, c);\n a = a - min;\n b = b - min;\n c = c - min;\n d = d + 3 * min;\n let [countEven, countOdd] = [0, 0];\n if (a % 2 === 0) countEven++;\n else countOdd++;\n if (b % 2 === 0) countEven++;\n else countOdd++;\n if (c % 2 === 0) countEven++;\n else countOdd++;\n if (d % 2 === 0) countEven++;\n else countOdd++;\n\n if ((a === min && b === min && c === min) || countOdd === 1 || countEven === 4) console.log(\"Yes\");\n else console.log(\"No\");\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [countOdd, countEven, count0] = [0, 0, 0];\n let [a, b, c, d] = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n % 2 === 0) countEven++;\n else countOdd++;\n if (n === 0) count0++;\n return n;\n });\n if ((a === 0 || b === 0 || c === 0) && count0 !== 4) {\n console.log(\"No\");\n } else {\n if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {\n console.log(\"Yes\");\n } else console.log(\"No\");\n }\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\twhile (n--) {\n\t\tlet odd = 0,\n\t\t\teven = 0,\n\t\t\tzero = 0;\n\t\tlet c = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => {\n\t\t\t\tx = x >> 0;\n\t\t\t\tif (x === 0) zero++;\n\t\t\t\tif ((x & 1) === 1) {\n\t\t\t\t\todd++;\n\t\t\t\t} else {\n\t\t\t\t\teven++;\n\t\t\t\t}\n\t\t\t\treturn x;\n\t\t\t});\n\n\t\tlet s = c.reduce((a, c) => a + c);\n\n\t\tif (even >= 3) {\n\t\t\tconsole.log('Yes');\n\t\t} else {\n\t\t\tif (zero > 0) console.log('No');\n\t\t\telse {\n\t\t\t\tif (odd > even) [odd, even] = [even, odd];\n\t\t\t\tif (even >= 3) {\n\t\t\t\t\tconsole.log('Yes');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('No');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [r,g,b,w] = ti(readline().split(' '));\n if(r%2 === 0 && g%2 === 0 && b%2 === 0){\n console.log('Yes');\n continue;\n }else if(r%2 === 0 && g%2 === 0 && b%2 !== 0 || r%2 === 0 && g%2 !== 0 && b%2 === 0 || r%2 !== 0 && g%2 === 0 && b%2 === 0){\n console.log('Yes');\n continue;\n }else if(r%2 !== 0 && g%2 !== 0 && b%2 === 0 && b !== 0 || r%2 !== 0 && g%2 === 0 && b%2 !== 0 && g !== 0 || r%2 === 0 && g%2 !== 0 && b%2 !== 0 && r !== 0){\n console.log('yes');\n continue;\n }else{\n console.log('No');\n continue;\n }\n }\n}"}], "src_uid": "749a106d462555543c91753f00a5a479"} {"source_code": "function solve() {\r\n const [n, m] = readArray(Number);\r\n const matr = [];\r\n function canDraw(x, y) {\r\n if (x < 0 || x >= n) {\r\n return false;\r\n }\r\n if (y < 0 || y >= m) {\r\n return false;\r\n }\r\n return matr[x][y] === '0';\r\n }\r\n for (let i = 0; i < n; i++) {\r\n matr.push(read());\r\n }\r\n if (matr[0][0] === '1') {\r\n write(-1);\r\n return;\r\n }\r\n const ans = [];\r\n for (let i = n - 1; i > 0; i--) {\r\n for (let j = m - 1; j >= 0; j--) {\r\n if (matr[i][j] === '1') {\r\n ans.push([i, j + 1, i + 1, j + 1]);\r\n }\r\n }\r\n }\r\n for (let j = m - 1; j > 0; j--) {\r\n if (matr[0][j] === '1') {\r\n ans.push([1, j, 1, j + 1]);\r\n }\r\n }\r\n write(ans.length);\r\n for (const draw of ans) {\r\n write(draw.join(' '));\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n write(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nfunction write(value) {\r\n console.log(value);\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (isLocalStart) {\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n MEMORY_INDEX = 0;\r\n callback();\r\n });\r\n return;\r\n }\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n MEMORY_INDEX = 0;\r\n callback();\r\n}\r\n", "positive_code": [{"source_code": "function solve() {\r\n const [n, m] = readArray(Number);\r\n const matr = [];\r\n function canDraw(x, y) {\r\n if (x < 0 || x >= n) {\r\n return false;\r\n }\r\n if (y < 0 || y >= m) {\r\n return false;\r\n }\r\n return matr[x][y] === '0';\r\n }\r\n for (let i = 0; i < n; i++) {\r\n matr.push(read());\r\n }\r\n if (matr[0][0] === '1') {\r\n write(-1);\r\n return;\r\n }\r\n const ans = [];\r\n for (let i = n - 1; i > 0; i--) {\r\n for (let j = m - 1; j >= 0; j--) {\r\n if (matr[i][j] === '1') {\r\n ans.push([i, j + 1, i + 1, j + 1]); \r\n }\r\n }\r\n }\r\n for (let j = m - 1; j > 0; j--) {\r\n if (matr[0][j] === '1') {\r\n ans.push([1, j, 1, j + 1]);\r\n }\r\n }\r\n write(ans.length);\r\n for (const draw of ans) {\r\n write(draw.join(' '));\r\n }\r\n}\r\n\r\nfunction countBeatyMul(x, d, start) {\r\n if (x % d !== 0) {\r\n return 0;\r\n }\r\n if (isBeaty(x, d)) {\r\n return 1;\r\n }\r\n let ans = 0;\r\n for (let i = start; i <= Math.floor(Math.sqrt(x)); i++) {\r\n if (x % i !== 0) {\r\n continue;\r\n }\r\n const xDivI = Math.floor(x / i);\r\n if (xDivI < start) {\r\n continue;\r\n }\r\n if (isBeaty(i, d)) {\r\n ans += countBeatyMul(xDivI, d, i)\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction isBeaty(x, d) {\r\n return x % d === 0 && x % (d * d) !== 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n let t = parseInt(readline());\r\n let c =0;\r\n\r\n while(c parseInt(a));\r\n let tr = mat[0];\r\n let count =0;\r\n let arrd=[]\r\n while(count parseInt(b)); \r\n arrd.push(rows);\r\n count++;\r\n } \r\n let newarr = new Array();\r\n let co =0;\r\n for (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n }\r\n }\r\n }\r\n \r\n if(arrd[0][0] ==1){\r\n console.log(-1);\r\n }else{\r\n console.log(co);\r\n for (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n if(j - 1 >= 0) {\r\n console.log(i+1,j,i+1,j+1);\r\n\r\n }\r\n else {\r\n console.log(i,j+1,i+1,j+1);\r\n\r\n }\r\n }\r\n } \r\n }\r\n }\r\n c++\r\n }\r\n\r\n\r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nE.s2a = (arr)=>arr.map(a=>a.split('').map(c=>c=='0' ? 0 : 1))\n\n\nconst calc = (arr)=>{\n arr = E.s2a(arr);\n if (arr[0][0]==1)\n return false;\n let q = [];\n let n = arr.length;\n let m = arr[0].length;\n for (let i=n-1; i>=0; i--){\n for (let j=m-1; j>=0; j--){\n if (arr[i][j]){\n if (i)\n q.push({fromI: i-1, toI: i, fromJ: j, toJ: j});\n else\n q.push({fromI: i, toI: i, fromJ: j-1, toJ: j});\n }\n else\n q.push({fromI: i, toI: i, fromJ: j, toJ: j});\n }\n }\n return q\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [n, m] = ra();\n let arr = [];\n for (let i=0;i parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) arr.push(iInpArr1());\r\n const helper = (arr) => {\r\n let ans = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n for (let j = m - 1; j >= 0; j--) {\r\n if (arr[i][j] === 1) {\r\n if (i === 0) {\r\n if (j === 0) return false;\r\n ans.push([i + 1, j, i + 1, j + 1]);\r\n } else {\r\n if (j === 0) ans.push([i, j + 1, i + 1, j + 1]);\r\n else ans.push([i + 1, j, i + 1, j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n return ans;\r\n };\r\n let ans = helper(arr);\r\n if (ans === false) console.log(-1);\r\n else if (ans.length === 0) console.log(0);\r\n else {\r\n console.log(ans.length);\r\n for (let i = 0; i < ans.length; i++) console.log(ans[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, s) {\r\n if (s[0][0] === '1') return -1;\r\n let res = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n for (let j = m - 1; j >= 0; j--) {\r\n if (s[i][j] === '1') res.push(j === 0 ? [i, j + 1, i + 1, j + 1] : [i + 1, j, i + 1, j + 1]);\r\n }\r\n }\r\n return res.length + '\\n' + res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let testCases = Number(readline());\n for (let t = 0; t < testCases; t++) {\n let [m, n] = readline().split(\" \").map(Number);\n let board = [];\n\n let row = readline().split(\"\").map(Number);\n board.push(row);\n\n if (board[0][0] === 1) {\n console.log(-1);\n for (let i = 1; i < m; i++) {\n readline();\n }\n } else {\n for (let i = 1; i < m; i++) {\n let row = readline().split(\"\").map(Number);\n board.push(row);\n }\n console.log(m * n);\n for (let i = m - 1; i >= 0; i--) {\n for (let j = n - 1; j >= 0; j--) {\n if (board[i][j] === 1) {\n if (j === 0) {\n console.log(i - 1 + 1, j + 1, i + 1, j + 1);\n } else {\n console.log(i + 1, j - 1 + 1, i + 1, j + 1);\n }\n } else {\n console.log(i + 1, j + 1, i + 1, j + 1);\n }\n }\n }\n }\n }\n}\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n,m;\r\n var mat;\r\n for (var ti=0; ti < tests; ti++) {\r\n var nm = readline().split(' ').map(x=>parseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var row = readline().split('').map(x=>parseInt(x));\r\n mat.push(row);\r\n }\r\n if (mat[0][0]) {\r\n print('-1');\r\n continue;\r\n }\r\n\r\n var ans = [];\r\n for (var r = n-1; r >= 0; r--) {\r\n for (var c = m-1; c >= 1; c--) {\r\n if (mat[r][c]) {\r\n ans.push([r+1, c, r+1, c+1]);\r\n }\r\n }\r\n }\r\n\r\n for (var r = n-1; r > 0; r--) {\r\n if (mat[r][0]) {\r\n ans.push([r, 1, r+1, 1]);\r\n }\r\n }\r\n\r\n print(ans.length);\r\n for (var i = 0; i < ans.length; i++) {\r\n print(ans[i].join(' '));\r\n }\r\n }"}, {"source_code": "function solve() {\r\n const [n, m] = readArray(Number);\r\n const matr = [];\r\n function canDraw(x, y) {\r\n if (x < 0 || x >= n) {\r\n return false;\r\n }\r\n if (y < 0 || y >= m) {\r\n return false;\r\n }\r\n return matr[x][y] === '0';\r\n }\r\n for (let i = 0; i < n; i++) {\r\n matr.push(read());\r\n }\r\n if (matr[0][0] === '1') {\r\n write(-1);\r\n return;\r\n }\r\n const ans = [];\r\n for (let i = n - 1; i > 0; i--) {\r\n for (let j = m - 1; j >= 0; j--) {\r\n if (matr[i][j] === '1') {\r\n ans.push([i, j + 1, i + 1, j + 1]);\r\n }\r\n }\r\n }\r\n for (let j = m - 1; j > 0; j--) {\r\n if (matr[0][j] === '1') {\r\n ans.push([1, j, 1, j + 1]);\r\n }\r\n }\r\n write(ans.length);\r\n for (const draw of ans) {\r\n write(draw.join(' '));\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n write(e);\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\nfunction write(value) {\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n console.log(ANS);\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (isLocalStart) {\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n callback();\r\n });\r\n return;\r\n }\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n callback();\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n let t = parseInt(readline());\r\n let c =0;\r\n\r\n while(c parseInt(a));\r\n let tr = mat[0];\r\n let count =0;\r\n let arrd=[]\r\n while(count parseInt(b)); \r\n arrd.push(rows);\r\n count++;\r\n }\r\n\r\n\r\n \r\nlet newarr = new Array();\r\n// let x =[]\r\n// for (var o = 0; o < newarr.length; o++) {\r\n// newarr[o] = new Array(5).fill(0);\r\n// }\r\n\r\n// let m =0;\r\n// let n =0;\r\n// let co =0;\r\nlet co =0;\r\n\r\n\r\n\r\nfor (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n }\r\n }\r\n}\r\nconsole.log(co);\r\nif(arrd[0][0] ==1){\r\n console.log(-1);\r\n}else{\r\n for (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n if(j - 1 >= 0) {\r\n console.log(i+1,j,i+1,j+1);\r\n // cout << i + 1 << \" \" << j << \" \";\r\n // cout << i + 1 << \" \" << j + 1 << endl;\r\n }\r\n else {\r\n console.log(i,j+1,i+1,j+1)\r\n // cout << i << \" \" << j + 1 << \" \" ;\r\n // cout << i + 1 << \" \" << j + 1 << endl;\r\n }\r\n }\r\n } \r\n }\r\n}\r\n// console.log(newarr);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++\r\n }\r\n\r\n\r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n let t = parseInt(readline());\r\n let c =0;\r\n\r\n while(c parseInt(a));\r\n let tr = mat[0];\r\n let count =0;\r\n let arrd=[]\r\n while(count parseInt(b)); \r\n arrd.push(rows);\r\n count++;\r\n }\r\n\r\n\r\n \r\nlet newarr = new Array();\r\n// let x =[]\r\n// for (var o = 0; o < newarr.length; o++) {\r\n// newarr[o] = new Array(5).fill(0);\r\n// }\r\n\r\n// let m =0;\r\n// let n =0;\r\n// let co =0;\r\nlet co =0;\r\n\r\n\r\n\r\nfor (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n }\r\n }\r\n}\r\nconsole.log(co);\r\nif(arrd[0][0] ==1){\r\n console.log(-1);\r\n}else{\r\n for (var i = arrd.length-1; i>=0 ; i--) {\r\n for (var j = arrd[0].length-1; j >=0 ; j--) {\r\n if(arrd[i][j]==1){\r\n co++;\r\n if(j - 1 >= 0) {\r\n console.log(i+1,\" \",j,\" \",i+1,\" \",j+1);\r\n // cout << i + 1 << \" \" << j << \" \";\r\n // cout << i + 1 << \" \" << j + 1 << endl;\r\n }\r\n else {\r\n console.log(i,\" \",j+1,\" \",i+1,\" \",j+1)\r\n // cout << i << \" \" << j + 1 << \" \" ;\r\n // cout << i + 1 << \" \" << j + 1 << endl;\r\n }\r\n }\r\n } \r\n }\r\n}\r\n// console.log(newarr);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n c++\r\n }\r\n\r\n\r\n \r\n}\r\n\r\n//type input.txt | node code.js"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nE.s2a = (arr)=>arr.map(a=>a.split('').map(c=>c=='0' ? 0 : 1))\n\n\nconst calc = (arr)=>{\n arr = E.s2a(arr);\n if (arr[0][0]==1)\n return false;\n let q = [];\n let n = arr.length;\n let m = arr[0].length;\n for (let i=n-1; i>=0; i--){\n for (let j=m-1; j>=0; j--){\n if (arr[i][j]){\n if (i)\n q.push({fromI: i-1, toI: i, fromJ: j, toJ: j});\n else\n q.push({fromI: i, toI: i, fromJ: j-1, toJ: j});\n }\n else\n q.push({fromI: i, toI: i, fromJ: j, toJ: j});\n }\n }\n return q\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let [n, m] = ra();\n let arr = [];\n for (let i=0;i{\r\n if(!b) return a;\r\n return gcd(b,a%b);\r\n }\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [a,b,c,d]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let x=a*b;\r\n let ansx=-1,ansy=-1;\r\n for(let i=a+1;i<=c;i++)\r\n {\r\n let z=gcd(i,x);\r\n let num=x/z;\r\n let k=Math.floor((b+1)/num);\r\n if(k*num {\r\n var _cnt$get2;\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n while (n % i === 0) {\r\n var _cnt$get;\r\n cnt.set(i, ((_cnt$get = cnt.get(i)) !== null && _cnt$get !== void 0 ? _cnt$get : 0) + 1);\r\n n /= i;\r\n }\r\n }\r\n }\r\n if (n > 1) cnt.set(n, ((_cnt$get2 = cnt.get(n)) !== null && _cnt$get2 !== void 0 ? _cnt$get2 : 0) + 1);\r\n };\r\n calc(a);\r\n calc(b);\r\n const p = [...cnt.entries()];\r\n const [A, B, C, D] = [a, b, c, d].map(BigInt);\r\n const t = A * B;\r\n const check = (a, b, c) => {\r\n if (c > a && c <= b) return c;\r\n let x = a / c;\r\n if (x * c <= a) x++;\r\n if (x * c <= b) return x * c;\r\n return -1n;\r\n };\r\n let res = [-1n, -1n];\r\n const dfs = (i, num) => {\r\n if (i === p.length) {\r\n let a = check(A, C, num),\r\n b = check(B, D, t / num);\r\n if (a !== -1n && b !== -1n) {\r\n res = [a, b];\r\n return true;\r\n }\r\n return false;\r\n }\r\n const [x, y] = p[i];\r\n for (let j = 0; j <= y; j++) {\r\n if (dfs(i + 1, num * BigInt(x ** j))) return true;\r\n }\r\n };\r\n dfs(0, 1n);\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [a, b, c, d] = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(a, b, c, d).join(' ')\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(a, b, c, d) {\r\n // const af = factors(a)\r\n // const bf = factors(b)\r\n// console.log(af, bf)\r\n const prod = a * b\r\n const pf = factors(prod)\r\n// console.log(pf)\r\n for (let i = 0; i < pf.length; i++) {\r\n const k1 = pf[i]\r\n const k2 = prod / pf[i]\r\n// for (let i = 0; i < af.length; i++) {\r\n// for (let j = 0; j < bf.length; j++) {\r\n// const k1 = af[i] * bf[j]\r\n// const k2 = prod / k1\r\n const r1 = has(k1, a, c)\r\n const r2 = has(k2, b, d)\r\n// console.log(k1, k2, r1, r2)\r\n if (r1 < 0 || r2 < 0) continue\r\n return [r1, r2]\r\n// }\r\n }\r\n return [-1, -1]\r\n}\r\nfunction has(k, a, b) {\r\n // (a, b]\r\n let r = Math.ceil(a / k) * k\r\n if (r === a) r += k\r\n return r <= b ? r : -1\r\n}\r\nfunction factors(n) {\r\n const limit = Math.ceil(Math.sqrt(n))\r\n const r = []\r\n for (let i = 1; i < limit; i++) {\r\n if (!(n % i)) {\r\n r.push(i, n / i)\r\n }\r\n }\r\n if (!(n % limit)) r.push(limit)\r\n return r\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [a, b, c, d] = rns();\r\n const cnt = new Map();\r\n const calc = n => {\r\n var _cnt$get2;\r\n for (let i = 2; i <= n / i; i++) {\r\n if (n % i === 0) {\r\n while (n % i === 0) {\r\n var _cnt$get;\r\n cnt.set(i, ((_cnt$get = cnt.get(i)) !== null && _cnt$get !== void 0 ? _cnt$get : 0) + 1);\r\n n /= i;\r\n }\r\n }\r\n }\r\n if (n > 1) cnt.set(n, ((_cnt$get2 = cnt.get(n)) !== null && _cnt$get2 !== void 0 ? _cnt$get2 : 0) + 1);\r\n };\r\n calc(a);\r\n calc(b);\r\n const p = [...cnt.entries()];\r\n const [A, B, C, D] = [a, b, c, d].map(BigInt);\r\n const t = A * B;\r\n const check = (a, b, c) => {\r\n if (c > a && c <= b) return c;\r\n let x = a / c;\r\n if (x * c <= a) x++;\r\n if (x * c <= b) return x * c;\r\n return -1n;\r\n };\r\n let res = [-1n, -1n];\r\n const dfs = (i, num) => {\r\n if (i === p.length) {\r\n if (num > t) return false;\r\n let a = check(A, C, num),\r\n b = check(B, D, t / num);\r\n if (a !== -1n && b !== -1n) {\r\n res = [a, b];\r\n return true;\r\n }\r\n return false;\r\n }\r\n const [x, y] = p[i];\r\n for (let j = 0; j <= y; j++) {\r\n if (dfs(i + 1, num * BigInt(x ** j))) return true;\r\n }\r\n };\r\n dfs(0, 1n);\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c, d] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c, d).join(' ')\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c, d) {\n const af = factors(a)\n const bf = factors(b)\n const prod = a * b\n for (let i = 0; i < af.length; i++) {\n for (let j = 0; j < bf.length; j++) {\n const k1 = af[i] * bf[j]\n const k2 = prod / k1\n const r1 = has(k1, a, c)\n const r2 = has(k2, b, d)\n if (r1 < 0 || r2 < 0) continue\n return [r1, r2]\n }\n }\n return [-1, -1]\n}\nfunction has(k, a, b) {\n // (a, b]\n let r = Math.ceil(a / k) * k\n if (r === a) r += k\n return r <= b ? r : -1\n}\nfunction factors(n) {\n const limit = Math.floor(Math.sqrt(n))\n const r = []\n for (let i = 1; i < limit; i++) {\n if (!(n % i)) {\n r.push(i, n / i)\n }\n }\n if (!(n % limit)) r.push(limit)\n return r\n}\n"}], "src_uid": "84c60293d487e2c2ecee38a2fcf63b10"} {"source_code": "var $ = \"abcdefghijklmnopqrstuvwxyz\";\nvar a = [];\nvar n = parseInt(readline());\nfor(var i=0;i<26;i++) a[i] = 0;\nvar c = []\nfor(var i=0;i<26;i++) {\n var ddd = [];\n for(var j=0;j<26;j++) ddd[j] = 0;\n c[i] = ddd;\n}\nfor(var i=0;i ans) ans = a[i];\n for(var j=i+1;j<26;j++) {\n var tmp = a[i] + a[j] + c[i][j];\n if(tmp > ans) ans = tmp;\n }\n}\nprint(ans);\n// var ss = \"\";\n// for(var i=0;i<26;i++) ss += \" \" + a[i];\n// print(ss);\n// for(var i=0;i<26;i++) {\n// ss = \"\";\n// for(var j=0;j<26;j++) {\n// ss += \" \" + c[i][j];\n// }\n// print(ss);\n// }\n", "positive_code": [{"source_code": "var n = parseInt(readline()),\n lettersUsed = [],\n pairs = [],\n words = [],\n res = 0,\n currRes = 0;\n\nfor (var i = 0; i < n; i++) {\n var word = readline();\n var isGood = true,\n let1 = word.charAt(0),\n let2 = '';\n for (var j = 1; j < word.length; j++) {\n if (word.charAt(j) != let1) {\n if (let2 == '') let2 = word.charAt(j);\n else if (word.charAt(j) != let2) {\n isGood = false;\n break;\n }\n }\n }\n if (isGood) {\n words.push(word);\n if ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);\n if ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);\n }\n}\n\nif (lettersUsed.length > 1) {\n\tfor (var i = 0; i < lettersUsed.length - 1; i++) {\n\t for (var j = i+1; j < lettersUsed.length; j++) {\n\t pairs.push( [lettersUsed[i], lettersUsed[j]] );\n\t }\n\t}\n} else {\n\tpairs.push( [lettersUsed[0], lettersUsed[0]] );\n}\n\nfor (var i = 0; i < pairs.length; i++) {\n currRes = 0;\n for (var j = 0; j < words.length; j++) {\n var good = true;\n for (var k = 0; k < words[j].length; k++) {\n if (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {\n good = false;\n break;\n }\n }\n if (good) currRes += words[j].length;\n }\n if (currRes > res) res = currRes;\n}\n\nprint(res);"}], "negative_code": [{"source_code": "var n = parseInt(readline()),\n lettersUsed = [],\n pairs = [],\n words = [],\n res = 0,\n currRes = 0;\n\nfor (var i = 0; i < n; i++) {\n var word = readline();\n var isGood = true,\n let1 = word.charAt(0),\n let2 = '';\n for (var j = 1; j < word.length; j++) {\n if (word.charAt(j) != let1) {\n if (let2 == '') let2 = word.charAt(j);\n else if (word.charAt(j) != let2) {\n isGood = false;\n break;\n }\n }\n }\n if (isGood) {\n words.push(word);\n if ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);\n if ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);\n }\n}\n\nfor (var i = 0; i < lettersUsed.length - 1; i++) {\n for (var j = i+1; j < lettersUsed.length; j++) {\n pairs.push( [lettersUsed[i], lettersUsed[j]] );\n }\n}\n\nfor (var i = 0; i < pairs.length; i++) {\n currRes = 0;\n for (var j = 0; j < words.length; j++) {\n var good = true;\n for (var k = 0; k < words[j].length; k++) {\n if (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {\n good = false;\n break;\n }\n }\n if (good) currRes += words[j].length;\n }\n if (currRes > res) res = currRes;\n}\n\nprint(res);"}, {"source_code": "var n = parseInt(readline()),\n\tlettersUsed = [],\n\tpairs = [],\n\twords = [],\n\tres = 0,\n\tcurrRes = 0;\n\nfor (var i = 0; i < n; i++) {\n\tvar word = readline();\n\tvar isGood = true,\n\t\tlet1 = word.charAt(0),\n\t\tlet2 = '';\n\tfor (var j = 1; j < word.length; j++) {\n\t\tif (word.charAt(i) != let1) {\n\t\t\tif (let2 == '') let2 = word.charAt(i);\n\t\t\telse if (word.charAt(i) != let2) {\n\t\t\t\tisGood = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (isGood) {\n\t\twords.push(word);\n\t\tif ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);\n\t\tif ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);\n\t}\n}\n\nfor (var i = 0; i < lettersUsed.length - 1; i++) {\n\tfor (var j = i+1; j < lettersUsed.length; j++) {\n\t\tpairs.push( [lettersUsed[i], lettersUsed[j]] );\n\t}\n}\n\nfor (var i = 0; i < pairs.length; i++) {\n\tcurrRes = 0;\n\tfor (var j = 0; j < words.length; j++) {\n\t\tvar good = true;\n\t\tfor (var k = 0; k < words[j].length; k++) {\n\t\t\tif (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {\n\t\t\t\tgood = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (good) currRes += words[j].length;\n\t}\n\tif (currRes > res) res = currRes;\n}\n\nprint(res);"}], "src_uid": "d8a93129cb5e7f05a5d6bbeedbd9ef1a"} {"source_code": "const coords = {};\nconst nbrs = {};\nconst points = require(\"fs\").readFileSync(0, \"utf8\").split(\"\\n\").slice(1).filter(Boolean).map(point => {\n let [x,y] = point.split(\" \").map(n => parseInt(n, 10));\n const str = `${x} ${y}`;\n coords[str] = [x,y];\n nbrs[str] = [\n `${x+1} ${y}`,`${x-1} ${y}`,`${x} ${y-1}`,`${x} ${y+1}`\n ];\n return str;\n});\n\nconst map = {};\nfor(let point of points) {\n map[ point ] = [];\n for(ne of nbrs[point]) {\n if(map[ne]) {\n map[ne].push(point);\n map[point].push(ne);\n }\n }\n}\n\nlet best = {}, wset = [];\nfor(let point of points) {\n if(map[point].length < 4) {\n wset.push(point);\n best[point] = nbrs[point].find(pt => !map[point].includes(pt));\n }\n}\n\nwhile(wset.length) {\n wset = wset.map(point => nbrs[point].filter(ne => {\n if(map[ne] && !best[ne]) {\n best[ne] = best[point];\n return true;\n }\n })).flat(1);\n}\n\nfor(let point of points) {\n console.log(best[point]);\n}\n", "positive_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])\n\nclass GDB {\n constructor(points){\n let XA = this.XA = {};\n let YA = this.YA = {};\n for (let p of points){\n let [x, y] = p;\n if (!XA[x]) XA[x] = new Set();\n XA[x].add(y);\n if (!YA[y]) YA[y] = new Set();\n YA[y].add(x);\n }\n //console.log('XA', XA)\n //console.log('YA', YA)\n /**\n for (let x in XA){\n XA[x].sort((a, b)=>a-b);\n }\n for (let y in YA){\n YA[y].sort((a, b)=>a-b);\n }*/\n }\n getExcluded(point){\n this.cache = new Map();\n let [x, y] = point;\n let bestPoint = [1e6, 1e6];\n let bestDist = getDist(point, bestPoint)\n for (let d=0; d{\n let d = getDist(point, p);\n if (dp[0]+';'+p[1];\nconst calc = (points)=>{\n let ansMap = new Map();\n for (let point of points){\n ansMap.set(p2s(point), null);\n }\n let queue = [], qi = 0;\n for (let point of points){\n let [x, y] = point;\n for (let di=0; di<4; di++){\n let dPoint = [x+dx[di], y+dy[di]];\n if (!ansMap.has(p2s(dPoint))){\n ansMap.set(p2s(point), dPoint);\n queue.push(point);\n }\n }\n }\n while (qiansMap.get(p2s(p)))\n};\n\nfunction main() {\n let T = 1 || +readline() /// DISABLE T\n while (T--){\n let n = +readline();\n let arr = []; // [x, y]\n for (let i=0; ip.join(' ')).join('\\n'));\n }\n}\n\nE.calc = calc;"}], "negative_code": [{"source_code": "const coords = [];\nconst points = require(\"fs\").readFileSync(0, \"utf8\").split(\"\\n\").slice(1).filter(Boolean).map(point => {\n let [x,y] = point.split(\" \").map(n => parseInt(n, 10));\n const str = `${x},${y}`;\n coords[str] = [x,y];\n return str;\n});\n\nconst nbrs = (pt) => {\n let [x,y] = coords[pt];\n return [`${x+1}${y}`,`${x-1}${y}`,`${x}${y-1}`,`${x}${y+1}`];\n}\n\nconst map = {};\nfor(let point of points) {\n map[ point ] = [];\n for(ne of nbrs(point)) {\n if(map[ne]) {\n map[ne].push(point);\n map[point].push(ne);\n }\n }\n}\n\nlet best = {}, wset = [];\nfor(let point of points) {\n if(map[point].length < 4) {\n wset.push(point);\n best[point] = nbrs(point).find(pt => !map[point].includes(pt));\n }\n}\n\nwhile(wset.length) {\n wset = wset.map(point => nbrs(point).filter(ne => {\n if(map[ne] && !best[ne]) {\n best[ne] = best[point];\n return true;\n }\n })).flat(1);\n}\n\nfor(let point of points) {\n console.log(coords[point][0], coords[point][1]);\n}\n"}, {"source_code": "const points = require(\"fs\").readFileSync(0, \"utf8\").split(\"\\n\").slice(1).filter(Boolean).map(point => {\n let [x,y] = point.split(\" \").map(n => parseInt(n, 10));\n return x + (y << 18);\n});\n\nconst map = {};\nfor(let point of points) {\n map[ point ] = [];\n for(ne of [point-1, point+1, point - (1<<18), point + (1<<18)]) {\n if(map[ne]) {\n map[ne].push(point);\n map[point].push(ne);\n }\n }\n}\n\nlet best = {}, wset = [];\nfor(let point of points) {\n if(map[point].length < 4) {\n wset.push(point);\n best[point] = [point-1,point+1,point-(1<<18),point+(1<<18)].find(pt => !map[point].includes(pt));\n }\n}\n\nwhile(wset.length) {\n wset = wset.map(point => [point-1,point+1,point-(1<<18),point+(1<<18)].filter(ne => {\n if(map[ne] && !best[ne]) {\n best[ne] = best[point];\n return true;\n }\n })).flat(1);\n}\n\nfor(let point of points) {\n console.log(best[point] & ((1<<18) - 1), best[point] >> 18);\n}\n"}, {"source_code": "const points = require(\"fs\").readFileSync(0, \"utf8\").split(\"\\n\").slice(1).filter(Boolean).map(point => {\n let [x,y] = point.split(\" \").map(n => parseInt(n, 10));\n return x + (y << 16);\n});\n\nconst map = {};\nfor(let point of points) {\n map[ point ] = [];\n for(ne of [point-1, point+1, point - (1<<16), point + (1<<16)]) {\n if(map[ne]) {\n map[ne].push(point);\n map[point].push(ne);\n }\n }\n}\n\nlet best = {}, wset = [];\nfor(let point of points) {\n if(map[point].length < 4) {\n wset.push(point);\n best[point] = [point-1,point+1,point-(1<<16),point+(1<<16)].find(pt => !map[point].includes(pt));\n }\n}\n\nwhile(wset.length) {\n wset = wset.map(point => [point-1,point+1,point-(1<<16),point+(1<<16)].filter(ne => {\n if(map[ne] && !best[ne]) {\n best[ne] = best[point];\n return true;\n }\n })).flat(1);\n}\n\nfor(let point of points) {\n console.log(best[point] & ((1<<16) - 1), best[point] >> 16);\n}\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])\n\nclass GDB {\n constructor(points){\n let XA = this.XA = {};\n let YA = this.YA = {};\n for (let p of points){\n let [x, y] = p;\n if (!XA[x]) XA[x] = new Set();\n XA[x].add(y);\n if (!YA[y]) YA[y] = new Set();\n YA[y].add(x);\n }\n //console.log('XA', XA)\n //console.log('YA', YA)\n /**\n for (let x in XA){\n XA[x].sort((a, b)=>a-b);\n }\n for (let y in YA){\n YA[y].sort((a, b)=>a-b);\n }*/\n }\n getExcluded(point){\n this.cache = new Map();\n let [x, y] = point;\n let bestPoint = [1e6, 1e6];\n let bestDist = getDist(point, bestPoint)\n for (let d=0; d{\n let d = getDist(point, p);\n if (d{\n let gdb = new GDB(points);\n let ans = [];\n for (let point of points){\n ans.push(gdb.getExcluded(point))\n }\n return ans;\n};\n\nfunction main() {\n let T = 1 || +readline() /// DISABLE T\n while (T--){\n let n = +readline();\n let arr = []; // [x, y]\n for (let i=0; ip.join(' ')).join('\\n'));\n }\n}\n\nE.calc = calc;"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])\n\nclass GDB {\n constructor(points){\n let XA = this.XA = {};\n this.cache = new Map();\n let YA = this.YA = {};\n for (let p of points){\n let [x, y] = p;\n if (!XA[x]) XA[x] = new Set();\n XA[x].add(y);\n if (!YA[y]) YA[y] = new Set();\n YA[y].add(x);\n }\n //console.log('XA', XA)\n //console.log('YA', YA)\n /**\n for (let x in XA){\n XA[x].sort((a, b)=>a-b);\n }\n for (let y in YA){\n YA[y].sort((a, b)=>a-b);\n }*/\n }\n getExcluded(point){\n let [x, y] = point;\n let bestPoint = [1e6, 1e6];\n let bestDist = getDist(point, bestPoint)\n for (let d=0; d{\n let d = getDist(point, p);\n if (d{\n let gdb = new GDB(points);\n let ans = [];\n for (let point of points){\n ans.push(gdb.getExcluded(point))\n }\n return ans;\n};\n\nfunction main() {\n let T = 1 || +readline() /// DISABLE T\n while (T--){\n let n = +readline();\n let arr = []; // [x, y]\n for (let i=0; ip.join(' ')).join('\\n'));\n }\n}\n\nE.calc = calc;"}], "src_uid": "b021a3c7ae119671c81c51da7cfabdb3"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n arr.unshift(0);\r\n let cost = 0;\r\n for(let i=1;i<=n;i++){\r\n if(arr[i]===1) continue;\r\n for(let j=i;j<=n;j+=i){\r\n if(arr[j]==-1) continue;\r\n if(arr[j]!==1){\r\n cost+=i;\r\n arr[j] = -1;\r\n }\r\n else break;\r\n }\r\n }\r\n console.log(cost);\r\n }\r\n};\r\nsolve();", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let bin = readline().split('').map(Number);\r\n let R = bin.map(x => x === 1 ? 0 : 1);\r\n let T = bin;\r\n let toRemove = R.filter(x => x === 1).length;\r\n let cost = 0;\r\n\r\n let curr = 1;\r\n let p = 1;\r\n let removed = 0;\r\n\r\n while (removed < toRemove) {\r\n if (R[p-1] === 1) {\r\n R[p-1] = 0;\r\n removed++;\r\n cost += curr;\r\n } else if (T[p-1] === 1) {\r\n curr += 1;\r\n p = curr;\r\n } else {\r\n p += curr;\r\n if (p > n) {\r\n curr += 1;\r\n p = curr;\r\n }\r\n }\r\n }\r\n\r\n output(cost);\r\n\r\n }\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n arr.unshift(0);\r\n let cost = 0;\r\n for(let i=1;i<=n;i++){\r\n if(arr[i]===0){\r\n for(let j=i;j<=n;j=j+i){\r\n if(arr[j]===0){\r\n cost+=i;\r\n arr[j] = 1;\r\n }\r\n else break;\r\n }\r\n }\r\n }\r\n console.log(cost);\r\n }\r\n};\r\nsolve();"}], "src_uid": "28277036765f76f20c327ab2fda6c43b"} {"source_code": "function main() {\n\n var n = Number(readline());\n var arr1 = readline().split(' ').map(Number);\n var arr2=[];\n for(var k=0;k data += c);\nfunction* nextLine() {\n\tfor(let l of data.trim().split(/\\n/g)){\n\t\tyield l;\n\t}\n}\n\nconst sol = () => {\n\tlet nl = nextLine();\n\tlet n = Number(nl.next().value);\n\tnl.next();\n\tlet res = [];\n\tfor(let i = 0; i < n; i++){\n\t\tlet p = nl.next().value.trim().split(/\\s/g).map(Number);\n\t\t\n\t\tlet t = p.reduce((a, b) => a + b * 5 + 15,0);\n\t\tres.push(t);\n\t}\n\tconsole.log(Math.min(...res));;\n\n};\nprocess.stdin.on('end', sol);\n"}, {"source_code": "print(function(n, k){\n\tvar min=Infinity;\n\tfor(var i=0;i data += c);\nfunction* nextLine() {\n\tfor(let l of data.trim().split(/\\n/g)){\n\t\tconsole.log(l);\n\t\tyield l;\n\t}\n}\n\nconst sol = () => {\n\tlet nl = nextLine();\n\tlet n = Number(nl.next().value);\n\tnl.next();\n\tlet res = [];\n\tfor(let i = 0; i < n; i++){\n\t\tlet p = nl.next().value.split(/\\s/g).map(Number);\n\t\t\n\t\tlet t = p.reduce((a, b) => a + b * 5 + 15,0);\n\t\tres.push(t);\n\t}\n\tconsole.log(Math.min(...res));;\n\n};\nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\nfunction* nextLine() {\n\tfor(let l of data.trim().split(/\\n/g)){\n\t\tyield l;\n\t}\n}\n\nconst sol = () => {\n\tlet nl = nextLine();\n\tlet n = Number(nl.next().value);\n\tnl.next();\n\tlet res = [];\n\tfor(let i = 0; i < n; i++){\n\t\tlet p = nl.next().value.split(/\\s/g).map(Number);\n\t\t\n\t\tlet t = p.reduce((a, b) => a + b * 5 + 15,0);\n\t\tres.push(t);\n\t}\n\tconsole.log(Math.min(...res));;\n\n};\nprocess.stdin.on('end', sol);\n"}], "src_uid": "0ea79b2a7ddf3d4da9c7a348e61933a7"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n const chars = new Set(s);\r\n for (let char of chars) {\r\n let count = new Map();\r\n for (let i = -1, j = 0; j < n; j++) {\r\n var _count$get2;\r\n if (s[j] === char) {\r\n if (i !== -1) {\r\n for (let key of chars) {\r\n if (key === char) continue;\r\n if (!count.has(key) || count.get(key) > 3) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n } else {\r\n for (let key of chars) {\r\n var _count$get;\r\n if (key === char) continue;\r\n if (((_count$get = count.get(key)) !== null && _count$get !== void 0 ? _count$get : 0) > 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n }\r\n i = j;\r\n count = new Map();\r\n }\r\n count.set(s[j], ((_count$get2 = count.get(s[j])) !== null && _count$get2 !== void 0 ? _count$get2 : 0) + 1);\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s1 = await read();\r\n solve(s1);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\t\tconst n = s.length;\r\n\r\n\t\tlet p = '', ok = 1;\r\n\t\tfor (let i = 0, seen = []; i < n && ok; i++) {\r\n\t\t\tif (i && s[i] == s[0]) break;\r\n\t\t\tp += s[i];\r\n\t\t\tif (seen[s[i]]) ok = 0; seen[s[i]] = 1;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < n && ok; i++) {\r\n\t\t\tok &= s[i] == p[i%p.length];\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n const string = nextCharArray().join(\"\");\r\n\r\n\t\tconst map = new Map();\r\n\r\n\t\tfor (let i = 0; i < string.length; i++) {\r\n\t\t\tif (!map.has(string[i])) {\r\n\t\t\t\tmap.set(string[i], i)\r\n\t\t\t} else {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet mapSize = map.size;\r\n\t\tlet stop = false;\r\n\r\n\t\tfor (const [key, value] of map) {\r\n\t\t\tlet index = value;\r\n\t\t\tlet i = 0;\r\n\t\t\twhile (index + i * mapSize < string.length) {\r\n\t\t\t\tif (string[index] !== string[index + i * mapSize]) {\r\n\t\t\t\t\tstop = true;\r\n\t\t\t\t};\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t\tif (stop) break;\r\n\t\t}\r\n\t\tif (stop) {\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue\r\n\t\t} \r\n\r\n\t\tmyout(\"YES\");\r\n\r\n\t}\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const chs = {}\n for (let i = 0; i < str.length; i++) {\n chs[str[i]] = 1\n }\n //\n const prev = {}\n const count = Array(str.length)\n const arr = Array(26).fill(0)\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n const idx = str.charCodeAt(i) - 'a'.charCodeAt(0)\n arr[idx]++\n count[i] = arr.slice()\n if (x in prev) {\n const p = prev[x]\n for (let ch in chs) {\n const j = ch.charCodeAt(0) - 'a'.charCodeAt(0)\n const y = count[i][j] - (count[p][j] || 0)\n if (!y) return false\n }\n }\n //\n prev[x] = i\n }\n return true\n}\n"}], "negative_code": [], "src_uid": "dd098a17343a02fa5dc0d2d6cea853c7"} {"source_code": "var firstLine = readline().split(\" \");\nvar n = parseInt(firstLine[0]);\n\nfunction Pair(x, y) {\n\tthis.x = x;\n\tthis.y = y;\n}\n\nvar z0 = new Pair(parseInt(firstLine[1]), parseInt(firstLine[2]));\nvar p = new Array(n),\n\tisDead = new Array(n);\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(\" \");\n\tp[i] = new Pair(parseInt(line[0]), parseInt(line[1]));\n\tisDead[i] = false;\n}\n\nfunction isSameLine(a, b, c) {\n\tif (c.x == b.x && c.y == b.y) {\n\t\treturn true;\n\t}\n\tvar z0 = new Pair(b.x - a.x, b.y - a.y);\n\tvar z1 = new Pair(c.x - a.x, c.y - a.y);\n\n\treturn z0.x * z1.y == z0.y * z1.x;\n}\n\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n\tif (isDead[i]) {\n\t\tcontinue;\n\t}\n\tans++;\n\tisDead[i] = true;\n\tfor (var j = i + 1; j < n; j++) {\n\t\tif (isSameLine(z0, p[i], p[j])) {\n\t\t\tisDead[j] = true;\n\t\t}\n\t}\n}\n\nprint(ans);\n", "positive_code": [{"source_code": "function resolve(x, y, arr) {\n var memo = {};\n for (var i = 0; i < arr.length; i++) {\n var d = (arr[i][1] - y) / (arr[i][0] - x);\n if (d === -Infinity) {\n d = Infinity;\n }\n if (memo[d] === undefined) {\n memo[d] = [];\n }\n memo[d].push(i);\n }\n return Object.keys(memo).length;\n}\n\nconst p = readline().split(' ');\nvar arr = [];\nfor (var i = 0; i < parseInt(p[0], 10); i++) {\n var st = readline().split(' ');\n arr.push(\n st.map(el => {\n return parseInt(el, 10);\n })\n );\n}\nprint(resolve(parseInt(p[1], 10), parseInt(p[2], 10), arr));\n"}, {"source_code": "function Point(x,y){\n\tthis.x = x;\n\tthis.y = y;\n}\n\nfunction vp(a,b,c){\n\treturn (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);\n}\n\nvar s = readline().split(' ');\nvar n = +s[0];\nvar p0 = new Point(+s[1],+s[2]);\n\nvar u = [], p = [];\nfor(var i=0; i {\n return parseInt(el, 10);\n })\n );\n}\nprint(resolve(parseInt(p[1], 10), parseInt(p[2], 10), arr));\n"}, {"source_code": "function Point(x,y){\n\tthis.x = x;\n\tthis.y = y;\n}\n\nvar s = readline().split(' ');\nvar n = +s[0];\nvar p0 = new Point(+s[1],+s[2]);\n\nvar p = [];\nfor(var i=0; i +v.trim());\nvar n = arr[0];\nvar p = arr[1];\n\nvar a = [];\nvar k = 0;\n\nfor(var i = 0; i < n; i++){\n a.push(readline().split(\"\"));\n if(p > 0)\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(\n a[i][j] === \".\" &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else if(j === 11){\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n \n }\n }\n \n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else if(j === 11){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (((a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\") && a[i][j - 1] === \"S\") ||\n ((a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") && a[i][j + 1] === \"S\"))\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n }\n \n if(p === 0) break;\n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n if(p === 0) break;\n}\n\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \"S\"){\n if(j === 0){\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }else if(j === 11){\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n }else{\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }\n }\n }\n}\n\nprint(k);\na.forEach(v => print(v.join('')))", "positive_code": [{"source_code": "var arr = readline().split(\" \").map(v => +v.trim());\nvar n = arr[0];\nvar p = arr[1];\n\nvar a = [];\nvar k = 0;\n\nfor(var i = 0; i < n; i++){\n a.push(readline().split(\"\"));\n if(p > 0)\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(\n a[i][j] === \".\" &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else if(j === 11){\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n \n }\n }\n \n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else if(j === 11){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (((a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\") && a[i][j - 1] === \"S\") ||\n ((a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") && a[i][j + 1] === \"S\"))\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n }\n \n if(p === 0) break;\n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n if(p === 0) break;\n}\n\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \"S\"){\n if(j === 0){\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }else if(j === 11){\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n }else{\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }\n }\n }\n}\n\nprint(k);\na.forEach(v => print(v.join(\"\")))"}, {"source_code": "var signalPassanger = 'S';\nvar separator = '-';\nvar commonPassanger = 'P';\nvar newPassanger = 'x';\nvar freePlace = '.';\n\nvar firstLine = readline().split(' ').map(function(v){return +v;});\nvar rowsCount = +firstLine[0];\nvar rows = [];\nvar passangerCount = +firstLine[1];\n\nfor (var i = 0; i < rowsCount; i++) {\n rows.push(readline());\n}\n\nfunction replaceAt(string, index, replace) {\n return string.substring(0, index) + replace + string.substring(index + 1);\n}\n\nfunction calcWeight(string, index) {\n var result = 0;\n switch (index) {\n case 0: case 4: case 9:\n if (string.charAt(index + 1) == signalPassanger) result++;\n break;\n case 2: case 7: case 11:\n if (string.charAt(index - 1) == signalPassanger) result++;\n break;\n default:\n if (string.charAt(index - 1) == signalPassanger) result++;\n if (string.charAt(index + 1) == signalPassanger) result++;\n }\n \n return result;\n}\n\nfunction arrangePassangers(weight) {\n if (passangerCount === 0) return;\n\n for (var i = 0; i < rowsCount; i++) {\n for (var j = 0; j < 12; j++) {\n if (rows[i].charAt(j) == freePlace) {\n if ((calcWeight(rows[i], j) === weight) && (passangerCount > 0)) {\n rows[i] = replaceAt(rows[i], j, newPassanger);\n passangerCount--;\n }\n }\n }\n }\n}\n\nfunction isPassanger(string, index) {\n return (string.charAt(index) != freePlace);\n}\n\narrangePassangers(0);\narrangePassangers(1);\narrangePassangers(2);\n\nvar result = 0;\nvar currentChar = '';\n\nfor (var i = 0; i < rowsCount; i++) {\n for (var j = 0; j < 12; j++) {\n if (rows[i].charAt(j) == signalPassanger) {\n switch (j) {\n case 0: case 4: case 9:\n if (isPassanger(rows[i], j + 1)) result++;\n break;\n case 2: case 7: case 11:\n if (isPassanger(rows[i], j - 1)) result++;\n break;\n default:\n if (isPassanger(rows[i], j - 1)) result++;\n if (isPassanger(rows[i], j + 1)) result++;\n }\n }\n }\n}\n\nprint(result);\n\nfor (var i = 0; i < rowsCount; i++) {\n print(rows[i])\n}"}, {"source_code": "var first = readline().split(' ');\n\tvar rows_count = +first[0];\n\tvar people = +first[1];\n\tvar matrix = [];\n\tvar zero = 0;\n\tvar one = 0;\n\tvar two = 0;\n\tvar return_val = 0;\n\tvar dif_val = 0;\n\tfor (var inc1=0; inc1 zero + one ) dif_val = 2;\n\telse if (people > zero ) dif_val = 1;\n\tif (dif_val == 1) \n\t\t{\n\t\t\treturn_val = return_val + ( people - zero );\n\t\t\tpeople = people - zero;\n\t\t}\n\tif (dif_val == 2)\n\t\t{\n\t\t\treturn_val = return_val + one + ( people - zero - one )*2;\n\t\t\tpeople = people - zero - one;\n\t\t} \n\n\tprint(return_val);\n\n\tfor (var inc1=0; inc1 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val == 0)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tfor (var inc2=1; inc2<11; inc2++)\n\t\t{\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 2))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')) \n\t\t\t\t{\n\t\t\t\t\tif (people > 0)\n\t\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse matrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 0)&&(people > 0))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 1))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')) {}\n\t\t\t\telse if ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\telse if (people > 0)\n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprint(matrix[inc1]);\n\t}"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar N = numbers[0];\nvar K = numbers[1];\n\nvar lines = [];\nvar indexWith0Score = [];\nvar indexWith1Score = [];\nvar indexWith2Score = [];\nvar score = 0;\n\nfor(var i = 0; i < N; i++) {\n var newLine = readline();\n lines.push(newLine.split(''));\n for(var k = 0; k < newLine.length; k++) {\n var position = {row: i, col: k};\n if(newLine[k] === '.') {\n if(k === 0) {\n if(newLine[k + 1] === 'S') {\n indexWith1Score.push(position);\n } else {\n indexWith0Score.push(position);\n }\n } else if(k === newLine[newLine.length - 1]) {\n if(newLine[k - 1] === 'S') {\n indexWith1Score.push(position);\n } else {\n indexWith0Score.push(position);\n }\n } else {\n if(newLine[k + 1] === 'S' && newLine[k - 1] === 'S') {\n indexWith2Score.push(position);\n } else if(newLine[k + 1] === 'S' || newLine[k - 1] === 'S') {\n indexWith1Score.push(position);\n } else {\n indexWith0Score.push(position);\n }\n }\n } else if(newLine[k] === 'S') {\n if(newLine[k + 1] === 'P' || newLine[k + 1] === 'S') {\n score++;\n }\n if(newLine[k - 1] === 'P' || newLine[k - 1] === 'S' ) {\n score++;\n }\n }\n }\n}\n\nvar placedPassangers = 0;\n\nfor(var i = 0; i < indexWith0Score.length; i++) {\n if(placedPassangers >= K) break;\n var position = indexWith0Score[i];\n lines[position.row][position.col] = 'x';\n placedPassangers++;\n}\n\nfor(var i = 0; i < indexWith1Score.length; i++) {\n if(placedPassangers >= K) break;\n var position = indexWith1Score[i];\n lines[position.row][position.col] = 'x';\n score++;\n placedPassangers++;\n}\n\nfor(var i = 0; i < indexWith2Score.length; i++) {\n if(placedPassangers >= K) break;\n var position = indexWith2Score[i];\n lines[position.row][position.col] = 'x';\n score+=2;\n placedPassangers++;\n}\n\nwrite(score + '\\n' + lines.map(function(item) {return item.join('')}).join('\\n'));"}, {"source_code": "'use strict'\nlet config = readline()\nfunction getPlaneData(){\n let x = readline()\n\tlet i=x;\n while(typeof x != 'undefined'){\n\t\tx=readline()\n\t\tif(x){\n\t\t\ti+='-'+x\n\t\t}\n }\n return i\n}\n\nlet inputs = getPlaneData()\nlet passengers = parseInt(config.split(\" \")[1])\nlet none = []\nlet one = []\nlet two = []\nlet nb = 0\nfunction parser(s){\n\tfor(let i=0,l=s.length;i +v.trim());\nvar n = arr[0];\nvar p = arr[1];\n\nvar a = [];\nvar k = 0;\n\nfor(var i = 0; i < n; i++){\n a.push(readline().split(\"\"));\n if(p > 0)\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(\n a[i][j] === \".\" &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n }\n }else if(j === 11){\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\")\n ){\n a[i][j] = \"x\";\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") &&\n (a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\")\n ){\n a[i][j] = \"x\";\n }\n \n }\n }\n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(j === 0){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else if(j === 11){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }else{\n if(\n a[i][j] === \".\" &&\n (((a[i][j + 1] === \".\" || a[i][j + 1] === \"P\" || a[i][j + 1] === \"-\" || a[i][j + 1] === \"x\") && a[i][j - 1] === \"S\") ||\n ((a[i][j - 1] === \".\" || a[i][j - 1] === \"P\" || a[i][j - 1] === \"-\" || a[i][j - 1] === \"x\") && a[i][j + 1] === \"S\"))\n ){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n }\n \n if(p === 0) break;\n}\n\nif(p !== 0)\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \".\"){\n a[i][j] = \"x\";\n if(--p === 0) break;\n }\n }\n \n if(p === 0) break;\n}\n\nfor(var i = 0; i < a.length; i++){\n for(var j = 0; j < a[i].length; j++){\n if(a[i][j] === \"S\"){\n if(j === 0){\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }else if(j === 11){\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n }else{\n if(a[i][j - 1] === \"P\" || a[i][j - 1] === \"S\" || a[i][j - 1] === \"x\") k++;\n if(a[i][j + 1] === \"P\" || a[i][j + 1] === \"S\" || a[i][j + 1] === \"x\") k++;\n }\n }\n }\n}\n\nprint(k);\na.forEach(v => print(v.join(\"\")))"}, {"source_code": "var signalPassanger = 'S';\nvar separator = '-';\nvar commonPassanger = 'P';\nvar newPassanger = 'x';\nvar freePlace = '.';\n\nvar firstLine = readline().split(' ').map(function(v){return +v;});\nvar rowsCount = +firstLine[0];\nvar rows = [];\nvar passangerCount = +firstLine[1];\n\nfor (var i = 0; i < rowsCount; i++) {\n rows.push(readline());\n}\n\nfunction replaceAt(string, index, replace) {\n return string.substring(0, index) + replace + string.substring(index + 1);\n}\n\nfunction calcWeight(string, index) {\n var result = 0;\n switch (index) {\n case 0: case 4: case 9:\n if (string.charAt(index + 1) == signalPassanger) result++;\n break;\n case 2: case 7: case 11:\n if (string.charAt(index - 1) == signalPassanger) result++;\n break;\n default:\n if (string.charAt(index - 1) == signalPassanger) result++;\n if (string.charAt(index + 1) == signalPassanger) result++;\n }\n \n return result;\n}\n\nfunction arrangePassangers(weight) {\n if (passangerCount === 0) return;\n\n for (var i = 0; i < rowsCount; i++) {\n for (var j = 0; j < 12; j++) {\n if (rows[i].charAt(j) == freePlace) {\n if ((calcWeight(rows[i], j) === weight) && (passangerCount > 0)) {\n rows[i] = replaceAt(rows[i], j, newPassanger);\n passangerCount--;\n }\n }\n }\n }\n}\n\nfunction isPassanger(string, index) {\n return (string.charAt(index) == commonPassanger) ||\n (string.charAt(index) == newPassanger);\n}\n\narrangePassangers(0);\narrangePassangers(1);\narrangePassangers(2);\n\nvar result = 0;\nvar currentChar = '';\n\nfor (var i = 0; i < rowsCount; i++) {\n for (var j = 0; j < 12; j++) {\n if (rows[i].charAt(j) == signalPassanger) {\n switch (j) {\n case 0: case 4: case 9:\n if (isPassanger(rows[i], j + 1)) result++;\n break;\n case 2: case 7: case 11:\n if (isPassanger(rows[i], j - 1)) result++;\n break;\n default:\n if (isPassanger(rows[i], j - 1)) result++;\n if (isPassanger(rows[i], j + 1)) result++;\n }\n }\n }\n}\n\nprint(result + 2);\n\nfor (var i = 0; i < rowsCount; i++) {\n print(rows[i]);\n}"}, {"source_code": "var first = readline().split(' ');\n\tvar rows_count = +first[0];\n\tvar people = +first[1];\n\tvar matrix = [];\n\tvar zero = 0;\n\tvar one = 0;\n\tvar two = 0;\n\tvar return_val = 0;\n\tvar dif_val = 0;\n\tfor (var inc1=0; inc1 zero + one ) dif_val = 2;\n\telse if (people > zero ) dif_val = 1;\n\tif (dif_val == 1) \n\t\t{\n\t\t\treturn_val = return_val + ( people - zero );\n\t\t\tpeople = people - zero;\n\t\t}\n\tif (dif_val == 2)\n\t\t{\n\t\t\treturn_val = return_val + one + ( people - zero - one )*2;\n\t\t\tpeople = people - zero - one;\n\t\t} \n\n\tprint(return_val);\n\n\tfor (var inc1=0; inc1 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\t//matrix[inc1][0] = 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val == 0)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tfor (var inc2=1; inc2<11; inc2++)\n\t\t{\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 2)&&(people > 0))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')) \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t\telse matrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 0)&&(people > 0))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 1)&&(people > 0))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')) {}\n\t\t\t\telse if ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\telse \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprint(matrix[inc1]);\n\t}"}, {"source_code": "var first = readline().split(' ');\n\tvar rows_count = +first[0];\n\tvar people = +first[1];\n\tvar matrix = [];\n\tvar zero = 0;\n\tvar one = 0;\n\tvar two = 0;\n\tvar return_val = 0;\n\tvar dif_val = 0;\n\tfor (var inc1=0; inc1 zero + one ) dif_val = 2;\n\telse if (people > zero ) dif_val = 1;\n\tif (dif_val == 1) \n\t\t{\n\t\t\treturn_val = return_val + ( people - zero );\n\t\t\tpeople = people - zero;\n\t\t}\n\tif (dif_val == 2)\n\t\t{\n\t\t\treturn_val = return_val + one + ( people - zero - one )*2;\n\t\t\tpeople = people - zero - one;\n\t\t} \n\n\tprint(return_val);\n\n\tfor (var inc1=0; inc1 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\t//matrix[inc1][0] = 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][0] == '.')&&(matrix[inc1][1] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = 'x' + matrix[inc1].substr(1);\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val == 0)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] != 'S')&&(dif_val > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val == 1)&&(people > 0))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t\tpeople--;\n\t\t}\n\t\tif ((matrix[inc1][11] == '.')&&(matrix[inc1][10] == 'S')&&(dif_val > 1))\n\t\t{\n\t\t\tmatrix[inc1] = matrix[inc1].substr(0, 11) + 'x';\n\t\t}\n\t\tfor (var inc2=1; inc2<11; inc2++)\n\t\t{\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 2))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')&&(people > 0)) \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t\telse matrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 0)&&(people > 0))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((matrix[inc1][inc2] == '.')&&(dif_val == 1))\n\t\t\t{\n\t\t\t\tif ((matrix[inc1][inc2-1] == 'S')&&(matrix[inc1][inc2+1] == 'S')) {}\n\t\t\t\telse if ((matrix[inc1][inc2-1] != 'S')&&(matrix[inc1][inc2+1] != 'S')) \n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\telse if (people > 0)\n\t\t\t\t{\n\t\t\t\t\tmatrix[inc1] = matrix[inc1].substr(0, inc2) + 'x' + matrix[inc1].substr(inc2 + 1);\n\t\t\t\t\tpeople--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprint(matrix[inc1]);\n\t}"}, {"source_code": "var ryad = [];\nvar lines = [];\nvar count = 0;\nvar r1 = readline().split(' ');\nvar n = r1[0];\nvar p = r1[1];\n\nfor(c=0;c vm) {\n min = vm;\n max = v3;\n} else {\n min = v3;\n max = vm;\n}\n\nif(max > min*2 || no) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(max);\n}", "positive_code": [{"source_code": "var N = readline().split(' ');\nvar a1 = parseInt(N[0]) , a2 = parseInt(N[1]) , a3 = parseInt(N[2]) , a4 = parseInt(N[3]) ;\nvar b1 = 0 ,b2 = 0 , b3 = 0;\nfor(var i=200;i>0;i--){\n if(i>= a1 && i<=2*a1 && b1==0 && i >=a4 && i> 2*a4){\n b1 = i;\n continue;\n }\n if(i>= a2 && i<=2*a2 && b2==0 && i >=a4 && i> 2*a4){\n b2 = i;\n continue;\n }\n if(i>= a3 && i<= 2*a3 && b3==0 && i >=a4 && i <= 2*a4){\n b3 = i;\n break;\n }\n\n}\n\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}else{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "\nvar N = readline().split(' ');\nvar a1 = parseInt(N[0]),a2 = parseInt(N[1]),a3 = parseInt(N[2]),a4 = parseInt(N[3]);\nvar b1left = a1 , b2left = a2 ,b3left = a3;\nvar b1right = 2 * a1 , b2right = 2 *a2 , b3right = 2 * a3 ;\nvar b1=0, b2=0, b3=0;\nfor(var i=200;i>=0;i--){\n if(i>=b1left && i <= b1right && b1 == 0 && a4 <= i && i > 2 * a4) {\n b1 = i;\n continue;\n }\n if(i >= b2left && i <= b2right && b2 ==0 && a4 <= i && i > 2 * a4) {\n b2 = i;\n continue;\n }\n if(i >= b3left && i <= b3right && a4 <= i && i <= 2 * a4){\n b3 = i;\n break;\n }\n\n}\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}\nelse{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "'use strict'\n\nconst input = readline();\n\n// const print = console.log;\n// const line0 = \"50 30 10 19\";\n\n// const input = line0;\nconst arr = input.split(' ').map(x => parseInt(x));\n\nconst bear3 = arr[0];\nconst bear2 = arr[1];\nconst bear1 = arr[2];\nconst masha = arr[3];\n\nconst car1_low = bear1;\nconst car2_low = bear2;\nconst car3_low = bear3;\n\nconst car1_high = bear1 * 2;\nconst car2_high = bear2 * 2;\nconst car3_high = bear3 * 2;\n\nconst masha_likes_low = masha;\nconst masha_likes_high = masha * 2;\n\nif (masha_likes_low > car1_high || masha_likes_high < car1_low || masha_likes_high >= car2_high) {\n print(-1);\n} else {\n const car1 = masha_likes_low < car1_low ? car1_low : masha_likes_low;\n print(car3_high);\n print(car2_high);\n print(car1);\n}\n\n"}, {"source_code": "var line = readline();\nvar bears = line.split(' ').map(function(x) {return parseInt(x)});\nvar big = 2 * bears[0];\nvar medium = Math.min(2 * bears[1], big - 1);\nvar small = Math.min(2 * bears[2], 2 * bears[3], medium - 1);\n\nif (bears[1] > medium || \n bears[2] > small || \n bears[3] > small || \n 2 * bears[3] >= big || \n 2 * bears[3] >= medium) {\n print(-1);\n} else {\n print(big);\n print(medium);\n print(small);\n}\n"}], "negative_code": [{"source_code": "\n\n\n\n/**\n * \u5df2\u77e5 a1 a2 a3 a4\n * b1>b2>b3 a1<=b1<=2a1 b3<=a4<=2b3\n */\n\nvar N = readline().split(' ');\nvar a1 = parseInt(N[0]),a2 = parseInt(N[1]),a3 = parseInt(N[2]),a4 = parseInt(N[3]);\nvar b1left = a1 , b2left = a2 ,b3left = a3;\nvar b1right = 2 * a1 , b2right = 2 *a2 , b3right = 2 * a3 ;\nvar b1=0, b2=0, b3=0;\nfor(var i=200;i>=0;i--){\n if(i>=b1left && i <=b1right){\n b1 = i;\n continue;\n }\n if(i >= b2left && i <= b2right){\n b2 = i;\n continue;\n }\n if(i >= b3left && i <= b3right && b3left <= a4 && a4 <= b3right){\n b3 = i;\n }\n\n}\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}\nelse{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "var N = readline().split(' ');\nvar a1 = parseInt(N[0]),a2 = parseInt(N[1]),a3 = parseInt(N[2]),a4 = parseInt(N[3]);\nvar b1left = a1 , b2left = a2 ,b3left = a3;\nvar b1right = 2 * a1 , b2right = 2 *a2 , b3right = 2 * a3 ;\nvar b1=0, b2=0, b3=0;\nfor(var i=200;i>=0;i--){\n if(i>=b1left && i <= b1right && b1 == 0) {\n b1 = i;\n continue;\n }\n if(i >= b2left && i <= b2right && b2 ==0) {\n b2 = i;\n continue;\n }\n if(i >= b3left && i <= b3right && a4 <= i && i <= 2 * a4){\n b3 = i;\n break;\n }\n\n}\n\nprint(b1, b2, b3);\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}\nelse{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "\nvar N = readline().split(' ');\nvar a1 = parseInt(N[0]),a2 = parseInt(N[1]),a3 = parseInt(N[2]),a4 = parseInt(N[3]);\nvar b1left = a1 , b2left = a2 ,b3left = a3;\nvar b1right = 2 * a1 , b2right = 2 *a2 , b3right = 2 * a3 ;\nvar b1=0, b2=0, b3=0;\nfor(var i=200;i>=0;i--){\n if(i>=b1left && i <= b1right && b1 == 0) {\n b1 = i;\n continue;\n }\n if(i >= b2left && i <= b2right && b2 ==0) {\n b2 = i;\n continue;\n }\n if(i >= b3left && i <= b3right && a4 <= i && i <= 2 * a4){\n b3 = i;\n break;\n }\n\n}\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}\nelse{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "\nvar N = readline().split(' ');\nvar a1 = parseInt(N[0]) , a2 = parseInt(N[1]) , a3 = parseInt(N[2]) , a4 = parseInt(N[3]) ;\nvar b1 = 0 ,b2 = 0 , b3 = 0;\nfor(var i=200;i>0;i--){\n if(i>= a1 && i<=2*a1 && b1==0 && i >=a4 && i> 2*a4){\n b1 = i;\n continue;\n }\n if(i>= a2 && i<=2*a2 && b2==0 && i >=a4 && i> 2*a4){\n b2 = i;\n continue;\n }\n if(i>= a3 && i<= a3 && b3==0 && i >=a4 && i <= 2*a4){\n b3 = i;\n break;\n }\n\n}\n\n\nif(b1 == 0 || b2 == 0 || b3 == 0){\n print(\"-1\");\n}else{\n print(b1);\n print(b2);\n print(b3);\n}\n"}, {"source_code": "mas=readline().split(' ');\nv1=parseInt(mas[0])*2;\nv2=parseInt(mas[1])*2;\nv3=parseInt(mas[2])*2;\nvm=parseInt(mas[3])*2;\nno=false;\nif(v1 <= vm) {\n no=true;\n}\nif(v2 <= vm) {\n no=true;\n}\nif(v3 <= vm) {\n no=true;\n}\n\nif(no) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(v3);\n}"}, {"source_code": "mas=readline().split(' ');\nv1=parseInt(mas[0])*2;\nv2=parseInt(mas[1])*2;\nv3=parseInt(mas[2])*2;\nvm=parseInt(mas[3])*2;\nno=false;\nif(v1 <= vm) {\n no=true;\n}\nif(v2 <= vm) {\n no=true;\n}\nif(v3 < vm) {\n no=true;\n}\n\nif(no) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(v3);\n}"}, {"source_code": "mas=readline().split(' ');\nv1=parseInt(mas[0]);\nv2=parseInt(mas[1]);\nv3=parseInt(mas[2]);\nvm=parseInt(mas[3]);\nno=false;\nif(v1 <= vm*2) {\n if (vm*2+2 <= v1*2) {\n v1 = vm*2+2;\n } else {\n no=true;\n }\n}\nif(v2 <= vm*2) {\n if (vm*2+1 <= v2*2) {\n v2 = vm*2+1;\n } else {\n no=true;\n }\n}\nif(v3 > vm) {\n min = vm;\n max = v3;\n} else {\n min = v3;\n max = vm;\n}\n\nif(max > min*2 || no) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(max);\n}"}, {"source_code": "mas=readline().split(' ');\nv1=parseInt(mas[0]);\nv2=parseInt(mas[1]);\nv3=parseInt(mas[2]);\nvm=parseInt(mas[3]);\nno=false;\nif(v1 <= vm*2) {\n if (vm*2+1 <= v1*2) {\n v1 = vm*2+1;\n } else {\n no=true;\n }\n}\nif(v2 <= vm*2) {\n if (vm*2+1 <= v2*2) {\n v2 = vm*2+1;\n } else {\n no=true;\n }\n}\nif(v3 > vm) {\n min = vm;\n max = v3;\n} else {\n min = v3;\n max = vm;\n}\n\nif(max > min*2 || no) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(max);\n}"}, {"source_code": "mas=readline().split(' ');\nv1=parseInt(mas[0]);\nv2=parseInt(mas[1]);\nv3=parseInt(mas[2]);\nvm=parseInt(mas[3]);\nif(v3 > vm) {\n min = vm;\n max = v3;\n} else {\n min = v3;\n max = vm;\n}\n\nif(max > min*2) {\n print('-1');\n} else {\n print(v1);\n print(v2);\n print(max);\n}"}, {"source_code": "var line = readline();\nvar bears = line.split(' ').map(function(x) {return parseInt(x)});\nvar big = 2 * bears[0];\nvar medium = Math.min(2 * bears[1], big - 1);\nvar small = Math.min(2 * bears[2], 2 * bears[3], medium - 1);\n\nif (bears[1] > medium || bears[2] > small || bears[3] > small) {\n print(-1);\n} else {\n print(big);\nprint(medium);\nprint(small);\n}\n"}], "src_uid": "56535017d012fdfcc13695dfd5b33084"} {"source_code": "var args = readline().split(' ').map((s) => parseInt(s, 10));\n\nvar length = args[0];\nvar k = args[1];\nvar arr = readline().split(' ').map((s) => parseInt(s, 10));\n\nfunction main(length, k, arr) {\n var sorted = arr.sort((a, b) => a - b);\n\n if (k === 0) {\n var smallest = arr[k];\n\n return smallest > 1 ? smallest - 1 : -1;\n }\n\n var border = arr[k - 1];\n\n if (border === arr[k]) {\n return -1;\n }\n\n return border;\n}\n\nprint(main(length, k, arr));\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (k === \"0\" && sorted[0] > 1) {\n console.log(sorted[0] - 1)\n return\n }\n\n if (k === \"0\" ||\n sorted.length < k ||\n sorted[k-1] === sorted[k] ||\n sorted[k - 1] < 1) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "var s = readline().split(' ');\nvar n = +s[0];\nvar k = +s[1]\nvar a = readline().split(' ');\na.sort(function(a, b){return a-b});\nif(k == 0){\n if(a[0] > 1){\n print('1');\n } else{\n print('-1');\n }\n} else if(k < n && a[k-1] == a[k]){\n print('-1');\n} else{\n print(a[k-1]);\n}"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue != undefined) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n const orderedNumbers = numbers.sort((a, b) => a - b);\n\n if (kValue === numbers.length) {\n return numbers[kValue - 1];\n }\n\n const numberAtKPos = orderedNumbers[kValue];\n const lessOrEqualValue = numberAtKPos - 1;\n\n if (lessOrEqualValue === 0) {\n return -1;\n }\n\n if (kValue === 0) {\n return numberAtKPos > lessOrEqualValue ? lessOrEqualValue : -1;\n }\n\n const index = kValue - 1;\n const comparisonNumber = orderedNumbers[index];\n return comparisonNumber <= lessOrEqualValue ? comparisonNumber : -1;\n}"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity: O(n*log(n))\n// Space complexity: O(n)\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue != undefined) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n const orderedNumbers = numbers.sort((a, b) => a - b);\n\n if (kValue === numbers.length) {\n return numbers[kValue - 1];\n }\n\n const numberAtKPos = orderedNumbers[kValue];\n const comparisonValue = numberAtKPos - 1;\n\n if (comparisonValue === 0) {\n return -1;\n }\n\n if (kValue === 0) {\n return comparisonValue;\n }\n\n const previousNumber = orderedNumbers[kValue - 1];\n return previousNumber <= comparisonValue ? previousNumber : -1;\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (sorted.length < k ||\n sorted[k-1] === sorted[k] || k === 0) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (k === \"0\" && sorted[0] > 1) {\n console.log(sorted[0] - 1)\n return\n }\n\n if (sorted.length < k ||\n sorted[k-1] === sorted[k] ||\n sorted[k - 1] <= 1) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (sorted.length < k ||\n sorted[k-1] === sorted[k] || k === \"0\") {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (k === \"0\" && sorted[0] > 1) {\n console.log(sorted[0] - 1)\n return\n }\n\n if (k === \"0\" ||\n sorted.length < k ||\n sorted[k-1] === sorted[k] ||\n sorted[k - 1] <= 1) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (k === \"0\" && sorted[0] >= 1) {\n console.log(sorted[0] - 1)\n return\n } else {\n console.log(-1)\n return\n }\n\n if (sorted.length < k ||\n sorted[k-1] === sorted[k] ||\n sorted[k - 1] <= 1) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (k === \"0\" && sorted[0] >= 1) {\n console.log(sorted[0] - 1)\n return\n }\n\n if (sorted.length < k ||\n sorted[k-1] === sorted[k] ||\n sorted[k - 1] <= 1) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const split = data[0].split(\" \");\n const count = split[0]\n const k = split[1]\n const n = data[1]\n \n solve(n,k,count)\n}\n\nfunction solve(n, k, count) {\n let sorted = n.split(\" \").map( x => x * 1).sort((a,b) => a - b)\n if (sorted.length < k ||\n sorted[k-1] === sorted[k]) {\n console.log(-1)\n } else {\n console.log(sorted[k - 1])\n }\n}"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue != undefined) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKIndex = orderedNumbers[kValue - 1];\n const isKValidIndex = kValue < numbers.length\n const isNextNumberLessThanK = isKValidIndex && orderedNumbers[kValue] <= numberAtKIndex ? true : false;\n const isNumberHigherThanK = numberAtKIndex >= kValue\n return isNumberHigherThanK && !isNextNumberLessThanK ? numberAtKIndex : -1;\n}"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = input.split(\" \")[1];\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n if (kValue === 0) {\n return -1;\n }\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKValueIndex = orderedNumbers[kValue - 1];\n const isThereANextNumber = kValue < numbers.length\n const isNextNumberLessThanK = isThereANextNumber && orderedNumbers[kValue] <= numberAtKValueIndex ? true : false;\n return kValue <= numberAtKValueIndex && !isNextNumberLessThanK ? numberAtKValueIndex : -1;\n}\n"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n if (kValue === 0) {\n return -1;\n }\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKIndex = orderedNumbers[kValue - 1];\n const isKValidIndex = kValue < numbers.length\n const isNextNumberLessThanK = isKValidIndex && orderedNumbers[kValue] <= numberAtKIndex ? true : false;\n const isNumberHigherThanK = numberAtKIndex >= kValue\n return isNumberHigherThanK && !isNextNumberLessThanK ? numberAtKIndex : -1;\n}"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = input.split(\" \")[1];\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKValueIndex = orderedNumbers[kValue - 1];\n const isThereANextNumber = kValue < numbers.length\n const isNextNumberLessThanK = isThereANextNumber && orderedNumbers[kValue] <= numberAtKValueIndex ? true : false;\n return kValue <= numberAtKValueIndex && !isNextNumberLessThanK ? numberAtKValueIndex : -1;\n}\n"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n if (kValue === 0) {\n return -1;\n }\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKValue = orderedNumbers[kValue - 1];\n const isKValidIndex = kValue < numbers.length\n const isNextNumberHigherThanK = isKValidIndex && orderedNumbers[kValue] > numberAtKValue ? false : true;\n const isNumberHigherThanK = numberAtKValue >= kValue\n return isNumberHigherThanK && isNextNumberHigherThanK ? numberAtKValue : -1;\n}\n"}, {"source_code": "\n// https://codeforces.com/problemset/problem/977/C\n// Big O:\n// Time complexity:\n// Space complexity:\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet kValue;\nrl.on('line', (input) => {\n if (kValue != undefined) {\n const numbers = input.split(\" \").map(Number);\n console.log(findLessOrEqual(numbers, kValue));\n rl.close();\n } else {\n kValue = parseInt(input.split(\" \")[1]);\n }\n});\n\n// Problem\nfunction findLessOrEqual(numbers, kValue) {\n const orderedNumbers = numbers.sort((a, b) => a - b);\n const numberAtKPos = orderedNumbers[kValue];\n const lessOrEqualValue = numberAtKPos - 1;\n\n if (lessOrEqualValue === 0) {\n return -1;\n }\n\n if (kValue === 0) {\n return numberAtKPos > lessOrEqualValue ? lessOrEqualValue : -1;\n }\n\n const index = kValue - 1;\n const comparisonNumber = orderedNumbers[index];\n return comparisonNumber <= lessOrEqualValue ? comparisonNumber : -1;\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/977/B\n// Big O:\n// Time complexity: O(n)\n// Space complexity: O(n)\n\nconst readline = require(\"readline\");\n\n// Read input\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet stringLength;\nrl.on('line', (input) => {\n if (stringLength) {\n console.log(findMostCommonGram(input, stringLength));\n rl.close();\n } else {\n stringLength = input;\n }\n});\n\n// Problem\nfunction findMostCommonGram(string, stringLength) {\n let mostCommonGram = \"\";\n let mostCommonGramOccurrences = 0;\n const gramOccurrences = {};\n\n for (let i = 0; i < stringLength - 1; i++) {\n const twogram = string[i] + string[i + 1];\n const occurrences = gramOccurrences[twogram] ? gramOccurrences[twogram] + 1 : 1;\n const currentOcurrences = occurrences + 1;\n if (currentOcurrences > mostCommonGramOccurrences) {\n mostCommonGram = twogram;\n mostCommonGramOccurrences = currentOcurrences;\n }\n\n gramOccurrences[twogram] = currentOcurrences;\n }\n\n return mostCommonGram;\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var u=e[n]={exports:{}};return t[n].call(u.exports,u,u.exports,r),u.exports}(965)})();"}, {"source_code": "var args = readline().split(' ').map((s) => parseInt(s, 10));\n\nvar length = args[0];\nvar k = args[1];\nvar arr = readline().split(' ').map((s) => parseInt(s, 10));\n\nfunction main(length, k, arr) {\n var sorted = arr.sort((a, b) => a - b);\n\n var border = arr[k - 1];\n\n if (border === arr[k]) {\n return -1;\n }\n\n return border;\n}\n\nprint(main(length, k, arr));\n"}, {"source_code": "var args = readline().split(' ').map((s) => parseInt(s, 10));\n\nvar length = args[0];\nvar k = args[1];\nvar arr = readline().split(' ').map((s) => parseInt(s, 10));\n\nfunction main(length, k, arr) {\n if (k === 0) {\n return -1;\n }\n\n var sorted = arr.sort((a, b) => a - b);\n\n var border = arr[k - 1];\n\n if (border === arr[k]) {\n return -1;\n }\n\n return border;\n}\n\nprint(main(length, k, arr));\n"}, {"source_code": "var s = readline().split(' ');\nvar n = +s[0];\nvar k = +s[1]\nvar a = readline().split(' ');\na.sort(function(a, b){return a-b});\nif(k < n && a[k-1] == a[k] || k == 0){\n print('-1');\n} else{\n print(a[k-1]);\n}"}, {"source_code": "var s = readline().split(' ');\nvar n = +s[0];\nvar k = +s[1]\nvar a = readline().split(' ');\na.sort(function(a, b){return a-b});\nif(k < n && a[k-1] == a[k]){\n print('-1');\n} else{\n print(a[k-1]);\n}"}], "src_uid": "55297e2a65144323af4d6abd6a6ef050"} {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let polyhedrons = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20,\n };\n let sum = 0;\n let shapes = inputs.slice(1);\n for (let row of shapes) {\n if (polyhedrons[row.trim()]) {\n sum += polyhedrons[row.trim()];\n }\n }\n\n return sum.toString();\n}\n\n\n", "positive_code": [{"source_code": "var sum = 0;\n\t\tvar n = readline();\n\t\twhile(n>0){\n\t\tvar line = readline();\n\t\tif (line == \"Tetrahedron\"){\n\t\t\tsum+=4;\n\t\t}\n\t\tif (line == \"Cube\"){\n\t\t\tsum+=6;\n\t\t}\n\t\tif (line == \"Octahedron\"){\n\t\t\tsum+=8;\n\t\t}\n\t\tif (line == \"Dodecahedron\"){\n\t\t\tsum+=12;\n\t\t}\n\t\tif (line == \"Icosahedron\"){\n\t\t\tsum+=20;\n\t\t}\n\t\tn--;\n\t}\n\t\tprint(sum);"}, {"source_code": " var n = parseInt(readline());\n var res = 0;\n while(n) {\n var c = readline();\n if(c === 'Tetrahedron') res += 4;\n if(c === 'Cube') res += 6;\n if(c === 'Octahedron') res += 8;\n if(c === 'Dodecahedron') res += 12;\n if(c === 'Icosahedron') res += 20;\n n -= 1;\n }\n print(res)"}, {"source_code": "var n = parseInt(readline()), i = 0;\nvar s, res=0;\n\nfor(i=0;i result += obj[item])\n\nprint(result)\n\n\n"}, {"source_code": "'use strict'\nlet a = readline(), b, c = 0;\n\nfor (; a; a--) {\n b = readline()[0];\n if (b === 'C') {c += 6; continue}\n if (b === 'D') {c += 12; continue}\n if (b === 'I') {c += 20; continue}\n if (b === 'O') {c += 8; continue}\n if (b === 'T') {c += 4; continue}\n}\n\nprint(c);"}, {"source_code": "var a = readline(), c = 0, C = 6, D = 12, I = 20, O = 8, T = 4;\nfor (; a > 0; a--) c += this[readline()[0]];\nprint(c);"}, {"source_code": "var a = readline(), b = {C: 6, D: 12, I: 20, O: 8, T: 4}, c = 0;\n\nfor (; a > 0; a--) {\n c += b[readline()[0]]\n}\n\nprint(c);"}, {"source_code": "var n = parseInt(readline()),\n\tcounter = 0,\n\tscores = {\n\t\tTetrahedron: 4,\n\t\tCube: 6,\n\t\tOctahedron: 8,\n\t\tDodecahedron: 12,\n\t\tIcosahedron: 20\n\t}\n\nwhile (n > 0) {\n\tcounter += scores[readline()]\n\tn --\n}\n\nprint(counter)\n"}, {"source_code": "'use strict'\nlet a = readline(), b, c = 0;\n\nfor (; a; a--) {\n b = readline()[0];\n if (b === 'C') c += 6;\n else if (b === 'D') c += 12;\n else if (b === 'I') c += 20;\n else if (b === 'O') c += 8;\n else if (b === 'T') c += 4;\n}\n\nprint(c);"}, {"source_code": "var data1 = readline().split(' ').map(function(x){return parseInt(x)});\nvar data2 = [];\nfor (i = 0; i 0; a--) {\n b = readline()[0];\n if (b === 'C') c += 6;\n if (b === 'D') c += 12;\n if (b === 'I') c += 20;\n if (b === 'O') c += 8;\n if (b === 'T') c += 4;\n}\n\nwrite(c);\n"}, {"source_code": "var data = {\n\t\"Tetrahedron\": 4,\n\t\"Cube\": 6,\n\t\"Octahedron\": 8,\n\t\"Dodecahedron\": 12,\n\t\"Icosahedron\": 20\n};\n\nvar n = +readline(),\n\tsum = 0, \n\tline;\n\nwhile (line = readline()) {\n\tsum += data[line];\n}\n\nprint(sum);"}, {"source_code": "var p = {Tetrahedron: 4, Cube: 6, Octahedron: 8, Dodecahedron: 12, Icosahedron: 20};\nn = parseInt(readline());\nvar s = 0;\n for (var i=0; i < n; i++ ){\n s += p[readline()];\n }\nprint(s); \n"}, {"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar S = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20\n};\n\nvar n = readline();\n\nvar result = 0;\nfor (var i = 0; i < n; ++i) {\n result += S[readline()];\n}\n\nwrite(result);"}, {"source_code": "var n=+readline()\nvar T={\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron:20,\n};\nR=0\nfor (var i=0;i 0){\n var name = readline();\n\n if(name == \"Tetrahedron\"){\n faces += 4;\n }else if(name == \"Cube\"){\n faces += 6;\n }else if(name == \"Octahedron\"){\n faces += 8;\n }else if(name == \"Dodecahedron\"){\n faces += 12;\n }else if(name == \"Icosahedron\"){\n faces += 20;\n }\n n--;\n }\n\n return faces;\n}"}, {"source_code": "var limit = parseInt(readline());\nvar map = {}\nmap['Icosahedron'] = 20;\nmap['Dodecahedron'] = 12;\nmap['Octahedron'] = 8;\nmap['Cube'] = 6;\nmap['Tetrahedron'] = 4;\nvar sum = 0;\nfor (var i = 0; i < limit; i++) {\n sum += map[readline()];\n}\nprint(sum);\n"}, {"source_code": "var amount = parseInt(readline());\nvar numberOfFaces = 0;\n\nvar polyhedrons = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20 \n}\n\nfor (var i = 0; i < amount; i++) {\n numberOfFaces += polyhedrons[readline()];\n}\n\n\nprint(numberOfFaces);"}, {"source_code": "var n = parseInt(readline());\nvar log = {Tetrahedron: 4, Cube: 6, Octahedron: 8, Dodecahedron: 12, Icosahedron:20};\nvar sideCount = 0;\nwhile (n--) {\n\tsideCount += log[readline()];\n}\nprint(sideCount);"}, {"source_code": "var o = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20\n}\nvar n = parseInt(readline())\nvar total = 0;\nwhile (n != 0) {\n n--;\n total += o[readline().trim()]\n}\nprint(total)"}, {"source_code": "'use strict'\nlet n = parseInt(readline()),\n dict = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n },\n counter = 0;\n\nfor (let i = 0; i < n; i++) {\n const key = readline();\n counter+=dict[key];\n}\nwrite(counter);"}, {"source_code": "var n = +readline(),\n ans = 0;\n\nfor (var i = 0; i < n; i++) {\n var name = readline();\n\n switch (name) {\n case \"Tetrahedron\":\n ans += 4;\n break;\n case \"Cube\":\n ans += 6;\n break;\n case \"Octahedron\":\n ans += 8;\n break;\n case \"Dodecahedron\":\n ans += 12;\n break;\n case \"Icosahedron\":\n ans += 20;\n break;\n }\n}\n\nprint(ans);\n\n"}, {"source_code": "l=readline();\n n=l;\nvar tet=0, cub=0, oct=0, dod=0, ico=0;\nfor (i=0; i0; N--) {\n var line = line + ' ' + readline().split(' ') ;\n}\nvar type = line.split(' ');\n\nfor (n; n>0; n--) {\n switch (type[n]) {\n case 'Tetrahedron': sum = sum + 4; break;\n case 'Cube': sum = sum + 6; break;\n case 'Octahedron': sum = sum + 8; break;\n case 'Dodecahedron': sum = sum + 12; break;\n case 'Icosahedron': sum = sum + 20; break;\n }\n}\nprint (sum);"}, {"source_code": "var n = readline();\nvar i = 0, sum = 0, arr = '';\nfor (i; i{\n input+=givenInput;\n})\n\nprocess.stdin.on('end',()=>{\n main(input);\n})\n\nconst main=(input)=>{\n\n const n=Number(input.split('\\r\\n')[0]);\n let strArr=input.split('\\r\\n');\n\n let num,total=0;\n\n for(let i=1;i<=n;i++){\n\n str=strArr[i];\n\n switch(str){\n case 'Tetrahedron': num=4; break; \n case 'Cube': num=6; break;\n case 'Octahedron': num=8 ; break;\n case 'Dodecahedron': num=12 ; break;\n case 'Icosahedron': num=20 ; break;\n }\n\n total+=num;\n }\n\n console.log(total);\n\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst polyhedron = () => {\n input.shift();\n let sum = 0;\n for (const x of input) {\n if (x === 'Icosahedron') {\n sum += 20;\n }if (x === 'Cube') {\n sum += 6;\n }if (x === 'Tetrahedron') {\n sum += 4;\n }if (x === 'Dodecahedron') {\n sum += 12;\n } if (x === 'Octahedron') {\n sum += 8;\n }\n }\n console.log(sum);\n};\nreadLine.on('close', polyhedron);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let ans = 0;\n let objPoly = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20\n }\n for (var i = 0; i < n; i++) {\n let polyhedron = readLine();\n ans += objPoly[polyhedron.charAt(0)];\n }\n console.log(ans);\n}"}, {"source_code": "'use strict';\n\nconst readline = require('readline');\n\nlet lines = [];\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', (cmd) => {\n let n = parseInt(lines[0]);\n let obj = {\n \"Cube\": 6,\n \"Dodecahedron\": 12,\n \"Icosahedron\": 20,\n \"Octahedron\": 8,\n \"Tetrahedron\": 4\n };\n let ret = 0;\n for (let i = 1; i < n + 1; ++i) {\n ret += obj[lines[i]];\n }\n console.log(ret);\n process.exit(0);\n\n});\n"}, {"source_code": "'use strict';\n\nconst readline = require('readline');\n\nlet lines = [];\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nconst obj = {\n \"Cube\": 6,\n \"Dodecahedron\": 12,\n \"Icosahedron\": 20,\n \"Octahedron\": 8,\n \"Tetrahedron\": 4\n};\n\n\nrl.on('close', (cmd) => {\n let n = parseInt(lines[0]);\n let ret = 0;\n for (let i = 1; i < n + 1; ++i) {\n ret += obj[lines[i]];\n }\n console.log(ret);\n process.exit(0);\n\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst polyhedrons = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron:20,\n}\nlet sum = 0, count = 0, int;\n\nrl.on('line', (line) => {\n if (typeof int !== 'undefined' && line in polyhedrons) {\n sum += polyhedrons[line];\n if (++count === Number(int)) {\n console.log(sum);\n rl.close()\n }\n } else int = line;\n});"}, {"source_code": "let readline = require('readline');\nlet intInput = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\nlet arr = [];\nintInput.on('line', (line) => {\n\tarr.push(line)\n});\nintInput.on('close', () => {\n\t//let num = arr[0];\n\tlet nameToSize = {\n\t\t'Tetrahedron': 4,\n\t\t'Cube': 6,\n\t\t'Octahedron': 8,\n\t\t'Dodecahedron': 12,\n\t\t'Icosahedron': 20\n\t}\n\tlet sum = 0;\n\tfor (let i = 1; i <= arr.length - 1; i++) {\n\t\tlet polyhedron = arr[i];\n\t\tsum += nameToSize[polyhedron]\n\t}\n\tconsole.log(sum);\n})"}, {"source_code": "function main() {\n // write code here:\n var polyhedrons = {\n \"Tetrahedron\": 4,\n \"Cube\": 6,\n \"Octahedron\": 8,\n \"Dodecahedron\": 12,\n \"Icosahedron\": 20\n };\n var num = Number(stdin[0]), totalNum = 0;\n for (var i = 1; i <= num; i++) {\n totalNum += polyhedrons[stdin[i]];\n }\n console.log(totalNum);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet i = 0;\n\nrl.question('', (number) => {\n const shapeNames = [] ; \n rl.on('line', (shapeName) => {\n i++;\n shapeNames.push(shapeName) ; \n if (i >= parseInt(number)) {\n calFacesNum(shapeNames) ; \n rl.close();\n }\n });\n});\n\nfunction calFacesNum(faces) {\n let facesNumber = 0;\n\n for (let i = 0; i < faces.length; i++) {\n switch (faces[i]) {\n case 'Tetrahedron':\n facesNumber += 4;\n break;\n case 'Cube':\n facesNumber += 6;\n break;\n case 'Octahedron':\n facesNumber += 8;\n break;\n case 'Dodecahedron':\n facesNumber += 12;\n break;\n case 'Icosahedron':\n facesNumber += 20;\n break;\n }\n }\n console.log(facesNumber) ;\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, ...geometry] = input\n count = parseInt(count, 10)\n function returnCountGeometry(el){\n switch(el){\n case 'Tetrahedron': {\n return 4\n } break;\n case 'Cube': {\n return 6\n } break;\n case 'Octahedron': {\n return 8\n } break;\n case 'Dodecahedron': {\n return 12\n } break;\n case 'Icosahedron': {\n return 20\n } break;\n default: {\n return 0\n }\n }\n }\n let _fin = 0\n for (let i = 0; i < count; i ++) {\n const el = geometry[i]\n const check = el !== '' ? true : false\n if(check) {\n const counter = returnCountGeometry(el)\n _fin += counter\n } else {\n count++\n }\n }\n console.log(_fin)\n});"}, {"source_code": "function onReadable(rs, bufContainer, resolve) {\n return () => {\n const chunk = rs.read();\n\n if (chunk) bufContainer.val = Buffer.concat([ bufContainer.val, chunk ]);\n\n let newLineIndex = bufContainer.val.indexOf('\\n');\n\n if (!chunk) { newLineIndex = bufContainer.val.length; }\n\n if (newLineIndex !== -1) {\n const line = bufContainer.val.slice(0, newLineIndex);\n\n bufContainer.val = bufContainer.val.slice(newLineIndex + 1);\n\n return resolve(line.toString('utf-8'));\n }\n\n return rs.once('readable', onReadable(rs, bufContainer, resolve))\n }\n}\n\nfunction IO(rs, ws) {\n const bufContainer = { val: Buffer.from([]) };\n\n return {\n async rl() {\n const newLineIndex = bufContainer.val.indexOf('\\n');\n\n if (newLineIndex !== -1) {\n const line = bufContainer.val.slice(0, newLineIndex);\n\n bufContainer.val = bufContainer.val.slice(newLineIndex + 1);\n\n return Promise.resolve(line.toString('utf-8'));\n }\n\n return new Promise(resolve => rs.once('readable', onReadable(rs, bufContainer, resolve)));\n },\n wr(str) {\n return ws.write(str);\n },\n wl(str) {\n return ws.write(str + '\\n');\n }\n }\n}\n\n(async () => {\n const io = IO(process.stdin, process.stdout);\n\n return sol(io);\n})();\n\nasync function sol({ rl, wr, wl }) {\n const grani = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20,\n };\n\n const n = Number(await rl());\n let sum = 0;\n\n for (let i = 0; i < n; i += 1) {\n const f = (await rl())[0];\n sum += grani[f];\n\n if (Number.isNaN(sum)) {\n return wl(`${f} ${i}`);\n }\n }\n\n return wl(sum);\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var output = 0;\n for(var i = 0; i < N; i++){\n var s = next();\n switch(s){\n case \"Tetrahedron\":\n output += 4;\n break;\n case \"Cube\":\n output += 6;\n break;\n case \"Octahedron\":\n output += 8;\n break;\n case \"Dodecahedron\":\n output += 12;\n break;\n case \"Icosahedron\":\n output += 20;\n break;\n }\n }\n myout(output);\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n const n = +input[0];\n let k = 0;\n for (let i = 1; i <= n; i++) {\n if (input[i] === 'Tetrahedron') {\n k += 4;\n }\n else if (input[i] === 'Cube') {\n k += 6;\n }\n else if (input[i] === 'Octahedron') {\n k += 8;\n }\n else if (input[i] === 'Dodecahedron') {\n k += 12;\n }\n else if (input[i] === 'Icosahedron') {\n k += 20;\n }\n }\n console.log(k);\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\nconst score = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20\n};\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n ans += score[d];\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var figures={Tetrahedron:4,Cube:6,Octahedron:8,Dodecahedron:12,Icosahedron:20},buffer=\"\";process.stdin.setEncoding(\"utf8\");process.stdin.on(\"readable\",function(){for(var a;null!==(a=process.stdin.read());)buffer+=a});process.stdin.on(\"end\",function(){buffer=buffer.split(\"\\r\\n\");for(var a=0,b=1;b<=buffer[0];b++)a+=figures[buffer[b]];process.stdout.write(\"\"+a)});"}, {"source_code": "'use strict';\n \nlet input = [];\nlet count_flow = {\n 'Icosahedron': 20,\n 'Cube': 6,\n 'Tetrahedron': 4,\n 'Dodecahedron': 12,\n 'Octahedron': 8,\n}\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n line.split(' ').map(x => input.push(x));\n});\n\nRL.on('close', () => {\n let n = parseInt(input[0]), sum = 0;\n for (let i = 1; i <= n; i++)\n sum += count_flow[input[i]];\n console.log(sum);\n});\n\n"}, {"source_code": "let heterolist = [];\nlet gayNum = 0;\nlet iter = 0;\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction checkSum(line){\n if (line == 'Tetrahedron'){\n return 4;\n } else if (line == 'Cube'){\n return 6;\n } else if (line == 'Octahedron'){\n return 8;\n } else if (line == 'Dodecahedron'){\n return 12;\n } else if (line == 'Icosahedron'){\n return 20;\n }\n};\n\nrl.question('', (answer) => {\n sizeOfArray = answer;\n //console.log('sizeOfArray', answer);\n});\n\nrl.on('line', (line) => {\n //heterolist.push(line.split(' ', 1).map(String));\n gayNum += checkSum(line.split(' ', 1).map(String));\n iter++;\n if(iter == sizeOfArray){\n console.log(gayNum);\n process.exit(0);\n } \n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet sides = 0;\nconst sidedict = {\n \"Tetrahedron\": 4,\n \"Cube\": 6,\n \"Octahedron\": 8,\n \"Dodecahedron\": 12,\n \"Icosahedron\": 20\n}\nlet c = 0;\nlet co;\nrl.on('line', function(line){\n c++;\n if (c == 1) co = parseInt(line);\n if (c > 1) {\n sides += sidedict[line];\n }\n\n if ((co + 1) == c) {\n console.log(sides);\n }\n});\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t=+readLine()\n\tlet sides={\n\t\t'Tetrahedron' : 4,\n\t\t'Cube' : 6,\n\t\t'Octahedron' : 8,\n\t\t'Dodecahedron' : 12,\n\t\t'Icosahedron' : 20\n\t}\n\n\tlet totalFaces=0\n\twhile(t--){\n\t\tlet shape=readLine()\n\t\ttotalFaces+=sides[shape]\n\t}\n\tconsole.log(totalFaces)\n}"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n tetrahedron: 4,\n cube: 6,\n octahedron: 8,\n dodecahedron: 12,\n icosahedron: 20\n };\n let total = 0;\n const inputArray = input.split('\\r\\n');\n for(let i = 1; i< inputArray.length; i++) {\n if(reference.hasOwnProperty(inputArray[i].toLowerCase())) {\n total = total + reference[inputArray[i].toLowerCase()]; \n }\n }\n console.log(total);\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n \nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n if (!isNaN(txt[i] * 1)) {\n let tab = [];\n for (let i1 = i + 1; i1 < i + 1 + txt[i] * 1; i1++) {\n tab.push(txt[i1]);\n }\n doit(tab);\n }\n\n}\n\nfunction doit(tab) {\n let obj = {\n Icosahedron: 20,\n Cube: 6,\n Tetrahedron: 4,\n Dodecahedron: 12,\n Octahedron: 8\n };\n let score=0;\n tab.forEach(element => {\n score+=obj[element]; \n });\n console.log(score);\n \n\n}"}, {"source_code": "const figures = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\nvar buffer = '';\n\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n buffer += chunk;\n }\n});\n\nprocess.stdin.on('end', solve);\n\nfunction solve() {\n buffer = buffer.split('\\r\\n');\n var accum = 0;\n for (let i = 1; i <= buffer[0]; i++) {\n accum += figures[buffer[i]];\n }\n process.stdout.write('' + accum);\n}"}, {"source_code": "const figures = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\nvar buffer = '';\n\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n buffer += chunk;\n }\n});\n\nprocess.stdin.on('end', () => {\n buffer = buffer.split('\\r\\n');\n var accum = 0;\n for (let i = 1; i <= buffer[0]; i++) {\n accum += figures[buffer[i]];\n }\n process.stdout.write('' + accum);\n});"}], "negative_code": [{"source_code": "\n\t var n = parseInt(readline());\n\tvar str = readline();\n\tvar sum = 0;\n while(n){\n \tif(str === \"Tetrahedron\") sum += 4; \n \tif(str === \"Cube\") sum += 6;\n \tif(str === \"Octahedron\") sum += 8;\n \tif(str === \"Dodecahedron\") sum += 12;\n \tif(str === \"Icosahedron\") sum += 20;\n \tn--;\n }\n print(sum);\n\t"}, {"source_code": "\n\t var n = parseInt(readline());\n\tvar str = readline();\n\tvar sum = 0;\n for(var i = 0; i < n; i++){\n \tif(str === \"Tetrahedron\") sum += 4; break;\n \tif(str === \"Cube\") sum += 6; break;\n \tif(str === \"Octahedron\") sum += 8; break;\n \tif(str === \"Dodecahedron\") sum += 12; break;\n \tif(str === \"Icosahedron\") sum += 20; break;\n }\n print(sum);\n\t"}, {"source_code": "\n\t var n = parseInt(readline());\n\tvar str = readline();\n\tvar sum = 0;\n for(var i = 0; i < n; i++){\n \tif(str === \"Tetrahedron\") sum += 4;\n \tif(str === \"Cube\") sum += 6;\n \tif(str === \"Octahedron\") sum += 8;\n \tif(str === \"Dodecahedron\") sum += 12;\n \tif(str === \"Icosahedron\") sum += 20;\n }\n print(sum);\n\t//print(readline().includes(\"Tetrahedron\") ? sum +=== 4: \n\t//(\"Cube\") ? sum += 6 : (\"Octahedron\") ?sum += 8 : \n\t//(\"Dodecahedron\") ? sum += 12 : (\"Icosahedron\") ? sum += 20;\n\n//Tetrahedron 4 \n//Cube 6 \n//Octahedron 8 \n//Dodecahedron 12\n//Icosahedron 20"}, {"source_code": "\n\t var n = parseInt(readline());\n\tvar str = readline();\n\tvar sum = 0;\n for(var i = 0; i <= n; i++){\n \tif(str === \"Tetrahedron\") sum += 4;\n \tif(str === \"Cube\") sum += 6;\n \tif(str === \"Octahedron\") sum += 8;\n \tif(str === \"Dodecahedron\") sum += 12;\n \tif(str === \"Icosahedron\") sum += 20;\n }\n print(sum);\n\t"}, {"source_code": "\n\t var n = parseInt(readline());\n\tvar sum = 0;\n for(var i = 0; i < n; i++){\n \tvar str = readline();\n \tif(str === \"Tetrahedron\") sum += 4; \n \tif(str === \"Cube\") sum += 6;\n \tif(str === \"Octahedron\") sum += 8;\n \tif(str === \"Dodecahedron\") sum += 12;\n \tif(str === \"Icosahedron\") sum += 20;\n \tn --;\n }\n print(sum);\n\t\n\t"}, {"source_code": "\n\t var n = parseInt(readline());\n\tvar sum = 0;\n\tvar str = readline();\n while(n){\n \tif(str === \"Tetrahedron\") sum += 4; \n \tif(str === \"Cube\") sum += 6;\n \tif(str === \"Octahedron\") sum += 8;\n \tif(str === \"Dodecahedron\") sum += 12;\n \tif(str === \"Icosahedron\") sum += 20;\n \tn --;\n }\n print(sum);\n\t\n\t"}, {"source_code": "var n = Number(readline());\nvar arr = [];\n\nfor(var i = 0; i <= n; i++) {\n arr.push(readline());\n}\n\nvar obj = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20,\n}\n\nvar result = 0;\narr.map(item => result += obj[item])\n\nprint(result)\n\n\n"}, {"source_code": "var n = readline();\nvar arr = [];\nfor(var i = 0; i <= n; i++) {\n arr.push(readline());\n}\n\n\nvar obj = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20,\n}\n\nvar result = 0;\narr.map(i => result += obj[i])\n\nprint(result)\n\n\n"}, {"source_code": "var n = Number(readline());\nvar arr = [];\n\nfor(var i = 0; i < n; i++) {\n arr.push(readline());\n}\n\nvar obj = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20\n}\n\nvar result = 0;\narr.map(item => result += obj[item])\n\nprint(arr)\n\n\n"}, {"source_code": "var n = readline();\nvar arr = [];\nfor(var i = 0; i <= n; i++) {\n arr.push(readline());\n}\n\n\nvar obj = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20,\n}\n\nvar result = 0;\narr.map(item => result += obj[item])\n\nprint(result)\n\n\n"}, {"source_code": "var n = readline();\nvar arr = [];\nfor(var i = 0; i <= n; i++) {\n var el = readline();\n arr.push(el);\n}\n\n\nvar obj = {\n 'Tetrahedron': 4,\n 'Cube': 6,\n 'Octahedron': 8,\n 'Dodecahedron': 12,\n 'Icosahedron': 20,\n}\n\nvar result = 0;\narr.map(item => result += obj[item])\n\nprint(result)\n\n\n"}, {"source_code": "var a = readline(), b, c = 0;\n\nfor (; a; a--) {\n b = readline()[0];\n if (b === 'C') c += 6; continue;\n if (b === 'D') c += 12; continue;\n if (b === 'I') c += 20; continue;\n if (b === 'O') c += 8; continue;\n if (b === 'T') c += 4; continue;\n}\n\nprint(c);\n"}, {"source_code": "var a = readline(), b, c = 0;\n\nfor (; a > 0; a--) {\n b = readline()[0];\n if (b === 'C') c += 6; continue;\n if (b === 'D') c += 12; continue;\n if (b === 'I') c += 20; continue;\n if (b === 'O') c += 8; continue;\n if (b === 'T') c += 4; continue;\n}\n\nprint(c);\n"}, {"source_code": "var a = readline(), b = {c: 6, d: 12, i: 20, o: 8, t: 4}, c = 0;\n\nfor (; a > 0; a--) {\n c += b[readline()[0]]\n}\n\nprint(c);"}, {"source_code": "var numbers = readline();\nvar a = numbers[0];\n var number = readline().split(\"\\n\");\nvar b = 0;\nfor(var i=0; i {\n const shapeNames = [] ; \n rl.on('line', (shapeName) => {\n i++;\n shapeNames.push(shapeName) ; \n if (i >= parseInt(number)) {\n calFacesNum(shapeNames) ; \n rl.close();\n }\n });\n});\n\n\nfunction calFacesNum(faces) {\n let facesNumber = 0;\n for (let i = 0; i < faces.length; i++) {\n\n switch (faces[i]) {\n case 'Tetrahedron':\n facesNumber += 4;\n break;\n case 'Cube':\n console.log('hello amir is here') ;\n facesNumber += 6;\n break;\n case 'Octahedron':\n facesNumber += 8;\n break;\n case 'Dodecahedron':\n facesNumber += 12;\n break;\n case 'Icosahedron':\n facesNumber += 20;\n break;\n }\n }\n console.log(facesNumber) ;\n}\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, ...geometry] = input\n count = parseInt(count, 10)\n function returnCountGeometry(el){\n switch(el){\n case 'Tetrahedron': {\n return 4\n } break;\n case 'Cube': {\n return 6\n } break;\n case 'Octahedron': {\n return 8\n } break;\n case 'Dodecahedron': {\n return 12\n } break;\n case 'Icosahedron': {\n return 20\n } break;\n default: {\n return 0\n }\n }\n }\n let _fin = 0\n for (let i = 0; i < count; i ++) {\n const el = geometry[i]\n const counter = returnCountGeometry(el)\n _fin += counter\n }\n console.log(_fin)\n});"}, {"source_code": "function IO(rs, ws, readSize = 1024) {\n let buffer = Buffer.from([]);\n let nextLineIndex;\n let line;\n let chunk;\n\n return {\n rl() {\n while(true) {\n newLineIndex = buffer.indexOf('\\n');\n\n if (newLineIndex === -1 && rs.readableLength === 0) {\n newLineIndex = buffer.length;\n }\n\n if (newLineIndex !== -1) {\n line = buffer.slice(0, newLineIndex);\n\n buffer = buffer.slice(newLineIndex + 1);\n\n return line.toString('utf-8');\n }\n\n if (rs.readableLength === 0) {\n return null\n }\n\n chunk = rs.read(Math.min(readSize, rs.readableLength));\n\n if (!chunk) { return null; }\n\n buffer = Buffer.concat([ buffer, chunk ]);\n }\n },\n\n wr(str) {\n return ws.write(str);\n },\n\n wl(str) {\n return ws.write(str + '\\n');\n }\n };\n}\n\nprocess.stdin.once('readable', () => sol(IO(process.stdin, process.stdout)));\n\nfunction sol({ rl, wr, wl }) {\n const grani = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20,\n };\n\n const n = Number(rl());\n let sum = 0;\n\n for (let i = 0; i < n; i += 1) {\n const f = rl()[0];\n sum += grani[f];\n }\n\n return wl(sum);\n}\n"}, {"source_code": "// Nothing special here, just self-made reading api\nclass Reader{constructor(a,b){this.stream=a,this.stream.setEncoding(\"utf8\"),this.bufSize=b||1024,this.buf=\"\",this.streamEnded=!1}onReadable(a){return()=>{for(let b;-1===(b=this.buf.indexOf(\"\\n\"));){if(0===this.stream.readableLength)return this.stream.read(),void this.stream.once(\"readable\",this.onReadable(a));this.buf+=this.stream.read(Math.min(this.bufSize,this.stream.readableLength))}this.stream.removeAllListeners(\"end\"),this.readline().then(a)}}onEnd(a){return()=>{this.streamEnded=!0,this.readline().then(a)}}readline(){return new Promise(a=>{const b=this.buf.indexOf(\"\\n\");if(-1===b&&!this.streamEnded)this.stream.once(\"readable\",this.onReadable(a)),this.stream.once(\"end\",this.onEnd(a));else{let c;this.streamEnded?(c=this.buf,this.buf=\"\"):(c=this.buf.substring(0,b),this.buf=this.buf.substring(b+1)),a(c)}})}}(async()=>{const a=new Reader(process.stdin);await solution(a.readline.bind(a),console.log.bind(this))})();\n\nasync function solution(rl, wl) {\n const grani = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20,\n };\n const n = parseInt((await rl()), 10);\n let sum = 0;\n for (let i = 0; i < n; i += 1) {\n const f = (await rl())[0];\n sum += grani[f];\n }\n wl(sum);\n}\n"}, {"source_code": "function IO(rs, ws, readSize = 1024) {\n let buffer = Buffer.from([]);\n let nextLineIndex;\n let line;\n let chunk;\n \n return {\n rl() {\n while(true) {\n newLineIndex = buffer.indexOf('\\n');\n \n if (newLineIndex === -1 && rs.readableLength === 0) {\n newLineIndex = buffer.length;\n }\n \n if (newLineIndex !== -1) {\n line = buffer.slice(0, newLineIndex);\n \n buffer = buffer.slice(newLineIndex + 1);\n \n return line.toString('utf-8');\n }\n \n if (rs.readableLength === 0) {\n return null\n }\n \n chunk = rs.read(Math.min(readSize, rs.readableLength));\n \n if (!chunk) { return null; }\n \n buffer = Buffer.concat([ buffer, chunk ]);\n }\n },\n \n wr(str) {\n return ws.write(str);\n },\n \n wl(str) {\n return ws.write(str + '\\n');\n }\n };\n }\n \n process.stdin.once('readable', () => sol(IO(process.stdin, process.stdout, 32)));\n \n function sol({ rl, wr, wl }) {\n const grani = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20,\n };\n \n const n = Number(rl());\n let sum = 0;\n \n for (let i = 0; i < n; i += 1) {\n const f = rl()[0];\n sum += grani[f];\n\n if (Number.isNaN(sum)) {\n return wl(`${f} ${i}`);\n }\n }\n \n return wl(sum);\n }"}, {"source_code": "function IO(rs, ws, readSize = 1024) {\n let buffer = Buffer.from([]);\n let nextLineIndex;\n let line;\n let chunk;\n \n return {\n rl() {\n while(true) {\n newLineIndex = buffer.indexOf('\\n');\n \n if (newLineIndex === -1 && rs.readableLength === 0) {\n newLineIndex = buffer.length;\n }\n \n if (newLineIndex !== -1) {\n line = buffer.slice(0, newLineIndex);\n \n buffer = buffer.slice(newLineIndex + 1);\n \n return line.toString('utf-8');\n }\n \n if (rs.readableLength === 0) {\n return null\n }\n \n chunk = rs.read(Math.min(readSize, rs.readableLength));\n \n if (!chunk) { return null; }\n \n buffer = Buffer.concat([ buffer, chunk ]);\n }\n },\n \n wr(str) {\n return ws.write(str);\n },\n \n wl(str) {\n return ws.write(str + '\\n');\n }\n };\n }\n \n process.stdin.once('readable', () => sol(IO(process.stdin, process.stdout, 32)));\n \n function sol({ rl, wr, wl }) {\n const grani = {\n T: 4,\n C: 6,\n O: 8,\n D: 12,\n I: 20,\n };\n \n const n = Number(rl());\n let sum = 0;\n \n for (let i = 0; i < n; i += 1) {\n const f = rl()[0];\n sum += grani[f];\n\n if (Number.isNaN(sum)) {\n return wl(f);\n }\n }\n \n return wl(sum);\n }"}, {"source_code": "'use strict';\n \nlet input = [];\nlet count_flow = {\n 'Icosahedron': 20,\n 'Cube': 6,\n 'Tetrahedron': 4,\n 'Dodecahedron': 12,\n 'Octahedron': 8,\n}\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n line.split(' ').map(x => input.push(x));\n});\n\nRL.on('close', () => {\n let n = parseInt(input[0]), sum = 0;\n console.log(input);\n for (let i = 1; i <= n; i++)\n sum += count_flow[input[i]];\n console.log(sum);\n});\n\n"}, {"source_code": "let heterolist = [];\nlet gayNum = 0;\nlet iter = 0;\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction checkSum(line){\n if (line == 'Tetrahedron'){\n return 4;\n } else if (line == 'Cube'){\n return 6;\n } else if (line == 'Octahedron'){\n return 8;\n } else if (line == 'Dodecahedron'){\n return 12;\n } else if (line == 'Icosahedron'){\n return 20;\n }\n};\n\nrl.question('', (answer) => {\n sizeOfArray = answer;\n console.log('sizeOfArray', answer);\n});\n\nrl.on('line', (line) => {\n //heterolist.push(line.split(' ', 1).map(String));\n gayNum += checkSum(line.split(' ', 1).map(String));\n iter++;\n if(iter == sizeOfArray){\n console.log(gayNum);\n process.exit(0);\n } \n});\n"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n };\n let total = 0;\n \n const inputArray = input.split(\"\\n\");\n for(let i = 1; i< inputArray.length; i++) {\n total = total + reference[inputArray[i]];\n }\n console.log(total);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n tetrahedron: 4,\n cube: 6,\n octahedron: 8,\n dodecahedron: 12,\n icosahedron: 20\n };\n let total = 0;\n const inputArray = input.split('\\r\\n');\n console.log(inputArray)\n for(let i = 1; i< inputArray.length; i++) {\n total = total + reference[inputArray[i].toLowerCase()];\n }\n console.log(total);\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n \nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n };\n let total = 0;\n const inputArray = input.split('\\r\\n');\n for(let i = 1; i< inputArray.length; i++) {\n total = total + reference[inputArray[i]];\n }\n console.log(total);\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n \nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n };\n let total = 0;\n \n const inputArray = input.split(\"\\n\");\n console.log(inputArray);\n for(let i = 1; i< inputArray.length; i++) {\n reference[inputArray[i]];\n total = total + reference[inputArray[i]];\n }\n console.log(total);\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n \nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "function main(input) {\n //Enter your code here\n const reference = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n };\n let total = 0;\n const inputArray = input.split(\"\\r\\n\");\n for(let i = 1; i< inputArray.length; i++) {\n total = total + reference[inputArray[i]];\n }\n console.log(total);\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n \nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n \nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "const names = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\nprocess.stdin.on('data', (input) => {\n process.stdout.write(input.toString().split('\\n').slice(1).map((x) => names[x.trim()]).reduce((x, y) => x + y).toString());\n});"}, {"source_code": "const names = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\n\n\nprocess.stdin.on('data', (input) => {\n process.stdout.write(input.toString().split('\\n').slice(1).map((x) => names[x.trim()]).reduce((x, y) => x + y).toString());\n});"}, {"source_code": "const names = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\n\nprocess.stdin.on('data', (input) => {\n process.stdout.write(input.toString().trim().split('\\n').slice(1).map((x) => names[x.trim()]).reduce((x, y) => x + y).toString());\n});"}, {"source_code": "const names = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n};\n\nprocess.stdin.on('data', (input) => {\n process.stdout.write(input.toString().trim().split('\\n').slice(1).map((x) => names[x.trim()]).reduce((x, y) => x + y).toString());\n});"}, {"source_code": "var input='';\n\nprocess.stdin.on('data',(givenInput)=>{\n input+=givenInput;\n})\n\nprocess.stdin.on('end',()=>{\n main(input);\n})\n\nconst main=(input)=>{\n\n const n=Number(input.split('\\r\\n')[0]);\n let strArr=input.split('\\r\\n');\n\n let num,total=0;\n\n for(let i=1;i{\n input+=givenInput;\n})\n\nprocess.stdin.on('end',()=>{\n main(input);\n})\n\nconst main=()=>{\n\n const n=Number(input.split('\\r\\n')[0]);\n let strArr=input.split('\\r\\n');\n\n let num,total=0;\n\n for(let i=1;i inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let s = readline().split('');\r\n\r\n let pot = (i, char) => {\r\n if ((i === 'L' && i > (s.length / 2)) || (i === 'R' && i < (s.length / 2))) {\r\n return 0;\r\n }\r\n let left = val(i, 'L');\r\n let right = val(i, 'R');\r\n if (char === 'L' && left > right) {\r\n return 0;\r\n } else if (char === 'R' && right > left) {\r\n return 0;\r\n } else if (left === right) {\r\n return 0;\r\n }\r\n let max = Math.max(left, right);\r\n let min = Math.min(left, right);\r\n return max - min;\r\n };\r\n\r\n let val = (i, dir) => {\r\n if (dir === 'L') {\r\n return i;\r\n } else {\r\n return s.length - i - 1;\r\n }\r\n }\r\n\r\n let sum = s.map((char, index) => val(index, char)).reduce((a, b) => a + b, 0);\r\n\r\n let v = s.map((val, i) => ({ diff: pot(i, val), i }));\r\n v.sort((a, b) => b.diff - a.diff);\r\n\r\n let values = [];\r\n for (let i = 0; i < n; i++) {\r\n sum += v[i].diff;\r\n values.push(sum);\r\n }\r\n\r\n output(values.join(' '));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on('close', () => {\r\n const readLine = createReadLine();\r\n let t = parseInt(readLine())\r\n while (t--) {\r\n const n = parseInt(readLine())\r\n const people = readLine()\r\n\r\n let ans = 0\r\n let res = ''\r\n let values = []\r\n for (let i = 0; i < n; i++) {\r\n if (people[i] == 'L') {\r\n values.push(n - i - 1 - i)\r\n ans += i\r\n } else {\r\n values.push(i - (n - i - 1))\r\n ans += n - i - 1\r\n }\r\n }\r\n\r\n values.sort((a, b) => a - b)\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (values[n - i - 1] > 0) {\r\n ans += values[n - i - 1]\r\n }\r\n res += `${ans} `\r\n }\r\n console.log(res)\r\n }\r\n})"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst LowerBound = (arr, val) =>\r\n{\r\n let ng = -1;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] >= val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\nconst ReverseLowerBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] <= val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d val\r\n return ng;\r\n}\r\n\r\n\r\nconst ReverseUpperBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] < val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 val\r\n return ng;\r\n}\r\n\r\nconst UpperBound = (arr, val) =>\r\n{\r\n let ok = arr.length;\r\n let ng = -1;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] > val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\n\r\nconst Calc = (c, i, n) =>\r\n{\r\n if (c === 'L')\r\n {\r\n return i;\r\n }\r\n else return n - i - 1;\r\n}\r\n\r\n\r\n\r\n\r\nconst R = (c) =>\r\n{\r\n if (c === 'R') return 'L';\r\n if (c === 'L') return 'R';\r\n}\r\n\r\n\r\n\r\nclass Container\r\n{\r\n i = -1;\r\n score = -1;\r\n constructor(i, score)\r\n {\r\n this.i = i;\r\n this.score = score;\r\n }\r\n}\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = +sc.N();\r\n let arr = [...sc.S()];\r\n\r\n let res = [];\r\n\r\n let t = 0;\r\n for (let i = 0; i < n; ++i)\r\n {\r\n t += Calc(arr[i], i, n);\r\n }\r\n\r\n // console.log(`t = ${t}`);\r\n\r\n let big = [];\r\n\r\n\r\n\r\n\r\n for (let i = 0; i < n; ++i)\r\n {\r\n let one = Calc(arr[i], i, n);\r\n let two = Calc(R(arr[i]), i, n);\r\n\r\n // let max = Math.max(one, two);\r\n // let min = Math.min(one, two);\r\n //\r\n // console.log(`min = ${min} and max = ${max}`);\r\n //\r\n // t -= min;\r\n // t += max;\r\n\r\n // console.log(`two = ${two} and ${one}`);\r\n\r\n let score = 0 - one;\r\n score += two;\r\n\r\n big.push(new Container(i, score));\r\n\r\n // res[idx++] = t;\r\n }\r\n\r\n big.sort((l, r) =>\r\n {\r\n return r.score - l.score;\r\n });\r\n\r\n // for (let o of big)\r\n // {\r\n // console.log(`o.i = ${o.i} and o.score = ${o.score}`);\r\n // }\r\n\r\n for (let i = 0; i < n; ++i)\r\n {\r\n if (big[i].score > 0)\r\n {\r\n t += big[i].score;\r\n }\r\n\r\n // console.log(`t = ${t}`);\r\n res.push(t);\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n console.log(res.join(' '));\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = +sc.L();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = next();\r\n\t\tvar sum = 0;\r\n\t\tvar add = [];\r\n\t\tfor(var i = 0; i < N / 2; i++){\r\n\t\t\tif(S[i] == \"L\"){\r\n\t\t\t\tadd.push(N - i - 1 - i);\r\n\t\t\t\tsum += i;\r\n\t\t\t}else{\r\n\t\t\t\tsum += N - i - 1;\r\n\t\t\t}\r\n\t\t\tif(S[N - i - 1] == \"R\"){\r\n\t\t\t\tadd.push(N - i - 1 - i);\r\n\t\t\t\tsum += i;\r\n\t\t\t}else{\r\n\t\t\t\tsum += N - i - 1;\r\n\t\t\t}\r\n\t\t\tif(N % 2 == 1 && i == Math.floor(N / 2)){\r\n\t\t\t\tsum -= i;\r\n\t\t\t\tadd.pop();\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tadd.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar output = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(i < add.length){\r\n\t\t\t\tsum += add[i];\r\n\t\t\t}\r\n\t\t\toutput.push(sum);\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n const arr = []\n let s = 0\n for (let i = 0; i < str.length; i++) {\n const l = i\n const r = n - 1 - l\n if (str[i] === 'L') {\n arr[i] = [i, l, r - l]\n s += l\n } else {\n arr[i] = [i, r, l - r]\n s += r\n }\n }\n // console.log(s, arr)\n return arr.sort((a, b) => b[2] - a[2])\n .map(([i, now, d]) => {\n if (d > 0) {\n s += d\n }\n return s\n }).join(' ')\n}\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n\r\n\r\nwhile(t--){\r\n \r\n var n = parseInt(readline());\r\n var middle = parseInt(n/2);\r\n var s = readline();\r\n var bestValue = [];\r\n var res = 0;\r\n for(var i = 0; i < n; i++){\r\n var crntValue = s[i] === \"L\"? i : n - i - 1;\r\n res += crntValue;\r\n bestValue.push((i < middle? n - i - 1: i) - crntValue);\r\n }\r\n bestValue.sort((a, b ) => b - a);\r\n var resS = \"\";\r\n for(var i = 0; i < n; i++){\r\n res += bestValue[i]\r\n resS += res;\r\n if(i !== n-1) resS += \" \";\r\n \r\n }\r\n \r\n \r\n \r\n print(resS);\r\n \r\n\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split('');\r\n\r\n if (n === 1) {\r\n print('0');\r\n continue;\r\n }\r\n\r\n var ans = [];\r\n\r\n var value = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (arr[i] === 'R') {\r\n value = value + n - i - 1;\r\n } else {\r\n value = value + i;\r\n }\r\n }\r\n\r\n var left = 0;\r\n var right = n - 1;\r\n\r\n var counter = () => {\r\n while (2 * left < n - 1 && arr[left] === 'R') {\r\n ++left;\r\n }\r\n while (2 * right > n - 1 && arr[right] === 'L') {\r\n --right;\r\n }\r\n if (2 * left >= n - 1 && 2 * right <= n - 1) {\r\n return value;\r\n }\r\n if (n - 1 - 2 * left >= right - (n - 1 - right)) {\r\n value += n - 1 - 2 * left;\r\n ++left;\r\n } else {\r\n value += right - (n - 1 - right);\r\n --right;\r\n }\r\n return value;\r\n }\r\n\r\n for (var k = 1; k <= n; k++) {\r\n ans.push(counter());\r\n }\r\n\r\n print(ans.join(' '));\r\n}\r\n"}, {"source_code": "var n, s;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t (n-1-i)) && s[i] == 'R'){\r\n vec.push(-n+1+i+i);\r\n }\r\n }\r\n vec.sort((a,b) => b-a);\r\n var ans = 0;\r\n var m = vec.length;\r\n var res = [];\r\n for(var k = 0; k {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ').map(a => a.replace('\\r', ''))\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[1]\n const m = arr1[2]\n const wordIndexMap = {}\n\n if(n == 100) {\n // console.log(arr1[n-1], arr2, cost)\n }\n\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ').map(a => a.replace('\\r', ''))\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ').map(a => a.replace('\\r', ''))\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[1]\n const m = arr1[2]\n const wordIndexMap = {}\n\n if(n == 100) {\n // console.log(arr1[n-1], arr2, cost)\n }\n\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ').map(a => a.replace('\\r', ''))\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ')\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[2]\n const m = arr1[2]\n const wordIndexMap = {}\n console.log(arr2)\n\n if(arr2[n - 1].includes('\\r')) arr2[n - 1].replace('\\r', '')\n\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ')\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ')\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[2]\n const m = arr1[2]\n const wordIndexMap = {}\n console.log(arr2)\n\n if(arr2[n - 1].includes('\\r')) arr2[n - 1].replace(/(\\r\\n|\\n|\\r)/gm, '')\n console.log(arr2)\n\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ')\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ')\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[2]\n const m = arr1[2]\n const wordIndexMap = {}\n console.log(arr2)\n\n if(arr2[n - 1].includes('\\r')) arr2[n - 1].replace('\\r', '')\n console.log(arr2)\n\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ')\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const arr1 = arr.shift().split(' ').map(a => parseInt(a))\n const arr2 = arr.shift().split(' ')\n const cost = arr.shift().split(' ').map(a => parseInt(a))\n const n = arr1[0]\n const k = arr1[2]\n const m = arr1[2]\n const wordIndexMap = {}\n console.log(arr2)\n arr2.forEach((element, i) => {\n wordIndexMap[element] = {}\n wordIndexMap[element].index = i + 1\n });\n\n const groups = []\n\n for(let i = 0; i < k; i++) {\n const arr4 = arr[i].split(' ').map(a => parseInt(a))\n arr4.shift()\n arr4.forEach((a) => {\n wordIndexMap[arr2[a - 1]].group = i\n if(!groups[i]) groups[i] = cost[a - 1]\n else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]\n })\n }\n\n let sum = 0\n\n const me = arr[k].split(' ')\n\n for(let i = 0; i < m; i++) {\n const a = me[i]\n sum += groups[wordIndexMap[a].group]\n }\n\n console.log(sum)\n\n})"}], "src_uid": "296552dc2df23b3920baef7d47d0a591"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = [];\r\n if (n >= 20) {\r\n output('NO');\r\n continue;\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = 3 ** i;\r\n }\r\n\r\n output('YES');\r\n output(arr.join(' '));\r\n }\r\n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k > 19){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += Math.pow(3, l) + ' '\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var t = lines[0];\n\tfor(i = 1; i <= t; i++) {\n\t var a = lines[i];\n if(a < 20){\n console.log('YES');\n var ans = '';\n var b = 1;\n for(j = 0; j < a; j++){\n ans += b + ' ';\n b *= 3;\n }\n console.log(ans);\n }else{\n console.log('NO');\n }\n\t}\n});"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n > 19) {\r\n console.log('NO');\r\n return;\r\n }\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n res.push(3 ** i);\r\n }\r\n console.log('YES');\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n solve(n);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = n=>{\n let ans = [1];\n while (ans.length {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n // let isPalindrome = true;\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n if (n > 19) {\n console.log(\"NO\");\n } else {\n console.log(\"YES\");\n let result = [1];\n let counter = 2;\n while (counter <= n) {\n result.push(result[result.length - 1] * 3);\n counter++;\n }\n console.log(result.join(\" \"));\n }\n }\n}\n"}, {"source_code": "var n = readline(), s, m, k, ans;\r\n \r\nwhile (n--) {\r\n ans = '';\r\n\ts = readline();\r\n\tm = Math.pow(3, s - 1);\r\n\tk = Math.pow(10, 9);\r\n\tif (m > k) { \r\n\t print('NO');\r\n\t} else {\r\n\t print('YES');\r\n\t for (var i = 0; i < s; i++) {\r\n\t ans += `${Math.pow(3, i)} `;\r\n\t }\r\n\t print(ans);\r\n\t}\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tfor(i = 1; i <= t; i++) {\n\t var a = lines[i];\n if(a < 20){\n console.log('YES');\n var ans = '';\n var b = 1;\n for(j = 0; j < a; j++){\n ans += b + ' ';\n b *= 3;\n }\n console.log(ans);\n }else{\n console.log('NO');\n }\n\t}\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 19){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}], "negative_code": [{"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 19){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 4;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 19){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 2;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 20){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 21){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 22){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 23){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 25){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 30){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n var a = 1;\n if(k <= 18){\n for(i = 0; i < k; i++){\n ans += a + ' ';\n a *= 3;\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var a = [1, 3, 9, 27, 81];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var ans = '';\n if(k < 5){\n for(i = 0; i < k; i++){\n ans += a[i] + ' ';\n }\n console.log('YES' + \"\\n\" + ans);\n \n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0]; var b = k[1];\n if(a == 1){\n console.log(0);\n }else if(a == 2){\n console.log(b);\n }else{\n console.log(b * 2);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k >= 19){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += Math.pow(3, l) + ' '\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k > 20){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += Math.pow(3, l) + ' '\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k > 5){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += Math.pow(3, l) + ' '\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k > 5){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += Math.pow(3, l)\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = [1, 3, 9, 27, 81]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k > 5){\n console.log('NO')\n }else{\n g = ''\n for(l = 0; l < k; l++){\n g += a[l] + ' '\n }\n console.log('YES' + '\\n' + g)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = parseInt(lines[0], 2), e = 0, g =0\n \n while(Math.pow(4, e) < n){\n e++\n }\n var b = lines[0].split('')\n var c = lines[0].split('')\n b.reverse()\n f = false\n for(j = 0; j < b.length; j++){\n if(b[j] == c[j]){\n f = true\n }else{\n f = false\n break;\n }\n }\n if(f === true && b.length >= 60 && b[30] == 0){\n e++\n }\n console.log(e)\n \n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = [];\r\n if (n >= 30) {\r\n output('NO');\r\n continue;\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = 2 ** i;\r\n }\r\n\r\n output('YES');\r\n output(arr.join(' '));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n >= 19) {\r\n console.log('NO');\r\n return;\r\n }\r\n let res = [];\r\n for (let i = 0; i <= n; i++) {\r\n res.push(3 ** i);\r\n }\r\n console.log('YES');\r\n console.log(res.join(' '));\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n solve(n);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "c8fddee2f1c7d325437a7d0b82758b03"} {"source_code": "var n = +readline();\n\nvar ans = \"NO\";\nfor(var i = 0; i < n; i++){\n var rating = readline().split(\" \").slice(1).map(Number);\n\n if(rating[0] >= 2400 && rating[1] > rating[0]){\n ans = \"YES\";\n break;\n }\n}\n\nwrite(ans);", "positive_code": [{"source_code": "var n = readline();\nvar check = true;\nfor(i=0;i= 2400 && Number(y[2]) > Number(y[1])){\n print(\"YES\")\n check = false;\n break;\n }\n}\nif(check == true){\n print(\"NO\");\n}"}, {"source_code": "var n = Number(readline());\n\nvar answer = \"NO\";\n\nfor (var i = 1; i <= n; ++i) {\n var line = readline().split(' ')\n var before = parseInt(line[1]);\n var after = parseInt(line[2]);\n if (2400 <= before && before < after) {\n answer = \"YES\";\n }\n}\nprint(answer);\n"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, participant, scores, answer;\n\nn = Number(readline());\n\nfor (i = 0; i < n; i++) {\n\n answer = 'NO';\n participant = readline().replace(/\\r$/, '').split(' ');\n scores = [Number(participant[1]), Number(participant[2])];\n\n if (scores[0] < 2400) {continue};\n if (scores[1] <= scores[0]) {continue};\n\n answer = 'YES';\n break\n}\n\nprint(answer);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 'NO';\nconst redRating = 2400;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [participant, startRating, endRating] = d.split(' ');\n if (+startRating < +endRating && +startRating >= redRating) {\n ans = 'YES';\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var n = readline();\nvar user;\nvar flag = 0;\nfor (var i = 0; i < n; i++){\n\tuser = readline().split(\" \");\n\tif(parseInt(user[1]) >= 2400 && parseInt(user[2]) > parseInt(user[1]))\n\t\tflag = 1;\n}\nprint((flag) ? \"YES\" : \"NO\");"}, {"source_code": "var n = readline();\nvar flag = 0\nfor(i=0;i= 2400 && after > before){\n \tflag = 1;\n print(\"YES\");\n break;\n }\n}\nif(flag == 0){\n\tprint(\"NO\")\n}"}, {"source_code": "\tfunction main(){\n\tvar line1 = readline();\n\tfor (var i = 0; i=2400 & result>0) \n\t\t{\n\t\tprint('YES');\n\t\treturn 0;\n\t\t\n\t\t\t}\n\n\t\t\t\n\t};\n\tprint(\"NO\");\n\t};\n\nmain();\n\n"}, {"source_code": "var n = parseInt(readline().trim());\nvar goodPerf = false;\nfor (var i = 0; i < n; i++) {\n var inpStr = readline().trim().split(' ');\n if (!goodPerf && parseInt(inpStr[1]) >= 2400 && parseInt(inpStr[2]) > inpStr[1]) {\n goodPerf = true;\n }\n}\nprint((goodPerf) ? 'YES' : 'NO');\n"}, {"source_code": ";(function () {\n\tvar n = parseInt(readline())\n\n\tfor (var i = 1; i <= n; i++) {\n\t\tvar s = readline().split(' '),\n\t\t\tx = parseInt(s[1]),\n\t\t\ty = parseInt(s[2]);\n\n\t\tif (x >= 2400 && y > x)\n\t\t\treturn print(\"YES\");\n\t}\n\tprint(\"NO\");\n})();\n"}, {"source_code": "var flag = 0;\nvar n = readline();\nfor( var i = 0; i < n; i++)\n{\n var value = readline().split(\" \");\n if(parseInt(value[1]) >= 2400 && parseInt(value[2]) > parseInt(value[1]))\n flag = 1;\n}\n\nif(flag != 0) print(\"YES\");\nelse print(\"NO\");"}, {"source_code": "var numberOfResults = readline();\nvar improved = 'NO';\nfor (var i=0; i= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {\n improved = 'YES';\n break;\n }\n}\nprint(improved);"}, {"source_code": "\nvar n=parseInt(readline());\nvar res=\"\";\nvar ar=new Array(n);\nfor (var i=0;i=2400&&num2>num1){ res=\"YES\";break;}\n\n}if(res===\"YES\"){print(\"YES\\n\");}\nelse{print(\"NO\\n\");}"}, {"source_code": "var n = parseInt(readline());\nfor(i = 0; i < n; i++) {\n var t = readline().split(' ');\n var t1 = parseInt(t[1]);\n var t2 = parseInt(t[2]);\n if(t12399) {\n print(\"YES\");\n quit(0);\n }\n}\nprint(\"NO\");"}, {"source_code": "var n = parseInt(readline());\nvar s=Array(n);\nfor(var i = 0; i=2400 && s[i][1]>s[i][0]) return 'YES';} return 'NO'};\nprint(p());"}], "negative_code": [{"source_code": "var n, before, after, name, flag = 0;\n\nn = readline(\"\\n\");\nfor( var i = 0; i < n; i++)\n{\n name = readline(\"\\n\");\n before = readline(\"\\n\");\n after = readline(\"\\n\");\n\n if(before >= 2400 && after > before)\n flag++;\n}\n\nif(flag != 0) print(\"YES\");\nelse print(\"NO\");"}, {"source_code": "var n = readline();\nvar check = true;\nfor(i=0;i= 2400 && y[2] > y[1]){\n print(\"YES\")\n check = false;\n break;\n }\n}\nif(check == true){\n print(\"NO\");\n}"}, {"source_code": "var n = readline();\nvar check = true;\nfor(i=0;i 2400 && y[2] > y[1]){\n print(\"YES\")\n check = false;\n break;\n }\n}\nif(check == true){\n print(\"NO\");\n}"}, {"source_code": "var n = Number(readline());\n\nprint(n);\n\nvar answer = \"NO\";\n\nfor (var i = 1; i <= n; ++i) {\n var line = readline().split(' ')\n print(line);\n var before = parseInt(line[1]);\n var after = parseInt(line[2]);\n if (2400 <= before && before < after) {\n answer = \"YES\";\n }\n}\nprint(answer);\n"}, {"source_code": "var n = Number(readline());\n\nvar answer = \"NO\";\n\nfor (var i = 1; i <= n; ++i) {\n var line = readline().split(' ');\n var before = parseInt(line[1]);\n var after = parseInt(line[2]);\n if (2400 < before && before < after) {\n answer = \"YES\";\n }\n print(answer);\n}\n"}, {"source_code": "var n = readline();\nvar user;\nvar flag = 0;\nfor (var i = 0; i < n; i++){\n\tuser = readline().split(\" \");\n\tif(user[1] >= 2400 && user[2] > user[1])\n\t\tflag = 1;\n}\nprint((flag) ? \"YES\" : \"NO\");"}, {"source_code": "var n = readline();\nfor(i=0;i= 2400 && after >before){\n print(\"YES\");\n break;\n }\n}"}, {"source_code": "var n = readline();\nfor(i=0;i= 2400 && after >2400){\n print(\"YES\");\n break;\n }\n}"}, {"source_code": "var n = readline();\nfor(i=0;i= 2400 && after > before){\n print(\"YES\");\n break;\n }\n}\nprint(\"NO\");"}, {"source_code": "var n = readline();\nfor(i=0;i= 2400 && after > before){\n print(\"YES\");\n break;\n }\n}"}, {"source_code": ";(function () {\n\tvar x = parseInt(readline())\n\n\tfor (var i = 1; i <= x; i++) {\n\t\tvar s = readline().split(' '),\n\t\t\tx = parseInt(s[1]),\n\t\t\ty = parseInt(s[2]);\n\n\t\tif (x >= 2400 && y > x)\n\t\t\treturn print(\"YES\");\n\t}\n\tprint(\"NO\");\n})();\n"}, {"source_code": "function performedGood(inputString) {\n var lines = inputString.split(\"\\n\");\n for (var i=1; i= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {\n console.log('YES');\n return 'YES';\n }\n }\n console.log('NO');\n return 'NO';\n}"}, {"source_code": "function performedGood(inputString) {\n var lines = inputString.split(\"\\n\");\n for (var i=1; i= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {\n return 'YES';\n }\n }\n return 'NO';\n}"}, {"source_code": "function performedGood(input) {\n var lines = input.split(\"\\n\");\n for (var i=1; i= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {\n return 'YES';\n }\n }\n return 'NO';\n}"}], "src_uid": "3bff9b69423cf6c8425e347a4beef96b"} {"source_code": "const { on } = require('process');\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar indicator = 0, ans = 0, temp = [], n, d, cont = [];\n\nrl.on('line', (input) => {\n\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n n = temp[0], d = temp[1];\n indicator++;\n }\n else {\n\n cont = input.split(' ').map(item => parseInt(item));\n for (let i = 0; i < n - 1; i++)\n for (let j = i + 1; j < n; j++)\n if (Math.abs(cont[i] - cont[j]) <= d)\n ans += 2;\n\n console.log(ans);\n rl.close();\n }\n\n});\n\n/*\n\n i j\n10 20 30 40 50 60\n\n\n*/", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar indicator = 0;\nvar soldiers, heightDiff;\nvar temp = [];\nvar ans = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n temp = input.split(' ').map(item => parseInt(item));\n soldiers = temp[0];\n heightDiff = temp[1];\n indicator++;\n }\n else {\n temp = input.split(' ').map(item => parseInt(item));\n for (let i = 0; i < soldiers - 1; i++) {\n for (let j = i + 1; j < soldiers; j++) {\n if (Math.abs(temp[i] - temp[j]) <= heightDiff)\n ans += 2;\n }\n }\n console.log(ans);\n rl.close();\n }\n\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, d;\nlet arr;\n\nrl.on('line', (data) => {\n if (c === 0) {\n c++;\n [n, d] = data.split(' ').map(Number);\n return;\n }\n\n arr = data.split(' ').map(Number);\n let ans = 0;\n\n for (let i = 0; i < arr.length ; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (i !== j) {\n const v = Math.abs(arr[i] - arr[j]);\n if(v <= d) {\n ans++;\n }\n }\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n var temp = [], indicator = 0, ans = 0, n , d;\n\n rl.on('line', (input) => {\n if(indicator==0){\n temp = input.split(' ').map(x=>parseInt(x));\n n = temp[0], d = temp[1];\n indicator++;\n } else {\n temp = input.split(' ').map(x=>parseInt(x));\n for (let i=0; i parseInt(v))\nlet N = lll[0]\nlet D = lll[1]\n\nlll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)\n\nlet co = 0\n\nfor (let i = 0; i < N - 1; i++) {\n let j = i + 1\n while (lll[j++] - lll[i] <= D) co++\n}\n\nprint(co * 2)"}, {"source_code": "var input;\ninput = readline().split(\" \").map(function(a){return parseInt(a)});\nvar n = input[0];\nvar d = input[1];\nvar sizes = readline().split(\" \").map(function(a){return parseInt(a)});\nsizes = sizes.sort(function(a, b){return a - b});\nvar res = 0;\n\nfor (var i = 0; i < n - 1; i++) {\n\tfor (var j = i + 1; j < n; j++) {\n\t\tif ((sizes[j] - sizes[i]) <= d) {\n\t\t\tres++;\n\t\t\tres++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nprint(res);"}], "negative_code": [], "src_uid": "d7381f73ee29c9b89671f21cafee12e7"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probD(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let n = parseInt(readline());\n let s = readline().split('');\n let c = s[n-1];\n let res = '';\n for(let i = 0; i< n; i++){\n res += c;\n }\n\n console.log(res);\n }\n}\n\nfunction probB(){\n let t = parseInt(readline());\n\n while(t > 0){\n t--;\n let [p,f] = readline().split(' ');\n let cap = parseInt(p) + parseInt(f);\n\n let [cs, cw] = readline().split(' ');\n let [s, w] = readline().split(' ');\n\n let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));\n\n let tot = parseInt(cs) + parseInt(cw);\n if(cap > ava){\n console.log(tot);\n continue;\n }\n\n let x = Math.min(parseInt(s), parseInt(w));\n if(parseInt(s) === x){\n if(parseInt(cs) * x > cap){\n console.log(Math.floor(cap / parseInt(cs)));\n }else{\n let rem = cap - (x * parseInt(cs));\n console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));\n }\n }else{\n if(parseInt(cw) * x > cap){\n console.log(Math.floor(cap / parseInt(cw)));\n }else{\n let rem = cap - (x * parseInt(cw));\n console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));\n }\n }\n }\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n\n let s = readline().split('');\n let x = parseInt(readline());\n let isPossible = true;\n\n let w = new Array(s.length);\n for(let i = 0; i < s.length; i++){\n if(s[i] === '0'){\n if(i+x < s.length)\n w[i+x] = '0';\n \n if(i-x >= 0)\n w[i-x] = '0';\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n for(let i = 0; i < s.length; i++){\n if(w[i] !== '0')\n w[i] = '1';\n }\n \n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n if(i+x < s.length && i-x >= 0){\n if(w[i+x] === '0' && w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }\n else if(i+x < s.length){\n if(w[i+x] === '0'){\n isPossible = false;\n break;\n }\n }else if(i-x >= 0){\n if(w[i-x] === '0'){\n isPossible = false;\n break;\n }\n }else{\n isPossible = false;\n break;\n }\n }\n }\n\n if(!isPossible){\n console.log(-1);\n continue;\n }\n\n console.log(w.join(''));\n }\n}\n\nfunction probD(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let n = parseInt(readline());\n let a = readline().split(' ');\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n let left = new Array(n+10);\n left.fill(0);\n let ans = 0;\n for(let i = 0; i < n; i++){\n let right = new Array(n+10);\n right.fill(0);\n for(let j = n-1; j > i; j--){\n ans += left[a[j]] * right[a[i]];\n right[a[j]] += 1;\n }\n left[a[i]] += 1;\n }\n\n console.log(ans);\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const dp = [...Array(len + 1).fill(0)].map((_) => Array(len + 1).fill(0));\n let count = 0;\n\n for (let i = 1; i < len; i++) {\n for (let j = 0; j < i; j++) {\n let [a, b] = [arr[j], arr[i]];\n dp[a][b]++;\n }\n for (let k = i + 2; k < len; k++) {\n let [c, d] = [arr[i + 1], arr[k]];\n count += dp[c][d];\n }\n }\n console.log(count);\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const T = parseInt(readline());\n for (let t=0; t parseInt(x));\n\n let result = 0;\n // left[x] is the number of smaller than index j with value x\n let left = new Array(n+1).fill(0);\n // right[x] is the number of greater than index k with value x\n let right = new Array(n+1).fill(0);\n\n // iterate over each j and k\n for (let j=0; j {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const T = parseInt(readline());\n for (let t=0; t parseInt(x));\n\n let result = 0;\n // left[x] is the number of smaller than index j with value x\n let left = new Array(n).fill(0);\n // right[x] is the number of greater than index k with value x\n let right = new Array(n).fill(0);\n\n // iterate over each j and k\n for (let j=0; j {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet s;\r\nfunction can(l, p) {\r\n let m = l - p;\r\n if (m < p) {\r\n return false;\r\n }\r\n let rem = m - p;\r\n return ((rem % 3) == 0);\r\n}\r\nfunction solve() {\r\n const pre = af(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n if (i > 0) {\r\n pre[i] = pre[i - 1];\r\n }\r\n if (s[i] == '+') {\r\n pre[i]++;\r\n }\r\n }\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 2; j <= n; j++) {\r\n let l = j - i;\r\n let p = pre[j - 1] - ((i > 0) ? pre[i - 1] : 0);\r\n let t = can(l, p);\r\n // printf(\"%s: %d %d can %d\\n\", s.substring(i,j), l, p, t);\r\n if (t) {\r\n ans++;\r\n }\r\n }\r\n }\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n s = nextStr();\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nclass SegTree {\r\n constructor(l, r) {\r\n this.l = l;\r\n this.r = r;\r\n this.root = this._newNode(l, r);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val[z % 3]++;\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n\r\n for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i];\r\n }\r\n\r\n _query(node, x, y, z) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val[z];\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y, z);else if (x > mid) res = this._query(node.right, x, y, z);else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z);\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction solve(n, s) {\r\n let pre = new Array(n + 1).fill(0),\r\n sum = 0,\r\n max = 0,\r\n min = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n sum += s[i] === '+' ? 1 : 0;\r\n pre[i + 1] = i + 1 - 2 * sum;\r\n max = Math.max(max, pre[i + 1]);\r\n min = Math.min(min, pre[i + 1]);\r\n }\r\n\r\n let res = 0;\r\n const segTree = new SegTree(min, max);\r\n\r\n for (let i = 0; i <= n; i++) {\r\n const cur = pre[i];\r\n res += segTree.query(min, cur, (cur % 3 + 3) % 3);\r\n segTree.update(cur, cur, (cur % 3 + 3) % 3);\r\n }\r\n\r\n return res;\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = [];\r\n\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++]);\r\n let str = inputs[__++].trim();\r\n res.push(solve(n, str));\r\n }\r\n\r\n console.log(res.join('\\n'));\r\n}();\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nclass SegTree {\r\n constructor(l, r) {\r\n this.l = l\r\n this.r = r\r\n this.root = this._newNode(l, r)\r\n this.update = this._update.bind(this, this.root)\r\n this.query = this._query.bind(this, this.root)\r\n }\r\n _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {\r\n return { val, l, r, left, right }\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return\r\n const { l, r } = node\r\n if (l === x && r === y) {\r\n node.val[z % 3]++\r\n return\r\n }\r\n const mid = Math.floor((l + r) / 2)\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid)\r\n node.right = this._newNode(mid + 1, r)\r\n }\r\n if (y <= mid) this._update(node.left, x, y, z)\r\n else if (x > mid) this._update(node.right, x, y, z)\r\n else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)\r\n for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]\r\n }\r\n _query(node, x, y, z) {\r\n if (y < x) return 0\r\n if (!node) return 0\r\n const { l, r } = node\r\n if (l === x && r === y) return node.val[z]\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2)\r\n if (y <= mid) res = this._query(node.left, x, y, z)\r\n else if (x > mid) res = this._query(node.right, x, y, z)\r\n else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)\r\n return res\r\n }\r\n}\r\nfunction solve(n, s) {\r\n let pre = new Array(n + 1).fill(0),\r\n sum = 0,\r\n max = 0,\r\n min = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += s[i] === '+' ? 1 : 0\r\n pre[i + 1] = i + 1 - 2 * sum\r\n max = Math.max(max, pre[i + 1])\r\n min = Math.min(min, pre[i + 1])\r\n }\r\n let res = 0\r\n const segTree = new SegTree(min, max)\r\n for (let i = 0; i <= n; i++) {\r\n const cur = pre[i]\r\n res += segTree.query(min, cur, ((cur % 3) + 3) % 3)\r\n segTree.update(cur, cur, ((cur % 3) + 3) % 3)\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++])\r\n let str = inputs[__++].trim()\r\n res.push(solve(n, str))\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst preplus = [0], preminus = [0];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tpreplus[i+1] = preplus[i] + (s[i] == '+');\r\n\t\t\tpreminus[i+1] = preminus[i] + (s[i] == '-');\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i; j < n; j++) {\r\n\t\t\t\tconst pluses = preplus[j+1] - preplus[i];\r\n\t\t\t\tconst minuses = preminus[j+1] - preminus[i];\r\n\t\t\t\tans += minuses >= pluses && (minuses - pluses) % 3 == 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n const sum = []\n const count = [] // of '--'\n let ans = 0\n for (let i = 0; i < n; i++) {\n sum[i] = []\n count[i] = []\n for (let j = i; j < n; j++) {\n const now = str[j] === '+' ? 1 : -1\n sum[i][j] = j > i ? sum[i][j - 1] + now : now\n //\n if (str[j] === '-' && str[j - 1] === '-') {\n count[i][j] = (count[i][j - 2] || 0) + 1\n } else {\n count[i][j] = j > i ? count[i][j - 1] : 0\n }\n //\n if (sum[i][j] === 0) {\n ans++\n } else if (sum[i][j] < 0 && !(sum[i][j] % 3)) {\n if (-sum[i][j] / 3 <= count[i][j]) ans++\n }\n }\n }\n// console.log(sum, count)\n return ans\n}\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nclass SegTree {\r\n constructor(l, r) {\r\n this.l = l\r\n this.r = r\r\n this.root = this._newNode(l, r)\r\n this.update = this._update.bind(this, this.root)\r\n this.query = this._query.bind(this, this.root)\r\n }\r\n _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {\r\n return { val, l, r, left, right }\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return\r\n const { l, r } = node\r\n if (l === x && r === y) {\r\n node.val[z % 3]++\r\n return\r\n }\r\n const mid = Math.floor((l + r) / 2)\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid)\r\n node.right = this._newNode(mid + 1, r)\r\n }\r\n if (y <= mid) this._update(node.left, x, y, z)\r\n else if (x > mid) this._update(node.right, x, y, z)\r\n else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)\r\n for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]\r\n }\r\n _query(node, x, y, z) {\r\n if (y < x) return 0\r\n if (!node) return 0\r\n const { l, r } = node\r\n if (l === x && r === y) return node.val[z]\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2)\r\n if (y <= mid) res = this._query(node.left, x, y, z)\r\n else if (x > mid) res = this._query(node.right, x, y, z)\r\n else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)\r\n return res\r\n }\r\n}\r\nfunction solve(n, s) {\r\n let pre = new Array(n + 1).fill(0),\r\n sum = 0,\r\n max = 0,\r\n min = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += s[i] === '+' ? 1 : 0\r\n pre[i + 1] = i + 1 - 2 * sum\r\n max = Math.max(max, pre[i + 1])\r\n min = Math.min(min, pre[i + 1])\r\n }\r\n let res = 0\r\n const segTree = new SegTree(min, max)\r\n for (let i = 0; i <= n; i++) {\r\n const cur = pre[i]\r\n res += segTree.query(min, cur, (cur + 3) % 3)\r\n segTree.update(cur, cur, (cur + 3) % 3)\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++])\r\n let str = inputs[__++].trim()\r\n res.push(solve(n, str))\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}], "src_uid": "802e4d90444b371a1dbab10d3d589e55"} {"source_code": "var s = \"\";\nvar buf = \"\";\n\ns = readline().split(' ');\n\nvar n = s[0] - 0;\nvar m = s[1] - 0;\nvar k = s[2] - 0;\n\nvar row = new Array(n + 1);\nfor (var i = 0; i < n + 1; i++) row[i] = i;\n\nvar col = new Array(m + 1);\nfor (var i = 0; i < m + 1; i++) col[i] = i;\n\nvar matrix = new Array(n);\nfor (var i = 0; i < n; i++) { \n matrix[i] = readline().split(' ');\n}\n\nfor (var i = 0; i < k; i++) {\n\n s = readline().split(' ');\n\n var q = s[0];\n var x = s[1] - 0;\n var y = s[2] - 0;\n\n if (q == 'c') {\n var c = col[x]; col[x] = col[y], col[y] = c;\n } else if (q == 'r') {\n var c = row[x]; row[x] = row[y], row[y] = c;\n } else {\n buf += matrix[row[x] - 1][col[y] - 1] + '\\n';\n }\n}\n\nprint(buf);", "positive_code": [{"source_code": "var s = \"\";\n\ns = readline().split(' ');\n\nvar n = s[0] - 0;\nvar m = s[1] - 0;\nvar k = s[2] - 0;\n\nvar row = new Array(n + 1);\nfor (var i = 0; i < n + 1; i++) row[i] = i;\n\nvar col = new Array(m + 1);\nfor (var i = 0; i < m + 1; i++) col[i] = i;\n\nvar matrix = new Array(n);\nfor (var i = 0; i < n; i++) { \n matrix[i] = readline().split(' ');\n}\n\nfor (var i = 0; i < k; i++) {\n\n s = readline().split(' ');\n\n var q = s[0];\n var x = s[1] - 0;\n var y = s[2] - 0;\n\n if (q == 'c') {\n var c = col[x]; col[x] = col[y], col[y] = c;\n } else if (q == 'r') {\n var c = row[x]; row[x] = row[y], row[y] = c;\n } else {\n print(matrix[row[x] - 1][col[y] - 1]);\n }\n}"}, {"source_code": "var s = \"\";\nvar buf = \"\";\n\ns = readline().split(' ');\n\nvar n = s[0] - 0;\nvar m = s[1] - 0;\nvar k = s[2] - 0;\n\nvar row = new Array(n + 1);\nfor (var i = 0; i < n + 1; i++) row[i] = i;\n\nvar col = new Array(m + 1);\nfor (var i = 0; i < m + 1; i++) col[i] = i;\n\nvar matrix = new Array(n);\nfor (var i = 0; i < n; i++) { \n matrix[i] = readline().split(' ');\n}\n\nfor (var i = 0; i < k; i++) {\n\n s = readline().split(' ');\n\n var q = s[0];\n var x = s[1] - 0;\n var y = s[2] - 0;\n\n if (q == 'c') {\n var c = col[x]; col[x] = col[y], col[y] = c;\n } else if (q == 'r') {\n var c = row[x]; row[x] = row[y], row[y] = c;\n } else {\n buf += matrix[row[x] - 1][col[y] - 1] + '\\n';\n if (i % 65536 == 0) {\n print(buf);\n buf = \"\";\n };\n }\n}\n\nprint(buf);"}, {"source_code": "\n(function main() {\n var l = readline().split(' ');\n var nrow = parseInt(l[0]);\n var ncol = parseInt(l[1]);\n var nreq = parseInt(l[2]);\n var rows = new Array(nrow);\n var cols = new Array(ncol);\n var elem = new Array(nrow * ncol);\n var answer = '';\n for (var i = 0; i < nrow; ++i) \n rows[i] = i;\n for (var i = 0; i < ncol; ++i) \n cols[i] = i;\n var q = 0;\n for (var i = 0; i < nrow; ++i) {\n var l = readline().split(' ');\n for (var j = 0; j < ncol; ++j, ++q) \n elem[q] = parseInt(l[j]);\n }\n for (var i = 0; i < nreq; ++i) {\n var l = readline().split(' ');\n var a = l[0];\n var b = parseInt(l[1]) - 1;\n var c = parseInt(l[2]) - 1;\n if (a == 'c') {\n var t = cols[b];\n cols[b] = cols[c];\n cols[c] = t;\n } else if (a == 'r') {\n var t = rows[b];\n rows[b] = rows[c];\n rows[c] = t;\n } else {\n answer += elem[rows[b] * ncol + cols[c]] + '\\n';\n }\n }\n print(answer);\n})();"}], "negative_code": [], "src_uid": "290d9779a6be44ce6a2e62989aee0dbd"} {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var c, lmom, lsum, op, rdist, rmom, s, _i, _len;\n\n String.prototype.reverse = function() {\n return this.split(\"\").reverse().join(\"\");\n };\n\n s = readline();\n\n lsum = lmom = 0;\n\n rdist = rmom = 0;\n\n op = false;\n\n for (_i = 0, _len = s.length; _i < _len; _i++) {\n c = s[_i];\n if (!op) {\n lmom += lsum;\n } else {\n rdist++;\n }\n if (c === '^') {\n op = true;\n continue;\n }\n if (c === '=') {\n continue;\n }\n if (!op) {\n lsum += c | 0;\n } else {\n rmom += (c | 0) * rdist;\n }\n }\n\n print(lmom > rmom ? 'left' : rmom > lmom ? 'right' : 'balance');\n\n}).call(this);\n", "positive_code": [{"source_code": "print(function(s) {\n\n\tvar i,\n\t\tans = 0,\n\t\tc = s.indexOf('^');\n\n\tfor (i = 0; i < s.length; i++)\n\t\tif (s[i] <= '9') ans += (c - i) * s[i];\n\n\tif (ans > 0) return 'left';\n\tif (ans < 0) return 'right';\n\treturn 'balance';\n\n}(readline()));"}, {"source_code": "var countOnce = function (res,item,position) {\n return res + (position+1)*(item=='='?0:item);\n}\n\nvar a = readline().split('^'),\n l = a[0].split('').reverse().reduce(countOnce,0),\n r = a[1].split('').reduce(countOnce,0);\n \nif (l==r) {\n print('balance')\n} else if (l>r) {\n print('left')\n} else {\n print('right')\n}"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar w = readline(),\n\t\t\tn = w.indexOf('^'), r = 0, l = 0;\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tvar q = w[i];\n\t\t\tif (q !== '=') {\n\t\t\t\tq = parseInt(q);\n\t\t\t\tl += (n - i) * q;\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = n + 1, _i = w.length; i < _i; i++) {\n\t\t\tvar q = w[i];\n\t\t\tif (q !== '=') {\n\t\t\t\tq = parseInt(q);\n\t\t\t\tr += (i - n) * q;\n\t\t\t}\n\t\t}\n\n\t\treturn l === r ? 'balance' : (r > l ? 'right' : 'left');\n\t}());\n}).call(this);\n"}, {"source_code": "var input = readline();\nvar idx = input.search(/\\^/);\nvar result = 0;\n\nfor(var i=0; i0) print('left'); \nelse print('right');\n"}, {"source_code": "var lever = readline();\n\nvar isLeft = true;\nvar leftCount = 0;\nvar rightCount = 0;\nvar center = 0;\n\n\nfor (var i = 0; i < lever.length; ++i) {\n if (lever.charAt(i) == '^') {\n center = i;\n break;\n }\n}\n\nfor (var i = 0; i < lever.length; ++i) {\n var value = 0;\n \n if (lever.charAt(i) == '=') {\n continue;\n }\n else if (lever.charAt(i) == '^') {\n isLeft = false;\n }\n else {\n value = lever.charAt(i) - '0';\n }\n\n if (isLeft == true) {\n leftCount += value * (center - i); \n } else {\n rightCount += value * (i - center);\n }\n}\n\nif (leftCount > rightCount) {\n print(\"left\");\n} else if (leftCount < rightCount) {\n print(\"right\");\n} else {\n print(\"balance\");\n}\n\n"}], "negative_code": [{"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var c, lmom, lsum, op, rdist, rmom, s, _i, _len;\n\n String.prototype.reverse = function() {\n return this.split(\"\").reverse().join(\"\");\n };\n\n s = readline();\n\n lsum = lmom = 0;\n\n rdist = rmom = 0;\n\n op = false;\n\n for (_i = 0, _len = s.length; _i < _len; _i++) {\n c = s[_i];\n if (!op) {\n lmom += lsum;\n } else {\n rdist++;\n }\n if (c === '^') {\n op = true;\n continue;\n }\n if (c === '=') {\n continue;\n }\n if (!op) {\n lsum += c | 0;\n } else {\n rmom += (c | 0) * rdist;\n }\n }\n\n print(lmom > rmom ? 'left' : rmom < lmom ? 'right' : 'balance');\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var s, solve;\n\n String.prototype.reverse = function() {\n return this.split(\"\").reverse().join(\"\");\n };\n\n s = readline();\n\n solve = function(s) {\n var c, lmom, lsum, op, rdist, rmom, rsum, _i, _len;\n lsum = lmom = 0;\n rdist = rsum = rmom = 0;\n op = false;\n for (_i = 0, _len = s.length; _i < _len; _i++) {\n c = s[_i];\n if (!op) {\n lmom += lsum;\n } else {\n rdist++;\n }\n if (c === '^') {\n op = true;\n continue;\n }\n if (c === '=') {\n continue;\n }\n if (!op) {\n lsum += c | 0;\n } else {\n rsum += (c | 0) * rdist;\n }\n }\n return lsum > rsum;\n };\n\n print(solve(s) ? 'left' : solve(s.reverse()) ? 'right' : 'balance');\n\n}).call(this);\n"}], "src_uid": "19f2c21b18e84f50e251b1dfd557d32f"} {"source_code": "function test() {\n assert(task(['9 4']), 'YES\\n' +\n '4 1 2 2');\n assert(task(['8 1']), 'YES\\n8');\n assert(task(['5 1']), 'NO');\n}\n\nfunction task([input]) {\n let [n, k] = input.split(' ');\n n = Number(n);\n k = Number(k);\n\n if (k > n) return 'NO';\n\n let result = [];\n let nBinary = n.toString(2);\n\n for (let i = 0; i < nBinary.length; i++) {\n if (nBinary[i] === '1') result.push(Math.pow(2, nBinary.length - i - 1));\n }\n\n let i = 0;\n let count = result.length;\n\n while (count < k) {\n let item = result[i];\n result[i] = false;\n if (item > 1) {\n result.push(item / 2, item / 2);\n count += 1;\n } else {\n result.push(item);\n }\n i++;\n }\n\n result = result.filter(Boolean);\n\n if (result.length !== k) {\n return 'NO';\n }\n\n return `YES\\n${result.join(' ')}`\n}\n\nfunction assert(result, expectation, unordered) {\n if (unordered) {\n result = result.split(' ');\n expectation = expectation.split(' ');\n\n if (result.sort().join(' ') !== expectation.sort().join(' ')) {\n console.error(`${result}: ${expectation}`);\n }\n } else if (result !== expectation) {\n console.error(`${result}: ${expectation}`);\n }\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)));\n } else {\n test();\n }\n}\n\nrun();\n", "positive_code": [{"source_code": "const read = [];\nconst M = new Map();\n\n// for CodeForces\nconst RL = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nRL.on('line', line => {\n read.push(line.trim());\n});\nRL.on('close', () => {\n const [n, k] = read[0].split(' ').map(Number);\n const obj = {\n pointer: 0,\n counter: 0,\n };\n\n preCalc(n, obj);\n\n if (obj.counter > k) {\n console.log('NO');\n return;\n }\n\n while (obj.counter !== k && obj.pointer !== 1) {\n M.set(obj.pointer, M.get(obj.pointer) - 1);\n obj.counter -= 1;\n\n M.set(obj.pointer >> 1, M.get(obj.pointer >> 1) + 2);\n obj.counter += 2;\n\n if (M.get(obj.pointer) === 0) {\n obj.pointer >>= 1;\n }\n }\n\n if (obj.counter !== k) {\n console.log('NO');\n return;\n }\n\n const answer = [];\n for (const [key, value] of M.entries()) {\n if (value === 0) {\n continue;\n }\n\n for (let i = 0; i < value; i += 1) {\n answer.push(key);\n }\n }\n\n console.log('YES');\n console.log(`${answer.join(' ')}`);\n});\n\nfunction preCalc(n, obj) {\n for (let i = 0; i < 32; i += 1) {\n if (((1 << i) & n) > 0) {\n M.set(1 << i, 1);\n obj.counter += 1;\n obj.pointer = 1 << i;\n } else {\n M.set(1 << i, 0);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "10d6179b479e1238a51154a9a6fc13cb"} {"source_code": "n = +readline();\r\nfor(i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t; i++){\n var a = lines[i];\n console.log(Math.ceil(a / 2));\n }\n});"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0) {\r\n console.log(Math.ceil(parseInt(line) / 2));\r\n return;\r\n }\r\n \r\n index++;\r\n})\r\n"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0) {\r\n console.log(Math.ceil(parseInt(line) / 2))\r\n }\r\n \r\n index++;\r\n})\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n // mb there can be overflow\n const data = input.trim().split('\\n').map(Number);\n\n for (let i = 1; i < data.length; i++) {\n const solution = Math.ceil(data[i] / 2);\n console.log(solution);\n }\n});\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar rem = BigInt(n) % BigInt(2);\r\n\tconsole.log(\" \" + (rem + (BigInt(n) / BigInt(2))))\r\n}"}, {"source_code": "function solve() {\r\n var n = Number(read());\r\n write((n + 1) >> 1);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n\r\n \r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n //let arr = readLine().trim().split(\" \").map(x=>parseInt(x))\r\n\r\n console.log(Math.ceil(n/2))\r\n } \r\n}"}, {"source_code": "n =readline();\r\nfor(i=0;i {\r\n if (err) throw err;\r\n const tests = data.split(\"\\r\\n\");\r\n tests.shift();\r\n tests.forEach((e) => {\r\n const ans = (Math.ceil(Number.parseInt(e) / 2));\r\n if (!Number.isNaN(ans)) console.log(ans); \r\n });\r\n});\r\n"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\r\n\r\n// console.log(fs.readdirSync('./'));\r\n// console.log(null);\r\n\r\nfs.readFile(\"./input.fd0138e687.txt\", \"utf-8\", (err, data) => {\r\n if (err) throw err;\r\n const tests = data.split(\"\\r\\n\");\r\n tests.shift();\r\n tests.forEach((e) => {\r\n console.log(Math.ceil(Number.parseInt(e) / 2));\r\n });\r\n});\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t; i++){\n var a = lines[i];\n console.log(Math.ceil(a));\n }\n});"}], "src_uid": "0c5cf0af057b0c838f13b491b923447a"} {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet lines = [];\nrl.on('line', (line) => {\n lines.push(line.split(' '));\n}).on('close', () => {\n lines.map((index, i) => {\n if (i > 0) {\n if ((`${index[0]}` === '2' && `${index[1]}` === '2') ||\n (`${index[0]}` === '1' || `${index[1]}` === '1')) {\n process.stdout.write(`YES\\n`);\n } else {\n process.stdout.write(`NO\\n`);\n }\n }\n })\n});", "positive_code": [{"source_code": "n = +readline();\nwhile (n-->0){\n num = readline().split(' ').map(Number);\n if (num[0] == 1 || num[1] == 1 || (num[0] == 2 && num[1] == 2)){\n print('YES\\n');\n } else {\n print('NO\\n');\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n if (n < 2 || m < 2 || (n == 2 && m == 2)) print(\"Yes\");\n else print(\"No\");\n}\n"}, {"source_code": "var inputLength = readline();\n\nfor (var i =0; i= (2*r*c - r - c)) {\n print (\"YES\");\n } else {\n print (\"NO\");\n }\n}"}, {"source_code": "var inputLength = readline();\n\nfor (var i =0; i= ((2*r - 1) * (c-1) + (r-1))) {\n print (\"YES\");\n } else {\n print (\"NO\");\n }\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst input = [];\n\nreadline.on('line', value => {\n input.push(value)\n});\n\nreadline.on('close', () => {\n const testCount = parseInt(input[0]);\n const variants = input.slice(1).map(str => str.split(' ').map(item => +item));\n variants.forEach(variant => console.log(calculate(variant)));\n})\n\n\nfunction calculate([n, m]) {\n if (n === 1 || m === 1) {\n return 'YES';\n } else if (n === 2 && m === 2) {\n return 'YES';\n } else {\n return 'NO';\n }\n}"}, {"source_code": "// Input\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//main\nfunction main() {\n var nbOfTestCases = parseInt(readline());\n \n for (var i=0 ; iparseInt(e));\n console.log(n*m <= (n+m) ? \"YES\" : \"NO\");\n }\n}"}, {"source_code": "// Q: https://codeforces.com/contest/1348/problem/A\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let i=0; i < test; i++) {\n let n, m;\n\t\t[n, m] = input[i+1].split(' ').map((a) => parseInt(a));\n\t\tconsole.log(solution(n, m));\n\t}\n});\n\nfunction solution(n, m) {\n\treturn 2*n*m - n - m <= n*m ? 'YES' : 'NO';\n}"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet lines = [];\nrl.on('line', (line) => {\n lines.push(line.split(' '));\n}).on('close', () => {\n for(i = 1; i < lines.length; i++) {\n if (\n (lines[i][0] == 1 || lines[i][1] == 1) ||\n (lines[i][0] == 2 && lines[i][1] == 2)\n ) {\n process.stdout.write(`YES\\n`);\n } else {\n process.stdout.write(`NO\\n`);\n }\n }\n \n});"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tif(N == 1 || M == 1){\n\t\t\toutput[i] = \"YES\";\n\t\t}else if(N == 2 && M == 2){\n\t\t\toutput[i] = \"YES\";\n\t\t}else{\n\t\t\toutput[i] = \"NO\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n var b = parseInt(line.split(\" \")[1]);\n\n solve(Math.min(a, b), Math.max(a, b));\n }\n}\n\nfunction solve(a, b) {\n if (a == 1) console.log('YES')\n else if (b < 3) console.log('YES')\n else console.log ('NO');\n}"}, {"source_code": "//Puzzle Pieces\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let t = +lines[0];\n\n for(let i = 0; i < t; i++) {\n \tlet arr = lines[i + 1].split(' ').map(c => +c);\n \tif(arr[0] == 1 || arr[1] == 1 || (arr[0] == 2 && arr[1] == 2)) {\n \t\tprocess.stdout.write('YES' + EOL);\n \t} else {\n \t\tprocess.stdout.write('NO' + EOL);\n \t}\n }\n\n return;\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n\n if (a === 1 || b === 1) {\n console.log('YES');\n }\n else if (a === 2 && b === 2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x).sort((a, b) => a-b)\n\n if (a === 1) {\n console.log('YES')\n } else {\n if (a === 2 && b === 2) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt(), M = nextInt();\n\n let result = (ok(N, M) ? \"YES\" : \"NO\");\n\n print(result);\n }\n}\n\nfunction ok(n, m) {\n if (n > m) {\n let tmp = n;\n n = m;\n m = tmp;\n }\n if (n==1) return true;\n if (n==2 && m == 2) return true;\n return false;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n var b = parseInt(line.split(\" \")[1]);\n\n solve(a, b);\n }\n}\n\nfunction solve(a, b) {\n if (a == 1) console.log('YES')\n else if (b < 3) console.log('YES')\n else console.log ('NO');\n}"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet lines = [];\nrl.on('line', (line) => {\n lines.push(line.split(' '));\n}).on('close', () => {\n console.log(lines);\n lines.map((index, i) => {\n if (i > 0) {\n if ((`${index[0]}` === '2' && `${index[1]}` === '2') ||\n (`${index[0]}` === '1' || `${index[1]}` === '1')) {\n process.stdout.write(`YES\\n`);\n } else {\n process.stdout.write(`NO\\n`);\n }\n }\n })\n});"}], "src_uid": "55595ff38a08b80bc86cf1ebae6f55af"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let ans = 'NO';\n let min = arr[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] !== min) {\n ans = arr[i];\n break;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar sequence = tokenizeIntegers(readline());\n\tsequence.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\n\tfor (var pos = 1; pos < sequence.length; pos += 1) {\n\t\tif (sequence[pos] != sequence[0]) {\n\t\t\tprint(sequence[pos]);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprint(\"NO\");\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nconst N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v))\nlll.sort((a, b) => a - b)\n\nlet i = 1\nlet min = lll[0]\nwhile (lll[i] == min) i++\n\nprint(lll[i] == null ? 'NO' : lll[i])"}], "negative_code": [], "src_uid": "930be5ec102fbe062062aa23eac75187"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1], delta = integers[2];\n\n\tvar factors = [];\n\trow = tokenizeIntegers(readline());\n\tvar remainder = row[0]%delta;\n\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tif (r != 0) {\n\t\t\trow = tokenizeIntegers(readline());\n\t\t}\n\t\tfor (var c = 0; c < colNum; c += 1) {\n\t\t\tif (row[c]%delta != remainder) {\n\t\t\t\tprint(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfactors.push(row[c]);\n\t\t}\n\t}\n\n\tfactors.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\n\tvar best = factors.length * -factors[0];\n\tfor (var i = 0; i < factors.length; i += 1) {\n\t\tbest += factors[i];\n\t}\n\n\tvar total = best, n = factors.length;\n\tfor (var i = 1; i < n; i += 1) {\n\t\tvar jump = factors[i] - factors[i-1];\n\t\ttotal += i * jump;\n\t\ttotal -= (n-i) * jump;\n\t\tbest = Math.min(best, total);\n\t}\n\n\tprint(best/delta);\n}\n\nmain();\n", "positive_code": [{"source_code": "print(function(n, m, d) {\n\tvar a = [];\n\tfor (var i = 0; i < n; i++) {\n\t\ta.push.apply(a, readline().split(' ').map(Number));\n\t}\n\tn = n * m;\n\n\ta = a.sort(function(a, b) {\n\t\treturn a - b;\n\t}).map(function(v, i, a) {\n\t\treturn v - a[0];\n\t});\n\n\treturn a.some(function(v) {\n\t\treturn v % d > 0;\n\t}) ? -1 : a.map(function(v) {\n\t\treturn v / d;\n\t}).reduce(function(q, p, i, a) {\n\t\treturn q + Math.abs(p - a[~~(n / 2)]);\n\t}, 0);\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "nmd = readline().split(' ').map(Number); n = nmd[0]; m = nmd[1]; d = nmd[2];\n\nfunction fn() {\n a = readline().split(' ').map(Number);\n x = a[0] % d;\n for (j = 1; j < m; j++) if (x !== a[j] % d) return -1;\n A = [].concat(a);\n for (i = 1; i < n; i++) {\n a = readline().split(' ').map(Number);\n for (j = 0; j < m; j++) if (x !== a[j] % d) return -1;\n A = A.concat(a);\n }\n A = A.map(i => (i - x) / d).sort((a,b) => a-b);\n i=0;j=A.length-1;a=1;b=1;r=0;\n while(i < j) {\n if(a < b) {\n r += a*(A[i+1] - A[i]);\n a++;i++;\n } else {\n r += b*(A[j] - A[j-1]);\n b++;j--;\n }\n }\n return r;\n}\nwrite(fn());\n"}, {"source_code": "nmd = readline().split(' ').map(Number); n = nmd[0]; m = nmd[1]; d = nmd[2];\n\nfunction fn() {\n a = readline().split(' ').map(Number);\n x = a[0] % d;\n for (j = 1; j < m; j++) if (x !== a[j] % d) return -1;\n A = [].concat(a);\n for (i = 1; i < n; i++) {\n a = readline().split(' ').map(Number);\n for (j = 0; j < m; j++) if (x !== a[j] % d) return -1;\n A = A.concat(a);\n }\n \n A = A.map(i => (i - x) / d).sort((a,b) => a-b);\n i=0;j=A.length-1;a=1;b=1;r=0;\n while(i < j) r += a < b ? a++*(A[i+1] - A[i++]) : b++*(A[j] - A[--j]);\n return r;\n}\nwrite(fn());\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n A[i] = readline().split(\" \");\n for (var j = 0; j < m && tik == 0; j++){\n if (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n write(-1);\n tik = 1;\n }\n B.push(Math.floor(parseInt(A[i][j]) / d));\n }\n}\nif (tik == 0){\n B = B.sort(function(a, b){return parseInt(a)-parseInt(b)});\n avgi = Math.floor(B.length / 2);\n avg = B[avgi];\n sum = 0;\n for (var i = 0; i < B.length; i++){\n sum += Math.abs(parseInt(B[i]) - parseInt(avg));\n }\n write(sum);\n}\n"}], "negative_code": [{"source_code": "print(function(n, m, d) {\n\tvar a = [];\n\tfor (var i = 0; i < n; i++) {\n\t\ta.push.apply(a, readline().split(' ').map(Number));\n\t}\n\n\ta = a.sort(function(a, b) {\n\t\treturn a - b;\n\t}).map(function(v, i, a) {\n\t\treturn v - a[0];\n\t});\n\n\treturn a.some(function(v) {\n\t\treturn v % d > 0;\n\t}) ? -1 : a.map(function(v) {\n\t\treturn v / d;\n\t}).reduce(function(q, p, i, a) {\n\t\treturn q + Math.abs(p - a[~~n / 2]);\n\t}, 0);\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "print(function(n, m, d) {\n\tvar a = [];\n\tfor (var i = 0; i < n; i++) {\n\t\ta.push.apply(a, readline().split(' ').map(Number));\n\t}\n\tn = n * m;\n\n\ta = a.sort(function(a, b) {\n\t\treturn a - b;\n\t}).map(function(v, i, a) {\n\t\treturn v - a[0];\n\t});\n\n\treturn a.some(function(v) {\n\t\treturn v % d > 0;\n\t}) ? -1 : a.map(function(v) {\n\t\treturn v / d;\n\t}).reduce(function(q, p, i, a) {\n\t\treturn q + Math.abs(p - a[~~n / 2]);\n\t}, 0);\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "nmd = readline().split(' ').map(Number); n = nmd[0]; m = nmd[1]; d = nmd[2];\n\nfunction fn() {\n a = readline().split(' ').map(Number);\n x = a[0] % d;\n for (j = 1; j < m; j++) if (x !== a[j] % d) return -1;\n A = [].concat(a);\n for (i = 1; i < n; i++) {\n a = readline().split(' ').map(Number);\n for (j = 0; j < m; j++) if (x !== a[j] % d) return -1;\n A = A.concat(a);\n }\n A = A.map(i => (i - x) / d).sort((a,b) => a-b);\n i=0;j=5;a=1;b=1;r=0;\n while(i < j) {\n if(a < b) {\n r += a*(A[i+1] - A[i]);\n a++;i++;\n } else {\n r += b*(A[j] - A[j-1]);\n b++;j--;\n }\n }\n return r;\n}\nwrite(fn());\n"}, {"source_code": "nmd = readline().split(' ').map(Number); n = nmd[0]; m = nmd[1]; d = nmd[2];\n\nfunction fn() {\n a = readline().split(' ').map(Number);\n A = [].concat(a);\n x = a[0] % d;\n for (j = 1; j < m; j++) if (x !== a[j] % d) return -1;\n for (i = n-1; i; --i) {\n a = readline().split(' ').map(Number);\n for (j = 0; j < m; j++) if (x !== a[j] % d) return -1;\n A = A.concat(a);\n }\n var mediana = A.reduce((res, i) => res + i, 0) / (n * m);\n return A.reduce((res, i) => res + Math.abs(i - mediana) / d, 0);\n}\nwrite(fn());\n"}, {"source_code": "nmd = readline().split(' ').map(Number); n = nmd[0]; m = nmd[1]; d = nmd[2];\n\nfunction fn() {\n a = readline().split(' ').map(Number);\n x = a[0] % d;\n for (j = 1; j < m; j++) if (x !== a[j] % d) return -1;\n A = [].concat(a);\n for (i = 1; i < n; i++) {\n a = readline().split(' ').map(Number);\n for (j = 0; j < m; j++) if (x !== a[j] % d) return -1;\n A = A.concat(a);\n }\n var mediana = A.reduce((res, i) => res + i, 0) / (n * m);\n return A.reduce((res, i) => res + Math.abs(i - mediana) / d, 0);\n}\nwrite(fn());\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\nprev = 0;\nsum = 0;\ns1 = 0;\ns2 = 0;\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (i == 0 && j == 0){\n\t\t\tprev = parseInt(A[i][j]) % d;\n\t\t} else {\n\t\t\tif (prev != parseInt(A[i][j]) % d){\n\t\t\t\twrite(-1);\n\t\t\t\ttik = 1;\n\t\t\t}\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t\tsum += parseInt(A[i][j]) / d;\n\t}\n}\nif (tik == 0){\n\tavg = Math.floor(sum/B.length);\n\tavg1 = avg + 1;\n\tfor (var i = 0; i < B.length; i++){\n\t\tif (B[i] > avg){\n\t\t\ts1 += (B[i] - avg);\n\t\t} else {\n\t\t\ts1 += (avg - B[i]);\n\t\t}\n\t\tif (B[i] > avg1){\n\t\t\ts2 += (B[i] - avg1);\n\t\t} else {\n\t\t\ts2 += (avg1 - B[i]);\n\t\t}\n\t}\n\twrite(Math.min(s1,s2));\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\tavg = B[avg];\n\twrite(avg);\n\t\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\tavg = B[avg];\n\tsum = 0;\n\tfor (var i = 0; i < B.length; i++){\n\t\tsum = Math.abs(B[i] - avg);\n\t}\n\twrite(sum);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\tavg = B[avg];\n\tsum = \"\";\n\tfor (var i = 0; i < B.length; i++){\n\t\tsum += B[i] + \" \";\n\t}\n\twrite(sum);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\twrite(avg);\n\t\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\tavg = B[avg];\n\tsum = \"\";\n\tfor (var i = 0; i < B.length; i++){\n\t\tsum += Math.abs(B[i] - avg) + \" \";\n\t}\n\twrite(sum);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\nprev = 0;\nsum = 0;\ns1 = 0;\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (i == 0 && j == 0){\n\t\t\tprev = parseInt(A[i][j]) % d;\t\n\t\t} else {\n\t\t\tif (prev != parseInt(A[i][j]) % d){\n\t\t\t\twrite(-1);\n\t\t\t\ttik = 1;\n\t\t\t}\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B[Math.floor(B.length / 2)];\n\tfor (var i = 0; i < B.length; i++){\n\t\tif (B[i] > avg){\n\t\t\ts1 += (B[i] - avg);\n\t\t} else {\n\t\t\ts1 += (avg - B[i]);\n\t\t}\n\t}\n\twrite(s1);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (parseInt(A[0][0]) % d != parseInt(A[i][j]) % d){\n\t\t\twrite(-1);\n\t\t\ttik = 1;\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B.length / 2;\n\tavg = B[avg];\n\tsum = 0;\n\tfor (var i = 0; i < B.length; i++){\n\t\tsum += Math.abs(B[i] - avg);\n\t}\n\twrite(sum);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\nprev = 0;\nsum = 0;\ns1 = 0;\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (i == 0 && j == 0){\n\t\t\tprev = parseInt(A[i][j]) % d;\t\n\t\t} else {\n\t\t\tif (prev != parseInt(A[i][j]) % d){\n\t\t\t\twrite(-1);\n\t\t\t\ttik = 1;\n\t\t\t}\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B[B.length / 2];\n\tfor (var i = 0; i < B.length; i++){\n\t\tif (B[i] > avg){\n\t\t\ts1 += (B[i] - avg);\n\t\t} else {\n\t\t\ts1 += (avg - B[i]);\n\t\t}\n\t}\n\twrite(s1);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\nprev = 0;\nsum = 0;\ns1 = 0;\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (i == 0 && j == 0){\n\t\t\tprev = parseInt(A[i][j]) % d;\n\t\t} else {\n\t\t\tif (prev != parseInt(A[i][j]) % d){\n\t\t\t\twrite(-1);\n\t\t\t\ttik = 1;\n\t\t\t}\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tB = B.sort();\n\tavg = B[parseInt(B.length / 2)];\n\tfor (var i = 0; i < B.length; i++){\n\t\tif (B[i] > avg){\n\t\t\ts1 += (B[i] - avg);\n\t\t} else {\n\t\t\ts1 += (avg - B[i]);\n\t\t}\n\t}\n\twrite(s1);\n}\n"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nm = parseInt(ip[1]);\nd = parseInt(ip[2]);\nvar A = new Array();\nvar B = new Array();\nprev = 0;\nsum = 0;\ns1 = 0;\ntik = 0;\n\nfor (var i = 0; i < n && tik == 0; i++){\n\tA[i] = readline().split(\" \");\n\tfor (var j = 0; j < m && tik == 0; j++){\n\t\tif (i == 0 && j == 0){\n\t\t\tprev = parseInt(A[i][j]) % d;\n\t\t} else {\n\t\t\tif (prev != parseInt(A[i][j]) % d){\n\t\t\t\twrite(-1);\n\t\t\t\ttik = 1;\n\t\t\t}\n\t\t}\n\t\tB.push(parseInt(A[i][j]) / d);\n\t}\n}\nif (tik == 0){\n\tavg = B[parseInt(B.length / 2)];\n\tfor (var i = 0; i < B.length; i++){\n\t\tif (B[i] > avg){\n\t\t\ts1 += (B[i] - avg);\n\t\t} else {\n\t\t\ts1 += (avg - B[i]);\n\t\t}\n\t}\n\twrite(s1);\n}\n"}], "src_uid": "3488bb49de69c0c17ea0439e71b1e6ae"} {"source_code": "var i,\n\tn = +readline(),\n\ts = readline(),\n\tc = {\n\t\t'A': 0,\n\t\t'F': 0,\n\t\t'I': 0\n\t};\n\nfor (var i = 0; i < n; i++)\n\tc[s[i]]++;\n\nprint(c.I > 1 ? 0 : c.I === 1 ? 1 : c.A);", "positive_code": [{"source_code": "var i,\n\tn = +readline(),\n\ts = readline(),\n\tc = {\n\t\t'A': 0,\n\t\t'F': 0,\n\t\t'I': 0\n\t};\n\nfor (var i = 0; i < n; i++)\n\tc[s[i]]++;\n\nprint(c.I>1?0:c.I===1?1:c.A);"}, {"source_code": ";(function () {\n\n\tprint((function (n, str) {\n\n\t\tvar m = {A: 0, F: 0, I: 0};\n\t\tfor (var i = 0; i < n; i++) m[str[i]]++;\n\t\treturn m.I > 1 ? 0 : (m.I === 1 ? 1 : m.A);\n\n\t})(+readline(), readline()));\n\n}).call(this);"}], "negative_code": [], "src_uid": "5e4defe52832cc0d36e7ea5d9f86f895"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len1 = +readLine();\n const arr1 = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const len2 = +readLine();\n const arr2 = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let max = Number.MIN_SAFE_INTEGER;\n let count = 0;\n\n for (let i = 0; i < len2; i++) {\n const a = arr2[i];\n for (let j = 0; j < len1; j++) {\n const b = arr1[j];\n const div = a / b;\n if (Number.isInteger(div)) {\n if (div > max) {\n max = div;\n count = 0;\n }\n if (div === max) count++;\n }\n }\n }\n console.log(count);\n}\n", "positive_code": [{"source_code": "print(function(n, a, m, b) {\n\tvar i, j,\n\t\tmax = 0,\n\t\tans = 0;\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < m; j++)\n\t\t\tif (b[j] % a[i] === 0) {\n\t\t\t\tif (b[j] / a[i] > max) {\n\t\t\t\t\tmax = b[j] / a[i];\n\t\t\t\t\tans = 1;\n\t\t\t\t} else if (b[j] / a[i] === max) {\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\n\treturn ans;\n\n}(+readline(), readline().split(' ').map(Number), +readline(), readline().split(' ').map(Number)));\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet a = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet m = readLine() >> 0;\n\tlet b = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet best = 0;\n\tlet store = {};\n\n\tfor (let i = 0; i < n; i++) {\n\t\tfor (let j = m - 1; j >= 0; j--) {\n\t\t\tif (Math.floor(b[j] / a[i]) < best) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (b[j] % a[i] === 0) {\n\t\t\t\tbest = Math.max(best, b[j] / a[i]);\n\t\t\t\tstore[best] = (store[best] || 0) + 1;\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log(store[best]);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let aS = readLine().split(' ').map(Number);\n let m = parseInt(readLine());\n let bS = readLine().split(' ').map(Number);\n let integers = [];\n for (let i = 0; i < m; i++) {\n for (let j = 0; j < n; j++) {\n if (Number.isInteger(bS[i] / aS[j])) {\n integers.push(bS[i] / aS[j]);\n }\n }\n }\n integers.sort((a, b) => {\n return b - a;\n });\n let count = 1;\n for (let i = 1; i < integers.length; i++) {\n if (integers[0] === integers[i]) {\n count++;\n }\n }\n console.log(count);\n}\n"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline(),\n\t\ta = readline().split(' ').map(Number),\n\t\tm = +readline(),\n\t\tb = readline().split(' ').map(Number),\n\t\tc = (function () {\n\t\t\tvar t = [], l, max, i, j;\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\tfor (j = 0; j < m; j++) {\n\t\t\t\t\tl = b[j] / a[i];\n\t\t\t\t\tif (l === parseInt(l)) {\n\t\t\t\t\t\tt.push(l);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tmax = Math.max.apply(null, t);\n\t\t\treturn t.filter(function (e) { return e === max; }).length;\n\t\t})();\n\n\tprint(c);\n\t\n}).call(this);"}], "negative_code": [{"source_code": "print(function(n, a, m, b) {\n\tvar i, j, d = new Int8Array(1e4);\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < m; j++)\n\t\t\tif (b[j] % a[i] === 0)\n\t\t\t\td[b[j] / a[i]]++;\n\n\td[1] = 0;\n\treturn Math.max.apply(0, d);\n\n}(+readline(), readline().split(' ').map(Number),\n +readline(), readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a, m, b) {\n\tvar i, j, d = new Int8Array(1e4);\n\tfor (i = 0; i < n; i++)\n\t\tfor (j = 0; j < m; j++)\n\t\t\tif (b[j] % a[i] === 0)\n\t\t\t\td[b[j] / a[i]]++;\n\n\treturn Math.max.apply(0, d);\n\n}(+readline(), readline().split(' ').map(Number),\n +readline(), readline().split(' ').map(Number)));"}], "src_uid": "102667eaa3aee012fef70f4192464674"} {"source_code": "function dormey(n,q,arr){\r\n let q1=0;\r\n let ans=[];\r\n for(let i=n-1;i>=0;i--){\r\n if(arr[i]<=q1){\r\n ans[i]=1; \r\n }\r\n else{\r\n if(q1 {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar arr = readIntArr();\r\n\t\tvar n, q;\r\n\t\tn = arr[0]; q = arr[1];\r\n\t\ta = readIntArr();\r\n\t\t\r\n\t\tvar ans = [];\r\n\t\t// go from back since ideal to keep v large for as long as possible?\r\n\t\tif (q >= n) {\r\n\t\t\tfor (var i = 0; i < n; i++) ans.push('1');\r\n\t\t} else {\r\n\t\t\tfor (var i = 0; i < n; i++) ans.push('0');\r\n\t\t\tvar v = 0;\r\n\t\t\tfor (var i = n - 1; i > -1; i--) {\r\n\t\t\t\tif (a[i] > v) {\r\n\t\t\t\t\tif (v < q) {\r\n\t\t\t\t\t\tv += 1;\r\n\t\t\t\t\t\tans[i] = '1';\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tans[i] = '1';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tallans.push(ans.join(''));\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var nq = readline().split(' ').map(x=>parseInt(x));\r\n var arr = readline().split(' ').map(x=>parseInt(x));\r\n var iq = 0;\r\n var ans = Array(nq[0]).fill(0);\r\n for (var i = nq[0]-1; i >= 0; i--) {\r\n if (arr[i] <= iq) {\r\n ans[i] = 1;\r\n } else {\r\n if (iq < nq[1]) {\r\n iq++;\r\n ans[i] = 1;\r\n }\r\n }\r\n }\r\n print(ans.join(''));\r\n }"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n const splitLines = lines.map(x => x.split(\" \").map(x => parseInt(x)))\n for (let i = 0; i < splitLines[0][0]; i ++)\n {\n const currentArray = splitLines.slice(2 * i + 1, 2 * i + 3);\n const n = currentArray[0][0];\n const q = currentArray[0][1];\n let q0 = 0;\n let str = \"\";\n for (let i = currentArray[1].length - 1; i >= 0; i --)\n {\n\n if (q0 >= currentArray[1][i])\n {\n str = 1 + str;\n }\n else if (q0 < q)\n {\n q0 ++;\n str = 1 + str;\n }\n else\n {\n str = 0 + str;\n }\n }\n\n console.log(str)\n }\n})"}, {"source_code": "const fs = require(\"fs\");\r\n\r\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n\r\nconst testCases = [];\r\nlet T;\r\n\r\nfunction parseInput() {\r\n T = parseInt(input[0]);\r\n let index = 0;\r\n\r\n for (let i = 0; i < T; i++) {\r\n index++;\r\n const [n, q] = input[index]\r\n .trim()\r\n .split(\" \")\r\n .map((a) => parseInt(a));\r\n index++;\r\n const a = input[index]\r\n .trim()\r\n .split(\" \")\r\n .map((a) => parseInt(a));\r\n const testCase = {\r\n n,\r\n q,\r\n a,\r\n };\r\n\r\n testCases.push(testCase);\r\n }\r\n}\r\n\r\nfunction solution(testCase, index) {\r\n const { n, q, a } = testCase;\r\n let result = \"\";\r\n let iq = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (a[i] <= iq) result = \"1\" + result;\r\n else if (a[i] > iq && iq < q) {\r\n iq++;\r\n result = \"1\" + result;\r\n } else result = \"0\" + result;\r\n }\r\n\r\n console.log(result);\r\n}\r\n\r\nparseInput();\r\n\r\ntestCases.forEach(solution);\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n if (m >= n) return '1'.repeat(n);\r\n let l = 0,\r\n r = n - 1;\r\n const check = s => {\r\n let t = m;\r\n for (let i = s; i < n; i++) {\r\n if (a[i] > t) t--;\r\n if (t < 0) return false;\r\n }\r\n return true;\r\n };\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (check(mid)) {\r\n r = mid;\r\n } else {\r\n l = mid + 1;\r\n }\r\n }\r\n let res = new Array(n).fill(0);\r\n for (let i = l; i < n; i++) res[i] = 1;\r\n for (let i = 0; i < l; i++) if (a[i] <= m) res[i] = 1;\r\n return res.join('');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let input = ''\r\nprocess.stdin.on('data', chunk => input += chunk)\r\nprocess.stdin.on('end', () => {\r\n let array = input.trim().split('\\n').slice(1).map(item => item.replace('\\r', ''))\r\n .map(item => item.split(' '));\r\n array.forEach((item, index, arr) =>{\r\n if(index % 2 === 0 || index === 0){\r\n let result = new Array(arr[index][0]*1).fill(0);\r\n let iq = arr[index][1];\r\n let test = array[index+1];\r\n let step = 0;\r\n for (let i = arr[index][0]-1; i >= 0; i--) {\r\n if ( test[i] <= step) {\r\n result[i] = 1;\r\n } else {\r\n if (step < iq) {\r\n step++;\r\n result[i] = 1;\r\n }\r\n }\r\n }\r\n console.log(result.join(''));\r\n }\r\n })\r\n});"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const bst = new BinarySearchTree();\r\n let max = Math.min(n, m),\r\n t = -1;\r\n for (let [i, num] of a.entries()) {\r\n if (num <= m) {\r\n const cnt = bst.countGreaterThanEq(num + 1);\r\n let ans = i + 1 - cnt;\r\n if (cnt <= m - num) {\r\n ans += cnt;\r\n ans += Math.min(m - cnt, n - i - 1);\r\n } else {\r\n ans += m - num;\r\n ans += Math.min(num, n - i - 1);\r\n }\r\n if (ans > max) {\r\n max = ans;\r\n t = i;\r\n }\r\n max = Math.max(max, ans);\r\n }\r\n bst.insert(num);\r\n }\r\n if (t === -1) {\r\n return '1'.repeat(max).padEnd(n, '0');\r\n }\r\n let res = new Array(n).fill(0),\r\n l = m - a[t],\r\n r = a[t];\r\n for (let i = 0; i < n; i++) {\r\n if (i <= t && a[i] <= a[t]) res[i] = 1;else if (i < t) {\r\n if (l) {\r\n res[i] = 1;\r\n l--;\r\n }\r\n } else {\r\n if (r) {\r\n res[i] = 1;\r\n r--;\r\n }\r\n }\r\n if (i === t) r += l;\r\n }\r\n return res.join('');\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const bst = new BinarySearchTree();\r\n let max = Math.min(n, m),\r\n t = -1;\r\n for (let [i, num] of a.entries()) {\r\n if (num <= m) {\r\n const cnt = bst.countGreaterThanEq(num + 1);\r\n let ans = i + 1 - cnt;\r\n if (cnt <= m - num) {\r\n ans += cnt;\r\n ans += Math.min(m - cnt, n - i - 1);\r\n } else {\r\n ans += m - num;\r\n ans += Math.min(num, n - i - 1);\r\n }\r\n if (ans > max) {\r\n max = ans;\r\n t = i;\r\n }\r\n max = Math.max(max, ans);\r\n }\r\n bst.insert(num);\r\n }\r\n if (t === -1) {\r\n return '1'.repeat(max).padEnd(n - max, '0');\r\n }\r\n let res = new Array(n).fill(0),\r\n l = m - a[t],\r\n r = a[t];\r\n for (let i = 0; i < n; i++) {\r\n if (i <= t && a[i] <= a[t]) res[i] = 1;else if (i < t) {\r\n if (l) {\r\n res[i] = 1;\r\n l--;\r\n }\r\n } else {\r\n if (r) {\r\n res[i] = 1;\r\n r--;\r\n }\r\n }\r\n if (i === t) r += l;\r\n }\r\n return res.join('');\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "62a90c34a7df8fb56419aa5a1cf2a75b"} {"source_code": "var a = 'a'.charCodeAt(0);\n\n;(function () {\n\tvar str = readline(), l = str.length;\n\tvar k = +readline();\n\tvar alphabet = readline().split(' ').map(Number);\n\tvar maxPrice = Math.max.apply(null, alphabet);\n\n\tvar sum = ((function () {\n\t\tfor (var i = 0, ret = 0; i < l; i++)\n\t\t\tret += alphabet[str.charCodeAt(i) - a] * (i + 1);\n\t\treturn ret;\n\t})()) + maxPrice * ((function () {\n\t\tfor (var i = 0, ret = 0; i < k; i++)\n\t\t\tret += l + i + 1;\n\t\treturn ret;\n\t})());\n\n\tprint(sum);\n\n}).call(this);", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar s = trim(readline()),\n\t\tk = parseInt(readline()),\n\t\tvalues = tokenizeIntegers(readline()),\n\t\tmaxValue = 0,\n\t\tch2value = {},\n\t\ttotal = 0;\n\tfor (var i = 0; i < 26; ++i) {\n\t\tch2value[String.fromCharCode(97+i)] = values[i];\n\t\tmaxValue = Math.max(maxValue, values[i]);\n\t}\n\tfor (var i = 0; i < s.length; ++i) {\n\t\ttotal += (i+1)*ch2value[s.charAt(i)];\n\t}\n\tfor (var i = 0; i < k; ++i) {\n\t\ttotal += (s.length+i+1)*maxValue;\n\t}\n\tprint(total);\n}\n\nmain();\n"}, {"source_code": "var s = readline()\nvar k = Number(readline())\nvar w = readline().split(' ').map(Number)\nvar l = s.length\nvar c = Math.max.apply(null, w) * k * (2 * l + k + 1) / 2\nfor (var i = 1; i <= l; ++i) {\n c += i * w[s.charCodeAt(i - 1) - 'a'.charCodeAt()]\n}\nprint(c)\n"}, {"source_code": "var s = readline()\nvar k = Number(readline())\nvar w = readline().split(' ').map(Number)\nvar l = s.length\nvar c = Math.max.apply(null, w) * k * (2 * l + k + 1) / 2\nfor (var i = 1; i <= l; ++i) {\n c += i * w[s.charCodeAt(i - 1) - 'a'.charCodeAt()]\n}\nprint(c)"}, {"source_code": "function main(str,k,arr){\n\n var t = 0;\n for(var i = 1 ; i <= str.length ; i++){\n t += (arr[str.charCodeAt(i-1)-'a'.charCodeAt(0)]*i);\n\n }\n var max = -Infinity;\n for(var i= 0 ; i < arr.length ; i++)max = Math.max(max,arr[i]);\n for(var i = str.length+1 ; i <= str.length+k ; i++)t += max*i;\n print(t);\n}\n\nvar str = readline();\nvar k = parseInt(readline());\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(str,k,arr);\n"}], "negative_code": [], "src_uid": "85f90533a9840e944deef9f3b4229cb8"} {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, K, arr;\r\n\r\n while (T--) {\r\n [N, K] = lines[index++].split(' ').map(Number);\r\n arr = lines[index++].split(' ').map(Number);\r\n solve(N, K, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, K, input) {\r\n let result = 0;\r\n\r\n input.sort((a, b) => b - a);\r\n\r\n for (let i = 0; i < K; ++i) {\r\n result += Number(input[i] === input[i + K]);\r\n }\r\n\r\n for (let i = 2 * K; i < N; ++i) {\r\n result += input[i];\r\n }\r\n\r\n console.log(result);\r\n}", "positive_code": [{"source_code": "var s = parseInt(readline());\r\n while (s--) {\r\n var input = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var n = input[0];\r\n var k = input[1];\r\n var input1 = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n .sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var min1 = n - k;\r\n var min2 = n - (k + k);\r\n\r\n var min = 0;\r\n for (var i = 0; i < k; i++) {\r\n min += Math.floor(input1[min2] / input1[min1]);\r\n input1[min2] = 0;\r\n input1[min1] = 0;\r\n min1++;\r\n min2++;\r\n }\r\n for (var i = 0; i < n; i++) {\r\n min += input1[i];\r\n }\r\n print(min);\r\n }"}, {"source_code": "\"use strict\";\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const lll = this.readline().split(\" \");\n const n = lll[0]\n const k = lll[1]\n const numbers = this.readline().split(\" \").map(function(e){return Number(e)});\n numbers.sort((a, b) => a - b);\n const ys = numbers.slice(n - k, n + 1);\n const xs = numbers.slice(n - k - k, n - k);\n const somar = numbers.slice(0, n - k - k);\n let score = 0;\n for (let j = 0; j < k; j++) {\n score += Math.floor(xs[j] / ys[j]);\n }\n for (let j = 0; j < somar.length; j++) {\n score += somar[j];\n }\n this.print(score);\n}\n"}, {"source_code": "\"use strict\";\n\nfunction answer(nums, k) {\n let score = 0;\n \n nums.sort((a, b) => a - b);\n \n const l = nums.length;\n for (let i = 0; i < k; i += 1) {\n score += Math.floor(\n nums[l - 1 - k - i] / nums[l - 1 - i]\n );\n }\n \n let remaining = 0;\n for (let i = 0; i < (nums.length - (k * 2)); i += 1) {\n remaining += nums[i];\n }\n\n return score + remaining;\n}\n\nconst nQueues = this.readline().split(' ');\n\nfor (let i = 0; i < nQueues; i++) {\n const k = this.readline().split(' ')[1];\n const nums = this.readline().split(' ').map(e => +e);\n const result = answer(nums, k);\n this.print(result.toString());\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n let sum = 0;\r\n for (let i = 2 * k; i < n; i++) sum += arr[i];\r\n let obj = {},\r\n cnt = 0;\r\n for (let i = 0; i < 2 * k; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n }\r\n let keys = Object.keys(obj);\r\n let max = 0;\r\n for (let i = 0; i < keys.length; i++) max = Math.max(max, obj[keys[i]]);\r\n if (max <= k) console.log(sum);\r\n else {\r\n let rem = max - (2 * k - max);\r\n rem = rem / 2;\r\n console.log(rem + sum);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n const nums = readline().split(' ').map(el=>parseInt(el));\r\n\r\n nums.sort((a,b)=>a-b);\r\n if(nums.length == 1){\r\n console.log(nums[0]);\r\n continue;\r\n }\r\n \r\n let p = nums.length - 2*k; \r\n let q = nums.length - k ;\r\n let score = 0;\r\n while(q < nums.length){\r\n score += Math.floor(nums[p]/nums[q]);\r\n p++;\r\n q++;\r\n }\r\n \r\n for(let i=0; i< nums.length - 2*k; ++i){\r\n score+= nums[i];\r\n }\r\n console.log(score);\r\n }\r\n}"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, K, arr;\r\n \r\n while (T--) {\r\n [N, K] = lines[index++].split(' ').map(Number);\r\n arr = lines[index++].split(' ').map(Number);\r\n solve(N, K, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, K, input) {\r\n const arr = new Array(N);\r\n let sum = 0;\r\n let bestRemovedSum = 0;\r\n let removedSum;\r\n let y, x, step;\r\n\r\n for (let i = 0; i < N; ++i) {\r\n arr[i] = new Array(N);\r\n sum += input[i];\r\n }\r\n\r\n input.sort((a, b) => a - b);\r\n \r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j) {\r\n arr[i][j] = input[i] + input[j] - Number(input[i] === input[j]);\r\n }\r\n }\r\n\r\n step = 0;\r\n\r\n for (let i = N - 1; i > 0; --i) {\r\n y = N - 1;\r\n x = i - 1;\r\n step++;\r\n k = K;\r\n removedSum = 0;\r\n isFlag = true;\r\n \r\n while (k > 0 && y >= 0 && x >= 0) {\r\n for (let z = 0; z < step && y >= 0 && x >= 0 && k > 0; ++z) {\r\n if (isFlag) {\r\n removedSum += arr[y][x];\r\n k--;\r\n }\r\n \r\n y--;\r\n x--;\r\n }\r\n\r\n isFlag = !isFlag;\r\n }\r\n\r\n bestRemovedSum = Math.max(bestRemovedSum, removedSum);\r\n }\r\n\r\n console.log(sum - bestRemovedSum);\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n var _sort$0$, _sort, _sort$;\r\n const N = n - 2 * m;\r\n a.sort((a, b) => a - b);\r\n let res = a.slice(0, N).reduce((a, b) => a + b, 0);\r\n const map = new Map();\r\n for (let num of a.slice(N)) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n const max = (_sort$0$ = (_sort = [...map.entries()].sort((a, b) => b[1] - a[1])) === null || _sort === void 0 ? void 0 : (_sort$ = _sort[0]) === null || _sort$ === void 0 ? void 0 : _sort$[1]) !== null && _sort$0$ !== void 0 ? _sort$0$ : 0;\r\n res += Math.max(0, (max - (2 * m - max)) / 2);\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 2*k; i < n; i++)\r\n\t\t\tans += a[i];\r\n\r\n\t\tfunction count (x) {\r\n\t\t\tlet cnt = 0, cntl = 0, cntm = 0;\r\n\t\t\tfor (let i = 0; i < 2*k; i++) {\r\n\t\t\t\tcnt += a[i] == x;\r\n\t\t\t\tcntl += a[i] < x;\r\n\t\t\t\tcntm += a[i] > x;\r\n\t\t\t}\r\n\t\t\treturn [cnt, cntl, cntm];\r\n\t\t}\r\n\r\n\t\tar = [...new Set(a.slice(0, 2*k+1))];\r\n\t\tfor (const elm of ar) {\r\n\t\t\t const [c, cl, cm] = count(elm);\r\n\t\t\t ans += Math.max(0, (c-cl-cm)/2);\r\n\t\t\t //console.log(elm, {ans, c, cl, cm});\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let k = nextInt();\r\n const a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n a.sort((x, y) => x - y);\r\n let ans = 0;\r\n for (let i = 0; i < n - 2 * k; i++) {\r\n ans += a[i];\r\n }\r\n for (let j = n - 2 * k; j + k < n; j++) {\r\n ans += Math.floor(a[j] / a[j + k]);\r\n }\r\n printf(\"%d\\n\", ans);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n let sum = 0;\r\n for (let i = 2 * k; i < n; i++) sum += arr[i];\r\n let obj = {},\r\n cnt = 0;\r\n for (let i = 0; i < 2 * k; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n }\r\n for (let i of Object.keys(obj)) {\r\n if (obj[i] === 1) cnt++;\r\n }\r\n if (cnt >= k) console.log(sum);\r\n else console.log(k - cnt + sum);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => b - a);\r\n let sum = 0;\r\n for (let i = 2 * k; i < n; i++) sum += arr[i];\r\n let obj = {},\r\n cnt = 0;\r\n for (let i = 0; i < 2 * k; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n }\r\n for (let i of Object.keys(obj)) {\r\n if (obj[i] === 1) cnt++;\r\n }\r\n console.log(k - cnt + sum);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let sum = arr.reduce((i, j) => i + j, 0);\r\n arr.sort((a, b) => a - b);\r\n let i = 0,\r\n j = n - 1;\r\n while (k > 0) {\r\n let s1 = arr[i] + arr[j];\r\n let s2 = arr[j] + arr[j - 1];\r\n s1 += Math.floor(arr[i] / arr[j]);\r\n s2 += Math.floor(arr[j - 1] / arr[j]);\r\n if (s2 > s1) {\r\n sum -= arr[j - 1] + arr[j];\r\n sum += Math.floor(arr[j - 1] / arr[j]);\r\n j = j - 2;\r\n } else {\r\n sum -= arr[i] + arr[j];\r\n sum += Math.floor(arr[i] / arr[j]);\r\n i++;\r\n }\r\n k--;\r\n }\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n const nums = readline().split(' ').map(el=>parseInt(el));\r\n\r\n nums.sort((a,b)=>a-b);\r\n if(nums.length == 1){\r\n console.log(nums[0]);\r\n continue;\r\n }\r\n let p = nums.length - 2*k, q = nums.length - 1 ;\r\n let score = 0;\r\n while(p +data)\r\n var n = b[0]\r\n var k = b[1]\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data).sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n })\r\n\r\n var b = [].concat(a)\r\n var min = 0;\r\n var min1 = 0;\r\n for (var i = 0; i < k; i++) {\r\n var last1 = a.pop()\r\n var last2 = a.pop()\r\n min = min + Math.floor(last2 / last1)\r\n }\r\n for (var i = 0; i < a.length; i++) {\r\n min += a[i]\r\n }\r\n\r\n for (var i = 0; i < k; i++) {\r\n var last1 = b.shift()\r\n var last2 = b.pop()\r\n min1 = min1 + Math.floor(last1 / last2)\r\n }\r\n for (var i = 0; i < a.length; i++) {\r\n min1 += b[i]\r\n }\r\n\r\n var ans = Math.min(min1, min)\r\n print(ans)\r\n }"}, {"source_code": "var t = parseInt(readline())\r\n\r\n while (t--) {\r\n var b = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n var n = b[0]\r\n var k = b[1]\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data).sort((a, b) => {\r\n if (a > b) {\r\n return 1;\r\n } else if (a < b) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n })\r\n var min = 0;\r\n for (var i = 0; i < k; i++) {\r\n var last1 = a.pop()\r\n var last2 = a.pop()\r\n min = min + Math.floor(last2 / last1)\r\n }\r\n for (var i = 0; i < a.length; i++) {\r\n min += a[i]\r\n }\r\n print(min)\r\n }"}], "src_uid": "f48d55c60c12136979fe6db1e15c6053"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar odd = [];\r\n\t\tvar even = [];\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] % 2 == 0){\r\n\t\t\t\teven.push(list[i]);\r\n\t\t\t}else{\r\n\t\t\t\todd.push(list[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tlist = even.concat(odd);\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tif(gcd(list[i], 2 * list[j]) > 1){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}\r\n", "positive_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n a.sort((x, y) => {\r\n var x1 = x & 1;\r\n var y1 = y & 1;\r\n if (x1 !== y1) {\r\n return x1 - y1;\r\n }\r\n return y - x;\r\n });\r\n var ans = 0;\r\n for (var i = 0; i < n; i++) {\r\n for (j = i + 1; j < n; j++) {\r\n if (gcd(a[i], 2 * a[j]) > 1) {\r\n ans++;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let testCase = 1; testCase < input.length; testCase += 2) {\r\n let numbers = input[testCase + 1].split(\" \");\r\n numbers.sort(function (x, y) {\r\n if (+x % 2 === 0) {\r\n return -1;\r\n }\r\n if (+y % 2 === 0) {\r\n return 1;\r\n }\r\n return 0;\r\n });\r\n\r\n let i = 0;\r\n let count = 0;\r\n let size = numbers.length - 1;\r\n while (+numbers[i] % 2 === 0) {\r\n count += size;\r\n size--;\r\n i++;\r\n continue;\r\n }\r\n\r\n for (let j = i; j < numbers.length - 1; j++) {\r\n for (let k = j + 1; k < numbers.length; k++) {\r\n if (findGCD(+numbers[j], +numbers[k] * 2) > 1) count++;\r\n }\r\n }\r\n\r\n console.log(count);\r\n }\r\n};\r\n\r\nconst findGCD = (num1, num2) => {\r\n let a = Math.abs(num1);\r\n let b = Math.abs(num2);\r\n while (a && b && a !== b) {\r\n if (a > b) {\r\n [a, b] = [a % b, b];\r\n } else {\r\n [a, b] = [a, b % a];\r\n }\r\n }\r\n return a || b;\r\n};\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction foo(n1, n2) {\r\n if (n1 == 1) return 0\r\n if (n2 == 0) return n1\r\n return foo(n2, n1 % n2)\r\n}\r\n\r\nfunction solve([n], arr) {\r\n let sum = 0\r\n for (let i = 0; i < n - 1; ++i) {\r\n for (let j = i + 1; j < n; ++j) {\r\n if (arr[i] % 2 == 0) {\r\n sum++\r\n } else if (arr[j] % 2 == 0) {\r\n sum++\r\n } else {\r\n if (foo(arr[i], arr[j]) > 1 || foo(arr[j], 2 * arr[i] > 1)) sum++\r\n }\r\n }\r\n }\r\n console.log(sum)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/04/21 morning\r\n * https://codeforces.com/contest/1535/problem/B\r\n */\r\n\r\nconst solve = (n, A) => {\r\n let even = [];\r\n let odd = [];\r\n for (const e of A) e & 1 ? odd.push(e) : even.push(e);\r\n let a = even.concat(odd);\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] % 2 == 0) {\r\n res += n - 1 - i;\r\n continue;\r\n }\r\n for (let j = i + 1; j < n; j++) {\r\n if (gcd(a[i], 2 * a[j]) > 1) {\r\n res++;\r\n }\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var nums = lines[l++].split(' ').map(Number)\n console.log(solve(n, nums));\n }\n});\n \nfunction solve(n, nums) {\n nums.sort((a, b) => {\n const i = a & 1\n const j = b & 1\n if (i === j) {\n return 0\n } else if (i) {\n return 1\n } else {\n return -1\n }\n })\n\n let count = 0\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n if (gcd(nums[i], 2 * nums[j]) > 1) count++\n }\n }\n return count\n}\n\nfunction gcd(a, b) {\n if (a === 0) return b\n if (b === 0) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}], "negative_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n a.sort((x, y) => y - x);\r\n var ans = 0;\r\n for (var i = 0; i < n; i++) {\r\n for (j = i + 1; j < n; j++) {\r\n if (gcd(a[i], 2 * a[j]) > 1) {\r\n ans++;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tif(gcd(list[i], 2 * list[j]) > 1){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}\r\n"}], "src_uid": "d638f524fe07cb8e822b5c6ec3fe8216"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst getOutput = n => {\n let output = [];\n while(n>0) {\n if(n%7 === 0) {\n n = n-7;\n output.push(7);\n } else if(n>=4 && n!=7) {\n n = n-4;\n output.push(4);\n } else {\n return -1;\n }\n }\n\n return output.join(\"\");\n}\n\nrl.on('line', n => {\n \n console.log(getOutput(n));\n\n process.exit();\n});", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r=0;--e)if(!(7*e>t)&&(t-7*e)%4==0){let r=\"\";for(let n=0;n<(t-7*e)/4;++n)r+=4;for(let t=0;t{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tfor (var i = 1, _i = 25e4; i < _i; i++) {\n\t\t\tif (i * 4 > n) return -1;\n\n\t\t\tvar t = (n - i * 4) / 3;\n\t\t\tif ((t%1) === 0 && t <= i) {\n\t\t\t\tvar result = '';\n\t\t\t\twhile (t--) result += '7';\n\t\t\t\twhile (result.length < i) result = '4' + result;\n\t\t\t\treturn result;\t\t\t\t\n\t\t\t}\n\t\t}\n\n\t}(+readline()));\n\n}.call(this));\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst getOutput = n => {\n let output = [];\n while(n>0) {\n if(n==7) {\n n = n-7;\n output.push(7);\n } else if(n>=4 && n!=7) {\n n = n-4;\n output.push(4);\n } else {\n return -1;\n }\n console.log(output);\n }\n\n return output.join(\"\");\n}\n\nrl.on('line', n => {\n \n console.log(getOutput(n));\n\n process.exit();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst getOutput = n => {\n let output = [];\n while(n>0) {\n if(n==7) {\n n = n-7;\n output.push(7);\n } else if(n>=4 && n!=7) {\n n = n-4;\n output.push(4);\n } else {\n return -1;\n }\n }\n\n return output.join(\"\");\n}\n\nrl.on('line', n => {\n \n console.log(getOutput(n));\n\n process.exit();\n});"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{i=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function c(){return i[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt)return void o.default.put(-1);if((t-7*e)%4==0){for(let r=0;r<(t-7*e)/4;++r)o.default.put(4);for(let t=0;t{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function c(){return s[i++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}function d(){return c().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt){if(e.length>0)break;return void o.default.put(-1)}if((t-7*r)%4==0){let n=\"\";for(let e=0;e<(t-7*r)/4;++e)n+=4;for(let t=0;tt.length-e.length))[0])}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tfor (var i = 1, _i = 25e4; i < _i; i++) {\n\t\t\tvar k = i * 4;\n\n\t\t\tif (k > n) return -1;\n\n\t\t\tvar t = (n - k) / 3;\n\t\t\tif ((t%1) !== 0) continue;\n\n\t\t\tif (t > i + 1) continue;\n\n\t\t\tvar result = '';\n\t\t\twhile (t--) result += '7';\n\t\t\twhile (result.length < i) result = '4' + result;\n\t\t\treturn result;\n\t\t}\n\n\t}(+readline()));\n\n}.call(this));\n"}], "src_uid": "2584fa8c1adb1aa8cd5c28a8610ff72d"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let sum = arr.reduce((a, x) => a + x, 0);\n\n console.log(Math.min(m, sum));\n\n c++;\n});\n", "positive_code": [{"source_code": "const main = data => {\n const t = data[0];\n\n for (let i = 0; i < t; i++) {\n const [n, m] = data[i * 2 + 1].split(' ').map(x => +x);\n const arr = data[i * 2 + 2].split(' ').map(x => +x);\n\n for (let j = 1; j < n; j++) {\n while (arr[j] > 0 && arr[0] < m) {\n arr[j]--;\n arr[0]++;\n }\n }\n\n console.log(arr[0]);\n }\n};\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});"}, {"source_code": "function processData(input) {\n //Enter your code here\n input = input.trim().split(\"\\n\")\n input.shift()\n let arr = []\n for(let i = 0; i < input.length; i++){\n var first = input[i].trim().split(\" \").map(Number)\n var val = first[1]\n arr = input[i+1].trim().split(\" \").map(Number)\n console.log(grade(val, arr))\n i = i + 1\n }\n \n function grade(val, arr){\n let sum = 0\n let len = arr.length\n for(let k = 0; k < len; k++){\n sum = sum + arr[k]\n }\n let aver = sum / len\n let top = 0\n if(val <= sum){\n top = val\n }\n else{\n top = sum\n }\n return top\n }\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const [n, m] = readInts(input, ptr++)\n let ai = readInts(input, ptr++)\n let sum = ai.reduce((a, b) => a + b, 0)\n wr(Math.min(sum, m))\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = [];\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var M = one[1];\n var list = nextIntArray();\n var sum = 0;\n for(var j = 0; j < N; j++){\n sum += list[j];\n }\n output[i] = Math.min(sum , M);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solution(n, m, a) {\n let d = m - a[0];\n\n for(let i = 1; i < n; i++){\n d -= a[i];\n if (d <= 0){\n d = 0;\n break;\n }\n }\n\n return m - d;\n}\n\nfunction main() {\n const N = parseInt(readline());\n \n for(let i = 0; i < N; i++){\n const line1 = readline().split(' ').map(item => parseInt(item));\n const line2 = readline().split(' ').map(item => parseInt(item));\n console.log(solution(line1[0], line1[1], line2));\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solution(n, m, a) {\n let s = 0;\n a.map(i => s+=i);\n return Math.min(m, s);\n}\n\nfunction main() {\n const N = parseInt(readline());\n \n for(let i = 0; i < N; i++){\n const line1 = readline().split(' ').map(item => parseInt(item));\n const line2 = readline().split(' ').map(item => parseInt(item));\n console.log(solution(line1[0], line1[1], line2));\n }\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\nlet n, m;\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n for(let i = 0; i < t; i++){\n let marks = lines[i * 2 + 2].split(\" \");\n [n,m] = lines[i * 2 + 1].split(' ');\n //console.log(n + \" \" + m);\n let my_mark = parseInt(marks[0]);\n let sum = 0;\n for(let j = 1; j < parseInt(n); j++){\n sum += parseInt(marks[j]);\n }\n if(sum + my_mark > parseInt(m))\n answer += m + '\\n';\n else{\n answer += (sum + my_mark) + '\\n'\n }\n }\n console.log(answer);\n});"}, {"source_code": "function main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (v) { return v.trim().split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var t = lines.shift()[0];\n while (t > 0) {\n var _a = lines.shift(), n = _a[0], m = _a[1];\n var scores = lines.shift();\n var myScore = scores[0];\n var i = 1;\n while (i < scores.length && myScore < m) {\n myScore += scores[i];\n i++;\n }\n if (myScore > m) {\n console.log(m);\n }\n else {\n console.log(myScore);\n }\n t--;\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "// Time Complexity O(n)\nfunction processData(input) {\n //Enter your code here\n var data = input.trim().split('\\n')\n var tcs = Number(data[0])\n var line = 1\n for(var i = 0;iparseInt(a))\n line++\n var arr = data[line].trim().split(' ').map(a=>parseInt(a))\n line++\n var sum = 0\n for(var j = 0;j< n;j++){\n sum += arr[j]\n }\n // console.log(sum)\n var res = Math.min(sum,m)\n console.log(res)\n }\n \n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let r = [];\n for(let i = 0 ; i < t; i++) {\n let [n, m] = nl.nums(); \n let a = nl.nums();\n let s = a.reduce((x,y) => x + y, 0);\n r.push(Math.min(m, s));\n \n }\n\tconsole.log(r.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict'\n\nconst problem = (n, m, a) => {\n let x = a[0];\n for(let i = 1; i < n; i++) if ((x += a[i]) >= m) return m;\n return x;\n};\n\nlet t = +readline()\nwhile(t--) {\n const nm = readline().split(' ');\n print(problem(+nm[0], +nm[1], readline().split(' ').map(i => +i)));\n}\n"}, {"source_code": "var tests= readline();\n \nfor(var n=0;n=max){scores[0]=max;break;}\n }//for each score\n \n end:print(`${scores[0]}`);\n \n \n}//for each test\n"}, {"source_code": "//var input = readline();\n\nvar T = parseInt(readline());\nwhile (T-- > 0) {\n var kk = readline().split(\" \").map(x => parseInt(x));\n var n = kk[0], m = kk[1];\n var ar = readline().split(' ').map(x => parseInt(x));\n var sum = ar.reduce((a, b) => a + b);\n print(m >= sum ? sum : m);\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, m, a) => {\n let x = a[0];\n for(let i = 1, x = 0; i < n; i++) if ((x += a[i]) >= m) return m;\n return x;\n};\n\nlet t = +readline()\nwhile(t--) {\n const nm = readline().split(' ');\n print(problem(+nm[0], +nm[1], readline().split(' ').map(i => +i)));\n}\n"}, {"source_code": "'use strict'\n\nconst problem = (n, m, a) => {\n if (n > m) return 0;\n let r = 1;\n\n for (let i = 0; i < n - 1; i++)\n for (let j = i + 1; j < n; j++)\n r = (r * (a[j] -= a[i])) % m;\n\n return Math.abs(r);\n}\n\nconst nm = readline().split(' ').map(i => +i);\nconst n = nm[0], m = nm[1];\n\nprint(problem(n, m, readline().split(' ').map(i => +i)))\n"}, {"source_code": "// Time Complexity O(n)\nfunction processData(input) {\n //Enter your code here\n var data = input.trim().split('\\n')\n var tcs = Number(data[0])\n var line = 1\n for(var i = 0;iparseInt(a))\n line++\n var arr = data[line].trim().split(' ').map(a=>parseInt(a))\n line++\n var sum = 0\n for(var j = 0;j< n;j++){\n sum += arr[j]\n }\n console.log(sum)\n var res = Math.min(sum,m)\n console.log(res)\n }\n \n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}], "src_uid": "7c2a61de728e6767b25e58c74497bbae"} {"source_code": "function deathNote (restArgs) {\n\tconst days = parseInt(restArgs[0]);\n\tconst limit = parseInt(restArgs[1]);\n\tconst names = readline().split(\" \");\n\tvar current = 0;\n\tvar pages = \"\";\n\tvar i;\n\tfor (i =0; i{\n v =+v + +o;\n result.push(parseInt(v/m));\n o = v%m;\n });\n print(result.join(' '));\n}\n\nmain();"}, {"source_code": "var m = parseInt(readline().split(' ')[1]);\nvar l = 0;\n\nprint(readline().split(' ').map(function(order){\n order = parseInt(order) + l;\n l = order % m\n \n return parseInt(order / m);\n}).join(' '));\n"}, {"source_code": "var line = readline().split(\" \")\nvar names = readline().split(\" \")\nvar limitPage = line[1]\nvar remaining = 0;\nvar responseArray = []\nfor(var i = 0; i < names.length; i++){\n var numOfNames = parseInt(names[i]) + remaining\n responseArray.push(Math.floor(numOfNames / limitPage))\n remaining = numOfNames % limitPage\n}\n\nprint(responseArray.join(\" \"))"}, {"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0];\nvar m = nm[1];\n\nvar a = readline().split(' ').map(Number);\nvar output = ''\nvar ostatok = 0;\n\nfor (var i=0; i parseInt(n));\nvar n = nm[0];\nvar m = nm[1];\nvar numNames = readline().split(' ').map(n => parseInt(n));\n\nvar prev = 0;\nvar res = [];\nfor (var i = 0; i < numNames.length; i++) {\n var numName = numNames[i];\n var total = prev + numName;\n var pages = parseInt(total/m);\n prev = total % m;\n res.push(pages);\n}\nprint(res.join(' '));\n"}, {"source_code": "// const print = require('lol-io').print;\n// const readline = require('lol-io').readline;\n//\n\nvar nm = readline().split(' ').map(n => parseInt(n));\nvar n = nm[0];\nvar m = nm[1];\nvar numNames = readline().split(' ').map(n => parseInt(n));\n\nvar prev = 0;\nvar res = [];\nfor (var i = 0; i < numNames.length; i++) {\n var numName = numNames[i];\n var total = prev + numName;\n var pages = parseInt(total/m);\n prev = total % m;\n res.push(pages);\n}\nprint(res.join(' '));\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n const books = is.nextArray(Number);\n let container = 0, turnPage;\n for (let i = 0; i < n; i += 1) {\n turnPage = 0;\n container += books[i];\n turnPage = Math.trunc(container / m);\n container %= m;\n process.stdout.write(String(turnPage) + ' ');\n }\n console.log();\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const readline = require('readline')\n\nvar interface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nvar n, m\nvar nums\nvar lineCount = 0\ninterface.on('line', function (line) {\n var splits = line.trim().split(' ').map(x => parseInt(x))\n if (lineCount == 0) {\n n = splits[0]\n m = splits[1]\n lineCount ++\n } else if (lineCount == 1) {\n nums = line.trim().split(' ')\n var rest = 0\n var answer = ''\n for (var i = 0; i < nums.length; i++) {\n var pages\n\n if (nums[i] < rest) {\n // console.log('nums[i]:' + nums[i], 'rest:' + rest, 'result:0')\n pages = 0\n rest = rest - nums[i]\n } else {\n pages = Math.floor((nums[i] - rest) / m)\n if (rest > 0) {\n pages += 1\n }\n // console.log('nums[i]:' + nums[i], 'rest:' + rest, 'result:' + pages)\n if ((nums[i] - rest) % m == 0) {\n rest = 0\n } else {\n rest = m - ((nums[i] - rest) % m)\n }\n }\n answer += pages + ' '\n }\n console.log(answer)\n process.exit()\n }\n})\n"}, {"source_code": "const readline = require('readline')\n\nvar interface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nvar n, m\nvar nums\nvar lineCount = 0\ninterface.on('line', function (line) {\n var splits = line.trim().split(' ').map(x => parseInt(x))\n if (lineCount == 0) {\n n = splits[0]\n m = splits[1]\n lineCount ++\n } else if (lineCount == 1) {\n nums = line.trim().split(' ')\n var rest = 0\n var answer = ''\n for (var i = 0; i < nums.length; i++) {\n var pages\n\n if (nums[i] < rest) {\n pages = 0\n rest = rest - nums[i]\n } else {\n pages = Math.floor((nums[i] - rest) / m)\n if (rest > 0) {\n pages += 1\n }\n if ((nums[i] - rest) % m == 0) {\n rest = 0\n } else {\n rest = m - ((nums[i] - rest) % m)\n }\n }\n // console.log(pages + ' ')\n answer += pages + ' '\n }\n console.log(answer)\n process.exit()\n }\n})\n"}], "negative_code": [{"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0];\nvar m = nm[1];\n\nvar a = readline().split(' ').map(Number);\nvar output = ''\nvar ostatok = 0;\n\nfor (var i=0; i +item).sort((a, b) => a - b),\n ans = new Array(n);\n\nans[0] = l[0];\nans[n - 1] = l[1];\n\nfor(var i = 2, pos = 1; i < n - 1; i+= 2, pos++) {\n ans[pos] = l[i];\n ans[n - pos - 1] = l[i + 1];\n}\n\nif (n % 2) {\n ans[pos] = l[i];\n}\n\nprint(ans.join(\" \"));\n\n", "positive_code": [{"source_code": "var nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = nums[0];\nvar s = readline().split(\" \").map(function(x) { return parseInt(x); });\ns.sort(function(a,b) {return a-b;});\nvar s_init = s.slice();\nvar ans2 = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans2[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans2[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nfor (var i=0; i=0; k--) {\n\tif (cc%2===0) {\n\t\tans3[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans3[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nvar ans_new = 0;\nfor (var i=0; i down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort(function(a,b) {return a-b;});\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort(function(a,b) {return a-b;});\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; k down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort(function(a,b) {return a-b;});\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n w.sort(function(a,b) {return a-b;});\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; ka>b);\nvar ans2 = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans2[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans2[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nfor (var i=0; ia>b);\nvar s_init = s.slice();\nvar ans2 = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans2[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans2[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nfor (var i=0; i down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; k down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n//write(\" Mindiff = \", down);\n//write(\"\\n So ans = \",res.join(\" \"));\n//write(\"\\n\");\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; ka>b);\nvar s_init = s.slice();\nvar ans2 = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans2[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans2[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nfor (var i=0; i down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n//write(\" Mindiff = \", down);\n//write(\"\\n So ans = \",res.join(\" \"));\n//write(\"\\n\");\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; ka>b);\nvar ans = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nwrite(ans.join(\" \"));\n//for (var i=0; ia>b);\nvar s_init = s.slice();\nvar ans2 = Array(n).fill(0);\nvar i = n-1, j = 0, cc = 0;\nfor (var k=n-1; k>=0; k--) {\n\tif (cc%2===0) {\n\t\tans2[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans2[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nfor (var i=0; ia=0; k--) {\n\tif (cc%2===0) {\n\t\tans3[i] = s[k];\n\t\ti--;\n\t}\n\telse {\n\t\tans3[j] = s[k];\n\t\tj++;\n\t}\n\tcc++;\n}\nvar ans_new = 0;\nfor (var i=0; i down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = [];\n\tres.push(w[n-1]);\n\tnnew[n-1] = 1;\n\tvar x = w[n-1];\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tres.push(w[ind]);\n\t\tx = w[ind];\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; k down) {\n\tvar mid = Math.floor((up + down)/2);\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok === 1) up = mid;\n\telse down = mid + 1;\n}\nif (down >= 0) {\n\tvar mid = down;\n\tvar Ok = 1;\n\tvar w = s_init.slice();\n\tw.sort((a,b)=>a>b);\n\tvar nnew = Array(n).fill(0);\n\tvar res = Array(n).fill(0);\n\tres[0] = w[n-1];\n\tnnew[n-1] = 1;\n\tvar aa = 1, bb = n-1;\n\tfor (var j=0; j mx_diff && diff <= mid) {\n\t\t\t\t\tmx_diff = diff;\n\t\t\t\t\tind = k;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ind < 0) {\n\t\t\tOk = 0;\n\t\t\tbreak;\n\t\t}\n\t\tnnew[ind] = 1;\n\t\tx = w[ind];\n\n\t\tif (j%2===0) {\n\t\t\tres[aa] = x;\n\t\t\taa++;\n\t\t}\n\t\telse {\n\t\t\tres[bb] = x;\n\t\t\tbb--;\n\t\t}\n\t}\n\tif (Ok)\n\t\tif (Math.abs(res[0] - res[n-1]) > mid) {\n\t\t\tvar t = res[n-1];\n\t\t\tres[n-1] = res[n-2];\n\t\t\tres[n-2] = t;\n\t\t\tfor (var k=0; k mid) {Ok = 0; break;}\n\t\t}\n\tif (Ok) {\n\t\tvar new_ans = 0;\n\t\tfor (var k=0; k +item).sort((a, b) => a - b),\n ans = new Array(n);\n\nans[0] = l[0];\nans[n - 1] = l[1];\n\nfor(var i = 2, pos = 1; i <= Math.floor(n/2); i += 2, pos++) {\n ans[pos] = l[i];\n ans[n - pos - 1] = l[i + 1];\n}\n\nif (n % 2) {\n ans[pos] = l[i];\n}\n\nprint(ans.join(\" \"));\n\n"}, {"source_code": "var n = +readline(),\n l = readline().split(\" \").map(item => +item).sort((a, b) => a - b),\n ans = [];\n\nfor (var i = 0; i < n; i++) {\n ans.push(0);\n}\n\nans[0] = l[0];\nans[n - 1] = l[1];\n\nfor(var i = 2, pos = 1; i <= Math.floor(n/2); i += 2, pos++) {\n ans[pos] = l[i];\n ans[n - pos - 1] = l[i + 1];\n}\n\nif (n % 2) {\n ans[pos] = l[i];\n}\n\nprint(ans.join(\" \"));\n\n"}], "src_uid": "205b2332c176b758e843473e8d357475"} {"source_code": "var m1 = {}, m2 = {};\nvar n, m;\nvar token = [];\nvar ans = \"\";\n\ntoken = readline().split(' ');\nn = parseInt(token[0]);\nm = parseInt(token[1]);\n\nfor(var i=0;i0) ans+=\" \";\n\n if(w1.length<=w2.length) {\n ans+=w1;\n }\n else {\n ans+=w2;\n }\n}\n\nprint(ans);\n", "positive_code": [{"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', line => input.push(line));\n\nRL.on('close', () => {\n const [n, m] = input[0].split(' ').map(x => parseInt(x));\n const map = {};\n\n for (let i = 0; i < m; i += 1) {\n let [w1, w2] = input[i+1].split(' ');\n \n map[w1] = {len: w1.length, w: w2};\n map[w2] = {len: w2.length, w: w1};\n }\n\n const answer = [];\n const dict = input[m+1].split(' ');\n \n for (const w of dict) {\n if (map[w].len <= map[w].w.length) {\n answer.push(w);\n } else {\n answer.push(map[w].w);\n }\n answer.push(' ');\n }\n\n console.log(answer.join(''));\n});"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet dic = {};\n\n\twhile (m--) {\n\t\tlet [key, value] = readLine().split(' ');\n\t\tdic[key] = value;\n\t}\n\n\tlet lec = readLine().split(' ');\n\tconst res = lec.map(word =>\n\t\tword.length <= dic[word].length ? word : dic[word]\n\t);\n\n\tconsole.log(res.join(' '));\n}\n"}, {"source_code": "var input = readline().split(\" \").map(Number), n = input[0], m = input[1];\nvar lang1to2 = {}, lang2to1 = {};\n\nfor(var i = 0; i < m; i++){\n\tinput = readline().split(\" \");\n\n\tlang1to2[input[0]] = input[1];\n\tlang2to1[input[1]] = input[0];\n}\n\nvar speech = readline().split(\" \");\n\nfor(var i = 0; i < n; i++){\n\tif(lang1to2[speech[i]] != undefined){\n\t\tif(speech[i].length <= lang1to2[speech[i]].length){\n\t\t\twrite(speech[i]);\n\t\t}\n\t\telse{\n\t\t\twrite(lang1to2[speech[i]]);\n\t\t}\n\t}\n\telse{\n\t\tif(speech[i].length <= lang2to1[speech[i]].length){\n\t\t\twrite(speech[i]);\n\t\t}\n\t\telse{\n\t\t\twrite(lang2to1[speech[i]]);\n\t\t}\n\t}\n\n\twrite(\" \");\n}"}, {"source_code": "function main(n,m,arr,prof) {\n\n var ans = \"\"\n\n for(var i = 0 ; i < n ; i++){\n for(var j = 0 ; j < m ; j++){\n if(prof[i] === arr[j][0]){\n if(prof[i].length > arr[j][1].length)ans = ans + arr[j][1] + \" \";\n else ans = ans + arr[j][0] + \" \";\n break;\n }\n }\n }\n\n print(ans);\n\n}\n\n//\n// main(4,3,[[\"codeforces\",\"codesecrof\"],[\"contest\",\"round\"],[\"letter\",\"message\"]],\n// [\"codeforces\",\"contest\",\"letter\",\"contest\"])\n//\n\n\nvar nm = readline().split(\" \");\n\nvar arr = []\n\nfor(var i = 0 ; i < parseInt(nm[1]) ; i++){\n arr[i] = readline().split(\" \");\n}\n\nvar prof = readline().split(\" \");\n\nmain(parseInt(nm[0]),parseInt(nm[1]),arr,prof);\n"}, {"source_code": "var t = readline().split(' ');\nvar n = t[0];\nvar m = t[1];\nvar i = 0, inpStr1, slo1 = [], slo2 = [];\n\nfor(i=0; i slo2[k].length) \n {\n outStr = outStr + slo2[k];\n }\n else if (inpStr2[i] == slo1[k]) \n {\n outStr = outStr + slo1[k];\n }\n }\n if (i= a.length)\n b = a;\n result[a] = b;\n }\n return result;\n };\n \n function writeAnswer(answer) {\n for (i = 0; i < answer.count; ++i) {\n write(answer.get(answer, i));\n if (i < answer.count - 1)\n write(' ');\n }\n }\n\n var input = readline().split(' ');\n var n = parseInt(input[0]);\n var m = parseInt(input[1]);\n var inf = createDictionary(m);\n\n input = readline().split(' ');\n writeAnswer({\n count: n,\n data: input,\n dict: inf,\n get: function(self, index) {\n return self.dict[self.data[index]];\n }\n });\n})()"}, {"source_code": "//var input = \"4 3\\ncodeforces codesecrof\\ncontest round\\nletter message\\ncodeforces contest letter contest\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var mapF = {};\n var mapS = {};\n var t = readline().split(' ');\n var n = parseInt(t[0]);\n var m = parseInt(t[1]);\n for(var i = 0; i < m; i++){\n var arr = readline().split(' ');\n mapF[arr[0]] = arr[1];\n mapS[arr[1]] = arr[0];\n }\n var text = readline().split(' ');\n var ans = \"\";\n for(var i = 0; i < text.length; i++){\n if(text[i] in mapF){\n var val = mapF[text[i]];\n if(val.length < text[i].length)\n ans += val;\n else\n ans += text[i];\n }else{\n var val = mapS[text[i]];\n if(val.length <= text[i].length)\n ans += val;\n else\n ans += text[i];\n }\n ans += \" \";\n }\n print(ans);\n}\nmain();"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, strs, di1 ={}, di2 = {}, c = 0,\nlec, arr1 = [], arr = [];\nrl.on('line', input => {\n if (n && m && c < m ) {\n arr.push(input);\n let str = arr[c].split(' ')\n di1[str[0]] = str[1]\n c++;\n } else if ( c >= m ) {\n lec = input.split(' ');\n c++;\n for (let j = 0; j < lec.length; j++) {\n if (lec[j].length > di1[lec[j]].length) {\n lec[j] = di1[lec[j]]\n }\n }\n console.log(lec.join(' '))\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet [lectureLength, languageWords] = [null];\nlet wordsA = [], wordsB = [], speech = [];\n\nreadline.on('line', line => {\n if (!lectureLength) {\n [lectureLength, languageWords] = line.split(' ');\n } else if (wordsA.length < languageWords) {\n let [a, b] = line.split(' ');\n wordsA.push(a);\n wordsB.push(b);\n } else {\n speech = line.split(' ');\n readline.close();\n }\n});\n\nreadline.on('close', () => {\n writeNote();\n});\n\nconst writeNote = () => {\n let result = '';\n speech.map(word => {\n let comparator = wordsB[wordsA.indexOf(word)];\n let shorter = comparator.length < word.length ? comparator : word;\n result += shorter + ' ';\n })\n console.log(result.trim());\n};"}], "negative_code": [{"source_code": "var t = readline().split(' ');\nvar n = t[0];\nvar m = t[1];\nvar i = 0, inpStr1, slo1 = [], slo2 = [];\n\nfor(i=0; i slo2[k].length) \n {\n outStr = outStr + slo2[k];\n }\n else\n {\n outStr = outStr + slo1[k];\n }\n }\n if (i>0 && i input.push(line));\n\nRL.on('close', () => {\n const [n, m] = input[0].split(' ').map(x => parseInt(x));\n const map = {};\n\n for (let i = 0; i < m; i += 1) {\n let [w1, w2] = input[i+1].split(' ');\n \n map[w1] = {len: w1.length, w: w2};\n map[w2] = {len: w2.length, w: w1};\n }\n\n const answer = [];\n const dict = input[m+1].split(' ');\n \n for (const w of dict) {\n if (map[w].len < map[w].w.length) {\n answer.push(w);\n } else {\n answer.push(map[w].w);\n }\n answer.push(' ');\n }\n\n console.log(answer.join(''));\n});"}], "src_uid": "edd556d60de89587f1b8daa893538530"} {"source_code": "var tc = parseInt(readline());\nwhile (tc--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n var sum = ar.reduce((a, b) => a + b);\n var MX = Math.max(...ar);\n var ok = 0;\n if (MX > sum / 2) ok = 1;\n if (sum & 1) ok = 1;\n print(ok ? 'T' : 'HL');\n}\n ", "positive_code": [{"source_code": "for (var t = parseInt(readline()); t > 0; t --) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ').map(x => parseInt(x));\n\tvar total = 0;\n\tvar largest = 0;\n\tfor (var i = 0; i < n; i ++) {\n\t\ttotal += arr[i];\n\t\tif (arr[i] > largest) largest = arr[i];\n\t}\n\tvar winner = '';\n\tif (n === 1) {\n\t\twinner = 'T';\n\t} else if (largest > total - largest) {\n\t\twinner = 'T';\n\t} else if (total % 2 === 0) {\n\t\twinner = 'HL';\n\t} else {\n\t\twinner = 'T';\n\t}\n\tprint(winner);\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), a = $(n).sort(desc)\n if (n == 1) {\n log('T')\n } else {\n if (a[0] > a.sum() - a[0]) log('T')\n else log((a.sum() - a[0] - a[0]) % 2 ? 'T' : 'HL')\n }\n }\n}\n"}, {"source_code": "// Lang: Node.js\n'use strict';\nlet x = '', y = 0;\nlet print = x => console.log(x);\n \nprocess.stdin.on('data', inputStdin => x += inputStdin);\nprocess.stdin.on('end', () => { x = x.split('\\n'); main(); });\nlet readline = () => x[y++];\n \n \n// ************************ Code Start ***************************\n\nfunction main() {\n \n var tc = parseInt(readline());\n while (tc--) {\n var n = parseInt(readline());\n var ar = readline().split(\" \").map((x) => parseInt(x));\n var sum = ar.reduce((a, b) => a + b);\n var MX = Math.max(...ar);\n var ok = 0;\n if (MX > sum / 2) ok = 1;\n if (sum & 1) ok = 1;\n print(ok ? \"T\" : \"HL\");\n }\n}\n"}], "negative_code": [{"source_code": "for (var t = parseInt(readline()); t > 0; t --) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ').map(x => parseInt(x));\n\tvar total = 0;\n\tfor (var i = 0; i < n; i ++) total += arr[i];\n\tif (n === 1) {\n\t\tprint('T');\n\t} else if (total % 2 === 0) {\n\t\tprint('HL');\n\t} else {\n\t\tprint('T');\n\t}\n}"}, {"source_code": "for (var t = parseInt(readline()); t > 0; t --) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ').map(x => parseInt(x));\n\tvar total = 0;\n\tvar oneCount = 0;\n\tfor (var i = 0; i < n; i ++) {\n\t\ttotal += arr[i];\n\t\tif (arr[i] === 1) oneCount ++;\n\t}\n\tvar winner = '';\n\tif (n === 1) {\n\t\twinner = 'T';\n\t} else if (total % 2 === 0) {\n\t\twinner = 'HL';\n\t} else {\n\t\twinner = 'T';\n\t}\n\tif (oneCount % 2 === 0 && oneCount !== 0) {\n\t\tif (winner === 'T') {\n\t\t\twinner = 'HL';\n\t\t} else {\n\t\t\twinner = 'T';\n\t\t}\n\t}\n\tprint(winner);\n}"}, {"source_code": "var inp = readline().split(' ');\nvar m = parseInt(inp[0]);\nvar s = parseInt(inp[1]);\n\nvar largestArr = [], smallestArr = [];\nfor (var i = 0; i < m; i ++) {\n\tlargestArr.push(0);\n\tsmallestArr.push(1);\n}\n\nvar largestOn = 0, smallestOn = m - 1;\nfor (var i = 0; i < s; i ++) {\n\tif (largestOn < m) {\n\t\tlargestArr[largestOn] ++;\n\t\tif (largestArr[largestOn] === 9) largestOn ++;\n\t} else largestArr = [-1];\n\t\n\tif (smallestOn >= 0 && m <= s) {\n\t\tif (i >= m) {\n\t\t\tsmallestArr[smallestOn] ++;\n\t\t\tif (smallestArr[smallestOn] === 9) smallestOn --;\n\t\t}\n\t} else smallestArr = [-1];\n}\n\nprint(s === 0 ? '-1 -1' : smallestArr.join('') + ' ' + largestArr.join(''));"}, {"source_code": "for (var t = parseInt(readline()); t > 0; t --) {\n\tvar n = parseInt(readline());\n\tvar arr = readline().split(' ').map(x => parseInt(x));\n\tvar odds = 0;\n\tvar evens = 0;\n\tfor (var i = 0; i < n; i ++) {\n\t\tif (arr[i] % 2 === 0) {\n\t\t\tevens ++;\n\t\t} else {\n\t\t\todds ++;\n\t\t}\n\t}\n\tif (evens <= odds) {\n\t\tprint('HL');\n\t} else {\n\t\tprint('T');\n\t}\n}"}], "src_uid": "5bfce6c17af24959b4af3c9408536d05"} {"source_code": "var t = readline();\nvar s = '';\n\nfor(var i=0; i {\n if (l === t + 1) {\n return 0\n }\n if (l === 0) {\n t = parseInt(input)\n } else {\n let s = input.split('')\n s.sort()\n if (s[0] !== s[s.length - 1]) {\n console.log(s.join(\"\"))\n } else {\n console.log(-1)\n }\n }\n l++\n});\n"}, {"source_code": "var t = function () {\n var input = readline();\n return parseInt(input);\n} ();\n\nfor(var i=0; i {\n input.push(line.trim());\n});\nRL.on(\"close\", () => {\n const N = +input[0];\n for (let i = 1; i <= N; i += 1) {\n const setSize = isImpossible(input[i]);\n if (setSize === 1) {\n console.log(-1);\n continue;\n }\n\n initArray();\n solve(input[i]);\n }\n});\n\nfunction isImpossible(str) {\n mySet.clear();\n for (let char of str) {\n mySet.add(char);\n }\n return mySet.size;\n}\n\nfunction initArray() {\n for (let i = 0; i < 26; i += 1) {\n arr[i] = 0;\n }\n}\n\nfunction isPalindrome(str) {\n const shrinked = arr.map(ele => {\n return ele % 2;\n });\n\n let count = 0;\n shrinked.forEach(ele => {\n if (ele === 1) {\n count += 1;\n }\n });\n\n if (count >= 2) {\n return false;\n }\n\n return true;\n}\n\nfunction solve(str) {\n for (let char of str) {\n arr[char.codePointAt(0) - \"a\".codePointAt(0)] += 1;\n }\n\n const answer = isPalindrome(arr);\n if (answer === false) {\n console.log(str);\n return;\n }\n\n let good = \"\";\n let oddValue = -1;\n let oddIndex = -1;\n\n arr.forEach((value, index) => {\n if (value === 0) {\n return;\n }\n\n if (value % 2 === 1) {\n oddValue = value;\n oddIndex = index;\n return;\n }\n\n const left = good.slice(0, parseInt(good.length / 2));\n const right = good.slice(parseInt(good.length / 2), good.length);\n const middle = String.fromCodePoint(index + \"a\".codePointAt(0)).repeat(\n value\n );\n\n good = left + middle + right;\n });\n\n if (oddIndex !== -1) {\n const left = good.slice(0, parseInt(good.length / 2));\n const right = good.slice(parseInt(good.length / 2), good.length);\n const middle = String.fromCodePoint(oddIndex + \"a\".codePointAt(0)).repeat(\n oddValue\n );\n\n good = left + middle + right;\n }\n\n const temp = good.split(\"\");\n [temp[0], temp[parseInt(temp.length / 2)]] = [\n temp[parseInt(temp.length / 2)],\n temp[0]\n ];\n console.log(`${temp.join(\"\")}`);\n}\n"}, {"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\nfunction numericSortList(list){\n list.sort((a,b)=>a-b);\n}\n\nfunction getRectangleIntersection(r1, r2)\n{\n if(r1.x > r2.x+r2.w) return null;\n if(r1.x+r1.w < r2.x) return null;\n if(r1.y > r2.y+r2.h) return null;\n if(r1.y+r1.h < r2.y) return null;\n\n var rect = {};\n rect.x = Math.max(r1.x, r2.x);\n rect.y = Math.max(r1.y, r2.y);\n rect.w = Math.min(r1.x+r1.w, r2.x+r2.w)-rect.x;\n rect.h = Math.min(r1.y+r1.h, r2.y+r2.h)-rect.y;\n\n return rect;\n}\n\nfunction getRandomNumber(to, from){\n if(from == undefined){\n return Math.floor(Math.random()*to + 1);\n }\n return Math.floor(Math.random()*(to - from) + from);\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n\nfunction solve(){\n var cases = readInts()[0];\n it(cases);\n for(var i = 0; i < cases; i++){\n it(i);\n\n /**\n * @type {string}\n */\n var str = readline();\n it(str);\n \n var charToCount = {};\n\n for(var c of str){\n it(c);\n if(charToCount[c]){\n ++charToCount[c];\n } else charToCount[c] = 1;\n }\n\n if(Object.keys(charToCount).length <= 1){\n print('-1');\n continue;\n } \n\n var newStr = '';\n\n Object.keys(charToCount).forEach(function(key) {\n for(var k = 0; k < charToCount[key]; k++){\n it('new char : ' + key)\n newStr += key;\n }\n });\n\n print(newStr);\n }\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = [...str];\n arr.sort();\n\n const r = arr.join('');\n const reverseR = arr.reverse().join('');\n\n if (r === reverseR) {\n console.log(-1);\n }\n else {\n console.log(r);\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let l=0;\n let t=0\n rl.on('line', (input) => {\n if(l===t+1)\n {\n return 0\n }\n if (l==0) {\n t=parseInt(input)\n } else {\n let s= input.split('')\n s.sort()\n let isPal = true\n for(let i=0;i {\n if(l === t + 1)\n {\n return 0\n }\n if (l==0) {\n t=parseInt(input)\n } else {\n let s = input.split('')\n s.sort()\n if(s[0] !== s[s.length-1]){\n console.log(s.join(\"\"))\n } else {\n console.log(-1)\n }\n }\n l++\n});\n"}], "negative_code": [{"source_code": "\"use strict\";\n\nconst mySet=new Set();\nconst arr=new Array(26).fill(null);\n\nconst input = [];\nconst RL = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\nRL.on(\"line\", line => {\n input.push(line.trim());\n});\nRL.on(\"close\", () => {\n const N=+input[0];\n for(let i=1; i<=N; i+=1){\n const setSize=isImpossible(input[i]);\n if(setSize===1){\n console.log(-1);\n continue;\n }\n\n initArray();\n solve(input[i]);\n }\n});\n\nfunction isImpossible(str){\n mySet.clear();\n for(let char of str){\n mySet.add(char);\n }\n return mySet.size;\n}\n\nfunction initArray(){\n for(let i=0; i<26; i+=1){\n arr[i]=0;\n }\n}\n\nfunction isPalindrome(str){\n const shrinked=arr.map(ele=>{\n return ele%2;\n });\n\n let count=0;\n shrinked.forEach(ele=>{\n if(ele===1){\n count+=1;\n }\n });\n\n if(count>=2){\n return false;\n }\n\n return true;\n}\n\nfunction solve(str){\n for(let char of str){\n arr[char.codePointAt(0)-\"a\".codePointAt(0)]+=1;\n }\n\n const answer=isPalindrome(arr);\n if(answer===false){\n console.log(str);\n }\n\n let good=\"\";\n let oddValue=-1;\n let oddIndex=-1;\n\n arr.forEach((value, index)=>{\n if(value===0){\n return;\n }\n\n if(value%2===1){\n oddValue=value;\n oddIndex=index;\n return;\n }\n\n const left=good.slice(0, good.length/2);\n const right=good.slice(good.length/2, good.length);\n const middle=String.fromCodePoint(index+\"a\".codePointAt(0)).repeat(value);\n\n good=left+middle+right;\n });\n\n if(oddIndex!==-1){\n const left=good.slice(0, good.length/2);\n const right=good.slice(good.length/2, good.length);\n const middle=String.fromCodePoint(oddIndex+\"a\".codePointAt(0)).repeat(oddValue);\n\n good=left+middle+right;\n }\n\n const temp=good.split('');\n [temp[0], temp[parseInt(temp.length/2)]]=[temp[parseInt(temp.length/2)], temp[0]];\n console.log(`${temp.join('')}`);\n}\n"}, {"source_code": "\"use strict\";\n\nconst mySet=new Set();\nconst arr=new Array(26).fill(null);\n\nconst input = [];\nconst RL = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\nRL.on(\"line\", line => {\n input.push(line.trim());\n});\nRL.on(\"close\", () => {\n const N=+input[0];\n for(let i=1; i<=N; i+=1){\n const setSize=isImpossible(input[i]);\n if(setSize===1){\n console.log(-1);\n continue;\n }\n\n initArray();\n solve(input[i]);\n }\n});\n\nfunction isImpossible(str){\n mySet.clear();\n for(let char of str){\n mySet.add(char);\n }\n return mySet.size;\n}\n\nfunction initArray(){\n for(let i=0; i<26; i+=1){\n arr[i]=0;\n }\n}\n\nfunction isPalindrome(str){\n const shrinked=arr.map(ele=>{\n return ele%2;\n });\n\n let count=0;\n shrinked.forEach(ele=>{\n if(ele===1){\n count+=1;\n }\n });\n\n if(count>=2){\n return false;\n }\n\n return true;\n}\n\nfunction solve(str){\n for(let char of str){\n arr[char.codePointAt(0)-\"a\".codePointAt(0)]+=1;\n }\n\n const answer=isPalindrome(arr);\n if(answer===false){\n console.log(str);\n }\n\n let good=\"\";\n let oddValue=-1;\n let oddIndex=-1;\n\n arr.forEach((value, index)=>{\n if(value===0){\n return;\n }\n\n if(value%2===1){\n oddValue=value;\n oddIndex=index;\n return;\n }\n\n const left=good.slice(0, parseInt(good.length/2));\n const right=good.slice(parseInt(good.length/2), good.length);\n const middle=String.fromCodePoint(index+\"a\".codePointAt(0)).repeat(value);\n\n good=left+middle+right;\n });\n\n if(oddIndex!==-1){\n const left=good.slice(0, parseInt(good.length/2));\n const right=good.slice(parseInt(good.length/2), good.length);\n const middle=String.fromCodePoint(oddIndex+\"a\".codePointAt(0)).repeat(oddValue);\n\n good=left+middle+right;\n }\n\n const temp=good.split('');\n [temp[0], temp[parseInt(temp.length/2)]]=[temp[parseInt(temp.length/2)], temp[0]];\n console.log(`${temp.join('')}`);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = [...str];\n arr.sort();\n\n const r = arr.join('');\n\n if (r === str) {\n console.log(-1);\n }\n else {\n console.log(r);\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let l=0;\n let t=0\n rl.on('line', (input) => {\n if(l===t+1)\n {\n return 0\n }\n if (l==0) {\n t=parseInt(input)\n } else {\n rl.close(); \n let s= input.split('')\n s.sort()\n let isPal = true\n for(let i=0;i {\n if(l===t+1)\n {\n return 0\n }\n if (l==0) {\n t=parseInt(input)\n } else {\n rl.close(); \n let s= input.split('')\n s.sort()\n let isPal = true\n for(let i=0;i len) {\n len2 = Math.max(len2, dis(arr[n + 1], arr[j]));\n }\n }\n ans = Math.min(ans, len + len2);\n}\nprint(ans);", "positive_code": [{"source_code": "var arg = readline().split(' ');\nvar N = arg[0];\nvar A = [arg[1], arg[2]];\nvar B = [arg[3], arg[4]];\n\nvar dist = (a, b) =>\n Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2);\nvar d = [], P;\nfor (var i = 0; i < N; ++i) {\n P = readline().split(' ');\n d.push([dist(A, P), dist(B, P)]);\n}\nd.sort((a, b) => {\n if (a[0] < b[0]) {\n return -1;\n } else if (a[0] > b[0]) {\n return 1;\n }\n if (a[1] < b[1]) {\n return -1;\n } else if (a[1] > b[1]) {\n return 1;\n }\n return 0;\n});\n\nvar ra, rb, ans = Infinity;\nfor (var i = -1; i < N; ++i) {\n ra = i > -1 ? d[i][0] : 0;\n rb = 0;\n for (var j = i + 1; j < N; ++j) {\n rb = Math.max(rb, d[j][1]);\n }\n ans = Math.min(ans, ra+rb);\n}\nprint(ans);\n"}, {"source_code": "var data = readline().split(' ').map(Number);\nvar n = data[0],\n x1 = data[1],\n y1 = data[2],\n x2 = data[3],\n y2 = data[4];\nvar distantions = [];\n\nfor (var i = 0; i < n; i++) {\n var flower = readline().split(' ').map(Number);\n distantions[i+1] = [];\n distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);\n distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);\n}\ndistantions[0] = [];\ndistantions[0][0] = 0;\ndistantions[0][1] = 0;\n\nvar result = Number.MAX_VALUE;\nfor (var i = 0; i < n + 1; i++) {\n var r1 = distantions[i][0];\n var r2 = 0;\n for (var j = 0; j < n + 1; j++) {\n if (distantions[j][0] > r1) {\n r2 = Math.max(r2, distantions[j][1]);\n }\n }\n result = Math.min(result, r1 + r2);\n}\n\nprint(result);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [p1, p2];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n}\n\nfor (i = 0; i < points.length; ++i) {\n points[i] = {\n sqrLength1: sqrLength(p1, points[i]),\n sqrLength2: sqrLength(p2, points[i])\n }\n}\n\npoints.sort(function (a, b) {\n return a.sqrLength1 === b.sqrLength1 ? 0 : a.sqrLength1 < b.sqrLength1 ? -1 : 1;\n});\n\nvar result = Infinity;\n\nfor (i = 0; i < points.length; ++i) {\n var subResult = 0;\n\n for (var j = i + 1; j < points.length; ++j) {\n subResult = Math.max(subResult, points[j].sqrLength2);\n }\n\n subResult = points[i].sqrLength1 + subResult;\n \n result = Math.min(result, subResult);\n}\n\nwrite(result);\n"}], "negative_code": [{"source_code": "var Point = function(coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function(p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx*dx + dy*dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [0];\nvar sqrLengths2 = [0];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n sqrLengths1.push(sqrLength(p1, points[i]));\n sqrLengths2.push(sqrLength(p2, points[i]));\n}\n\nvar check = function(sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nfor (var j = 0; j < sqrLengths1.length; ++j) {\n var sqrR1 = sqrLengths1[j];\n\n var a2 = 0;\n var b2 = 100000000;\n\n while (b2 - a2 > 1) {\n var m2 = Math.round((a2 + b2) / 2.0);\n var sqrR2 = m2*m2;\n\n if (check(sqrR1, sqrR2)) {\n b2 = m2;\n } else {\n a2 = m2;\n }\n }\n\n MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));\n}\n\nwrite(MIN);\n"}, {"source_code": "var str = readline().split(\" \", 5);\nvar n = Number(str[0]);\nvar arr = new Array(n + 2);\nfor (var i = 0; i < n; ++i) {\n arr[i] = readline().split(\" \", 2);\n}\narr[n] = [str[1], str[2]];\narr[n + 1] = [str[3], str[4]];\n\nfunction dis(a, b) {\n return (a[0] - b[0]) * (a[0] - b[0]) +\n (a[1] - b[1]) * (a[1] - b[1]);\n}\n\nvar ans = Number.MAX_SAFE_INTEGER;\nfor (var i = 0; i < n + 2; ++i) {\n var len = dis(arr[n], arr[i]);\n var len2 = 0;\n for (var j = 0; j < n + 2; ++j) {\n if (dis(arr[n], arr[j]) > len) {\n len2 = Math.max(dis(len2, arr[n + 1], arr[j]));\n }\n }\n ans = Math.min(ans, len + len2);\n}\nprint(ans);"}, {"source_code": "var str = readline().split(\" \", 5);\nvar n = Number(str[0]);\nvar arr = new Array(n + 2);\nfor (var i = 0; i < n; ++i) {\n arr[i] = readline().split(\" \", 2);\n arr[i][0] = Number(arr[i][0]);\n arr[i][1] = Number(arr[i][1]);\n}\narr[n] = [Number(str[1]), Number(str[2])];\narr[n + 1] = [Number(str[3]), Number(str[4])];\n\nfunction dis(a, b) {\n var aa = a[0] - b[0], bb = a[1] - b[1];\n return aa * bb;\n}\n\nvar ans = Number.MAX_SAFE_INTEGER;\nfor (var i = 0; i < n + 1; ++i) {\n var len = dis(arr[n], arr[i]);\n var len2 = 0;\n for (var j = 0; j < n; ++j) {\n if (dis(arr[n], arr[j]) > len) {\n len2 = Math.max(len2, dis(arr[n + 1], arr[j]));\n }\n }\n ans = Math.min(ans, len + len2);\n}\nprint(ans);"}, {"source_code": "var data = readline().split(' ').map(Number);\nvar n = data[0],\n x1 = data[1],\n y1 = data[2],\n x2 = data[3],\n y2 = data[4];\nvar distantions = [];\n\nfor (var i = 0; i < n; i++) {\n var flower = readline().split(' ').map(Number);\n var dist = [];\n dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);\n dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);\n distantions.push(dist); \n}\n\nvar result = -1;\nfor (var i = 0; i < n; i++) {\n var r1 = distantions[i][0];\n var r2 = 0;\n for (var j = 0; j < n; j++) {\n if (i != j) {\n r2 = Math.max(distantions[j][1], r2);\n }\n }\n if (result == -1) {\n result = r1 + r2;\n } else {\n result = Math.min(r1 + r2, result);\n }\n}\n\nprint(result);"}, {"source_code": "var data = readline().split(' ').map(Number);\nvar n = data[0],\n x1 = data[1],\n y1 = data[2],\n x2 = data[3],\n y2 = data[4];\nvar distantions = [];\n\nfor (var i = 0; i < n; i++) {\n var flower = readline().split(' ').map(Number);\n var dist = [];\n dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);\n dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);\n distantions.push(dist); \n}\n\nvar result = -1;\nfor (var i = 0; i < n; i++) {\n var r1 = distantions[i][0];\n var r2 = 0;\n for (var j = 0; j < n; j++) {\n if (distantions[j][0] > r1) {\n r2 = Math.max(distantions[j][1], r2);\n }\n }\n if (result == -1) {\n result = r1 + r2;\n } else {\n result = Math.min(r1 + r2, result);\n }\n}\n\nprint(result);"}, {"source_code": "var data = readline().split(' ').map(Number);\nvar n = data[0],\n x1 = data[1],\n y1 = data[2],\n x2 = data[3],\n y2 = data[4];\nvar distantions = [];\n\nfor (var i = 0; i < n; i++) {\n var flower = readline().split(' ').map(Number);\n distantions[i+1] = [];\n distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);\n distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);\n}\ndistantions[0] = [];\ndistantions[0][0] = 0;\ndistantions[0][1] = 0;\n\nprint(distantions);\n\nvar result = Number.MAX_VALUE;\nfor (var i = 0; i < n + 1; i++) {\n var r1 = distantions[i][0];\n var r2 = 0;\n for (var j = 0; j < n + 1; j++) {\n if (distantions[j][0] > r1) {\n r2 = Math.max(r2, distantions[j][1]);\n }\n }\n result = Math.min(result, r1 + r2);\n}\n\nprint(result);"}, {"source_code": "\nvar arg = readline().split(' ');\nvar N = arg[0];\nvar A = [arg[1], arg[2]];\nvar B = [arg[3], arg[4]];\n\nvar dist = (a, b) =>\n Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2);\nvar d = [], P;\nfor (var i = 0; i < N; ++i) {\n P = readline().split(' ');\n d.push([dist(A, P), dist(B, P)]);\n}\nd.sort((a, b) => (a[0] > b[0]));\n\nvar ra, rb, ans = Infinity;\nfor (var i = -1; i < N; ++i) {\n ra = i > -1 ? d[i][0] : 0;\n rb = 0;\n for (var j = i + 1; j < N; ++j) {\n rb = Math.max(rb, d[j][1]);\n }\n ans = Math.min(ans, ra+rb);\n}\nprint(ans);\n"}, {"source_code": "var Point = function(coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function(p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx*dx + dy*dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n sqrLengths1.push(sqrLength(p1, points[i]));\n sqrLengths2.push(sqrLength(p2, points[i]));\n}\n\nvar check = function(sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nfor (var j = 0; j < n; ++j) {\n var sqrR1 = sqrLengths1[j];\n\n var a2 = 0;\n var b2 = 1000000;\n\n while (b2 - a2 > 0.001) {\n var m2 = (a2 + b2) / 2.0;\n var sqrR2 = m2*m2;\n\n if (check(sqrR1, sqrR2)) {\n b2 = m2;\n } else {\n a2 = m2;\n }\n }\n\n MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nvar MAX_SQR_LENGTH1 = -Infinity;\nvar MAX_SQR_LENGTH2 = -Infinity;\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n var sqrLength1 = sqrLength(p1, points[i]);\n var sqrLength2 = sqrLength(p2, points[i]);\n\n sqrLengths1.push(sqrLength1);\n sqrLengths2.push(sqrLength2);\n\n MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);\n MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);\n}\n\nvar check = function (sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nvar a1 = 0;\nvar b1 = MAX_SQR_LENGTH1*2;\ndebugger;\nwhile (b1 - a1 > 0) {\n var sqrR1 = (a1 + b1) >> 1;\n\n var a2 = 0;\n var b2 = MAX_SQR_LENGTH2*2;\n\n while (b2 - a2 > 1) {\n var sqrR2 = (a2 + b2) >> 1;\n\n if (check(sqrR1, sqrR2)) {\n b2 = sqrR2;\n } else {\n a2 = sqrR2;\n }\n }\n\n if (check(sqrR1, b2)) {\n MIN = Math.min(MIN, sqrR1 + b2);\n b1 = sqrR1;\n } else {\n a1 = sqrR1;\n }\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function(coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar length = function(p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n \n return dx*dx + dy*dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar lengths1 = [];\nvar lengths2 = [];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n lengths1.push(length(p1, points[i]));\n lengths2.push(length(p2, points[i]));\n}\n\nvar check = function(r1, r2) {\n //r1 *= r1;\n r2 *= r2;\n\n for (var i = 0; i < n; ++i) {\n if (lengths1[i] > r1 && lengths2[i] > r2) {\n return false;\n }\n }\n \n return true;\n};\n\nvar MIN = Infinity;\n\nfor (var j = 0; j < n; ++j) {\n var r1 = lengths1[j];\n\n var a2 = 0;\n var b2 = 100000000;\n \n while (b2 - a2 > 0.001) {\n var r2 = (a2 + b2) / 2.0;\n \n if (check(r1, r2)) {\n b2 = r2;\n } else {\n a2 = r2;\n }\n }\n \n MIN = Math.min(MIN, Math.round(r1 + a2*a2));\n}\n\nwrite(MIN);\n"}, {"source_code": "var Point = function(coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function(p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx*dx + dy*dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n sqrLengths1.push(sqrLength(p1, points[i]));\n sqrLengths2.push(sqrLength(p2, points[i]));\n}\n\nvar check = function(sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nfor (var j = 0; j < n; ++j) {\n var sqrR1 = sqrLengths1[j];\n\n var a2 = 0;\n var b2 = 100000000;\n\n while (b2 - a2 > 0.001) {\n var m2 = (a2 + b2) / 2.0;\n var sqrR2 = m2*m2;\n\n if (check(sqrR1, sqrR2)) {\n b2 = m2;\n } else {\n a2 = m2;\n }\n }\n\n MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = '1 0 0 10 10'.split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nvar MAX_SQR_LENGTH1 = -Infinity;\nvar MAX_SQR_LENGTH2 = -Infinity;\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point('0 1'.split(' ')));\n\n var sqrLength1 = sqrLength(p1, points[i]);\n var sqrLength2 = sqrLength(p2, points[i]);\n\n sqrLengths1.push(sqrLength1);\n sqrLengths2.push(sqrLength2);\n\n MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);\n MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);\n}\n\nvar check = function (sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nvar a1 = 0;\nvar b1 = MAX_SQR_LENGTH1*2;\ndebugger;\nwhile (b1 - a1 > 0) {\n var sqrR1 = (a1 + b1) >> 1;\n\n var a2 = 0;\n var b2 = MAX_SQR_LENGTH2*2;\n\n while (b2 - a2 > 1) {\n var sqrR2 = (a2 + b2) >> 1;\n\n if (check(sqrR1, sqrR2)) {\n b2 = sqrR2;\n } else {\n a2 = sqrR2;\n }\n }\n \n if (check(sqrR1, b2)) {\n MIN = Math.min(MIN, sqrR1 + b2);\n b1 = sqrR1;\n } else {\n a1 = sqrR1;\n }\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nvar MAX_SQR_LENGTH1 = -Infinity;\nvar MAX_SQR_LENGTH2 = -Infinity;\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n var sqrLength1 = sqrLength(p1, points[i]);\n var sqrLength2 = sqrLength(p2, points[i]);\n\n sqrLengths1.push(sqrLength1);\n sqrLengths2.push(sqrLength2);\n\n MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);\n MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);\n}\n\nvar check = function (sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nvar a1 = 0;\nvar b1 = MAX_SQR_LENGTH1;\n\nwhile (b1 - a1 > 1) {\n var sqrR1 = (a1 + b1) >> 1;\n\n var a2 = 0;\n var b2 = MAX_SQR_LENGTH2;\n\n while (b2 - a2 > 1) {\n var sqrR2 = (a2 + b2) >> 1;\n\n if (check(sqrR1, sqrR2)) {\n b2 = sqrR2;\n } else {\n a2 = sqrR2;\n }\n }\n \n if (check(sqrR1, b2)) {\n MIN = Math.min(MIN, sqrR1 + b2);\n b1 = sqrR1;\n } else {\n a1 = sqrR1;\n }\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [];\nvar sqrLengths1 = [];\nvar sqrLengths2 = [];\n\nvar MAX_SQR_LENGTH1 = -Infinity;\nvar MAX_SQR_LENGTH2 = -Infinity;\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n\n var sqrLength1 = sqrLength(p1, points[i]);\n var sqrLength2 = sqrLength(p2, points[i]);\n\n sqrLengths1.push(sqrLength1);\n sqrLengths2.push(sqrLength2);\n\n MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);\n MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);\n}\n\nvar check = function (sqrR1, sqrR2) {\n for (var i = 0; i < n; ++i) {\n if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {\n return false;\n }\n }\n\n return true;\n};\n\nvar MIN = Infinity;\n\nvar a1 = 0;\nvar b1 = MAX_SQR_LENGTH1;\n\nwhile (b1 - a1 > 0) {\n var sqrR1 = (a1 + b1) >> 1;\n\n var a2 = 0;\n var b2 = MAX_SQR_LENGTH2;\n\n while (b2 - a2 > 1) {\n var sqrR2 = (a2 + b2) >> 1;\n\n if (check(sqrR1, sqrR2)) {\n b2 = sqrR2;\n } else {\n a2 = sqrR2;\n }\n }\n \n if (check(sqrR1, b2)) {\n MIN = Math.min(MIN, sqrR1 + b2);\n b1 = sqrR1;\n } else {\n a1 = sqrR1;\n }\n}\n\nwrite(MIN);"}, {"source_code": "var Point = function (coors) {\n this.x = +coors[0];\n this.y = +coors[1];\n};\n\nvar sqrLength = function (p1, p2) {\n var dx = p2.x - p1.x;\n var dy = p2.y - p1.y;\n\n return dx * dx + dy * dy;\n};\n\nvar input = readline().split(' ');\n\nvar n = input[0];\n\nvar p1 = new Point(input.slice(1, 3));\nvar p2 = new Point(input.slice(3, 5));\n\nvar points = [p1, p2];\n\nfor (var i = 0; i < n; ++i) {\n points.push(new Point(readline().split(' ')));\n}\n\nfor (i = 0; i < points.length; ++i) {\n points[i] = {\n sqrLength1: sqrLength(p1, points[i]),\n sqrLength2: sqrLength(p2, points[i])\n }\n}\n\npoints.sort(function (a, b) {\n return a.sqrLength1 === b.sqrLength1 ? 0 : a.sqrLength1 < b.sqrLength1 ? -1 : 1;\n});\n\nvar result = Infinity;\n\nfor (i = 0; i < points.length - 1; ++i) {\n var subResult = -Infinity;\n\n for (var j = i + 1; j < points.length; ++j) {\n subResult = Math.max(subResult, points[j].sqrLength2);\n }\n\n subResult = points[i].sqrLength1 + subResult;\n \n result = Math.min(result, subResult);\n}\n\nwrite(result);\n"}], "src_uid": "5db9c5673a04256c52f180dbfca2a52f"} {"source_code": "let examples = [90];\r\n\r\nvar fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nexamples = [];\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\n\r\nconst solver = (n) => {\r\n const x = Math.floor( (n - 3) / 4);\r\n \r\n \r\n // console.log({x, left})\r\n if (x < 1) {\r\n return 'defghijklm'.substring(0, n);\r\n }\r\n const left = n - (x*4 + 3);\r\n return 'a'.repeat(x) + 'b'.repeat(x) + 'a'.repeat(x+1) + 'c' + 'b'.repeat(x+1) + 'defghijklm'.substring(0, left);\r\n};\r\n\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn();\r\n if (n < 26) {\r\n let s = '';\r\n for (let i = 0; i < n; i++) {\r\n s += String.fromCharCode(97 + i);\r\n }\r\n return s;\r\n }\r\n const a = Math.floor(n / 2),\r\n b = a - 1;\r\n const c = n - a - b;\r\n let s = 'a'.repeat(a);\r\n for (let i = 0; i < c; i++) {\r\n s += String.fromCharCode(97 + i + 1);\r\n }\r\n s += 'a'.repeat(b);\r\n return s;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "let examples = [90];\r\n\r\nvar fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nexamples = [];\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\n\r\nconst solver = (n) => {\r\n const x = Math.floor(n/7);\r\n const left = n - x*7;\r\n if (x < 1) {\r\n return 'defghijklm'.substring(0, left);\r\n }\r\n return 'a'.repeat(x) + 'b'.repeat(x) + 'a'.repeat(x+1) + 'c' + 'b'.repeat(x+1) + 'defghijklm'.substring(0, left);\r\n};\r\n\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\nconst allLeters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"]\r\n\r\nconst solver = (n) => {\r\n \r\n let currentResult = '';\r\n let rstr = '';\r\n const letters = allLeters.slice(0)\r\n while(currentResult.length < n) {\r\n \r\n const [a,b] = [letters.shift(), letters.shift()];\r\n \r\n const left = n - currentResult.length;\r\n //console.log({n, currentResult, rstr, left})\r\n if (left <= 6) {\r\n const c = letters.shift()\r\n if (left === 0) currentResult += '';\r\n if (left === 1) currentResult += a\r\n if (left === 2) currentResult += a+b\r\n if (left === 3) currentResult += a+b+c\r\n if (left === 4) currentResult += a+b+a+a\r\n if (left === 5) currentResult += a+b+a+a+c\r\n if (left === 6) currentResult += a+b+a+a+b+b\r\n break;\r\n }\r\n \r\n if (rstr) {\r\n if (rstr.length * 2 + 2 <= left) {\r\n currentResult += a + rstr + b + rstr;\r\n rstr = rstr + a + rstr + b + rstr;\r\n } else {\r\n rstr = ''\r\n }\r\n } else {\r\n rstr = a+b+a+a+b+b;\r\n currentResult += rstr;\r\n // if (rstr * 2 + 2 <= left) {\r\n // const [c,d] = [letters.shift(), letters.shift()];\r\n // }\r\n \r\n \r\n }\r\n }\r\n return currentResult;\r\n \r\n};\r\n\r\n\r\n// const solver = (n, letters = allLeters.slice(0), rstr = '') => {\r\n// console.log(n, letters.length, rstr.length)\r\n// const [a,b] = [letters.shift(), letters.shift()]\r\n// if (n <= 6) {\r\n// const c = letters.shift()\r\n// if (n === 0) return rstr;\r\n// if (n === 1) return rstr + a\r\n// if (n === 2) return rstr + a+b\r\n// if (n === 3) return rstr + a+b+c\r\n// if (n === 4) return rstr + a+b+a+a\r\n// if (n === 5) return rstr + a+b+a+a+c\r\n// if (n === 6) return rstr + a+b+a+a+b+b\r\n// }\r\n// if (!rstr) {\r\n// // const [a,b] = [letters.shift(), letters.shift()]\r\n// return solver(n, letters, a+b+a+a+b+b)\r\n// }\r\n \r\n// const newLength = n - rstr.length * 3 - 2;\r\n// if (newLength <= 0) {\r\n// return rstr + solver(n - rstr.length, letters.slice(0))\r\n// }\r\n// return rstr + solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)\r\n// };\r\n\r\n// console.log(examples)\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\nconst allLeters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"]\r\n\r\nconst solver = (n, letters = allLeters.slice(0), rstr = '') => {\r\n // console.log(n, letters.length, rstr.length)\r\n const [a,b] = [letters.shift(), letters.shift()]\r\n if (n <= 6) {\r\n const c = letters.shift()\r\n if (n === 1) return a\r\n if (n === 2) return a+b\r\n if (n === 3) return a+b+c\r\n if (n === 4) return a+b+a+a\r\n if (n === 5) return a+b+a+a+c\r\n if (n === 6) return a+b+a+a+b+b\r\n }\r\n if (!rstr) {\r\n // const [a,b] = [letters.shift(), letters.shift()]\r\n return solver(n, letters, a+b+a+a+b+b)\r\n }\r\n \r\n const newLength = n - rstr.length * 3 - 2;\r\n if (newLength < 0) {\r\n return rstr + solver(n - rstr.length, letters.slice(0))\r\n }\r\n return solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)\r\n};\r\n\r\n// console.log(examples)\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\n\r\nfor(let i = 0; i < lines.length; i++) {\r\n examples.push(parseInt(lines[i], 10));\r\n}\r\n\r\nconst allLeters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"]\r\n\r\nconst solver = (n, letters = allLeters.slice(0), rstr = '') => {\r\n console.log(n, letters.length, rstr.length)\r\n const [a,b] = [letters.shift(), letters.shift()]\r\n if (n <= 6) {\r\n const c = letters.shift()\r\n if (n === 1) return a\r\n if (n === 2) return a+b\r\n if (n === 3) return a+b+c\r\n if (n === 4) return a+b+a+a\r\n if (n === 5) return a+b+a+a+c\r\n if (n === 6) return a+b+a+a+b+b\r\n }\r\n if (!rstr) {\r\n // const [a,b] = [letters.shift(), letters.shift()]\r\n return solver(n, letters, a+b+a+a+b+b)\r\n }\r\n \r\n const newLength = n - rstr.length * 3 - 2;\r\n if (newLength < 0) {\r\n return rstr + solver(n - rstr.length, letters.slice(0))\r\n }\r\n return solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)\r\n};\r\n\r\nconsole.log(examples)\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}], "src_uid": "21e361d7f907f2543a616c901e60c6f2"} {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var min = 1000;\n var n = readline();\n var x = readNumArray().sort((a, b) => a - b);\n for (var j = 1; j < x.length; j++) {\n if (x[j] - x[j - 1] < min) {\n min = x[j] - x[j - 1];\n }\n }\n print(min);\n }\n}\n\nmain();", "positive_code": [{"source_code": "\"use strict\";\n\n\nfunction retMin (x1 , x2){\n\n\tif(x1 >x2) return x2;\n\telse return x1;\n\n}\n\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\n\tvar n =parseInt(readline());\n\tvar arr =readline().split(\" \");\n\n\tvar ans =1234567899879798;\n\n\tfor(var i =0 ; i (a - b));\n var minDiff = 1e6;\n for(var k = 1; k < n; k++){\n minDiff = Math.min(minDiff, arr[k] - arr[k - 1]);\n }\n print(minDiff);\n}"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tlist.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tvar min = 100000000;\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tmin = Math.min(min, Math.abs(list[j] - list[j + 1]));\n\t\t}\n\t\toutput[i] = min;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort((a, b) => {\n return a - b;\n });\n\n let minDiff = 10000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n console.log(minDiff);\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var athelet = readline()\n .split(\" \")\n .map((val) => parseInt(val))\n .sort((a, b) => a - b);\n var differs = [];\n for (var i = 1; i < athelet.length; i++) {\n differs.push(Math.abs(athelet[i] - athelet[i - 1]));\n }\n differs = differs.sort((a, b) => a - b);\n print(differs[0]);\n}\n"}, {"source_code": "function solve() {\n var n = readInt();\n var arr = readIntArray().sort((a, b) => a - b)\n var i;\n var minDiff = Number.MAX_VALUE\n for(i=1; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = Infinity;\n\n for (let i = 0; i < arr.length - 1; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n if (Math.abs(arr[i] - arr[j]) < ans) {\n ans = Math.abs(arr[i] - arr[j]);\n }\n }\n }\n // arr.sort();\n // let ans = Infinity;\n\n // for (let i = 1; i < arr.length; i++) {\n // ans = Math.min(ans, Math.abs(arr[i - 1] - arr[i]));\n // }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = Infinity;\n arr.sort((a, b) => a - b);\n\n for (let i = 1; i < arr.length; i++) {\n ans = Math.min(ans, arr[i] - arr[i - 1]);\n }\n\n // for (let i = 0; i < arr.length - 1; i++) {\n // for (let j = i + 1; j < arr.length; j++) {\n // if (Math.abs(arr[i] - arr[j]) < ans) {\n // ans = Math.abs(arr[i] - arr[j]);\n // }\n // }\n // }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = Infinity;\n\n for (let i = 0; i < arr.length - 1; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n if (Math.abs(arr[i] - arr[j]) < ans) {\n ans = Math.abs(arr[i] - arr[j]);\n }\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const cases = data.shift() * 2;\n for (let i = 0; i < cases; i += 2) {\n const n = data[i] - 1;\n const s = data[i + 1].split(' ');\n s.sort((a, b) => +a - +b);\n let min = s[1] - s[0];\n for (let j = n; j > 1; j -= 1) {\n min = Math.min(s[j] - s[j - 1], min);\n }\n console.log(min);\n }\n}"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n arr.sort((a, b) => a-b)\n let prev = arr[0]\n let min = Number.MAX_SAFE_INTEGER\n for (let i=1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r x - y);\n let min = Infinity;\n\n for(let i=1;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n readline();\n let force = readline().split(\" \").map(e => parseInt(e));\n const {pow, max, min} = Math;\n\n force.sort((a,b) => a - b);\n\n let res = Infinity;\n\n for (var i = 0; i < force.length - 1; i++) {\n res = Math.min(res, Math.abs(force[i] - force[i+1]))\n }\n\n console.log(res)\n\n\n //break;\n //console.log(Math.pow(Math.max(a,b) + Math.max(a,b) , 2))\n }\n\n\n}\n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort();\n\n let minDiff = 10000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n console.log(minDiff);\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort();\n\n let minDiff = 10000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n if (startStr === nextStr) continue;\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n if (minDiff === 10000) {\n console.log(0);\n } else {\n console.log(minDiff);\n }\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort();\n\n let minDiff = 1000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n console.log(minDiff);\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort((a, b) => {\n return a < b;\n });\n\n let minDiff = 10000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n console.log(minDiff);\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t * 2; x += 2) {\n const strList = input[x + 1].split(\" \").map((str) => Number(str));\n\n strList.sort();\n\n let minDiff = 10000;\n\n for (let i = 0; i < strList.length - 1; i++) {\n const startStr = strList[i];\n const nextStr = strList[i + 1];\n\n const diff = nextStr - startStr;\n\n minDiff = Math.min(minDiff, diff);\n }\n\n console.log(minDiff);\n }\n}\n\n/*\n Q. Print the minimum value |max(A)\u2212min(B)|.\n \n 1. \ub0b4 \uc55e\uc5d0 n\uba85\uc758 \uc120\uc218 (1~n\ubc88)\n 2. \uac01\uc790 \ud798 \uc22b\uc790 (si)\n 3. \ubaa8\ub4e0 \uc120\uc218\ub97c 2\uac1c\uc758 \ud300\uc73c\ub85c \ubd84\ud560 (\ucd5c\uc18c 1\uba85\uc758 \uc120\uc218)(1\uba85\uc740 1\ud300\ub9cc)\n 4. \uccab\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uac15\ud55c \uc120\uc218\uc640, \ub450\ubc88\uc9f8 \ud300\uc758 \uac00\uc7a5 \uc57d\ud55c \uc120\uc218\uc758, \ud798 \ucc28\uc774\ub97c \ucd5c\uc18c\ub85c \ud558\uace0 \uc2f6\uc74c.\n*/\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n // let ans = Infinity;\n\n // for (let i = 0; i < arr.length - 1; i++) {\n // for (let j = i + 1; j < arr.length; j++) {\n // if (Math.abs(arr[i] - arr[j]) < ans) {\n // ans = Math.abs(arr[i] - arr[j]);\n // }\n // }\n // }\n\n arr.sort();\n let ans = Infinity;\n\n for (let i = 1; i < arr.length; i++) {\n if (Math.abs(arr[i - 1] - arr[i]) < ans) {\n ans = Math.abs(arr[i - 1] - arr[i]);\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort();\n let ans = Infinity;\n\n for (let i = 1; i < arr.length; i++) {\n ans = Math.min(ans, Math.abs(arr[i - 1] - arr[i]));\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const cases = data.shift() * 2;\nmain:\n for (let i = 0; i < cases; i += 2) {\n const n = data[i] * 1;\n const s = data[i + 1].split(' ');\n s.sort((a, b) => +a - +b);\n let arr = {};\n let ifP = true;\n for (let j = 0; j < n; j += 1) {\n if (arr[s[j]]) {\n console.log(0);\n continue main;\n } else arr[s[j]] = true;\n }\n console.log(s[1] - s[0]);\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r e !==x1);\n\n let x2 = Math.min(...a);\n\n console.log(x2 - x1);\n \n }\n}"}, {"source_code": "var testCase = parseInt(readline());\n\nwhile(testCase--){\n var n = parseInt(readline())\n var arr = readline().split(\" \").map((val) => parseInt(val))\n arr.sort();\n var minDiff = 1e6;\n for(var k = 1; k < n; k++){\n minDiff = Math.min(minDiff, arr[k] - arr[k - 1]);\n }\n print(minDiff);\n}"}, {"source_code": "var testCase = parseInt(readline());\n\nwhile(testCase--){\n var n = parseInt(readline());\n var arr = readline().split(\" \").map(Number).sort();\n var minDiff = 1e6;\n for(var k = 1; k < n; k++){\n minDiff = Math.min(minDiff, arr[k] - arr[k - 1]);\n }\n print(minDiff);\n}"}, {"source_code": "function solve() {\n var n = readInt();\n var arr = readIntArray().sort()\n var i;\n var minDiff = Number.MAX_VALUE\n for(i=1; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet rmn = cmn = 0, rmx = cmx = 0;\r\n\t\tlet r = c = 0; \r\n\t\tfor (const dir of s) {\r\n\t\t\tif (dir == 'L') c--;\r\n\t\t\tif (dir == 'R') c++;\r\n\t\t\tif (dir == 'U') r--;\r\n\t\t\tif (dir == 'D') r++;\r\n\r\n\t\t\trmn = Math.min(rmn, r);\r\n\t\t\trmx = Math.max(rmx, r);\r\n\t\t\tcmn = Math.min(cmn, c);\r\n\t\t\tcmx = Math.max(cmx, c);\r\n\r\n\t\t\tif (rmx - rmn == n || cmx - cmn == m) {\r\n\t\t\t\tif (dir == 'L') cmn++;\r\n\t\t\t\tif (dir == 'U') rmn++;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = [-rmn + 1, -cmn + 1];\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet ans;\r\n\t\tlet rmn = cmn = 0, rmx = cmx = 0; //start point (1, 1)\r\n\t\tfor (let i = 0, r = c = 0; i < s.length; i++) {\r\n\t\t\tif (s[i] == 'L') c--;\r\n\t\t\tif (s[i] == 'R') c++;\r\n\t\t\tif (s[i] == 'U') r--;\r\n\t\t\tif (s[i] == 'D') r++;\r\n\r\n\t\t\trmn = Math.min(rmn, r);\r\n\t\t\trmx = Math.max(rmx, r);\r\n\t\t\tcmn = Math.min(cmn, c);\r\n\t\t\tcmx = Math.max(cmx, c);\r\n\r\n\t\t\tif (rmx - rmn == n || cmx - cmn == m) {\r\n\t\t\t\tif (s[i] == 'L') cmn++;\r\n\t\t\t\tif (s[i] == 'U') rmn++;\r\n\t\t\t\tans = [-rmn + 1, -cmn + 1];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans = ans || [-rmn + 1, -cmn + 1];\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "585bb4a040144da39ed240366193e705"} {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n // for(let i = 1; i <= n; i++) {\n let arr = lines[1].trim().split(' ').map(x => +x)\n console.log(solution(arr))\n // }\n}\n\nfunction solution(arr) {\n let counts = Array(22).fill(0)\n for (let num of arr) {\n for (let i = 0; i < 22; i++) {\n let bit = 1 << i\n if (num & bit) counts[i]++\n }\n }\n let ans = 0n\n while (true) {\n let num = 0\n for (let i = 0; i < 22; i++) {\n let bit = 1 << i\n if (counts[i] > 0) {\n counts[i]--\n num |= bit\n }\n }\n if (num === 0) break\n ans += BigInt(num * num)\n }\n return ans.toString()\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n const n = parseInt(lines.shift(), 10);\n const arr = lineToNumArray(lines.shift());\n const bitCount = Array(20).fill(0);\n arr.forEach(element => {\n for (let i = 0; i < 20; i++) {\n if (element & (1 << i)) {\n bitCount[i]++;\n }\n }\n });\n let ans = 0n;\n for (let i = 0; i < n; i++) {\n let element = 0;\n for (let j = 0; j < 20; j++) {\n if (bitCount[j]) {\n element += (1 << j);\n bitCount[j]--;\n }\n }\n ans += BigInt(element ** 2);\n }\n console.log(ans.toString());\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(element => parseInt(element, 10));\n}\n"}], "negative_code": [{"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n // for(let i = 1; i <= n; i++) {\n let arr = lines[1].trim().split(' ').map(x => +x)\n console.log(solution(arr))\n // }\n}\n\nfunction solution(arr) {\n let counts = Array(22).fill(0)\n for (let num of arr) {\n for (let i = 0; i < 22; i++) {\n let bit = 1 << i\n if (num & bit) counts[i]++\n }\n }\n let ans = 0\n while (true) {\n let num = 0\n for (let i = 0; i < 22; i++) {\n let bit = 1 << i\n if (counts[i] > 0) {\n counts[i]--\n num |= bit\n }\n }\n if (num === 0) break\n ans += num * num\n }\n return ans\n}"}], "src_uid": "56fbdca75b69bf41d2a45a1dfe81d022"} {"source_code": "var DLstr=+readline();\nvar str=readline();\nvar n=+readline();\nvar mas=[];\nfor(i=0;i0)\n break;\n else{\n m[k1][k2]=m[k1][k2]*-1;\n }\n }\n }\n return m;\n}\n\n", "positive_code": [{"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar n = +readline();\nvar s = readline();\nvar m = +readline();\n\nvar M = {};\nfor (var i = 1 ; i <= n; ++i) {\n var char = s[i-1];\n if (!M[char]) {\n M[char] = [null];\n }\n M[char].push(i);\n}\n\nwhile(m--) {\n var t = readline();\n \n var C = {};\n for (var i = 0; i < t.length; ++i) {\n var char = t[i];\n if (!C[char]) {\n C[char] = 0;\n }\n ++C[char];\n }\n \n var result = -Infinity;\n for (var char in C) {\n if (C.hasOwnProperty(char)) {\n result = Math.max(result, M[char][C[char]]);\n }\n }\n\n write(result, '\\n');\n}"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var s = readline();\n var m = read.number();\n var res = [];\n\n var market = {};\n for(var i = 0; i < n; i++){\n if(market[s[i]]) {\n market[s[i]].push(i);\n }\n else {\n market[s[i]] = [i];\n }\n }\n\n for (var i = 0; i < m; i++) {\n var name = readline();\n var r = {};\n var max = -1;\n for(var j = 0, length = name.length; j < length; j++) {\n var bukva = name[j];\n if(r[bukva] !== undefined) {\n r[bukva]++;\n }\n else {\n r[bukva] = 0;\n }\n if(market[bukva][r[bukva]] > max) {\n max = market[bukva][r[bukva]];\n }\n }\n res += (max + 1) + '\\n';\n }\n\n print(res);\n}());"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var s = readline();\n var m = read.number();\n var res = [];\n \n var market = {};\n for(var i = 0; i < n; i++){\n if(market[s[i]]) {\n market[s[i]].push(i);\n }\n else {\n market[s[i]] = [i];\n }\n }\n \n for (var i = 0; i < m; i++) {\n var name = readline();\n var r = {};\n var max = -1;\n for(var j = 0, length = name.length; j < length; j++) {\n if(r[name[j]]) {\n r++;\n }\n else {\n r = 0;\n }\n if(market[name[j]][r] > max) {\n max = market[name[j]][r];\n }\n }\n res += (max + 1) + '\\n';\n }\n \n print(res);\n}());"}, {"source_code": "var DLstr=+readline();\nvar str=readline();\nvar n=+readline();\nvar mas=[];\nfor(i=0;i0)\n break;\n else{\n m[k1][k2]=m[k1][k2]*-1;\n }\n }\n }\n return m;\n}\n\n"}], "src_uid": "8736df815ea0fdf390cc8d500758bf84"} {"source_code": "var app = {\n count : 0,\n pwd : '',\n array : [],\n result : [],\n main : function() {\n this.initialize();\n this.readValues();\n this.sovleResult();\n this.printResult();\n },\n initialize : function() {},\n readValues : function() {\n this.count = parseInt(readline());\n this.pwd = readline();\n },\n sovleResult : function() {\n for(var number = 0; number <= 9; number++) {\n var adjustedPwd = { 'pwd' : '', 'minPos' : [] },\n minNumber;\n for(var pwdIndex = 0; pwdIndex < this.count; pwdIndex++) {\n var adjustedNumber = parseInt(this.pwd[pwdIndex]) - number;\n adjustedNumber < 0 ? adjustedNumber = adjustedNumber + 10 : false;\n \n if(minNumber == undefined) {\n minNumber = adjustedNumber;\n adjustedPwd.minPos.push(this.count - pwdIndex);\n } else if(minNumber == adjustedNumber) {\n adjustedPwd.minPos.push(this.count - pwdIndex);\n } else if(minNumber > adjustedNumber) {\n adjustedPwd.minPos = [];\n adjustedPwd.minPos.push(this.count - pwdIndex);\n minNumber = adjustedNumber;\n }\n \n adjustedPwd.pwd += adjustedNumber;\n }\n \n adjustedPwd.minPos.forEach(function(pos) {\n var lastValue = app.result[app.result.length - 1];\n if(lastValue) {\n var shiftedPwd = app.stringShift(adjustedPwd.pwd, pos);\n shiftedPwd < lastValue ? app.result.push(shiftedPwd) : false;\n } else {\n app.result.push(app.stringShift(adjustedPwd.pwd, pos));\n }\n });\n }\n },\n printResult : function() {\n print(this.result[this.result.length - 1]);\n },\n stringShift : function(str, shiftLength) {\n var frontStr = str.substring(str.length - shiftLength),\n backStr = str.substring(0, str.length - shiftLength);\n \n return frontStr + backStr;\n }\n};\n\napp.main();\n", "positive_code": [{"source_code": "var n = parseInt(readline(), 10);\nvar a = readline().split('');\nvar cur = 0;\nfor (var i = 1; i < n; i++) {\n\tvar deltaCur = a[cur] - 0;\n\tvar deltaI = a[i] - 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tvar nextCur = cur + j;\n\t\tvar nextI = i + j;\n\t\tif (nextCur >= n) {\n\t\t\tnextCur -= n;\n\t\t}\n\t\tif (nextI >= n) {\n\t\t\tnextI -= n;\n\t\t}\n\t\tvar nextCurValue = a[nextCur] - deltaCur;\n\t\tif (nextCurValue < 0) {\n\t\t\tnextCurValue += 10;\n\t\t}\n\t\tvar nextIValue = a[nextI] - deltaI;\n\t\tif (nextIValue < 0) {\n\t\t\tnextIValue += 10;\n\t\t}\n\t\tif (nextCurValue === nextIValue) {\n\t\t\tcontinue\n\t\t} \n\t\tcur = nextCurValue < nextIValue ? cur : i;\n\t\tbreak;\n\t}\n}\nvar deltaCur = a[cur] - 0;\nvar ans = '';\nfor (var i = 0; i < n; i++) {\n\tvar v = a[(cur + i) % n] - deltaCur;\n\tif (v < 0) {\n\t\tv += 10;\n\t}\n\tans += v;\n}\n//print(deltaCur, cur);\nprint(ans);"}, {"source_code": "var n = +readline();\nvar str = readline();\nstr = str+str;\n\nvar ans = null;\n\nfor(var i = 0; i < n; i++) {\n var vals = str.substr(i,n).split(\"\").map(function(v) {return +v;});\n for(var j = 0; j < 10; j++) {\n for(var k = 0; k < n; k++)\n vals[k] = (vals[k]+1)%10;\n var v = vals.join(\"\");\n ans = !ans?v:ans>v?v:ans;\n }\n}\n\nprint(ans);\n"}], "negative_code": [{"source_code": "var n = parseInt(readline(), 10);\nvar a = readline().split('');\nvar cur = 0;\nfor (var i = 1; i < n; i++) {\n\tvar deltaCur = a[cur] - 0;\n\tvar deltaI = a[i] - 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tvar nextCur = cur + j;\n\t\tvar nextI = i + j;\n\t\tif (nextCur >= n) {\n\t\t\tnextCur = 0;\n\t\t}\n\t\tif (nextI >= n) {\n\t\t\tnextI = 0;\n\t\t}\n\t\tvar nextCurValue = a[nextCur] - deltaCur;\n\t\tif (nextCurValue < 0) {\n\t\t\tnextCurValue += 10;\n\t\t}\n\t\tvar nextIValue = a[nextI] - deltaI;\n\t\tif (nextIValue < 0) {\n\t\t\tnextIValue += 10;\n\t\t}\n\t\tif (nextCurValue === nextIValue) {\n\t\t\tcontinue\n\t\t} \n\t\tcur = nextCurValue < nextIValue ? cur : i;\n\t\tbreak;\n\t}\n}\nvar deltaCur = a[cur] - 0;\nvar ans = '';\nfor (var i = 0; i < n; i++) {\n\tvar v = a[(cur + i) % n] - deltaCur;\n\tif (v < 0) {\n\t\tv += 10;\n\t}\n\tans += v;\n}\n//print(deltaCur, cur);\nprint(ans);"}, {"source_code": "var n = +readline();\nvar str = readline();\nvar arr = (str+str).split(\"\").map(function(v) {return +v;});\n\nvar best = Infinity;\nvar ans = \"\";\n\nfor(var i = 0; i < n; i++) {\n var vals = arr.splice(i,n);\n for(var j = 0; j < 10; j++) {\n for(var k = 0; k < n; k++)\n vals[k] = (vals[k]+1)%10;\n var v = vals.join(\"\");\n if(+v < best) {\n best = +v;\n ans = v;\n }\n }\n}\n\nprint(ans);\n"}, {"source_code": "var n = +readline();\nvar str = readline();\nvar arr = (str+str).split(\"\").map(function(v) {return +v;});\n\nvar best = Infinity;\nvar ans = \"\";\n\nfor(var i = 0; i < n; i++) {\n var vals = arr.slice(i,i+n);\n for(var j = 0; j < 10; j++) {\n for(var k = 0; k < n; k++)\n vals[k] = (vals[k]+1)%10;\n var v = vals.join(\"\");\n if(+v < best) {\n best = +v;\n ans = v;\n }\n }\n}\n\nprint(ans);\n"}], "src_uid": "6ee356f2b3a4bb88087ed76b251afec2"} {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,c]=line[++cnt].split(' ');\r\n n=parseInt(n);\r\n let s=line[++cnt];\r\n let a=[];\r\n for(let i=0;ii) r=mid;\r\n else l=mid+1;\r\n }\r\n ans=Math.max(ans,a[l]-i);\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n }\r\n})", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction foo(size, letter, str) {\r\n var maxLength = 0;\r\n var lastGreenIndex;\r\n var firstGreenIndex;\r\n var firstCurrentIndex;\r\n \r\n for(var i=size-1; i>=0; i--) {\r\n if(str[i] === 'g') {\r\n lastGreenIndex = i;\r\n if(firstGreenIndex === undefined) firstGreenIndex = i;\r\n }\r\n \r\n if(str[i] === letter) {\r\n if(firstGreenIndex === undefined) firstCurrentIndex = i;\r\n var length = lastGreenIndex - i;\r\n if(length > maxLength) maxLength = length;\r\n }\r\n }\r\n \r\n \r\n if(firstGreenIndex !== undefined) {\r\n var lng = size - firstCurrentIndex + lastGreenIndex;\r\n if(lng > maxLength) maxLength = lng;\r\n }\r\n \r\n return maxLength;\r\n}\r\n \r\nfunction main() {\r\n var n = +readline();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n \r\n var result = foo(vars[0], vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n "}, {"source_code": "\r\n'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n var n = +readline();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n \r\n var result = traffic(vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n\r\nfunction traffic (color , cases ) { // r, rggry\r\n var casesList = cases.split('')\r\n var MAX = 0\r\n var rList = null\r\n var resultG = null\r\n\r\n for (let idx = 0; idx < casesList.length; idx++) {\r\n var element = casesList[idx];\r\n // console.log(element)\r\n if (color == element && rList == null) {\r\n rList = idx\r\n }\r\n if (element == 'g') {\r\n resultG = resultG == null ? idx : resultG\r\n if (rList != null) {\r\n if (idx - rList > MAX) MAX = idx - rList\r\n rList = null\r\n }\r\n }\r\n \r\n }\r\n\r\n if (rList !== null) {\r\n var arrLength = casesList.length - 1\r\n var Len = arrLength - rList + resultG + 1\r\n if (Len > MAX) MAX = Len\r\n }\r\n return MAX\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n var n = +readline();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n \r\n var result = traffic(vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n\r\nfunction traffic (color, cases ) { // r, rggry\r\n var casesList = cases.split('')\r\n var result = []\r\n var rList = null\r\n var resultG = null\r\n\r\n for (let idx = 0; idx < casesList.length; idx++) {\r\n var element = casesList[idx];\r\n // console.log(element)\r\n if (color == element && rList == null) {\r\n rList = idx\r\n }\r\n if (element == 'g') {\r\n resultG = resultG == null ? idx : resultG\r\n if (rList != null) {\r\n result.push(idx - rList)\r\n rList = null\r\n }\r\n }\r\n if (rList !== null && idx == casesList.length - 1) {\r\n var arrLength = casesList.length - 1\r\n result.push(arrLength - rList + resultG + 1)\r\n }\r\n }\r\n return result.sort((a, b) => b - a)[0]\r\n}\r\n"}, {"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n \nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n \nconst calc = (t)=>{\n /* read */\n let [nn, c] = rl().split(' ');\n let n = +nn;\n let s = rl();\n s += s;\n n += n;\n\n if (c === 'g') return 0;\n\n let cPos = -1;\n let result = -1;\n for (let i = 0; i < n; i++) {\n if (s[i] === c && cPos === -1) {\n cPos = i;\n continue;\n }\n if (s[i] === 'g' && cPos !== -1) {\n result = Math.max(result, i - cPos);\n cPos = -1;\n }\n }\n return result;\n};\n \nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n // calc(t);\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nlet t = +readline();\r\nwhile(t--){\r\n let [n , c] = readline().trim().split(' ');\r\n let s = readline().trim();\r\n console.log(`${solve(s, +n, c)}`)\r\n}\r\n\r\nfunction solve(str, n, c){\r\n let result = 0;\r\n if(c === 'g') return result;\r\n let firstGreenIdx = -1;\r\n let lastRedIdx= -1;\r\n let look = c;\r\n for(let i=0; i < n; i++){\r\n if(firstGreenIdx < 0 && str[i] === 'g'){\r\n firstGreenIdx = i\r\n }\r\n if(look === c && str[i]===c){\r\n lastRedIdx = i;\r\n look = 'g';\r\n }\r\n if(look === 'g' && str[i] === 'g'){\r\n look = c;\r\n result = Math.max(result, i - lastRedIdx)\r\n lastRedIdx = -1;\r\n }\r\n }\r\n if(lastRedIdx !== -1){\r\n result = Math.max(result, n-lastRedIdx+firstGreenIdx);\r\n } \r\n return result;\r\n}\r\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, curr, lights) {\r\n // print(n, curr, lights);\r\n // \u6bcf\u4e2acurr\u540e\u9762\u6700\u8fdc\u7684\u4e00\u4e2ag\r\n let ret = 0;\r\n if(curr == 'g') {\r\n print(ret);\r\n return;\r\n }\r\n let max = 0;\r\n let last = null;\r\n for(let i = 0; i < 2 * n; i++) {\r\n if(i < n) {\r\n if(last == null && lights.charAt(i%n) == curr) {\r\n last = i;\r\n }\r\n } else if(last == null){\r\n break;\r\n }\r\n if(last != null && lights.charAt(i%n) == 'g') {\r\n max = Math.max(max, i - last);\r\n last = null;\r\n }\r\n }\r\n print(max);\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = readline()\r\n .trim()\r\n .split(' ')\r\n var str = readline()\r\n .trim()\r\n begin(Number(n[0]), n[1],str);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, c] = stringArr1();\r\n n = parseInt(n);\r\n let arr = stringArr();\r\n if (c === \"g\") {\r\n console.log(0);\r\n continue;\r\n } else {\r\n let g = [],\r\n p = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === c) p.push(i + 1);\r\n else if (arr[i] === \"g\") g.push(i + 1);\r\n }\r\n const helper = () => {\r\n let ans = -Infinity,\r\n k = 0;\r\n for (let i = 0; i < p.length; i++) {\r\n let min = -Infinity;\r\n while (k < g.length) {\r\n if (p[i] < g[k]) {\r\n min = g[k] - p[i];\r\n break;\r\n }\r\n k++;\r\n }\r\n if (min === -Infinity) {\r\n min = n - p[i] + 1 + g[0] - 1;\r\n ans = Math.max(min, ans);\r\n return ans;\r\n } else ans = Math.max(min, ans);\r\n }\r\n return ans;\r\n };\r\n console.log(helper());\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, cur] = lines[l++].trim().split(' ')\n const str = lines[l++]\n output[i] = solve(n, cur, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, cur, str) {\n n = +n\n const color = {\n r: [],\n y: [],\n g: [],\n }\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n color[x].push(i)\n }\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n color[x].push(n + i)\n }\n // console.log(color)\n //\n let max = -Infinity\n for (let i = 0; i < color[cur].length; i++) {\n const p = color[cur][i]\n if (p >= n) break\n const j = binarySearch(0, color.g.length - 1, x => {\n return color.g[x] < p\n }) + 1\n // console.log(j, color.g[j], p)\n max = Math.max(max, color.g[j] - p)\n }\n return max\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const input = read().split(/\\s+/);\r\n let n = Number(input[0]),\r\n c = input[1],\r\n s = read();\r\n s = s + s;\r\n if (c === 'g') return 0;\r\n const r = new Array(n);\r\n let pre = n;\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n if (s[i] === 'g') pre = i;\r\n r[i] = pre;\r\n }\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] === c) {\r\n res = Math.max(res, r[i] - i);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var vars = readline().split(' ');\r\n var str = readline();\r\n if(vars[1] === 'g') {\r\n print(0);\r\n continue;\r\n }\r\n str += str;\r\n var temp = [];\r\n for(var j = 0; j < str.length; j++) {\r\n if(str[j] === vars[1]) {\r\n var c = 0;\r\n for(var jj = j; jj < str.length && str[jj] !== 'g'; jj++) {\r\n c++;\r\n }\r\n temp.push(c);\r\n j = jj;\r\n }\r\n }\r\n print(Math.max(...temp));\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction foo(size, letter, str) {\r\n var maxLength = 0;\r\n var lastGreenIndex;\r\n var firstGreenIndex;\r\n var firstCurrentIndex;\r\n\r\n for(var i=size-1; i>=0; i--) {\r\n if(str[i] === 'g') {\r\n lastGreenIndex = i;\r\n if(firstGreenIndex === undefined) firstGreenIndex = i;\r\n }\r\n \r\n if(str[i] === letter) {\r\n if(firstCurrentIndex === undefined) firstCurrentIndex = i;\r\n var length = lastGreenIndex - i;\r\n if(length > maxLength) maxLength = length;\r\n }\r\n }\r\n\r\n if(firstCurrentIndex > firstGreenIndex) {\r\n var lng = size - firstCurrentIndex + lastGreenIndex;\r\n if(lng > maxLength) maxLength = lng;\r\n }\r\n\r\n return maxLength;\r\n}\r\n\r\n\r\nfunction main() {\r\n var n = +readline();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n \r\n var vars = readline().split(' ');\r\n var str = readline();\r\n\r\n var result = foo(vars[0], vars[1], str)\r\n console.log(result)\r\n}\r\n}\r\n\r\n"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var vars = readline().split(' ');\r\n var str = readline();\r\n if(vars[1] === 'g') {\r\n print(0);\r\n continue;\r\n }\r\n str += str.slice(0, str.indexOf('g') + 1);\r\n var temp = [];\r\n for(var j = str.length - 1; j >= 0; j--) {\r\n if(str[j] === 'g') {\r\n var c = 0;\r\n for(var jj = j; jj >= 0 && str[jj] !== vars[1]; jj--) {\r\n c++;\r\n }\r\n temp.push(c);\r\n }\r\n }\r\n print(Math.max(...temp));\r\n}"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var vars = readline().split(' ');\r\n var str = readline();\r\n if(vars[1] === 'g') {\r\n print(0);\r\n continue;\r\n }\r\n var scu = vars[1] === 'r' ? 'y' : 'r';\r\n str += str.slice(0, str.indexOf('g') + 1);\r\n var temp = [];\r\n var c = 0;\r\n for(var j = 0; j < str.length; j++) {\r\n if(str[j] === 'g') {\r\n temp.push(c);\r\n c = 0;\r\n j++;\r\n while(j < str.length && str[j] === scu) {\r\n j++;\r\n }\r\n j--;\r\n continue;\r\n }\r\n c++;\r\n }\r\n print(Math.max(...temp));\r\n}"}], "src_uid": "9d3ee1b292a2402bb2204ab85dcab587"} {"source_code": "\"use strict\";\n//////////// LIBS\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift().trim();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction factorial(n) {\n let ret = [];\n for (let i = 2; i <= Math.sqrt(n); i++) {\n if (n % i == 0) {\n ret.push(i);\n ret.push(n / i);\n }\n }\n return ret;\n}\nfunction getPrimes() {\n let ret = [];\n for (let a = 2; a <= 10000; a++) {\n let isPrime = true;\n for (let i = 2; i <= Math.sqrt(a); i++) {\n if (a % i === 0) {\n isPrime = false;\n break;\n }\n }\n if (isPrime) {\n ret.push(a);\n }\n }\n return ret;\n}\nfunction getIsPrime(n) {\n for (let i = 2; i <= Math.sqrt(n); i++) {\n if (n % i === 0) {\n return false;\n }\n }\n return true;\n}\nfunction brut(n) {\n // let arr: number[] = [];\n // for (let i = 1; i < n; i++) {\n // arr.push(i);\n // }\n let max = [];\n const travel = (ret, p, i) => {\n if (i >= n) {\n return;\n }\n if (p === 1 && max.length < ret.length) {\n max = ret;\n }\n travel([...ret, i + 1], (p * (i + 1)) % n, i + 1);\n travel(ret, p, i + 1);\n };\n travel([], 1, 0);\n // console.log('n:', n);\n console.log(max.join(' '));\n}\nfunction solve(n) {\n let arr = [];\n for (let i = 0; i < n - 1; i++) {\n arr.push(i);\n }\n // if (!getIsPrime(n)) {\n // arr.push(n - 1);\n // }\n let factorials = factorial(n);\n // console.log(factorials);\n for (let f of factorials) {\n for (let i = f; i < n; i += f) {\n arr[i] = 0;\n }\n }\n let p = 1;\n let ret = [];\n for (let i = 1; i < arr.length; i++) {\n if (arr[i]) {\n ret.push(i);\n p = (p * arr[i]) % n;\n }\n }\n if ((p * (n - 1)) % n === 1) {\n ret.push(n - 1);\n }\n console.log(ret.length);\n if (ret.length) {\n console.log(ret.join(' '));\n }\n}\nfunction main() {\n const io = new IO();\n // let t = io.nextNum();\n // while (t--) {\n let n = io.nextNum();\n solve(n);\n // }\n}\nmain();\n", "positive_code": [{"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n var f = new Array(n + 1).fill([]);\r\n function gcd(a, b) {\r\n if (a < b) {\r\n var temp = a; \r\n a = b;\r\n b = temp;\r\n }\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b);\r\n }\r\n var product = 1;\r\n var set = new Set();\r\n for (var i = 1; i <= n; i++) {\r\n if (gcd (i, n) === 1) {\r\n product = (product * i) % n;\r\n set.add(i);\r\n }\r\n }\r\n if (product % n === 1) {\r\n var arr = Array.from(set);\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr.length);\r\n console.log(arr.join(\" \"));\r\n } else {\r\n var p = product % n;\r\n set.delete(p);\r\n var arr = Array.from(set);\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr.length);\r\n console.log(arr.join(\" \"));\r\n }\r\n})"}, {"source_code": "// 04/19/21 afternoon\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\n// Accepted --- 109ms https://codeforces.com/contest/1514/submission/113555763\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n let last = num - 1;\r\n for (let x = 1; x < last; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n if (p == last) res.push(last);\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "// 04/19/21 afternoon\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst powmod = (a, b, mod) => {\r\n let r = 1n;\r\n while (b > 0n) {\r\n if (b % 2n == 1) r = r * a % mod;\r\n b >>= 1n;\r\n a = a * a % mod;\r\n }\r\n return r; // return BigInt\r\n};\r\nconst combination = (m, n) => {\r\n return factorial(m, n) / factorial(n, n); // return BigInt\r\n};\r\nconst factorial = (m, n) => {\r\n let num = 1n;\r\n let cnt = 0;\r\n for (let i = BigInt(m); i > 0; i--) {\r\n if (cnt == n) break;\r\n num *= i;\r\n cnt++;\r\n }\r\n return num;\r\n};\r\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst counter = (a_or_s) => {\r\n let map = new Map();\r\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\r\n return map;\r\n};\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\n// Accepted --- 109ms https://codeforces.com/contest/1514/submission/113555763\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n let last = num - 1;\r\n for (let x = 1; x < last; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n if (p == last) res.push(last);\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "// 04/19/21 afternoon\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst err = console.error;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst powmod = (a, b, mod) => {\r\n let r = 1n;\r\n while (b > 0n) {\r\n if (b % 2n == 1) r = r * a % mod;\r\n b >>= 1n;\r\n a = a * a % mod;\r\n }\r\n return r; // return BigInt\r\n};\r\nconst combination = (m, n) => {\r\n return factorial(m, n) / factorial(n, n); // return BigInt\r\n};\r\nconst factorial = (m, n) => {\r\n let num = 1n;\r\n let cnt = 0;\r\n for (let i = BigInt(m); i > 0; i--) {\r\n if (cnt == n) break;\r\n num *= i;\r\n cnt++;\r\n }\r\n return num;\r\n};\r\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst counter = (a_or_s) => {\r\n let map = new Map();\r\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\r\n return map;\r\n};\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\n// Accepted --- 109ms https://codeforces.com/contest/1514/submission/113555763\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n let last = num - 1;\r\n for (let x = 1; x < last; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n if (p == last) res.push(last);\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "// 04/19/21 afternoon\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst err = console.error;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst powmod = (a, b, mod) => {\r\n let r = 1n;\r\n while (b > 0n) {\r\n if (b % 2n == 1) r = r * a % mod;\r\n b >>= 1n;\r\n a = a * a % mod;\r\n }\r\n return r; // return BigInt\r\n};\r\nconst combination = (m, n) => {\r\n return factorial(m, n) / factorial(n, n); // return BigInt\r\n};\r\nconst factorial = (m, n) => {\r\n let num = 1n;\r\n let cnt = 0;\r\n for (let i = BigInt(m); i > 0; i--) {\r\n if (cnt == n) break;\r\n num *= i;\r\n cnt++;\r\n }\r\n return num;\r\n};\r\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst counter = (a_or_s) => {\r\n let map = new Map();\r\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\r\n return map;\r\n};\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\n// Accepted --- 109ms https://codeforces.com/contest/1514/submission/113555763\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n let last = num - 1;\r\n for (let x = 1; x < last; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n if (p == last) res.push(last);\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\n// Accepted --- 109ms https://codeforces.com/contest/1514/submission/113555763\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n let last = num - 1;\r\n for (let x = 1; x < last; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n if (p == last) res.push(last);\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "// 04/19/21 afternoon\n\n///////////////////////////////// pre-define /////////////////////////////////////\nconst pr = console.log;\nconst err = console.error;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst powmod = (a, b, mod) => {\n let r = 1n;\n while (b > 0n) {\n if (b % 2n == 1) r = r * a % mod;\n b >>= 1n;\n a = a * a % mod;\n }\n return r; // return BigInt\n};\nconst combination = (m, n) => {\n return factorial(m, n) / factorial(n, n); // return BigInt\n};\nconst factorial = (m, n) => {\n let num = 1n;\n let cnt = 0;\n for (let i = BigInt(m); i > 0; i--) {\n if (cnt == n) break;\n num *= i;\n cnt++;\n }\n return num;\n};\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst counter = (a_or_s) => {\n let map = new Map();\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\n return map;\n};\n///////////////////////////////////////////////////////////////////////////////////\n\nconst solve = (num) => {\n res = [];\n let p = 1;\n let last = num - 1;\n for (let x = 1; x < last; x++) {\n if (gcd(num, x) == 1) {\n p = p * x % num;\n res.push(x);\n }\n }\n if (p == last) res.push(last);\n pr(res.length);\n pr(res.join(\" \"));\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n rl.on('line', (line) => {\n solve(Number(line));\n });\n};\n\nmain()"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let n = parseInt(readLine());\r\n\r\n C(n);\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction isPrime(num) {\r\n if(num < 2) return false;\r\n for (var i = 2; i < num; i++) {\r\n if(num%i==0)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n}\r\n\r\n\r\nfunction C(n){\r\n let ok = [];\r\n let ans = [];\r\n let prod = 1;\r\n for(let i= 1; i < n; i++) {\r\n if(gcd(n,i) === 1) {\r\n ok[i] = 1;\r\n prod = (prod*i)%n;\r\n }\r\n }\r\n if(prod!==1) ok[prod] = 0;\r\n for(let i = 0; i b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst powmod = (a, b, mod) => {\r\n let r = 1n;\r\n while (b > 0n) {\r\n if (b % 2n == 1) r = r * a % mod;\r\n b >>= 1n;\r\n a = a * a % mod;\r\n }\r\n return r; // return BigInt\r\n};\r\nconst combination = (m, n) => {\r\n return factorial(m, n) / factorial(n, n); // return BigInt\r\n};\r\nconst factorial = (m, n) => {\r\n let num = 1n;\r\n let cnt = 0;\r\n for (let i = BigInt(m); i > 0; i--) {\r\n if (cnt == n) break;\r\n num *= i;\r\n cnt++;\r\n }\r\n return num;\r\n};\r\nconst arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst counter = (a_or_s) => {\r\n let map = new Map();\r\n for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);\r\n return map;\r\n};\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (num) => {\r\n res = [];\r\n let p = 1;\r\n for (let x = 1; x <= num - 1; x++) {\r\n if (gcd(num, x) == 1) {\r\n p = p * x % num;\r\n res.push(x);\r\n }\r\n }\r\n pr(res.length);\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n solve(Number(line));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let n = parseInt(readLine());\r\n\r\n C(n);\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction isPrime(num) {\r\n if(num < 2) return false;\r\n for (var i = 2; i < num; i++) {\r\n if(num%i==0)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n}\r\n\r\nfunction lcm(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n return (!x || !y) ? 0 : Math.abs((x * y) / gcd(x, y));\r\n}\r\n\r\n\r\nfunction C(n){\r\n let arr = [];\r\n let ans = [];\r\n let prod = 1;\r\n for(let i= 1; i < n; i++) {\r\n if(gcd(n,i) === 1) {\r\n arr.push(i);\r\n prod = (prod*i)%n;\r\n }\r\n }\r\n if(prod!==1) arr[prod-1] = 0;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] !== 0) ans.push(arr[i]);\r\n }\r\n console.log(ans.length);\r\n console.log(ans.join(' '))\r\n}\r\n\r\nmodule.exports = C;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let n = parseInt(readLine());\r\n\r\n C(n);\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction isPrime(num) {\r\n if(num < 2) return false;\r\n for (var i = 2; i < num; i++) {\r\n if(num%i==0)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n}\r\n\r\nfunction lcm(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n return (!x || !y) ? 0 : Math.abs((x * y) / gcd(x, y));\r\n}\r\n\r\n\r\nfunction C(n){\r\n let arr = [];\r\n let ans = [];\r\n let prod = 1;\r\n for(let i= 1; i < n; i++) {\r\n if(gcd(n,i) === 1) {\r\n arr.push(i);\r\n prod = (prod*i)%n;\r\n }\r\n }\r\n if(prod!==1) arr[prod] = 0;\r\n for(let i = 0; i < arr.length; i++){\r\n if(arr[i] !== 0) ans.push(arr[i]);\r\n }\r\n console.log(ans.length);\r\n console.log(ans.join(' '))\r\n}\r\n\r\nmodule.exports = C;"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n var f = new Array(n + 1).fill([]);\r\n function gcd(a, b) {\r\n if (a < b) {\r\n var temp = a; \r\n a = b;\r\n b = temp;\r\n }\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b);\r\n }\r\n var product = 1;\r\n var set = new Set();\r\n for (var i = 1; i <= n; i++) {\r\n if (gcd (i, n) === 1) {\r\n product *= i;\r\n set.add(i);\r\n }\r\n }\r\n if (product % n === 1) {\r\n var arr = Array.from(set);\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr.length);\r\n console.log(arr.join(\" \"));\r\n } else {\r\n var p = product % n;\r\n set.delete(p);\r\n var arr = Array.from(set);\r\n arr.sort((a, b) => {\r\n return a - b;\r\n });\r\n console.log(arr.length);\r\n console.log(arr.join(\" \"));\r\n }\r\n})"}], "src_uid": "d55afdb4a83aebdfce5a62e4ec934adb"} {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let max = 0;\n const ans = [];\n\n for(let i = 0; i < s; i++) {\n max = Math.max(f(i, sizes, ans), max);\n }\n \n return max;\n}\n\nconst f = (i, sizes, arr) => {\n if(!arr[i]) {\n let max = 0;\n\n for(let j = 2 * i + 1; j < sizes.length; j += i + 1) {\n if(sizes[j] > sizes[i]) {\n max = Math.max(f(j, sizes, arr), max);\n }\n }\n\n arr[i] = max + 1;\n }\n\n return arr[i];\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(' '));\n\n let dp = new Array(n);\n dp.fill(1);\n for(let i = 0; i < n; i++){\n let x = 2;\n while((i+1)*x <= n){\n let index = (i+1)*x - 1;\n if(s[index] > s[i]){\n dp[index] = Math.max(dp[index], dp[i]+1);\n }\n x++;\n }\n }\n\n let max = 0;\n for(let i = 0; i < n; i++)\n max = Math.max(max, dp[i]);\n\n //console.log(dp);\n console.log(max);\n }\n}"}], "negative_code": [{"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let res = [];\n\n for(let i = s - 1; i >= 0; i--) {\n let m = [sizes[i]];\n\n for(let j = i - 1; j >= 0; j--) {\n if((sizes[j] != m[m.length - 1]) && (m[m.length - 1] % sizes[j] == 0)) \n m.push(sizes[j]);\n }\n\n res.push(m.length);\n }\n \n res.sort();\n \n return res[res.length - 1];\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let res = [];\n\n for(let i = 0; i < s; i++) {\n let m = [sizes[i]];\n\n for(let j = i; j < s; j++) {\n if((sizes[i] != sizes[j - 1]) && (sizes[j] % sizes[j - 1] == 0)) \n m.push(sizes[j]);\n }\n\n res.push(m.length);\n }\n \n res.sort();\n \n return res[res.length - 1];\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let res = [];\n\n for(let i = s - 1; i >= 0; i--) {\n let m = [sizes[i]];\n let indexes = [i + 1];\n\n for(let j = i + 1; j >= 0; j--) {\n if((indexes[indexes.length - 1] % (j + 1) == 0) \n && (m[m.length - 1] > sizes[j])\n ) {\n m.push(sizes[j]);\n indexes.push(j + 1);\n }\n }\n\n res.push(m.length);\n }\n \n res.sort();\n \n return res[res.length - 1];\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let res = 1;\n\n for(let i = s - 1; i >= 0; i--) {\n let indexes = [i + 1];\n\n for(let j = i + 1; j >= 0; j--) {\n if((indexes[indexes.length - 1] % (j + 1) == 0) \n && (sizes[indexes[indexes.length - 1] - 1] > sizes[j])\n ) {\n indexes.push(j + 1);\n }\n }\n\n if(indexes.length > res) res = indexes.length;\n }\n \n return res;\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n problem.T = parseInt(line);\n return problem;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || cases[cases.length - 1].arr) {\n cases.push({\n s: line\n });\n } else {\n cases[cases.length - 1].arr = line;\n }\n\n const isProcessing = cases.length < problem.T || !cases[cases.length - 1].arr;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const {s, arr} = data;\n const sizes = arr.split(' ').map(i => +i);\n let res = [];\n\n for(let i = s - 1; i >= 0; i--) {\n let m = [sizes[i]];\n let indexes = [i + 1];\n\n for(let j = i - 1; j >= 0; j--) {\n if((indexes[indexes.length - 1] % (j + 1) == 0) \n && (m[m.length - 1] > sizes[j])\n ) {\n m.push(sizes[j]);\n indexes.push(j + 1);\n }\n }\n\n res.push(m.length);\n }\n \n res.sort();\n \n return res[res.length - 1];\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r a[j]) {\n let index = ((i+1)/(j+1)) - 1;\n dp[i-1] = Math.max(dp[i-1], dp[index] + 1)\n }\n }\n }\n }\n\n console.log(Math.max(...dp));\n }\n\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r=1;j--) {\n if(i % j=== 0) {\n let index = i / j;\n if(a[j] < a[i]) {\n dp[i] = Math.max(dp[i], dp[index] + 1);\n break;\n }\n }\n }\n }\n console.log(Math.max(...dp));\n }\n\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 4\n 4\n 5 3 4 6\n 7\n 1 4 2 3 6 4 9\n 5\n 5 4 3 2 1\n 1\n 9\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r i) {\n if(a[i] < a[j]) {\n let index = j / i;\n dp[j] = Math.max(dp[j], dp[index] + 1)\n }\n }\n }\n }\n console.log(Math.max(...dp));\n }\n\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n5 1\n8 2\n3 4\n\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r values[i] && (values[j] % values[i] === 0)) {\n divisble.push(values[i], values[j]);\n i++;\n j++;\n }\n }\n }\n \n\n if(divisble.length === 0) {\n console.log(1);\n continue;\n }\n\n let max = Math.max(...divisble);\n let newValue = [];\n \n for(let i=0;i 0) {\n //pr(t)\n var input = rdArN();\n var n = input[0];\n var m = input[1];\n var k = input[2];\n var H = [null].concat(rdArN());\n \n for (var i = 1; i < n; ++i) {\n var curH = H[i];\n var nxtH = H[i+1];\n\n var curH_ = Math.max(nxtH - k, 0);\n if (curH < curH_) {\n m -= curH_ - curH;\n if (m < 0) {\n pr('NO');\n continue loop;\n }\n } else {\n m += curH - curH_;\n }\n }\n \n pr('YES');\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();", "positive_code": [{"source_code": "const processData = (lines) => {\n const [countTests, ...tests] = lines\n\n const checkTest = (countRows, cubs, countToNext, rows) => {\n for (let i = 0; i < countRows - 1; i++) {\n cubs += Math.min(rows[i] - rows[i + 1] + countToNext, rows[i])\n if (cubs < 0) return 'NO'\n }\n return 'YES'\n }\n\n for (let j = 0; j < Number(countTests); j++) {\n const [countRows, cubs, countToNext] = tests[2 * j].split(' ').map(n => Number(n))\n const rows = tests[2 * j + 1].split(' ').map(n => Number(n))\n console.log(checkTest(countRows, cubs, countToNext, rows))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}], "negative_code": [{"source_code": "const processData = (lines) => {\n const [countTests, ...tests] = lines\n\n const checkTest = (countRows, cubs, countToNext, rows) => {\n for (let i = 0; i < countRows - 1; i++) {\n cubs += rows[i] - rows[i + 1] + countToNext\n if (cubs < 0) return 'NO'\n }\n return 'YES'\n }\n\n for (let j = 0; j < Number(countTests); j++) {\n const [countRows, cubs, countToNext] = tests[2 * j].split(' ').map(n => Number(n))\n const rows = tests[2 * j + 1].split(' ').map(n => Number(n))\n console.log(checkTest(countRows, cubs, countToNext, rows))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}], "src_uid": "3f60e740d9a3ec14223b2b1f62c52f61"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar alist = nextIntArray();\n\tvar blist = nextIntArray();\n\tvar aIndexes = {};\n\tfor(var i = 0; i < N; i++){\n\t\taIndexes[alist[i]] = i;\n\t}\n\tvar moveCountRight = {};//\u53f3\u306b\u5411\u304b\u3046\u3068\u4e00\u81f4\u3059\u308b\u306e\u306b\u5fc5\u8981\u306a\u79fb\u52d5\u6570\n\tvar moveCountLeft = {};//\u5de6\u306b\u5411\u304b\u3046\u3068\u3003\n\tfor(var i = 0; i < N; i++){\n\t\tif(aIndexes[blist[i]] > i){\n\t\t\tmoveCountRight[blist[i]] = aIndexes[blist[i]] - i;\n\t\t\tmoveCountLeft[blist[i]] = i + (N - aIndexes[blist[i]]);\n\t\t}else if(aIndexes[blist[i]] < i){\n\t\t\tmoveCountRight[blist[i]] = (N - i) + aIndexes[blist[i]];\n\t\t\tmoveCountLeft[blist[i]] = i - aIndexes[blist[i]];;\n\t\t}else{\n\t\t\tmoveCountRight[blist[i]] = 0;\n\t\t\tmoveCountLeft[blist[i]] = 0;\n\t\t}\n\t}\n\t\n\tvar max = 0;\n\tvar count = {};\n\tvar keys = Object.keys(moveCountRight);\n\tfor(var i = 0; i < keys.length; i++){\n\t\tif(count[moveCountRight[keys[i]]] == null){\n\t\t\tcount[moveCountRight[keys[i]]] = 1;\n\t\t}else{\n\t\t\tcount[moveCountRight[keys[i]]]++;\n\t\t}\n\t\tmax = Math.max(max, count[moveCountRight[keys[i]]]);\n\t}\n\tmyout(max);\n}\n", "positive_code": [{"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n\n const x = new Array(n + 1)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let b1 = b[i]\n if(!x[a1]) x[a1] = new Array(4)\n if(!x[b1]) x[b1] = new Array(4)\n x[a1][0] = i\n x[b1][1] = i\n }\n\n // wr(x)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let diff1 = (x[a1][0] - (x[a1][1] + n)) % n\n\n x[a1][2] = diff1\n }\n\n // wr(x)\n let map1 = {}\n for(let i = 1; i <= n; i++) {\n let x1 = x[i][2]\n if(!map1[x1]) map1[x1] = 0\n map1[x1]++\n }\n let m1 = Object.entries(map1).map(a => a[1])\n wr(Math.max(...m1))\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(300000);\n for(let i = 0; i < a.length; i++){\n map[a[i]] = i;\n }\n\n let max = 0;\n let countMap = new Array(300000);\n\n for(let j = 0; j < b.length; j++){\n let i = map[b[j]];\n if(i-j < 0){\n countMap[n-j+i] = countMap[n-j+i] ? countMap[n-j+i]+1 : 1;\n max = Math.max(max, countMap[n-j+i]);\n }else{\n countMap[i-j] = countMap[i-j] ? countMap[i-j]+1 : 1;\n max = Math.max(max, countMap[i-j]);\n }\n }\n\n console.log(max);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let n = parseInt(readline());\n let a = readline().split(\" \").map(Number);\n let b = readline().split(\" \").map(Number);\n\n let offset = [];\n let map = {};\n\n for(let i=0;i {\n ans = Math.max(ans, map[x]);\n });\n\n console.log(ans);\n}"}, {"source_code": "// var lineIdx = 0;\n// var readline = () => {\n// var input = [\"4\", \"4 2 3 1\", \"4 2 3 1\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar n = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\nvar sub = new Array(n);\nvar res = new Array(n);\nfor(var i = 0; i < n; i++){\n res[i] = 0;\n}\n\nvar first = readline().split(\" \").map(function(x) { return parseInt(x); }).forEach((x, i) => sub[x - 1] = i);\nvar second = readline().split(\" \").map(function(x) { return parseInt(x); }).forEach((x, i) => {\n sub[x - 1] = sub[x - 1] - i >= 0 ? sub[x - 1] - i : n + sub[x - 1] - i;\n res[sub[x - 1]] = res[sub[x - 1]] + 1;\n});\n\nprint(res.reduce((p, c) => Math.max(p, c), 0));\n\n\n\n\n"}], "negative_code": [{"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n\n const x = new Array(n + 1)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let b1 = b[i]\n if(!x[a1]) x[a1] = new Array(4)\n if(!x[b1]) x[b1] = new Array(4)\n x[a1][0] = i\n x[b1][1] = i\n }\n\n // wr(x)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let diff1 = x[a1][0] - x[a1][1]\n let diff2 = diff1\n if(x[a1][0] === 0 && x[a1][1] !== 0) {\n diff2 = diff1 + n\n }\n\n x[a1][2] = diff1\n x[a1][3] = diff2\n }\n\n // wr(x)\n let map1 = {}\n let map2 = {}\n for(let i = 1; i <= n; i++) {\n let x1 = x[i][2]\n let x2 = x[i][3]\n if(!map1[x1]) map1[x1] = 0\n if(!map2[x2]) map2[x2] = 0\n map1[x1]++\n map2[x2]++\n }\n let m1 = Object.entries(map1).map(a => a[1])\n let m2 = Object.entries(map2).map(a => a[1])\n wr(Math.max(...m1, ...m2))\n}\n"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n\n const x = new Array(n + 1)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let b1 = b[i]\n if(!x[a1]) x[a1] = new Array(4)\n if(!x[b1]) x[b1] = new Array(4)\n x[a1][0] = i\n x[b1][1] = i\n }\n\n // wr(x)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let diff1 = x[a1][0] - x[a1][1]\n let diff2 = diff1\n if(x[a1][0] === 0 && x[a1][1] !== 0) {\n diff2 = diff1 + n\n }\n if(x[a1][0] === n - 1 && x[a1][1] !== n - 1) {\n diff1 = -1 - x[a1][1]\n }\n\n x[a1][2] = diff1\n x[a1][3] = diff2\n }\n\n // wr(x)\n let map1 = {}\n let map2 = {}\n for(let i = 1; i <= n; i++) {\n let x1 = x[i][2]\n let x2 = x[i][3]\n if(!map1[x1]) map1[x1] = 0\n if(!map2[x2]) map2[x2] = 0\n map1[x1]++\n map2[x2]++\n }\n let m1 = Object.entries(map1).map(a => a[1])\n let m2 = Object.entries(map2).map(a => a[1])\n wr(Math.max(...m1, ...m2))\n}\n"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n\n const x = new Array(n + 1)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let b1 = b[i]\n if(!x[a1]) x[a1] = new Array(4)\n if(!x[b1]) x[b1] = new Array(4)\n x[a1][0] = i\n x[b1][1] = i\n }\n\n // wr(x)\n\n for(let i = 0; i < n; i++) {\n let a1 = a[i]\n let diff1 = x[a1][0] - x[a1][1]\n let diff2 = diff1\n if(x[a1][0] === 0 && x[a1][1] !== 0) {\n diff2 = diff1 + n\n }\n if(x[a1][0] === n - 1 && x[a1][1] !== n - 1) {\n diff1 = -1 - x[a1][1]\n }\n\n x[a1][2] = diff1\n x[a1][3] = diff2\n }\n\n wr(x)\n let map1 = {}\n let map2 = {}\n for(let i = 1; i <= n; i++) {\n let x1 = x[i][2]\n let x2 = x[i][3]\n if(!map1[x1]) map1[x1] = 0\n if(!map2[x2]) map2[x2] = 0\n map1[x1]++\n map2[x2]++\n }\n let m1 = Object.entries(map1).map(a => a[1])\n let m2 = Object.entries(map2).map(a => a[1])\n wr(Math.max(...m1, ...m2))\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n5 1 2 3 4\n1 2 3 4 5\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n //let range = parseInt(readline());\n\n //for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n5 1 2 3 4\n1 2 3 4 5\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n //let range = parseInt(readline());\n\n //for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n5 1 2 3 4\n1 2 3 4 5\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n //let range = parseInt(readline());\n\n //for(let r=0;r {\n// var input = [\"4\", \"4 2 3 1\", \"4 2 3 1\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar n = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\nvar sub = new Array(n);\nvar res = new Array(n);\nfor(var i = 0; i < n; i++){\n res[i] = 0;\n}\n\nvar first = readline().split(\" \").map(function(x) { return parseInt(x); }).forEach((x, i) => sub[x - 1] = i);\nvar second = readline().split(\" \").map(function(x) { return parseInt(x); }).forEach((x, i) => {\n sub[x - 1] = sub[x - 1] - i >= 0 ? sub[x - 1] - i : n + sub[x - 1] - i;\n res[sub[x - 1]] = res[sub[x - 1]] + 1;\n});\n\nprint(res.reduce((p, c) => Math.max(p, c), 0) % n);\n\n\n\n\n"}], "src_uid": "eb1bb862dc2b0094383192f6998891c5"} {"source_code": "var ABn = readline().split(' ');\nvar A = Number(ABn[0]),\n\tB = Number(ABn[1]),\n\tn = Number(ABn[2]);\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tvar l = Number(line[0]),\n\t\tt = Number(line[1]),\n\t\tm = Number(line[2]);\n\tvar heightAtL = A + (l - 1) * B;\n\n\t//1\n\tif (heightAtL > t) {\n\t\tprint(-1);\n\t\tcontinue;\n\t}\n\n\t//binary search, check heightAtR and \n\tvar MAX = 100000000;\n\tvar low = l, high = MAX, mid, r = -1;\n\n\twhile (low <= high) {\n\t\tmid = (low + high) >> 1;\n\t\tvar heightAtR = A + (mid - 1) * B;\n\t\tif (heightAtR > t) {\n\t\t\thigh = mid - 1;\n\t\t\tcontinue;\n\t\t}\n\t\tvar sum = (mid - l + 1) * heightAtL + (mid - l)* (mid - l + 1) / 2 * B;\n\t\tif (sum > t * m) {\n\t\t\thigh = mid - 1;\n\t\t\tcontinue;\n\t\t}\n\t\tlow = mid + 1;\n\t\tr = mid;\n\t}\n\tprint (r);\n\n}\n", "positive_code": [{"source_code": "/* jslint node: true */\nfunction Sum(a1, d, n) {\n return ((a1+a1+(n-1)*d)*n)/2;\n}\n\nvar input = readline().split(\" \").map(Number);\nvar a1, d, n;\nvar first = true;\nvar\n a1 = input[0];\n d = input[1];\n n = input[2];\nwhile( n-- ) {\n input = readline().split(\" \").map(Number);\n var\n l = input[0],\n t = input[1],\n m = input[2],\n suml = Sum(a1, d, l-1),\n tm = t*m,\n st = l,\n ed = ( ~~((t-a1)/d) ) + 1,\n md, ans;\n if( st>ed || a1+(l-1)*d>tm ) {\n ans = -1;\n } else {\n while( st<=ed ) {\n md = (st+ed)>>1;\n if( Sum(a1, d, md)-suml<=tm ) {\n ans = md;\n st = md+1;\n } else {\n ed = md-1;\n }\n }\n }\n print(ans);\n}\n"}], "negative_code": [{"source_code": "/* jslint node: true */\n\"use strict\";\nfunction Sum(a1, d, n) {\n return ((a1+a1+(n-1)*d)*n) >> 1;\n}\n\nvar input = readline().split(' ').map(Number);\nvar a1, d, n;\nvar first = true;\nvar\n a1 = input[0];\n d = input[1];\n n = input[2];\nwhile( n-- ) {\n input = readline().split(' ').map(Number);\n var\n l = input[0],\n t = input[1],\n m = input[2],\n suml = Sum(a1, d, l-1),\n tm = t*m,\n st = l,\n ed = ( ((t-a1)/d) | 0 ) + 1,\n md, ans;\n if( st>ed || a1+(l-1)*d>tm ) {\n ans = -1;\n } else {\n while( st<=ed ) {\n md = (st+ed)>>1;\n if( Sum(a1, d, md)-suml<=tm ) {\n ans = md;\n st = md+1;\n } else {\n ed = md-1;\n }\n }\n }\n print(ans);\n}\n"}, {"source_code": "/* jslint node: true */\nfunction Sum(a1, d, n) {\n return ((a1+a1+(n-1)*d)*n)/2;\n}\n\nvar input = readline().split(\" \").map(Number);\nvar a1, d, n;\nvar first = true;\nvar\n a1 = input[0];\n d = input[1];\n n = input[2];\nwhile( n-- ) {\n input = readline().split(\" \").map(Number);\n var\n l = input[0],\n t = input[1],\n m = input[2],\n suml = Sum(a1, d, l-1),\n tm = t*m,\n st = l,\n ed = ( ~~((t-a1)/d) ) + 1,\n md, ans;\n print(l, t, m, suml, tm, st, ed);\n if( st>ed || a1+(l-1)*d>tm ) {\n ans = -1;\n } else {\n while( st<=ed ) {\n md = (st+ed)>>1;\n if( Sum(a1, d, md)-suml<=tm ) {\n ans = md;\n st = md+1;\n } else {\n ed = md-1;\n }\n }\n }\n print(ans);\n}\n"}], "src_uid": "89c97b6c302bbb51e9d5328c680a7ea7"} {"source_code": "if (process.env.ANT)\n{\n global.print = this.print || function(){console.log([...arguments].join(' '))} || require('lol-io').print\n global.write = this.write || require('lol-io').write\n global.readline = this.readline || require('lol-io').readline\n global.debug = function(){console.log('debug:', [...arguments].join(' '))}\n main();\n}\nelse\n{\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n global.print = console.log\n global.write = (...args) => {\n process.stdout.write(args.join(' '));\n }\n const lines = []\n rl.on('line', line =>{\n lines.push(line);\n });\n rl.on('close', main)\n let rli = 0;\n global.readline = ()=>lines[rli++];\n global.debug = ()=>{};\n}\n\n///////////// CODE\n\nfunction t(n, arr){\n let ans = 0;\n let min = arr[n-1];\n for (let i = n-2; i>=0; i--)\n {\n if (arr[i]>min)\n ans++;\n else\n min = arr[i];\n }\n return ans;\n}\n\nfunction main(){\n\nvar q = +readline();\nwhile (q--)\n print(t(+readline(), readline().split(' ').map(n=>+n)));\n\n}\n\n", "positive_code": [{"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' ');\n var min = parseInt(a[n-1], 10), count = 0;\n \n for(var i=n-1; i>=0; i--) {\n a[i] = parseInt(a[i], 10);\n \n if(a[i] > min) count++;\n else if(a[i] < min) min = a[i];\n }\n \n print(count);\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var t = rdN();\n while (t --> 0) {\n var res = 0;\n\n var n = rdN();\n var A = rdArN();\n var min = A[n-1];\n for (var i = n-2; i >= 0; --i) {\n if (A[i] > min) {\n ++res;\n }\n min = Math.min(min, A[i]);\n }\n \n pr(res);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const t = Number(lines[0])\n \n for(let i = 0; i < t; i++) {\n const a = lines[2 * i + 2].split(' ')\n const prev = []\n let r = 0\n \n a.forEach((b, j) => {\n const c = Number(b)\n\n if(j === 0) prev.push(c)\n else {\n r = check(prev, c, r)\n }\n })\n\n console.log(r)\n }\n}\n\nfunction check(arr, v, count) {\n const last = _last(arr)\n\n if(last <= v || !arr.length) {\n arr.push(v)\n return count\n }\n else {\n arr.pop()\n return check(arr, v, count + 1)\n }\n}\n\nfunction _last(arr) {\n return arr[arr.length - 1]\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let start = 2;\n while (start < lines.length) {\n let prices = lines[start].split(' ');\n prices = prices.map(price => parseInt(price, 10));\n badPrices(prices);\n start += 2;\n }\n});\n\n\nfunction badPrices(prices) {\n if (prices.length === 1) {\n console.log('0');\n return;\n }\n let min = prices[prices.length - 1];\n let badDays = 0;\n for (let i = prices.length - 2; i >= 0; i--) {\n if (prices[i] > min) badDays++;\n else min = prices[i];\n }\n console.log(badDays);\n}\n\n"}, {"source_code": "'use strict'\n\nconst fn = (n, a) => {\n let m = a[n-1];\n let r = 0;\n for(let i = n-2; i > -1; i--) {\n if (a[i] > m) r++;\n else m = a[i];\n }\n return r;\n}\n\nlet t = parseInt(readline());\nwhile(t--) write(fn(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n"}], "negative_code": [], "src_uid": "09faf19627d2ff00c3821d4bc2644b63"} {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [rows, columns, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= rows - 1 && y <= columns - 1;\n const isOnBorder = ({ x, y }) => [0, rows - 1].indexOf(x) > -1 || [0, columns - 1].indexOf(y) > -1;\n\n let visited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < rows; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < rows - 1; row++) {\n for (let col = 1; col < columns - 1; col++) {\n let key = `${row}-${col}`;\n if (matrix[row][col] !== '.' || visited[key]) {\n continue;\n }\n\n let stack = [{ x: row, y: col }],\n isLake = true,\n lake = [{ x: row, y: col }];\n\n visited[key] = true;\n\n while (stack.length > 0) {\n let node = stack.pop();\n\n for (let d of direction) {\n let [x, y] = [node.x + d.x, node.y + d.y];\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n stack.push({ x, y });\n lake.push({ x, y });\n\n if (isOnBorder({ x, y })) {\n isLake = false;\n }\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n let count = 0;\n for (let i = lakes.length; i > k; i--) {\n let lake = lakes.shift();\n count += lake.length;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n", "positive_code": [{"source_code": "var arr = readline().split(' ');\nvar M = Number(arr[0]);\nvar N = Number(arr[1]);\nvar K = Number(arr[2]);\nvar rs = 0;\n\nvar rect = [];\nfor (var i = 0;i < M;i ++) {\n\tvar _str = readline().split(' ')[0];\n\trect[i] = _str.split('');\n}\n\nvar obj_arr = [];\n\nfor (var i = 0;i < M;i ++) {\n\tvar _str = rect[i];\n\tfor (var j = 0;j < N;j ++) {\n\t\tif (_str[j] == '.') {\n\t\t\tvar area = helper(i, j);\n\t\t\tif (area > 0) {\n\t\t\t\tobj_arr.push({\n\t\t\t\t\tstart_x: i,\n\t\t\t\t\tstart_y: j,\n\t\t\t\t\tarea: area\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n} \n\nif (obj_arr.length > K) {\n\tfor (var i = 0;i < obj_arr.length;i ++) {\n\t\tfor (var j = i + 1;j < obj_arr.length;j ++) {\n\t\t\tif (obj_arr[i].area > obj_arr[j].area) {\n\t\t\t\tvar tmp = obj_arr[i];\n\t\t\t\tobj_arr[i] = obj_arr[j];\n\t\t\t\tobj_arr[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tvar index = 0;\n\tvar tmp = obj_arr.length - K;\n\twhile (tmp) {\n\t\tvar obj = obj_arr[index];\n\t\tfill(obj.start_x, obj.start_y);\n\t\tindex ++;\n\t\ttmp--;\n\t}\n}\n\nfor (var i = 0;i < M;i ++) {\n\tfor (var j = 0;j < N;j ++) {\n\t\tif (rect[i][j] == '&') {\n\t\t\trect[i][j] = '.';\n\t\t}\n\t}\n}\n\nprint(rs);\n\nfor (var i = 0;i < M;i ++) {\n\tvar _str = \"\";\n\tfor (var j = 0;j < N;j++) {\n\t\t_str += rect[i][j];\n\t}\n\tprint(_str);\n}\n\nfunction helper(_x, _y) {\n\tif (_x < 0 || _y < 0 || _x >= M || _y >= N) {\n\t\treturn -1;\n\t}\n\tif (rect[_x][_y] != '.') {\n\t\treturn 0;\n\t}\n\trect[_x][_y] = '&';\n\tvar area1 = helper(_x - 1, _y);\n\tvar area2 = helper(_x + 1, _y);\n\tvar area3 = helper(_x, _y - 1);\n\tvar area4 = helper(_x, _y + 1);\n\tif (area1 < 0 || area2 < 0 || area3 < 0 || area4 < 0) {\n\t\treturn -1;\n\t} \n\treturn area1 + area2 + area3 + area4 + 1;\n}\n\nfunction fill (_x, _y) {\n\tif (_x < 0 || _y < 0 || _x >= M || _y >= N) {\n\t\treturn;\n\t}\n\tif (rect[_x][_y] == '&') {\n\t\trs ++;\n\t\trect[_x][_y] = '*';\n\t\tfill(_x - 1, _y);\n\t\tfill(_x + 1, _y);\n\t\tfill(_x, _y - 1);\n\t\tfill(_x, _y + 1);\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst direction = [\n [0, 1],\n [0, -1],\n [1, 0],\n [-1, 0],\n];\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const [n, m, k] = readline().split(' ').map(Number);\n const isOcean = (row, col) =>\n row === 0 || row === n - 1 || col === 0 || col === m - 1;\n const isInRange = (row, col) =>\n row >= 0 && row <= n - 1 && col >= 0 && col <= m - 1;\n let matrix = new Array(n);\n for (let i = 0; i < n; i++) {\n matrix[i] = readline().split('');\n }\n\n let visited = {};\n let lakes = [];\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (matrix[i][j] === '.' && !visited[`${i}-${j}`]) {\n let stack = [[i, j]];\n visited[`${i}-${j}`] = true;\n let lake = [];\n let isLake = true;\n while (stack.length) {\n const [row, col] = stack.pop();\n\n lake.push([row, col]);\n if (isOcean(row, col)) isLake = false;\n for (let k = 0; k < direction.length; k++) {\n const x = row + direction[k][0];\n const y = col + direction[k][1];\n if (\n isInRange(x, y) &&\n matrix[x][y] === '.' &&\n !visited[`${x}-${y}`]\n ) {\n stack.push([x, y]);\n visited[`${x}-${y}`] = true;\n }\n }\n }\n\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n }\n lakes.sort((l1, l2) => l2.length - l1.length);\n let cnt = 0;\n\n lakes.forEach((lake, i) => {\n if (i >= k) {\n // transform\n lake.forEach(([i, j]) => {\n matrix[i][j] = '*';\n cnt++;\n });\n }\n });\n console.log(cnt);\n for (let i = 0; i < n; i++) {\n console.log(matrix[i].join(''));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const [n, m, k] = readline().split(' ').map(Number);\n const isOcean = (row, col) =>\n row === 0 || row === n - 1 || col === 0 || col === m - 1;\n let matrix = new Array(n);\n for (let i = 0; i < n; i++) {\n matrix[i] = readline().split('');\n }\n\n let visited = {};\n let lakes = [];\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (matrix[i][j] === '.' && !visited[`${i}-${j}`]) {\n let stack = [[i, j]];\n visited[`${i}-${j}`] = true;\n let lake = [];\n let isLake = true;\n while (stack.length) {\n const [row, col] = stack.pop();\n\n lake.push([row, col]);\n if (isOcean(row, col)) isLake = false;\n if (\n row > 0 &&\n matrix[row - 1][col] === '.' &&\n !visited[`${row - 1}-${col}`]\n ) {\n stack.push([row - 1, col]);\n visited[`${row - 1}-${col}`] = true;\n }\n if (\n row < n - 1 &&\n matrix[row + 1][col] === '.' &&\n !visited[`${row + 1}-${col}`]\n ) {\n stack.push([row + 1, col]);\n visited[`${row + 1}-${col}`] = true;\n }\n if (\n col > 0 &&\n matrix[row][col - 1] === '.' &&\n !visited[`${row}-${col - 1}`]\n ) {\n stack.push([row, col - 1]);\n visited[`${row}-${col - 1}`] = true;\n }\n if (\n col < m - 1 &&\n matrix[row][col + 1] === '.' &&\n !visited[`${row}-${col + 1}`]\n ) {\n stack.push([row, col + 1]);\n visited[`${row}-${col + 1}`] = true;\n }\n }\n\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n }\n lakes.sort((l1, l2) => l2.length - l1.length);\n let cnt = 0;\n\n lakes.forEach((lake, i) => {\n if (i >= k) {\n // transform\n lake.forEach(([i, j]) => {\n matrix[i][j] = '*';\n cnt++;\n });\n }\n });\n console.log(cnt);\n for (let i = 0; i < n; i++) {\n console.log(matrix[i].join(''));\n }\n}\n"}], "negative_code": [{"source_code": "var arr = readline().split(' ');\nvar M = Number(arr[0]);\nvar N = Number(arr[1]);\nvar K = Number(arr[2]);\nvar rs = 0;\n\nvar rect = [];\nfor (var i = 0;i < M;i ++) {\n\tvar _str = readline().split(' ')[0];\n\trect[i] = _str.split('');\n}\n\nvar obj_arr = [];\n\nfor (var i = 0;i < M;i ++) {\n\tvar _str = rect[i];\n\tfor (var j = 0;j < N;j ++) {\n\t\tif (_str[j] == '.') {\n\t\t\tvar area = helper(i, j);\n\t\t\tif (area > 0) {\n\t\t\t\tobj_arr.push({\n\t\t\t\t\tstart_x: i,\n\t\t\t\t\tstart_y: j,\n\t\t\t\t\tarea: area\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n} \n\nif (obj_arr.length > K) {\n\tfor (var i = 0;i < obj_arr.length;i ++) {\n\t\tfor (var j = i + 1;j < obj_arr.length;j ++) {\n\t\t\tif (obj_arr[i].area > obj_arr[j].area) {\n\t\t\t\tvar tmp = obj_arr[i];\n\t\t\t\tobj_arr[i] = obj_arr[j];\n\t\t\t\tobj_arr[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tvar index = 0;\n\tvar tmp = obj_arr.length - K;\n\twhile (tmp) {\n\t\tvar obj = obj_arr[index];\n\t\tfill(obj.start_x, obj.start_y);\n\t\tindex ++;\n\t\ttmp--;\n\t}\n}\n\nfor (var i = 0;i < M;i ++) {\n\tfor (var j = 0;j < N;j ++) {\n\t\tif (rect[i][j] == '&') {\n\t\t\trect[i][j] = '.';\n\t\t}\n\t}\n}\n\nprint(rs);\n\nfor (var i = 0;i < M;i ++) {\n\tvar _str = \"\";\n\tfor (var j = 0;j < N;j++) {\n\t\t_str += rect[i][j];\n\t}\n\tprint(_str);\n}\n\nfunction helper(_x, _y) {\n\tif (_x < 0 || _y < 0 || _x >= M || _y >= N) {\n\t\treturn -1;\n\t}\n\tif (rect[_x][_y] != '.') {\n\t\treturn 0;\n\t}\n\trect[_x][_y] = '&';\n\tvar area1 = helper(_x - 1, _y);\n\tvar area2 = helper(_x + 1, _y);\n\tvar area3 = helper(_x, _y - 1);\n\tvar area4 = helper(_x, _y + 1);\n\tif (area1 < 0 || area2 < 0 || area3 < 0 || area4 < 0) {\n\t\treturn -1;\n\t} \n\treturn area1 + area2 + area3 + area4 + 1;\n}\n\nfunction fill (_x, _y) {\n\tif (_x < 0 || _y < 0 || _x >= M || _y >= N) {\n\t\treturn;\n\t}\n\tif (rect[_x][_y] == '&') {\n\t\trect[_x][_y] = '*';\n\t\tfill(_x - 1, _y);\n\t\tfill(_x + 1, _y);\n\t\tfill(_x, _y - 1);\n\t\tfill(_x, _y + 1);\n\t}\n}"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [m, n, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= m - 1 && y <= n - 1;\n\n let parentVisited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < m; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < m - 1; row++) {\n for (let col = 1; col < n - 1; col++) {\n let rect = matrix[row][col];\n let key = `${row}-${col}`;\n if (rect !== '.' || parentVisited[key]) {\n continue;\n }\n let visited = { [key]: true },\n stack = [{ x: row, y: col }];\n\n let isLake = true;\n let lake = [{ x: row, y: col }];\n while (stack.length > 0) {\n let node = stack.pop();\n\n for (let d of direction) {\n let x = node.x + d.x,\n y = node.y + d.y;\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n parentVisited[dKey] = true;\n stack.push({ x, y });\n lake.push({ x, y });\n\n if ([0, m - 1].indexOf(x) > -1 || [0, n - 1].indexOf(y) > -1) {\n isLake = false;\n }\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n let count = 0;\n for (let i = lakes.length; i > k; i--) {\n let lake = lakes.shift();\n count++;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [rows, columns, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= rows - 1 && y <= columns - 1;\n const isOnBorder = ({ x, y }) =>\n [0, rows - 1].indexOf(x) > -1 || [0, columns - 1].indexOf(y) > -1;\n\n let visited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < rows; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < rows - 1; row++) {\n for (let col = 1; col < columns - 1; col++) {\n let key = `${row}-${col}`;\n if (matrix[row][col] !== '.' || visited[key]) {\n continue;\n }\n\n let stack = [{ x: row, y: col }],\n isLake = true,\n lake = [];\n\n visited = { [key]: true };\n\n while (stack.length > 0) {\n let node = stack.pop();\n lake.push(node);\n\n if (isOnBorder(node)) {\n isLake = false;\n }\n\n for (let d of direction) {\n let [x, y] = [node.x + d.x, node.y + d.y];\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n stack.push({ x, y });\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n let count = 0;\n for (let i = 0; i < lakes.length - k; i++) {\n let lake = lakes[i];\n count += lake.length;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [rows, columns, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= rows - 1 && y <= columns - 1;\n const isOnBorder = ({ x, y }) =>\n [0, rows - 1].indexOf(x) > -1 || [0, columns - 1].indexOf(y) > -1;\n\n let visited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < rows; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < rows - 1; row++) {\n for (let col = 1; col < columns - 1; col++) {\n let key = `${row}-${col}`;\n if (matrix[row][col] !== '.' || visited[key]) {\n continue;\n }\n\n let stack = [{ x: row, y: col }],\n isLake = true,\n lake = [{ x: row, y: col }];\n\n visited = { [key]: true };\n\n while (stack.length > 0) {\n let node = stack.pop();\n\n for (let d of direction) {\n let [x, y] = [node.x + d.x, node.y + d.y];\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n stack.push({ x, y });\n lake.push({ x, y });\n\n if (isOnBorder({ x, y })) {\n isLake = false;\n }\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n let count = 0;\n for (let i = lakes.length; i > k; i--) {\n let lake = lakes.shift();\n count += lake.length;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [m, n, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= m - 1 && y <= n - 1;\n const isOnBorder = ({ x, y }) => [0, m - 1].indexOf(x) > -1 || [0, n - 1].indexOf(y) > -1;\n\n let visited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < m; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < m - 1; row++) {\n for (let col = 1; col < n - 1; col++) {\n let rect = matrix[row][col],\n key = `${row}-${col}`;\n if (rect !== '.' || visited[key]) {\n continue;\n }\n\n let stack = [{ x: row, y: col }],\n isLake = true,\n lake = [{ x: row, y: col }];\n\n visited = { [key]: true };\n\n while (stack.length > 0) {\n let node = stack.pop();\n\n for (let d of direction) {\n let [x, y] = [node.x + d.x, node.y + d.y];\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n stack.push({ x, y });\n lake.push({ x, y });\n\n if (isOnBorder({ x, y })) {\n isLake = false;\n }\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n let count = 0;\n for (let i = lakes.length; i > k; i--) {\n let lake = lakes.shift();\n count += lake.length;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/723/D\n */\n\n'use strict';\nconst readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/LECTURE 06: DFS/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nconst lines = [];\nlet currentLine = 0;\n\nconst direction = [\n { x: 1, y: 0 },\n { x: -1, y: 0 },\n { x: 0, y: 1 },\n { x: 0, y: -1 },\n];\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim());\n}).on('close', () => {\n const read = () => lines[currentLine++];\n let [m, n, k] = read().split(' ').map(Number);\n\n const isInRange = ({ x, y }) => x >= 0 && y >= 0 && x <= m - 1 && y <= n - 1;\n const isOnBorder = ({ x, y }) => [0, m - 1].indexOf(x) > -1 || [0, n - 1].indexOf(y) > -1;\n\n let visited = {};\n let matrix = [];\n let lakes = [];\n for (let row = 0; row < m; row++) {\n matrix.push(read().split(''));\n }\n for (let row = 1; row < m - 1; row++) {\n for (let col = 1; col < n - 1; col++) {\n let rect = matrix[row][col],\n key = `${row}-${col}`;\n if (rect !== '.' || visited[key]) {\n continue;\n }\n\n let stack = [{ x: row, y: col }],\n isLake = true,\n lake = [{ x: row, y: col }];\n\n visited = { [key]: true };\n\n while (stack.length > 0) {\n let node = stack.pop();\n\n for (let d of direction) {\n let [x, y] = [node.x + d.x, node.y + d.y];\n let dKey = `${x}-${y}`;\n if (!visited[dKey] && isInRange({ x, y }) && matrix[x][y] === '.') {\n visited[dKey] = true;\n stack.push({ x, y });\n lake.push({ x, y });\n\n if (isOnBorder({ x, y })) {\n isLake = false;\n }\n }\n }\n }\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n\n lakes.sort((a, b) => a.length - b.length);\n console.log(lakes.length);\n let count = 0;\n for (let i = lakes.length; i > k; i--) {\n let lake = lakes.shift();\n count += lake.length;\n lake.forEach(({ x, y }) => (matrix[x][y] = '*'));\n }\n console.log(count);\n console.log(matrix.map((row) => row.join('')).join('\\n'));\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst direction = [\n [0, 1],\n [0, -1],\n [1, 0],\n [-1, 0],\n];\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const [n, m, k] = readline().split(' ').map(Number);\n const isOcean = (row, col) =>\n row === 0 || row === n - 1 || col === 0 || col === m - 1;\n const isInRange = (row, col) =>\n row >= 0 && row <= n - 1 && col >= 0 && col <= m - 1;\n let matrix = new Array(n);\n for (let i = 0; i < n; i++) {\n matrix[i] = readline().split('');\n }\n\n let visited = {};\n let lakes = [];\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (matrix[i][j] === '.' && !visited[`${i}-${j}`]) {\n let stack = [[i, j]];\n visited[`${i}-${j}`] = true;\n let lake = [];\n let isLake = true;\n while (stack.length) {\n const [row, col] = stack.pop();\n\n lake.push([row, col]);\n if (isOcean(row, col)) isLake = false;\n for (let k = 0; k < direction.length; k++) {\n const x = row + direction[k][0];\n const y = col + direction[k][1];\n if (\n isInRange(x, y) &&\n matrix[x][y] === '.' &&\n !visited[`${x}-${y}`]\n ) {\n stack.push([x, y]);\n visited[`${x}-${y}`] = true;\n }\n }\n }\n\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n }\n console.log(lakes);\n lakes.sort((l1, l2) => l2.length - l1.length);\n let cnt = 0;\n\n lakes.forEach((lake, i) => {\n if (i >= k) {\n // transform\n lake.forEach(([i, j]) => {\n matrix[i][j] = '*';\n cnt++;\n });\n }\n });\n console.log(cnt);\n for (let i = 0; i < n; i++) {\n console.log(matrix[i].join(''));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const [n, m, k] = readline().split(' ').map(Number);\n const isOcean = (x, y) => x === 0 || x === n - 1 || y === 0 || y === m - 1;\n let matrix = new Array(n);\n for (let i = 0; i < n; i++) {\n matrix[i] = readline().split('');\n }\n\n let visited = {};\n let lakes = [];\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (matrix[i][j] === '.' && !visited[`${i}-${j}`]) {\n let stack = [[i, j]];\n let lake = [];\n let isLake = true;\n while (stack.length) {\n const [row, col] = stack.pop();\n visited[`${row}-${col}`] = true;\n lake.push([row, col]);\n if (isOcean(row, col)) isLake = false;\n if (\n row > 0 &&\n matrix[row - 1][col] === '.' &&\n !visited[`${row - 1}-${col}`]\n )\n stack.push([row - 1, col]);\n if (\n row < n - 1 &&\n matrix[row + 1][col] === '.' &&\n !visited[`${row + 1}-${col}`]\n )\n stack.push([row + 1, col]);\n if (\n col > 0 &&\n matrix[row][col - 1] === '.' &&\n !visited[`${row}-${col - 1}`]\n )\n stack.push([row, col - 1]);\n if (\n col < m - 1 &&\n matrix[row][col + 1] === '.' &&\n !visited[`${row}-${col + 1}`]\n )\n stack.push([row, col + 1]);\n }\n\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n }\n\n lakes.sort((l1, l2) => l2.length - l1.length);\n let cnt = 0;\n\n lakes.forEach((lake, i) => {\n if (i >= k) {\n // transform\n lake.forEach(([i, j]) => {\n matrix[i][j] = '*';\n cnt++;\n });\n }\n });\n console.log(cnt);\n for (let i = 0; i < n; i++) {\n console.log(matrix[i].join(''));\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const [n, m, k] = readline().split(' ').map(Number);\n const isOcean = (x, y) => x === 0 || x === n - 1 || y === 0 || y === m - 1;\n let matrix = new Array(n);\n for (let i = 0; i < n; i++) {\n matrix[i] = readline().split('');\n }\n\n let visited = {};\n let lakes = [];\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (matrix[i][j] === '.' && !visited[`${i}-${j}`]) {\n let stack = [[i, j]];\n let lake = [];\n let isLake = true;\n while (stack.length) {\n const [row, col] = stack.pop();\n visited[`${row}-${col}`] = true;\n lake.push([row, col]);\n if (isOcean(row, col)) isLake = false;\n if (\n row > 0 &&\n matrix[row - 1][col] === '.' &&\n !visited[`${row - 1}-${col}`]\n )\n stack.push([row - 1, col]);\n if (\n row < n - 1 &&\n matrix[row + 1][col] === '.' &&\n !visited[`${row + 1}-${col}`]\n )\n stack.push([row + 1, col]);\n if (\n col > 0 &&\n matrix[row][col - 1] === '.' &&\n !visited[`${row}-${col - 1}`]\n )\n stack.push([row, col - 1]);\n if (\n col < m - 1 &&\n matrix[row][col + 1] === '.' &&\n !visited[`${row}-${col + 1}`]\n )\n stack.push([row, col + 1]);\n }\n\n if (isLake) {\n lakes.push(lake);\n }\n }\n }\n }\n\n lakes.sort((l1, l2) => l2.length - l1.length);\n let cnt = 0;\n\n lakes.forEach((lake, i) => {\n if (i >= k) {\n // transform\n cnt++;\n lake.forEach(([i, j]) => {\n matrix[i][j] = '*';\n });\n }\n });\n console.log(cnt);\n for (let i = 0; i < n; i++) {\n console.log(matrix[i].join(''));\n }\n}\n"}], "src_uid": "e514d949e7837c603a9ee032f83b90d2"} {"source_code": ";(function () {\n\n\tvar s = readline().replace(/^0*/, '');\n\tvar ns = s.replace(/0/, '');\n\tprint( ns.length != s.length ? ns : s.replace(/1/, '') );\n\n}).call(this);", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const str = readLine();\n let found = false;\n let res = \"\";\n\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (char === \"0\" && !found) {\n found = true;\n continue;\n }\n res += char;\n }\n\n if (!found) console.log(res.slice(0, -1));\n else console.log(res);\n}\n"}, {"source_code": "function main(){\n\nvar num = readline();\nvar length = num.length;\n\nvar zloc=-1;\n\nfor(i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var m = new Map();\n var h = [];\n for(j = 0; j < n; j++){\n if(m.get(a[j]) === 0){\n m.set(a[j], 1);\n }else{\n var temp = m.get(a[j]);\n temp++;\n m.set(a[j], temp);\n }\n }\n for(j = 1; j <= n; j++){\n if(j <= m.size){\n h.push(m.size);\n }else{\n var x = h[h.length - 1];\n h.push(x + 1);\n }\n }\n var ans = '';\n for(j = 0; j < h.length; j++){\n ans += h[j] + ' ';\n }\n console.log(ans);\n }\n }\n});", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const size = new Set(a).size;\r\n const res = new Array(n);\r\n for (let i = 0; i < size; i++) {\r\n res[i] = size;\r\n }\r\n for (let i = size; i < n; i++) {\r\n var _res;\r\n res[i] = ((_res = res[i - 1]) !== null && _res !== void 0 ? _res : 0) + 1;\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n \n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (n, arr)=>{\n let ans = [];\n arr.sort((a,b)=>a-b);\n let cnt = new Map();\n for (let i=0; i=0)\n nn--;\n }\n l('ans')\n return ans.reverse();\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let n = +readline()\n let arr = ra();\n print(calc(n, arr).join(' '));\n }\n}\n \nE.calc = calc;"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n var k = readline().split(' ').map(Number);\r\n var len = Array.from(new Set(k)).length;\r\n var res = k.map((el, i) => Math.max(i + 1, len)).join(' ');\r\n print(res);\r\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n\n for(let i = 0; i < fileContents.length; i+=2){\n const setDiff = new Set()\n const powerUps = fileContents[i+1]\n // console.log(\"powerUps\",powerUps)\n const splitPow = powerUps.split(\" \")\n\n splitPow.forEach(type => {\n if(!setDiff.has(type)) {\n setDiff.add(type)\n }\n })\n\n let output = []\n\n for(let k = 1; k <= splitPow.length; k++){\n const add = k <= setDiff.size ? setDiff.size : k\n output.push(add)\n\n }\n\n console.log(output.join(\" \"))\n }\n\n}\n\n"}], "negative_code": [{"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n\n for(let i = 0; i < fileContents.length; i+=2){\n const setDiff = new Set()\n const powerUps = fileContents[i+1]\n console.log(\"powerUps\",powerUps)\n powerUps.split(\" \").forEach(type => {\n setDiff.add(type)\n })\n\n let output = \"\"\n\n for(let k = 1; k <= powerUps.split(\" \").length; k++){\n const add = k <= setDiff.size ? setDiff.size : k\n output+=add\n if(powerUps.length != k){\n output+=\" \"\n }\n\n }\n\n console.log(output)\n }\n\n}\n\n"}], "src_uid": "06212223295c56a78a5d4e55c53a63e0"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const gs = Array(1001).fill(0).map(() => [])\n arr.forEach(([h, w]) => {\n gs[h].push(w)\n })\n for (let i = 0; i < gs.length; i++) {\n gs[i].sort((a, b) => a - b)\n const sum = []\n if (gs[i].length) {\n sum[0] = gs[i][0]\n for (let j = 1; j < gs[i].length; j++) {\n sum[j] = sum[j - 1] + gs[i][j]\n }\n }\n gs[i].sum = sum\n }\n // console.log(gs[999])\n const query = []\n qs.forEach(([hs, ws, hb, wb], i) => {\n query.push([hs, -1, i])\n query.push([hb - 1, 1, i])\n })\n // console.log(query)\n const ans = Array(qs.length).fill(0)\n const F = Array(1e3 + 5).fill(0) // a little larger in case\n let hnow = 0\n query.sort((a, b) => a[0] - b[0])\n .forEach(([h, d, i]) => {\n while (hnow < h) {\n hnow++\n gs[hnow].forEach(w => {\n inc(F, w, w * hnow)\n })\n }\n // console.log(hnow)\n const [hs, ws, hb, wb] = qs[i]\n if (wb - 1 > ws) {\n ans[i] += d * (sum(F, wb - 1) - sum(F, ws))\n }\n // console.log(ans[i], F.slice(0, 6), sum(F, wb - 1), sum(F, ws))\n })\n return ans.join('\\n')\n}\nfunction inc(F, idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(F, idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split(' ');\r\n var n = inp[0];\r\n var q = inp [1];\r\n\r\n var matr = [];\r\n for (var i = 0; i < 1001; i++) {\r\n matr.push(new Array(1001).fill(0));\r\n }\r\n\r\n for (var i = 0; i < n; i++) {\r\n var rect = readline().split(' ');\r\n matr[rect[0]][rect[1]] += rect[0] * rect[1];\r\n }\r\n\r\n var s = matr;\r\n for (var i = 1; i < 1001; i++) {\r\n for (var j = 1; j < 1001; j++) {\r\n s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + s[i][j];\r\n }\r\n }\r\n\r\n for (var i = 0; i < q; i++) {\r\n var query = readline().split(' ');\r\n var hs = query[0] - (-1);\r\n var ws = query[1] - (-1);\r\n var hb = query[2] - 1;\r\n var wb = query[3] - 1;\r\n\r\n if (hs > hb || ws > wb) {\r\n print(0);\r\n } else {\r\n var ans = s[hb][wb] - s[hs-1][wb] - s[hb][ws-1] + s[hs-1][ws-1];\r\n\r\n print(ans);\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const gs = Array(1001).fill(0).map(() => [])\n arr.forEach(([h, w]) => {\n gs[h].push(w)\n })\n for (let i = 0; i < gs.length; i++) {\n gs[i].sort((a, b) => a - b)\n const sum = []\n if (gs[i].length) {\n sum[0] = gs[i][0]\n for (let j = 1; j < gs[i].length; j++) {\n sum[j] = sum[j - 1] + gs[i][j]\n }\n }\n gs[i].sum = sum\n }\n // console.log(gs[999])\n return qs.map(([hs, ws, hb, wb]) => {\n let r = 0\n for (let h = hs + 1; h < hb; h++) {\n if (!gs[h].length) continue\n const i = binarySearch(0, gs[h].length - 1, x => {\n return !(ws < gs[h][x])\n }) + 1\n const j = binarySearch(0, gs[h].length - 1, x => {\n return gs[h][x] < wb\n })\n // r += j - i + 1\n // console.log(i, j, gs[h])\n r += h * range(gs[h].sum, i, j)\n }\n return r\n }).join('\\n')\n //\n function range(sum, i, j) {\n return sum[j] - (sum[i - 1] || 0)\n }\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "9e9c7434ebf0f19261012975fe9ee7d0"} {"source_code": "s=readline().split(' ')\nn=+s[0]\nx=+s[1]\nsum=0\na=readline().split(' ').map(function(q){sum+=+q;})\nif (sum+n==x+1)\n{\n print(\"YES\")\n}\nelse\n{\n print(\"NO\")\n}", "positive_code": [{"source_code": "var n_x =readline().split(' ');\nvar sum=0;\nreadline().split(' ').map(q=>sum+=Number(q));\nprint(sum+Number(n_x[0])-1==Number(n_x[1])?\"Yes\":\"No\");"}], "negative_code": [{"source_code": "var n_x =readline().split(' ');\nvar sum=0;\nreadline().split(' ').map(q=>sum+=(q));\nprint(sum+(n_x[0])-1==(n_x[1])?\"Yes\":\"No\");"}], "src_uid": "080a3458eaea4903da7fa4cf531beba2"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar pointNum = parseInt(readline());\n\tvar xLine = [], yLine = [];\n\tfor (var i = 0; i < 101; ++i) {\n\t\txLine.push(0);\n\t\tyLine.push(0);\n\t}\n\n\tfor (var i = 0; i < pointNum; ++i) {\n\t\tvar point = tokenizeIntegers(readline());\n\t\tvar x = point[0], y = point[1];\n\t\txLine[x] = 1;\n\t\tyLine[y] = 1;\n\t}\n\n\tvar xSum = 0, ySum = 0;\n\tfor (var i = 0; i < 101; ++i) {\n\t\txSum += xLine[i];\n\t\tySum += yLine[i];\n\t}\n\tprint(Math.min(xSum, ySum));\n}\n\nmain();\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet count = 0;\nlet linesCount = 0;\nconst lines = [];\nrl.on('line', (line) => {\n if (count != linesCount - 1) {\n if (linesCount == 0) {\n linesCount = parseInt(line);\n } else {\n lines.push(line.split(' '));\n count++;\n }\n } else {\n lines.push(line.split(' '));\n const linesData = {\n x: [],\n y: []\n }\n for (let i = 0; i < lines.length; i++) {\n if (linesData.x.indexOf(lines[i][0]) == -1) linesData.x.push(lines[i][0])\n if (linesData.y.indexOf(lines[i][1]) == -1) linesData.y.push(lines[i][1])\n }\n console.log(linesData.x.length >= linesData.y.length ? linesData.y.length : linesData.x.length);\n }\n})\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet count = 0;\nlet linesCount = 0;\nconst lines = [];\nrl.on('line', (line) => {\n if (count != linesCount - 1) {\n if (linesCount == 0) {\n linesCount = parseInt(line);\n } else {\n lines.push(line.split(' '));\n count++;\n }\n } else {\n lines.push(line.split(' '));\n const xes = [];\n const ys = [];\n for (let i = 0; i < lines.length; i++) {\n if (xes.indexOf(lines[i][0]) == -1) xes.push(lines[i][0])\n if (ys.indexOf(lines[i][1]) == -1) ys.push(lines[i][1])\n }\n console.log(xes.length >= ys.length ? ys.length : xes.length);\n }\n})\n\n"}], "negative_code": [], "src_uid": "89a8936bf7d43a9c5f69714a7cb7df82"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n t = parseInt(lines[0])\r\n let line = 1\r\n for (let i = 1; i <= t; i++) {\r\n const n = parseInt(lines[line].split(' ')[0], 10)\r\n \r\n console.log(n % 2 == 0 ? 2 : 3);\r\n line++\r\n }\r\n}\r\n", "positive_code": [{"source_code": "length = +readline();\r\n\r\nwhile (length--) {\r\n n = +readline();\r\n\r\n print(7);\r\n}\r\n\r\n"}, {"source_code": "length = +readline();\r\n\r\nwhile (length--) {\r\n n = +readline();\r\n \r\n if (n === 2) {\r\n print(7);\r\n continue;\r\n }\r\n\r\n print(3);\r\n}\r\n\r\n"}, {"source_code": "var n = readline();\r\nfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n) {\r\n if(n == 2) {\r\n print(2);\r\n } else {\r\n print(3);\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n begin(n);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n if (n === 2) return 2;\r\n return 3;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var t = readline();\r\n console.log(t);\r\n}"}], "negative_code": [{"source_code": "length = +readline();\r\n\r\nwhile (length--) {\r\n n = +readline();\r\n \r\n if (n === 2) {\r\n print(7);\r\n break;\r\n }\r\n\r\n print(3);\r\n}\r\n\r\n"}, {"source_code": "length = +readline();\r\n\r\nwhile (length--) {\r\n n = +readline();\r\n \r\n if (n === 2) {\r\n print(7);\r\n break\r\n }\r\n\r\n print(3)\r\n}\r\n\r\n"}, {"source_code": "length = +readline();\r\n\r\nwhile (length--) {\r\n n = +readline();\r\n m = 3;\r\n\r\n print(m);\r\n}\r\n\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n if(n===2) console.log(4);\r\n else console.log(3);\r\n }\r\n})"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n) {\r\n if(n == 2) {\r\n print(n+2);\r\n } else {\r\n print(n+3);\r\n }\r\n \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n begin(n);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n if (n === 2) return 2;\r\n return n + 1;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "b7e36ca8a96dd7951359070d4953beec"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let dec = false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i] < arr[i-1]) dec= true;\r\n }\r\n output(dec ? 'YES' : 'NO');\r\n }\r\n}\r\n", "positive_code": [{"source_code": "var t = readline()\r\nwhile(t--) {\r\n var test = readline()\r\n var test1 = readline().split(' ')\r\n print(taskContext1(test1))\r\n \r\n}\r\n \r\n \r\nfunction taskContext1(arr) {\r\n \r\n var test = arr.slice(0);\r\n arr.sort((a,b) => a-b);\r\n for(var i = 0; i parseInt(w))\r\n var inf = 100000000000;\r\n var nef = -100000000000;\r\n var mn = []\r\n //var mx = []\r\n for(var i=a.length-1;i>=0;i--) {\r\n \tmn[i] = Math.min(inf, a[i])\r\n \t//mx[i] = Math.max(nef, a[i])\r\n }\r\n inf = 1000000000000;\r\n nef = -1000000000000;\r\n var ans = true;\r\n for(var i=0;i mn[i]) {\r\n \t\tans = false;\r\n \t\tbreak;\r\n \t}\r\n }\r\n console.log(ans ? 'NO' : 'YES');\r\n}"}, {"source_code": "var t = +readline()\r\nfor(var index = 0; index a-b);\r\n for(var i = 0; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var yes = true;\n var k = lines[j].split(' ').map(Number);\n for(var l = 1; l < e; l++){\n if(k[l] < k[l - 1]){\n yes = false;\n }\n }\n if(yes === true){\n console.log('NO');\n }else{\n console.log('YES');\n }\n }\n }\n}); "}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var n = readline();\r\n var ar = readline().split(\" \").map(w => parseInt(w))\r\n var f = []\r\n var s = []\r\n for(var i=1;i parseInt(w))\r\n var f = []\r\n var s = []\r\n for(var i=1;i a-b);\r\n for(var i = 0; i a-b);\r\nprint(len)\r\n for(var i = 0; i0;--i)\n\t{\n\t\tif(vis[i+1] x - y);\nconst d = [];\n \nfor(let i = 0; i < a.length; i++) {\n if (!d[a[i]-1] && a[i] !== 1) d[a[i]-1] = true;\n else if (!d[a[i]]) d[a[i]] = true;\n else if (!d[a[i]+1]) d[a[i]+1] = true;\n}\nwrite(d.slice(1).reduce((r, i) => i ? r + 1 : r, 0));"}, {"source_code": "'use strict'\n \nlet n = parseInt(readline());\nlet w = 0;\nconst a = readline().split(' ').map(Number).sort((x, y) => x - y);\n\nfor(let i = 0; i < a.length; i++) {\n if(a[i] < w) n--;\n else w = Math.max(a[i] - 1, w + 1);\n}\nwrite(n);"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/*\n * Complete the simpleArraySum function below.\n */\n\nfunction addMapKey(map, key) {\n // console.log(key, map[key]) \n if (!map[key - 1] && (key - 1) > 0) { \n map[key - 1] = 1;\n map[key]--;\n if (!map[key])\n delete map[key];\n }\n if (map[key] > 1) {\n if (!map[key + 1]) map[key + 1] = 0; \n map[key + 1] += map[key] - 1;\n map[key] = 1;\n }\n}\n\nfunction simpleArraySum(ar) {\n const map = {};\n ar.forEach(el => {\n el = Number(el)\n if (!map[el]) {\n map[el] = 0;\n }\n map[el]++;\n });\n \n const mapKeys = Object.keys(map).map(el => Number(el)).sort((a,b) => a-b);\n mapKeys.forEach(key => {\n key = Number(key);\n addMapKey(map, key);\n })\n // console.log(map)\n return Object.keys(map).length;\n}\n\nfunction main() {\n const arCount = parseInt(readLine(), 10);\n\n const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));\n\n let result = simpleArraySum(ar);\n\n console.log(result)\n}\n"}, {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction check(quota, size) {\n var used = new Array(size + 1).fill(0);\n var x = 0;\n // console.log(\"Testing\", size, \"|\", quota);\n for (var i = size + 1; i > 0; i--) {\n // console.log(i, used);\n if (used[i + 1] < quota[i + 1]) {\n used[i + 1]++;\n x++;\n continue;\n }\n if (used[i] < quota[i]) {\n used[i]++;\n x++;\n continue;\n }\n if (used[i - 1] < quota[i - 1]) {\n used[i - 1]++;\n x++;\n continue;\n }\n }\n\n print(x);\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n // prep\n var quota = new Array(n + 1).fill(0);\n values.forEach(function(i) {\n quota[i] = quota[i] ? quota[i] + 1 : 1;\n });\n //x\n\n // calculation\n check(quota, 150001);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "'use strict'\n \nreadline();\nconst a = readline().split(' ').map(Number).sort((x, y) => x - y);\nconst d = [];\n\nfor(let i = 0; i < a.length; i++) {\n if (!d[a[i]-1]) d[a[i]-1] = true;\n else if (!d[a[i]]) d[a[i]] = true;\n else if (!d[a[i]+1]) d[a[i]+1] = true;\n}\nwrite(d.slice(1).reduce((r, i) => i ? r + 1 : r, 0));"}, {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction check(quota, size) {\n var used = new Array(size + 1).fill(0);\n for (var i = size; i > 0; i--) {\n if (used[i + 1] < quota[i + 1]) {\n used[i + 1]++;\n continue;\n }\n if (used[i] < quota[i]) {\n used[i]++;\n continue;\n }\n if (i > 0 && used[i - 1] < quota[i - 1]) {\n used[i - 1]++;\n continue;\n }\n\n return false;\n }\n return true;\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n // prep\n var quota = new Array(n + 1).fill(0);\n values.forEach(function(i) {\n quota[i] = quota[i] ? quota[i] + 1 : 1;\n });\n //x\n\n // calculation\n for (var i = n; i > 0; i--) {\n if (check(quota, i)) {\n print(i);\n return;\n }\n }\n\n print(0);\n}\n\nmain();\n"}, {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction check(quota, size) {\n var used = new Array(size + 1).fill(0);\n var x = 0;\n // console.log(\"Testing\", size, \"|\", quota);\n for (var i = size + 1; i > 0; i--) {\n // console.log(i, used);\n if (used[i + 1] < quota[i + 1]) {\n used[i + 1]++;\n x++;\n continue;\n }\n if (used[i] < quota[i]) {\n used[i]++;\n x++;\n continue;\n }\n if (used[i - 1] < quota[i - 1]) {\n used[i - 1]++;\n x++;\n continue;\n }\n }\n\n print(x);\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n // prep\n var quota = new Array(n + 1).fill(0);\n values.forEach(function(i) {\n quota[i] = quota[i] ? quota[i] + 1 : 1;\n });\n //x\n\n // calculation\n check(quota, n);\n}\n\nmain();\n"}, {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction check(quota, size) {\n var used = new Array(size + 1).fill(0);\n for (var i = size; i >= 0; i--) {\n if (used[i + 1] < quota[i + 1]) {\n used[i + 1]++;\n continue;\n }\n if (used[i] < quota[i]) {\n used[i]++;\n continue;\n }\n if (i > 0 && used[i - 1] < quota[i - 1]) {\n used[i - 1]++;\n continue;\n }\n\n return false;\n }\n return true;\n}\n\nfunction main() {\n // get input\n var read = input();\n var n = read[0];\n var values = read[1];\n\n // prep\n var quota = new Array(n + 1).fill(0);\n values.forEach(function(i) {\n quota[i] = quota[i] ? quota[i] + 1 : 1;\n });\n //x\n\n // calculation\n for (var i = n; i > 0; i--) {\n if (check(quota, i)) {\n print(i);\n return;\n }\n }\n\n print(0);\n}\n\nmain();\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/*\n * Complete the simpleArraySum function below.\n */\n\nfunction addMapKey(map, key) { \n if (map[key] > 1 && !map[key + 1]) {\n map[key + 1] = 1;\n map[key]--;\n }\n if (map[key] > 1 && !map[key - 1] && (key - 1) > 0) {\n map[key - 1] = 1;\n map[key]--;\n }\n}\n\nfunction simpleArraySum(ar) {\n const map = {};\n ar.forEach(el => {\n el = Number(el)\n if (!map[el]) {\n map[el] = 0;\n }\n map[el]++;\n });\n \n const mapKeys = Object.keys(map).sort();\n mapKeys.forEach(key => {\n key = Number(key);\n addMapKey(map, key);\n })\n return Object.keys(map).length;\n}\n\nfunction main() {\n const arCount = parseInt(readLine(), 10);\n\n const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));\n\n let result = simpleArraySum(ar);\n\n console.log(result)\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/*\n * Complete the simpleArraySum function below.\n */\n\nfunction addMapKey(map, key) { \n if (!map[key - 1] && (key - 1) > 0) { \n map[key - 1] = 1;\n map[key]--;\n if (!map[key])\n delete map[key];\n }\n if (map[key] > 1) { \n map[key + 1] += map[key] - 1;\n map[key] = 1;\n }\n}\n\nfunction simpleArraySum(ar) {\n const map = {};\n ar.forEach(el => {\n el = Number(el)\n if (!map[el]) {\n map[el] = 0;\n }\n map[el]++;\n });\n \n const mapKeys = Object.keys(map).map(el => Number(el)).sort((a,b) => a-b);\n mapKeys.forEach(key => {\n key = Number(key);\n addMapKey(map, key);\n })\n return Object.keys(map).length;\n}\n\nfunction main() {\n const arCount = parseInt(readLine(), 10);\n\n const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));\n\n let result = simpleArraySum(ar);\n\n console.log(result)\n}\n"}], "src_uid": "41215d764f10c025bf18a70b6215aecf"} {"source_code": "var getNums = function () {\n return readline().split(' ').map(function (a) { return parseInt(a) });\n};\n\n\n//137B\n//Local attempts - 1\n//Sent attempts - 1\nvar n = parseInt(readline());\nvar data = getNums();\nvar hash = {};\nfor (var i = 1; i <= n; i++) {\n hash[i] = 0; \n}\ndata.forEach(d => hash[d]++);\nvar res = 0;\nObject.keys(hash).forEach(h => {\n if (hash[h] === 0) {\n res++;\n }\n});\nprint(res);", "positive_code": [{"source_code": "var up = Number(readline());\nvar nums = readline().split(' ');\nnums = nums.map(function(a){\n return Number(a);\n});\nnums.sort();\nnum_count = up;\nvar result = 0;\nvar last = null;\nfor (var i in nums) {\n if (nums[i] > up || nums[i] === last)\n result++;\n else\n last = nums[i];\n}\nprint(result)\n"}, {"source_code": "(function() {\n var ch, count, i, map, max, res;\n readline();\n ch = readline().split(\" \").map(Number);\n max = ch.length;\n map = {};\n res = 0;\n ch.forEach(function(num) {\n if (map[num]) {\n return map[num]++;\n } else {\n return map[num] = 1;\n }\n });\n for (i in map) {\n count = map[i];\n if (count !== 1) {\n res += count - 1;\n }\n if (+i > max) {\n res += 1;\n }\n }\n write(res);\n}).call(this);\n\n"}, {"source_code": "var n = +readline();\nprint(n - readline().split(' ').map(Number).sort(function(a, b) {\n\treturn a - b;\n}).filter(function(v, i, a) {\n\treturn v !== a[i - 1] && v <= n;\n}).length);"}, {"source_code": "var n= parseInt(readline().trim());\nvar a= readline().trim().split(' ').map((x)=>parseInt(x));\n\nvar sa = new Set(a);\n\nvar na = Array.from(sa)\n\nvar ans = a.length - na.length;\n\n\nans+=na.filter((x)=>!(x>=1 && x<=n)).length;\n\nprint(ans);"}, {"source_code": ";(function () {\n\tfor (var i = 0, n = +readline(), m = new Array(n); i < n; i++) m[i] = false;\n\treadline().split(' ').forEach(function (e, i, a) { m[e - 1] = true; });\n\tprint(m.filter(function (e, i, a) { return !e; }).length);\n}).call(this)"}], "negative_code": [{"source_code": "var up = Number(readline());\nvar nums = readline().split(' ');\nnums = nums.map(function(a){\n return Number(a);\n});\nnums.sort();\nnum_count = up;\nvar result = 0;\nvar last = null;\nfor (var i in nums) {\n if (nums[i] > up || nums[i] === last)\n result++;\n else\n last = i;\n}\nprint(result)\n"}, {"source_code": "(function() {\n var ch, count, i, map, res;\n readline();\n ch = readline().split(\" \").map(Number);\n map = {};\n res = 0;\n ch.forEach(function(num) {\n if (map[num]) {\n return map[num]++;\n } else {\n return map[num] = 1;\n }\n });\n for (i in map) {\n count = map[i];\n if (count !== 1) {\n res += count - 1;\n }\n }\n write(res);\n}).call(this);\n\n"}, {"source_code": "(function() {\n var ch, count, i, map, max, res;\n readline();\n ch = readline().split(\" \").map(Number);\n max = ch.length;\n map = {};\n res = 0;\n ch.forEach(function(num) {\n if (map[num]) {\n return map[num]++;\n } else {\n return map[num] = 1;\n }\n });\n for (i in map) {\n count = map[i];\n if (count !== 1) {\n res += count - 1;\n } else {\n if (i > max) {\n res += 1;\n }\n }\n }\n write(res);\n}).call(this);\n\n"}, {"source_code": "(function() {\n var ch, count, i, map, max, res;\n readline();\n ch = readline().split(\" \").map(Number);\n max = ch.length;\n map = {};\n res = 0;\n ch.forEach(function(num) {\n if (map[num]) {\n return map[num]++;\n } else {\n return map[num] = 1;\n }\n });\n for (i in map) {\n count = map[i];\n if (count !== 1) {\n res += count - 1;\n } else {\n if (+i > max) {\n res += 1;\n }\n }\n }\n write(res);\n}).call(this);\n\n"}], "src_uid": "bdd86c8bc54bbac6e2bb5a9d68b6eb1c"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main)\n\nfunction main() {\n const n = parseInt(stdin[0])\n const sizes = stdin[1].split(' ').map(s => parseInt(s))\n const sizeMap = new Map()\n sizeMap.set(0, [0, 0]) //default\n sizes.forEach((size, position) => {\n if (sizeMap.has(size)) {\n sizeMap.get(size).push(position)\n } else {\n sizeMap.set(size, [position])\n }\n })\n \n let movement = 0\n for(let size = 1; size <= n; size++) {\n const prevPos = sizeMap.get(size-1)\n const pos = sizeMap.get(size)\n movement = movement + Math.abs(prevPos[0]-pos[0]) + Math.abs(prevPos[1]-pos[1])\n }\n \n console.log(movement)\n}", "positive_code": [{"source_code": "let rawInput = '';\nprocess.stdin.on('data', c => rawInput += c);\nlet inputByLinesOnResolve = new Promise((resolve, reject) => {\n process.stdin.on('end', () => {\n const { EOL } = require('os');\n resolve(rawInput.split(EOL));\n });\n});\n\n\n(async function(){\n\n let lines = await inputByLinesOnResolve;\n let n = parseInt(lines[0]);\n let nn = n << 1;\n let tierInHouse = lines[1].split(\" \").map(tier => parseInt(tier));\n \n let availableTiers = new Array(nn);\n\n for (let i = 0; i < nn; ++i) {\n if (!availableTiers[tierInHouse[i]]) {\n availableTiers[tierInHouse[i]] = Array(2);\n availableTiers[tierInHouse[i]][0] = i;\n } else {\n availableTiers[tierInHouse[i]][1] = i;\n }\n }\n\n let currentPosition1 = 0;\n let currentPosition2 = 0;\n let distance = 0;\n let Abs = x => (x < 0) ? (-x) : x;\n for (let i = 1; i <= n; ++i) {\n \n distance += Abs(currentPosition1 - availableTiers[i][0]);\n distance += Abs(currentPosition2 - availableTiers[i][1]);\n currentPosition1 = availableTiers[i][0];\n currentPosition2 = availableTiers[i][1];\n }\n\n console.log(distance);\n\n})();"}], "negative_code": [{"source_code": "let rawInput = '';\nprocess.stdin.on('data', c => rawInput += c);\nlet inputByLinesOnResolve = new Promise((resolve, reject) => {\n process.stdin.on('end', () => {\n const { EOL } = require('os');\n resolve(rawInput.split(EOL));\n });\n});\n\n\n(async function(){\n\n let lines = await inputByLinesOnResolve;\n let n = parseInt(lines[0]);\n let nn = n << 1;\n let tierInHouse = lines[1].split(\" \").map(tier => parseInt(tier));\n \n let availableTiers = new Array(nn);\n\n for (let i = 0; i < nn; ++i) {\n if (!availableTiers[tierInHouse[i]]) {\n availableTiers[tierInHouse[i]] = Array(2);\n availableTiers[tierInHouse[i]][0] = i;\n } else {\n availableTiers[tierInHouse[i]][1] = i;\n }\n }\n\n let currentPosition1 = 0;\n let currentPosition2 = 0;\n let distance = 0;\n let Abs = x => (x < 0) ? (-x) : x;\n for (let i = 1; i < n; ++i) {\n \n distance += Abs(currentPosition1 - availableTiers[i][0]) + 1;\n distance += Abs(currentPosition2 - availableTiers[i][1]) + 1;\n currentPosition1 = availableTiers[i][0];\n currentPosition2 = availableTiers[i][1];\n }\n\n console.log(distance);\n\n})();"}, {"source_code": "let rawInput = '';\nprocess.stdin.on('data', c => rawInput += c);\nlet inputByLinesOnResolve = new Promise((resolve, reject) => {\n process.stdin.on('end', () => {\n const { EOL } = require('os');\n resolve(rawInput.split(EOL));\n });\n});\n\n\n(async function(){\n\n let lines = await inputByLinesOnResolve;\n let n = parseInt(lines[0]);\n let nn = n << 1;\n let tierInHouse = lines[1].split(\" \").map(tier => parseInt(tier));\n \n let availableTiers = new Array(nn);\n\n for (let i = 0; i < nn; ++i) {\n if (!availableTiers[tierInHouse[i]]) {\n availableTiers[tierInHouse[i]] = Array(2);\n availableTiers[tierInHouse[i]][0] = i;\n } else {\n availableTiers[tierInHouse[i]][1] = i;\n }\n }\n\n let currentPosition1 = 1;\n let currentPosition2 = 1;\n let distance = 0;\n let Abs = x => (x < 0) ? (-x) : x;\n for (let i = 1; i < n; ++i) {\n \n let distance0 = Abs(currentPosition1 - availableTiers[i][0]) + 1;\n let distance1 = Abs(currentPosition1 - availableTiers[i][1]) + 1;\n\n let distance2 = Abs(currentPosition2 - availableTiers[i][0]) + 1;\n let distance3 = Abs(currentPosition2 - availableTiers[i][1]) + 1;\n\n if ((distance0 + distance3) < (distance1 + distance2)) {\n distance += distance0 + distance3;\n currentPosition1 = availableTiers[i][0];\n currentPosition2 = availableTiers[i][1];\n } else {\n distance += distance1 + distance2;\n currentPosition1 = availableTiers[i][1];\n currentPosition2 = availableTiers[i][0];\n }\n }\n\n console.log(distance);\n\n})();"}, {"source_code": "let rawInput = '';\nprocess.stdin.on('data', c => rawInput += c);\nlet inputByLinesOnResolve = new Promise((resolve, reject) => {\n process.stdin.on('end', () => {\n const { EOL } = require('os');\n resolve(rawInput.split(EOL));\n });\n});\n\n\n(async function(){\n\n let lines = await inputByLinesOnResolve;\n let n = parseInt(lines[0]);\n let nn = n << 1;\n let tierInHouse = lines[1].split(\" \").map(tier => parseInt(tier));\n \n let availableTiers = new Array(n + 1);\n\n for (let i = 0; i < nn; ++i) {\n if (!availableTiers[tierInHouse[i]]) {\n availableTiers[tierInHouse[i]] = Array(2);\n availableTiers[tierInHouse[i]][0] = i + 1;\n } else {\n availableTiers[tierInHouse[i]][1] = i + 1;\n }\n }\n \n \n let Abs = x => (x < 0)?(-x):x;\n\n function goForTiers(currentPosition) {\n \n let distance = 0;\n for (let i = 1; i < n; ++i) {\n \n let newPosition0 = 20000000;\n let newPosition1 = 20000000;\n \n if (availableTiers[i][0] != -1) { newPosition0 = availableTiers[i][0]; } \n if (availableTiers[i][1] != -1) { newPosition1 = availableTiers[i][1]; }\n let distance0 = Abs(currentPosition - newPosition0) + 1;\n let distance1 = Abs(currentPosition - newPosition1) + 1;\n \n if (distance0 < distance1) {\n availableTiers[i][0] = -1;\n distance += distance0;\n currentPosition = newPosition0;\n } else {\n availableTiers[i][1] = -1;\n distance += distance1;\n currentPosition = newPosition1;\n }\n }\n \n return distance;\n };\n\n console.log(goForTiers(1) + goForTiers(1));\n\n})();"}], "src_uid": "dc9c2703aa7aaf1d254211cf06030329"} {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n\r\n let arr = new Array(m*n);\r\n let c = 0;\r\n let d1, d2, d3, d4;\r\n for(let j =0; ja-b)\r\n for(let el of arr)\r\n process.stdout.write(`${el} `);\r\n console.log()\r\n }\r\n}", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < m; j++) {\r\n\t\t\t\tans.push(Math.max(n-1-i, i) + Math.max(m-1-j, j));\r\n\t\t\t}\r\n\t\t}\r\n\t\tans.sort((x, y) => x - y);\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t//-------------------------------------------------------------//\r\n\tlet t = inputReader.readNumber();\r\n\t//let t = 1;\r\n\t\r\n\tfunction solve() {\r\n\t let [n, m] = inputReader.readNumberArray();\r\n\t let dist = [];\r\n\t for (let i = 0; i < n; i++) {\r\n\t for (let j = 0; j < m; j++) {\r\n\t let distance = Math.max(i, n - i - 1) + Math.max(j, m - j - 1);\r\n\t dist.push(distance);\r\n\t }\r\n\t }\r\n\t dist.sort((a, b) => {\r\n\t if(a > b) return 1;\r\n\t else if(a == b) return 0;\r\n\t else return -1;\r\n\t });\r\n\t\r\n\t console.log(dist.join(\" \"));\r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\t\r\n\t//--------------------------------------------------------//\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}, {"source_code": " var t = parseInt(readline());\r\n function solve(){\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var n = inp[0]\r\n var m = inp[1]\r\n var arr = []\r\n for (var i = 0; i < n; ++i)\r\n for (var j = 0; j < m; ++j)\r\n arr.push(Math.max(i, n - i - 1) + Math.max(j, m - j - 1));\r\n\r\n arr.sort((a,b) =>{\r\n if(a>b){\r\n return 1\r\n }else if(a < b){\r\n return -1\r\n }else{\r\n return 0\r\n }\r\n })\r\n return arr.join(\" \")\r\n }\r\n\r\nwhile(t--){\r\n print(solve())\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n const getmax = (i, j) => {\r\n let p1 = Math.abs(1 - i) + Math.abs(1 - j);\r\n let p2 = Math.abs(1 - i) + Math.abs(m - j);\r\n let p3 = Math.abs(n - i) + Math.abs(1 - j);\r\n let p4 = Math.abs(n - i) + Math.abs(m - j);\r\n return Math.max(p1, p2, p3, p4);\r\n };\r\n let res = [],\r\n i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n let k = 0,\r\n l = m - 1;\r\n if (i !== j) {\r\n while (k <= l) {\r\n if (k === l) {\r\n res.push(getmax(i + 1, k + 1));\r\n res.push(getmax(j + 1, k + 1));\r\n } else {\r\n res.push(getmax(i + 1, k + 1));\r\n res.push(getmax(j + 1, k + 1));\r\n res.push(getmax(i + 1, l + 1));\r\n res.push(getmax(j + 1, l + 1));\r\n }\r\n k++;\r\n l--;\r\n }\r\n } else {\r\n while (k <= l) {\r\n if (k === l) res.push(getmax(i + 1, k + 1));\r\n else {\r\n res.push(getmax(i + 1, k + 1));\r\n res.push(getmax(i + 1, l + 1));\r\n }\r\n k++;\r\n l--;\r\n }\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(res.sort((a, b) => a - b).join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n const getmax = (i, j) => {\r\n let p1 = Math.abs(1 - i) + Math.abs(1 - j);\r\n let p2 = Math.abs(1 - i) + Math.abs(n - j);\r\n let p3 = Math.abs(n - i) + Math.abs(j - 1);\r\n let p4 = Math.abs(n - i) + Math.abs(m - j);\r\n return Math.max(p1, p2, p3, p4);\r\n };\r\n let res = [],\r\n i = 0,\r\n j = n - 1;\r\n while (i <= j) {\r\n let k = 0,\r\n l = m - 1;\r\n while (k <= l) {\r\n res.push(getmax(i + 1, k + 1));\r\n if (k !== l || i !== j) res.push(res[res.length - 1]);\r\n if (k !== l && i !== j) {\r\n res.push(getmax(i + 1, l + 1));\r\n res.push(res[res.length - 1]);\r\n }\r\n k++;\r\n l--;\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(res.reverse().join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "dc1dc5e5dd17d19760c772739ce244a7"} {"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst _fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));\n }\n return r;\n};\n \nconst fn = (x) => {\n if (gt(x[0], `${Number.MAX_SAFE_INTEGER}`) && x[1].length < 3) return _fn(x);\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');", "positive_code": [{"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst _fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));\n }\n return r;\n};\n \nconst fn = (x) => {\n if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);\n if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);\n if (x[0] === '9999999999999983' && x[1] === '16') return _fn(x);\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst _fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));\n }\n return r;\n};\n \nconst fn = (x) => {\n if (parseInt(x[0]) > Number.MAX_SAFE_INTEGER && x[1].length < 3 && +x[1] % 8 === 0) return _fn(x);\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}], "negative_code": [{"source_code": "'use strict'\n\nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n\nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n\n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n\n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n\nconst del = (a, b) => {\n let r = '';\n const lenB = b.length;\n\n while (gt(a, b, true)) {\n const l = lenB + +!gt(a.slice(0, lenB), b);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n a = aB + a.slice(l);\n r += `${i}`;\n }\n return r || '0';\n};\n\nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n\n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));\n }\n return r;\n};\n\nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');\n"}, {"source_code": "'use strict'\n\nconst fn = (x) => {\n const n = x[0], m = x[1];\n const K = Math.floor(n / m);\n const k = K % 10;\n const k10 = (K - k) / 10;\n \n let r10 = 0;\n for (let i = 1; i < 10; i++) {\n r10 += (i * m) % 10;\n }\n let r = 0;\n for (let i = 1; i <= k; i++) {\n r += (i * m) % 10;\n }\n \n return r10 * k10 + r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ').map(Number)) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 755) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst fn = (x) => {\n const m = x[1] % 10, k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1)\n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '7050080492234632 1792069373270308') {\n write(fn(first.split(' ').map(x => parseInt(x))) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ').map(x => parseInt(x))) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 145) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst MAX = `${Number.MAX_SAFE_INTEGER}`;\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst minus = (a, b, zero) => {\n if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst del = (a, b) => {\n if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst plus = (a, b) => {\n a = a.split('').map(Number).reverse();\n b = b.split('').map(Number).reverse();\n let mem = 0, c = 0, i = 0;\n for(i = 0; i < b.length; i++) {\n c = (a[i] || 0) + b[i] + mem;\n if (c > 9) { c = c % 10; mem = 1;}\n else { mem = 0; }\n a[i] = c;\n }\n while (mem) {\n c = (a[i] || 0) + mem;\n if (c === 10) { a[i] = 0; mem = 1;}\n else { a[i] = c; mem = 0; }\n i++;\n }\n return a.reverse().join('');\n}\n \nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (gt(x[1], x[0])) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));\n }\n return r;\n};\n \nlet test = 0;\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n const x = readline();\n if (x === '575154303 436759189') test = 205;\n if (!test) write(fn(x.split(' ')) + '\\n');\n else if (i > test) write(i + ' : ' + x);\n}\n"}, {"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst _fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));\n }\n return r;\n};\n \nconst fn = (x) => {\n if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);\n if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 10000;\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 85) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 88) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst fn = (x) => {\n const n = x[0], m = x[1], k = Math.floor(n / m);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1)\n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ').map(Number)) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = `${Number.MAX_SAFE_INTEGER}`;\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst minus = (a, b, zero) => {\n if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n\nconst del = (a, b) => {\n if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst plus = (a, b) => {\n a = a.split('').map(Number).reverse();\n b = b.split('').map(Number).reverse();\n let mem = 0, c = 0, i = 0;\n for(i = 0; i < b.length; i++) {\n c = (a[i] || 0) + b[i] + mem;\n if (c > 9) { c = c % 10; mem = 1;}\n else { mem = 0; }\n a[i] = c;\n }\n while (mem) {\n c = (a[i] || 0) + mem;\n if (c === 10) { a[i] = 0; mem = 1;}\n else { a[i] = c; mem = 0; }\n }\n return a.reverse().join('');\n}\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (gt(x[1], x[0])) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));\n }\n return r;\n};\n \nlet test = 0;\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n const x = readline();\n if (x === '575154303 436759189') test = 205;\n if (!test) write(fn(x.split(' ')) + '\\n');\n else if (i > test) write(i + ' : ' + x);\n}"}, {"source_code": "'use strict'\n\nconst fn = (x) => {\n const n = x[0], m = x[1], k = Math.floor(n / m);\n let r = 0;\n\n for (let i = 1; i < 10; i++) { r += (i * m) % 10; }\n r *= Math.floor(k / 10);\n \n for (let i = 1; i <= k % 10; i++) { r += (i * m) % 10; }\n \n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ').map(Number)) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = `${Number.MAX_SAFE_INTEGER}`;\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst minus = (a, b, zero) => {\n if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n\nconst del = (a, b) => {\n if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst plus = (a, b) => {\n a = a.split('').map(Number).reverse();\n b = b.split('').map(Number).reverse();\n let mem = 0, c = 0, i = 0;\n for(i = 0; i < b.length; i++) {\n c = (a[i] || 0) + b[i] + mem;\n if (c > 9) { c = c % 10; mem = 1;}\n else { mem = 0; }\n a[i] = c;\n }\n while (mem) {\n c = (a[i] || 0) + mem;\n if (c === 10) { a[i] = 0; mem = 1;}\n else { a[i] = c; mem = 0; }\n }\n return a.reverse().join('');\n}\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (gt(x[1], x[0])) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));\n }\n return r;\n};\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = `${Number.MAX_SAFE_INTEGER}`;\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst minus = (a, b, zero) => {\n if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst del = (a, b) => {\n if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst plus2 = (a, b) => {\n a = a.split('').map(Number).reverse();\n b = b.split('').map(Number).reverse();\n let mem = 0, c = 0, i = 0;\n for(i = 0; i < b.length; i++) {\n c = a[i] + b[i] + mem;\n if (c > 9) { c = c % 10; mem = 1;}\n else { mem = 0; }\n a[i] = c;\n }\n while (mem) {\n c = a[i] + mem;\n if (c === 10) { a[i] = 0; mem = 1;}\n else { a[i] = c; mem = 0; }\n }\n return a.reverse().join('');\n}\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (gt(x[1], x[0])) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, plus2(k, `${10 - i}`).slice(-1)));\n }\n return r;\n};\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \n\nconst fn = (x) => {\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 208) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 185) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}\n"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 60) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}\n"}, {"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n\nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst _fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));\n }\n return r;\n};\n\nconst fn = (x) => {\n if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x)\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ')) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ')) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 920) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}\n"}, {"source_code": "'use strict'\n \nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n\nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst del = (a, b) => {\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));\n }\n return r;\n};\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1)\n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n if (x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '9999999999999904 9999999999999921') {\n write(fn(first.split(' ').map(x => parseInt(x))) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ').map(x => parseInt(x))) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n if (i > 60) write(i + ' : ' + readline().split(' ') + '\\n');\n else readline();\n}"}, {"source_code": "'use strict'\n \nconst MAX = `${Number.MAX_SAFE_INTEGER}`;\n \nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n \nconst minus = (a, b, zero) => {\n if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n \nconst plus = (a, b) => {\n if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n \n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n \n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\n \nconst del = (a, b) => {\n if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;\n if(!gt(a, b, true)) return '0';\n\tconst lA = a.length\n const lB = b.length;\n const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);\n while (gt(a, b, true)) {\n const l = lB + +!gt(a.slice(0, lB), b, true);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n if (i) r[a.length - l] = i;\n a = `${aB}${a.slice(l)}`.replace(/^0+/, '')\n }\n return r.reverse().join('');\n};\n \nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n \nconst plus2 = (a, b) => {\n a = a.split('').map(Number).reverse();\n b = b.split('').map(Number).reverse();\n let mem = 0, c = 0, i = 0;\n for(i = 0; i < b.length; i++) {\n c = (a[i] || 0) + b[i] + mem;\n if (c > 9) { c = c % 10; mem = 1;}\n else { mem = 0; }\n a[i] = c;\n }\n while (mem) {\n c = (a[i] || 0) + mem;\n if (c === 10) { a[i] = 0; mem = 1;}\n else { a[i] = c; mem = 0; }\n }\n return a.reverse().join('');\n}\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (gt(x[1], x[0])) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n \n for (let i = 1; i < 10; i++) {\n r = ((x, y) => y ? plus2(r, times(x, y)) : r)(i * m % 10, plus2(k, `${10 - i}`).slice(0, -1));\n }\n return r;\n};\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "\n'use strict'\n \nconst fn = (x) => {\n const m = x[1] % 10, k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1)\n }\n return r;\n}\n \nconst n = parseInt(readline());\nconst first = readline();\nif (first !== '7050080492234632 1792069373270308') {\n write(fn(first.split(' ').map(x => parseInt(x))) + '\\n');\n for (let i = n - 1; i; i--)\n write(fn(readline().split(' ').map(x => parseInt(x))) + '\\n');\n} else {\n for (let i = 0; i < n - 1; i++)\n write(i + ' : ' + readline().split(' ') + '\\n');\n}"}, {"source_code": "'use strict'\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > Number.MAX_SAFE_INTEGER / 100) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);\n }\n return `${r}`.slice(0, -4) + `${R}`.slice(-4); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n\nconst fn = (x) => {\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n \nconst MAX = Number.MAX_SAFE_INTEGER;\n \nconst fn = (x) => {\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * m % 10 * (Math.floor((k - i)/10) + 1);\n }\n if (r > MAX) {\n let R = 0;\n for (let i = 1; i < 10; i++) {\n R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;\n }\n return `${r}`.slice(0, -3) + `${R}`.slice(-3); \n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');"}, {"source_code": "'use strict'\n\nconst minus = (a, b, zero) => {\n if (a === b) return zero;\n const lA = a.length;\n const lB = b.length;\n if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;\n};\n\nconst plus = (a, b) => {\n const lA = a.length;\n const lB = b.length;\n if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;\n\n const a15 = parseInt(a.slice(-15));\n const b15 = parseInt(b.slice(-15));\n\n const s15 = `${a15 + b15}`;\n const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);\n return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;\n};\nconst gt = (a, b, ifEqual) => {\n if (a === b) return !!ifEqual;\n const lA = a.length;\n const lB = b.length;\n if (lA > lB) return true;\n if (lA < lB) return false;\n if (lA < 15) return parseInt(a) > parseInt(b);\n const a15 = parseInt(a.slice(0, 15));\n const b15 = parseInt(b.slice(0, 15));\n if (a15 > b15) return true;\n if (a15 < b15) return false;\n return parseInt(a.slice(15)) > parseInt(b.slice(15));\n};\n\nconst del = (a, b) => {\n let r = '';\n const lenB = b.length;\n\n while (gt(a, b, true)) {\n const l = lenB + +!gt(a.slice(0, lenB), b);\n let i = 0, aB = a.slice(0, l);\n while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }\n a = aB + a.slice(l);\n r += `${i}`;\n }\n return r;\n};\n\nconst times = (a, b) => {\n let r = '0';\n for (let i = 0; i < a; i++) r = plus(r, b);\n return r;\n};\n\nconst fn = (x) => {\n if (x[0] === x[1]) return x[1][x[1].length - 1];\n if (x[0].length === x[1].length && x[0] < x[1]) return 0;\n const m = parseInt(x[1][x[1].length - 1]);\n const k = del(x[0], x[1]);\n let r = '0';\n\n for (let i = 1; i < 10; i++) {\n r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));\n }\n return r;\n};\n\nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ')) + '\\n');\n"}, {"source_code": "'use strict'\n \nconst fn = (x) => {\n const n = x[0], m = x[1], k = Math.floor(n / m);\n let r = 0;\n \n for (let i = 1; i < 10; i++) {\n r += i * (m % 10) % 10 * (Math.floor((k - i)/10) + 1)\n }\n return r;\n}\n \nfor (let i = parseInt(readline()); i; i--)\n write(fn(readline().split(' ').map(Number)) + '\\n');"}], "src_uid": "9964bfdcfdd041b839ce120019e8220f"} {"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s));\nlet n = _in[0], m = _in[1];\n_in = Array.from(readline().trim());\nlet a = new Int8Array(n + 2);\na[0] = a[n + 1] = 1;\nfor (let i = 0; i < n; i++) {\n a[i + 1] = _in[i] == '.' ? 0 : 1;\n}\nlet ans = 0;\nlet state = 1;\nfor (let i = 1; i <= n; i++) {\n if (state == 0) {\n if (a[i] == 0) {\n ans++;\n state = 0;\n } else {\n state = 1;\n }\n } else {\n if (a[i] == 0) {\n state = 0;\n } else {\n state = 1;\n }\n }\n}\n\nwhile (m--) {\n _in = readline().split(/\\s+/);\n let i = parseInt(_in[0]), c = _in[1] == '.' ? 0 : 1;\n if (a[i] == c) {\n print(ans);\n continue;\n }\n a[i] = c;\n if (c == 0) {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans += 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans += 1;\n } else {\n ans += 0;\n }\n } else {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans -= 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans -= 1;\n } else {\n ans -= 0;\n }\n }\n print(ans);\n}\n", "positive_code": [{"source_code": "\nfunction main() {\n var n, m, s;\n var x = [], c = [];\n \n read();\n solve();\n \n function read() {\n var toks;\n var i;\n \n toks = readline().split(\" \");\n n = parseInt(toks[0]), m = parseInt(toks[1]);\n s = readline();\n s = (\"#\" + s + \"#\").split(\"\");\n \n for (i = 0; i < m; ++i) {\n toks = readline().split(\" \");\n x.push(parseInt(toks[0]));\n c.push(toks[1]);\n }\n }\n \n function solve() {\n var num_p, num_s;\n var dots;\n var i;\n \n dots = false;\n num_p = num_s = 0;\n for (i = 1; i <= n; ++i) {\n if (s[i] == '.') {\n ++num_p;\n if (!dots)\n dots = true, ++num_s;\n }\n else if (dots)\n dots = false;\n }\n \n for (i = 0; i < m; ++i) {\n if (c[i] == \".\" && s[x[i]] != \".\") {\n ++num_p;\n if (s[x[i] - 1] == \".\" && s[x[i] + 1] == \".\") --num_s;\n if (s[x[i] - 1] != \".\" && s[x[i] + 1] != \".\") ++num_s;\n }\n else if (c[i] != \".\" && s[x[i]] == \".\") {\n --num_p;\n if (s[x[i] - 1] == \".\" && s[x[i] + 1] == \".\") ++num_s;\n if (s[x[i] - 1] != \".\" && s[x[i] + 1] != \".\") --num_s;\n }\n \n s[x[i]] = c[i];\n print(num_p - num_s);\n }\n }\n}\n\nmain();\n"}, {"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s));\nlet n = _in[0], m = _in[1];\n_in = Array.from(readline().trim());\nlet a = new Int8Array(n + 2);\na[0] = a[n + 1] = 1;\nfor (let i = 0; i < n; i++) {\n a[i + 1] = _in[i] == '.' ? 0 : 1;\n}\nlet ans = 0;\nlet state = 1;\nfor (let i = 1; i <= n; i++) {\n if (state == 0) {\n if (a[i] == 0) {\n ans++;\n state = 0;\n } else {\n state = 1;\n }\n } else {\n if (a[i] == 0) {\n state = 0;\n } else {\n state = 1;\n }\n }\n}\n\nlet buf = [];\nwhile (m--) {\n _in = readline().split(/\\s+/);\n let i = parseInt(_in[0]), c = _in[1] == '.' ? 0 : 1;\n if (a[i] == c) {\n buf.push(ans);\n continue;\n }\n a[i] = c;\n if (c == 0) {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans += 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans += 1;\n } else {\n ans += 0;\n }\n } else {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans -= 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans -= 1;\n } else {\n ans -= 0;\n }\n }\n buf.push(ans);\n}\nprint(buf.join('\\n'))\n"}, {"source_code": "\nfunction main() {\n var n, m, s;\n var x = [], c = [];\n \n read();\n solve();\n \n function read() {\n var toks;\n var i;\n \n toks = readline().split(\" \");\n n = parseInt(toks[0]), m = parseInt(toks[1]);\n s = readline();\n s = (\"#\" + s + \"#\").split(\"\");\n \n for (i = 0; i < m; ++i) {\n toks = readline().split(\" \");\n x.push(parseInt(toks[0]));\n c.push(toks[1]);\n }\n }\n \n function solve() {\n var res = [];\n var num_p, num_s;\n var dots;\n var i;\n \n dots = false;\n num_p = num_s = 0;\n for (i = 1; i <= n; ++i) {\n if (s[i] == '.') {\n ++num_p;\n if (!dots)\n dots = true, ++num_s;\n }\n else if (dots)\n dots = false;\n }\n \n for (i = 0; i < m; ++i) {\n if (c[i] == \".\" && s[x[i]] != \".\") {\n ++num_p;\n if (s[x[i] - 1] == \".\" && s[x[i] + 1] == \".\") --num_s;\n if (s[x[i] - 1] != \".\" && s[x[i] + 1] != \".\") ++num_s;\n }\n else if (c[i] != \".\" && s[x[i]] == \".\") {\n --num_p;\n if (s[x[i] - 1] == \".\" && s[x[i] + 1] == \".\") ++num_s;\n if (s[x[i] - 1] != \".\" && s[x[i] + 1] != \".\") --num_s;\n }\n \n s[x[i]] = c[i];\n res.push(num_p - num_s);\n }\n \n for (i = 0; i < m; ++i)\n print(res[i]);\n }\n}\n\nmain();\n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0], m = input[1];\nvar str = readline().split('');\nvar groups = 0;\nvar current = 0;\nvar f = 0;\nfor (var i = 0; i < n; i++) {\n if (str[i] == '.') {f++; current++;}\n if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {\n groups++;\n current = 0;\n }\n}\nstr.splice(0,0,'a');\nstr.splice(str.length, 0, 'a');\nwhile (m--) {\n input = readline().split(' '), idx = parseInt(input[0]), c = input[1];\n var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));\n if (changed) {\n if (str[idx] != '.') f++;\n if (str[idx] == '.') f--;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.') groups++;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.') groups++;\n } \n str[idx] = c;\n write(f-groups, '\\n');\n}\n"}], "negative_code": [{"source_code": "'use strict';\nlet _in = readline().split(/\\s+/).map((s) => parseInt(s));\nlet n = _in[0], m = _in[1];\n_in = Array.from(readline().trim());\nlet a = new Int8Array(n + 2);\na[0] = a[n + 1] = 1;\nfor (let i = 0; i < n; i++) {\n a[i + 1] = _in[i] == '.' ? 0 : 1;\n}\nlet ans = 0;\nlet state = 1;\nfor (let i = 1; i <= n; i++) {\n if (state == 0) {\n if (a[i] == 0) {\n ans++;\n state = 0;\n } else {\n state = 1;\n }\n } else {\n if (a[i] == 0) {\n state = 0;\n } else {\n state = 1;\n }\n }\n}\n\nlet buf = [];\nwhile (m--) {\n _in = readline().split(/\\s+/);\n let i = parseInt(_in[0]), c = _in[1] == '.' ? 0 : 1;\n if (a[i] == c) {\n print(ans);\n continue;\n }\n a[i] = c;\n if (c == 0) {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans += 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans += 1;\n } else {\n ans += 0;\n }\n } else {\n if (a[i - 1] == 0 && a[i + 1] == 0) {\n ans -= 2;\n } else if (a[i - 1] == 0 || a[i + 1] == 0) {\n ans -= 1;\n } else {\n ans -= 0;\n }\n }\n buf.push(ans);\n}\nprint(buf.join('\\n'))\n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0], m = input[1];\nvar str = readline().split('');\nvar groups = 0;\nvar current = 0;\nvar f = 0;\nfor (var i = 0; i < n; i++) {\n if (str[i] == '.') {f++; current++;}\n if ((str[i] != '.' && i < n-1 && current > 0) || (str[i] =='.' && i == n-1)) {\n groups++;\n current = 0;\n }\n}\nstr.splice(0,0,'a');\nstr.splice(str.length, 0, 'a');\nwhile (m--) {\n input = readline().split(' '), idx = parseInt(input[0]), c = input[1];\n var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));\n if (changed) {\n if (str[idx] != '.') f++;\n if (str[idx] == '.') f--;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.') groups++;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.') groups++;\n } \n str[idx] = c;\n write(f-groups, '\\n');\n}\n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0], m = input[1];\nvar str = readline().split('');\nvar groups = 0;\nvar current = 0;\nvar f = 0;\nfor (var i = 0; i < n; i++) {\n if (str[i] == '.') {f++; current++;}\n if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {\n groups++;\n current = 0;\n }\n}\nstr.splice(0,0,'a');\nstr.splice(str.length, 0, 'a');\nwhile (m--) {\n write(f, groups, f-groups, '\\n');\n input = readline().split(' '), idx = parseInt(input[0]), c = input[1];\n var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));\n if (changed) {\n if (str[idx] != '.') f++;\n if (str[idx] == '.') f--;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.') groups++;\n if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.') groups--;\n if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.') groups++;\n } \n str[idx] = c;\n write(f, groups, f-groups, '\\n');\n write(f-groups, '\\n');\n}\n"}], "src_uid": "68883ab115882de5cf77d0848b80b422"} {"source_code": "print(function(x, y, a, b) {\n\tvar ans = [];\n\n\tfor (var i = Math.max(a,b+1); i <= x; i++)\n\t\tfor (var j = b, l = Math.min(i-1,y); j <= l; j++)\n\t\t\tans.push(i + ' ' + j);\n\n\treturn ans.length + (ans.length > 0 ? '\\n' + ans.join('\\n') : '');\n\n} .apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": ";(function () {\n\n\tprint(function (x, y, a, b) {\n\t\tvar n = 0, r = [];\n\n\t\twhile (b <= y) {\n\t\t\tvar _a = Math.max(a, b), _b = b;\n\t\t\twhile (_a <= x) {\n\t\t\t\tif (_a > _b) {\n\t\t\t\t\tr.push([_a, _b]);\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t\t_a++;\n\t\t\t}\n\t\t\tb++;\n\t\t}\n\n\t\treturn n + '\\n' + r.sort(function (a, b) { return (a[0] - b[0])*1000 + a[1] - b[1]; }).map(function (e) { return e.join(' '); }).join('\\n');\n\t}.apply(0, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tx = data[0], y = data[1], a = data[2], b = data[3],\n\t\tlines = [];\n\tfor (var i = Math.max(a, b+1); i <= x; ++i) {\n\t\tfor (var j = b; j < i; ++j) {\n\t\t\tif (j > y) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlines.push(i+' '+j);\n\t\t}\n\t}\n\tprint(lines.length);\n\tif (lines.length != 0) {\n\t\tprint(lines.join('\\n'));\n\t}\n}\n\nmain();\n"}, {"source_code": "print(function(x, y, a, b) {\n\tvar ans = [];\n\n\tfor (var i = Math.max(a,b+1); i <= x; i++)\n\t\tfor (var j = b, l = Math.min(i-1,y); j <= l; j++)\n\t\t\tans.push(i + ' ' + j);\n\n\tans.unshift(ans.length);\n\n\treturn ans.join('\\n');\n\n} .apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(x, y, a, b) {\n\tvar ans = [];\n\n\tfor (var i = Math.max(a,b+1); i <= x; i++)\n\t\tfor (var j = Math.min(i-1,y); j >= b; j--)\n\t\t\tans.push(i + ' ' + j);\n\n\treturn ans.length + (ans.length > 0 ? '\\n' + ans.join('\\n') : '');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\n\tprint(function (x, y, a, b) {\n\t\tvar n = 0, r = [];\n\n\t\twhile (b <= y) {\n\t\t\tvar _a = Math.max(a, b), _b = b;\n\t\t\twhile (_a <= x) {\n\t\t\t\tif (_a > _b) {\n\t\t\t\t\tr.push([_a, _b]);\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t\t_a++;\n\t\t\t}\n\t\t\tb++;\n\t\t}\n\n\t\treturn n + '\\n' + r.map(function (e) { return e.join(' '); }).join('\\n');\n\t}.apply(0, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": ";(function () {\n\n\tprint(function (x, y, a, b) {\n\t\tvar n = 0, r = [];\n\n\t\twhile (b <= y) {\n\t\t\tvar _a = Math.max(a, b), _b = b;\n\t\t\twhile (_a <= x) {\n\t\t\t\tif (_a > _b) r.push([_a, _b]);\n\t\t\t\t_a++;\n\t\t\t}\n\t\t\tb++;\n\t\t}\n\n\t\treturn n + '\\n' + r.map(function (e) { return e.join(' '); }).join('\\n');\n\t}.apply(0, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tx = data[0], y = data[1], a = data[2], b = data[3],\n\t\tlines = [];\n\tfor (var i = Math.max(a, b+1); i <= x; ++i) {\n\t\tfor (var j = b; j < i; ++j) {\n\t\t\tlines.push(i+' '+j);\n\t\t}\n\t}\n\tprint(lines.length);\n\tif (lines.length != 0) {\n\t\tprint(lines.join('\\n'));\n\t}\n}\n\nmain();\n"}], "src_uid": "bb3e3b51a4eda8fef503952a00777910"} {"source_code": "function getMinSteps (a,b) {\n var countMinSteps = 0;\n \n var pos = Array.apply(null, Array(a+2)).map(Number.prototype.valueOf,0);\n\n for (var i=0; i= value) {\r\n value += (scopeLevel * 2) - 1\r\n scopeLevel++\r\n }\r\n scopeLevel--;\r\n\r\n const scopeStart = value - scopeLevel*2 + 1\r\n const scopeMiddle = value - scopeLevel;\r\n const scopeEnd = value - 1\r\n\r\n let row, column;\r\n\r\n if(k < scopeMiddle) {\r\n row = (k - scopeStart + 1 ) ;\r\n column = scopeLevel;\r\n }\r\n if(k === scopeMiddle) {\r\n row = scopeLevel;\r\n column = scopeLevel;\r\n }\r\n\r\n if(k > scopeMiddle) {\r\n row = scopeLevel;\r\n column = scopeLevel - (k - scopeMiddle);\r\n }\r\n console.log(`${row} ${column}`)\r\n }\r\n }\r\n\r\n\r\n\r\n////////////////////////\r\nlet inputString = '';\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\r\n\r\n main(inputString);\r\n});", "positive_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let number = +input[z++];\r\n if(number == parseInt(Math.sqrt(number))**2){\r\n console.log(Math.sqrt(number), 1);\r\n }\r\n else{\r\n let low = parseInt(Math.sqrt(number))**2;\r\n let high = (parseInt(Math.sqrt(number)) + 1)**2;\r\n let middle = (low + high + 1) / 2;\r\n if(number === middle){\r\n console.log(Math.abs(low - middle), Math.abs(low - middle));\r\n }\r\n else if(number < middle){\r\n console.log(Math.abs(low - number), Math.abs(low - middle));\r\n }\r\n else{\r\n console.log(Math.abs(low - middle), Math.abs(high - number + 1));\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "/****************************************************************\\\r\n NAME: MD. TAHURUZZOHA TUHIN\r\n\\****************************************************************/\r\n\r\n\r\nconst readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet matrix = [];\r\nlet nbr = 0;\r\nlet cnt = 0;\r\nrl.on('line', (line) => {\r\n matrix.push(line.split(' '));\r\n let a = matrix.map(x => parseInt(x));\r\n nbr++;\r\n\r\n if (nbr > a[0]) {\r\n for (let i = 1; i <= a[0]; i++) {\r\n let n = a[i];\r\n let x = 1;\r\n let k = 1;\r\n let r, cc = 0, int;\r\n if (n == 1) {\r\n console.log(1, 1);\r\n continue;\r\n }\r\n while (1) {\r\n cc++;\r\n\r\n if (n >= x && n < x + k) {\r\n int = parseInt(k / 2 + x);\r\n cnt = int;\r\n if (n >= x && n <= cnt) {\r\n r = Math.abs(n - x) + 1;\r\n }\r\n else {\r\n int = parseInt(k / 2 + 1);\r\n r = int;\r\n cc = Math.abs(x + k - n);\r\n }\r\n\r\n console.log(r, cc);\r\n break;\r\n }\r\n x += k;\r\n k += 2;\r\n }\r\n }\r\n\r\n\r\n\r\n\r\n rl.close();\r\n }\r\n\r\n});"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/18/21 morning\r\n * https://codeforces.com/contest/1560/problem/A\r\n */\r\nconst solve = (x) => {\r\n // pr(x)\r\n let i = 1;\r\n for (; i * i < x; i++);\r\n // pr(i, i * i)\r\n if (i * i == x) {\r\n return pr(i, 1);\r\n }\r\n let pre = (i - 1) * (i - 1);\r\n let rest = x - pre;\r\n // pr('pre', pre, 'rest', rest);\r\n // if (rest == 0) return pr(i + 1, i);\r\n if (rest <= i) {\r\n return pr(rest, i);\r\n }\r\n rest -= i;\r\n pr(i, i - rest);\r\n};\r\n\r\n// const cal = (n) => {\r\n// let cnt = (n - 1) / 2 + 1;\r\n// return (1 + n) * cnt / 2;\r\n// };\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n\r\n// pr(cal(1), cal(3), cal(5), cal(7));"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i], num = Math.ceil(Math.sqrt(n)), sq = num * num, d = sq - n;\n var row = 0, cl = 0;\n if(d < num){\n row = num;\n cl = d + 1;\n }else{\n cl = num;\n d -= num;\n d = num - d - 1;\n row = d;\n }\n console.log(row, cl);\n }\n});"}, {"source_code": "let input = ''\r\nprocess.stdin.on('data', c => input += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = input.split(EOL)\r\n const count = parseInt(lines[0]);\r\n for (let i = 1; i <= count; i++) {\r\n const n = parseInt(lines[i]);\r\n compute(n);\r\n }\r\n})\r\n \r\nfunction compute(num) {\r\n if (num === 1) {\r\n console.log('1 1');\r\n return;\r\n }\r\n let lower = -1;\r\n let upper = -1;\r\n for (let s = 1; s < 31623; s++) {\r\n lower = Math.pow(s, 2);\r\n upper = Math.pow(s+1, 2);\r\n if (lower <= num && num <= upper) break;\r\n }\r\n let r = -1;\r\n let c = -1;\r\n if (lower === num) {\r\n r = Math.sqrt(lower);\r\n c = 1;\r\n } else if (upper === num) {\r\n r = Math.sqrt(upper);\r\n c = 1;\r\n } else {\r\n const middle = lower + Math.floor((upper - lower) / 2) + 1;\r\n if (num < middle) {\r\n r = num - lower;\r\n c = Math.sqrt(upper);\r\n } else {\r\n r = Math.sqrt(upper);\r\n c = upper - num + 1;\r\n }\r\n }\r\n\r\n console.log(r, c);\r\n}\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n console.log(solve(n).join(' '))\n }\n// })()\n})\n\nfunction solve(n) {\n const k = Math.floor(Math.sqrt(n))\n const r = n - k * k\n // console.log(n, k, r)\n if (!r) {\n return [k, 1]\n }\n if (r > k) {\n return [k + 1, k + 1 - (r - k - 1)]\n } else {\n return [r, k + 1]\n }\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst k = rn();\r\n\r\n\t\tlet x = Math.floor(Math.sqrt(k-1));\r\n\t\tconst d = k - x*x;\r\n\r\n\t\tlet r, c;\r\n\t\t++x;\r\n\t\tif (d <= x) {\r\n\t\t\tr = d, c = x;\r\n\t\t} else {\r\n\t\t\tr = x, c = 2 * x - d;\r\n\t\t}\r\n\t\t\r\n\t\tconsole.log(r, c);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n // return prompt()\r\n}\r\n\r\nfunction solve() {\r\n // let lis = readline().split(\" \");\r\n // let a, b;\r\n // a = parseInt(lis[0]);\r\n // b = parseInt(lis[1]);\r\n // c = parseInt(lis[2]);\r\n let p = parseInt(readline());\r\n if(p == parseInt(Math.sqrt(p))**2){\r\n return [Math.sqrt(p) , 1]\r\n }\r\n let l = parseInt(Math.sqrt(p))**2;\r\n let h = (parseInt(Math.sqrt(p))+1)**2;\r\n let m = (l+h+1)/2;\r\n if(p == m){\r\n return [l-m , l-m]\r\n }\r\n else if(p < m){\r\n return [l-p , l-m]\r\n }else{\r\n return [l-m , h-p+1]\r\n }\r\n\r\n}\r\nfor (let i = parseInt(readline()); i > 0; i--) {\r\n let [a , b] = solve();\r\n console.log(Math.abs(a),Math.abs(b))\r\n}\r\n"}, {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let k = readInt();\n let c = parseInt(Math.sqrt(k - 1)) + 1;\n while (k - 1 < c * c) c--;\n let r = k - c * c;\n if (r <= c) {\n console.log(r + ' ' + (c + 1));\n }\n else {\n console.log((c + 1) + ' ' + (2 * c - r + 2));\n }\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n"}, {"source_code": "function solve (k) {\n const n = Math.floor(Math.sqrt(k));\n if (n * n === k) {\n return {\n x: n,\n y: 1,\n };\n }\n if (n * n + 1 === k) {\n return {\n x: 1,\n y: n + 1,\n };\n }\n const maxLeft = (n * n + 1 + (n + 1) * (n + 1)) / 2;\n if (k === maxLeft) {\n return {\n x: n + 1,\n y: n + 1,\n };\n }\n if (k > maxLeft) {\n return {\n x: n + 1,\n y: n - (k - maxLeft) + 1,\n };\n }\n if (k < maxLeft) {\n return {\n y: n + 1,\n x: (n + 1) - ((maxLeft - k)),\n };\n }\n}\n\nfunction main(array) {\n const T = array[0];\n for (let i = 0; i < T; i++) {\n const k = parseInt(array[i + 1], 10);\n const { x, y} = solve(k);\n console.log(`${x} ${y}`);\n }\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\n\n main(inputString);\n});\n"}, {"source_code": "const arr = [];\r\nlet add = 1;\r\nlet current = 1;\r\nconst max = Math.pow(10, 9);\r\nwhile(current <= max) {\r\n arr.push(current);\r\n current += add;\r\n add += 2;\r\n}\r\narr.push(current);\r\n\r\nfunction solve() {\r\n const k = Number(read());\r\n let index;\r\n for(let i = arr.length - 1; i >= 0; i--) {\r\n if (arr[i] > k) {\r\n continue;\r\n }\r\n index = i;\r\n break;\r\n }\r\n const x1 = arr[index];\r\n const x3 = arr[index + 1] - 1;\r\n const x2 = ((x1 + x3) >> 1);\r\n if (k === x2) {\r\n write((index + 1) + ' ' + (index + 1));\r\n return;\r\n }\r\n if (k < x2) {\r\n write((k - x1 + 1) + ' ' + (index + 1))\r\n return;\r\n }\r\n write((index + 1) + ' ' + (x3 - k + 1))\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar K = nextInt();\r\n\t\tif(K == 1){\r\n\t\t\tmyout(\"1 1\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar r = 1;\r\n\t\tvar L = -1;\r\n\t\tvar R = -1;\r\n\t\twhile(true){\r\n\t\t\tL = r * r;\r\n\t\t\tR = (r + 1) * (r + 1);\r\n\t\t\tif(L < K && K <= R){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tr++;\r\n\t\t}\r\n\t\tL++;\r\n\t\tvar center = (L + R) / 2;\r\n\t\tvar c;\r\n\t\tif(K >= center){\r\n\t\t\tc = 1 + ((r + 1) * (r + 1) - K);\r\n\t\t\tr++;\r\n\t\t}else{\r\n\t\t\tc = r + 1;\r\n\t\t\tr = r - (center - K) + 1;\r\n\t\t}\r\n\t\tmyout(r + \" \" + c);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n //\r\n // var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var ii = 1\r\n while (ii * ii < n) {\r\n ii++\r\n }\r\n var count = ii * ii\r\n var x = ii\r\n var y = 1\r\n var direction = true\r\n while (count !== n) {\r\n if (direction) y++\r\n if (!direction) x--\r\n count--\r\n if (y === ii) direction = false\r\n }\r\n console.log(x, y)\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve(e) {\r\n let t = Math.max(1, Math.floor(Math.sqrt(e)) - 2)\r\n for (; (t + 1) * (t + 1) <= e; ) t += 1\r\n if (t * t === e) return [t, 1]\r\n let n = e - t * t\r\n return n <= t + 1 ? [n, t + 1] : ((n -= t + 1), [t + 1, t + 1 - n])\r\n}\r\n__main__(function (e) {\r\n const t = e.readLineAsNumber()\r\n for (let n = 1; n <= t; ++n) {\r\n const t = e.readLineAsNumber(),\r\n [n, i] = solve(t)\r\n e.print(n + ' ' + i + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "var t = parseInt(readline());\r\nfor(i=0;i l) {\r\n num -= l;\r\n l = l + 2;\r\n ++x;\r\n }\r\n if (x === num) print(x + ' ' + x);\r\n else if (x < num) print(x + ' ' + (2 * x - num));\r\n else print(num + ' ' + x);\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let number = +input[z++];\r\n if(number == parseInt(Math.sqrt(number))**2){\r\n console.log(Math.sqrt(number), 1);\r\n }\r\n else{\r\n let low = parseInt(Math.sqrt(number))**2;\r\n let high = (parseInt(Math.sqrt(number)) + 1)**2;\r\n let middle = (low + high + 1) / 2;\r\n if(number === middle){\r\n console.log(Math.abs(low - middle), Math.abs(low - middle));\r\n }\r\n else if(number < middle){\r\n console.log(Math.abs(low - number), Math.abs(low - middle));\r\n }\r\n else{\r\n console.log(Math.abs(low - middle), Math.abs(high - middle + 1));\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "/****************************************************************\\\r\n NAME: MD. TAHURUZZOHA TUHIN\r\n\\****************************************************************/\r\n\r\n\r\nconst readline = require('readline');\r\nconst input = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet p = 0, m = 0, cnt = 0;\r\nlet array1 = [];\r\nlet array2 = [];\r\n\r\ninput.on('line', (line) => {\r\n array1.push(line.split(\" \"));\r\n let a = array1[p].map(x => parseInt(x));\r\n p++;\r\n if (p > 0) {\r\n\r\n input.on('line', (line) => {\r\n array2.push(line.split(' '));\r\n let b = array2[m].map(x => parseInt(x));\r\n m++;\r\n if (m > 0) input.close();\r\n\r\n\r\n for (const n of b) {\r\n let x = 1;\r\n let k = 1;\r\n let r, cc = 0, int;\r\n if (n == 1) {\r\n console.log(1, 1);\r\n continue;\r\n }\r\n while (1) {\r\n cc++;\r\n\r\n if (n >= x && n < x + k) {\r\n int = parseInt(k / 2 + x);\r\n cnt = int;\r\n if (n >= x && n <= cnt) {\r\n r = Math.abs(n - x) + 1;\r\n }\r\n else {\r\n int = parseInt(k / 2 + 1);\r\n r = int;\r\n cc = Math.abs(x + k - n);\r\n }\r\n\r\n console.log(r, cc);\r\n break;\r\n }\r\n x += k;\r\n k += 2;\r\n }\r\n }\r\n\r\n })\r\n\r\n }\r\n\r\n})"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/18/21 morning\r\n * https://codeforces.com/contest/1560/problem/A\r\n */\r\nconst solve = (x) => {\r\n // pr(x)\r\n let i = 1;\r\n for (; i * i < x; i++);\r\n // pr(i, i * i)\r\n if (i * i == x) {\r\n return pr(i, 1);\r\n }\r\n let pre = (i - 1) * (i - 1);\r\n let rest = x % pre;\r\n if (rest == 0) return pr(rest + 1, i);\r\n // pr('rest', rest);\r\n if (rest <= i) {\r\n return pr(rest, i);\r\n }\r\n rest -= i;\r\n pr(i, i - rest);\r\n};\r\n\r\n// const cal = (n) => {\r\n// let cnt = (n - 1) / 2 + 1;\r\n// return (1 + n) * cnt / 2;\r\n// };\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n\r\n// pr(cal(1), cal(3), cal(5), cal(7));"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/18/21 morning\r\n * https://codeforces.com/contest/1560/problem/A\r\n */\r\nconst solve = (x) => {\r\n // pr(x)\r\n let i = 1;\r\n for (; i * i < x; i++);\r\n // pr(i, i * i)\r\n if (i * i == x) {\r\n return pr(i, 1);\r\n }\r\n let pre = (i - 1) * (i - 1);\r\n let rest = x % pre;\r\n if (rest <= i) {\r\n return pr(rest, i);\r\n }\r\n rest -= i;\r\n pr(i, i - rest);\r\n};\r\n\r\n// const cal = (n) => {\r\n// let cnt = (n - 1) / 2 + 1;\r\n// return (1 + n) * cnt / 2;\r\n// };\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n\r\n// pr(cal(1), cal(3), cal(5), cal(7));"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n var x = 0;\n while(n > 0){\n var z = n % 10;\n x = Math.max(x, z);\n n /= 10;\n }\n console.log(Math.floor(x));\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n console.log(solve(n))\n }\n// })()\n})\n\nfunction solve(n) {\n const k = Math.floor(Math.sqrt(n))\n const r = n - k * k\n // console.log(n, k, r)\n if (r > k) {\n return [k + 1, k + 1 - (r - k - 1)].join(' ')\n } else {\n return [r, k + 1].join(' ')\n }\n}\n"}], "src_uid": "f8335c59cd05988c8053f138c4df06aa"} {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n let s1=line[++cnt];\r\n let s2=line[++cnt];\r\n let a=[],b=[];\r\n for(let i=0;ib.length)\r\n {\r\n if(a[0]===0) c0=1;\r\n else c1=1;\r\n a.shift();\r\n }\r\n flag=true;\r\n if(b[0]===0)\r\n {\r\n if(c0)\r\n {\r\n a[0]=0;\r\n }\r\n }\r\n else\r\n {\r\n if(c1)\r\n {\r\n a[0]=1;\r\n }\r\n }\r\n for(let i=0;i{return parseInt(x)});\r\n let s1=line[++cnt];\r\n let s2=line[++cnt];\r\n let a=[],b=[];\r\n for(let i=0;ib.length)\r\n {\r\n if(a[0]===0) c0=1;\r\n else c1=1;\r\n a.shift();\r\n }\r\n flag=true;\r\n if(b[0]===0)\r\n {\r\n if(c0)\r\n {\r\n a[0]=0;\r\n }\r\n }\r\n else\r\n {\r\n if(c1)\r\n {\r\n a[0]=1;\r\n }\r\n }\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let a = readline();\r\n let b = readline();\r\n if (a.length === b.length) {\r\n output(a === b ? 'YES' : 'NO');\r\n continue;\r\n }\r\n let p = a.length - b.length + 1;\r\n if (a.slice(p) === b.slice(1)) {\r\n if (a.slice(0, p).includes(b[0])) {\r\n output('YES');\r\n } else {\r\n output('NO');\r\n }\r\n } else {\r\n output('NO');\r\n }\r\n }\r\n}"}, {"source_code": "// ------------------------\r\n// Codeabschnitt, der f\u00fcr die Verarbeitung der Eingabe zust\u00e4ndig ist\r\n'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nconst print = console.log\r\n \r\n// ---------------------------\r\n \r\n/**\r\n * Usage (Linux/Unix): cat input.txt | node index.js \r\n */\r\n \r\nfunction main() {\r\n const testCases = +readline()\r\n \r\n for (let i = 0; i < testCases; i++) {\r\n let len = readline().split(\" \").map(Number)\r\n\r\n let a = readline()\r\n let b = readline()\r\n\r\n let pos = true;\r\n let ind;\r\n for(ind = 0; ind < len[1] - 1; ind++){\r\n if(a[ind + 1 + len[0] - len[1]] != b[ind + 1]){\r\n pos = false;\r\n }\r\n }\r\n\r\n let pos2 = false;\r\n for(let ii = 0; ii < len[0] - len[1] + 1; ii++){\r\n if(a[ii] == b[0]){\r\n pos2 = true;\r\n }\r\n }\r\n\r\n if(!(pos && pos2)){\r\n print(\"NO\")\r\n } else {\r\n print(\"YES\")\r\n }\r\n }\r\n}"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n'use strict';\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() { return inputs.next().value.trim(); };\r\n\r\nasync function solve() {\r\n let [a_length, b_length] = (await read()).split(' ').map(Number)\r\n let dataA = (await read())//.split('').map(Number)\r\n let dataB = (await read())//.split('').map(Number)\r\n\r\n const firstA = dataA.substring(0, dataA.length - dataB.length + 1);\r\n const secondA = dataA.substring(dataA.length - dataB.length + 1);\r\n const firstB = dataB[0];\r\n const secondB = dataB.substring(1);\r\n\r\n if (secondB === secondA && firstA.indexOf(firstB) != -1) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n\r\n}\r\n\r\nasync function main() {\r\n let tasks_amount = parseInt(await read())\r\n for (let i = 0; i < tasks_amount; i++) {\r\n const element = tasks_amount[i];\r\n await solve()\r\n }\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n await main();\r\n\r\n});"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i{return parseInt(x)});\r\n let s1=line[++cnt];\r\n let s2=line[++cnt];\r\n let a=[],b=[];\r\n for(let i=0;ib.length)\r\n {\r\n if(a[0]===0) c0=1;\r\n else c1=1;\r\n a.shift();\r\n }\r\n flag=true;\r\n if(b[0]===0)\r\n {\r\n if(c0)\r\n {\r\n a[0]=0;\r\n }\r\n }\r\n else\r\n {\r\n if(c1)\r\n {\r\n a[0]=1;\r\n }\r\n }\r\n if(a!==b)\r\n {\r\n flag=false;\r\n }\r\n if(flag) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n let s1=line[++cnt];\r\n let s2=line[++cnt];\r\n let a=[],b=[];\r\n for(let i=0;ib.length)\r\n {\r\n if(a[0]===0) c0=1;\r\n else c1=1;\r\n a.shift();\r\n }\r\n flag=true;\r\n if(b[0]===0)\r\n {\r\n if(c0)\r\n {\r\n a[0]=0;\r\n }\r\n }\r\n else\r\n {\r\n if(c1)\r\n {\r\n a[0]=1;\r\n }\r\n }\r\n if(a[0]===b[0])\r\n {\r\n for(let i=1;i{return parseInt(x)});\r\n let s1=line[++cnt];\r\n let s2=line[++cnt];\r\n let a=[],b=[];\r\n for(let i=0;ib.length)\r\n {\r\n if(a[0]===0) c0=1;\r\n else c1=1;\r\n a.shift();\r\n }\r\n flag=true;\r\n if(b[0]===0)\r\n {\r\n if(c0)\r\n {\r\n a[0]=0;\r\n }\r\n }\r\n else\r\n {\r\n if(c1)\r\n {\r\n a[0]=1;\r\n }\r\n }\r\n if(a[0]===b[0])\r\n {\r\n for(let i=1;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let a = readline();\r\n let b = readline();\r\n let firstBIndex = a.length - b.length;\r\n if (a === b) {\r\n output('YES');\r\n continue;\r\n }\r\n if (a.substring(firstBIndex + 1) === b.substring(1)) {\r\n if (a.substring(0, firstBIndex).includes(b[0])) {\r\n output('YES');\r\n } else if (b.length === 1) {\r\n output('YES');\r\n } else {\r\n output('NO');\r\n }\r\n } else {\r\n output('NO');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let a = readline();\r\n let b = readline();\r\n let firstBIndex = a.length - b.length;\r\n if (a === b) {\r\n output('YES');\r\n continue;\r\n }\r\n if (a.substring(firstBIndex + 1) === b.substring(1)) {\r\n if (a.substring(0, firstBIndex).includes(b[0])) {\r\n output('YES');\r\n } else if (b.length === 1) {\r\n output('YES');\r\n } else {\r\n output('NO1');\r\n }\r\n } else {\r\n output('NO2');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let a = readline();\r\n let b = readline();\r\n let firstBIndex = a.length - b.length;\r\n if (a === b) {\r\n output('YES');\r\n continue;\r\n }\r\n if (a.substring(firstBIndex + 1) === b.substring(1)) {\r\n if (a.substring(0, firstBIndex).includes(b[0])) {\r\n output('YES');\r\n } else output('NO');\r\n } else output('NO');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let a = readline();\r\n let b = readline();\r\n let firstBIndex = a.length - b.length;\r\n if (a.substring(firstBIndex + 1) === b.substring(1)) {\r\n if (a.substring(0, firstBIndex).includes(b[0])) {\r\n output('YES');\r\n } else output('NO');\r\n } else output('NO');\r\n }\r\n}\r\n"}, {"source_code": "// ------------------------\r\n// Codeabschnitt, der f\u00fcr die Verarbeitung der Eingabe zust\u00e4ndig ist\r\n'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nconst print = console.log\r\n \r\n// ---------------------------\r\n \r\n/**\r\n * Usage (Linux/Unix): cat input.txt | node index.js \r\n */\r\n \r\nfunction main() {\r\n const testCases = +readline()\r\n \r\n for (let i = 0; i < testCases; i++) {\r\n let len = readline().split(\" \").map(Number)\r\n\r\n let a = readline()\r\n let b = readline()\r\n\r\n let pos = true;\r\n let ind;\r\n for(ind = 0; ind < len[1]; ind++){\r\n if(a[ind + 1 + len[0] - len[1]] != b[ind + 1]){\r\n pos = false;\r\n }\r\n }\r\n\r\n let pos2 = false;\r\n for(let ii = 0; ii < len[0] - ind - 1; ii++){\r\n if(a[ii] == b[0]){\r\n pos2 = true;\r\n }\r\n }\r\n\r\n if(!(pos && pos2)){\r\n print(\"NO\")\r\n } else {\r\n print(\"YES\")\r\n }\r\n }\r\n}"}], "src_uid": "83050a8a4c7b64004681bdadb630292e"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nvar q, nn = 0, n, m , arr = [], ans;\n\nrl.on(\"line\", (line) => {\n\tif (q == null) q = parseInt(line);\n\telse if (nn == 0) {\n\t\tnn = parseInt(line.split(' ')[0]);\n\t\tm = parseInt(line.split(' ')[1]);\n\t\tn = 0;\n\t\tarr = [];\n\t\tans = 1000000000;\n\t}\n\telse {\n\t\tarr.push(line);\n\t\tn ++;\n\t\tif (n == nn) {\n\t\t\tnn = 0;\n\t\t\t// begin to solve\n\t\t\tvar row_cnt = arr.map( row => { \n\t\t\t\tvar cnt = 0;\n\t\t\t\tfor (var i = 0; i < m; i ++) if (row[i] == '*') cnt ++;\n\t\t\t\treturn cnt; \n\t\t\t } );\n\t\t\tvar col_cnt = [];\n\t\t\tfor (var i = 0; i < m; i ++) {\n\t\t\t\tvar cnt = arr.reduce( \n\t\t\t\t\t(pre, nxt) => { if (nxt[i]=='*') return pre+1; else return pre; },\n\t\t\t\t\t0\n\t\t\t\t );\n\t\t\t\t col_cnt.push(cnt);\n\t\t\t}\n\t\t\tfor (var i = 0; i < n; i ++) {\n\t\t\t\tfor (var j = 0; j < m; j ++) {\n\t\t\t\t\tvar tmp = row_cnt[i] + col_cnt[j] - ( arr[i][j] == '*' ? 1 : 0 );\n\t\t\t\t\tans = Math.min(ans, n+m-1-tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconsole.log(ans);\n\n\t\t\t// end of solve\n\t\t\tq --;\n\t\t\tif (q == 0) \n\t\t\t\trl.close();\n\t\t}\n\t}\n});", "positive_code": [{"source_code": "\"use strict\";\n \nvar main = function() {\n var q = +rd();\n while (q-->0) {\n var input = rdAr();\n var n = input[0];\n var m = input[1];\n \n var R = [];\n for (var i = 0; i < n; ++i) {\n R.push(rd());\n }\n \n var H = new Array(m).fill(0);\n var V = [];\n for (var i = 0; i < n; ++i) {\n V.push(0);\n for (var j = 0; j < m; ++j) {\n var isWhite = R[i][j] === '.';\n H[j] += +isWhite;\n V[i] += +isWhite;\n }\n }\n \n var result = +Infinity;\n for (var i = 0; i < n; ++i) {\n for (var j = 0; j < m; ++j) {\n var isWhite = R[i][j] === '.';\n var needToPaint = H[j] + V[i] - (+isWhite);\n result = Math.min(result, needToPaint);\n }\n }\n \n pr(result);\n }\n};\n \nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar prAr = (a) => pr(a.join(' '));\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n \nmain();"}], "negative_code": [], "src_uid": "a1b6a2f4659169e0e818bbdee6d36e76"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nconst sol = () => {\n let line = data.trim().split(/\\n/g);\n let [a, b, c] = line[0].split(/\\s/g).map(Number);\n let n = Number(line[1]);\n let s = line[2].split(/\\s/g).map(Number);\n let ans = 0;\n for(let i of s){\n if (i > b && i < c) {\n ans++;\n }\n }\n \n \n console.log(ans);\n \n};\n \nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nconst sol = () => {\n let line = data.trim().split(/\\n/g);\n let [a, b, c] = line[0].split(/\\s/g).map(Number);\n let ans = line[2].split(/\\s/g).map(Number).reduce((x,y) => x + ((y > b && y < c)?1:0), 0); \n console.log(ans);\n \n};\n \nprocess.stdin.on('end', sol);"}, {"source_code": " var tmp = readline().split(' ').map(x => parseInt(x));\n var a = tmp[0];\n var b = tmp[1];\n var c = tmp[2];\n var n = parseInt(readline());\n var d = readline().split(' ').map(x => parseInt(x));\n print(d.filter(x => x > b && x < c).length);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\nlet a, b, c, n;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n [a, b, c] = d.split(' ').map(Number);\n return;\n }\n\n if (count === 1) {\n n = +d;\n count++;\n return;\n }\n\n const safes = d.split(' ').map(Number);\n let ans = 0;\n\n for (let i = 0; i < safes.length; i++) {\n if (safes[i] > b && safes[i] < c) {\n ans++;\n }\n }\n\n console.log(ans);\n\n count++;\n});\n"}, {"source_code": "/*var c = readline()\nvar ar = []\nvar count = 0\nvar diff=9999999999999999999999999999;\nvar counter =0;\nvar k = readline().split(' ')\n \nfor(i=0,l=k.length;i1)\n { \n l[0]=''\n print(l.join(''))\n }\n\nelse\n{\n print(l.join(''))\n}\n*/\n\nvar k = readline().split(' ').map(x=>parseInt(x))\nvar j = readline().split(' ').map(x=>parseInt(x))\n \nvar c = readline().split(' ').map(x=>parseInt(x))\nvar count =0;\n \n for(var ins=0;insk[2] || c[ins]1)\n { \n l[0]=''\n print(l.join(''))\n }\n\nelse\n{\n print(l.join(''))\n}\n*/\n\nvar k = readline().split('').map(function(x){\n return parseInt(x)}\n )\n var j = readline().split('').map(function(x){\n return parseInt(x)}\n )\n \n var c = readline().split('').map(function(x){\n return parseInt(x)}\n )\nvar count =0;\n for(var out=0;out {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n let a=BigInt(aa[0]);\r\n let b=BigInt(aa[1]);\r\n if(a===b)\r\n {\r\n console.log(0,0);\r\n //cout<<0<<\" \"<<0< dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nconst min = (a, b) => a < b ? a : b;\r\nconst abs = a => a < 0 ? -a : a;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\r\n\t\tif (a == b) { \r\n\t\t\tconsole.log(\"0 0\");\r\n\t\t\tcontinue; \r\n\t\t}\r\n\r\n\t\tconst g = abs(a-b);\r\n\t\tconst mvs = min(a % g, g - a % g);\r\n\t\tconsole.log(g.toString(), mvs.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction solve() {\r\n const [a, b] = readArray(BigInt);\r\n const diff = a > b ? a - b : b - a;\r\n if (diff === 0n) {\r\n write('0 0');\r\n return;\r\n }\r\n const steps1 = a % diff;\r\n const steps2 = diff - steps1;\r\n const steps = steps1 > steps2 ? steps2 : steps1;\r\n write(diff + ' ' + steps);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var [a, b] = lines[l++].trim().split(' ').map(BigInt)\n console.log(solve(a, b).join(' '))\n }\n});\n\nfunction solve(a, b) {\n if (a === b) return [0, 0]\n if (a > b) return solve(b, a)\n\n const d = a > b ? a - b : b - a\n const r = a % d\n if (r > d / 2n) {\n const op = d - r\n return [gcd(a + op, b + op), op]\n } else {\n return [gcd(a - r, b - r), r]\n }\n}\n\nfunction gcd(a, b) {\n if (a === 0n) return b\n if (b === 0n) return a\n\n while (a) {\n const r = b % a\n b = a\n a = r\n }\n return b\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n let a=parseInt(aa[0]);\r\n let b=parseInt(aa[1]);\r\n if(a===b)\r\n {\r\n console.log(0,0);\r\n //cout<<0<<\" \"<<0< {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n let a=parseInt(aa[0]);\r\n let b=parseInt(aa[1]);\r\n if(a===b)\r\n {\r\n console.log(0,0);\r\n //cout<<0<<\" \"<<0< {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n let a=parseInt(aa[0]);\r\n let b=parseInt(aa[1]);\r\n if(a===b)\r\n {\r\n console.log(0,0);\r\n //cout<<0<<\" \"<<0< {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n \r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n a=parseInt(aa[0]);\r\n b=parseInt(aa[1]);\r\n if(a===b)\r\n {\r\n console.log(0,0);\r\n //cout<<0<<\" \"<<0< dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\r\n\t\tif (a == b) { \r\n\t\t\tconsole.log(\"0 0\");\r\n\t\t\tcontinue; \r\n\t\t}\r\n\r\n\t\tconst gcd = Math.abs(a-b);\r\n\t\tconst moves = Math.min(a % gcd, gcd - a % gcd);\r\n\t\tconsole.log(gcd, moves);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\r\n\t\tif (a == b) { \r\n\t\t\tconsole.log(\"0 0\");\r\n\t\t\tcontinue; \r\n\t\t}\r\n\r\n\t\tif ( a > b) [a, b] = [b, a];\r\n\r\n\t\tconst gcd = b - a;\r\n\t\tconst moves = Math.min(a, (gcd - b % gcd) % gcd);\r\n\t\tconsole.log(gcd, moves);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b] = rna();\r\n\r\n\t\tif (a == b) { \r\n\t\t\tconsole.log(\"0 0\");\r\n\t\t\tcontinue; \r\n\t\t}\r\n\r\n\t\tconst gcd = Math.abs(a - b);\r\n\t\tconst moves = Math.min(Math.min(a, b), (gcd - a % gcd) % gcd);\r\n\t\tconsole.log(gcd, moves);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "994a9cb52cf0fdab72be068eab1b27ef"} {"source_code": "const fs = require('fs');\nconst readline = require('readline');\nconst path = require('path')\n\nclass PacketsCounter {\n count = undefined\n\n isInited() {\n return typeof this.count !== 'undefined';\n }\n\n setInitialCount(count) {\n if (this.isInited()) {\n throw new Error('Commands counter is already inited');\n }\n\n this.count = count;\n }\n\n isPacketsLeft() {\n return this.count > 0;\n }\n\n decreaseCounter() {\n this.count--;\n }\n}\n\nclass MonitorsMatcher {\n list = [] // all monitors\n\n addMonitor(monitor) {\n const [w, h] = monitor.split(' ');\n\n this.list.push({ w, h });\n }\n\n countCombinations() {\n let sum = 0;\n\n for (let i = 0; i < this.list.length; i++) {\n const first = this.list[i];\n\n for (let j = i + 1; j < this.list.length; j++) {\n const second = this.list[j];\n\n if (first.h === second.h || first.w === second.h || first.h === second.w || first.w === second.w) {\n sum += 1\n }\n }\n }\n\n return sum;\n }\n}\n\n\n// MAIN\n\nfunction main() {\n const monitorsMatcher = new MonitorsMatcher();\n const commandsCounter = new PacketsCounter();\n // const readStream = fs.createReadStream(path.resolve(__dirname, './input'));\n const readStream = process.stdin;\n\n const lineCallback = (line) => processLine(monitorsMatcher, commandsCounter, line);\n const closeCallback = () => sendAnswer(String(monitorsMatcher.countCombinations()));\n\n initInputRead(readStream, lineCallback, closeCallback);\n}\n\nmain();\n\n// ---\n\nfunction initInputRead(inputInterface, lineCb, closeCb) {\n const readInterface = readline.createInterface({\n input: inputInterface,\n });\n\n readInterface.on('line', line => lineCb(line));\n readInterface.on('close', () => closeCb());\n}\n\nfunction processLine(monitorsMatcher, commandsCounter, line) {\n // first line: init counter\n if (!commandsCounter.isInited()) {\n commandsCounter.setInitialCount(Number(line));\n return;\n }\n\n // exec commands while counter of commands is more than inited in first line\n if (commandsCounter.isPacketsLeft()) {\n monitorsMatcher.addMonitor(line);\n commandsCounter.decreaseCounter();\n return;\n }\n}\n\nfunction sendAnswer(answer) {\n process.stdout.write(answer);\n process.stdout.write('\\n');\n}\n\n\n", "positive_code": [{"source_code": "n = +readline()\r\na = []\r\nb = []\r\n\r\nfor (var i=0;i { return +el; });\r\n w = pair[0];\r\n h = pair[1];\r\n solo.push(w);\r\n if (h != w) {\r\n solo.push(h);\r\n pairs.push([Math.min.apply(null, pair), Math.max.apply(null, pair)]);\r\n }\r\n }\r\n if (count === n) {\r\n console.log(calcEqual(solo) - calcEqual(pairs));\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n if (a !== b) {\r\n ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)\r\n }\r\n else {\r\n ans += (obj[a] || 0)\r\n }\r\n // console.log('i = ' + i + ': ' + ans)\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n if (a !== b) {\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n }\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "let _DEBUG;\r\n\r\nconst fs = require('fs');\r\nconst print = console.log;\r\nconst debug = (x) => {\r\n if (!_DEBUG) return;\r\n let vn = Object.keys(x)[0];\r\n console.error(`${vn}: ${x[vn]}`);\r\n};\r\nconst debugf = !_DEBUG ? () => {} : console.error;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nlet n = +input[0];\r\n\r\nlet s = new Map();\r\nlet hw = new Map();\r\n\r\nlet res = 0n;\r\n\r\nfor (let i = 0; i < n; i++) {\r\n let row = input[i + 1].split(' ').map((x) => +x);\r\n let [x, y] = row;\r\n\r\n // x <= y\r\n if (x > y) {\r\n [x, y] = [y, x];\r\n }\r\n\r\n let a = s.get(x) || 0;\r\n let b = s.get(y) || 0;\r\n let ab = (hw.has(x) && hw.get(x).get(y)) || 0;\r\n if (x == y) {\r\n res += BigInt(a);\r\n } else {\r\n res += BigInt(a + b - ab);\r\n }\r\n\r\n debugf(`${x} ${y} -> ${a} ${b} ${ab}`);\r\n debug({ res });\r\n\r\n s.set(x, (s.get(x) || 0) + 1);\r\n if (x != y) {\r\n s.set(y, (s.get(y) || 0) + 1);\r\n }\r\n\r\n if (!hw.has(x)) {\r\n hw.set(x, new Map());\r\n }\r\n let hw2 = hw.get(x);\r\n hw2.set(y, (hw2.get(y) || 0) + 1);\r\n\r\n debugf(`??? ${x} -> ${s.get(x)}`);\r\n}\r\n\r\nprint(`${res}`);\r\n"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n \r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n \r\nlet count = 0;\r\nlet n = 0;\r\nlet solo = [];\r\nlet pairs = [];\r\nlet values = [];\r\n\r\nfunction calcEqual(a) {\r\n let last = -1;\r\n let res = 0;\r\n let cnt = 0;\r\n a.sort();\r\n for (let i = 0; i < a.length; i++) {\r\n let x = a[i];\r\n if (JSON.stringify(x) === JSON.stringify(last)) {\r\n res += cnt;\r\n cnt += 1;\r\n } else {\r\n cnt = 1;\r\n }\r\n last = x;\r\n }\r\n return res;\r\n}\r\n \r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n n = +line;\r\n } else {\r\n let pair = line.split(' ').map(el => { return +el; });\r\n w = pair[0];\r\n h = pair[1];\r\n solo.push(w);\r\n if (h != w) {\r\n solo.push(h);\r\n pairs.push([Math.min.apply(null, pair), Math.max.apply(null, pair)]);\r\n }\r\n }\r\n if (count === n) {\r\n console.log(calcEqual(solo) - calcEqual(pairs));\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n \r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n \r\nlet count = 0;\r\nlet total = 0;\r\nlet values = [];\r\nlet output = 0;\r\n \r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n total = +line;\r\n } else {\r\n values.push(line);\r\n }\r\n \r\n if (values.length === total) {\r\n \r\n for (let i = 0; i < total; i++) {\r\n let item = values.shift();\r\n \r\n let filtered = values.filter(el => {\r\n let itemSize = item.split(' ');\r\n let itemW = itemSize[0];\r\n let itemH = itemSize[1];\r\n \r\n let elSize = el.split(' ');\r\n let elW = elSize[0];\r\n let elH = elSize[1];\r\n return itemH === elH || itemW === elH || itemW === elW || itemH === elW;\r\n })\r\n \r\n output += filtered.length;\r\n }\r\n \r\n console.log(output);\r\n }\r\n \r\n count++;\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet total = 0;\r\nlet values = [];\r\nlet output = 0;\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n total = +line;\r\n } else {\r\n values.push(line);\r\n }\r\n \r\n if (values.length === total) {\r\n\r\n for (let i = 0; i < total; i++) {\r\n let item = values.shift();\r\n\r\n let filtered = values.filter(el => {\r\n let itemSize = item.split(' ');\r\n let itemW = itemSize[0];\r\n let itemH = itemSize[1];\r\n\r\n let elSize = el.split(' ');\r\n let elW = elSize[0];\r\n let elH = elSize[1];\r\n return itemH === elH || itemW === elH || itemW === elW || itemH === elW;\r\n })\r\n \r\n output += filtered.length;\r\n }\r\n \r\n console.log(output);\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "var readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nvar count_of_monitors\r\nvar monitors_sizes = []\r\nfunction start() {\r\n rl.question(\"\", function(answer) {\r\n count_of_monitors = parseInt(answer)\r\n get_mon()\r\n });\r\n}\r\n\r\nfunction get_monitors() {\r\n rl.question(\"\", function(answer) {\r\n monitors_sizes.push(answer)\r\n count_of_monitors--\r\n get_mon()\r\n });\r\n \r\n}\r\n\r\nfunction get_mon() {\r\n if (count_of_monitors > 0) {\r\n get_monitors()\r\n } else {\r\n get_pairs()\r\n }\r\n}\r\n\r\nfunction factorial(n) {\r\n return (n != 1) ? n * factorial(n - 1) : 1;\r\n}\r\n\r\nfunction get_pairs() {\r\n\r\n var pairs = []\r\n var dubl_pairs = 0\r\n var count = 0\r\n\r\n monitors_sizes = monitors_sizes.sort()\r\n\r\n for (var i = 0; i < monitors_sizes.length; i++) {\r\n if (i >= 0) {\r\n if (monitors_sizes[i] != monitors_sizes[i - 1]) {\r\n count = 0\r\n monitors_sizes.slice(i + 1).filter((size, index) => {\r\n var i_str = monitors_sizes[i].split(\" \")\r\n var index_str = size.split(\" \")\r\n if (parseInt(i_str[0]) == parseInt(index_str[0]) ||\r\n parseInt(i_str[0]) == parseInt(index_str[1]) ||\r\n parseInt(i_str[1]) == parseInt(index_str[0]) ||\r\n parseInt(i_str[1]) == parseInt(index_str[1])) {\r\n pairs.push(`${i_str} - ${index_str}`)\r\n count++\r\n return true\r\n }\r\n })\r\n } else {\r\n count--\r\n dubl_pairs += count\r\n }\r\n }\r\n \r\n }\r\n console.log(pairs.length + dubl_pairs)\r\n \r\n\r\n}\r\n\r\nstart();"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const params = [];\n\n for (let i = 1; i < lines.length; i++) {\n params.push(lines[i].split(' ').map((x) => parseInt(x)));\n }\n\n const recurse = (arr, sum = 0) => {\n if (arr.length < 1) {\n return sum;\n } else {\n const x = arr[arr.length - 1][0];\n const y = arr[arr.length - 1][1];\n for (let i = 0; i < arr.length - 1; i++) {\n if (\n x === params[i][0] ||\n x === params[i][1] ||\n y === params[i][0] ||\n y === params[i][1]\n ) {\n sum++;\n }\n }\n arr.pop();\n return recurse(arr, sum);\n }\n };\n\n console.log(recurse(params, 0));\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const params = [];\n let resSum = 0;\n\n for (let i = 1; i < lines.length; i++) {\n params.push(lines[i].split(' ').map((x) => parseInt(x)));\n }\n\n for (let i = 0; i < params.length - 1; i++) {\n for (let j = i + 1; j < params.length; j++) {\n if (\n params[i][0] === params[j][0] ||\n params[i][0] === params[j][1] ||\n params[i][1] === params[j][0] ||\n params[i][1] === params[j][1]\n ) {\n resSum++;\n }\n }\n }\n\n console.log(resSum);\n});\n"}, {"source_code": "function program(lines) {\n\n const count = Number(lines[0]);\n const heights = new Map();\n const results = new Set();\n\n for (let i = 1; i <= count; i++) {\n\n const [wS, hS] = lines[i].trim().split(' ');\n\n const w = Number(wS.trim());\n if (!heights.has(w)) {\n heights.set(w, new Set());\n }\n\n const wSet = heights.get(w);\n if (!wSet.has(i)) {\n for (const el of wSet) {\n results.add(`${i}-${el}`);\n }\n wSet.add(i);\n }\n\n const h = Number(hS.trim());\n if (!heights.has(h)) {\n heights.set(h, new Set());\n }\n const hSet = heights.get(h);\n if (!hSet.has(i)) {\n for (const el of hSet) {\n results.add(`${i}-${el}`);\n }\n hSet.add(i);\n }\n }\n\n return results.size;\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL)\n console.log(program(lines));\n})"}, {"source_code": "function program(lines) {\n\n const count = Number(lines[0]);\n const heights = new Map();\n\n for (let i = 1; i <= count; i++) {\n\n const [wS, hS] = lines[i].trim().split(' ');\n\n const w = Number(wS.trim());\n if (!heights.has(w)) {\n heights.set(w, new Set());\n }\n heights.get(w).add(i);\n\n const h = Number(hS.trim());\n if (!heights.has(h)) {\n heights.set(h, new Set());\n }\n heights.get(h).add(i);\n }\n\n const results = new Set();\n\n for (const items of heights.values()) {\n for (const first of items) {\n for (const second of items) {\n if (first !== second) {\n results.add(`${first}-${second}`);\n }\n }\n }\n }\n\n return results.size / 2;\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL)\n console.log(program(lines));\n})"}, {"source_code": "const readline = require('readline');\n\nconst data = [];\nlet length = 0;\nlet msgCounter = 0;\nlet pairsCounter = 0;\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction countPairs () {\n for (let i = data.length - 1; i > 0; i--) {\n for (let j = i - 1; j >= 0; j--) {\n if (data[i][0] === data[j][0]\n || data[i][0] === data[j][1]\n || data[i][1] === data[j][1]\n || data[i][1] === data[j][0]) {\n pairsCounter++;\n }\n }\n }\n}\n\nrl.on('line', input => {\n if (length === 0) length = +(input);\n else data.push(input.split(' '));\n\n if (length === msgCounter) {\n countPairs();\n console.log(pairsCounter);\n rl.close();\n } else msgCounter++;\n});"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet content = []\nlet i = 0\n\nfunction B (content) {\n let count = 0;\n for (let current = 0; current < content.length; current++) {\n let [h, w] = content[current]\n for (let next = current + 1; next < content.length; next++) {\n let val = content[next]\n if (val[0] === h || val[0] === w || val[1] === h || val[1] === w) {\n count++\n }\n }\n }\n console.log(count)\n}\n\nrl\n .on('line', value => {\n if (i === 0) {\n i++\n return\n }\n content.push(value.split(' '))\n })\n .on('close', () => {\n B(content)\n })\n\nmodule.exports = B"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n let lines = i.split(EOL);\r\n const itemsLength = lines[0];\r\n lines = lines.slice(1, lines.length - 1);\r\n /****** */\r\n const monitors = [];\r\n lines.forEach(item => {\r\n monitors.push({\r\n width: item.split(' ')[0],\r\n height: item.split(' ')[1]\r\n })\r\n })\r\n let acceptableMonitorsCount = 0;\r\n function checkMonitors(m1, m2) {\r\n let accept = false;\r\n if ( m1.height === m2.height\r\n || m1.width === m2.height\r\n || m1.height === m2.width\r\n || m1.width === m2.width ) {\r\n accept = true;\r\n }\r\n return accept;\r\n }\r\n for (let i = 0; i < itemsLength - 1; i++) {\r\n for (let j = i + 1; j < itemsLength; j++) {\r\n if (checkMonitors(monitors[i], monitors[j])) {\r\n acceptableMonitorsCount++;\r\n }\r\n }\r\n }\r\n\r\n /****** */\r\n console.log(acceptableMonitorsCount);\r\n});\r\n"}, {"source_code": "let _DEBUG;\r\n\r\nconst fs = require('fs');\r\nconst print = console.log;\r\nconst debug = (x) => {\r\n if (!_DEBUG) return;\r\n let vn = Object.keys(x)[0];\r\n console.error(`${vn}: ${x[vn]}`);\r\n};\r\nconst debugf = !_DEBUG ? () => {} : console.error;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nlet n = +input[0];\r\n\r\nlet s = new Map();\r\nlet hw = new Map();\r\n\r\nlet res = 0n;\r\n\r\nfor (let i = 0; i < n; i++) {\r\n let row = input[i + 1].split(' ').map((x) => +x);\r\n let [x, y] = row;\r\n\r\n // x <= y\r\n if (x > y) {\r\n [x, y] = [y, x];\r\n }\r\n\r\n let a = s.get(x) || 0;\r\n let b = s.get(y) || 0;\r\n let ab = (hw.has(x) && hw.get(x).get(y)) || 0;\r\n if (x == y) {\r\n res += BigInt(a);\r\n } else {\r\n res += BigInt(a + b - ab);\r\n }\r\n\r\n debugf(`${x} ${y} -> ${a} ${b} ${ab}`);\r\n debug({ res });\r\n\r\n s.set(x, (s.get(x) || 0) + 1);\r\n if (x != y) {\r\n s.set(y, (s.get(y) || 0) + 1);\r\n }\r\n\r\n if (!hw.has(x)) {\r\n hw.set(x, new Map());\r\n }\r\n let hw2 = hw.get(x);\r\n hw2.set(y, (hw2.get(y) || 0) + 1);\r\n\r\n debugf(`??? ${x} -> ${s.get(x)}`);\r\n}\r\n\r\nprint(`${res}`);\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n if (a !== b) {\r\n ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)\r\n }\r\n else {\r\n ans += (obj[a] || 0)\r\n }\r\n // console.log('i = ' + i + ': ' + ans)\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n if (a !== b) {\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n }\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "var n = readline();\nvar pairs = []\nvar pairsCount = 0\nvar r = 0\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ')\n\n\tr += pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;\n\n\tpairs.push(l)\n}\n\n\nprint(r);"}], "negative_code": [{"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet total = 0;\r\nlet values = [];\r\nlet output = 0;\r\nlet repeats = {};\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n total = +line;\r\n } else {\r\n if (values.includes(line)) {\r\n repeats[line] += 1;\r\n } else {\r\n repeats[line] = 1;\r\n values.push(line);\r\n }\r\n }\r\n \r\n if (values.length === total) {\r\n\r\n for (let i = 0; i < total; i++) {\r\n let item = values.shift();\r\n\r\n let filtered = values.filter(el => {\r\n let itemSize = item.split(' ');\r\n let itemW = itemSize[0];\r\n let itemH = itemSize[1];\r\n\r\n let elSize = el.split(' ');\r\n let elW = elSize[0];\r\n let elH = elSize[1];\r\n return itemH === elH || itemW === elH || itemW === elW || itemH === elW;\r\n })\r\n \r\n let result = filtered.length * repeats[item];\r\n \r\n output += filtered.length;\r\n }\r\n \r\n console.log(output);\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n if (a !== b) {\r\n ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)\r\n }\r\n else {\r\n ans += (obj[a] || 0)\r\n }\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n if (a !== b) {\r\n ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)\r\n }\r\n else {\r\n ans += obj[a]\r\n }\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n let obj = {}\r\n let ans = 0\r\n for (let i = 0; i < n; ++i) {\r\n let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)\r\n let mid = a + '_' + b\r\n ans += obj[a] + obj[b] - obj[mid]\r\n obj[a] = obj[a] ? obj[a] + 1 : 1\r\n obj[b] = obj[b] ? obj[b] + 1 : 1\r\n obj[mid] = obj[mid] ? obj[mid] + 1 : 1\r\n }\r\n console.log(ans)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n \r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n \r\nlet count = 0;\r\nlet n = 0;\r\nlet solo = [];\r\nlet pairs = [];\r\nlet values = [];\r\n\r\nfunction calcEqual(a) {\r\n let last = -1;\r\n let res = 0;\r\n let cnt = 0;\r\n a.sort();\r\n for (let i = 0; i < a.length; i++) {\r\n let x = a[i];\r\n if (JSON.stringify(x) === JSON.stringify(last)) {\r\n res += cnt;\r\n cnt += 1;\r\n } else {\r\n cnt = 1;\r\n }\r\n last = x;\r\n }\r\n return res;\r\n}\r\n \r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n n = +line;\r\n } else {\r\n values.push(line);\r\n }\r\n \r\n if (values.length === n) {\r\n for (let i = 0; i < n; i++) {\r\n let pair = line.split(' ').map(el => { return +el; });\r\n w = pair[0];\r\n h = pair[1];\r\n solo.push(w);\r\n if (h != w) {\r\n solo.push(h);\r\n pairs.push([Math.min.apply(null, pair), Math.max.apply(null, pair)]);\r\n }\r\n }\r\n console.log(calcEqual(solo) - calcEqual(pairs));\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet total = 0;\r\nlet values = [];\r\nlet output = 0;\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n total = +line;\r\n } else {\r\n values.push(line);\r\n }\r\n \r\n if (values.length === total) {\r\n\r\n for (let i = 0; i < total; i++) {\r\n let item = values.shift();\r\n console.log('item', item);\r\n console.log('values', values);\r\n\r\n let filtered = values.filter(el => {\r\n let itemSize = item.split(' ');\r\n let itemW = itemSize[0];\r\n let itemH = itemSize[1];\r\n\r\n let elSize = el.split(' ');\r\n let elW = elSize[0];\r\n let elH = elSize[1];\r\n return itemH === elH || itemW === elH || itemW === elW || itemH === elW;\r\n })\r\n console.log('filtered', filtered);\r\n \r\n output += filtered.length;\r\n }\r\n \r\n console.log(output);\r\n }\r\n\r\n count++;\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\nconst fs = require('fs');\r\n\r\nconst readInterface = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n console: false\r\n});\r\n\r\nlet count = 0;\r\nlet total = 0;\r\nlet values = [];\r\nlet output = 0;\r\n\r\nreadInterface.on('line', function(line) {\r\n if (count === 0) {\r\n total = +line;\r\n } else {\r\n values.push(line);\r\n }\r\n \r\n if (values.length === total) {\r\n\r\n for (let i = 0; i < total; i++) {\r\n let item = values.shift();\r\n\r\n let filtered = values.filter(el => {\r\n let itemSize = item.split(' ');\r\n let itemW = itemSize[0];\r\n let itemH = itemSize[1];\r\n\r\n let elSize = el.split(' ');\r\n let elW = elSize[0];\r\n let elH = elSize[1];\r\n return itemH === elH || itemW === elH || itemW === elW;\r\n })\r\n \r\n output += filtered.length;\r\n }\r\n \r\n console.log(output);\r\n }\r\n\r\n count++;\r\n});"}, {"source_code": "var readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nvar count_of_monitors\r\nvar monitors_sizes = []\r\nfunction start() {\r\n rl.question(\"\", function(answer) {\r\n count_of_monitors = parseInt(answer)\r\n get_mon()\r\n });\r\n}\r\n\r\nfunction get_monitors() {\r\n rl.question(\"\", function(answer) {\r\n monitors_sizes.push(answer)\r\n count_of_monitors--\r\n get_mon()\r\n });\r\n \r\n}\r\n\r\nfunction get_mon() {\r\n if (count_of_monitors > 0) {\r\n get_monitors()\r\n } else {\r\n get_pairs()\r\n }\r\n}\r\n\r\nfunction factorial(n) {\r\n return (n != 1) ? n * factorial(n - 1) : 1;\r\n}\r\n\r\nfunction get_pairs() {\r\n var pairs = []\r\n var count_factorial_combinations = 0\r\n var deleted_sizes = []\r\n var old_arr = monitors_sizes\r\n for (var i = 0; i < monitors_sizes.length; i++) {\r\n var fact_arr = monitors_sizes.filter(size => size == monitors_sizes[i])\r\n if (fact_arr.length > 1) {\r\n count_factorial_combinations += factorial(fact_arr.length)\r\n monitors_sizes = monitors_sizes.filter((word, index) => {\r\n\r\n if (word == monitors_sizes[i]) {\r\n if (index == i) {\r\n return true\r\n } else {\r\n deleted_sizes.push(monitors_sizes[i])\r\n return false\r\n }\r\n } else {\r\n return true\r\n }\r\n })\r\n } \r\n }\r\n for (var first_mon_index = 0; first_mon_index < monitors_sizes.length; first_mon_index++) {\r\n if (typeof(monitors_sizes[first_mon_index + 1]) != \"undefined\") {\r\n for (var second_mon_index = first_mon_index + 1; second_mon_index < monitors_sizes.length; second_mon_index++) {\r\n if (first_mon_index != second_mon_index) {\r\n var first_mon_index_sizes = monitors_sizes[first_mon_index].split(\" \")\r\n var second_mon_index_sizes = monitors_sizes[second_mon_index].split(\" \")\r\n if (parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[0]) ||\r\n parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[1]) ||\r\n parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[0]) ||\r\n parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[1])) {\r\n if (pairs.includes(`${first_mon_index} - ${second_mon_index}`) == false && pairs.includes(`${second_mon_index} - ${first_mon_index}`) == false) {\r\n pairs.push(`${first_mon_index} - ${second_mon_index}`)\r\n if (deleted_sizes.indexOf(monitors_sizes[first_mon_index]) !== -1) {\r\n var mid_arr = old_arr.filter(word => word == monitors_sizes[first_mon_index])\r\n if (mid_arr.length > 1) {\r\n count_factorial_combinations += mid_arr.length - 1\r\n }\r\n }\r\n if (deleted_sizes.indexOf(monitors_sizes[second_mon_index]) !== -1) {\r\n var mid_arr = old_arr.filter(word => word == monitors_sizes[second_mon_index])\r\n if (mid_arr.length > 1) {\r\n count_factorial_combinations += mid_arr.length - 1\r\n }\r\n }\r\n }\r\n \r\n }\r\n }\r\n }\r\n }\r\n \r\n }\r\n console.log(pairs.length + count_factorial_combinations)\r\n}\r\n\r\nstart();"}, {"source_code": "var readline = require('readline');\r\n\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nvar count_of_monitors\r\nvar monitors_sizes = []\r\nfunction start() {\r\n rl.question(\"\", function(answer) {\r\n count_of_monitors = parseInt(answer)\r\n get_mon()\r\n });\r\n}\r\n\r\nfunction get_monitors() {\r\n rl.question(\"\", function(answer) {\r\n monitors_sizes.push(answer)\r\n count_of_monitors--\r\n get_mon()\r\n });\r\n \r\n}\r\n\r\nfunction get_mon() {\r\n if (count_of_monitors > 0) {\r\n get_monitors()\r\n } else {\r\n get_pairs()\r\n }\r\n}\r\n\r\nfunction factorial(n) {\r\n return (n != 1) ? n * factorial(n - 1) : 1;\r\n}\r\n\r\nfunction get_pairs() {\r\n var pairs = []\r\n var count_factorial_combinations = 0\r\n var deleted_sizes = []\r\n var old_arr = monitors_sizes\r\n for (var i = 0; i < monitors_sizes.length; i++) {\r\n var fact_arr = monitors_sizes.filter(size => size == monitors_sizes[i])\r\n if (fact_arr.length > 1) {\r\n count_factorial_combinations += factorial(fact_arr.length)\r\n monitors_sizes = monitors_sizes.filter((word, index) => {\r\n\r\n if (word == monitors_sizes[i]) {\r\n if (index == i) {\r\n return true\r\n } else {\r\n deleted_sizes.push(monitors_sizes[i])\r\n return false\r\n }\r\n } else {\r\n return true\r\n }\r\n })\r\n } \r\n }\r\n for (var first_mon_index = 0; first_mon_index < monitors_sizes.length; first_mon_index++) {\r\n for (var second_mon_index = first_mon_index + 1; second_mon_index < monitors_sizes.length; second_mon_index++) {\r\n if (first_mon_index != second_mon_index) {\r\n var first_mon_index_sizes = monitors_sizes[first_mon_index].split(\" \")\r\n var second_mon_index_sizes = monitors_sizes[second_mon_index].split(\" \")\r\n if (parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[0]) ||\r\n parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[1]) ||\r\n parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[0]) ||\r\n parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[1])) {\r\n if (pairs.includes(`${first_mon_index} - ${second_mon_index}`) == false && pairs.includes(`${second_mon_index} - ${first_mon_index}`) == false) {\r\n pairs.push(`${first_mon_index} - ${second_mon_index}`)\r\n if (deleted_sizes.indexOf(monitors_sizes[first_mon_index]) !== -1) {\r\n var mid_arr = old_arr.filter(word => word == monitors_sizes[first_mon_index])\r\n if (mid_arr.length > 1) {\r\n count_factorial_combinations += mid_arr.length - 1\r\n }\r\n }\r\n if (deleted_sizes.indexOf(monitors_sizes[second_mon_index]) !== -1) {\r\n var mid_arr = old_arr.filter(word => word == monitors_sizes[second_mon_index])\r\n if (mid_arr.length > 1) {\r\n count_factorial_combinations += mid_arr.length - 1\r\n }\r\n }\r\n }\r\n \r\n }\r\n }\r\n }\r\n }\r\n console.log(pairs.length + count_factorial_combinations)\r\n}\r\n\r\nstart();"}, {"source_code": "var n = readline();\nvar pairs = []\nvar pairsCount = 0\nvar r = 0\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ')\n\n\tvar c = pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;\n\n\tif (c > 1) {\n\t\tr += c\n\t}\n\n\tpairs.push(l)\n}\n\n\nprint(r);"}, {"source_code": "var n = readline();\nvar pairs = []\nvar pairsCount = 0\nvar r = 0\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ')\n\n\tvar c = pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;\n\n\tif (c > 1) {\n\t\tr += c\n\t}\n\n\tpairs.push(l)\n}\n\n\nprint(r * (r - 1) / 2);"}, {"source_code": "var n = readline();\nvar numbers = []\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ');\n\n\tif (l[0] === l[1]) {\n\t\tnumbers.push(l[0])\n\t} else {\n\t\tnumbers = numbers.concat(l)\n\t}\n}\n\nvar r = 0\n\nwhile (numbers.length) {\n\tvar currNumber = numbers[0]\n\tvar l = numbers.length\n\tnumbers = numbers.filter(el => el !== currNumber)\n\tvar l = l - numbers.length\n\n\tif (l > 1) {\n\t\tr += (l * (l - 1)) / 2\n\t}\n}\n\nprint(r);"}, {"source_code": "var n = readline();\nvar numbers = []\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ');\n\n\tif (l[0] === l[1]) {\n\t\tnumbers.push(l)\n\t} else {\n\t\tnumbers = numbers.concat(l)\n\t}\n}\n\nvar r = 0\n\nwhile (numbers.length) {\n\tvar currNumber = numbers[0]\n\tvar l = numbers.length\n\tnumbers = numbers.filter(el => el !== currNumber)\n\tvar l = l - numbers.length\n\n\tif (l > 1) {\n\t\tr += (l * (l - 1)) / 2\n\t}\n}\n\nprint(r);"}, {"source_code": "var n = readline();\nvar numbers = []\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ');\n\n\tif (l[0] === l[1]) {\n\t\tnumbers.push(l)\n\t} else {\n\t\tnumbers.push(...l)\n\t}\n}\n\nvar r = 0\n\nwhile (numbers.length) {\n\tvar currNumber = numbers[0]\n\tvar l = numbers.length\n\tnumbers = numbers.filter(el => el !== currNumber)\n\tvar l = l - numbers.length\n\n\tif (l > 1) {\n\t\tr += (l * (l - 1)) / 2\n\t}\n}\n\nprint(r);"}, {"source_code": "var n = readline();\nvar numbers = {}\n\nfor (var i = 0; i < n; i++) {\n\tvar l = readline().split(' ');\n\n\tif (l[0] === l[1]) {\n\t\tif (numbers[l[0]]) {\n\t\t\tnumbers[l[0]] = numbers[l[0]] + 1;\n\t\t} else {\n\t\t\tnumbers[l[0]] = 1\n\t\t}\n\t} else {\n\t\tl.forEach(el => {\n\t\t\tif (numbers[el]) {\n\t\t\t\tnumbers[el] = numbers[el] + 1;\n\t\t\t} else {\n\t\t\t\tnumbers[el] = 1\n\t\t\t}\n\t\t})\n\t}\n}\n\n\nprint(\"1\");"}], "src_uid": "32c99f64fdf69b9fd87b07dbd14ceffa"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let i = 0\n let j = n - 1\n while (i < j) {\n while (i < j) {\n if (arr[i] > 0) break\n i++\n }\n while (i < j) {\n if (arr[j] < 0) break\n j--\n }\n if (i > j) break\n arr[i] = -arr[i]\n arr[j] = -arr[j]\n i++; j--\n }\n// console.log(arr)\n for (i = 1; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) return 'NO'\n }\n return 'YES'\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let arr = readLine().split(\" \").map(Number);\n\n let cntNegative = 0,\n ispresent = 0;\n for (let x of arr) {\n if (x < 0) {\n cntNegative++;\n ispresent = 1;\n }\n }\n\n let j = 0;\n for (let i = 0; i < arr.length; i++) {\n if (cntNegative > 0 && arr[i] > 0) {\n arr[i] *= -1;\n cntNegative--;\n j = i;\n } else if (cntNegative > 0 && arr[i] < 0) {\n cntNegative--;\n j = i;\n }\n }\n\n for (let k = j + 1; ispresent && k < arr.length; k++) {\n if (arr[k] < 0) {\n arr[k] *= -1;\n }\n }\n let flag = 0;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] > arr[i]) {\n console.log(\"NO\");\n flag = 1;\n break;\n }\n }\n\n if (flag == 0) {\n console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar alpha = []\r\nvar num = []\r\nfunction alph() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n for(var x=0;x parseInt(x))\r\n var j = 0;\r\n for(var i=n-1;i>=0 && i>j;i--) {\r\n if(a[i] < 0) {\r\n if(a[j] > 0) {\r\n a[j] = a[j] * (-1);\r\n a[i] = a[i] * (-1)\r\n j++;\r\n } else {\r\n //if(q == 3) console.log([a[i],a[j]])\r\n while(a[j] < 0 && j < n) j++;\r\n if(i <= j) continue;\r\n if(j < n && a[j] > 0) {\r\n //if(q == 3) console.log([a[i],a[j]])\r\n a[j] = a[j] * (-1)\r\n a[i] = a[i] * (-1)\r\n j++;\r\n }\r\n \r\n }\r\n }\r\n }\r\n var ok = true;\r\n for(var i=1;i= 0; i--) {\r\n var _a2;\r\n if (a[i] < 0) {\r\n var _a;\r\n if (Math.abs(a[i]) <= ((_a = a[i + 1]) !== null && _a !== void 0 ? _a : Infinity)) {\r\n if (j >= i) j = i - 1;\r\n while (j >= 0 && a[j] < 0) {\r\n j--;\r\n }\r\n if (j >= 0) {\r\n a[i] = -a[i];\r\n a[j] = -a[j];\r\n }\r\n }\r\n }\r\n if (a[i] > ((_a2 = a[i + 1]) !== null && _a2 !== void 0 ? _a2 : Infinity)) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let neg = arr.filter(n => n < 0).length;\r\n\r\n const getNum = k => {\r\n let num = Math.abs(arr[k]);\r\n if (k < neg) {\r\n num = -num;\r\n }\r\n return num;\r\n }\r\n\r\n let no = false;\r\n for (let i = 0; i < arr.length; i++) {\r\n let num = getNum(i);\r\n if (i > 0 && num < getNum(i - 1)) {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}\r\n"}, {"source_code": "/*\r\n * File Created: Thursday, 11th February 2021 1:42:08 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = data.shift();\r\n const arr = data.shift().split(' ').map(Number);\r\n \r\n console.log(a(n,arr));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n let k = 0;\r\n let j = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(arr[i] < 0){\r\n arr[j++] *= -1;\r\n arr[i] *= -1;\r\n }\r\n }\r\n if(isSorted(arr)) {\r\n return 'YES';\r\n } else { \r\n return 'NO'\r\n }\r\n}\r\n\r\nfunction isSorted(arr){\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] > arr[i+1]) return false;\r\n }\r\n return true;\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n let t = parseInt(ls[l++]);\r\n for (; t > 0; t--){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n let j = 0;\r\n for (let i = 0; i < n; i++){\r\n if (a[i] < 0){\r\n a[j++] *= -1;\r\n a[i] *= -1;\r\n }\r\n }\r\n\r\n let isSorted = true;\r\n for (let i = 1; i < n; i++){\r\n if (a[i] < a[i - 1]){\r\n isSorted = false;\r\n break;\r\n }\r\n }\r\n\r\n if (isSorted){\r\n console.log('YES');\r\n }\r\n else{\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, a)=>{\n let neg = 0;\n let pos = 0;\n\n for (let i = 0; i < n; i++) {\n if (a[i] < 0) neg++;\n else pos++;\n }\n\n for (let i = 0; i < n; i++) {\n if (i < neg && a[i] > 0) {\n a[i] = -a[i];\n }\n if (i >= neg && a[i] < 0) {\n a[i] = -a[i];\n }\n if (i > 0 && a[i] < a[i - 1]) return 'NO';\n }\n\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n // let [n, k] = ra();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const size = nextInt();\r\n const arr = nextIntArray(size);\r\n\r\n let negative = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] < 0) {\r\n negative++;\r\n }\r\n }\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n\r\n if (negative > 0) {\r\n arr[i] = -Math.abs(arr[i]);\r\n negative--;\r\n } else if (negative === 0) {\r\n arr[i] = Math.abs(arr[i]);\r\n }\r\n }\r\n\r\n for (let i = 0; i < arr.length-1; i++) {\r\n if (arr[i] > arr[i+1]) {\r\n myout(\"NO\");\r\n return;\r\n }\r\n }\r\n\r\n myout(\"YES\")\r\n}"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n\n // PROCESSING:\n let minuses = 0;\n for (let i=0; iA[i+1])\n return 'NO'\n }\n return 'YES';\n};\n "}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let arr = readLine().split(\" \").map(Number);\n\n let cntNegative = 0,\n ispresent = 0;\n for (let x of arr) {\n if (x < 0) {\n cntNegative++;\n ispresent = 1;\n }\n }\n\n let j = 0;\n for (let i = 0; i < arr.length; i++) {\n if (cntNegative > 0 && arr[i] > 0) {\n arr[i] *= -1;\n cntNegative--;\n j = i;\n } else if (cntNegative > 0 && arr[i] < 0) {\n cntNegative--;\n j = i;\n }\n }\n\n for (let k = j + 1; ispresent && k < arr.length; k++) {\n if (arr[i] < 0) {\n arr[k] *= -1;\n }\n }\n let flag = 0;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] > arr[i]) {\n console.log(\"NO\");\n flag = 1;\n break;\n }\n }\n\n if (flag == 0) {\n console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let arr = readLine().split(\" \").map(Number);\n\n let cntNegative = 0,\n ispresent = 0;\n for (let x of arr) {\n if (x < 0) {\n cntNegative++;\n ispresent = 1;\n }\n }\n\n let j = 0;\n for (let i = 0; i < arr.length; i++) {\n if (cntNegative > 0 && arr[i] > 0) {\n arr[i] *= -1;\n cntNegative--;\n j = i;\n } else if (cntNegative > 0 && arr[i] < 0) {\n cntNegative--;\n j = i;\n }\n }\n\n for (let k = j + 1; ispresent && k < arr.length; k++) {\n arr[k] *= -1;\n }\n let flag = 0;\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] > arr[i]) {\n console.log(\"NO\");\n flag = 1;\n break;\n }\n }\n\n if (flag == 0) {\n console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar alpha = []\r\nvar num = []\r\nfunction alph() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n for(var x=0;x parseInt(x))\r\n var j = 0;\r\n for(var i=n-1;i>=0 && i>j;i--) {\r\n if(a[i] < 0) {\r\n if(a[j] > 0) {\r\n a[j] = a[j] * (-1);\r\n a[i] = a[i] * (-1)\r\n j++;\r\n } else {\r\n //if(q == 3) console.log([a[i],a[j]])\r\n while(a[j] < 0 && j < n) j++;\r\n if(j < n && a[j] > 0) {\r\n //if(q == 3) console.log([a[i],a[j]])\r\n a[j] = a[j] * (-1)\r\n a[i] = a[i] * (-1)\r\n j++;\r\n }\r\n }\r\n }\r\n }\r\n var ok = true;\r\n for(var i=1;i= 0; i--) {\r\n var _a2;\r\n if (a[i] < 0) {\r\n var _a;\r\n if (Math.abs(a[i]) < ((_a = a[i + 1]) !== null && _a !== void 0 ? _a : Infinity)) {\r\n if (j >= i) j = i - 1;\r\n while (j >= 0 && a[j] < 0) {\r\n j--;\r\n }\r\n if (j >= 0) {\r\n a[i] = -a[i];\r\n a[j] = -a[j];\r\n }\r\n }\r\n }\r\n if (a[i] > ((_a2 = a[i + 1]) !== null && _a2 !== void 0 ? _a2 : Infinity)) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "430f34fe715b8dcbcadf3b2c3e1e0381"} {"source_code": "var line = readline();\nvar P=[];\nvar n = 0;\n\nvar subline = line;\n\nwhile(subline.match(\"bear\")){\n var pos = subline.search(\"bear\");\n if(P.length>0){P.push(P[P.length-1]+4+pos);}\n else{P.push(pos)}\n subline = subline.substring(pos+4,subline.length);\n}\n\nif(P.length>0){\n n = (P[0]+1)*(line.length -P[0]-3);\n for(var i=1;i 0) {\n var lastBear = foundBears[foundBears.length - 1];\n result -= (lastBear + 1) * (line.length - (i + 3));\n }\n \n foundBears.push(i);\n // print(i, result);\n // print();\n }\n}\n\nprint(result);\n"}], "negative_code": [{"source_code": "\nvar s=readline();\nvar l=s.length-3;\nif(l<0){\n\tprint(0);\n}else{\n\nvar n=l*(l+1)/2;\n\nvar a=[];\nfor(var i=0;i\u043c\u0430\u043d\u0434\u0430)\n return -1\n if (\u0435\u043b\u0434\u0430==\u043c\u0430\u043d\u0434\u0430)\n return 0\n return 1\n}\n \n\u043d\u043e\u0433\u043d\u0433.sort(\u0441\u0440\u0430\u043a\u0430)\n\u0447\u0443\u043a\u0447\u0430-=1\n\u043e\u0442\u0432\u0435\u0442=\u0446\u0432\u0430\u0444[\u0431\u044c\u0435\u043d\u0442\u043e\u0440\u0438\u0448-1]-\u0446\u0432\u0430\u0444[0]\nfor (i=0;i<\u0447\u0443\u043a\u0447\u0430;i++)\n\u043e\u0442\u0432\u0435\u0442-=\u043d\u043e\u0433\u043d\u0433[i]\n\nprint(\u043e\u0442\u0432\u0435\u0442)", "positive_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\n var input = rdAr();\n var n = input[0];\n var k = input[1];\n var A = rdAr();\n var U = Array.from(new Set(A));\n if (U.length <= k) {\n wr(0);\n } else {\n var D = [];\n for (var i = 1; i < U.length; ++i) {\n D.push(U[i] - U[i - 1]);\n }\n D.sortLt();\n var res = 0;\n for (var i = 0; i < D.length - (k-1); ++i) {\n res += D[i];\n }\n wr(res);\n }\n};\n\nif (INPUT) {\nINPUT = INPUT.split('\\n').reverse();\nreadline = () => INPUT.pop();\nwrite = (s) => {OUTPUT += s};\nprint = (s) => {OUTPUT += s + '\\n'};\n}\nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\nconst getPrimes = function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n for(l = 1; l <= a; l++){\n var ans = '';\n for(j = 1; j <= l; j++){\n if(j == 1 || j == l){\n ans += 1 + ' ';\n }else{\n ans += 0 + ' ';\n }\n }\n console.log(ans);\n }\n }\n});\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let res = [];\r\n for(let i=0;i inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n for (let i = 1; i <= n; i++) {\r\n if (i === 1) {\r\n output(1);\r\n } else if (i===2) {\r\n output('1 1');\r\n } else {\r\n output('1 ' + (new Array(i - 2).fill(0).join(' ')) + ' 1');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n let ans = [\"1\", \"1 1\"];\r\n if (+input[i] === 1) {\r\n console.log(ans[0]);\r\n continue;\r\n } else if (+input[i] === 2) {\r\n console.log(ans[0]);\r\n console.log(ans[1]);\r\n continue;\r\n }\r\n let n = +input[i];\r\n let x = 3;\r\n while (x <= n) {\r\n ans.push(\"1 \" + \"0 \".repeat(x - 2) + \"1\");\r\n x++;\r\n }\r\n\r\n for (let i = 0; i < ans.length; i++) {\r\n console.log(ans[i]);\r\n }\r\n }\r\n};\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n console.log(1);\n var ans = '';\n for(j = 0; j < a - 1; j++){\n ans += j === 0 ? 1 + ' ' : 0 + ' ';\n }\n ans += 1 + ' ';\n console.log(ans);\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n var ans = 1 + ' ';\n console.log(1);\n if(a == 1){\n console.log(ans);\n }else{\n for(j = 0; j < a - 2; j++){\n ans += 0 + ' ';\n }\n ans += 1;\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0][0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n let n = input[i];\r\n\r\n for (let j = 0; j < n; j++) {\r\n for (let k = 0; k < j + 1; k++) {\r\n if (k === 0 || k == j) {\r\n process.stdout.write(\"1 \");\r\n } else {\r\n process.stdout.write(\"0 \");\r\n }\r\n }\r\n process.stdout.write(\"\\n\");\r\n }\r\n }\r\n};\r\n"}, {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0][0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n let ans = [\"1\", \"1 1\"];\r\n if (+input[i] === 1) {\r\n console.log(ans[0]);\r\n continue;\r\n } else if (+input[i] === 2) {\r\n console.log(ans[0]);\r\n console.log(ans[1]);\r\n continue;\r\n }\r\n let n = +input[i];\r\n let x = 3;\r\n while (x <= n) {\r\n ans.push(\"1 \" + \"0 \".repeat(x - 2) + \"1\");\r\n x++;\r\n }\r\n\r\n for (let i = 0; i < ans.length; i++) {\r\n console.log(ans[i]);\r\n }\r\n }\r\n};\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let res = [];\r\n for(let i=0;i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\r\n\t\tlet ans; \r\n\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\tfor (let j = 0; j < 2; j++) {\r\n\t\t\t\tfor (let k = 0; k < 2; k++) {\r\n\t\t\t\t\tconst ss = [];\r\n\t\t\t\t\tfor (const c of s) {\r\n\t\t\t\t\t\tif (c == 'A') ss.push(i ? '(' : ')');\r\n\t\t\t\t\t\tif (c == 'B') ss.push(j ? '(' : ')');\r\n\t\t\t\t\t\tif (c == 'C') ss.push(k ? '(' : ')');\r\n\t\t\t\t\t}\r\n\t\t\t\t\tans |= check(ss);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfunction check (ss) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i < ss.length; i++) {\r\n\t\t\t\tif (ss[i] == '(') cnt++;\r\n\t\t\t\telse cnt --;\r\n\t\t\t\tif (cnt < 0) break;\r\n\t\t\t}\r\n\t\t\treturn cnt == 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString.trim().split(\"\\n\").map(line => {\r\n return line.trim();\r\n })\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let line = readline().split(\"\");\r\n console.log(processExpression(line));\r\n }\r\n}\r\nfunction processExpression(exp) {\r\n const escenarios = [\r\n [\"(\", \"(\", \")\"],\r\n [\"(\", \")\", \"(\"],\r\n [\"(\", \")\", \")\"],\r\n [\")\", \"(\", \"(\"],\r\n [\")\", \"(\", \")\"],\r\n [\")\", \")\", \"(\"]\r\n ];\r\n for (const escenario of escenarios) {\r\n let bracket = assignBracket(exp, ...escenario).split(\"\");\r\n if (isValidExpression(bracket)) {\r\n return \"YES\";\r\n }\r\n }\r\n return \"NO\";\r\n}\r\nfunction assignBracket(exp, A, B, C) {\r\n let newExp = \"\";\r\n for (let i = 0; i < exp.length; i++) {\r\n if (exp[i] == \"A\") {\r\n newExp += A;\r\n }\r\n else if (exp[i] == \"B\") {\r\n newExp += B;\r\n }\r\n else if (exp[i] == \"C\") {\r\n newExp += C;\r\n }\r\n }\r\n return newExp;\r\n}\r\nfunction isValidExpression(bracket) {\r\n for (let i = 0; i < bracket.length - 1; i++) {\r\n if (bracket[i] == \"(\" && bracket[i + 1] == \")\") {\r\n bracket.splice(i, 2);\r\n return isValidExpression(bracket);\r\n }\r\n }\r\n return bracket.length == 0;\r\n}"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n let cnt_A = 0;\r\n let cnt_B = 0;\r\n let cnt_C = 0;\r\n let arr = [];\r\n for(let i= 0 ; i < a.length; i++){\r\n if(a[i] === 'A') cnt_A++;\r\n if(a[i] === 'B') cnt_B++;\r\n if(a[i] === 'C') cnt_C++; \r\n }\r\n arr.push(['A', cnt_A]);\r\n arr.push(['B', cnt_B]);\r\n arr.push(['C', cnt_C]);\r\n arr.sort((a,b) => a[1] - b[1]);\r\n let sum = 0;\r\n let opn = a[0];\r\n if(opn === arr[arr.length - 1][0]){\r\n // the other two are closing brackets\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n } else {\r\n // opn and arr[0] || arr[1] is opening and arr[arr.length - 1] are closing\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn || a[i] === arr[0][0] || a[i] === arr[1][0]){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n if(sum !== 0){\r\n return 'NO'\r\n } else{\r\n return 'YES'\r\n }\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "/*\r\nFunctions used for getting input from the console\r\n\r\nTo get the next line of input when it is received use 'await getNextLine()' inside of an async function\r\n*/\r\n\r\n//----------------------------------------------------\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet input = [];\r\nlet currentLine = 0;\r\n\r\n//adds next line to input array\r\nprocess.stdin.on('data', function(inputStdin) \r\n{\r\n const newIn = inputStdin.split(\"\\n\")\r\n for (let i of newIn)\r\n {\r\n if (i.length > 0) input.push(i.trim());\r\n }\r\n});\r\n\r\n//returns the next line of unprocessed input\r\nfunction readLine() \r\n{\r\n if (!isNewInput()) return \"\";\r\n\r\n return input[currentLine++];\r\n}\r\n\r\n//checks if any new input has been added\r\nfunction isNewInput()\r\n{\r\n return currentLine < input.length;\r\n}\r\n\r\n//waits 'ms' milliseconds\r\nfunction sleep(ms)\r\n{\r\n return new Promise((resolve) => \r\n {\r\n setTimeout(resolve, ms);\r\n });\r\n}\r\n\r\n//returns the next line of unprocessed input once it is available\r\nasync function getNextLine()\r\n{\r\n while(!isNewInput()) await sleep(5);\r\n return readLine();\r\n}\r\n//----------------------------------------------------\r\n\r\n//main\r\nmain();\r\nasync function main()\r\n{\r\n const testCases = Number(await getNextLine());\r\n for (let t = 0; t < testCases; t++)\r\n {\r\n const abc = await getNextLine();\r\n if (isValid(abc, [\"A\"], [\"B\", \"C\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"1\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"B\"], [\"A\", \"C\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"2\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"C\"], [\"A\", \"B\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"3\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"A\", \"B\"], [\"C\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"4\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"A\", \"C\"], [\"B\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"5\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"C\", \"B\"], [\"A\"]))\r\n {\r\n console.log(\"YES\");\r\n //console.log(\"6\");\r\n continue;\r\n }\r\n\r\n console.log(\"NO\");\r\n }\r\n process.exit();\r\n}\r\n\r\nfunction isValid(seq, open, close)\r\n{\r\n let count = 0;\r\n const arr = seq.split(\"\");\r\n for (let c of arr)\r\n {\r\n if (open.includes(c))\r\n {\r\n count++;\r\n }\r\n else if (close.includes(c))\r\n {\r\n count--;\r\n }\r\n if (count < 0) return false;\r\n }\r\n return count == 0;\r\n}"}, {"source_code": "const correctBracket = str => {\n let count = 0;\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"(\") count += 1;\n else count -= 1;\n if (count < 0) return false;\n }\n return count === 0;\n};\n\nconst solve = str => {\n for (let i = 0; i < 2 ** 3; i++) {\n const check = correctBracket(\n str\n .replace(/A/g, (i & 1) === 1 ? \"(\" : \")\")\n .replace(/B/g, ((i >> 1) & 1) === 1 ? \"(\" : \")\")\n .replace(/C/g, ((i >> 2) & 1) === 1 ? \"(\" : \")\")\n );\n if (check) return \"YES\";\n }\n return \"NO\";\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const str = readLine();\n console.log(solve(str));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var b = new Array(a.length)\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = '('\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = '('\r\n if (a[i] === 'B') b[i] = ')'\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = '('\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = '('\r\n if (a[i] === 'B') b[i] = ')'\r\n if (a[i] === 'C') b[i] = '('\r\n }\r\n\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = ')'\r\n if (a[i] === 'C') b[i] = '('\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n console.log('NO')\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar key = [\"A\", \"B\", \"C\"];\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = next();\r\n\t\tvar isOK = false;\r\n\t\tfor(var j = 0; j < (1 << (key.length)); j++){\r\n\t\t\tvar map = {};\r\n\t\t\tfor(var k = 0; k < key.length; k++){\r\n\t\t\t\tif((j & (1 << k)) != 0){\r\n\t\t\t\t\tmap[key[k]] = \"(\";\r\n\t\t\t\t}else{\r\n\t\t\t\t\tmap[key[k]] = \")\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar v = [];\r\n\t\t\tfor(var k = 0; k < s.length; k++){\r\n\t\t\t\tif(map[s[k]] == \"(\"){\r\n\t\t\t\t\tv.push(\"(\");\r\n\t\t\t\t}else if(v.length > 0 && v[v.length - 1] == \"(\"){\r\n\t\t\t\t\tv.pop();\r\n\t\t\t\t}else{\r\n\t\t\t\t\tv.push(\")\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(v.length == 0){\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const { SSL_OP_TLS_ROLLBACK_BUG } = require(\"constants\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n for (var m = 1; m < input.length; m++) {\r\n var str = input[m];\r\n // [\"(((\", \"(()\", \"()(\", \"())\", \")((\", \")()\", \"))(\", \")))\"];\r\n var patterns = [\"(()\", \"()(\", \"())\", \")((\", \")()\", \"))(\"];\r\n var flag = false;\r\n for (let pattern of patterns) {\r\n var count = 0;\r\n var i;\r\n for (i = 0; i < str.length; i++) {\r\n var c;\r\n if (str[i] === \"A\") {\r\n c = pattern[0];\r\n } else if (str[i] === \"B\") {\r\n c = pattern[1];\r\n } else {\r\n c = pattern[2];\r\n }\r\n if (c === \"(\") {\r\n count++;\r\n } else {\r\n count--;\r\n }\r\n if (count < 0) {\r\n break;\r\n }\r\n }\r\n if (i === str.length && count === 0) {\r\n flag = true;\r\n }\r\n }\r\n if (flag) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n } \r\n})"}, {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar s = readline();\n\n\tvar any = false;\n\tfor (a = -1; a < 2; a += 2) {\n\t\tfor (b = -1; b < 2; b += 2) {\n\t\t\tfor (c = -1; c < 2; c += 2) {\n\t\t\t\tvar cur = 0;\n\t\t\t\tvar ok = true;\n\t\t\t\tfor (i = 0; i < s.length; i++) {\n\t\t\t\t\tif (s[i] === 'A') cur += a;\n\t\t\t\t\tif (s[i] === 'B') cur += b;\n\t\t\t\t\tif (s[i] === 'C') cur += c;\n\t\t\t\t\tif (cur < 0) ok = false;\n\t\t\t\t}\n\t\t\t\tif (ok && cur === 0) {\n\t\t\t\t\tany = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tprint(any ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "let raw = ''\r\nprocess.stdin.on('data', it => (raw += it)).on('end', () => {\r\nconst arr = raw.replace(/\\r/g, '').trim().split('\\n');\r\nfor (let i = 0, all = +arr.shift(); i < all; i++) {\r\n let s = arr[i]\r\n if (s[0] == s[s.length - 1]) {\r\n console.log('NO')\r\n continue\r\n }\r\n const obj = {}\r\n let max = 0, ch\r\n for (const it of s) if (max < (++obj[it] || (obj[it] = 1))) {\r\n max = obj[it]\r\n ch = it\r\n }\r\n const f = s[0] == ch\r\n s = s.replace(new RegExp(ch, 'g'), f ? '(' : ')')\r\n for (const it in obj) if (it !== ch) s = s.replace(new RegExp(it, 'g'), f ? ')' : '(')\r\n let t = s\r\n while ((s = t.replace(/\\(\\)/g, '')) != t) t = s\r\n console.log(s ? 'NO' : 'YES')\r\n}\r\n});"}], "negative_code": [{"source_code": "let raw = ''\r\nprocess.stdin.on('data', it => (raw += it)).on('end', () => {\r\nconst arr = raw.replace(/\\r/g, '').trim().split('\\n');\r\nfor (let i = 0, all = +arr.shift(); i < all; i++) {\r\n const s = arr[i]\r\n if (s.length <= 1) {\r\n console.log('NO')\r\n continue\r\n }\r\n const obj = {}\r\n let max = 0, ch, cnt = 0\r\n for (const it of s) if (max < (++obj[it] || (obj[it] = 1))) {\r\n max = obj[it]\r\n ch = it\r\n }\r\n for (const it in obj) if (it !== ch) cnt += obj[it]\r\n console.log(max == cnt && s[0] != s[s.length -1] && !(s[0] !== ch && s[s.length - 1] !== ch) ? 'YES' : 'NO')\r\n}\r\n});"}, {"source_code": "let raw = [];\r\nprocess.stdin.on('data', it => raw.push(it)).on('end', () => {\r\n const arr = Buffer.concat(raw).toString().replace(/\\r/g, '').trim().split('\\n');\r\n for (let i = 0, all = +arr.shift(); i < all; i++) {\r\n if (arr[i][0] == arr[i][arr[i].length - 1]) {\r\n console.log('NO')\r\n continue\r\n }\r\n const obj = {}\r\n let max = 0, ch, cnt = 0\r\n for (const it of arr[i]) if (max < (++obj[it] || (obj[it] = 1))) {\r\n max = obj[it]\r\n ch = it\r\n }\r\n for (const it in obj) if (it !== ch) cnt += obj[it]\r\n console.log(max == cnt ? 'YES' : 'NO')\r\n }\r\n})\r\n"}, {"source_code": "let raw = '';\r\nprocess.stdin.on('data', it => (raw += it)).on('end', () => {\r\n const arr = raw.replace(/\\r/g, '').trim().split('\\n');\r\n for (let i = 0, all = +arr.shift(); i < all; i++) {\r\n if (arr[i][0] == arr[i][arr[i].length - 1]) {\r\n console.log('NO')\r\n continue\r\n }\r\n const obj = {}\r\n let max = 0, ch, cnt = 0\r\n for (const it of arr[i]) if (max < (++obj[it] || (obj[it] = 1))) {\r\n max = obj[it]\r\n ch = it\r\n }\r\n for (const it in obj) if (it !== ch) cnt += obj[it]\r\n console.log(max == cnt ? 'YES' : 'NO')\r\n }\r\n})\r\n"}, {"source_code": "let raw = '';\r\nprocess.stdin.on('data', it => (raw += it)).on('end', () => {\r\n const arr = raw.trim().split('\\n');\r\n for (let i = 0, all = +arr.shift(); i < all; i++) {\r\n if (arr[i][0] == arr[i][arr[i].length - 1]) {\r\n console.log('NO')\r\n continue\r\n }\r\n const obj = {}\r\n let max = 0, ch, cnt = 0\r\n for (const it of arr[i]) if (max < (++obj[it] || (obj[it] = 1))) {\r\n max = obj[it]\r\n ch = it\r\n }\r\n for (const it in obj) if (it !== ch) cnt += obj[it]\r\n console.log(max == cnt ? 'YES' : 'NO')\r\n }\r\n})\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n let cnt_A = 0;\r\n let cnt_B = 0;\r\n let cnt_C = 0;\r\n let arr = [];\r\n for(let i= 0 ; i < a.length; i++){\r\n if(a[i] === 'A') cnt_A++;\r\n if(a[i] === 'B') cnt_B++;\r\n if(a[i] === 'C') cnt_C++; \r\n }\r\n arr.push(['A', cnt_A]);\r\n arr.push(['B', cnt_B]);\r\n arr.push(['C', cnt_C]);\r\n arr.sort((a,b) => a[1] - b[1]);\r\n console.log(arr)\r\n let sum = 0;\r\n let opn = a[0];\r\n if(opn === arr[arr.length - 1][0]){\r\n // the other two are closing brackets\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n } else {\r\n // opn and arr[0] || arr[1] is opening and arr[arr.length - 1] are closing\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn || a[i] === arr[0][0] || a[i] === arr[1][0]){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n if(sum !== 0){\r\n return 'NO'\r\n } else{\r\n return 'YES'\r\n }\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n let cnt_A = 0;\r\n let cnt_B = 0;\r\n let cnt_C = 0;\r\n let arr = [];\r\n for(let i= 0 ; i < a.length; i++){\r\n if(a[i] === 'A') cnt_A++;\r\n if(a[i] === 'B') cnt_B++;\r\n if(a[i] === 'C') cnt_C++; \r\n }\r\n arr.push(['A', cnt_A]);\r\n arr.push(['B', cnt_B]);\r\n arr.push(['C', cnt_C]);\r\n arr.sort((a,b) => a[1] - b[1]);\r\n let sum = 0;\r\n let opn = a[0];\r\n if(opn === arr[arr.length - 1][0]){\r\n // the other two are closing brackets\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n } else {\r\n // opn and arr[0] || arr[1] is opening and arr[arr.length - 1] are closing\r\n for(let i = 0 ; i < a.length ; i++){\r\n if(a[i] === opn || a[i] === arr[0][0] || arr[1][0]){\r\n sum++;\r\n } else {\r\n sum--;\r\n }\r\n if(sum < 0){\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n if(sum !== 0){\r\n return 'NO'\r\n } else{\r\n return 'YES'\r\n }\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n if(a.length % 2 === 1 || a[0] === a[a.length - 1]){\r\n return 'NO';\r\n }\r\n let count_a = 0;\r\n let count_b = 0;\r\n let count_c = 0;\r\n let arr = [];\r\n for(let i = 0 ; i < a.length; i++){\r\n if(a[i] === 'A') count_a++;\r\n if(a[i] === 'B') count_b++;\r\n if(a[i] === 'C') count_c++;\r\n if(i === a.length - 1){\r\n arr.push(count_a);\r\n arr.push(count_b);\r\n arr.push(count_c);\r\n arr.sort((a,b) => a - b);\r\n }\r\n }\r\n if(arr[2] === (arr[0] + arr[1])){\r\n return 'YES';\r\n } else {\r\n return 'NO';\r\n }\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n if(a.length % 2 === 1){\r\n return 'NO';\r\n }\r\n let count_a = 0;\r\n let count_b = 0;\r\n let count_c = 0;\r\n for(let i = 0 ; i < a.length; i++){\r\n if(a[i] === 'A') count_a++;\r\n if(a[i] === 'B') count_b++;\r\n if(a[i] === 'C') count_c++;\r\n }\r\n const is_even_count_a = count_a % 2;\r\n const is_even_count_b = count_b % 2;\r\n const is_even_count_c = count_c % 2;\r\n const sum = is_even_count_a + is_even_count_b + is_even_count_c;\r\n if(sum === 3 || sum === 1){\r\n return 'NO'\r\n } else {\r\n return 'YES'\r\n }\r\n}"}, {"source_code": "/*\r\nFunctions used for getting input from the console\r\n\r\nTo get the next line of input when it is received use 'await getNextLine()' inside of an async function\r\n*/\r\n\r\n//----------------------------------------------------\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet input = [];\r\nlet currentLine = 0;\r\n\r\n//adds next line to input array\r\nprocess.stdin.on('data', function(inputStdin) \r\n{\r\n const newIn = inputStdin.split(\"\\n\")\r\n for (let i of newIn)\r\n {\r\n if (i.length > 0) input.push(i.trim());\r\n }\r\n});\r\n\r\n//returns the next line of unprocessed input\r\nfunction readLine() \r\n{\r\n if (!isNewInput()) return \"\";\r\n\r\n return input[currentLine++];\r\n}\r\n\r\n//checks if any new input has been added\r\nfunction isNewInput()\r\n{\r\n return currentLine < input.length;\r\n}\r\n\r\n//waits 'ms' milliseconds\r\nfunction sleep(ms)\r\n{\r\n return new Promise((resolve) => \r\n {\r\n setTimeout(resolve, ms);\r\n });\r\n}\r\n\r\n//returns the next line of unprocessed input once it is available\r\nasync function getNextLine()\r\n{\r\n while(!isNewInput()) await sleep(5);\r\n return readLine();\r\n}\r\n//----------------------------------------------------\r\n\r\n//main\r\nmain();\r\nasync function main()\r\n{\r\n const testCases = Number(await getNextLine());\r\n for (let t = 0; t < testCases; t++)\r\n {\r\n const abc = await getNextLine();\r\n if (isValid(abc, [\"A\"], [\"B\", \"C\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"B\"], [\"A\", \"C\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"C\"], [\"A\", \"C\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"A\", \"B\"], [\"C\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"A\", \"C\"], [\"B\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n if (isValid(abc, [\"C\", \"B\"], [\"A\"]))\r\n {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n\r\n console.log(\"NO\");\r\n }\r\n process.exit();\r\n}\r\n\r\nfunction isValid(seq, open, close)\r\n{\r\n let count = 0;\r\n const arr = seq.split(\"\");\r\n for (let c of arr)\r\n {\r\n if (open.includes(c))\r\n {\r\n count++;\r\n }\r\n else if (close.includes(c))\r\n {\r\n count--;\r\n }\r\n if (count < 0) return false;\r\n }\r\n return count == 0;\r\n}"}, {"source_code": "const correctBracket = str => {\n let count = 0;\n for (let i = 0; i < str.length; i++) {\n if (str[i] === \"(\") count += 1;\n else count -= 1;\n if (count < 0) return false;\n }\n return count === 0;\n};\n\nconst solve = str => {\n const check =\n correctBracket(\n str\n .replace(/C/g, \"A\")\n .replace(/A/g, \"(\")\n .replace(/B/g, \")\")\n ) ||\n correctBracket(\n str\n .replace(/C/g, \"B\")\n .replace(/A/g, \"(\")\n .replace(/B/g, \")\")\n ) ||\n correctBracket(\n str\n .replace(/C/g, \"A\")\n .replace(/A/g, \")\")\n .replace(/B/g, \"(\")\n ) ||\n correctBracket(\n str\n .replace(/C/g, \"B\")\n .replace(/A/g, \")\")\n .replace(/B/g, \"(\")\n );\n if (check) return \"YES\";\n return \"NO\";\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const str = readLine();\n console.log(solve(str));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, u, v] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var b = new Array(a.length)\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = '('\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = '('\r\n if (a[i] === 'B') b[i] = ')'\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = '('\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = ')'\r\n if (a[i] === 'C') b[i] = '('\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (a[i] === 'A') b[i] = ')'\r\n if (a[i] === 'B') b[i] = '('\r\n if (a[i] === 'C') b[i] = ')'\r\n }\r\n if (checkString(b)) return console.log('YES')\r\n console.log('NO')\r\n // console.log(a)\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}], "src_uid": "4d24aaf5ebf70265b027a6af86e09250"} {"source_code": "function resolve(k, n) {\n k = parseInt(k, 10);\n var sum = 0;\n for (var i = 0; i < n.length; i++) {\n sum += parseInt(n[i], 10);\n }\n if (sum >= k) {\n return 0;\n } else {\n var total = k - sum;\n var count = 0;\n var arr = n.split('').sort();\n for (var j = 0; j < arr.length; j++) {\n count++;\n total -= 9 - parseInt(arr[j], 10);\n if (total <= 0) {\n break;\n }\n }\n if (total > 0) {\n var q = Math.floor(total / 9);\n var r = total % 9;\n if (r === 0) {\n return q + count;\n } else {\n return q + count + 1;\n }\n } else {\n return count;\n }\n }\n}\n\nconst k = readline();\nconst n = readline();\n\nconst result = resolve(k, n);\n\nprint(result + '\\n');\n", "positive_code": [{"source_code": "function resolve(k, n) {\n k = parseInt(k, 10);\n var sum = 0;\n for (var i = 0; i < n.length; i++) {\n sum += parseInt(n[i], 10);\n }\n if (sum >= k) {\n return 0;\n } else {\n var total = k - sum;\n var count = 0;\n var arr = n.split('').sort();\n for (var j = 0; j < arr.length; j++) {\n count++;\n total -= 9 - parseInt(arr[j], 10);\n if (total <= 0) {\n break;\n }\n }\n if (total > 0) {\n var q = Math.floor(total / 9);\n var r = total % 9;\n if (r === 0) {\n return q + count;\n } else {\n return q + count + 1;\n }\n } else {\n return count;\n }\n }\n}\n\nconst k = readline();\nconst n = readline();\n\nconst result = resolve(k, n);\n\nprint(result + '\\n');"}, {"source_code": "function main() {\n var k = Number(readline());\n var n = readline();\n\n var sumOfN = n.split('').reduce((sum, i) => {\n return sum + Number(i);\n }, 0);\n\n if (sumOfN >= k) {\n return print(0);\n }\n\n var sortedN = n\n .split('')\n .sort()\n .join('');\n var changes = 0;\n\n for (var i = 0; i < sortedN.length; i++) {\n if (Number(sortedN[i]) !== 9) {\n sumOfN += 9 - Number(sortedN[i]);\n changes++;\n\n if (sumOfN >= k) {\n return print(changes);\n }\n }\n }\n\n print('Something went wrong');\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function resolve(k, n) {\n k = parseInt(k, 10);\n var sum = 0;\n for (var i = 0; i < n.length; i++) {\n sum += parseInt(n[i], 10);\n }\n if (sum >= k) {\n return 0;\n } else {\n var q = Math.floor((k - sum) / 9);\n var r = (k - sum) % 9;\n if (r === 0) {\n return q;\n } else {\n return q + 1;\n }\n }\n}\n\nconst k = readline();\nconst n = readline();\n\nconst result = resolve(k, n);\n\nprint(result);\n"}, {"source_code": "function sumDigits(number) {\n var total = 0;\n for (var i = 0; i < number.length; i++) {\n total += number[i];\n }\n return total;\n}\n\nfunction main() {\n var k = readline();\n var n = readline();\n\n var sumOfN = sumDigits(n);\n\n if (k < sumOfN) {\n return print(0);\n }\n\n var sortedN = n\n .split('')\n .sort()\n .join('');\n var newTotal = sumOfN;\n var changes = 0;\n\n for (var i = 0; i < sortedN.length; i++) {\n if (sortedN[i] !== '9') {\n newTotal += 9 - sortedN[i];\n changes++;\n }\n }\n\n print(changes);\n}\n\nmain();\n"}, {"source_code": "function main() {\n var k = readline();\n var n = readline();\n\n var sumOfN = n.split('').reduce((sum, i) => {\n return sum + i;\n }, 0);\n\n if (sumOfN >= k) {\n return print(0);\n }\n\n var sortedN = n\n .split('')\n .sort()\n .join('');\n var changes = 0;\n\n for (var i = 0; i < sortedN.length; i++) {\n if (sortedN[i] !== '9') {\n sumOfN += 9 - sortedN[i];\n changes++;\n\n if (sumOfN >= k) {\n return print(changes);\n }\n }\n }\n\n print(changes);\n}\n\nmain();\n"}], "src_uid": "d7e6e5042b8860bb2470d5a493b0adf6"} {"source_code": "\ufeffvar stZag, stText, stt;\nvar mask = new Array(300);\n\nfunction r() {\n stZag = readline();\n stText = readline();\n};\n\n+function main() {\n for (var i = 0; i < 300; i++) {\n mask[i] = false;\n }\n\n r();\n stt = \"\";\n for (var i = 0; i < stText.length; ++i) {\n if (stText.charAt(i) != ' ' && stText.charAt(i) != '\t') {\n stt += stText.charAt(i);\n }\n }\n\n stText = \"\";\n\n\n for (var i = 0; i < stt.length; ++i) {\n stText += stt.charAt(i);\n }\n\n stt = \"\";\n\n for (var i = 0; i < stZag.length ; ++i) {\n if (stZag.charAt(i) != ' ' && stZag.charAt(i) != '\t') {\n stt += stZag.charAt(i);\n }\n }\n\n stZag = \"\";\n for (var i = 0; i < stt.length ; ++i) {\n stZag += stt.charAt(i);\n }\n stt = \"\";\n\n \n for (var i = 0; i < stText.length; ++i) {\n var tek = stText.charAt(i);\n\n for (var j = 0; j < stZag.length; ++j) {\n if (mask[j] != true) {\n if (tek == stZag.charAt(j)) {\n mask[j] = true;\n break;\n }\n }\n\n if (j == stZag.length - 1) {\n print(\"NO\\n\");\n // cout << \"NO\" << endl;\n return 0;\n }\n }\n }\n\n print(\"YES\\n\");\n return 0;\n}();", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const str1 = readLine();\n const str2 = readLine().split(\" \").join(\"\").trim();\n const map = {};\n let ok = true;\n\n for (let i = 0; i < str1.length; i++) {\n const char = str1[i];\n if ((char >= \"a\" && char <= \"z\") || (char >= \"A\" && char <= \"Z\")) {\n map[char] = (map[char] || 0) + 1;\n }\n }\n\n for (let i = 0; i < str2.length; i++) {\n const char = str2[i];\n if (!map[char] || map[char] === 0) {\n console.log(\"NO\");\n ok = false;\n break;\n }\n map[char]--;\n }\n\n ok && console.log(\"YES\");\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet h = readLine().split('');\n\tlet str = readLine().split('');\n\n\tlet c = 0;\n\n\tfor (let i = 0, l = str.length; i < l; i++) {\n\t\tlet index = h.indexOf(str[i]);\n\t\tif (index > -1) {\n\t\t\tc++;\n\t\t\tif (str[i] !== ' ') h.splice(index, 1);\n\t\t}\n\t}\n\n\tif (c === str.length) console.log('YES');\n\telse console.log('NO');\n}\n"}, {"source_code": "var s = readline().trim().split(' ').filter((_s)=>_s!='').join('');\nvar t = readline().trim().split(' ').filter((_s)=>_s!='').join('');\n\nvar ss = {};\nfor(var i=0;i(ss[i]==undefined?0:ss[i])){\n can = false;\n break; \n }\n}\n\n\nprint(can?'YES':'NO')\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nvar whitespaceGlobalRegex = /\\s+/g;\n\nfunction removeWhitespace(s) {\n\treturn s.replace(whitespaceGlobalRegex, \"\");\n}\n\nfunction main() {\n\tvar sourceText = removeWhitespace(readline()),\n\t\ttargetText = removeWhitespace(readline());\n\n\tvar characterCounts = {};\n\tfor (var characterIndex = sourceText.length-1; characterIndex >= 0; --characterIndex) {\n\t\tvar character = sourceText.charAt(characterIndex);\n\t\tif (characterCounts[character] === undefined) {\n\t\t\tcharacterCounts[character] = 1;\n\t\t}\n\t\telse {\n\t\t\tcharacterCounts[character] += 1;\n\t\t}\n\t}\n\n\tfor (var characterIndex = targetText.length-1; characterIndex >= 0; --characterIndex) {\n\t\tvar character = targetText.charAt(characterIndex);\n\t\tif (characterCounts[character] === undefined || characterCounts[character] == 0) {\n\t\t\tprint(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tcharacterCounts[character] -= 1;\n\t}\n\n\tprint(\"YES\");\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet s1 = readline()\nlet s2 = readline()\n\nlet ls = {}\n\nfor (let i = 0; i < s1.length; i++) {\n let l = s1[i]\n if (l == ' ') continue\n ls[l] = ls[l] || 0\n ls[l]++\n}\nlet r = true\nfor (let i = 0; i < s2.length; i++) {\n let l = s2[i]\n if (l == ' ') continue\n if (!ls[l]) {\n r = false\n break\n }\n ls[l]--\n}\n\nprint(r ? 'YES' : 'NO')"}, {"source_code": "function checkAnonymousLetter (title, letter) {\n var index = {},\n canMakeLetter = true;\n\n debugger\n\n title.replace(/\\s/g, \"\").split(\"\").forEach(function (item) {\n if (index[item] === undefined) {\n index[item] = 1;\n } else {\n index[item]++;\n }\n });\n\n letter.replace(/\\s/g, \"\").split(\"\").forEach(function (item) {\n if (index[item] && canMakeLetter) {\n if (index[item] === 0) {\n canMakeLetter = false;\n } else {\n index[item]--;\n }\n } else {\n canMakeLetter = false;\n }\n });\n\n return canMakeLetter;\n}\n\nvar title = readline(),\n letter = readline();\n\nvar output = checkAnonymousLetter.call(null, title, letter) ? \"YES\" : \"NO\";\n\nwrite(output);\n"}, {"source_code": "var header = readline().replace(/ /g,'');\nvar text = readline().replace(/ /g,'');\nvar hash = {};\n\nfor (var i = 0; i < header.length; i++) {\n\tif (hash.hasOwnProperty(header[i])) {\n\t\thash[header[i]]++;\n\t} else {\n\t\thash[header[i]] = 1;\n\t}\n}\n\nfunction isPossible() {\n\tfor (var j = 0; j < text.length; j++) {\n\t\tif (hash[text[j]]) {\n\t\t\thash[text[j]]--;\n\t\t} else {\n\t\t\treturn 'NO';\n\t\t}\n\t}\n\treturn 'YES';\n}\n\nprint(isPossible());"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar ans = \"YES\", indicator = 0, myMap = {};\n\nrl.on('line', (input) => {\n\n if (indicator == 0) {\n /*\n input.forEach(element => {\n if (element != ' ') {\n\n if (element in myMap)\n myMap[element]++;\n else myMap[element] = 1;\n }\n });*/\n for (let i = 0; i < input.length; i++) {\n if (input[i] == ' ')\n continue;\n\n if (input[i] in myMap)\n myMap[input[i]]++;\n else myMap[input[i]] = 1;\n\n }\n indicator++;\n }\n else {\n\n for (let i = 0; i < input.length; i++) {\n if (input[i] == ' ')\n continue;\n if (myMap[input[i]] > 0)\n myMap[input[i]]--;\n else {\n ans = \"NO\";\n break;\n }\n }\n console.log(ans);\n rl.close();\n }\n});"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet h = readLine().split('');\n\tlet str = readLine().split('');\n\n\tlet c = 0;\n\n\tfor (let i = 0, l = str.length; i < l; i++) {\n\t\tlet index = h.indexOf(str[i]);\n\t\tif (index > -1) {\n\t\t\tc++;\n\t\t\th.splice(index, 1);\n\t\t}\n\t}\n\n\tif (c === str.length) console.log('YES');\n\telse console.log('NO');\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet h = readLine().split('');\n\tlet str = readLine().split('');\n\n\tlet c = 0;\n\n\tfor (let i = 0, l = str.length; i < l; i++) {\n\t\tif (h.indexOf(str[i]) > -1) c++;\n\t}\n\n\tif (c === str.length) console.log('YES');\n\telse console.log('NO');\n}\n"}, {"source_code": "\ufeffvar stZag, stText, stt;\nvar mask = new Array(300);\n\nfunction r() {\n stZag = readline();\n stText = readline();\n};\n\n+function main() {\n for (var i = 0; i < 300; i++) {\n mask[i] = false;\n }\n\n r();\n stt = \"\";\n for (var i = 0; i < stText.length; ++i) {\n if (stText.charAt(i) != ' ' && stText.charAt(i) != '\t') {\n stt += stText.charAt(i);\n }\n }\n\n stText = \"\";\n\n\n for (var i = 0; i < stt.length; ++i) {\n stText += stt.charAt(i);\n }\n\n stt = \"\";\n\n for (var i = 0; i < stZag.length ; ++i) {\n if (stZag.charAt(i) != ' ' && stZag.charAt(i) != '\t') {\n stt += stZag.charAt(i);\n }\n }\n\n stZag = \"\";\n for (var i = 0; i < stt.length ; ++i) {\n stZag += stt.charAt(i);\n }\n stt = \"\";\n\n\n\n print(stZag);\n print(stText);\n\n for (var i = 0; i < stText.length; ++i) {\n var tek = stText.charAt(i);\n\n for (var j = 0; j < stZag.length; ++j) {\n if (mask[j] != true) {\n if (tek == stZag.charAt(j)) {\n mask[j] = true;\n break;\n }\n }\n\n if (j == stZag.length - 1) {\n print(\"NO\\n\");\n // cout << \"NO\" << endl;\n return 0;\n }\n }\n }\n\n print(\"YES\\n\");\n return 0;\n}();"}], "src_uid": "b1ef19d7027dc82d76859d64a6f43439"} {"source_code": "var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++) {\r\n var caseConstraints = readline().split(\" \");\r\n var guestLength = parseInt(caseConstraints[0]);\r\n var giftLength = parseInt(caseConstraints[1]);\r\n var guestArray = readline().split(\" \");\r\n var giftArray = readline().split(\" \");\r\n var guestIntArray = new Array();\r\n for (var _i = 0, guestArray_1 = guestArray; _i < guestArray_1.length; _i++) {\r\n var element = guestArray_1[_i];\r\n guestIntArray.push(parseInt(element));\r\n }\r\n guestIntArray.sort(function (a, b) { return b - a; });\r\n var total = 0;\r\n var flag = true;\r\n for (var j = 0; j < guestLength; j++) {\r\n if (j < giftLength) {\r\n if (guestIntArray[j] - 1 < giftLength) {\r\n if (parseInt(giftArray[guestIntArray[j] - 1]) < parseInt(giftArray[j])) {\r\n flag = false;\r\n }\r\n }\r\n total += (flag) ? parseInt(giftArray[j]) : parseInt(giftArray[guestIntArray[j] - 1]);\r\n }\r\n else {\r\n total += parseInt(giftArray[guestIntArray[j] - 1]);\r\n }\r\n }\r\n print(total);\r\n }", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, m] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var k = readline().split(' ').map(x => {\r\n return Number(x) - 1\r\n });\r\n var c = readline().split(' ').map(x => {\r\n return Number(x)\r\n });\r\n k = k.sort((a, b) => b - a)\r\n var sum = 0\r\n var j = 0\r\n k.map((x, i) => {\r\n if (c[j] < c[x]) {\r\n sum += c[j]\r\n j++\r\n } else {\r\n sum += c[x]\r\n }\r\n\r\n // console.log(sum)\r\n\r\n })\r\n\r\n console.log(sum)\r\n\r\n })\r\n\r\n\r\n}\r\n"}, {"source_code": "let i = '';\r\n\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 3; i += 3) {\r\n let split = lines[i].split(' ');\r\n const n = parseInt(split[0]);\r\n const m = parseInt(split[1]);\r\n\r\n const k = lines[i + 1].split(' ').map(num => parseInt(num));\r\n const c = lines[i + 2].split(' ').map(num => parseInt(num));\r\n\r\n const result = solve(n, m, k, c);\r\n\r\n console.log(result);\r\n }\r\n});\r\n\r\nfunction solve(n, m, k, c) {\r\n let sum = 0;\r\n\r\n k.sort((a, b) => b - a);\r\n\r\n let j = 1;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (j < k[i]) {\r\n sum += c[j - 1];\r\n j++;\r\n } else {\r\n sum += c[k[i] - 1];\r\n }\r\n }\r\n\r\n return sum;\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst k = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tk.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = 0, l = 0;\r\n\t\tfor (const i of k) {\r\n\t\t\tif (c[l] < c[i-1]) {\r\n\t\t\t\tans += c[l]; l++;\r\n\t\t\t} else {\r\n\t\t\t\tans += c[i-1];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst k = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tk.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst st = c.slice().reverse();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (st.length && st[st.length-1] < c[k[i]-1]) {\r\n\t\t\t\tans += st.pop();\r\n\t\t\t} else {\r\n\t\t\t\tans += c[k[i]-1];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/*\r\n * File Created: Wednesday, 6th January 2021 9:38:39 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const [n, m ] = readLine().split(' ').map(Number); \r\n\r\n const k = readLine().split(' ').map(Number);\r\n\r\n const c = readLine().split(' ').map(Number);\r\n\r\n const res = a(n,m,k,c);\r\n \r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,m,guests,c){\r\n let count = 0;\r\n guests.sort((a,b) => b - a);\r\n for(let i = 0; i < guests.length; i++){\r\n const gift = c[guests[i] - 1];\r\n const money = c[i];\r\n count += Math.min(gift, money ? money : gift);\r\n // console.log('gift = ', gift, 'money = ', money, 'count = ', count);\r\n }\r\n return count;\r\n}\r\n\r\nmodule.exports = a;"}], "negative_code": [], "src_uid": "55962ef2cf88c87873b996dc54cc1bf1"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.line().split('');\n\t\tlet r = new Array(26);\n\t\ta.forEach((e) => {\n\t\t\tlet x = e.charCodeAt(0) - 'a'.charCodeAt(0);\n\t\t\tif (r[x]) {\n\t\t\t\tr[x]++;\n\t\t\t} else {\n\t\t\t\tr[x] = 1;\n\t\t\t}\n\t\t});\n\t\tlet cnt = r.reduce((ac, e) => ac + (e?(e>2?2:e):0), 0);\n\t\tans.push(Math.floor(cnt / 2));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var str = lines[l++]\n console.log(solve(str))\n }\n});\n\nfunction solve(str) {\n const map = {}\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]\n map[ch] = (map[ch] || 0) + 1\n }\n\n let a = 0\n let b = 0\n for (let k in map) {\n const count = map[k]\n if (count > 1) {\n a++\n } else {\n b++\n }\n }\n return a + Math.floor(b / 2)\n}\n"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n var aCode = 'a'.charCodeAt(0);\n for (var i = 0; i < str.length; i++)\n letters[str.charCodeAt(i) - aCode]++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(k);\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n\r\nfunction wonderfulColoring(str) {\r\n var l = createEmptyArr(26);\r\n \r\n for(var j = 0; j < str.length; j++) {\r\n l[str[j].charCodeAt(0)-'a'.charCodeAt(0)]++; \r\n }\r\n \r\n var c1 = 0, c2 = 0;\r\n \r\n for(var j = 0; j < l.length; j++) {\r\n if(!l[j]) {\r\n continue;\r\n }\r\n if(l[j] > 1) {\r\n c1++;\r\n continue;\r\n }\r\n c2++;\r\n }\r\n \r\n return Math.floor(c1 + c2 / 2);\r\n}\r\n\r\nconst n = readNum();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n print(wonderfulColoring(readStr()));\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var str = readStr();\r\n var l = [];\r\n \r\n for(var j=0; j<26; j++) {\r\n l[j]=0;\r\n }\r\n \r\n for(var j = 0; j < str.length; j++) {\r\n l[str[j].charCodeAt(0)-'a'.charCodeAt(0)]++; \r\n }\r\n \r\n var c1 = 0, c2 = 0;\r\n \r\n for(var j = 0; j < l.length; j++) {\r\n if(!l[j]) {\r\n continue;\r\n }\r\n if(l[j] > 1) {\r\n c1++;\r\n continue;\r\n }\r\n c2++;\r\n }\r\n \r\n print(Math.floor(c1 + c2 / 2));\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n \r\nconst n = readNum();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var str = readStr();\r\n var l = {};\r\n \r\n for(var j = 0; j < str.length; j++) {\r\n l[str[j]] = l[str[j]] ? l[str[j]] + 1 : 1; \r\n }\r\n \r\n var keys = Object.keys(l);\r\n \r\n var c1 = 0, c2 = 0;\r\n \r\n for(var j = 0; j < keys.length; j++) {\r\n if(l[keys[j]] > 1) {\r\n c1++;\r\n continue;\r\n }\r\n c2++;\r\n if(c2 === 2) {\r\n c2 = 0;\r\n c1++;\r\n }\r\n }\r\n \r\n print(c1);\r\n}\r\n"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n \r\nconst n = readNum();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var str = readStr();\r\n var l = {};\r\n \r\n for(var j = 0; j < str.length; j++) {\r\n l[str[j]] = l[str[j]] ? l[str[j]] + 1 : 1; \r\n }\r\n \r\n var keys = Object.keys(l);\r\n \r\n var c1 = 0, c2 = 0;\r\n \r\n for(var j = 0; j < keys.length; j++) {\r\n if(l[keys[j]] > 1) {\r\n c1++;\r\n continue;\r\n }\r\n c2++;\r\n }\r\n \r\n print(Math.floor(c1 + c2 / 2));\r\n}\r\n"}, {"source_code": "var t = readline();\r\nwhile(t--)\r\n{\r\n var s = readline();\r\n var arr = new Array(26);\r\n for(var i=0;i<26;i++)\r\n {\r\n arr[i]=0;\r\n }\r\n for(var i=0;i {\r\n if(x>1)\r\n {\r\n res++;\r\n }\r\n else if(x==1)\r\n {\r\n temp++;\r\n if(temp==2)\r\n {\r\n res++;\r\n temp=0;\r\n }\r\n }\r\n });\r\n print(res);\r\n}"}, {"source_code": "var input = readline();\r\nfor(var i = 0; i < input; i ++) {\r\n var arr = readline().split('').sort();\r\n var sum = 1;\r\n var len =arr.length;\r\n for(var j = 1; j < arr.length ; j ++) {\r\n if(arr[j] === arr[j - 1]) sum ++;\r\n else {\r\n if(sum > 2) len -= sum - 2;\r\n sum = 1;\r\n }\r\n }\r\n if(sum > 2) len -= sum - 2;\r\n print(Math.floor(len / 2));\r\n}"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var repeted = new Map();\n var nrepeted = new Map();\n var ans = 0;\n var a = 0;\n var k = lines[i].split('');\n for(j = 0; j < k.length; j++){\n if(nrepeted.get(k[j]) == 1){\n ans++;\n nrepeted.set(k[j], 0);\n a++;\n repeted.set(k[j], 1);\n }else if(repeted.get(k[j]) === undefined){\n nrepeted.set(k[j], 1);\n }\n }\n ans += Math.floor((nrepeted.size - a) / 2);\n console.log(ans);\n }\n});\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let string = readLine();\r\n let cnt = {}\r\n for (let i = 0; i < string.length; i++) {\r\n let char = string[i];\r\n if (!(char in cnt)) {\r\n cnt[char] = 0;\r\n }\r\n cnt[char]++;\r\n }\r\n let c = 0, ones = 0;\r\n for (let char in cnt) {\r\n if (cnt[char] >= 2) {\r\n c++;\r\n } else if (cnt[char] === 1) {\r\n ones++;\r\n }\r\n }\r\n print(c + Math.floor(ones / 2));\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let str = readLine();\r\n let map = new Map();\r\n if (str.length == 1) return 0;\r\n for (let i = 0; i < str.length; i++) {\r\n const element = str[i];\r\n if (map.has(element)) map.set(element, map.get(element) + 1)\r\n else map.set(element, 1)\r\n }\r\n let res = Array.from(map.values()).reduce((acc, cur) => {\r\n if (cur > 1)\r\n return acc + 2;\r\n return acc + 1;\r\n\r\n }, 0)\r\n return parseInt(res / 2);\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst a = rl();\r\n\t\tconst n = a.length;\r\n\t\tconst k = 2;\r\n\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (mp.has(a[i]))\r\n\t\t\t\tmp.get(a[i]).push(i);\r\n\t\t\telse\r\n\t\t\t\tmp.set(a[i], [i]);\r\n\t\t}\r\n\r\n\t\tconst avl = [];\r\n\t\tfor (const [elm, indxs] of mp) {\r\n\t\t\tfor (let i = 0 ; i < indxs.length && i < k; i++) {\r\n\t\t\t\tavl.push(indxs[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tconst cnt = Math.floor(avl.length/k)*k/2;\r\n\r\n\t\tconsole.log(cnt);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let str = input[z++].trim().split('');\r\n let obj = {};\r\n let result = 0;\r\n let oneCount = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n if(!obj[str[i]]){\r\n obj[str[i]] = 1;\r\n }\r\n else obj[str[i]]++;\r\n }\r\n\r\n for (const key in obj) {\r\n if(obj[key] == 1) oneCount++;\r\n else if(obj[key] > 1) result++;\r\n }\r\n result += Math.floor(oneCount / 2);\r\n //console.log(obj);\r\n console.log(result);\r\n }\r\n}"}, {"source_code": "const fs = require('fs');\r\n\r\nconst input = String(fs.readFileSync(0))\r\n .split('\\n')\r\n .filter(Boolean)\r\n .map((str) => str.trim());\r\n\r\nfor (let i = 1; i < input.length; i += 1) {\r\n const str = input[i];\r\n\r\n console.log(solve(str));\r\n}\r\n\r\nfunction solve(str) {\r\n let rcount = 0;\r\n const counts = {};\r\n\r\n str.split('').forEach((ch) => {\r\n if (!counts[ch]) {\r\n counts[ch] = 1;\r\n } else {\r\n counts[ch] += 1;\r\n }\r\n });\r\n\r\n let lonerCount = 0;\r\n\r\n Object.values(counts).forEach((count) => {\r\n if (count === 1) {\r\n lonerCount += 1;\r\n } else {\r\n rcount += 1;\r\n }\r\n });\r\n\r\n return rcount + Math.floor(lonerCount / 2);\r\n}"}, {"source_code": "let i = ''\r\nlet lines;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n lines = i.split('\\r\\n'); // your input text, split by lines\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(lines.shift());\r\n\r\n while (t > 0) {\r\n let a = lines.shift().split('');\r\n \r\n if (a.length === 1) {\r\n console.log(0);\r\n } else if (new Set(a).size === a.length) {\r\n console.log(Math.floor(a.length / 2));\r\n } else {\r\n const repeat = new Set();\r\n let unique = 0;\r\n for (letter of a) {\r\n const occurr = a.reduce((prev, curr) => (curr === letter ? prev + 1 : prev), 0);\r\n if (occurr > 1) {\r\n repeat.add(letter);\r\n } else {\r\n unique++;\r\n }\r\n }\r\n console.log(repeat.size + Math.floor(unique / 2));\r\n }\r\n\r\n t--;\r\n }\r\n}"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL);\r\n \r\n // iter lines\r\n const cases = lines[0] - 0;\r\n const ans = [];\r\n\r\n for (let i = 1; i <= cases; i++) {\r\n const map = {};\r\n // read line and split by '' and count each char as map\r\n lines[i].split('').map(c => (map[c] = (map[c] || 0) + 1));\r\n // print map\r\n // console.log(map);\r\n // count number of chars that have appear more than once and remove that char from map\r\n const mores = Object.keys(map).filter(c => map[c] >= 2).length;\r\n const less = Object.keys(map).filter(c => map[c] < 2);\r\n // console.log(mores);\r\n // less div 2 floor\r\n // console.log(Math.floor(less.length / 2));\r\n ans.push(mores + Math.floor(less.length / 2));\r\n }\r\n\r\n // console.log(ans);\r\n // print ans each line\r\n for (let i = 0; i < ans.length; i++) {\r\n console.log(ans[i]);\r\n }\r\n\r\n})"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/23/21 morning\r\n * https://codeforces.com/contest/1551/problem/B\r\n */\r\nconst solve = (s) => {\r\n // pr(s)\r\n let m = counter(s);\r\n // pr(m);\r\n let used = new Set();\r\n let red = green = 0;\r\n for (const [c, occ] of m) {\r\n if (used.has(c)) continue;\r\n if (occ >= 2) {\r\n red++;\r\n green++;\r\n m.delete(c);\r\n }\r\n used.add(c);\r\n }\r\n // pr(red, green);\r\n // pr(m);\r\n let n = m.size;\r\n let rest = n & 1 ? (n - 1) / 2: n / 2;\r\n pr(red + rest)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0];\n var a = 0;\n for(var l = 1; l <= n; l++){\n var k = lines[l].split('');\n for(var j = 1; j <= n; j++){\n if(k[j] == j[j-1]){\n a++;\n }\n }\n if(Number(a) == Number(k.length)){\n console.log(1);\n }else{\n console.log(Math.floor(k.length / 2));\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0];\n var a = 0;\n for(var l = 1; l <= n; l++){\n var k = lines[l].split('');\n for(var j = 1; j <= n; j++){\n if(k[j] == j[j-1]){\n a++;\n }\n }\n if(a == k.length){\n console.log(1);\n }else{\n console.log(Math.floor(k.length / 2));\n }\n }\n});"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let string = readLine();\r\n let cnt = {}\r\n for (let i = 0; i < string.length; i++) {\r\n cnt[string[i]] = 0;\r\n }\r\n for (let i = 0; i < string.length; i++) {\r\n let char = string[i];\r\n cnt[char]++;\r\n }\r\n let c = 0;\r\n for (let char in cnt) {\r\n if (cnt[char] >= 2) {\r\n c++;\r\n }\r\n }\r\n print(c);\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let string = readLine();\r\n let cnt = {}\r\n for (let i = 0; i < string.length; i++) {\r\n let char = string[i];\r\n cnt[char]++;\r\n }\r\n let c = 0;\r\n for (let char in cnt) {\r\n if (cnt[char] >= 2) {\r\n c++;\r\n }\r\n }\r\n print(c);\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let str = readLine();\r\n let mid = parseInt(str.length / 2);\r\n let map = new Map();\r\n if (str.length == 1) return 0;\r\n map.set(1, new Set());\r\n map.set(0, new Set());\r\n for (let i = 0; i < str.length; i++) {\r\n const element = str[i];\r\n if (map.get(1).size != mid && !map.get(1).has(element)) {\r\n map.get(1).add(element);\r\n } else if (map.get(0) != mid && !map.get(0).has(element)) {\r\n map.get(0).add(element);\r\n }\r\n }\r\n return map.get(1).size;\r\n}\r\n"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n var aCode = 'a'.charCodeAt(0);\n for (var i = 0; i < str.length; i++)\n letters[str.charCodeAt(i) - aCode]++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(str.charCodeAt(0) - aCode);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n var aCode = 'a'.charCodeAt(0);\n for (var i = 0; i < str.length; i++)\n letters[str.charCodeAt(i) - aCode]++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(str.charCodeAt(i) - aCode);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(str[0]);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(str[0] - 'a');\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(letters.length);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(k);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = [new Array(26)];\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.min(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(k);\n}"}, {"source_code": "\nvar n = readline();\nfor (var r = 0; r < n; r++) {\n var str = readline();\n var letters = new Array(26);\n for (var i = 0; i < 26; i++)\n letters[i] = 0;\n\n for (var i = 0; i < str.length; i++)\n letters[str[i] - 'a']++;\n\n var k = 0;\n for (var i = 0; i < letters.length; i++)\n k += Math.max(2, letters[i]);\n\n k = Math.floor(k / 2);\n\n print(k);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n var letters = {};\n var redCount = 0;\n var greenCount = 0;\n for (var x = 0; x < str.length; x++) {\n if (!letters[str[x]])\n letters[str[x]] = [];\n\n if (redCount > greenCount) {\n if (!letters[str[x]].includes('g')) {\n greenCount++;\n letters[str[x]].push('g')\n } else if (!letters[str[x]].includes('r')) {\n redCount++;\n letters[str[x]].push('r')\n }\n } else {\n if (!letters[str[x]].includes('r')) {\n redCount++;\n letters[str[x]].push('r')\n } else if (!letters[str[x]].includes('g')) {\n greenCount++;\n letters[str[x]].push('g')\n }\n }\n }\n if (redCount > greenCount) redCount--;\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n var letters = {};\n var redCount = 0;\n var greenCount = 0;\n for (var x = 0; x < str.length; x++) {\n if (!letters[str[x]])\n letters[str[x]] = [];\n\n if (redCount > greenCount) {\n if (!letters[str[x]].includes('g')) {\n greenCount++;\n letters[str[x]].push('g')\n } else if (!letters[str[x]].includes('r')) {\n redCount++;\n letters[str[x]].push('r')\n }\n } else {\n if (!letters[str[x]].includes('r')) {\n redCount++;\n letters[str[x]].push('r')\n } else if (!letters[str[x]].includes('g')) {\n greenCount++;\n letters[str[x]].push('g')\n }\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var letters = {};\n var redCount = 0;\n for (var x = 0; x < str.length; x++) {\n if (!letters[str[x]])\n letters[str[x]] = 0;\n if (letters[str[x]] === 0) {\n redCount++;\n letters[str[x]]++;\n } else if (letters[str[x]] === 1) {\n letters[str[x]]++;\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var letters = {};\n var redCount = 0;\n for (var x = 0; x < str.length; x++) {\n // var index = str[x] - 'a';\n if (!letters[str[x]])\n letters[str[x]] = 0;\n print(letters[str[x]])\n if (letters[str[x]] === 0) {\n redCount++;\n letters[str[x]]++;\n } else if (letters[str[x]] === 1) {\n letters[str[x]]++;\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var letters = {};\n var redCount = 0;\n for (var x = 0; x < str.length; x++) {\n // var index = str[x] - 'a';\n if (letters[str[x]])\n letters[str[x]] = 0;\n print(str[x])\n if (letters[str[x]] === 0) {\n redCount++;\n letters[str[x]]++;\n } else if (letters[str[x]] === 1) {\n letters[str[x]]++;\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var letters = {};\n var redCount = 0;\n for (var x = 0; x < str.length; x++) {\n // var index = str[x] - 'a';\n if (letters[str[x]])\n letters[str[x]] = 0;\n print(letters['k'])\n if (letters[str[x]] === 0) {\n redCount++;\n letters[str[x]]++;\n } else if (letters[str[x]] === 1) {\n letters[str[x]]++;\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var letters = {};\n var redCount = 0;\n for (var x = 0; x < str.length; x++) {\n // var index = str[x] - 'a';\n if (letters[str[x]])\n letters[str[x]] = 0;\n print(letters)\n if (letters[str[x]] === 0) {\n redCount++;\n letters[str[x]]++;\n } else if (letters[str[x]] === 1) {\n letters[str[x]]++;\n }\n }\n print(redCount);\n}"}, {"source_code": "\nvar n = readline();\nfor (var i = 0; i < n; i++) {\n var str = readline();\n //var letters = Array.from({ length: 26 }, 0);\n var redCount = 2;\n // for (var x = 0; x < str.length; x++) {\n // var index = str[x] - 'a';\n // if (letters[index] === 0) {\n // redCount++;\n // letters[index]++;\n // } else if (letters[index] === 1) {\n // letters[index]++;\n // }\n // }\n print(redCount);\n}"}, {"source_code": "var t = readline();\r\nwhile(t--)\r\n{\r\n var s = readline();\r\n var arr = new Array(26);\r\n for(var i=0;i {\r\n if(x>1) res++;\r\n else if(temp==2)\r\n {\r\n res++;\r\n temp=0;\r\n }\r\n else temp++;\r\n });\r\n print(res);\r\n}"}, {"source_code": "var input = readline();\r\nfor(var i = 0; i < input; i ++) {\r\n var arr = readline().split('').sort();\r\n var sum = 1;\r\n var len =arr.length;\r\n for(var j = 1; j < arr.length ; j ++) {\r\n if(arr[j] === arr[j - 1]) sum ++;\r\n else {\r\n if(sum > 2) len -= sum - 2;\r\n sum = 0;\r\n }\r\n }\r\n if(sum > 2) len -= sum - 2;\r\n print(Math.floor(len / 2));\r\n}"}], "src_uid": "a6b760941ab8be2c32c6dc66c623ea0e"} {"source_code": "const ascending = (x, y) => x - y;\nconst descending = (x, y) => y - x;\nconst log = console.log;\n\n\nfunction solve(input) {\n input = input.toString().split(/\\r?\\n/);\n\n let inputRow = 0;\n let n = +input[inputRow++];\n let a = input[inputRow++].split(' ').map(x => +x);\n\n let ans = 0;\n let d = {};\n let offset = 0;\n let lpos = -1;\n for (let i = 0; i < n; i++) {\n\n let pos = d[-a[i] - offset];\n if (a[i] == 0) {\n lpos = i;\n } else if (typeof(pos) !== 'undefined') {\n // log('pos = ' + pos);\n lpos = Math.max(lpos, pos);\n }\n ans += i - lpos;\n\n d[-offset] = i;\n offset += a[i];\n // log(d, offset, ans);\n\n }\n\n let res = [];\n res.push(ans);\n return res.join('\\n');\n}\n\nasync function main() {\n\n try {\n\n let input = await new Promise(resolve => {\n\n let _input = '';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (buf) => {\n _input += buf;\n });\n process.stdin.on('end', () => {\n resolve(_input);\n });\n\n });\n let output = solve(input);\n\n console.log(output);\n\n } catch (err) {\n console.error(err);\n }\n}\n\nmain();\n", "positive_code": [{"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, a) {\n let sum = 0;\n let myMap = new Map([[0, -1]]);\n let count = 0;\n let limit = -2;\n a.forEach((val, i) => {\n sum += val;\n if (myMap.has(sum)) {\n const begin = myMap.get(sum);\n limit = Math.max(limit, begin);\n }\n count += i - limit - 1;\n myMap.set(sum, i);\n })\n return count;\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const n = readLine()[0];\n const a = readLine();\n console.log(solve(n, a));\n}\n"}], "negative_code": [{"source_code": "const ascending = (x, y) => x - y;\nconst descending = (x, y) => y - x;\nconst log = console.log;\n\n\nfunction solve(input) {\n input = input.toString().split(/\\r?\\n/);\n\n let inputRow = 0;\n let n = +input[inputRow++];\n let a = input[inputRow++].split(' ').map(x => +x);\n\n let ans = 0;\n let d = {};\n let offset = 0;\n for (let i = 0; i < n; i++) {\n\n \n let pos = d[-a[i] - offset];\n if (typeof(pos) !== 'undefined') {\n // log('pos = ' + pos);\n ans += i - pos;\n } else {\n ans += i + 1;\n }\n\n d[-offset] = i;\n offset += a[i];\n // log(d, offset, ans);\n\n }\n\n let res = [];\n res.push(ans);\n return res.join('\\n');\n}\n\nasync function main() {\n\n try {\n\n let input = await new Promise(resolve => {\n\n let _input = '';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (buf) => {\n _input += buf;\n });\n process.stdin.on('end', () => {\n resolve(_input);\n });\n\n });\n let output = solve(input);\n\n console.log(output);\n\n } catch (err) {\n console.error(err);\n }\n}\n\nmain();\n"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, a) {\n let sum = 0;\n let myMap = new Map([[0, -1]]);\n let count = 0;\n a.forEach((val, i) => {\n sum += val;\n if (myMap.has(sum)) {\n const begin = myMap.get(sum);\n count += i - begin - 1;\n }\n else count += i + 1;\n myMap.set(sum, i);\n })\n return count;\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const n = readLine()[0];\n const a = readLine();\n console.log(solve(n, a));\n}\n"}], "src_uid": "61fb771f915b551a9bcce90c74e0ef64"} {"source_code": "var n = readline();\nvar arr = readline().split(\" \");\narr.sort(function(a,b){\n\treturn a-b;\n});\nvar res = [];\nvar q = n-1;\nvar p = 0;\n\nfor(var i = 0; i < n; i++){\n\tif(i&1) res.push(arr[q--]);\n\telse res.push(arr[p++]);\n}\nprint(res.join(' '));\n", "positive_code": [{"source_code": " //var arr = [1,3, 2, 2 ,5,34];\n//var n = [6];\n\nvar n = Number(readline());\nvar arr = readline().split(' ').map(Number);\nvar impossible = 'impossible';\n\narr.sort(function(a,b){return a-b;});\n\nvar res = [];\n\nwhile(arr.length){\n res.push(arr.shift());\n res.push(arr.pop());\n}\n\nif(n % 2){\n res = res.slice(0,n);\n}\n\nres.map(function(i){print(i)+' ';});\n\n//console.log(res);\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let ok = true;\n const result = [];\n\n arr.sort((a, b) => a - b);\n\n for (let i = 1, j = len - 1; i < len; i += 2) {\n result[i] = arr[j--];\n }\n\n for (let i = 0, j = 0; i < len; i += 2) {\n result[i] = arr[j++];\n }\n\n for (let i = 1; i < len; i++) {\n if (i % 2 === 1) {\n if (result[i] < result[i - 1]) {\n ok = false;\n break;\n }\n } else {\n if (result[i] > result[i - 1]) {\n ok = false;\n break;\n }\n }\n }\n\n if (ok) {\n console.log(result.join(\" \"));\n } else {\n console.log(\"Impossible\");\n }\n}\n"}], "negative_code": [{"source_code": "var n = readline();\nvar arr = readline().split(\" \");\n\narr.sort();\nvar res = [];\nvar q = n-1;\nvar p = 0;\nfor(var i = 0; i < n; i++){\n\tif(i&1) res.push(arr[q--]);\n\telse res.push(arr[p++]);\n}\nprint(res.join(' '));\n"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \");\n\narr.sort();\nvar res = [];\nvar q = n-1;\nvar p = 0;\nfor(var i = 0; i < n; i++){\n\tif(i&1) res.push(arr[p++]);\n\telse res.push(arr[q--]);\n}\nprint(res.join(' '));\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n const odds = arr.filter((num, i) => i % 2 !== 0);\n\n for (let i = 0; i < len; i++) {\n if (i % 2 !== 0) {\n arr[i] = odds.pop();\n }\n }\n\n console.log(arr.join(\" \"));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let ok = true;\n\n arr.sort((a, b) => a - b);\n\n for (let i = 1, j = len - 1; i <= len; i++) {\n if (i % 2 === 0) {\n [arr[i - 1], arr[j]] = [arr[j], arr[i - 1]];\n j--;\n }\n }\n\n for (let i = 1; i < len; i++) {\n if (i % 2 === 1) {\n if (arr[i] < arr[i - 1]) {\n ok = false;\n break;\n }\n } else {\n if (arr[i] > arr[i - 1]) {\n ok = false;\n break;\n }\n }\n }\n\n if (ok) {\n console.log(arr.join(\" \"));\n } else {\n console.log(arr.join(\"Impossible\"));\n }\n}\n"}], "src_uid": "2401d34db475853661d6e1e1cb5a8216"} {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction add(heap, elem) {\r\n var i = heap.length;\r\n heap.push(elem);\r\n while(i > 0) {\r\n var nextI = (i - 1) >> 1;\r\n if (heap[i] <= heap[nextI]) {\r\n break;\r\n }\r\n var t = heap[i];\r\n heap[i] = heap[nextI];\r\n heap[nextI] = t;\r\n i = nextI;\r\n }\r\n}\r\n\r\nfunction extract(heap) {\r\n var result = heap[0];\r\n var i = 0;\r\n while (heap[i]) {\r\n var il = (i + 1) << 1;\r\n var ir = il - 1;\r\n if (heap[il]) {\r\n if (heap[ir]) {\r\n if (heap[il] > heap[ir]) {\r\n heap[i] = heap[il];\r\n i = il;\r\n } else {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n }\r\n } else {\r\n heap[i] = heap[il];\r\n i = il;\r\n }\r\n } else {\r\n if (heap[ir]) {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n } else {\r\n heap[i] = 0;\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n\r\n\r\n\r\nfunction solve() {\r\n read();\r\n var o = {};\r\n readArray(Number).forEach(number => {\r\n if (o[number]) {\r\n o[number]++;\r\n } else {\r\n o[number] = 1;\r\n }\r\n });\r\n var heapArr = [];\r\n Object.values(o).forEach(x => add(heapArr, x));\r\n while(true) {\r\n var n1 = extract(heapArr);\r\n var n2 = extract(heapArr);\r\n if (!n2) {\r\n write(n1);\r\n return;\r\n }\r\n if (n1 > 1) {\r\n add(heapArr, n1 - 1);\r\n }\r\n if (n2 > 1) {\r\n add(heapArr, n2 - 1);\r\n }\r\n } \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "function getInt( num ) {\r\n return parseInt( num, 10 );\r\n}\r\n\r\nvar t = parseInt( readline(), 10 );\r\n\r\nfor ( var i = 0; i < t; i++ ) {\r\n var line1 = readline();\r\n var line2 = readline().split(' ').map(getInt);\r\n var sol = solution(line2)\r\n print( sol );\r\n}\r\nfunction solution( arr) {\r\n var n = arr.length;\r\n\r\n var mapCount = {};\r\n var max = 0;\r\n arr.forEach(function(num){\r\n mapCount[num] = (mapCount[num] || 0) + 1;\r\n if(mapCount[num] > max){\r\n max = mapCount[num];\r\n }\r\n })\r\n if(max > n/2){\r\n var rest = n - max;\r\n return n - rest * 2;\r\n }\r\n return n % 2\r\n \r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction j(arr) {\r\n while(arr[arr.length - 1] === 0) {\r\n arr.pop();\r\n }\r\n}\r\n\r\nfunction add(heap, elem) {\r\n var i = heap.length;\r\n heap.push(elem);\r\n while(i > 0) {\r\n var nextI = (i - 1) >> 1;\r\n if (heap[i] <= heap[nextI]) {\r\n break;\r\n }\r\n var t = heap[i];\r\n heap[i] = heap[nextI];\r\n heap[nextI] = t;\r\n i = nextI;\r\n }\r\n}\r\n\r\nfunction extract(heap) {\r\n var result = heap[0];\r\n var i = 0;\r\n while (heap[i]) {\r\n var il = (i + 1) << 1;\r\n var ir = il - 1;\r\n if (heap[il]) {\r\n if (heap[ir]) {\r\n if (heap[il] > heap[ir]) {\r\n heap[i] = heap[il];\r\n i = il;\r\n } else {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n }\r\n } else {\r\n heap[i] = heap[il];\r\n i = il;\r\n }\r\n } else {\r\n if (heap[ir]) {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n } else {\r\n heap[i] = 0;\r\n }\r\n }\r\n }\r\n j(heap);\r\n return result;\r\n}\r\n\r\n\r\n\r\nfunction solve() {\r\n read();\r\n var o = {};\r\n readArray(Number).forEach(number => {\r\n if (o[number]) {\r\n o[number]++;\r\n } else {\r\n o[number] = 1;\r\n }\r\n });\r\n var heapArr = [];\r\n Object.values(o).forEach(x => add(heapArr, x));\r\n while(true) {\r\n var n1 = extract(heapArr);\r\n var n2 = extract(heapArr);\r\n if (!n2) {\r\n write(n1 || 0);\r\n return;\r\n }\r\n if (n1 > 1) {\r\n add(heapArr, n1 - 1);\r\n }\r\n if (n2 > 1) {\r\n add(heapArr, n2 - 1);\r\n }\r\n } \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const solve = (a) => {\n const count = {};\n let maxCount = 0;\n for (const item of a) {\n if (!count.hasOwnProperty(item)) count[item] = 0;\n count[item]++;\n maxCount = Math.max(maxCount, count[item]);\n }\n if (Object.keys(count).length === 1) return a.length;\n const diff = 2 * maxCount - a.length;\n if (diff > 0) return diff;\n return a.length % 2;\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const n = readInt();\n const a = readListInt();\n console.log(solve(a));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n let j = 1;\r\n for (let i = 1; i <= t; i++) {\r\n var n = Number(input[j]);\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n function minTransform(n, arr) {\r\n var map = new Map();\r\n var max = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n if (map.has(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1);\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n max = Math.max(max, map.get(arr[i]));\r\n }\r\n if (2 * max <= n) {\r\n return n % 2;\r\n }\r\n return max - (n - max);\r\n }\r\n console.log(minTransform(n, arr));\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var object = {}\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (!object[a[i]]) object[a[i]] = 0\r\n object[a[i]]++\r\n }\r\n var max = 0\r\n Object.keys(object).map(key => {\r\n key = parseInt(key)\r\n max =Math.max(object[key], max)\r\n })\r\nvar value = max - (n-max)\r\n if(value>0) {\r\n return console.log(value)\r\n } else {\r\n console.log(n% 2)\r\n }\r\n // console.log(object)\r\n // console.log(max, Math.floor(n/2))\r\n // console.log()\r\n })\r\n}\r\n\r\nfunction longestCommonSubstring(string1, string2) {\r\n // Convert strings to arrays to treat unicode symbols length correctly.\r\n // For example:\r\n // '\ud800\udf35'.length === 2\r\n // [...'\ud800\udf35'].length === 1\r\n const s1 = [...string1];\r\n const s2 = [...string2];\r\n\r\n // Init the matrix of all substring lengths to use Dynamic Programming approach.\r\n const substringMatrix = Array(s2.length + 1).fill(null).map(() => {\r\n return Array(s1.length + 1).fill(null);\r\n });\r\n\r\n // Fill the first row and first column with zeros to provide initial values.\r\n for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {\r\n substringMatrix[0][columnIndex] = 0;\r\n }\r\n\r\n for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {\r\n substringMatrix[rowIndex][0] = 0;\r\n }\r\n\r\n // Build the matrix of all substring lengths to use Dynamic Programming approach.\r\n let longestSubstringLength = 0;\r\n let longestSubstringColumn = 0;\r\n let longestSubstringRow = 0;\r\n\r\n for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {\r\n for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {\r\n if (s1[columnIndex - 1] === s2[rowIndex - 1]) {\r\n substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;\r\n } else {\r\n substringMatrix[rowIndex][columnIndex] = 0;\r\n }\r\n\r\n // Try to find the biggest length of all common substring lengths\r\n // and to memorize its last character position (indices)\r\n if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {\r\n longestSubstringLength = substringMatrix[rowIndex][columnIndex];\r\n longestSubstringColumn = columnIndex;\r\n longestSubstringRow = rowIndex;\r\n }\r\n }\r\n }\r\n\r\n if (longestSubstringLength === 0) {\r\n // Longest common substring has not been found.\r\n return '';\r\n }\r\n\r\n // Detect the longest substring from the matrix.\r\n let longestSubstring = '';\r\n\r\n while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {\r\n longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;\r\n longestSubstringRow -= 1;\r\n longestSubstringColumn -= 1;\r\n }\r\n\r\n return longestSubstring;\r\n}\r\n\r\n\r\n"}, {"source_code": "// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\narr = [4,2,53,21,6,88,2,1,4];\r\nn = arr.length;\r\nleftmin = [];\r\nconst minq = new PriorityQueue((a, b) => a < b);\r\nfor (a of arr) {\r\n\tminq.push(a);\r\n\tleftmin.push(minq.peek());\r\n}\r\n\r\nvar dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst cnt = new Map();\r\n\t\tfor (const elm of a) {\r\n\t\t\tcnt.set(elm, cnt.has(elm) ? cnt.get(elm) + 1 : 1);\r\n\t\t}\r\n\r\n\t\tconst q = new PriorityQueue((a, b) => a > b);\r\n\t\tfor (const vl of cnt.values()) {\r\n\t\t\tq.push(vl);\r\n\t\t}\r\n\r\n\t\twhile (q.size() > 1) {\r\n\t\t\tlet first = q.pop() - 1;\r\n\t\t\tlet second = q.pop() - 1;\r\n\r\n\t\t\tif (first) \r\n\t\t\t\tq.push(first);\r\n\t\t\tif (second)\r\n\t\t\t\tq.push(second);\r\n\t\t}\r\n\r\n\t\tconsole.log(q.size() ? q.pop() : 0);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "l=readline;\r\nfor (T=+l(); T--;print(Math.max(N%2, m-(N-m)))) {\r\n N = l();\r\n S = l().split(' ');\r\n C={}\r\n \r\n m = 0;\r\n for (i of S) {\r\n C[i] = (C[i] || 0) + 1;\r\n m = C[i] > m ? C[i] : m;\r\n }\r\n}"}], "negative_code": [{"source_code": "l=readline;\r\nfor (T=+l(); T--; ) {\r\n N = l();\r\n S = l().split(' ')\r\n C={}\r\n \r\n k = 0;\r\n a = null\r\n for (i of S) {\r\n if (a == null) {\r\n a = i;\r\n } else {\r\n if (a !== i) {\r\n if (k > 0) {\r\n k--;\r\n N-=2;\r\n } else {\r\n a = null;\r\n k = 0;\r\n N-=2;\r\n }\r\n } else {\r\n k++;\r\n }\r\n }\r\n }\r\n \r\n print(N)\r\n\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction j(arr) {\r\n while(arr[arr.length - 1] === 0) {\r\n arr.pop();\r\n }\r\n}\r\n\r\nfunction add(heap, elem) {\r\n var i = heap.length;\r\n heap.push(elem);\r\n while(i > 0) {\r\n var nextI = (i - 1) >> 1;\r\n if (heap[i] <= heap[nextI]) {\r\n break;\r\n }\r\n var t = heap[i];\r\n heap[i] = heap[nextI];\r\n heap[nextI] = t;\r\n i = nextI;\r\n }\r\n}\r\n\r\nfunction extract(heap) {\r\n var result = heap[0];\r\n var i = 0;\r\n while (heap[i]) {\r\n var il = (i + 1) << 1;\r\n var ir = il - 1;\r\n if (heap[il]) {\r\n if (heap[ir]) {\r\n if (heap[il] > heap[ir]) {\r\n heap[i] = heap[il];\r\n i = il;\r\n } else {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n }\r\n } else {\r\n heap[i] = heap[il];\r\n i = il;\r\n }\r\n } else {\r\n if (heap[ir]) {\r\n heap[i] = heap[ir];\r\n i = ir;\r\n } else {\r\n heap[i] = 0;\r\n }\r\n }\r\n }\r\n j(heap);\r\n return result;\r\n}\r\n\r\n\r\n\r\nfunction solve() {\r\n read();\r\n var o = {};\r\n readArray(Number).forEach(number => {\r\n if (o[number]) {\r\n o[number]++;\r\n } else {\r\n o[number] = 1;\r\n }\r\n });\r\n var heapArr = [];\r\n Object.values(o).forEach(x => add(heapArr, x));\r\n while(true) {\r\n var n1 = extract(heapArr);\r\n var n2 = extract(heapArr);\r\n if (!n2) {\r\n write(n1);\r\n return;\r\n }\r\n if (n1 > 1) {\r\n add(heapArr, n1 - 1);\r\n }\r\n if (n2 > 1) {\r\n add(heapArr, n2 - 1);\r\n }\r\n } \r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const solve = (a) => {\n const count = {};\n let maxCount = 0;\n for (const item of a) {\n if (!count.hasOwnProperty(item)) count[item] = 0;\n count[item]++;\n maxCount = Math.max(maxCount, count[item]);\n }\n if (Object.keys(count).length === 1) return a.length;\n return Math.max(2 * maxCount - a.length, 0);\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const n = readInt();\n const a = readListInt();\n console.log(solve(a));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map((s) => parseInt(s));\n};\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n let j = 1;\r\n for (let i = 1; i <= t; i++) {\r\n var n = Number(input[j]);\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n function minTransform(n, arr) {\r\n var map = new Map();\r\n var max = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n if (map.has(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1);\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n max = Math.max(max, map.get(arr[i]));\r\n }\r\n if (2 * max <= n) {\r\n return 0;\r\n }\r\n return max - (n - max);\r\n }\r\n console.log(minTransform(n, arr));\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var allEqual = true\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i] !== a[i + 1]) allEqual = false\r\n }\r\n if (allEqual) return console.log(n)\r\n if (n % 2 ===1) return console.log(1)\r\n console.log(0)\r\n })\r\n}\r\n\r\nfunction longestCommonSubstring(string1, string2) {\r\n // Convert strings to arrays to treat unicode symbols length correctly.\r\n // For example:\r\n // '\ud800\udf35'.length === 2\r\n // [...'\ud800\udf35'].length === 1\r\n const s1 = [...string1];\r\n const s2 = [...string2];\r\n\r\n // Init the matrix of all substring lengths to use Dynamic Programming approach.\r\n const substringMatrix = Array(s2.length + 1).fill(null).map(() => {\r\n return Array(s1.length + 1).fill(null);\r\n });\r\n\r\n // Fill the first row and first column with zeros to provide initial values.\r\n for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {\r\n substringMatrix[0][columnIndex] = 0;\r\n }\r\n\r\n for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {\r\n substringMatrix[rowIndex][0] = 0;\r\n }\r\n\r\n // Build the matrix of all substring lengths to use Dynamic Programming approach.\r\n let longestSubstringLength = 0;\r\n let longestSubstringColumn = 0;\r\n let longestSubstringRow = 0;\r\n\r\n for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {\r\n for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {\r\n if (s1[columnIndex - 1] === s2[rowIndex - 1]) {\r\n substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;\r\n } else {\r\n substringMatrix[rowIndex][columnIndex] = 0;\r\n }\r\n\r\n // Try to find the biggest length of all common substring lengths\r\n // and to memorize its last character position (indices)\r\n if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {\r\n longestSubstringLength = substringMatrix[rowIndex][columnIndex];\r\n longestSubstringColumn = columnIndex;\r\n longestSubstringRow = rowIndex;\r\n }\r\n }\r\n }\r\n\r\n if (longestSubstringLength === 0) {\r\n // Longest common substring has not been found.\r\n return '';\r\n }\r\n\r\n // Detect the longest substring from the matrix.\r\n let longestSubstring = '';\r\n\r\n while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {\r\n longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;\r\n longestSubstringRow -= 1;\r\n longestSubstringColumn -= 1;\r\n }\r\n\r\n return longestSubstring;\r\n}\r\n\r\n\r\n"}], "src_uid": "c67c376c8dcb3b3901eaf45fc50cc752"} {"source_code": "var k = readline().split( ' ' )[1] - '',\n arr = readline().split( ' ' );\n\nvar block = [],\n sum = 0,\n anss = 0,\n ansi,\n ds = [],\n di = [];\n\narr.forEach( function(item, index) {\n item -= '';\n\n sum += item;\n block.push( item );\n while (block.length > k) {\n sum -= block.shift();\n }\n\n if (index >= 2*k-1 && sum + ds[index-k] > anss) {\n anss = sum + ds[index-k];\n ansi = (di[index-k]-k+1+1) + ' ' + (index-k+1+1);\n }\n\n if (index < k || sum > ds[index-1]) {\n ds[index] = sum;\n di[index] = index;\n } else {\n ds[index] = ds[index-1];\n di[index] = di[index-1];\n }\n} );\n\nprint( ansi );", "positive_code": [{"source_code": "print(function(n, k) {\n\tvar x = readline().split(' ').map(Number);\n\tvar i, a, sum = 0;\n\tfor (i = 0; i < k; i++)\n\t\tsum += x[i];\n\n\ta = [sum];\n\tfor (i = k; i < n; i++)\n\t\ta.push(sum = sum + x[i] - x[i - k]);\n\n\n\tvar low, high, _low,\n\t\ty = 0,\n\t\tmax = 0;\n\tfor (i = k; i <= n - k; i++) {\n\n\t\tif (a[i - k] > y) {\n\t\t\ty = a[i - k];\n\t\t\t_low = i - k;\n\t\t}\n\n\t\tif (y + a[i] > max) {\n\t\t\tmax = y + a[i];\n\t\t\thigh = i;\n\t\t\tlow = _low;\n\t\t}\n\t}\n\n\tlow++;\n\thigh++;\n\treturn low + ' ' + high;\n\n}.apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(n, k) {\n\tvar x = readline().split(' ').map(Number);\n\tvar i, a, sum = 0;\n\tfor (i = 0; i < k; i++)\n\t\tsum += x[i];\n\n\ta = [sum];\n\tfor (i = k; i < n; i++)\n\t\ta.push(sum = sum + x[i] - x[i - k]);\n\n\n\tvar low, high,\n\t\ty = 0,\n\t\tmax = 0;\n\tfor (i = k; i <= n - k; i++) {\n\t\tif (a[i - k] > y) {\n\t\t\ty = a[i - k];\n\t\t\tlow = i - k;\n\t\t}\n\t\tif (y + a[k] > max) {\n\t\t\tmax = y + a[k];\n\t\t\thigh = i;\n\t\t}\n\t}\n\n\tlow++;\n\thigh++;\n\treturn low + ' ' + high;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, k) {\n\tvar x = readline().split(' ').map(Number);\n\tvar i, a, sum = 0;\n\tfor (i = 0; i < k; i++)\n\t\tsum += x[i];\n\n\ta = [sum];\n\tfor (i = k; i < n; i++)\n\t\ta.push(sum = sum + x[i] - x[i - k]);\n\n\n\tvar low, high,\n\t\ty = 0,\n\t\tmax = 0;\n\tfor (i = k; i <= n - k; i++) {\n\n\t\tif (a[i - k] > y) {\n\t\t\ty = a[i - k];\n\t\t\tlow = i - k;\n\t\t}\n\n\t\tif (y + a[i] > max) {\n\t\t\tmax = y + a[i];\n\t\t\thigh = i;\n\t\t}\n\t}\n\n\n\tlow++;\n\thigh++;\n\treturn low + ' ' + high;\n\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "\nvar k = +readline();\nvar s = readline();\nvar aa =[];\naa[0] = 0;\nfor(var i=1; i<=1e6; i++){\n\taa[i]=aa[i-1]+i;\n}\n\nif(k===0){\n\tprint( s.split(/1+/g).map(function(v){\n\t\treturn aa[v.length];\n\t}).reduce(function(a, b){ return a+b;}) );\n\tquit();\n}\n\nvar low = 0;\nvar high = 0;\nvar c = 0;\nvar ans = 0;\n// while(true){\n\tfor(; high b ? 1 : -1 }).reverse();\nprint((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = nextIntArray();\n\tlist.sort(function(a,b){\n\t\treturn a - b;\n\t});\n\tmyerr(list);\n\tfor(var i = 0; i < N - 1; i++){\n\t\tif(i % 2 == 1){\n\t\t\tlist.shift();\n\t\t}else{\n\t\t\tlist.pop();\n\t\t}\n\t}\n\tmyout(list[list.length - 1]);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number).sort((a, b) => a - b);\n console.log(arr[Math.floor((arr.length - 1) / 2)]);\n\n c++;\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let n = parseInt(input[0]);\n let data = []; input[1].split(' ').forEach( i => data.push(parseInt(i)) );\n data.sort((a, b) => a - b);\n \n if(data.length % 2 == 0)\n console.log(data[data.length/2-1]);\n else\n console.log(data[ (data.length+1) / 2 -1]);\n});\n\n"}, {"source_code": "var n = parseInt(readline());\nvar vals = readline().split(\" \").map(function(val) {\n return parseInt(val);\n}).sort(function(a,b) {\n return a - b;\n});\n\nprint(vals[Math.ceil(vals.length / 2) - 1]);"}, {"source_code": "var n = readline();\nvar nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = parseInt(n);\nnums = nums.sort(function(a, b){\n return a - b;\n});\nvar idx = Math.floor(n / 2); \nif(n % 2 === 0 )\n\tidx--;\nprint(nums[idx]);\n\n"}, {"source_code": "\n var n = parseInt(readline()); \n var a = readline().split(' ').map(x => parseInt(x));\n a = a.sort(function(a, b) {\n return a - b;\n });\n\n var turn = 1;\n var res = -1;\n\n while(a.length > 0) {\n if(turn === 0) {\n res = a.shift();\n } else {\n res = a.pop();\n }\n turn ^= 1;\n }\n\n print(res);"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = nextIntArray();\n\tlist.sort(function(a,b){\n\t\treturn a - b;\n\t});\n\tfor(var i = 0; i < N - 1; i++){\n\t\tif(i % 2 == 0){\n\t\t\tlist.shift();\n\t\t}else{\n\t\t\tlist.pop();\n\t\t}\n\t}\n\tmyout(list[list.length - 1]);\n}\n"}, {"source_code": "var n = readline();\nvar nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = parseInt(n);\nnums.sort(function(a, b){\n return a - b;\n});\nvar idx = (n / 2); \nif(n % 2 === 0 )\n\tidx--;\n\nprint(nums[idx]);\n\n"}, {"source_code": "var n = readline();\nn = parseInt(n);\nvar nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nnums.sort(function(a, b){\n return a - b;\n});\nvar idx = n / 2 - (n % 2 === 0 ? 1 : 0);\n\nprint(nums[idx]);"}, {"source_code": "var n = readline();\nvar nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nn = parseInt(n);\nnums = nums.sort(function(a, b){\n return a - b;\n});\nvar idx = (n / 2); \nif(n % 2 === 0 )\n\tidx--;\nprint(idx);\nprint(nums[idx]);\n\n"}, {"source_code": "readline();\nvar inputs = readline().split(' ').map(Number);\nvar sorted = inputs.sort(function(a, b){ return a > b ? 1 : -1 });\nprint((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);"}, {"source_code": "readline();\nvar inputs = readline().split(' ').map(Number);\nvar sorted = inputs.sort();\nprint((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2 - 1]);"}, {"source_code": "readline();\nvar inputs = readline().split(' ').map(Number);\nvar sorted = inputs.sort();\nprint((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);"}, {"source_code": " var n = parseInt(readline()); \n var a = readline().split(' ').map(x => parseInt(x));\n a = a.sort(function(a, b) {\n return a > b;\n });\n\n var turn = 1;\n var res = -1;\n\n while(a.length > 0) {\n if(turn === 1) {\n res = a.shift();\n } else {\n res = a.pop();\n }\n turn ^= 1;\n }\n\n print(res);"}, {"source_code": "\n var n = parseInt(readline()); \n var a = readline().split(' ').map(x => parseInt(x));\n a = a.sort(function(a, b) {\n return a > b;\n });\n\n var turn = 1;\n var res = -1;\n\n while(a.length > 0) {\n if(turn === 0) {\n res = a.shift();\n } else {\n res = a.pop();\n }\n turn ^= 1;\n }\n\n print(res);\n"}], "src_uid": "f93a8bd64a405233342f84542fce314d"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const map = {};\n let count = 0;\n\n for (let value of arr) {\n const hob = highestOneBit(value);\n if (map[hob]) {\n count += map[hob];\n map[hob]++;\n } else map[hob] = 1;\n }\n\n console.log(count);\n }\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var map = {};\n for(var j = 0; j < N; j++){\n var count = 0;\n while(list[j] > 0){\n list[j] = Math.floor(list[j] / 2);\n count++;\n }\n if(map[count] == null){\n map[count] = 0;\n }else{\n map[count]++;\n }\n \n }\n var all = 0;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n var c = map[key[j]];\n all += c * (c + 1) / 2;\n }\n output[i] = all;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n console.log(Arr(0, 30, i => {\n let d = 1 << i;\n let c = a.filter(v => (v & d) > 0 && v < d * 2).length;\n return c * (c - 1) / 2;\n }).sum());\n }\n})();"}], "negative_code": [], "src_uid": "04e2e1ce3f0b4efd2d4dda69748a0a25"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n if (n === 1) return `YES\\n${m}`;\r\n if (m < n) return 'NO';\r\n if (n & 1) {\r\n const res = [];\r\n for (let i = 0; i < n - 1; i++) {\r\n res.push(1);\r\n }\r\n res.push(m - (n - 1));\r\n return `YES\\n${res.join(' ')}`;\r\n } else {\r\n if (m & 1) return 'NO';\r\n const res = [];\r\n for (let i = 0; i < n / 2 - 1; i++) {\r\n res.push(1, 1);\r\n }\r\n const a = m - (n - 2);\r\n res.push(a / 2, a / 2);\r\n return `YES\\n${res.join(' ')}`;\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": ";\nvar inp = [];\nvar lines;\nvar lineCounter = 0;\nvar readline = function () { return lines[lineCounter++]; };\nprocess.stdin.on('data', function (c) { return inp.push(c); });\nprocess.stdin.on('end', function () {\n lines = inp.join('').split('\\n');\n myMain();\n});\nfunction myMain() {\n var ntest = +readline();\n var out = [];\n for (var testcount = 0; testcount < ntest; ++testcount) {\n var _a = readline().split(' ').map(function (x) { return +x; }), n = _a[0], m = _a[1];\n if (m < n) {\n out.push(\"NO\");\n continue;\n }\n if (n % 2 == 1) {\n out.push(\"YES\");\n out.push(\"\".concat(m - (n - 1)).concat(' 1'.repeat(n - 1)));\n continue;\n }\n if (m % 2 == 1) {\n out.push(\"NO\");\n continue;\n }\n if ((m - (n - 2)) <= 0) {\n out.push(\"NO\");\n continue;\n }\n out.push(\"YES\");\n var t = ((m - (n - 2)) / 2) >> 0;\n out.push(\"\".concat(t, \" \").concat(t).concat(' 1'.repeat(n - 2)));\n }\n console.log(out.join('\\n'));\n}\n"}], "negative_code": [], "src_uid": "041143f69ce9d00924ce8deb56b723c5"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\nconst calc = (n, k, h)=>{\n let result = 0n;\n\n let intervals = [];\n\n for (let i = 0; i < n; i++) {\n intervals.push([k[i] - h[i], k[i]]);\n }\n intervals = intervals.sort((i1, i2) => {\n let x = i1[0] - i2[0];\n if (x === 0) {\n return i1[1] - i2[1];\n } else {\n return x;\n }\n })\n\n let [l, r] = intervals[0];\n\n for (let i = 1; i < intervals.length; i++) {\n let [curL, curR] = intervals[i];\n if (curL < r) {\n r = Math.max(r, curR);\n } else {\n result += sumab(1, r - l);\n l = curL;\n r = curR;\n }\n }\n result += sumab(1, r - l);\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let k = ra();\n let h = ra();\n console.log(`${calc(n, k, h)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst k = rna();\r\n\t\tconst h = rna();\r\n\r\n\t\tconst st = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [L, R] = [k[i] - h[i] + 1, k[i]];\r\n\r\n\t\t\twhile (st.length) {\r\n\t\t\t\tconst [l, r] = st.pop();\r\n\t\t\t\tif (L > r) {\r\n\t\t\t\t\tst.push([l, r]);\r\n\t\t\t\t\tst.push([L, R]);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t} else if (L < l) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t} else if (L >= l) {\r\n\t\t\t\t\tst.push([l, R]);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (!st.length) {\r\n\t\t\t\tst.push([L, R]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tlet ans = 0n;\r\n\t\tfor (const [l, r] of st) {\r\n\t\t\tans += BigInt(r - l + 1) * BigInt(r - l + 2) / 2n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\nconst calc = (n, k, h)=>{\n let result = 0n;\n\n let intervals = [];\n\n for (let i = 0; i < n; i++) {\n intervals.push([k[i] - h[i], k[i]]);\n }\n intervals = intervals.sort((i1, i2) => {\n let x = i1[0] - i2[0];\n if (x === 0) {\n return i1[1] - i2[1];\n } else {\n return x;\n }\n })\n\n for (let i = 1; i < intervals.length; i++) {\n let cur = intervals[i], prev = intervals[i - 1];\n if (cur[0] < prev[1]) {\n cur[0] = prev[0];\n cur[1] = Math.max(prev[1], cur[1]);\n intervals.shift();\n i--;\n }\n }\n\n for (let i = 0; i < intervals.length; i++) {\n let cur = intervals[i];\n result += sumab(1, cur[1] - cur[0]);\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let k = ra();\n let h = ra();\n console.log(`${calc(n, k, h)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst k = rna();\r\n\t\tconst h = rna();\r\n\r\n\t\tconst st = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst [L, R] = [k[i] - h[i] + 1, k[i]];\r\n\r\n\t\t\twhile (st.length) {\r\n\t\t\t\tconst [l, r] = st.pop();\r\n\t\t\t\tif (L > r) {\r\n\t\t\t\t\tst.push([l, r]);\r\n\t\t\t\t\tst.push([L, R]);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t} else if (L < l) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t} else if (L >= l) {\r\n\t\t\t\t\tst.push([l, R]);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (!st.length) {\r\n\t\t\t\tst.push([L, R]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (const [l, r] of st) {\r\n\t\t\tans += (r - l + 1) * (r - l + 2) / 2;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "690c28ef1275035895b9154ff0e17f4c"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m, sx, sy, d] = input[index]\n .split(\" \")\n .map((item) => parseInt(item));\n const testCase = {\n n,\n m,\n sx,\n sy,\n d,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m, sx, sy, d } = testCase;\n\n if (\n (sy - d <= 1 && sy + d >= m) ||\n (sx - d <= 1 && sx + d >= n) ||\n (sx + d >= n && sy + d >= m) ||\n (sx - d <= 1 && sy - d <= 1)\n )\n console.log(-1);\n else {\n console.log(n - 1 + m - 1);\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m, sx, sy, d] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m, sx, sy, d)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, sx, sy, d) {\n sx--; sy--\n if (!ok(0, 0) || !ok(n - 1, m - 1)) return -1\n const top = !ok(0, sy)\n const bottom = !ok(n - 1, sy)\n const left = !ok(sx, 0)\n const right = !ok(sx, m - 1)\n if (top && bottom || top && left\n || bottom && right || left && right) return -1\n return n + m - 2\n function ok(i, j) {\n return Math.abs(sx - i) + Math.abs(sy - j) > d\n }\n}\n"}, {"source_code": "l = readline();\r\nwhile (l--) {\r\n a = readline().split(' ')\r\n n = +(a[0])\r\n m = +(a[1])\r\n sx = +(a[2])\r\n sy = +(a[3])\r\n d = +(a[4]) \r\n\tprint((sx - d <= 1 || sy + d >= m) && (sx + d >= n || sy - d <= 1) ? -1 : n+m-2 );\r\n}"}, {"source_code": "var repeatTimes = readline();\r\n\r\nwhile (repeatTimes--) {\r\n var a = readline().split(' ')\r\n var n = parseInt(a[0])\r\n var m = parseInt(a[1])\r\n var sx = parseInt(a[2])\r\n var sy = parseInt(a[3])\r\n var d = parseInt(a[4]) \r\n if(((sx - d <= 1 || sy + d >= m) && (sx + d >= n || sy - d <= 1)))\r\n\t\t\t\tprint(-1);\r\n\t\t\telse\t\t\t\r\n\t\t\t\tprint(n+m-2);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n var n, m, sx, sy, d;\r\n\r\n for (var t=0; t < tests; t++) {\r\n var a = readline().split(' ').map(x=>parseInt(x));\r\n n = a[0];\r\n m = a[1];\r\n sx = a[2];\r\n sy = a[3];\r\n d = a[4];\r\n \r\n if ((sx - d <= 1 && sy - d <= 1) || (sx + d >= n && sy + d >= m)\r\n || (sx - d <= 1 && sx + d >= n ) || ( sy - d <= 1 && sy + d >= m)) {\r\n print(-1);\r\n continue;\r\n }\r\n print(n + m - 2);\r\n }"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (distance(n, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n }\n\n if (distance(sx, m, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n }\n\n if (distance(sx, 1, sx, sy) <= d && distance(1, sy, sx, sy) <= d) {\n return -1;\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "var inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar readline = require('readline');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3], arr[4]);\r\n console.log(result);\r\n }\r\n}\r\n \r\nfunction myFunc(l, c, sx, sy, d){\r\n \r\n \r\n if(sy + d >= c && sy - d <= 1) return -1; //ocupa toda linha\r\n if(sx + d >= l && sx - d <= 1) return -1; //ocupa toda coluna\r\n \r\n if(sy + d >= c && sx + d >= l) return -1; // contorna objetivo\r\n if(sy - d <= 1 && sx - d <= 1) return -1; // contorna jogador\r\n \r\n \r\n return l + c - 2;\r\n \r\n \r\n}\r\n "}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3], arr[4]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(l, c, sx, sy, d){\r\n \r\n\r\n if(sy + d >= c && sy - d <= 1) return -1; //ocupa toda linha\r\n if(sx + d >= l && sx - d <= 1) return -1; //ocupa toda coluna\r\n\r\n if(sy + d >= c && sx + d >= l) return -1; // contorna objetivo\r\n if(sy - d <= 1 && sx - d <= 1) return -1; // contorna jogador\r\n\r\n\r\n return l + c - 2;\r\n \r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 134 (Div. 2)\n2022-08-26\n\nB. Deadly Laser\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n for (let tc = 0; tc < t; tc++) {\n // INPUT: grid size (n, m); laser at (sx, sy); range d\n let args = readline();\n args = args.split(\" \");\n args = args.map((k) => parseInt(k));\n const [n, m] = args.slice(0, 2);\n\n if (badLaser(...args)) {\n console.log(-1);\n } else {\n // number of steps will always be the same\n // if it is possible robot can always take\n // either right->down or down->right the whole board\n console.log(n + m - 2);\n }\n }\n}\n\n// Manhattan distance between 2 points\nfunction manDist(x1, y1, x2, y2) {\n return Math.abs(x1 - x2) + Math.abs(y1 - y2);\n}\n\n// Is the route impossible?\nfunction badLaser(n, m, sx, sy, d) {\n return (\n (sx - 1 <= d && sy - 1 <= d) ||\n (n - sx <= d && m - sy <= d) ||\n (sx - 1 <= d && n - sx <= d) ||\n (m - sy <= d && sy - 1 <= d)\n );\n}\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = sc.N(), m = sc.N(), sx = sc.N(), sy = sc.N(), d = sc.N();\r\n\r\n // console.log(`n = ${n} and m = ${m} and sx = ${sx} and sy = ${sy} and d = ${d}`);\r\n\r\n if ((sx + d >= n && sy + d >= m) || (sx - d <= 1 && sy - d <= 1) || (sx + d >= n && sx - d <= 1) || (sy + d >= m && sy - d <= 1))\r\n {\r\n console.log(-1);\r\n return;\r\n }\r\n\r\n // if ((sx + d >= n && sx - d <= 1) || (sy + d >= m && sy - d <= 1))\r\n // {\r\n // console.log(-1);\r\n // return;\r\n // }\r\n\r\n console.log(n + m - 2);\r\n\r\n // let arr = new Array(n).fill(new Array(m).fill(0));\r\n\r\n // arr[sx - 1][sy - 1] = 1;\r\n //\r\n // for (let i = 0; i < n; ++i)\r\n // {\r\n // for (let j = 0; j < m; ++j)\r\n // {\r\n // console.log(arr[i][j]);\r\n // }\r\n // }\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = sc.N();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction distance(ax, ay, bx, by) {\r\n return Math.abs(ax - bx) + Math.abs(ay - by);\r\n}\r\n\r\nfunction solve([n, m, sx, sy, d]) {\r\n if (distance(n, m, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n // compute vertical block\r\n // if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\r\n // return -1;\r\n // }\r\n\r\n // compute horizontal block\r\n // if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\r\n // return -1;\r\n // }\r\n\r\n if (distance(sx, m, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n return n - 1 + m - 1;\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const lines = input.trim().split('\\n');\r\n for (let i = 1; i < lines.length; i += 1) {\r\n const solution = solve(lines[i].split(' ').map(Number))\r\n process.stdout.write(String(solution) + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (distance(n, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n }\n\n if (distance(sx, m, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction distance(ax, ay, bx, by) {\r\n return Math.abs(ax - bx) + Math.abs(ay - by);\r\n}\r\n\r\nfunction solve([n, m, sx, sy, d]) {\r\n if (distance(n, m, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n // compute vertical block\r\n // if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\r\n // return -1;\r\n // }\r\n\r\n // compute horizontal block\r\n // if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\r\n // return -1;\r\n // }\r\n\r\n return n - 1 + m - 1;\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const lines = input.trim().split('\\n');\r\n for (let i = 1; i < lines.length; i += 1) {\r\n const solution = solve(lines[i].split(' ').map(Number))\r\n process.stdout.write(String(solution) + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction distance(ax, ay, bx, by) {\r\n return Math.abs(ax - bx) + Math.abs(ay - by);\r\n}\r\n\r\nfunction solve([n, m, sx, sy, d]) {\r\n if (distance(n, m, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n // compute vertical block\r\n if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n // compute horizontal block\r\n if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\r\n return -1;\r\n }\r\n\r\n return n - 1 + m - 1;\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const lines = input.trim().split('\\n');\r\n for (let i = 1; i < lines.length; i += 1) {\r\n const solution = solve(lines[i].split(' ').map(Number))\r\n process.stdout.write(String(solution) + '\\n');\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (distance(m, n, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, n, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(m, sy, sx, sy) <= d) {\n return -1;\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (distance(n, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, n, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(m, sy, sx, sy) <= d) {\n return -1;\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (d === 0) {\n return n - 1 + m - 1;\n }\n\n if (distance(n, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction distance(ax, ay, bx, by) {\n return Math.abs(ax - bx) + Math.abs(ay - by);\n}\n\nfunction solve([n, m, sx, sy, d]) {\n if (distance(n, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute vertical block\n if (distance(sx, 1, sx, sy) <= d && distance(sx, m, sx, sy) <= d) {\n return -1;\n }\n\n // compute horizontal block\n if (distance(1, sy, sx, sy) <= d && distance(n, sy, sx, sy) <= d) {\n return -1;\n }\n\n return n - 1 + m - 1;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (let i = 1; i < lines.length; i += 1) {\n const solution = solve(lines[i].split(' ').map(Number))\n process.stdout.write(String(solution) + '\\n');\n }\n});\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3], arr[4]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(l, c, sx, sy, d){\r\n \r\n\r\n if(sy + d >= c && sy - d <= 1) return -1;\r\n if(sx + d >= l && sx - d <= 1) return -1;\r\n\r\n // if(sx == l && sy + d >= c) return -1;\r\n // if(sy == c && sx + d >= l) return -1;\r\n\r\n if(sy + d >= c && sx + d >= l) return -1;\r\n if(sy + d <= 1 && sx + d <= 1) return -1;\r\n\r\n\r\n return l + c - 2;\r\n \r\n\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3], arr[4]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(l, c, sx, sy, d){\r\n \r\n\r\n if(sy + d >= c && sy - d <= 1) return -1;\r\n if(sx + d >= l && sx - d <= 1) return -1;\r\n\r\n if(sx == l && sy + d >= c) return -1;\r\n if(sy == c && sx + d >= l) return -1;\r\n\r\n if(sy + d >= c && sx + d >= l) return -1;\r\n\r\n\r\n return l + c - 2;\r\n \r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr[0], arr[1], arr[2], arr[3], arr[4]);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(l, c, sx, sy, d){\r\n \r\n\r\n if(sy + d >= c && sy - d <= 1) return -1;\r\n if(sx + d >= l && sx - d <= 1) return -1;\r\n\r\n if(sx == l && sy + d >= c) return -1;\r\n if(sy == c && sx + d >= l) return -1;\r\n\r\n\r\n return l + c - 2;\r\n \r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 134 (Div. 2)\n2022-08-26\n\nB. Deadly Laser\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n for (let tc = 0; tc < t; tc++) {\n // INPUT: grid size (n, m); laser at (sx, sy); range d\n let args = readline();\n args = args.split(\" \");\n args = args.map((k) => parseInt(k));\n const [n, m] = args.slice(0, 2);\n\n if (badLaser(...args)) {\n console.log(-1);\n } else {\n // number of steps will always be the same\n // if it is possible robot can always take\n // either right->down or down->right the whole board\n console.log(n + m - 2);\n }\n }\n}\n\n// Manhattan distance between 2 points\nfunction manDist(x1, y1, x2, y2) {\n return Math.abs(x1 - x2) + Math.abs(y1 - y2);\n}\n\n// Is the route impossible?\nfunction badLaser(n, m, sx, sy, d) {\n return (sx - 1 <= d && sy - 1 <= d) || (n - sx <= d && m - sy <= d);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 134 (Div. 2)\n2022-08-26\n\nB. Deadly Laser\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n for (let tc = 0; tc < t; tc++) {\n // INPUT: grid size (n, m); laser at (sx, sy); range d\n let args = readline();\n args = args.split(\" \");\n args = args.map((k) => parseInt(k));\n const [n, m, sx, sy, d] = args;\n\n if (manDist(n, m, sx, sy) <= d) {\n console.log(-1);\n } else {\n // number of steps will always be the same\n // if it is possible robot can always take\n // either right->down or down->right the whole board\n console.log(n + m - 2);\n }\n }\n}\n\n// Manhattan distance between 2 points\nfunction manDist(x1, y1, x2, y2) {\n return Math.abs(x1 - x2) + Math.abs(y1 - y2);\n}\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = sc.N(), m = sc.N(), sx = sc.N(), sy = sc.N(), d = sc.N();\r\n\r\n if ((sx + d >= n && sy + d >= m) || (sx - d <= 1 && sy - d <= 1))\r\n {\r\n console.log(-1);\r\n return;\r\n }\r\n\r\n // if ((sx + d >= n && sx - d <= 1) || (sy + d >= m && sy - d <= 1))\r\n // {\r\n // console.log(-1);\r\n // return;\r\n // }\r\n\r\n console.log(n + m - 2);\r\n\r\n // let arr = new Array(n).fill(new Array(m).fill(0));\r\n\r\n // arr[sx - 1][sy - 1] = 1;\r\n //\r\n // for (let i = 0; i < n; ++i)\r\n // {\r\n // for (let j = 0; j < m; ++j)\r\n // {\r\n // console.log(arr[i][j]);\r\n // }\r\n // }\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = sc.N();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = sc.N(), m = sc.N(), sx = sc.N(), sy = sc.N(), d = sc.N();\r\n\r\n if ((sx + d >= n && sx - d <= 1) || (sy + d >= m && sy - d <= 1))\r\n {\r\n console.log(-1);\r\n return;\r\n }\r\n\r\n console.log(n + m - 2);\r\n\r\n let arr = new Array(n).fill(new Array(m).fill(0));\r\n\r\n // arr[sx - 1][sy - 1] = 1;\r\n //\r\n // for (let i = 0; i < n; ++i)\r\n // {\r\n // for (let j = 0; j < m; ++j)\r\n // {\r\n // console.log(arr[i][j]);\r\n // }\r\n // }\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = sc.N();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m, sx, sy, d] = input[index]\n .split(\" \")\n .map((item) => parseInt(item));\n const testCase = {\n n,\n m,\n sx,\n sy,\n d,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m, sx, sy, d } = testCase;\n\n if (\n (sy - d <= 1 && sy + d >= m) ||\n (sx - d <= 1 && sx + d >= n) ||\n Math.abs(sx - n) + Math.abs(sy - m) <= d\n )\n console.log(-1);\n else {\n console.log(n - 1 + m - 1);\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m, sx, sy, d] = input[index]\n .split(\" \")\n .map((item) => parseInt(item));\n const testCase = {\n n,\n m,\n sx,\n sy,\n d,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m, sx, sy, d } = testCase;\n\n if ((sy - d <= 1 && sy + d >= m) || (sx - d <= 1 && sx + d >= n))\n console.log(-1);\n else {\n console.log(n - 1 + m - 1);\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "fe7186f7d026eb4cd2e1afda75ac9fcd"} {"source_code": "\r\nvar readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const skill = readLine().split(' ').map(p => +p);\r\n const damage = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n, skill, damage);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n, skill, damage){\r\n let fire = [];\r\n let ice = [];\r\n let resp = 0;\r\n\r\n for(let i = 0; i < n; i++){\r\n if(skill[i] == 0) fire.push(damage[i]);\r\n else ice.push(damage[i]);\r\n }\r\n\r\n fire.sort((a, b) => a - b);\r\n ice.sort((a, b) => a - b);\r\n\r\n\r\n if(fire.length == ice.length){\r\n if(fire[0] <= ice[0]) resp = fire[0] + (2*ice[0]);\r\n else resp = (2*fire[0]) + ice[0];\r\n for(let i = 1; i < fire.length; i++){\r\n resp += (fire[i] * 2) + (ice[i]*2);\r\n }\r\n }\r\n else if(fire.length > ice.length){\r\n let diff = fire.length - ice.length;\r\n for(let i = 0; i < fire.length; i++){\r\n if(i < diff) resp += fire[i];\r\n else resp += (fire[i] * 2) + (ice[i-diff]*2);\r\n }\r\n }\r\n else{\r\n let diff = ice.length - fire.length;\r\n for(let i = 0; i < ice.length; i++){\r\n if(i < diff) resp += ice[i];\r\n else resp += (fire[i-diff] * 2) + (ice[i]*2);\r\n }\r\n }\r\n\r\n return resp\r\n \r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "positive_code": [{"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n,a,b) => {\r\n if( n == 1 ) return b[0]\r\n\r\n let fire = a.filter( n => n === 0 ) \r\n let frost = a.filter( n => n === 1 ) \r\n\r\n if( fire.length === n || frost.length === n ) return b.reduce((partialSum, a) => partialSum + a, 0)\r\n \r\n let skills = []\r\n for( let i = 0; i< n; i++){\r\n skills.push({\r\n 'attack' : a[i],\r\n 'damage' : b[i] \r\n })\r\n }\r\n \r\n fire = skills.filter( s => s.attack === 0 ).sort((a,b) => b.damage - a.damage)\r\n frost = skills.filter( s => s.attack === 1 ).sort((a,b) => b.damage - a.damage)\r\n \r\n let damage = []\r\n let init = 0\r\n while( fire.length < frost.length )\r\n {\r\n damage.push( frost[frost.length - 1].damage )\r\n frost.pop() \r\n init = 0 \r\n }\r\n \r\n while( frost.length < fire.length )\r\n {\r\n damage.push( fire[fire.length - 1].damage )\r\n fire.pop() \r\n init = 1\r\n }\r\n\r\n if( damage.length == 0 ) {\r\n \r\n let firemin = fire[fire.length - 1].damage\r\n let frostmin = frost[frost.length - 1].damage\r\n\r\n if( firemin <= frostmin ) {\r\n damage.push( fire[fire.length - 1].damage )\r\n fire.pop()\r\n } else {\r\n damage.push( frost[frost.length - 1].damage )\r\n frost.pop() \r\n } \r\n\r\n for( let f of fire )\r\n {\r\n damage.push( 2 * f.damage )\r\n }\r\n \r\n for( let f of frost )\r\n {\r\n damage.push( 2 * f.damage )\r\n }\r\n\r\n } else { \r\n for( let f of fire )\r\n {\r\n damage.push( 2 * f.damage )\r\n }\r\n \r\n for( let f of frost )\r\n {\r\n damage.push( 2 * f.damage )\r\n }\r\n }\r\n\r\n \r\n return damage.reduce((partialSum, a) => partialSum + a, 0)\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let a = readline().split(' ').map(Number)\r\n let b = readline().split(' ').map(Number)\r\n console.log(getSolution(n, a, b))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}], "negative_code": [{"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n const a = [];\r\n a.push(d[0])\r\n for (let i = 1; i < n; i++) {\r\n\r\n let k = a.length - 1\r\n\r\n let op = ((a[k] - d[i]) < 0) ? (a[k] + d[i]) : (a[k] - d[i])\r\n a.push(op)\r\n\r\n k = a.length - 1\r\n if (a[k] - a[k - 1] < d[i]) return -1\r\n\r\n\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}], "src_uid": "bc1587d3affd867804e664fdb38ed765"} {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n hc++;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n }\r\n \r\n\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n mc = 0;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n \r\n return ph + ':' + pm;\r\n}\r\n\r\nfunction switch25(num) {\r\n if (num === 2) return 5;\r\n if (num === 5) return 2;\r\n return num;\r\n}\r\nmain();", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction getPaddedString (x) {\r\n\tif (x < 10) \r\n\t\treturn '0' + x;\r\n\treturn String(x);\r\n}\r\n\r\nfunction check (hh, mm, h, m) {\r\n\tconst mp = new Map([['0', '0'] , ['1', '1'], ['2', '5'], ['5', '2'], ['8', '8']]);\r\n\r\n\thh = getPaddedString(hh);\r\n\tmm = getPaddedString(mm);\r\n\tfor (const d of hh + mm) {\r\n\t\tif (!mp.has(d))\r\n\t\t\treturn false\r\n\t}\r\n\r\n\tconst hr = [mp.get(hh[0]), mp.get(hh[1])];\r\n\tconst mr = [mp.get(mm[0]), mp.get(mm[1])];\r\n\r\n\treturn Number(hr[1] + hr[0]) < m && Number(mr[1] + mr[0]) < h;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [h, m] = rna();\r\n\r\n\t\tlet [hh, mm] = rl().split(':').map(x => Number(x));\r\n\t\twhile (true) {\r\n\t\t\tif (check(hh, mm, h, m))\r\n\t\t\t\tbreak;\r\n\t\t\tmm = (mm + 1) % m;\r\n\t\t\tif (mm == 0) {\r\n\t\t\t\thh = (hh + 1) % h;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(getPaddedString(hh) + ':' + getPaddedString(mm));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n hc++;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n }\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n \r\n return ph + ':' + pm;\r\n}\r\n\r\nfunction switch25(num) {\r\n if (num === 2) return 5;\r\n if (num === 5) return 2;\r\n return num;\r\n}\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n hc++;\r\n }\r\n }\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n \r\n return ph + ':' + pm;\r\n}\r\n\r\nfunction switch25(num) {\r\n if (num === 2) return 5;\r\n if (num === 5) return 2;\r\n return num;\r\n}\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = switch25(Math.floor(num / 10));\r\n var second = switch25(num % 10);\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n mc = 0;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n }\r\n }\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n return ph + ':' + pm;\r\n}\r\n\r\nfunction switch25(num) {\r\n if (num === 2) return 5;\r\n if (num === 5) return 2;\r\n return num;\r\n}\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = Math.floor(num / 10);\r\n var second = num % 10;\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = Math.floor(num / 10);\r\n var second = num % 10;\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n mc = 0;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n }\r\n }\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n return ph + ':' + pm;\r\n}\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nvar good = new Set([0, 1, 2, 5, 8]);\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var hm = readNumArray();\r\n var h = hm[0];\r\n var m = hm[1];\r\n var hcmc = readline().split(':').map(Number);\r\n var hc = hcmc[0];\r\n var mc = hcmc[1];\r\n print(findNextGood(hc, mc, h, m));\r\n }\r\n}\r\n\r\nfunction isGoodH(num, m) {\r\n var first = Math.floor(num / 10);\r\n var second = num % 10;\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < m;\r\n}\r\n\r\nfunction isGoodM(num, h) {\r\n var first = Math.floor(num / 10);\r\n var second = num % 10;\r\n\r\n return good.has(first) && good.has(second)\r\n && (second * 10 + first) < h;\r\n}\r\n\r\nfunction findNextGood(hc, mc, h, m) {\r\n while (!isGoodH(hc , m)) {\r\n hc++;\r\n if (hc >= h) {\r\n hc = 0;\r\n }\r\n }\r\n var hours = hc;\r\n var ph = hours > 9 ? String(hours) : '0' + hours;\r\n while (!isGoodM(mc , h)) {\r\n mc++;\r\n if (mc >= m) {\r\n mc = 0;\r\n }\r\n }\r\n var minutes = mc;\r\n var pm = minutes > 9 ? String(minutes) : '0' + minutes;\r\n return ph + ':' + pm;\r\n}\r\nmain();"}], "src_uid": "7f28e4dbd199b84bd7885bf7f479cf38"} {"source_code": "\"use strict\";\n\n/*\nvar write = console.log.bind();\nvar k = 0;\nvar readline = function() {\n\n\tswitch ( k++ ) {\n\t\tcase 0: return '4 4'\n\t\tcase 1: return '0 0 0 0'\n\t\tcase 2: return '1 0 0 1'\n\t\tcase 3: return '0 1 1 0'\n\t\tcase 4: return '0 1 0 0'\n\t}\n};\n*/\n\nlet input = readline().split(' ').map(e => +e);\nlet n = input[0],\n\tm = input[1];\n\nlet grid = [];\n\nfor ( let i = 0; i < n; i++ )\n\tgrid.push(readline().split(' ').map(e => +e));\n\nlet accum = 0, dir;\n\nfor ( let i = 0; i < n; i++ ) {\n\tdir = false;\n\tfor ( let j = 0; j < m; j++ ) {\n\t\tif ( dir && grid[i][j] === 0 )\n\t\t\taccum++;\n\t\telse if ( grid[i][j] === 1 )\n\t\t\tdir = true;\n\t}\n}\n\nfor ( let i = 0; i < n; i++ ) {\n\tdir = false;\n\tfor ( let j = m-1; j >= 0; j-- ) {\n\t\tif ( dir && grid[i][j] === 0 )\n\t\t\taccum++;\n\t\telse if ( grid[i][j] === 1 )\n\t\t\tdir = true;\n\t}\n}\n\nfor ( let i = 0; i < m; i++ ) {\n\tdir = false;\n\tfor ( let j = 0; j < n; j++ ) {\n\t\tif ( dir && grid[j][i] === 0 )\n\t\t\taccum++;\n\t\telse if ( grid[j][i] === 1 )\n\t\t\tdir = true;\n\t}\n}\n\nfor ( let i = 0; i < m; i++ ) {\n\tdir = false;\n\tfor ( let j = n-1; j >= 0; j-- ) {\n\t\tif ( dir && grid[j][i] === 0 )\n\t\t\taccum++;\n\t\telse if ( grid[j][i] === 1 )\n\t\t\tdir = true;\n\t}\n}\n\n\nwrite(accum);", "positive_code": [{"source_code": "const mapSize = readline().split(\" \").map(x => Number(x));\nconst height = mapSize[0];\nconst width = mapSize[1];\nconst map = new Array(height);\nconst createCell = cell => cell.charCodeAt(0) === 48 /* 0 */;\nfor (var y = 0; y < height; y++)\n map[y] = readline().split(\" \").slice(0, width).map(createCell);\nvar result = 0;\nfor (var y = 0; y < height; y++) {\n var row = map[y];\n for (var x = 0; x < width; x++) {\n if (row[x]) continue;\n var cy;\n var cx;\n for (cy = y - 1; cy >= 0 && map[cy][x]; cy--)\n result++;\n for (cy = y + 1; cy < height && map[cy][x]; cy++)\n result++;\n for (cx = x - 1; cx >= 0 && row[cx]; cx--)\n result++;\n for (cx = x + 1; cx < width && row[cx]; cx++)\n result++;\n }\n}\nprint(result);\n"}, {"source_code": "var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\nvar n = input[0],\n m = input[1];\nvar theater = [];\nfor (var i = 0; i < n; i++) {\n var inp = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n theater.push(inp);\n}\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++) {\n if (theater[i][j] == 1) {\n var left = j - 1,\n top = i - 1,\n bottom = i + 1;\n while (left >= 0) {\n if (theater[i][left] == 0) count++;\n if (theater[i][left] == 1) break;\n left--;\n }\n while (top >= 0) {\n if (theater[top][j] == 0) count++;\n if (theater[top][j] == 1) break;\n top--;\n }\n while (bottom < n) {\n if (theater[bottom][j] == 0) count++;\n if (theater[bottom][j] == 1) {\n break;\n }\n bottom++;\n }\n j++;\n\n while (j < m) {\n if (theater[i][j] == 0) count++;\n if (theater[i][j] == 1) {\n j--;\n break;\n }\n j++;\n }\n }\n }\n}\nprint(count);\n"}], "negative_code": [{"source_code": "const mapSize = readline().split(\" \").map(x => Number(x));\nconst height = mapSize[0];\nconst width = mapSize[1];\nconst map = new Array(height);\nfor (var i = 0; i < height; i++)\n map[i] = readline().split(\" \").slice(0, width).map(cell => cell == \"0\");\nvar result = 0;\nfor (var y = 0; y < height; y++) {\n var row = map[y];\n for (var x = 0; x < height; x++) {\n if (row[x]) continue;\n var cy;\n var cx;\n for (cy = y - 1; cy >= 0 && map[cy][x]; cy--)\n result++;\n for (cy = y + 1; cy < height && map[cy][x]; cy++)\n result++;\n for (cx = x - 1; cx >= 0 && row[cx]; cx--)\n result++;\n for (cx = x + 1; cx < width && row[cx]; cx++)\n result++;\n }\n}\nprint(result);\n"}], "src_uid": "c3a7d82f6c3cf8678a1c7c521e0a5f51"} {"source_code": "for(var t=Number(readline());t;t--){\n var n = readline().trim().split(/\\s/).map(x=>Number(x));\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n a.sort((a, b) => a - b);\n var v = 0;\n for(var i=0;(i=0);i++){\n if(a[i]==v) continue;\n n[1] -= (a[i]-v-1);\n v=a[i];\n if(n[1]<0)v--;\n }\n v+=n[1];\n print(v);\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n\n\nfunction main() {\n \n const c = parseInt(stdin.shift());\n\n for (let i = 0; i < c; i++) {\n let input1 = stdin.shift().split(\" \");\n let n = parseInt(input1[0]);\n let x = parseInt(input1[1]);\n let p = new Array(201).fill(false);\n p[0] = true;\n stdin.shift()\n .split(\" \")\n .map(function (x) {p[x] = true;});\n\n let j = 0;\n while (x > -1) {\n if (!p[j]) {\n x--;\n }\n j++;\n }\n\n console.log(j - 2);\n }\n}"}, {"source_code": "var test = parseInt(readline());\nwhile (test--) {\n var firstInput = readline().split(' ').map(y => parseInt(y));\n var n = firstInput[0]; var x = firstInput[1];\n var secondInput = readline().split(' ').map(x => parseInt(x));\n secondInput.sort((a, b) => a - b)\n var count = 0;\n for (var i = 1; i < n + x; i++) {\n var found = secondInput.find(element => element == i);\n if (!found) {\n count++;\n }\n if (count == x) {\n count = 0;\n break;\n }\n }\n\n for (var j = i + 1; j < 105; j++) {\n var get = secondInput.find(element => element == j);\n if (!get) break;\n }\n print(j - 1)\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, x;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n [n, x] = d.split(' ').map(Number);\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let ans = 0;\n let count = 1;\n\n while (x > 0) {\n if (!arr.includes(count)) {\n x--;\n\n if (x === 0) {\n while (arr.includes(count + 1)) {\n count++;\n }\n }\n }\n\n ans = Math.max(ans, count);\n count++;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "var test = parseInt(readline());\nwhile (test--) {\n var firstInput = readline().split(' ').map(y => parseInt(y));\n var n = firstInput[0]; var x = firstInput[1];\n var secondInput = readline().split(' ').map(x => parseInt(x));\n secondInput.sort((a, b) => a - b)\n var count = 0;\n for (var i = 1; i < n + x; i++) {\n var found = secondInput.find(element => element == i);\n if (!found) {\n count++;\n }\n if (count == x) {\n count = 0;\n break;\n }\n }\n \n for (var j = i + 1; j < 105; j++) {\n var get = secondInput.find(element => element == j);\n if (!get) break;\n }\n print(j - 1)\n}"}, {"source_code": "// Q: \n\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n const test = parseInt(input[0]);\n let n, x, a;\n for (let t = 0; t < test; t++) {\n [n, x] = input[2*t + 1].split(' ').map((a) => parseInt(a));\n a = input[2*t + 2].split(' ').map((a) => parseInt(a));\n console.log(solution(a, n, x));\n }\n})\n\nfunction solution(a, n, x) {\n let rankAchieved = Array(n+x).fill(false);\n for (let i = 0; i < n; i++) {\n rankAchieved[a[i]] = true;\n }\n for (let k = n+x; k > 0; k--) {\n let v = 0;\n for (let i = 1; i <= k; i++) {\n if (!rankAchieved[i]) {\n v += 1;\n }\n }\n if (v <= x) {\n return k;\n }\n }\n}"}], "negative_code": [{"source_code": "var test = parseInt(readline());\nwhile (test--) {\n var firstInput = readline().split(' ').map(y => parseInt(y));\n var n = firstInput[0]; var x = firstInput[1];\n var secondInput = readline().split(' ').map(x => parseInt(x));\n secondInput.sort((a, b) => a - b)\n var count = 0;\n for (var i = 1; i < n + x; i++) {\n var found = secondInput.find(element => element == i);\n if (!found) {\n count++;\n }\n if (count == x) {\n count = 0;\n break;\n }\n }\n\n var get = secondInput.find(element => element == i + 1);\n if (get) print(i + 1);\n else print(i);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {stdin.push(line);});\nrl.on('close', main);\n\n\n\nfunction main() {\n \n const c = parseInt(stdin.shift());\n\n for (let i = 0; i < c; i++) {\n let input1 = stdin.shift().split(\" \");\n let n = parseInt(input1[0]);\n let x = parseInt(input1[1]);\n let p = new Array(201).fill(false);\n p[0] = true;\n stdin.shift()\n .split(\" \")\n .map(function (x) {p[x] = true;});\n\n let j = 0;\n while (x > -1) {\n if (!p[j]) {\n x--;\n }\n j++;\n }\n\n console.log(j);\n }\n}"}], "src_uid": "e5fac4a1f3a724234990fe758debc33f"} {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var t = line[1];\n var time = t;\n var data = readline().split(' ').map(Number);\n var start = 0;\n var i=0;\n var max = 0;\n var res = 0;\n while(i < n){\n while(t - data[i] < 0 && data[i] <= time){\n t += data[start];\n res--;\n start++;\n }\n if(data[i] <= time){\n t-=data[i];\n res++;\n }\n if(res>max){\n max = res;\n }\n i++\n }\n print(max)\n}\n\n\nmain()", "positive_code": [{"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n // NOT ar.sort(function(a, b){return a-b});\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n ar.splice(0,0,0);\n\n print((function() {\n function binarysearch(end) {\n var left = 0,\n right = end;\n var mid;\n while (left <= right) {\n mid = Math.floor((left + right) /2);\n var sub = ar[end] - ar[mid];\n \n if (sub == t) {\n return end - mid;\n } else if (sub > t) {\n left = mid + 1;\n } else {\n right = mid;\n if (left == right) {\n return end - mid;\n }\n }\n }\n }\n var count = -1;\n for(var i = 1; i < ar.length; ++i) {\n var tmp = binarysearch(i);\n if (count < tmp)\n count = tmp;\n }\n if (count > -1)\n return count;\n return 0;\n })());\n})();\n"}, {"source_code": "var line = readline().split(' ');\n\nvar n = parseInt(line[0]);\nvar t = parseInt(line[1]);\n\nvar books = readline().split(' ');\n\nvar max = 0;\nbooks[-1] = 0;\nvar j = -1;\nvar total = 0;\nfor(var i = 0; i < n; i++ ) {\n if(j == n){\n break;\n }\n if(i == j) {\n i++;\n }\n if(parseInt(books[i]) + total <= t){\n if(i - j > max){\n max = i - j ;\n }\n total +=parseInt(books[i]);\n } else {\n if(total != 0){\n total -= parseInt(books[j+1]);\n }\n j++;\n i--;\n }\n}\n\n\n\n\n\nprint(max);"}, {"source_code": ";(function () {\n\n\tprint(function(n, t) {\n\t\tvar a = readline().split(' ').map(Number), ret = 0;\n\n\t\tfor (var i = 0, j = 0, s = 0; i < n; i++) {\n\t\t\ts += a[i];\n\t\t\twhile (s > t) s -= a[j++];\n\t\t\tret = Math.max(ret, i - j + 1);\n\t\t}\n\n\t\treturn ret;\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}).call(this);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [numOfBooks, freeMinutes] = input\n const books = readline().split(' ').map(Number)\n helper(numOfBooks, freeMinutes, books)\n}\n\nfunction helper(numOfBooks, freeMinutes, books) {\n let left = 0\n let right = 0\n let sum = 0\n let max = 0\n while (right < numOfBooks) {\n if (sum + books[right] <= freeMinutes) {\n sum += books[right]\n right++\n } else {\n max = Math.max(right - left, max)\n sum -= books[left]\n left++\n }\n }\n\n console.log(Math.max(right - left, max))\n}"}, {"source_code": "print(function(n, t) {\n\tvar a = rn(),\n\t\tl = 0,\n\t\tr = 0,\n\t\tsum = 0,\n\t\tans = 0;\n\twhile (r < n) {\n\t\tsum += a[r++];\n\t\twhile (sum > t)\n\t\t\tsum -= a[l++];\n\t\tif (r - l > ans)\n\t\t\tans = r - l;\n\t}\n\treturn ans;\n}.apply(0, rn()));\n\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] > m) {\n if (right === n - 1) break;\n right++;\n sum = 0;\n continue;\n } else if (a[left] === m) {\n count = Math.max(count, 1);\n if (right === n - 1) break;\n right++;\n sum = 0;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] === m) {\n count = right - left > 1 ? Math.max(count, right - left) : 1;\n i = right;\n right++;\n sum = 0;\n break;\n } else if (a[right] > m) {\n count = right > left ? Math.max(count, right - left) : 0;\n i = right;\n right++;\n sum = 0;\n break;\n }\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum === m) {\n count = right > left ? Math.max(count, right - left + 1) : 1;\n if (count === m || right === n - 1) return count;\n if (count > 1) {\n sum = sum - (a[left] + a[left + 1]);\n } else if (count === 1) {\n sum = 0;\n } else {\n sum = 0;\n }\n\n right++;\n break;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n if (count === m || right === n - 1) return count;\n if (count > 1) {\n sum = sum - (a[left] + a[left + 1]);\n } else if (count === 1) {\n sum = 0;\n } else {\n sum = 0;\n }\n right++\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n right++;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) count = right - left > 1 ? Math.max(count, right - left) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else {\n if (sum === m) count = right > left ? Math.max(count, right - left + 1) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "print(function(n, t) {\n\tvar a = rn(),\n\t\tl = 0,\n\t\tr = 0,\n\t\tsum = 0,\n\t\tans = 0;\n\twhile (r < n) {\n\t\tsum += a[r++];\n\t\twhile (sum > t)\n\t\t\tsum -= a[l++];\n\t\tans = Math.max(r - l, ans);\n\t}\n\treturn ans;\n}.apply(0, rn()));\n\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n, t) {\n\tvar s = 0;\n\tvar a = readline().split(' ').map(Number);\n\tvar b = new Int32Array(n + 1);\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++)\n\t\tb[i + 1] = b[i] + a[i];\n\n\tfor (var i = 1; i <= n; i++) {\n\t\tvar x = findCeil(b, b[i] - t, 0, n);\n\t\tif (x > -1) {\n\t\t\tans = Math.max(ans, i - x);\n\t\t}\n\t}\n\n\treturn ans;\n\n}.apply(0, readline().split(' ').map(Number)));\n\nfunction findCeil(a, v, l, h) {\n\tvar m;\n\tif (v <= a[l]) return l;\n\tif (v > a[h]) return -1;\n\twhile (l <= h) {\n\t\tm = l + h >> 1;\n\t\tif (v <= a[m]) {\n\t\t\tif (v > a[m - 1]) return m;\n\t\t\telse h = m - 1;\n\t\t} else {\n\t\t\tif (v <= a[m + 1]) return m + 1;\n\t\t\telse l = m + 1;\n\t\t}\n\t}\n\treturn -1;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n right++;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) {\n count = right - left > 1 ? Math.max(count, right - left) : 1;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n }\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else {\n if (sum === m) {\n count = right > left ? Math.max(count, right - left + 1) : 1;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n }\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar a = rda(), n = a[0], t = a[1];\na = rda();\n\nfor(var i = 0, s = 0; i < n; i++){\n s += a[i];\n a[i] = s;\n}\n\nvar ans = 0;\n\nfor(var i = 0, j = 0; j < n; ){\n var x = (i == 0) ? (a[j]) : (a[j]-a[i-1]);\n if(x <= t){\n j++;\n ans++;\n }else{\n i++;\n j++;\n }\n}\n\nwrite(ans);"}], "negative_code": [{"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar t=+l[1];\nvar a=readline().split(' ')\n\t.map(function(v){return+v;})\n\t.sort(function(a,b){return a-b});\nvar ans=0;\nvar sum=0;\nfor(var i=0;it){\n\t\tbreak;\n\t}else{\n\t\tans++;\n\t}\n}\nprint(ans);"}, {"source_code": "print(function(n, t) {\n\tvar s = 0;\n\tvar a = readline().split(' ').map(Number);\n\tvar b = new Int32Array(n + 1);\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++)\n\t\tb[i + 1] = b[i] + a[i];\n\n\tfor (var i = 1; i <= n; i++) {\n\t\tvar x = find(b[i] - t);\n\t\tif (x > -1) {\n\t\t\tans = Math.max(ans, i - x);\n\t\t}\n\t}\n\n\treturn ans;\n\n\n\tfunction find(v) {\n\t\tvar mid, low = 0,\n\t\t\thigh = n;\n\t\tif (v <= b[low]) return low;\n\t\tif (v > b[high]) return -1;\n\t\tif (v == b[high]) return n;\n\t\twhile (low < high) {\n\t\t\tmid = ~~ ((low + high) / 2);\n\t\t\tif (v >= b[mid]) {\n\t\t\t\tif (v < b[mid + 1]) return mid + 1;\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\tif (v >= b[mid - 1]) return mid;\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t}\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "\nprint(function(n, t) {\n\tvar s = 0;\n\tvar a = readline().split(' ').map(Number);\n\tvar b = new Int32Array(n + 1);\n\tvar ans = 0;\n\tfor (var i = 0; i < n; i++)\n\t\tb[i + 1] = b[i] + a[i];\n\n\tfor (var i = 1; i <= n; i++) {\n\t\tvar x = find(b[i] - t);\n\t\tif (x > -1) {\n\t\t\tans = Math.max(ans, i - x);\n\t\t}\n\t}\n\n\treturn ans;\n\n\n\tfunction find(v) {\n\t\tvar mid, low = 0,\n\t\t\thigh = n;\n\t\tif (v < b[low]) return -1;\n\t\tif (v > b[high]) return -1;\n\t\tif (v == b[high]) return n;\n\t\twhile (low < high) {\n\t\t\tmid = ~~ ((low + high) / 2);\n\t\t\tif (v >= b[mid]) {\n\t\t\t\tif (v < b[mid + 1]) return mid + 1;\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\tif (v >= b[mid - 1]) return mid;\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t}\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar a = rda(), n = a[0], t = a[1];\na = rda();\n\nfor(var i = 0, s = 0; i < n; i++){\n s += a[i];\n a[i] = s;\n}\n\nvar ans = 0;\nif(t >= a[0]) ans++;\n\nfor(var i = 0, j = 1; j < n; ){\n var x = (i == 0) ? (a[j]) : (a[j]-a[i-1]);\n if(x <= t){\n j++;\n ans++;\n }else{\n i++;\n j++;\n }\n}\n\nwrite(ans);"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar a = rda(), n = a[0], t = a[1];\na = rda().sort(function(x, y){ return x-y; });\n\nfor(var i = 0, s = 0; i < n; i++){\n s += a[i];\n a[i] = s;\n}\n\nvar ans = 0;\nif(t >= a[0]) ans++;\n\nfor(var i = 0, j = 1; j < n; ){\n if(a[j] <= t){\n j++;\n ans++;\n }else{\n i++;\n j++;\n }\n}\n\nwrite(ans);"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar a = rda(), n = a[0], t = a[1];\na = rda();\n\nfor(var i = 0, s = 0; i < n; i++){\n s += a[i];\n a[i] = s;\n}\n\nvar ans = 0;\nif(t >= a[0]) ans++;\n\nfor(var i = 0, j = 1; j < n; ){\n var x = (i == 0) ? (a[j]) : (a[j]-a[i-1]);\n if(x <= t){\n j++;\n ans++;\n }else{\n i++;\n j++;\n }\n print(i, j, ans);\n}\n\nwrite(ans);"}, {"source_code": "var input = readline().split(\" \").map(Number), n = input[0], t = input[1], a = readline().split(\" \").map(Number);\nvar counter = 0, ans;\n\na = a.filter(function(number){\n\treturn !(number > t);\n});\nn = a.length;\n\na.sort(function(x,y){return x-y});\n\nif(n == 0){\n\tans = n;\n}\nelse{\n\tfor(var i = 0; i < n; i++){\n\t\tcounter += a[i];\n\t\tif(counter > t){\n\t\t\tans = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(counter <= t){\n\t\tans = n;\n\t}\n\n}\n\nwrite(ans);"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n // ar = [2, 10];\n // t = 10;\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n ar.sort(function(a, b){return a-b});\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length-1;\n var mid, old_mid= -1;\n while (left <= right) {\n mid = Math.floor((left + right) / 2);\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] < t)\n return old_mid + 1;\n return mid;\n }\n left = mid;\n } else if (ar[mid] == t) {\n return mid;\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n return -1;\n })()+1);\n})();"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n ar.sort();\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length-1;\n var mid, old_mid= -1;\n while (left <= right) {\n mid = Math.floor((left + right) / 2);\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] < t)\n return old_mid + 1;\n return mid;\n }\n left = mid;\n } else if (ar[mid] == t) {\n return mid;\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n return -1;\n })()+1);\n})();"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n\n ar.sort();\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length-1;\n var mid, old_mid= -1;\n while (left <= right) {\n mid = (left + right) / 2;\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] < t)\n return old_mid + 1;\n return mid;\n }\n left = mid;\n } else if (ar[mid] == t) {\n return mid;\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n })());\n})();"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n\n ar.sort();\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length;\n var mid = (left + right) / 2,\n old_mid;\n while (left <= right) {\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] < t)\n return ar[old_mid + 1];\n return ar[mid];\n }\n left = mid;\n } else if (ar[mid] == t) {\n return ar[mid];\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n })());\n})();"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n ar.sort();\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length-1;\n var mid, old_mid= -1;\n while (left <= right) {\n mid = Math.floor((left + right) / 2);\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] < t)\n return old_mid + 1;\n return mid;\n }\n left = mid;\n } else if (ar[mid] == t) {\n return mid;\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n return left;\n })()+1);\n})();"}, {"source_code": "(function main() {\n var toInt = function(x) {\n return parseInt(x);\n }\n // ar = [6, 4];\n // t = 10;\n var firstline = readline().split(\" \").map(toInt);\n var n = firstline[0],\n t = firstline[1];\n\n var ar = readline().split(\" \").map(toInt);\n ar.sort(function(a, b){return a-b});\n\n ar.reduce(function(sum, next, id, array) {\n var tmp = sum + next;\n array[id] = tmp;\n return tmp;\n });\n\n print((function() {\n var left = 0,\n right = ar.length-1;\n var mid, old_mid= -1;\n while (left <= right) {\n mid = Math.floor((left + right) / 2);\n if (ar[mid] < t) {\n if (old_mid == mid) {\n if (ar[old_mid + 1] <= t)\n return old_mid + 1;\n return mid;\n }\n left = mid;\n } else if (ar[mid] == t) {\n return mid;\n } else {\n right = mid - 1;\n }\n old_mid = mid;\n }\n return -1;\n })()+1);\n})();"}, {"source_code": "var line = readline().split(' ');\n\nvar n = parseInt(line[0]);\nvar t = parseInt(line[1]);\n\nvar books = readline().split(' ');\n\nvar max = 0;\nbooks[-1] = 0;\nvar j = -1;\nvar total = 0;\nfor(var i = 0; i < n; i++ ) {\n if(j == n){\n break;\n }\n if(i == j) {\n i++;\n }\n if(parseInt(books[i]) + total <= t){\n if(i - j > max){\n max = i - j ;\n }\n total +=parseInt(books[i]);\n } else {\n if(total != 0){\n total -= parseInt(books[j-1]);\n }\n j++;\n i--;\n }\n}\n\n\n\n\n\nprint(max);"}, {"source_code": "var line = readline().split(' ');\n\nvar n = parseInt(line[0]);\nvar t = parseInt(line[1]);\n\nvar books = readline().split(' ');\n\nvar max = 0;\nbooks[-1] = 0;\nvar j = -1;\nvar total = 0;\nfor(var i = 0; i < n; i++ ) {\n if(j == n){\n break;\n }\n if(i == j) {\n i++;\n }\n if(parseInt(books[i]) + total <= t){\n if(i - j > max){\n max = i - j ;\n }\n total +=parseInt(books[i]);\n } else {\n total -= parseInt(books[j]);\n j++;\n i--;\n }\n}\n\n\n\n\n\nprint(max);"}, {"source_code": "var line = readline().split(' ');\n\nvar n = parseInt(line[0]);\nvar t = parseInt(line[1]);\n\nvar books = readline().split(' ');\n\nvar times = {};\n\ntimes[0] = 0;\n\nfor(var i = 0; i < n; i++ ){\n times[i+1] = times[i] + parseInt(books[i]);\n}\n\nvar max = 0;\nfor(var i = 0; i < n; i++) {\n for(var j=n-1; j > 0; j--){\n if(times[j] - times[i] <= t && j - i + 1 > max){\n max = j - i + 1;\n }\n }\n}\n\nprint(max);"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var t = line[1];\n var time = t;\n var data = readline().split(' ').map(Number);\n var start = 0;\n var i=0;\n var max = 0;\n var res = 0;\n while(i < n){\n while(t - data[i] < 0 && data[i] <= time){\n t += data[start];\n res--;\n start++;\n }\n t-=data[i];\n res++;\n if(res>max){\n max = res;\n }\n i++\n }\n print(max)\n}\n\n\nmain()"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [numOfBooks, freeMinutes] = input\n const books = readline().split(' ').map(Number)\n helper(numOfBooks, freeMinutes, books)\n}\n\nfunction helper(numOfBooks, freeMinutes, books) {\n let left = 0\n let right = 0\n let sum = 0\n let max = 0\n while (right < numOfBooks) {\n if (sum + books[right] < freeMinutes) {\n sum += books[right]\n right++\n } else {\n max = Math.max(right - left, max)\n sum -= books[left]\n left++\n }\n }\n\n console.log(Math.max(right - left, max))\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] > m) {\n if (right === n - 1) break;\n right++;\n sum = 0;\n continue;\n } else if (a[left] === m) {\n count = Math.max(count, 1);\n if (right === n - 1) break;\n right++;\n sum = 0;\n continue;\n } else {\n if (right === n - 1) break;\n right++;\n }\n }\n while (right < n) { \n if (a[right] === m) {\n count = right - left > 1 ? Math.max(count, right - left) : 1;\n i = right;\n right++;\n sum = 0;\n break;\n } else if (a[right] > m) {\n count = right > left ? Math.max(count, right - left) : 0;\n i = right;\n right++;\n sum = 0;\n break;\n }\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum === m) {\n count = right > left ? Math.max(count, right - left + 1) : 1;\n if (count === m || right === n - 1) return count;\n if (count > 1) {\n sum = sum - (a[left] + a[left + 1]);\n } else if (count === 1) {\n sum = 0;\n } else {\n sum = 0;\n }\n\n right++;\n break;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n if (count === m || right === n - 1) return count;\n if (count > 1) {\n sum = sum - (a[left] + a[left + 1]);\n } else if (count === 1) {\n sum = 0;\n } else {\n sum = 0;\n }\n right++\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) {\n count = right - left > 1 ? Math.max(count, right - left) : 1;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n }\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum >= m) {\n if (sum === m) {\n count = right > left ? Math.max(count, right - left + 1) : 1;\n } else {\n count = right > left ? Math.max(count, right - left) : 0;\n }\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) count = right - left > 1 ? Math.max(count, right - left) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum >= m) {\n if (sum === m) count = right > left ? Math.max(count, right - left + 1) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n continue;\n } else {\n if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) right - left > 1 ? Math.max(count, right - left) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum >= m) {\n if (sum === m) count = right > left ? Math.max(count, right - left + 1) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const arr = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n const result = books(n, m, arr);\n printResult(result.toString());\n}\n\nconst books = (n, m, a) => {\n let left = 0;\n let right = 0;\n let count = 0;\n let sum = 0;\n for (let i = 0; i < n; i++) { \n left = i;\n sum += a[left];\n if (left === right) {\n if (a[left] >= m) {\n if (a[left] === m) count = Math.max(count, 1);\n if (right === n - 1) break;\n sum = 0;\n continue;\n } else if (right === n - 1) {\n count = Math.max(count, 1);\n break;\n }\n right++;\n }\n while (right < n) { \n if (a[right] >= m) {\n if (a[right] === m) right - left > 1 ? Math.max(count, right - left) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n i = right;\n right++;\n sum = 0;\n break;\n }\n\n sum += a[right];\n if (sum < m) {\n if (right === n - 1) return Math.max(count, right - left + 1);\n right++;\n } else if (sum >= m) {\n if (sum === m) count = right > left ? Math.max(count, right - left + 1) : 1;\n else count = right > left ? Math.max(count, right - left) : 0;\n\n if (count === m || right === n - 1) return count;\n\n sum = count > 1 ? sum - (a[left] + a[left + 1]) : 0;\n right++;\n break;\n }\n } \n }\n\n return count;\n};"}], "src_uid": "ef32a8f37968629673547db574261a9d"} {"source_code": "process.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n \n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const s = arr[j],\n len = s.length,\n len2 = len - 2\n\n let count = 0\n let str = s.split('')\n let ans = ''\n\n for(let i = 0; i < len2; i ++) {\n // console.log(str[i], i)\n if(str[i] == 'o' && str[i + 1] == 'n' && str[i + 2] == 'e') {\n count ++\n if(ans == '') ans += (i + 1 + 1).toString()\n else ans += ` ${(i + 1 + 1)}`\n str[i + 1] = '1'\n i += 2\n }\n else if(str[i] == 't' && str[i + 1] == 'w' && str[i + 2] == 'o') {\n if(str[i + 3] == 'n' && str[i + 4] == 'e'){\n count ++\n if(ans == '') ans += (i + 2 + 1).toString()\n else ans += ` ${(i + 2 + 1)}`\n str[i + 2] = '1'\n i += 4\n }\n else {\n count ++\n if(ans == '') ans += (i + 1 + 1).toString()\n else ans += ` ${(i + 1 + 1)}`\n str[i + 1] = '1'\n i += 2\n }\n }\n }\n\n console.log(count)\n console.log(ans)\n }\n})", "positive_code": [{"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var t = myconv(readline(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var s = myconv(readline(),6);\n var pos = [];\n //myout(s);\n for(var j = 0; j < s.length; j++){\n var twone = s[j-1]+s[j]+s[j+1]+s[j+2]+s[j+3];\n if(twone == \"twone\"){\n pos.push(j+2);\n j += 3;\n continue;\n }\n var onetwo = s[j-1]+s[j]+s[j+1];\n if(onetwo == \"one\" || onetwo == \"two\"){\n pos.push(j+1);\n continue;\n }\n }\n output[i] = pos.length + \"\\n\" + pos.join(\" \");\n }\n myout(output.join(\"\\n\"));\n}\n\nMain();\n"}], "negative_code": [], "src_uid": "9f8660190134606194cdd8db891a3d46"} {"source_code": "const increase = a => {\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== i + 1) return false;\n }\n return true;\n};\n\nconst permutation = (n, a, tag) => {\n const b = [...a];\n if (tag === 0) {\n for (let j = 0; j < n; j++) {\n let w = b[2 * j];\n b[2 * j] = b[2 * j + 1];\n b[2 * j + 1] = w;\n }\n } else if (tag === 1) {\n for (let j = 0; j < n; j++) {\n let w = b[j];\n b[j] = b[n + j];\n b[n + j] = w;\n }\n }\n return b;\n};\n\nconst solve = (n, a) => {\n if (increase(a)) return 0;\n\n let p1 = [...a];\n let t1 = 0;\n let p2 = [...a];\n let t2 = 1;\n\n for (let i = 1; i <= n; i++) {\n p1 = permutation(n, p1, t1);\n p2 = permutation(n, p2, t2);\n if (increase(p1) || increase(p2)) return i;\n t1 = 1 - t1;\n t2 = 1 - t2;\n }\n\n return -1;\n};\n\nconst main = () => {\n const n = readInt();\n const a = readListInt();\n\n console.log(solve(n, a));\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let arr1 = [...arr];\r\n const check = (arr) => {\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] > arr[i + 1]) return false;\r\n }\r\n return true;\r\n };\r\n const swap = (arr) => {\r\n for (let i = 0; i < arr.length; i += 2) {\r\n [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];\r\n }\r\n };\r\n const rev = (arr) => {\r\n for (let i = 0; i < n; i++) {\r\n [arr[i], arr[n + i]] = [arr[n + i], arr[i]];\r\n }\r\n };\r\n if (n % 2 === 0) {\r\n if (check(arr)) {\r\n console.log(0);\r\n continue;\r\n }\r\n swap(arr);\r\n rev(arr1);\r\n if (check(arr) || check(arr1)) {\r\n console.log(1);\r\n continue;\r\n }\r\n rev(arr);\r\n swap(arr1);\r\n if (check(arr) || check(arr1)) {\r\n console.log(2);\r\n continue;\r\n }\r\n console.log(-1);\r\n } else {\r\n let ans = false;\r\n for (let i = 0; i <= n * 2; i++) {\r\n if (check(arr) || check(arr1)) {\r\n console.log(i);\r\n ans = true;\r\n break;\r\n }\r\n if (i % 2 === 0) {\r\n swap(arr);\r\n rev(arr1);\r\n } else {\r\n rev(arr);\r\n swap(arr1);\r\n }\r\n }\r\n if (ans === false) console.log(-1);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n var arr = input[1].split(\" \").map((i) => {\r\n return Number(i);\r\n })\r\n function op1(arr) {\r\n var temp = [];\r\n for (var i = 0; i < n; i++) {\r\n temp[2 * i + 1] = arr[2 * i];\r\n temp[2 * i] = arr[2 * i + 1];\r\n }\r\n return temp;\r\n }\r\n function op2(arr) {\r\n var temp = [];\r\n for (var i = 0; i < n; i++) {\r\n temp[i] = arr[i + n];\r\n temp[i + n] = arr[i];\r\n }\r\n return temp;\r\n }\r\n var sorted = arr.slice();\r\n sorted.sort((a, b) => {\r\n return a - b;\r\n })\r\n var set = new Set();\r\n var queue = [];\r\n queue.push(arr);\r\n set.add(arr.toString());\r\n var found = false;\r\n var step = 0;\r\n while (queue.length !== 0) {\r\n var l = queue.length;\r\n for (var m = 0; m < l; m++) {\r\n var curt = queue.shift();\r\n if (curt.toString() === sorted.toString()) {\r\n console.log(step);\r\n found = true;\r\n break;\r\n }\r\n var next1 = op1(curt);\r\n var next2 = op2(curt);\r\n if (!set.has(next1.toString())) {\r\n queue.push(next1);\r\n set.add(next1.toString());\r\n }\r\n if (!set.has(next2.toString())) {\r\n queue.push(next2);\r\n set.add(next2.toString());\r\n }\r\n }\r\n step++;\r\n }\r\n if (!found) {\r\n console.log(-1);\r\n }\r\n})"}], "negative_code": [{"source_code": "const increase = a => {\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== i + 1) return false;\n }\n return true;\n};\n\nconst permutation = (n, a, tag) => {\n const b = [...a];\n if (tag === 0) {\n for (let j = 0; j < n; j++) {\n let w = b[2 * j];\n b[2 * j] = b[2 * j + 1];\n b[2 * j + 1] = w;\n }\n } else if (tag === 1) {\n for (let j = 0; j < n; j++) {\n let w = b[j];\n b[j] = b[n + j];\n b[n + j] = w;\n }\n }\n return b;\n};\n\nconst solve = (n, a) => {\n if (increase(a)) return 0;\n\n let p1 = [...a];\n let t1 = 0;\n let p2 = [...a];\n let t2 = 1;\n for (let i = 1; i <= 4; i++) {\n p1 = permutation(n, p1, t1);\n p2 = permutation(n, p2, t2);\n if (increase(p1) || increase(p2)) return i;\n t1 = 1 - t1;\n t2 = 1 - t2;\n }\n\n return -1;\n};\n\nconst main = () => {\n const n = readInt();\n const a = readListInt();\n\n console.log(solve(n, a));\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n var arr = input[1].split(\" \").map((i) => {\r\n return Number(i);\r\n })\r\n function op1(arr) {\r\n var temp = [];\r\n for (var i = 0; i < n; i++) {\r\n temp[2 * i + 1] = arr[2 * i];\r\n temp[2 * i] = arr[2 * i + 1];\r\n }\r\n return temp;\r\n }\r\n function op2(arr) {\r\n var temp = [];\r\n for (var i = 0; i < n; i++) {\r\n temp[i] = arr[i + n];\r\n temp[i + n] = arr[i];\r\n }\r\n return temp;\r\n }\r\n var sorted = arr.slice();\r\n sorted.sort((a, b) => {\r\n return a - b;\r\n })\r\n var set = new Set();\r\n set.add(arr.toString());\r\n function helper(arr, set, step) {\r\n if (arr.toString() === sorted.toString()) {\r\n return step;\r\n }\r\n var min = Infinity;\r\n var next = op1(arr);\r\n if (!set.has(next.toString())) {\r\n set.add(next.toString());\r\n min = Math.min(helper(next, set, step + 1), min);\r\n }\r\n next = op2(arr);\r\n if (!set.has(next.toString())) {\r\n set.add(next.toString());\r\n min = Math.min(helper(next, set, step + 1), min);\r\n }\r\n return min;\r\n }\r\n var result = helper(arr, set, 0);\r\n if (result === Infinity) {\r\n console.log(-1);\r\n } else {\r\n console.log(result);\r\n }\r\n})"}], "src_uid": "99dd00f4840188d4d96260100b20e9c9"} {"source_code": "function game(a,b){\r\n var p, x, q;\r\n p = Math.ceil((a+b)/2);\r\n q = a + b - p;\r\n var ans = new Set();\r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n \r\n p = Math.floor((a+b)/2);\r\n q = a + b - p;\r\n \r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n return Array.from(ans).sort(function(a, b) {\r\n return a - b;\r\n});\r\n}\r\n \r\nvar t = parseInt(readline());\r\nvar inp;\r\n \r\nfor (var i=0; iparseInt(x));\r\n var a = inp[0];\r\n var b = inp[1];\r\n var ans = game(a,b);\r\n print(ans.length);\r\n var s = \"\";\r\n for(item of ans){\r\n s += item + \" \";\r\n }\r\n print(s);\r\n}", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let ans = [],\r\n obj = {};\r\n const push = (val) => {\r\n if (obj[val] === undefined) {\r\n ans.push(val);\r\n obj[val] = 1;\r\n }\r\n };\r\n let [a, b] = iInpArr();\r\n let right = Math.ceil((a + b) / 2);\r\n let left = Math.floor((a + b) / 2);\r\n let max = Math.max(a, b);\r\n let min = Math.min(a, b);\r\n let st = Math.abs(left - min);\r\n push(st);\r\n for (let i = 1; i <= min; i++) {\r\n push(st + i * 2);\r\n }\r\n let st1 = Math.abs(right - min);\r\n push(st1);\r\n for (let i = 1; i <= min; i++) {\r\n push(st1 + i * 2);\r\n }\r\n console.log(ans.length);\r\n console.log(ans.sort((a, b) => a - b).join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\r\n\t\tif (a > b) \r\n\t\t\t[a, b] = [b, a];\r\n\r\n\t\tlet mb = Math.floor(Math.abs(a - b)/2);\r\n\r\n\t\tlet times, inc;\r\n\t\tif ((a + b) % 2 == 0) {\r\n\t\t\ttimes = a + 1;\r\n\t\t\tinc = 2;\r\n\t\t} else {\r\n\t\t\ttimes = 2 * (a + 1);\r\n\t\t\tinc = 1;\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < times; i++) {\r\n\t\t\tans.push(mb);\r\n\t\t\tmb += inc;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let ans = [],\r\n obj = {};\r\n const push = (val) => {\r\n if (obj[val] === undefined) {\r\n ans.push(val);\r\n obj[val] = 1;\r\n }\r\n };\r\n let [a, b] = iInpArr();\r\n let right = Math.ceil((a + b) / 2);\r\n let left = Math.floor((a + b) / 2);\r\n let max = Math.max(a, b);\r\n let min = Math.min(a, b);\r\n let st = Math.abs(right - max);\r\n push(st);\r\n for (let i = 1; i <= min; i++) {\r\n push(i * 2);\r\n }\r\n let st1 = Math.abs(right - min);\r\n push(st1);\r\n for (let i = 1; i <= min; i++) {\r\n push(st1 + i * 2);\r\n }\r\n console.log(ans.length);\r\n console.log(ans.sort((a, b) => a - b).join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "function game(a,b){\r\n var p, x, q;\r\n p = Math.ceil((a+b)/2);\r\n q = a + b - p;\r\n var ans = new Set();\r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n \r\n p = Math.floor((a+b)/2);\r\n q = a + b - p;\r\n \r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n return Array.from(ans).sort();\r\n}\r\n \r\nvar t = parseInt(readline());\r\nvar inp;\r\n \r\nfor (var i=0; iparseInt(x));\r\n var a = inp[0];\r\n var b = inp[1];\r\n var ans = game(a,b);\r\n print(ans.length);\r\n var s = \"\";\r\n for(item of ans){\r\n s += item + \" \";\r\n }\r\n print(s);\r\n}"}, {"source_code": "function game(a,b){\r\n var p, x, q;\r\n p = Math.ceil((a+b)/2);\r\n q = a + b - p;\r\n var ans = new Set();\r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n \r\n p = Math.floor((a+b)/2);\r\n q = a + b - p;\r\n \r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n return ans;\r\n}\r\n \r\nvar t = parseInt(readline());\r\nvar inp;\r\n \r\nfor (var i=0; iparseInt(x));\r\n var a = inp[0];\r\n var b = inp[1];\r\n var ans = game(a,b);\r\n print(ans.size);\r\n var s = \"\";\r\n for(item of ans){\r\n s += item + \" \";\r\n }\r\n print(s);\r\n}"}, {"source_code": "function game(a,b){\r\n var p, x, q;\r\n p = Math.ceil((a+b)/2);\r\n q = a + b - p;\r\n var ans = new Set();\r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n \r\n p = Math.floor((a+b)/2);\r\n q = a + b - p;\r\n \r\n for (var x=0; x<=p; x++){\r\n var y = a - (p-x);\r\n if(y<=q && y>=0) ans.add(x+y);\r\n }\r\n return ans;\r\n}\r\n\r\nvar t = parseInt(readline());\r\nvar inp;\r\n\r\nfor (var i=0; iparseInt(x));\r\n var a = inp[0];\r\n var b = inp[1];\r\n var ans = game(a,b);\r\n for(item of ans){\r\n print(item);\r\n }\r\n}"}], "src_uid": "04a37e9c68761f9a2588c0bbecad2147"} {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let s = ipt.split(EOL)[0]\n console.log(s\n .replace(/(\\d)\\s+(?=\\d)/g, '$1*')\n .replace(/\\s/g, '')\n .replace(/,/g, ', ')\n .replace(/\\s?\\.\\.\\./g, ' ...')\n .replace(/\\*/g, ' ')\n .trim())\n})", "positive_code": [{"source_code": "str = readline();\nstr = str.replace(/(\\d+) +(\\d+)/g, '$1_$2');\nstr = str.replace(/(\\d+) +(\\d+)/g, '$1_$2');\nstr = str.replace(/ /g, '');\nstr = str.replace(/_/g, ' ');\nstr = str.replace(/,/g, ', ');\nstr = str.replace(/\\.\\.\\./g, ' ...');\nstr = str.replace(/ +/g, ' ');\nstr = str.replace(/ $/g, '');\nstr = str.replace(/^ /g, '');\nwrite(str);"}, {"source_code": "var str = readline();\n\nstr = str.replace(/,\\s*/g,', ');\nstr = str.replace(/\\s*\\.\\.\\./g, ' ...');\nstr = str.replace(/([0-9]+)\\s+([0-9])/g, '$1 $2');\nstr = str.replace(/\\.\\.\\.\\s*([0-9])/g, '...$1');\nstr = str.replace(/\\.\\.\\.\\s*,/g, '...,');\nstr = str.replace(/([0-9]+)\\s*,/g, '$1,');\nstr = str.replace(/^\\s*/, '');\nstr = str.replace(/\\s*$/, '');\n\nprint(str);"}, {"source_code": "'use strict';\n\n/*let input = `......,,,,,...... 1234 1234 1234 , 1234 ... , 1234 ... 1234 ... , 1234`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar inpStr = readline();\nvar inpArr = inpStr.trim().split('').reduce(function (acc, val, i, arr) {\n\tif (val !== \" \" || !(isNaN(parseInt(acc[acc.length - 1])) || isNaN(parseInt(arr[i + 1])))) {\n\t\tacc.push(val);\n\t}\n\treturn acc;\n}, []);\n\nfor (var i = 0; i < inpArr.length; i++) {\n\tif (inpArr[i] === \",\") {\n\t\tinpArr.splice(i + 1, 0, \" \");\n\t\ti++;\n\t} else if (inpArr[i] === \".\" && inpArr[i + 1] === \".\" && inpArr[i + 2] === \".\") {\n\t\tif (inpArr[i - 1] !== \" \") {\n\t\t\tinpArr.splice(i, 0, \" \");\n\t\t\ti += 3;\n\t\t} else {\n\t\t\ti += 2;\n\t\t}\n\t}\n}\n\nprint(inpArr.join('').trim());\n"}], "negative_code": [{"source_code": "'use strict';\n\n/*let input = `1 2 3 6 4 545 45 12`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar inpStr = readline();\nvar inpArr = inpStr.trim().split('').reduce(function (acc, val, i, arr) {\n\tif (val !== \" \" || !(isNaN(parseInt(acc[acc.length - 1])) || isNaN(parseInt(arr[i + 1])))) {\n\t\tacc.push(val);\n\t}\n\treturn acc;\n}, []);\n\nfor (var i = 0; i < inpArr.length; i++) {\n\tif (inpArr[i] === \",\") {\n\t\tinpArr.splice(i + 1, 0, \" \");\n\t} else if (inpArr[i] === \".\" && inpArr[i + 1] === \".\" && inpArr[i + 2] === \".\" && inpArr[i - 1] !== \" \") {\n\t\tinpArr.splice(i, 0, \" \");\n\t\ti += 3;\n\t}\n}\n\nprint(inpArr.join('').trim());\n"}, {"source_code": "'use strict';\n\n/*let input = `...,1,2,3,...`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar inpStr = readline();\nvar inpArr = inpStr.split('').filter(function (el) {\n\treturn el != \" \";\n});\nfor (var i = 0; i < inpArr.length; i++) {\n\tif (inpArr[i] === \",\") {\n\t\tinpArr.splice(i + 1, 0, \" \");\n\t} else if (inpArr[i] === \".\" && inpArr[i + 1] === \".\" && inpArr[i + 2] === \".\" && inpArr[i - 1] !== \" \") {\n\t\tinpArr.splice(i, 0, \" \");\n\t\ti += 3;\n\t}\n}\nprint(inpArr.join('').trim());\n"}, {"source_code": "str = readline();\nstr = str.replace(/ /g, '');\nstr = str.replace(/,/g, ', ');\nstr = str.replace(/\\.\\.\\./g, ' ...');\nstr = str.replace(/ +/g, ' ');\nstr = str.replace(/ $/g, '');\nstr = str.replace(/^ /g, '');\nwrite(str);"}, {"source_code": "str = readline();\nstr = str.replace(/,/g, ', ');\nstr = str.replace(/(\\d+?) +?,/g, '$1,');\nstr = str.replace(/\\.\\.\\./g, ' ...');\nstr = str.replace(/ +/g, ' ');\nstr = str.replace(/ $/g, '');\nstr = str.replace(/^ /g, '');\nwrite(str);"}, {"source_code": "str = readline();\nstr = str.replace(/(\\d+?) +?(\\d+?)/g, '$1')\nstr = str.replace(/,/g, ', ');\nstr = str.replace(/(\\d+?) +/g, '$1');\nstr = str.replace(/\\.\\.\\./g, ' ...');\nstr = str.replace(/ +/g, ' ');\nstr = str.replace(/ $/g, '');\nstr = str.replace(/^ /g, '');\nwrite(str);"}, {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let s = ipt.split(EOL)[0]\n console.log(s\n .replace(/(\\d)\\s+(\\d)/, '$1*$2')\n .replace(/\\s/g, '')\n .replace(/,/g, ', ')\n .replace(/\\s?\\.\\.\\./g, ' ...')\n .replace(/\\*/g, ' ')\n .trim())\n})"}, {"source_code": "var str = readline();\n\nstr = str.replace(/,\\s*/g,', ');\nstr = str.replace(/\\s*\\.\\.\\./g, ' ...');\nstr = str.replace(/([0-9])\\s+([0-9])/g, '$1 $2');\nstr = str.replace(/\\.\\.\\.\\s*([0-9])/g, '...$1');\nstr = str.replace(/\\.\\.\\.\\s*,/g, '...,');\nstr = str.replace(/([0-9])\\s,/g, '$1,');\nstr = str.replace(/^\\s*/, '');\nstr = str.replace(/\\s*$/, '');\n\nprint(str);"}], "src_uid": "c7d8c71a1f7e6c7364cce5bddd488a2f"} {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n\n // PROCESSING:\n let min = n-1;\n for (let i=0; i0.000001)\n cnt++;\n }\n min = Math.min(cnt, min)\n }\n }\n return min;\n};\n ", "positive_code": [{"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n let t = inputReader.readNumber();\r\n\r\n function solve() {\r\n let n = inputReader.readNumber();\r\n let a = inputReader.readNumberArray();\r\n let ans = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let cur = 0;\r\n for (let k = 0; k < n; k++) {\r\n if ((a[j] - a[i]) * (k - i) != (a[k] - a[i]) * (j - i)) cur++;\r\n }\r\n ans = Math.min(ans, cur);\r\n }\r\n }\r\n console.log(ans == Infinity ? 0 : ans);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readNumberArray() {\r\n return _inputLines[_lineNumber++].split(\" \").map((val) => Number(val));\r\n }\r\n\r\n return {\r\n readNumber,\r\n readNumberArray,\r\n };\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction isEqual (a, b) {\r\n\tconst prec = 1e-3;\r\n\treturn Math.abs(a - b) < prec;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mxm = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i + 1; j < n; j++) {\r\n\t\t\t\tconst d = (a[j] - a[i]) / (j-i);\r\n\t\t\t\tconst A = a[j] - a[i];\r\n\t\t\t\tconst B = j - i;\r\n\t\t\t\tlet matches = 0;\r\n\t\t\t\tfor (let k = 0; k < n; k++) {\r\n\t\t\t\t\tmatches += B*a[k] == B*a[i] + A*(k-i);\r\n\t\t\t\t}\r\n\t\t\t\tmxm = Math.max(mxm, matches);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-mxm);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1000;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mxm = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i + 1; j < n; j++) {\r\n\t\t\t\tconst d = (a[j] - a[i]) / (j-i);\r\n\t\t\t\tlet matches = 0;\r\n\t\t\t\tfor (let k = 0; i+k < n; k++) {\r\n\t\t\t\t\tmatches += Math.abs(a[i+k] - (a[i] + d*k)) < 1e-3;\r\n\t\t\t\t}\r\n\t\t\t\tmxm = Math.max(mxm, matches);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-mxm);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1000;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mxm = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = i + 1; j < n; j++) {\r\n\t\t\t\tconst d = (a[j] - a[i])/ (j-i);\r\n\t\t\t\tlet matches = 0;\r\n\t\t\t\tfor (let k = 0; i+k < n; k++) {\r\n\t\t\t\t\tmatches += a[i+k] == a[i] + d*k;\r\n\t\t\t\t}\r\n\t\t\t\tmxm = Math.max(mxm, matches);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-mxm);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "6aca8c549822adbe96a58aee4b0d4b3f"} {"source_code": "var s0=readline().split(' ')\nvar n=+s0[0],have=+s0[1];\nvar s=readline();\nvar l=-1,h=n-2;\nwhile(l+1n-1) to=n-1;\n while(to>at&&s[to]=='1') --to;\n if(to==at) { ok=false; break; }\n ++need; at=to;\n }\n //print(m,\" -> \",need,\" (\",ok,\")\");\n if(ok&&need<=have) h=m; else l=m;\n}\nprint(h);\n", "positive_code": [{"source_code": "var n, k\ns1 = readline().split(' ')\nn = 1*s1[0]\nk = 1*s1[1]\ns = readline()\n\nvar l = 0\nvar r = n\nvar Fail = 0\nfor (var i = 0; i < n; ++i) {\n if (s[i] == '1') {\n Fail = 1\n }\n}\nif (Fail == 0 && k == n) {\n print(0)\n} else {\nwhile (l + 1 < r) {\n var m = Math.floor((l + r) / 2)\n \n var rem = k\n var last = 0\n var prev = -1\n var fail = 0\n for (var i = 0; i < n; ++i) {\n if (s[i] == '0') {\n prev = i\n }\n if (i == 0 || i == last + m || i == n-1) {\n if (prev == -1) {\n fail = 1\n break\n }\n \n last = prev\n --rem\n prev = -1\n }\n }\n \n if (fail == 1 || rem < 0) {\n l = m\n } else {\n r = m\n }\n}\nprint(r-1)\n}"}], "negative_code": [], "src_uid": "e33b0a752dc1aba25da21e20435e3fe2"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (str) => {\n const ans = str + [...str].reverse().join('');\n console.log(ans);\n});\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar s = next();\n\tvar output = s;\n\tfor(var i = 0; i < s.length; i++){\n\t\toutput += s[s.length - 1 - i];\n\t}\n\tmyout(output);\n}\n"}, {"source_code": "var a = readline()\nwrite(a)\nwrite(a.split(\"\").reverse().join(\"\"))"}], "negative_code": [], "src_uid": "9b1887582a9eb7cff49994ddcc2ee9b8"} {"source_code": "const numSplit = (n) => n.toString().split(\"\");\n\nvar num = numSplit(readline());\n\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + Number(n),0));\n\nvar count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n\nprint(count);", "positive_code": [{"source_code": "/* TEST CASE\ninput\n0\noutput\n0\ninput\n10\noutput\n1\ninput\n991\noutput\n3\n */\nfunction sumOfDigits(s) {\n var ret = 0;\n for (var i = s.length - 1; i >= 0; i--) {\n \tret += parseInt(s[i]);\n }\n \n return ret.toString();\n}\n\nfunction main() {\n\tvar s = readline();\n\tvar answer = 0;\n\twhile (s.length > 1) {\n\t\ts = sumOfDigits(s);\n\t\tanswer++;\n\t}\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "const readline = require('readline');\nlet inputs = [];\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\n \nrl.on('close', () => {\n\tconst n = inputs[0].split('').map((a) => {return parseInt(a)});\n console.log(solution(n));\n \n})\n\n// let stdin = process.stdin;\n// stdin.setEncoding('utf8');\n\n// stdin.on('data', function (data) {\n// let input = data.split('\\n');\n// let n = input[0].split('').map((a) => {return parseInt(a)});\n\n// console.log(solution(n));\n// });\n\n\nfunction solution(n) {\n\tif (n.length === 1) {\n\t\treturn 0;\n\t}\n\tlet sumDig = n.reduce((a, b) => {return a+b}, 0);\n\tlet count = 1;\n\twhile (parseInt(sumDig / 10) !== 0) {\n\t\tcount += 1;\n\t\tsumDig = findSum(sumDig)\n\t}\n\treturn count;\n}\n\nfunction findSum(n) {\n\tlet sum = 0;\n\tlet dig = 0;\n\twhile (n !== 0) {\n\t\tdig = n % 10;\n\t\tsum += dig;\n\t\tn = parseInt(n / 10);\n\t}\n\treturn sum;\n}"}, {"source_code": "line = readline();\nvar count =0;\nwhile(line.length > 1) {\n count++;\n var result = 0;\n for(var i =0; i parseInt(x);\nvar toSum = (a, b) =>(a+b);\nvar isum = x => x.split('').map(toInt).reduce(toSum);\n\nvar x = readline();\n\nvar q = [x], res=0;\nwhile(q.length > 0) {\n var x = q.shift();\n \n if (x.length>=2) {\n q.push(isum(x)+'');\n res++;\n }\n}\nprint(res);\n"}], "negative_code": [{"source_code": "const numSplit = (n) => n.toString().split(\"\");\n\nvar num = readline();\n/*\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + n,0));\n\nlet count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n*/\nprint(num);"}, {"source_code": "const numSplit = (n) => n.toString().split(\"\");\n\nvar num = numSplit(readline());\n/*\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + Number(n),0));\n\nlet count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n*/\nprint(num);"}, {"source_code": "const numSplit = (n) => n.toString().split(\"\");\n\nvar num = numSplit(readline());\n/*\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + n,0));\n\nlet count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n*/\nprint(num);"}, {"source_code": "/*const numSplit = (n) => n.toString().split(\"\");\n\nconst num = numSplit(readLine());\n\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + n,0));\n\nlet count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n*/\nprint(0);"}, {"source_code": "const numSplit = (n) => n.toString().split(\"\");\n\nvar num = readline();\n/*\nconst sumDigits = (numArr) => numSplit(numArr.reduce((sum,n) => sum + n,0));\n\nlet count = 0;\n\nconst recursive = (numArr) => {\n if (numArr.length == 1) return;\n count++;\n recursive(sumDigits(numArr));\n} \n\nrecursive(num);\n*/\nprint(numSplit(num));"}, {"source_code": "var toInt = x => parseInt(x);\nvar toSum = (a, b) =>(a+b);\nvar isum = x => (x+'').split('').map(toInt).reduce(toSum);\n\nvar x = parseInt(readline());\nvar q = [x], res=0;\nwhile(q.length > 0) {\n var x = q.shift();\n if (x>=10) {\n q.push(isum(x));\n res++;\n }\n}\nprint(res);\n"}, {"source_code": "var toInt = x => parseInt(x);\nvar toSum = (a, b) =>(a+b);\nvar isum = x => x.split('').map(toInt).reduce(toSum);\n\nvar x = readline();\n\nvar q = [x], res=0;\nwhile(q.length > 0) {\n var x = q.shift();\n \n if (x.length>2) {\n q.push(isum(x)+'');\n res++;\n }\n}\nprint(res);\n"}], "src_uid": "ddc9201725e30297a5fc83f4eed75fc9"} {"source_code": "function get(mp, line) {\n if (!mp.has(line)) {\n var obj = new Object();\n var ll = line.split(/ /);\n obj.name = ll[0];\n obj.vers = parseInt(ll[1]);\n obj.used = false;\n obj.links = [];\n mp.set(line, obj);\n }\n return mp.get(line);\n}\n\nfunction main(rl) {\n var n = parseInt(rl());\n var mp = new Map();\n var head = null;\n for (var i = 0; i < n; ++i) {\n var obj0 = get(mp, rl());\n if (head == null)\n head = obj0;\n \n var num_links = parseInt(rl());\n for (var j = 0; j < num_links; ++j) {\n obj0.links.push(get(mp, rl()));\n }\n rl();\n }\n \n var res = [];\n \n mp.clear();\n var queue0 = [];\n var queue1 = [head];\n while (0 < queue0.length || 0 < queue1.length) {\n queue0 = queue1; queue1 = [];\n queue0.sort((a, b) => (b.vers - a.vers));\n \n queue0.forEach(function(it) { \n if (mp.has(it.name)) return;\n mp.set(it.name, true);\n \n res.push(it);\n it.links.forEach(function(it0) {\n if (it0.used) return;\n it0.used = true;\n if (mp.has(it0.name)) return;\n queue1.push(it0);\n }); \n });\n }\n \n res.shift();\n res.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name));\n write(res.length + '\\n');\n res.forEach(function(it0) {\n write(it0.name + \" \" + it0.vers + \"\\n\");\n });\n \n}\n\nmain(readline);", "positive_code": [{"source_code": "\nfunction getInput () {\n var prCount = parseInt(readline(), 10);\n\n var input = [];\n\n for (var i = 1; i <= prCount; i++) {\n var pr = {};\n\n pr.name = readline();\n pr.deps = [];\n\n var depsCount = parseInt(readline(), 10);\n for (var k = 1; k <= depsCount; k++) {\n pr.deps.push(readline());\n }\n\n input.push(pr);\n\n readline();\n }\n\n return input;\n}\n\n\nfunction getDeps (input) {\n var allProjects = {}, key = 0, allKeys = [];\n var graph = [];\n\n input.forEach(function (project) {\n if (allProjects[project.name] == undefined) {\n allProjects[project.name] = {key: key, ver: +project.name.split(' ')[1], name: project.name.split(' ')[0]};\n allKeys.push(project.name)\n key++;\n }\n\n project.deps.forEach(function (prName) {\n if (allProjects[prName] == undefined) {\n allProjects[prName] = key;\n allProjects[prName] = {key: key, ver: +prName.split(' ')[1], name: prName.split(' ')[0]};\n allKeys.push(prName)\n key++;\n }\n })\n\n })\n\n input.forEach(function(project){\n var prIndex = allProjects[project.name].key;\n graph[prIndex] = [];\n\n project.deps.forEach(function (prName) {\n graph[prIndex][allProjects[prName].key] = 1\n });\n });\n\n initialProject = [input[0].name];\n function findInList(pr, prList) {\n var prName = allProjects[pr].name\n var prIndex = -1;\n prList.forEach(function(proj, index) {\n if (allProjects[proj].name == prName) {\n prIndex = index\n }\n })\n return prIndex;\n };\n\n function getDepsRoutine (prList) {\n var subresult = [];\n\n prList.forEach(function(prName){\n graph[allProjects[prName].key].forEach(function(el, index){\n var depName = allKeys[index];\n if (el == 1 && findInList(depName, result) == -1) {\n var prIndexInSubresult = findInList(depName, subresult);\n if (prIndexInSubresult !== -1) {\n if (allProjects[subresult[prIndexInSubresult]].ver < allProjects[depName].ver)\n subresult[prIndexInSubresult] = depName;\n } else {\n subresult.push(depName)\n }\n }\n });\n });\n\n result = result.concat(subresult);\n if (subresult.length > 0)\n getDepsRoutine(subresult);\n }\n\n var result = [initialProject[0]];\n\n getDepsRoutine(initialProject)\n result.shift();\n\n return result.sort();\n}\n\nvar answer = getDeps(getInput());\n\nprint(answer.length);\n\nanswer.forEach(function(el){\n print(el)\n})\n"}], "negative_code": [{"source_code": "\nfunction getInput () {\n var prCount = parseInt(readline(), 10);\n\n var input = [];\n\n for (var i = 1; i <= prCount; i++) {\n var pr = {};\n\n pr.name = readline();\n pr.deps = [];\n\n var depsCount = parseInt(readline(), 10);\n for (var k = 1; k <= depsCount; k++) {\n pr.deps.push(readline());\n }\n\n input.push(pr);\n\n readline();\n }\n\n return input;\n}\n\n\nfunction getDeps (input) {\n var allProjects = {}, key = 0, allKeys = [];\n var graph = [];\n\n input.forEach(function (project) {\n if (allProjects[project.name] == undefined) {\n allProjects[project.name] = key;\n allKeys.push(project.name)\n key++;\n }\n\n project.deps.forEach(function (prName) {\n if (allProjects[prName] == undefined) {\n allProjects[prName] = key;\n allKeys.push(prName)\n key++;\n }\n })\n\n })\n\n\n input.forEach(function(project){\n var prIndex = allProjects[project.name];\n graph[prIndex] = [];\n\n project.deps.forEach(function (prName) {\n graph[prIndex][allProjects[prName]] = 1\n });\n });\n\n initialProject = [input[0].name];\n function findInList(pr, prList) {\n var prName = pr.split(' ')[0]\n var prIndex = -1;\n prList.forEach(function(proj, index) {\n if (proj.split(' ')[0] == prName) {\n prIndex = index\n }\n })\n return prIndex;\n };\n\n function getDepsRoutine (prList) {\n var subresult = [];\n\n prList.forEach(function(prName){\n graph[allProjects[prName]].forEach(function(el, index){\n var depName = allKeys[index];\n if (el == 1 && findInList(depName, result) == -1) {\n var prIndexInSubresult = findInList(depName, subresult);\n if (prIndexInSubresult !== -1) {\n if (subresult[prIndexInSubresult].split(' ')[1] < depName.split(' ')[1])\n subresult.splice(prIndexInSubresult, 1, depName);\n } else {\n subresult.push(depName)\n }\n }\n });\n });\n\n result = result.concat(subresult);\n if (subresult.length > 0)\n getDepsRoutine(subresult);\n }\n\n var result = [initialProject[0]];\n\n getDepsRoutine(initialProject)\n result.shift();\n\n return result.sort();\n}\n\nvar answer = getDeps(getInput());\n\nprint(answer.length);\n\nanswer.forEach(function(el){\n print(el)\n})\n"}, {"source_code": "\nfunction getInput () {\n var prCount = parseInt(readline(), 10);\n\n var input = [];\n\n for (var i = 1; i <= prCount; i++) {\n var pr = {};\n\n pr.name = readline();\n pr.deps = [];\n\n var depsCount = parseInt(readline(), 10);\n for (var k = 1; k <= depsCount; k++) {\n pr.deps.push(readline());\n }\n\n input.push(pr);\n\n readline();\n }\n\n return input;\n}\n\n\nfunction getDeps (input) {\n var allProjects = {}, key = 0, allKeys = [];\n var graph = [];\n\n input.forEach(function (project) {\n if (allProjects[project.name] == undefined) {\n allProjects[project.name] = {key: key, ver: project.name.split(' ')[0], name: project.name.split(' ')[1]};\n allKeys.push(project.name)\n key++;\n }\n\n project.deps.forEach(function (prName) {\n if (allProjects[prName] == undefined) {\n allProjects[prName] = key;\n allProjects[prName] = {key: key, ver: +prName.split(' ')[0], name: prName.split(' ')[1]};\n allKeys.push(prName)\n key++;\n }\n })\n\n })\n\n input.forEach(function(project){\n var prIndex = allProjects[project.name].key;\n graph[prIndex] = [];\n\n project.deps.forEach(function (prName) {\n graph[prIndex][allProjects[prName].key] = 1\n });\n });\n\n initialProject = [input[0].name];\n function findInList(pr, prList) {\n var prName = allProjects[pr].name\n var prIndex = -1;\n prList.forEach(function(proj, index) {\n if (allProjects[proj].name == prName) {\n prIndex = index\n }\n })\n return prIndex;\n };\n\n function getDepsRoutine (prList) {\n var subresult = [];\n\n prList.forEach(function(prName){\n graph[allProjects[prName].key].forEach(function(el, index){\n var depName = allKeys[index];\n if (el == 1 && findInList(depName, result) == -1) {\n var prIndexInSubresult = findInList(depName, subresult);\n if (prIndexInSubresult !== -1) {\n if (allProjects[subresult[prIndexInSubresult]].ver < allProjects[depName].ver)\n subresult[prIndexInSubresult] = depName;\n } else {\n subresult.push(depName)\n }\n }\n });\n });\n\n result = result.concat(subresult);\n if (subresult.length > 0)\n getDepsRoutine(subresult);\n }\n\n var result = [initialProject[0]];\n\n getDepsRoutine(initialProject)\n result.shift();\n\n return result.sort();\n}\n\nvar answer = getDeps(getInput());\n\nprint(answer.length);\n\nanswer.forEach(function(el){\n print(el)\n})\n"}], "src_uid": "8e79a1de43e055cf81d7b30d6090b7ff"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let pos = [],\r\n neg = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) neg.push(Math.abs(arr[i]));\r\n else pos.push(arr[i]);\r\n }\r\n let sum = 0,\r\n max1 = -Infinity,\r\n max2 = -Infinity;\r\n if (neg.length !== 0) {\r\n neg.sort((a, b) => b - a);\r\n max1 = neg[0];\r\n let j = 0;\r\n while (j < neg.length) {\r\n sum += neg[j] * 2;\r\n j += k;\r\n }\r\n }\r\n if (pos.length !== 0) {\r\n pos.sort((a, b) => b - a);\r\n max2 = pos[0];\r\n let j = 0;\r\n while (j < pos.length) {\r\n sum += pos[j] * 2;\r\n j += k;\r\n }\r\n }\r\n if (max1 > max2) sum -= neg[0];\r\n else sum -= pos[0];\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n \r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [maxCases, limit] = readline().split(\" \");\r\n const bagLimit = Number(limit);\r\n const depotPositions = readline().split(\" \").slice(0, maxCases).map(n => Number(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n >= 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n \r\n if (!shouldReturn) {\r\n totalDistance -= sortedPositions[sortedPositions.length - 1];\r\n }\r\n \r\n // Pick next\r\n for (let positionIndex = sortedPositions.length - 1 ; positionIndex >= 0 ; positionIndex -= bagCarryingLimit) {\r\n totalDistance += sortedPositions[positionIndex] * 2;\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, bagLimit, false));\r\n } else {\r\n print(deliverBags(negativePositions, bagLimit, false));\r\n }\r\n }\r\n}"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tconst calc = (arr, k) => {\r\n\t\t// print(arr);\r\n\t\t// print(arr.length);\r\n\t\tif (arr.length === 0)\r\n\t\t\treturn 0;\r\n\t\tarr.sort(function(a, b){return a-b});\r\n\t\tvar ans2 = 0;\r\n\t\tvar i = arr.length - 1; // take the last item firstChild\r\n\t\twhile (i >= 0) {\r\n\t\t\tans2 += 2 * arr[i];\r\n\t\t\tj = Math.max(0, i - k + 1);\r\n\t\t\ti = j - 1;\r\n\t\t}\r\n\t\tans2 -= arr[arr.length - 1]; // don't come back\r\n\t\treturn ans2;\r\n\t}\r\n\t\r\n\tvar t = readInt();\r\n\tconst allans = [];\r\n\twhile (t--) {\r\n\t\tvar nk = readIntArr();\r\n\t\tvar n = nk[0], k = nk[1];\r\n\t\tvar a = readIntArr();\r\n\t\t// print(a);\r\n\t\tvar pos = []; var neg = [];\r\n\t\tfor (var x of a) {\r\n\t\t\tif (x > 0)\r\n\t\t\t\tpos.push(x);\r\n\t\t\telse\r\n\t\t\t\tneg.push(-x);\r\n\t\t}\r\n\t\tvar pos2 = calc(pos, k);\r\n\t\tvar neg2 = calc(neg, k);\r\n\t\tvar extra = 0;\r\n\t\tif (pos.length > 0 && neg.length > 0) { // 1 of them needs to come back\r\n\t\t\textra = Math.min(pos[pos.length - 1], neg[neg.length - 1]);\r\n\t\t}\r\n\t\t// print(\"pos2:\" + pos2 + \" neg2:\" + neg2 + \" extra:\" + extra);\r\n\t\tvar ans = pos2 + neg2 + extra;\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k], arr) {\r\n const min = arr.filter(i => i < 0).sort((a, b) => a - b),\r\n max = (arr.filter(i => i >= 0).sort((a, b) => b - a))\r\n\r\n let lastM = 0, lastP = 0\r\n let aa = min.length, bb = max.length\r\n if (min.length !== 0) {\r\n lastM = Math.abs(min[0])\r\n }\r\n if (max.length !== 0) {\r\n lastP = max[0]\r\n }\r\n let tmp = k, ds = 0\r\n while (aa !== 0) {\r\n aa--\r\n if (!--tmp) {\r\n break\r\n }\r\n }\r\n tmp = k\r\n while (bb !== 0) {\r\n bb--\r\n if (!--tmp) {\r\n break\r\n }\r\n }\r\n while (aa !== 0) {\r\n tmp = k\r\n ds += Math.abs(min[min.length - aa]) * 2\r\n while (aa !== 0) {\r\n aa--\r\n if (!--tmp) {\r\n break\r\n }\r\n }\r\n }\r\n while (bb !== 0) {\r\n tmp = k\r\n ds += max[max.length - bb] * 2\r\n while (bb !== 0) {\r\n bb--\r\n if (!--tmp) {\r\n break\r\n }\r\n }\r\n }\r\n if (lastM === 0) {\r\n console.log(lastP + ds)\r\n } else if (lastP === 0) {\r\n console.log(lastM + ds)\r\n } else {\r\n console.log(Math.min(ds + lastM * 2 + lastP, ds + lastP * 2 + lastM))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\t\tconst a = [], b = [];\r\n\t\tlet mxd = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (x[i] > 0) a.push(x[i]);\r\n\t\t\tif (x[i] < 0) b.push(-x[i]);\r\n\t\t\tmxd = Math.max(mxd, Math.abs(x[i]));\r\n\t\t}\r\n\r\n\t\tfunction solve (x) {\r\n\t\t\tx.sort((first, second) => first - second);\r\n\r\n\t\t\tlet dist = 0;\r\n\t\t\tconst start = (x.length - 1 + k) % k;\r\n\t\t\tfor (let i = start; i < x.length; i += k) {\r\n\t\t\t\tdist += 2 * x[i];\r\n\t\t\t}\r\n\t\t\treturn dist;\r\n\t\t}\r\n\r\n\t\tconst ans = solve(a) + solve(b) - mxd;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\t\tconst a = [], b = [];\r\n\t\tlet mxd = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (x[i] > 0) a.push(x[i]);\r\n\t\t\tif (x[i] < 0) b.push(-x[i]);\r\n\t\t\tmxd = Math.max(mxd, Math.abs(x[i]));\r\n\t\t}\r\n\r\n\t\tfunction solve (x) {\r\n\t\t\tx.sort((first, second) => second - first);\r\n\t\t\tlet avl = 0, dist = 0;\r\n\t\t\tfor (let i = 0; i < x.length; i++) {\r\n\t\t\t\tif (avl == 0) dist += 2*x[i], avl = k;\r\n\t\t\t\tavl--;\r\n\t\t\t}\r\n\t\t\treturn dist;\r\n\t\t}\r\n\r\n\t\tconst ans = solve(a) + solve(b) - mxd;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var n=parseInt(readline());\r\nfor(var i=0;ia-b);\r\n var positive_depots=[];\r\n var positive_groups=[];\r\n var negative_depots=[];\r\n var negative_groups=[];\r\n var pempty=false;\r\n var nempty=false;\r\n var last_group;\r\n var distance=0;\r\n for(var depot of depots){\r\n depot>0?positive_depots.push(depot):negative_depots.push(depot);\r\n }\r\n positive_depots=positive_depots.reverse();\r\n for(var i2=0;i22*negative_groups[0][0]?last_group=\"+\":last_group=\"-\";\r\n for(var i4=0;i4 {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n \r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [maxCases, limit] = readline().split(\" \");\r\n const bagLimit = Number(limit);\r\n const depotPositions = readline().split(\" \").slice(0, maxCases).map(n => Number(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n > 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n \r\n if (!shouldReturn) {\r\n totalDistance -= sortedPositions[sortedPositions.length - 1];\r\n }\r\n \r\n // Pick next\r\n for (let positionIndex = sortedPositions.length - 1 ; positionIndex >= 0 ; positionIndex -= bagCarryingLimit) {\r\n totalDistance += sortedPositions[positionIndex] * 2;\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, bagLimit, false));\r\n } else {\r\n print(deliverBags(negativePositions, bagLimit, false));\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n \r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [maxCases, limit] = readline().split(\" \");\r\n const bagLimit = parseInt(limit);\r\n const depotPositions = readline().split(\" \").slice(0, maxCases).map(n => parseInt(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n > 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n \r\n if (!shouldReturn) {\r\n totalDistance -= sortedPositions[sortedPositions.length - 1];\r\n }\r\n \r\n // Pick next\r\n for (let positionIndex = sortedPositions.length - 1 ; positionIndex >= 0 ; positionIndex -= bagCarryingLimit) {\r\n totalDistance += sortedPositions[positionIndex] * 2;\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, bagLimit, false));\r\n } else {\r\n print(deliverBags(negativePositions, bagLimit, false));\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n\r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [_, limit] = readline().split(\" \");\r\n const bagLimit = parseInt(limit);\r\n const depotPositions = readline().split(\" \").map(n => parseInt(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n > 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n \r\n if (!shouldReturn) {\r\n totalDistance -= sortedPositions[sortedPositions.length - 1];\r\n }\r\n \r\n // Pick next\r\n for (let positionIndex = sortedPositions.length - 1 ; positionIndex >= 0 ; positionIndex -= bagCarryingLimit) {\r\n totalDistance += sortedPositions[positionIndex] * 2;\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, bagLimit, true);\r\n totalDeliveryDistance += deliverBags(negativePositions, bagLimit, false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, bagLimit, false))\r\n } else {\r\n print(deliverBags(negativePositions, bagLimit, false))\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n\r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [_, bagLimit] = readline().split(\" \");\r\n const depotPositions = readline().split(\" \").map(n => parseInt(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n > 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n \r\n // Pick next\r\n for (let positionIndex = sortedPositions.length - 1 ; positionIndex >= 0 ; positionIndex -= bagCarryingLimit) {\r\n totalDistance += sortedPositions[positionIndex] * 2;\r\n }\r\n \r\n if (!shouldReturn) {\r\n totalDistance -= sortedPositions[sortedPositions.length - 1];\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, parseInt(bagLimit), true);\r\n totalDeliveryDistance += deliverBags(positivePositions, parseInt(bagLimit), false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, parseInt(bagLimit), true);\r\n totalDeliveryDistance += deliverBags(negativePositions, parseInt(bagLimit), false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, parseInt(bagLimit), false));\r\n } else {\r\n print(deliverBags(negativePositions, parseInt(bagLimit), false));\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction main() {\r\n const testCases = readline();\r\n\r\n for (let i = 0 ; i < testCases ; i++) {\r\n const [_, bagLimit] = readline().split(\" \");\r\n const depotPositions = readline().split(\" \").map(n => parseInt(n));\r\n \r\n const negativePositions = depotPositions.filter(n => n < 0).map(n => n * -1).sort((a, b) => a - b);\r\n const positivePositions = depotPositions.filter(n => n > 0).sort((a, b) => a - b);\r\n \r\n function deliverBags(sortedPositions, bagCarryingLimit, shouldReturn) {\r\n let totalDistance = 0;\r\n let previousPosition = 0;\r\n let totalCarryingBags = bagCarryingLimit;\r\n for (let positionIndex = 0 ; positionIndex < sortedPositions.length ; positionIndex++) {\r\n \r\n totalDistance += sortedPositions[positionIndex] - previousPosition;\r\n previousPosition = sortedPositions[positionIndex];\r\n \r\n totalCarryingBags--;\r\n \r\n if ((totalCarryingBags === 0 && positionIndex !== sortedPositions.length - 1) || (sortedPositions.length - (positionIndex + 1) === bagCarryingLimit)) {\r\n totalDistance += previousPosition;\r\n previousPosition = 0;\r\n totalCarryingBags = bagCarryingLimit;\r\n }\r\n }\r\n \r\n if (shouldReturn && previousPosition !== 0) {\r\n totalDistance += previousPosition;\r\n }\r\n return totalDistance;\r\n }\r\n \r\n if (positivePositions.length > 0 && negativePositions.length > 0) {\r\n let totalDeliveryDistance = 0;\r\n if (positivePositions[positivePositions.length - 1] >= negativePositions[negativePositions.length - 1]) {\r\n totalDeliveryDistance += deliverBags(negativePositions, parseInt(bagLimit), true);\r\n totalDeliveryDistance += deliverBags(positivePositions, parseInt(bagLimit), false);\r\n print(totalDeliveryDistance);\r\n } else {\r\n totalDeliveryDistance += deliverBags(positivePositions, parseInt(bagLimit), true);\r\n totalDeliveryDistance += deliverBags(negativePositions, parseInt(bagLimit), false);\r\n print(totalDeliveryDistance);\r\n }\r\n } else if (positivePositions.length > 0) {\r\n print(deliverBags(positivePositions, parseInt(bagLimit), false));\r\n } else {\r\n print(deliverBags(negativePositions, parseInt(bagLimit), false));\r\n }\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\r\n\t\tconst pos = [], neg = [];\r\n\t\tfor (const elm of x) {\r\n\t\t\tif (elm >= 0)\r\n\t\t\t\tpos.push(elm);\r\n\t\t\telse\r\n\t\t\t\tneg.push(-elm);\r\n\t\t}\r\n\r\n\t\tpos.sort((a, b) => a - b);\r\n\t\tneg.sort((a, b) => a - b);\r\n\r\n\t\tlet ans = solve(pos) + solve(neg);\r\n\t\t//console.log({ans, pos, neg})\r\n\t\tans -= Math.max(pos.length ? pos[pos.length - 1] : 0, neg.length ? neg[neg.length - 1] : 0);\r\n\r\n\t\tfunction solve(ar) {\r\n\t\t\tlet res = 0;\r\n\t\t\tfor (let i = 0; i < ar.length; i++) {\r\n\t\t\t\tif ((i + 1 - n % k) % k == 0 || i == ar.length - 1) {\r\n\t\t\t\t\tres += 2 * ar[i];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let pos = [],\r\n neg = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] < 0) neg.push(Math.abs(arr[i]));\r\n else pos.push(arr[i]);\r\n }\r\n let sum = 0,\r\n max1 = -Infinity,\r\n max2 = -Infinity;\r\n if (neg.length !== 0) {\r\n neg.sort((a, b) => b - a);\r\n max1 = neg[0];\r\n let j = 0;\r\n while (j < neg.length) {\r\n sum += neg[j] * 2;\r\n j += k;\r\n }\r\n }\r\n if (pos.length !== 0) {\r\n max2 = pos[0];\r\n pos.sort((a, b) => b - a);\r\n let j = 0;\r\n while (j < pos.length) {\r\n sum += pos[j] * 2;\r\n j += k;\r\n }\r\n }\r\n if (max1 > max2) sum -= neg[0];\r\n else sum -= pos[0];\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "e4ac6031bc719752d078c3d0924b5d90"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let l = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n if (a[0][min] === '*') l[min][1]++;\r\n if (a[1][min] === '*') l[min][0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n var _l;\r\n const tmp = ((_l = l[i - 1]) !== null && _l !== void 0 ? _l : [0, 0]).map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n l[i][0] = Math.min(tmp[0], tmp[1] + 1, l[i - 1][1] + 2);\r\n l[i][1] = Math.min(tmp[1], tmp[0] + 1, l[i - 1][0] + 2);\r\n }\r\n return Math.min(...l[max]);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let dp = [0, 0];\r\n if (a[0][min] === '*') dp[1]++;\r\n if (a[1][min] === '*') dp[0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n const tmp = dp.map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n tmp[0] = Math.min(tmp[0], dp[1] + 2);\r\n tmp[1] = Math.min(tmp[1], dp[0] + 2);\r\n dp = tmp;\r\n }\r\n return Math.min(...dp);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let l = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n if (a[0][min] === '*') l[min][1]++;\r\n if (a[1][min] === '*') l[min][0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n var _l;\r\n const tmp = ((_l = l[i - 1]) !== null && _l !== void 0 ? _l : [0, 0]).map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n l[i][0] = Math.min(tmp[0], tmp[1] + 1, l[i - 1][1] + 2);\r\n l[i][1] = Math.min(tmp[1], tmp[0] + 1, l[i - 1][0] + 2);\r\n }\r\n let r = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n if (a[0][max] === '*') r[max][1]++;\r\n if (a[1][max] === '*') r[max][0]++;\r\n for (let i = max - 1; i >= min; i--) {\r\n var _r;\r\n const tmp = ((_r = r[i + 1]) !== null && _r !== void 0 ? _r : [0, 0]).map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n r[i][0] = Math.min(tmp[0], tmp[1] + 1, r[i + 1][1] + 2);\r\n r[i][1] = Math.min(tmp[1], tmp[0] + 1, r[i + 1][0] + 2);\r\n }\r\n let res = Infinity;\r\n for (let i = min; i <= max; i++) {\r\n if (i < max) res = Math.min(res, l[i][0] + r[i + 1][0] + 1, l[i][1] + r[i + 1][1] + 1);else res = Math.min(res, l[i][0], l[i][1]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let S = [];\n S.push(readline())\n S.push(readline())\n LT('\\n'+ S.join('\\n'));\n // PROCESSING:\n let ans = 0;\n let l = 0;\n let r = n-1;\n let toNum = (pos)=>{\n if (S[0][pos]=='.' && S[1][pos]=='.')\n return 0;\n if (S[0][pos]=='*' && S[1][pos]=='*')\n return 3;\n if (S[0][pos]=='*')\n return 1;\n if (S[1][pos]=='*')\n return 2;\n }\n while (toNum(l)==0)\n l++;\n while (toNum(r)==0)\n r--;\n let lstate = toNum(l);\n if (lstate==3){\n ans++;\n }\n l++;\n while (l<=r){\n ans++;\n let nextL = toNum(l);\n if (nextL==0){\n l++;\n continue;\n }\n if (nextL==3){\n ans++;\n lstate = 3;\n l++;\n continue;\n }\n if (nextL==lstate || lstate==3){\n l++;\n lstate = nextL;\n continue;\n }\n ans++;\n l++;\n lstate = 3;\n }\n return ans;\n};\n "}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const grid = lines.slice(l, l + 2).map(str => str.trim())\r\n l += 2\r\n output[i] = solve(n, grid)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, grid) {\r\n const p0 = Array(n)\r\n const p1 = Array(n)\r\n for (let i = 0; i < n; i++) {\r\n let now\r\n now = grid[0][i] === '*' ? 1 : 0\r\n p0[i] = i ? p0[i - 1] + now : now\r\n now = grid[1][i] === '*' ? 1 : 0\r\n p1[i] = i ? p1[i - 1] + now : now\r\n }\r\n const pre = []\r\n const suf = []\r\n for (let i = 0; i < n; i++) {\r\n pre[i] = []\r\n for (let j = 0; j < 2; j++) {\r\n if (i) {\r\n pre[i][j] = Math.min(\r\n ((ok(grid, pre, i - 1, j) || grid[1 - j][i - 1] === '*') ? 1 : 0)\r\n + pre[i - 1][j]\r\n + (grid[1 - j][i - 1] === '*' ? 1 : 0),\r\n ok(grid, pre, i - 1, 1 - j) ? pre[i - 1][1 - j] + 2 : (grid[j][i - 1] === '*' ? 1 : 0)\r\n )\r\n } else {\r\n pre[i][j] = 0\r\n }\r\n }\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n suf[i] = []\r\n for (let j = 0; j < 2; j++) {\r\n if (i < n - 1) {\r\n suf[i][j] = Math.min(\r\n ((ok(grid, suf, i + 1, j) || grid[1 - j][i + 1] === '*') ? 1 : 0)\r\n + suf[i + 1][j]\r\n + (grid[1 - j][i + 1] === '*' ? 1 : 0),\r\n ok(grid, suf, i + 1, 1 - j) ? suf[i + 1][1 - j] + 2 : (grid[j][i + 1] === '*' ? 1 : 0)\r\n )\r\n } else {\r\n suf[i][j] = 0\r\n }\r\n }\r\n }\r\n let ans = Infinity\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < 2; j++) {\r\n ans = Math.min(\r\n ans,\r\n get(n, pre, i, j) + get(n, suf, i, j) + (grid[1 - j][i] === '*' ? 1 : 0),\r\n get(n, pre, i, 1 - j) + get(n, suf, i, 1 - j) + 1,\r\n )\r\n }\r\n }\r\n // console.log(pre, suf)\r\n return ans\r\n}\r\nfunction ok(grid, dp, i, j) {\r\n return dp[i][j] > 0 || grid[j][i] === '*'\r\n}\r\nfunction get(n, dp, i, j) {\r\n if (i < 0 || i >= n) return 0\r\n return dp[i][j]\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nconst calc = ()=>{\n /* read */\n let n = +readline();\n let s0 = readline();\n let s1 = readline();\n\n let count = 0;\n let result = 0;\n\n for (let i = 0; i < n; i++) {\n if (s0[i] === '*') count++;\n if (s1[i] === '*') count++;\n }\n\n if (count === 1) return 0;\n\n let prev = -1;\n\n for (let i = 0; i < n; i++) {\n if (count === 1) return result;\n if (prev !== -1) {\n result++;\n if (s0[i] === '*' && s1[i] === '*') {\n result++;\n count -= 2;\n prev = 2;\n } else {\n if (s0[i] === '*' && prev === 1) {\n result++;\n count--;\n prev = 2;\n } else if (s1[i] === '*' && prev === 0) {\n result++;\n count--;\n prev = 2;\n } else if (s0[i] === '*' && prev === 0) {\n count--;\n } else if (s1[i] === '*' && prev === 1) {\n count--;\n } else if (s0[i] === '*' && prev === 2) {\n count--;\n prev = 0;\n } else if (s1[i] === '*' && prev === 2) {\n count--;\n prev = 1;\n }\n }\n } else {\n if (s0[i] === '*' && s1[i] === '*') {\n result++;\n count--;\n prev = 2;\n } else {\n if (s0[i] === '*') {\n prev = 0;\n }\n if (s1[i] === '*') {\n prev = 1;\n }\n }\n }\n // console.log(`DEBUG result ${result} count ${count} prev`, prev);\n }\n\n return count === 1 ? result : result + 1;\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var n = +readline();\r\n var a = Array(2);\r\n a[0] = readline();\r\n a[1] = readline();\r\n var l0 = a[0].indexOf('*');\r\n var r0 = a[0].lastIndexOf('*');\r\n var l1 = a[1].indexOf('*');\r\n var r1 = a[1].lastIndexOf('*');\r\n if (l0 === -1)\r\n l0 = l1;\r\n if (l1 === -1)\r\n l1 = l0;\r\n var ans = 0;\r\n var cur = l0 < l1 ? 1 : l0 === l1 ? 2 : 0;\r\n for (var i = Math.min(l0, l1); i <= Math.max(r0, r1); i++) {\r\n if (a[0][i] === '*' && a[1][i] === '*') {\r\n ans++;\r\n cur = 2;\r\n }\r\n else if (a[0][i] === '*') {\r\n if (cur === 0) {\r\n ans++;\r\n cur = 2;\r\n }\r\n else\r\n cur = 1;\r\n }\r\n else if (a[1][i] === '*') {\r\n if (cur === 1) {\r\n ans++;\r\n cur = 2;\r\n }\r\n else\r\n cur = 0;\r\n }\r\n ans++;\r\n }\r\n print(ans - 1);\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let l = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n if (a[0][min] === '*') l[min][1]++;\r\n if (a[1][min] === '*') l[min][0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n var _l;\r\n const tmp = ((_l = l[i - 1]) !== null && _l !== void 0 ? _l : [0, 0]).map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n l[i][0] = Math.min(tmp[0], tmp[1] + 1);\r\n l[i][1] = Math.min(tmp[1], tmp[0] + 1);\r\n }\r\n let r = Array.from({\r\n length: n\r\n }, () => [0, 0]);\r\n if (a[0][max] === '*') r[max][1]++;\r\n if (a[1][max] === '*') r[max][0]++;\r\n for (let i = max - 1; i >= min; i--) {\r\n var _r;\r\n const tmp = ((_r = r[i + 1]) !== null && _r !== void 0 ? _r : [0, 0]).map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n r[i][0] = Math.min(tmp[0], tmp[1] + 1);\r\n r[i][1] = Math.min(tmp[1], tmp[0] + 1);\r\n }\r\n let res = Infinity;\r\n for (let i = min; i <= max; i++) {\r\n if (i < max) res = Math.min(res, l[i][0] + r[i + 1][0] + 1, l[i][1] + r[i + 1][1] + 1);else res = Math.min(res, l[i][0], l[i][1]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let dp = [0, 0];\r\n if (a[0][min] === '*') dp[1]++;\r\n if (a[1][min] === '*') dp[0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n const tmp = dp.map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n dp[0] = Math.min(tmp[0], tmp[1] + 1);\r\n dp[1] = Math.min(tmp[1], tmp[0] + 1);\r\n }\r\n let res = Math.min(...dp);\r\n {\r\n let dp = [0, 0];\r\n if (a[0][max] === '*') dp[1]++;\r\n if (a[1][max] === '*') dp[0]++;\r\n for (let i = max - 1; i >= min; i--) {\r\n const tmp = dp.map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n dp[0] = Math.min(tmp[0], tmp[1] + 1);\r\n dp[1] = Math.min(tmp[1], tmp[0] + 1);\r\n }\r\n res = Math.min(res, ...dp);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let min = -1,\r\n max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[0][i] === '*' || a[1][i] === '*') {\r\n if (min === -1) min = i;\r\n max = i;\r\n }\r\n }\r\n if (min === max) {\r\n if (a[0][min] === '*' && a[1][min] === '*') return 1;\r\n return 0;\r\n }\r\n let dp = [0, 0];\r\n if (a[0][min] === '*') dp[1]++;\r\n if (a[1][min] === '*') dp[0]++;\r\n for (let i = min + 1; i <= max; i++) {\r\n const tmp = dp.map(num => num + 1);\r\n if (a[0][i] === '*') tmp[1]++;\r\n if (a[1][i] === '*') tmp[0]++;\r\n dp[0] = Math.min(tmp[0], tmp[1] + 1);\r\n dp[1] = Math.min(tmp[1], tmp[0] + 1);\r\n }\r\n return Math.min(...dp);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let S = [];\n S.push(readline())\n S.push(readline())\n LT('\\n'+ S.join('\\n'));\n // PROCESSING:\n let ans = 0;\n let l = 0;\n let r = n-1;\n let toNum = (pos)=>{\n if (S[0][pos]=='.' && S[1][pos]=='.')\n return 0;\n if (S[0][pos]=='*' && S[1][pos]=='*')\n return 3;\n if (S[0][pos]=='*')\n return 1;\n if (S[1][pos]=='*')\n return 2;\n }\n while (toNum(l)==0)\n l++;\n while (toNum(r)==0)\n r--;\n let lstate = toNum(l), rstate = toNum(r);\n if (l==r)\n return toNum(l)==3 ? 1 : 0;\n while (l{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let S = [];\n S.push(readline())\n S.push(readline())\n LT('\\n'+ S.join('\\n'));\n // PROCESSING:\n let ans = 0;\n let l = 0;\n let r = n-1;\n let toNum = (pos)=>{\n if (S[0][pos]=='.' && S[1][pos]=='.')\n return 0;\n if (S[0][pos]=='*' && S[1][pos]=='*')\n return 3;\n if (S[0][pos]=='*')\n return 1;\n if (S[1][pos]=='*')\n return 2;\n }\n while (toNum(l)==0)\n l++;\n while (toNum(r)==0)\n r--;\n let lstate = toNum(l), rstate = toNum(r);\n if (l==r)\n return toNum(l)==3 ? 1 : 0;\n while (l {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const grid = lines.slice(l, l + 2).map(str => str.trim())\n l += 2\n output[i] = solve(n, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, grid) {\n const p0 = Array(n)\n const p1 = Array(n)\n for (let i = 0; i < n; i++) {\n let now\n now = grid[0][i] === '*' ? 1 : 0\n p0[i] = i ? p0[i - 1] + now : now\n now = grid[1][i] === '*' ? 1 : 0\n p1[i] = i ? p1[i - 1] + now : now\n }\n const pre = []\n const suf = []\n for (let i = 0; i < n; i++) {\n pre[i] = []\n for (let j = 0; j < 2; j++) {\n if (i) {\n pre[i][j] = Math.min(\n pre[i - 1][j] + 1 + (grid[1 - j][i - 1] === '*' ? 1 : 0),\n pre[i - 1][1 - j] + 2\n )\n } else {\n pre[i][j] = 0\n }\n }\n }\n for (let i = n - 1; i >= 0; i--) {\n suf[i] = []\n for (let j = 0; j < 2; j++) {\n if (i < n - 1) {\n suf[i][j] = Math.min(\n suf[i + 1][j] + 1 + (grid[1 - j][i + 1] === '*' ? 1 : 0),\n suf[i + 1][1 - j] + 2\n )\n } else {\n suf[i][j] = 0\n }\n }\n }\n let ans = Infinity\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < 2; j++) {\n ans = Math.min(\n ans,\n get(n, pre, i, j) + get(n, suf, i, j) + (grid[1 - j][i] === '*' ? 1 : 0),\n get(n, pre, i, 1 - j) + get(n, suf, i, 1 - j) + 1,\n )\n }\n }\n // console.log(pre, suf)\n return ans\n}\nfunction get(n, dp, i, j) {\n if (i < 0 || i >= n) return 0\n return dp[i][j]\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nconst calc = ()=>{\n /* read */\n let n = +readline();\n let s0 = readline();\n let s1 = readline();\n\n let count = 0;\n let result = 0;\n\n for (let i = 0; i < n; i++) {\n if (s0[i] === '*') count++;\n if (s1[i] === '*') count++;\n }\n\n if (count === 1) return 0;\n\n let prev = -1;\n\n for (let i = 0; i < n; i++) {\n if (count === 1) return result;\n if (prev !== -1) {\n result++;\n if (s0[i] === '*' && s1[i] === '*') {\n result++;\n count -= 2;\n prev = 2;\n } else {\n if (s0[i] === '*' && prev === 1) {\n result++;\n count--;\n prev = 2;\n }\n if (s1[i] === '*' && prev === 0) {\n result++;\n count--;\n prev = 2;\n }\n if (s0[i] === '*' && prev === 0) {\n count--;\n }\n if (s1[i] === '*' && prev === 1) {\n count--;\n }\n }\n } else {\n if (s0[i] === '*' && s1[i] === '*') {\n result++;\n count--;\n prev = 2;\n } else {\n if (s0[i] === '*') {\n prev = 0;\n }\n if (s1[i] === '*') {\n prev = 1;\n }\n }\n }\n \n }\n\n return result;\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var n = +readline();\r\n var a = Array(2);\r\n a[0] = readline();\r\n a[1] = readline();\r\n var l0 = a[0].indexOf('*');\r\n var r0 = a[0].lastIndexOf('*');\r\n var l1 = a[1].indexOf('*');\r\n var r1 = a[1].lastIndexOf('*');\r\n if (l0 === -1)\r\n l0 = l1;\r\n if (l1 === -1)\r\n l1 = l0;\r\n var ans = 0;\r\n var cur = l0 < l1 ? 1 : l0 === l1 ? 2 : 0;\r\n for (var i = Math.min(l0, l1); i <= Math.max(r0, r1); i++) {\r\n if (a[0][i] === '*' && a[1][i] === '*') {\r\n ans++;\r\n cur = 2;\r\n }\r\n else if (a[0][i] === '*') {\r\n if (cur === 0) {\r\n ans++;\r\n cur = 2;\r\n }\r\n }\r\n else if (a[1][i] === '*') {\r\n if (cur === 1) {\r\n ans++;\r\n cur = 2;\r\n }\r\n }\r\n ans++;\r\n }\r\n print(ans - 1);\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var n = +readline();\r\n var a = Array(2);\r\n a[0] = readline();\r\n a[1] = readline();\r\n var l0 = a[0].indexOf('*');\r\n var r0 = a[0].lastIndexOf('*');\r\n var l1 = a[1].indexOf('*');\r\n var r1 = a[1].lastIndexOf('*');\r\n if (l0 === -1)\r\n l0 = l1;\r\n if (l1 === -1)\r\n l1 = l0;\r\n var ans = 0;\r\n var cur = 2;\r\n for (var i = Math.min(l0, l1); i < Math.max(r0, r1); i++) {\r\n if (a[0][i] === '*' && a[1][i] === '*') {\r\n ans++;\r\n cur = 2;\r\n }\r\n else if (a[0][i] === '*') {\r\n if (cur === 0)\r\n ans++;\r\n cur = 1;\r\n }\r\n else if (a[1][i] === '*') {\r\n if (cur === 1)\r\n ans++;\r\n cur = 0;\r\n }\r\n ans++;\r\n }\r\n if (r0 === r1) {\r\n ans++;\r\n }\r\n print(ans);\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var n = +readline();\r\n var a = Array(3);\r\n a[1] = readline();\r\n a[2] = readline();\r\n var l1 = a[1].indexOf('*');\r\n var r1 = a[1].lastIndexOf('*');\r\n var l2 = a[2].indexOf('*');\r\n var r2 = a[2].lastIndexOf('*');\r\n if (l1 === -1) {\r\n print(r2 - l2);\r\n continue;\r\n }\r\n if (l2 === -1) {\r\n print(r1 - l1);\r\n continue;\r\n }\r\n var ans = 0;\r\n if (r1 >= l2 && r2 >= l1) {\r\n ans = (r1 - l1) + (r2 - l2) + 1;\r\n }\r\n else {\r\n ans = Math.max(r1, r2) - Math.min(l1, l2) + 1;\r\n }\r\n print(ans);\r\n}\r\n"}], "src_uid": "2724bff6614e8cc02c07924771bd2920"} {"source_code": "nk = readline().split(\" \").map(Number)\nn = nk[0]\nk = nk[1]\na=readline().split(\" \").map(Number)\n\nst=1\nend=1000000000\nwhile (st<=end) {\n mid=(st+end)>>1\n ct=0;i=1;pos=n\n if (k%2!==0) pos-=1\n while (i=k>>1) {\n end=mid-1\n continue;\n }\n ct=0;i=0;pos=n\n if (k%2===0) pos-=1\n while (i=(k+1)>>1) {\n end=mid-1\n continue;\n }\n st=mid+1\n}\nprint (end+1)", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var _a = lineToNumArray(lines.shift()), n = _a[0], k = _a[1];\n var arr = lineToNumArray(lines.shift());\n console.log(Math.min(binarySearch(n, k, arr, 0), binarySearch(n, k, arr, 1)));\n});\nfunction binarySearch(n, k, arr, parity) {\n var lo = 1, hi = Math.max.apply(Math, arr);\n var ans;\n while (lo <= hi) {\n var mid = Math.floor((lo + hi) / 2);\n var count = 0;\n for (var i = 0; i < n && count < k; i++) {\n if (count % 2 === parity) {\n count += Number(arr[i] <= mid);\n }\n else {\n count++;\n }\n }\n if (count === k) {\n ans = mid;\n hi = mid - 1;\n }\n else {\n lo = mid + 1;\n }\n }\n return ans;\n}\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n const [n, k] = lineToNumArray(lines.shift());\n const arr = lineToNumArray(lines.shift());\n console.log(Math.min(binarySearch(n, k, arr, 0), binarySearch(n, k, arr, 1)));\n});\nfunction binarySearch(n, k, arr, parity) {\n let lo = 1, hi = Math.max(...arr);\n let ans;\n while (lo <= hi) {\n const mid = Math.floor((lo + hi) / 2);\n let count = 0;\n for (let i = 0; i < n && count < k; i++) {\n if (count % 2 === parity) {\n count += Number(arr[i] <= mid);\n }\n else {\n count++;\n }\n }\n if (count === k) {\n ans = mid;\n hi = mid - 1;\n }\n else {\n lo = mid + 1;\n }\n }\n return ans;\n}\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(element => parseInt(element, 10));\n}\n"}], "negative_code": [{"source_code": "nk = readline().split(\" \").map(Number);\nn = nk[0];\nk = nk[1];\na=readline().split(\" \").map(Number);\n\nst=1\nend=100000000\nwhile (st<=end) {\n mid=(st+end)>>1\n ct=0;i=1;pos=n\n if (k%2!==0) pos-=1\n while (i=k/2) {\n end=mid-1\n continue;\n }\n ct=0;i=0;pos=n\n if (k%2===0) pos-=1\n while (i=(k+1)/2) {\n end=mid-1\n continue;\n }\n st=mid+1\n}\nprint (end+1)"}, {"source_code": "nk = readline().split(\" \").map(Number)\nn = nk[0]\nk = nk[1]\na=readline().split(\" \").map(Number)\n\nst=1\nend=1000000000\nwhile (st<=end) {\n mid=(st+end)>>1\n ct=0;i=1;pos=n\n if (k%2!==0) pos-=1\n while (i=k/2) {\n end=mid-1\n continue;\n }\n ct=0;i=0;pos=n\n if (k%2===0) pos-=1\n while (i=(k+1)>>1) {\n end=mid-1\n continue;\n }\n st=mid+1\n}\nprint (end+1)"}], "src_uid": "d55ed15b600477e292406bef0b2d3b49"} {"source_code": "var n=parseInt(readline())\nvar a=readline().split(\" \").map(x=>parseInt(x))\nvar s=new Set()\ns.add(0)\nvar chk=0\nvar cnt=1;\nfor(x of a){\n if(s.has(x) || s.has(x-1)){\n cnt+=1;\n s.add(x);\n }\n else{\n chk=1;\n break;\n }\n}\nif (a[0]!=0) print(1)\nelse if (chk==0) print(-1)\nelse print(cnt)", "positive_code": [{"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n let max = 0;\n for (let i = 0; i < length; i++) {\n if (result[i] > max) {\n return i + 1;\n }\n if ( max == result[i] )\n max += 1;\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "var m = readline(),\n arr = readline().split(' '),\n flag = 1,\n max = -1;\nfor(var i = 0; i < m; i++) {\n var newMax = Math.max(max, arr[i]);\n if(newMax - max > 1) {\n write(i + 1);\n flag = 0;\n break;\n }\n max = newMax;\n}\nif(flag) {\n write(-1);\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] >= i+1 ) {\n console.log(result[i]);\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] > i || result[i] > result[i-1] + 1) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] > i+1 ) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] >= i+1 ) {\n if ( i > 4000) {\n console.log(result[i]);\n }\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] >= i+2 ) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n let naj = 0;\n for (let i = 0; i < length; i++) {\n if (result[i] > naj ) {\n return i + 1;\n }\n naj = Math.max(naj, result[i] + 1);\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.trim();\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if ( i == 42230 || i == 42231 ) {\n console.log(result[i]);\n }\n if (result[i] >= i+1 ) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n let max = 0;\n for (let i = 0; i < length; i++) {\n if (result[i] > max) {\n return i + 1;\n }\n max = Math.max(max, result[i] + 1);\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] > i && result[i] > result[i-1] + 1) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst appnedMex = (length, result) => {\n for (let i = 0; i < length; i++) {\n if (result[i] >= i+1 ) {\n return i + 1;\n }\n }\n return -1;\n}\n\nlet length, result;\n\nrl.on('line', (line) => {\n if (!length) {\n length = line;\n } else {\n result = line.split(' ');\n console.log(appnedMex(length, result));\n rl.close();\n process.exit();\n }\n});\n"}, {"source_code": "var n=parseInt(readline())\nvar a=readline().split(\" \").map(x=>parseInt(x))\nvar s=new Set()\ns.add(0)\nvar chk=0\nvar cnt=1;\nfor(x of a){\n if(s.has(x) || s.has(x-1)){\n cnt+=1;\n }\n else{\n chk=1;\n break;\n }\n}\nif (a[0]!=0) print(1)\nelse if (chk==0) print(-1)\nelse print(cnt+1)"}, {"source_code": "var m = readline(),\n arr = readline().split(' '),\n flag = 1;\nfor(var i = 0; i < m; i++) {\n if(arr[i] > i) {\n write(i + 1);\n flag = 0;\n break;\n }\n}\nif(flag) {\n write(-1);\n}"}], "src_uid": "e17427897fd5147c601204cb1c48b143"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read();\r\n const n = s.length;\r\n const map = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _map$get;\r\n if (!map.has(s[i])) map.set(s[i], []);\r\n (_map$get = map.get(s[i])) === null || _map$get === void 0 ? void 0 : _map$get.push(i);\r\n }\r\n let flag = 1;\r\n if (s[0] > s[n - 1]) {\r\n flag = -1;\r\n }\r\n let res = [],\r\n d = 0,\r\n p = s.charCodeAt(0);\r\n for (let i = p; flag > 0 ? i <= s.charCodeAt(n - 1) : i >= s.charCodeAt(n - 1); i += flag) {\r\n const ch = String.fromCharCode(i);\r\n if (map.has(ch)) {\r\n d += Math.abs(i - p);\r\n p = i;\r\n for (let j of map.get(ch)) {\r\n res.push(j);\r\n }\r\n }\r\n }\r\n return `${d} ${res.length}\\n${res.map(num => num + 1).join(' ')}`;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let a = str[0]\n let b = str[str.length - 1]\n let f = 0\n if (a > b) {\n [a, b] = [b, a]\n f = 1\n }\n const r = []\n for (let i = 1; i < str.length - 1; i++) {\n if (str[i] >= a && str[i] <= b) {\n r.push(i + 1)\n }\n }\n r.sort((p, q) => str.charCodeAt(p - 1) - str.charCodeAt(q - 1))\n if (f) r.reverse()\n r.unshift(1)\n r.push(str.length)\n const cost = b.charCodeAt(0) - a.charCodeAt(0)\n return cost + ' ' + r.length + '\\n' + r.join(' ')\n}\n"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i { return a-b })\n\n var mode = 1\n if (head>tail) mode = 2\n\n var max_step = 0\n var ret = []\n //for (var k=0; k= Math.min(head, tail) && k <= Math.max(head, tail)) {\n \n max_step = max_step + pos[k].length\n\n //var kk = pos[nums[k]].shift()\n //if (kk > 1 && kk < nums.length) ret.push(kk)\n ret = ret.concat(pos[k])\n }\n }\n\n if (mode == 2) {\n ret = ret.reverse()\n }\n max_step = max_step + 2\n print(min_cost + \" \" +max_step)\n ret.unshift(1)\n //ret.push(nums.length)\n ret.push(nums.length+2)\n print(ret.join(\" \"))\n \n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read();\r\n const n = s.length;\r\n const map = new Map();\r\n for (let i = 0; i < n; i++) {\r\n var _map$get;\r\n if (!map.has(s[i])) map.set(s[i], []);\r\n (_map$get = map.get(s[i])) === null || _map$get === void 0 ? void 0 : _map$get.push(i);\r\n }\r\n let flag = 1;\r\n if (s[0] > s[n - 1]) {\r\n flag = -1;\r\n }\r\n let res = [],\r\n d = 0,\r\n p = s.charCodeAt(0);\r\n for (let i = p; flag > 0 ? i <= s.charCodeAt(n - 1) : i >= s.charCodeAt(n - 1); i += flag) {\r\n const ch = String.fromCharCode(i);\r\n if (map.has(ch)) {\r\n d += Math.abs(i - p);\r\n p = i;\r\n for (let j of map.get(ch)) {\r\n res.push(j);\r\n }\r\n }\r\n }\r\n return `${d} ${res.length}\\n${res.map(num => num + 1).join(' ')}`;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let a = str[0]\n let b = str[str.length - 1]\n if (a > b) {\n [a, b] = [b, a]\n }\n const r = []\n for (let i = 1; i < str.length - 1; i++) {\n if (str[i] >= a && str[i] <= b) {\n r.push(i + 1)\n }\n }\n r.sort((p, q) => str.charCodeAt(p - 1) - str.charCodeAt(q - 1))\n r.unshift(1)\n r.push(str.length)\n const cost = b.charCodeAt(0) - a.charCodeAt(0)\n return cost + ' ' + r.length + '\\n' + r.join(' ')\n}\n"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i { return a-b })\n\n var mode = 1\n if (head>tail) mode = 2\n\n var max_step = 0\n var ret = []\n //for (var k=0; k= Math.min(head, tail) && k <= Math.max(head, tail)) {\n \n max_step++\n\n //var kk = pos[nums[k]].shift()\n //if (kk > 1 && kk < nums.length) ret.push(kk)\n ret = ret.concat(pos[k])\n }\n }\n\n if (mode == 2) {\n ret = ret.reverse()\n }\n max_step = max_step + 2\n print(min_cost + \" \" +max_step)\n ret.unshift(1)\n //ret.push(nums.length)\n ret.push(nums.length+2)\n print(ret.join(\" \"))\n \n}"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i { return a-b })\n\n var mode = 1\n if (head>tail) mode = 2\n\n var max_step = 0\n var ret = []\n for (var k=0; k= Math.min(head, tail) && nums[k] <= Math.max(head, tail)) {\n \n max_step++\n\n //var kk = pos[nums[k]].shift()\n //if (kk > 1 && kk < nums.length) ret.push(kk)\n ret = ret.concat(pos[nums[k]])\n }\n }\n\n if (mode == 2) {\n ret = ret.reverse()\n }\n max_step = max_step + 2\n print(min_cost + \" \" +max_step)\n ret.unshift(1)\n //ret.push(nums.length)\n ret.push(nums.length+2)\n print(ret.join(\" \"))\n \n}"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i { return a-b })\n //print(head)\n //print(tail)\n \n var mode = 1\n if (head>tail) mode = 2\n\n var max_step = 0\n var ret = []\n for (var k=0; k= Math.min(head, tail) && nums[k] <= Math.max(head, tail)) {\n \n max_step++\n //print(\"max_step=\"+max_step )\n\n //print(\"seq = \" + pos[nums[k]].shift())\n ret.push(pos[nums[k]].shift())\n }\n }\n\n //reverse ret\n if (mode == 2) {\n ret = ret.reverse()\n }\n\n\n \n //print (\"min=\" + min_cost)\n //print (\"max=\" + max_step)\n //print (\"ret = \"+ ret)\n \n print(min_cost + \" \" + max_step)\n print(ret.join(\" \"))\n}"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i { return b-a })\n print (nums)\n //print(\"answer\")\n}"}], "src_uid": "d17c9f91504e1d4c4eae7294bf09dcfc"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k) {\r\n const dp = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(Infinity));\r\n dp[0][0] = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (i === 0 && j === 0) continue;\r\n if (i > 0) dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + j + 1);\r\n if (j > 0) dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + i + 1);\r\n }\r\n }\r\n return dp[n - 1][m - 1] === k ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, k);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": " var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var inputs = readline().split(' '),\r\n n = inputs[0],\r\n m = inputs[1],\r\n k = inputs[2] ;\r\n if((n*m) - 1 == k){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n\r\n }"}, {"source_code": "(function () {\r\n const count = readline();\r\n const n = Number(count);\r\n\r\n var i;\r\n for (i = 0; i < n; i++) {\r\n var line = readline();\r\n var items = line.split(' ');\r\n var x = Number(items[0]) - 1;\r\n var y = Number(items[1]) - 1;\r\n var j;\r\n var k;\r\n var c = 0;\r\n var result = 'No';\r\n for (j = 1; j <= x; j++) {\r\n c += 1;\r\n }\r\n for (k = 1; k <= y; k++) {\r\n c += Number(items[0]);\r\n }\r\n if (c === Number(items[2])) {\r\n result = 'Yes';\r\n }\r\n\r\n print(result);\r\n }\r\n})();"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n const length = Number(readline());\r\n for (let i = 0; i < length; i++) {\r\n const [x, y, budget] = readline().split(' ').map(e => Number(e));\r\n if(x * y - 1 === budget) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n return;\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k) {\r\n let res = 0;\r\n for (let i = 1; i < n; i++) res += 1;\r\n for (let i = 1; i < m; i++) res += n;\r\n return res === k ? 'YES' : 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, k);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n;// CONCATENATED MODULE: ./src/io.js\nvar interact = function interact(main) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var inputString = '';\n var currentLine = 0;\n\n var readline = function readline() {\n return inputString[currentLine++];\n };\n\n var print = function print() {\n for (var _len = arguments.length, any = new Array(_len), _key = 0; _key < _len; _key++) {\n any[_key] = arguments[_key];\n }\n\n process.stdout.write(any.join(' '));\n };\n\n var println = function println() {\n for (var _len2 = arguments.length, any = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n any[_key2] = arguments[_key2];\n }\n\n any.length > 0 && print(any);\n print('\\n');\n };\n\n var obj = {\n print: print,\n println: println,\n readline: readline\n };\n process.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n });\n process.stdin.on('end', function () {\n inputString = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main(obj);\n });\n};\n\n/* harmony default export */ const io = (interact);\n;// CONCATENATED MODULE: ./src/index.js\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\n\n\nvar main = function main(io) {\n var tc = parseInt(io.readline());\n\n var _loop = function _loop() {\n var _io$readline$split$ma = io.readline().split(' ').map(function (x) {\n return parseInt(x);\n }),\n _io$readline$split$ma2 = _slicedToArray(_io$readline$split$ma, 3),\n n = _io$readline$split$ma2[0],\n m = _io$readline$split$ma2[1],\n k = _io$readline$split$ma2[2];\n\n var dp = Array.from(Array(1 + n), function () {\n return Array.from(Array(1 + m), function () {\n return Infinity;\n });\n }); // from (1,1) it is possible to use exactly\n // 0 burles to reach (1,1)\n\n dp[1][1] = 0;\n\n for (var i = 1; i <= n; i++) {\n for (var j = 1; j <= m; j++) {\n dp[i][j] = Math.min(dp[i][j], j + dp[i - 1][j], i + dp[i][j - 1]);\n }\n }\n\n io.println(dp[n][m] === k ? 'YES' : 'NO');\n };\n\n while (tc--) {\n _loop();\n }\n};\n\nio(main);\n/******/ })()\n;"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n if(c == a * b - 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n if(c == a * b - 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [n, m, k] = nl.nums();\n\t\tans.push((n * m - 1) === k);\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tif(H * W - 1 == K){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n \r\n while(testCases--)\r\n {\r\n let [n,m,k] = get_ints();\r\n let [x,y] = [1,1];\r\n let burles = 0;\r\n while(x < n)\r\n {\r\n burles += y;\r\n x++;\r\n }\r\n while(y < m)\r\n {\r\n burles += x;\r\n y++;\r\n }\r\n burles === k ? print('YES') : print('NO');\r\n }\r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, m, k]) {\r\n let a = n - 1 + (n * (m - 1));\r\n (a === k) ? console.log('YES') : console.log('NO')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-b.ts\n\nconst io = new IO();\n\nfunction solve(n, m, k) {\n let s = n - 1 + (m - 1) * n;\n\n if (k === s) {\n io.writeLine('YES');\n } else {\n io.writeLine('NO');\n }\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let m = io.nextNum();\n let k = io.nextNum();\n solve(n, m, k);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}], "negative_code": [], "src_uid": "8b0a9c7e997034d3ecce044b9f64aeba"} {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 1; i < input.length; i++) {\r\n let [rows, cols] = input[i].split(' ').map(Number);\r\n \r\n let grid = input.slice(i+1, i+rows+1).map(v=>v.split(''));\r\n \r\n for (let col = 0; col < cols; col++) {\r\n for (let row = rows-2; row >= 0; row--) {\r\n if (grid[row][col] === '*') {\r\n while (grid[row+1][col] === '.') {\r\n [grid[row][col], grid[row+1][col]] = [grid[row+1][col], grid[row][col]];\r\n if (row+1 < rows-1) row++;\r\n }\r\n }\r\n }\r\n }\r\n ans.push(grid.map(v=>v.join('')).join('\\n'));\r\n \r\n i+=rows;\r\n }\r\n console.log(ans.join('\\n'));\r\n});", "positive_code": [{"source_code": "'use strict';\n\nconst { domainToASCII } = require('url');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst to_s = (i, j)=>i*1000+j;\nconst calc = (n, m, G)=>{\n let iterate = ()=>{\n let NG = [];\n let flag;\n let dots = new Set();\n for (let i=n-1; i>=0; i--){\n let s = '';\n for (let j=0; j0 && G[i-1][j]=='*'){\n dots.add(to_s(i-1, j));\n flag = true;\n s += '*';\n } else {\n s += dots.has(to_s(i, j)) ? '.' : G[i][j];\n }\n }\n NG.push(s);\n }\n //L('\\nstart:'); L(NG.join('\\n')); L('\\nend:');\n G = NG.reverse();\n return flag\n };\n while (iterate());\n return G.join('\\n');\n L({n, m, G})\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, m] = ra();\n let G = [];\n for (let i=0; i {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(readline().trim().split(\"\"));\r\n }\r\n for (let i = 0; i < m; i++) {\r\n let s = 0,\r\n j;\r\n for (j = 0; j < n; j++) {\r\n if (arr[j][i] === \"*\") {\r\n s++;\r\n arr[j][i] = \".\";\r\n } else if (arr[j][i] === \"o\" && s != 0) {\r\n let k = j - 1;\r\n while (s--) arr[k--][i] = \"*\";\r\n s = 0;\r\n }\r\n }\r\n let k = j - 1;\r\n while (s--) arr[k--][i] = \"*\";\r\n }\r\n for (let i = 0; i < n; i++) console.log(arr[i].join(\"\"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let _t = parseInt(readline());\r\n let a = [];\r\n while (_t) {\r\n _t -= 1;\r\n let nm = readline()\r\n .split(' ')\r\n .map((e) => parseInt(e));\r\n\r\n let n = nm[0];\r\n let m = nm[1];\r\n for (let i = 0; i < n; i++) {\r\n a[i] = readline();\r\n }\r\n let d = [];\r\n for (let j = 0; j < m; j++) {\r\n d[j] = [];\r\n let cur = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i][j] === '*') cur++;\r\n if (a[i][j] === 'o') {\r\n d[j].push(cur);\r\n cur = 0;\r\n }\r\n }\r\n d[j].push(cur);\r\n }\r\n\r\n let b = [];\r\n for (let i = 0; i < n; i++) b[i] = [];\r\n\r\n for (let j = 0; j < m; j++) {\r\n let cur = d[j].pop();\r\n for (let i = n - 1; i >= 0; i--) {\r\n b[i][j] = a[i][j];\r\n if (a[i][j] === 'o') {\r\n cur = d[j].pop();\r\n continue;\r\n }\r\n if (a[i][j] === '*') b[i][j] = '.';\r\n if (cur) {\r\n cur--;\r\n b[i][j] = '*';\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n console.log(b[i].join(''));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst a = [];\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = rl().split('');\r\n\t\t}\r\n\r\n\t\tfor (let j = 0; j < m; j++) {\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i][j] == '*') {\r\n\t\t\t\t\tfor (let k = i + 1; k < n; k++) {\r\n\t\t\t\t\t\tif (a[k][j] == 'o') break;\r\n\t\t\t\t\t\tif (a[k][j] == '.') {\r\n\t\t\t\t\t\t\ta[k][j] = '*';\r\n\t\t\t\t\t\t\ta[i][j] = '.';\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconsole.log(a[i].join(''));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n // console.log(`DEBUG res`, res);\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, m, grid)=>{\n let result = new Array(n + 1).fill(0).map(() => new Array(m).fill('.'));\n for (let j = 0; j < m; j++) {\n result[n][j] = 'o';\n }\n grid.push(new Array(m).fill('o'));\n\n let stonesAbove = new Array(n + 1).fill(0).map(() => new Array(m).fill(0));\n\n for (let j = 0; j < m; j++) {\n let lasto = n;\n let count = 0;\n for (let i = n - 1; i >= 0; i--) {\n if (grid[i][j] === 'o') {\n stonesAbove[lasto][j] = count;\n count = 0;\n lasto = i;\n }\n if (grid[i][j] === '*') {\n count++;\n } \n }\n if (count > 0) {\n stonesAbove[lasto][j] = count;\n }\n }\n\n for (let j = 0; j < m; j++) {\n for (let i = n; i >= 0; i--) {\n if (grid[i][j] === 'o') result[i][j] = 'o';\n if (stonesAbove[i][j] > 0) {\n let count = stonesAbove[i][j];\n while(count--) {\n i--;\n result[i][j] = '*';\n }\n }\n }\n }\n\n result.pop();\n\n return result.map((s) => s.join('')).join('\\n');\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, m] = ra();\n let grid = [];\n for (let i = 0; i < n; i++) {\n grid.push(readline());\n }\n console.log(`${calc(n, m, grid)}`);\n }\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, a) {\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(m).fill('.'));\r\n const floors = new Array(m).fill(n - 1);\r\n for (let i = n - 1; i >= 0; i--) {\r\n for (let j = 0; j < m; j++) {\r\n if (a[i][j] === 'o') {\r\n res[i][j] = 'o';\r\n floors[j] = i - 1;\r\n } else if (a[i][j] === '*') {\r\n res[floors[j]][j] = '*';\r\n floors[j]--;\r\n }\r\n }\r\n }\r\n console.log(res.map(a => a.join('')).join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n let [n, m] = (await read()).split(' ').map(Number),\r\n a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n solve(n, m, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar map = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmap[i] = nextCharArray();\r\n\t\t}\r\n\t\tmap.push(new Array(M).fill(\"*\"));\r\n\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\tfor(var j = 0; j < M; j++){\r\n\t\t\t\tif(map[i][j] == \"*\"){\r\n\t\t\t\t\tfor(var k = i + 1; k <= N; k++){\r\n\t\t\t\t\t\tif(map[k][j] == \"o\" || map[k][j] == \"*\"){\r\n\t\t\t\t\t\t\tmap[i][j] = \".\";\r\n\t\t\t\t\t\t\tmap[k - 1][j] = \"*\";\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmyout(myconv(map[i], 0));\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, m, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n const ans = []\n for (let i = 0; i < n; i++) {\n ans[i] = []\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === 'o') {\n ans[i][j] = 'o'\n } else {\n ans[i][j] = '.'\n }\n }\n }\n for (let i = n - 1; i >= 0; i--) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === '*') {\n let k = i\n while (k + 1 < n && ans[k + 1][j] === '.') k++\n ans[k][j] = '*'\n }\n }\n }\n return ans.map(r => r.join('')).join('\\n')\n}\n"}], "negative_code": [], "src_uid": "964ce5983d0e9b1a3f460ad6e6078d47"} {"source_code": "let readline=require('readline');\nlet rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nlet arr=[],n;\nrl.on('line',function(inp){\n arr.push(inp);\n let len=arr.length;\n if(len===1) n=parseInt(arr[0]);\n else{\n let a=arr[1].split(' ');\n for(let i=0;i inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var n = +inputs[0];\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var minArr = arr.slice(0, n / 2 | 0);\n var maxArr = arr.slice(n / 2 | 0);\n var c = [];\n for (let i = 0; i < n; i++) {\n if (i % 2 == 0)\n c.push(maxArr[i / 2 | 0]);\n else\n c.push(minArr[i / 2 | 0]);\n }\n console.log(c.filter((v, i) => i > 0 && i < n - 1 && v < c[i - 1] && v < c[i + 1]).length);\n console.log(c.join(' '));\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(''));\n\n let isEvenEven = false;\n let isOddOdd = false;\n for(let i = 0; i < n; i++){\n if((i+1) % 2 === 0){\n if(!isEvenEven){\n isEvenEven = s[i] % 2 === 0;\n }\n }else{\n if(!isOddOdd){\n isOddOdd = s[i] % 2 !== 0;\n }\n }\n }\n\n if(n % 2 === 0){\n if(isEvenEven)\n console.log(2);\n else{\n console.log(1);\n }\n }else{\n if(isOddOdd)\n console.log(1);\n else{\n console.log(2);\n }\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let x = pi(readline());\n if(x === 0){\n console.log(0);\n continue;\n }\n\n if(t === 1000-182){\n console.log(x);\n break;\n }\n\n let count = 0;\n let y = 1;\n while(x > 0){\n let val = (y*(y+1)/2);\n x -= val;\n if(x >= 0)\n count += 1;\n y = 1 + (2*y);\n }\n\n console.log(count);\n }\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let ans = new Array(n);\n let p = 0;\n for(let i = 1; i < n; i+=2){\n ans[i] = a[p];\n p++;\n }\n\n for(let i = 0; i < n; i+=2){\n ans[i] = a[p];\n p++;\n }\n\n let count = 0;\n for(let i = 1; i < n; i+=2){\n if(i !== n-1){\n if(ans[i-1] > ans[i] && ans[i+1] > ans[i])\n count += 1;\n }\n }\n\n console.log(count);\n for(let i of ans)\n console.log(i);\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(''));\n\n let isEvenEven = false;\n let isOddOdd = false;\n for(let i = 0; i < n; i++){\n if((i+1) % 2 === 0){\n if(!isEvenEven){\n isEvenEven = s[i] % 2 === 0;\n }\n }else{\n if(!isOddOdd){\n isOddOdd = s[i] % 2 !== 0;\n }\n }\n }\n\n if(n % 2 === 0){\n if(isEvenEven)\n console.log(2);\n else{\n console.log(1);\n }\n }else{\n if(isOddOdd)\n console.log(1);\n else{\n console.log(2);\n }\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let x = pi(readline());\n if(x === 0){\n console.log(0);\n continue;\n }\n\n if(t === 1000-182){\n console.log(x);\n break;\n }\n\n let count = 0;\n let y = 1;\n while(x > 0){\n let val = (y*(y+1)/2);\n x -= val;\n if(x >= 0)\n count += 1;\n y = 1 + (2*y);\n }\n\n console.log(count);\n }\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let ans = new Array(n);\n let p = 0;\n let count = 0;\n for(let i = 1; i < n; i+=2){\n if(i !== n-1){\n count += 1;\n }\n ans[i] = a[p];\n p++;\n }\n\n for(let i = 0; i < n; i+=2){\n ans[i] = a[p];\n p++;\n }\n\n console.log(count);\n for(let i of ans)\n console.log(i);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(''));\n\n let isEvenEven = false;\n let isOddOdd = false;\n for(let i = 0; i < n; i++){\n if((i+1) % 2 === 0){\n if(!isEvenEven){\n isEvenEven = s[i] % 2 === 0;\n }\n }else{\n if(!isOddOdd){\n isOddOdd = s[i] % 2 !== 0;\n }\n }\n }\n\n if(n % 2 === 0){\n if(isEvenEven)\n console.log(2);\n else{\n console.log(1);\n }\n }else{\n if(isOddOdd)\n console.log(1);\n else{\n console.log(2);\n }\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let x = pi(readline());\n if(x === 0){\n console.log(0);\n continue;\n }\n\n if(t === 1000-182){\n console.log(x);\n break;\n }\n\n let count = 0;\n let y = 1;\n while(x > 0){\n let val = (y*(y+1)/2);\n x -= val;\n if(x >= 0)\n count += 1;\n y = 1 + (2*y);\n }\n\n console.log(count);\n }\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let ans = new Array(n);\n let p = 0;\n let count = 0;\n for(let i = 1; i < n; i+=2){\n if(i !== n-1){\n ans[i] = a[p];\n p++;\n count += 1;\n }\n }\n\n for(let i = 0; i < n; i+=2){\n ans[i] = a[p];\n p++;\n }\n\n console.log(count);\n for(let i of ans)\n console.log(i);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(''));\n\n let isEvenEven = false;\n let isOddOdd = false;\n for(let i = 0; i < n; i++){\n if((i+1) % 2 === 0){\n if(!isEvenEven){\n isEvenEven = s[i] % 2 === 0;\n }\n }else{\n if(!isOddOdd){\n isOddOdd = s[i] % 2 !== 0;\n }\n }\n }\n\n if(n % 2 === 0){\n if(isEvenEven)\n console.log(2);\n else{\n console.log(1);\n }\n }else{\n if(isOddOdd)\n console.log(1);\n else{\n console.log(2);\n }\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let x = pi(readline());\n if(x === 0){\n console.log(0);\n continue;\n }\n\n if(t === 1000-182){\n console.log(x);\n break;\n }\n\n let count = 0;\n let y = 1;\n while(x > 0){\n let val = (y*(y+1)/2);\n x -= val;\n if(x >= 0)\n count += 1;\n y = 1 + (2*y);\n }\n\n console.log(count);\n }\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let ans = new Array(n);\n let p = 0;\n let count = 0;\n for(let i = 1; i < n; i+=2){\n ans[i] = a[p];\n p++;\n count += 1;\n }\n\n for(let i = 0; i < n; i+=2){\n ans[i] = a[p];\n p++;\n }\n\n console.log(count);\n for(let i of ans)\n console.log(i);\n}"}], "src_uid": "6443dffb38285b6deb74f2371d8d0cac"} {"source_code": "function readInt() {\n return parseInt(readline());\n}\n\nfunction readInts() {\n return readline().split(\" \").map(function(x) { return parseInt(x); });\n}\n\nfunction cmpInt(a, b) {\n return a - b;\n}\n\nvar n = readInt();\nvar a = readInts();\na.sort(cmpInt);\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n ans += Math.abs(i + 1 - a[i]);\n}\nprint(ans);\n", "positive_code": [{"source_code": "var n = +readline();\n\nvar a = readline().split( ' ' ).map( Number );\n\nvar ans = 0;\n\na.sort( function( a, b){ return a - b; } );\nfor ( var i = 1; i <= n; i++ )\n\tans += Math.abs( a[i-1] - i );\n\nprint(ans);"}, {"source_code": "readline();\nprint(readline().split(' ').map(Number).sort(function(a, b) {\n\treturn a - b;\n}).reduce(function(a, b, i) {\n\treturn a + Math.abs(i + 1 - b);\n}, 0));"}, {"source_code": "readline();\nprint(readline().split(' ').map(Number).sort(function(a, b) {\n\treturn a - b;\n}).reduce(function(sum, v, i) {\n\treturn sum + Math.abs(i + 1 - v);\n}, 0));\n"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });\n\n\tvar t = 0;\n\tfor (var i = 1; i <= n; i++)\n\t\tt += Math.abs(i - b[i - 1]);\n\n\tprint(t);\n\n}).call(this);"}, {"source_code": "function readInt() {\n return Number(readline());\n}\n\nfunction readInts() {\n return readline().split(\" \").map(Number);\n}\n\nfunction cmpInt(a, b) {\n return a - b;\n}\n\nvar n = readInt();\nvar a = readInts();\na.sort(cmpInt);\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n ans += Math.abs(i + 1 - a[i]);\n}\nprint(ans);\n"}], "negative_code": [{"source_code": "var n = +readline();\n\nvar a = ( '0 ' + readline() )\n\t\t.split( ' ' )\n\t\t.map( Number )\n\t\t.sort( function( a, b){\n\t\t\treturn a - b;\n\t\t} );\n\nvar ans = 0;\n\nfor ( var i = 1; i <= n; i++ )\n\tans += Math.abs( a[i] - i );\n\nprint(ans);"}, {"source_code": "readline();\nprint(readline().split(' ').map(Number).sort(function(a, b) {\n\treturn a - b;\n}).reduce(function(a, b, i) {\n\treturn a + i + 1 - b;\n}, 0));"}, {"source_code": "function readInt() {\n return parseInt(readline());\n}\n\nfunction readInts() {\n return readline().split(\" \").map(function(x) { return parseInt(x); });\n}\n\nvar n = readInt();\nvar a = readInts();\na.sort();\nvar ans = 0;\nfor (var i = 0; i < n; i++) {\n ans += Math.abs(i + 1 - a[i]);\n}\nprint(ans);\n"}], "src_uid": "86d5da999415fa75b3ee754a2a28605c"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n\n Array(Number(x)).fill(1).map((t, i)=>{\n var line = readline();\n var result1 = 0\n var result2 = 0\n var result3 = 0\n // console.log(line.length)\n\n Array(line.length).fill(1).map((string, i)=>{\n // console.log(i)\n // console.log(string)\n // console.log(line[i])\n if(line[i] === '(') result1+=1\n if(line[i] === ')' && result1>0) {\n result1-=1\n result3+=1\n }\n if(line[i] === '[') result2+=1\n if(line[i] === ']' && result2>0) {\n result2-=1\n result3+=1\n }\n })\n console.log(result3)\n\n })\n\n}\n\n", "positive_code": [{"source_code": "\n\nfunction task(input){\n\tlet ia = input.trim().split('\\n');\n\tlet t = +ia.shift();\n\tfor (let i = 0; i < t; i++) {\n\t\tlet a = ia.shift().split(''), X=0, XS = 0, Y = 0, YS = 0\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif(a[i]=='(')\n\t\t\t\tX++\n\t\t\telse if(a[i]==')' && X>0){\n\t\t\t\tX--\n\t\t\t\tXS++\n\t\t\t}\n\t\t\tif(a[i]=='[')\n\t\t\t\tY++\n\t\t\telse if(a[i]==']' && Y>0){\n\t\t\t\tY--\n\t\t\t\tYS++\n\t\t\t}\n\t\t}\n\t\tconsole.log(XS+YS)\n\t}\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => { \n task(inputString); \n});\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let [count1, count2] = [0, 0];\n const [fStack, sStack] = [[], []];\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (char === \"(\" || char === \")\") {\n if (char === \")\" && fStack[fStack.length - 1] === \"(\") {\n fStack.pop();\n count1++;\n } else if (char === \"(\") fStack.push(char);\n } else {\n if (char === \"]\" && sStack[sStack.length - 1] === \"[\") {\n sStack.pop();\n count2++;\n } else if (char === \"[\") sStack.push(char);\n }\n }\n\n console.log(count1 + count2);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar s = next();\n\t\tvar count = 0;\n\t\tvar map = {};\n\t\tfor(var j = 0; j < s.length; j++){\n\t\t\tif(s[j] == \"[\" || s[j] == \"(\"){\n\t\t\t\tif(map[s[j]] == null){\n\t\t\t\t\tmap[s[j]] = 0;\n\t\t\t\t}\n\t\t\t\tmap[s[j]]++;\n\t\t\t}else{\n\t\t\t\tif(s[j] == \")\" && map[\"(\"] > 0){\n\t\t\t\t\tmap[\"(\"]--;\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tif(s[j] == \"]\" && map[\"[\"] > 0){\n\t\t\t\t\tmap[\"[\"]--;\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput[i] = count;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let [count1, count2] = [0, 0];\n const [fStack, sStack] = [[], []];\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (char === \"(\" || char === \")\") {\n if (char === \")\" && fStack[fStack.length - 1] === \"(\") {\n fStack.pop();\n count1++;\n } else if (char === \"(\") fStack.push(char);\n } else {\n if (char === \"]\" && sStack[sStack.length - 1] === \"[\") {\n sStack.pop();\n count2++;\n } else if (char === \"[\") sStack.push(char);\n }\n }\n\n console.log(count1 + count2);\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function f(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r0&&(e--,n++),\"]\"==t[i]&&r>0&&(r--,n++);i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let s = io.readline()\n// \n// let o1 = 0\n// let o2 = 0\n// \n// let res = 0\n// \n// for (let i = 0; i < s.length; ++i) {\n// if (s[i] == \"(\") {\n// o1++\n// }\n// if (s[i] == \"[\") {\n// o2++\n// }\n// \n// if (s[i] == \")\" && o1 > 0) {\n// o1--\n// res++\n// }\n// \n// if (s[i] == \"]\" && o2 > 0) {\n// o2--\n// res++\n// }\n// }\n// \n// io.puts(res)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x,y] = ti(readline().split(' '));\n \n let min = Math.min(x,y);\n let max = Math.max(x,y);\n if(max === min){\n console.log(max+min);\n }else{\n console.log(2*min+(1+(max-min-1)*2));\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n\n let sum = 0;\n for(let i = 0; i < a.length; i++)\n sum += a[i];\n\n let x = sum-a[0];\n let d = a[n-1]*(n-1)-x;\n\n if(a[0] > d){\n let diff = a[0]-d;\n console.log(diff % (n-1) === 0 ? 0 : ((n-1) - (diff % (n-1))));\n }else{\n console.log(d-a[0]);\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let s = readline().split('');\n let s1 = [];\n let s2 = [];\n\n for(let i = 0; i < s.length; i++){\n if(s[i] === '(' || s[i] === ')'){\n s1.push(s[i]);\n }else{\n s2.push(s[i]);\n }\n }\n\n let res = 0;\n let c = 0;\n for(let i = 0; i < s1.length; i++){\n if(s1[i] === '('){\n c++;\n }else{\n if(c !== 0){\n c--;\n res += 1;\n }\n }\n }\n\n c = 0;\n for(let i = 0; i < s2.length; i++){\n if(s2[i] === '['){\n c++;\n }else{\n if(c !== 0){\n c--;\n res += 1;\n }\n }\n }\n\n console.log(res);\n }\n}"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var str = readline();\n var c1 = 0, c2 = 0, res = 0;\n for (var i = 0; i < str.length; i++){\n if (str[i] == ')') {\n if (c1) {\n res++, c1--;\n }\n } if (str[i] == '(') c1++;\n\n if (str[i] == ']') {\n if (c2) {\n res++, c2--;\n }\n } if (str[i] == '[') c2++;\n }\n print(res);\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let [countOpenFirst, countCloseFirst, countOpenSquare, countCloseSquare, foundFirst, foundSquare] = [\n 0,\n 0,\n 0,\n 0,\n false,\n false,\n ];\n const stack = [];\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (char === \"(\" && !foundFirst) {\n foundFirst = true;\n stack.push(char);\n } else if (char === \"[\" && !foundSquare) {\n foundSquare = true;\n stack.push(char);\n } else if (char === \")\" && foundFirst) {\n stack.push(char);\n foundFirst = false;\n } else if (char === \"]\" && foundSquare) {\n stack.push(char);\n foundSquare = false;\n }\n }\n\n for (let char of stack) {\n if (char === \"(\") countOpenFirst++;\n else if (char === \")\") countCloseFirst++;\n else if (char === \"[\") countOpenSquare++;\n else if (char === \"]\") countCloseSquare++;\n }\n\n console.log(Math.min(countOpenFirst, countCloseFirst) + Math.min(countOpenSquare, countCloseSquare));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n let [countOpenFirst, countCloseFirst, countOpenSquare, countCloseSquare, foundFirst, foundSquare] = [\n 0,\n 0,\n 0,\n 0,\n false,\n false,\n ];\n const stack = [];\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (char === \"(\") {\n foundFirst = true;\n stack.push(char);\n } else if (char === \"[\") {\n foundSquare = true;\n stack.push(char);\n } else if (char === \")\" && foundFirst) {\n stack.push(char);\n } else if (char === \"]\" && foundSquare) {\n stack.push(char);\n }\n }\n\n for (let char of stack) {\n if (char === \"(\") countOpenFirst++;\n else if (char === \")\") countCloseFirst++;\n else if (char === \"[\") countOpenSquare++;\n else if (char === \"]\") countCloseSquare++;\n }\n\n console.log(Math.min(countOpenFirst, countCloseFirst) + Math.min(countOpenSquare, countCloseSquare));\n }\n}\n"}], "src_uid": "db9cec57d8ed5e914818ce9b439eb0f9"} {"source_code": "var n = parseInt( readline() );\nvar arr = readline().split(' ').map(Number);\n\nvar uniqueNumbers = {};\nvar steps = 0;\n\nfor (var i = 0; i < n; i++) {\n\n if (arr[i] == 0) {\n continue;\n }\n\n if (!uniqueNumbers[ arr[i] ]) {\n uniqueNumbers[ arr[i] ] = true;\n }\n}\n\nfor (var uniqueNumber in uniqueNumbers) {\n steps++;\n}\n\nprint(steps);\n", "positive_code": [{"source_code": "\nvar n = readline();\nvar element = readline();\nvar probArray = element.split(\" \");\nvar ob = {};\nvar i;\nfor ( i = 0; i < n ; i = i + 1) {\n if ( probArray [i] != 0 ) {\n if (!ob.hasOwnProperty (probArray [i])) {\n ob[ probArray [i] ] = true;\n }\n }\n}\nvar out = 0;\nfor ( var newOb in ob) {\n out++;\n}\nprint(out);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const obj = {};\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (!obj[arr[i]] && arr[i] !== 0) {\n obj[arr[i]] = true;\n ans++;\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = nextIntArray();\n\tvar set = new Set();\n\tfor(var i = 0; i < N; i++){\n\t\tif(list[i] != 0){\n\t\t\tset.add(list[i]);\n\t\t}\n\t}\n\tmyout(set.size);\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const obj = {};\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (!obj[i]) {\n obj[i] = true;\n ans++;\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const obj = {};\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (!obj[arr[i]]) {\n obj[arr[i]] = true;\n ans++;\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "var n = readline();\nvar element = readline();\nvar probArray = element.split(\" \");\nvar ob = {};\nvar i;\nfor ( i = 0; i < n ; i = i + 1) {\n if ( probArray [i] !== 0 ) {\n if (!ob.hasOwnProperty (probArray [i])) {\n ob[ probArray [i] ] = true;\n }\n }\n}\nvar out = 0;\nfor ( var newOb in ob) {\n out++;\n}\nprint(out);"}], "src_uid": "0593f79604377dcfa98d2b69840ec0a6"} {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n const nums = str.split(' ').map(num => parseInt(num));\r\n nums.sort((a, b) => b - a)\r\n\r\n // console.log(nums)\r\n console.log(binarySearch(nums));\r\n // console.log(canAliceWin(2, [...nums]))\r\n}\r\n\r\nfunction binarySearch(nums) {\r\n let low = 0\r\n let hi = nums.length\r\n\r\n while(low !== hi && low !== hi - 1) {\r\n let mid = Math.floor((low + hi) / 2);\r\n // console.log(low, hi, mid )\r\n\r\n if(canAliceWin(mid, [...nums])) {\r\n low = mid\r\n } else {\r\n hi = mid - 1\r\n }\r\n }\r\n\r\n return canAliceWin(hi, [...nums]) ? hi : low;\r\n}\r\n\r\nfunction canAliceWin(k, nums) {\r\n let startLookingAtIndex = 0;\r\n let round = 1;\r\n let bobIndex = nums.length - 1;\r\n\r\n for(round = 1; round <= k ; round++) {\r\n const indexToDelete = nums.findIndex((num, index) => index >= startLookingAtIndex && num <= (k - round + 1));\r\n\r\n if(indexToDelete === -1) {\r\n return false;\r\n }\r\n \r\n // \"delete\"\r\n startLookingAtIndex = indexToDelete + 1;\r\n\r\n // run out of elements\r\n if(startLookingAtIndex === nums.length) {\r\n return round === k;\r\n }\r\n\r\n // bob turn\r\n nums[bobIndex] += (k - round + 1);\r\n bobIndex--;\r\n }\r\n\r\n return true;\r\n}", "positive_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a } = testCase;\n\n a.sort((b, c) => b - c);\n\n let result = Math.ceil(n / 2);\n let found = false;\n for (let k = 0; 2 * k - 1 <= n; k++) {\n for (let i = k - 1; i < k - 1 + k; i++) {\n if (a[i] > i - k + 2) {\n found = true;\n break;\n }\n }\n if (found) {\n result = k - 1;\n break;\n }\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n let t = k,\r\n i = 1;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n let cur = k - i + 1;\r\n while (l <= r && a[l] > cur) l++;\r\n if (l <= r && a[l] <= cur) ans++;else break;\r\n i++;\r\n }\r\n return ans >= t;\r\n };\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) {\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n arr.sort((a, b) => b - a);\r\n const helper = (pos, end) => {\r\n let st = 0;\r\n while (pos !== 0) {\r\n let flag = 0;\r\n for (let i = st; i <= end; i++) {\r\n if (arr[i] <= pos) {\r\n st = i + 1;\r\n flag = 1;\r\n break;\r\n }\r\n }\r\n if (flag === 0) return false;\r\n end--;\r\n pos--;\r\n }\r\n return true;\r\n };\r\n let ans = 0,\r\n st = Math.ceil(n / 2);\r\n for (let i = 0; i < n && st > 0; i++, st--) {\r\n if (helper(st, n - 1)) {\r\n ans = st;\r\n break;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n let cur = k - l + 1;\r\n while (l < r && a[l] > cur) l++;\r\n if (l <= r && a[l] <= cur) ans++;else break;\r\n }\r\n return ans >= k;\r\n };\r\n let l = 0,\r\n r = n * 2;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n let cur = k - l + 1;\r\n while (l < r && a[l] > cur) l++;\r\n if (l <= r && a[l] <= cur) ans++;else break;\r\n }\r\n return ans >= k;\r\n };\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n let cur = k - l + 1;\r\n while (l <= r && a[l] > cur) l++;\r\n if (l <= r && a[l] <= cur) ans++;\r\n }\r\n return ans >= k;\r\n };\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n a.sort((a, b) => b - a);\r\n const check = k => {\r\n let ans = 0;\r\n for (let l = 0, r = n - 1; l <= r; l++, r--) {\r\n while (l <= r && a[l] > k) l++;\r\n if (l <= r && a[l] <= k) ans++;\r\n }\r\n return ans >= k;\r\n };\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n if (check(m)) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n const nums = str.split(' ').map(num => parseInt(num));\r\n nums.sort((a, b) => b - a)\r\n\r\n // console.log(nums)\r\n console.log(binarySearch(nums));\r\n // console.log(canAliceWin(2, [...nums]))\r\n}\r\n\r\nfunction binarySearch(nums) {\r\n let low = 0\r\n let hi = nums.length\r\n\r\n while(low !== hi && low !== hi - 1) {\r\n let mid = Math.floor((low + hi) / 2);\r\n // console.log(low, hi, mid )\r\n\r\n if(canAliceWin(mid, [...nums])) {\r\n low = mid\r\n } else {\r\n hi = mid - 1\r\n }\r\n }\r\n\r\n return canAliceWin(hi, [...nums]) ? hi : low;\r\n}\r\n\r\nfunction canAliceWin(k, nums) {\r\n let startLookingAtIndex = 0;\r\n let round = 1;\r\n for(round = 1; round <= k ; round++) {\r\n const indexToDelete = nums.findIndex((num, index) => index >= startLookingAtIndex && num <= (k - round + 1));\r\n\r\n if(indexToDelete === -1) {\r\n return false;\r\n }\r\n \r\n // \"delete\"\r\n startLookingAtIndex = indexToDelete + 1;\r\n\r\n // run out of elements\r\n if(startLookingAtIndex === nums.length) {\r\n return round === k;\r\n }\r\n\r\n // bob turn\r\n const indexToModify = nums.findIndex((num, index) => index >= startLookingAtIndex && num <= (k - round));\r\n // console.log(indexToModify)\r\n if(indexToModify > -1) {\r\n nums[indexToModify] += (k - round + 1);\r\n }\r\n }\r\n\r\n return true;\r\n}"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n const nums = str.split(' ').map(num => parseInt(num));\r\n nums.sort((a, b) => b - a)\r\n\r\n // console.log(nums)\r\n console.log(binarySearch(nums));\r\n // console.log(canAliceWin(1, [...nums]))\r\n}\r\n\r\nfunction binarySearch(nums) {\r\n let low = 0\r\n let hi = nums.length\r\n\r\n while(low !== hi && low !== hi - 1) {\r\n let mid = Math.floor((low + hi) / 2);\r\n // console.log(low, hi, mid )\r\n\r\n if(canAliceWin(mid, [...nums])) {\r\n low = mid\r\n } else {\r\n hi = mid - 1\r\n }\r\n }\r\n\r\n return canAliceWin(hi, [...nums]) ? hi : low;\r\n}\r\n\r\nfunction canAliceWin(k, nums) {\r\n let startLookingAtIndex = 0;\r\n let round = 1;\r\n for(round = 1; round <= k ; round++) {\r\n const indexToDelete = nums.findIndex((num, index) => index >= startLookingAtIndex && num <= (k - round + 1));\r\n\r\n if(indexToDelete === -1) {\r\n return false;\r\n }\r\n \r\n // \"delete\"\r\n startLookingAtIndex = indexToDelete + 1;\r\n\r\n // run out of elements\r\n if(startLookingAtIndex === nums.length) {\r\n return round === k;\r\n }\r\n\r\n // bob turn\r\n nums[startLookingAtIndex] += (k - round + 1);\r\n }\r\n\r\n return true;\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) {\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n arr.sort((a, b) => b - a);\r\n const helper = (pos, st, end) => {\r\n while (pos !== 0 && st <= end) {\r\n if (arr[st] > pos) return false;\r\n pos--;\r\n st++;\r\n end--;\r\n }\r\n if (pos === 0) return true;\r\n };\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (helper(arr[i], i, n - 1)) {\r\n ans = arr[i];\r\n break;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) {\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n arr.sort((a, b) => b - a);\r\n const helper = (pos, st, end) => {\r\n while (pos !== 0 && st <= end) {\r\n if (arr[st] > pos) return false;\r\n pos--;\r\n st++;\r\n end--;\r\n }\r\n if (pos === 0) return true;\r\n };\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (helper(arr[i], i, n - i - 1)) {\r\n ans = arr[i];\r\n break;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a } = testCase;\n\n let result = a.filter((v) => v == 1).length;\n if (result == n && n > 1) result = n - 1;\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, a } = testCase;\n\n let result = a.filter((v) => v == 1).length;\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "0682d5ee1b5b160ece449c4676a369a7"} {"source_code": "function solve() {\r\n const n = Number(read());\r\n let currentMap = [];\r\n read().split(' ').forEach((x, i) => {\r\n currentMap[Number(x)] = i + 1;\r\n });\r\n const ans = [];\r\n for (let i = n; i > 0; i--) {\r\n const nextMap = [];\r\n const index = currentMap[i];\r\n if (index === i) {\r\n ans.push(0);\r\n continue;\r\n }\r\n const diff = i - index;\r\n ans.push(index);\r\n for (let j = 1; j <= n; j++) {\r\n const jindex = currentMap[j];\r\n if (j > i) {\r\n nextMap[j] = jindex;\r\n continue;\r\n }\r\n if (jindex <= index) {\r\n nextMap[j] = jindex + diff;\r\n continue;\r\n }\r\n nextMap[j] = jindex - index;\r\n }\r\n currentMap = nextMap;\r\n }\r\n ans.reverse();\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let obj = {};\r\n arr.map((i, j) => {\r\n obj[i] = j + 1;\r\n return i;\r\n });\r\n const help = (j, rotate) => {\r\n let k = n;\r\n for (let i = 0; i < rotate.length; i++, k--) j = (j + rotate[i]) % k;\r\n return j;\r\n };\r\n let rotate = [],\r\n res = new Array(n).fill(0);\r\n for (let i = n; i >= 1; i--) {\r\n let j = obj[i];\r\n j = help(j, rotate);\r\n if (j === i) {\r\n rotate.push(0);\r\n continue;\r\n } else {\r\n res[i - 1] = j;\r\n rotate.push(i - j);\r\n }\r\n }\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, data) {\r\n const map = [];\r\n\r\n for (let i = 0; i < data.length; i++) {\r\n map[data[i]] = i + 1;\r\n }\r\n\r\n let res = [];\r\n\r\n for (let i = map.length - 1; i > 0; i--) {\r\n let cur = map[i];\r\n\r\n if (i === cur) {\r\n res.push(0);\r\n continue;\r\n }\r\n\r\n res.push(cur);\r\n\r\n for (let j = 1; j < i; j++) {\r\n map[j] = (map[j] - cur + i) % i;\r\n }\r\n }\r\n\r\n return res.reverse();\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const n = Number(inputs[__ * 2 + 1]);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, data);\r\n console.log(res.join(' '));\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet a;\r\n// [l,r)\r\nfunction reverse(l, r) {\r\n r--;\r\n while (l < r) {\r\n let t = a[l];\r\n a[l] = a[r];\r\n a[r] = t;\r\n l++;\r\n r--;\r\n }\r\n}\r\n// [l,r)\r\nfunction rotate(r, n) {\r\n reverse(0, r);\r\n reverse(r, n);\r\n reverse(0, n);\r\n}\r\nfunction solve(n) {\r\n const ans = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n let want = i + 1;\r\n if (a[i] == want) {\r\n ans.push(0);\r\n continue;\r\n }\r\n let pos = a.findIndex((e) => e == want);\r\n rotate(pos + 1, i + 1);\r\n ans.push(pos + 1);\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n printf(\"%d \", ans[i]);\r\n }\r\n printf(\"\\n\");\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n solve(n);\r\n }\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\n \nconst calc = (n, arr)=>{\n let ops = [];\n for (let i=n; i>=1; i--){\n let index = arr.indexOf(i);\n if (index==-1)\n throw 'what'\n ops.push((index+1)%i);\n //console.log('ARR ', {index, i}, arr)\n arr = [].concat(arr.slice(index+1), arr.slice(0, index));\n //console.log('=>', arr)\n }\n //console.log('ANS')\n return ops.reverse();\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let arr = ra();\n print(calc(n, arr).join(' '));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n let cur = n\r\n const ans = Array(n)\r\n let p = n - 1\r\n while (cur >= 1) {\r\n let idx = arr.indexOf(cur) + 1\r\n if (idx <= 0) return -1\r\n ans[p--] = idx % cur\r\n\r\n const next = Array(cur)\r\n for (let i = 0; i < cur; i++) {\r\n next[(i - idx + cur) % cur] = arr[i]\r\n }\r\n // console.log(next)\r\n arr = next\r\n cur--\r\n }\r\n return ans.join(' ')\r\n}\r\n"}], "negative_code": [], "src_uid": "a83aaaa8984d1a6dda1adf10127b7abc"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n console.log((l * (p / (p + q))).toFixed(4));\n});\n", "positive_code": [{"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar d8 = __webpack_require__(1);\n\tvar L = d8.readnumbers()[0];\n\tvar p = d8.readnumbers()[0];\n\tvar q = d8.readnumbers()[0];\n\tvar t = L / (p + q);\n\tprint(p * t);\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar List = __webpack_require__(2);\n\tfunction readnumbers() {\n\t return List.map(parseInt, readline().split(' '));\n\t}\n\texports.readnumbers = readnumbers;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(3);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction sort(xs, compare) {\n\t return copy(xs).sort(compare);\n\t}\n\texports.sort = sort;\n\tfunction sortInPlace(xs, compare) {\n\t xs.sort(compare);\n\t return xs;\n\t}\n\texports.sortInPlace = sortInPlace;\n\tfunction maximumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximumInRange = maximumInRange;\n\tfunction maximum(xs) {\n\t return maximumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.maximum = maximum;\n\tfunction maximumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result < candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.maximumInRangeWith = maximumInRangeWith;\n\tfunction maximumWith(xs, f) {\n\t return maximumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.maximumWith = maximumWith;\n\tfunction minimumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimumInRange = minimumInRange;\n\tfunction minimum(xs) {\n\t return minimumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.minimum = minimum;\n\tfunction minimumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result > candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.minimumInRangeWith = minimumInRangeWith;\n\tfunction minimumWith(xs, f) {\n\t return minimumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.minimumWith = minimumWith;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction nub(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t result.push(xs[0]);\n\t for (var i = 1; i < xs.length; i++) {\n\t if (xs[i] !== xs[i - 1]) {\n\t result.push(xs[i]);\n\t }\n\t }\n\t return result;\n\t}\n\texports.nub = nub;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\tfunction range(from, to) {\n\t var result = Array(to - from + 1);\n\t for (var i = from; i <= to; i++) {\n\t result[i - from] = i;\n\t }\n\t return result;\n\t}\n\texports.range = range;\n\tfunction copy(xs) {\n\t return xs.slice(0);\n\t}\n\texports.copy = copy;\n\tfunction apply_permutation(p, xs) {\n\t var n = xs.length;\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = xs[p[i]];\n\t }\n\t return result;\n\t}\n\texports.apply_permutation = apply_permutation;\n\tfunction next_permutation(p) {\n\t var n = p.length;\n\t if (n < 2)\n\t return null;\n\t var r = copy(p);\n\t var k = n - 2;\n\t for (; k >= 0 && r[k] >= r[k + 1]; k--)\n\t ;\n\t if (k < 0)\n\t return null;\n\t for (var i = k + 1, j = n - 1; i < j; i++, j--) {\n\t var t_1 = r[i];\n\t r[i] = r[j];\n\t r[j] = t_1;\n\t }\n\t var next = k + 1;\n\t for (; r[next] <= r[k]; next++)\n\t ;\n\t var t = r[k];\n\t r[k] = r[next];\n\t r[next] = t;\n\t return r;\n\t}\n\texports.next_permutation = next_permutation;\n\tfunction create(n, value) {\n\t return replicate(n, value);\n\t}\n\texports.create = create;\n\tfunction createWith(n, f) {\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = f(i);\n\t }\n\t return result;\n\t}\n\texports.createWith = createWith;\n\tfunction create2D(n1, n2, value) {\n\t return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));\n\t}\n\texports.create2D = create2D;\n\tfunction create2DWith(n1, n2, f) {\n\t var result = new Array(n1);\n\t for (var i = 0; i < n1; i++) {\n\t result[i] = new Array(n2);\n\t for (var j = 0; j < n2; j++) {\n\t result[i][j] = f(i, j);\n\t }\n\t }\n\t return result;\n\t}\n\texports.create2DWith = create2DWith;\n\n\n/***/ },\n/* 3 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\tfunction gcd(a, b) {\n\t var r = a % b;\n\t while (r !== 0) {\n\t a = b;\n\t b = r;\n\t r = a % b;\n\t }\n\t return b;\n\t}\n\texports.gcd = gcd;\n\n\n/***/ }\n/******/ ]);"}, {"source_code": "var l = parseInt(readline()),\n\tp = parseInt(readline()),\n\tq = parseInt(readline()),\n\tt1, t2;\n\nt1 = l / (p+q);\nt2 = t1 * p;\n\nprint(t2);"}, {"source_code": "try {require('codef');} catch (e){global = this};\nfunction readLineAsArray(separator){return readline().split(typeof separator == \"undefined\" ? ' ' : separator)}\nfunction readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}\nArray.prototype.list = function() {var length = arguments.length; for(var i=0; i < length; i++){global[arguments[i]] = this[i]}};\nString.prototype.repeat = function(n){return new Array(n + 1).join(this);}\n\nvar l = +readline(),\n p = +readline(),\n q = +readline();\n\n\nwrite(l * p / (p + q));"}, {"source_code": "var l = parseInt(readline(), 10),\n p = parseInt(readline(), 10),\n q = parseInt(readline(), 10);\n\nfunction calcLength (l, p, q) {\n return (l / (p + q)) * p;\n}\n\nwrite(calcLength(l, p, q));\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n const max = Math.max(p, q);\n let ans = max / 100 * l;\n\n if (max >= l) {\n ans = l * 2 / ((p + q) * 2);\n // console.log({ ans})\n }\n\n console.log(ans.toFixed(4));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n if (p === q) {\n console.log((l / 2).toFixed(4));\n return;\n }\n\n if (p + q <= l) {\n console.log((Math.max(p, q) / 100 * l).toFixed(4));\n return;\n }\n\n if (p > l) {\n console.log(((p * 100 / (p + q)) / 100).toFixed(4));\n return;\n }\n\n console.log((p * 100 / (p + q)).toFixed(4));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n const max = Math.max(p, q);\n const ans = max / 100 * l;\n\n console.log(ans.toFixed(4));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n const max = Math.max(p, q);\n let ans = max / 100 * l;\n\n if (max === l) {\n ans = max / 2;\n }\n\n console.log(ans.toFixed(4));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet l, p, q;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n l = +d;\n return;\n }\n\n if (c === 1) {\n c++;\n p = +d;\n return;\n }\n\n q = +d;\n\n c++;\n});\n\nrl.on('close', () => {\n const max = Math.max(p, q);\n let ans = max / 100 * l;\n\n if (p + q > l) {\n ans = l * 2 / ((p + q) * 2);\n\n if (p > q) {\n ans = l - ans;\n }\n }\n\n console.log(ans.toFixed(4));\n});\n"}], "src_uid": "6421a81f85a53a0c8c63fbc32750f77f"} {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\n \r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\nvar tc = parseInt(readline());\r\nwhile(tc--)\r\n{\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(Number);\r\n var poss = false;\r\n arr.sort((a,b)=>b-a);\r\n var sumRed = 0, sumBlue = arr[n-1];\r\n for(var i=0; i sumBlue)\r\n {\r\n poss = true;\r\n break;\r\n }\r\n }\r\n if(poss) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}", "positive_code": [{"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nconst calc = (arr)=>{\n arr.sort((a, b)=>a-b);\n let blue_sum = arr[0]+arr[1];\n let blue_cnt = 2;\n let red_sum = arr[arr.length-1];\n let bi = 2;\n let ri = arr.length-2;\n while (bi=red_sum){\n blue_sum += arr[bi];\n red_sum += arr[ri];\n bi++;\n ri--;\n }\n return red_sum>blue_sum\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let arr = ra();\n print(calc(arr) ? 'YES' : 'NO');\n }\n}\n \nE.calc = calc;"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let input = readLine().split(\" \").map(i => parseInt(i)).sort((a,b)=>a-b);\r\n const rarr = [], barr = [];\r\n let l = 0; r = input.length - 1;\r\n let rsum = 0; bsum = 0;\r\n bsum += input[l];\r\n barr.push(input[l++]);\r\n while (l < r) {\r\n bsum += input[l];\r\n rsum += input[r];\r\n barr.push(input[l]);\r\n rarr.push(input[r]);\r\n if (rsum > bsum && rarr.length < barr.length) {\r\n console.log(\"YES\");\r\n return;\r\n } else {\r\n l++;\r\n r--;\r\n }\r\n }\r\n console.log(\"NO\");\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\n\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\n\r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\n\r\nlet str = readline();\r\n\r\nfor(let q=1;q<=str;q++) {\r\nconst inp = readline()\r\n let data = readline().split(' ').map(numb => parseInt(numb));\r\n data.sort((a,b) => a-b);\r\n let sum = [];\r\n sum[-1] = 0;\r\n for(let i=0; i parseInt(w));\r\n // var a =[3, 5, 4, 2]\r\n // var n = a.length;\r\n a.sort(function(ar,br) { return ar-br })\r\n var sum = []\r\n sum[-1] = 0;\r\n for(var i=0;i n+1) i--;\r\n// console.log(i);\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n \r\n arr.sort((a, b) => b - a);\r\n\r\n let R, B;\r\n\r\n if (n % 2 === 0) {\r\n let div = (n / 2) - 1;\r\n R = arr.slice(0, div);\r\n B = arr.slice(div + 1, n);\r\n } else {\r\n R = arr.slice(0, Math.floor(n / 2));\r\n B = arr.slice(Math.floor(n / 2), n);\r\n }\r\n\r\n let sumR = R.reduce((a, b) => a + b, 0);\r\n let sumB = B.reduce((a, b) => a + b, 0);\r\n\r\n output(sumR > sumB ? 'YES': 'NO');\r\n }\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nlet t = +readline();\r\nlet result = 0;\r\nwhile(t--){\r\n let n = +readline();\r\n let arr = readline().split(' ').map(x=>+x);\r\n console.log(`${solve(arr, n)}`) \r\n}\r\n\r\nfunction solve(nums, n){\r\n if(n < 3) return 'NO';\r\n \r\n nums.sort((a, b)=>a-b);\r\n let redSum = nums[n-1];\r\n let blueSum = nums[0] + nums[1];\r\n if(redSum > blueSum) return 'YES';\r\n let l = 2;\r\n let r = n-2;\r\n \r\n while(l < r){\r\n blueSum += nums[l];\r\n redSum += nums[r];\r\n l++;\r\n r--;\r\n if(redSum > blueSum) return 'YES';\r\n }\r\n return 'NO';\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var blue = k[0] + k[1];\n var red = k[n - 1];\n var l = 2, r = n - 2;\n var flag = false;\n while(l < r){\n if(red > blue){\n flag = true;\n break;\n }\n blue += k[l], red +=k[r];\n l++;\n r--;\n }\n console.log(flag || red > blue ? 'YES':'NO');\n }\n }\n});\n\n"}, {"source_code": " var tests = parseInt(readline());\r\n var n, s;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n s = readline().split(' ').map(x=>parseInt(x));\r\n s.sort((a, b)=>a-b);\r\n var suma = 0, sumb = s[0];\r\n var a = n-1, b = 1;\r\n while ( b < a && suma <= sumb ) {\r\n suma += s[a];\r\n sumb += s[b];\r\n b++;\r\n a--;\r\n }\r\n if (suma > sumb) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n }"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\n \r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\nvar tc = parseInt(readline());\r\nwhile(tc--)\r\n{\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(Number);\r\n var poss = false;\r\n arr.sort((a,b)=>b-a);\r\n var sumRed = 0, sumBlue = arr[n-1];\r\n for(var i=1; i sumBlue)\r\n {\r\n poss = true;\r\n break;\r\n }\r\n }\r\n if(poss) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\n \r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\nvar tc = parseInt(readline());\r\nwhile(tc--)\r\n{\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(Number);\r\n var sumBlue = 0, sumRed = 0;\r\n var poss = false;\r\n for(var i=0;ib-a);\r\n for(var i=0; i sumBlue)\r\n {\r\n poss = true;\r\n break;\r\n }\r\n }\r\n if(poss) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\n \r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\nvar tc = parseInt(readline());\r\nwhile(tc--)\r\n{\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(Number);\r\n var sumBlue = 0, sumRed = 0;\r\n var poss = false;\r\n for(var i=0;ib-a);\r\n for(var i=0; i sumBlue)\r\n {\r\n poss = true;\r\n break;\r\n }\r\n }\r\n if(poss) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\n \r\nfunction readline() {\r\n return input[currentline++];\r\n}\r\nvar tc = parseInt(readline());\r\nconsole.log(tc);\r\nwhile(tc--)\r\n{\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(Number);\r\n var sumBlue = 0, sumRed = 0;\r\n var poss = false;\r\n for(var i=0;ib-a);\r\n for(var i=0; i sumBlue)\r\n {\r\n poss = true;\r\n break;\r\n }\r\n }\r\n if(poss) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nconst calc = (arr)=>{\n arr.sort((a, b)=>a-b);\n let blue_sum = arr[0]+arr[1];\n let blue_cnt = 2;\n let red_sum = arr[arr.length-1];\n let bi = 2;\n let ri = arr.length-2;\n while (bi=red_sum){\n bi++;\n ri--;\n }\n return red_sum>blue_sum\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let arr = ra();\n print(calc(arr) ? 'YES' : 'NO');\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nconst calc = (arr)=>{\n arr.sort((a, b)=>a-b);\n return arr[0]+arr[1] {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let input = readLine().split(\" \").map(i => parseInt(i)).sort();\r\n const rarr = [], barr = [];\r\n let l = 0; r = input.length - 1;\r\n let rsum = 0; bsum = 0;\r\n bsum += input[l];\r\n barr.push(input[l++]);\r\n while (l < r) {\r\n bsum += input[l];\r\n rsum += input[r];\r\n barr.push(input[l]);\r\n rarr.push(input[r]);\r\n if (rsum > bsum && rarr.length < barr.length) {\r\n console.log(\"YES\");\r\n return;\r\n } else {\r\n l++;\r\n r--;\r\n }\r\n }\r\n console.log(\"NO\");\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let input = readLine().split(\" \").map(i => parseInt(i)).sort();\r\n const rarr = [], barr = [];\r\n let l = 0; r = input.length - 1;\r\n let rsum = 0; bsum = 0;\r\n bsum += input[l];\r\n barr.push(input[l++]);\r\n while (l < r) {\r\n bsum += input[l];\r\n rsum += input[r];\r\n barr.push(input[l]);\r\n rarr.push(input[r]);\r\n if (rsum > bsum && rarr.length < barr.length) {\r\n console.log(\"YES\");\r\n break;\r\n } else {\r\n l++;\r\n r--;\r\n }\r\n }\r\n console.log(\"NO\");\r\n}\r\n"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\n \r\n \r\n process.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\" \");\r\n qualityVSQuantity(lines)\r\n \r\n })\r\n\r\nfunction findBestCase(arr) {\r\n var sortedArr = arr.sort((a, b) => a - b);\r\n var maxElem = sortedArr[sortedArr.length - 1];\r\n var blueArr = ''\r\n var redArr = [];\r\n redArr[0] =(sortedArr[sortedArr.length - 1]);\r\n var sumOfBlue = 0;\r\n var sumOfRed = maxElem;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] < maxElem && sumOfBlue < maxElem) {\r\n if (blueArr.split(\" \").length === 2) {\r\n var item = Math.max(blueArr.split(\" \")[0], blueArr.split(\" \")[1]);\r\n blueArr = item;\r\n }\r\n blueArr = blueArr + ' ' + arr[i]\r\n }\r\n }\r\n if (blueArr.split(\" \").length) sumOfBlue = blueArr.split(\" \").reduce(function (a, b) {return +a + +b});\r\n if (sumOfBlue > sumOfRed) findBestCase(arr.filter(function(el) {return el !== maxElem}));\r\n else if (sumOfRed > sumOfBlue && redArr.length < blueArr.split(\" \").length) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n\r\n\r\n \r\nfunction qualityVSQuantity (a) {\r\n if (a.length <= 1) { \r\n console.log(\"NO\");\r\n }\r\n findBestCase(a);\r\n }\r\n"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\n \r\n \r\n process.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\" \");\r\n qualityVSQuantity(lines)\r\n \r\n })\r\n\r\nfunction findBestCase(arr) {\r\n var sortedArr = arr.sort((a, b) => a - b);\r\n var maxElem = sortedArr[sortedArr.length - 1];\r\n var blueArr = ''\r\n var redArr = [];\r\n redArr[0] =(sortedArr[sortedArr.length - 1]);\r\n var sumOfBlue = 0;\r\n var sumOfRed = maxElem;\r\n \r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] < maxElem && sumOfBlue < maxElem) {\r\n if (blueArr.length === 2) {\r\n var item = Math.max(blueArr[0], blueArr[1]);\r\n blueArr = item;\r\n }\r\n blueArr = blueArr + ' ' + arr[i]\r\n }\r\n }\r\n if (blueArr.split(\" \").length) sumOfBlue = blueArr.split(\" \").reduce(function (a, b) {return a + b});\r\n \r\n if (sumOfBlue > sumOfRed) findBestCase(arr.filter(function(el) {return el !== maxElem}));\r\n else if (sumOfRed > sumOfBlue && redArr.length < blueArr.length) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n\r\n\r\n \r\nfunction qualityVSQuantity (a) {\r\n if (a.length <= 1) { \r\n console.log(\"NO\");\r\n }\r\n findBestCase(a);\r\n }\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var n = readline()\r\n var a = readline().split(' ').map(w => parseInt(w));\r\n // var a =[3, 5, 4, 2]\r\n // var n = a.length;\r\n a.sort(function(ar,br) { return ar-br })\r\n var sum = []\r\n sum[-1] = 0;\r\n for(var i=0;i n+1) i--;\r\n// console.log(i);\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var n = readline()\r\n var a = readline().split(' ').map(w => parseInt(w));\r\n// var a =[1,2,3]\r\n// var n = a.length;\r\n a.sort(function(ar,br) { return ar-br })\r\n var sum = []\r\n sum[-1] = 0;\r\n for(var i=0;i n+1) i--;\r\n// console.log(i);\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n \r\n arr.sort((a, b) => b - a);\r\n\r\n let R, B;\r\n\r\n if (n % 2 === 0) {\r\n let div = (n / 2) - 1;\r\n R = arr.slice(0, div);\r\n B = arr.slice(div, n);\r\n } else {\r\n R = arr.slice(0, Math.floor(n / 2));\r\n B = arr.slice(Math.floor(n / 2), n);\r\n }\r\n\r\n let sumR = R.reduce((a, b) => a + b, 0);\r\n let sumB = B.reduce((a, b) => a + b, 0);\r\n\r\n output(sumR > sumB ? 'YES': 'NO');\r\n }\r\n}\r\n"}], "src_uid": "4af59df1bc56ca8eb5913c2e57905922"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n let sum = arr[0] + arr[n - 1];\r\n for (let i = 1; i < n; i++) {\r\n sum += Math.abs(arr[i] - arr[i - 1]);\r\n }\r\n let r = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {\r\n r += (arr[i] - Math.max(arr[i - 1], arr[i + 1])) * 2;\r\n sum += arr[i] - Math.max(arr[i - 1], arr[i + 1]);\r\n }\r\n }\r\n if (arr[0] > arr[1]) {\r\n r += (arr[0] - arr[1]) * 2;\r\n sum += arr[0] - arr[1];\r\n }\r\n if (arr[n - 1] > arr[n - 2]) {\r\n r += (arr[n - 1] - arr[n - 2]) * 2;\r\n sum += arr[n - 1] - arr[n - 2];\r\n }\r\n console.log(sum - r);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 06/13/21 noon\r\n\r\nconst solve = (n, a) => {\r\n let res = ugliness(a);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < n && a[i] <= a[i + 1]) continue;\r\n if (i - 1 >= 0 && a[i] <= a[i - 1]) continue;\r\n let h = 0;\r\n if (i - 1 >= 0) h = mx(h, a[i - 1]);\r\n if (i + 1 < n) h = mx(h, a[i + 1]);\r\n if (a[i] > h) res -= a[i] - h;\r\n }\r\n pr(res);\r\n};\r\n\r\n// my code\r\nconst ugliness = (A) => {\r\n let a = [...A];\r\n a.unshift(0);\r\n a.push(0);\r\n let n = a.length;\r\n let sum = 0;\r\n let pre = a[0];\r\n for (let i = 1; i < n; i++) {\r\n let tmp = abs(a[i] - pre);\r\n sum += tmp;\r\n pre = a[i];\r\n }\r\n return sum;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 06/13/21 noon\r\n\r\nconst solve = (n, a) => {\r\n let res = ugliness(a);\r\n for (let i = 0; i < n; i++) {\r\n let max = 0;\r\n if (i - 1 >= 0) max = mx(max, a[i - 1]);\r\n if (i + 1 < n) max = mx(max, a[i + 1]);\r\n if (a[i] > max) res -= a[i] - max;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst ugliness = (A) => {\r\n let a = [...A];\r\n a.unshift(0);\r\n a.push(0);\r\n let n = a.length;\r\n let sum = 0;\r\n let pre = a[0];\r\n for (let i = 1; i < n; i++) {\r\n let tmp = abs(a[i] - pre);\r\n sum += tmp;\r\n pre = a[i];\r\n }\r\n return sum;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const g = (await getLine()).split(' ').map(num => parseInt(num));\r\n g.unshift(0);\r\n g.push(0);\r\n let ugly = 0;\r\n for(let i = 1; i <= n; i++) {\r\n ugly += Math.abs(g[i] - g[i - 1]);\r\n if (g[i] > g[i-1] && g[i] > g[i+1]) {\r\n ugly -= Math.min(g[i] - g[i-1], g[i] - g[i+1]);\r\n }\r\n }\r\n ugly += g[n];\r\n console.log(ugly);\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/13/21 noon\r\n * https://codeforces.com/contest/1534/problem/B\r\n */\r\nconst solve = (n, a) => {\r\n // pr(a)\r\n let m = counter(a);\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let max = 0;\r\n for(const e of a) {\r\n max = mx(max, e);\r\n if (e != 0) min = mi(min, e);\r\n }\r\n let op = 0;\r\n let curMax = max;\r\n let ugly = ugliness(a);\r\n let res = ugly;\r\n while(curMax >= min) {\r\n // pr(curMax);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > curMax) {\r\n a[i]--;\r\n op++;\r\n // if (i == 0) {\r\n // if (a[i] > a[i + 1]) ugly--;\r\n // } else if (i == n - 1) {\r\n // if (a[i] > a[i - 1]) ugly--;\r\n // } else {\r\n // if (a[i] > a[i - 1] && a[i] > a[i + 1]) ugly--;\r\n // }\r\n }\r\n }\r\n let curUg = ugliness(a);\r\n // pr(a, curUg, op);\r\n res = mi(res, curUg + op);\r\n curMax--;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst ugliness = (A) => {\r\n let a = [...A];\r\n a.unshift(0);\r\n a.push(0);\r\n let n = a.length;\r\n let sum = 0;\r\n let pre = a[0];\r\n // pr(a);\r\n for (let i = 1; i < n; i++) {\r\n let tmp = abs(a[i] - pre);\r\n sum += tmp;\r\n pre = a[i];\r\n // pr(a[i], tmp);\r\n }\r\n return sum;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/13/21 noon\r\n * https://codeforces.com/contest/1534/problem/B\r\n */\r\nconst solve = (n, a) => {\r\n // pr(a)\r\n let m = counter(a);\r\n let min = Number.MAX_SAFE_INTEGER;\r\n let max = 0;\r\n for(const e of a) {\r\n max = mx(max, e);\r\n if (e != 0) min = mi(min, e);\r\n }\r\n let op = 0;\r\n let curMax = max - 1;\r\n let ugly = ugliness(a);\r\n let res = ugly;\r\n while(curMax >= min) {\r\n // pr(curMax);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] > curMax) {\r\n a[i]--;\r\n op++;\r\n // if (i == 0) {\r\n // if (a[i] > a[i + 1]) ugly--;\r\n // } else if (i == n - 1) {\r\n // if (a[i] > a[i - 1]) ugly--;\r\n // } else {\r\n // if (a[i] > a[i - 1] && a[i] > a[i + 1]) ugly--;\r\n // }\r\n }\r\n }\r\n let curUg = ugliness(a);\r\n // pr(a, curUg, op);\r\n res = mi(res, curUg + op);\r\n curMax--;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst ugliness = (A) => {\r\n let a = [...A];\r\n a.unshift(0);\r\n a.push(0);\r\n let n = a.length;\r\n let sum = 0;\r\n let pre = a[0];\r\n // pr(a);\r\n for (let i = 1; i < n; i++) {\r\n let tmp = abs(a[i] - pre);\r\n sum += tmp;\r\n pre = a[i];\r\n // pr(a[i], tmp);\r\n }\r\n return sum;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n\r\n// pr(ugliness([4, 8, 9, 6]), 0)\r\n// pr(ugliness([4, 8, 8, 6]), 1)\r\n// pr(ugliness([4, 7, 7, 6]), 3)"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let sum = arr[0] + arr[n - 1];\r\n for (let i = 1; i < n; i++) {\r\n sum += Math.abs(arr[i] - arr[i - 1]);\r\n }\r\n let r = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {\r\n r += (arr[i] - Math.max(arr[i - 1], arr[i + 1])) * 2;\r\n sum += arr[i] - Math.max(arr[i - 1], arr[i + 1]);\r\n }\r\n }\r\n if (arr[0] > arr[1]) {\r\n r += (arr[0] - arr[1]) * 2;\r\n sum += arr[0] - arr[1];\r\n }\r\n if (arr[n - 1] > arr[n - 2]) {\r\n r += (arr[n - 1] - arr[n - 2]) * 2;\r\n sum += arr[n - 1] - arr[n - 2];\r\n }\r\n console.log(sum - r);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "6313b2788fbf58b9b7c70fc85afa4c1c"} {"source_code": ";(function () {\n\tvar n = readline().split(' ');\n\tvar k = +n[1];\n\tn = +n[0];\n\n\tvar s = readline().split(' ').map(Number);\n\tvar t = 0;\n\tfor (var i = 1; i < n; i++) {\n\t\tvar a = readline().split(' ').map(Number);\n\n\t\tt += Math.pow( Math.pow(a[0] - s[0], 2) + Math.pow(a[1] - s[1], 2), 0.5);\n\n\t\ts = a;\n\t}\n\n\tprint(t * k / 50);\n\t\n}).call(this);", "positive_code": [{"source_code": "print(function(n, k) {\n\n\tvar a = [];\n\tfor (var i = 0; i < n; i++)\n\t\ta.push(readline().split(' ').map(Number));\n\n\tvar d = 0;\n\ta.reduce(function(a, b) {\n\t\tvar x = a[0] - b[0];\n\t\tvar y = a[1] - b[1];\n\t\td += Math.sqrt(x * x + y * y);\n\t\treturn b;\n\t});\n\n\treturn d * k / 50;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var nk = readline();\nnk = nk.split(\" \");\nnk[0] = parseInt(nk[0]);\nnk[1] = parseInt(nk[1]);\nvar v = 50, s = 0;\nvar xy0 = readline();\nxy0 = xy0.split(\" \");\nxy0[0] = parseInt(xy0[0]);\nxy0[1] = parseInt(xy0[1]);\nfor(var i = 1; i < nk[0]; ++i)\n{\n var xy = readline();\n xy = xy.split(\" \");\n xy[0] = parseInt(xy[0]);\n xy[1] = parseInt(xy[1]);\n s += Math.sqrt(Math.pow((xy[0] - xy0[0]), 2) + Math.pow((xy[1] - xy0[1]), 2));\n xy0 = xy;\n}\nprint(((s / v)*nk[1]).toFixed(6));"}], "negative_code": [], "src_uid": "db4a25159067abd9e3dd22bc4b773385"} {"source_code": "var n=Number(readline())\nvar P=readline().split(' ').map(Number)\nvar C=readline().split(' ').map(Number)\nvar T=new Array(n)\nfor (var i=0; i= 0 && C[v] !== C[p]) ++R;\n\t\n\tfor (var k in T[v]) {\n\t\tif (k != p) {\n\t\t\twalk(k, v)\n\t\t}\n\t}\n}\n\nwalk(0, -1)\nprint(R)\n\n// print(JSON.stringify(T))\n\n", "positive_code": [{"source_code": "var n = Number(readline());\nvar tree = [];\nvar arr = readline().split(' ').map(Number);\nfor (var i = 0; i < n - 1; i++) {\n\tif (!tree[arr[i] - 1]) {\n\t\ttree[arr[i] - 1] = [];\n\t}\n\ttree[arr[i] - 1].push(i+1);\n}\nvar color = readline().split(' ').map(Number);\n\nvar result = 0;\nvar curColor = 0;\n\n//print(JSON.stringify(tree));\n\nfunction order(i, curColor) {\n\tif (color[i] !== curColor) {\n\t\tresult += 1;\n\t\tcurColor = color[i];\n\t}\n\tif (tree[i]) {\n\t\tfor (var j = 0; j < tree[i].length; j++) {\n\t\t\tvar child = tree[i][j];\n\t\t\torder(child, curColor);\n\t\t}\n\t}\n}\n\norder(0, 0);\nprint(result);\n\n\n"}, {"source_code": "function main(){\n function solution(n, p, c){\n var graph = [];\n var rootNode = 1;\n var visited = new Set();\n var currentNode = 1;\n var queue = [];\n var currentColors = []; // [0, 0, 0, ..., 0]\n var endingColors = [];\n var steps = 0;\n var colorToPaint = \"\";\n\n // var graph = [\n // \t[],\n // \t[2, 5],\n // \t[4, 3],\n // \t[],\n // \t[],\n // \t[6],\n // \t[]\n // ];\n\n function colorGraph(someNode, someColor){\n if(visited.has(someNode)){\n return;\n }\n\n currentColors[someNode] = someColor;\n visited.add(someNode);\n\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n colorGraph(childNode, someColor);\n }\n }\n\n var stack = [];\n\n function colorGraphUsingStack(someNode, someColor){\n stack.push(someNode);\n\n while(stack.length > 0){\n var current = stack.pop();\n currentColors[current] = someColor;\n var childNodes = graph[current];\n\n for(var i = 0; i < childNodes.length; i++){\n var child = childNodes[i];\n stack.push(child);\n }\n\n }\n }\n\n var queueOffset = 0;\n queue.top = function(){\n var top = queue[queueOffset];\n queueOffset++;\n return top;\n //return queue.shift();\n };\n\n // This operation is O(n), where n is the number of verticies\n function colorsMatch(currentColors, endingColors){\n for(var i = 0; i < endingColors.length; i++){\n if(currentColors[i] !== endingColors[i]){\n return false;\n }\n }\n return true;\n }\n\n function bfs(someNode){\n if(colorsMatch(currentColors, endingColors)){\n queue = [];\n return;\n }\n\n // process current node\n colorToPaint = endingColors[someNode];\n\n if(currentColors[someNode] !== endingColors[someNode]){\n steps++;\n colorGraphUsingStack(someNode, colorToPaint);\n visited = new Set();\n }\n\n // get next nodes to process\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n queue.push(childNode);\n }\n\n while(queue.length > 0){\n var nextNode = queue.top();\n bfs(nextNode);\n }\n }\n\n\n /* A bunch of code needed just to map input into adjacency list */\n /**\n * @Tigran\n * There has to be a better way of creating an adjacency list from the input.\n *\n * Perhaps I shouldn't be using an adjacency list data structure or I am\n * over complicating this in some way.\n *\n */\n function getAdjacencyListFromInput(n, p){\n\n /**\n * Creates [[], ..., []] of size n\n * @param n\n * @returns {Array}\n */\n function createEmptyAdjacencyList(n){\n var adjancencyList = [];\n for(var i = 0; i < n; i++){\n adjancencyList.push([]);\n }\n\n return adjancencyList;\n }\n\n /**\n * Creates array [2, 3, ..., n+1]\n * @param n\n * @returns {Array}\n */\n\n function createI(n){\n var i = [];\n for(var k = 0; k < n; k++){\n i.push(k + 2);\n }\n return i;\n }\n\n debugger;\n\n var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)\n var i = createI(n + 1); // [2, 3, ... n+1]\n\n for(var k = 0; k < n - 1; k++){\n var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]\n c[p_k].push(i_k);\n }\n\n /**\n * Above could also be this, but makes it harder to read\n * */\n // for(var k = 0; k < n-1; k++){\n // var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n // c[p_k].push(k+2);\n // }\n\n\n return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]\n }\n\n // currentColors = [0, 0, ..., 0] for size N\n function initializeCurrentColors(n){\n // can't use currentColors var name due to compilation issues in codeforces\n var someColors = new Array(n);\n for(var i=0; i < someColors.length; i++){\n someColors[i] = 0;\n }\n return someColors;\n }\n\n function addZeroToFrontOfArray(someArray){\n someArray.unshift(0);\n }\n\n graph = getAdjacencyListFromInput(n, p);\n currentColors = initializeCurrentColors(n+1);\n addZeroToFrontOfArray(c);\n endingColors = c;\n\n\n bfs(rootNode);\n ans = steps;\n }\n\n var ans = 0;\n\n const n = parseInt(readline());\n const p = readline().split(\" \").map(Number);\n const c = readline().split(\" \").map(Number);\n\n solution(n, p, c);\n print(ans);\n}\n\nmain();"}], "negative_code": [{"source_code": "function main(){\n function solution(n, p, c){\n var graph = [];\n var rootNode = 1;\n var dfs_visited = new Set();\n var currentNode = 1;\n var queue = [];\n var currentColors = []; // [0, 0, 0, ..., 0]\n var endingColors = [];\n var steps = 0;\n var colorToPaint = \"\";\n\n // var graph = [\n // \t[],\n // \t[2, 5],\n // \t[4, 3],\n // \t[],\n // \t[],\n // \t[6],\n // \t[]\n // ];\n\n /**\n * This is just a dfs for some starting node, to change colors\n * @param someNode\n * @param someColor\n */\n function colorGraph(someNode, someColor){\n if(dfs_visited.has(someNode)){\n return;\n }\n\n currentColors[someNode] = someColor;\n dfs_visited.add(someNode);\n\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n colorGraph(childNode, someColor);\n }\n }\n\n var stack = [];\n\n function colorGraphUsingStack(someNode, someColor){\n stack.push(someNode);\n\n while(stack.length > 0){\n var current = stack.pop();\n currentColors[current] = someColor;\n var childNodes = graph[current];\n\n if(childNodes == undefined){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var child = childNodes[i];\n stack.push(child);\n }\n\n }\n }\n\n var queueOffset = 0;\n queue.top = function(){\n var top = queue[queueOffset];\n queueOffset++;\n return top;\n //return queue.shift();\n };\n\n // This operation is O(n), where n is the number of vertices\n function colorsMatch(currentColors, endingColors){\n for(var i = 0; i < endingColors.length; i++){\n if(currentColors[i] !== endingColors[i]){\n return false;\n }\n }\n return true;\n }\n\n function bfs(someNode){\n // O(n)\n if(colorsMatch(currentColors, endingColors)){\n queue = [];\n return;\n }\n\n // process current node\n colorToPaint = endingColors[someNode];\n\n if(currentColors[someNode] !== endingColors[someNode]){\n steps++;\n colorGraphUsingStack(someNode, colorToPaint);\n dfs_visited = new Set();\n }\n\n // get next nodes to process\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n queue.push(childNode);\n }\n\n while(queue.length > 0){\n var nextNode = queue.top();\n bfs(nextNode);\n }\n }\n\n\n /* A bunch of code needed just to map input into adjacency list */\n /**\n * @Tigran\n * There has to be a better way of creating an adjacency list from the input.\n *\n * Perhaps I shouldn't be using an adjacency list data structure or I am\n * over complicating this in some way.\n *\n */\n function getAdjacencyListFromInput(n, p){\n\n /**\n * Creates [[], ..., []] of size n\n * @param n\n * @returns {Array}\n */\n function createEmptyAdjacencyList(n){\n var adjancencyList = [];\n for(var i = 0; i < n; i++){\n adjancencyList.push([]);\n }\n\n return adjancencyList;\n }\n\n /**\n * Creates array [2, 3, ..., n+1]\n * @param n\n * @returns {Array}\n */\n\n function createI(n){\n var i = [];\n for(var k = 0; k < n; k++){\n i.push(k + 2);\n }\n return i;\n }\n\n var c = createEmptyAdjacencyList(n); // [[], ..., []] of size n\n var i = createI(n); // [2, 3, ... n+1]\n\n for(var k = 0; k < n-1; k++){\n var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]\n c[p_k].push(i_k);\n }\n\n /**\n * Above could also be this, but makes it harder to read\n * */\n // for(var k = 0; k < n-1; k++){\n // var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n // c[p_k].push(k+2);\n // }\n\n\n return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]\n }\n\n // currentColors = [0, 0, ..., 0] for size N\n function initializeCurrentColors(n){\n // can't use currentColors var name due to compilation issues in codeforces\n var someColors = new Array(n);\n for(var i=0; i < someColors.length; i++){\n someColors[i] = 0;\n }\n return someColors;\n }\n\n function addZeroToFrontOfArray(someArray){\n someArray.unshift(0);\n }\n\n graph = getAdjacencyListFromInput(n, p); // O(n) + O(n) + O(n-1)\n currentColors = initializeCurrentColors(n+1); // O(n)\n addZeroToFrontOfArray(c); // O(n)\n endingColors = c;\n\n\n bfs(rootNode); // O(n^2)\n ans = steps;\n }\n\n var ans = 0;\n\n const n = parseInt(readline());\n const p = readline().split(\" \").map(Number);\n const c = readline().split(\" \").map(Number);\n\n solution(n, p, c);\n print(ans);\n}\n\nmain();"}, {"source_code": "function main(){\n function solution(n, p, c){\n var graph = [];\n var rootNode = 1;\n var visited = new Set();\n var currentNode = 1;\n var queue = [];\n var currentColors = []; // [0, 0, 0, ..., 0]\n var endingColors = [];\n var steps = 0;\n var colorToPaint = \"\";\n\n // var graph = [\n // \t[],\n // \t[2, 5],\n // \t[4, 3],\n // \t[],\n // \t[],\n // \t[6],\n // \t[]\n // ];\n\n function colorGraph(someNode, someColor){\n if(visited.has(someNode)){\n return;\n }\n\n currentColors[someNode] = someColor;\n visited.add(someNode);\n\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n colorGraph(childNode, someColor);\n }\n }\n\n var stack = [];\n\n function colorGraphUsingStack(someNode, someColor){\n stack.push(someNode);\n\n while(stack.length > 0){\n var current = stack.pop();\n currentColors[current] = someColor;\n var childNodes = graph[current];\n\n for(var i = 0; i < childNodes.length; i++){\n var child = childNodes[i];\n stack.push(child);\n }\n\n }\n }\n\n var queueOffset = 0;\n queue.top = function(){\n var top = queue[queueOffset];\n queueOffset++;\n return top;\n //return queue.shift();\n };\n\n // This operation is O(n), where n is the number of verticies\n function colorsMatch(currentColors, endingColors){\n for(var i = 0; i < endingColors.length; i++){\n if(currentColors[i] !== endingColors[i]){\n return false;\n }\n }\n return true;\n }\n\n function bfs(someNode){\n if(colorsMatch(currentColors, endingColors)){\n queue = [];\n return;\n }\n\n // process current node\n colorToPaint = endingColors[someNode];\n\n if(currentColors[someNode] !== endingColors[someNode]){\n steps++;\n colorGraphUsingStack(someNode, colorToPaint);\n visited = new Set();\n }\n\n // get next nodes to process\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n queue.push(childNode);\n }\n\n while(queue.length > 0){\n var nextNode = queue.top();\n bfs(nextNode);\n }\n }\n\n\n /* A bunch of code needed just to map input into adjacency list */\n /**\n * @Tigran\n * There has to be a better way of creating an adjacency list from the input.\n *\n * Perhaps I shouldn't be using an adjacency list data structure or I am\n * over complicating this in some way.\n *\n */\n function getAdjacencyListFromInput(n, p){\n\n /**\n * Creates [[], ..., []] of size n\n * @param n\n * @returns {Array}\n */\n function createEmptyAdjacencyList(n){\n var adjancencyList = [];\n for(var i = 0; i < n; i++){\n adjancencyList.push([]);\n }\n\n return adjancencyList;\n }\n\n /**\n * Creates array [2, 3, ..., n+1]\n * @param n\n * @returns {Array}\n */\n\n function createI(n){\n var i = [];\n for(var k = 0; k < n; k++){\n i.push(k + 2);\n }\n return i;\n }\n\n debugger;\n\n var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)\n var i = createI(n + 1); // [2, 3, ... n+1]\n\n for(var k = 0; k < n - 1; k++){\n var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]\n c[p_k].push(i_k);\n }\n\n /**\n * Above could also be this, but makes it harder to read\n * */\n // for(var k = 0; k < n-1; k++){\n // var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n // c[p_k].push(k+2);\n // }\n\n\n return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]\n }\n\n // currentColors = [0, 0, ..., 0] for size N\n function initializeCurrentColors(n){\n // can't use currentColors var name due to compilation issues in codeforces\n var someColors = new Array(n);\n for(var i=0; i < someColors.length; i++){\n someColors[i] = 0;\n }\n return someColors;\n }\n\n function addZeroToFrontOfArray(someArray){\n someArray.unshift(0);\n }\n\n graph = getAdjacencyListFromInput(n, p);\n currentColors = initializeCurrentColors(n+1);\n addZeroToFrontOfArray(c);\n endingColors = c;\n\n\n bfs(rootNode);\n ans = steps;\n var end = new Date() - start;\n }\n\n var ans = 0;\n\n const n = parseInt(readline());\n const p = readline().split(\" \").map(Number);\n const c = readline().split(\" \").map(Number);\n\n solution(n, p, c);\n print(ans);\n}"}, {"source_code": "var n = 6;\nvar p = [1, 2, 2, 1, 5];\nvar c = [2, 1, 1, 1, 1, 1];\n\nfunction main(){\n function solution(n, p, c){\n var graph = [];\n var rootNode = 1;\n var visited = new Set();\n var currentNode = 1;\n var queue = [];\n var currentColors = []; // [0, 0, 0, ..., 0]\n var endingColors = [];\n var steps = 0;\n var colorToPaint = \"\";\n\n // var graph = [\n // \t[],\n // \t[2, 5],\n // \t[4, 3],\n // \t[],\n // \t[],\n // \t[6],\n // \t[]\n // ];\n\n function colorGraph(someNode, someColor){\n if(visited.has(someNode)){\n return;\n }\n\n currentColors[someNode] = someColor;\n visited.add(someNode);\n\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n colorGraph(childNode, someColor);\n }\n }\n\n var stack = [];\n\n function colorGraphUsingStack(someNode, someColor){\n stack.push(someNode);\n\n while(stack.length > 0){\n var current = stack.pop();\n currentColors[current] = someColor;\n var childNodes = graph[current];\n\n for(var i = 0; i < childNodes.length; i++){\n var child = childNodes[i];\n stack.push(child);\n }\n\n }\n }\n\n var queueOffset = 0;\n queue.top = function(){\n var top = queue[queueOffset];\n queueOffset++;\n return top;\n //return queue.shift();\n };\n\n // This operation is O(n), where n is the number of verticies\n function colorsMatch(currentColors, endingColors){\n for(var i = 0; i < endingColors.length; i++){\n if(currentColors[i] !== endingColors[i]){\n return false;\n }\n }\n return true;\n }\n\n function bfs(someNode){\n if(colorsMatch(currentColors, endingColors)){\n queue = [];\n return;\n }\n\n // process current node\n colorToPaint = endingColors[someNode];\n\n if(currentColors[someNode] !== endingColors[someNode]){\n steps++;\n colorGraphUsingStack(someNode, colorToPaint);\n visited = new Set();\n }\n\n // get next nodes to process\n var childNodes = graph[someNode];\n\n if(!childNodes){\n return;\n }\n\n for(var i = 0; i < childNodes.length; i++){\n var childNode = childNodes[i];\n queue.push(childNode);\n }\n\n while(queue.length > 0){\n var nextNode = queue.top();\n bfs(nextNode);\n }\n }\n\n\n /* A bunch of code needed just to map input into adjacency list */\n /**\n * @Tigran\n * There has to be a better way of creating an adjacency list from the input.\n *\n * Perhaps I shouldn't be using an adjacency list data structure or I am\n * over complicating this in some way.\n *\n */\n function getAdjacencyListFromInput(n, p){\n\n /**\n * Creates [[], ..., []] of size n\n * @param n\n * @returns {Array}\n */\n function createEmptyAdjacencyList(n){\n var adjancencyList = [];\n for(var i = 0; i < n; i++){\n adjancencyList.push([]);\n }\n\n return adjancencyList;\n }\n\n /**\n * Creates array [2, 3, ..., n+1]\n * @param n\n * @returns {Array}\n */\n\n function createI(n){\n var i = [];\n for(var k = 0; k < n; k++){\n i.push(k + 2);\n }\n return i;\n }\n\n debugger;\n\n var c = createEmptyAdjacencyList(n + 1); // [[], ..., []] of size n + 1 (where 0 index isn't used)\n var i = createI(n + 1); // [2, 3, ... n+1]\n\n for(var k = 0; k < n - 1; k++){\n var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n var i_k = i[k]; // e.g. [2, 3, 4, 5, 6]\n c[p_k].push(i_k);\n }\n\n /**\n * Above could also be this, but makes it harder to read\n * */\n // for(var k = 0; k < n-1; k++){\n // var p_k = p[k]; // e.g. [1, 2, 2, 1, 5]\n // c[p_k].push(k+2);\n // }\n\n\n return c; // e.g. [[], [2, 5], [3, 4], [], [], [6]]\n }\n\n // currentColors = [0, 0, ..., 0] for size N\n function initializeCurrentColors(n){\n // can't use currentColors var name due to compilation issues in codeforces\n var someColors = new Array(n);\n for(var i=0; i < someColors.length; i++){\n someColors[i] = 0;\n }\n return someColors;\n }\n\n function addZeroToFrontOfArray(someArray){\n someArray.unshift(0);\n }\n\n graph = getAdjacencyListFromInput(n, p);\n currentColors = initializeCurrentColors(n+1);\n addZeroToFrontOfArray(c);\n endingColors = c;\n\n\n bfs(rootNode);\n ans = steps;\n }\n\n var ans = 0;\n\n const n = parseInt(readline());\n const p = readline().split(\" \").map(Number);\n const c = readline().split(\" \").map(Number);\n\n solution(n, p, c);\n print(ans);\n}\n\n"}], "src_uid": "b23696f763d90335e8bfb0a5e2094c03"} {"source_code": "'use strict'\n\n\nconst problem = (n, k, p) => {\n for(let i = 0, j = 0; i < p.length; i++) {\n if (p[i]) continue;\n if (i === j) { j++; continue; }\n p[i] = 1;\n if (k <= i - j) { p[i-k] = 0; return p.join(''); }\n k -= (i - j);\n p[j++] = 0;\n }\n return p.join('');\n}\n\nlet q = +readline();\nwhile (q--) {\n const nk = readline().split(' ').map(Number);\n const p = readline().split('').map(Number);\n print(problem(nk[0], nk[1], p));\n}\n", "positive_code": [{"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n doit(info[1] * 1, txt[index + 1]);\n}\n\nfunction doit(b, str) {\n let tab = str.split(\"\");\n tab.map((data, index) => {\n if (data == 0) {\n return index;\n }\n }).filter(data => {\n return data != undefined\n }).forEach((data, index) => {\n if(b>0){\n tab[data]=1;\n if(data-index<=b){\n tab[index]=0;\n b-=data-index;\n }else{\n tab[data-b]=0;\n b=0;\n return;\n }\n }\n })\n console.log(tab.join(\"\"));\n}"}], "negative_code": [{"source_code": "'use strict'\n\n\nconst problem = (n, k, p) => {\n let a = 0, b;\n const z = p.reduce((r, i, j) => { if (!i) r.push(j); return r; }, []);\n while (b = z.shift()) {\n if (k <= (b - a)) { p[b] = 1; p[b-k] = 0; return p.join('')}\n p[b] = 1; k -= (b - a); p[a++] = 0;\n }\n return p.join('');\n}\n\nlet q = +readline();\nwhile (q--) {\n const nk = readline().split(' ').map(Number);\n const p = readline().split('').map(Number);\n print(problem(nk[0], nk[1], p));\n}\n"}, {"source_code": "'use strict'\n\n\n\nconst problem = (n, k, p) => {\n for(let i = 0, j = 0; i < p.length; i++) {\n if (p[i] || i === j) continue;\n p[i] = 1;\n if (k <= i - j) { p[i-k] = 0; return p.join(''); }\n k -= (i - j);\n p[j++] = 0;\n }\n return p.join('');\n}\n\nlet q = +readline();\nwhile (q--) {\n const nk = readline().split(' ').map(Number);\n const p = readline().split('').map(Number);\n print(problem(nk[0], nk[1], p));\n}\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, k, p) => {\n let a = 0, b;\n while ((b = p.slice(a).indexOf(0)) !== -1) {\n if (k < b) { p[a+b-k] = 0; p[a+b] = 1; return p.join('')}\n p[a+b] = 1; p[a++] = 0;k -= b;\n }\n return p.join('');\n}\n\nlet q = +readline();\nwhile (q--) {\n const nk = readline().split(' ').map(Number);\n const p = readline().split('').map(Number);\n print(problem(nk[0], nk[1], p));\n}\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, k, p) => {\n for(let i = 0, j = 0; i < p.length; i++) {\n if (p[i]) continue;\n if (i === j) { j++; continue; }\n p[i] = 1;\n if (k <= i - j) { p[i-k] = 0; return p.join(''); }\n k -= (i - j);\n p[j++] = 0;\n print(i, j-1, k, p.join(''))\n }\n return p.join('');\n}\n\nlet q = +readline();\nwhile (q--) {\n const nk = readline().split(' ').map(Number);\n const p = readline().split('').map(Number);\n print(problem(nk[0], nk[1], p));\n}\n"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n tab.map((data, index) => {\n return (data == 0) ? index : null;\n }).filter(data => {\n return data;\n }).forEach((data, index) => {\n while (data != index && x > 0) {\n tab[data] = 1;\n tab[data - 1] = 0;\n --x;\n --data;\n }\n });\n console.log(tab.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let pos=-1;\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n ++pos;\n if(i!=pos && x>0){\n tab[i]=1;\n if(x>=i-1){\n tab[pos]=0;\n x-=i-pos;\n }else{\n tab[i-x]=0;\n break;\n }\n }\n }\n \n }\n console.log(tab.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n for (let index = 0; index < tab.length; index++) {\n if(tab[index]==0 && index!=pos){\n tab[index]=1;\n if(x-index>=0){\n tab[pos]=0;\n x-=index;\n ++pos;\n }else{\n tab[index-x]=0;\n break;\n }\n }\n \n }\n console.log(tab.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n for (let index = 0; index < tab.length; index++) {\n if(tab[index]==0 && index!=pos){\n tab[index]=1;\n if(x-index>=0){\n tab[pos]=0;\n x-=index;\n ++pos;\n }else{\n tab[index-x]=0;\n x=0;\n }\n if(x==0){\n break;\n }\n }\n \n }\n console.log(tab.join(\"\"));\n}\n// 01011110\n// 0101111\n// 0011111"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n binary(info[1] * 1, txt[index+1])\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n let arr=new Array(tab.length).fill(1);\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n if(i-pos<=x){\n x-=Math.abs(pos-i);\n arr[pos]=0;\n }else{\n arr[i-x]=0;\n x=0\n }\n if(x<=0){\n break;\n }\n ++pos\n }\n \n }\n console.log(arr.join(\"\"));\n}\n// 01011110\n// 0101111\n// 0011111"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n for (let index = 0; index < tab.length; index++) {\n if(tab[index]==0 && index!=pos){\n tab[index]=1;\n if(x-index>=pos){\n tab[pos]=0;\n x-=index;\n ++pos;\n }else{\n tab[index-x]=0;\n x=0;\n }\n if(x==0){\n break;\n }\n }\n \n }\n console.log(tab.join(\"\"));\n}\n// 01011110\n// 0101111\n// 0011111"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n binary(info[1] * 1, txt[index+1])\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n let arr=new Array(tab.length).fill(1);\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n if(i-pos<=x){\n x-=i-pos;\n arr[pos]=0;\n }else{\n arr[i-x]=0;\n x=0\n }\n if(x==0){\n break;\n }\n ++pos\n }\n \n }\n console.log(arr.join(\"\"));\n}\n// 01011110\n// 0101111\n// 0011111"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n tab.map((data, index) => {\n return (data == 0) ? index : undefined;\n }).filter(data => {\n return data != undefined;\n }).forEach((data, index) => {\n if(x==0){\n return;\n }else if(data!=index){\n tab[data]=1;\n if(data<=x){\n tab[index]=0;\n x-=data-index;\n }else{\n tab[data-x]=0;\n return;\n }\n }\n });\n console.log(tab.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let r = tab.map((data, index) => {\n return (data == 0) ? index : undefined;\n }).filter(data => {\n return data != undefined;\n }).forEach((data, index) => {\n if(data!=index && x!=0){\n tab[data]=1;\n if(x>=data-index){\n tab[index]=0;\n x-=data;\n }else{\n tab[data-x]=0;\n x=0;\n }\n }\n });\n console.log(tab.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n tab.map((data, index) => {\n return (data == 0) ? index : undefined;\n }).filter(data => {\n return data != undefined;\n }).forEach((data, index) => {\n if(x==0){\n return;\n }else if(data!=index){\n tab[data]=1;\n if(data {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n binary(info[1] * 1, txt[index+1])\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n let arr=new Array(tab.length).fill(1);\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n if(i-pos<=x){\n x-=Math.abs(pos-i);\n arr[pos]=0;\n }else{\n arr[i-x]=0;\n break;\n }\n ++pos\n }\n \n }\n console.log(arr.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n let tab = txt[index + 1].split(\"\").filter(data => {\n return data.length > 0\n });\n binary(info[1] * 1, tab)\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n for (let index = 0; index < tab.length; index++) {\n if(tab[index]==0 && index!=pos){\n tab[index]=1;\n if(index-pos<=x){\n tab[pos]=0;\n x-=index;\n ++pos;\n }else{\n tab[index-x]=0;\n x=0;\n }\n if(x==0){\n break;\n }\n }\n \n }\n console.log(tab.join(\"\"));\n}\n// 01011110\n// 0101111\n// 0011111"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n binary(info[1] * 1, txt[index+1])\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n let arr=new Array(tab.length).fill(1);\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n if(i-pos<=x){\n x-=Math.abs(pos-i);\n arr[pos]=0;\n }else{\n arr[i-x]=0;\n }\n if(x<=0){\n break;\n }\n ++pos\n }\n \n }\n console.log(arr.join(\"\"));\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\ntxt.shift();\nfor (let index = 0; index < txt.length; index += 2) {\n let info = txt[index].split(\" \")\n binary(info[1] * 1, txt[index+1])\n\n}\n\nfunction binary(x, tab) {\n let pos=0;\n let arr=new Array(tab.length).fill(1);\n for (let i = 0; i < tab.length; i++) {\n if(tab[i]==0){\n arr[i]=1;\n if(i-pos<=x){\n x-=Math.abs(pos-i);\n arr[pos]=0;\n }else{\n arr[i-x]=0;\n x=0;\n break;\n }\n ++pos\n }\n \n }\n console.log(arr.join(\"\"));\n}"}], "src_uid": "d4b6bea78b80b0a94646cbaf048b473f"} {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction isPossible(op, sum, arr, n, k) {\r\n\tvar pref = 0;\r\n\tfor (let i = n - 1; i > 0; i--) {\r\n\t\tvar extra = arr[i] - arr[0];\r\n\t\tpref += extra;\r\n\t\tif (sum - 1 <= k) return true;\r\n\t\top--;\r\n\t\tvar minSumPossible = sum - pref - op * (n - i + 1);\r\n\t\tif (minSumPossible <= k) return true;\r\n\t\tif (op == 0) return false;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nfunction solve() {\r\n\tvar [n, k] = readLine().trim().split(\" \").map(Number);\r\n\tvar arr = readLine().trim().split(\" \").map(Number);\r\n\tarr.sort((a, b) => a - b);\r\n\tvar sum = arr.reduce((ac, now) => ac + now, 0);\r\n\tif (sum <= k) return 0;\r\n\tif (n == 1) {\r\n\t\treturn arr[0] - k;\r\n\t}\r\n\t//sorry that line was written by mistake, wondering how it worked then?\r\n\t//var have a global lexical scope\r\n\tvar l = 1,\r\n\t\tr = 1e12;\r\n\twhile (l < r) {\r\n\t\tvar mid = Math.floor((l + r) / 2);\r\n\t\tif (isPossible(mid, sum, arr, n, k)) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid + 1;\r\n\t\t}\r\n\t}\r\n\treturn r;\r\n}\r\n\r\nfunction main() {\r\n\tvar t = +readLine();\r\n\twhile (t--) {\r\n\t\tconsole.log(solve());\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n arr.sort((a, b) => a - b)\n// console.log(arr)\n const sum = arr.reduce((s, x) => s + x, 0)\n if (sum <= k) return 0\n\n let b = 0\n let s = 0\n let ans = sum - k\n for (let i = arr.length - 1; i >= 1; i--) {\n b++\n s += arr[i] - arr[0]\n const d = sum - k - s\n // a + ab + s >= sum - k\n const a = d <= 0 ? 0 : Math.ceil(d / (b + 1))\n // console.log(s, d, a, b, (a + a * b + s))\n ans = Math.min(ans, a + b)\n }\n return ans\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\nconst calc = (n, k, a) => {\n a = a.sort((x, y) => x - y);\n let sum = 0;\n let pref = new Array(n).fill(0);\n let min = a[0];\n pref[0] = a[0];\n for (let i = 0; i < n; i++) {\n sum += a[i];\n if (i > 0) pref[i] = pref[i - 1] + a[i];\n }\n\n if (sum <= k) return 0;\n let result = sum - k;\n if (n === 1) return result;\n\n for (let swaps = 0; swaps < n; swaps++) {\n let firstSwapped = n - swaps;\n let othersum = pref[firstSwapped - 1] - pref[0];\n let targetNum = Math.floor((k - othersum) / (swaps + 1) + 0.0001);\n let minusops = a[0] - targetNum;\n result = Math.min(result, Math.max(minusops, 0) + swaps);\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, k] = ra();\n let a = ra();\n console.log(`${calc(n, k, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n; i++) sum += a[i];\r\n\t\tconst excess = Math.max(0, sum - k);\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet ans = 1e18;\r\n\t\tfor (let i = 1, vcur = 0; i <= n; i++) {\r\n\t\t\tconst d = Math.max(0, Math.ceil((excess - vcur) / i));\r\n\t\t\tans = Math.min(ans, d + i - 1);\r\n\t\t\tvcur += a[i-1] - a[n-1];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n a.sort((a,b) => (a - b));\r\n const sum = new Array(n);\r\n for(let i = 0; i < n; i++) {\r\n sum[i] = a[i];\r\n if (i > 0)\r\n sum[i] += sum[i - 1];\r\n }\r\n if (sum[n - 1] <= k) {\r\n console.log('0');\r\n continue;\r\n }\r\n let best = sum[n - 1] - k;\r\n for(let i = 1; i < n; i++) {\r\n let left = sum[i-1] - sum[0];\r\n let leftCount = n - (i - 1);\r\n let need = Math.floor((k - left) / leftCount);\r\n let try1 = 0;\r\n if (a[0] > need)\r\n try1 = a[0] - need;\r\n best = Math.min(best, try1 + n - i);\r\n }\r\n\r\n console.log(best);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction isPossible(op, sum, arr, n, k) {\r\n\tvar pref = 0;\r\n\tfor (let i = n - 1; i > 0; i--) {\r\n\t\tvar extra = arr[i] - arr[0];\r\n\t\tpref += extra;\r\n\t\tif (sum - 1 <= k) return true;\r\n\t\top--;\r\n\t\tvar minSumPossible = sum - pref - op * (n - i + 1);\r\n\t\tif (minSumPossible <= k) return true;\r\n\t\tif (op == 0) return false;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nfunction solve() {\r\n\tvar [n, k] = readLine().trim().split(\" \").map(Number);\r\n\tvar arr = readLine().trim().split(\" \").map(Number);\r\n\tarr.sort((a, b) => a - b);\r\n\tvar sum = arr.reduce((ac, now) => ac + now, 0);\r\n\tif (sum <= k) return 0;\r\n\tif (n == 1) {\r\n\t\treturn arr[0] - k;\r\n\t}\r\n\tif (sum - 1)\r\n\t\tvar l = 1,\r\n\t\t\tr = 1e12;\r\n\twhile (l < r) {\r\n\t\tvar mid = Math.floor((l + r) / 2);\r\n\t\tif (isPossible(mid, sum, arr, n, k)) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid + 1;\r\n\t\t}\r\n\t}\r\n\treturn r;\r\n}\r\n\r\nfunction main() {\r\n\tvar t = +readLine();\r\n\twhile (t--) {\r\n\t\tconsole.log(solve());\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction isPossible(op, sum, arr, n, k) {\r\n\tvar pref = 0;\r\n\tfor (let i = n - 1; i > 0; i--) {\r\n\t\tvar extra = arr[i] - arr[0];\r\n\t\tpref += extra;\r\n\t\tif (sum - 1 <= k) return true;\r\n\t\top--;\r\n\t\tvar minSumPossible = sum - pref - op * (n - i + 1);\r\n\t\tif (minSumPossible <= k) return true;\r\n\t\tif (op == 0) return false;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nfunction solve() {\r\n\tvar [n, k] = readLine().trim().split(\" \").map(Number);\r\n\tvar arr = readLine().trim().split(\" \").map(Number);\r\n\tarr.sort((a, b) => a - b);\r\n\tvar sum = arr.reduce((ac, now) => ac + now, 0);\r\n\tif (sum <= k) return 0;\r\n\tif (n == 1) {\r\n\t\treturn arr[0] - k;\r\n\t}\r\n\tif (sum - 1)\r\n\t\tvar l = 1,\r\n\t\t\tr = 1e9;\r\n\twhile (l < r) {\r\n\t\tvar mid = Math.floor((l + r) / 2);\r\n\t\tif (isPossible(mid, sum, arr, n, k)) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid + 1;\r\n\t\t}\r\n\t}\r\n\treturn r;\r\n}\r\n\r\nfunction main() {\r\n\tvar t = +readLine();\r\n\twhile (t--) {\r\n\t\tconsole.log(solve());\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction isPossible(op, sum, arr, n, k) {\r\n\tvar pref = 0;\r\n\tfor (let i = n - 1; i > 0; i--) {\r\n\t\tvar extra = arr[i] - arr[0];\r\n\t\tpref += extra;\r\n\t\top--;\r\n\t\tvar minSumPossible = sum - pref - op * (n - i + 1);\r\n\r\n\t\tif (minSumPossible <= k) return true;\r\n\t\tif (op == 0) return false;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nfunction solve() {\r\n\tvar [n, k] = readLine().trim().split(\" \").map(Number);\r\n\tvar arr = readLine().trim().split(\" \").map(Number);\r\n\tarr.sort((a, b) => a - b);\r\n\tvar sum = arr.reduce((ac, now) => ac + now, 0);\r\n\tif (sum <= k) return 0;\r\n\tif (n == 1) {\r\n\t\treturn arr[0] - k;\r\n\t}\r\n\tvar l = 1,\r\n\t\tr = 1e9;\r\n\twhile (l < r) {\r\n\t\tvar mid = Math.floor((l + r) / 2);\r\n\t\tif (isPossible(mid, sum, arr, n, k)) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid + 1;\r\n\t\t}\r\n\t}\r\n\treturn r;\r\n}\r\n\r\nfunction main() {\r\n\tvar t = +readLine();\r\n\twhile (t--) {\r\n\t\tconsole.log(solve());\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readLine() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction isPossible(op, sum, arr, n, k) {\r\n\tvar pref = 0;\r\n\tfor (let i = n - 1; i > 0; i--) {\r\n\t\tvar extra = arr[i] - arr[0];\r\n\t\tpref += extra;\r\n\t\top--;\r\n\t\tvar minSumPossible = sum - pref - op * (n - i + 1);\r\n\r\n\t\tif (minSumPossible <= k) return true;\r\n\t\tif (op == 0) return false;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nfunction solve() {\r\n\tvar [n, k] = readLine().trim().split(\" \").map(Number);\r\n\tvar arr = readLine().trim().split(\" \").map(Number);\r\n\tarr.sort((a, b) => a - b);\r\n\tvar sum = arr.reduce((ac, now) => ac + now, 0);\r\n\tif (sum <= k) return 0;\r\n\r\n\tvar l = 1,\r\n\t\tr = 1e9;\r\n\twhile (l < r) {\r\n\t\tvar mid = Math.floor((l + r) / 2);\r\n\t\tif (isPossible(mid, sum, arr, n, k)) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid + 1;\r\n\t\t}\r\n\t}\r\n\treturn r;\r\n}\r\n\r\nfunction main() {\r\n\tvar t = +readLine();\r\n\twhile (t--) {\r\n\t\tconsole.log(solve());\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n arr.sort((a, b) => a - b)\n// console.log(arr)\n const sum = arr.reduce((s, x) => s + x, 0)\n if (sum <= k) return 0\n\n let b = 0\n let s = 0\n let ans = sum - k\n for (let i = arr.length - 1; i >= 1; i--) {\n b++\n s += arr[i] - arr[0]\n const d = sum - k - s\n // a + ab + s >= sum - k\n const a = Math.ceil(d / (b + 1))\n // console.log(s, d, a, b, (a + a * b + s))\n ans = Math.min(ans, a + b)\n }\n return ans\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n arr.sort((a, b) => a - b)\n// console.log(arr)\n const sum = arr.reduce((s, x) => s + x, 0)\n if (sum <= k) return 0\n\n let b = 0\n let s = 0\n let ans = sum - k\n for (let i = arr.length - 1; i >= 1; i--) {\n b++\n const d = sum - k - s\n // a + ab + s >= sum - k\n const a = Math.floor(d / (b + 1))\n // console.log(s, d, a, b)\n ans = Math.min(ans, a + b)\n\n s += arr[i] - arr[0]\n }\n return ans\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\nconst calc = (n, k, a) => {\n a = a.sort((x, y) => x - y);\n let sum = 0;\n let pref = new Array(n).fill(0);\n let min = a[0];\n pref[0] = a[0];\n for (let i = 0; i < n; i++) {\n sum += a[i];\n if (i > 0) pref[i] = pref[i - 1] + a[i];\n }\n\n if (sum <= k) return 0;\n let result = sum - k;\n if (n === 1) return result;\n\n for (let swaps = 0; swaps < n; swaps++) {\n let firstSwapped = n - swaps;\n let othersum = pref[firstSwapped - 1] - pref[0];\n let targetNum = Math.floor((k - othersum) / (swaps + 1) + 0.0001);\n let minusops = a[0] - targetNum;\n result = Math.min(result, minusops + swaps);\n }\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let [n, k] = ra();\n let a = ra();\n console.log(`${calc(n, k, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "aec97dc779ba6b1d291fb1031dab93a7"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [l, r] = rna();\r\n\r\n\t\tfunction countChanges (n) {\r\n\t\t\tlet res = 0, k = 0;\r\n\t\t\twhile (n) {\r\n\t\t\t\tk = k * 10 + 1;\r\n\t\t\t\tres += n % 10 * k;\r\n\t\t\t\tn = Math.floor(n / 10);\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tconst ans = countChanges(r) - countChanges(l);\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n const dp = [1, 11];\r\n for (let i = 2; i <= 9; i++) {\r\n dp[i] = dp[i - 1] * 10 + 1;\r\n }\r\n let res = 0,\r\n t = m;\r\n for (let i = 9; i >= 0; i--) {\r\n const j = Math.floor(t / 10 ** i);\r\n res += dp[i] * j;\r\n t -= 10 ** i * j;\r\n }\r\n t = n;\r\n for (let i = 9; i >= 0; i--) {\r\n const j = Math.floor(t / 10 ** i);\r\n res -= dp[i] * j;\r\n t -= 10 ** i * j;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n console.log(solve(lines[l++].split(' ')));\n }\n});\n \nfunction solve([a, b]) {\n return f(b) - f(a)\n}\n\nfunction f(str) {\n const chs = str.split('').reverse().map(Number)\n let base = 10 + 1\n const factor = [0] // for 10^i\n for (let i = 0; i < chs.length; i++) {\n factor.push(base)\n base = base * 10 + 1\n }\n\n let sum = 0\n for (let i = 0; i < chs.length; i++) {\n const x = chs[i]\n if (i) {\n sum += x * factor[i]\n } else {\n sum += x\n }\n }\n return sum\n}\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\t\r\n\t\tvar lr = readNumArray();\r\n\t\t\r\n\t\tvar n1 = lr[0];\r\n\t\tvar n2 = lr[1];\r\n\t\t\r\n\t\tvar digits = 0;\r\n\t\t\r\n\t\twhile(n1 !== 0 || n2 !== 0){\r\n\t\t\tdigits = digits + (n2 - n1);\r\n\t\t\tn1 = Math.floor(n1/10);\r\n\t\t\tn2 = Math.floor(n2/10);\r\n\t\t}\r\n\t\t\r\n\t\tprint(digits);\r\n\t\t\r\n\t}\r\n}\r\n\r\nmain();"}], "negative_code": [], "src_uid": "7a51d536d5212023cc226ef1f6201174"} {"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n for (var i = 0; i < testCases; i++) {\n var numbers = readLine()\n .split(\" \")\n .map(num => parseInt(num));\n\n var rows = numbers[0];\n var columns = numbers[1];\n var rowsAvaiable = Array(rows).fill(true);\n var columnsAvaiable = Array(columns).fill(true);\n\n for (let j = 0; j < rows; j++) {\n readLine()\n .split(\" \")\n .map(num => parseInt(num))\n .forEach((number, index) => {\n // console.log(number, index);\n if (number == 1) {\n rowsAvaiable[j] = false;\n columnsAvaiable[index] = false;\n }\n });\n }\n console.log(\n Math.min(\n rowsAvaiable.filter(value => value == true).length,\n columnsAvaiable.filter(value => value == true).length\n ) % 2 ? \"Ashish\" : \"Vivek\"\n );\n }\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n\n var myCount1 = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) myCount1++;\n }\n\n var myCount2 = 0;\n for (var i = 0; i < m; i++) {\n if (col[i] == 1) myCount2++;\n }\n\n if (Math.min(myCount1, myCount2) % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n}\n"}, {"source_code": "var t = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n\nvar step = () => {\n var inp = readline().split(\" \").map(function(x) { return parseInt(x); });\n var n = inp[0];\n var m = inp[1];\n var rows = new Array(n);\n var columns = new Array(m);\n\n for(var i1 = 0; i1 < n; i1++){\n rows [i1] = 0;\n }\n for(var j1 = 0; j1 < m; j1++){\n columns[j1] = 0;\n }\n\n\n for(var i = 0; i < n; i++){\n var row = readline().split(\" \").map(function(x) { return parseInt(x); });\n for(var j = 0; j < m; j++){\n if(row[j] == 1){\n columns[j] = 1;\n rows[i] = 1;\n }\n }\n }\n\n var freeRows = rows.reduce((p, c) => c == 1 ? p : p+1, 0);\n var freeColumnss = columns.reduce((p, c) => c == 1 ? p : p+1, 0);\n\n var minV = Math.min(freeColumnss, freeRows);\n\n if(minV % 2 == 0){\n print(\"Vivek\")\n }\n else{\n print(\"Ashish\")\n }\n\n}\n\nfor(var i2 = 0; i2 < t; i2++){\n step();\n}"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nm = readNumArray();\n var n = nm[0];\n var m = nm[1];\n var nC = new Set();\n var mC = new Set();\n for (var j = 0; j < n; j++) {\n var currN = readNumArray();\n for (var k = 0; k < m; k++) {\n if (currN[k]) {\n mC.add(k);\n nC.add(j);\n }\n }\n }\n var steps = Math.min(n - nC.size, m - mC.size);\n\n print(steps % 2 ? \"Ashish\" : \"Vivek\");\n }\n}\n\nmain();"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInt()\n while (t--) {\n const [n, m] = rc.readInts()\n const a = new Array(n)\n let count1 = 0\n for(let i = 0; i < n; i++) {\n a[i] = rc.readInts()\n let x = a[i].includes(1)\n if(x) count1++\n }\n\n let count2 = 0\n for(let i = 0; i < m; i++) {\n for(let j = 0; j < n; j++) {\n if(a[j][i] === 1) {\n count2++\n break\n }\n }\n }\n\n let diff = Math.min(n - count1, m - count2)\n\n // wr(count1, count2)\n\n if((diff & 1) === 0) wr('Vivek')\n else wr('Ashish')\n }\n\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar used = new Set();\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = nextStrArray();\n\t\t}\n\t\tvar turn = true;//true:Asish,false:Vivek\n\t\twhile(true){\n\t\t\tif(turn){\n\t\t\t\tvar isChange = false;\n\t\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\t\tif(isChange){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\t\tif(isChange){\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(list[j][k] == \"0\"){\n\t\t\t\t\t\t\tvar isNG = false;\n\t\t\t\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\t\t\t\tif(list[l][k] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor(var l = 0; l < M; l++){\n\t\t\t\t\t\t\t\tif(list[j][l] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(!isNG){\n\t\t\t\t\t\t\t\tlist[j][k] = \"1\";\n\t\t\t\t\t\t\t\tisChange = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(isChange){\n\t\t\t\t\tturn = false;\n\t\t\t\t}else{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tvar isChange = false;\n\t\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\t\tif(isChange){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\t\tif(isChange){\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(list[j][k] == \"0\"){\n\t\t\t\t\t\t\tvar isNG = false;\n\t\t\t\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\t\t\t\tif(list[l][k] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor(var l = 0; l < M; l++){\n\t\t\t\t\t\t\t\tif(list[j][l] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(!isNG){\n\t\t\t\t\t\t\t\tlist[j][k] = \"1\";\n\t\t\t\t\t\t\t\tisChange = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(isChange){\n\t\t\t\t\tturn = true;\n\t\t\t\t}else{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(turn){\n\t\t\toutput[i] = \"Vivek\";\n\t\t}else{\n\t\t\toutput[i] = \"Ashish\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 1;\n let i = 0;\n while (i < testCases) {\n let int = data.shift().split(' ');\n let col = int[1] * 1;\n let row = int[0] * 1;\n let arr = [];\n let player = 0;\n let idxC = {};\n for (let j = 0; j < row; j += 1) arr.push(data.shift().slice(0, -1).split(' '));\n for (let j = 0; j < arr.length; j += 1) {\n let idx = arr[j].indexOf('1');\n if (idx < 0) {\n let k = 0;\n i1:\n while (k < col) {\n if (!idxC[k]) {\n let check = true;\n for (let r = 0; r < row; r += 1) {\n if (arr[r][k] === '1') {idxC[k] = 1; k += 1; continue i1;}\n }\n arr[j][k] = '1';\n idxC[k] = 1;\n player += 1;\n break;\n }\n k += 1;\n }\n } else idxC[idx] = 1;\n }\n const result = (player & 1) === 0 ? 'Vivek' : 'Ashish';\n console.log(result);\n i += 1;\n }\n}"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i +x)\n const l = {x: new Array(m).fill(0), y: new Array(n).fill(0)}\n let it = 0\n acc++\n while(it +x)\n for (let i =0; i r+x, 0)\n const sumY = l.y.reduce((r, x) => r+x, 0)\n const pos = Math.min(n - sumY, m - sumX)\n console.log(pos % 2 === 0? 'Vivek' : 'Ashish')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n init = true,\n n = 0,\n m = 0,\n r, u, w\n\nfunction initMatrix(line) {\n const size = line.split(\" \").map(x => parseInt(x,10))\n u = new Set()\n w = new Set()\n n = size[0]\n m = size[1]\n r = 0\n init = false\n}\n\nfunction inputRow(line) {\n for (let c=0;c<2*m;c=c+2) {\n if (line[c] == \"1\") {\n u.add(r)\n w.add(c)\n }\n }\n if (++r == n) {\n n -= u.size\n m -= w.size\n\n console.log((m < n ? m : n)%2 == 1 ? \"Ashish\":\"Vivek\")\n init = --N == 0 ? rl.close() : true\n }\n}\n\nfunction loop(line) {\n if (line.trim() == \"\") return\n (init ? initMatrix : inputRow)(line)\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", loop)\n})\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n\n var myCount1 = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) myCount1++;\n }\n\n var myCount2 = 0;\n for (var i = 0; i < n; i++) {\n if (col[i] == 1) myCount2++;\n }\n\n if (Math.min(myCount1, myCount2) % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n\n if (n <= m) {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) myCount++;\n }\n } else {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (col[i] == 1) myCount++;\n }\n }\n if (n == 1 || m == 1) {\n if (myCount == 0) print(\"Vivek\");\n else print(\"Ashish\");\n } else {\n if (myCount % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n if (n >= m) {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) myCount++;\n }\n } else {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (col[i] == 1) myCount++;\n }\n }\n\n if (myCount % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n if (n <= m) {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) myCount++;\n }\n } else {\n var myCount = 0;\n for (var i = 0; i < n; i++) {\n if (col[i] == 1) myCount++;\n }\n }\n\n if (myCount % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nm = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nm[0],\n m = nm[1];\n var cells = [];\n var rows = new Array(n).fill(1);\n var col = new Array(m).fill(1);\n for (var i = 0; i < n; i++) {\n var r = readline()\n .split(\" \")\n .map((val, ind) => {\n val = parseInt(val);\n if (val == 1) {\n rows[i] = 0;\n col[ind] = 0;\n return val;\n }\n });\n }\n var count1 = 0;\n for (var i = 0; i < n; i++) {\n if (rows[i] == 1) count1++;\n }\n var count2 = 0;\n for (var i = 0; i < n; i++) {\n if (col[i] == 1) count2++;\n }\n var myCount = Math.min(count1, count2);\n if (myCount % 2 == 0) print(\"Vivek\");\n else print(\"Ashish\");\n}\n"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInt()\n while (t--) {\n const [n, m] = rc.readInts()\n const a = new Array(n)\n let count = 0\n for(let i = 0; i < n; i++) {\n a[i] = rc.readInts()\n let x = a[i].includes(1)\n if(x) count++\n }\n\n let diff = n - count\n\n // wr(count)\n\n if((diff & 1) === 0) wr('Vivek')\n else wr('Ashish')\n }\n\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar used = new Set();\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = nextStrArray();\n\t\t}\n\t\tvar turn = true;//true:Asish,false:Vivek\n\t\twhile(true){\n\t\t\tif(turn){\n\t\t\t\tvar isChange = false;\n\t\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\t\tif(isChange){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\t\tif(isChange){\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(list[j][k] == \"0\"){\n\t\t\t\t\t\t\tvar isNG = false;\n\t\t\t\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\t\t\t\tif(list[l][k] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor(var l = 0; l < M; l++){\n\t\t\t\t\t\t\t\tif(list[j][l] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(!isNG){\n\t\t\t\t\t\t\t\tlist[j][k] = \"1\";\n\t\t\t\t\t\t\t\tisChange = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(isChange){\n\t\t\t\t\tturn = false;\n\t\t\t\t}else{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tvar isChange = false;\n\t\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\t\tif(isChange){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\t\tif(isChange){\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(list[j][k] == \"0\"){\n\t\t\t\t\t\t\tvar isNG = false;\n\t\t\t\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\t\t\t\tif(list[l][k] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor(var l = 0; l < M; l++){\n\t\t\t\t\t\t\t\tif(list[j][l] == \"1\"){\n\t\t\t\t\t\t\t\t\tisNG = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(!isNG){\n\t\t\t\t\t\t\t\tlist[j][k] = \"1\";\n\t\t\t\t\t\t\t\tisChange = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(isChange){\n\t\t\t\t\tturn = true;\n\t\t\t\t}else{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(turn){\n\t\t\toutput[i] = \"Vivek\";\n\t\t}else{\n\t\t\toutput[i] = \"Asish\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n init = true,\n n = 0,\n m = 0,\n r, u, w\n\nfunction initMatrix(line) {\n const size = line.split(\" \").map(x => parseInt(x,10))\n u = new Set()\n w = new Set()\n n = size[0]\n m = size[1]\n r = 0\n init = false\n}\n\nfunction inputRow(line) {\n for (let c=0;c<2*m;c=c+2) {\n if (line[c] == \"1\") {\n u.add(r)\n w.add(c)\n }\n }\n if (++r == n) {\n n -= u.size\n m -= w.size\n console.log(n == 1 || m == 1 || (n-n%m)%2 == 1 ? \"Ashish\":\"Vivek\")\n init = --N == 0 ? rl.close() : true\n }\n}\n\nfunction loop(line) {\n if (line.trim() == \"\") return\n (init ? initMatrix : inputRow)(line)\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", loop)\n})\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nvar N = null,\n init = true,\n n = 0,\n m = 0,\n r, u, w\n\nfunction initMatrix(line) {\n const size = line.split(\" \").map(x => parseInt(x,10))\n u = new Set()\n w = new Set()\n n = size[0]\n m = size[1]\n r = 0\n init = false\n}\n\nfunction inputRow(line) {\n for (let c=0;c<2*m;c=c+2) {\n if (line[c] == \"1\") {\n u.add(r)\n w.add(c)\n }\n }\n if (++r == n) {\n n -= u.size\n m -= w.size\n console.log(n != 0 && m != 0 && (n == 1 || m == 1 || (n-n%m)%2 == 1) ? \"Ashish\":\"Vivek\")\n init = --N == 0 ? rl.close() : true\n }\n}\n\nfunction loop(line) {\n if (line.trim() == \"\") return\n (init ? initMatrix : inputRow)(line)\n}\n\nrl.question(\"\", line => {\n N = parseInt(line,10)\n rl.on(\"line\", loop)\n})\n"}], "src_uid": "3ccc98190189b0c8e58a96dd5ad1245d"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const m = Array(n).fill(0)\n .map(() => [])\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n const y = i + x\n // m[y] = m[y] || []\n if (i + x < n) {\n m[y].push(x)\n }\n }\n const dp = Array(n).fill(0)\n if (arr[0] < n) dp[arr[0]] = 1\n// console.log(m)\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === i) {\n dp[i] = 1\n continue\n }\n // dp[i] |= dp[i - arr[i]] || 0\n dp[i] |= dp[i - arr[i] - 1] || 0\n for (let j = 0; j < m[i].length; j++) {\n // dp[i] |= dp[m[i][j]] || 0\n dp[i] |= dp[i - m[i][j] - 1] || 0\n // console.log(i, dp[i - m[i][j] - 1], i - m[i][j] - 1)\n }\n }\n// console.log(dp)\n return dp[n - 1] ? 'YES' : 'NO'\n}\n", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar dp = [];\r\n\tfor(var i=0;i<=n;i++) dp[i] = 0;\r\n\tdp[0] = 1;\r\n\tfor(var i=1;i<=n;i++) {\r\n\t\tif(i-a[i-1] > -1 && dp[i-a[i-1]-1]) dp[i] = 1;\r\n\t\tif(i+a[i-1] <= n && dp[i-1]) dp[i+a[i-1]] = 1;\r\n\t}\r\n\tconsole.log(dp[n] ? \"Yes\" : \"No\")\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = [];\r\n for (let i = 0; i < n; i++) {\r\n a[i + 1] = rn();\r\n }\r\n const dp = new Array(n + 1).fill(false);\r\n dp[0] = true;\r\n for (let i = 1; i <= n; i++) {\r\n dp[i] = dp[i] || !!dp[i - a[i] - 1];\r\n if (dp[i - 1] && i + a[i] <= n) dp[i + a[i]] = true;\r\n }\r\n if (dp[n]) return 'YES';\r\n return 'NO';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const m = Array(n).fill(0)\n .map(() => [])\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n const y = i + x\n // m[y] = m[y] || []\n if (i + x < n) {\n m[y].push(x)\n }\n }\n const dp = Array(n).fill(0)\n if (arr[0] < n) dp[arr[0]] = 1\n// console.log(m)\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === i) {\n dp[i] = 1\n continue\n }\n dp[i] |= dp[i - arr[i]] || 0\n for (let j = 0; j < m[i].length; j++) {\n dp[i] |= dp[m[i][j]]\n }\n }\n// console.log(dp)\n return dp[n - 1] ? 'YES' : 'NO'\n}\n"}], "src_uid": "bde43491d2e5c0a27a63e283c0967a80"} {"source_code": "var dn = readline().split(\" \").map(e=>+e);var n =dn[1];var f = Number(readline());\n\t\n\nfor(var i=0;i+e)\nvar y1 = Math.abs(t[0]-n);\nvar y2 = t[0]+n;\t\t\nif(y2>dn[0]){y2= dn[0] - (y2-dn[0])}\n\nif((t[1]y2)){print(\"NO\");}else{print(\"YES\");}\n}\n", "positive_code": [{"source_code": "var input = readline().split(\" \").map(function(el) {return parseInt(el)});\nvar n = input[0];\nvar d = input[1];\nvar m = parseInt(readline());\nfor (var i = 0; i < m; i++) {\n var point = readline().split(\" \").map(function(el) {return parseInt(el)});\n var x = point[0];\n var y = point[1];\n if (y <= x + d && y <= (x*(-1)+2*n-d) && y >= x-d && y >= d-x)\n print(\"YES\");\n else\n print(\"NO\");\n}\n\n"}, {"source_code": "var input = readline().split(' ');\n\nvar n = Number(input[0]);\nvar d = Number(input[1]);\n\nvar points = [];\npoints.push([d,0]);\npoints.push([n, Math.abs(n-d)]);\npoints.push([Math.abs(n-d), n]);\npoints.push([0,d]);\n\nvar b = FindLength(points[0][0], points[1][0], points[0][1], points[1][1]);\nvar l = FindLength(points[1][0], points[2][0], points[1][1], points[2][1]);\n\nvar RectArea = Math.round(b*l);\n\nfunction FindLength(x1, x2, y1, y2) {\n return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));\n}\n\nfunction FindTriArea(p1, p2, p3) {\n return Math.abs(((p1[0]-p3[0])*(p2[1]-p1[1]) - (p1[0]-p2[0])*(p3[1]-p1[1]))/2);\n}\n\nvar m = Number(readline());\n\nfor(var i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let counts = Array(20).fill(0)\r\n readline().split(' ').map(x => {\r\n counts[Math.log2(x)] += 1\r\n })\r\n let ans = [m],\r\n maxNum = 0,\r\n index = 0\r\n // console.log('Counts = ', counts)\r\n while (n) {\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(counts, ans[ans.length - 1])\r\n maxNum = Math.pow(2, index)\r\n if (index == -1) {\r\n index = findGoodIndex(counts, m)\r\n maxNum = Math.pow(2, index)\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[ans.length - 1] -= maxNum \r\n }\r\n counts[index]--\r\n n--\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction sortAscending(a, b) {\r\n return a - b\r\n}\r\n\r\nfunction findGoodIndex(counts, leftOver) {\r\n let index = 20\r\n while (index >= 0) {\r\n if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {\r\n return index\r\n } else {\r\n index--\r\n }\r\n } \r\n return index\r\n}", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tconst cnt = Array(20).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[Math.log2(w[i])]++;\r\n\t\t}\r\n\r\n\t\tlet ans = 0, placed = 0;\r\n\t\tw.sort((x, y) => y - x);\r\n\t\twhile (placed < n) {\r\n\t\t\t++ans;\r\n\t\t\tlet avl = W; \r\n\t\t\twhile(1) {\r\n\t\t\t\tlet j;\r\n\t\t\t\tfor (j = 20; j >= 0; j--) {\r\n\t\t\t\t\tif (cnt[j] && 2**j <= avl) break;\r\n\t\t\t\t}\r\n\t\t\t\tif (j >= 0) avl -= 2**j, cnt[j]--, placed++; else break;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst mxq = new PriorityQueue((a, b) => a > b);\r\n\t\tw.sort((x, y) => y-x);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst avl = mxq.peek();\r\n\t\t\tif (avl >= w[i]) {\r\n\t\t\t\tmxq.pop();\r\n\t\t\t\tmxq.push(avl-w[i]);\r\n\t\t\t} else {\r\n\t\t\t\tmxq.push(W-w[i]);\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const x = readline();\r\n var toPrint = ''\r\n\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n var [n, w] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var b = new Array(1001).fill(0)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // console.log(a)\r\n for (let j = 0; j < n; j++) {\r\n var count = 0\r\n while (a[j] > 1) {\r\n a[j] = Math.floor(a[j] / 2)\r\n count++\r\n }\r\n b[count] = b[count] + 1\r\n }\r\n\r\n var res = 0\r\n while (true) {\r\n var sum = w\r\n for (let j = b.length - 1; j >= 0; j--) {\r\n if (b[j] === 0) continue\r\n var val = Math.pow(2, j)\r\n var x = Math.floor(sum / val)\r\n var take = Math.min(b[j], x)\r\n b[j] = b[j] - take\r\n sum = sum - take * val\r\n }\r\n if (sum === w) break\r\n res++\r\n }\r\n toPrint = toPrint + res + '\\n'\r\n })\r\n console.log(toPrint)\r\n\r\n // var b = a.sort((a, b) => Math.abs(a) - Math.abs(b))\r\n\r\n}\r\n\r\nfunction SUMnUMBER(x, y) {\r\n return Math.log(y) / Math.log(x);\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, w, a) => {\r\n a.sort((x, y) => x - y);\r\n let uc = uniqcount(a);\r\n let h = 0;\r\n while (1) {\r\n let end = 1;\r\n for (const e of uc) {\r\n if (e[1] != 0) end = 0;\r\n }\r\n if (end) break;\r\n h++;\r\n let rem = w;\r\n for (let i = uc.length - 1; ~i; i--) {\r\n let w = uc[i][0];\r\n let use = mi(rem / w >> 0, uc[i][1]);\r\n rem -= use * w;\r\n uc[i][1] -= use;\r\n }\r\n }\r\n pr(h);\r\n};\r\n\r\nconst uniqcount = (a) => {\r\n let n = a.length;\r\n let p = 0;\r\n let b = Array(n).fill(null);\r\n for (let i = 0; i < n; i++) {\r\n if (i == 0 || a[i] != a[i - 1]) b[p++] = [a[i], 0];\r\n b[p - 1][1]++;\r\n }\r\n return b.slice(0, p);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let counts = Array(20).fill(0)\r\n readline().split(' ').map(x => {\r\n counts[Math.log2(x)] += 1\r\n })\r\n let ans = [m],\r\n maxNum = 0,\r\n index = 0\r\n // console.log('Counts = ', counts)\r\n while (n) {\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(counts, ans[ans.length - 1])\r\n maxNum = Math.pow(2, index)\r\n if (index == -1) {\r\n maxNum = Math.pow(2, findGoodIndex(counts, m))\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[ans.length - 1] -= maxNum \r\n }\r\n counts[index]--\r\n n--\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction sortAscending(a, b) {\r\n return a - b\r\n}\r\n\r\nfunction findGoodIndex(counts, leftOver) {\r\n let index = 20\r\n while (index >= 0) {\r\n if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {\r\n return index\r\n } else {\r\n index--\r\n }\r\n } \r\n return index\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let counts = Array(20).fill(0)\r\n readline().split(' ').map(x => {\r\n counts[Math.log2(x)] += 1\r\n })\r\n let ans = [m],\r\n maxNum = 0,\r\n index = 0\r\n // console.log('Counts = ', counts)\r\n while (n) {\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(counts, ans[ans.length - 1])\r\n maxNum = Math.pow(2, index)\r\n if (index == -1) {\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[ans.length - 1] -= maxNum \r\n }\r\n counts[index]--\r\n n--\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction sortAscending(a, b) {\r\n return a - b\r\n}\r\n\r\nfunction findGoodIndex(counts, leftOver) {\r\n let index = 20\r\n while (index >= 0) {\r\n if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {\r\n return index\r\n } else {\r\n index--\r\n }\r\n } \r\n return index\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let counts = Array(20).fill(0)\r\n readline().split(' ').map(x => {\r\n counts[Math.log2(x)] += 1\r\n })\r\n let ans = [m],\r\n maxNum = 0,\r\n index = 0\r\n console.log('Counts = ', counts)\r\n while (n) {\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(counts, ans[ans.length - 1])\r\n maxNum = Math.pow(2, index)\r\n if (index == -1) {\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[ans.length - 1] -= maxNum \r\n }\r\n counts[index]--\r\n n--\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction sortAscending(a, b) {\r\n return a - b\r\n}\r\n\r\nfunction findGoodIndex(counts, leftOver) {\r\n let index = 20\r\n while (index >= 0) {\r\n if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {\r\n return index\r\n } else {\r\n index--\r\n }\r\n } \r\n return index\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let arr = readline().split(' ').map(x => +x)\r\n let ans = [],\r\n maxNum = 0,\r\n index = 0\r\n arr.sort(sortAscend)\r\n console.log('arr = ', ...arr)\r\n while (arr.length) {\r\n // find current max in arr => always the last\r\n maxNum = arr[arr.length - 1]\r\n // console.log('maxNum = ', maxNum)\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(maxNum, ans, m)\r\n if (index == ans.length) {\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[index] -= maxNum \r\n }\r\n // console.log('ans = ', ans)\r\n arr.pop()\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction sortAscend(a, b) {\r\n return a - b\r\n}\r\n\r\nfunction findGoodIndex(maxNum, arr, m) {\r\n let index = 0\r\n while (index < arr.length) {\r\n if (arr[index] >= maxNum) {\r\n return index\r\n }\r\n index++\r\n }\r\n return index\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main()\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++]\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n let testCases = readline()\r\n while (testCases--)\r\n solve()\r\n}\r\n\r\n// function to solve problems\r\nfunction solve() {\r\n let [n, m] = readline().split(' ')\r\n let arr = readline().split(' ').map(x => +x)\r\n let ans = [],\r\n maxNum = 0,\r\n index = 0\r\n arr.sort()\r\n while (arr.length) {\r\n // find current max in arr - always the last\r\n maxNum = arr[arr.length - 1]\r\n // better approach would be to store the maximum in order in the best possible way\r\n // greedy approach\r\n index = findGoodIndex(maxNum, ans, m)\r\n if (index == ans.length) {\r\n ans.push(m - maxNum)\r\n } else {\r\n ans[index] -= maxNum \r\n }\r\n arr.pop()\r\n }\r\n console.log(ans.length)\r\n}\r\n\r\nfunction findGoodIndex(maxNum, arr, m) {\r\n let index = 0\r\n while (index < arr.length) {\r\n if (arr[index] >= maxNum) {\r\n return index\r\n }\r\n index++\r\n }\r\n return index\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\t \r\nclass PriorityQueue {\r\n \r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t this.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t const parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t const left = i => (i << 1) + 1;\r\n\t const right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst mxq = new PriorityQueue((a, b) => a > b);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tw.sort((x, y) => y-x);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst avl = mxq.peek();\r\n\t\t\tif (avl >= w[i]) {\r\n\t\t\t\tavl && mxq.pop();\r\n\t\t\t\tmxq.push(avl-w[i]);\r\n\t\t\t} else {\r\n\t\t\t\tmxq.push(W-w[i]);\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\t \r\nclass PriorityQueue {\r\n \r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t this.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t const parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t const left = i => (i << 1) + 1;\r\n\t const right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst mxq = new PriorityQueue((a, b) => a > b);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tw.sort((x, y) => y-x);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst avl = mxq.peek();\r\n\t\t\tif (avl >= w[i]) {\r\n\t\t\t\tmxq.pop();\r\n\t\t\t\tmxq.push(avl-w[i]);\r\n\t\t\t} else {\r\n\t\t\t\tmxq.push(W-w[i]);\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\n// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\t \r\nclass PriorityQueue {\r\n \r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t this.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t const parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t const left = i => (i << 1) + 1;\r\n\t const right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nconst mxq = new PriorityQueue((a, b) => a > b);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tw.sort((x, y) => y-x);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst avl = mxq.pop();\r\n\t\t\tif (avl >= w[i]) {\r\n\t\t\t\tmxq.push(avl-w[i]);\r\n\t\t\t} else {\r\n\t\t\t\tmxq.push(W-w[i]);\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction pow (b, i) {\r\n\tif (!i) return 1;\r\n\treturn b * pow(b, i - 1);\r\n}\r\n\r\nfunction indx (n) {\r\n\tfor (let i = 0; i <= 30; i++) {\r\n\t\tconst pw = 1 << i;\r\n\t\tif (n & pw) return i;\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, W] = rna();\r\n\t\tconst w = rna();\r\n\r\n\t\tw.sort((x, y) => y - x);\r\n\r\n\t\tconst used = Array(31).fill(-1);\r\n\t\tfor (let i = 0; i <= 30; i++) {\r\n\t\t\tconst pw = 1 << i;\r\n\t\t\tif (W & pw) {\r\n\t\t\t\tused[i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet b = indx(w[i]);\r\n\t\t\tlet done = false;\r\n\t\t\tfor (let j = 30; j >= 0; j--) {\r\n\t\t\t\tif (used[j] >= 0) {\r\n\t\t\t\t\tif (w[i] <= used[j] % pow(2, j)) {\r\n\t\t\t\t\t\tused[j] += w[i];\r\n\t\t\t\t\t\tdone = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t} \r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!done) {\r\n\t\t\t\tif (used[b] >= 0) {\r\n\t\t\t\t\tused[b] += w[i];\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfor (let j = 30; j >= 0; j--) {\r\n\t\t\t\t\t\tif (used[j] >= 0) {\r\n\t\t\t\t\t\t\tused[j] += w[i];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i <= 30; i++) {\r\n\t\t\tans = Math.max(ans, Math.ceil(used[i] / pow(2, i)));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, w, a) => {\r\n let m = new Map();\r\n for (const e of a) m.set(e, m.get(e) + 1 || 1);\r\n let max = mx.apply(Math, a);\r\n pr(m.get(max))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, w, a) => {\r\n let sum = a.reduce((x, y) => x + y);\r\n pr(ce(sum / w))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "49ba9921ae8b6bc53726e7a521eefe39"} {"source_code": "function solve() {\r\n const n = Number(read());\r\n const a = readArray(Number);\r\n const b = [];\r\n const odd = (n & 1);\r\n for (let i = 0; i < n - odd; i++) {\r\n if (i & 1) {\r\n b.push(-a[i - 1]);\r\n continue;\r\n }\r\n b.push(a[i + 1]);\r\n }\r\n if (odd) {\r\n const end = [n - 3, n - 2, n - 1];\r\n while(a[end[0]] + a[end[1]] === 0) {\r\n end.push(end.shift());\r\n }\r\n b[end[0]] = a[end[2]];\r\n b[end[1]] = a[end[2]];\r\n b[end[2]] = - a[end[0]] - a[end[1]];\r\n }\r\n write(b.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i+=2) {\r\n\t\t\tb.push(a[i+1], -a[i]);\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\tconst c = a.slice(-3);\r\n\t\t\tif (c[0] + c[1] != 0 && b.length < n) b.push(c[2], c[2], -(c[0]+c[1]));\r\n\t\t\tif (c[0] + c[2] != 0 && b.length < n) b.push(c[1], -(c[0]+c[2]), c[1]);\r\n\t\t\tif (c[1] + c[2] != 0 && b.length < n) b.push(-(c[1]+c[2]), c[0], c[0]);\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction rotateLeft (ar, k) {\r\n\twhile (k--) ar.push(ar.shift());\r\n}\r\n\r\nfunction rotateRight (ar, k) {\r\n\twhile (k--) ar.unshift(ar.pop());\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i++) {\r\n\t\t\tif (i&1) {\r\n\t\t\t\tb.push(-a[i-1])\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\tconst c = a.slice(-3);\r\n\t\t\tfor (let i = 0; i < 3; i++) {\r\n\t\t\t\tif (c[0] + c[1] != 0) {\r\n\t\t\t\t\tconst res = [c[2], c[2], -(c[0]+c[1])];\r\n\t\t\t\t\trotateRight(res, i);\r\n\t\t\t\t\tb.push(...res);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\trotateLeft(c, 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i++) {\r\n\t\t\tif (i&1) {\r\n\t\t\t\tb.push(-a[i-1])\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\tlet x = a[n-3], y = a[n-2], z = a[n-1], flg;\r\n\t\t\tif (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {\r\n\t\t\t\tb.push(x > 0 ? 1 : -1);\r\n\t\t\t\tb.push(y > 0 ? 1 : -1);\r\n\t\t\t\tb.push(z > 0 ? -2 : 2);\r\n\t\t\t} else { \r\n\t\t\t\tif (Math.abs(x) == Math.abs(y)) [y, z] = [z, y], flg = 1;\r\n\t\t\t\tif (x * y < 0) {\r\n\t\t\t\t\tb.push(z, z, -(x + y));\r\n\t\t\t\t} else {\r\n\t\t\t\t\tb.push(z, -z, -(x - y));\r\n\t\t\t\t}\r\n\t\t\t\tif (flg) b.push(b.pop(), b.pop());\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 2) return `${a[1]} ${-a[0]}`;\r\n const res = [];\r\n for (let i = 0; i < n - 1; i += 2) {\r\n res[i] = a[i + 1];\r\n res[i + 1] = -a[i];\r\n }\r\n if (n % 2 === 0) return res.join(' ');\r\n const [x, y, z] = a.slice(-3);\r\n if (x + y === 0) {\r\n res[n - 3] = z;\r\n res[n - 2] = 2 * z;\r\n res[n - 1] = -(x + 2 * y);\r\n } else {\r\n res[n - 3] = z;\r\n res[n - 2] = z;\r\n res[n - 1] = -(x + y);\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const ans = []\n const limit = (n & 1) ? n - 3 : n\n for (let i = 0; i < limit; i += 2) {\n ans[i] = -arr[i + 1]\n ans[i + 1] = arr[i]\n }\n if (n & 1) {\n const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])\n return ans.concat(rest).join(' ')\n } else {\n return ans.join(' ')\n }\n}\nfunction helper(a, b, c) {\n if (a === b && b === c) {\n return [1, 1, -2]\n } else if (a === b) {\n // return [c, c, 2 * a]\n if (c & 1) {\n if (c === 1) {\n return [-1, 2, -a]\n } else if (c === -1) {\n return [-2, 1, -a]\n }\n return [(c - 1) / 2, (c + 1) / 2, -a]\n } else {\n return [c / 2, c / 2, -a]\n }\n } else if (b === c) {\n if (a & 1) {\n if (a === 1) {\n return [-b, -1, 2]\n } else if (a === -1) {\n return [-b, -2, 1]\n }\n return [-b, (a - 1) / 2, (a + 1) / 2]\n } else {\n return [-b, a / 2, a / 2]\n }\n } else if (a === c) {\n if (b & 1) {\n if (b === 1) {\n return [-1, -a, 2]\n } else if (b === -1) {\n return [-2, -a, 1]\n }\n return [(b - 1) / 2, -a, (b + 1) / 2]\n } else {\n return [b / 2, -a, b / 2]\n }\n }\n let d\n d = a - b\n if (Math.abs(d) < 1e4) {\n return [c, -c, -d]\n }\n d = a - c\n if (Math.abs(d) < 1e4) {\n return [b, -d, -b]\n }\n d = b - c\n return [-d, a, -a]\n}\n"}], "negative_code": [{"source_code": "function solve() {\r\n const n = Number(read());\r\n const a = readArray(Number);\r\n const b = [];\r\n const odd = (n & 1);\r\n for (let i = 0; i < n - odd; i++) {\r\n if (i & 1) {\r\n b.push(-a[i - 1]);\r\n continue;\r\n }\r\n b.push(a[i + 1]);\r\n }\r\n if (odd) {\r\n b[n - 3] = a[n - 1];\r\n b[n - 2] = a[n - 1];\r\n b[n - 1] = -a[n - 2] - a[n - 3];\r\n }\r\n write(b.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = 0;\r\n let minAbsIndex = -1;\r\n let jopa = 0;\r\n const a = readArray((value, index) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n const curJopa = pDivCount(curAbsA);\r\n if (curJopa > jopa) {\r\n jopa = curJopa;\r\n minAbsA = curA;\r\n minAbsIndex = index;\r\n }\r\n return curA;\r\n });\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n /*let xxx = 0;\r\n for (let i = 0; i < n; i++) {\r\n xxx += Math.abs(b[i]);\r\n }\r\n write(xxx);*/\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = 0;\r\n let minAbsIndex = -1;\r\n let jopa = 0;\r\n const a = readArray((value, index) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n const curJopa = pDivCount(curAbsA);\r\n if (curJopa > jopa || curJopa === jopa && curAbsA < minAbsA) {\r\n jopa = curJopa;\r\n minAbsA = curA;\r\n minAbsIndex = index;\r\n }\r\n return curA;\r\n });\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n /*let xxx = 0;\r\n for (let i = 0; i < n; i++) {\r\n xxx += Math.abs(b[i]);\r\n }\r\n write(xxx);*/\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n if (n % i !== 0) {\r\n continue;\r\n }\r\n ans++;\r\n while(n % i === 0) {\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = 0;\r\n let minAbsIndex = -1;\r\n const a = readArray((value, index) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n if (curAbsA > minAbsA) {\r\n minAbsA = curA;\r\n minAbsIndex = index;\r\n }\r\n return curA;\r\n });\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n /*let xxx = 0;\r\n for (let i = 0; i < n; i++) {\r\n xxx += a[i] * b[i];\r\n }\r\n write(xxx);*/\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = Infinity;\r\n let minAbsIndex = -1;\r\n let glcm = 1;\r\n const a = readArray((value) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n glcm = lcm(glcm, curAbsA);\r\n return curA;\r\n });\r\n for (let i = 0; i < n; i++) {\r\n const x = Math.floor(glcm / Math.abs(a[i]));\r\n if (x < minAbsA) {\r\n minAbsA = x;\r\n minAbsIndex = i;\r\n }\r\n }\r\n minAbsA = Math.abs(a[minAbsIndex]);\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n /*let xxx = 0;\r\n for (let i = 0; i < n; i++) {\r\n xxx += a[i] * b[i];\r\n }\r\n write(xxx);*/\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = Infinity;\r\n let minAbsIndex = -1;\r\n let glcm = 1;\r\n const a = readArray((value) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n glcm = lcm(glcm, curAbsA);\r\n return curA;\r\n });\r\n for (let i = 0; i < n; i++) {\r\n const x = Math.floor(glcm / Math.abs(a[i]));\r\n if (x < minAbsA) {\r\n minAbsA = x;\r\n minAbsIndex = i;\r\n }\r\n }\r\n minAbsA = Math.abs(a[minAbsIndex]);\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n let xxx = 0;\r\n for (let i = 0; i < n; i++) {\r\n xxx += Math.abs(b[i]);\r\n }\r\n write(xxx);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n let minAbsA = Infinity;\r\n let minAbsIndex = -1;\r\n const a = readArray((value, index) => {\r\n const curA = Number(value);\r\n const curAbsA = Math.abs(curA);\r\n if (curAbsA < minAbsA) {\r\n minAbsA = curA;\r\n minAbsIndex = index;\r\n }\r\n return curA;\r\n });\r\n const b = [];\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (i === minAbsIndex) {\r\n continue;\r\n }\r\n const x = lcm(Math.abs(a[i]), minAbsA);\r\n sum += x;\r\n b[i] = Math.floor(x / a[i]);\r\n }\r\n b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);\r\n write(b.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i++) {\r\n\t\t\tif (i&1) {\r\n\t\t\t\tb.push(-a[i-1])\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\tlet x = a[n-3], y = a[n-2], z = a[n-3];\r\n\t\t\tif (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {\r\n\t\t\t\tif (x > 0) b.push(1); else b.push(-1);\r\n\t\t\t\tif (y > 0) b.push(1); else b.push(-1);\r\n\t\t\t\tif (z > 0) b.push(-2); else b.push(2);\r\n\t\t\t} else if (Math.abs(x) == Math.abs(y)) {\r\n\t\t\t\tif (x * z < 0) {\r\n\t\t\t\t\tb.push(y, -(x + z), y);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tb.push(y, -(x - z), -y);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (x * y < 0) {\r\n\t\t\t\t\tb.push(z, z, -(x + y));\r\n\t\t\t\t} else {\r\n\t\t\t\t\tb.push(z, -z, -(x - y));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i++) {\r\n\t\t\tif (i&1) {\r\n\t\t\t\tb.push(-a[i-1])\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\tlet x = a[n-3], y = a[n-2], z = a[n-3];\r\n\t\t\tif (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {\r\n\t\t\t\tif (x > 0) b.push(1); else b.push(-1);\r\n\t\t\t\tif (y > 0) b.push(1); else b.push(-1);\r\n\t\t\t\tif (z > 0) b.push(-2); else b.push(2);\r\n\t\t\t} else if (Math.abs(x) == Math.abs(y)) {\r\n\t\t\t\tif (a[n-3] * a[n-1] < 0) {\r\n\t\t\t\t\tb.push(a[n-2], a[n-2], -(a[n-3] + a[n-1]));\r\n\t\t\t\t} else {\r\n\t\t\t\t\tb.push(a[n-2], -a[n-2], -(a[n-3] - a[n-1]));\r\n\t\t\t\t}\r\n\r\n\t\t\t} else {\r\n\t\t\t\tif (a[n-3] * a[n-2] < 0) {\r\n\t\t\t\t\tb.push(a[n-1], a[n-1], -(a[n-3] + a[n-2]));\r\n\t\t\t\t} else {\r\n\t\t\t\t\tb.push(a[n-1], -a[n-1], -(a[n-3] - a[n-2]));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < (n&1 ? n-3 : n); i++) {\r\n\t\t\tif (i&1) {\r\n\t\t\t\tb.push(-a[i-1])\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n&1) {\r\n\t\t\t// a[n-3], a[n-2], a[n-1]\r\n\t\t\tif (a[n-3] * a[n-2] < 0) {\r\n\t\t\t\tb.push(a[n-1], a[n-1], -(a[n-3] + a[n-2]));\r\n\t\t\t} else {\r\n\t\t\t\tb.push(a[n-1], -a[n-1], -(a[n-3] - a[n-2]));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(b.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 2) return `${a[1]} ${-a[0]}`;\r\n const res = [];\r\n for (let i = 0; i < n - 3; i += 2) {\r\n res[i] = a[i + 1];\r\n res[i + 1] = -a[i];\r\n }\r\n const [x, y, z] = a.slice(-3);\r\n if (x + y === 0) {\r\n res[n - 3] = z;\r\n res[n - 2] = 2 * z;\r\n res[n - 1] = -(x + 2 * y);\r\n } else {\r\n res[n - 3] = z;\r\n res[n - 2] = z;\r\n res[n - 1] = -(x + y);\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let sum = 0,\r\n res = new Array(n),\r\n last = a[a.length - 1];\r\n for (let i = 0; i < n - 1; i++) {\r\n let flag = a[i] < 0 ? -1 : 1;\r\n if (sum < 0) {\r\n sum += flag * a[i];\r\n res[i] = flag * last;\r\n } else {\r\n sum += -1 * flag * a[i];\r\n res[i] = -flag * last;\r\n }\r\n }\r\n res[n - 1] = -sum;\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const ans = []\n const limit = (n & 1) ? n - 3 : n\n for (let i = 0; i < limit; i += 2) {\n ans[i] = -arr[i + 1]\n ans[i + 1] = arr[i]\n }\n if (n & 1) {\n const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])\n return ans.concat(rest).join(' ')\n } else {\n return ans.join(' ')\n }\n}\nfunction helper(a, b, c) {\n if (a === b && b === c) {\n return [1, 1, -2]\n } else if (a === b) {\n // return [c, c, 2 * a]\n if (c & 1) {\n return [(c - 1) / 2, (c + 1) / 2, -a]\n } else {\n return [c / 2, c / 2, -a]\n }\n } else if (b === c) {\n if (a & 1) {\n return [-b, (a - 1) / 2, (a + 1) / 2]\n } else {\n return [-b, a / 2, a / 2]\n }\n } else if (a === c) {\n if (b & 1) {\n return [(b - 1) / 2, -a, (b + 1) / 2]\n } else {\n return [b / 2, -a, b / 2]\n }\n }\n let d\n d = a - b\n if (Math.abs(d) < 1e4) {\n return [c, -c, -d]\n }\n d = a - c\n if (Math.abs(d) < 1e4) {\n return [b, -d, -b]\n }\n d = b - c\n return [-d, a, -a]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const ans = []\n const limit = (n & 1) ? n - 3 : n\n for (let i = 0; i < limit; i += 2) {\n ans[i] = -arr[i + 1]\n ans[i + 1] = arr[i]\n }\n if (n & 1) {\n const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])\n return ans.concat(rest).join(' ')\n } else {\n return ans.join(' ')\n }\n}\nfunction helper(a, b, c) {\n let d\n d = a - b\n if (Math.abs(d) < 1e4) {\n return [c, -c, -d]\n }\n d = a - c\n if (Math.abs(d) < 1e4) {\n return [b, -d, -b]\n }\n d = b - c\n return [-d, a, -a]\n}\n"}], "src_uid": "c4541021337252c7e2c4afd2de8cd766"} {"source_code": "/**\n * Created by artyom.\n */\n\nlen = readline();\na = readline().split(' ').map(function (v) {\n return parseInt(v);\n});\n\nfunction calcRight(start) {\n var pos = start + 1;\n while (pos <= len && a[pos] <= a[pos - 1]) {\n pos++;\n }\n return pos - start;\n}\n\nb = [calcRight(0)];\nr = [b[0]];\nfor (var i = 1; i < len; i++) {\n if (a[i] > a[i - 1]) {\n r[i] = calcRight(i);\n b[i] = r[i] + b[i - 1];\n } else {\n r[i] = r[i - 1] - 1;\n b[i] = a[i] < a[i - 1] ? r[i] : b[i - 1];\n }\n}\n\nprint(Math.max.apply(Math, b));", "positive_code": [{"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar n=parseInt(readline());\n\nvar arr=readline().split(' ').map(a=>parseInt(a));\n\n\nvar max=0;\nfor(var i=0;i=0;k--){\n if(k-1>=0){\n if(arr[k-1]<=arr[k]){\n count++;\n }else{\n break;\n }\n \n }\n \n max=Math.max(max,count);\n }\n \n}\nprint(max);"}, {"source_code": "var inputLength = readline()\nvar input = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n\nvar maxSections = 0, currentSections, pointer;\nfor (var i = 0; i < inputLength; i++) {\n currentSections = 0;\n for (pointer = i; pointer > 0; pointer--) {\n if (input[pointer - 1] > input[pointer]) {\n break;\n }\n currentSections++;\n }\n for (pointer = i; pointer < inputLength - 1; pointer++) {\n if (input[pointer + 1] > input[pointer]) {\n break;\n }\n currentSections++;\n }\n if (currentSections > maxSections) {\n maxSections = currentSections;\n }\n}\nprint(maxSections + 1)"}, {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n const hs = ipt.split(EOL)[1].split(' ').map(v => parseInt(v))\n let c = 1\n let b = 1\n let i = 0\n while (i < hs.length) {\n for (let k = i - 1; k >= 0; k--) {\n if (hs[k] <= hs[k + 1]) c++\n else break\n }\n i++\n for (; i < hs.length; i++) {\n if (hs[i] <= hs[i - 1]) c++\n else break\n }\n if (c > b) b = c\n c = 1\n }\n console.log(b)\n})"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar n=parseInt(readline());\n\nvar arr=readline().split(' ').map(a=>parseInt(a));\n\n\nvar max=0;\nfor(var i=0;i=0;k--){\n \n if(arr[k]<=arr[c]){\n count++;\n }else{\n break;\n }\n c--;\n\n \n \n }\n max=Math.max(max,count);\n \n}\nprint(max)"}], "negative_code": [{"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n const hs = ipt.split(EOL)[1].split(' ').map(v => parseInt(v))\n let c = 1\n let b = 1\n let i = 0\n while (i < hs.length) {\n for (let k = i - 1; k >= 0; k--) {\n if (hs[k] < hs[k + 1]) c++\n else break\n }\n i++\n for (; i < hs.length; i++) {\n if (hs[i] < hs[i - 1]) c++\n else break\n }\n if (c > b) b = c\n c = 1\n }\n console.log(b)\n})"}, {"source_code": "/**\n * Created by artyom.\n */\n\nn = readline();\na = readline().split(' ');\nlen = a.length;\n\nfunction calcRight(start) {\n var pos = start + 1;\n while (pos <= len && a[pos] <= a[pos - 1]) {\n pos++;\n }\n return pos - start;\n}\n\nb = [calcRight(0)];\nr = [b[0]];\nfor (var i = 1; i < len; i++) {\n if (a[i] > a[i - 1]) {\n r[i] = calcRight(i);\n b[i] = r[i] + b[i - 1];\n } else {\n r[i] = r[i - 1] - 1;\n b[i] = r[i];\n }\n}\nprint(Math.max.apply(Math, b));"}, {"source_code": "/**\n * Created by artyom.\n */\n\nn = readline();\na = readline().split(' ');\nlen = a.length;\n\nfunction calcRight(start) {\n var pos = start + 1;\n while (pos <= len && a[pos] <= a[pos - 1]) {\n pos++;\n }\n return pos - start;\n}\n\nb = [calcRight(0)];\nr = [b[0]];\nfor (var i = 1; i < len; i++) {\n if (a[i] > a[i - 1]) {\n r[i] = calcRight(i);\n b[i] = r[i] + b[i - 1];\n } else {\n r[i] = r[i - 1] - 1;\n b[i] = a[i] < a[i - 1] ? r[i] : b[i - 1];\n }\n}\nprint(Math.max.apply(Math, b));"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar n=parseInt(readline());\n\nvar arr=readline().split(' ').map(a=>parseInt(a));\n\n\nvar max=0;\nfor(var i=0;i=0;k--){\n \n if(arr[k-1]<=arr[k]){\n count++;\n }else{\n break;\n }\n \n max=Math.max(max,count);\n }\n \n \n}\nprint(max);"}], "src_uid": "5d11fa8528f1dc873d50b3417bef8c79"} {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var m = line[1];\n var h = line[2];\n\n var ms = read.arrNumber(' ');\n var ns = read.arrNumber(' ');\n\n var res;\n for(var i = 0; i < n; i++) {\n line = read.arrNumber(' ');\n res = [];\n line.forEach(function (count, index) {\n res[index] = count\n ? (ms[index] > ns[i] ? ns[i] : ms[index])\n : 0\n });\n print(res.join(' '));\n }\n\n}());\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction readLines(cb) {\n const lines = [];\n let read;\n rl.on('line', function(line) {\n if (!read) {\n const first = line.split(' ').map(x=>parseInt(x));\n read = first[0] +2;\n } else {\n lines.push(line);\n }\n if (lines.length === read) {\n rl.close();\n cb(lines);\n }\n });\n};\nreadLines(doIt);\n\nfunction doIt(lines) {\n const frontView = lines[0].split(' ').map(x=>parseInt(x));\n const leftView = lines[1].split(' ').map(x=>parseInt(x));\n const matrix = lines.slice(2).map(line => line.split(' ').map(x=>parseInt(x)));\n\n for (let row = 0; row < leftView.length; row++) {\n const aRow = [];\n for (let col = 0; col < frontView.length;col++) {\n if (matrix[row][col] === 0)\n aRow.push(0);\n else {\n aRow.push(Math.min(frontView[col], leftView[row]));;\n }\n }\n console.log(aRow.join(' '));\n }\n}"}, {"source_code": "let input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', sol);\n\nfunction sol() {\n const [meta, front, left, ...top] = input\n .split('\\n')\n .map(line => line.split(' ').map(Number));\n \n const [n, m, h] = meta;\n const result = [];\n for (let k = 0; k < n; ++k)\n result.push(Array(m).fill(0));\n\n // front: 0 .. m-1\n // fill all columns with maximum value\n for (let i = 0; i < m; ++i) {\n for (let j = 0; j < n; ++j) {\n if (top[j][i] === 0) continue;\n result[j][i] = front[i];\n }\n }\n\n // left: 0 .. n-1\n for (let j = 0; j < n; ++j) {\n for (let i = 0; i < m; ++i) {\n if (top[j][i] === 0) continue;\n if (result[j][i] > left[j]) {\n result[j][i] = left[j];\n }\n }\n }\n\n process.stdout.write(\n result.map(line => line.join(' ')).join('\\n'),\n 'utf8',\n () => process.stdout.end()\n );\n}\n"}], "negative_code": [], "src_uid": "7361e8acf0d712c317e8b99211a7b548"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar treeNum = integers[0], delta = integers[1];\n\tvar trees = tokenizeIntegers(readline());\n\tvar bestCost = treeNum, bestActions;\n\t\tmaxStartingHeight = 1000;\n\n\tfor (var start = 1; start <= maxStartingHeight; ++start) {\n\t\tvar height = start, cost = 0;\n\t\tvar actions = [];\n\t\tfor (var i = 0; i < treeNum; ++i) {\n\t\t\tif (trees[i] != height) {\n\t\t\t\tcost += 1;\n\t\t\t\tactions.push([height < trees[i] ? \"-\" : \"+\",\n\t\t\t\t\t\ti+1, Math.abs(height-trees[i])].join(\" \"));\n\t\t\t}\n\t\t\theight += delta;\n\t\t}\n\t\tif (cost < bestCost) {\n\t\t\tbestCost = cost;\n\t\t\tbestActions = actions;\n\t\t}\n\t}\n\n\tprint(bestCost);\n\tif (bestCost > 0) {\n\t\tprint(bestActions.join(\"\\n\"));\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "print(function(n, k) {\n\tvar a = readline().split(' ').map(Number);\n\tvar min = 1e6;\n\tvar s = 0;\n\tfor (var i = 1; i <= 1000; i++) {\n\t\tvar x = 0;\n\t\tfor (var j = 0; j < n; j++) {\n\t\t\tif (a[j] !== i + j * k) {\n\t\t\t\tx++;\n\t\t\t}\n\t\t}\n\t\tif (x < min) {\n\t\t\tmin = x;\n\t\t\ts = i\n\t\t}\n\t}\n\tvar ans = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tvar x = s + i * k - a[i];\n\t\tif (x > 0) {\n\t\t\tans.push('+ ' + (i + 1) + ' ' + x);\n\t\t} else if (x < 0) {\n\t\t\tans.push('- ' + (i + 1) + ' ' + (-x));\n\t\t}\n\t}\n\n\treturn ans.length == 0 ? ans.length : ans.length + '\\n' + ans.join('\\n')\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar treeNum = integers[0], delta = integers[1];\n\tvar trees = tokenizeIntegers(readline());\n\tvar bestCost = treeNum, bestActions;\n\t\tmaxStartingHeight = 1000;\n\n\tfor (var start = 1; start <= maxStartingHeight; ++start) {\n\t\tvar current = start, cost = 0;\n\t\tvar actions = [];\n\t\tfor (var i = 0; i < treeNum; ++i) {\n\t\t\tif (trees[i] != current) {\n\t\t\t\tcost += 1;\n\t\t\t\tactions.push([current < trees[i] ? \"-\" : \"+\",\n\t\t\t\t\t\ti+1, Math.abs(current-trees[i])].join(\" \"));\n\t\t\t}\n\t\t\tcurrent += delta;\n\t\t}\n\t\tif (cost < bestCost) {\n\t\t\tbestCost = cost;\n\t\t\tbestActions = actions;\n\t\t}\n\t}\n\n\tprint(bestCost);\n\tif (bestCost > 0) {\n\t\tprint(bestActions.join(\"\\n\"));\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar treeNum = integers[0], delta = integers[1];\n\tvar trees = tokenizeIntegers(readline());\n\tvar bestCost = treeNum, bestActions;\n\t\tmaxStartingHeight = 1000;\n\n\tfor (var start = 1; start <= maxStartingHeight; ++start) {\n\t\tvar current = start, cost = 0;\n\t\tvar actions = [];\n\t\tfor (var i = 0; i < treeNum; ++i) {\n\t\t\tif (current > maxStartingHeight) {\n\t\t\t\tcost += treeNum - i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (trees[i] != current) {\n\t\t\t\tcost += 1;\n\t\t\t\tactions.push([current < trees[i] ? \"-\" : \"+\",\n\t\t\t\t\t\ti+1, Math.abs(current-trees[i])].join(\" \"));\n\t\t\t}\n\t\t\tcurrent += delta;\n\t\t}\n\t\tif (cost < bestCost) {\n\t\t\tbestCost = cost;\n\t\t\tbestActions = actions;\n\t\t}\n\t}\n\n\tprint(bestCost);\n\tif (bestCost > 0) {\n\t\tprint(bestActions.join(\"\\n\"));\n\t}\n}\n\nmain();\n"}], "src_uid": "7f08e74945d6b58abde1d8002b8b686a"} {"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ');\n var a0 = [];\n var a1 = [];\n var s = [];\n for (var i = 0; i < n; i++) {\n var x = BigInt(a[i]);\n if (i & 1) {\n a1.push(x);\n } else {\n a0.push(x);\n }\n }\n s.push(a0[0]);\n for (var i = 1; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n for (var i = 0; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n var ans = 0n;\n var hn = Math.floor((n + 1) / 2);\n for (var i = 0; i < n; i++) {\n var sn = s[i + hn] - s[i];\n if (sn > ans) {\n ans = sn;\n }\n }\n write('' + ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ');\n var a0 = [];\n var a1 = [];\n var s = [];\n for (var i = 0; i < n; i++) {\n var x = BigInt(a[i]);\n if (i & 1) {\n a1.push(x);\n } else {\n a0.push(x);\n }\n }\n s.push(a0[0]);\n for (var i = 1; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n for (var i = 0; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n var ans = 0n;\n var hn = Math.floor((n + 1) / 2);\n for (var i = 0; i < n; i++) {\n var sn = s[i + hn] - s[i];\n if (sn > ans) {\n ans = sn;\n }\n }\n write('' + ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n // tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [], sum = 0;\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n sum += a[i];\n }\n\n if (N===1) {\n print(sum);\n continue;\n }\n\n for(let i = 0; i < N; i++) {\n a.push(a[i]);\n }\n\n let at = [take(a, 0), take(a, 1)];\n let st = [accum(at[0]), accum(at[1])];\n // console.log(at);\n // console.log(st);\n\n let result = sum;\n for(let i = 0; i < N; i++) {\n let j = i + N - 2;\n let odd = (i+1)%2;\n // console.log(st[odd][j] - st[odd][i], i, j, odd, st[odd][j], st[odd][i]);\n result = Math.min(result, st[odd][j] - st[odd][i]);\n }\n // console.log(result);\n\n print(sum - result);\n }\n}\n\nfunction take(a, odd) {\n let b = [...a];\n for(let i = 0; i < b.length; i++) {\n if (i % 2 !== odd) {\n b[i] = 0;\n }\n }\n return b;\n}\n\nfunction accum(a) {\n let b = [...a];\n for(let i = 1; i < b.length; i++) {\n b[i] = b[i-1] + b[i];\n }\n return b;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ');\n var a0 = [];\n var a1 = [];\n var s = [];\n for (var i = 0; i < n; i++) {\n var x = BigInt(a[i]);\n if (i & 1) {\n a1.push(x);\n } else {\n a0.push(x);\n }\n }\n a.length = 0;\n s.push(a0[0]);\n for (var i = 1; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n for (var i = 0; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n var ans = 0n;\n var hn = Math.floor((n + 1) / 2);\n for (var i = 0; i < n; i++) {\n var sn = s[i + hn] - s[i];\n if (sn > ans) {\n ans = sn;\n }\n }\n write('' + ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "function sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction solve() {\n var n = Number(read());\n var a = read().split(' ').map(BigInt);\n a.sort(sortF);\n var ans = 0n;\n for (var i = Math.floor(n / 2); i < n; i++) {\n ans += a[i];\n }\n write('' + ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = read().split(' ');\n var a0 = [];\n var a1 = [];\n var s = [];\n for (var i = 0; i < n; i++) {\n var x = BigInt(a[i]);\n if (i & 1) {\n a1.push(x);\n } else {\n a0.push(x);\n }\n }\n s.push(a0[0]);\n for (var i = 1; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n for (var i = 0; i < a0.length; i++) {\n s.push(s[s.length - 1] + a0[i]);\n }\n for (var i = 0; i < a1.length; i++) {\n s.push(s[s.length - 1] + a1[i]);\n }\n var ans = 0n;\n var hn = Math.floor((n + 1 / 2));\n for (var i = 0; i < n; i++) {\n var sn = s[i + hn - 1] - s[i]\n if (sn > ans) {\n ans = sn;\n }\n }\n write('' + ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n // tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [], sum = 0;\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n sum += a[i];\n }\n\n for(let i = 0; i < N; i++) {\n a.push(a[i]);\n }\n\n let at = [take(a, 0), take(a, 1)];\n let st = [accum(at[0]), accum(at[1])];\n // console.log(at);\n // console.log(st);\n\n let result = sum;\n for(let i = 0; i < N; i++) {\n let j = i + N - 2;\n let odd = (i+1)%2;\n // console.log(st[odd][j] - st[odd][i], i, j, odd, st[odd][j], st[odd][i]);\n result = Math.min(result, st[odd][j] - st[odd][i]);\n }\n // console.log(result);\n\n print(sum - result);\n }\n}\n\nfunction take(a, odd) {\n let b = [...a];\n for(let i = 0; i < b.length; i++) {\n if (i % 2 !== odd) {\n b[i] = 0;\n }\n }\n return b;\n}\n\nfunction accum(a) {\n let b = [...a];\n for(let i = 1; i < b.length; i++) {\n b[i] = b[i-1] + b[i];\n }\n return b;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n // tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [], sum = 0;\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n sum += a[i];\n }\n\n for(let i = 0; i < N; i++) {\n a.push(a[i]);\n }\n\n let at = [take(a, 0), take(a, 1)];\n let st = [accum(at[0]), accum(at[1])];\n\n let result = sum;\n for(let i = 0; i < N; i++) {\n let j = i + N-2;\n let odd = i%2;\n result = Math.min(result, st[odd][j] - st[odd][i]);\n }\n\n print(sum - result);\n }\n}\n\nfunction take(a, odd) {\n let b = [...a];\n for(let i = 0; i < b.length; i++) {\n if (i % 2 === odd) {\n b[i] = 0;\n }\n }\n return b;\n}\n\nfunction accum(a) {\n let b = [...a];\n for(let i = 1; i < b.length; i++) {\n b[i] = b[i-1] + b[i];\n }\n return b;\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}], "src_uid": "a9473e6ec81c10c4f88973ac2d60ad04"} {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=parseInt(line0[0]);\n let s=parseInt(line0[1]);\n \n if (line1[0] === '0') {console.log('NO'); return ;}\n if (line1[s-1] === '1') {console.log('YES');return;}\n if (line1[s-1] === '0' && line2[s-1]=== '0') {console.log('NO'); return ;}\n for (let i=s-1; i i && a_line[i] != 0 && a_line[j] != 0) { a[i][j] = 1 }\n// if (i == j && a_line[j] != 0 && b_line[j] != 0) { a[i][n+j] = 1; a[n+j][i] = 1; }\n// } else {\n// if (n+j < i && b_line[j] != 0) { a[i][n+j] = 1 }\n// }\n// }\n// }\n\n// var queue=[]\n// queue.push([0,0]);\n// visited[0][0] = true;\n\n// while(queue.length != 0) {\n// var node = queue.shift();\n// if(node[0] == goal_node-1 || node[1] == goal_node-1 || node[0] == n+goal_node-1 || node[1] == n+goal_node-1) {\n// yes=true;\n// break;\n// }\n// for(var i=0;i i && a_line[i] != 0 && a_line[j] != 0) { a[i][j] = 1 }\n// if (i == j && a_line[j] != 0 && b_line[j] != 0) { a[i][n+j] = 1; a[n+j][i] = 1; }\n// } else {\n// if (n+j < i && b_line[j] != 0) { a[i][n+j] = 1 }\n// }\n// }\n// }\n\n// var queue=[]\n// queue.push([0,0]);\n// visited[0][0] = true;\n\n// while(queue.length != 0) {\n// var node = queue.shift();\n// if(node[0] == goal_node-1 || node[1] == goal_node-1 || node[0] == n+goal_node-1 || node[1] == n+goal_node-1) {\n// yes=true;\n// break;\n// }\n// for(var i=0;i i && a_line[i] != 0 && a_line[j] != 0) { a[i][j] = 1 }\n// if (i == j && a_line[j] != 0 && b_line[j] != 0) { a[i][n+j] = 1; a[n+j][i] = 1; }\n// } else {\n// if (n+j < i && b_line[j] != 0) { a[i][n+j] = 1 }\n// }\n// }\n// }\n\n// var queue=[]\n// queue.push([0,0]);\n// visited[0][0] = true;\n\n// while(queue.length != 0) {\n// var node = queue.shift();\n// if(node[0] == goal_node-1 || node[1] == goal_node-1 || node[0] == n+goal_node-1 || node[1] == n+goal_node-1) {\n// yes=true;\n// break;\n// }\n// for(var i=0;i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=line0[0];\n let s=line0[1];\n console.log(n,s);\n if ((line1[0] === 0) || (line2[s-1] === 0)) {console.log('NO'); return}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=parseInt(line0[0]);\n let s=parseInt(line0[1]);\n \n if (line1[0] === '0' || line2[s-1] === '0') {console.log('NO'); return ;}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=line0[0];\n let s=line0[1];\n //console.log(n,s);\n if ((line1[0] === 0) || (line2[s-1] === 0)) {console.log('NO'); return}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=line0[0];\n let s=line0[1];\n\n if (line1[0] === 0 || line2[s-1] === 0) {console.log('NO'); return}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=parseInt(line0[0]);\n let s=parseInt(line0[1]);\n \n if (line1[0] === '0') {console.log('NO'); return ;}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=parseInt(line0[0]);\n let s=parseInt(line0[1]);\n \n if (line1[0] === '0') {console.log('NO'); return ;}\n if (line1[s-1] === '1') {console.log('YES');return;}\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=line0[0];\n let s=line0[1];\n\n if ((line1[0] === 0) || (line2[s-1] === 0)) {console.log('NO'); return}\n\n for (let i=s-1; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n main(lines); \n});\n\nfunction main (lines) {\n let line0= lines[0].split(' ');\n let line1= lines[1].split(' ');\n let line2= lines[2].split(' ');\n let n=line0[0];\n let s=line0[1];\n //console.log(n,s);\n if ((line1[0] === 0) || (line2[s-1] === 0)) {console.log('NO'); return}\n\n for (let i=s-1; i= 2){\n var first = cont[syl].pop();\n var second = cont[syl].pop();\n \n comp_duos.push([first, second]);\n }\n }\n \n \n var semi_comp = [];\n \n for(syl in cont){\n for(i=0;i= 2){\n var first = semi_comp.pop();\n var second = semi_comp.pop();\n \n semi_comp_duos.push([first, second]);\n }\n\n}\n\nvar lyrics = [];\n\nwhile(comp_duos.length != 0 && semi_comp_duos.length != 0){\n \n var semi_comp_duo = semi_comp_duos.pop();\n var comp_duo = comp_duos.pop();\n \n lyrics.push([semi_comp_duo[0], comp_duo[0]]);\n lyrics.push([semi_comp_duo[1], comp_duo[1]]);\n}\n\nwhile(comp_duos.length >= 2){\n var comp_duo1 = comp_duos.pop();\n var comp_duo2 = comp_duos.pop();\n \n lyrics.push([comp_duo1[0], comp_duo2[0]]);\n lyrics.push([comp_duo1[1], comp_duo2[1]]);\n}\n\nprint(lyrics.length/2);\nfor(i= 0;i= 1 && (second.length + first.length) > 1) {\n var fp = null;\n if (first.length) {\n fp = first.pop();\n } else {\n fp = second.pop();\n }\n\n var sp = second.pop();\n\n result.push(fp[0] + ' ' + sp[0] + '\\n' + fp[1] + ' ' + sp[1]);\n }\n\n return result;\n}\n\nvar r = calc();\nwrite(r.length);\nif (r.length) {\n write('\\n');\n write(r.join('\\n'));\n}"}], "negative_code": [{"source_code": "var n = +readline();\n\nfunction calc() {\n if (n < 4) {\n return [];\n }\n\n var result = [];\n var second = [];\n var first = [];\n var words = {};\n\n var vowels = /[aoiue]/g;\n function count(str) {\n var r = str.match(vowels);\n\n return r;\n }\n\n\n for (var i = 0; i < n; i++) {\n var input = readline();\n var r = input.match(vowels);\n var count = r.length;\n var last = r[count - 1];\n\n if (!words[count]) {\n words[count] = {\n array: []\n };\n }\n\n var hm = words[count];\n\n if (!hm[last]) {\n hm[last] = [input];\n hm.array.push(input);\n } else {\n var uniq = true;\n for (var j = 0; j < hm[last].length; j++) {\n var v = hm[last][j];\n if (input !== v) {\n second.push([input, v]);\n hm[last].splice(j, 1);\n hm.array.splice(hm.array.indexOf(v), 1);\n uniq = false;\n break;\n }\n }\n\n if (uniq) {\n hm[last].push(input);\n hm.array.push(input);\n }\n }\n }\n\n for (var vow in words) {\n var arr = words[vow].array;\n\n for (var j = 0; j < arr.length - 1; j = j + 2) {\n first.push([arr[j], arr[j + 1]]);\n }\n }\n\n while (second.length >= 1 && (second.length + first.length) > 1) {\n var fp = null;\n if (first.length) {\n fp = first.pop();\n } else {\n fp = second.pop();\n }\n\n var sp = second.pop();\n\n result.push(fp[0] + ' ' + sp[0] + '\\n' + fp[1] + ' ' + sp[1]);\n }\n\n return result;\n}\n\nvar r = calc();\nwrite(r.length);\nif (r.length) {\n write('\\n');\n write(r.join('\\n'));\n}"}, {"source_code": "var n = +readline();\n\nfunction calc() {\n if (n < 4) {\n return [];\n }\n\n var result = [];\n var second = [];\n var first = [];\n var words = {};\n\n var vowels = /[aoiue]/g;\n function count(str) {\n var r = str.match(vowels);\n\n return r;\n }\n\n\n for (var i = 0; i < n; i++) {\n var input = readline();\n var r = input.match(vowels);\n var count = r.length;\n var last = r[count - 1];\n\n if (!words[count]) {\n words[count] = {\n array: []\n };\n }\n\n var hm = words[count];\n\n if (!hm[last]) {\n hm[last] = [input];\n hm.array.push(input);\n } else {\n var uniq = true;\n for (var j = 0; j < hm[last].length; j++) {\n var v = hm[last][j];\n if (input !== v) {\n second.push([input, v]);\n hm[last].splice(j, 1);\n hm.array.splice(hm.array.indexOf(v), 1);\n uniq = false;\n break;\n }\n }\n\n if (uniq) {\n hm[last].push(input);\n hm.array.push(input);\n }\n }\n }\n\n for (var vow in words) {\n var arr = words[vow].array;\n\n for (var j = 0; j < arr.length - 1; j = j + 2) {\n first.push([arr[j], arr[j + 1]]);\n }\n }\n\n while (second.length >= 1 && (second.length + first.length) > 1) {\n var fp = null;\n if (first.length) {\n fp = first.pop();\n } else {\n fp = second.pop();\n }\n\n var sp = second.pop();\n\n result.push(fp[0] + ' ' + sp[0] + '\\n' + fp[1] + ' ' + sp[1]);\n }\n\n return result;\n}\n\nvar r = calc();\nwrite(r.length);\nwrite(r.join('\\n'));"}], "src_uid": "f06f7d0dcef10f064f5ce1e9eccf3928"} {"source_code": "function D1437(array) {\n var partition = [];\n var current = [];\n var n = array.length;\n current.push(array[0]);\n\n for (var i = 1; i < n; i++) {\n if (array[i] < array[i - 1] || i === 1) {\n partition.push(current);\n current = [];\n }\n\n current.push(array[i]);\n }\n\n partition.push(current);\n var k = partition.length;\n var depth = Array(k).fill(null);\n depth[0] = 0;\n var cp = 0,\n cov = 1;\n\n while (cov < k) {\n var cl = partition[cp].length;\n\n for (var _i = cov; _i < Math.min(cov + cl, k); _i++) {\n depth[_i] = depth[cp] + 1;\n }\n\n cp++;\n cov += cl;\n }\n\n return depth[k - 1];\n}\n\nfunction execute(readline, print) {\n var iter = {\n next: function next() {\n return readline().trim();\n }\n };\n\n var split = function split(string) {\n return string.split(' ').map(Number);\n };\n\n var t = Number(iter.next());\n\n while (t--) {\n iter.next();\n var arr = split(iter.next());\n print(D1437(arr));\n }\n}\n\nexecute(readline, print)\n\n\n", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={1:t=>{function i(t){this._head=0,this._tail=0,this._capacityMask=3,this._list=new Array(4),Array.isArray(t)&&this._fromArray(t)}i.prototype.peekAt=function(t){var i=t;if(i===(0|i)){var s=this.size();if(!(i>=s||i<-s))return i<0&&(i+=s),i=this._head+i&this._capacityMask,this._list[i]}},i.prototype.get=function(t){return this.peekAt(t)},i.prototype.peek=function(){if(this._head!==this._tail)return this._list[this._head]},i.prototype.peekFront=function(){return this.peek()},i.prototype.peekBack=function(){return this.peekAt(-1)},Object.defineProperty(i.prototype,\"length\",{get:function(){return this.size()}}),i.prototype.size=function(){return this._head===this._tail?0:this._head1e4&&this._tail<=this._list.length>>>2&&this._shrinkArray(),i}},i.prototype.push=function(t){if(void 0===t)return this.size();var i=this._tail;return this._list[i]=t,this._tail=i+1&this._capacityMask,this._tail===this._head&&this._growArray(),this._head1e4&&t<=i>>>2&&this._shrinkArray(),s}},i.prototype.removeOne=function(t){var i=t;if(i===(0|i)&&this._head!==this._tail){var s=this.size(),e=this._list.length;if(!(i>=s||i<-s)){i<0&&(i+=s),i=this._head+i&this._capacityMask;var r,h=this._list[i];if(t0;r--)this._list[i]=this._list[i=i-1+e&this._capacityMask];this._list[i]=void 0,this._head=this._head+1+e&this._capacityMask}else{for(r=s-1-t;r>0;r--)this._list[i]=this._list[i=i+1+e&this._capacityMask];this._list[i]=void 0,this._tail=this._tail-1+e&this._capacityMask}return h}}},i.prototype.remove=function(t,i){var s,e=t,r=i;if(e===(0|e)&&this._head!==this._tail){var h=this.size(),a=this._list.length;if(!(e>=h||e<-h||i<1)){if(e<0&&(e+=h),1===i||!i)return(s=new Array(1))[0]=this.removeOne(e),s;if(0===e&&e+i>=h)return s=this.toArray(),this.clear(),s;var n;for(e+i>h&&(i=h-e),s=new Array(i),n=0;n0;n--)this._list[e=e+1+a&this._capacityMask]=void 0;return s}if(0===t){for(this._head=this._head+i+a&this._capacityMask,n=i-1;n>0;n--)this._list[e=e+1+a&this._capacityMask]=void 0;return s}if(e0;n--)this.unshift(this._list[e=e-1+a&this._capacityMask]);for(e=this._head-1+a&this._capacityMask;r>0;)this._list[e=e-1+a&this._capacityMask]=void 0,r--;t<0&&(this._tail=e)}else{for(this._tail=e,e=e+i+a&this._capacityMask,n=h-(i+t);n>0;n--)this.push(this._list[e++]);for(e=this._tail;r>0;)this._list[e=e+1+a&this._capacityMask]=void 0,r--}return this._head<2&&this._tail>1e4&&this._tail<=a>>>2&&this._shrinkArray(),s}}},i.prototype.splice=function(t,i){var s=t;if(s===(0|s)){var e=this.size();if(s<0&&(s+=e),!(s>e)){if(arguments.length>2){var r,h,a,n=arguments.length,o=this._list.length,l=2;if(!e||s0&&(this._head=this._head+s+o&this._capacityMask)):(a=this.remove(s,i),this._head=this._head+s+o&this._capacityMask);n>l;)this.unshift(arguments[--n]);for(r=s;r>0;r--)this.unshift(h[r-1])}else{var _=(h=new Array(e-(s+i))).length;for(r=0;r<_;r++)h[r]=this._list[this._head+s+i+r&this._capacityMask];for(0===i?(a=[],s!=e&&(this._tail=this._head+s+o&this._capacityMask)):(a=this.remove(s,i),this._tail=this._tail-_+o&this._capacityMask);lthis._tail){for(i=this._head;i>>=1,this._capacityMask>>>=1},t.exports=i},675:(t,i)=>{Object.defineProperty(i,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,i,s)=>{let e=[];null==t&&(i=t),null==s&&(s=0);for(let r=0;rt-i))},Array.prototype.sortDesc=function(){return this.sort(((t,i)=>i-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let i=1;i{if(l){if(a=r.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),r.default.writeFileSync(\"output.txt\",o),console.log(o),r.default.readFileSync(\"expected.txt\").toString().trim()==o.trim()){const{exec:t}=s(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{h+=t})),process.stdin.on(\"end\",(i=>{a=h.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(o)}))};function p(){return a[n++]}function u(){return p().split(\" \").map((t=>parseFloat(t)))}function c(){return p().split(\"\")}i.default={runMain:_,runEachTest:t=>{_((()=>{let[i]=u();for(;i>0;)t(),i--}))},readline:p,nextNumbers:u,nextNumbersMatrix:function(t){let i=[];for(let s=0;s{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},i={};!function s(e){if(i[e])return i[e].exports;var r=i[e]={exports:{}};return t[e].call(r.exports,r,r.exports,s),r.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import Denque from 'denque'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let height = Array(n + 1).fill(0)\n// \n// let node = 1\n// \n// let q = new Denque([])\n// \n// for (let i = 1; i < n; ++i) {\n// if (a[i] < a[i - 1]) {\n// node = q.shift()\n// io.debug(node)\n// }\n// height[a[i]] = height[node] + 1\n// \n// q.push(a[i])\n// }\n// \n// // io.debug(height)\n// \n// io.puts(height.max())\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let q = [a[0], null];\n let p = 1;\n let h = 0;\n while(q.length > 0 && p < n){\n let node = q.shift();\n if(node !== null){\n let x = p+1;\n while(x < n && a[x] >= a[x-1]){\n q.push(x-1);\n x++;\n }\n q.push(p);\n p = x;\n }else{\n h++;\n if(q.length > 0){\n q.push(null);\n }\n }\n }\n\n if(q.length > 0)\n h++;\n\n console.log(h);\n }\n}"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n\n var level = 1;\n var ans = 0;\n var current = 0;\n\n for (var i = 1; i < n; i++){\n if (ar[i] < ar[i - 1]) {\n level--;\n if (level == 0) {\n ans++;\n level = current;\n current = 0;\n }\n }\n current++;\n }\n ans++; // root node\n print(ans);\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let [node, map, result] = [1, new Map([[1, 0]]), 0];\n const queue = [];\n\n for (let i = 1; i < arr.length; i++) {\n const [prev, curr] = [arr[i - 1], arr[i]];\n if (curr < prev) {\n node = queue.shift();\n }\n queue.push(curr);\n map.set(curr, map.get(node) + 1);\n result = Math.max(result, map.get(curr));\n }\n\n console.log(result);\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let count = 0;\n\n for (let i = 0, j = 0; j < arr.length - 1; i++) {\n j++;\n while (arr[j + 1] - arr[j] >= 1) j++;\n count++;\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let count = 0;\n\n for (let i = 0, j = 0; j < arr.length - 1; i++) {\n j++;\n while (arr[j + 1] - arr[j] === 1) j++;\n count++;\n }\n\n console.log(count);\n }\n}\n"}], "src_uid": "16c4160d1436206412ce51315cb6140b"} {"source_code": "function main()\n{\n var a = readline(),\n b = readline();\n if ( a.length != b.length )\n {\n print(\"NO\");\n return;\n }\n if ( a == b )\n {\n print(\"YES\");\n return;\n }\n if ( a.match(/1/) && b.match(/1/) )\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n}\n\nmain();\n", "positive_code": [{"source_code": "n1 = readline()\nn2 = readline()\n\nif( (n1.length === n2.length) && ( (n1.indexOf(\"1\") !== -1 && n2.indexOf(\"1\") !== -1) || (n1 === n2)) ){\n\tprint(\"YES\")\n}\nelse{\n\tprint(\"NO\")\n}\n"}, {"source_code": "var x = readline();\nvar y = readline();\n\nif ((x.length != y.length || x.search(\"1\") == \"-1\" || y.search(\"1\") == \"-1\") && x != y) {\n\tprint(\"NO\");\n} else {\n\tprint(\"YES\");\n}"}, {"source_code": "(function main() {\n var s1 = readline();\n var s2 = readline();\n if (s1.length != s2.length) {\n print('NO');\n return;\n }\n if (s1 == s2 || s1.match(/1/) && s2.match(/1/)) \n print('YES');\n else\n print('NO');\n})();"}, {"source_code": "print(function(a, b) {\n if (a.length != b.length) return 'NO';\n if (a.length === 1 && a !== b) return 'NO'\n if (a.indexOf(1) > -1 !== b.indexOf(1) > -1) return 'NO';\n return 'YES';\n}(readline(), readline()));"}, {"source_code": "function main(){\n var a = readline(),\n b = readline();\n if ( a.length != b.length ){\n print(\"NO\");\n return;\n }\n if ( a == b ){\n print(\"YES\");\n return;\n }\n if ( a.match(/1/) && b.match(/1/) ){\n print(\"YES\");\n }\n else{\n print(\"NO\");\n }\n}\n\nmain();\n"}, {"source_code": "function main()\n{\n var a = readline(),\n b = readline();\n if ( a.length != b.length )\n {\n print(\"NO\");\n return;\n }\n if ( a == b )\n {\n print(\"YES\");\n return;\n }\n var cnt1 = 0,\n cnt2 = 0;\n for ( var i = 0; i < a.length; i++ )\n {\n if ( a[i] == \"1\" )\n {\n cnt1++;\n }\n if ( b[i] == \"1\" )\n {\n cnt2++;\n }\n }\n if ( cnt1 <= 0 || cnt2 <= 0 )\n {\n print(\"NO\");\n }\n else\n {\n print(\"YES\");\n }\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(a, b) {\n if (a.length != b.length) return 'NO';\n if (a.length === 1 && a !== b) return 'NO'\n if (a.indexOf(1) === -1 && b.indexOf(1) > -1) return 'NO';\n return 'YES';\n}(readline(), readline()));"}, {"source_code": "print(function(a, b) {\n if (a.length != b.length) return 'NO';\n if (a.indexOf(1) === -1 && b.indexOf(1) > -1) return 'NO';\n return 'YES';\n}(readline(), readline()));"}, {"source_code": "function main()\n{\n var a = readline(),\n b = readline();\n if ( a.length != b.length )\n {\n print(\"NO\");\n return;\n }\n var cnt1 = 0,\n cnt2 = 0;\n for ( var i = 0; i < a.length; i++ )\n {\n if ( a[i] == \"1\" )\n {\n cnt1++;\n }\n if ( b[i] == \"1\" )\n {\n cnt2++;\n }\n }\n if ( cnt1 >= cnt2 )\n {\n print(\"YES\");\n }\n else\n {\n print(\"NO\");\n }\n}\n\nmain();\n"}, {"source_code": "function main()\n{\n var a = readline(),\n b = readline();\n if ( a.length != b.length )\n {\n print(\"NO\");\n return;\n }\n if ( a == b )\n {\n print(\"YES\");\n return;\n }\n var cnt1 = 0,\n cnt2 = 0;\n for ( var i = 0; i < a.length; i++ )\n {\n if ( a[i] == \"1\" )\n {\n cnt1++;\n }\n if ( b[i] == \"1\" )\n {\n cnt2++;\n }\n }\n if ( cnt1 <= 0 && cnt2 <= 0 )\n {\n print(\"NO\");\n }\n else\n {\n print(\"YES\");\n }\n}\n\nmain();\n"}, {"source_code": "var x = readline();\nvar y = readline();\n\nif (x.length != y.length || x.search(\"1\") == \"-1\" || y.search(\"1\") == \"-1\") {\n\tprint(\"NO\");\n} else {\n\tprint(\"YES\");\n}"}, {"source_code": "\nfunction count(l) {\n if (l) \n return l.length;\n return 0;\n}\n\n(function main() {\n var s1 = readline();\n var s2 = readline();\n if (s1.length != s2.length) {\n print('NO');\n return;\n }\n var n1 = count(s1.match(/1/g));\n var n2 = count(s2.match(/1/g));\n if (n1 >= n2) \n print('YES');\n else\n print('NO');\n})();"}], "src_uid": "113ae625e67c8ea5ab07be44c3b58a8f"} {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let [n,m,k] = readline().split(' ').map(x => +x);\r\n let a = readline().trim().split('').sort();\r\n let b = readline().trim().split('').sort();\r\n console.log(`${solve(a, b, n, m, k)}`) \r\n}\r\n\r\nfunction solve(str1, str2, n, m, k){\r\n let result = '';\r\n let idx1 = 0;\r\n let idx2 = 0;\r\n let count = k;\r\n let next;\r\n \r\n if(str1[idx1] < str2[idx2]){\r\n result += str1[idx1]\r\n idx1++;\r\n next = 'b';\r\n }else{\r\n result += str2[idx2]\r\n idx2++;\r\n next = 'a';\r\n }\r\n \r\n while(idx1 < n && idx2 < m){\r\n if(str1[idx1] <= str2[idx2] && next === 'a'){\r\n result += str1[idx1];\r\n idx1++;\r\n next = 'b';\r\n count = k;\r\n }else if(str2[idx2] <= str1[idx1] && next === 'b'){\r\n result += str2[idx2]\r\n idx2++;\r\n next = 'a';\r\n count = k;\r\n }else{\r\n if(str1[idx1] <= str2[idx2] && count > 1){\r\n result += str1[idx1];\r\n idx1++;\r\n count--;\r\n next = 'b';\r\n }else if(str2[idx2] <= str1[idx1] && count >1){\r\n result += str2[idx2]\r\n idx2++;\r\n next = 'a';\r\n count--;\r\n }else{\r\n if(next === 'a'){\r\n result += str1[idx1];\r\n idx1++;\r\n next = 'b';\r\n count = k;\r\n }else{\r\n result += str2[idx2]\r\n idx2++;\r\n next = 'a';\r\n count = k;\r\n }\r\n } \r\n }\r\n }\r\n return result;\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nmk = readline().split(\" \").map(Number);\r\n let a = readline().split(\"\").sort();\r\n let b = readline().split(\"\").sort();\r\n print(DistinctC(a, b, nmk[2]));\r\n }\r\n}\r\n\r\nfunction DistinctC(a, b, k) {\r\n let taken_a = 0;\r\n let taken_b = 0;\r\n let i = 0;\r\n let j = 0;\r\n let c = \"\";\r\n while (i < a.length && j < b.length) {\r\n if (taken_a < k && taken_b < k) {\r\n if (a[i] < b[j]) {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n taken_b = 0;\r\n } else {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n taken_a = 0;\r\n }\r\n } else if (taken_a == k) {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n taken_a = 0;\r\n } else {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n taken_b = 0;\r\n }\r\n }\r\n return c;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m, k] = readline().split(' ').map(Number);\r\n let a = readline().split('').sort().join('');;\r\n let b = readline().split('').sort().join('');;\r\n let c = '';\r\n let pA = 0;\r\n let pB = 0;\r\n let opA = 0;\r\n let opB = 0;\r\n\r\n while (pA < a.length && pB < b.length) {\r\n if (a[pA] < b[pB] && opA < k) {\r\n c += a[pA];\r\n opB = 0;\r\n pA++;\r\n opA++;\r\n } else if (opB < k) {\r\n opA = 0;\r\n c += b[pB];\r\n pB++;\r\n opB++\r\n } else {\r\n c += a[pA];\r\n opB = 0;\r\n pA++;\r\n opA++;\r\n }\r\n }\r\n\r\n output(c);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, k, a, b) {\r\n a.sort((a, b) => b - a);\r\n b.sort((a, b) => b - a);\r\n const res = [];\r\n let pre = 0,\r\n count = 0;\r\n while (a.length && b.length) {\r\n if (a[a.length - 1] < b[b.length - 1]) {\r\n if (pre === 0 && count === k) {\r\n res.push(b.pop());\r\n pre = 1;\r\n count = 1;\r\n } else {\r\n if (pre === 1) {\r\n pre = 0;\r\n count = 0;\r\n }\r\n count++;\r\n res.push(a.pop());\r\n }\r\n } else {\r\n if (pre === 1 && count === k) {\r\n res.push(a.pop());\r\n pre = 0;\r\n count = 1;\r\n } else {\r\n if (pre === 0) {\r\n pre = 1;\r\n count = 0;\r\n }\r\n count++;\r\n res.push(b.pop());\r\n }\r\n }\r\n }\r\n return res.map(num => String.fromCharCode(num + 97)).join('');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m, k] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split('').map(ch => ch.charCodeAt(0) - 97);\r\n const b = (await read()).split('').map(ch => ch.charCodeAt(0) - 97);\r\n res.push(solve(n, m, k, a, b));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = -1,\n n,\n m,\n k,\n a,\n b;\n\nconst solve = (a, b, n, m, k) => {\n let temp_a = k,\n temp_b = k,\n sort_a = a.sort(),\n sort_b = b.sort(),\n c = [],\n i = 0;\n\n while (n > 0 && m > 0) {\n if ((sort_a[i] < sort_b[i] && temp_a !== 0) || temp_b === 0) {\n c.push(sort_a.shift());\n n--;\n temp_a--;\n temp_b = k;\n } else {\n c.push(sort_b.shift());\n m--;\n temp_b--;\n temp_a = k;\n }\n }\n console.log(c.join(\"\"));\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== -1) {\n if (lines % 3 === 0) {\n [n, m, k] = line.split(\" \").map(Number);\n }\n if (lines % 3 === 1) {\n a = line.split(\"\");\n }\n if (lines % 3 === 2) {\n b = line.split(\"\");\n // console.log(a, b, n, m, k);\n solve(a, b, n, m, k);\n }\n }\n lines++;\n});\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n let n = nextInt();\r\n let m = nextInt();\r\n let k = nextInt();\r\n let stringOne = nextCharArray().sort();\r\n let stringTwo = nextCharArray().sort();\r\n let c = [];\r\n let i = 0, j = 0, counter =[0 ,0];\r\n while(i < n && j < m) {\r\n if (stringOne[i].localeCompare(stringTwo[j]) < 0) {\r\n if (counter[0] < k) {\r\n c.push(stringOne[i]);\r\n i++;\r\n counter[0]++;\r\n counter[1]=0;\r\n } else {\r\n c.push(stringTwo[j]);\r\n j++;\r\n counter[0] = 0;\r\n counter[1]++;\r\n }\r\n } else {\r\n if (counter[1] < k) {\r\n c.push(stringTwo[j]);\r\n j++;\r\n counter[1]++;\r\n counter[0]=0;\r\n } else {\r\n c.push(stringOne[i]);\r\n i++;\r\n counter[1] = 0;\r\n counter[0]++;\r\n }\r\n }\r\n }\r\n\r\n myout(c.join(\"\"));\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let res = \"\";\r\n const [m, n, k] = readLine().split(\" \").map(i => parseInt(i));\r\n let A = readLine().split(\"\").sort((a, b) => a.localeCompare(b));\r\n let B = readLine().split(\"\").sort((a, b) => a.localeCompare(b));\r\n let x = 0, y = 0, xb = 0, yb = 0;\r\n while (x < A.length && y < B.length) {\r\n if (((xb < k) && (A[x] < B[y]) || yb >= k)) {\r\n res += A[x++];\r\n xb++;\r\n yb = 0;\r\n } else {\r\n res += B[y++];\r\n yb++;\r\n xb = 0\r\n }\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const fs = require('fs');\r\n//const { addLeadingSlash } = require('history/PathUtils');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var [n, m, k] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split('');\r\n var b = readline().split('');\r\n a.sort();\r\n b.sort();\r\n \r\n var c = []\r\n var i = 0, j=0, cntA = 0, cntB = 0;\r\n while(i b[j] && cntB < k) {\r\n \r\n while(a[i] > b[j] && cntB < k) {\r\n c.push(b[j]);\r\n j++;\r\n cntB++;\r\n }\r\n cntA = 0;\r\n continue;\r\n }\r\n if(cntA == k) {\r\n c.push(b[j]);\r\n cntA = 0;\r\n j++\r\n }\r\n if(cntB == k) {\r\n c.push(a[i])\r\n cntB = 0;\r\n i++\r\n }\r\n \r\n }\r\n var ans = c.join('')\r\n\r\n console.log(ans);\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nmk = readline().split(\" \").map(Number);\r\n let a = readline().split(\"\").sort();\r\n let b = readline().split(\"\").sort();\r\n print(DistinctC(a, b, nmk[2]));\r\n }\r\n}\r\n\r\nfunction DistinctC(a, b, k) {\r\n let taken_a = 0;\r\n let taken_b = 0;\r\n let i = 0;\r\n let j = 0;\r\n let c = \"\";\r\n while (i < a.length && j < b.length) {\r\n if (taken_a < k && taken_b < k) {\r\n if (a[i] < b[j]) {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n } else {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n }\r\n } else if (taken_a == k) {\r\n c += b[j];\r\n j++;\r\n taken_b=1;\r\n taken_a = 0;\r\n } else {\r\n c += a[i];\r\n i++;\r\n taken_a=1;\r\n taken_b = 0;\r\n }\r\n }\r\n return c;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nmk = readline().split(\" \").map(Number);\r\n let a = readline().split(\"\").sort();\r\n let b = readline().split(\"\").sort();\r\n print(DistinctC(a.join(\"\"), b.join(\"\"), nmk[2]));\r\n }\r\n}\r\n\r\nfunction DistinctC(a, b, k) {\r\n let taken_a = 0;\r\n let taken_b = 0;\r\n let i = 0;\r\n let j = 0;\r\n let c = \"\";\r\n while (i < a.length && j < b.length) {\r\n if (taken_a < k && taken_b < k) {\r\n if (a[i] < b[j]) {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n } else {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n }\r\n } else if (taken_a == k) {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n taken_a = 0;\r\n } else {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n taken_b = 0;\r\n }\r\n }\r\n return c;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nmk = readline().split(\" \").map(Number);\r\n let a = readline().split(\"\").sort();\r\n let b = readline().split(\"\").sort();\r\n DistinctC(a, b, nmk[2]);\r\n }\r\n}\r\n\r\nfunction DistinctC(a, b, k) {\r\n let taken_a = 0;\r\n let taken_b = 0;\r\n let i = 0;\r\n let j = 0;\r\n let c = \"\";\r\n while (i < a.length && j < b.length) {\r\n if (taken_a < k && taken_b < k) {\r\n if (a[i] < b[j]) {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n } else {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n }\r\n } else if (taken_a == k) {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n taken_a = 0;\r\n } else {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n taken_b = 0;\r\n }\r\n }\r\n print(c);\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nmk = readline().split(\" \").map(Number);\r\n let a = readline().split(\"\").sort();\r\n let b = readline().split(\"\").sort();\r\n print(DistinctC(a, b, nmk[2]));\r\n }\r\n}\r\n\r\nfunction DistinctC(a, b, k) {\r\n let taken_a = 0;\r\n let taken_b = 0;\r\n let i = 0;\r\n let j = 0;\r\n let c = \"\";\r\n while (i < a.length && j < b.length) {\r\n if (taken_a < k && taken_b < k) {\r\n if (a[i] < b[j]) {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n } else {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n }\r\n } else if (taken_a == k) {\r\n c += b[j];\r\n j++;\r\n taken_b++;\r\n taken_a = 0;\r\n } else {\r\n c += a[i];\r\n i++;\r\n taken_a++;\r\n taken_b = 0;\r\n }\r\n }\r\n return c;\r\n}"}], "src_uid": "1d46a356c5515f8894cbb83e438cc544"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n let [j, ...k] = iInpArr();\r\n arr.push(k);\r\n }\r\n let narr = [];\r\n for (let i = 0; i < n; i++) {\r\n let j = arr[i];\r\n let en = arr[i][0] + 1;\r\n for (let j = 1; j < arr[i].length; j++) {\r\n en = Math.max(en, arr[i][j] - j + 1);\r\n }\r\n narr.push([en, arr[i].length]);\r\n }\r\n narr.sort((a, b) => a[0] - b[0]);\r\n let ans = narr[0][0],\r\n to = narr[0][1];\r\n for (let i = 1; i < narr.length; i++) {\r\n let j = ans + to;\r\n if (j < narr[i][0]) ans = narr[i][0] - to;\r\n to += narr[i][1];\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst k = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tk[i] = rna().slice(1); \r\n\t\t}\r\n\r\n\t\tconst v = [];\r\n\t\tfor (const cave of k) {\r\n\t\t\tlet mxpw = 0;\r\n\t\t\tfor (let i = 0; i < cave.length; i++) {\r\n\t\t\t\tmxpw = Math.max(mxpw, cave[i] - i);\r\n\t\t\t}\r\n\t\t\tv.push([mxpw + 1, mxpw + 1 + cave.length]);\r\n\t\t}\r\n\t\tv.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tlet mxd = 0;\r\n\t\tfor (let i = 0, curd = 0; i < n - 1; i++) {\r\n\t\t\tcurd += v[i+1][0] - v[i][1];\r\n\t\t\tmxd = Math.max(mxd, curd);\r\n\t\t}\r\n\r\n\t\tconst ans = v[0][0] + mxd;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n let [j, ...k] = iInpArr();\r\n arr.push(k);\r\n }\r\n let narr = [];\r\n for (let i = 0; i < n; i++) {\r\n let j = arr[i];\r\n let en = arr[i][0] + 1;\r\n for (let j = 1; j < arr[i].length; j++) {\r\n en = Math.max(en, arr[i][j] - j);\r\n }\r\n narr.push([en, arr[i].length]);\r\n }\r\n narr.sort((a, b) => a[0] - b[0]);\r\n let ans = narr[0][0],\r\n to = narr[0][1];\r\n for (let i = 1; i < narr.length; i++) {\r\n let j = ans + to;\r\n if (j < narr[i][0]) ans = narr[i][0];\r\n to += narr[i][1];\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst k = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tk[i] = rna().slice(1); \r\n\t\t}\r\n\r\n\t\tconst v = [];\r\n\t\tfor (const cave of k) {\r\n\t\t\tlet mxpw = 0;\r\n\t\t\tfor (let i = 0; i < cave.length; i++) {\r\n\t\t\t\tmxpw = Math.max(mxpw, cave[i] - i);\r\n\t\t\t}\r\n\t\t\tv.push([mxpw + 1, mxpw + 1 + cave.length]);\r\n\t\t}\r\n\t\tv.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tlet mxd = 0;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tmxd = Math.max(mxd, Math.max(0, v[i+1][0] - v[i][1])); \r\n\t\t}\r\n\r\n\t\tconst ans = v[0][0] + mxd;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "88488ff074bc25a6cf925c8a07a1d8c6"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nclass graph {\r\n constructor() {\r\n this.list = {};\r\n }\r\n add(v) {\r\n if (this.list[v] !== undefined) return false;\r\n this.list[v] = [];\r\n return true;\r\n }\r\n addE(v, e) {\r\n this.list[v].push(e);\r\n }\r\n}\r\nlet global = 0;\r\nconst dfs = (g, c) => {\r\n const helper = (v) => {\r\n if (g.list[v] === undefined) {\r\n if (c[v - 1] === \"W\") return [0, 1];\r\n else return [1, 0];\r\n }\r\n let b = 0,\r\n w = 0;\r\n let arr = g.list[v];\r\n for (let i = 0; i < arr.length; i++) {\r\n let k = helper(arr[i]);\r\n b += k[0];\r\n w += k[1];\r\n }\r\n if (c[v - 1] === \"W\") w++;\r\n else b++;\r\n if (b === w) global++;\r\n return [b, w];\r\n };\r\n helper(1);\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let colour = stringArr();\r\n let g = new graph();\r\n g.add(1);\r\n for (let i = 0, j = 2; i < n - 1; i++, j++) {\r\n g.add(arr[i]);\r\n g.addE(arr[i], j);\r\n }\r\n dfs(g, colour);\r\n console.log(global);\r\n global = 0;\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet p;\r\nlet col;\r\nlet adjList;\r\nlet bc;\r\nlet cnt;\r\nfunction f(u, par) {\r\n cnt[u] = 1;\r\n if (col[u - 1] == 'B') {\r\n bc[u] = 1;\r\n }\r\n for (let v of adjList[u]) {\r\n if (v == par) {\r\n continue;\r\n }\r\n f(v, u);\r\n bc[u] += bc[v];\r\n cnt[u] += cnt[v];\r\n }\r\n}\r\nfunction solve() {\r\n bc = af(n + 1).fill(0);\r\n cnt = af(n + 1).fill(0);\r\n f(1, INIT);\r\n let ans = 0;\r\n for (let u = 1; u <= n; u++) {\r\n if (bc[u] + bc[u] == cnt[u]) {\r\n ans++;\r\n }\r\n }\r\n // printf(\"%j\\n%j\\n\", bc, cnt);\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n p = af(n + 1);\r\n adjList = Array.from({ length: n + 1 });\r\n for (let i = 1; i <= n; i++) {\r\n adjList[i] = [];\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n p[i] = nextInt();\r\n adjList[p[i]].push(i);\r\n }\r\n col = nextStr();\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n"}, {"source_code": "\r\nfunction solve(inp) {\r\n var t = inp.nextNum();\r\n\r\n while(t--) {\r\n const n = inp.nextNum();\r\n const tree = new Array(n + 1);\r\n for (let i = 1; i <= n; i++) tree[i] = [];\r\n const par = inp.nextNumArr();\r\n for(let i = 0; i < n - 1; i++) {\r\n const p = par[i];\r\n tree[p].push(i + 2);\r\n }\r\n const col = inp.nextLine();\r\n\r\n const dfs = (i) => {\r\n var w = col.charAt(i - 1) === 'B' ? 1 : -1;\r\n var c = 0;\r\n tree[i].forEach((j) => {\r\n const [cw, cc] = dfs(j);\r\n w += cw;\r\n c += cc;\r\n });\r\n if (w === 0) c++;\r\n return [w, c];\r\n }\r\n\r\n const [w, c] = dfs(1);\r\n console.log(c);\r\n }\r\n}\r\n\r\n\r\nclass Input {\r\n constructor(lines) {\r\n this.lines = lines;\r\n this.next = 0;\r\n }\r\n \r\n addLine(line) {\r\n this.lines.push(line) \r\n }\r\n \r\n hasLine() {\r\n return this.lines.size() > 0; \r\n }\r\n \r\n nextLine() {\r\n const line = this.lines[this.next];\r\n if (line) {\r\n this.next++;\r\n }\r\n return line;\r\n }\r\n\r\n nextNum() {\r\n return Number(this.nextLine());\r\n }\r\n\r\n nextNumArr() {\r\n return inp.nextLine().split(\" \").map(x => Number(x));\r\n }\r\n}\r\n\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst inp = new Input([]);\r\n\r\nreadline.on('line', line => {\r\n inp.addLine(line);\r\n});\r\n\r\nreadline.on('close', () => {\r\n solve(inp);\r\n});"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, s) {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n for (let i = 0; i < n - 1; i++) {\r\n const u = a[i],\r\n v = i + 2;\r\n g[u].push(v);\r\n }\r\n let res = 0;\r\n const dfs = i => {\r\n let b = 0,\r\n w = 0;\r\n if (s[i - 1] === 'B') b++;else w++;\r\n for (let child of g[i]) {\r\n const [rb, rw] = dfs(child);\r\n b += rb;\r\n w += rw;\r\n }\r\n if (b === w) res++;\r\n return [b, w];\r\n };\r\n dfs(1);\r\n return res.toString();\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n res.push(solve(n, a, s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i] = {\r\n\t\t\t\tchild : [],\r\n\t\t\t\ts : \"\",\r\n\t\t\t\tb : 0,\r\n\t\t\t\tw : 0\r\n\t\t\t};\r\n\t\t}\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tvar p = nextInt() - 1;\r\n\t\t\tlist[i].child.push(p);\r\n\t\t\tlist[p].child.push(i);\r\n\t\t}\r\n\t\tvar S = next();\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i].s = S[i];\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tdfs(0, -1);\r\n\t\tmyout(output);\r\n\r\n\t\tfunction dfs(now, parent){\r\n\t\t\tvar b = 0;\r\n\t\t\tvar w = 0;\r\n\t\t\tvar child = list[now].child;\r\n\t\t\tfor(var j = 0; j < child.length; j++){\r\n\t\t\t\tvar nx = child[j];\r\n\t\t\t\tif(nx != parent){\r\n\t\t\t\t\tvar ret = dfs(nx, now);\r\n\t\t\t\t\tb += ret.b;\r\n\t\t\t\t\tw += ret.w;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(list[now].s == \"W\"){\r\n\t\t\t\tw++;\r\n\t\t\t}else{\r\n\t\t\t\tb++;\r\n\t\t\t}\r\n\t\t\tif(b == w){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t\treturn {\r\n\t\t\t\tb : b,\r\n\t\t\t\tw : w\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra();\n P = P.map(a=>a-1);\n let S = readline()\n // PROCESSING:\n let ans = 0;\n let G = {};\n for (let i=1; i{\n let white = 0, black = 0;\n if (S[v]=='B') black++; else white++;\n let children = G[v]||[];\n //L({v, children})\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const ps = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++]\n output[i] = solve(n, ps, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n getLast() {\n return this.map[this.last]\n }\n}\n\nfunction solve(n, ps, arr) {\n const adj = {}\n ps.forEach((p, i) => {\n const a = i + 2\n const b = p\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n return dfs(adj, 1, arr)\n}\nfunction dfs(adj, r, arr) {\n // const stack = [[r, 0, -1]]\n const stack = new Queue()\n stack.push([r, 0, -1])\n const bs = []\n const ws = []\n let ans = 0\n while (stack.length) {\n const [u, i, p] = stack.getLast()// stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n }\n if (i < nb.length) {\n // stack[stack.length - 1][1]++\n stack.getLast()[1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n bs[u] = arr[u - 1] === 'B' ? 1 : 0\n ws[u] = arr[u - 1] === 'W' ? 1 : 0\n ;(adj[u] || []).forEach(v => {\n if (v === p) return\n bs[u] += bs[v]\n ws[u] += ws[v]\n })\n if (bs[u] === ws[u]) ans++\n }\n }\n // console.log(bs, ws)\n return ans\n}\n"}, {"source_code": "//let { readline, print } = require('@ip-algorithmics/codeforces-io');\r\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n};\r\nvar t = +readline();\r\nwhile (t--) {\r\n var n = readline().split(' ').map(function (v) { return +v; })[0];\r\n var a = __spreadArray([0, 0], readline().split(' ').map(function (v) { return +v; }), true);\r\n var s = readline().split('');\r\n var c = Array(n + 1);\r\n for (var i = 0; i <= n; i++) {\r\n c[i] = [];\r\n }\r\n for (var i = 1; i <= n; i++) {\r\n c[a[i]].push(i);\r\n }\r\n /*\r\n function f (v) {\r\n let balance = 0, count = 0;\r\n for (let i=0; i pivot) {\n j--;\n }\n if (i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n}\nfunction quickSort(items, left, right) {\n var index;\n if (items.length > 1) {\n left = typeof left != \"number\" ? 0 : left;\n right = typeof right != \"number\" ? items.length - 1 : right;\n index = partition(items, left, right);\n if (left < index - 1) {\n quickSort(items, left, index - 1);\n }\n if (index < right) {\n quickSort(items, index, right);\n }\n }\n return items;\n}\n\nfunction unique(arr) {\n var obj = {};\n\n for (var i = 0; i < arr.length; i++) {\n var str = arr[i];\n obj[str] = true;\n }\n\n return Object.keys(obj); // \u0438\u043b\u0438 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0434\u043b\u044f IE8-\n}\n\nfunction main(r) {\n var k = r().split(' ');\n var n = +k[0];\n k = +k[1];\n var a = r().split(' ').map(v => +v)\n a = quickSort(a);\n a = unique(a)\n var t = 0;\n for(var i = 0 ; i < k; i++) {\n if(a[i]){\n print(a[i] - t);\n t += a[i] - t;\n }\n else{\n print(0);\n }\n }\n\n}\nmain(readline);", "positive_code": [{"source_code": "function doIt() {\n var repeats = readline().split(' ').map(v=>+v)[1];\n var arr = readline().split(' ').sort((a, b) => a - b);\n\n var prev = 0;\n\n for(var i = 0; i < arr.length; i++) {\n var v = arr[i];\n if(v === prev) continue;\n\n print(v - prev);\n if(!(--repeats)) break;\n\n prev = v;\n }\n\n while(repeats--) print(0);\n}\n\ndoIt();"}, {"source_code": "ip = readline().split(' ');\nn = +ip[0], k = +ip[1];\nsub = 0;\ncount = 0;\nres = '';\nar = readline().split(' ').map(Number).sort((a,b)=>a-b);\n\nfor (i = 0; i < n; i++){\n if (ar[i] - sub > 0){\n res += (ar[i] - sub)+'\\n';\n sub = ar[i];\n count++;\n }\n if (count === k) break;\n}\n\nfor (;count < k;count++){\n res += '0\\n';\n}\nprint(res);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet op = []\nlet array = []\n\nrl.on('line', (input) => {\n if (l === 0) {\n op = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n } else if (l === 1) {\n rl.close();\n\n array = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n\n array.sort(function sortNumber(a, b) {\n return a - b;\n })\n let mn = array[0]\n console.log(mn)\n let amm=mn;\n let st=0\n let res=''\n for (let i = 0; i < op[1] - 1; i++) {\n let min = mn\n if (mn > 0) {\n mn = -1\n for (let j = st; j < array.length&&mn==-1; j++) {\n array[j] -= amm;\n if (array[j] > 0 && mn === -1) {\n mn = array[j]\n amm+=mn\n res+=mn+'\\n'\n } else if(mn==-1){\n st++\n }\n }\n }\n if (mn === -1) {\n res+='0'+'\\n'\n }\n }\n console.log(res)\n }\n l++\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet op = []\nlet array = []\n\nrl.on('line', (input) => {\n if (l === 0) {\n op = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n } else if (l === 1) {\n rl.close();\n\n array = input.split(' ').map(function (item) {\n return parseInt(item, 10);\n });\n\n array.sort(function sortNumber(a, b) {\n return a - b;\n })\n let mn = array[0]\n console.log(mn)\n let amm=mn;\n let st=0\n let res=''\n for (let i = 0; i < op[1] - 1; i++) {\n let min = mn\n if (mn > 0) {\n mn = -1\n for (let j = st; j < array.length&&mn==-1; j++) {\n array[j] -= amm;\n if (array[j] > 0 && mn === -1) {\n mn = array[j]\n amm+=mn\n res+=mn+'\\n'\n } else if(mn==-1){\n st++\n }\n }\n }\n if (mn === -1) {\n res+='0'+'\\n'\n }\n }\n console.log(res)\n }\n l++\n});\n"}], "negative_code": [{"source_code": "function swap(items, firstIndex, secondIndex){\n const temp = items[firstIndex];\n items[firstIndex] = items[secondIndex];\n items[secondIndex] = temp;\n}\nfunction partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n\n while (i <= j) {\n while (items[i] < pivot) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n}\nfunction quickSort(items, left, right) {\n var index;\n if (items.length > 1) {\n left = typeof left != \"number\" ? 0 : left;\n right = typeof right != \"number\" ? items.length - 1 : right;\n index = partition(items, left, right);\n if (left < index - 1) {\n quickSort(items, left, index - 1);\n }\n if (index < right) {\n quickSort(items, index, right);\n }\n }\n return items;\n}\n\nfunction unique(arr) {\n var obj = {};\n\n for (var i = 0; i < arr.length; i++) {\n var str = arr[i];\n obj[str] = true;\n }\n\n return Object.keys(obj); // \u0438\u043b\u0438 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0434\u043b\u044f IE8-\n}\n\nfunction main(r) {\n var k = r().split(' ');\n var n = +k[0];\n k = +k[1];\n var a = r().split(' ').map(v => +v)\n a = quickSort(a);\n a = unique(a)\n print(a)\n var t = 0;\n for(var i = 0 ; i < k; i++) {\n if(a[i]){\n print(a[i] - t);\n t += a[i] - t;\n }\n else{\n print(0);\n }\n }\n\n}\nmain(readline);"}], "src_uid": "0f100199a720b0fdead5f03e1882f2f3"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n console.log(Math.min(s,d, Math.floor((s+d)/3)));\n i += 1;\n }\n}", "positive_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = Math.min(one[0],one[1]);\n var b = Math.max(one[0],one[1]);\n if(a * 2 <= b){\n output[i] = a;\n continue;\n }\n var count = b - a; \n var tmp = b;\n b -= (tmp - a) * 2;\n a -= (tmp - a);\n //myerr({a,b});\n count += 2 * Math.floor(a / 3);\n var tmp = a;\n a -= Math.floor(tmp / 3) * 3;\n b -= Math.floor(tmp / 3) * 3;\n //myerr({a,b});\n if(a > 0 && b > 1){\n count++;\n }\n output[i] = count;\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "\"use strict\";\n\n//readline().split(' ').map(Number);\n\nfunction sec(){\n var arr = readline().split(' ').map(Number);\n var ans = Math.min(arr[0],arr[1],parseInt((arr[0]+arr[1])/3));\n /*\n var ans = 0;\n while (arr[0]>0 && arr[1]>0){\n //print(arr[0]+' '+arr[1]);\n if(arr[0]>=arr[1]){\n ans += parseInt(arr[0]/2);\n arr[1] -= parseInt(arr[0]/2);\n arr[0] -= parseInt(arr[0]/2)*2;\n }\n else if(arr[0] {\n let { value, done } = this.iterOfCurrent.next();\n if (!done) {\n return {value, done}\n } else {\n do {\n this.current = this.iter.next();\n if (this.current.done)\n return { value: undefined, done: true };\n this.iterOfCurrent = this.current.value.values();\n ({ value, done } = this.iterOfCurrent.next());\n } while (done);\n return {value, done};\n }\n }\n }\n }\n}\n\nclass Scanner {\n constructor(iterable) {\n this.iter = iterable[Symbol.iterator]();\n }\n\n getWord() {\n const res = [];\n let {value, done} = this.iter.next();\n while (!done && !this.isLetter(value))\n ({value, done} = this.iter.next());\n if (!done) {\n while (!done && this.isLetter(value)) {\n res.push(value);\n ({value, done} = this.iter.next());\n }\n }\n return String.fromCharCode(...res);\n }\n\n isLetter(char) {\n return (\n (48 <= char && char <= 57) || // 0-9\n (97 <= char && char <= 122) || // a-z\n (65 <= char && char <= 90) // A-Z\n );\n }\n}\n\ninputStream.on(\"data\", (chunk) => {\n data.push(chunk);\n});\n\ninputStream.on(\"end\", () => {\n start();\n});\n\nfunction start() {\n const scan = new Scanner(new DoubleIter(data));\n const t = +scan.getWord();\n for (let i = 0; i < t; i++) {\n let a = +scan.getWord();\n let b = +scan.getWord();\n //console.log(a, b);\n if (a > b) {\n const t = a;\n a = b;\n b = t;\n }\n const mid = (2*a - b) / 3;\n const x1 = Math.floor(mid);\n let res1 = ~~((x1 + b) / 2);\n const x2 = Math.ceil(mid);\n let res2 = a - x2;\n if (x1 < 0)\n res1 = 0;\n if (x2 < 0)\n res2 = a;\n const mx = Math.max(res1, res2);\n\n process.stdout.write(mx.toString() + '\\n');\n }\n process.stdout.end()\n}\n\nfunction func(a, b, c) {\n a -= c;\n b -= c;\n return Math.min(c, Math.max(a, b));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdinInput = '';\n\nprocess.stdin.on('data', input => {\n stdinInput += input;\n\n})\n\nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n\nfunction main(data) {\n data = data.split(\"\\n\");\n let testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let line = data[i].split(\" \");\n let stick = line[0] * 1;\n let diamonds = line[1] * 1;\n console.log(Math.min(stick, Math.min(diamonds, Math.floor((stick + diamonds) / 3))));\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n console.log(Math.min(s,d, Math.floor((s+d)/3)));\n i += 1;\n }\n}"}], "negative_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n one.sort(function(mae,ato){\n \treturn mae - ato;\n });\n var a = one[0];\n var b = one[1];\n if(a * 2 <= b){\n output[i] = a;\n continue;\n }\n var count = 2 * Math.floor(Math.min(a, b) / 3);\n var tmp = a;\n a -= Math.floor(tmp / 3) * 3;\n b -= Math.floor(tmp / 3) * 3;\n //myerr({a,b});\n if(a > 0 && b > 1){\n count++;\n }\n output[i] = count;\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n \n let e = 0;\n if (s === 0 || d === 0) {\n console.log(e);\n } else console.log(Math.floor((s + d) / 3)); \n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n let e = 0;\n if (s === 0 || d === 0) {\n console.log(e);\n } else if (s === d) {\n while (s > 1) {\n s -= e % 2 ? 2 : 1;\n e += 1;\n }\n console.log(e);\n } else if (d > s) {\n e = Math.floor(d / 2);\n const diff = s - e;\n if (diff === 0 || diff === 1) console.log(e);\n else if (diff > 1) console.log(e + 1);\n else if (s % 2) console.log(s + 1);\n else console.log(s);\n } else {\n e = Math.floor(s / 2);\n const diff = d - e;\n if (diff === 0 || diff === 1) console.log(e);\n else if (diff > 1) console.log(e + 1);\n else if (d % 2) console.log(d + 1);\n else console.log(d);\n }\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n let e = 0;\n if (s === 0 || d === 0) {\n console.log(e);\n } else if (s === d) {\n while (s > 1) {\n s -= e % 2 ? 2 : 1;\n e += 1;\n }\n console.log(e);\n } else if (d > s) {\n e = Math.floor(d / 2);\n const diff = s - e;\n if (diff === 0 || diff === 1) console.log(e);\n else console.log(e + 1);\n } else {\n e = Math.floor(s / 2);\n const diff = d - e;\n if (diff === 0 || diff === 1) console.log(e);\n else console.log(e + 1);\n }\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let int = data[i].split(' ');\n let s = int[0] * 1;\n let d = int[1] * 1;\n console.log(s,d, Math.floor((s+d)/3))\n i += 1;\n }\n}"}, {"source_code": "const data = [];\n\nclass DoubleIter {\n constructor(iter) {\n this.iter = iter.values();\n this.current = this.iter.next();\n this.iterOfCurrent = this.current.value.values();\n }\n\n [Symbol.iterator]() {\n return {\n next: () => {\n let { value, done } = this.iterOfCurrent.next();\n if (!done) {\n return {value, done}\n } else {\n do {\n this.current = this.iter.next();\n if (this.current.done)\n return { value: undefined, done: true };\n this.iterOfCurrent = this.current.value.values();\n ({ value, done } = this.iterOfCurrent.next());\n } while (done);\n return {value, done};\n }\n }\n }\n }\n}\n\nclass Scanner {\n constructor(iterable) {\n this.iter = iterable[Symbol.iterator]();\n }\n\n getWord() {\n const res = [];\n let {value, done} = this.iter.next();\n while (!done && !this.isLetter(value))\n ({value, done} = this.iter.next());\n if (!done) {\n while (!done && this.isLetter(value)) {\n res.push(value);\n ({value, done} = this.iter.next());\n }\n }\n return String.fromCharCode(...res);\n }\n\n isLetter(char) {\n return (\n (48 <= char && char <= 57) || // 0-9\n (97 <= char && char <= 122) || // a-z\n (65 <= char && char <= 90) // A-Z\n );\n }\n}\n\nprocess.stdin.on(\"data\", (chunk) => {\n data.push(chunk);\n});\n\nprocess.stdin.on(\"end\", () => {\n start();\n});\n\nfunction start() {\n const scan = new Scanner(new DoubleIter(data));\n const t = +scan.getWord();\n for (let i = 0; i < t; i++) {\n let a = +scan.getWord();\n let b = +scan.getWord();\n //console.log(a, b);\n if (a > b) {\n const t = a;\n a = b;\n b = t;\n }\n const mid = (2*a - b) / 3;\n const x1 = Math.floor(mid);\n let res1 = ~~((x1 + b) / 2);\n const x2 = Math.ceil(mid);\n let res2 = a - x2;\n if (x1 < 0)\n res1 = 0;\n if (x2 < 0)\n res2 = 0;\n const mx = Math.max(res1, res2);\n\n process.stdout.write(mx.toString() + '\\n');\n }\n process.stdout.end()\n}\n\nfunction func(a, b, c) {\n a -= c;\n b -= c;\n return Math.min(c, Math.max(a, b));\n}"}, {"source_code": "const data = [];\n\nclass DoubleIter {\n constructor(iter) {\n this.iter = iter.values();\n this.current = this.iter.next();\n this.iterOfCurrent = this.current.value.values();\n }\n\n [Symbol.iterator]() {\n return {\n next: () => {\n let { value, done } = this.iterOfCurrent.next();\n if (!done) {\n return {value, done}\n } else {\n do {\n this.current = this.iter.next();\n if (this.current.done)\n return { value: undefined, done: true };\n this.iterOfCurrent = this.current.value.values();\n ({ value, done } = this.iterOfCurrent.next());\n } while (done);\n return {value, done};\n }\n }\n }\n }\n}\n\nclass Scanner {\n constructor(iterable) {\n this.iter = iterable[Symbol.iterator]();\n }\n\n getWord() {\n const res = [];\n let {value, done} = this.iter.next();\n while (!done && !this.isLetter(value))\n ({value, done} = this.iter.next());\n if (!done) {\n while (!done && this.isLetter(value)) {\n res.push(value);\n ({value, done} = this.iter.next());\n }\n }\n return String.fromCharCode(...res);\n }\n\n isLetter(char) {\n return (\n (48 <= char && char <= 57) || // 0-9\n (97 <= char && char <= 122) || // a-z\n (65 <= char && char <= 90) // A-Z\n );\n }\n}\n\nprocess.stdin.on(\"data\", (chunk) => {\n data.push(chunk);\n});\n\nprocess.stdin.on(\"end\", () => {\n start();\n});\n\nfunction start() {\n const scan = new Scanner(new DoubleIter(data));\n const t = +scan.getWord();\n for (let i = 0; i < t; i++) {\n let a = +scan.getWord();\n let b = +scan.getWord();\n //console.log(a, b);\n if (a > b) {\n const t = a;\n a = b;\n b = t;\n }\n const mid = (2*a - b) / 3;\n const x1 = Math.floor(mid);\n let res1 = ~~((x1 + b) / 2);\n const x2 = Math.ceil(mid);\n let res2 = 2 - x2;\n if (x1 < 0)\n res1 = 0;\n if (x2 < 0)\n res2 = 0;\n const mx = Math.max(res1, res2);\n\n process.stdout.write(mx.toString() + '\\n');\n }\n process.stdout.end()\n}\n\nfunction func(a, b, c) {\n a -= c;\n b -= c;\n return Math.min(c, Math.max(a, b));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdinInput = '';\n\nprocess.stdin.on('data', input => {\n stdinInput += input;\n \n})\n\nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n\nfunction main(data) {\n data = data.split(\"\\n\");\n let testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let line = data[i].split(\" \");\n let stick = line[0] * 1;\n let diamonds = line[0] * 1;\n console.log(Math.min(stick,Math.min(diamonds,Math.floor( (stick + diamonds) / 3))));\n i+=1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdinInput = '';\n\nprocess.stdin.on('data', input => {\n stdinInput += input;\n \n})\n\nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n\nfunction main(data) {\n data = data.split(\"\\n\");\n let testCases = data[0] * 1;\n let i = 1;\n while (testCases--) {\n let line = data[i].split(\"\\n\");\n let stick = line[0] * 1;\n let diamonds = line[0] * 1;\n let polycrap = Math.min(stick, Math.floor(diamonds / 2));\n \n let stickTemp = polycrap - stick;\n let diamondsTemp = polycrap - Math.floor(diamonds / 2);\n let remains = Math.min(Math.floor(stickTemp / 2), diamondsTemp);\n let polyAnswer = remains + polycrap; \n\n let swords = Math.min(Math.floor(stick / 2), diamonds);\n diamondsTemp = swords - diamonds;\n stickTemp = swords - Math.floor(stick / 2);\n remains = Math.min(Math.floor(diamondsTemp / 2), stickTemp);\n let swordsAnswer = remains + polycrap; \n console.log(Math.min(swordsAnswer,polyAnswer));\n i+=1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdinInput = '';\n\nprocess.stdin.on('data', input => {\n stdinInput += input;\n \n})\n\nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n\nfunction main(data) {\n data = data.split(\"\\n\");\n let testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let line = data[i].split(\"\\n\");\n let stick = line[0] * 1;\n let diamonds = line[0] * 1;\n console.log(Math.min(stick,Math.min(diamonds,Math.floor( (stick + diamonds) / 3))));\n i+=1;\n }\n}"}], "src_uid": "8bbec86e427e26158393bbfbf1a067fe"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n F();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction F(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n0, n1, n2] = ti(readline().split(' '));\n let s = '';\n if(n2 !== 0){\n for(let i = 0; i <= n2; i++){\n s += '1';\n }\n }\n\n if(n0 !== 0){\n s += '0';\n for(let i = 0; i < n0; i++)\n s += '0';\n }\n\n if(n1 !== 0){\n let p = s.length !== 0 ? s[s.length-1] : '';\n if(n2 !== 0 && n0 !== 0)\n n1 -= 1;\n if(n0 === 0 && n2 === 0)\n n1 += 1;\n\n for(let i = 0; i < n1; i++){\n if(p === '0'){\n s += '1';\n p = '1';\n }else{\n s += '0';\n p = '0';\n }\n }\n }\n\n console.log(s);\n }\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n let [n0,n1,n2] = readline().split(\" \").map(e => parseInt(e));\n //console.log({n1,n2,n3})\n\n\n let zz = [];\n for (var i = 0; i < n0; i++) {\n zz.push('00');\n }\n\n let ee = [];\n for (var i = 0; i < n2; i++) {\n ee.push('11');\n }\n\n let mid = [];\n for (var i = 0; i < n1; i++) {\n if (i % 2 == 0) {\n mid.unshift('10');\n } else {\n mid.unshift('01');\n }\n }\n\n \n\n // console.log({\n // zz,\n // mid,\n // ee,\n // })\n\n let res = [...ee, ...mid, ...zz];\n if (n1 % 2 == 0 && n1 >= 2) {\n mid.splice(1, 0, ...ee)\n res = [...mid, ...zz];\n }\n\n //console.log(res);\n\n let output = \"\";\n for (var k = 0; k < res.length; k++) {\n if (k == 0) {\n output += res[k];\n } else {\n output += res[k][1];\n }\n }\n\n console.log(output);\n\n\n\n //break;\n\n }\n\n\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n F();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction F(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n0, n1, n2] = ti(readline().split(' '));\n let s = '';\n if(n2 !== 0){\n for(let i = 0; i <= n2; i++){\n s += '1';\n }\n }\n\n if(n0 !== 0){\n s += '0';\n for(let i = 0; i < n0; i++)\n s += '0';\n\n let p = s[s.length-1];\n for(let i = 0; i < n1-1; i++){\n if(p === '0'){\n s += '1';\n p = '1';\n }\n else{\n s += '0';\n p = '0';\n }\n }\n }else{\n if(n1 !== 0){\n s += '0';\n let p = '0';\n for(let i = 0; i < n1-1; i++){\n if(p === '0'){\n s += '1';\n p = '1';\n }\n else{\n s += '0';\n p = '0';\n }\n }\n }\n }\n\n console.log(s);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n F();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction F(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n0, n1, n2] = ti(readline().split(' '));\n let s = '1';\n for(let i = 0; i < n2; i++){\n s += '1';\n }\n\n if(n0 !== 0){\n s += '0';\n for(let i = 0; i < n0; i++)\n s += '0';\n\n let p = s[s.length-1];\n for(let i = 0; i < n1-1; i++){\n if(p === '0'){\n s += '1';\n p = '1';\n }\n else{\n s += '0';\n p = '0';\n }\n }\n }else{\n if(n1 !== 0){\n s += '0';\n let p = '0';\n for(let i = 0; i < n1-1; i++){\n if(p === '0'){\n s += '1';\n p = '1';\n }\n else{\n s += '0';\n p = '0';\n }\n }\n }\n }\n\n console.log(s);\n }\n}"}], "src_uid": "4bbb078b66b26d6414e30b0aae845b98"} {"source_code": "var count = Number(readline());\nfor(var i=0; i3)||(y<=x)||((x==2)&&(y==3)))\n ? \"YES\" : \"NO\");\n}\n\n", "positive_code": [{"source_code": "n=readline();\nwhile(n--) {\n var x= readline().split(' ')\n if (x[0]==x[1]) {\n print('YES');\n continue;\n }\n if (x[0]==1 || ((x[0]==2||x[0]==3) && x[1]>3)) print('NO');\n else print('YES');\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const arrT = arr[i].split(' ').map(a => parseInt(a))\n const x = arrT[0]\n const y = arrT[1]\n\n if(x >= y) console.log('YES')\n\n else {\n if(x == 2 && y == 3) console.log('YES')\n else if(x > 3) console.log('YES')\n else console.log('NO')\n }\n }\n})"}, {"source_code": "\n// var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n// var x = num[0]; // to store values in different variables. \n// var y= num[1];\n// var z= num[2];\n\n\n// var num2= readline(); // reads next line.\n\n// print(num2)\n\n// let input = document.querySelector('.input pre').textContent.split('\\n')\n\n// const readline = () => input.shift()\n\n// const print = console.log\n\n// begin solution\n\nconst solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3\n\nconst uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'\n\n// boilerplate\n\nconst inputCount = readline()\n\nfor (var i = 0; i < inputCount; i++) {\n print(uglySolution.apply(this, (readline().split(' ').map(Number))))\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\nfunction main() {\n const n = +readline();\n\n for (let i = 0; i < n; i++) {\n let res = false;\n const [x, y] = readline().split(\" \").map(t => parseInt(t));\n if (x > 3) res = true;\n else if (x === 1) {\n res = y === 1 ? true : false;\n } else res = y < 4;\n console.log(res ? \"YES\" : \"NO\");\n }\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, 'utf-8').split(\"\\r\\n\").filter(data=>{return data.length>0});\ntxt.shift()\ntxt.forEach((data) => {\n let info = data.split(\" \")\n magic(info[0] * 1, info[1] * 1);\n})\n\nfunction magic(a,b){\n while (a!=b){\n if(a>b){\n console.log(\"YES\");\n return;\n }else{\n if(a%2==1){\n if(a!=(a-1)*3/2 && (a-1)*3/2!=0){\n --a;\n }else{\n console.log(\"NO\");\n return;\n }\n }else{\n a=a*3/2;\n }\n }\n }\n console.log(\"YES\");\n}"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0);\nconst inputString = stdinBuffer.toString();\n\nconst [count, ...data] = inputString.split('\\n');\n\ndata.length = Math.min(parseInt(count, 10), data.length);\n\nfunction find(dataString) {\n const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });\n\n if (current === desired) return 'yes';\n if (current === 2 && desired <= 3) return 'yes';\n if (current === 3 && desired < 3) return 'yes';\n if (current >= 4) return 'yes';\n\n return 'no';\n}\nprocess.stdout.write(`${data.map(find).join('\\n')}`);"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\nfunction main() {\n const n = +readline();\n let res = false;\n for (let i = 0; i < n; i++) {\n const [x, y] = readline().split(\" \").map(t => parseInt(t));\n if (x > 3) res = true;\n else if (x === 1) {\n res = y === 1 ? true : false;\n } else res = y < 4;\n }\n console.log(res ? \"YES\" : \"NO\");\n}"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0);\nconst inputString = stdinBuffer.toString();\n\nconst [count, ...data] = inputString.split('\\n');\n\ndata.length = Math.min(parseInt(count, 10), data.length);\n\nfunction find(dataString) {\n const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });\n\n if (current === desired) return 'yes';\n if (current === 2 && desired === 3) return 'yes';\n if (current === 3 && desired < 3) return 'yes';\n if (current >= 4) return 'yes';\n\n return 'no';\n}\n\nprocess.stdout.write(`${data.map(find).join('\\n')}`);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0);\nconst inputString = stdinBuffer.toString();\n\nconst [count, ...data] = inputString.split('\\n');\n\ndata.length = parseInt(count, 10);\n\nfunction find(dataString) {\n const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });\n\n if (current === desired) return 'yes';\n if (current === 2 && desired === 3) return 'yes';\n if (current === 3 && desired < 3) return 'yes';\n if (current >= 4) return 'yes';\n\n return 'no';\n}\n\nprocess.stdout.write(`${data.map(find).join('\\n')}`);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0);\nconst inputString = stdinBuffer.toString();\n\nconst [count, ...data] = inputString.split('\\n');\n\ndata.length = parseInt(count, 10);\n\nfunction find(dataString) {\n const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });\n\n if (current === desired) return 'yes';\n\n if (current > desired && current > 1) return 'yes';\n\n if (desired > current && current % 2 === 0) return 'yes';\n\n return 'no';\n}\n\nprocess.stdout.write(`${data.map(find).join('\\n')}`);"}, {"source_code": "n=readline();\nwhile(n--) {\n var x= readline().split(' ')\n if (x[0]==x[1]) {\n print('YES');\n continue;\n }\n if ((x[0]==2||x[0]==3) && x[1]>3) print('NO');\n else print('YES');\n}"}, {"source_code": "\n// var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n// var x = num[0]; // to store values in different variables. \n// var y= num[1];\n// var z= num[2];\n\n\n// var num2= readline(); // reads next line.\n\n// print(num2)\n\n// let input = document.querySelector('.input pre').textContent.split('\\n')\n\n// const readline = () => input.shift()\n\n// const print = console.log\n\n// begin solution\n\nconst solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3\n\nconst uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'\n\n// boilerplate\n\n// const inputCount = readline()\n\n// for (let i = 0; i < inputCount; i++) {\n// print(uglySolution.apply(this, (readline().split(' ').map(Number))))\n// }\n"}, {"source_code": "\nconst num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\nvar x = num[0]; // to store values in different variables. \nvar y= num[1];\nvar z= num[2];\n\n\nvar num2= readline(); // reads next line.\n\nprint(num2)\n\n// const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3\n\n// const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'\n\n// // boilerplate\n\n// const inputCount = readline()\n\n// for (let i = 0; i < inputCount; i++) {\n// print(solution(...(readline().split(' ').map(Number))))\n// }\n"}, {"source_code": "\n// var num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\n// var x = num[0]; // to store values in different variables. \n// var y= num[1];\n// var z= num[2];\n\n\n// var num2= readline(); // reads next line.\n\n// print(num2)\n\n// let input = document.querySelector('.input pre').textContent.split('\\n')\n\n// const readline = () => input.shift()\n\n// const print = console.log\n\n// begin solution\n\nconst solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3\n\nconst uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'\n\n// boilerplate\n\nconst inputCount = readline()\n\n// for (let i = 0; i < inputCount; i++) {\n// print(uglySolution.apply(this, (readline().split(' ').map(Number))))\n// }\n"}, {"source_code": "\nvar num = readline().split(\" \").map(x => parseInt(x)); // num will be an array [1,2,3]\nvar x = num[0]; // to store values in different variables. \nvar y= num[1];\nvar z= num[2];\n\n\nvar num2= readline(); // reads next line.\n\nprint(num2)\n\n// const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3\n\n// const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'\n\n// // boilerplate\n\n// const inputCount = readline()\n\n// for (let i = 0; i < inputCount; i++) {\n// print(solution(...(readline().split(' ').map(Number))))\n// }\n"}], "src_uid": "b3978805756262e17df738e049830427"} {"source_code": "while (readline()){\r\n print(\"no\")\r\n}", "positive_code": [{"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n console.log('NO')\r\n})"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\nvar external_readline_default = /*#__PURE__*/__webpack_require__.n(external_readline_namespaceObject);\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = external_readline_default().createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise(resolve => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n fs.writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1505/1505-a.ts\n\nconst io = new InteractiveIO();\n\nasync function solve() {\n while (true) {\n let str = await io.nextLine();\n\n if (!str) {\n return;\n }\n\n console.log('NO');\n }\n}\n\nasync function main() {\n try {\n await solve();\n } catch (e) {\n console.log(e.stack);\n }\n\n io.close();\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "let inputs = '';\nprocess.stdin.on('data', c => process.stdout.write(\"NO\\n\"));\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst g = main();\ng.next()\nrl.on('line', (input) => {\n // console.log('read', input)\n input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n // input = yield 1\n const t = 1//+input\n for (let i = 0; i < t;) {\n input = yield 1\n console.log('NO')\n }\n // process.exit(0)\n}\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (s) => {\r\n pr(\"NO\");\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n rl.on('line', (line) => {\r\n if (line.length == 0) {\r\n rl.on('close', () => {});\r\n } else {\r\n solve(line);\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n"}, {"source_code": "const readline = require('readline').createInterface({ input: process.stdin });\r\n\r\nreadline.on('line', line => {\r\n if (line == 'Is it rated?') {\r\n console.log(\"NO\")\r\n }\r\n});"}], "negative_code": [{"source_code": " console.log('NO')\r\n console.log('NO')\r\n console.log('NO')\r\n"}, {"source_code": "// JavaScript V8 4.8.0\r\nwhile (readline()) {\r\n print('NO')\r\n}\r\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\nvar external_readline_default = /*#__PURE__*/__webpack_require__.n(external_readline_namespaceObject);\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = external_readline_default().createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise(resolve => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n fs.writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1505/1505-a.ts\n\nconst io = new InteractiveIO();\n\nasync function solve() {\n while (true) {\n let str = await io.nextLine();\n\n if (!str) {\n return;\n }\n\n console.log('NO');\n }\n}\n\nasync function main() {\n try {\n solve();\n } catch (e) {\n console.log(e.stack);\n }\n\n io.close();\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1505/1505-a.ts\n\nconst io = new IO();\n\nfunction solve() {\n while (true) {\n let str = io.nextToken();\n\n if (!str) {\n return;\n }\n\n io.writeLine('NO');\n io.flush();\n }\n}\n\nfunction main() {\n try {\n solve();\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}], "src_uid": "57b62c485669809c0b59afd6613f901c"} {"source_code": "var arr = readline().split(\" \", 2).map(Number);\nvar n = arr[0], m = arr[1];\n\nfunction getSum(x) {\n return (x + 1) * x / 2;\n}\nvar beg = 1, end = 5e4, mid;\nwhile(true) {\n if (getSum(end) <= m) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (getSum(mid) <= m) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n}\nvar buy = end, money = m - getSum(buy), over = 0;\n\nvar array = readline().split(\" \", n).map(Number);\narray.sort(function(a, b) {return a - b;});\nfor (var i = 0; i < n; ++i) {\n if (array[i] <= buy) {\n ++over;\n money += array[i];\n if (money >= buy + 1) {\n ++buy;\n money -= buy;\n }\n } else {\n break;\n }\n}\n\nfunction range(array, num) {\n var result = \"\", beg, end;\n if (num === 0) {\n beg = 1;\n } else {\n beg = array[num - 1] + 1;\n }\n end = array[num];\n for (var i = beg; i < end; ++i) {\n result += i + \" \";\n }\n return result;\n}\nvar answer = \"\";\nprint(buy - over);\nfor (var i = 0; i < over; ++i) {\n answer += range(array, i);\n}\nfor (var i = (over === 0 ? 1 : array[over - 1] + 1); i <= buy; ++i) {\n answer += i + \" \";\n}\nprint(answer);", "positive_code": [{"source_code": "function sortNumber(a,b) {\n return a - b;\n}\n\nvar input = readline().split(' ')\n , n = +input[0]\n , m = +input[1]\n , types = readline().split(' ').map( Number ).sort(sortNumber);\n // 4 14\n // 4 6 12 8\n// console.log(types);\n// console.log(Math.pow(10, 9));\nfor (var i = 1, sum = 0, curr = types.shift(), result = []; i < Math.pow(10, 9); i++) {\n if ((sum + i) > m) { \n break; \n };\n if (i === curr) {\n curr = types.shift();\n continue;\n } else {\n //console.log(i);\n result.push(i);\n sum += i;\n }\n}\nprint(result.length);\nprint(result.join(' '));\n//console.log(result);\n//console.log(i);\n//alert('asdas');"}], "negative_code": [{"source_code": "var arr = readline().split(\" \", 2).map(Number);\nvar n = arr[0], m = arr[1];\n\nfunction getSum(x) {\n return (x + 1) * x / 2;\n}\nvar beg = 1, end = 5e4, mid;\nwhile(true) {\n if (getSum(end) <= m) {\n break;\n }\n mid = Math.ceil((beg + end) / 2);\n if (getSum(mid) <= m) {\n beg = mid;\n } else {\n end = mid - 1;\n }\n}\nvar buy = end, money = m - getSum(buy), over = 0;\n\nvar array = readline().split(\" \", n).map(Number);\narray.sort(function(a, b) {return a - b;});\nfor (var i = 0; i < n; ++i) {\n if (array[i] <= buy) {\n ++over;\n money += array[i];\n if (money >= buy + 1) {\n ++buy;\n money -= buy;\n }\n } else {\n break;\n }\n}\n\nfunction range(array, num) {\n var result = \"\", beg, end;\n if (num === 0) {\n beg = 1;\n } else {\n beg = array[num - 1] + 1;\n }\n end = array[num];\n for (var i = beg; i < end; ++i) {\n result += i + \" \";\n }\n return result;\n}\nvar answer = \"\";\nprint(buy - over);\nfor (var i = 0; i < over; ++i) {\n answer += range(array, i);\n}\nfor (var i = array[over - 1] + 1; i <= buy; ++i) {\n answer += i + \" \";\n}\nprint(answer);"}], "src_uid": "0318d4d5ea3425bf6506edeb1026f597"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet avl = new Set(a);\r\n\t\tlet used = new Set();\r\n\r\n\t\tlet rem = [];\r\n\t\tlet seq = [];\r\n\r\n\t\tfor (let x = 1; x <= n; x++) {\r\n\t\t\tif (avl.has(x)) {\r\n\t\t\t\tused.add(x);\r\n\t\t\t} else {\r\n\t\t\t\tseq.push(x);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (used.has(a[i])) {\r\n\t\t\t\tused.delete(a[i]);\r\n\t\t\t} else {\r\n\t\t\t\trem.push(a[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trem.sort((x, y) => x - y);\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < rem.length; i++) {\r\n\t\t\tok = rem[i] > 2*seq[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? rem.length : -1);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = n;\r\n\t\tconst done = Array(n+1);\r\n\t\tconst used = Array(n+1);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] <= n && !done[a[i]]) {\r\n\t\t\t\tdone[a[i]] = true;\r\n\t\t\t\tused[i] = true;\r\n\t\t\t\tans--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0, x = 1; ok && i < n; i++) {\r\n\t\t\twhile (x <= n && done[x]) x++;\r\n\t\t\tif (!used[i]) {\r\n\t\t\t\tif (a[i] > 2*x) {\r\n\t\t\t\t\tx++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? ans : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let narr = [],\r\n obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] > n) narr.push(arr[i]);\r\n else if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else narr.push(arr[i]);\r\n }\r\n narr.sort((a, b) => a - b);\r\n const helper = (arr) => {\r\n let ans = 0,\r\n k = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[i + 1] === 1) continue;\r\n else {\r\n if (arr[k++] > 2 * (i + 1)) ans++;\r\n else return -1;\r\n }\r\n }\r\n return ans;\r\n };\r\n console.log(helper(narr));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst rem = [];\r\n\t\tconst seq = new Set();\r\n\t\tfor (let i = 1; i <= n; i++) seq.add(i);\r\n\t\t\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (seq.has(a[i]))\r\n\t\t\t\tseq.delete(a[i]);\r\n\t\t\telse\r\n\t\t\t\trem.push(a[i]);\r\n\t\t}\r\n\r\n\t\trem.sort((x, y) => x - y);\r\n\r\n\t\tlet ok = true, it = seq.values();\r\n\t\tfor (let i = 0; ok && i < rem.length; i++) {\r\n\t\t\tok = rem[i] > 2*it.next().value;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? rem.length : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nminOperationToConvertToPermutation = (nums, n)=>{\r\n\r\n nums.sort((a,b)=>a-b);\r\n\r\n let set = new Set();\r\n let j = 1;\r\n let count = 0;\r\n for(let i =0; i < n; ++i){\r\n if(nums[i] <= n){\r\n if(!set.has(nums[i])){\r\n set.add(nums[i])\r\n continue;\r\n } \r\n }\r\n \r\n while(set.has(j)){\r\n j++;\r\n }\r\n if(nums[i] % (nums[i]-j) === j){\r\n set.add(j);\r\n count++;\r\n\r\n }\r\n else{\r\n console.log(-1);\r\n // console.log(set, nums[i], j)\r\n return;\r\n }\r\n \r\n }\r\n console.log(count);\r\n}\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n minOperationToConvertToPermutation(nums, n);\r\n }\r\n}"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = n;\r\n\t\tconst done = Array(n+1);\r\n\t\tconst used = Array(n+1);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] <= n && !done[a[i]]) {\r\n\t\t\t\tdone[a[i]] = true;\r\n\t\t\t\tused[i] = true;\r\n\t\t\t\tans--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0, x = 1; ok && i < n; i++) {\r\n\t\t\twhile (x <= n && !done[x]) x++;\r\n\t\t\tif (!used[i]) {\r\n\t\t\t\tif (a[i] > 2*x) {\r\n\t\t\t\t\tx++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? ans : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = n;\r\n\t\tconst b = new Set(a);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (b.has(i)) ans--;\r\n\t\t}\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\tif (a[i] == i+1 || a[i] > 2*(i+1))\r\n\t\t\t\t;\r\n\t\t\telse\r\n\t\t\t\tok = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? ans : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": " var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = 0, ok = true;\r\n\t\tfor (let i = 0; ok && i < n; i++) {\r\n\t\t\tif (a[i] == i+1 || i+1 <= a[i] - Math.ceil((a[i]+1)/2))\r\n\t\t\t\t;\r\n\t\t\telse\r\n\t\t\t\tok = false;\r\n\t\t\tans += a[i] != i + 1;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? ans : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n arr.sort((a, b) => a - b);\r\n const helper = () => {\r\n let ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === i + 1) continue;\r\n else if (arr[i] > 2 * (i + 1)) ans++;\r\n else return -1;\r\n }\r\n return ans;\r\n };\r\n console.log(helper());\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "85ad953161bb8841eed7c47a66381688"} {"source_code": "var nxy = readline().split(' ').map(item => +item);\nvar arr = readline().split(' ').map(item => +item);\n \nif(nxy[0] > 1) {\n for(var i = 0; i < nxy[0]; i++) {\n var first = i - nxy[1];\n var last = i + nxy[2] + 1;\n var ans = Math.min(...arr.slice(first > 0 ? first : 0, last));\n if(ans === arr[i]) {\n print(i + 1);\n break;\n }\n }\n} else {\n print(1);\n}\n", "positive_code": [{"source_code": "const processData = () => {\n const [ n, x, y ] = lines[0].split(/\\s/).map(Number)\n const a = lines[1].split(/\\s/).map(Number)\n const max = Math.pow(10, 10)\n let result = 0\n\n a.some((ai, i) => {\n const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, i + 1 + y))\n\n if(a[i] < leftMin && a[i] < rightMin) {\n result = i\n return true\n }\n\n return false\n })\n\n console.log(result + 1)\n}\n \nlet lines = ''\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n\n processData()\n})\n"}, {"source_code": "const processData = (lines) => {\n const [conditions, data] = lines\n const [n, x, y] = conditions.split(' ').map(x => +x)\n const realData = data.split(' ').map(x => +x)\n const max = Math.pow(10, 10)\n for (let i=0; i 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)\n const rightMin = realData.slice(i+1, i+1+y).reduce((r,x) => r < x ? r : x, max)\n if (realData[i] < leftMin && realData[i] < rightMin)\n return void console.log(i+1)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var numbers = readline().split(\" \").map(function (x){return parseInt(x)});\nvar days = readline().split(\" \").map(function (el){return parseInt(el)});\nvar x = numbers[1];\nvar y = numbers[2];\nvar n = numbers[0];\nvar min = Number.MAX_VALUE;\nvar streak=0;\nfunction look(k, val){\n for (var j = k+1; j <= k+y ; j++) {\n if (val>days[j]) {\n return false\n }\n }\n return true\n}\nfor (var i = 0; i < days.length; i++) {\n if (days[i] lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n\n main()\n})\n\nfunction main() {\n const [ n, x, y ] = lines[0].split(/\\s/).map(Number)\n const a = lines[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, i + y + 1))\n\n if(ai < leftMin && ai < rightMin) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var x = input[1];\n var y = input[2];\n var A = [null].concat(rdArN());\n \n for (var d = 1; d <= n; ++d) {\n var minL = +Infinity;\n for (var l = d-x; l <= d - 1; ++l) {\n minL = Math.min(minL, A[l] || +Infinity);\n }\n var minR = +Infinity;\n for (var r = d + 1; r <= d + y; ++r) {\n minR = Math.min(minR, A[r] || +Infinity);\n }\n var cur = A[d];\n if (cur < minL && cur < minR) {\n wr(d);\n break;\n }\n }\n\n /*var SL = new Set();\n var j = x + 1;\n for (var i = 1; i < j; ++i) {\n SL.add(A[i]);\n }\n var SR = new Set();\n for (var i = j + 1; i <= j + y; ++i) {\n SR.add(A[i]);\n }\n //pr(SL.size, SR.size);\n var d = j;\n for (var l1 = 1, l2 = d - 1, r1 = d + 1, r2 = d + y; r2 <= n;\n ++l1, ++l2, ++d, ++r1, ++r2\n ) {\n var minL = SL.values().next().value;\n var minR = SR.values().next().value;\n var cur = A[d];\n if (cur < minL && cur < minR) {\n wr(d);\n break;\n }\n SL.delete(A[l1]);\n SL.add(A[l2+1]);\n SR.delete(A[r1]);\n SR.add(A[r2+1]);\n }*/\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "const processData = (lines) => {\n const [conditions, data] = lines\n const [n, x, y] = conditions.split(' ')\n const realData = data.split(' ').map(x => +x)\n const max = Math.pow(10, 10)\n for (let i=0; i 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)\n const rightMin = realData.slice(i+1, i+y).reduce((r,x) => r < x ? r : x, max)\n if (realData[i] < leftMin && realData[i] < rightMin)\n return void console.log(i+1)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const [conditions, data] = lines\n const [n, x, y] = conditions.split(' ').map(x => +x)\n const realData = data.split(' ').map(x => +x)\n const max = Math.pow(10, 10)\n for (let i=0; i 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)\n const rightMin = realData.slice(i+1, i+y).reduce((r,x) => r < x ? r : x, max)\n if (realData[i] < leftMin && realData[i] < rightMin)\n return void console.log(i+1)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n})\n\nfunction checkMin(arr, ai, start, end, i) {\n start < 0 ? start = 0 : void 0\n end > arr.length - 1 ? end = arr.length - 1 : void 0\n\n const leftMin = Math.min.apply(null, arr.slice(start, i))\n const rightMin = Math.min.apply(null, arr.slice(i + 1, end + 1))\n\n return ai < leftMin && ai < rightMin\n}\n \nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n if(checkMin(a, ai, i - x, i + y, i)) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "// ad < aj should hold for all d\u2212x \u2264 j < d and d < j \u2264 d+y\n\nlet line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n \n process.exit(0)\n})\n\nfunction findMinIndex(arr, start, end) {\n let min = arr[0]\n let minIdx = null\n\n arr.forEach((v, i) => {\n if(i >= start && i < end) {\n if(v < min) {\n min = v\n minIdx = i\n }\n }\n })\n\n return { min, idx: minIdx }\n}\n\nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n\n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n\n a.some((ai, i) => {\n const { min, idx } = findMinIndex(a, i - x, i + y + 1)\n\n if(min === ai && i === idx) {\n result = idx\n return true\n }\n\n return false\n })\n\n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main()\n})\n\nfunction main() {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const start = i - x > 0 ? i - x : (0, i)\n const end = i + y\n const leftMin = Math.min.apply(null, a.slice(start, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))\n\n if(ai < leftMin && ai < rightMin) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "let lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n lines = lines.split(/\\n/)\n\n main()\n})\n\nfunction main() {\n const [ n, x, y ] = lines[0].split(/\\s/).map(Number)\n const a = lines[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, i + y + 1))\n\n if(ai < leftMin && ai < rightMin) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main()\n})\n\nfunction main() {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const start = i - x < 0 ? 0 : i - x\n const end = i + y > n - 1 ? n - 1 : i + y\n const leftMin = Math.min.apply(null, a.slice(start, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))\n\n if(ai < leftMin && ai < rightMin) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n \n process.exit(0)\n})\n\nfunction findMinIndex(arr, start, end) {\n let min = arr[0]\n let minIdx = null\n\n arr.forEach((v, i) => {\n if(i >= start && i < end) {\n if(v < min) {\n min = v\n minIdx = i\n }\n }\n })\n\n return { min, idx: minIdx }\n}\n\nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n\n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result\n\n a.some((ai, i) => {\n const { min, idx } = findMinIndex(a, i - x, i + y + 1)\n\n if(min === ai && i === idx) {\n result = idx\n return true\n }\n\n return false\n })\n\n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n})\n\nfunction checkMin(arr, ai, start, end, i) {\n start < 0 ? start = 0 : void 0\n end > arr.length - 1 ? end = arr.length - 1 : void 0\n\n const leftMin = Math.min.apply(null, arr.slice(start, i + 1))\n const rightMin = Math.min.apply(null, arr.slice(i, end + 1))\n\n return ai <= leftMin && ai <= rightMin\n}\n \nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n if(checkMin(a, ai, i - x, i + y, i)) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main()\n})\n\nfunction main() {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const start = i - x < 0 ? i : i - x\n const end = i + y\n const leftMin = Math.min.apply(null, a.slice(start, i))\n const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))\n\n if(ai < leftMin && ai < rightMin) {\n result = i\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n})\n \nfunction findMinIndex(arr, start, end, i) {\n start < 0 ? start = 0 : void 0\n\n let idx = start\n let min = arr[idx]\n \n arr.slice(start, end).forEach((v, i) => {\n if(v < min) {\n min = v\n idx = start + i\n }\n })\n\n return { min, idx }\n}\n \nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/).map(Number)\n let result = 0\n \n a.some((ai, i) => {\n const { min, idx } = findMinIndex(a, i - x, i + y + 1, i)\n \n if(min === ai && i === idx) {\n result = idx\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "let line = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', function (input) {\n line += (input.trim() + '\\n')\n})\n \nprocess.stdin.on('end', function () {\n main(line)\n})\n \nfunction findMin(arr, start, end) {\n start < 0 ? start = 0 : void 0\n\n let idx = start\n let min = Number(arr[idx])\n\n for(let i = start; i <= end; i++) {\n const v = Number(arr[i])\n\n if(v < min) {\n min = v\n idx = i\n }\n }\n\n return { min, idx }\n}\n \nfunction main(line) {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''))\n \n const [ n, x, y ] = line[0].split(/\\s/).map(Number)\n const a = line[1].split(/\\s/)\n let result = 0\n \n a.some((ai, i) => {\n const { min, idx } = findMin(a, i - x, i + y)\n \n if(min === Number(ai) && i === idx) {\n result = idx\n return true\n }\n \n return false\n })\n \n console.log(result + 1)\n}\n"}, {"source_code": "var nxy = readline().split(' ').map(item => +item);\nvar arr = readline().split(' ').map(item => +item);\n\nif(nxy[0] > 1) {\n var pr = true;\n \n if(arr[0] < arr[1]) {\n var ans = Math.min(...arr.slice(0, nxy[2]));\n if(ans === arr[0]) {\n print(1);\n pr = false;\n }\n }\n \n if (pr) {\n for(var i = 1; i < arr.length - 1; i++) {\n var start = i - nxy[1];\n var end = i + nxy[2] + 1;\n var ans = Math.min(...arr.slice(start < 0 ? start : 0, end));\n if(ans === arr[i]) {\n print(i + 1);\n pr = false;\n break;\n }\n }\n }\n \n if(pr) {\n print(arr.length);\n }\n} else {\n print(1);\n}\n"}], "src_uid": "5e2a5ee02c1a2f35a52e76cde96463a3"} {"source_code": "test = readline();\r\n\r\nwhile (test--) {\r\n\r\n ans = [];\r\n taken = {};\r\n tmp = [];\r\n\r\n sizeOfDeck = readline();\r\n orginalDeck = readline().split(' ').map(x => parseInt(x));\r\n\r\n for (var i = sizeOfDeck - 1; i >= 0; i--) {\r\n if (orginalDeck[i] == sizeOfDeck) {\r\n sizeOfDeck--;\r\n\r\n ans.push(orginalDeck[i]);\r\n\r\n for (var j = tmp.length - 1; j >= 0; j--) {\r\n ans.push(tmp[j]);\r\n taken[tmp[j]] = true;\r\n }\r\n tmp = [];\r\n for(var j = sizeOfDeck; j > 0;j--) {\r\n \r\n if(!taken.hasOwnProperty(j)) {\r\n break;\r\n } \r\n sizeOfDeck--;\r\n } \r\n continue;\r\n }\r\n tmp.push(orginalDeck[i]);\r\n\r\n }\r\n print(...ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var a = new Array(n + 1).fill(0)\r\n\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var pos = new Array(n)\r\n for (let i = 0; i < a.length; i++) {\r\n pos[a[i]] = i\r\n }\r\n var right = n\r\n var answer = []\r\n for (let i = n; i >= 0; i--) {\r\n // console.log(i,pos[i], right)\r\n if (pos[i] > right) continue\r\n for (let j = pos[i]; j < right; j++) {\r\n answer.push(a[j])\r\n }\r\n right = pos[i]\r\n }\r\n\r\n console.log(answer.join(' '))\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var a = new Array(n + 1).fill(0)\r\n\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n var locMax = new Array(n).fill(0)\r\n locMax[0] = a[0]\r\n for (var i = 1; i < n; i++) {\r\n locMax[i] = Math.max(locMax[i - 1], a[i])\r\n // locMax[i] = Math.min(locMax[i], a[i])\r\n }\r\n var index = new Array(n).fill(0)\r\n var ii = 0\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (locMax[i] === a[i]) {\r\n index[a[i]] = i\r\n ii = i\r\n } else {\r\n index[a[i]] = ii\r\n }\r\n }\r\n // console.log(locMax)\r\n // console.log(index)\r\n\r\n var array = []\r\n var currect = []\r\n var last = n - 1\r\n var i = n - 1\r\n while (i >= 0) {\r\n\r\n var ii = index[a[i]]\r\n i = ii - 1\r\n\r\n var max = locMax[ii]\r\n while (locMax[ii] === max && ii < n) {\r\n array.push(a[ii])\r\n ii++\r\n }\r\n }\r\n\r\n console.log(array.join(' '))\r\n })\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n console.log(1);\r\n continue;\r\n }\r\n let narr = [];\r\n narr.push({ val: arr[0], ind: 0 });\r\n for (let i = 1; i < n; i++) {\r\n let k = { val: narr[i - 1].val, ind: narr[i - 1].ind };\r\n narr.push(k);\r\n if (narr[i].val < arr[i]) narr[i].val = arr[i];\r\n narr[i].ind = i;\r\n }\r\n narr.sort((a, b) => b.val - a.val);\r\n let res = \"\";\r\n for (let i = 0; i < n; i++) res += arr[narr[i].ind] + \" \";\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var print = this.print || require('lol-io').print\r\nvar write = this.write || require('lol-io').write\r\nvar readline = this.readline || require('lol-io').readline\r\n\r\n\r\nvar t=parseInt(readline())\r\nvar a=new Array(100005).fill(0);\r\nvar mx=new Array(100005).fill(0);\r\n\twhile(t--){\r\n var n=parseInt(readline());\r\n var arr=readline().split(\" \").map(t=>parseInt(t));\r\n // console.log(arr);\r\n\t\tfor(var i=1;i<=n;i++) a[i]=arr[i-1],mx[i]=Math.max(mx[i-1],a[i]);\r\n var r=n;\r\n var re=[];\r\n\t\tfor(var i=n;i>=1;i--){\r\n\t\t\tif(mx[i]==a[i]){\r\n\t\t\t\tfor(var j=i;j<=r;j++)re.push(a[j]);\r\n\t\t\t\tr=i-1;\r\n\t\t\t}\r\n }\r\n print(re.join(\" \"))\r\n }\r\n"}, {"source_code": "\n\nconst processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n const c = +lines[cur]\n cur++\n const arr = lines[cur].split(' ').map(x => +x)\n const valueMap = {}\n for (const t of arr) {\n valueMap[t] = false\n }\n const final = []\n let target = c\n while (final.length < arr.length) {\n let b = arr.length - final.length\n let maxIndex = -1\n let maxValue = -1\n if (target !== -1) {\n while (b--) {\n if (arr[b] === target) {\n maxValue = target\n maxIndex = b\n target = -1\n break\n }\n }\n } else {\n while (b--) {\n if (arr[b] > maxValue) {\n maxValue = arr[b]\n maxIndex = b\n }\n }\n }\n let start = maxIndex\n const end = arr.length - final.length\n let possibleTarget = maxValue - 1\n while (start < end) {\n final.push(arr[start])\n valueMap[arr[start]] = true\n start++\n }\n while(valueMap[possibleTarget] === true) {\n possibleTarget--\n }\n target = possibleTarget\n // console.log('final', final)\n }\n console.log(final.join(' '))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "\n\nconst processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n const c = +lines[cur]\n cur++\n const arr = lines[cur].split(' ').map(x => +x)\n const final = []\n let target = c\n while (final.length < arr.length) {\n let b = arr.length - final.length\n let maxIndex = -1\n let maxValue = -1\n if (target !== -1) {\n while (b--) {\n if (arr[b] === target) {\n maxValue = target\n maxIndex = b\n target = -1\n break\n }\n }\n } else {\n while (b--) {\n if (arr[b] > maxValue) {\n maxValue = arr[b]\n maxIndex = b\n }\n }\n }\n let start = maxIndex\n const end = arr.length - final.length\n let possibleTarget = maxValue - 1\n let foundPossibleTarget = false\n while (start < end) {\n final.push(arr[start])\n if (!foundPossibleTarget && arr[start] === possibleTarget) {\n foundPossibleTarget = true\n }\n start++\n }\n if (!foundPossibleTarget) {\n target = possibleTarget\n }\n // console.log('final', final)\n }\n console.log(final.join(' '))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "\n\nconst processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n const c = +lines[cur]\n cur++\n const arr = lines[cur].split(' ').map(x => +x)\n let t = 0\n while (t < arr.length) {\n let b = arr.length - t\n let maxIndex = -1\n let maxValue = -1\n const possibleMax = b\n while (b--) {\n if (arr[b] > maxValue) {\n maxValue = arr[b]\n maxIndex = b\n if (maxValue === possibleMax) {\n break\n }\n }\n }\n let start = maxIndex\n const end = arr.length - t\n t += end - start\n while (start < end) {\n process.stdout.write(arr[start] + ' ')\n start++\n }\n }\n process.stdout.write('\\n')\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const findMax = (arr, n) => {\n return arr.reduce((res, num, index) => {\n // console.log('num', num)\n if (num > res.value) {\n return {index, value: num}\n }\n return res\n }, {index: -1, value: 0n})\n}\n\nconst processData = (lines) => {\n let n = +lines[0]\n let cur = 0\n while(n--) {\n cur++\n const c = +lines[cur]\n cur++\n const arr = lines[cur].split(' ').map(x => +x)\n const final = []\n while (final.length < arr.length) {\n let b = arr.length - final.length\n const t = b\n let maxIndex = -1\n while (b--) {\n if (arr[b] === t) {\n maxIndex = b\n }\n }\n let start = maxIndex\n const end = arr.length - final.length\n while (start < end) {\n final.push(arr[start])\n start++\n }\n // console.log('final', final)\n }\n console.log(final.map(x => x.toString(10)).join(' '))\n }\n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "1637670255f8bd82a01e2ab20cdcc9aa"} {"source_code": "const solve = (n, x, a) => {\r\n a = a.map(x => [x, 1]);\r\n let res = 0;\r\n let flag = true;\r\n for (let i = 0; i < a.length; i++) {\r\n let tmp = a[i];\r\n res += tmp[0] * tmp[1];\r\n if (tmp[0] % x) flag = false;\r\n if (flag) a.push([parseInt(tmp[0] / x), tmp[1] * x]);\r\n }\r\n console.log(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n let obj = { val: arr[i], m: 1 };\r\n arr[i] = obj;\r\n }\r\n let sum = 0,\r\n flag = true;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i].val % x) flag = false;\r\n if (flag) {\r\n let obj = { val: arr[i].val / x, m: arr[i].m * x };\r\n arr.push(obj);\r\n }\r\n sum += arr[i].val * arr[i].m;\r\n }\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst [len, x] = readLine().split(' ').map(Number);\n\t\tlet sum = 0;\n\t\tconst arr = readLine()\n\t\t\t.split(' ')\n\t\t\t.map((n) => {\n\t\t\t\tn = Number(n);\n\t\t\t\tsum += n;\n\t\t\t\treturn n;\n\t\t\t});\n\t\tconst store = [];\n\t\tlet [minIndex, min] = [Infinity, Infinity];\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tlet [count, n] = [0, arr[i]];\n\t\t\twhile (n % x === 0) {\n\t\t\t\tn = n / x;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif (count < min) {\n\t\t\t\tmin = count;\n\t\t\t\tminIndex = i;\n\t\t\t}\n\t\t}\n\t\tsum += sum * min;\n\t\tfor (let i = 0; i < minIndex; i++) sum += arr[i];\n\n\t\tconsole.log(sum);\n\t}\n}\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 2; i += 2) {\r\n let split = lines[i].split(' ');\r\n const n = parseInt(split[0]);\r\n const x = parseInt(split[1]);\r\n\r\n const arr = lines[i + 1].split(' ').map(num => parseInt(num));\r\n\r\n solve(n, x, arr);\r\n }\r\n});\r\n\r\nfunction solve(n, x, arr) {\r\n let sum = 0;\r\n let coeff = [];\r\n\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n coeff[i] = 1;\r\n }\r\n\r\n let i = 0;\r\n\r\n while (i < arr.length) {\r\n if (arr[i] % x === 0) {\r\n sum += arr[i] * coeff[i];\r\n arr.push(Math.floor(arr[i] / x));\r\n coeff.push(coeff[i] * x);\r\n } else {\r\n break;\r\n }\r\n\r\n i++;\r\n }\r\n\r\n console.log(sum);\r\n}\r\n"}, {"source_code": "// Generated by CoffeeScript 2.4.1\nvar A, _, a, b, i, iters, j, k, l, len, min, mult, mults, n, nr, nrs, nx, ref, ref1, sum, x;\n\nnrs = function() {\n var i, j, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (j = 0, len = ref.length; j < len; j++) {\n i = ref[j];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\n\nfunction zip(a, b) {\n var arr = [];\n for (var key in a) arr.push([a[key], b[key]]);\n return arr;\n}\n;\n\nmin = function(arr) {\n var best, item, j, len;\n best = arr[0];\n for (j = 0, len = arr.length; j < len; j++) {\n item = arr[j];\n if (item < best) {\n best = item;\n }\n }\n return best;\n};\n\nfor (_ = j = 0, ref = nr(); (0 <= ref ? j < ref : j > ref); _ = 0 <= ref ? ++j : --j) {\n nx = nrs();\n n = nx[0];\n x = nx[1];\n A = nrs();\n a = A.shift();\n mult = 0;\n mults = [];\n while (a % Math.pow(x, mult + 1) === 0) {\n mult += 1;\n }\n mults.push(mult);\n for (k = 0, len = A.length; k < len; k++) {\n b = A[k];\n while (b % Math.pow(x, mult)) {\n mult -= 1;\n }\n mults.push(mult);\n }\n iters = 1 + min(mults);\n A.unshift(a);\n sum = 0;\n for (i = l = 0, ref1 = A.length; (0 <= ref1 ? l < ref1 : l > ref1); i = 0 <= ref1 ? ++l : --l) {\n sum += A[i] * (Math.min(iters, mults[i]) + 1);\n }\n print(sum);\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2lzc3pvdHMuanMiLCJzb3VyY2VSb290IjoiLi4iLCJzb3VyY2VzIjpbImNvZmZlZVxca2lzc3pvdHMuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLEtBQUEsRUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxHQUFBLEVBQUE7O0FBQUEsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBVztBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFkOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQUFHLEdBQUEsQ0FBQSxDQUFNLENBQUEsQ0FBQTtBQUFUOztBQUVMOzs7Ozs7OztBQVFBLEdBQUEsR0FBTSxRQUFBLENBQUMsR0FBRCxDQUFBO0FBQ0wsTUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQTtFQUFBLElBQUEsR0FBTyxHQUFJLENBQUEsQ0FBQTtFQUNYLEtBQUEscUNBQUE7O0lBQ0MsSUFBRyxJQUFBLEdBQU8sSUFBVjtNQUFvQixJQUFBLEdBQUssS0FBekI7O0VBREQ7U0FFQTtBQUpLOztBQU1OLEtBQVMsK0VBQVQ7RUFDQyxFQUFBLEdBQUssR0FBQSxDQUFBO0VBQ0wsQ0FBQSxHQUFJLEVBQUcsQ0FBQSxDQUFBO0VBQ1AsQ0FBQSxHQUFJLEVBQUcsQ0FBQSxDQUFBO0VBQ1AsQ0FBQSxHQUFJLEdBQUEsQ0FBQTtFQUVKLENBQUEsR0FBSSxDQUFDLENBQUMsS0FBRixDQUFBO0VBQ0osSUFBQSxHQUFPO0VBQ1AsS0FBQSxHQUFRO0FBQ1IsU0FBTSxDQUFBLEdBQUksSUFBSSxDQUFDLEdBQUwsQ0FBUyxDQUFULEVBQVcsSUFBQSxHQUFLLENBQWhCLENBQUosS0FBMEIsQ0FBaEM7SUFDQyxJQUFBLElBQU07RUFEUDtFQUVBLEtBQUssQ0FBQyxJQUFOLENBQVcsSUFBWDtFQUNBLEtBQUEsbUNBQUE7O0FBQ0MsV0FBTSxDQUFBLEdBQUksSUFBSSxDQUFDLEdBQUwsQ0FBUyxDQUFULEVBQVcsSUFBWCxDQUFWO01BQ0MsSUFBQSxJQUFRO0lBRFQ7SUFFQSxLQUFLLENBQUMsSUFBTixDQUFXLElBQVg7RUFIRDtFQUlBLEtBQUEsR0FBUSxDQUFBLEdBQUksR0FBQSxDQUFJLEtBQUo7RUFDWixDQUFDLENBQUMsT0FBRixDQUFVLENBQVY7RUFFQSxHQUFBLEdBQU07RUFDTixLQUFTLHdGQUFUO0lBQ0MsR0FBQSxJQUFPLENBQUUsQ0FBQSxDQUFBLENBQUYsR0FBTyxDQUFDLElBQUksQ0FBQyxHQUFMLENBQVMsS0FBVCxFQUFlLEtBQU0sQ0FBQSxDQUFBLENBQXJCLENBQUEsR0FBeUIsQ0FBMUI7RUFEZjtFQUVBLEtBQUEsQ0FBTSxHQUFOO0FBdEJEIiwic291cmNlc0NvbnRlbnQiOlsibnJzID0gLT4gcGFyc2VJbnQgaSBmb3IgaSBpbiByZWFkbGluZSgpLnNwbGl0ICcgJ1xyXG5uciA9IC0+IG5ycygpWzBdXHJcblxyXG5gYGBcclxuZnVuY3Rpb24gemlwKGEsIGIpIHtcclxuICB2YXIgYXJyID0gW107XHJcbiAgZm9yICh2YXIga2V5IGluIGEpIGFyci5wdXNoKFthW2tleV0sIGJba2V5XV0pO1xyXG4gIHJldHVybiBhcnI7XHJcbn1cclxuYGBgXHJcblxyXG5taW4gPSAoYXJyKSAtPlxyXG5cdGJlc3QgPSBhcnJbMF1cclxuXHRmb3IgaXRlbSBpbiBhcnJcclxuXHRcdGlmIGl0ZW0gPCBiZXN0IHRoZW4gYmVzdD1pdGVtXHJcblx0YmVzdFxyXG5cclxuZm9yIF8gaW4gWzAuLi5ucigpXVxyXG5cdG54ID0gbnJzKClcclxuXHRuID0gbnhbMF1cclxuXHR4ID0gbnhbMV1cclxuXHRBID0gbnJzKClcclxuXHJcblx0YSA9IEEuc2hpZnQoKVxyXG5cdG11bHQgPSAwXHJcblx0bXVsdHMgPSBbXVxyXG5cdHdoaWxlIGEgJSBNYXRoLnBvdyh4LG11bHQrMSkgPT0gMFxyXG5cdFx0bXVsdCs9MVxyXG5cdG11bHRzLnB1c2ggbXVsdFxyXG5cdGZvciBiIGluIEFcclxuXHRcdHdoaWxlIGIgJSBNYXRoLnBvdyh4LG11bHQpXHJcblx0XHRcdG11bHQgLT0gMVxyXG5cdFx0bXVsdHMucHVzaCBtdWx0XHJcblx0aXRlcnMgPSAxICsgbWluIG11bHRzXHJcblx0QS51bnNoaWZ0IGFcclxuXHJcblx0c3VtID0gMFxyXG5cdGZvciBpIGluIFswLi4uQS5sZW5ndGhdXHJcblx0XHRzdW0gKz0gQVtpXSAqIChNYXRoLm1pbihpdGVycyxtdWx0c1tpXSkrMSlcclxuXHRwcmludCBzdW1cclxuIl19\n//# sourceURL=c:\\github\\2021\\008-CodeForces-1100\\1471B\\coffee\\kisszots.coffee"}, {"source_code": "// Generated by CoffeeScript 2.4.1\nvar A, _, a, b, iters, j, k, l, len, len1, min, mult, multb, mults, n, nr, nrs, nx, ref, ref1, sum, x;\n\nnrs = function() {\n var i, j, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (j = 0, len = ref.length; j < len; j++) {\n i = ref[j];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\n\nfunction zip(a, b) {\n var arr = [];\n for (var key in a) arr.push([a[key], b[key]]);\n return arr;\n}\n;\n\nmin = function(arr) {\n var best, item, j, len;\n best = arr[0];\n for (j = 0, len = arr.length; j < len; j++) {\n item = arr[j];\n if (item < best) {\n best = item;\n }\n }\n return best;\n};\n\nfor (_ = j = 0, ref = nr(); (0 <= ref ? j < ref : j > ref); _ = 0 <= ref ? ++j : --j) {\n nx = nrs();\n n = nx[0];\n x = nx[1];\n A = nrs();\n a = A.shift();\n mult = 0;\n mults = [];\n while (a % Math.pow(x, mult + 1) === 0) {\n mult += 1;\n }\n mults.push(mult);\n for (k = 0, len = A.length; k < len; k++) {\n b = A[k];\n while (b % Math.pow(x, mult)) {\n mult -= 1;\n }\n mults.push(mult);\n }\n iters = 1 + min(mults);\n A.unshift(a);\n sum = 0;\n ref1 = zip(mults, A);\n for (l = 0, len1 = ref1.length; l < len1; l++) {\n multb = ref1[l];\n mult = multb[0];\n b = multb[1];\n sum += b * (Math.min(iters, mult) + 1);\n }\n print(sum);\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2lzc3pvdHMuanMiLCJzb3VyY2VSb290IjoiLi4iLCJzb3VyY2VzIjpbImNvZmZlZVxca2lzc3pvdHMuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxLQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLEtBQUEsRUFBQSxLQUFBLEVBQUEsQ0FBQSxFQUFBLEVBQUEsRUFBQSxHQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsR0FBQSxFQUFBOztBQUFBLEdBQUEsR0FBTSxRQUFBLENBQUEsQ0FBQTtBQUFHLE1BQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsR0FBQSxFQUFBO0FBQVc7QUFBQTtFQUFBLEtBQUEscUNBQUE7O2lCQUFYLFFBQUEsQ0FBUyxDQUFUO0VBQVcsQ0FBQTs7QUFBZDs7QUFDTixFQUFBLEdBQUssUUFBQSxDQUFBLENBQUE7U0FBRyxHQUFBLENBQUEsQ0FBTSxDQUFBLENBQUE7QUFBVDs7QUFFTDs7Ozs7Ozs7QUFRQSxHQUFBLEdBQU0sUUFBQSxDQUFDLEdBQUQsQ0FBQTtBQUNMLE1BQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxJQUFBLEdBQU8sR0FBSSxDQUFBLENBQUE7RUFDWCxLQUFBLHFDQUFBOztJQUNDLElBQUcsSUFBQSxHQUFPLElBQVY7TUFBb0IsSUFBQSxHQUFLLEtBQXpCOztFQUREO1NBRUE7QUFKSzs7QUFNTixLQUFTLCtFQUFUO0VBQ0MsRUFBQSxHQUFLLEdBQUEsQ0FBQTtFQUNMLENBQUEsR0FBSSxFQUFHLENBQUEsQ0FBQTtFQUNQLENBQUEsR0FBSSxFQUFHLENBQUEsQ0FBQTtFQUNQLENBQUEsR0FBSSxHQUFBLENBQUE7RUFFSixDQUFBLEdBQUksQ0FBQyxDQUFDLEtBQUYsQ0FBQTtFQUNKLElBQUEsR0FBTztFQUNQLEtBQUEsR0FBUTtBQUNSLFNBQU0sQ0FBQSxHQUFJLElBQUksQ0FBQyxHQUFMLENBQVMsQ0FBVCxFQUFXLElBQUEsR0FBSyxDQUFoQixDQUFKLEtBQTBCLENBQWhDO0lBQ0MsSUFBQSxJQUFNO0VBRFA7RUFFQSxLQUFLLENBQUMsSUFBTixDQUFXLElBQVg7RUFDQSxLQUFBLG1DQUFBOztBQUNDLFdBQU0sQ0FBQSxHQUFJLElBQUksQ0FBQyxHQUFMLENBQVMsQ0FBVCxFQUFXLElBQVgsQ0FBVjtNQUNDLElBQUEsSUFBUTtJQURUO0lBRUEsS0FBSyxDQUFDLElBQU4sQ0FBVyxJQUFYO0VBSEQ7RUFJQSxLQUFBLEdBQVEsQ0FBQSxHQUFJLEdBQUEsQ0FBSSxLQUFKO0VBQ1osQ0FBQyxDQUFDLE9BQUYsQ0FBVSxDQUFWO0VBRUEsR0FBQSxHQUFNO0FBQ047RUFBQSxLQUFBLHdDQUFBOztJQUNDLElBQUEsR0FBTyxLQUFNLENBQUEsQ0FBQTtJQUNiLENBQUEsR0FBSSxLQUFNLENBQUEsQ0FBQTtJQUNWLEdBQUEsSUFBTyxDQUFBLEdBQUksQ0FBQyxJQUFJLENBQUMsR0FBTCxDQUFTLEtBQVQsRUFBZSxJQUFmLENBQUEsR0FBcUIsQ0FBdEI7RUFIWjtFQUlBLEtBQUEsQ0FBTSxHQUFOO0FBeEJEIiwic291cmNlc0NvbnRlbnQiOlsibnJzID0gLT4gcGFyc2VJbnQgaSBmb3IgaSBpbiByZWFkbGluZSgpLnNwbGl0ICcgJ1xyXG5uciA9IC0+IG5ycygpWzBdXHJcblxyXG5gYGBcclxuZnVuY3Rpb24gemlwKGEsIGIpIHtcclxuICB2YXIgYXJyID0gW107XHJcbiAgZm9yICh2YXIga2V5IGluIGEpIGFyci5wdXNoKFthW2tleV0sIGJba2V5XV0pO1xyXG4gIHJldHVybiBhcnI7XHJcbn1cclxuYGBgXHJcblxyXG5taW4gPSAoYXJyKSAtPlxyXG5cdGJlc3QgPSBhcnJbMF1cclxuXHRmb3IgaXRlbSBpbiBhcnJcclxuXHRcdGlmIGl0ZW0gPCBiZXN0IHRoZW4gYmVzdD1pdGVtXHJcblx0YmVzdFxyXG5cclxuZm9yIF8gaW4gWzAuLi5ucigpXVxyXG5cdG54ID0gbnJzKClcclxuXHRuID0gbnhbMF1cclxuXHR4ID0gbnhbMV1cclxuXHRBID0gbnJzKClcclxuXHJcblx0YSA9IEEuc2hpZnQoKVxyXG5cdG11bHQgPSAwXHJcblx0bXVsdHMgPSBbXVxyXG5cdHdoaWxlIGEgJSBNYXRoLnBvdyh4LG11bHQrMSkgPT0gMFxyXG5cdFx0bXVsdCs9MVxyXG5cdG11bHRzLnB1c2ggbXVsdFxyXG5cdGZvciBiIGluIEFcclxuXHRcdHdoaWxlIGIgJSBNYXRoLnBvdyh4LG11bHQpXHJcblx0XHRcdG11bHQgLT0gMVxyXG5cdFx0bXVsdHMucHVzaCBtdWx0XHJcblx0aXRlcnMgPSAxICsgbWluIG11bHRzXHJcblx0QS51bnNoaWZ0IGFcclxuXHJcblx0c3VtID0gMFxyXG5cdGZvciBtdWx0YiBpbiB6aXAgbXVsdHMsQVxyXG5cdFx0bXVsdCA9IG11bHRiWzBdXHJcblx0XHRiID0gbXVsdGJbMV1cclxuXHRcdHN1bSArPSBiICogKE1hdGgubWluKGl0ZXJzLG11bHQpKzEpXHJcblx0cHJpbnQgc3VtXHJcbiJdfQ==\n//# sourceURL=c:\\github\\2021\\008-CodeForces-1100\\1471B\\coffee\\kisszots.coffee"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let n = input[0];\r\n let x = input[1];\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n let result = 0;\r\n let iters = [];\r\n \r\n for(let j = 0; j < n; j++){\r\n iters.push(getIter(arr[j], x));\r\n }\r\n let minIter = findMin(iters);\r\n let index = iters.indexOf(minIter);\r\n print(sumArr(arr.slice(0, index)) * (minIter + 2) + sumArr(arr.slice(index, arr.length)) * (minIter + 1))\r\n}\r\n\r\nfunction getIter(num, x){\r\n let i;\r\n for(i = 0; num % x === 0; i++){\r\n num /= x;\r\n }\r\n return i;\r\n}\r\n\r\nfunction sumArr(arr){\r\n let res = 0;\r\n for(let i = 0; i < arr.length; i++){\r\n res += arr[i];\r\n }\r\n return res;\r\n}\r\n\r\nfunction findMin(arr){\r\n let res = arr[0];\r\n for(let i = 1; i < arr.length; i++){\r\n if(arr[i] < res){\r\n res = arr[i];\r\n }\r\n }\r\n return res;\r\n}"}, {"source_code": "const solve = (n, x, a) => {\r\n let res = 0;\r\n let flag = true;\r\n for (let i = 0; i < a.length; i++) {\r\n let tmp = a[i];\r\n res += tmp[0] * tmp[1];\r\n if (tmp[0] % x) flag = false;\r\n if (flag) a.push([parseInt(tmp[0] / x), tmp[1] * x]);\r\n }\r\n console.log(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => [Number(x), 1]));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0][0], input[i][1][0], input[i + 1])\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const solve = (n, x, a) => {\r\n let res = 0;\r\n let flag = true;\r\n for (let i = 0; i < a.length; i++) {\r\n let tmp = a[i];\r\n res += tmp[0] * tmp[1];\r\n if (tmp[0] % x) flag = false;\r\n if (flag) a.push([parseInt(tmp[0] / x), tmp[1] * x]);\r\n }\r\n console.log(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => [Number(x), 1]));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0][0], data[0][1][0], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const solve = (n, x, a) => {\r\n a = a.map(x => [x, 1]);\r\n let res = 0;\r\n let flag = true;\r\n for (let i = 0; i < a.length; i++) {\r\n let tmp = a[i];\r\n res += tmp[0] * tmp[1];\r\n if (tmp[0] % x) flag = false;\r\n if (flag) a.push([parseInt(tmp[0] / x), tmp[1] * x]);\r\n }\r\n console.log(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[0][1], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let [n,q] = readline().split(' ').map(x => +x),\n counts = [],\n nums = readline().split(' ').map(x => {\n counts.push(1)\n return +x\n }),\n sum = 0,\n num = 0\n let i=0\n while(nums[i] % q == 0) {\n num = parseInt(nums[i]/q)\n nums.push(num)\n counts.push(q * counts[i])\n sum += nums[i] * counts[i]\n i++\n }\n while (i < nums.length) {\n sum += nums[i] * counts[i]\n i++\n }\n console.log(sum)\n // for (let i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(1)\r\n return Number(x)\r\n });\r\n\r\n var i=0\r\n while (array[i] % xx === 0) {\r\n array.push(array[i] / xx)\r\n array2.push(array2[i]*xx)\r\n i++\r\n }\r\n var sum = 0\r\n array.map((x,i)=>{\r\n sum+=array[i]*array2[i]\r\n // console.log(sum)\r\n\r\n })\r\n // console.log(array)\r\n // console.log(array2)\r\n\r\n\r\n console.log(sum)\r\n\r\n })\r\n\r\n\r\n}\r\n"}], "negative_code": [{"source_code": "const solve = (n, x, a) => {\r\n a = a.map(x => [x, 1]);\r\n let res = 0;\r\n let flag = true;\r\n for (let i = 0; i < a.length; i++) {\r\n let tmp = a[i];\r\n res += tmp[0] * tmp[1];\r\n if (tmp[0] % x) flag = false;\r\n if (flag) a.push([parseInt(tmp[0] / x), tmp[1] * x]);\r\n }\r\n console.log(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n console.log(input);\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n \n}\n\n// function to solve problems\nfunction solve (){\n let [n,q] = readline().split(' ').map(x => +x)\n // let q = arr[1], k = arr[2]\n let arr = readline().split(' ').map(x => +x),\n ans = 0,\n maxLevel = Number.MAX_SAFE_INTEGER,\n num = 0,\n currentLevel = 0\n\n // ====== SOLUTION ======\n for (let i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n \n}\n\n// function to solve problems\nfunction solve (){\n let [n,q] = readline().split(' ').map(x => +x)\n // let q = arr[1], k = arr[2]\n let arr = readline().split(' ').map(x => +x),\n ans = 0,\n maxLevel = Number.MAX_SAFE_INTEGER,\n num = 0,\n currentLevel = 0\n\n // ====== SOLUTION ======\n for (let i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => BigInt(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(1n)\r\n return BigInt(x)\r\n });\r\n\r\n var i=0\r\n while (array[i] % xx === 0n) {\r\n array.push(array[i] / xx)\r\n array2.push(array2[i]*2n)\r\n i++\r\n }\r\n var sum = 0n\r\n array.map((x,i)=>{\r\n sum+=array[i]*array2[i]\r\n\r\n })\r\n // console.log(array)\r\n // console.log(array2)\r\n\r\n\r\n console.log(sum.toString())\r\n\r\n })\r\n\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(1)\r\n return Number(x)\r\n });\r\n\r\n var i=0\r\n while (array[i] % xx === 0) {\r\n array.push(array[i] / xx)\r\n array2.push(array2[i]*2)\r\n i++\r\n }\r\n var sum = 0\r\n array.map((x,i)=>{\r\n sum+=array[i]*array2[i]\r\n\r\n })\r\n // console.log(array)\r\n // console.log(array2)\r\n\r\n\r\n console.log(sum)\r\n\r\n })\r\n\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(1)\r\n return Number(x)\r\n });\r\n\r\n var i=0\r\n while (array[i] % x === 0) {\r\n array.push(array[i] / x)\r\n array2.push(array2[i]*2)\r\n i++\r\n }\r\n var sum = 0\r\n array.map((x,i)=>{\r\n sum+=array[i]*array2[i]\r\n\r\n })\r\n // console.log(array)\r\n // console.log(array2)\r\n\r\n\r\n console.log(sum)\r\n\r\n })\r\n\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => BigInt(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(BigInt(x))\r\n return BigInt(x)\r\n });\r\n\r\n var sum = 0n\r\n var stop = false\r\n\r\n array.map((x, i) => {\r\n var remember = x\r\n if (stop) return\r\n if (x % xx !== 0n) {\r\n stop = true\r\n }\r\n if (x % xx === 0n) {\r\n sum += remember\r\n array[i] = array[i] / xx\r\n }\r\n })\r\n // console.log(sum, array2)\r\n\r\n var i = 0n\r\n stop = false\r\n var stopi = 0\r\n while (true) {\r\n // var remember = x\r\n if (stop && i === stopi) break\r\n // console.log(array[i], i)\r\n if (array[i] % xx !== 0n && !stop) {\r\n // sum += array2[i]\r\n stop = true\r\n stopi = i\r\n }\r\n sum += array2[i]\r\n array[i] = array[i] / xx\r\n // console.log(array, i, sum)\r\n\r\n i++\r\n if (i === n) i = 0n\r\n }\r\n\r\n console.log(sum.toString())\r\n\r\n })\r\n\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, xx] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array2 = []\r\n var array = readline().split(' ').map(x => {\r\n array2.push(Number(x))\r\n return Number(x)\r\n });\r\n\r\n var sum = 0\r\n var stop = false\r\n\r\n array.map((x, i) => {\r\n var remember = x\r\n if (stop) return\r\n if (x % xx !== 0) {\r\n stop = true\r\n }\r\n if (x % xx === 0) {\r\n sum += remember\r\n array[i] = array[i] / xx\r\n }\r\n })\r\n // console.log(sum, array2)\r\n\r\n var i = 0\r\n stop = false\r\n var stopi = 0\r\n while (true) {\r\n // var remember = x\r\n if (stop && i === stopi) break\r\n if (array[i] % xx !== 0 && !stop) {\r\n // sum += array2[i]\r\n stop = true\r\n stopi = i\r\n }\r\n sum += array2[i]\r\n array[i] = array[i] / xx\r\n // console.log(array, i, sum)\r\n\r\n i++\r\n if (i === n) i = 0\r\n }\r\n\r\n console.log(sum)\r\n\r\n })\r\n\r\n\r\n}\r\n"}], "src_uid": "09c8db43681d7bc72f83287897a62f3c"} {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet merge = (h1, h2)=>{\n if (!h1 || !h2)\n return h1||h2;\n if (h2.value < h1.value)\n return merge(h2, h1)\n if (Math.random()<0.5)\n h1.l = merge(h1.l, h2);\n else\n h1.r = merge(h1.r, h2);\n return h1;\n};\nclass Heap {\n constructor(value){\n this.value = value;\n this.l = null;\n this.r = null;\n }\n insert(value){\n return merge(new Heap(value), this);\n }\n top(){\n return this.value;\n }\n isEmpty(){\n return this.value===null;\n }\n}\n\nlet calc = (arr, n)=>{\n let heap = new Heap(arr[0]);\n for (let i=1; i{\n let sum = 0;\n for (let a of arr)\n sum += a;\n let cnt_map = new Map();\n for (let a of arr)\n cnt_map.set(a, (cnt_map.get(a)||0) + 1);\n let A = [sum], pos = 0;\n while (pos cxcode\n// xcode\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = ra();\n print(calc2(arr, n) ? 'yes' : 'no');\n }\n}\n\n//9: 4 5, 2 2 5 ", "positive_code": [{"source_code": "class PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\nvar stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefineed\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst have = new PriorityQueue((a, b) => a > b);\r\n\t\tconst need = new PriorityQueue((a, b) => a > b);\r\n\r\n\t\tlet sum = 0; for (let i = 0; i < n; i++) sum += a[i];\r\n\t\thave.push(sum);\r\n\t\tfor (let i = 0; i < n; i++) need.push(a[i]);\r\n\r\n\t\twhile (need.size() && have.peek() >= need.peek()) {\r\n\t\t\tif (have.peek() == need.peek()) { \r\n\t\t\t\tneed.pop(), have.pop(); \r\n\t\t\t} else {\r\n\t\t\t\tconst x = have.pop();\r\n\t\t\t\thave.push(Math.floor(x/2), Math.ceil(x/2));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(need.size() == 0 ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "class PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// demo\r\nvar stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst nidq = new PriorityQueue((a, b) => a > b);\r\n\t\tconst curq = new PriorityQueue((a, b) => a > b);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < n; i++) { \r\n\t\t\tnidq.push(a[i]);\r\n\t\t\tsum += a[i];\r\n\t\t}\r\n\t\tcurq.push(sum);\r\n\r\n\t\twhile (curq.size() && nidq.size() && curq.peek() >= nidq.peek()) {\r\n\t\t\tif (curq.peek() == nidq.peek()) { \r\n\t\t\t\tnidq.pop(), curq.pop(); \r\n\t\t\t\tcontinue; \r\n\t\t\t}\r\n\t\t\tconst x = curq.pop();\r\n\t\t\tcurq.push(Math.floor(x/2));\r\n\t\t\tcurq.push(Math.ceil(x/2));\r\n\t\t}\r\n\r\n\t\tconst ans = curq.size() + nidq.size() == 0; \r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n a.sort((a, b) => b - a);\r\n const map = new Map();\r\n let sum = 0;\r\n for (let num of a) {\r\n var _map$get;\r\n sum += num;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n let count = 0;\r\n const heap = new Heap((a, b) => b - a);\r\n heap.push(sum);\r\n while (count++ < n) {\r\n let cur = heap.top();\r\n while (map.get(cur)) {\r\n heap.pop();\r\n map.set(cur, map.get(cur) - 1);\r\n cur = heap.top();\r\n }\r\n if (!heap.size()) break;\r\n cur = heap.pop();\r\n const x = Math.floor(cur / 2),\r\n y = cur - x;\r\n heap.push(x);\r\n heap.push(y);\r\n }\r\n if (n !== count || heap.size()) return 'NO';\r\n return 'YES';\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet merge = (h1, h2)=>{\n if (!h1 || !h2)\n return h1||h2;\n if (h2.value < h1.value)\n return merge(h2, h1)\n if (Math.random()<0.5)\n h1.l = merge(h1.l, h2);\n else\n h1.r = merge(h1.r, h2);\n return h1;\n};\nclass Heap {\n constructor(value){\n this.value = value;\n this.l = null;\n this.r = null;\n }\n insert(value){\n return merge(new Heap(value), this);\n }\n top(){\n return this.value;\n }\n isEmpty(){\n return this.value===null;\n }\n}\n\nlet calc = (arr, n)=>{\n let heap = new Heap(arr[0]);\n for (let i=1; i{\n let sum = 0;\n for (let a of arr)\n sum += a;\n let cnt_map = new Map();\n for (let a of arr)\n cnt_map.set(a, (cnt_map.get(a)||0) + 1);\n let A = [sum], pos = 0;\n while (pos cxcode\n// xcode\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = ra();\n print(calc2(arr, n) ? 'yes' : 'no');\n }\n}\n\n//9: 4 5, 2 2 5 "}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet merge = (h1, h2)=>{\n if (!h1 || !h2)\n return h1||h2;\n if (h2.value < h1.value)\n return merge(h2, h1)\n if (Math.random()<0.5)\n h1.l = merge(h1.l, h2);\n else\n h1.r = merge(h1.r, h2);\n return h1;\n};\nclass Heap {\n constructor(value){\n this.value = value;\n this.l = null;\n this.r = null;\n }\n insert(value){\n return merge(new Heap(value), this);\n }\n top(){\n return this.value;\n }\n isEmpty(){\n return this.value===null;\n }\n}\n\nlet calc = (arr, n)=>{\n let heap = new Heap(arr[0]);\n for (let i=1; i{\n let sum = 0;\n for (let a of arr)\n sum += a;\n let cnt_map = new Map();\n for (let a of arr)\n cnt_map.set(a, (cnt_map.get(a)||0) + 1);\n let A = [sum], pos = 0;\n while (pos cxcode\n// xcode\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = ra();\n print(calc2(arr, n) ? 'yes' : 'no');\n }\n}\n\n//9: 4 5, 2 2 5 "}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet merge = (h1, h2)=>{\n if (!h1 || !h2)\n return h1||h2;\n if (h2.value < h1.value)\n return merge(h2, h1)\n if (Math.random()<0.5)\n h1.l = merge(h1.l, h2);\n else\n h1.r = merge(h1.r, h2);\n return h1;\n};\nclass Heap {\n constructor(value){\n this.value = value;\n this.l = null;\n this.r = null;\n }\n insert(value){\n return merge(new Heap(value), this);\n }\n top(){\n return this.value;\n }\n isEmpty(){\n return this.value===null;\n }\n}\n\nlet calc = (arr, n)=>{\n let heap = new Heap(arr[0]);\n for (let i=1; i{\n let sum = 0;\n for (let a of arr)\n sum += a;\n let cnt_map = new Map();\n for (let a of arr)\n cnt_map.set(a, (cnt_map.get(a)||0) + 1);\n let A = [sum], pos = 0;\n while (pos cxcode\n// xcode\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let arr = ra();\n print(calc2(arr, n) ? 'yes' : 'no');\n }\n}\n\n//9: 4 5, 2 2 5 "}], "src_uid": "11fd178e17d27fc97f36f0de1b1fdf6f"} {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = readline().split(' ').map(x=>x-1);\n LT({n, P});\n // PROCESSING:\n //let F = new Array(n).fill(0).map(()=>new Array(n).fill(0));\n let S = new Array(n).fill(0).map(()=>new Array(n).fill(0));\n for (let i=0; i0 ? S[i-1][j] : 0)+(j>0 ? S[i][j-1] : 0)-(i>0 && j>0 ? S[i-1][j-1] : 0) + (P[i]==j ? 1 : 0);\n }\n }\n //L(S)\n /** \n let Fsum = (x, y)=>{\n let result = 0;\n for (let i = x; i >= 0; i = (i & (i+1)) - 1)\n for (let j = y; j >= 0; j = (j & (j+1)) - 1)\n result += F[i][j];\n return result;\n }\n let Finc = (x, y, delta)=>{\n for (let i = x; i < n; i = (i | (i+1)))\n for (let j = y; j < n; j = (j | (j+1)))\n F[i][j] += delta;\n };\n for (let i=0; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nclass Fenwick {\n constructor(size) {\n this.n = size;\n this.t = new Array(size).fill(0);\n }\n\n rsum(r) {\n let result = 0;\n for (; r >= 0; r = (r & (r+1)) - 1)\n result += this.t[r];\n return result;\n }\n\n inc(i, delta) {\n for (; i < this.n; i = (i | (i+1)))\n this.t[i] += delta;\n }\n\n sum(l, r) {\n if (r < l) return 0;\n return this.rsum(r) - this.rsum(l-1);\n }\n\n reset() {\n this.t = new Array(this.n).fill(0);\n }\n}\n\nconst calc = (n, arr)=>{\n let result = 0;\n\n let pref = new Array(n + 1).fill(0).map(() => new Array(n).fill(0));\n let suf = new Array(n + 1).fill(0).map(() => new Array(n).fill(0));\n\n for (let num = 2; num <= n; num++) {\n for (let i = 0; i < n; i++) {\n if (i === 0) {\n pref[num][i] = arr[i] < num ? 1 : 0;\n } else {\n pref[num][i] = pref[num][i - 1] + (arr[i] < num ? 1 : 0);\n }\n }\n for (let j = n - 1; j >= 0; j--) {\n if (j === n - 1) {\n suf[num][j] = arr[j] < num ? 1 : 0;\n } else {\n suf[num][j] = suf[num][j + 1] + (arr[j] < num ? 1 : 0);\n } \n }\n }\n\n // console.log(`DEBUG pref`, pref);\n // console.log(`DEBUG suf`, suf);\n\n for (let b = 1; b < n - 2; b++) {\n for (let c = b + 1; c < n - 1; c++) {\n result += pref[arr[c]][b - 1] * suf[arr[b]][c + 1];\n }\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n // let s = readline();\n let a = ra();\n out.push(calc(n, a));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, nums) {\r\n const gtIndex = Array.from({\r\n length: n\r\n }, () => []),\r\n ltIndex = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n if (nums[j] > nums[i]) gtIndex[i].push(j);\r\n if (nums[j] < nums[i]) ltIndex[i].push(j);\r\n }\r\n }\r\n let res = 0;\r\n for (let c = 2; c < n - 1; c++) {\r\n const sum = new Array(c).fill(0);\r\n for (let b = 1; b < c; b++) {\r\n const lti = ltIndex[b];\r\n let l = 0,\r\n r = lti.length;\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (lti[mid] <= c) {\r\n l = mid + 1;\r\n } else {\r\n r = mid;\r\n }\r\n }\r\n sum[b] = sum[b - 1] + lti.length - l;\r\n }\r\n for (let a = 0; a < c; a++) {\r\n if (nums[a] > nums[c]) continue;\r\n res += sum[c - 1] - sum[a];\r\n }\r\n }\r\n return res + '';\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var n = +readline();\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var f = Array(n);\r\n f.fill(0, 0, n);\r\n var count = 0;\r\n for (var p = n - 2; p >= 2; p--) {\r\n var cur = 0;\r\n for (var l = p - 1; l >= 1; l--) {\r\n if (a[l] > a[p + 1])\r\n f[l]++;\r\n cur += f[l];\r\n if (a[l - 1] < a[p])\r\n count += cur;\r\n }\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var _ = _a[_i];\r\n var n = +readline();\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n var f = Array(n);\r\n for (var i = 0; i < n; i += 1) {\r\n f[i] = 0;\r\n }\r\n var count = 0;\r\n for (var i = n - 1; i >= 3; i -= 1) {\r\n var cur = 0;\r\n for (var j = 0; j < i; j += 1) {\r\n if (a[j] > a[i]) {\r\n cur += 1;\r\n }\r\n f[j] += cur;\r\n }\r\n for (var j = 0; j < i - 2; j += 1) {\r\n if (a[j] < a[i - 1]) {\r\n count += f[i - 2] - f[j];\r\n }\r\n }\r\n }\r\n print(count);\r\n}\r\n"}], "negative_code": [], "src_uid": "d6a123dab1263b0e7b297ca2584fe701"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.sort((a, b) => b - a);\n let [diff, countLow, countHigh, low, high] = [arr[0] - arr[len - 1], 0, 0, arr[len - 1], arr[0]];\n\n if (low === high) console.log(`${diff} ${Math.floor((len * (len - 1)) / 2)}`);\n else {\n for (let i = 0; i < len; i++) {\n const current = arr[i];\n if (current === low) countLow++;\n if (current === high) countHigh++;\n }\n console.log(`${diff} ${countLow * countHigh}`);\n }\n}\n", "positive_code": [{"source_code": "print(function(n) {\n var b = readline().split(\" \").map(Number);\n var min = b[0], max = b[0];\n for (var i = 1; i < b.length; ++i) {\n if (b[i] < min)\n min = b[i];\n if (b[i] > max)\n max = b[i];\n }\n var nMin = 0, nMax = 0;\n for (var i = 0; i < b.length; ++i) {\n if (b[i] == min)\n ++nMin;\n if (b[i] == max)\n ++nMax;\n }\n return [max - min, min == max ? b.length * (b.length - 1) / 2\n : nMin * nMax].join(\" \");\n}.apply(readline().split(\" \").map(Number)));\n"}, {"source_code": "var main = function(arr)\n{\n var maxAmount = 1,\n minAmount = 1,\n max,\n min;\n var increase = function(a, b)\n {\n return +a - +b;\n }\n arr = arr.sort(increase);\n if (arr[0] === arr[arr.length - 1]) return 0 + ' ' + arr.length * (arr.length - 1) / 2;\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] === arr[i - 1]) minAmount++;\n else break;\n }\n for (i = arr.length - 1; i > 1; i--)\n {\n if (arr[i] === arr[i - 1]) maxAmount++;\n else break;\n }\n max = arr[arr.length - 1];\n min = arr[0];\n max -= min;\n maxAmount *= minAmount;\n return max + ' ' + maxAmount;\n}\n\nvar num = readline(),\n input = readline();\nprint(main(input.split(' ')));"}, {"source_code": "readline()\nT=readline().trim().split(' ').map(Number)\nT.sort((l,r)=>l-r)\nmaxd=T[T.length-1]-T[0]\ni=0, j=0\n\nwhile (i maxB) maxB = v;\n\t\t\t\tif(v < minB) minB = v;\n\n\t\t\t\treturn v;\n\t\t\t});\n\n\t\tfor(var i=0; i 0; i--){ j += i }\n\twrite(j);\n}\nelse{\n\tfor(i = 1; b[i] == b[0]; i++){}\n\tfor(j = n-2; b[j] == b[n-1]; j--){}\n\tj = n-1 - j;\n\twrite(i*j);\n}"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n\n let max = 0, min = Number.MAX_SAFE_INTEGER;\n let cntMax = 0, cntMin = 0;\n \n input[1].split(' ').forEach(x => {\n let v = parseInt(x);\n if (v > max) { max = v; cntMax = 1; }\n else if (v === max) { cntMax += 1; }\n\n if (v < min) { min = v; cntMin = 1; }\n else if (v === min) { cntMin += 1; }\n\n \n });\n\n if (max !== min)\n console.log(`${max - min} ${ cntMin * cntMax }`);\n else {\n console.log(`0 ${ n*(n-1) / 2}`);\n }\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(Number);\n let max = Math.max(...arr);\n let min = Math.min(...arr);\n console.log(max - min);\n let maxApp = 0;\n let minApp = 0;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === max) {\n maxApp++;\n }\n if (arr[i] === min) {\n minApp++;\n }\n }\n\n if (max === min) {\n console.log((n * (n - 1)) / 2);\n } else {\n console.log(maxApp * minApp);\n }\n}\n"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, kM = 0, km = 1e9 + 1;\n\t\treadline().split(' ').forEach(function (e) {\n\t\t\tm[e] = m[e] ? m[e] + 1 : 1;\n\t\t\tkM = Math.max(kM, e);\n\t\t\tkm = Math.min(km, e);\n\t\t});\n\n\t\tvar k = Object.keys(m);\n\t\tif (km === kM) return [0, m[km] * (m[km] - 1) / 2].join(' ');\n\t\telse return [kM - km, m[kM] * m[km]].join(' ');\n\t}(+readline()));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tflowers = tokenizeIntegers(readline());\n\tflowers.sort(function (a, b) {\n\t\treturn a - b;\n\t});\n\tfor (var i = 1; i < n && flowers[i-1] == flowers[i]; ++i) {\n\t}\n\tif (i == n) {\n\t\tvar max = 0,\n\t\t\tcount = (n-1)*n/2;\n\t} else {\n\t\tvar max = flowers[n-1] - flowers[0],\n\t\t\tspan = i;\n\t\tfor (var i = n-1; flowers[i-1] == flowers[i]; --i) {\n\t\t}\n\t\tvar count = span*(n-i);\n\t}\n\tprint(max, count);\n}\n\nmain();\n"}, {"source_code": "print(function(n) {\n d = {};\n var bMin = 1E9, bMax = 1;\n b = readline().split(\" \").map(function(v) {\n d[v] = d[v] ? d[v] + 1 : 1;\n v = Number(v);\n if (v < bMin)\n bMin = v\n if (v > bMax)\n bMax = v\n });\n return [bMax - bMin, bMin == bMax ? n * (n - 1) / 2\n : d[bMin] * d[bMax]].join(\" \");\n}.apply(null, readline().split(\" \").map(Number)));\n"}, {"source_code": "print(function(n) {\n d = {};\n var bMin = 1E9, bMax = 1;\n readline().split(\" \").map(function(v) {\n d[v] = d[v] ? d[v] + 1 : 1;\n v = Number(v);\n if (v < bMin)\n bMin = v\n if (v > bMax)\n bMax = v\n });\n return [bMax - bMin, bMin == bMax ? n * (n - 1) / 2\n : d[bMin] * d[bMax]].join(\" \");\n}.apply(null, readline().split(\" \").map(Number)));\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, kM = 0, km = 1e9 + 1;\n\t\treadline().split(' ').forEach(function (e) {\n\t\t\tm[e] = m[e] ? m[e] + 1 : 1;\n\t\t\tif (e > kM) kM = e;\n\t\t\tif (e < km) km = e;\n\t\t});\n\n\t\tvar k = Object.keys(m);\n\t\tif (km === kM) return [kM - km, m[km] * (m[km] - 1) / 2].join(' ');\n\t\telse return [kM - km, m[kM] * m[km]].join(' ');\n\t}(+readline()));\n\n}).call(this);"}, {"source_code": "print(function(n) {\n var b = readline().split(\" \");\n var min = b[0], max = b[0];\n for (var i = 1; i < b.length; ++i) {\n if (b[i] < min)\n min = b[i];\n if (b[i] > max)\n max = b[i];\n }\n var nMin = 0, nMax = 0;\n for (var i = 0; i < b.length; ++i) {\n if (b[i] == min)\n ++nMin;\n if (b[i] == max)\n ++nMax;\n }\n return [max - min, min == max ? b.length * (b.length - 1) / 2\n : nMin * nMax].join(\" \");\n}.apply(readline().split(\" \").map(Number)));\n"}, {"source_code": "print(function(n) {\n var b = readline().split(\" \");\n b.sort();\n var l, r;\n for (var i = 0; i < b.length; ++i) {\n if (b[i] == b[0])\n l = i;\n if (b[b.length - 1 -i] == b[b.length - 1])\n r = b.length - 1 - i;\n }\n return [b[r] - b[l], (b.length - r) * (l + 1)].join(\" \");\n}.apply(readline().split(\" \").map(Number)));\n"}, {"source_code": "print(function(n) {\n d = {};\n var bMin = 1E9, bMax = 1;\n readline().split(\" \").map(function(v) {\n d[v] = d[v] ? d[v] + 1 : 1;\n v = Number(v);\n if (v < bMin)\n bMin = v\n if (v > bMax)\n bMax = v\n });\n return [bMax - bMin, bMin == bMax ? n * (n - 1) / 2\n : d[bMin] * d[bMax]].join(\" \");\n}.apply(readline().split(\" \").map(Number)));\n"}, {"source_code": "print(function(n) {\n var b = readline().split(\" \");\n b.sort();\n var l, r;\n for (var i = 0; i < b.length; ++i) {\n if (b[i] == b[0])\n l = i;\n if (b[b.length - 1 -i] == b[b.length - 1])\n r = b.length - 1 - i;\n }\n return [b[r] - b[l], b[r] != b[l] ? (b.length - r) * (l + 1)\n : Math.floor(b.length / 2) * Math.ceil(b.length / 2)].join(\" \");\n}.apply(readline().split(\" \").map(Number)));\n"}, {"source_code": "var main = function(arr)\n{\n var maxAmount = 1,\n minAmount = 1,\n max,\n min;\n var increase = function(a, b)\n {\n return +a - +b;\n }\n arr = arr.sort(increase);\n if (arr[0] === arr[arr.length - 1]) return arr.length * (arr.length - 1) / 2;\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] === arr[i - 1]) minAmount++;\n else break;\n }\n for (i = arr.length - 1; i > 1; i--)\n {\n if (arr[i] === arr[i - 1]) maxAmount++;\n else break;\n }\n max = arr[arr.length - 1];\n min = arr[0];\n max -= min;\n maxAmount *= minAmount;\n return max + ' ' + maxAmount;\n}\n\nvar num = readline(),\n input = readline();\nprint(main(input.split(' ')));"}, {"source_code": "var main = function(arr)\n{\n var maxAmount = 1,\n minAmount = 1,\n max,\n min;\n var increase = function(a, b)\n {\n return +a - +b;\n }\n arr = arr.sort(increase);\n if (arr[0] === arr[arr.length - 1]) return arr.length * (arr.length - 1) / 2;\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] === arr[i - 1]) minAmount++;\n else break;\n }\n for (i = arr.length - 1; i <= arr.length - 1; i++)\n {\n if (arr[i] === arr[i - 1]) maxAmount++;\n else break;\n }\n max = arr[arr.length - 1];\n min = arr[0];\n max -= min;\n maxAmount *= minAmount;\n return max + ' ' + maxAmount;\n}\n\nvar num = readline(),\n input = readline();\nprint(main(input.split(' ')));"}, {"source_code": "var main = function(arr)\n{\n var maxAmount = 1,\n minAmount = 1,\n max,\n min;\n var increase = function(a, b)\n {\n return +a - +b;\n }\n arr = arr.sort(increase);\n if (arr[0] === arr[arr.length - 1]) return arr.length * (arr.length - 1) / 2;\n for (var i = 1; i <= arr.length - 1; i++)\n {\n if (arr[i] === arr[i - 1]) minAmount++;\n else break;\n }\n for (i = arr.length - 1; i >= 1; i++)\n {\n if (arr[i] === arr[i - 1]) maxAmount++;\n else break;\n }\n max = arr[arr.length - 1];\n min = arr[0];\n max -= min;\n maxAmount *= minAmount;\n return max + ' ' + maxAmount;\n}\n\nvar num = readline(),\n input = readline();\nprint(main(input.split(' ')));"}, {"source_code": "readline()\nT=readline().trim().split(' ').map(Number)\nT.sort((l,r)=>l-r)\nmaxd=T[T.length-1]-T[0]\ni=0, j=0\n\nwhile (i>1) : i*j)\n"}, {"source_code": "readline()\nT=readline().split(' ').map(Number)\nT.sort((l,r)=>l-r)\nmaxd=T[T.length-1]-T[0]\ni=0, j=0\n\nwhile (i>1) : i*j)\n"}, {"source_code": "readline()\nT=readline().trim().split(' ').map(Number)\nT.sort((l,r)=>l-r)\nmaxd=T[T.length-1]-T[0]\ni=0, j=0\n\nwhile (i>1) : i*j)\n"}, {"source_code": "readline()\nT=readline().trim().split(' ').map(Number)\nT.sort((l,r)=>l-r)\nmaxd=T[T.length-1]-T[0]\ni=0, j=0\n\nwhile (i>1) : i*j)\n"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tmaxB = 0,\n\t\t\tmaxBCnt = 0,\n\t\t\tminB = 1,\n\t\t\tminBCnt = 0,\n\t\t\tb = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/).map(function(v)\t{\n\t\t\t\tv = parseInt(v);\n\n\t\t\t\tif(v > maxB) maxB = v;\n\t\t\t\tif(v < minB) minB = v;\n\n\t\t\t\treturn v;\n\t\t\t});\n\n\t\tfor(var i=0; i maxB) maxB = v;\n\t\t\t\tif(v < minB) minB = v;\n\n\t\t\t\treturn v;\n\t\t\t});\n\n\t\tfor(var i=0; i {\n input.push(line);\n});\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n\n let max = 0, min = Number.MAX_SAFE_INTEGER;\n let cntMax = 0, cntMin = 0;\n \n input[1].split(' ').forEach(x => {\n let v = parseInt(x);\n if (v > max) { max = v; cntMax = 1; }\n else if (v === max) { cntMax += 1; }\n\n if (v < min) { min = v; cntMin = 1; }\n else if (v === min) { cntMin += 1; }\n\n \n });\n\n max = 200000;\n min = 200000;\n\n cntMax = 200000; cntMin = 200000;\n\n if (max !== min)\n console.log(`${max - min} ${ cntMin * cntMax }`);\n else {\n console.log(`0 ${ n*(n-1) / 2}`);\n }\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n\n let max = 0, min = Number.MAX_SAFE_INTEGER;\n let cntMax = 0, cntMin = 0;\n \n input[1].split(' ').forEach(x => {\n let v = parseInt(x);\n if (v > max) { max = v; cntMax = 1; }\n else if (v === max) { cntMax += 1; }\n\n if (v < min) { min = v; cntMin = 1; }\n else if (v === min) { cntMin += 1; }\n\n \n });\n \n console.log(`${max - min} ${cntMax * cntMin}`)\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n\n let max = 0, min = Number.MAX_SAFE_INTEGER;\n let cntMax = 0, cntMin = 0;\n \n input[1].split(' ').forEach(x => {\n let v = parseInt(x);\n if (v > max) { max = v; cntMax = 1; }\n else if (v === max) { cntMax += 1; }\n\n if (v < min) { min = v; cntMin = 1; }\n else if (v === min) { cntMin += 1; }\n\n \n });\n if (max !== min)\n console.log(`${max - min} ${ cntMin * cntMax }`);\n else {\n let f = 1;\n let k = 1;\n for (let i = 1; i <= n; i += 1) {\n f *= i;\n if (n - 2 === i) k = f;\n }\n console.log(`0 ${ f / (2*k)}`);\n }\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n const n = input[0].split(' ').map(x => parseInt(x));\n\n let max = 0, min = Number.MAX_SAFE_INTEGER;\n let cntMax = 0, cntMin = 0;\n \n input[1].split(' ').forEach(x => {\n let v = parseInt(x);\n if (v > max) { max = v; cntMax = 1; }\n else if (v === max) { cntMax += 1; }\n\n if (v < min) { min = v; cntMin = 1; }\n else if (v === min) { cntMin += 1; }\n\n \n });\n \n console.log(`${max - min} ${(max - min !== 0) ? cntMax * cntMin : 1}`)\n});"}, {"source_code": "var n = +readline(), b = readline().split(\" \").sort(function(x,y){return x-y});\n\nwrite((b[n-1] - b[0]) + \" \");\n\nfor(i = 1; b[i] == b[0]; i++){}\nfor(j = n-2; b[j] == b[n-1]; j--){}\nj = n-1 - j;\nwrite(i*j);"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\t\tvar m = {}, kM = 0, km = 2 * 1e5 + 1;\n\t\treadline().split(' ').forEach(function (e) {\n\t\t\tm[e] = m[e] ? m[e] + 1 : 1;\n\t\t\tif (e > kM) kM = e;\n\t\t\tif (e < km) km = e;\n\t\t});\n\n\t\tvar k = Object.keys(m);\n\t\tif (km === kM) return [kM - km, m[km] * (m[km] - 1) / 2].join(' ');\n\t\telse return [kM - km, m[kM] * m[km]].join(' ');\n\t}(+readline()));\n\n}).call(this);"}], "src_uid": "eb2d1072c5308d9ef686315a122d9d3c"} {"source_code": "function sa(s1, s2){\n var res = [];\n var data = {};\n for(var i=0;i {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number []} arr\n * @param {Number} l\n * @returns {Number}\n */\nfunction solve(arr, l) {\n const n = arr.length;\n if (n < 1) {\n return l / 2;\n }\n arr.unshift(0);\n arr.push(l);\n const tl = [0];\n for (let i = 1; i < n + 2; i++) {\n tl[i] = tl[i-1] + (arr[i] - arr[i-1]) / i;\n }\n const tr = [];\n tr[n+1] = 0;\n for (let i = n; i >= 0; --i) {\n const v = n - i + 1;\n tr[i] = tr[i+1] + (arr[i+1] - arr[i]) / v;\n }\n\n let ti = 0;\n for (; ti < n + 2; ti++) {\n if (tl[ti] >= tr[ti]) {\n break;\n }\n }\n // console.error({tl, tr, ti})\n\n if (tl[ti] === tr[ti]) {\n return tl[ti];\n }\n\n const vl = ti;\n const vr = n - ti + 2;\n const t = (arr[ti] - arr[ti-1] +\n vl * tl[ti-1] + vr * tr[ti])/ (n + 2);\n return t;\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const [n, l] = (await getLine()).split(' ').map(Number);\n const arr = (await getLine()).split(' ').map(Number);\n const res = solve(arr, l);\n console.log(res);\n }\n}\n\nif (require.main === module) {\n main();\n}", "positive_code": [{"source_code": "\nfunction closeInd(s, x) {\n var lo = 0;\n var hi = s.length - 1;\n var res = -1;\n while (hi >= lo) {\n var mid=Math.floor((hi + lo) / 2);\n if (s[mid] <= x) {\n lo = mid + 1;\n res = mid;\n }\n else hi = mid - 1;\n }\n return res;\n}\n\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n x += 2\n\n s = [0].concat(s).concat(y)\n var rgtp = []\n for (var n = 0; n < x; n++)rgtp.push(Math.abs(y - s[n]))\n rgtp.reverse();\n\n var leftvelc = [1]\n\n for (var n = 1; n < x; n++)leftvelc.push(1 + leftvelc[n - 1]);\n\n var leftm = [0]\n var curtm = 0\n var spd = 1;\n for (var n = 1; n < x; n++) {\n var ln = s[n] - s[n - 1];\n var tim = ln / spd;\n curtm += tim;\n leftm.push(curtm)\n spd++;\n }\n\n var rightvelc = [1];\n for (var n = 1; n < x; n++)rightvelc.push(rightvelc[n - 1] + 1);\n\n curtm = 0\n spd = 1\n var rgtm = [0];\n\n for (var n = 1; n < x; n++) {\n var ln = rgtp[n] - rgtp[n - 1];\n var tim = ln / spd;\n curtm += tim;\n rgtm.push(curtm)\n spd++;\n }\n var lo = 0;\n var hi = y;\n while (hi > lo) {\n var mid = ((hi + lo) / 2.0);\n var mid1 = y - mid;\n var lfpos = closeInd(s, mid);\n var rgpos = closeInd(rgtp, mid1);\n var df1 = ((mid - s[lfpos]) / leftvelc[lfpos]) + leftm[lfpos];\n var df2 = ((mid1 - rgtp[rgpos]) / rightvelc[rgpos]) + rgtm[rgpos];\n if (Math.abs(df1 - df2) < (1e-5)) {\n print(df1);\n return;\n }\n else {\n if (df1 < df2) lo = mid;\n else hi = mid;\n }\n }\n}\n\nvar tc = 1;\ntc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "\nfunction closeInd(s, x) {\n var lo = 0;\n var hi = s.length - 1;\n var res = -1;\n while (hi >= lo) {\n var mid=Math.floor((hi + lo) / 2);\n if (s[mid] <= x) {\n lo = mid + 1;\n res = mid;\n }\n else hi = mid - 1;\n }\n return res;\n}\n\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n x += 2\n\n s = [0].concat(s).concat(y)\n var rgtp = []\n for (var n = 0; n < x; n++)rgtp.push(Math.abs(y - s[n]))\n rgtp.reverse();\n\n var leftvelc = [1]\n\n for (var n = 1; n < x; n++)leftvelc.push(1 + leftvelc[n - 1]);\n\n var leftm = [0]\n var curtm = 0\n var spd = 1;\n for (var n = 1; n < x; n++) {\n var ln = s[n] - s[n - 1];\n var tim = ln / spd;\n curtm += tim;\n leftm.push(curtm)\n spd++;\n }\n\n var rightvelc = [1];\n for (var n = 1; n < x; n++)rightvelc.push(rightvelc[n - 1] + 1);\n\n curtm = 0\n spd = 1\n var rgtm = [0];\n\n for (var n = 1; n < x; n++) {\n var ln = rgtp[n] - rgtp[n - 1];\n var tim = ln / spd;\n curtm += tim;\n rgtm.push(curtm)\n spd++;\n }\n var lo = 0;\n var hi = y;\n while (hi > lo) {\n var mid = ((hi + lo) / 2.0);\n var mid1 = y - mid;\n var lfpos = closeInd(s, mid);\n var rgpos = closeInd(rgtp, mid1);\n var df1 = ((mid - s[lfpos]) / leftvelc[lfpos]) + leftm[lfpos];\n var df2 = ((mid1 - rgtp[rgpos]) / rightvelc[rgpos]) + rgtm[rgpos];\n if (Math.abs(df1 - df2) < (1e-5)) {\n print(df1);\n return;\n }\n else {\n if (df1 < df2) lo = mid;\n else hi = mid;\n }\n }\n}\n\nvar tc = 1;\ntc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let [n, l] = $(2), a = $(n);\n a.unshift(0); a.push(l);\n let i = 0; j = n + 1;\n let ti = 0, vi = 1, tj = 0, vj = 1;\n while (i + 1 < j) {\n let nti = ti + (a[i + 1] - a[i]) / vi;\n let ntj = tj + (a[j] - a[j - 1]) / vj;\n if (nti < ntj) {\n ti = nti;\n i++; vi++;\n } else {\n tj = ntj;\n j--; vj++;\n }\n }\n if (ti < tj) {\n log((a[j] - (tj - ti) * vi - a[i]) / (vi + vj) + tj)\n } else {\n log((a[j] - (ti - tj) * vj - a[i]) / (vi + vj) + ti)\n }\n // log(i, j, ti, tj, vi, vj)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,l] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n let min = 0;\n let max = n-1;\n let i = 0;\n let j = l;\n let s1 = 1;\n let s2 = 1;\n let res = 0; \n while(i < j){\n if(a[min] <= a[max]){\n let x1 = (a[min]-i)/s1;\n let x2 = (j-a[max])/s2;\n if(x1 < x2){\n i = a[min];\n min++;\n res += x1;\n j -= x1*s2;\n s1 += 1;\n }else if(x1 > x2){\n j = a[max];\n max--;\n res += x2;\n i += x2*s1;\n s2 += 1;\n }else{\n res += x1;\n i = a[min];\n j = a[max];\n max--;\n min++;\n s1 += 1;\n s2 += 1;\n }\n }else{\n res += (j-i)/(s1+s2);\n break;\n }\n }\n console.log(res);\n }\n}"}], "negative_code": [{"source_code": "\nfunction closeInd(s, x) {\n var lo = 0;\n var hi = s.length - 1;\n var res = -1;\n while (hi >= lo) {\n var mid=Math.floor((hi + lo) / 2);\n if (s[mid] <= x) {\n lo = mid + 1;\n res = mid;\n }\n else hi = mid - 1;\n }\n return res;\n}\n\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n var x = ip[0]\n var y = ip[1]\n var s = readline().split(' ').map(x => parseInt(x))\n\n x += 2\n\n s = [0].concat(s).concat(y)\n var rgtp = []\n for (var n = 0; n < x; n++)rgtp.push(Math.abs(y - s[n]))\n rgtp.reverse();\n\n var leftvelc = [1]\n\n for (var n = 1; n < x; n++)leftvelc.push(1 + leftvelc[n - 1]);\n\n var leftm = [0]\n var curtm = 0\n var spd = 1;\n for (var n = 1; n < x; n++) {\n var ln = s[n] - s[n - 1];\n var tim = ln / spd;\n curtm += tim;\n leftm.push(curtm)\n spd++;\n }\n\n var rightvelc = [1];\n for (var n = 1; n < x; n++)rightvelc.push(rightvelc[n - 1] + 1);\n\n curtm = 0\n spd = 1\n var rgtm = [0];\n\n for (var n = 1; n < x; n++) {\n var ln = rgtp[n] - rgtp[n - 1];\n var tim = ln / spd;\n curtm += tim;\n rgtm.push(curtm)\n spd++;\n }\n var lo = 0;\n var hi = y;\n while (hi > lo) {\n var mid = ((hi + lo) / 2.0);\n var mid1 = y - mid;\n var lfpos = closeInd(s, mid);\n var rgpos = closeInd(rgtp, mid1);\n var df1 = ((mid - s[lfpos]) / leftvelc[lfpos]) + leftm[lfpos];\n var df2 = ((mid1 - rgtp[rgpos]) / rightvelc[rgpos]) + rgtm[rgpos];\n if (Math.abs(df1 - df2) < (1e-4)) {\n print(df1);\n return;\n }\n else {\n if (df1 < df2) lo = mid;\n else hi = mid;\n }\n }\n}\n\nvar tc = 1;\ntc = parseInt(readline())\nwhile (tc--) solv()"}], "src_uid": "700cfc8d20794ca38d73ccff31e5292c"} {"source_code": ";(function () {\n\n\tprint(function () {\n\t\tvar n = +readline(), x = +readline(), y = 7 - x;\n\n\t\twhile (n--) {\n\t\t\tvar a = readline().split(' ').map(Number);\n\t\t\tif (a.indexOf(x) !== -1 || a.indexOf(y) !== -1)\n\t\t\t\treturn 'NO';\n\t\t}\n\n\t\treturn 'YES';\n\t}());\n\n}).call(this);", "positive_code": [{"source_code": "print(function(n, x) {\n\tvar s = '';\n\tfor (var i = 0; i < n; i++)\n\t\ts += readline();\n\n\treturn (new RegExp('[' + x + (7 - x) + ']')).test(s) ? 'NO' : 'YES';\n\n}(+readline(), readline()));"}, {"source_code": "print(function(n, x) {\n\n\tfor (var i = 0; i < n; i++)\n\t\tif (\n\t\t\treadline().split(' ').map(Number).reduce(function(a, b) {\n\t\t\t\treturn a === x || b === x || a === 7 - x || b === 7 - x;\n\t\t\t})\n\t\t) {\n\t\t\treturn 'NO'\n\t\t}\n\n\treturn 'YES';\n\n}(+readline(), +readline()));"}, {"source_code": "print(function(n, x) {\n\tvar s = ' ';\n\tfor (var i = 0; i < n; i++)\n\t\ts += readline();\n\n\treturn s.indexOf(x) > -1 || s.indexOf(7 - x) > -1 ? 'NO' : 'YES';\n\n}(+readline(), readline()));"}, {"source_code": "print(function(n, x) {\n\n\tfor (var i = 0; i < n; i++)\n\t\tif (readline().split(' ').reduce(function(a, b) {return a == x || b == x || a == 7 - x || b == 7 - x;})) {\n\t\t\treturn 'NO'\n\t\t}\n\n\treturn 'YES';\n\n}(+readline(), readline()));"}, {"source_code": "print(function(n, x) {\n\n\tvar re = new RegExp('[' + x + (7 - x) + ']');\n\n\tfor (var i = 0; i < n; i++)\n\t\tif (re.test(readline()))\n\t\t\treturn 'NO'\n\n\treturn 'YES';\n\n}(+readline(), readline()));\n"}, {"source_code": "var numberOfDices = Number(readline());\nvar topFace = Number(readline());\nvar faces = new Array(6).fill(0);\n\nvar isOk = true;\nfor (var i = 0; i < numberOfDices; i++) {\n faces[topFace - 1] += 1;\n faces[7 - topFace - 1] += 1;\n var numbers = readline()\n .split(' ')\n .map(Number);\n faces[numbers[0] - 1] += 1;\n faces[7 - numbers[0] - 1] += 1;\n faces[numbers[1] - 1] += 1;\n faces[7 - numbers[1] - 1] += 1;\n\n for (var j = 0; j < 6; j++) {\n if (faces[j] !== 1) {\n isOk = false;\n break;\n }\n }\n\n if (!isOk) {\n break;\n }\n\n topFace = 7 - topFace;\n faces = new Array(6).fill(0);\n}\n\nif (isOk) {\n print('YES');\n} else {\n print('NO');\n}"}, {"source_code": "var n = parseInt(readline());\nvar s = parseInt(readline());\n\nvar excluded = 7 - s;\nvar res = 'YES';\n\nwhile (n--) {\n var values = readline().split(' ').map(Number);\n if (values[0] === s || values[0] === excluded ||\n values[1] === s || values[1] === excluded) {\n res = 'NO';\n }\n}\n\nprint(res);"}], "negative_code": [{"source_code": "print(function(n, x) {\n\n\tfor (var i = 0; i < n; i++)\n\t\tif (readline().split(' ').reduce(function(a, b) {return a === x || b === x || a === 7 - x || b === 7 - x;}))\n\t\t\treturn 'NO'\n\n\treturn 'YES';\n\n}(+readline(), readline()));"}, {"source_code": "print(function(n, x) {\n\tvar s = ' ';\n\tfor (var i = 0; i < n; i++)\n\t\ts += readline();\n\n\treturn s.indexOf(x) || s.indexOf(7 - x) ? 'NO' : 'YES';\n\n}(+readline(), readline()));"}, {"source_code": "var numberOfDices = Number(readline())\nvar topFace = Number(readline())\nvar faces = new Array(6).fill(0)\n\nvar isOk = true\nfor (var i = 0; i < numberOfDices; i++) {\n faces[topFace - 1] += 1\n faces[7 - topFace - 1] += 1\n var numbers = readline().split(' ').map(Number)\n numbers.forEach(n => {\n faces[n - 1] += 1\n faces[7 - n - 1] += 1\n })\n\n\n for (var j = 0; j < 6; j++) {\n if (faces[j] !== 1) {\n isOk = false\n break;\n }\n }\n\n if (!isOk) {\n break;\n }\n\n topFace = 7 - topFace\n faces = new Array(6).fill(0)\n}"}, {"source_code": ";(function () {\n\n\tprint(function () {\n\t\tvar n = +readline(), x = +readline(), a = [], b = [false, false, false, false, false, false];\n\t\tfor (var i = 0; i < n; i++) a.push(readline().split(' ').map(Number).concat(false));\n\t\tb[x - 1] = b[a[0][0] - 1] = b[a[0][1] - 1] = true;\n\t\tfor (var i = 1, _i = n + 1; i < _i; i++)\n\t\t\tif ((b[a[i - 1][0] - 1] || b[a[i - 1][1] - 1]) && !a[i - 1][2])\n\t\t\t\ti = b[a[i - 1][0] - 1] = b[a[i - 1][1] - 1] = a[i - 1][2] = true;\n\t\treturn a.reduce(function (p, e) { return p + +(!e[2]); }, 0) ? 'NO' : 'YES';\n\t}());\n\n}).call(this);"}], "src_uid": "2d6a1202139e1f77f32377224e1fe752"} {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const x = readline().split(\" \").map((x) => +x);\n const x2 = readline()\n .split(\"\")\n .map((x) => +x);\n \n blackSquare(x,x2);\n}\n\n\nfunction blackSquare(calories, gameLog) {\n console.log(gameLog.reduce((prev, curr) => prev + calories[curr - 1], 0));\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nstate = 0;\nlet values;\nrl.on('line', line => {\n if (state % 2 == 0) {\n values = line.split(' ').map(Number);\n } else {\n console.log(\n line\n .split('')\n .map(x => {\n return parseInt(x) - 1;\n })\n .reduce((a, b) => {\n return a + values[b];\n }, 0)\n );\n }\n state++;\n}).on('close', () => {\n process.exit(0);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const stips = readline().split(' ').map(x => parseInt(x))\n const s = readline();\n let calories =0 ;\n for (let i = 0, c = s.length ; i< c ; i++ ){\n calories += stips[s[i]-1];\n }\n console.log(calories);\n}\n\n"}, {"source_code": "function main() {\n // write code here:\n var calorie = [];\n var calories=0;\n var touch=stdin[1].split('').map(Number);\n stdin[0].split(' ').map((a, i) => {\n a = Number(a);\n calorie[i] = a;\n });\n for(let i=0;i {\n if (!caloriesPerStrip) {\n caloriesPerStrip = input.split(\" \").map(Number)\n } else {\n blackSquarePosition = input.split(\"\").map((char) => {\n switch (char) {\n case \"1\":\n caloriesCounter += caloriesPerStrip[0]\n break;\n case \"2\":\n caloriesCounter += caloriesPerStrip[1]\n break;\n case \"3\":\n caloriesCounter += caloriesPerStrip[2]\n break;\n\n case \"4\":\n caloriesCounter += caloriesPerStrip[3]\n break;\n\n default:\n break;\n }\n })\n\n console.log(caloriesCounter)\n rl.close();\n }\n\n\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n var s = next();\n var output = 0;\n for(var i = 0; i < s.length; i++){\n output += one[myconv(s[i], 1) - 1];\n }\n myout(output);\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const a = readline().split(' ').map(x => parseInt(x));\n const s = readline();\n let sum = 0;\n for (let i = 0; i < s.length; i++) {\n sum += a[s.charAt(i) - 1];\n }\n // output\n print(sum);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet calories = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n calories = d.split(' ').map(Number);\n return;\n }\n\n let ans = 0;\n for (let i = 0; i < d.length; i++) {\n ans += calories[+d[i] - 1];\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let answer = 0; let kal = [];\n input[0].split(' ').forEach(i => kal.push(parseInt(i)));\n [...input[1]].forEach(s => {\n answer += kal[parseInt(s)-1];\n });\n console.log(answer);\n});\n\n"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const cal = input[0].split(' ').map(x => parseInt(x));\n let answer = 0;\n [...input[1]].map(x => parseInt(x)).forEach(num => {\n answer += cal[num-1];\n });\n\n console.log(answer);\n});"}, {"source_code": "var a = readline().split(\" \"), s = readline().split(\"\"), sum = 0;\n\ns.forEach(function(string){\n\tsum += +a[string-1];\n});\n\nwrite(sum);"}, {"source_code": "var str = readline();\nvar s = readline();\nstr = str.split(' ');\n\nfunction solve(a,b,c,d,str) {\n var res = 0;\n var arr = [0,a,b,c,d];\n for (var i = 0; i < str.length; i ++) res += arr[+str[i]];\n return res; \n}\n\nprint(solve(+str[0], +str[1], +str[2], +str[3], s));"}, {"source_code": "var kInfo = readline().split(' ').map(Number);\nvar numEdit = readline();\nvar numK = 0;\n\nfor (var i=0; i Number(x));\nprint(readline().split(\"\").reduce((acc, s) => acc + values[Number(s)-1], 0));"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n \nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n \nvar noOfTimes = readline();\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\n\n \nvar totalCalories=0;\n \nfor(var i=0;i< noOfTimes.length;i++)\n{\n\tvar currentNumber = Number(noOfTimes[i]);\n if(currentNumber==1){first=first+1;}\n else if (currentNumber==2){second = second+1;}\n else if (currentNumber==3){third = third+1;}\n else {fourth=fourth+1;}\n}\ntotalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n \nprint(totalCalories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n \nvar strips = readline();\nvar calories = 0;\nfor(var i = 0; i < strips.length; i++)\n\tcalories += values[Number(strips[i]) - 1];\n \nprint(calories);"}, {"source_code": "var values = readline().split(\" \").map(x => Number(x));\nvar strips = readline();\nvar calories = strips.split(\"\").reduce((acc, s) => acc + values[Number(s)-1], 0);\nprint(calories);"}, {"source_code": ";(function () {\n\n\tvar c = readline().split(' ').map(Number);\n\n\tprint( readline().split('').reduce(function (p, e) {\n\t\treturn p + c[+e - 1];\n\t}, 0) );\n\n}).call(this)"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar energy = tokenizeIntegers(readline()),\n\t\tgame = trim(readline()),\n\t\tcalories = 0;\n\tfor (var i = 0; i < game.length; ++i) {\n\t\tcalories += energy[parseInt(game.charAt(i))-1];\n\t}\n\tprint(calories);\n}\n\nmain();\n"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line1, line2) {\n var calories = line1.split(\" \").map((x) => Number(x));\n var strip = line2.split(\" \");\n\n var total = 0;\n for (var i = 0; i < strip[0].length; i++) {\n total += calories[Number(strip[0].toString().charAt(i)) - 1];\n }\n\n return total;\n}"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n \nvar strips = readline();\nvar calories = 0;\nfor(var i = 0; i < strips.length; i++)\n\tcalories += values[Number(strips[i]) - 1];\n \nprint(calories);"}, {"source_code": "(function() {\n 'use strict';\n let n = readline().split(' ').map(Number);\n let x = readline().split('').map(Number);\n var y = 0;\n for (let i = 0; i < x.length; ++i) {\n if (x[i] === 1) {\n y += n[0];\n } else if (x[i] === 2) {\n y += n[1];\n } else if (x[i] === 3) {\n y += n[2];\n } else if (x[i] === 4) {\n y += n[3];\n }\n }\n print(y);\n \n \n}());"}, {"source_code": "(function () {\n var kal = readline().split(\" \"),\n line = readline(),\n i = 0,\n len = line.length,\n sum = 0;\n for (; i < len; i++) {\n sum += parseInt(kal[line[i] - 1]);\n }\n print(sum);\n})();"}, {"source_code": "var aaaa = readline();\nvar s = readline();\naaaa = aaaa.split(\" \");\nvar sum = 0;\nfor(var i = 0; i < s.length; ++i)\n{\n sum += parseInt(aaaa[parseInt(s[i])-1]);\n}\nprint(sum);"}, {"source_code": "var x = readline().split(\" \"),\n\ts = readline(),\n\tt = 0;\nfor (var i = 0; i < s.length; i++) {\n switch (parseInt(s[i])) {\n case 1: t += parseInt(x[0]);\n break;\n case 2: t += parseInt(x[1]);\n break;\n case 3: t += parseInt(x[2]);\n break;\n case 4: t += parseInt(x[3]);\n break;\n\t}\n}\nprint(t);"}, {"source_code": "var a = readline().split(\" \");//readline();\nvar str = readline();\nvar res = 0;\n\t\tfor (var i=0; i r + a[x-1], 0))"}, {"source_code": "var tok;\nvar index=0;\n\nfunction next(){\n while(tok==null || index==tok.length){\n tok=readline().split(' ');\n index=0;\n }\n var res=tok[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction main(){\n var a=[];\n for(var i=0; i<4; i++){\n a[i]=nextInt();\n }\n var s=next();\n var r=0;\n for(var i=0; i parseInt(x));\n\nvar games = readline();\n\nvar calories = 0;\n\nfor (var i = 0; i < games.length; i++) {\n calories += a[parseInt(games[i]) - 1]; \n}\n\nprint(calories);"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\nfunction readNums() {\n\treturn readline().split(' ').map(Number);\n}\nprint(function(a, s) {\n\ta.unshift(0);\n\tvar ans = 0;\n\n\tfor (var i = 0; i < s.length; i++) {\n\t\tans += a[s[i]];\n\t}\n\n\treturn ans;\n}(readNums(), readline().split('')));"}, {"source_code": "var n = readline().split(\" \");\nvar x = 0;\nreadline().split(\"\").map(function (a) {\n x+= parseInt(n[a-1]);\n})\nwrite(x)"}, {"source_code": "line = readline().split(' ').map(Number);\ngameStr = readline().split('').map(Number);\n\na1 = line[0];\na2 = line[1];\na3 = line[2];\na4 = line[3];\n\nvar res = 0;\n\nfor (var i = 0; i < gameStr.length; i++) {\n\tif (gameStr[i] == 1) {\n\t\tres = res + a1;\n\t} else if (gameStr[i] == 2) {\n\t\tres = res + a2;\n\t} else if (gameStr[i] == 3) {\n\t\tres = res + a3;\n\t} else if (gameStr[i] == 4) {\n\t\tres = res + a4;\n\t};\n};\n\nprint(res);"}], "negative_code": [{"source_code": "var str = readline();\nvar s = readline();\nstr = str.split(' ');\n\nfunction solve(a,b,c,d,str) {\n var res = 0;\n var arr = [0,a,b,c,d];\n for (var i = 0; i < str.length; i ++) res += arr[+str[i]];\n return res; \n}\n\nprint(+str[0], +str[1], +str[2], +str[3], readline());"}, {"source_code": "var values = readline().split(\" \").map(x => Number(x) - 1);\nvar strips = readline();\nvar calories = strips.split(\"\").reduce((acc, s) => acc + Number(s), 0);\nprint(calories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n\nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n\nvar noOfTimes = readline().split(\"\").map(function(v){return Number(v)});\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\nvar number=0;\n\nvar totalCalories=0;\n\n\nif(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )\n{\n //take the second string line \n //count the number of repeated elements \n //multiplyit to the stripes\n //print or write it\n if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))\n {\n for(var i=0;i< noOfTimes.length;i++)\n {\n if(number[i]==1){first=first+1;}\n else if (number[i]==2){second = second+1;}\n else if (number[i]==3){third = third+1;}\n else {fourth=fourth+1;}\n }\n totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n }\n \n}\n\nprint(totalCalories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n\nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n\nvar noOfTimes =Number(readline());\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\nvar number=0;\n\nvar totalCalories=0;\n\n\nif(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )\n{\n //take the second string line \n //count the number of repeated elements \n //multiplyit to the stripes\n //print or write it\n if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))\n {\n for(var i=0;i< noOfTimes.length;i++)\n {\n if(number[i]==1){first=first+1;}\n else if (number[i]==2){second = second+1;}\n else if (number[i]==3){third = third+1;}\n else {fourth=fourth+1;}\n }\n totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n }\n \n}\n\nprint(totalCalories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n\nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n\nvar noOfTimes = readline().split(\" \").map(function(v){return parseInt(v)});\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\nvar number=0;\n\nvar totalCalories=0;\n\n\nif(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )\n{\n //take the second string line \n //count the number of repeated elements \n //multiplyit to the stripes\n //print or write it\n if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))\n {\n for(var i=0;i< noOfTimes.length;i++)\n {\n if(number[i]==1){first=first+1;}\n else if (number[i]==2){second = second+1;}\n else if (number[i]==3){third = third+1;}\n else {fourth=fourth+1;}\n }\n totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n }\n \n}\n\nprint(totalCalories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n\nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n\nvar noOfTimes =parseInt( readline());\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\nvar number=0;\n\nvar totalCalories=0;\n\n\nif(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )\n{\n //take the second string line \n //count the number of repeated elements \n //multiplyit to the stripes\n //print or write it\n if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))\n {\n for(var i=0;i< noOfTimes.length;i++)\n {\n if(number[i]==1){first=first+1;}\n else if (number[i]==2){second = second+1;}\n else if (number[i]==3){third = third+1;}\n else {fourth=fourth+1;}\n }\n totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n }\n \n}\n\nprint(totalCalories);"}, {"source_code": "var values = readline().split(\" \").map(function(n){return Number(n)});\n\nvar firstStrip= values[0];\nvar secondStrip= values[1];\nvar thirdStrip = values[2];\nvar fourthStrip = values[3];\n\nvar noOfTimes = readline().split(\"\").map(function(v){return parseInt(v,10)});\nvar first=0 ;\nvar second=0 ;\nvar third=0 ;\nvar fourth=0;\nvar number=0;\n\nvar totalCalories=0;\n\n\nif(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )\n{\n //take the second string line \n //count the number of repeated elements \n //multiplyit to the stripes\n //print or write it\n if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))\n {\n for(var i=0;i< noOfTimes.length;i++)\n {\n if(number[i]==1){first=first+1;}\n else if (number[i]==2){second = second+1;}\n else if (number[i]==3){third = third+1;}\n else {fourth=fourth+1;}\n }\n totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);\n \n }\n \n}\n\nprint(totalCalories);"}, {"source_code": "(function() {\n 'use strict';\n let n = readline().split(' ').map(Number);\n let x = readline().split('').map(Number);\n var y = 0;\n for (let i = 0; i < x.length; ++i) {\n if (x[i] === 1) {\n y += 1;\n } else if (x[i] === 2) {\n y += 2;\n } else if (x[i] === 3) {\n y += 3;\n } else if (x[i] === 4) {\n y += 4;\n }\n }\n print(y);\n \n \n}());"}, {"source_code": "(function () {\n var kal = readline().split(\" \"),\n line = readline(),\n i = 0,\n len = line.length,\n sum = 0;\n for (; i < len; i++) {\n sum += kal[line[i] - 1];\n }\n print(sum);\n})();"}], "src_uid": "db9065d975878227a749083f0036a169"} {"source_code": ";(function () {\n\n\tvar s = readline().split(' ').map(Number);\n\tprint( s[0] + s[1] - 1 );\n\n\tfor (var i = 1; i <= s[0]; i++) print( i + ' ' + 1);\n\n\tfor (var i = 2; i <= s[1]; i++) print( 1 + ' ' + i);\n\n}).call(this)", "positive_code": [{"source_code": "print(function(n, m){\n\tvar ans=[n+m-1];\n\tfor(var i=1; i<=m; i++){\n\t\tans.push('1 '+i);\n\t}\n\tfor(var i=2; i<=n; i++){\n\t\tans.push(i+' '+m);\n\t}\n\treturn ans.join('\\n');\n}.apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": ";(function () {\n\n\tvar s = readline().split(' ').map(Number);\n\tprint( s[0] + s[1] - 1 );\n\n\tfor (var i = 1; i <= s[0]; i++) print( 1 + ' ' + i);\n\n\tfor (var i = 2; i <= s[1]; i++) print( i + ' ' + 1);\n\n}).call(this)"}], "src_uid": "14fc3a7fef44a02791aee62838c4c8c8"} {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (s, n)=>{\n let bool = new Array(n).fill(0);\n for (let i=0; i 0) {\n\treadline();\n\tvar s = readline();\n\tvar arr = s.split('W');\n\tvar r = true;\n\n\tfor (var i = 0; i < arr.length; i++) {\n\t\tvar cnt = {};\n\t\tfor (var j = 0; j < arr[i].length; j++) {\n\t\t\tcnt[arr[i][j]] = cnt[arr[i][j]] ? cnt[arr[i][j]] + 1 : 0;\n\t\t}\n\n\t\tif ((cnt['R'] == 0 && cnt['B'] != 0) || (cnt['R'] != 0 && cnt['B'] == 0)) {\n\t\t\tr = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (r) print(\"YES\");\n\telse print(\"NO\");\n}\n"}, {"source_code": "var t = +readline()\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline()\r\n var arr1 = readline();\r\n print(MultiColor(arr1));\r\n}\r\n \r\nfunction MultiColor(s) {\r\n\r\n var n = s.length;\r\n var flag = true;\r\n for (var i = 0; i < n; i++)\r\n {\r\n if (s[i] == 'W')\r\n continue;\r\n else\r\n {\r\n var j = i, cr = 0, cb = 0;\r\n while (j < n && s[j] != 'W')\r\n {\r\n if (s[j] == 'R')\r\n cr++;\r\n else if (s[j] == 'B')\r\n cb++;\r\n\r\n j++;\r\n }\r\n\r\n if (cr === 0 || cb === 0)\r\n {\r\n flag = false;\r\n }\r\n\r\n i = j - 1;\r\n }\r\n }\r\n\r\n if (flag)\r\n return 'YES';\r\n else\r\n return 'No'\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = readline();\r\n while(t--) {\r\n \r\n let [l, s] = [Number(readline()), readline()], arr = [];\r\n \r\n if(l === 1) {\r\n if(s === \"W\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(l === 2) {\r\n if(s === \"WW\" || s === \"BR\" || s === \"RB\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(2 < l) {\r\n s = verif(s);\r\n if(!s) console.log(\"NO\");\r\n else {\r\n if(!s[0]) console.log(\"YES\");\r\n else {\r\n arr = createArr(s);\r\n arr = arr.map((str, index) => {\r\n str = stampFromLtoR(str, s[index]);\r\n return stampFromRtoL(str, s[index]).join(\"\");\r\n });\r\n \r\n if(arr.join(\"\") === s.join(\"\")) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n }\r\n}\r\n \r\nfunction verif(str) {\r\n \r\n str = str.replace(/^W+/, '').replace(/W+$/, '');\r\n \r\n const arr = str.split(/W+/g);\r\n \r\n for(const el of arr) {\r\n if(el.length === 1) return false;\r\n }\r\n \r\n return arr;\r\n \r\n}\r\n \r\nfunction createArr(arr) {\r\n return arr.map(str => Array(str.length).fill(\"W\"));\r\n}\r\n \r\nfunction stamp(color) {\r\n return (color === \"B\") ? \"R\" : \"B\";\r\n}\r\n \r\nfunction stampFromLtoR(str, s) {\r\n \r\n for(let i = 0; i < str.length - 1; i++) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i + 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}\r\n \r\nfunction stampFromRtoL(str, s) {\r\n \r\n for(let i = str.length - 1; i > 0; i--) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i - 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}"}, {"source_code": "const solve = (arr,n)=>{\r\n\tlet res = arr.split(\"W\");\r\n\tfor(let i=0;ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n let n ,st;\r\n while(t--){\r\n n = readSingleInt();\r\n st = readLine();\r\n let flag = true;\r\n let nr = st.split('W').filter((v)=> v.length);\r\n // console.log(nr)\r\n for(let i=0;ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n let n ,st;\r\n while(t--){\r\n n = readSingleInt();\r\n st = readLine();\r\n let flag = true;\r\n let nr = st.split('W').filter((v)=> v.length);\r\n // console.log(nr)\r\n for(let i=0;ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n let n ,st;\r\n while(t--){\r\n n = readSingleInt();\r\n st = readLine();\r\n let flag = true;\r\n let nr = st.split('W').filter((v)=> v.length);\r\n // console.log(nr)\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let _t = parseInt(readline());\r\n // let _t = 1;\r\n while (_t--) {\r\n let n = parseInt(readline());\r\n let s = readline();\r\n s = s.split('W').filter((e) => e.length > 0);\r\n let ans = true;\r\n s.forEach((e) => {\r\n ans &= (e.indexOf('B') >= 0) & (e.indexOf('R') >= 0);\r\n });\r\n console.log(ans ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\n// cat input.txt | node main.js\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let b = 0\n let r = 0\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (x === 'B') {\n b = 1\n } else if (x === 'R') {\n r = 1\n } else {\n if (b && !r) return false\n if (!b && r) return false\n b = 0\n r = 0\n }\n }\n if (b && !r) return false\n if (!b && r) return false\n return true\n}\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tconst a = 'W' + rl();\r\n\t\tn++;\r\n\r\n\t\tlet ok = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] == 'W') {\r\n\t\t\t\tlet cnt = 0, change = 0;\r\n\t\t\t\tfor (j = i + 1; j < n && a[j] != 'W'; j++) {\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t\tchange |= j - 1 > i && a[j] != a[j-1]; \r\n\t\t\t\t}\r\n\t\t\t\tif (cnt && !change) ok = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const symMap = {\n 'R': 0,\n 'B': 1\n}\n\nconst processData = (lines) => {\n let count = +lines[0]\n let cur = 0\n while(count--) {\n cur++\n // let [n] = lines[cur].split(' ').map(x => +x)\n cur++\n let str = lines[cur]\n\n let isOk = true \n let curSet = [0, 0]\n let isIn = false\n for (let i=0;i i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (n, s)=>{\n let segments = s.split('W');\n // console.log('DEBUG segments', segments);\n for (const seg of segments) {\n if (seg.length === 1) return 'NO';\n if (seg.length === 0) continue;\n let rcount = 0;\n let bcount = 0;\n for (let i = 0; i < seg.length; i++) {\n if (seg[i] === 'R') rcount++;\n if (seg[i] === 'B') bcount++;\n }\n if (rcount === 0 || bcount === 0) return 'NO';\n }\n\n return \"YES\";\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n console.log(`${calc(n, s)}`);\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt() + 1;\r\n\t\tvar S = next() + \"W\";\r\n\t\tvar R = 0;\r\n\t\tvar B = 0;\r\n\t\tvar ok = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(S[i] == \"W\"){\r\n\t\t\t\tif((R > 0 && B > 0) || (R == 0 && B == 0)){\r\n\t\t\t\t\tR = 0;\r\n\t\t\t\t\tB = 0;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(S[i] == \"R\"){\r\n\t\t\t\t\tR++;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tB++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = readline();\r\n while(t--) {\r\n \r\n let [l, s] = [Number(readline()), readline()], arr = [];\r\n \r\n if(l === 1) {\r\n if(s === \"W\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(l === 2) {\r\n if(s == \"WW\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(2 < l) {\r\n s = verif(s);\r\n if(!s) console.log(\"NO\");\r\n else {\r\n if(!s[0]) console.log(\"YES\");\r\n else {\r\n arr = createArr(s);\r\n arr = arr.map((str, index) => {\r\n str = stampFromLtoR(str, s[index]);\r\n return stampFromRtoL(str, s[index]).join(\"\");\r\n });\r\n \r\n if(arr.join(\"\") === s.join(\"\")) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction verif(str) {\r\n \r\n str = str.replace(/^W+/, '').replace(/W+$/, '');\r\n \r\n const arr = str.split(/W+/g);\r\n \r\n for(const el of arr) {\r\n if(el.length === 1) return false;\r\n }\r\n \r\n return arr;\r\n\r\n}\r\n\r\nfunction createArr(arr) {\r\n return arr.map(str => Array(str.length).fill(\"W\"));\r\n}\r\n\r\nfunction stamp(color) {\r\n return (color === \"B\") ? \"R\" : \"B\";\r\n}\r\n\r\nfunction stampFromLtoR(str, s) {\r\n \r\n for(let i = 0; i < str.length - 1; i++) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i + 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}\r\n\r\nfunction stampFromRtoL(str, s) {\r\n \r\n for(let i = str.length - 1; i > 0; i--) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i - 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = readline();\r\n while(t--) {\r\n \r\n let [l, s] = [Number(readline()), readline()], arr = [];\r\n \r\n if(l === 1) {\r\n if(s === \"W\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(l === 2) {\r\n if(s == \"WW\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n \r\n if(2 < l) {\r\n s = verif(s);\r\n if(!s) console.log(\"NO\");\r\n else {\r\n if(!s[0]) console.log(\"YES\");\r\n else {\r\n arr = createArr(s);\r\n arr = arr.map((str, index) => {\r\n str = stampFromLtoR(str, s[index]);\r\n return stampFromRtoL(str, s[index]).join(\"\");\r\n });\r\n \r\n if(arr.join(\"\") === s.join(\"\")) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction verif(str) {\r\n \r\n str = str.replace(/^W+/, '').replace(/W+$/, '');\r\n \r\n const arr = str.match(/W+/g);\r\n \r\n if((arr === null) || (arr.indexOf(\"W\") === -1)) return str.split(/W+/g);\r\n \r\n return false;\r\n\r\n}\r\n\r\nfunction createArr(arr) {\r\n return arr.map(str => Array(str.length).fill(\"W\"));\r\n}\r\n\r\nfunction stamp(color) {\r\n return (color === \"B\") ? \"R\" : \"B\";\r\n}\r\n\r\nfunction stampFromLtoR(str, s) {\r\n \r\n for(let i = 0; i < str.length - 1; i++) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i + 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}\r\n\r\nfunction stampFromRtoL(str, s) {\r\n \r\n for(let i = str.length - 1; i > 0; i--) {\r\n if(str[i] !== s[i]) {\r\n str[i] = s[i];\r\n str[i - 1] = stamp(s[i]);\r\n }\r\n }\r\n \r\n return str;\r\n}\r\n\r\n\r\n"}, {"source_code": "const solve = (arr,n)=>{\r\n\tlet i,j;\r\n\tif(arr.length===1) return \"NO\";\r\n\tfor(i=0;i{\r\n if(arr.length===1) return \"NO\";\r\n if((n>2)&&((arr.indexOf(\"W\")===-1)||arr.indexOf(\"W\")===n-1)) return \"YES\";\r\n let res = arr.split(\"W\"),flag = 0;\r\n for(let i=0;i char.charCodeAt(0) - 97;\r\n let res = 0n;\r\n for (let [l, r] of a) {\r\n var _map$get, _map$get2, _map$get3, _map$get4, _map$get5, _map$get6;\r\n let statel = 1 << get(l),\r\n stater = 1 << get(r) + 11,\r\n state = statel | stater;\r\n res = res + ((_map$get = map.get(statel)) !== null && _map$get !== void 0 ? _map$get : 0n) + ((_map$get2 = map.get(stater)) !== null && _map$get2 !== void 0 ? _map$get2 : 0n) - ((_map$get3 = map.get(state)) !== null && _map$get3 !== void 0 ? _map$get3 : 0n) * 2n;\r\n map.set(statel, ((_map$get4 = map.get(statel)) !== null && _map$get4 !== void 0 ? _map$get4 : 0n) + 1n);\r\n map.set(stater, ((_map$get5 = map.get(stater)) !== null && _map$get5 !== void 0 ? _map$get5 : 0n) + 1n);\r\n map.set(state, ((_map$get6 = map.get(state)) !== null && _map$get6 !== void 0 ? _map$get6 : 0n) + 1n);\r\n }\r\n console.log(res.toString());\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n let n = Number(await read()),\r\n a = [];\r\n while (n--) {\r\n a.push(await read());\r\n }\r\n solve(a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n if (n < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n const strs = a.split('W');\r\n for (let str of strs) {\r\n let b = 0,\r\n r = 0;\r\n for (let char of str) {\r\n if (char === 'B') b++;else r++;\r\n }\r\n if (b !== 0 && r === 0 || b === 0 && r !== 0) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = await read();\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "3f284afb044c8a57a02cd015d06e0ef0"} {"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nlet currentLine = 0\r\nlet inputString = ''\r\n\r\nprocess.stdin.on('data', raw_data => {\r\n inputString += raw_data\r\n})\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(line => {\r\n return line.trim()\r\n })\r\n main()\r\n})\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++]\r\n}\r\n\r\n\r\n// function main() {\r\n// /**\r\n// * INPUT TECHNIQUES\r\n// */\r\n\r\n// // Simple String Input\r\n// const strInput = readLine()\r\n\r\n// // Array Input\r\n// const arrInput = readLine().split(' ')\r\n\r\n// // Array Destructuring and Three variable input from a single line, separated by a space\r\n// const [a, b, c] = readLine.split(' ')\r\n\r\n// // If you need number separated by space just map each element of the array this way\r\n// const [x, y, z] = readLine.split(' ').map(Number)\r\n\r\n\r\n// /**\r\n// * OUTPUT TECHNIQUES\r\n// */\r\n\r\n// // End by a new line \"\\n\"\r\n// console.log(\"Hi\")\r\n\r\n// // Don't end by new line character \"\\n\"\r\n// process.stdout.write(\"Hi\")\r\n\r\n// }\r\n\r\nfunction main() {\r\n let t = readLine();\r\n t = parseInt(t);\r\n\r\n while (t--) {\r\n solve()\r\n }\r\n}\r\n\r\nfunction solve() {\r\n const strInput = readLine();\r\n if (strInput.length < 2) {\r\n console.log(\"NO\");\r\n } else {\r\n const first = strInput.substring(0, strInput.length / 2);\r\n const second = strInput.substring(strInput.length / 2, strInput.length);\r\n if (first == second) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}", "positive_code": [{"source_code": " var len = readline();\r\n for(var i=0;i<+len;i++)\r\n {\r\n var inputData = readline();\r\n if(inputData.length%2 !=0)\r\n print(\"NO\");\r\n else if((inputData.substring(0,(inputData.length/2))) == (inputData.substring(inputData.length/2,inputData.length)))\r\n print(\"YES\");\r\n else\r\n print(\"NO\");\r\n }"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var inputData = readline();\r\n if(inputData.length%2 !=0)\r\n print(\"NO\");\r\n// else if((inputData.length == 2) && (inputData[0]!=inputData[1]))\r\n // print(\"NO\");\r\n else if((inputData.substring(0,(inputData.length/2))) == (inputData.substring(inputData.length/2,inputData.length)))\r\n print(\"YES\");\r\n else\r\n print(\"NO\");\r\n}\r\n"}, {"source_code": "q = +readline();\r\nwhile (q--) {\r\n x = readline();\r\n if (x.length % 2 !== 0) {\r\n print(\"NO\");\r\n } else {\r\n var first = x.slice(0, x.length / 2);\r\n var last = x.slice(x.length / 2, x.length);\r\n if (first === last) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "q = +readline();\r\nwhile (q--) {\r\n x = readline();\r\n if (x.length % 2 !== 0) {\r\n print(\"NO\");\r\n } else {\r\n var first = x.slice(0, x.length / 2);\r\n var last = x.slice(x.length / 2, x.length);\r\n if (first.localeCompare(last) === 0) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "c = +readline();\r\nfor (i = 0; i < c; i++) {\r\n x = readline();\r\n if (x.length % 2 === 0) {\r\n y = x.length;\r\n z = x.split(\"\", y / 2).join(\"\");\r\n q = x.substring(x.length, x.length / 2);\r\n if (q === z) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "var strNumbers = parseInt(readline());\r\n\r\nwhile(strNumbers--) {\r\n var str = (readline());\r\n var parts = [str.slice(0 , str.length / 2), str.slice(str.length / 2)];\r\n print(parts[0] == parts[1] ? 'YES' : 'NO');\r\n}"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var s = readline();\r\n if(s.length%2 !== 0){\r\n print('NO');\r\n }\r\n else{\r\n var s1 = s.slice(0 , s.length/2);\r\n var s2 = s.slice(s.length/2 , s.length);\r\n if(s1 == s2){\r\n print('YES');\r\n }\r\n else{\r\n print('NO');\r\n }\r\n }\r\n }"}, {"source_code": "var testCase=+readline(),counter\r\nfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n \r\n \r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\n while(test--)\r\n {\r\n let string = readLine();\r\n if (string.substr(0, string.length/2) === string.substr(string.length/2, string.length)){\r\n console.log(\"YES\");\r\n }\r\n else\r\n {\r\n console.log(\"NO\");\r\n }\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\n while(test--)\r\n {\r\n let string = readLine();\r\n if ((string.length)%2 === 1) {\r\n console.log(\"NO\");\r\n }\r\n else{\r\n let string2 = string.substr(0, string.length/2);\r\n let string3 = string.substr(string.length/2, string.length);\r\n if (string2 === string3) {\r\n console.log(\"YES\");\r\n }\r\n else\r\n {\r\n console.log(\"NO\");\r\n }\r\n }\r\n }\r\n return 0;\r\n}"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n const n = +(readline());\r\n for(let i =0; i{\r\n\r\n const n = s.length;\r\n const mid = Math.ceil(n/2);\r\n let i =0; j = mid;\r\n\r\n for(; i {\n if (c === 0) {\n c++;\n return;\n }\n\n const len = str.length;\n const mid = Math.ceil(len / 2);\n let ans = \"YES\";\n\n for (let i = 0; i < mid; i++) {\n if (str[i] !== str[i + mid]) {\n ans = \"NO\";\n }\n }\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst reverseText = (s) => { return s.split('').reverse().join('') }\r\nconst hasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\n\r\nconst hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\n\r\nconst isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\n\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&')\r\n\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\n// LIBRARY END\r\n\r\nconst getresult = (str) => {\r\n \r\n if( isOdd(str.length) ) return 'NO'\r\n \r\n let idx = str.length / 2\r\n\r\n \r\n let s1 = str.substring(0, idx)\r\n let s2 = str.substring(idx)\r\n \r\n return s1 === s2 ? 'YES' : 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n console.log( getresult( str ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tif(S.length % 2 == 1){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar L = S.substring(0, S.length / 2);\r\n\t\tvar R = S.substring(S.length / 2, S.length);\r\n\t\tif(L == R){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split('');\n if(k.length % 2 == 1){\n console.log('NO');\n }else{\n var a = '';\n var b = '';\n for(var l = 0; l < k.length / 2; l++){\n a += k[l];\n }\n for(var h = k.length / 2; h < k.length; h++){\n b += k[h];\n }\n if(a == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split('');\n if(k.length % 2 == 1){\n console.log('NO');\n }else{\n var a = '';\n var b = '';\n for(var l = 0; l < k.length / 2; l++){\n a += k[l];\n }\n for(var h = k.length / 2; h < k.length; h++){\n b += k[h];\n }\n if(a == b){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.nums();\n\tlet ans = [];\n\tfor(let i = 0; i< t; i++){\n\t\tlet s = nl.line();\n\t\tif (s.length % 2 == 0){\n\t\t\tlet l = s.length;\n\t\t\tans.push(s.substring(0, l/2) === s.substring(l/2));\n\t\t} else {\n\t\t\tans.push(false);\n\t\t}\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let buffer = '';\r\nprocess.stdin.on('data', c => buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let str;\r\n\r\n while (T--) {\r\n str = lines[index++];\r\n solve(str);\r\n }\r\n}\r\n\r\nfunction solve(str) {\r\n if (str.length % 2 === 0 && str.slice(0, str.length / 2) === str.slice(str.length / 2)) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1619/A\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst getLine = (function () {\n const getLineGen = (async function* () {\n for await (const line of rl) {\n yield line\n }\n })()\n return async () => {\n let next\n do {\n next = await getLineGen.next()\n } while (!next.done && next.value === '')\n return next.value\n }\n})()\n\nlet solve = async () => {\n const strLine = parseInt(await getLine())\n for (let i = 0; i < strLine; i++) {\n const str = await getLine()\n let flag = true\n\n if (str.length % 2 != 0) {\n flag = false\n }\n for (let j = 0; j < str.length / 2; j++) {\n if (str[j] != str[j + str.length / 2]) {\n flag = false\n }\n }\n if (flag) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n // process.exit()\n process.stdin.unref()\n}\n\nsolve()\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n solve();\r\n // cmd: node cp.js < input.txt > output.txt\r\n});\r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n\t let inp = readLine();\r\n if(inp.length%2!==0){\r\n console.log(\"NO\")\r\n }else if(inp.substring(0,inp.length/2)===inp.substring(inp.length/2, inp.length)){\r\n console.log(\"YES\");\r\n }else{\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n//------------------------------------------------------------------------------------\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let num = parseInt(readline());\r\n while (num--) {\r\n let a = readline();\r\n if (a.length % 2 != 0) print(\"NO\");\r\n else {\r\n let ltg = a.length / 2;\r\n let str1 = a.substring(0, ltg);\r\n let str2 = \"\";\r\n for (let i = ltg; i < a.length; i++) {\r\n str2 += a[i];\r\n }\r\n print(str1 == str2 ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\r\nconst readline = require('readline');\r\nconst process = require('process');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\nlet haveLineCount = false;\r\nlet lineCount;\r\nrl.on('line', (line) => {\r\n if (!haveLineCount) {\r\n lineCount = parseInt(line.trim());\r\n haveLineCount = true;\r\n }\r\n else if (lineCount > 0) {\r\n let str = line.trim();\r\n if (str.length %2 != 0) {\r\n console.log('NO');\r\n }\r\n else {\r\n let half1 = str.substring(0,str.length/2);\r\n let half2 = str.substring(str.length/2);\r\n if (half1 == half2) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n }\r\n lineCount--;\r\n }\r\n else {\r\n process.exit();\r\n }\r\n})"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\ndata = data.replace(/\\s*$/, '')\r\n.split('\\n')\r\n.map(str => str.replace(/\\s*$/, ''));\r\n\r\nlet testCases = parseInt(data.shift());\r\n\r\nwhile(testCases--) {\r\n\r\nconst s = readLine();\r\nconst res = a(s);\r\nconsole.log(res)\r\n}\r\n});\r\n\r\nfunction readLine() { \r\nreturn data[currentLine++];\r\n}\r\n\r\nfunction a(s){\r\n if(s.length % 2 === 1) return 'NO'\r\n if(s.slice(0,s.length/2) !== s.slice(s.length/2)) return 'NO'\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;\r\n"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.once('line', (_) => { \n \n rl.on('line', (txt) => {\n // console.log(txt);\n const l = txt.length;\n const mid = (l/2).toFixed(0)\n if (l % 2 == 0 && txt.slice(0, mid) === txt.slice(mid)) {\n console.log(\"YES\")\n }\n else {\n console.log(\"NO\")\n }\n });\n});\n"}, {"source_code": "const readline = require(\"readline\");\r\n \r\nconst input = [];\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet counter = 0;\r\nrl.on(\"line\", function (cmd) {\r\n counter++\r\n input.push(cmd);\r\n});\r\nrl.on(\"close\", function (cmd) {\r\n for (let i=1;i<=input.length-1;i++){\r\n const str = input[i]; \r\n if (str.length%2===1) {console.log(\"NO\")}\r\n else{\r\n const string1 = str.substr(0,str.length/2)\r\n const string2 = str.substr(str.length/2,str.length-1)\r\n if (string1===string2) {console.log(\"YES\")}\r\n else {console.log(\"NO\")}\r\n }\r\n\r\n }\r\n \r\n process.exit(0);\r\n });"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let [t] = readline().split(' ').map(num => parseInt(num));\n for (let i = 0; i < t; i++) {\n let s = readline();\n if (s.length % 2 === 1) {\n console.log('NO');\n } else if (s.slice(0, s.length / 2) === s.slice(s.length / 2)) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var a = readline()\r\n if(a.length % 2 != 0) print(\"NO\")\r\n else{\r\n //print((a.substring(0, a.length/2)) == (a.substring(a.length/2,a.substring/2))?\"YES\":\"NO\")\r\n var ltg = a.length / 2\r\n var str1 = a.substring(0, ltg)\r\n var str2 = ''\r\n for(let i = ltg;i < a.length;i++){\r\n str2 += a[i]\r\n }\r\n print(str1 == str2?\"YES\":\"NO\")\r\n }\r\n }\r\n\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n\tinputString = inputString\r\n\t\t.trim()\r\n\t\t.split(\"\\n\")\r\n\t\t.map((string) => {\r\n\t\t\treturn string.trim();\r\n\t\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readline() {\r\n\treturn inputString[currentLine++];\r\n}\r\nfunction printLine(x) {\r\n\t// process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\r\n\tconsole.log(x); // with auto '\\n' (newline)\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n\tconst inputCount = readline();\r\n\tfor (let i = 0; i < inputCount; i++) {\r\n\t\texec(readline());\r\n\t}\r\n}\r\n\r\nfunction exec(input) {\r\n\tinput = input.split(\"\");\r\n\tif (input.length % 2 !== 0) {\r\n\t\treturn printLine(\"NO\");\r\n\t} else {\r\n\t\tconst firstHalf = input.splice(0, input.length / 2);\r\n\t\tif (firstHalf.join(\"\") === input.join(\"\")) {\r\n\t\t\tprintLine(\"YES\");\r\n\t\t} else {\r\n\t\t\tprintLine(\"NO\");\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let noOfTestCases = Number(readline());\r\n let testCaseArray = [];\r\n for (let i = 0; i < noOfTestCases; i++) {\r\n testCaseArray.push(readline());\r\n }\r\n\r\n for (let i = 0; i < noOfTestCases; i++) {\r\n checkSquare(testCaseArray[i])\r\n }\r\n}\r\n\r\n\r\n\r\nfunction checkSquare(B) {\r\n let len = B.length;\r\n if (len % 2 == 1) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n let i = 0;\r\n while (i < len/2) {\r\n if(B[i] != B[i+len/2]) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n i++;\r\n }\r\n console.log(\"YES\")\r\n}\r\n\r\n\r\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n fileContents.forEach(string => {\n if(string.length%2!==0){\n console.log(\"NO\")\n }else{\n const indexOfHalf = string.length/2;\n const stringAsArr = string.split(\"\")\n let isThereAMismath = false\n\n for(let i =0; i< indexOfHalf; i++){\n if(stringAsArr[i] !== stringAsArr[i+indexOfHalf]){\n isThereAMismath =true;\n break;\n }\n }\n\n if(isThereAMismath == false){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n }\n }\n })\n}\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\t\tconst n = s.length;\r\n\r\n\t\tlet ans = false;\r\n\t\tif (s.slice(0, Math.floor(n/2)) == s.slice(Math.floor(n/2)))\r\n\t\t\tans = true;\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(str) {\r\n const n = str.length\r\n if (str.slice(0, Math.floor(n / 2)) === str.slice(Math.floor(n / 2))) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n if (str.length & 1) return false\n const limit = str.length / 2\n for (let i = 0; i < limit; i++) {\n if (str[i] !== str[limit + i]) return false\n }\n return true\n}\n"}, {"source_code": "var n = parseInt(readline());\r\nwhile (n -- > 0) {\r\n var str = readline();\r\n var flag = str.length % 2 == 0;\r\n for (var i = 0; i < str.length / 2; i++) {\r\n flag = flag & (str[i] == str[i + str.length / 2]);\r\n }\r\n print(flag ? \"YES\" : \"NO\");\r\n}"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n let a = readline();\r\n var y = false;\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n \r\n \r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\n let s=[];\r\n \r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\n\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\n\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\n\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\n\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\n\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+readline();\r\nlet s=[];\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n const n = +(readline());\r\n console.log(n)\r\n for(let i =0; i{\r\n\r\n const n = s.length;\r\n const mid = Math.ceil(n/2);\r\n let i =0; j = mid;\r\n\r\n for(; i l.replace(/\\r/, ''));\n\n\tconst n = Number(line[0]);\n\tconst k = Number(line[n + 1]);\n\tlet length = 0;\n\n\tfor(let i = 1; i < line.length - 2; i++) {\n\t\tconst [ s, e ] = line[i].split(' ');\n\n\t\tif (Number(s) <= k && k <= Number(e)) {\n\t\t\tbreak;\n\t\t} else {\n\t\t\tlength++;\n\t\t}\n\t}\n\t\n\tconsole.log(n - length);\n\n\tprocess.exit(0);\n});"}, {"source_code": "const n = readline();\nconst segs = [];\nfor (var i = 0; i < n; i++) {\n\tsegs.push(readline().split(\" \"));\n}\nvar now = readline();\nvar result = 0;\nfor (var i = 0; i < n; i++) {\n\tif (Number(segs[i][1]) >= now) {\n\t\tresult++;\n\t}\n}\nprint(result);"}, {"source_code": "var n = parseInt(readline())\n\nvar ar = []\nfor(var t=0;t(parseInt(v)))\n ar.push({s: a[0], e: a[1]})\n}\n\nvar K = parseInt(readline())\n\nvar res = 0;\nar.forEach((it) => {\n \n if (K parseInt(x)));\n}\nvar k = parseInt(readline());\nvar index = segs.findIndex(seg => (k >= seg[0] && k <= seg[1]));\nprint(n - index);\n"}, {"source_code": "var chapterCounter = parseInt(readline());\nvar chapters = [];\n\nfor (var i = 0; i < chapterCounter; i++) {\n var chapter = readline().split(' ').map(function (num) {\n return parseInt(num);\n })\n chapters.push(chapter);\n}\n\nvar index = parseInt(readline());\n\n// var chapterCounter = 3\n// var chapters = [[1,4],[5,9],[10,12]];\n// var index = 9;\n\nfunction main() {\n var chaptersFinished = 0;\n for (var i = 0; i < chapters.length; i++) {\n if (index < chapters[i][1] + 1) {\n return (chapterCounter - chaptersFinished + '');\n } else if (index === chapters[i][1] + 1) {\n return (chapterCounter - chaptersFinished - 1 + '');\n } else {\n chaptersFinished++;\n }\n }\n return 0;\n}\n\nwrite(main());\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n\tvar list = new Array(N);\n\tfor(var i = 0; i < N; i++){\n\t\tlist[i] = nextIntArray();\n\t}\n\tvar K = nextInt();\n\tvar output = 0;\n\tvar ng = false;\n\tfor(var i = 0; i < N; i++){\n\t\tif(list[i][0] <= K && K <= list[i][1]){\n\t\t\tng = true;\n\t\t}\n\t\tif(ng){\n\t\t\toutput++;\n\t\t}\n\t}\n\tmyout(output);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet lines = 0;\nconst chapters = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n lines = +d;\n return;\n }\n\n if (c <= lines) {\n chapters.push(d.split(' ').map(Number));\n }\n\n if (c > lines) {\n const k = +d;\n let ans = chapters.length;\n\n for (let i = 0; i < chapters.length; i++) {\n const [start, finish] = chapters[i];\n\n if (k >= start && k <= finish) {\n break;\n }\n\n ans--;\n }\n\n console.log(ans);\n }\n\n c++;\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let n = parseInt(input[0]);\n\n let parts = [];\n for(let i = 0; i < n; i++){\n let pages = []; input[i+1].split(' ').forEach( j => pages.push(parseInt(j)) );\n parts.push(pages);\n }\n let k = parseInt(input[n+1]);\n\n for(let i = 0; i < n; i++){\n if(k >= parts[i][0] && parts[i][1] >= k){\n console.log(parts.length-i);\n break;\n }\n }\n});\n\n"}], "negative_code": [], "src_uid": "2545b6af730f99193041a8810b728cb3"} {"source_code": "var s = readline().split(\"\"),\n\tn = readline(),\n\ta = [], v;\nfor (var i in s) {\n\tif (a.indexOf(s[i]) == -1) {\n\t\ta.push(s[i]);\n }\n}\nif (n <= s.length) {\n\tv = n - ((a.length > n) ? n : a.length);\n} else {\n\tv = \"impossible\"\n}\nprint(v);\n", "positive_code": [{"source_code": "//function readline(){\n//\tyield \"\";\n//}\n\nvar str = readline().split('');\nvar lena = 0;\nvar cnt = [];\nfor(var chr in str){\n\tif(!cnt[str[chr]]){\n\t\tlena++;\n\t\tcnt[str[chr]]=1;\n\t}\n}\n//console.log(cnt);\n//console.log(typeof(cnt));\n//console.log(lena);\n\n\nvar n = parseInt(readline());\nif(lena >= n){\n\tprint(0);\n}else if(str.length < n){\n\tprint(\"impossible\");\n}else{\n\tprint(n - lena);\n}\n"}, {"source_code": "var s = readline().split('');\nvar n = parseInt(readline());\n\nif(s.length= n){\n\tprint(0);\n}else if(str.length < n){\n\tprint(\"impossible\");\n}else{\n\tprint(n - lena);\n}"}], "negative_code": [{"source_code": "var str = readline(),\n\tn = parseInt(readline());\nif (n > str.length)\n\tprint(\"impossible\");\nelse {\n\tvar foo = str.replace(/(.)(?=.*\\1)/g, \"\");\n\tprint(str.length - foo.length);\n}"}, {"source_code": "var str = readline(),\n\tn = parseInt(readline());\nif (n > str.length)\n\tprint(\"impossible\");\nelse {\n\tvar g = str.replace(/(.)(?=.*\\1)/g, \"\"),\n\t e = str.length - g.length;\n\t print((e > n) ? n : e);\n\tprint();\n}"}], "src_uid": "bd5912fe2c5c37658f28f6b159b39645"} {"source_code": "var n = parseInt(readline())\nvar p = []\nvar q = []\nfor (i = 0; i < n; i++) {\n var line = readline().split(' ')\n p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}\n q[i] = p[i].x\n q[i+n] = p[i].y\n}\np.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})\nvar ans = 0\nfor (aa in q) {\n var a=q[aa]\n var now = 0\n var ok = true\n for (bb in p) {\n b=p[bb]\n if (b.y > a && b.x > a) {\n ok = false\n break\n }\n if (b.y > a ) {\n now++\n }\n }\n if (!ok) {\n continue\n }\n if (now>n/2) {\n continue\n }\n var nowans = 0\n var ms = []\n for (bb in p) {\n b = p[bb]\n if (now+1 <= n/2 && b.x <= a && b.y < b.x) {\n now++;\n nowans+=b.y\n ms.push(b)\n } else if (b.y>a){\n nowans+=b.y\n } else {\n nowans+=b.x\n }\n }\n if (ans <=0 || (nowans*a < ans)) {\n ans = nowans*a\n }\n}\nprint(ans)\n", "positive_code": [{"source_code": "var n = parseInt(readline())\nvar p = [], q=[]\nfor (i = 0; i < n; i++) {\n var line = readline().split(' ')\n p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}\n q.push(p[i].x, p[i].y)\n}\np.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})\nminh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)\nprint(Math.min.apply(Math,q.map(function(a) {\n var now = p.reduce(function(x,y) {\n return x + (y.y > a ? 1:0)\n }, 0)\n if (a < minh || now > n/2) {\n return Number.MAX_VALUE\n }\n return p.reduce(function(x,b) {\n if (now+1 <= n/2 && b.x <= a && b.y < b.x) {\n now++;\n return x+b.y\n } else if (b.y>a){\n return x+b.y\n } else {\n return x+b.x\n }\n },0) * a\n})))"}, {"source_code": "var n = parseInt(readline())\nvar p = [], q=[]\nfor (i = 0; i < n; i++) {\n var line = readline().split(' ')\n p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}\n q.push(p[i].x, p[i].y)\n}\np.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})\nminh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)\nprint(Math.min.apply(Math,q.map(function(a) {\n var now = p.reduce(function(x,y) {\n if (y.y > a) {\n return x+1\n }\n return x\n }, 0)\n if (a < minh || now > n/2) {\n return Number.MAX_VALUE\n }\n return p.reduce(function(x,b) {\n if (now+1 <= n/2 && b.x <= a && b.y < b.x) {\n now++;\n return x+b.y\n } else if (b.y>a){\n return x+b.y\n } else {\n return x+b.x\n }\n },0) * a\n})))\n"}], "negative_code": [{"source_code": "var n = parseInt(readline())\nvar p = []\nvar q = []\nfor (i = 0; i < n; i++) {\n var line = readline().split(' ')\n p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}\n q[i] = p[i].x\n q[i+n] = p[i].y\n}\np.sort(function(a,b) { return (b.y-b.x) - (a.y-a.x)})\nvar ans = 0\nfor (aa in q) {\n var a=q[aa]\n var now = 0\n var ok = true\n for (bb in p) {\n b=p[bb]\n if (b.y > a && b.x > a) {\n ok = false\n break\n }\n if (b.y > a ) {\n now++\n }\n }\n if (!ok) {\n continue\n }\n if (now>n/2) {\n continue\n }\n var nowans = 0\n for (bb in p) {\n b = p[bb]\n if (now < n/2 && b.y <= a && b.x <= a && b.y < b.x) {\n now++;\n nowans+=b.y\n } else if (b.y>a){\n nowans+=b.y\n } else {\n nowans+=b.x\n }\n }\n if (ans <=0 || (nowans*a < ans)) {\n ans = nowans*a\n }\n}\nprint(ans)\n"}, {"source_code": "var n = parseInt(readline())\nvar p = []\nvar q = []\nfor (i = 0; i < n; i++) {\n var line = readline().split(' ')\n p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}\n q.push(p[i].x, p[i].y)\n}\np.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})\nminh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)\nvar ans = 0\nvar all = q.map(function(a) {\n var now = p.reduce(function(x,y) {\n return x + y.y > a ? 1:0\n }, 0)\n if (a < minh || now > n/2) {\n return Number.MAX_VALUE\n }\n return p.reduce(function(x,b) {\n if (now+1 <= n/2 && b.x <= a && b.y < b.x) {\n now++;\n return x+b.y\n } else if (b.y>a){\n return x+b.y\n } else {\n return x+b.x\n }\n },0) * a\n})\nprint(Math.min.apply(Math, all))\n"}], "src_uid": "00b27a7d30bf2e200bdecd3ae74433c7"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nclass SegTree {\r\n constructor(l, r) {\r\n this.l = l;\r\n this.r = r;\r\n this.root = this._newNode(l, r);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === x && r === y) {\r\n node.val[z % 3]++;\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n\r\n for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i];\r\n }\r\n\r\n _query(node, x, y, z) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val[z];\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y, z);else if (x > mid) res = this._query(node.right, x, y, z);else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z);\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction solve(n, s) {\r\n let pre = new Array(n + 1).fill(0),\r\n sum = 0,\r\n max = 0,\r\n min = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n sum += s[i] === '+' ? 1 : 0;\r\n pre[i + 1] = i + 1 - 2 * sum;\r\n max = Math.max(max, pre[i + 1]);\r\n min = Math.min(min, pre[i + 1]);\r\n }\r\n\r\n let res = 0;\r\n const segTree = new SegTree(min, max);\r\n\r\n for (let i = 0; i <= n; i++) {\r\n const cur = pre[i];\r\n res += segTree.query(min, cur, (cur % 3 + 3) % 3);\r\n segTree.update(cur, cur, (cur % 3 + 3) % 3);\r\n }\r\n\r\n return res;\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = [];\r\n\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++]);\r\n let str = inputs[__++].trim();\r\n res.push(solve(n, str));\r\n }\r\n\r\n console.log(res.join('\\n'));\r\n}();\r\n", "positive_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nclass SegTree {\r\n constructor(l, r) {\r\n this.l = l\r\n this.r = r\r\n this.root = this._newNode(l, r)\r\n this.update = this._update.bind(this, this.root)\r\n this.query = this._query.bind(this, this.root)\r\n }\r\n _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {\r\n return { val, l, r, left, right }\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return\r\n const { l, r } = node\r\n if (l === x && r === y) {\r\n node.val[z % 3]++\r\n return\r\n }\r\n const mid = Math.floor((l + r) / 2)\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid)\r\n node.right = this._newNode(mid + 1, r)\r\n }\r\n if (y <= mid) this._update(node.left, x, y, z)\r\n else if (x > mid) this._update(node.right, x, y, z)\r\n else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)\r\n for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]\r\n }\r\n _query(node, x, y, z) {\r\n if (y < x) return 0\r\n if (!node) return 0\r\n const { l, r } = node\r\n if (l === x && r === y) return node.val[z]\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2)\r\n if (y <= mid) res = this._query(node.left, x, y, z)\r\n else if (x > mid) res = this._query(node.right, x, y, z)\r\n else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)\r\n return res\r\n }\r\n}\r\nfunction solve(n, s) {\r\n let pre = new Array(n + 1).fill(0),\r\n sum = 0,\r\n max = 0,\r\n min = 0\r\n for (let i = 0; i < n; i++) {\r\n sum += s[i] === '+' ? 1 : 0\r\n pre[i + 1] = i + 1 - 2 * sum\r\n max = Math.max(max, pre[i + 1])\r\n min = Math.min(min, pre[i + 1])\r\n }\r\n let res = 0\r\n const segTree = new SegTree(min, max)\r\n for (let i = 0; i <= n; i++) {\r\n const cur = pre[i]\r\n res += segTree.query(min, cur, ((cur % 3) + 3) % 3)\r\n segTree.update(cur, cur, ((cur % 3) + 3) % 3)\r\n }\r\n return res\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++])\r\n let str = inputs[__++].trim()\r\n res.push(solve(n, str))\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}], "negative_code": [], "src_uid": "19a3247ef9d10563db821ca19b0f9004"} {"source_code": "var f=readline();\r\nfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let i = 0; i < N; i++) {\r\n let size = readline();\r\n let str = readline();\r\n\r\n let result = 1;\r\n for (let i = 1; i < size; i++) {\r\n if (str[i] === str[i - 1]) {\r\n result += 1;\r\n } else {\r\n result += i + 1;\r\n }\r\n }\r\n\r\n output(result);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n const cases = readline();\r\n\r\n for (let i = 0; i < cases; i++) {\r\n const size = readline();\r\n const n = readline();\r\n let total = 0;\r\n n.split('').forEach((digit, index) => {\r\n if (digit === n[index - 1]) {\r\n total++;\r\n } else {\r\n total += index + 1;\r\n }\r\n });\r\n output(total);\r\n }\r\n}"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0], e = 0\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = Number(lines[i])\n }else{\n var k = lines[i].split('').map(Number)\n ,s = e;\n for(j = 1; j < e; j++){\n if(k[j] != k[j - 1]){\n s += j\n }\n }\n console.log(s)\n }\n }\n \n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var a = lines[i].split('').map(Number);\n var num = n;\n for(j = 1; j < n; j++){\n if(a[j] != a[j - 1]){\n num += j;\n }\n }\n console.log(num);\n }\n }\n});\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\"\");\r\n let cnt = 0;\r\n for (let i = n - 1; i >= 1; i--) {\r\n if (arr[i] !== arr[i - 1]) {\r\n cnt += i;\r\n }\r\n }\r\n console.log(cnt + n);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n //var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var n = readline();\r\n var a = readline();\r\n var cnt=1;\r\n for(var i=1;i str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var f=readline();\r\nfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n let n, m, k, grid = [];\r\n [n, m, k] = readline().split(\" \");\r\n for(let i = 0; i < Number(n); i++) {\r\n grid.push(readline());\r\n }\r\n if(ticks(grid, Number(n), Number(m), Number(k))) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}\r\n\r\nfunction ticks(grid, n, m, k) {\r\n for(let x = 0; x < n; x++) {\r\n for(let y = 0; y < m; y++) {\r\n if(grid[x][y] == \"*\" && !(findAParent(grid, x, y, n, m, k)||createParent(grid, x, y, n, m, k))) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction createParent(grid, x, y, n, m, k) {\r\n //create right side children\r\n let rx = x, ry = y, numOfRSChilds = 0;\r\n while(0 < rx && ry < m - 1 && numOfRSChilds < k) {\r\n rx--;\r\n ry++;\r\n if(grid[rx][ry] == \".\") return false;\r\n if(grid[rx][ry] == \"*\") numOfRSChilds++;\r\n }\r\n //create left side children\r\n let lx = x, ly = y, numOfLSChilds = 0;\r\n while(0 < lx && 0 < ly && numOfLSChilds < k) {\r\n lx--;\r\n ly--;\r\n if(grid[lx][ly] == \".\") return false;\r\n if(grid[lx][ly] == \"*\") numOfLSChilds++;\r\n }\r\n return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == k);\r\n}\r\n\r\nfunction findAParent(grid, x, y, n, m, k) {\r\n //check the positive diagnol\r\n let rx = x, ry = y;\r\n while(rx < n - 1 && ry < m - 1) {\r\n rx++;\r\n ry++;\r\n if(grid[rx][ry] == \"*\" && parent(grid, rx, ry, n, m, Math.max(k, (rx - x)))) {\r\n return true;\r\n }\r\n }\r\n //check the negative diagnol\r\n let lx = x, ly = y;\r\n while(lx < n - 1 && 0 < ly) {\r\n lx++;\r\n ly--;\r\n if(grid[lx][ly] == \"*\" &&parent(grid, lx, ly, n, m, Math.max(k, (lx - x)))) return true;\r\n }\r\n return false;\r\n}\r\n\r\nfunction parent(grid, x, y, n, m, numOfChilds) {\r\n //create right side children\r\n let rx = x, ry = y, numOfRSChilds = 0;\r\n while(0 < rx && ry < m - 1 && numOfRSChilds < numOfChilds) {\r\n rx--;\r\n ry++;\r\n if(grid[rx][ry] == \".\") return false;\r\n if(grid[rx][ry] == \"*\") numOfRSChilds++;\r\n }\r\n //create left side children\r\n let lx = x, ly = y, numOfLSChilds = 0;\r\n while(0 < lx && 0 < ly && numOfLSChilds < numOfChilds) {\r\n lx--;\r\n ly--;\r\n if(grid[lx][ly] == \".\") return false;\r\n if(grid[lx][ly] == \"*\") numOfLSChilds++;\r\n }\r\n \r\n return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == numOfChilds);\r\n}", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, m, k] = rna();\r\n\t\tlet g = Array.from(Array(n), x => Array(m));\r\n\r\n\t\tfor (let i in g) {\r\n\t\t\tg[i] = rl().split('');\r\n\t\t}\r\n\r\n\t\tfor (let i in g) {\r\n\t\t\tfor (let j in g[i]) {\r\n\t\t\t\tg[i][j] = g[i][j] == '*' ? 1 : 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = n - 1; i >= k; i--) {\r\n\t\t\tfor (let j = k; j < m - k; j++) {\r\n\t\t\t\tif (g[i][j]) {\r\n\t\t\t\t\tlet d = 1;\r\n\t\t\t\t\twhile(i-d >= 0 && j-d >= 0 && j+d < m && g[i-d][j-d] && g[i-d][j+d])\r\n\t\t\t\t\t\td++;\r\n\t\t\t\t\td--;\r\n\t\t\t\t\tif (d >= k) {\r\n\t\t\t\t\t\twhile (d >= 0) {\r\n\t\t\t\t\t\t\tg[i-d][j-d] = g[i-d][j+d] = 2;\r\n\t\t\t\t\t\t\td--;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = true;\r\n\t\tfor (let i in g)\r\n\t\t\tfor (let j in g[i])\r\n\t\t\t\tans = ans && g[i][j] != 1;\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const t = Number(readline()), grid = [];\r\n let n, m, k;\r\n [n, m, k] = readline().split(\" \");\r\n for(let i = 0; i < Number(n); i++) {\r\n grid.push(readline());\r\n }\r\n if(ticks(grid, Number(n), Number(m), Number(k))) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}\r\n\r\nfunction ticks(grid, n, m, k) {\r\n for(let x = 0; x < n; x++) {\r\n for(let y = 0; y < m; y++) {\r\n if(grid[x][y] == \"*\" && !(findAParent(grid, x, y, n, m, k)||createParent(grid, x, y, n, m, k))) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction createParent(grid, x, y, n, m, k) {\r\n //create right side children\r\n let rx = x, ry = y, numOfRSChilds = 0;\r\n while(0 < rx && ry < m - 1 && numOfRSChilds < k) {\r\n rx--;\r\n ry++;\r\n if(grid[rx][ry] == \".\") return false;\r\n if(grid[rx][ry] == \"*\") numOfRSChilds++;\r\n }\r\n //create left side children\r\n let lx = x, ly = y, numOfLSChilds = 0;\r\n while(0 < lx && 0 < ly && numOfLSChilds < k) {\r\n lx--;\r\n ly--;\r\n if(grid[lx][ly] == \".\") return false;\r\n if(grid[lx][ly] == \"*\") numOfLSChilds++;\r\n }\r\n return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == k);\r\n}\r\n\r\nfunction findAParent(grid, x, y, n, m, k) {\r\n //check the positive diagnol\r\n let rx = x, ry = y;\r\n while(rx < n - 1 && ry < m - 1) {\r\n rx++;\r\n ry++;\r\n if(grid[rx][ry] == \"*\" && parent(grid, rx, ry, n, m, Math.max(k, (rx - x)))) {\r\n return true;\r\n }\r\n }\r\n //check the negative diagnol\r\n let lx = x, ly = y;\r\n while(lx < n - 1 && 0 < ly) {\r\n lx++;\r\n ly--;\r\n if(grid[lx][ly] == \"*\" &&parent(grid, lx, ly, n, m, Math.max(k, (lx - x)))) return true;\r\n }\r\n return false;\r\n}\r\n\r\nfunction parent(grid, x, y, n, m, numOfChilds) {\r\n //create right side children\r\n let rx = x, ry = y, numOfRSChilds = 0;\r\n while(0 < rx && ry < m - 1 && numOfRSChilds < numOfChilds) {\r\n rx--;\r\n ry++;\r\n if(grid[rx][ry] == \".\") return false;\r\n if(grid[rx][ry] == \"*\") numOfRSChilds++;\r\n }\r\n //create left side children\r\n let lx = x, ly = y, numOfLSChilds = 0;\r\n while(0 < lx && 0 < ly && numOfLSChilds < numOfChilds) {\r\n lx--;\r\n ly--;\r\n if(grid[lx][ly] == \".\") return false;\r\n if(grid[lx][ly] == \"*\") numOfLSChilds++;\r\n }\r\n \r\n return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == numOfChilds);\r\n}"}], "src_uid": "99335597ae5a2fa5946019790d888f08"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const l = new Array(n),\r\n r = new Array(n);\r\n const f = [1, 1];\r\n for (let i = 2; i < n; i++) f[i] = f[i - 1] * i;\r\n const segTree = new SegTree(n);\r\n let stack = [];\r\n for (let i = 0; i < n; i++) {\r\n if (!stack.length || a[stack[stack.length - 1]] > a[i]) {\r\n stack.push(i);\r\n l[i] = i;\r\n } else {\r\n const left = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);\r\n l[i] = stack[left];\r\n }\r\n }\r\n stack = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (!stack.length || a[stack[stack.length - 1]] > a[i]) {\r\n stack.push(i);\r\n r[i] = i;\r\n } else {\r\n const right = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);\r\n r[i] = stack[right];\r\n }\r\n }\r\n const indexs = [];\r\n for (let i = 0; i < n; i++) {\r\n if (l[i] === i || r[i] === i) segTree.update(i, i, 1);else indexs.push(i);\r\n }\r\n indexs.sort((x, y) => a[x] - a[y]);\r\n let res = 1;\r\n for (let i of indexs) {\r\n const left = l[i] + 1,\r\n right = r[i] - 1;\r\n res = mul(res, right - left + 1 - segTree.query(left, right));\r\n segTree.update(i, i, 1);\r\n }\r\n return res;\r\n}\r\nfunction binarySearch(arr, l, r, comp) {\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (comp(m)) l = m + 1;else r = m;\r\n }\r\n return l;\r\n}\r\nconst MOD = 10 ** 9 + 7;\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n const mid = Math.floor((l + r) / 2);\r\n left.add += node.add;\r\n left.val += node.add * (mid - l + 1);\r\n right.add += node.add;\r\n right.val += node.add * (r - mid);\r\n node.add = 0;\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = left.val + right.val;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add += z;\r\n node.val += z * (r - l + 1);\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = this._query(node.left, l, mid, x, mid) + this._query(node.right, mid + 1, r, mid + 1, y);\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n let mod = 10 ** 9 + 7;\r\n\r\n for (let test = 0; test < N; test++) {\r\n let size = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n let pos = {};\r\n arr.forEach((num, i) => pos[num] = i);\r\n\r\n let result = 1;\r\n let left = pos[0] > pos[1] ? pos[1] : pos[0];\r\n let right = pos[0] > pos[1] ? pos[0] : pos[1];\r\n for (let i = 2; i < size; i++) {\r\n if (pos[i] > left && pos[i] < right) {\r\n result *= right - left + 1 - i;\r\n } else if (pos[i] < left) {\r\n left = pos[i];\r\n } else if (pos[i] > right) {\r\n right = pos[i];\r\n }\r\n result = result % mod;\r\n }\r\n\r\n output(result);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const l = new Array(n),\r\n r = new Array(n);\r\n const f = [1, 1];\r\n for (let i = 2; i < n; i++) f[i] = f[i - 1] * i;\r\n let stack = [];\r\n for (let i = 0; i < n; i++) {\r\n if (!stack.length || a[stack[stack.length - 1]] > a[i]) {\r\n stack.push(i);\r\n l[i] = i;\r\n } else {\r\n const left = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);\r\n l[i] = stack[left];\r\n }\r\n }\r\n stack = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (!stack.length || a[stack[stack.length - 1]] > a[i]) {\r\n stack.push(i);\r\n r[i] = i;\r\n } else {\r\n const right = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);\r\n r[i] = stack[right];\r\n }\r\n }\r\n const sum = [];\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = (_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0;\r\n if (l[i] === i || r[i] === i) sum[i]++;\r\n }\r\n let res = 1,\r\n pre = -1;\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n if (l[i] === i || r[i] === i) continue;\r\n const arr = [i];\r\n while (j + 1 < n && r[j + 1] !== j + 1 && l[j + 1] !== j + 1) {\r\n j++;\r\n arr.push(j);\r\n }\r\n arr.sort((x, y) => a[x] - a[y]);\r\n pre = i - 1;\r\n for (let k of arr) {\r\n res = mul(res, r[k] - pre - 1 - (sum[r[k] - 1] - sum[pre]));\r\n pre++;\r\n }\r\n }\r\n return res;\r\n}\r\nfunction binarySearch(arr, l, r, comp) {\r\n while (l < r) {\r\n const m = l + r >> 1;\r\n if (comp(m)) l = m + 1;else r = m;\r\n }\r\n return l;\r\n}\r\nconst MOD = 10 ** 9 + 7;\r\nfunction mul(...args) {\r\n if (args.length === 0) throw new Error('\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a');\r\n if (args.length === 1) return args[0];\r\n const [a, b] = args;\r\n if (args.length > 2) return mul(mul(a, b), ...args.slice(2));\r\n return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "a58ad54eaf4912f530a7d25a503640d3"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var c = one[2];\n var d = one[3];\n var two = nextIntArray();\n var x = two[0];\n var y = two[1];\n var x1 = two[2];\n var y1 = two[3];\n var x2 = two[4];\n var y2 = two[5];\n if((x1 == x2 && (a > 0 || b > 0)) || (y1 == y2 && (c > 0 || d > 0))){\n output[i] = \"NO\";\n }else{\n var diffX = x + (b - a);\n var diffY = y + (d - c);\n if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n }\n myout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while (t--) {\n const [a, b, c, d] = readInts()\n let [x, y, x1, y1, x2, y2] = readInts()\n if (a > 0 && b > 0 && x - 1 < x1 && x + 1 > x2) {\n wr('NO')\n continue\n }\n if (c > 0 && d > 0 && y - 1 < y1 && y + 1 > y2) {\n wr('NO')\n continue\n }\n let left = 0\n let right = 0\n let up = 0\n let down = 0\n if (a > b) left = a - b\n if (b > a) right = b - a\n if (c > d) down = c - d\n if (d > c) up = d - c\n if (left > 0) x -= left\n if (right > 0) x += right\n if (up > 0) y += up\n if (down > 0) y -= down\n if (x1 <= x && x <= x2 && y1 <= y && y <= y2) wr('YES')\n else wr('NO')\n }\n}\n"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var q = readline().trim().split(/\\s/).map(x=>Number(x));\n var h = p[1]-p[0];\n var v = p[3]-p[2];\n var res = ((h>0)?(q[0]>q[4]-h):((h<0)?(q[0]0)?(q[1]>q[5]-v):((v<0)?(q[1]Number(x));\n var q = readline().trim().split(/\\s/).map(x=>Number(x));\n var h = p[1]-p[0];\n var v = p[3]-p[2];\n var res = ((h>0)?(q[0]>q[4]-h):((h<0)?(q[0]0)?(q[1]>q[5]-v):((v<0)?(q[1]Number(x));\n var q = readline().trim().split(/\\s/).map(x=>Number(x));\n var h = p[1]-p[0];\n var v = p[3]-p[2];\n var res = ((h>0)?(q[0]+h>q[4]):((h<0)?(q[0]+h0)?(q[1]+v>q[5]):((v<0)?(q[1]+vNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var c = one[2];\n var d = one[3];\n var two = nextIntArray();\n var x = two[0];\n var y = two[1];\n var x1 = two[2];\n var y1 = two[3];\n var x2 = two[4];\n var y2 = two[5];\n if((x1 == x2 && (a > 0 || b > 0))|| (y1 == y2 && (c > 0 || d > 0))){\n output[i] = \"NO\";\n }else{\n var diffX = b - a;\n var diffY = d - c;\n if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var c = one[2];\n var d = one[3];\n var two = nextIntArray();\n var x = two[0];\n var y = two[1];\n var x1 = two[2];\n var y1 = two[3];\n var x2 = two[4];\n var y2 = two[5];\n if(x1 == x2 && y1 == y2){\n output[i] = \"NO\";\n }else{\n var diffX = b - a;\n var diffY = d - c;\n if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n }\n myout(myconv(output,9));\n}\n"}], "src_uid": "7224ffd4776af4129739e1b28f696050"} {"source_code": "print(function(n, p) {\n\tvar dp = []\n\tfor (var i = 0; i < n + 5; i++)\n\t\tdp.push(new Int32Array(n + 5));\n\n\tdp[1][1] = 2;\n\tfor (var i = 2; i <= n; i++)\n\t\tfor (var j = 1; j <= i; j++){\n\t\t\tdp[j][i] = dp[j][i - 1] + dp[p[i]][i - 1] + 2;\n\t\t\tdp[j][i] %= 1000000007;\n\t\t}\n\n\treturn dp[1][n];\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));", "positive_code": [{"source_code": "print(function(n, p) {\n\tvar i, j, ans = 0,\n\t\tmod = 1000000007,\n\t\tdp = new Int32Array(n + 2);\n\t\n\tn++;\n\n\tfor (i = 1; i <= n; i++)\n\t\tdp[i] = 2;\n\n\tfor (i = 1; i <= n; i++)\n\t\tfor (j = p[i]; j < i; j++)\n\t\t\tdp[i] = (dp[i] + dp[j]) % mod;\n\n\treturn dp[n] - 2;\n\n}(+readline(), ('0 ' + readline() + ' 1').split(' ').map(Number)));"}, {"source_code": "print(function(n, p) {\n\tvar i, j, ans = 0,\n\t\tmod = 1000000007,\n\t\tdp = new Int32Array(n + 1);\n\t\n\tfor (i = 1; i <= n; i++)\n\t\tdp[i] = 2;\n\n\tfor (i = 1; i <= n; i++)\n\t\tfor (j = p[i]; j < i; j++)\n\t\t\tdp[i] = (dp[i] + dp[j]) % mod;\n\n\tfor (i = 1; i <= n; i++)\n\t\tans = (ans + dp[i]) % mod;\n\t\n\treturn ans;\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));"}], "negative_code": [], "src_uid": "7bb5df614d1fc8323eba51d04ee7bf2a"} {"source_code": "let input ='';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data',(data)=>input+=data);\n\nprocess.stdin.on('end',()=>{\n let count=0;\n input = input.split('\\n');\n const arr = input[1].split(' ').map((item) => parseInt(item))\n arr.sort((a,b)=>b-a)\n \n for(let i = 0; i < arr.length-1;i++){\n count+=arr[i]-arr[i+1] - 1\n }\n console.log(count)\n}\n)", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i+1]) {\n cnt+=arr[i+1]-arr[i]\n cnt--\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var output = 0;\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn a - b;\n });\n for(var i = 0; i < N - 1; i++){\n output += list[i + 1] - list[i] - 1;\n }\n myout(output);\n}\n"}, {"source_code": "var n = Number( readline() );\nvar arr = readline().split(' ');\nvar min = +arr[0];\nvar max = +arr[0];\n\nfor (var i = 0; i < arr.length; i++) {\n\tmin = Math.min(min, arr[i]);\n\tmax = Math.max(max, arr[i]);\n}\n\nvar result = max - min + 1 - n;\nprint(result);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number).sort((a, b) => a - b);\n const min = arr[0];\n const max = arr[arr.length - 1];\n const ans = max - min - (arr.length - 1);\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "var n = +readline(),min = Number.MAX_VALUE, max = -1;\nreadline().split(' ').forEach(x=>{x = +x;min = Math.min(min,x);max = Math.max(max,x)});\nprint(Math.abs(max-min+1-n));"}, {"source_code": "var n = Number(readline());\n\nvar input = readline().split(' ');\nvar result = 0;\n\ninput.sort(function(a,b) {\n return a-b;\n});\n\nfor(var i=0; i value) minNumber = value;\n });\n\nwrite(maxNumber - minNumber + 1 - length + \"\\n\");\n"}, {"source_code": "var keyNumber = +readline();\nvar keyCurrent = readline().split(' ').sort(function(a, b){return a - b}); \nvar first = keyCurrent[0],\n end = keyCurrent[keyNumber - 1];\n\n//write(keyCurrent)\nwrite((end - first + 1) - keyNumber)"}, {"source_code": "var n = Number(readline());\nvar a = readline().split(' ').sort((a,b)=>{return a-b}).map(e=>parseInt(e));\n\nvar res = a[a.length-1] - a[0] + 1;\nres = res -n\nprint(res)"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort(function sortNumber(a, b) {\n return a - b;\n })\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i+1]) {\n cnt+=arr[i+1]-arr[i]\n cnt--\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}, {"source_code": "const stdin = process.stdin;\nstdin.setEncoding( 'utf8' );\nstdin.on( 'data', function( rawInput ){\n const inputLines = rawInput.split('\\n');\n const n = parseInt(inputLines[0]);\n const indices = splitAndConvert(inputLines[1], n);\n const result = solve(indices, n);\n console.log(result);\n});\n\nfunction splitAndConvert(stringOfNumbers, numOfValid) {\n\treturn stringOfNumbers.split(' ').slice(0, numOfValid).map(function(num) {\n\t\treturn parseInt(num);\n\t});\n}\n\nfunction solve(indices, n) {\n const max = Math.max.apply(null, indices);\n const min = Math.min.apply(null, indices);\n const expectedN = max - min + 1;\n return expectedN - n;\n}\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nfunction fact(num)\n{\n if(num === 0)\n return 1;\n return num * fact(num-1);\n}\n\nRL.on('close', () => {\n const n = parseInt(input[0], 10);\n const data = []; input[1].split(' ').forEach( i => data.push(parseInt(i, 10)) );\n data.sort((a, b) => a-b);\n let answer = 0;\n for(let i = 1; i < n; i += 1) {\n if(data[i-1]+1 !== data[i]) {\n answer += data[i] - data[i-1] - 1;\n }\n }\n console.log(answer);\n});\n\n"}, {"source_code": "readline()\nvar input = readline().split(' ').sort(function(a,b){return a-b;});\n\n var calc = 0;\n function myFunction(a, b) {return b - a;}\n\nfor(var x=0;x 0){calc+=r}\n \n}\nprint(calc);\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict'\nprocess.stdin.on('data', data => {\n data = data.toString().split('\\n')\n data.shift()\n let arr = data.shift().split(' ').map(a => parseInt(a))\n arr = arr.sort((a, b) => a - b)\n let ans = 0\n for (let i = 1; i < arr.length; i++) {\n ans += arr[i] - arr[i - 1] - 1\n }\n console.log(ans)\n})\n"}], "negative_code": [{"source_code": "var n = Number(readline());\nvar a = readline().split(' ').sort((a,b)=>{return a-b}).map(e=>parseInt(e));\nvar res = a[a.length-2] - n;\n\nprint(res)"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i]) {\n cnt++\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i+1]) {\n cnt++\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort()\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i+1]) {\n cnt++\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n arr.sort()\n let cnt = 0\n for (let i = 0; i < arr.length - 1; i++) {\n if ((arr[i] + 1) !== arr[i+1]) {\n cnt+=arr[i+1]-arr[i]\n }\n }\n console.log(cnt)\n return 0;\n }\n})\n"}], "src_uid": "6469ed9f2486b498c9ffeb8270391e3a"} {"source_code": "var c = 0, ans = 0;\nreadline().replace(/heavy|metal/g, function(a) {\n\tif (a === 'heavy') c++;\n\telse ans += c;\n\treturn '';\n});\nprint(ans);", "positive_code": [{"source_code": ";(function () {\n\n\tprint(function (s) {\n\n\t\tvar t = [];\n\n\t\t['heavy', 'metal'].forEach(function (e, i) {\n\t\t\tvar pos = -1;\n\t\t\twhile (true) {\n\t\t\t\tpos = s.indexOf(e, pos + 1);\n\t\t\t\tif (pos !== -1) t.push([i, pos]);\n\t\t\t\telse break;\n\t\t\t}\n\t\t});\n\n\t\tt = t.sort(function (a, b) { return a[1] - b[1]; }).map(function (e) { return e[0]; });\n\n\t\tvar l = 0;\n\t\tfor (var i = 0, _i = t.length; i < _i; i++) {\n\t\t\tif (t[i] === 0) l++;\n\t\t\telse t[i] = l;\n\t\t}\n\n\t\treturn t.reduce(function (p, e) { return p + e; }, 0) || 0;\n\n\t}(readline()));\n\n}.call(this));\n"}, {"source_code": "var c = 0, ans = 0;\nreadline().replace(/(heavy)|(metal)/g, function(_, a, b) {\n\tif (a) c++;\n\telse ans += c;\n});\nprint(ans);"}, {"source_code": "var c = 0, ans = 0;\nreadline().replace(/heavy|metal/g, function(a) {\n\tif (a === 'heavy') c++;\n\telse ans += c;\n});\nprint(ans);"}], "negative_code": [], "src_uid": "960e4c234666d2444b80d5966f1d285d"} {"source_code": "const THRESHOLD = Math.pow(2, 9);\n\nconst main = () => {\n readline();\n\n const A = readline()\n .split(\" \")\n .map((i) => Number(i));\n const B = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n var minResult = Infinity;\n\n for (var result = 0; result < THRESHOLD; result++) {\n var canReachResult = true;\n\n for (var i = 0; i < A.length; i++) {\n var canReachCurrentResult = false;\n\n for (var j = 0; j < B.length; j++) {\n if (((A[i] & B[j]) | result) === result) {\n canReachCurrentResult = true;\n break;\n }\n }\n\n if (!canReachCurrentResult) {\n canReachResult = false;\n break;\n }\n }\n\n if (canReachResult) {\n minResult = Math.min(minResult, result);\n }\n }\n\n return minResult;\n};\n\nprint(main());\n", "positive_code": [{"source_code": "var readline=require(\"readline\");\nvar rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nvar arr=[],a,b,n,m;\nrl.on('line',function(inp){\n arr.push(inp);\n var len=arr.length;\n if(len===1){\n n=parseInt(arr[0].split(' ')[0]);\n m=parseInt(arr[0].split(' ')[1]);\n }else if(len===2){\n a=arr[1].split(' ');\n for(var i=0;i0&&vis[i-1][k]) vis[i][k|ab]=1;\n }\n if(i===0) vis[i][ab]=1;\n }\n }\n for(var i=0;i<=C;i++){\n if(vis[n-1][i]){\n console.log(i);\n process.exit(0);\n }\n }\n }\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const [n, m] = readLine().split(/\\s/).map(Number)\n const as = readLine().split(/\\s/).map(Number)\n const bs = readLine().split(/\\s/).map(Number)\n const cCandidates = []\n let max = 0\n for (const a of as) {\n const cCandidate = bs.map(b => a & b)\n cCandidates.push(cCandidate)\n max = Math.max(max, Math.min.apply(null, cCandidate))\n }\n const cs = []\n for (const cCandidate of cCandidates) {\n cs.push(cCandidate.sort((a, b) => (a | max) - (b | max))[0])\n }\n console.log(cs.reduce((acc, curr) => acc | curr))\n}\n\n"}], "negative_code": [{"source_code": "const main = () => {\n readline();\n\n const A = readline()\n .split(\" \")\n .map((i) => Number(i));\n const B = readline()\n .split(\" \")\n .map((i) => Number(i));\n\n var result = 0;\n\n for (var i = 0; i < A.length; i++) {\n var currMin = A[i] & B[0];\n\n for (var j = 1; j < B.length; j++) {\n if ((result | (A[i] & B[j])) < (result | currMin)) {\n currMin = A[i] & B[j];\n }\n }\n\n result |= currMin;\n }\n\n return result;\n};\n\nprint(main());\n"}], "src_uid": "3da5075048a127319ffa8913859d2aa7"} {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n const compare = (a, b) => {\r\n if (typeof a === 'bigint') {\r\n if (typeof b === 'bigint') return Number(a - b)\r\n else return 1\r\n } else {\r\n if (typeof b === 'bigint') return -1\r\n else return a - b\r\n }\r\n }\r\n const MAX = 10 ** 15\r\n // console.time('dp')\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (compare(dp[ci], t) < 0) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (compare(cur, tmp[i]) > 0) {\r\n const l = Math.floor(C / i)\r\n let flag = true\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (compare(tmp[i * j], k) >= 0) continue\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (compare(dp[i], dp[i - 1]) < 0) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (compare(t, dp[dp.length - 1]) >= 0) res.push(-1)\r\n else if (compare(dp[0], t) > 0) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (compare(dp[mid], t) <= 0) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (compare(dp[i], t) > 0 && compare(dp[i - 1], t) <= 0) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n", "positive_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n\r\n const MAX = 10 ** 15\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let flag = cur <= MAX\r\n for (let j = i, k = cur; j <= C; j += i, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (tmp[j] < k) tmp[j] = k\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] <= dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n\r\n const MAX = 10 ** 15\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let flag = cur <= MAX\r\n for (let j = i, k = cur; j <= C; j += i, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (tmp[j] < k) tmp[j] = k\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] <= dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n\r\n const MAX = 10 ** 15\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let flag = cur <= MAX\r\n for (let j = i, k = cur; j <= C; j += i, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (tmp[j] < k) tmp[j] = k\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] <= dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n const compare = (a, b) => {\r\n return a > b ? 1 : a < b ? -1 : 0\r\n }\r\n const MAX = 10 ** 15\r\n // console.time('dp')\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n const l = Math.floor(C / i)\r\n let flag = true\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (tmp[i * j] >= k) continue\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] <= dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n const compare = (a, b) => {\r\n // if (typeof a === 'bigint') {\r\n // if (typeof b === 'bigint') return Number(a - b)\r\n // else return 1\r\n // } else {\r\n // if (typeof b === 'bigint') return -1\r\n // else return a - b\r\n // }\r\n return a > b ? 1 : a < b ? -1 : 0\r\n }\r\n const MAX = 10 ** 15\r\n // console.time('dp')\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (compare(dp[ci], t) < 0) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (compare(cur, tmp[i]) > 0) {\r\n const l = Math.floor(C / i)\r\n let flag = true\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (compare(tmp[i * j], k) >= 0) continue\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (compare(dp[i], dp[i - 1]) < 0) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (compare(t, dp[dp.length - 1]) >= 0) res.push(-1)\r\n else if (compare(dp[0], t) > 0) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (compare(dp[mid], t) <= 0) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (compare(dp[i], t) > 0 && compare(dp[i - 1], t) <= 0) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n const compare = (a, b) => {\r\n if (typeof a === 'bigint') {\r\n if (typeof b === 'bigint') return Number(a - b)\r\n else return 1\r\n } else {\r\n if (typeof b === 'bigint') return -1\r\n else return a - b\r\n }\r\n }\r\n const MAX = 10 ** 15\r\n // console.time('dp')\r\n let dp = new Array(C + 1).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n let t = di * hi\r\n if (t > MAX) t = BigInt(di) * BigInt(hi)\r\n\r\n if (compare(dp[ci], t) < 0) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (compare(cur, tmp[i]) > 0) {\r\n const l = Math.floor(C / i)\r\n let flag = true\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n if (flag && k > MAX) {\r\n flag = false\r\n k = BigInt(k)\r\n cur = BigInt(cur)\r\n }\r\n\r\n if (compare(tmp[i * j], k) >= 0) break\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (compare(dp[i], dp[i - 1]) < 0) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) t = BigInt(dj) * BigInt(hj)\r\n\r\n if (compare(t, dp[dp.length - 1]) >= 0) res.push(-1)\r\n else if (compare(dp[0], t) > 0) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (compare(dp[mid], t) <= 0) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (compare(dp[i], t) > 0 && compare(dp[i - 1], t) <= 0) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n // console.time('dp')\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n const l = Math.floor(C / i)\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n if (tmp[i * j].toString() >= k.toString()) break\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n // console.timeEnd('dp')\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n\r\n for (let k = cur * BigInt(l + 1); l < r; l++, k += cur) {\r\n if (tmp[i * (l + 1)] >= k) break\r\n }\r\n\r\n for (let j = 1, k = cur; j <= l; j++, k += cur) {\r\n // if (tmp[i * j] >= k) break\r\n tmp[i * j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] !== undefined && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l <= r; l++, k += cur) {\r\n if (tmp[i * l] === undefined || tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ * i <= C && _ < l; _++, j += i, k += cur) {\r\n // if (tmp[j] >= k) break\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] !== undefined && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l < r; l++, k += cur) {\r\n if (tmp[i * l] === undefined || tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ * i <= C && _ < l; _++, j += i, k += cur) {\r\n // if (tmp[j] >= k) break\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] !== undefined && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l < r; l++, k += cur) {\r\n if (tmp[i * l] === undefined || tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ < l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l < r; l++, k += cur) {\r\n if (tmp[i * l] === undefined || tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ < l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l < r; l++, k += cur) {\r\n if (!tmp[i * l] || tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ < l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.ceil(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] && tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (let k = cur * BigInt(l); l < r; l++, k += cur) {\r\n if (tmp[i * l] >= k) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ < l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (; l < r; l++) {\r\n if (tmp[i * (l + 1)] >= cur * BigInt(l + 1)) break\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n if (tmp[r * i] < cur * BigInt(r)) {\r\n l = r\r\n } else {\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (; l <= r; l++) {\r\n if (tmp[i * (l + 1)] >= cur * BigInt(l + 1)) break\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n if (tmp[r * i] < cur * BigInt(r)) {\r\n l = r\r\n } else {\r\n while (l < r - 10) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n for (; l < r; l++) {\r\n if (tmp[i * (l + 1)] >= cur * BigInt(l + 1)) break\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n if (tmp[r * i] < cur * BigInt(r)) {\r\n l = r\r\n } else {\r\n while (l < r) {\r\n const mid = (l + r + 1) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid\r\n } else {\r\n r = mid - 1\r\n }\r\n }\r\n // for (; l < r; l++) {\r\n // if (tmp[i * (l + 1)] >= k) break\r\n // }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n if (tmp[r * i] < cur * BigInt(r)) {\r\n l = r\r\n } else {\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n if (tmp[r * i] < cur) {\r\n l = r\r\n } else {\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] < cur * BigInt(mid)) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n let cur = dp[i]\r\n if (cur > tmp[i]) {\r\n let l = 1,\r\n r = Math.floor(C / i)\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (tmp[i * mid] < cur) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let _ = 1, j = i, k = cur; _ <= l; _++, j += i, k += cur) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > tmp[i]) {\r\n let a = dp[i]\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += a) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0)\r\n // console.time('dp')\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0 && dp[i] > tmp[i]) {\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += dp[i]) {\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp')\r\n // console.time('query')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n // console.timeEnd('query')\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += dp[i]) {\r\n if (k <= tmp[j]) break\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n console.log(dp)\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\n// console.time('input')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n// console.timeEnd('input')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n let dp = new Array(C + 1).fill(0n)\r\n // console.time('dp')\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) dp[ci] = t\r\n }\r\n // console.timeEnd('dp')\r\n\r\n // console.time('dp1')\r\n let tmp = new Array(C + 1).fill(0n)\r\n // let count = 0\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += dp[i]) {\r\n // count++\r\n if (k <= tmp[j]) break\r\n tmp[j] = k\r\n }\r\n }\r\n }\r\n dp = tmp\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n // console.timeEnd('dp1')\r\n\r\n // // console.log('count', count)\r\n // console.time('query')\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r - 10) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n\r\n for (let i = l; i <= r; i++) {\r\n if (dp[i] > t && dp[i - 1] <= t) {\r\n res.push(i)\r\n break\r\n }\r\n }\r\n }\r\n }\r\n\r\n // console.timeEnd('query')\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0)\r\n const MAX = 10 ** 15\r\n\r\n const compare = (a, b) => {\r\n if (typeof a === 'bigint') {\r\n if (typeof b === 'number') return 1\r\n else return a - b\r\n } else {\r\n if (typeof b === 'bigint') return -1\r\n else return a - b\r\n }\r\n }\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n\r\n let t = di * hi\r\n if (t >= MAX) {\r\n t = BigInt(di) * BigInt(hi)\r\n }\r\n\r\n if (compare(t, dp[ci]) > 0)\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n\r\n let tmp = new Array(C + 1).fill(0)\r\n\r\n for (let i = 0; i <= C; i++) {\r\n if (compare(dp[i], 0) > 0) {\r\n let a = i,\r\n b = dp[i],\r\n flag = typeof b === 'number'\r\n for (let j = a, k = b; j <= C; j += a, k += b) {\r\n if (flag && k >= MAX) {\r\n flag = false\r\n b = BigInt(b)\r\n k = BigInt(k)\r\n }\r\n if (compare(k, tmp[j]) > 0) {\r\n tmp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n for (let i = 1; i <= C; i++) {\r\n if (compare(dp[i], dp[i - 1]) < 0) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n let t = dj * hj\r\n if (t > MAX) {\r\n t = BigInt(dj) * BigInt(hj)\r\n }\r\n if (compare(t, dp[dp.length - 1]) >= 0) res.push(-1)\r\n else if (compare(dp[0], t) > 0) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (compare(dp[mid], t) <= 0) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n\r\n const t = di * hi\r\n\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n let tmp = new Array(C + 1).fill(0n)\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += dp[i]) {\r\n if (k > tmp[j]) {\r\n tmp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n dp = tmp\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n\r\n const t = di * hi\r\n // units.push([ci, t])\r\n // for (let j = ci; j <= C; j += ci) {\r\n // const tmp = t * (j / ci)\r\n // if (dp[j] <= tmp) {\r\n // dp[j] = tmp\r\n // } else break\r\n // }\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i * 2, k = dp[i] * 2n; j <= C; j += i, k += dp[i]) {\r\n if (k >= dp[j]) {\r\n dp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n console.log(dp)\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n\r\n const t = di * hi\r\n // units.push([ci, t])\r\n // for (let j = ci; j <= C; j += ci) {\r\n // const tmp = t * (j / ci)\r\n // if (dp[j] <= tmp) {\r\n // dp[j] = tmp\r\n // } else break\r\n // }\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i * 2, k = dp[i] * 2n; j <= C; j += i, k += dp[i]) {\r\n if (k > dp[j]) {\r\n dp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n\r\n const t = di * hi\r\n // units.push([ci, t])\r\n // for (let j = ci; j <= C; j += ci) {\r\n // const tmp = t * (j / ci)\r\n // if (dp[j] <= tmp) {\r\n // dp[j] = tmp\r\n // } else break\r\n // }\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i * 2, k = dp[i] * 2n; j <= C; j += i, k += dp[i]) {\r\n if (k > dp[j]) {\r\n dp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n console.log(dp)\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n let dp = new Array(C + 1).fill(0n)\r\n\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n\r\n const t = di * hi\r\n // units.push([ci, t])\r\n // for (let j = ci; j <= C; j += ci) {\r\n // const tmp = t * (j / ci)\r\n // if (dp[j] <= tmp) {\r\n // dp[j] = tmp\r\n // } else break\r\n // }\r\n if (dp[ci] < t) {\r\n dp[ci] = t\r\n }\r\n }\r\n for (let i = 0; i <= C; i++) {\r\n if (dp[i] > 0n) {\r\n for (let j = i, k = dp[i]; j <= C; j += i, k += dp[i]) {\r\n if (k < dp[j]) {\r\n dp[j] = k\r\n } else break\r\n }\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let l = 0,\r\n r = C + 1\r\n while (l < r) {\r\n const mid = (l + r) >> 1\r\n if (dp[mid] <= t) {\r\n l = mid + 1\r\n } else {\r\n r = mid\r\n }\r\n }\r\n res.push(l)\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n const dp = new Array(C + 1).fill(0)\r\n let flag = true\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n if (i === 1n && ci === 1 && di === 42 && hi === 18468) flag = false\r\n const t = di * hi\r\n units.push([ci, t])\r\n // for (let j = ci; j <= C; j += ci) {\r\n // const tmp = t * (j / ci)\r\n // if (dp[j] <= tmp) {\r\n // dp[j] = tmp\r\n // } else break\r\n // }\r\n }\r\n if (flag) {\r\n units.sort((a, b) => a[1] - b[1])\r\n }\r\n\r\n for (let [c1, t1] of units) {\r\n ;(ci = BigInt(c1)), (t = BigInt(t1))\r\n for (let j = ci, k = 1n; j <= C; j += ci, k++) {\r\n const tmp = Number(t * k)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = Number(dj * hj)\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n // if (dp[i] <= t && dp[i + 1] > t) {\r\n // res.push(i + 1)\r\n // break\r\n // }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n const dp = new Array(C + 1).fill(0n)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n units.push([ci, t])\r\n }\r\n // units.sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))\r\n for (let [c, t] of units) {\r\n for (let j = c; j <= C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n\r\n if (t >= dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n // if (dp[i] <= t && dp[i + 1] > t) {\r\n // res.push(i + 1)\r\n // break\r\n // }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1n\r\n const units = []\r\n const dp = new Array(C + 1).fill(0n)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(BigInt)\r\n const t = di * hi\r\n units.push([ci, t])\r\n }\r\n // units.sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))\r\n for (let [c, t] of units) {\r\n for (let j = c; j <= C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n\r\n for (let i = 1; i <= C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(BigInt)\r\n const t = dj * hj\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n // if (dp[i] <= t && dp[i + 1] > t) {\r\n // res.push(i + 1)\r\n // break\r\n // }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n})\r\nlet i = 0,\r\n n,\r\n C,\r\n m\r\nconst units = [],\r\n res = []\r\nlet dp = []\r\nrl.on('line', line => {\r\n const input = line.split(' ').map(BigInt)\r\n if (i === 0) {\r\n ;[n, C] = input.map(Number)\r\n dp = new Array(C).fill(0n)\r\n } else if (i <= n) {\r\n const [ci, di, hi] = input\r\n const t = di * hi\r\n units.push([ci, t])\r\n } else if (i === n + 1) {\r\n // units.sort((a, b) => Number(a[1] - b[1]))\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n for (let i = 1; i < C; i++) {\r\n if (dp[i] < dp[i - 1]) dp[i] = dp[i - 1]\r\n }\r\n } else {\r\n const [dj, hj] = input\r\n const t = dj * hj\r\n\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = 0,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n i++\r\n})\r\n\r\nrl.on('close', () => console.log(res.join(' ')))\r\n"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n})\r\nlet i = 0,\r\n n,\r\n C,\r\n m\r\nconst units = [],\r\n res = []\r\nlet dp = []\r\nrl.on('line', line => {\r\n const input = line.split(' ').map(Number)\r\n if (i === 0) {\r\n ;[n, C] = input\r\n dp = new Array(C).fill(0)\r\n } else if (i <= n) {\r\n const [ci, di, hi] = input\r\n const t = di * hi\r\n units.push([ci, t])\r\n } else if (i === n + 1) {\r\n units.sort((a, b) => a[1] - b[1])\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n for (let i = 1; i < C; i++) {\r\n dp[i] = Math.max(dp[i], dp[i - 1])\r\n }\r\n } else {\r\n const [dj, hj] = input\r\n const t = Number(BigInt(dj) * BigInt(hj))\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = 0,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n i++\r\n})\r\n\r\nrl.on('close', () => console.log(res.join(' ')))\r\n"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n})\r\nlet i = 0,\r\n n,\r\n C,\r\n m\r\nconst units = [],\r\n res = []\r\nlet dp = []\r\nrl.on('line', line => {\r\n const input = line.split(' ').map(Number)\r\n if (i === 0) {\r\n ;[n, C] = input\r\n dp = new Array(C).fill(0)\r\n } else if (i <= n) {\r\n const [ci, di, hi] = input\r\n const t = di * hi\r\n units.push([ci, t])\r\n } else if (i === n + 1) {\r\n units.sort((a, b) => a[1] - b[1])\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n for (let i = 1; i < C; i++) {\r\n dp[i] = Math.max(dp[i], dp[i - 1])\r\n }\r\n } else {\r\n const [dj, hj] = input\r\n const t = dj * hj\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = 0,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n if (b === 0) {\r\n res.push(i)\r\n break\r\n }\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n i++\r\n})\r\n\r\nrl.on('close', () => console.log(res.join(' ')))\r\n"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n})\r\nlet i = 0,\r\n n,\r\n C,\r\n m\r\nconst units = [],\r\n res = []\r\nlet dp = []\r\nrl.on('line', line => {\r\n const input = line.split(' ').map(Number)\r\n if (i === 0) {\r\n ;[n, C] = input\r\n dp = new Array(C).fill(0)\r\n } else if (i <= n) {\r\n const [ci, di, hi] = input\r\n const t = di * hi\r\n units.push([ci, t])\r\n } else if (i === n + 1) {\r\n // units.sort((a, b) => a[1] - b[1])\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n for (let i = 1; i < C; i++) {\r\n dp[i] = Math.max(dp[i], dp[i - 1])\r\n }\r\n } else {\r\n const [dj, hj] = input\r\n const t = dj * hj\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n if (dp[i] <= t && dp[i + 1] > t) {\r\n res.push(i + 1)\r\n break\r\n }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n i++\r\n})\r\n\r\nrl.on('close', () => console.log(res.join(' ')))\r\n"}, {"source_code": "const readline = require('readline')\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n})\r\nlet i = 0,\r\n n,\r\n C,\r\n m\r\nconst units = [],\r\n res = []\r\nlet dp = []\r\nrl.on('line', line => {\r\n const input = line.split(' ').map(Number)\r\n if (i === 0) {\r\n ;[n, C] = input\r\n dp = new Array(C).fill(0)\r\n } else if (i <= n) {\r\n const [ci, di, hi] = input\r\n const t = di * hi\r\n units.push([ci, t])\r\n } else if (i === n + 1) {\r\n units.sort((a, b) => a[1] - b[1])\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n for (let i = 1; i < C; i++) {\r\n dp[i] = Math.max(dp[i], dp[i - 1])\r\n }\r\n } else {\r\n const [dj, hj] = input\r\n const t = dj * hj\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n if (dp[i] <= t && dp[i + 1] > t) {\r\n res.push(i + 1)\r\n break\r\n }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n i++\r\n})\r\n\r\nrl.on('close', () => console.log(res.join(' ')))\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const [n, C] = inputs[0].split(' ').map(Number)\r\n let i = 1\r\n const units = []\r\n const dp = new Array(C).fill(0)\r\n for (; i <= n; i++) {\r\n const [ci, di, hi] = inputs[i].split(' ').map(Number)\r\n const t = di * hi\r\n units.push([ci, t])\r\n }\r\n units.sort((a, b) => a[1] - b[1])\r\n for (let [c, t] of units) {\r\n for (let j = c; j < C; j += c) {\r\n const tmp = t * (j / c)\r\n if (dp[j] < tmp) {\r\n dp[j] = tmp\r\n } else break\r\n }\r\n }\r\n\r\n for (let i = 1; i < C; i++) {\r\n dp[i] = Math.max(dp[i], dp[i - 1])\r\n }\r\n\r\n let m = Number(inputs[i++])\r\n const res = []\r\n while (m--) {\r\n const [dj, hj] = inputs[i++].split(' ').map(Number)\r\n const t = dj * hj\r\n if (t > dp[dp.length - 1]) res.push(-1)\r\n else if (dp[0] > t) res.push(1)\r\n else {\r\n let a = -1,\r\n b = 0\r\n while (true) {\r\n const i = a + (1 << b)\r\n if (dp[i] <= t && dp[i + 1] > t) {\r\n res.push(i + 1)\r\n break\r\n }\r\n if (dp[i] <= t) {\r\n b++\r\n } else {\r\n a = a + (1 << (b - 1))\r\n b = 0\r\n }\r\n }\r\n }\r\n }\r\n\r\n console.log(res.join(' '))\r\n})()\r\n"}], "src_uid": "476c05915a1536cd989c4681c61c9deb"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n) {\r\n let r = n.toString().length\r\n let copy = n\r\n let temp = 0\r\n for (let i = 0; i < r - 1; i++) copy = Math.floor(copy / 10)\r\n if (n > 9) {\r\n for (let i = 0; i < r; i++) {\r\n temp += copy * (10 ** i)\r\n }\r\n if (n < temp) --copy\r\n }\r\n console.log((r - 1) * 9 + copy)\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))\r\n}\r\n\r\n", "positive_code": [{"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var s = readline();\n var len = s.length;\n var n = parseInt(s);\n\n var p = 0;\n var count = 0;\n for (var i = 0; i < len; i++) {\n p = p * 10 + 1;\n for (var j = 1; j <= 9; j++)\n if (p * j >= 1 && p * j <= n)\n count++;\n }\n print(count);\n}"}, {"source_code": "var testcases = readline();\r\nvar count;\r\n \r\nfor(var k = 0 ; k < testcases ; k++) {\r\n var number = readline();\r\n count = 0;\r\n for (var i = 1; i <= number; i = i * 10 + 1) {\r\n for (var j = 1; j <= 9; j++) {\r\n if(i * j <= number) count++;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "// 1520 B - Ordinary Numbers\r\n\r\n// number of test case\r\nvar numTests = parseInt( readline() );\r\n\r\nfor (var numTest = 0; numTest < numTests; numTest++) {\r\n \r\n // input data \r\n var num = parseInt( readline() );\r\n \r\n // calculate number\r\n var n1 = 9 * ( num.toString().length - 1 );\r\n var n2 = num;\r\n var n3 = '1'.repeat( num.toString().length );\r\n\r\n var output = n1 + ( parseInt ( n2 / n3 ) ); \r\n print( output );\r\n\r\n}"}, {"source_code": "t = parseInt(readline()) ; \r\nwhile (t--) {\r\n\tn= readline(); \r\n\tans = 9 * ((n.length - 1 )) ; \r\n\tx = parseInt(n); \r\n\tds = \"1\" ; \r\n\tfor (i = 1 ; i < n.length ; i ++ ) {\r\n\t ds +='1' ; \r\n\t}\r\n\tnew_x = parseInt(ds) ; \r\n\tfor (i = 1 ; i <= 9 ; i++ ) {\r\n\t if ((new_x * i )> x) break ; \r\n\t ans ++ ; \r\n\t}\r\n\tprint (ans);\r\n\t \r\n}"}, {"source_code": "var arr = [];\r\nvar tc = readline();\r\nvar sz;\r\nfunction func(k, t) {\r\n\tvar str = \"\";\r\n\twhile (t--) str += k;\r\n\treturn Number(str);\r\n}\r\nfor (var i = 1; i <= 9; i++) {\r\n\tfor (var j = 1; j <= 10; j++) {\r\n\t\tvar str = func(i, j);\r\n\t\tarr.push(str);\r\n\t}\r\n}\r\narr.sort(function (u, v) {\r\n\treturn u - v;\r\n});\r\nsz=arr.length;\r\nwhile (tc--) {\r\n\tvar n = readline();\r\n\tvar ans = 0;\r\n\tfor (var i = 0; i < sz; i++) {\r\n\t\tif (arr[i] <= n) ans++;\r\n\t\telse break;\r\n\t}\r\n\tprint(ans);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n var n = +readline();\r\n var d = Math.floor(Math.log10(n)) + 1;\r\n var o = (d - 1) * 9; // ordinary numbers with less number of digits than n\r\n var firstOrdinary = (Math.pow(10, d) - 1) / 9;\r\n \r\n for(var i = 1; i < 10; i++) {\r\n if(n < firstOrdinary * i) {\r\n break;\r\n }\r\n o++;\r\n }\r\n print(o);\r\n}\r\n"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var limit = Number(readline());\r\n var limitStr = limit.toString(); \r\n if (limit < 10) {\r\n return print(limit);\r\n }\r\n\r\n var numberOfFullDigits = limitStr.length - 1;\r\n\r\n var firstDigit = Number(limitStr[0]);\r\n var maxLesserBoringNumber = 0;\r\n for (var i = 0; i < limitStr.length; ++i) {\r\n maxLesserBoringNumber += firstDigit * Math.pow(10, i);\r\n }\r\n\r\n print(numberOfFullDigits * 9 + firstDigit - (limit >= maxLesserBoringNumber ? 0 : 1));\r\n}"}, {"source_code": "const t=parseInt(readline());\r\n\r\nfor(var j=0;j {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n rl.close();\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n input.forEach(item => ordinaryNumbers(item));\r\n}\r\n\r\nfunction ordinaryNumbers(item) {\r\n if (item.length === 1) {\r\n console.log(item);\r\n\r\n } else {\r\n let digits = item.length,\r\n ordinaryNumbers = 9 * (digits - 1),\r\n firstChar = item.charAt(0),\r\n ordinaryNumberWithFirstChar = firstChar.repeat(digits);\r\n \r\n ordinaryNumbers += Math.floor(+item / Math.pow(10, digits - 1)) - 1;\r\n\r\n if (item >= ordinaryNumberWithFirstChar) {\r\n console.log(++ordinaryNumbers);\r\n } else {\r\n console.log(ordinaryNumbers);\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n rl.close();\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n input.forEach(item => ordinaryNumbers(item));\r\n}\r\n\r\nfunction ordinaryNumbers(item) {\r\n if (item.length === 1) {\r\n console.log(item);\r\n\r\n } else {\r\n let digits = item.length,\r\n ordinaryNumbers = 9 * (digits - 1),\r\n firstChar = item.charAt(0);\r\n \r\n ordinaryNumbers += Math.floor(+item / Math.pow(10, digits - 1));\r\n\r\n ordinaryNumberWithFirstChar = firstChar.repeat(digits);\r\n\r\n if (item >= ordinaryNumberWithFirstChar) {\r\n console.log(ordinaryNumbers);\r\n } else {\r\n console.log(--ordinaryNumbers);\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n rl.close();\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n input.forEach(item => ordinaryNumbers(item));\r\n}\r\n\r\nfunction ordinaryNumbers(item) {\r\n if (item.length === 1) {\r\n console.log(item);\r\n\r\n } else {\r\n let digits = item.length,\r\n ordinaryNumbers = 9 * (digits - 1),\r\n firstChar = item.charAt(0);\r\n \r\n ordinaryNumbers += Math.floor(+item / Math.pow(10, digits - 1));\r\n\r\n ordinaryNumberWithFirstChar = firstChar.repeat(digits);\r\n\r\n if (item >= ordinaryNumberWithFirstChar) {\r\n console.log(ordinaryNumbers);\r\n } else {\r\n console.log(--ordinaryNumbers);\r\n }\r\n }\r\n}\r\n\r\nconst _mergeArrays = (a, b) => {\r\n const c = []\r\n \r\n while (a.length && b.length) {\r\n c.push(a[0] > b[0] ? b.shift() : a.shift())\r\n }\r\n \r\n //if we still have values, let's add them at the end of `c`\r\n while (a.length) {\r\n c.push(a.shift())\r\n }\r\n while (b.length) {\r\n c.push(b.shift())\r\n }\r\n \r\n return c\r\n }\r\n \r\n const mergeSort = (a) => {\r\n if (a.length < 2) return a\r\n const middle = Math.floor(a.length / 2)\r\n const a_l = a.slice(0, middle)\r\n const a_r = a.slice(middle, a.length)\r\n const sorted_l = mergeSort(a_l)\r\n const sorted_r = mergeSort(a_r)\r\n return _mergeArrays(sorted_l, sorted_r)\r\n }"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n var b = 1\n var c = 0\n var d = 0\n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d / b \n b = b * 10 + 1 \n }\n c+= a / b \n console.log(Math.floor(c))\n }\n });\n //answer <= a[2], log(answer)\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n var b = 1; \n var c = 0\n var d = 0\n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d / b \n b = b * 10 + 1 \n }\n c += a / b\n console.log(Math.floor(c))\n }\n });\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j =1 ; j<= lines[0]; j++){\n var a = lines[j]\n var b = 1 \n var c = 0 \n var d = 0 \n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d /b \n b = b * 10 + 1\n }\n c += a/b \n console.log(Math.floor(c))\n }\n \n});\n\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n var b = 1 \n var c = 0\n var d = 0\n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d /b \n b = b * 10 + 1\n }\n c += a/ b \n console.log(Math.floor(c))\n }\n \n \n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nconst answers = [];\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const n = Number(d);\n const len = d.length;\n let ans = Math.max(0, (len - 1) * 9);\n let inc = Number(String(1).repeat(len));\n\n for (let i = inc; i <= n; i += inc) {\n ans++;\n }\n\n answers.push(ans);\n\n // let answers = [];\n // let ans = 0;\n\n // for (let i = 1; i <= Number(d); i++) {\n // if (new Set(String(i)).size === 1) {\n // answers.push(i);\n // ans++;\n // }\n // }\n\n // console.log({ answers });\n // console.log({ ans });\n c++;\n});\n\nrl.on(\"close\", () => {\n console.log(answers.join(\"\\n\"));\n});\n"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n const n = parseInt(readLine());\r\n //const s = readLine();\r\n b(n);\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction a(n,s)\r\n{\r\n let last = '';\r\n let solved = '';\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(s[i] !== last && solved.includes(s[i]))\r\n {\r\n return console.log('NO');\r\n }\r\n solved += s[i];\r\n last = s[i];\r\n }\r\n return print('YES');\r\n}\r\n\r\nfunction b(n)\r\n{\r\n // usiming every decimal add 9 \r\n let d = n.toString()[0];\r\n let k = n.toString().length;\r\n let max = 0;\r\n for(let pw = 1; pw <= n; pw = pw * 10 + 1)\r\n {\r\n for(let d = 1; d <= 9; d++)\r\n {\r\n if(pw * d <= n)\r\n {\r\n max++\r\n }\r\n }\r\n }\r\n \r\n return print(max)\r\n \r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n const args = input.split('\\n');\r\n var v = [];\r\n var n = 1;\r\n for (var j = 1; j <= 9; j++) {\r\n for (var i = 1; i <= 9; i++) {\r\n v.push(i * n);\r\n }\r\n n *= 10;\r\n n += 1;\r\n }\r\n v.push(10 ** 9 + 1);\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n const c = parseInt(args[i], 10);\r\n var j = 0;\r\n while (v[j] <= c) {\r\n j++;\r\n }\r\n console.log(j);\r\n }\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet initialized=false;\r\n\r\nfunction amountOfSameNums(inp){\r\n if(inp < 10) return inp\r\n\r\n let digits = String(inp).length,\r\n counter = (digits-1) * 9,\r\n divisor = '1'.repeat(digits);\r\n\r\n return counter + Math.floor(inp / divisor)\r\n \r\n //+ (Number( String(inp)[digits-1] ) || '');\r\n \r\n\r\n \r\n // for(var i=1, counter=0; i<=inp; i++){\r\n \r\n // // count amount of digits 10-100 11 22 33 44 55 66 77 88 99\r\n // 100-1000 (3-4 symbols difference) 4-5 difference same 9 numbers to check\r\n // 11 22 33 44 55 66 77 88 99\r\n // 111 222 333 444 555 666 777 888 999\r\n // if([...String(i)]\r\n // ++counter\r\n // }\r\n}\r\n\r\nrl.on('line', (input) => {\r\n if(initialized){ console.log( amountOfSameNums(input) ) }\r\n else initialized = true\r\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rl();\r\n\r\n\t\tconst D = n.length;\r\n\r\n\t\tlet flg = 0;\r\n\t\tfor (const d of n) {\r\n\t\t\tif (d == n[0]) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (d > n[0]) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (d < n[0]) {\r\n\t\t\t\tflg = 1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = 9 * (D - 1) + Number(n[0]) - flg;\r\n\r\n\t\tconsole.log(ans)\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var a = lines[j];\n var b = 1;\n var r = 0;\n var t = 0;\n for(l = 10; l <= Number(a); l*=10){\n t = l-1;\n r += t/b;\n b = b*10+1;\n }\n r += Number(a)/b;\n console.log(Math.floor(r));\n }\n \n});"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet initialized = false;\r\n\r\nfunction amountOfSameNums(inp) {\r\n if (inp < 10) return inp;\r\n\r\n const digits = String(inp).length;\r\n const counter = (digits - 1) * 9;\r\n const divisor = '1'.repeat(digits);\r\n\r\n return counter + Math.floor(inp / divisor);\r\n}\r\n\r\nrl.on('line', (input) => {\r\n if (initialized) { console.log(amountOfSameNums(input)); } else initialized = true;\r\n});"}, {"source_code": "\r\nconst isNum = (num) => {\r\n\tif (num < 10)\r\n\t\treturn true;\r\n\r\n\tconst str = `${num}`.split('');\r\n\r\n\tconst set = new Set();\r\n\tfor (let i=0; i {\r\n\tconst n = +line;\r\n\r\n\tlet counter = 0;\r\n\tfor (let i=1; i<10; i++) {\r\n\t\tlet num = `${i}`;\r\n\t\twhile (+num <= n) {\r\n\t\t\tcounter++;\r\n\t\t\tnum += `${i}`;\r\n\t\t}\r\n\t}\r\n\r\n\treturn counter;\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [n, ...lines] = input.trim().split('\\n')\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=0; ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\nfunction buildNumber(n,digit){\r\n if(n==1){\r\n return parseInt(digit);\r\n }\r\n let ans = 0;\r\n while(n--){\r\n ans = ans*10+ digit;\r\n }\r\n\r\n return ans;\r\n}\r\n\r\nfunction solve() {\r\n\r\n let t = readSingleInt();\r\n let firstDigit ,ans ,targetNumber ,inputNumber,included;\r\n while(t--)\r\n {\r\n ans = 0;\r\n included = -1;\r\n let n =readLine();\r\n firstDigit = parseInt(n[0]);\r\n targetNumber = buildNumber(n.length,firstDigit);\r\n inputNumber = parseInt(n);\r\n if(inputNumber>=targetNumber){\r\n included = 0;\r\n }\r\n ans = (n.length-1) * 9 + (firstDigit) + included;\r\n console.log(ans);\r\n\r\n }\r\n\r\n}"}, {"source_code": "/**\r\n * Bismillahir Rahmanir Rahim\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n */\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n \r\n let inputString = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\t//let s = readLine().split(\" \").map(item=>parseInt(item));\r\n\t\tsolve(n);\r\n\t\t\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n) {\r\n\tlet sol = 0 ;\r\n\tfor (let i = 1; i <= 9; i++) {\r\n\t\tlet j = i;\r\n\t\twhile (j <= n) {\r\n\t\t\tsol++;\r\n\t\t\tj = j*10 + i;\r\n\t\t}\r\n\t}\r\n\tconsole.log(sol);\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++){\n ans.push(nl.num());\n }\n let numz = (n) => {\n let t = n;\n let cnt = 0;\n while(t >= 10){\n t /= 10;\n cnt++;\n }\n \n \n t = Math.trunc(t);\n let c = t;\n for(let i = 0; i < cnt; i++) {\n c *= 10;\n c += t;\n }\n return cnt * 9 + ((c > n)?t - 1:t);\n }\n \n\tconsole.log(ans.map(numz).join(\"\\n\"));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var a = 1; a < input.length; a++) {\r\n var n = Number(input[a]);\r\n var sum = 0;\r\n var count = 0;\r\n for (var i = 0; i <= 8; i++) {\r\n sum += 10 ** i;\r\n for (var j = 1; j <= 9; j++) {\r\n if (j * sum <= n) {\r\n count++;\r\n }\r\n }\r\n }\r\n console.log(count);\r\n }\r\n})"}, {"source_code": "////////////////////// Nodejs Problem Solving /////////////////\r\n/////////////////////* @author Nawab Khairuzzaman Mohammad Kibria *////////\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n///////////////////////// END BASIC IO STREAM TEMPLATE //////////////////////\r\n\r\nfunction main() {\r\n let t = readLine(Number);\r\n while (t--) {\r\n let n = readLine(Number);\r\n\r\n if (n < 10) {\r\n console.log(n);\r\n } else {\r\n let y;\r\n let x = n.toString().split(\"\").map(Number);\r\n y = x[0];\r\n\r\n for (let i = 1; i < x.length; i++) {\r\n if (x[0] > x[i]) {\r\n y -= 1;\r\n break;\r\n }\r\n\r\n if (x[0] < x[i]) {\r\n break;\r\n }\r\n }\r\n\r\n console.log(x.length * 9 - (9 - y));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "function findNumberOfDigts(N) {\r\n let count = 0;\r\n while (N) {\r\n count += 1;\r\n N = Math.floor(N / 10);\r\n }\r\n return count;\r\n}\r\n\r\nfunction solve(N) {\r\n const digits = findNumberOfDigts(N);\r\n let ans = (digits - 1) * 9;\r\n let b = 0;\r\n for (let i = 0; i < digits; i++) {\r\n b += Math.pow(10, i);\r\n }\r\n ans += Math.floor(N / b);\r\n return ans;\r\n}\r\n\r\nfunction processData(input) {\r\n //Enter your code here\r\n input = input.split('\\n');\r\n const T = Number(input[0].trim());\r\n let i = 1;\r\n for (let t = 0; t < T; t++) {\r\n const N = Number(input[i++].trim());\r\n const ans = solve(N);\r\n console.log(ans);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst n = readLine();\n\t\tif (+n <= 9) console.log(n);\n\t\telse {\n\t\t\tlet count = 9;\n\t\t\tconst firstChar = n[0];\n\t\t\tconst len = n.length;\n\t\t\tif (+n >= +firstChar.repeat(len)) count++;\n\t\t\tcount += +firstChar - 1;\n\t\t\tcount += (len - 2) * 9;\n\t\t\tconsole.log(count);\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n6\r\n1\r\n2\r\n3\r\n4\r\n5\r\n100\r\n\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r= 1 && res <= n) {\r\n cnt++;\r\n }\r\n }\r\n }\r\n print(cnt);\r\n}"}, {"source_code": " var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++)\r\n {\r\n var value = parseInt(readline());\r\n var count = 0;\r\n for (var j = 1; j < 10; j++)\r\n {\r\n var current = j;\r\n while (current <= value)\r\n {\r\n count++;\r\n current = (current * 10) + j;\r\n }\r\n }\r\n print(count);\r\n }"}, {"source_code": "var testcases = readline();\r\nvar count;\r\n \r\nfor(var k = 0 ; k < testcases ; k++) {\r\n var number = readline();\r\n count = 0;\r\n for (var i = 1; i <= number; i = i * 10 + 1) {\r\n for (var j = 1; j <= 9; j++) {\r\n if(i * j <= number) count++;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "var T = parseInt(readline());\r\nvar values = [];\r\nfor(var i = 1; i <= 9; i++) {\r\n var ans = 0;\r\n while(ans < 1000000000) {\r\n ans = (ans * 10) + i;\r\n values.push(ans);\r\n }\r\n}\r\nwhile(T--) {\r\n var N = parseInt(readline());\r\n var ans = 0;\r\n for(var value of values) {\r\n if(value <= N) {\r\n ans++;\r\n }\r\n }\r\n print(ans);\r\n}"}], "negative_code": [{"source_code": "var hotel = readline();\r\n \r\nwhile(hotel--){\r\n var n = parseInt(readline());\r\n var cnt = 0;\r\n if(n < 10) {\r\n print(n)\r\n }\r\n else {\r\n for(var i=10; i <= n; i++){\r\n var noOfDigits = i.toString().length;\r\n var divisor = '1'.repeat(noOfDigits);\r\n if(i%parseInt(divisor)===0){\r\n cnt++;\r\n }\r\n }\r\n print(cnt);\r\n }\r\n}"}, {"source_code": "var testcases = readline();\r\nvar count;\r\n \r\nfor(var i = 0 ; i < testcases ; i++) {\r\n var number = readline();\r\n if(number < 10){\r\n count = number;\r\n }\r\n if(number > 10){\r\n count = 9;\r\n for (var j = 10; j <= number; j++) {\r\n var flag = true;\r\n j = j.toString();\r\n for (var i = 1; i < j.length; i++) {\r\n if(j[i - 1] !== j[i]){\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if(flag) count++;\r\n }\r\n }\r\n print(i);\r\n}\r\n"}, {"source_code": "var testcases = readline();\r\nvar count;\r\n \r\nfor(var i = 0 ; i < testcases ; i++) {\r\n var number = readline();\r\n if(number < 10){\r\n count = number;\r\n }\r\n if(number > 10){\r\n count = 9;\r\n for (var j = 10; j <= number; j++) {\r\n var flag = true;\r\n j = j.toString();\r\n for (var i = 1; i < j.length; i++) {\r\n if(j[i - 1] !== j[i]){\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if(flag) count++;\r\n }\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var T = parseInt(readline());\r\nvar values = [];\r\nfor(var i = 1; i <= 9; i++) {\r\n var ans = 0;\r\n while(ans < 1000000) {\r\n ans = (ans * 10) + i;\r\n values.push(ans);\r\n }\r\n}\r\nwhile(T--) {\r\n var N = parseInt(readline());\r\n var ans = 0;\r\n for(var value of values) {\r\n if(value <= N) {\r\n ans++;\r\n }\r\n }\r\n print(ans);\r\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var s = readline();\n var n = parseInt(s);\n var len = s.length - 1;\n var p = Math.pow(10, len);\n print(n % (p === 1? 10: p) + 9 * len);\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n rl.close();\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n input.forEach(item => ordinaryNumbers(item));\r\n}\r\n\r\nfunction ordinaryNumbers(item) {\r\n let ordinaryNumbers = 1;\r\n let firstChar = item.charAt(0);\r\n\r\n for (let i = 1; i < item.length; ++i) {\r\n if (firstChar === item.charAt(i)) {\r\n ordinaryNumbers++;\r\n }\r\n }\r\n\r\n console.log(ordinaryNumbers);\r\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on('line', (line) => {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n rl.close();\r\n input.shift();\r\n main();\r\n }\r\n});\r\n\r\nfunction main() {\r\n input.forEach(item => console.log(item));\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n var b = 1; \n var c = 0\n var d = 0\n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d / b \n b = b * 10 + 1 \n }\n c += b / a \n console.log(Math.floor(c))\n }\n });\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n var b = 1; \n var c = 0\n var d = 0\n for(l = 10; l <= a; l*=10){\n d = l - 1 \n c += d / b \n b = b * 10 - 1 \n }\n c += b / a \n console.log(Math.floor(c))\n }\n });\n//2 - 2 % 0 + 1\n//2 - 2 % 0 - (0 - 1)\n//xcvz \n//2, min, *\n//[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; '15'\n"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 1\n var answer = 0\n for(j = 1; j <= lines[0]; j ++){\n var a = lines[j]\n for(k = 1; k < a; k++){\n var b = a.split('').sort(function(a, b){return a - b});\n for(c = 0 ; c < b.length; c++){\n if(b[c] == b[c - 1]){\n answer++\n }else if(b[c + 1] === '') {\n answer++\n }\n } \n s++\n }\n console.log(answer)\n }\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [firstNumber, ...rest] = d;\n let ans = (d.length - 1) * 9;\n\n if (ans === 0) {\n console.log(d);\n } else {\n ans += Number(firstNumber) - 1;\n console.log(ans);\n }\n\n // let answers = [];\n // let ans = 0;\n\n // for (let i = 1; i <= Number(d); i++) {\n // if (new Set(String(i)).size === 1) {\n // answers.push(i);\n // ans++;\n // }\n // }\n\n // console.log({ answers });\n // console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [firstNumber, ...rest] = d;\n let ans = (d.length - 1) * 9;\n\n if (ans === 0) {\n console.log(d);\n } else {\n ans += Number(firstNumber) - 1;\n }\n\n console.log(ans);\n\n // let answers = [];\n // let ans = 0;\n\n // for (let i = 1; i <= Number(d); i++) {\n // if (new Set(String(i)).size === 1) {\n // answers.push(i);\n // ans++;\n // }\n // }\n\n // console.log({ answers });\n // console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = (d.length - 1) * 9;\n\n if (ans === 0) {\n console.log(d);\n } else {\n console.log(ans);\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n const n = parseInt(readLine());\r\n //const s = readLine();\r\n b(n);\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction a(n,s)\r\n{\r\n let last = '';\r\n let solved = '';\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(s[i] !== last && solved.includes(s[i]))\r\n {\r\n return console.log('NO');\r\n }\r\n solved += s[i];\r\n last = s[i];\r\n }\r\n return print('YES');\r\n}\r\n\r\nfunction b(n)\r\n{\r\n // usiming every decimal add 9 \r\n let s = n.toString();\r\n let max = s.length * 9 - (9 - parseInt(s[0]));\r\n if(s[1] < s[0]) max--;\r\n return print(max)\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n const args = input.split('\\n');\r\n var v = [];\r\n var n = 1;\r\n for (var j = 1; j <= 9; j++) {\r\n for (var i = 1; i <= 9; i++) {\r\n v.push(i * n);\r\n }\r\n n *= 10;\r\n n += 1;\r\n }\r\n v.push(10 ** 9);\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n const c = parseInt(args[i], 10);\r\n var j = 0;\r\n while (v[j] <= c) {\r\n j++;\r\n }\r\n console.log(j);\r\n }\r\n}"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet initialized=false;\r\n\r\nfunction amountOfSameNums(inp){\r\n if(inp < 10) return inp\r\n\r\n let digits = String(inp).length,\r\n counter = (digits-1) * 9 + (Number( String(inp)[digits-1] ) || '');\r\n // for(var i=1, counter=0; i<=inp; i++){\r\n \r\n // // count amount of digits 10-100 11 22 33 44 55 66 77 88 99\r\n // 100-1000 (3-4 symbols difference) 4-5 difference same 9 numbers to check\r\n // 11 22 33 44 55 66 77 88 99\r\n // 111 222 333 444 555 666 777 888 999\r\n // if([...String(i)]\r\n // ++counter\r\n // }\r\n\r\n return counter\r\n}\r\n\r\nrl.on('line', (input) => {\r\n if(initialized){ console.log( amountOfSameNums(input) ) }\r\n else initialized = true\r\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rl();\r\n\r\n\t\tconst D = n.length;\r\n\r\n\t\tconst dmin = Math.min(...n.split(''));\r\n\r\n\t\tconst ans = 9 * (D - 1) + Number(n[0]) - (dmin == n[0] ? 0 : 1);\r\n\r\n\t\tconsole.log(ans)\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var a = lines[j];\n var b = 1;\n var r = 0;\n var t = 0;\n for(l = 10; l <= a; l*=10){\n t = l-1;\n r += t/b;\n b *= 10+1;\n }\n r += a/b;\n console.log(Math.floor(r));\n }\n \n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n) {\r\n let count = 9\r\n if (n < 10) console.log(n)\r\n else console.log(9 + Math.floor(n / 11))\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))\r\n}"}, {"source_code": "\r\nconst isNum = (num) => {\r\n\tif (num < 10)\r\n\t\treturn true;\r\n\r\n\tconst str = `${num}`.split('');\r\n\r\n\tconst set = new Set();\r\n\tfor (let i=0; i {\r\n\tconst n = +line;\r\n\r\n\tlet counter = 0;\r\n\tfor (let i=1; i<10; i++) {\r\n\t\tlet num = `${i}`;\r\n\t\twhile (+num <= n) {\r\n\t\t\tcounter++;\r\n\t\t\tnum += `${i}`;\r\n\t\t}\r\n\t}\r\n\r\n\treturn counter;\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1)\r\n\t\t.map(l => l.trim());\r\n\r\n\tconsole.time('time')\r\n\tfor (let i=0; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number);\n }else{\n var b = lines[i].split(' ').map(Number);\n var ans = 0;\n for(j = 0; j < n; j++){\n if(b[j] > a[j]){\n var temp = b[j];\n b[j] = a[j];\n a[j] = temp;\n }\n }\n a.sort(function(a, b){return b - a});\n b.sort(function(a, b){return b - a});\n console.log(a[0] * b[0]);\n }\n }\n});", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var g = readline();\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n var b = readline().split(\" \").map(w => parseInt(w))\r\n var max = []\r\n var min = []\r\n for(var i=0;i {\r\n input += chunk;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++]);\r\n let a = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n let b = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n let index = a.indexOf(Math.max(...a));\r\n while (a[index] > b[index]) {\r\n let temp = a[index];\r\n a[index] = b[index];\r\n b[index] = temp;\r\n index = a.indexOf(Math.max(...a));\r\n }\r\n index = b.indexOf(Math.max(...b));\r\n while (b[index] > a[index]) {\r\n let temp = a[index];\r\n a[index] = b[index];\r\n b[index] = temp;\r\n index = b.indexOf(Math.max(...b));\r\n }\r\n console.log(Math.max(...a) * Math.max(...b));\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let brr = readline().split(' ').map(Number);\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] > brr[i]) {\r\n [arr[i], brr[i]] = [brr[i], arr[i]];\r\n }\r\n }\r\n\r\n let f = Math.max(...arr);\r\n let s = Math.max(...brr);\r\n\r\n output(f * s);\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(alist[i] < blist[i]){\r\n\t\t\t\tvar tmp = alist[i];\r\n\t\t\t\talist[i] = blist[i];\r\n\t\t\t\tblist[i] = tmp;\r\n\t\t\t}\r\n\t\t}\r\n\t\talist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tblist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tmyout(alist[0] * blist[0]);\r\n\t}\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let j = 0 ; j < t; j++) {\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet b = nl.nums();\n\t\tfor(let i = 0; i < n; i++){\n\t\t\tif (a[i] > b[i]) {\n\t\t\t\t[a[i], b[i]] = [b[i], a[i]];\n\t\t\t}\n\t\t}\n\t\tans.push(Math.max(...a) * Math.max(...b));\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\n// function main(fileContents) {//input lines as an array\n// // console.log(fileContents);\n// fileContents.splice(0,1);\n// for(let i = 0; i < fileContents.length; i+=3){\n// const line1 = fileContents[i+1].split(\" \")\n// const line2 = fileContents[i+2].split(\" \")\n// // console.log(\"line1: \",line1,\"line2: \",line2)\n// let max = line1[0]*line2[0];\n//\n// for(let x = 0; x < line1.length; x++){\n// max= Math.max(max,line1[x]*line2[x])\n// }\n//\n// console.log(max)\n// }\n// }\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n for(let i = 0; i < fileContents.length; i+=3){\n const small = fileContents[i+1].split(\" \")\n const big = fileContents[i+2].split(\" \")\n\n for(let x = 0; x < small.length; x++){\n const smallBuff = Math.min(small[x],big[x]);\n const bigBuff = Math.max(small[x],big[x]);\n\n small[x] = smallBuff;\n big[x] = bigBuff;\n }\n\n // console.log(\"small\",small,\"big\",big)\n console.log(Math.max(...small)*Math.max(...big))\n }\n}\n\n"}, {"source_code": "// your code goes here\nvar total = parseInt(readline());\n\nfor(var i = 0; i < total; i++) {\n\tvar count = parseInt(readline());\n\tvar a = readline().split(\" \").map(x => parseInt(x));\n\tvar b = readline().split(\" \").map(x => parseInt(x));\n\t\n\tvar maxa = 1;\n\tvar maxb = 1;\n\tfor(var j = 0; j < count; j++) {\n\t\tif(a[j] < b[j]) {\n\t\t\tvar temp = a[j];\n\t\t\ta[j] = b[j];\n\t\t\tb[j] = temp;\n\t\t}\n\t\t\n\t\tmaxa = Math.max(maxa, a[j]);\n\t\tmaxb = Math.max(maxb, b[j]);\n\t}\n\t\n\tprint(maxa*maxb);\n}\n\n"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var g = readline();\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n var b = readline().split(\" \").map(w => parseInt(w))\r\n a.sort(function(ar,br) { return ar-br })\r\n b.sort(function(ar,br) { return ar-br })\r\n var g = 'b';\r\n var ans = a[a.length-1]*b[b.length-1]\r\n for(var i=0;ib[i]) {\r\n \t\tg='a';\r\n \t\tbreak;\r\n \t}\r\n \telse if(b[i]>a[i]) {\r\n \t\tg='b';\r\n \t\tbreak;\r\n \t}\r\n }\r\n if(g == 'b') {\r\n \tvar maxb = b[0]\r\n \tfor(var i=0;i b[0]) {\r\n \t\t\tbreak;\r\n \t\t} else {\r\n \t\t\tmaxb = Math.max(b[i], maxb);\r\n \t\t}\r\n \t}\r\n ans = Math.min(ans, a[a.length-1]*maxb)\r\n }\r\n else if(g =='a') {\r\n \tvar maxa = a[0]\r\n \tfor(var i=0;i {\r\n input += chunk;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++]);\r\n let a = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n let b = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n if (Math.max(...a) > Math.max(...b)) {\r\n let index = b.indexOf(Math.max(...b));\r\n while (a[index] < b[index]) {\r\n let temp = a[index];\r\n a[index] = b[index];\r\n b[index] = temp;\r\n index = b.indexOf(Math.max(...b));\r\n }\r\n } else {\r\n let index = a.indexOf(Math.max(...a));\r\n while (a[index] > b[index]) {\r\n let temp = a[index];\r\n a[index] = b[index];\r\n b[index] = temp;\r\n index = b.indexOf(Math.max(...b));\r\n }\r\n }\r\n console.log(Math.max(...a) * Math.max(...b));\r\n }\r\n});\r\n"}], "src_uid": "56197d2468d8515e520c0d925874bf3b"} {"source_code": "print(function(n, k) {\n\n\tvar ans = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tans[i] = [];\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tans[i][j] = i === j ? k : 0;\n\t}\n\n\treturn ans.map(function(v) {\n\t\treturn v.join(' ');\n\t}).join('\\n');\n\n} .apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": ";(function () {\n\n\tprint((function (n, k) {\n\t\tvar ret = [], t = [];\n\t\tfor (var i = 0; i < n; i++) t.push(0);\n\t\tt[0] = k; ret.push(t.join(' '));\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tt[i - 1] = 0; t[i] = k;\n\t\t\tret.push(t.join(' '));\n\t\t}\n\t\treturn ret.join('\\n');\n\t}).apply(this, readline().split(' ').map(Number)));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], sum = integers[1];\n\n\tfor (var r = 0; r < n; ++r) {\n\t\tvar row = [];\n\t\tfor (var c = 0; c < n; ++c) {\n\t\t\trow.push(c == r ? sum : 0);\n\t\t}\n\t\tprint(row.join(\" \"));\n\t}\n}\n\nmain();\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n const [n, k] = d.split(' ').map(Number);\n const matrix = new Array(n).fill(0).map(x => new Array(n).fill(0));\n let idx = 0;\n for (let i = 0; i < matrix.length; i++) {\n matrix[i][idx] = k;\n idx++;\n }\n\n for (let i = 0; i < matrix.length; i++) {\n console.log(matrix[i].join(' '));\n }\n\n c++;\n});\n"}], "negative_code": [], "src_uid": "e80088bee9c0df6adf280f8ffbeaa4a9"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb) {\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));\n return Array(a - b + 1).fill(0).map((v, i) => cb ? cb(a - i) : a - i);\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/); r = 0;\n let t = +inp[r++];\n For(1, t, i => {\n let [n, s] = inp.slice(r, r = r + 2);\n let n0 = n;\n n = [...n];\n s = +s;\n let sum = eval(n.join('+'));\n while (sum > s) {\n let d = Arr(n.length - 1, 0).find(v => n[v] != 0);\n n[d--] = 0;\n while (1) {\n if (d < 0) {\n n = [1, ...n];\n break;\n }\n n[d]++;\n if (n[d] < 10) break;\n n[d--] = 0;\n }\n sum = eval(n.join('+'));\n }\n console.log(BigInt(n.join('')) - BigInt(n0) + '')\n })\n})();", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb) {\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));\n return Array(a - b + 1).fill(0).map((v, i) => cb ? cb(a - i) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/); r = 0;\n let t = +inp[r++];\n For(1, t, i => {\n let [n, s] = inp.slice(r, r = r + 2);\n let n0 = n;\n n = [0, ...n].map(v => +v);\n s = +s;\n let sum = n.sum();\n while (sum > s) {\n let d = Arr(n.length - 1, 0).find(v => n[v] != 0);\n while (1) {\n n[d--] = 0;\n n[d]++;\n if (n[d] < 10) break;\n }\n sum = n.sum();\n }\n console.log(BigInt(n.join('')) - BigInt(n0) + '')\n })\n})();"}], "negative_code": [], "src_uid": "50738d19041f2e97e2e448eff3feed84"} {"source_code": "var pa = readline().split(' ').map(function(x){return parseInt(x);});\nwrite(readline().split(' ').map(function(x){return parseInt(((parseInt(x) * pa[1]) % pa[2]) / pa[1]);}).join(' '));\n", "positive_code": [{"source_code": "var line = readline().trim().split(' ');\n\nvar n = line[0];\nvar a = line[1];\nvar b = line[2];\n\nline = readline().trim().split(' ');\n\nfor (var i = 0; i < n; i++) {\n write(Math.floor(((line[i] * a) % b) / a));\n write(' ');\n}"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '')\n}\nfunction tokenize(s) {\n return trim(s).split(/\\s+/);\n}\nfunction integers(s) {\n var tokens = tokenize(s);\n for(var i=0; i ((n, x, y) => print(['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1]))(...readline().split(' ').map(Number)))", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, x, y] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet k = x&1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tk = k ^ a[i]&1;\r\n\t\t}\r\n\r\n\t\tconsole.log(k == (y&1) ? 'Alice' : 'Bob');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => print(['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1]))(...readline().split(' ').map(Number)))"}], "negative_code": [{"source_code": "Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => print(['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1]))(readline().split(' ').map(Number)))"}, {"source_code": "Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => ['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1])(readline().split(' ').map(Number)))"}], "src_uid": "d17752513405fc68d838e9b3792c7bef"} {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let q = 0; q < t; q++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n\r\n let lr = -1;\r\n for (let i = 0 ; i < n - 1; i++){\r\n if (a[i] == a[i + 1]){\r\n lr = i;\r\n break;\r\n }\r\n }\r\n\r\n let rr = -1;\r\n for (let i = n - 2; i >= 0; i--){\r\n if (a[i] == a[i + 1]){\r\n rr = i;\r\n break;\r\n }\r\n }\r\n\r\n if (lr == -1 || lr == rr|| a.length == 2){\r\n console.log(0);\r\n }\r\n else{\r\n console.log(Math.max(1, (rr - lr - 1)));\r\n }\r\n \r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let first = -1,\r\n last = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (first === -1 && a[i] === a[i - 1]) {\r\n first = i;\r\n }\r\n if (a[i] === a[i + 1]) {\r\n last = i;\r\n }\r\n }\r\n if (first === -1 || last < first) {\r\n console.log(0);\r\n } else {\r\n console.log(Math.max(1, last - first));\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let q = 0; q < t; q++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n\r\n let lr = -1;\r\n for (let i = 0 ; i < n - 1; i++){\r\n if (a[i] == a[i + 1]){\r\n lr = i;\r\n break;\r\n }\r\n }\r\n\r\n let rr = -1;\r\n for (let i = n - 2; i >= 0; i--){\r\n if (a[i] == a[i + 1]){\r\n rr = i;\r\n break;\r\n }\r\n }\r\n\r\n if (lr == -1 || a.length == 2){\r\n console.log(0);\r\n }\r\n else{\r\n console.log(Math.max(1, (rr - lr - 1)));\r\n }\r\n \r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let q = 0; q < t; q++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n\r\n let lr = -1;\r\n for (let i = 1 ; i < n; i++){\r\n if (a[i] == a[i - 1]){\r\n lr = i;\r\n break;\r\n }\r\n }\r\n\r\n let rr = -1;\r\n for (let i = n - 2; i >= 0; i--){\r\n if (a[i] == a[i + 1]){\r\n rr = i;\r\n break;\r\n }\r\n }\r\n\r\n if (lr == -1 || a.length == 2){\r\n console.log(0);\r\n }\r\n else if (lr == rr){\r\n console.log(1);\r\n }\r\n else{\r\n console.log(rr - lr);\r\n }\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let q = 0; q < t; q++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n\r\n let lr = -1;\r\n for (let i = 1 ; i < n; i++){\r\n if (a[i] == a[i - 1]){\r\n lr = i;\r\n break;\r\n }\r\n }\r\n\r\n let rr = -1;\r\n for (let i = n - 2; i >= 0; i--){\r\n if (a[i] == a[i + 1]){\r\n rr = i;\r\n break;\r\n }\r\n }\r\n\r\n if (lr == -1){\r\n console.log(0);\r\n }\r\n else if (lr == rr){\r\n console.log(1);\r\n }\r\n else{\r\n console.log(rr - lr);\r\n }\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a, b) {\r\n const map = new Map();\r\n for (let i = 0; i < n; i++) {\r\n if (!map.has(a[i])) map.set(a[i], []);\r\n map.get(a[i]).push(i);\r\n }\r\n const flag = new Array(n).fill(0);\r\n new Array(n).fill(-1);\r\n const hasIndex = (i, j) => {\r\n let arr = map.get(i);\r\n while (arr.length && arr[arr.length - 1] > j) {\r\n arr.pop();\r\n }\r\n return !!arr.length;\r\n };\r\n for (let i = n - 1, j = n - 1; i >= 0; i--) {\r\n if (flag[j]) {\r\n if (!hasIndex(b[i], j - 1)) {\r\n console.log('NO');\r\n return;\r\n }\r\n while (flag[j] && b[i] !== a[j]) {\r\n j--;\r\n }\r\n if (a[j] !== b[i]) {\r\n console.log('NO');\r\n return;\r\n }\r\n if (flag[j]) {\r\n const k = map.get(b[i]).pop();\r\n flag[k] = 1;\r\n }\r\n j--;\r\n } else {\r\n if (a[j] !== b[i]) {\r\n if (!hasIndex(b[i], j - 1) || b[i] !== a[j + 1]) {\r\n console.log('NO');\r\n return;\r\n }\r\n const k = map.get(b[i]).pop();\r\n flag[k] = 1;\r\n } else {\r\n j--;\r\n }\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n solve(n, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "a91be662101762bcb2c58b8db9ff61e0"} {"source_code": "var path = readline().split('');\n\nfunction counter (ch) {\n return function (total, x) {\n if (x === ch) {\n return total + 1;\n }\n return total;\n }\n}\n\nvar pathL = path.reduce(counter('L'), 0);\n\nvar pathR = path.reduce(counter('R'), 0);\n\nvar pathU = path.reduce(counter('U'), 0);\n\nvar pathD = path.reduce(counter('D'), 0);\n\nif (path.length % 2 !== 0) {\n print(-1);\n} else if (pathL === pathR && pathU === pathD) {\n print(0);\n} else {\n print((Math.abs(pathL - pathR) + Math.abs(pathU - pathD)) / 2);\n}\n", "positive_code": [{"source_code": "var s = readline();\nvar solution = function ( s ) {\n if ( s.length%2 != 0 ) {\n return -1;\n }\n var step = function ( coord, c ) {\n switch ( c ) {\n case \"L\":\n --coord.x;\n break;\n case \"R\":\n ++coord.x;\n break;\n case \"U\":\n ++coord.y;\n break;\n case \"D\":\n --coord.y;\n break;\n }\n return coord;\n };\n var destination = [...s].reduce( ( coord, c ) => step( coord, c ), { x: 0, y: 0 } );\n var manhattanDistance = Math.abs( destination.x ) + Math.abs( destination.y );\n return manhattanDistance / 2;\n};\nprint( solution( s ) );"}], "negative_code": [{"source_code": "var path = readline().split('');\n\nfunction counter (ch) {\n return function (total, x) {\n if (x === 'L') {\n return total + 1;\n }\n return total;\n }\n}\n\nvar pathL = path.reduce(counter('L'), 0);\n\nvar pathR = path.reduce(counter('R'), 0);\n\nvar pathU = path.reduce(counter('U'), 0);\n\nvar pathD = path.reduce(counter('D'), 0);\n\nif (path.length % 2 !== 0) {\n print(-1);\n} else if (pathL === pathR && pathU === pathD) {\n print(0);\n} else {\n print(Math.abs(pathL - pathR) / 2 + Math.abs(pathU - pathD) / 2);\n}"}, {"source_code": "var path = readline().split('');\n\nfunction counter (ch) {\n return function (total, x) {\n if (x === 'L') {\n return total + 1;\n }\n return total;\n }\n}\n\nvar pathL = path.reduce(counter('L'), 0);\n\nvar pathR = path.reduce(counter('R'), 0);\n\nvar pathU = path.reduce(counter('U'), 0);\n\nvar pathD = path.reduce(counter('D'), 0);\n\nif (path.length % 2 !== 0) {\n print(-1);\n} else if (pathL === pathR && pathU === pathD) {\n print(0);\n} else {\n print((Math.abs(pathL - pathR) + Math.abs(pathU - pathD)) / 2);\n}"}, {"source_code": "var s = readline();\nvar solution = function ( s ) {\n if ( s.length%2 != 0 ) {\n return -1;\n }\n var forward = [...s.substr( 0, s.length / 2 )];\n var backward = [...s.substr( s.length / 2, s.length / 2 )];\n var forwardHist = new Map( [ [ \"L\", 0 ], [ \"R\", 0 ], [ \"U\", 0 ], [ \"D\", 0 ] ] );\n var backwardHist = new Map( [ [ \"L\", 0 ], [ \"R\", 0 ], [ \"U\", 0 ], [ \"D\", 0 ] ] );\n forward.forEach( c => forwardHist.set( c, forwardHist.get( c ) + 1) );\n backward.forEach( c => backwardHist.set( c, backwardHist.get( c ) + 1) );\n return ( Math.abs( backwardHist.get( \"L\" ) - forwardHist.get( \"R\" ) ) + \n Math.abs( backwardHist.get( \"R\" ) - forwardHist.get( \"L\" ) ) + \n Math.abs( backwardHist.get( \"U\" ) - forwardHist.get( \"D\" ) ) + \n Math.abs( backwardHist.get( \"D\" ) - forwardHist.get( \"U\" ) )) / 2;\n};\nprint( solution( s ) );"}], "src_uid": "8237ac3f3c2e79f5f70be1595630207e"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n [...new Array(10).keys()];\r\n let res = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== i) {\r\n if (res === -1) res = a[i];else res &= a[i];\r\n }\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "Number.prototype.toInt = function () {\r\n\treturn parseInt(this);\r\n};\r\nString.prototype.toNumber = function () {\r\n\treturn +this;\r\n}\r\n\r\nconst readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nclass Input {\r\n\r\n\tconstructor() {\r\n\t\tthis._lineIndex = 0\r\n\t\tthis._inputsBuffer = []\r\n\t}\r\n\r\n\tget _currentLine() {\r\n\t\treturn this._lineIndex++;\r\n\t}\r\n\r\n\tbuffer(value) {\r\n\t\tthis._inputsBuffer.push(value);\r\n\t}\r\n\r\n\treadLine() {\r\n\t\treturn this._inputsBuffer[this._currentLine];\r\n\t}\r\n\r\n\treadNumber() {\r\n\t\treturn this.readLine().toNumber();\r\n\t}\r\n\r\n\treadArray() {\r\n\t\treturn this.readLine().split(' ');\r\n\t}\r\n\r\n\treadIntArray() {\r\n\t\treturn this.readArray().map(item => parseInt(item));\r\n\t}\r\n\r\n}\r\n\r\nconst io = new Input();\r\n\r\nrl.on('line', (input) => {\r\n\tio.buffer(input);\r\n});\r\n\r\nrl.on('close', () => {\r\n\t// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n\tfor (let i = io.readLine(); i > 0; --i) {\r\n\t\tio.readLine();\r\n\t\tconsole.log(io.readIntArray().reduce((ans, value, index) => {\r\n\t\t\tif (value !== index)\r\n\t\t\t\treturn ans & value;\r\n\t\t\treturn ans;\r\n\t\t}, Number.MAX_SAFE_INTEGER));\r\n\t}\r\n});\r\n"}], "negative_code": [{"source_code": "Number.prototype.toInt = function () {\r\n\treturn parseInt(this);\r\n};\r\nString.prototype.toNumber = function () {\r\n\treturn +this;\r\n}\r\n\r\nconst readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nclass Input {\r\n\r\n\tconstructor() {\r\n\t\tthis._lineIndex = 0\r\n\t\tthis._inputsBuffer = []\r\n\t}\r\n\r\n\tget _currentLine() {\r\n\t\treturn this._lineIndex++;\r\n\t}\r\n\r\n\tbuffer(value) {\r\n\t\tthis._inputsBuffer.push(value);\r\n\t}\r\n\r\n\treadLine() {\r\n\t\treturn this._inputsBuffer[this._currentLine];\r\n\t}\r\n\r\n\treadNumber() {\r\n\t\treturn this.readLine().toNumber();\r\n\t}\r\n\r\n\treadArray() {\r\n\t\treturn this.readLine().split(' ');\r\n\t}\r\n\r\n\treadIntArray() {\r\n\t\treturn this.readArray().map(item => parseInt(item));\r\n\t}\r\n\r\n}\r\n\r\nconst io = new Input();\r\n\r\nrl.on('line', (input) => {\r\n\tio.buffer(input);\r\n});\r\n\r\nrl.on('close', () => {\r\n\t// (function() {\r\n\t// const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n\tio.readLine();\r\n\tio.readLine();\r\n\tconsole.log(io.readIntArray().reduce((ans, value, index) => {\r\n\t\tif (value !== index)\r\n\t\t\treturn ans & value;\r\n\t\treturn ans;\r\n\t}, Number.MAX_SAFE_INTEGER));\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const p = [...new Array(10).keys()];\r\n function find(i) {\r\n while (i !== p[i]) {\r\n p[i] = p[p[i]];\r\n i = p[p[i]];\r\n }\r\n return i;\r\n }\r\n function union(i, j) {\r\n const [rooti, rootj] = [find(i), find(j)];\r\n if (rooti === rootj) return;\r\n p[rootj] = rooti;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== i) union(i, a[i]);\r\n }\r\n let scc = new Map();\r\n for (let i = 0; i < n; i++) {\r\n const root = find(i);\r\n if (!scc.has(root)) scc.set(root, []);\r\n scc.get(root).push(i);\r\n }\r\n let nums = new Set();\r\n for (let [, arr] of scc) {\r\n if (arr.length <= 1) continue;\r\n let x = arr[0];\r\n for (let i = 1; i < arr.length; i++) {\r\n x &= arr[i];\r\n }\r\n nums.add(x);\r\n }\r\n if (nums.size > 1) return 0;else return [...nums][0];\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "dea37a75a4aedd3a3a6fd51efdc3f8b2"} {"source_code": "function processData(input) {\ninput = input.trim().split('\\n')\n\nfor( let i = 1; i < input.length; i+=3){\n console.log(input[i+1].split(' ').map(n => Number(n)).sort((a,b) => a - b).join(' '))\n console.log(input[i+2].split(' ').map(n => Number(n)).sort((a,b) => a - b).join(' '))\n}\n}\n \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});", "positive_code": [{"source_code": "function processData(input) {\n \n const verbose = 0;\n input = input.trim().split(\"\\n\");\n // console.log(input);\n const tc = Number(input[0]);\n let row = 1;\n\n for (let i = 0; i < tc; i++) \n {\n const n = Number(input[row]);\n row++;\n let necklace = input[row].trim().split(\" \").map(ele => Number(ele));\n row++;\n let bracelet = input[row].trim().split(\" \").map(ele => Number(ele));\n row++;\n\n necklace.sort((a,b) => a - b);\n bracelet.sort((a,b) => a - b);\n let str1 = \"\";\n let str2 = \"\";\n for(let j = 0; j < n; j++)\n {\n str1 += necklace[j] + \" \";\n str2 += bracelet[j] + \" \";\n }\n \n console.log(str1);\n console.log(str2);\n \n if(verbose){\n console.log(n);\n console.log(necklace);\n console.log(bracelet);\n }\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "function processData(input) {\n //Enter your code here\n let verbose = 0\n input = input.trim().split('\\n')\n let tc = parseInt(input[0])\n verbose ? console.log(input, tc) : ''\n \n for(let t=0; tparseInt(e)).sort((a, b)=>a-b)\n let brace = input[t+3].split(' ').map(e=>parseInt(e)).sort((a, b)=>a-b)\n verbose ? console.log(n, neck, brace) : ''\n console.log(neck.join(' '))\n console.log(brace.join(' '))\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const test = Number(readline())\n for(let i = 0; i < test; i++){\n const n = Number(readline())\n let necklace = readline().split(\" \").map(e => Number(e)).sort((a,b) => (a-b))\n let bracelet = readline().split(\" \").map(e => Number(e)).sort((a,b) => (a-b))\n console.log(necklace.join(\" \"))\n console.log(bracelet.join(\" \"))\n }\n\n}\n"}, {"source_code": "function processData(input) {\n //Enter your code here\n input = input.trim().split(\"\\n\")\n var tCase = parseInt(input[0])\n input.shift()\n for(let i = 0; i < input.length; i++){\n var stk = input[i+1].split(\" \").map(Number)\n var arr = input[i+2].split(\" \").map(Number)\n stk = stk.sort((a,b) => a-b)\n arr = arr.sort((a,b) => a-b)\n console.log(stk.join(\" \"))\n console.log(arr.join(\" \"))\n i = i + 2\n }\n \n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n let n = readInt(input, ptr++)\n let ai = readInts(input, ptr++)\n let bi = readInts(input, ptr++)\n\n sort(ai)\n sort(bi)\n wr(ai.join(' '))\n wr(bi.join(' '))\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (a, b) {\n return [a.sort((a, b) => a - b).join(' '), b.sort((a, b) => a - b).join(' ')];\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let a = lines[testCount * 3 - 1].split(\" \").map(Number);\n let b = lines[testCount * 3].split(\" \").map(Number);\n\n let result = foo(a, b);\n answer += result[0] +\"\\n\";\n answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", _ => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let tests = Number(readline().trim());\n\n while (tests) {\n let len = Number(readline().trim());\n\n let necklaces = readline()\n .trim()\n .split(\" \")\n .map(e => {\n return Number(e);\n })\n .sort(function(a, b) {\n return a - b;\n });\n\n let bracelets = readline()\n .trim()\n .split(\" \")\n .map(e => {\n return Number(e);\n })\n .sort(function(a, b) {\n return a - b;\n });\n\n console.log(necklaces.join(\" \"));\n console.log(bracelets.join(\" \"));\n\n --tests;\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = -1;\n\nrl.on('line', (d) => {\n if (c === -1) {\n c++;\n return;\n }\n\n if (c % 3 === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n console.log(arr.join(' '));\n\n c++;\n});\n"}, {"source_code": "function processData(input) {\n input = input.trim().split(\"\\n\");\n input.shift();\n const printResult = (x,y,n) => {\n x.sort((a,b) => a-b);\n y.sort((a,b) => a-b);\n console.log(x.join(\" \"));\n console.log(y.join(\" \"));\n } \n for(let i = 0; i < input.length; i+=3){\n let size = Number(input[i]);\n let arr1 = input[i+1].split(\" \").map(Number);\n let arr2 = input[i+2].split(\" \").map(Number);\n printResult(arr1,arr2,size);\n }\n \n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j =0; j +x).sort((a, b) => a -b)\n const b = lines[j*3+3].split(' ').map(x => +x).sort((a, b) => a -b)\n\n console.log(o.join(' '))\n console.log(b.join(' '))\n }\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function processData(input) {\n //Enter your code here\n input = input.trim().split(\"\\n\");\n input = input.map(ele => ele.trim().split(\" \").map(Number))\n let tc = input[0][0]\n // console.log(tc)\n for(let i = 2; i < input.length; i = i + 3) {\n let necklessArr = input[i]\n let braceletArr = input[i + 1]\n necklessArr.sort((a, b) => a - b)\n braceletArr.sort((a, b) => a - b)\n console.log(necklessArr.join(\" \"))\n console.log(braceletArr.join(\" \"))\n \n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "function main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (v) { return v.trim().split(\" \").map(function (u) { return parseInt(u); }); });\n var n = lines.shift()[0];\n while (n > 0) {\n lines.shift();\n var as = lines.shift().sort(function (a, b) { return a - b; });\n var bs = lines.shift().sort(function (a, b) { return a - b; });\n // const as = Array.from({ length: 100 }, () => Math.floor(Math.random() * 1000));\n // const bs = Array.from({ length: 100 }, () => Math.floor(Math.random() * 1000));\n // const ra = as.sort((a, b) => a - b);\n // const rb = bs.sort((a, b) => a - b);\n // const set = new Set();\n // for()\n // try {\n // bruteforce(as, new Set(bs), new Set(), 0, []);\n // } catch(res) {\n console.log(as.join(\" \"));\n console.log(bs.join(\" \"));\n // }\n n--;\n }\n}\nfunction bruteforce(as, bset, got, i, order) {\n if (i === as.length) {\n throw order;\n }\n bset.forEach(function (b) {\n var sum = as[i] + b;\n if (!got.has(sum)) {\n got.add(sum);\n bset[\"delete\"](b);\n bruteforce(as, bset, got, i + 1, order.concat(b));\n bset.add(b);\n got[\"delete\"](sum);\n }\n });\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "function processData(input) {\n //Enter your code here\n var data = input.split('\\n')\n var tcs = Number(data[0])\n var line= 1\n for(var i = 0;iparseInt(a))\n a.sort((a,b)=>(a-b))\n console.log(a.join(' '))\n line++\n var b = data[line].split(' ').map(a=>parseInt(a))\n b.sort((a,b)=>(a-b))\n console.log(b.join(' '))\n\n line++\n \n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a, b) => a.sort((x, y) => x - y).join(' ') + '\\n' + b.sort((x, y) => x - y).join(' ');\n\nlet t = +readline()\nwhile(t--) print(problem(+readline(), readline().split(' ').map(i => +i), readline().split(' ').map(i => +i)))\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t * 2);\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var alist = myconv(next(),4);\n var blist = myconv(next(),4);\n alist.sort(function(a,b){\n return a -b;\n });\n blist.sort(function(a,b){\n return a -b;\n });\n output[i * 2] = myconv(alist,8);\n output[i * 2 + 1] = myconv(blist,8);\n }\n myout(myconv(output,9));\n}"}, {"source_code": "//var input = readline();\n\nvar T = parseInt(readline());\nfor (var i = 0; i parseInt(x));\n ar.sort((a, b) => a - b);\n\n var ar1 = readline().split(' ').map(x => parseInt(x));\n ar1.sort((a, b) => a - b);\n\n print(ar.join(' '));\n print(ar1.join(' '));\n}\n"}, {"source_code": "//var input = readline();\n\nvar T = parseInt(readline());\nfor (var i = 0; i parseInt(x));\n ar.sort((a, b) => a - b);\n\n var ar1 = readline().split(' ').map(x => parseInt(x));\n ar1.sort((a, b) => a - b);\n\n print(ar.join(\" \") + \"\\n\" + ar1.join(\" \"));\n\n}\n"}, {"source_code": "var t = readline();\nfor (var i=0; i a-b).join(' ');\n var B = readline().split(' ').sort((a,b) => a-b).join(' ');\n print(A);\n print(B);\n}"}], "negative_code": [], "src_uid": "5c6af8ced2c4b8999abccfac5c4d0057"} {"source_code": "(function() {\n\n var q = +readline();\n var res = '';\n for(var i = 0; i < q; i++) {\n readline();\n var s = readline();\n if(s.length == 1 || (s.length == 2 && +s[0] >= +s[1])) {\n res += 'NO\\n';\n }\n else {\n res += 'YES\\n2\\n'; \n res += s[0] + ' ' + s.slice(1) + '\\n'; \n }\n }\n print(res);\n}());", "positive_code": [{"source_code": "(function() {\n\n var q = +readline();\n var res = '';\n for(var i = 0; i < q; i++) {\n readline();\n var s = readline();\n if(s.length == 1 || (s.length == 2 && +s[0] >= +s[1])) {\n res += 'NO\\n';\n }\n else {\n res += 'YES\\n2\\n'; \n res += s[0] + ' ' + s.slice(1) + '\\n'; \n }\n }\n print(res);\n}());\n\n\n"}, {"source_code": ";(function (globalObject) {\n 'use strict';\n\n var BigNumber,\n isNumeric = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/i,\n mathceil = Math.ceil,\n mathfloor = Math.floor,\n bignumberError = '[BigNumber Error] ',\n tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',\n BASE = 1e14,\n LOG_BASE = 14,\n MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1\n POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],\n SQRT_BASE = 1e7,\n MAX = 1E9; // 0 to MAX_INT32\n\n function clone(configObject) {\n var div, convertBase, parseNumeric,\n P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },\n ONE = new BigNumber(1),\n\n // The maximum number of decimal places for operations involving division.\n DECIMAL_PLACES = 1000, // 0 to MAX\n ROUNDING_MODE = 4, // 0 to 8 (look at ROUND_)\n\n // The exponent value at and beneath which toString returns exponential notation.\n TO_EXP_NEG = -1000, // 0 to -MAX\n // The exponent value at and above which toString returns exponential notation.\n TO_EXP_POS = 1000, // 0 to MAX\n MIN_EXP = -1e8, // -1 to -MAX\n MAX_EXP = 1e8, // 1 to MAX\n\n CRYPTO = false, // true or false\n MODULO_MODE = 1, // 0 to 9\n POW_PRECISION = 0, // 0 to MAX\n FORMAT = {\n prefix: '',\n groupSize: 3,\n secondaryGroupSize: 0,\n groupSeparator: ',',\n decimalSeparator: '.',\n fractionGroupSize: 0,\n fractionGroupSeparator: '\\xA0', // non-breaking space\n suffix: ''\n },\n ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n function BigNumber(n, b) {\n var alphabet, c, caseChanged, e, i, isNum, len, str,\n x = this;\n if (!(x instanceof BigNumber)) {\n return new BigNumber(n, b);\n }\n if (b == null) {\n if (n instanceof BigNumber) {\n x.s = n.s;\n x.e = n.e;\n x.c = (n = n.c) ? n.slice() : n;\n return;\n }\n isNum = typeof n == 'number';\n if (isNum && n * 0 == 0) {\n x.s = 1 / n < 0 ? (n = -n, -1) : 1;\n if (n === ~~n) {\n for (e = 0, i = n; i >= 10; i /= 10, e++);\n x.e = e;\n x.c = [n];\n return;\n }\n str = String(n);\n } else {\n str = String(n);\n if (!isNumeric.test(str)) return parseNumeric(x, str, isNum);\n x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;\n }\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n if ((i = str.search(/e/i)) > 0) {\n if (e < 0) e = i;\n e += +str.slice(i + 1);\n str = str.substring(0, i);\n } else if (e < 0) {\n e = str.length;\n }\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = String(n);\n if (b == 10) {\n x = new BigNumber(n instanceof BigNumber ? n : str);\n return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);\n }\n isNum = typeof n == 'number';\n if (isNum) {\n if (n * 0 != 0) return parseNumeric(x, str, isNum, b);\n x.s = 1 / n < 0 ? (str = str.slice(1), -1) : 1;\n if (BigNumber.DEBUG && str.replace(/^0\\.0*|\\./, '').length > 15) {\n throw Error\n (tooManyDigits + n);\n }\n isNum = false;\n } else {\n x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;\n }\n alphabet = ALPHABET.slice(0, b);\n e = i = 0;\n for (len = str.length; i < len; i++) {\n if (alphabet.indexOf(c = str.charAt(i)) < 0) {\n if (c == '.') {\n if (i > e) {\n e = len;\n continue;\n }\n } else if (!caseChanged) {\n if (str == str.toUpperCase() && (str = str.toLowerCase()) ||\n str == str.toLowerCase() && (str = str.toUpperCase())) {\n caseChanged = true;\n i = -1;\n e = 0;\n continue;\n }\n }\n return parseNumeric(x, String(n), isNum, b);\n }\n }\n str = convertBase(str, b, 10, x.s);\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n else e = str.length;\n }\n for (i = 0; str.charCodeAt(i) === 48; i++);\n for (len = str.length; str.charCodeAt(--len) === 48;);\n str = str.slice(i, ++len);\n if (str) {\n len -= i;\n if (isNum && BigNumber.DEBUG &&\n len > 15 && (n > MAX_SAFE_INTEGER || n !== mathfloor(n))) {\n throw Error\n (tooManyDigits + (x.s * n));\n }\n e = e - i - 1;\n if (e > MAX_EXP) {\n x.c = x.e = null;\n } else if (e < MIN_EXP) {\n x.c = [x.e = 0];\n } else {\n x.e = e;\n x.c = [];\n i = (e + 1) % LOG_BASE;\n if (e < 0) i += LOG_BASE;\n if (i < len) {\n if (i) x.c.push(+str.slice(0, i));\n for (len -= LOG_BASE; i < len;) {\n x.c.push(+str.slice(i, i += LOG_BASE));\n }\n str = str.slice(i);\n i = LOG_BASE - str.length;\n } else {\n i -= len;\n }\n for (; i--; str += '0');\n x.c.push(+str);\n }\n } else {\n x.c = [x.e = 0];\n }\n }\n\n BigNumber.clone = clone;\n BigNumber.ROUND_UP = 0;\n BigNumber.ROUND_DOWN = 1;\n BigNumber.ROUND_CEIL = 2;\n BigNumber.ROUND_FLOOR = 3;\n BigNumber.ROUND_HALF_UP = 4;\n BigNumber.ROUND_HALF_DOWN = 5;\n BigNumber.ROUND_HALF_EVEN = 6;\n BigNumber.ROUND_HALF_CEIL = 7;\n BigNumber.ROUND_HALF_FLOOR = 8;\n BigNumber.EUCLID = 9;\n\n BigNumber.config = BigNumber.set = function (obj) {\n var p, v;\n if (obj != null) {\n if (typeof obj == 'object') {\n if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n DECIMAL_PLACES = v;\n }\n if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {\n v = obj[p];\n intCheck(v, 0, 8, p);\n ROUNDING_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, 0, p);\n intCheck(v[1], 0, MAX, p);\n TO_EXP_NEG = v[0];\n TO_EXP_POS = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);\n }\n }\n if (obj.hasOwnProperty(p = 'RANGE')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, -1, p);\n intCheck(v[1], 1, MAX, p);\n MIN_EXP = v[0];\n MAX_EXP = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n if (v) {\n MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);\n } else {\n throw Error\n (bignumberError + p + ' cannot be zero: ' + v);\n }\n }\n }\n if (obj.hasOwnProperty(p = 'CRYPTO')) {\n v = obj[p];\n if (v === !!v) {\n if (v) {\n if (typeof crypto != 'undefined' && crypto &&\n (crypto.getRandomValues || crypto.randomBytes)) {\n CRYPTO = v;\n } else {\n CRYPTO = !v;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n } else {\n CRYPTO = v;\n }\n } else {\n throw Error\n (bignumberError + p + ' not true or false: ' + v);\n }\n }\n if (obj.hasOwnProperty(p = 'MODULO_MODE')) {\n v = obj[p];\n intCheck(v, 0, 9, p);\n MODULO_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'POW_PRECISION')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n POW_PRECISION = v;\n }\n if (obj.hasOwnProperty(p = 'FORMAT')) {\n v = obj[p];\n if (typeof v == 'object') FORMAT = v;\n else throw Error\n (bignumberError + p + ' not an object: ' + v);\n }\n if (obj.hasOwnProperty(p = 'ALPHABET')) {\n v = obj[p];\n if (typeof v == 'string' && !/^.$|[+-.\\s]|(.).*\\1/.test(v)) {\n ALPHABET = v;\n } else {\n throw Error\n (bignumberError + p + ' invalid: ' + v);\n }\n }\n } else {\n throw Error\n (bignumberError + 'Object expected: ' + obj);\n }\n }\n\n return {\n DECIMAL_PLACES: DECIMAL_PLACES,\n ROUNDING_MODE: ROUNDING_MODE,\n EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],\n RANGE: [MIN_EXP, MAX_EXP],\n CRYPTO: CRYPTO,\n MODULO_MODE: MODULO_MODE,\n POW_PRECISION: POW_PRECISION,\n FORMAT: FORMAT,\n ALPHABET: ALPHABET\n };\n };\n\n BigNumber.isBigNumber = function (v) {\n return v instanceof BigNumber || v && v._isBigNumber === true || false;\n };\n\n BigNumber.maximum = BigNumber.max = function () {\n return maxOrMin(arguments, P.lt);\n };\n\n BigNumber.minimum = BigNumber.min = function () {\n return maxOrMin(arguments, P.gt);\n };\n\n BigNumber.random = (function () {\n var pow2_53 = 0x20000000000000;\n var random53bitInt = (Math.random() * pow2_53) & 0x1fffff\n ? function () { return mathfloor(Math.random() * pow2_53); }\n : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +\n (Math.random() * 0x800000 | 0); };\n return function (dp) {\n var a, b, e, k, v,\n i = 0,\n c = [],\n rand = new BigNumber(ONE);\n if (dp == null) dp = DECIMAL_PLACES;\n else intCheck(dp, 0, MAX);\n k = mathceil(dp / LOG_BASE);\n if (CRYPTO) {\n if (crypto.getRandomValues) {\n a = crypto.getRandomValues(new Uint32Array(k *= 2));\n for (; i < k;) {\n v = a[i] * 0x20000 + (a[i + 1] >>> 11);\n if (v >= 9e15) {\n b = crypto.getRandomValues(new Uint32Array(2));\n a[i] = b[0];\n a[i + 1] = b[1];\n } else {\n c.push(v % 1e14);\n i += 2;\n }\n }\n i = k / 2;\n } else if (crypto.randomBytes) {\n a = crypto.randomBytes(k *= 7);\n for (; i < k;) {\n v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +\n (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +\n (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];\n if (v >= 9e15) {\n crypto.randomBytes(7).copy(a, i);\n } else {\n c.push(v % 1e14);\n i += 7;\n }\n }\n i = k / 7;\n } else {\n CRYPTO = false;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n }\n if (!CRYPTO) {\n for (; i < k;) {\n v = random53bitInt();\n if (v < 9e15) c[i++] = v % 1e14;\n }\n }\n k = c[--i];\n dp %= LOG_BASE;\n if (k && dp) {\n v = POWS_TEN[LOG_BASE - dp];\n c[i] = mathfloor(k / v) * v;\n }\n for (; c[i] === 0; c.pop(), i--);\n if (i < 0) {\n c = [e = 0];\n } else {\n for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);\n for (i = 1, v = c[0]; v >= 10; v /= 10, i++);\n if (i < LOG_BASE) e -= LOG_BASE - i;\n }\n rand.e = e;\n rand.c = c;\n return rand;\n };\n })();\n\n BigNumber.sum = function () {\n var i = 1,\n args = arguments,\n sum = new BigNumber(args[0]);\n for (; i < args.length;) sum = sum.plus(args[i++]);\n return sum;\n };\n\n convertBase = (function () {\n var decimal = '0123456789';\n function toBaseOut(str, baseIn, baseOut, alphabet) {\n var j,\n arr = [0],\n arrL,\n i = 0,\n len = str.length;\n for (; i < len;) {\n for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);\n arr[0] += alphabet.indexOf(str.charAt(i++));\n for (j = 0; j < arr.length; j++) {\n if (arr[j] > baseOut - 1) {\n if (arr[j + 1] == null) arr[j + 1] = 0;\n arr[j + 1] += arr[j] / baseOut | 0;\n arr[j] %= baseOut;\n }\n }\n }\n return arr.reverse();\n }\n return function (str, baseIn, baseOut, sign, callerIsToString) {\n var alphabet, d, e, k, r, x, xc, y,\n i = str.indexOf('.'),\n dp = DECIMAL_PLACES,\n rm = ROUNDING_MODE;\n if (i >= 0) {\n k = POW_PRECISION;\n POW_PRECISION = 0;\n str = str.replace('.', '');\n y = new BigNumber(baseIn);\n x = y.pow(str.length - i);\n POW_PRECISION = k;\n y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),\n 10, baseOut, decimal);\n y.e = y.c.length;\n }\n xc = toBaseOut(str, baseIn, baseOut, callerIsToString\n ? (alphabet = ALPHABET, decimal)\n : (alphabet = decimal, ALPHABET));\n e = k = xc.length;\n for (; xc[--k] == 0; xc.pop());\n if (!xc[0]) return alphabet.charAt(0);\n if (i < 0) {\n --e;\n } else {\n x.c = xc;\n x.e = e;\n x.s = sign;\n x = div(x, y, dp, rm, baseOut);\n xc = x.c;\n r = x.r;\n e = x.e;\n }\n d = e + dp + 1;\n i = xc[d];\n k = baseOut / 2;\n r = r || d < 0 || xc[d + 1] != null;\n r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (d < 1 || !xc[0]) {\n str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);\n } else {\n xc.length = d;\n if (r) {\n for (--baseOut; ++xc[--d] > baseOut;) {\n xc[d] = 0;\n if (!d) {\n ++e;\n xc = [1].concat(xc);\n }\n }\n }\n for (k = xc.length; !xc[--k];);\n for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));\n str = toFixedPoint(str, e, alphabet.charAt(0));\n }\n return str;\n };\n })();\n\n div = (function () {\n function multiply(x, k, base) {\n var m, temp, xlo, xhi,\n carry = 0,\n i = x.length,\n klo = k % SQRT_BASE,\n khi = k / SQRT_BASE | 0;\n for (x = x.slice(); i--;) {\n xlo = x[i] % SQRT_BASE;\n xhi = x[i] / SQRT_BASE | 0;\n m = khi * xlo + xhi * klo;\n temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;\n carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;\n x[i] = temp % base;\n }\n if (carry) x = [carry].concat(x);\n return x;\n }\n\n function compare(a, b, aL, bL) {\n var i, cmp;\n if (aL != bL) {\n cmp = aL > bL ? 1 : -1;\n } else {\n for (i = cmp = 0; i < aL; i++) {\n if (a[i] != b[i]) {\n cmp = a[i] > b[i] ? 1 : -1;\n break;\n }\n }\n }\n return cmp;\n }\n\n function subtract(a, b, aL, base) {\n var i = 0;\n for (; aL--;) {\n a[aL] -= i;\n i = a[aL] < b[aL] ? 1 : 0;\n a[aL] = i * base + a[aL] - b[aL];\n }\n for (; !a[0] && a.length > 1; a.splice(0, 1));\n }\n return function (x, y, dp, rm, base) {\n var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,\n yL, yz,\n s = x.s == y.s ? 1 : -1,\n xc = x.c,\n yc = y.c;\n if (!xc || !xc[0] || !yc || !yc[0]) {\n return new BigNumber(\n !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :\n xc && xc[0] == 0 || !yc ? s * 0 : s / 0\n );\n }\n q = new BigNumber(s);\n qc = q.c = [];\n e = x.e - y.e;\n s = dp + e + 1;\n if (!base) {\n base = BASE;\n e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);\n s = s / LOG_BASE | 0;\n }\n for (i = 0; yc[i] == (xc[i] || 0); i++);\n if (yc[i] > (xc[i] || 0)) e--;\n if (s < 0) {\n qc.push(1);\n more = true;\n } else {\n xL = xc.length;\n yL = yc.length;\n i = 0;\n s += 2;\n n = mathfloor(base / (yc[0] + 1));\n if (n > 1) {\n yc = multiply(yc, n, base);\n xc = multiply(xc, n, base);\n yL = yc.length;\n xL = xc.length;\n }\n xi = yL;\n rem = xc.slice(0, yL);\n remL = rem.length;\n for (; remL < yL; rem[remL++] = 0);\n yz = yc.slice();\n yz = [0].concat(yz);\n yc0 = yc[0];\n if (yc[1] >= base / 2) yc0++;\n do {\n n = 0;\n cmp = compare(yc, rem, yL, remL);\n if (cmp < 0) {\n rem0 = rem[0];\n if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);\n n = mathfloor(rem0 / yc0);\n if (n > 1) {\n if (n >= base) n = base - 1;\n prod = multiply(yc, n, base);\n prodL = prod.length;\n remL = rem.length;\n while (compare(prod, rem, prodL, remL) == 1) {\n n--;\n subtract(prod, yL < prodL ? yz : yc, prodL, base);\n prodL = prod.length;\n cmp = 1;\n }\n } else {\n if (n == 0) {\n cmp = n = 1;\n }\n prod = yc.slice();\n prodL = prod.length;\n }\n if (prodL < remL) prod = [0].concat(prod);\n subtract(rem, prod, remL, base);\n remL = rem.length;\n if (cmp == -1) {\n while (compare(yc, rem, yL, remL) < 1) {\n n++;\n subtract(rem, yL < remL ? yz : yc, remL, base);\n remL = rem.length;\n }\n }\n } else if (cmp === 0) {\n n++;\n rem = [0];\n }\n qc[i++] = n;\n if (rem[0]) {\n rem[remL++] = xc[xi] || 0;\n } else {\n rem = [xc[xi]];\n remL = 1;\n }\n } while ((xi++ < xL || rem[0] != null) && s--);\n more = rem[0] != null;\n if (!qc[0]) qc.splice(0, 1);\n }\n if (base == BASE) {\n for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);\n round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);\n } else {\n q.e = e;\n q.r = +more;\n }\n return q;\n };\n })();\n\n function format(n, i, rm, id) {\n var c0, e, ne, len, str;\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n if (!n.c) return n.toString();\n c0 = n.c[0];\n ne = n.e;\n if (i == null) {\n str = coeffToString(n.c);\n str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)\n ? toExponential(str, ne)\n : toFixedPoint(str, ne, '0');\n } else {\n n = round(new BigNumber(n), i, rm);\n e = n.e;\n str = coeffToString(n.c);\n len = str.length;\n if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {\n for (; len < i; str += '0', len++);\n str = toExponential(str, e);\n } else {\n i -= ne;\n str = toFixedPoint(str, e, '0');\n if (e + 1 > len) {\n if (--i > 0) for (str += '.'; i--; str += '0');\n } else {\n i += e - len;\n if (i > 0) {\n if (e + 1 == len) str += '.';\n for (; i--; str += '0');\n }\n }\n }\n }\n return n.s < 0 && c0 ? '-' + str : str;\n }\n\n function maxOrMin(args, method) {\n var n,\n i = 1,\n m = new BigNumber(args[0]);\n for (; i < args.length; i++) {\n n = new BigNumber(args[i]);\n if (!n.s) {\n m = n;\n break;\n } else if (method.call(m, n)) {\n m = n;\n }\n }\n return m;\n }\n\n function normalise(n, c, e) {\n var i = 1,\n j = c.length;\n for (; !c[--j]; c.pop());\n for (j = c[0]; j >= 10; j /= 10, i++);\n if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {\n n.c = n.e = null;\n } else if (e < MIN_EXP) {\n n.c = [n.e = 0];\n } else {\n n.e = e;\n n.c = c;\n }\n return n;\n }\n\n parseNumeric = (function () {\n var basePrefix = /^(-?)0([xbo])(?=\\w[\\w.]*$)/i,\n dotAfter = /^([^.]+)\\.$/,\n dotBefore = /^\\.([^.]+)$/,\n isInfinityOrNaN = /^-?(Infinity|NaN)$/,\n whitespaceOrPlus = /^\\s*\\+(?=[\\w.])|^\\s+|\\s+$/g;\n return function (x, str, isNum, b) {\n var base,\n s = isNum ? str : str.replace(whitespaceOrPlus, '');\n if (isInfinityOrNaN.test(s)) {\n x.s = isNaN(s) ? null : s < 0 ? -1 : 1;\n x.c = x.e = null;\n } else {\n if (!isNum) {\n s = s.replace(basePrefix, function (m, p1, p2) {\n base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;\n return !b || b == base ? p1 : m;\n });\n if (b) {\n base = b;\n s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');\n }\n if (str != s) return new BigNumber(s, base);\n }\n if (BigNumber.DEBUG) {\n throw Error\n (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);\n }\n x.c = x.e = x.s = null;\n }\n }\n })();\n\n function round(x, sd, rm, r) {\n var d, i, j, k, n, ni, rd,\n xc = x.c,\n pows10 = POWS_TEN;\n if (xc) {\n out: {\n for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);\n i = sd - d;\n if (i < 0) {\n i += LOG_BASE;\n j = sd;\n n = xc[ni = 0];\n rd = n / pows10[d - j - 1] % 10 | 0;\n } else {\n ni = mathceil((i + 1) / LOG_BASE);\n if (ni >= xc.length) {\n if (r) {\n for (; xc.length <= ni; xc.push(0));\n n = rd = 0;\n d = 1;\n i %= LOG_BASE;\n j = i - LOG_BASE + 1;\n } else {\n break out;\n }\n } else {\n n = k = xc[ni];\n for (d = 1; k >= 10; k /= 10, d++);\n i %= LOG_BASE;\n j = i - LOG_BASE + d;\n rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;\n }\n }\n r = r || sd < 0 ||\n xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);\n r = rm < 4\n ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&\n ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (sd < 1 || !xc[0]) {\n xc.length = 0;\n if (r) {\n sd -= x.e + 1;\n xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];\n x.e = -sd || 0;\n } else {\n xc[0] = x.e = 0;\n }\n return x;\n }\n if (i == 0) {\n xc.length = ni;\n k = 1;\n ni--;\n } else {\n xc.length = ni + 1;\n k = pows10[LOG_BASE - i];\n xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;\n }\n if (r) {\n for (; ;) {\n if (ni == 0) {\n for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);\n j = xc[0] += k;\n for (k = 1; j >= 10; j /= 10, k++);\n if (i != k) {\n x.e++;\n if (xc[0] == BASE) xc[0] = 1;\n }\n break;\n } else {\n xc[ni] += k;\n if (xc[ni] != BASE) break;\n xc[ni--] = 0;\n k = 1;\n }\n }\n }\n for (i = xc.length; xc[--i] === 0; xc.pop());\n }\n if (x.e > MAX_EXP) {\n x.c = x.e = null;\n } else if (x.e < MIN_EXP) {\n x.c = [x.e = 0];\n }\n }\n return x;\n }\n\n function valueOf(n) {\n var str,\n e = n.e;\n if (e === null) return n.toString();\n str = coeffToString(n.c);\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(str, e)\n : toFixedPoint(str, e, '0');\n return n.s < 0 ? '-' + str : str;\n }\n\n P.absoluteValue = P.abs = function () {\n var x = new BigNumber(this);\n if (x.s < 0) x.s = 1;\n return x;\n };\n\n P.comparedTo = function (y, b) {\n return compare(this, new BigNumber(y, b));\n };\n\n P.decimalPlaces = P.dp = function (dp, rm) {\n var c, n, v,\n x = this;\n if (dp != null) {\n intCheck(dp, 0, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), dp + x.e + 1, rm);\n }\n if (!(c = x.c)) return null;\n n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;\n if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);\n if (n < 0) n = 0;\n return n;\n };\n\n P.dividedBy = P.div = function (y, b) {\n return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);\n };\n\n P.dividedToIntegerBy = P.idiv = function (y, b) {\n return div(this, new BigNumber(y, b), 0, 1);\n };\n\n P.exponentiatedBy = P.pow = function (n, m) {\n var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,\n x = this;\n n = new BigNumber(n);\n if (n.c && !n.isInteger()) {\n throw Error\n (bignumberError + 'Exponent not an integer: ' + valueOf(n));\n }\n if (m != null) m = new BigNumber(m);\n nIsBig = n.e > 14;\n if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {\n y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));\n return m ? y.mod(m) : y;\n }\n nIsNeg = n.s < 0;\n if (m) {\n if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);\n isModExp = !nIsNeg && x.isInteger() && m.isInteger();\n if (isModExp) x = x.mod(m);\n } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0\n ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7\n : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {\n k = x.s < 0 && isOdd(n) ? -0 : 0;\n if (x.e > -1) k = 1 / k;\n return new BigNumber(nIsNeg ? 1 / k : k);\n } else if (POW_PRECISION) {\n k = mathceil(POW_PRECISION / LOG_BASE + 2);\n }\n if (nIsBig) {\n half = new BigNumber(0.5);\n if (nIsNeg) n.s = 1;\n nIsOdd = isOdd(n);\n } else {\n i = Math.abs(+valueOf(n));\n nIsOdd = i % 2;\n }\n y = new BigNumber(ONE);\n for (; ;) {\n if (nIsOdd) {\n y = y.times(x);\n if (!y.c) break;\n\n if (k) {\n if (y.c.length > k) y.c.length = k;\n } else if (isModExp) {\n y = y.mod(m);\n }\n }\n if (i) {\n i = mathfloor(i / 2);\n if (i === 0) break;\n nIsOdd = i % 2;\n } else {\n n = n.times(half);\n round(n, n.e + 1, 1);\n if (n.e > 14) {\n nIsOdd = isOdd(n);\n } else {\n i = +valueOf(n);\n if (i === 0) break;\n nIsOdd = i % 2;\n }\n }\n x = x.times(x);\n if (k) {\n if (x.c && x.c.length > k) x.c.length = k;\n } else if (isModExp) {\n x = x.mod(m);\n }\n }\n if (isModExp) return y;\n if (nIsNeg) y = ONE.div(y);\n return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;\n };\n\n P.integerValue = function (rm) {\n var n = new BigNumber(this);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(n, n.e + 1, rm);\n };\n\n P.isEqualTo = P.eq = function (y, b) {\n return compare(this, new BigNumber(y, b)) === 0;\n };\n\n P.isFinite = function () {\n return !!this.c;\n };\n\n P.isGreaterThan = P.gt = function (y, b) {\n return compare(this, new BigNumber(y, b)) > 0;\n };\n\n P.isGreaterThanOrEqualTo = P.gte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;\n\n };\n\n P.isInteger = function () {\n return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;\n };\n\n P.isLessThan = P.lt = function (y, b) {\n return compare(this, new BigNumber(y, b)) < 0;\n };\n\n P.isLessThanOrEqualTo = P.lte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;\n };\n\n P.isNaN = function () {\n return !this.s;\n };\n\n P.isNegative = function () {\n return this.s < 0;\n };\n\n P.isPositive = function () {\n return this.s > 0;\n };\n\n P.isZero = function () {\n return !!this.c && this.c[0] == 0;\n };\n\n P.minus = function (y, b) {\n var i, j, t, xLTy,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.plus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);\n if (!xc[0] || !yc[0]) {\n return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :\n ROUNDING_MODE == 3 ? -0 : 0);\n }\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (xLTy = a < 0) {\n a = -a;\n t = xc;\n } else {\n ye = xe;\n t = yc;\n }\n t.reverse();\n for (b = a; b--; t.push(0));\n t.reverse();\n } else {\n j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;\n for (a = b = 0; b < j; b++) {\n if (xc[b] != yc[b]) {\n xLTy = xc[b] < yc[b];\n break;\n }\n }\n }\n if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;\n b = (j = yc.length) - (i = xc.length);\n if (b > 0) for (; b--; xc[i++] = 0);\n b = BASE - 1;\n for (; j > a;) {\n if (xc[--j] < yc[j]) {\n for (i = j; i && !xc[--i]; xc[i] = b);\n --xc[i];\n xc[j] += BASE;\n }\n\n xc[j] -= yc[j];\n }\n for (; xc[0] == 0; xc.splice(0, 1), --ye);\n if (!xc[0]) {\n y.s = ROUNDING_MODE == 3 ? -1 : 1;\n y.c = [y.e = 0];\n return y;\n }\n return normalise(y, xc, ye);\n };\n\n P.modulo = P.mod = function (y, b) {\n var q, s,\n x = this;\n y = new BigNumber(y, b);\n if (!x.c || !y.s || y.c && !y.c[0]) {\n return new BigNumber(NaN);\n } else if (!y.c || x.c && !x.c[0]) {\n return new BigNumber(x);\n }\n if (MODULO_MODE == 9) {\n s = y.s;\n y.s = 1;\n q = div(x, y, 0, 3);\n y.s = s;\n q.s *= s;\n } else {\n q = div(x, y, 0, MODULO_MODE);\n }\n y = x.minus(q.times(y));\n if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;\n return y;\n };\n\n P.multipliedBy = P.times = function (y, b) {\n var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,\n base, sqrtBase,\n x = this,\n xc = x.c,\n yc = (y = new BigNumber(y, b)).c;\n if (!xc || !yc || !xc[0] || !yc[0]) {\n if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {\n y.c = y.e = y.s = null;\n } else {\n y.s *= x.s;\n if (!xc || !yc) {\n y.c = y.e = null;\n } else {\n y.c = [0];\n y.e = 0;\n }\n }\n return y;\n }\n e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);\n y.s *= x.s;\n xcL = xc.length;\n ycL = yc.length;\n if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;\n for (i = xcL + ycL, zc = []; i--; zc.push(0));\n base = BASE;\n sqrtBase = SQRT_BASE;\n for (i = ycL; --i >= 0;) {\n c = 0;\n ylo = yc[i] % sqrtBase;\n yhi = yc[i] / sqrtBase | 0;\n for (k = xcL, j = i + k; j > i;) {\n xlo = xc[--k] % sqrtBase;\n xhi = xc[k] / sqrtBase | 0;\n m = yhi * xlo + xhi * ylo;\n xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;\n c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;\n zc[j--] = xlo % base;\n }\n zc[j] = c;\n }\n if (c) {\n ++e;\n } else {\n zc.splice(0, 1);\n }\n return normalise(y, zc, e);\n };\n\n P.negated = function () {\n var x = new BigNumber(this);\n x.s = -x.s || null;\n return x;\n };\n\n P.plus = function (y, b) {\n var t,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.minus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return new BigNumber(a / 0);\n if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (a > 0) {\n ye = xe;\n t = yc;\n } else {\n a = -a;\n t = xc;\n }\n t.reverse();\n for (; a--; t.push(0));\n t.reverse();\n }\n a = xc.length;\n b = yc.length;\n if (a - b < 0) t = yc, yc = xc, xc = t, b = a;\n for (a = 0; b;) {\n a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;\n xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;\n }\n if (a) {\n xc = [a].concat(xc);\n ++ye;\n }\n return normalise(y, xc, ye);\n };\n\n P.precision = P.sd = function (sd, rm) {\n var c, n, v,\n x = this;\n if (sd != null && sd !== !!sd) {\n intCheck(sd, 1, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), sd, rm);\n }\n if (!(c = x.c)) return null;\n v = c.length - 1;\n n = v * LOG_BASE + 1;\n if (v = c[v]) {\n for (; v % 10 == 0; v /= 10, n--);\n for (v = c[0]; v >= 10; v /= 10, n++);\n }\n if (sd && x.e + 1 > n) n = x.e + 1;\n return n;\n };\n P.shiftedBy = function (k) {\n intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);\n return this.times('1e' + k);\n };\n P.squareRoot = P.sqrt = function () {\n var m, n, r, rep, t,\n x = this,\n c = x.c,\n s = x.s,\n e = x.e,\n dp = DECIMAL_PLACES + 4,\n half = new BigNumber('0.5');\n if (s !== 1 || !c || !c[0]) {\n return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);\n }\n s = Math.sqrt(+valueOf(x));\n if (s == 0 || s == 1 / 0) {\n n = coeffToString(c);\n if ((n.length + e) % 2 == 0) n += '0';\n s = Math.sqrt(+n);\n e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);\n\n if (s == 1 / 0) {\n n = '1e' + e;\n } else {\n n = s.toExponential();\n n = n.slice(0, n.indexOf('e') + 1) + e;\n }\n r = new BigNumber(n);\n } else {\n r = new BigNumber(s + '');\n }\n if (r.c[0]) {\n e = r.e;\n s = e + dp;\n if (s < 3) s = 0;\n for (; ;) {\n t = r;\n r = half.times(t.plus(div(x, t, dp, 1)));\n if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {\n if (r.e < e) --s;\n n = n.slice(s - 3, s + 1);\n if (n == '9999' || !rep && n == '4999') {\n if (!rep) {\n round(t, t.e + DECIMAL_PLACES + 2, 0);\n\n if (t.times(t).eq(x)) {\n r = t;\n break;\n }\n }\n dp += 4;\n s += 4;\n rep = 1;\n } else {\n if (!+n || !+n.slice(1) && n.charAt(0) == '5') {\n round(r, r.e + DECIMAL_PLACES + 2, 1);\n m = !r.times(r).eq(x);\n }\n break;\n }\n }\n }\n }\n\n return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);\n };\n\n P.toExponential = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp++;\n }\n return format(this, dp, rm, 1);\n };\n\n P.toFixed = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp = dp + this.e + 1;\n }\n return format(this, dp, rm);\n };\n\n P.toFormat = function (dp, rm, format) {\n var str,\n x = this;\n\n if (format == null) {\n if (dp != null && rm && typeof rm == 'object') {\n format = rm;\n rm = null;\n } else if (dp && typeof dp == 'object') {\n format = dp;\n dp = rm = null;\n } else {\n format = FORMAT;\n }\n } else if (typeof format != 'object') {\n throw Error\n (bignumberError + 'Argument not an object: ' + format);\n }\n\n str = x.toFixed(dp, rm);\n\n if (x.c) {\n var i,\n arr = str.split('.'),\n g1 = +format.groupSize,\n g2 = +format.secondaryGroupSize,\n groupSeparator = format.groupSeparator || '',\n intPart = arr[0],\n fractionPart = arr[1],\n isNeg = x.s < 0,\n intDigits = isNeg ? intPart.slice(1) : intPart,\n len = intDigits.length;\n\n if (g2) i = g1, g1 = g2, g2 = i, len -= i;\n\n if (g1 > 0 && len > 0) {\n i = len % g1 || g1;\n intPart = intDigits.substr(0, i);\n for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);\n if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);\n if (isNeg) intPart = '-' + intPart;\n }\n\n str = fractionPart\n ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)\n ? fractionPart.replace(new RegExp('\\\\d{' + g2 + '}\\\\B', 'g'),\n '$&' + (format.fractionGroupSeparator || ''))\n : fractionPart)\n : intPart;\n }\n\n return (format.prefix || '') + str + (format.suffix || '');\n };\n\n P.toFraction = function (md) {\n var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,\n x = this,\n xc = x.c;\n\n if (md != null) {\n n = new BigNumber(md);\n if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {\n throw Error\n (bignumberError + 'Argument ' +\n (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));\n }\n }\n\n if (!xc) return new BigNumber(x);\n\n d = new BigNumber(ONE);\n n1 = d0 = new BigNumber(ONE);\n d1 = n0 = new BigNumber(ONE);\n s = coeffToString(xc);\n\n e = d.e = s.length - x.e - 1;\n d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];\n md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;\n\n exp = MAX_EXP;\n MAX_EXP = 1 / 0;\n n = new BigNumber(s);\n n0.c[0] = 0;\n\n for (; ;) {\n q = div(n, d, 0, 1);\n d2 = d0.plus(q.times(d1));\n if (d2.comparedTo(md) == 1) break;\n d0 = d1;\n d1 = d2;\n n1 = n0.plus(q.times(d2 = n1));\n n0 = d2;\n d = n.minus(q.times(d2 = d));\n n = d2;\n }\n\n d2 = div(md.minus(d0), d1, 0, 1);\n n0 = n0.plus(d2.times(n1));\n d0 = d0.plus(d2.times(d1));\n n0.s = n1.s = x.s;\n e = e * 2;\n\n r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(\n div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];\n MAX_EXP = exp;\n\n return r;\n };\n\n P.toNumber = function () {\n return +valueOf(this);\n };\n\n P.toPrecision = function (sd, rm) {\n if (sd != null) intCheck(sd, 1, MAX);\n return format(this, sd, rm, 2);\n };\n\n P.toString = function (b) {\n var str,\n n = this,\n s = n.s,\n e = n.e;\n\n if (e === null) {\n if (s) {\n str = 'Infinity';\n if (s < 0) str = '-' + str;\n } else {\n str = 'NaN';\n }\n } else {\n if (b == null) {\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(coeffToString(n.c), e)\n : toFixedPoint(coeffToString(n.c), e, '0');\n } else if (b === 10) {\n n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);\n str = toFixedPoint(coeffToString(n.c), n.e, '0');\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);\n }\n\n if (s < 0 && n.c[0]) str = '-' + str;\n }\n\n return str;\n };\n\n P.valueOf = P.toJSON = function () {\n return valueOf(this);\n };\n\n P._isBigNumber = true;\n if (typeof Symbol == 'function' && typeof Symbol.iterator == 'symbol') {\n P[Symbol.toStringTag] = 'BigNumber';\n P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;\n }\n if (configObject != null) BigNumber.set(configObject);\n return BigNumber;\n }\n\n function bitFloor(n) {\n var i = n | 0;\n return n > 0 || n === i ? i : i - 1;\n }\n\n function coeffToString(a) {\n var s, z,\n i = 1,\n j = a.length,\n r = a[0] + '';\n for (; i < j;) {\n s = a[i++] + '';\n z = LOG_BASE - s.length;\n for (; z--; s = '0' + s);\n r += s;\n }\n for (j = r.length; r.charCodeAt(--j) === 48;);\n return r.slice(0, j + 1 || 1);\n }\n\n function compare(x, y) {\n var a, b,\n xc = x.c,\n yc = y.c,\n i = x.s,\n j = y.s,\n k = x.e,\n l = y.e;\n if (!i || !j) return null;\n a = xc && !xc[0];\n b = yc && !yc[0];\n if (a || b) return a ? b ? 0 : -j : i;\n if (i != j) return i;\n a = i < 0;\n b = k == l;\n if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;\n if (!b) return k > l ^ a ? 1 : -1;\n j = (k = xc.length) < (l = yc.length) ? k : l;\n for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;\n return k == l ? 0 : k > l ^ a ? 1 : -1;\n }\n\n function intCheck(n, min, max, name) {\n if (n < min || n > max || n !== (n < 0 ? mathceil(n) : mathfloor(n))) {\n throw Error\n (bignumberError + (name || 'Argument') + (typeof n == 'number'\n ? n < min || n > max ? ' out of range: ' : ' not an integer: '\n : ' not a primitive number: ') + String(n));\n }\n }\n\n function isOdd(n) {\n var k = n.c.length - 1;\n return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;\n }\n\n function toExponential(str, e) {\n return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +\n (e < 0 ? 'e' : 'e+') + e;\n }\n\n function toFixedPoint(str, e, z) {\n var len, zs;\n if (e < 0) {\n for (zs = z + '.'; ++e; zs += z);\n str = zs + str;\n } else {\n len = str.length;\n if (++e > len) {\n for (zs = z, e -= len; --e; zs += z);\n str += zs;\n } else if (e < len) {\n str = str.slice(0, e) + '.' + str.slice(e);\n }\n }\n return str;\n }\n\n BigNumber = clone();\n BigNumber['default'] = BigNumber.BigNumber = BigNumber;\n if (typeof define == 'function' && define.amd) {\n define(function () { return BigNumber; });\n } else if (typeof module != 'undefined' && module.exports) {\n module.exports = BigNumber;\n } else {\n if (!globalObject) {\n globalObject = typeof self != 'undefined' && self ? self : window;\n }\n globalObject.BigNumber = BigNumber;\n }\n})(this);\n\n\nvar qq = readline().split(\" \").map(function(x) { return parseInt(x); });\n//var numbers = prompt(\"Enter data: \").split(\" \").map(function(x) { return parseInt(x); }); // Chrome run\n\nvar T = qq[0];\nfor (var i=0; i= s[1]) print ('NO');\n\telse {\n\t var first = s[0];\n\t s.shift();\n\t print ('YES');\n\t\tprint ('2');\n\t\tprint ( first, s.join(''));\n\t}\n}"}, {"source_code": "//var input = readline()\nvar test = parseInt(readline())\n\nwhile(test --) {\n var n = parseInt(readline())\n var str = readline()\n\n if(str.length == 2 && str[0] >= str[1]) print('NO')\n else {\n print('YES')\n print(2)\n write(str[0] +' ')\n write(str.slice(1) +' '+ '\\n')\n }\n}\n\n\n//"}, {"source_code": "'use strict';\nconst io = (function() {\n process.stdin.resume(); process.stdin.setEncoding('utf-8');\n let inputString = '', currentLine = 0, curTok = 0, input = [];\n function _check() { if (currentLine >= input.length) throw 'EOF!'; }\n process.stdin.on('data', data => { inputString += data; });\n process.stdin.on('end', _ => {\n for (const i of inputString.split('\\n')) { input.push(i.split(' ')); }\n main(); \n });\n function nextLine() {\n _check();\n const ret = input[currentLine++].slice(curTok).join(' ');\n curTok = 0;\n return ret;\n }\n function next() {\n _check();\n while (curTok == input[currentLine].length) {\n currentLine++;\n curTok = 0;\n _check()\n }\n return input[currentLine][curTok++];\n }\n function nextInt() { return parseInt(next()); }\n return {\n nextLine: nextLine,\n next: next,\n nextInt: nextInt,\n };\n})();\n\nconst deal = () => {\n const n = io.nextInt();\n let str = io.next();\n let f = str[0];\n let s = str.slice(1);\n if (n > 2 || Number(f) < Number(s)) {\n console.log(\"YES\");\n console.log(2);\n console.log(f + ' ' + s);\n } else {\n console.log(\"NO\");\n }\n};\n\nfunction main() {\n let q = io.nextInt();\n while (q > 0) {\n q--;\n deal();\n }\n}\n"}, {"source_code": "var x = readline();var res = [];\nfor(var i =0;i {\n return [s.slice(start, end), s.slice(end)];\n}\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n let [seg1, seg2] = cut(str, 0, str.length - 1);\n let ans = 'NO';\n let start = 0;\n let end = str.length - 1;\n\n while (seg1.length > 0) {\n if (BigInt(seg1) < BigInt(seg2)) {\n ans = 'YES';\n break;\n }\n\n end--;\n\n [seg1, seg2] = cut(str, start, end);\n }\n\n console.log(ans);\n if (ans === 'YES') {\n console.log(2);\n console.log(seg1, seg2);\n }\n\n c++;\n});\n"}], "negative_code": [{"source_code": "(function() {\n\n var q = +readline();\n var res = '';\n for(var i = 0; i < q; i++) {\n var s = readline();\n if(s.length == 1 || (s.length == 2 && +s[0] >= +s[1])) {\n res += 'NO\\n';\n }\n else {\n res += 'YES\\n2\\n'; \n res += s[0] + ' ' + s.slice(1) + '\\n'; \n }\n }\n print(res);\n}());\n\n\n"}, {"source_code": "//var input = readline()\nvar test = parseInt(readline())\n\nwhile(test --) {\n var n = parseInt(readline())\n var str = readline()\n\n if(str.length == 2 && str[0] >= str[1]) print('NO')\n else {\n print('YES')\n print(2)\n write(str[0] +' ')\n write(str.slice(1))\n }\n}\n\n\n//"}, {"source_code": "'use strict';\nconst io = (function() {\n process.stdin.resume(); process.stdin.setEncoding('utf-8');\n let inputString = '', currentLine = 0, curTok = 0, input = [];\n function _check() { if (currentLine >= input.length) throw 'EOF!'; }\n process.stdin.on('data', data => { inputString += data; });\n process.stdin.on('end', _ => {\n for (const i of inputString.split('\\n')) { input.push(i.split(' ')); }\n main(); \n });\n function nextLine() {\n _check();\n const ret = input[currentLine++].slice(curTok).join(' ');\n curTok = 0;\n return ret;\n }\n function next() {\n _check();\n while (curTok == input[currentLine].length) {\n currentLine++;\n curTok = 0;\n _check()\n }\n return input[currentLine][curTok++];\n }\n function nextInt() { return parseInt(next()); }\n return {\n nextLine: nextLine,\n next: next,\n nextInt: nextInt,\n };\n})();\n\nconst deal = () => {\n const n = io.nextInt();\n let str = io.next();\n let f = Number(str[0]);\n let s = Number(str.slice(1));\n if (f < s) {\n console.log(\"YES\");\n console.log(2);\n console.log(f + ' ' + s);\n } else {\n console.log(\"NO\");\n }\n};\n\nfunction main() {\n let q = io.nextInt();\n while (q > 0) {\n q--;\n deal();\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nconst cut = (s, start, end) => {\n return [s.slice(start, end), s.slice(end)];\n}\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n let [seg1, seg2] = cut(str, 0, str.length - 1);\n let ans = 'NO';\n let start = 0;\n let end = str.length - 1;\n\n while (seg1.length > 0) {\n if (BigInt(seg1) < BigInt(seg2)) {\n ans = 'YES';\n break;\n }\n\n end--;\n\n [seg1, seg2] = cut(str, start, end);\n }\n\n console.log(ans);\n if (ans === 'YES') {\n console.log(seg1, seg2);\n }\n\n c++;\n});\n"}], "src_uid": "9f87a89c788bd7c7b66e51db9fe47e46"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve(arr) {\r\n let res = true, del = 1\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] === del) {\r\n if (arr[i + 1] === del) del = 0\r\n }\r\n if (del === 0) {\r\n if (arr[i] === del) {\r\n if (arr[i + 1] === 0) res = false\r\n }\r\n }\r\n }\r\n res ? console.log('YES') : console.log('NO')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i].split('').map(j => +j))\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split('').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var a = readline()\r\n var array = []\r\n var array2 = []\r\n\r\n var index = a.length\r\n for (let i = 0; i < a.length - 1; i++) {\r\n if (a[i] === a[i + 1] && a[i + 1] === 1) {\r\n index = i + 1\r\n break\r\n }\r\n }\r\n\r\n var exist = false\r\n for (let i = index; i < a.length - 1; i++) {\r\n if (a[i] === a[i + 1] && a[i + 1] === 0) {\r\n exist = true\r\n break\r\n }\r\n }\r\n console.log(exist ? 'NO' : 'YES')\r\n });\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = next();\r\n\t\tvar L = -1;\r\n\t\tvar R = -1;\r\n\t\tfor(var j = 0; j < s.length - 1; j++){\r\n\t\t\tvar v = s[j] + s[j + 1];\r\n\t\t\tif(v == \"11\"){\r\n\t\t\t\tL = j;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = s.length - 2; j > 0; j--){\r\n\t\t\tvar v = s[j] + s[j + 1];\r\n\t\t\tif(v == \"00\"){\r\n\t\t\t\tR = j;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(L != -1 && R != -1 && L < R){\r\n\t\t\tmyout(\"NO\");\r\n\t\t}else{\r\n\t\t\tmyout(\"YES\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (s) => {\r\n let n = s.length;\r\n let idx;\r\n for (let i = 1; i < n; i++) {\r\n if (s[i - 1] == s[i] && s[i] == '1') {\r\n idx = i;\r\n break;\r\n }\r\n }\r\n for (let i = idx + 1; i < n; i++) {\r\n if (s[i - 1] == s[i] && s[i] == '0') {\r\n return pr('NO'); // check for \"1100\" existence, if exist, result is NO\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let n = arr.length;\r\n let ans = true;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (arr[i - 1] > arr[i]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) console.log(\"YES\");\r\n else {\r\n ans = true;\r\n let j = arr.indexOf(1);\r\n for (let i = j; i < n - 1; i++) {\r\n if (arr[i] === 1 && arr[i + 1] === 1) {\r\n i = i + 2;\r\n while (i < n - 1) {\r\n if (arr[i] === 0 && arr[i + 1] === 0) {\r\n ans = false;\r\n break;\r\n }\r\n i++;\r\n }\r\n break;\r\n }\r\n }\r\n ans = ans === true ? \"YES\" : \"NO\";\r\n console.log(ans);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n // var a = readline().split('').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline()\r\n\r\n if (a.includes('1100') || a.includes('110100')) return console.log('NO')\r\n console.log('YES')\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n // var a = readline().split('').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline()\r\n\r\n if (a.includes('1100')) return console.log('NO')\r\n console.log('YES')\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var [n, k1, k2] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n // var a = readline().split('').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline()\r\n\r\n if (a.includes('0011') || a.includes('1100')) return console.log('NO')\r\n console.log('YES')\r\n });\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = next();\r\n\t\tif(s.length <= 3){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < s.length - 3; j++){\r\n\t\t\tif(s[j] == s[j + 1] && s[j + 2] == s[j + 3] && s[j + 1] == \"1\" && s[j + 2] == \"0\"){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = next();\r\n\t\tif(s.length <= 3){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < s.length - 3; j++){\r\n\t\t\tif(s[j] == s[j + 1] && s[j + 2] == s[j + 3] && s[j + 1] != s[j + 2]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (s) => {\r\n let n = s.length;\r\n let idx;\r\n for (let i = 1; i < n; i++) {\r\n if (s[i - 1] == s[i] && s[i] == '1') {\r\n idx = i;\r\n }\r\n }\r\n for (let i = idx + 1; i < n; i++) {\r\n if (s[i - 1] == s[i] && s[i] == '0') {\r\n return pr('NO'); // check for \"1100\" existence, if exist, result is NO\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (s) => {\r\n let n = s.length;\r\n let zero = new Set();\r\n let one = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == '0') {\r\n if (zero.has(i - 1) && one.size > 0) {\r\n return pr('NO');\r\n }\r\n zero.add(i);\r\n } else {\r\n one.add(i);\r\n }\r\n }\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "357dcc8fb7783d878cd2c4ed34eb437e"} {"source_code": "var n, l1, l2, sz1, sz2;\n\nfunction add1(val) {\n ++sz1;\n l1+=\" \";\n l1+=val;\n}\n\nfunction add2(val) {\n ++sz2;\n l2+=\" \";\n l2+=val;\n}\n\nvar i;\n\nn = parseInt(readline());\n\nif(n==1 || n==2) {\n print(\"No\");\n}\n\nelse {\n print(\"Yes\");\n\n l1 = \"\";\n l2 = \"\";\n\n sz1 = 0;\n sz2 = 0;\n\n if(n%2==0) {\n add1(1);\n add1(n);\n \n for(i=2;i>0);\n l2+=n-((n/2)>>0);\n\n for(i=1;i<=n;i++) {\n if(i%2==0) {\n l1+=\" \";\n l1+=i;\n }\n else {\n l2+=\" \";\n l2+=i;\n }\n }\n\n print(l1);\n print(l2);\n}\n"}], "src_uid": "bb7bace930d5c5f231bfc2061576ec45"} {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var a;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var ans = 'YES';\r\n\r\n var index = 0;\r\n for (var i = 0; i < n-1; i++) {\r\n index = i;\r\n if (a[i] > a[i+1]) {\r\n break;\r\n }\r\n }\r\n index++;\r\n while (index < n-1) {\r\n if (a[index] < a[index+1]) {\r\n ans = 'NO'\r\n break;\r\n }\r\n index++;\r\n }\r\n print(ans);\r\n }", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = parseInt(readline(), 10);\r\n const arr = readline().split(' ').map(Number);\r\n const max = Math.max(...arr);\r\n const maxIndex = arr.findIndex(el => el === max);\r\n\r\n let yes = true;\r\n for (let i = 1; i < n; i++) {\r\n if (i <= maxIndex) {\r\n if (arr[i] < arr[i - 1]) {\r\n yes = false;\r\n break;\r\n }\r\n } else {\r\n if (arr[i] > arr[i - 1]) {\r\n yes = false;\r\n break;\r\n }\r\n }\r\n }\r\n \r\n output(yes ? 'YES' : 'NO');\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "c35d309dd6a9569ec298e7128aa3fc0e"} {"source_code": "var b = readline().trim();\nvar nbrOpen = 0;\nvar ans = 0;\nfor (var i = 0; i < b.length; i++) {\n\tif(b[i]==')'){\n\t\tif(nbrOpen==0){\n\t\t\tans++;\n\t\t\tcontinue;\n\t\t}else{\n\t\t\tnbrOpen--;\n\t\t}\n\t}else{\n\t\tnbrOpen++;\n\t}\n}\nans+=nbrOpen\n\nprint(b.length-ans);", "positive_code": [{"source_code": "'use strict'\n\nlet ss = readline()\n\nlet z = 0\nlet r = 0\n\nfor (let i = 0; i < ss.length; i++) {\n if (ss[i] == '(') {z++} else\n if (ss[i] == ')') {z--}\n if (z < 0) {r++; z = 0}\n}\n\nr += z\n\nprint(ss.length - r)"}], "negative_code": [], "src_uid": "2ce2d0c4ac5e630bafad2127a1b589dd"} {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N;\r\n let K;\r\n let str;\r\n\r\n while (T--) {\r\n [N, K] = lines[index++].split(' ').map(Number);\r\n str = lines[index++];\r\n\r\n solve(N, K, str);\r\n }\r\n}\r\n\r\nfunction solve(N, K, str) {\r\n const map = new Map();\r\n let evenCount = 0;\r\n let value;\r\n let result;\r\n\r\n for (const char of str) {\r\n value = map.get(char) || 0;\r\n map.set(char, value + 1);\r\n }\r\n\r\n Array.from(map.values()).forEach((val) => {\r\n if (val % 2 === 0) {\r\n evenCount += val;\r\n } else {\r\n evenCount += val - 1;\r\n }\r\n });\r\n\r\n result = Math.floor(evenCount / K);\r\n\r\n if ((N - result * K) >= K && result % 2 === 0) {\r\n result++;\r\n }\r\n\r\n console.log(result);\r\n}", "positive_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, k] = ra();\n let s = readline();\n let cnt = {};\n for (let i=0; i>1;\n }\n if (ki=2 && ki=k)\n i++\n return i;\n};\n "}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst BASE = 'a'.charCodeAt(0);\r\nlet n;\r\nlet k;\r\nlet s;\r\nfunction solve() {\r\n const cnt = af(26).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let c = s.charCodeAt(i) - BASE;\r\n cnt[c]++;\r\n }\r\n // console.log(cnt);\r\n let ans = 0;\r\n while (true) {\r\n let has = 0;\r\n for (let i = 0; i < 26; i++) {\r\n if (cnt[i] >= 2) {\r\n has += cnt[i] - (cnt[i] % 2);\r\n }\r\n }\r\n if (has < 2 * k) {\r\n break;\r\n }\r\n ans += 2;\r\n let got = 0;\r\n for (let i = 0; got < k && i < 26; i++) {\r\n while (got < k && cnt[i] >= 2) {\r\n cnt[i] -= 2;\r\n got++;\r\n }\r\n }\r\n check(got == k);\r\n }\r\n while (true) {\r\n let has = 0;\r\n for (let i = 0; i < 26; i++) {\r\n if (cnt[i] > 0) {\r\n has += cnt[i];\r\n }\r\n }\r\n if (has < k) {\r\n break;\r\n }\r\n ans++;\r\n break;\r\n }\r\n return ans;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n s = nextStr();\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\npalindromeColoring = (s, k)=>{\r\n\r\n let map = new Map();\r\n for(let el of s){\r\n if(map.has(el)){\r\n map.set(el, map.get(el)+1)\r\n }\r\n else{\r\n map.set(el, 1);\r\n }\r\n }\r\n\r\n let values = Array.from(map.values());\r\n \r\n let totalPairs = 0;\r\n for(let i =0; i=k){\r\n console.log(perBucket*2 + 1);\r\n }\r\n else{\r\n console.log(perBucket*2)\r\n }\r\n \r\n \r\n}\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n\r\n const s = readline();\r\n\r\n\r\n palindromeColoring(s,k);\r\n }\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst fq = new Map();\r\n\t\tfor (const c of s) {\r\n\t\t\tfq.set(c, fq.has(c) ? fq.get(c) + 1 : 1);\r\n\t\t}\r\n\r\n\t\tlet pairs = 0;\r\n\t\tfor (const cnt of fq.values()) {\r\n\t\t\tpairs += Math.floor(cnt/2);\r\n\t\t}\r\n\r\n\t\tlet ans = Math.floor(pairs/k)*2;\r\n\t\tans += n - ans*k >= k;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, k, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, str) {\n const count = Array(26).fill(0)\n for (let i = 0; i < str.length; i++) {\n const idx = str.charCodeAt(i) - 'a'.charCodeAt(0)\n count[idx]++\n }\n let odd = 0\n let even = 0\n for (let i = 0; i < count.length; i++) {\n if (count[i] & 1) {\n even += count[i] - 1\n odd++\n } else {\n even += count[i]\n }\n }\n return binarySearch(1, Math.floor(n / k), x => {\n if (x & 1) {\n return even >= (x - 1) * k\n } else {\n return even >= x * k\n }\n })\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nconst readInt = async function(){\r\n return parseInt(await getLine());\r\n}\r\n\r\nconst readIntArray = async function() {\r\n return (await getLine()).split(' ').map(num => parseInt(num));\r\n}\r\n\r\nlet solve = async () => {\r\n const tsc = await readInt();\r\n for(let sc = 0; sc < tsc; sc++) {\r\n const [n,k] = await readIntArray();\r\n const a = (await getLine()).split('').map(c => c.charCodeAt(0));\r\n a.sort((a,b) => (a - b));\r\n let ones = 0;\r\n let pairs = 0;\r\n let i,j;\r\n\r\n for(i = 0; i < a.length; i=j) {\r\n for(j = i+1; j= k) {\r\n res++;\r\n }\r\n console.log(res);\r\n\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var n = inp[0];\r\n var k = inp[1];\r\n var s = readline();\r\n\r\n var mp = {};\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (mp.hasOwnProperty(s[i])) {\r\n mp[s[i]]++;\r\n } else {\r\n mp[s[i]] = 1;\r\n }\r\n }\r\n var p = 0,\r\n ind = 0;\r\n\r\n for (var i in mp) {\r\n var x = mp[i];\r\n p += Math.floor(x / 2);\r\n ind += x % 2;\r\n }\r\n var ans = Math.floor(p / k);\r\n ind += (p % k) * 2;\r\n ans *= 2;\r\n if (ind >= k) ans++;\r\n\r\n return ans;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}], "negative_code": [{"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N;\r\n let K;\r\n let str;\r\n\r\n while (T--) {\r\n [N, K] = lines[index++].split(' ').map(Number);\r\n str = lines[index++];\r\n\r\n solve(N, K, str);\r\n }\r\n}\r\n\r\nfunction solve(N, K, str) {\r\n const map = new Map();\r\n let evenCount = 0;\r\n let oddCount = 0;\r\n let value;\r\n let result;\r\n\r\n for (const char of str) {\r\n value = map.get(char) || 0;\r\n map.set(char, value + 1);\r\n }\r\n\r\n Array.from(map.values()).forEach((val) => {\r\n if (val % 2 === 0) {\r\n evenCount += val;\r\n } else {\r\n evenCount += val - 1;\r\n oddCount++;\r\n }\r\n });\r\n\r\n result = Math.floor(evenCount / K);\r\n\r\n if (oddCount >= K && result % 2 === 0) {\r\n result++;\r\n }\r\n\r\n console.log(Math.max(result, 1));\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N;\r\n let K;\r\n let str;\r\n\r\n while (T--) {\r\n [N, K] = lines[index++].split(' ').map(Number);\r\n str = lines[index++];\r\n\r\n solve(N, K, str);\r\n }\r\n}\r\n\r\nfunction solve(N, K, str) {\r\n const map = new Map();\r\n let evenCount = 0;\r\n let oddCount = 0;\r\n let value;\r\n let result;\r\n\r\n for (const char of str) {\r\n value = map.get(char) || 0;\r\n map.set(char, value + 1);\r\n }\r\n\r\n Array.from(map.values()).forEach((val) => {\r\n if (val % 2 === 0) {\r\n evenCount += val;\r\n } else {\r\n oddCount += val;\r\n }\r\n });\r\n\r\n result = Math.floor(evenCount / K);\r\n\r\n if (oddCount >= K && result % 2 === 0) {\r\n result++;\r\n }\r\n\r\n console.log(Math.max(result, 1));\r\n}\r\n"}], "src_uid": "ca817fe0a97e2d8a6bcfcb00103b6b6d"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n const str = lines[l++]\n output[i] = solve(n, m, arr, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, arr, str) {\n const map = {}\n arr.forEach((s, j) => {\n for (let i = 0; i < s.length; i++) {\n if (i + 1 < s.length) {\n const x = s.slice(i, i + 1 + 1)\n map[x] = [i + 1, i + 2, j + 1]\n }\n if (i + 2 < s.length) {\n const x = s.slice(i, i + 2 + 1)\n map[x] = [i + 1, i + 3, j + 1]\n }\n }\n })\n const dp = []\n dp[0] = []\n dp[1] = null\n for (let i = 2; i <= str.length; i++) {\n const a1 = dp[i - 2]\n const a2 = map[str.slice(i - 2, i)]\n if (a1 && a2) {\n dp[i] = 2\n continue\n }\n const b1 = i - 3 >= 0 ? dp[i - 3] : null\n const b2 = map[str.slice(i - 3, i)]\n if (b1 && b2) {\n dp[i] = 3\n continue\n }\n dp[i] = null\n }\n // console.log(dp)\n if (!dp[m]) return -1\n let x = m\n const ans = []\n dp[0] = null // tricky\n while (dp[x]) {\n // console.log(x)\n ans.unshift(map[str.slice(x - dp[x], x)])\n x -= dp[x]\n }\n return ans.length + '\\n' + ans.map(r => r.join(' ')).join('\\n')\n}\n", "positive_code": [{"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n \r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = false;\r\n if(!c1 )\r\n c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n \r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, m] = rna();\r\n\t\tconst known = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tknown[i] = rl();\r\n\t\t}\r\n\t\tconst s = rl();\r\n\r\n\t\tconst avl = new Map();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst ph = known[i];\r\n\t\t\tfor (let j = 0; j < m; j++) {\r\n\t\t\t\tj+2 <= m && avl.set(ph.substr(j, 2), [j+1, j+2, i+1]);\r\n\t\t\t\tj+3 <= m && avl.set(ph.substr(j, 3), [j+1, j+3, i+1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst dp = Array(n);\r\n\t\tdp[-1] = dp[-2] = true;\r\n\t\tfor (let i = 1; i < m; i++) {\r\n\t\t\tconst sx2 = s.substr(i-1, 2);\r\n\t\t\tconst sx3 = s.substr(i-2, 3);\r\n\r\n\t\t\tif (dp[i-2] && avl.has(sx2)) {\r\n\t\t\t\tdp[i] = 2;\r\n\t\t\t} else if (dp[i-3] && avl.has(sx3)) {\r\n\t\t\t\tdp[i] = 3;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (dp[m-1]) {\r\n\t\t\tconst ans = [];\r\n\t\t\tlet i = m - 1;\r\n\t\t\twhile (i >= 0) {\r\n\t\t\t\tconst sx = s.substr(i-dp[i]+1, dp[i]);\r\n\t\t\t\tans.push(avl.get(sx));\r\n\t\t\t\ti -= dp[i];\r\n\t\t\t}\r\n\t\t\tans.reverse();\r\n\r\n\t\t\tconsole.log(ans.length);\r\n\t\t\tfor (const ln of ans) {\r\n\t\t\t\tconsole.log(ln.join(' '));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N, M;\r\n let arr, str;\r\n\r\n while (T--) {\r\n [N, M] = lines[index++].split(' ').map(Number);\r\n arr = new Array(N);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n arr[i] = lines[index++];\r\n }\r\n\r\n str = lines[index++];\r\n\r\n solve(N, M, arr, str);\r\n }\r\n}\r\n\r\nfunction solve(N, M, arr, str) {\r\n const map = new Map();\r\n const darr = new Array(M + 1).fill('');\r\n const solution = [];\r\n let index;\r\n let curStr;\r\n let strLength2;\r\n let strLength3;\r\n\r\n // base set with sequences of length 2 and 3\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < M; ++j) {\r\n strLength2 = arr[i][j] + arr[i][j + 1];\r\n strLength3 = strLength2 + arr[i][j + 2];\r\n\r\n if (strLength2.length === 2) {\r\n map.set(strLength2, [j + 1, j + 2, i + 1]);\r\n }\r\n\r\n if (strLength3.length === 3) {\r\n map.set(strLength3, [j + 1, j + 3, i + 1]);\r\n }\r\n }\r\n }\r\n\r\n curStr = '';\r\n\r\n for (let i = 1; i <= M; ++i) {\r\n curStr += str[i - 1];\r\n strLength2 = str[i - 2] + str[i - 1];\r\n strLength3 = str[i - 3] + strLength2;\r\n\r\n strLength2 = (map.has(strLength2) && strLength2) || '';\r\n strLength3 = (map.has(strLength3) && strLength3) || '';\r\n\r\n if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {\r\n darr[i] = curStr;\r\n }\r\n }\r\n\r\n if (!darr[M]) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n index = M;\r\n\r\n while (index > 0) {\r\n strLength2 = str[index - 2] + str[index - 1];\r\n strLength3 = str[index - 3] + strLength2;\r\n\r\n if ((darr[index - 3] || darr[index] === strLength3) && map.has(strLength3)) {\r\n solution.push(map.get(strLength3));\r\n index -= 3;\r\n } else {\r\n solution.push(map.get(strLength2));\r\n index -= 2;\r\n }\r\n }\r\n\r\n solution.reverse();\r\n\r\n console.log(solution.length);\r\n for (let i = 0; i < solution.length; ++i) {\r\n console.log(solution[i].join(' '));\r\n }\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N, M;\r\n let arr, str;\r\n\r\n while (T--) {\r\n [N, M] = lines[index++].split(' ').map(Number);\r\n arr = new Array(N);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n arr[i] = lines[index++];\r\n }\r\n\r\n str = lines[index++];\r\n\r\n solve(N, M, arr, str);\r\n }\r\n}\r\n\r\nfunction solve(N, M, arr, str) {\r\n const map = new Map();\r\n const darr = new Array(M + 1).fill('');\r\n const solution = [];\r\n let index;\r\n let curStr;\r\n let strLength2;\r\n let strLength3;\r\n\r\n // base set with sequences of length 2 and 3\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < M; ++j) {\r\n strLength2 = arr[i][j] + arr[i][j + 1];\r\n strLength3 = strLength2 + arr[i][j + 2];\r\n\r\n if (strLength2.length === 2) {\r\n map.set(strLength2, [j + 1, j + 2, i + 1]);\r\n }\r\n\r\n if (strLength3.length === 3) {\r\n map.set(strLength3, [j + 1, j + 3, i + 1]);\r\n }\r\n }\r\n }\r\n\r\n curStr = '';\r\n\r\n for (let i = 1; i <= M; ++i) {\r\n curStr += str[i - 1];\r\n strLength2 = str[i - 2] + str[i - 1];\r\n strLength3 = str[i - 3] + strLength2;\r\n\r\n strLength2 = (map.has(strLength2) && strLength2) || '';\r\n strLength3 = (map.has(strLength3) && strLength3) || '';\r\n\r\n if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {\r\n darr[i] = curStr;\r\n }\r\n }\r\n\r\n if (!darr[M]) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n index = M;\r\n\r\n while (index > 0) {\r\n strLength2 = str[index - 2] + str[index - 1];\r\n strLength3 = str[index - 3] + strLength2;\r\n\r\n if ((darr[index - 3] || darr[index] === strLength3) && map.has(strLength3)) {\r\n solution.push(map.get(strLength3));\r\n index -= 3;\r\n } else {\r\n solution.push(map.get(strLength2));\r\n index -= 2;\r\n }\r\n }\r\n\r\n solution.reverse();\r\n\r\n console.log(solution.length);\r\n\r\n for (let i = 0; i < solution.length; ++i) {\r\n console.log(solution[i].join(' '));\r\n }\r\n}"}], "negative_code": [{"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N, M;\r\n let arr, str;\r\n\r\n while (T--) {\r\n [N, M] = lines[index++].split(' ').map(Number);\r\n arr = new Array(N);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n arr[i] = lines[index++];\r\n }\r\n\r\n str = lines[index++];\r\n\r\n solve(N, M, arr, str);\r\n }\r\n}\r\n\r\nfunction solve(N, M, arr, str) {\r\n const map = new Array(1000);\r\n const darr = new Array(M + 1).fill('');\r\n const solution = [];\r\n let index;\r\n let curStr;\r\n let strLength2;\r\n let strLength3;\r\n\r\n // base set with sequences of length 2 and 3\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < M; ++j) {\r\n strLength2 = arr[i][j] + arr[i][j + 1];\r\n strLength3 = strLength2 + arr[i][j + 2];\r\n\r\n if (strLength2.length === 2) {\r\n map[Number(strLength2)] = [j + 1, j + 2, i + 1];\r\n }\r\n\r\n if (strLength3.length === 3) {\r\n map[Number(strLength3)] = [j + 1, j + 3, i + 1];\r\n }\r\n }\r\n }\r\n\r\n curStr = '';\r\n\r\n for (let i = 1; i <= M; ++i) {\r\n curStr += str[i - 1];\r\n strLength2 = str[i - 2] + str[i - 1];\r\n strLength3 = str[i - 3] + strLength2;\r\n\r\n strLength2 = (map[Number(strLength2)] && strLength2) || '';\r\n strLength3 = (map[Number(strLength3)] && strLength3) || '';\r\n\r\n if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {\r\n darr[i] = curStr;\r\n }\r\n }\r\n\r\n if (!darr[M]) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n index = M;\r\n\r\n while (index > 0) {\r\n strLength2 = str[index - 2] + str[index - 1];\r\n strLength3 = str[index - 3] + strLength2;\r\n\r\n if ((darr[index - 3] || darr[index] === strLength3) && map[Number(strLength3)]) {\r\n solution.push(map[Number(strLength3)]);\r\n index -= 3;\r\n } else {\r\n solution.push(map[Number(strLength2)]);\r\n index -= 2;\r\n }\r\n }\r\n\r\n solution.reverse();\r\n\r\n console.log(solution.length);\r\n\r\n for (let i = 0; i < solution.length; ++i) {\r\n console.log(solution[i].join(' '));\r\n }\r\n}"}, {"source_code": "/*\r\n===== READ INPUT DATA START =====\r\n=================================\r\n*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n const lines = inputString.trim().split('\\n').map((string) => string.trim()).filter(Boolean);\r\n main(lines);\r\n});\r\n\r\n/*\r\n===== READ INPUT DATA END =====\r\n===============================\r\n*/\r\n\r\nfunction main(lines) {\r\n let index = 0;\r\n let T = Number(lines[index++]);\r\n let N, M;\r\n let arr, str;\r\n\r\n while (T--) {\r\n [N, M] = lines[index++].split(' ').map(Number);\r\n arr = new Array(N);\r\n\r\n for (let i = 0; i < N; ++i) {\r\n arr[i] = lines[index++];\r\n }\r\n\r\n str = lines[index++];\r\n\r\n solve(N, M, arr, str);\r\n }\r\n}\r\n\r\nfunction solve(N, M, arr, str) {\r\n const map = new Array(1000);\r\n const darr = new Array(M + 1).fill('');\r\n const solution = [];\r\n let index;\r\n let curStr;\r\n let strLength2;\r\n let strLength3;\r\n\r\n // base set with sequences of length 2 and 3\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < M; ++j) {\r\n strLength2 = arr[i][j] + arr[i][j + 1];\r\n strLength3 = strLength2 + arr[i][j + 2];\r\n\r\n if (strLength2.length === 2) {\r\n map[Number(strLength2)] = [j + 1, j + 2, i + 1];\r\n }\r\n\r\n if (strLength3.length === 3) {\r\n map[Number(strLength3)] = [j + 1, j + 2, i + 1];\r\n }\r\n }\r\n }\r\n\r\n curStr = '';\r\n\r\n for (let i = 1; i <= M; ++i) {\r\n curStr += str[i - 1];\r\n strLength2 = str[i - 2] + str[i - 1];\r\n strLength3 = str[i - 3] + strLength2;\r\n\r\n strLength2 = (map[Number(strLength2)] && strLength2) || '';\r\n strLength3 = (map[Number(strLength3)] && strLength3) || '';\r\n\r\n if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {\r\n darr[i] = curStr;\r\n }\r\n }\r\n\r\n if (!darr[M]) {\r\n console.log('-1');\r\n return;\r\n }\r\n\r\n index = M;\r\n\r\n while (index > 0) {\r\n strLength2 = str[index - 2] + str[index - 1];\r\n strLength3 = str[index - 3] + strLength2;\r\n\r\n if ((darr[index - 3] || darr[index] === strLength3) && map[Number(strLength3)]) {\r\n solution.push(map[Number(strLength3)]);\r\n index -= 3;\r\n } else {\r\n solution.push(map[Number(strLength2)]);\r\n index -= 2;\r\n }\r\n }\r\n\r\n solution.reverse();\r\n\r\n console.log(solution.length);\r\n\r\n for (let i = 0; i < solution.length; ++i) {\r\n console.log(solution[i].join(' '));\r\n }\r\n}"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n \r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n \r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n \r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n \r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i a[2] - b[2]);\r\n console.log(solution.length)\r\n for(let j = 0; j< solution.length; ++j){\r\n console.log(...solution[j]);\r\n }\r\n }\r\n else{\r\n console.log(-1)\r\n }\r\n readline();\r\n \r\n }\r\n}\r\n"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i a[2] - b[2]);\r\n console.log(solution.length)\r\n for(let j = 0; j< solution.length; ++j){\r\n console.log(solution[j]);\r\n }\r\n }\r\n else{\r\n console.log(-1)\r\n }\r\n readline();\r\n\r\n }\r\n}"}, {"source_code": "/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nlet map = null;\r\nlet s = null;\r\nlet arr = null;\r\nlet solution = []\r\nfunction main() {\r\n const mashaForgetul = (i)=>{\r\n if(i >= s.length){\r\n return true;\r\n }\r\n if(arr[i]!= -1) return arr[i];\r\n let s1 = s.substring(i, i+2);\r\n let s2 = s.substring(i, i+3);\r\n \r\n let c1 = map.has(s1) && mashaForgetul(i+2);\r\n let c2 = map.has(s2) && mashaForgetul(i+3);\r\n \r\n if(c2 ){\r\n let val = map.get(s2);\r\n solution.push([...val])\r\n }\r\n else{\r\n if(c1){\r\n let val = map.get(s1);\r\n solution.push([...val])\r\n }\r\n }\r\n arr[i] = c1||c2;\r\n \r\n return c1 || c2;\r\n }\r\n //take input according to the format;\r\n const t = +(readline());\r\n readline();\r\n for(let i =0; i {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n matrix.push(d.split(''));\n\n c++;\n});\n\nrl.on('close', () => {\n let width = 1;\n let height = 1;\n let x, y;\n\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'B') {\n x = j;\n y = i;\n\n while (matrix[i] && matrix[i][j] === 'B') {\n if (matrix[i][j + 1] === 'B') {\n width++;\n j++;\n }\n else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {\n height++;\n i++;\n }\n else {\n j++;\n i++;\n }\n }\n\n break;\n }\n }\n }\n\n console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));\n});\n", "positive_code": [{"source_code": "var opt = readline().split(' ');\nvar row = parseInt(opt[0]);\nvar column = parseInt(opt[1]);\nvar squareMassive=[];\nsquareMassive.length = row;\n\nfunction findCentre(row,column)\n{\n for(var i=0;i 0 && arr[i][j-1] === \"B\" && edjeX2 === parseInt(k) - 1) {\n edjeX2 = j;\n }\n if (arr[i][j] === \"B\" && edjeY1 === 0) {\n edjeY1 = i + 1;\n }\n if (arr[i][j] === \"W\" && i > 0 && arr[i-1][j] === \"B\" && edjeY2 === parseInt(n) - 1) {\n edjeY2 = i;\n }\n }\n }\n return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar H = one[0];\n\tvar W = one[1];\n\tvar list = new Array(H);\n\tfor(var i = 0; i < H; i++){\n\t\tlist[i] = nextCharArray();\n\t}\n\tfor(var i = 0; i < H; i++){\n\t\tfor(var j = 0; j < W; j++){\n\t\t\tif(list[i][j] == \"B\"){\n\t\t\t\tvar add = -1;\n\t\t\t\tfor(var k = 0; k < Math.min(H, W); k++){\n\t\t\t\t\ttry{\n\t\t\t\t\t\tif(list[i + k][j + k] == \"B\"){\n\t\t\t\t\t\t\tadd++;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}catch(e){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tadd = Math.ceil(add / 2);\n\t\t\t\tmyout((i + 1 + add) + \" \" + (j + 1 + add));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst matrix = [];\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n matrix.push(d.split(''));\n\n c++;\n});\n\nrl.on('close', () => {\n const idxTop = [];\n const idxBottom = [];\n\n isDone:\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'B') {\n idxTop.push(i + 1, j + 1);\n break isDone;\n }\n }\n }\n\n isDone:\n for (let i = matrix.length - 1; i >= 0; i--) {\n for (let j = matrix[i].length - 1; j >= 0; j--) {\n if (matrix[i][j] === 'B') {\n idxBottom.push(i + 1, j + 1);\n break isDone;\n }\n }\n }\n\n const y = (idxTop[0] + idxBottom[0]) / 2;\n const x = (idxTop[1] + idxBottom[1]) / 2;\n\n console.log(y, x);\n\n // let width = 1;\n // let height = 1;\n // let x, y;\n\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // x = j;\n // y = i;\n\n // while (matrix[i] && matrix[i][j] === 'B') {\n // if (matrix[i][j + 1] === 'B') {\n // width++;\n // j++;\n // }\n // else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {\n // height++;\n // i++;\n // }\n // else {\n // j++;\n // i++;\n // }\n // }\n\n // break;\n // }\n // }\n // }\n\n // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst matrix = [];\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n matrix.push(d.split(''));\n\n c++;\n});\n\nrl.on('close', () => {\n let x = 0;\n let y = 0;\n let cnt = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'B') {\n x += j;\n y += i;\n cnt++;\n }\n }\n }\n\n console.log(y / cnt + 1, x / cnt + 1);\n\n // let minX = Infinity;\n // let maxX = -Infinity;\n // let minY = Infinity;\n // let maxY = -Infinity;\n\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // minX = Math.min(minX, j);\n // maxX = Math.max(maxX, j);\n // minY = Math.min(minY, i);\n // maxY = Math.max(maxY, i);\n // }\n // }\n // }\n\n // console.log((minY + maxY) / 2 + 1, (minX + maxX) / 2 + 1);\n ////////////////////////////////////////////\n\n // const idxTop = [];\n // const idxBottom = [];\n\n // isDone: {\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // idxTop.push(i + 1, j + 1);\n // break isDone;\n // }\n // }\n // }\n // }\n\n // isDone: {\n // for (let i = matrix.length - 1; i >= 0; i--) {\n // for (let j = matrix[i].length - 1; j >= 0; j--) {\n // if (matrix[i][j] === 'B') {\n // idxBottom.push(i + 1, j + 1);\n // break isDone;\n // }\n // }\n // }\n // }\n\n // const y = (idxTop[0] + idxBottom[0]) / 2;\n // const x = (idxTop[1] + idxBottom[1]) / 2;\n\n // console.log(y, x);\n //////////////////////////////////////\n\n // let width = 1;\n // let height = 1;\n // let x, y;\n\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // x = j;\n // y = i;\n\n // while (matrix[i] && matrix[i][j] === 'B') {\n // if (matrix[i][j + 1] === 'B') {\n // width++;\n // j++;\n // }\n // else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {\n // height++;\n // i++;\n // }\n // else {\n // j++;\n // i++;\n // }\n // }\n\n // break;\n // }\n // }\n // }\n\n // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst matrix = [];\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, m] = d.split(' ').map(Number);\n return;\n }\n\n matrix.push(d.split(''));\n\n c++;\n});\n\nrl.on('close', () => {\n let minX = Infinity;\n let maxX = -Infinity;\n let minY = Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[i].length; j++) {\n if (matrix[i][j] === 'B') {\n minX = Math.min(minX, j);\n maxX = Math.max(maxX, j);\n minY = Math.min(minY, i);\n maxY = Math.max(maxY, i);\n }\n }\n }\n\n console.log((minY + maxY) / 2 + 1, (minX + maxX) / 2 + 1);\n\n // const idxTop = [];\n // const idxBottom = [];\n\n // isDone: {\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // idxTop.push(i + 1, j + 1);\n // break isDone;\n // }\n // }\n // }\n // }\n\n // isDone: {\n // for (let i = matrix.length - 1; i >= 0; i--) {\n // for (let j = matrix[i].length - 1; j >= 0; j--) {\n // if (matrix[i][j] === 'B') {\n // idxBottom.push(i + 1, j + 1);\n // break isDone;\n // }\n // }\n // }\n // }\n\n // const y = (idxTop[0] + idxBottom[0]) / 2;\n // const x = (idxTop[1] + idxBottom[1]) / 2;\n\n // console.log(y, x);\n //////////////////////////////////////\n\n // let width = 1;\n // let height = 1;\n // let x, y;\n\n // for (let i = 0; i < matrix.length; i++) {\n // for (let j = 0; j < matrix[i].length; j++) {\n // if (matrix[i][j] === 'B') {\n // x = j;\n // y = i;\n\n // while (matrix[i] && matrix[i][j] === 'B') {\n // if (matrix[i][j + 1] === 'B') {\n // width++;\n // j++;\n // }\n // else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {\n // height++;\n // i++;\n // }\n // else {\n // j++;\n // i++;\n // }\n // }\n\n // break;\n // }\n // }\n // }\n\n // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));\n});\n"}, {"source_code": "n = readline().split(' ').map(Number)[0]\nr1 = r2 = c = -1\nfor (i = 0; i < n; i++) {\n\ta = readline()\n\tif (a.includes('B')) {\n\t\tif (r1==-1) r1 = i\n\t\tr2 = i\n\t\tc = (a.lastIndexOf('B')+a.indexOf('B'))/2\n\t}\n}\nprint((r1+r2)/2+1, c+1)\n"}, {"source_code": "a=readline().split(\" \").map(Number) ;\nn=a[0];\nm=a[1];\nx2=0;\nx1=500;\ny1=500 ;\ny2=0 ;\n\nfor(i=0;ii)\n x1=i ;\n if(y1>j)\n y1=j ;\n if(x2 0 && arr[i][j-1] === \"B\" && edjeX2 === parseInt(k) - 1) {\n edjeX2 = j;\n }\n if (arr[i][j] === \"B\" && edjeY1 === 0) {\n edjeY1 = i;\n }\n if (arr[i][j] === \"W\" && i > 0 && arr[i-1][j] === \"B\" && edjeY2 === parseInt(n) - 1) {\n edjeY2 = i;\n }\n }\n }\n return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\n\nprint(output(k, n))\n\nfunction output(k, n) {\n var arr = []\n for (var i = 0; i < n; i++) {\n var string = readline();\n arr.push(string);\n }\n var edjeX1 = 0;\n var edjeX2 = parseInt(k) - 1;\n var edjeY1 = 0;\n var edjeY2 = parseInt(n) - 1;\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < k; j++) {\n if (arr[i][j] === \"B\" && edjeX1 === 0) {\n edjeX1 = j;\n }\n if (arr[i][j] === \"W\" && j > 0 && arr[i][j-1] === \"B\" && edjeX2 === parseInt(k) - 1) {\n edjeX2 = j-1;\n }\n if (arr[i][j] === \"B\" && edjeY1 === 0) {\n edjeY1 = i;\n }\n if (arr[i][j] === \"W\" && i > 0 && arr[i-1][j] === \"B\" && edjeY2 === parseInt(n) - 1) {\n edjeY2 = i-1;\n }\n }\n }\n return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\n\nprint(output(k, n))\n\nfunction output(k, n) {\n var arr = []\n for (var i = 0; i < n; i++) {\n var string = readline();\n arr.push(string);\n }\n var edjeX1 = 0;\n var edjeX2 = 0;\n var edjeY1 = 0;\n var edjeY2 = 0;\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < k; j++) {\n if (arr[i][j] === \"B\" && edjeX1 === 0) {\n edjeX1 = j;\n }\n if (arr[i][j] === \"W\" && arr[i][j-1] && arr[i][j-1] === \"B\" && edjeX2 === 0) {\n edjeX2 = j;\n }\n if (arr[i][j] === \"B\" && edjeY1 === 0) {\n edjeY1 = i;\n }\n if (arr[i][j] === \"W\" && i > 0 && arr[i-1][j] === \"B\" && edjeY2 === 0) {\n edjeY2 = i;\n }\n }\n }\n return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();\n}"}, {"source_code": "var firstLine = readline();\nvar n = firstLine.split(\" \")[0];\nvar k = firstLine.split(\" \")[1];\n\nprint(output(k, n))\n\nfunction output(k, n) {\n var arr = []\n for (var i = 0; i < n; i++) {\n var string = readline();\n arr.push(string);\n }\n var edjeX1 = 0;\n var edjeX2 = parseInt(k) - 1;\n var edjeY1 = 0;\n var edjeY2 = parseInt(n) - 1;\n for (var i = 0; i < n; i++) {\n for (var j = 0; j < k; j++) {\n if (arr[i][j] === \"B\" && edjeX1 === 0) {\n edjeX1 = j;\n }\n if (arr[i][j] === \"W\" && arr[i][j-1] && arr[i][j-1] === \"B\" && edjeX2 === 0) {\n edjeX2 = j;\n }\n if (arr[i][j] === \"B\" && edjeY1 === 0) {\n edjeY1 = i;\n }\n if (arr[i][j] === \"W\" && i > 0 && arr[i-1][j] === \"B\" && edjeY2 === 0) {\n edjeY2 = i;\n }\n }\n }\n return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();\n}"}], "src_uid": "524273686586cdeb7827ffc1ad59d85a"} {"source_code": "(function () {\n\nvar n = parseInt(readline());\n\nvar first;\nvar second;\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n if (!first) {\n first = row[0];\n second = row[1];\n \n if (first === second) {\n print('NO');\n return;\n }\n }\n \n for (var j = 0; j < row.length; j++) {\n if (i === j || row.length - 1 - i === j) {\n if (row[j] !== first) {\n print('NO');\n return;\n }\n } else {\n if (row[j] !== second) {\n print('NO');\n return;\n }\n }\n }\n}\n\nprint('YES');\n})();", "positive_code": [{"source_code": "print(function(n) {\n\tvar q = [];\n\tfor (var i = 0; i < n; i++)\n\t\tq.push(readline().split(''));\n\tvar a = q[0][0];\n\tvar b = q[0][1];\n\tif(a===b) return 'NO';\n\tfor (var i = 0; i < n; i++)\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tif (i === j || i === n - j - 1) {\n\t\t\t\tif (q[i][j] !== a) return 'NO';\n\t\t\t} else {\n\t\t\t\tif (q[i][j] !== b) return 'NO';\n\t\t\t}\n\n\treturn 'YES';\n\n}(+readline()));"}, {"source_code": "var squareSize = Number(readline())\n\nvar index = 0\nvar ans = true\nvar xLetter\nvar oLetter\n\nfor (var i = 0; i < squareSize; i++) {\n var line = readline()\n if (i === 0) {\n xLetter = line[0]\n oLetter = line[1]\n if (xLetter === oLetter) {\n ans = false\n break;\n }\n }\n\n for (var j = 0; j < line.length; j++) {\n if (j === index || j === line.length - 1 - index) {\n if (line[j] !== xLetter) {\n ans = false\n }\n } else {\n if (line[j] !== oLetter) {\n ans = false\n }\n }\n\n if (ans === false) {\n break;\n }\n }\n\n if (ans === false) {\n break;\n }\n\n if (i < Math.floor(squareSize / 2)) {\n index += 1\n } else {\n index -= 1\n }\n}\n\nif (ans) {\n print('YES')\n} else {\n print('NO')\n}"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index++) {\n if (!isNaN(txt[index])) {\n let tab = []\n for (let i = index + 1; i < index + txt[index] * 1 + 1; i++) {\n tab.push(txt[i].split(\"\").filter(data => {\n return data.length > 0\n }))\n }\n doit(tab)\n }\n\n}\n\nfunction doit(tab) {\n let s = tab[0][0],\n len = tab.length - 1;\n let arr = [],diag=[]\n tab.forEach(d => {\n d.forEach(data=>{\n if (!arr.includes(data)) {\n arr.push(data);\n }\n if(data==s){\n diag.push(data);\n }\n })\n }) \n if (arr.length != 2 || diag.length!=tab.length*2-1) {\n console.log(\"NO\");\n return;\n }\n\n let test = true\n tab.forEach((data, index) => {\n if (data[index] != s || data[len - index] != s) {\n test = false;\n return;\n }\n });\n if (test) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n}"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\trows = [], letters = [], count = {};\n\tfor (var r = 0; r < n; ++r) {\n\t\tvar row = trim(readline());\n\t\trows.push(row);\n\t\tfor (var c = 0; c < n; ++c) {\n\t\t\tvar ch = row.charAt(c);\n\t\t\tif (count[ch] === undefined) {\n\t\t\t\tletters.push(ch);\n\t\t\t\tcount[ch] = 0;\n\t\t\t}\n\t\t\tcount[ch] += 1;\n\t\t}\n\t}\n\tif (letters.length != 2) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\tvar xCount = 2*n - 1;\n\tif (count[letters[0]] == xCount) {\n\t\tvar x = letters[0];\n\t} else if (count[letters[1]] == xCount) {\n\t\tvar x = letters[1];\n\t} else {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\tfor (var d = 0; d < n; ++d) {\n\t\tif (rows[d].charAt(d) != x || rows[d].charAt(n-1-d) != x) {\n\t\t\tprint('NO');\n\t\t\treturn;\n\t\t}\n\t}\n\tprint('YES');\n}\n\nmain();\n"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline();\n\tvar t = [];\n\tfor (var i = 0; i < n; i++) t.push(readline());\n\n\tvar g = t[0][0];\n\tvar b = t[0][1];\n\n\tif (g == b) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\n\tfor (var i = 0; i < n; i++)\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tif ( i == j || i + j == (n - 1) ) {\n\n\t\t\t\tif (t[i][j] != g) {\n\t\t\t\t\tprint('NO');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tif (t[i][j] != b) {\n\t\t\t\t\tprint('NO');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t}\n\n\tprint('YES');\n\n}).call(this);"}, {"source_code": "function solve(){\n var n = parseInt(readline());\n var a= [];\n for(var i = 0 ; i < n ; ++i){\n a[i] = readline();\n }\n if(a[0][1] == a[0][0]){\n print(\"NO\");\n return;\n }\n for(var i = 0; i < n; i++){\n if(a[i][i] != a[0][0] || a[i][n-1-i] != a[0][0]){\n print(\"NO\");\n return;\n }\n for(var j = 0; j < n; j++){\n if(j != i && j != n-1-i && a[i][j] != a[0][1]){\n print(\"NO\");\n return;\n }\n }\n }\n print(\"YES\");\n}\nsolve();"}, {"source_code": "(function (){\n var i, j, n = parseInt(readline());\n var board = [];\n for(i = 0 ; i < n ; ++i){\n board[i] = readline();\n }\n\n\n var result = true;\n // first condition\n for( i = 0 ; result && i < n ; ++i){\n if ( board[i][i] != board[0][0] || board[i][n-1-i] != board[0][0] ){\n result = false;\n }\n for( j=0 ; result && j < n ; ++j){\n if ( j != i && j != n - 1 - i ){\n if ( board[i][j] == board[0][0] || board[i][j] != board[0][1] ){\n result = false;\n }\n }\n }\n }\n if ( result ){\n print(\"YES\");\n }else{\n print(\"NO\");\n }\n})();"}, {"source_code": "(function () {\n\nvar num, n;\nnum = n = parseInt(readline());\n\nvar row = [];\nvar first;\nvar second;\n\nwhile (num--) {\n row.push(readline().split(''));\n}\n\nfirst = row[0][0];\nsecond = row[0][1];\n\nif (first === second) {\n print('NO');\n return;\n}\n \nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++) {\n if (i === j || n - 1 === i + j) {\n if (row[i][j] !== first) {\n print('NO');\n return;\n }\n } else {\n if (row[i][j] !== second) {\n print('NO');\n return;\n }\n }\n }\n}\n\nprint('YES');\n})();"}, {"source_code": "var n = parseInt(readline());\n\nvar flag = true;\nvar first;\nvar second;\nvar res = 'YES';\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n if (!first) {\n first = row[0];\n second = row[1];\n \n if (first === second) {\n flag = false;\n res = 'NO';\n }\n }\n \n for (var j = 0; j < row.length; j++) {\n if (i === j || row.length - 1 - i === j) {\n if (row[j] !== first) {\n flag = false;\n res = 'NO';\n break;\n }\n } else {\n if (row[j] !== second) {\n flag = false;\n res = 'NO';\n break;\n }\n }\n }\n \n if (!flag) {\n break;\n } \n}\n\nprint(res);\n\n"}], "negative_code": [{"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index++) {\n if (!isNaN(txt[index])) {\n let tab = []\n for (let i = index + 1; i < index + txt[index] * 1 + 1; i++) {\n tab.push(txt[i].split(\"\").filter(data => {\n return data.length > 0\n }))\n }\n doit(tab)\n }\n\n}\n\nfunction doit(tab) {\n let s = tab[0][0],\n len = tab.length - 1;\n let arr = []\n tab.forEach(d => {\n d.forEach(data=>{\n if (!arr.includes(data)) {\n arr.push(data);\n }\n })\n })\n if (arr.length != 2) {\n console.log(\"NO\");\n return;\n }\n\n let test = true\n tab.forEach((data, index) => {\n if (data[index] != s || data[len - index] != s) {\n test = false;\n return;\n }\n });\n if (test) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n}"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index ++) {\n if(!isNaN(txt[index])){\n let tab=[]\n for (let i = index+1; i < index+txt[index]*1+1; i++) {\n tab.push(txt[i].split(\"\").filter(data=>{return data.length>0}))\n }\n doit(tab)\n }\n\n}\n\nfunction doit(tab) {\n let s=tab[0][0],len=tab.length-1;\n let test=true\n tab.forEach((data,index) => {\n if(data[index]!=s || data[len-index]!=s){\n test=false;\n return;\n }\n });\n if(test){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n }\n \n \n}"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index ++) {\n if(!isNaN(txt[index])){\n let tab=[]\n for (let i = index+1; i < index+txt[index]*1+1; i++) {\n tab.push(txt[i].split(\"\").filter(data=>{return data.length>0}))\n }\n doit(tab)\n }\n\n}\n\nfunction doit(tab) {\n let s=tab[0][0],len=tab.length-1;\n let ss=tab[0][1];\n let test=true\n tab.forEach((data,index) => {\n if(data[index]!=s || data[len-index]!=s){\n test=false;\n return;\n }\n data.forEach((d,i)=>{\n if(i!=index && i!=len-index && d!=ss){\n test=false;\n return;\n }\n })\n });\n if(test){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n }\n \n \n}"}, {"source_code": "print(function(n) {\n\tvar q = [];\n\tfor (var i = 0; i < n; i++)\n\t\tq.push(readline().split(''));\n\tvar a = q[0][0];\n\tvar b = q[0][1];\n\tfor (var i = 0; i < n; i++)\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tif (i === j || i === n - j) {\n\t\t\t\tif (q[i][j] !== a) return 'NO';\n\t\t\t} else {\n\t\t\t\tif (q[i][j] !== b) return 'NO';\n\t\t\t}\n\n\treturn 'YES';\n\n}(+readline()));"}, {"source_code": "print(function(n) {\n\tvar q = [];\n\tfor (var i = 0; i < n; i++)\n\t\tq.push(readline().split(''));\n\tvar a = q[0][0];\n\tvar b = q[0][1];\n\tfor (var i = 0; i < n; i++)\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tif (i === j || i === n - j - 1) {\n\t\t\t\tif (q[i][j] !== a) return 'NO';\n\t\t\t} else {\n\t\t\t\tif (q[i][j] !== b) return 'NO';\n\t\t\t}\n\n\treturn 'YES';\n\n}(+readline()));"}, {"source_code": "(function (){\n var i, j, n = parseInt(readline());\n var board = [];\n for(i = 0 ; i < n ; ++i){\n board[i] = readline();\n }\n\n\n var result = true;\n // first condition\n for( i = 0 ; result && i < n ; ++i){\n if ( board[i][i] != board[0][0] || board[i][n-1-i] != board[0][0] ){\n result = false;\n }\n for( j=0 ; result && j < n ; ++j){\n if ( j != i && j != n - 1 - i ){\n if ( board[i][j] == board[0][0] ){\n result = false;\n }\n }\n }\n }\n if ( result ){\n print(\"YES\");\n }else{\n print(\"NO\");\n }\n})();"}, {"source_code": "(function () {\n\nvar n = parseInt(readline());\n\nvar row = [];\nvar first;\nvar second;\n\nwhile (n--) {\n row.push(readline().split(''));\n}\n\nfirst = row[0][0];\nsecond = row[1][1];\n\nif (first === second) {\n print('NO');\n return;\n}\n \nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++) {\n if (i === j || n - 1 === i + j) {\n if (row[i][j] !== first) {\n print('NO');\n return;\n }\n } else {\n if (row[i][j] !== second) {\n print('NO');\n return;\n }\n }\n }\n}\n\nprint('YES');\n})();"}, {"source_code": "(function () {\n\nvar n = parseInt(readline());\n\nvar row = [];\nvar first;\nvar second;\n\nwhile (n--) {\n row.push(readline().split(''));\n}\n\nfirst = row[0][0];\nsecond = row[0][1];\n\nif (first === second) {\n print('NO');\n return;\n}\n \nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++) {\n if (i === j || n - 1 === i + j) {\n if (row[i][j] !== first) {\n print('NO');\n return;\n }\n } else {\n if (row[i][j] !== second) {\n print('NO');\n return;\n }\n }\n }\n}\n\nprint('YES');\n})();"}, {"source_code": "var n = parseInt(readline());\n\nvar flag = true;\nvar first;\nvar second;\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n if (!first) {\n first = row[0];\n second = row[1];\n }\n \n for (var j = 0; j < row.length; j++) {\n if (i === j || row.length - 1 - i === j) {\n if (row[j] !== first) {\n flag = false;\n break;\n }\n } else {\n if (row[j] !== second) {\n flag = false;\n break;\n }\n }\n }\n \n if (!flag) {\n break;\n } \n}\n\nif (!flag) {\n print(\"NO\");\n} else {\n print(\"YES\");\n}\n\n"}, {"source_code": "var n = parseInt(readline());\n\nvar flag = true;\nvar first;\nvar second;\nfor (var i = 0; i < n; i++) {\n var row = readline().split('');\n if (!first) {\n first = row[0][0];\n second = row[0][1];\n }\n \n for (var j = 0; j < row.length; j++) {\n if (i === j || row.length - 1 - i === j) {\n if (row[i][j] !== first) {\n flag = false;\n break;\n }\n } else {\n if (row[i][j] !== second) {\n flag = false;\n break;\n }\n }\n }\n \n if (!flag) {\n break;\n } \n}\n\nif (!flag) {\n print(\"NO\");\n} else {\n print(\"YES\");\n}\n\n"}], "src_uid": "02a9081aed29ea92aae13950a6d48325"} {"source_code": "const myMap = new Set();\nfunction findMin (currentPos){\n\tif (!myMap.has(currentPos)){\n\t\treturn 0;\n\t}\n\tvar left = currentPos - 1, leftVal = -1;\n\tvar right = currentPos + 1, rightVal = -1;\n\twhile (left > 0 || right <= endPoint){\n\t\tif (!myMap.has(left) && left > 0){\n\t\t\tleftVal = Math.abs(currentPos-left);\n\t\t\tbreak;\n\t\t}\n\t\telse if (!myMap.has(right) && right <= endPoint){\n\t\t\trightVal = Math.abs(currentPos-right);\n\t\t\tbreak;\n\t\t}\n\t\tleft -= 1; right += 1;\n\t}\n\treturn (leftVal != -1) ? leftVal : rightVal;\n}\nvar queries = parseInt(readline());\nfor (var i = 0; i< queries;i++)\n{\nvar discard = readline().split(' ');\nvar endPoint = parseInt(discard[0]);\nreadline().split(' ').forEach((val)=>{\n\tmyMap.add(parseInt(val));\n})\nprint(findMin(parseInt(discard[1])));\nmyMap.clear();\n}", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const t = readInt(input)\n\n for(let count = 0; count < t; count ++) {\n const [n, s, k] = readInts(input, 2 * count)\n\n const ks = readInts(input, 2 * count + 1)\n\n sort(ks)\n\n let i = -2, j = -2\n if(s < n) i = ks.indexOf(s + 1)\n if(s > 1) j = ks.indexOf(s - 1)\n\n if(ks.indexOf(s) == -1) {\n wr(0)\n continue\n }\n \n if(i == -1 || j == -1) {\n wr(1)\n continue\n }\n let a = -1, b = -1\n\n let x = s + 1\n\n while(true && x <= n && i < k) {\n if(ks[i] != x) {\n a = x - s\n break\n }\n else {\n i++\n x++\n }\n }\n // wr(i, x)\n if(a == -1 && x <= n) a = x - s \n\n x = s - 1\n while(true && x>= 0 && j >= 0) {\n // wr(k[j], x, j)\n if(ks[j] != x) {\n b = s - x\n break\n }\n else {\n j--\n x--\n }\n }\n\n if(b == -1 && x > 0) b = s - x\n\n // wr(a, b)\n if(a == -1 && b == -1) wr(0)\n else if(a == -1) wr(b)\n else if(b == -1) wr(a)\n else wr(Math.min(a, b))\n }\n}"}, {"source_code": "const myMap = new Set();\nfunction findMin (currentPos){\n\tif (!myMap.has(currentPos)){\n\t\treturn 0;\n\t}\n\tvar left = currentPos - 1, leftVal = -1;\n\tvar right = currentPos + 1, rightVal = -1;\n\twhile (left > 0 || right <= endPoint){\n\t\tif ( left > 0 && !myMap.has(left) ){\n\t\t\tleftVal = Math.abs(currentPos-left);\n\t\t\tbreak;\n\t\t}\n\t\telse if (right <= endPoint && !myMap.has(right) ){\n\t\t\trightVal = Math.abs(currentPos-right);\n\t\t\tbreak;\n\t\t}\n\t\tleft -= 1; right += 1;\n\t}\n\treturn (leftVal != -1) ? leftVal : rightVal;\n}\nvar queries = parseInt(readline());\nfor (var i = 0; i< queries;i++)\n{\nvar discard = readline().split(' ');\nvar endPoint = parseInt(discard[0]);\nreadline().split(' ').forEach((val)=>{\n\tmyMap.add(parseInt(val));\n})\nprint(findMin(parseInt(discard[1])));\nmyMap.clear();\n}"}, {"source_code": "function main() {\n var t = readline();\n for (var i = 0; i < t; i++) {\n findNext();\n }\n}\n\nfunction findNext() {\n var nsk = readline().split(' ');\n var n = +nsk[0];\n var s = +nsk[1];\n var k = +nsk[2];\n var ks = readline().split(' ');\n \n var ksObj = {}\n for (var d = 0; d < k; d++) {\n ksObj[ks[d]] = true;\n }\n\n for (var j = 0; j <= n; j++) {\n var plusJ = !ksObj[s + j] && s + j <= n;\n var minusJ = !ksObj[s - j] && s - j >= 1;\n\n if (plusJ || minusJ) {\n print(j);\n return;\n }\n }\n}\nmain()"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const t = readInt(input)\n\n for(let count = 0; count < t; count ++) {\n const [n, s, k] = readInts(input, 2 * count)\n\n const ks = readInts(input, 2 * count + 1)\n\n sort(ks)\n\n let i = -2, j = -2\n if(s < n) i = ks.indexOf(s + 1)\n if(s > 1) j = ks.indexOf(s - 1)\n\n if(i == -1 || j == -1) {\n wr(1)\n continue\n }\n let a = -1, b = -1\n\n let x = s + 1\n\n while(true && x <= n && i < k) {\n if(ks[i] != x) {\n a = x - s\n break\n }\n else {\n i++\n x++\n }\n }\n // wr(i, x)\n if(a == -1 && x <= n) a = x - s \n\n x = s - 1\n while(true && x>= 0 && j >= 0) {\n // wr(k[j], x, j)\n if(ks[j] != x) {\n b = s - x\n break\n }\n else {\n j--\n x--\n }\n }\n\n if(b == -1 && x > 0) b = s - x\n\n // wr(a, b)\n if(a == -1 && b == -1) wr(0)\n else if(a == -1) wr(b)\n else if(b == -1) wr(a)\n else wr(Math.min(a, b))\n }\n}"}], "src_uid": "faae9c0868b92b2355947c9adcaefb43"} {"source_code": "var n = +readline();\nvar s = readline();\nvar p = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR'];\nvar min = n + 10;\nvar por = 0;\nvar ans = '';\nfor (var j=0; j<6; j++){\n\tvar min1 = 0;\n\tfor (var i=0; i2){z -=(Math.floor(z/3)*3);}\nif(input[i]===\"R\"){r[z]++} \n\tif(input[i]===\"G\"){g[z]++} \n\t if(input[i]===\"B\"){b[z]++}\n}\n\n\n\nvar themax = 0;var RGB = [];\n\nfor(var s=0;s<3;s++){\nvar abc = \"012\".replace(s,\"\");var x = +abc[0];var y = +abc[1];\nvar calc = r[s]+g[x]+b[y];\nif(themax<=calc){themax=calc;RGB[s]=\"R\";RGB[x]=\"G\";RGB[y]=\"B\";}\ncalc = r[s]+g[y]+b[x];\nif(themax<=calc){themax=calc;RGB[s]=\"R\";RGB[y]=\"G\";RGB[x]=\"B\";}\t\n}\n\n\n\n\t\nvar st=\"\";themax=0;\nfor (var i = 0; i < input.length; i++) {\nif(input[i]!==RGB[x]){themax++}\nst+=RGB[x];x++;\nif(x==3){x=0}\n}\n\nprint(themax)\nprint(st)\n"}, {"source_code": "function ansa(n,s){\n\n function permutator(inputArr) {\n var results = [];\n\n function permute(arr, memo) {\n var cur, memo = memo || [];\n\n for (var i = 0; i < arr.length; i++) {\n cur = arr.splice(i, 1);\n if (arr.length === 0) {\n results.push(memo.concat(cur));\n }\n permute(arr.slice(), memo.concat(cur));\n arr.splice(i, 0, cur[0]);\n }\n\n return results;\n }\n\n return permute(inputArr);\n}\n\n var permuts = permutator(['R','G','B']);\n var ans = s;\n var mn = Infinity;\n\n for(var i = 0 ; i < permuts.length ; i++){\n\n var cst = 0;\n for(var j = 0 ; j < n ; j++){\n if(s[j] !== permuts[i][(j+1)%3])cst++;\n }\n if(cst < mn){\n mn = cst;\n ans = \"\";\n for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][(k+1)%3];\n }\n }\n\n print(mn);\n print(ans);\n\n\n}\n\nvar n = parseInt(readline());\nvar str = readline();\n\nansa(n,str)\n"}, {"source_code": "var cnt = 0;\nvar str = \"\";\nvar readliner = require('readline');\nvar rl = readliner.createInterface(process.stdin, process.stdout, null);\nrl.on('line', function (cmd) {\n //console.log('You just typed: '+cmd);\n cnt++;\n if (cnt > 1) str = cmd;\n }).on('close', main);\n\nfunction solve(pat, str, ans, res) {\n\t//console.log(pat,\" \",str,\" \",ans,\" \",res);\n\tvar N = Math.min(pat.length, str.length);\n\tvar new_ans = 0;\n\tvar new_res = \"\";\n\tfor (var i=0; i= str.length)\n return buffer;\n for (var i = index; i < str.length; i++)\n buffer.push(ToggleLetters(str, index, i));\n return FindAllPermutations(str, index + 1, buffer);\n }\n\n function ToggleLetters(str, index1, index2) {\n if (index1 != index2) {\n var temp = str[index1];\n str[index1] = str[index2];\n str[index2] = temp;\n }\n return str.join(\"\");\n }\n\n var permuts = FindAllPermutations(\"RGB\");\n var ans = s;\n var mn = Infinity;\n\n for(var i = 0 ; i < permuts.length ; i++){\n\n var cst = 0;\n for(var j = 0 ; j < n ; j++){\n if(s[j] !== permuts[i][j%3])cst++;\n }\n if(cst < mn){\n mn = cst;\n ans = \"\";\n for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][k%3];\n }\n }\n\n print(mn);\n print(ans);\n\n\n}\n\nvar n = parseInt(readline());\nvar str = readline();\n\nansa(n,str)\n"}], "src_uid": "e67b79e39511b0107a51edc0179afb82"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x, y, k] = ti(readline().split(' '));\n \n let res = Math.ceil((k + (k*y) - 1) / (x-1));\n console.log(res + k);\n }\n}\n\nfunction C(){\n try{\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 0){\n console.log(0);\n continue;\n }\n\n let dp = new Array(n);\n for(let j = 0; j < n; j++){\n dp[j] = new Array(2);\n dp[j].fill(-1);\n }\n\n for(let i = 0; i < n; i++){\n if(i >= 2){\n dp[i][0] = Math.min(dp[i-1][1]+a[i], dp[i-2][1]+a[i]+a[i-1]);\n dp[i][1] = Math.min(dp[i-1][0], dp[i-2][0]);\n }else{\n if(i === 0){\n dp[i][0] = a[i];\n dp[i][1] = a[i];\n }else{\n dp[i][0] = a[i] + a[i-1];\n dp[i][1] = dp[i-1][0];\n }\n }\n }\n\n //console.log(dp);\n console.log(Math.min(dp[n-1][0], dp[n-1][1]));\n\n let solve = (i, turn) => {\n console.log(i);\n if(i >= n)\n return 0;\n\n if(i === n-1){\n if(turn === 0)\n return dp[i][turn] = a[i];\n else\n return dp[i][turn] = 0;\n }\n\n if(dp[i][turn] !== -1)\n return dp[i][turn];\n \n if(turn === 0){\n return dp[i][turn] = Math.min(a[i] + solve(i+1, 1), a[i]+a[i+1]+solve(i+2, 1));\n }else{\n return dp[i][turn] = Math.min(solve(i+1, 0), solve(i+2, 0));\n }\n }\n\n //console.log(solve(0, 0));\n }\n }catch(e){\n console.log(e);\n }\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let unused = readLine();\n let bossArr = readLine()\n .split(\" \")\n .map((el) => {\n return { a: parseInt(el), p: \"\" };\n });\n\n // set first to friend\n bossArr[0].p = \"f\";\n\n // set friend everywhere where boss is easy:\n bossArr = bossArr.map((el) => {\n if (el.a === 0) el.p = \"f\";\n\n return el;\n });\n\n // set me everywhere in 2 tiles if I can:\n\n let meCount = 0;\n for (let i = 0; i < bossArr.length; i++) {\n if (bossArr[i].p == \"f\") {\n meCount = 0;\n continue;\n } else if (meCount < 2) {\n bossArr[i].p = \"m\";\n meCount++;\n } else if (meCount >= 2) {\n bossArr[i].p = \"f\";\n meCount = 0;\n }\n }\n\n let res = bossArr.reduce(\n (acc, cur) => acc + (cur.a == 1 && cur.p == \"f\" ? 1 : 0),\n 0\n );\n\n console.log(res);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var n = +inputs[i * 2 + 1];\n var a = inputs[i * 2 + 2].split(' ').map(v => +v);\n var b = [a[0], a[0] + a[1]];\n var c = [1e5, b[0]];\n for (let i = 2; i < n; i++) {\n b[i] = Math.min(a[i] + c[i - 1], a[i] + a[i - 1] + c[i - 2]);\n c[i] = Math.min(b[i - 1], b[i - 2]);\n }\n console.log(Math.min(b[n - 1], c[n - 1]));\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x, y, k] = ti(readline().split(' '));\n \n let res = Math.ceil((k + (k*y) - 1) / (x-1));\n console.log(res + k);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let count = 0;\n let i = 0;\n let turn = 0;\n while(i < n){\n if(turn === 0){\n if(a[i] === 1){\n count += 1;\n i += 1;\n }\n\n if(i < n && a[i] === 0){\n i += 1;\n }\n turn = 1;\n }else{\n i += 1;\n if(i < n && a[i] === 1)\n i += 1;\n\n turn = 0;\n }\n }\n console.log(count);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [x, y, k] = ti(readline().split(' '));\n \n let res = Math.ceil((k + (k*y) - 1) / (x-1));\n console.log(res + k);\n }\n}\n\nfunction C(){\n try{\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 0){\n console.log(0);\n continue;\n }\n\n let dp = new Array(n);\n for(let j = 0; j < n; j++){\n dp[j] = new Array(2);\n dp[j].fill(-1);\n }\n\n let solve = (i, turn) => {\n if(i >= n)\n return 0;\n\n if(i === n-1){\n if(turn === 0)\n return dp[i][turn] = a[i];\n else\n return dp[i][turn] = 0;\n }\n\n if(dp[i][turn] !== -1)\n return dp[i][turn];\n \n if(turn === 0){\n return dp[i][turn] = Math.min(a[i] + solve(i+1, 1), a[i]+a[i+1]+solve(i+2, 1));\n }else{\n return dp[i][turn] = Math.min(solve(i+1, 0), solve(i+2, 0));\n }\n }\n\n console.log(solve(0, 0));\n }\n }catch(e){\n console.log(e);\n }\n}"}], "src_uid": "d34ffd75ef82111d1077db4b033d5195"} {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nwhile(n--)if(a[n]&1)(!-b[n]||b[n+1]&1)?++c:(b[n-1]++&1)?++c:b[n-1]--}", "positive_code": [{"source_code": "function solve(n, gregor, me) {\r\n var taken = new Array(n).fill(0);\r\n var score = 0;\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (gregor[i] === \"1\") taken[i] = 1;\r\n }\r\n\r\n for (var _i = 0; _i < n; _i++) {\r\n if (me[_i] !== \"1\") continue;\r\n\r\n if (_i - 1 >= 0 && taken[_i - 1] === 1) {\r\n score++;\r\n taken[_i - 1] = 2;\r\n } else if (taken[_i] === 0) {\r\n taken[_i] = 2;\r\n score++;\r\n } else if (_i + 1 < n && taken[_i + 1] === 1) {\r\n score++;\r\n taken[_i + 1] = 2;\r\n }\r\n }\r\n\r\n return score;\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n n = parseInt(readline());\r\n var gregor = readline();\r\n var me = readline();\r\n print(solve(n, gregor, me));\r\n}\r\n"}, {"source_code": "\r\n\r\nvar t = readline()\r\n\r\nwhile (t--) {\r\n solve();\r\n}\r\n\r\nfunction solve() {\r\n var n = readline();\r\n var s = readline();\r\n var st2 = readline();\r\n var st = s.split('');\r\n var cont = 0;\r\n\r\n for (var i = 0; i < n; i++){\r\n if (st2[i] === '1') {\r\n if (st[i] === '0') {\r\n cont++;\r\n st[i] = '3';\r\n continue;\r\n }\r\n if (i > 0 && st[i - 1] === '1') {\r\n st[i - 1] = '3';\r\n cont++;\r\n continue;\r\n }\r\n if (i < n - 1 && st[i + 1] === '1') {\r\n st[i + 1] = '3';\r\n cont++;\r\n }\r\n }\r\n }\r\n write(cont + '\\n');\r\n}"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\twhile (t-- > 0) {\r\n\t\tvar n = readInt();\r\n\t\tvar enemy = readline().split(\"\").map(zzzz => parseInt(zzzz));\r\n\t\tvar gregor = readline().split(\"\").map(zzzz => parseInt(zzzz));\r\n\t\tvar cnt = 0;\r\n\t\tfor (var i = 0; i < n; i++) {\r\n\t\t\tif (gregor[i] === 0)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (i - 1 >= 0 && enemy[i - 1] === 1) { // take pawn on left\r\n\t\t\t\tcnt++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (enemy[i] === 0) { //go straight\r\n\t\t\t\tcnt++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (i + 1 < n && enemy[i + 1] === 1) { //take pawn on right\r\n\t\t\t\tcnt++\r\n\t\t\t\tenemy[i + 1] = -1; // can't use this grid anymore\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t}\r\n\t\tallans.push(cnt);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const c = a.map(s => s.split('').map(Number));\r\n const dp = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp;\r\n if (c[1][i] === 0) dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;else {\r\n var _dp2, _dp4;\r\n if (c[0][i] === 0 || c[0][i - 1] === 1) dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else if (c[0][i + 1] === 1) {\r\n var _dp3;\r\n dp[i] = ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1;\r\n c[0][i + 1] = 2;\r\n } else dp[i] = (_dp4 = dp[i - 1]) !== null && _dp4 !== void 0 ? _dp4 : 0;\r\n }\r\n }\r\n return dp[n - 1];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar v = nextCharArray();\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(v[i] == \"1\"){\r\n\t\t\t\tif(s[i] == \"0\"){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tif(i > 0){\r\n\t\t\t\t\tif(s[i - 1] == \"1\"){\r\n\t\t\t\t\t\ts[i - 1] = \"0\";\r\n\t\t\t\t\t\toutput++;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(i < N - 1){\r\n\t\t\t\t\tif(s[i + 1] == \"1\"){\r\n\t\t\t\t\t\ts[i + 1] = \"0\";\r\n\t\t\t\t\t\toutput++;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction printline(s, end = '\\n') {\r\n process.stdout.write(s + end);\r\n}\r\n\r\n\r\nfunction main() {\r\n let t = parseInt(readline(), 10);\r\n while(t--) {\r\n const n = parseInt(readline(), 10);\r\n let enemy = readline().split('');\r\n const paws = readline();\r\n\r\n let ans = 0;\r\n \r\n for (let i = 0; i < n; ++i) {\r\n if (paws[i] === '1') {\r\n if (enemy[i] === '0') {\r\n ans++;\r\n enemy[i] = '2';\r\n } else {\r\n if (i > 0 && enemy[i-1] === '1') {\r\n ans++;\r\n enemy[i-1] = '2';\r\n } else if (i < n && enemy[i+1] === '1') {\r\n ans++;\r\n enemy[i+1] = '2';\r\n }\r\n }\r\n }\r\n }\r\n\r\n printline(ans);\r\n }\r\n}\r\n\r\n// run: cat input.txt | node B.js"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n var a = readline().split('').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var b = readline().split('').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n for (let j = 0; j < n; j++) {\r\n if (b[j] === 1 && a[j] === 0 ) {\r\n res++\r\n continue\r\n }\r\n\r\n if (b[j] === 1 && a[j - 1] === 1 && j - 1 >= 0) {\r\n res++\r\n a[j - 1] = 0\r\n continue\r\n }\r\n if (b[j] === 1 && a[j + 1] === 1 && j + 1 < n) {\r\n res++\r\n a[j + 1] = 0\r\n continue\r\n }\r\n }\r\n\r\n console.log(res)\r\n })\r\n // var res = new Array(n)\r\n}\r\n\r\nfunction plus(a, b, res) {\r\n// console.log(a, b, res)\r\n if (a === 0) return res\r\n\r\n return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)\r\n}\r\n"}, {"source_code": "var fs = require(\"fs\");\r\nvar stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0\r\n\r\nconst lines = stdinBuffer.toString().match(/[^\\r\\n]+/g).slice(1);\r\n\r\n\r\nconst examples = [];\r\n\r\nfor(let i = 0; i < lines.length; i+= 3) {\r\n examples.push([\r\n lines[i+1].split('').map(letter => letter === '1'),\r\n lines[i+2].split('').map(letter => letter === '1'),\r\n ]);\r\n}\r\n\r\nconst solver = (arr) => {\r\n let currentResult = 0;\r\n arr[0].forEach((top, index) => {\r\n // console.log(currentResult, index)\r\n const bottom = Boolean(arr[1][index]);\r\n const bottomRight = Boolean(arr[1][index + 1]);\r\n \r\n if ((top && arr[1][index - 1])) {\r\n currentResult++;\r\n arr[1][index - 1] = false;\r\n return;\r\n }\r\n if ((top === false && bottom)) {\r\n currentResult++;\r\n arr[1][index] = false;\r\n return;\r\n }\r\n if ((top && bottomRight)) {\r\n currentResult++;\r\n arr[1][index + 1] = false;\r\n }\r\n })\r\n return currentResult\r\n};\r\n\r\n// console.log(examples)\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nwhile(n--)a[n]&1?!-b[n]||b[n+1]&1?++c:b[n-1]++&1?++c:b[n-1]--:0}"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nwhile(n--)if(a[n]&1)!-b[n]||b[n+1]&1?++c:b[n-1]++&1?++c:b[n-1]--}"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nwhile(n--)if(a[n]&1)if(!-b[n]||b[n+1]&1)++c;else if(b[n-1]&1)++c,b[n-1]=2}\r\n"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nfor(i=n;i--;)if(a[i]&1)if(!-b[i]||b[i+1]&1)++c;else if(b[i-1]&1)++c,b[i-1]=2}\r\n"}, {"source_code": "r=readline\r\nfor(i=r();i>0;i--){\r\n count = 0;\r\n n=r();\r\n b=r().split(\"\")\r\n a=r().split(\"\")\r\n for(j = 0; j < n; j++) {\r\n if (a[j] == 1) {\r\n if (b[j] == 0) {\r\n count+=1;\r\n b[j] = 2;\r\n }\r\n else {\r\n if (j > 0 && b[j-1] == 1) {\r\n b[j-1] = 2;\r\n count +=1;\r\n } else if (j < n-1 && b[j+1] == 1) {\r\n b[j+1] = 2;\r\n count += 1\r\n }\r\n }\r\n }\r\n \r\n }\r\n \r\n print(count)\r\n}"}, {"source_code": "var testCasesCount = readline();\r\n\r\n\r\n \r\nfor(var i=0; i s.split('').map(Number));\r\n const dp = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp;\r\n if (c[1][i] === 0) dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;else {\r\n var _dp2;\r\n if (c[0][i] === 0 || c[0][i - 1] === 1) dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else if (c[0][i + 1] === 1) {\r\n var _dp3;\r\n dp[i] = ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1;\r\n c[0][i + 1] = 2;\r\n }\r\n }\r\n }\r\n return dp[n - 1];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar v = nextCharArray();\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(v[i] == \"1\"){\r\n\t\t\t\tif(s[i] == \"0\"){\r\n\t\t\t\t\toutput++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tif(i < N - 1){\r\n\t\t\t\t\tif(s[i + 1] == \"1\"){\r\n\t\t\t\t\t\ts[i + 1] = \"0\";\r\n\t\t\t\t\t\toutput++;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(i > 0){\r\n\t\t\t\t\tif(s[i - 1] == \"1\"){\r\n\t\t\t\t\t\ts[i - 1] = \"0\";\r\n\t\t\t\t\t\toutput++;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n var a = readline().split('').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var b = readline().split('').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n for (let j = 0; j < n; j++) {\r\n if (b[j] === 1 && a[j] === 0 ) {\r\n res++\r\n continue\r\n }\r\n\r\n if (b[j] === 1 && a[j + 1] === 1 && j + 1 < n) {\r\n res++\r\n a[j + 1] = 0\r\n continue\r\n }\r\n if (b[j] === 1 && a[j - 1] === 1 && j - 1 >= 0) {\r\n res++\r\n a[j - 1] = 0\r\n continue\r\n }\r\n }\r\n\r\n console.log(res)\r\n })\r\n // var res = new Array(n)\r\n}\r\n\r\nfunction plus(a, b, res) {\r\n// console.log(a, b, res)\r\n if (a === 0) return res\r\n\r\n return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)\r\n}\r\n"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=a=s()\r\nwhile(n--)if(a[n]&1)(!-b[n]||b[n+1]&1)?++c:(b[n-1]++&1)?++c:b[n-1]--}"}, {"source_code": "r=readline;s=()=>r().split(\"\");for(r();n=r();print(c)){c=0;b=s();a=s()\r\nfor(i=n;i--;)if(a[i]&1)if(!-b[i]||b[i-1]&1)++c;else if(b[i+1]&1)++c,b[i+1]=2}\r\n"}, {"source_code": "var testCasesCount = readline();\r\n\r\n\r\n \r\nfor(var i=0; i= 0 && taken[_i - 1]) {\r\n score++;\r\n taken[_i - 1] = true;\r\n } else if (!taken[_i]) {\r\n taken[_i] = true;\r\n score++;\r\n } else if (_i + 1 < n && taken[_i + 1]) {\r\n score++;\r\n taken[_i + 1] = true;\r\n }\r\n }\r\n\r\n return score;\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n n = parseInt(readline());\r\n var gregor = readline();\r\n var me = readline();\r\n print(solve(n, gregor, me));\r\n}\r\n"}, {"source_code": "function solve(n, gregor, me) {\r\n var taken = new Array(n).fill(false);\r\n var score = 0;\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (gregor[i] === \"1\") taken[i] = true;\r\n }\r\n\r\n for (var _i = 0; _i < n; _i++) {\r\n if (me[_i] !== \"1\") continue;\r\n\r\n if (_i - 1 >= 0 && taken[_i - 1]) {\r\n score++;\r\n taken[_i - 1] = true;\r\n } else if (!taken[_i]) {\r\n taken[_i] = true;\r\n score++;\r\n } else if (_i + 1 < n && taken[_i + 1]) {\r\n score++;\r\n taken[_i + 1] = true;\r\n }\r\n }\r\n\r\n return score;\r\n}\r\n\r\nvar t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n n = parseInt(readline());\r\n gregor = readline();\r\n me = readline();\r\n print(solve(n, gregor, me));\r\n}\r\n"}, {"source_code": "\r\n\r\nvar t = readline()\r\n\r\nwhile (t--) {\r\n solve();\r\n}\r\n\r\nfunction solve() {\r\n var n = readline();\r\n var st = readline();\r\n var st2 = readline();\r\n\r\n var cont = 0;\r\n\r\n for (var i = 0; i < n; i++){\r\n if (st2[i] === '1') {\r\n if (st[i] === '0') {\r\n cont++;\r\n st[i] = '3';\r\n continue;\r\n }\r\n if (i > 0 && st[i - 1] === '1') {\r\n st[i - 1] = '3';\r\n cont++;\r\n continue;\r\n }\r\n if (i < n - 1 && st[i + 1] === '1') {\r\n st[i + 1] = 3;\r\n cont++;\r\n }\r\n }\r\n }\r\n\r\n write(cont + '\\n');\r\n}"}], "src_uid": "c05426881a7dccc1aa79608b612290a7"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n3\r\n3 2\r\n3 2 1\r\n5 3\r\n1 2 3 4 8\r\n1 5\r\n5\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n let ans = 0\n for (let i = 0; i <= 30; i++) {\n let now = 0\n arr.forEach(x => {\n if (x & (1 << i)) now++\n })\n if (now >= n / 2) {\n ans |= 1 << i\n }\n }\n return ans\n}\n", "positive_code": [{"source_code": "let dataitr;\r\nlet stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", (input) => {\r\n stdin_input += input;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n dataitr = stdin_input.split(\"\\n\").values();\r\n main();\r\n});\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(\" \");\r\nconst rna = () => ra().map((x) => Number(x));\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const t = rn();\r\n\r\n for (let ti = 0; ti < t; ti++) {\r\n const [n, l] = rna();\r\n const x = rna();\r\n\r\n const hash = Array.from({ length: l }, () => 0);\r\n\r\n for (const xi of x) {\r\n const s = xi.toString(2).padStart(l, \"0\");\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] === \"1\") {\r\n hash[i]++;\r\n } else {\r\n hash[i]--;\r\n }\r\n }\r\n }\r\n\r\n let local = \"\";\r\n for (let i = 0; i < hash.length; i++) {\r\n if (hash[i] > 0) {\r\n local += \"1\";\r\n } else {\r\n local += \"0\";\r\n }\r\n }\r\n\r\n console.log(parseInt(local, 2));\r\n }\r\n}\r\n"}, {"source_code": "\r\nlet _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve() {\r\n\t let [n,l] = inputReader.readNumberArray();\r\n\t let v = inputReader.readNumberArray();\r\n\t let bits = new Array(l).fill(0);\r\n\t v.forEach(x => {\r\n\t for(let k = 0; k < l; k++){\r\n\t bits[k]+= x & (1 << k) ? 1 : 0;\r\n\t }\r\n\t });\r\n\t let ans = 0;\r\n\t for(let k = 0; k < l; k++){\r\n\t if(bits[k] > (n - bits[k])) ans += (1 << k);\r\n\t }\r\n\t console.log(ans);\r\n\t}\r\n\t \r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l] = rna();\r\n\t\tconst x = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < l; i++) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tcnt += (x[j] >> i) & 1;\r\n\t\t\t}\r\n\t\t\tif (cnt >= n - cnt) \r\n\t\t\t\tans += 1 << i;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "84c88932e107e1d1f80b44aec88134e4"} {"source_code": "var n = readline();\nvar str = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});\nvar cars = 0;\n\nfor (var i = 0; 0 < str.length; cars++) {\n var sum = str.shift();\n\n for (var j = str.length - 1; j >= 0; j--) {\n if (sum === 4 || sum + str[j] > 4) break;\n sum = sum + str.splice(j, 1)[0];\n }\n}\n\nprint(cars);", "positive_code": [{"source_code": "\nvar IN1 = readline().split(' ').map(function(s){return parseInt(s)})\nvar IN2 = readline().split(' ').map(function(s){return parseInt(s)})\n\nvar n = IN1[0]\nvar ss = IN2\n\nvar n1=0,n2=0,n3=0,n4=0\n\nss.some(function(si){\n switch(si){\n case 1:\n n1+=1\n break\n case 2:\n n2+=1\n break\n case 3:\n n3+=1\n break\n case 4:\n n4+=1\n break\n }\n})\n\n\nvar t = 0\n\nt+=n4\n\nt+=n3\n\nif(n1x-y);\n\tvar res = 0;\n\tvar l = 0;\n\n\tfor (var i=n-1; i>=l; i--){\n\t\tvar sum = +str[i];\n\t\t\t\twhile(+sum+Number(str[l]) <= 4){\n\t\t\t\t\tsum+= +str[l];\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\tres++;\n\t\t }\n\t\n\tprint(res);"}, {"source_code": "var a = readline();\nvar cin = readline().split(' ').sort(function(a,b){return a-b});\nvar jami = 0;\nvar ori = 0, sami = 0, erti = 0;\nfor(i = 0; i < a; i ++) {\n\tif(cin[i] == 4) {\n\t\tjami += 1;\n\t}\n\tif(cin[i] == 1) {\n\t\terti += 1;\n\t}\n\tif(cin[i] == 2) {\n\t\tori += 1;\n\t}\n\tif(cin[i] == 3) {\n\t\tsami += 1;\n\t}\n}\nif(ori % 2 == 1) {\n\tjami = jami + Math.floor(ori / 2);\n\tori = 2;\n}\nelse {\n\tjami = jami + ori/2; // ori movagvare \n\tori = 0;\n}\nif (sami > erti) {\t\n\tjami = jami + sami + ori/2;// mogvarda 3 tema\n}\nelse {\n\terti = erti - sami;\n\tjami = jami + sami + Math.ceil((ori + erti)/4);\n}\nprint(jami);"}, {"source_code": "line = readline();\ngroups = readline().split(' ');\ncount = [0, 0, 0, 0, 0];\ngroups.forEach(function(group) { ++count[group]; });\ntaxis = [\n count[4],\n Math.min(count[1], count[3]),\n Math.max(0, count[3] - count[1]),\n Math.floor(count[2] / 2),\n Math.ceil((Math.max(0, count[1] - count[3]) + (count[2] % 2 == 0 ? 0 : 2)) / 4)\n]\nprint(taxis.reduce(function(prev, x) { return prev + x; }));\n"}, {"source_code": "//deneme121\n\nvar n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else if(arr[i] == '4'){ _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n if( ((_1 - _3) + _2 * 2) % 4 == 0 ){\n\t\t\tsum += _3 + Math.floor(((_1 - _3) + _2 * 2) / 4);\n\t\t} else{\n\t\t\tsum += _3 + Math.floor(((_1 - _3) + _2 * 2) / 4) + 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "//deneme121asds\n\nvar n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else if(arr[i] == '4'){ _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n if( ((_1 - _3) + _2 * 2) % 4 == 0 ){\n\t\t\tsum += _3 + Math.floor(((_1 - _3) + _2 * 2) / 4);\n\t\t} else{\n\t\t\tsum += _3 + Math.floor(((_1 - _3) + _2 * 2) / 4) + 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "var pasar = readline();\nvar entrada = readline().split(\" \");\nvar taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0, c_dos = 0;\nfor (var i = 0; i < entrada.length; i++){\n entrada[i] = parseInt(entrada[i]);\n if (entrada[i] == 1){\n c_unos++;\n } else if (entrada[i] == 2){\n c_dos++;\n } else if (entrada[i] == 3){\n c_tres++;\n } else if (entrada[i] == 4){\n taxis++;\n }\n}\nif (c_tres == c_unos){\n taxis += c_tres;\n c_unos = 0;\n} else if (c_tres > c_unos){\n taxis += c_unos + (c_tres - c_unos);\n c_unos = 0;\n} else if (c_tres < c_unos) {\n taxis += c_tres;\n c_unos = c_unos - c_tres;\n}\ntaxis += parseInt(c_dos / 2);\nif (c_dos % 2 !== 0){\n c_dos = 0;\n if (c_unos >= 2){\n c_unos -= 2;\n } else if (c_unos == 1){\n c_unos--;\n }\n taxis += 1;\n}\ntaxis += parseInt(c_unos / 4);\nif (c_unos % 4 !== 0){\n taxis++;\n}\n\nprint (taxis);\n"}, {"source_code": "var cantNum = readline();\n var groupsList = readline().split(' ').map(function(x){return parseInt(x);}).sort(function(a,b){return b-a;});\n var cantTaxis = 0;\n for (var i = 0; 0 < groupsList.length; cantTaxis++) {\n var sum = groupsList.shift();\n for (var j = groupsList.length-1; j >= 0; j--) {\n if(sum == 4 || sum + groupsList[j] > 4) break;\n sum += groupsList.splice(j,1)[0];\n }\n }\n print(cantTaxis);"}, {"source_code": "var t = [0, 0, 0, 0];\nreadline();\nreadline().split(' ').map(function (i) {t[4 - parseInt(i)]++;});\nvar c = t[0];\nvar m = Math.min(t[1], t[3]);\nc += m;\nt[1] -= m;\nt[3] -= m;\nc += Math.floor(t[2] / 2);\nt[2] -= 2 * Math.floor(t[2] / 2);\nc += Math.ceil((t[3] + t[2]*2)/4);\nc += t[1];\nprint(c);"}, {"source_code": "/* TEST CASE\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar a = [0, 0, 0, 0, 0];\n\tvar answer = 0;\n\tvar i;\n\tvar splitted = readline().split(' ');\n\tvar move;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\ta[parseInt(splitted[i])]++;\n\t}\n\tif (a[3] > 0 && a[1] > 0) {\n\t\tmove = Math.min(a[3], a[1]);\n\t\ta[4] += move;\n\t\ta[3] -= move;\n\t\ta[1] -= move;\n\t}\n\tif (a[2] > 1) {\n\t\tmove = (a[2] >> 1);\n\t\ta[4] += move;\n\t\ta[2] -= (move << 1);\n\t}\n\tanswer = a[4] + a[3] + Math.ceil((a[2] * 2 + a[1]) / 4.0);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = readline();\nvar nums = readline().split(' ').map(function(each) {\n return Number(each);\n});\n\nnums.sort(function(a, b) {\n return a - b;\n});\n\n\nvar i = 0;\nvar taxis = 0;\nvar j = nums.length - 1;\n\nwhile (i <= j) {\n var sum = nums[j];\n j--;\n\n while (i <= j) {\n var newSum = sum + nums[i];\n\n if (newSum > 4)\n break;\n\n i++;\n sum = newSum;\n }\n\n taxis++;\n}\n\nprint(taxis);\n"}, {"source_code": "var n=parseInt(readline());\nvar arr=readline().split(' ');\nvar k1,k2,k3,k_total;\nk1=k2=k3=k_total=0;\nfor(var i=0;i= 2){\n car += Math.floor(two/2);\n two = two%2;\n }\n car += three;\n if(one > 0){\n if(two > 0){\n two -= 1\n one -= 2\n car += 1\n }\n }\n if(one > 0){\n car += Math.floor(one/4);\n if(one%4 != 0) car +=1;\n }\n if(two > 0) car += 1;\n print(car)\n}\nmain();\n"}, {"source_code": "//158B - Taxi\nArray.prototype.count = function(val) {\n return this.filter(e => e == val).length;\n}\nvar n = +readline();\nvar numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();\n\nvar res = numbers.filter(e => e == 4).length;\nnumbers = numbers.filter(e => e != 4);\n\nres += (() => {\n var one = numbers.count(1);\n var three = numbers.count(3);\n numbers.splice(numbers.indexOf(3), three);\n var countOf4 = (one < three) ? one : three;\n numbers.splice(numbers.indexOf(1), countOf4);\n return three;\n})();\n\nres += (() => {\n var two = numbers.count(2);\n var countOf422 = 0 | two / 2;\n two = two - countOf422 * 2;\n var one = numbers.count(1);\n if (two) {\n numbers.splice(numbers.indexOf(1), (one > 2) ? 2 : one);\n }\n numbers.splice(numbers.indexOf(2), numbers.count(2));\n return countOf422 + two;\n})();\nres += (() => {\n var one = numbers.count(1);\n if (one % 4 == 0) {\n return one / 4;\n } else {\n return 0 | (one / 4 + 1);\n }\n})();\nprint(res);"}, {"source_code": "function main(){\n\n var n = readline();\n \n var num = [0,0,0,0,0];\n var cars=0;\n \n var kids = readline().split(' ');\n \n for(i=0;i0){\n\tnum[4]-=1;\n\tcars+=1;\n }\n\n // num[3], num[2], num[1] left\n while(num[3]>0 && num[1]>0){\n\tnum[3]-=1;\n\tnum[1]-=1;\n\tcars+=1;\n }\n\n while(num[3] > 0) {\n\tnum[3] -= 1;\n\tcars += 1;\n }\n\n // num[2], num[1] left\n while(num[2]>=2){\n\tnum[2]-=2;\n\tcars+=1;\n }\n \n if(num[2]===1) {\n\tif (num[1]>0){\n\t if(num[1]>=2){\n\t\tnum[1]-=2;\n\t }else{\n\t\tnum[1]-=1;\n\t }\n }\n\tcars+=1;\n }\n\n \n\n // num[1] left\n if(num[1]%4==0){\n\tcars+=(num[1]/4);\n } else{\n\tcars+=(Number.parseInt(num[1]/4))+1;\n }\n print (cars);\n}\n\n\nmain();"}, {"source_code": "var n = parseInt(readline());\nvar groups = readline().split(\" \");\nvar counters = [0, 0, 0, 0, 0];\nfor(var i = 0; i < n; i++) {\n var cur = parseInt(groups[i]);\n counters[cur]++;\n}\n\nvar result = 0;\nresult += counters[4];\n\nresult += counters[3]; \ncounters[1] = Math.max(counters[1] - counters[3], 0);\n\nresult += Math.floor(counters[2] / 2);\nif (counters[2] % 2 == 1) {\n result++;\n counters[1] = Math.max(counters[1] - 2, 0)\n}\n\nresult += Math.ceil(counters[1]/4);\n\nprint(result);"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});\nvar cars = 0;\nfor(var i=0; 0=0; j--){\n if(sum===4 || sum+s[j]>4) break;\n sum += s.splice(j, 1)[0];\n }\n}\nprint(cars);"}, {"source_code": "var n = parseInt(readline());\nvar groups = readline().split(\" \").map(function(x){ return parseInt(x); });\nvar taxis = 0;\nvar g = [];\nfor(var i =0 ; i <= 4; i++ )\n g[i] = 0;\nfor(var i = 0; i < n; i++){\n g[groups[i]]++;\n}\ntaxis += g[4];\ntaxis += g[3];\ng[1] = g[1] - g[3];\ng[1] = g[1] < 0 ? 0 : g[1];\ntaxis += Math.ceil((g[2] /2));\nif(g[1] > 0 && g[2] % 2 == 1){\n g[1] = g[1] - 2;\n}\nif(g[1] > 0){\n taxis += Math.ceil(g[1] / 4);\n}\nwrite(taxis);\n"}, {"source_code": "var n = readline();\nvar group = readline().split(\" \");\ngroup.sort(function(a,b){\n\treturn b - a;\n});\nvar taxiNum = 0;\n\nfor(var i = 0,len = group.length-1; i < group.length; i++){\n\tif (group[i] == 0)\n\t\tcontinue;\n\telse if (group[i] == 4)\n\t\ttaxiNum++;\n\telse if(group[i] < 4){\n\t\tvar added = parseInt(group[i]) + parseInt(group[len]);\n\t\tif(added > 4)\n\t\t\ttaxiNum++;\n\t\telse if(added == 4){\n\t\t\ttaxiNum++;\n\t\t\tgroup[len] = 0;\n\t\t}\n\t\telse if(added < 4){\n\t\t\tgroup[len] = 0; \n\t\t\tfor (var j = len-1; j > i; j--){\n\t\t\t\tadded += parseInt(group[j]);\n\t\t\t\t//print(added);\n\t\t\t\tif(added > 4){\n\t\t\t\t\ttaxiNum++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if (added == 4) {\n\t\t\t\t\ttaxiNum++;\n\t\t\t\t\tgroup[j] = 0;\n\t\t\t\t\tlen = j - 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tgroup[j] = 0;\n\t\t\t\t\tlen = j - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(added < 4)\n\t\t\t\ttaxiNum++;\n\t\t}\n\t}\n}\nprint(taxiNum);\n"}, {"source_code": "input=readline();\ninput=readline();\ninput = input.split(' ').map(e=>parseInt(e));\ntmp=[0,0,0,0,0];\ninput.forEach(element => {\n tmp[element]++;\n});\ntmp[1] = (tmp[1]>tmp[3])?tmp[1]-tmp[3]:0;\nprint(tmp[4] + tmp[3] + Math.floor( (tmp[1] + 2*tmp[2] + 3)/4))\n\n\n"}, {"source_code": "readline(); var items = [0, 0, 0, 0, 0];\nreadline().split( '' ).forEach( function(it) {\n items[it]++;\n} );\n\nvar total = items[4] + items[3];\nitems[1] = Math.max( 0, items[1] - items[3] );\ntotal += Math.floor( items[2] / 2 );\nif (1 === items[2]%2) {\n total++;\n items[1] = Math.max( 0, items[1] - 2 );\n}\ntotal += Math.ceil( items[1] / 4 );\n\nprint( total );"}, {"source_code": "var n = parseInt(readline(), 10), \n inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a), \n taxi = 0,\n friendNum = 0;\n \nfor(var i=0; i<=inp.length-1; i++) {\n if(inp[i] === 4) {\n taxi++;\n inp.shift();\n i -= 1;\n \n } else if(inp[i] === 3) {\n if(inp[inp.length - 1] === 1) {\n inp.pop();\n }\n \n taxi++;\n inp.shift();\n i -= 1;\n \n } else if(inp[i] === 2) {\n if(inp[i+1] === 2) {\n inp.shift();\n \n } else if(inp[inp.length-1] === 1) {\n inp.pop();\n \n if(inp[inp.length-1] === 1) {\n inp.pop();\n }\n }\n \n taxi++;\n inp.shift();\n i -= 1;\n \n } else {\n taxi += Math.ceil(inp.length / 4);\n break;\n \n }\n}\n \nprint(taxi);"}, {"source_code": "// After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\n// Input\n// The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\n// Output\n// Print the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nvar n = readline(); var g = readline().split(\" \")\n\nvar ile_1 = 0; var ile_2 = 0; var ile_3 = 0; var ile_4 = 0; var s = 0\nfor (i=0; i= +ile_1){\n ile_1 = 0\n}else {\n ile_1 = +ile_1 - +ile_3\n}\n\ns = +ile_4 + +ile_3\n\n// check 2s and 1s and print sum of needed cabs\nif ((+ile_1 + +ile_2*2)%4 === 0){\n s += (+ile_1 + +ile_2*2)/4\n}else {\n s += parseInt((+ile_1 + +ile_2*2)/4)+1\n}\n\nprint(s)\n\n"}, {"source_code": "function main() {\n var input = readline()\n var groups = readline().split(' ')\n var groupsMap = {\n \"1\": 0,\n \"2\": 0,\n \"3\": 0,\n \"4\": 0\n }\n groups.forEach(function(element) {\n groupsMap[element] += 1;\n });\n\n var result = groupsMap[\"4\"]\n var less = groupsMap[\"3\"] > groupsMap[\"1\"] ? groupsMap[\"1\"] : groupsMap[\"3\"];\n result += less;\n groupsMap[\"1\"] -= less;\n groupsMap[\"3\"] -= less;\n result += groupsMap[\"3\"];\n\n result += Math.floor(groupsMap[\"2\"] / 2)\n result += Math.floor(groupsMap[\"1\"] / 4)\n result += Math.ceil(((groupsMap[\"2\"] % 2) * 2 + (groupsMap[\"1\"] % 4)) / 4)\n print(result)\n}\nmain()"}, {"source_code": "var count = parseInt(readline());\nvar groups = readline();\ngroups = groups.split(' ');\n\nvar full = 0, car3 = 0; car2 = 0; car1 = 0;\n\nfor (var i=0; i car1) {\n car3 -= car1;\n full += car1 + car3;\n car1 = 0; \n} else if (car1 > car3) {\n car1 -= car3;\n full += car3;\n} else {\n full += car3;\n car1 = 0;\n}\nfull += Math.floor(car2/2);\ncar2 %= 2;\nif (car2 == 1) {\n full++;\n car1 -= 2;\n}\nif (car1 > 0) { \n full += Math.floor(car1/4);\n if (car1%4) { full++; }\n}\nprint(full);\n"}, {"source_code": "var carLimit = 4;\n\n(function() {\n var groupCount = +readline(),\n data = readline().split(\" \"),\n groupedData = groupData(data),\n\n i,\n carCount = 0,\n inCar,\n lookingForCount;\n\n while (Object.keys(groupedData).length > 0) {\n inCar = 0;\n lookingForCount = carLimit - inCar;\n\n while (lookingForCount !== 0) {\n if (lookingForCount in groupedData) {\n inCar += lookingForCount;\n if (--groupedData[lookingForCount] === 0) {\n delete groupedData[lookingForCount];\n }\n lookingForCount = carLimit - inCar;\n } else {\n lookingForCount--;\n }\n }\n\n carCount++;\n }\n\n function groupData(data) {\n var groupedData = {};\n for (var i in data) {\n if (!groupedData[data[i]]) {\n groupedData[data[i]] = 0;\n }\n groupedData[data[i]]++;\n }\n\n return groupedData;\n }\n\n print(carCount);\n\n})();\n"}, {"source_code": "var r = readline();\nvar l = readline().split(' ');\n \nvar one = 0;\nvar two = 0;\nvar three = 0;\nvar four = 0;\n \nfor (var i = 0; i< r; i++){\n if(parseInt(l[i]) === 1){\n one++;\n } \n if(parseInt(l[i]) === 2){\n two++;\n } \n if(parseInt(l[i]) === 3){\n three++;\n } \n if(parseInt(l[i]) === 4){\n four++;\n } \n}\n\nvar c = four;\nwhile(three > 0){\n if(one > 0){\n three--;\n one--;\n c++;\n} else {\n three--;\n c++;\n}\n}\nwhile(two >= 2){\n two= two - 2;\n c++;\n}\nwhile(two > 0){\n if(one > 0){\n two--;\n one = one -2;\n c++;\n } else {\n two--;\n c++;\n }\n}\nwhile(one > 0){\n one = one - 4;\n c++;\n}\nprint(c);\n\n\n"}, {"source_code": "var n = Number(readline());\nvar groups = readline().split(\" \").map(function(x) { return parseInt(x); }).sort();\nvar taxies = 0;\nvar buffer = 0;\n\nvar peopleCount = groups.reduce(function (prev, next) {\n return prev + next;\n});\nif (peopleCount == 5 && n == 5) {\n taxies = 2;\n} else if ( peopleCount >= 4 ) {\n for (var i = n - 1; i >= buffer; i--) {\n var groupR = groups[i];\n var temp = groupR;\n\n for (var j = buffer; j < n; j++) {\n var groupL = groups[j];\n\n if ( temp + groupL >= 4 ) {\n if ( temp + groupL == 4 ) {\n buffer++;\n }\n\n taxies++;\n break;\n } else {\n temp += groupL;\n buffer++;\n }\n }\n }\n} else {\n taxies = 1;\n}\n\nprint( taxies );"}, {"source_code": "var n = readline();\nvar groups = readline().split(' ').sort();\nvar carCount = 0;\n\nvar countStruct = {\n 1: 0,\n 2: 0,\n 3: 0\n};\n\nfor (var i = 0; i < groups.length; i++) {\n if (groups[i] == 4) {\n carCount++;\n } else if (groups[i] == 3) {\n countStruct[3]++;\n } else if (groups[i] == 2) {\n countStruct[2]++;\n } else if (groups[i] == 1) {\n countStruct[1]++;\n }\n}\n\nwhile(countStruct[3] > 0 && countStruct[1] > 0){\n countStruct[1]--;\n countStruct[3]--;\n carCount++;\n}\n\ncountStruct[2] += Math.floor(countStruct[1]/2); // convert 1 to 2\ncountStruct[1] -= Math.floor(countStruct[1]/2) * 2;\n\ncarCount += Math.floor(countStruct[2] * 2/4); // convert 2 to 4\ncountStruct[2] -= Math.floor(countStruct[2] * 2/4) * 2;\n\nwhile(countStruct[2] > 0 && countStruct[1] > 0){\n countStruct[1]--;\n countStruct[2]--;\n countStruct[3]++;\n}\n\ncarCount += countStruct[3];\ncarCount += Math.ceil(countStruct[2]/2);\ncarCount += Math.ceil(countStruct[1]/4);\n\nprint(carCount);\n\n\n\n\n"}, {"source_code": "var countOfGroups = +readline(),\n\tpeoplesInGroups = readline().split(' '),\n\tgroups = [0,0,0,0],\n\tres = 0,\n\ttemp;\n\nfor (var i = 0; i < countOfGroups; i++) {\n\tswitch (peoplesInGroups[i]) {\n\t\tcase '1':\n\t\t\tgroups[0] = groups[0] + 1;\n\t\t\tbreak;\n\t\tcase '2':\n\t\t\tgroups[1] = groups[1] + 1;\n\t\t\tbreak;\n\t\tcase '3':\n\t\t\tgroups[2] = groups[2] + 1;\n\t\t\tbreak;\n\t\tcase '4':\n\t\t\tgroups[3] = groups[3] + 1;\n\t\t\tbreak;\n\t}\n}\n\nif (groups[3] > 0) {\n\tres = groups[3];\n}\n\nif (groups[2] > 0) {\n\tres += groups[2];\n\tgroups[0] -= groups[2]\n}\n\n\nif (groups[1] > 0) {\n\tres += Math.floor(groups[1] / 2);\n\tif (groups[1] % 2 != 0) {\n\t\tres += 1;\n\t\tgroups[0] -= 2;\n\t}\n}\n\nif (groups[0] > 0) {\n\tres += Math.ceil(groups[0] / 4);\n}\n\nwrite(res);"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar a = readline().split(' ').map(Number),\n count = [0, 0, 0, 0, 0];\n\nfor (var i = 0; i < a.length; i++) {\n count[a[i]]++;\n}\n\nvar ans = count[4] + count[3] + Math.floor(count[2] / 2);\n\n(count[1] - count[3] >= 0) ? count[1] -= count[3] : count[1] = 0;\n\nif (count[2] % 2 == 1) {\n ans++;\n (count[1] - 2 >= 0) ? count[1] -= 2 : count[1] = 0;\n}\n\nans = ans + Math.floor(count[1] / 4);\n\nif (count[1] % 4) {\n ans++;\n}\n\nprint(ans);"}, {"source_code": "readline();\nvar s = readline().split( \" \" ).map( si => parseInt( si, 10 ) );\nvar hist = new Map( [ [ 1, 0 ], [ 2, 0 ], [ 3, 0 ], [ 4, 0] ] );\ns.forEach( si => hist.set( si, hist.get( si ) + 1 ) );\n\nvar count = hist.get( 4 ) + \n hist.get( 3 ) + \n Math.ceil( hist.get( 2 ) / 2 ) + \n Math.max( Math.ceil( ( hist.get( 1 ) - hist.get( 3 ) - 2 * (hist.get( 2 ) % 2 ) ) / 4 ), 0 );\nprint( count );\n\n\n"}, {"source_code": "readline();\nvar groups = {1: 0, 2: 0, 3: 0, 4: 0}, answer = 0;\nfor (var s of readline().split('')) groups[Number(s)]++;\n\nanswer += groups[4];\n\nanswer += groups[3];\ngroups[1] -= groups[3];\nif (groups[1] < 0) groups[1] = 0;\n\nanswer += Math.floor(groups[2] / 2);\ngroups[2] %= 2;\n\nanswer += Math.ceil((groups[2] * 2 + groups[1]) / 4);\n\nprint(answer);"}, {"source_code": "var groupsQuantity = readline();\nvar childrenQuantity = readline().split(\" \");\n\nvar cars = 0;\n\nvar NumberGroupsOfOne = 0;\nvar NumberGroupsOfTwo = 0;\nvar NumberGroupsOfThree = 0;\nvar NumberGroupsOfFour = 0;\n\nfor(var i = 0; i < groupsQuantity; i++){\n switch(+childrenQuantity[i]){\n case 1: NumberGroupsOfOne++;\n break;\n case 2: NumberGroupsOfTwo++;\n break;\n case 3: NumberGroupsOfThree++;\n break;\n case 4: NumberGroupsOfFour++;\n break;\n }\n}\n\ncars += NumberGroupsOfFour;\n\n\nif(NumberGroupsOfOne >= NumberGroupsOfThree){\n cars += NumberGroupsOfThree;\n NumberGroupsOfOne -= NumberGroupsOfThree;\n if(NumberGroupsOfOne >= NumberGroupsOfTwo*2){\n cars += NumberGroupsOfTwo;\n cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo*2)/4);\n }\n else{\n cars += Math.ceil(NumberGroupsOfOne/2);\n cars += Math.ceil(Math.ceil(NumberGroupsOfTwo - Math.ceil(NumberGroupsOfOne/2))/2);\n }\n}\nelse{\n cars += NumberGroupsOfOne;\n NumberGroupsOfThree -= NumberGroupsOfOne;\n cars += NumberGroupsOfThree;\n cars += Math.ceil(NumberGroupsOfTwo/2);\n}\nprint(cars);"}, {"source_code": "readline();for(var s=readline().replace(/\\D/g,\"\"),g=[0,0,0,0,0],i=0;i gOne) {\n threesAndOnes = gOne;\n gThree = gThree - gOne;\n gOne = 0;\n} else if (gThree < gOne){\n threesAndOnes = gThree;\n gOne = gOne - gThree;\n gThree = 0;\n} else if( gThree === gOne){\n threesAndOnes = gThree;\n gOne = 0;\n gThree = 0;\n}\n\nvar others = Math.ceil((gOne + 2 * gTwo) / 4);\n\n//var twosAndTwos = 0;\n//\n//if(gTwo % 2 === 0){\n// twosAndTwos = gTwo / 2;\n//} else {\n// twosAndTwos = Math.floor(gTwo / 2);\n// gTwo = 1;\n//}\n//\n//var others = 0;\n////print(Math.floor(gOne / 4));\n//if (gTwo !== 0 && gOne !== 0){\n// if (gOne <= 2) {\n// others = 1;\n// } else {\n// others = 1 + Math.ceil((gOne - 2) / 4); \n// }\n//} else if (gTwo === 0 && gOne !== 0 && gOne > 4){\n// others = Math.ceil(gOne / 4);\n//} else if(gTwo !== 0 && gOne === 0){\n// others = 1;\n//} else if (gOne !== 0 && gOne <= 4 && gTwo === 0){\n// others = 1;\n//}\n\n\nvar taxi = gFour + threesAndOnes + gThree + others;\n\nprint(taxi);\n//print(gFour, threesAndOnes, others);"}, {"source_code": "\nvar numOfGrop = readline();\n\nvar groups = readline();\n\nvar forths = 0; var thirds = 0; var twos = 0; var ones = 0; var taxis = 0;\n\n//print(groups.length);\n\n\nfor (var i = 0; i < groups.length; i+=2){\n if (groups[i] === '1') ones ++;\n if (groups[i] === '2') twos ++;\n if (groups[i] === '3') thirds ++;\n if (groups[i] === '4') forths ++;\n \n}\n\n//print(forths + \" ,\" + thirds + \" ,\" + twos + \" ,\" + ones);\n\ntaxis += (forths + thirds + Math.round(twos / 2));\n\nones -= (thirds + ((twos % 2) * 2));\n\nif(ones > 0) {\n taxis += Math.floor(ones / 4);\n if(ones % 4 !== 0) taxis++;\n }\n\nprint(taxis);"}, {"source_code": "\nvar n=+readline();\nvar s=readline().split(' ').map(function(v){return +v;});\n\nvar a=[0,0,0,0,0];\ns.forEach(function(v){\n\ta[v]++;\n});\n\nvar ans = a[4];\n\nvar b=Math.min(a[3],a[1]);\na[3]-=b;\na[1]-=b;\nans+=b;\n\nb=Math.floor(a[2]/2);\na[2]-=2*b;\nans+=b;\n\nif(a[3]>0){\n\tans+=a[3];\n}\n\nif(a[2]>0){\n\ta[1]-=2;\n\ta[2]--;\n\tans++;\n}\nif(a[1]>0){\n\tans+=Math.ceil(a[1]/4);\n}\nprint(ans);"}, {"source_code": "\nvar n=+readline();\nvar s=readline().split(' ').map(function(v){return +v;});\n\nvar taxi=0;\nvar s3=0;\nvar s2=0;\nvar s1=0;\nfor(var i=0;i0){\n\t\t\ts1--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts3++;\n\t\t}\n\t}\n\tif(s[i]==2){\n\t\tif(s2>0){\n\t\t\ts2--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts2++;\n\t\t}\n\t}\n\tif(s[i]==1){\n\t\tif(s3>0){\n\t\t\ts3--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts1++;\n\t\t}\n\t}\n}\n\nif(s3>0){\n\ttaxi+=s3;\n}\nif(s2>0){\n\tif(s1>0){\n\t\ts1-=2;\n\t}\n\ts2--;\n\ttaxi++;\n}\nif(s1>0){\n\ttaxi+=Math.ceil(s1/4);\n}\nprint(taxi);"}, {"source_code": "var n = readline();\nvar mm = [0,0,0,0];\nvar inp = readline().split(\" \").map(function (t) {\n return parseInt(t);\n})\nfor (var i = 0;imm[0]){\n total+= mm[0];\n mm[2] -= mm[0]\n mm[0] = 0;\n}else{\n total+= mm[2];\n mm[0] -= mm[2]\n mm[2] = 0;\n}\nmm[1] += Math.ceil(mm[0]/2);\nmm[0] = 0;\n\ntotal += mm[2] + mm[0] + Math.ceil(mm[1]/2);\n\nwrite(total);"}, {"source_code": " var taxi=0;var one=0;var two=0;var three=0;\n var len = readline();\n var readitem = readline().split(' ');\n \nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n if(readitem[i] == \"3\"){three+=1;}\n if(readitem[i] == \"2\"){two+=2;}\n if(readitem[i] == \"1\"){one+=1;}}\n\n taxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=three;} \n one+=two\n while (one >= 4){one-= 4;taxi+=1;}\n if ((one>0)){taxi+=1;}\n print(taxi);\n"}, {"source_code": "function countTaxis(n,g){\n\tvar g4 = g.filter(function(a){return a == 4}).length, g3 = g.filter(function(a){return a == 3}).length, g2 = g.filter(function(a){return a == 2}).length, g1 = g.filter(function(a){return a == 1}).length;\n\tvar count;\n\n\tcount = g4;\n\n\tfor(i = 1; ; i++){\n\t\tif( g3 > 0 ){\n\t\t\tg3--;\n\t\t\tif( g1 > 0 ){\n\t\t\t\tg1--;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\telse if( g2 > 0 ){\n\t\t\tg2--;\n\t\t\tif( g2 > 0 ){\n\t\t\t\tg2--;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse if( g1 > 0 ){\n\t\t\t\tg1--;\n\t\t\t\tif( g1 > 0 ){\n\t\t\t\t\tg1--;\n\t\t\t\t\tcount++\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tcount++\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\telse if( g1 > 0 ){\n\t\t\tg1--;\n\t\t\tif( g1 > 0 ){\n\t\t\t\tg1--;\n\t\t\t\tif( g1 > 0 ){\n\t\t\t\t\tg1--;\n\t\t\t\t\tif( g1 > 0 ){\n\t\t\t\t\t\tg1--;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\twrite(count);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nvar n = +readline(), g = readline().split(\" \");\n\ncountTaxis(n,g);"}, {"source_code": "var x= parseInt(readline());\nvar arr=readline().split(' ').map(x => parseInt(x));\n\narr.sort((a,b) => a-b);\nvar taxis=0;\nvar i=0;\nvar j=x-1;\n\nwhile(i= a_1) {\n if(a_2 % 2 == 0)\n sum = a_4 + a_3 + Math.floor(a_2 / 2);\n else\n sum = a_4 + a_3 + Math.floor(a_2 / 2) + 1;\n}\nelse {\n if(((a_1 - a_3) + a_2 * 2) % 4 == 0)\n sum = a_4 + a_3 + Math.floor(((a_1 - a_3) + a_2 * 2) / 4);\n else\n sum = a_4 + a_3 + Math.floor(((a_1 - a_3) + a_2 * 2) / 4) + 1;\n}\nprint(sum);\n"}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction main() {\n const count = readline();\n var groupCount = {'1': 0, '2': 0, '3': 0, 4: 0};\n var groupArr = readline().split(\" \").map(elem => {\n groupCount[elem]++;\n return +elem;\n });\n var taxi = groupCount['4'] || 0;\n if (groupCount['3'] >= groupCount['2'] && Math.floor(groupCount['1']/2) < groupCount['2']) {\n if (groupCount['1'] >= groupCount['3']) {\n taxi += groupCount['3'];\n groupCount['1'] -= groupCount['3'];\n groupCount['3'] = 0;\n } else {\n taxi += groupCount['1'];\n groupCount['3'] -= groupCount['1'];\n groupCount['1'] = 0;\n }\n } \n if (groupCount['2']%2 === 1 && groupCount['1'] > 1) {\n taxi++;\n groupCount['2']--;\n groupCount['1']-= 2;\n }\n var floor2SecondGroup = Math.floor(groupCount['2']/2);\n taxi += floor2SecondGroup;\n groupCount['2'] -= floor2SecondGroup * 2;\n var floor2FirstGroup = Math.floor(groupCount['1']/2);\n if (floor2FirstGroup >= groupCount['2']) {\n taxi += groupCount['2'];\n groupCount['1'] -= groupCount['2'] * 2;\n groupCount['2'] = 0;\n } else {\n taxi += floor2FirstGroup;\n groupCount['2'] -= floor2FirstGroup;\n groupCount['1'] -= floor2FirstGroup * 2;\n }\n if (groupCount['1'] >= groupCount['3']) {\n taxi += groupCount['3'];\n groupCount['1'] -= groupCount['3'];\n groupCount['3'] = 0;\n } else {\n taxi += groupCount['1'];\n groupCount['3'] -= groupCount['1'];\n groupCount['1'] = 0;\n }\n if (groupCount['2'] > 0 && groupCount['1'] > 0) {\n taxi++;\n groupCount['2'] = 0;\n groupCount['1'] -= 1;\n }\n var floor4FirstGroup = Math.floor(groupCount['1']/4);\n taxi += floor4FirstGroup;\n groupCount['1'] -= floor4FirstGroup * 4;\n if (groupCount['1'] > 0) {\n taxi++;\n groupCount['1'] = 0;\n }\n var resultTaxi = taxi + groupCount['3'] + groupCount['2'] + groupCount['1'];\n print(resultTaxi);\n}"}, {"source_code": "readline(); var items = [0, 0, 0, 0, 0];\nreadline().split( '' ).forEach( function(it) {\n items[it]++;\n} );\n\nvar total = items[4] + items[3];\nitems[1] = Math.max( 0, items[1] - items[3] );\ntotal += Math.floor( items[2] / 2 );\nif (1 === items[2]%2) {\n total++;\n items[1] = Math.max( 0, items[1] - 2 );\n}\ntotal += Math.ceil( items[1] / 4 );\n\nprint( total );"}, {"source_code": "readline();\n\nvar car = [0,0,0,0,0];\nreadNums().map(v => car[v]++);\n\nvar m = Math.min(car[1], car[3]);\ncar[1] -= m;\ncar[3] -= m;\ncar[4] += m;\n\ncar[4] += Math.floor(car[2] / 2);\nif (car[2] & 1) {\n if (car[1] > 1) {\n car[1] -= 2\n car[2] = 0;\n car[4]++;\n } else if (car[1] > 0) {\n car[1]--;\n car[2] = 0;\n car[3]++;\n } else {\n car[2] = 1;\n }\n} else {\n car[2] = 0;\n}\n\nm = Math.ceil(car[1] / 4);\ncar[1] = 0;\ncar[4] += m;\n\nprint(car.reduce((a,b) => a + b));\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0)\n}\n"}, {"source_code": "groups = readline();\nkids = readline().split(' ');\nvar count1 = 0;\nvar count2 = 0;\nvar count3 = 0;\nvar count4 = 0;\ntaxi = 0\n\nfor(var i = 0; i < kids.length; ++i){\n if(kids[i] == 1)\n count1++;\n if(kids[i] == 2)\n count2++;\n if(kids[i] == 3)\n count3++;\n if(kids[i] == 4) {\n count4++;\n }\n}\n\n\n if(count1 > count3) {\n taxi = count3 + (Math.abs( count3 - count1) + count2*2 )/4 + count4\n print(Math.ceil(taxi));\n \n }\n else if( count3 > count1) {1\n taxi = count1 + Math.abs( count3 - count1) + (count2/2) + count4\n print(Math.ceil(taxi));\n \n }\n else {\n taxi = count3 + count2/2 + count4\n print(Math.ceil(taxi));\n \n \n }"}, {"source_code": "n = parseInt(readline());\nA = readline().split(\" \");\nA.sort(function(a,b){return parseInt(a) - parseInt(b)});\nl = 0;\nats = 0;\nfor (var i = n-1; i >= l; i--){\n\tsum = parseInt(A[i]);\n\twhile (sum + parseInt(A[l]) <= 4 && i != l){\n\t\tsum += parseInt(A[l]);\n\t\tl++;\n\t}\n\tats++;\n}\nwrite(ats);\n"}, {"source_code": "var a = readline();\nvar b = readline();\n\nvar b = b.split(' ');\nvar countTaxi = 0;\nvar c = [];\nc[1] = c[2] = c[3] = 0;\n\nb.forEach( function(item, key, arr) {\n if ( item == 4 ) countTaxi++;\n else c[ item ]++;\n});\n\nif ( c[2] > 2 ) {\n if ( c[2] % 2 == 0 ) {\n\tcountTaxi += c[2] / 2;\n\tc[2] = 0;\n } else {\n\tcountTaxi += Math.floor(c[2] / 2);\n\tc[2] = 2;\n }\n} else if ( c[2] == 2 ) {\n countTaxi++;\n c[2] = 0;\n}\n\nwhile ( c[1] > 0 && c[3] > 0 ) {\n c[1]--;\n c[3]--;\n countTaxi++;\n}\n\nwhile ( c[1] > 0 ) {\n c[1]--;\n c[2]++;\n if ( c[2] == 4 ) {\n\tcountTaxi++;\n\tc[2] = 0;\n } \n}\n\nif ( c[2] > 3 ) {\n if ( c[2] % 2 == 0 ) {\n\tcountTaxi += c[2] / 2;\n } else {\n\tcountTaxi += Math.floor(c[2] / 2) + 1;\n }\n} else if (c[2] > 0)\n countTaxi++;\n\nif ( c[1] > 3 ) {\n if ( c[1] % 4 == 0 ) {\n\tcountTaxi += c[1] / 4;\n } else {\n\tcountTaxi += Math.floor(c[1] / 4) + 1;\n }\n} else if ( c[1] > 0)\n countTaxi++;\n\ncountTaxi = countTaxi + c[3];\n\nprint(countTaxi);"}, {"source_code": "var n = parseInt(readline());\nvar numbersInput = readline().split(' ');\nvar groupsOne = 0;\nvar groupsTwo = 0;\nvar groupsThree = 0;\nvar taxis = 0;\n\nfor (var k = 0; k < n; k++) {\n var newGroup = parseInt(numbersInput[k]);\n if (newGroup === 4) {\n taxis++;\n } else if (newGroup === 1) {\n groupsOne++;\n } else if (newGroup === 2) {\n groupsTwo++;\n } else {\n groupsThree++;\n }\n}\n\ntaxis = taxis + ((groupsTwo / 2) >> 0);\ngroupsTwo = groupsTwo % 2;\n\nif (groupsTwo > 0 && groupsOne > 0) {\n groupsOne--;\n groupsOne--;\n groupsTwo--;\n taxis++;\n}\n\n//groupsTwo must be 0\nwhile (groupsOne > 0 && groupsThree > 0) {\n taxis++;\n groupsOne--;\n groupsThree--;\n}\n\n\nif (groupsOne <= 0) {\n taxis = taxis + groupsThree;\n groupsThree = 0;\n}\n\nwhile (groupsOne >= 4) {\n groupsOne = groupsOne - 4;\n taxis++;\n}\n\nif (groupsOne > 0) {\n taxis++;\n}\n\nif(groupsTwo > 0){\n\ttaxis++;\n\tgroupsTwo--;\n}\n\nprint(taxis);\n"}, {"source_code": "var readInts = function() {\n\treturn readline().split(' ').map(function(word) {\n\t\treturn parseInt(word)\n\t})\n}\n\nreadline()\n\nvar result = readInts().reduce(function(list, n) {\n\tlist[n] ++\n\treturn list\n}, [0, 0, 0, 0, 0])\n\nvar count = result[4] + result[3] + Math.floor(result[2] / 2)\n\nresult[1] -= result[3]\nif (result[1] < 0)\n\tresult[1] = 0\n\nif (result[2] % 2 == 1)\n\tresult[1] += 2\n\nif (result[1] > 0)\n\tcount += Math.ceil(result[1] / 4)\n\nprint(count)"}, {"source_code": "function solve(groupArray) {\n var z = [0, 0, 0, 0, 0];\n groupArray.forEach((i) => z[i] += 1);\n\n if (z[3] >= z[1]) {\n var seatThree = z[1];\n z[1] = 0;\n } else {\n seatThree = z[3];\n z[1] = z[1] - z[3];\n }\n z[3] = z[3] - seatThree;\n\n if (z[2]*2 >= z[1]) {\n var seatTwo = Math.ceil(z[1] / 2);\n z[1] = 0;\n } else {\n seatTwo = z[2];\n z[1] = z[1] - z[2]*2;\n }\n z[2] = z[2] - seatTwo;\n\n var seatTwo2 = Math.ceil(z[2] / 2);\n\n return z[4] + seatThree + z[3] + seatTwo + seatTwo2 + Math.ceil(z[1]/4);\n}\n\nreadline();\nprint(solve(readline().split(' ')));"}, {"source_code": ";(function () {\n\tvar t = [0, 0, 0, 0];\n\n\treadline();\n\treadline().split(' ').map(function (i) {t[4 - parseInt(i)]++;});\n\n\tvar c = t[0];\n\n\tvar m = Math.min(t[1], t[3]);\n\tc += m;\n\tt[1] -= m;\n\tt[3] -= m;\n\n\tc += Math.floor(t[2] / 2);\n\tt[2] -= 2 * Math.floor(t[2] / 2);\n\n\tc += Math.ceil((t[3] + t[2]*2)/4);\n\tc += t[1];\n\n\tprint(c);\n}).call(this);"}, {"source_code": "var scores = parseInt(readline());\nvar numm = readline().split(' ');\nvar sum, one, thr;\nsum = one = thr = 0;\nfor (var i = 0; i < scores; i++) {\n \n var num = parseInt(numm[i]);\n switch (num) {\n case 3:\n if (one > 0) {\n sum += 4;\n one--;\n }\n else {\n thr++;\n\n }\n break;\n\n case 1:\n if (thr > 0) {\n sum += 4;\n thr--;\n }\n else {\n one++;\n\n }\n break;\n\n default:\n sum += num;\n break;\n }\n}\nsum += one;\nprint(Math.ceil(sum / 4) + thr);"}, {"source_code": " function main(){\n var ans=0;\n var n=parseInt(readline());\n var arr=readline().split(' ');\n var m=[0,0,0,0,0];\n for(var i=0;i0){\n ans+=Math.ceil(m[1]/4);\n }\n print(ans);\n}\nmain();"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \").sort((x,y)=>x-y);\nvar taxi = 0;\nvar l = 0;\nfor(var i=n-1;i>=l;i--){\n\tvar sum = +str[i];\n\t while(+sum+Number(str[l]) <= 4){\n\t\t\t\t sum+= +str[l];\n\t\t\t\t\tl++\n\t\t\t}\n taxi++;\n}\nprint(taxi);"}, {"source_code": "var n = parseInt(readline());\nvar groups = readline().split(\" \");\nvar counters = [0, 0, 0, 0, 0];\nfor(var i = 0; i < n; i++) {\n var cur = parseInt(groups[i]);\n counters[cur]++;\n}\n\nvar result = 0;\nresult += counters[4];\n\nresult += counters[3]; \ncounters[1] = Math.max(counters[1] - counters[3], 0);\n\nresult += Math.floor(counters[2] / 2);\nif (counters[2] % 2 == 1) {\n result++;\n counters[1] = Math.max(counters[1] - 2, 0)\n}\n\nresult += Math.ceil(counters[1]/4);\n\nprint(result);"}, {"source_code": "var n = +readline();\nvar arrGroup = readline().split(' ');\nvar check1 = 0;\nvar check2 = 0;\nvar check3 = 0;\nvar check4 = 0;\nvar valCar = 0;\nfor(var i = 0; i < n; i++){\n\tarrGroup[i] = +arrGroup[i];\n}\nfor(var i = 0; i < n; i++){\n\tswitch(arrGroup[i]){\n\t\tcase 1: check1++;\n\t\t\tbreak;\n\t\tcase 2: check2++;\n\t\t\tbreak;\n\t\tcase 3: check3++;\n\t\t\tbreak;\n\t\tcase 4: check4++;\n\t\t\tbreak;\n\t}\n}\nvalCar += check4;\nif(check3 >= check1){\n\tvalCar += check3;\n\tcheck1 = 0;\n}else{\n\tvalCar += check3;\n\tcheck1 -= check3;\n}\nif(check2 % 2 == 0){\n\tvalCar = valCar + check2 / 2;\n\tif(check1 != 0 && check1 % 4 == 0)valCar = valCar + check1 / 4;\n\tif(check1 != 0 && check1 % 4 != 0)valCar = valCar + Math.floor(check1 / 4) + 1;\n}else{\n\tvalCar += Math.floor(check2 / 2);\n\tcheck2 = 1;\n\tif(check1 <= 2)valCar += 1;\n\tif(check1 > 2){\n\t\tvalCar += 1;\n\t\tcheck1 -= 2;\n\t\tif(check1 % 4 == 0)valCar = valCar + check1 / 4;\n\t\tif(check1 % 4 != 0)valCar = valCar + Math.floor(check1 / 4) + 1;\n\t}\n}\nprint(valCar);\n//print(check1 + ' ' + check2 + ' ' + check3 + ' ' + check4);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = 0,\n num2 = 0,\n num3 = 0,\n num4 = 0\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1++\n } break;\n case 2: {\n num2++\n } break;\n case 3: {\n num3++\n } break;\n case 4: {\n num4++\n } break;\n }\n }\n let allSum = num4\n if (num1 > 0 && num3 > 0) {\n if (num1 > num3) {\n const after = num1 - num3\n allSum += num3\n num1 = after\n num3 = 0\n } else if (num1 < num3) {\n const after = num3 - num1\n allSum += num1\n num1 = 0\n num3 = after\n } else {\n allSum += num1\n num1 = 0\n num3 = 0\n }\n } else if (num1 > 0 && num3 === 0) {\n const after = Math.floor(num1 / 4)\n const ostatok = ((num1 / 4) - after) * 4\n allSum += after\n num1 = ostatok\n } else if (num1 === 0 && num3 > 0) {\n allSum += num3\n num3 = 0\n }\n if (num2 > 0) {\n const after = Math.floor(num2 / 2)\n allSum += after\n const ostatok = ((num2 / 2) - after) * 2\n num2 = ostatok\n }\n if (num4 > 0) {\n num4 = 0\n }\n allSum += num3\n num3 = 0\n const check = (num2 + num1) / 4\n allSum += check >= 0.25 ? Math.ceil(check) : 0\n num1 = 0\n num2 = 0\n if (allSum === 33333) {\n allSum += 1\n }\n if (allSum === 62401) {\n allSum += 1\n }\n console.log(allSum)\n});"}, {"source_code": "\n var n = parseInt(readline()),\n sum = 0,\n l = 0,\n counter = 0;\n var line = readline().split(' ').map(el => parseInt(el));\n line.sort((a, b) => {\n return a - b;\n })\n for (var i = n - 1; i >= l; i--) {\n sum = line[i];\n while (sum + line[l] <= 4 && i != l) {\n sum += line[l];\n l++;\n }\n counter++;\n }\n print(counter);\n "}, {"source_code": "var groupOfOne =0,\n groupOfTwo = 0,\n groupOfThree = 0,\n numberOfGroup = readline(),\n numberOfGroupMembers = readline().split(\" \")\n result = 0;\nwhile(numberOfGroup--){\n switch(+numberOfGroupMembers[numberOfGroup]){\n case 1: groupOfOne++;\n break;\n case 2: groupOfTwo++;\n break;\n case 3: groupOfThree++;\n break;\n case 4: result++;\n \n }\n}\nif(groupOfThree>groupOfOne){\n if(groupOfTwo%2!==0){\n result+=groupOfThree + Math.ceil(groupOfTwo/2);\n }\n else{\n result+=groupOfThree + groupOfTwo/2;\n }\n}\nelse if(groupOfThree === groupOfOne){\n result+=groupOfThree + Math.ceil(groupOfTwo/2);\n}\nelse\n{\n result+=groupOfThree;\n if(groupOfTwo%2===0){\n result+=groupOfTwo/2+Math.ceil((groupOfOne-groupOfThree)/4);\n }\n else{\n result+=Math.ceil(groupOfTwo/2) +Math.ceil((groupOfOne-2-groupOfThree)/4);\n }\n}\nprint(result);"}, {"source_code": "var numberOfGroup = +readline()\n groups = readline().split(\" \").sort(),\n count = 0,\n j = 0;\nfor(var i = 0; i < groups.length; i++){\n groups[i] = +groups[i];\n}\nfor(var i = groups.length-1; i >= j; i--){\n var temp = groups[i];\n \n if(i===j)\n count++;\n else{\n while(temp+groups[j]<=4 && j 0)\n{\n\tcontainer['4']--;\n\ttaxis++;\n}\n\n//greedy 3\nwhile(container['3'] > 0)\n{\n\tcontainer['3']--;\n\tif(container['1'] > 0) container['1']--;\n\ttaxis++;\n}\n\n//greedy 2\nwhile(container['2'] > 0)\n{\n\tcontainer['2']--;\n\tif(container['2'] > 0)\n\t\tcontainer['2']--;\n\telse if(container['1'] > 0)\n\t{\n\t\tcontainer['1']--;\n\t\tif(container['1'] > 0) container['1']--;\n\t}\n\ttaxis++;\n}\n\n//greedy 1\nwhile(container['1'] > 0)\n{\n\tcontainer['1']--;\n\tif(container['1'] > 0) container['1']--;\n\tif(container['1'] > 0) container['1']--;\n\tif(container['1'] > 0) container['1']--;\n\ttaxis++;\n}\n\nprint(taxis);"}, {"source_code": "var n = parseInt(readline());\nvar container = {'1': 0, '2': 0, '3': 0, '4': 0};\nvar taxis = 0;\nvar groups = readline().split(' ').map(function(c){\n\tcontainer[c]++;\n});\n\n//greedy select\n\n//greedy 4\nwhile(container['4'] > 0)\n{\n\tcontainer['4']--;\n\ttaxis++;\n}\n\n//greedy 3\nwhile(container['3'] > 0)\n{\n\tcontainer['3']--;\n\tif(container['1'] > 0) container['1']--;\n\ttaxis++;\n}\n\n//greedy 2\nwhile(container['2'] > 0)\n{\n\tcontainer['2']--;\n\tif(container['2'] > 0)\n\t\tcontainer['2']--;\n\telse if(container['1'] > 0)\n\t{\n\t\tcontainer['1']--;\n\t\tif(container['1'] > 0) container['1']--;\n\t}\n\ttaxis++;\n}\n\n//greedy 1\nwhile(container['1'] > 0)\n{\n\tif(container['1'] > 0) container['1']--;\n\tif(container['1'] > 0) container['1']--;\n\tif(container['1'] > 0) container['1']--;\n\tif(container['1'] > 0) container['1']--;\n\ttaxis++;\n}\n\nprint(taxis);"}, {"source_code": "var readline = require('readline')\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nvar k = 2,\n rows = [];\n\nrl.on('line', function(line){\n rows.push(line)\n if (k === rows.length) {\n console.log(taxi(rows))\n rows.length = 0;\n }\n})\n\n// taxi\nfunction taxi(rows) {\n var group = rows[1].split(' '),\n arr4 = group.filter(a => a === '4'),\n arr3 = group.filter(a => a === '3'),\n arr2 = group.filter(a => a === '2'),\n arr1 = group.filter(a => a === '1'),\n car = arr4.length;\n\n if (arr3.length - arr1.length >= 0) {\n car += arr3.length + Math.ceil(arr2.length / 2)\n } else {\n arr1.length -= arr3.length\n car += arr3.length\n if (arr2.length % 2 === 0) {\n car += arr2.length / 2 + Math.ceil(arr1.length / 4)\n } else {\n if (arr1.length < 2) {\n car += Math.ceil((arr1.length + arr2.length) / 2)\n } else {\n arr1.length -= 2\n car += Math.ceil(arr2.length / 2) + Math.ceil(arr1.length / 4)\n }\n }\n }\n\n return car;\n}\n"}, {"source_code": "'use strict';\nconst n = readline();\nlet array = readline().replace(/\\s/g, '');\nlet taxiNum = 0;\nlet leftSpace = 4;\nwhile(array.length) {\n leftSpace -= parseInt(array[0]);\n array = array.replace(array[0], '');\n for (let i = leftSpace; i > 0; i--) {\n while(leftSpace && leftSpace - i >= 0 && array.indexOf(i) >= 0) {\n array = array.replace(i, '');\n leftSpace -= i;\n }\n }\n taxiNum++;\n leftSpace = 4;\n}\nwrite(taxiNum);"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\nvar input = readline();\nvar ninyos= readline().split(\" \");\nvar taxi1 = 0;\nvar taxi2 = 0;\nvar taxi3 = 0;\nvar taxis = 0;\n\nfor (var x = 0; x0){\n\t\t\ttaxi1--;\n\t\t\ttaxis++;\n\t\t}else{\n\t\t\ttaxi3++;\n\t\t}\n\t}\n\tif(ninyos[x]==2){\n\t\tif(taxi2>0){\n\t\t\ttaxi2--;\n\t\t\ttaxis++;\n\t\t}else{\n\t\t\ttaxi2++;\n\t\t}\n\t}\n\tif (ninyos[x]==1){\n\t\tif(taxi3>0){\n\t\t\ttaxi3--;\n\t\t\ttaxis++;\n\t\t}else{\n\t\t\ttaxi1++;\n\t\t}\n\t}\n}\n\nif (taxi3>0){\n\ttaxis+=taxi3;\n}\nif(taxi2>0){\n\tif(taxi1>0){\n\t\ttaxi1-=2;\n\t}\n\ttaxi2--;\n\ttaxis++;\n}\nif(taxi1>0){\n\ttaxis+=Math.ceil(taxi1/4);\n}\nprint(taxis);\n\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const groups = input[1].split(' ').map(x => parseInt(x));\n const countGroups = [0, 0, 0, 0];\n\n groups.forEach(g => countGroups[g-1] += 1);\n let taxi = countGroups[3];\n taxi += countGroups[2];\n\n if (countGroups[2] > 0 && countGroups[0] > 0) {\n if (countGroups[0] <= countGroups[2]) countGroups[0] = 0;\n else countGroups[0] -= countGroups[2];\n }\n\n if (countGroups[1] > 0) {\n if (countGroups[1] % 2 === 0) {\n taxi += countGroups[1]/2; countGroups[1] = 0;\n } else {\n taxi += (countGroups[1]-1)/2; countGroups[1] -= (countGroups[1]-1);\n }\n }\n\n if (countGroups[0] > 0) {\n if (countGroups[1] === 1 && countGroups[0] > 2) {\n taxi += 1; countGroups[1] = 0; countGroups[0] -= 2;\n } else if (countGroups[1] === 1 && countGroups[0] <= 2) {\n taxi += 1; countGroups[1] = 0; countGroups[0] = 0;\n }\n\n if (countGroups[0] > 0) {\n taxi += parseInt(Math.ceil(countGroups[0]/4));\n }\n }\n\n if (countGroups[1] > 0) {\n taxi += parseInt(Math.ceil(countGroups[1]/2));\n }\n\n\n console.log(taxi);\n});"}, {"source_code": "const { count } = require(\"console\");\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n const n = parseInt(input[0]);\n const allGroups = splitAndParseInt(input[1]);\n\n const countGroups = [0, 0, 0, 0];\n allGroups.forEach((gr) => {\n countGroups[gr - 1] += 1;\n });\n\n const [x, y, z, f] = countGroups;\n\n let answer =\n f +\n Math.min(x, z) +\n (z - Math.min(x, z)) +\n Math.ceil((x - Math.min(x, z) + (y % 2)*2) / 4) +\n Math.floor(y / 2);\n\nconsole.log(answer);\n});\n"}, {"source_code": "var input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let groups = input.split('\\r\\n')[1].replace(/\\D/g, '')\n let g = {1: 0, 2: 0, 3: 0, 4: 0}\n for (var i = 0; i < groups.length; i++) { g[groups[i]]++ }\n g[1] -= g[2] * 2 % 4\n g[1] -= g[3]\n console.log(g[4] + g[3] + Math.ceil(g[2]/2) + (g[1] > 0 ? Math.ceil(g[1]/4):0))\n})\n"}, {"source_code": "//var input = \"8\\n2 3 4 4 2 1 3 1\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n//\nfunction integerDivision(x, y){\n return (x - x % y) / y;\n}\n\nfunction main(){\n readline();\n var arr = readline().split(' ');\n var ans = 0;\n var a1 = 0, a2 = 0, a3 = 0;\n for(var i = 0; i < arr.length; i++){\n if(arr[i] == 4)\n ans++;\n else if(arr[i] == 1)\n a1++;\n else if(arr[i] == 2)\n a2++;\n else if(arr[i] == 3)\n a3++;\n }\n ans += integerDivision(a2, 2);\n a2 = a2 % 2;\n if(a1 >= a3){\n ans += a3;\n ans += integerDivision((a1 - a3) + a2 * 2, 4);\n if(((a1 - a3) + a2 * 2) % 4 != 0)\n ans++;\n }else{\n ans += a1 + (a3 - a1);\n if((a2 * 2) % 4 != 0)\n ans++;\n }\n print(ans);\n}\nmain();"}, {"source_code": "function readNumbers() {\n\treturn readline().split(' ').map(function (x) {\n\t\treturn parseInt(x);\n\t});\n}\n\nvar n = readline();\nvar groups = readNumbers();\n\nvar total = [undefined, 0, 0, 0, 0];\n\nfor (var i = 0; i < n; i++) {\n\ttotal[groups[i]]++;\n}\n\nvar count = total[4];\n\ncount += total[3];\n\ntotal[1] = total[1] > total[3]\n\t? total[1] - total[3]\n\t: 0;\n\ncount += Math.floor(total[2] / 2);\n\nif (total[2] % 2) {\n\ttotal[1] += 2;\n}\n\ncount += Math.ceil(total[1] / 4);\n\nprint(count);"}, {"source_code": "let fs = require('fs')\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\nfor (let i = 1; i < txt.length; i += 2) {\n let info = txt[i].split(\" \").filter(data => {\n return data.length > 0\n }).map(data => {\n return data * 1\n }).sort((a, b) => {\n return b - a\n });\n doit(info)\n}\n\nfunction doit(tab) {\n let t = []\n let taxi = 0;\n for (let index = 4; index > 0; index--) {\n t.push(tab.filter(data => {\n return data == index\n }).length);\n }\n taxi += t[0];\n taxi += t[1]\n t[3] -= t[1];\n if (t[3] < 0) t[3] = 0;\n taxi += Math.floor(t[2] / 2);\n t[2] = t[2] % 2;\n if (t[2] == 1) {\n ++taxi;\n t[3] -= 2;\n if (t[3] < 0) t[3] = 0;\n }\n taxi += Math.floor(t[3] / 4);\n t[3] = t[3] % 4;\n if (t[3] != 0) ++taxi;\n console.log(taxi);\n}"}, {"source_code": "input=readline();\ninput=readline();\ninput = input.split(' ').map(e=>parseInt(e));\ntmp=[0,0,0,0,0];\ninput.forEach(element => {\n tmp[element]++;\n});\ntmp[1] = (tmp[1]>tmp[3])?tmp[1]-tmp[3]:0;\nprint(tmp[4] + tmp[3] + Math.floor( (tmp[1] + 2*tmp[2] + 3)/4))"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n car_q[parseInt(mas[i])-1] ++;\n}\ncars += car_q[3];\nif(car_q[0] >= car_q[2])\n{\n cars += car_q[2];\n car_q[0] -= car_q[2];\n}\nelse\n{\n cars += car_q[2];\n car_q[0] = 0; \n}\ncars += Math.ceil(car_q[1]/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n car_q[0] --;\n if(car_q[0] != 0){car_q[0] --;}\n}\ncars += Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "n=readline();\ns=readline().split(' ').map(v=>+v);\nvar hash={1:0,2:0,3:0,4:0};\nfor(var i=0;i0) hash[1]--;\n\ttaxis++;\n}\nwhile(hash[2]--){\n\tif(hash[2]>0) hash[2]--;\n\telse{\n\t\tif(hash[1]>0) hash[1]--;\n\t\tif(hash[1]>0) hash[1]--;\n\t} \n\ttaxis++;\n}\nwhile(hash[1]--){\n\tif(hash[1]>0) hash[1]--;\n\tif(hash[1]>0) hash[1]--;\n\tif(hash[1]>0) hash[1]--;\n\ttaxis++;\n}\nprint(taxis);"}, {"source_code": "var n = readline();\n\nvar arr = readline().split(' ');\n\nvar ans = [0,0,0,0,0];\n\nfor(var i in arr){\n\tvar idx = parseInt(arr[i]);\n\tans[idx]++;\n\t\n}\n\nvar sum = 0;\n\nsum = Math.min(ans[1],ans[3]);\n\nans[1] -= sum;\nans[3] -= sum;\n\nsum += ans[3];\nsum += ans[4];\n\nsum += Math.floor(ans[1]/4);\nans[1] %= 4;\n\nsum += Math.floor(ans[2]/2);\nans[2] %= 2;\n\nif(ans[2] > 0){\n\tsum += 1;\n\tans[1] -= 2;\n\tans[2] = 0;\n}\n\nif(ans[1] > 0)\n\tsum += 1;\n\nprint(sum);\n\n\t"}, {"source_code": "var linenum = parseInt(readline());\nvar map = {\n '4': 0,\n '3': 0,\n '2': 0,\n '1': 0\n}, taxi = 0;\nvar groups = readline().split(' ').map(function(numStr){\n map[numStr] = map[numStr] + 1;\n return parseInt(numStr);\n});\n\ntaxi += map['4'];\ntaxi += Math.floor(map['2'] / 2);\nmap['2'] = map['2'] % 2;\ntaxi += map['3'];\nif(map['3'] >= map['1']){\n taxi += map['2'];\n}else{\n map['1'] -= map['3'];\n if(map['2'] > 0){\n taxi += 1;\n if(map['1'] >= 2){\n map['1'] -= 2;\n taxi += Math.ceil(map['1'] / 4);\n }\n }else{\n taxi += Math.ceil(map['1'] / 4);\n }\n}\n\nprint(taxi);\n"}, {"source_code": "\nvar num = readline();\nvar nums = readNums();\n\nvar k = 0;\n\nnums.sort(function(a,b){return b-a});\n\nwhile (1) {\n\t\n\tif (nums.length == 0) {\n\t\tbreak;\n\t}\n\t\n\tvar firstObj = nums.shift();\n\n\tif (firstObj == 4) {\n\t\tk++;\n\t}else{\n\t\t\n\t\tvar endObj = nums.pop();\n\t\t\n\t\tif (firstObj+endObj<4) {\n\t\t\tnums.unshift(firstObj+endObj);\n\t\t}else if (firstObj+endObj>4) {\n\t\t\tnums.push(endObj);\n\t\t\tk++;\n\t\t}else{\n\t\t\tk++;\n\t\t}\n\t}\n\n}\n\nprint(k);\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}], "negative_code": [{"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = 0,\n num2 = 0,\n num3 = 0,\n num4 = 0\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1++\n } break;\n case 2: {\n num2++\n } break;\n case 3: {\n num3++\n } break;\n case 4: {\n num4++\n } break;\n }\n }\n let allSum = num4\n if (num1 > 0 && num3 > 0) {\n if (num1 > num3) {\n const after = num1 - num3\n allSum += num3\n num1 = after\n num3 = 0\n } else if (num1 < num3) {\n const after = num3 - num1\n allSum += num1\n num1 = 0\n num3 = after\n } else {\n allSum += num1\n num1 = 0\n num3 = 0\n }\n } else if (num1 > 0 && num3 === 0) {\n const after = Math.floor(num1 / 4)\n const ostatok = ((num1 / 4) - after) * 4\n allSum += after\n num1 = ostatok\n } else if (num1 === 0 && num3 > 0) {\n allSum += num3\n num3 = 0\n }\n if (num2 > 0) {\n const after = Math.floor(num2 / 2)\n allSum += after\n const ostatok = ((num2 / 2) - after) * 2\n num2 = ostatok\n }\n if (num4 > 0) {\n num4 = 0\n }\n allSum += num3\n num3 = 0\n const check = (num2 + num1) / 4\n allSum += check >= 0.25 ? Math.ceil(check) : 0\n num1 = 0\n num2 = 0\n if (allSum === 33333) {\n allSum += 1\n }\n console.log(allSum)\n});"}, {"source_code": "let fs = require('fs')\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\nfor (let i = 1; i < txt.length; i += 2) {\n let info = txt[i].split(\" \").filter(data => {\n return data.length > 0\n }).map(data => {\n return data * 1\n }).sort((a, b) => {\n return b-a\n });\n doit(info)\n}\n\nfunction doit(tab) {\n let count = 0;\n let taxi = 0;\n while (tab.length > 0) {\n count+=tab.shift()\n if(count==4){\n ++taxi;\n count=0;\n }else if(count+tab[tab.length-1]>4){\n count=0;\n ++taxi;\n }else if(tab.length==0){\n ++taxi;\n }else{\n let r=tab.includes(4-count)\n if(r!=-1) {\n tab.splice(tab.indexOf(4-count),1);\n count=0;\n ++taxi\n }\n }\n }\n console.log(taxi);\n\n}"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\n//var input = 5;\n//var input2 = new Array(1,2,4,3,3)\nvar lleno3 = 0;\nvar cont4 = 0;\nvar ninyos = 0;\n\nfor (var x = 0; x 0) {\n h = a;\n j++;\n } else {\n h = 4;\n j++;\n }\n}\n\nif(d>=1){\n print(c);\n} else if ((d < 1) && ((c+1) <= r)) {\n print(c+1);\n} else {\n print(r);\n}\n"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').sort(function(a,b){return b-a;});\nfor(var i=0, j=n-1; i<=j; i++){\n if(i parseInt(el));\n line.sort((a, b) => {\n return a - b;\n })\n for (var i = n - 1; i >= l; i--) {\n sum = line[i];\n while (sum + line[l] <= 4 && i != 1) {\n sum += line[l];\n l++;\n }\n counter++;\n }\n print(counter);\n "}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n car_q[parseInt(mas[i])-1] ++;\n}\nprint(typeof(cars));\ncars += car_q[3];\nif(car_q[0] >= car_q[2])\n{\n cars += car_q[2];\n car_q[0] -= car_q[2];\n}\nelse\n{\n cars += car_q[2];\n car_q[0] = 0; \n}\ncars += Math.ceil(car_q/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n car_q[0] --;\n}\ncars += Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n sum += (_1 - (_1 - _3));\n _1 = (_1 - _3);\n sum += Math.floor(_2/2);\n sum += Math.floor(_1/4);\n if(_2 % 2 !== 0 && _1 % 4 <= 2 && _1 % 4 != 0){\n sum += 1;\n } else if(_2 % 2 !== 0 && _1 % 4 > 2){\n sum += 2;\n } else if(_2 % 2 === 0 && _1 % 4 != 0){\n\t\t\tsum += 1;\n\t\t} \n }\n\nprint(sum);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peopleMain] = input\n count = parseInt(count)\n people = peopleMain.split(' ')\n let sub = []\n let countOne = 0\n const replace = (idA, idB, count) => {\n if (idA !== idB) {\n people[idA] = 0\n people[idB] = 0\n sub.push(count)\n }\n }\n let stopCheck = false\n for (let i = 0; i < count; i++) {\n const person = parseInt(people[i])\n if (person < 4) {\n stopCheck = false\n switch (person) {\n case 1: {\n const findNum = 3\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n countOne++\n }\n } break;\n case 2: {\n const findNum = 2\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n sub.push(person)\n }\n } break;\n case 3: {\n const findNum = 1\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n sub.push(person)\n }\n } break;\n }\n } else {\n people[i] = 0\n sub.push(person)\n }\n }\n const ostatok = Math.ceil(countOne / 4)\n console.log(sub.length + ostatok)\n});"}, {"source_code": "var s = readline().replace(/\\D/g, '')\nvar g = [0,0,0,0,0]\nfor (var i = 0; i < s.length; i++) { g[s[i]]++ }\ng[1] -= g[3]\nif (g[3] < 1) g[3] = 0\nprint(g[4] + g[3] + Math.ceil((g[2] * 2 + g[1]) / 4))"}, {"source_code": "var groupOfOne =0,\n groupOfTwo = 0,\n groupOfThree = 0,\n numberOfGroup = readline(),\n numberOfGroupMembers = readline().split(\" \")\n result = 0;\nwhile(numberOfGroup--){\n switch(+numberOfGroupMembers[numberOfGroup]){\n case 1: groupOfOne++;\n break;\n case 2: groupOfTwo++;\n break;\n case 3: groupOfThree++;\n break;\n case 4: result++;\n \n }\n}\nif(groupOfThree>groupOfOne){\n if(groupOfTwo%2!==0){\n result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne-1)/4);\n }\n else{\n result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne)/4);\n }\n}\nelse if(groupOfThree === groupOfOne){\n result+=groupOfThree + groupOfTwo/2;\n}\nelse\n{\n result+=groupOfThree;\n if(groupOfTwo%2===0){\n result+=groupOfTwo/2+Math.ceil(groupOfOne/4);\n }\n else{\n result+=groupOfTwo/2 +Math.ceil((groupOfOne-1)/4);\n }\n}\nprint(result);"}, {"source_code": "const { count } = require(\"console\");\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n const n = parseInt(input[0]);\n const allGroups = splitAndParseInt(input[1]);\n\n const countGroups = [0, 0, 0, 0];\n allGroups.forEach((gr) => {\n countGroups[gr - 1] += 1;\n });\n\n const [x, y, z, f] = countGroups;\n\n let answer =\n f +\n Math.min(x, z) +\n Math.min(z - Math.min(x, z), z - Math.min(x, z) + (y % 2)) +\n Math.ceil((x - Math.min(x, z) + (y % 2)) / 4) +\n Math.floor(y / 2);\n\n console.log(answer);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = []\n let num2 = []\n let num3 = []\n let num4 = []\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1.push(el)\n } break;\n case 2: {\n num2.push(el)\n } break;\n case 3: {\n num3.push(el)\n } break;\n case 4: {\n num4.push(el)\n } break;\n }\n }\n let allSum = num4.length\n let notRegister = 0\n if (num1.length > 0 && num3.length > 0) {\n if (num1.length > num3.length) {\n let after = num1.length - num3.length\n // let ostatok = 0\n if (after >= 4) {\n const one = Math.floor(after / 4)\n ostatok = ((after / 4) - one) * 4\n // console.log(one)\n allSum += one\n } else {\n notRegister += after\n }\n // console.log(ostatok)\n // console.log(after)\n allSum += num1.length - after\n // notRegister += ostatok\n } else if (num1.length < num3.length) {\n const after = num3.length - num1.length\n const ostatok = (num3.length - after) * 3\n allSum += after\n notRegister += ostatok\n } else {\n allSum += num1.length\n }\n } else if (num1.length === 0 && num3.length > 0) {\n allSum += num3.length\n } else if (num1.length > 0 && num3.length === 0) {\n const after = Math.floor(num1.length / 4)\n const ostatok = Math.ceil((num1.length / 4) - after)\n allSum += after\n notRegister += ostatok\n }\n if (num2.length > 0) {\n if ((num2.length / 2) > 1) {\n const after = Math.floor(num2.length / 2)\n const ostatok = ((num2.length / 2) - after) * 2\n allSum += after\n notRegister += ostatok\n } else {\n notRegister += num2.length * 2\n }\n }\n // console.log([allSum,notRegister])\n allSum += Math.ceil(notRegister / 4)\n console.log(allSum)\n});"}, {"source_code": "var n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else { _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n sum += (_1 - (_1 - _3));\n _1 = (_1 - _3);\n sum += Math.floor(_2/2);\n sum += Math.floor(_1/4);\n if(_2 % 2 !== 0 && _1 % 4 <= 2){\n sum += 1;\n } else if(_2 % 2 !== 0 && _1 % 4 > 2){\n sum += 2;\n } else if(_2 % 2 === 0){\n\t\t\tsum += 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "var taxi=0;\n var one=0;\n var two=0;\n var three=0;\n\tvar len = readline();\n\tvar readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}}\n\ttaxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=(one-three);} \n \n if((two%2)!=0){\n two-=1;\n one+=1;}\n\n if(two>0){taxi+=(two/2);}\n\t while (one >= 4){\n one-= 4;\n taxi+=1;}\n if (one>0){taxi+=1;}\n print(taxi);\t\t\t\t\n"}, {"source_code": "var pasar = readline();\nvar entrada = readline().split(\" \");\nvar taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0, c_dos = 0;\nfor (var i = 0; i < entrada.length; i++){\n entrada[i] = parseInt(entrada[i]);\n if (entrada[i] == 1){\n c_unos++;\n } else if (entrada[i] == 2){\n c_dos++;\n } else if (entrada[i] == 3){\n c_tres++;\n } else if (entrada[i] == 4){\n taxis++;\n }\n}\nif (c_tres == c_unos){\n taxis += c_tres;\n c_unos = 0;\n} else if (c_tres > c_unos){\n taxis += c_unos + (c_tres - c_unos);\n c_unos = 0;\n} else if (c_tres < c_unos) {\n taxis += c_tres;\n c_unos = c_unos - c_tres;\n}\ntaxis += parseInt(c_dos / 2);\nif (c_dos % 2 !== 0){\n if (c_unos >= 2){\n c_dos = 0;\n c_unos -= 2;\n }\n taxis += 1;\n}\ntaxis += parseInt(c_unos / 4) + c_unos % 4;\n\nprint (taxis);\n"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nprint(typeof(car_q[0]));\nfor(var i = 0; i < n; ++i)\n{\n car_q[parseInt(mas[i])-1] ++;\n}\ncars += car_q[3];\nif(car_q[0] >= car_q[2])\n{\n cars += car_q[2];\n car_q[0] -= car_q[2];\n}\nelse\n{\n cars += car_q[2];\n car_q[0] = 0; \n}\ncars += Math.ceil(car_q/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n car_q[0] --;\n}\ncars += Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "var n = parseInt(readline());\n\nvar gFour = 0;\nvar gThree = 0;\nvar gTwo = 0;\nvar gOne = 0;\n\nvar gList = readline();\n\nfor(var i = 0; i < gList.length; i++){\n if (gList[i] === '4'){\n gFour++;\n } else if (gList[i] === '3'){\n gThree++;\n } else if (gList[i] === '2'){\n gTwo++;\n } else if (gList[i] === '1'){\n gOne++;\n }\n}\n\nvar v1 = 0;\n\nvar gOne2 = 0\nif (gThree > gOne) {\n v1 = gOne + ( gThree - gOne);\n} else if (gThree < gOne){\n v1 = gThree;\n gOne2 = gOne - gThree;\n} else if( gThree === gOne){\n v1 = gThree;\n}\n\nvar v2 = 0;\n\nvar gTwo2 = 0;\nif(gTwo % 2 === 0){\n v2 = gTwo / 2;\n} else {\n v2 = Math.floor(gTwo / 2);\n gTwo2 = 1;\n}\n\nvar v3 = 0;\n\nif (gTwo2 != 0 && gOne2 !== 0){\n if (gOne2 <= 2) {\n v3 = 1;\n } else {\n v3 = 1 + Math.ceil((gOne - 2) / 4); \n }\n} else if (gTwo2 === 0 && gOne2 !== 0){\n v3 = Math.ceil(gOne / 4);\n} else if(gTwo2 != 0 && gOne2 === 0){\n v3 = 1;\n}\n\n\nvar tax = gFour + v1 + v2 + v3;\n\nprint(tax);"}, {"source_code": "var n = parseInt(readline());\nvar groups = readline().split(\" \");\nvar counters = [0, 0, 0, 0, 0];\nfor(var i = 0; i < n; i++) {\n var cur = parseInt(groups[i]);\n counters[cur]++;\n}\n\nvar result = 0;\nresult += counters[4];\n\nresult += counters[3]; \ncounters[1] = Math.max(counters[1] - counters[3], 0);\n\nresult += Math.floor(counters[2] / 2);\nif (counters[2] %2 == 1) {\n result++;\n counters[1] = Math.max(counters[1] - 1, 0)\n}\n\nresult += Math.ceil(counters[1]/4);\n\nprint(result);\n\n\n\n\n"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x=3){\n\t\tcont++;\n\t}else {\n\t\tninyos+=parseInt(input[x]);\n\t}\n\t\n\t\t\n}\n\nprint(Math.floor(ninyos/4)+cont);"}, {"source_code": "var n = readline();\nn = parseInt(n);\nvar sn = readline();\nvar a = [];\na = sn.split(' ');\nvar i, a_1 = 0, a_2 = 0, a_3 = 0, a_4 = 0, num = 0;\nfor(i = 0; i < n; i++) {\n a[i] = parseInt(a[i]);\n}\nfor(i = 0; i < n; i++) {\n if(a[i] == 4)\n a_4++;\n else {\n if(a[i] == 3)\n a_3++;\n else {\n if(a[i] == 2) \n a_2++;\n else\n a_1++;\n }\n }\n}\nif(a_3 >= a_1) {\n if(a_2 % 2 == 0)\n sum = a_4 + a_3 + Math.floor(a_2 / 2);\n else\n sum = a_4 + a_3 + Math.floor(a_2 / 2) + 1;\n}\nelse {\n if(((a_1 - a_3) + a_2) % 4 == 0)\n sum = a_4 + a_3 + Math.floor(((a_1 - a_3) + a_2) / 4);\n else\n sum = a_4 + a_3 + Math.floor(((a_1 - a_3) + a_2) / 4) + 1;\n}\nprint(sum);\n"}, {"source_code": "var n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else { _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n sum += (_1 - (_1 - _3));\n _1 = (_1 - _3);\n sum += Math.floor(_2/2);\n sum += Math.floor(_1/4);\n if(_2 % 2 !== 0 && _1 % 4 <= 2){\n sum += 1;\n } else if(_2 % 2 !== 0 && _1 % 4 > 2){\n sum += 2;\n } else if(_2 % 2 === 0 && _1 != 0){\n\t\t\tsum += 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar taxis = ninyos/4;;\nfor (var x = 0; x input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = []\n let num2 = []\n let num3 = []\n let num4 = []\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1.push(el)\n } break;\n case 2: {\n num2.push(el)\n } break;\n case 3: {\n num3.push(el)\n } break;\n case 4: {\n num4.push(el)\n } break;\n }\n }\n let allSum = num4.length\n let notRegister = 0\n if (num1.length > 0 && num3.length > 0) {\n if (num1.length > num3.length) {\n let after = num1.length - num3.length\n if (after >= 4) {\n const one = Math.floor(after / 4)\n ostatok = ((after / 4) - one) * 4\n allSum += one\n } else {\n notRegister += after\n }\n allSum += num1.length - after\n } else if (num1.length < num3.length) {\n const after = num3.length - num1.length\n const ostatok = (num3.length - after) * 3\n allSum += after\n notRegister += ostatok\n } else {\n allSum += num1.length\n }\n } else if (num1.length === 0 && num3.length > 0) {\n allSum += num3.length\n } else if (num1.length > 0 && num3.length === 0) {\n const after = Math.floor(num1.length / 4)\n const ostatok = Math.ceil((num1.length / 4) - after)\n allSum += after\n notRegister += ostatok\n }\n if (num2.length > 0) {\n const after = Math.floor(num2.length / 2)\n allSum += after\n const ostatok = ((num2.length / 2) - after) * 4\n notRegister += ostatok\n }\n // console.log([allSum,notRegister])\n allSum += Math.ceil(notRegister / 4)\n console.log(allSum)\n});"}, {"source_code": "var r = readline();\nvar l = readline().split(' ');\n \nvar one = 0;\nvar two = 0;\nvar three = 0;\nvar four = 0;\n \nfor (var i = 0; i< r; i++){\n if(parseInt(l[i]) === 1){\n one++;\n } \n if(parseInt(l[i]) === 2){\n two++;\n } \n if(parseInt(l[i]) === 3){\n three++;\n } \n if(parseInt(l[i]) === 4){\n four++;\n } \n}\n\nvar c = four;\nwhile(three > 0){\n if(one > 0){\n three--;\n one--;\n c++;\n} else {\n three--;\n c++;\n}\n}\nwhile(two >= 2){\n two= two - 2;\n c++;\n}\nwhile(two > 0){\n if(one > 0){\n two--;\n one = one -2;\n c++;\n } else {\n two--;\n c++;\n }\n}\nif(one > 0){\n c++;\n}\nprint(c);\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peopleMain] = input\n count = parseInt(count)\n people = peopleMain.split(' ')\n let sub = []\n const replace = (idA, idB, count) => {\n if (idA !== idB) {\n people[idA] = 0\n people[idB] = 0\n sub.push(count)\n }\n }\n for (let b = 0; b < people.length; b++) {\n stopCheck = false\n const el = parseInt(people[b])\n if (el > 0) {\n for (let c = 0; c < people.length; c++) {\n if (stopCheck === false) {\n if (b !== c) {\n const _el = parseInt(people[c])\n if ((parseInt(people[b]) + _el) <= 4) {\n people[c] = 0\n people[b] = parseInt(people[b]) + _el\n }\n }\n }\n }\n }\n }\n const finis = people.filter((el) => el > 0)\n const finishAll = sub.filter((el) => el > 0)\n console.log(finis.length + finishAll.length)\n});"}, {"source_code": "var x= parseInt(readline());\nvar arr=readline().split(' ').map(x => parseInt(x));\n\narr.sort((a,b) => a-b);\nvar taxis=0;\nvar rem=0;\nfor(var i=0; i0)\n taxis++;\n\nprint(taxis);\n"}, {"source_code": "var num = parseInt(readline()),\n group = readline().split(' ').map(el => parseInt(el)),\n counter = 0;\nfor (var i = 0; i < group.length; i++) {\n if (group[i] == 4) {\n counter++;\n group.splice(i, 1);\n i = -1;\n continue;\n }\n for (var j = 1; j < group.length; j++) {\n if (i == -1) i++;\n if (i == j) continue;\n if (group[i] + group[j] == 4) {\n counter++;\n group.splice(i, 1);\n group.splice(j - 1, 1);\n i = -1, j = 0;\n }\n if (group.length == 0) {\n break;\n }\n }\n for (var a = 0; a < group.length; a++) {\n if (group[a] == 1 && group[a + 1] < 3 || group[a] < 3 && group[a + 1] == 1) {\n group[a] += group[a + 1];\n group.splice(a + 1, 1);\n }\n }\n}\n\nprint(counter + group.length);"}, {"source_code": "var num1 = parseInt(readline());\nvar sum , one , thr;\nsum = one = thr = 0;\nfor(var i = 0 ; i < num1 ; i++)\n{\n var num = parseInt(readline());\n switch (num) {\n case 3:\n if (one > 0 ) {\n sum+=4;\n one--;\n }\n else\n {\n thr++;\n \n }\n break;\n \n case 1:\n if (thr > 0) {\n sum += 4;\n thr--;\n }\n else {\n one++;\n \n }\n break;\n \n default:\n sum += num;\n break;\n }\n}\nsum += one ;\nprint(Math.ceil(sum/4)+thr);"}, {"source_code": "function Programa(){\n var pasar = readline();\n var entrada = readline().split(\" \");\n var taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0;\n for (var i = 0; i < entrada.length; i++){\n cantidad_de_pibes += parseInt(entrada[i]);\n if (entrada[i] == \"1\"){\n c_unos++;\n } else if (entrada[i] == \"3\"){\n c_tres++;\n }\n }\n if (cantidad_de_pibes % 4 > 0){\n taxis += parseInt(cantidad_de_pibes / 4) + 1;\n } else {\n if (c_tres != c_unos){\n taxis += parseInt(cantidad_de_pibes / 4) + 1;\n } else {\n taxis += parseInt(cantidad_de_pibes / 4);\n }\n }\n \n print (taxis);\n}\nPrograma();"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x=3){\n\t\tcont++;\n\t}else {\n\t\tninyos+=parseInt(input[x]);\n\t}\n\t\n\t\t\n}\n\nprint(Math.floor(ninyos/4)+cont);"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main(){\n var n = readline();\n var arr = readNumArray();\n var car = 0;\n var one = 0;\n var two = 0;\n var three = 0;\n var four = 0;\n for (var i = 0; i < arr.length; i++) {\n if(arr[i] == 1) one++;\n else if(arr[i] == 2) two++;\n else if(arr[i] == 3) three++;\n else if(arr[i] == 4) four++;\n }\n car += four;\n four = 0;\n minn = Math.min(three,one);\n car += minn;\n three -= minn;\n one -= minn;\n if(two >= 2){\n car += two/2\n two = two%2\n }\n car += three\n if(one > 0){\n if(two > 0){\n two -= 1\n one -= 2\n car += 1\n }\n }\n if(one > 0){\n car += one/4\n if(one%4 != 0) car +=1;\n }\n if(two > 0) car += 1;\n print(car)\n}\nmain();\n"}, {"source_code": "\n var taxi=0;var one=0;var two=0;var three=0;\n var len = readline();\n //var ajx = \"3 1 2 1 1 1 1 1 1\";\n var readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n if(readitem[i] == \"3\"){three+=1;}\n if(readitem[i] == \"2\"){two+=1;}\n if(readitem[i] == \"1\"){one+=1;}}\n\n taxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=three;} \n \n if((two%2)!=0){two-=1;one+=1;}if(two>0){taxi+=(two/2);two=0;} \n\n \n \n if(two!=0){\n while((two > 0)&&(two < 4)&&(one > 0)){one -=1; two +=1;}\n \n }\n \n if((two%2)!=0){two-=1;one+=1;}\n if(two>=1){taxi+=(two/2);}\n\n\n while (one >= 4){one-= 4;taxi+=1;}\n if ((two>0)){taxi+=1;}\n if ((one>0)){taxi+=1;}\n\n\n print(taxi);\n\n"}, {"source_code": "var n = readline();\nvar groups = readline().split(' ').sort();\nvar carCount = 0;\n\nvar countStruct = {\n 1: 0,\n 2: 0,\n 3: 0\n};\n\nfor (var i = 0; i < groups.length; i++) {\n if (groups[i] == 4) {\n carCount++;\n } else if (groups[i] == 3) {\n countStruct[3]++;\n } else if (groups[i] == 2) {\n countStruct[2]++;\n } else if (groups[i] == 1) {\n countStruct[1]++;\n }\n}\n\nwhile(countStruct[3] > 0 && countStruct[1] > 0){\n countStruct[1]--;\n countStruct[3]--;\n carCount++;\n}\n\nwhile(countStruct[2] > 0 && countStruct[1] > 0){\n countStruct[1]--;\n countStruct[2]--;\n countStruct[3]++;\n}\n\nwhile(countStruct[3] > 0 && countStruct[1] > 0){\n countStruct[1]--;\n countStruct[3]--;\n carCount++;\n}\n\n\n\n\ncarCount += countStruct[3];\ncarCount += Math.ceil(countStruct[2]/4);\ncarCount += Math.ceil(countStruct[1]/4);\n\nprint(carCount);"}, {"source_code": "n = readline();\nstr = readline().split(' ').map(Number);\n\nvar count = 0;\n\nfor (var i = 0; i < str.length; i++) {\n\tcount += str[i];\n};\n\nif (count % 4 !== 0) {\n\tprint(Math.floor(count / 4) + 1);\n} else {\n\tprint(count / 4);\n};\n\n"}, {"source_code": "function Programa(){\n var pasar = readline();\n var entrada = readline().split(\" \");\n var taxis = 0, cantidad_de_pibes = 0;\n for (var i = 0; i < entrada.length; i++){\n cantidad_de_pibes += parseInt(entrada[i]);\n }\n taxis += parseInt(cantidad_de_pibes / 4) + 1;\n print (taxis);\n}\nPrograma();"}, {"source_code": "\nvar num = readline();\nvar nums = readNums();\n\nvar k = 0;\n\nnums.sort(function(a,b){return b-a});\n\nwhile (1) {\n\t\n\tif (nums.length == 0) {\n\t\tbreak;\n\t}\n\t\n\tvar firstObj = nums.shift();\n\tvar endObj = nums.pop();\n\t\t\n\tif (firstObj == 4) {\n\t\tk++;\n\t}else{\n\t\tif (firstObj+endObj<4) {\n\t\t\tnums.unshift(firstObj+endObj);\n\t\t}else if (firstObj+endObj>4) {\n\t\t\tnums.push(endObj);\n\t\t\tk++;\n\t\t}else{\n\t\t\tk++;\n\t\t}\n\t}\n\n}\n\nprint(k);\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}, {"source_code": "var kids = 0;\nreadline();\nreadline().split(' ').map(function(c){\n\tkids += parseInt(c);\n});\n\nprint(Math.ceil(kids / 4));\n"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').sort();\nfor(var i=n-1, j=0; i>=j; i--){\n if(i===j) continue;\n if(s[i]+s[j]<=4) j++;\n}\nprint(i);"}, {"source_code": "\nvar n=+readline();\nvar s=readline().split(' ').map(function(v){return +v;});\n\nvar taxi=0;\nvar s3=0;\nvar s2=0;\nvar s1=0;\nfor(var i=0;i0){\n\t\t\ts1--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts3++;\n\t\t}\n\t}\n\tif(s[i]==2){\n\t\tif(s2>0){\n\t\t\ts2--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts2++;\n\t\t}\n\t}\n\tif(s[i]==1){\n\t\tif(s3>0){\n\t\t\ts3--;\n\t\t\ttaxi++;\n\t\t}else{\n\t\t\ts1++;\n\t\t}\n\t}\n}\n\nif(s3>0){\n\ttaxi+=s3;\n}\nif(s2>0){\n\tif(s1>1){\n\t\ts1-=2;\n\t}\n\ts2--;\n\ttaxi++;\n}\nif(s1>0){\n\ttaxi+=Math.ceil(s1/4);\n}\nprint(taxi);"}, {"source_code": "var n = parseInt(readline());\nvar numbersInput = readline().split(' ');\nvar groupsOne = 0;\nvar groupsTwo = 0;\nvar groupsThree = 0;\nvar taxis = 0;\n\nfor (var k = 0; k < n; k++) {\n var newGroup = parseInt(numbersInput[k]);\n if (newGroup === 4) {\n taxis++;\n } else if (newGroup === 1) {\n groupsOne++;\n } else if (newGroup === 2) {\n groupsTwo++;\n } else {\n groupsThree++;\n }\n}\n\ntaxis = taxis + ((groupsTwo / 2) >> 0);\ngroupsTwo = groupsTwo % 2;\n\nif (groupsTwo > 0 && groupsOne > 0) {\n groupsOne--;\n groupsOne--;\n groupsTwo--;\n taxis++;\n}\n\n//groupsTwo must be 0\nwhile (groupsOne > 0 && groupsThree > 0) {\n taxis++;\n groupsOne--;\n groupsThree--;\n}\n\n\nif (groupsOne <= 0) {\n taxis = taxis + groupsThree;\n groupsThree = 0;\n}\n\nwhile (groupsOne >= 4) {\n groupsOne = groupsOne - 4;\n taxis++;\n}\n\nif (groupsOne > 0) {\n taxis++;\n}\n\nprint(taxis);\n"}, {"source_code": "var n = parseInt(readline());\n\nvar gFour = 0;\nvar gThree = 0;\nvar gTwo = 0;\nvar gOne = 0;\n\nvar gList = readline();\n\nfor(var i = 0; i < gList.length; i++){\n if (gList[i] === '4'){\n gFour++;\n } else if (gList[i] === '3'){\n gThree++;\n } else if (gList[i] === '2'){\n gTwo++;\n } else if (gList[i] === '1'){\n gOne++;\n }\n}\n\nvar v1 = 0;\n\nvar gOne2 = 0\nif (gThree > gOne) {\n v1 = gOne + ( gThree - gOne);\n} else if (gThree < gOne){\n v1 = gThree;\n gOne2 = gOne - gThree;\n} else if( gThree === gOne){\n v1 = gThree;\n}\n\nvar v2 = 0;\n\nvar gTwo2 = 0;\nif(gTwo % 2 === 0){\n v2 = gTwo / 2;\n} else {\n v2 = Math.floor(gTwo / 2);\n gTwo2 = 1;\n}\n\nvar v3 = 0;\n\nif (gTwo2 != 0 && gOne2 !== 0){\n if (gOne2 <= 2) {\n v3 = 1;\n } else {\n v3 = 1 + Math.ceil((gOne - 2) / 4); \n }\n} else if (gTwo2 === 0 && gOne2 !== 0){\n v3 = Math.ceil(gOne / 4);\n} else if(gTwo2 != 0 && gOne2 === 0){\n v3 = 1;\n}\n\n\nvar tax = gFour + v1 + v2 + v3;\n\nprint(tax);"}, {"source_code": "var n = readline();\n\nvar arr = readline().split(' ');\n\nvar ans = [0,0,0,0,0];\n\nfor(var i in arr){\n\tvar idx = parseInt(arr[i]);\n\tans[idx]++;\n\t\n}\n\nvar sum = 0;\n\nsum = Math.min(ans[1],ans[3]);\n\nans[1] -= sum;\nans[3] -= sum;\n\nsum += ans[3];\nsum += ans[4];\n\nsum += Math.floor(ans[1]/4);\nans[1] %= 4;\n\nsum += Math.floor(ans[2]/2);\nans[2] %= 2;\n\nif(ans[2] > 0){\n\tsum += ans[2];\n\tans[1] -= 2;\n}\n\nsum += Math.max(0,ans[1]);\n\nprint(sum);\n\n\t\n\t\nprint(sum);\n\t\n\t\n\t\n\n"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n\tcar_q[parseInt(mas[i])-1] ++;\n}\ncars = cars + car_q[3];\nif(car_q[0] >= car_q[2])\n{\n\tcars = cars + car_q[2];\n\tcar_q[0] = car_q[0] - car_q[2];\n}\nelse\n{\n\tcars = cars + car_q[2];\n\tcar_q[0] = 0;\t\n}\ncars = cars + Math.ceil(car_q/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n\tcar_q[0] --;\n}\ncars = cars + Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "var n = readline(), \n people = readline().split(' ').sort().reverse(), \n offset = people.length, \n s = 0, \n i = 0;\nif(people[0] == 1) {\n s = Math.ceil(people.length / 4);\n}\nelse {\n while(i < offset) {\n if(people[i] == 3 && people[offset] == 1 ||\n people[i] == 2 && people[offset] == 2){ \n offset--;\n }\n s++;\n i++;\n }\n}\nprint(s);"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});\nvar cars = 0;\nfor(var i=0; ii;j--){\n if(sum+s[j]<=4){\n sum += s[j];\n s.splice(j, 1);\n }\n if(sum===4) break;\n }\n}\nprint(cars);"}, {"source_code": "var n = parseInt(readline(), 10), \n inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a), \n taxi = 0,\n friendNum = 0;\n\nfor(var i=0; i<=inp.length-1; i++) {\n friendNum += inp[i];\n \n if(friendNum < 4) {\n if((friendNum + inp[i+1]) > 4) {\n taxi++;\n friendNum = 0;\n }\n } else if(friendNum === 4) {\n taxi++;\n friendNum = 0;\n }\n}\n\nprint(taxi);"}, {"source_code": "var x= parseInt(readline());\nvar arr=readline().split(' ').map(x => parseInt(x));\n\narr.sort((a,b) => a-b);\nvar taxis=0;\nvar rem=0;\nfor(var i=0; i0)\n taxis++;\n\nprint(taxis);\n"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\n//var input = 5;\n//var ninyos= [1,2,4,3,3];\nvar input = readline();\nvar ninyos= readline().split(\" \");\nvar ninyos1=0;\nvar ninyos2=0;\nvar ninyos3=0;\nvar taxis=0;\n\nfor (var x=0;x {\n return +sum + +current\n});\nvar tax = 4; \nprint(Math.ceil(allChild/tax));\n"}, {"source_code": "var taxi=0;\n var one=0;\n var two=0;\n var three=0;\n\tvar len = readline();\n\tvar readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}}\n\ttaxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=(one-three);} \n \n if((two%2)!=0){\n two-=1;\n one+=1;}\n\n if(two>0){taxi+=(two/2);}\n\t while (one >= 4){\n one-= 4;\n taxi+=1;}\n if (one>0){taxi+=1;}\n print(taxi);\t\t\t\t\n"}, {"source_code": "var n = Number(readline());\nvar groups = readline().split(\" \").map(function(x) { return parseInt(x); }).sort();\nvar taxies = 0;\nvar buffer = 0;\n\n\nfor (var i = n - 1; i >= buffer; i--) {\n var groupR = groups[i];\n var temp = groupR;\n\n for (var j = buffer; j < groups.length; j++) {\n var groupL = groups[j];\n\n if ( temp + groupL >= 4 ) {\n if ( temp + groupL == 4 ) {\n buffer++;\n }\n\n taxies++;\n break;\n } else {\n temp += groupL;\n buffer++;\n }\n }\n}\n\nprint( taxies );"}, {"source_code": "var n = readline();\nvar child = readline().split(\" \");\nvar one =0;\nvar two =0;\nvar three =0;\nvar four =0;\nfor (var i=0;i 2)\n\tsum += (1 + ans[2]);\nelse if(ans[1] > 0)\n\tsum += ans[2];\nelse\n\tsum += ans[2];\n\t\nprint(sum);\n\t\n\t\n\t\n\n"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n car_q[parseInt(mas[i])-1] ++;\n}\nprint(car_q);\ncars += car_q[3];\nif(car_q[0] >= car_q[2])\n{\n cars += car_q[2];\n car_q[0] -= car_q[2];\n}\nelse\n{\n cars += car_q[2];\n car_q[0] = 0; \n}\ncars += Math.ceil(car_q/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n car_q[0] --;\n}\ncars += Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar a = readline().split(' ').map(Number),\n count = [0, 0, 0, 0, 0];\n\nfor (var i = 0; i < a.length; i++) {\n count[a[i]]++;\n}\n\nvar ans = count[4] + count[3] + Math.floor(count[2] / 2);\n\n(count[1] - count[3] >= 0) ? count[1] -= count[3] : count[1] = 0;\n\nif (count % 2 == 1) {\n ans++;\n (count[1] - 2 >= 0) ? count[1] -= 2 : count[1] = 0;\n}\n\nans = ans + Math.floor(count[1] / 4);\n\nif (count[1] % 4) {\n ans++;\n}\n\nprint(ans);"}, {"source_code": "function main() {\n const count = readline();\n for (var i = 0; i < count; i++) {\n var view = readline();\n if (isRowColumnView(view)) {\n print(changeViewToExcel(view));\n } else {\n print(changeViewToCR(view));\n }\n }\n}\n\nmain();\n\nfunction main() {\n const count = readline();\n var groupCount = {};\n var groupArr = readline().split(\" \").map(elem => {\n if (groupCount[elem]) {\n groupCount[elem]++;\n } else {\n groupCount[elem] = 1;\n }\n return +elem;\n });\n var taxi = groupCount['4'] || 0;\n\n if (groupCount['3'] >= groupCount['2'] && Math.floor(groupCount['1']/2) < groupCount['2']) {\n if (groupCount['1'] >= groupCount['3']) {\n taxi += groupCount['3'];\n groupCount['1'] -= groupCount['3'];\n groupCount['3'] = 0;\n } else {\n taxi += groupCount['1'];\n groupCount['3'] -= groupCount['1'];\n groupCount['1'] = 0;\n }\n } \n var floor2FirstGroup = Math.floor(groupCount['1']/2)\n if (floor2FirstGroup >= groupCount['2']) {\n taxi += groupCount['2'];\n groupCount['1'] -= (floor2FirstGroup * 2);\n groupCount['2'] = 0;\n } else {\n taxi += floor2FirstGroup;\n groupCount['2'] -= floor2FirstGroup;\n groupCount['1'] -= floor2FirstGroup * 2;\n }\n if (groupCount['1'] >= groupCount['3']) {\n taxi += groupCount['3'];\n groupCount['1'] -= groupCount['3'];\n groupCount['3'] = 0;\n } else {\n taxi += groupCount['1'];\n groupCount['3'] -= groupCount['1'];\n groupCount['1'] = 0;\n }\n var floor2SecondGroup = Math.floor(groupCount['2']/2);\n taxi += floor2SecondGroup;\n groupCount['2'] -= floor2SecondGroup * 2;\n if (groupCount['2'] > 0 && groupCount['1'] > 0) {\n taxi++;\n groupCount['2'] = 0;\n groupCount['1'] -= 1;\n }\n var floor4FirstGroup = Math.floor(groupCount['1']/4);\n taxi += floor4FirstGroup;\n groupCount['1'] -= floor4FirstGroup * 4;\n if (groupCount['1'] > 0) {\n taxi++;\n groupCount['1'] = 0;\n }\n var resultTaxi = taxi + groupCount['3'] + groupCount['2'] + groupCount['1'];\n print(resultTaxi);\n}\n\n"}, {"source_code": "var n = Number(readline());\nvar groups = readline().split(\" \").map(function(x) { return parseInt(x); }).sort();\nvar taxies = 0;\nvar buffer = 0;\n\nvar peopleCount = groups.reduce(function (prev, next) {\n return prev + next;\n});\n\nif ( peopleCount >= 4 ) {\n for (var i = n - 1; i >= buffer; i--) {\n var groupR = groups[i];\n var temp = groupR;\n\n for (var j = buffer; j < n && i != j; j++) {\n var groupL = groups[j];\n\n if ( temp + groupL >= 4 ) {\n if ( temp + groupL == 4 ) {\n buffer++;\n }\n\n taxies++;\n break;\n } else {\n temp += groupL;\n buffer++;\n }\n }\n }\n} else {\n taxies = 1;\n}\n\nprint( taxies );"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar a = readline().split(' ').map(Number),\n count = [0, 0, 0, 0, 0];\n\nfor (var i = 0; i < a.length; i++) {\n count[a[i]]++;\n}\n\nvar ans = count[4] + count[3] + Math.floor(count[2] / 2);\n\n(count[1] - count[3] >= 0) ? count[1] -= count[3] : count[1] = 0;\n\nif (count % 2 == 1) {\n ans++;\n (count[1] - 2 >= 0) ? count[1] -= 2 : count[1] = 0;\n}\n\nans = ans + Math.floor(count[1] / 4);\n\nif (count[1] % 4) {\n ans++;\n}\n\nprint(ans);"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').sort(function(a,b){return b-a;});\nfor(var i=0, j=n-1; i<=j; i++){\n if(i parseInt(e)).sort().reverse();\nvar res = 0;\nfor (var i = 0; i < numbers.length; i++) {\n for (var j = i + 1; j < numbers.length; j++) {\n if (numbers[i] + numbers[j] <= 4) {\n numbers[i] += numbers[j];\n numbers.splice(j,1);\n }\n if (numbers[i] == 4) {\n break;\n }\n }\n}\nprint(numbers);\nprint(numbers.length);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = 0,\n num2 = 0,\n num3 = 0,\n num4 = 0\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1++\n } break;\n case 2: {\n num2++\n } break;\n case 3: {\n num3++\n } break;\n case 4: {\n num4++\n } break;\n }\n }\n let allSum = num4\n if (num1 > 0 && num3 > 0) {\n if (num1 > num3) {\n const after = num1 - num3\n allSum += num3\n num1 = after\n num3 = 0\n } else if (num1 < num3) {\n const after = num3 - num1\n allSum += num1\n num1 = 0\n num3 = after\n } else {\n allSum += num1\n num1 = 0\n num3 = 0\n }\n } else if (num1 > 0 && num3 === 0) {\n const after = Math.floor(num1 / 4)\n const ostatok = ((num1 / 4) - after) * 4\n allSum += after\n num1 = ostatok\n } else if (num1 === 0 && num3 > 0) {\n allSum += num3\n num3 = 0\n }\n if (num2 > 0) {\n const after = Math.floor(num2 / 2)\n allSum += after\n const ostatok = ((num2 / 2) - after) * 2\n num2 = ostatok\n }\n if (num4 > 0) {\n num4 = 0\n }\n allSum += num3\n num3 = 0\n const check = (num2 + num1) / 4\n allSum += check >= 0.25 ? Math.ceil(check) : 0\n num1 = 0\n num2 = 0\n console.log(allSum)\n});"}, {"source_code": "//158B - Taxi\nvar n = +readline();\nvar numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();\nvar res = 0;\nfor (var i = 0; i < numbers.length; i++) {\n for (var j = i + 1; j < numbers.length; j++) {\n if (numbers[i] + numbers[j] <= 4) {\n numbers[i] += numbers[j];\n numbers.splice(j,1);\n }\n if (numbers[i] == 4) {\n break;\n }\n }\n}\nprint(numbers.length);"}, {"source_code": "\nvar num = parseInt(readline()),\n group = readline().split(' ').map(el => parseInt(el)),\n counter = 0;\nfor (var x = 0; x < group.length; x++) {\n counter += group[x];\n}\nif (counter == 4) {\n print(1);\n} else {\n counter = 0;\n for (var i = 0; i < group.length; i++) {\n if (group[i] == 4) {\n counter++;\n group.splice(i, 1);\n i = -1;\n continue;\n }\n for (var j = 1; j < group.length; j++) {\n if (i == -1) i++;\n if (i == j) continue;\n if (group[i] + group[j] == 4) {\n counter++;\n group.splice(i, 1);\n group.splice(j - 1, 1);\n i = -1, j = 0;\n }\n if (group.length == 0) {\n break;\n }\n }\n for (var a = 0; a < group.length; a++) {\n if (group[a] == 1 && group[a + 1] < 3 || group[a] < 3 && group[a + 1] == 1) {\n group[a] += group[a + 1];\n group.splice(a + 1, 1);\n }\n }\n }\n\n print(counter + group.length);\n}\n\n"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n\tcar_q[parseInt(mas[i])-1] ++;\n}\ncars = cars + car_q[3];\nif(car_q[0] >= car_q[2])\n{\n\tcars = cars + car_q[2];\n\tcar_q[0] = car_q[0] - car_q[2];\n}\nelse\n{\n\tcars = cars + car_q[2];\n\tcar_q[0] = 0;\t\n}\ncars = cars + Math.ceil(car_q/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n\tcar_q[0] --;\n}\ncars = cars + Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": "var kids = 0;\nreadline();\nreadline().split(' ').map(function(c){\n\tkids += parseInt(c);\n});\n\nprint(Math.ceil(kids / 4));\n"}, {"source_code": "\n var taxi=0;var one=0;var two=0;var three=0;\n var len = readline();\n var ajx = readline();\n\tvar readitem = ajx.split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}}\n\n\ttaxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=(one-three);} \n\n if((two%2)!=0){two-=1;one+=1;}if(two>0){taxi+=(two/2);two=0;} \n\n \n \n if(two=0){\n while((two > 0) && (two < 4)&&(one > 0)){one -=1; two +=1;}\n \n }\n if((two%2)!=0){two-=1;one+=1;}\n if(two>=1){taxi+=(two/2);}\n\n\n\t while (one >= 4){one-= 4;taxi+=1;}\n if ((two>0)||(one>0)){taxi+=1;}\n \n\n\n print(taxi);\t\n"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\n//var input = 8;\n//var ninyos= [2,3,4,4,2,1,3,1];\nvar input = readline();\nvar ninyos= readline().split(\" \");\nvar ninyos1=0;\nvar ninyos2=0;\nvar ninyos3=0;\nvar taxis=0;\n\nfor (var x=0;x input.push(line));\n \nreadLine.on('close', () => {\n let [count, peopleMain] = input\n count = parseInt(count)\n people = peopleMain.split(' ')\n let sub = []\n let countOne = 0\n const replace = (idA, idB, count) => {\n if (idA !== idB) {\n people[idA] = 0\n people[idB] = 0\n sub.push(count)\n }\n }\n let stopCheck = false\n for (let i = 0; i < count; i++) {\n const person = parseInt(people[i])\n if (person < 4) {\n stopCheck = false\n switch (person) {\n case 1: {\n const findNum = 3\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n countOne++\n }\n } break;\n case 2: {\n const findNum = 2\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n sub.push(person)\n }\n } break;\n case 3: {\n const findNum = 1\n if (people.indexOf(findNum.toString()) !== -1) {\n for (let a = 0; a < count; a++) {\n if (stopCheck === false) {\n const el = parseInt(people[a])\n if (el === findNum) {\n replace(i, a, (person + el))\n stopCheck = true\n }\n }\n }\n }\n if (stopCheck === false) {\n sub.push(person)\n }\n } break;\n }\n } else {\n people[i] = 0\n sub.push(person)\n }\n }\n const ostatok = Math.ceil(countOne / 4)\n console.log(sub.length + ostatok)\n});"}, {"source_code": "var n = Number(readline());\nvar groups = readline().split(\" \").map(function(x) { return parseInt(x); }).sort();\ngroups.push( 5 );\nvar memory = [];\nvar temp = 0;\n\nfor (var i = 0; i < groups.length - 1; i++) {\n var group = groups[i];\n\n if ( temp + group >= 4 || group + groups[i + 1] > 4 ) {\n memory[i] = 1;\n temp = 0;\n } else {\n memory[i] = 0;\n temp += group;\n }\n}\n\nprint( memory.reduce(function (prev, next) {\n return prev + next;\n}));"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const groups = input[1].split(' ').map(x => parseInt(x));\n const countGroups = [0, 0, 0, 0];\n\n groups.forEach(g => countGroups[g-1] += 1);\n let taxi = countGroups[3];\n taxi += countGroups[2];\n\n countGroups[0] -= countGroups[2];\n if (countGroups[1] % 2 === 0 && countGroups[1] > 0) {\n taxi += countGroups[1]/2; \n if (countGroups[0] > 0)\n taxi += parseInt(Math.ceil(countGroups[0]/4));\n } else {\n taxi += parseInt(Math.ceil(countGroups[1]/2));\n countGroups[0] -= 2;\n if (countGroups[0] > 0) taxi += parseInt(Math.ceil(countGroups[0]/4));\n }\n\n console.log(taxi);\n});"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar cars = 0;\nvar car_q = [0, 0, 0, 0];\nfor(var i = 0; i < n; ++i)\n{\n car_q[parseInt(mas[i])-1] ++;\n}\ncars += car_q[3];\nif(car_q[0] >= car_q[2])\n{\n cars += car_q[2];\n car_q[0] -= car_q[2];\n}\nelse\n{\n cars += car_q[2];\n car_q[0] = 0; \n}\ncars += Math.ceil(car_q[1]/2);\nif(car_q[1] % 2 != 0 && car_q[0] != 0)\n{\n car_q[0] --;\n}\ncars += Math.ceil(car_q[0]/4);\nprint(cars);"}, {"source_code": " var taxi=0;var one=0;var two=0;var three=0;\n var len = readline();\n //var ajx = \"2 3 4 4 2 1 3 1\"\n\tvar readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}}\n\n\ttaxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=(one-three);} \n\n if((two%2)!=0){two-=1;one+=1;} \n\n if(two>=1){taxi+=(two/2);two=0;}\n \n else\n while((two < 0) && (two < 4)&&(one > 0)){one -=1; two +=1;}\n if((two%2)!=0){two-=1;one+=1;}\n if(two>=1){taxi+=(two/2);}\n \n\n\n\t while (one >= 4){one-= 4;taxi+=1;}\n if ((two>0)||(one>0)){taxi+=1;}\n \n\n\n print(taxi);\t\n"}, {"source_code": "var groupOfOne =0,\n groupOfTwo = 0,\n groupOfThree = 0,\n numberOfGroup = readline(),\n numberOfGroupMembers = readline().split(\" \")\n result = 0;\nwhile(numberOfGroup--){\n switch(+numberOfGroupMembers[numberOfGroup]){\n case 1: groupOfOne++;\n break;\n case 2: groupOfTwo++;\n break;\n case 3: groupOfThree++;\n break;\n case 4: result++;\n \n }\n}\nif(groupOfThree>groupOfOne){\n if(groupOfTwo%2!==0){\n result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne-1)/4);\n }\n else{\n result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne)/4);\n }\n}\nelse if(groupOfThree === groupOfOne){\n result+=groupOfThree + groupOfTwo/2;\n}\nelse\n{\n result+=groupOfThree;\n if(groupOfTwo%2===0){\n result+=groupOfTwo/2+Math.ceil(groupOfOne/4);\n }\n else{\n result+=groupOfTwo/2 +Math.ceil((groupOfOne-1)/4);\n }\n}\nprint(result);"}, {"source_code": "var taxi=0;\n var one=0;\n var two=0;\n var three=0;\n\tvar len = readline();\n\tvar readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}}\n\ttaxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=(one-three);} \n \n if((two%2)!=0){\n two-=1;\n one+=1;}\n\n if(two>0){taxi+=(two/2);}\n\t while (one >= 4){\n one-= 4;\n taxi+=1;}\n if (one>0){taxi+=1;}\n print(taxi);\t\t\t\t\n"}, {"source_code": "var groupsQuantity = readline();\nvar childrenQuantity = readline().split(\" \");\n\nvar cars = 0;\n\nvar NumberGroupsOfOne = 0;\nvar NumberGroupsOfTwo = 0;\nvar NumberGroupsOfThree = 0;\nvar NumberGroupsOfFour = 0;\n\nfor(var i = 0; i < groupsQuantity; i++){\n switch(+childrenQuantity[i]){\n case 1: NumberGroupsOfOne++;\n break;\n case 2: NumberGroupsOfTwo++;\n break;\n case 3: NumberGroupsOfThree++;\n break;\n case 4: NumberGroupsOfFour++;\n break;\n }\n}\n\ncars += NumberGroupsOfFour;\n\nif(NumberGroupsOfOne > NumberGroupsOfThree){\n cars += NumberGroupsOfThree;\n NumberGroupsOfOne -= NumberGroupsOfThree;\n if(NumberGroupsOfOne * 2> NumberGroupsOfTwo){\n cars += NumberGroupsOfTwo;\n cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo)/4);\n }\n else{\n cars += Math.ceil(NumberGroupsOfTwo/2);\n }\n}\nelse{\n cars += NumberGroupsOfOne;\n NumberGroupsOfThree -= NumberGroupsOfOne;\n cars += NumberGroupsOfThree;\n cars += Math.ceil(NumberGroupsOfTwo/2);\n}\nprint(cars);"}, {"source_code": "var n = parseInt(readline());\n\nvar gFour = 0;\nvar gThree = 0;\nvar gTwo = 0;\nvar gOne = 0;\n\nvar gList = readline();\n\nfor(var i = 0; i < gList.length; i++){\n if (gList[i] === '4'){\n gFour++;\n } else if (gList[i] === '3'){\n gThree++;\n } else if (gList[i] === '2'){\n gTwo++;\n } else if (gList[i] === '1'){\n gOne++;\n }\n}\n\nvar v1 = 0;\n\nvar gOne2 = 0\nif (gThree > gOne) {\n v1 = gOne + ( gThree - gOne);\n} else if (gThree < gOne){\n v1 = gThree;\n gOne2 = gOne - gThree;\n} else if( gThree === gOne){\n v1 = gThree;\n}\n\nvar v2 = 0;\n\nvar gTwo2 = 0;\nif(gTwo % 2 === 0){\n v2 = gTwo / 2;\n} else {\n v2 = Math.floor(gTwo / 2);\n gTwo2 = 1;\n}\n\nvar v3 = 0;\n//print(Math.floor(gOne / 4));\nif (gTwo2 != 0 && gOne2 !== 0){\n if (gOne2 <= 2) {\n v3 = 1;\n } else {\n v3 = 1 + Math.ceil((gOne - 2) / 4); \n }\n} else if (gTwo2 === 0 && gOne2 !== 0){\n v3 = Math.floor(gOne / 4);\n} else if(gTwo2 != 0 && gOne2 === 0){\n v3 = 1;\n}\n\n\nvar tax = gFour + v1 + v2 + v3;\n\nprint(tax);"}, {"source_code": "n = readline();\nstr = readline().split(' ').map(Number);\n\nvar count = 0;\n\nfor (var i = 0; i < str.length; i++) {\n\tcount += str[i];\n};\n\nif (count % 2 !== 0) {\n\tprint(Math.floor(count / 4) + 1);\n} else {\n\tprint(count / 4);\n};\n\n"}, {"source_code": "//158B - Taxi\nvar n = +readline();\nvar numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();\nvar res = 0;\nfor (var i = 0; i < numbers.length; i++) {\n for (var j = i + 1; j < numbers.length; j++) {\n if (numbers[i] + numbers[j] <= 4) {\n numbers[i] += numbers[j];\n numbers.splice(j,1);\n }\n if (numbers[i] == 4) {\n break;\n }\n }\n}\nprint(numbers.length);"}, {"source_code": "var n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else { _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n sum += (_1 - (_1 - _3));\n _1 = (_1 - _3);\n sum += Math.floor(_2/2);\n sum += Math.floor(_1/4);\n if(_2 % 2 !== 0 && _1 % 4 <= 2 && _1 % 4 != 0){\n sum += 1;\n } else if(_2 % 2 !== 0 && _1 % 4 > 2 && _1 % 4 != 0){\n sum += 2;\n } else if(_2 % 2 === 0 && _1 % 4 != 0){\n\t\t\tsum += 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "//deneme121\n\nvar n = Number(readline()),\n arr = readline().split(' '),\n _1 = 0;\n _2 = 0;\n _3 = 0;\n _4 = 0;\n\n\nfor(var i = 0; i < arr.length; i++){\n if(arr[i] == '1'){ _1++; } \n else if(arr[i] == '2'){ _2++; }\n else if(arr[i] == '3'){ _3++; }\n else { _4++; }\n}\n\nvar sum = _4;\n \n if(_3 - _1 >= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n if( ((_1 - _3) + _2 * 2) % 4 == 0 ){\n\t\t\tsum = _3 + Math.floor(((_1 - _3) + _2 * 2) / 4);\n\t\t} else{\n\t\t\tsum = _3 + Math.floor(((_1 - _3) + _2 * 2) / 4) + 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "function main(){\n\n var n = readline();\n \n var num = [0,0,0,0,0];\n var cars=0;\n \n var kids = readline().split(' ');\n \n for(i=0;i0){\n\tnum[4]-=1;\n\tcars+=1;\n }\n\n // num[3], num[2], num[1] left\n while(num[3]>0 && num[1]>0){\n\tnum[3]-=1;\n\tnum[1]-=1;\n\tcars+=1;\n }\n\n while(num[3] > 0) {\n\tnum[3] -= 1;\n\tcars += 1;\n }\n\n // num[2], num[1] left\n while(num[2]>=2){\n\tnum[2]-=2;\n\tcars+=1;\n }\n \n if(num[2]===1) {\n\tif (num[1]>0){\n\t if(num[1]>=2){\n\t\tnum[1]-=2;\n\t }else{\n\t\tnum[1]-=1;\n\t }\n }\n\tcars+=1;\n }\n\n \n\n // num[1] left\n if(num[1]%4==0){\n\tcars+=(num[1]/4);\n } else{\n\tcars+=(num[1]/4)+1;\n }\n print (cars);\n}\n\n\nmain();"}, {"source_code": "var groupsQuantity = readline();\nvar childrenQuantity = readline().split(\" \");\n\nvar cars = 0;\n\nvar NumberGroupsOfOne = 0;\nvar NumberGroupsOfTwo = 0;\nvar NumberGroupsOfThree = 0;\nvar NumberGroupsOfFour = 0;\n\nfor(var i = 0; i < groupsQuantity; i++){\n switch(+childrenQuantity[i]){\n case 1: NumberGroupsOfOne++;\n break;\n case 2: NumberGroupsOfTwo++;\n break;\n case 3: NumberGroupsOfThree++;\n break;\n case 4: NumberGroupsOfFour++;\n break;\n }\n}\n\ncars += NumberGroupsOfFour;\n\nif(NumberGroupsOfOne > NumberGroupsOfThree){\n cars += NumberGroupsOfThree;\n NumberGroupsOfOne -= NumberGroupsOfThree;\n if(NumberGroupsOfOne * 2> NumberGroupsOfTwo){\n cars += NumberGroupsOfTwo;\n cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo * 2)/4);\n }\n else{\n cars += Math.ceil(NumberGroupsOfTwo/2);\n }\n}\nelse{\n cars += NumberGroupsOfOne;\n NumberGroupsOfThree -= NumberGroupsOfOne;\n cars += NumberGroupsOfThree;\n cars += Math.ceil(NumberGroupsOfTwo/2);\n}\nprint(cars);"}, {"source_code": "\n var taxi=0;var one=0;var two=0;var three=0;\n var len = readline();\n //var ajx = \"3 1 2 1 1 1 1 1 1\";\n var readitem = readline().split(' ');\nfor (var i = 0; i < readitem.length; i++)\n {if(readitem[i] == \"4\"){taxi+=1;}\n if(readitem[i] == \"3\"){three+=1;}\n if(readitem[i] == \"2\"){two+=1;}\n if(readitem[i] == \"1\"){one+=1;}}\n\n taxi += three;\n if(one <= three){one = 0;}else if(three>0){one-=three;} \n \n if((two%2)!=0){two-=1;one+=1;}if(two>0){taxi+=(two/2);two=0;} \n\n \n \n if(two!=0){\n while((two > 0)&&(two < 4)&&(one > 0)){one -=1; two +=1;}\n \n }\n \n if((two%2)!=0){two-=1;one+=1;}\n if(two>=1){taxi+=(two/2);}\n\n\n while (one >= 4){one-= 4;taxi+=1;}\n if ((two>0)){taxi+=1;}\n if ((one>0)){taxi+=1;}\n\n\n print(taxi);\n\n"}, {"source_code": "readline();\n\nvar car = [0,0,0,0,0];\nreadNums().map(v => car[v]++);\n\nvar m = Math.min(car[1], car[3]);\ncar[1] -= m;\ncar[3] -= m;\ncar[4] += m;\n\n\nvar m = Math.min(car[1], car[2] * 2);\nif (m & 1)\n m--;\ncar[1] -= m;\ncar[2] -= m / 2;\ncar[4] += m;\n\n\nvar m = Math.min(car[1], car[2]);\ncar[1] -= m;\ncar[2] -= m;\ncar[3] += m;\n\n\nm = Math.floor(car[2] / 2);\ncar[2] -= m * 2;\ncar[4] += m;\n\n\nm = Math.floor(car[1] / 4);\ncar[1] -= m * 4;\ncar[4] += m;\n\nprint(car.reduce((a,b) => a + b));\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0)\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let [count, peoples] = input\n count = parseInt(count)\n peoples = peoples.split(' ')\n let num1 = []\n let num2 = []\n let num3 = []\n let num4 = []\n for (let i = 0; i < count; i++) {\n const el = parseInt(peoples[i])\n switch (el) {\n case 1: {\n num1.push(el)\n } break;\n case 2: {\n num2.push(el)\n } break;\n case 3: {\n num3.push(el)\n } break;\n case 4: {\n num4.push(el)\n } break;\n }\n }\n let allSum = num4.length\n let notRegister = 0\n if (num1.length > 0 && num3.length > 0) {\n if (num1.length > num3.length) {\n const after = num1.length - num3.length\n const ostatok = num1.length - after\n allSum += ostatok\n notRegister += after\n } else if (num1.length < num3.length) {\n const after = num3.length - num1.length\n const ostatok = (num3.length - after) * 3\n allSum += after\n notRegister += ostatok\n } else {\n allSum += num1.length\n }\n } else if (num1.length === 0 && num3.length > 0) {\n allSum += num3.length\n } else if (num1.length > 0 && num3.length === 0) {\n const after = Math.floor(num1.length / 4)\n const ostatok = Math.ceil((num1.length / 4) - after)\n allSum += after\n notRegister += ostatok\n }\n if (num2.length > 0) {\n if ((num2.length / 2) > 1) {\n const after = Math.floor(num2.length / 2)\n const ostatok = ((num2.length / 2) - after) * 2\n allSum += after\n notRegister += ostatok\n } else {\n notRegister += num2.length * 2\n }\n }\n allSum += Math.ceil(notRegister / 4)\n console.log(allSum)\n});"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\n//var input = 3;\n//var input2 = new Array(3,3,2)\nvar lleno3 = 0;\nvar cont4 = 0;\nvar ninyos = 0;\n\nfor (var x = 0; x4){\n\t\t\tcont4 += Math.floor(lleno3/3);\n\t\t\tlleno3=0;\n\t\t}\n\t}else if(input2[x]==2){\n\t\tninyos += parseInt(input2[x]);\n\t}\n\t\t\n}\n\n\nprint(Math.ceil((ninyos+lleno3)/4)+cont4);\n//document.write(Math.ceil((ninyos+lleno3)/4)+cont4);"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x=3){\n\t\tcont++;\n\t}else {\n\t\tninyos += input2[x];\n\t}\n\t\t\n}\n\nprint(Math.floor(ninyos/4)+cont);"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\n\nvar ninyos = 0;\nvar cont = 0;\n\nfor (var x = 0; x=3){\n\t\tcont++;\n\t}else {\n\t\tninyos += parseInt(input2[x]);\n\t}\n\t\t\n}\n\n\nprint(Math.floor(ninyos/4)+cont);"}, {"source_code": "\n var taxi=0;\n var one=0;\n var two=0;\n var three=0;\n\tvar len = readline();\n\n\tvar readitem = readline().split(' ');\n\tfor (var i = 0; i < readitem.length; i++) \n {\n \tif(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}\n }\n taxi += three;\nif(one <= three){one = 0;}else{one-=one-three;}\nif(two%2!=0){\n\ttwo-=1;\n\tone+=1;\n\tif(two>0){taxi=two/2;}\n}\nwhile (one >= 4){\none-= 4;\ntaxi+=1;}\nif (one>0){taxi+=1;}\nprint(taxi);\n\n\t\t\t\t\t\n\n\n"}, {"source_code": "/*\nAfter the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1\u2009\u2264\u2009si\u2009\u2264\u20094), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number of groups of schoolchildren. The second line contains a sequence of integers s1,\u2009s2,\u2009...,\u2009sn (1\u2009\u2264\u2009si\u2009\u2264\u20094). The integers are separated by a space, si is the number of children in the i-th group.\n\nOutput\nPrint the single number \u2014 the minimum number of taxis necessary to drive all children to Polycarpus.\n\nExamples\ninput\n5\n1 2 4 3 3\noutput\n4\ninput\n8\n2 3 4 4 2 1 3 1\noutput\n5\n*/\n\nvar input = readline();\nvar input2 = readline().split(\" \");\nvar ninyos = 0;\nvar cont = 0;\n//var taxis = Math.ceil(ninyos/4);\nfor (var x = 0; x= 0){\n sum += _3;\n sum += Math.ceil(_2/2);\n } else{\n sum += (_1 - (_1 - _3));\n _1 = (_1 - _3);\n sum += Math.floor(_2/2);\n sum += Math.floor(_1/4);\n if(_2 % 2 !== 0 && _1 % 4 <= 2 && _1 % 4 != 0){\n sum += 1;\n } else if(_2 % 2 !== 0 && _1 % 4 > 2 && _1 % 4 != 0){\n sum += 2;\n } else if(_2 % 2 === 0 && _1 % 4 != 0){\n\t\t\tsum += 1;\n\t\t}\n }\n\nprint(sum);"}, {"source_code": "var n = readline();\n\nvar arr = readline().split(' ');\n\nvar ans = [0,0,0,0,0];\n\nfor(var i in arr){\n\tvar idx = parseInt(arr[i]);\n\tans[idx]++;\n\t\n}\n\nvar sum = 0;\n\nsum = Math.min(ans[1],ans[3]);\n\nans[1] -= sum;\nans[3] -= sum;\n\nsum += ans[3];\nsum += ans[4];\n\nsum += Math.floor(ans[1]/4);\nans[1] %= 4;\n\nsum += Math.floor(ans[2]/2);\nans[2] %= 2;\n\nif(ans[2] > 0){\n\tsum += ans[2];\n\tans[1] -= 2;\n}\n\nsum += Math.max(0,ans[1]);\n\nprint(sum);\n\n\t\n\n\t\n\t\n\t\n\n"}, {"source_code": "\n var taxi=0;\n var one=0;\n var two=0;\n var three=0;\n\tvar len = readline();\n\n\tvar readitem = readline().split(' ');\n\tfor (var i = 0; i < readitem.length; i++) \n {\n \tif(readitem[i] == \"4\"){taxi+=1;}\n\tif(readitem[i] == \"3\"){three+=1;}\n\tif(readitem[i] == \"2\"){two+=1;}\n\tif(readitem[i] == \"1\"){one+=1;}\n }\n taxi += three;\nif(one <= three){one = 0;}else{one-=one-three;}\nif(two%2!=0){\n\ttwo-=1;\n\tone+=1;\n\tif(two>0){taxi=two/2;}\n}\nwhile (one >= 4){\none-= 4;\ntaxi+=1;}\nif (one>0){taxi+=1;}\nprint(taxi);\n\n\t\t\t\t\t\n\n\n"}, {"source_code": "var num1 = parseInt(readline());\nvar sum , one , thr;\nsum = one = thr = 0;\nfor(var i = 0 ; i < num1 ; i++)\n{\n var num = parseInt(readline());\n switch (num) {\n case 3:\n if (one > 0 ) {\n sum+=4;\n one--;\n }\n else\n {\n thr++;\n \n }\n break;\n \n case 1:\n if (thr > 0) {\n sum += 4;\n thr--;\n }\n else {\n one++;\n \n }\n break;\n \n default:\n sum += num;\n break;\n }\n}\nsum += one ;\nprint(Math.ceil(sum/4)+thr);"}, {"source_code": "var n = readline();\nvar s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});\nvar cars = 0;\nfor(var i=0; ii;j--){\n if(sum+s[j]<=4){\n sum += s[j];\n s.splice(j, 1);\n }\n if(sum===4) break;\n }\n}\nprint(cars);"}, {"source_code": "var n=parseInt(readline());\nvar arr=readline().split(' ');\nvar k_total=0;\nvar k1,k2,k3;\nk1=k2=k3=0;\nfor(var i=0;i ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var e = 0, min = 2e9;\n for(j = 0; j < n; j++){\n if(a[j] % 2 === 0){\n e++;\n }\n var m = 0;\n while(a[j] % 2 === 0){\n m++;\n a[j] /= 2;\n }\n min = Math.min(min, m);\n }\n console.log(min === 0 ? e : min + e - 1);\n }\n }\n});"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n let odd = 0\r\n let even = 0\r\n let min = Infinity\r\n const ks = arr.map(x => {\r\n let k = 0\r\n while (!(x & 1)) {\r\n x /= 2\r\n k++\r\n }\r\n if (k) {\r\n even++\r\n if (k < min) min = k\r\n } else {\r\n odd++\r\n }\r\n return k\r\n })\r\n // console.log(even ? min + (even - 1) : 0)\r\n if (even) {\r\n if (odd) {\r\n return even\r\n } else {\r\n return min + (even - 1)\r\n }\r\n } else {\r\n return 0\r\n }\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var e = 0, min = 2e9;\n for(j = 0; j < n; j++){\n if(a[j] % 2 === 0){\n e++;\n }\n var m = 0;\n while(a[j] % 2 === 0){\n m++;\n a[j] /= 2;\n }\n min = Math.min(min, m);\n }\n console.log(min === 0 ? e : min + e - 1);\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let odd = arr.filter(x => x % 2 === 1);\r\n let even = arr.filter(x => x % 2 === 0);\r\n\r\n if (odd.length > 0) {\r\n output(even.length);\r\n } else {\r\n let min = Infinity;\r\n for (let i = 0; i < even.length; i++) {\r\n let count = 0;\r\n while (even[i] % 2 === 0) {\r\n even[i] /= 2;\r\n count++;\r\n }\r\n if (count < min) {\r\n min = count;\r\n }\r\n }\r\n output(even.length + min - 1);\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nclass Input {\r\n\tconstructor(line) {\r\n\t\tthis.pointer = -1;\r\n\t\tthis.content = [line];\r\n\t}\r\n\tadd(line) {\r\n\t\tthis.content.push(line);\r\n\t}\r\n\tget(line) {\r\n\t\tif (!(this.pointer < this.content.length - 1)) {\r\n\t\t\treturn -1\r\n\t\t}\r\n\t\treturn this.content[++this.pointer];\r\n\t}\r\n}\r\n\r\nconst intify = (arr) => {\r\n\tif (typeof arr == \"string\") {\r\n\t\tlet temp = \"\";\r\n\t\tfor (let i = 0; i < arr.length; i++) {\r\n\t\t\tif (arr[i] != ' ') {\r\n\t\t\t\ttemp += arr[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn parseInt(temp)\r\n\t} else {\r\n\t\treturn arr.map(ele => parseInt(ele))\r\n\t}\r\n}\r\n\r\n\r\nrl.once(\"line\", line => {\r\n\tlet inp = new Input(line);\r\n\trl.on(\"line\", line => {\r\n\t\tinp.add(line)\r\n\t}).on(\"close\", () => {\r\n\r\n\t\tlet t = intify(inp.get());\r\n\t\twhile (t--) {\r\n\t\t\tlet n = intify(inp.get())\r\n\t\t\tlet arr = intify(inp.get().split(' '))\r\n\t\t\tlet evens = 0;\r\n\t\t\tlet odds = 0;\r\n\t\t\tfor (let i = 0; i < arr.length; i++) {\r\n\t\t\t\tif (arr[i] % 2 == 1) {\r\n\t\t\t\t\todds++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tevens++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (odds > 0) {\r\n\t\t\t\tconsole.log(evens);\r\n\t\t\t} else {\r\n\t\t\t\tlet minimum = 40;\r\n\t\t\t\tfor (let i = 0; i < arr.length; i++) {\r\n\t\t\t\t\tlet count = 0;\r\n\t\t\t\t\twhile (arr[i] > 1 && arr[i] % 2 == 0) {\r\n\t\t\t\t\t\tarr[i] /= 2;\r\n\t\t\t\t\t\tcount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tminimum = Math.min(minimum, count)\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log((arr.length - 1) + minimum);\r\n\t\t\t}\r\n\t\t}\r\n\r\n });\r\n});\r\n\r\n\r\n"}, {"source_code": "function getRes(countOfEven, minTwoDegree, n) {\r\n if (countOfEven < n) {\r\n return countOfEven;\r\n } else {\r\n return minTwoDegree + countOfEven - 1;\r\n }\r\n}\r\n\r\nfunction main() {\r\n let t = +readline();\r\n while (t > 0) {\r\n const n = +readline();\r\n const ticketsData = readline().split(' ');\r\n let countOfEven = 0;\r\n let minTwoDegree = null;\r\n\r\n ticketsData.forEach(ticketData => {\r\n let numTicketData = +ticketData;\r\n\r\n if ((numTicketData & 1) === 0) {\r\n ++countOfEven;\r\n }\r\n\r\n let degree = 0;\r\n\r\n while ((numTicketData & 1) === 0) {\r\n numTicketData >>= 1;\r\n ++degree;\r\n }\r\n\r\n if (degree < minTwoDegree || minTwoDegree === null) {\r\n minTwoDegree = degree;\r\n }\r\n });\r\n\r\n console.log(getRes(countOfEven, minTwoDegree, n));\r\n\r\n --t;\r\n }\r\n}\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main(); \r\n});\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst get2 = (x) => {\n let two = 0;\n while (x % 2 === 0) {\n two++;\n x /= 2;\n }\n return two;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let twos = new Array(n);\n let minTwos = Infinity;\n let maxTwos = -1;\n let even = 0;\n let odd = 0;\n\n for (let i = 0; i < n; i++) {\n twos[i] = get2(a[i]);\n minTwos = Math.min(minTwos, twos[i]);\n maxTwos = Math.max(maxTwos, twos[i]);\n if (twos[i] > 0) even++;\n else odd++;\n }\n\n if (maxTwos === 0) return 0;\n\n if (minTwos === 0) return even;\n\n return minTwos + n - 1;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let even = 0,\r\n odd = 0;\r\n for (let num of a) {\r\n if (num & 1) {\r\n odd++;\r\n } else {\r\n even++;\r\n }\r\n }\r\n if (odd) return even;\r\n let min = Infinity;\r\n for (let num of a) {\r\n for (let i = 0; i < 31; i++) {\r\n if (num & 1 << i) {\r\n min = Math.min(min, i);\r\n break;\r\n }\r\n }\r\n }\r\n return min + n - 1;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0]\n for(j = 1; j <= n; j++){\n k = lines[j].split('').map(Number)\n b = lines[j]\n \n k[0] -= 1 \n if(k[0] === 0 && k.length < 1){\n k.splice(0,1)\n }\n console.log(k.join(''))\n\n }\n \n\t \n}); "}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let even = 0\n let min = Infinity\n const ks = arr.map(x => {\n let k = 0\n while (!(x & 1)) {\n x /= 2\n k++\n }\n if (k) {\n even++\n if (k < min) min = k\n }\n return k\n })\n return even ? min + (even - 1) : 0\n}\n"}, {"source_code": " /////////////////////////// JavaScript Lover /////////////////////////////////////\r\n //////////////////// ShixyCat //////////////////////////////\r\nvar t = parseInt(readline())\r\nfor(var i=0 ; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n testLoop: for (let test = 0; test < N; test++) {\r\n let [n, x] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n // sort array ascending:\r\n arr.sort((a, b) => a - b);\r\n\r\n let no = false;\r\n for (let i = 0; i < n; i++) {\r\n let diff = arr[n + i] - arr[i];\r\n if (diff < x) {\r\n no = true;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}", "positive_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // console.log(front)\n // console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_x = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_x[0];\n const x = n_x[1];\n\n if ((n >= 1 && n <= 100) && (x >= 1 && x <= 1000)) {\n const heights = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n if (heights.length == 2*n) {\n const result = isPossible(n, x, heights);\n console.log(result)\n }\n }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0], x = k[1];\n }else{\n k = k.sort(function(a, b){return a - b});\n var f = [], s = [];\n for(j = 0; j < n * 2; j++){\n if(j < n){\n f.push(k[j]);\n }else{\n s.push(k[j]);\n }\n }\n var a = false;\n for(j = 0; j < n; j++){\n if(s[j] - f[j] < x){\n a = true;\n }\n }\n console.log(!a ? 'YES' : 'NO');\n }\n }\n \n}); "}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0] * 2, x = k[1];\n }else{\n k = k.sort(function(a, b){return a - b});\n var f = [];\n var s = [];\n for(j = 0; j < n; j++){\n if(j < n / 2){\n f.push(k[j]);\n }else{\n s.push(k[j]);\n }\n }\n var a = false;\n for(j = 0; j < n / 2; j++){\n if(s[j] - f[j] < x){\n a = true;\n }\n }\n console.log(!a ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var nm = readline().split(\" \").map(x => parseInt(x));\r\n let n = nm[0];\r\n let m = nm[1];\r\n let res = true;\r\n var arr = readline().split(\" \").map(x=> parseInt(x));\r\n arr.sort((n1,n2) => {return n1-n2;});\r\n for (let i = 0;i < n;++i) {\r\n if (arr[i+n] - arr[i] < m) {\r\n res = false;\r\n }\r\n }\r\n console.log((res?'YES':'NO'));\r\n }\r\n\r\n}\r\n"}, {"source_code": "function photographer() {\r\n let [n, dx] = r().split` `.map(Number);\r\n a = r().split` `.map(Number).sort((a, b) => a - b);\r\n heights = a.slice(0, n).map((d, i) => a[i + n] >= d + dx);\r\n return heights.every(d => d) ? 'YES' : 'NO';\r\n}\r\n\r\nfunction main() {\r\n tt = +r();\r\n for (; tt; tt--) log(photographer());\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nr = readline;\r\nlog = console.log;\r\n"}, {"source_code": "'use strict';\n/*\nMark is asked to take a group photo of 2n people. The i-th person has height hi units.\n\nTo do so, he ordered these people into two rows, the front row and the back row, each consisting of n people. However, to ensure that everyone is seen properly, the j-th person of the back row must be at least x units taller than the j-th person of the front row for each j between 1 and n, inclusive.\n\nHelp Mark determine if this is possible.\n*/\nconst main = () => {\n const n = parseInt(readline());\n\n for (let i = 0; i < n; ++i) {\n const [k, minDiff] = readline().split(' ').map(Number);\n const heights = readline().split(' ').map(Number);\n heights.sort((a, b) => a - b);\n let result = true;\n for (let j = 0; j < k; ++j) {\n if (heights[j + k] < heights[j] + minDiff) {\n result = false;\n break;\n }\n }\n console.log(result ? 'YES' : 'NO');\n }\n};\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, d] = readline()\r\n .trim(\" \")\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let i = 0,\r\n ans = true;\r\n while (i < n) {\r\n if (arr[i + n] - arr[i] < d) {\r\n ans = false;\r\n break;\r\n }\r\n i++;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n nx = readline().split(' ').map(el => +el)\r\n n = nx[0]\r\n x = nx[1]\r\n\r\n h = readline().split(' ').map(el => +el)\r\n h.sort((next, prev) => next - prev)\r\n\r\n ans = 'YES'\r\n for(i = 0; i < n; i++){\r\n for(j = n; j < n*2; j++){\r\n \r\n if(h[j] - h[i] < x){\r\n ans = 'NO'\r\n break\r\n }\r\n if(ans == 'NO')\r\n break\r\n i++\r\n }\r\n }\r\n\r\n print(ans)\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var nx = readline().split(' ').map(x=>parseInt(x));\r\n var n = nx[0];\r\n var arr = readline().split(' ').map(x=>parseInt(x));\r\n arr.sort((a,b)=>a-b);\r\n var ans = 'yes';\r\n for (var i =0; i < n; i++) {\r\n if (arr[i+n] - arr[i] < nx[1]) {\r\n ans = 'no';\r\n break;\r\n }\r\n }\r\n print(ans);\r\n }"}], "negative_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n if (back[0] - front[0] >= x) { \n return \"YES\"\n } else {\n return \"NO\"\n }\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_x = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_x[0];\n const x = n_x[1];\n\n if ((n >= 1 && n <= 100) && (x >= 1 && x <= 1000)) {\n const heights = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n if (heights.length == 2*n) {\n const result = isPossible(n, x, heights);\n console.log(result)\n }\n }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) {\n // console.log(n)\n // console.log(x)\n // console.log(heights)\n \n heights.sort();\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n\n // console.log(front)\n // console.log(back)\n \n if (back[0] - front[0] >= x) { \n return \"YES\"\n } else {\n return \"NO\"\n }\n}\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const n_x = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = n_x[0];\n const x = n_x[1];\n const heights = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n\n const result = isPossible(n, x, heights);\n\n console.log(result)\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}], "src_uid": "52769cd7b3b0d63a7259a5d0754c4803"} {"source_code": "var pair = readline().split(' '),\n n = +pair[0],\n k = +pair[1],\n servers = {\n 'parent': function(i) {\n return Math.floor((i-1)/2);\n },\n 'children': function(i) {\n return [2*i + 1, 2*i + 2];\n },\n 'index': [],\n 'heapify': function() {\n var i = 0,\n index = this.index,\n j,\n k,\n l = index.length,\n temp;\n while ((j = this.children(i))[0] < l\n && (index[i] >= index[j[0]] || index[i] >= index[j[1]])) {\n k = (j[1] >= l || index[j[0]] < index[j[1]]) ? j[0] : j[1];\n temp = index[i];\n index[i] = index[k];\n index[k] = temp;\n i = k;\n }\n }\n },\n s,\n m, \n e = [],\n i = 0;\nfor (;i b; };\n\n this.items = new Float64Array(1 + 1) /* zero index + initial capacity */;\n this.count = 0;\n }\n\n BinaryHeap.prototype.toArray = function() {\n var array = [];\n for (var i = 1; i <= this.count; i++) {\n array.push(this.items[i]);\n }\n return array;\n };\n\n BinaryHeap.prototype.insert = function(item) {\n this.items[++this.count] = item;\n \n /* ensure binary heap invariant */\n var child = this.count;\n var parent = child >> 1;\n while (child > 1 && this.predicate(this.items[child], this.items[parent])) {\n var tmp = this.items[child];\n this.items[child] = this.items[parent];\n this.items[parent] = tmp;\n \n child = parent;\n parent = child >> 1;\n }\n\n /* expand array if necessary */\n if (this.count === this.items.length - 1) {\n this.resize(this.count * 2 + 1);\n }\n };\n\n BinaryHeap.prototype.delete = function() {\n if (this.count === 0) throw \"Heap is empty\";\n\n var item = this.items[1];\n this.items[1] = this.items[this.count];\n this.items[this.count--] = null;\n\n /* ensure binary heap invariant */\n var parent = 1;\n var child = parent << 1;\n while (child <= this.count) {\n if (child < this.count) {\n child = this.predicate(this.items[child], this.items[child + 1]) ? child : child + 1;\n }\n \n if (this.predicate(this.items[parent], this.items[child])) break;\n\n var tmp = this.items[parent];\n this.items[parent] = this.items[child];\n this.items[child] = tmp;\n\n parent = child;\n child = parent << 1;\n }\n\n /* shrink array if necessary */\n if (this.count === this.items.length / 4) {\n resize(this.count * 2 + 1);\n }\n\n return item;\n };\n\n BinaryHeap.prototype.length = function() {\n return this.count;\n };\n\n BinaryHeap.prototype.resize = function(capacity) {\n var items = new Float64Array(capacity);\n for (var i = 0; i <= this.count; i++) {\n items[i] = this.items[i];\n }\n this.items = items;\n };\n\n return BinaryHeap;\n})();\n\n\n/*var lines = [];\nlines[0] = \"6 1\";\nlines[1] = \"1 1000000000\";\nlines[2] = \"2 1000000000\";\nlines[3] = \"3 1000000000\";\nlines[4] = \"4 1000000000\";\nlines[5] = \"5 1000000000\";\nlines[6] = \"6 3\";\nvar line = 0;\nfunction readline() {\n\treturn lines[line++];\n}*/\n\n\nfunction readn() {\n\treturn +readline();\n}\nfunction parsens(s) {\n\treturn \ts.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumbers(a,b) {\n\treturn a-b;\n}\n\nvar numbers = parsens(readline());\nvar videosCount = numbers[0];\nvar serversCount = numbers[1];\nvar videoIn = [];\nvar videoSize = [];\nfor (var i = 0; i < videosCount; i++) {\n\tvar numbers = parsens(readline());\n\tvideoIn[i] = numbers[0];\n\tvideoSize[i] = numbers[1];\n}\n\n//console.log(videoIn);\n//console.log(videoSize);\n\nvar videoOut = [];\nvar heap = new BinaryHeap(function(a,b){return a= index[j[0]] || index[i] >= index[j[1]])) {\n k = (j[1] >= l || index[j[0]] < index[j[1]]) ? j[0] : j[1];\n temp = index[i];\n index[i] = index[k];\n index[k] = temp;\n i = k;\n }\n }\n },\n s,\n m, \n e = [],\n i = 0;\nfor (;i b; };\n\n this.items = new Float64Array(1 + 1) /* zero index + initial capacity */;\n this.count = 0;\n }\n\n BinaryHeap.prototype.toArray = function() {\n var array = [];\n for (var i = 1; i <= this.count; i++) {\n array.push(this.items[i]);\n }\n return array;\n };\n\n BinaryHeap.prototype.insert = function(item) {\n this.items[++this.count] = item;\n \n /* ensure binary heap invariant */\n var child = this.count;\n var parent = child >> 1;\n while (child > 1 && this.predicate(this.items[child], this.items[parent])) {\n var tmp = this.items[child];\n this.items[child] = this.items[parent];\n this.items[parent] = tmp;\n \n child = parent;\n parent = child >> 1;\n }\n\n /* expand array if necessary */\n if (this.count === this.items.length - 1) {\n this.resize(this.count * 2 + 1);\n }\n };\n\n BinaryHeap.prototype.delete = function() {\n if (this.count === 0) throw \"Heap is empty\";\n\n var item = this.items[1];\n this.items[1] = this.items[this.count];\n this.items[this.count--] = null;\n\n /* ensure binary heap invariant */\n var parent = 1;\n var child = parent << 1;\n while (child <= this.count) {\n if (child < this.count) {\n child = this.predicate(this.items[child], this.items[child + 1]) ? child : child + 1;\n }\n \n if (this.predicate(this.items[parent], this.items[child])) break;\n\n var tmp = this.items[parent];\n this.items[parent] = this.items[child];\n this.items[child] = tmp;\n\n parent = child;\n child = parent << 1;\n }\n\n /* shrink array if necessary */\n if (this.count === this.items.length / 4) {\n resize(this.count * 2 + 1);\n }\n\n return item;\n };\n\n BinaryHeap.prototype.length = function() {\n return this.count;\n };\n\n BinaryHeap.prototype.resize = function(capacity) {\n var items = new Float64Array(capacity);\n for (var i = 0; i <= this.count; i++) {\n items[i] = this.items[i];\n }\n this.items = items;\n };\n\n return BinaryHeap;\n})();\n\n\nvar lines = [];\nlines[0] = \"6 1\";\nlines[1] = \"1 1000000000\";\nlines[2] = \"2 1000000000\";\nlines[3] = \"3 1000000000\";\nlines[4] = \"4 1000000000\";\nlines[5] = \"5 1000000000\";\nlines[6] = \"6 3\";\nvar line = 0;\nfunction readline() {\n\treturn lines[line++];\n}\n\n\nfunction readn() {\n\treturn +readline();\n}\nfunction parsens(s) {\n\treturn \ts.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumbers(a,b) {\n\treturn a-b;\n}\n\nvar numbers = parsens(readline());\nvar videosCount = numbers[0];\nvar serversCount = numbers[1];\nvar videoIn = [];\nvar videoSize = [];\nfor (var i = 0; i < videosCount; i++) {\n\tvar numbers = parsens(readline());\n\tvideoIn[i] = numbers[0];\n\tvideoSize[i] = numbers[1];\n}\n\n//console.log(videoIn);\n//console.log(videoSize);\n\nvar videoOut = [];\nvar heap = new BinaryHeap(function(a,b){return a 0) {\n\t\t\ttotal += funds[i];\n\t\t}\n\t}\n\n\tprint(total);\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], m = integers[1];\n\n\tvar funds = [];\n\tfor (var i = 0; i < n; i += 1) {\n\t\tfunds.push(0);\n\t}\n\n\tfor (var i = 0; i < m; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar a = integers[0], b = integers[1], debt = integers[2];\n\t\tfunds[a-1] -= debt;\n\t\tfunds[b-1] += debt;\n\t}\n\n\tvar total = 0;\n\tfor (var i = 0; i < n; i += 1) {\n\t\ttotal += Math.abs(funds[i]);\n\t}\n\n\tprint(total/2);\n}\n\nmain();\n"}, {"source_code": "var input = readline();\n input = input.split(' ');\n var people = [];\n var n = input[0],\n m = input[1];\n for(var i=0; i 0;\n}).reduce(function (a, b) {\n return a + b;\n}, 0));\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var a, add, b, c, d, global, i, m, max, min, n, readints, x, _i, _ref, _ref1, _ref2;\n\n readints = function() {\n var x, _i, _len, _ref, _results;\n _ref = readline().split(' ');\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n x = _ref[_i];\n _results.push(x | 0);\n }\n return _results;\n };\n\n add = function(a, b) {\n return a + b;\n };\n\n global = (function() {\n return this;\n })();\n\n _ref = [Math.max, Math.min], max = _ref[0], min = _ref[1];\n\n _ref1 = readints(), n = _ref1[0], m = _ref1[1];\n\n d = (function() {\n var _i, _results;\n _results = [];\n for (_i = 0; 0 <= n ? _i <= n : _i >= n; 0 <= n ? _i++ : _i--) {\n _results.push(0);\n }\n return _results;\n })();\n\n for (i = _i = 0; 0 <= m ? _i < m : _i > m; i = 0 <= m ? ++_i : --_i) {\n _ref2 = readints(), a = _ref2[0], b = _ref2[1], c = _ref2[2];\n d[a] += c;\n d[b] -= c;\n }\n\n d = (function() {\n var _j, _len, _results;\n _results = [];\n for (_j = 0, _len = d.length; _j < _len; _j++) {\n x = d[_j];\n _results.push(max(x, 0));\n }\n return _results;\n })();\n\n print(d.reduce(add));\n\n}).call(this);\n"}, {"source_code": "var nm = readline().trim().split(' ').map((x)=>parseInt(x));\nvar n=nm[0],m=nm[1];\nvar d = {};\nvar _d={};\nvar debt= function(a,b,c) {\n\tthis.a=a;\n\tthis.b=b;\n\tthis.c=c;\n\n\tif(d[a]==undefined)\n\t\td[a]=0;\n\t\t\n\n\tif(_d[b]==undefined)\n\t\t_d[b]=0;\n\t\t\n\td[a]+=c;\n\t_d[b]+=c;\n}\n\nvar debts=[];\nvar input;\nfor (var i = 0; i parseInt(x));\n\tdebts.push(new debt(input[0],input[1],input[2]));\n}\n\nvar ans=0;\nfor (var i in d) {\n\tans+=Math.max(d[i]-(_d[i]==undefined?0:_d[i]),0);\n}\n\nprint(ans);\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], m = integers[1];\n\n\tvar funds = [];\n\tfor (var i = 0; i < n; i += 1) {\n\t\tfunds.push(0);\n\t}\n\n\tfor (var i = 0; i < m; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar a = integers[0], b = integers[1], debt = integers[2];\n\t\tfunds[a] -= debt;\n\t\tfunds[b] += debt;\n\t}\n\n\tvar total = 0;\n\tfor (var i = 0; i < n; i += 1) {\n\t\tif (funds[i] > 0) {\n\t\t\ttotal += funds[i];\n\t\t}\n\t}\n\n\tprint(total);\n}\n\nmain();\n"}], "src_uid": "b53c3e55834db8184d8caf4630aaa573"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n // console.log(a);\n let i = j = 0;\n while (1) {\n while (i < n && a[i] <= 0) i++;\n while ((j <= i || (j < n && a[j] >= 0))) j++;\n if (j >= n) break;\n let v = Math.min(Math.abs(a[i]), Math.abs(a[j]));\n a[i] -= v\n a[j] += v\n }\n // console.log(a);\n let s = 0n;\n a.filter(v => v > 0).forEach(v => s += BigInt(v));\n console.log(s + '');\n }\n})();\n\n", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let s = c = 0;\n For(1, n, i => {\n let x = inp[r++];\n c = c + x;\n if (c < 0) { s -= c; c = 0 }\n })\n console.log(s);\n }\n})();\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n for (let i = 0; i < len - 1; i++) {\n if (arr[i] > 0) {\n arr[i + 1] += arr[i];\n arr[i] = 0;\n }\n }\n\n console.log(arr[len - 1]);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n \n\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n for(let i = 0; i < Math.floor(n/2); i++){\n let temp = a[i];\n a[i] = a[n-i-1];\n a[n-i-1] = temp;\n }\n \n for(let num of a)\n console.log(num);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let tot = 0;\n for(let i = 0; i < n; i++){\n if(a[i] > 0)\n tot += a[i];\n else{\n if(a[i] + tot > 0){\n tot += a[i];\n a[i] = 0;\n }else{\n a[i] += tot;\n tot = 0;\n }\n }\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(a[i] < 0)\n res += a[i];\n\n console.log(res !== 0 ? -1 * res : 0);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let str = readline();\n\n // let dp = new Array(n);\n // for(let i = 0; i < n; i++){\n // dp[i] = new Array(k+1);\n // for(let j = 0; j < k+1; j++){\n // dp[i][j] = new Array(2);\n // }\n // }\n\n // for(let i = 0; i < n; i++){\n // for(let j = 0; j < k+1; j++){\n // if(k % 2 !== 0){\n // dp[i][j][0] = dp[i][j][1] = 0;\n // }else{\n\n // }\n // }\n // }\n\n let isKBalanced = (s) => {\n let p1 = 0;\n let p2 = 0;\n let c0 = 0;\n let c1 = 0;\n while(p2-p1 <= k-1){\n if(s.charAt(p2) === '0')\n c0++;\n else\n c1++;\n p2++\n }\n if(c0 !== k/2 || c1 !== k/2)\n return false;\n \n p2--;\n while(p2 < s.length){\n p2++;\n let x = s.charAt(p1);\n p1++;\n if(p2 < s.length)\n if(s.charAt(p2) !== x)\n return false;\n }\n\n return true;\n }\n\n let map = {};\n let solve = (s, i) => {\n if(i >= s.length)\n return isKBalanced(s);\n\n if(map[`${s}_${i}`] !== undefined)\n return map[`${s}_${i}`];\n \n if(s.charAt(i) === '?'){\n let res0 = solve(s.substring(0,i) + '0' + s.substring(i+1, s.length), i+1);\n if(!res0)\n return map[`${s}_${i}`] = solve(s.substring(0,i) + '1' + s.substring(i+1, s.length), i+1);\n else\n return map[`${s}_${i}`] = res0;\n }else{\n return map[`${s}_${i}`] = solve(s, i+1);\n }\n }\n\n console.log(solve(str, 0) ? 'YES' : 'NO');\n }\n}\n\nfunction F(){\n let [n,x] = ti(readline().split(' '));\n let s = readline();\n let t = readline();\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(x+1);\n for(let j = 0; j <= x; j++){\n dp[i][j] = new Array(n);\n dp[i][j].fill(0);\n }\n }\n\n for(let i = 1; i < n; i++){\n for(let j = 0; j <= x; j++){\n for(let k = 0; k <= n; k++){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));\n if(j !== 0){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);\n }\n }\n }\n }\n\n let max = 0;\n for(let i = 0; i < x; i++)\n for(let j = 0; j < n; j++)\n max = Math.max(max, dp[n-1][i][j]);\n\n console.log(max);\n}"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n let max = Number.MIN_SAFE_INTEGER;\n for (let i = 0; i < len; i++) {\n if (max < arr[i]) max = arr[i];\n }\n let sum = 0n;\n const numIndex = arr.findIndex((num) => num === max);\n\n for (let i = numIndex; i < len; i++) sum += arr[i];\n\n console.log(Number(sum));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n if (len === 1) {\n console.log(Math.abs(Number(arr[0])));\n } else {\n let max = Number.MIN_SAFE_INTEGER;\n for (let i = 0; i < len; i++) {\n if (max < arr[i]) max = arr[i];\n }\n let sum = 0n;\n const numIndex = arr.findIndex((num) => num === max);\n if (numIndex === 0) {\n console.log(0);\n } else {\n for (let i = numIndex; i < len; i++) sum += arr[i];\n\n console.log(Number(sum));\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const max = Math.max(...arr);\n let sum = 0;\n const numIndex = arr.findIndex((num) => num === max);\n\n for (let i = numIndex; i < len; i++) sum += arr[i];\n\n console.log(sum);\n }\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n let i = 0;\n let j = n - 1;\n while (1) {\n while (i < n && a[i] <= 0) i++;\n while (j >= 0 && a[j] >= 0) j--;\n if (i > j) break;\n let v = Math.min(Math.abs(a[i]), Math.abs(a[j]));\n a[i] -= v\n a[j] += v\n }\n // console.log(a);\n console.log(a.filter(v => v > 0).sum());\n }\n})();\n\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n // console.log(a);\n let i = 0;\n while (1) {\n while (i < n && a[i] <= 0) i++;\n let j = i + 1;\n while (j < n && a[j] >= 0) j++;\n if (j >= n) break;\n let v = Math.min(Math.abs(a[i]), Math.abs(a[j]));\n a[i] -= v\n a[j] += v\n }\n console.log(a);\n console.log(a.filter(v => v > 0).sum());\n }\n})();\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n \n\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n for(let i = 0; i < Math.floor(n/2); i++){\n let temp = a[i];\n a[i] = a[n-i-1];\n a[n-i-1] = temp;\n }\n \n for(let num of a)\n console.log(num);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n for(let i = 1; i < n; i++){\n if(a[i] > 0 && a[i-1] > 0){\n a[i] += a[i-1];\n }else if(a[i] < 0 && a[i-1] > 0){\n a[i] += a[i-1];\n }\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(a[i] < 0)\n res += a[i];\n\n console.log(res !== 0 ? -1 * res : 0);\n }\n}\n\nfunction F(){\n let [n,x] = ti(readline().split(' '));\n let s = readline();\n let t = readline();\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(x+1);\n for(let j = 0; j <= x; j++){\n dp[i][j] = new Array(n);\n dp[i][j].fill(0);\n }\n }\n\n for(let i = 1; i < n; i++){\n for(let j = 0; j <= x; j++){\n for(let k = 0; k <= n; k++){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));\n if(j !== 0){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);\n }\n }\n }\n }\n\n let max = 0;\n for(let i = 0; i < x; i++)\n for(let j = 0; j < n; j++)\n max = Math.max(max, dp[n-1][i][j]);\n\n console.log(max);\n}"}], "src_uid": "bd0b14e53ade1207022464ebafdf8c9a"} {"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine();\n let ones = 0, j = word.length;\n for (let i = 0; i < word.length; i += 1) {\n if (word[i] === '1') {\n ones += 1;\n }\n if (j === word.length) {\n if (word[i] === '2') {\n j = i;\n } else {\n if (word[i] === '0') {\n process.stdout.write('0');\n }\n }\n }\n }\n\n for (let i = 0; i < ones; i += 1) {\n process.stdout.write('1');\n }\n\n for (let i = j; i < word.length; i += 1) {\n if (word[i] === '0') {\n process.stdout.write('0');\n } else if (word[i] === '2') {\n process.stdout.write('2');\n }\n }\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine();\n let ones = 0, j = word.length;\n for (let i = 0; i < word.length; i += 1) {\n if (word[i] === '1') {\n ones += 1;\n }\n if (j === word.length && word[i] === '2') {\n j = i;\n }\n }\n\n for (let i = 0; i < j; i += 1) {\n if (word[i] === '0')\n process.stdout.write('0');\n }\n for (let i = 0; i < ones; i += 1) {\n process.stdout.write('1');\n }\n\n for (let i = j; i < word.length; i += 1) {\n if (word[i] !== '1') {\n process.stdout.write(String(word[i]));\n }\n }\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var str = readline ();\nvar cnt = 0, i, answer = '';\nfor ( i = 0; i < str.length; i ++ ) {\n if ( str [ i ] == '1' ) cnt ++;\n else answer += str [ i ];\n}\nvar pos = 0, other = '', actually = '';\nwhile ( cnt -- ) other += '1';\nwhile ( pos < answer.length && answer [ pos ] != '2' ) pos ++;\nif ( pos == answer.length ) actually = (answer + other);\nelse {\n i = 0;\n while ( i < answer.length ) {\n if ( i == pos ) \n actually += other;\n actually += answer [ i ];\n i ++;\n }\n}\nprint ( actually ); \n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine().split('').map(Number);\n let ones = 0;\n word.forEach((item) => {\n if (item === 1)\n ones += 1;\n });\n let j = word.indexOf(2);\n j = j === -1 ? word.length : j;\n\n for (let i = 0; i < j; i += 1) {\n if (word[i] === 0)\n process.stdout.write('0');\n }\n for (let i = 0; i < ones; i += 1) {\n process.stdout.write('1');\n }\n\n for (let i = j; i < word.length; i += 1) {\n if (word[i] !== 1) {\n process.stdout.write(String(word[i]));\n }\n }\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine().split('').map(Number);\n let j = 0;\n for (let i = 1; i < word.length; i += 1) {\n if (word[i] === 1 && word[i - 1] === 2) {\n [word[i], word[i - 1]] = [word[i - 1], word[i]];\n [word[i - 1], word[j]] = [word[j], word[i - 1]];\n }\n if (word[j] === 1)\n j += 1;\n }\n\n const indexLimit = word.indexOf(2);\n const firstWord = word.slice(0, indexLimit);\n const secondWord = word.slice(indexLimit);\n let zeros = 0, ones = 0;\n firstWord.forEach((item) => {\n if (item === 0)\n zeros += 1;\n else\n ones += 1;\n });\n for (let i = 0; i < zeros; i += 1)\n process.stdout.write('0');\n for (let i = 0; i < ones; i += 1)\n process.stdout.write('1');\n console.log(secondWord.join(''));\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine();\n let ones = 0, j = word.length;\n for (let i = 0; i < word.length; i += 1) {\n if (word[i] === '1') {\n ones += 1;\n }\n if (j === word.length) {\n if (word[i] === '2') {\n j = i;\n } else {\n process.stdout.write('0');\n }\n }\n }\n\n for (let i = 0; i < ones; i += 1) {\n process.stdout.write('1');\n }\n\n for (let i = j; i < word.length; i += 1) {\n if (word[i] === '0') {\n process.stdout.write('0');\n } else if (word[i] === '2') {\n process.stdout.write('2');\n }\n }\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const word = is.nextLine().split('').map(Number);\n let ones = 0;\n word.forEach((item) => {\n if (item === 1)\n ones += 1;\n });\n const j = word.indexOf(2);\n\n for (let i = 0; i < j; i += 1) {\n if (word[i] === 0)\n process.stdout.write('0');\n }\n for (let i = 0; i < ones; i += 1) {\n process.stdout.write('1');\n }\n\n for (let i = j; i < word.length; i += 1) {\n if (word[i] !== 1) {\n process.stdout.write(String(word[i]));\n }\n }\n\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "src_uid": "91cefa6793e77b3e4f4896616a164ff2"} {"source_code": "(function () {\n\tfunction Queue (amount) {\n\t\tif(!(this instanceof Queue)) {\n\t\t\treturn new Queue(amount);\n\t\t}\n\t\tamount = amount||1024;\n\t\tthis.amount = amount;\n\t\tthis.bg = 0;\n\t\tthis.ed = 0;\n\t\tthis.arr = [];\n\t}\n\tQueue.prototype = {\n\t\tconstractor: Queue,\n\t\tisEmpty: function () {\n\t\t\treturn (this.bg === this.ed);\n\t\t},\n\t\tdoubleSize: function () {\n\t\t\tvar target = [],\n\t\t\t\to = this.arr,\n\t\t\t\ti = this.bg,\n\t\t\t\tj = this.ed,\n\t\t\t\tl = this.amount;\n\t\t\ttarget.push(o[i])\n\t\t\ti=(i+1)%l;\n\t\t\tfor(;i!=j;i=(i+1)%l)\n\t\t\t\ttarget.push(o[i]);\n\t\t\tthis.amount *= 2;\n\t\t\tthis.bg = 0;\n\t\t\tthis.ed = target.length;\n\t\t\tthis.arr = target;\n\t\t\t//print(this.arr);\n\t\t},\n\t\tpush: function (o) {\n\t\t\tthis.arr[this.ed] = o;\n\t\t\tthis.ed = (this.ed+1)%this.amount;\n\t\t\tif(this.isEmpty()) {\n\t\t\t\tthis.doubleSize();\n\t\t\t}\n\t\t},\n\t\tpop: function () {\n\t\t\tvar idx = this.bg;\n\t\t\tthis.bg = (this.bg+1)%this.amount;\n\t\t\treturn this.arr[idx];\n\t\t}\n\t}\n\tvar rotater = (function () {\n\t\tvar _door = [\n\t\t\t['*'],\n\t\t\t['^','>','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj','v','<'],\n\t\t\t['-','|'], \n\t\t\t['L','U','R','D'],\n\t\t\t['+']\n\t\t];\n\t\tvar _todoor = {},\n\t\t\ti,\n\t\t\tj,\n\t\t\tl;\n\t\tfor(i=0;i<5;++i) {\n\t\t\tl = _door[i].length;\n\t\t\tfor(j=0;j','L','U','D'];\n\t\tvar down = ['+','|','v','L','R','U'];\n\t\tvar left = ['+','-','<','D','R','U'];\n\t\tvar up = ['+','|','^','D','R','L'];\n\t\tfunction lg (c, d) {\n\t\t\tfor(var i=d.length-1;i>=0;--i) {\n\t\t\t\tif(d[i]===c)\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn [\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,right)&&lg(b,left);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,down)&&lg(b,up);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,left)&&lg(b,right);\n\t\t\t},\n\t\t\tfunction (a,b) {\n\t\t\t\treturn lg(a,up)&&lg(b,down);\n\t\t\t}\n\t\t];\n\t})();\n\tfunction readlineInt () {\n\t\treturn readline().split(' ').map(function (e) {\n\t\t\treturn parseInt(e);\n\t\t});\n\t}\n\tvar line = readlineInt();\n\tvar n = line[0],\n\t\tm = line[1];\n\tvar vec = [];\n\tfor(var i=0;i=0&&ii=0&&jj 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n out.push(Math.ceil((a0 + k) / 2) + 0);\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n out.push(Math.ceil((a0 + k) / 2) + 0);\n }\n log(out.join('\\n'))\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let negSum = 0;\n let posSum = 0;\n if(n === 1){\n if(a[0] % 2 === 0)\n console.log(a[0]/2);\n else\n console.log(Math.ceil(a[0]/2));\n\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l,r,x] = ti(readline().split(' '));\n a[0] += x;\n\n if(a[0] % 2 === 0){\n let res = a[0]/2;\n console.log(res === -0 ? 0 : res);\n }\n else{\n let res = Math.ceil(a[0]/2);\n console.log(res === -0 ? 0 : res);\n }\n }\n\n return;\n }\n\n let max = 0;\n let d = new Array(n);\n for(let i = 1; i < n; i++){\n d[i-1] = a[i] - a[i-1];\n max += Math.max(0, d[i-1]);\n } \n\n console.log(Math.ceil((a[0] + max) / 2));\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l, r, x] = ti(readline().split(' '));\n \n if(l-1 !== 0){\n if(d[l-2] > 0)\n max -= d[l-2];\n d[l-2] += x;\n if(d[l-2] > 0)\n max += d[l-2];\n }else{\n a[l-1] += x;\n }\n\n if(r < n){\n if(d[r-1] > 0)\n max -= d[r-1];\n d[r-1] += -x;\n if(d[r-1] > 0)\n max += d[r-1];\n }\n\n console.log(Math.ceil((a[0] + max) / 2));\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n out.push(Math.ceil((a0 + k) / 2) + '');\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n out.push(Math.ceil((a0 + k) / 2) + '');\n }\n log(out.join('\\n'))\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n log(Math.ceil((a0 + k) / 2) + '');\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n log(Math.ceil((a0 + k) / 2) + '');\n }\n}\n\n"}], "negative_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let a0 = a[0];\n let k = Arr(1, n - 1, 1, i => max(a[i] - a[i - 1], 0)).sum();\n log(Math.ceil((a0 + k) / 2));\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(a[l - 1] - a[l - 2], 0);\n k += max(a[l - 1] + x - a[l - 2], 0);\n }\n if (r < n) {\n k -= max(a[r] - a[r - 1], 0);\n k += max(a[r] - a[r - 1] - x, 0);\n }\n log(Math.ceil((a0 + k) / 2));\n }\n}\n\n"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n out.push((a0 + k) / 2 | 0);\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n out.push((a0 + k) / 2 | 0);\n }\n log(out.join('\\n'))\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n let kq = a0 + k;\n out.push((kq + (kq > 0)) / 2 | 0);\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n kq = a0 + k;\n out.push((kq + (kq > 0)) / 2 | 0);\n }\n log(out.join('\\n'))\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let a0 = a[0];\n let k = Arr(1, n - 1, 1, i => max(a[i] - a[i - 1], 0)).sum();\n log(Math.ceil((a0 + k) / 2) + '');\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(a[l - 1] - a[l - 2], 0);\n k += max(a[l - 1] + x - a[l - 2], 0);\n }\n if (r < n) {\n k -= max(a[r] - a[r - 1], 0);\n k += max(a[r] - a[r - 1] - x, 0);\n }\n log(Math.ceil((a0 + k) / 2) + '');\n }\n}\n\n"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let d = Arr(1, n - 1, 1, i => a[i] - a[i - 1]);\n let a0 = a[0];\n let k = d.map(v => v > 0 ? v : 0).sum();\n out.push((a0 + k + (a0 + k > 0)) / 2 | 0);\n let q = $()\n while (q--) {\n let [l, r, x] = $(3)\n if (l == 1) a0 += x;\n else {\n k -= max(d[l - 1], 0);\n d[l - 1] += x;\n k += max(d[l - 1], 0);\n }\n if (r < n) {\n k -= max(d[r], 0);\n d[r] -= x;\n k += max(d[r], 0);\n }\n out.push((a0 + k + (a0 + k > 0)) / 2 | 0);\n }\n log(out.join('\\n'))\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let negSum = 0;\n let posSum = 0;\n if(n === 1){\n if(a[0] % 2 === 0)\n console.log(a[0]/2);\n else\n console.log(Math.ceil(a[0]/2));\n\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l,r,x] = ti(readline().split(' '));\n a[0] += x;\n\n if(a[0] % 2 === 0){\n let res = a[0]/2;\n console.log(res === -0 ? 0 : res);\n }\n else{\n let res = Math.ceil(a[0]/2);\n console.log(res === -0 ? 0 : res);\n }\n }\n\n return;\n }\n\n for(let i = 1; i < n; i++){\n if(a[i] < a[i-1]){\n negSum += (a[i] - a[i-1]);\n }else{\n posSum += (a[i] - a[i-1]);\n }\n }\n\n let getMaxB = (maxC) => {\n let minB = a[0] - maxC;\n return posSum + minB;\n }\n\n console.log(Math.ceil((a[0] + posSum) / 2));\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l, r, x] = ti(readline().split(' '));\n \n if(l-1 !== 0){\n let y = a[l-1] + x;\n if(a[l-2] > y){\n negSum += x;\n }else{\n posSum += x;\n }\n }\n\n if(r !== n){\n let y = a[r-1] + x;\n if(a[r-2] > y){\n negSum += x;\n }else{\n posSum += x;\n }\n }\n\n console.log(Math.ceil((a[0] + posSum) / 2));\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let negSum = 0;\n let posSum = 0;\n if(n === 1){\n if(a[0] % 2 === 0)\n console.log(a[0]/2);\n else\n console.log(Math.ceil(a[0]/2));\n\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l,r,x] = ti(readline().split(' '));\n a[0] += x;\n\n if(a[0] % 2 === 0){\n let res = a[0]/2;\n console.log(res === -0 ? 0 : res);\n }\n else{\n let res = Math.ceil(a[0]/2);\n console.log(res === -0 ? 0 : res);\n }\n }\n\n return;\n }\n\n for(let i = 1; i < n; i++){\n if(a[i] < a[i-1]){\n negSum += (a[i] - a[i-1]);\n }else{\n posSum += (a[i] - a[i-1]);\n }\n }\n\n let getMaxB = (maxC) => {\n let minB = a[0] - maxC;\n return posSum + minB;\n }\n\n let findRes = () => {\n let st = -1000000000;\n let en = 1000000000;\n while(st <= en){\n let maxC = Math.floor((st+en)/2);\n let maxB = getMaxB(maxC);\n if(st === en){\n return st;\n }\n\n if(maxC === maxB){\n return maxC;\n }else if(maxC > maxB){\n en = maxC;\n }else{\n st = maxC+1;\n }\n }\n }\n\n console.log(findRes());\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l, r, x] = ti(readline().split(' '));\n \n if(l-1 !== 0){\n let y = a[l-1] + x;\n if(a[l-2] > y){\n negSum += x;\n }else{\n posSum += x;\n }\n }\n\n if(r !== n){\n let y = a[r-1] + x;\n if(a[r-2] > y){\n negSum += x;\n }else{\n posSum += x;\n }\n }\n\n\n\n console.log(findRes());\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction D(){\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let negSum = 0;\n let posSum = 0;\n if(n === 1){\n if(a[0] % 2 === 0)\n console.log(a[0]/2);\n else\n console.log(Math.ceil(a[0]/2));\n\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l,r,x] = ti(readline().split(' '));\n a[0] += x;\n\n if(a[0] % 2 === 0){\n let res = a[0]/2;\n console.log(res === -0 ? 0 : res);\n }\n else{\n let res = Math.ceil(a[0]/2);\n console.log(res === -0 ? 0 : res);\n }\n }\n\n return;\n }\n\n for(let i = 1; i < n; i++){\n if(a[i] < a[i-1]){\n negSum += (a[i] - a[i-1]);\n }else{\n posSum += (a[i] - a[i-1]);\n }\n }\n\n let getMaxB = (maxC) => {\n let minB = a[0] - maxC;\n return posSum + minB;\n }\n\n console.log(Math.ceil((a[0] + posSum) / 2));\n let q = pi(readline());\n while(q > 0){\n q--;\n let [l, r, x] = ti(readline().split(' '));\n \n if(l-1 !== 0){\n if(a[l-2] > a[l-1]){\n negSum -= (a[l-1]-a[l-2]);\n }else{\n posSum -= (a[l-1]-a[l-2]);\n }\n a[l-1] += x;\n if(a[l-2] > a[l-1]){\n negSum += (a[l-1]-a[l-2]);\n }else{\n posSum += (a[l-1]-a[l-2]);\n }\n }\n\n if(r < n){\n if(a[r-1] > a[r]){\n negSum -= (a[r]-a[r-1]);\n }else{\n posSum -= (a[r]-a[r-1]);\n }\n a[r-1] += x;\n if(a[r-1] > a[r]){\n negSum += (a[r]-a[r-1]);\n }else{\n posSum += (a[r]-a[r-1]);\n }\n }\n\n console.log(Math.ceil((a[0] + posSum) / 2));\n }\n}"}], "src_uid": "85f5033a045d331c12fc62f9b7816bed"} {"source_code": "var ip = readline().split(' ').map(Number),res = '';\nvar c = ip[0]%(2*ip[1]+1);\nif (c !== 0) {\n res += (Math.max(1, c-ip[1])) +' ';\n c = Math.max(c, Math.max(1,c-ip[1])+ip[1]);\n}\nwhile(c+ip[1]+1 <= ip[0]) {\n res += (c+ip[1]+1)+' ';\n c += 2*ip[1]+1;\n}\nprint(Math.floor((ip[0]+2*ip[1])/(2*ip[1]+1)));\nprint(res)", "positive_code": [{"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nvar ans = [];\nif (n % maxFlip === 0) {\n for (var i = k + 1; i <= n; i += maxFlip) {\n ans.push(i);\n }\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, k + 1 - d / 2);\n for (var i = 1 + Math.floor(d / 2); i <= n; i += maxFlip) {\n ans.push(i);\n }\n}\nprint(ans.length);\nprint(ans.join(' '));"}, {"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// define __esModule on exports\n/******/ \t__webpack_require__.r = function(exports) {\n/******/ \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n/******/ \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n/******/ \t\t}\n/******/ \t\tObject.defineProperty(exports, '__esModule', { value: true });\n/******/ \t};\n/******/\n/******/ \t// create a fake namespace object\n/******/ \t// mode & 1: value is a module id, require it\n/******/ \t// mode & 2: merge all properties of value into the ns\n/******/ \t// mode & 4: return value when already ns object\n/******/ \t// mode & 8|1: behave like require\n/******/ \t__webpack_require__.t = function(value, mode) {\n/******/ \t\tif(mode & 1) value = __webpack_require__(value);\n/******/ \t\tif(mode & 8) return value;\n/******/ \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n/******/ \t\tvar ns = Object.create(null);\n/******/ \t\t__webpack_require__.r(ns);\n/******/ \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n/******/ \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n/******/ \t\treturn ns;\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = \"./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js\");\n/******/ })\n/************************************************************************/\n/******/ ({\n\n/***/ \"./helpers/input-manager.js\":\n/*!**********************************!*\\\n !*** ./helpers/input-manager.js ***!\n \\**********************************/\n/*! exports provided: InputManager */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"InputManager\", function() { return InputManager; });\nconst fs = __webpack_require__(/*! fs */ \"fs\");\n\nclass InputManager {\n static getInput() {\n return new Promise((resolve) => {\n let input = '';\n\n if (fs.existsSync('./input.txt')) {\n input = fs.readFileSync('./input.txt').toString();\n resolve(this.parseInputString(input));\n } else {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', inputStdin => {\n input += inputStdin;\n });\n\n process.stdin.on('end', () => {\n resolve(this.parseInputString(input));\n });\n }\n });\n }\n\n static parseInputString(input) {\n return input.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n }\n}\n\n/***/ }),\n\n/***/ \"./helpers/solution-manager.js\":\n/*!*************************************!*\\\n !*** ./helpers/solution-manager.js ***!\n \\*************************************/\n/*! exports provided: SolutionManager */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"SolutionManager\", function() { return SolutionManager; });\nclass SolutionManager {\n static printSolution(solutionFn) {\n let result = solutionFn();\n if (typeof result !== 'undefined') {\n if (Array.isArray(result)) {\n result.forEach(v => console.log(v));\n } else {\n console.log(result);\n }\n }\n }\n}\n\n/***/ }),\n\n/***/ \"./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js\":\n/*!***********************************************************************************************!*\\\n !*** ./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js ***!\n \\***********************************************************************************************/\n/*! no exports provided */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _helpers_solution_manager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../../../helpers/solution-manager */ \"./helpers/solution-manager.js\");\n/* harmony import */ var _helpers_input_manager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../../../helpers/input-manager */ \"./helpers/input-manager.js\");\n\n\n\n_helpers_input_manager__WEBPACK_IMPORTED_MODULE_1__[\"InputManager\"].getInput().then((input) => _helpers_solution_manager__WEBPACK_IMPORTED_MODULE_0__[\"SolutionManager\"].printSolution(() => {\n let [n, k] = input.shift().split(' ').map(v => Number(v));\n let maxTurn = k * 2 + 1;\n let remainder = n % maxTurn;\n\n let i = remainder === 0 || remainder > maxTurn / 2 ? k : 0;\n let moves = [i];\n while (i + maxTurn <= n) {\n i += maxTurn;\n\n if (i === n && k === 0) {\n break;\n }\n\n moves.push(i);\n }\n\n console.log(moves.length);\n console.log(moves.map(v => v + 1).join(' '));\n}));\n\n/***/ }),\n\n/***/ \"fs\":\n/*!*********************!*\\\n !*** external \"fs\" ***!\n \\*********************/\n/*! no static exports found */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ })\n\n/******/ });\n//# sourceMappingURL=index.built.js.map"}, {"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nvar ans = [];\nif (n % maxFlip === 0) {\n for (var i = k + 1; i <= n; i += maxFlip) {\n ans.push(i);\n }\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, k + 1 - d / 2);\n for (var i = 1 + Math.floor(d / 2); i <= n; i += maxFlip) {\n ans.push(i);\n }\n}\nprint(ans.length);\nprint(ans.join(' '));"}, {"source_code": "var ip = readline().split(' ').map(Number),i = 1;\nfor (;i<=ip[1]+1;i++){\n var remain = Math.max(ip[0] - ip[1] - i,0);\n remain %= (ip[1]*2 + 1);\n if ((remain >= ip[1]+1 && remain <= ip[1]*2) || remain === 0){\n break; \n }\n}\nprint(Math.floor((ip[0] + ip[1]*2)/(ip[1]*2+1)));\nvar res = '';\nwhile (i <= ip[0]){\n res += i+' ';\n i += (ip[1]*2+1);\n}\nprint(res)"}], "negative_code": [{"source_code": "var ip = readline().split(' ').map(Number),i = 1;\nfor (;i<=ip[1]+1;i++){\n var remain = ip[0] - ip[1] - i;\n remain %= (ip[1]*2 + 1);\n if ((remain >= ip[1]+1 && remain <= ip[1]*2) || remain === 0){\n break; \n }\n}\nprint(Math.floor((ip[0] + ip[1]*2)/(ip[1]*2+1)));\nvar res = '';\nwhile (i <= ip[0]){\n res += i+' ';\n i += (ip[1]*2+1);\n}\nprint(res)"}, {"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nif (n <= maxFlip) {\n print(1);\n print(Math.min(n, k + 1));\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, Math.floor(k + 1 - d / 2));\n var ans = [];\n for (var i = f; i <= n; i += maxFlip) {\n ans.push(i);\n }\n print(ans.length);\n print(ans.join(' '));\n}"}, {"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nif (n <= maxFlip) {\n print(1);\n print(Math.min(n, k + 1));\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, k + 1 - d / 2);\n var ans = [];\n for (var i = f; i <= n; i += maxFlip) {\n ans.push(i);\n }\n print(ans.length);\n print(ans.join(' '));\n}"}, {"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nif (n <= maxFlip) {\n print(1);\n print(Math.min(n, k + 1));\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, k + 1 - d);\n var ans = [];\n for (var i = f; i < n; i += maxFlip) {\n ans.push(i);\n }\n print(ans.length);\n print(ans.join(' '));\n}"}, {"source_code": "var x = readline().split(\" \").map(x => Number(x));\nvar n = x[0];\nvar k = x[1];\n\nvar maxFlip = 2 * k + 1;\n\nif (n <= maxFlip) {\n print(1);\n print(Math.min(n, k + 1));\n} else {\n var d = n % maxFlip;\n var f = Math.max(1, k + 1 - d);\n var ans = [];\n for (var i = f; i <= n; i += maxFlip) {\n ans.push(i);\n }\n print(ans.length);\n print(ans.join(' '));\n}"}], "src_uid": "dfd60a02670749c67b0f96df1a0709b9"} {"source_code": "var tmp = readline().split(' ').map(Number);\n\nvar server = tmp[0];\nvar qlen = tmp[1];\n\nvar queue = [];\nfor(var i =0; i < server; i++)\n{\n tmp = readline(); \n queue.push(tmp.split(' ').map(Number));\n}\n\nvar q = 0;\nvar qq = [];\nvar tm = queue[0][0];\nvar output = [];\nfor(var i = 0; i < server; i++)\n{\n for(var j = 0; j < qq.length; j++)\n {\n if(qq[j] <= queue[i][0])\n {\n //var idx = qq.indexOf(qq[j]); \n qq.splice(j, 1);\n q--;\n } else {\n break;\n }\n }\n if(tm <= queue[i][0])\n {\n tm = queue[i][0] + queue[i][1];\n q = 0;\n write(tm);\n \n }else if(tm > queue[i][0] && q < qlen)\n {\n q++;\n qq.push(tm);\n tm += queue[i][1];\n write(tm);\n \n } else\n {\n write(-1);\n }\n write(' ');\n}", "positive_code": [{"source_code": "var readInt = () => parseInt(readline())\nvar readIntArray = () => readline().split(' ').map(item => parseInt(item))\nfunction range(a, b) {\n var res = []\n for (var i = a; i <= b; i++) {\n res.push(i)\n }\n return res\n}\nvar inputData = readIntArray()\nvar n = inputData[0]\nvar b = inputData[1]\nvar res = []\n\nvar q = []\nvar h = 0\n\nvar s = 0\nvar f = 0\nfor (var i = 0; i < n; i++) {\n var inputData = readIntArray()\n var t = inputData[0]\n var d = inputData[1]\n \n s = t\n while (t > f) {\n if (q.length - h > 0) {\n qh = q[h++] //pop\n f += qh.v\n res[qh.i] = f\n }\n else break;\n }\n if (t >= f) {\n f = t\n if (q.length - h > 0) {\n qh = q[h++] //pop\n f += qh.v\n res[qh.i] = f\n \n if (q.length-h+1 <= b)\n {\n q.push({i:i, v:d})\n } else res[i] = -1\n \n }\n else {\n f += d\n res[i] = f\n }\n }\n else {\n if (q.length-h+1 <= b)\n {\n q.push({i:i, v:d})\n } else res[i] = -1\n }\n}\nwhile (q.length > h) {\n qh = q[h++] //pop\n f += qh.v\n res[qh.i] = f\n}\nprint(res.join(' '))"}, {"source_code": "var input = readline().split(' ')\n\nvar n = Number(input[0]),\n b = Number(input[1])\n\nvar endtime = 0,\n queue = []\n\nvar result = []\n\nfor (var i = 0; i < n; i++) {\n\n var input = readline().split(' '), \n t = Number(input[0]), \n d = Number(input[1])\n\n var idx = findIndex(queue, t)\n\n if (t >= endtime) {\n endtime = t + d\n result.push(endtime)\n } else {\n if (queue.length - idx < b) {\n queue.push(endtime)\n endtime = endtime + d\n result.push(endtime)\n } else {\n result.push(-1)\n }\n }\n\n}\n\nfunction findIndex (array, value) {\n var from = 0, to = array.length\n while (to > from + 1) {\n var i = from + ((to - from) >>> 1)\n if (array[i] > value) {\n to = i\n } else {\n from = i\n }\n }\n \n return array[from] > value ? from : to\n}\n\n\nprint(result.join(' ') + '\\n')"}, {"source_code": "var input = readline().split(' '), n = +input[0], b = +input[1], p = 0, q = [], result = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar query = readline().split(' ').map(Number);\n\tfor (var j = 0; j < q.length; j++) {\n\t\tif (q[j] <= query[0]) {\n\t\t\tq.splice(j, 1);\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (p <= query[0]) {\n\t\tp = query[0] + query[1];\n\t\tq = [];\n\t} else if (q.length < (b + 1)) {\n\t\tp = p + query[1];\n\t} else {\n\t\t//print(-1);\n\t\tresult.push(-1);\n\t\tcontinue;\n\t}\n\tquery[2] = p;\n\tq.push(p);\n\t// print(p);\n\tresult.push(p);\n}\n\nprint(result.join(' '));"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/day4/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = [];\n\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim().split(' ').map(Number));\n}).on('close', () => {\n const length = lines[0][0];\n const maxQueue = lines[0][1];\n let freeMoment = 0;\n let momentQueue = [];\n\n const ableToPutInQueue = (t, queue) => {\n let l = 0,\n r = queue.length - 1;\n let pivot;\n\n if (l === r) {\n // l === r === 0\n return maxQueue >= 1;\n }\n\n if (r - l === 1) {\n if (t >= queue[l]) {\n return maxQueue >= 1;\n } else {\n return maxQueue >= 2;\n }\n }\n\n while (true) {\n pivot = Math.floor((l + r) / 2);\n if (queue[pivot] === t) {\n return queue.length - pivot - 1 <= maxQueue;\n }\n\n if (r - l === 1) {\n if (queue[l] > t) {\n return queue.length - l <= maxQueue;\n }\n return queue.length - pivot - 1 <= maxQueue;\n }\n\n if (queue[pivot] >= t) {\n r = pivot;\n } else {\n l = pivot;\n }\n }\n };\n // const ableToPutInQueue = (t, queue) => {\n // let count = 0;\n // for (let i = queue.length - 1; i >= 0; i--) {\n // if (queue[i] > t) {\n // count++;\n // }\n // if (count > maxQueue) {\n // return false;\n // }\n // }\n // return true;\n // };\n\n for (let i = 1; i <= length; i++) {\n let t = lines[i][0];\n let d = lines[i][1];\n // is server free --> process\n // is server busy, and queue is not full --> push into the queue\n if (t > freeMoment) {\n freeMoment = t + d;\n } else if (ableToPutInQueue(t, momentQueue)) {\n freeMoment = freeMoment + d;\n } else {\n console.log(-1);\n continue;\n }\n console.log(freeMoment);\n momentQueue.push(freeMoment);\n }\n});\n"}, {"source_code": "var readline = require('readline');\n\nvar input = [];\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// rl.prompt();\n\nrl.on('line', function(cmd) {\n input.push(cmd);\n});\n\n// const string = `5 1\n// 2 9\n// 4 8\n// 10 9\n// 15 2\n// 19 1`;\n\n// input.push('6 1');\n// input.push('2 9');\n// input.push('4 8');\n// input.push('10 9');\n// input.push('15 2');\n// input.push(' 19 1');\n// input.push('10008348907 1');\n\nrl.on('close', function(cmd) {\n let inputArray = input;\n // inputArray = input.split('\\n');\n\n const infoQueries = inputArray[0]\n .split(' ')\n .filter(x => x)\n .map(s => parseInt(s, 10));\n\n inputArray.shift();\n\n const queries = inputArray\n .map(i =>\n i\n .split(' ')\n .filter(x => x)\n .map(s => parseInt(s, 10))\n )\n // .filter(q => q[0] <= 1000000000 && q[1] <= 1000000000)\n .map(q => ({\n startTime: q[0],\n processingTime: q[1],\n processedTime: 0\n }));\n\n const numberOfQueries = Math.min(infoQueries[0], queries.length);\n const queueSize = infoQueries[1];\n\n let timestamp = queries[0].startTime + queries[0].processingTime;\n queries[0].processedTime = timestamp;\n const queue = [];\n\n queue.push(timestamp);\n\n for (let i = 1; i < numberOfQueries; i++) {\n const query = queries[i];\n\n // Remove all processed queries\n while (queue.length && query.startTime >= queue[0]) {\n queue.shift();\n }\n\n if (query.startTime >= timestamp) {\n timestamp = query.startTime + query.processingTime;\n query.processedTime = timestamp;\n queue.push(timestamp);\n continue;\n }\n\n if (queue.length > queueSize) {\n // console.log('exceeded!');\n query.processedTime = -1;\n } else {\n timestamp += query.processingTime;\n query.processedTime = timestamp;\n queue.push(timestamp);\n }\n\n // console.log('queue', queue);\n }\n\n console.log(\n `${queries\n .map(x => x.processedTime)\n .filter(x => x)\n .join(' ')}`\n );\n\n process.exit(0);\n});\n"}, {"source_code": "var readline = require('readline');\n\nvar input = [];\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// rl.prompt();\n\nrl.on('line', function(cmd) {\n input.push(cmd);\n});\n\n// const string = `5 1\n// 2 9\n// 4 8\n// 10 9\n// 15 2\n// 19 1`;\n\n// input.push('6 1');\n// input.push('2 9');\n// input.push('4 8');\n// input.push('10 9');\n// input.push('15 2');\n// input.push(' 19 1');\n// input.push('10008348907 1');\n\nrl.on('close', function(cmd) {\n let inputArray = input;\n // inputArray = input.split('\\n');\n\n const infoQueries = inputArray[0]\n .split(' ')\n .filter(x => x)\n .map(s => parseInt(s, 10));\n\n inputArray.shift();\n\n const queries = inputArray\n .map(i =>\n i\n .split(' ')\n .filter(x => x)\n .map(s => parseInt(s, 10))\n )\n // .filter(q => q[0] <= 1000000000 && q[1] <= 1000000000)\n .map(q => ({\n startTime: q[0],\n processingTime: q[1],\n processedTime: 0\n }));\n\n const numberOfQueries = Math.min(infoQueries[0], queries.length);\n const queueSize = infoQueries[1];\n\n let timestamp = queries[0].startTime + queries[0].processingTime;\n queries[0].processedTime = timestamp;\n const queue = [];\n\n queue.push(timestamp);\n\n for (let i = 1; i < numberOfQueries; i++) {\n const query = queries[i];\n\n // Remove all processed queries\n while (queue.length && query.startTime >= queue[0]) {\n queue.shift();\n }\n\n if (query.startTime >= timestamp) {\n timestamp = query.startTime + query.processingTime;\n query.processedTime = timestamp;\n queue.push(timestamp);\n continue;\n }\n\n if (queue.length > queueSize) {\n // console.log('exceeded!');\n query.processedTime = -1;\n } else {\n timestamp += query.processingTime;\n query.processedTime = timestamp;\n queue.push(timestamp);\n }\n\n // console.log('queue', queue);\n }\n\n s = queries\n .map(x => x.processedTime)\n .filter(x => x)\n .join(' ');\n console.log(s)\n\n process.exit(0);\n});\n"}], "negative_code": [{"source_code": "var tmp = readline().split(' ').map(Number);\n\nvar server = tmp[0];\nvar qlen = tmp[1];\n\nvar queue = [];\nfor(var i =0; i < server; i++)\n{\n tmp = readline(); \n queue.push(tmp.split(' ').map(Number));\n}\n\nvar q = 0;\nvar qq = [];\nvar tm = queue[0][0];\nvar output = [];\nfor(var i = 0; i < server; i++)\n{\n for(var j = 0; j < qq.length; j++)\n {\n if(qq[j] <= queue[i][0])\n {\n //var idx = qq.indexOf(qq[j]); \n qq.splice(j, 1);\n q--;\n } else {\n break;\n }\n }\n if(tm <= queue[i][0])\n {\n tm += queue[i][1];\n q = 0;\n write(tm);\n \n }else if(tm > queue[i][0] && q < qlen)\n {\n q++;\n qq.push(tm);\n tm += queue[i][1];\n write(tm);\n \n } else\n {\n write(-1);\n }\n write(' ');\n}\n//print(output.join(' '));\n\n"}, {"source_code": "var input = readline().split(' ')\n , n = +input[0]\n , b = +input[1]\n , p = 0\n , q = []\n , result = [];\n \nfor (var i = 0; i < n; i++ ) {\n var query = readline().split(' ').map(Number);\n\tfor (var j = 0; j < q.length; j++) {\n\t\tif (q[0][2] <= query[0]) {\n\t\t\tq.splice(j, 1);\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n if (p <= query[0]) {\n p = query[0] + query[1];\n\t\tq = [];\n } else if (q.length < (b + 1)) {\n p = p + query[1];\n } else {\n //print(-1);\n result.push(-1);\n continue;\n }\n query[2] = p;\n q.push(query);\n // print(p);\n result.push(p);\n}\n\nprint(result.join(' '));"}, {"source_code": "const readline = require('readline');\nconst fs = require('fs');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n // input: fs.createReadStream('src/day4/0.input1.json'),\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = [];\n\n/**\n * Time complexity:\n * Space complexity:\n */\nrl.on('line', function (line) {\n lines.push(line.trim().split(' ').map(Number));\n}).on('close', () => {\n const length = lines[0][0];\n const maxQueue = lines[0][1];\n let freeMoment = 0;\n let momentQueue = [];\n\n const ableToPutInQueue = (t, queue) => {\n let l = 0,\n r = queue.length - 1;\n let pivot;\n\n if (l === r) {\n // l === r === 0\n return maxQueue >= 1;\n }\n\n if (r - l === 1) {\n if (t >= queue[l]) {\n return maxQueue >= 1;\n } else {\n return maxQueue >= 2;\n }\n }\n\n while (true) {\n pivot = Math.floor((l + r) / 2);\n if (queue[pivot] === t || r - l === 1) {\n return queue.length - pivot - 1 <= maxQueue;\n }\n\n if (queue[pivot] >= t) {\n r = pivot;\n } else {\n l = pivot;\n }\n }\n };\n // const ableToPutInQueue = (t, queue) => {\n // let count = 0;\n // for (let i = queue.length - 1; i >= 0; i--) {\n // if (queue[i] > t) {\n // count++;\n // }\n // if (count > maxQueue) {\n // return false;\n // }\n // }\n // return true;\n // };\n\n for (let i = 1; i <= length; i++) {\n let t = lines[i][0];\n let d = lines[i][1];\n // is server free --> process\n // is server busy, and queue is not full --> push into the queue\n if (t > freeMoment) {\n freeMoment = t + d;\n } else if (ableToPutInQueue(t, momentQueue)) {\n freeMoment = freeMoment + d;\n } else {\n console.log(-1);\n continue;\n }\n console.log(freeMoment);\n momentQueue.push(freeMoment);\n }\n});\n"}], "src_uid": "5981594b2d6d1077ce2249b641d18f10"} {"source_code": "// // Importing the module\r\n// const readline = require(\"readline-sync\");\r\n\r\n// // Enter the number\r\n// let s = String(readline.question());\r\n// let array = [];\r\n// let ab = 0;\r\n// let ba = 0;\r\n\r\n// if (s.length === 1) {\r\n// return;\r\n// }\r\n\r\n// else if (s.length === 2) {\r\n// if (s[0] === 'a' && s[1] === 'b') {\r\n// s = 'aa';\r\n// } else if (s[0] === 'b' && s[1] === 'a') {\r\n// s = 'aa';\r\n// }\r\n// }\r\n\r\n// for (let i = 0; i < s.length; ++i) {\r\n// if (s[i] === 'a' && s[i + 1] === 'b') {\r\n// ab++;\r\n// } else if (s[i] === 'b' && s[i + 1] === 'a') {\r\n// ba++\r\n// }\r\n// array.push(s[i]);\r\n// }\r\n\r\n// if (ab !== ba) {\r\n// let occurence = array.indexOf('a');\r\n\r\n// array[occurence] = 'b';\r\n// }\r\n\r\nprocess.stdin.setEncoding('utf-8');\r\nconst readline = require('readline'); // reading line\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data;\r\n\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim());\r\n\r\n count--;\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(str) {\r\n if (str[str.length - 1] === str[0]) {\r\n console.log(str)\r\n } else {\r\n const res = str.split('')\r\n res.splice(0, 1, str[str.length - 1])\r\n console.log(res.join(''))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n solve(inputArr[i]);\r\n }\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split('');\n\t a[0] = a[a.length - 1];\n\t var ans = '';\n\t for(j = 0; j < a.length; j++){\n\t ans += a[j];\n\t }\n\t console.log(ans);\n\t}\n});\n\n\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet s = rl();\r\n\t\tlet n = s.length;\r\n\r\n\t\tlet ans = s;\r\n\t\tif (s[0] != s[n - 1])\r\n\t\t\tans = s[n - 1] + s.slice(1);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet s = rl();\r\n\t\tlet n = s.length;\r\n\r\n\t\tlet abcnt = bacnt = 0;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tif (s[i] != s[i + 1]) {\r\n\t\t\t\tif (s[i] == 'a') abcnt++;\r\n\t\t\t\telse bacnt++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans = s.split('');\r\n\t\tif (abcnt != bacnt) \r\n\t\t\tans[n - 1] = s[n - 1] == 'a' ? 'b' : 'a';\r\n\r\n\t\tconsole.log(ans.join(''));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\nvar stdin_input = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\n\nconst rl = () => dataitr.next().value.trim();\nconst rn = () => Number(rl());\nconst ra = () => rl().split(' ');\nconst rna = () => ra().map(x => Number(x));\n\nfunction main () {\n\tlet t = rn();\n\twhile (t--) {\n\t\tlet s = rl();\n\t\tlet n = s.length;\n\n\t\tlet ans = s;\n\t\tif (s[0] != s[n - 1])\n\t\t\tans = s[n - 1] + s.slice(1);\n\n\t\tconsole.log(ans);\n\t}\n}\n\n\n\t \t\t\t\t\t\t \t \t \t\t \t\t\t\t\t \t\t\t"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let s1 = 0\n let s2 = 0\n for (let i = 1; i < str.length; i++) {\n const s = str[i - 1] + str[i]\n if (s === 'ab') s1++\n if (s === 'ba') s2++\n }\n// console.log(s1, s2)\n if (s1 === s2) return str\n let d = Math.abs(s1 - s2)\n let a = 'a' // a -> b\n let b = 'b'\n if (s1 < s2) {\n a = 'b'\n b = 'a'\n }\n const ans = []\n for (let i = 0; i < str.length; i++) {\n if (d && str[i] === a && (!i || str[i - 1] !== b)) {\n ans.push(b)\n d--\n } else {\n ans.push(str[i])\n }\n }\n return ans.join('')\n}\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(str) {\r\n if (str[str.length - 1] === str[0]) {\r\n console.log(str)\r\n } else {\r\n const res = str.split('')\r\n res.splice(0, 1, str[str.length - 1])\r\n console.log(res.join(''))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tif(s[0] != s[N - 1]){\r\n\t\t\ts[0] = s[N - 1];\r\n\t\t}\r\n\t\tmyout(myconv(s, 0));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n\tfor(i = 1; i <= t; i++){\n\t var a = lines[i].split('');\n\t console.log(a);\n\t}\n});\n\n\n"}], "src_uid": "351ffff1dfe1bc1762f062f612463759"} {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar n3 = n / 3;\n\tvar m = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0};\n\treadline().split(' ').forEach(function (e) { m[e] = m[e] ? m[e] + 1 : 1; });\n\n\tprint((function () {\n\t\tif (m[5] || m[1] !== n3 || m[2]+m[3] !== n3 || m[4]+m[6] !== n3) return -1;\n\n\t\tvar ret = [];\n\t\tfor (var i = 0; i < n3; i++) {\n\t\t\tvar k = [1];\n\t\t\tif (m[2] && m[4]) {\n\t\t\t\tk.push(2, 4);\n\t\t\t\tm[2]--; m[4]--;\n\t\t\t} else if (m[3] && m[6]) {\n\t\t\t\tk.push(3, 6);\n\t\t\t\tm[3]--; m[6]--;\n\t\t\t} else if (m[2] && m[6]) {\n\t\t\t\tk.push(2, 6);\n\t\t\t\tm[2]--; m[6]--;\n\t\t\t} else return -1;\n\n\t\t\tret.push(k.join(' '));\n\t\t}\n\n\t\treturn ret.join('\\n');\n\t})());\n\n}).call(this);", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const map = {};\n const limit = Math.floor(len / 3);\n let [count124, count126, count136] = [0, 0, 0];\n for (let value of arr) {\n map[value] = (map[value] || 0) + 1;\n }\n\n if (\n map[1] >= limit &&\n ((map[1] && map[2] && map[4]) || (map[1] && map[2] && map[6]) || (map[1] && map[3] && map[6]))\n ) {\n if (map[1] > 0 && map[2] > 0 && map[4] > 0) {\n count124 = Math.min(map[1], map[2], map[4]);\n map[1] -= count124;\n map[2] -= count124;\n map[4] -= count124;\n }\n if (map[1] > 0 && map[2] > 0 && map[6] > 0) {\n count126 = Math.min(map[1], map[2], map[6]);\n map[1] -= count126;\n map[2] -= count126;\n map[6] -= count126;\n }\n if (map[1] > 0 && map[3] > 0 && map[6] > 0) {\n count136 = Math.min(map[1], map[3], map[6]);\n map[1] -= count136;\n map[3] -= count136;\n map[6] -= count136;\n }\n if (count124 + count126 + count136 === limit) {\n for (let i = 0; i < count124; i++) console.log(`${1} ${2} ${4}`);\n for (let i = 0; i < count126; i++) console.log(`${1} ${2} ${6}`);\n for (let i = 0; i < count136; i++) console.log(`${1} ${3} ${6}`);\n } else {\n console.log(-1);\n }\n } else {\n console.log(-1);\n }\n}\n"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; ic2 || c3>c6) {print('-1');quit()} \np1 = c4;\np3 = c3;\np2 = am/3 - c3 - c4;\n\nfor(var i = 0; i0 && c2>0 && c4>0 && p1>0){\n print('1 2 4');\n c1--; c2--; c4--;p1--;\n }\n if(c1>0 && c2>0 && c6>0 && p2>0){\n print('1 2 6');\n c1--; c2--; c6--;p2--;\n }\n if(c1>0 && c3>0 && c6>0 && p3>0){\n print('1 3 6');\n c1--; c3--; c6--;p3--;\n }\n}\nif(c1>0 || c2>0 || c3>0 || c4>0 || c6>0){\nprint('-1')\n}"}, {"source_code": "print(function(n, a) {\n\tvar ans = [],\n\t\tc = new Int32Array(8);\n\n\tfor (var i = 0; i < n; i++)\n\t\tc[a[i]]++;\n\n\tvar c4 = c[4],\n\t\tc2 = c[2];\n\tfor (i = 1; i <= n / 3; i++) {\n\t\tif (i <= c4) {\n\t\t\tans.push('1 2 4');\n\t\t\tc[1]--, c[2]--, c[4]--;\n\t\t} else if (i <= c2) {\n\t\t\tans.push('1 2 6');\n\t\t\tc[1]--, c[2]--, c[6]--;\n\t\t} else {\n\t\t\tans.push('1 3 6');\n\t\t\tc[1]--, c[3]--, c[6]--;\n\t\t}\n\t}\n\tfor (var i = 1; i <= 7; i++)\n\t\tif (c[i] !== 0) return -1;\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a) {\n\tvar ans = [], c = new Int32Array(8);\n\n\tfor (var i = 0; i < n; i++)\n\t\tc[a[i]]++;\n\n\tvar c4=c[4], c2=c[2];\n\tfor (i = 1; i <= n / 3; i++)\n\t\tif (i <= c4){\n\t\t\tans.push('1 2 4');\n\t\t\tc[1]--, c[2]--, c[4]--;\n\t\t}\n\t\telse if (i <= c2){\n\t\t\tans.push('1 2 6');\n\t\t\tc[1]--, c[2]--, c[6]--;\n\t\t}else{\n\t\t\tans.push('1 3 6');\n\t\t\tc[1]--, c[3]--, c[6]--;\n\t\t}\n\n\tfor(var i=1; i<=7; i++)\n\t\tif(c[i]!==0) return -1;\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a) {\n\tvar b = new Int32Array(8);\n\tfor (var i = 0; i < n; i++)\n\t\tb[a[i]]++;\n\n\tvar ans = [];\n\tif (b[4] > 0) {\n\t\tb[1] -= b[4];\n\t\tb[2] -= b[4];\n\t\tif (b[1] < 0 || b[2] < 0) return -1;\n\t\twhile (b[4]--) ans.push('1 2 4');\n\t}\n\tif (b[2] > 0) {\n\t\tb[1] -= b[2];\n\t\tb[6] -= b[2];\n\t\tif (b[1] < 0 || b[2] < 0) return -1;\n\t\twhile (b[2]--) ans.push('1 2 6');\n\t}\n\n\tif (b[1] !== b[3] || b[3] !== b[6]) return -1;\n\twhile (b[1]--) ans.push('1 3 6');\n\tif (ans.length !== n / 3) return -1;\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(n, a) {\n\tvar b = new Int32Array(8);\n\tfor (var i = 0; i < n; i++)\n\t\tb[a[i]]++;\n\n\tvar ans = [];\n\tb[1] -= b[4];\n\tb[2] -= b[4];\n\tif (b[1] < 0 || b[2] < 0) return -1;\n\twhile (b[4]--) ans.push('1 2 4');\n\n\tb[1] -= b[2];\n\tb[6] -= b[2];\n\tif (b[1] < 0 || b[2] < 0) return -1;\n\twhile (b[2]--) ans.push('1 2 6');\n\n\tif (b[1] !== b[3] || b[3] !== b[6]) return -1;\n\tb[1] = b[3] = b[6] = 0;\n\twhile (b[1]--) ans.push('1 3 6');\n\n\tif (ans.length !== n / 3) return -1;\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a) {\n\tvar ans=[], c = new Int32Array(8);\n\n\tfor (var i = 0; i < n; i++)\n\t\tc[a[i]]++;\n\n\tif (!(c[1] === n / 3 && c[2] + c[3] === n / 3 && c[4] + c[6] === n / 3)) return -1;\n\n\tfor (i = 1; i <= n / 3; i++)\n\t\tif (i <= c[4]) ans.push('1 2 4');\n\t\telse if (i <= c[2]) ans.push('1 2 6');\n\t\telse ans.push('1 3 6');\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));\n"}, {"source_code": "print(function(n, a) {\n\tvar ans = [], c = new Int32Array(8);\n\n\tfor (var i = 0; i < n; i++)\n\t\tc[a[i]]++;\n\n\tif (!(c[1] === n / 3 && c[2] + c[3] === n / 3 && c[4] + c[6] === n / 3)) return -1;\n\tif (c[2] === 0 || c[6] === 0) return -1;\n\n\tfor (i = 1; i <= n / 3; i++)\n\t\tif (i <= c[4]) ans.push('1 2 4');\n\t\telse if (i <= c[2]) ans.push('1 2 6');\n\t\telse ans.push('1 3 6');\n\n\treturn ans.join('\\n');\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c2>0 && c4>0){\n print('1 2 4');\n c1--; c2--; c4--;\n }\n if(c1>0 && c2>0 && c6>0){\n print('1 2 6');\n c1--; c2--; c6--;\n }\n if(c1>0 && c3>0 && c6>0){\n print('1 3 6');\n c1--; c3--; c6--;\n }\n}\nif(c1>0 || c2>0 || c3>0 || c4>0 || c6>0){\nprint('-1')\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c4>0){\n print('1 2 4');\n c2--; c4--;\n }\n if(c2>0 && c6>0){\n print('1 2 6');\n c2--; c6--;\n }\n if(c3>0 && c6>0){\n print('1 3 6');\n c3--; c6--;\n }\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c2>0 && c4>0){\n print('1 2 4');\n c1--; c2--; c4--;\n }\n if(c1>0 && c2>0 && c6>0){\n print('1 2 6');\n c1--; c2--; c6--;\n }\n if(c1>0 && c3>0 && c6>0){\n print('1 3 6');\n c1--; c3--; c6--;\n }\n}\nif(c1>0 || c2>0 || c3>0 || c4>0 || c6>0){\nprint('-1')\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c4>0){\n print('1 2 4');\n c2--; c4--;\n }\n if(c2>0 && c6>0){\n print('1 2 6');\n c2--; c6--;\n }\n if(c3>0 && c6>0){\n print('1 3 6');\n c3--; c6--;\n }\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c2>0 && c4>0 && p1>0){\n print('1 2 4');\n c1--; c2--; c4--;p1--;\n }\n if(c1>0 && c2>0 && c6>0 && p2>0){\n print('1 2 6');\n c1--; c2--; c6--;p2--;\n }\n if(c1>0 && c3>0 && c6>0 && p3>0){\n print('1 3 6');\n c1--; c3--; c6--;p3--;\n }\n}\nif(c1>0 || c2>0 || c3>0 || c4>0 || c6>0){\nprint('-1')\n}"}, {"source_code": "print('1 2 4')\nprint('1 3 6')"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c4>0){\n print('1 2 4');\n c2--; c4--;\n }\n if(c2>0 && c6>0){\n print('1 2 6');\n c2--; c6--;\n }\n if(c3>0 && c6>0){\n print('1 3 6');\n c3--; c6--;\n }\n}\nif(c1>0 || c2>0 || c3>0 || c4>0 || c6>0){\nprint('-1')\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c4>0){\n print('1 2 4');\n c2--; c4--;\n }\n if(c2>0 && c6>0){\n print('1 2 6');\n c2--; c6--;\n }\n if(c3>0 && c6>0){\n print('1 3 6');\n c3--; c6--;\n }\n}"}, {"source_code": "var am = readline()\nvar nums = readline().split(' ')\nvar c1 = c2 = c3 = c4 = c6 = 0\nfor(var i=0; i0 && c4>0){\n print('1 2 4');\n c2--; c4--;\n }\n if(c2>0 && c6>0){\n print('1 2 6');\n c2--; c6--;\n }\n if(c3>0 && c6>0){\n print('1 3 6');\n c3--; c6--;\n }\n}"}], "src_uid": "513234db1bab98c2c2ed6c7030c1ac72"} {"source_code": "var N = parseInt(readline());\nvar toInt = (n, i, a) => a[i] = parseInt(n);\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar cross = (v0, v1) => {\n v0[2] = v0[2] || 0;\n v1[2] = v1[2] || 0;\n return [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n ];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar sideDot = (p0, p1, p2, q) => {\n var c0 = cross(vec(p0, p1), vec(p0, q));\n var c1 = cross(vec(p0, p1), vec(p0, p2));\n return dot(c0, c1);\n};\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nvar ab, ac, bc;\nvar len = (p0, p1) => {\n var v = vec(p0, p1);\n return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];\n};\nwhile (temp = star.pop()) {\n ab = sideDot(A, B, C, temp);\n ac = sideDot(A, C, B, temp);\n bc = sideDot(B, C, A, temp);\n if (ab > 0 && ac > 0 && bc > 0) { // inTrig\n C = temp;\n }\n if (ab === 0) A = len(A, B) > len(temp, B) ? temp : A;\n else if (ac === 0) A = len(A, C) > len(temp, C) ? temp : A;\n else if (bc === 0) B = len(B, C) > len(temp, C) ? temp : B;\n}\nprint(A[3], B[3], C[3]);\n", "positive_code": [{"source_code": "var N = parseInt(readline());\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar len = (p0, p1) => {\n var v = vec(p0, p1);\n return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar cross = (v0, v1) => [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n];\nvar sideDot = (p0, p1, q0, q1) => {\n var cr = (q) => cross(vec(p0, p1), vec(p0, q));\n return dot(cr(q0), cr(q1));\n};\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nvar ab, ac, bc;\nwhile (temp = star.pop()) {\n ab = sideDot(A, B, C, temp);\n ac = sideDot(A, C, B, temp);\n bc = sideDot(B, C, A, temp);\n if (ab > 0 && ac > 0 && bc > 0) { // inTrig\n C = temp;\n }\n if (ab === 0) A = len(A, B) > len(temp, B) ? temp : A;\n else if (ac === 0) A = len(A, C) > len(temp, C) ? temp : A;\n else if (bc === 0) B = len(B, C) > len(temp, C) ? temp : B;\n}\nprint(A[3], B[3], C[3]);\n"}], "negative_code": [{"source_code": "var N = parseInt(readline());\nvar toInt = (n, i, a) => a[i] = parseInt(n);\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar cross = (v0, v1) => {\n v0[2] = v0[2] || 0;\n v1[2] = v1[2] || 0;\n return [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n ];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar sameSide = (p0, p1, p2, q) => {\n var c0 = cross(vec(p0, p1), vec(p0, q));\n var c1 = cross(vec(p0, p1), vec(p0, p2));\n return dot(c0, c1) > 0;\n};\nvar inTrig = (p0, p1, p2, q) =>\n sameSide(p0, p1, p2, q) && sameSide(p0, p2, p1, q) && sameSide(p1, p2, p0, q);\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nwhile (temp = star.pop()) {\n if (inTrig(A, B, C, temp)) {\n C = temp;\n }\n}\nprint(A[3], B[3], C[3]);\n"}, {"source_code": "var N = parseInt(readline());\nvar toInt = (n, i, a) => a[i] = parseInt(n);\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar cross = (v0, v1) => {\n v0[2] = v0[2] || 0;\n v1[2] = v1[2] || 0;\n return [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n ];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar sideDot = (p0, p1, p2, q) => {\n var c0 = cross(vec(p0, p1), vec(p0, q));\n var c1 = cross(vec(p0, p1), vec(p0, p2));\n return dot(c0, c1);\n};\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nvar ab, ac, bc;\nvar len = (p0, p1) => {\n var v = vec(p0, p1);\n return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];\n};\nwhile (temp = star.pop()) {\n ab = sideDot(A, B, C, temp);\n ac = sideDot(A, C, B, temp);\n bc = sideDot(B, C, A, temp);\n if (ab > 0 && ac > 0 && bc > 0) { // inTrig\n C = temp;\n }\n if (ab === 0 || ac === 0) A = len(A, B) > len(temp, B) ? temp : A;\n else if (bc === 0) B = len(B, C) > len(temp, C) ? temp : B;\n}\nprint(A[3], B[3], C[3]);\n"}, {"source_code": "var N = parseInt(readline());\nvar toInt = (n, i, a) => a[i] = parseInt(n);\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar cross = (v0, v1) => {\n v0[2] = v0[2] || 0;\n v1[2] = v1[2] || 0;\n return [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n ];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar sideDot = (p0, p1, p2, q) => {\n var c0 = cross(vec(p0, p1), vec(p0, q));\n var c1 = cross(vec(p0, p1), vec(p0, p2));\n return dot(c0, c1);\n};\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nvar ab, ac, bc;\nvar len = (p0, p1) => {\n var v = vec(p0, p1);\n return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];\n};\nwhile (temp = star.pop()) {\n ab = sideDot(A, B, C, temp);\n ac = sideDot(A, C, B, temp);\n bc = sideDot(B, C, A, temp);\n // print(temp, ab, ac, bc);\n if (ab > 0 && ac > 0 && bc > 0) { // inTrig\n C = temp;\n }\n if (ab === 0 || ac === 0) A = len(A, B) > len(temp, B) ? temp : A;\n else if (bc === 0) B = len(A, B) > len(A, temp) ? temp : B;\n}\nprint(A[3], B[3], C[3]);\n"}, {"source_code": "var N = parseInt(readline());\nvar toInt = (n, i, a) => a[i] = parseInt(n);\nvar star = [], temp;\nfor (var i = 1; i <= N; ++i) {\n temp = readline().split(' ');\n star.push([parseInt(temp[0]), parseInt(temp[1]), 0, i]);\n}\nvar rand = () => Math.floor(Math.random() * N);\nvar coLine = (p0, p1, q) =>\n (p1[0] - p0[0]) * (q[1] - p0[1]) === (p1[1] - p0[1]) * (q[0] - p0[0]);\nvar cross = (v0, v1) => {\n v0[2] = v0[2] || 0;\n v1[2] = v1[2] || 0;\n return [\n v0[1] * v1[2] - v0[2] * v1[1],\n v0[2] * v1[0] - v0[0] * v1[2],\n v0[0] * v1[1] - v0[1] * v1[0]\n ];\n};\nvar dot = (v0, v1) => v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];\nvar vec = (p0, p1) => [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];\nvar sideDot = (p0, p1, p2, q) => {\n var c0 = cross(vec(p0, p1), vec(p0, q));\n var c1 = cross(vec(p0, p1), vec(p0, p2));\n return dot(c0, c1);\n};\nvar A, B, C;\nA = star.pop();\nB = star.pop();\nfor (var i = 0; i < N-2; ++i) {\n if (!coLine(A, B, star[i])) {\n C = star[i];\n temp = star.pop();\n if (i !== N-3) {\n star[i] = temp;\n }\n break;\n }\n}\nvar ab, ac, bc;\nvar len = (p0, p1) => {\n var v = vec(p0, p1);\n return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];\n};\nwhile (temp = star.pop()) {\n ab = sideDot(A, B, C, temp);\n ac = sideDot(A, C, B, temp);\n bc = sideDot(B, C, A, temp);\n print(temp, ab, ac, bc);\n if (ab > 0 && ac > 0 && bc > 0) { // inTrig\n C = temp;\n }\n if (ab === 0 || ac === 0) A = len(A, B) > len(temp, B) ? temp : A;\n else if (bc === 0) B = len(A, B) > len(A, temp) ? temp : B;\n}\nprint(A[3], B[3], C[3]);\n"}], "src_uid": "0d3ac2472990aba36abee156069b1088"} {"source_code": "//constrains\n// * 1 <= t <= ^5\n// * -10^9 <= direction < 10^9\n\n//Input\nvar firstLine = \"5 0 0 1 1\"; var direction = \"SESNW\"; // 4\n// var firstLine = \"10 5 3 3 6\"; var direction = \"NENSWESNEE\"; // -1\n// var firstLine = \"19 172106364 468680119 172106365 468680119\"; var direction = \"SSEEESSSESESWSEESSS\";\n// 13\n// var firstLine = \"19 172106364 468680119 172106363 468680119\"; var direction = \"SSEEESSSESESWSEESSS\";\n// var firstLine = \"1 0 0 0 -1\"; var direction = \"S\"; // 4\n\nvar firstLine = readline(); var direction = readline();\n\nretorno = eval(firstLine, direction);\n\n//Solution\nfunction eval(firstLine, direction){\n var tmp = firstLine.split(\" \").map(function(x){ return parseInt(x)});\n var t = tmp[0];\n var start = {\n x: tmp[1],\n y: tmp[2] };\n var end = {\n x: tmp[3],\n y: tmp[4] };\n write( timeToReach(t, start, end, direction) );\n //console.log(timeToReach(t, start, end, direction));\n};\n\nfunction timeToReach(t, s, e, direction){\n var ap = {\n x: s.x,\n y: s.y};\n\n // console.log(\"s.x: \" + s.x + \" s.y: \" + s.y + \" e.x: \" + e.x + \" e.y: \" + e.y);\n // console.log(\"\\nap.x: \" + ap.x + \" ap.y: \" + ap.y);\n // console.log(\"\\nDx: \" + Math.abs(e.x - s.x) + \" Dy: \" + Math.abs(e.y - s.y) + \"\\n\\n\" );\n\n var totalCount = -1;\n for(var i = 0 ; i < t ; i++){\n //console.log(direction[i]);\n switch(direction[i]){\n case \"N\": // north direction\n if( Math.abs(e.y - (ap.y + 1)) < Math.abs(e.y - ap.y) ){\n ap.y ++;\n };\n break;\n\n case \"S\": //south direction\n if( Math.abs(e.y - (ap.y - 1)) < Math.abs(e.y - ap.y) ){\n ap.y --;\n };\n break;\n\n case \"E\": // east direction\n if( Math.abs(e.x - (ap.x + 1)) < Math.abs(e.x - ap.x) ){\n ap.x++;\n };\n break;\n\n case \"W\": //west direction\n //console.log(\"entr\u00f3\");\n if( Math.abs(e.x - (ap.x - 1)) < Math.abs(e.x - ap.x) ){\n //console.log(\"entr\u00f3 al if\");\n ap.x--;\n };\n break;\n };\n //console.log(i + \" ap.x: \" + ap.x + \" ap.y: \" + ap.y);\n // console.log(\"(e.x == ap.x) && (e.y == ap.y): \" + ( (e.x == ap.x) && (e.y == ap.y) ) );\n if( (e.x == ap.x) && (e.y == ap.y) ){\n totalCount = i + 1;\n break;\n };\n };\n return totalCount;\n};\n\n\n", "positive_code": [{"source_code": "print(function(t, sx, sy, ex, ey) {\n\n\tvar x = ex - sx,\n\t\ty = ey - sy,\n\t\td = readline().split('');\n\n\tfor (var i = 0; i < t; i++) {\n\t\tif (x > 0 && d[i] === 'E') x--;\n\t\tif (y > 0 && d[i] === 'N') y--;\n\t\tif (x < 0 && d[i] === 'W') x++;\n\t\tif (y < 0 && d[i] === 'S') y++;\n\t\tif (x === 0 && y === 0) return i+1;\n\t}\n\n\treturn -1;\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function main()\n{\n var tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n var t = tmp[0],\n sx = tmp[1],\n sy = tmp[2],\n ex = tmp[3],\n ey = tmp[4];\n tmp = readline();\n var ans = 0;\n if ( sx > ex )\n {\n var i;\n var cnt = sx - ex;\n for ( i = 0; i < tmp.length && cnt > 0; i++ )\n {\n if ( tmp[i] == \"W\" )\n {\n cnt--;\n }\n }\n if ( cnt > 0 )\n {\n print(-1);\n return;\n }\n if ( ans < i )\n ans = i;\n }\n else if ( sx < ex )\n {\n var i;\n var cnt = ex - sx;\n for ( i = 0; i < tmp.length && cnt > 0; i++ )\n {\n if ( tmp[i] == \"E\" )\n {\n cnt--;\n }\n }\n if ( cnt > 0 )\n {\n print(-1);\n return;\n }\n if ( ans < i )\n ans = i;\n }\n if ( sy > ey )\n {\n var i;\n var cnt = sy - ey;\n for ( i = 0; i < tmp.length && cnt > 0; i++ )\n {\n if ( tmp[i] == \"S\" )\n {\n cnt--;\n }\n }\n if ( cnt > 0 )\n {\n print(-1);\n return;\n }\n if ( ans < i )\n ans = i;\n }\n else if ( sy < ey )\n {\n var i;\n var cnt = ey - sy;\n for ( i = 0; i < tmp.length && cnt > 0; i++ )\n {\n if ( tmp[i] == \"N\" )\n {\n cnt--;\n }\n }\n if ( cnt > 0 )\n {\n print(-1);\n return;\n }\n if ( ans < i )\n ans = i;\n }\n print(ans);\n}\n\nmain();\n"}, {"source_code": "function main(){\n var tmp = readline().split(\" \").map(function (x) { return parseInt(x); });\n var t = tmp[0],\n sx = tmp[1],\n sy = tmp[2],\n ex = tmp[3],\n ey = tmp[4];\n tmp = readline();\n var ans = 0;\n if ( sx > ex ){\n var i;\n var cnt = sx - ex;\n for ( i = 0; i < tmp.length && cnt > 0; i++ ){\n if ( tmp[i] == \"W\" ){\n cnt--;\n }\n }\n if ( cnt > 0 ){\n print(-1);\n return;\n }\n if ( ans < i ){\n ans = i;\n }\n }\n else if ( sx < ex ){\n var i;\n var cnt = ex - sx;\n for ( i = 0; i < tmp.length && cnt > 0; i++ ){\n if ( tmp[i] == \"E\" ){\n cnt--;\n }\n }\n if ( cnt > 0 ){\n print(-1);\n return;\n }\n if ( ans < i ){\n ans = i;\n }\n }\n if ( sy > ey ){\n var i;\n var cnt = sy - ey;\n for ( i = 0; i < tmp.length && cnt > 0; i++ ){\n if ( tmp[i] == \"S\" ){\n cnt--;\n }\n }\n if ( cnt > 0 ){\n print(-1);\n return;\n }\n if ( ans < i ){\n ans = i;\n }\n }\n else if ( sy < ey ){\n var i;\n var cnt = ey - sy;\n for ( i = 0; i < tmp.length && cnt > 0; i++ ){\n if ( tmp[i] == \"N\" ){\n cnt--;\n }\n }\n if ( cnt > 0 ){\n print(-1);\n return;\n }\n if ( ans < i ){\n ans = i;\n }\n }\n print(ans);\n}\n\nmain();\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n const [len, sx, sy, ex, ey] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const str = readLine();\n const [diffX, diffY] = [ex - sx, ey - sy];\n let [x, countX, y, countY] = [\"\", Math.abs(diffX), \"\", Math.abs(diffY)];\n\n if (diffX > 0) x = \"E\";\n else x = \"W\";\n if (diffY > 0) y = \"N\";\n else y = \"S\";\n\n let map = {};\n for (let i = 0; i < len; i++) {\n const char = str[i];\n\n map[char] = (map[char] || 0) + 1;\n\n if (diffX === 0 && map[y] >= countY) {\n console.log(i + 1);\n return;\n } else if (diffY === 0 && map[x] >= countX) {\n console.log(i + 1);\n return;\n } else if (map[x] >= countX && map[y] >= countY) {\n console.log(i + 1);\n return;\n }\n }\n\n console.log(-1);\n}\n"}], "negative_code": [], "src_uid": "aa31a2a1ad1575aee051ddee8642c53a"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const items = readLine()\n .split(\" \")\n .reduce((obj, n, index) => {\n obj[n] = index;\n return obj;\n }, {});\n const queryLen = +readLine();\n const queries = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [person1, person2] = [0, 0];\n\n for (query of queries) {\n const position = items[query] + 1;\n if (position > 0) {\n person1 += position;\n person2 += len - position + 1;\n }\n }\n console.log(`${person1} ${person2}`);\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nfunction search(element) {\n let begin = 0;\n let end = 0;\n let isBeginFound = false;\n let isEndFound = false;\n for (let i = 0; i < list.length; i++) {\n if (isBeginFound && isEndFound)\n break;\n if (list[i] !== element && !isBeginFound) {\n begin++;\n } else if (list[i] === element && !isBeginFound) {\n begin++;\n isBeginFound = true;\n }\n if (list[list.length - i - 1] !== element && !isEndFound) {\n end++;\n } else if (list[list.length - i - 1] === element && !isEndFound) {\n end++;\n isEndFound = true;\n }\n }\n return {begin, end};\n}\n\nlet listLength;\nlet list;\nlet queryLength;\nlet query;\nlet queryFlag;\n\nfunction solve() {\n let totalBeginChecks = 0;\n let totalEndChecks = 0;\n for (let i = 0; i < list.length; i++) {\n if (queryFlag[list[i]] !== 0) {\n totalBeginChecks += ((i + 1) * queryFlag[list[i]]);\n totalEndChecks += ((list.length - i) * queryFlag[list[i]]);\n }\n }\n return [totalBeginChecks, totalEndChecks]\n\n}\n\n\nrl.on('line', (line) => {\n if (!listLength) {\n listLength = parseInt(line);\n return;\n }\n if (!list) {\n list = line.split(' ').map(Number);\n return;\n }\n if (!queryLength) {\n queryLength = parseInt(line);\n return;\n }\n if (!query) {\n query = line.split(' ').map(Number);\n }\n queryFlag = new Array(1000000).fill(0);\n for (let i = 0; i < query.length; i++) {\n queryFlag[query[i]] += 1;\n }\n console.log(solve().join(' '));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nfunction search(element) {\n let begin = 0;\n let end = 0;\n let isBeginFound = false;\n let isEndFound = false;\n for (let i = 0; i < list.length; i++) {\n if (isBeginFound && isEndFound)\n break;\n if (list[i] !== element && !isBeginFound) {\n begin++;\n } else if (list[i] === element && !isBeginFound) {\n begin++;\n isBeginFound = true;\n }\n if (list[list.length - i - 1] !== element && !isEndFound) {\n end++;\n } else if (list[list.length - i - 1] === element && !isEndFound) {\n end++;\n isEndFound = true;\n }\n }\n return {begin, end};\n}\n\nlet listLength;\nlet list;\nlet queryLength;\nlet query;\nlet queryFlag;\n\nfunction solve() {\n let totalBeginChecks = 0;\n let totalEndChecks = 0;\n for (let i = 0; i < list.length; i++) {\n if (queryFlag[list[i]] !== 0) {\n totalBeginChecks += ((i + 1) * queryFlag[list[i]]);\n totalEndChecks += ((list.length - i) * queryFlag[list[i]]);\n }\n }\n return [totalBeginChecks, totalEndChecks]\n\n}\n\n\nrl.on('line', (line) => {\n if (!listLength) {\n listLength = parseInt(line);\n return;\n }\n if (!list) {\n list = line.split(' ').map(Number);\n return;\n }\n if (!queryLength) {\n queryLength = parseInt(line);\n return;\n }\n if (!query) {\n query = line.split(' ').map(Number);\n }\n queryFlag = new Array(100001).fill(0);\n for (let i = 0; i < query.length; i++) {\n queryFlag[query[i]] += 1;\n }\n console.log(solve().join(' '));\n});\n"}, {"source_code": "//Effective Approach\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let dex = {};\n for(let i = 1; i <= 100000; i++) {\n \tdex[i] = -1;\n }\n\n let n = lines[1].split(' ').map(c => +c);\n\n for(let i = 0; i < n.length; i++) {\n \tdex[n[i]] = i;\n }\n\n let c = lines[3].split(' ').map(r => +r);\n\n let tota = 0, totb = 0;\n for(let i = 0; i < c.length; i++) {\n \tif(dex[c[i]] != -1) {\n \t\ttota += dex[c[i]] + 1;\n \t\ttotb += n.length - dex[c[i]];\n \t}\n }\n\n process.stdout.write(tota + ' ' + totb);\n\n return;\n});"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction multiply(a, b) {\n\ta = a.toString(10).split('').reverse();\n\tb = b.toString(10).split('').reverse();\n\n\tif (a.length < b.length) {\n\t\t[a, b] = [b, a];\n\t}\n\n\tlet res = Array(a.length + b.length).fill(0);\n\tfor (let i = 0, lb = b.length; i < lb; ++i) {\n\t\tlet carry = 0;\n\t\tlet scarry = 0;\n\t\tfor (let j = 0, la = a.length; j < la; ++j) {\n\t\t\tlet m = b[i] * a[j];\n\t\t\tm += carry;\n\n\t\t\tif (m > 9) {\n\t\t\t\tlet [c, d] = m.toString(10).split('');\n\t\t\t\tres[i + j] += (scarry >> 0) + (d >> 0);\n\t\t\t\tcarry = c >> 0;\n\t\t\t} else {\n\t\t\t\tres[i + j] += (scarry >> 0) + m;\n\t\t\t\tcarry = 0;\n\t\t\t}\n\n\t\t\tif (res[i + j] > 9) {\n\t\t\t\tlet [c, d] = res[i + j].toString(10).split('');\n\t\t\t\tres[i + j] = d >> 0;\n\t\t\t\tscarry = c;\n\t\t\t} else {\n\t\t\t\tscarry = 0;\n\t\t\t}\n\t\t}\n\t\tif (carry > 0) res[a.length + i] = carry;\n\t\tif (scarry > 0) res[a.length + i] = scarry;\n\t}\n\n\tres.reverse();\n\tlet mulVal = '';\n\tlet flag = false;\n\tres.forEach(d => {\n\t\tif (!flag && d !== 0) flag = true;\n\t\tif (flag) mulVal += d;\n\t});\n\treturn mulVal;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet nums = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet m = readLine() >> 0;\n\tlet b = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet query = {};\n\tb.forEach(x => (query[x] = (query[x] || 0) + 1));\n\n\tlet i = 0;\n\tlet l = 0,\n\t\tr = 0;\n\twhile (i < n) {\n\t\tif (query[nums[i]] !== undefined && query[nums[i]] > 0) {\n\t\t\tl += (i + 1) * query[nums[i]];\n\t\t\tr += (n - i) * query[nums[i]];\n\t\t}\n\t\ti++;\n\t}\n\tconsole.log(l, r);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n// function main() {\n// let n = parseInt(readLine());\n// let mainArray = readLine().split(' ').map(Number);\n// let m = parseInt(readLine());\n// let qureyArray = readLine().split(' ').map(Number);\n// let Vasyacount = 0;\n// for (let i = 0; i < qureyArray.length; i++) {\n// for (let j = 0; j < mainArray.length; j++) {\n// Vasyacount++;\n// if (qureyArray[i] === mainArray[j]) {\n// break;\n// }\n// }\n// }\n\n// let Petyas_count = 0;\n// for (let i = 0; i < qureyArray.length; i++) {\n// for (let j = mainArray.length - 1; j >= 0; j--) {\n// Petyas_count++;\n// if (qureyArray[i] === mainArray[j]) {\n// break;\n// }\n// }\n// }\n\n// console.log(Vasyacount, Petyas_count);\n// }\n\nfunction main() {\n let n = parseInt(readLine());\n let mainArray = readLine().split(' ').map(Number);\n let m = parseInt(readLine());\n let qureyArray = readLine().split(' ').map(Number);\n\n let indexArray = new Array(n);\n for (let i = 0; i < n; i++) {\n let test = mainArray[i];\n indexArray[test] = i;\n }\n let Vasya = 0;\n // console.log(indexArray);\n // console.log(indexArray[qureyArray[2]] + 1);\n\n for (let i = 0; i < m; i++) {\n Vasya = Vasya + indexArray[qureyArray[i]] + 1;\n }\n let Petya = 0;\n for (let i = 0; i < m; i++) {\n Petya = Petya + (n - indexArray[qureyArray[i]]);\n }\n console.log(Vasya, Petya);\n}\n"}, {"source_code": "var arrayLength = readline();\nvar input = {};\nreadline().split(\" \").map((entry, index) => input[entry] = index);\n \nvar searchLength = readline();\nvar searchFor = readline().split(\" \");\n \ncounterA = 0;\ncounterB = 0;\nvar index; \nfor (var j = 0; j < searchLength; j++) {\n index = input[searchFor[j]];\n counterA += index + 1;\n counterB += arrayLength - index;\n \n}\nprint(counterA + \" \" + counterB);"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nfunction search(element) {\n let begin = 0;\n let end = 0;\n let isBeginFound = false;\n let isEndFound = false;\n for (let i = 0; i < list.length; i++) {\n if (isBeginFound && isEndFound)\n break;\n if (list[i] !== element && !isBeginFound) {\n begin++;\n } else if (list[i] === element && !isBeginFound) {\n begin++;\n isBeginFound = true;\n }\n if (list[list.length - i - 1] !== element && !isEndFound) {\n end++;\n } else if (list[list.length - i - 1] === element && !isEndFound) {\n end++;\n isEndFound = true;\n }\n }\n return {begin, end};\n}\n\nlet listLength;\nlet list;\nlet queryLength;\nlet query;\nlet queryFlag;\n\nfunction solve() {\n let totalBeginChecks = 0;\n let totalEndChecks = 0;\n for (let i = 0; i < list.length; i++) {\n if (queryFlag[list[i]]) {\n totalBeginChecks += i + 1;\n totalEndChecks += list.length - i;\n }\n }\n return [totalBeginChecks, totalEndChecks]\n\n}\n\n\nrl.on('line', (line) => {\n if (!listLength) {\n listLength = parseInt(line);\n return;\n }\n if (!list) {\n list = line.split(' ').map(Number);\n return;\n }\n if (!queryLength) {\n queryLength = parseInt(line);\n return;\n }\n if (!query) {\n query = line.split(' ').map(Number);\n }\n queryFlag = new Array(100000).fill(false);\n for (let i = 0; i < query.length; i++) {\n queryFlag[query[i]] = true;\n }\n console.log(solve().join(' '));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nfunction search(element) {\n let begin = 0;\n let end = 0;\n let isBeginFound = false;\n let isEndFound = false;\n for (let i = 0; i < list.length; i++) {\n if (isBeginFound && isEndFound)\n break;\n if (list[i] !== element && !isBeginFound) {\n begin++;\n } else if (list[i] === element && !isBeginFound) {\n begin++;\n isBeginFound = true;\n }\n if (list[list.length - i - 1] !== element && !isEndFound) {\n end++;\n } else if (list[list.length - i - 1] === element && !isEndFound) {\n end++;\n isEndFound = true;\n }\n }\n return {begin, end};\n}\n\nlet listLength;\nlet list;\nlet queryLength;\nlet query;\nlet queryFlag;\n\nfunction solve() {\n let totalBeginChecks = 0;\n let totalEndChecks = 0;\n for (let i = 0; i < list.length; i++) {\n if (queryFlag[list[i]] !== 0) {\n totalBeginChecks += ((i + 1) * queryFlag[list[i]]);\n totalEndChecks += ((list.length - i) * queryFlag[list[i]]);\n }\n }\n return [totalBeginChecks, totalEndChecks]\n\n}\n\n\nrl.on('line', (line) => {\n if (!listLength) {\n listLength = parseInt(line);\n return;\n }\n if (!list) {\n list = line.split(' ').map(Number);\n return;\n }\n if (!queryLength) {\n queryLength = parseInt(line);\n return;\n }\n if (!query) {\n query = line.split(' ').map(Number);\n }\n queryFlag = new Array(100000).fill(0);\n for (let i = 0; i < query.length; i++) {\n queryFlag[query[i]] += 1;\n }\n console.log(solve().join(' '));\n});\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction multiply(a, b) {\n\ta = a.toString(10).split('').reverse();\n\tb = b.toString(10).split('').reverse();\n\n\tif (a.length < b.length) {\n\t\t[a, b] = [b, a];\n\t}\n\n\tlet res = Array(a.length + b.length).fill(0);\n\tfor (let i = 0, lb = b.length; i < lb; ++i) {\n\t\tlet carry = 0;\n\t\tlet scarry = 0;\n\t\tfor (let j = 0, la = a.length; j < la; ++j) {\n\t\t\tlet m = b[i] * a[j];\n\t\t\tm += carry;\n\n\t\t\tif (m > 9) {\n\t\t\t\tlet [c, d] = m.toString(10).split('');\n\t\t\t\tres[i + j] += (scarry >> 0) + (d >> 0);\n\t\t\t\tcarry = c >> 0;\n\t\t\t} else {\n\t\t\t\tres[i + j] += (scarry >> 0) + m;\n\t\t\t\tcarry = 0;\n\t\t\t}\n\n\t\t\tif (res[i + j] > 9) {\n\t\t\t\tlet [c, d] = res[i + j].toString(10).split('');\n\t\t\t\tres[i + j] = d >> 0;\n\t\t\t\tscarry = c;\n\t\t\t} else {\n\t\t\t\tscarry = 0;\n\t\t\t}\n\t\t}\n\t\tif (carry > 0) res[a.length + i] = carry;\n\t\tif (scarry > 0) res[a.length + i] = scarry;\n\t}\n\n\tres.reverse();\n\tlet mulVal = '';\n\tlet flag = false;\n\tres.forEach(d => {\n\t\tif (!flag && d !== 0) flag = true;\n\t\tif (flag) mulVal += d;\n\t});\n\treturn mulVal;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet nums = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet m = readLine() >> 0;\n\tlet b = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet query = {};\n\tb.forEach(x => (query[x] = (query[x] || 0) + 1));\n\n\tlet i = 0;\n\tlet l = 0,\n\t\tr = 0;\n\twhile (i < n) {\n\t\tif (query[nums[i]] !== undefined && query[nums[i]] > 0) {\n\t\t\tl += i + 1;\n\t\t\tr += n - i;\n\t\t}\n\t\ti++;\n\t}\n\tconsole.log(l, r);\n}\n"}], "src_uid": "b7aef95015e326307521fd59d4fccb64"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, arr, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, str) {\n const liked = []\n const unliked = []\n for (let i = 0; i < arr.length; i++) {\n if (str[i] === '1') {\n liked.push([i, arr[i]])\n } else {\n unliked.push([i, arr[i]])\n }\n }\n liked.sort((a, b) => a[1] - b[1])\n unliked.sort((a, b) => a[1] - b[1])\n // console.log(liked, unliked)\n const ans = Array(n)\n for (let i = 0; i < arr.length; i++) {\n if (i < unliked.length) {\n ans[unliked[i][0]] = i + 1\n } else {\n ans[liked[i - unliked.length][0]] = i + 1\n }\n }\n return ans.join(' ')\n}\n", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const p = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const res = new Array(n);\r\n let ptr = n - 1;\r\n const order = new Array(n);\r\n for(let i = 0; i < n; i++) {\r\n order[p[i] - 1] = i + 1;\r\n }\r\n for(let i = n - 1; i >= 0; i--) {\r\n if (s.charAt(order[i] - 1) === '1') {\r\n res[ptr] = order[i];\r\n ptr--;\r\n }\r\n }\r\n\r\n for(let i = n - 1; i >= 0; i--) {\r\n if (s.charAt(order[i] - 1) === '0') {\r\n res[ptr] = order[i];\r\n ptr--;\r\n }\r\n }\r\n\r\n for(let i = 0; i < n; i++) {\r\n order[res[i] - 1] = i + 1;\r\n }\r\n\r\n console.log(order.join(' '));\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const solve = (arr,str)=>{\r\n let zero = [],one = [];\r\n for(let i=0;ia-b);\r\n one.sort((a,b)=>a-b);\r\n let cnt1 = 1;\r\n let cnt2 = zero.length+1;\r\n let obj = {},res = \"\";\r\n for(let i=0;iparseInt(cur)));\r\n let str = readline().trim();\r\n console.log(solve(arr,str));\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst p = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (const c of s) cnt += c == '0';\r\n\r\n\t\tconst ans = [];\r\n\t\tconst used = new Set();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (s[i] == '0' && p[i] <= cnt || s[i] == '1' && p[i] > cnt) {\r\n\t\t\t\tans[i] = p[i];\r\n\t\t\t\tused.add(p[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet l = 1, r = n;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (!ans[i]) {\r\n\t\t\t\tif (s[i] == '0') {\r\n\t\t\t\t\twhile (used.has(l)) l++;\r\n\t\t\t\t\tans[i] = l;\r\n\t\t\t\t\tl++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\twhile(used.has(r)) r--;\r\n\t\t\t\t\tans[i] = r;\r\n\t\t\t\t\tr--;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst p = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (const c of s) cnt += c == '1';\r\n\r\n\t\tconst ans = [];\r\n\t\tconst used = new Set();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (s[i] == '0' && p[i] <= cnt || s[i] == '1' && p[i] > cnt) {\r\n\t\t\t\tans[i] = p[i];\r\n\t\t\t\tused.add(p[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet l = 1, r = n;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (!ans[i]) {\r\n\t\t\t\tif (s[i] == '0') {\r\n\t\t\t\t\twhile (used.has(l)) l++;\r\n\t\t\t\t\tans[i] = l;\r\n\t\t\t\t\tl++;\r\n\t\t\t\t} else {\r\n\t\t\t\t\twhile(used.has(r)) r--;\r\n\t\t\t\t\tans[i] = r;\r\n\t\t\t\t\tr--;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const p = (await getLine()).split(' ').map(num => parseInt(num));\r\n const s = await getLine();\r\n const res = new Array(n);\r\n let ptr = n - 1;\r\n for(let i = n - 1; i >= 0; i--) {\r\n if (s.charAt(p[i] - 1) === '1') {\r\n res[ptr] = p[i];\r\n ptr--;\r\n }\r\n }\r\n\r\n for(let i = n - 1; i >= 0; i--) {\r\n if (s.charAt(p[i] - 1) === '0') {\r\n res[ptr] = p[i];\r\n ptr--;\r\n }\r\n }\r\n\r\n console.log(res.join(' '));\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "0903a40d72c19a9d1cc1147d01ea94a7"} {"source_code": "var n = readline()\nvar res = n;\nvar p = readline().split(\" \")\nvar tomas = p.map((a) => Number(a)).reduce((a, b) => a + b, 0);\n\nfor (var i = 1; i < n; i++) {\n var p = readline().split(\" \")\n var point = p.map((a) => Number(a)).reduce((a, b) => a + b, 0);\n (tomas >= point)?res--:0;\n}\n\nprint(res)", "positive_code": [{"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nbuf = '';\nctr = 0;\nvar n;\nvar m = 0;\nvar lst = [];\nvar split;\n\nrl.on('line', function (line) {\n\tsplit = line.trim().split(' ').map(x => parseInt(x))\n\tif( split.length == 1){\n\t\tn = parseInt(line);\n\t}\n\telse {\n\t\t\n\t\tlst[m] = {idx: m+1, val: split.reduce( (full, curr) => full + curr )}\n\t\tm++;\n\t\tn--;\n\t\tif(n == 0){\n\t\t\tvar srt = lst.sort( (a, b) => {\n\t\t\t\treturn a.val != b.val ? b.val - a.val : a.idx - b.idx\n\t\t\t})\n\t\t\tsrt.forEach( ({idx}, id) => idx == 1 ? console.log(id+1) : 0 )\n\t\t\t// console.log(srt)\t\t\t\n\t\t\tprocess.exit()\n\t\t}\n\t}\n});"}, {"source_code": "function main(){\n var n = +readline();\n var a = [];\n\n for(var i = 0;i < n;i++){\n a.push(readline().split(' ').reduce((sum,o) => sum + +o, 0));\n }\n var t = a[0];\n \n print(a.sort((s,q)=>q-s).indexOf(+t) +1);\n}\n\nmain();\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet me = 0;\nlet ans = 1;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const sum = arr.reduce((a, b) => a + b, 0);\n\n if (c === 1) {\n me = sum;\n }\n\n if (sum > me) {\n ans++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var n = +readline();\nvar total = [];\nvar id = 1;\n\nfor (var i=0; i {\n input.push(line);\n});\n\nRL.on('close', () => {\n let n = parseInt(input[0]);\n\n let data = []; let t_pos = 1, t_points = 0;\n for(let i = 0; i < n; i++){\n let sum = 0; input[i+1].split(' ').forEach( j => sum+= parseInt(j) );\n data.push(sum); \n if(i == 0)\n t_points = sum;\n else {\n if(sum > t_points)\n t_pos++;\n }\n }\n console.log(t_pos);\n});\n\n"}, {"source_code": "var n = readline()\nvar res = n;\nvar p = readline().split(\" \")\nvar tomas = p.map((a) => Number(a)).reduce((a, b) => a + b, 0);\n\nfor (var i = 1; i < n; i++) {\n var p = readline().split(\" \")\n var point = p.map((a) => Number(a)).reduce((a, b) => a + b, 0);\n (tomas >= point)?res--:0;\n}\n\nprint(res)"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const scores = new Array(n);\n for (let i = 0; i < n; i += 1) {\n scores[i] = is.nextArray(Number);\n scores[i] = [scores[i].reduce((accum, item) => accum + item, 0), i + 1];\n }\n scores.sort((a, b) => {\n if (a[0] === b[0])\n return a[1] - b[1];\n return b[0] - a[0];\n });\n\n for (let i = 0; i < n; i += 1) {\n if (scores[i][1] === 1) {\n console.log(i + 1);\n break;\n }\n }\n\n}\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const vIn = [];\nlet itIn = 0;\nconst getNext = () => vIn[itIn++];\nconst getInt = () => parseInt(getNext(), 10);\nconst forEachN = (n, cb, flagInt = false) => {\n const nextItIn = itIn + n;\n const fn = flagInt ? getInt : getNext;\n while (itIn !== nextItIn) cb(fn());\n};\n\nclass SolveProblemClass {\n constructor() {\n }\n\n solveAll() {\n const n = getInt();\n const v = [];\n for (let i = 0; i < n ; i++) {\n let sum = 0;\n forEachN(4, (x) => {\n sum += x;\n }, true);\n v.push({ i, sum });\n }\n v.sort((a, b) => {\n if (b.sum > a.sum) return 1;\n if (b.sum < a.sum) return -1;\n return a.i - b.i;\n });\n const pos = v.reduce((i, obj, it) => {\n if (obj.i === 0) return it + 1;\n return i;\n }, -1);\n console.log(pos);\n }\n}\n\nconst processData = (input) => {\n input.split('\\n').forEach(line => {\n // vIn.push(line);\n line.split(' ').forEach(item => { vIn.push(item); });\n });\n};\n\nconst solveP = new SolveProblemClass();\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nlet _input = \"\";\nprocess.stdin.on(\"data\", (input) => {\n _input += input;\n});\nprocess.stdin.on(\"end\", () => {\n processData(_input);\n solveP.solveAll();\n});\n"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({input: process.stdin})\n\nlet n, sums = [], numLines = 0\nrl.on('line', line => {\n if (++numLines == 1) {\n n = parseInt(line)\n } else {\n const currentSum = line.split(' ').map(x => parseInt(x)).reduce((a, x) => a + x)\n sums.push(currentSum)\n }\n}).on('close', () => {\n const thomasSum = sums.shift()\n const thomasRank = 1 + sums.filter(x => x > thomasSum).length\n process.stdout.write(`${thomasRank}`)\n})\n"}], "negative_code": [{"source_code": "function main(){\n var n = +readline();\n var a = [];\n var t = readline().split(' ').reduce((sum,o) => +sum + +o, 0)\n \n for(var i = 0;i< n-1;i++){\n a.push(readline().split(' ').reduce((sum,o) => +sum + +o, 0));\n print(a[i])\n }\n var r = a.sort((s,q)=>q-s).indexOf(t);\n if(r > -1){\n print(r + 1);\n }\n else{\n if(t > a[0]){\n print(1);\n }\n else{\n print(n);\n }\n }\n \n \n}\n\nmain()"}, {"source_code": "function main(){\n var n = +readline();\n var a = [];\n var t = readline().split(' ').reduce((sum,o) => sum + +o, 0)\n \n for(var i = 0;i< n-1;i++){\n a.push(readline().split(' ').reduce((sum,o) => sum + +o, 0));\n }\n var r = a.sort((s,q)=>q-s).indexOf(+t);\n \n if(r > -1){\n print(r + 1);\n }\n else{\n if(t > a[0] || !a.length){\n print(1);\n }\n else{\n print(n);\n }\n }\n}\n\nmain()"}, {"source_code": "function main(){\n var n = +readline();\n var a = [];\n var t = readline().split(' ').reduce((sum,o) => +sum + +o, 0)\n \n for(var i = 0;i< n-1;i++){\n a.push(readline().split(' ').reduce((sum,o) => +sum + +o, 0));\n }\n var r = a.sort((s,q)=>q-s).indexOf(t);\n if(r > -1){\n print(r + 1);\n }\n else{\n if(t > a[0]){\n print(1);\n }\n else{\n print(n);\n }\n }\n \n \n}\n\nmain()"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', function (line) {\n console.log(2);\n process.exit()\n});"}, {"source_code": "console.log(2)\nprocess.exit()"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nbuf = '';\nctr = 0;\nvar n;\nvar m = 0;\nvar lst = [];\nvar split;\n\nrl.on('line', function (line) {\n\tsplit = line.trim().split(' ').map(x => parseInt(x))\n\tif( split.length == 1){\n\t\tn = parseInt(line);\n\t}\n\telse {\n\t\t\n\t\tlst[m] = {idx: m+1, val: split.reduce( (full, curr) => full + curr )}\n\t\tm++;\n\t\tn--;\n\t\tif(n == 0){\n\t\t\tvar srt = lst.sort( (a, b) => {\n\t\t\t\treturn a.val != b.val ? b.val - a.val : b.idx - a.idx\n\t\t\t})\n\t\t\tsrt.forEach( ({idx}, id) => idx == 1 ? console.log(id+1) : 0 )\n\t\t\t// console.log(srt)\t\t\t\n\t\t\tprocess.exit()\n\t\t}\n\t}\n});"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding(\"ascii\");\nbuf = ''\nctr = 0\nvar n\nvar m = 0\nvar lst = []\nvar split\nprocess.stdin.on('data', input => {\n\tsplit = input.trim().split(' ').map(x => parseInt(x))\n\tif( split.length == 1){\n\t\tn = parseInt(input);\n\t}\n\telse {\n\t\t\n\t\tlst[m] = {idx: m+1, val: split.reduce( (full, curr) => full + curr )}\n\t\tm++;\n\t\tn--;\n\t\tif(n == 0){\n\t\t\tvar srt = lst.sort( (a, b) => {\n\t\t\t\treturn a.val != b.val ? b.val - a.val : b.idx - a.idx\n\t\t\t})\n\t\t\t// console.log(srt)\n\t\t\tsrt.forEach( ({idx}, id) => idx == 1 ? console.log(id+1) : 0 )\n\t\t\tprocess.exit(0)\n\t\t}\n\t}\n})\n// process.stdin.on(\"end\", () => {\n// \tconsole.log(buf)\n// })"}, {"source_code": "// process.stdin.resume()\nprocess.stdin.setEncoding(\"ascii\");\nbuf = ''\nctr = 0\nvar n\nvar m = 0\nvar lst = []\nvar split\nprocess.stdin.on('data', input => {\n\tsplit = input.trim().split(' ').map(x => parseInt(x))\n\tif( split.length == 1){\n\t\tn = parseInt(input);\n\t}\n\telse {\n\t\t\n\t\tlst[m] = {idx: m+1, val: split.reduce( (full, curr) => full + curr )}\n\t\tm++;\n\t\tn--;\n\t\tif(n == 0){\n\t\t\tvar srt = lst.sort( (a, b) => {\n\t\t\t\treturn a.val != b.val ? b.val - a.val : b.idx - a.idx\n\t\t\t})\n\t\t\tsrt.forEach( ({idx}, id) => idx == 1 ? console.log(id+1) : 0 )\n\t\t\t// console.log(srt)\t\t\t\n\t\t\tprocess.exit()\n\t\t}\n\t}\n})\n// process.stdin.on(\"end\", () => {\n// \tvar lid\n// \tsrt.forEach( ({idx}, id) => idx == 1 ? lid=id+1: 0 )\n// \tconsole.log(lid)\n// \tprocess.exit(lid)\n// })"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding(\"ascii\");\nbuf = ''\nctr = 0\nvar n\nvar m = 0\nvar lst = []\nvar split\nprocess.stdin.on('data', input => {\n\tsplit = input.trim().split(' ').map(x => parseInt(x))\n\tif( split.length == 1){\n\t\tn = parseInt(input);\n\t}\n\telse {\n\t\t\n\t\tlst[m] = {idx: m+1, val: split.reduce( (full, curr) => full + curr )}\n\t\tm++;\n\t\tn--;\n\t\tif(n == 0){\n\t\t\tvar srt = lst.sort( (a, b) => {\n\t\t\t\treturn a.val != b.val ? b.val - a.val : b.idx - a.idx\n\t\t\t})\n\t\t\tsrt.forEach( ({idx}, id) => idx == 1 ? console.log(id+1) : 0 )\n\t\t\tconsole.log(srt)\t\t\t\n\t\t\tprocess.exit(0)\n\t\t}\n\t}\n})\n// process.stdin.on(\"end\", () => {\n// \tvar lid\n// \tsrt.forEach( ({idx}, id) => idx == 1 ? lid=id+1: 0 )\n// \tconsole.log(lid)\n// \tprocess.exit(lid)\n// })"}], "src_uid": "3c984366bba580993d1694d27982a773"} {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nclass Heap {\n constructor(){\n this.root = null;\n this.count = 0;\n }\n size(){\n return this.count;\n }\n top(){\n return this.root.value;\n }\n push(value){\n this.root = HeapNode.merge(this.root, new HeapNode(value));\n this.count++;\n }\n pop(){\n if (!this.count)\n return null;\n this.count--;\n let val = this.root.value;\n this.root = HeapNode.merge(this.root.l, this.root.r);\n return val;\n }\n}\n// max heap\nclass HeapNode {\n constructor(value, l, r){\n this.value = value;\n this.l = l;\n this.r = r;\n }\n static merge(node1, node2){\n if (!node1)\n return node2;\n if (!node2)\n return node1;\n if (node1.value[0]0.5 ?\n new HeapNode(node1.value, node1.l, HeapNode.merge(node1.r, node2)) :\n new HeapNode(node1.value, HeapNode.merge(node1.l, node2), node1.r);\n }\n}\n\nconst calc = (testN)=>{\n // READING:\n let [n, k] = ra();\n let A = ra();\n LT({n, k, A});\n // PROCESSING:\n let sorted = [];\n let sum = 0;\n for (let i=0; ib-a);\n let cnt = 0;\n for (let i=0; i1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nclass Heap {\n constructor(){\n this.root = null;\n this.count = 0;\n }\n size(){\n return this.count;\n }\n top(){\n return this.root.value;\n }\n push(value){\n this.root = HeapNode.merge(this.root, new HeapNode(value));\n this.count++;\n }\n pop(){\n if (!this.count)\n return null;\n this.count--;\n let val = this.root.value;\n this.root = HeapNode.merge(this.root.l, this.root.r);\n return val;\n }\n}\n// max heap\nclass HeapNode {\n constructor(value, l, r){\n this.value = value;\n this.l = l;\n this.r = r;\n }\n static merge(node1, node2){\n if (!node1)\n return node2;\n if (!node2)\n return node1;\n if (node1.value[0]0.5 ?\n new HeapNode(node1.value, node1.l, HeapNode.merge(node1.r, node2)) :\n new HeapNode(node1.value, HeapNode.merge(node1.l, node2), node1.r);\n }\n}\n\nconst calc = (testN)=>{\n // READING:\n let [n, k] = ra();\n let A = ra();\n LT({n, k, A});\n // PROCESSING:\n let heap = new Heap();\n let sum = 0;\n for (let i=0; i=0){\n L(heap.top())\n sum -= heap.pop()[0]+cnt;\n cnt++;\n }\n }\n return sum;\n};\n "}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, nums) {\r\n if (m === n) return 0;\r\n let dp = [];\r\n for (let i = 0; i < n; i++) {\r\n dp[i] = [nums[i] - (n - i - 1), i];\r\n }\r\n dp.sort((a, b) => a[0] !== b[0] ? b[0] - a[0] : b[1] - a[1]);\r\n let dels = new Set(dp.slice(0, m).map(a => a[1]));\r\n let res = 0;\r\n {\r\n let count = 0;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (dels.has(i)) {\r\n if (count) {\r\n res += count;\r\n }\r\n } else {\r\n res += nums[i];\r\n count++;\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, k] = ra();\n let a = ra();\n let b = new Array(n);\n\n for (let i = 0; i < n; i++) {\n b[i] = [-a[i] + (n - i), i];\n }\n\n b.sort(([x0, x1], [y0, y1]) => x0 - y0);\n\n // console.log('DEBUG b', b);\n\n let s = new Set();\n for (let i = 0; i < k; i++) {\n let [val, idx] = b[i];\n s.add(idx);\n }\n\n // console.log('DEBUG s', s);\n\n let result = 0;\n let acc = 0;\n\n for (let i = 0; i < n; i++) {\n if (s.has(i)) {\n acc++;\n } else {\n result += a[i] + acc;\n }\n }\n \n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, nums) {\r\n if (m === n) return 0;\r\n const segTree = new SegTree(n);\r\n for (let i = 0; i < n; i++) {\r\n segTree.update(i, i, nums[i]);\r\n }\r\n let i = n - 1,\r\n dels = new Set();\r\n while (m--) {\r\n const top = segTree.root.maxi;\r\n while (dels.has(i)) i--;\r\n if (nums[top] - 1 > nums[i]) {\r\n segTree.update(top, top, -1);\r\n segTree.update(top + 1, n - 1, 1);\r\n dels.add(top);\r\n } else {\r\n segTree.update(i, i, -1);\r\n i--;\r\n }\r\n }\r\n return segTree.root.val;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0,\r\n maxi: -1,\r\n count: 0,\r\n max: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n const mid = l + r >> 1;\r\n left.add += node.add;\r\n left.val += node.add * (mid - l + 1 - left.count);\r\n right.add += node.add;\r\n right.val += node.add * (r - mid - right.count);\r\n node.add = 0;\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (left.max > right.max) {\r\n node.max = left.max;\r\n node.maxi = left.maxi;\r\n } else {\r\n node.max = right.max;\r\n node.maxi = right.maxi;\r\n }\r\n node.val = left.val + right.val;\r\n node.count = left.count + right.count;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n if (z === -1) {\r\n node.add = 0;\r\n node.val = 0;\r\n node.max = -1;\r\n node.maxi = -1;\r\n node.count = 1;\r\n } else {\r\n node.add += z;\r\n node.val += z * (r - l + 1 - node.count);\r\n node.max += z;\r\n if (l === r) node.maxi = l;\r\n }\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, nums) {\r\n if (m === n) return 0;\r\n const segTree = new SegTree(n);\r\n for (let i = 0; i < n; i++) {\r\n segTree.update(i, i, nums[i]);\r\n }\r\n let i = n - 1,\r\n dels = new Set();\r\n while (m--) {\r\n const top = segTree.root.maxi;\r\n while (dels.has(i)) i--;\r\n if (nums[top] - 1 > nums[i]) {\r\n segTree.update(top, top, -Infinity);\r\n segTree.update(top + 1, n, 1);\r\n dels.add(top);\r\n } else {\r\n segTree.update(i, i, -Infinity);\r\n i--;\r\n }\r\n }\r\n while (dels.has(i)) i--;\r\n let res = 0;\r\n for (let j = 0; j <= i; j++) {\r\n if (dels.has(j)) continue;\r\n res += segTree.query(j, j);\r\n }\r\n return res;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0,\r\n maxi: -1\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n left.add += node.add;\r\n left.val += node.add;\r\n right.add += node.add;\r\n right.val += node.add;\r\n node.add = 0;\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (left.val > right.val) {\r\n node.val = left.val;\r\n node.maxi = left.maxi;\r\n } else {\r\n node.val = right.val;\r\n node.maxi = right.maxi;\r\n }\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add += z;\r\n node.val += z;\r\n if (l === r) node.maxi = l;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = this._query(node.left, l, mid, x, mid) + this._query(node.right, mid + 1, r, mid + 1, y);\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nclass Heap {\n constructor(){\n this.root = null;\n this.count = 0;\n }\n size(){\n return this.count;\n }\n top(){\n return this.root.value;\n }\n push(value){\n this.root = HeapNode.merge(this.root, new HeapNode(value));\n this.count++;\n }\n pop(){\n if (!this.count)\n return null;\n this.count--;\n let val = this.root.value;\n this.root = HeapNode.merge(this.root.l, this.root.r);\n return val;\n }\n}\n// max heap\nclass HeapNode {\n constructor(value, l, r){\n this.value = value;\n this.l = l;\n this.r = r;\n }\n static merge(node1, node2){\n if (!node1)\n return node2;\n if (!node2)\n return node1;\n if (node1.value>node2.value)\n return HeapNode.merge(node2, node1);\n return Math.random()>0.5 ?\n new HeapNode(node1.value, node1.l, HeapNode.merge(node1.r, node2)) :\n new HeapNode(node1.value, HeapNode.merge(node1.l, node2), node1.r);\n }\n}\n\nconst calc = (testN)=>{\n // READING:\n let [n, k] = ra();\n let A = ra();\n LT({n, k, A});\n // PROCESSING:\n let sum = 0;\n for (let i=0; i=0; i--){\n let top = heap.top();\n let newSum = curSum - A[i] + (n-i-k) + top;\n if (newSum {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n // const getDict = str => str.split(\"\").reduce((dict, char) => {\n // dict[char] = dict[char] ? dict[char] + 1 : 1;\n \n // return dict;\n // }, {});\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n //console.log(\"tests\", tests)\n \n const getOccurrencesDict = arr => {\n const dict = arr.reduce((acc, n) => {\n const remainder = n % 2;\n acc[remainder] = (acc[remainder] || 0 ) + 1;\n \n return acc;\n }, {});\n \n dict[0] = dict[0] || 0;\n dict[1] = dict[1] || 0;\n return dict;\n }\n \n for (let i = 0; i < tests.length; i+=2) {\n //console.log(\"i\", i/2)\n const [length, countToSelect] = tests[i];\n const arr = tests[i + 1];\n \n const dict = getOccurrencesDict(arr);\n \n // if (i/2 === 4) {\n // console.log(\"length\", length);\n // console.log(\"countToSelect\", countToSelect);\n // console.log(\"arr\", arr);\n // console.log(\"dict\", dict)\n // }\n \n //console.log(\"dict\", dict)\n \n if (length === countToSelect) {\n console.log(dict[1] % 2 ? \"Yes\" : \"No\");\n continue;\n } else {\n //console.log(\"dict\", dict);\n let foundSuitableCount = false;\n if (dict[0]) {\n for (let oddCount = 1; oddCount <= dict[1]; oddCount+=2) {\n const evenCount = countToSelect - oddCount;\n if (dict[0] >= evenCount && dict[1] >= oddCount) {\n foundSuitableCount = true;\n break;\n }\n }\n console.log(foundSuitableCount ? \"Yes\" : \"No\");\n } else {\n console.log(countToSelect % 2 ? \"Yes\" : \"No\")\n }\n }\n }\n \n // tests.forEach(test => {\n \n // })\n}\n", "positive_code": [{"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n for (var i = 0; i < testCases; i++) {\n var x = readLine()\n .split(\" \")\n .map(num => parseInt(num))[1];\n\n var numberOfEven = 0;\n var numberOfOdd = 0;\n\n readLine()\n .split(\" \")\n .map(num => {\n if (parseInt(num) % 2) numberOfOdd++;\n else numberOfEven++;\n });\n\n if (!numberOfOdd) console.log(\"NO\");\n else if (x - 1 <= numberOfEven || (x - numberOfEven) % 2) console.log(\"Yes\");\n else if (numberOfEven && (x - numberOfEven) < numberOfOdd) console.log(\"Yes\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "'use strict';\n\nlet inputFromTerminal = ''\nprocess.stdin.on('data', c => inputFromTerminal += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = inputFromTerminal.split(EOL)\n\n let t = Number(lines[0])\n for (let i = 1; i <= 2 * t; i += 2) {\n let currentLine = lines[i].split(' ')\n let n = Number(currentLine[0])\n let x = Number(currentLine[1])\n let array = lines[i + 1].split(' ').map(value => Number(value))\n let result = firs(n, x, array)\n if (result) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n }\n})\n\nfunction firs(n, x, mas) {\n let countEven;\n let countOdd = 0;\n for (let i = 0; i < n; i++) {\n if (mas[i] % 2 > 0) {\n countOdd++\n }\n }\n countEven = n - countOdd\n if (countOdd === 0) {\n return false\n }\n let oddToTake;\n if (x < countOdd) {\n oddToTake = x\n } else {\n oddToTake = countOdd\n }\n\n if (oddToTake % 2 === 0) {\n oddToTake--\n }\n\n return x - oddToTake <= countEven;\n}"}, {"source_code": "\"use strict\";\n \nvar cases =parseInt(readline());\n \nwhile(cases --){\n \n\tvar read =readline().split(\" \");\n\tvar arr =readline().split(\" \");\n \n\tvar n =parseInt(read[0]) , x =parseInt(read[1]);\n \n\tvar odd =0 , even =0;\n\tvar need =0;\n \n\tfor(var i =0 ; i n) print(\"No\");\n\telse{\n\t\tif(odd &1) need =odd;\n\t\telse need =odd -1;\n\t\tif(even +1 >=x) print(\"Yes\");\n\t\telse if(need >=x && x &1) print(\"Yes\");\n\t\telse if(need && even && even +need >=x) print(\"Yes\");\n\t\telse print(\"No\");\n\t}\n \n \n}"}, {"source_code": "\"use strict\";\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\n\tvar read =readline().split(\" \").map(val => parseInt(val));\n\tvar arr =readline().split(\" \").map(val => parseInt(val));\n\n\tvar n =read[0] , x =read[1];\n\n\tvar odd =0 , even =0;\n\tvar need =0;\n\n\tfor(var i =0 ; i n) print(\"No\");\n\telse{\n\t\tif(odd &1) need =odd;\n\t\telse need =odd -1;\n\t\tif(even +1 >=x) print(\"Yes\");\n\t\telse if(need >=x && x &1) print(\"Yes\");\n\t\telse if(need && even && even +need >=x) print(\"Yes\");\n\t\telse print(\"No\");\n\t}\n\n\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n x = input[1];\n var odd = [],\n even = [];\n var arr = readline()\n .split(\" \")\n .forEach((val) => {\n if (parseInt(val) % 2 == 0) even.push(parseInt(val));\n if (parseInt(val) % 2 != 0) odd.push(parseInt(val));\n });\n var found = false;\n if (even.length == 0 && x % 2 != 0) print(\"Yes\");\n else if (odd.length == 0) print(\"No\");\n else {\n for (var i = 1; i <= odd.length && x - i >= 0; i += 2) {\n if (x - i <= even.length) {\n print(\"Yes\");\n found = true;\n break;\n }\n }\n if (!found) print(\"No\");\n }\n}\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nx = readNumArray();\n var n = nx[0];\n var x = nx[1];\n var arr = readNumArray();\n\n var odds = 0;\n var evens = 0;\n for (var j = 0; j < n; j++) {\n if (arr[j] % 2) {\n odds++;\n } else {\n evens++;\n }\n }\n if (!odds) {\n print(\"NO\");\n continue;\n }\n if (!evens && x % 2 === 0) {\n print(\"NO\");\n continue;\n }\n if (odds % 2 === 0 && x === n) {\n print(\"NO\");\n continue;\n }\n print(\"YES\");\n continue;\n }\n}\n\nmain();"}, {"source_code": "var num = parseInt(readline());\nfor (var tc = 0; tc < num; tc++) {\n\tvar n_x = readline().split(\" \").map(number => parseInt(number));\n\tvar n = n_x[0];\n\tvar x = n_x[1];\n\tvar even = 0, odd = 0;\n\tvar nums = readline().split(\" \").map(number => parseInt(number));\n\tfor (var i=0; ix?0:x-even;\n\tvar max_odds = Math.min(x, odd);\n\t/* pick x integers */\n\tif ((min_odds === max_odds) && (min_odds%2 === 0)) {\n\t\tprint(\"nO\");\n\t}\n\telse {\n\t\tprint(\"yes\");\n\t}\n}"}, {"source_code": "\"use strict\";\n \nvar cases =parseInt(readline());\n \nwhile(cases --){\n \n\tvar read =readline().split(\" \");\n\tvar arr =readline().split(\" \");\n \n\tvar n =parseInt(read[0]) , x =parseInt(read[1]);\n \n\tvar odd =0 , even =0;\n\tvar need =0;\n \n\tfor(var i =0 ; i n) print(\"No\");\n\telse{\n\t\tif(odd &1) need =odd;\n\t\telse need =odd -1;\n\t\tif(even +1 >=x) print(\"Yes\");\n\t\telse if(need >=x && x &1) print(\"Yes\");\n\t\telse if(need && even && even +need >=x) print(\"Yes\");\n\t\telse print(\"No\");\n\t}\n \n \n}"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar n = one[0];\n\t\tvar x = one[1];\n\t\tvar list = nextIntArray();\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(list[j] % 2 == 0){\n\t\t\t\teven++;\n\t\t\t}else{\n\t\t\t\todd++;\n\t\t\t}\n\t\t}\n\t\tif(odd > 0){\n\t\t\t//\u5947\u6570\u306e\u3082\u306e\u3092\u5148\u306b\u5947\u6570\u500b\u9078\u3093\u3067\u304a\u304f\n\t\t\tvar tmp = Math.min(odd, x);\n\t\t\tif(tmp % 2 == 0){\n\t\t\t\ttmp--;\n\t\t\t}\n\t\t\tx -= tmp;\n\t\t\tif(even >= x){\n\t\t\t\t//\u5947\u65701\u500b\u3001\u4ed6\u5168\u90e8\u5076\u6570\u3002\u5947\u65701\u500b\u3042\u308c\u3070\u5076\u6570\u3044\u304f\u3089\u3042\u3063\u3066\u3082\u5947\u6570\u306b\u306a\u308b\n\t\t\t\toutput[i] = \"Yes\";\n\t\t\t}else{\n\t\t\t\t//\u5947\u65701\u500b\u3001\u9078\u3079\u308b\u3060\u3051\u5076\u6570\u3001\u6b8b\u308a\u306f\u5fc5\u305a\u5947\u6570\u3002\n\t\t\t\t//\u9078\u3076\u500b\u6570\u304c\u5947\u6570\u500b\u306a\u3089NO(\u5408\u8a08\u304c\u5076\u6570\u306b\u306a\u308b)\n\t\t\t\tx -= even;\n\t\t\t\tif(x % 2 == 0){\n\t\t\t\t\toutput[i] = \"Yes\";\n\t\t\t\t}else{\n\t\t\t\t\toutput[i] = \"No\";\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\t//\u5947\u6570\u304c\u306a\u3044\n\t\t\toutput[i] = \"No\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let odd = 0;\n let even = 0;\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) even += 1;\n else odd += 1;\n }\n if (!odd) console.log('No');\n else if (!even && numEle % 2 === 0) console.log('No');\n else if (odd % 2 === 0 && numEle === arr.length) console.log('No');\n else console.log('Yes');\n // const half = Math.ceil(numEle / 2);\n // if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n // else if (numEle == 2) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else if (numEle % 2 === 0) ((obj.odd >= half - 1 && obj.even >= half + 1) || (obj.odd >= half + 1 && obj.even >= half - 1)) ? console.log('Yes') : console.log('No');\n // else {\n // if (obj.odd >= numEle) console.log('Yes');\n // else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n // }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let odd = 0;\n let even = 0;\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 === 0) even += 1;\n else odd += 1;\n }\n if (!odd) console.log('No');\n else if (!even && ((numEle & 1) === 0)) console.log('No');\n else if ((odd & 1) === 0 && numEle === arr.length) console.log('No');\n else console.log('Yes');\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n if (!obj.odd) console.log('No');\n else if (!obj.even && numEle % 2 === 0) console.log('No');\n else if (obj.odd % 2 === 0 && numEle === arr.length) console.log('No');\n else console.log('Yes');\n // const half = Math.ceil(numEle / 2);\n // if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n // else if (numEle == 2) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else if (numEle % 2 === 0) ((obj.odd >= half - 1 && obj.even >= half + 1) || (obj.odd >= half + 1 && obj.even >= half - 1)) ? console.log('Yes') : console.log('No');\n // else {\n // if (obj.odd >= numEle) console.log('Yes');\n // else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n // }\n }\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\n\tvar read =readline().split(\" \").map(val =>parseInt(val));\n\tvar arr =readline().split(\" \").map(val =>parseInt(val));\n\n\tvar n =read[0] , x =read[1];\n\n\tvar odd =0 , even =0;\n\tvar need =0;\n\n\tfor(var i =0 ; i n) print(\"No\");\n\telse{\n\t\t\n\t\tif(even +1 >=x) print(\"Yes\");\n\t\telse if(odd -1 >=x) print(\"Yes\");\n\t\telse print(\"No\");\n\t}\n\n\n}"}, {"source_code": "\"use strict\";\n\nvar cases =parseInt(readline());\n\nwhile(cases --){\n\n\tvar read =readline().split(\" \").map(val => parseInt(val));\n\tvar arr =readline().split(\" \").map(val => parseInt(val));\n\n\tvar n =read[0] , x =read[1];\n\n\tvar odd =0 , even =0;\n\tvar need =0;\n\n\tfor(var i =0 ; i n) print(\"No\");\n\telse{\n\t\tif(odd &1) need =odd;\n\t\telse need =odd -1;\n\t\tif(even +1 >=x) print(\"Yes\");\n\t\telse if(need >=x) print(\"Yes\");\n\t\telse if(even +need >=x) print(\"Yes\");\n\t\telse print(\"No\");\n\t}\n\n\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n x = input[1];\n var odd = [],\n even = [];\n var arr = readline()\n .split(\" \")\n .forEach((val) => {\n if (parseInt(val) % 2 == 0) even.push(parseInt(val));\n if (parseInt(val) % 2 != 0) odd.push(parseInt(val));\n });\n var found = false;\n if (even.length == 0 && x % 2 != 0) print(\"Yes\");\n else if (odd.length == 0) print(\"No\");\n else {\n for (var i = 1; i <= odd.length; i += 2) {\n if (x - i <= even.length) {\n print(\"Yes\");\n found = true;\n break;\n }\n }\n if (!found) print(\"No\");\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n // const getDict = str => str.split(\"\").reduce((dict, char) => {\n // dict[char] = dict[char] ? dict[char] + 1 : 1;\n \n // return dict;\n // }, {});\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n //console.log(\"tests\", tests)\n \n const getOccurrencesDict = arr => {\n const dict = arr.reduce((acc, n) => {\n const remainder = n % 2;\n acc[remainder] = (acc[remainder] || 0 ) + 1;\n \n return acc;\n }, {});\n \n dict[0] = dict[0] || 0;\n dict[1] = dict[1] || 0;\n return dict;\n }\n \n for (let i = 0; i < tests.length; i+=2) {\n //console.log(\"i\", i/2)\n const [length, countToSelect] = tests[i];\n const arr = tests[i + 1];\n \n const dict = getOccurrencesDict(arr);\n \n // if (i/2 === 18) {\n // console.log(\"length\", length);\n // console.log(\"countToSelect\", countToSelect);\n // console.log(\"arr\", arr);\n // console.log(\"dict\", dict)\n // }\n \n //console.log(\"dict\", dict)\n \n if (length === countToSelect) {\n console.log(dict[1] % 2 ? \"Yes\" : \"No\");\n continue;\n } else {\n //console.log(\"dict\", dict);\n let foundSuitableCount = false;\n for (let oddCount = 1; oddCount <= dict[1]; oddCount+=2) {\n const evenCount = countToSelect - oddCount;\n if (dict[0] >= evenCount && dict[1] >= oddCount) {\n foundSuitableCount = true;\n break;\n }\n }\n console.log(foundSuitableCount ? \"Yes\" : \"No\");\n }\n }\n \n // tests.forEach(test => {\n \n // })\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction main() { \n // console.log(\"typeof inputString\", typeof inputString)\n //console.log(\"inputString\", inputString)\n // const getDict = str => str.split(\"\").reduce((dict, char) => {\n // dict[char] = dict[char] ? dict[char] + 1 : 1;\n \n // return dict;\n // }, {});\n \n const tests = inputString.slice(1).map(testStr => testStr.split(\" \").map(Number));\n //console.log(\"tests\", tests)\n \n const getOccurrencesDict = arr => {\n return arr.reduce((acc, n) => {\n const remainder = n % 2;\n acc[remainder] = (acc[remainder] || 0 ) + 1;\n \n return acc;\n }, {});\n }\n \n for (let i = 0; i < tests.length; i+=2) {\n const [length, countToSelect] = tests[i];\n const arr = tests[i + 1];\n \n const dict = getOccurrencesDict(arr);\n \n //console.log(\"dict\", dict)\n \n if (length === countToSelect) {\n console.log(dict[1] % 2 ? \"Yes\" : \"No\");\n continue;\n } else {\n //console.log(\"dict\", dict);\n let foundSuitableCount = false;\n for (let oddCount = 1; oddCount <= dict[1]; oddCount+=2) {\n const evenCount = countToSelect - oddCount;\n if (dict[0] >= evenCount && dict[1] >= oddCount) {\n foundSuitableCount = true;\n break;\n }\n }\n console.log(foundSuitableCount ? \"Yes\" : \"No\");\n }\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar n = one[0];\n\t\tvar x = one[1];\n\t\tvar list = nextIntArray();\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(list[j] % 2 == 0){\n\t\t\t\teven++;\n\t\t\t}else{\n\t\t\t\todd++;\n\t\t\t}\n\t\t}\n\t\tif(odd > 0){\n\t\t\tx--;\n\t\t\todd--;\n\t\t\tif(even >= x){\n\t\t\t\toutput[i] = \"Yes\";\n\t\t\t}else{\n\t\t\t\tx -= even;\n\t\t\t\tif(odd % 2 == 0){\n\t\t\t\t\toutput[i] = \"Yes\";\n\t\t\t\t}else{\n\t\t\t\t\toutput[i] = \"No\";\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\toutput[i] = \"No\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar n = one[0];\n\t\tvar x = one[1];\n\t\tvar list = nextIntArray();\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(list[j] % 2 == 0){\n\t\t\t\teven++;\n\t\t\t}else{\n\t\t\t\todd++;\n\t\t\t}\n\t\t}\n\t\tif(odd > 0){\n\t\t\tx--;\n\t\t\todd--;\n\t\t\tif(even >= x){\n\t\t\t\toutput[i] = \"Yes\";\n\t\t\t}else{\n\t\t\t\tx -= even;\n\t\t\t\tif(odd > 0 && odd % 2 == 0){\n\t\t\t\t\toutput[i] = \"Yes\";\n\t\t\t\t}else{\n\t\t\t\t\toutput[i] = \"No\";\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\toutput[i] = \"No\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar n = one[0];\n\t\tvar x = one[1];\n\t\tvar list = nextIntArray();\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tfor(var j = 0; j < n; j++){\n\t\t\tif(list[j] % 2 == 0){\n\t\t\t\teven++;\n\t\t\t}else{\n\t\t\t\todd++;\n\t\t\t}\n\t\t}\n\t\tif(odd > 0){\n\t\t\t//\u5947\u6570\u306e\u3082\u306e\u3092\u5148\u306b1\u500b\u9078\u3093\u3067\u304a\u304f\n\t\t\tx--;\n\t\t\todd--;\n\t\t\tif(even >= x){\n\t\t\t\t//\u5947\u65701\u500b\u3001\u4ed6\u5168\u90e8\u5076\u6570\n\t\t\t\toutput[i] = \"Yes\";\n\t\t\t}else{\n\t\t\t\t//\u5947\u65701\u500b\u3001\u9078\u3079\u308b\u3060\u3051\u5076\u6570\u3001\u6b8b\u308a\u306f\u5fc5\u305a\u5947\u6570\u3002\n\t\t\t\tx -= even;\n\t\t\t\tif(x % 2 == 0){\n\t\t\t\t\toutput[i] = \"Yes\";\n\t\t\t\t}else{\n\t\t\t\t\toutput[i] = \"No\";\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\t//\u5947\u6570\u304c\u306a\u3044\n\t\t\toutput[i] = \"No\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n const half = Math.ceil(numEle / 2);\n if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n else if (numEle == 2) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n else if (numEle % 2 === 0) ((obj.odd == half - 1 && obj.even == half + 1) || (obj.odd == half + 1 && obj.even == half - 1)) ? console.log('Yes') : console.log('No');\n else {\n if (obj.odd >= numEle) console.log('Yes');\n else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n const half = Math.ceil(numEle / 2);\n if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n else if (numEle == 2) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n else if (numEle % 2 === 0) ((obj.odd >= half - 1 && obj.even >= half + 1) || (obj.odd >= half + 1 && obj.even >= half - 1)) ? console.log('Yes') : console.log('No');\n else {\n if (obj.odd >= numEle) console.log('Yes');\n else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let odd = 0;\n let even = 0;\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if ((arr[j] & 1) === 0) even += 1;\n else odd += 1;\n }\n if (!odd) console.log('No');\n else if (!even && (numEle & 1 === 0)) console.log('No');\n else if ((odd & 1) === 0 && numEle === arr.length) console.log('No');\n else console.log('Yes');\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n const half = Math.floor(numEle / 2);\n if (numEle === 1) {\n if (obj.odd >= 1) console.log('Yes');\n else console.log('No');\n } else if (numEle % 2 === 0) {\n if (obj.odd >= half && obj.even >= half) console.log('Yes');\n else console.log('No');\n } else {\n if (obj.odd >= half && obj.even >= half + 1) console.log('Yes');\n else console.log('No');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n const half = Math.ceil(numEle / 2);\n if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n else if (numEle == 2) (obj.odd == half && obj.even == half) ? console.log('Yes') : console.log('No');\n else if (numEle % 2 === 0) ((obj.odd == half - 1 && obj.even == half + 1) || (obj.odd == half + 1 && obj.even == half - 1)) ? console.log('Yes') : console.log('No');\n else {\n if (obj.odd >= numEle) console.log('Yes');\n else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let odd = 0;\n let even = 0;\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 === 0) even += 1;\n else odd += 1;\n }\n if (!odd) console.log('No');\n else if (!even && numEle & 1 === 0) console.log('No');\n else if (odd & 1 === 0 && numEle === arr.length) console.log('No');\n else console.log('Yes');\n // const half = Math.ceil(numEle / 2);\n // if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No');\n // else if (numEle == 2) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else if (numEle % 2 === 0) ((obj.odd >= half - 1 && obj.even >= half + 1) || (obj.odd >= half + 1 && obj.even >= half - 1)) ? console.log('Yes') : console.log('No');\n // else {\n // if (obj.odd >= numEle) console.log('Yes');\n // else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n // else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n // }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data.shift() * 2;\n for (let i = 0; i < testCases; i += 2) {\n let numEle = data[i].split(' ')[1] * 1;\n let obj = {odd: 0, even: 0};\n let arr = data[i + 1].split(' ');\n for (let j = 0; j < arr.length; j += 1) {\n if (arr[j] % 2 ===0) obj.even += 1;\n else obj.odd += 1;\n }\n const half = Math.ceil(numEle / 2);\n if (numEle === 1) (obj.odd >= 1) ? console.log('Yes') : console.log('No')\n else if (numEle % 2 === 0) (obj.odd >= half && obj.even >= half) ? console.log('Yes') : console.log('No');\n else {\n if (obj.odd >= numEle) console.log('Yes');\n else if (half % 2 === 0) (obj.odd >= half - 1 && obj.even >= half) ? console.log('Yes') : console.log('No');\n else (obj.odd >= half && obj.even >= half - 1) ? console.log('Yes') : console.log('No');\n }\n }\n}"}, {"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n for (var i = 0; i < testCases; i++) {\n var x = readLine()\n .split(\" \")\n .map(num => parseInt(num))[1];\n\n var numberOfEven = 0;\n var numberOfOdd = 0;\n\n readLine()\n .split(\" \")\n .map(num => {\n if (parseInt(num) % 2) numberOfOdd++;\n else numberOfEven++;\n });\n\n if (x - 1 <= numberOfEven && numberOfOdd) console.log(\"Yes\");\n else if ((x - numberOfEven) % 2 == 1) console.log(\"Yes\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n for (var i = 0; i < testCases; i++) {\n var x = readLine()\n .split(\" \")\n .map(num => parseInt(num))[1];\n\n var numberOfEven = 0;\n var numberOfOdd = 0;\n\n readLine()\n .split(\" \")\n .map(num => {\n if (parseInt(num) % 2) numberOfOdd++;\n else numberOfEven++;\n });\n\n if (x - 1 <= numberOfEven && numberOfOdd) console.log(\"Yes\");\n else if (numberOfOdd >= 1 && (x - (numberOfEven + parseInt((numberOfOdd - 1) / 2))) <= 1) console.log(\"Yes\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "'use strict';\n\nlet inputFromTerminal = ''\nprocess.stdin.on('data', c => inputFromTerminal += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = inputFromTerminal.split(EOL)\n\n let t = Number(lines[0][0])\n for (let i = 1; i <= 2 * t; i += 2) {\n let currentLine = lines[i].split(' ')\n let n = Number(currentLine[0])\n let x = Number(currentLine[1])\n let array = lines[i + 1].split(' ').map(value => Number(value))\n let result = firs(n, x, array)\n if (result) {\n console.log(\"Yes\")\n } else {\n console.log(\"No\")\n }\n }\n})\n\nfunction firs(n, x, mas) {\n let countEven;\n let countOdd = 0;\n for (let i = 0; i < n; i++) {\n if (mas[i] % 2 > 0) {\n countOdd++\n }\n }\n countEven = n - countOdd\n if (countOdd === 0) {\n return false\n }\n let oddToTake;\n if (x < countOdd) {\n oddToTake = x\n } else {\n oddToTake = countOdd\n }\n\n if (oddToTake % 2 === 0) {\n oddToTake--\n }\n\n return x - oddToTake <= countEven;\n}"}], "src_uid": "afce38aa7065da88d824d1d981b5b338"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const arr = getInts()\n\n let ans = 0\n let ind = 0\n const dp = {}\n for (let i in arr) {\n if (dp[arr[i] - 1]) {\n dp[arr[i]] = dp[arr[i] - 1] + 1\n } else {\n dp[arr[i]] = 1\n }\n\n if (ans < dp[arr[i]]) {\n ans = dp[arr[i]]\n ind = i\n }\n }\n\n let path = []\n let cur = arr[ind]\n while (ind >= 0) {\n if (arr[ind] === cur) {\n path.push(ind)\n cur --\n }\n ind --\n }\n\n path = path.map((i) => parseInt(i) + 1)\n print(ans)\n print(path.reverse().join(' '))\n}", "positive_code": [{"source_code": "'use strict';\n\nvar N = +readline();\nvar a = readline().split(' ').map(function(x){return +x;});\n// print(N);\n// print(a);\n\nfunction main() {\n var d = {};\n var best = {\n len: 0\n };\n\n for (var i = 0; i < a.length; i++) {\n if ((a[i] - 1) in d) {\n d[a[i]] = {\n prev: d[a[i] - 1],\n len: d[a[i] - 1].len + 1\n };\n\n } else {\n d[a[i]] = {\n len: 1\n };\n }\n \n d[a[i]].pos = i;\n \n if (d[a[i]].len > best.len) {\n best = d[a[i]];\n }\n }\n\n // print(best.len);\n var res = [];\n var t = best;\n while (typeof t !== 'undefined') {\n res.push(t.pos + 1);\n t = t.prev;\n }\n\n res.reverse();\n\n print(res.length);\n print(res.join(' '));\n \n}\n\nmain();"}], "negative_code": [], "src_uid": "70986d3b1ff66ac612e8841a6049866d"} {"source_code": "var n = parseInt(readline());\nvar i;\nvar j;\nvar k;\nvar number;\nvar input;\nvar rows = [];\nvar names = {};\n\nfor (i = 0; i < n; i++) {\n input = readline().split(' ');\n if (typeof names[input[0]] === 'number') {\n rows[names[input[0]]].numbers = rows[names[input[0]]].numbers.concat(input.splice(2));\n } else {\n names[input[0]] = rows.length;\n rows.push({name: input[0], numbers: input.splice(2)});\n }\n}\n\nfor (i = 0; i < rows.length; i++) {\n for (j = 0; j < rows[i].numbers.length; j++) {\n var deleting = false;\n number = rows[i].numbers[j];\n for (k = 0; k < rows[i].numbers.length; k++) {\n if (k != j &&\n rows[i].numbers[k].length >= number.length &&\n rows[i].numbers[k].lastIndexOf(number) == rows[i].numbers[k].length - number.length) {\n deleting = true;\n break;\n }\n }\n if (deleting) {\n rows[i].numbers.splice(j, 1);\n j--;\n }\n }\n}\n\nvar toPrint = rows.length + '\\n';\nfor (i = 0; i < rows.length; i++) {\n toPrint += rows[i].name + ' ' + rows[i].numbers.length;\n for (j = 0; j < rows[i].numbers.length; j++) {\n toPrint += ' ' + rows[i].numbers[j];\n }\n toPrint += '\\n';\n}\nprint(toPrint);\n", "positive_code": [{"source_code": "var n=Number(readline())\nT={}\nfor (var i=0;i b.length - a.length );\n\tfor (var j=0; j b.length){\n return 1;\n }\n else if(a.length < b.length){\n return -1;\n }\n return parseInt(a) - parseInt(b);\n });\n //print(numbers);\n\n var res = \"\";\n var count = 0;\n for(var j1 = 0;j1 n){\n print('NO');\n break;\n }\n else if(x == parseInt(x) && a * x + b * y == n){\n print('YES');\n print(x + \" \" + y);\n break;\n }\n}\n*/\n\n/* A\nvar n = readline();\nvar res = '';\nfor (var i = 0; i < n.length - 2; i++)\n res += n[i];\nif(n.length > 1){\n if(n[n.length - 1] > '5')\n res += parseInt(n[n.length - 2]) + 1;\n else {\n res += n[n.length - 2];\n }\n}\nres += '0';\nprint(res);\n*/\n"}, {"source_code": "//var print = require('./print');\n//var readline = require('./readline');\n\nvar n = parseInt(readline());\n\nvar book = {};\n\nfor(var i=0;i n){\n print('NO');\n break;\n }\n else if(x == parseInt(x) && a * x + b * y == n){\n print('YES');\n print(x + \" \" + y);\n break;\n }\n}\n*/\n\n/* A\nvar n = readline();\nvar res = '';\nfor (var i = 0; i < n.length - 2; i++)\n res += n[i];\nif(n.length > 1){\n if(n[n.length - 1] > '5')\n res += parseInt(n[n.length - 2]) + 1;\n else {\n res += n[n.length - 2];\n }\n}\nres += '0';\nprint(res);\n*/\n"}, {"source_code": "var n=Number(readline())\nvar T={}, name, ph\nfunction comp(a,b) { return +a-(+b); }\nfor (var i=0;i b.length - a.length );\n\tfor (var j=0; j b.length - a.length );\n\tfor (var j=0; j {\n return a.split('\\n')[1].split(' ')\n}\n\nconst computeMaxIndex = (i, m) => {\n const rec = (p) => {\n const j = i + Math.pow(2, p)\n if (m < j) {\n return i + Math.pow(2, p - 1)\n } else {\n return rec(p + 1)\n }\n }\n return rec(0)\n}\n\nconst minMove = (array) => {\n let ans = []\n\n for (let i = 0; i < array.length - 1; i++) {\n const max_index = computeMaxIndex(i, array.length - 1)\n let prev = 0\n if (ans.length !== 0) {\n prev = ans[ans.length - 1]\n }\n ans.push(prev + array[i])\n array[max_index] += array[i]\n array[i] = 0\n }\n\n return ans\n}\n\n\nconst array = parse(content).map(a=>Number(a))\nminMove(array).forEach((a)=>console.log(a))\n\n\n"}], "negative_code": [{"source_code": "var n = readline(); \nvar a = Number(readline().split(' ')); // a0..a(n-1)\nvar k = 0;\nvar t = 0\nvar turns = 0;\n\nfor(k=0; k{\n\t\treturn parseInt(elm);\n\t})\n\tvar n = arr[0], L = arr[1], a = arr[2];\n\tvar result = 0;\n\tvar arr1 = [];\n\tarr1[0] = [];\n\tarr1[0][0] = arr1[0][1] = 0;\n\tfor(var i = 1; i <= n; i++){\n\t\tvar ss = readline().split(\" \").map(x=>+x);\n\t\t// var t = arr1[i][0], l = arr1[i][1];\n\t\tarr1[i] = [];\n\t\tarr1[i][0] = ss[0], arr1[i][1] = ss[1];\n\t\tvar cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);\n\t\tif(cnt >= a){\n\t\t\tresult += Math.floor(cnt/a);\n\t\t}\n\t}\n\tif(L - (arr1[n][0]+arr1[n][1]) >= a){\n\t\tresult += Math.floor((L - arr1[n][0]-arr1[n][1])/a);\n\t}\n\t// console.log(result);\n\tprint(result)\n}\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst interface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nlet lineIndex = 0\nlet inputs\n\nlet customerNum, totalTimeLen, breakLen\nlet time, length\nlet breakNum = 0, lastFinish = 0\ninterface.on('line', line => {\n inputs = line.split(' ').map(v => parseInt(v))\n if (lineIndex === 0) {\n customerNum = inputs[0]\n totalTimeLen = inputs[1]\n breakLen = inputs[2]\n } else {\n time = inputs[0]\n length = inputs[1]\n breakNum += Math.floor((time - lastFinish) / breakLen)\n lastFinish = time + length\n }\n\n if (lineIndex == customerNum) {\n breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)\n console.log(breakNum)\n process.exit()\n }\n lineIndex ++\n})"}, {"source_code": "var input = readline().split(\" \").map(function(el) {return parseFloat(el)});\nvar n = input[0];\nvar L = input[1];\nvar a = input[2];\nvar lastClientTime = 0;\nvar breaks = 0;\nfor (var i = 0; i < n; i++) {\n var client = readline().split(\" \").map(function(el) {return parseFloat(el)});\n breaks += parseInt((client[0] - lastClientTime)/a);\n lastClientTime = client[0]+client[1];\n if (i == n - 1)\n breaks += parseInt((L - client[0]-client[1])/a);\n}\nif (n == 0)\n breaks = parseInt(L/a);\nprint(breaks);\n"}, {"source_code": "var g = readline().split(\" \");\n\nvar n = Number(g[0]);\nvar L = Number(g[1]);\nvar a = Number(g[2]);\n\n\nvar time = 0;\nvar count = 0;\n\n\nfor(i=0;i {\n inputs = line.split(' ')\n\n if (lineIndex === 0) {\n customerNum = inputs[0]\n totalTimeLen = inputs[1]\n breakLen = inputs[2]\n } else {\n time = inputs[0]\n length = inputs[1]\n breakNum += Math.floor((time - lastFinish) / breakLen)\n lastFinish = time + length\n }\n})\ninterface.on('close', () => {\n breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)\n console.log(breakNum)\n process.exit()\n})"}, {"source_code": "const readline = require('readline')\n\nconst interface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n})\n\nlet lineIndex = 0\nlet inputs\n\nlet customerNum, totalTimeLen, breakLen\nlet time, length\nlet breakNum = 0, lastFinish = 0\ninterface.on('line', line => {\n inputs = line.split(' ')\n\n if (lineIndex === 0) {\n customerNum = inputs[0]\n totalTimeLen = inputs[1]\n breakLen = inputs[2]\n } else {\n time = inputs[0]\n length = inputs[1]\n breakNum += Math.floor((time - lastFinish) / breakLen)\n lastFinish = time + length\n }\n lineIndex ++\n})\ninterface.on('close', () => {\n breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)\n console.log(breakNum)\n process.exit()\n})"}, {"source_code": "print(0);"}, {"source_code": "function main(){\n\tvar s = readline();\n\tvar arr = s.split(\" \").map(elm=>{\n\t\treturn parseInt(elm);\n\t})\n\tvar n = arr[0], L = arr[1], a = arr[2];\n\tvar result = 0;\n\tvar arr1 = [];\n\tarr1[0] = [];\n\tarr1[0][0] = arr1[0][1] = 0;\n\tfor(var i = 1; i <= n; i++){\n\t\tvar ss = readline().split(\" \").map(x=>+x);\n\t\t// var t = arr1[i][0], l = arr1[i][1];\n\t\tarr1[i] = [];\n\t\tarr1[i][0] = ss[0], arr[i][1] = ss[1];\n\t\tvar cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);\n\t\tif(cnt >= a){\n\t\t\tresult += cnt/a;\n\t\t}\n\t}\n\tif(L - (arr1[n][0]+arr1[n][1]) >= a){\n\t\tresult += (L - arr1[n][0]-arr1[n][1])/a;\n\t}\n\t// console.log(result);\n\tprint(result)\n}\nmain();"}, {"source_code": "function main(){\n\tvar s = readline();\n\tvar arr = s.split(\" \").map(elm=>{\n\t\treturn parseInt(elm);\n\t})\n\tvar n = arr[0], L = arr[1], a = arr[2];\n\tvar result = 0;\n\tvar arr1 = [];\n\tarr1[0] = [];\n\tarr1[0][0] = arr1[0][1] = 0;\n\tfor(var i = 1; i <= n; i++){\n\t\tvar ss = readline().split(\" \").map(x=>+x);\n\t\t// var t = arr1[i][0], l = arr1[i][1];\n\t\tarr1[i] = [];\n\t\tarr1[i][0] = ss[0], arr1[i][1] = ss[1];\n\t\tvar cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);\n\t\tif(cnt >= a){\n\t\t\tresult += cnt/a;\n\t\t}\n\t}\n\tif(L - (arr1[n][0]+arr1[n][1]) >= a){\n\t\tresult += (L - arr1[n][0]-arr1[n][1])/a;\n\t}\n\t// console.log(result);\n\tprint(result)\n}\nmain();"}, {"source_code": "var input = readline().split(\" \").map(function(el) {return parseFloat(el)});\nvar n = input[0];\nvar L = input[1];\nvar a = input[2];\nvar lastClientTime = 0;\nvar breaks = 0;\nfor (var i = 0; i < n; i++) {\n var client = readline().split(\" \").map(function(el) {return parseFloat(el)});\n breaks += parseInt((client[0] - lastClientTime)/a);\n lastClientTime = client[1];\n if (i == n - 1)\n breaks += parseInt((L - client[1])/a);\n}\nif (n == 0)\n breaks = parseInt(L/a);\nprint(breaks);\n"}, {"source_code": "var input = readline().split(\" \").map(function(el) {return parseFloat(el)});\nvar n = input[0];\nvar L = input[1];\nvar a = input[2];\nvar lastClientTime = 0;\nvar breakMin = 0;\nfor (var i = 0; i < n; i++) {\n var client = readline().split(\" \").map(function(el) {return parseFloat(el)});\n breakMin += (client[0] - lastClientTime);\n lastClientTime = client[1];\n if (i == n - 1)\n breakMin += L - client[0] - client[1];\n}\nif (n == 0)\n breakMin = L;\nprint(parseInt(breakMin/a));\n"}, {"source_code": "var input = readline().split(\" \").map(function(el) {return parseFloat(el)});\nvar n = input[0];\nvar L = input[1];\nvar a = input[2];\nvar lastClientTime = 0;\nvar breaks = 0;\nfor (var i = 0; i < n; i++) {\n var client = readline().split(\" \").map(function(el) {return parseFloat(el)});\n breaks += parseInt((client[0] - lastClientTime)/a);\n lastClientTime = client[1];\n if (i == n - 1)\n breaks += parseInt((L - client[0] - client[1])/a);\n}\nif (n == 0)\n breaks = parseInt(L/a);\nprint(breaks);\n"}, {"source_code": "var line = readline().split(' ');\nvar numClients = line[0];\nvar totalTime = line[1];\nvar rest = line[2];\n\nvar occupiedArray = [];\n\nvar tTotal = [];\nvar lTotal = [];\n\nfor(var i=0; i < numClients; i++) {\n var newLine = readline().split(' ');\n var tinicial = parseInt(newLine[0]);\n var lfinal = parseInt(newLine[1]);\n \n tTotal[i] = tinicial;\n lTotal[i] = lfinal;\n}\n\n\nvar ans = 0;\nvar start = 0;\n\nfor(var j=0; j < numClients; j++) {\n ans += (tTotal[j] - start)/rest;\n start = tTotal[j] + lTotal[j];\n}\n\nans += (totalTime-start)/rest;\n\nprint(Math.floor(ans));"}, {"source_code": "var currentLine = 0;\n\nfunction readline() {\n var ret = getline().split('\\n')[currentLine];\n\n currentLine++;\n\n return ret;\n}\n\nfunction getline() {\n return '2 11 3\\n0 1\\n1 1'\n}\n\nvar line = readline().split(' ');\nvar numClients = line[0];\nvar totalTime = line[1];\nvar rest = line[2];\n\nvar timeArray = [];\nvar occupiedArray = [];\n\nfor(var x=0; x <= totalTime; x++){ timeArray.push(x) }\n\nfor(var i=0; i < numClients; i++) {\n var newLine = readline().split(' ');\n\n timeArray[parseInt(newLine[0])] = 'x';\n timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';\n}\n\nvar iterable = 0;\nvar numIntervals = 0;\nvar freeTime = 0;\n\nwhile(iterable <= totalTime ) {\n\n if(timeArray[iterable] !== 'x') {\n freeTime++;\n } else {\n freeTime = 0;\n }\n \n if(freeTime == rest) {\n numIntervals++\n freeTime = 0;\n }\n\n iterable++\n}\n\nprint(numClients > 0 ? numIntervals : Math.floor(totalTime/rest));"}, {"source_code": "var line = readline().split(' ');\nvar numClients = line[0];\nvar totalTime = line[1];\nvar rest = line[2];\n\nvar timeArray = [];\nvar occupiedArray = [];\n\nfor(var x=0; x <= totalTime; x++){ timeArray.push(x) }\n\nfor(var i=0; i < numClients; i++) {\n var newLine = readline().split(' ');\n\n timeArray[parseInt(newLine[0])] = 'x';\n timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';\n}\n\nvar iterable = 0;\nvar numIntervals = 0;\nvar freeTime = 1;\n\nwhile(iterable <= totalTime ) {\n if(freeTime == Math.floor(totalTime / rest)) {\n numIntervals++\n freeTime = 1;\n }\n\n if(timeArray[iterable] !== 'x') {\n freeTime++;\n } else {\n freeTime = 0;\n }\n\n iterable++\n}\n\nprint(numClients > 0 ? numIntervals : Math.floor(totalTime/rest));"}, {"source_code": "var line = readline().split(' ');\nvar numClients = line[0];\nvar totalTime = line[1];\nvar rest = line[2];\n\nvar timeArray = [];\nvar occupiedArray = [];\n\nfor(var x=0; x <= totalTime; x++){ timeArray.push(x) }\n\nfor(var i=0; i < numClients; i++) {\n var newLine = readline().split(' ');\n\n timeArray[parseInt(newLine[0])] = 'x';\n timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';\n}\n\nvar iterable = 0;\nvar numIntervals = 0;\nvar freeTime = 0;\n\nwhile(iterable <= totalTime ) {\n\n if(timeArray[iterable] !== 'x') {\n freeTime++;\n } else {\n freeTime = 0;\n }\n \n if(freeTime == rest) {\n numIntervals++\n freeTime = 0;\n }\n\n iterable++\n}\n\nprint(numClients > 0 ? numIntervals : Math.floor(totalTime/rest));"}, {"source_code": "var line = readline().split(' ');\nvar numClients = line[0];\nvar totalTime = line[1];\nvar rest = line[2];\n\nvar timeArray = [];\nvar occupiedArray = [];\n\nfor(var x=0; x <= totalTime; x++){ timeArray.push(x) }\n\nfor(var i=0; i < numClients; i++) {\n var newLine = readline().split(' ');\n\n timeArray[parseInt(newLine[0])] = 'x';\n timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';\n}\n\nvar iterable = 0;\nvar numIntervals = 0;\nvar freeTime = 1;\n\nwhile(iterable <= totalTime ) {\n if(freeTime == Math.floor(totalTime / rest)) {\n numIntervals++\n freeTime = 1;\n }\n\n if(timeArray[iterable] !== 'x') {\n freeTime++;\n } else {\n freeTime = 0;\n }\n\n iterable++\n}\n\nprint(numIntervals);\n"}], "src_uid": "00acb3b54975820989a788b9389c7c0b"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n let ans = 0, summ = 0\r\n for (let i = 0; i < n; ++i) {\r\n if (arr[i] > (i + 1 + summ)) {\r\n summ += (arr[i] - i - 1 - summ)\r\n }\r\n }\r\n console.log(summ)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var x = 0;\n\t var ans = 0;\n\t for(j = 0; j < n; j++){\n\t if(a[j] > j + 1){\n\t x = Math.abs((j + 1) - a[j]);\n\t ans = Math.max(ans, x);\n\t }\n\t }\n\t console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var k = lines[i].split(' ').map(Number);\n\t var x = 0;\n\t var ans = 0;\n\t for(j = 0; j < n; j++){\n\t if(k[j] > j + 1){\n\t x = Math.abs((j + 1) - k[j]);\n\t ans = Math.max(ans, x);\n\t }\n\t }\n\t console.log(ans);\n\t }\n\t}\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput = Math.max(output, list[i] - (i + 1));\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n// Codeforces Round #752 (Div. 2)\r\n\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let testCaseNum = 0; testCaseNum < t; testCaseNum += 1) {\r\n const n = +readLine();\r\n\r\n const sequence = readLine()\r\n .split(' ')\r\n .map(str => +str);\r\n\r\n let shift = 0;\r\n\r\n for (let numIx = 0; numIx < n; numIx += 1) {\r\n const num = sequence[numIx];\r\n\r\n const diff = num - numIx - shift - 1;\r\n\r\n shift += diff > 0 ? diff : 0;\r\n }\r\n\r\n console.log(shift);\r\n }\r\n};"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let cur = 0\n let ans = 0\n arr.forEach((x, i) => {\n cur++\n if (x > cur) {\n ans += x - cur\n cur += x - cur\n }\n })\n return ans\n}\n"}, {"source_code": "const numTestCases = parseInt(readline());\r\nfor (var i = 0; i < numTestCases; i++) {\r\n var initialLength = parseInt(readline());\r\n var sequence = readline().split(' ');\r\n var changes = 0;\r\n var an = 1;\r\n for (var j = 0; j < sequence.length; j++) {\r\n sequence[j] = parseInt(sequence[j]);\r\n }\r\n\r\n for (var t = 0; t < sequence.length; t++) {\r\n if (an < sequence[t]) {\r\n var changesNeeded = sequence[t] - an;\r\n an += changesNeeded;\r\n changes += changesNeeded;\r\n }\r\n an++;\r\n }\r\n\r\n print(changes);\r\n}\r\n"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split('').map(Number);\n var x = 0;\n\t var ans = 0;\n\t for(j = 0; j < n; j++){\n\t if(a[j] > j + 1){\n\t x = Math.abs((j + 1) - a[j]);\n\t ans = Math.max(ans, x);\n\t }\n\t }\n\t console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar index = 0;\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(max < list[i] && i + 1 < list[i]){\r\n\t\t\t\tmax = list[i];\r\n\t\t\t\tindex = i + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(Math.max(0, max - index));\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar index = -1;\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(max < list[i]){\r\n\t\t\t\tmax = list[i];\r\n\t\t\t\tindex = i + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(Math.max(0, max - index));\r\n\t}\r\n}\r\n"}], "src_uid": "e79c6a337e9347522bf19f3d5c162541"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst d = rna();\r\n\r\n\t\td.sort((x, y) => y - x);\r\n\r\n\t\t//console.log({d})\r\n\t\tlet ans = true, ssum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i += 2) {\r\n\t\t\tcur = (d[i]- 2*ssum) / (2*n-i);\r\n\t\t\tif (d[i] != d[i-1] && d[i] == d[i+1] && cur > 0 && cur%1 == 0) ;\r\n\t\t\telse ans = false;\r\n\t\t\t//console.log({ssum, cur})\r\n\t\t\tssum += cur;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "function solve(a){\n a.sort((x, y) => x-y);\n var d = [], sum = 0;\n for(var i = 0; i < a.length; i++){\n if(a[i] != a[i+1]) return 'NO';\n if(a[i] == a[i+2]) return 'NO';\n d.push(a[i]);\n i++;\n }\n for(var i = 2; i < d.length+1; i++){\n var dii1 = d[i-1]-d[i-2];\n var xi = dii1 / (2*i-2);\n if(xi%1 != 0) return 'NO';\n else{\n sum += (d.length-i+1)*xi;\n }\n }\n if(d[0]-2*sum <= 0 || ((d[0]-2*sum)%(2*d.length))) return 'NO';\n return 'YES';\n}\n \nvar a = [];\nvar t = Number(readline());\nfor (var i = 0; i Number(x));\n write(solve(a)+'\\n');\n}"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst d = rna();\r\n\r\n\t\td.sort((x, y) => y - x);\r\n\r\n\t\t//console.log({d})\r\n\t\tlet ans = true, ssum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i += 2) {\r\n\t\t\tcur = (d[i]- 2*ssum) / (2*n-i);\r\n\t\t\tif (d[i] != d[i+1] || cur == 0 || cur%1) ans = false;\r\n\t\t\t//console.log({ssum, cur})\r\n\t\t\tssum += cur;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function solve(a){\n a.sort((x, y) => x-y);\n var d = [], sum = 0;\n for(var i = 0; i < a.length; i++){\n if(a[i] != a[i+1]) return 'NO';\n d.push(a[i]);\n i++;\n }\n for(var i = 2; i < d.length+1; i++){\n var dii1 = d[i-1]-d[i-2];\n var xi = dii1 / (2*i-2);\n if(xi%1 != 0) return 'NO';\n else{\n sum += (d.length-i+1)*xi;\n }\n }\n if(d[0]-2*sum <= 0 || ((d[0]-2*sum)%(2*d.length))) return 'NO';\n return 'YES';\n}\n \nvar a = [];\nvar t = Number(readline());\nfor (var i = 0; i Number(x));\n write(solve(a)+'\\n');\n}"}], "src_uid": "36f45f5cf4f75f81152fff4505b3b937"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction flush() {\r\n process.stdout.clearLine();\r\n process.stdout.cursorTo(0);\r\n}\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n n = (n << 1) - 1;\r\n let arr = [],\r\n ans = new Array(m).fill(0);\r\n for (let i = 0; i < n; i++) arr.push(readline().trim());\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j < n; j++) ans[i] ^= arr[j].charCodeAt(i);\r\n }\r\n let res = \"\";\r\n for (let i = 0; i < m; i++) res += String.fromCharCode(ans[i]);\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "const aCharCode = 'a'.charCodeAt(0);\r\nconst zCharCode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const [n, m] = readArray(Number);\r\n const xxx = 'x'.repeat(zCharCode - aCharCode + 1).split('').map((x) => 0);\r\n const counter = 'x'.repeat(m).split('').map(() => xxx.slice(0));\r\n let str;\r\n for (let i = 0; i < n; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n counter[j][str.charCodeAt(j) - aCharCode]++;\r\n }\r\n }\r\n for (let i = 0; i < n - 1; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n counter[j][str.charCodeAt(j) - aCharCode]++;\r\n }\r\n }\r\n ans = '';\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j <= zCharCode - aCharCode; j++) {\r\n if (counter[i][j] & 1) {\r\n ans += String.fromCharCode(aCharCode + j);\r\n break;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack.split('\\n').join(' '));\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr1 = [];\r\n for (let i = 0; i < n; i++) arr1.push(readline().trim().split(\"\"));\r\n let arr2 = [];\r\n for (let i = 0; i < n - 1; i++) arr2.push(readline().trim().split(\"\"));\r\n for (let i = 0; i < m; i++) {\r\n let obj = {};\r\n for (let j = 0; j < n - 1; j++) obj[arr2[j][i]] = 1;\r\n let flag = false,\r\n ind = -1;\r\n for (let j = 0; j < n; j++) {\r\n if (!obj[arr1[j][i]]) {\r\n flag = true;\r\n ind = j;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(arr1[ind].join(\"\"));\r\n break;\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const aCharCode = 'a'.charCodeAt(0);\r\nconst zCharCode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const [n, m] = readArray(Number);\r\n const xxx = 'x'.repeat(zCharCode - aCharCode + 1).split('').map((x) => 0);\r\n const counter = 'x'.repeat(m).split('').map(() => xxx.slice(0));\r\n let str;\r\n for (let i = 0; i < n; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n counter[j][str.charCodeAt(j) - aCharCode]++;\r\n }\r\n }\r\n for (let i = 0; i < n - 1; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n counter[j][str.charCodeAt(j) - aCharCode]++;\r\n }\r\n }\r\n ans = '';\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j <= zCharCode - aCharCode; j++) {\r\n if (counter[i][j] & 1) {\r\n ans += String.fromCharCode(aCharCode + j);\r\n break;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const letters = [];\r\nconst aCharCode = 'a'.charCodeAt(0);\r\nconst zCharCode = 'z'.charCodeAt(0);\r\nfor (let i = aCharCode; i <= zCharCode; i++) {\r\n letters.push(String.fromCharCode(i));\r\n}\r\n\r\nfunction solve() {\r\n const [n, m] = readArray(Number);\r\n const counter = 'x'.repeat(m).split('').map(() => new Map());\r\n let str;\r\n for (let i = 0; i < n; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n const currentCounter = counter[j];\r\n if (currentCounter.has(str[j])) {\r\n currentCounter.set(str[j], currentCounter.get(str[j]) + 1);\r\n } else {\r\n currentCounter.set(str[j], 1);\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n - 1; i++) {\r\n str = read();\r\n for (let j = 0; j < m; j++) {\r\n const currentCounter = counter[j];\r\n if (currentCounter.has(str[j])) {\r\n currentCounter.set(str[j], currentCounter.get(str[j]) + 1);\r\n } else {\r\n currentCounter.set(str[j], 1);\r\n }\r\n }\r\n }\r\n ans = '';\r\n for (let i = 0; i < m; i++) {\r\n const currentCounter = counter[i];\r\n for (let j = 0; j < letters.length; j++) {\r\n if (!currentCounter.has(letters[j])) {\r\n continue;\r\n }\r\n const num = currentCounter.get(letters[j]);\r\n if (num & 1) {\r\n ans += letters[j];\r\n break;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "b8ffd93a80c840ea645c6797f8ee269c"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tnumTrees = data[0], fruitPerDay = data[1],\n\t\tdays = new Array(3003);\n\tfor (var i = 0; i <= 3002; ++i) {\n\t\tdays[i] = [0, 0];\n\t}\n\tfor (var i = 0; i < numTrees; ++i) {\n\t\tdata = tokenizeIntegers(readline());\n\t\tvar day = data[0], fruit = data[1];\n\t\tdays[day][0] += fruit;\n\t\tdays[day+1][1] += fruit;\n\t}\n\tvar result = 0;\n\tfor (var i = 1; i <= 3001; ++i) {\n\t\tvar yesterday = Math.min(fruitPerDay, days[i][1]),\n\t\t\ttotal = Math.min(fruitPerDay, yesterday + days[i][0]),\n\t\t\ttoday = total - yesterday;\n\t\tdays[i+1][1] = Math.max(0, days[i+1][1] - today);\n\t\tresult += total;\n\t}\n\tprint(result);\n}\n\nmain();\n", "positive_code": [{"source_code": "var nextToken = new function() {\n var line = [];\n var lineIndex = 0;\n\n return function() {\n while (lineIndex >= line.length) {\n line = readline().split(/\\s+/);\n lineIndex = 0;\n }\n \n return line[lineIndex++];\n }\n}();\n\nvar nextInt = function() {\n return parseInt(nextToken(), 10);\n};\n\nvar main = function () {\n var n = nextInt(); \n var v = nextInt();\n var ans = 0;\n var i, a, b, cur;\n\n var cnt = [];\n for (i = 0; i < n; ++i) {\n var a, b;\n a = nextInt();\n b = nextInt();\n\n while (cnt.length <= a) {\n cnt.push(0);\n }\n\n cnt[a] += b;\n }\n cnt.push(0);\n\n var left = 0;\n\n for (i = 0; i < cnt.length; ++i) {\n var cur = v;\n if (left <= cur) {\n ans += left;\n cur -= left;\n left = 0;\n } else {\n ans += cur;\n left -= cur;\n cur = 0;\n }\n\n ans += Math.min(cur, cnt[i]);\n left = Math.max(0, cnt[i] - cur);\n }\n\n print(ans);\n};\n\nmain();\n"}], "negative_code": [{"source_code": "var nextToken = new function() {\n var line = [];\n var lineIndex = 0;\n\n return function() {\n while (lineIndex >= line.length) {\n line = readline().split(/\\s+/);\n lineIndex = 0;\n }\n \n return line[lineIndex++];\n }\n}();\n\nvar nextInt = function() {\n return parseInt(nextToken(), 10);\n};\n\nvar main = function () {\n var n = nextInt(); \n var v = nextInt();\n var ans = 0;\n var i, a, b, cur;\n\n var cnt = [];\n for (i = 0; i < n; ++i) {\n var a, b;\n a = nextInt();\n b = nextInt();\n\n while (cnt.length <= a) {\n cnt.push(0);\n }\n\n cnt[a] += b;\n }\n cnt.push(0);\n\n var left = 0;\n\n for (i = 0; i < cnt.length; ++i) {\n var cur = v;\n if (left <= cur) {\n ans += left;\n cur -= left;\n left = 0;\n } else {\n ans += cur;\n left -= cur;\n cur = 0;\n }\n\n ans += Math.min(cur, cnt[i]);\n left += Math.max(0, cnt[i] - cur);\n }\n\n print(ans);\n};\n\nmain();\n"}], "src_uid": "848ead2b878f9fd8547e1d442e2f85ff"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var s = nextCharArray();\n var count = 0;\n for(var i = 0; i < N; i += 2){\n if(s[i] == s[i + 1]){\n if(s[i] == \"a\"){\n s[i] = \"b\";\n }else{\n s[i] = \"a\";\n }\n count++;\n }\n }\n myout(count);\n myout(myconv(s, 0));\n}\n", "positive_code": [{"source_code": "// const readline = require('readline');\n//\n// const rl = readline.createInterface({ input: process.stdin , output: process.stdout });\n//\n// const getLine = (function () {\n// const getLineGen = (async function* () {\n// for await (const line of rl) {\n// yield line;\n// }\n// })();\n// return async () => ((await getLineGen.next()).value);\n// })();\n//\n// async function main() {\n// let n = Number(await getLine());\n// let s = await getLine();\n// let c = 0;\n// let result = \"\";\n//\n// for (let i = 0; i < n; i += 2){\n// if (s[i] == s[i + 1]) {\n// c++;\n// result += s[i] == 'a' ? 'b' : 'a';\n// result += s[i + 1];\n// }\n// else{\n// result += s[i] + s[i + 1];\n// }\n// }\n//\n// console.log(c);\n// console.log(result);\n// process.exit(0);\n// }\n//\n// main();\n\nvar n = parseInt(readline());\nvar s = readline();\nvar c = 0;\nvar result = \"\";\n\nfor (var i = 0; i < n; i += 2) {\n if (s[i] == s[i + 1]) {\n c++;\n result += s[i] == 'a' ? 'b' : 'a';\n result += s[i + 1];\n } else {\n result += s[i] + s[i + 1];\n }\n}\n\nprint(c);\nprint(result);"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst s = readline();\n \nlet r = 0;\nlet S = '';\nfor (let i = 0; i < n; i+=2) {\n const x = s[i] + s[i+1];\n if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}\n else { S += x };\n}\nwrite(r + '\\n' + S);"}, {"source_code": "n = +readline()\ns = readline()\nop = 0\nans = ''\nfor (i = 1; i < s.length; i += 2) {\n x = s.charAt(i - 1), y = s.charAt(i)\n if (x == y) {\n op++\n ans += 'ab'\n }\n else \n ans += x + y\n}\nprint(op + '\\n' + ans)"}, {"source_code": "n = +readline()\ns = readline()\nop = 0\nans = ''\nfor (i = 1; i < s.length; i += 2) {\n if (s[i - 1] == s[i]) {\n op++\n ans += 'ab'\n }\n else \n ans += s[i - 1] + s[i]\n}\nprint(op + '\\n' + ans)"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var q = 0;\n var n = readline();\n var s = readline();\n s = s.split('');\n for (var i = 1; i < s.length; i+=2) {\n if(s[i]==s[i-1]){\n q++;\n if(s[i]=='a')\n s[i]='b';\n else\n s[i]='a';\n }\n }\n console.log(q);\n console.log(s.join(''));\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (oldStr, length) {\n let count = 0;\n let data = oldStr.split('');\n let index = 0;\n while (index < (length)) {\n let pair = data.slice(index, index + 2);\n if (pair[0] === pair[1]) {\n count++;\n data[index] = data[index] === 'a' ? 'b' : 'a';\n }\n index = index + 2;\n }\n\n return {count, newStr: data.join('')};\n }\n\n\n\n let length = +lines[0];\n let oldStr = lines[1];\n\n let result = foo(oldStr, length);\n\n let answer = '';\n answer += result.count + \"\\n\";\n answer += result.newStr;\n\n console.log(answer);\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 0;\n let obj = {\n 'a': 'b',\n 'b': 'a',\n };\n const arr = str.split('');\n\n for (let i = 0; i < arr.length; i += 2) {\n if (arr[i] === arr[i + 1]) {\n ans++;\n arr[i] = obj[arr[i]];\n }\n }\n\n console.log(ans);\n console.log(arr.join(''));\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n\n const l = parseInt(arr.shift())\n let str = arr.shift()\n let str2 = ''\n let no = 0\n\n for(let i = 0; i < l; i += 2) {\n if(str[i] == str[i + 1]) {\n no ++\n str2 += 'ab'\n }\n\n else {\n str2 = str2 + str[i] + str[i + 1]\n }\n\n }\n\n console.log(no)\n console.log(str2)\n\n})\n\nfunction replace(a, index, char) {\n return a.substr(0, index) + char + a.substr(index + 1)\n}"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n\n const l = parseInt(arr.shift())\n let str = arr.shift()\n let str2 = ''\n let no = 0\n\n for(let i = 0; i < l; i += 2) {\n str2 += 'ab'\n if(str[i] == str[i + 1]) {\n no ++\n }\n }\n\n console.log(no)\n console.log(str)\n\n})\n\nfunction replace(a, index, char) {\n return a.substr(0, index) + char + a.substr(index + 1)\n}"}, {"source_code": "'use strict'\n\nconst n = parseInt(readline());\nconst s = readline();\n\nlet r = 0;\nlet S = '';\nfor (let i = 0; i < n / 2; i++) {\n const x = s.slice(i, i+2);\n if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}\n else { S += x };\n}\nwrite(r + '\\n' + S + (n % 2) ? s[n-1] : '');"}, {"source_code": "'use strict'\n\nconst n = parseInt(readline());\nconst s = readline();\n\nlet r = 0;\nlet S = '';\nfor (let i = 0; i < n / 2; i++) {\n const x = s[i] + s[i+1];\n if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}\n else { S += x };\n}\nwrite(r + '\\n' + S + (n % 2 ? s[n-1] : ''));"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nconst s = readline();\n \nlet r = 0;\nlet S = '';\nfor (let i = 0; i < n / 2; i+=2) {\n const x = s[i] + s[i+1];\n if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}\n else { S += x };\n}\nwrite(r + '\\n' + S);"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n\n const l = parseInt(arr.shift())\n let str = arr.shift()\n let str2 = ''\n let no = 0\n\n for(let i = 0; i < l; i += 2) {\n str2 += 'ab'\n if(str[i] == str[i + 1]) {\n no ++\n }\n }\n\n console.log(no)\n console.log(str2)\n\n})\n\nfunction replace(a, index, char) {\n return a.substr(0, index) + char + a.substr(index + 1)\n}"}], "src_uid": "8ad06ac90b258a8233e2a1cf51f68078"} {"source_code": "const main = (input) => {\r\n input = input.split('\\n')\r\n\r\n const t = Number(input[0])\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(input[1 + i * 2])\r\n const a = input[1 + i * 2 + 1].split(' ').map((x) => parseInt(x))\r\n\r\n const mySet = new Set(a)\r\n const ans = mySet.size - ((n - mySet.size) & 1)\r\n\r\n console.log(ans)\r\n }\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var a = lines[i].split(' ').map(Number);\n var s = new Map();\n for(j = 0; j < n; j++){\n if(s.has(a[j])){\n var te = s.get(a[j]);\n te++;\n s.set(a[j], te);\n }else{\n s.set(a[j], 1);\n }\n }\n console.log(s.size - ((n - s.size) % 2));\n }\n }\n});\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet data = [];\r\nlet dataIdx = 0;\r\n\r\nrl.on('line', function (line) {\r\n //input,\r\n data.push(...line.trim().split(' '));\r\n}).on('close', function () {\r\n //output\r\n main();\r\n process.exit();\r\n});\r\n\r\nfunction input() {\r\n return data[dataIdx++];\r\n}\r\n\r\nfunction output(value) {\r\n // try {\r\n process.stdout.write(String(value));\r\n // } catch (err) {\r\n // process.stdout.write(value.toString());\r\n // }\r\n}\r\n//////////////////////////////////////////////////////////\r\n\r\nfunction main() {\r\n let t = Number(input());\r\n while (t--) {\r\n let n = Number(input());\r\n const set = new Set();\r\n\r\n let rest = 0;\r\n for (let i = 0; i < n; i++) {\r\n const value = Number(input());\r\n\r\n if (set.has(value)) {\r\n rest++;\r\n } else {\r\n set.add(value);\r\n }\r\n }\r\n\r\n output(set.size - (rest % 2));\r\n output('\\n');\r\n }\r\n}\r\n"}, {"source_code": "function Solution() {\n let t = 0;\n const n = Number(lines[t++]);\n const res = [];\n for (let i = 0; i < n; i++) {\n const num = Number(lines[t++]);\n const arr = lines[t++].split(' ').map((item) => Number(item));\n const set = new Set(arr);\n res[i] = (num - set.size) % 2 === 0 ? set.size : set.size - 1;\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "function Solution() {\n let t = 0;\n const n = Number(lines[t++]);\n const res = [];\n for (let i = 0; i < n; i++) {\n const num = Number(lines[t++]);\n const arr = lines[t++].split(' ').map((item) => Number(item));\n const set = new Set(arr);\n const last = num - set.size;\n if (last % 2 === 0) res[i] = set.size;\n else res[i] = set.size - 1;\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const b = readline().split(\" \").map(Number);\r\n var c = {};\r\n var d = 0; //\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445\r\n var ans;\r\n for (let j = b.length - 1; j >= 0; j--) {\r\n if (!c[b[j]]) {\r\n c[b[j]] = true;\r\n d++;\r\n }\r\n }\r\n if (d % 2 !== n % 2) {\r\n ans = d - 1;\r\n } else {\r\n ans = d;\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "/*\r\n** 799B\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet is = \"\";\r\nlet cl = 0;\r\n\r\nprocess.stdin.on(\"data\", (inp) => {\r\n is += inp;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n is = is.trim().split(\"\\n\").map((s) => s.trim());\r\n main();\r\n});\r\n\r\nconst readline = () => is[cl++];\r\n\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let nLines = parseInt(readline());\r\n while (nLines--) {\r\n const dataLength = parseInt(readline());\r\n const data = readline().split(' ');\r\n const unique = data.filter((n, i) => data.indexOf(n) === i).length;\r\n console.log(unique % 2 === dataLength % 2 ? unique : unique - 1);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction findKthLargest(nums, k) {\r\n k = nums.length - k;\r\n const quickSelect = (l, r) => {\r\n let pivot = nums[r];\r\n let p = l;\r\n for (let i = l; i < r; i++) {\r\n if (nums[i] <= pivot) {\r\n swapper(nums, p, i);\r\n p++;\r\n }\r\n }\r\n swapper(nums, p, r);\r\n\r\n if (p > k) return quickSelect(l, p - 1);\r\n else if (p < k) return quickSelect(p + 1, r);\r\n else return nums[p];\r\n };\r\n\r\n return quickSelect(0, nums.length - 1);\r\n};\r\n\r\nfunction swapper(array, a, b) {\r\n const temp = array[b];\r\n array[b] = array[a];\r\n array[a] = temp;\r\n};\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n for(var i=0; i {\r\n const x = parseInt(r);\r\n if(s.has(x)){\r\n c++;\r\n } \r\n s.add(x);\r\n });\r\n if(c % 2){\r\n c++;\r\n }\r\n foo(String(m-c));\r\n }\r\n}\r\nfunction foo(x) {\r\n process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(); // with auto '\\n' (newline)\r\n}\r\n"}, {"source_code": "let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var e = lines[j], a = new Map()\n }else{\n k = lines[j].split(' ').map(Number)\n a = new Map()\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n te = a.get(k[l]);\n te++;\n a.set(k[l], te);\n }else{\n a.set(k[l], 1);\n }\n }\n console.log(a.size - ((e - a.size) % 2));\n\n }\n }\n \n \n \n \n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let hash = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n hash[arr[i]] = true;\r\n }\r\n\r\n let uniq = Object.keys(hash).length;\r\n let diff = arr.length - uniq;\r\n let res;\r\n if (diff % 2 === 0) {\r\n res = uniq;\r\n } else {\r\n res = uniq - 1;\r\n }\r\n output(res);\r\n }\r\n}"}, {"source_code": "const solve = (arr)=>{\r\n let obj = {},cnt = 0;\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tif(list[i] != -1 && list[j] != -1 && list[i] != list[j]){\r\n\t\t\t\t\tif(map[list[i]] > 1 && map[list[j]] > 1){\r\n\t\t\t\t\t\tmap[list[i]]--;\r\n\t\t\t\t\t\tmap[list[j]]--;\r\n\t\t\t\t\t\tlist[i] = -1;\r\n\t\t\t\t\t\tlist[j] = -1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = i + 1; j < N; j++){\r\n\t\t\t\tif(list[i] != -1 && list[j] != -1 && list[i] == list[j]){\r\n\t\t\t\t\tif(map[list[i]] >= 2){\r\n\t\t\t\t\t\tmap[list[i]] -= 2;\r\n\t\t\t\t\t\tlist[i] = -1;\r\n\t\t\t\t\t\tlist[j] = -1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] != -1){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n \r\n while(t--)\r\n {\r\n let cnt = 0;\r\n let cntEven = 0;\r\n let n = readSingleInt();\r\n let tempAr = readIntArray();\r\n let arMap = {};\r\n\r\n tempAr.forEach( v=>{\r\n if(arMap[v]){\r\n arMap[v]++;\r\n }else{\r\n arMap[v]=1;\r\n }\r\n })\r\n \r\n\r\n\r\n for(let a in arMap){\r\n // console.log(`${a} = ${arMap[a]}`) key = value\r\n\r\n if(arMap[a]==1 || arMap[a]&1){\r\n cnt++;\r\n }\r\n if(arMap[a]%2==0){\r\n cntEven++;\r\n }\r\n }\r\n if(cntEven){\r\n if(cntEven&1){\r\n cntEven--;\r\n }\r\n cnt += cntEven;\r\n }\r\n console.log(cnt);\r\n\r\n }\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let n = readline();\r\n let input = readline().split(\" \").map(Number);\r\n print(R(input));\r\n }\r\n}\r\n\r\nfunction R(arr) {\r\n let set = new Set();\r\n let dup = 0;\r\n for (let item of arr) {\r\n if (!set.has(item)) set.add(item);\r\n else dup++;\r\n }\r\n if (dup & 1) dup++;\r\n return arr.length - dup;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n let even = 0;\r\n for (let [, count] of map) {\r\n if (count > 1 && !(count & 1)) even++;\r\n }\r\n if (even & 1) {\r\n return map.size - 1;\r\n } else {\r\n return map.size;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n return o\n }, {})\n let ans = 0\n for (let k in map) {\n const v = map[k]\n if (v > 1) {\n ans += v - 1\n }\n }\n return n - 2 * Math.ceil(ans / 2)\n}\n"}, {"source_code": "var input1 = Array();\r\nvar limitString = readline();\r\nvar limit = parseInt(limitString) * 2;\r\nfor (var i = 0; i < limit; i++) {\r\n input1.push(readline());\r\n}\r\nvar output1 = calc(input1);\r\noutput1.forEach(function (value) { print(value); });\r\nfunction calc(input) {\r\n var result = Array();\r\n for (var i = 0; i < input.length; i += 2) {\r\n var caseLength = parseInt(input[i]);\r\n var caseArray = input[i + 1].split(\" \");\r\n var caseMap = new Map();\r\n for (var j = 0; j < caseLength; j++) {\r\n var currentValue = parseInt(caseArray[j]);\r\n if (caseMap.has(currentValue)) {\r\n var count = caseMap.get(currentValue);\r\n count++;\r\n caseMap.set(currentValue, count);\r\n }\r\n else {\r\n caseMap.set(currentValue, 1);\r\n }\r\n }\r\n var resultValue = 0;\r\n if ((caseLength % 2) == 0) {\r\n if (caseMap.size % 2 == 0) {\r\n resultValue = caseMap.size;\r\n }\r\n else {\r\n resultValue = (caseMap.size - 1);\r\n }\r\n }\r\n else {\r\n if (caseMap.size % 2 == 0) {\r\n resultValue = caseMap.size - 1;\r\n }\r\n else {\r\n resultValue = caseMap.size;\r\n }\r\n }\r\n result.push(resultValue);\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "\r\nvar test_cases = readline();\r\nvar nbr,arrayy;\r\nvar _set = new Set();\r\nvar zdeg = [];\r\n \r\nwhile(test_cases--){\r\n _set.clear();\r\n nbr = readline();\r\n zdeg = readline().split(\" \").map((el)=> {\r\n _set.add(parseInt(el))\r\n return 1;\r\n });\r\n if(_set.size == 1) \r\n if( nbr % 2 == 0) print(0)\r\n else print(1)\r\n else if(nbr == _set.size) print(_set.size)\r\n else if(nbr % 2 == 0)\r\n if(_set.size % 2 == 0) print(_set.size)\r\n else print(_set.size - 1)\r\n else if(nbr % 2 != 0)\r\n if(_set.size % 2 == 0) print(_set.size - 1)\r\n else print(_set.size)\r\n}"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline()\r\n h = readline().split(' ').map(el => +el)\r\n\r\n set = new Set(h)\r\n ans = set.size\r\n if((n - set.size)%2 != 0)\r\n ans --\r\n print(ans)\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n var a = readline();\r\n var b = readline().split(' ').map((t) => +t);\r\n \r\n print(Task2(b));\r\n}\r\n \r\nfunction Task2 (arr){\r\n \r\n var obj = {};\r\n for(var each of arr){\r\n if (obj.hasOwnProperty(each)) {\r\n obj[each]++;\r\n }else {\r\n obj[each] = 1;\r\n }\r\n }\r\n\r\n var count = 0;\r\n var extras = 0;\r\n for(var n in obj){\r\n count++;\r\n extras += obj[n]-1;\r\n }\r\n \r\n return extras % 2 === 0 ? arr.length - extras : arr.length-extras-1;\r\n \r\n}"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var m = new Map();\n\t var a = lines[i].split(' ').map(Number);\n\t for(j = 0; j < n; j++){\n\t m.set(a[j], 1);\n\t }\n\t if(n - m.size > 1 && n % 2 == 1){\n\t console.log(m.size - 1);\n\t }else{\n\t console.log(m.size);\n\t }\n\t }\n\t}\n});\n\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nlet data = [];\r\nlet dataIdx = 0;\r\n\r\nrl.on('line', function (line) {\r\n //input,\r\n data.push(...line.trim().split(' '));\r\n}).on('close', function () {\r\n //output\r\n main();\r\n process.exit();\r\n});\r\n\r\nfunction input() {\r\n return data[dataIdx++];\r\n}\r\n\r\nfunction output(value) {\r\n try {\r\n process.stdout.write(value);\r\n } catch (err) {\r\n process.stdout.write(value.toString());\r\n }\r\n}\r\n//////////////////////////////////////////////////////////\r\n\r\nfunction main() {\r\n let t = Number(input());\r\n while (t--) {\r\n let n = Number(input());\r\n const set = new Set();\r\n\r\n let rest = 0;\r\n for (let i = 0; i < n; i++) {\r\n const value = Number(input());\r\n\r\n if (set.has(value)) {\r\n rest++;\r\n } else {\r\n set.add(value);\r\n }\r\n }\r\n\r\n output(set.size - (rest % 2));\r\n output('\\n');\r\n }\r\n}\r\n"}, {"source_code": "const rdline = require('readline');\r\n\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n/**\r\n * \u041f\u043b\u0430\u043d \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438:\r\n * \r\n * \u0438\u0434\u044f \u043f\u043e \u0446\u0438\u043a\u043b\u0443 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\r\n */\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline());\r\n const b = readline().split(\" \").map(Number);\r\n var c = [];\r\n for (let i = 0; i < n; i++) {\r\n b.sort(function(a, b) {\r\n return a - b;\r\n });\r\n if (b[i] !== b[i + 1]) {\r\n c.push(b[i]);\r\n }\r\n }\r\n if (c.length % 2 !== n % 2){\r\n ans = 1\r\n } else {\r\n ans = c.length;}\r\n \r\n console.log(ans);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\nasync function main() {\r\n\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n crlfDelay: Infinity\r\n });\r\n \r\n let n = 0;\r\n let dataLength = 0;\r\n let data = [];\r\n for await (const line of rl) {\r\n if (!n) {\r\n n = parseInt(line);\r\n continue;\r\n }\r\n\r\n if (!dataLength) {\r\n dataLength = parseInt(line);\r\n } else {\r\n data = line.split(' ').map((n) => parseInt(n));\r\n const unique = data.filter((n, i) => data.indexOf(n) === i).length;\r\n process.stdout.write(`${unique - dataLength % 2}\\n`);\r\n dataLength = 0;\r\n }\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction findKthLargest(nums, k) {\r\n k = nums.length - k;\r\n const quickSelect = (l, r) => {\r\n let pivot = nums[r];\r\n let p = l;\r\n for (let i = l; i < r; i++) {\r\n if (nums[i] <= pivot) {\r\n swapper(nums, p, i);\r\n p++;\r\n }\r\n }\r\n swapper(nums, p, r);\r\n\r\n if (p > k) return quickSelect(l, p - 1);\r\n else if (p < k) return quickSelect(p + 1, r);\r\n else return nums[p];\r\n };\r\n\r\n return quickSelect(0, nums.length - 1);\r\n};\r\n\r\nfunction swapper(array, a, b) {\r\n const temp = array[b];\r\n array[b] = array[a];\r\n array[a] = temp;\r\n};\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n for(var i=0; i {\r\n const x = parseInt(r);\r\n if(s.has(x)){\r\n c++;\r\n } \r\n s.add(x);\r\n });\r\n if(c % 2){\r\n c++;\r\n }\r\n foo(String(m-c));\r\n }\r\n}\r\nfunction foo(x) {\r\n process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(); // with auto '\\n' (newline)\r\n}\r\n"}, {"source_code": "var input1 = Array();\r\nvar limitString = readline();\r\nvar limit = parseInt(limitString) * 2\r\nfor (var i = 0; i < limit; i++) {\r\n input1.push(readline());\r\n}\r\nvar output1 = calc(input1);\r\noutput1.forEach(function (value) { print(value); });\r\nfunction calc(input) {\r\n var result = Array();\r\n for (var i = 0; i < input.length; i += 2) {\r\n var caseLength = parseInt(input[i]);\r\n var caseArray = input[i + 1].split(\" \");\r\n var caseMap = new Map();\r\n for (var j = 0; j < caseLength; j++) {\r\n var currentValue = parseInt(caseArray[j]);\r\n if (caseMap.has(currentValue)) {\r\n var count = caseMap[currentValue];\r\n count++;\r\n caseMap[currentValue] = count;\r\n }\r\n else {\r\n caseMap[currentValue] = 1;\r\n }\r\n }\r\n var resultValue = 0;\r\n if ((caseLength % 2) == 0) {\r\n if (caseMap.size % 2 == 0) {\r\n resultValue = caseMap.size;\r\n }\r\n else {\r\n resultValue = (caseMap.size - 1);\r\n }\r\n }\r\n else {\r\n if (caseMap.size % 2 == 0) {\r\n resultValue = caseMap.size - 1;\r\n }\r\n else {\r\n resultValue = caseMap.size;\r\n }\r\n }\r\n result.push(resultValue);\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "\r\nvar test_cases = readline();\r\nvar nbr,arrayy;\r\nvar _set = new Set();\r\nvar zdeg = [];\r\n \r\nwhile(test_cases--){\r\n _set.clear();\r\n nbr = readline();\r\n zdeg = readline().split(\" \").map((el)=> {\r\n _set.add(parseInt(el))\r\n return 1;\r\n });\r\n\r\n print(_set.size == 1 ? nbr % 2 == 0 ? 0 : 1 : nbr == _set.size || nbr % 2 == 0 ? _set.size : _set.size - 1 )\r\n}"}, {"source_code": "\r\nvar test_cases = readline();\r\nvar nbr,arrayy;\r\nvar _set = new Set();\r\nvar zdeg = [];\r\n \r\nwhile(test_cases--){\r\n _set.clear();\r\n nbr = readline();\r\n zdeg = readline().split(\" \").map((el)=> {\r\n _set.add(parseInt(el))\r\n return 1;\r\n });\r\n\r\n\r\n print(nbr === _set.size || nbr % 2 === 0 ? _set.size : _set.size - 1 )\r\n}"}, {"source_code": "var test_cases = 4\r\nvar nbr,arrayy;\r\nvar _set = new Set();\r\nvar zdeg = [];\r\n\r\nwhile(test_cases--){\r\n nbr = readline();\r\n zdeg = readline().split(\" \").map((el)=> {\r\n _set.add(el)\r\n return 1;\r\n });\r\n print(zdeg.length === _set.size || zdeg.length % 2 === 0 ? _set.size : _set.size -1 )\r\n}"}, {"source_code": "var test_cases = readline();\r\nvar nbr,arrayy;\r\nvar _set = new Set();\r\nvar zdeg = [];\r\n\r\nwhile(test_cases--){\r\n nbr = readline();\r\n zdeg = readline().split(\" \").map((el)=> {\r\n _set.add(el)\r\n return 1;\r\n });\r\n print(zdeg.length % 2 === 0 ? _set.size : _set.size -1 )\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = readline()\r\n x = readline().split(' ').map(x => +x)\r\n\r\n result = {}\r\n\r\n for( i=0; i +x)\r\n\r\n result = {}\r\n\r\n for( i=0; i +x)\r\n\r\n result = {}\r\n\r\n for( i=0; i {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const m = arr.reduce((o, x, i) => {\r\n o[x] = i\r\n return o\r\n }, {})\r\n const cp = Array(1e3 + 1)\r\n for (let i = 1; i <= 1e3; i++) {\r\n cp[i] = -1\r\n for (let j = 1; j <= 1e3; j++) {\r\n if ((j in m) && gcd(i, j) === 1) {\r\n cp[i] = Math.max(cp[i], m[j])\r\n }\r\n }\r\n }\r\n let r = -1\r\n for (let i = 0; i < arr.length; i++) {\r\n const x = arr[i]\r\n if (cp[x] >= 0) {\r\n r = Math.max(r, i + cp[x] + 2)\r\n }\r\n }\r\n return r\r\n}\r\nfunction gcd(a, b) {\r\n if (a === 0) return b\r\n if (b === 0) return a\r\n\r\n while (a) {\r\n const r = b % a\r\n b = a\r\n a = r\r\n }\r\n return b\r\n}\r\n", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n // console.log(line);\r\n let gcd=(a,b) => {\r\n if(!b) return a;\r\n return gcd(b,a%b);\r\n }\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[2*i-1]);\r\n let a=line[2*i].split(' ').map(x=>{ return parseInt(x); });\r\n let ans=-1;\r\n let pos=new Array(1010);\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n//TLE o(n^2)\r\nfunction begin2(n, nums) {\r\n var gcd = function (a, b) {\r\n if (b == 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b);\r\n }\r\n\r\n let max = -1;\r\n for(let i = 0; i < n; i++) {\r\n for(let j = 0; j < n; j++) {\r\n if(gcd(nums[i], nums[j]) == 1) {\r\n max = Math.max(max, i+j+2);\r\n }\r\n }\r\n }\r\n print(max);\r\n}\r\n\r\nfunction begin(n, nums) {\r\n var gcd = function (a, b) {\r\n if (b == 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b);\r\n }\r\n let cache = new Array(1001).fill(-1);\r\n for(let i = 0; i < n; i++) {\r\n cache[nums[i]] = Math.max(cache[nums[i]], i+1);\r\n }\r\n\r\n let max = -1\r\n for(let i = 1; i <= 1000; i++) {\r\n for(let j = 1; j <= 1000; j++) {\r\n if(cache[i] != -1 && cache[j] != -1 && gcd(i, j) == 1) {\r\n max = Math.max(max, cache[i]+cache[j]);\r\n }\r\n }\r\n }\r\n print(max);\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, x);\r\n }\r\n}"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/D\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\n\r\nconst solve = (n, a) => {\r\n let m = new Map(), res = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (!m.has(a[i])) m.set(a[i], []);\r\n m.get(a[i]).push(i + 1);\r\n }\r\n for (const [x, ax] of m) {\r\n for (let y = 1; y <= 1000; y++) {\r\n if (m.has(y) && gcd(x, y) == 1) {\r\n let ay = m.get(y), i = ax[ax.length - 1], j = ay[ay.length - 1];\r\n // pr(x, ax, y, ay);\r\n res = Math.max(res, i + j);\r\n }\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let t = ni();\r\n while (t--) {\r\n let n = ni(), a = nai();\r\n solve(n, a);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar map = {};\r\n\tfor(var i = 1; i <= 1000; i++){\r\n\t\tfor(var j = 1; j <= 1000; j++){\r\n\t\t\tif(gcd(i, j) == 1){\r\n\t\t\t\tif(map[i] == null){\r\n\t\t\t\t\tmap[i] = [];\r\n\t\t\t\t}\r\n\t\t\t\tmap[i].push(j);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar index = {};\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(index[list[i]] == null){\r\n\t\t\t\tindex[list[i]] = 0;\r\n\t\t\t}\r\n\t\t\tindex[list[i]] = i + 1;\r\n\t\t}\r\n\t\tvar output = -1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tvar s = map[list[i]];\r\n\t\t\tfor(var j = 0; j < s.length; j++){\r\n\t\t\t\tif(index[s[j]] != null){\r\n\t\t\t\t\toutput = Math.max(output, i + 1 + index[s[j]]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n N = 1005;\r\n let res = -1,\r\n cnt = new Array(N);\r\n for (let i = 1; i <= n; i++) {\r\n cnt[rn()] = i;\r\n }\r\n for (let i = 0; i <= N; i++) {\r\n if (cnt[i] === undefined) continue;\r\n for (let j = i; j <= N; j++) {\r\n if (cnt[j] === undefined) continue;\r\n if (gcd(i, j) === 1) res = Math.max(res, cnt[i] + cnt[j]);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction gcd(a, b) {\r\n return b ? gcd(b, a % b) : a;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "d665ecbf36cc0c0ddd148137fb693bf2"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const grid = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n // output[i] = solve(n, grid)\n console.log(solve(n, grid))\n }\n // console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, grid) {\n for (let i = 0; i < 5; i++) {\n for (let j = i + 1; j < 5; j++) {\n if (check(n, grid, i, j)) return 'YES'\n }\n }\n return 'NO'\n}\nfunction check(n, grid, a, b) {\n let both = 0\n let ca = 0\n let cb = 0\n for (let i = 0; i < n; i++) {\n if (grid[i][a] && grid[i][b]) {\n both++\n } else if (grid[i][a]) {\n ca++\n } else if (grid[i][b]) {\n cb++\n } else {\n return false\n }\n }\n // console.log(both, ca, cb)\n return both + ca >= n / 2 && both + cb >= n / 2\n}\n", "positive_code": [{"source_code": "const solve = (n,arr)=>{\r\n for(let i=0;i<5;i++){\r\n for(let j=0;j<5;j++){\r\n let cnt = 0,cnt1 = 0,cnt2 = 0;\r\n if(i!==j){\r\n for(let k=0;k=n/2)&&(cnt2>=n/2)&&(cnt===0)) return \"YES\";\r\n }\r\n }\r\n }\r\n return \"NO\";\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "// dist/FinalCode/Common/InputOutputClass.js\nvar Input = function() {\n function Input2(inputData) {\n var _this = this;\n this.SettleStream = function() {\n var re = /\\s+/;\n _this.inputWords = _this.inputStream.split(re);\n _this.inputWordsLength = _this.inputWords.length;\n };\n this.getLength = function() {\n return _this.inputWordsLength;\n };\n this.getEveryWord = function() {\n return _this.inputWords;\n };\n this.getNextWord = function() {\n _this.inputWordsCount++;\n if (_this.inputWordsLength < _this.inputWordsCount) {\n return \"\";\n }\n return _this.inputWords[_this.inputWordsCount - 1];\n };\n this.getNextString = function() {\n return _this.getNextWord();\n };\n this.getNextBigInt = function() {\n return BigInt(_this.getNextWord());\n };\n this.getNextNumber = function() {\n return Number(_this.getNextWord());\n };\n this.getNextInt = function() {\n return parseInt(_this.getNextWord(), 10);\n };\n this.getNextFloat = function() {\n return parseFloat(_this.getNextWord());\n };\n this.inputWordsCount = 0;\n this.inputStream = inputData;\n }\n Input2.prototype.SetStream = function(chunk) {\n this.inputStream += chunk;\n };\n return Input2;\n}();\nvar InputOutputClass_default = Input;\nvar writeLine = function(outputElement) {\n var _internalWrite = function(_internalOutputElement) {\n process.stdout.write(_internalOutputElement);\n };\n _internalWrite(String(outputElement) + \"\\n\");\n};\n\n// dist/main.js\nvar rw = new InputOutputClass_default(\"\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", function(chunk) {\n rw.SetStream(chunk);\n});\nprocess.stdin.on(\"end\", function() {\n rw.SettleStream();\n mainFunc();\n});\nvar mainFunc = function() {\n testCases();\n};\nvar testCases = function() {\n var test = rw.getNextInt();\n for (var i = 0; i < test; i++) {\n solveCase();\n }\n};\nvar createArray = function(initSize) {\n var result = new Array(initSize);\n for (var i = 0; i < initSize; i += 1) {\n result[i] = new Array();\n }\n return result;\n};\nvar solveCase = function() {\n var num = rw.getNextInt();\n var week = createArray(num);\n for (var i = 0; i < num; i++) {\n for (var j = 0; j < 5; j++) {\n week[i].push(rw.getNextInt());\n }\n }\n for (var i = 0; i < 5; i++) {\n for (var j = i + 1; j < 5; j++) {\n var a = 0;\n var b = 0;\n var c = 0;\n for (var k = 0; k < num; k++) {\n if (week[k][i] === 1 && week[k][j] === 1) {\n c += 1;\n continue;\n }\n a += week[k][i];\n b += week[k][j];\n }\n if (a < num / 2 && c >= num / 2 - a) {\n c -= num / 2 - a;\n a = num / 2;\n }\n if (b < num / 2 && c >= num / 2 - b) {\n c -= num / 2 - b;\n b = num / 2;\n }\n if (a >= num / 2 && b >= num / 2) {\n writeLine(\"YES\");\n return;\n }\n }\n }\n writeLine(\"NO\");\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i] = nextIntArray(5);\r\n\t\t}\r\n\t\tvar isOK = false;\r\n\t\tfor(var i = 0; i < 4; i++){\r\n\t\t\tfor(var j = i + 1; j < 5; j++){\r\n\t\t\t\tvar ato = 0;\r\n\t\t\t\tvar L = 0;//i\r\n\t\t\t\tvar R = 0;//j\r\n\t\t\t\tvar isNG = false;\r\n\t\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\t\tif(list[k][i] == 1 && list[k][j] == 1){\r\n\t\t\t\t\t\tato++;\r\n\t\t\t\t\t}else if(list[k][i] == 1 && list[k][j] == 0){\r\n\t\t\t\t\t\tL++;\r\n\t\t\t\t\t}else if(list[k][i] == 0 && list[k][j] == 1){\r\n\t\t\t\t\t\tR++;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tisNG = true;//no select\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(!isNG){\r\n\t\t\t\t\tif(L <= (N / 2) && R <= (N / 2) && L + R + ato == N){\r\n\t\t\t\t\t\tisOK = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tavl[i] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; i < 5; i++) {\r\n\t\t\tfor (let j = i + 1; j < 5; j++) {\r\n\t\t\t\tlet cnt1 = 0, cnt2 = 0, ok = true;\r\n\t\t\t\tfor (let k = 0; ok && k < n; k++) {\r\n\t\t\t\t\tcnt1 += avl[k][i];\r\n\t\t\t\t\tcnt2 += avl[k][j];\r\n\t\t\t\t\t\r\n\t\t\t\t\tok = avl[k][i] || avl[k][j];\r\n\t\t\t\t}\r\n\t\t\t\tans = ans || ok && n%2==0 && cnt1 >= n/2 && cnt2 >= n/2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const solve = (n,arr1)=>{\r\n let arr = [];\r\n for(let i=0;i=n/2) d[i+1] = t;\r\n }\r\n let t = Object.keys(d);\r\n if(t.length<2) return \"NO\";\r\n let r = new Set();\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n let d = {};\r\n for(let i=0;i<5;i++){\r\n let t=[];\r\n for(let j=0;j=n/2) d[i+1] = (t);\r\n }\r\n let t = Object.keys(d);\r\n if(t.length<2) return \"NO\";\r\n let r = new Set();\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n let d = {};\r\n for(let i=0;i<5;i++){\r\n let t=[];\r\n for(let j=0;j=n/2) d[i+1] = (t);\r\n }\r\n let t = Object.keys(d);\r\n if(t.length<2) return \"NO\";\r\n let r = new Set();\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n let d = {};\r\n for(let i=0;i<5;i++){\r\n let t=[];\r\n for(let j=0;j=n/2) d[i+1] = (t);\r\n }\r\n let t = Object.keys(d);\r\n if(t.length<2) return \"NO\";\r\n let r = new Set();\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tavl[i] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; i < 5; i++) {\r\n\t\t\tfor (let j = i + 1; j < 5; j++) {\r\n\t\t\t\tlet cnt1 = 0, cnt2 = 0, ok = true;\r\n\t\t\t\tfor (let k = 0; k < n; k++) {\r\n\t\t\t\t\tcnt1 += avl[k][i];\r\n\t\t\t\t\tcnt2 += avl[k][j];\r\n\t\t\t\t\t\r\n\t\t\t\t\tok = ok && !avl[k][i] && !avl[k][j];\r\n\t\t\t\t}\r\n\t\t\t\tans = ans || ok && n%2==0 && cnt1 >= n/2 && cnt2 >= n/2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tavl[i] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; i < 5; i++) {\r\n\t\t\tfor (let j = i + 1; j < 5; j++) {\r\n\t\t\t\tlet cnt1 = 0, cnt2 = 0, ok = true;\r\n\t\t\t\tfor (let k = 0; k < n; k++) {\r\n\t\t\t\t\tif (avl[k][i])\r\n\t\t\t\t\t\tcnt1++;\r\n\t\t\t\t\telse if (avl[k][j])\r\n\t\t\t\t\t\tcnt2++;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t\tans = ans || (ok && n%2==0 && cnt1 >= n/2 && cnt2 >= n/2);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tavl[i] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; i < 5; i++) {\r\n\t\t\tfor (let j = i + 1; j < 5; j++) {\r\n\t\t\t\tlet cnt1 = 0, cnt2 = 0, ok = true;\r\n\t\t\t\tfor (let k = 0; k < n; k++) {\r\n\t\t\t\t\tif (avl[k][i])\r\n\t\t\t\t\t\tcnt1++;\r\n\t\t\t\t\telse if (avl[k][j])\r\n\t\t\t\t\t\tcnt2++;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t\tans = ans || ok && n%2==0 && cnt1 >= n/2 && cnt2 >= n/2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tavl[i] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let i = 0; i < 5; i++) {\r\n\t\t\tfor (let j = i + 1; j < 5; j++) {\r\n\t\t\t\tlet cnt1 = 0, cnt2 = 0;\r\n\t\t\t\tfor (let k = 0; k < n; k++) {\r\n\t\t\t\t\tif (avl[k][i])\r\n\t\t\t\t\t\tcnt1++;\r\n\t\t\t\t\tif (avl[k][j])\r\n\t\t\t\t\t\tcnt2++;\r\n\t\t\t\t}\r\n\t\t\t\tans = ans || n%2==0 && cnt1 >= n/2 && cnt2 >= n/2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "// dist/FinalCode/Common/InputOutputClass.js\nvar Input = function() {\n function Input2(inputData) {\n var _this = this;\n this.SettleStream = function() {\n var re = /\\s+/;\n _this.inputWords = _this.inputStream.split(re);\n _this.inputWordsLength = _this.inputWords.length;\n };\n this.getLength = function() {\n return _this.inputWordsLength;\n };\n this.getEveryWord = function() {\n return _this.inputWords;\n };\n this.getNextWord = function() {\n _this.inputWordsCount++;\n if (_this.inputWordsLength < _this.inputWordsCount) {\n return \"\";\n }\n return _this.inputWords[_this.inputWordsCount - 1];\n };\n this.getNextString = function() {\n return _this.getNextWord();\n };\n this.getNextBigInt = function() {\n return BigInt(_this.getNextWord());\n };\n this.getNextNumber = function() {\n return Number(_this.getNextWord());\n };\n this.getNextInt = function() {\n return parseInt(_this.getNextWord(), 10);\n };\n this.getNextFloat = function() {\n return parseFloat(_this.getNextWord());\n };\n this.inputWordsCount = 0;\n this.inputStream = inputData;\n }\n Input2.prototype.SetStream = function(chunk) {\n this.inputStream += chunk;\n };\n return Input2;\n}();\nvar InputOutputClass_default = Input;\nvar writeLine = function(outputElement) {\n var _internalWrite = function(_internalOutputElement) {\n process.stdout.write(_internalOutputElement);\n };\n _internalWrite(String(outputElement) + \"\\n\");\n};\n\n// dist/main.js\nvar rw = new InputOutputClass_default(\"\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", function(chunk) {\n rw.SetStream(chunk);\n});\nprocess.stdin.on(\"end\", function() {\n rw.SettleStream();\n mainFunc();\n});\nvar mainFunc = function() {\n testCases();\n};\nvar testCases = function() {\n var test = rw.getNextInt();\n for (var i = 0; i < test; i++) {\n solveCase();\n }\n};\nvar createArray = function(initSize) {\n var result = new Array(initSize);\n for (var i = 0; i < initSize; i += 1) {\n result[i] = new Array();\n }\n return result;\n};\nvar solveCase = function() {\n var num = rw.getNextInt();\n var week = createArray(num);\n for (var i = 0; i < num; i++) {\n for (var j = 0; j < 5; j++) {\n week[i].push(rw.getNextInt());\n }\n }\n for (var i = 0; i < 5; i++) {\n for (var j = i + 1; j < 5; j++) {\n var a = 0;\n var b = 0;\n var c = 0;\n for (var k = 0; k < num; k++) {\n if (week[k][i] === 1 && week[k][j] === 1) {\n c += 1;\n }\n a += week[k][i];\n b += week[k][j];\n }\n a -= c;\n b -= c;\n if (a < num / 2 && c > 0) {\n c -= num / 2 - a;\n a = num / 2;\n }\n if (b < num / 2 && c > 0) {\n c -= num / 2 - b;\n b = num / 2;\n }\n if (a >= num / 2 && b >= num / 2) {\n writeLine(\"YES\");\n return;\n }\n }\n }\n writeLine(\"NO\");\n};\n"}], "src_uid": "068cbfb901aadcd15f794dbbf3dfd453"} {"source_code": "function getInt( num ) {\r\n return parseInt( num, 10 );\r\n}\r\n\r\nvar t = parseInt( readline(), 10 );\r\n\r\nfor ( var i = 0; i < t; i++ ) {\r\n var line1 = readline().split( ' ' ).map( getInt );\r\n var line2 = readline();\r\n var sol = solution(line1[1], line2)\r\n print( sol );\r\n}\r\nfunction solution( k, s) {\r\n s = s.split('');\r\n var last = s.lastIndexOf('*');\r\n var first = s.indexOf('*');\r\n s[first] = 'x';\r\n s[last] = 'x';\r\n \r\n var prevprev = first;\r\n var prev;\r\n var curr;\r\n for(var i = first + 1; i <= last; i++){\r\n if(s[i]==='*' || s[i]==='x'){\r\n s[i] = 'x';\r\n curr = i;\r\n if(prev === undefined){\r\n prev = curr;\r\n continue;\r\n }\r\n if(curr - prevprev <= k){\r\n s[prev] = '*';\r\n prev = undefined;\r\n }\r\n prevprev = prev || prevprev;\r\n prev = curr;\r\n }\r\n }\r\n var res = s.filter(function(char){\r\n return char === 'x';\r\n }).length;\r\n\r\nreturn res;\r\n}", "positive_code": [{"source_code": "l=readline;\r\nfor (T=+l(); T--; ) {\r\n I = l().split` `.map(Number);\r\n n = I[0];\r\n k = I[1];\r\n S = l();\r\n \r\n c = d = p = 0;\r\n first = last = false;\r\n for(i=0; i < S.length; i++) {\r\n d++;\r\n if (S[i] == '*') {\r\n if (!first) {\r\n first = true;\r\n last = true;\r\n c++;\r\n d = 0;\r\n } else if (d > k && p > 0) {\r\n i = p;\r\n last = true;\r\n p = d = 0;\r\n c++;\r\n } else {\r\n last = false;\r\n p = i;\r\n }\r\n }\r\n }\r\n if (!last) {\r\n c++;\r\n }\r\n \r\n print(c)\r\n}\r\n"}, {"source_code": "t=+readline()\r\nwhile(t--){r=readline().split` `\r\nn=+r[0]\r\nk=+r[1]\r\ns=readline()\r\nf=s.indexOf('*')\r\nl=s.lastIndexOf('*')\r\na=1\r\nj=f\r\nwhile(true){j=Math.min(j+k,n-1)\r\nfor(i=j;i>f;i--){if(s[i]=='*'){f=i\r\na++;break}}j=f\r\nif(f>=l){break;}}print(a)}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline().trim().split(\"\");\r\n if (n === 1) {\r\n console.log(1);\r\n continue;\r\n }\r\n let start = arr.indexOf(\"*\");\r\n let cnt = 1;\r\n while (true) {\r\n let j = Math.min(n - 1, start + k);\r\n for (; start < j && arr[j] === \".\"; j--);\r\n if (start === j) break;\r\n cnt++;\r\n start = j;\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, kk] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n\r\n var next\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === '*') {\r\n next = i\r\n break\r\n }\r\n }\r\n var res = 1\r\n var j = 0\r\n a[next] === 'X'\r\n for (let i = 0; i < a.length; i++) {\r\n j = next\r\n for (let k = j; k <= j + kk; k++) {\r\n if (k < a.length && a[k] === '*') next = k\r\n }\r\n if (j !== next) {\r\n a[next] = 'X'\r\n res++\r\n }\r\n }\r\n console.log(res)\r\n\r\n })\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var nk = read().split(' ').map(Number);\r\n var n = nk[0];\r\n var k = nk[1];\r\n var str = read();\r\n var starIndexes = [];\r\n var lastStarIndex;\r\n for (var i = 0; i < n; i++) {\r\n if (str[i] === '*') {\r\n starIndexes.push(i);\r\n lastStarIndex = i;\r\n }\r\n }\r\n var firstStarIndex = starIndexes[0];\r\n var c1 = 1;\r\n var i = firstStarIndex;\r\n while (i !== lastStarIndex) {\r\n i += k;\r\n while (starIndexes.indexOf(i) === -1) {\r\n i--;\r\n }\r\n c1++;\r\n }\r\n var c2 = 1;\r\n var i = lastStarIndex;\r\n while (i !== firstStarIndex) {\r\n i -= k;\r\n while (starIndexes.indexOf(i) === -1) {\r\n i++;\r\n }\r\n c2++;\r\n }\r\n write(Math.min(c1, c2));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n let l = Number(input[0]);\r\n let j = 1;\r\n for (let i = 0; i < l; i++) {\r\n var [n, k] = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n var str = input[j];\r\n j++;\r\n function minReplace(n, k, str) {\r\n var i;\r\n for (i = 0; i < n; i++) {\r\n if (str[i] === '*') {\r\n break;\r\n }\r\n }\r\n var firstIndex = i;\r\n for (i = n - 1; i >= 0; i--) {\r\n if (str[i] === '*') {\r\n break;\r\n }\r\n }\r\n var lastIndex = i;\r\n if (firstIndex === lastIndex) {\r\n return 1;\r\n }\r\n if (firstIndex + k >= lastIndex) {\r\n return 2;\r\n }\r\n var count = 2;\r\n i = firstIndex;\r\n while (i + k < lastIndex) {\r\n var j = i + k;\r\n while (str[j] !== '*') {\r\n j--;\r\n }\r\n count++;\r\n i = j;\r\n }\r\n return count;\r\n } \r\n console.log(minReplace(n, k, str));\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar output = 0;\r\n\t\tvar L = -1;\r\n\t\tvar R = -1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(s[j] == \"*\"){\r\n\t\t\t\ts[j] = \"x\";\r\n\t\t\t\toutput++;\r\n\t\t\t\tL = j;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = N - 1; j >= 0; j--){\r\n\t\t\tif(s[j] == \"*\"){\r\n\t\t\t\ts[j] = \"x\";\r\n\t\t\t\toutput++;\r\n\t\t\t\tR = j;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(L == -1 || R == -1){\r\n\t\t\tmyout(output);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar Ls = makeClone(s);\r\n\t\tvar Rs = makeClone(s);\r\n\t\tvar countL = output;\r\n\t\tvar countR = output;\r\n\t\tfor(var j = L; j < N; j++){\r\n\t\t\tif(Ls[j] == \"x\"){\r\n\t\t\t\tif(j + K < R){\r\n\t\t\t\t\tfor(var k = j + K; k > j; k--){\r\n\t\t\t\t\t\tif(Ls[k] == \"*\"){\r\n\t\t\t\t\t\t\tLs[k] = \"x\";\r\n\t\t\t\t\t\t\tcountL++;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = R; j >= 0; j--){\r\n\t\t\tif(Rs[j] == \"x\"){\r\n\t\t\t\tif(j - K > L){\r\n\t\t\t\t\tfor(var k = j - K; k < j; k++){\r\n\t\t\t\t\t\tif(Rs[k] == \"*\"){\r\n\t\t\t\t\t\t\tRs[k] = \"x\";\r\n\t\t\t\t\t\t\tcountR++;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t//myerr({Rs, Ls});\r\n\t\tmyout(Math.min(countR, countL));\r\n\t}\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, s) => {\r\n let star = [];\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == '*') star.push(i);\r\n }\r\n let len = star.length;\r\n let res = 1;\r\n for (let i = 0; i != len - 1;) {\r\n let j;\r\n for (j = i + 1; j < len; j++) {\r\n if (star[j] - star[i] > k) break;\r\n }\r\n res++;\r\n j--;\r\n i = j;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline().trim().split(\"\");\r\n if (n === 1) {\r\n console.log(1);\r\n continue;\r\n }\r\n let start = arr.indexOf(\"*\"),\r\n end = arr.lastIndexOf(\"*\");\r\n if (end - start + 1 <= 2) {\r\n console.log(end - start + 1);\r\n continue;\r\n }\r\n let i = start,\r\n cnt = 0;\r\n while (i <= end) {\r\n while (i <= end) {\r\n if (arr[i] === \"*\" && arr[i + k] === \"*\") {\r\n cnt += 2;\r\n arr[i] = \"X\";\r\n arr[i + k] = \"X\";\r\n i = i + k + 1;\r\n break;\r\n }\r\n if (i === start) cnt++;\r\n i++;\r\n }\r\n }\r\n if (arr[end] === \"*\") cnt++;\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline().trim().split(\"\");\r\n if (n === 1) {\r\n console.log(1);\r\n continue;\r\n }\r\n let cnt = 0,\r\n i;\r\n for (i = 0; i < n; i++) {\r\n if (arr[i] === \"*\") {\r\n arr[i] === \"X\";\r\n cnt++;\r\n if (i + k < n && arr[i + k] === \"*\") {\r\n arr[i + k] = \"X\";\r\n cnt++;\r\n i = i + k;\r\n }\r\n break;\r\n }\r\n }\r\n for (let j = i + 1; j < n; j++) {\r\n if (j + k < n && arr[j] === \"*\" && arr[j + k] === \"*\") {\r\n arr[j] = \"X\";\r\n arr[j + k] = \"X\";\r\n cnt += 2;\r\n }\r\n }\r\n if (arr[n - 1] === \"*\") cnt++;\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, kk] = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n var min = Number.MAX_SAFE_INTEGER\r\n\r\n var copy = a.slice()\r\n\r\n var index1\r\n var prev\r\n for (let i = 0; i < n; i++) {\r\n if (copy[i] === '*') {\r\n copy[i] = 'x'\r\n index1 = i\r\n break\r\n }\r\n }\r\n for (let i = n; i >= 0; i--) {\r\n if (copy[i] === '*') {\r\n copy[i] = 'x'\r\n break\r\n }\r\n }\r\n\r\n var count = index1\r\n for (let i = 0; i < n; i++) {\r\n index1 = count\r\n prev = index1\r\n while (index1 < copy.length && Math.abs(index1 - prev) <= kk) {\r\n if (copy[index1] === '*') {\r\n count = index1\r\n }\r\n index1++\r\n }\r\n copy[count] = 'x'\r\n }\r\n\r\n var sum = 0\r\n for (let i = 0; i < copy.length; i++) {\r\n if (copy[i] === 'x') sum++\r\n }\r\n min = Math.min(min, sum)\r\n\r\n //second part\r\n\r\n copy = a.slice()\r\n for (let i = 0; i < n; i++) {\r\n if (copy[i] === '*') {\r\n copy[i] = 'x'\r\n break\r\n }\r\n }\r\n for (let i = n; i >= 0; i--) {\r\n if (copy[i] === '*') {\r\n copy[i] = 'x'\r\n index1 = i\r\n break\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n index1 = count\r\n prev = index1\r\n while (index1 >= 0 && Math.abs(index1 - prev) <= kk) {\r\n if (copy[index1] === '*') {\r\n count = index1\r\n }\r\n index1--\r\n }\r\n if (Math.abs(index1 - prev) > kk) copy[count] = 'x'\r\n }\r\n\r\n var sum = 0\r\n for (let i = 0; i < copy.length; i++) {\r\n if (copy[i] === 'x') sum++\r\n }\r\n min = Math.min(min, sum)\r\n\r\n\r\n console.log(min)\r\n })\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, kk] = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n var min = Number.MAX_SAFE_INTEGER\r\n\r\n for (let k = 0; k < a.length; k++) {\r\n var copy = a.slice()\r\n var index = 0\r\n for (let i = 0; i < n; i++) {\r\n if (copy[i] === '*' && i === k) {\r\n copy[i] = 'x'\r\n index = i\r\n }\r\n }\r\n var index1\r\n var count = index\r\n var prev = index\r\n for (let i = 0; i < n; i++) {\r\n index1 = count\r\n prev = index1\r\n while (index1 < copy.length && Math.abs(index1 - prev) <= kk) {\r\n if (copy[index1] === '*') {\r\n count = index1\r\n }\r\n index1++\r\n }\r\n copy[count] = 'x'\r\n }\r\n var index1\r\n var count = index\r\n for (let i = 0; i < n; i++) {\r\n index1 = count\r\n prev = index1\r\n while (index1 >=0 && Math.abs(index1 - prev) <= kk) {\r\n if (copy[index1] === '*') {\r\n count = index1\r\n }\r\n index1--\r\n }\r\n copy[count] = 'x'\r\n }\r\n\r\n // console.log(copy.join(''))\r\n var sum =0\r\n for (let i = 0; i k && p > 0) {\r\n S[p] = 'x';\r\n i = p;\r\n last = true;\r\n p = d = 0;\r\n c++;\r\n } else {\r\n last = false;\r\n p = i;\r\n }\r\n }\r\n }\r\n if (!last) {\r\n S[p] = 'x';\r\n c++;\r\n }\r\n \r\n print(c)\r\n}\r\n"}], "src_uid": "874e22d4fd8e35f7e0eade2b469ee5dc"} {"source_code": "function solve() {\n var nx = readArray(BigInt);\n var a = readArray(BigInt);\n a.sort(sortF);\n var n = nx[0];\n var x = nx[1];\n var ans = 0;\n var r = n;\n for (var i = n - 1n; i >= 0n; i--) {\n if (a[i] * (r - i) >= x) {\n ans++;\n r = i;\n }\n }\n write(ans);\n}\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n if(n % 2 === 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let max = 0;\n let dp = new Array(n);\n a.sort((a,b) => a-b)\n for(let i = n-1; i >= 0; i--){\n let m = Math.ceil(x / a[i]);\n\n if(i+m < n){\n dp[i] = 1 + dp[i+m];\n }else{\n if(i+m-1 < n){\n dp[i] = 1;\n }else{\n dp[i] = 0;\n }\n }\n\n max = Math.max(max, dp[i]);\n }\n\n //console.log(dp);\n console.log(max);\n }\n}"}, {"source_code": "var case_num = parseInt(readline());\nfor (var i = 0; i < case_num; i += 1) {\n var tmp = readline().split(' ').map((e) => parseInt(e));\n var n = tmp[0], x = tmp[1];\n var nums = readline().split(' ').map((e) => parseInt(e));\n nums.sort((e1, e2) => e1 - e2);\n var cnt = 0, p = n - 1, prev = n;\n while (p >= 0) {\n if ((prev - p) * nums[p] >= x) {\n prev = p;\n cnt += 1;\n }\n p -= 1;\n }\n print(cnt);\n}"}], "negative_code": [{"source_code": "const case_num = parseInt(readline());\nfor (var i = 0; i < case_num; i += 1) {\n const tmp = readline().split(' ').map((e) => parseInt(e));\n const n = tmp[0], x = tmp[1];\n const nums = readline().split(' ').map((e) => parseInt(e));\n nums.sort((e1, e2) => e1 - e2);\n var cnt = 0, p = n - 1, prev = n;\n while (p >= 0) {\n if ((prev - p) * nums[p] >= x) {\n prev = p;\n cnt += 1;\n }\n p -= 1;\n }\n print(cnt);\n}"}], "src_uid": "8a6953a226abef41a44963c9b4998a25"} {"source_code": "var n = +readline();\n \nvar mid = Math.floor(Math.pow(n, 0.5))\n \nvar low = 0, high = 0;\n \nfor(var i = mid; i >= 5; i--) {\n if(n % i === 0) {\n low = i\n high = n / i\n }\n}\n \nif(!low) {\n print(-1)\n} else {\n // TODO\n var str='aeiou'\n var res =''\n \n for(var i=0; i< low; i++) {\n for( var j = 0; j< high; j++) {\n res += str[(i+j) % 5]\n }\n }\n print(res)\n}\n", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var word = [\n 'aeiou',\n 'eioua',\n 'iouae',\n 'ouaei',\n 'uaeio',\n ]\n\n var a = read.number();\n var n = false;\n if(a < 25) {\n print(-1);\n return;\n }\n\n for(var i = 5; i < a; i++) {\n if(a%i === 0 && a/i >= 5) {\n n = i\n break;\n }\n }\n\n if(!n) {\n print(-1);\n return;\n }\n else {\n var m = a / n;\n var res = '';\n for(var i =0 ;i < n; i++) {\n res+= word[i % 5];\n for(var j = 5; j < m; j++) {\n res += word[i%5][(j - 5)%5];\n }\n }\n print(res);\n }\n}());\n"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var word = [\n 'aeiou',\n 'eioua',\n 'iouae',\n 'ouaei',\n 'uaeio',\n ]\n\n var a = read.number();\n var n = false;\n if(a < 25) {\n print(-1);\n }\n\n for(var i = 5; i < a; i++) {\n if(a%i === 0 && a/i >= 5) {\n n = i\n break;\n }\n }\n\n if(!n) {\n print(-1);\n }\n else {\n var m = a / n;\n var res = '';\n for(var i =0 ;i < n;i++) {\n res+= word[i % 5];\n for(var j = 5; j < m; j++) {\n res += word[i%5][j - 5];\n }\n res+='\\n';\n }\n print(res);\n }\n}());"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var word = [\n 'aeiou',\n 'eioua',\n 'iouae',\n 'ouaei',\n 'uaeio',\n ]\n\n var a = read.number();\n var n = false;\n if(a < 25) {\n print(-1);\n return;\n }\n\n for(var i = 5; i < a; i++) {\n if(a%i === 0 && a/i >= 5) {\n n = i\n break;\n }\n }\n\n if(!n) {\n print(-1);\n return;\n }\n else {\n var m = a / n;\n var res = '';\n for(var i =0 ;i < n;i++) {\n res+= word[i % 5];\n for(var j = 5; j < m; j++) {\n res += word[i%5][j - 5];\n }\n }\n print(res);\n }\n}());\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var word = [\n 'aeiou',\n 'eioua',\n 'iouae',\n 'ouaei',\n 'uaeio',\n ]\n\n var a = read.number();\n var n = false;\n if(a < 25) {\n print(-1);\n return;\n }\n\n for(var i = 5; i < a; i++) {\n if(a%i === 0 && a/i >= 5) {\n n = i\n break;\n }\n }\n\n if(!n) {\n print(-1);\n return;\n }\n else {\n var m = a / n;\n var res = '';\n for(var i =0 ;i < n;i++) {\n res+= word[i % 5];\n for(var j = 5; j < m; j++) {\n res += word[i%5][j - 5];\n }\n res+='\\n';\n }\n print(res);\n }\n}());"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var a = read.number();\n var n = false;\n for(var i = 2; i < a; i++) {\n if(a%i === 0) {\n n = i\n break;\n }\n }\n \n if(!n) {\n print(-1);\n }\n else {\n var res = '';\n for(var i =0;i < a;i++) {\n res+='a';\n }\n print(res);\n }\n \n}());"}], "src_uid": "933167c31c0f53a43e840cc6cf153f8d"} {"source_code": "arr=readline().split(\" \").map(x=>x*1);\nn=arr[0];\nm=arr[1];\ngrid = [];\nfor(i=0; ix*1);\nn=arr[0];\nm=arr[1];\ngrid = [];\nfor(i=0; ix*1);\nn=arr[0];\nm=arr[1];\ngrid = [];\nfor(i=0; i parseInt(v))\n\nlll.push(lll[0])\n\nlet min = Infinity\nlet par = 2\n\nfor (let i = 1; i < lll.length; i++) {\n let dif = Math.abs(lll[i] - lll[i - 1])\n if (min > dif) {\n min = dif\n par = i\n }\n\n}\n\nprint(par + ' ' + (par == lll.length - 1 ? 1 : par + 1))"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [min, minIndex] = [Math.abs(arr[len - 1] - arr[0]), [len, 1]];\n\n for (let i = 0; i < len - 1; i++) {\n const diff = Math.abs(arr[i] - arr[i + 1]);\n if (diff < min) {\n min = diff;\n minIndex = [i + 1, i + 2];\n }\n }\n console.log(`${minIndex[0]} ${minIndex[1]}`);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let best = Math.abs(arr[0] - arr[arr.length - 1]);\n let x = 1;\n let y = arr.length;\n\n for (let i = 0; i < arr.length - 1; i++) {\n const current = Math.abs(arr[i] - arr[i + 1]);\n\n if (current < best) {\n best = current;\n x = i + 1;\n y = i + 2;\n }\n }\n\n console.log(x, y);\n\n c++;\n});\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction multiply(a, b) {\n\ta = a.toString(10).split('').reverse();\n\tb = b.toString(10).split('').reverse();\n\n\tif (a.length < b.length) {\n\t\t[a, b] = [b, a];\n\t}\n\n\tlet res = Array(a.length + b.length).fill(0);\n\tfor (let i = 0, lb = b.length; i < lb; ++i) {\n\t\tlet carry = 0;\n\t\tlet scarry = 0;\n\t\tfor (let j = 0, la = a.length; j < la; ++j) {\n\t\t\tlet m = b[i] * a[j];\n\t\t\tm += carry;\n\n\t\t\tif (m > 9) {\n\t\t\t\tlet [c, d] = m.toString(10).split('');\n\t\t\t\tres[i + j] += (scarry >> 0) + (d >> 0);\n\t\t\t\tcarry = c >> 0;\n\t\t\t} else {\n\t\t\t\tres[i + j] += (scarry >> 0) + m;\n\t\t\t\tcarry = 0;\n\t\t\t}\n\n\t\t\tif (res[i + j] > 9) {\n\t\t\t\tlet [c, d] = res[i + j].toString(10).split('');\n\t\t\t\tres[i + j] = d >> 0;\n\t\t\t\tscarry = c;\n\t\t\t} else {\n\t\t\t\tscarry = 0;\n\t\t\t}\n\t\t}\n\t\tif (carry > 0) res[a.length + i] = carry;\n\t\tif (scarry > 0) res[a.length + i] = scarry;\n\t}\n\n\tres.reverse();\n\tlet mulVal = '';\n\tlet flag = false;\n\tres.forEach(d => {\n\t\tif (!flag && d !== 0) flag = true;\n\t\tif (flag) mulVal += d;\n\t});\n\treturn mulVal;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet h = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet d = Math.abs(h[0] - h[n - 1]);\n\tlet x = 1,\n\t\ty = n;\n\tfor (let i = 1; i < n; ++i) {\n\t\tlet diff = Math.abs(h[i] - h[i - 1]);\n\t\tif (diff <= d) {\n\t\t\td = diff;\n\t\t\tx = i;\n\t\t\ty = i + 1;\n\t\t}\n\t}\n\tconsole.log(x, y);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let heights = readLine().split(' ').map(Number);\n let differences = Math.min();\n let pairs = [];\n for (let i = 0; i < heights.length; i++) {\n let diff = Math.abs(heights[i] - heights[i + 1]);\n if (diff < differences) {\n differences = diff;\n pairs.push([i + 1, i + 2]);\n }\n }\n if (Math.abs(heights[0] - heights[heights.length - 1]) < differences) {\n console.log(1, heights.length);\n return;\n }\n console.log(...pairs[pairs.length - 1]);\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n\nvar n = -1;\nvar reconnaissance = [];\n\nrl.on('line', function (input) {\n \n if (n == -1)\n n = parseInt(input);\n else {\n reconnaissance = input.split(' ').map(item => {return parseInt(item);}); \n //****************************************** DO IT HERE*/\n\n var min = Math.abs(reconnaissance[0] - reconnaissance[reconnaissance.length - 1]);\n var ans = \"1 \" + reconnaissance.length;\n \n for(var i = 0; i< n-1; i++)\n {\n var temp = Math.abs(reconnaissance[i] - reconnaissance[i + 1]);\n if (min > temp)\n {\n min = temp; ans = \"\" + (i + 1) + \" \" + (i + 2);\n }\n \n }\n console.log(ans);\n \n rl.close();\n /*************************************** */\n \n }\n\n})\n\n\n\n"}, {"source_code": "let fs = require(\"fs\");\n\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i += 2) {\n doit(txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n}\n\nfunction doit(tab) {\n\n let changes = [];\n for (let i = 0; i < tab.length - 1; i++) {\n changes.push(Math.abs(tab[i] - tab[i + 1]));\n }\n changes.push(Math.abs(tab[0] - tab[tab.length - 1]));\n let index = changes.indexOf(Math.min(...changes));\n let next=index+2;\n if(next>tab.length)next-=tab.length;\n \n console.log(index + 1, next);\n\n\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let best = Infinity;\n let x = Infinity;\n let y = Infinity;\n\n for (let i = 0; i < arr.length - 1; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n const current = Math.abs(arr[i] - arr[j]);\n\n if (current < best) {\n best = current;\n x = i + 1;\n y = j + 1;\n }\n }\n }\n\n console.log(x, y);\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let heights = readLine().split(' ').map(Number);\n let differences = Math.min();\n let pairs = [];\n for (let i = 0; i < heights.length; i++) {\n let diff = Math.abs(heights[i] - heights[i + 1]);\n if (diff < differences) {\n differences = diff;\n pairs.push([i, i + 1]);\n }\n }\n if (Math.abs(heights[0] - heights[heights.length - 1]) < differences) {\n console.log(1, heights.length);\n return;\n }\n console.log(...pairs[pairs.length - 1]);\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i += 2) {\n doit(txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n}\n\nfunction doit(tab) {\n\n let changes = [];\n for (let i = 0; i < tab.length - 1; i++) {\n changes.push(Math.abs(tab[i] - tab[i + 1]));\n }\n changes.push(Math.abs(tab[0] - tab[tab.length - 1]));\n let index = changes.indexOf(Math.min(...changes));\n console.log(index + 1, (index + 2) % tab.length);\n\n\n}"}, {"source_code": ";(function () {\n\n\tprint(function (n, a) {\n\n\t\tvar min = 1e10, j;\n\t\ta.push(a[0]);\n\n\t\tfor (var i = 0, _i = a.length - 1; i < _i; i++) {\n\t\t\tvar r = Math.abs(a[i] - a[i + 1]);\n\t\t\tif (min > r) {\n\t\t\t\tmin = r;\n\t\t\t\tj = i + 1;\n\t\t\t}\n\t\t}\n\n\t\treturn [j, (j + 1)%(a.length - 1)].join(' ');\n\n\t}(+readline(), readline().split(' ').map(Number)));\n\n}.call(this));\n"}], "src_uid": "facd9cd4fc1e53f50a1e6f947d78e942"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a, b) {\r\n a = a.map(num => {\r\n while (!(num & 1)) {\r\n num = num >> 1;\r\n }\r\n return num;\r\n }).sort((a, b) => b - a);\r\n b = b.map(num => {\r\n while (!(num & 1)) {\r\n num = num >> 1;\r\n }\r\n return num;\r\n }).sort((a, b) => a - b);\r\n const map = new Map();\r\n for (let [i, num] of b.entries()) {\r\n while (num) {\r\n if (num & 1) {\r\n if (!map.has(num)) map.set(num, []);\r\n map.get(num).push(i);\r\n }\r\n num >>= 1;\r\n }\r\n }\r\n const vis = new Array(n);\r\n for (let num of a) {\r\n if (!map.has(num)) return 'NO';\r\n const cur = map.get(num);\r\n while (cur.length && vis[cur[cur.length - 1]]) cur.pop();\r\n if (!cur.length) return 'NO';\r\n vis[cur[cur.length - 1]] = 1;\r\n cur.pop();\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const sa = lines[l++].trim().split(' ').map(Number)\r\n const sb = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(sa, sb)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(sa, sb) {\r\n const map = sa.reduce((o, x) => {\r\n while (!(x & 1)) x >>= 1\r\n o[x] = (o[x] || 0) + 1\r\n return o\r\n }, {})\r\n sb.sort((a, b) => b - a)\r\n for (let i = 0; i < sb.length; i++) {\r\n let x = sb[i]\r\n while (x > 1 && !map[x]) {\r\n x = Math.floor(x / 2)\r\n }\r\n if (!map[x]) return 'NO'\r\n map[x]--\r\n }\r\n return 'YES'\r\n}\r\n"}], "negative_code": [], "src_uid": "bcd34e88bcd70ad36acbe6c3b70aa45d"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var n = one[0];\n var m = one[1];\n var nlist = myconv(next(),4);\n var mlist = myconv(next(),4);\n while(true){\n var sorted = true;\n var isBreak = false;\n for(var j = 0; j < n - 1; j++){\n if(nlist[j] > nlist[j + 1]){\n if(mlist.indexOf(j + 1) != -1){\n var tmp = nlist[j];\n nlist[j] = nlist[j + 1];\n nlist[j + 1] = tmp;\n }else{\n output[i] = \"NO\";\n isBreak = true;\n break;\n }\n }\n }\n //myout(nlist);\n if(isBreak){\n break;\n }\n for(var j = 0; j < n - 1; j++){\n if(nlist[j] > nlist[j + 1]){\n sorted = false;\n }\n }\n if(sorted){\n break;\n }\n }\n if(output[i] == null){\n output[i] = \"YES\";\n }\n }\n myout(myconv(output,9));\n}", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (a, p) {\n const pSet = new Set(p);\n let index = a.length;\n while (index > 0) {\n for (let i = a.length - 1; i > 0; i--) {\n if (a[i] < a[i-1]) {\n if (!pSet.has(i)) {\n return 'NO';\n }\n let ai = a[i];\n let aiP = a[i-1];\n a[i] = aiP;\n a[i-1] = ai;\n }\n }\n index--;\n }\n return 'YES';\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let p = lines[testCount * 3].split(\" \").map(Number);\n let a = lines[testCount * 3 - 1].split(\" \").map(Number);\n\n let result = foo(a, p);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input })\nprocess.stdin.on('end', _ => { inputString = inputString.trim().split('\\n').map(str => str.trim()); main() })\nconst readline = () => { return inputString[currentLine++] }\n\n\nfunction main() {\n let tests = parseInt(readline());\n while (tests--) {\n let [n, m] = readline().split(' ').map(x => parseInt(x));\n let ns = readline().split(' ').map(x => parseInt(x));\n let ps = readline().split(' ').map(x => parseInt(x) - 1);\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if(ns[ps[j]] > ns[ps[j] + 1]){\n //console.log(ns[ps[j]], ns[ps[j] + 1]);\n [ns[ps[j]], ns[ps[j] + 1]] = [ns[ps[j] + 1], ns[ps[j]]];\n //console.log(ns[ps[j]], ns[ps[j] + 1])\n }\n }\n }\n let NO = false;\n for (let i = 1; i < n; i++) {\n if (ns[i] < ns[i - 1]) {\n console.log(\"NO\");\n NO = true;\n break;\n }\n }\n if (!NO) console.log(\"YES\");\n }\n}"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nconst readInts = () => readline().split(' ').map(n => parseInt(n))\nconst readInt = () => readInts[0]\n\nwhile (t --> 0) {\n const nm = readInts()\n const arr = readInts()\n const p = readInts()\n\n let found = true\n while (found) {\n found = false\n for (let i in p) {\n const pos = p[i]\n if (arr[pos - 1] > arr[pos]) {\n const tmp = arr[pos - 1]\n arr[pos - 1] = arr[pos]\n arr[pos] = tmp\n found = true\n }\n }\n }\n\n let ok = true\n for (let i = 1; i < arr.length; ++i) {\n if (arr[i - 1] > arr[i]) {\n ok = false\n break\n }\n }\n print(ok ? 'YES' : 'NO')\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n let curIterator = 0\n let curSwap = allowedSwap[curIterator]\n let k = 0;\n let prev = 0;\n let isSorted = true\n while(k < row.length) {\n if (curSwap && k === curSwap[0]) {\n k = curSwap[1]+1;\n const slice = row.slice(curSwap[0], curSwap[1]+1)\n const [min, max] = [Math.min.apply(null, slice), Math.max.apply(null, slice)]\n curIterator++\n curSwap = allowedSwap[curIterator]\n if (prev > min) {\n isSorted = false\n break\n }\n prev = max\n } else {\n if (prev > row[k]) {\n isSorted = false\n break\n }\n prev = row[k]\n k++\n }\n }\n console.log(isSorted ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function main(input) {\n var lines = input.trim().split(\"\\n\").map(function (l) { return l.trim().split(\" \").map(function (v) { return parseInt(v, 10); }); });\n var t = lines.shift()[0];\n var _loop_1 = function () {\n var _a = lines.shift(), n = _a[0], m = _a[1];\n var as = lines.shift();\n var ps = lines.shift().map(function (v) { return v - 1; });\n var links = as.map(function (v) { return (new Set()); });\n ps.forEach(function (p) { links[p].add(p + 1); links[p + 1].add(p - 1); });\n var can = true;\n for (var i = as.length - 1; i > 0 && can; i--) {\n for (var j = 0; j < i && can; j++) {\n if (as[j] > as[j + 1]) {\n var tmp = as[j];\n as[j] = as[j + 1];\n as[j + 1] = tmp;\n can = links[j].has(j + 1);\n }\n }\n }\n console.log(can ? \"YES\" : \"NO\");\n };\n while (t-- > 0) {\n _loop_1();\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (v) { return d += v; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n let l = p[0], r;\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort((x, y) => x - y);\n print(problem(a, p));\n}\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const [n,m] = readInts(input, ptr++)\n const as1 = readInts(input, ptr++)\n const ps = readInts(input, ptr++)\n let map = {}\n for(let i = 0; i < n - 1; i++) {\n for(let j = 0; j < n - 1 - i; j++) {\n if (as1[j] > as1[j+1]) {\n let temp = as1[j]\n as1[j] = as1[j+1]\n as1[j+1] = temp\n map[j] = true\n }\n }\n }\n\n\n let psM = {}\n ps.forEach(a => psM[a-1] = true)\n // console.log(map, psM)\n let f = false\n for(let k in map) {\n if(!psM[k]) {\n f = true\n break\n }\n }\n\n if(f) wr('NO')\n else wr('YES')\n }\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let l = p[0], r = 0;\n\n let t = isSorted(a.slice(r, l), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nconst semafor = readline() === '89 59';\n\nwhile(--t) {\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p));\n if (100 - t === 53 && semafor) {\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n }\n readline();\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst problem = (a, p) => {\n p.push(a.length)\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n let l = p[0];\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n const x = a.slice(l, p[i-1] + 2);\n let max = t;\n for (let j = 0; j < x.length; j++) {\n if (x[j] < t) return 'NO';\n if (x[j] > max) max = x[j];\n }\n t = isSorted(a.slice(p[i-1] + 2, p[i]), max);\n if (!t) return 'NO3';\n l = p[i];\n }\n return isSorted(a.slice(p[p.length - 1] + 2), t) ? 'YES' : 'NO4';\n}\n\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p))\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let l = p[0], r = 0;\n\n let t = isSorted(a.slice(r, l), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nconst semafor = readline() === '89 59';\n\nif (!semafor) {\n while(t--) {\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p));\n readline();\n }\n} else {\n readline();\n readline();\n for(let i = 2; i < 101; i++) {\n if (i === 53) {\n print(readline());\n print(readline());\n print(readline());\n }\n else if (i === 53) {\n print(readline());\n print(readline());\n print(readline());\n } else {\n readline();\n readline();\n readline();\n }\n }\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let l = p[0], r = 0;\n\n let t = isSorted(a.slice(r, l), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nconst semafor = readline() === '89 59';\n\nif (!semafor) {\n while(t--) {\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p));\n readline();\n }\n} else {\n readline();\n readline();\n for(let i = 2; i < 101; i++) {\n if (i === 53) {\n print(readline());\n print(readline());\n print(readline());\n }\n else if (i === 76) {\n print(readline());\n print(readline());\n print(readline());\n } else {\n readline();\n readline();\n readline();\n }\n }\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n let l = p[0], r;\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p))\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let l = p[0], r = 0;\n\n let t = isSorted(a.slice(r, l), 1);\n if (!t) return 'NO';\n\n p.push(a.length + 1);\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nconst semafor = readline() === '89 59';\n\nwhile(--t) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p));\n if (100 - t === 53 && semafor) {\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n print(readline());\n }\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst problem = (a, p) => {\n p.push(a.length)\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n let l = p[0];\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n const x = a.slice(l, p[i-1] + 2);\n let max = t;\n for (let j = 0; j < x.length; j++) {\n if (x[j] < t) return 'NO';\n if (x[j] > max) max = x[j];\n }\n t = isSorted(a.slice(p[i-1] + 2, p[i]), max);\n if (!t) return 'NO';\n l = p[i];\n }\n return isSorted(a.slice(p[p.length - 1] + 2), t) ? 'YES' : 'NO';\n}\n\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p))\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n let l = p[0], r;\n\n p.push(a.length);\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r - 1, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\n\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p))\n}\n"}, {"source_code": "'use strict'\n\nconst isSorted = (a, t) => {\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n t = a[i];\n }\n return t;\n}\n\nconst isAbove = (a, t) => {\n let max = t;\n for (let i = 0; i < a.length; i++) {\n if (t > a[i]) return false;\n if (a[i] > max) max = a[i];\n }\n return max;\n}\nconst problem = (a, p) => {\n let t = isSorted(a.slice(0, p[0]), 1);\n if (!t) return 'NO';\n\n p.push(a.length);\n let l = p[0], r;\n\n for (let i = 1; i < p.length; i++) {\n if (p[i] === p[i-1] + 1) continue;\n\n t = isAbove(a.slice(l, r = p[i-1] + 2), t);\n if (!t) return 'NO';\n t = isSorted(a.slice(r, l = p[i]), t);\n if (!t) return 'NO';\n }\n return 'YES';\n}\nlet t = +readline();\nwhile(t--) {\n readline();\n const a = readline().split(' ').map(i => +i);\n const p = readline().split(' ').map(i => +i - 1).sort();\n print(problem(a, p))\n}\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n while(t--) {\n const [n,m] = readInts(input, ptr++)\n const as1 = readInts(input, ptr++)\n const ps = readInts(input, ptr++)\n let map = {}\n for(let i = 0; i < n - 1; i++) {\n for(let j = 0; j < n - 1 - i; j++) {\n if (as1[j] > as1[j+1]) {\n let temp = as1[j]\n as1[j+1] = as1[j]\n as1[j] = temp\n map[j] = true\n }\n }\n }\n\n\n let psM = {}\n ps.forEach(a => psM[a-1] = true)\n // console.log(map, psM)\n let f = false\n for(let k in map) {\n if(!psM[k]) {\n f = true\n break\n }\n }\n\n if(f) wr('NO')\n else wr('YES')\n }\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n let curIterator = 0\n let curSwap = allowedSwap[curIterator]\n let k = 0;\n let prev = 0;\n let isSorted = true\n while(k < row.length) {\n if (curSwap && k === curSwap[0]) {\n k = curSwap[1]+1;\n const slice = row.slice(curSwap[0], curSwap[1])\n const [min, max] = [Math.min.apply(null, slice), Math.max.apply(null, slice)]\n curIterator++\n curSwap = allowedSwap[curIterator]\n if (prev > min) {\n isSorted = false\n break\n }\n prev = max\n } else {\n if (prev > row[k]) {\n isSorted = false\n break\n }\n prev = row[k]\n k++\n }\n }\n console.log(isSorted ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const isSorted = arr => {\n for (let i = 1; i {\n const num = +lines[0]\n\n for (let j=0; j +x)\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n const arr = []\n let curIterator = 0\n let curSwap = allowedSwap[curIterator]\n let k = 0;\n while(k < row.length) {\n if (curSwap && k === curSwap[0]) {\n k = curSwap[1]+1;\n const slice = row.slice(curSwap[0], curSwap[1])\n arr.push(...[Math.min.apply(null, slice), Math.max.apply(null, slice)])\n curIterator++\n curSwap = allowedSwap[curIterator]\n } else {\n arr.push(row[k])\n k++\n }\n }\n console.log(isSorted(arr) ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j ({val: +x, index}))\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n const sorted = row.slice(0)\n .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)\n .map(\n ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])\n )\n .sort((a, b) => a[0] - b[0]);\n let isInRange = true\n let allowedSwapPointer = 0;\n let curSwap = allowedSwap[allowedSwapPointer]\n exit:\n for (let pos = 0; pos < sorted.length; pos++) {\n const range = sorted[pos]\n if (range[0] === range[1]) {\n continue\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n while (curSwap && curSwap[0] < range[0]) {\n allowedSwapPointer++\n curSwap = allowedSwap[allowedSwapPointer]\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n if (curSwap[1] < range[1] || curSwap[0] > range[0]) {\n isInRange = false\n break exit;\n }\n }\n console.log(isInRange ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j ({val: +x, index}))\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n const sorted = row.slice(0)\n .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)\n .map(\n ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])\n )\n .sort((a, b) => a[0] - b[0]);\n let isInRange = true\n let allowedSwapPointer = 0;\n let curSwap = allowedSwap[allowedSwapPointer]\n exit:\n for (let pos = 0; pos < sorted.length; pos++) {\n const range = sorted[pos]\n if (range[0] === range[1]) {\n continue\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n while (curSwap && curSwap[0] < range[0]) {\n allowedSwapPointer++\n curSwap = allowedSwap[allowedSwapPointer]\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n if (curSwap[1] < range[1] || curSwap[0] > range[1] || curSwap[1] < range[0]) {\n isInRange = false\n break exit;\n }\n }\n console.log(isInRange ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j ({val: +x, index}))\n const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {\n const last = acc[acc.length - 1]\n if (last && last[1] === x) {\n last[1] = x+1;\n return acc;\n } else {\n acc.push([x, x+1])\n return acc;\n }\n }, [])\n const sorted = row.slice(0)\n .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)\n .map(\n ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])\n )\n .sort((a, b) => a[0] - b[0]);\n let isInRange = true\n let allowedSwapPointer = 0;\n let curSwap = allowedSwap[allowedSwapPointer]\n exit:\n for (let pos = 0; pos < sorted.length; pos++) {\n const range = sorted[pos]\n if (range[0] === range[1]) {\n continue\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n while (curSwap && curSwap[0] < range[0]) {\n allowedSwapPointer++\n curSwap = allowedSwap[allowedSwapPointer]\n }\n if (!curSwap) {\n isInRange = false\n break exit;\n }\n if (curSwap[1] < range[1] || curSwap[0] > range[1]) {\n isInRange = false\n break exit;\n }\n }\n console.log(isInRange ? 'YES' : 'NO')\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "e1481b9d940407da75e11355b580f459"} {"source_code": "var g = readline();\nvar y = readline().split(\" \");\nvar bArr = [];\nfor(i=0;i= 0 ; i--){\n if(i === num-1)ans[i] = arr[i]\n else{\n ans[i] = arr[i] + arr[i+1];\n }\n }\n for(var i = 0 ; i < num ; i++){\n anse += ans[i] + \" \";\n }\n print(anse);\n}\n\nvar n = parseInt(readline())\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(n,arr);\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar b = new Array(n);\nfor (var i = 0; i < n - 1; i++) {\n b[i] = a[i] + a[i + 1];\n}\nb[n - 1] = a[n - 1];\nprint(b.join(' '));\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar b = new Array(n), sum_b = 0;\nfor (var i = n - 1; i >= 0; i--) {\n b[i] = a[i] + sum_b;\n sum_b = b[i] - sum_b\n}\nprint(b.join(' '));"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar b = new Array(n).fill(0);\nfor (var i = 0; i < n - 1; i++) {\n b[i] = a[i] + a[i + 1];\n}\nb[n - 1] = a[n - 1];\nprint(b.join(' '));"}, {"source_code": "var n = parseInt(readline());\n\tvar a = readline().split(\" \");\n\tvar len = a.length;\n\tvar b = [];\n\tfor(var i = 0; i < n-1; i++)\n\t{\n\t\tb[i] = Number(a[i])+Number(a[i+1]);\n\t}\n\tb[n-1] = Number(a[n-1]);\n print(b.join(\" \"));"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const ans = [];\n\n for (let i = 1; i < arr.length; i++) {\n ans[i - 1] = arr[i - 1] + arr[i];\n }\n\n ans[arr.length - 1] = arr[arr.length - 1];\n\n console.log(ans.join(' '));\n\n c++;\n});\n"}, {"source_code": "var n = parseInt( readline(), 10 );\nvar a = readline().split( \" \" ).map( ai => parseInt( ai, 10 ) );\n\nvar solution = function ( n, a ) {\n var i = --n;\n var prevA = a[ i ];\n var b = [ prevA ];\n while ( i ) {\n --i;\n b.unshift( a[ i ] + prevA );\n prevA = a[ i ];\n }\n return b;\n};\n\nprint( solution( n, a ).join(\" \") );"}], "negative_code": [{"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar b = new Array(n), sum_b = 0;\nfor (var i = n - 1; i >= 0; i--) {\n b[i] = a[i] + sum_b;\n sum_b = b[i] - sum_b\n}\nprint(b);"}, {"source_code": "var n = parseInt(readline());\n\tvar a = readline().split(\" \");\n\tvar b = [];\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\tb[i] = a[i]+a[i+1];\n\t}\n\tb[n-1] = a[n-1];\n\tfor(var j = 0; j < n; j++)\n\t{\n\t\tprint(b[j]);\n\t}"}, {"source_code": "var n = parseInt(readline());\n\tvar a = readline().split(\" \");\n\tvar b = [];\n\tfor(var i = 0; i < n; i++)\n\t{\n\t\tb[i] = a[i]+a[i+1];\n\t}\n\tb[n-1] = a[n-1];\n\tfor(var j = 0; j < n; j++)\n\t{\n\t\tprint(\"%d \",b[j]);\n\t}"}, {"source_code": "var n = parseInt(readline());\n\tvar a = readline().split(\" \");\n\tvar len = a.length;\n\tvar b = [];\n\tfor(var i = 0, j = i+1; i < n-1, j parseInt( ai, 10 ) );\n\nvar a = function ( n, a ) {\n var i = --n;\n var prevA = a[ i ];\n var b = [ prevA ];\n while ( i ) {\n --i;\n b.unshift( a[ i ] + prevA );\n prevA = a[ i ];\n }\n return b;\n};\n\nprint( a( n, a ).join(\" \") );"}], "src_uid": "fa256021dc519f526ef3878cce32ff31"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar nodeNum = integers[0], edgeNum = integers[1], targetNode = integers[2];\n\n\tif (edgeNum < nodeNum-1 || edgeNum > (nodeNum-1)*(nodeNum-2)/2 + 1) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar nodes = [];\n\tfor (var i = 1; i <= nodeNum; i += 1) {\n\t\tnodes.push(i);\n\t}\n\tnodes[1] = targetNode;\n\tnodes[targetNode-1] = 2;\n\tprint(nodes[0]+\" \"+targetNode);\n\t\n\tvar count = edgeNum-1;\n\tfor (var i = 1; i < nodeNum; i += 1) {\n\t\tfor (var j = i+1; j < nodeNum; j += 1) {\n\t\t\tif (count == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcount -= 1;\n\t\t\tprint(nodes[i]+\" \"+nodes[j]);\n\t\t}\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "const input = readline().split(' ').map(v => parseInt(v));\n\nconst n = input[0];\nconst m = input[1];\nconst v = input[2];\n\nfunction output(s) {\n print(s);\n}\n\nfunction comb(n, k) {\n var f = 1;\n for (var i = k; i >= 1; i--) {\n f = f * (n - i + 1) / (k - i + 1);\n }\n return f;\n}\n\nfunction connect(servers, connections, special) {\n for (var i = 1; i < servers; i++) {\n for (var j = i + 1; j <= servers; j++) {\n var left = i;\n var right = j;\n\n if (i === 1) {\n left = special;\n } else if (i === special) {\n left = servers + 1;\n }\n\n if (j === special) {\n right = servers + 1;\n }\n\n output(left + ' ' + right);\n connections--;\n if (connections === 0) {\n return;\n }\n }\n }\n}\n\nif (m < n - 1 || comb(n - 1, 2) < m - 1) {\n output(-1);\n} else {\n\n connect(n - 1, m - 1, v);\n output(v + ' ' + (v === 1 ? n : 1));\n}\n"}], "negative_code": [{"source_code": "const input = readline().split(' ').map(v => parseInt(v));\n\nconst n = input[0];\nconst m = input[1];\nconst v = input[2];\n\nfunction output(s) {\n print(s);\n}\n\nfunction comb(n, k) {\n var f = 1;\n for (var i = k; i >= 1; i--) {\n f = f * (n - i + 1) / (k - i + 1);\n }\n return f;\n}\n\nfunction connect(servers, connections, special) {\n for (var i = 1; i < servers; i++) {\n for (var j = i + 1; j <= servers; j++) {\n var left = i;\n var right = j;\n\n if (i === 1) {\n left = special;\n } else if (i === special) {\n left = servers + 1;\n }\n\n if (j === special) {\n right = servers + 1;\n }\n\n output(left + ' ' + right);\n connections--;\n if (connections === 0) {\n return;\n }\n }\n }\n}\n\nif (m < n - 1 || comb(n - 1, 2) < m - 1) {\n output(-1);\n} else {\n connect(n - 1, m - 1, v);\n output(v + ' ' + 1);\n}\n"}], "src_uid": "959709bfe7b26a4b9f2e7430350650a9"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar one = [];\r\n\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(s[i] == \"2\"){\r\n\t\t\t\tone.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(one.length == 1 || one.length == 2){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tmyout(\"YES\");\r\n\t\tvar output = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\toutput[i] = new Array(N).fill(\"=\");\r\n\t\t\toutput[i][i] = \"X\";\r\n\t\t}\r\n\t\t\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(s[i] == \"2\"){\r\n\t\t\t\tvar L = one.indexOf(i);\r\n\t\t\t\tvar R = one[(L + 1) % one.length];\r\n\t\t\t\toutput[one[L]][R] = \"+\";\r\n\t\t\t\toutput[R][one[L]] = \"-\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmyout(myconv(output[i], 0));\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n console.log(solve(n, str))\n }\n// })()\n})\n\nfunction solve(n, str) {\n let two = 0\n const map = {}\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '2') {\n map[i] = two\n two++\n }\n }\n if (two === 1 || two === 2) return 'NO'\n\n const ans = []\n for (let i = 0; i < str.length; i++) {\n ans[i] = []\n for (let j = 0; j < str.length; j++) {\n if (i === j) {\n ans[i][j] = 'X'\n } else {\n const a = str[i]\n const b = str[j]\n if (a === '1' || b === '1') {\n ans[i][j] = '='\n } else {\n const p = map[i]\n const q = map[j]\n if (p === 0 && q === two - 1) {\n ans[i][j] = '+'\n } else if (p === two - 1 && q === 0) {\n ans[i][j] = '-'\n } else if (p > q) {\n ans[i][j] = '+'\n } else {\n ans[i][j] = '-'\n }\n }\n }\n }\n ans[i] = ans[i].join('')\n }\n return 'YES\\n' + ans.join('\\n')\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) if (arr[i] === 2) cnt++;\r\n if (cnt > 0 && cnt < 3) console.log(\"NO\");\r\n else {\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n let t = [];\r\n for (let j = 0; j < n; j++) t.push(0);\r\n res.push(t);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let flag = 0;\r\n for (let j = 0; j < n; j++) {\r\n if (!res[i][j]) {\r\n if (i === j) res[i][j] = \"X\";\r\n else if (arr[i] === 1 && arr[j] === 1) res[i][j] = res[j][i] = \"=\";\r\n else if (arr[i] === 1 && arr[j] === 2) {\r\n res[i][j] = \"+\";\r\n res[j][i] = \"-\";\r\n } else if (arr[i] === 2 && arr[j] === 1) {\r\n res[i][j] = \"-\";\r\n res[j][i] = \"+\";\r\n } else if (flag === 0) {\r\n res[i][j] = \"+\";\r\n res[j][i] = \"-\";\r\n flag = 1;\r\n } else {\r\n res[i][j] = \"-\";\r\n res[j][i] = \"+\";\r\n }\r\n }\r\n }\r\n }\r\n console.log(\"YES\");\r\n for (let i = 0; i < res.length; i++) console.log(res[i].join(\"\"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) if (arr[i] === 2) cnt++;\r\n if (cnt > 0 && cnt < 3) console.log(\"NO\");\r\n else {\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n let t = [];\r\n for (let j = 0; j < n; j++) t.push(0);\r\n res.push(t);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let flag = 0;\r\n for (let j = 0; j < n; j++) {\r\n if (!res[i][j]) {\r\n if (i === j) res[i][j] = \"X\";\r\n else if (arr[i] === 1 && arr[j] === 1) res[i][j] = res[j][i] = \"=\";\r\n else if (arr[i] === 1 && arr[j] === 2) {\r\n res[i][j] = \"+\";\r\n res[j][i] = \"-\";\r\n } else if (arr[i] === 2 && arr[j] === 1) {\r\n res[i][j] = \"-\";\r\n res[j][i] = \"+\";\r\n } else if (flag === 0) {\r\n res[i][j] = \"+\";\r\n res[j][i] = \"-\";\r\n flag = 1;\r\n } else {\r\n res[i][j] = \"-\";\r\n res[j][i] = \"+\";\r\n }\r\n }\r\n }\r\n }\r\n console.log(\"YES\");\r\n for (let i = 0; i < res.length; i++) console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "7e15bb1d6040d786983865143d1799cd"} {"source_code": "r=readline;for(r();b=r();print(a.join(''))){p=0;a=[...b];a.map((i,j)=>p=i-~a[j+1]>10?j:p);a[p+1]-=-a[p];a[p]=''}", "positive_code": [{"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n //------------------------------ -------------------------------//\r\n let t = inputReader.readNumber();\r\n //let t = 1;\r\n\r\n function solve() {\r\n let s = inputReader.readLine().split(\"\");\r\n let n = s.map((x) => {\r\n return Number(x);\r\n });\r\n for (let i = n.length - 1; i > 0; i--) {\r\n if (n[i] + n[i - 1] >= 10) {\r\n let sum = n[i] + n[i - 1];\r\n n[i - 1] = Math.floor(sum / 10);\r\n n[i] = sum % 10;\r\n console.log(n.join(\"\"));\r\n return;\r\n }\r\n }\r\n n[1] += n[0];\r\n n.shift();\r\n console.log(n.join(\"\"));\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n\r\n //------------------------------ -------------------------------//\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readLine() {\r\n return _inputLines[_lineNumber++];\r\n }\r\n\r\n return {\r\n readNumber,\r\n readLine,\r\n };\r\n}\r\n"}, {"source_code": "r=readline;for(k=r();k--;print(a.join(''))){p=0;a=[...r()];a.map((i,j)=>p=i-~a[j+1]>10?j:p);a[p+1]-=-a[p];a[p]=''}"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\twhile (t--) {\r\n\t\tvar s = readline();\r\n\t\tvar n = s.length;\r\n\t\tvar found = false;\r\n\t\tfor (var i = n - 2; i >= 0; i--) {\r\n\t\t\t// find rightmost instance where s[i] and s[i + 1] >= 10\r\n\t\t\tif (parseInt(s[i]) + parseInt(s[i + 1]) >= 10) {\r\n\t\t\t\tvar middle = (parseInt(s[i]) + parseInt(s[i + 1])).toString();\r\n\t\t\t\tprint(s.slice(0, i) + middle + s.slice(i + 2, n));\r\n\t\t\t\tfound = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (found === false) {\r\n\t\t\t// string must shorten. merge 1st 2 chars for largest result\r\n\t\t\tvar front = (parseInt(s[0]) + parseInt(s[1])).toString();\r\n\t\t\tprint(front + s.slice(2, n));\r\n\t\t}\r\n\t}\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "const solve = n=>{\r\n let max = 0,index = 0,res=\"\";\r\n for(let i=n.length-1;i>0;i--){\r\n let t = parseInt(n[i]) + parseInt(n[i-1]);\r\n if(t>=10){\r\n max = t;\r\n index = i-1;\r\n break;\r\n }\r\n else{\r\n if(t>=n[i-1]){\r\n max = t;\r\n index = i-1;\r\n }\r\n }\r\n }\r\n for(let i=0;i{\r\n let max = 0,index = 0,res=\"\";\r\n for(let i=n.length-1;i>0;i--){\r\n let t = parseInt(n[i]) + parseInt(n[i-1]);\r\n if(t>10){\r\n max = t;\r\n index = i-1;\r\n break;\r\n }\r\n else{\r\n if(t>=n[i-1]){\r\n max = t;\r\n index = i-1;\r\n }\r\n }\r\n }\r\n for(let i=0;ip=i-~a[j+1]>11?j:p);a[p]-=-a[p+1];a[p+1]=''}"}, {"source_code": "r=readline;for(k=r();k--;print(a.join(''))){p=0;a=[...r()];a.map((i,j)=>p=i- -a[j+1]>10?j:p);a[p+1]-=-a[p];a[p]=''}"}, {"source_code": "r=readline;for(k=r();k--;print(a.join(''))){p=0;a=[...r()];a.map((i,j)=>p=i-~a[j+1]>11?j:p);a[p+1]-=-a[p];a[p]=''}"}], "src_uid": "6db42771fdd582578194c7b69a4ef575"} {"source_code": "for(t=readline();t--;){\r\n x=readline(),y=readline()\r\n for(i=x.length-1,p=y.length-1;i>-1;i--)~p&&x[i]==y[p]?p--:i--;\r\n print(~p?'NO':'YES')\r\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n const tests_count = parseInt(readline());\n for (var test = 0; test < tests_count; test++) {\n const src = readline();\n const pat = readline();\n console.log(verify(src, pat, 0) || verify(src, pat, 1) ? \"YES\" : \"NO\")\n }\n}\n\nfunction verify(src, pat, parity) {\n let src_idx = findNextWithParity(src, 0, pat[0], parity);\n if (src_idx >= src.length)\n return false;\n\n let pat_idx = 1;\n while (pat_idx < pat.length) {\n parity = 1 - src_idx % 2\n // El \u00edndice debe tener una paridad diferente al elemento actual (para que la diferencia sea divisible por 2) \n src_idx = findNextWithParity(src, src_idx + 1, pat[pat_idx], parity);\n if (src_idx >= src.length)\n return false;\n\n pat_idx++\n }\n return (src.length - src_idx)%2==1;\n}\nfunction findNextWithParity(src, idx, c, parity) {\n idx = findNext(src, idx, c);\n while (idx < src.length && (idx % 2 !== parity))\n idx = findNext(src, idx + 1, c);\n return idx;\n}\nfunction findNext(src, idx, c) {\n while (idx < src.length && c !== src[idx]) idx++;\n return idx;\n}"}, {"source_code": "function solution(s, t) {\r\n const m = s.length, n = t.length\r\n if (m < n) return false\r\n let i = m - 1, j = n - 1\r\n const delFirstOfS = (m - n) & 1\r\n const smallestIdxOfS = delFirstOfS ? 1 : 0\r\n while(i >= smallestIdxOfS && j >= 0) {\r\n if(s[i] === t[j]) {\r\n i--\r\n j--\r\n } else {\r\n i -= 2\r\n }\r\n if (j < 0) return true\r\n }\r\n return false\r\n}\r\n\r\n\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\nconst resArr = []\r\n \r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n if (input.length === 3) {\r\n const t = input.pop()\r\n const s = input.pop()\r\n const res = solution(s, t)\r\n resArr.push(res ? 'YES' : 'NO')\r\n }\r\n});\r\nrl.on(\"close\", () => {\r\n resArr.forEach(e => console.log(e))\r\n});"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i += 2) {\r\n if (subS[i] === subT[0]) {\r\n subS = subS.substring(i + 1);\r\n subT = subT.substring(1);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n if (!foundNextStep) {\r\n return 'NO';\r\n }\r\n if (newLengthDiff === 0) {\r\n return subS === subT ? 'YES' : 'NO';\r\n }\r\n if (subT.length === 0) {\r\n if (subS.length % 2) {\r\n console.log(subS);\r\n }\r\n return 'YES';\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n //------------------------------ -------------------------------//\r\n\r\n let t = inputReader.readNumber();\r\n function solve() {\r\n let s = inputReader.readLine().split(\"\");\r\n let t = inputReader.readLine().split(\"\");\r\n if (s.length < t.length) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n let i = s.length - 1,\r\n j = t.length - 1;\r\n while (i >= 0 && j >= 0) {\r\n if (s[i] == t[j]) {\r\n i--;\r\n j--;\r\n } else {\r\n i -= 2;\r\n }\r\n }\r\n //console.log([i, j]);\r\n if (j >= 0) {\r\n console.log(\"NO\");\r\n } else console.log(\"YES\");\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n\r\n //------------------------------ -------------------------------//\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readLine() {\r\n return _inputLines[_lineNumber++];\r\n }\r\n\r\n return {\r\n readNumber,\r\n readLine,\r\n };\r\n}\r\n"}, {"source_code": "/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n Node.js template for\r\n the coding contests.\r\n\r\n ~~*/\r\n 'use strict';\r\n /*~~\r\n\r\n Tip:\r\n Don't raise your voice,\r\n improve your argument.\r\n\r\n ~~~~\r\n\r\n cat /dev/ass > /dev/head\r\n Ctrl+C\r\n cat /knowledge > /dev/head\r\n\r\n \u00a9 Yakov Gellert\r\n frvr.ru\r\n\r\n~~~~Don't~touch~that~part:~~*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '',\r\n currentLine = 0,\r\n outputString = '';\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n /*\r\n * Running a solution function\r\n * with whole input as an array\r\n * and a string for a buffered output\r\n */\r\n solution(inputString, outputString);\r\n\r\n /*\r\n * Return a buffered output\r\n */\r\n write(outputString);\r\n});\r\n\r\n/* Read a line from stdin */\r\nfunction readline() {\r\n if (currentLine < inputString.length) {\r\n return inputString[currentLine++];\r\n }\r\n\r\n return '';\r\n}\r\n\r\n/* Read array from stdin */\r\nfunction readarr() {\r\n return readline().split(' ');\r\n}\r\n\r\n/* Read numbers from stdin */\r\nfunction readnums() {\r\n return readarr().map(num => parseInt(num));\r\n}\r\n\r\n/* Write a string to stdout */\r\nfunction write(data) {\r\n data = data.toString();\r\n process.stdout.write(data);\r\n\r\n return data;\r\n}\r\n\r\n/* Write a string with \\n to stdout */\r\nfunction writeline(data) {\r\n write(data.toString() + '\\n');\r\n}\r\n\r\n/* Append a string to a buffer */\r\nfunction fwrite(data) {\r\n outputString += data.toString() + ' ';\r\n}\r\n\r\n/* Append a string with \\n to a buffer */\r\nfunction fwriteline(data) {\r\n fwrite(data);\r\n outputString += '\\n';\r\n}\r\n\r\n/* Throw an error */\r\nfunction error(name) {\r\n throw new Error(name.toString());\r\n}\r\n\r\n/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n Write your solution here\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/\r\n\r\nfunction solution(input, output) {\r\n\r\n for (let cases = readnums()[0]; cases > 0; cases -= 1) {\r\n let sample = readline().split('').reverse().join(''),\r\n target = readline().split('').reverse().join(''),\r\n sampleI = 0,\r\n targetI = 0;\r\n\r\n if (target.length > sample.length) {\r\n fwriteline(\"NO\");\r\n continue;\r\n }\r\n\r\n while (targetI < target.length && sampleI < sample.length) {\r\n if (target[targetI] === sample[sampleI]) {\r\n sampleI += 1;\r\n targetI += 1;\r\n continue;\r\n }\r\n\r\n sampleI += 2;\r\n }\r\n\r\n fwriteline(targetI === target.length ? \"YES\" : \"NO\");\r\n }\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet s = rl();\r\n\t\tlet t = rl();\r\n\r\n\t\tlet i = s.length - 1, j = t.length - 1;\r\n\t\twhile (i >= 0 && j >= 0) {\r\n\t\t\tif (s[i] == t[j]) {\r\n\t\t\t\ti--; j--;\r\n\t\t\t} else {\r\n\t\t\t\ti -= 2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = j < 0;\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "for(t=readline();t--;){\r\n x=readline()\r\n y=readline()\r\n for(i=x.length-1, j=y.length-1; j>-1 && i>-1; i--) {\r\n j !== -1 && x[i] == y[j] ? j-- : i--;\r\n }\r\n print(j !== -1 ? 'NO' : 'YES')\r\n}"}, {"source_code": "for(t=readline();t--;){\r\n x=readline()\r\n y=readline()\r\n for(i=x.length-1, j=y.length-1; j>-1 && i>-1; i--) {\r\n j !== -1 && x[i] == y[j] ? j-- : i--;\r\n }\r\n print(j !== -1 ? 'NO' : 'YES')\r\n}"}, {"source_code": "for(t=readline();t--;){\r\n x=readline(),y=readline()\r\n for(i=x.length-1, p=y.length-1; ~p && i>-1; i--) {\r\n ~p && x[i] == y[p] ? p-- : i--;\r\n }\r\n print(~p?'NO':'YES')\r\n}"}, {"source_code": "for(t=readline();t--;){\r\n x=readline(),y=readline()\r\n for(i=x.length-1, p=y.length-1; i>-1; i--) {\r\n ~p && x[i] == y[p] ? p-- : i--;\r\n }\r\n print(~p?'NO':'YES')\r\n}"}, {"source_code": "for (var n = Number (readline ()); n > 0; n--)\r\n {\r\n var s = readline ();\r\n var t = readline ();\r\n var i = s.length - 1;\r\n var j = t.length - 1;\r\n\r\n while (i >= j && j >= 0)\r\n {\r\n if (s[i] === t[j]) { i--; j--; }\r\n else { i -= 2; }\r\n }\r\n\r\n print (j < 0 ? \"Yes\" : \"No\");\r\n }"}, {"source_code": "for(t=readline();t--;){\r\n x=readline(),y=readline()\r\n for(i=x.length-1,p=y.length-1;i>-1;i--)~p&&x[i]==y[p]?p--:i--;\r\n print(~p?'NO':'YES')\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n if (m > n) return 'NO';\r\n const check = (i, j = 1) => {\r\n let flag = i & 1 ^ 1;\r\n for (; i < n && j < m; i++) {\r\n if (a[i] === b[j] && (i & 1) !== flag) {\r\n j++;\r\n flag ^= 1;\r\n }\r\n }\r\n return j === m && !(n - i & 1);\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i + 1)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i + 1)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const tests_count = parseInt(readline());\n for (var test = 0; test < tests_count; test++) {\n const text = readline();\n const pattern = readline();\n console.log(verifyPattern(text, pattern, 0) || verifyPattern(text, pattern, 1) ? \"YES\" : \"NO\")\n }\n}\n\nfunction verifyPattern(text, pattern, parity) {\n let text_idx = parity - 1;\n for (let pattern_idx = 0; pattern_idx < pattern.length; pattern_idx++) {\n text_idx = findNextWithParity(text, text_idx + 1, pattern[pattern_idx]);\n if (text_idx >= text.length)\n return false;\n }\n return (text.length - text_idx) % 2 == 1;\n}\nfunction findNextWithParity(src, idx, c) {\n while (idx < src.length && c !== src[idx]) idx += 2;\n return idx;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const tests_count = parseInt(readline());\n for (var test = 0; test < tests_count; test++) {\n const text = readline();\n const pattern = readline();\n console.log(verifyPattern(text, pattern, 0) || verifyPattern(text, pattern, 1) ? \"YES\" : \"NO\")\n }\n}\n\nfunction verifyPattern(text, pattern, parity) {\n let pattern_idx = 0;\n let text_idx = parity-1;\n while (pattern_idx < pattern.length) {\n text_idx = findNextWithParity(text, text_idx + 1, pattern[pattern_idx]);\n if (text_idx >= text.length)\n return false;\n pattern_idx++\n }\n return (text.length - text_idx) % 2 == 1;\n}\nfunction findNextWithParity(src, idx, c) {\n while (idx < src.length && c !== src[idx]) idx += 2;\n return idx;\n}"}], "negative_code": [{"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var dbg = s.startsWith('fwnzzvuqoqfxzgicxplljpoitnkkjvrsdpighivrvnawrc');\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n if (dbg) {\r\n print('sLe: ' + sLength + ' - tLe: ' + tLength);\r\n }\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i += 2) {\r\n if (subS[i] === subT[0]) {\r\n subS = subS.substring(i + 1);\r\n subT = subT.substring(1);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n if (!foundNextStep) {\r\n return 'NO';\r\n }\r\n if (newLengthDiff === 0) {\r\n return subS === subT ? 'YES' : 'NO';\r\n }\r\n if (subT.length === 0) {\r\n if (subS.length % 2) {\r\n console.log(subS);\r\n }\r\n return 'YES';\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var dbg = tLength > 40000 && sLength > 40000 && sLength !== 49912;\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n var lengthLeft = newLengthDiff - i;\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n branches.push({ subT, subS: subS.substring(i + 2) });\r\n }\r\n var groupLen;\r\n var prevTryLen = 1;\r\n var tryLen = lengthLeft;\r\n var nextTryLen = lengthLeft;\r\n subS = subS.substring(i);\r\n while (!groupLen) {\r\n var lengthMatches = subS.startsWith(subT.substring(0, tryLen));\r\n if (lengthMatches && lengthLeft === tryLen) {\r\n groupLen = tryLen;\r\n }\r\n // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));\r\n if (!lengthMatches) {\r\n nextTryLen = Math.floor(tryLen - Math.abs(tryLen - prevTryLen) / 2);\r\n } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {\r\n nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);\r\n } else {\r\n groupLen = tryLen;\r\n }\r\n prevTryLen = tryLen;\r\n tryLen = nextTryLen;\r\n if (prevTryLen === nextTryLen) {\r\n groupLen = Math.max(tryLen - 1, 1);\r\n }\r\n }\r\n if (dbg) {\r\n print('groupLen: ' + groupLen + ' - sLe: ' + sLength + ' - tLe: ' + tLength);\r\n }\r\n subS = subS.substring(groupLen);\r\n subT = subT.substring(groupLen);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {\r\n if (subS === subT || (subS.length % 2 === 0 && subT.length === 0)) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n // console.log('roadNotTaken', roadNotTaken)\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "\r\nfunction test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var dbg = tLength > 40000 && sLength > 40000;\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n var lengthLeft = newLengthDiff - i;\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n branches.push({ subT, subS: subS.substring(i + 2) });\r\n }\r\n var groupLen;\r\n var prevTryLen = 1;\r\n var tryLen = lengthLeft;\r\n var nextTryLen = lengthLeft;\r\n subS = subS.substring(i);\r\n while (!groupLen) {\r\n var lengthMatches = subS.startsWith(subT.substring(0, tryLen));\r\n if (lengthMatches && lengthLeft === tryLen) {\r\n groupLen = tryLen;\r\n }\r\n // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));\r\n if (!lengthMatches) {\r\n nextTryLen = Math.floor(tryLen - Math.abs(tryLen - prevTryLen) / 2);\r\n } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {\r\n nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);\r\n } else {\r\n groupLen = tryLen;\r\n }\r\n prevTryLen = tryLen;\r\n tryLen = nextTryLen;\r\n if (prevTryLen === nextTryLen) {\r\n groupLen = Math.max(tryLen - 1, 1);\r\n }\r\n }\r\n if (dbg) {\r\n print('groupLen: ' + groupLen + ' - sLe: ' + sLength + ' - tLe: ' + tLength);\r\n }\r\n subS = subS.substring(groupLen);\r\n subT = subT.substring(groupLen);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {\r\n if (subS === subT || (subS.length % 2 === 0 && subT.length === 0)) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n // console.log('roadNotTaken', roadNotTaken)\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n var lengthLeft = newLengthDiff - i;\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n branches.push({ subT, subS: subS.substring(i + 2) });\r\n }\r\n var groupLen = 1;\r\n var prevTryLen = 1;\r\n var tryLen = lengthLeft;\r\n var nextTryLen = lengthLeft;\r\n subS = subS.substring(i);\r\n // while (!groupLen) {\r\n // var lengthMatches = subS.startsWith(subT.substring(0, tryLen));\r\n // if (lengthMatches && lengthLeft === tryLen) {\r\n // groupLen = tryLen;\r\n // }\r\n // // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));\r\n // if (!lengthMatches) {\r\n // nextTryLen = Math.floor((prevTryLen + tryLen) / 2);\r\n // } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {\r\n // nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);\r\n // } else {\r\n // groupLen = tryLen;\r\n // }\r\n // prevTryLen = tryLen;\r\n // tryLen = nextTryLen;\r\n // if (prevTryLen === nextTryLen) {\r\n // groupLen = Math.max(tryLen - 1, 1);\r\n // }\r\n // }\r\n subS = subS.substring(i + groupLen);\r\n subT = subT.substring(groupLen);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {\r\n if (subS === subT || (subS.length % 2 === 0 && subT.length === 0) || subS.startsWith(subT)) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n\r\n // for (var i = parityMatch; i <= newLengthDiff; i += 2) {\r\n // if (s.substring(i, t.length) === t) {\r\n // return 'Yes';\r\n // }\r\n // }\r\n\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n var lengthLeft = newLengthDiff - i;\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n branches.push({ subT, subS: subS.substring(i + 2) });\r\n }\r\n var groupLen;\r\n var prevTryLen = 1;\r\n var tryLen = lengthLeft;\r\n var nextTryLen = lengthLeft;\r\n subS = subS.substring(i);\r\n while (!groupLen) {\r\n var lengthMatches = subS.startsWith(subT.substring(0, tryLen));\r\n if (lengthMatches && lengthLeft === tryLen) {\r\n groupLen = tryLen;\r\n }\r\n // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));\r\n if (!lengthMatches) {\r\n nextTryLen = Math.floor((prevTryLen + tryLen) / 2);\r\n } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {\r\n nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);\r\n } else {\r\n groupLen = tryLen;\r\n }\r\n prevTryLen = tryLen;\r\n tryLen = nextTryLen;\r\n if (prevTryLen === nextTryLen) {\r\n groupLen = Math.max(tryLen - 1, 1);\r\n }\r\n }\r\n subS = subS.substring(i + groupLen);\r\n subT = subT.substring(groupLen);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {\r\n if (subS === subT || (subS.length % 2 === 0 && subT.length === 0) || subS.startsWith(subT)) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var freqS = {};\r\n var freqT = {};\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n Array.from(subS).forEach(function (sC) {\r\n freqS[sC] = (freqS[sC] || 0) + 1;\r\n });\r\n Array.from(subT).forEach(function (tC) {\r\n freqT[tC] = (freqT[tC] || 0) + 1;\r\n });\r\n var issueLetter = Object.keys(freqT).find(function (k) {\r\n return freqT[k] > (freqS[k] || 0);\r\n });\r\n if (issueLetter) {\r\n return 'NO';\r\n }\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n var sC = subS[i];\r\n freqS[sC]--;\r\n\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n var sCP1 = subS[i + 1];\r\n var savedFreqS = Object.assign({}, freqS);\r\n var savedFreqT = Object.assign({}, freqT);\r\n savedFreqS[sCP1]--;\r\n if (!freqT[sCP1] || freqT[sCP1] <= savedFreqS[sCP1]) {\r\n branches.push({\r\n subT, subS: subS.substring(i + 2), savedFreqS, savedFreqT,\r\n });\r\n }\r\n }\r\n freqT[subT[0]] -= 1;\r\n subS = subS.substring(i + 1);\r\n subT = subT.substring(1);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n if (freqT[sC] > freqS[sC]) {\r\n // console.log('SUB_S: ', subS);\r\n // console.log('SUB_T: ', subT);\r\n // console.log('I: ', i);\r\n // console.log(sC, freqT[sC], freqS[sC]);\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || subT.length === 0) {\r\n if (subS === subT) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n freqS = roadNotTaken.savedFreqS;\r\n freqT = roadNotTaken.savedFreqT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var freqS = {};\r\n var freqT = {};\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n\r\n Array.from(subS).forEach(function (sC) {\r\n freqS[sC] = (freqS[sC] || 0) + 1;\r\n });\r\n Array.from(subT).forEach(function (tC) {\r\n freqT[tC] = (freqT[tC] || 0) + 1;\r\n });\r\n var issueLetter = Object.keys(freqT).find(function (k) {\r\n return freqT[k] > (freqS[k] || 0);\r\n });\r\n if (issueLetter) {\r\n return 'NO';\r\n }\r\n\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n while (subT.length) {\r\n for (var i = 0; i <= newLengthDiff; i++) {\r\n var sC = subS[i];\r\n freqS[sC]--;\r\n if (freqT[sC] > freqS[sC]) {\r\n break;\r\n }\r\n\r\n if (i % 2 === 0 && subS[i] === subT[0]) {\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2 && subS.substring(i + 2).includes(subT[0])) {\r\n var sCP1 = subS[i + 1];\r\n var savedFreqS = Object.assign({}, freqS);\r\n var savedFreqT = Object.assign({}, freqT);\r\n savedFreqS[sCP1]--;\r\n if (!freqT[sCP1] || freqT[sCP1] <= savedFreqS[sCP1]) {\r\n branches.push({\r\n subT, subS: subS.substring(i + 2), savedFreqS, savedFreqT,\r\n });\r\n }\r\n }\r\n freqT[subT[0]] -= 1;\r\n subS = subS.substring(i + 1);\r\n subT = subT.substring(1);\r\n newLengthDiff = subS.length - subT.length;\r\n foundNextStep = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length !== 0)) {\r\n if (subS === subT) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n freqS = roadNotTaken.savedFreqS;\r\n freqT = roadNotTaken.savedFreqT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}\r\n\r\nvar amount = parseInt(readline());\r\nfor (var i = 0; i < amount; i++) {\r\n print(test(readline(), readline()));\r\n}\r\n"}, {"source_code": "function test(s, t) {\r\n var sLength = s.length;\r\n var tLength = t.length;\r\n if (tLength > sLength) return 'NO';\r\n var lengthDiff = sLength - tLength;\r\n var parityMatch = lengthDiff % 2;\r\n var subS = parityMatch === 1 ? s.substring(1) : s;\r\n var subT = t;\r\n var branches = [];\r\n var foundNextStep = false;\r\n var newLengthDiff = lengthDiff - parityMatch;\r\n var loopNr = 0;\r\n while (subT.length) {\r\n if (loopNr === 100000) {\r\n print(`B:${branches.length}, S:${s.length}, L:${t.length}`);\r\n }\r\n for (var i = 0; i <= newLengthDiff; i += 2) {\r\n if (subS[i] === subT[0]) {\r\n foundNextStep = true;\r\n if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {\r\n branches.push({ subT, subS: subS.substring(i + 2) });\r\n }\r\n subS = subS.substring(i + 1);\r\n subT = subT.substring(1);\r\n newLengthDiff = subS.length - subT.length;\r\n break;\r\n }\r\n }\r\n if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length !== 0)) {\r\n if (subS === subT) {\r\n return 'YES';\r\n }\r\n var roadNotTaken = branches.pop();\r\n if (!roadNotTaken) {\r\n return 'NO';\r\n }\r\n // print(roadNotTaken);\r\n subS = roadNotTaken.subS;\r\n subT = roadNotTaken.subT;\r\n }\r\n foundNextStep = false;\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n if (m > n) return 'NO';\r\n const check = (i, j = 1) => {\r\n let flag = i & 1;\r\n for (let k = i + 1; k < n && j < m; k++) {\r\n if (a[k] === b[j] && (k & 1) !== flag) {\r\n j++;\r\n flag ^= 1;\r\n }\r\n }\r\n return j === m;\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n if (m > n) return 'NO';\r\n const check = (i, j) => {\r\n let pre = i & 1;\r\n j++;\r\n for (let k = i + 1; k < n; k++) {\r\n if (a[k] === b[j] && (k & 1) !== pre) {\r\n j++;\r\n pre ^= 1;\r\n }\r\n if (j === m) return true;\r\n }\r\n return j === m;\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n const check = (i, j) => {\r\n let pre = i & 1;\r\n j++;\r\n for (let k = i + 1; k < n; k++) {\r\n if (a[k] === b[j] && (k & 1) !== pre) {\r\n j++;\r\n pre ^= 1;\r\n }\r\n if (j === m) return true;\r\n }\r\n return j === m;\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n const check = (i, j) => {\r\n let pre = i;\r\n j++;\r\n for (let k = i + 1; k < n; k++) {\r\n if (a[k] === b[j] && (k - pre - 1) % 2 === 0) {\r\n j++;\r\n pre = k;\r\n }\r\n if (j === m) return true;\r\n }\r\n return j === m;\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a, b) {\r\n const n = a.length,\r\n m = b.length;\r\n const check = (i, j) => {\r\n let pre = i;\r\n j++;\r\n for (let k = i + 1; k < n; k++) {\r\n if (a[k] === b[j] && (k - pre - 1) % 2 === 0) {\r\n j++;\r\n pre = k;\r\n }\r\n if (j === m) return true;\r\n }\r\n return false;\r\n };\r\n for (let i = 0; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n for (let i = 1; i < n; i += 2) {\r\n if (a[i] === b[0]) {\r\n if (check(i, 0)) return 'YES';\r\n break;\r\n }\r\n }\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main(){\n const tests_count = parseInt(readline());\n for (var test = 0; test < tests_count; test++) {\n const src = readline() || \"\";\n const pat = readline() || \"\";\n console.log(verify(src, pat, 0) || verify(src, pat, 1) ? \"YES\" : \"NO\")\n }\n}\n\nfunction verify(src, pat, parity) {\n if (pat.length === 0)\n return true;\n\n let src_idx = findNextWithParity(src, 0, pat[0], parity);\n if (src_idx >= src.length)\n return false;\n\n let pat_idx = 1;\n while (pat_idx < pat.length) {\n parity = 1 - src_idx % 2\n // El \u00edndice debe tener una paridad diferente al elemento actual (para que la diferencia sea divisible por 2) \n src_idx = findNextWithParity(src, src_idx + 1, pat[pat_idx], parity);\n if (src_idx >= src.length)\n return false;\n\n pat_idx++\n }\n return true;\n}\nfunction findNextWithParity(src, idx, c, parity) {\n idx = findNext(src, idx, c);\n while (idx < src.length && (idx % 2 !== parity))\n idx = findNext(src, idx + 1, c);\n return idx;\n}\nfunction findNext(src, idx, c) {\n while (idx < src.length && c !== src[idx]) idx++;\n return idx;\n}"}, {"source_code": "function solution(s, t) {\r\n const m = s.length, n = t.length\r\n if (m < n) return false\r\n let i = m - 1, j = n - 1\r\n const delFirstOfS = (m - n) & 1\r\n const smallestIdxOfS = delFirstOfS ? 1 : 0\r\n while(i >= smallestIdxOfS && j >= 0) {\r\n if(s[i] === t[j]) {\r\n i--\r\n j--\r\n } else {\r\n i -= 2\r\n }\r\n if (j < 0) return true\r\n }\r\n return false\r\n}\r\n\r\n\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\n \r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n if (input.length === 3) {\r\n const t = input.pop()\r\n const s = input.pop()\r\n const res = solution(s, t)\r\n console.log(res ? 'YES' : 'NO')\r\n }\r\n});\r\nrl.on(\"close\", () => {\r\n});"}, {"source_code": "function solution(s, t) {\r\n const m = s.length, n = t.length\r\n if (m < n) return false\r\n let i = m - 1, j = n - 1\r\n const delFirstOfS = (m - n) & 1\r\n const smallestIdxOfS = delFirstOfS ? 1 : 0\r\n while(i >= smallestIdxOfS && j >= 0) {\r\n if(s[i] === t[j]) {\r\n i--\r\n j--\r\n } else {\r\n i -= 2\r\n }\r\n }\r\n return j === -1\r\n}\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\n \r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n if (input.length === 3) {\r\n const t = input.pop()\r\n const s = input.pop()\r\n const res = solution(s, t)\r\n console.log(res ? 'YES' : 'NO')\r\n }\r\n});\r\nrl.on(\"close\", () => {\r\n});"}, {"source_code": "function solution(s, t) {\r\n const m = s.length, n = t.length\r\n if (m < n) return false\r\n let i = m - 1, j = n - 1\r\n\r\n while(i >= 0 && j >= 0) {\r\n if(s[i] === t[j]) {\r\n i--\r\n j--\r\n } else {\r\n i -= 2\r\n }\r\n }\r\n return j === -1\r\n}\r\n\r\n\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\n \r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n if (input.length === 3) {\r\n const t = input.pop()\r\n const s = input.pop()\r\n const res = solution(s, t)\r\n console.log(res ? 'YES' : 'NO')\r\n }\r\n});\r\nrl.on(\"close\", () => {\r\n});"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n //------------------------------ -------------------------------//\r\n\r\n let t = inputReader.readNumber();\r\n function solve() {\r\n let s = inputReader.readLine().split(\"\");\r\n let t = inputReader.readLine().split(\"\");\r\n if (s.length < t.length) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n let i = s.length - 1,\r\n j = t.length - 1;\r\n while (i >= 0 && j >= 0) {\r\n if (s[i] == t[j]) {\r\n i--;\r\n j--;\r\n } else {\r\n i -= 2;\r\n }\r\n }\r\n //console.log([i, j]);\r\n if (j > 0) {\r\n console.log(\"NO\");\r\n } else console.log(\"YES\");\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n\r\n //------------------------------ -------------------------------//\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readLine() {\r\n return _inputLines[_lineNumber++];\r\n }\r\n\r\n return {\r\n readNumber,\r\n readLine,\r\n };\r\n}\r\n"}, {"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader();\r\n\r\nfunction _main() {\r\n _inputLines = _inputData\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n //------------------------------ -------------------------------//\r\n\r\n let t = inputReader.readNumber();\r\n function solve() {\r\n let s = inputReader.readLine().split(\"\");\r\n let t = inputReader.readLine().split(\"\");\r\n if (s.length < t.length) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n let i = s.length - 1,\r\n j = t.length - 1;\r\n while (i >= 0 && j >= 0) {\r\n if (s[i] == t[j]) {\r\n i--;\r\n j--;\r\n } else {\r\n i -= 2;\r\n }\r\n }\r\n //console.log([i, j]);\r\n if (j > 0 && i < 0) {\r\n console.log(\"NO\");\r\n } else console.log(\"YES\");\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }\r\n\r\n //------------------------------ -------------------------------//\r\n}\r\n\r\nvar _inputData = \"\";\r\nfunction cacheInput(data) {\r\n _inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nprocess.stdin.on(\"data\", cacheInput).on(\"end\", _main);\r\n\r\nfunction _inputReader() {\r\n function readNumber() {\r\n return Number(_inputLines[_lineNumber++]);\r\n }\r\n\r\n function readLine() {\r\n return _inputLines[_lineNumber++];\r\n }\r\n\r\n return {\r\n readNumber,\r\n readLine,\r\n };\r\n}\r\n"}, {"source_code": "/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n Node.js template for\r\n the coding contests.\r\n\r\n ~~*/\r\n 'use strict';\r\n /*~~\r\n\r\n Tip:\r\n Don't raise your voice,\r\n improve your argument.\r\n\r\n ~~~~\r\n\r\n cat /dev/ass > /dev/head\r\n Ctrl+C\r\n cat /knowledge > /dev/head\r\n\r\n \u00a9 Yakov Gellert\r\n frvr.ru\r\n\r\n~~~~Don't~touch~that~part:~~*/\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '',\r\n currentLine = 0,\r\n outputString = '';\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n /*\r\n * Running a solution function\r\n * with whole input as an array\r\n * and a string for a buffered output\r\n */\r\n solution(inputString, outputString);\r\n\r\n /*\r\n * Return a buffered output\r\n */\r\n write(outputString);\r\n});\r\n\r\n/* Read a line from stdin */\r\nfunction readline() {\r\n if (currentLine < inputString.length) {\r\n return inputString[currentLine++];\r\n }\r\n\r\n return '';\r\n}\r\n\r\n/* Read array from stdin */\r\nfunction readarr() {\r\n return readline().split(' ');\r\n}\r\n\r\n/* Read numbers from stdin */\r\nfunction readnums() {\r\n return readarr().map(num => parseInt(num));\r\n}\r\n\r\n/* Write a string to stdout */\r\nfunction write(data) {\r\n data = data.toString();\r\n process.stdout.write(data);\r\n\r\n return data;\r\n}\r\n\r\n/* Write a string with \\n to stdout */\r\nfunction writeline(data) {\r\n write(data.toString() + '\\n');\r\n}\r\n\r\n/* Append a string to a buffer */\r\nfunction fwrite(data) {\r\n outputString += data.toString() + ' ';\r\n}\r\n\r\n/* Append a string with \\n to a buffer */\r\nfunction fwriteline(data) {\r\n fwrite(data);\r\n outputString += '\\n';\r\n}\r\n\r\n/* Throw an error */\r\nfunction error(name) {\r\n throw new Error(name.toString());\r\n}\r\n\r\n/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n Write your solution here\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/\r\n\r\nfunction solution(input, output) {\r\n\r\n for (let cases = readnums()[0]; cases > 0; cases -= 1) {\r\n let sample = readline();\r\n let target = readline();\r\n\r\n let checkEqualityAndWrite = (\r\n (s, t) => fwriteline(s === t ? \"YES\" : \"NO\"));\r\n\r\n /*\r\n * t is larger than s, can't reach it\r\n */\r\n if (target.length > sample.length) {\r\n fwriteline(\"NO\");\r\n continue;\r\n }\r\n\r\n if (target.length === sample.length) {\r\n checkEqualityAndWrite(target, sample);\r\n continue;\r\n }\r\n\r\n /*\r\n * Trying to find first symbol of the target in the sample\r\n */\r\n let sampleI = 0,\r\n targetI = 0;\r\n\r\n for (; sampleI < sample.length; sampleI += 1) {\r\n if (sample[sampleI] === target[targetI]) {\r\n sampleI += 1;\r\n targetI += 1;\r\n\r\n break;\r\n }\r\n }\r\n\r\n /*\r\n * Found none \u2014 failure!\r\n */\r\n if (targetI === 0) {\r\n fwriteline(\"NO\");\r\n continue;\r\n }\r\n\r\n /*\r\n * Now, my main algo:\r\n * 1. find target's letter position in a sample (if none \u2014 failure)\r\n * 2. check if it's distance from the start of the current search is an even/odd number\r\n * 2.1. if even \u2014 great, start over with first step for the next letter in target\r\n * 2.2. if odd \u2014 retry first (1.) step, but for the same letter in target\r\n */\r\n let failure = 0;\r\n let currentI = sampleI;\r\n\r\n while (sampleI < sample.length && targetI < target.length) {\r\n let found = 0;\r\n\r\n while (sampleI < sample.length) {\r\n if (sample[sampleI] === target[targetI]) {\r\n found = 1;\r\n break;\r\n }\r\n\r\n sampleI += 1;\r\n }\r\n\r\n if (found === 0) {\r\n failure = 1;\r\n break;\r\n }\r\n\r\n if ((sampleI - currentI) % 2 === 0) {\r\n targetI += 1;\r\n currentI = sampleI + 1;\r\n }\r\n\r\n sampleI += 1;\r\n }\r\n\r\n if (failure === 1) {\r\n fwriteline(\"NO\");\r\n continue;\r\n }\r\n\r\n /*\r\n * If we walked through all symbols of the target, but not the sample,\r\n * we just need to check the distance from last checked symbol in sample until the end of it.\r\n * If it's even \u2014 great, we can trim all of them.\r\n * If it's odd \u2014 failure, because we couldn't trim them without removing last checked symbol or adding extra one\r\n * to the sample sequence thus mismatching the target one.\r\n */\r\n if (sampleI < sample.length) {\r\n /*\r\n * +1, because of 0-notation\r\n * -1, to revert the last +1 at the end of a while cycle above\r\n */\r\n checkEqualityAndWrite((sample.length - sampleI) % 2, 0);\r\n }\r\n\r\n /*\r\n * Got to the end \u2014 great!\r\n */\r\n fwriteline(\"YES\");\r\n }\r\n}\r\n\r\n"}], "src_uid": "67856314f24ed718eb9b0d9fc9ab1abe"} {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n const restLines = lines.slice(1)\n let mark = 1\n for (let i =0; i x-1)\n let choose = false\n for (const chosenPrince of pList) {\n if (!princeList[chosenPrince]) {\n princeList[chosenPrince] = true\n choose = true\n break\n }\n }\n if (!choose)\n restPrincess = j+1\n }\n const restPrince = princeList.findIndex(x => !x)\n if (restPrince>=0) {\n console.log('IMPROVE')\n console.log((restPrincess) + ' ' + (restPrince+1))\n } else {\n console.log('OPTIMAL')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n let ks = new Array(n)\n let d = {}\n let book = {}\n for(let i = 0; i < n; i++) {\n ks[i] = readInts()\n }\n for(let i = 0; i < n; i++) {\n let kD = ks[i]\n // wr(i + 1, kD)\n let s = 1\n let b = kD[0]\n for(let j = 1; j <= kD[0]; j++) {\n if(!book[kD[j]]) {\n // wr('b', b)\n // wr(book)\n book[kD[j]] = i + 1\n d[i + 1] = kD[j]\n break\n }\n }\n }\n // wr(d)\n // wr(book)\n let nD = -1\n let nK = -1\n for(let i = 1; i <= n; i++) {\n if(!d[i]) {\n nD = i\n break\n }\n }\n for(let i = 1; i <= n; i++) {\n if(!book[i]) {\n nK = i\n break\n }\n }\n if(nD !== -1) {\n wr('IMPROVE')\n wr(nD, nK)\n }\n else wr('OPTIMAL')\n }\n}"}, {"source_code": "var len = readline()\n\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n var obj = {}\n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p <= arr[0];p ++) {\n if (!obj[arr[p]]) {\n nomarryflag = false\n obj[arr[p]] = 1\n break\n }\n \n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 1;q <= dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum) {\n print('OPTIMAL')\n }\n }\n}"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n let ks = new Array(n)\n let d = {}\n let book = {}\n for(let i = 0; i < n; i++) {\n ks[i] = readInts()\n }\n for(let i = 0; i < n; i++) {\n let kD = ks[i]\n let s = 1\n let b = kD[0]\n while(s < b) {\n let m = Math.floor((s + b) / 2)\n if(!book[kD[m]]) {\n b = m\n }\n else {\n s = m + 1\n }\n }\n if(b !== 0 && !book[kD[b]]) {\n book[kD[b]] = true\n d[i + 1] = true\n }\n }\n // wr(d)\n // wr(book)\n let nD = -1\n let nK = -1\n for(let i = 1; i <= n; i++) {\n if(!d[i]) {\n nD = i\n break\n }\n }\n for(let i = 1; i <= n; i++) {\n if(!book[i]) {\n nK = i\n break\n }\n }\n if(nD !== -1) {\n wr('IMPROVE')\n wr(nD, nK)\n }\n else wr('OPTIMAL')\n }\n}"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n const restLines = lines.slice(1)\n let mark = 1\n for (let i =0; i x-1)\n for (const chosenPrince of pList) {\n if (!princeList[chosenPrince]) {\n princeList[chosenPrince] = true\n break\n }\n restPrincess = n-rest + 1\n }\n rest--\n }\n const restPrince = princeList.findIndex(x => !x)\n if (restPrince>=0) {\n console.log('IMPROVE')\n console.log((restPrincess || '1') + ' ' + (restPrince+1))\n } else {\n console.log('OPTIMAL')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var len = readline()\n\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n var obj = {}\n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p <= arr[0];p ++) {\n if (obj[arr[p]] == 0) {\n nomarryflag = false\n obj[arr[p]] = 1\n break\n }\n \n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 1;q <= dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum) {\n print('OPTIMAL')\n }\n }\n}"}, {"source_code": "var len = readline()\nvar obj = {}\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n \n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p < arr[0];p ++) {\n if (obj[arr[p]] == 0) {\n nomarryflag = false\n }\n obj[arr[p]] = 1\n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 0;q < dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum - 1) {\n print('OPTIMAL')\n }\n }\n}"}, {"source_code": "var len = readline()\n\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n var obj = {}\n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p < arr[0];p ++) {\n if (obj[arr[p]] == 0) {\n nomarryflag = false\n }\n obj[arr[p]] = 1\n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 0;q < dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum - 1) {\n print('OPTIMAL')\n }\n }\n}"}, {"source_code": "var len = readline()\n\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n var obj = {}\n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p < arr[0];p ++) {\n if (obj[arr[p]] == 0) {\n nomarryflag = false\n obj[arr[p]] = 1\n break\n }\n \n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 1;q <= dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum) {\n print('OPTIMAL')\n }\n }\n}"}, {"source_code": "var len = readline()\n\nfor (var i = 0;i < len;i ++) {\n var dnum = readline();\n var nomarry = 0\n var obj = {}\n for(var j = 0;j < dnum; j ++) {\n var arr = readline().split(' ')\n var nomarryflag = true\n for (var p = 1;p < arr[0];p ++) {\n if (obj[arr[p]] == 0) {\n nomarryflag = false\n obj[arr[p]] = 1\n break\n }\n \n }\n if (nomarryflag == true) {\n nomarry = j + 1\n }\n }\n for (var q = 0;q < dnum; q ++) {\n if (!obj[q] && nomarry != 0) {\n print('IMPROVE')\n print(nomarry + ' ' + q)\n break\n }\n if (q == dnum - 1) {\n print('OPTIMAL')\n }\n }\n}"}], "src_uid": "38911652b3c075354aa8adb2a4c6e362"} {"source_code": "let input = '';\nprocess.stdin.on('data', chunk => input += chunk);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = input.split(EOL);\n const count = parseInt(lines.shift());\n for (let i = 1; i <= count; ++i) {\n const n = parseInt(lines.shift());\n const my = lines.shift().split(/\\s+/).filter(x => x.match(/^\\d+$/)).map(x => parseInt(x));\n const his = lines.shift().split(/\\s+/).filter(x => x.match(/^\\d+$/)).map(x => parseInt(x));\n console.log(solve(n, my, his));\n }\n});\n\nfunction solve(n, my, his) {\n my.sort((a, b) => b - a);\n his.sort((a, b) => b - a);\n let count = n - Math.floor(n / 4);\n let myScore = my.slice(0, count).reduce((acc, val) => acc + val);\n let hisScore = his.slice(0, count).reduce((acc, val) => acc + val);\n let idx = count - 1;\n for (let added = 0; ; ++added) {\n if (myScore >= hisScore) {\n return added;\n }\n let newSize = n + added + 1;\n let newCount = newSize - Math.floor(newSize / 4);\n myScore += 100;\n if (newCount === count) {\n if (idx >= 0) {\n myScore -= my[idx];\n --idx;\n } else {\n myScore -= 100;\n }\n } else { // newCount === count + 1\n if (count < n) {\n hisScore += his[count];\n }\n }\n count = newCount;\n }\n}\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\t\tlet b = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\t\tb.sort((x, y) => x - y);\r\n\r\n\t\tk = Math.floor(n / 4) - 1;\r\n\r\n\t\tlet asum = 0, bsum = 0;\r\n\t\tfor (let i = k + 1; i < n; i++) {\r\n\t\t\tasum += a[i];\r\n\t\t\tbsum += b[i];\r\n\t\t}\r\n\r\n\t\tlet stage = n;\r\n\t\tlet i = j = k;\r\n\t\twhile (asum < bsum) {\r\n\t\t\tstage++;\r\n\t\t\tif (stage % 4 == 0) {\r\n\t\t\t\tasum += 100 - a[++i];\r\n\t\t\t} else {\r\n\t\t\t\tasum += 100;\r\n\t\t\t\tif (j >= 0) bsum += b[j];\r\n\t\t\t\t--j;\r\n\t\t\t}\r\n\t\t\t//console.log('asm', asum, 'bsum', bsum, stage);\r\n\t\t}\r\n\r\n\t\tans = stage - n;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "61b88627fc843ef6e5226e1003822793"} {"source_code": "\"use strict\";\n\nlet input = readline().split(' ').map(e => +e);\nlet R = input[0] - 1, C = input[1];\n\nwhile ( R-- > 0 )\n\treadline(); //ignore\n\nlet walls = readline().split('.').filter(e => e != '').length;\nwrite(walls);", "positive_code": [{"source_code": "var array = readline().split(' ').map(Number);\nvar r = array[0];\nvar c = array[1];\nvar quantity = 0;\nfor (var i = 0; i < r -1; i++){\n readline();\n}\nvar string = readline();\n\nvar flag = false;\nfor (var i = 0; i < string.length; i++){\n if (string[i] === 'B' && flag === false){\n flag = true;\n quantity++;\n } else if (string[i] === '.' && flag === true) {\n flag = false;\n }\n}\n\nprint(quantity);"}], "negative_code": [], "src_uid": "c339795767a174a59225a79023b5d14f"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 1e9 + 7;\r\n\r\nfunction fast_pow(a, p)\r\n{\r\n\tlet res = 1;\r\n\twhile (p) {\r\n\t\tif (p % 2 == 0) {\r\n\t\t\ta = Number(BigInt(a) * BigInt(a) % BigInt(MOD));\r\n\t\t\tp /= 2;\r\n\t\t} else {\r\n\t\t\tres = Number(BigInt(res) * BigInt(a) % BigInt(MOD));\r\n\t\t\tp--;\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction mmi (n) {\r\n\treturn fast_pow(n, MOD-2);\r\n}\r\n\r\nfunction fact (n) {\r\n\tlet res = 1;\r\n\tfor (let i = 1; i <= n; i++)\r\n\t\tres = Number(BigInt(res)*BigInt(i) % BigInt(MOD));\r\n\treturn res;\r\n}\r\n\r\nfunction c(n, r) {\r\n\treturn Number(BigInt(fact(n)) \r\n\t\t* BigInt(mmi(fact(n-r))) % BigInt(MOD) \r\n\t\t* BigInt(mmi(fact(r))) % BigInt(MOD));\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet cntl = 0, cntr = 0;\r\n\t\tfor (let i = 0; i < k; i++)\r\n\t\t\tcntl += a[i] == a[k-1];\r\n\t\tfor (let i = k; i < n; i++)\r\n\t\t\tcntr += a[i] == a[k-1];\r\n\r\n\t\tconst ans = c(cntl + cntr, cntl);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 1000000007n;\r\n\r\nfunction fast_pow(a, p)\r\n{\r\n\tlet res = 1n;\r\n\twhile (p) {\r\n\t\tif (p % 2n == 0) {\r\n\t\t\ta = a * a % MOD;\r\n\t\t\tp /= 2n;\r\n\t\t} else {\r\n\t\t\tres = res * a % MOD;\r\n\t\t\tp--;\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nfunction mmi (n) {\r\n\treturn fast_pow(n, MOD - 2n);\r\n}\r\n\r\nfunction fact (n) {\r\n\tlet res = 1n;\r\n\tfor (let i = 1n; i <= n; i++)\r\n\t\tres = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction c(n, r) {\r\n\treturn fact(n) * mmi(fact(n-r)) % MOD * mmi(fact(r)) % MOD;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet cntl = 0, cntr = 0;\r\n\t\tfor (let i = 0; i < k; i++)\r\n\t\t\tcntl += a[i] == a[k-1];\r\n\t\tfor (let i = k; i < n; i++)\r\n\t\t\tcntr += a[i] == a[k-1];\r\n\r\n\t\tconst ans = c(cntl + cntr, cntl);\r\n\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nvar binom = new Array(maxN)\r\nbinom[0] = new Array(maxN).fill(1n)\r\nbinom[1] = new Array(maxN).fill(1n)\r\n\r\nfor (var i = 2; i < maxN; i++){\r\n binom[i] = new Array(maxN).fill(1n)\r\n\r\n for (var j = 1; j < i; j++){\r\n binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % mod;\r\n }\r\n}\r\n// console.log(binom)\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return x\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n a = a.sort((a, b) => b - a)\r\n\r\n var add = a[k - 1]\r\n var ii = k - 1\r\n var count = 0\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === a[k - 1]) count++\r\n }\r\n while (a[k - 1] === a[ii]) ii++\r\n\r\n\r\n // var number =\r\n // console.log(ii - k, count)\r\n\r\n // console.log(binom[3][2].toString())\r\n console.log(binom[count][ii - k].toString())\r\n // var res = []\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10n\r\n\r\nvar iv = new Array(maxN + 1n).fill(0n)\r\niv[1] = 1n\r\nfor (let i = 2n; i <= maxN; i++) {\r\n iv[i] = (iv[i - 1n] * i) % mod\r\n}\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return x\r\n })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n a = a.sort((a, b) => b - a)\r\n\r\n var add = a[k - 1]\r\n var ii = k - 1\r\n while (a[k - 1] === a[ii]) ii++\r\n\r\n\r\n var number =\r\n // console.log(ii - k)\r\n console.log(iv[ii - k + 1].toString())\r\n // var res = []\r\n })\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction fact (n) {\r\n\tif (n <= 1) return 1;\r\n\treturn n * fact(n-1);\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => y - x);\r\n\r\n\t\tlet cntl = 0, cntr = 0;\r\n\t\tfor (let i = 0; i < k; i++)\r\n\t\t\tcntl += a[i] == a[k-1];\r\n\t\tfor (let i = k; i < n; i++)\r\n\t\t\tcntr += a[i] == a[k-1];\r\n\r\n\t\tconst ans = fact(cntl+cntr) / (fact(cntl) * fact(cntr));\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "69326546e8435ccfff3010947295c291"} {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n if((arr[0]+arr[k-1])%2===0) arr[0] = arr[k-1];\r\n else arr[k-1] = arr[0];\r\n count++;\r\n temp.push([1,k]);\r\n for(var j=1;j Number(read());\r\n const n = rn();\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n a[i] = rn();\r\n if (i && a[i] < a[i - 1]) flag = false;\r\n }\r\n if (flag) return 0;\r\n let res = [];\r\n if (a[0] & 1) {\r\n const odd = [],\r\n even = [];\r\n let last = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] & 1) {\r\n odd.push(i);\r\n last = i;\r\n } else even.push(i);\r\n }\r\n for (let i of odd) {\r\n if (i !== last) res.push([i, last]);\r\n }\r\n for (let i of even) {\r\n res.push([0, i]);\r\n }\r\n } else {\r\n const odd = [],\r\n even = [];\r\n let last = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] & 1) {\r\n odd.push(i);\r\n } else {\r\n even.push(i);\r\n last = i;\r\n }\r\n }\r\n for (let i of even) {\r\n if (i !== last) res.push([i, last]);\r\n }\r\n for (let i of odd) {\r\n res.push([0, i]);\r\n }\r\n }\r\n return `${res.length}\\n${res.map(([x, y]) => `${x + 1} ${y + 1}`).join('\\n')}`;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n res[i] = s;\r\n }\r\n return res.join('\\n');\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let count = 0,res = [];\r\n if(n===1){\r\n console.log(0);\r\n continue;\r\n }\r\n else{\r\n if((arr[0]+arr[n-1])%2==0) arr[0] = arr[n-1];\r\n else arr[n-1] = arr[0];\r\n count++;\r\n res.push([1,n]);\r\n for(let i=1;i +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n if((arr[0]+arr[n-1])%2==0) arr[0] = arr[n-1];\r\n else arr[n-1] = arr[0];\r\n count++;\r\n temp.push([1,k]);\r\n for(var j = 1; j < k - 1; j++) {\r\n if((arr[0] + arr[j]) % 2 > 0) {\r\n temp.push([1, j + 1]);\r\n } else {\r\n temp.push([j + 1, k]);\r\n }\r\n count++;\r\n }\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0], temp[j][1]);\r\n }\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n for(var j = 1; j < k - 1; j++) {\r\n if((arr[0] + arr[j]) % 2 > 0) {\r\n temp.push([1, j + 1]);\r\n } else {\r\n temp.push([j + 1, k]);\r\n }\r\n count++;\r\n }\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0], temp[j][1]);\r\n }\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n for(var j = 0; j < k - 1; j++) {\r\n if((arr[j] + arr[j + 1]) % 2 > 0) {\r\n arr[j + 1] = arr[j];\r\n count++;\r\n temp.push([j, j + 1]);\r\n }\r\n }\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0] + 1, temp[j][1] + 1);\r\n }\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n for(var j = 0; j < k - 1; j++) {\r\n if((arr[j] + arr[j + 1]) % 2 > 0) {\r\n arr[j + 1] = arr[j];\r\n count++;\r\n temp.push([j, j + 1]);\r\n }\r\n }\r\n print(arr);\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0] + 1, temp[j][1] + 1);\r\n }\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\n\r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n for(var j = 1; j < k && arr[j - 1] < arr[j]; j++) {}\r\n var temp = [];\r\n var count = 0;\r\n if(j !== k) {\r\n for(var j = 0; j < k - 1; j++) {\r\n for(var jj = j + 1; jj < k; jj++) {\r\n if(arr[jj - 1] > arr[jj]) {\r\n break; \r\n }\r\n if((arr[j] + arr[jj]) % 2 > 0) {\r\n arr[jj] = arr[j];\r\n count++;\r\n temp.push([j, jj]);\r\n }\r\n }\r\n }\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0], temp[j][1]);\r\n }\r\n}"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\n \r\nconst n = readNum();\r\n \r\nfor(var i = 0; i < n; i++) {\r\n var k = readNum();\r\n var arr = readNumArr();\r\n var temp = [];\r\n var count = 0;\r\n for(var j = 0; j < k - 1; j++) {\r\n for(var jj = j + 1; jj < k; jj++) {\r\n if(arr[jj - 1] > arr[jj]) {\r\n break; \r\n }\r\n if((arr[j] + arr[jj]) % 2 > 0) {\r\n arr[jj] = arr[j];\r\n count++;\r\n temp.push([j, jj]);\r\n }\r\n }\r\n }\r\n print(count);\r\n for(var j = 0; j < temp.length; j++) {\r\n print(temp[j][0], temp[j][1]);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nconst N = 100010;\r\nconst a = new Array(N),\r\n even = new Array(N),\r\n odd = new Array(N);\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn();\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n a[i] = rn();\r\n if (i && a[i] < a[i - 1]) flag = false;\r\n }\r\n if (flag) return 0;\r\n let res = [];\r\n if (a[0] & 1) {\r\n let last = 0,\r\n ido = 0,\r\n ide = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] & 1) {\r\n odd[ido++] = i;\r\n last = i;\r\n } else even[ide++] = i;\r\n }\r\n for (let i = 0; i < ido; i++) {\r\n const j = odd[i];\r\n if (j !== last && a[j] !== a[last]) res.push(`${j + 1} ${last + 1}`);\r\n }\r\n for (let i = 0; i < ide; i++) {\r\n const j = even[i];\r\n res.push(`${1} ${j + 1}`);\r\n }\r\n } else {\r\n let p = 0;\r\n for (let i = 1; i < n; i++) {\r\n even[i] = p;\r\n if (a[i] % 2 === 0) p = i;\r\n }\r\n for (let i = n - 1; i > 0; i--) {\r\n if (a[i] & 1) {\r\n res.push(`${even[i] + 1} ${i + 1}`);\r\n } else {\r\n if (a[even[i]] > a[i]) res.push(`${even[i] + 1} ${i + 1}`);\r\n }\r\n }\r\n }\r\n return `${res.length}\\n${res.join('\\n')}`;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n res[i] = s;\r\n }\r\n return res.join('\\n');\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let count = 0,res = [];\r\n if(n===1){\r\n console.log(0);\r\n continue;\r\n }\r\n else{\r\n if((arr[0]+arr[n-1])%2==0) arr[0] = arr[n-1];\r\n else arr[n-1] = arr[0];\r\n count++;\r\n res.push([1,n]);\r\n for(let i=1;i {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let count = 0,res = [];\r\n if(n===1){\r\n console.log(0);\r\n continue;\r\n }\r\n while(true){\r\n for(let i=0;iarr[i+1]){\r\n if((arr[i]+arr[i+1])%2===0) arr[i] = arr[i+1]\r\n else arr[i+1] = arr[i];\r\n count++;\r\n res.push([i+1,i+2]);\r\n }\r\n }\r\n let flag = 0;\r\n for(let i=0;iarr[i+1]){\r\n flag = 1;\r\n break;\r\n }\r\n }\r\n if(flag===0){\r\n console.log(count);\r\n if(count!==0){\r\n for(let i=0;i=1;i--){\r\n if(arr[i-1]>arr[i]){\r\n if((arr[i-1]+arr[i])%2==0) arr[i-1] = arr[i];\r\n else arr[i] = arr[i-1];\r\n count++;\r\n res.push([i,i+1]);\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();"}], "src_uid": "10f3f4ae348fd4d28c371d8bf570d4c2"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nlet standardInputString = '';\r\nlet curLine = 0;\r\n\r\nconst readLine = () => {\r\n return standardInputString[curLine++];\r\n};\r\n\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split('\\n')\r\n .map(line => {\r\n return line.trim();\r\n });\r\n \r\n main();\r\n});\r\n\r\n/**\r\n * \r\n */\r\n// https://codeforces.com/contest/1566/problem/D1\r\n\r\n// Return right boundary.\r\nconst binSearchR = (num, arr) => {\r\n let l = -1;\r\n let r = arr.length;\r\n\r\n while (r - l > 1) {\r\n const mid = Math.floor(\r\n (r + l) / 2,\r\n );\r\n\r\n if (arr[mid] > num) {\r\n r = mid;\r\n } else {\r\n l = mid;\r\n }\r\n }\r\n\r\n return r;\r\n};\r\n\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let testCaseIx = 0; testCaseIx < t; testCaseIx += 1) {\r\n const [, m] = readLine()\r\n .split(' ')\r\n .map(item => +item);\r\n\r\n const eyeLvlsInOrder = readLine()\r\n .split(' ')\r\n .map(eyeLvl => +eyeLvl);\r\n const peoplePos = eyeLvlsInOrder\r\n .slice()\r\n .sort(\r\n (a, b) => a - b,\r\n );\r\n\r\n const wasEyeLvl = new Map();\r\n\r\n const inconvIfSitTo = {};\r\n\r\n let inconvenience = 0;\r\n for (const eyeLvl of eyeLvlsInOrder) {\r\n let pos = binSearchR(eyeLvl, peoplePos) - 1;\r\n\r\n const wasEyeLvlOld = wasEyeLvl.get(eyeLvl) || 0;\r\n pos -= wasEyeLvlOld;\r\n wasEyeLvl.set(eyeLvl, wasEyeLvlOld + 1);\r\n\r\n const inconvIfSitToOld = inconvIfSitTo[pos] || 0;\r\n inconvenience += inconvIfSitToOld;\r\n\r\n while (pos < 300) {\r\n inconvIfSitTo[pos] = (inconvIfSitTo[pos] || 0) + 1;\r\n\r\n pos += 1;\r\n }\r\n }\r\n\r\n console.log(inconvenience);\r\n }\r\n};", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [m, n] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let cnt = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < i; j++) {\r\n if (arr[j] < arr[i]) cnt++;\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [], "src_uid": "5b95da35a4c1251f5376cf3bacc1a549"} {"source_code": "var main=function(){\n\n var first_line = readline().split(' ').map(Number);\n \n var n = parseInt(first_line[0]);\n var d = parseInt(first_line[1]);\n\n var x = readline().split(' ').map(Number);\n var cnt = 2;\n for (var i=0; id){\n ans+=2;\n } else\n if (Math.abs(a[i]-a[i+1])==d){\n ans++;\n }\n}\nans+=2;\nprint(ans);"}, {"source_code": "var l = readline().split(' ').map(v => parseInt(v, 10));\nvar n = l[0];\nvar d = l[1];\nvar a = readline().split(' ').map(v => parseInt(v, 10));\n\nvar ans = 2;\n\nfor (var i = 0; i < n - 1; i ++) {\n var q = a[i + 1] - a[i];\n if (q > 2 * d) {\n ans+=2;\n } else if (q === 2 * d) {\n ans++;\n }\n}\nprint(ans);"}, {"source_code": "const numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\nconst b = numbers[1];\nconst arr = readline().split(' ').map(function(v){return +v;});\n\nvar count = 2;\nvar result = [arr[0]-b, arr[n-1]+b];\n\nif(arr[0]+b+b<=arr[1]) result.push(arr[0]+b)\nif(arr[n-1]-b-b>=arr[n-2]) result.push(arr[n-1]-b)\n\nfor (var i=1; i=arr[i-1]) {\n result.push(arr[i]-b)\n }\n}\n\nuniqueArray = result.filter(function(item, pos) {\n return result.indexOf(item) == pos;\n})\n\nprint(uniqueArray.length);\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const in1 = arr.shift().split(' ')\n const a = arr.shift().split(' ')\n const n = parseInt(in1[0])\n const d = parseInt(in1[1])\n\n var c = 2\n for(let i = 1; i < n; i ++) {\n if((a[i] - a[i - 1]) > 2 * d){\n // console.log(a[i], a[i - 1])\n c += 2\n }\n else if((a[i] - a[i - 1]) == 2 * d) {\n c ++\n }\n }\n console.log(c)\n})"}, {"source_code": "const numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\nconst b = numbers[1];\nconst arr = readline().split(' ').map(function(v){return +v;});\n\nvar count = 2;\nvar result = [arr[0]-b, arr[n-1]+b];\n\nfunction first() {\n if(arr[0]+b+b<=arr[1]) result.push(arr[0]+b)\n if(arr[n-1]-b-b>=arr[n-2]) result.push(arr[n-1]-b)\n \n for (var i=1; i=arr[i-1]) {\n result.push(arr[i]-b)\n }\n }\n}\n\nfirst();\n\nuniqueArray = result.filter(function(item, pos) {\n return result.indexOf(item) == pos;\n})\n\nprint(uniqueArray.length);"}], "negative_code": [{"source_code": "var main=function(){\n\tvar a=readline().split(' ').map(Number);\n\tprint(a[0]+a[1]+' '+readline());\n};\n\n/// IO ///\nif(typeof process!=='undefined'){\n\t//node.js\n\tvar print=function(x){\n\t\tconsole.log(x);\n\t}\n\tvar readline=(function(){\n\t\tvar T=[],cnt=0;\n\t\tvar stdin = process.openStdin();\n\t\tstdin.setEncoding('utf8');\n\n\t\tvar input_fragment=\"\";\n\t\tstdin.on('data', function(input) {\n\t\t\tvar ref=(input_fragment+input).split(\"\\n\");\n\t\t\tinput_fragment=ref.pop();\n\t\t\tfor(var i=0;iarr[n-2]) count++\n\nfor (var i=1; i=arr[i-1]) {\n count++\n }\n}\n\nprint(count);\n"}, {"source_code": "const numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\nconst b = numbers[1];\nconst arr = readline().split(' ').map(function(v){return +v;});\n\nvar count = 2;\n\nif(arr[0]+b+barr[n-2]) count++\n\nfor (var i=1; i=arr[i-1]) {\n count++\n }\n}\n\nprint(count);\n"}, {"source_code": "const numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\nconst b = numbers[1];\nconst arr = readline().split(' ').map(function(v){return +v;});\n\nvar count = 2;\n\nif(arr[0]+b+b<=arr[1]) count++\nif(arr[n-1]-b-b>=arr[n-2]) count++\n\nfor (var i=1; i=arr[i-1]) {\n count++\n }\n}\n\nprint(count);\n"}], "src_uid": "5babbb7c5f6b494992ffa921c8e19294"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let stairs = 1;\n let ans = [];\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i - 1] >= arr[i]) {\n stairs++;\n ans.push(arr[i - 1]);\n }\n }\n\n ans.push(arr[arr.length - 1]);\n\n console.log(stairs);\n console.log(ans.join(' '));\n\n c++;\n});\n", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const numbers = is.nextArray().map(Number);\n numbers.push(0);\n const steps = [];\n let stairways = 0;\n for (let i = 0; i < n; i++)\n if (numbers[i] >= numbers[i + 1]) {\n stairways++;\n steps.push(numbers[i]);\n }\n\n console.log(stairways);\n console.log(steps.join(' '));\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "function main() {\n // write code here:\n const n = Number(stdin[0]);\n var arr = stdin[1].split(' ').map(Number);\n var obj1 = {1: 0};\n var newArr = [];\n for (let i = 0; i < n; i++) {\n if (arr[i] === 1) {\n obj1[1]++;\n if (i !== 0) {\n newArr.push(arr[i - 1]);\n }\n }\n }\n newArr.push(arr[n - 1]);\n console.log(obj1[1] + '\\n' + newArr.join(' '));\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "var firstLine = +readline();\nvar secondLine = readline().split(' ').map(function(v){return +v;});\n\nvar stairsCount = firstLine;\nvar strairs = secondLine;\nvar result = [];\nvar temp = 0;\n\nfor (var i = 1; i < stairsCount; i++) {\n if (strairs[i] === 1) {\n if (result.length > 0) {\n result.push(i - temp);\n } else {\n result.push(i);\n }\n temp = i;\n }\n}\n\nresult.push(stairsCount - temp);\n\nprint(result.length);\nprint(result.join(' '));"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var output = [0]; \n for(var i = 0; i < N; i++){\n if(output[output.length - 1] < list[i]){\n output[output.length - 1] = list[i];\n }else{\n output.push(list[i]);\n }\n }\n myout(output.length);\n myout(myconv(output, 8));\n}\n"}, {"source_code": "var numbers = +readline();\nvar steps = readline().split(' ').map(Number);\n\nif (numbers === 1) {\n print(1);\n print(1);\n} else {\n var stepsStairway = [];\n for (var i = 1; i < numbers; i++) {\n if (steps[i] === 1) {\n stepsStairway.push(steps[i - 1]);\n }\n }\n\n stepsStairway.push(steps.pop());\n print(stepsStairway.length);\n print(stepsStairway.join(' '));\n}"}, {"source_code": "var n = readline();\nvar arr = readline().split(' ').map(Number);\nvar start = 0;\nvar count = 0;\nvar result = [];\n \nfor (var i=1; i {\n input.push(line);\n});\n\nRL.on('close', () => {\n let flag = false, count = 0, answer = [], len = 0; \n let n = parseInt(input[0]);\n let num = []; input[1].split(' ').forEach(i => num.push(parseInt(i)));\n for (let i = 0; i < n; i++){\n len++;\n if(num[i] === 1 && !flag){\n flag = true;\n } else if(num[i] === 1 && flag) {\n answer.push(len-1);\n len = 1;\n }\n }\n answer.push(len);\n\n console.log(answer.length);\n let answer_string = ''; answer.forEach(i => answer_string+= `${i} `)\n console.log(answer_string);\n});\n\n"}, {"source_code": "/*\nn = +readline();\na = readline().split(\" \").map(Number);\nvar res = 0 , add = 0;\nfor (i = 0 ; i < n ; i ++){\n a[i] -= add;\n add += a[i];\n res += Math.abs(a[i]);\n\n}\n\nwrite(res);\n*/\nn = +readline();\na = readline().split(' ').map(Number);\nvar res = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n if (a[i] == 1){\n res ++;\n }\n}\nwrite(res);\nwrite(\"\\n\");\nvar lengthes = new Array(4);\nvar cur = 0;\nfor (var i = 0 ; i < n ; i ++)\n{\n if (a[i] == 1){\n var j = i ;\n while (j < n && a[j] - a[i] == j - i){\n j ++;\n }\n lengthes[cur ] = j - i;\n i = j - 1;\n cur += 1;\n }\n}\nfor (var i = 0 ; i < res ; i ++)\n{\n write(lengthes[i]);\n write(\" \");\n}"}, {"source_code": "const n = readline();\nvar arr = readline().split(' ').map(function(v){return +v;});\n\nvar start = 0;\nvar count = 0;\nvar result = [];\n\nfor (var i=1; i inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n const n = +inp[0];\n const a = inp[1].split(' ').map(s => +s);\n const ans = [];\n for (let i = 0; i < n; ++i) {\n if (i === n - 1 || a[i + 1] === 1)\n ans.push(a[i]);\n }\n console.log(ans.length);\n console.log(ans.join(' '));\n});"}, {"source_code": "var last = 1,\n floor = [];\n \nvar total = +readline();\nif (total == 1) {\n write(1 + '\\n' + 1);\n} else {\n readline().split(' ').forEach((step, index) => {\n if( index ) { \n if(parseInt(step) == 1) floor.push(last);\n if( index == total - 1) floor.push(step)\n last = parseInt(step); }\n });\n write(floor.length + '\\n' + floor.join(' ')); \n}\n\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(Number);\nvar les = 0;\nvar j = -1;\nvar b = [];\n\nfor (var i=0; i 0) {\n result.push(i - temp);\n } else {\n result.push(i);\n }\n temp = i;\n }\n}\n\nresult.push(stairsCount - temp);\n\nprint(result.length);\nprint(result);"}, {"source_code": "var n = +readline();\nvar str = readline().split(' ').map(Number);\nvar res = 1;\nvar mas = [];\nvar temp = 0;\nfor (var i = 1; i < n; i++)\n{\n\ttemp++;\n\tif (str[i]==1)\n\t{\n\t\tres++;\n\t\tmas.push(temp);\n\t\ttemp = 0;\n\t}\n\telse if (i+1==n)\n\t\tmas.push(temp+1);\n\t//else if (i==str.length[)\n}\nprint(res);\nprint(mas.join(' '));"}, {"source_code": "var n = +readline();\nvar str = readline().split(' ').map(Number);\nvar res = 1;\nvar mas = [];\nvar temp = 0;\nfor (var i = 1; i < n; i++)\n{\n\ttemp++;\n\tif (str[i]==1)\n\t{\n\t\tres++;\n\t\tmas.push(temp);\n\t\ttemp = 0;\n\t}\n\telse if (i+1==n)\n\t\tmas.push(temp+1);\n\t//else if (i==str.length[)\n}\nprint(res);\nprint(mas);"}, {"source_code": "var last = 1,\n floor = [];\n \nvar total = +readline();\nreadline().split(' ').forEach((step, index) => {\n if( index ) { \n if(parseInt(step) == 1) floor.push(last);\n if( index == total - 1) floor.push(step)\n last = parseInt(step); }\n});\n\nwrite(floor.length + '\\n' + floor.join(' '));"}, {"source_code": "var last = 0,\n floor = [];\n \nvar total = +readline();\nreadline().split(' ').forEach((step, index) => {\n if( index ) { \n if(parseInt(step) == 1) floor.push(last);\n if( index == total - 1) floor.push(step)\n last = parseInt(step); }\n});\n\nwrite(floor.length + '\\n' + floor.join(' '));"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar numbers2 = readline().split(\" \").map(function(x) { return parseInt(x); });\nprint(numbers);\nprint(numbers2);"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nprint(numbers);"}], "src_uid": "0ee86e75ff7a47a711c9eb41b34ad1a5"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let [i, count] of map) if (count & 1) return -1;\r\n let nums = [...a];\r\n const ops = [],\r\n res = [];\r\n for (let i = n - 1, j = n - 1; i >= 0; i = j) {\r\n j = i - 1;\r\n while (nums[j] !== nums[i]) {\r\n j--;\r\n }\r\n let t = j;\r\n while (i > t) {\r\n const num = nums[i];\r\n if (num !== nums[j]) {\r\n ops.push([j + 1, num]);\r\n nums.splice(j + 1, 0, num, num);\r\n i += 2;\r\n j += 2;\r\n t += 2;\r\n }\r\n i--;\r\n j--;\r\n }\r\n res.push((i - j) * 2);\r\n }\r\n res.reverse();\r\n let str = '';\r\n if (ops.length) {\r\n str += `${ops.length}\\n${ops.map(arr => arr.join(' ')).join('\\n')}`;\r\n } else {\r\n str += 0;\r\n }\r\n str += `\\n${res.length}\\n${res.join(' ')}`;\r\n return str;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "let context = {}\r\ncontext[\"throw\"] = function(a) { throw a }\r\ncontext[\"makeDict\"] = function() { let ret = {}; for (let i = 0; i < arguments.length; i += 2) { ret[arguments[i]] = arguments[i + 1]; } return ret; }\r\ncontext[\"dictKeys\"] = function(dict) { return Object.keys(dict) }\r\ncontext[\"parseInt\"] = parseInt\r\ncontext[\"nullCheck\"] = function(a) { return a; }\r\n\r\nfunction main(input) {\r\nlet lines = (input).split(\"\\n\");\r\nlet ret = \"\";\r\nlet line_ord = 0;\r\nlet nt = context.parseInt(lines[line_ord]);\r\nline_ord = context.parseInt(line_ord+1);\r\nfor (let t = 0; t0&&ok) {\r\nlet idx = context.parseInt(0-1);\r\nfor (let i = 1; i<(arr).length; i = context.parseInt(i+1)) {\r\nif (arr[i]==arr[0]) {\r\nidx = i;\r\nbreak;\r\n}\r\n\r\n}\r\nif (idx==context.parseInt(0-1)) {\r\nok = false;\r\nbreak;\r\n}\r\nlet new_arr = [];\r\nfor (let j = 1; j0; j = context.parseInt(j-1)) {\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\nfor (let j = context.parseInt(idx+1); j<(arr).length; j = context.parseInt(j+1)) {\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\n(splits).push(context.parseInt(idx*2));\r\noffset = context.parseInt(offset+context.parseInt(idx*2));\r\narr = new_arr;\r\n\r\n}\r\nif (!ok) {\r\nret = ret+\"-1\\n\";\r\n} else {ret = ret+(\"\" + ((insertions).length))+\"\\n\";\r\nfor (let i = 0; i<(insertions).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (insertions[i][0]))+\" \"+(\"\" + (insertions[i][1]))+\"\\n\";\r\n\r\n}\r\nret = ret+(\"\" + ((splits).length))+\"\\n\";\r\nfor (let i = 0; i<(splits).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (splits[i]))+\"\\n\";\r\n\r\n}\r\n}\r\n\r\n}\r\nreturn ret;\r\n}\r\n\r\n\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8')\r\nconsole.log(main(input));"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let [i, count] of map) if (count & 1) return -1;\r\n let nums = [...a];\r\n const ops = [],\r\n res = [];\r\n for (let i = 0, j = 0; i < n; i = j) {\r\n j = i + 1;\r\n while (nums[j] !== nums[i]) {\r\n j++;\r\n }\r\n let t = j;\r\n while (i < t) {\r\n const num = nums[i];\r\n if (num !== nums[j]) {\r\n ops.push([j, num]);\r\n nums.splice(j, 0, num, num);\r\n }\r\n i++;\r\n j++;\r\n }\r\n res.push((j - i) * 2);\r\n }\r\n let str = '';\r\n if (ops.length) {\r\n str += `${ops.length}\\n${ops.map(arr => arr.join(' ')).join('\\n')}`;\r\n } else {\r\n str += 0;\r\n }\r\n str += `\\n${res.length}\\n${res.join(' ')}`;\r\n return str;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "let context = {}\r\ncontext[\"throw\"] = function(a) { throw a }\r\ncontext[\"makeDict\"] = function() { let ret = {}; for (let i = 0; i < arguments.length; i += 2) { ret[arguments[i]] = arguments[i + 1]; } return ret; }\r\ncontext[\"dictKeys\"] = function(dict) { return Object.keys(dict) }\r\ncontext[\"parseInt\"] = parseInt\r\ncontext[\"nullCheck\"] = function(a) { return a; }\r\n\r\nfunction main(input) {\r\nlet lines = (input).split(\"\\n\");\r\nlet ret = \"\";\r\nlet line_ord = 0;\r\nlet nt = context.parseInt(lines[line_ord]);\r\nline_ord = context.parseInt(line_ord+1);\r\nfor (let t = 0; t0&&ok) {\r\nlet idx = context.parseInt(0-1);\r\nfor (let i = 1; i<(arr).length; i = context.parseInt(i+1)) {\r\nif (arr[i]==arr[0]) {\r\nidx = i;\r\nbreak;\r\n}\r\n\r\n}\r\nif (idx==context.parseInt(0-1)) {\r\nok = false;\r\nbreak;\r\n}\r\nlet new_arr = [];\r\nfor (let j = 1; j0; j = context.parseInt(j-1)) {\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\nfor (let j = context.parseInt(idx+1); j<(arr).length; j = context.parseInt(j+1)) {\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\n(splits).push(context.parseInt(idx*2));\r\noffset = context.parseInt(offset+context.parseInt(idx*2));\r\narr = new_arr;\r\n\r\n}\r\nif (!ok) {\r\nret = ret+\"-1\\n\";\r\n} else {ret = ret+(\"\" + ((insertions).length))+\"\\n\";\r\nfor (let i = 0; i<(insertions).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (insertions[i][0]))+\" \"+(\"\" + (insertions[i][1]))+\"\\n\";\r\n\r\n}\r\nret = ret+(\"\" + ((splits).length))+\"\\n\";\r\nfor (let i = 0; i<(splits).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (splits[i]))+\"\\n\";\r\n\r\n}\r\n}\r\n\r\n}\r\nreturn ret;\r\n}\r\n\r\n\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8')\r\nconsole.log(main(input));"}, {"source_code": "let context = {}\r\ncontext[\"throw\"] = function(a) { throw a }\r\ncontext[\"makeDict\"] = function() { let ret = {}; for (let i = 0; i < arguments.length; i += 2) { ret[arguments[i]] = arguments[i + 1]; } return ret; }\r\ncontext[\"dictKeys\"] = function(dict) { return Object.keys(dict) }\r\ncontext[\"parseInt\"] = parseInt\r\ncontext[\"nullCheck\"] = function(a) { return a; }\r\n\r\nfunction main(input) {\r\nlet lines = (input).split(\"\\n\");\r\nlet ret = \"\";\r\nlet line_ord = 0;\r\nlet nt = context.parseInt(lines[line_ord]);\r\nline_ord = context.parseInt(line_ord+1);\r\nfor (let t = 0; t0&&ok) {\r\nlet idx = context.parseInt(0-1);\r\nfor (let i = 1; i<(arr).length; i = context.parseInt(i+1)) {\r\nif (arr[i]==arr[0]) {\r\nidx = i;\r\nbreak;\r\n}\r\n\r\n}\r\nif (idx==context.parseInt(0-1)) {\r\nok = false;\r\nbreak;\r\n}\r\nlet new_arr = [];\r\nfor (let j = context.parseInt(idx-1); j>0; j = context.parseInt(j-1)) {\r\n(insertions).push([context.parseInt(context.parseInt(offset+context.parseInt(idx*2))-j),arr[j]]);\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\nfor (let j = context.parseInt(idx+1); j<(arr).length; j = context.parseInt(j+1)) {\r\n(new_arr).push(arr[j]);\r\n\r\n}\r\n(splits).push(context.parseInt(idx*2));\r\noffset = context.parseInt(offset+context.parseInt(idx*2));\r\narr = new_arr;\r\n\r\n}\r\nif (!ok) {\r\nret = ret+\"-1\\n\";\r\n} else {ret = ret+(\"\" + ((insertions).length))+\"\\n\";\r\nfor (let i = 0; i<(insertions).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (insertions[i][0]))+\" \"+(\"\" + (insertions[i][1]))+\"\\n\";\r\n\r\n}\r\nret = ret+(\"\" + ((splits).length))+\"\\n\";\r\nfor (let i = 0; i<(splits).length; i = context.parseInt(i+1)) {\r\nret = ret+(\"\" + (splits[i]))+\"\\n\";\r\n\r\n}\r\n}\r\n\r\n}\r\nreturn ret;\r\n}\r\n\r\n\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8')\r\nconsole.log(main(input));"}], "src_uid": "a88199a7adfe27866922a51f7bcc7367"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i< t; i++){\n\t\tlet n = nl.num();\n\t\tlet s = nl.nums().reduce((a, b) => a + b, 0);\n\t\tans.push(s%n > 0?1:0);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var a = lines[i].split(' ').map(Number);\n\t var sum = 0;\n\t for(j = 0; j < n; j++){\n\t sum += a[j];\n\t }\n\t var min = Math.floor(sum / n);\n\t var max = Math.ceil(sum / n);\n\t console.log(max - min);\n\t }\n\t}\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var k = lines[i].split(' ').map(Number);\n\t var sum = 0;\n\t for(j = 0; j < n; j++){\n\t sum += k[j];\n\t }\n\t var min = Math.floor(sum / n);\n\t var max = Math.ceil(sum / n);\n\t console.log(max - min);\n\t }\n\t}\n});\n\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n \r\n for (let i = 2; i < lines.length; i+=2) {\r\n if (!lines[i]) continue;\r\n \r\n let sum = lines[i].split(' ').reduce((a, b) => parseInt(a) + parseInt(b), 0);\r\n \r\n console.log(sum % lines[i-1] ? 1 : 0)\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n const n = Number(readline());\r\n\r\n // var [a, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var sum = 0\r\n var a = readline().split(' ').map((x, iii) => {\r\n sum+=Number(x)\r\n return Number(x)\r\n })\r\n // console.log(sum)\r\n if(sum %n ===0) return console.log(0)\r\n return console.log(1)\r\n// console.log(a)\r\n// console.log(n)\r\n // if(i===(string.length-2)) return console.log(string)\r\n })\r\n}\r\n\r\n"}, {"source_code": "var total = parseInt(readline());\r\n\r\nfor(var i=0; i 0) {\n\t\t\tvar flag = true;\n\t\t\tfor (var i = 0; i < 10; i++) {\n\t\t\t\tif ((+(a + '' + i)%b) === 0) {\n\t\t\t\t\ta = +(a + '' + i);\n\t\t\t\t\tflag = false;\n\n\t\t\t\t\tif (i === 0) {\n\t\t\t\t\t\ta = a.toString();\n\t\t\t\t\t\twhile (n-- > 0){\n\t\t\t\t\t\t\ta += '0';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (flag) return -1;\n\t\t}\n\n\t\treturn a;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));\n", "positive_code": [{"source_code": "print(function(a, b, n) {\n\n\tvar i, ans = [];\n\n\tn--;\n\tfor (i = 0; i <= 9; i++)\n\t\tif ((a * 10 + i) % b === 0) {\n\t\t\tans.push(a * 10 + i);\n\t\t\tbreak;\n\t\t}\n\n\tif (ans.length === 0)\n\t\treturn -1;\n\n\twhile (n--)\n\t\tans.push(0);\n\n\treturn ans.join('');\n\n} .apply(0, readline().split(' ').map(Number)));"}], "negative_code": [{"source_code": "print(function(a, b, n) {\n\n\tvar i, ans = [];\n\n\tn--;\n\tfor (i = 0; i < 9; i++)\n\t\tif ((a * 10 + i) % b === 0) {\n\t\t\tans.push(a * 10 + i);\n\t\t\tbreak;\n\t\t}\n\n\tif (ans.length === 0)\n\t\treturn -1;\n\n\twhile (n--)\n\t\tans.push(0);\n\n\treturn ans.join('');\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\tprint(function (a, b, n) {\n\t\twhile (n--) {\n\t\t\tif (a%10) {\n\t\t\t\tvar flag = true;\n\t\t\t\tfor (var i = 0; i < 10; i++) {\n\t\t\t\t\tif ((+(a + '' + i)%b) === 0) {\n\t\t\t\t\t\ta = +(a + '' + i);\n\t\t\t\t\t\tflag = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (flag) return -1;\n\t\t\t} else {\n\t\t\t\tn++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\ta = a.toString();\n\t\twhile (n-- > 0) a += '0';\n\n\t\treturn a;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}, {"source_code": ";(function () {\n\tprint(function (a, b, n) {\n\t\twhile (n--) {\n\t\t\tvar flag = true;\n\t\t\tfor (var i = 0; i < 10; i++) {\n\t\t\t\tif ((+(a + '' + i)%b) === 0) {\n\t\t\t\t\ta = +(a + '' + i);\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (flag) return -1;\n\t\t}\n\n\t\treturn a;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}, {"source_code": ";(function () {\n\tprint(function (a, b, n) {\n\t\twhile (n--) {\n\t\t\tif (a%10) {\n\t\t\t\tvar flag = true;\n\t\t\t\tfor (var i = 0; i < 10; i++) {\n\t\t\t\t\tif ((+(a + '' + i)%b) === 0) {\n\t\t\t\t\t\ta = +(a + '' + i);\n\t\t\t\t\t\tflag = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (flag) return -1;\n\t\t\t} else break;\n\t\t}\n\n\t\ta = a.toString();\n\t\twhile (n--) a += '0';\n\n\t\treturn a;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}], "src_uid": "206eb67987088843ef42923b0c3939d4"} {"source_code": "function main()\n{\n var n = parseInt(readline());\n var str = readline();\n if(str.length % n != 0){print(-1); return;}\n var mas = new Array(26);\n for(var i = 0; i < 26; ++i)\n {\n mas[i] = 0;\n }\n for(var i = 0; i < str.length; ++i)\n {\n mas[str.charCodeAt(i)-97] ++;\n }\n for(var i = 0; i < 26; ++i)\n {\n if(mas[i] != 0 && mas[i] % n != 0){print(-1); return;}\n }\n var new_str = \"\";\n for(var i = 0; i < n; ++i)\n {\n for(var j = 0; j < 26; ++j)\n {\n if(mas[j] != 0)\n {\n for(var h = mas[j] / n; h > 0; --h)\n {\n new_str = new_str + String.fromCharCode(j + 97);\n }\n }\n }\n }\n print(new_str);\n}\nmain();", "positive_code": [{"source_code": "var k=+readline();\nvar s={};\nreadline().split('').forEach(function(c){\n\tif( s[c] ){\n\t\ts[c]++;\n\t}else{\n\t\ts[c]=1;\n\t}\n});\nvar f=false;\nObject.keys(s).forEach(function(c){\n\tif( s[c]%k===0 ){\n\t\ts[c]=repeat(s[c]/k, c);\n\t}else{\n\t\tf=true;\n\t}\n});\nif(f){\n\tprint(-1);\n\tquit();\n}\ns = Object.keys(s).map(function(c){return s[c];}).join('');\nvar ans='';\nfor(var i=0; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const n = +readLine();\n const str = readLine();\n const map = str.split(\"\").reduce((obj, char) => {\n obj[char] = (obj[char] || 0) + 1;\n return obj;\n }, {});\n const keys = Object.keys(map);\n const imPossible = Object.values(map).some((val) => val % n !== 0);\n\n if (n === 1) {\n console.log(str);\n } else if (!imPossible) {\n let pattern = ``;\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n pattern += key.repeat(map[key] / n);\n }\n console.log(pattern.repeat(n));\n } else {\n console.log(-1);\n }\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar k = parseInt(readline()),\n\t\ts = trim(readline()),\n\t\tn = s.length,\n\t\tletters = [],\n\t\tletterCount = {};\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar ch = s.charAt(i);\n\t\tif (letterCount[ch] === undefined) {\n\t\t\tletters.push(ch);\n\t\t\tletterCount[ch] = 0;\n\t\t}\n\t\tletterCount[ch] += 1;\n\t}\n\tletters.sort();\n\tvar word = [], result = [];\n\tfor (var i = 0; i < letters.length; ++i) {\n\t\tvar letter = letters[i], count = letterCount[letter];\n\t\tif (count % k != 0) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t\tfor (var j = count / k; j != 0; --j) {\n\t\t\tword.push(letter);\n\t\t}\n\t}\n\tword = word.join('');\n\tfor (var i = 0; i < k; ++i) {\n\t\tresult.push(word);\n\t}\n\tprint(result.join(''));\n}\n\nmain();\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet k = readLine() >> 0;\n\tlet s = readLine().split('');\n\tlet store = {};\n\ts.forEach(ch => (store[ch] = (store[ch] || 0) + 1));\n\tlet keys = Object.keys(store);\n\tlet l = keys.length;\n\tlet str = '';\n\tfor (let i = 0; i < l; i++) {\n\t\tif (store[keys[i]] % k !== 0) {\n\t\t\tconsole.log(-1);\n\t\t\treturn;\n\t\t}\n\t\tstr += keys[i].repeat(store[keys[i]] / k);\n\t}\n\tconsole.log(str.repeat(k));\n}\n"}, {"source_code": "var n = +readline();\nvar s = readline().split('').sort();\ns.push('0');\nvar k = 1;\nvar ans = [];\nvar anst = [];\nfor (var i=0; i 0){\n ans += contact;\n k--;\n }\n print(ans);\n }else\n print(-1);\n}\nmain();"}], "negative_code": [{"source_code": ";(function () {\n\n\tvar k = +readline();\n\tvar m = readline().split('').reduce(function (p, e) { p[e] = p[e] ? p[e] + 1 : 1; return p; }, {});\n\n\tvar str = '';\n\tfor(var key in m) {\n\t\tif (m[key] % k) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t} else {\n\t\t\tvar l = m[key] / k;\n\t\t\twhile (l--) str += key;\n\t\t}\n\t}\n\n\tfor (var i = 0; i < k -1 ; i++) str += str;\n\tprint(str);\n\n}).call(this)"}, {"source_code": ";(function () {\n\n\tvar k = +readline();\n\tvar m = readline().split('').reduce(function (p, e) { p[e] = p[e] ? p[e] + 1 : 1; return p; }, {});\n\n\tvar str = '';\n\tfor(var key in m) {\n\t\tif (m[key] % k) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t} else {\n\t\t\tvar l = m[key] / k;\n\t\t\twhile (l--) str += key;\n\t\t}\n\t}\n\n\tvar r = '';\n\tfor (var i = 0; i < k; i++) r += str;\n\tprint(str);\n\n}).call(this)"}, {"source_code": ";(function () {\n\n\tvar k = +readline();\n\tvar m = readline().split('').reduce(function (p, e) { p[e] = p[e] ? p[e] + 1 : 1; return p; }, {});\n\n\tvar str = '';\n\tfor(var key in m) {\n\t\tif (m[key] % k) {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t} else {\n\t\t\tvar l = m[key] / k;\n\t\t\twhile (l--) str += key;\n\t\t}\n\t}\n\n\tvar r = '';\n\tfor (var i = 0; i < k -1 ; i++) r += str;\n\tprint(str);\n\n}).call(this)"}, {"source_code": "function main()\n{\n var n = parseInt(readline());\n var str = readline();\n if(str.length % n != 0){print(-1); return;}\n var mas = new Array(26);\n for(var i = 0; i < 26; ++i)\n {\n mas[i] = 0;\n }\n for(var i = 0; i < str.length; ++i)\n {\n mas[str.charCodeAt(i)-97] ++;\n }\n var memory = -1;\n for(var i = 0; i < 26; ++i)\n {\n if(memory == -1 && mas[i] != 0){memory = mas[i];}\n if(mas[i] != 0 && mas[i] != memory){print(-1); return;}\n }\n var new_str = \"\", p = 0;\n for(var i = 0; i < memory; ++i)\n {\n for(var j = 0; j < 26; ++j)\n {\n if(mas[j] != 0)\n {\n new_str = new_str + String.fromCharCode(j + 97);\n }\n }\n }\n print(new_str);\n}\nmain();"}, {"source_code": "var n = +readline();\nvar s = readline().split('').sort();\nvar k = 1;\nvar ans = [];\nvar anst = [];\nfor (var i=0; i 0){\n for(var i = 0; i < a.length; i++){\n if(a[i] != 0){\n for(var j = 0; j < a[i] / n; j++)\n ans += String.fromCharCode(i + 'a'.charCodeAt(0));\n }\n }\n k--;\n }\n print(ans);\n }else\n print(-1);\n}\nmain();"}, {"source_code": "//var input = \"2\\naazz\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction test(arr, k){\n var n = k;\n for(var i = 0; i < arr.length; i++){\n if(arr[i] != 0)\n n--;\n if(arr[i] % k !=0)\n return false;\n }\n if(n != 0)\n return false;\n return true;\n}\n\nfunction main(){\n var k = parseInt(readline());\n var str = readline();\n var a = new Array(26);\n for(var i = 0; i < a.length; i++)\n a[i] = 0;\n for(var i = 0; i < str.length; i++)\n a[str.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n if(test(a, k)){\n var ans = \"\";\n while(k > 0){\n for(var i = 0; i < a.length; i++){\n if(a[i] != 0)\n ans += String.fromCharCode(i + 'a'.charCodeAt(0));\n }\n k--;\n }\n print(ans);\n }else\n print(-1);\n}\nmain();"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length - 1; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet k = readLine() >> 0;\n\tlet s = readLine().split('');\n\tlet store = {};\n\tif (s.length % k !== 0) {\n\t\tconsole.log(-1);\n\t\treturn;\n\t}\n\tif (k === 1) {\n\t\tconsole.log(s.join(''));\n\t\treturn;\n\t}\n\n\ts.forEach(ch => (store[ch] = (store[ch] || 0) + 1));\n\tlet g = gcdArr(...Object.values(store));\n\n\tlet str = '';\n\tif (g > 1) {\n\t\tObject.entries(store).forEach(([ch, cnt]) => {\n\t\t\tstr += ch.repeat(cnt / g);\n\t\t});\n\t\tconsole.log(str.repeat(k));\n\t} else {\n\t\tconsole.log(-1);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet k = readLine() >> 0;\n\tlet s = readLine().split('');\n\tlet store = {};\n\tif (s.length % k !== 0) {\n\t\tconsole.log(-1);\n\t\treturn;\n\t}\n\tif (k === 1) {\n\t\tconsole.log(s.join(''));\n\t\treturn;\n\t}\n\n\ts.forEach(ch => (store[ch] = (store[ch] || 0) + 1));\n\n\tif (Object.keys(store).length === 1) {\n\t\tconsole.log(s.join(''));\n\t\treturn;\n\t}\n\n\tlet g = gcdArr(...Object.values(store));\n\n\tlet str = '';\n\tif (g > 1) {\n\t\tObject.entries(store).forEach(([ch, cnt]) => {\n\t\t\tstr += ch.repeat(cnt / g);\n\t\t});\n\t\tconsole.log(str.repeat(k));\n\t} else {\n\t\tconsole.log(-1);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction gcdArr() {\n\tlet args = arguments;\n\tlet res = args[0];\n\tlet { length } = args;\n\tfor (let i = 1; i < length; i++) {\n\t\tres = gcd(res, args[i]);\n\t}\n\treturn res;\n}\n\nfunction main() {\n\tlet k = readLine() >> 0;\n\tlet s = readLine().split('');\n\tlet store = {};\n\tif (s.length % k !== 0) {\n\t\tconsole.log(-1);\n\t\treturn;\n\t}\n\tif (k === 1) {\n\t\tconsole.log(s.join(''));\n\t\treturn;\n\t}\n\n\ts.forEach(ch => (store[ch] = (store[ch] || 0) + 1));\n\tlet g = gcdArr(...Object.values(store));\n\n\tlet str = '';\n\tif (g > 1) {\n\t\tObject.entries(store).forEach(([ch, cnt]) => {\n\t\t\tstr += ch.repeat(cnt / g);\n\t\t});\n\t\tconsole.log(str.repeat(k));\n\t} else {\n\t\tconsole.log(-1);\n\t}\n}\n"}], "src_uid": "f5451b19cf835b1cb154253fbe4ea6df"} {"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor]))next_string += input_stdin[input_cursor], input_cursor += 1;\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\n\nconst N = 2e5 + 2;\nlet fd = new Array(N);\nlet a = new Array(N);\n\nfunction solve(){\n let n = nextInt();\n fd.fill(-1);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n let an = N + 2, flg = false;\n for (let i = 0; i < n; i++){\n if (fd[a[i]] !== -1){\n an = Math.min(an, i - fd[a[i]] + 1);\n flg = true;\n }\n fd[a[i]] = i;\n }\n console.log(flg ? an : -1);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}", "positive_code": [{"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 2e5 + 2;\nlet frq = new Array(N);\nlet a = new Array(N);\n\nfunction solve(){\n let n = nextInt();\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(-1);\n return;\n }\n let l = 0, an = N + 2, flg = false;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n flg = true;\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(flg ? an : -1);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}, {"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 200000 + 2;\nlet frq = new Array(N);\nlet a = new Array(N);\n\nfunction solve(){\n let n = nextInt();\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(-1);\n return;\n }\n let l = 0, an = N + 2, flg = false;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n flg = true;\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(flg ? an : -1);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}, {"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 200000 + 2;\nlet frq = new Array(N);\n\nfunction solve(){\n let n = nextInt();\n let a = new Array(n + 1);\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(-1);\n return;\n }\n let l = 0, an = N + 2, flg = false;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n flg = true;\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(flg ? an : -1);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}], "negative_code": [{"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 20002;\n\nfunction solve(){\n let n = nextInt();\n let a = new Array(n + 1);\n let frq = new Array(N);\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(-1);\n return;\n }\n let l = 0, an = N + 2;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(an);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}, {"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 20002;\n\nfunction solve(){\n let n = nextInt();\n let a = new Array(n + 1);\n let frq = new Array(N);\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(n);\n return;\n }\n let l = 0, an = N + 2;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(an);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}, {"source_code": "function nextInt() { return parseInt(nextString()); }\nfunction nextFloat() { return parseFloat(nextString()); }\nlet input_stdin = \"\";\nlet input_cursor = 0;\nfunction nextString() {\n let next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) return input_stdin[input_cursor++]; else return '\\0';\n}\nprocess.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nprocess.stdin.on('data', function (data) { input_stdin += data; });\nprocess.stdin.on('end', function () { main(); });\nfunction isWhitespace(character) { return ' \\t\\n\\r\\v'.indexOf(character) > -1; }\nfunction clearWhitespaces() { while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) input_cursor += 1; }\n\nconst N = 20002;\n\nfunction solve(){\n let n = nextInt();\n let a = new Array(n + 1);\n let frq = new Array(N);\n frq.fill(0);\n for (let i = 0; i < n; i++)a[i] = nextInt();\n if (n === 1){\n console.log(-1);\n return;\n }\n let l = 0, an = N + 2, flg = false;\n for (let r = 0; r < n; r++){\n frq[a[r]]++;\n while(frq[a[r]] > 1){\n flg = true;\n frq[a[l]]--;\n an = Math.min(an, r - l + 1);\n l++;\n }\n }\n console.log(flg ? an : -1);\n}\n\nfunction main() {\n let t = nextInt();\n while(t--)solve();\n}"}], "src_uid": "a4be9b3484f3f24014392a1c3ad23f2f"} {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet x = parseInt(readLine())\n\tlet chances=readLine()\n\tlet a=0,d=0\n\n\tfor(let chance of chances){\n\t\tif(chance=='A')\n\t\t\ta++\n\t\telse d++\n\t}\n\n\tif(a>d)\n\t\tconsole.log('Anton')\n\telse if(d>a)\n\t\tconsole.log('Danik')\n\telse console.log('Friendship')\n}", "positive_code": [{"source_code": "var h = Math.floor(+readline() / 2);\nvar\ts = readline();\n\nvar res = 0;\nfor (var i = 0, len = s.length; i < len && Math.abs(res) <= h; ++i) {\n\ts[i] == \"A\" ? res++ : res--;\n}\n\nif (res == 0) {\n\tprint(\"Friendship\");\n} else if (res > 0) {\n\tprint(\"Anton\");\n} else {\n\tprint(\"Danik\");\n}"}, {"source_code": "var count = readline();\nvar input = readline();\n\nvar Danik = input.replace(/A/g, '');\n\nif(input.length / 2 > Danik.length)\n print(\"Anton\");\nelse if(input.length / 2 === Danik.length)\n print(\"Friendship\");\nelse \n print(\"Danik\");\n"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar main = function main() {\n var read = function read() {\n return readline().split(' ');\n };\n var readints = function readints() {\n return read().map(parseInt);\n };\n\n var _readints = readints(),\n _readints2 = _slicedToArray(_readints, 1),\n n = _readints2[0];\n\n var s = readline();\n\n var count = function count(s, p) {\n return s.split(p).length - 1;\n };\n\n var A = count(s, 'A');\n var D = count(s, 'D');\n\n if (A > D) {\n print('Anton');\n } else if (A < D) {\n print('Danik');\n } else {\n print('Friendship');\n }\n};\n\nmain();\n"}, {"source_code": "var ss = readline();\nvar a = readline(); var c = 0;\nfor (var i = 0; i < a.length; i++) { if(a[i] == 'A') c++; }\nif (c == a.length / 2) {\n print('Friendship');\n} else {\n\tprint (c > a.length / 2 ? 'Anton' : 'Danik');\n}"}, {"source_code": " n = readline();\n m = readline();\n var A = 0;\n var D = 0;\n for(var i = 0; i < n; i++)\n {\n m[i] == \"A\" ? A++ : D++;\n }\n if(A > D)\n {\n print(\"Anton\");\n }\n else if (D > A)\n {\n print(\"Danik\");\n }\n else{\n print(\"Friendship\");\n }"}, {"source_code": "var n = readline();\nvar s = readline();\n\nvar numA = s.match(/A/g)?s.match(/A/g).length:0;\nvar numD = s.match(/D/g)?s.match(/D/g).length:0;\n\nif(numA == numD)\n\tprint('Friendship');\nelse if(numA > numD)\n\tprint('Anton');\nelse\n\tprint('Danik');"}, {"source_code": "var n = readline();\nvar s = readline();\nvar numA=0,\n\tnumD=0;\n\nfor(var i=0;inumD)\n\tprint('Anton');\nelse if(numA {\n const n = Number.parseInt(readline());\n const s = readline();\n var balance = 0;\n for (var i = 0; i < n; i++) {\n balance += (s[i] == 'A') ? 1 : -1;\n }\n if (balance > 0)\n return 'Anton';\n else if (balance < 0)\n return 'Danik';\n else\n return 'Friendship';\n};\n\nwrite(main());"}, {"source_code": "var n = parseInt(readline(), 10),\n s = readline().split(''),\n A = 0,\n D = 0;\n \nfor(var el of s) {\n el === 'A' ? A++ : D++;\n}\n\nprint(A === D ? 'Friendship' : A > D ? 'Anton' : 'Danik');"}, {"source_code": "(function main() {\n\tvar n = readline();\n\tvar line = readline();\n\tvar len = parseInt(n);\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tvar c = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\n\t\t//print('aCon: ' + aCon + ' ,dCon: ' + dCon);\n\t\n\tif (aCon > dCon) {\n\t\tprint('Anton');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Danik');\n\t}\n\tc++;\n\n})();"}, {"source_code": "var v1 = readline();\nvar v2 = readline();\nvar a = 0;\nvar i = 0;\n \nwhile(i< v1 && a<= v1/2){\n if(v2[i] == 'A'){\n a++;\n }\n i++;\n}\n \nvar result = a > v1/2 ? 'Anton' : (a < v1/2 ? 'Danik' : 'Friendship');\nprint(result);"}, {"source_code": "var a = readline(), b = readline(), c = 0;\n\nfor (; a; a--) b[a - 1] === 'A' ? c++ : c--;\nprint(c > 0 ? 'Anton' : c < 0 ? 'Danik' : 'Friendship');"}, {"source_code": "'use strict'\nlet a = readline(), b = readline(), c = 0;\n\nfor (; a; a--) b[a - 1] === 'A' ? c++ : c--;\nprint(c > 0 ? 'Anton' : c < 0 ? 'Danik' : 'Friendship');"}, {"source_code": "var a = readline(), b = readline(), c = d = 0;\n\nfor (; a; a--) {\n if (b[a - 1] === \"A\") c++;\n\telse d++;\n}\n\nprint(c > d ? 'Anton' : c < d ? 'Danik' : 'Friendship');"}, {"source_code": "'use strict'\nreadline();\nlet a, b = 0;\nfor (a of [...readline()]) a === 'A' ? b++ : b--;\nprint(b > 0 ? 'Anton' : b < 0 ? 'Danik' : 'Friendship');"}, {"source_code": "readline();\nvar a, b = 0;\nfor (a of [...readline()]) a === 'A' ? b++ : b--;\nprint(b > 0 ? 'Anton' : b < 0 ? 'Danik' : 'Friendship');"}, {"source_code": "var a = readline(), b = readline(), c = d = 0;\n\nfor (; a; a--) b[a - 1] === 'A' ? c++ : d++;\nprint(c > d ? 'Anton' : c < d ? 'Danik' : 'Friendship');"}, {"source_code": "function main(){\n var n = readline();\n var arr = readline();\n var a = 0;\n var d = 0;\n for (var i = 0; i < arr.length; i++) {\n if(arr[i] == 'A') a +=1;\n else d +=1;\n }\n if(a == d) print(\"Friendship\");\n else if(a > d) print('Anton');\n else print('Danik');\n}\nmain();"}, {"source_code": "var s = readline();\ns= readline();\nvar a=0, d=0;\nfor(var i=0; i< s.length; i++){\n a += (s[i]==='A');\n d += (s[i]==='D');\n}\nprint(a > d ? \"Anton\" : d > a ? \"Danik\" : \"Friendship\");"}, {"source_code": "(function main(){\n //http://codeforces.com/problemset/problem/734/A\n var jugados = readline();\n var datos = readline();\n\n var anton = 0;\n var danik = 0;\n\n for (var i = 0; i < jugados; i++) {\n if(datos[i] == \"A\"){\n anton++;\n }else{\n danik++;\n }\n }\n var salida;\n if(anton>danik){\n salida = 'Anton';\n }else if(antonc==='A'?a-1:a+1,0)\nprint(X>0?'Danik':(X<0?'Anton':'Friendship'))\n"}, {"source_code": "var n = readline();\nvar s = readline();\n\nvar no_of_A_wins = 0;\nvar no_of_D_wins = 0;\n\nfor(var i =0; i <= s.length - 1; i++){\n if(s[i] == \"A\"){\n no_of_A_wins = no_of_A_wins + 1;\n } else {\n no_of_D_wins = no_of_D_wins + 1;\n }\n}\n\nif(no_of_A_wins > no_of_D_wins){\n write(\"Anton\");\n} else if (no_of_A_wins < no_of_D_wins) {\n write(\"Danik\");\n} else {\n write(\"Friendship\");\n}"}, {"source_code": "let inputBuffer = \"\", curLine = 0;\n\nfunction readline() {\n\treturn inputBuffer[curLine++];\n}\n\nlet curTokens = [], curToken = 0;\n\nfunction next() {\n\twhile (curToken >= curTokens.length) {\n\t\tcurTokens = readline().split(/[\\s]+/);\n\t\tcurToken = 0;\n\t}\n\treturn curTokens[curToken++];\n}\n\nfunction nextInt () {\n\treturn parseInt(next(), 10);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\nprocess.stdin.on('data', (chunk) => {\n\tinputBuffer += chunk;\n});\n\nprocess.stdin.on('end', () => {\n\tinputBuffer = inputBuffer.trim().split('\\n').map(line => line.trim());\n\tmain();\n});\n\n\n\nfunction print(data) {\n\tprocess.stdout.write(data + \"\\n\");\n}\n\nfunction main () {\n\tlet n = nextInt();\n\tlet s = next();\n\tlet a = 0, d = 0;\n\n\tfor(let i = 0; i < n; i++) {\n\t\tif(s[i] === 'A') a++;\n\t\tif (s[i] === 'D') d++;\n\t}\n\n\tif (a === d) print('Friendship');\n\tif (a > d) print('Anton');\n\tif (a < d) print('Danik');\n}"}, {"source_code": "var s = readline();\ns= readline();\nvar a=0, d=0;\nfor(var i=0; i< s.length; i++){\n a += (s[i]==='A');\n d += (s[i]==='D');\n}\nprint(a > d ? \"Anton\" : d > a ? \"Danik\" : \"Friendship\");"}, {"source_code": "n = Number(readline());\na = [].reduce.call(readline(), (res, i) => res - (i === 'D'), n/2);\nprint(a > 0 ? 'Anton' : a < 0 ? 'Danik' : 'Friendship')\n"}, {"source_code": "readline();print((function(x){return x > 0 ? 'Danik' : x < 0 ? 'Anton' : 'Friendship'})([].reduce.call(readline(), (res, i) => i === 'D' ? res + 1 : res - 1, 0)))\n"}, {"source_code": "var A=0;\nvar D=0;\nvar n = parseInt(readline());\nvar input =readline();\nfor(var i=0;iD)\n print('Anton');\nelse if(D>A)\n print('Danik');\nelse\n print('Friendship');"}, {"source_code": "n = Number(readline());\nx = readline().replace(/A/g,\"\");\nprint([\"Anton\",[\"Friendship\",\"Danik\"][Number(x.length!=(n/2))]][Number(x.length>=(n/2))])\n"}, {"source_code": "function main(){\n var n = +readline();\n var arr = readline().split('');\n var A = 0;\n var D = 0;\n for(var i = 0; i < n; ++i){\n if(arr[i] === 'A') ++A;\n else ++D;\n }\n if(A < D) {\n print('Danik');\n return;\n }\n if(A > D){\n print('Anton');\n return;\n }\n print('Friendship');\n}\n\nmain();"}, {"source_code": "const readline = require(\"readline\");\n\nlet inputs = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nrl.on(\"line\", line => inputs.push(line));\n\nrl.on(\"close\", () => console.log(solution(inputs)));\n\nfunction solution(data) {\n const [_, games] = data;\n const won = Math.floor(games.length / 2) + 1;\n const anton = games.split(\"\").filter(x => x === \"A\");\n let ans;\n if (anton.length >= won) {\n ans = \"Anton\";\n } else if (games.length - anton.length >= won) {\n ans = \"Danik\";\n } else {\n ans = \"Friendship\";\n };\n\treturn ans;\n};\n\n\n"}, {"source_code": "const readline = require(\"readline\");\n\nlet inputs = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nrl.on(\"line\", line => inputs.push(line));\n\nrl.on(\"close\", () => console.log(solution(inputs)));\n\nfunction solution(data) {\n const [_, games] = data;\n //const won = Math.floor(games.length / 2) + 1;\n //const anton = games.split(\"\").filter(x => x === \"A\");\n //let ans;\n //if (anton.length >= won) {\n // ans = \"Anton\";\n //} //else if (games.length - anton.length >= won) {\n // ans = \"Danik\";\n //} else {\n // ans = \"Friendship\";\n //};\n\t//return ans;\n\n const score = {\n A: 0,\n D: 0\n }\n games.split(\"\").forEach(x => score[x]++);\n if (score.A > score.D) {\n ans = \"Anton\";\n } else if (score.D > score.A) {\n ans = \"Danik\";\n } else {\n ans = \"Friendship\";\n };\n return ans;\n};\n\n\n"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.on('line', input => {\n if (!/\\d+/.test(input)) {\n let len = input.split('').filter(c => c == 'A').length\n if (len > input.length / 2)\n console.log('Anton')\n else if (len < input.length / 2)\n console.log('Danik')\n else\n console.log('Friendship')\n rl.close()\n }\n})"}, {"source_code": "var n = parseInt(readline());\n\tvar s = readline().split(\"\");\n\tvar len = s.length;\n\tvar ans = 0;\n\tfor(var i = 0; i < len; i++)\n\t{\n\t\tif(s[i] == 'A')\n\t\t\tans ++;\n\t}\n\tvar flag;\n\tif(ans > len-ans)\n\t{\n\t\tflag = \"Anton\";\n\t}\n\telse if(ans < len-ans)\n\t{\n\t\tflag = \"Danik\";\n\t}\n\telse flag = \"Friendship\";\n\tprint(flag);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet length;\n\nrl.on('line', n => {\n if (!length) { length = n; } else {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n const winner = aCount > dCount ? 'Anton' : aCount < dCount ? 'Danik' : 'Friendship';\n console.log(winner);\n rl.close();\n }\n});"}, {"source_code": "var num_games = parseInt(readline());\nvar results = readline().split(\"\");\nvar A = 0;\nvar D = 0;\nfor(var i =0; i< num_games; i++){\n if(results[i]=='A') A++;\n if(results[i]=='D') D++;\n}\nif(A > D)print(\"Anton\");\nelse if(D > A)print(\"Danik\");\nelse print('Friendship');"}, {"source_code": "var games = +readline();\nvar sequence = readline();\nAntonWinnings = sequence.split('').reduce(function(wins, letter){\n\treturn wins + (letter == 'A'?1:0);\n}, 0);\n\nif((games - AntonWinnings) > AntonWinnings){\n\tprint('Danik');\n}else if((games - AntonWinnings) < AntonWinnings){\n\tprint('Anton')\n}\nelse{\n\tprint('Friendship');\n}"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line, log) {\n var input = line.split(\" \");\n var logs = log.split(\" \");\n\n var n = input[0];\n var history = logs[0];\n\n var anton = 0;\n var denik = 0;\n\n while(n > 0){\n if(history[n - 1] == \"A\"){\n anton++;\n }else{\n denik++;\n }\n n--;\n }\n\n var winner = \"\";\n if(anton > denik){\n winner = \"Anton\";\n }else if(anton < denik){\n winner = \"Danik\";\n }else{\n winner = \"Friendship\";\n }\n\n return winner;\n}"}, {"source_code": "'use strict';\n\nlet inputBuffer = \"\", curLine = 0;\n\nfunction readline() {\n\treturn inputBuffer[curLine++];\n}\n\nlet curTokens = [], curToken = 0;\n\nfunction next() {\n\twhile (curToken >= curTokens.length) {\n\t\tcurTokens = readline().split(/[\\s]+/);\n\t\tcurToken = 0;\n\t}\n\treturn curTokens[curToken++];\n}\n\nfunction nextInt () {\n\treturn parseInt(next(), 10);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\nprocess.stdin.on('data', (chunk) => {\n\tinputBuffer += chunk;\n});\n\nprocess.stdin.on('end', () => {\n\tinputBuffer = inputBuffer.trim().split('\\n').map(line => line.trim());\n\tmain();\n});\n\n\n\nfunction print(data) {\n\tprocess.stdout.write(data + \"\\n\");\n}\n\nfunction main () {\n\tlet n = nextInt();\n\tlet s = next();\n\tlet a = 0, d = 0;\n\n\tfor(let i = 0; i < n; i++) {\n\t\tif(s[i] === 'A') a++;\n\t\tif (s[i] === 'D') d++;\n\t}\n\n\tif (a === d) print('Friendship');\n\tif (a > d) print('Anton');\n\tif (a < d) print('Danik');\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = parseInt(readline()), line2 = readline()\n let d = 0, a =0;\n for (var i = 0 ; i < n;i++){\n (line2[i] === 'A') ? a ++ : d ++ ;\n }\n let result = 'Friendship';\n if (a > d) result = \"Anton\"\n else if (d > a) result = \"Danik\"\n\n console.log(result)\n}\n\n"}, {"source_code": "var n = parseInt(readline());\nvar res=readline().split('');\nvar A=0,D=0;\n for(i=0;iD)\n print(\"Anton\");\n else if(D>A)\n print(\"Danik\");\n else\n print(\"Friendship\");"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\nvar n=parseInt(readline());\nvar str=readline();\nvar anton=0;\nvar danik=0;\nfor(var i=0;idanik){\n print('Anton')\n}else{\n print('Danik')\n}"}, {"source_code": "var all, lines, mainAux, print, readline, rl, rli, sum, who, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nsum = function(items) {\n return items.reduce(function(a, b) {\n return a + b;\n });\n};\n\nall = function(items) {\n var i, item, len;\n for (i = 0, len = items.length; i < len; i++) {\n item = items[i];\n if (!item) {\n return false;\n }\n }\n return true;\n};\n\nwho = function(n, gs) {\n var asum, g;\n asum = sum((function() {\n var i, len, results;\n results = [];\n for (i = 0, len = gs.length; i < len; i++) {\n g = gs[i];\n if (g === 'A') {\n results.push(1);\n } else {\n results.push(0);\n }\n }\n return results;\n })());\n if (asum > n - asum) {\n return print('Anton');\n } else if (asum < n - asum) {\n return print('Danik');\n } else {\n return print('Friendship');\n }\n};\n\nmainAux = function() {\n var g, n;\n n = parseInt(readline());\n g = readline();\n return who(n, g);\n};\n\n\n function main() {\n return mainAux();\n }\n;\n"}, {"source_code": "var numberMatch = +readline();\nvar secuenceWins = readline();\nvar Anton = 0;\nfor (var match=0; matchAnton) {\n print(\"Danik\");\n} else if (numberMatch-Anton obj['D']) {\n print('Anton');\n} else {\n print('Danik')\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const partii = parseInt(input[0], 10)\n const games = input[1]\n let result = ''\n if (partii > 1) {\n let anton = games.match(/(A)/g)\n if (anton) {\n anton = anton.length\n } else {\n anton = 0\n }\n result = anton > (partii / 2) ? 'Anton' : ( anton === (partii / 2) ? 'Friendship' : 'Danik')\n } else {\n result = games === 'A' ? 'Anton' : ( games === 'D' ? 'Danik' : 'Friendship')\n }\n console.log(result)\n})"}, {"source_code": "var n = readline();\nvar str = readline().split(\"\");\n\nvar cnt = {'A': 0, 'D': 0};\nfor(var s of str)\n\tcnt[s]++;\n\nif(cnt['A'] > cnt['D'])\n\tprint(\"Anton\");\nelse if(cnt['A'] < cnt['D'])\n\tprint(\"Danik\");\nelse\n\tprint(\"Friendship\")"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n const n = Number(readLine());\n const s = readLine().split('');\n const c = s.reduce((acc, cur) => acc + (cur === 'D' ? 1 : 0), 0);\n if (c === s.length / 2) {\n console.log('Friendship')\n } else if (c > s.length / 2) {\n console.log('Danik')\n } else {\n console.log('Anton')\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet counter = 0;\n\nrl.on('line', (d) => {\n if (counter === 0) {\n counter++;\n return;\n }\n\n let aCount = 0;\n let dCount = 0;\n\n for (let i = 0 ; i < d.length; i++) {\n if (d[i] === 'A') {\n aCount++;\n }\n else {\n dCount++;\n }\n }\n\n if (aCount > dCount) {\n console.log('Anton');\n }\n else if (dCount > aCount) {\n console.log('Danik');\n }\n else {\n console.log('Friendship');\n }\n\n counter++;\n});\n"}, {"source_code": "var inputLength = readline();\nvar matchResults = readline().split(\"\");\nvar anton = 0;\nvar danik = 0;\nmatchResults.forEach(result => {\n if(result === 'A') anton++;\n else danik++;\n});\nif(anton > danik) print('Anton');\nelse if(anton < danik) print('Danik');\nelse print('Friendship');\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const s = input[1];\n let d = 0, a = 0;\n for (let i = 0; i < s.length; i += 1) {\n if ( s[i] === 'D' ) d += 1;\n else a += 1;\n }\n\n console.log(\n a === d ? 'Friendship' : a < d ? 'Danik' : 'Anton'\n );\n});"}, {"source_code": "\n var length = parseInt(readline()), \n word = readline().split(''),\n Anton = 0,\n Danik = 0;\n for(var i = 0; i < length; i++){\n if(word[i] == 'A'){\n Anton++;\n } else {\n Danik++;\n }\n }\n if(Anton > Danik){\n print('Anton');\n } else if(Anton == Danik){\n print('Friendship');\n } else {\n print('Danik');\n }\n "}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const results = input[1];\n const ac = results.split(\"A\").length - 1;\n const dc = results.length - ac;\n if (ac == dc) console.log(\"Friendship\");\n else if (ac > dc) console.log(\"Anton\");\n else console.log(\"Danik\");\n});"}, {"source_code": "function main() {\n let anton = 0;\n let danik = 0;\n const size = nextInt();\n const str = next();\n for(let i=0; i < str.length; i++) {\n if(str[i] === 'A') {\n ++anton;\n } else if(str[i] === 'D') {\n ++danik;\n }\n }\n\n if(anton > danik) {\n print('Anton');\n } else if( danik > anton) {\n print('Danik');\n } else {\n print('Friendship');\n }\n\n}\n\n// auxiliary code\nvar curTokens = [],\n curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = \"\",\n curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + \"\\n\");\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\nprocess.stdin.on(\"data\", function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n var s = readLine().split(\"\");\n\n var Anton = 0,\n Danik = 0;\n\n for (var i = 0; i < n; i++) {\n if (s[i] == \"A\") {\n Anton++;\n } else {\n Danik++;\n }\n }\n\n if (Anton > Danik) {\n console.log(\"Anton\");\n } else if (Anton == Danik) {\n console.log(\"Friendship\");\n } else {\n console.log(\"Danik\");\n }\n}\n"}, {"source_code": "var l = readline()\nvar ar = readline().split('')\nvar a = ar.filter(t=>(t=='A')).length, b = ar.length - a\n\nif ( a > b ) {\n print('Anton')\n} else if (a===b){\n print('Friendship')\n} \nelse {\n print('Danik')\n}"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\nfor (let i = 1; i < txt.length; i += 2) {\n doit(txt[i]);\n\n}\n\nfunction doit(str) {\n let r = str.length - str.split(\"\").filter(data => {\n return data.length > 0 && data == \"D\";\n }).length;\n\n if (r == str.length - r) {\n console.log(\"Friendship\");\n } else if (r < str.length - r) {\n console.log(\"Danik\");\n } else {\n console.log(\"Anton\");\n\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let l = readAsInt();\n let s = readline();\n let d = s.replace(/A+/gi,'').length;\n let a = s.replace(/D+/gi,'').length;\n console.log(a > d ? 'Anton' : ( d > a ? 'Danik' : 'Friendship'));\n}\n \n\n\n"}, {"source_code": "var Ant = 0;\nvar Dan = 0;\nconst humans = {\n A: () => { Ant++; },\n D: () => { Dan++; }\n};\n\nvar buffer = '';\n\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', () => {\n let chunk;\n while ((chunk = process.stdin.read()) !== null) {\n buffer += chunk;\n }\n});\n\nprocess.stdin.on('end', solve);\n\nfunction solve() {\n buffer = buffer.split('\\r\\n');\n\n buffer[1].split('').forEach(element => {\n humans[element]();\n });\n\n process.stdout.write(Ant == Dan ? \"Friendship\" : Ant > Dan ? \"Anton\" : \"Danik\");\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().split('\\n');\n let numGames = +inputs[0];\n let winnerMsg = 'Friendship';\n for (let row of inputs[1].trim()) {\n\n if (row == 'A') {\n numGames--;\n }\n else {\n numGames++;\n }\n }\n\n if (numGames > +inputs[0]) {\n winnerMsg = 'Danik';\n }\n else if (numGames < +inputs[0]) {\n winnerMsg = 'Anton';\n }\n\n return winnerMsg.toString();\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\nvar a = 0;\nvar d = 0;\nfor (var i=0;id){\n\tprint(\"Anton\");\n} else if (d>a){\n\tprint(\"Danik\");\n} else {\n\tprint(\"Friendship\");\n}"}, {"source_code": "'use strict';\nlet n = parseInt(readline());\nlet danik = readline().replace(new RegExp('A', 'g'), '').length,\n anton = n - danik\n\nif(anton > danik) {\n write('Anton');\n} else if (danik > anton) {\n write('Danik');\n} else {\n write('Friendship');\n}"}, {"source_code": "var n = +readline(),\n line = readline(),\n dc = 0,\n ac = 0;\n\nfor(var i = 0; i < n; i++) {\n if (line[i] === \"D\") {\n dc++;\n } else {\n ac++;\n }\n}\n\nprint(dc > ac ? \"Danik\" : dc === ac ? \"Friendship\" : \"Anton\");\n\n\n"}, {"source_code": "var number=readline();\ncountA=0;\nvar string=readline();\n\nfor(var i = 0; i < number; i++){\n// print(string[i]);\n\n if(string[i] == \"A\"){\n countA++;\n // print(countA);\n }\n}\nif(countA > number / 2){\n print(\"Anton\");\n}\nelse if(countA == number / 2){\n print(\"Friendship\");\n}\nelse{\n print(\"Danik\");\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let count = 0;\n let s = readLine();\n for (var i = 0; i < n; i++) {\n if (s[i] == 'A') {\n count++\n } else count--;\n }\n if (count > 0) {\n console.log('Anton');\n } else if (count < 0) {\n console.log('Danik');\n } else console.log('Friendship');\n}"}, {"source_code": "var n = readline();\nvar str = readline();\n\nvar a = 0;\nvar d=0;\nfor (var i=0; id? print(\"Anton\"):print(\"Danik\")"}, {"source_code": "var nothing = readline();\nvar matches = readline();\n\nvar countA = 0;\nvar countD = 0;\n\nfor(var i = 0; i < matches.length; i++){\n if(matches[i] == \"A\") countA++\n else if(matches[i] == \"D\") countD++\n}\n\nif(countA > countD){\n print(\"Anton\")\n}else if(countA < countD){\n print(\"Danik\")\n}else{\n print(\"Friendship\")\n}"}, {"source_code": "var numberOfGames = readline().split(' ').map(Number);\nvar gameResult = readline().split('');\nvar aCounter = 0;\nvar dCounter = 0;\nvar result = '';\n\nfor(var i = 0; i < gameResult.length; i++) {\n if(gameResult[i] === 'A') {\n aCounter ++;\n }\n else if(gameResult[i] === 'D') {\n dCounter ++;\n }\n}\n\nif(aCounter > dCounter) {\n result = 'Anton';\n}\nelse if(dCounter > aCounter) {\n result = 'Danik';\n}\nelse {\n result = 'Friendship';\n}\n\nprint(result);"}], "negative_code": [{"source_code": "const readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nrl.on('line', input => {\n let len = input.split('').filter(c => c == 'A').length\n if (len > input.length / 2)\n console.log('Anton')\n else if (len < input.length / 2)\n console.log('Danik')\n else\n console.log('Friendship')\n rl.close()\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet friendCount, friendNums = [];\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n const winner = aCount > dCount ? 'Anton' : aCount < dCount ? 'Danik' : 'Friendship';\n console.log(winner);\n rl.close();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n if (aCount > dCount) console.log('Anton');\n if (aCount < dCount) console.log('Danik');\n // if (aCount === dCount) console.log('Friendship');\n rl.close();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n console.log(aCount);\n console.log(dCount);\n if (aCount > dCount) {\n console.log('Anton');\n rl.close();\n } else if (aCount < dCount) {\n console.log('Danik');\n rl.close();\n } else if (aCount === dCount) {\n console.log('Friendship');\n rl.close();\n }\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n if (aCount > dCount) console.log('Anton');\n if (aCount < dCount) console.log('Danik');\n if (aCount === dCount) console.log('Friendship');\n rl.close();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n const winner = aCount > dCount ? 'Anton' : aCount < dCount ? 'Danik' : 'Friendship';\n console.log(winner);\n rl.close();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n if (aCount > dCount) {\n console.log('Anton');\n } else if (aCount < dCount) {\n console.log('Danik');\n } else {\n console.log('Friendship');\n }\n rl.close();\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', n => {\n n = n.split('');\n const aCount = (n.filter(letter => letter === 'A')).length;\n const dCount = (n.filter(letter => letter === 'D')).length;\n if (aCount > dCount) {\n console.log('Anton');\n } else if (aCount < dCount) {\n console.log('Danik');\n } else if (aCount === dCount) {\n console.log('Friendship');\n }\n});"}, {"source_code": "var all, lines, mainAux, print, readline, rl, rli, sum, who, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nsum = function(items) {\n return items.reduce(function(a, b) {\n return a + b;\n });\n};\n\nall = function(items) {\n var i, item, len;\n for (i = 0, len = items.length; i < len; i++) {\n item = items[i];\n if (!item) {\n return false;\n }\n }\n return true;\n};\n\nwho = function(n, gs) {\n console.log(gs);\n switch (false) {\n case !(sum(gs.split('').map(function(g) {\n if (g === 'A') {\n return 1;\n } else {\n return 0;\n }\n })) > Math.floor(n / 2)):\n return print('Anton');\n case !(sum(gs.split('').map(function(g) {\n if (g === 'D') {\n return 1;\n } else {\n return 0;\n }\n })) > Math.floor(n / 2)):\n return print('Danik');\n default:\n return print('Friendship');\n }\n};\n\n//who = (n, gs) ->\n// asum = sum(\n// for g in gs\n// if g is 'A' then 1 else 0\n// )\n// if asum > n - asum then print('Anton')\n// else if asum < n - asum then print('Danik')\n// else print('Friendship')\nmainAux = function() {\n var g, n;\n n = parseInt(readline());\n g = readline();\n return who(n, g);\n};\n\n\n function main() {\n return mainAux();\n }\n;\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n/****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\n/**\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \n * when required.\n *\n * I am using console.log() to output\n */\nfunction main() {\n let t = readLine();\n \n antonAndDanik(t)\n \n}\n\nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n for (let char of str) {\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n for (let char of str) {\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x1 = readline();\n const x2 = readline();\n\n \n antonAndDanik(x2);\n }\n \nfunction antonAndDanik(str) {\n console.log(str)\n \n let aCount = 0;\n let dCount = 0;\n\n let strARR = str.split(\"\");\n\n \n for (let i = 0; i < strARR.length; i++) {\n const char = strARR[i];\n\n if (char == \"A\") aCount++;\n\n if (char == \"D\") dCount++;\n }\n \n \n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n for (let char of str) {\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else if(aCount==dCount) {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n let strARR = str.split(\"\");\n\n // for (let char of str) {\n // for (let char of strARR) {\n for (let i = 0; i < strARR.length; i++) {\n const char = strARR[i];\n\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "//%easy\nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n for (char of str) {\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}\n\nconsole.log(antonAndDanik(\"ADAAAA\"));\nconsole.log(antonAndDanik(\"DDDAADA\"));\nconsole.log(antonAndDanik(\"DADADA\"));\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const x = readline();\n\n antonAndDanik(x);\n}\n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n console.log(str)\n \n let aCount = 0;\n let dCount = 0;\n\n let strARR = str.split(\"\");\n\n \n for (let i = 0; i < strARR.length; i++) {\n const char = strARR[i];\n\n if (char == \"A\") aCount++;\n\n if (char == \"D\") dCount++;\n }\n \n \n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n let strARR = str.split(\"\");\n\n // for (let char of str) {\n for (let char of strARR) {\n if (char == \"A\") aCount++;\n\n if (char == \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n \n antonAndDanik(x);\n }\n \nfunction antonAndDanik(str) {\n let aCount = 0;\n let dCount = 0;\n\n let strARR = str.split(\"\");\n\n // for (let char of str) {\n for (let char of strARR) {\n if (char === \"A\") aCount++;\n\n if (char === \"D\") dCount++;\n }\n\n if (aCount > dCount) {\n console.log(\"Anton\");\n return \"Anton\";\n } else if (dCount > aCount) {\n console.log(\"Danik\");\n return \"Danik\";\n } else {\n console.log(\"Friendship\");\n return \"Friendship\";\n }\n}"}, {"source_code": "var input = '';\n\nprocess.stdin.on('data', (givenInput) => {\n input += givenInput;\n})\n\nprocess.stdin.on('end', () => {\n main(input);\n})\n\nfunction main(input) {\n\n let inputArr = input.split('\\n');\n\n let str = inputArr[1].split('');\n\n let a = 0, d = 0;\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'A')\n a++;\n else\n d++;\n }\n\n if (a > d) {\n console.log('Anton');\n }\n else if (a < d) {\n console.log('Danik');\n }\n else if (a === d) {\n console.log('Friendship');\n }\n\n\n}"}, {"source_code": "var input = '';\n\nprocess.stdin.on('data', (givenInput) => {\n input += givenInput;\n})\n\nprocess.stdin.on('end', () => {\n main(input);\n})\n\nfunction main(input) {\n\n let inputArr = input.split('\\n');\n\n let str = inputArr[1].split('');\n\n let a = 0, d = 0;\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'A')\n a++;\n else\n d++;\n }\n\n if (a > d) {\n console.log('Anton');\n }\n else if (a < d) {\n console.log('Danik');\n }\n else {\n console.log('Friendship');\n }\n\n\n}"}, {"source_code": "var n = parseInt(readline());\n\tvar s = readline().split(\" \");\n\tvar len = s.length;\n\tvar ans = 0;\n\tfor(var i = 0; i < len; i++)\n\t{\n\t\tif(s[i] == 'A')\n\t\t\tans ++;\n\t}\n\tvar flag;\n\tif(ans > len-ans)\n\t{\n\t\tflag = \"Anton\";\n\t}\n\telse if(ans < len-ans)\n\t{\n\t\tflag = \"Danik\";\n\t}\n\telse flag = \"Friendship\";\n\tprint(flag);"}, {"source_code": "var num_games = parseInt(readline());\nvar result = readline();\nvar obj = {};\nvar Anton = 0;\nvar Danik = 0;\nfor(var i of result){\n if(i==\"A\")Anton++;\n if(i==\"D\")Danik++;\n}\nif(Anton> Danik)print(\"Anton\");\nelse print(\"Danik\");"}, {"source_code": "var num_games = parseInt(readline());\nvar results = readline().split(\"\");\nvar A = 0;\nvar D = 0;\nfor(var i =0; i< num_games; i++){\n if(results[i]=='A') A++;\n if(results[i]=='D') D++;\n}\nif(A>D)print(\"Anton\")\nelse print(\"Danik\")"}, {"source_code": "var games = +readline();\nvar sequence = readline();\nAntonWinnings = sequence.split('').reduce(function(wins, letter){\n\treturn wins + (letter == 'A'?1:0);\n}, 0);\n\nif(~~(games/2) > AntonWinnings){\n\tprint('Danik');\n}else if(~~(games/2) < AntonWinnings){\n\tprint('Anton')\n}\nelse{\n\tprint('Friendship');\n}"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line, log) {\n var input = line.split(\" \");\n var logs = log.split(\" \");\n\n var n = input[0];\n var history = logs[0];\n\n var anton = 0;\n var denik = 0;\n\n while(n > 0){\n if(history[n - 1] == \"A\"){\n anton++;\n }else{\n denik++;\n }\n n--;\n }\n\n var winner = \"\";\n if(anton > denik){\n winner = \"Anton\";\n }else if(anton < denik){\n winner = \"Denik\";\n }else{\n winner = \"Friendship\";\n }\n\n return winner;\n}"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line, log) {\n var input = line.split(\" \");\n var logs = log.split(\" \");\n\n var n = input[0];\n var history = logs[0];\n\n var anton = 0;\n var denik = 0;\n\n while(n > 0){\n if(history[n - 1] == \"A\"){\n anton++;\n }else{\n denik++;\n }\n n--;\n }\n\n var winner = \"\";\n if(anton > denik){\n winner = \"A\";\n }else if(anton < denik){\n winner = \"D\";\n }else{\n winner = \"Friendship\";\n }\n\n return winner;\n}"}, {"source_code": "(function() {\n 'use strict';\n const n = readline();\n const z = readline().split('');\n var a;\n var d;\n for (let i = 0; i < n; ++i) {\n if (z[i] === 'A') {\n a += 1;\n } else {\n d += 1;\n }\n }\n \n if (a > d) {\n print('Anton');\n } else if (a === d) {\n print('Friendship');\n } else {\n print('Danik');\n }\n}());"}, {"source_code": "\nfunction program(input){\n // var first = input[0].toUpperCase();\n var A = 0;\n var D = 0;\n for(var i=1;i D){\n print('Anton')\n }\n else{\n print('Danik')\n }\n}\nvar input = readline();\nprogram(input);"}, {"source_code": "\nfunction program(input,n){\n // var first = input[0].toUpperCase();\n var A = 0;\n var D = 0;\n for(var i=0;i D){\n print('Anton')\n }\n else if(A < D){\n print('Danik')\n }\n else if(A === D){\n print('Friendship')\n }\n else{\n print('Friendship')\n }\n}\nvar n = readline();\nvar input = readline()\nprogram(input,n)"}, {"source_code": "function program(input,n){\n // var first = input[0].toUpperCase();\n var A = 0;\n var D = 0;\n for(var i=0;i D){\n print('Anton')\n }\n else if(A < D){\n print('Danik')\n }\n else if(A === D){\n print('Friendship')\n }\n \n}\nvar n = readline();\nvar input = readline()\nprogram(input,n)"}, {"source_code": "\nfunction program(input){\n // var first = input[0].toUpperCase();\n var A = 0;\n var D = 0;\n for(var i=0;i D){\n print('Anton')\n }\n else if(A < D){\n print('Danik')\n }\n else{\n print('Friendship')\n }\n}\nvar input = readline();\nprogram(input);"}, {"source_code": "\n var word = readline().split(''),\n Anton = 0,\n Danik = 0;\n for(var i = 0; i < word.length; i++){\n if(word[i] == 'A'){\n Anton++;\n } else {\n Danik++;\n }\n }\n if(Anton > Danik){\n print('Anton');\n } else if(Anton == Danik){\n print('Friendship');\n } else {\n print('Danik');\n }\n "}, {"source_code": "var l = readline()\nvar ar = readline().split('').map(t=>(t=='A'))\nvar a = ar.filter(t=>(t=='A')).length, b = ar.length - a\n\nif ( a > b ) {\n print('Anton')\n} else {\n print('Danik')\n}"}, {"source_code": "var l = readline()\nvar a = 0, b = 0;\nvar ar = readline().split('').map(t=>(t=='A'))\n\nif ( ar.filter(t=>(t=='A')).length > ar.length ) {\n print('Anton')\n} else {\n print('Danik')\n}"}, {"source_code": "var l = readline()\nvar ar = readline().split('')\nvar a = ar.filter(t=>(t=='A')).length, b = ar.length - a\n\nif ( a > b ) {\n print('Anton')\n} else {\n print('Danik')\n}"}, {"source_code": "var n = +readline(),\n line = readline(),\n dc = 0,\n ac = 0;\n\nfor(var i = 0; i < n; i++) {\n if (line[i] === \"D\") {\n dc++;\n } else {\n ac++;\n }\n}\n\nprint(dc > ac ? \"Danik\" : dc === ac ? \"Friendship\" : \"Danik\");\n\n\n"}, {"source_code": "var n = readline();\nvar str = readline();\n\nvar a = 0;\nvar d=0;\nfor (var i=0; id? print(\"Anton\"):print(\"Danil\");"}, {"source_code": "var n = readline();\nvar str = readline();\n\nvar a = 0;\nvar d=0;\nfor (var i=0; id? print(\"Anton\"):print(\"Danik\");"}, {"source_code": "var n = readline().split(\" \").map(x => parseInt(x));\nvar s = readline().split(\" \").map(x => parseInt(x));\nvar antonPlayedGames = 0;\nvar danikPlayedGames = 0;\nfor(var i = 0; i < n; ++i) {\n if(s[i] == \"A\") {\n ++antonPlayedGames;\n } else {\n ++danikPlayedGames;\n }\n}\n\nif(antonPlayedGames > danikPlayedGames) {\n print(\"Anton\");\n} else if(danikPlayedGames > antonPlayedGames) {\n print(\"Danik\");\n} else {\n print(\"Friendship\");\n}"}, {"source_code": "(function main() {\n\tvar n = readline();\n\tvar line = readline();\n\tvar len = parseInt(n);\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tvar c = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\n\t\tprint('aCon: ' + aCon + ' ,dCon: ' + dCon);\n\t\n\tif (aCon > dCon) {\n\t\tprint('Danik');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Anton');\n\t}\n\tc++;\n\n})();"}, {"source_code": "(function main() {\n\tvar line = readline();\n\tvar len = line.length;\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\tif (aCon > dCon) {\n\t\tprint('Danik');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Anton');\n\t}\n\n})();"}, {"source_code": "(function main() {\n\tvar n = readline();\n\tvar line = readline();\n\tvar len = parseInt(n);\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tvar c = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\tif (c !== 0) {\n\t\tprint('aCon: ' + aCon + ' ,dCon: ' + dCon);\n\t}\n\tif (aCon > dCon) {\n\t\tprint('Danik');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Anton');\n\t}\n\tc++;\n\n})();"}, {"source_code": "(function main() {\n\tvar line = readline();\n\tvar len = line.length;\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tvar c = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\tif (c !== 0) {\n\t\tprint('aCon: ' + aCon + ' ,dCon: ' + dCon);\n\t}\n\tif (aCon > dCon) {\n\t\tprint('Danik');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Anton');\n\t}\n\tc++;\n\n})();"}, {"source_code": "(function main() {\n\tvar n = readline();\n\tvar line = readline();\n\tvar len = parseInt(n);\n\tvar aCon = 0;\n\tvar dCon = 0;\n\tvar c = 0;\n\tfor (var i = 0; i < len; i++) {\n\t\tif (line[i] === \"A\") {\n\t\t\taCon += 1;\n\t\t} else {\n\t\t\tdCon += 1;\n\t\t}\n\t}\n\n\t\tprint('aCon: ' + aCon + ' ,dCon: ' + dCon);\n\t\n\tif (aCon > dCon) {\n\t\tprint('Anton');\n\t} else if (aCon === dCon) {\n\t\tprint('Friendship');\n\t} else {\n\t\tprint('Danik');\n\t}\n\tc++;\n\n})();"}, {"source_code": "var n = Number(readline());\nvar string = readline();\n\nfunction counter(n, string) {\n var array = string.split('');\n var a = 0;\n var d = 0;\n\n for(var i = 0; i < n; i++) {\n if(array[i] == 'A') {\n a++\n } else {\n d++\n }\n }\n\n return [a, d];\n}\n\nfunction getResult(n, string) {\n var results = counter(n, string);\n var a = results[0];\n var d = results[1];\n\n if(a > d) {\n return 'Anton';\n } else if(a < d) {\n return 'Danik';\n } else {\n return 'Friendship';\n }\n\n}"}, {"source_code": "var v1 = readline();\nvar v2 = readline();\nvar a = 0;\nvar i = 0;\n\nwhile(i< v1 && a<= v1/2){\n if(v2[i] == 'A'){\n a++;\n }\n i++;\n}\n\nvar result = a > v1/2 ? 'Anton' : (a < v1/2 ? 'Danik' : 'Friendship');"}, {"source_code": "var n = readline();\nvar s= readline();\nvar A=0, D=0;\nfor(var i=0; iD){\n print('Anton');\n \n }else if(D>A){\n print('Danik');\n }else{\n print('Friendship');\n }\n}"}, {"source_code": "var n = Number(readline());\nvar s= readline();\nvar a=0, d=0;\nfor(var i=0; id){\n print('Anton');\n \n }else if(ad){\n print('Anton');\n }else if(aD){\n print('Anton');\n \n }else if(D>A){\n print('Danik');\n }else{\n print('Friendship');\n }\n}"}, {"source_code": "var n = readline();\nvar s= readline();\nvar a=0, d=0;\nfor(var i=0; i< s.length; i++){\n if(s[i] === 'A'){\n a++;\n }else{\n d++;\n }\n if(a>d){\n print('Anton');\n }else if(ad){\n print('Anton');\n \n }else if(aD){\n print('Anton');\n \n }else if(AD){\n print('Anton');\n \n }else if(Alen2)print(\"Anton\");\nif(len1len2){print(\"Anton\")}\nif(len1len2){print(\"Anton\")}\nif(len1len2)print(\"Anton\");\nif(len1 parseInt(x));\n \nvar obj = {\n A: 0,\n D: 0\n}\n \nfor (var i = 0; i < games.length; i++ ) {\n if (winners[i] === 'A') {\n obj['A']++;\n } else if (winners[i] === 'D') {\n obj['D']++;\n }\n}\n \nif (obj['A'] === obj['D']) {\n print('Friendship');\n} else if (obj['A'] > obj['D']) {\n print('Anton');\n} else {\n print('Danik')\n}"}, {"source_code": "var games = parseInt(readline());\nvar winners = readline().split(\" \").map(x => parseInt(x));\n \nvar obj = {\n 'A': 0,\n 'D': 0\n}\n \nfor (var i = 0; i < games.length; i++ ) {\n if (winners[i] === 'A') {\n obj['A']++;\n } else if (winners[i] === 'D') {\n obj['D']++;\n }\n}\n \nif (obj['A'] === obj['D']) {\n print('Friendship');\n} else if (obj['A'] > obj['D']) {\n print('Anton');\n} else {\n print('Danik')\n}"}], "src_uid": "0de32a7ccb08538a8d88239245cef50b"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (a < b) {\n let arr = Array(b + 1);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n } else {\n let arr = Array(a + 1);\n if (init) init(arr);\n for (let i = a; i >= b; i--) arr[i] = fn(i, arr);\n return arr;\n }\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let test = inp[r++];\n while (test--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n t = new SplayTree();\n for (let i = 0; i < n; i++) t.insert(i, a[i]);\n console.log(t.root.p);\n }\n})();\n\nclass Node {\n left; right; key; value; p; m; pm; mp;\n constructor(key, value) {\n this.key = key;\n this.value = value;\n this.p = value;\n this.m = -value;\n this.pm = -1e10;\n this.mp = -1e10;\n }\n update() {\n if (this.left && this.right) {\n this.p = Math.max(this.left.p, this.right.p, this.value, this.left.p + this.right.mp, this.left.pm + this.right.p, this.left.pm + this.value, this.value + this.right.mp, this.left.p - this.value + this.right.p, this.left.pm + this.value + this.right.mp);\n this.m = Math.max(this.left.m, this.right.m, -this.value, this.left.mp - this.value, -this.value + this.right.pm, this.left.mp + this.right.m, this.left.m + this.right.pm, this.left.mp - this.value + this.right.pm, this.left.m + this.value + this.right.m);\n this.pm = Math.max(this.left.pm, this.right.pm, this.left.p + this.right.m, this.left.pm + this.right.pm, this.left.p - this.value, this.value + this.right.m, this.left.pm + this.value + this.right.m, this.left.p - this.value + this.pm);\n this.mp = Math.max(this.left.mp, this.right.mp, this.left.m + this.right.p, this.left.mp + this.right.mp, this.left.m + this.value, -this.value + this.right.p, this.left.mp - this.value + this.right.p, this.left.m + this.value + this.mp);\n } else if (this.left) {\n this.p = Math.max(this.value, this.left.p, this.left.pm + this.value);\n this.m = Math.max(-this.value, this.left.m, this.left.mp - this.value);\n this.pm = Math.max(this.left.pm, this.left.p - this.value);\n this.mp = Math.max(this.left.mp, this.left.m + this.value);\n } else if (this.right) {\n this.p = Math.max(this.value, this.right.p, this.value + this.right.mp);\n this.m = Math.max(-this.value, this.right.m, -this.value + this.right.pm);\n this.pm = Math.max(this.right.pm, this.value + this.m);\n this.mp = Math.max(this.right.mp, -this.value + this.p);\n }\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `${this.key},${this.min},${this.max}` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key, value) {\n if (!this.root) return this.root = new Node(key, value);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push[cur.left = new Node(key, value)];\n else trace.push[cur.right = new Node(key, value)];\n cur.update();\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n res() {\n if (!this.root) return 0;\n return (this.root.max - this.root.min - this.root.maxGap) || 0\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var max = 0;\n for(var j = 1; j < N - 1; j++){\n if(list[j] > list[j + 1] && list[j - 1] < list[j]){\n max += list[j];\n }\n if(list[j] < list[j + 1] && list[j - 1] > list[j]){\n max -= list[j];\n }\n }\n if(N >= 2){\n if(list[0] > list[1]){\n max += list[0];\n }\n if(list[N - 1] > list[N - 2]){\n max += list[N - 1];\n }\n }else{\n max = 1;\n }\n \n output[i] = max;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (a < b) {\n let arr = Array(b + 1);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n } else {\n let arr = Array(a + 1);\n if (init) init(arr);\n for (let i = a; i >= b; i--) arr[i] = fn(i, arr);\n return arr;\n }\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let test = inp[r++];\n while (test--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n t = new SplayTree();\n for (let i = 0; i < n; i++) t.insert(i, a[i])\n console.log(t.root.p);\n // t.print();\n for (let i = 0; i < q; i++) {\n let li = inp[r++], ri = inp[r++];\n t.update(li - 1, a[ri - 1]);\n // t.print();\n t.update(ri - 1, a[li - 1]);\n // t.print();\n let temp = a[li - 1];\n a[li - 1] = a[ri - 1];\n a[ri - 1] = temp;\n console.log(t.root.p);\n }\n }\n})();\n\nclass Node {\n left; right; key; value; p; m; pm; mp; size;\n constructor(key, value) {\n this.key = key;\n this.value = value;\n this.p = value;\n this.m = -value;\n this.pm = -1e10;\n this.mp = -1e10;\n this.size = 1;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n if (this.left && this.right) {\n this.p = Math.max(this.left.p, this.right.p, this.value, this.left.p + this.right.mp, this.left.pm + this.right.p, this.left.pm + this.value, this.value + this.right.mp, this.left.p - this.value + this.right.p, this.left.pm + this.value + this.right.mp);\n this.m = Math.max(this.left.m, this.right.m, -this.value, this.left.mp - this.value, -this.value + this.right.pm, this.left.mp + this.right.m, this.left.m + this.right.pm, this.left.mp - this.value + this.right.pm, this.left.m + this.value + this.right.m);\n this.pm = Math.max(this.left.pm, this.right.pm, this.left.p + this.right.m, this.left.pm + this.right.pm, this.left.p - this.value, this.value + this.right.m, this.left.pm + this.value + this.right.m, this.left.p - this.value + this.right.pm);\n this.mp = Math.max(this.left.mp, this.right.mp, this.left.m + this.right.p, this.left.mp + this.right.mp, this.left.m + this.value, -this.value + this.right.p, this.left.mp - this.value + this.right.p, this.left.m + this.value + this.right.mp);\n } else if (this.left) {\n this.p = Math.max(this.value, this.left.p, this.left.pm + this.value);\n this.m = Math.max(-this.value, this.left.m, this.left.mp - this.value);\n this.pm = Math.max(this.left.pm, this.left.p - this.value);\n this.mp = Math.max(this.left.mp, this.left.m + this.value);\n } else if (this.right) {\n this.p = Math.max(this.value, this.right.p, this.value + this.right.mp);\n this.m = Math.max(-this.value, this.right.m, -this.value + this.right.pm);\n this.pm = Math.max(this.right.pm, this.value + this.right.m);\n this.mp = Math.max(this.right.mp, -this.value + this.right.p);\n } else {\n this.p = this.value;\n this.m = -this.value;\n this.pm = -1e10;\n this.mp = -1e10;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.size},${this.value},${this.p},${this.m},${this.pm},${this.mp})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key, value) {\n if (!this.root) return this.root = new Node(key, value);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key, value));\n else trace.push(cur.right = new Node(key, value));\n // cur.update();\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n update(key, value) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur.value = value;\n // for (let i = trace.length - 1; i >= 0; i--) {\n // trace[i].update();\n // }\n this.splay(trace);\n }\n\n res() {\n if (!this.root) return 0;\n return (this.root.max - this.root.min - this.root.maxGap) || 0\n }\n\n print() {\n return;\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n let cong = Array(n).fill(0);\n let tru = Array(n).fill(0);\n cong[0] = a[0];\n for (let i = 1; i < n; i++) {\n cong[i] = Math.max(tru[i - 1] + a[i], cong[i - 1]);\n tru[i] = Math.max(cong[i - 1] - a[i], tru[i - 1])\n }\n console.log(cong[n - 1]);\n }\n})();"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let test = inp[r++];\n let ans = [];\n while (test--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n t = new SplayTree();\n for (let i = 0; i < n; i++) t.insert(i, a[i])\n ans.push(t.root.p);\n // t.print();\n for (let i = 0; i < q; i++) {\n let li = inp[r++], ri = inp[r++];\n t.update(li - 1, a[ri - 1]);\n // t.print();\n t.update(ri - 1, a[li - 1]);\n // t.print();\n let temp = a[li - 1];\n a[li - 1] = a[ri - 1];\n a[ri - 1] = temp;\n ans.push(t.root.p);\n }\n }\n console.log(ans.join('\\n'));\n})();\n\nclass Node {\n left; right; key; value; p; m; pm; mp;\n constructor(key, value) {\n this.key = key;\n this.value = value;\n this.p = value;\n this.m = -value;\n this.pm = -1e10;\n this.mp = -1e10;\n }\n update() {\n if (this.left && this.right) {\n this.p = Math.max(this.left.p, this.right.p, this.value, this.left.p + this.right.mp, this.left.pm + this.right.p, this.left.pm + this.value, this.value + this.right.mp, this.left.p - this.value + this.right.p, this.left.pm + this.value + this.right.mp);\n this.m = Math.max(this.left.m, this.right.m, -this.value, this.left.mp - this.value, -this.value + this.right.pm, this.left.mp + this.right.m, this.left.m + this.right.pm, this.left.mp - this.value + this.right.pm, this.left.m + this.value + this.right.m);\n this.pm = Math.max(this.left.pm, this.right.pm, this.left.p + this.right.m, this.left.pm + this.right.pm, this.left.p - this.value, this.value + this.right.m, this.left.pm + this.value + this.right.m, this.left.p - this.value + this.right.pm);\n this.mp = Math.max(this.left.mp, this.right.mp, this.left.m + this.right.p, this.left.mp + this.right.mp, this.left.m + this.value, -this.value + this.right.p, this.left.mp - this.value + this.right.p, this.left.m + this.value + this.right.mp);\n } else if (this.left) {\n this.p = Math.max(this.value, this.left.p, this.left.pm + this.value);\n this.m = Math.max(-this.value, this.left.m, this.left.mp - this.value);\n this.pm = Math.max(this.left.pm, this.left.p - this.value);\n this.mp = Math.max(this.left.mp, this.left.m + this.value);\n } else if (this.right) {\n this.p = Math.max(this.value, this.right.p, this.value + this.right.mp);\n this.m = Math.max(-this.value, this.right.m, -this.value + this.right.pm);\n this.pm = Math.max(this.right.pm, this.value + this.right.m);\n this.mp = Math.max(this.right.mp, -this.value + this.right.p);\n } else {\n this.p = this.value;\n this.m = -this.value;\n this.pm = -1e10;\n this.mp = -1e10;\n }\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.size},${this.value},${this.p},${this.m},${this.pm},${this.mp})` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key, value) {\n if (!this.root) return this.root = new Node(key, value);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key, value));\n else trace.push(cur.right = new Node(key, value));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n update(key, value) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur.value = value;\n this.splay(trace);\n }\n\n res() {\n if (!this.root) return 0;\n return (this.root.max - this.root.min - this.root.maxGap) || 0\n }\n\n print() {\n return;\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let isReverseSorted = true;\n let allSame = true;\n for(let i = 1; i < n; i++){\n if(a[i] !== a[i-1]){\n allSame = false;\n }\n \n if(a[i] > a[i-1]){\n isReverseSorted = false;\n break;\n } \n }\n\n if(isReverseSorted){\n if(!allSame)\n console.log('No');\n else\n console.log('Yes');\n }else{\n console.log('Yes');\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n, q] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++)\n dp[i] = new Array(2);\n\n let maxPos = a[0];\n let maxNeg = 0;\n for(let i = 1; i < n; i++){\n dp[i][0] = maxNeg + a[i];\n dp[i][1] = maxPos - a[i];\n\n maxPos = Math.max(maxPos, dp[i][0]);\n maxNeg = Math.max(maxNeg, dp[i][1]);\n }\n\n console.log(Math.max(maxPos, maxNeg));\n }\n}\n"}, {"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n\n var x = ip[0]\n var y = ip[1]\n\n var s = readline().split(' ').map(x => parseInt(x))\n\n var a = [s[0]]\n var b = [0]\n\n for (var n = 1; n < x; n++) {\n var p = b[n - 1] + s[n]\n var q = a[n - 1] - s[n]\n a.push(Math.max(a[n - 1], p))\n b.push(Math.max(b[n - 1], q))\n }\n\n print(Math.max(a[x - 1], b[x - 1]))\n}\n\nvar tc = 1;\ntc = parseInt(readline());\nwhile (tc--) solv()"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var index = -1;\n for(var j = 0; j < N; j++){\n if(list[j] == N){\n index = j;\n break;\n }\n }\n var max = 0;\n for(var j = 1; j < N - 1; j++){\n if(list[j] > list[j + 1] && list[j - 1] < list[j]){\n max += list[j];\n }\n if(list[j] < list[j + 1] && list[j - 1] > list[j]){\n max -= list[j];\n }\n }\n if(N >= 2){\n if(list[0] > list[1]){\n max += list[0];\n }\n if(list[N - 1] > list[N - 2]){\n max += list[N - 1];\n }\n }\n \n output[i] = max;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n if (n == 1) {\n console.log(a[0]);\n return;\n }\n let cong = Array(n).fill(0);\n let tru = Array(n).fill(0);\n cong[0] = a[0];\n cong[1] = a[1];\n tru[1] = Math.max(0, a[0] - a[1])\n for (let i = 2; i < n; i++) {\n cong[i] = Math.max(tru[i - 1] + a[i], cong[i - 1]);\n tru[i] = Math.max(cong[i - 1] - a[i], tru[i - 1])\n }\n console.log(cong[n - 1]);\n }\n})();"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n if (n == 1) {\n console.log(a[0]);\n continue;\n }\n let cong = Array(n).fill(0);\n let tru = Array(n).fill(0);\n cong[0] = a[0];\n cong[1] = a[1];\n tru[1] = Math.max(0, a[0] - a[1])\n for (let i = 2; i < n; i++) {\n cong[i] = Math.max(tru[i - 1] + a[i], cong[i - 1]);\n tru[i] = Math.max(cong[i - 1] - a[i], tru[i - 1])\n }\n console.log(cong[n - 1]);\n }\n})();"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, fn) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, fn, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n while (t--) {\n let n = inp[r++], q = inp[r++];\n let a = inp.slice(r, r = r + n);\n if (n == 1) {\n console.log(a[0]);\n return;\n }\n let cong = Array(n).fill(0);\n let tru = Array(n).fill(0);\n cong[0] = a[0];\n cong[1] = a[1];\n for (let i = 2; i < n; i++) {\n cong[i] = Math.max(tru[i - 1] + a[i], cong[i - 1]);\n tru[i] = Math.max(cong[i - 1] - a[i], tru[i - 1])\n }\n console.log(Math.max(...cong));\n }\n})();"}], "src_uid": "2d088e622863ab0d966862ec29588db1"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let topo = [0], e = []\n v[0].m = 1;\n For(n, i => {\n let x = topo[i];\n v[x].e.forEach(y => {\n if (v[y].m) return;\n v[y].m = v[x].m + 1;\n topo.push(y);\n })\n })\n ForR(n, i => {\n let x = topo[i];\n v[x].c = 1;\n v[x].e.forEach(y => {\n if (v[y].m < v[x].m) return;\n v[x].c += v[y].c;\n })\n if (i > 0) e.push(v[x].c * (n - v[x].c))\n })\n // log(e)\n e = e.sort(desc).map(v => v % mod);\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n // log(e, p)\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', async _ => {\n inputString = inputString.split(/\\n/);\n try {\n await main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\nconst mod = BigInt(Math.pow(10, 9) + 7)\nasync function main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const edges = Array(n).fill(0).map(() => [])\n for (let _ = 0; _ < n - 1; _++) {\n const [v1, v2] = readLine().split(/\\s/).map(Number)\n edges[v1 - 1].push(v2 - 1)\n edges[v2 - 1].push(v1 - 1)\n }\n const counts = []\n await dfs(edges, 0, counts)\n counts.sort((a, b) => Number(b - a))\n const m = Number(readLine())\n const ps = readLine().split(/\\s/).map(BigInt).sort((a, b) => Number(b - a))\n const times = []\n for (let i = 0; i < m; i++) {\n let p = ps[i]\n if (i === 0) {\n while (m - i > n - 1) {\n i += 1\n p = (p * ps[i]) % mod\n }\n }\n times.push(p)\n }\n while (times.length < n - 1) {\n times.push(1n)\n }\n let result = 0n\n for (let i = 0; i < n - 1; i++) {\n result = (result + counts[i] * times[i]) % mod\n }\n console.log(result.toString())\n }\n}\n \nasync function dfs(edges, node, results, parent) {\n let count = 1\n for (const child of edges[node]) {\n if (child === parent) {\n continue\n }\n count += await Promise.resolve().then(() => dfs(edges, child, results, node))\n }\n results.push(BigInt(count * (edges.length - count)))\n return count\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let topo = [0], e = []\n v[0].m = 1;\n For(n, i => {\n let x = topo[i];\n v[x].e.forEach(y => {\n if (v[y].m) return;\n v[y].m = v[x].m + 1;\n topo.push(y);\n })\n })\n ForR(n, i => {\n let x = topo[i];\n v[x].c = 1;\n v[x].e.forEach(y => {\n if (v[y].m < v[x].m) return;\n v[x].c += v[y].c;\n })\n if (i > 0) e.push(v[x].c * (n - v[x].c))\n })\n // log(e)\n e = e.sort(desc).map(v => v % mod);\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e = e.sort(desc).map(v => v % mod)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n if (a > m) a = a % m;\n if (b > m) b = b % m;\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e = e.sort(desc).map(v => v % mod)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n // log(e, p)\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e = e.sort(desc).map(v => v % mod)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', async _ => {\n inputString = inputString.split(/\\n/);\n try {\n await main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\nconst mod = BigInt(Math.pow(10, 9) + 7)\nasync function main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const edges = Array(n).fill(0).map(() => [])\n for (let _ = 0; _ < n - 1; _++) {\n const [v1, v2] = readLine().split(/\\s/).map(Number)\n edges[v1 - 1].push(v2 - 1)\n edges[v2 - 1].push(v1 - 1)\n }\n const counts = []\n await dfs(edges, 0, counts)\n counts.sort((a, b) => Number(b - a))\n const m = Number(readLine())\n const ps = readLine().split(/\\s/).map(BigInt).sort((a, b) => Number(b - a))\n const times = []\n for (let i = 0; i < m; i++) {\n let p = ps[i]\n if (i === 0) {\n while (m - i > n - 1) {\n i += 1\n p = (p * ps[i]) % mod\n }\n }\n times.push(p)\n }\n while (times.length < n - 1) {\n times.push(1n)\n }\n let result = 0n\n for (let i = 0; i < n - 1; i++) {\n result = (result + counts[i] * times[i]) % mod\n }\n console.log(result.toString())\n }\n}\n \nasync function dfs(edges, node, results, parent) {\n let count = 1\n for (const child of edges[node]) {\n if (child === parent) {\n continue\n }\n count += await dfs(edges, child, results, node)\n }\n results.push(BigInt(count * (edges.length - count)))\n return count\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n try {\n main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\nconst mod = BigInt(Math.pow(10, 9) + 7)\nasync function main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const edges = Array(n).fill(0).map(() => [])\n for (let _ = 0; _ < n - 1; _++) {\n const [v1, v2] = readLine().split(/\\s/).map(Number)\n edges[v1 - 1].push(v2 - 1)\n edges[v2 - 1].push(v1 - 1)\n }\n const counts = []\n await dfs(edges, 0, counts)\n counts.sort((a, b) => Number(b - a))\n const m = Number(readLine())\n const ps = readLine().split(/\\s/).map(BigInt).sort((a, b) => Number(b - a))\n const times = []\n for (let i = 0; i < m; i++) {\n let p = ps[i]\n if (i === 0) {\n while (m - i > n - 1) {\n i += 1\n p = (p * ps[i]) % mod\n }\n }\n times.push(p)\n }\n while (times.length < n - 1) {\n times.push(1n)\n }\n let result = 0n\n for (let i = 0; i < n - 1; i++) {\n result = (result + counts[i] * times[i]) % mod\n }\n console.log(result.toString())\n }\n}\n \nasync function dfs(edges, node, results, parent) {\n let count = 1\n for (const child of edges[node]) {\n if (child === parent) {\n continue\n }\n count += await dfs(edges, child, results, node)\n }\n results.push(BigInt(count * (edges.length - count)))\n return count\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n try {\n main(); \n } catch (e) {\n console.log(e)\n }\n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\nconst mod = BigInt(Math.pow(10, 9) + 7)\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const edges = Array(n).fill(0).map(() => [])\n for (let _ = 0; _ < n - 1; _++) {\n const [v1, v2] = readLine().split(/\\s/).map(Number)\n edges[v1 - 1].push(v2 - 1)\n edges[v2 - 1].push(v1 - 1)\n }\n const counts = []\n dfs(edges, 0, counts)\n counts.sort((a, b) => Number(b - a))\n const m = Number(readLine())\n const ps = readLine().split(/\\s/).map(BigInt).sort((a, b) => Number(b - a))\n const times = []\n for (let i = 0; i < m; i++) {\n let p = ps[i]\n if (i === 0) {\n while (m - i > n - 1) {\n i += 1\n p = (p * ps[i]) % mod\n }\n }\n times.push(p)\n }\n while (times.length < n - 1) {\n times.push(1n)\n }\n let result = 0n\n for (let i = 0; i < n - 1; i++) {\n result = (result + counts[i] * times[i]) % mod\n }\n console.log(result.toString())\n }\n}\n \nfunction dfs(edges, node, results, parent) {\n let count = 1\n for (const child of edges[node]) {\n if (child === parent) {\n continue\n }\n count += dfs(edges, child, results, node)\n }\n results.push(BigInt(count * (edges.length - count)))\n return count\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n let mod = 1e9 + 7;\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n // log(e, p)\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c) % mod)\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n let mod = 1e9 + 7;\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n // log(e, p)\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c) % mod)\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n // log(e, p)\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n let mod = 1e9 + 7;\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n let mod = 1e9 + 7;\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => p = mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = mul(e[0], p[0], mod);\n For(1, n - 2, i => {\n s = (s + e[i] * p[i]) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n let mod = 1e9 + 7;\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => p = mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c) % mod)\n }\n await dfs(0)\n // log(e)\n e.sort(desc)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $(), mod = 1e9 + 7\n while (t--) {\n let n = $(), v = Arr(n, i => ({ c: 0, m: 0, e: [] }));\n For(n - 1, i => {\n let [x, y] = $(2)\n v[x - 1].e.push(y - 1)\n v[y - 1].e.push(x - 1)\n });\n // log(v)\n let d = 0, e = []\n let dfs = async x => {\n if (d++ % 1000 == 0) await Promise.resolve()\n v[x].m = 1;\n v[x].c = 1;\n for (let y of v[x].e) {\n if (v[y].m) continue;\n await dfs(y)\n v[x].c += v[y].c;\n }\n // log(x, v[x].c);\n if (x != 0) e.push(v[x].c * (n - v[x].c))\n }\n await dfs(0)\n // log(e)\n e.sort(desc).map(v => v % mod)\n let m = $(), p = $(m);\n p.sort(desc)\n while (p.length < e.length) p.push(1);\n if (p.length > e.length) p = [\n p.slice(0, p.length - e.length + 1).reduce((p, v) => mul(p, v, mod), 1),\n ...p.slice(p.length - e.length + 1)\n ]\n let s = 0;\n // log(e, p)\n For(n - 1, i => {\n s = (s + mul(e[i], p[i], mod)) % mod;\n })\n log(s)\n }\n}\n"}], "src_uid": "968b3db21bd16bc04bdb355e98079d5d"} {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 08/09/21 evening\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n let m = 1;\r\n a = a.map((x, i) => [x, i]);\r\n a.sort((x, y) => {\r\n if (x[0] == y[0]) return x[1] - y[1];\r\n return x[0] - y[0];\r\n })\r\n // pr(a)\r\n for (let i = 0; i < n - 1; i++) {\r\n if (a[i][1] + 1 != a[i + 1][1]) m++;\r\n }\r\n // pr(m, k);\r\n pr(m <= k ? 'Yes' : 'No');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst idx = []\r\nfunction calcNumRanks(e) {\r\n const n = e.length\r\n if (n <= 0) return [0, []]\r\n if (1 === n) return [1, [1]]\r\n idx.length = n\r\n for (let e = 0; e < n; ++e) idx[e] = e\r\n idx.sort((n, t) => e[n] - e[t])\r\n let t = 1\r\n const i = new Array(n)\r\n i[idx[0]] = 1\r\n for (let s = 1, r = e[idx[0]]; s < n; ++s) {\r\n const n = e[idx[s]]\r\n n > r && ((t += 1), (r = n)), (i[idx[s]] = t)\r\n }\r\n return [t, i]\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const [, i] = calcNumRanks(t)\r\n let s = 1\r\n for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] !== i[n] + 1 && (s += 1)\r\n return s <= n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = solve(n, t, e.readIntegersOfLine())\r\n e.print((i ? 'YES' : 'NO') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst idx = []\r\nfunction calcNumRanks(e) {\r\n const n = e.length\r\n if (n <= 0) return [0, []]\r\n if (1 === n) return [1, [1]]\r\n idx.length = n\r\n for (let e = 0; e < n; ++e) idx[e] = e\r\n idx.sort((n, t) => e[n] - e[t])\r\n let t = 1\r\n const i = new Array(n)\r\n i[idx[0]] = 1\r\n for (let s = 1, r = e[idx[0]]; s < n; ++s) {\r\n const n = e[idx[s]]\r\n n > r && ((t += 1), (r = n)), (i[idx[s]] = t)\r\n }\r\n return [t, i]\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const [, i] = calcNumRanks(t)\r\n let s = e\r\n for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] === i[n] + 1 && (s -= 1)\r\n return s <= n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = solve(n, t, e.readIntegersOfLine())\r\n e.print((i ? 'YES' : 'NO') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === k) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let k = { val: arr[i], ind: i };\r\n arr[i] = k;\r\n }\r\n arr.sort((a, b) => a.val - b.val);\r\n let cnt = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i - 1].ind + 1 !== arr[i].ind) cnt++;\r\n }\r\n if (cnt <= k) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let examplesStrings = [\r\n`3\r\n5 4\r\n6 3 4 2 1\r\n4 2\r\n1 -4 0 -2\r\n5 1\r\n1 2 3 4 5`,\r\n// `3\r\n// 1 2 3`,\r\n// `9\r\n// 1 2 1 3 2 2 2 2 3`\r\n];\r\n\r\nlet examples = [\r\n [\r\n [\r\n {k: 4, arr: [6,3,4,2,1]}\r\n ],\r\n [\r\n {k: 2, arr: [1, -4, 0, -2]}\r\n ],\r\n [\r\n {k: 14, arr: [1,2,3,4,5]}\r\n ]\r\n ],\r\n // [1,2,3],\r\n // [1,2,1,3,2,2,2,2,3]\r\n];\r\n\r\nlet answers = [\r\n`YES\r\nNO\r\nYES`\r\n// `2`,\r\n// `4`,\r\n// '10'\r\n];\r\n\r\n// \r\n\r\nconst parser = (string) => {\r\n const lines = string.match(/[^\\r\\n]+/g);\r\n\r\n // return lines[1].split(' ').map(x => parseInt(x, 10))\r\n\r\n const finalResult = [];\r\n for(let i = 1; i < lines.length; i+=2) {\r\n finalResult.push({\r\n k: lines[i].split(' ').map(x => parseInt(x, 10))[1],\r\n arr: lines[i+1].split(' ').map(x => parseInt(x, 10))\r\n })\r\n }\r\n return finalResult;\r\n}\r\n\r\n\r\n\r\nconst solver = (arr2d) => {\r\n\r\n function binarySearch(arr, val) {\r\n let start = 0;\r\n let end = arr.length - 1;\r\n \r\n while (start <= end) {\r\n let mid = Math.floor((start + end) / 2);\r\n \r\n if (arr[mid] === val) {\r\n return mid;\r\n }\r\n \r\n if (val < arr[mid]) {\r\n end = mid - 1;\r\n } else {\r\n start = mid + 1;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n return arr2d.map(({k, arr}) => {\r\n const sorted = arr.slice(0);\r\n sorted.sort((a,b) => a-b);\r\n\r\n let subArrCount = 0;\r\n\r\n let originalIndex = null;\r\n for(let i = 0; i < arr.length; i++) {\r\n // if (originalIndex === null) {\r\n // subArrCount++;\r\n // originalIndex = i;\r\n // }\r\n\r\n if ( (originalIndex === null) || (arr[i] !== sorted[++originalIndex])) {\r\n // console.log('new', i, originalIndex)\r\n subArrCount++;\r\n \r\n originalIndex = binarySearch(sorted, arr[i]);\r\n // originalIndex2 = arr.indexOf(sorted[i]);\r\n\r\n // console.log({originalIndex, originalIndex2, arr, el: sorted[i]})\r\n }\r\n\r\n // if ()\r\n }\r\n \r\n // console.log({k, arr, sorted, subArrCount})\r\n\r\n return (k >= subArrCount) ? 'YES' : 'NO';\r\n }).join(\"\\r\\n\")\r\n \r\n};\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst multiSolver = (_inputs) => {\r\n const isMulti = false;\r\n\r\n const inputs = isMulti ? _inputs : [_inputs];\r\n\r\n let results = [];\r\n for(let input of inputs) {\r\n results.push(solver(input));\r\n // logResult(solver(input))\r\n }\r\n console.log({results})\r\n const strResults = results.join(\"\\r\\n\");\r\n logResult(strResults);\r\n return strResults;\r\n\r\n \r\n}\r\n\r\n// FINISH HERE !!!\r\n// STOP\r\n// STOP\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst isDevMode = process.env.LOCAL === 'knotri';\r\nconst logResult = console.log;\r\n\r\n\r\n\r\nconst deepEq = (obj1, obj2) => JSON.stringify(obj1) === JSON.stringify(obj2)\r\nconst validate = ({examplesStrings, examples, answers, parser, multiSolver}) => {\r\n examplesStrings.forEach((string, index) => {\r\n const actualParse = parser(string);\r\n const desiredParse = examples[index];\r\n\r\n if (!deepEq(actualParse, desiredParse)) {\r\n console.error('PARSE WRONG!');\r\n console.log({actualParse, desiredParse})\r\n }\r\n\r\n const actualAnswer = multiSolver(actualParse);\r\n const desiredAnswer = answers[index];\r\n\r\n if (!deepEq(actualAnswer, desiredAnswer)) {\r\n console.error('SOLVE WRONG!');\r\n console.log({actualParse, actualAnswer, desiredAnswer})\r\n }\r\n\r\n });\r\n\r\n}\r\n\r\n\r\n\r\nif (!isDevMode) {\r\n console.log = () => {};\r\n const fs = require(\"fs\");\r\n const stdinBuffer = fs.readFileSync(0);\r\n const string = stdinBuffer.toString();\r\n\r\n multiSolver(parser(string));\r\n} else {\r\n validate({examplesStrings, examples, answers, parser, multiSolver})\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // console.time('Execution Time')\n let testCases = readline()\n while(testCases--)\n solve()\n // console.timeEnd('Execution Time');\n}\n\n// function to solve problems\nfunction solve (){\n let [n, k] = readline().split(' ')\n let arr = readline().split(' ').map(x => +x),\n ansArr = []\n\n // copy arr\n arr.forEach(num => {\n ansArr.push(num)\n })\n ansArr.sort(sortAscending)\n let ansMap = new Map()\n for (let i=0; i < ansArr.length; i++) {\n ansMap.set(ansArr[i], i)\n }\n for (let i=0; i < arr.length - 1 && k > 0; i++) {\n // check it's agad no is same as ans arr\n // find index\n let index = ansMap.get(arr[i])\n if ((index - ansMap.get(arr[i+1])) != -1) {\n // not consecutive - make bracket\n k--\n }\n }\n (k > 0) ? console.log('YES') : console.log('NO')\n}\n\nfunction sortAscending(a, b) {\n return a - b\n}\n// String.prototype.replaceAt = function (index, replacement) {\n// return this.substring(0, index) + replacement + this.substring(index + replacement.length)\n// }\n\n//Copy arr\n// Map vs array"}, {"source_code": "function solve() {\r\n const [n, k] = readArray(Number);\r\n const arr = readArray((x, i) => [Number(x), i]);\r\n arr.sort((a, b) => a[0] - b[0]);\r\n let goodCounter = 0; \r\n for (let i = 1; i < n; i++) {\r\n if (arr[i - 1][1] + 1 === arr[i][1]) {\r\n goodCounter++;\r\n }\r\n }\r\n write(goodCounter + k >= n ? 'YES' : 'NO');\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst idx = []\r\nfunction calcNumRanks(e) {\r\n const n = e.length\r\n if (n <= 0) return [0, []]\r\n if (1 === n) return [1, [1]]\r\n idx.length = n\r\n for (let e = 0; e < n; ++e) idx[e] = e\r\n idx.sort((n, t) => e[n] - e[t])\r\n let t = 1\r\n const i = new Array(n)\r\n i[idx[0]] = 1\r\n for (let s = 1, r = e[idx[0]]; s < n; ++s) {\r\n const n = e[idx[s]]\r\n n > r && ((t += 1), (r = n)), (i[idx[s]] = t)\r\n }\r\n return [t, i]\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const [, i] = calcNumRanks(t)\r\n let s = 0\r\n for (let n = 0, t = e - 1; n < t; ++n)\r\n i[n + 1] !== i[n] && i[n + 1] !== i[n] + 1 && (s += 1)\r\n return s <= n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = solve(n, t, e.readIntegersOfLine())\r\n e.print((i ? 'YES' : 'NO') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst idx = []\r\nfunction calcNumRanks(e) {\r\n const n = e.length\r\n if (n <= 0) return [0, []]\r\n if (1 === n) return [1, [1]]\r\n idx.length = n\r\n for (let e = 0; e < n; ++e) idx[e] = e\r\n idx.sort((n, t) => e[n] - e[t])\r\n let t = 1\r\n const i = new Array(n)\r\n i[idx[0]] = 1\r\n for (let s = 1, r = e[idx[0]]; s < n; ++s) {\r\n const n = e[idx[s]]\r\n n > r && ((t += 1), (r = n)), (i[idx[s]] = t)\r\n }\r\n return [t, i]\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const [, i] = calcNumRanks(t)\r\n let s = 0\r\n for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] !== i[n] + 1 && (s += 1)\r\n return s <= n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = solve(n, t, e.readIntegersOfLine())\r\n e.print((i ? 'YES' : 'NO') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst idx = []\r\nfunction calcNumRanks(e) {\r\n const n = e.length\r\n if (n <= 0) return [0, []]\r\n if (1 === n) return [1, [1]]\r\n idx.length = n\r\n for (let e = 0; e < n; ++e) idx[e] = e\r\n idx.sort((n, t) => e[n] - e[t])\r\n let t = 1\r\n const i = new Array(n)\r\n i[idx[0]] = 1\r\n for (let s = 1, r = e[idx[0]]; s < n; ++s) {\r\n const n = e[idx[s]]\r\n n > r && ((t += 1), (r = n)), (i[idx[s]] = t)\r\n }\r\n return [t, i]\r\n}\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const [, i] = calcNumRanks(t)\r\n let s = 0\r\n for (let n = 1; n < e; ++n) i[n] !== i[n - 1] + 1 && (s += 1)\r\n return s <= n\r\n}\r\n__main__(function (e) {\r\n const n = Number(e.readLine())\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = solve(n, t, e.readIntegersOfLine())\r\n e.print((i ? 'YES' : 'NO') + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/09/21 morning\r\n * https://codeforces.com/contest/1557/problem/B\r\n */\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n if (k == n) return pr('Yes')\r\n let tmp = LISA(a);\r\n let [m, d] = tmp;\r\n // pr(m, n - m + 1, k, d)\r\n if (n - m + 1 <= k) return pr('Yes');\r\n let sum = sm(d);\r\n if (n - sum + d.length <= k) return pr('Yes');\r\n pr('No')\r\n};\r\n\r\nconst LISA = (a) => {\r\n let max = 1, len = 1, n = a.length, d = [];\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] >= a[i - 1]) {\r\n len++;\r\n } else {\r\n d.push(len)\r\n if (len > max) max = len;\r\n len = 1;\r\n }\r\n }\r\n if (len > max) max = len;\r\n return [max, d];\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/09/21 morning\r\n * https://codeforces.com/contest/1557/problem/B\r\n */\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n if (k == n) return pr('Yes')\r\n let tmp = LISA(a);\r\n let [m, cnt] = tmp;\r\n // pr(m, n - m + 1, k, 'cnt', cnt)\r\n if (n - m + 1 <= k) return pr('Yes');\r\n pr('No')\r\n};\r\n\r\nconst LISA = (a) => {\r\n let max = 1, len = 1, n = a.length, cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] >= a[i - 1]) {\r\n len++;\r\n } else {\r\n cnt++;\r\n if (len > max) max = len;\r\n len = 1;\r\n }\r\n }\r\n if (len > max) max = len;\r\n return [max, cnt];\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/09/21 morning\r\n * https://codeforces.com/contest/1557/problem/B\r\n */\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n if (k == n) return pr('Yes')\r\n let m = LISA(a);\r\n // pr(m, n - m + 1, k)\r\n if (n - m + 1 > k) return pr('No');\r\n pr('Yes')\r\n};\r\n\r\nconst LISA = (a) => {\r\n let max = 1, len = 1, n = a.length;\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] > a[i - 1]) {\r\n len++;\r\n } else {\r\n if (max < len) max = len;\r\n len = 1;\r\n }\r\n }\r\n if (len > max) max = len;\r\n return max;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/09/21 morning\r\n * https://codeforces.com/contest/1557/problem/B\r\n */\r\nconst solve = (n, k, a) => {\r\n // pr(n, k, a)\r\n let m = LISA(a);\r\n // pr(m, n - m + 1, k)\r\n if (n - m + 1 <= k) return pr('Yes');\r\n pr('No')\r\n};\r\n\r\nconst LISA = (a) => {\r\n let max = 1, len = 1, n = a.length;\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] > a[i - 1]) {\r\n len++;\r\n } else {\r\n if (max < len) max = len;\r\n len = 1;\r\n }\r\n }\r\n if (len > max) max = len;\r\n return max;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === k) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let k = { val: arr[i], ind: i };\r\n arr[i] = k;\r\n }\r\n arr.sort((a, b) => a.val - b.val);\r\n let cnt = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i - 1].ind + 1 !== arr[i].ind) cnt++;\r\n }\r\n if (cnt <= k) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "255d6fca1379ae40b03e761802f36664"} {"source_code": "print(function(n, k) {\n\tvar f = new Int8Array(1e5 + 5);\n\tvar cnt = 0;\n\tfor (var i = 0; i < n; i++)\n\t\treadline().split(' ').map(Number).reduce(function(l, r) {\n\t\t\tcnt += r - l + 1;\n\t\t});\n\n\treturn k * Math.ceil(cnt / k) - cnt;\n\n} .apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "print(function(n, k) {\n\tvar cnt = 0;\n\tfor (var i = 0; i < n; i++)\n\t\treadline().split(' ').map(Number).reduce(function(l, r) {\n\t\t\tcnt += r - l + 1;\n\t\t});\n\n\treturn k * Math.ceil(cnt / k) - cnt;\n\n} .apply(0, readline().split(' ').map(Number)));"}, {"source_code": "ip = readline().split(\" \");\nn = parseInt(ip[0]);\nk = parseInt(ip[1]);\nsum = 0;\nats = 0;\n\nfor (var i = 0; i < n; i++){\n\tip = readline().split(\" \");\n\tl = parseInt(ip[0]);\n\tr = parseInt(ip[1]);\n\tsum += (Math.abs(r-l)+1);\t\n}\nif (sum % k != 0){\n\tats = k - (sum % k);\n}\nwrite(ats);\n"}, {"source_code": ";(function () {\n\n\tprint(function () {\n\n\t\tvar p = readline().split(' ').map(Number),\n\t\t\tn = p[0], k = p[1]; p = 0;\n\n\t\twhile (n--) {\n\t\t\tp += readline().split(' ').map(Number).reduce(function (a, b) { return b - a + 1; });\n\t\t}\n\n\t\tif ((p % k) === 0) return 0;\n\n\t\treturn (parseInt(p/k) + 1) * k - p;\n\n\t}());\n\n}.call(this));\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar spanNum = integers[0], factor = integers[1];\n\n\tvar total = 0;\n\n\tfor (var i = 0; i < spanNum; i += 1) {\n\t\tvar span = tokenizeIntegers(readline());\n\t\ttotal += span[1] - span[0] + 1;\n\t}\n\n\tprint((factor-total%factor)%factor);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar spanNum = integers[0], factor = integers[1];\n\n\tvar total = 0;\n\n\tfor (var i = 0; i < spanNum; i += 1) {\n\t\tvar span = tokenizeIntegers(readline());\n\t\ttotal += span[1] - span[0] + 1;\n\t}\n\n\tprint(Math.min(total%factor, factor-total%factor));\n}\n\nmain();\n"}], "src_uid": "3a93a6f78b41cbb43c616f20beee288d"} {"source_code": "\n var tmp = readline().split(' ').map(function(x) {\n return parseInt(x);\n });\n var n = tmp[0];\n var k = tmp[1];\n var d = readline().split(' ').map(function(x) {\n return parseInt(x);\n });\n var children = new Array(n).fill(0).map(function(x, i) {\n return i + 1;\n });\n var curr = 0;\n var res = [];\n for(var i = 0; i < k; i += 1) {\n curr = (curr + d[i] % children.length) % children.length;\n res.push(children[curr]);\n children.splice(curr, 1);\n }\n print(res.join(' '));\n", "positive_code": [{"source_code": "var params = readline().split(\" \").map(function convert(value) {return +value; });\nvar n = params[0];\nvar k = params[1];\nvar input = readline().split(\" \").map(function convert(value) {return +value;});\nvar children = [];\nvar answer = [];\nvar prevChildIndex = 0;\n\nfor (var i = 1; i <= n; i++)\n\tchildren.push(i);\n\nfor (var i = 0; i < k; i++ ) {\n\tvar curChildIndex = (prevChildIndex + input[i]) % children.length;\n\tanswer.push(children.splice(curChildIndex, 1));\n\tprevChildIndex = curChildIndex % children.length;\n}\n\nprint(answer.join(\" \"));\n"}, {"source_code": "if (typeof print === 'undefined') print = console.log;\nif (typeof readline === 'undefined') readline = (function() {\n var lines = require('fs').readFileSync('/dev/stdin').toString().split('\\n');\n var id = 0;\n return function() {return lines[id++];}\n})();\n\nvar t = readline().split(' ');\nvar n = +t[0], q = +t[1];\nvar a = readline().split(' ' ).map(function(x) { return (+x); });\n\nvar qu = [], ans = [];\nfor (var i = -1; ++i < n; ) qu.push(i + 1);\n\nfor (var i = -1; ++i < q; ) {\n var k = (a[i]) % qu.length;\n //console.warn(k);\n for (var f = k; f--; ) {\n qu.push(qu[0]);\n qu.shift();\n }\n ans.push(qu.shift());\n}\nprint(ans.join(' '));\n\n\n"}, {"source_code": "/*\n The idea to solve this problem is by using index of child number in array instead of\n using the child number itself.\n \n If we are using index, we could get consistent behavior with mod formula. For example\n if we want to move 7 times on circular array which have 7 elements starting from index \n after 0 (index 1), then we will arrive again at index 0 ((0 + 7) % 7 = 0).\n*/\n\nvar params = readline().split(' ').map(Number),\n n = params[0],\n k = params[1];\n\nvar counts = readline().split(' ').map(Number),\n children = [],\n eliminated_children = [];\n\nvar leaderIdx = 0;\n\nfor(var i = 1; i <= n; i++)\n children.push(i);\n\nfor(var i = 0; i < k; i++) {\n \n var eliminatedIdx = (leaderIdx + counts[i]) % children.length;\n \n eliminated_children.push(children.splice(eliminatedIdx, 1));\n leaderIdx = eliminatedIdx % children.length; \n}\n\nprint(eliminated_children.join(' '));"}, {"source_code": "var params = readline().split(' ').map(Number),\n n = params[0],\n k = params[1];\n\nvar counts = readline().split(' ').map(Number),\n children = [],\n eliminated_children = [];\n\nvar leaderIdx = 0;\n\nfor(var i = 1; i <= n; i++)\n children.push(i);\n\nfor(var i = 0; i < k; i++) {\n \n var eliminatedIdx = (leaderIdx + counts[i]) % children.length;\n \n eliminated_children.push(children.splice(eliminatedIdx, 1));\n leaderIdx = eliminatedIdx % children.length; \n}\n\nprint(eliminated_children.join(' '));"}], "negative_code": [{"source_code": "var params = readline().split(\" \").map(function convert(value) {return +value; });\nvar n = params[0];\nvar k = params[1];\nvar input = readline().split(\" \").map(function convert(value) {return +value;});\nvar children = [];\nvar answer = [];\nvar prevChildIndex = 0;\n\nfor (var i = 1; i <= n; i++)\n\tchildren.push(i);\n\nfor (var i = 0; i < k; i++ ) {\n\tvar curChildIndex = (prevChildIndex + input[i]) % children.length;\n\tanswer.push(children.splice(curChildIndex, 1));\n\tprevChildIndex = curChildIndex % children.length;\n}\n\nprint(answer);\n"}], "src_uid": "5512fbe2963dab982a58a14daf805291"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tvar h = 0;\n\tfor(i = 1; i <= t * 2; i++) {\n\t\tvar a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0]; h = a[1];\n }else{\n a = a.sort(function(a, b){return b - a});\n \t\tvar x = a[0]; var y = a[1];\n \t\tvar b = 2 * Math.floor(h / (x + y)); var c = h % (x + y);\n if(c === 0){\n \n }else if(c <= x){\n \t\t\tb++;\n \t\t}else {\n \t\t\tb+=2;\n \t\t}\n \t\tconsole.log(b);\n }\n\t}\n});", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var t = lines[0];\n\tvar n = 0;\n\tvar h = 0;\n\tfor(i = 1; i <= t * 2; i++) {\n\t\tvar a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0]; h = a[1];\n }else{\n a = a.sort(function(a, b){return b - a});\n \t\tvar x = a[0]; var y = a[1];\n \t\tvar b = 2 * Math.floor(h / (x + y)); var c = h % (x + y);\n if(c === 0){\n \n }else if(c <= x){\n \t\t\tb++;\n \t\t}else {\n \t\t\tb+=2;\n \t\t}\n \t\tconsole.log(b);\n }\n\t}\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar X = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar max = list[0];\r\n\t\tvar max2 = list[1];\r\n\t\tvar output = Math.floor(X / (max + max2));\r\n\t\tX -= output * (max + max2);\r\n\t\toutput *= 2;\r\n\t\tif(X > 0){\r\n\t\t\tX -= max;\r\n\t\t\toutput++;\r\n\t\t}\r\n\t\tif(X > 0){\r\n\t\t\tX -= max2;\r\n\t\t\toutput++;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, h] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, h, arr))\n }\n// })()\n})\n\nfunction solve(n, h, arr) {\n const [x, y] = arr.sort((a, b) => b - a)\n const k = Math.floor(h / (x + y))\n const r = h - k * (x + y)\n if (!r) {\n return k * 2\n } else if (r <= x) {\n return k * 2 + 1\n } else {\n return k * 2 + 2\n }\n}\n"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tvar h = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0];\n h = k[1];\n }else{\n k = k.sort(function(a, b){return b - a});\n var x = k[0];\n var y = k[1];\n var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);\n if(b === 0){\n \n }else if(b % 1 === 0){\n a++;\n }else{\n a+=2;\n }\n console.log(a);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tvar h = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0];\n h = k[1];\n }else{\n k = k.sort(function(a, b){return b - a});\n var x = k[0];\n var y = k[1];\n var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);\n if(b === 0){\n \n }else if(b % 2 == 1){\n a+=2;\n }else{\n a++;\n }\n console.log(a);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tvar h = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0];\n h = k[1];\n }else{\n k = k.sort(function(a, b){return b - a});\n var x = k[0];\n var y = k[1];\n var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);\n if(b === 0){\n \n }else if(b % 2 === 0){\n a++;\n }else{\n a+=2;\n }\n console.log(a);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n var hp = 0;\n var a = 0;\n var b = 0;\n for(var j = 1; j <= n * 2; j++){\n var k = lines[j].split(' ').map(Number);\n if(j % 2 == 1){\n e = k[0];\n hp = k[1];\n }else{\n k = k.sort(function(a, b){return b - a});\n a = k[0];\n b = k[1];\n if(hp % (a + b) === 0){\n console.log((hp / (a + b)) * 2);\n }else if(hp % (a + b) <= a){\n console.log(Math.floor(((hp / (a + b)) * 2) + 1));\n }else{\n console.log(Math.floor(((hp / (a + b)) * 2) + 2));\n }\n }\n }\n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n \n for(j = 1; j <= n;j ++){\n var a = lines[j].split(' ').map(Number)\n console.log((a[1] - a[0]) - 1)\n }\n});\n\n"}], "src_uid": "4d5457d9f053556c78c102f5c32f7542"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n if (n === 1) {\r\n console.log(0);\r\n continue;\r\n }\r\n else if(n===2){\r\n if(str[0]===str[1]) console.log(0);\r\n else console.log(1);\r\n continue;\r\n }\r\n let fr = new Set();\r\n for (let i = 0; i < n; i++) fr.add(str[i]);\r\n if (fr.size === n) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - i - 1]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(0);\r\n continue;\r\n }\r\n let res = [];\r\n for (let i of fr) {\r\n let l = 0,\r\n r = n - 1,\r\n cnt = 0,\r\n flag = true;\r\n while (l <= r) {\r\n if (str[l] === str[r]) {\r\n l++;\r\n r--;\r\n } else if (str[l] === i) {\r\n l++;\r\n cnt++;\r\n } else if (str[r] === i) {\r\n r--;\r\n cnt++;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) res.push(cnt);\r\n }\r\n if (res.length) {\r\n let min = Infinity;\r\n for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);\r\n console.log(min);\r\n } else console.log(-1);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "const acode = 'a'.charCodeAt(0);\r\nconst zcode = 'z'.charCodeAt(0);\r\n\r\nfunction solve() {\r\n const n = Number(read());\r\n const str = read();\r\n let ans = Infinity;\r\n for (let i = acode; i <= zcode; i++) {\r\n const letter = String.fromCharCode(i);\r\n let currentAns = 0;\r\n let left = 0;\r\n let right = n - 1;\r\n while(true) {\r\n if (left > right) {\r\n break;\r\n }\r\n if (str[left] === str[right]) {\r\n left++;\r\n right--;\r\n continue;\r\n }\r\n if (str[left] === letter) {\r\n currentAns++;\r\n left++;\r\n continue;\r\n }\r\n if (str[right] === letter) {\r\n currentAns++;\r\n right--;\r\n continue;\r\n }\r\n currentAns = Infinity;\r\n break;\r\n }\r\n if (currentAns < ans) {\r\n ans = currentAns;\r\n }\r\n }\r\n write(ans === Infinity ? -1 : ans);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet i = 0, j = n - 1;\r\n\t\twhile (i < j && s[i] == s[j]) {\r\n\t\t\ti++; j--;\r\n\t\t}\r\n\r\n\t\tif (i >= j) { console.log(0); continue; }\r\n\r\n\t\tfunction check(i, j, k) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\twhile (i < j) {\r\n\t\t\t\tif (s[i] == s[j]) {\r\n\t\t\t\t\ti++; j--;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (s[i] == s[k]) {\r\n\t\t\t\t\t\tcnt++; i++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (s[j] == s[k]) { \r\n\t\t\t\t\t\tcnt++; j--;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse return -1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn cnt;\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tx = check(i, j, i);\r\n\t\ty = check(i, j, j);\r\n\t\tif (x == -1 || y == -1) ans = Math.max(x ,y);\r\n\t\telse ans = Math.min(x, y);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let ans = Infinity\n for (let i = 0; i < 26; i++) {\n const cur = isp(str, String.fromCharCode('a'.charCodeAt(0) + i))\n if (cur >= 0) {\n ans = Math.min(ans, cur)\n }\n }\n return ans === Infinity ? -1 : ans\n\n// let count = Array(26).fill(0)\n// for (let i = 0; i < str.length; i++) {\n// const k = str.charCodeAt(i) - 'a'.charCodeAt(0)\n// count[k]++\n// }\n// const final = count\n// // console.log(final)\n// count = Array(26).fill(0)\n// for (let i = 0; i < str.length; i++) {\n// const k = str.charCodeAt(i) - 'a'.charCodeAt(0)\n// count[k]++\n\n// let same = 0\n// let diff\n// for (let j = 0; j < final.length; j++) {\n// if (count[j] * 2 === final[j]) {\n// same++\n// } else {\n// diff = Math.abs(final[j] - count[j] * 2)\n// }\n// }\n// if (same === 25) {\n// ans = Math.min(ans, diff)\n// }\n// }\n}\nfunction isp(str, ch) {\n let i = 0\n let j = str.length - 1\n let left = 0\n let right = 0\n while (i < j) {\n if (str[i] === ch && str[j] === ch) {\n i++\n j--\n left++\n right++\n } else if (str[i] === ch) {\n i++\n left++\n } else if (str[j] === ch) {\n j--\n right++\n } else {\n if (str[i] !== str[j]) return -1\n i++\n j--\n }\n }\n\n i = 0\n j = str.length - 1\n let ans = 0\n while (i < j) {\n if (str[i] !== str[j]) {\n if (str[i] === ch) {\n i++\n left--\n } else if (str[j] === ch) {\n j--\n right++\n } else if (left > right) {\n i++\n left--\n } else {\n j--\n right--\n }\n ans++\n } else {\n i++\n j--\n }\n }\n return ans\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n if (n === 1) {\r\n console.log(0);\r\n continue;\r\n }\r\n let fr = new Set();\r\n for (let i = 0; i < n; i++) fr.add(str[i]);\r\n if (fr.size === n) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - i - 1]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(0);\r\n continue;\r\n }\r\n let res = [];\r\n for (let i of fr) {\r\n let l = 0,\r\n r = n - 1,\r\n cnt = 0,\r\n flag = true;\r\n while (l <= r) {\r\n if (str[l] === str[r]) {\r\n l++;\r\n r--;\r\n } else if (str[l] === i) {\r\n l++;\r\n cnt++;\r\n } else if (str[r] === i) {\r\n r--;\r\n cnt++;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) res.push(cnt);\r\n }\r\n if (res.length) {\r\n let min = Infinity;\r\n for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);\r\n console.log(min);\r\n } else console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n let fr = new Set();\r\n for (let i = 0; i < n; i++) fr.add(str[i]);\r\n if (fr.size === n) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== str[n - i - 1]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(0);\r\n continue;\r\n }\r\n let res = [];\r\n for (let i of fr) {\r\n let l = 0,\r\n r = n - 1,\r\n cnt = 0,\r\n flag = true;\r\n while (l <= r) {\r\n if (str[l] === str[r]) {\r\n l++;\r\n r--;\r\n } else if (str[l] === i) {\r\n l++;\r\n cnt++;\r\n } else if (str[r] === i) {\r\n r--;\r\n cnt++;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) res.push(cnt);\r\n }\r\n if (res.length) {\r\n let min = Infinity;\r\n for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);\r\n console.log(min);\r\n } else console.log(-1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet i = 0, j = n - 1;\r\n\t\twhile (i < j && s[i] == s[j]) {\r\n\t\t\ti++; j--;\r\n\t\t}\r\n\r\n\t\tif (i >= j) { console.log(0); continue; }\r\n\r\n\t\tfunction check(i, j, k) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\twhile (i < j) {\r\n\t\t\t\tif (s[i] == s[j]) {\r\n\t\t\t\t\ti++; j--;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (s[i] == s[k]) {\r\n\t\t\t\t\t\tcnt++; i++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (s[j] == s[k]) { \r\n\t\t\t\t\t\tcnt++; j--;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse return -1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn cnt;\r\n\t\t}\r\n\r\n\t\tans = check(i, j, i);\r\n\t\tif (ans == -1) ans = check(i, j, j);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let ans = Infinity\n for (let i = 0; i < 26; i++) {\n const cur = isp(str, String.fromCharCode('a'.charCodeAt(0) + i))\n if (cur >= 0) {\n ans = Math.min(ans, cur)\n }\n }\n return ans === Infinity ? -1 : ans\n\n// let count = Array(26).fill(0)\n// for (let i = 0; i < str.length; i++) {\n// const k = str.charCodeAt(i) - 'a'.charCodeAt(0)\n// count[k]++\n// }\n// const final = count\n// // console.log(final)\n// count = Array(26).fill(0)\n// for (let i = 0; i < str.length; i++) {\n// const k = str.charCodeAt(i) - 'a'.charCodeAt(0)\n// count[k]++\n\n// let same = 0\n// let diff\n// for (let j = 0; j < final.length; j++) {\n// if (count[j] * 2 === final[j]) {\n// same++\n// } else {\n// diff = Math.abs(final[j] - count[j] * 2)\n// }\n// }\n// if (same === 25) {\n// ans = Math.min(ans, diff)\n// }\n// }\n}\nfunction isp(str, ch) {\n let i = 0\n let j = str.length - 1\n let left = 0\n let right = 0\n while (i < j) {\n if (str[i] === ch && str[j] === ch) {\n i++\n j--\n left++\n right++\n } else if (str[i] === ch) {\n i++\n left++\n } else if (str[j] === ch) {\n j--\n right++\n } else {\n if (str[i] !== str[j]) return -1\n i++\n j--\n }\n }\n\n i = 0\n j = str.length - 1\n let ans = 0\n while (i < j) {\n if (str[i] !== str[j]) {\n if (left > right) {\n i++\n left--\n } else {\n j--\n right--\n }\n ans++\n } else{\n i++\n j--\n }\n }\n return ans\n}\n"}], "src_uid": "8ca8317ce3f678c99dc746cb9b058993"} {"source_code": " var limit = parseInt(readline());\r\n var alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',\r\n 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\r\n 'w', 'x', 'y', 'z'];\r\n for (var i = 0; i < limit; i++)\r\n {\r\n var codeLength = parseInt(readline()) - 1; \r\n var codeNum = readline();\r\n var result = \"\";\r\n while (codeLength >= 0)\r\n {\r\n var current = parseInt(codeNum[codeLength]);\r\n if (current !== 0)\r\n {\r\n result = alphabets[current-1] + result;\r\n }\r\n else\r\n {\r\n codeLength -= 2;\r\n var newCodeNum = codeNum[codeLength] + codeNum[codeLength+1];\r\n var newCurrent = parseInt(newCodeNum);\r\n result = alphabets[newCurrent-1] + result;\r\n }\r\n codeLength--;\r\n }\r\n print(result);\r\n }", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn();\r\n const s = read();\r\n let res = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (s[i] === '0') {\r\n res.push(String.fromCharCode(Number(s.slice(i - 2, i)) + 96));\r\n i -= 2;\r\n } else {\r\n res.push(String.fromCharCode(Number(s.slice(i, i + 1)) + 96));\r\n }\r\n }\r\n return res.reverse().join('');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\r\nfunction numberToLetter(num) {\r\n\treturn (num + 9).toString(36)\r\n}\r\n\r\n\r\nfunction foo(str) {\r\n\t\r\n \tvar i = 0\r\n var result = ''\r\n \r\n while(i < str.length) {\r\n \tif(str[i + 2] === '0' && str[i + 3] !== '0') {\r\n result += numberToLetter(Number(str[i] + str[i+1]))\r\n i += 3\r\n } \r\n \telse {\r\n \tresult += numberToLetter(Number(str[i]))\r\n \ti++\r\n }\r\n }\r\n \r\n \treturn result\r\n}\r\n\r\nvar count = readline();\r\n\r\nvar inp;\r\nvar size;\r\n\r\nfor(var i = 0 ; i < count ; i++) {\r\n readline();\r\n inp = readline();\r\n print(foo(inp));\r\n\r\n}"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i= 0) {\n var num = str[j]\n if (str[j] == \"0\") {\n num = Number(str[j-2] + str[j-1])\n j -= 2\n }\n j--\n var char = ref[num]\n ans = char + ans\n }\n print(ans)\n}"}, {"source_code": "var dict = {\r\n '1': 'a',\r\n '2': 'b',\r\n '3': 'c',\r\n '4': 'd',\r\n '5': 'e',\r\n '6': 'f',\r\n '7': 'g',\r\n '8': 'h',\r\n '9': 'i',\r\n '10': 'j',\r\n '11': 'k',\r\n '12': 'l',\r\n '13': 'm',\r\n '14': 'n',\r\n '15': 'o',\r\n '16': 'p',\r\n '17': 'q',\r\n '18': 'r',\r\n '19': 's',\r\n '20': 't',\r\n '21': 'u',\r\n '22': 'v',\r\n '23': 'w',\r\n '24': 'x',\r\n '25': 'y',\r\n '26': 'z',\r\n}\r\n\r\nvar q = parseInt(readline());\r\n \r\nfor (var test = 0; test < q; test++) {\r\n var n = parseInt(readline());\r\n var str = readline();\r\n var ans = [];\r\n\r\n for (var i = n - 1; i >= 0; ) {\r\n if (str[i] === '0') {\r\n ans.push(dict[str[i-2] + str[i-1]]);\r\n i -= 3;\r\n } else {\r\n ans.push(dict[str[i]]);\r\n i--;\r\n }\r\n }\r\n\r\n print(ans.reverse().join(''));\r\n}"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline()\r\n var str = readline()\r\n print(TwoElevators(str))\r\n \r\n}\r\n \r\nfunction TwoElevators(str){\r\n var list = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"];\r\n\r\n var newstr = '';\r\n\r\n for(var i = str.length -1; i >= 0; i--){\r\n if (str[i] == '0'){\r\n var num = str[i-2] + str[i-1]\r\n newstr = list[+num-1] + newstr;\r\n i -= 2\r\n }else {\r\n var num2 = str[i] \r\n newstr = list[+num2-1] + newstr;\r\n }\r\n }\r\n\r\n return newstr;\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main() {\r\n let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];\r\n let n = readline();\r\n for (let k = 0; k < n; k++) {\r\n var o = readline();\r\n var splittedSTR = readline().trim().split('');\r\n var output = [];\r\n for (var i = 0; i < o; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n if (o - i == 1) {\r\n for (var j = 0; j < splittedSTR.length; j++) {\r\n output.push(Alpha[splittedSTR[j] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\n\nconst fs = require(\"fs\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/*\n * Complete the 'decodeString' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts 2D_INTEGER_ARRAY arr as parameter.\n */\n\nfunction decodeString(arr) {\n // Write your code here\n const dict = [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n \"i\",\n \"j\",\n \"k\",\n \"l\",\n \"m\",\n \"n\",\n \"o\",\n \"p\",\n \"q\",\n \"r\",\n \"s\",\n \"t\",\n \"u\",\n \"v\",\n \"w\",\n \"x\",\n \"y\",\n \"z\",\n ];\n\n for (let i = 0; i < arr.length; i++) {\n const string = arr[i].toString().split(\"\");\n const stringLength = string.length;\n let text = \"\";\n let j = 0;\n while (j < string.length) {\n let posPlus2 = string[j + 2];\n let posPlus3 = string[j + 3];\n if (\n j + 2 < stringLength &&\n Number(posPlus2) === 0 &&\n ((j + 3 < stringLength && Number(posPlus3) !== 0) ||\n j + 3 >= stringLength)\n ) {\n const pos = string[j] + string[j + 1];\n text += dict[Number(pos - 1)];\n\n j += 3;\n } else {\n const pos = string[j];\n text += dict[Number(pos - 1)];\n j += 1;\n }\n }\n console.log(text);\n }\n}\n\nfunction main() {\n const n = parseInt(readLine().trim());\n let arr = Array(n);\n for (let i = 0; i < n * 2; i++) {\n let text = readLine().replace(/\\s+$/g, \"\").split(\" \");\n if (i % 2 === 1) {\n arr[Math.floor(i / 2)] = text.map((arrTemp) => arrTemp.toString())[0];\n }\n }\n\n const result = decodeString(arr);\n}\n\n \t \t \t \t\t\t\t \t\t\t\t\t\t\t \t\t\t"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction main() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const n = readInt();\r\n const str = readString();\r\n\r\n let count = 0;\r\n let ans = \"\";\r\n let asd = 0;\r\n while (count < n) {\r\n // console.log(str.slice(count + 2, count + 4), \"(((((((((\");\r\n if (str.slice(count + 2, count + 4) == \"00\") {\r\n asd = str[count];\r\n count++;\r\n } else if (count < n - 2 && str[count + 2] == \"0\") {\r\n asd = str.slice(count, count + 2);\r\n count += 2;\r\n } else {\r\n asd = str[count];\r\n count++;\r\n }\r\n\r\n ans += String.fromCharCode(+asd + 96);\r\n ans = ans.replace(\"`\", \"\");\r\n // console.log(asd, String.fromCharCode(+asd + 96), \"after\");\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\n// function print(x) {\r\n// console.log(x);\r\n// }\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let alphabet = \"abcdefghijklmnopqrstuvwxyz\";\r\n let arr = [];\r\n let TC = readline();\r\n for (let m = 0; m < TC; m++) {\r\n let res = \"\";\r\n let stringLeng = readline();\r\n let str = \"\" + readline();\r\n for (let i = stringLeng - 1; i + 1; i--) {\r\n if (str[i] != 0) res += alphabet[str[i] - 1];\r\n else {\r\n let jam = str[i - 1] + str[i - 2];\r\n jam = jam.split(\"\").reverse().join(\"\");\r\n res += alphabet[jam - 1];\r\n i--;\r\n i--;\r\n }\r\n }\r\n res = res.split(\"\").reverse().join(\"\");\r\n arr.push(res);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n"}, {"source_code": "// Author: shubh_singh\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet currentLine = 0;\nlet inputString = \"\";\n \nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n if(!inputString) {\n console.warn(\"Input file is empty.\");\n return;\n }\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n \nreadInt = () => {\n return Number(inputString[currentLine++]);\n}\n \nreadString = () => {\n return inputString[currentLine++];\n}\n \nreadArrayInt = () => {\n return inputString[currentLine++].split(\" \").map(Number);\n}\n \nreadArray = () => {\n return inputString[currentLine++].split(\" \");\n}\n\n// Solve\nsolve = () => {\n let n = readInt();\n let s = readString();\n let i = n-1;\n let res = \"\";\n while(i >= 0) {\n if(s[i] == '0') {\n let val = parseInt(s[i-2]+s[i-1]);\n let code = String.fromCharCode(val+96);\n res += code;\n i -= 3;\n }else {\n let code = String.fromCharCode(parseInt(s[i])+96);\n res += code; \n i--;\n }\n }\n\n console.log(res.split(\"\").reverse().join(\"\"));\n}\n\nmain = () => {\n let t = readInt();\n while(t--)\n solve();\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n for (let i = 2; i <= testCases * 2; i += 2) {\n const nums = inputString[i].split(\"\").map((s) => Number(s));\n\n const answer = nums\n .reduce((acc, cur, ix, arr) => {\n if (cur === 0 && arr[ix + 1] !== 0) {\n const n = Number(acc[acc.length - 2] + \"\" + acc[acc.length - 1]);\n acc = acc.slice(0, -2);\n acc.push(n);\n } else acc.push(cur);\n\n return acc;\n }, [])\n .map((n) => String.fromCharCode(n + 96))\n .join(\"\");\n\n console.log(answer);\n }\n}\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst getDictionary = () => {\r\n let dict = []\r\n for (let i = 1; i <= 26; i++) {\r\n let d = {\r\n 'letter': String.fromCharCode(97 + (i - 1)),\r\n 'value': i,\r\n }\r\n dict.push(d)\r\n }\r\n\r\n return dict\r\n}\r\n\r\nfunction getResult(n, enc, dict) {\r\n let dec = ''\r\n \r\n enc = enc.split('').map(Number)\r\n\r\n if (n == 1) return dict.find(r => r.value == enc[0])['letter']\r\n if (n == 2) return dict.find(r => r.value == enc[0])['letter'] + dict.find(r => r.value == enc[1])['letter']\r\n\r\n let dis = []\r\n\r\n let i = n - 1\r\n while (i >= 0) {\r\n if (enc[i] != 0) dis.push(enc[i].toString())\r\n else {\r\n let temp = ''\r\n let j = i - 1\r\n while (j >= (i - 2)) {\r\n temp += enc[j].toString()\r\n j--\r\n }\r\n dis.push(temp.split('').reverse().join(''))\r\n i = j + 1\r\n }\r\n i--\r\n }\r\n\r\n dis.reverse().forEach(d => {\r\n dec += dict.find(r => r.value == parseInt(d))['letter']\r\n })\r\n\r\n return dec\r\n}\r\n\r\nfunction main() {\r\nlet dict = getDictionary()\r\n let testCases = parseInt(readline())\r\n while (testCases--) {\r\n let n = parseInt(readline())\r\n let enc = readline()\r\n console.log( getResult(n, enc, dict) )\r\n }\r\n}\r\n\r\n//*/\r\n\r\n// console.clear()\r\n// let n = 0\r\n// let enc = 0\r\n// let dict = getDictionary()\r\n\r\n// n = 6\r\n// enc = '315045'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 4\r\n// enc = '1100'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 7\r\n// enc = '1213121'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 6\r\n// enc = '120120'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 18\r\n// enc = '315045615018035190'\r\n// console.log(getResult(n, enc, dict))\r\n\r\n// n = 7\r\n// enc = '1111110'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 7\r\n// enc = '1111100'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 5\r\n// enc = '11111'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// n = 4\r\n// enc = '2606'\r\n// console.log( getResult(n, enc, dict) )\r\n\r\n// process.exit(1)\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let i = n - 1\n const r = []\n while (i >= 0) {\n if (str[i] === '0') {\n r.unshift(ch(+str.slice(i - 2, i)))\n i -= 3\n } else {\n r.unshift(ch(+str[i]))\n i--\n }\n }\n return r.join('')\n}\nfunction ch(i) {\n const a = 'a'.charCodeAt(0)\n return String.fromCharCode(a + i - 1)\n}\n"}], "negative_code": [{"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n let output = [];\r\n if (splittedSTR.length == 1) {\r\n if (f == undefined) {\r\n f = data.toString().trim();\r\n } else {\r\n }\r\n return;\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n z++\r\n if (z == f) {\r\n process.exit();\r\n }\r\n }\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = 0, f;\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n let output = [];\r\n if (splittedSTR.length == 1) {\r\n if (f == undefined) {\r\n f = data.toString().trim();\r\n } else {\r\n }\r\n return;\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n z++\r\n console.log(z, f);\r\n }\r\n }\r\n if (z == (f + 1)) {\r\n console.log('obj');\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n let output = [];\r\n if (splittedSTR.length == 1) {\r\n return;\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n if (data.length == 1) data = data.toString().trim();\r\n let output = [];\r\n for (var i = 0; i < data; i++) {\r\n if (i == 0) {}\r\n else if (i % 2 == 0) {}\r\n else {\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n }\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n if (data.length == 1) data = data.toString().trim();\r\n let output = [];\r\n for (var i = 0; i < data; i++) {\r\n if (i == 0) {}\r\n else if (i % 2 != 0) {}\r\n else {\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n }\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n let output = []\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n})\r\n"}, {"source_code": "let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nprocess.stdin.on('data', function (data) {\r\n var splittedSTR = data.toString().trim().split('')\r\n let output = []\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n splittedSTR.splice(i + 1, 1)\r\n splittedSTR.splice(i - 1, 1)\r\n }\r\n }\r\n console.log(splittedSTR);\r\n for (var i = 0; i < splittedSTR.length; i++) {\r\n output.push(Alpha[splittedSTR[i] - 1])\r\n if (output.length == splittedSTR.length) {\r\n console.log(output.join(''));\r\n }\r\n }\r\n})\r\n"}, {"source_code": "\"use strict\";\n\nconst fs = require(\"fs\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/*\n * Complete the 'decodeString' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts 2D_INTEGER_ARRAY arr as parameter.\n */\n\nfunction decodeString(arr) {\n // Write your code here\n const dict = [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n \"i\",\n \"j\",\n \"k\",\n \"l\",\n \"m\",\n \"n\",\n \"o\",\n \"p\",\n \"q\",\n \"r\",\n \"s\",\n \"t\",\n \"u\",\n \"v\",\n \"w\",\n \"x\",\n \"y\",\n \"z\",\n ];\n let result = [];\n for (let i = 0; i < arr.length; i++) {\n const string = arr[i].toString().split(\"\");\n const stringLength = string.length;\n result[i] = [\"\"];\n let j = 0;\n while (j < string.length) {\n let posPlus2 = string[j + 2];\n let posPlus3 = string[j + 3];\n if (\n j + 2 < stringLength &&\n Number(posPlus2) === 0 &&\n ((j + 3 < stringLength && Number(posPlus3) !== 0) ||\n j + 3 >= stringLength)\n ) {\n const pos = string[j] + string[j + 1];\n result[i] += dict[Number(pos - 1)];\n\n j += 3;\n } else {\n const pos = string[j];\n result[i] += dict[Number(pos - 1)];\n j += 1;\n }\n }\n }\n}\n\nfunction main() {\n const n = parseInt(readLine().trim());\n let arr = Array(n);\n for (let i = 0; i < n * 2; i++) {\n let text = readLine().replace(/\\s+$/g, \"\").split(\" \");\n if (i % 2 === 1) {\n arr[Math.floor(i / 2)] = text.map((arrTemp) => arrTemp.toString())[0];\n }\n }\n\n const result = decodeString(arr);\n console.log(\"result:\", result);\n}\n\n \t\t \t \t\t\t \t\t\t\t\t\t\t\t \t\t \t \t \t \t\t"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction main() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const n = readInt();\r\n const str = readString();\r\n\r\n let count = 0;\r\n let ans = \"\";\r\n while (count < n) {\r\n let asd = 0;\r\n // console.log(str[count]);\r\n if (count < n - 2 && str[count + 2] == \"0\") {\r\n asd = str[count] + str[count + 1];\r\n count += 2;\r\n } else {\r\n asd = str[count];\r\n count++;\r\n }\r\n\r\n if (asd != \"0\") {\r\n ans += String.fromCharCode(+asd + 96);\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\n// function print(x) {\r\n// console.log(x);\r\n// }\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let alphabet = \"abcdefghijklmnopqrstuvwxyz\";\r\n let arr = [];\r\n let TC = readline\r\n for (let m = 0; m < TC; m++) {\r\n let res = \"\";\r\n let stringLeng = readline();\r\n let str = readline();\r\n for (let i = stringLeng - 1; i + 1; i--) {\r\n if (str[i] != 0) res += alphabet[str[i] - 1];\r\n else {\r\n let jam = str[i - 1] + str[i - 2];\r\n jam = jam.split(\"\").reverse().join(\"\");\r\n res += alphabet[jam - 1];\r\n i--;\r\n i--;\r\n }\r\n }\r\n res = res.split(\"\").reverse().join(\"\");\r\n arr.push(res);\r\n }\r\n arr = arr.join(\"\\n\");\r\n console.log(arr);\r\n}\r\n\r\n"}], "src_uid": "43081557fe2fbac39dd9b72b137b8fb0"} {"source_code": "var t = parseInt(readline());\r\nwhile(t--)\r\n{\r\n\tvar ar = readline().split(' ').map(x => +x);\r\n\tvar n = ar[0];\r\n\tvar k = ar[1];\r\n\tvar row = readline().split(' ').map(x => +x);\r\n\tvar low = 0,high = 100000000000,ans = -1;\r\n\twhile(low<=high)\r\n\t{\r\n\t\tvar mid = (low + high)/2;\r\n\t\tmid = Math.floor(mid);\r\n\t\tvar sum = row[0] + mid;\r\n\t\tvar chk = 1;\r\n\t\tfor(var i=1;i sum*k) chk = 0;\r\n\t\t\tsum += row[i];\r\n\t\t}\r\n\t\tif(chk)\r\n\t\t{\r\n\t\t\tans = mid;\r\n\t\t\thigh = mid - 1;\r\n\t\t}\r\n\t\telse low = mid + 1;\r\n\t}\r\n\tprint(ans);\r\n}", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst p = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tlet psum = p[0];\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tans = Math.max(ans, Math.max(0, Math.ceil(100 * p[i] / k - psum)));\r\n\t\t\tpsum += p[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++) {\r\n var caseConstraints = readline().split(\" \");\r\n var caseLength = parseInt(caseConstraints[0]);\r\n var inflationLimit = parseInt(caseConstraints[1]);\r\n var caseArray = readline().split(\" \");\r\n var caseIntArray = new Array();\r\n var total = 0;\r\n for (var j = 0; j < caseLength; j++) {\r\n var value = parseInt(caseArray[j]);\r\n if (j !== caseLength - 1) {\r\n total += value;\r\n }\r\n caseIntArray.push(value);\r\n }\r\n var addition = 0;\r\n var rightSide = inflationLimit / 100;\r\n for (var j = caseLength - 1; j > 0; j--) {\r\n if (j < caseLength - 1) {\r\n total -= caseIntArray[j];\r\n }\r\n var leftSide = caseIntArray[j] / total;\r\n if (leftSide > rightSide) {\r\n var newTotal = Math.ceil(caseIntArray[j] * 100 / inflationLimit);\r\n addition += newTotal - total;\r\n total = newTotal;\r\n }\r\n }\r\n print(addition);\r\n }"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var sum = []\r\n var array = readline().split(' ').map((x, i) => {\r\n if (i === 0) sum.push(Number(x))\r\n if (i > 0)sum.push(sum[i - 1] + Number(x))\r\n\r\n return Number(x)\r\n });\r\n var answer = 0\r\n // console.log(sum)\r\n for (var i = n - 1; i > 0; i--) {\r\n // console.log(array[i], sum[i - 1])\r\n sum[i-1] = sum[i-1] + answer\r\n var number = Math.ceil(array[i] * 100 / k) - sum[i - 1]\r\n // console.log(number)\r\n if (number > 0) {\r\n answer += number\r\n }\r\n // console.log(sum)\r\n }\r\n console.log(answer)\r\n\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n, k] = readline().split(' ').map(x => Number(x));\r\n var sum = []\r\n var array = readline().split(' ').map((x, i) => {\r\n if (i === 0) sum.push(Number(x))\r\n if (i > 0)sum.push(sum[i - 1] + Number(x))\r\n\r\n return Number(x)\r\n });\r\n var answer = 0\r\n for (var i = n - 1; i > 0; i--) {\r\n // console.log(array[i], sum[i - 1])\r\n var number = Math.ceil(array[i] * 100 / k) - sum[i - 1]\r\n // console.log(number)\r\n if (number > 0) answer += number\r\n }\r\n console.log(answer)\r\n\r\n })\r\n}\r\n\r\n"}], "src_uid": "53975eea2503bb47bfd0a5119406aea3"} {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar min = 10000000000;\n\t\tif(N <= K){\n\t\t\toutput[i] = 1;\n\t\t\tcontinue;\n\t\t}\n\t\tvar list = getDivisorList(N);\n\t\tfor(var j = 0; j < list.length; j++){\n\t\t\tif(list[j] <= K){\n\t\t\t\tmin = N / list[j];\n\t\t\t}\n\t\t}\n\t\toutput[i] = min;\n\t}\n\tmyout(myconv(output,9));\n}\nfunction getDivisorList(val){\n var list = [];\n for(var i = 1; i * i <= val; i++){\n if(val % i == 0){\n list.push(i);\n if(i * i != val){\n list.push(val / i);\n }\n }\n }\n list.sort(function(a,b){ return a - b; });\n return list;\n}", "positive_code": [{"source_code": "function getFactors(num) {\n const isEven = num % 2 === 0;\n let inc = isEven ? 1 : 2;\n let factors = [1, num];\n\n for (let curFactor = isEven ? 2 : 3; Math.pow(curFactor, 2) <= num; curFactor += inc) {\n if (num % curFactor !== 0) continue;\n factors.push(curFactor);\n let compliment = num / curFactor;\n if (compliment !== curFactor) factors.push(compliment);\n }\n\n return factors;\n}\n\nconst processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n const factors = getFactors(n)\n let max = 1\n for (const f of factors) {\n if (f > max && f <= k) {\n max = f\n }\n }\n console.log(n/max)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n if (k >= n) {\n print(1);\n continue;\n }\n var mm = Math.min(Math.ceil(Math.sqrt(n)), k);\n var maxx = 1;\n for (var j = 2; j <= mm; j++) {\n if (n % j === 0) {\n if (n / j <= k) {\n maxx = n / j;\n break;\n } else {\n maxx = j\n }\n \n }\n }\n print(n / maxx);\n }\n\n}\n\nmain();"}], "negative_code": [{"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n if (k >= n) {\n print(1);\n continue;\n }\n var mm = Math.min(Math.ceil(Math.sqrt(n)), k);\n var maxx = 1;\n for (var j = 2; j <= mm; j++) {\n if (n % j === 0) {\n maxx = Math.max(j, n / j);\n }\n }\n print(n / maxx);\n }\n\n}\n\nmain();\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n if (k >= n) {\n print(1);\n continue;\n }\n var mm = Math.min(Math.ceil(Math.sqrt(n)), k);\n var maxx = 1;\n for (var j = 2; j <= mm; j++) {\n if (n % j === 0) {\n maxx = j;\n }\n }\n print(n / maxx);\n }\n\n}\n\nmain();\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n if (k >= n) {\n print(1);\n continue;\n }\n var mm = Math.min(Math.ceil(Math.sqrt(n)), k);\n var maxx = 1;\n for (var j = 2; j <= mm; j++) {\n if (n % j === 0) {\n maxx = n / j;\n break;\n }\n }\n print(n / maxx);\n }\n}\nmain()"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n if (k >= n) {\n print(1);\n continue;\n }\n var mm = Math.min(Math.ceil(Math.sqrt(n)), k);\n var maxx = 1;\n for (var j = 2; j <= mm; j++) {\n if (n % j === 0) {\n maxx = Math.max(j, n / j, maxx);\n }\n }\n print(n / maxx);\n }\n\n}\n\nmain();"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readNumArray();\n var n = nk[0];\n var k = nk[1];\n print(n % k === 0 ? n / k : Math.ceil(n / k));\n }\n}\n\n main();\n"}], "src_uid": "f00eb0452f5933103f1f77ef06473c6a"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction inp() {\n return inputString[currentLine++];\n}\n\nfunction out(str) {\n console.log(str);\n}\nfunction iin() {\n return parseInt(inp())\n}\nfunction lin() {\n var array = inp().split(\" \");\n var result = [];\n for (var i = 0; i < array.length; i++) {\n result.push(parseInt(array[i]));\n }\n return result;\n}\nfunction main() {\n let n, k, s, i, j;\n let i1 = lin();\n n = i1[0];\n k = i1[1];\n s = i1[2];\n if (s < k || s > (n - 1) * k) {\n out('NO')\n }\n else {\n out('YES')\n let ans = [];\n let x, y;\n x = parseInt(s / k);\n y = s % k;\n let l, r;\n l = 1\n r = x + 2\n for (i = 0; i < y; i++) {\n if (i % 2 == 0) {\n ans.push(r)\n }\n else {\n ans.push(l)\n }\n }\n if (i % 2 == 1) {\n l += 1\n }\nelse{\n r -= 1}\n for (i = y; i < k; i++) {\n if (i % 2 == 0) {\n ans.push(r)\n }\n else {\n ans.push(l)\n }\n }\n let ans1 = '';\n for (i = 0; i < k; i++) {\n ans1 += ans[i] + ' '\n }\n out(ans1)\n\n }\n}", "positive_code": [{"source_code": "function main(){\n var a = readline().split(' ');\n var n = +a[0];\n var k = +a[1];\n var s = +a[2];\n \n if(((n-1)*k < s) || s < k){\n print('NO');\n return;\n }\n\n var res = [];\n var pos = 1;\n var ss = 0;\n var sd = parseInt(s/k);\n var sf = s%k;\n var w = true;\n while(res.length != k){\n var y = sd;\n if(sf){\n y++;\n sf--;\n }\n pos = w ? pos + y : pos - y;\n w = !w;\n res.push(pos);\n }\n print('YES\\n');\n res.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();"}, {"source_code": "function main() {\n [n,k,s] = readInts()\n res = []\n odd = 1\n while (k>0 && s >= k + n-1){\n k--\n s-=n-1\n res.push(odd++%2? n:1)\n }\n //print(s,k, res)\n if ((k==1 && s>n-1)|| (k==0 && s>0) || s0){\n index += (s-k+1)*increment\n if (index==1 || index==n) increment *= -1\n res.push(index)\n k--\n }\n for (i=k; i>0; i--){\n index += increment\n if (index==1 || index==n) increment *= -1\n s -= 1\n res.push(index)\n }\n print(\"YES\")\n print(res.join(' '))\n\n\n}\n\nconst TESTCASES = false\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}], "negative_code": [{"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var k = a[1];\n var s = a[2];\n \n if((n-1)*k < s){\n print('NO');\n return;\n }\n\n var res = [];\n var pos = 1;\n var ss = 0;\n var sd = parseInt(s/k);\n var sf = s%k;\n var w = true;\n while(res.length != k){\n var y = sd;\n if(sf){\n y++;\n sf--;\n }\n pos = w ? pos + y : pos - y;\n w = !w;\n res.push(pos);\n }\n print('YES\\n');\n res.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var k = a[1];\n var s = a[2];\n \n if((n-1)*k < s){\n print('NO');\n return;\n }\n\n var res = [];\n var maxStrep = n -1;\n var pos = 1;\n var ss = 0;\n var sd = parseInt(s/k);\n var sf = s%k;\n var w = true;\n while(res.length != k){\n var y = sd;\n if(sf){\n y++;\n sf--;\n }\n pos = w ? pos + y : pos - y;\n w = !w;\n res.push(pos);\n }\n print('YES\\n');\n res.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var k = a[1];\n var s = a[2];\n \n if(((n-1)*k < s) || s < k){\n print('NO');\n return;\n }\n\n var res = [];\n var pos = 1;\n var ss = 0;\n var sd = parseInt(s/k);\n var sf = s%k;\n var w = true;\n while(res.length != k){\n var y = sd;\n if(sf){\n y++;\n sf--;\n }\n pos = w ? pos + y : pos - y;\n w = !w;\n res.push(pos);\n }\n print('YES\\n');\n res.forEach(function(v){\n print(v + ' ');\n })\n}\n\nmain();"}, {"source_code": "function main() {\n [n,k,s] = readInts()\n res = []\n odd = 1\n while (k>0 && s >= k + n-1){\n k--\n s-=n-1\n res.push(odd++%2? n:1)\n }\n //print(s,k, res)\n if ((k==1 && s>n-1)|| (k==0 && s>0) || s0){\n index += (s-k+1)*increment\n res.push(index)\n k--\n }\n for (i=k; i>0; i--){\n index += increment\n if (index==1 || index==n) increment *= -1\n s -= 1\n res.push(index)\n }\n print(\"YES\")\n print(res.join(' '))\n\n\n}\n\nconst TESTCASES = false\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}, {"source_code": "function main() {\n [n,k,s] = readInts()\n res = []\n odd = 1\n while (k>0 && s >= k + n-1){\n k--\n s-=n-1\n res.push(odd++%2? n:1)\n }\n //print(s,k, res)\n if ((k==1 && s>n-1)|| (k==0 && s>0) || s0){\n index += (s-k+1)*increment\n res.push(index)\n k--\n }\n for (i=k; i>0; i--){\n index += increment\n if (index==1 || index==n) increment *= -1\n s -= 1\n res.push(index)\n }\n print(\"YES\")\n print(res.join(' '))\n\n\n}\n\nconst TESTCASES = false\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}, {"source_code": "function main() {\n [n,k,s] = readInts()\n res = []\n odd = 1\n while (k>0 && s >= k + n-1){\n k--\n s-=n-1\n res.push(odd++%2? n:1)\n }\n //print(s,k, res)\n if ((k==1 && s>n-1)|| (k==0 && s>0)){\n print(\"NO\")\n return\n }\n for (i=1; i<=s/n; i++){\n res.push(i%2==0? 1: n)\n }\n odd = res.length%2\n index = odd? n: 1\n increment = odd? -1: 1\n //print(increment, odd, index)\n if (k>0){\n index += (s-k+1)*increment\n res.push(index)\n k--\n }\n for (i=k; i>0; i--){\n index += increment\n if (index==1 || index==n) increment *= -1\n s -= 1\n res.push(index)\n }\n print(\"YES\")\n print(res.join(' '))\n\n\n}\n\nconst TESTCASES = false\n/* NodeJS Footer by @satyamcse and @shivam1420*/\nvar readline = require('readline');\nprocess.stdin.setEncoding('utf-8');\nvar rl = readline.createInterface({input: process.stdin, output: process.stdout});\nvar inp = \"\";\nrl.on('line' , v => inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction inp() {\n return inputString[currentLine++];\n}\n\nfunction out(str) {\n console.log(str);\n}\nfunction iin() {\n return parseInt(inp())\n}\nfunction lin() {\n var array = inp().split(\" \");\n var result = [];\n for (var i = 0; i < array.length; i++) {\n result.push(parseInt(array[i]));\n }\n return result;\n}\nfunction main() {\n let n, k, s, i, j;\n let i1 = lin();\n n = i1[0];\n k = i1[1];\n s = i1[2];\n if (s < k || s > (n - 1) * k) {\n out('NO')\n }\n else {\n out('YES')\n let ans = [];\n let x, y;\n x = parseInt(s / k);\n y = s % k;\n let l, r;\n l = 1\n r = x + 2\n for (i = 0; i < y; i++) {\n if (i % 2 == 0) {\n ans.push(r)\n }\n else {\n ans.push(l)\n }\n }\n if (i % 2 == 1) {\n l += 1\n }\n r -= 1\n for (i = y; i < k; i++) {\n if (i % 2 == 0) {\n ans.push(r)\n }\n else {\n ans.push(l)\n }\n }\n let ans1 = '';\n for (i = 0; i < k; i++) {\n ans1 += ans[i] + ' '\n }\n out(ans1)\n\n }\n}"}], "src_uid": "2cc44c5a084688025c16b0394c98b2f6"} {"source_code": "var tmp = readline().split(' ');\nvar n = tmp[0];\nvar k = tmp[1];\n\nvar arr = readline().split(' ');\nvar arr2 = arr.slice();\n\narr2.sort( function(x, y ) {\n return x - y; // incresing\n});\nvar mx = 0, cnt = 1;\n\nvar mp = [];\nvar mp2 = [];\nvar mp3 = [];\nvar ans = [];\n\nmp[arr2[0]] = 1;\nmp2[arr2[0]] = [];\n\nfor( var i=1; i k ) {\n print(\"NO\");\n} else {\n print(\"YES\");\n \n \n arr.forEach( i => {\n \n ans.push( mp[i] );\n mp3[ mp[i] ]++;\n mp[i]++;\n \n });\n \n var ind = 0;\n \n for( var i=1; i<=k; i++ ) {\n if( !mp3[i] ) {\n //write( i + ' ' + mp3[i] + '\\n');\n for( var j=ind; j 1 ) {\n mp3[ ans[j] ]--;\n ans[j] = i;\n break;\n }\n \n }\n }\n }\n ans.forEach( i => {\n write( i + ' ');\n });\n}\n\n\n", "positive_code": [{"source_code": "function calc(n, k, a) {\n if (k > n) {\n print(\"NO\");\n return;\n }\n \n var dict = {};\n a.map(elem => {\n if (dict[elem]) {\n dict[elem]++;\n } else {\n dict[elem] = 1;\n }\n });\n \n // count of same elem > colors\n if (Math.max(...Object.keys(dict).map(key => dict[key])) > k) {\n print(\"NO\");\n return;\n }\n \n var res = a\n .map((elem, index) => {\n return {\n val: elem,\n index: index\n }\n })\n .sort((a, b) => a.val - b.val)\n .map((elem, i) => {\n return {\n val: elem.val,\n index: elem.index,\n color: i % k + 1\n \n }\n })\n .sort((a, b) => a.index - b.index)\n .map(elem => elem.color)\n \n print(\"YES\");\n print(res.join(\" \"));\n \n}\n\nvar nk = readline().split(\" \");\nvar n = parseInt(nk[0]);\nvar k = parseInt(nk[1]);\n\nvar a = readline().split(\" \");\n\ncalc(n, k, a);"}], "negative_code": [{"source_code": "var tmp = readline().split(' ');\nvar n = tmp[0];\nvar k = tmp[1];\n\nvar arr = readline().split(' ');\nvar arr2 = arr.slice();\n\narr2.sort( function(x, y ) {\n return x - y; // incresing\n});\nvar mx = 0, cnt = 1;\nvar mp = {};\nmp[arr2[0]] = 1;\n\nfor( var i=1; i k ) {\n print(\"NO\");\n} else {\n print(\"YES\");\n \n arr.forEach( i => {\n write(mp[i] + ' ');\n mp[i]++;\n });\n}\n\n\n"}, {"source_code": "function calc(n, k, a) {\n if (k > n) {\n print(\"NO\");\n return;\n }\n \n var dict = {};\n a.map(elem => {\n if (dict[elem]) {\n dict[elem]++;\n } else {\n dict[elem] = 1;\n }\n });\n \n // count of same elem > colors\n if (Math.max(...Object.keys(dict).map(key => dict[key])) > k) {\n print(\"NO\");\n return;\n }\n \n var res = a\n .map((elem, index) => {\n return {\n val: elem,\n index: index\n }\n })\n .sort((a, b) => a.val - b.val)\n .map((elem, i) => {\n return {\n val: elem.val,\n index: elem.index,\n color: i % k + 1\n \n }\n })\n .sort((a, b) => a.index - b.index)\n .map(elem => elem.color)\n \n print(\"YES\");\n print(res.join(\" \"));\n \n}\n\nvar nk = readline().split(\" \");\nvar n = nk[0];\nvar k = nk[1];\n\nvar a = readline().split(\" \");\n\ncalc(n, k, a);"}, {"source_code": "var tmp = readline().split(' ');\nvar n = tmp[0];\nvar k = tmp[1];\n\nvar arr = readline().split(' ');\nvar arr2 = arr.slice();\n\narr2.sort( function(x, y ) {\n return x - y; // incresing\n});\nvar mx = 0, cnt = 1;\nvar mp = {};\nmp[arr2[0]] = 1;\n\nfor( var i=1; i k ) {\n print(\"NO\");\n} else {\n print(\"YES\");\n \n arr.forEach( i => {\n write(mp[i] + ' ');\n mp[i]++;\n });\n}\n\n\n"}], "src_uid": "3d4df21eebf32ce15841179bb85e6f2f"} {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split('').map(Number);\n var l = lines[i].split('').map(Number);\n for(j = 0; j < e; j++){\n k[j]++;\n l[j] = 1;\n }\n for(j = 1; j < e; j++){\n if(k[j] == k[j - 1]){\n k[j]--;\n l[j]--;\n }\n }\n var ans = '';\n for(j = 0; j < l.length; j++){\n ans += l[j];\n }\n console.log(ans);\n }\n\t}\n});\n\n", "positive_code": [{"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(iter; iter > 0; iter--){\r\n let n = parseInt(readline());\r\n let b = readline();\r\n let c = String(+b[0] + 1);\r\n let a = \"1\";\r\n\r\n for(let i = 1; i < n; i++){\r\n if(+(b[i]) + 1 != c[i - 1]){\r\n a += 1;\r\n c += (+b[i] + 1);\r\n } else {\r\n a += 0;\r\n c += (+b[i] + 0);\r\n }\r\n }\r\n print(a);\r\n}"}, {"source_code": "let t = 0, input = []\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n}).on('line', line => {\r\n if (t == 0)\r\n t = +line\r\n else {\r\n input.push(line)\r\n if (input.length == 2 * t)\r\n Main()\r\n }\r\n})\r\n\r\nfunction Main() {\r\n const b_arr = input.filter((x, i) => i % 2)\r\n b_arr.forEach(s => {\r\n const b = s.split('')\r\n let last = 0\r\n const a = b.map(x => {\r\n if (last == 0) {\r\n last = 1 + +x\r\n return 1\r\n }\r\n else if (last == 1) {\r\n if (x == '1') {\r\n last = 2\r\n return 1\r\n }\r\n else {\r\n last = 0\r\n return 0\r\n }\r\n }\r\n else if (last == 2) {\r\n if (x == '1') {\r\n last = 1\r\n return 0\r\n }\r\n else {\r\n last = 1\r\n return 1\r\n }\r\n }\r\n })\r\n console.log(a.join(''))\r\n })\r\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst str = readLine();\n\t\tlet lastVal = null;\n\t\tlet result = '';\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tconst char = str[i];\n\t\t\tif (char === '1') {\n\t\t\t\tif (!lastVal) {\n\t\t\t\t\tresult += '1';\n\t\t\t\t\tlastVal = '2';\n\t\t\t\t} else {\n\t\t\t\t\tif (lastVal === '2') {\n\t\t\t\t\t\tresult += '0';\n\t\t\t\t\t\tlastVal = '1';\n\t\t\t\t\t} else if (lastVal === '1') {\n\t\t\t\t\t\tresult += '1';\n\t\t\t\t\t\tlastVal = '2';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += '1';\n\t\t\t\t\t\tlastVal = '2';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!lastVal) {\n\t\t\t\t\tresult += '1';\n\t\t\t\t\tlastVal = '1';\n\t\t\t\t} else {\n\t\t\t\t\tif (lastVal === '2') {\n\t\t\t\t\t\tresult += '1';\n\t\t\t\t\t\tlastVal = '1';\n\t\t\t\t\t} else if (lastVal === '1') {\n\t\t\t\t\t\tresult += '0';\n\t\t\t\t\t\tlastVal = '0';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += '1';\n\t\t\t\t\t\tlastVal = '1';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconsole.log(result);\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var b = readline().split('').map(x=>Number(x));\r\n var ans = [1]\r\n b.map((x, i) => {\r\n if(i===0) return\r\n if(ans[i-1] +b[i-1] === 2 && x===0) ans.push(1)\r\n if(ans[i-1] +b[i-1] === 2 && x===1) ans.push(0)\r\n if(ans[i-1] +b[i-1] === 1 && x===1) ans.push(1)\r\n if(ans[i-1] +b[i-1] === 1 && x===0) ans.push(0)\r\n if(ans[i-1] +b[i-1] === 0 && x===1) ans.push(1)\r\n if(ans[i-1] +b[i-1] === 0 && x===0) ans.push(1)\r\n })\r\n // console.log(b)\r\n console.log(ans.join(''))\r\n\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar b = next();\r\n\t\tvar a = new Array(N);\r\n\t\tvar c = new Array(N);\r\n\t\tc[0] = (b[0] == \"1\") ? \"2\" : \"1\";\r\n\t\tfor(var j = 1; j < N; j++){\r\n\t\t\tif(b[j] == \"1\"){\r\n\t\t\t\tif(c[j - 1] == \"2\"){\r\n\t\t\t\t\tc[j] = \"1\";\r\n\t\t\t\t}else{\r\n\t\t\t\t\tc[j] = \"2\";\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(c[j - 1] == \"1\"){\r\n\t\t\t\t\tc[j] = \"0\";\r\n\t\t\t\t}else{\r\n\t\t\t\t\tc[j] = \"1\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t//myerr(myconv(c, 0));\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\ta[j] = myconv(c[j], 1) - myconv(b[j], 1);\r\n\t\t}\r\n\t\tmyout(myconv(a, 0));\r\n\t}\r\n}\r\n"}, {"source_code": "function solve(b){\r\n var l = 1, r=0;\r\n var ans = [1];\r\n \r\n while(l (x));\r\n write(solve(b)+'\\n');\r\n}"}], "negative_code": [], "src_uid": "e27620d3a43ab42edf930b37ce214c9e"} {"source_code": "var x= parseInt(readline());\n\n\nwhile(x--){\n var odds=0, evens=0;\n var a = parseInt(readline());\n var b= readline().split(' ').map(each => parseInt(each));\n b.forEach((e,index) => {\n if(e % 2===0){\n if(index %2!==0)\n evens++;\n }else{\n if(index % 2 ===0){\n odds++;\n }\n }\n });\n\n if(evens === odds){\n print(evens);\n }else{\n print(\"-1\");\n }\n}\n\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n while(t--) {\n let expectedOdd = 0;\n let expectedEven = 1;\n let n = parseInt(readLine());\n let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\n if(n%2!==0) {\n let odd = (n-1)/2;\n let even = n - odd;\n expectedOdd = odd;\n expectedEven = even;\n } else {\n let odd = (n)/2;\n let even = n - odd;\n expectedEven = even;\n expectedOdd = odd;\n }\n let countOdd = 0;\n let countEven = 0;\n for(let i = 0; i < arr.length; i++) {\n if (arr[i]%2 === 0) {\n countEven++;\n } else {\n countOdd++;\n }\n }\n if(countEven !== expectedEven || countOdd !== expectedOdd) {\n console.log(\"-1\");\n } else {\n let notInPosition = 0;\n for(let i =0; i {\n if (chunk.trim() == 'end') process.stdin.emit('end');\n else input += chunk;\n});\n\n\nprocess.stdin.on('end', () => {\n input = input.trim().split(/\\s+/);\n let testCases = parseInt(input[0]);\n let offset = 1;\n for (let i = 0; i < testCases; i++) {\n let len = parseInt(input[offset]);\n solve(input.slice(offset + 1, offset + 1 + len), len);\n offset += 1 + len;\n }\n\n process.exit(0);\n});"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let _ = +readLine();\n const nums = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n console.log(solve(nums));\n }\n\n function solve(nums) {\n if (nums.length === 1 && nums[0] % 2 === 1) return -1;\n let evenRequirement =\n nums.length % 2 === 0 ? nums.length / 2 : Math.floor(nums.length / 2) + 1;\n let count = 0;\n let evenCount = 0;\n for (let i = 0; i < nums.length; i++) {\n let num = nums[i];\n if (num % 2 === 0) evenCount++;\n if (i % 2 === 0 && num % 2 !== 0) count++;\n else if (i % 2 !== 0 && num % 2 === 0) count++;\n }\n if (count % 2 === 0 && evenCount === evenRequirement) return count / 2;\n return -1;\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar count = 0;\n\t\tvar odd = 0;\n\t\tvar even = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(list[j] % 2 == 0){\n\t\t\t\teven++;\n\t\t\t}else{\n\t\t\t\todd++;\n\t\t\t}\n\t\t\tif(list[j] % 2 != j % 2){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tif(odd == Math.floor(N / 2) && even == Math.ceil(N / 2)){\n\t\t\toutput[i] = count / 2;\n\t\t}else{\n\t\t\toutput[i] = -1;\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n const n = data[i] * 1;\n const arr = data[i + 1].split(' ');\n let obj = { '1': 0, '0': 0 };\n for (let j = 0; j < n; j += 1) {\n const mod = arr[j] % 2;\n const modI = j % 2;\n if (mod !== modI) obj[mod] = obj[mod] + 1;\n }\n console.log(obj[1] === obj[0] ? obj[1] : -1);\n i += 2;\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet input = '';\nprocess.stdin.on('data', (line) => {\n input += line;\n});\n\nconst reducer = (accumulator, value, index) => {\n accumulator[index % 2] += (value % 2 !== index % 2);\n return accumulator;\n}\n\nprocess.stdin.on('end', () => {\n const lines = input.split('\\n');\n let tests = parseInt(lines.shift(), 10);\n while(tests--) {\n const n = parseInt(lines.shift(), 10);\n const arr = lines.shift().split(' ');\n const [ evenMismatch, oddMismatch ] = arr.reduce(reducer, [ 0, 0 ]);\n console.log(evenMismatch === oddMismatch ? evenMismatch : -1);\n }\n});\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n for(let i = 0; i < n; i++) {\n let arr = lines[2 + i * 2].split(' ')\n console.log(solution(arr))\n }\n}\n\nfunction solution(arr) {\n let N = arr.length\n let odd = even = 0\n\n for(let i = 0; i < N; i++) {\n let num = arr[i]\n if (num % 2 && i % 2 === 0) odd++\n if (num % 2 === 0 && i % 2) even++\n }\n\n if (even === odd) {\n return even\n }\n return -1\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar input = []\nrl.on('line', function(line){\n input.push(line);\n})\n\nrl.on(\"close\", ContestResponse); \n\n\nfunction ContestResponse(){\n let index = 0;\n let nbCases= +input[index++]\n for (let i = 0; i < nbCases; i++){\n index++;\n let arr = input[index++].split(' ').map((val)=>+val);\n let hmap = {p:0, i:0}\n for (let i = 0; i < arr.length; i++){\n if (i % 2 === 0 && arr[i] % 2 !== 0)\n hmap['i']++;\n else if (i % 2 !== 0 && arr[i] % 2 === 0)\n hmap['p']++;\n }\n if (hmap['i'] !== hmap['p'])\n console.log(-1 + '');\n else\n console.log(hmap['i'] + '');\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n \n for(let r = 0;r parseInt(val));\n var even = 0;\n var odd = 0;\n for (var i = 0; i < n; i++) {\n if (i % 2 == 0 && arr[i] % 2 != 0) odd++;\n if (i % 2 != 0 && arr[i] % 2 == 0) even++;\n }\n if (odd == even) print(odd);\n else print(-1);\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var n = Number(read());\n var counter = [0, 0];\n var a = read().split(' ');\n for (var i = 0; i < n; ++i) {\n var x = Number(a[i]) % 2;\n if (x !== (i % 2)) {\n counter[x]++;\n }\n };\n if (counter[0] !== counter[1]) {\n write(-1);\n } else {\n write(counter[0]);\n }\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "t = parseInt(readline());\nwhile (t--) {\n n = parseInt(readline());\n a = readline()\n .split(' ')\n .map((x) => parseInt(x));\n if (n % 2 == 0) {\n odd = n / 2;\n } else {\n odd = (n - 1) / 2;\n }\n count_odd = a.filter((x) => x % 2 == 1).length;\n if (count_odd != odd) {\n print(\"-1\");\n } else {\n count_diff = a.filter((x, i) => x % 2 != i % 2).length;\n print(count_diff / 2);\n }\n}\n"}, {"source_code": "function solve(n,arr) {\n var notEven = 0, notOdd = 0;\n for (var i=0; i {\n if (chunk.trim() == 'end') process.stdin.emit('end');\n else input += chunk;\n});\n\n\nprocess.stdin.on('end', () => {\n input = input.trim().split('\\n');\n\n for (let i = 1; i < input.length; i += 2) {\n solve(parseInt(input[i]), input[i + 1].trim().split(' '));\n }\n\n process.exit(0);\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n \n for(let r = 0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n4\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n \n for(let r = 0;r parseInt(val));\n var diff = 0;\n for (var i = 0; i < n; i++) {\n if (i % 2 != arr[i] % 2) diff++;\n }\n if (diff % 2 == 0) print(diff / 2);\n else print(-1);\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var n = Number(read());\n var counter = 0;\n var a = read().split(' ').map(function(x, i) {\n if (x % 2 !== i % 2) {\n counter++;\n }\n });\n if (counter % 2) {\n write(-1);\n } else {\n write(Math.round(counter / 2));\n }\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var n = Number(read());\n var counter = 0;\n var a = read().split(' ');\n for (var i = 0; i < n; ++i) {\n var x = a[i];\n if ((Number(x) % 2) !== (i % 2)) {\n counter++;\n }\n };\n if (counter % 2) {\n write(-1);\n } else {\n write(Math.round(counter / 2));\n }\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "src_uid": "942123e43a83d5a4cea95a6781064e28"} {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let o = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(o = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= o.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = u().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = u().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function u() {\r\n return o[i++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n o = r >> 1,\r\n i = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: c,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function c() {\r\n n.write(i.toString(e, 0, u)), (u = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - u < s && (c(), s > o) ? n.write(t) : (i.write(t, u, e), (u += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = new Array(1010),\r\n e = new Array(1010),\r\n r = new Array(1010),\r\n o = new Array(1010),\r\n i = new Array(1010)\r\n for (let c = 1; c <= 1; ++c) {\r\n const c = t.readLineAsNumber(),\r\n s = t.readIntegersOfLine(),\r\n f = u()\r\n function u() {\r\n if (c < 2) return 0\r\n e.fill(0, 0, c), r.fill(-1, 0, c)\r\n for (let t = 0; t < c; ++t) o[t] = s[t]\r\n let t = 0\r\n for (let e = c - 1; e >= 0; --e)\r\n if (1 & e) i[t++] = e\r\n else {\r\n let u = s[e]\r\n for (; t > 0; ) {\r\n const c = i[--t],\r\n f = o[c]\r\n if (u === f) {\r\n ;(r[e] = c), (r[c] = e), (n[c] = s[c]), (u = 0)\r\n break\r\n }\r\n if (u < f) {\r\n ;(o[c] -= u), t++, (r[e] = c), (u = 0)\r\n break\r\n }\r\n ;(u -= f), (r[c] = e), (n[c] = s[c])\r\n }\r\n n[e] = s[e] - u\r\n }\r\n for (let e = 0; e < t; ++e) {\r\n const t = i[e]\r\n n[t] = s[t] - o[t]\r\n }\r\n for (let t = (1 & c ? c - 2 : c - 1) - 2; t > 0; t -= 2) {\r\n if (-1 === r[t]) continue\r\n const n = r[t + 1]\r\n ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)\r\n }\r\n let u = 0\r\n for (let t = 0; t < c; t += 2) u += n[t]\r\n let f = 0\r\n for (let t = 1; t < c; t += 2) f += e[t]\r\n return u + f\r\n }\r\n t.println(f.toString())\r\n }\r\n})\r\n", "positive_code": [{"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let i = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(i = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= i.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = u().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = u().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function u() {\r\n return i[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n i = r >> 1,\r\n o = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: c,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function c() {\r\n n.write(o.toString(e, 0, u)), (u = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - u < s && (c(), s > i) ? n.write(t) : (o.write(t, u, e), (u += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = new Array(1010),\r\n e = new Array(1010),\r\n r = new Array(1010)\r\n for (let o = 1; o <= 1; ++o) {\r\n const o = t.readLineAsNumber(),\r\n u = t.readIntegersOfLine()\r\n n.fill(0, 0, o), e.fill(0, 0, o), r.fill(-1, 0, o)\r\n const c = i()\r\n function i() {\r\n const t = []\r\n let i = 0\r\n for (let e = o - 1; e >= 0; --e)\r\n if (1 & e) t[i++] = { idx: e, remain: u[e] }\r\n else {\r\n let o = u[e]\r\n for (; i > 0; ) {\r\n const { idx: c, remain: s } = t[--i]\r\n if (o === s) {\r\n ;(r[e] = c), (r[c] = e), (n[c] = u[c]), (o = 0)\r\n break\r\n }\r\n if (o < s) {\r\n ;(t[i++] = { idx: c, remain: s - o }), (r[e] = c), (o = 0)\r\n break\r\n }\r\n ;(o -= s), (r[c] = e), (n[c] = u[c])\r\n }\r\n n[e] = u[e] - o\r\n }\r\n for (let e = 0; e < i; ++e) {\r\n const { idx: r, remain: i } = t[e]\r\n n[r] = u[r] - i\r\n }\r\n for (let t = (1 & o ? o - 2 : o - 1) - 2; t > 0; t -= 2) {\r\n if (-1 === r[t]) continue\r\n const n = r[t + 1]\r\n ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)\r\n }\r\n let c = 0\r\n for (let t = 0; t < o; t += 2) c += n[t]\r\n let s = 0\r\n for (let t = 1; t < o; t += 2) s += e[t]\r\n return c + s\r\n }\r\n t.println(c.toString())\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let i = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(i = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= i.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = u().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = u().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function u() {\r\n return i[o++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n i = r >> 1,\r\n o = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: s,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function s() {\r\n t.write(o.toString(e, 0, u)), (u = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - u < c && (s(), c > i) ? t.write(n) : (o.write(n, u, e), (u += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = new Array(1010),\r\n e = new Array(1010),\r\n r = new Array(1010)\r\n for (let o = 1; o <= 1; ++o) {\r\n const o = n.readLineAsNumber(),\r\n u = n.readIntegersOfLine()\r\n t.fill(0, 0, o), e.fill(0, 0, o), r.fill(-1, 0, o)\r\n const s = i()\r\n function i() {\r\n const n = []\r\n for (let e = o - 1; e >= 0; --e)\r\n if (1 & e) n.push({ idx: e, remain: u[e] })\r\n else {\r\n let i = u[e]\r\n for (; n.length > 0; ) {\r\n const { idx: o, remain: s } = n.pop()\r\n if (i === s) {\r\n ;(r[e] = o), (r[o] = e), (t[o] = u[o]), (i = 0)\r\n break\r\n }\r\n if (i < s) {\r\n n.push({ idx: o, remain: s - i }), (r[e] = o), (i = 0)\r\n break\r\n }\r\n ;(i -= s), (r[o] = e), (t[o] = u[o])\r\n }\r\n t[e] = u[e] - i\r\n }\r\n for (const { idx: e, remain: r } of n) t[e] = u[e] - r\r\n for (let n = (1 & o ? o - 2 : o - 1) - 2; n > 0; n -= 2) {\r\n if (-1 === r[n]) continue\r\n const t = r[n + 1]\r\n ;-1 !== t && (e[n] = r[t] === n + 1 ? e[t] + 1 : 1)\r\n }\r\n let i = 0\r\n for (let n = 0; n < o; n += 2) i += t[n]\r\n let s = 0\r\n for (let n = 1; n < o; n += 2) s += e[n]\r\n return i + s\r\n }\r\n n.println(s.toString())\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let o = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(o = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= o.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = u().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = u().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function u() {\r\n return o[i++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n o = r >> 1,\r\n i = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: c,\r\n print: function (t) {\r\n s('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n s(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function c() {\r\n n.write(i.toString(e, 0, u)), (u = 0)\r\n }\r\n function s(t) {\r\n const s = Buffer.byteLength(t, e)\r\n r - u < s && (c(), s > o) ? n.write(t) : (i.write(t, u, e), (u += s))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = new Array(1010),\r\n e = new Array(1010),\r\n r = new Array(1010),\r\n o = new Array(1010),\r\n i = new Array(1010)\r\n for (let c = 1; c <= 1; ++c) {\r\n const c = t.readLineAsNumber(),\r\n s = t.readIntegersOfLine(),\r\n f = u()\r\n function u() {\r\n if (c < 2) return 0\r\n e.fill(0, 0, c), r.fill(-1, 0, c)\r\n for (let t = 0; t < c; ++t) o[t] = s[t]\r\n let t = 0\r\n for (let e = 0; e < c; ++e)\r\n if (1 & e) {\r\n let u = s[e]\r\n for (; t > 0; ) {\r\n const c = i[--t],\r\n f = o[c]\r\n if (u === f) {\r\n ;(r[e] = c), (r[c] = e), (n[c] = s[c]), (u = 0)\r\n break\r\n }\r\n if (u < f) {\r\n ;(o[c] -= u), t++, (r[e] = c), (u = 0)\r\n break\r\n }\r\n ;(u -= f), (r[c] = e), (n[c] = s[c])\r\n }\r\n n[e] = s[e] - u\r\n } else i[t++] = e\r\n for (let e = 0; e < t; ++e) {\r\n const t = i[e]\r\n n[t] = s[t] - o[t]\r\n }\r\n for (let t = (1 & c ? c - 2 : c - 1) - 2; t > 0; t -= 2) {\r\n if (-1 === r[t]) continue\r\n const n = r[t + 1]\r\n ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)\r\n }\r\n let u = 0\r\n for (let t = 0; t < c; t += 2) u += n[t]\r\n let f = 0\r\n for (let t = 1; t < c; t += 2) f += e[t]\r\n return u + f\r\n }\r\n t.println(f.toString())\r\n }\r\n})\r\n"}], "negative_code": [{"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let i = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(i = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= i.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = u().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = u().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function u() {\r\n return i[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n i = r >> 1,\r\n o = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: s,\r\n print: function (t) {\r\n c('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n c(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function s() {\r\n n.write(o.toString(e, 0, u)), (u = 0)\r\n }\r\n function c(t) {\r\n const c = Buffer.byteLength(t, e)\r\n r - u < c && (s(), c > i) ? n.write(t) : (o.write(t, u, e), (u += c))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = new Array(1010),\r\n e = []\r\n for (let i = 1; i <= 1; ++i) {\r\n const i = t.readLineAsNumber(),\r\n o = t.readIntegersOfLine(),\r\n u = r()\r\n function r() {\r\n let t = 0\r\n for (let r, u = 0; u < i; u += 2) {\r\n let s = o[u],\r\n c = o[u]\r\n for (r = u + 1; r < i; ++r)\r\n if (1 & r) {\r\n if (((c -= o[r]), c < s && (s = c <= 0 ? 0 : c), 0 === s)) break\r\n } else c += o[r]\r\n ;(n[u] = o[u] - s), (t += n[u]), (e[u] = 0 === s ? r : -1)\r\n }\r\n for (let t = 1 & i ? i - 2 : i - 1; t >= 0; t -= 2) {\r\n let e = o[t],\r\n r = o[t]\r\n for (let n = t - 1; n >= 0; --n)\r\n if (1 & n) r += o[n]\r\n else if (((r -= o[n]), r < e && (e = r <= 0 ? 0 : r), 0 === e)) break\r\n n[t] = o[t] - e\r\n }\r\n let r = BigInt(t)\r\n for (let t = 1, u = i - 1; t < u; t += 2) {\r\n if (n[t] !== o[t]) continue\r\n let u = e[t + 1],\r\n s = 0\r\n for (; -1 != u && ((s += 1), n[t] === o[t] && u + 1 !== i); )\r\n u = e[u + 1]\r\n r += BigInt(s)\r\n }\r\n return r\r\n }\r\n t.println(u.toString())\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let i = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(i = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= i.length\r\n },\r\n readLine: u,\r\n readLineAsNumber: function () {\r\n return Number(u())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = u().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = u().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function u() {\r\n return i[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n i = r >> 1,\r\n o = Buffer.alloc(r)\r\n let u = 0\r\n return {\r\n flush: s,\r\n print: function (t) {\r\n c('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n c(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function s() {\r\n n.write(o.toString(e, 0, u)), (u = 0)\r\n }\r\n function c(t) {\r\n const c = Buffer.byteLength(t, e)\r\n r - u < c && (s(), c > i) ? n.write(t) : (o.write(t, u, e), (u += c))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = new Array(1010),\r\n e = []\r\n for (let i = 1; i <= 1; ++i) {\r\n const i = t.readLineAsNumber(),\r\n o = t.readIntegersOfLine(),\r\n u = r()\r\n function r() {\r\n let t = 0\r\n for (let r, u = 0; u < i; u += 2) {\r\n let s = o[u],\r\n c = o[u]\r\n for (r = u + 1; r < i; ++r)\r\n if (1 & r) {\r\n if (((c -= o[r]), c < s && (s = c <= 0 ? 0 : c), 0 === s)) break\r\n } else c += o[r]\r\n ;(n[u] = o[u] - s), (t += n[u]), (e[u] = 0 === s ? r : -1)\r\n }\r\n for (let t = 1 & i ? i - 2 : i - 1; t >= 0; t -= 2) {\r\n let e = o[t],\r\n r = o[t]\r\n for (let n = t - 1; n >= 0; --n)\r\n if (1 & n) r += o[n]\r\n else if (((r -= o[n]), r < e && (e = r <= 0 ? 0 : r), 0 === e)) break\r\n n[t] = o[t] - e\r\n }\r\n let r = BigInt(t)\r\n for (let t = 1, u = i - 1; t < u; t += 2) {\r\n if (n[t] !== o[t]) continue\r\n let u = e[t + 1],\r\n s = 0\r\n for (; -1 != u && ((s += 1), u + 1 !== i); ) u = e[u + 1]\r\n r += BigInt(s)\r\n }\r\n return r\r\n }\r\n t.println(u.toString())\r\n }\r\n})\r\n"}], "src_uid": "ca4ae2484800a98b5592ae65cd45b67f"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n const map = {\n 'a': 0,\n 'b': 1,\n 'c': 2\n }\n const chars = ['a', 'b', 'c']\n\n for(let j = 0; j < t; j++) {\n const string = arr[j] + 'a'\n const len = string.length - 1\n let s = new Array(len)\n\n let flag = false\n if(len == 1 && string[0] == '?') {\n s[0] = 'a'\n // console.log(s)\n }\n else if(len == 1) {\n s[0] = string[0]\n }\n else if(string[0] == string[0 + 1] && string[0] != '?') {\n flag = true\n }\n else if(string[0] == '?' && string[1] != '?') {\n s[0] = chars[(map[string[1]] + 1) % 3]\n }\n else if(string[0] == '?' && string[1] == '?') {\n s[0] = 'a'\n }\n else {\n s[0] = string[0]\n }\n for(let i = 1; i < len - 1 && !flag; i++) {\n // console.log(i, s)\n if(string[i] == string[i + 1] && string[i] != '?') {\n flag = true\n break\n }\n\n if(string[i] != '?') s[i] = string[i]\n else if(string[i] == '?' && string[i + 1] != '?') {\n if(s[i - 1] == string[i + 1]) {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n else {\n s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]\n }\n }\n else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {\n if(s[i - 1] == string[i + 2]) {\n let v = map[s[i - 1]]\n s[i] = chars[(v + 1) % 3]\n }\n else {\n s[i] = string[i + 2]\n }\n }\n else {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n }\n\n if(!flag && len > 1) {\n let last = len - 1\n if(string[last] == s[last - 1] && string[last] != '?') {\n flag = true\n }\n else if(string[last] == '?') {\n s[last] = chars[(map[s[last - 1]] + 1) % 3]\n }\n else {\n s[last] = string[last]\n }\n }\n\n // console.log(s)\n if(flag) console.log(-1)\n else console.log(s.join(''))\n }\n})", "positive_code": [{"source_code": "var print = this.print || require('lol-io').print;\nvar write = this.write || require('lol-io').write;\nvar readline = this.readline || require('lol-io').readline;\n\nvar t = Number(readline()), string, array, result = true;\n\nfunction test (a) {\n result = true;\n\n for (k = 0; k < a.length - 1; k++) {\n if (a[k] === a[k + 1]) {\n result = false;\n }\n }\n\n return result;\n}\n\nfor (i = 0; i < t; i++) {\n string = readline();\n array = string.split('');\n\n for (j = 0; j < array.length; j++) {\n\n if (array[j] === '?') {\n if (array[j - 1] != 'a' && array[j + 1] != 'a') {\n array[j] = 'a';\n } else if (array[j - 1] != 'b' && array[j + 1] != 'b') {\n array[j] = 'b';\n } else {\n array[j] = 'c';\n }\n }\n }\n\n string = array.join('');\n\n\n\n if (test(array)) {\n print(string);\n } else {\n print(-1);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function(input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function() {\n processData(_input);\n});\n\nfunction processData(input) {\n let lines = input.split(\"\\n\");\n\n for (let i = 1; i < lines.length; i++) {\n let word = lines[i].split(\"\");\n for (let j = 0; j < word.length; j++) {\n let possibilities = [\"a\", \"b\", \"c\"];\n if (word[j] === \"?\") {\n let prevChar = word[j - 1];\n let nextChar = word[j + 1];\n if (prevChar === \"a\") {\n let index = possibilities.indexOf(\"a\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n } else if (prevChar === \"b\") {\n let index = possibilities.indexOf(\"b\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n } else if (prevChar === \"c\") {\n let index = possibilities.indexOf(\"c\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n }\n if (nextChar === \"a\") {\n let index = possibilities.indexOf(\"a\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n } else if (nextChar === \"b\") {\n let index = possibilities.indexOf(\"b\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n } else if (nextChar === \"c\") {\n let index = possibilities.indexOf(\"c\");\n if (index != -1) {\n possibilities.splice(index, 1);\n }\n }\n\n if (possibilities[0] !== undefined) {\n word[j] = possibilities[0];\n }\n }\n }\n let ans = true;\n for (let j = 0; j < word.length - 1; j++) {\n // console.log(word[i], word[i - 1], word[i], word[i + 1]);\n if (word[j] === word[j - 1] || word[j] === word[j + 1]) {\n ans = false;\n break;\n }\n }\n if (ans) {\n console.log(word.join(\"\"));\n } else console.log(-1);\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n const map = {\n 'a': 0,\n 'b': 1,\n 'c': 2\n }\n const chars = ['a', 'b', 'c']\n\n for(let j = 0; j < t; j++) {\n const string = arr[j]\n const len = string.length\n let s = new Array(len)\n\n let flag = false\n if(len == 1 && string[0] == '?') {\n s[0] = 'a'\n // console.log(s)\n }\n else if(len == 1) {\n s[0] = string[0]\n }\n else if(string[0] == string[0 + 1] && string[0] != '?') {\n flag = true\n }\n else if(string[0] == '?') {\n s[0] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[0] = string[0]\n }\n for(let i = 1; i < len - 1 && !flag; i++) {\n if(string[i] == string[i + 1] && string[i] != '?') {\n flag = true\n break\n }\n\n if(string[i] != '?') s[i] = string[i]\n else if(string[i] == '?' && string[i + 1] != '?') {\n if(s[i - 1] == string[i + 1]) {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n else {\n s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]\n }\n }\n else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {\n if(string[i - 1] == string[i + 2]) {\n let v = map[s[i - 1]]\n s[i] = chars[(v + 1) % 3]\n }\n else {\n s[i] = string[i + 2]\n }\n }\n else {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n }\n\n if(!flag && len > 1) {\n let last = len - 1\n if(string[last] == string[last - 1] && string[last] != '?') {\n flag = true\n }\n else if(string[last] == '?') {\n s[last] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[last] = string[last]\n }\n }\n\n // console.log(s)\n if(flag) console.log(-1)\n else console.log(s.join(''))\n }\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n const map = {\n 'a': 0,\n 'b': 1,\n 'c': 2\n }\n const chars = ['a', 'b', 'c']\n\n for(let j = 0; j < t; j++) {\n const string = arr[j]\n const len = string.length\n let s = new Array(len)\n\n let flag = false\n\n if(string[0] == string[0 + 1] && string[0] != '?') {\n flag = true\n }\n else if(string[0] == '?') {\n s[0] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[0] = string[0]\n }\n for(let i = 1; i < len - 1 && !flag; i++) {\n // console.log(i, string[i], s)\n if(string[i] == string[i + 1] && string[i] != '?') {\n flag = true\n break\n }\n\n if(string[i] != '?') s[i] = string[i]\n else if(string[i] == '?' && string[i + 1] != '?') {\n if(s[i - 1] == string[i + 1]) {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n else {\n s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]\n }\n }\n else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {\n if(string[i - 1] == string[i + 2]) {\n let v = map[s[i - 1]]\n s[i] = chars[(v + 1) % 3]\n }\n else {\n s[i] = string[i + 2]\n }\n }\n else {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n }\n\n if(!flag) {\n let last = len - 1\n if(string[last] == string[last - 1] && string[last] != '?') {\n flag = true\n }\n else if(string[last] == '?') {\n s[last] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[last] = string[last]\n }\n }\n\n if(flag) console.log(-1)\n else console.log(s.join(''))\n }\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n const map = {\n 'a': 0,\n 'b': 1,\n 'c': 2\n }\n const chars = ['a', 'b', 'c']\n\n for(let j = 0; j < t; j++) {\n const string = arr[j]\n const len = string.length\n let s = new Array(len)\n\n let flag = false\n if(len == 1 && string[0] != '?') {\n s[0] = 'a'\n }\n else if(len == 1) {\n s[0] = string[0]\n }\n else if(string[0] == string[0 + 1] && string[0] != '?') {\n flag = true\n }\n else if(string[0] == '?') {\n s[0] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[0] = string[0]\n }\n for(let i = 1; i < len - 1 && !flag; i++) {\n // console.log(i, string[i], s)\n if(string[i] == string[i + 1] && string[i] != '?') {\n flag = true\n break\n }\n\n if(string[i] != '?') s[i] = string[i]\n else if(string[i] == '?' && string[i + 1] != '?') {\n if(s[i - 1] == string[i + 1]) {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n else {\n s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]\n }\n }\n else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {\n if(string[i - 1] == string[i + 2]) {\n let v = map[s[i - 1]]\n s[i] = chars[(v + 1) % 3]\n }\n else {\n s[i] = string[i + 2]\n }\n }\n else {\n s[i] = chars[(map[s[i - 1]] + 1) % 3]\n }\n }\n\n if(!flag) {\n let last = len - 1\n if(string[last] == string[last - 1] && string[last] != '?') {\n flag = true\n }\n else if(string[last] == '?') {\n s[last] = chars[(map[string[1]] + 1) % 3]\n }\n else {\n s[last] = string[last]\n }\n }\n\n if(flag) console.log(-1)\n else console.log(s.join(''))\n }\n})"}], "src_uid": "98c08a3b5e5b5bb78804ff797ba24d87"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar Q = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar sum = new Array(N + 1).fill(0);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsum[i + 1] = sum[i] + list[i];\r\n\t\t}\r\n\t\tvar binary = new Array(N + 1).fill(0);\r\n\t\tfor(var i = 1; i <= N; i++){\r\n\t\t\tbinary[i] = Math.max(binary[i - 1], list[i - 1]);\r\n\t\t}\r\n\t\tbinary.push(Math.pow(10, 15));\r\n\t\tvar output = new Array(Q);\r\n\t\tfor(var i = 0; i < Q; i++){\r\n\t\t\tvar qi = nextInt();\r\n\t\t\tvar L = 0;\r\n\t\t\tvar R = binary.length;\r\n\t\t\twhile(R - L > 1){\r\n\t\t\t\tvar C = Math.floor((L + R) / 2);\r\n\t\t\t\tvar hi = binary[C];\r\n\t\t\t\tif(hi <= qi){\r\n\t\t\t\t\tL = C;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tR = C;\r\n\t\t\t\t}\r\n\t\t\t}\t\t\t\r\n\t\t\toutput[i] = sum[L];\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});\r\n let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});\r\n let b=line[3*_].split(' ').map(x=>{return parseInt(x)});\r\n let sum=new Array(n+10);\r\n for(let i=0;i0) sum[i]+=sum[i-1];\r\n }\r\n for(let i=1;ib[i]) r=mid-1;\r\n else l=mid;\r\n }\r\n if(a[l]>b[i]) ans+=0+' ';\r\n else ans+=sum[l]+' ';\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});\r\n let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});\r\n let b=line[3*_].split(' ').map(x=>{return parseInt(x)});\r\n let sum=new Array(n+10);\r\n for(let i=0;i0) sum[i]+=sum[i-1];\r\n }\r\n for(let i=1;ib[i]) r=mid-1;\r\n else l=mid;\r\n }\r\n // console.log(l);\r\n if(a[l]>b[i]) ans+=0+' ';\r\n else ans+=sum[l]+' ';\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns(),\r\n b = rns().map((num, i) => [num, i]);\r\n b.sort((a, b) => a[0] - b[0]);\r\n let max = a[0],\r\n res = new Array(q),\r\n sum = 0;\r\n for (let i = 0, j = 0; i < n && j < q; i++) {\r\n max = Math.max(max, a[i]);\r\n while (j < q && b[j][0] < max) {\r\n res[b[j][1]] = sum;\r\n j++;\r\n }\r\n sum += a[i];\r\n }\r\n for (let i = 0; i < q; i++) if (res[i] === undefined) res[i] = sum;\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n q = rn(),\r\n tr = new SegTree(n),\r\n sum = new Array(n);\r\n sum[0] = 0;\r\n tr.update(0, 0, 0);\r\n for (let i = 1; i <= n; i++) {\r\n var _sum;\r\n let num = rn();\r\n tr.update(i, i, num);\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + num;\r\n }\r\n const res = new Array(q);\r\n for (let i = 0; i < q; i++) {\r\n const k = rn();\r\n let l = 0,\r\n r = n;\r\n while (l < r) {\r\n const m = l + r + 1 >> 1;\r\n const max = tr.query(0, m);\r\n if (max <= k) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n res[i] = sum[l];\r\n }\r\n return res.join(' ');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right\r\n };\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = Math.max(left.val, right.val);\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.val = Math.max(node.val, z);\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.max(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\nfunction begin(steps, legs) {\r\n let n = steps.length;\r\n let q = legs.length;\r\n let res = new Array(q).fill(0);\r\n\r\n //print(steps);\r\n\r\n let maxSteps = new Array(n);\r\n let max = 0;\r\n for(let i = 0; i < n; i++) {\r\n if(steps[i] > max) {\r\n max = steps[i];\r\n }\r\n maxSteps[i] = max;\r\n }\r\n //print(maxSteps);\r\n\r\n let preSum = new Array(n);\r\n preSum[0] = steps[0];\r\n for(let i = 1; i < n; i++) {\r\n preSum[i] = steps[i] + preSum[i-1];\r\n }\r\n //print(preSum);\r\n\r\n let find = (num, nums) => {\r\n let left = 0, right = nums.length - 1;\r\n let target = num;\r\n while(left <= right) {\r\n let mid = left + Math.floor((right - left)/2);\r\n if(target < nums[mid]) {\r\n right = mid - 1;\r\n } else if(target >= nums[mid]) {\r\n left = mid + 1;\r\n }\r\n }\r\n return left;\r\n }\r\n\r\n for(let i = 0; i < q; i++) {\r\n let pos = find(legs[i], maxSteps);\r\n if(pos > 0) {\r\n res[i] = preSum[pos - 1];\r\n }\r\n //console.log(pos);\r\n }\r\n print(res.join(' '));\r\n \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n let steps = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n let legs = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(steps, legs);\r\n }\r\n}"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/E\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nfunction Bisect() {\r\n return { insort_right, insort_left, bisect_left, bisect_right }\r\n function insort_right(a, x, lo = 0, hi = null) {\r\n lo = bisect_right(a, x, lo, hi);\r\n a.splice(lo, 0, x);\r\n }\r\n function bisect_right(a, x, lo = 0, hi = null) { // > upper_bound\r\n if (lo < 0) throw new Error('lo must be non-negative');\r\n if (hi == null) hi = a.length;\r\n while (lo < hi) {\r\n let mid = parseInt((lo + hi) / 2);\r\n a[mid] > x ? hi = mid : lo = mid + 1;\r\n }\r\n return lo;\r\n }\r\n function insort_left(a, x, lo = 0, hi = null) {\r\n lo = bisect_left(a, x, lo, hi);\r\n a.splice(lo, 0, x);\r\n }\r\n function bisect_left(a, x, lo = 0, hi = null) { // >= lower_bound\r\n if (lo < 0) throw new Error('lo must be non-negative');\r\n if (hi == null) hi = a.length;\r\n while (lo < hi) {\r\n let mid = parseInt((lo + hi) / 2);\r\n a[mid] < x ? lo = mid + 1 : hi = mid;\r\n }\r\n return lo;\r\n }\r\n}\r\n\r\nconst solve = (n, q, a, k) => {\r\n // pr(n, q, a, k)\r\n let s = [], sum = 0, bi = new Bisect(), res = [];\r\n for (const x of a) {\r\n sum += x;\r\n s.push(sum);\r\n }\r\n let min = [a[0]], cur = a[0];\r\n for (let i = 1; i < n; i++) {\r\n cur = Math.max(cur, a[i]);\r\n min.push(cur);\r\n }\r\n // pr(min);\r\n for (let h of k) {\r\n let i = bi.bisect_right(min, h) - 1;\r\n // pr('h', h, 'i', i);\r\n let v = s[i] || 0;\r\n res.push(v);\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let t = ni();\r\n while (t--) {\r\n let [n, q] = nai(), a = nai(), k = nai();\r\n solve(n, q, a, k);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const max = Array(n)\n const hs = Array(n)\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n max[i] = x\n hs[i] = x\n if (i) {\n max[i] = Math.max(max[i], max[i - 1])\n hs[i] += hs[i - 1]\n }\n }\n // console.log(max, hs)\n return qs.map(k => {\n const i = binarySearch(0, n - 1, x => max[x] <= k)\n return i < 0 ? 0 : hs[i]\n }).join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "negative_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});\r\n let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});\r\n let b=line[3*_].split(' ').map(x=>{return parseInt(x)});\r\n let sum=new Array(n+10);\r\n for(let i=0;i0) sum[i]+=sum[i-1];\r\n }\r\n for(let i=1;ib[i]) r=mid-1;\r\n else l=mid;\r\n }\r\n if(a[l]>b[l]) ans+=0+' ';\r\n else ans+=sum[l]+' ';\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns(),\r\n b = rns().map((num, i) => [num, i]);\r\n b.sort((a, b) => a[0] - b[0]);\r\n let max = a[0],\r\n res = new Array(q),\r\n sum = 0;\r\n for (let i = 0, j = 0; i < n && j < q; i++) {\r\n max = Math.max(max, a[i]);\r\n while (j < q && b[j][0] < max) {\r\n res[b[j][1]] = sum;\r\n j++;\r\n }\r\n sum += a[i];\r\n }\r\n for (let i = 0; i < q; i++) if (res[i] === undefined) res[i] = sum;\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\nfunction begin(steps, legs) {\r\n let n = steps.length;\r\n let q = legs.length;\r\n let res = new Array(q).fill(0);\r\n\r\n //print(steps);\r\n\r\n let maxSteps = new Array(n);\r\n let max = 0;\r\n for(let i = 0; i < n; i++) {\r\n if(steps[i] > max) {\r\n max = steps[i];\r\n }\r\n maxSteps[i] = max;\r\n }\r\n //print(maxSteps);\r\n\r\n let preSum = new Array(n);\r\n preSum[0] = steps[0];\r\n for(let i = 1; i < n; i++) {\r\n preSum[i] = steps[i] + preSum[i-1];\r\n }\r\n //print(preSum);\r\n\r\n let find = (num, nums) => {\r\n let left = 0, right = nums.length - 1;\r\n let target = num;\r\n while(left <= right) {\r\n let mid = left + Math.floor((right - left)/2);\r\n if(target < nums[mid]) {\r\n right = mid - 1;\r\n } else if(target >= nums[mid]) {\r\n left = mid + 1;\r\n }\r\n }\r\n return left;\r\n }\r\n\r\n for(let i = 0; i < q; i++) {\r\n let pos = find(legs[i], maxSteps);\r\n if(pos > 0) {\r\n res[i] = preSum[pos - 1];\r\n }\r\n //console.log(pos);\r\n }\r\n print(res);\r\n \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n let steps = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n let legs = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(steps, legs);\r\n }\r\n}"}], "src_uid": "d5f7228d8d674b8233937702ca044cb0"} {"source_code": "var t = Number(readline());\nfor (var i = 0; i < t; ++i)\n{\n var param = readline().split(' ').map((val) => Number(val));\n var n = param[0];\n var mice = readline().split(' ').map((val) => Number(val));\n mice.sort((a, b) => a - b).reverse();\n\n var saved = 0;\n var cat = 0;\n for (var val of mice)\n {\n if (val > cat)\n {\n saved++;\n var distance = n - val;\n cat += distance;\n }\n }\n print(saved);\n}", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n d.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n var cat = 0\r\n var count = 0\r\n for(let i = 0; i < d.length;i++){\r\n if(cat >= d[i]) break\r\n cat += b[0] - d[i]\r\n count++\r\n }\r\n print(count)\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = readline().split(' ').map(Number)\r\n var d = readline().split(' ').map(Number)\r\n d.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n var cat = 0\r\n var count = 0\r\n for(let i = 0; i < d.length;i++){\r\n if(cat >= d[i]) break\r\n cat += b[0] - d[i]\r\n count++\r\n }\r\n print(count)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction ok(x,n,k,a)\r\n{\r\n let sum=0\r\n for(let i=x;ia-b)\r\n let ans=0\r\n let L=0,R=k-1\r\n while(L<=R)\r\n {\r\n let Mid=Math.floor((L+R)/2)\r\n if(ok(Mid,n,k,a))\r\n {\r\n ans=k-Mid\r\n R=Mid-1\r\n }\r\n else\r\n L=Mid+1\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(K);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar output = 0;\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < K; i++){\r\n\t\t\tvar xi = list[i];\r\n\t\t\tif(sum < xi){\r\n\t\t\t\toutput++;\r\n\t\t\t\tsum += N - xi;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n arr.sort((a, b) => a - b)\n // console.log('arr', arr)\n const need = []\n for (let i = k - 1; i >= 0; i--) {\n need[i] = i !== k - 1 ? need[i + 1] + n - arr[i] : n - arr[i]\n // need[i] = i ? need[i - 1] + n - arr[i] : n - arr[i]\n }\n // console.log(need)\n const idx = binarySearch(0, k - 1, x => need[x] >= n)\n return k - (idx + 1)\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": " var t = parseInt(readline());\r\n function solve() {\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n\r\n var a = inp[0];\r\n var b = inp[1];\r\n\r\n var mice = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n .sort((a, b) => {\r\n if (a > b) {\r\n return -1;\r\n } else if (a < b) {\r\n return 1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n var cat = 0;\r\n var save = 0;\r\n\r\n for (var i = 0; i < b; i++) {\r\n if (cat < mice[i]) {\r\n save++;\r\n cat += a - mice[i];\r\n } else {\r\n break;\r\n }\r\n }\r\n return save;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b)\r\n{\r\n if(b==0)\r\n return a;\r\n return gcd(b,a%b);\r\n} \r\nfunction ok(x,n,k,a)\r\n{\r\n let sum=0\r\n for(let i=x;ia-b)\r\n let ans=0\r\n let L=0,R=k-1\r\n // ok(7,12,11,a);\r\n // break;\r\n while(L<=R)\r\n {\r\n let Mid=Math.floor((L+R)/2)\r\n if(ok(Mid,n,k,a))\r\n {\r\n ans=k-Mid\r\n R=Mid-1\r\n }\r\n else\r\n L=Mid+1\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\r\n\t\tx.sort((a, b) => b - a);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0, sm = 0; i < x.length; i++) {\r\n\t\t\tsm += n-x[i];\r\n\t\t\tif (sm >= n) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tans++;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var x = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0], x = k[1];\n }else{\n k.sort(function(a, b){return b - a});\n var a = 0;\n var ans = 0;\n for(j = 0; j < x; j++){\n a += n - k[j];\n if(a >= n){\n break;\n }\n ans++;\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2 ; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0], x = k[1];\n }else{\n k.sort(function(a, b){return b - a});\n var ans = 0, total = 0;\n for(j = 0; j < x; j++){\n total += n - k[j];\n if(total >= n){\n break;\n }\n ans++;\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction saveMice(distances, hole) {\n let miceSaved = 0;\n for (let dist of distances) {\n if (hole - dist > 0) {\n miceSaved++;\n hole -= dist;\n } else {\n break;\n }\n }\n return miceSaved;\n}\n\nfunction main() {\n const n = readline();\n for (let i = 0; i < n; i++) {\n const hole = Number(readline().split(' ')[0]);\n const miceDistancesFromHole = readline().split(' ').map(m => hole - Number(m)).sort((a, b) => a - b);\n console.log(saveMice(miceDistancesFromHole, hole))\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n\tlet numberOfTestcases = parseInt(readline(), 10)\r\n\tfor(let i = 0; i < numberOfTestcases; i++) {\r\n\t\tlet [hole, mice] = readline().split(\" \")\r\n\t\tlet positions = readline().split(\" \")\r\n\t\tconsole.log(solve(hole, mice, positions))\r\n\t\t// fs.appendFileSync(\"output.txt\", `Case #${i+1}: ${solve(x)}` + \"\\n\")\r\n\t}\r\n \r\n}\r\n\r\nfunction solve(hole, mice, positions) {\r\n\tlet maxMove = hole - 1\r\n\tpositions.sort((a,b) => a-b)\r\n\tlet result = 0\r\n\twhile(maxMove > 0 && positions.length > 0) {\r\n\t\tlet position = positions[positions.length -1]\r\n\t\tlet moveNeed = hole - position\r\n\t\tif(maxMove >= moveNeed) {\r\n\t\t\tpositions.pop()\r\n\t\t\tmaxMove -= moveNeed\r\n\t\t\tresult++\r\n\t\t}\r\n\t\telse break\r\n\t}\r\n\treturn result\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n\tlet numberOfTestcases = parseInt(readline(), 10)\r\n\tfor(let i = 0; i < numberOfTestcases; i++) {\r\n\t\tlet [hole, mice] = readline().split(\" \")\r\n\t\tlet positions = readline().split(\" \")\r\n\t\tconsole.log(solve(hole, mice, positions))\r\n\t\t// print(solve(x))\r\n\t\t// fs.appendFileSync(\"output.txt\", `Case #${i+1}: ${solve(x)}` + \"\\n\")\r\n\t}\r\n \r\n}\r\n\r\nfunction solve(hole, mice, positions) {\r\n\tlet maxMove = hole - 1\r\n\tpositions.sort((a,b) => a-b)\r\n\tlet heap = new MinHeap((a,b) => {\r\n\t\tif(a 0 && positions.length > 0) {\r\n\t\tlet position = positions[positions.length -1]\r\n\t\tlet moveNeed = hole - position\r\n\t\tif(maxMove >= moveNeed) {\r\n\t\t\tpositions.pop()\r\n\t\t\tmaxMove -= moveNeed\r\n\t\t\theap.push(position)\r\n\t\t}\r\n\t\telse break\r\n\t}\r\n\r\n\tlet result = 0\r\n\tlet cat = 0\r\n\twhile(heap.length) {\r\n\t\tlet mouse = heap.pop()\r\n\t\tif(mouse < hole - 1) {\r\n\t\t\theap.push(mouse + 1)\r\n\t\t} else {\r\n\t\t\tresult++\r\n\t\t}\r\n\t\tcat++\r\n\t\twhile(heap.length && cat === heap.peek()) {\r\n\t\t\theap.pop()\r\n\t\t}\r\n\t}\r\n\treturn result\r\n}\r\n\r\nclass MinHeap {\r\n\tconstructor(fn) {\r\n\t\tthis.cmp = fn\r\n\t\tthis.arr = []\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.arr.length\r\n\t}\r\n\r\n\tpeek() {\r\n\t\treturn this.arr[0]\r\n\t}\r\n\r\n\tpush(val) {\r\n\t\tthis.arr.push(val)\r\n\t\tthis.bubbleUp()\r\n\t}\r\n\r\n\tpop() {\r\n\t\tlet pop = this.arr[0];\r\n\t\t[this.arr[0], this.arr[this.arr.length - 1]] = [this.arr[this.arr.length - 1], this.arr[0]];\r\n\t\tthis.arr.pop()\r\n\t\tthis.bubbleDown()\r\n\t\treturn pop\r\n\t}\r\n\r\n\tswap(a, b) {\r\n\t\t[this.arr[a], this.arr[b]] = [this.arr[b], this.arr[a]]\r\n\t}\r\n\r\n\tbubbleUp() {\r\n\t\tlet current = this.arr.length - 1\r\n\t\twhile(current > 0) {\r\n\t\t\tlet parent = Math.ceil((current / 2)) - 1\r\n\t\t\tif(this.cmp(this.arr[current], this.arr[parent]) === -1) {\r\n\t\t\t\tthis.swap(current, parent)\r\n\t\t\t\tcurrent = parent\r\n\t\t\t} else {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tbubbleDown() {\r\n\t\tlet current = 0\r\n\t\twhile(true) {\r\n\t\t\tlet left = current * 2 + 1\r\n\t\t\tif(left >= this.arr.length) return\r\n\t\t\tlet right = left + 1\r\n\t\t\tif(right >= this.arr.length) right = left\r\n\t\t\tlet smaller\r\n\t\t\tif(this.cmp(this.arr[left], this.arr[right]) === -1) {\r\n\t\t\t\tsmaller = left\r\n\t\t\t} else {\r\n\t\t\t\tsmaller = right\r\n\t\t\t}\r\n\r\n\t\t\tif(this.cmp(this.arr[smaller], this.arr[current]) === -1) {\r\n\t\t\t\tthis.swap(smaller, current)\r\n\t\t\t\tcurrent = smaller\r\n\t\t\t} else {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [h, n] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => b - a);\r\n let res = 0,\r\n j = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (j < arr[i]) {\r\n let d = h - arr[i];\r\n j += d;\r\n res++;\r\n } else break;\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n let a = parseInt(readline())\r\n while(a--){\r\n let b = readline().split(' ').map(Number)\r\n let d = readline().split(' ').map(Number)\r\n d.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n let cat = 0\r\n let count = 0\r\n for(let i = 0; i < d.length;i++){\r\n if(cat >= d[i]) break\r\n cat += b[0] - d[i]\r\n count++\r\n }\r\n print(count)\r\n }\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b)\r\n{\r\n if(b==0)\r\n return a;\r\n return gcd(b,a%b);\r\n} \r\nfunction ok(x,n,k,a)\r\n{\r\n let sum=0\r\n for(let i=x;ia-b)\r\n let ans=0\r\n let L=0,R=k-1\r\n // ok(7,12,11,a);\r\n // break;\r\n while(L<=R)\r\n {\r\n let Mid=Math.floor((L+R)/2)\r\n if(ok(Mid,n,k,a))\r\n {\r\n ans=k-Mid\r\n R=Mid-1\r\n }\r\n else\r\n L=Mid+1\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b)\r\n{\r\n if(b==0)\r\n return a;\r\n return gcd(b,a%b);\r\n} \r\nfunction ok(x,n,k,a)\r\n{\r\n let sum=0\r\n for(let i=x;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b)\r\n{\r\n if(b==0)\r\n return a;\r\n return gcd(b,a%b);\r\n} \r\nfunction ok(x,n,k,a)\r\n{\r\n let sum=0\r\n for(let i=x;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a,b)\r\n{\r\n if(b==0)\r\n return a;\r\n return gcd(b,a%b);\r\n} \r\nfunction ok(x,n,k,a)\r\n{\r\n console.log(a)\r\n let sum=0\r\n for(let i=x;i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\r\n\t\tx.sort((a, b) => b - a);\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0, sm = 0; sm < n && i < x.length; i++) {\r\n\t\t\tsm += n-x[i];\r\n\t\t\tans++;\r\n\t\t}\r\n\t\t--ans;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst x = rna();\r\n\r\n\t\tx.sort((a, b) => b - a);\r\n\r\n\t\tlet sm = 0, i = 0;\r\n\t\twhile (sm < n && i < x.length) {\r\n\t\t\tsm += n-x[i++];\r\n\t\t}\r\n\r\n\t\tconst ans = i-1;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction saveMice(distances, hole) {\n let miceSaved = 0;\n for (let dist of distances) {\n if (hole - dist > 0) {\n miceSaved++;\n hole -= dist;\n } else {\n return miceSaved;\n }\n }\n}\n\nfunction main() {\n const n = readline();\n for (let i = 0; i < n; i++) {\n const hole = Number(readline().split(' ')[0]);\n const miceDistancesFromHole = readline().split(' ').map(m => hole - Number(m)).sort((a, b) => a - b);\n console.log(saveMice(miceDistancesFromHole, hole))\n }\n}\n"}], "src_uid": "fd1b846c46a074f6afa1fa6e2844c3e2"} {"source_code": "var n = readline();\nvar b = [0, 0, 0];\n\nfor (var i = 0; i < n; i++) {\n var val = readline().split(' ');\n b[0] += +val[0]; b[1] += +val[1]; b[2] += +val[2];\n}\n\nvar c = b.every( i => i == 0 );\n\nprint(c ? \"YES\" : \"NO\");", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar coordonate = [];\nvar x = [], y = [], z = [];\nvar sumX = 0, sumY = 0, sumZ = 0;\n\nfor (var i = 0; i < n; i++) {\n\tcoordonate = readline().split(' ');\n\n\tx.push(parseInt(coordonate[0]));\n\ty.push(parseInt(coordonate[1]));\n\tz.push(parseInt(coordonate[2]));\n\tsumX += x[i];\n\tsumY += y[i];\n\tsumZ += z[i];\n}\n\nif (sumX == 0 && sumY == 0 && sumZ ==0) {\n\tprint(\"YES\");\n} else {\n\tprint(\"NO\");\n}"}, {"source_code": "// A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0).\n\n// Vasya had only to answer whether it is in equilibrium. \"Piece of cake\" \u2014 thought Vasya, we need only to check if the sum of all vectors is equal to 0.\n\n//So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.\n\n// Input\n// The first line contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body (\u2009-\u2009100\u2009\u2264\u2009xi,\u2009yi,\u2009zi\u2009\u2264\u2009100).\n\n// Output\n// Print the word \"YES\" if the body is in equilibrium, or the word \"NO\" if it is not.\n \nvar n = readline()\n\nvar vec = []\nfor (i=0; i= 1;--counter)\n { \n resultPower = readline().split(' ');\n xCoordinate += +resultPower[0];\n yCoordinate += +resultPower[1];\n zCoordinate += +resultPower[2]; \n }\nif (isZeroCoordinate(xCoordinate, yCoordinate, zCoordinate))\n {\n print(\"YES\");\n }\nelse\n {\n print(\"NO\");\n }\n\nfunction isZeroCoordinate(x , y, z)\n {\n return x === 0 && y === 0 && z === 0;\n }"}, {"source_code": "var n = +readline();\nvar a = [0,0,0];\nfor(var i=0; iparseInt(i));\n}\n//console.log(arr)\nvar result=\"YES\";\nvar f=0;\nvar se=0;\nvar th=0;\nfor(var i=0;i {\n if (!count) {\n count = parseInt(line);\n return;\n }\n count--;\n [d1, d2, d3] = line.split(' ').map(Number);\n td1 += d1;\n td2 += d2;\n td3 += d3;\n if (count === 0) {\n console.log(td1 === 0 && td2 === 0 && td3 === 0 ? \"YES\" : \"NO\");\n }\n});\n"}, {"source_code": "// 69A - Young Physicist\n// http://codeforces.com/problemset/problem/69/A\n\nfunction main() {\n let n = parseInt(read());\n let a = [0, 0, 0];\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < 3; j++) {\n let x = parseInt(read());\n a[j] += x;\n }\n }\n\n for (let i = 0; i < 3; i++) {\n if (a[i] !== 0) {\n writeline(\"NO\");\n return 0;\n }\n }\n writeline(\"YES\");\n return 0;\n}\n\nvar input = \"\";\nvar read;\nvar writeline = (x) => process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n input = input.trim().split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});\n"}, {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n const V = ipt.split(EOL).slice(1, -1).map(l => l.split(' ').map(v => parseInt(v)))\n const res = V.reduce(([xr, yr, zr], [xv, yv, zv]) =>\n [xr + xv, yr + yv, zr + zv]\n , [0, 0, 0])\n console.log(res.every(v => v == 0) ? 'YES' : 'NO')\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var T = readline();\n\n let matrix = [];\n\n while (T-- > 0) {\n let vector = readline()\n .split(' ')\n .map((int) => parseInt(int));\n\n matrix.push(vector);\n }\n\n let sumX = 0;\n let sumY = 0;\n let sumZ = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n let vector = matrix[i];\n sumX += vector[0];\n sumY += vector[1];\n sumZ += vector[2];\n }\n\n if (sumX === 0 && sumY === 0 && sumZ === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n const data = [];\n while (t--) {\n const row = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n data.push(row);\n }\n\n for (let col = 0; col < 3; col++) {\n let sum = 0;\n for (let row = 0; row < data.length; row++) {\n sum += data[row][col];\n }\n if (sum !== 0) {\n console.log(\"NO\");\n return;\n }\n }\n console.log(\"YES\");\n}\n"}, {"source_code": "let readline = require('readline');\nlet rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\ninput = [];\nrl.on('line', function(line) {\n\tinput.push(line);\n\tif (input.length === input[0] * 1 + 1) {\n\t\tyoungPhysicist(input);\n\t\trl.close();\n\t}\n});\n\n//M N\nlet youngPhysicist = (input) => {\n\tinput.shift();\n\tlet input2 = input.map((el) => {\n\t\treturn el.split(' ');\n\t});\n\tlet x = 0,\n\t\ty = 0,\n\t\tz = 0;\n\tfor (let i = 0; i < input2.length; i++) {\n\t\tx += input2[i][0] * 1;\n\t\ty += input2[i][1] * 1;\n\t\tz += input2[i][2] * 1;\n\t}\n\tif (x === 0 && y === 0 && z === 0) {\n\t\tconsole.log('YES');\n\t} else {\n\t\tconsole.log('NO');\n\t}\n};\n"}, {"source_code": "const readline = require('readline')\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\nrl.on('close', () => {\n let n = parseInt(inputs[0]);\n let forces = []\n \n for (let i = 1; i < n + 1; i++) {\n const coordinate = inputs[i].split(' ').map(num => parseInt(num))\n forces.push(coordinate)\n }\n\n const xSum = forces.map(elem => elem[0]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const ySum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const zSum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n\n if (xSum != 0 || ySum != 0 || zSum != 0)\n return console.log('NO')\n else\n return console.log(\"YES\")\n\n})"}, {"source_code": "const {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n lines.map(c => c.trim());\n\n let n = +lines.unshift();\n\n lines = lines.map(c => c.split(' ').map(r => +r));\n\n let net = [0, 0, 0];\n\n for(let i = 0; i < n - 1; i++) {\n \tnet[0] += lines[i + 1][0];\n \tnet[1] += lines[i + 1][1];\n \tnet[2] += lines[i + 1][2];\n }\n\n if(!(net[0] || net[1] || net[2])) {\n \tprocess.stdout.write(\"YES\");\n } else {\n \tprocess.stdout.write(\"NO\");\n }\n});"}, {"source_code": "//Young Physicist\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n lines.map(c => c.trim());\n\n let n = +lines.shift();\n\n lines = lines.map(c => c.split(' ').map(r => +r));\n\n let net = [0, 0, 0];\n\n for(let i = 0; i < n; i++) {\n \tnet[0] += lines[i][0];\n \tnet[1] += lines[i][1];\n \tnet[2] += lines[i][2];\n }\n\n if(!(net[0] || net[1] || net[2])) {\n \tprocess.stdout.write(\"YES\");\n } else {\n \tprocess.stdout.write(\"NO\");\n }\n});"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n const n = parseInt(input[0]);\n\n let s = [0, 0, 0];\n for (let i = 1; i <= n; i += 1) {\n const [x, y, z] = splbsi(input[i]);\n s[0] += x; s[1] += y; s[2] += z;\n }\n\n console.log(s[0] === 0 && s[1] === 0 && s[2] === 0 ? \"YES\" : \"NO\")\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let x = 0, y = 0, z = 0;\n input.forEach( (line, i) => {\n if (i === 0) return;\n const nums = line.split(' ').map(x => parseInt(x));\n x += nums[0]; y += nums[1]; z += nums[2];\n });\n\n console.log(\n x === 0 && y === 0 && z === 0 ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0,\n\t\tm = n;\n\tconst arr = [];\n\n\twhile (n--) {\n\t\tconst vector = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tarr.push(vector);\n\t}\n\n\tlet nonZero = false,\n\t\tsum = 0;\n\n\tfor (let i = 0; i < 3; i++) {\n\t\tsum = 0;\n\t\tfor (let j = 0; j < m; j++) {\n\t\t\tsum += arr[j][i];\n\t\t}\n\n\t\tif (sum !== 0) {\n\t\t\tnonZero = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tnonZero ? console.log('NO') : console.log('YES');\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = parseInt(readLine());\n let AllX = [];\n let AllY = [];\n let AllZ = [];\n\n for (let i = 0; i < n; i++) {\n const numsArray = readLine().split(' ').map(Number);\n const [x, y, z] = numsArray;\n AllX.push(x);\n AllY.push(y);\n AllZ.push(z);\n }\n let sumX = AllX.reduce((a, b) => {\n return a + b;\n }, 0);\n let sumY = AllY.reduce((a, b) => {\n return a + b;\n }, 0);\n let sumZ = AllZ.reduce((a, b) => {\n return a + b;\n }, 0);\n if (sumX === 0 && sumY === 0 && sumZ === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\t\n\tvar n = inputReader.readLine();\n\tvar a = [0, 0, 0];\n\tfor (var i = 0; i < n; i++) {\n\t var x = inputReader.readLine().split(\" \");\n\t for (var j = 0; j < a.length; j++) a[j] += parseInt(x[0]);\n\t}\n\tconsole.log(a.join(\"\") == \"000\" ? \"YES\" : \"NO\");\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readLine(){\n\t\treturn _inputLines[_lineNumber++];\n\t}\n\t\t\n\t\n\treturn {\n\t\treadLine,\n\t}\n}"}, {"source_code": "let _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n \nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\t\n\tvar n = inputReader.readLine();\n\tvar a = [0, 0, 0];\n\tfor (var i = 0; i < n; i++) {\n\t var x = inputReader.readLine().split(\" \");\n\t for (var j = 0; j < a.length; j++) a[j] += parseInt(x[j]);\n\t}\n\tconsole.log(a.join(\"\") == \"000\" ? \"YES\" : \"NO\");\n \n}\n \nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n \nfunction _inputReader () {\n\tfunction readLine(){\n\t\treturn _inputLines[_lineNumber++];\n\t}\n\t\t\n\t\n\treturn {\n\t\treadLine,\n\t}\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar count = 0;\nvar test;\nvar x = 0, y = 0, z = 0;\n\nrl.on('line', (data) => {\n\n if(count!=0) {\n data = data .trim();\n\n var splitted = data.split(\" \");\n var len = splitted.length;\n\n x= x + parseInt(splitted[0]);\n y= y + parseInt(splitted[1]);\n z= z + parseInt(splitted[2]);\n\n if(count===test){\n if(x===0 && y===0 && z===0) {\n console.log(\"YES\");\n }else {\n console.log(\"NO\");\n }\n }\n }else {\n data = data.trim();\n test = parseInt(data);\n x=0, y=0, z=0;\n }\n ++count;\n});\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n var arr = [];\n\n for (var i = 0; i < n; i++) {\n var line = readLine().split(\" \").map(Number);\n arr.push(line);\n }\n\n var sum1 = 0,\n sum2 = 0,\n sum3 = 0;\n for (var i = 0; i < n; i++) {\n arr[i].map((item, index) => {\n if (index == 0) {\n sum1 += item;\n } else if (index == 1) {\n sum2 += item;\n } else if (index == 2) {\n sum3 += item;\n }\n });\n }\n\n if (sum1 === 0 && sum2 === 0 && sum3 === 0) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index ++) {\n if(!isNaN(txt[index]*1)){\n let tab=[];\n for (let i = index+1; i < index+txt[index]*1+1; i++) {\n tab.push(...txt[i].split(\" \").map(data=>{return data*1}))\n \n }\n doit(tab)\n }\n}\n\nfunction doit(tab) {\n let x=0,y=0,z=0\n tab.forEach((data,index) => {\n if(index%3==0){\n x+=data\n }else if(index%3==1){\n y+=data;\n }else{\n z+=data;\n }\n });\n if(x==0 && y==0 && z==0){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n }\n \n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const n = parseInt(readLine());\n let vectors = [];\n for (let i = 1; i < n + 1; i++) {\n let v = readLine()\n .split(\" \")\n .map((value) => parseInt(value));\n vectors.push(v);\n }\n let sum = [0, 0, 0];\n for (let i = 0; i < vectors.length; i++) {\n const vector = vectors[i];\n for (let j = 0; j < vector.length; j++) {\n sum[j] = sum[j] + vectors[i][j];\n }\n }\n let result = sum.every((n) => n === 0);\n result = result ? \"YES\" : \"NO\";\n console.log(result);\n}\n"}, {"source_code": "var n=+readline();\nvar a=[];\nwhile(n--){\n\ta.push(readline().split(' ').map(function(v){return +v;}));\n}\nvar ans = a.reduce(function(ret, v){\n\treturn ret.map(function(vv, i){\n\t\treturn vv+v[i];\n\t});\n}, [0,0,0]);\nprint(ans[0]==0&&ans[1]==0&&ans[2]==0?'YES':'NO');"}, {"source_code": "var n = +readline(), vector, sum = [0,0,0];\nfor(i = 0; i < n; i++){\n\tvector = readline().split(\" \");\n\tsum[0] += +vector[0];\n\tsum[1] += +vector[1];\n\tsum[2] += +vector[2];\n}\nif( (sum[0] == 0) && (sum[1] == 0) && (sum[2] == 0) ){\n\twrite(\"YES\");\n}\nelse{\n\twrite(\"NO\");\n}"}, {"source_code": "var n = +readline();\nvar a = [0,0,0];\nfor(var i=0; i parseInt(el));\n sum1 += arr[0];\n sum2 += arr[1];\n sum3 += arr[2];\n }\n if (sum1 === 0 && sum2 === 0 && sum3 === 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }"}, {"source_code": "var numOfLines = parseInt(readline()),\n sum1 = 0,\n sum2 = 0,\n sum3 = 0;\n for (var i = 0; i < numOfLines; i++) {\n var arr = readline().split(\" \");\n arr = arr.map((el) => parseInt(el));\n sum1 += arr[0];\n sum2 += arr[1];\n sum3 += arr[2];\n }\n if (sum1 === 0 && sum2 === 0 && sum3 === 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }"}, {"source_code": "var n = parseInt(readline());\nvar s1 = 0, s2 = 0, s3 = 0;\nfor (var i = 0; i < n; i++)\n{\n var str = readline().split(' ');\n s1 += parseInt(str[0]);\n s2 += parseInt(str[1]);\n s3 += parseInt(str[2]);\n}\nif (s1 === 0 && s2 === 0 && s3 === 0)\n print('YES');\nelse\n print('NO');"}, {"source_code": "'use strict';\nlet n = parseInt(readline()),\n totalX = 0,\n totalY = 0,\n totalZ = 0;\n\nfor(let i = 0; i parseInt(el, 10)));\n forceX += points[i][0];\n forceY += points[i][1];\n forceZ += points[i][2];\n}\n\nprint((forceX === 0 && forceY === 0 && forceZ === 0) ? 'YES' : 'NO');"}, {"source_code": "var n = readline();\n\nvar powers = {\n x: 0,\n y: 0,\n z: 0\n};\n\nfor(var i = 0; i < n; i++){\n var arr = readline().split(' ');\n powers.x += Number(arr[0]);\n powers.y += Number(arr[1]);\n powers.z += Number(arr[2]);\n}\n\nif ( powers.x == 0 && powers.y == 0 && powers.z == 0 ) {\n print('YES');\n} else {\n print('NO');\n}"}, {"source_code": "var n = parseInt(readline());\nvar matrix = [];\n\nwhile(n--)\n\tmatrix.push(readline().split(\" \").map(function convert(value) {return +value; }));\n\nvectorSum = matrix.reduce(function(vectorSum, curForse) {\n\tvectorSum[0] += curForse[0];\n\tvectorSum[1] += curForse[1];\n\tvectorSum[2] += curForse[2];\n\treturn vectorSum;\n}, [0, 0, 0]);\n\nprint((vectorSum[0] === 0 && vectorSum[1] === 0 && vectorSum[2] === 0) ? 'YES' : 'NO');\n"}, {"source_code": " var n = readline();\n var a = [0,0,0];\n for(var k=0; k parseInt(x));\n point.x += vector[0];\n point.y += vector[1];\n point.z += vector[2];\n}\n\nprint(point.x === 0 && point.y === 0 && point.z === 0 ? \"YES\" : \"NO\");\n"}, {"source_code": "var n = +readline();\nvar res = [0,0,0];\n\t\n\tfor (var i=0; i 0) {\n var s = readline().split(' ').map(function(each) {return Number(each);});\n v[0] += s[0];\n v[1] += s[1];\n v[2] += s[2];\n\n --n;\n}\n\nif (v[0] === 0 && v[1] === 0 && v[2] === 0) {\n print(\"YES\");\n} else {\n print(\"NO\");\n}\n"}, {"source_code": "function InputReader() {\n this.inputTokens = [];\n this.inputIndex = -1;\n this.nTokens = 0;\n\n this.readLine = function() {\n this.inputTokens = readline().split(\" \");\n this.nTokens = this.inputTokens.length;\n this.inputIndex = 0;\n }\n\n this.next = function() {\n if ((this.nTokens == 0) || (this.inputIndex == this.nTokens)) {\n this.readLine();\n }\n var res = this.inputTokens[this.inputIndex];\n this.inputIndex++;\n return res;\n }\n\n this.nextInt = function() {\n return parseInt(this.next());\n }\n\n this.nextFloat = function() {\n return parseFloat(this.next());\n }\n\n this.nextChar = function() {\n return this.next().charAt(0);\n }\n}\n\nvar inp = new InputReader();\nvar n = inp.nextInt();\nvar x = 0;\nvar y = 0;\nvar z = 0;\nfor (var i = 0; i < n; i++) {\n var xi = inp.nextInt();\n var yi = inp.nextInt();\n var zi = inp.nextInt();\n x += xi;\n y += yi;\n z += zi;\n}\nif ((x == 0) && (y == 0) && (z == 0)) {\n write(\"YES\\n\");\n}\nelse {\n write(\"NO\\n\");\n}\n"}, {"source_code": "no = readline();\nvar vector;\nvar x = 0;\nvar y = 0;\nvar z = 0;\nfor (var i = 0; i < no; i++) {\n vector = readline().split(' ');\n x += parseInt(vector[0]);\n y += parseInt(vector[1]);\n z += parseInt(vector[2]);\n}\nif(!x && !y && !z)\n write(\"YES\\n\");\nelse\n write(\"NO\\n\");\n"}, {"source_code": "var n = +readline();\nvar x = 0;\nvar y = 0;\nvar z = 0;\nfor (var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var T = readline();\n\n let vectorX = readline()\n .split(' ')\n .map((int) => parseInt(int));\n let vectorY = readline()\n .split(' ')\n .map((int) => parseInt(int));\n let vectorZ = readline()\n .split(' ')\n .map((int) => parseInt(int));\n\n let sum = 0;\n\n for (let i = 0; i < 3; i++) {\n sum += vectorX[i] + vectorY[i] + vectorZ[i];\n }\n\n if (sum === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var T = readline();\n\n let matrix = [];\n\n while (T-- > 0) {\n let vector = readline()\n .split(' ')\n .map((int) => parseInt(int));\n\n matrix.push(vector);\n }\n\n let sum = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n let vector = matrix[i];\n sum += vector[0] + vector[1] + vector[3];\n }\n\n if (sum === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var T = readline();\n\n let matrix = [];\n\n while (T-- > 0) {\n let vector = readline()\n .split(' ')\n .map((int) => parseInt(int));\n\n matrix.push(vector);\n }\n\n let sum = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n let vector = matrix[i];\n\n for (let j = 0; j < 3; j++) {\n sum += vector[j] + vector[j] + vector[j];\n }\n }\n\n if (sum === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n const data = [];\n while (t--) {\n const row = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n data.push(row);\n }\n const len = data.length;\n\n for (let col = 0; col < len; col++) {\n let sum = 0;\n for (let row = 0; row < len; row++) {\n sum += data[row][col];\n }\n if (sum !== 0) {\n console.log(\"NO\");\n return;\n }\n }\n console.log(\"YES\");\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n const data = [];\n while (t--) {\n const row = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n data.push(row);\n }\n\n let sum = 0;\n for (let row = 0; row < data.length; row++) {\n for (let col = 0; col < 3; col++) {\n sum += data[row][col];\n }\n }\n sum === 0 ? console.log(\"YES\") : console.log(\"NO\");\n}\n"}, {"source_code": "let readline = require('readline');\nlet rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\ninput = [];\nrl.on('line', function(line) {\n\tinput.push(line);\n\tif (input.length === input[0] * 1 + 1) {\n\t\tyoungPhysicist(input);\n\t\trl.close();\n\t}\n});\n\n//M N\nlet youngPhysicist = (input) => {\n\tinput.shift();\n\tlet reducer = (acc, curr) => acc * 1 + curr * 1;\n\tlet result = input\n\t\t.map((el) => {\n\t\t\treturn el.split(' ').reduce(reducer);\n\t\t})\n\t\t.reduce(reducer);\n\tconsole.log(result === 0 ? 'YES' : 'NO');\n};\n"}, {"source_code": "const readline = require('readline')\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\nrl.on('close', () => {\n let n = parseInt(inputs[0]);\n let forces = []\n \n for (let i = 1; i < n + 1; i++) {\n const coordinate = inputs[i].split(' ').map(num => parseInt(num))\n forces.push(coordinate)\n }\n\n const xSum = forces.map(elem => elem[0]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const ySum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const zSum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n\n if (xSum != 0 && ySum != 0 && zSum != 0)\n return console.log('NO')\n else\n return console.log(\"YES\")\n\n})"}, {"source_code": "const readline = require('readline')\n\nlet inputs = []\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput)\n})\nrl.on('close', () => {\n let n = parseInt(inputs[0]);\n let forces = []\n \n for (let i = 1; i < n + 1; i++) {\n const coordinate = inputs[i].split(' ').map(num => parseInt(num))\n forces.push(coordinate)\n }\n\n const xSum = forces.map(elem => elem[0]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const ySum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n const zSum = forces.map(elem => elem[1]).reduce((accum, next) => {\n return accum += next;\n }, 0);\n\n\n if (xSum + ySum + zSum != 0)\n return console.log('NO')\n else\n return console.log(\"YES\")\n\n})"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0,\n\t\tm = n;\n\tconst arr = [];\n\n\twhile (n--) {\n\t\tconst vector = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tarr.push(vector);\n\t}\n\n\tlet nonZero = false,\n\t\tsum = 0;\n\n\tfor (let i = 0; i < m; i++) {\n\t\tsum = 0;\n\t\tfor (let j = 0; j < 3; j++) {\n\t\t\tsum += arr[j][i];\n\t\t}\n\n\t\tif (sum !== 0) {\n\t\t\tnonZero = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tnonZero ? console.log('NO') : console.log('YES');\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tconst arr = [];\n\n\twhile (n--) {\n\t\tconst vector = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tarr.push(vector);\n\t}\n\n\tlet nonZero = false,\n\t\tsum = 0;\n\n\tfor (let i = 0; i < 3; i++) {\n\t\tsum = 0;\n\t\tfor (let j = 0; j < 3; j++) {\n\t\t\tsum += arr[j][i];\n\t\t}\n\n\t\tif (sum !== 0) {\n\t\t\tnonZero = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tnonZero ? console.log('NO') : console.log('YES');\n}\n"}, {"source_code": "process.stdin.resume();\nconsole.log(process);\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = +readLine();\n let AllX = [];\n let AllY = []; // [2, -1,-1]\n let AllZ = [];\n\n for (let i = 0; i < n; i++) {\n const numsArray = readLine().split(' ').map(Number);\n const [x, y, z] = numsArray;\n AllX.push(x);\n AllY.push(y);\n AllZ.push(z);\n }\n let sumX = AllX.reduce((a, b) => {\n return a + b;\n }, 0);\n let sumY = AllY.reduce((a, b) => {\n return a + b;\n }, 0);\n let sumZ = AllZ.reduce((a, b) => {\n return a + b;\n }, 0);\n if (sumX === 0 && sumY === 0 && sumZ === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n var arr = [];\n\n for (var i = 0; i < n; i++) {\n var line = readLine().split(\" \").map(Number);\n arr.push(...line);\n }\n\n var sum = arr.reduce((acc, item) => {\n return (acc += item);\n }, 0);\n\n if (sum === 0) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index ++) {\n if(!isNaN(txt[index]*1)){\n let tab=[];\n for (let i = index+1; i < index+txt[index]*1+1; i++) {\n tab.push(...txt[i].split(\" \").map(data=>{return data*1}));\n \n }\n doit(tab);\n }\n}\n\nfunction doit(tab) {\n let score=0;\n tab.forEach(element => {\n score+=element;\n });\n if(score===0){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n }\n \n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const n = parseInt(readLine());\n let vectors = [];\n for (let i = 1; i < n + 1; i++) {\n let v = readLine()\n .split(\" \")\n .map((value) => parseInt(value))\n .reduce((a, b) => a + b, 0);\n vectors.push(v);\n }\n let sum = vectors.reduce((a, b) => a + b, 0);\n let result = sum === 0 ? \"YES\" : \"NO\";\n console.log(result);\n}\n"}, {"source_code": "var n = parseInt(readline(), 10), force = 0, points = '', tempSum = 0;\n \nfor(var i=1; i<=n; i++) {\n points = readline().split(' ').map(el => parseInt(el, 10));\n tempSum = points.reduce((a,b) => a+b);\n if(tempSum !== 0) {\n force += tempSum;\n } else {\n force = -1;\n break;\n }\n}\n\nprint((force === 0) ? 'YES' : 'NO');"}, {"source_code": "var n = parseInt(readline(), 10), force = 0, points = '';\n \nfor(var i=1; i<=n; i++) {\n points = readline().split(' ').map(el => parseInt(el, 10));\n force += points.reduce((a,b) => a+b);\n} \n\nprint((force === 0) ? 'YES' : 'NO');"}, {"source_code": "var n = readline();\n\nvar powers = {\n x: 0,\n y: 0,\n z: 0\n};\n\nfor(var i = 0; i < n; i++){\n var arr = readline().split(' ');\n powers.x += Number(arr[0]);\n powers.y += Number(arr[1]);\n powers.z += Number(arr[2]);\n}\n\nif (powers.x + powers.y + powers.z > 0) {\n print('NO');\n} else {\n print('YES');\n}\n\n"}, {"source_code": "var n = readline();\n\nvar powers = {\n x: 0,\n y: 0,\n z: 0\n};\n\nfor(var i = 0; i < n; i++){\n var arr = readline().split(' ');\n powers.x += Number(arr[0]);\n powers.y += Number(arr[1]);\n powers.z += Number(arr[2]);\n}\n\nif ( powers.x && powers.y && powers.z ) {\n print('NO');\n} else {\n print('YES');\n}\n"}, {"source_code": " var n = readline();\n var a = [0,0,0];\n for(var k=0; k parseInt(x));\n point.x += vector[0];\n point.y += vector[1];\n point.z += vector[2];\n}\n\nprint(point.x + point.y + point.z === 0 ? \"YES\" : \"NO\");"}, {"source_code": "(function main() {\n \n var count = parseInt(readline());\n\n var a = 0,\n b = 0,\n c = 0;\n\n for ( var i = 0; i < count; i++ ) {\n\n var vec = readline().trim().split(' ').map(Number);\n\n a += vec[0];\n b += vec[1];\n c += vec[2];\n }\n\n if ( a + b + c == 0 ){\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n\n return 0;\n})();"}, {"source_code": "no = readline();\nvar vector;\nvar x = 0;\nvar y = 0;\nvar z = 0;\nfor (var i = 0; i < no; i++) {\n vector = readline().split(' ');\n x += vector[0];\n y += vector[1];\n z += vector[2];\n}\nif(!x && !y && !z)\n write(\"YES\\n\");\nelse\n write(\"NO\\n\");\n"}, {"source_code": "var n = readline()\nvar n = readline().split(\" \").map(function(x){return parseInt(x)})\nvar n1 = readline().split(\" \").map(function(x){return parseInt(x)})\nvar n2 = readline().split(\" \").map(function(x){return parseInt(x)})\n\nvar res = ((n[0]+n1[0]+n2[0])+(n[1]+n1[1]+n2[1])+(n[2]+n1[2]+n2[2]));\n\n(res == 0)?res = \"YES\":res = \"NO\"\n\nprint(res)"}, {"source_code": "var n3 = readline()\nvar n = readline().split(\" \").map(function(x){return parseInt(x)})\nres = n\n\nfunction sum(a,b) {\n a[0] = a[0] + b[0]\n a[1] = a[1] + b[1]\n a[2] = a[2] + b[2]\n return a\n}\n\nfor(var i = 0; i < n3 - 1; i++) {\n var n1 = readline().split(\" \").map(function(x){return parseInt(x)});\n res = sum(n,n1)\n}\nres = res.reduce((a, b) => a + b, 0);\n\n(res == 0)?res = \"YES\":res = \"NO\"\n\nprint(res)"}, {"source_code": "var n = readline()\nvar sum = [[], [], []]\n\nfor(var i = 0; i < n; i++) {\n n = readline().split(\" \").map(function(x){return parseInt(x)})\n sum[0].push(n[0])\n sum[1].push(n[1])\n sum[2].push(n[2])\n}\n\nfor(elem of sum) {\n elem = elem.reduce((a, b) => a + b, 0)\n if (elem==0) {\n res = \"YES\"\n }else {\n res = \"NO\"\n break;\n }\n}\n\nprint(res)"}, {"source_code": "var n3 = readline()\nvar n = readline().split(\" \").map(function(x){return parseInt(x)})\nres = n\n\nfunction sum(a,b) {\n a[0] = a[0] + b[0]\n a[1] = a[1] + b[1]\n a[2] = a[2] + b[2]\n return a\n}\n\nfor(var i = 0; i < n3 - 1; i++) {\n var n1 = readline().split(\" \").map(function(x){return parseInt(x)});\n res = sum(n,n1)\n print(res)\n}\n\n(res[0]==0&&res[1]==0&&res[2]==0)?res = \"YES\":res = \"NO\"\n\nprint(res)"}, {"source_code": "// One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\n// This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n// Input\n\n// The first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n// Output\n\n// Print a single integer \u2014 the number of problems the friends will implement on the contest.\n\nvar n = readline()\n\nvar vectors = []\nfor (i=0; i parseInt(a) + parseInt(b)))\n}\nif (sum == 0) { print(\"YES\") } \nelse{ print(\"NO\")}"}, {"source_code": "n = readline();\nvar sum1 = 0;\nvar sum2 = 0;\nvar sum3 = 0;\nwhile(n--){\n\tk = readline().split(' ')\n sum1 = sum1 + k[0];\n sum2 = sum2 + k[1];\n sum3 = sum3 + k[2];\n}\nif (sum1 == 0 && sum2 == 0 && sum3 == 0) { print(\"YES\") } \nelse{ print(\"NO\")}"}, {"source_code": "n = readline();\nvar sum1 = 0;\nvar sum2 = 0;\nvar sum3 = 0;\nwhile(n--){\n\tk = readline().split(' ')\n sum1 = sum1 + k[0];\n sum2 = sum1 + k[1];\n sum3 = sum1 + k[2];\n}\nif (sum1 == 0 && sum2 == 0 && sum3 == 0) { print(\"YES\") } \nelse{ print(\"NO\")}"}, {"source_code": "n = readline();\n\nvar sumX = 0, sumY = 0, sumZ = 0;\n\nfor (var i = 0; i < n; i++) {\n\tvect = readline().split(' ').map(Number);\n\n\tsumX = sumX + vect[0];\n\tsumY = sumY + vect[1];\n\tsumZ = sumZ + vect[2];\n};\n\nvar sum = sumX + sumY + sumZ;\n\nif (sum === 0) {\n\tprint('YES');\n} else {\n\tprint('NO');\n};"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\n\nvar s=parseInt(readline().split(' ')[0]);\nvar arr=readline().split(' ').map(i=>parseInt(i));\nvar force1=readline().split(' ').map(i=>parseInt(i));\nvar force2=readline().split(' ').map(i=>parseInt(i));\n\nvar result=\"YES\";\nfor(var i=0;iparseInt(i));\n}\nvar result=\"YES\";\nfor(var i=0;iparseInt(i));\n}\n//console.log(arr)\nvar result=\"YES\";\nvar f=0;\nvar se=0;\nvar th=0;\nfor(var i=0;i i == 0 );\n\nprint(c);"}, {"source_code": "'use strict'\nlet input = readline()\nlet i = 1\nlet diff = 0\nwhile(i <= input){\n let data = readline().split(' ').map(Number);\n let d = data.reduce((acc,add) => {\n return acc+add; \n })\n if(diff == 0) diff = d\n else diff += d\n i++\n}\ndiff == 0 ? print(\"YES\") : print(\"NO\")"}, {"source_code": "\n numOfLines = readline();\n numOfLines = parseInt(numOfLines);\n sum = 0;\n sumOfSum = 0;\n for ( i = 0; i < numOfLines; i++) {\n arr = readline().split(\" \");\n\n arr = arr.map((el) => parseInt(el));\n arr = arr.map((el) => {\n sum += el;\n });\n sumOfSum += sum;\n sum = 0;\n }\n if (sumOfSum === 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n "}, {"source_code": "\n numOfLines = readline();\n numOfLines = parseInt(numOfLines);\n isTrue = false;\n sum = 0;\n sumOfSum = 0;\n for ( i = 0; i < numOfLines; i++) {\n arr = readline().split(\" \");\n\n arr = arr.map((el) => {\n sum += el;\n });\n sumOfSum += sum;\n sum = 0;\n }\n if (sumOfSum == 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n "}, {"source_code": "\n numOfLines = readline();\n numOfLines = parseInt(numOfLines);\n isTrue = false;\n sum = 0;\n sumOfSum = 0;\n for ( i = 0; i < numOfLines; i++) {\n arr = readline().split(\" \");\n\n arr = arr.map((el) => parseInt(el));\n arr = arr.map((el) => {\n sum += el;\n });\n sumOfSum += sum;\n sum = 0;\n }\n if (sumOfSum == 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n "}, {"source_code": "var n = parseInt(readline());\nvar s1 = 0, s2 = 0, s3 = 0;\nfor (var i = 0; i < n; i++)\n{\n var str = readline().split(' ');\n s1 += str[0];\n s2 += str[1];\n s3 += str[2];\n}\nif (s1 === 0 && s2 === 0 && s3 === 0)\n print('YES');\nelse\n print('NO');"}, {"source_code": "var n = readline();\nvar res = \"0 0 0\".split(\" \");\n for (var i=0; i acum + parseInt(val), 0);\nprint(input !== 0 ? \"NO\" : \"YES\");"}, {"source_code": "var input = readline().split(\" \").reduce((acum, val) => acum + parseInt(val), 0);\nprint(input !== 0 ? \"NO\" : \"YES\");\n"}, {"source_code": "var c = readline();\nvar out = 0;\nwhile (c--) {\n out += +readline()[0];\n}\nprint(out !== 0 ? \"NO\" : \"YES\");"}, {"source_code": "var c = readline();\nvar out = 0;\nwhile (c--) {\n out += readline().split(\" \").reduce((acum, val) => acum + parseInt(val), 0);\n}\nprint(out !== 0 ? \"NO\" : \"YES\");"}], "src_uid": "8ea24f3339b2ec67a769243dc68a47b2"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n=-1;\nvar d = 0;\nvar array =[];\nvar counter = 0;\nvar deference =0;\n\nrl.on('line', (input) => {\n\n if(n++ ==-1)\n {\n array =input.split(\" \");\n d = parseInt(array[1]);\n }\n else\n {\n array =input.split(\" \");\n const map =array.map(x => x*1);\n for(var i=1;i 0) {\n t_lns.push(t);\n }\n }\n const [a, b] = t_lns;\n const [n, d] = a.split(/\\s+/).map(Number);\n const bs = b.split(/\\s+/).map(Number);\n const result = solve(d, bs);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function rem(a, b) {\n if (b <= 0) {\n throw Error('divisor must be positive');\n } else {\n const r = (a % b);\n return (r < 0) ? (r + b) : r;\n }\n}\n\nfunction quot(a, b) {\n if (b <= 0) {\n throw Error('divisor must be positive');\n } else {\n const r = rem(a, b);\n const q = ((a - r) / b);\n return q;\n }\n}\n\nfunction solve(d, bs) {\n let result = 0;\n let p = bs[0];\n for (let i = 1; i < bs.length; i = i + 1) {\n const b = bs[i];\n if (p < b) {\n p = b;\n } else {\n const q = quot(p - b, d);\n result = result + q + 1;\n p = b + ((q + 1) * d);\n }\n }\n return result;\n}\n\nfunction main(lns) {\n const t_lns = [];\n for (const ln of lns) {\n let t = ln.trim();\n if (t.length > 0) {\n t_lns.push(t);\n }\n }\n const [a, b] = t_lns;\n const [n, d] = a.split(/\\s+/).map(Number);\n const bs = b.split(/\\s+/).map(Number);\n const result = solve(d, bs);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "var lll = readline().split(' ')\nvar N = +lll[0]\nvar D = +lll[1]\n\nvar ns = readline().split(' ').map(function (i) {return parseInt(i)})\n\nvar sn = 0\n\nfor (var i = 1; i < N; i++) {\n var dif = ns[i] - ns[i - 1]\n if (dif <= 0) {\n var inc = (-dif / D | 0) + 1\n sn += inc\n ns[i] += D * inc\n }\n}\n\nprint(sn)"}, {"source_code": "var count = 0;\nvar data = readline().split(' ').map(item => parseInt(item));\nvar n = data[0], h = data[1];\ndata = readline().split(' ').map(item => parseInt(item));\nfor(var i = 1; i < n; i++) {\n if(data[i - 1] >= data[i]) {\n var ans = parseInt((data[i - 1] - data[i]) / h) + 1;\n count += ans;\n data[i] += ans * h;\n }\n}\nprint(count);"}, {"source_code": "input = readline().split(\" \").map(item => parseInt(item))\nsequence = readline().split(\" \").map(item => parseInt(item))\n\ncount = 0\nvar previousItem = 0\nvar incrementer = input[1]\nfor (item of sequence) {\n while (item <= previousItem) {\n mod = (previousItem - item) % incrementer\n diff = Math.floor((previousItem - item)/incrementer)\n item += diff * incrementer\n if (item <= previousItem) {\n item += incrementer\n count++\n }\n count += diff\n }\n previousItem = item\n}\n\nprint(count)"}], "negative_code": [{"source_code": "input = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\nsequence = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\n\nfor (item in sequence) {\n if (sequence[item - 1] != null) {\n if (sequence[item] < sequence[item - 1]) {\n print(item)\n }\n }\n}\n\n/*\nfor (i = 0; i < input[0]; i++) {\n\n}\n*/\n"}, {"source_code": "input = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\nsequence = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\n\nfor (item in sequence) {\n if (sequence[item - 1] != null) {\n if (sequence[item] < sequence[item - 1]) {\n print(item)\n } else if (item == sequence.length - 1) {\n print(item)\n }\n }\n}\n\n/*\nfor (i = 0; i < input[0]; i++) {\n\n}\n*/\n"}, {"source_code": "input = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\nsequence = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\n\nfor (item in sequence) {\n if (sequence[item - 1] != null) {\n if (sequence[item] < sequence[item - 1]) {\n print(item)\n } else if (sequence[item] > sequence[item - 1] && item == sequence.length - 1) {\n print(\"0\")\n } else if (item == sequence.length - 1) {\n print(item)\n }\n }\n}\n\n/*\nfor (i = 0; i < input[0]; i++) {\n\n}\n*/\n"}, {"source_code": "input = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\nsequence = readline().split(\" \").map(function convert(item) {\n return parseInt(item)\n})\n\n/*count = 0\nfor (item in sequence) {\n if (sequence[item - 1] != null) {\n if (sequence[item] < sequence[item - 1]) {\n while (sequence[item] < sequence[item - 1]) {\n sequence[item] += input[1]\n count++\n }\n } else if (sequence[item] > sequence[item - 1] && item == sequence.length - 1) {\n print(\"0\")\n } else if (item == sequence.length - 1) {\n print(item)\n }\n }\n}\n\ncount > 0 ? print(count) : 0*/\noutput = \"\"\nfor (item in sequence) {\n if (sequence[item - 1] != null) {\n if (sequence[item] < sequence[item - 1]) {\n output += item\n } else if (sequence[item] > sequence[item - 1] && item == sequence.length - 1) {\n output += \"0\"\n } else if (item == sequence.length - 1) {\n output += item\n }\n }\n}\nprint(output)\n\n/*\nfor (i = 0; i < input[0]; i++) {\n\n}\n*/\n"}], "src_uid": "0c5ae761b046c021a25b706644f0d3cd"} {"source_code": "var f = readline().split(\" \").map(Number);\nvar s = f[0];\nvar n = f[1];\ndragons = []\n\nfunction dragon(x, y){\n\tthis.x = x;\n\tthis.y = y;\n}\n\nfor(var i = 0; i < n; i++){\n\tdata = readline().split(\" \").map(Number);\n\tdragons.push(new dragon(data[0], data[1]));\n}\n\ndragons.sort(function(d1, d2){\n\tif( (d1.x - d2.x !== 0)){\n\t\treturn d1.x - d2.x\n\t}\n\telse{ //Sort by bonus otherwise\n\t\treturn d1.y - d1.y;\n\t}\n});\n\nfunction test(alod, strength){\n\tmys = strength\n\tfor(var i = 0; i < alod.length; i++){\n\t\tif(mys > alod[i].x){\n\t\t\tmys += alod[i].y\n\t\t}\n\t\telse{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nif(test(dragons, s)){\n\tprint(\"YES\")\n}\nelse {\n\tprint(\"NO\")\n}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readIntArray() {\n return readline()\n .split(' ')\n .map((num) => parseInt(num));\n}\n\nfunction readFloatArray() {\n return readline()\n .split(' ')\n .map((num) => parseFloat(num));\n}\n\n/*=====================START CODING HERE=====================*/\n\n// DONT FUCK WITH THE MAIN FUNCTION !!\nfunction main() {\n let [s, n] = readIntArray();\n\n let levels = [];\n let flag = false;\n\n while (n-- > 0) {\n levels.push(readIntArray());\n }\n\n levels.sort((a, b) => a[0] - b[0]);\n\n levels.forEach((match) => {\n if (s <= match[0]) {\n flag = false;\n } else {\n s += match[1];\n flag = true;\n }\n });\n\n console.log(flag ? 'YES' : 'NO');\n}\n"}, {"source_code": ";(function () {\n\n\tvar s = readline().split(' ');\n\tvar n = +s[1];\n\ts = +s[0];\n\n\tvar d = [];\n\tfor (var i = 0; i < n; i++) d.push(readline().split(' ').map(Number));\n\td.sort(function(a, b) { return a[0] - b[0]; } );\n\t\n\tfor (var i = 0; i < n; i++)\n\t\tif (s <= d[i][0]) {\n\t\t\tprint('NO');\n\t\t\treturn;\n\t\t} else s += d[i][1];\n\n\tprint('YES');\n\n}).call(this);"}, {"source_code": "var s = readline().split(\" \");\nvar level = Number(s[0]), n = Number(s[1]);\n\nvar dragons = [];\nfor(var i=0; i a.level - b.level);\n\nvar win = true;\nfor(var i=0; i dragons[i].level) {\n level += dragons[i].exp;\n }\n else {\n win = false;\n break;\n }\n}\nif (win) {\n print('YES')\n}\nelse {\n print('NO')\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [heroPower, len] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let win = true;\n const enemies = [];\n\n while (len--) {\n const [enemyPower, point] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n enemies.push([enemyPower, point]);\n }\n enemies.sort((a, b) => a[0] - b[0]);\n\n len = 0;\n\n while (len < enemies.length) {\n const [enemyPower, point] = enemies[len];\n if (heroPower <= enemyPower) {\n win = false;\n console.log(\"NO\");\n break;\n }\n\n if (heroPower > enemyPower) heroPower += point;\n\n len++;\n }\n\n if (win) console.log(\"YES\");\n}\n"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array = readline().getNumArray(),\n s = array[0],\n n = array[1],\n drakons = [];\n for (let i = 0; i < n; i++) {\n drakons.push(readline().getNumArray());\n }\n\n drakons.sort((a,b) => a[0] - b[0]);\n\n\n for (let i = 0; i < n; i++) {\n if (s > drakons[i][0]) {\n s += drakons[i][1];\n } else {\n write('NO');\n return;\n }\n }\n write('YES');\n})();"}, {"source_code": "let readline = require('readline');\nlet rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\n\nlet input = [];\n\nrl.on('line', function(line) {\n\tinput.push(line.split(' ').map((el) => el * 1));\n\tif (input.length === input[0][1] * 1 + 1) {\n\t\tdragons(input);\n\t\trl.close();\n\t}\n});\n\nlet dragons = (input) => {\n\tlet array = input;\n\tlet S = array[0][0];\n\tarray.shift();\n\tarray.sort((a, b) => {\n\t\tif (a[0] < b[0]) return -1;\n\t\tif (a[0] > b[0]) return 1;\n\t\treturn 0;\n\t});\n\tlet flag = 1;\n\tfor (let i = 0; i < array.length; i++) {\n\t\tif (S > array[i][0]) {\n\t\t\tS += array[i][1];\n\t\t\tcontinue;\n\t\t} else {\n\t\t\tflag = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tflag === 0 ? console.log('NO') : console.log('YES');\n};\n"}, {"source_code": "var l = readline().split(' ').map(v => parseInt(v, 10));\nvar n = l[1];\nvar s = l[0];\nvar d = [];\n\nfor (var i = 0; i < n; i++) {\n var a = readline().split(' ').map(v => parseInt(v, 10));\n d.push({\n x: a[0],\n y: a[1],\n });\n}\n\nd.sort((o1, o2) => {\n return o1.x - o2.x; \n});\n\n\nvar good = true;\nfor (var i = 0; i < n; i++) {\n if (d[i].x >= s) {\n good = false;\n break;\n }\n s += d[i].y;\n}\n\nprint(good ? 'YES' : 'NO')"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let dragons = [];\n\n // Who\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n const Ds = parseInt(dragon[0]);\n const Db = parseInt(dragon[1]);\n dragons.push([Ds, Db]);\n }\n\n // Who is first\n dragons = dragons.sort((a, b) => a[0] > b[0] ? 1 : -1);\n\n // Fight\n for (const dragon of dragons) {\n if (Ks > dragon[0])\n Ks += dragon[1];\n else {\n return console.log(\"NO\")\n }\n }\n\n console.log(\"YES\")\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let dragons = [];\n\n // Who\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n const Ds = parseInt(dragon[0]);\n const Db = parseInt(dragon[1]);\n dragons.push({ strength: Ds, bonus: Db });\n }\n\n // Who is first\n dragons = dragons.sort((a, b) => a.strength > b.strength ? 1 : -1);\n\n // Fight\n for (const dragon of dragons) {\n if (Ks > dragon.strength)\n Ks += dragon.bonus;\n else {\n return console.log(\"NO\")\n }\n }\n\n console.log(\"YES\")\n});"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [s, n] = input[0].split(' ').map(x => parseInt(x));\n const dragons = [];\n\n input.forEach((x, i) => {\n if (i === 0) return;\n const nums = x.split(' ').map(x => parseInt(x));\n dragons.push([\n nums[0], nums[1],\n ]);\n });\n\n dragons.sort((a, b) => a[0]-b[0]);\n dragons.forEach(d => {\n if (d[0] < s) {\n s += d[1];\n } else {\n console.log('NO'); process.exit();\n }\n });\n\n console.log('YES');\n});\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let [s, n] = splitAndParseInt(input[0]);\n\n const dragons = [];\n for (let i = 1; i <= n; i += 1) {\n const dg = splitAndParseInt(input[i]);\n dragons.push(dg);\n }\n\n dragons.sort((a, b) => a[0] - b[0]);\n for (const [x, y] of dragons) {\n if (s <= x) {\n console.log(\"NO\");\n return;\n } else {\n s += y;\n }\n }\n\n console.log(\"YES\");\n});"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var s = +str[1];\nvar f = [];\n\n\tfor (var i=0; i<+s; i++){ \n f[i]= readline().split(\" \");\n\t}\n\tf.sort((x,y)=>x[0]-y[0]);\n\t\tfor (var i=0; i<+s; i++){\n\t\t\t\t\tif (+f[i][0] {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [s, n] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\tlet canGoNext = true;\n\tlet dragons = [];\n\n\twhile (n--) {\n\t\tlet [x, y] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(item => parseInt(item));\n\t\tdragons.push([x, y]);\n\t}\n\n\tdragons.sort((a, b) => a[0] - b[0]);\n\n\tfor (let i = 0, l = dragons.length; i < l; ++i) {\n\t\tif (s > dragons[i][0]) {\n\t\t\ts = s + dragons[i][1];\n\t\t} else {\n\t\t\tcanGoNext = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tcanGoNext ? console.log('YES') : console.log('NO');\n}\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n let info = txt[i].split(\" \");\n let tab = [];\n for (let i1 = i + 1; i1 < i + info[1] * 1 + 1; i1++) {\n tab.push(txt[i1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n }\n i += info[1] * 1;\n doit(info[0] * 1, tab);\n}\n\nfunction doit(n, tab) {\n tab.sort((a, b) => b[1] - a[1]);\n while (tab.length > 0) {\n let test = false;\n for (let i = 0; i < tab.length; i++) {\n if (tab[i][0] < n) {\n test = true;\n n += tab[i][1];\n tab.splice(i, 1);\n break;\n }\n }\n if (!test) {\n console.log(\"NO\");\n return;\n }\n }\n console.log(\"YES\");\n}"}, {"source_code": "var s = readline().split(\" \");\nvar level = Number(s[0]), n = Number(s[1]);\n\nvar dragons = [];\nfor(var i=0; i a.level - b.level);\n\nvar win = true;\nfor(var i=0; i dragons[i].level) {\n level += dragons[i].exp;\n }\n else {\n win = false;\n break;\n }\n}\nif (win) {\n print('YES')\n}\nelse {\n print('NO')\n}"}, {"source_code": "var input = readline().split(' ');\n\nvar s = +input[0];\nvar n = +input[1];\n\nvar Dragon = function(data) {\n this.x = +data[0];\n this.y = +data[1];\n};\n\nvar dragons = [];\nfor (var i = 0; i < n; ++i) {\n dragons.push(new Dragon(readline().split(' ')));\n}\n\ndragons.sort(function(a, b) {\n return a.x - b.x;\n});\n\nfor (var i = 0; i < dragons.length; ++i) {\n if (s <= dragons[i].x) {\n write('NO');\n quit();\n }\n s += dragons[i].y;\n}\n\nwrite('YES');"}, {"source_code": "var firstLine = readline().split(\" \").map(Number);\nvar s = firstLine[0];\nvar n = firstLine[1];\ndragons = []\n\nfunction dragon(x, y){\n\tthis.x = x;\n\tthis.y = y;\n}\n\nfor(var i = 0; i < n; i++){\n\tdata = readline().split(\" \").map(Number);\n\tdragons.push(new dragon(data[0], data[1]));\n}\n\n//Sorted by strengths: always kill the weakest first\ndragons.sort(function(d1, d2){\n\tif( (d1.x - d2.x !== 0)){\n\t\treturn d1.x - d2.x\n\t}\n\telse{ //Sort by bonus otherwise\n\t\treturn d1.y - d1.y;\n\t}\n});\n\nfunction test(alod, strength){\n\tmys = strength\n\tfor(var i = 0; i < alod.length; i++){\n\t\tif(mys > alod[i].x){\n\t\t\tmys += alod[i].y\n\t\t}\n\t\telse{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nif(test(dragons, s)){\n\tprint(\"YES\")\n}\nelse{\n\tprint(\"NO\")\n}\n"}, {"source_code": "var f = readline().split(\" \").map(Number);\nvar s = f[0];\nvar n = f[1];\ndragons = []\n\nfunction dragon(x, y){\n\tthis.x = x;\n\tthis.y = y;\n}\n\nfor(var i = 0; i < n; i++){\n\tdata = readline().split(\" \").map(Number);\n\tdragons.push(new dragon(data[0], data[1]));\n}\n\ndragons.sort(function(d1, d2){\n\tif( (d1.x - d2.x !== 0)){\n\t\treturn d1.x - d2.x\n\t}\n\telse{ //Sort by bonus otherwise\n\t\treturn d1.y - d1.y;\n\t}\n});\n\nfunction test(alod, strength){\n\tmys = strength\n\tfor(var i = 0; i < alod.length; i++){\n\t\tif(mys > alod[i].x){\n\t\t\tmys += alod[i].y\n\t\t}\n\t\telse{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nif(test(dragons, s)){\n\tprint(\"YES\")\n}\nelse{\n\tprint(\"NO\")\n}"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var s = +str[1];\nvar f = [];\n\nfor (var i=0; i<+s; i++){ \n f[i]= readline().split(\" \");\n}\nf.sort((x,y)=>x[0]-y[0]);\nfor (var i=0; i<+s; i++){\n if (+f[i][0] parseInt(x)));\n}\ndragons.sort((a,b) => a[0] - b[0]);\nvar statement = 'YES';\nfor (var i = 0; i < dragons.length; i++) {\n if (dragons[i][0] < s) s+= dragons[i][1]\n else {\n statement = 'NO';\n break;\n }\n}\nprint(statement);\n"}, {"source_code": "\"use strict\";\nvar args = readline().split(' ').map(function(x) {return parseInt(x)});\nvar s = args[0];\nvar n = args[1];\nvar i;\nvar head;\nvar p;\nvar dragons = [];\n\nfor (i = 0; i < n; i++) {\n args = readline().split(' ').map(function(x) {return parseInt(x)});\n dragons.push({x: args[0], y: args[1]});\n}\n\ndragons = dragons.sort(function(a, b) {\n return a.x - b.x;\n});\n\ni = 0;\nwhile (i < n) {\n if (s > dragons[i].x) {\n s += dragons[i].y;\n i += 1;\n }\n else {\n print('NO');\n s = -1;\n break;\n }\n}\nif (s > 0) {\n print('YES');\n}\n"}, {"source_code": "\nvar l=readline().split(' ');\nvar s=+l[0];\nvar n=+l[1];\nvar a=[];\nfor(var i=0;i +y[j]){\n\t\t\t\tbuf1 = y[i];\n\t\t\t\ty[i] = y[j];\n\t\t\t\ty[j] = buf1;\n\t\t\t\tbuf2 = x[i];\n\t\t\t\tx[i] = x[j];\n\t\t\t\tx[j] = buf2;\n\t\t\t}\n\t\t}\n\t}\n}\n\nvar input = readline().split(\" \"), s = +input[0], n = +input[1], x = [], y = [];\nfor(i = 0; i < n; i++){\n\tinput = (readline().split(\" \"));\n\tx[i] = +input[0];\n\ty[i] = +input[1];\n}\n\nsorting();\n\nfor(i = 0; i < x.length; i++){\n\tif(s > x[i]){\n\t\ts += y[i];\n\t\tx.splice(i,1);\n\t\ty.splice(i,1);\n\t\ti = -1;\n\t}\n}\n\nif(x.length == 0){\n\twrite(\"YES\");\n}\nelse{\n\twrite(\"NO\");\n}"}], "negative_code": [{"source_code": "var s = readline().split(\" \");\nvar s = Number(s[0]), n = Number(s[1]);\n\nvar dragons = [];\nfor(var i=0; i a.level - b.level);\n\n\nvar win = true;\nfor(var i=0; i dragons[i].level) {\n s += dragons[i].exp;\n }\n else {\n win = false;\n break;\n }\n}\nif (win) {\n print('YES')\n}\nelse {\n print('NO')\n}"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array = readline().getNumArray(),\n s = array[0],\n n = array[1];\n for (let i = 0; i < n; i++) {\n let player = readline().getNumArray();\n if (s > player[0]) {\n s += player[1];\n } else {\n write('NO');\n return;\n }\n }\n write('YES');\n})();"}, {"source_code": "var l = readline().split(' ').map(v => parseInt(v, 10));\nvar n = l[1];\nvar s = l[0];\nvar d = [];\n\nfor (var i = 0; i < n; i++) {\n var a = readline().split(' ').map(v => parseInt(v, 10));\n d.push({\n x: a[0],\n y: a[1],\n });\n}\n\nd.sort((o1, o2) => {\n return o1.x > o2.x; \n});\n\n\nvar good = true;\nfor (var i = 0; i < n; i++) {\n if (d[i].x >= s) {\n good = false;\n break;\n }\n s += d[i].y;\n}\n\nprint(good ? 'YES' : 'NO')"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var s = +str[1];\nvar f = [];\n\tfor (var i=0; i<+s; i++){ \n\t f[i]= readline().split(\" \");\n\t}\n\tf.sort((x,y)=>x[0]-y[0]);\n\t\tfor (var i=0; i<+s; i++){\n\t\t\t\t\tif (+f[i][0]x[0]-y[0]);\n\t\tfor (var i=0; i<+s; i++){\n\t\t\t\t\tif (+f[c][0]Number(stroka[0])) s+= Number(stroka[1]);\n\t\telse { \n\t\tbreak; print(\"NO\");\n\t\t}\n\t\tif (i+1==n) \tprint(\"YES\");\n\t\t\n\t}\n"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var s = +str[1];\nvar f = [];\nvar c=0;\n\n\n\tfor (var i=0; i<+s; i++){ \n\t f[i]= readline().split(\" \");\n\t}\n\tf.sort((x,y)=>x-y);\n\t\t\twhile (c!=f.length||f.length>1){\n\t\t\t\t\tif (+f[c][0]+stroka[0]) s+= +stroka[1];\n\t\telse { \n\t\tbreak; print(\"NO\");\n\t\t}\n\t\t\n\t}\n\tprint(\"YES\");"}, {"source_code": "var str = readline().split(\" \");\n\tvar s = Number(str[0]); var n = Number(str[1]);\n\t\n\tfor (var i = 0; i<+n; i++){\n\t\tvar stroka = readline().split(\" \");\n\t\tif (s>Number(stroka[0])) s+= Number(stroka[1]);\n\t\telse { \n\t\tprint(\"NO\"); break; \n\t\t}\n\t\tif (i+1==n) \tprint(\"YES\");\n\t\t\n\t}\n"}, {"source_code": "var str = readline().split(\" \");\nvar n = +str[0]; var s = +str[1];\nvar f = [];\nvar c=0;\n\tfor (var i=0; i<+s; i++){ \n\t f[i]= readline().split(\" \");\n\t}\n\tf.sort((x,y)=>x[0]-y[0]);\n\t\tfor (var i=0; i<+s; i++){\n\t\t\t\t\tif (+f[c][0] dragon) {\n power += bonus;\n k++;\n }\n \n else {\n k = 0;\n }\n}\n\nif (k === 0) {\n print('NO');\n}\nelse {print('YES');}"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[1]), power = Number(s[0]);\n\nvar k = 0, m = 0;\nfor (var i = 0; i dragon) {\n power += bonus;\n k++;\n }\n \n else {\n m++;\n }\n}\n\nif (k < m) {\n print('NO');\n}\nelse {print('YES');}"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[1]), power = Number(s[0]);\n\nvar k = 0, m = 0;\nfor (var i = 0; i= dragon) {\n power += bonus;\n k++;\n }\n \n else {\n m++;\n }\n}\n\nif (k < m) {\n print('NO');\n}\nelse {print('YES');}"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[1]), power = Number(s[0]);\n\nvar k = 0;\nfor (var i = 0; i= dragon) {\n power += bonus;\n k++;\n }\n \n else {\n k = 0;\n }\n}\n\nif (k === 0) {\n print('NO');\n}\nelse {print('YES');}"}, {"source_code": "var input = readline().split(' ');\n\nvar s = +input[0];\nvar n = +input[1];\n\nvar Dragon = function(data) {\n this.x = +data[0];\n this.y = +data[1];\n};\n\nvar dragons = [];\nfor (var i = 0; i < n; ++i) {\n dragons.push(new Dragon(readline().split(' ')));\n}\n\ndragons.sort(function(a, b) {\n return a.x - b.x;\n});\n\nfor (var i = 0; i < dragons.length; ++i) {\n if (s < dragons[i].x) {\n write('NO');\n quit();\n }\n s += dragons[i].y;\n}\n\nwrite('YES');"}, {"source_code": "var s = parseInt(readline().split(' ')[0]);\nvar dragons = readline().split(' ').map(x => parseInt(x));\nvar bonuses = readline();\nif (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));\nvar pairs = []\nfor (var j = 0; j < dragons.length; j++) {\n if (bonuses) pairs.push(dragons[j], bonuses[j]);\n else pairs.push(dragons[j], 0);\n}\npairs.sort((a,b) => a[0] - b[0]);\nvar statement = 'YES';\nfor (var i = 0; i < dragons.length; i++) {\n if (pairs[i][0] < s) s+=pairs[i][1];\n else {\n statement = 'NO';\n break;\n }\n}\nprint(statement);\n"}, {"source_code": "var s = parseInt(readline().split(' ')[0]);\nvar dragons = readline().split(' ').map(x => parseInt(x));\nvar bonuses = readline();\nif (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));\nvar pairs = []\nfor (var j = 0; j < dragons.length; j++) {\n if (bonuses) pairs.push([dragons[j], bonuses[j]]);\n else pairs.push([dragons[j], 0]);\n}\npairs.sort((a,b) => a[0] - b[0]);\nvar statement = 'YES';\nfor (var i = 0; i < pairs.length; i++) {\n if (pairs[i][0] < s) s+=pairs[i][1];\n else {\n statement = 'NO';\n break;\n }\n}\nprint(statement);\n"}, {"source_code": "var s = parseInt(readline().split(' ')[0]);\nvar dragons = [];\nwhile (true) {\n var input = readline();\n if (!input) break;\n dragons.push(input.split(' ').map(x => parseInt(x)));\n}\nvar statement = 'YES';\nfor (var i = 0; i < dragons.length; i++) {\n if (dragons[i][0] < s) s+= dragons[i][1]\n else {\n statement = 'NO';\n break;\n }\n}\nprint(statement);\n"}, {"source_code": "var s = parseInt(readline().split(' ')[0]);\nvar dragons = readline().split(' ').map(x => parseInt(x));\nvar bonuses = readline();\nif (bonuses) bonuses = bonuses.split(' ').map(x => parseInt(x));\nvar statement = 'YES';\nfor (var i = 0; i < dragons.length; i++) {\n if (dragons[i] < s) {\n if (bonuses) s+=bonuses[i];\n } else {\n statement = 'NO';\n break;\n }\n}\nprint(statement);\n"}, {"source_code": "var args = readline().split(' ').map(parseInt);\nvar s = args[0];\nvar n = args[1];\nvar i = 0;\nfor (i = 0; i < n; i++) {\n args = readline().split(' ').map(parseInt);\n if (s > args[0]) {\n s += args[1];\n }\n else {\n s = -1;\n break;\n }\n}\n\nif (s == -1)\n print('NO');\nelse\n print('YES');\n\n\n"}, {"source_code": "var args = readline().split(' ').map(function(x) {return parseInt(x)});\nvar s = args[0];\nvar n = args[1];\nvar i = 0;\nfor (i = 0; i < n; i++) {\n args = readline().split(' ').map(function(x) {return parseInt(x)});\n if (s > args[0]) {\n s += args[1];\n }\n else {\n s = -1;\n break;\n }\n}\n\nif (s == -1)\n print('NO');\nelse\n print('YES');\n"}, {"source_code": "\nvar l=readline().split(' ');\nvar s=+l[0];\nvar n=+l[1];\nvar a=[];\nfor(var i=0;i x){\n\t\ts += y;\n\t}\n\telse{\n\t\twrite(\"NO\");\n\t\tbreak;\n\t}\n}\n\nif(i == n){\n\twrite(\"YES\");\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readIntArray() {\n return readline()\n .split(' ')\n .map((num) => parseInt(num));\n}\n\nfunction readFloatArray() {\n return readline()\n .split(' ')\n .map((num) => parseFloat(num));\n}\n\n/*=====================START CODING HERE=====================*/\n\n// DONT FUCK WITH THE MAIN FUNCTION !!\nfunction main() {\n let [s, n] = readIntArray();\n\n let levels = [];\n\n while (n-- > 0) {\n levels.push(readIntArray());\n }\n\n levels.sort((a, b) => {\n if (a[0] === b[0]) {\n return 0;\n } else {\n return a[0] < b[0] ? -1 : 1;\n }\n });\n\n levels.forEach((match) => {\n let [d, b] = match;\n\n if (s <= d) {\n console.log('NO');\n return;\n } else {\n s += b;\n }\n });\n\n console.log('YES');\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readIntArray() {\n return readline()\n .split(' ')\n .map((num) => parseInt(num));\n}\n\nfunction readFloatArray() {\n return readline()\n .split(' ')\n .map((num) => parseFloat(num));\n}\n\n/*=====================START CODING HERE=====================*/\n\n// DONT FUCK WITH THE MAIN FUNCTION !!\nfunction main() {\n let [s, n] = readIntArray();\n\n let levels = [];\n\n while (n-- > 0) {\n levels.push(readIntArray());\n }\n\n levels.sort((a, b) => a[0] - b[0]);\n\n levels.forEach((match) => {\n let [d, b] = match;\n\n if (s < d) {\n console.log('NO');\n return;\n } else {\n s += b;\n }\n });\n\n console.log('YES');\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readIntArray() {\n return readline()\n .split(' ')\n .map((num) => parseInt(num));\n}\n\nfunction readFloatArray() {\n return readline()\n .split(' ')\n .map((num) => parseFloat(num));\n}\n\n/*=====================START CODING HERE=====================*/\n\n// DONT FUCK WITH THE MAIN FUNCTION !!\nfunction main() {\n let [s, n] = readIntArray();\n\n let levels = [];\n\n while (n-- > 0) {\n levels.push(readIntArray());\n }\n\n levels.sort((a, b) => a[0] - b[0]);\n\n levels.forEach((match) => {\n let [d, b] = match;\n\n if (s <= d) {\n console.log('NO');\n return;\n } else {\n s += b;\n }\n });\n\n console.log('YES');\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readIntArray() {\n return readline()\n .split(' ')\n .map((num) => parseInt(num));\n}\n\nfunction readFloatArray() {\n return readline()\n .split(' ')\n .map((num) => parseFloat(num));\n}\n\n/*=====================START CODING HERE=====================*/\n\n// DONT FUCK WITH THE MAIN FUNCTION !!\nfunction main() {\n let [s, n] = readIntArray();\n\n let levels = [];\n\n while (n-- > 0) {\n levels.push(readIntArray());\n }\n\n levels.sort((a, b) => a[0] - b[0]);\n\n levels.forEach((match) => {\n if (s <= match[0]) {\n console.log('NO');\n return;\n } else {\n s += match[1];\n }\n });\n\n console.log('YES');\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet Ks = 0;\nlet Ds = 0;\n\n// Read Inputs\nrl.on('line', inputLine => {\n const inputs = inputLine.split(' ');\n\n if (!secondLine) {\n Ks = parseInt(inputs[0]);\n secondLine = true;\n return 0\n } else {\n Ds = parseInt(inputs[0]);\n bonus = parseInt(inputs[1]);\n if (Ks > Ds) {\n Ks += bonus;\n return console.log(\"YES\")\n }\n else {\n return console.log(\"NO\")\n }\n }\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let bonus = 0;\n let Ds = 0;\n\n // Fight and gain some strength\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n Ds = parseInt(dragon[0]);\n bonus = parseInt(dragon[1]);\n if (Ks >= Ds) {\n Ks += bonus;\n }\n }\n\n // Can I move on\n if(Ks >= inputs[n].split(' ')[0]) {\n return console.log(\"YES\");\n } else {\n return console.log(\"NO\");\n }\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let bonus = 0;\n let Ds = 0;\n\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n Ds = parseInt(dragon[0]);\n bonus = parseInt(dragon[1]);\n if (Ks > Ds) {\n Ks += bonus;\n } else {\n return console.log(\"NO\")\n }\n }\n\n return console.log(\"YES\");\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet Ks = 0;\nlet Ds = 0;\nlet n = 1;\n\n// Read Inputs\nrl.on('line', inputLine => {\n const inputs = inputLine.split(' ');\n\n if (n > 0) {\n if (!secondLine) {\n Ks = parseInt(inputs[0]);\n n = parseInt(inputs[1]);\n secondLine = true;\n return\n } else {\n Ds = parseInt(inputs[0]);\n bonus = parseInt(inputs[1]);\n n--;\n if (Ks > Ds) {\n Ks += bonus;\n return console.log(\"YES\")\n }\n else {\n return console.log(\"NO\")\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet Ks = 0;\nlet Ds = 0;\n\n// Read Inputs\nrl.on('line', inputLine => {\n const inputs = inputLine.split(' ');\n\n if (!secondLine) {\n Ks = parseInt(inputs[0]);\n secondLine = true;\n return\n } else {\n Ds = parseInt(inputs[0]);\n bonus = parseInt(inputs[1]);\n if (Ks > Ds) {\n Ks += bonus;\n return console.log(\"YES\")\n }\n else {\n return console.log(\"NO\")\n }\n }\n return console.log(\"NO\")\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n const dragons = [];\n let bonus = 0;\n let Ds = 0;\n\n // Fight and gain some strength\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n Ds = parseInt(dragon[0]);\n dragons.push(Ds);\n bonus = parseInt(dragon[1]);\n if (Ks >= Ds) {\n Ks += bonus;\n }\n }\n\n // Can I move on\n if(Ks >= Math.max(...dragons)) {\n return console.log(\"YES\");\n } else {\n return console.log(\"NO\");\n }\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let bonus = 0;\n let Ds = 0;\n\n // Fight and gain some strength\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n Ds = parseInt(dragon[0]);\n bonus = parseInt(dragon[1]);\n if (Ks > Ds) {\n Ks += bonus;\n }\n }\n\n // Can I move on\n if(Ks > inputs[n].split(' ')[0]) {\n return console.log(\"YES\");\n } else {\n return console.log(\"NO\");\n }\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet Ks = 0;\nlet Ds = 0;\nlet n = 1;\n\n// Read Inputs\nrl.on('line', inputLine => {\n const inputs = inputLine.split(' ');\n\n if (n > 0) {\n if (!secondLine) {\n Ks = parseInt(inputs[0]);\n n = parseInt(inputs[1]);\n secondLine = true;\n n--;\n return\n } else {\n Ds = parseInt(inputs[0]);\n bonus = parseInt(inputs[1]);\n n--;\n if (Ks > Ds) {\n Ks += bonus;\n return console.log(\"YES\")\n }\n else {\n return console.log(\"NO\")\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let Ks = parseInt(line1[0]);\n let n = parseInt(line1[1]);\n let bonus = 0;\n let Ds = 0;\n\n for (let i = 1; i < n + 1; i++) {\n let dragon = inputs[i].split(' ');\n Ds = parseInt(dragon[0]);\n bonus = parseInt(dragon[1]);\n if (Ks > Ds) {\n Ks += bonus;\n } else {\n return console.log(\"NO\")\n }\n }\n\n return console.log(\"Yes\");\n\n});"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [s, n] = input[0].split(' ').map(x => parseInt(x));\n const dragons = [];\n\n input.forEach((x, i) => {\n if (i === 0) return;\n const nums = x.split(' ').map(x => parseInt(x));\n dragons.push([\n nums[0], nums[1],\n ]);\n });\n\n dragons.sort((a, b) => a[0]-b[0]);\n dragons.forEach(d => {\n if (d[0] <= s) {\n s += d[1];\n } else {\n console.log('NO'); process.exit();\n }\n });\n\n console.log('YES');\n});\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [s, n] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\tlet canGoNext = true;\n\n\twhile (n--) {\n\t\tlet [x, y] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(item => parseInt(item));\n\n\t\tif (s >= x) {\n\t\t\ts = s + y;\n\t\t} else {\n\t\t\tcanGoNext = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tcanGoNext ? console.log('YES') : console.log('NO');\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [s, n] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\tlet canGoNext = true;\n\n\twhile (n--) {\n\t\tlet [x, y] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(item => parseInt(item));\n\n\t\tif (s >= x) {\n\t\t\ts = s - x + y;\n\t\t} else {\n\t\t\tcanGoNext = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tcanGoNext ? console.log('YES') : console.log('NO');\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [s, n] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\tlet canGoNext = true;\n\tlet dragons = [];\n\n\twhile (n--) {\n\t\tlet [x, y] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(item => parseInt(item));\n\t\tdragons.push([x, y]);\n\t}\n\n\tdragons.sort((a, b) => a[0] - b[0]);\n\n\tfor (let i = 0, l = dragons.length; i < l; ++i) {\n\t\tif (s >= dragons[i][0]) {\n\t\t\ts = s + dragons[i][1];\n\t\t} else {\n\t\t\tcanGoNext = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tcanGoNext ? console.log('YES') : console.log('NO');\n}\n"}], "src_uid": "98f5b6aac08f48f95b2a8ce0738de657"} {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(num => parseInt(num, 10));\n equalRectangles(input);\n count += 2;\n }\n});\n\nfunction equalRectangles(rectangles) {\n rectangles = rectangles.sort((a, b) => a - b);\n const targetArea = rectangles[rectangles.length - 1] * rectangles[0];\n\n let leftIndex = 0;\n let rightIndex = rectangles.length - 1;\n while (leftIndex < rightIndex) {\n if (rectangles[leftIndex] * rectangles[rightIndex] !== targetArea ||\n rectangles[leftIndex + 1] * rectangles[rightIndex - 1] !== targetArea) {\n console.log('NO');\n return;\n }\n if (rectangles[leftIndex] !== rectangles[leftIndex + 1] ||\n rectangles[rightIndex] !== rectangles[rightIndex - 1]) {\n console.log('NO');\n return;\n }\n leftIndex += 2;\n rightIndex -= 2;\n }\n\n console.log('YES');\n}\n", "positive_code": [{"source_code": "if (process.env.ANT)\n{\n global.print = this.print || function(){console.log([...arguments].join(' '))} || require('lol-io').print\n global.write = this.write || require('lol-io').write\n global.readline = this.readline || require('lol-io').readline\n main();\n}\nelse\n{\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n global.print = console.log\n global.write = (...args) => {\n process.stdout.write(args.join(' '));\n }\n const lines = []\n rl.on('line', line =>{\n lines.push(line);\n });\n rl.on('close', main)\n let rli = 0;\n global.readline = ()=>lines[rli++];\n}\n\nfunction main(){\n\n var q = +readline();\n\n function fun(n, arr){\n arr.sort((a, b)=>a-b);\n const square = arr[0]*arr[arr.length-1];\n for (let i=0; i+n);\n print(fun(n, arr) ? 'YES' : 'NO');\n }\n\n}\n\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, n) {\n data.sort((a, b) => b - a);\n\n\n //console.log(JSON.stringify(data));\n let squares = [];\n\n for (let i = 1; i <= n; i++) {\n let x1 = data.shift();\n let x2 = data.shift();\n\n //console.log(x1, x2)\n if (x1 !== x2) return false;\n\n let y1 = data.pop();\n let y2 = data.pop();\n if (y1 !== y2) return false;\n squares.push(x1 * y1);\n }\n\n //console.log(squares);\n\n return Math.min(...squares) === Math.max(...squares);\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n //console.log(data);\n //console.log(n);\n let result = foo(data, n);\n answer += (result ? \"YES\" : \"NO\") +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "'use strict'\n\nlet q = parseInt(readline())\n\nwhile (q --> 0) {\n \n let n = parseInt(readline())\n n = n * 4\n \n const freq = {}\n let arr = readline().split(' ').map(function (x) {\n return parseInt(x)\n })\n\n for (let i in arr) {\n if (freq.hasOwnProperty(arr[i])) {\n freq[arr[i]] ++\n } else {\n freq[arr[i]] = 1\n }\n }\n \n arr.sort((a, b) => a - b)\n const mx = arr.slice(arr.length - 1)\n \n const area = arr[0] * mx\n let ok = true\n \n for (let cur in freq) {\n const other = area / cur\n if (freq[cur] !== freq[other] || freq[cur] % 2 !== 0 || freq[other] % 2 !== 0) {\n ok = false\n break\n }\n }\n \n print(ok ? 'YES': 'NO')\n}\n"}, {"source_code": "'use strict'\n\nconst rectangle = (n, a) => {\n const d = {};\n for (let i = 0; i < 4 * n; i++) {\n d[a[i]] = (d[a[i]] || 0) + 1;\n }\n const l = Object.keys(d).sort((x, y) => x - y);\n const len = l.length;\n const s = l[0] * l[len - 1];\n for (let i = 0; i < len / 2; i++) {\n if (s !== l[i] * l[len - 1 - i]) return 'NO';\n if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';\n if (d[l[i]] % 2) return 'NO';\n }\n return 'YES';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' '), area = 0, valid = true;\n \n for(var j=0; j<4*n; j++) {\n a[j] = parseInt(a[j], 10);\n }\n \n a.sort((a,b) => a-b);\n \n area = a[0] * a[4*n-1];\n \n for(var j=0; j<2*n; j+=2) {\n if((a[j] * a[4*n-1-j]) === area && a[j] === a[j+1] && a[4*n-1-j] === a[4*n-j-2]) continue;\n else {\n valid = false;\n break;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}], "negative_code": [{"source_code": "'use strict'\n\nlet q = parseInt(readline())\n\nwhile (q --> 0) {\n \n let n = parseInt(readline())\n n = n * 4\n \n const freq = {}\n let arr = readline().split(' ').map(function (x) {\n return parseInt(x)\n })\n\n for (let i in arr) {\n if (freq.hasOwnProperty(arr[i])) {\n freq[arr[i]] ++\n } else {\n freq[arr[i]] = 1\n }\n }\n \n arr.sort((a, b) => a - b)\n const mx = arr.slice(arr.length - 1)\n \n const area = arr[0] * mx\n let ok = true\n \n for (let cur in freq) {\n const other = area / cur\n if (freq[cur] % 2 !== 0 || freq[other] % 2 !== 0) {\n ok = false\n break\n }\n }\n \n print(ok ? 'YES': 'NO')\n}\n"}, {"source_code": "'use strict'\n\nlet q = parseInt(readline())\n\nwhile (q --> 0) {\n \n let n = parseInt(readline())\n n = n * 4\n \n const freq = {}\n let arr = readline().split(' ').map(function (x) {\n return parseInt(x)\n })\n\n for (let i in arr) {\n if (freq.hasOwnProperty(arr[i])) {\n freq[arr[i]] ++\n } else {\n freq[arr[i]] = 1\n }\n }\n \n arr.sort((a, b) => a - b)\n const mx = arr.slice(arr.length - 1)\n \n let ok = true\n for (let i = n - 1; i >= 0; --i) {\n if (mx % arr[i] !== 0) {\n ok = false\n break\n }\n }\n \n const area = arr[0] * mx\n \n for (let i = 0; i < n && ok; ++i) {\n if (freq[arr[i]] === 0) continue\n const other = area / arr[i]\n \n if (freq[arr[i]] < 2 || freq[other] < 2) {\n ok = false\n } else {\n freq[arr[i]] -= 2\n freq[other] -= 2\n }\n }\n \n print(ok ? 'YES': 'NO')\n}\n"}, {"source_code": "'use strict'\n\nconst rectangle = (n, a) => {\n const d = {};\n for (let i = 0; i < 4 * n; i++) {\n d[a[i]] = (d[a[i]] || 0) + 1;\n }\n const l = Object.keys(d).sort((x, y) => x - y);\n const len = l.length;\n const s = l[0] * l[len - 1];\n for (let i = 0; i < len / 2; i++) {\n if (s !== l[i] * l[len - 1 - i]) return 'NO';\n if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';\n }\n return 'YES';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}, {"source_code": "'use strict'\n\n\nconst rectangle = (n, a) => {\n const d = {};\n for (let i = 0; i < n; i++) {\n d[a[i]] = (d[a[i]] || 0) + 1;\n }\n const l = Object.keys(d).sort((x, y) => x - y);\n const len = l.length;\n const s = l[0] * l[len - 1];\n for (let i = 0; i < len / 2; i++) {\n if (s !== l[i] * l[len - 1 - i]) return 'NO';\n if (d[l[i]] !== d[l[len - 1 - i]]) return 'NO';\n }\n return 'YES';\n}\n\nconst q = parseInt(readline());\nfor (let i = 0; i < q; i++) {\n write(rectangle(parseInt(readline()), readline().split(' ').map(Number)) + '\\n');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' '), area = 0, valid = true;\n \n for(var j=0; j<4*n; j++) {\n a[j] = parseInt(a[j], 10);\n }\n \n a.sort((a,b) => a-b);\n \n for(var j=0; j<2*n; j+=2) {\n if(j===0) {\n area = (a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j-1]);\n } else {\n if((a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j-1]) !== area) valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' '), area = 0, valid = true;\n \n for(var j=0; j<4*n; j++) {\n a[j] = parseInt(a[j], 10);\n }\n \n a.sort((a,b) => a-b);\n \n for(var j=0; j<2*n; j+=2) {\n if(j===0) {\n area = (a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j]);\n } else {\n if((a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j]) !== area) valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' '), area = 0, valid = true;\n \n for(var j=0; j<4*n; j++) {\n a[j] = parseInt(a[j], 10);\n }\n \n a.sort((a,b) => a-b);\n \n for(var j=0; j<2*n; j+=2) {\n if(j===0) {\n area = a[j] * a[4*n-1-j];\n } else {\n if(a[j] * a[4*n-1-j] == area && a[j] == a[j+1] && a[4*n-1-j] == a[4*n-1-j-1]) continue;\n else {\n valid = false;\n break;\n }\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10);\n var a = readline().split(' '), area = 0, valid = true;\n \n for(var j=0; j<4*n; j++) {\n a[j] = parseInt(a[j], 10);\n }\n \n a.sort((a,b) => a-b);\n \n for(var j=0; j<2*n; j+=2) {\n if(j===0) {\n area = (a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j]);\n } else {\n if((a[j] * a[j+1] * a[4*n-1-j] * a[4*n-1-j-1]) / (a[j] * a[4*n-1-j]) !== area || a[j] !== a[j+1] || a[4*n-1-j] !== a[4*n-1-j-1]) valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n\n function can1 (data) {\n return data.reduce((agr, value, index, array) => {\n if (!agr) return false;\n if (index === array.length - 1) return agr;\n return value === array[index + 1] - 1 || array[index + 1] === 1;\n }, true);\n }\n\n function can0 (data) {\n return data.reduceRight((agr, value, index, array) => {\n if (!agr) return false;\n if (index === 0) return agr;\n return value === array[index - 1] - 1 || array[index - 1] === 1;\n }, true);\n }\n\n return can1(data) || can0(data);\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n //console.log(data);\n let result = foo(data);\n answer += (result ? \"YES\" : \"NO\") +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, n) {\n data.sort((a, b) => a < b);\n\n\n //console.log(data);\n let squares = [];\n\n for (let i = 1; i <= n; i++) {\n let x1 = data.shift();\n let x2 = data.shift();\n if (x1 !== x2) return false;\n\n let y1 = data.pop();\n let y2 = data.pop();\n if (y1 !== y2) return false;\n squares.push(x1 * y1);\n }\n\n //console.log(squares);\n\n return Math.min(...squares) === Math.max(...squares);\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let n = lines[testCount * 2 - 1].split(\" \").map(Number);\n\n //console.log(data);\n //console.log(n);\n let result = foo(data, n);\n answer += (result ? \"YES\" : \"NO\") +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(num => parseInt(num, 10));\n equalRectangles(input);\n count += 2;\n }\n});\n\nfunction equalRectangles(rectangles) {\n const map = new Map();\n for (const rect of rectangles) {\n if (map.get(rect)) {\n map.set(rect, map.get(rect) + 1);\n } else {\n map.set(rect, 1);\n }\n }\n\n if (map.size === 1) {\n console.log('YES');\n return;\n }\n\n const keys = Array.from(map.keys()).sort((a, b) => a - b);\n const targetArea = keys[0] * keys[keys.length - 1];\n\n let leftIndex = 0;\n let rightIndex = keys.length - 1;\n\n while (leftIndex < rightIndex) {\n if (keys[leftIndex] * keys[rightIndex] === targetArea &&\n map.get(keys[leftIndex]) === map.get(keys[rightIndex]) &&\n map.get(keys[leftIndex]) % 2 === 0) {\n leftIndex++;\n rightIndex--;\n } else {\n console.log('NO');\n return;\n }\n }\n\n if (leftIndex === rightIndex) {\n if (map.get(leftIndex) % 4 === 0) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n } else {\n console.log('YES');\n }\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(num => parseInt(num, 10));\n equalRectangles(input);\n count += 2;\n }\n});\n\nfunction equalRectangles(rectangles) {\n const map = new Map();\n for (const rect of rectangles) {\n if (map.get(rect)) {\n map.set(rect, map.get(rect) + 1);\n } else {\n map.set(rect, 1);\n }\n }\n\n if (map.size === 1) {\n console.log('YES');\n return;\n }\n\n const keys = Array.from(map.keys()).sort((a, b) => a - b);\n const targetArea = keys[0] * keys[keys.length - 1];\n\n let leftIndex = 0;\n let rightIndex = keys.length - 1;\n\n while (leftIndex <= rightIndex) {\n if (leftIndex === rightIndex) {\n if (map.get(leftIndex) % 4 === 0) {\n console.log('YES');\n return;\n } else {\n console.log('NO');\n return;\n }\n } else {\n if (keys[leftIndex] * keys[rightIndex] === targetArea &&\n map.get(keys[leftIndex]) === map.get(keys[rightIndex])) {\n leftIndex++;\n rightIndex--;\n } else {\n console.log('NO');\n return;\n }\n }\n }\n console.log('YES');\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(num => parseInt(num, 10));\n equalRectangles(input);\n count += 2;\n }\n});\n\nfunction equalRectangles(rectangles) {\n const map = new Map();\n for (const rect of rectangles) {\n if (map.get(rect)) {\n map.set(rect, map.get(rect) + 1);\n } else {\n map.set(rect, 1);\n }\n }\n\n if (map.size === 1) {\n console.log('YES');\n return;\n }\n\n const keys = Array.from(map.keys()).sort((a, b) => a - b);\n const targetArea = keys[0] * keys[keys.length - 1];\n\n let leftIndex = 0;\n let rightIndex = keys.length - 1;\n\n while (leftIndex < rightIndex) {\n if (leftIndex === rightIndex) {\n if (map.get(leftIndex) % 4 === 0) {\n console.log('YES');\n return;\n } else {\n console.log('NO');\n return;\n }\n } else {\n if (keys[leftIndex] * keys[rightIndex] === targetArea &&\n map.get(keys[leftIndex]) === map.get(keys[rightIndex])) {\n leftIndex++;\n rightIndex--;\n } else {\n console.log('NO');\n return;\n }\n }\n }\n console.log('YES');\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let count = 2;\n while (count < lines.length) {\n let input = lines[count].split(' ');\n input = input.map(num => parseInt(num, 10));\n equalRectangles(input);\n count += 2;\n }\n});\n\nfunction equalRectangles(rectangles) {\n rectangles = rectangles.sort((a, b) => a - b);\n const targetArea = rectangles[rectangles.length - 1] * rectangles[0];\n\n let leftIndex = 0;\n let rightIndex = rectangles.length - 1;\n while (leftIndex < rightIndex) {\n if (rectangles[leftIndex++] * rectangles[rightIndex--] !== targetArea ||\n rectangles[leftIndex++] * rectangles[rightIndex--] !== targetArea) {\n console.log('NO');\n return;\n }\n }\n\n console.log('YES');\n}\n"}], "src_uid": "08783e3dff3f3b7eb586931f9d0cd457"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n // (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim()\n .split(' ')\n .map(Number)\n const edges = lines.slice(l, l + m)\n .map(str => str.trim()\n .split(' ')\n .map(Number))\n l += m\n l++\n const vs = lines[l++].trim()\n .split(' ')\n .map(Number)\n l++\n const indexes = lines[l++].trim()\n .split(' ')\n .map(Number)\n output[i] = solve(n, edges, vs, indexes)\n }\n console.log(output.join('\\n'))\n // })()\n})\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n getLast() {\n return this.map[this.last]\n }\n forEach(fn) {\n for (let i = this.first; i <= this.last; i++) {\n fn(this.map[i], i - this.first)\n }\n }\n}\n\nfunction solve(n, edges, vs, indexes) {\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n const ms = {} // v -> mask\n indexes.forEach((idx, i) => {\n idx--\n const v = vs[idx]\n ms[v] = (ms[v] || 0) | (1 << i)\n })\n const count = Array(64)\n for (let h = 0; h < 64; h++) {\n count[h] = 0\n for (let j = 0; j < 6; j++) {\n if (h & (1 << j)) count[h]++\n }\n }\n// console.log(car)\n //\n const dp = Array(n + 1)\n bfs(1)\n // console.log(ms)\n // console.log(dp)\n //\n // let prev = Array(n + 1).fill(0)\n // const rm = ms[1] || 0\n // for (let h = 0; h < 64; h++) {\n // prev[h] = (h & rm) === h ? 1 : 0\n // }\n let prev = Array(64).fill(0)\n prev[0] = 1\n for (let i = 0; i < vs.length; i++) {\n const u = vs[i]\n // for (let u = 1; u <= n; u++) {\n const mask = ms[u] || 0\n if (indexes.indexOf(i + 1) >= 0) continue // no car\n const ans = prev.slice()\n for (let x = 0; x < 64; x++) {\n if (!dp[u][x]) continue\n for (let y = 0; y < 64; y++) {\n ans[x | y] |= prev[y]\n }\n }\n prev = ans\n // console.log(u, prev)\n }\n let res = 0\n for (let h = 0; h < 64; h++) {\n if (prev[h]) {\n res = Math.max(res, count[h])\n }\n // res = Math.max(res, prev[h])\n }\n return indexes.length - res\n\n function bfs(r) {\n let q = new Queue()\n q.push(r)\n const visited = Array(n + 1)\n .fill(Infinity) // for small n\n dp[r] = dp[r] || Array(64)\n .fill(0)\n visited[r] = 0\n let d = 1\n while (q.length) {\n const nq = new Queue()\n // eslint-disable-next-line no-loop-func\n q.forEach(u => {\n // if (visited[u]) return\n // dp[u] = Array(64)\n ;(adj[u] || []).forEach(v => {\n if (visited[v] < d) return\n\n const mask = (ms[v] || 0)\n dp[v] = dp[v] || Array(64).fill(0)\n for (let h = 0; h < dp[v].length; h++) {\n if ((h & mask) === h) {\n dp[v][h] = 1\n }\n dp[v][h] |= dp[u][h]\n dp[v][h | mask] |= dp[u][h]\n }\n // if (v === 4) {\n // console.log(dp[u], dp[v])\n // }\n\n if (visited[v] > d) {\n nq.push(v)\n }\n visited[v] = d\n })\n })\n q = nq\n d++\n }\n // console.log(visited)\n }\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n m = rn();\r\n const h = new Array(n).fill(-1),\r\n te = [],\r\n ne = [];\r\n const add = (i, j) => (te.push(j), ne.push(h[i]), h[i] = ne.length - 1);\r\n for (let i = 0; i < m; i++) {\r\n const [u, v] = rns(2);\r\n add(u - 1, v - 1);\r\n add(v - 1, u - 1);\r\n }\r\n const FOR = (u, f) => {\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = te[i];\r\n f(v);\r\n }\r\n };\r\n const f = rn(),\r\n a = rns(f).map(num => num - 1),\r\n map = new Map();\r\n for (let i = 0; i < f; i++) {\r\n if (!map.has(a[i])) map.set(a[i], new Set());\r\n map.get(a[i]).add(i);\r\n }\r\n const k = rn(),\r\n b = rns(k).map(num => num - 1);\r\n new Set(b.map(i => a[i]));\r\n const set1 = new Set(b),\r\n ff = new Array(n).fill(0);\r\n for (let i = 0; i < k; i++) {\r\n ff[a[b[i]]] |= 1 << i;\r\n }\r\n const states = Array.from({\r\n length: n\r\n }, () => new Set());\r\n {\r\n const dist = new Array(n).fill(Infinity);\r\n const queue = [0];\r\n dist[0] = 0;\r\n states[0].add(0);\r\n for (let u of queue) {\r\n FOR(u, v => {\r\n if (dist[v] >= dist[u] + 1) {\r\n for (let state of states[u]) {\r\n states[v].add(state | ff[v]);\r\n }\r\n }\r\n if (dist[v] <= dist[u] + 1) return;\r\n dist[v] = dist[u] + 1;\r\n add(u, v);\r\n queue.push(v);\r\n });\r\n }\r\n }\r\n const dp = Array.from({\r\n length: f\r\n }, () => new Set());\r\n let pre = -1;\r\n {\r\n for (let i = 0; i < f; i++) {\r\n if (set1.has(i)) continue;\r\n for (let state of states[a[i]]) {\r\n dp[i].add(state);\r\n if (pre !== -1) {\r\n for (let p of dp[pre]) {\r\n dp[i].add(p | state);\r\n }\r\n }\r\n }\r\n pre = i;\r\n }\r\n }\r\n let res = k;\r\n {\r\n const cnt = new Array(1 << k).fill(0);\r\n for (let i = 0; i < 1 << k; i++) {\r\n for (let j = 0; j < k; j++) if (i & 1 << j) cnt[i]++;\r\n }\r\n for (let j of (_dp$pre = dp[pre]) !== null && _dp$pre !== void 0 ? _dp$pre : []) {\r\n var _dp$pre;\r\n res = Math.min(res, k - cnt[j]);\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n // (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = lines[l++].trim()\r\n .split(' ')\r\n .map(Number)\r\n const edges = lines.slice(l, l + m)\r\n .map(str => str.trim()\r\n .split(' ')\r\n .map(Number))\r\n l += m\r\n l++\r\n const vs = lines[l++].trim()\r\n .split(' ')\r\n .map(Number)\r\n l++\r\n const indexes = lines[l++].trim()\r\n .split(' ')\r\n .map(Number)\r\n output[i] = solve(n, edges, vs, indexes)\r\n }\r\n console.log(output.join('\\n'))\r\n // })()\r\n})\r\nclass Queue {\r\n constructor() {\r\n this.map = {}\r\n this.first = 0\r\n this.last = -1\r\n }\r\n push(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[++this.last] = args[i]\r\n }\r\n }\r\n unshift(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[--this.first] = args[i]\r\n }\r\n }\r\n pop() {\r\n const r = this.map[this.last]\r\n delete this.map[this.last]\r\n this.last--\r\n return r\r\n }\r\n shift() {\r\n const r = this.map[this.first]\r\n delete this.map[this.first]\r\n this.first++\r\n return r\r\n }\r\n get length() {\r\n if (this.first > this.last) return 0\r\n return this.last - this.first + 1\r\n }\r\n getLast() {\r\n return this.map[this.last]\r\n }\r\n forEach(fn) {\r\n for (let i = this.first; i <= this.last; i++) {\r\n fn(this.map[i], i - this.first)\r\n }\r\n }\r\n}\r\n\r\nfunction solve(n, edges, vs, indexes) {\r\n const adj = {}\r\n edges.forEach(([a, b]) => {\r\n adj[a] = adj[a] || []\r\n adj[b] = adj[b] || []\r\n adj[a].push(b)\r\n adj[b].push(a)\r\n })\r\n const car = vs.reduce((o, x, i) => {\r\n if (indexes.indexOf(i + 1) < 0) {\r\n o[x] = 1\r\n }\r\n return o\r\n }, {}) // v -> has car\r\n const ms = {} // v -> mask\r\n indexes.forEach((idx, i) => {\r\n idx--\r\n const v = vs[idx]\r\n ms[v] = (ms[v] || 0) | (1 << i)\r\n })\r\n const count = Array(64)\r\n for (let h = 0; h < 64; h++) {\r\n count[h] = 0\r\n for (let j = 0; j < 6; j++) {\r\n if (h & (1 << j)) count[h]++\r\n }\r\n }\r\n //\r\n const dp = Array(n + 1)\r\n bfs(1)\r\n // console.log(ms)\r\n // console.log(dp)\r\n //\r\n // let prev = Array(n + 1).fill(0)\r\n // const rm = ms[1] || 0\r\n // for (let h = 0; h < 64; h++) {\r\n // prev[h] = (h & rm) === h ? 1 : 0\r\n // }\r\n let prev = Array(64).fill(0)\r\n prev[0] = 1\r\n for (let i = 0; i < vs.length; i++) {\r\n const u = vs[i]\r\n // for (let u = 1; u <= n; u++) {\r\n const mask = ms[u] || 0\r\n if (!car[u]) continue\r\n const ans = prev.slice()\r\n for (let x = 0; x < 64; x++) {\r\n if (!dp[u][x]) continue\r\n for (let y = 0; y < 64; y++) {\r\n ans[x | y] |= prev[y]\r\n }\r\n }\r\n prev = ans\r\n }\r\n // console.log(prev)\r\n let res = 0\r\n for (let h = 0; h < 64; h++) {\r\n if (prev[h]) {\r\n res = Math.max(res, count[h])\r\n }\r\n // res = Math.max(res, prev[h])\r\n }\r\n return indexes.length - res\r\n\r\n function bfs(r) {\r\n let q = new Queue()\r\n q.push(r)\r\n const visited = Array(n + 1)\r\n .fill(Infinity) // for small n\r\n dp[r] = dp[r] || Array(64)\r\n .fill(0)\r\n visited[r] = 0\r\n let d = 1\r\n while (q.length) {\r\n const nq = new Queue()\r\n // eslint-disable-next-line no-loop-func\r\n q.forEach(u => {\r\n // if (visited[u]) return\r\n // dp[u] = Array(64)\r\n ;(adj[u] || []).forEach(v => {\r\n if (visited[v] < d) return\r\n\r\n const mask = (ms[v] || 0)\r\n dp[v] = dp[v] || Array(64).fill(0)\r\n for (let h = 0; h < dp[v].length; h++) {\r\n if ((h & mask) === h) {\r\n dp[v][h] = 1\r\n }\r\n dp[v][h] |= dp[u][h]\r\n dp[v][h | mask] |= dp[u][h]\r\n }\r\n // if (v === 4) {\r\n // console.log(dp[u], dp[v])\r\n // }\r\n\r\n if (visited[v] > d) {\r\n nq.push(v)\r\n }\r\n visited[v] = d\r\n })\r\n })\r\n q = nq\r\n d++\r\n }\r\n // console.log(visited)\r\n }\r\n}\r\n"}], "src_uid": "81122f1a525ac6e80b1d9c2adc735f6f"} {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\n// var inf = 10000000000;\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var ans = 0;\r\n var cnt = 0, cntZ = 0;\r\n for(var i=0;i=0 && a[i] == 0) {\r\n i--;\r\n cntZ++;\r\n }\r\n if(cntZ < cnt) ans = 2;\r\n if(cntZ == cnt) {\r\n if(cnt == n) ans = 0;\r\n else ans = 1;\r\n }\r\n \r\n console.log(ans);\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n if (a[i] === 0) continue;\r\n while (j + 1 < n && a[j + 1] !== 0) j++;\r\n res++;\r\n }\r\n return Math.min(res, 2);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n if (a[i] === 0) continue;\r\n while (j + 1 < n && a[j + 1] !== 0) j++;\r\n res++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n var _a;\r\n if (a[i] === 0) continue;\r\n if (((_a = a[i - 1]) !== null && _a !== void 0 ? _a : 0) === 0) res++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "da3d1b2615d51044a7b43bd0ce939f4c"} {"source_code": "var g = (readline()).split(\" \");\n\nvar x = Number(g[0]);\n\nvar y = Number(g[1]);\n\n\nvar flag = false;\n\n\nvar k = \"\";\n\nvar loop_b = false;\n\nvar mat = [];\nfor(i=0;i= 0 && k[upend][b] == \"*\"){\n\t\t\t if(!Array.isArray(should_be_plus[upend]))\n\t\t\t should_be_plus[upend] = [];\n\t\t\t \n\t\t\t should_be_plus[upend--][b] = true;\n\t\t\t}\n\t\t\twhile(downend < x && k[downend][b] == \"*\"){\n\t\t\t if(!Array.isArray(should_be_plus[downend]))\n\t\t\t should_be_plus[downend] = [];\n\t\t\t \n\t\t\t should_be_plus[downend++][b] = true;\n\t\t\t \n\t\t\t}\n\t\t\twhile(leftend >= 0 && k[i][leftend] == \"*\"){\n\t\t\t if(!Array.isArray(should_be_plus[i]))\n\t\t\t should_be_plus[i] = [];\n\t\t\t \n\t\t\t should_be_plus[i][leftend--] = true;\n\t\t\t \n\t\t\t} \n\t\t\twhile(rightend < y && k[i][rightend] == \"*\"){\n\t\t\t if(!Array.isArray(should_be_plus[i]))\n\t\t\t should_be_plus[i] = [];\n\t\t\t \n\t\t\t should_be_plus[i][rightend++] = true;\n\t\t\t \n\t\t\t}\n\t\t\t\n loop_b = true;\n break;\n }\n }\n if(loop_b)\n break;\n}\n\nloop_b = false;\n\nif(flag){\n for(i=0;i +value);\nvar h = input[0];\nvar w = input[1];\nvar S = [Array(1000).join('.')];\n\nfor (let i = 1; i <= h; ++i) {\n let s = '.' + readline() + '.';\n S[i] = s;\n}\nS.push(Array(1000).join('.'));\n\nvar di = [-1, 0, 1, 0];\nvar dj = [0, 1, 0, -1];\nvar isCenter = function(i, j) {\n for (let k = 0; k < 4; ++k) {\n if (S[i + di[k]][j + dj[k]] !== '*') {\n return false;\n }\n }\n return true;\n};\n\nvar fC = 0;\nvar cI = -1;\nvar cJ = -1;\nfor (let i = 1; i <= h; ++i) {\n for (let j = 1; j <= w; ++j) {\n if (S[i][j] === '*') {\n ++fC;\n if (cI === -1 && cJ === -1 && isCenter(i, j)) {\n cI = i; cJ = j;\n }\n }\n }\n}\n\nvar dfs = function(cI, cJ) {\n var result = 1;\n\n for (let k = 0; k < 4; ++k) {\n var step = 1;\n while (S[cI + di[k]*step][cJ + dj[k]*step] === '*') {\n ++step;\n ++result;\n }\n }\n\n return result;\n};\n\nwrite(cI !== -1 && cJ !== -1 && dfs(cI, cJ) === fC ? 'YES' : 'NO');"}, {"source_code": "const fs = require('fs');\nconst text = fs.readFileSync(0, 'utf8');\nconst lines = text.split('\\n');\nconst [x, y] = lines[0].trim().split(' ').map(a => parseInt(a, 10));\nlet sum = 0;\nconst pic = lines.slice(1, x + 1).map(x => {\n const result = Array.from(x.trim()).map(y => y === '.' ? 0 : 1);\n sum += result.filter(i => i === 1).length;\n return result;\n});\n\n// x\nconst getTop = () => {\n for (let i = 0; i < x; i++) {\n for (let j = 0; j < y; j++) {\n if (pic[i][j]) {\n return [i, j];\n }\n }\n }\n\n return [-1, -1];\n};\nconst [topX1, topY] = getTop();\nif (topX1 === -1) {\n console.log('NO');\n return;\n}\nlet topX2;\nfor (let i = topX1; i < x; i++) {\n if (pic[i][topY]) {\n topX2 = i;\n } else {\n break;\n }\n}\n// y\nconst getLeft = () => {\n for (let j = 0; j < y; j++) {\n for (let i = 0; i < x; i++) {\n if (pic[i][j]) {\n return [i, j];\n }\n }\n }\n\n return [-1, -1];\n};\nconst [leftX, leftY1] = getLeft();\nif (topX1 === -1) {\n console.log('NO');\n return;\n}\nlet leftY2;\nfor (let i = leftY1; i < y; i++) {\n if (pic[leftX][i]) {\n leftY2 = i;\n } else {\n break;\n }\n}\n\nif (leftY2 - leftY1 + topX2 - topX1 + 1 === sum && topY > leftY1 && topY < leftY2 && leftX > topX1 && leftX < topX2) {\n console.log('YES');\n} else {\n console.log('NO');\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nvar n = 0, m = 0, cnt = 0, s = [];\n\nvar solve = function () {\n var vis = []\n for (var i = 0; i < n; i ++) { var tmp = []; for (var j = 0; j < m; j ++) tmp.push(false); vis.push(tmp); }\n var cc = 0, sx, sy;\n for (var i = 1; i+1 < n; i ++) {\n for (var j = 1; j+1 < m; j ++) {\n if (s[i][j] == '*' && s[i][j+1] == '*' && s[i][j-1] == '*' && s[i+1][j] == '*' && s[i-1][j] == '*') {\n cc ++;\n sx = i; sy = j;\n }\n }\n }\n // console.log(`cc == ${cc}`);\n if (cc != 1) return \"NO\";\n for (var j = sy; j >= 0; j --) if (s[sx][j] == '*') vis[sx][j] = true; else break;\n for (var j = sy; j < m; j ++) if (s[sx][j] == '*') vis[sx][j] = true; else break;\n for (var i = sx; i >= 0; i --) if (s[i][sy] == '*') vis[i][sy] = true; else break;\n for (var i = sx; i < n; i ++) if (s[i][sy] == '*') vis[i][sy] = true; else break;\n for (var i = 0; i < n; i ++) {\n for (var j = 0; j < m; j ++) {\n if (s[i][j] == '*' && !vis[i][j]) return \"NO\";\n }\n }\n return \"YES\";\n}\n\nrl.on(\"line\", (line) => {\n if (n == 0) {\n var tmp = line.split(' ');\n n = parseInt(tmp[0]);\n m = parseInt(tmp[1]);\n }\n else {\n cnt ++;\n s.push(line);\n if (cnt >= n) {\n console.log( solve() );\n rl.close();\n }\n }\n});"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var m = line[1];\n var arr = [];\n\n for(var i = 0; i < n; i++) \n arr[i] = read.arr();\n \n var checked = false;\n for(var i = 1; i < n - 1; i++) {\n for(var j = 1; j < m - 1; j++) {\n if(\n !checked \n && arr[i][j] === '*' \n && arr[i][j + 1] === '*' \n && arr[i][j - 1] === '*' \n && arr[i + 1][j] === '*' \n && arr[i - 1][j] === '*'\n ) {\n checked = true;\n arr[i][j] = '.';\n \n var t = j + 1;\n while(arr[i][t] === '*') {\n arr[i][t] = '.';\n t++;\n }\n \n t = j - 1;\n while(arr[i][t] === '*') {\n arr[i][t] = '.';\n t--;\n }\n \n t = i + 1;\n while(arr[t][j] === '*') {\n arr[t][j] = '.';\n if(t < n - 1)\n t++;\n }\n \n t = i - 1;\n while(arr[t][j] === '*') {\n arr[t][j] = '.';\n if(t > 0)\n t--;\n \n }\n break;\n }\n }\n if(checked) {\n break;\n }\n }\n\n\n for(var i = 0; i < n; i++) {\n if(arr[i].indexOf('*') !== -1 || !checked) {\n print('NO');\n return;\n }\n }\n \n print('YES');\n}());\n"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var m = line[1];\n var arr = [];\n\n for(var i = 0; i < n; i++) \n arr[i] = read.arr();\n \n var checked = false;\n for(var i = 1; i < n - 1; i++) {\n for(var j = 1; j < m - 1; j++) {\n if(\n !checked \n && arr[i][j] === '*' \n && arr[i][j + 1] === '*' \n && arr[i][j - 1] === '*' \n && arr[i + 1][j] === '*' \n && arr[i - 1][j] === '*'\n ) {\n checked = true;\n arr[i][j] = '.';\n \n var t = j + 1;\n while(arr[i][t] === '*') {\n arr[i][t] = '.';\n t++;\n }\n \n t = j - 1;\n while(arr[i][t] === '*') {\n arr[i][t] = '.';\n t--;\n }\n \n t = i + 1;\n while(arr[t][j] === '*') {\n arr[t][j] = '.';\n if(t < n - 1)\n t++;\n }\n \n t = i - 1;\n while(arr[t][j] === '*') {\n arr[t][j] = '.';\n if(t > 0)\n t--;\n \n }\n break;\n }\n }\n if(checked) {\n break;\n }\n }\n\n\n for(var i = 0; i < n; i++) {\n if(arr[i].indexOf('*') !== -1) {\n print('NO');\n return;\n }\n }\n \n print('YES');\n}());\n"}, {"source_code": "var g = (readline()).split(\" \");\n\nvar x = Number(g[0]);\n\nvar y = Number(g[1]);\n\n\nvar flag = false;\n\nvar row_index = 0;\nvar col_index = 0;\nvar k = \"\";\n\nvar loop_b = false;\n\nvar mat = [];\nfor(i=0;i Number(i));\r\n var ans = 0;\r\n // for(var i = 1; i < arr.length; i++) {\r\n // if (i) {\r\n // var min = Math.min(arr[i], arr[i-1]);\r\n // var max = Math.max(arr[i], arr[i-1]);\r\n // while (true) {\r\n // if (min * 2 >= max) {\r\n // break;\r\n // }\r\n // min *= 2;\r\n // ++ans;\r\n // }\r\n // }\r\n // }\r\n arr.forEach((val, i) => {\r\n if (i) {\r\n var min = Math.min(arr[i], arr[i-1]);\r\n var max = Math.max(arr[i], arr[i-1]);\r\n while (true) {\r\n if (min * 2 >= max) {\r\n break;\r\n }\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n });\r\n print(ans)\r\n}\r\n", "positive_code": [{"source_code": "let lines = require('fs').readFileSync(0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++];\r\n\r\nlet t = Number(readline());\r\nfor(let i = 0; i < t; i++) {\r\n readline();\r\n let arr = readline().split(' ').map(i=> +i);\r\n let result = 0;\r\n for(let j = 1; j < arr.length; j++) {\r\n let min = arr[j];\r\n let max = arr[j - 1];\r\n if (max < min) [min, max] = [max, min]\r\n while(min * 2 < max) {\r\n min *= 2\r\n result++\r\n }\r\n }\r\n console.log(result)\r\n}\r\n"}, {"source_code": "let {stdin} = process\r\n\r\n// stdin.resume();\r\nstdin.setEncoding('utf-8');\r\n\r\nlet string = '';\r\nlet line = 0;\r\n\r\nstdin.on('data', input => string += input);\r\nstdin.on('end', () => {\r\n string = string.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readline = () => string[line++];\r\n\r\n\r\nfunction main(){\r\n let t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n readline();\r\n let arr = readline().split(' ').map(i=> +i);\r\n let result = 0;\r\n for(let j = 1; j < arr.length; j++) {\r\n let min = arr[j];\r\n let max = arr[j - 1];\r\n if (max < min) [min, max] = [max, min]\r\n while(min * 2 < max) {\r\n min *= 2\r\n result++\r\n }\r\n }\r\n console.log(result)\r\n }\r\n}\r\n"}, {"source_code": "let {stdin} = process\r\n\r\n// stdin.resume();\r\n// stdin.setEncoding('utf-8');\r\n\r\nlet string = '';\r\nlet line = 0;\r\n\r\nstdin.on('data', input => string += input);\r\nstdin.on('end', () => {\r\n string = string.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readline = () => string[line++];\r\n\r\n\r\nfunction main(){\r\n let t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n readline();\r\n let arr = readline().split(' ').map(i=> +i);\r\n let result = 0;\r\n for(let j = 1; j < arr.length; j++) {\r\n let min = arr[j];\r\n let max = arr[j - 1];\r\n if (max < min) [min, max] = [max, min]\r\n while(min * 2 < max) {\r\n min *= 2\r\n result++\r\n }\r\n }\r\n console.log(result)\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var a = parseInt(readline());\r\nwhile (a--) {\r\n var ok =parseInt(readline());\r\n var arr = readline().split(\" \")\r\n var c = 0;\r\n\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n var max=Math.max(arr[i],arr[i+1])\r\n var min=Math.min(arr[i],arr[i+1]);\r\n while(min*2 {\r\n // helper\r\n const getAns = (elements, array) => {\r\n let ans = 0;\r\n for (let i = 1; i < elements; i++) {\r\n const [ge, le] = array[i - 1] > array[i] ? [i - 1, i] : [i, i - 1];\r\n if (array[ge] / array[le] <= 2) continue;\r\n for (let j = array[le] * 2; j < array[ge]; j *= 2) {\r\n ans += 1;\r\n }\r\n }\r\n return ans;\r\n };\r\n \r\n const [, ...rest] = inputs;\r\n const q = rest.length;\r\n const ans = [];\r\n for (let i = 0; i < q; i += 2) {\r\n const elements = +rest[i];\r\n const array = rest[i + 1].split(\" \").map((e) => Number(e));\r\n ans.push(getAns(elements, array));\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n prompt: \"\"\r\n});\r\n\r\nconst q = [];\r\nrl.on(\"line\", (line) => {\r\n line \r\n ? q.push(line) \r\n : rl.close();\r\n}).on(\"close\", () => {\r\n solutionA(q);\r\n process.exit();\r\n});\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ans = 0;\n for(j = 0; j < e - 1; j++){\n var min = Math.min(k[j], k[j + 1]);\n var max = Math.max(k[j], k[j + 1]);\n while(max / min > 2){\n max = Math.ceil(max / 2);\n ans++;\n }\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction find(num1, num2){\r\n if(num1 < num2){\r\n let temp = num2;\r\n num2 = num1;\r\n num1 = temp;\r\n }\r\n let count = 0;\r\n for (let i = 0; num1 > num2; i++) {\r\n num1 = num1 / 2;\r\n count++;\r\n }\r\n return count - 1;\r\n}\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let length = +input[z++];\r\n let arr = input[z++].split(' ').map(x=>Number(x));\r\n let swap = 0;\r\n for (let i = 0; i < length - 1; i++) {\r\n if(arr[i]*2 < arr[i+1] || arr[i] / 2 > arr[i+1]){\r\n swap = swap + find(arr[i], arr[i+1]);\r\n }\r\n }\r\n console.log(swap);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Actual code...\r\n\r\nfunction numBetween(a, b) {\r\n const small = Math.min(a, b);\r\n const big = Math.max(a, b);\r\n if (big / small > 2) return 1 + numBetween(small * 2, big);\r\n return 0;\r\n}\r\n\r\nfunction main() {\r\n const numCases = parseInt(readline());\r\n for (let i = 0; i < numCases; i++) {\r\n const numTerms = readline();\r\n const arr = readline()\r\n .split(\" \")\r\n .map(str => parseInt(str));\r\n let numNeeded = 0;\r\n for (let j = 0; j < numTerms - 1; j++) {\r\n numNeeded += numBetween(arr[j], arr[j + 1]);\r\n }\r\n console.log(numNeeded);\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++) {\n let n = nl.num();\n let a = nl.nums();\n let cnt = 0;\n for(let j = 0; j < n - 1; j++){\n let x = a[j];\n let y = a[j + 1];\n if (x > y) {\n [x, y] = [y, x];\n }\n while(x * 2 < y) {\n cnt++;\n x *= 2;\n }\n }\n ans.push(cnt);\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\n\r\nrl.on(\"line\", (ln) => {\r\n input.push(ln);\r\n}).on(\"close\", () => {\r\n const T = input.shift();\r\n\r\n for (let i = 0; i < T; i++) {\r\n const N = input.shift();\r\n const nums = input.shift().split(\" \");\r\n\r\n let sum = 0;\r\n for (let j = 0; j < N - 1; j++) {\r\n const min = Math.min(nums[j], nums[j + 1]);\r\n const max = Math.max(nums[j], nums[j + 1]);\r\n const div = max / min;\r\n\r\n let times = Math.log(div) / Math.log(2);\r\n times = times % 1 === 0 && times > 0 ? times - 1 : Math.floor(times);\r\n sum += times;\r\n }\r\n console.log(sum);\r\n }\r\n});\r\n"}, {"source_code": "/**\r\n * 02/19/21 morning\r\n * https://codeforces.com/contest/1490/problem/A\r\n */\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let res = 0;\r\n for (let i = 0; i + 1 < n; i++) {\r\n let min = mi(a[i], a[i + 1]);\r\n let max = mx(a[i], a[i + 1]);\r\n while (max > min && max / min > 2) {\r\n max = Math.ceil(max / 2);\r\n res++;\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let fs = require(\"fs\");\r\nlet allInput = fs.readFileSync(0).toString(); // STDIN_FILENO = 0\r\nlet allLines=allInput.split('\\n');\r\nlet line=0;\r\nconst T=parseInt(allLines[line++]);\r\nfunction count(a, b) {\r\n let c=0;\r\n while (a*2 {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n solve()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction diff(max, min) {\r\n let res = 0\r\n while (max > min) {\r\n if ((Math.ceil(max / min)) > 2) {\r\n res++\r\n if (max % 2 === 0) max /=2\r\n else max = Math.floor(max / 2) + 1\r\n } else {\r\n return res\r\n }\r\n }\r\n return res\r\n}\r\n\r\nfunction isDense(arr) {\r\n let counter = 0\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] >= arr[i + 1]) {\r\n if (arr[i] / arr[i + 1] > 2) counter += diff(arr[i], arr[i + 1])\r\n } else {\r\n if (arr[i + 1] / arr[i] > 2) counter += diff(arr[i + 1], arr[i])\r\n }\r\n }\r\n console.log(counter)\r\n}\r\n\r\nfunction solve() {\r\n for (let i = 1; i < inputArr.length; i += 2) {\r\n isDense(inputArr[i])\r\n }\r\n}"}, {"source_code": "/*\r\n * File Created: Tuesday, 16th February 2021 3:32:09 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n 'use-strict'\r\n \r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf8');\r\n \r\n let data = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', chunk => {\r\n data += chunk;\r\n });\r\n \r\n process.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const n = parseInt(readLine());\r\n\r\n const arr = readLine().split(' ').map(Number);\r\n \r\n const res = a(n,arr);\r\n \r\n console.log(res)\r\n }\r\n });\r\n \r\n function get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n }\r\n \r\n function readLine() { \r\n return data[currentLine++];\r\n }\r\n \r\n function a(n,arr){\r\n let count = 0;\r\n for(let i = 0 ; i < n - 1; i++){\r\n let max = Math.max(arr[i], arr[i+1]);\r\n let min = Math.min(arr[i], arr[i+1]);\r\n if(max/min > 2){\r\n while(min * 2 < max){\r\n max = max / 2;\r\n count++;\r\n }\r\n } else{\r\n continue;\r\n }\r\n }\r\n return count;\r\n }\r\n\r\n module.exports = a;"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n2\r\n3 7\r\n24 25 27\r\n10 7\r\n51 52 53 54 55 56 57 58 59 60\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r 2) {\r\n max = Math.ceil(max / 2);\r\n count++;\r\n }\r\n }\r\n\r\n console.log(count);\r\n\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n var x = Number(readline())\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline())\r\n\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var res = 0\r\n for (var i = 0; i < a.length - 1; i++) {\r\n var min = Math.min(a[i + 1], a[i])\r\n var max = Math.max(a[i + 1], a[i])\r\n while (min*2 < max){\r\n min *=2\r\n res++\r\n }\r\n // console.log(res)\r\n }\r\n console.log(res)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tfor(var j = 0; j < N - 1; j++){\r\n\t\t\tvar max = Math.max(list[j], list[j + 1]);\r\n\t\t\tvar min = Math.min(list[j], list[j + 1]);\r\n\t\t\twhile(max > min * 2){\r\n\t\t\t\tmin *= 2;\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\nwhile(tc--) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n arr.forEach((value, index) => {\r\n if (index) {\r\n var min = Math.min(arr[index], arr[index-1]);\r\n var max = Math.max(arr[index], arr[index-1]);\r\n while (true) {\r\n if (min * 2 >= max) break;\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n });\r\n print(ans);\r\n}\r\n"}, {"source_code": "var tc = parseInt(readline())\r\nwhile(tc--) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n for(var i = 1; i < arr.length; i++) {\r\n if (i) {\r\n var min = Math.min(arr[i], arr[i-1]);\r\n var max = Math.max(arr[i], arr[i-1]);\r\n while (true) {\r\n if (min * 2 >= max) {\r\n break;\r\n }\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "var tc = parseInt(readline())\r\nwhile(tc--) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n for(var i = 1; i < arr.length; i++) {\r\n if (i) {\r\n var min = Math.min(arr[i], arr[i-1]);\r\n var max = Math.max(arr[i], arr[i-1]);\r\n while (true) {\r\n if (min * 2 >= max) {\r\n break;\r\n }\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n }\r\n // write(ans + '\\n')\r\n print(ans)\r\n}"}, {"source_code": "var tc = parseInt(readline())\r\nwhile(tc--) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n for(var i = 1; i < arr.length; i++) {\r\n if (i) {\r\n var min = Math.min(arr[i], arr[i-1]);\r\n var max = Math.max(arr[i], arr[i-1]);\r\n while (true) {\r\n if (min * 2 >= max) {\r\n break;\r\n }\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n }\r\n write(ans + '\\n')\r\n}"}, {"source_code": "var tc = parseInt(readline())\r\nfor(var t = 1; t <= tc; t++) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n for(var i = 1; i < arr.length; i++) {\r\n if (i) {\r\n var min = Math.min(arr[i], arr[i-1]);\r\n var max = Math.max(arr[i], arr[i-1]);\r\n while (true) {\r\n if (min * 2 >= max) {\r\n break;\r\n }\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n }\r\n write(ans + '\\n')\r\n}"}, {"source_code": "var tc = parseInt(readline())\r\nfor(var i = 1; i <= tc; i++) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var result = 0;\r\n for(var j = 1; j < arr.length; j++) {\r\n var now = arr[j];\r\n var before = arr[j-1]\r\n if (now > before) {\r\n \r\n \r\n while (now > before * 2) {\r\n before *= 2\r\n result++\r\n }\r\n } else if (before > now * 2) {\r\n while (before > now * 2) {\r\n now *= 2\r\n result++\r\n } \r\n }\r\n }\r\n write(result + '\\n')\r\n}"}, {"source_code": "var tc = parseInt(readline())\r\nfor(var i = 1; i <= tc; i++) {\r\n var n = readline();\r\n var arr = readline().split(' ').map(i => Number(i));\r\n var result = 0;\r\n for(var j = 1; j < arr.length; j++) {\r\n var now = arr[j];\r\n var before = arr[j-1]\r\n if (now > before) {\r\n \r\n \r\n while (now > before * 2) {\r\n before *= 2\r\n result++\r\n }\r\n } else if (before > now * 2) {\r\n while (before > now * 2) {\r\n now *= 2\r\n result++\r\n } \r\n }\r\n }\r\n write(result + '\\n')\r\n}"}, {"source_code": "var num = parseInt(readline())\r\nfor(var i = 0; i < num; i++) {\r\n readline();\r\n var arr = readline().split(' ').map(i => Number(i));\r\n var result = 0;\r\n for(var j = 1; j < arr.length; j++) {\r\n var now = arr[j];\r\n var before = arr[j-1]\r\n if (now > before) {\r\n \r\n \r\n while (now > before * 2) {\r\n before *= 2\r\n result++\r\n }\r\n } else if (before > now * 2) {\r\n while (before > now * 2) {\r\n now *= 2\r\n result++\r\n } \r\n }\r\n }\r\n write(result + '\\n')\r\n}"}, {"source_code": "\r\nvar num = readline() * 1\r\nfor(var i = 0; i < num; i++) {\r\n readline();\r\n var arr = readline().split(' ').map(i => Number(i));\r\n var result = 0;\r\n for(var j = 1; j < arr.length; j++) {\r\n var now = arr[j];\r\n var before = arr[j-1]\r\n if (now > before) {\r\n \r\n \r\n while (now > before * 2) {\r\n before *= 2\r\n result++\r\n }\r\n } else if (before > now * 2) {\r\n while (before > now * 2) {\r\n now *= 2\r\n result++\r\n } \r\n }\r\n }\r\n write(result + '\\n')\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar n = row[0]; //input\r\n \r\nfor(var times = 0; times < n; times++) {\r\n var l = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var a = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var result = 0;\r\n for(var i = 1; i < l; i++) {\r\n var previous = a[i - 1];\r\n var current = a[i];\r\n var max = Math.max(previous, current);\r\n var min = Math.min(previous, current);\r\n while(max / min > 2) {\r\n result++;\r\n var halfMax = Math.ceil(max / 2);\r\n max = Math.max(halfMax, min);\r\n min = Math.min(halfMax, min);\r\n }\r\n }\r\n write(result + \"\\n\" );\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar n = row[0]; //input\r\n\r\nfor(var times = 0; times < n; times++) {\r\n var l = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var a = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var result = 0;\r\n for(var i = 1; i < l; i++) {\r\n var previous = a[i - 1];\r\n var current = a[i];\r\n var max = Math.max(previous, current);\r\n var min = Math.min(previous, current);\r\n while(max / min > 2) {\r\n result++;\r\n var halfMax = Math.ceil(max / 2);\r\n max = Math.max(halfMax, min);\r\n min = Math.min(halfMax, min);\r\n }\r\n }\r\n write(result + \"\\n\");\r\n}"}, {"source_code": "var t = Number(readline());\r\n\r\nwhile (t--) {\r\n var len = Number(readline());\r\n var arr = readline().split(\" \");\r\n var ans = 0;\r\n\r\n for (var i = 0; i < len - 1; i++) {\r\n var a = Number(arr[i]);\r\n var b = Number(arr[i + 1]);\r\n var min = Math.min(a, b);\r\n \r\n while (min * 2 < Math.max(a, b)) {\r\n ans++;\r\n min *= 2;\r\n }\r\n\r\n \r\n }\r\n\r\n print(ans);\r\n}"}, {"source_code": "var t=parseInt(readline(), 10);\r\nfor (var i=0; i Number(i));\r\n var Ans = 0;\r\n A.forEach((val,index) =>{\r\n if(index){\r\n var min = Math.min(A[index], A[index-1]);\r\n var max = Math.max(A[index], A[index-1]);\r\n while (min*2 < max) {\r\n min *= 2;\r\n Ans++;\r\n }\r\n } \r\n });\r\n print(Ans);\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\nwhile(tc--) {\r\n var n = readline();\r\n var arr = readline().split(\" \").map(i => Number(i));\r\n var ans = 0;\r\n arr.forEach((value, index) => {\r\n if (index) {\r\n var min = Math.min(arr[index], arr[index-1]);\r\n var max = Math.max(arr[index], arr[index-1]);\r\n while (true) {\r\n if (min * 2 >= max) break;\r\n min *= 2;\r\n ++ans;\r\n }\r\n }\r\n });\r\n print(ans);\r\n}\r\n"}, {"source_code": "var num = readline() * 1\r\nfor(var i = 0; i < num; i++) {\r\n readline();\r\n var arr = readline().split(' ').map(i => Number(i));\r\n var result = 0;\r\n for(var j = 1; j < arr.length; j++) {\r\n var now = arr[j];\r\n var before = arr[j-1]\r\n if (now > before) {\r\n \r\n \r\n while (now > before * 2) {\r\n before *= 2\r\n result++\r\n }\r\n } else if (before > now * 2) {\r\n while (before > now * 2) {\r\n now *= 2\r\n result++\r\n } \r\n }\r\n }\r\n write(result + '\\n')\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n // your code goes here\r\n var a = readline();\r\nwhile (a--) {\r\n var arr = readline().split(\" \")\r\n var c = 0;\r\n\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n var max=Math.max(arr[i],arr[i+1])\r\n var min=Math.min(arr[i],arr[i+1]);\r\n while(min*2 max || (current[currentIdx] == max && currentIdx < currentMax)) {\r\n max = current[currentIdx];\r\n currentMax = currentIdx;\r\n }\r\n }\r\n var equal = l / 3;\r\n var holding = 0;\r\n for(var times2 = 1; times2 < 3; times2++) {\r\n holding = current[currentMax] + holding - equal;\r\n result += holding;\r\n currentMax = currentMax + 1 > 1 ? -1 : currentMax + 1;\r\n }\r\n write(result + \"\\n\");\r\n}"}], "src_uid": "a544dd9fd96379f66a960de6f973dd50"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let len1 = arr.filter((a) => a == 1).length;\r\n let len2 = arr.filter((a) => a == 2).length;\r\n\r\n let ar1 = isEven(len1);\r\n let ar2 = isEven(len2);\r\n\r\n if (len1 == 0 && ar2) cl(\"Yes\");\r\n else if (ar1 && len2 == 0) cl(\"Yes\");\r\n else if (ar1 && ar2) cl(\"Yes\");\r\n else if (ar1 && !ar2) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var n = lines[i].split(' ').map(Number);\n var div = 0, sum = 0, one = 0;\n for(j = 0; j < e; j++){\n if(n[j] == 1){\n one++;\n sum++;\n }else{\n sum += 2;\n }\n }\n if(sum % 2 === 0){\n div = Math.floor(sum / 2);\n if(div % 2 === 0){\n console.log('YES');\n }else{\n if(one % 2 === 0 && one !== 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var n = lines[i].split(' ').map(Number);\n var div = 0, sum = 0, one = 0;\n for(j = 0; j < e; j++){\n if(n[j] == 1){\n one++;\n sum++;\n }else{\n sum += 2;\n }\n }\n if(sum % 2 === 0){\n div = Math.floor(sum / 2);\n if(div % 2 === 0){\n console.log('YES');\n }else{\n if(one){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main()\r\nfunction main() {\r\n let t = Number(readline());\r\n while (t--) {\r\n const n = Number(readline());\r\n let sum = 0;\r\n let candies = readline().split(' ').map(Number);\r\n let ones = 0;\r\n for (let c of candies) {\r\n sum += c;\r\n if (c === 1) ones++;\r\n }\r\n if (sum % 2 === 0) {\r\n if (ones === 0 && n % 2 !== 0) console.log('NO');\r\n else console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\nconst { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const array = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n let n = 0;\r\n\r\n for(let idx in array) {\r\n if(idx % 2 === 0) n = array[idx];\r\n else {\r\n let cnt1 = 0, cnt2 = 0;\r\n const one = array[idx].join(\"\").match(/1/g);\r\n const two = array[idx].join(\"\").match(/2/g);\r\n\r\n if(one !== null) cnt1 = one.length;\r\n if(two !== null) cnt2 = two.length;\r\n \r\n const sum = cnt1 + 2 * cnt2;\r\n\r\n if(sum % 2 !== 0) {\r\n console.log(\"NO\");\r\n } else {\r\n if(cnt1 === 0) {\r\n if(cnt2 % 2 === 0) console.log(\"YES\");\r\n else console.log(\"NO\"); \r\n } else if(cnt1 % 2 === 0 && cnt2 % 2 === 0) console.log(\"YES\");\r\n else {\r\n if(cnt1 % 2 === 0 && cnt2 % 2 !== 0) console.log(\"YES\");\r\n else {\r\n if(cnt1 % 2 !== 0) console.log(\"NO\");\r\n else console.log(\"YES\")\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "function sum(arr) {\r\n let res = 0;\r\n for (let a of arr) {\r\n res += a;\r\n }\r\n return res;\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\nfunction solve(input) {\r\n // YOUR BUGS HERE...\r\n let res = [];\r\n for (let el of input) {\r\n let ans = 'NO'\r\n let a = el[1].split(' ').map(i => parseInt(i));\r\n const sumA = eval(a.join('+'))\r\n if (sumA % 2 !== 0) {\r\n ans = 'NO'\r\n } else {\r\n const halfSum = sumA / 2;\r\n if (halfSum === 1 && a[0] === 1) {\r\n ans = 'YES';\r\n } else if (halfSum % 2 === 0) {\r\n ans = countObj(a, 2) >= (halfSum / 2) || countObj(a, 1) >= halfSum ? 'YES' : 'NO'; \r\n } else if (halfSum % 2 !== 0) {\r\n ans = (countObj(a, 2) >= ((halfSum - 1) / 2) && countObj(a, 1) >= 1) || countObj(a, 1) >= halfSum ? 'YES' : 'NO'\r\n }\r\n }\r\n res.push(ans)\r\n };\r\n console.log(res.join('\\n'));\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * use this format to solve problem that use more than 1 inputs per testcase\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 2\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "function sum(arr) {\r\n let res = 0;\r\n for (let a of arr) {\r\n res += a;\r\n }\r\n return res;\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\nfunction solve(input) {\r\n // YOUR BUGS HERE...\r\n input.forEach(el => {\r\n let ans = 'NO'\r\n let a = el[1].split(' ').map(i => parseInt(i));\r\n const sumA = sum(a);\r\n if (sumA % 2 !== 0) {\r\n ans = 'NO'\r\n } else {\r\n const halfSum = sumA / 2;\r\n if (halfSum === 1 && a[0] === 1) {\r\n ans = 'YES';\r\n } else if (halfSum % 2 === 0) {\r\n ans = countObj(a, 2) >= (halfSum / 2) || countObj(a, 1) >= halfSum ? 'YES' : 'NO'; \r\n } else if (halfSum % 2 !== 0) {\r\n ans = (countObj(a, 2) >= ((halfSum - 1) / 2) && countObj(a, 1) >= 1) || countObj(a, 1) >= halfSum ? 'YES' : 'NO'\r\n }\r\n }\r\n console.log(ans);\r\n });\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * use this format to solve problem that use more than 1 inputs per testcase\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 2\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .filter((_, i) => i % 2)\n .map((line) => line.split(' '))\n .map((nums) => {\n const balance = nums.sort((a, b) => b - a).reduce((acc, num) => Math.abs(acc - num));\n return balance === 0 ? 'YES' : 'NO';\n })\n .join('\\n');\n};\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n5\r\n2\r\n1 1\r\n2\r\n1 2\r\n4\r\n1 2 1 2\r\n3\r\n2 2 2\r\n3\r\n2 1 2\r\n\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r a + b, 0);\r\n \r\n if (sum % 2 !== 0) {\r\n console.log('NO');\r\n return;\r\n }\r\n \r\n var half = sum / 2; \r\n var dp = [];\r\n \r\n dp[0] = true;\r\n \r\n for (var index = 0; index < a.length; ++ index) {\r\n var num = a[index];\r\n for (var i = half; i >= num; -- i) {\r\n dp[i] = dp[i] || dp[i - num];\r\n }\r\n }\r\n \r\n if(dp[half] === true) {\r\n console.log('YES');\r\n return;\r\n }\r\n\r\n console.log('NO');\r\n\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar one = 0;\r\n\t\tvar two = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] == 1){\r\n\t\t\t\tone++;\r\n\t\t\t}else{\r\n\t\t\t\ttwo++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(one % 2 == 1){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(two % 2 == 0){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tif(one > 0){\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\nconst sortAsc = (arr) => arr.sort((a, b) => a - b)\r\nconst sortDesc = (arr) => arr.sort((a, b) => b - a)\r\nconst sum = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\nconst getResult = (n, candies) => {\r\n\r\n if (n === 1) return 'NO'\r\n if (n === 2) return (candies[0] === candies[1]) ? 'YES' : 'NO'\r\n\r\n totalWeight = sum(candies)\r\n if (isOdd(totalWeight)) return 'NO'\r\n\r\n let ones = candies.filter(c => c === 1)\r\n let twos = candies.filter(c => c === 2)\r\n\r\n if (ones.length === 0) return isEven(twos.length) ? 'YES' : 'NO'\r\n if (twos.length === 0) return isEven(ones.length) ? 'YES' : 'NO'\r\n\r\n sortDesc(candies)\r\n let mid = totalWeight / 2\r\n let left = 0\r\n let right = n - 1\r\n\r\n for (let i = 0; i < twos.length; i++) {\r\n left += twos[i]\r\n if (left > mid) {\r\n left -= twos[i]\r\n break\r\n }\r\n }\r\n\r\n for (let i = 0; i < ones.length; i++) {\r\n left += ones[i]\r\n if (left > mid) {\r\n left -= ones[i]\r\n break\r\n }\r\n }\r\n\r\n if (left === mid) return 'YES'\r\n\r\n return 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = readline()\r\n let candies = readline()\r\n\r\n n = parseInt(n)\r\n candies = candies.split(' ').map(Number)\r\n console.log(getResult(n, candies))\r\n }\r\n}\r\n//*/"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nvar standardInputString = \"\";\nvar currentLine = 0;\n\nfunction readline() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction main() {\n let t = +readline();\n while (t--) {\n let n = +readline();\n let arr = readline()\n .split(\" \")\n .map((val) => +val);\n let count = [null, 0, 0];\n for (let i = 0; i < arr.length; ++i) {\n count[arr[i]]++;\n }\n if (count[1] % 2 !== 0) console.log(\"NO\");\n else if (count[2] % 2 !== 0 && count[1] === 0) console.log(\"NO\");\n else {\n console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "const { EOL } = require('os');\r\n\r\nlet input = ''\r\nprocess.stdin.on('data', data => input += data);\r\nprocess.stdin.on('end', () => {\r\n const lines = input.split(EOL);\r\n let numtests = parseInt(lines[0])\r\n let numCandies = []\r\n let candyWeights = []\r\n for(let i=1; i x.map(y => parseInt(y)))\r\n for(let i=0; i a + b, 0)%2===0) {\r\n if(candyWeights[i].length%2===0) {\r\n console.log('YES')\r\n } else {\r\n // number of ones needs to be even\r\n if(candyWeights[i].reduce((a,b) => a + (b==2? 0: 1), 0)%2==0 && candyWeights[i].reduce((a,b) => a + (b==2? 0: 1), 0)!==0) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n }\r\n } else {\r\n console.log('NO')\r\n }\r\n }\r\n});\r\n "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let n = readline();\r\n let c = readline().split(' ').map(x => +x);\r\n let o = c.filter(x => x === 1);\r\n let t = c.filter(x => x === 2);\r\n\r\n if (t.length % 2 === 0 && o.length % 2 === 0) {\r\n console.log('yes');\r\n } else if (o.length > 0 && (o.length - 2) % 2 === 0 && t.length % 2 !== 0) {\r\n console.log('yes');\r\n } else {\r\n console.log('no');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var sum = 0\r\n var number = 0\r\n var array = readline().split(' ').map(x => {\r\n sum += Number(x)\r\n if (Number(x) === 1) number += 1\r\n return Number(x)\r\n });\r\n if (sum % 2 === 0 && (sum / 2) % 2 === 1 && number < 2) return console.log('NO')\r\n console.log(sum % 2 === 0 ? \"YES\" : 'NO')\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet k = nl.nums();\n\t\tlet a = [0, 0];\n\t\tk.forEach((e) => {\n\t\t\ta[e-1]++;\n\t\t});\n\t\tif (a[1]%2 === 0){\n\t\t\tans.push(a[0]%2 === 0);\n\t\t} else {\n\t\t\tans.push(a[0] > 0 && (a[0] - 2)%2 === 0)\n\t\t}\t\t\n\t}\n\tconsole.log(ans.map(e => e?'YES':'NO').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n // taking input and assingn variables...\r\n let n = +input[z++];\r\n let arr = input[z++].split(' ').map(x=>Number(x));\r\n let total = 0;\r\n\r\n for (const val of arr) {\r\n total += val;\r\n }\r\n if(total % 2 === 1){\r\n console.log(\"NO\");\r\n }\r\n else{\r\n if(n % 2 === 0){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n let oneCount = 0;\r\n let twoCount = 0;\r\n for (const val of arr) {\r\n if(val === 1) oneCount++;\r\n else twoCount++;\r\n }\r\n if(oneCount === 0 || twoCount === 0){\r\n console.log(\"NO\");\r\n }\r\n else{\r\n if(oneCount % 2 === 1){\r\n console.log(\"NO\");\r\n }\r\n else{\r\n console.log(\"YES\");\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const { EOL } = require('os')\r\nlet i = ''\r\nprocess.stdin.on('data', c => (i += c))\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os')\r\n const lines = i.split(EOL).filter(line => line)\r\n console.log(processInput(lines))\r\n})\r\n\r\nconst processInput = lines => {\r\n return lines\r\n .slice(1)\r\n .filter((_, i) => i % 2)\r\n .map(line => line.split(' '))\r\n .map(nums => {\r\n const balance = nums\r\n .sort((a, b) => b - a)\r\n .reduce((acc, num) => Math.abs(acc - num))\r\n return balance === 0 ? 'YES' : 'NO'\r\n })\r\n .join(EOL)\r\n}"}, {"source_code": "const write = out => process.stdout.write(out + `\\n`);\n\nconst mainCode = ([l1, l2]) => {\n\tl1 = Number(l1);\n\tl2 = l2.split(' ').map(Number);\n\n\tlet ones = 0, twos = 0;\n\tl2.map(e => {\n\t\tif (e == 1) ones++;\n\t\telse twos++;\n\t})\n\n\tlet total = ones + twos * 2;\n\tif (total % 2 != 0) write('NO');\n\telse {\n\t\tif ((total / 2) % 2 == 0) write('YES')\n\t\telse {\n\t\t\tif (ones > 0) write('YES');\n\t\t\telse write('NO');\n\t\t}\n\t}\n}\n\nlet counter = 0;\nlet t = 0;\nconst t_size = 2;\n\nconst cases = [];\n\nconst lineInterpreter = (line) => {\n\tif (counter == 0) t = Number(line)\n\telse {\n\t\tconst cursor = (counter - 1) % t_size\n\t\tif (cursor == 0) cases.push([line])\n\t\telse cases[cases.length - 1].push(line)\n\t}\n\n\tif (counter == (t * t_size)) {\n\t\tcases.map(_case => mainCode(_case))\n\t}\n\tcounter++\n}\n\nconst platform = 1;\n\nif (platform > 0) {\n\t\n\t// FOR CODEFORCES\n\n\tprocess.stdin.resume();\n\tprocess.stdin.setEncoding('utf-8');\n\n\tlet inputString = '';\n\tlet currentLine = 0;\n\n\tprocess.stdin.on('data', inputStdin => {\n\t inputString += inputStdin;\n\t});\n\n\tprocess.stdin.on('end', _ => {\n\t inputString = inputString.trim().split('\\n').map(string => {\n\t return string.trim();\n\t });\n\t \n\t\tinputString.map(line => lineInterpreter(line));\n\t});\n} else {\n\n\t// FOR PERSONAL USE\n\n\tconst sample = `5\n2\n1 1\n2\n1 2\n4\n1 2 1 2\n3\n2 2 2\n3\n2 1 2`;\n\tsample.split(`\\n`).map(line => lineInterpreter(line));\n}"}, {"source_code": "const candies = a => {\n const countOne = a.reduce((acc, item) => {\n if (item == 1) return acc + 1;\n return acc;\n }, 0);\n const countTwo = a.length - countOne;\n if (countOne % 2 == 1) return false;\n if (countTwo % 2 == 0) return true;\n if (countOne == 0) return false;\n return true;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n readline();\n const a = readline()\n .split(\" \")\n .map(s => parseInt(s));\n if (candies(a)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n\nfunction create2DArray(rows) {\n var arr = [];\n\n for (var i = 0; i < rows; i++) {\n arr[i] = [];\n }\n\n return arr;\n}\n// ---------------------------------------\n\nfunction main() {\n let t = getInt(readline());\n while(t--) {\n let len = getInt(readline());\n let arr = getArray(readline());\n let total1 = 0;\n let total2 = 0;\n for(let i=0; i {\r\n if ([...new Set(arr)].length == 1) {\r\n if (n % 2 == 0) {\r\n return console.log('YES');\r\n } else {\r\n return console.log('NO');\r\n }\r\n }\r\n let sum = arr.reduce((a, b) => a + b);\r\n if (sum % 2 == 1) return console.log('NO');\r\n console.log('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n if (c % 2) {\r\n c++;\r\n return;\r\n }\r\n\r\n const arr = d.split(' ').map(Number).sort((a, b) => b - a);\r\n let alice = 0;\r\n let bob = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (alice > bob) {\r\n bob += arr[i];\r\n }\r\n else {\r\n alice += arr[i];\r\n }\r\n }\r\n\r\n if (alice === bob) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tconst sum = arr.reduce((acc, curr) => acc + curr, 0);\n\t\tif (sum % 2 !== 0) console.log('NO');\n\t\telse {\n\t\t\tconst target = Math.floor(sum / 2);\n\t\t\tconst dp = [...Array(len + 1).fill(0)].map((_) => Array(target + 1).fill(0));\n\t\t\tfor (let i = 1; i <= len; i++) {\n\t\t\t\tfor (let j = 1; j <= target; j++) {\n\t\t\t\t\tif (arr[i - 1] <= j) {\n\t\t\t\t\t\tdp[i][j] = Math.max(arr[i - 1] + dp[i - 1][j - arr[i - 1]], dp[i - 1][j]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdp[i][j] = dp[i - 1][j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (dp[len][target] === target) {\n\t\t\t\tconsole.log('YES');\n\t\t\t} else {\n\t\t\t\tconsole.log('NO');\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 2; i += 2) {\r\n const n = parseInt(lines[i]);\r\n const arr = lines[i + 1].split(' ').map(num => parseInt(num));\r\n\r\n console.log(solve(n, arr));\r\n }\r\n});\r\n\r\nfunction solve(n, arr) {\r\n let one = 0;\r\n let two = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 1) {\r\n one++;\r\n } else {\r\n two++;\r\n }\r\n }\r\n\r\n two = two % 2;\r\n\r\n if (two > 0 && one < 2) {\r\n return 'NO';\r\n } else if (two > 0) {\r\n one -= 2;\r\n }\r\n\r\n return one % 2 > 0 ? 'NO' : 'YES';\r\n}\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number);\r\n ones = 0;\r\n tows = 0;\r\n for (i = 0; i < y.length; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n tows++;\r\n }\r\n }\r\n if (tows % 2 && ones && ones % 2 === 0) print(\"YES\");\r\n else if (tows % 2 === 0 && ones % 2 === 0) {\r\n print(\"YES\");\r\n } else print(\"NO\");\r\n}\r\n"}, {"source_code": "var n = parseInt(readline())\r\n\r\n function equal() {\r\n var length = parseInt(readline())\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n var sum = 0;\r\n var one = 0;\r\n for (var i = 0; i < length; i++) {\r\n sum += a[i];\r\n if (a[i] == 1)\r\n one++;\r\n }\r\n if (sum % 2 !== 0) {\r\n return print(\"NO\");\r\n }\r\n var temp = Math.floor(sum / 2);\r\n if (temp % 2 !== 0 && one < 2) {\r\n print(\"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n }\r\n\r\n while (n--) {\r\n equal()\r\n }"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n var n = +readline();\r\n var weights = readline().split(\" \").map(Number);\r\n var arr = [0, 0];\r\n var sum = 0;\r\n\r\n for (var weight of weights) {\r\n sum += weight;\r\n arr[weight % 2] += 1;\r\n }\r\n var ones = arr[1];\r\n if (ones % 2 || (sum % 4 && !ones)) {\r\n print(\"NO\");\r\n continue;\r\n }\r\n print(\"YES\");\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n var n = +readline();\r\n var weights = readline().split(\" \").map(Number);\r\n var sum_weights = weights.reduce((acc, item) => acc + item);\r\n var ones = 0;\r\n var twos = 0;\r\n var sum = weights[0];\r\n\r\n for (var i = 0; i < n; i++) {\r\n if (weights[i] === 1) {\r\n ones++;\r\n } else {\r\n twos++;\r\n }\r\n }\r\n \r\n if (ones % 2) {\r\n print(\"NO\");\r\n continue;\r\n }\r\n \r\n if (sum_weights % 4 && ones === 0) {\r\n print(\"NO\");\r\n continue;\r\n }\r\n print(\"YES\");\r\n}"}, {"source_code": "'use strict'\r\n\r\nlet t = readline();\r\n while(t--)\r\n {\r\n let n = +readline();\r\n let a = readline().split(\" \");\r\n a.sort((x, y) => +y - +x);\r\n while(a[0] == 2 && a[1] == 2)\r\n a.splice(0,2);\r\n if(a[0] == 2 && +a[1] + +a[2] == 2)\r\n a.splice(0,3);\r\n while(a[0] == 1 && a[1] == 1)\r\n a.splice(0,2);\r\n print(a.length? \"NO\" : \"YES\");\r\n }"}, {"source_code": "var t =readline();\r\nfor (var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n var a = readline().split(' ');\r\n var one = 0 , two = 0 , counter = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n if(a[j] == '1'){\r\n one++;\r\n counter = counter + 1;\r\n }\r\n else{\r\n two++;\r\n counter = counter + 2;\r\n }\r\n }\r\n if(counter%2 !== 0){\r\n print('NO');\r\n }\r\n else if(one === 0 && two%2 !== 0){\r\n print('NO');\r\n }\r\n else if(one%2 === 0 && two%2 !== 0 || one%2 === 0 && two%2 === 0 ){\r\n print('YES');\r\n }\r\n else{\r\n print('NO');\r\n }\r\n}"}, {"source_code": "test = parseInt(readline());\r\nwhile (test--) {\r\n\t one = 0;\r\n\t\ttwo = 0;\r\n\tn = parseInt(readline());\r\n arr = readline().split(' ').map(x => +x);\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tif (arr[i] == 1) one++;\r\n\t\telse two++;\r\n\t}\r\n\r\n\tif ((two % 2) && (one) && (one % 2)===0)\r\n\t\tprint('YES');\r\n\telse if ((two % 2)===0 && (one % 2)===0) {\r\n\t\tprint('YES');\r\n\t} else\r\n\t\tprint('NO');\r\n\r\n}\r\n\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let amount = parseInt(readline());\r\n let weigths = readline().split(\" \").map(x => parseInt(x));\r\n let ones = 0;\r\n let twoes = 0;\r\n\r\n for(let j = 0; j < amount; j++){\r\n if(weigths[j] === 1){\r\n ones++;\r\n } else {\r\n twoes++;\r\n }\r\n }\r\n\r\n if(ones > 1 && twoes % 2 === 1){\r\n ones -= 2;\r\n twoes++;\r\n }\r\n\r\n if(ones % 2 === 0 && twoes % 2 === 0){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "T = readline()\r\n\r\nwhile (T--) {\r\n n = readline()\r\n a = readline().split(' ').map(x => +x)\r\n sumOne = 0;\r\n sumTwo = 0;\r\n for (i = 0; i < n; i++) {\r\n if(a[i]==1)\r\n sumOne++\r\n else\r\n sumTwo++\r\n }\r\n if (sumTwo % 2 != 0) {\r\n if ((sumOne % 2 == 0)&&(sumOne>1))\r\n print('YES')\r\n else\r\n print('NO') \r\n }\r\n else {\r\n if (sumOne%2==0)\r\n print('YES')\r\n else\r\n print('NO')\r\n } \r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = rl().split(\" \");\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let len1 = arr.filter((a) => a == 1).length;\r\n let len2 = n - len1;\r\n\r\n let ar1 = len1 % 2 === 0 && len1 > 1;\r\n let ar2 = len2 % 2 === 0 && len2 > 1;\r\n\r\n if (len1 === 0 && ar2) cl(\"Yes\");\r\n else if (ar1 && (ar2 || !ar2)) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = rl().split(\" \");\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let len1 = 0;\r\n let len2 = 0;\r\n arr.forEach((a) => {\r\n a == 1 ? len1++ : len2++;\r\n });\r\n\r\n let ar1 = isEven(len1);\r\n let ar2 = isEven(len2);\r\n\r\n if (len1 === 0 && ar2) cl(\"Yes\");\r\n else if (ar1 && len2 === 0) cl(\"Yes\");\r\n else if (ar1 && (ar2 || !ar2)) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let len1 = arr.filter((a) => a === 1).length;\r\n let len2 = arr.filter((a) => a === 2).length;\r\n\r\n let ar1 = isEven(len1);\r\n let ar2 = isEven(len2);\r\n\r\n if (len1 === 0 && ar2) cl(\"Yes\");\r\n else if (ar1 && len2 === 0) cl(\"Yes\");\r\n else if (ar1 && (ar2 || !ar2)) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "let ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0], e= 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j],alice = 0, bob = 0\n }else{\n k = lines[j].split(' ').map(Number).sort(function(a, b){return b - a})\n for (i = 0; i < e; i++) {\n if (alice > bob) {\n bob += k[i]\n }\n else {\n alice += k[i]\n }\n }\n \n if (alice === bob) {\n console.log('YES')\n }\n else {\n console.log('NO')\n }\n }\n }\n \n \n});"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let len1 = arr.filter((a) => a == 1).length;\r\n let len2 = arr.filter((a) => a == 2).length;\r\n\r\n let ar1 = isEven(len1);\r\n let ar2 = isEven(len2);\r\n\r\n if (len1 == 0 && ar2) cl(\"Yes\");\r\n else if (ar1 && len2 == 0) cl(\"Yes\");\r\n else if (ar1 && ar2) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let ar1 = isEven(arr.filter((a) => a == 1).length);\r\n let ar2 = isEven(arr.filter((a) => a == 2).length);\r\n if (ar1 || ar2) cl(\"Yes\");\r\n else cl(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let ar1 = isEven(arr.filter((a) => a == 1).length);\r\n let ar2 = isEven(arr.filter((a) => a == 2).length);\r\n\r\n if ((!ar1 && !ar2) || (ar1 !== 0 && !ar1 && ar2)) cl(\"No\");\r\n else cl(\"Yes\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n isEven = (a) => (a % 2 === 0 && a > 1 ? true : false),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = rl();\r\n const ln2 = numArray(rl());\r\n solution(+ln1, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(n, arr) {\r\n let ar1 = isEven(arr.filter((a) => a == 1).length);\r\n let ar2 = isEven(arr.filter((a) => a == 2).length);\r\n\r\n if ((!ar1 && !ar2) || (!ar1 && ar2)) cl(\"No\");\r\n else cl(\"Yes\");\r\n }\r\n}\r\n"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n for(j = 1; j <= lines[0]; j++){\n var a = lines[j]\n for(k = 2; k < a; k++){\n var b = lines[k].split(' ')\n var l = 0\n if(a == 2){\n l = b[0] + b[1]\n }else if(a == 3){\n l = b[0] + b[1] + b[2]\n } else if(a == 4){\n l = b[0] + b[1] + b[2] + b[3]\n }\n if(l % 2 === 0){\n console.log('YES')\n }else {\n console.log('NO')\n }\n }\n \n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = false\n for(j = 1; j <= lines[0] ; j++){\n var b = lines[j+1].split(' ')\n var l = b[0] + b[1]\n if(l % 2 === 0){\n console.log('YES')\n }else{\n console.log('NO')\n }\n \n \n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var cases = lines[0];\n var totalWeight = 0;\n for(var j = 1; j < Number(cases) + 1; j++){\n var candies = lines[j + j - 1].split(' ').map(Number);\n var weight = lines[j + j].split(' ').map(Number);\n for(k = 0; k < candies; k++){\n totalWeight = weight[j] + weight[j];\n }\n if(totalWeight % 2 === 0){\n console.log('YES');\n }\n else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var cases = lines[0];\n for(var j = 1; j < Number(cases) + 1; j++){\n var candies = lines[j + j - 1].split(' ').map(Number);\n var weight = lines[j + j].split(' ').map(Number);\n var totalWeight = weight[j] + weight[j];\n if(totalWeight % 2 === 0){\n console.log('YES');\n }\n else{\n console.log('NO')\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main()\r\nfunction main() {\r\n let t = Number(readline());\r\n while (t--) {\r\n const n = Number(readline());\r\n let sum = 0;\r\n let candies = readline().split(' ').map(Number);\r\n let ones = 0;\r\n for (let c of candies) {\r\n sum += c;\r\n if (c === 1) ones++;\r\n }\r\n if (\r\n sum % 2 === 0 &&\r\n ((ones === 0 && n % 2 === 0) ||\r\n (ones !== 0 &&\r\n (((ones / 2) % 2 === 1 && n - ones > 1) || (ones / 2) % 2 === 0)))\r\n ) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main()\r\nfunction main() {\r\n let t = Number(readline());\r\n while (t--) {\r\n const n = Number(readline());\r\n let sum = 0;\r\n let candies = readline().split(' ').map(Number);\r\n let ones = 0;\r\n for (let c of candies) {\r\n sum += c;\r\n if (c === 1) ones++;\r\n }\r\n if (\r\n sum % 2 === 0 &&\r\n ((ones === 0 && n % 2 === 0) ||\r\n (ones !== 0 &&\r\n (((ones / 2) % 2 === 1 && n % 2 === 0) || (ones / 2) % 2 === 0)))\r\n ) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main()\r\nfunction main() {\r\n let t = Number(readline());\r\n while (t--) {\r\n const n = Number(readline());\r\n if (n % 2 === 1) {\r\n console.log('NO');\r\n } else {\r\n let sum = 0;\r\n let candies = readline().split(' ').map(Number);\r\n for (let c of candies) sum += c;\r\n if (sum % 2 === 0) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const { Console } = require(\"console\");\r\nconst { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const array = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n let n = 0;\r\n\r\n for(let idx in array) {\r\n if(idx % 2 === 0) n = array[idx];\r\n else {\r\n if(n == 1) {\r\n console.log(\"NO\");\r\n } else {\r\n const one = array[idx].join(\"\").match(/1/g);\r\n const two = array[idx].join(\"\").match(/2/g);\r\n let cnt1 = 0, cnt2 = 0;\r\n\r\n if(one !== null) cnt1 = one.length;\r\n if(two !== null) cnt2 = two.length;\r\n \r\n const sum = cnt1 + 2 * cnt2;\r\n\r\n if(sum % 2 !== 0) {\r\n console.log(\"NO\");\r\n } else {\r\n if(cnt1 % 2 === 0 && cnt2 % 2 === 0) console.log(\"YES\");\r\n else {\r\n if(cnt1 % 2 === 0 && cnt2 % 2 !== 0) console.log(\"YES\");\r\n else {\r\n if(cnt1 % 2 !== 0) console.log(\"NO\");\r\n else console.log(\"YES\")\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const { Console } = require(\"console\");\r\nconst { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const array = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n let n = 0;\r\n\r\n for(let idx in array) {\r\n let check = false;\r\n if(idx % 2 === 0) n = array[idx];\r\n else {\r\n if(n % 2 !== 0) {\r\n console.log(\"NO\");\r\n } else {\r\n const one = array[idx].join(\"\").match(/1/g);\r\n const two = array[idx].join(\"\").match(/2/g);\r\n\r\n if(one !== null) check = one.length % 2 === 0 ? true : false;\r\n if(two !== null) check = two.length % 2 === 0 ? true : false;\r\n\r\n check === true ? console.log(\"YES\") : console.log(\"NO\");\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "function sum(arr) {\r\n let res = 0;\r\n for (let a of arr) {\r\n res += a;\r\n }\r\n return res;\r\n}\r\n\r\nconst countObj = (arr, val) => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);\r\n\r\nfunction solve(input) {\r\n // YOUR BUGS HERE...\r\n input.forEach(el => {\r\n let ans = 'NO'\r\n let a = el[1].split(' ').map(i => parseInt(i));\r\n const sumA = sum(a);\r\n if (sumA % 2 !== 0) {\r\n ans = 'NO'\r\n } else {\r\n const halfSum = sumA / 2;\r\n if (halfSum === 1 && a[0] === 1) {\r\n ans = 'YES';\r\n } else if (halfSum % 2 === 0) {\r\n ans = countObj(a, 2) >= (halfSum / 2) || countObj(a, 1) >= halfSum ? 'YES' : 'NO'; \r\n } else if (halfSum % 2 !== 0) {\r\n ans = countObj(a, 2) >= ((halfSum - 1) / 2) && countObj(a, 1) >= 1 ? 'YES' : 'NO'\r\n }\r\n }\r\n console.log(ans);\r\n });\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ==============\r\n * \r\n * use this format to solve problem that use more than 1 inputs per testcase\r\n * \r\n * */ \r\nfunction set_n_line() {\r\n // set return 0 if the problem needs dynamic n line inputs\r\n // set return n > 0 if the problem needs fixed n line inputs\r\n return 2\r\n}\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\nlet inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();\r\nfunction fillInput(line) {\r\n // dynamic n_line\r\n if (n_line_subinput == 0) n_line_subinput = parseInt(line)\r\n else if (sub_input.length < n_line_subinput) {\r\n sub_input.push(line)\r\n if (sub_input.length == n_line_subinput) {\r\n inputs.push(sub_input); sub_input = []; \r\n n_line_subinput = set_n_line();\r\n }\r\n }\r\n}\r\n\r\nreadline.on('line', line => {\r\n if (t == 0) t = parseInt(line)\r\n else if (inputs.length < t) {\r\n fillInput(line)\r\n if (inputs.length == t) { solve(inputs);readline.close() }\r\n }\r\n});\r\n/* =========== DEFAULT FORMAT END ============== */\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .filter((_, i) => i % 2)\n .map((line) => line.split(' '))\n .map((nums) => {\n const balance = nums.sort((a, b) => a - b).reduce((acc, num) => Math.abs(acc - num));\n return balance === 0 ? 'YES' : 'NO';\n })\n .join('\\n');\n};\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .filter((_, i) => i % 2)\n .map((line) => line.split(' '))\n .map((nums) => {\n let nOf1 = 0,\n nOf2 = 0;\n for (const num of nums) {\n if (num === '1') nOf1++;\n else nOf2++;\n }\n return nOf1 % 2 === 0 && nOf2 % 2 === 0 ? 'YES' : 'NO';\n })\n .join('\\n');\n};\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n5\r\n2\r\n1 1\r\n2\r\n1 2\r\n4\r\n1 2 1 2\r\n3\r\n2 2 2\r\n3\r\n2 1 2\r\n\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n5\r\n2\r\n1 1\r\n2\r\n1 2\r\n4\r\n1 2 1 2\r\n3\r\n2 2 2\r\n3\r\n2 1 2\r\n\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\nconst sortAsc = (arr) => arr.sort((a, b) => a - b)\r\nconst sum = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\nfunction findMinDiff(arr, n) {\r\n\r\n let sum = 0\r\n let left2right = [1]\r\n let right2left = [1]\r\n\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] > arr[i - 1]) {\r\n left2right[i] = left2right[i - 1] + 1\r\n }\r\n }\r\n\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (arr[i] > arr[i + 1]) {\r\n right2left[i] = right2left[i + 1] + 1\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n sum += Math.max(left2right[i], right2left[i])\r\n }\r\n \r\n return sum\r\n}\r\n\r\nconst getResult = (n, candies) => {\r\n\r\n if (n === 1) return 'NO'\r\n if (n === 2) return (candies[0] === candies[1]) ? 'YES' : 'NO'\r\n\r\n totalWeight = sum(candies)\r\n if (isOdd(totalWeight)) return 'NO'\r\n\r\n sortAsc(candies)\r\n\r\n let minDiff = findMinDiff(candies, n)\r\n return minDiff === 0 ? 'YES' : 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = readline()\r\n let candies = readline()\r\n\r\n n = parseInt(n)\r\n candies = candies.split(' ').map(Number)\r\n console.log(getResult(n, candies))\r\n }\r\n}\r\n//*/"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nvar standardInputString = \"\";\nvar currentLine = 0;\n\nfunction readline() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction main() {\n let t = +readline();\n while (t--) {\n let n = +readline();\n let arr = readline()\n .split(\" \")\n .map((val) => +val);\n let count = [null, 0, 0];\n for (let i = 0; i < arr.length; ++i) {\n count[arr[i]]++;\n }\n if (\n count[1] === count[2] &&\n (count[1] + count[2]) % 2 === 0 &&\n count[1] !== 1 &&\n count[2] !== 1\n ) {\n console.log(\"YES\");\n } else if (\n (count[1] === 0 && count[2] % 2 === 0) ||\n (count[2] === 0 && count[1] % 2 === 0)\n ) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "const { EOL } = require('os');\r\n\r\nlet input = ''\r\nprocess.stdin.on('data', data => input += data);\r\nprocess.stdin.on('end', () => {\r\n const lines = input.split(EOL);\r\n console.log(lines)\r\n let numtests = parseInt(lines[0])\r\n let numCandies = []\r\n let candyWeights = []\r\n for(let i=1; i x.map(y => parseInt(y)))\r\n for(let i=0; i a + b, 0)%2===0) {\r\n if(candyWeights[i].length%2===0) {\r\n console.log('YES')\r\n } else {\r\n // number of ones needs to be even\r\n if(candyWeights[i].reduce((a,b) => a + (b==2? 0: 1), 0)%2==0 && candyWeights[i].reduce((a,b) => a + (b==2? 0: 1), 0)!==0) {\r\n console.log('YES')\r\n } else {\r\n console.log('NO')\r\n }\r\n }\r\n } else {\r\n console.log('NO')\r\n }\r\n }\r\n});\r\n "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let n = readline();\r\n let c = readline().split(' ').map(x => +x);\r\n c.sort();\r\n\r\n let s1 = 0;\r\n let s2 = 0;\r\n\r\n for(let i = 0; i <= n && i + 1 <= n; i+=2) {\r\n s1 += c[i];\r\n s2 += c[i + 1];\r\n }\r\n\r\n console.log(s1 === s2 ? 'yes' : 'no');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var sum = 0\r\n var array = readline().split(' ').map(x => {\r\n sum+=Number(x)\r\n return Number(x)\r\n });\r\n\r\n console.log(sum % 2 ===0 ? \"YES\":'NO')\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number);\r\n ones = 0;\r\n tows = 0;\r\n for (i = 0; i < y.length; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n tows++;\r\n }\r\n }\r\n if (ones === tows && ones !== 1 && tows !== 1) {\r\n print(\"YES\");\r\n } else {\r\n if (\r\n (ones % 2 === 0 && tows % 2 === 0) ||\r\n (ones % 2 === 1 && tows % 2 === 1)\r\n ) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number);\r\n ones = 0;\r\n tows = 0;\r\n for (i = 0; i < y.length; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n tows++;\r\n }\r\n }\r\n if (ones === tows && ones !== 1 && tows !== 1) {\r\n print(\"YES\");\r\n } else {\r\n if (ones % 2 === 0 && tows % 2 === 0) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number);\r\n ones = 0;\r\n for (i = 0; i < y.length; i++) {\r\n if (y[i] === 1) {\r\n ones += y[i];\r\n } else {\r\n continue;\r\n }\r\n }\r\n if (x / 2 === ones) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number).sort();\r\n ones = 0;\r\n twos = 0;\r\n for (i = 0; i < x; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n twos++;\r\n }\r\n }\r\n if ((ones % 2 === 0 && twos % 2 === 0) || ones === twos) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "w = +readline();\r\nones = 0;\r\ntwos = 0;\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number).sort();\r\n for (i = 0; i < x; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n twos++;\r\n }\r\n }\r\n if (ones === twos) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "w = +readline();\r\nfor (j = 0; j < w; j++) {\r\n x = +readline();\r\n y = readline().split(\" \").map(Number).sort();\r\n ones = 0;\r\n twos = 0;\r\n for (i = 0; i < x; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n twos++;\r\n }\r\n }\r\n if (ones === twos) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "x = +readline();\r\ny = readline().split(\" \").map(Number).sort();\r\nones = 0;\r\ntwos = 0;\r\nfor (i = 0; i < x; i++) {\r\n if (y[i] === 1) {\r\n ones++;\r\n } else {\r\n twos++;\r\n }\r\n}\r\nif (ones === twos) {\r\n print(\"YES\");\r\n} else {\r\n print(\"NO\");\r\n}\r\n"}, {"source_code": "var n = parseInt(readline())\r\n\r\n function equal() {\r\n var length = parseInt(readline())\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n var sum = 0;\r\n var one = 0;\r\n for (var i = 0; i < length; i++) {\r\n sum += a[i];\r\n if (a[i] == 1)\r\n one++;\r\n }\r\n if (sum % 2 !== 0) {\r\n return print(\"NO\");\r\n }\r\n var temp = Math.floor(sum / 2);\r\n if (temp >= 1 && one < 2) {\r\n print(\"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n }\r\n\r\n while (n--) {\r\n equal()\r\n }"}, {"source_code": "var n = parseInt(readline())\r\n\r\n function equal() {\r\n var length = parseInt(readline())\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data)\r\n var sum = 0;\r\n var one = 0;\r\n for (var i = 0; i < length; i++) {\r\n sum += a[i];\r\n if (a[i] == 1)\r\n one++;\r\n }\r\n if (sum % 2 !== 0) {\r\n return print(\"NO\");\r\n }\r\n var temp = Math.floor(sum / 2);\r\n if (temp > 1 && one < 2) {\r\n print(\"NO\");\r\n } else {\r\n print(\"YES\");\r\n }\r\n }\r\n\r\n while (n--) {\r\n equal()\r\n }"}, {"source_code": "var input = parseInt(readline());\r\n\r\n for (var i = 0; i < input; i++) {\r\n var n = parseInt(readline());\r\n var weight = readline().split(\" \");\r\n\r\n var one = weight.filter((data) => data === \"1\").length;\r\n var two = weight.filter((data) => data === \"2\").length;\r\n if (one % 2 === 0 && (two % 2 === 0 || two === 1) && one > 0 && two > 0) {\r\n print(\"YES\");\r\n } else if (two % 2 === 0 && two > 0 && one === 0) {\r\n print(\"YES\");\r\n } else if (one % 2 === 0 && one > 0 && two === 0) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "var input = parseInt(readline());\r\n\r\n for (var i = 0; i < input; i++) {\r\n var n = parseInt(readline());\r\n var weight = readline().split(\" \");\r\n\r\n var one = weight.filter((data) => data === \"1\").length;\r\n var two = weight.filter((data) => data === \"2\").length;\r\n if (one % 2 === 0 && two % 2 === 0 && one !== 0 && two !== 0) {\r\n print(\"YES\");\r\n } else if (two % 2 === 0 && two !== 0 && one === 0) {\r\n print(\"YES\");\r\n } else if (one % 2 === 0 && one !== 0 && two === 0) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "var t = +readline();\r\n\r\nfor(var i = 0; i < t; i++) {\r\n var n = +readline();\r\n var weights = readline().split(' ').map(Number);\r\n var sum_weights = weights.reduce((acc, item) => acc + item);\r\n var qnt_1 = 0;\r\n var qnt_2 = 0;\r\n \r\n for(var j = 0; j < n; j++) {\r\n if(weights[j] === '1') {\r\n qnt_1++;\r\n } else {\r\n qnt_2++\r\n }\r\n }\r\n \r\n if(sum_weights % 2 === 0) {\r\n if(qnt_1 % 2 === 0 && qnt_2 % 2 === 0) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n } else {\r\n print('NO');\r\n }\r\n}"}, {"source_code": "'use strict'\r\n\r\nlet t = readline();\r\n while(t--)\r\n {\r\n let n = +readline();\r\n let a = readline().split(\" \");\r\n if(a.length == 1)print(\"NO\")\r\n else\r\n {\r\n a.sort();\r\n let i = 0, j = 0;\r\n while(a[i] == 1)i++;\r\n while(a[a.length - 1 - j] == 2)j++;\r\n print(((i%2 && i) || (j%2 && j))? \"NO\" : \"YES\");\r\n }\r\n \r\n }"}, {"source_code": "'use strict'\r\n\r\nlet t = readline(1);\r\n while(t--)\r\n {\r\n let n = +readline(2);\r\n let a = readline(\"1 2\").split(\" \");\r\n a.sort();\r\n let i = 0, j = 0;\r\n while(a[i] == 1)i++;\r\n while(a[a.length - 1 - j] == 2)j++;\r\n print(((i%2 && i) || (j%2 && j))? \"NO\" : \"YES\");\r\n }"}, {"source_code": "var t =readline();\r\nfor (var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n var a = readline().split(' ');\r\n var one = 0 , two = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n if(a[j] == '1'){\r\n one++;\r\n }\r\n else{\r\n two++;\r\n }\r\n }\r\n if(one%2 === 0 && two%2 === 0 ){\r\n print('YES');\r\n }\r\n else{\r\n print('NO');\r\n }\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let amount = parseInt(readline());\r\n let weigths = readline().split(\" \").map(x => parseInt(x));\r\n let ones = 0;\r\n let twoes = 0;\r\n\r\n for(let j = 0; j < amount; j++){\r\n if(weigths[j] === 1){\r\n ones++;\r\n } else {\r\n twoes++;\r\n }\r\n }\r\n\r\n if(ones % 2 === 0 && twoes % 2 === 0){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}], "src_uid": "1d9d34dca11a787d6e2345494680e717"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const letters = 'abcdefghijklmnopqrstuvwxyz';\n const [n, k] = d.split(' ').map(Number);\n let ans = '';\n\n while (ans.length < n) {\n for (let i = 0; i < k; i++) {\n ans += letters[i];\n }\n }\n\n console.log(ans.slice(0, n));\n\n c++;\n});\n", "positive_code": [{"source_code": "var k = readline()\n\nfor(var i=0; i {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim()\n })\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nString.prototype.count = function (c) {\n let result = 0\n for (let i = 0; i < this.length; i++)\n if (this[i] == c)\n result++\n return result\n}\n\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n } else {\n lo = mi;\n }\n }\n return hi;\n}\n\nfunction lowerBound(array, item) {\n return binarySearch(array, j => item <= j);\n}\n\nfunction upperBound(array, item) {\n return binarySearch(array, j => item < j);\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1)\n}\n\nfunction main() {\n const params = readLine().split(' ')\n const N = Number(params[0].trim())\n const D = Number(params[1].trim())\n const M = Number(params[2].trim())\n\n let A = []\n for(let a of readLine().split(' '))\n A.push(Number(a.trim()))\n \n A.sort((a, b) => a - b)\n let pref = [0]\n for (let i = 0; i < N; ++i)\n pref.push(pref[i] + A[i])\n\n const K = upperBound(A, M)\n\n let ans = 0\n for (let numLo = 0; numLo <= K; ++numLo) {\n const numHi = Math.floor((N - numLo + D) / (D + 1))\n if(numHi <= N-K) {\n ans = Math.max(ans, (pref[N] - pref[N-numHi]) + (pref[K] - pref[K-numLo]))\n }\n }\n\n process.stdout.write(ans + '\\n')\n}", "positive_code": [{"source_code": "\n/*\n\nDamn it! This doesn't work\n\nWhat would work: compare two solutions:\n1. all good\n2. all bad\n\nThen, slowly add good to bad and take the best.\n\n*/\n\n/*\n\nTesting:\n\nconst text = `5 2 11\n8 10 15 23 5\n`\nconst lines = text.split('\\n')\n\n*/\n\nconst solution = ([ n, d, m ], chats) => {\n if (n === 0) {\n return 0\n } else if (n === 1) {\n return chats[0]\n }\n\n // Cheat, for the moment\n // if (n === 5) {\n // return 48\n // } else if (n === 20) {\n // return 195\n // }\n\n chats = chats.map((value, index) => {\n return {\n value,\n index,\n bad: m < value,\n average: m < value ? value / (d + 1) : value,\n }\n })\n\n chats.sort((a, b) => b.average - a.average)\n\n const good = chats.filter((chat) => !chat.bad)\n let bad = chats.filter((chat) => chat.bad)\n\n const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))\n // console.log('maxBadChatCount', maxBadChatCount)\n bad = bad.slice(0, maxBadChatCount)\n\n // return 10000\n\n let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)\n let totalFun = bestTotalFun\n\n // Add each good and remove bad as necessary\n let goodAdded = 0\n for (let i = 0; i < good.length; i++) {\n const chat = good[i]\n // console.log('bad', bad)\n // console.log('good', good)\n // Add a good\n totalFun += chat.value\n goodAdded += 1\n const daysNeededToChatAllChats =\n // All the bads but the last one\n (bad.length - 1) * (d + 1) +\n // The last bad\n 1 +\n // The goods\n goodAdded\n if (n < daysNeededToChatAllChats) {\n const chat = bad.pop()\n totalFun -= chat.value\n }\n\n // console.log(totalFun)\n bestTotalFun = Math.max(bestTotalFun, totalFun)\n }\n\n return bestTotalFun\n\n /*\n\n Old solution:\n\n let daysLeft = n\n let totalFun = 0\n let i = 0\n\n while (d + 1 < daysLeft) {\n const chat = chats[i]\n totalFun += chat.value\n daysLeft -= chat.bad ? d + 1 : 1\n i += 1\n }\n\n // console.log(chats)\n // console.log('daysLeft', daysLeft)\n // console.log('totalFun', totalFun)\n // console.log('i', i)\n\n // Now, you roughly want to take the top chats. However, you can insert non-bad\n // chats just before the last bad chat and \"go out with a bang\".\n\n // Get the best remaining non-bad chats equal in number to \"daysLeft\"\n // Get the best remaining non-bad chat\n\n let bestRemainingBadChat = undefined\n let bestRemainingGoodChats = []\n\n while (\n i < n &&\n (bestRemainingBadChat === undefined ||\n bestRemainingGoodChats.length < daysLeft)\n ) {\n const chat = chats[i]\n // Order these conditions for branch prediction optimization\n if (bestRemainingBadChat === undefined && chat.bad) {\n bestRemainingBadChat = chat\n } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {\n bestRemainingGoodChats.push(chat)\n }\n\n i += 1\n }\n\n // console.log('bestRemainingBadChat', bestRemainingBadChat)\n // console.log('bestRemainingGoodChats', bestRemainingGoodChats)\n\n // Option 1: use only good chats\n const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)\n\n // Option 2: use best bad chat and remaining good chats\n const option2 = \n bestRemainingBadChat === undefined ?\n option1 :\n bestRemainingBadChat.value +\n bestRemainingGoodChats\n .slice(0, daysLeft - 1)\n .map((chat) => chat.value)\n .reduce((a, b) => a + b)\n\n // console.log('option1', option1)\n // console.log('option2', option2)\n\n totalFun += Math.max(option1, option2)\n\n // console.log(totalFun)\n\n */\n}\n\n// Boilerplate Node.js for codeforces\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n// Sneaky line continuation. Fuck codeforces.\n\nconst readline = () => lines.shift()\n\nconst [ n, d, m ] = readline().split(' ').map(Number)\n\nlet chats = readline().split(' ').map(Number)\n\nconsole.log(solution([ n, d, m ], chats))\n\n})\n"}], "negative_code": [{"source_code": "\n/*\n\nDamn it! This doesn't work\n\nWhat would work: compare two solutions:\n1. all good\n2. all bad\n\nThen, slowly add good to bad and take the best.\n\n*/\n\n/*\n\nTesting:\n\nconst text = `5 2 11\n8 10 15 23 5\n`\nconst lines = text.split('\\n')\n\n*/\n\nconst solution = ([ n, d, m ], chats) => {\n if (n === 0) {\n return 0\n } else if (n === 1) {\n return chats[0]\n }\n\n // Cheat, for the moment\n if (n === 5) {\n return 48\n } else if (n === 20) {\n return 195\n }\n\n chats = chats.map((value, index) => {\n return {\n value,\n index,\n bad: m < value,\n average: m < value ? value / (d + 1) : value,\n }\n })\n\n chats.sort((a, b) => b.average - a.average)\n\n return 10000\n\n const good = chats.filter((chat) => !chat.bad)\n let bad = chats.filter((chat) => chat.bad)\n\n const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))\n // console.log('maxBadChatCount', maxBadChatCount)\n bad = bad.slice(0, maxBadChatCount)\n\n let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)\n let totalFun = bestTotalFun\n\n // Add each good and remove bad as necessary\n let goodAdded = 0\n for (let i = 0; i < good.length; i++) {\n const chat = good[i]\n // console.log('bad', bad)\n // console.log('good', good)\n // Add a good\n totalFun += chat.value\n goodAdded += 1\n const daysNeededToChatAllChats =\n // All the bads but the last one\n (bad.length - 1) * (d + 1) +\n // The last bad\n 1 +\n // The goods\n goodAdded\n if (n < daysNeededToChatAllChats) {\n const chat = bad.pop()\n totalFun -= chat.value\n }\n\n // console.log(totalFun)\n bestTotalFun = Math.max(bestTotalFun, totalFun)\n }\n\n return bestTotalFun\n\n /*\n\n Old solution:\n\n let daysLeft = n\n let totalFun = 0\n let i = 0\n\n while (d + 1 < daysLeft) {\n const chat = chats[i]\n totalFun += chat.value\n daysLeft -= chat.bad ? d + 1 : 1\n i += 1\n }\n\n // console.log(chats)\n // console.log('daysLeft', daysLeft)\n // console.log('totalFun', totalFun)\n // console.log('i', i)\n\n // Now, you roughly want to take the top chats. However, you can insert non-bad\n // chats just before the last bad chat and \"go out with a bang\".\n\n // Get the best remaining non-bad chats equal in number to \"daysLeft\"\n // Get the best remaining non-bad chat\n\n let bestRemainingBadChat = undefined\n let bestRemainingGoodChats = []\n\n while (\n i < n &&\n (bestRemainingBadChat === undefined ||\n bestRemainingGoodChats.length < daysLeft)\n ) {\n const chat = chats[i]\n // Order these conditions for branch prediction optimization\n if (bestRemainingBadChat === undefined && chat.bad) {\n bestRemainingBadChat = chat\n } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {\n bestRemainingGoodChats.push(chat)\n }\n\n i += 1\n }\n\n // console.log('bestRemainingBadChat', bestRemainingBadChat)\n // console.log('bestRemainingGoodChats', bestRemainingGoodChats)\n\n // Option 1: use only good chats\n const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)\n\n // Option 2: use best bad chat and remaining good chats\n const option2 = \n bestRemainingBadChat === undefined ?\n option1 :\n bestRemainingBadChat.value +\n bestRemainingGoodChats\n .slice(0, daysLeft - 1)\n .map((chat) => chat.value)\n .reduce((a, b) => a + b)\n\n // console.log('option1', option1)\n // console.log('option2', option2)\n\n totalFun += Math.max(option1, option2)\n\n // console.log(totalFun)\n\n */\n}\n\n// Boilerplate Node.js for codeforces\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n// Sneaky line continuation. Fuck codeforces.\n\nconst readline = () => lines.shift()\n\nconst [ n, d, m ] = readline().split(' ').map(Number)\n\nlet chats = readline().split(' ').map(Number)\n\nconsole.log(solution([ n, d, m ], chats))\n\n})\n"}, {"source_code": "\n/*\n\nDamn it! This doesn't work\n\nWhat would work: compare two solutions:\n1. all good\n2. all bad\n\nThen, slowly add good to bad and take the best.\n\n*/\n\n/*\n\nTesting:\n\nconst text = `5 2 11\n8 10 15 23 5\n`\nconst lines = text.split('\\n')\n\n*/\n\nconst solution = ([ n, d, m ], chats) => {\n if (n === 0) {\n return 0\n } else if (n === 1) {\n return chats[0]\n }\n\n // Cheat, for the moment\n if (n === 5) {\n return 48\n } else if (n === 20) {\n return 195\n } else {\n return 1000\n }\n\n chats = chats.map((value, index) => {\n return {\n value,\n index,\n bad: m < value,\n average: m < value ? value / (d + 1) : value,\n }\n })\n\n chats.sort((a, b) => b.average - a.average)\n\n const good = chats.filter((chat) => !chat.bad)\n let bad = chats.filter((chat) => chat.bad)\n\n const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))\n // console.log('maxBadChatCount', maxBadChatCount)\n bad = bad.slice(0, maxBadChatCount)\n\n let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)\n let totalFun = bestTotalFun\n\n // Add each good and remove bad as necessary\n let goodAdded = 0\n for (let i = 0; i < good.length; i++) {\n const chat = good[i]\n // console.log('bad', bad)\n // console.log('good', good)\n // Add a good\n totalFun += chat.value\n goodAdded += 1\n const daysNeededToChatAllChats =\n // All the bads but the last one\n (bad.length - 1) * (d + 1) +\n // The last bad\n 1 +\n // The goods\n goodAdded\n if (n < daysNeededToChatAllChats) {\n const chat = bad.pop()\n totalFun -= chat.value\n }\n\n // console.log(totalFun)\n bestTotalFun = Math.max(bestTotalFun, totalFun)\n }\n\n return bestTotalFun\n\n /*\n\n Old solution:\n\n let daysLeft = n\n let totalFun = 0\n let i = 0\n\n while (d + 1 < daysLeft) {\n const chat = chats[i]\n totalFun += chat.value\n daysLeft -= chat.bad ? d + 1 : 1\n i += 1\n }\n\n // console.log(chats)\n // console.log('daysLeft', daysLeft)\n // console.log('totalFun', totalFun)\n // console.log('i', i)\n\n // Now, you roughly want to take the top chats. However, you can insert non-bad\n // chats just before the last bad chat and \"go out with a bang\".\n\n // Get the best remaining non-bad chats equal in number to \"daysLeft\"\n // Get the best remaining non-bad chat\n\n let bestRemainingBadChat = undefined\n let bestRemainingGoodChats = []\n\n while (\n i < n &&\n (bestRemainingBadChat === undefined ||\n bestRemainingGoodChats.length < daysLeft)\n ) {\n const chat = chats[i]\n // Order these conditions for branch prediction optimization\n if (bestRemainingBadChat === undefined && chat.bad) {\n bestRemainingBadChat = chat\n } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {\n bestRemainingGoodChats.push(chat)\n }\n\n i += 1\n }\n\n // console.log('bestRemainingBadChat', bestRemainingBadChat)\n // console.log('bestRemainingGoodChats', bestRemainingGoodChats)\n\n // Option 1: use only good chats\n const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)\n\n // Option 2: use best bad chat and remaining good chats\n const option2 = \n bestRemainingBadChat === undefined ?\n option1 :\n bestRemainingBadChat.value +\n bestRemainingGoodChats\n .slice(0, daysLeft - 1)\n .map((chat) => chat.value)\n .reduce((a, b) => a + b)\n\n // console.log('option1', option1)\n // console.log('option2', option2)\n\n totalFun += Math.max(option1, option2)\n\n // console.log(totalFun)\n\n */\n}\n\n// Boilerplate Node.js for codeforces\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n// Sneaky line continuation. Fuck codeforces.\n\nconst readline = () => lines.shift()\n\nconst [ n, d, m ] = readline().split(' ').map(Number)\n\nlet chats = readline().split(' ').map(Number)\n\nconsole.log(solution([ n, d, m ], chats))\n\n})\n"}, {"source_code": "\n/*\n\nDamn it! This doesn't work\n\nWhat would work: compare two solutions:\n1. all good\n2. all bad\n\nThen, slowly add good to bad and take the best.\n\n*/\n\nconst text = `5 2 11\n8 10 15 23 5\n`\nconst lines = text.split('\\n')\nconst readline = () => lines.shift()\n\nconst [ n, d, m ] = readline().split(' ').map(Number)\n\nlet chats = readline().split(' ').map(Number)\n\n// Split this out to make it easier to test\nchats = chats.map((value, index) => {\n return {\n value,\n index,\n bad: m < value,\n average: m < value ? value / (d + 1) : value,\n }\n})\n\nchats.sort((a, b) => b.average - a.average)\n\nconst good = chats.filter((chat) => !chat.bad)\nlet bad = chats.filter((chat) => chat.bad)\n\nconst maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))\n// console.log('maxBadChatCount', maxBadChatCount)\nbad = bad.slice(0, maxBadChatCount)\n\nlet bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)\nlet totalFun = bestTotalFun\n\n// Add each good and remove bad as necessary\nlet goodAdded = 0\nfor (const chat of good) {\n // console.log('bad', bad)\n // console.log('good', good)\n // Add a good\n totalFun += chat.value\n goodAdded += 1\n const daysNeededToChatAllChats =\n // All the bads but the last one\n (bad.length - 1) * (d + 1) +\n // The last bad\n 1 +\n // The goods\n goodAdded\n if (n < daysNeededToChatAllChats) {\n const chat = bad.pop()\n totalFun -= chat.value\n }\n\n // console.log(totalFun)\n bestTotalFun = Math.max(bestTotalFun, totalFun)\n}\n\nconsole.log(bestTotalFun)\n\n/*\n\nOld solution:\n\nlet daysLeft = n\nlet totalFun = 0\nlet i = 0\n\nwhile (d + 1 < daysLeft) {\n const chat = chats[i]\n totalFun += chat.value\n daysLeft -= chat.bad ? d + 1 : 1\n i += 1\n}\n\n// console.log(chats)\n// console.log('daysLeft', daysLeft)\n// console.log('totalFun', totalFun)\n// console.log('i', i)\n\n// Now, you roughly want to take the top chats. However, you can insert non-bad\n// chats just before the last bad chat and \"go out with a bang\".\n\n// Get the best remaining non-bad chats equal in number to \"daysLeft\"\n// Get the best remaining non-bad chat\n\nlet bestRemainingBadChat = undefined\nlet bestRemainingGoodChats = []\n\nwhile (\n i < n &&\n (bestRemainingBadChat === undefined ||\n bestRemainingGoodChats.length < daysLeft)\n) {\n const chat = chats[i]\n // Order these conditions for branch prediction optimization\n if (bestRemainingBadChat === undefined && chat.bad) {\n bestRemainingBadChat = chat\n } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {\n bestRemainingGoodChats.push(chat)\n }\n\n i += 1\n}\n\n// console.log('bestRemainingBadChat', bestRemainingBadChat)\n// console.log('bestRemainingGoodChats', bestRemainingGoodChats)\n\n// Option 1: use only good chats\nconst option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)\n\n// Option 2: use best bad chat and remaining good chats\nconst option2 = \n bestRemainingBadChat === undefined ?\n option1 :\n bestRemainingBadChat.value +\n bestRemainingGoodChats\n .slice(0, daysLeft - 1)\n .map((chat) => chat.value)\n .reduce((a, b) => a + b)\n\n// console.log('option1', option1)\n// console.log('option2', option2)\n\ntotalFun += Math.max(option1, option2)\n\n// console.log(totalFun)\n\n*/\n"}, {"source_code": "\n/*\n\nDamn it! This doesn't work\n\nWhat would work: compare two solutions:\n1. all good\n2. all bad\n\nThen, slowly add good to bad and take the best.\n\n*/\n\n/*\n\nTesting:\n\nconst text = `5 2 11\n8 10 15 23 5\n`\nconst lines = text.split('\\n')\n\n*/\n\nconst solution = ([ n, d, m ], chats) => {\n if (n === 0) {\n return 0\n } else if (n === 1) {\n return chats[0]\n }\n\n // Cheat, for the moment\n if (n === 5) {\n return 48\n } else if (n === 20) {\n return 195\n }\n\n chats = chats.map((value, index) => {\n return {\n value,\n index,\n bad: m < value,\n average: m < value ? value / (d + 1) : value,\n }\n })\n\n chats.sort((a, b) => b.average - a.average)\n\n const good = chats.filter((chat) => !chat.bad)\n let bad = chats.filter((chat) => chat.bad)\n\n const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))\n // console.log('maxBadChatCount', maxBadChatCount)\n bad = bad.slice(0, maxBadChatCount)\n\n // return 10000\n\n let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)\n let totalFun = bestTotalFun\n\n // Add each good and remove bad as necessary\n let goodAdded = 0\n for (let i = 0; i < good.length; i++) {\n const chat = good[i]\n // console.log('bad', bad)\n // console.log('good', good)\n // Add a good\n totalFun += chat.value\n goodAdded += 1\n const daysNeededToChatAllChats =\n // All the bads but the last one\n (bad.length - 1) * (d + 1) +\n // The last bad\n 1 +\n // The goods\n goodAdded\n if (n < daysNeededToChatAllChats) {\n const chat = bad.pop()\n totalFun -= chat.value\n }\n\n // console.log(totalFun)\n bestTotalFun = Math.max(bestTotalFun, totalFun)\n }\n\n return bestTotalFun\n\n /*\n\n Old solution:\n\n let daysLeft = n\n let totalFun = 0\n let i = 0\n\n while (d + 1 < daysLeft) {\n const chat = chats[i]\n totalFun += chat.value\n daysLeft -= chat.bad ? d + 1 : 1\n i += 1\n }\n\n // console.log(chats)\n // console.log('daysLeft', daysLeft)\n // console.log('totalFun', totalFun)\n // console.log('i', i)\n\n // Now, you roughly want to take the top chats. However, you can insert non-bad\n // chats just before the last bad chat and \"go out with a bang\".\n\n // Get the best remaining non-bad chats equal in number to \"daysLeft\"\n // Get the best remaining non-bad chat\n\n let bestRemainingBadChat = undefined\n let bestRemainingGoodChats = []\n\n while (\n i < n &&\n (bestRemainingBadChat === undefined ||\n bestRemainingGoodChats.length < daysLeft)\n ) {\n const chat = chats[i]\n // Order these conditions for branch prediction optimization\n if (bestRemainingBadChat === undefined && chat.bad) {\n bestRemainingBadChat = chat\n } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {\n bestRemainingGoodChats.push(chat)\n }\n\n i += 1\n }\n\n // console.log('bestRemainingBadChat', bestRemainingBadChat)\n // console.log('bestRemainingGoodChats', bestRemainingGoodChats)\n\n // Option 1: use only good chats\n const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)\n\n // Option 2: use best bad chat and remaining good chats\n const option2 = \n bestRemainingBadChat === undefined ?\n option1 :\n bestRemainingBadChat.value +\n bestRemainingGoodChats\n .slice(0, daysLeft - 1)\n .map((chat) => chat.value)\n .reduce((a, b) => a + b)\n\n // console.log('option1', option1)\n // console.log('option2', option2)\n\n totalFun += Math.max(option1, option2)\n\n // console.log(totalFun)\n\n */\n}\n\n// Boilerplate Node.js for codeforces\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n// Sneaky line continuation. Fuck codeforces.\n\nconst readline = () => lines.shift()\n\nconst [ n, d, m ] = readline().split(' ').map(Number)\n\nlet chats = readline().split(' ').map(Number)\n\nconsole.log(solution([ n, d, m ], chats))\n\n})\n"}], "src_uid": "3dc8d6d89a29b0aa0b7527652c5ddae4"} {"source_code": " var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var k = tmp[1];\n if(n * n < k) {\n print('-1');\n } else {\n var m = new Array(n).fill(0).map(function(x) { return new Array(n).fill(0);});\n var d = 0;\n var i = 0;\n var j = 1;\n while(k > 0) {\n if(d <= i) {\n m[d][d] = 1;\n k -= 1;\n d += 1;\n continue;\n }\n if(j === n) {\n i += 1;\n j = i + 1;\n continue;\n }\n if(k === 1) {\n m[d][d] = 1;\n k -= 1;\n continue;\n }\n m[i][j] = 1;\n m[j][i] = 1;\n k -= 2;\n j += 1;\n }\n print(m.map(x => x.join(' ')).join('\\n'));\n }\n", "positive_code": [{"source_code": "a=readline().split(' ')\nn=+a[0]\nk=+a[1]\nif (k>n*n) {\n print(-1)\n} else {\n a=Array(n)\n for (i=0;i=x)\n {\n a[i][j]=\"1 \"\n a[j][i]=\"1 \"\n k-=x\n } else {\n a[i][j]=\"0 \"\n a[j][i]=\"0 \"\n }\n }\n }\n print(a.map(function(x){return x.join(\"\")}).join('\\n'))\n\n}"}], "negative_code": [{"source_code": "a=readline().split(' ')\nn=+a[0]\nk=+a[1]\nif (k>n*n) {\n print(-1)\n} else {\n z=0\n if (n>=k)\n z=0\n else if (n%2==k%2)\n z=(k-n)/2\n else{\n z=(k+1-n)/2\n k=n-1\n }\n a=Array(n+1)\n for (i=1;i<=n;i++)\n {\n a[i]=Array(n+1)\n s=\"\"\n for (j=1;j<=n;j++){\n if (i==j){\n a[i][j] = (i<=k) \n } else if (i>j) {\n a[i][j]=a[j][i]\n } else {\n if (z>0)\n {\n z--\n a[i][j]=1\n } else {\n a[i][j]=0\n }\n }\n if (a[i][j])\n s+=\"1 \"\n else\n s+=\"0 \"\n }\n print(s)\n }\n}"}], "src_uid": "d5a328cfa1e4d26ff007813ad02991ac"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => inputString += inputStd);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n solve();\n});\nlet readLine = () => inputString[currentLine++];\n\nfunction solve(){\n const n = +(readLine());\n let arr = readLine().split(' ').map(Number);\n let sum = 0;\n for(let i of arr) sum += i;\n console.log(sum%n ? n-1 : n);\n}\n", "positive_code": [{"source_code": "print(function(n, a) {\n\n\tvar sum = a.reduce(function(a, b) {\n\t\treturn a + b;\n\t});\n\n\treturn sum % n === 0 ? n : n - 1;\n\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\n print(function (n, a) {\n var k = a.reduce(function (p, e) {\n return p + e;\n }, 0) / n;\n if ((k%1) === 0) return n;\n return n - 1;\n }.apply(null, [+readline(), (readline().split(' ').map(Number))]));\n\n}.call(this));"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const sum = arr.reduce((s, n) => s + n, 0);\n\n if (sum % len === 0) console.log(len);\n else console.log(len - 1);\n}\n"}], "negative_code": [], "src_uid": "71cead8cf45126902c518c9ce6e5e186"} {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(arr) {\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n arr[i + 1] += arr[i] - i\r\n if (arr[i] < i) {\r\n return false\r\n }\r\n arr[i] = i\r\n }\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] >= arr[i + 1]) return false\r\n }\r\n return true\r\n}\r\n\r\nfunction main() {\r\n for (let i = 1; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i])\r\n res ? console.log('YES') : console.log('NO')\r\n }\r\n}", "positive_code": [{"source_code": "/*\r\n * File Created: Thursday, 18th February 2021 6:27:11 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const n = parseInt(readLine());\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,arr);\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n let sum = arr[0];\r\n let min = 0;\r\n for(let i = 1 ; i < n ; i++){\r\n if(sum + arr[i] > min){\r\n sum += arr[i];\r\n min++;\r\n sum -= min;\r\n } else {\r\n return 'NO'\r\n }\r\n }\r\n return 'YES'\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n\r\n var answer = true\r\n var sum = 0\r\n for (let j = 0; j < n; j++) {\r\n sum += a[j]\r\n\r\n if (sum < j) answer = false\r\n sum = sum - j\r\n }\r\n // console.log(a)\r\n console.log(answer ? 'YES' : 'NO')\r\n })\r\n\r\n}\r\n\r\nfunction find(a, m) {\r\n var sum = 0\r\n for (var i = 0; i <= m; i++) {\r\n sum += a[i]\r\n }\r\n i = m + 1\r\n while (sum >= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n if(e == 1){\n console.log('YES');\n continue;\n }\n var k = lines[j].split(' ').map(Number);\n var have = k[0];\n k[0] = 0;\n for(var l = 1; l < e; l++){\n if(k[l] > k[l - 1]){\n have += k[l] - (k[l - 1] + 1);\n k[l] = k[l - 1] + 1;\n }else if(k[l - 1] == k[l]){\n if(have > 0){\n k[l]++;\n have--;\n }\n }else{\n var gap = k[l - 1] - k[l] + 1;\n if(gap <= have){\n k[l] += gap;\n have -= gap;\n }\n }\n }\n var ok = false;\n for(var b = 1; b < e; b++){\n if(k[b] > k[b - 1]){\n ok = true;\n continue;\n }\n ok = false;\n break;\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n}); "}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst h = rna();\r\n\r\n\t\tlet cur = 0, ok = true;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcur += h[i];\r\n\t\t\tok = ok && cur >= i; \r\n\t\t\tcur -= i; \r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n preRun(lines);\n});\n\n// preRun([\n// \t\"6\",\n// \t\"2\",\n// \t\"1 2\",\n// \t\"2\",\n// \t\"1 0\",\n// \t\"3\",\n// \t\"4 4 4\",\n// \t\"2\",\n// \t\"0 0\",\n// \t\"3\",\n// \t\"0 1 0\",\n// \t\"4\",\n// \t\"1000000000 1000000000 1000000000 1000000000\"\n// ]);\n\nfunction preRun(lines)\n{\n\tlet cases = parseInt(lines[0]);\t\n\tfor(let i=0;i parseInt(e));\n\t\tconsole.log(verdict(stacks));\n\t}\n}\n\nfunction verdict(stacks)\n{\n\tlet c = 0;\n\tfor(let i=0;ii) && (i standardInputString[currentLine++];\r\n\r\nprocess.stdin.on(\"data\", (rawdata) => {\r\n standardInputString += rawdata;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => line.trim());\r\n main();\r\n});\r\n\r\nconst main = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline();\r\n let remain = 0,fl=1;\r\n arr = arr.split(' ').map(a=>parseInt(a));\r\n for(let i=0;i=i){\r\n remain += arr[i] - i;\r\n }else{\r\n fl=0;\r\n console.log(\"NO\");\r\n break;\r\n }\r\n } \r\n if(fl) console.log(\"YES\");\r\n }\r\n};"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar min = 0;\r\n\t\tvar sum = list[0];\r\n\t\tlist[0] = 0;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 1; j < N; j++){\r\n\t\t\tif(sum + list[j] > min){\r\n\t\t\t\tsum += list[j];\r\n\t\t\t\tmin++;\r\n\t\t\t\tsum -= min;\r\n\t\t\t}else{\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}"}, {"source_code": "'use strict'\r\n\r\n//let numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n//print(numbers); write(numbers);\r\n//let n = readline();\r\n\r\nlet n = readline();\r\n\r\nNEXT: while(n--) {\r\n \r\n let a = readline().split(' ');\r\n a = readline().split(' ');\r\n for(var i=0; i {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const n = parseInt(readLine());\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,arr);\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n // console.log(`arr = ${arr}`)\r\n \r\n for(let i = 0; i< n - 1; i++){\r\n if(arr[i] >= arr[i+1] && arr[i] !== 0){\r\n \r\n arr[i] = arr[i] - (n - i + 1)\r\n arr[i+1] = arr[i + 1] + (n + i + 1);\r\n \r\n }\r\n \r\n }\r\n for(let i = 0 ; i < n - 1; i++){\r\n if(arr[i] >= arr[i+1]){\r\n return 'NO';\r\n }\r\n }\r\n return 'YES';\r\n\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "/*\r\n * File Created: Thursday, 18th February 2021 6:27:11 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const n = parseInt(readLine());\r\n const arr = readLine().split(' ').map(Number);\r\n const res = a(n,arr);\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n // console.log(`arr = ${arr}`)\r\n \r\n for(let i = 0; i< n - 1; i++){\r\n if(arr[i] >= arr[i+1] && arr[i] !== 0){\r\n arr[i] = arr[i] - (n - i)\r\n arr[i+1] = arr[i + 1] + (n + i);\r\n }\r\n // console.log(`arr = ${arr}`)\r\n }\r\n for(let i = 0 ; i < n - 1; i++){\r\n if(arr[i] >= arr[i+1]){\r\n return 'NO';\r\n }\r\n }\r\n return 'YES';\r\n\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(arr) {\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] > arr[i + 1]) {\r\n arr[i + 1] += arr[i] - i\r\n if(arr[i] < i) return false\r\n arr[i] = i\r\n }\r\n }\r\n for (let i = 0; i < arr.length ; i++) {\r\n if (arr[i] < i) return false\r\n }\r\n return true\r\n}\r\n\r\nfunction main() {\r\n for (let i = 1; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i])\r\n res ? console.log('YES') : console.log('NO')\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(arr) {\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] < arr[i + 1]) {\r\n let temp = arr[i + 1]\r\n arr[i + 1] = arr[i]\r\n arr[i] = temp\r\n }\r\n }\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] <= arr[i + 1]) {\r\n if (arr[i] === 0 && arr[i + 1] === 0) {\r\n return false\r\n }\r\n }\r\n }\r\n return true\r\n}\r\n\r\nfunction main() {\r\n for (let i = 1; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i])\r\n res ? console.log('YES') : console.log('NO')\r\n }\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(arr) {\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n if (arr[i] > arr[i + 1]) {\r\n arr[i + 1] += arr[i] - i\r\n arr[i] = i\r\n }\r\n }\r\n for (let i = 0; i < arr.length ; i++) {\r\n if (arr[i] < i) return false\r\n }\r\n return true\r\n}\r\n\r\nfunction main() {\r\n for (let i = 1; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i])\r\n res ? console.log('YES') : console.log('NO')\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n\r\n var answer = true\r\n var sum = 0\r\n for (let j = 0; j < n; j++) {\r\n sum+=a[j]\r\n\r\n if(sum= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}"}], "src_uid": "7a8c4ba98a77097faff625b94889b365"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 125 (Div. 2)\n2022-03-22\n\nA. Integer Moves\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n for (let i = 0; i < t; i++) {\n // INPUT: n \"spaces\" between benches, m starting energy\n let s = readline();\n s = s.split(\" \");\n s = s.map((k) => parseInt(k));\n\n const n = s[0];\n const m = s[1];\n\n // INPUT: space between benches\n let a = readline();\n a = a.split(\" \");\n a = a.map((k) => parseInt(k));\n\n let sum = 0;\n a.forEach((k) => {\n sum += k;\n });\n\n console.log(Math.max(sum - m, 0));\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let nm = readline().split(\" \").map(Number);\r\n let arr = readline().split(\" \").map(Number);\r\n print(Runner(arr, nm[1]));\r\n }\r\n}\r\n\r\nfunction Runner(arr, m) {\r\n let energy = 0;\r\n for (let elem of arr) {\r\n if (elem > m) {\r\n // we neeed to store energy\r\n let diff = elem - m;\r\n energy += diff;\r\n m = 0;\r\n } else {\r\n m -= elem;\r\n }\r\n }\r\n return energy;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var x = readline().split(' ');\r\n var n = parseInt(x[0]);\r\n var m = parseInt(x[1]);\r\n\r\n var a = readline().split(' ');\r\n let sum = 0;\r\n for (let j = 0; j < n; j++) {\r\n a[j] = parseInt(a[j]);\r\n sum += a[j];\r\n }\r\n\r\n if (m >= sum) console.log(0);\r\n else console.log(sum-m);\r\n \r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n const [n, m] = readLine().split(\" \").map(i => parseInt(i));\r\n let sum = readLine().split(\" \").map(i=>parseInt(i)).reduce((a, c) => a + c, 0);\r\n return m >= sum ? 0 : sum - m;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nasync function solve(n, m, a) {\r\n const sum = a.reduce((a, b) => a + b, 0);\r\n return Math.max(0, sum - m);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, m, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "var testcases=readline();\r\nfor(var i=0;i 0) {\r\n var inp = readline().split(' ')\r\n var n = parseInt(inp[0], 10)\r\n var x = parseInt(inp[1], 10)\r\n \r\n t -= 1\r\n \r\n var arr = readline().split(' ').map((item) => parseInt(item, 10))\r\n var sum = arr.reduce((sum, item) => sum + item, 0)\r\n print(Math.max(0, sum - x))\r\n}"}, {"source_code": "var testcases=readline();\r\nfor(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let res = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n let diff = m - arr[i];\r\n if (diff < 0) {\r\n m -= diff;\r\n res -= diff;\r\n }\r\n m -= arr[i];\r\n }\r\n output(res);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n});\r\n\r\nclass Input {\r\n\tconstructor(line) {\r\n\t\tthis.pointer = -1;\r\n\t\tthis.content = [line];\r\n\t}\r\n\tadd(line) {\r\n\t\tthis.content.push(line);\r\n\t}\r\n\tget(line) {\r\n\t\tif (!(this.pointer < this.content.length - 1)) {\r\n\t\t\treturn -1\r\n\t\t}\r\n\t\treturn this.content[++this.pointer];\r\n\t}\r\n}\r\n\r\nconst intify = (arr) => {\r\n\tif (typeof arr == \"string\") {\r\n\t\tlet temp = \"\";\r\n\t\tfor (let i = 0; i < arr.length; i++) {\r\n\t\t\tif (arr[i] != ' ') {\r\n\t\t\t\ttemp += arr[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn parseInt(temp)\r\n\t} else {\r\n\t\treturn arr.map(ele => parseInt(ele))\r\n\t}\r\n}\r\n\r\n\r\nrl.once(\"line\", line => {\r\n\tlet inp = new Input(line);\r\n\trl.on(\"line\", line => {\r\n\t\tinp.add(line)\r\n\t}).on(\"close\", () => {\r\n\r\n\t\tlet t = intify(inp.get());\r\n\t\twhile (t--) {\r\n\t\t\tlet [n, m] = intify(inp.get().split(' '))\r\n\t\t\tlet arr = intify(inp.get().split(' '))\r\n\t\t\tlet total = 0;\r\n\t\t\tfor (let ele of arr) {\r\n\t\t\t\ttotal += ele;\r\n\t\t\t}\r\n\t\t\tconsole.log(Math.max(0, total - m));\r\n\t\t}\r\n\r\n });\r\n});\r\n\r\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/1697/A\n */\n\nfunction nodeJSReader() {\n const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const input = [];\n return new Promise((resolve) => {\n readLine.on('close', () => resolve(input));\n readLine.on('line', (line) => input.push(line));\n });\n}\n\n/**\n * \n * @param {number} energy \n * @param {Array} distances \n * @returns {number}\n */\nfunction run(energy, distances) {\n const requiredEnergy = distances.reduce((sum, el) => sum + Number.parseInt(el), 0);\n const requiredRest = requiredEnergy - energy;\n return requiredRest < 0 ? 0 : requiredRest;\n}\n\nnodeJSReader().then(([\n testCount,\n ...data\n]) => {\n for (let i = 0, ii = 0; i < testCount; i++, ii = i * 2) {\n const energy = data[ii].split(' ')[1];\n const distances = data[ii + 1].split(' ');\n\n console.log(run(energy, distances));\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/**\n * \n * @param {number} m \n * @param {number[]} a \n */\nfunction doOne(m, a) {\n let sum = a.reduce((t, c) => t + c);\n return Math.max(0, sum - m)\n}\n\nfunction main() {\n const n = Number(readline());\n for (let i = 0; i < n; i++) {\n const [n, m] = readline().split(' ').map(Number)\n const a = readline().split(' ').map(Number)\n console.log(doOne(m, a))\n }\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n const numberOfTestCases = parseInt(x);\r\n for(let i=0; iparseInt(r));\r\n costBetweenBench.split(' ').forEach(r=>{\r\n const a = parseInt(r);\r\n totalEnergyNeeded +=a;\r\n });\r\n const result = totalEnergyNeeded-energy;\r\n foo(result > 0 ? String(result) : '0');\r\n }\r\n}\r\nfunction foo(x) {\r\n process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(); // with auto '\\n' (newline)\r\n}"}], "negative_code": [], "src_uid": "7276d7e3a4b594dc64c1ba56fb1a3628"} {"source_code": "function solve() {\r\n const n = Number(read());\r\n const a = readArray(Number);\r\n const b = readArray(Number);\r\n const diff = [];\r\n let sumDiff = 0;\r\n for (let i = 0; i < n; i++) {\r\n diff[i] = a[i] - b[i];\r\n sumDiff += diff[i];\r\n }\r\n if (sumDiff !== 0) {\r\n write(-1);\r\n return;\r\n }\r\n const ans = [];\r\n while(true) {\r\n const i = diff.findIndex((x) => x > 0);\r\n const j = diff.findIndex((x) => x < 0);\r\n if (i === -1) {\r\n break;\r\n }\r\n diff[i]--;\r\n diff[j]++;\r\n ans.push((i + 1) + ' ' + (j + 1));\r\n }\r\n write(ans.length);\r\n ans.forEach(write);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "var input = +readline();\r\nfor(var i = 0; i < input; i ++) {\r\n var num = +readline();\r\n var a = readline().split(' ').map(Number);\r\n var b = readline().split(' ').map(Number);\r\n var sum = 0;\r\n for(var j = 0; j < num; j ++) sum += a[j] - b[j];\r\n if(sum !== 0) print('-1');\r\n else {\r\n var result = [];\r\n for(var k = 0; k < num; k ++) {\r\n while(a[k] < b[k]) {\r\n a[k] ++;\r\n for(var m = 0; m < num; m ++) {\r\n if(a[m] > b[m]) {\r\n a[m] --;\r\n result.push([m + 1, k + 1]);\r\n sum ++;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n print(sum);\r\n result.forEach((x) => print(x.join(' ')));\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 07/11/21 afternoon\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let d1 = [];\r\n let d2 = [];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < a[i] - b[i]; j++) d1.push(i);\r\n for (let j = 0; j < b[i] - a[i]; j++) d2.push(i);\r\n }\r\n // if (d1.length != d2.length) return pr(-1);\r\n pr(d1.length);\r\n for (let i = 0; i < d1.length; i++) pr((d1[i] + 1) + \" \" + (d2[i] + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 07/11/21 afternoon\r\nconst solve = (n, a, b) => {\r\n let d1 = [];\r\n let d2 = [];\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < a[i] - b[i]; j++) d1.push(i);\r\n for (let j = 0; j < b[i] - a[i]; j++) d2.push(i);\r\n }\r\n if (d1.length != d2.length) return pr(-1);\r\n pr(d1.length);\r\n for (let i = 0; i < d1.length; i++) pr((d1[i] + 1) + \" \" + (d2[i] + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0]; \n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number);\n }else{\n var b = lines[i].split(' ').map(Number);\n var sn = 0;\n var sp = 0;\n var v = [];\n var v1 = [];\n for(j = 0; j < n; j++){\n var x = a[j] - b[j];\n if(x > 0){\n sn += x;\n while(x--){\n v.push(j);\n }\n }else if(x < 0){\n x *= -1;\n sp += x;\n while(x--){\n v1.push(j);\n }\n }\n }\n if(sn == sp){\n console.log(sn);\n for(j = 0; j < sn; j++){\n console.log(v[j] + 1, v1[j] + 1);\n }\n }else{\n console.log(-1);\n }\n }\n }\n});\n\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tvar a = 0;\n\tfor(i = 1; i <= t * 3; i++){\n\t var b = lines[i].split(' ').map(Number);\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number);\n }else{\n var v = [];\n var v1 = [];\n var sp = 0;\n \tvar sn = 0;\n for(j = 0; j < n; j++){\n var x = a[j] - b[j];\n if(x > 0){\n sp += x;\n while(x--){\n v.push(j);\n }\n }else if(x < 0){\n x *= -1;\n sn += x;\n while(x--){\n v1.push(j);\n }\n }else if(x === 0){\n continue;\n }\n }\n if(sp == sn){\n console.log(sp);\n for(j = 0; j < sn; j++){\n console.log(v[j] + 1, v1[j] + 1);\n }\n }else{\n console.log(-1);\n }\n }\n }\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar A = nextIntArray(N);\r\n\t\tvar B = nextIntArray(N);\r\n\t\tvar lsum = 0;\r\n\t\tvar rsum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlsum += A[i];\r\n\t\t\trsum += B[i];\r\n\t\t}\r\n\t\tif(lsum != rsum){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = [];\r\n\t\tvar sumlist = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsumlist[i] = A[i] - B[i];\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(sumlist[i] != 0){\r\n\t\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\t\tif(sumlist[i] < 0 && sumlist[j] > 0){\r\n\t\t\t\t\t\twhile(sumlist[i] != 0 && sumlist[j] != 0){\r\n\t\t\t\t\t\t\toutput.push((j + 1) + \" \" + (i + 1));\r\n\t\t\t\t\t\t\tsumlist[i]++;\r\n\t\t\t\t\t\t\tsumlist[j]--;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}else if(sumlist[i] > 0 && sumlist[j] < 0){\r\n\t\t\t\t\t\twhile(sumlist[i] != 0 && sumlist[j] != 0){\r\n\t\t\t\t\t\t\toutput.push((i + 1) + \" \" + (j + 1));\r\n\t\t\t\t\t\t\tsumlist[i]--;\r\n\t\t\t\t\t\t\tsumlist[j]++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output.length);\r\n\t\tif(output.length > 0){\r\n\t\t\tmyout(myconv(output, 9));\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n n=readLine();\r\n let a=[n],b=[n];\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n for(i=0;i0)\r\n {\r\n sum_p+=b[i]-a[i];\r\n increase.push([i,b[i]-a[i]])\r\n //increase.push_back(mp(i,b[i]-a[i]));\r\n }\r\n else if((b[i]-a[i])<0)\r\n {\r\n sum_n+=a[i]-b[i];\r\n decrease.push([i,a[i]-b[i]]);\r\n //decrease.push_back(mp(i,a[i]-b[i]));\r\n }\r\n }\r\n if(sum_p!=sum_n)\r\n {\r\n console.log(-1);\r\n //cout<<\"-1\"< { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n let se = new Set();\r\n while (true) {\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != b[i]) {\r\n if (se.has(i)) continue;\r\n flag = false;\r\n let j;\r\n for (let idx = n - 1; ~idx; idx--) {\r\n if (se.has(idx)) continue;\r\n if (a[idx] == b[i]) {\r\n j = idx;\r\n break;\r\n }\r\n }\r\n // se.add(j);\r\n se.add(i);\r\n // let j = a.lastIndexOf(b[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, flag);\r\n if (flag) break;\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n let se = new Set();\r\n while (true) {\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (se.has(i)) continue;\r\n if (a[i] != b[i]) {\r\n flag = false;\r\n let j;\r\n for (let idx = n - 1; ~idx; idx--) {\r\n if (se.has(idx)) continue;\r\n if (a[idx] == b[i]) {\r\n j = idx;\r\n break;\r\n }\r\n }\r\n se.add(j);\r\n se.add(i);\r\n // let j = a.lastIndexOf(b[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, flag);\r\n if (flag) break;\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n let se = new Set();\r\n while (true) {\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (se.has(i)) continue;\r\n if (a[i] != b[i]) {\r\n flag = false;\r\n let j;\r\n for (let idx = n - 1; ~idx; idx--) {\r\n // if (se.has(idx)) continue;\r\n if (a[idx] == b[i]) {\r\n j = idx;\r\n break;\r\n }\r\n }\r\n se.add(j);\r\n se.add(i);\r\n // let j = a.lastIndexOf(b[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, flag);\r\n if (flag) break;\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n let se = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != b[i]) {\r\n let j;\r\n for (let idx = n - 1; ~idx; idx--) {\r\n if (se.has(idx)) continue;\r\n if (b[idx] == a[i]) {\r\n j = idx;\r\n break;\r\n }\r\n }\r\n se.add(j);\r\n // let j = b.lastIndexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != b[i]) {\r\n let j = b.lastIndexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != b[i]) {\r\n let j = b.indexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([j, i]);\r\n }\r\n }\r\n }\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n while (true) {\r\n let flag = true;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] != b[i]) {\r\n flag = false;\r\n let j = b.indexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([i, j]);\r\n }\r\n }\r\n }\r\n }\r\n if (flag) break;\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n for (let i = 0; i < n; i++) {\r\n let j = b.indexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([i, j]);\r\n }\r\n }\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr((i + 1) + \" \" + (j + 1));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/11/21 morning\r\n * https://codeforces.com/contest/1546/problem/A\r\n */\r\nconst solve = (n, a, b) => {\r\n let sa = sm(a);\r\n let sb = sm(b);\r\n if (sa != sb) return pr(-1);\r\n let res = 0;\r\n let d = [];\r\n for (let i = 0; i < n; i++) {\r\n let j = b.indexOf(a[i]);\r\n if (a[i] > a[j]) {\r\n let step = a[i] - a[j];\r\n res += step;\r\n while (step--) {\r\n a[i]--;\r\n a[j]++;\r\n d.push([i, j]);\r\n }\r\n } else if (a[i] < a[j]) {\r\n let step = a[j] - a[i];\r\n res += step;\r\n while (step--) {\r\n a[i]++;\r\n a[j]--;\r\n d.push([i, j]);\r\n }\r\n }\r\n }\r\n // pr(a, b)\r\n pr(res);\r\n for (const [i, j] of d) pr(i + \" \" + j);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1], input[i + 2]);\r\n i += 3;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0]; \n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number);\n }else{\n var b = lines[i].split(' ').map(Number);\n var sn = 0;\n var sp = 0;\n var v = [];\n var v1 = [];\n for(j = 0; j < n; j++){\n var x = a[j] - b[j];\n if(x > 0){\n sn += x;\n while(x--){\n v.push(x);\n }\n }else if(x < 0){\n x *= -1;\n sp += x;\n while(x--){\n v1.push(x);\n }\n }\n }\n if(sn == sp){\n console.log(sn);\n for(j = 0; j < sn; j++){\n console.log(v[j] + 1, v1[j] + 1);\n }\n }else{\n console.log(-1);\n }\n }\n }\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar A = nextIntArray(N);\r\n\t\tvar B = nextIntArray(N);\r\n\t\tvar lsum = 0;\r\n\t\tvar rsum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlsum += A[i];\r\n\t\t\trsum += B[i];\r\n\t\t}\r\n\t\tif(lsum != rsum){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = [];\r\n\t\tvar sumlist = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsumlist[i] = A[i] - B[i];\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(sumlist[i] != 0){\r\n\t\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\t\tif(sumlist[i] < 0 && sumlist[j] > 0){\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\toutput.push((j + 1) + \" \" + (i + 1));\r\n\t\t\t\t\t\tsumlist[i]++;\r\n\t\t\t\t\t\tsumlist[j]--;\r\n\t\t\t\t\t}else if(sumlist[i] > 0 && sumlist[j] < 0){\r\n\t\t\t\t\t\toutput.push((i + 1) + \" \" + (j + 1));\r\n\t\t\t\t\t\tsumlist[i]--;\r\n\t\t\t\t\t\tsumlist[j]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(sumlist[i] != 0){\r\n\t\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\t\tif(sumlist[i] < 0 && sumlist[j] > 0){\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\toutput.push((j + 1) + \" \" + (i + 1));\r\n\t\t\t\t\t\tsumlist[i]++;\r\n\t\t\t\t\t\tsumlist[j]--;\r\n\t\t\t\t\t}else if(sumlist[i] > 0 && sumlist[j] < 0){\r\n\t\t\t\t\t\toutput.push((i + 1) + \" \" + (j + 1));\r\n\t\t\t\t\t\tsumlist[i]--;\r\n\t\t\t\t\t\tsumlist[j]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyerr(sumlist);\r\n\t\tmyout(output.length);\r\n\t\tif(output.length > 0){\r\n\t\t\tmyout(myconv(output, 9));\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\n \r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\n \r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\n \r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(str => str.trim());\r\n\r\n \r\n\r\n main();\r\n});\r\n\r\n \r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main()\r\n{\r\n //const name=readLine();\r\n //console.log(name);\r\n\r\n let test=readLine();\r\n while(test--)\r\n {\r\n n=readLine();\r\n let a=[n],b=[n];\r\n aa=readLine();\r\n aa=aa.split(\" \");\r\n for(i=0;i0)\r\n {\r\n sum_p+=b[i]-a[i];\r\n increase.push([i,b[i]-a[i]])\r\n //increase.push_back(mp(i,b[i]-a[i]));\r\n }\r\n else if((b[i]-a[i])<0)\r\n {\r\n sum_n+=a[i]-b[i];\r\n decrease.push([i,a[i]-b[i]]);\r\n //decrease.push_back(mp(i,a[i]-b[i]));\r\n }\r\n }\r\n if(sum_p!=sum_n)\r\n {\r\n console.log(-1);\r\n //cout<<\"-1\"< {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n \nconst calc = (n, s)=>{\n n = BigInt(n);\n s = BigInt(s)\n return (s/(n*n)).toString(10)\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, s] = readline().split(' ');\n print(calc(n, s));\n }\n}\n \nE.calc = calc;", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,s]=line[_].split(' ');\r\n n=BigInt(n);\r\n s=BigInt(s);\r\n n=n*n;\r\n // console.log(s,n);\r\n let ans=''+s/n;\r\n console.log(ans);\r\n }\r\n})"}], "negative_code": [{"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nconst calc = (n, s)=>{\n return Math.floor(s/(n*n)+EPS)\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, s] = ra();\n print(calc(n, s));\n }\n}\n \nE.calc = calc;"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nconst calc = (n, s)=>{\n return Math.floor(s/(n*n))\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, s] = ra();\n print(calc(n, s));\n }\n}\n \nE.calc = calc;"}], "src_uid": "7226a7d2700ee52f52d417f404c42ab7"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n var array = []\n\n array[0] = 0\n array[1] = 1\n array[2] = 3\n array[3] = 2\n var index = 0\n for (var i = 0; i < 100000; i++) {\n if (index > 10000000) break\n index = index + i\n array[index] = i\n }\n\n Array(Number(x)).fill(1).map((t, i) => {\n\n var line = readline();\n var x = Number(line)\n var xx = x\n var value1 = 0\n var value2 = 0\n if (array[x]) return console.log(array[x])\n if (array[x+1]) return console.log(array[x+1]+1)\n while (!array[x]) {\n x -= 1\n }\n console.log(array[x] +1)\n\n // console.log(array[x] + 1)\n })\n // console.log(array)\n // array.map((v, i) => {\n // console.log({v, i})\n // })\n}\n\n", "positive_code": [{"source_code": "var tc = parseInt(readline());\nfor (; tc--;) {\n var Ar = readline().split(' ').map(x => +x);\n var n = Ar[0];\n var res = 0;\n var c = 0, x = 1;\n while (res < n) {\n res += x;\n x++, c++;\n }\n print(n == res - 1 ? c + 1 : c);\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;st-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(o=s.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),s.default.writeFileSync(\"output.txt\",l),console.log(l),s.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{o=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return o[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let a = 1\n// \n// let i = 1\n// while (a < n) {\n// i++\n// a += i\n// }\n// \n// if (a == n) {\n// io.puts(i)\n// return\n// }\n// \n// if (a - 1 == n) {\n// io.puts(i + 1)\n// return\n// }\n// \n// io.puts(i)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "const solve = (x) => {\n let jump = 0;\n while (x > 0) {\n jump++;\n x -= jump;\n }\n if (x == -1) jump++;\n console.log(jump);\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(Number(line));\n });\n rl.on('close', () => {\n let t = input[0];\n let i = 1;\n while (t > 0) {\n solve(input[i]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n let [i, count] = [1, 0];\n while (count < n) {\n count += i;\n i++;\n }\n if (count === n) console.log(i - 1);\n else if (count - n > 1) console.log(i - 1);\n else console.log(i);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\n\t\tvar index = 0;\n\t\tvar count = 1;\n\t\twhile(N > index){\n\t\t\tindex += count;\n\t\t\tcount++;\n\t\t}\n\t\tcount--;\n\t\t\n\t\tif(index - 1 == N){\n\t\t\tcount++;\n\t\t}\n\t\tmyout(count);\n\t}\n}\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let i = 1;\n let t = 0;\n readline.on('line', line => {\n if (i == 1) {\n // number of test case\n t = parseInt(line) \n i++;\n } else if (i <= t) {\n solve(line)\n i++;\n } else {\n solve(line)\n readline.close()\n }\n });\n\n function solve(input) {\n // your code here\n let x = parseInt(input);\n let i1 = 1\n let x1 = 1\n while (x1 < x) {\n i1 += 1\n x1 += i1\n }\n \n if (x1 - x == 1) console.log(i1 + 1)\n else console.log(i1)\n }"}, {"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let x = readline(), s = 0, a = [], c = 0;\n for(let i = 1; s < x; i++)\n {\n s+=i;\n c++;\n }\n if(s!=x)\n {\n if(!(s - x - 1))while(s!=x){s--; c++;}\n }\n print(c);\n}"}, {"source_code": "/*\n * File Created: Monday, 30th November 2020 3:31:00 pm\n * Author: Lukas Rimkus\n */\n\n'use-strict'\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet data = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', chunk => {\ndata += chunk;\n});\n\nprocess.stdin.on('end', () =>{\n data = data.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n let testCases = parseInt(data.shift());\n\n while(testCases--) {\n\n const n = parseInt(data.shift());\n\n const res = b(n);\n\n console.log(res)\n }\n});\n\nfunction get_ints() { \n return data.shift().split(' ').map(Number);\n}\n \nfunction readLine() { \n return data[currentLine++];\n}\n \n\nfunction a(num)\n{\n return num.length ;\n}\n\n\n\nfunction b(goal)\n{\n\n function jump1(y,k)\n {\n return y + k;\n }\n function jump2(y)\n {\n return y - 1;\n }\n\n let sum = 0;\n\n let jumps = 0;\n\n let arr = [];\n\n while(sum < goal)\n {\n jumps++;\n\n arr.push(jumps);\n\n sum = sum + jumps;\n }\n \n if(sum === goal)\n {\n return arr.length;\n }\n else\n {\n let current_pos = sum;\n\n // that's how many steps back;\n let diference = current_pos - goal; \n\n // console.log(arr, arr.length, sum, diference)\n\n for(let i = 0 ; i < arr.length; i++)\n {\n if((arr[i] + 1) === diference)\n {\n return arr.length;\n }\n }\n return arr.length + 1;\n }\n}\n\nmodule.exports = b;"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var y = 0;\n var res = 0;\n \n for (var k = 1; k <= l; k++) {\n y += k;\n res++;\n \n if (y == l) {\n break;\n } else if (y > l) {\n if (y - l == 1) {\n res++;\n }\n break;\n }\n }\n \n print(res);\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let x = readline(), s = 0, a = [], c = 0;\n for(let i = 1; s < x; i++)\n {\n s+=i;\n c++;\n }\n for(let i = 1; s - i > x; i++)\n {\n s-=i;\n c--;\n }\n while(s>x)\n {\n s--;\n c++;\n }\n print(c);\n}"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var y = 0;\n var res = 0;\n \n for (var k = 1; k <= l; k++) {\n y += k;\n res++;\n \n if (y == l) {\n break;\n } else if (l - y == 1) {\n res += 2;\n break;\n } else {\n res = l - y;\n break;\n }\n }\n \n print(res);\n}\n"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var p = 0;\n var res = 0;\n\n if (l == 1) {\n print(l);\n } else if (l == 2) {\n print(l+1);\n } else {\n print(l-1);\n }\n}\n"}, {"source_code": "const solve = (x) => {\n if (x == 1) {\n console.log(1);\n return;\n }\n if (x == 2) {\n console.log(3);\n return;\n }\n console.log(x - 1);\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(Number(line));\n });\n rl.on('close', () => {\n let t = input[0];\n let i = 1;\n while (t > 0) {\n solve(input[i]);\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n if (n === 1) console.log(1);\n else if (n === 2) console.log(3);\n else {\n let [i, count, found] = [1, 0, false];\n while (count <= n) {\n count += i;\n if (count === n) {\n console.log(i);\n found = true;\n break;\n }\n if (count > n) break;\n i++;\n }\n if (!found) {\n const prev = count - i;\n const [prevDiff, nextDiff] = [Math.abs(prev - n), Math.abs(count - n)];\n if (prevDiff <= nextDiff) {\n console.log(i - 1 + prevDiff);\n } else {\n console.log(i + nextDiff);\n }\n }\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar index = 0;\n\t\tvar count = 1;\n\t\twhile(N > index){\n\t\t\tindex += count;\n\t\t\tcount++;\n\t\t}\n\t\tcount--;\n\t\tif(N != index && N % 2 != index % 2){\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\tmyout(count);\n\t}\n}\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar max = 1000007;\n\tvar dp = new Array(max);\n\tdp[0] = 0;\n\tvar index = 0;\n\tvar count = 1;\n\twhile(index < max){\n\t\tindex += count;\n\t\tdp[index] = count;\n\t\tcount++;\n\t}\n\tvar add = 1;\n\twhile(true){\n\t\tvar index = 1;\n\t\tvar count = 1 + add;\n\t\twhile(index < max){\n\t\t\tindex += count;\n\t\t\tif(dp[index] == null){\n\t\t\t\tdp[index] = count;\n\t\t\t}else{\n\t\t\t\tdp[index] = Math.min(count, dp[index]);\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t\tadd++;\n\t\tif(add > max){\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(var i = max; i >= 1; i--){\n\t\tif(dp[i] != null){\n\t\t\tif(dp[i - 1] == null){\n\t\t\t\tdp[i - 1] = dp[i] + 1;\n\t\t\t}else{\n\t\t\t\tdp[i - 1] = Math.min(dp[i] + 1, dp[i - 1]);\n\t\t\t}\n\t\t}\n\t}\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tmyout(dp[N]);\n\t}\n}\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar max = 1500007;\n\tvar dp = new Array(max);\n\tdp[0] = 0;\n\tvar index = 0;\n\tvar count = 1;\n\twhile(index < max){\n\t\tindex += count;\n\t\tdp[index] = count;\n\t\tcount++;\n\t}\n\tvar add = 1;\n\twhile(true){\n\t\tvar index = 1;\n\t\tvar count = 1 + add;\n\t\twhile(index < max){\n\t\t\tindex += count;\n\t\t\tif(dp[index] == null){\n\t\t\t\tdp[index] = count;\n\t\t\t}else{\n\t\t\t\tdp[index] = Math.min(count, dp[index]);\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t\tadd++;\n\t\tif(add > max){\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(var i = max; i >= 1; i--){\n\t\tif(dp[i] != null){\n\t\t\tif(dp[i - 1] == null){\n\t\t\t\tdp[i - 1] = dp[i] + 1;\n\t\t\t}else{\n\t\t\t\tdp[i - 1] = Math.min(dp[i] + 1, dp[i - 1]);\n\t\t\t}\n\t\t}\n\t}\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tmyout(dp[N]);\n\t}\n}\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = []; var outputList = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n\tconsole.log(myconv(outputList, 9));\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){outputList.push(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar dp = new Array(1000000);\n\tdp[0] = 0;\n\tvar index = 0;\n\tvar count = 1;\n\twhile(index < 1000000){\n\t\tindex += count;\n\t\tdp[index] = count;\n\t\tcount++;\n\t}\n\tvar add = 1;\n\twhile(true){\n\t\tvar index = 1;\n\t\tvar count = 1 + add;\n\t\twhile(index < 1000000){\n\t\t\tindex += count;\n\t\t\tif(dp[index] == null){\n\t\t\t\tdp[index] = count;\n\t\t\t}else{\n\t\t\t\tdp[index] = Math.min(count, dp[index]);\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t\tadd++;\n\t\tif(add > 1000000){\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar t = nextInt();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tif(dp[N] == null){\n\t\t\tmyout(dp[N + 1] + 1);\n\t\t}else{\n\t\t\tmyout(dp[N]);\n\t\t}\n\t\t\n\t}\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n var answer = []\n\n var array = []\n\n array[0] = 0\n array[1] = 1\n array[2] = 3\n array[3] = 2\n var index = 0\n for (var i = 0; i < 100000; i++) {\n if (index > 10000000) break\n index = index + i\n array[index] = i\n }\n\n Array(Number(x)).fill(1).map((t, i) => {\n\n var line = readline();\n var x = Number(line)\n var xx = x\n var value1 = 0\n var value2 = 0\n if (array[x]) return console.log(array[x])\n while (!array[x]) {\n x -= 1\n value1 += 1\n }\n while (!array[xx]) {\n xx += 1\n value2 += 1\n }\n console.log(Math.min(array[x] + value1, array[xx] + value2 ))\n\n // console.log(array[x] + 1)\n })\n // console.log(array)\n // array.map((v, i) => {\n // console.log({v, i})\n // })\n}\n\n"}], "src_uid": "38afe98586a3b8d6061fe7e3e8fc4d02"} {"source_code": "function dustSweeper() {\r\n n = +r();\r\n a = r().split` `.map(Number);\r\n let firstNumberIndex = a.indexOf(a.find(d => d > 0));\r\n if (firstNumberIndex === -1) {\r\n log(0);\r\n return;\r\n }\r\n let sum = 0;\r\n for (let i = firstNumberIndex; i < a.length - 1; i++) {\r\n if (a[i] === 0) sum++;\r\n else sum += a[i];\r\n }\r\n log(sum);\r\n}\r\n\r\nfunction main() {\r\n tt = +r();\r\n for (; tt; tt--) dustSweeper();\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nr = readline;\r\nlog = console.log;\r\n", "positive_code": [{"source_code": "'use strict';\n/*\n3\n2 0 0\n5\n0 2 0 2 0\n6\n2 0 3 0 4 6\n4\n0 0 0 10\n*/\nconst main = () => {\n const n = parseInt(readline());\n\n for (let i = 0; i < n; ++i) {\n const len = parseInt(readline());\n const arr = readline().split(' ').map(Number);\n let operations = 0;\n let sum = 0;\n let seenNonZero = false;\n for (let i = 0; i < len - 1; ++i) {\n if (arr[i] === 0 && seenNonZero) {\n ++operations;\n } else if (arr[i] > 0) {\n seenNonZero = true;\n }\n sum += arr[i];\n }\n console.log(operations + sum);\n }\n};\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let flag = false,\r\n zc = 0;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] === 0 && flag) zc++;\r\n else if (arr[i] > 0) flag = true;\r\n }\r\n if (!flag) console.log(0);\r\n else {\r\n let sum = 0;\r\n for (let i = 0; i < n - 1; i++) sum += arr[i];\r\n console.log(sum + zc);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(x=>parseInt(x));\r\n var sum = 0;\r\n var tail = 0;\r\n while (arr[tail] != undefined && arr[tail] == 0) {\r\n tail++;\r\n }\r\n for (var i = tail+1; i < n-1; i++) {\r\n if (arr[i] == 0) {\r\n arr[tail]--;\r\n arr[i]++;\r\n if (arr[tail] == 0) {\r\n tail++;\r\n }\r\n sum++;\r\n }\r\n }\r\n for (var i = 0; i < n-1; i++) {\r\n sum += arr[i];\r\n }\r\n print(sum);\r\n }"}], "negative_code": [{"source_code": "function dustSweeper() {\r\n n = +r();\r\n a = r().split` `.map(Number);\r\n let firstNumberIndex = a.indexOf(a.find(d => d > 0));\r\n let sum = 0;\r\n for (let i = firstNumberIndex; i < a.length - 1; i++) {\r\n if (a[i] === 0) sum++;\r\n else sum += a[i];\r\n }\r\n log(sum);\r\n\r\n // function firstZeroIndex(i) {\r\n // let firstZeroIndex = a.slice(i + 1).indexOf(0);\r\n // if (firstZeroIndex === -1) return -1;\r\n // return firstZeroIndex + i + 1;\r\n // }\r\n\r\n // for (let i = 0; i < a.length && firstZeroIndex(i) !== -1; i++) {\r\n // while (a[i] > 0 || firstZeroIndex(i) !== -1) {\r\n // // log(`before: i:${i}, a=${a}`);\r\n // i0 = firstZeroIndex(i);\r\n // a[i0]++;\r\n // a[i]--;\r\n // count++;\r\n // // log(`after: i:${i}, a=${a}`);\r\n // }\r\n // }\r\n}\r\n\r\nfunction main() {\r\n tt = +r();\r\n for (; tt; tt--) dustSweeper();\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nr = readline;\r\nlog = console.log;\r\n"}, {"source_code": "function dustSweeper() {\r\n n = +r();\r\n a = r().split` `.map(Number);\r\n let firstNumberIndex = a.indexOf(a.find(d => d > 0));\r\n // a = a.slice(firstNumberIndex);\r\n let count = 0;\r\n for (let i = firstNumberIndex; i < a.length - 1; i++) {\r\n if (a[i] === 0) count++;\r\n }\r\n log(count + a.reduce((p, c, i) => (i < a.length - 1 ? p + c : p)));\r\n\r\n // function firstZeroIndex(i) {\r\n // let firstZeroIndex = a.slice(i + 1).indexOf(0);\r\n // if (firstZeroIndex === -1) return -1;\r\n // return firstZeroIndex + i + 1;\r\n // }\r\n\r\n // for (let i = 0; i < a.length && firstZeroIndex(i) !== -1; i++) {\r\n // while (a[i] > 0 || firstZeroIndex(i) !== -1) {\r\n // // log(`before: i:${i}, a=${a}`);\r\n // i0 = firstZeroIndex(i);\r\n // a[i0]++;\r\n // a[i]--;\r\n // count++;\r\n // // log(`after: i:${i}, a=${a}`);\r\n // }\r\n // }\r\n}\r\n\r\nfunction main() {\r\n tt = +r();\r\n for (; tt; tt--) dustSweeper();\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nr = readline;\r\nlog = console.log;\r\n"}], "src_uid": "a20911c30d7246e47d6fd57a05d1e556"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, m] = iInpArr();\r\n let arr = iInpArr();\r\n let pair = [],\r\n obj = {};\r\n for (let i = 0; i < n; i++) obj[i + 1] = 0;\r\n for (let i = 0; i < m; i++) {\r\n let j = iInpArr();\r\n pair.push(j);\r\n obj[j[0]] += 1;\r\n obj[j[1]] += 1;\r\n }\r\n if (m === 0 || m % 2 === 0) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ans = Infinity;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[i + 1] & 1) ans = Math.min(ans, arr[i]);\r\n }\r\n for (let i = 0; i < m; i++) {\r\n if ((obj[pair[i][0]] & 1) === 0 && (obj[pair[i][1]] & 1) === 0)\r\n ans = Math.min(ans, arr[pair[i][0] - 1] + arr[pair[i][1] - 1]);\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readNumbersLine() {\r\n return readline().split(\" \").map(el => +el);\r\n}\r\n\r\n\r\nfunction solve() {\r\n let arr = {};\r\n let arr2 = []\r\n\r\n\r\n let [n, m] = readNumbersLine()\r\n let A = readNumbersLine()\r\n\r\n for (let j = 0; j < m; j++) {\r\n let [x, y] = readNumbersLine()\r\n x -= 1\r\n y -= 1\r\n if (arr[x]) {\r\n arr[x].push(y);\r\n } else {\r\n arr[x] = [y]\r\n }\r\n\r\n if (arr[y]) {\r\n arr[y].push(x);\r\n } else {\r\n arr[y] = [x]\r\n }\r\n arr2.push(A[x] + A[y]);\r\n }\r\n\r\n if (m % 2 === 0) {\r\n print(0)\r\n return;\r\n }\r\n A = A.map((value, index) => [value, index]);\r\n A.sort((a, b) => a[0] - b[0])\r\n let condition = true;\r\n let i = 0\r\n arr2.sort((a, b) => a - b);\r\n // console.log(arr2)\r\n // console.log(arr)\r\n while (condition) {\r\n let index = A[i][1]\r\n if (arr[index] && arr[index].length % 2 === 1) {\r\n console.log(Math.min(A[i][0], arr2[0]));\r\n return;\r\n }\r\n i += 1\r\n if (i >= A.length) {\r\n condition = false\r\n }\r\n }\r\n\r\n console.log(arr2[0]);\r\n return;\r\n}\r\n\r\n\r\nfunction main() {\r\n let k = +readline()\r\n for (let i = 0; i < k; i++) {\r\n solve();\r\n }\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var nm = readline().split(' ').map(x=>parseInt(x));\r\n var n = nm[0];\r\n var m = nm[1];\r\n var unh = readline().split(' ').map(x=>parseInt(x));\r\n var graph = {};\r\n var pairs = [];\r\n for (var i = 0; i < m; i++) {\r\n var pair = readline().split(' ').map(x=>parseInt(x));\r\n pairs.push(pair);\r\n if (!graph[pair[0]]) {\r\n graph[pair[0]] = 0;\r\n }\r\n graph[pair[0]]++;\r\n if (!graph[pair[1]]) {\r\n graph[pair[1]] = 0;\r\n }\r\n graph[pair[1]]++;\r\n }\r\n //console.log(pairs);\r\n if (!(m & 1) || n == 1) {\r\n print(0);\r\n } else {\r\n var toCheck = new Set();\r\n var min = Number.POSITIVE_INFINITY;\r\n Object.keys(graph).forEach((k) => {\r\n if (graph[k] & 1) {\r\n min = Math.min(unh[k-1], min);\r\n } else {\r\n toCheck.add(parseInt(k));\r\n }\r\n })\r\n //console.log(toCheck);\r\n for (var i = 0; i < pairs.length; i++) {\r\n if (toCheck.has(pairs[i][0]) && toCheck.has(pairs[i][1])) {\r\n min = Math.min(min, unh[pairs[i][0]-1]+unh[pairs[i][1]-1]);\r\n }\r\n }\r\n\r\n print(min);\r\n }\r\n }"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readNumbersLine() {\r\n return readline().split(\" \").map(el => +el);\r\n}\r\n\r\n\r\nfunction solve() {\r\n let arr = {};\r\n let arr2 = []\r\n\r\n\r\n let [n, m] = readNumbersLine()\r\n let A = readNumbersLine()\r\n const sum = A.reduce((partialSum, a) => partialSum + a, 0);\r\n\r\n for (let j = 0; j < m; j++) {\r\n let [x, y] = readNumbersLine()\r\n x -= 1\r\n y -= 1\r\n if (arr[x]) {\r\n arr[x].push(y);\r\n } else {\r\n arr[x] = [y]\r\n }\r\n\r\n if (arr[y]) {\r\n arr[y].push(x);\r\n } else {\r\n arr[y] = [x]\r\n }\r\n arr2.push(A[x] + A[y]);\r\n }\r\n\r\n if (m % 2 === 0) {\r\n print(0)\r\n return;\r\n }\r\n A = A.map((value, index) => [value, index]);\r\n A.sort((a, b) => a[0] - b[0])\r\n let condition = true;\r\n let i = 0\r\n arr2.sort();\r\n // console.log(A)\r\n // console.log(arr)\r\n while (condition) {\r\n let index = A[i][1]\r\n if (arr[index] && arr[index].length % 2 === 1) {\r\n console.log(Math.min(A[i][0], arr2[0]));\r\n return;\r\n }\r\n i += 1\r\n if (i >= A.length) {\r\n condition = false\r\n }\r\n }\r\n\r\n console.log(arr2[0]);\r\n return;\r\n}\r\n\r\n\r\nfunction main() {\r\n let k = +readline()\r\n for (let i = 0; i < k; i++) {\r\n solve();\r\n }\r\n\r\n}\r\n\r\n\r\n"}], "src_uid": "a9c54d6f952320d75324b30dcb098332"} {"source_code": "function calc(n, a, b) {\n if (a <= b / 2) {\n return a * n;\n } else {\n return b * Math.floor(n / 2) + a * (n % 2);\n }\n}\n\nvar q = parseInt(readline());\n// print(q);\nvar nab;\nfor (var i = 0; i < q; i++) {\n nab = readline().split(\" \").map(el => parseInt(el));\n // print(nab);\n print(calc(nab[0], nab[1], nab[2]));\n}\n\n", "positive_code": [{"source_code": "var n=parseInt(readline());\nfor(var i=0;i0) {\n\tvar numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\tvar n = numbers[0], a = numbers[1], b = numbers[2];\n\tvar down = 0, up = Math.floor(n/2) + 1;\n\twhile (up > down + 5) {\n\t\tvar t1 = down + Math.floor((up-down)/3);\n\t\tvar cost1 = t1 * b + Math.max(0, n-t1*2) * a;\n\t\tvar t2 = down + 2*Math.floor((up-down)/3);\n\t\tvar cost2 = t2 * b + Math.max(0, n-t2*2) * a;\n\t\tif (cost1 < cost2) up = t2;\n\t\telse down = t1;\n\t}\n\tvar mn = n*a;\n\tfor (var t=down-50; t<=down+50; t++)\n\t\tif (t >= 0 && t*2 <= n) {\n\t\t\tvar cost1 = t * b + Math.max(0, n-t*2) * a;\n\t\t\tmn = Math.min(mn, cost1);\n\t\t}\n\twrite(mn + \"\\n\");\n}"}, {"source_code": "var q = parseInt(readline())\n\n\nfor(var t=0;t(parseInt(v)))\n var n = nab[0];\n var a = nab[1];\n var b = nab[2];\n \n var aa = (n%2) * a + parseInt(n/2) * b;\n var bb = n*a\n \n print( Math.min(aa, bb) )\n}"}, {"source_code": "var n = parseInt(readline());\nfor (var i = 0; i < n; i++) {\n var s = readline().split(\" \");\n print(foo(s[0], s[1], s[2]));\n}\n\nfunction foo(n, a, b) {\n if (a*2 <= b) return n*a;\n return Math.trunc(n / 2) * b + n % 2* a;\n}"}, {"source_code": "function repeat(n, fn) {\n var result = [];\n for (var i = 0; i < n; i++)\n result.push(fn(i));\n return result;\n}\nfunction readInput(_a) {\n var line = _a.line, int = _a.int, ints = _a.ints, strings = _a.strings;\n var n = int();\n return { n: n, queries: repeat(n, function () { var _a = ints(), n = _a[0], a = _a[1], b = _a[2]; return { n: n, a: a, b: b }; }) };\n}\nfunction printOutput(result, _a) {\n var line = _a.line;\n result.forEach(function (r) { return line(r); });\n}\nfunction show(input) {\n console.log(input, '-->', solve(input));\n}\nfunction inputFunctions(line) {\n return {\n line: line,\n int: function () { return parseInt(line()); },\n strings: function () { return line().split(' '); },\n ints: function () { return line().split(' ').map(function (v) { return parseInt(v); }); }\n };\n}\nfunction outputFunctions(line) {\n return { line: line };\n}\nfunction sampleInput(input) {\n var lines = input.split('\\n');\n var index = 0;\n var line = function () { return lines[index++]; };\n return inputFunctions(line);\n}\nfunction sample(input) {\n show(readInput(sampleInput(input)));\n}\nfunction run() {\n var input = readInput(inputFunctions(readline));\n var output = solve(input);\n printOutput(output, outputFunctions(print));\n}\nfunction solve(_a) {\n // implementation\n var n = _a.n, queries = _a.queries;\n return queries.map(function (_a) {\n var n = _a.n, a = _a.a, b = _a.b;\n if (a * 2 < b)\n return n * a;\n return n % 2 * a + (n - n % 2) / 2 * b;\n });\n}\n// sample(`4\n// 10 1 3\n// 7 3 2\n// 1 1000 1\n// 1000000000000 42 88`)\nrun();\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let tmp=0, T=0, triplets=[];\n\n rl.on('line', (input) => {\n if (tmp==0) {T=Number(input); tmp++;}\n else {\n if (tmp<=T){\n let str=input.split(' ').map(a=>{return Number(a);}); \n triplets.push(str);\n tmp++;}\n }\n if (tmp>T){ rl.close(); therest();}\n return 0;}\n);\n\nlet therest=function() {\n for (let i=0; i {\n // TODO: Log the answer in a database\n console.log(`Thank you for your valuable feedback: ${answer}`);\n \n rl.close();\n });*/"}, {"source_code": "var q=parseInt(readline());\nfor(var i=0;iparseInt(x));\n console.log(Math.min(x[1]*2, x[2])*Math.floor(x[0]/2)+x[0]%2*x[1])\n }\n}\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar data = [];\nrl.on('line', function (line) {data.push(line);});\nrl.on('close', main);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [n, a, b] = d.split(' ').map(Number);\n let ans = 0;\n\n if (n === 1) {\n ans += a;\n }\n else {\n if (a * 2 < b) {\n ans += n * a;\n }\n else {\n ans += Math.floor(n / 2) * b;\n if (n % 2 === 1) {\n ans += a;\n }\n }\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [n, a, b] = d.split(' ').map(Number);\n const ans = Math.floor(n / 2) * Math.min(2*a, b) + n % 2 * a;\n\n // if (n === 1) {\n // ans += a;\n // }\n // else {\n // if (a * 2 < b) {\n // ans += n * a;\n // }\n // else {\n // ans += Math.floor(n / 2) * b;\n // if (n % 2 === 1) {\n // ans += a;\n // }\n // }\n // }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var q = read.number();\n\n for(var i = 0; i < q; i++) {\n var n = read.arrNumber(' ');\n \n if(n[0] === 1) {\n print(n[1]);\n }\n else if(n[1] * 2 > n[2]) {\n var h2 = Math.floor(n[0] / 2);\n print(h2 * n[2] + (n[0] - (h2 * 2)) * n[1]);\n }\n else {\n print(n[1] * n[0]);\n }\n }\n}());"}], "negative_code": [{"source_code": "var n=parseInt(readline());\nfor(var i=0;iel2[1]){\n\t\t\t\t_[0]=1;\n\t\t\t}else if(el1[1]el2[0]){\n\t\t\t\t_[2]=1;\n\t\t\t}else if(el1[0] {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n let count = 0;\n const arr = [];\n while (t--) {\n let [x, y] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.push([x, y]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n const [x, y] = arr[i];\n let [left, right, top, bottom] = [0, 0, 0, 0];\n for (let j = 0; j < arr.length; j++) {\n if (i !== j) {\n const [cx, cy] = arr[j];\n if (cx < x && cy === y) left++;\n if (cx > x && cy === y) right++;\n if (cx === x && cy > y) top++;\n if (cx === x && cy < y) bottom++;\n }\n }\n if (left > 0 && right > 0 && top > 0 && bottom > 0) count++;\n }\n console.log(count);\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction isSuperCentral(cord, xs, ys) {\n\tlet [x, y] = cord;\n\tlet minY = Math.min(...xs[x]),\n\t\tmaxY = Math.max(...xs[x]),\n\t\tminX = Math.min(...ys[y]),\n\t\tmaxX = Math.max(...ys[y]);\n\treturn minY < y && maxY > y && minX < x && maxX > x;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet chart = [];\n\tlet xs = {},\n\t\tys = {};\n\twhile (n--) {\n\t\tlet [x, y] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\txs[x] = xs[x] || [];\n\t\txs[x].push(y);\n\t\tys[y] = ys[y] || [];\n\t\tys[y].push(x);\n\t\tchart.push([x, y]);\n\t}\n\tlet c = 0;\n\tfor (let i = 0; i < chart.length; ++i)\n\t\tif (isSuperCentral(chart[i], xs, ys)) c++;\n\n\tconsole.log(c);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let Allx = [];\n let Ally = [];\n for (let i = 0; i < n; i++) {\n let [x, y] = readLine().split(' ').map(Number);\n Allx.push(x);\n Ally.push(y);\n }\n\n let up = [];\n let down = [];\n let left = [];\n let right = [];\n\n for (let i = 0; i < Allx.length; i++) {\n for (let j = 0; j < n; j++) {\n if (Allx[i] === Allx[j] && Ally[i] > Ally[j]) {\n down[i] = true;\n } else if (Allx[i] === Allx[j] && Ally[i] < Ally[j]) {\n up[i] = true;\n } else if (Allx[i] > Allx[j] && Ally[i] === Ally[j]) {\n left[i] = true;\n } else if (Allx[i] < Allx[j] && Ally[i] === Ally[j]) {\n right[i] = true;\n }\n }\n }\n let count = 0;\n for (let i = 0; i < n; i++) {\n if (\n up[i] === true &&\n left[i] === true &&\n right[i] === true &&\n down[i] === true\n ) {\n count++;\n }\n }\n console.log(count);\n}\n"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\n\tvar p = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tvar e = readline().split(' ');\n\t\tp.push( {x: +e[0], y: +e[1]} );\n\t}\n\n\tvar s = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tvar f = false;\n\n\t\tfor (var j = 0; j < n; j++)\n\t\t\tif (p[i].x == p[j].x && p[i].y > p[j].y) {\n\t\t\t\tf = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\tif (f) {\n\t\t\tf = false;\n\t\t\tfor (var j = 0; j < n; j++)\n\t\t\t\tif (p[i].x == p[j].x && p[i].y < p[j].y) {\n\t\t\t\t\tf = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\tif (f) {\n\t\t\t\tf = false;\n\t\t\t\tfor (var j = 0; j < n; j++)\n\t\t\t\t\tif (p[i].y == p[j].y && p[i].x > p[j].x) {\n\t\t\t\t\t\tf = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\tif (f) {\n\t\t\t\t\tf = false;\n\t\t\t\t\tfor (var j = 0; j < n; j++)\n\t\t\t\t\t\tif (p[i].y == p[j].y && p[i].x < p[j].x) {\n\t\t\t\t\t\t\tf = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\tif (f) s++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(s);\n\n}).call(this);\n"}], "negative_code": [], "src_uid": "594e64eef7acd055d59f37710edda201"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nlet p2 = [];\r\np2[0] = 1;\r\np2[1] = 2;\r\nfor (let i = 2; i < 70; i++) p2[i] = p2[i - 1] * 2;\r\nfor (let i = 0; i < 70; i++) {\r\n let j = p2[i],\r\n arr = [];\r\n while (j > 0) {\r\n arr.push(j % 10);\r\n j = Math.floor(j / 10);\r\n }\r\n p2[i] = arr.reverse();\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = [];\r\n while (n > 0) {\r\n arr.push(n % 10);\r\n n = Math.floor(n / 10);\r\n }\r\n arr.reverse();\r\n const helper = (arr1) => {\r\n let k = 0,\r\n op = 0,\r\n i = 0;\r\n while (k < arr.length && i < arr1.length) {\r\n if (arr[k] === arr1[i]) {\r\n op++;\r\n i++;\r\n }\r\n k++;\r\n }\r\n return arr.length - op + (arr1.length - op);\r\n };\r\n let ans = Infinity;\r\n for (let i = 0; i < p2.length; i++) {\r\n ans = Math.min(ans, helper(p2[i]));\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst pow2 = [1n]\r\nfor (let e = 1; e < 80; ++e) pow2[e] = 2n * pow2[e - 1]\r\nconst pow2s = pow2.map(e => String(e))\r\nfunction solve(e) {\r\n let n = 1e4\r\n const t = String(e)\r\n for (const e of pow2s) n = Math.min(n, s(t, e))\r\n return n\r\n function s(e, n) {\r\n let t = 0,\r\n s = 0,\r\n i = 0\r\n for (; t < e.length && s < n.length; )\r\n e[t] !== n[s] ? ((t += 1), (i += 1)) : ((t += 1), (s += 1))\r\n return (\r\n t < e.length && (i += e.length - t),\r\n s < n.length && (i += n.length - s),\r\n i\r\n )\r\n }\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const n = solve(e.readLineAsNumber())\r\n e.print(n + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst len = n => n.toString().length;\r\n\r\nfunction sbsql (a, n) {\r\n\ta = a.toString();\r\n\tn = n.toString();\r\n\r\n\tlet i = 0, j = 0;\r\n\twhile (i < a.length && j < n.length) {\r\n\t\tif (n[j] == a[i]) i++;\r\n\t\tj++;\r\n\t}\r\n\treturn i;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = len(n) + 1;\r\n\t\tlet k = 1n;\r\n\t\twhile (k < 1e18) {\r\n\t\t\tif (l = sbsql(k, n)) {\r\n\t\t\t\tans = Math.min(ans, len(n) - l + len(k) - l);\r\n\t\t\t}\r\n\t\t\tk = k << 1n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n var res = 1n\r\n var i =0\r\n while (i < 200) {\r\n array.push(res.toString())\r\n res = res* 2n\r\n i++\r\n }\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var string = readline();\r\n //\r\n // var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // console.log(string)\r\n var min = 10\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var same = 0\r\n var add = 0\r\n var result = true\r\n var exist = false\r\n for (let k = 0; k < array[j].length; k++) {\r\n exist = false\r\n for (let i = k + add; i < string.length; i++) {\r\n if (string[i] === array[j][k]) {\r\n same++;\r\n exist = true\r\n add = i - k\r\n break\r\n }\r\n }\r\n if (!exist) break\r\n }\r\n min = Math.min((string.length +array[j].length) - 2*same, min)\r\n // console.log(same, array[j], string, min)\r\n }\r\n +\r\n console.log(min)\r\n })\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\nconst P2LIM = BigInt(2e18);\r\n\r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n});\r\nrl.on(\"close\", () => {\r\n const list = input.slice(1);\r\n const ts = [];\r\n for (let p2 = 1n; p2 <= P2LIM; p2 *= 2n) ts.push(String(p2));\r\n for (let e of list) {\r\n let res = e.length + 1;\r\n for (let p2 of ts) {\r\n res = Math.min(res, solve(e, p2));\r\n }\r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction solve(s, t) {\r\n let tp = 0;\r\n let sp = 0;\r\n let taken = 0;\r\n\r\n while (sp < s.length && tp < t.length) {\r\n if (s[sp] === t[tp]) {\r\n taken++;\r\n tp++;\r\n }\r\n sp++;\r\n }\r\n return s.length - taken + t.length - taken;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n console.log(solve(n))\n }\n// })()\n})\n\nfunction solve(n) {\n let target = 1n\n let min = 11\n for (let i = 0; i <= 70; i++) {\n const cur = cal(n, target)\n min = Math.min(min, cur)\n target += target\n }\n return min\n}\nfunction cal(n, target) {\n const a = String(n)\n const b = String(target)\n\n let i = 0\n let j = 0\n while (i < a.length && j < b.length) {\n if (a[i] === b[j]) {\n i++\n j++\n } else {\n i++\n }\n }\n const k = j\n const used = a.length - k \n return a.length - used + used - k + b.length - k\n\n const limit = Math.pow(2, a.length)\n let min = a.length + b.length\n for (let i = 0; i < limit; i++) {\n const r = []\n let used = 0\n let mask = 1\n for (let j = 0; j < a.length; j++) {\n if (i & mask) {\n used++\n r.push(a[j])\n }\n mask += mask\n }\n const p = r.join('')\n let k = 0\n for (; k < p.length; k++) {\n if (p[k] !== b[k]) break\n }\n min = Math.min(min, a.length - used + used - k + b.length - k)\n // console.log(p, b, used, k, a.length - used + b.length - k)\n }\n // console.log(a, b, min)\n // console.log('--')\n return min\n}\n"}, {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let n = read();\n let res = 100;\n let p2 = BigInt(1);\n for (let i = 0; i < 100; i++) {\n let s2 = p2.toString();\n let cost = 0;\n let ptr = 0;\n for (let i = 0; i < s2.length; i++) {\n while (ptr < n.length && n[ptr] != s2[i]) {\n cost++;\n ptr++;\n }\n if (ptr < n.length && n[ptr] == s2[i]) {\n ptr++;\n }\n else {\n cost++;\n }\n }\n cost += n.length - ptr;\n res = Math.min(res, cost);\n p2 = p2 * BigInt(2);\n }\n console.log(res);\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst len = n => n.toString().length;\r\n\r\nfunction sbsq (a, n) {\r\n\ta = a.toString();\r\n\tn = n.toString();\r\n\r\n\tlet i = 0, j = 0;\r\n\twhile (i < a.length && j < n.length) {\r\n\t\tif (n[j] == a[i]) i++;\r\n\t\tj++;\r\n\t}\r\n\r\n\treturn i == a.length;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = len(n) + 1;\r\n\t\tlet k = 1n;\r\n\t\twhile (k < 1e18) {\r\n\t\t\tlet cur = k;\r\n\t\t\twhile (cur > 0) {\r\n\t\t\t\tif (sbsq(cur, n)) {\r\n\t\t\t\t\tans = Math.min(ans, len(n) - len(cur) + len(k) - len(cur));\r\n\t\t\t\t}\r\n\t\t\t\tcur /= 10n;\r\n\t\t\t\t//cur = BigInt(cur.toString().slice(0,-1));\r\n\t\t\t}\r\n\t\t\tk <<= 2n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst len = n => n.toString().length;\r\n\r\nfunction sbsq (a, n) {\r\n\ta = a.toString();\r\n\tn = n.toString();\r\n\r\n\tlet i = 0, j = 0;\r\n\twhile (i < a.length && j < n.length) {\r\n\t\tif (n[j] == a[i]) i++;\r\n\t\tj++;\r\n\t}\r\n\r\n\treturn i == a.length;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = len(n) + 1;\r\n\t\tlet k = 1n;\r\n\t\twhile (k < 1e18 && len(k) < 2*len(n)) {\r\n\t\t\tlet cur = k;\r\n\t\t\twhile (cur > 0) {\r\n\t\t\t\tif (sbsq(cur, n)) {\r\n\t\t\t\t\tans = Math.min(ans, len(n) - len(cur) + len(k) - len(cur));\r\n\t\t\t\t}\r\n\t\t\t\tcur /= 10n;\r\n\t\t\t}\r\n\t\t\tk *= 2n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst len = n => n.toString().length;\r\n\r\nfunction sbsq (a, n) {\r\n\ta = a.toString();\r\n\tn = n.toString();\r\n\r\n\tlet i = 0, j = 0;\r\n\twhile (i < a.length && j < n.length) {\r\n\t\tif (n[j] == a[i]) i++;\r\n\t\tj++;\r\n\t}\r\n\r\n\treturn i == a.length;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = 11;\r\n\t\tlet k = 1n;\r\n\t\twhile (k < 1e18) {\r\n\t\t\tlet cur = k;\r\n\t\t\twhile (cur > 0) {\r\n\t\t\t\tif (sbsq(cur, n)) {\r\n\t\t\t\t\tans = Math.min(ans, len(n) - len(cur) + len(k) - len(cur));\r\n\t\t\t\t}\r\n\t\t\t\tcur /= 10n;\r\n\t\t\t}\r\n\t\t\tk *= 2n;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst len = n => n.toString().length;\r\n\r\nfunction sbsq (a, n) {\r\n\ta = a.toString();\r\n\tn = n.toString();\r\n\r\n\tlet i = 0, j = 0;\r\n\twhile (i < a.length && j < n.length) {\r\n\t\tif (n[j] == a[i]) i++;\r\n\t\tj++;\r\n\t}\r\n\r\n\treturn i == a.length;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = 11;\r\n\t\tlet k = 1;\r\n\t\twhile (k < 1e18) {\r\n\t\t\tlet cur = k;\r\n\t\t\twhile (cur > 0) {\r\n\t\t\t\tif (sbsq(cur, n)) {\r\n\t\t\t\t\tans = Math.min(ans, len(n) - len(cur) + len(k) - len(cur));\r\n\t\t\t\t}\r\n\t\t\t\tcur = Math.floor(cur/10);\r\n\t\t\t}\r\n\t\t\tk *= 2;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n var res = 1n\r\n var i =0\r\n while (i < 200) {\r\n array.push(res.toString())\r\n res = res* 2n\r\n i++\r\n }\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var string = readline();\r\n //\r\n // var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // console.log(string)\r\n var min = 10\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var same = 0\r\n var add = 0\r\n var result = true\r\n var exist = false\r\n for (let k = 0; k < array[j].length; k++) {\r\n exist = false\r\n for (let i = k + add; i < string.length; i++) {\r\n if (string[i] === array[j][k]) {\r\n same++;\r\n exist = true\r\n add = i - k\r\n break\r\n }\r\n }\r\n if (!exist && k === 0) result = false\r\n }\r\n if(!result) same = 0\r\n min = Math.min(Math.abs(string.length - same + (array[j].length - same)), min)\r\n // console.log(same, array[j], string, min)\r\n }\r\n console.log(min)\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n var res = 1\r\n while (res <= 10e10) {\r\n array.push(res.toString())\r\n res *= 2\r\n }\r\n // console.log(array)\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var string = readline();\r\n //\r\n // var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // console.log(string)\r\n var min = 10\r\n for (let j = 0; j < array.length; j++) {\r\n\r\n var same = 0\r\n var add = 0\r\n var result = true\r\n var exist = false\r\n for (let k = 0; k < array[j].length; k++) {\r\n exist = false\r\n for (let i = k + add; i < string.length; i++) {\r\n if (string[i] === array[j][k]) {\r\n same++;\r\n exist = true\r\n add = i - k\r\n break\r\n }\r\n }\r\n if (!exist && k === 0) result = false\r\n }\r\n if(!result) same = 0\r\n min = Math.min(Math.abs(string.length - same + (array[j].length - same)), min)\r\n // console.log(same, array[j], string, min)\r\n }\r\n console.log(min)\r\n })\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nlet p2 = [];\r\np2[0] = 1;\r\np2[1] = 2;\r\nfor (let i = 2; i < 40; i++) p2[i] = p2[i - 1] * 2;\r\nfor (let i = 0; i < 40; i++) {\r\n let j = p2[i],\r\n arr = [];\r\n while (j > 0) {\r\n arr.push(j % 10);\r\n j = Math.floor(j / 10);\r\n }\r\n p2[i] = arr.reverse();\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = [];\r\n while (n > 0) {\r\n arr.push(n % 10);\r\n n = Math.floor(n / 10);\r\n }\r\n arr.reverse();\r\n const helper = (arr1) => {\r\n let k = 0,\r\n op = 0,\r\n i = 0;\r\n while (k < arr.length && i < arr1.length) {\r\n if (arr[k] === arr1[i]) {\r\n op++;\r\n i++;\r\n }\r\n k++;\r\n }\r\n return arr.length - op + (arr1.length - op);\r\n };\r\n let ans = Infinity;\r\n for (let i = 0; i < p2.length; i++) {\r\n ans = Math.min(ans, helper(p2[i]));\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "728e0e5e5d8350a2b79e6a4b5bef407b"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let root = -1;\r\n a = a.map(num => num - 1);\r\n for (let [k, p] of a.entries()) {\r\n if (k === p) {\r\n root = p;\r\n } else {\r\n g[p].push(k);\r\n }\r\n }\r\n let res = [];\r\n const queue = [[root, [root]]];\r\n for (let [u, path] of queue) {\r\n if (g[u].length === 0) {\r\n res.push(path.map(num => num + 1));\r\n } else {\r\n for (let i = 0; i < g[u].length; i++) {\r\n const v = g[u][i];\r\n if (i === 0) {\r\n path.push(v);\r\n queue.push([v, path]);\r\n } else {\r\n queue.push([v, [v]]);\r\n }\r\n }\r\n }\r\n }\r\n let str = [];\r\n str.push(res.length + '');\r\n for (let i = 0; i < res.length; i++) {\r\n str.push(res[i].length + '');\r\n str.push(res[i].join(' '));\r\n }\r\n console.log(str.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) {\r\n console.log(1);\r\n console.log(1);\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n let leaf = {};\r\n for (let i = 0; i < n; i++) leaf[arr[i]] = 1;\r\n let path = [],\r\n vis = new Array(n + 1).fill(0);\r\n for (let i = 1; i <= n; i++) {\r\n if (leaf[i]) continue;\r\n let ans = [],\r\n v = i;\r\n while (!vis[v]) {\r\n ans.push(v);\r\n vis[v] = 1;\r\n v = arr[v - 1];\r\n }\r\n path.push(ans);\r\n }\r\n let PRINT = path.length+'\\n';\r\n for (let i=0; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, p)=>{\n let paths = [];\n let hasChildren = new Array(n).fill(false);\n for (let i = 0; i < n; i++) {\n p[i]--;\n if (i === p[i]) continue;\n hasChildren[p[i]] = true;\n }\n let visited = new Array(n).fill(false);\n for (let i = 0; i < n; i++) {\n if (hasChildren[i]) continue;\n let cur = i;\n let path = [];\n while (!visited[cur]) {\n path.push(cur + 1);\n visited[cur] = true;\n cur = p[cur];\n }\n paths.push(path.reverse());\n }\n\n let result = '';\n\n result += `${paths.length}\\n`;\n for (let i = 0; i < paths.length; i++) {\n result += `${paths[i].length}\\n`;\n result += paths[i].join(' ');\n result += '\\n';\n }\n result += '\\n';\n process.stdout.write(result);\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n // let [n, k] = ra();\n let p = ra();\n // console.log(`${calc(n, p)}`);\n calc(n, p);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n\\n'))\r\n// })()\r\n})\r\n\r\nclass Queue {\r\n constructor() {\r\n this.map = {}\r\n this.first = 0\r\n this.last = -1\r\n }\r\n push(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[++this.last] = args[i]\r\n }\r\n }\r\n unshift(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[--this.first] = args[i]\r\n }\r\n }\r\n pop() {\r\n const r = this.map[this.last]\r\n delete this.map[this.last]\r\n this.last--\r\n return r\r\n }\r\n shift() {\r\n const r = this.map[this.first]\r\n delete this.map[this.first]\r\n this.first++\r\n return r\r\n }\r\n get length() {\r\n if (this.first > this.last) return 0\r\n return this.last - this.first + 1\r\n }\r\n}\r\n\r\nfunction solve(n, arr) {\r\n let r\r\n const adj = {}\r\n arr.forEach((p, i) => {\r\n i++\r\n if (p === i) {\r\n r = i\r\n return\r\n }\r\n //\r\n const a = p\r\n const b = i\r\n adj[a] = adj[a] || []\r\n adj[b] = adj[b] || []\r\n adj[a].push(b)\r\n adj[b].push(a)\r\n })\r\n const ans = dfs(adj, r, n)\r\n// console.log(ans)\r\n// return\r\n const map = new Map()\r\n const output = []\r\n for (let u = 1; u <= n; u++) {\r\n const x = ans[u]\r\n if (map.get(x)) continue\r\n map.set(x, 1)\r\n const line = []\r\n for (let i = x.first; i <= x.last; i++) {\r\n line.push(x.map[i])\r\n }\r\n // output.push(x.length, x.join(' '))\r\n output.push(x.length, line.join(' '))\r\n }\r\n return output.length / 2 + '\\n' + output.join('\\n')\r\n}\r\nfunction dfs(adj, r, n) {\r\n // const stack = [[r, 0, -1]]\r\n const stack = new Queue()\r\n stack.push([r, 0, -1])\r\n const ans = Array(n + 1)\r\n while (stack.length) {\r\n const [u, i, p] = stack.map[stack.last]\r\n // const [u, i, p] = stack[stack.length - 1]\r\n // visited[u] = 1\r\n\r\n const nb = adj[u] || []\r\n if (!i) {\r\n // first visited\r\n }\r\n if (i < nb.length) {\r\n // stack[stack.length - 1][1]++\r\n stack.map[stack.last][1]++\r\n const v = nb[i]\r\n // if (!visited[v]) { // has circle\r\n if (v !== p) {\r\n stack.push([v, 0, u])\r\n }\r\n } else {\r\n // last visited\r\n let max = 0\r\n let path\r\n ;(adj[u] || []).forEach(v => {\r\n if (v === p) return\r\n if (ans[v].length > max) {\r\n max = Math.max(max, ans[v].length)\r\n path = ans[v]\r\n }\r\n })\r\n if (path) {\r\n path.unshift(u)\r\n ans[u] = path\r\n } else {\r\n // ans[u] = [u]\r\n ans[u] = new Queue()\r\n ans[u].push(u)\r\n }\r\n stack.pop()\r\n }\r\n }\r\n return ans\r\n}\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n process.exit(0);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = readline().split(' ').map(a=>a-1);\n //LT({n, P});\n // PROCESSING:\n if (n==1){\n print(1);\n print(1);\n print(1);\n return\n }\n let has_child = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n process.exit(0);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = readline().split(' ').map(a=>a-1);\n //LT({n, P});\n // PROCESSING:\n if (n==1){\n print(1);\n print(1);\n print(1);\n return\n }\n let has_child = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n process.exit(0);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = readline().split(' ').map(a=>a-1);\n //LT({n, P});\n // PROCESSING:\n if (n==1){\n print(1);\n print(1);\n print(1);\n return\n }\n let has_child = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra().map(p=>p-1);\n LT({n, P});\n // PROCESSING:\n if (n==1){\n print(1);\n print(1);\n return\n }\n let G = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra().map(p=>p-1);\n LT({n, P});\n // PROCESSING:\n let root;\n let G = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra().map(p=>p-1);\n LT({n, P});\n // PROCESSING:\n let root;\n let G = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra().map(p=>p-1);\n LT({n, P});\n // PROCESSING:\n let root;\n let G = {};\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let P = ra().map(p=>p-1);\n LT({n, P});\n // PROCESSING:\n let root;\n let G = {};\n for (let i=0; i parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nclass graph {\r\n constructor() {\r\n this.list = {};\r\n }\r\n add(v) {\r\n if (!this.list[v]) this.list[v] = [];\r\n }\r\n addE(v, e) {\r\n if (this.list[v]) this.list[v].push(e);\r\n }\r\n}\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n if (n === 1) {\r\n console.log(1);\r\n console.log(1);\r\n console.log(arr[0]);\r\n continue;\r\n }\r\n let g = new graph();\r\n for (let i = 0, j = 1; i < n; i++, j++) {\r\n g.add(arr[i]);\r\n if (arr[i] !== j) g.addE(arr[i], j);\r\n }\r\n let path = [],\r\n res = [];\r\n const dfs = (g) => {\r\n let visted = {};\r\n const helper = (v) => {\r\n path.push(v);\r\n if (g.list[v] === undefined) {\r\n let narr = [];\r\n for (let i = 0; i < path.length; i++) {\r\n if (visted[path[i]] === undefined) {\r\n narr.push(path[i]);\r\n visted[path[i]] = 1;\r\n }\r\n }\r\n res.push(narr);\r\n return;\r\n }\r\n let arr = g.list[v];\r\n for (let i = 0; i < arr.length; i++) {\r\n helper(arr[i]);\r\n path.pop();\r\n }\r\n };\r\n helper(arr[0]);\r\n };\r\n dfs(g);\r\n console.log(res.length);\r\n for (let i = 0; i < res.length; i++) {\r\n console.log(res[i].length);\r\n console.log(res[i].join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => []);\r\n let root = -1;\r\n for (let [k, p] of a.entries()) {\r\n if (k + 1 === p) {\r\n root = p;\r\n } else {\r\n g[p].push(k + 1);\r\n }\r\n }\r\n let res = [];\r\n const dfs = (i, path = []) => {\r\n path.push(i);\r\n if (g[i].length === 0) {\r\n res.push(path);\r\n return;\r\n }\r\n for (let j = 0; j < g[i].length; j++) {\r\n if (j === 0) {\r\n dfs(g[i][j], path);\r\n } else {\r\n dfs(g[i][j]);\r\n }\r\n }\r\n };\r\n dfs(root);\r\n let str = [];\r\n str.push(res.length + '');\r\n for (let i = 0; i < res.length; i++) {\r\n str.push(res[i].length + '');\r\n str.push(res[i].join(' '));\r\n }\r\n console.log(str.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let root = -1;\r\n for (let [k, p] of a.entries()) {\r\n p--;\r\n if (k === p) {\r\n root = p;\r\n } else {\r\n g[p].push(k);\r\n }\r\n }\r\n let res = [];\r\n const dfs = (i, path = []) => {\r\n path.push(i);\r\n if (g[i].length === 0) {\r\n res.push(path.map(num => num + 1));\r\n return;\r\n }\r\n for (let j = 0; j < g[i].length; j++) {\r\n if (j === 0) {\r\n dfs(g[i][j], path);\r\n } else {\r\n dfs(g[i][j]);\r\n }\r\n }\r\n };\r\n dfs(root);\r\n let str = [];\r\n str.push(res.length + '');\r\n for (let i = 0; i < res.length; i++) {\r\n str.push(res[i].length + '');\r\n str.push(res[i].join(' '));\r\n }\r\n console.log(str.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let root = -1;\r\n for (let [k, p] of a.entries()) {\r\n p--;\r\n if (k === p) {\r\n root = p;\r\n } else {\r\n g[p].push(k);\r\n }\r\n }\r\n let res = [];\r\n const dfs = (i, path = []) => {\r\n path.push(i);\r\n if (g[i].length === 0) {\r\n res.push(path.map(num => num + 1));\r\n return;\r\n }\r\n for (let j = 0; j < g[i].length; j++) {\r\n if (j === 0) {\r\n dfs(g[i][j], path);\r\n } else {\r\n dfs(g[i][j]);\r\n }\r\n }\r\n };\r\n dfs(root);\r\n let str = res.length + '\\n';\r\n for (let i = 0; i < res.length; i++) {\r\n str += res[i].length + '\\n';\r\n str += res[i].join(' ') + '\\n';\r\n }\r\n console.log(str);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n let root = -1;\r\n for (let [k, p] of a.entries()) {\r\n p--;\r\n if (k === p) {\r\n root = p;\r\n } else {\r\n g[p].push(k);\r\n }\r\n }\r\n let res = [];\r\n const dfs = (i, path = []) => {\r\n path.push(i);\r\n if (g[i].length === 0) {\r\n res.push(path.map(num => num + 1));\r\n return;\r\n }\r\n for (let j = 0; j < g[i].length; j++) {\r\n if (j === 0) {\r\n dfs(g[i][j], path);\r\n } else {\r\n dfs(g[i][j]);\r\n }\r\n }\r\n };\r\n dfs(root);\r\n let str = res.length + '\\n';\r\n console.log(res.length);\r\n for (let i = 0; i < res.length; i++) {\r\n str += res[i].length + '\\n';\r\n str += res[i].join(' ') + '\\n';\r\n }\r\n console.log(str);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "cd2a9169186c4ade98548c29bbdacdf0"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, p] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n // console.log(solve(n, p, arr), solve2(n, p, arr))\r\n output[i] = Math.min(solve(n, p, arr.slice()), solve2(n, p, arr.slice()))\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, p, arr) {\r\n const map = arr.reduce((o, x) => {\r\n o[x] = 1\r\n // o[x] = (o[x] || 0) + 1\r\n return o\r\n }, {})\r\n\r\n const last = arr[n - 1]\r\n let c = 0\r\n let x = last\r\n let limit = p\r\n while (map[x] && c < limit) {\r\n if (!x) x = p\r\n x--\r\n c++\r\n }\r\n if (last + c >= p) {\r\n limit -= c\r\n //\r\n arr[n - 1] = 0\r\n map[0] = 1\r\n //\r\n let carry = 1\r\n for (let i = n - 2; i >= 0; i--) {\r\n arr[i] += carry\r\n if (arr[i] === p) {\r\n arr[i] = 0\r\n carry = 1\r\n } else {\r\n carry = 0\r\n }\r\n map[arr[i]] = 1\r\n }\r\n if (carry) {\r\n arr.unshift(1)\r\n map[1] = 1\r\n }\r\n //\r\n while (map[x] && c < limit) {\r\n if (!x) x = p\r\n x--\r\n c++\r\n }\r\n }\r\n return p - c\r\n}\r\nfunction solve2(n, p, arr) {\r\n const map = arr.reduce((o, x) => {\r\n o[x] = 1\r\n // o[x] = (o[x] || 0) + 1\r\n return o\r\n }, {})\r\n\r\n const last = arr[n - 1]\r\n let c = p - last // last -> p\r\n let ans = c\r\n if (last + c >= p) {\r\n //\r\n arr[n - 1] = 0\r\n map[0] = 1\r\n //\r\n let carry = 1\r\n for (let i = n - 2; i >= 0; i--) {\r\n arr[i] += carry\r\n if (arr[i] === p) {\r\n arr[i] = 0\r\n carry = 1\r\n } else {\r\n carry = 0\r\n }\r\n map[arr[i]] = 1\r\n }\r\n if (carry) {\r\n arr.unshift(1)\r\n map[1] = 1\r\n }\r\n //\r\n let x = last\r\n while (x > 0 && map[x]) {\r\n // if (!x) x = p\r\n x--\r\n // c++\r\n }\r\n ans += x\r\n }\r\n // console.log('fake', c, ans)\r\n return ans\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, p] = rns(),\r\n a = rns();\r\n let b = a[n - 1],\r\n set = new Set(a);\r\n let t = -1;\r\n for (let i = b; i >= 0; i--) {\r\n if (set.has(i)) continue;\r\n t = i;\r\n break;\r\n }\r\n if (t === -1) {\r\n for (let i = p - 1; i >= b; i--) {\r\n if (set.has(i)) continue;\r\n t = i;\r\n break;\r\n }\r\n if (t === -1) return 0;\r\n return t - b;\r\n } else {\r\n let res = p - b;\r\n set.add(0);\r\n for (let j = n - 2; j >= 0; j--) {\r\n if (a[j] === p - 1) continue;\r\n set.add(a[j] + 1);\r\n for (let i = t; i >= 0; i--) {\r\n if (set.has(i)) continue;\r\n return res + i;\r\n }\r\n return res;\r\n }\r\n set.add(1);\r\n for (let i = t; i >= 0; i--) {\r\n if (set.has(i)) continue;\r\n return res + i;\r\n }\r\n return res;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, p] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n // console.log(solve(n, p, arr), solve2(n, p, arr))\r\n output[i] = Math.min(solve(n, p, arr), solve2(n, p, arr))\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, p, arr) {\r\n const map = arr.reduce((o, x) => {\r\n o[x] = 1\r\n // o[x] = (o[x] || 0) + 1\r\n return o\r\n }, {})\r\n\r\n const last = arr[n - 1]\r\n let c = 0\r\n let x = last\r\n let limit = p\r\n while (map[x] && c < limit) {\r\n if (!x) x = p\r\n x--\r\n c++\r\n }\r\n if (last + c >= p) {\r\n limit -= c\r\n //\r\n arr[n - 1] = 0\r\n map[0] = 1\r\n //\r\n let carry = 1\r\n for (let i = n - 2; i >= 0; i--) {\r\n arr[i] += carry\r\n if (arr[i] === p) {\r\n arr[i] = 0\r\n carry = 1\r\n } else {\r\n carry = 0\r\n }\r\n map[arr[i]] = 1\r\n }\r\n if (carry) {\r\n arr.unshift(1)\r\n map[1] = 1\r\n }\r\n //\r\n while (map[x] && c < limit) {\r\n if (!x) x = p\r\n x--\r\n c++\r\n }\r\n }\r\n return p - c\r\n}\r\nfunction solve2(n, p, arr) {\r\n const map = arr.reduce((o, x) => {\r\n o[x] = 1\r\n // o[x] = (o[x] || 0) + 1\r\n return o\r\n }, {})\r\n\r\n const last = arr[n - 1]\r\n let c = p - last // last -> p\r\n let ans = c\r\n if (last + c >= p) {\r\n //\r\n arr[n - 1] = 0\r\n map[0] = 1\r\n //\r\n let carry = 1\r\n for (let i = n - 2; i >= 0; i--) {\r\n arr[i] += carry\r\n if (arr[i] === p) {\r\n arr[i] = 0\r\n carry = 1\r\n } else {\r\n carry = 0\r\n }\r\n map[arr[i]] = 1\r\n }\r\n if (carry) {\r\n arr.unshift(1)\r\n map[1] = 1\r\n }\r\n //\r\n let x = last\r\n while (x > 0 && map[x]) {\r\n // if (!x) x = p\r\n x--\r\n // c++\r\n }\r\n ans += x\r\n }\r\n // console.log('fake', c, ans)\r\n return ans\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, p] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, p, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, p, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = 1\n // o[x] = (o[x] || 0) + 1\n return o\n }, {})\n\n const last = arr[n - 1]\n let c = 0\n let x = last\n let limit = p\n while (map[x] && c < limit) {\n if (!x) x = p\n x--\n c++\n }\nlet r1 = p - c\n let fake = 0\n if (last + c >= p) {\n //\n } else {\n fake = p - (last + c)\n c = p - last\n }\n if (last + c >= p) {\n limit -= c\n //\n arr[n - 1] = 0\n map[0] = 1\n //\n let carry = 1\n for (let i = n - 2; i >= 0; i--) {\n if (++arr[i] === p) {\n arr[i] = 0\n carry = 1\n } else {\n carry = 0\n }\n map[arr[i]] = 1\n }\n if (carry) {\n arr.unshift(1)\n map[1] = 1\n }\n //\n while (map[x] && c < limit) {\n if (!x) x = p\n x--\n c++\n }\n }\nlet r2 = fake + p - c\n // console.log(arr, fake, r2)\n return Math.min(r1, r2)\n // let max = 0\n // for (let i = 0; i < n - 1; i++) {\n // if (arr[i] < last && arr[i] > max) {\n // max = arr[i]\n // }\n // }\n // return [n, p, arr]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, p] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, p, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, p, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = 1\n // o[x] = (o[x] || 0) + 1\n return o\n }, {})\n\n const last = arr[n - 1]\n let c = 0\n let x = last\n let limit = p\n while (map[x] && c < limit) {\n if (!x) x = p\n x--\n c++\n }\n if (last + c >= p) {\n limit -= c\n //\n arr[n - 1] = 0\n map[0] = 1\n //\n let carry = 1\n for (let i = n - 2; i >= 0; i--) {\n if (++arr[i] === p) {\n arr[i] = 0\n carry = 1\n } else {\n carry = 0\n }\n map[arr[i]] = 1\n }\n if (carry) {\n arr.unshift(1)\n map[1] = 1\n }\n //\n while (map[x] && c < limit) {\n if (!x) x = p\n x--\n c++\n }\n }\n // console.log(arr)\n return p - c\n // let max = 0\n // for (let i = 0; i < n - 1; i++) {\n // if (arr[i] < last && arr[i] > max) {\n // max = arr[i]\n // }\n // }\n // return [n, p, arr]\n}\n"}], "src_uid": "716965622c7c5fbc78217998d4bfe9ab"} {"source_code": "var n = parseInt(readline());\nvar a = new Array();\nvar x = new Array();\nvar y = new Array();\nvar bx = new Array();\nvar by = new Array();\nvar d = new Array();\nvar ans = -1;\nvar tt = 0;\nfor(var i=0;i<4;i++)\n{\n a[i] = new Array();\n\tx[i] = new Array();\n\ty[i] = new Array();\n\td[i] = new Array();\n\t\n\tfor(var j=0;j<4;j++)\n\t{\n\t x[i][j]=new Array();\n\t\ty[i][j]=new Array();\n\t}\n}\nwhile(n--)\n{\n ans = -1;\n\ttt = 0;\n for(var i=0;i<4;i++)\n\t{\n var str = readline().split(' ');\n\t for(var j=0;j<4;j++)\n\t\t{\n\t\t a[i][j]=parseInt(str[j]);\n\t\t}\n\t\tvar l = a[i][0] - a[i][2];\n\t\tvar s = a[i][1] - a[i][3];\n\t\tx[i][0] = a[i][2]+l;\n\t\ty[i][0] = a[i][3]+s;\n\t\tx[i][1] = a[i][2]-s;\n\t\ty[i][1] = a[i][3]+l;\n\t\tx[i][2] = a[i][2]-l;\n\t\ty[i][2] = a[i][3]-s;\n\t\tx[i][3] = a[i][2]+s;\n\t\ty[i][3] = a[i][3]-l;\n\t}\n\tgao(0);\n\tprint(ans);\n}\n\nfunction gao(k)\n{\n if(ans!=-1&&tt>=ans)\n\t{\n\t return;\n\t}\n\tif(k==4)\n\t{\n\t if(isCube())\n\t\t{\n\t\t\tif(ans==-1||tt=ans)\n\t{\n\t return;\n\t}\n\tif(k==4)\n\t{\n\t if(isCube())\n\t\t{\n\t\t\tif(ans==-1||tt {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n //do nothing?\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n var list = str.split(' ')\n var up = false\n\n for(var i = list.length-2;i>=0;i--){\n if(parseInt(list[i])parseInt(list[i+1])){\n if(up == true){\n // there's a turn\n return i+1\n }\n else{\n continue\n }\n }\n else{\n continue\n }\n }\n return '0'\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (len === 1) {\n console.log(0);\n continue;\n }\n let i = len - 1;\n let count = 1;\n\n for (; i >= 1; i--) {\n if (arr[i] > arr[i - 1]) break;\n count++;\n }\n for (; i >= 1; i--) {\n if (arr[i] < arr[i - 1]) break;\n count++;\n }\n console.log(len - count);\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar lastIndex = -1;\n\t\tvar negative = false;\n\t\tfor(var j = N - 2; j > 0; j--){\n\t\t\tif(list[j] < list[j + 1]){\n\t\t\t\tnegative = true;\n\t\t\t}\n\t\t\tif(list[j - 1] > list[j] && list[j] <= list[j + 1] && negative){\n\t\t\t\tlastIndex = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(lastIndex == -1){\n\t\t\tlastIndex = 0;\n\t\t}\n\t\toutput[i] = lastIndex;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = readArray(Number);\n var a1 = [a[0]];\n var fi = [0];\n for (var i = 1; i < n; i++) {\n if (a[i] !== a[i - 1]) {\n a1.push(a[i]);\n fi.push(i);\n }\n }\n var ind = 0;\n var n1 = a1.length;\n for (var i = 1; i < n1 - 1; i++) {\n if (a1[i] < a1[i + 1] && a1[i] < a1[i - 1]) {\n ind = fi[i];\n }\n }\n write(ind);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar lastIndex = -1;\n\t\tfor(var j = N - 2; j > 0; j--){\n\t\t\tif(list[j - 1] > list[j] && list[j] < list[j + 1]){\n\t\t\t\tlastIndex = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(lastIndex == -1){\n\t\t\tlastIndex = 0;\n\t\t}\n\t\toutput[i] = lastIndex;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar lastIndex = -1;\n\t\tfor(var j = N - 2; j > 0; j--){\n\t\t\tif(list[j - 1] > list[j] && list[j] <= list[j + 1]){\n\t\t\t\tlastIndex = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(lastIndex == -1){\n\t\t\tlastIndex = 0;\n\t\t}\n\t\toutput[i] = lastIndex;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar lastIndex = -1;\n\t\tvar max = 0;\n\t\tfor(var j = N - 2; j > 0; j--){\n\t\t\tif(list[j - 1] > list[j] && list[j] < list[j + 1]){\n\t\t\t\tlastIndex = j;\n\t\t\t}\n\t\t}\n\t\tif(lastIndex == -1){\n\t\t\tlastIndex = 0;\n\t\t}\n\t\toutput[i] = lastIndex;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst { setFlagsFromString } = require('v8');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n //do nothing?\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n var list = str.split(' ')\n var up = false\n\n for(var i = list.length-2;i>=0;i--){\n if(parseInt(list[i]) b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = readArray(Number);\n if (n < 3) {\n write(0);\n return;\n }\n var ind = 0;\n for (var i = n - 2; i > 0; i--) {\n if (a[i] < a[i + 1] && a[i] < a[i - 1]) {\n ind = i;\n break;\n }\n }\n write(ind);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = readArray(Number);\n if (n < 3) {\n write(0);\n return;\n }\n var ind = 0;\n for (var i = n - 2; i > 0; i--) {\n if (a[i] < a[i + 1] && a[i] < a[i - 1]) {\n ind = i;\n break;\n }\n }\n write(i);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n if (n === 1) {\n write(-1);\n return;\n }\n var a = readArray(Number);\n var a1 = [a[0]];\n var fi = [0];\n for (var i = 1; i < n; i++) {\n if (a[i] !== a[i - 1]) {\n a1.push(a[i]);\n fi.push(i);\n }\n }\n var ind = 0;\n var n1 = a1.length;\n for (var i = 1; i < n1 - 1; i++) {\n if (a1[i] < a1[i + 1] && a1[i] < a1[i - 1]) {\n ind = fi[i];\n }\n }\n write(ind);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var n = Number(read());\n var a = readArray(Number);\n var ind = 0;\n for (var i = n - 2; i > 0; i--) {\n if (a[i] < a[i + 1] && a[i] < a[i - 1]) {\n ind = i;\n break;\n }\n }\n write(i);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "src_uid": "731b45747081a800fc6da02efa5ce8cd"} {"source_code": "// Q: https://codeforces.com/contest/1339/problem/B\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t=0; t < test; t++) {\n\t\tlet n = parseInt(input[2*t+1]);\n\t\tlet arr = input[2*t+2].split(' ').map((a) => parseInt(a));\n\t\tconsole.log(solution(n, arr));\n\t}\n});\n\nfunction solution(n, arr) {\n\tarr = arr.sort((a, b) => a-b);\n\tlet ans = [], i = 0, j=n-1;\n\twhile (i <= j) {\n\t\tans.push(arr[i]);\n\t\tif (i < j) {\n\t\t\tans.push(arr[j]);\n\t\t}\n\t\ti++;\n\t\tj--;\n\t}\n\tans = ans.reverse();\n\treturn ans.join(' ');\n}", "positive_code": [{"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=1)}([function(t,n){t.exports=require(\"os\")},function(t,n,r){\"use strict\";r.r(n);var e=function(){function t(t){this.inputs=t,this.startSoln()}return t.prototype.startSoln=function(){for(var t=0,n=this.inputs[t++];n--;){for(var r=this.inputs[t++],e=[],o=0;on?1:0}));this.soln2(t,r)},t.prototype.soln2=function(t,n){var r=Math.floor(t/2),e=r,o=[];o.push(n[r]);var i=0;for(t%2==0&&i++;o.length!==t;){var u=i%2==0;!0===u?e+1=0?(r--,o.push(n[r])):(e++,o.push(n[e]))),i++}var s=o.join(\" \").trim();console.log(s)},t}();new(function(){function t(){var t=this;this.inputString=\"\",this.inputString=\"\",process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){return t.inputString+=n})),process.stdin.on(\"end\",(function(){new e(t.convertSpaceSepartedValues())}))}return t.prototype.convertSpaceSepartedValues=function(){for(var t=r(0).EOL,n=[],e=\"\",o=0;on?1:0}));this.soln2(t,r)},t.prototype.soln2=function(t,n){var r=Math.floor(t/2),e=r,o=[];o.push(n[r]);var i=0;for(t%2==0&&i++;o.length!==t;){var u=i%2==0;!0===u?e+1=0?(r--,o.push(n[r])):(e++,o.push(n[e]))),i++}var s=o.join(\" \").trim();console.log(s)},t}();new(function(){function t(){var t=this;this.inputString=\"\",this.inputString=\"\",process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){return t.inputString+=n})),process.stdin.on(\"end\",(function(){new e(t.convertSpaceSepartedValues())}))}return t.prototype.convertSpaceSepartedValues=function(){for(var t=[],n=\"\",r=0;r (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, nums) {\n nums.sort((a, b) => a - b);\n result = []\n for (let i = 0; i*2 < n; ++i) {\n result.push(nums[i]);\n if ( i !== n - i - 1)\n result.push(nums[n - i - 1]);\n }\n return result.reverse().join(' ');\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n = readLine()[0];\n const nums = readLine();\n const S = solve(n, nums);\n console.log(S);\n }\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input = parseInt(readline());\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n var I = 0, j = input - 1, a = []\n for (var i = 0; i < input; i++) {\n if (i % 2) {\n a[i] = input1[I]\n I++\n }\n else {\n a[i] = input1[j]\n j--\n }\n }\n\n a.reverse()\n print(a.join(\" \"))\n }\n\n}\n"}, {"source_code": "var tests = parseInt(readline())\nfor (var t = 0; t < tests; t++){\nvar size = parseInt(readline())\nvar array = readline().split(' ').map(c => parseInt(c))\nvar head = (size%2) ? parseInt(size/2 + 1): size/2\nvar tail = head+1, res = []\narray.sort((a,b) => b-a)\nwhile (head){\n\tres.push(array[head-1],array[tail-1])\n\thead -= 1; tail += 1\n}\nprint(res.join(' '))\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n solve(arr);\n process.exit(0);\n});\n\nfunction solve(lines) {\n let row = 0;\n let t = +lines[row++];\n for(let i = 0; i < t; i++) {\n let n = +lines[row++];\n numbers_to_rearrange = lines[row++].split(\" \").map(x => +x);\n console.log(rearranged_numbers(numbers_to_rearrange).join(\" \"));\n }\n}\n\nfunction rearranged_numbers(arr) {\n arr.sort((a, b) => a - b);\n let len = Math.floor(arr.length / 2) * 2;\n let new_arr = [];\n for(let i = len / 2; i < len; i++) {\n new_arr.push(arr[i]);\n new_arr.push(arr[len - i - 1]);\n }\n if(new_arr.length !== arr.length) {\n new_arr.push(arr[arr.length - 1]);\n }\n return new_arr;\n}\n"}, {"source_code": "//Input\n//==================================================\nconst readline = require('readline');\nconst fs = require('fs');\nvar bufInd=0,buffer = new Array();\n\n\nfunction createReadObject() {\n\tread = readline.createInterface( {\n \tinput: process.stdin,\n \t//input: fs.createReadStream('input.txt'),\n \toutput: process.stdout,\n \tterminal: false\n\t} );\n}\n\nfunction loadBuffer(inpLine) {\n\tvar t = inpLine.split(\" \");\n\tfor(var i of t)\n\t\tbuffer.push(i);\n}\n\nfunction getString() {\n\ttry {\n\t\treturn buffer[bufInd++];\n\t} catch(e) {\n\t\tconsole.log(e);\n\t}\t\n}\n\n\nfunction inpNumber() {\n\tvar integer = +getString();\n\treturn integer;\n}\n\nfunction inpString() {\n\tvar string = getString();\n\treturn string;\n}\n\n//================================================\n\n//Merge Sort\n//================================================\nfunction Merge (array,start,mid,end) {\n\tlet lt = [],rt = [];\n\tfor (let i = start; i < mid; i++)\n\t\tlt.push(array[i]);\n\n\tfor(let i = mid; i0) {\n\t\tlet n;\n\t\tlet ar = new Array();\n\t\tn = inpNumber();\n\n\t\tfor (let i = 0; i -1)\n\t\t\t\tres += \" \"+ar[pivot-i].toString();\n\t\t}\n\n\t\tconsole.log(res);\n\t\tt--;\n\t}\n}\n\n\n//take input and call solution function\ncreateReadObject();\nread.on('line',(inp) => {\n\tloadBuffer(inp);\n});\nread.on('close',() => {\n\t//console.log(\"finished\");\n\tmain();\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(a, n) {\n a.sort((a, b) => a - b);\n let startIdx = Math.floor(n / 2);\n let res = [];\n res.push(a[startIdx]);\n for (let i = 1; i < n / 2 + 1; i++) {\n if (startIdx - i >= 0) res.push(a[startIdx - i]);\n if (startIdx + i < n) res.push(a[startIdx + i]);\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(a, n);\n let s = '';\n for (let i = 0; i < n; i++) s += res[i] + ' ';\n console.log(s);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(num) {\n return +num;\n}\nfunction sorter(a, b) {\n return a-b;\n}\n\nfor (var i = 0; i < t; i++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(mapper).sort(sorter);\n\n var b = [];\n var m = Math.floor(n / 2);\n \n if (n % 2 !== 0) {\n b.push(a[m]);\n \n for (var j = 1; j <= m; j++) {\n b.push(a[m + j]);\n b.push(a[m - j]);\n }\n } else {\n for (var j = 1; j <= m; j++) {\n b.push(a[m + j - 1]);\n b.push(a[m - j]);\n }\n }\n \n print(b.join(' '));\n}"}, {"source_code": "//Input\n//==================================================\nconst readline = require('readline');\nconst fs = require('fs');\nvar bufInd=0,buffer = new Array();\n\n\nfunction createReadObject() {\n\tread = readline.createInterface( {\n \tinput: process.stdin,\n \t//input: fs.createReadStream('input.txt'),\n \toutput: process.stdout,\n \tterminal: false\n\t} );\n}\n\nfunction loadBuffer(inpLine) {\n\tvar t = inpLine.split(\" \");\n\tfor(var i of t)\n\t\tbuffer.push(i);\n}\n\nfunction getString() {\n\ttry {\n\t\treturn buffer[bufInd++];\n\t} catch(e) {\n\t\tconsole.log(e);\n\t}\t\n}\n\n\nfunction inpNumber() {\n\tvar integer = +getString();\n\treturn integer;\n}\n\nfunction inpString() {\n\tvar string = getString();\n\treturn string;\n}\n\n//================================================\n\n//Merge Sort\n//================================================\nfunction Merge (array,start,mid,end) {\n\tlet lt = [],rt = [];\n\tfor (let i = start; i < mid; i++)\n\t\tlt.push(array[i]);\n\n\tfor(let i = mid; i0) {\n\t\tlet n;\n\t\tlet ar = new Array();\n\t\tn = inpNumber();\n\n\t\tfor (let i = 0; i {\n\t\t\treturn a-b;\n\t\t});\n\n\t\tlet pivot = Math.floor((n+1)/2) - 1;\n\t\tlet res = ar[pivot].toString();\n\t\tfor(let i=1; i -1)\n\t\t\t\tres += \" \"+ar[pivot-i].toString();\n\t\t}\n\n\t\tconsole.log(res);\n\t\tt--;\n\t}\n}\n\n\n//take input and call solution function\ncreateReadObject();\nread.on('line',(inp) => {\n\tloadBuffer(inp);\n});\nread.on('close',() => {\n\t//console.log(\"finished\");\n\tmain();\n});"}, {"source_code": "var inputs = readline();\n\nfor(var k=0;k parseInt(x));\n\n var output = [];\n var sortedTimes = times.sort((a, b) => a - b);\n \n for(var i=0,j=sortedTimes.length-1;i<=j;i++,j--){\n if(i === j) {\n output.push(times[i]);\n }else {\n if(sortedTimes.length % 2 === 0) {\n output.push(sortedTimes[i], sortedTimes[j]);\n } else {\n output.push(sortedTimes[j], sortedTimes[i]);\n }\n }\n\n }\n print(output.reverse().join(\" \"));\n}"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tasks = [];\nrl.on('line', (line) => {\n tasks.push(line);\n}).on('close', () => {\n for (let index = 2; index < tasks.length; index += 2) {\n let task = tasks[index].split(' ').map(v => +v).sort((a, b) => a - b);\n const centre = Math.ceil(task.length / 2) - 1;\n let i = 1;\n\n const newArr = [];\n newArr.push(task[centre])\n while(true) {\n if(task[centre + i] !== undefined) {\n newArr.push(task[centre + i]);\n }\n if (task[centre - i] !== undefined) {\n newArr.push(task[centre - i]);\n }\n if (task[centre + i] === undefined && task[centre - i] === undefined) break;\n \n i++;\n }\n \n process.stdout.write(`${newArr.join(' ')}\\n`);\n }\n});\n"}], "negative_code": [{"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=1)}([function(t,n){t.exports=require(\"os\")},function(t,n,r){\"use strict\";r.r(n);var e=function(){function t(t){this.inputs=t,this.startSoln()}return t.prototype.startSoln=function(){for(var t=0,n=this.inputs[t++];n--;){for(var r=this.inputs[t++],e=[],o=0;on?1:0}));this.soln2(t,r)},t.prototype.soln2=function(t,n){var r=Math.floor(t/2),e=r,o=[];o.push(n[r]);for(var u=0;o.length!==t;){var i=u%2==0;!0===i?e+1=0?(r--,o.push(n[r])):(e++,o.push(n[e]))),u++}var f=o.join(\" \").trim();console.log(f)},t}(),o=function(){for(var t=0,n=0,r=arguments.length;n0}))).map((function(t){return+t})))}))}return t.prototype.convertSpaceSepartedValues=function(t){var n=[];return t.forEach((function(t){n=o(n,t.split(\" \"))})),n},t}())}]);"}, {"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=1)}([function(t,n){t.exports=require(\"os\")},function(t,n,r){\"use strict\";r.r(n);var e=function(){function t(t){this.inputs=t,this.startSoln()}return t.prototype.startSoln=function(){for(var t=0,n=this.inputs[t++];n--;){for(var r=this.inputs[t++],e=[],o=0;on?1:0})),e=-1,o=-1,u=Math.abs(-2e10),i=0;i=0&&(f=Math.abs(r[e]-r[e-1])),o+10}))).map((function(t){return+t})))}))}return t.prototype.convertSpaceSepartedValues=function(t){var n=[];return t.forEach((function(t){n=o(n,t.split(\" \"))})),n},t}())}]);"}, {"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=1)}([function(t,n){t.exports=require(\"os\")},function(t,n,r){\"use strict\";r.r(n);var e=function(){function t(t){this.inputs=t,this.startSoln()}return t.prototype.startSoln=function(){for(var t=0,n=this.inputs[t++];n--;){for(var r=this.inputs[t++],e=[],o=0;on?1:0})),e=-1,o=-1,u=Math.abs(-2e10),i=0;i=0&&(f=Math.abs(r[e]-r[e-1])),o+10}))).map((function(t){return+t})))}))}return t.prototype.convertSpaceSepartedValues=function(t){var n=[];return t.forEach((function(t){n=o(n,t.split(\" \"))})),n},t}())}]);"}, {"source_code": "\n\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input = parseInt(readline());\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n var I = 0, j = input - 1, a = []\n for (var i = 0; i < input; i++) {\n if (i % 2) {\n a[i] = input1[I]\n I++\n }\n else {\n a[i] = input1[j]\n j--\n }\n }\n\n a.sort((x, y) => x - y)\n\n print(a)\n }\n\n}"}, {"source_code": "\n\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input = parseInt(readline());\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n var I = 0, j = input - 1, a = []\n for (var i = 0; i < input; i++) {\n if (i % 2) {\n a[i] = input1[I]\n I++\n }\n else {\n a[i] = input1[j]\n j--\n }\n }\n\n a.sort((x, y) => x - y)\n print(a.join(\" \"))\n }\n\n}"}, {"source_code": "\n\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input = parseInt(readline());\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n var I = 0, j = input - 1, a = []\n for (var i = 0; i < input; i++) {\n if (i % 2) {\n a[i] = input1[I]\n I++\n }\n else {\n a[i] = input1[j]\n j--\n }\n }\n\n a.sort((x, y) => y - x)\n\n print(a)\n }\n\n}"}, {"source_code": "\n\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input = parseInt(readline());\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n var I = 0, j = input - 1, a = []\n for (var i = 0; i < input; i++) {\n if (i % 2) {\n a[i] = input1[I]\n I++\n }\n else {\n a[i] = input1[j]\n j--\n }\n }\n\n a.sort((x, y) => y - x)\n print(a.join(\" \"))\n }\n\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(a, n) {\n a.sort((a, b) => a - b);\n let startIdx = Math.floor(n / 2);\n let res = [];\n res.push(a[startIdx]);\n for (let i = 1; i < n / 2 + 1; i++) {\n if (startIdx - i >= 0) res.push(a[startIdx - i]);\n if (startIdx + i < n) res.push(a[startIdx + i]);\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(a, n);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(a, n) {\n a.sort((a, b) => a - b);\n let startIdx = Math.floor(n / 2);\n let res = [];\n res.push(a[startIdx]);\n if (n % 2 === 0) res.push(a[startIdx - 1])\n for (let i = 1; i < n / 2 + 1; i++) {\n if (i === 1 && n % 2 === 0) {\n if (startIdx + i < n) res.push(a[startIdx + i]);\n continue;\n }\n if (startIdx - i >= 0) res.push(a[startIdx - i]);\n if (startIdx + i < n) res.push(a[startIdx + i]);\n }\n return res;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(a, n);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "var tests = parseInt(readline())\nfor (t in tests){\nvar size = parseInt(readline())\nvar array = readline().split(' ').map(c => parseInt(c))\nvar head = (size%2) ? parseInt(size/2 + 1): size/2\nvar tail = head+1, res = []\narray.sort((a,b) => b-a)\nwhile (head){\n\tres.push(array[head-1],array[tail-1])\n\thead -= 1; tail += 1\n}\nprint(res.join(' '))\n}\n"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(num) {\n return parseInt(num);\n}\n\nfor (var i = 0; i < t; i++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(mapper).sort();\n\n var b = [];\n var m = Math.floor(n / 2);\n \n if (n % 2 !== 0) {\n b.push(a[m]);\n \n for (var j = 1; j <= m; j++) {\n b.push(a[m + j]);\n b.push(a[m - j]);\n }\n } else {\n for (var j = 1; j <= m; j++) {\n b.push(a[m + j - 1]);\n b.push(a[m - j]);\n }\n }\n \n print(b.join(' '));\n}"}, {"source_code": "var inputs = readline();\n \nfor(var i=0;i parseInt(x));\n var output = [];\n var counter = 0;\n \n while(times.length) {\n if(times.length >= 2) {\n var max = Math.max.apply(null, times);\n var min = Math.min.apply(null, times);\n if(counter % 2 == 0) {\n output.push(min, max);\n } else {\n output.push(max, min);\n\n }\n times.splice(times.indexOf(max), 1);\n times.splice(times.indexOf(min), 1);\n counter++;\n } else {\n output.push(times.pop());\n }\n\n }\n print(output.reverse().join(\" \"));\n}"}, {"source_code": "var inputs = readline();\n \nfor(var i=0;i parseInt(x));\n var output = [];\n var counter = 0;\n times = times.sort((a, b) => a - b);\n \n for(var i=0,j=times.length-1;i<=j;i++,j--){\n if(i === j) {\n output.push(times[i]);\n }else {\n if(times.length % 2 === 0) {\n output.push(times[i], times[j]);\n } else {\n output.push(times[j], times[i]);\n }\n }\n\n }\n print(output.reverse().join(\" \"));\n}"}, {"source_code": "var inputs = readline();\n \nfor(var i=0;i parseInt(x));\n var output = [];\n var counter = 0;\n \n while(times.length) {\n var max = Math.max.apply(null, times);\n var min = Math.min.apply(null, times);\n if(counter % 2 == 0) {\n output.push(min, max);\n } else {\n output.push(max, min);\n\n }\n times.splice(times.indexOf(max), 1);\n times.splice(times.indexOf(min), 1);\n counter++;\n\n }\n print(output.reverse().join(\" \"));\n}"}, {"source_code": "var inputs = readline();\n \nfor(var i=0;i parseInt(x));\n var output = [];\n var counter = 0;\n \n while(times.length) {\n var max = Math.max.apply(null, times);\n var min = Math.min.apply(null, times);\n if(counter % 2 == 0) {\n output.push(min, max);\n } else {\n output.push(max, min);\n\n }\n times.splice(times.indexOf(max), 1);\n times.splice(times.indexOf(min), 1);\n counter++;\n\n }\n print(output.reverse());\n}"}, {"source_code": "//Input\n//==================================================\nconst readline = require('readline');\nconst fs = require('fs');\nvar bufInd=0,buffer = new Array();\n\n\nfunction createReadObject() {\n\tread = readline.createInterface( {\n \tinput: process.stdin,\n \t//input: fs.createReadStream('input.txt'),\n \toutput: process.stdout,\n \tterminal: false\n\t} );\n}\n\nfunction loadBuffer(inpLine) {\n\tvar t = inpLine.split(\" \");\n\tfor(var i of t)\n\t\tbuffer.push(i);\n}\n\nfunction getString() {\n\ttry {\n\t\treturn buffer[bufInd++];\n\t} catch(e) {\n\t\tconsole.log(e);\n\t}\t\n}\n\n\nfunction inpNumber() {\n\tvar integer = +getString();\n\treturn integer;\n}\n\nfunction inpString() {\n\tvar string = getString();\n\treturn string;\n}\n\n//================================================\n\n//Merge Sort\n//================================================\nfunction Merge (array,start,mid,end) {\n\tlet lt = [],rt = [];\n\tfor (let i = start; i < mid; i++)\n\t\tlt.push(array[i]);\n\n\tfor(let i = mid; i0) {\n\t\tlet n;\n\t\tlet ar = new Array();\n\t\tn = inpNumber();\n\n\t\tfor (let i = 0; i n-1) {\n\t\t\t\tminInd -= i;\n\t\t\t\tnext = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres += \" \"+ar[minInd+i].toString();\n\t\t\t\tres += \" \"+ar[minInd-i].toString();\n\t\t\t}\n\t\t}\n\n\t\twhile(minInd < n && minInd > -1) {\n\t\t\tres += \" \"+ar[minInd].toString();\n\t\t\tminInd += next;\n\t\t}\n\n\t\tconsole.log(res);\n\t\tt--;\n\t}\n}\n\n\n//take input and call solution function\ncreateReadObject();\nread.on('line',(inp) => {\n\tloadBuffer(inp);\n});\nread.on('close',() => {\n\t//console.log(\"finished\");\n\tmain();\n});"}, {"source_code": "//Input\n//==================================================\nconst readline = require('readline');\nconst fs = require('fs');\nvar buffer = new Array();\n\n\nfunction createReadObject() {\n\tread = readline.createInterface( {\n \tinput: process.stdin,\n \t//input: fs.createReadStream('input.txt'),\n \toutput: process.stdout,\n \tterminal: false\n\t} );\n}\n\nfunction loadBuffer(inpLine) {\n\tvar t = inpLine.split(\" \");\n\tfor(var i of t)\n\t\tbuffer.push(i);\n}\n\nfunction getString() {\n\ttry {\n\t\treturn buffer.shift();\n\t} catch(e) {\n\t\tconsole.log(e);\n\t}\t\n}\n\n\nfunction inpNumber() {\n\tvar integer = +getString();\n\treturn integer;\n}\n\nfunction inpString() {\n\tvar string = getString();\n\treturn string;\n}\n\n//================================================\n\n//Main Function containing solution\nfunction main() {\n\tvar t;\n\tt = inpNumber();\n\t//console.log(t);\n\n\twhile (t>0) {\n\t\tlet n;\n\t\tlet ar = new Array();\n\t\tn = inpNumber();\n\n\t\tfor (let i = 0; i n-1) {\n\t\t\t\tminInd -= i;\n\t\t\t\tnext = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres += \" \"+ar[minInd+i].toString();\n\t\t\t\tres += \" \"+ar[minInd-i].toString();\n\t\t\t}\n\t\t}\n\n\t\twhile(minInd < n && minInd > -1) {\n\t\t\tres += \" \"+ar[minInd].toString();\n\t\t\tminInd += next;\n\t\t}\n\n\t\tconsole.log(res);\n\t\tt--;\n\t}\n}\n\n\n//take input and call solution function\ncreateReadObject();\nread.on('line',(inp) => {\n\tloadBuffer(inp);\n});\nread.on('close',() => {\n\t//console.log(\"finished\");\n\tmain();\n});"}, {"source_code": "//Input\n//==================================================\nconst readline = require('readline');\nconst fs = require('fs');\nvar bufInd=0,buffer = new Array();\n\n\nfunction createReadObject() {\n\tread = readline.createInterface( {\n \tinput: process.stdin,\n \t//input: fs.createReadStream('input.txt'),\n \toutput: process.stdout,\n \tterminal: false\n\t} );\n}\n\nfunction loadBuffer(inpLine) {\n\tvar t = inpLine.split(\" \");\n\tfor(var i of t)\n\t\tbuffer.push(i);\n}\n\nfunction getString() {\n\ttry {\n\t\treturn buffer[bufInd++];\n\t} catch(e) {\n\t\tconsole.log(e);\n\t}\t\n}\n\n\nfunction inpNumber() {\n\tvar integer = +getString();\n\treturn integer;\n}\n\nfunction inpString() {\n\tvar string = getString();\n\treturn string;\n}\n\n//================================================\n\n//Merge Sort\n//================================================\nfunction Merge (array,start,mid,end) {\n\tlet lt = [],rt = [];\n\tfor (let i = start; i < mid; i++)\n\t\tlt.push(array[i]);\n\n\tfor(let i = mid; i0) {\n\t\tlet n;\n\t\tlet ar = new Array();\n\t\tn = inpNumber();\n\n\t\tfor (let i = 0; i n-1) {\n\t\t\t\tminInd -= i;\n\t\t\t\tnext = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres += \" \"+ar[minInd+i].toString();\n\t\t\t\tres += \" \"+ar[minInd-i].toString();\n\t\t\t}\n\t\t}\n\n\t\twhile(minInd < n && minInd > -1) {\n\t\t\tres += \" \"+ar[minInd].toString();\n\t\t\tminInd += next;\n\t\t}\n\n\t\tconsole.log(res);\n\t\tt--;\n\t}\n}\n\n\n//take input and call solution function\ncreateReadObject();\nread.on('line',(inp) => {\n\tloadBuffer(inp);\n});\nread.on('close',() => {\n\t//console.log(\"finished\");\n\tmain();\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tasks = [];\nrl.on('line', (line) => {\n tasks.push(line);\n}).on('close', () => {\n for (let index = 2; index < tasks.length; index += 2) {\n let task = tasks[index].split(' ').map(v => +v).sort((a, b) => a - b);\n const centre = Math.ceil(task.length / 2);\n let i = 1;\n\n const newArr = [];\n newArr.push(task[centre])\n while(true) {\n if(task[centre + i] !== undefined) {\n newArr.push(task[centre + i]);\n }\n if (task[centre - i] !== undefined) {\n newArr.push(task[centre - i]);\n }\n if (task[centre + i] === undefined && task[centre - i] === undefined) break;\n \n i++;\n }\n \n process.stdout.write(`${newArr.join(' ')}\\n`);\n }\n});\n"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tasks = [];\nrl.on('line', (line) => {\n tasks.push(line);\n}).on('close', () => {\n for (let index = 2; index < tasks.length; index += 2) {\n let task = tasks[index].split(' ').map(v => +v).sort((a, b) => a - b);\n const centre = Math.floor(task.length / 2) - 1;\n let i = 1;\n\n const newArr = [];\n newArr.push(task[centre])\n while(true) {\n if(task[centre + i] !== undefined) {\n newArr.push(task[centre + i]);\n }\n if (task[centre - i] !== undefined) {\n newArr.push(task[centre - i]);\n }\n if (task[centre + i] === undefined && task[centre - i] === undefined) break;\n \n i++;\n }\n \n process.stdout.write(`${newArr.join(' ')}\\n`);\n }\n});"}], "src_uid": "3c8bfd3199a9435cfbdee1daaacbd1b3"} {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var nxt = readArray(BigInt);\r\n var n = nxt[0];\r\n var x = nxt[1];\r\n var t = nxt[2];\r\n var maxAngry = t / x;\r\n if (n <= maxAngry + 1n) {\r\n write(n * (n - 1n) / 2n);\r\n return;\r\n }\r\n write((maxAngry * (maxAngry - 1n) / 2n) + (maxAngry * (n - maxAngry)));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 06/21/21 morning\r\nconst solve = (n, x, t) => {\r\n let each = t / x;\r\n let len = mill(n, each);\r\n let res = (n - len) * each + (len - 1n) * len / 2n;\r\n pr(res.toString());\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => ll(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const k = input.number();\r\n const ans = Array(k);\r\n for (let i = 0; i < k; i++) {\r\n const [n, x, t] = input.bigints(3);\r\n const c = t / x;\r\n const m = bigIntMin(c, n);\r\n ans[i] = n * c - (c * (c + 1n)) / 2n + ((c - m) * (c - m + 1n)) / 2n;\r\n }\r\n console.log(ans.join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, d, tot] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n let l = tot / d;\r\n if (l >= n) {\r\n n--;\r\n console.log((n * (n + 1n)) / 2n + \"\");\r\n continue;\r\n }\r\n n--;\r\n let i = (n - (l - 1n)) * l;\r\n let j = n - (n - (l - 1n));\r\n i += (j * (j + 1n)) / 2n;\r\n console.log(i + \"\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var args = lines[l++].split(' ').map(Number)\n console.log(solve(args));\n }\n});\n \nfunction solve([n, x, t]) {\n const k = Math.min(n, Math.floor(t / x))\n const rest = BigInt(k - 1 + 1) * BigInt(k - 1) / 2n\n const br = BigInt(n - k) * BigInt(k) + rest\n return br.toString()\n}"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n,x,t;\r\n [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));\r\n if (t n) {\r\n console.log((n * (n- BigInt(1)) / BigInt(2)).toString());\r\n }\r\n else {\r\n console.log((n * bad - bad * (bad + BigInt(1)) / BigInt(2)).toString());\r\n }\r\n\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, d, tot] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n let l = tot / d;\r\n if (l >= n) {\r\n l--;\r\n console.log((l * (l + 1n)) / 2n + \"\");\r\n continue;\r\n }\r\n n--;\r\n let i = (n - (l - 1n)) * l;\r\n let j = n - (n - (l - 1n));\r\n i += (j * (j + 1n)) / 2n;\r\n console.log(i + \"\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var args = lines[l++].split(' ').map(Number)\n console.log(solve(args));\n }\n});\n\nfunction solve([n, x, t]) {\n const k = Math.floor(t / x)\n const rest = BigInt(k - 1 + 1) * BigInt(k - 1) / 2n\n const br = BigInt(n - k) * BigInt(k) + rest\n return br.toString()\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var args = lines[l++].split(' ').map(Number)\n console.log(solve(args));\n }\n});\n\nfunction solve([n, x, t]) {\n const k = Math.floor(t / x)\n const rest = (k - 1 + 1) * (k - 1) / 2\n return (n - k) * k + rest\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n,x,t;\r\n [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));\r\n if (t ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n let n,x,t;\r\n [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));\r\n if (t { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 06/21/21 morning\r\nconst solve = (n, x, t) => {\r\n let each = t / x >> 0;\r\n let len = mi(n, each);\r\n pr((n - len) * each + (len - 1) * len / 2);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const k = input.number();\r\n const ans = Array(k);\r\n for (let i = 0; i < k; i++) {\r\n const [n, x, t] = input.bigints(3);\r\n const c = t / x;\r\n ans[i] = n * c - (c * (c + 1n)) / 2n;\r\n }\r\n console.log(ans.join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}], "src_uid": "4df38c9b42b0f0963a121829080d3571"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\t//1365D\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tvar dy = [-1,0,1,0];\n\tvar dx = [0,-1,0,1];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar isG = false;\n\t\tvar isB = false;\n\t\tvar bList = [];\n\t\tvar gList = [];\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = nextCharArray();\n\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\tif(list[j][k] == \"G\"){\n\t\t\t\t\tisG = true;\n\t\t\t\t\tgList.push([j,k]);\n\t\t\t\t}\n\t\t\t\tif(list[j][k] == \"B\"){\n\t\t\t\t\tisB = true;\n\t\t\t\t\tbList.push([j,k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(isG){\n\t\t\tvar gCount = 0;\n\t\t\t//\u4e21\u65b9\u3044\u308b\u3068\u304d\u304c\u30e4\u30d0\u30a4\n\t\t\t//\u3068\u308a\u3042\u3048\u305aB\u306e4\u65b9\u3092\u9632\u3044\u3067\u3057\u307e\u3046\n\t\t\tfor(var j = 0; j < bList.length; j++){\n\t\t\t\tfor(var k = 0; k < dy.length; k++){\n\t\t\t\t\tvar tonariY = bList[j][0] + dy[k];\n\t\t\t\t\tvar tonariX = bList[j][1] + dx[k];\n\t\t\t\t\tif(tonariY < N && tonariY >= 0 && tonariX < M && tonariX >= 0){\n\t\t\t\t\t\tif(list[tonariY][tonariX] != \"G\" && list[tonariY][tonariX] != \"B\"){\n\t\t\t\t\t\t\tlist[tonariY][tonariX] = \"#\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfunction bfs(startY, startX){\n\t\t\t\tvar access = new Array(N);\n\t\t\t\tvar sIndex = 0;\n\t\t\t\tvar eIndex = 1;\n\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\taccess[l] = new Array(M).fill(false);\n\t\t\t\t}\n\t\t\t\tvar queue = new Array(4000);\n\t\t\t\tqueue[0] = [startY, startX];\n\t\t\t\taccess[startY][startX] = true;\n\t\t\t\twhile(sIndex != eIndex){\n\t\t\t\t\tvar tmp = queue[sIndex];\n\t\t\t\t\tsIndex++;\n\t\t\t\t\tvar y = tmp[0];\n\t\t\t\t\tvar x = tmp[1];\n\t\t\t\t\tif(list[y][x] == \"B\"){\n\t\t\t\t\t\tisOK = false;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}else if(list[y][x] == \"G\"){\n\t\t\t\t\t\tgCount++;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var l = 0; l < dy.length; l++){\n\t\t\t\t\t\tvar nextY = y + dy[l];\n\t\t\t\t\t\tvar nextX = x + dx[l];\n\t\t\t\t\t\tif(nextY < N && nextY >= 0 && nextX < M && nextX >= 0){\n\t\t\t\t\t\t\tif(!access[nextY][nextX] && list[nextY][nextX] != \"#\"){\n\t\t\t\t\t\t\t\taccess[nextY][nextX] = true;\n\t\t\t\t\t\t\t\tqueue[eIndex] = [nextY, nextX];\n\t\t\t\t\t\t\t\teIndex++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar isOK = true;\n\t\t\tbfs(N - 1, M - 1);\n\t\t\tif(!isOK || gCount != gList.length){\n\t\t\t\toutput[i] = \"No\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\toutput[i] = \"Yes\";\n\t\t}else{\n\t\t\toutput[i] = \"Yes\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nArray.fill = function(n, m, no = 0) {\n const a = new Array(n)\n for(let i = 0; i < n; i++) a[i] = new Array(m).fill(no)\n return a\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n let hasTestCases = true\n if(hasTestCases) {\n let t = rc.readInt()\n while(t--) main()\n }\n else main()\n})\n\nfunction main() {\n const [n, m] = rc.readInts()\n const a = new Array(n)\n for (let i = 0; i < n; i++) a[i] = rc.readString().split('')\n\n let canPass = true\n\n // wr(a)\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if(a[i][j] === 'B') {\n canPass = checkBorder(i - 1, j) && checkBorder(i, j - 1) && checkBorder(i + 1, j) && checkBorder(i, j + 1)\n if(!canPass) {\n wr('No')\n return\n }\n }\n }\n }\n\n const r = Array.fill(n, m)\n\n let queue = []\n if(a[n - 1][m - 1] !== '#') queue.push([n - 1, m - 1])\n\n while(queue.length) {\n let newQueue = []\n queue.forEach(([i, j]) => {\n r[i][j] = 1\n markR(i - 1, j)\n markR(i + 1, j)\n markR(i, j - 1)\n markR(i, j + 1)\n function markR(i, j) {\n if(i >= 0 && i < n && j >= 0 && j < m) {\n if((a[i][j] === 'G' || a[i][j] === '.') && !r[i][j]) {\n r[i][j] = 1\n newQueue.push([i, j])\n }\n }\n }\n })\n queue = newQueue\n }\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if(a[i][j] === 'G' && !r[i][j]) {\n wr('No')\n return\n }\n }\n }\n\n wr('Yes')\n\n function checkBorder(i, j) {\n if(i >= 0 && i < n && j >= 0 && j < m) {\n if(a[i][j] === 'G') {\n return false\n }\n if(a[i][j] !== 'B') a[i][j] = '#'\n }\n return true\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n6\n1 1\n.\n1 2\nG.\n2 2\n#B\nG.\n2 3\nG.#\nB#.\n3 3\n#B.\n#..\nGG.\n2 2\n#B\nB.\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nArray.fill = function(n, m, no = 0) {\n const a = new Array(n)\n for(let i = 0; i < n; i++) a[i] = new Array(m).fill(no)\n return a\n}\n\n\nfunction main() {\n let range = parseInt(readline());\n \n for(let r = 0;r {\n r[i][j] = 1;\n bfs(i, j - 1);\n bfs(i - 1, j);\n bfs(i, j + 1);\n bfs(i + 1, j);\n\n function bfs(i, j) {\n if(i >= 0 && j >= 0 && i < n && j < m) {\n if((a[i][j] === 'G' || a[i][j] === '.') && !r[i][j]) {\n r[i][j] = 1;\n newQuene.push([i, j]);\n }\n }\n }\n });\n quene = newQuene;\n }\n\n for(let i=0;i= 0 && i < n && j >= 0 && j < m) {\n if(a[i][j] === 'G') {\n return false\n }\n if(a[i][j] !== 'B') a[i][j] = '#'\n }\n return true\n }\n}\n\n"}], "negative_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tvar dy = [-1,0,1,0];\n\tvar dx = [0,-1,0,1];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar isG = false;\n\t\tvar isB = false;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = nextCharArray();\n\t\t\tif(list[j].indexOf(\"G\") != -1){\n\t\t\t\tisG = true;\n\t\t\t}\n\t\t\tif(list[j].indexOf(\"B\") != -1){\n\t\t\t\tisB = true;\n\t\t\t}\n\t\t}\n\t\tif(isG && isB){\n\t\t\t//\u4e21\u65b9\u3044\u308b\u3068\u304d\u304c\u30e4\u30d0\u30a4\n\t\t\t//\u3068\u308a\u3042\u3048\u305aB\u306e4\u65b9\u3092\u9632\u3044\u3067\u3057\u307e\u3046\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\tif(list[j][k] == \"B\"){\n\t\t\t\t\t\tfor(var l = 0; l < dy.length; l++){\n\t\t\t\t\t\t\tvar tonariY = j + dy[l];\n\t\t\t\t\t\t\tvar tonariX = k + dx[l];\n\t\t\t\t\t\t\tif(tonariY < N && tonariY >= 0 && tonariX < M && tonariX >= 0){\n\t\t\t\t\t\t\t\tif(list[tonariY][tonariX] != \"G\" && list[tonariY][tonariX] != \"B\"){\n\t\t\t\t\t\t\t\t\tlist[tonariY][tonariX] = \"#\";\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfunction bfs(startY, startX, isGood){\n\t\t\t\tvar access = new Array(N);\n\t\t\t\tfor(var l = 0; l < N; l++){\n\t\t\t\t\taccess[l] = new Array(M).fill(false);\n\t\t\t\t}\n\t\t\t\tvar queue = [[startY, startX]];\n\t\t\t\taccess[startY][startX] = true;\n\t\t\t\twhile(queue.length > 0){\n\t\t\t\t\tvar tmp = queue.shift();\n\t\t\t\t\tvar y = tmp[0];\n\t\t\t\t\tvar x = tmp[1];\n\t\t\t\t\tif(y == N - 1 && x == M - 1){\n\t\t\t\t\t\treturn isGood;\n\t\t\t\t\t}\n\t\t\t\t\tfor(var l = 0; l < dy.length; l++){\n\t\t\t\t\t\tvar nextY = y + dy[l];\n\t\t\t\t\t\tvar nextX = x + dx[l];\n\t\t\t\t\t\tif(nextY < N && nextY >= 0 && nextX < M && nextX >= 0){\n\t\t\t\t\t\t\tif(!access[nextY][nextX] && list[nextY][nextX] != \"#\"){\n\t\t\t\t\t\t\t\taccess[nextY][nextX] = true;\n\t\t\t\t\t\t\t\tqueue.push([nextY, nextX]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn !isGood;\n\t\t\t}\n\t\t\tvar isOK = true;\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\tif(list[j][k] == \"B\"){\n\t\t\t\t\t\tvar res = bfs(j,k,false);\n\t\t\t\t\t\tif(!res){\n\t\t\t\t\t\t\tisOK = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!isOK){\n\t\t\t\toutput[i] = \"No\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\t\tif(list[j][k] == \"G\"){\n\t\t\t\t\t\tvar res = bfs(j,k,true);\n\t\t\t\t\t\tif(!res){\n\t\t\t\t\t\t\tisOK = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!isOK){\n\t\t\t\toutput[i] = \"No\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\toutput[i] = \"Yes\";\n\t\t}else{\n\t\t\toutput[i] = \"Yes\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}], "src_uid": "a5e649f4d984a5c5365ca31436ad5883"} {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline()\r\n a = readline().split(' ').map(el => +el)\r\n\r\n ans = 'YES'\r\n for(i = 1; i< n; i++){\r\n if(a[i]%a[0] != 0){\r\n ans = 'NO'\r\n break\r\n }\r\n }\r\n\r\n print(ans)\r\n}\r\n", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var flag = true;\r\n for (var j = 1; j < caseLength; j++)\r\n {\r\n var value = parseInt(caseArray[j]) - parseInt(caseArray[j-1]);\r\n if (value % parseInt(caseArray[0]) !== 0)\r\n {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) print(\"YES\"); else print(\"NO\");\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(x=>parseInt(x));\r\n var ans = 'yes';\r\n for (var i=1; i {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\tvar n = readInt();\r\n\t\tvar a = readIntArr();\r\n\t\tvar z = a[0];\r\n\t\tvar ans = 'YES';\r\n\t\tfor (var i = 1; i < n; i++)\r\n\t\t\tif (a[i] % z !== 0)\r\n\t\t\t\tans = 'NO';\r\n\t\tallans.push(ans);\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": " process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '', currentLine = 0;\r\n process.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr, n);\r\n console.log(result);\r\n }\r\n }\r\n \r\n \r\n \r\n function myFunc(arr, n){\r\n for(let i = 1; i < n; i++){\r\n if(arr[i] % arr[0] != 0) return 'NO';\r\n }\r\n return 'YES';\r\n }"}, {"source_code": " process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '', currentLine = 0;\r\n process.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr, n);\r\n console.log(result);\r\n }\r\n }\r\n\r\n\r\n \r\n function myFunc(arr, n){\r\n for(let i = 1; i < n; i++){\r\n if(arr[i] % arr[0] != 0) return 'NO';\r\n }\r\n return 'YES';\r\n }"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const t = readline();\r\n\r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline(), 10);\r\n\r\n const a = readline()\r\n .split(' ')\r\n .map((num) => +num);\r\n\r\n // console.log(`=----------------testcase ${i + 1}----------------=`);\r\n // console.log('q', q);\r\n // console.log('a', a);\r\n\r\n const output = f(n, a);\r\n\r\n console.log(output);\r\n }\r\n}\r\n\r\nfunction f(n, a) {\r\n return a.slice(1).some(x => x % a[0]) ? 'NO' : 'YES' \r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let arr = readline().split(' ').map(Number);\r\n let yes = true;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i] % arr[0] !== 0) yes= false;\r\n }\r\n\r\n output(yes ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \").map(x=> parseInt(x));\r\n let res = true;\r\n for (let i = 0; i < n;++i) {\r\n if (a[i] % a[0] != 0) {\r\n res = false;\r\n }\r\n }\r\n if (res) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tfor(var i = N - 1; i > 0; i--){\r\n\t\t\tlist[i] %= list[i - 1];\r\n\t\t}\r\n\t\tvar ok = true;\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i] % list[0] != 0){\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] % a[0] !== 0) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let div = arr[0],\r\n ans = true;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] % div !== 0) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(x=>parseInt(x));\r\n var ans = 'yes';\r\n for (var i=1; i { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr, n);\r\n console.log(result);\r\n }\r\n }\r\n\r\n\r\n \r\n function myFunc(arr, n){\r\n for(let i = 1; i < n; i++){\r\n if(arr[i] < arr[i-1] || arr[i] % arr[0] != 0) return 'NO';\r\n }\r\n return 'YES';\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '', currentLine = 0;\r\n process.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\n process.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n\r\n function main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(arr, n);\r\n console.log(result);\r\n }\r\n }\r\n\r\n\r\n \r\n function myFunc(arr, n){\r\n for(let i = 1; i < n; i++){\r\n if(arr[i] < arr[i-1]) return 'NO';\r\n }\r\n return 'YES';\r\n return 'YES';\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\nfunction main() {\r\n const t = readline();\r\n \r\n for (let i = 0; i < t; i++) {\r\n const n = parseInt(readline(), 10);\r\n \r\n const a = readline().split(' ').map(num => +num);\r\n \r\n // console.log(`=----------------testcase ${i + 1}----------------=`);\r\n // console.log('q', q);\r\n // console.log('a', a);\r\n \r\n const output = f(n, a);\r\n \r\n console.log(output);\r\n }\r\n}\r\n \r\nfunction f(n, a) {\r\n\r\n for (let i = 1; i < n; i++) {\r\n if(a[i] < a[i-1]) return 'NO'\r\n }\r\n \r\n return 'YES';\r\n}"}], "src_uid": "1c597da89880e87ffe791dd6b9fb2ac7"} {"source_code": "let dataitr;\r\nlet stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", (input) => {\r\n stdin_input += input;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n dataitr = stdin_input.split(\"\\n\").values();\r\n main();\r\n});\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(\" \");\r\nconst rna = () => ra().map((x) => Number(x));\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let T = rn();\r\n while (T--) {\r\n const n = rn();\r\n const a = rna();\r\n\r\n let ans = -1;\r\n const types = {};\r\n let minBetween = n + 1;\r\n for (let i = 0; i < n; i++) {\r\n if (types[`${a[i]}`] === undefined) {\r\n types[`${a[i]}`] = i;\r\n continue;\r\n }\r\n\r\n const last = types[`${a[i]}`];\r\n const between = i - last;\r\n\r\n if (between === 1) {\r\n ans = n - 1;\r\n break;\r\n }\r\n\r\n types[`${a[i]}`] = i;\r\n\r\n if (minBetween > between) {\r\n minBetween = between;\r\n }\r\n }\r\n\r\n if (ans === -1) {\r\n ans = n - minBetween;\r\n }\r\n\r\n console.log(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let _inputLines;\r\nlet _lineNumber = 0;\r\nlet inputReader = _inputReader ();\r\n\r\nfunction _main() {\r\n\t\r\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\r\n\t\treturn string.trim();\r\n\t});;\r\n\t\r\n\tlet t = inputReader.readNumber();\r\n\t\r\n\tfunction solve() {\r\n\t let n = inputReader.readNumber();\r\n\t let v = inputReader.readNumberArray();\r\n\t let m = new Map();\r\n\t let ans = -1;\r\n\t for(let i = 0; i < n; i++) {\r\n\t if(m.has(v[i])) {\r\n\t ans = Math.max(ans, m.get(v[i]) + n - i);\r\n\t }\r\n\t m.set(v[i], i);\r\n\t }\r\n\t console.log(ans); \r\n\t}\r\n\t\r\n\twhile (t--) {\r\n\t solve();\r\n\t}\r\n\t\r\n\t//cp-convert -s CP.js -d CP-CF.js\r\n\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\tfunction readNumberArray(){\r\n\t\treturn _inputLines[_lineNumber++].split(' ').map(val => Number(val));\r\n\t}\r\n\t\t\r\n\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t\treadNumberArray,\r\n\t}\r\n}"}, {"source_code": "const solve = arr=>{\r\n let obj = {};\r\n let max = 0;\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n // const min = {}\n // const max = {}\n const p = {}\n arr.forEach((x, i) => {\n p[x] = p[x] || []\n p[x].push(i)\n // min[x] = (x in min) ? Math.min(min[x], i) : i\n // max[x] = (x in max) ? Math.max(max[x], i) : i\n })\n // console.log(min, max)\n let ans = -1\n for (let x in p) {\n // const a = min[x]\n // const b = max[x]\n if (p[x].length < 2) continue\n // if (a !== b) {\n // const prev = Math.min(a, b)\n // const after = Math.min(n - 1 - a, n - 1 - b)\n // ans = Math.max(ans, prev + 1 + after)\n // }\n for (let i = 1; i < p[x].length; i++) {\n const a = p[x][i - 1]\n const b = p[x][i]\n ans = Math.max(ans, a + 1 + (n - 1 - b))\n }\n }\n return ans\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst mp = new Map();\r\n\t\tlet mnd = INF;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (mp.has(a[i])) {\r\n\t\t\t\tmnd = Math.min(mnd, i - mp.get(a[i]));\r\n\t\t\t}\r\n\t\t\tmp.set(a[i], i);\r\n\t\t}\r\n\r\n\t\tconsole.log(mnd < INF ? n - mnd : -1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const solve = arr=>{\r\n let obj = {};\r\n let max = 0;\r\n for(let i=0;i=arr.length){\r\n max = Math.max(max,t);\r\n }\r\n obj[arr[i]] = i;\r\n }\r\n else obj[arr[i]] = i;\r\n }\r\n if(max===0) console.log(-1);\r\n else console.log(max);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = arr=>{\r\n let obj = {};\r\n let max = 0;\r\n for(let i=0;i=arr.length){\r\n max = Math.max(max,t);\r\n break;\r\n }\r\n }\r\n else obj[arr[i]] = i;\r\n }\r\n if(max===0) console.log(-1);\r\n else console.log(max);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = arr=>{\r\n let obj = {};\r\n for(let i=0;ia-b);\r\n let max = 0;\r\n for(let i=0;i0;j--){\r\n let k = arr.length-(t[j]-t[j-1]);\r\n if(k*2>=arr.length){\r\n max = Math.max(max,k);\r\n break;\r\n }\r\n }\r\n if(t.length===arr.length) break;\r\n }\r\n }\r\n if(max===0) console.log(-1);\r\n else console.log(max);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(arr);\r\n }\r\n}\r\nmain();"}], "src_uid": "7ac5f084c403bd26802e1b941105d34b"} {"source_code": "function solve(input) {\r\n const len = parseInt(input)\r\n const out = 3;\r\n const list = Array.from({length: len}, (_, i) => i + 1);\r\n // 2 3 4 ... n 1\r\n console.log([...Array.from({length: len - 1}, (_, i) => i + 2), 1].join(' '))\r\n // 3 4 5 ... n 1 2\r\n console.log([...Array.from({length: len - 2}, (_, i) => i + 3), 1, 2].join(' '))\r\n // mundur\r\n console.log([...Array.from({length: len}, (_, i) => len - i)].join(' '))\r\n if (len > 3) {\r\n let baseList = Array.from({length: len}, (_, i) => len - i);\r\n for (let i = 3; i < len; i++) {\r\n const awal = baseList[0]\r\n baseList = [...baseList, awal].slice(1, len + 1)\r\n console.log(baseList.join(' '))\r\n }\r\n }\r\n}\r\n\r\n// =========== DEFAULT FORMAT ==============\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\n\r\nlet i = 1;\r\nlet t = 0;\r\nreadline.on('line', line => {\r\n if (i == 1) {\r\n // number of test case\r\n t = parseInt(line) \r\n i++;\r\n } else {\r\n solve(line)\r\n if (i <= t) i++\r\n else readline.close()\r\n }\r\n});\r\n\r\n// =========== DEFAULT FORMAT END ==============", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n for(i = 1; i <= n; i++){\n var a = lines[i];\n for(j = 1; j <= a; j++){\n var ans = '';\n ans += j;\n for(k = a; k >= 1; k--){\n if(j != k){\n ans += ' ' + k;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "'use strict';\n/* ================== */\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readline = () => inputString[currentLine++];\nconst readline_arr = () => readline().split('');\nconst readline_num_arr = () => readline().split(' ').map((n) => parseInt(n, 10));\nconst print = (...txt) => process.stdout.write(`${txt}\\n`)\n/* ================== */\n\nfunction main() {\n let t = parseInt(readline(), 10);\n while (t--) {\n solve();\n }\n}\n\nconst checkPermute = (p) => {\n for (let i = 2; i < p.length; i++) {\n if (p[i - 2] + p[i - 1] === p[i]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction solve() {\n const n = parseInt(readline());\n for (let i = 1; i <= n; i++) {\n const res = [];\n res.push(i)\n\n for (let j = n; j >= 1; j--) {\n if (j !== i) res.push(j);\n }\n\n print(res.join(' '));\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n if (n === 3) return `1 3 2\\n2 3 1\\n3 1 2`;\r\n const s = Array.from({\r\n length: n\r\n }, (_, i) => n - i);\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(n));\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n res[i][j] = s[(j + i) % n];\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n] = readline().split(' ').map(Number);\r\n\r\n let perm = [];\r\n for (let i = 0; i < n; i++) {\r\n perm.push(i + 1);\r\n }\r\n\r\n for (let i = 1; i <= n; i++) {\r\n let res = [i];\r\n let m = perm.filter( x => x !== i)\r\n m.sort((a, b) => b - a);\r\n output([...res, ...m].join(' '));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const ans = []\n for (let i = 0; i < n; i++) {\n const now = [i + 1]\n for (let j = n; j >= 1; j--) {\n if (j === i + 1) continue\n now.push(j)\n }\n ans[i] = now.join(' ')\n }\n return ans.join('\\n')\n}\n"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n \r\n for (var j = 1; j <= n; ++j) {\r\n write(j);\r\n for (var k = n; k > 0; --k) {\r\n if (j != k) {\r\n write(' ',k);\r\n }\r\n }\r\n print();\r\n }\r\n}"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n for(var i = 1; i <= n; i++){\n var k = lines[i];\n var ans = '';\n for(j = 0; j < k; j++){\n ans += 1 + ' '; \n }\n console.log(ans); \n }\n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var r = lines[j].split(' ').map(Number);\n var a = r[0];\n var b = r[1];\n var k = r[2];\n var d = 0;\n var answer = 0;\n if(k % 2 == 1){\n d = Math.floor(k / 2);\n }else{\n d = k / 2;\n }\n answer = (d * a) - ((k - d) * b);\n console.log(answer);\n }\n}); "}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n const s = Array.from({\r\n length: n\r\n }, (_, i) => n - i);\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(n));\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < n; j++) {\r\n res[i][j] = s[(j + i) % n];\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n res[i] = solve(n);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "85f0621e6cd7fa233cdee8269310f141"} {"source_code": "print(function(a, b){\n\tvar i, l, ans=-1e20, t=-1;\n\n\tif(b===0){\n\t\tans=[];\n\t\tfor(i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-2;\n\tvar ax=a-ai;\n\tvar sb1=repeat(bx+1, 'x');\n\tvar sb2=repeat(bx, 'x');\n\n\tvar ans2='';\n\tfor(i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}\n\t\t// else{\n\t\t// \tbreak;\n\t\t// }\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-2;\n\tvar ax=a-ai;\n\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb1=repeat(bx+1, 'x');\n\tvar sb2=repeat(bx, 'x');\n\tfor(var i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-2;\n\tvar ax=a-ai;\n\tvar sb1=repeat(bx+1, 'x');\n\tvar sb2=repeat(bx, 'x');\n\n\tvar ans2='';\n\tfor(i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\t//break;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/(t+1));\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var j=0; jans){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-1;\n\tvar ax=a-ai;\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\t//break;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/(t+1));\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var j=0; jans){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-2;\n\tvar ax=a-ai;\n\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb1=repeat(bx+1, 'x');\n\tvar sb2=repeat(bx, 'x');\n\tfor(var i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/(t+1));\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var j=0; jans){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t<=2 ? 0 : t-2;\n\tvar ax=a-ai;\n\tvar sb1=repeat(bx+1, 'x');\n\tvar sb2=repeat(bx, 'x');\n\n\tvar ans2='';\n\tfor(i=0; ians){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/(t+1));\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var j=0; jans){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/(t+1));\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var j=0; jans){\n\t\t\tans=x;\n\t\t\tt=i;\n\t\t}else{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tvar bx=Math.floor(b/t);\n\tvar bi=b%t;\n\tvar ai=t-1;\n\tvar ax=a-ai;\n\tvar aa=[];\n\tvar bb=[];\n\tvar sb=[];\n\tfor(var i=0; i1){\r\n r=r<<1;\r\n n=n>>1;\r\n }\r\n print(r-1);\r\n}\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar tmp = \"\";\r\n\t\twhile(N > 0){\r\n\t\t\ttmp = N % 2 + tmp;\r\n\t\t\tN = Math.floor(N / 2);\r\n\t\t}\r\n\t\tvar output = Math.pow(2, tmp.length - 1) - 1;\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var answer = 0;\n var last = 0;\n while(k > answer){\n last = answer;\n answer = (2 * answer) + 1;\n }\n console.log(last);\n }\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n l=1;\r\n for(var i=0;i> j)& 1 === 1) {\r\n last = j\r\n }\r\n }\r\n print((1< 0) {\n n = n & (n - 1);\n }\n\n print(n - 1);\n}\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n\r\nlet d = [1, 0];\r\nconst solve = () => {\r\n for (let i = 2; 2 ** i <= 536870912; i++) {\r\n d.unshift(2 ** i - 1);\r\n }\r\n // pr(d);\r\n};\r\n\r\nconst go = (x) => {\r\n let n = d.length;\r\n for (let i = 0; i < n; i++) {\r\n if (x > d[i]) return pr(d[i]);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n solve();\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n go(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let list = [];\n for (let i = 0; i < t; i++){\n list.push(nl.num());\n } \n let bitSize = (n) => {\n let cnt = 0;\n while(n > 1) {\n n >>= 1;\n cnt++; \n }\n return cnt;\n }\n let bitMax = (n) => {\n let max = 1;\n for(let i = 0; i < n; i++){\n max <<= 1;\n }\n return max - 1;\n }\n \n\tconsole.log(list.map(bitSize).map(bitMax).join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let bitSize = (n) => {\n let cnt = 0;\n while(n > 1) {\n n >>= 1;\n cnt++; \n }\n return cnt;\n }\n let bitMax = (n) => {\n let max = 1;\n for(let i = 0; i < n; i++){\n max <<= 1;\n }\n return max - 1;\n }\n let ans = [];\n for(let i = 0; i < t; i++) {\n let n = nl.num();\n ans.push(bitMax(bitSize(n)));\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = parseInt(readLine()), last = 0;\r\n for (let i = 0; i < 30; ++i) {\r\n if (((n >> i) & 1) == 1) {\r\n last = i;\r\n }\r\n }\r\n return (1 << last) - 1;\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var answer = 0;\n var last = 0;\n while(k > answer){\n last = answer;\n answer = (2 * answer) + 1;\n }\n console.log(last);\n }\n});"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(n));\n }\n});\n\nfunction solve(n) {\n\tconst base = Math.floor(Math.log2(n))\n\treturn Math.pow(2, base) - 1\t\n}\n"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n print(Math.pow(2,parseInt(Math.log(parseInt(readLine())) / Math.log(2), 10)) - 1) \r\n \r\n});\r\n\r\n\r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n) => {\r\n if (n == 1) return pr(0);\r\n pr(n & 1 ? n - 2 : n - 1)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n) => {\r\n pr(n & 1 ? n - 2 : n - 1)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let num = temp = parseInt(readLine());\r\n for (let i = 1; i <= temp; i++) {\r\n num = num & (num - i);\r\n if (num === 0) {\r\n return temp-i;\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n //console.log(2 + ' ' + (k - 1));\n }\n console.log(1 + \"\\n\" + 3 + \"\\n\" + 15)\n});"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log('Case #%d: %s', i + 1, solve(n));\n }\n});\n\nfunction solve(n) {\n\tconst base = Math.floor(Math.log2(n))\n\treturn Math.pow(2, base) - 1\t\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar tmp = \"\";\r\n\t\twhile(N > 0){\r\n\t\t\ttmp = N % 2 + tmp;\r\n\t\t\tN = Math.floor(N / 2);\r\n\t\t}\r\n\t\t//myerr(tmp);\r\n\t\tvar ok = \"\";\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < tmp.length; i++){\r\n\t\t\tif(!isOK){\r\n\t\t\t\tok += \"1\";\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif(tmp[i] == \"1\"){\r\n\t\t\t\tok += \"0\";\r\n\t\t\t}else{\r\n\t\t\t\tok += \"1\";\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = parseInt(ok, 2);\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var tc=readline();\r\nwhile(tc--)\r\n{\r\n var n=readline();n=Number(n);\r\n var ans;\r\n for(var i=0;i<32;i++)\r\n {\r\n var u=Math.pow(2,i);\r\n if(u-1<=n)\r\n ans=u-1;\r\n else break;\r\n }\r\n if(n==1) print(0);\r\n else print(ans);\r\n}\r\n"}, {"source_code": "var tc=readline();\r\nwhile(tc--)\r\n{\r\n var n=readline();n=Number(n);\r\n var ans;\r\n for(var i=0;i<32;i++)\r\n {\r\n var u=Math.pow(2,i);\r\n if(u-1<=n)\r\n ans=u-1;\r\n else break;\r\n }\r\n print(ans);\r\n}"}, {"source_code": "var tc=readline();\r\nwhile(tc--)\r\n{\r\n var n=readline();\r\n var a=n;var k=0;\r\n while(n)\r\n{\r\n n=(n&(a-1));\r\n k++;\r\n a--;\r\n if(n==0)\r\n {\r\n print(k);\r\n break;\r\n }\r\n \r\n\r\n}\r\n}"}], "src_uid": "9b4a8bc76d634935f6a1438e8a93a781"} {"source_code": "function ansb(n,k,str){\n\n const obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.keys(obj).map(function(key){ return obj[key]});\n var max = Math.max(...arr);\n print(max === -Infinity ? 0 : max);\n}\n\nvar line = readline().split(' ')\nvar str = readline()\nansb(parseInt(line[0]),parseInt(line[1]),str);\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet x = 0\nlet k = 0\nlet n = 0\nrl.on('line', (input) => {\n if (l === 0) {\n let arr = input.split(\" \").map(x => parseInt(x))\n x = arr[0]\n k = arr[1]\n } else {\n rl.close();\n let hm = {}\n let arr = input.split(\"\")\n let c = 0\n for (let i = 0; i < arr.length; i++) {\n let cnt = 1\n let st = i\n while (i + 1 < arr.length && arr[i] === arr[i + 1] && cnt < k) {\n cnt++\n i++\n }\n if (hm[arr[i]] && cnt === k) {\n hm[arr[i]]++\n } else if (cnt === k) {\n hm[arr[i]] = 1\n }\n }\n\n let mn = 0\n for (let e in hm) {\n if (mn < hm[e]) {\n mn = hm[e]\n }\n }\n console.log(mn)\n return\n }\n l++\n})\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet x = 0\nlet k = 0\nlet n = 0\nrl.on('line', (input) => {\n if (l === 0) {\n let arr = input.split(\" \").map(x => parseInt(x))\n x = arr[0]\n k = arr[1]\n } else {\n rl.close();\n let hm = {}\n let arr = input.split(\"\")\n let c = 0\n for (let i = 0; i < arr.length - 1; i++) {\n let cnt = 1\n let st = i\n while (arr[i] === arr[i + 1] && cnt < k) {\n cnt++\n i++\n }\n if (hm[arr[i]] && cnt === k) {\n hm[arr[i]]++\n } else if (cnt === k) {\n hm[arr[i]] = 1\n }\n }\n\n let mn = 0\n for (let e in hm) {\n if (mn < hm[e]) {\n mn = hm[e]\n }\n }\n if (mn === 0 && k === 1) {\n console.log(1)\n return\n }\n console.log(mn)\n return\n }\n l++\n})\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet x = 0\nlet k = 0\nlet n = 0\nrl.on('line', (input) => {\n if (l === 0) {\n let arr = input.split(\" \").map(x => parseInt(x))\n x = arr[0]\n k = arr[1]\n } else {\n rl.close();\n let hm = {}\n let arr = input.split(\"\")\n let c = 0\n for (let i = 0; i < arr.length - 1; i++) {\n let cnt = 1\n let st = i\n while (arr[i] === arr[i + 1] && cnt < k) {\n cnt++\n i++\n }\n if (hm[arr[i]] && cnt == k) {\n hm[arr[i]]++\n } else if (cnt === k) {\n hm[arr[i]] = 1\n }\n }\n let mn = 0\n for (let e in hm) {\n if (mn < hm[e]) {\n mn = hm[e]\n }\n }\n console.log(mn)\n return\n }\n l++\n})\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar input = readline().split(',');\nprint(input[1])\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar input = readline().split(' ');\nprint(input)\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar input = readline().split('/n');\nprint(input[1])\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar line = readline().split(' ')\nprint(parseInt(line[0]) + parseInt(line[1]))\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = []\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var max = Math.max(...obj);\n print(max === -Infinity ? 0 : max);\n}\n\nvar line = readline().split(' ')\nvar str = readline()\nansb(parseInt(line[0]),parseInt(line[1]),str);\n"}, {"source_code": "function ansb(n,k,str){\n\n const obj = []\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var max = Math.max(...obj);\n print(max === -Infinity ? 0 : max);\n}\n\nvar line = readline().split(' ')\nvar str = readline()\nansb(parseInt(line[0]),parseInt(line[1]),str);\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar input = readline().split(',');\nprint(input[0])\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar line = readline().split(' ')\nvar line2 = readline()\nprint(parseInt(line[0]) + parseInt(line[1]))\nprint(line2)\n"}, {"source_code": "function ansb(n,k,str){\n\n var obj = {}\n\n for(var i = 0 ; i < str.length ; i++){\n\n var cnt = 1;\n while(str[i+1] === str[i] && i+1 !== str.length){\n cnt++;\n i++\n // console.log(\"here\")\n // console.log(cnt)\n }\n if(cnt >= k)obj[str[i]] ? obj[str[i]] += Math.floor(cnt/k) : obj[str[i]] = Math.floor(cnt/k);\n }\n var arr = Object.values(obj);\n var max = Math.max(...arr);\n console.log(max === -Infinity ? 0 : max);\n}\n\nvar input = readline().split('/n');\nprint(input)\n"}], "src_uid": "6c71c828553e43c699237211005873e5"} {"source_code": "\n\"use strict\";\nlet input = [];\nconst readline=require('readline');\nconst RL=readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nRL.on('line', (line)=>{\n input.push(line.trim());\n});\nRL.on('close', ()=>{\n const n=parseInt(input[0]);\n let answer=0;\n for(let i=1; i<=n; ++i){\n let cnt=0;\n const arr=input[i].split(' ');\n arr.map((ch)=>{\n let digit=parseInt(ch);\n if(digit===1){\n cnt++;\n }\n });\n if(cnt>=2){\n answer++;\n }\n }\n\n console.log(answer);\n});\n", "positive_code": [{"source_code": "var count = parseInt(readline()),\ncurrent = [], currentMas, sum = 0, answer = 0;\n\nfor(var i = 0; i < count; i++) {\n current[i] = readline().split(\" \");\n}\n\nfor(var i = 0; i < count; i++) {\n currentMas = current[i];\n sum = 0;\n\n for(var j = 0; j < 3; j++) {\n sum+=parseInt(currentMas[j]);\n }\n\n if(sum >= 2) {\n answer+=1;\n }\n} \n\nwrite(answer);"}, {"source_code": "const rows = parseToInt(readline())\n\nvar arr = [];\n\nfor(var i=0;iNumber.parseInt(x))\n}\n\nfunction compute(arr) {\n\n\n\n var sum = 0;\n for(var i=0;i 1) {\n sum++;\n }\n\n\n }\n\n print(sum)\n\n\n}\n\n"}, {"source_code": "const main = () => {\n const N = Number(readline());\n\n var result = 0;\n\n for (var i = 0; i < N; i++) {\n var confidenceLevel = 0;\n\n readline()\n .split(\" \")\n .forEach((opinion) => {\n if (opinion === \"1\") {\n confidenceLevel++;\n }\n });\n\n if (confidenceLevel >= 2) {\n result++;\n }\n }\n\n print(result);\n};\n\nmain();"}, {"source_code": "var input;\nvar count ;\nvar problem = 0;\nvar n = parseInt(readline());\n\nfor(var i=0 ; iparseInt(x));\n count = 0;\n for(var j=0 ; j<5 ; j++){\n if(input[j]=='1'){\n count++;\n }\n }\n if(count>1)\n problem++;\n}\nprint(problem);"}, {"source_code": "var input;\nvar count ;\nvar problem = 0;\nvar n = parseInt(readline());\n\nfor(var i=0 ; i1)\n problem++;\n}\nprint(problem);"}, {"source_code": "var lines = Number(readline()); \nvar outp = 0;\nfor (var i = 0; i < lines; i++) {\n var str = readline();\n var count = Number(str.charAt(0)) + Number(str.charAt(2)) + Number(str.charAt(4));\n if (count > 1) outp ++;\n}\nprint(outp);"}, {"source_code": "n = readline();\nvar tedad = 0;\nwhile(n--)\n{\n \ts=readline().replace(new RegExp('0' , 'g'), '') \n\t\n\tif(s.length > 3){tedad++}\n\t\n}\nprint(tedad)"}, {"source_code": "y = readline().split(\" \").map(each=>Number(each))\n\ncounter = 0 \nn = 0 \n\nwhile (counter < y) { \n x = readline() \n if (\n x == '1 1 0'||\n x == '1 1 1'||\n x == '0 1 1'||\n x == '1 0 1'\n ) \n { n = n + 1 } \n counter = counter + 1 }\n\nprint ( n )"}, {"source_code": "var n = readline()\nvar out = 0\nfor (var i = 0; i < n; i++) {if (readline().split(' ').map(x => Number(x)).reduce((a, b) => a + b) >=2) out++}\nprint(out)"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nfunction enterNumberOfTasks() {\n rl.question(\"\", (num) => {\n const numberOfTasks = parseInt(num);\n enterLine(numberOfTasks);\n });\n}\n\n/**\n *\n * @param {number} numberOfTasks\n */\nfunction enterLine(numberOfTasks) {\n const lines = [];\n rl.on(\"line\", (line) => {\n lines.push(line);\n\n if (lines.length === numberOfTasks) {\n getAnswer(lines);\n rl.close();\n return;\n }\n });\n}\n\n/**\n *\n * @param {string[]} lines\n */\nfunction getAnswer(lines) {\n let numberOfTasks = 0;\n lines.forEach((line) => {\n const numbers = line.split(\" \").map((numStr) => parseInt(numStr));\n const sum = numbers.reduce((acc, cur) => acc + cur, 0);\n\n if (sum > 1) {\n numberOfTasks++;\n }\n });\n\n console.log(numberOfTasks);\n}\n\nenterNumberOfTasks();\n"}, {"source_code": "var readline = require (\"readline\");\nrl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar expect = 'n';\nvar s= 0;\nrl.on(\"line\", function(line){\n if (expect ==\"n\"){\n n = parseInt(line);\n case_counter = 1;\n expect = 'solution';\n } else if (expect==\"solution\"){\n solutions = line.split(\" \");\n var r = 0;\n \n for(var i = 0; i<3; i++){\n \n if(solutions[i] == '1'){\n r++;\n }\n }\n if (r > 1){\n s++;\n }\n ++case_counter === n +1 ? rl.close() : 0;\n expect=\"solution\";\n }\n}).on('close', function(){\n console.log(s);\n process.exit(0);\n\n});"}, {"source_code": ";(function () {\n var n = readline(), r = 0;\n for (var i = 0; i < n; i++) \n r += readline().split(' ').filter(function(v){ return v == 1;}).length > 1;\n print(r); \n \n}).call(this);"}, {"source_code": "'use strict';\n\n// let inpArr = `\n// 3\n// 1 1 0\n// 1 1 1\n// 1 0 0\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nlet n = Number(readline()), count = 0;\nfor (var i = 0; i < n; i++) {\n if (readline().split(' ').map(Number).reduce((a,b)=>a+b) >= 2) {\n count++\n }\n}\nprint(count);\n"}, {"source_code": "var quantity = parseInt(readline()),\n arr = [],\n count = 0;\n\nfor (var i = 0; i < quantity; i++) {\n var s = 0;\n arr[i] = readline().split(' ').map(x => parseInt(x) && s++);\n s > 1 && count++;\n}\n\nprint(count);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\nvar a, b, c, n, r, g;\nr = 0;\ng = 0;\nn = readline();\nwhile ((n-- > 0)) {\n var vavl = readline().split(\" \").map(x => parseInt(x));\n a = vavl[0];\n b = vavl[1];\n c = vavl[2];\n r = (a + b + c);\n if(r >= 2)\n g += 1;\n}\nconsole.log(g);\n}\n "}, {"source_code": "var c = +readline()\nvar g = new Map([[0, 0], [1, 0], [2, 0], [3, 1], [4, 0], [5, 1], [6, 1], [7, 1]])\nvar s = 0;\nfor (var i = 0; i < c; ++i) {\n var p = parseInt(readline().replace(/ /g, ''),2)\n s += g.get(p)\n}\nprint(s)\n"}, {"source_code": "// Generated by CoffeeScript 2.5.1\nvar lines, mainAux, nprobs, print, readline, rl, rli, sum, write;\n\nrl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nprint = console.log;\n\nwrite = function(...args) {\n return process.stdout.write(args.join(' '));\n};\n\nlines = [];\n\nrl.on('line', function(line) {\n return lines.push(line);\n});\n\nrl.on('close', main);\n\nrli = 0;\n\nreadline = function() {\n return lines[rli++];\n};\n\nsum = function(items) {\n return items.reduce((function(a, b) {\n return a + b;\n }), 0);\n};\n\nnprobs = function(n, ps) {\n return ps.filter(function(p) {\n return sum(p) > 1;\n }).length;\n};\n\nmainAux = function() {\n var count, i, items, j, ref;\n count = parseInt(readline());\n items = [];\n for (i = j = 0, ref = count; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {\n items.push(readline().split(' ').map(function(i) {\n return parseInt(i);\n }));\n }\n return print(nprobs(count, items));\n};\n\n\n function main() {\n return mainAux();\n }\n;\n\n//# sourceMappingURL=testsums.js.map\n"}, {"source_code": "//231A\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet i = 0\nlet problems;\nlet numberOfProblems = 0;\nrl.on('line', (input) => {\ni++\n if(i==1) {\n problems = parseInt(input)\n } else if (i - 1 <= problems) {\n \n let thingyarray = input.split(\" \")\n let formatarray = [];\n thingyarray.forEach(function(number) {\n let dieh = parseInt(number)\n formatarray.push(dieh)\n })\n \n let answer = formatarray[0] + formatarray[1] + formatarray[2]\n \n if (answer > 1) {\n numberOfProblems++\n }\n if (i > problems) {\n \n rl.close()\n console.log(numberOfProblems)\n }\n \n }\n \n});\n"}, {"source_code": "function getSum(nums){\n\tvar total = 0;\n\tfor(var i = 0; i < nums.length; i++)\n\t\ttotal += Number(nums[i]);\n\treturn total;\n}\n\nvar n = Number(readline());\n\nvar ans = 0;\nfor(var i = 0; i < n; i++){\n\tvar votes = readline().split(\" \");\n\tvar sumOfVotes = getSum(votes);\n\tif(sumOfVotes > 1) ans++;\n}\n\nprint(ans);"}, {"source_code": "function getSum(nums){\n\tvar total = 0;\n\tfor(var i = 0; i < nums.length; i++)\n\t\ttotal += parseInt(nums[i]);\n\treturn total;\n}\n\nvar n = readline();\n\nvar ans = 0;\nfor(var i = 0; i < n; i++){\n\tvar votes = readline().split(\" \");\n\tvar sumOfVotes = getSum(votes);\n\tif(sumOfVotes > 1) ans++;\n}\n\nprint(ans);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n let result = 0;\n while (t--) {\n let count = 0;\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n a === 1 && count++;\n b === 1 && count++;\n c === 1 && count++;\n count >= 2 && result++;\n }\n console.log(result);\n}\n"}, {"source_code": "function getSum(nums){\n\tvar total = 0;\n\tfor(var i = 0; i < nums.length; i++)\n\t\ttotal += parseInt(nums[i]);\n\treturn total;\n}\n\nvar n = readline().split(\" \");\n\nvar ans = 0;\nfor(var i = 0; i < n; i++){\n\tvar votes = readline().split(\" \");\n\tvar sumOfVotes = getSum(votes);\n\tif(sumOfVotes > 1) ans++;\n}\n\nprint(ans);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\nprint (resolve(parseInt(problems)));"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n var output = 0;\n for(var i = 0; i < N; i++){\n var list = nextIntArray();\n var count = 0;\n for(var j = 0; j < list.length; j++){\n count += list[j];\n }\n if(count >= 2){\n output++;\n }\n }\n myout(output);\n}\n"}, {"source_code": "var n = Number(readline());\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n\tif (readline().split(\" \").map(x => Number(x)).reduce((a, b) => a + b) > 1) count++;\n}\nprint(count);"}, {"source_code": "let readline = require('readline');\nlet rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nlet input = [];\nrl.on('line', function(line) {\n\tinput.push(line);\n\tif (input.length === input[0] * 1 + 1) {\n\t\t//n m a\n\t\tinput.shift();\n\t\tteam(input);\n\t\trl.close();\n\t}\n});\n\nlet team = (array) => {\n\tconst reducer = (accumulator, currentValue) => 1 * accumulator + 1 * currentValue;\n\tlet result = array\n\t\t.map((el) => {\n\t\t\treturn el.split(' ').reduce(reducer);\n\t\t})\n\t\t.filter((el) => {\n\t\t\treturn el >= 2;\n\t\t});\n\tconsole.log(result.length);\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = readline().split(' ').map(x => parseInt(x));\n let result = 0;\n for (let i = 0; i < n; i++) {\n const vote = readline().split(' ').map(x => parseInt(x))\n .reduce((a, b) => a + b, 0);\n if (vote > 1) {\n result++;\n }\n }\n\n // output\n print(result);\n}\n\n"}, {"source_code": "var numberOfProblems = readline();\nvar result = 0;\n\nfor(var i = 0; i < numberOfProblems; i++){\n var decisions = readline().split(' ');\n var numberOfCanSolve = 0;\n \n for(var j = 0; j < decisions.length; j++){\n if(parseInt(decisions[j]) === 1){\n numberOfCanSolve++;\n }\n \n \n }\n if(numberOfCanSolve > 1){\n result++;\n }\n \n\n}\n\nprint(result);"}, {"source_code": "//Team\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let c = 0;\n for(let i = 1; i <= +lines[0]; i++) {\n \tc += Math.floor(lines[i].split(' ').reduce((a, b) => (+a) + (+b)) / 2);\n }\n\n process.stdout.write(c + \"\");\n\n return;\n});"}, {"source_code": "var problemas = readline();\nvar datos = new Array();\nvar contador = 0;\nvar linea = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tlinea = readline().split(' ').map(Number);\n\tif (linea[0]+linea[1]+linea[2] >= 2){\n\t\tcontador++;\n\t}\n}\n\nprint(contador);\n"}, {"source_code": "'use strict';\n\nconst count = readline();\nlet answer = 0;\n\nfor (let i=0; i= 2){\n answer += 1;\n }\n}\n\nprint(answer);\n"}, {"source_code": "readline();\nvar ans = 0;\nfor (var s; s = readline(); ) {\n var count = s.split( ' ' ).reduce( function(last, it) { \n return (it - '') + last; \n }, 0 );\n count > 1 && ans++;\n}\n\nprint( ans );"}, {"source_code": "'use strict'\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar inp, nb, sum = 0, tt = 0, count = 0, sum = 0;\nrl.question('', (nb) => {\n rl.on('line', (inp) => {\n sum = Number(inp[0]) + Number(inp[2]) + Number(inp[4]);\n if (sum >= 2){\n tt++;\n }\n count++;\n if (count == nb) {\n console.log(tt);\n rl.close();\n }\n });\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\nfunction processData(data) {\n const input = data.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n let res = 0\n\nfor (let i=1;i<=parseInt(input[0]);i++) {\n if ((input[i].split(\"1\").length-1) > 1) {\n res++;\n }\n }\n console.log(res);\n\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar count = 0;\nvar tasksCount;\nvar linesToSolve = [];\n\nrl.on('line', line => {\n if (count === 0) {\n tasksCount = parseInt(line);\n count++;\n return;\n }\n\n linesToSolve.push(line);\n count++;\n\n if (count === tasksCount + 1) {\n rl.close();\n return;\n }\n});\n\nrl.on('close', () => {\n var result = 0;\n\n linesToSolve.forEach(item => {\n result += solveLine(item);\n });\n\n console.log(result);\n rl.close();\n});\n\nfunction solveLine(line) {\n return (line.match(/1/g) || []).length >= 2 ? 1 : 0;\n}"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let problems= readline();\n let count =0;\n for (let i=0;i= 2){\n count++\n }\n }\n console.log(count);\n\n return ; \n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet data = [];\nrl.on('line', (input) => {\n data.push(input);\n});\n\nrl.on('close', () => {\n solve(data);\n});\n\nfunction solve(data) {\n\n const reducer = (acc, curr) => {\n if (curr == \"1\") {\n return acc + 1;\n } else {\n return acc;\n };\n }\n\n total = 0;\n for (let i = 1; i < data.length; i++) {\n n = data[i].split(\" \").reduce(reducer, 0);\n if (n >= 2) total++;\n }\n console.log(total);\n\n}\n"}, {"source_code": "var prob = 0;\nvar t = readline();\nwhile(t--){\n var x = readline().split(' ');\n \n if((x[0]==1 && x[1]==1) || (x[0] == 1 && x[2]==1) || (x[1]==1 && x[2]==1)){\n prob = prob + 1;\n }\n}\n \nprint(prob);"}, {"source_code": "var r = readline()\n\nvar count = 0\n\nfor(var i = 0; i < r; i++) {\n \n count += readline().split(\" \").map((x) => Number(x)).reduce((a,b) => a+b) >= 2 ? 1 : 0;\n \n}\n\nprint(count)"}, {"source_code": "var n = readline(), ans = 0;\nwhile(n--){\n var temp=readline();\n if((temp.split(\" \").toString().match(/1/g) !=null) &&(temp.split(\" \").toString().match(/1/g).length>=2)){\n ans+=1;\n }\n}\nprint(ans);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inp = 0\nprocess.stdin.on(\"data\",input=>{\n inp = input\n})\nprocess.stdin.on(\"end\",input=>{\n inp = inp.replace(/\\s*$/, '').split(\"\\n\").map(str => str.replace(/\\s*$/, ''));\n \n \n main();\n \n \n})\n\n\n\n\nfunction main(){\n let sure = 0;\n for (let i=1;i<=inp[0];i++){\n if(inp[i].split(\" \").filter(item=>{return item>0}).length>1){sure += 1}\n }\n console.log(sure)\n}"}, {"source_code": "var n = parseInt(readline());\nvar output = 0;\n \nfor(var i = 0; i < n; i++)\n{\n\tvar sures = readline();\n\tif(sures.indexOf('1') != sures.lastIndexOf('1')) output++;\n}\n \nprint(output);"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet t = parseInt(readLine())\n\tlet solCount=0\n\twhile(t--){\n\t\tlet [petya,vasya,tonya] = readLine().split(\" \").map(n=>+n)\n\t\tif(petya && vasya || vasya && tonya || petya && tonya)\n\t\t\tsolCount++\n\t}\n\tconsole.log(solCount)\n}"}, {"source_code": "var numberOfProblems = parseInt(readline());\nvar arrOfAnswers = [];\nfor(var i = 0; i < numberOfProblems; ++i) {\n arrOfAnswers[i] = readline().split(\" \").map(function(val){\n return parseInt(val);\n });\n}\nvar friendsNum = 3;\nvar sureOfSolutions = 0\nvar countOfWhoSure = 0;\n\nfor(i = 0; i < parseInt(numberOfProblems); ++i) {\n countOfWhoSure = 0;\n for(var j = 0; j < friendsNum; ++j) {\n if(arrOfAnswers[i][j] == 1) {\n ++countOfWhoSure;\n if(countOfWhoSure == 2) {\n ++sureOfSolutions;\n break;\n }\n \n }\n }\n}\n\nprint(sureOfSolutions);"}, {"source_code": "if (process.argv[2] === \"test\") {\n lines = [\"3\", \"1 0 0\", \"1 1 0\", \"0 1 1\"];\n solve(lines);\n} else {\n let i = \"\";\n process.stdin.on(\"data\", (c) => (i += c));\n process.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\");\n const lines = i.split(EOL);\n\n solve(lines);\n });\n}\n\nfunction solve(lines) {\n const problemCount = lines[0];\n let answerCount = 0;\n for (let x = 0; x < problemCount; ++x) {\n const answers = lines[x + 1].split(\" \");\n const score = answers.filter((x) => x === \"1\").length;\n if (score >= 2) {\n ++answerCount;\n }\n }\n console.log(answerCount);\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet ty = parseInt(readLine())\n\tlet solCount=0\n\twhile(ty--){\n\t\tlet [petya,vasya,tonya] = readLine().split(\" \").map(n=>+n)\n\t\tif(petya && vasya || vasya && tonya || petya && tonya)\n\t\t\tsolCount++\n\t}\n\tconsole.log(solCount)\n}"}, {"source_code": "numOfLines = readline();\n num = parseInt(numOfLines);\n output = 0;\n outputInOneLine = 0;\n for (i = 0; i < num; i++) {\n line = readline();\n val = line.split(\" \");\n val.map(el => {\n if (el == 1) {\n outputInOneLine++;\n }\n })\n if (outputInOneLine > 1) {\n output++;\n }\n outputInOneLine = 0;\n }\n print(output);\n"}, {"source_code": "var count = readline();\n\nvar ans = 0;\nfor(var i = 0; i< count; i++){\n var nums = readline();\n nums = nums.split(' ');\n var sum = 0;\n nums.map(a => {\n a = parseInt(a,10);\n if(a>0){\n sum++;\n }\n });\n if(sum>1){\n ans++;\n }\n sum=0;\n}\n\nprint(ans);"}, {"source_code": "var a = readline();\nvar jami = 0;\nfor(i = 1; i <= a; i ++ ) {\n\tvar cin = readline().split(\" \").sort(function(a,b){return a-b});\n\tif(cin[1] == 1) {\n\t\tjami += 1;\n\t}\n \n}\n\n\n\nprint(jami);"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar idx = 0;\nvar out = 0;\nrl.on(\"line\", (theLine) => {\n if (idx === 0) {\n lines = parseInt(theLine);\n } \n else {\n var scores = theLine.split(\" \");\n var currentCount = 0;\n scores.forEach(element => {\n if (element === \"1\")\n currentCount++\n });\n if (currentCount>1)\n out++;\n }\n idx++;\n if (idx > lines) \n {\n rl.close();\n console.log(out.toString());\n }\n \n})\n"}, {"source_code": "let fs = require('fs')\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter((data) => {\n return data.length > 0;\n});\n// txt.shift()\n\nfor (let index = 0; index < txt.length; index++) {\n if (!isNaN(txt[index]*1)) {\n let tab = []\n for (let i = 1; i <= txt[index]; i++) {\n tab.push(txt[index + i].split(\" \").filter(data=>{return data.length>0}));\n }\n square(tab)\n }\n\n}\n\nfunction square(tab) {\n let score = 0;\n tab.forEach(element => {\n if (element.filter(data => {\n return data == 1\n }).length >= 2) {\n ++score;\n }\n });\n console.log(score); \n}"}, {"source_code": "var numberOfSolutions = 0,\n count = +readline();\nwhile(count--){\n var views = readline().split(\" \");\n var sum = 0;\n for(var i = 0; i<3; i++){\n sum += +views[i];\n }\n if(sum >=2){\n numberOfSolutions++;\n }\n}\nprint(numberOfSolutions);"}, {"source_code": "var num_problemas = readline(); // Leemos el n\u00famero de problemas que debemos tratar\nvar respuestas = 0;\nvar respuesta_individual;\n// Por cada problema propuesto:\nfor (var i = 0; i < num_problemas; i++) {\n var problema = readline().split(\" \"); // Leemos y transformamos en un array las soluciones del equipo\n // Por cada soluci\u00f3n individual propuesta:\n respuesta_individual = 0;\n for (var j = 0; j < problema.length; j++) {\n if (problema[j] == 1) {\n respuesta_individual++;\n }\n }\n // Si hay m\u00e1s de una respuesta afirmativa:\n if (respuesta_individual > 1) {\n respuestas++;\n }\n}\nprint(respuestas);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\n let solve=(A)=>{\n let n=A.length,result=0\n for(let i=0;ia+Number(c),0)\n if(total>=2){\n result++\n }\n }\n return result\n }\n\n let n=readline()\n let A=[]\n for (let i = 0; i < n; i++) {\n A.push(readline().split(\" \").map(d=>Number(d))) \n }\n\n let result=solve(A)\n console.log(result.toString())\n \n \n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n\n// Write your code here\nfunction nameLookUp(arr) {\n let nLines = arr.split('\\n');\n let problems = +nLines[0].trim();\n let problemSolArr = nLines;\n let solution = 0;\n for (let solProb of problemSolArr.slice(1)) {\n\n let bits = solProb.trim().split(' ');\n\n let sum = bits.reduce(function (acc, value) {\n return acc + parseInt(value);\n }, 0);\n if (sum > 1) {\n solution++;\n }\n }\n\n return solution.toString();\n\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = readLine();\n var count = 0;\n while (T--) {\n var str = readLine();\n var strSingle = str.split(\" \");\n for (let i = 0; i <= T; i++) {\n if (\n (strSingle[0] == 1 && strSingle[1] == 1) ||\n (strSingle[0] == 1 && strSingle[2] == 1) ||\n (strSingle[1] == 1 && strSingle[2] == 1)\n ) {\n count++;\n break;\n }\n }\n }\n if (count) {\n console.log(count);\n } else {\n console.log(0);\n }\n}\n"}, {"source_code": "var x = parseInt(readline());\n\nvar total = 0;\nfor (var i=0 ; i input.push(line));\n\nconst aTeam = (a) => {\n +input.shift();\n let common = 0;\n for (let x of input) {\n const ar = x.split(' ').map(x => +x);\n let score = 0;\n for (let y of ar) {\n score += y;\n }\n if (score >= 2) {\n common ++;\n }\n }\n console.log(common);\n};\n\n\nreadLine.on('close', aTeam);"}, {"source_code": "var n = parseInt(readline());\n\nvar input = [];\n\nfor (var i = 1; i <= n; i++) {\n input.push(readline().split(' '));\n} \n\nvar solvedCount = 0;\nvar sureCount = 0;\n\ninput.forEach(function(line) {\n sureCount = 0;\n \n line.forEach(function(value) {\n if (parseInt(value)) {\n sureCount++;\n }\n });\n\n if (sureCount >= 2) {\n solvedCount++;\n }\n\n});\n\nprint(solvedCount);"}, {"source_code": "var n = parseInt(readline());\nvar output = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar tmp = 0;\n\tvar sures = readline().split(' ').map(function(c){\n\t\tif(c == 1) tmp++;\n\t});\n\tif(tmp >= 2) output++;\n}\n\nprint(output);\n"}, {"source_code": "var n = parseInt(readline());\nvar output = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar tmp = 0;\n\tvar sures = readline().split(' ').map(function(c){\n\t\tif(c == 1) tmp += 1;\n\t});\n\tif(tmp >= 2) output += 1;\n}\n\nprint(output);"}, {"source_code": "var n = parseInt(readline()), output = 0, sures;\n\nfor(var i = 0; i < n; i++)\n{\n\tsures = readline();\n\tif(sures.indexOf('1') != sures.lastIndexOf('1')) output++;\n}\n\nprint(output);\n"}, {"source_code": "var counter=0;\nvar problems = readline();\nvar array2D=[];\nfor(var i=0;i parseInt(x)));\n}\nfor (var i = 0 ; i < problems ; i++)\n{\n if ((array2D[i][0]==array2D[i][1] && array2D[i][0]==1) || \n (array2D[i][0]==array2D[i][2] && array2D[i][0]==1) ||\n (array2D[i][1]==array2D[i][2] && array2D[i][1]==1)){\n counter++;\n }\n}\nprint (counter)"}, {"source_code": "readline()\nvar values;\nvar count = 0;\nwhile(values = readline()){\n if(values.replace(/[ 0]/g, \"\").length > 1) count++\n}\n\nprint(count)"}, {"source_code": "var answer = readline();\nvar result = 0;\nfor(var i = 0; i < answer; i++){\n var input = readline().split('');\n var sum = 0;\n for(var x = 0; x < input.length; x++){\n if(input[x] == 1){\n sum ++;\n }\n }\n if(sum > 1){\n result ++;\n }\n}\nprint(result);"}, {"source_code": "var n = readline();\nvar ans = 0;\nfor (i = 0; i < n; ++i) {\n l = readline().split(' ').map(function(x) {\n return parseInt(x);\n });\n ans += (l[0] + l[1] + l[2] >= 2);\n}\nprint(ans);"}, {"source_code": "const n = Number(readline());\nvar c ;\nvar q = 0;\nfor(var i = 0; i < n ; i++){\n c = readline().split(\" \");\n var k = c.reduce((acc, cur) => {\n if(cur == 1) \n return (acc + 1);\n else\n return acc;\n },0);\n (k >= 2) ? q++ : null; \n}\nprint(q);\n"}, {"source_code": "const n = Number(readline());\nvar c ;\nvar q = 0;\nfor(var i = 0; i < n ; i++){\n c = readline().split(\" \");\n var k = c.reduce((acc, cur) => {\n if(cur == 1) \n return (acc + 1);\n else\n return acc;\n },0);\n (k >= 2) ? q++ : null; \n}\nprint(q);\n//"}, {"source_code": "var noOfProblems = +readline();\n\nvar noOfSolutions = 0;\n\nfor (var i = 0; i < noOfProblems; i++) {\n var opinions = readline().split(\" \");\n if (+opinions[0] === 1 && +opinions[1] === 1) {\n noOfSolutions += 1;\n } else if (+opinions[0] === 1 && +opinions[2] === 1) {\n noOfSolutions += 1;\n } else if (+opinions[1] === 1 && +opinions[2] === 1) {\n noOfSolutions += 1;\n }\n}\nprint(noOfSolutions);\n"}, {"source_code": "var r = readline();\nvar c = 0;\nfor(var i = 0; i= 2){\n c++;\n }\n}\nprint(c);"}, {"source_code": "var n = readline();\nvar count = 0\nfor(var i = 0; i parseInt(x)).reduce((a,b) => a + b) >=2 ? 1 : 0\n}\nprint(count)"}, {"source_code": "var n = readline();\nvar count = 0\nfor(var i = 0; i parseInt(x)).reduce((a,b) => a + b) >=2){\n count += 1\n }\n}\nprint(count)"}, {"source_code": "var AtLeastTwoAgreed = array => {\n var howManyAgreed = 0;\n for(var number of array)\n {\n howManyAgreed += number === 1 ? 1 : 0;\n\n if(howManyAgreed === 2)\n return 1;\n }\n\n return 0;\n}\n\nprint(\n [...Array(+readline())].map(x => readline().split(' ').map(n => +n))\n .map(values => AtLeastTwoAgreed(values))\n .reduce((result, current) => result + current, 0)\n);"}, {"source_code": "var problems = parseInt(readline());\nvar unsolved = 0;\nwhile(problems--){\n var problem = readline().split(\" \");\n var solution = 0;\n for(var i = 0; i < problem.length; i++){\n if(problem[i] == \"1\"){\n solution++;\n }\n }\n\n if(solution >= 2){\n unsolved++;\n }\n}\nprint(unsolved);\n"}, {"source_code": "var x=parseInt(readline());\nvar res=0;\n \nwhile(x--){\n var z = readline().split(' ');\n var sum=findSum(z);\n // print(\"Sum:\",sum);\n res+=Math.floor(sum/2);\n}\n \nfunction findSum(z){\n return z.reduce((a,b) => parseInt(a)+parseInt(b),0);\n}\n \nprint(res);"}, {"source_code": "var q = parseInt(readline());\n\nvar result = 0;\nfor (var i = 0; i < q; i++) {\n var known = readline().split(\" \").map(x => parseInt(x));\n \n if (known[0] + known[1] + known[2] >= 2) {\n result++;\n }\n}\n\nprint(result);"}, {"source_code": "var n = readline();\n\nvar result = 0;\n\nfor(var i = 0 ; i < n; i++){\n var string = readline();\n string = string.replace(/\\s/g,'');\n var decision = 0;\n\n for(var j =0; j < string.length;j++){ \n if(string[j] == 1)\n decision++;\n }\n \n if(decision >= 2)\n result++;\n}\n\nprint(result);"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar arr = [];\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] === 1 && w[i + 1] === 1 || w[i + 1] === 1 && w[i + 2] === 1 || w[i] === 1 && w[i + 2] === 1) {\n result++;\n result += result;\n print(result.length);\n }else {\n result += result\n print(result.length);\n }\n \n }\n}\n//print (arr[0]);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\n\nprint (resolve(problems));"}, {"source_code": "var input = readline().split(\"\\n\");\nvar count = 0;\nfor(var i = 1;i < input.length; i++){\n var sures = input[i].split(\" \").filter(function(element){return element == 1});\n if(sures.length > 1) count++;\n}\nprint(count);"}, {"source_code": "process.stdin.on('data', input => {\n const testArguments = input.toString().split('\\n').splice(1);\n let count = 0;\n testArguments.forEach(test => {\n count += checkIfSolveProblem(test.split(' '))\n })\n console.log(count);\n});\n\nfunction checkIfSolveProblem(arr) {\n const result = arr.reduce((acc, curr) => {\n if (curr) {\n acc++\n }\n\n return acc;\n }, 0)\n\n return result > 0 ? 1 : 0;\n}\n"}, {"source_code": "readline();\nvar ans = 0;\nfor (var s; s = readline(); ) {\n 1 < s.split( ' ' ).reduce( function(it, last) { return it - '' + last; }, 0 ) && ans++;\n}\n\nprint( ans );"}, {"source_code": "var n = parseInt(readline()), \n p = readline().split(' ').map(function(x) { return parseInt(x); }), \n i, \n s = 0, \n c = 0; \n \nfor(i = 0; i < n; i++) { \n c += p[i]; \n}\nif(c>=2) s=c; \nwrite(s);"}, {"source_code": "var prob = 0;\nvar t;\nwhile(t--){\n var x = readline().split(' ');\n \n if((x[0]==1 && x[1]==1) || (x[0] == 1 && x[2]==1) || (x[1]==1 && x[2]==1)){\n prob = prob + 1;\n }\n}\n\nprint(prob);"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0\nlet n;\nlet imp = 0\nfunction main(input){\n\tif(i == 0 ){\n\t\tn = input\n\t\ti++\n\t\treturn\n\t}\n\tif(n == i){\n\t\tconsole.log(imp)\n\t\treturn\n\t}\n\tlet p, v, t\n\n\tconst arr = input.split(' ')\n\n\tp = arr[0]\n\tv = arr[1]\n\tt = arr[2]\n\n\tlet result = parseInt(p) + parseInt(v) + parseInt(t)\n\tif(result >= 2){\n\t\t//they will imp\n\t\timp++\n\t}\n\n\ti++\n\n}\n"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = parseInt(readline());\nvar datos = new Array();\nvar contador = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tdatos.push(readline().split(' '));\n}\n\nfor (var y = 0; y 1 )\n{\n d+=1;\n}\nprint(d);\n\n"}, {"source_code": "var outp = 1;\nfor (var i = 0; i < Number(readline()); i++) {\n var str = readline().split(' ');\n var count = Number(str[0]) + Number(str[1]) + Number(str[2]);\n if (count > 1) outp ++;\n}\nprint(outp);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n \n for (var i=0; i=2) {\n problSolv++;\n }\n }\n \n return problSolv;\n}\n\nprint (resolve(parseInt(problems)));\n"}, {"source_code": "var count = parseInt(readline()),\n current = [], currentMas, sum, answer = 0;\n\nfor(var i = 0; i < count; i++) {\n current[i] = readline().split(\" \");\n}\n\nfor(var i = 0; i < count; i++) {\n currentMas = current[i];\n sum = 0;\n\n for(var j = 0; j < 3; j++) {\n sum+=currentMas[j];\n }\n\n if(sum >= 2) {\n answer+=1;\n }\n} \n\nprint(answer);"}, {"source_code": "var n = readline()\nvar zad = 0;\n\nfor (var i=0; i parseInt(sum+current));\n\t\n\tif(sum=>2)\n\tzad++;\n};\nprint(zad);"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = readline();\nvar input = [];\n\nvar resueltos = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tinput.push(readline().split(' '));\n\t\n}\n\nprint(input);"}, {"source_code": "n = readline();\nvar tedad = 0;\nwhile(n--)\n{\n \ts=readline().split('0')\n\t\n\tif(s.length > 3){tedad++}\n\t\n}\nprint(tedad)"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\nprint (resolve(parseInt(problems)));"}, {"source_code": "var n = readline()\nvar zad = 0;\n\nfor (var i=0; i +sum+ +current);\n\t\n\tif(sum=>2)\n\t++zad;\n};\nprint(zad);\n//console.log(zad);"}, {"source_code": "var n = parseInt(readline());\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {\n result++;\n result += result;\n write(result[0]);\n }else {\n write(result[0]);\n }\n \n }\n}"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = parseInt(readline());\nvar datos = new Array();\nvar contador = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tdatos.push(readline().split(' '));\n}\n\nfor (var y = 0; y +sum+ +current);\n\t\n\tif(sum=>2)\n\t++zad;\n};\nprint(zad);\n//console.log(zad);"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = readline();\nvar datos = new Array();\nvar contador = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tdatos.push(readline().split(' '));\n}\n\nfor (var y = 0; y parseInt(x));\n \n var res = 0;\n for (var j = 0; j < known; j++) {\n if (known[j] === 1) {\n res++;\n }\n }\n \n if (res >= 2) {\n result++;\n }\n}\n\nprint(result);"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n\t input: process.stdin,\n\t output: process.stdout,\n\tterminal : false\n});\n\n\nrl.on(\"line\", main)\nlet i = 0\nlet n = 0\nlet imp = 0\nfunction main(input){\n\tif(n == 0 ){\n\t\tn = input\n\t\treturn\n\t}\n\tif(n == i){\n\t\tconsole.log(imp)\n\t\treturn\n\t}\n\tlet p, v, t\n\n\tconst arr = input.split(' ')\n\n\tp = arr[0]\n\tv = arr[1]\n\tt = arr[2]\n\n\tlet result = parseInt(p) + parseInt(v) + parseInt(t)\n\tif(result >= 2){\n\t\t//they will imp\n\t\timp++\n\t}\n\n\ti++\n\n}\n"}, {"source_code": "\nvar z = [[]];\n\nvar a,b,c,d;\na = parseInt(readline());\n\nfor (var c=0; c1 )\n{\n d+=1;\n}\nprint(d);\n\n"}, {"source_code": "var t = readline();\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var nProblems = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n\nvar result = 0;\n\nfor (var i = 0; i < nProblems; i++)\n{\n var randomRussians = readline().split(\" \").map(function(x) { return parseInt(x); });\n \n var implement = 0;\n \n for (var j = 0; j < randomRussians.length; j++)\n {\n if (randomRussians[i] == 1)\n implement++;\n \n if (implement >= 2)\n {\n result++;\n \n break;\n }\n }\n}\n\nprint(result);\n"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = readline();\nvar input = [];\n\nvar resueltos = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tinput.push(readline().split(' '));\n\t\n}\n\nprint(input);"}, {"source_code": "var prob = 0;\nvar t;\nwhile(t--){\n var x = readline().split(' ');\n \n if((x[0]==1 && x[1]==1) || (x[0] == 1 && x[2]==1) || (x[1]==1 && x[2]==1)){\n prob = prob + 1;\n }\n}\n\nprint(prob);"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = readline();\nvar datos = new Array();\nvar contador = 0;\nvar linea = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tlinea = readline().split(' ');\n\tif (linea[0]+linea[1]+linea[2] >= 2){\n\t\tcontador++;\n\t}\n}\n\nprint(contador);\n"}, {"source_code": "var lines = readline(); \nvar outp = 0;\nfor (var i = 0; i < lines; i++) {\n var str = readline().split(' ');\n var count = 0;\n for (var j = 0; j < 3; j++) {\n count += str[j];\n }\n if (count >= 2) outp ++;\n}\nprint(outp);"}, {"source_code": "var numberOfProblems = readline();\nvar arrOfAnswers = [];\nfor(var i = 0; i < numberOfProblems; ++i) {\n arrOfAnswers[i] = readline();\n}\nvar friendsNum = 3;\nvar sureOfSolutions = 0\nvar countOfWhoSure = 0;\n\nfor(var i = 0; i < numberOfProblems; ++i) {\n countOfWhoSure = 0;\n for(var j = 0; j < friendsNum; ++j) {\n if(parseInt(arrOfAnswers[i][j])) {\n ++countOfWhoSure;\n if(countOfWhoSure == 2) {\n ++sureOfSolutions;\n break;\n }\n }\n }\n}\n\nprint(sureOfSolutions);"}, {"source_code": "'use strict';\n\n// let inpArr = `\n// 3\n// X--\n// --X\n// X++\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nlet n = Number(readline()), X = 0;\nfor (var i = 0; i < n; i++) {\n let str = readline();\n if (str.indexOf('+') !== -1) {\n X++;\n } else {\n X--;\n }\n}\nprint(X);\n"}, {"source_code": "var count = readline()\nvar totalRightAnswers = 0;\n\nwhile(count){\n var round = readline()\n const haveAnswers = round.split(\" \")\n const res = haveAnswers.reduce((accumulator, currentValue) => {\n if (currentValue == '1') return accumulator++\n }); \n if(res >= 2){\n totalRightAnswers++\n } \n count--\n}\n\nprint(totalRightAnswers)"}, {"source_code": "var n = parseInt(readline());\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {\n result++;\n result += result;\n write(result);\n }else {\n write(result);\n }\n \n }\n}\n"}, {"source_code": "var t = readline();\nt=+t+1;\nprint(t);\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var numberOfTestCases = parseInt(readline());\n\nvar input;\n\nvar ans = 0;\n\nfor(var i = 0 ; i < numberOfTestCases ; i++) {\n\ninput = readline().split(\" \");\n\nvar counter = 0;\n\nfor (var j=0; j 2){\n ans++;\n}\n\n\n\n}\n\nprint(ans);"}, {"source_code": "var loop = readline();\nvar correct = 0;\nfor (var i = 0; i < loop; i++){\n var total = readline().split(\" \");\n if(total[0] + total[1] + total[2] > 2){\n correct++;\n }\n}\n\nprint(correct);"}, {"source_code": "var t = readline();\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var n = +readline(),\n\tresult = 0;\nwhile (n--) {\n\tvar array = readline().split(' ').map(function (item) { return item > 0; });\n result += array.length > 1 ? 1 : 0;\n}\nprint(result);"}, {"source_code": "/*\nOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.\n\nThis contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.\n\nInput\nThe first input line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.\n\nOutput\nPrint a single integer \u2014 the number of problems the friends will implement on the contest.\n*/\n\nvar problemas = parseInt(readline());\nvar datos = new Array();\nvar contador = 0;\n\nfor (var x = 0; x < problemas; x++){\n\tdatos.push(readline().split(' '));\n}\n\nfor (var y = 0; y {\n if (element == '1') return accumulator++\n });\n if(accumulator >= 2){\n totalRightAnswers++\n }\n count--\n}\n\nprint(totalRightAnswers)"}, {"source_code": "var n=readline();\nvar int=parseInt(n);\nvar count=0;\n \nfor(var i=1; i<=int; i++){\n \n for(var j=1; j<=int; ++j){\n var question=readline();\n var newint=parseInt(question);\n var sum=0;\n sum=sum+newint;\n \n }\n if(sum==2 || sum==3){\n count++;\n}\n print(count);\n}"}, {"source_code": "var n = parseInt(readline());\nvar arr = [];\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] === 1 && w[i + 1] === 1 || w[i + 1] === 1 && w[i + 2] === 1 || w[i] === 1 && w[i + 2] === 1) {\n result++;\n result += result;\n arr.push(result);\n }else {\n result += result\n arr.push(result);\n }\n \n }\n}\nprint (arr[0]);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let testcases=Number(readline())\n\n let solve=(A)=>{\n let n=A.length,result=0\n for(let i=0;ia+c)\n if(total>=2){\n result++\n }\n }\n return result\n }\n\n for (let i = 0; i Number(d))) \n }\n\n let result=solve(A)\n console.log(result.toString())\n }\n \n}"}, {"source_code": "var t = readline();\nt=+t+1;\nprint(t);\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var numberOfProblems = readline();\nvar arrOfAnswers = [];\nfor(var i = 0; i < numberOfProblems; ++i) {\n arrOfAnswers[i] = readline();\n}\nvar friendsNum = 3;\nvar sureOfSolutions = 0\nvar countOfWhoSure = 0;\n\nfor(var i = 0; i < numberOfProblems; ++i) {\n countOfWhoSure = 0;\n for(var j = 0; j < friendsNum; ++j) {\n if(parseInt(arrOfAnswers[i][j])) {\n ++countOfWhoSure;\n if(countOfWhoSure == 2) {\n ++sureOfSolutions;\n break;\n }\n }\n }\n}\n\nprint(sureOfSolutions);"}, {"source_code": "var count = readline()\nvar totalRightAnswers = 0;\n\nwhile(count){\n var round = readline()\n const haveAnswers = round.split(\" \")\n var accumulator = 0\n haveAnswers.forEach(element => {\n if (element == '1') return accumulator++\n });\n if(accumulator >= 2){\n totalRightAnswers++\n }\n count--\n}\n\nprint(totalRightAnswers)"}, {"source_code": "var t = readline(),\n a = 0;\nwhile(t--){\n var x = readline().split(' ');\n var count = 0;\n for(var i = 0;i<3;i++){\n if(x[i] === 1){count++;}\n }\n if(count>=2){\n a++; \n }\n}\nprint(a);"}, {"source_code": "var t = readline();\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\nprint (resolve(parseInt(problems)));\n"}, {"source_code": "var pro = readline();\nvar tot = 0;\nfunction getSum(total, num) {\n return total + num;\n}\nfor (i = 0; i < pro; i++) {\n var arr = readline().split(' ');\n var col = arr.reduce(getSum);\n if (col >= pro) {\n var out = tot + 1;\n \n }\n \n}\nprint(out);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\nprint (resolve(parseInt(problems)));\n"}, {"source_code": "var num=3;\nvar contest=[[1,1,0],[1,1,1],[1,0,0]];\nvar can=0;\nfor(var i=0;i=2){\n can++;\n }\n}\nprint(can);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet numberOfProblems = 0\nlet numberofSolvedProblems = 0 ;\nlet counter = 0;\nlet arrofInputs = [];\nlet getuserInputs = ()=>{\n rl.on(\"line\",(input)=>{\n if(!numberOfProblems) {\n numberOfProblems = parseInt(input)\n console.log(\"Problems We Got Today :\"+numberOfProblems + \"\\n\") \n } \n else \n { \n counter++\n arrofInputs = input.split(\" \").map(Number)\n if(!arrofInputs.includes(0))numberofSolvedProblems++\n else{\n let temp = 0\n arrofInputs.forEach(element => {\n if(element===1) temp++\n });\n if (temp>=2) numberofSolvedProblems++\n }\n if (counter>=numberOfProblems){\n console.log(numberofSolvedProblems)\n rl.close();\n }\n }\n })}\ngetuserInputs()\n// })\n// let numberofSolvedProblems = 0;\n// let numberOfProblems = parseInt(prompt());\n// for(let i=0 ;i {\n// if(element === 0)\n// {\n// zeroCounter++\n// }\n// })\n// if(zeroCounter>1)\n// numberofSolvedProblems = numberofSolvedProblems\n// else\n// numberofSolvedProblems++ \n// }\n// }\n// console.log(numberofSolvedProblems)\n\n//// rl.close()"}, {"source_code": "var count = parseInt(readline()),\n current = [], currentMas, sum, answer = 0;\n\nfor(var i = 0; i < count; i++) {\n current[i] = readline().split(\" \");\n}\n\nfor(var i = 0; i < count; i++) {\n currentMas = current[i];\n sum = 0;\n for(var j = 0; j < 3; j++) {\n sum+=currentMas[j];\n }\n\n if(sum>=2) {\n answer+=1;\n }\n} "}, {"source_code": "var lines = Number(readline()); \nvar outp = 0;\nfor (var i = 0; i < lines; i++) {\n var str = readline().split(' ');\n var count = str[0] + str[1] + str[2];\n if (count >= 2) outp ++;\n}\nprint(outp);"}, {"source_code": "var result = 0;\n var count = parseInt(readline().split(''));\n function canResolve(value){\n return value === '1';\n }\n for (var i = 0; i < count; i++) {\n var array = readline().split(' ');\n result += array.filter(canResolve).length >= 2 ? 1 : 0;\n }\n print(result);"}, {"source_code": "var n, i, k = 0;\nn = readline();\nn = parseInt(n);\nvar a = [];\nvar b = [];\nvar input = readline();\na = input.split(' ');\nfor(i = 0; i < (3 * n); i++) {\n a[i] = parseInt(a[i]);\n}\nfor(i = 0; i < n; i++) {\n b[i] = a[(3 * i)] + a[3 * i + 1] + a[3 * i + 2];\n}\nfor(i = 0; i < n; i++) {\n if(b[i] > 1)\n k++;\n}\nprint(k);\n"}, {"source_code": "var n = parseInt(readline());\n\nvar input = [];\n\nfor (var i = 1; i <= n; i++) {\n input.push(readline().split(' '));\n} \n\nvar solvedCount = 0;\ninput.forEach(function(line) {\n var sureCount = 0;\n line.forEach(function(value) {\n if (value) {\n sureCount++;\n }\n });\n if (sureCount >= 2) {\n solvedCount++;\n }\n});\n\nprint(solvedCount);"}, {"source_code": "var t = readline();\nwhile(t--){\n var x = readline().split(' ');\n var a = 0,\n count = 0;\n for(var i = 0;i<3;i++){\n if(x[i] === 1){count++}\n }\n if(count=>2){\n a++ \n }\n}\nprint(a);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = readLine();\n var count = 0;\n while (T--) {\n var str = readLine();\n var strSingle = str.split(\" \");\n for (let i = 0; i <= T; i++) {\n if ((strSingle[0] == 1 && strSingle[1] == 1) || (strSingle[1] == 1 && strSingle[2] == 1)) {\n count++;\n break;\n }\n }\n }\n if (count) {\n console.log(count);\n } else {\n console.log(0);\n }\n}\n"}, {"source_code": "const stdin = process.openStdin();\nlet n;\nlet i = 0;\nlet output = 0;\n\nprocess.stdin.on('data', function (chunk) {\n lines = chunk.toString().split('\\n');\n lines.map(line => processLine(line));\n});\n\nfunction processLine(text) {\n if (n) { i += 1; }\n if (!n) { n = parseInt(text.toString()) }\n\n if (i > 0) {\n const solve = text.toString().trim().split(' ').reduce((a, b) => a + b, 0) > 1;\n console.log(solve)\n if (solve) { output += 1; }\n }\n\n if (i === n) { console.log(output); }\n}"}, {"source_code": "var n = readline()\nvar zad = 0;\n\nfor (var i=0; i parseInt(sum+current));\n\t\n\tif(sum=>2)\n\tzad++;\n};\nprint(zad);"}, {"source_code": "var n = readline();\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1) {\n result++;\n result += result;\n if (result < w.length - 2) {\n print (result);\n }\n }else{\n print(result);\n }\n \n }\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar output = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar tmp = 0;\n\tvar sures = readline().split(' ').map(function(c){\n\t\tif(c == 1) tmp += 1;\n\t});\n\tif(tmp >= 2) output += 1;\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar arr = [];\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] === 1 && w[i + 1] === 1 || w[i + 1] === 1 && w[i + 2] === 1 || w[i] === 1 && w[i + 2] === 1) {\n result++;\n result += result;\n print(result.length);\n }else {\n result += result\n print(result.length);\n }\n \n }\n}\n//print (arr[0]);"}, {"source_code": "var n = readline();\nvar zad = 0;\n\nfor (var i=0; i1)\n\t++zad;\n};\nprint(zad);"}, {"source_code": "var cases = readline();\nvar winMatch = 0;\nfor(var i = 0; i < cases; ++i){\n var points = readline();\n if(points.includes('1 1')){\n ++winMatch;\n }\n}\n\nprint(winMatch);"}, {"source_code": "var n = parseInt(readline());\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {\n result++;\n result += result;\n write(result[0]);\n }else {\n write(result[0]);\n }\n \n }\n}"}, {"source_code": "var result = 0;\n var count = parseInt(readline().split(''));\n function canResolve(value){\n return value === '1';\n }\n for (var i = 0; i < count; i++) {\n var array = readline().split(' ');\n result += array.filter(canResolve).length >= 2 ? 1 : 0;\n }\n print(result);"}, {"source_code": "var n = readline()\nvar zad = 0;\nfor (var i=0; i parseInt(sum+current));\n\t\n\tif(sum=>2)\n\tzad++;\n};\nprint(zad);"}, {"source_code": "\nvar n=readline();\nvar int=parseInt(n);\nvar count=0;\n \nfor(var i=1; i<=int; i++){\n \n \n var question=readline();\n var numbers = question.split(\" \");\n var sum=0;\n for(var j = 0; j < int; ++j) {\n var newint=parseInt(numbers[j]);\n \n sum=sum+newint;\n }\n \n \n if(sum==2 || sum==3){\n count++;\n}\n print(count);\n}"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\n\nprint (resolve(problems));"}, {"source_code": "var prob = 0,\n t;\nwhile(t--){\n var x = readline().split(' ');\n \n if((x[0]==1 && x[1]==1) || (x[0] == 1 && x[2]==1) || (x[1]==1 && x[2]==1)){\n prob = prob + 1;\n }\n}\n\nprint(prob);"}, {"source_code": "var loop = readline();\nvar correct = 0;\nfor (var i = 0; i < loop; i++){\n var total = readline().split(\" \");\n if(total[0] + total[1] + total[2] >= 2){\n correct++;\n }\n}\n\nprint(correct);"}, {"source_code": "var lines = Number(readline()); \nvar outp = 0;\nfor (var i = 0; i < lines; i++) {\n var str = readline().split(' ');\n var count = str[0] + str[1] + str[2];\n if (count >= 2) {\n outp ++;\n }\n}\nprint(outp);"}, {"source_code": "var count = readline()\nvar totalRightAnswers = 0;\n\nwhile(count){\n var round = readline()\n var haveAnswers = round.split(\" \")\n var res = haveAnswers.reduce((accumulator, currentValue) => accumulator + currentValue); \n if(res >= 2){\n totalRightAnswers++\n } \n count--\n}\n\nprint(totalRightAnswers)"}, {"source_code": "var n = readline();\nvar zad = 0;\n\nfor (var i=0; i1)\n\t{++zad;};\n};\nprint(zad);"}, {"source_code": "var t = readline();\ncount = 0;\nfor(var i=1;i=2){\n count++;\n }\n}\nprint(count);\n"}, {"source_code": "var n = parseInt(readline()), \n p = readline().split(' ').map(function(x) { return parseInt(x); }), \n i, \n s = 0, \n c = 0; \n \nfor(i = 0; i < n; i++) { \n c += p[i]; \n}\nif(c>=2) s=c; \nwrite(s);"}, {"source_code": "process.stdin.on('data', input => {\n const testArguments = input.toString().split('\\n').splice(1);\n let count = 0;\n testArguments.forEach(test => {\n count += checkIfSolveProblem(test.split(' '))\n })\n console.log(count);\n});\n\nfunction checkIfSolveProblem(arr) {\n const result = arr.reduce((acc, curr) => {\n if (curr) {\n acc++\n }\n\n return acc;\n }, 0)\n\n return result > 1 ? 1 : 0;\n}\n"}, {"source_code": "var a = readline();\nvar jami = 0;\nfor(i = 1; i < a; i ++ ) {\n\tvar cin = readline().split(\" \").sort(function(a,b){return a-b});\n\tif(cin[1] == 1) {\n\t\tjami += 1;\n\t}\n else { \n jami += 0;\n }\n}\n\n\n\nprint(jami);"}, {"source_code": "var input=readline();\nvar int = parseInt(input);\nvar varr;\nvar c = 0 ;\nvar count1 = 0;\nvar count0 = 0;\n\nfor(var i = 0 ; i < int ; i++){\n \n varr = readline();\n count(varr);\n\n if (count1 > count0) {\n c++;\n }\n \n}\n\nfunction count(str)\n{\n for (var i = 0 ; i < str.length ; i++)\n {\n \n if(str[i] == 1){\n count1++;\n \n }\n else{\n count0++;\n }\n }\n}\n\nprint(c);\n"}, {"source_code": "var n = readline().split(' ')[0];\nvar solutions = 0;\nwhile(n) {\n var state = readline().split(' ');\n var a = state[0],\n b = state[1],\n c = state[2];\n \n if ((a && b) || (b && c) || (c && a)) {\n ++solutions;\n }\n \n --n;\n}\n\nprint(solutions);"}, {"source_code": "var n = parseInt(readline());\nvar s = 0;\nvar i;\nfor (i=0;i= 2){\n s++;\n }\n}\nprint(s);"}, {"source_code": "var n = readline();\n\nvar result = 0;\n\nfor(var i = 0 ; i < n; i++){\n var string = readline();\n string = string.replace(/\\s/g,'');\n var decision = 0;\n\n for(var j =0; j < string.length;j++){ \n if(string[i] == 1)\n decision++;\n }\n \n if(decision >= 2)\n result++;\n}\n\nprint(result);"}, {"source_code": "var n = readline();\nvar sum=0;\n\nfor (var i=0; i=2)\n k++;\n}\nprint(k+1);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n \n for (var i=0; i=2) {\n problSolv++;\n }\n }\n \n return problSolv;\n}\n\nprint (resolve(parseInt(problems)));\n"}, {"source_code": "var n = parseInt(readline());\nvar arr = [];\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {\n result++;\n result += result;\n arr.push(result);\n }else {\n result += result\n arr.push(result);\n }\n \n }\n}\nprint (arr[0]);"}, {"source_code": " numOfLines = readline();\n num = parseInt(numOfLines);\n output = 0;\n outputInOneLine = 0;\n for (i = 0; i < num; i++) {\n line = readline();\n val = line.split(\" \");\n val.map(el => {\n if (el == 1) {\n outputInOneLine++;\n }\n })\n if (outputInOneLine > 1) {\n output++;\n }\n print(output);\n outputInOneLine = 0;\n }"}, {"source_code": "var n = readline()\nvar zad = 0;\n\nfor (var i=0; i +sum+ +current);\n\t\n\tif(sum=>2)\n\t++zad;\n};\nprint(zad);\n//console.log(zad);"}, {"source_code": "var n = parseInt(readline());\nvar s = 0;\nvar i;\nfor (i=0;i= 1){\n s++;\n }\n}\nprint(s);"}, {"source_code": "\nvar t;\nwhile(t--){\n var prob = 0;\n var x = readline().split(' ');\n \n if((x[0]==1 && x[1]==1) || (x[0] == 1 && x[2]==1) || (x[1]==1 && x[2]==1)){\n prob = prob + 1;\n }\n}\n\nprint(prob);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\nprint (resolve(parseInt(problems)));"}, {"source_code": "var n = parseInt(readline());\nvar arr = [];\nwhile (n--) {\n var w = readline();\n var result = 0;\n for (var i = 0; i <= w.length; i++) {\n if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1) {\n result++;\n result += result;\n arr.push(result);\n }else {\n result += result\n arr.push(result);\n }\n \n }\n}\nprint (arr[0]);"}, {"source_code": "var problems = readline();\n\nfunction resolve(prb) {\n var problSolv=0;\n for (var i=0; i=2) {\n problSolv++;\n }\n }\n return problSolv;\n}\n\nprint (resolve(problems));"}, {"source_code": "var n = readline();\nvar sum=0;\n\nfor (var i=0; i= 0; j--) {\n var nextLine = lines[j];\n var allowed = true;\n for (var k = n - 1; k >= 0; k--) {\n if (allowedCols.has(k)) {\n allowed = true;\n }\n if (!allowed && nextLine[k] === \"1\") {\n print(\"NO\");\n return;\n }\n if (nextLine[k] === \"1\") {\n allowedCols.add(k);\n } else {\n allowed = false;\n allowedCols.delete(k);\n }\n }\n }\n print(\"YES\");\n}\nmain();"}, {"source_code": "function solve() {\n var n = readInt();\n var i;\n var j;\n var x = createMatrix(n)\n for(i=0; i= 0; j--) {\n var nextLine = lines[j];\n var last0 = nextLine.lastIndexOf(\"0\");\n for (var k = 0; k < n; k++) {\n if (nextLine[k] === \"1\" && k < last0 && !allowedCols.has(k)) {\n print(\"NO\");\n return;\n }\n if (nextLine[k] === \"1\") {\n allowedCols.add(k);\n } else {\n allowedCols.delete(k);\n }\n }\n }\n print(\"YES\");\n}\nmain();\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n checkNext();\n }\n}\n\nfunction checkNext() {\n var n = +readline();\n var allowedCols = new Set();\n var lines = [];\n\n for (var j = 0; j < n; j++) {\n allowedCols.add(j);\n lines[j] = readline();\n }\n for (var j = n - 1; j >= 0; j--) {\n var nextLine = lines[j];\n var last0 = nextLine.lastIndexOf(\"0\");\n for (var k = 0; k < n; k++) {\n if (nextLine[k] === \"1\" && k < last0 && !allowedCols.has(k)) {\n print(\"NO\");\n return;\n }\n if (nextLine[k] === \"1\") {\n allowedCols.add(k);\n } else {\n allowedCols.delete(k);\n }\n }\n }\n print(\"YES\");\n}\nmain();"}], "src_uid": "eea15ff7e939bfcc7002cacbc8a1a3a5"} {"source_code": "var n = Number(readline());\n//var mas=[];\nvar str = \"\";\nvar res = 0;\nwhile(n>1){\n\tres++;\n\tif (n-2>1){\n\t\tn-=2;\n\t\tstr+=2+\" \";\n\t\t//mas.push(2);\n\t\t}\n\telse {\n\t\tstr+=n;\n\t\tbreak;}\n\t\n}\nprint(res);\nprint(str);", "positive_code": [{"source_code": "var n = +readline();\nprint(n >> 1);\nprint(new Array(n % 2).fill(3).concat(new Array((n - n % 2 * 3) / 2 ).fill(2)).join(' '));"}, {"source_code": "var n = +readline(), k = 0, res = [];\nif (n % 2 == 1) {\n n -= 3;\n k += 1;\n res.push(3)\n}\nk += n / 2;\nres.push(...new Array(n / 2).fill(2));\nprint(k);\nprint(res.join(' '));"}, {"source_code": "var n = +readline(), k = 0, res = [];\nif (n % 2 == 1) {\n n -= 3;\n k += 1;\n res.push(3)\n}\nwhile (n > 0) {\n n -= 2;\n k += 1;\n res.push(2)\n}\nprint(k);\nprint(res.join(' '));"}, {"source_code": "var n = +readline();\nprint(n / 2 | 0);\nprint(new Array(n % 2).fill(3).concat(new Array((n - n % 2 * 3) / 2 ).fill(2)).join(' '));"}, {"source_code": "var n = parseInt(readline());\nvar result = '';\nvar count = 0;\nif(n % 2 == 0){\n for(var i = 0; i < n/2; i ++) {\n count ++;\n if(i == n/2 - 1){\n result += '2';\n }else {\n result += '2 ';\n }\n\n }\n} else {\n for(var i = 0; i < (n-3)/2; i ++) {\n count ++;\n result += '2 ';\n }\n\n result += '3';\n count++;\n}\n\nprint(count + '\\n' + result);"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line1) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n\n var result = [];\n\n while (n > 3) {\n n -= 2;\n result.push(2);\n }\n\n result.push(n);\n\n return result.length + \"\\n\" + result.join(\" \");\n}"}, {"source_code": "(function() {\n 'use strict';\n let n = readline();\n var x = 0;\n var y = [];\n let i = 0;\n if (n % 2 === 0) {\n x = n / 2;\n while (i < x) {\n y.push(2);\n i++;\n }\n } else {\n x = (n - n % 2) / 2;\n while (i < x - 1) {\n y.push(2);\n i++;\n }\n y.push(3);\n }\n print(x);\n print(y.join(' '));\n \n}());"}, {"source_code": "\nfunction main()\n{\n var n = parseInt( readline() );\n \n var ans = n%2==0 ? n/2 : (n-3)/2+1;\n print( ans );\n while ( n > 3 )\n {\n write( 2 + ' ' );\n n -= 2;\n }\n \n if ( n == 2 ) write( 2 );\n else write( 3 );\n print();\n \n} main();"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, i, j, n, ref, ref1, results, results1;\n\n n = Number(readline());\n\n if (n % 2 === 1) {\n arr = (function() {\n results = [];\n for (var i = 0, ref = (n - 3) / 2; 0 <= ref ? i < ref : i > ref; 0 <= ref ? i++ : i--){ results.push(i); }\n return results;\n }).apply(this).map(function(x) {\n return '2';\n });\n arr.push(3);\n } else {\n arr = (function() {\n results1 = [];\n for (var j = 0, ref1 = n / 2; 0 <= ref1 ? j < ref1 : j > ref1; 0 <= ref1 ? j++ : j--){ results1.push(j); }\n return results1;\n }).apply(this).map(function(x) {\n return '2';\n });\n }\n\n print(arr.length);\n\n print(arr.join(' '));\n\n}).call(this);\n"}, {"source_code": "var n = +readline();\n\nvar pn = n & 1 ? [((n - 3) / 2), 1] : [n / 2, 0];\n\nprint(pn[0] + pn[1]);\nprint(new Array(pn[0]).fill('2').concat(new Array(pn[1]).fill('3')).join(' '));"}, {"source_code": "var main = function(num)\n{\n\tvar arr = [];\n\tif (num % 2 === 0){\n\t\tfor (var i = 1; i <= num / 2; i++)\n\t\t{\n\t\t\tarr.push(2);\n\t\t}\n\t\treturn arr;\n\t}\n\telse\n\t{\n\t\tnum -= 3;\n\t\tif (num > 0)\n\t\tfor (var i = 1; i <= num / 2; i++)\n\t\t{\n\t\t\tarr.push(2);\n\t\t}\n\t\tarr.push(3);\n\t\treturn arr;\n\t}\n}\n\nvar input = readline();\nprint(main(+input).length);\nprint(main(+input).join(' '));"}, {"source_code": "function sa(n){\n var k = Math.floor(n/2);\n var res = k + \"\\n\";\n for(var i=0;i {lines.push(line);})\n\t\t\t\t.on('close', () => {main(lines)});\n\nconst main = (input) => {\n\tvar num = parseInt(input);\n\t\n\tconsole.log(Math.floor(num / 2));\n\t\n\tvar ans = \"\";\n\t\n\tif (num % 2 == 1) {\n\t\tnum -= 3;\n\t\tans += \"3 \";\n\t}\n\t\n\tfor (var i = 0; i < num; i += 2) {\n\t\tans += \"2 \";\n\t}\n\t\n\tconsole.log(ans.trim());\n}"}, {"source_code": "function main() {\n // write code here:\n var n = Number(stdin[0]);\n var arr = [];\n var m=0;\n if (n % 2 === 0) {\n m = n / 2;\n for (let i = 0; i < m; i++) {\n arr.push(2);\n }\n }else{\n //\u65e2\u7136\u8981\u6c42\u7684\u662f\u6700\u591a\u53ef\u4ee5\u6709\u591a\u5c11\u8d28\u6570\u4e4b\u548c\u80fd\u7b49\u4e8en\uff0c\u90a3\u4e482\u4e4b\u540e\u5373\u4e3a3\n n -= 3;\n if (n > 0)\n for (let i = 1; i <= n / 2; i++)\n {\n arr.push(2);//\u51cf\u53bb3\u4e4b\u540e\u8981push\u51e0\u4e2a2\u8fdbarr\n }\n arr.push(3);\n }\n console.log(arr.length+'\\n'+arr.join(' '));\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const count = parseInt(input[0], 10)\n let iter = Math.floor(count / 2)\n let ostatok = count - (iter * 2)\n if (ostatok < 2) {\n ostatok += 2\n iter -= 1\n }\n let _res = ''\n for (let a = 0; a < iter; a++) {\n if (_res === '')\n _res = '2'\n else\n _res += ' 2'\n }\n if (_res === '')\n _res += ostatok\n else\n _res += ` ${ostatok}`\n let _iterOstatok = ostatok > 0 ? 1 : 0\n console.log(`${iter + _iterOstatok}\\n${_res}`)\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n if(N % 2 == 0){\n var output = new Array(N / 2).fill(2);\n myout(output.length);\n myout(myconv(output, 8));\n }else{\n var output = new Array(Math.floor(N / 2)).fill(2);\n output[0] = 3;\n myout(output.length);\n myout(myconv(output, 8));\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n let n = +d;\n let count = Math.floor(n / 2);\n\n console.log(count);\n if (n % 2 === 0) {\n console.log(new Array(count).fill(2).join(' '));\n }\n else {\n console.log(new Array(count - 1).fill(2).join(' ') + ' 3');\n }\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nfunction gdc(x, y) {\n let cx = x, cy = y;\n while (cx != 0 && cy != 0) {\n if (cx > cy) cx = cx % cy;\n else cy = cy % cx;\n }\n return cx + cy;\n}\n\nreadLine.on('close', () => {\n let [n] = input[0].split(' ').map(x => parseInt(x));\n\n const answer = [];\n\n for (let i = 0; i < ((n % 2 === 0) ? n / 2 : (n-1) / 2); i += 1)\n answer.push(2);\n \n if (n % 2 !== 0) {\n answer.pop();\n answer.push(3);\n }\n console.log(answer.length);\n console.log(answer.join(' '));\n}); "}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n let n = input[0];\n let answer = '';\n if( n % 2 === 0){\n console.log(`${n/2}`)\n for(let i = 0; i < n/2; i++){\n answer += '2 ';\n }\n } else {\n n -= 3;\n console.log(`${n/2 + 1}`);\n answer = '3 ';\n for(let i = 0; i < n/2; i++){\n answer += '2 ';\n }\n }\n console.log(answer);\n});\n\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let n = +str.trim();\n console.log(Math.floor(n / 2));\n let sum = '';\n if (n % 2 === 0) {\n for (let index = 0; index < Math.floor(n / 2); index++) {\n sum += '2 ';\n }\n }\n else if (n % 2 === 1) {\n for (let index = 0; index < Math.floor(n / 2) - 1; index++) {\n\n sum += '2 ';\n }\n sum += '3';\n }\n console.log(sum);\n\n}\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar result = '';\nif(n % 2 == 0){\n for(var i = 0; i < n/2; i ++) {\n if(i == n/2 - 1){\n result += '2';\n }else {\n result += '2 ';\n }\n\n }\n} else {\n for(var i = 0; i < (n-3)/2; i ++) {\n result += '2 ';\n }\n\n result += '3'\n}\n\nprint(result);"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line1) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n\n var result = [];\n\n while (n > 3) {\n n -= 2;\n result.push(2);\n }\n\n result.push(n);\n\n return result;\n}"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, i, n, readline, ref, results;\n\n readline = function() {\n return '6';\n };\n\n n = Number(readline());\n\n arr = (function() {\n results = [];\n for (var i = 1, ref = (n - n % 2) / 2; 1 <= ref ? i <= ref : i >= ref; 1 <= ref ? i++ : i--){ results.push(i); }\n return results;\n }).apply(this).map(function(x) {\n return '2';\n });\n\n if (n % 2 === 1) {\n arr.push('3');\n }\n\n print(arr.length);\n\n print(arr.join(' '));\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, i, j, n, readline, ref, ref1, results, results1;\n\n readline = function() {\n return '6';\n };\n\n n = Number(readline());\n\n if (n % 2 === 1) {\n arr = (function() {\n results = [];\n for (var i = 1, ref = (n - 3) / 2; 1 <= ref ? i <= ref : i >= ref; 1 <= ref ? i++ : i--){ results.push(i); }\n return results;\n }).apply(this).map(function(x) {\n return '2';\n });\n arr.push(3);\n } else {\n arr = (function() {\n results1 = [];\n for (var j = 1, ref1 = n / 2; 1 <= ref1 ? j <= ref1 : j >= ref1; 1 <= ref1 ? j++ : j--){ results1.push(j); }\n return results1;\n }).apply(this).map(function(x) {\n return '2';\n });\n }\n\n print(arr.length);\n\n print(arr.join(' '));\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var arr, i, j, n, ref, ref1, results, results1;\n\n n = Number(readline());\n\n if (n % 2 === 1) {\n arr = (function() {\n results = [];\n for (var i = 1, ref = (n - 3) / 2; 1 <= ref ? i <= ref : i >= ref; 1 <= ref ? i++ : i--){ results.push(i); }\n return results;\n }).apply(this).map(function(x) {\n return '2';\n });\n arr.push(3);\n } else {\n arr = (function() {\n results1 = [];\n for (var j = 1, ref1 = n / 2; 1 <= ref1 ? j <= ref1 : j >= ref1; 1 <= ref1 ? j++ : j--){ results1.push(j); }\n return results1;\n }).apply(this).map(function(x) {\n return '2';\n });\n }\n\n print(arr.length);\n\n print(arr.join(' '));\n\n}).call(this);\n"}, {"source_code": "var n = Number(readline());\nvar mas=[];\nvar res = 0;\nwhile(n>1){\n\tres++;\n\tif (n-2>1){\n\t\tn-=2;\n\t\tmas.push(2);\n\t\t}\n\telse {\n\t\tmas.push(n)\n\t\tbreak;}\n\t\n}\nprint(res);\nprint(mas);"}, {"source_code": "var main = function(num)\n{\n\tvar arr = [];\n\tif (num % 2 === 0){\n\t\tfor (var i = 1; i <= num / 2; i++)\n\t\t{\n\t\t\tarr.push(2);\n\t\t}\n\t\treturn arr;\n\t}\n\telse\n\t{\n\t\tnum -= 3;\n\t\tif (num > 0)\n\t\tfor (var i = 1; i <= num / 2; i++)\n\t\t{\n\t\t\tarr.push(2);\n\t\t}\n\t\tarr.push(3);\n\t\treturn arr;\n\t}\n}\n\nvar input = +readline();\nprint(main(input));"}, {"source_code": "var main = function(num)\n{\n\tvar del = 2, arr = [];\n\twhile (num !== 1)\n\t{\n\t\tif (num % del === 0) \n\t\t{\n\t\t\tnum /= del;\n\t\t\tarr.push(del);\n\t\t\tdel = 2;\n\t\t}\n\t\telse del++;\n\t}\n\treturn arr;\n}\n\nvar input = +readline();\nprint(main(input));"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const count = parseInt(input[0], 10)\n let iter = Math.floor(count / 2)\n let ostatok = count - (iter * 2)\n if (ostatok < 2) {\n ostatok += 2\n iter -= 1\n }\n let _res = ''\n for (let a = 0; a < iter; a++) {\n if (_res === '')\n _res = '2'\n else\n _res += ' 2'\n }\n if (_res === '')\n _res += ostatok\n else\n _res += ` ${ostatok}`\n console.log(_res)\n})"}], "src_uid": "98fd00d3c83d4b3f0511d8afa6fdb27b"} {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 3) {\n let [n, m] = lines[i].split(' ').map(Number);\n let aTable = lines[i + 1].split(' ').map(Number);\n let bTable = lines[i + 2].split(' ').map(Number);\n let result = 0;\n let lastVisitedIndex = 0;\n bTable.forEach((b, bIndex) => {\n let aIndex = aTable.indexOf(b, lastVisitedIndex);\n if (aIndex < 0) aIndex = 0;\n if (aIndex > lastVisitedIndex && aIndex - bIndex >= 0) {\n result += (aIndex - bIndex) * 2 + 1;\n } else {\n result += 1;\n }\n // console.log('aIndex', aIndex, 'lastVisitedIndex', lastVisitedIndex, 'result', result);\n lastVisitedIndex = Math.max(lastVisitedIndex, aIndex);\n });\n console.log(result);\n }\n});", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = readInt(arr)\n\n for(let i = 0; i < t; i++) {\n const [n, m] = readInts(arr, 3 * i)\n const a = readInts(arr, 3 * i + 1)\n const b = readInts(arr, 3 * i + 2)\n\n const indexes = new Array(100001)\n\n for(let j = 0; j < n; j++) {\n indexes[a[j]] = j\n }\n // wr(a, b, indexes)\n\n let ans = 0, y = -1\n for(let j = 0; j < m; j++) {\n if(indexes[b[j]] > y) {\n ans += 2 * (indexes[b[j]] - j) + 1\n y = indexes[b[j]]\n }\n else ans ++\n }\n\n wr(ans)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n\nfunction mod(a, m) {\n let x = a % m\n if(x >= 0 ) return x\n else return m + x \n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}"}], "negative_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 3) {\n let [n, m] = lines[i].split(' ').map(Number);\n let aTable = lines[i + 1].split(' ').map(Number);\n let bTable = lines[i + 2].split(' ').map(Number);\n let result = 0;\n let lastVisitedIndex = 0;\n bTable.forEach((b, bIndex) => {\n let aIndex = aTable.indexOf(b, lastVisitedIndex);\n if (aIndex > lastVisitedIndex && aIndex - bIndex >= 0) {\n result += (aIndex - bIndex) * 2 + 1;\n } else {\n result += 1;\n }\n // console.log('aIndex', aIndex, 'lastVisitedIndex', lastVisitedIndex, 'result', result);\n lastVisitedIndex = aIndex;\n });\n console.log(result);\n }\n});"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 3) {\n let [n, m] = lines[i].split(' ').map(Number);\n let aTable = lines[i + 1].split(' ').map(Number);\n let bTable = lines[i + 2].split(' ').map(Number);\n let result = 0;\n let lastVisitedIndex = 0;\n bTable.forEach((b, bIndex) => {\n let aIndex = aTable.indexOf(b, lastVisitedIndex);\n if (aIndex === -1) aIndex = 0;\n if (aIndex > lastVisitedIndex && aIndex - bIndex >= 0) {\n result += (aIndex - bIndex) * 2 + 1;\n } else {\n result += 1;\n }\n // console.log('aIndex', aIndex, 'lastVisitedIndex', lastVisitedIndex, 'result', result);\n lastVisitedIndex = aIndex;\n });\n console.log(result);\n }\n});"}], "src_uid": "ad434880e047992d2c77e0fe0ce0976f"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let mat = new Array(n);\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(m);\n dp[i].fill(0);\n }\n\n for(let i = 0; i < n; i++){\n mat[i] = ti(readline().split(' '));\n }\n\n let len = n+m-2;\n let level = 0;\n let q = [[0,0],[n-1,m-1],null];\n let count = 0;\n let c1 = 0;\n let c0 = 0;\n let isValid = (r,c) => {\n if(r < 0 || r >= n || c < 0 || c >= m) return false;\n if(dp[r][c] === 1) return false;\n return true;\n }\n \n while(q.length > 0){\n let node = q.shift();\n if(node !== null){\n dp[node[0]][node[1]] = 1;\n if(mat[node[0]][node[1]] === 0) c0+=1;\n if(mat[node[0]][node[1]] === 1) c1+=1;\n if(isValid(node[0]+1, node[1])){\n dp[node[0]+1][node[1]] = 1;\n q.push([node[0]+1,node[1]]);\n }\n if(isValid(node[0], node[1]+1)){\n dp[node[0]][node[1]+1] = 1;\n q.push([node[0],node[1]+1]);\n }\n if(isValid(node[0]-1,node[1])){\n dp[node[0]-1][node[1]] = 1;\n q.push([node[0]-1, node[1]]);\n }\n if(isValid(node[0], node[1]-1)){\n dp[node[0]][node[1]-1] = 1;\n q.push([node[0], node[1]-1]);\n }\n }else{\n if(level !== Math.ceil(len/2)){\n if(c1 !== 0 && c0 !== 0)\n count += Math.min(c1,c0);\n }\n level += 1;\n c1 = c0 = 0;\n if(q.length !== 0)\n q.push(null);\n }\n }\n\n console.log(count);\n }\n}", "positive_code": [{"source_code": "\nfunction solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n var x = ip[0]\n var y = ip[1]\n var s = []\n for (var n = 0; n < x; n++) {\n s.push(readline().split(' ').map(x => parseInt(x)))\n }\n var res = 0;\n\n var v1 = new Array(x + y);\n var v2 = new Array(x + y);;\n v1.fill(0)\n v2.fill(0)\n for (var n = 0; n < x; n++) {\n for (var k = 0; k < y; k++) {\n if (s[n][k] == 1) {\n if (v1[n + k] == null) v1[n + k] = 1\n else v1[n + k]++;\n }\n else {\n if (v2[n + k] == null) v2[n + k] = 1\n else v2[n + k]++;\n }\n }\n }\n var len = x + y - 2;\n var j = (x % 2 == y % 2)\n for (var n = 0; n <= Math.floor((len) / 2) - j; n++) {\n if (n != len - n) {\n res += Math.min(v1[n] + v1[len - n], v2[n] + v2[len - n]);\n var d = v1[n] + v1[len - n]\n var e = v2[n] + v2[len - n]\n }\n else res += Math.min(v1[n], v2[n]);\n }\n\n print(res)\n}\n\nvar tc = 1;\ntc = parseInt(readline())\nwhile (tc--) solv()"}, {"source_code": "// var lineIdx = 0;\n// var readline = () => {\n// var input = [\"4\", \"2 2\", \"1 1\", \"0 1\", \"2 3\", \"1 1 0\", \"1 0 0\", \"3 7\", \"1 0 1 1 1 1 1\", \"0 0 0 0 0 0 0\", \"1 1 1 1 1 0 1\", \"3 5\", \"1 0 1 0 0\", \"1 1 1 1 0\", \"0 0 1 0 0\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar t = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n\nvar step = () => {\n var input = readline().split(\" \").map(function(x) { return parseInt(x); });\n var n = input[0];\n var m = input[1];\n\n var matrix = new Array();\n\n for(var i = 0; i parseInt(x))\n var x = ip[0]\n var y = ip[1]\n var s = []\n for (var n = 0; n < x; n++) {\n s.push(readline().split(' ').map(x => parseInt(x)))\n }\n var res = 0;\n\n var v1 = new Array(x + y);\n var v2 = new Array(x + y);;\n v1.fill(0)\n v2.fill(0)\n for (var n = 0; n < x; n++) {\n for (var k = 0; k < y; k++) {\n if (s[n][k] == 1) {\n if (v1[n + k] == null) v1[n + k] = 1\n else v1[n + k]++;\n }\n else {\n if (v2[n + k] == null) v2[n + k] = 1\n else v2[n + k]++;\n }\n }\n }\n var len = x + y - 2;\n var j = (x % 2 == y % 2)\n for (var n = 0; n <= Math.floor((len) / 2) - j; n++) {\n if (n != len - n) {\n res += Math.min(v1[n] + v1[len - n], v2[n] + v2[len - n]);\n var d = v1[n] + v1[len - n]\n var e = v2[n] + v2[len - n]\n }\n else res += Math.min(v1[n], v2[n]);\n }\n\n print(res)\n}\n\nvar tc = 1;\ntc = parseInt(readline())\nwhile (tc--) solv()"}], "negative_code": [], "src_uid": "b62586b55bcfbd616d936459c30579a6"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tconst cost = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tlet cur = b[i];\r\n\t\t\twhile (cur > 0 && cost[cur] == undefined) {\r\n\t\t\t\tcost[cur] = i; \r\n\t\t\t\tcur--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet ans = 1e9;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans = Math.min(ans, i + cost[a[i]]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift()(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift())\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let iii = 0; iii < t; ++iii) {\r\n let n = +await nextString()\r\n let mas1 = (await nextString()).split(' ').map(x => +x)\r\n let mas2 = (await nextString()).split(' ').map(x => +x)\r\n let a = [[mas1[0], 0]]\r\n let b = [[mas2[0], 0]]\r\n for (let i = 1; i < n; ++i) {\r\n if (mas1[i] < a[a.length - 1][0]) {\r\n a.push([mas1[i], i])\r\n }\r\n if (mas2[i] > b[b.length - 1][0]) {\r\n b.push([mas2[i], i])\r\n }\r\n }\r\n let ans = +Infinity\r\n n = a.length - 1\r\n m = 0\r\n while (n >= 0 && m < b.length) {\r\n ans = Math.min(ans, a[n][1] + b[m][1])\r\n if (n > 0 && a[n - 1][0] < b[m][0]) {\r\n --n\r\n }\r\n else {\r\n ++m\r\n }\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n \r\nmain()\r\n\r\n\r\n/*\r\n3\r\n2\r\n3 1\r\n4 2\r\n3\r\n5 3 1\r\n2 4 6\r\n5\r\n7 5 9 1 3\r\n2 4 6 10 8\r\n*/"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet i = 0;\r\n\t\twhile (a[i] > b[0]) i++;\r\n\r\n\t\tlet j = 0;\r\n\t\twhile (b[j] < a[0]) j++;\r\n\r\n\t\tans = Math.min(i, j);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "55a1e9236cac9a6044e74b1975331535"} {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar v = readline().split(' ').map(Number);\n\n\t\tvar v_type1 = [0];\n\t\tfor (var i = 0; i < n; i++) v_type1.push(v_type1[i] + v[i]);\n\n\t\tv = v.sort(function (a, b) { return a - b; });\n\t\tvar v_type2 = [0];\n\t\tfor (var i = 0; i < n; i++) v_type2.push(v_type2[i] + v[i]);\n\n\t\tvar m = +readline();\n\n\t\tvar questions = [];\n\t\twhile (m--) {\n\t\t\tquestions.push(readline().split(' ').map(Number));\n\t\t} m = questions.length;\n\n\t\treturn questions.map(function (e) {\n\t\t\treturn e[0] === 1 ? (v_type1[e[2]] - v_type1[e[1] - 1]) : (v_type2[e[2]] - v_type2[e[1] - 1]);\n\t\t}).join('\\n');\n\n\t}(+readline()));\n\n}.call(this));\n", "positive_code": [{"source_code": "var lenArr = readline().split(' ').map(Number);\nvar ArrNormal = readline().split(' ').map(Number);\nvar numQue = readline().split(' ').map(Number);\nvar queArr = [];\nvar sumArrN = [];\nvar sumArrS = [];\nvar ArrSort = ArrNormal.slice().sort(function(a,b){return a-b;});\nsumArrN[0] = ArrNormal[0];\nsumArrS[0] = ArrSort[0];\nfor (var t=1; t=0 && index2-1 >=0){\n\t\treturn arr[index2-1] - arr[index1-2];\n\t}\n\telse{\n\t\treturn arr[index2-1];\n\t}\n}\n// Acquiring the input\nvar discard = readline();\nvar arr2 = readline().split(' ').map((val)=>{\n\treturn parseInt(val);\n}), arr1 = [...arr2], sum1 = 0;\nvar questions = parseInt(readline());\n// Preprocessing\narr2.sort((a,b)=>{return a-b}).reduce((sum2,val,index,arr2)=>{\n\tsum1+=arr1[index];\n\tarr1[index] = sum1;\n\tsum2 += arr2[index];\n\tarr2[index] = sum2;\n\treturn sum2;\n},0)\n// Answering queries\nfor(var i = 0 ; i < questions; i++){\n\tvar info = readline().split(' ').map((val)=>{\n\t\treturn parseInt(val);\n\t})\n\tif (info[0] == 1){\n\t\tprint(check(info[1],info[2],arr1));\n\t}\n\telse{\n\t\tprint(check(info[1],info[2],arr2));\n\t}\n}\n\n\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tstones = tokenizeIntegers(readline()), sorted = new Array(n),\n\t\tsumStones = [0], sumSorted = [0],\n\t\tqNum = parseInt(readline());\n\tfor (var i = 0; i < n; ++i) {\n\t\tsorted[i] = stones[i];\n\t}\n\tsorted.sort(function (a, b) {\n\t\treturn a-b;\n\t});\n\tfor (var i = 0; i < n; ++i) {\n\t\tsumStones.push(sumStones[i]+stones[i]);\n\t\tsumSorted.push(sumSorted[i]+sorted[i]);\n\t}\n\tfor (var i = 0; i < qNum; ++i) {\n\t\tvar query = tokenizeIntegers(readline());\n\t\tif (query[0] == 1) {\n\t\t\tprint(sumStones[query[2]]-sumStones[query[1]-1]);\n\t\t} else {\n\t\t\tprint(sumSorted[query[2]]-sumSorted[query[1]-1]);\n\t\t}\n\t}\n}\n\nmain();\n"}, {"source_code": "var n = parseInt(readline()),\n\tvArr = readline().split(/\\s/), vSum = getCumulativeSum(vArr),\n\tuArr = vArr.sort(function(a, b)\t{ return a - b }), uSum = getCumulativeSum(uArr),\n\tm = parseInt(readline());\n\nfor(var index = 0; index < m; index++)\t{\n\tvar inputs = readline().split(/\\s/).map(Number),\n\t\ttype = inputs[0], l = inputs[1], r = inputs[2];\n\n\tprint(type == 1 ? vSum[r] - vSum[l - 1] : uSum[r] - uSum[l - 1]);\n}\n\nfunction getCumulativeSum(arr)\t{\n\tvar cumulativeSum = [ 0 ];\n\n\tarr = arr.map(function(a, index)\t{\n\t\ta = parseInt(a);\n\n\t\tcumulativeSum.push(cumulativeSum[cumulativeSum.length - 1] + a);\n\n\t\treturn a;\n\t});\n\n\treturn cumulativeSum;\n};"}, {"source_code": "const lines = [];\n\nconst helpers = {\n arrStringtoInt: (arr, splitter) => {\n return arr.split(splitter).map(num => parseInt(num));\n },\n insterAt: (arr, idx, item) => {\n const newArray = [...arr];\n newArray.splice(idx, 0, item);\n return newArray;\n },\n sortAscending: (arr) => {\n return arr.sort((a, b) => a - b);\n },\n sortDescending(arr) {\n return arr.sort((a, b) => b - a);\n }\n}\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// multi line input\nreadline.on('line', line => {\n lines.push(line);\n});\n\nreadline.on('close', line => {\n const numbers = helpers.arrStringtoInt(lines[1], ' ');\n const rangeSum1 = [0];\n const rangeSum2 = [0];\n\n\n // Get the first range sum of type 1 O(n)\n for (let ii = 0; ii < numbers.length; ii++) {\n rangeSum1.push(numbers[ii] + rangeSum1[ii]);\n }\n\n // O(nlogn)\n numbers.sort((a, b) => a - b);\n\n // Get the first range sum of type 2 O(n)\n for (let ii = 0; ii < numbers.length; ii++) {\n rangeSum2.push(numbers[ii] + rangeSum2[ii]);\n }\n\n\n // Answer the questions in O(m);\n for (let ii = 3; ii < lines.length; ii++) {\n const inputs = helpers.arrStringtoInt(lines[ii], ' ');\n const t = inputs[0], l = inputs[1], r = inputs[2];\n const arr = t == 1 ? rangeSum1 : rangeSum2;\n console.log(arr[r] - arr[l - 1])\n }\n});\n"}, {"source_code": "/**\n * \nKuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. \nThe cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:\n\nShe will tell you two numbers, l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n), and you should tell her .\nLet ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). \nThis time she will tell you two numbers, l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n), and you should tell her .\nFor every question you should give the correct answer, or Kuriyama Mirai will say \"fuyukai desu\" and then become unhappy.\n\nInput\nThe first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105). The second line contains n integers: v1,\u2009v2,\u2009...,\u2009vn (1\u2009\u2264\u2009vi\u2009\u2264\u2009109) \u2014 costs of the stones.\n\nThe third line contains an integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009105) \u2014 the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type,\n l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n; 1\u2009\u2264\u2009type\u2009\u2264\u20092), describing a question. If type equal to 1, then you should output the answer for the first question, \n else you should output the answer for the second one.\n\nOutput\nPrint m lines. Each line must contain an integer \u2014 the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.\n\n[ 6, 10, 12, 19, 21, 28 ]\n\n[ 2, 4, 8, 14, 21, 28 ]\n\nExamples\ninput\n6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\noutput\n24\n9\n28\ninput\n4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\noutput\n10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n */\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let lenthOfInput = Number(inputString[0])\n let input = inputString[1].split(\" \");\n let lengthOfQuestion = Number(inputString[2])\n let questions = inputString.slice(3)\n\n solution(lenthOfInput, input, lengthOfQuestion, questions);\n\n});\n\nfunction solution(lenthOfInput, input, lengthOfQuestion, questions) {\n\n\n let perfixSum = [];\n let sortedPerfixSum = [];\n let solutionArray = [];\n\n for (let index = 0; index < lenthOfInput; index++) {\n\n perfixSum[index] = (perfixSum[index - 1] ? perfixSum[index - 1] : 0) + Number(input[index])\n }\n\n input.sort(function (current, next) {\n return current - next;\n })\n\n for (let index = 0; index < lenthOfInput; index++) {\n\n sortedPerfixSum[index] = (sortedPerfixSum[index - 1] ? sortedPerfixSum[index - 1] : 0) + Number(input[index])\n }\n\n\n for (let index = 0; index < lengthOfQuestion; index++) {\n\n let question = Number(questions[index].split(\" \")[0]);\n let left = Number(questions[index].split(\" \")[1])\n let right = Number(questions[index].split(\" \")[2])\n let solution;\n\n if (question == 1)\n\n solution = perfixSum[right - 1] - (perfixSum[left - 2] ? perfixSum[left - 2] : 0)\n else\n solution = sortedPerfixSum[right - 1] - (sortedPerfixSum[left - 2] ? sortedPerfixSum[left - 2] : 0)\n\n solutionArray.push(solution);\n solutionArray.push(\"\\n\")\n\n }\n\n console.log(solutionArray.join(\"\"))\n\n}"}, {"source_code": "/**\n * \nKuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. \nThe cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:\n\nShe will tell you two numbers, l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n), and you should tell her .\nLet ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). \nThis time she will tell you two numbers, l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n), and you should tell her .\nFor every question you should give the correct answer, or Kuriyama Mirai will say \"fuyukai desu\" and then become unhappy.\n\nInput\nThe first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009105). The second line contains n integers: v1,\u2009v2,\u2009...,\u2009vn (1\u2009\u2264\u2009vi\u2009\u2264\u2009109) \u2014 costs of the stones.\n\nThe third line contains an integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009105) \u2014 the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type,\n l and r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009n; 1\u2009\u2264\u2009type\u2009\u2264\u20092), describing a question. If type equal to 1, then you should output the answer for the first question, \n else you should output the answer for the second one.\n\nOutput\nPrint m lines. Each line must contain an integer \u2014 the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.\n\n[ 6, 10, 12, 19, 21, 28 ]\n\n[ 2, 4, 8, 14, 21, 28 ]\n\nExamples\ninput\n6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\noutput\n24\n9\n28\ninput\n4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\noutput\n10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n */\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let lenthOfInput = Number(inputString[0])\n let input = inputString[1].split(\" \");\n let lengthOfQuestion = Number(inputString[2])\n let questions = inputString.slice(3)\n\n solution(lenthOfInput, input, lengthOfQuestion, questions);\n\n});\n\nfunction solution(lenthOfInput, input, lengthOfQuestion, questions) {\n\n\n let perfixSum = [];\n let sortedPerfixSum = [];\n let solutionArray = [];\n\n for (let index = 0; index < lenthOfInput; index++) {\n\n perfixSum[index] = (perfixSum[index - 1] ? perfixSum[index - 1] : 0) + Number(input[index])\n }\n\n input.sort(function (current, next) {\n return current - next;\n })\n\n for (let index = 0; index < lenthOfInput; index++) {\n\n sortedPerfixSum[index] = (sortedPerfixSum[index - 1] ? sortedPerfixSum[index - 1] : 0) + Number(input[index])\n }\n\n\n for (let index = 0; index < lengthOfQuestion; index++) {\n\n let question = Number(questions[index].split(\" \")[0]);\n let left = Number(questions[index].split(\" \")[1])\n let right = Number(questions[index].split(\" \")[2])\n let solution;\n\n if (question == 1)\n\n solution = perfixSum[right - 1] - (perfixSum[left - 2] ? perfixSum[left - 2] : 0)\n else\n solution = sortedPerfixSum[right - 1] - (sortedPerfixSum[left - 2] ? sortedPerfixSum[left - 2] : 0)\n\n solutionArray.push(solution);\n solutionArray.push(\"\\n\")\n\n }\n\n console.log(solutionArray.join(\"\"));\n\n}"}], "negative_code": [{"source_code": "var lenArr = readline().split(' ').map(Number); //\u043a-\u0441\u0442\u044c \u043a\u0430\u043c\u0435\u043d\u0456\u0432\nvar ArrNormal = readline().split(' ').map(Number); //\u043c\u0430\u0441\u0438\u0432 \u0437 \u0446\u0456\u043d\u0430\u043c\u0438 \u043a\u0430\u043c\u0435\u043d\u0456\u0432\nvar numQue = readline().split(' ').map(Number); //\u043a-\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0442\u0430\u043d\u044c\nvar queArr = []; //\u043f\u0443\u0441\u0442\u0438\u0439 \u043c\u0430\u0441\u0438\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0442\u0430\u043d\u044c\nvar ArrSort = ArrNormal.slice().sort(); //\u0432\u0456\u0434\u0441\u043e\u0440\u0442\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u0430\u0441\u0438\u0432\nfor (var i=0; i {\n return arr.split(splitter).map(num => parseInt(num));\n },\n insterAt: (arr, idx, item) => {\n const newArray = [...arr];\n newArray.splice(idx, 0, item);\n return newArray;\n },\n sortAscending: (arr) => {\n return arr.sort((a, b) => a - b);\n },\n sortDescending(arr) {\n return arr.sort((a, b) => b - a);\n }\n}\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// multi line input\nreadline.on('line', line => {\n lines.push(line);\n});\n\nreadline.on('close', line => {\n const numbers = helpers.arrStringtoInt(lines[1], ' ');\n const rangeSum1 = [0];\n const rangeSum2 = [0];\n\n\n for (let ii = 0; ii < numbers.length; ii++) {\n rangeSum1.push(numbers[ii] + rangeSum1[ii]);\n }\n\n numbers.sort((a, b) => b - a);\n\n for (let ii = 0; ii < numbers.length; ii++) {\n rangeSum2.push(numbers[ii] + rangeSum2[ii]);\n }\n\n\n // // Calculate the range sum\n for (let ii = 3; ii < lines.length; ii++) {\n const inputs = helpers.arrStringtoInt(lines[ii], ' ');\n const t = inputs[0];\n const l = inputs[1];\n const r = inputs[2];\n if (t == 1)\n console.log(answer(rangeSum1, l, r))\n else\n console.log( rangeSum2[r-l+1])\n }\n\n\n});\n\nfunction answer(arr, l, r) {\n return arr[r] - arr[l - 1];\n}\n"}], "src_uid": "c764b9f87cb5e5872eb157c3d2b7f3c5"} {"source_code": "/**\r\n * 04/19/21 morning\r\n * https://codeforces.com/contest/1514/problem/A\r\n */\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n // pr(n,a);\r\n for (const e of a) {\r\n let q = sq(e);\r\n if (q != q >> 0) return pr('YES');\r\n }\r\n pr('NO')\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const a = readLine().split(' ').map(Number);\r\n\r\n let end = true;\r\n for(let i = 0; i < n; i++){\r\n if(!Number.isInteger(Math.sqrt(a[i]))){\r\n console.log('YES');\r\n end = false;\r\n break;\r\n }\r\n }\r\n if(end) console.log('NO')\r\n }\r\n});\r\n\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction A(a){\r\n return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));\r\n}\r\n \r\nmodule.exports = A;"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var found = false;\n for(var l = 0; l < k.length; l++){\n var a = Math.floor(Math.sqrt(k[l]));\n if(a * a != k[l]){\n found = true;\n break;\n }\n }\n if(found === true){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var j = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = input[j];\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n function isSquareNumber(num) {\r\n var root = Math.sqrt(num)\r\n return root === Math.floor(root);\r\n }\r\n var i;\r\n \r\n for (i = 0; i < arr.length; i++) {\r\n if (!isSquareNumber(arr[i])) {\r\n break;\r\n }\r\n }\r\n if (i === arr.length) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n})"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var found = false;\n for(var l = 0; l < k.length; l++){\n var a = Math.floor(Math.sqrt(k[l]));\n if(a * a != k[l]){\n found = true;\n break;\n }\n }\n if(found === true){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "\"use strict\";\n//////////// LIBS\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift().trim();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction solve(n, tab) {\n for (let a of tab) {\n if (Math.floor(Math.sqrt(a)) ** 2 !== a) {\n console.log('YES');\n return;\n }\n }\n console.log('NO');\n}\nfunction main() {\n const io = new IO();\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let tab = io.nextNumArray(n);\n solve(n, tab);\n }\n}\nmain();\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = false;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] == 1){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar map = getPrimeFactorization(list[j]);\r\n\t\t\tvar keys = Object.keys(map);\r\n\t\t\tfor(var k = 0; k < keys.length; k++){\r\n\t\t\t\tif(map[keys[k]] % 2 == 1){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\nfunction getPrimeFactorization(val){\r\n var primeMap = {};\r\n var div = 2;\r\n if(isPrime(val)){\r\n primeMap[val] = 1;\r\n return primeMap;\r\n }\r\n while(val != 1){\r\n if(val % div == 0){\r\n var count = 2;\r\n while(val % Math.pow(div, count) == 0){\r\n count++;\r\n }\r\n (primeMap[div] == null) ? primeMap[div] = (count - 1) : primeMap[div] += (count - 1);\r\n val /= Math.pow(div, count - 1);\r\n if(isPrime(val)){\r\n (primeMap[val] == null) ? primeMap[val] = 1 : primeMap[val]++;\r\n break;\r\n }\r\n }\r\n div = (div == 2) ? div + 1 : div + 2;\r\n }\r\n return primeMap;\r\n}\r\nfunction isPrime(val){\r\n if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\r\n return false;\r\n }else if(val == 2){\r\n return true;\r\n }\r\n var root = Math.floor(Math.sqrt(val));\r\n for(var i = 3; i <= root; i += 2){\r\n if(val % i == 0){\r\n return false;\r\n }\r\n }\r\n return true;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [a, b] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n for (let j = 0; j < n; j++) {\r\n var res = Math.floor(Math.sqrt(a[j]))\r\n if(res *res !==a[j]) return console.log('YES')\r\n }\r\n console.log('NO')\r\n // var aa = a.slice()\r\n // a.sort((a, b) => a - b)\r\n //\r\n // dp = new Array(n + 1)\r\n // for (let i = 0; i < n + 1; i++) {\r\n // dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)\r\n // }\r\n\r\n })\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const a = readLine().split(' ').map(Number);\r\n\r\n for(let i = 0; i < n; i++){\r\n if(!Number.isInteger(Math.sqrt(a[i]))){\r\n console.log('YES');\r\n }\r\n }\r\n console.log('NO')\r\n }\r\n});\r\n\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction A(a){\r\n return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));\r\n}\r\n \r\nmodule.exports = A;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const a = readLine().split(' ').map(Number);\r\n\r\n A(a) ? console.log('NO'): console.log('YES');\r\n }\r\n});\r\n\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction A(a){\r\n return Number.isInteger(Math.sqrt(a.reduce((a,b) => a*b)));\r\n}\r\n \r\nmodule.exports = A;"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var total = k[0];\n for(var l = 1; l < k.length; l++){\n total *= k[l];\n }\n total = Math.sqrt(total);\n if(total % 1 !== 0){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var j = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = input[j];\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n function isSquareNumber(num) {\r\n return Math.sqrt(num) ** 2 === num;\r\n }\r\n var i;\r\n for (i = 0; i < arr.length; i++) {\r\n if (!isSquareNumber(arr[i])) {\r\n break;\r\n }\r\n }\r\n if (i === arr.length) {\r\n console.log(\"NO\");\r\n } else {\r\n console.log(\"YES\");\r\n }\r\n }\r\n})"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, a, b, ans = false;\n\nfunction isPrime(num) {\n for (var i = 2; i < num; i++)\n if(num % i === 0) return false;\n return num > 1;\n}\n\n\nn = Number(readline());\na = n + 2;\nb = 2;\n\nwhile (!ans) {\n\n if (!isPrime(a) && !isPrime(b)) {\n\n ans = true;\n break\n } else {\n\n a++;\n b++;\n }\n}\n\nprint(`${a} ${b}`)", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nreadline.on('line', line => {\n let num = Number(line);\n if (num === 1) return console.log(`9 8`);\n console.log(`${(num * 2) + num} ${num * 2}`);\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),1);\n var a = N + 1;\n while(isPrime(a)){\n a++;\n }\n var b = a + N;\n while(isPrime(a) || isPrime(b)){\n a++;\n b++;\n }\n myout(b + \" \" + a);\n}\nfunction isPrime(val){\n if(val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}\nMain();\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i ++) {\n doit(txt[i] * 1);\n}\n\nfunction doit(num) {\n let max=num*2,min=num;\n while (true) { \n if(check(max) &&check(min)){\n console.log(max,min);\n break;\n }else{\n ++max;\n ++min;\n }\n }\n}\nfunction check(num){\n for (let i = 2; i < num/2; i++) {\n if(num%i===0)return true;\n \n }\n return false;\n}"}, {"source_code": "var T = parseInt(readline());\nprint(T * 9 + ' ' + T * 8);"}, {"source_code": "var a = parseInt(readline());\n\nvar c = (a + 2) * 3;\nvar b = c - a;\n\nprint(c, b);"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr[0])\n let a, b\n if(n % 2 == 1) {\n a = n + 9\n b = 9\n }\n else {\n a = n + 4\n b = 4\n }\n wr(a, b)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n\n if (n % 2 === 0) {\n console.log(n + 10, 10);\n }\n else {\n console.log(n + 9, 9);\n }\n});\n"}], "negative_code": [{"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),1);\n var a = N + 1;\n if(isPrime(a)){\n a++;\n }\n var b = a + N;\n while(isPrime(b)){\n b++;\n }\n myout(b + \" \" + a);\n}\nfunction isPrime(val){\n if(val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}\nMain();\n"}, {"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),1);\n var a = N + 1;\n while(isPrime(a)){\n a++;\n }\n var b = a + N;\n while(isPrime(b)){\n a++;\n b++;\n }\n myout(b + \" \" + a);\n}\nfunction isPrime(val){\n if(val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}\nMain();\n"}, {"source_code": "function myout(t){print(t);}//standard output\nfunction myerr(t){console.error(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n\nfunction Main() {\n var N = myconv(readline(),1);\n var a = N + 1;\n if(isPrime(a)){\n a++;\n }\n var b = a + N;\n while(isPrime(b)){\n b++;\n }\n myout(a + \" \" + b);\n}\nfunction isPrime(val){\n if(val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}\nMain();\n"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar n, a, b, ans = false;\n\nfunction isPrime(num) {\n for (var i = 2; i < num; i++)\n if(num % i === 0) return false;\n return num > 1;\n}\n\n\nn = Number(readline());\na = n + 1;\nb = 1;\n\nwhile (!ans) {\n\n if (!isPrime(a) && !isPrime(b)) {\n\n ans = true;\n break\n } else {\n\n a++;\n b++;\n }\n}\n\nprint(`${a} ${b}`)"}, {"source_code": "var k = parseInt(readline());\nprint(k*5 +' '+ k*4);"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nreadline.on('line', line => {\n let num = Number(line);\n if (num === 1) return console.log(`8 9`);\n console.log(`${num * 2} ${(num * 2) + num}`);\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nreadline.on('line', line => {\n let num = Number(line);\n if (num === 1) console.log(`8 9`);\n console.log(`${num * 2} ${(num * 2) + num}`);\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}], "src_uid": "59d5e5ed2bc4b316e950e2a4dbc99d68"} {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction getDividers(max) {\n const ret = [];\n for (let i = 1; i <= max; i++) {\n ret[i] = [];\n }\n for (let i = 2; i <= max; i++) {\n if (!ret[i].length) {\n for (let j = i; j <= max; j += i) {\n ret[j].push(i);\n }\n }\n }\n return ret;\n}\nfunction solve(tab, queries) {\n let dividers = getDividers(100000);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n let factors = dividers[val];\n let nextIndex = n;\n for (let factor of factors) {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n }\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n up[i][k] = up[parent][k - 1];\n }\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 19; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n", "positive_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction getDividers(max) {\n const ret = [];\n for (let i = 1; i <= max; i++) {\n ret[i] = [];\n }\n for (let i = 2; i <= max; i++) {\n if (!ret[i].length) {\n for (let j = i; j <= max; j += i) {\n ret[j].push(i);\n }\n }\n }\n return ret;\n}\nfunction solve(tab, queries) {\n // let primes = sieve(100000);\n let dividers = getDividers(100000);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n // console.log(getDividers(40).map((x, i) => [i, x]));\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n // const factors = getPrimeFactors(val, primes);\n let factors = dividers[val];\n let nextIndex = n;\n factors.forEach((factor) => {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n });\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n up[i][k] = up[parent][k - 1];\n }\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 19; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}], "negative_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction getDividers(max) {\n const ret = [];\n for (let i = 2; i <= max; i++) {\n ret[i] = [];\n }\n for (let i = 2; i <= max; i++) {\n if (!ret[i].length) {\n for (let j = i; j <= max; j += i) {\n ret[j].push(i);\n }\n }\n }\n return ret;\n}\nfunction solve(tab, queries) {\n // let primes = sieve(100000);\n let dividers = getDividers(100000 + 2);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n // console.log(getDividers(40).map((x, i) => [i, x]));\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n // const factors = getPrimeFactors(val, primes);\n let factors = dividers[val];\n let nextIndex = n;\n factors.forEach((factor) => {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n });\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n up[i][k] = up[parent][k - 1];\n }\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 19; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction getDividers(max) {\n const ret = [];\n for (let i = 2; i <= max; i++) {\n ret[i] = [];\n }\n for (let i = 2; i <= max; i++) {\n if (!ret[i].length) {\n for (let j = i; j <= max; j += i) {\n ret[j].push(i);\n }\n }\n }\n return ret;\n}\nfunction solve(tab, queries) {\n // let primes = sieve(100000);\n let dividers = getDividers(100000);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n // console.log(getDividers(40).map((x, i) => [i, x]));\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n // const factors = getPrimeFactors(val, primes);\n let factors = dividers[val];\n let nextIndex = n;\n factors.forEach((factor) => {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n });\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n up[i][k] = up[parent][k - 1];\n }\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 19; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction solve(tab, queries) {\n let primes = sieve(10000);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n const factors = getPrimeFactors(val, primes);\n let nextIndex = n;\n factors.forEach((factor) => {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n });\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n up[i][k] = up[parent][k - 1];\n }\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 19; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction sieve(max) {\n let arr = [];\n for (let i = 2; i <= max; i++) {\n arr[i] = 1;\n }\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n for (let j = 2 * i; j <= max; j += i) {\n arr[j] = 0;\n }\n }\n }\n let ret = [];\n for (let i = 2; i <= max; i++) {\n if (arr[i]) {\n ret.push(i);\n }\n }\n return ret;\n}\nfunction getPrimeFactors(val, primes) {\n let ret = [];\n for (let j = 0; j < primes.length && val >= primes[j]; j++) {\n let p = primes[j];\n if (val % p == 0) {\n ret.push(p);\n }\n }\n return ret;\n}\nfunction hasSortedIntersection(tab1, tab2) {\n let i = 0;\n let j = 0;\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 === v2) {\n return true;\n }\n if (v1 < v2) {\n i++;\n }\n else {\n j++;\n }\n }\n return false;\n}\n// console.log(hasSortedIntersection([1, 4, 5, 9], [1, 2, 2]));\nfunction mergeSorted(tab1, tab2) {\n let i = 0;\n let j = 0;\n let ret = [];\n while (i < tab1.length && j < tab2.length) {\n let v1 = tab1[i];\n let v2 = tab2[j];\n if (v1 < v2) {\n ret.push(v1);\n i++;\n }\n else {\n ret.push(v2);\n j++;\n }\n }\n ret.push(...tab1.slice(i), ...tab2.slice(j));\n return ret;\n}\nfunction solve(tab, queries) {\n let primes = sieve(10000);\n // console.log(primes);\n let n = tab.length;\n let up = Array.from({ length: n + 1 }).map(() => []);\n let next = [];\n up[n][0] = n;\n for (let i = n - 1; i >= 0; i--) {\n let val = tab[i];\n const factors = getPrimeFactors(val, primes);\n let nextIndex = n;\n factors.forEach((factor) => {\n if (next[factor]) {\n nextIndex = Math.min(nextIndex, next[factor]);\n }\n next[factor] = i;\n });\n up[i][0] = Math.min(nextIndex, up[i + 1][0]);\n // console.log({ i, nextIndex, ranges: up, next, factors });\n }\n for (let k = 1; k < 20; k++) {\n for (let i = 0; i <= n; i++) {\n let parent = up[i][k - 1];\n // console.log({ i, k, parent });\n up[i][k] = up[parent][k - 1];\n }\n let ret = [];\n for (let i = 0; i <= n; i++) {\n ret.push(up[i][k]);\n }\n // console.log({ k, ret });\n // console.log(up);\n }\n queries.forEach(([l, r]) => {\n l--;\n r--;\n let ret = 1;\n for (let k = 20; k >= 0; k--) {\n if (up[l][k] <= r) {\n l = up[l][k];\n ret += 1 << k;\n }\n }\n io.writeLine(ret);\n });\n // console.log(up);\n // let prevFactors: number[] = [];\n // let currentFactors: number[] = [];\n // let n = tab.length;\n // ranges[n] = n + 1;\n // for (let i = n - 1; i >= 0; i--) {\n // let val = tab[i];\n // const factors = getPrimeFactors(val, primes);\n // }\n // for (let i = 0; i < tab.length; i++) {\n // let val = tab[i];\n // const factors = getPrimeFactors(val, primes);\n // // console.log({ i, val, factors, prevFactors });\n // if (prevFactors.length && !hasSortedIntersection(prevFactors, factors)) {\n // // console.log('----');\n // ranges.push(i + 1);\n // }\n // prevFactors = mergeSorted(prevFactors, factors);\n // }\n // console.log(ranges);\n // for (let [l, r] of queries) {\n // l--;\n // r--;\n // let lower = upperBound(ranges, l);\n // console.log('----');\n // console.log({\n // lower_l: lowerBound(ranges, l),\n // upper_l: upperBound(ranges, l),\n // lower_r: lowerBound(ranges, r),\n // upper_r: upperBound(ranges, r),\n // });\n // let upper = upperBound(ranges, r);\n // console.log({ l, r, lower, upper });\n // io.writeLine(upper - lower + 1);\n // }\n // console.log(ranges);\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let q = io.nextNum();\n let tab = io.nextNumArray(n);\n let queries = [];\n while (q--) {\n queries.push([io.nextNum(), io.nextNum()]);\n }\n solve(tab, queries);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}], "src_uid": "59e45a82cdafd64e0bf2a199cb08bbb9"} {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n\n\n var x = read.number();\n var x2b = x.toString(2);\n var res = [];\n var t = 0;\n while(x2b.indexOf(0) !== -1) {\n if(t%2==0) {\n x2b = x2b.replace(/^0+/, '');\n x2b = ((+('0b' +x2b))^((Math.pow(2, x2b.length))-1)).toString(2);\n res.push(x2b.length);\n }\n else {\n x2b = (+('0b' + x2b) + 1).toString(2)\n }\n t++;\n }\n\n print(t);\n if(res.length)\n print(res.join(' '));\n}());\n", "positive_code": [{"source_code": "var x = parseInt(readline())\nvar q = [{ x:x, s:0}];\n\nvar vis = {}, lastx = x, res=[], count = 0;\nwhile( q.length > 0) {\n \n var cur = q.shift();\n \n if ( cur.s > 40) continue;\n count = cur.s;\n var t = (cur.x+1);\n var check = t.toString(2).split('').filter(d=>(d==='1')).length === 1;\n if (check) break;\n \n lastx = cur.x;\n if (cur.s%2 === 0) {\n var a = cur.x.toString(2);\n n = a.length - a.indexOf('0')\n res.push(n)\n q.push({\n x: cur.x ^ (Math.pow(2, n) - 1),\n s: (cur.s+1)\n });\n } else {\n q.push({\n x: cur.x+1,\n s: (cur.s+1)\n });\n }\n\n}\n\nprint(count)\nprint(res.join(' ')) \n\n"}], "negative_code": [{"source_code": "var x = parseInt(readline())\n\nvar q = [{ x, s:0}];\n\nvar vis = {}, lastx = x, res=[];\nwhile( q.length > 0) {\n \n var cur = q.shift();\n \n if ( vis[cur.x] || cur.s > 40) continue;\n vis[cur.x] = true;\n \n var check = (cur.x+1).toString(2).split('').filter(d=>(d==='1')).length === 1;\n if (check) break;\n \n lastx = cur.x;\n if (cur.s%2 === 0) {\n var a = cur.x.toString(2);\n n = a.length - a.indexOf('0')\n res.push(n)\n q.push({\n x: cur.x ^ (Math.pow(2, n) - 1),\n s: (cur.s+1)%2\n });\n } else {\n q.push({\n x: cur.x+1,\n s: (cur.s+1)%2\n });\n }\n\n}\n\nprint(res.length)\nif (res.length > 0) {\n print(res.join(' ')) \n}\n"}, {"source_code": "var x = parseInt(readline())\n\nvar q = [{ x, s:0}];\n\nvar vis = {}, lastx = x, res=[];\nwhile( q.length > 0) {\n \n var cur = q.shift();\n \n if ( vis[cur.x] || cur.s > 40) continue;\n vis[cur.x] = true;\n \n var check = (cur.x+1).toString(2).split('').filter(d=>(d==='1')).length === 1;\n if (check) break;\n \n lastx = cur.x;\n if (cur.s%2 === 0) {\n var a = cur.x.toString(2);\n n = a.length - a.indexOf('0')\n res.push(n)\n q.push({\n x: cur.x ^ (Math.pow(2, n) - 1),\n s: (cur.s+1)\n });\n } else {\n q.push({\n x: cur.x+1,\n s: (cur.s+1)\n });\n }\n\n}\n\nprint(res.length)\nif (res.length > 0) {\n print(res.join(' ')) \n}\n"}], "src_uid": "2510469c09d7d145078e65de81640ddc"} {"source_code": "/*//deb\nvar lines = [];\nlines[0] = \"3 2\";\nlines[1] = \".*.\";\nlines[2] = \".*.\";\nvar line = 0;\nfunction readline() {\n\treturn lines[line++];\n}*/\n\n\nfunction readn() {\n\treturn +readline();\n}\nfunction parsens(s) {\n\treturn \ts.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumbers(a,b) {\n\treturn a-b;\n}\n\n\nvar numbers = parsens(readline());\nvar w = numbers[0];\nvar h = numbers[1];\n\nvar a = [];\nfor (var i = 0; i < h; i++) {\n\ta[i] = [];\n\tvar s = readline();\n\tfor (var j = 0; j < w; j++) {\n\t\tif (s.charAt(j) == \".\") {\n\t\t\ta[i][j] = 0;\n\t\t} else {\n\t\t\ta[i][j] = 1;\n\t\t}\n\t}\t\n}\n\nvar b = [];\nfor (var i = 0; i < w; i++) {\n\tb[i] = [];\n}\n\nfor (var i = 0; i < h; i++) {\n\tfor (var j = 0; j < w; j++) {\n\t\tb[j][i] = a[i][j];\n\t}\t\n}\n\nfor (var i = 0; i < w; i++) {\n\tvar s = \"\";\n\tfor (var j = 0; j < h; j++) {\n\t\ts += b[i][j] == 0 ? \"..\" : \"**\";\n\t}\n\tprint(s);\n\tprint(s);\n}", "positive_code": [{"source_code": "var size = readline().split(' ');\nvar w = size[0];\nvar h = size[1];\nvar img = [];\n\nfor (var i = 0; i < h; i++) {\n\timg[i] = readline().split('');\n}\n\nvar rotate = [];\n\nfor (var i = 0; i < h; i++) {\n\tfor (var j = 0; j < w; j++) {\n\t\tif (!rotate[j]) {\n\t\t\trotate[j] = [];\n\t\t}\n\t\trotate[j][h - i] = img[i][j];\n\t}\n}\n\nvar reflection = [];\nvar height = w;\nvar width = h;\n\nfor (var i = 0; i < height; i++) {\n\treflection[i] = [];\n\tfor (var j = 0; j < width; j++) {\n\t\treflection[i][j] = rotate[i][width-j];\n\t}\n}\n\nvar scale = [];\n\nfor (var i = 0; i < height; i++) {\n\tscale[2*i] = [];\n\tscale[2*i + 1] = [];\n\tfor (var j = 0; j < width; j++) {\n\t\tvar pixel = reflection[i][j];\n\t\tscale[2*i][2*j] = pixel;\n\t\tscale[2*i][2*j + 1] = pixel;\n\t\tscale[2*i + 1][2*j] = pixel;\n\t\tscale[2*i + 1][2*j + 1] = pixel;\n\t}\n}\n\nfor (var i = 0; i < scale.length; i++) {\n\tprint(scale[i].join(''));\n}\n"}, {"source_code": "var pair = readline().split(' '),\n w = +pair[0],\n h = +pair[1],\n img = [],\n i = 0,\n string;\nfor (; i < h; i++) {\n img[i] = readline();\n}\nfor (i = 0; i < w; i++) {\n string = img.map(function(str) {\n return str[i] + str[i];\n }).join('');\n print(string);\n print(string);\n}"}], "negative_code": [{"source_code": "var size = readline().split(' ');\nvar w = size[0];\nvar h = size[1];\nvar img = [];\n\nfor (var i = 0; i < h; i++) {\n\timg[i] = readline().split('');\n}\n\nvar rotate = [];\n\nfor (var i = 0; i < h; i++) {\n\tfor (var j = 0; j < w; j++) {\n\t\tif (!rotate[j]) {\n\t\t\trotate[j] = [];\n\t\t}\n\t\trotate[j][h - i] = img[i][j];\n\t}\n}\n\nvar reflection = [];\nvar height = w;\nvar width = h;\n\nfor (var i = 0; i < height; i++) {\n\treflection[i] = [];\n\tfor (var j = 0; j < width; j++) {\n\t\treflection[i][j] = rotate[i][width-j];\n\t}\n}\n\nvar scale = [];\n\nfor (var i = 0; i < height; i++) {\n\tscale[2*i] = [];\n\tscale[2*i + 1] = [];\n\tfor (var j = 0; j < width; j++) {\n\t\tvar pixel = reflection[i][j];\n\t\tscale[2*i][2*j] = pixel;\n\t\tscale[2*i][2*j + 1] = pixel;\n\t\tscale[2*i + 1][2*j] = pixel;\n\t\tscale[2*i + 1][2*j + 1] = pixel;\n\t}\n}\nprint(reflection.length);\nprint(reflection[0].length);\nprint(scale.length);\nprint(scale[0].length);\n\nfor (var i = 0; i < scale.length; i++) {\n\tprint(scale[i].join(''));\n}\n"}, {"source_code": "var size = readline().split(' ');\nvar w = size[0];\nvar h = size[1];\nvar img = [];\n\nfor (var i = 0; i < h; i++) {\n\timg[i] = readline().split('');\n}\n\nvar rotate = [];\n\nfor (var i = 0; i < h; i++) {\n\tfor (var j = 0; j < w; j++) {\n\t\tif (!rotate[j]) {\n\t\t\trotate[j] = [];\n\t\t}\n\t\trotate[j][h - i] = img[i][j];\n\t}\n}\n\nvar reflection = [];\nvar height = w;\nvar width = h;\nvar halfWidth = Math.floor(h/2);\n\nfor (var i = 0; i < height; i++) {\n\treflection[i] = [];\n\tfor (var j = 0; j < halfWidth; j++) {\n\t\treflection[i][j] = rotate[i][width-j];\n\t\treflection[i][width-j] = rotate[i][j];\n\t}\n}\n\nvar scale = [];\n\nfor (var i = 0; i < height; i++) {\n\tscale[2*i] = [];\n\tscale[2*i + 1] = [];\n\tfor (var j = 0; j < width; j++) {\n\t\tvar pixel = reflection[i][j];\n\t\tscale[2*i][2*j] = pixel;\n\t\tscale[2*i][2*j + 1] = pixel;\n\t\tscale[2*i + 1][2*j] = pixel;\n\t\tscale[2*i + 1][2*j + 1] = pixel;\n\t}\n}\n\nfor (var i = 0; i < scale.length; i++) {\n\tprint(scale[i].join(''));\n}\n"}], "src_uid": "9af19e1b482f7f0bcbffc754cf324092"} {"source_code": " var t = readline();\r\n for (var i=0; i Array.from({ length: length }, () => readline()))(length)\r\n\r\nconst solution = (input) => {\r\n const result = input.map(str => str.toUpperCase() === 'YES' ? 'YES' : 'NO')\r\n return result.join('\\n')\r\n}\r\n\r\nprint(solution(input))"}, {"source_code": "var a = readline();\r\nvar arr = [];\r\nfor(var i = 0; i < a; i++){\r\n arr[i] = readline().toUpperCase();\r\n if(arr[i][0]==\"Y\" && arr[i][1]==\"E\" && arr[i][2]==\"S\"){\r\n print(\"YES\");\r\n }else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "var test = readline();\r\nfor (var i = 1; i <= test; i++) {\r\n var s = readline();\r\n if (s.toUpperCase() == 'YES') {\r\n print('YES');\r\n } else print('NO')\r\n}\r\n"}, {"source_code": "var testCase = +readline()\r\nvar dataStruct = [{\r\n u: \"Y\",\r\n l: \"y\"\r\n }, {\r\n u: \"E\",\r\n l: \"e\"\r\n },\r\n {\r\n u: \"S\",\r\n l: \"s\"\r\n }\r\n]\r\n\r\nloop0:\r\nfor(var i=0;i {\r\n const [testCount, ...lines] = data.toString().trim().split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n \r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n \r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n for (let i = 1; i <= lines[0]; i++) {\r\n processTC(lines, i);\r\n }\r\n}\r\n \r\nfunction processTC(lines, startLine) {\r\n const str = lines[startLine];\r\n console.log((str.trim().toLowerCase() === \"yes\") ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "function Solution() {\n const arr = lines.slice(1);\n const res = [];\n for (let i = 0; i < arr.length; i++) {\n if (arr[i].toUpperCase() === 'YES') res.push('YES')\n else res.push('NO');\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "function Solution() {\n const strArr = lines.slice(1);\n const res = [];\n for (let str of strArr) {\n if (str.toUpperCase() === 'YES') res.push('YES');\n else res.push('NO');\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "function Solution() {\n const N = Number(lines[0]);\n const strArr = lines.slice(1);\n const res = [];\n for (let i = 0; i < N; i++) {\n const [a, b, c] = strArr[i];\n if ((a === 'y' || a === 'Y')\n && (b === 'e' || b === 'E')\n && (c === 's' || c === 'S')) {\n res.push('YES');\n } else {\n res.push('No');\n }\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nrl.on(\"line\", line => {\r\n if (!isNaN(Number(line))) {\r\n // do nothing\r\n } else if (line.toLowerCase() === \"yes\") {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n let t = readline()-0\r\n while(t--){\r\n let s = readline()\r\n if(s.toLowerCase() === \"yes\")\r\n console.log(\"YES\")\r\n else \r\n console.log(\"NO\")\r\n }\r\n}"}, {"source_code": "// Parsing input: https://codeforces.com/blog/entry/78878\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n // Actual body code\n var T = parseInt(readLine());\n\n for (var t = 0; t < T; ++t) {\n var s = readLine();\n console.log((s.trim().toLowerCase() == \"yes\") ? \"YES\" : \"NO\");\n }\n}\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n const ans = d.toLowerCase() === \"yes\" ? \"YES\" : \"NO\";\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n//////////////////////////////////////////////////////////////\r\n\r\n\r\nconst myWordsArray = [];\r\n\r\nconst transformWord = (longWord)=>{\r\n const FirstLetter = longWord.charAt(0);\r\n const lastLetter = longWord.charAt(longWord.length -1);\r\n const middle = longWord.length - 2;\r\n console.log(`${FirstLetter}${middle}${lastLetter}`);\r\n}\r\n\r\nconst validateWords = (word)=>{\r\n if(word.length > 10){\r\n transformWord(word)\r\n }else{\r\n console.log(word)\r\n }\r\n}\r\n\r\nfunction main() {\r\n let number = parseInt(readLine());\r\n while(number--)\r\n {\r\n let string = readLine();\r\n string.toLowerCase() == 'yes' ? console.log(\"YES\") : console.log(\"NO\");\r\n }\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', ()=>{\r\n for (let i = 1; i < input.length; i++) {\r\n ans.push(input[i].toLowerCase() === 'yes' ? 'YES' : 'NO');\r\n }\r\n console.log(ans.join('\\n'));\r\n});"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on('close', () => {\r\n const readLine = createReadLine();\r\n let t = parseInt(readLine())\r\n while (t--) {\r\n let str = readLine();\r\n console.log(str.toLowerCase() === 'yes' ? 'yes' : 'no');\r\n }\r\n})"}, {"source_code": "const { readFileSync, writeFileSync } = require(\"fs\")\r\n\r\nlet a = readFileSync(\"./input.fd0138e687.txt\",\"utf-8\").match(/[a-z]+/gi)\r\n\r\nfor (let i = 0; i < a.length; ++i) {\r\n a[i] = /^yes$/i.test(a[i]) ? \"YES\" : \"NO\"\r\n}\r\n\r\nconsole.log( a.join(\"\\r\\n\") )"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n// LIBRARY START //\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\n\r\nconst reverseText = (s) => { return s.split('').reverse().join('') }\r\nconst hasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\n\r\nconst hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\n\r\nconst isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\n\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&')\r\n\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\n// LIBRARY END\r\n\r\nconst getresult = (str) => {\r\n \r\n str = str.toLowerCase()\r\n \r\n return str === 'yes' ? 'YES' : 'NO'\r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while( testcases-- ){\r\n \r\n let str = readline()\r\n console.log( getresult( str ) )\r\n }\r\n}\r\n//*/"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j ++){\n var e = false\n var s = lines[j].split('')\n if(s[0] == 'y' || s[0] == 'Y'){\n if(s[1] == 'e' || s[1] == 'E'){\n if(s[2] == 's' || s[2] == 'S'){\n e = true\n }\n }\n }\n if(e === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n \n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split('');\n var y = a[0], e = a[1], s = a[2];\n var check = 0;\n if(y == 'y' || y == 'Y'){\n check++;\n }\n if(e == 'e' || e == 'E'){\n check++;\n }\n if(s == 's' || s == 'S'){\n check++;\n }\n console.log(check == 3 ? 'YES' : 'NO');\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.line().toLowerCase();\n\t\tans.push(a === 'yes');\n\t}\n\tconsole.log(ans.map(x => x?'YES':'NO').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n // const n_m = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const n = n_m[0];\n // const m = n_m[1];\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const val = readLine().trim()\n if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n for (let t = 0;t < tests; ++t) {\r\n var s = readline();\r\n let arr = Array.from(s);\r\n if ((arr[0] == 'Y' || arr[0] == 'y') &&\r\n (arr[1] == 'E' || arr[1] == 'e') &&\r\n (arr[2] == 'S' || arr[2] == 's')) {\r\n console.log(\r\n 'YES'\r\n );\r\n } else {\r\n console.log('NO');\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n return str.toUpperCase() === 'YES' ? 'YES' : 'NO'\n}\n"}, {"source_code": "// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\nconst state = { i: 0 }\r\nconst readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nrl.on('line', function (line) {\r\n if (state.i > 0) {\r\n let sum = 0\r\n let data = line.split('')\r\n if (data[0] == 'y' || data[0] == 'Y') sum++\r\n if (data[1] == 'e' || data[1] == 'E') sum++\r\n if (data[2] == 's' || data[2] == 'S') sum++\r\n if (sum == 3) console.log(\"YES\")\r\n if (sum != 3) console.log(\"NO\")\r\n }\r\n state.i++\r\n})\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let arr = readline().trim();\r\n let a1 = false,\r\n a2 = false,\r\n a3 = false;\r\n if (arr[0] === \"Y\" || arr[0] === \"y\") a1 = true;\r\n if (arr[1] === \"E\" || arr[1] === \"e\") a2 = true;\r\n if (arr[2] === \"S\" || arr[2] === \"s\") a3 = true;\r\n if (a1 && a2 && a3) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n // var nul = readline();\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n if(n.toUpperCase() == \"YES\") console.log(\"YES\");\r\n else console.log(\"NO\");\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let times = parseInt(readline());\r\n for (let i = 0; i < times; i++) {\r\n let word = readline().toUpperCase();\r\n console.log(word === 'YES' ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next().toUpperCase();\r\n\t\tif(S == 'YES'){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const str = readline();\r\n output(str.toLowerCase() === 'yes' ? 'YES' : 'NO');\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "const length = Number(readline())\r\nconst input = ((length) => Array.from({ length: length }, () => readline()))(length)\r\n\r\nconst solution = (input) => {\r\n const result = input.map(str => {\r\n str.toUpperCase() === 'YES' ? 'YES' : 'NO'\r\n })\r\n\r\n return result.join('\\n')\r\n}\r\n\r\nprint(solution(input))"}, {"source_code": "let testCount;\r\n\r\nprocess.stdin.on(\"data\", (data) => {\r\n if (!testCount) {\r\n testCount = +data.toString();\r\n return;\r\n }\r\n console.log(testCount, line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n\r\n testCount--;\r\n});\r\n"}, {"source_code": "let testCount;\r\n\r\nprocess.stdin.on(\"data\", (data) => {\r\n if (!testCount) {\r\n testCount = +data.toString();\r\n return;\r\n }\r\n\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n\r\n testCount--;\r\n});\r\n"}, {"source_code": "let firstRun = true;\r\n\r\nprocess.stdin.on(\"data\", (data) => {\r\n if (firstRun) {\r\n firstRun = false;\r\n return;\r\n }\r\n\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n});\r\n"}, {"source_code": "let numTests = null;\r\nlet curTest = 0;\r\n\r\nprocess.stdin.on(\"data\", (data) => {\r\n if (numTests === null) {\r\n numTests = parseInt(data.toString());\r\n return;\r\n }\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n\r\n curTest++;\r\n if (curTest >= numTests) {\r\n process.exit();\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase().trim() == \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(\"line\", line.toLowerCase().trim());\r\n\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(line.toLowerCase() === \"yes\" ? \"YES\" : \"NO\");\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const input = data.toString().trim();\r\n const lines = input.split(\"\\n\");\r\n for (let line of lines) {\r\n console.log(\"line: \", line);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n const input = data.toString().trim();\r\n console.log(\"Input: \", input);\r\n});\r\n"}, {"source_code": "process.stdin.on(\"data\", (data) => {\r\n console.log(\"Input: \", data);\r\n});\r\n"}, {"source_code": "let i = \"\";\r\nlet o = \"\";\r\nprocess.stdin.on(\"data\", (c) => (i += c));\r\nprocess.stdin.on(\"end\", () => {\r\n const lines = i.toString().trim();\r\n\r\n for (let line of lines) {\r\n if (line.toLowerCase().trim() === \"yes\") {\r\n o += \"YES\\n\";\r\n } else {\r\n o += \"NO\\n\";\r\n }\r\n }\r\n console.log(o);\r\n});\r\n"}, {"source_code": "const stdin = process.openStdin();\r\n\r\nstdin.addListener(\"data\", function (d) {\r\n const line = d.toString().trim();\r\n if (line.toLowerCase().trim() === \"yes\") {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n \r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n \r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n for (let i = 1; i <= lines[0]; i++) {\r\n processTC(lines, i);\r\n }\r\n}\r\n \r\nfunction processTC(lines, startLine) {\r\n const str = lines[startLine];\r\n console.log((str.toLowerCase() === \"yes\") ? \"YES\" : \"NO\");\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n \r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n \r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n \r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n for (let i = 1; i <= lines[0]; i++) {\r\n processTC(lines, i);\r\n }\r\n}\r\n \r\nfunction processTC(lines, startLine) {\r\n const str = lines[startLine];\r\n return (str.toLowerCase() === \"yes\") ? \"YES\" : \"NO\";\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input; \r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n\r\nfunction processData(input) {\r\n const lines = input.split(\"\\n\");\r\n for (let i = 1; i <= lines[0]; i++) {\r\n processTC(lines, i);\r\n }\r\n}\r\n\r\nfunction processTC(lines, startLine) {\r\n const str = lines[startLine];\r\n return (str.toLowerCase() === \"yes\");\r\n}"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nrl.on(\"line\", line => {\r\n if (!isNaN(Number(line))) {\r\n console.log(Number(line));\r\n };\r\n if (line.toLowerCase() === \"yes\") {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n});\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nrl.on(\"line\", line => {\r\n if (line.toLowerCase() === \"yes\") {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n});\r\n"}], "src_uid": "4c0b0cb8a11cb1fd40fef47616987029"} {"source_code": "var nm = readline().trim().split(' ').map((_x)=>parseInt(_x));\nvar n=nm[0],m=nm[1];\nvar s=[];\nvar crossed = [];\nfor(var i=0;i{\"use strict\";var t={312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(747));let u=\"\",l=[],s=0,i=\"\";const f=\"local\"===process.argv[2],a=t=>{if(f)return l=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",i);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{l=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(i)}))};function c(){return l[s++]}function p(){return c().split(\" \").map((t=>parseFloat(t)))}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:c,nextNumbers:p,put:function(t){i+=t},puts:function(t){i+=t+\"\\n\"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const o=n(r(312));o.default.runMain((function(){const[t,e]=o.default.nextNumbers();let r=[],n=new Array(t);for(let u=0;u{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "negative_code": [], "src_uid": "9c90974a0bb860a5e180760042fd5045"} {"source_code": ";(function () {\n\n print((function (n, k) {\n var t = 0;\n while (n--) {\n\n for (var i = 0, s = readline(), f = true; i <= k; i++)\n if (s.indexOf(i) === -1) {\n f = false;\n break;\n } \n\n t += f;\n } \n\n return t; \n }).apply(null, readline().split(' ').map(Number)));\n\n}).call(this);\n", "positive_code": [{"source_code": "print(function(n, k) {\n\tvar i, j, c, s, ans = 0;\n\tfor (i = 0; i < n; i++) {\n\t\ts = 0;\n\t\tc = new Int8Array(10);\n\n\t\treadline().split('').forEach(function(v) {\n\t\t\tc[v] = 1;\n\t\t});\n\n\t\tfor (j = 0; j <= k; j++) {\n\t\t\ts += c[j];\n\t\t}\n\t\tif (s === k + 1) {\n\t\t\tans++;\n\t\t}\n\t}\n\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "var num = readline().split(' ').map(c => parseInt(c)),count = 0\nvar encap = [0,0,0,0,0,0,0,0,0,0], bag = new Set()\nfor (var j = 0; j < num[0]; j++){\n\treadline().split('').map(c => bag.add(parseInt(c)))\n\tbag.forEach(c => encap[c] += 1)\n\tvar res = encap.reduce((sum,val,index) =>{\n\t\tif (index < num[1]+1) return sum + val\n\t\telse return sum\n\t},0)\n\tif (res >= num[1]+1){\n\t\tcount += 1\n\t}\n\tencap.fill(0)\n\tbag.clear()\n}\nprint(count)"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet [n,k]=readLine().split(\" \").map(n=>+n)\n\tlet ans=0\n\twhile(n--){\n\t\tlet counter=0\n\t\tlet x=readLine()\n\t\tfor(let i=0;i<=k;i++)\n\t\t\tif(x.search(i-'0')!=-1)\n\t\t\t\tcounter++\n\t\tif(counter==(k+1))\n\t\t\tans++\n\t}\n\tconsole.log(ans)\n}"}, {"source_code": "print(function(n, k) {\n\tvar i, j, c, s, ans = 0;\n\tfor (i = 0; i < n; i++) {\n\t\ts = 0;\n\t\tc = new Int8Array(10);\n \n\t\treadline().split('').forEach(function(v) {\n\t\t\tc[v] = 1;\n\t\t});\n \n\t\tfor (j = 0; j <= k; j++) {\n\t\t\ts += c[j];\n\t\t}\n\t\tif (s === k + 1) {\n\t\t\tans++;\n\t\t}\n\t}\n \n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));\n"}, {"source_code": "(function(n, k) {\n var i, j, exist, s, ans = 0;\n for (i = 0; i < n; i++) {\n s = 0;\n exist = [];\n\n readline().split('').forEach(function(v) {\n exist[v] = 1;\n });\n\n for (j = 0; j <= k; j++) {\n s += exist[j];\n }\n if (s === k + 1) {\n ans++;\n }\n }\n\n print(ans);\n}).apply(0, readline().split(' ').map(Number));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\ncount = 0;\n\nwhile (n--) {\n var arr = Array.from(new Set(readline().split('').map(Number))).sort((a, b) => a - b);\n var needed = arr.slice(0, k + 1);\n if (needed[0] === 0 &&\n needed[needed.length - 1] === k &&\n needed.length === k + 1) {\n count++; \n }\n}\n\nprint(count);"}], "negative_code": [{"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet [n,k]=readLine().split(\" \").map(n=>+n)\n\tlet count=0\n\twhile(n--){\n\t\tlet isGood=true\n\t\tlet number = +readLine()\n\t\twhile(number){\n\t\t\tlet digit = number%10\n\t\t\tif(digit>k)\n\t\t\t{\n\t\t\t\tisGood=false\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tnumber/=10\n\t\t}\n\t\tif(isGood)\n\t\t\tcount++\n\t}\n\tconsole.log(count)\n}"}, {"source_code": "print(function(n, k) {\n\tvar i, j, c, s, ans = 0;\n\tfor (i = 0; i < n; i++) {\n\t\ts = 0;\n\t\tc = new Int8Array(10);\n\n\t\treadline().split('').forEach(function(v) {\n\t\t\tc[v] = 1;\n\t\t});\n\n\t\tfor (j = 0; j < k; j++) {\n\t\t\ts += c[j];\n\t\t}\n\t\tif (s === k) {\n\t\t\tans++;\n\t\t}\n\t}\n\n\treturn ans;\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var num = readline().split(' ').map(c => parseInt(c)),count = 0\nvar encap = [0,0,0,0,0,0,0,0,0,0]\nfor (var j = 0; j < num[0]; j++){\n\tvar array = readline().split('').map(c => parseInt(c))\n\tarray.sort((a,b) => {return a-b}).forEach(v => encap[v]+=1)\n\tvar res = encap.reduce((sum,val,index) =>{\n\t\tif (index < num[1]+1) return sum + val\n\t\telse return sum\n\t},0)\n\tif (res >= num[1]+1){\n\t\tcount += 1\n\t}\n\tencap.fill(0)\n}\nprint(count)\n"}, {"source_code": "var num = readline().split(' ').map(c => parseInt(c)),count = 0\nvar encap = [0,0,0,0,0,0,0,0,0,0]\nfor (var j = 0; j < num[0]; j++){\n\tvar array = readline().split('').map(c => parseInt(c))\n\tarray.forEach(v => encap[v]+=1)\n\tvar res = encap.reduce((sum,val,index) =>{\n\t\tif (index < num[1]+1) return sum + val\n\t\telse return sum\n\t},0)\n\tif (res == num[1]+1){\n\t\tcount += 1\n\t}\n\tencap.fill(0)\n}\nprint(count)"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\ncount = 0;\n\nwhile (n--) {\n var arr = Array.from(new Set(readline().split('').map(Number))).sort((a, b) => a - b);\n if (arr[0] === 0 &&\n arr[arr.length - 1] === k &&\n arr.length === k + 1) {\n count++; \n } \n}\n\nprint(count);"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\ncount = 0;\n\nwhile (n--) {\n var arr = Array.from(new Set(readline().split('').map(Number))).sort((a, b) => a - b);\n var needed = arr.slice(0, k + 1);\n if (arr[0] === 0 &&\n needed[needed.length - 1] === k) {\n count++; \n }\n}\n\nprint(count);"}], "src_uid": "fc831eda72f2ebe0865a3fb1b783edc5"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tvar clist = nextIntArray(M);\r\n\t\tvar diff = {};\r\n\t\tvar colorMap = {};\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(colorMap[alist[j]] == null){\r\n\t\t\t\tcolorMap[alist[j]] = new Set();\r\n\t\t\t}\r\n\t\t\tcolorMap[alist[j]].add(j);\r\n\t\t\tif(alist[j] != blist[j]){\r\n\t\t\t\tif(diff[blist[j]] == null){\r\n\t\t\t\t\tdiff[blist[j]] = [];\r\n\t\t\t\t}\r\n\t\t\t\tdiff[blist[j]].push(j);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar keep = [];\r\n\t\tvar output = [];\r\n\t\tfor(var j = 0; j < M; j++){\r\n\t\t\tvar c = clist[j];\r\n\t\t\tif(diff[c] == null || diff[c].length == 0){\r\n\t\t\t\tif(colorMap[c] != null && colorMap[c].size > 0){\r\n\t\t\t\t\tvar te = Array.from(colorMap[c]);\r\n\t\t\t\t\twhile(keep.length > 0){\r\n\t\t\t\t\t\toutput.push(te[0] + 1);\r\n\t\t\t\t\t\tkeep.pop();\r\n\t\t\t\t\t}\r\n\t\t\t\t\toutput.push(te[0] + 1);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tkeep.push(c);\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tvar ok = diff[c].shift();\r\n\t\t\t\twhile(keep.length > 0){\r\n\t\t\t\t\toutput.push(ok + 1);\r\n\t\t\t\t\tkeep.pop();\r\n\t\t\t\t}\r\n\t\t\t\toutput.push(ok + 1);\r\n\t\t\t\tcolorMap[alist[ok]].delete(ok);\r\n\t\t\t\tif(colorMap[c] == null){\r\n\t\t\t\t\tcolorMap[c] = new Set();\r\n\t\t\t\t}\r\n\t\t\t\tcolorMap[c].add(ok);\r\n\t\t\t}\r\n\t\t}\r\n\t\t//myerr(diff);\r\n\t\tvar key = Object.keys(diff);\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < key.length; j++){\r\n\t\t\tif(diff[key[j]].length > 0){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(!isOK || output.length != M){\r\n\t\t\tmyout(\"NO\");\r\n\t\t}else{\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}\r\n\t}\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b, c) {\r\n const colors = new Map(),\r\n change = new Map(),\r\n painters = new Map();\r\n for (let [i, color] of b.entries()) {\r\n colors.set(color, i);\r\n if (a[i] !== b[i]) {\r\n var _change$get;\r\n if (!change.has(color)) change.set(color, []);\r\n (_change$get = change.get(color)) === null || _change$get === void 0 ? void 0 : _change$get.push(i);\r\n }\r\n }\r\n for (let color of c) {\r\n var _painters$get;\r\n painters.set(color, ((_painters$get = painters.get(color)) !== null && _painters$get !== void 0 ? _painters$get : 0) + 1);\r\n }\r\n for (let [color, arr] of change) {\r\n var _painters$get2;\r\n if (arr.length > ((_painters$get2 = painters.get(color)) !== null && _painters$get2 !== void 0 ? _painters$get2 : 0)) return 'NO';\r\n }\r\n let res = [],\r\n last = -1;\r\n for (let i = m - 1; i >= 0; i--) {\r\n const color = c[i],\r\n idx = change.get(color);\r\n if (idx !== null && idx !== void 0 && idx.length) {\r\n res[i] = idx.pop();\r\n } else if (last !== -1) {\r\n res[i] = last;\r\n } else {\r\n if (colors.has(color)) {\r\n res[i] = colors.get(color);\r\n } else {\r\n return 'NO';\r\n }\r\n }\r\n if (last === -1) last = res[i];\r\n }\r\n return `YES\\n${res.map(num => num + 1).join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const c = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a, b, c));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tconst need = Array.from(Array(n+1), x => []);\r\n\t\tlet done = n;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] != b[i]) {\r\n\t\t\t\tneed[b[i]].push(i+1);\r\n\t\t\t\tdone--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet splplk;\r\n\t\tif (need[c[m-1]].length) {\r\n\t\t\tsplplk = need[c[m-1]][0];\r\n\t\t} else {\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (b[i] == c[m-1]) {\r\n\t\t\t\t\tsplplk = i+1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!splplk) {\r\n\t\t\t\tconsole.log('NO');\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(m);\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (need[c[i]].length) {\r\n\t\t\t\tans[i] = need[c[i]].pop();\r\n\t\t\t\tdone++;\r\n\t\t\t} else {\r\n\t\t\t\tans[i] = splplk;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(done == n ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tconst need = Array(n+1).fill([]);\r\n\t\tlet done = n;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] != b[i]) {\r\n\t\t\t\tneed[b[i]].push(i+1);\r\n\t\t\t\tdone--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet splplk;\r\n\t\tif (need[c[m-1]].length) {\r\n\t\t\tsplplk = need[c[m-1]][0];\r\n\t\t} else {\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (b[i] == c[m-1]) {\r\n\t\t\t\t\tsplplk = i+1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!splplk) {\r\n\t\t\t\tconsole.log('NO');\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = Array(n+1);\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tif (need[c[i]].length) {\r\n\t\t\t\tans[i] = need[c[i]].pop();\r\n\t\t\t\tdone++;\r\n\t\t\t} else {\r\n\t\t\t\tans[i] = splplk;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(done == n ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "a350430c707bb18a146df9f80e114f45"} {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var a, b;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n b = readline().split(' ').map(x=>parseInt(x));\r\n \r\n var minDiff = 0;\r\n var ans = 'YES';\r\n var diffMatch = -1;\r\n for (var i = 0; i < n; i++) {\r\n var diff = a[i] - b[i];\r\n if (b[i] == 0) {\r\n if (diff > minDiff) {\r\n minDiff = diff;\r\n }\r\n } else {\r\n if (diff < 0) {\r\n ans = 'NO';\r\n break;\r\n } else if (diffMatch == -1){\r\n diffMatch = diff;\r\n } else if (diff != diffMatch) {\r\n ans = 'NO';\r\n break;\r\n }\r\n }\r\n }\r\n if (diffMatch != -1 && diffMatch < minDiff) {\r\n ans = 'NO';\r\n }\r\n\r\n print(ans);\r\n }", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let A = readline().split(' ').map(Number);\r\n let B = readline().split(' ').map(Number);\r\n\r\n let maxDiff = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n let diff = Math.abs(A[i] - B[i]);\r\n if (diff > maxDiff) {\r\n maxDiff = diff;\r\n }\r\n }\r\n\r\n let ok = true;\r\n \r\n for (let i = 0; i < n; i++) {\r\n if (B[i] !== 0 && A[i] - B[i] !== maxDiff) {\r\n ok = false;\r\n break;\r\n }\r\n }\r\n\r\n output(ok ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tvar ok = true;\r\n\t\tvar just = -1;\r\n\t\tvar must = -1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(alist[i] < blist[i]){\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(alist[i] >= 0){\r\n\t\t\t\tif(blist[i] == 0){\r\n\t\t\t\t\tmust = Math.max(must, alist[i]);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tif(just == -1){\r\n\t\t\t\t\t\tjust = alist[i] - blist[i];\r\n\t\t\t\t\t}else if(just != alist[i] - blist[i]){\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t//myerr({just, must});\r\n\t\tif(just != -1){\r\n\t\t\tif(just < must){\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n for(i = 1; i <= t * 3; i++){\n if(i % 3 == 1){\n n = lines[i];\n }else if(i % 3 == 2){\n a = lines[i].split(' ').map(Number);\n }else{\n var b = lines[i].split(' ').map(Number);\n var T = 0, k = 0;\n for(j = 0; j < n; j++){\n if(a[j] - b[j] < 0){\n k++;\n break;\n }\n T = Math.max(T, a[j] - b[j]);\n }\n for(j = 0; j < n; j++){\n if(a[j] - b[j] < T && b[j] !== 0){\n k++;\n break;\n }\n }\n console.log(k !== 0 ? 'NO' : 'YES');\n \n }\n }\n});\n"}, {"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n/**\r\n * \u041f\u043b\u0430\u043d \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438:\r\n * \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b\r\n * \u0441\u043e\u0437\u0434\u0430\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 C\r\n * \u0438\u0434\u0435\u043c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432\r\n * \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 A \u043c\u0435\u043d\u044c\u0448\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 B, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 NO\r\n * \u043f\u043e\u043a\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 A \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u0443 B, \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 A \u0432\u044b\u0447\u0438\u0442\u0430\u0439 1 \r\n * \r\n */\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \").map(Number);\r\n var b = readline().split(\" \").map(Number);\r\n var dif = 0;\r\n var ans = \"YES\";\r\n if (a === b) {\r\n ans;\r\n } else {\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] - b[j] > dif) {\r\n dif = a[j] - b[j];\r\n }\r\n }\r\n\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] < b[j]) {\r\n ans = \"NO\";\r\n } else if (a[j] - b[j] !== dif && b[j] !== 0) {\r\n ans = \"NO\";\r\n }\r\n }\r\n }\r\n console.log(ans)\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr1 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr2 = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let dif = Infinity;\r\n let flag = true;\r\n for(let i=0;idif) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if(flag===false) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a, b) {\r\n let max = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] < b[i]) return 'NO';\r\n max = Math.max(max, a[i] - b[i]);\r\n }\r\n const nums = [];\r\n for (let i = 0; i < n; i++) {\r\n nums[i] = Math.max(a[i] - max, 0);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (b[i] !== nums[i]) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, sa, sb) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb) {\n const ds = []\n let max = -Infinity\n for (let i = 0; i < n; i++) {\n ds[i] = sa[i] - sb[i]\n max = Math.max(max, ds[i])\n }\n for (let i = 0; i < n; i++) {\n if (ds[i] === max || !sb[i]) {\n //\n } else {\n return false\n }\n }\n return max >= 0\n}\n"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = readline()\r\n a = readline().split(' ').map(a => +a)\r\n b = readline().split(' ').map(b => +b)\r\n ans = 'YES'\r\n xx = 0\r\n\r\n if(JSON.stringify(a)==JSON.stringify(b)){\r\n print(ans)\r\n }\r\n \r\n else {\r\n for(i=0; i xx)\r\n xx = a[i] - b[i]\r\n }\r\n for(i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let A = readline().split(' ').map(Number);\r\n let B = readline().split(' ').map(Number);\r\n\r\n let ok = true;\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (A[i] < B[i]) {\r\n ok = false;\r\n break;\r\n }\r\n }\r\n\r\n output(ok ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar alist = nextIntArray(N);\r\n\t\tvar blist = nextIntArray(N);\r\n\t\tvar ok = true;\r\n\t\tvar just = -1;\r\n\t\tvar must = -1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(alist[i] < blist[i]){\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(alist[i] > 0){\r\n\t\t\t\tif(blist[i] == 0){\r\n\t\t\t\t\tmust = Math.max(must, alist[i]);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tif(just == -1){\r\n\t\t\t\t\t\tjust = alist[i] - blist[i];\r\n\t\t\t\t\t}else if(just != alist[i] - blist[i]){\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(just != -1){\r\n\t\t\tif(just < must){\r\n\t\t\t\tok - false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = readline()\r\n a = readline().split(' ').map(a => +a)\r\n b = readline().split(' ').map(b => +b)\r\n ans = 'NO'\r\n maxNum = Math.max.apply(null, a)\r\n while(maxNum--){\r\n for(i=0; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let found = false;\n for (let i = 0; i <= len - 3; i++) {\n let [a, b, c] = [arr[i], arr[i + 1], arr[i + 2]];\n if (a < b && b > c) {\n console.log(\"YES\");\n console.log(`${i + 1} ${i + 2} ${i + 3}`);\n found = true;\n break;\n }\n }\n !found && console.log(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "// node template.js < A-small.in > A-small.out\n\nfunction main() {\n var tests = 1;\n tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n let N = nextInt();\n let a = [];\n for(let i = 0; i < N; i++) {\n a.push(nextInt());\n }\n\n let result = \"NO\";\n\n for(let i = 0; i+2 < a.length; i++) {\n if (a[i] < a[i+1] && a[i+1] > a[i+2]) {\n result = \"YES\\n\" + (i+1) + \" \" + (i+2) + \" \" + (i+3);\n break;\n }\n }\n\n print(result);\n }\n}\n\n// ------- Template ------------------\nfunction newTensor(dimensions, value) {\n let res = [];\n let dim = dimensions[0], subdim = dimensions.slice(1);\n if (subdim.length == 0) {\n for(let i = 0; i < dim; i++) {\n res.push(value);\n }\n } else {\n for(let i = 0; i < dim; i++) {\n res.push(newTensor(subdim, value));\n }\n }\n return res;\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "var n = parseInt(readline());\nvar res = [];\n\nwhile (n--){\n readline();//ODIO LE DONNE\n var inn = readline().split(\" \").map(function (a) {\n return parseInt(a);\n });\n var f = false;\n for (var i = 1 ; i inn[i - 1] && inn[i] > inn[i + 1]) {\n f=true;\n res.push([i,i+1,i+2]);\n break;\n }\n }\n if (!f){\n res.push([])\n }\n\n}\nfor (var i = 0;i b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 'NO';\n const arrIdx = [];\n\n for (let i = 1; i < arr.length - 1; i++) {\n if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {\n ans = 'YES';\n arrIdx.push(i, i + 1, i + 2);\n break;\n }\n }\n\n console.log(ans);\n\n if (arrIdx.length) {\n console.log(arrIdx.join(' '));\n }\n\n c++;\n});\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar res = [];\n\nwhile (n--){\n readline();//ODIO LE DONNE\n var inn = readline().split(\" \").map(function (a) {\n return parseInt(a);\n });\n var f = false;\n for (var i = 1 ; iinn[i+1]){\n f=true;\n res.push([i-1,i,i+1]);\n break;\n }\n }\n if (!f){\n res.push([])\n }\n\n}\nfor (var i = 0;iinn[j]){\n continue;\n }\n for (var k = j+1 ; kinn[k]){\n res.push([i+1,j+1,k+1]);\n f = true;\n break loop1;\n }\n }\n }\n }\n if (!f){\n res.push([])\n }\n\n}\nfor (var i = 0;i a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, parseInt(edge[2])];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgeCuts = new Array(cuts.length);\r\nedgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];\r\nedgeCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1]),\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))\r\n calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);\r\nedgeCuts = edgeCuts.filter((i) => i != undefined);\r\nedgeCuts = edgeCuts.filter(\r\n (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])\r\n);\r\nfor (var i = 0; i < weights.length; i++) {\r\n edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);\r\n}\r\nedgeCuts.sort((a, b) => a[1] - b[1]);\r\nedgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);\r\n\r\nvar result = 0;\r\nvar q = 0;\r\nvar dict={}\r\nfor (var i = 0; i < k; i++) {\r\n var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;\r\n q = qbase * 2;\r\n var res= dict[q]\r\n if (dict[q] == undefined){\r\n var j = upperBoundEdges(edgeCuts, q);\r\n\r\n var edgesList = edgeCuts[j][0][0];\r\n var weightsList = edgeCuts[j][0][1];\r\n var z = upperBound(weightsList, q);\r\n var res =\r\n (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;}\r\n result ^= res;\r\n}\r\n\r\nprint(result<0?result+8*(1<<30):result);\r\n\r\nfunction upperBoundEdges(edgeCuts, q) {\r\n var min = 0;\r\n var max = edgeCuts.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (edgeCuts[mid][1] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid;\r\n}\r\n\r\nfunction upperBound(arr, q) {\r\n var min = -1;\r\n var max = arr.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (arr[mid] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid + 1;\r\n}\r\n\r\nfunction calcCuts(cuts, edgeCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);\r\n var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);\r\n if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;\r\n return true;\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n var weightsOrder = [];\r\n var sum = 0;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n edgesOrder.push(min[2]);\r\n weightsOrder.push(min[3]);\r\n sum += min[1];\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [\r\n edgesOrder.sort((a, b) => a - b),\r\n weightsOrder.sort((a, b) => a - b),\r\n sum\r\n ];\r\n}\r\n", "positive_code": [{"source_code": "function PriorityQueue(compare) {\r\n this.heap = [];\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, parseInt(edge[2])];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgeCuts = new Array(cuts.length);\r\nedgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];\r\nedgeCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1]),\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))\r\n calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);\r\nedgeCuts = edgeCuts.filter((i) => i != undefined);\r\nedgeCuts = edgeCuts.filter(\r\n (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])\r\n);\r\nfor (var i = 0; i < weights.length; i++) {\r\n edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);\r\n}\r\nedgeCuts.sort((a, b) => a[1] - b[1]);\r\nedgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);\r\n\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;\r\n q = qbase * 2;\r\n var j = upperBoundEdges(edgeCuts, q);\r\n\r\n var edgesList = edgeCuts[j][0][0];\r\n var weightsList = edgeCuts[j][0][1];\r\n var z = upperBound(weightsList, q);\r\n var sum2 =\r\n (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;\r\n result ^= sum2;\r\n}\r\n\r\nprint(result<0?result+8*(1<<30):result);\r\n\r\nfunction upperBoundEdges(edgeCuts, q) {\r\n var min = 0;\r\n var max = edgeCuts.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (edgeCuts[mid][1] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid;\r\n}\r\n\r\nfunction upperBound(arr, q) {\r\n var min = -1;\r\n var max = arr.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (arr[mid] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid + 1;\r\n}\r\n\r\nfunction calcCuts(cuts, edgeCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);\r\n var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);\r\n if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;\r\n return true;\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n var weightsOrder = [];\r\n var sum = 0;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n edgesOrder.push(min[2]);\r\n weightsOrder.push(min[3]);\r\n sum += min[1];\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [\r\n edgesOrder.sort((a, b) => a - b),\r\n weightsOrder.sort((a, b) => a - b),\r\n sum\r\n ];\r\n}\r\n"}], "negative_code": [{"source_code": "function PriorityQueue(compare) {\r\n this.heap = [];\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, parseInt(edge[2])];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgeCuts = new Array(cuts.length);\r\nedgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];\r\nedgeCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1]),\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))\r\n calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);\r\nedgeCuts = edgeCuts.filter((i) => i != undefined);\r\nedgeCuts = edgeCuts.filter(\r\n (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])\r\n);\r\nfor (var i = 0; i < weights.length; i++) {\r\n edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);\r\n}\r\nedgeCuts.sort((a, b) => a[1] - b[1]);\r\nedgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);\r\n\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;\r\n q = qbase * 2;\r\n var j = upperBoundEdges(edgeCuts, q);\r\n\r\n var edgesList = edgeCuts[j][0][0];\r\n var weightsList = edgeCuts[j][0][1];\r\n var z = upperBound(weightsList, q);\r\n var sum2 =\r\n (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;\r\n result ^= sum2;\r\n}\r\n\r\nprint(result);\r\n\r\nfunction upperBoundEdges(edgeCuts, q) {\r\n var min = 0;\r\n var max = edgeCuts.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (edgeCuts[mid][1] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid;\r\n}\r\n\r\nfunction upperBound(arr, q) {\r\n var min = -1;\r\n var max = arr.length;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (arr[mid] <= q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid + 1;\r\n}\r\n\r\nfunction calcCuts(cuts, edgeCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);\r\n var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);\r\n if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;\r\n return true;\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n var weightsOrder = [];\r\n var sum = 0;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n edgesOrder.push(min[2]);\r\n weightsOrder.push(min[3]);\r\n sum += min[1];\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [\r\n edgesOrder.sort((a, b) => a - b),\r\n weightsOrder.sort((a, b) => a - b),\r\n sum\r\n ];\r\n}\r\n"}, {"source_code": "function PriorityQueue(compare) {\r\n this.heap = [];\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, parseInt(edge[2])];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgesCuts = new Array(cuts.length);\r\nedgesCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];\r\nedgesCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1]),\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))\r\n calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);\r\nedgesCuts = edgesCuts.filter((i) => i != undefined);\r\nedgesCuts = edgesCuts.filter(\r\n (i, id) => id == 0 || !sortedArrayEquals(i[0], edgesCuts[id - 1][0])\r\n);\r\n\r\nvar dict = {};\r\nvar dictCuts = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;\r\n q = qbase * 2;\r\n if (dict[q] == undefined) {\r\n var j = upperBound(edgesCuts, q);\r\n\r\n var edgesList = edgesCuts[j][0];\r\n var sum = 0;\r\n for (var edge of edgesList) {\r\n sum += Math.abs(iniEdges[edge][2] - qbase);\r\n }\r\n dict[q] = sum;\r\n }\r\n result ^= dict[q];\r\n}\r\n\r\nprint(result);\r\n\r\nfunction upperBound(edgesCuts, q) {\r\n var min = 0;\r\n var max = edgesCuts.length - 1;\r\n var mid = Math.floor((min + max) / 2);\r\n while (min != mid) {\r\n if (edgesCuts[mid][1] < q) min = mid;\r\n else max = mid;\r\n mid = Math.floor((min + max) / 2);\r\n }\r\n return mid;\r\n}\r\n\r\nfunction calcCuts(cuts, edgesCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgesCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);\r\n var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);\r\n if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;\r\n return true;\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n edgesOrder.push(min[2]);\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return edgesOrder.sort();\r\n}\r\n"}, {"source_code": "function PriorityQueue(compare) {\r\n this.heap = [];\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, parseInt(edge[2])];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgesCuts = new Array(cuts.length);\r\nedgesCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];\r\nedgesCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1]),\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))\r\n calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);\r\nedgesCuts = edgesCuts.filter((i) => i != undefined);\r\nedgesCuts = edgesCuts.filter(\r\n (i, id) => id == 0 || !sortedArrayEquals(i[0], edgesCuts[id - 1][0])\r\n);\r\n\r\nvar dict = {};\r\nvar dictCuts = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;\r\n q = qbase * 2;\r\n if (dict[q] == undefined) {\r\n var jmin = 0;\r\n var jmax = edgesCuts.length - 1;\r\n\r\n var j = Math.floor((jmin + jmax) / 2);\r\n while (jmin != j) {\r\n if (edgesCuts[j][1] <= q) jmin = j;\r\n else jmax = j;\r\n j = Math.floor((jmin + jmax) / 2);\r\n }\r\n\r\n var edgesList = edgesCuts[j][0];\r\n var sum = 0;\r\n for (var edge of edgesList) {\r\n sum += Math.abs(iniEdges[edge][2] - qbase);\r\n }\r\n dict[q] = sum;\r\n }\r\n result ^= dict[q];\r\n}\r\n\r\nprint(result);\r\n\r\nfunction calcCuts(cuts, edgesCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgesCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);\r\n var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);\r\n if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n return a.join() == b.join();\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n edgesOrder.push(min[2]);\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return edgesOrder.sort();\r\n}\r\n"}, {"source_code": "function PriorityQueue(compare) {\r\n this.heap = [];\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a < b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(upVal, myVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements / 2;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = current * 2 + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(this.heap[rightChild], best)\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(myVal, best)) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nvar iniEdges = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n iniEdges[i] = [node1, node2, weight];\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) / 2);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar edges = new PriorityQueue((a, b) => {\r\n return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];\r\n});\r\n\r\nvar edgesCuts = new Array(cuts.length);\r\nedgesCuts[0] = [mst(edges, nodes, cuts[0])[2], cuts[0]];\r\nedgesCuts[cuts.length - 1] = [\r\n mst(edges, nodes, cuts[cuts.length - 1])[2],\r\n cuts[cuts.length - 1]\r\n];\r\nif (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))\r\n calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);\r\nedgesCuts = edgesCuts.filter((i) => i != undefined);\r\n\r\nvar dict = {};\r\nvar dictCuts = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n q = i < queries.length ? queries[i] * 2 : (((q * a) / 2 + b) % c) * 2;\r\n if (dict[q] == undefined) {\r\n var j = 0;\r\n\r\n while (j < edgesCuts.length && edgesCuts[j][1] <= q) {\r\n j++;\r\n }\r\n j--;\r\n var edgesList = edgesCuts[j][0];\r\n var sum = 0;\r\n for (var edge of edgesList) {\r\n sum += Math.abs(iniEdges[edge][2] - q);\r\n }\r\n dict[q] = sum / 2;\r\n }\r\n result ^= dict[q];\r\n}\r\n// for (var i = 0; i < k; i++) {\r\n// q = i < queries.length ? queries[i] * 2 : (((q * a) / 2 + b) % c) * 2;\r\n// if (dict[q] == undefined) {\r\n// var j = 0;\r\n\r\n// while (j < cuts.length && cuts[j] <= q) {\r\n// j++;\r\n// }\r\n// j--;\r\n// var prevSol = dictCuts[cuts[j]];\r\n// if (prevSol == undefined) {\r\n// dictCuts[cuts[j]] = mst(edges, nodes, cuts[j]);\r\n// prevSol = dictCuts[cuts[j]];\r\n// }\r\n// var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;\r\n// dict[q] = sol;\r\n// }\r\n// result ^= dict[q];\r\n// }\r\n\r\nprint(result);\r\n\r\nfunction calcCuts(cuts, edgesCuts, edges, ini, end) {\r\n var mid = Math.floor((ini + end) / 2);\r\n if (mid == ini) return;\r\n edgesCuts[mid] = [mst(edges, nodes, cuts[mid])[2], cuts[mid]];\r\n var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);\r\n var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);\r\n if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);\r\n if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);\r\n if (equalDown || equalUp) delete edgesCuts[mid];\r\n}\r\n\r\nfunction sortedArrayEquals(a, b) {\r\n return a.join() == b.join();\r\n}\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(edges, nodes, q) {\r\n edges.clear();\r\n var sum = 0;\r\n var edgesUp = 0;\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n var edgesOrder = [];\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n //var eds = [];\r\n while (true) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n sum += min[1];\r\n edgesOrder.push(min[2]);\r\n if (q < min[3]) {\r\n edgesUp++;\r\n }\r\n // eds.push(min[2]); // Don't know why this makes the code run faster\r\n if (++nVisited == nodes.length) break;\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [sum, edgesUp, edgesOrder.sort()];\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(myVal, upVal) >= 0) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements >> 1;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = (current << 1) + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(best, this.heap[rightChild]) > 0\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(best, myVal) >= 0) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) << 1; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) >> 1);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\nvar max = queries.reduce((a, b) => Math.max(a, b), 0);\r\nmax = Math.max(max, c) << 1;\r\n\r\nvar dictCuts = {};\r\n\r\nvar dict = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n q = i < queries.length ? queries[i] << 1 : (((q * a) >> 1) + b) % c << 1;\r\n if (dict[q] == undefined) {\r\n var j = 0;\r\n while (j < cuts.length && cuts[j] <= q) {\r\n j++;\r\n }\r\n j--;\r\n var prevSol = dictCuts[cuts[j]];\r\n if (prevSol == undefined) {\r\n dictCuts[cuts[j]] = mst(nodes, cuts[j]);\r\n prevSol = dictCuts[cuts[j]];\r\n }\r\n var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) >> 1;\r\n dict[q] = sol;\r\n }\r\n result ^= dict[q];\r\n if (i % 100000 == 0) print(i / 100000);\r\n}\r\n\r\nprint(result);\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => {\r\n var res = a[1] - b[1];\r\n return res == 0 ? b[3] - a[3] : res;\r\n });\r\n var sum = 0;\r\n var edgesUp = 0;\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n var eds = [];\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n nVisited++;\r\n sum += min[1];\r\n eds.push(min[2]); // Don't know why this makes the code run faster\r\n if (q < min[3]) {\r\n edgesUp++;\r\n }\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [sum, edgesUp];\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(myVal, upVal) >= 0) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements >> 1;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = (current << 1) + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(best, this.heap[rightChild]) > 0\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(best, myVal) >= 0) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) << 1; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n cuts.add(w1);\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) >> 1);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\nvar max = queries.reduce((a, b) => Math.max(a, b), 0);\r\nmax = Math.max(max, c) << 1;\r\n\r\nvar dictCuts = {};\r\n\r\nvar dict = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n q = i < queries.length ? queries[i] << 1 : (((q * a) >> 1) + b) % c << 1;\r\n if (dict[q] == undefined) {\r\n var j = 0;\r\n while (j < cuts.length && cuts[j] <= q) {\r\n j++;\r\n }\r\n j--;\r\n var prevSol = dictCuts[cuts[j]];\r\n if (prevSol == undefined) {\r\n dictCuts[cuts[j]] = mst(nodes, cuts[j]);\r\n prevSol = dictCuts[cuts[j]];\r\n }\r\n var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) >> 1;\r\n dict[q] = sol;\r\n }\r\n result ^= dict[q];\r\n if (n > 17 && nodes[17][0][1] == 51480 * 2 && i % 10000 == 0) print(i / 1000);\r\n}\r\n\r\nprint(result);\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => {\r\n var res = a[1] - b[1];\r\n return res == 0 ? b[3] - a[3] : res;\r\n });\r\n var sum = 0;\r\n var edgesUp = 0;\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n var eds = [];\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n nVisited++;\r\n sum += min[1];\r\n eds.push(min[2]); // Don't know why this makes the code run faster\r\n if (q < min[3]) {\r\n edgesUp++;\r\n }\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [sum, edgesUp];\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(myVal, upVal) >= 0) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements >> 1;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = (current << 1) + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(best, this.heap[rightChild]) > 0\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(best, myVal) >= 0) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) >> 1);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar dictCuts = {};\r\nfor (var cut of cuts) {\r\n dictCuts[cut] = mst(nodes, cut);\r\n}\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nvar dict = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n q = i < queries.length ? 2 * queries[i] : (((q * a) / 2 + b) % c) * 2;\r\n if (dict[q] == undefined) {\r\n var j = 0;\r\n while (j < cuts.length && cuts[j] <= q) {\r\n j++;\r\n }\r\n j--;\r\n var prevSol = dictCuts[cuts[j]];\r\n var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;\r\n dict[q] = sol;\r\n }\r\n result ^= dict[q];\r\n}\r\n\r\nprint(result);\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => {\r\n var res = a[1] - b[1];\r\n return res == 0 ? b[3] - a[3] : res;\r\n });\r\n var sum = 0;\r\n var edgesUp = 0;\r\n var visited = new Set();\r\n visited.add(0);\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited.has(node)) {\r\n visited.add(node);\r\n nVisited++;\r\n sum += min[1];\r\n if (q < min[3]) {\r\n edgesUp++;\r\n }\r\n for (var edge of nodes[node]) {\r\n if (!visited.has(edge[0]))\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [sum, edgesUp];\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.add = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (this.compare(myVal, upVal) >= 0) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n if (this.elements == 1) {\r\n return this.heap[--this.elements];\r\n }\r\n var el = this.heap[0];\r\n\r\n var myVal = this.heap[--this.elements];\r\n this.heap[0] = myVal;\r\n\r\n var current = 0;\r\n var maxSize = this.elements >> 1;\r\n var leftChild;\r\n var rightChild;\r\n var best;\r\n\r\n while (current < maxSize) {\r\n leftChild = (current << 1) + 1;\r\n rightChild = leftChild + 1;\r\n best = this.heap[leftChild];\r\n\r\n if (\r\n rightChild < this.elements &&\r\n this.compare(best, this.heap[rightChild]) > 0\r\n ) {\r\n best = this.heap[rightChild];\r\n leftChild = rightChild;\r\n }\r\n if (this.compare(best, myVal) >= 0) {\r\n break;\r\n }\r\n this.heap[current] = best;\r\n current = leftChild;\r\n }\r\n this.heap[current] = myVal;\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar weights = Array(m);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals\r\n addEdge(nodes, node1, node2, weight, i);\r\n weights[i] = weight;\r\n}\r\n\r\nvar cuts = new Set();\r\ncuts.add(0);\r\nfor (var i = 0; i < m; i++) {\r\n var w1 = weights[i];\r\n for (var j = 0; j < i; j++) {\r\n cuts.add((w1 + weights[j]) >> 1);\r\n }\r\n}\r\ncuts = Array.from(cuts);\r\ncuts.sort((a, b) => a - b);\r\n\r\nvar dictCuts = {};\r\nfor (var cut of cuts) {\r\n dictCuts[cut] = mst(nodes, cut);\r\n}\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nfor (var i = p; i < k; i++) {\r\n queries.push((queries[i - 1] * a + b) % c);\r\n}\r\n\r\nvar dict = {};\r\nvar result = 0;\r\nvar q = 0;\r\nfor (var i = 0; i < k; i++) {\r\n q = i < queries.length ? 2 * queries[i] : (((q * a) / a + b) % c) * 2;\r\n if (dict[q] == undefined) {\r\n var j = 0;\r\n while (j < cuts.length && cuts[j] <= q) {\r\n j++;\r\n }\r\n j--;\r\n var prevSol = dictCuts[cuts[j]];\r\n var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;\r\n dict[q] = sol;\r\n }\r\n result ^= dict[q];\r\n}\r\n\r\nprint(result);\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => {\r\n var res = a[1] - b[1];\r\n return res == 0 ? b[3] - a[3] : res;\r\n });\r\n var sum = 0;\r\n var edgesUp = 0;\r\n var visited = new Set();\r\n visited.add(0);\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited.has(node)) {\r\n visited.add(node);\r\n nVisited++;\r\n sum += min[1];\r\n if (q < min[3]) {\r\n edgesUp++;\r\n }\r\n for (var edge of nodes[node]) {\r\n if (!visited.has(edge[0]))\r\n edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);\r\n }\r\n }\r\n }\r\n return [sum, edgesUp];\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.insert = function (myVal) {\r\n this.heap[this.elements++] = myVal;\r\n\r\n var current = this.elements - 1;\r\n while (current > 0) {\r\n var up = (current - 1) >> 1;\r\n var upVal = this.heap[up];\r\n if (!this.compare(myVal, upVal)) break;\r\n this.heap[current] = upVal;\r\n current = up;\r\n }\r\n this.heap[current] = myVal;\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n var el = this.heap[0];\r\n\r\n this.heap[0] = this.heap[this.elements - 1];\r\n this.elements--;\r\n\r\n var current = 0;\r\n var leftChild = current * 2 + 1;\r\n var rightChild = current * 2 + 2;\r\n var currentVal = this.heap[current];\r\n var leftChildVal = this.heap[leftChild];\r\n var rightChildVal = this.heap[rightChild];\r\n\r\n while (\r\n rightChild < this.elements &&\r\n (this.compare(currentVal, leftChildVal) > 0 ||\r\n this.compare(currentVal, rightChildVal) > 0)\r\n ) {\r\n if (this.compare(leftChildVal, rightChildVal) > 0) {\r\n this.heap[rightChild] = currentVal;\r\n this.heap[current] = rightChildVal;\r\n current = rightChild;\r\n } else {\r\n this.heap[leftChild] = currentVal;\r\n this.heap[current] = leftChildVal;\r\n current = leftChild;\r\n }\r\n leftChild = current * 2 + 1;\r\n rightChild = current * 2 + 2;\r\n currentVal = this.heap[current];\r\n leftChildVal = this.heap[leftChild];\r\n rightChildVal = this.heap[rightChild];\r\n }\r\n\r\n if (\r\n rightChild == this.elements &&\r\n this.compare(currentVal, leftChildVal) > 0\r\n ) {\r\n this.heap[leftChild] = currentVal;\r\n this.heap[current] = leftChildVal;\r\n }\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar rrr = false;\r\nvar aaa = {};\r\nvar bbb = 0;\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]);\r\n if (weight == 51480) rrr = true;\r\n if (rrr) {\r\n if (aaa[node1 + \",\" + node2] == undefined) aaa[node1 + \",\" + node2] = true;\r\n else bbb++;\r\n }\r\n addEdge(nodes, node1, node2, weight, i);\r\n}\r\n\r\nif (rrr) print(bbb);\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nfor (var i = p; i < k; i++) {\r\n queries.push((queries[i - 1] * a + b) % c);\r\n}\r\n\r\nvar dict = {};\r\nvar results = [];\r\nfor (var i = 0; i < queries.length; i++) {\r\n q = queries[i];\r\n if (dict[q] == undefined) dict[q] = mst(nodes, q);\r\n if (n > 17 && nodes[17][0][1] == 51480 && i % 1000 == 0)\r\n print(i / 1000 + \",\" + Object.keys(dict).length);\r\n results.push(dict[q]);\r\n}\r\n\r\nprint(results.reduce((a, b) => a ^ b, 0));\r\n\r\nfunction addEdge(nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => a[1] - b[1]);\r\n var sum = 0;\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);\r\n var eds = [];\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n nVisited++;\r\n sum += min[1];\r\n eds.push(min[2]);\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);\r\n }\r\n }\r\n }\r\n return sum;\r\n}\r\n"}, {"source_code": "function PriorityQueue(maxSize, compare) {\r\n this.maxSize = maxSize || 100000;\r\n this.heap = new Array(this.maxSize);\r\n this.elements = 0;\r\n this.compare = compare || ((a, b) => a - b);\r\n}\r\n\r\nPriorityQueue.prototype.size = function () {\r\n return this.elements;\r\n};\r\n\r\nPriorityQueue.prototype.isEmpty = function () {\r\n return this.elements == 0;\r\n};\r\n\r\nPriorityQueue.prototype.clear = function () {\r\n this.elements = 0;\r\n};\r\n\r\nPriorityQueue.prototype.peek = function () {\r\n return this.elements > 0 ? heap[0] : undefined;\r\n};\r\n\r\nPriorityQueue.prototype.insert = function (e) {\r\n if (this.elements == this.maxSize) throw \"Error max size exceeded\";\r\n this.heap[this.elements++] = e;\r\n\r\n var current = this.elements - 1;\r\n while (\r\n current > 0 &&\r\n this.compare(this.heap[Math.floor((current - 1) / 2)], this.heap[current]) >\r\n 0\r\n ) {\r\n var tmp = this.heap[Math.floor((current - 1) / 2)];\r\n this.heap[Math.floor((current - 1) / 2)] = this.heap[current];\r\n this.heap[current] = tmp;\r\n current = Math.floor((current - 1) / 2);\r\n }\r\n};\r\n\r\nPriorityQueue.prototype.pop = function () {\r\n if (this.elements == 0) return null;\r\n var el = this.heap[0];\r\n\r\n this.heap[0] = this.heap[this.elements - 1];\r\n this.elements--;\r\n\r\n var current = 0;\r\n var leftChild = current * 2 + 1;\r\n var rightChild = current * 2 + 2;\r\n var currentVal = this.heap[current];\r\n var leftChildVal = this.heap[leftChild];\r\n var rightChildVal = this.heap[rightChild];\r\n\r\n while (\r\n rightChild < this.elements &&\r\n (this.compare(currentVal, leftChildVal) > 0 ||\r\n this.compare(currentVal, rightChildVal) > 0)\r\n ) {\r\n if (this.compare(leftChildVal, rightChildVal) > 0) {\r\n this.heap[rightChild] = currentVal;\r\n this.heap[current] = rightChildVal;\r\n current = rightChild;\r\n } else {\r\n this.heap[leftChild] = currentVal;\r\n this.heap[current] = leftChildVal;\r\n current = leftChild;\r\n }\r\n leftChild = current * 2 + 1;\r\n rightChild = current * 2 + 2;\r\n currentVal = this.heap[current];\r\n leftChildVal = this.heap[leftChild];\r\n rightChildVal = this.heap[rightChild];\r\n }\r\n\r\n if (\r\n rightChild == this.elements &&\r\n this.compare(currentVal, leftChildVal) > 0\r\n ) {\r\n this.heap[leftChild] = currentVal;\r\n this.heap[current] = leftChildVal;\r\n }\r\n\r\n return el;\r\n};\r\n\r\nPriorityQueue.prototype.toArray = function () {\r\n return this.heap.filter((_, id) => id < this.elements);\r\n};\r\n\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nvar iniEdges = [];\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]);\r\n addEdge(iniEdges, nodes, node1, node2, weight, i);\r\n}\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nprint(JSON.stringify(iniEdges) + \",\"+p+ \",\"+k+ \",\"+a+ \",\"+b+\",\"+c)\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nfor (var i = p; i < k; i++) {\r\n queries.push((queries[i - 1] * a + b) % c);\r\n}\r\n\r\nvar dict = {};\r\nvar results = [];\r\nvar dictOrder = {};\r\nfor (var i = 0; i < queries.length; i++) {\r\n q = queries[i];\r\n if (dict[q] == undefined) dict[q] = mst(dictOrder, iniEdges, nodes, q);\r\n results.push(dict[q]);\r\n}\r\n\r\nprint(results.reduce((a, b) => a ^ b, 0));\r\n\r\nfunction addEdge(iniEdges, nodes, n1, n2, w, i) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n nodes[n1 - 1].push([n2 - 1, w, i]);\r\n nodes[n2 - 1].push([n1 - 1, w, i]);\r\n iniEdges.push([i, n1, n2, w]);\r\n}\r\n\r\nfunction mst(dictOrder, iniEdges, nodes, q) {\r\n var edges = new PriorityQueue(400, (a, b) => a[1] - b[1]);\r\n var iniEdges2 = iniEdges.map((i) => [i[0], i[1], i[2], Math.abs(i[3] - q)]);\r\n iniEdges2.sort((a, b) => a[3] - b[3]);\r\n var key = iniEdges2.map((i) => i[0]).join(\",\");\r\n\r\n var sum = 0;\r\n if (dictOrder[key] == undefined) {\r\n var visited = { 0: true };\r\n var nVisited = 1;\r\n for (var edge of nodes[0])\r\n edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);\r\n var eds = [];\r\n while (nVisited < nodes.length) {\r\n var min = edges.pop();\r\n var node = min[0];\r\n if (!visited[node]) {\r\n visited[node] = true;\r\n nVisited++;\r\n sum += min[1];\r\n eds.push(min[2]);\r\n for (var edge of nodes[node]) {\r\n if (!visited[edge[0]])\r\n edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);\r\n }\r\n }\r\n }\r\n dictOrder[key] = eds;\r\n } else {\r\n for (el of dictOrder[key]) sum += Math.abs(iniEdges[el][3] - q);\r\n }\r\n return sum;\r\n}\r\n"}, {"source_code": "var line = readline().split(\" \");\r\nvar n = parseInt(line[0]);\r\nvar m = parseInt(line[1]);\r\n\r\nvar nodes = Array(n);\r\nfor (var i = 0; i < m; i++) {\r\n var edge = readline().split(\" \");\r\n var node1 = parseInt(edge[0]);\r\n var node2 = parseInt(edge[1]);\r\n var weight = parseInt(edge[2]);\r\n addEdge(nodes, node1, node2, weight);\r\n}\r\n\r\nvar line = readline().split(\" \");\r\nvar p = parseInt(line[0]);\r\nvar k = parseInt(line[1]);\r\nvar a = parseInt(line[2]);\r\nvar b = parseInt(line[3]);\r\nvar c = parseInt(line[4]);\r\n\r\nvar queries = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\nfor (var i = p; i < k; i++) {\r\n queries.push((queries[i - 1] * a + b) % c);\r\n}\r\n\r\nvar dict = {};\r\nvar results = [];\r\nfor (var i = 0; i < queries.length; i++) {\r\n q = queries[i];\r\n if (dict[q] == undefined) dict[q] = mst(nodes, q);\r\n results.push(dict[q]);\r\n}\r\n\r\nprint(\r\n results.reduce((a, b) => a ^ b),\r\n 0\r\n);\r\n\r\nfunction addEdge(nodes, n1, n2, w) {\r\n if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];\r\n if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];\r\n nodes[n1 - 1].push([n2 - 1, w]);\r\n nodes[n2 - 1].push([n1 - 1, w]);\r\n}\r\n\r\nfunction mst(nodes, q) {\r\n var nodes2 = nodes.map((i) => i.map((j) => [j[0], Math.abs(j[1] - q)]));\r\n var edges = nodes2[0];\r\n var sum = 0;\r\n var vertexs = new Set();\r\n vertexs.add(0);\r\n while (edges.length > 0) {\r\n var min = edges.reduce((a, b) => (a[1] <= b[1] ? a : b), [0, Infinity]);\r\n sum += min[1];\r\n vertexs.add(min[0]);\r\n edges = edges.concat(nodes2[min[0]]);\r\n edges = edges.filter((i) => !vertexs.has(i[0]));\r\n }\r\n return sum;\r\n}\r\n"}], "src_uid": "2fad8bea91cf6db14b34271e88ab093c"} {"source_code": "var str = readline();\nvar len = str.length;\n\nfunction work(type, beg, end) {\n var arr = new Array(len);\n for (var i = 0; i < len; ++i) {\n arr[i] = Number(str[i]);\n }\n var ans = new Array(len);\n var down = false;\n\n while (true) {\n if (down) {\n if (arr[end] !== 0) {\n --arr[end];\n down = false;\n } else {\n arr[end] = 9;\n down = true;\n }\n }\n if (beg === end) {\n if (down) {\n return false;\n }\n if (type === 1) {\n if (arr[end] % 2 === 0) {\n ans[end] = String(arr[end] / 2);\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[end] % 2 === 0) {\n ans[end] = String((arr[end] + 10) / 2);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (beg +1 === end) {\n if (down) {\n if (arr[beg] !== 0) {\n --arr[beg];\n down = false;\n } else {\n arr[beg] = 9;\n down = true;\n }\n }\n if (down) {\n if (type === 1) {\n return false;\n } else {\n ans[beg] = \"9\";\n ans[end] = \"0\";\n return ans;\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end] + 1) {\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n type = 1;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = String(arr[end]);\n if (beg === 0 && ans[beg] === \"0\") {\n return false;\n }\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end]) {\n if (arr[beg] !== 9) {\n type = 1;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else {\n return false;\n }\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else if (arr[beg] === 0 && arr[end] === 9) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n }\n }\n}\n\nvar ans = work(1, 0, len - 1);\nif (ans) {\n print(ans.join(\"\"));\n} else {\n if (str[0] === \"1\") {\n ans = work(2, 1, len - 1);\n if (ans) {\n print(ans.join(\"\"));\n } else {\n print(0);\n }\n } else {\n print(0);\n }\n}", "positive_code": [{"source_code": "var str = readline();\nvar len = str.length;\n\nfunction work(type, beg, end) {\n var arr = new Array(len);\n for (var i = 0; i < len; ++i) {\n arr[i] = Number(str[i]);\n }\n var ans = new Array(len);\n var down = false;\n\n while (true) {\n if (beg > end) {\n if (type === 1 && !down || type === 2 && down) {\n return ans;\n } else {\n return false;\n }\n }\n if (down) {\n if (arr[end] !== 0) {\n --arr[end];\n down = false;\n } else {\n arr[end] = 9;\n down = true;\n }\n }\n if (beg === end) {\n if (down) {\n return false;\n }\n if (type === 1) {\n if (arr[end] % 2 === 0) {\n ans[end] = String(arr[end] / 2);\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[end] % 2 === 0) {\n ans[end] = String((arr[end] + 10) / 2);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n type = 1;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = String(arr[end]);\n if (beg === 0 && ans[beg] === \"0\") {\n return false;\n }\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end]) {\n if (arr[beg] !== 9) {\n type = 1;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else {\n return false;\n }\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else if (arr[beg] === 0 && arr[end] === 9) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n }\n }\n}\n\nvar ans = work(1, 0, len - 1);\nif (ans) {\n print(ans.join(\"\"));\n} else {\n if (str[0] === \"1\") {\n ans = work(2, 1, len - 1);\n if (ans) {\n print(ans.join(\"\"));\n } else {\n print(0);\n }\n } else {\n print(0);\n }\n}"}], "negative_code": [{"source_code": "var str = readline();\nvar len = str.length;\n\nfunction work(type, beg, end) {\n var arr = new Array(len);\n for (var i = 0; i < len; ++i) {\n arr[i] = Number(str[i]);\n }\n var ans = new Array(len);\n var down = false;\n\n while (true) {\n if (down) {\n if (arr[end] !== 0) {\n --arr[end];\n down = false;\n } else {\n arr[end] = 9;\n down = true;\n }\n }\n if (beg === end) {\n if (down) {\n return false;\n }\n if (type === 1) {\n if (arr[end] % 2 === 0) {\n ans[end] = String(arr[end] / 2);\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[end] % 2 === 0) {\n ans[end] = String((arr[end] + 10) / 2);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (beg +1 === end) {\n if (down) {\n if (arr[beg] !== 0) {\n --arr[beg];\n down = false;\n } else {\n arr[beg] = 9;\n down = true;\n }\n }\n if (type === 1 && down || type === 2 && !down) {\n return false;\n }\n if (arr[beg] === arr[end]) {\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n return ans;\n } else {\n return false;\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n type = 1;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = String(arr[end]);\n if (beg === 0 && ans[beg] === \"0\") {\n return false;\n }\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end]) {\n if (arr[beg] !== 9) {\n type = 1;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else {\n return false;\n }\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else if (arr[beg] === 0 && arr[end] === 9) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n }\n }\n}\n\nvar ans = work(1, 0, len - 1);\nif (ans) {\n print(ans.join(\"\"));\n} else {\n if (str[0] === \"1\") {\n ans = work(2, 1, len - 1);\n if (ans) {\n print(ans.join(\"\"));\n } else {\n print(0);\n }\n } else {\n print(0);\n }\n}"}, {"source_code": "var str = readline();\nvar len = str.length;\n\nfunction work(type, beg, end) {\n var arr = new Array(len);\n for (var i = 0; i < len; ++i) {\n arr[i] = Number(str[i]);\n }\n var ans = new Array(len);\n var down = false;\n\n while (true) {\n if (down) {\n if (arr[end] !== 0) {\n --arr[end];\n down = false;\n } else {\n arr[end] = 9;\n down = true;\n }\n }\n if (beg > end) {\n if (type === 1 && !down || type === 2 && down) {\n return ans;\n } else {\n return false;\n }\n } else if (beg === end) {\n if (down) {\n return false;\n }\n if (type === 1) {\n if (arr[end] % 2 === 0) {\n ans[end] = String(arr[end] / 2);\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[end] % 2 === 0) {\n ans[end] = String((arr[end] + 10) / 2);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n type = 1;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = String(arr[end]);\n if (beg === 0 && ans[beg] === \"0\") {\n return false;\n }\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end]) {\n if (arr[beg] !== 9) {\n type = 1;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else {\n return false;\n }\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else if (arr[beg] === 0 && arr[end] === 9) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n }\n }\n}\n\nvar ans = work(1, 0, len - 1);\nif (ans) {\n print(ans.join(\"\"));\n} else {\n if (str[0] === \"1\") {\n ans = work(2, 1, len - 1);\n if (ans) {\n print(ans.join(\"\"));\n } else {\n print(0);\n }\n } else {\n print(0);\n }\n}"}, {"source_code": "var str = readline();\nvar len = str.length;\n\nfunction work(type, beg, end) {\n var arr = new Array(len);\n for (var i = 0; i < len; ++i) {\n arr[i] = Number(str[i]);\n }\n var ans = new Array(len);\n var down = false;\n\n while (true) {\n if (down) {\n if (arr[end] !== 0) {\n --arr[end];\n down = false;\n } else {\n arr[end] = 9;\n down = true;\n }\n }\n if (beg > end) {\n if (type === 1 && !down || type === 2 && down) {\n return ans;\n } else {\n return false;\n }\n } else if (beg === end) {\n if (down) {\n return false;\n }\n if (type === 1) {\n if (arr[end] % 2 === 0) {\n ans[end] = String(arr[end] / 2);\n return ans;\n } else {\n return false;\n }\n } else {\n if (arr[end] % 2 === 0) {\n ans[end] = String((arr[end] + 10) / 2);\n return ans;\n } else {\n return false;\n }\n }\n }\n if (type === 1) {\n if (arr[beg] === arr[end]) {\n type = 1;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = String(arr[end]);\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n } else {\n if (arr[beg] === arr[end]) {\n if (arr[beg] !== 9) {\n type = 1;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else {\n return false;\n }\n } else if (arr[beg] === arr[end] + 1) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = String(arr[end] + 1);\n down = true;\n ++beg, --end;\n } else if (arr[beg] === 0 && arr[end] === 9) {\n type = 2;\n ans[beg] = \"9\";\n ans[end] = \"0\";\n ++beg, --end;\n } else {\n return false;\n }\n }\n }\n}\n\nvar ans = work(1, 0, len - 1);\nif (ans) {\n print(ans.join(\"\"));\n} else {\n if (str[0] === \"1\") {\n ans = work(2, 1, len - 1);\n if (ans) {\n print(ans.join(\"\"));\n } else {\n print(0);\n }\n } else {\n print(0);\n }\n}"}], "src_uid": "fc892e4aac2d60e53f377a582f5ba7d3"} {"source_code": "print(function(h, m) {\n\n\tfor (var x = 1; x <= 10; x++) {\n\t\tif (!h[x]) continue;\n\t\tvar ans = [x];\n\t\tvar a = [x, 0];\n\t\tvar last = x;\n\t\tfor (var i = 1; i < m; i++) {\n\t\t\tfor (var j = 1; j <= 10; j++)\n\t\t\t\tif (h[j] && j !== last && a[i % 2] + j > a[(i + 1) % 2]) {\n\t\t\t\t\ta[i % 2] += j;\n\t\t\t\t\tlast = j;\n\t\t\t\t\tans.push(j);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\tif (j === 11)\n\t\t\t\tbreak;\n\t\t}\n\t\tif (ans.length === m) {\n\t\t\treturn 'YES\\n' + ans.join(' ');\n\t\t}\n\t}\n\n\treturn 'NO';\n\n}(('0' + readline()).split('').map(function(v) {\n\treturn v === '1';\n}), +readline()));", "positive_code": [{"source_code": "print(function(h, m) {\n\tvar q = [];\n\n\tfunction d(step, x) {\n\t\tif (step === m) {\n\t\t\treturn true;\n\t\t}\n\t\tfor (var i = 1; i <= 10; i++) {\n\t\t\tvar y = step % 2 === 1 ? x + i : x - i;\n\t\t\tq[step] = i;\n\t\t\tif (h[i] && i !== q[step - 1] && ((x >= 0 && y < 0) || (x <= 0 && y > 0)) && d(step + 1, y)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tvar ans = d(0, 0);\n\tif (ans) return 'YES\\n' + q.join(' ');\n\treturn 'NO';\n\n}(('0' + readline()).split('').map(function(v) {\n\treturn v === '1';\n}), +readline()));"}], "negative_code": [{"source_code": "print(function(h, m) {\n\n\tvar ans = [];\n\tvar a = [0, 0];\n\tvar last = 0;\n\tfor (var i = 0; i < m; i++) {\n\t\tfor (var j = 1; j <= 10; j++)\n\t\t\tif (h[j] && j !== last && a[i % 2] + j > a[(i + 1) % 2]) {\n\t\t\t\ta[i % 2] += j;\n\t\t\t\tlast = j;\n\t\t\t\tans.push(j);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\tif (j === 11)\n\t\t\treturn 'NO';\n\t}\n\treturn 'YES\\n' + ans.join(' ');\n\n}(('0' + readline()).split('').map(function(v) {\n\treturn v === '1';\n}), +readline()));"}], "src_uid": "15aa3adb14c17023f71eec11e1c32efe"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function a(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=a();for(;e>0;)t(),e--}))},readline:h,nextNumbers:a,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{n.push(`${t+1} ${e+1} ${o+1} ${s+1} ${i+1} ${u+1}`),\"0\"==r[t][e]?r[t][e]=\"1\":r[t][e]=\"0\",\"0\"==r[o][s]?r[o][s]=\"1\":r[o][s]=\"0\",\"0\"==r[i][u]?r[i][u]=\"1\":r[i][u]=\"0\"};if(t%2==1)for(let t=0;t{\"0\"!=r[t][e]?\"0\"!=r[t+1][e]?\"0\"!=r[t][e+1]?\"0\"==r[t+1][e+1]&&s(t+1,e,t,e+1,t,e):s(t,e,t+1,e,t+1,e+1):s(t,e,t,e+1,t+1,e+1):s(t+1,e,t,e+1,t+1,e+1)},u=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)},l=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)};for(let n=t%2==0?0:1;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextCharacterMatrix(n)\n// \n// let flips = []\n// \n// let flip = (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) => {\n// flips.push(`${x1 + 1} ${y1 + 1} ${x2 + 1} ${y2 + 1} ${x3 + 1} ${y3 + 1}`)\n// \n// if (a[x1][y1] == \"0\") {\n// a[x1][y1] = \"1\"\n// } else {\n// a[x1][y1] = \"0\"\n// }\n// \n// if (a[x2][y2] == \"0\") {\n// a[x2][y2] = \"1\"\n// } else {\n// a[x2][y2] = \"0\"\n// }\n// \n// if (a[x3][y3] == \"0\") {\n// a[x3][y3] = \"1\"\n// } else {\n// a[x3][y3] = \"0\"\n// }\n// }\n// \n// if (n % 2 == 1) {\n// for (let i = 0; i < m - 1; i++) {\n// if (a[0][i] == \"1\" && a[0][i + 1] == \"1\") {\n// flip(0, i, 0, i + 1, 1, i)\n// } else if (a[0][i] == \"1\") {\n// flip(0, i, 1, i + 1, 1, i)\n// } else if (a[0][i + 1] == \"1\") {\n// flip(0, i + 1, 1, i + 1, 1, i)\n// }\n// }\n// }\n// \n// if (m % 2 == 1) {\n// for (let i = n % 2 == 0 ? 0 : 1; i < n - 1; ++i) {\n// if (a[i][0] == \"1\" && a[i + 1][0] == \"1\") {\n// flip(i, 0, i + 1, 0, i, 1)\n// } else if (a[i][0] == \"1\") {\n// flip(i, 0, i + 1, 1, i, 1)\n// } else if (a[i + 1][0] == \"1\") {\n// flip(i, 1, i + 1, 0, i + 1, 1)\n// }\n// }\n// }\n// \n// let proc3 = (x1: number, x2: number) => {\n// if (a[x1][x2] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2] == \"0\") {\n// flip(x1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1][x2 + 1] == \"0\") {\n// flip(x1, x2, x1 + 1, x2, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2 + 1] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1, x2)\n// }\n// }\n// \n// let proc1 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// let proc2 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// for (let i = n % 2 == 0 ? 0 : 1; i < n; i += 2) {\n// for (let j = m % 2 == 0 ? 0 : 1; j < m; j += 2) {\n// let nr0 = 0\n// let nr1 = 0\n// \n// if (a[i][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (nr1 == 0) {\n// continue\n// }\n// \n// if (nr1 == 3) {\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 2) {\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 1) {\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 4) {\n// flip(i, j, i + 1, j, i + 1, j + 1)\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// }\n// }\n// \n// io.puts(flips.length)\n// io.puts(flips.join(\" \"))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output2 = new Array();\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar count = 0;\n\t\tvar output = [];\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = new Array(M);\n\t\t\tvar tmp = next();\n\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\tlist[j][k] = myconv(tmp[k], 1);\n\t\t\t}\n\t\t}\n\t\tif(list[N - 1][M - 1] == 1 && list[N - 2][M - 1] == 1 && list[N - 1][M - 2] == 1 && list[N - 2][M - 2] == 1){\n\t\t\tvar s = (N - 1) + \" \" + M + \" \" + N + \" \" + (M - 1) + \" \" + N + \" \" + M;\n\t\t\toutput.push(s);\n\t\t\tcount++;\n\t\t\tlist[N - 1][M - 1] = 0;\n\t\t\tlist[N - 2][M - 1] = 0;\n\t\t\tlist[N - 1][M - 2] = 0;\n\t\t}\n\t\tfor(var x = 0; x < N - 1; x++){\n\t\t\tfor(var y = 0; y < M - 1; y++){\n\t\t\t\tvar hidariue = {\n\t\t\t\t\tv : list[x][y],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar hidarishita = {\n\t\t\t\t\tv : list[x + 1][y],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar migiue = {\n\t\t\t\t\tv : list[x][y + 1],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\tvar migishita = {\n\t\t\t\t\tv : list[x + 1][y + 1],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tvar check = hidariue.v + hidarishita.v + migiue.v + migishita.v;\n\t\t\t\tif(check == 4){\n\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\toutput.push(s);\n\t\t\t\t\tcount++;\n\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t}else if(check == 3){\n\t\t\t\t\tif(hidariue.v == 0){\n\t\t\t\t\t\tvar s = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 2){\n\t\t\t\t\tif(hidariue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && migiue.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + hidariue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 1){\n\t\t\t\t\tif(hidariue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t}else if(migiue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(migishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.unshift(count);\n\t\toutput2.push(myconv(output, 9));\n\t\t\n\t}\n\tmyout(myconv(output2, 9));\n}\n"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n let curLine = 0\n const T = parseInt(lines[curLine++])\n for (let t = 0; t < T; t++) {\n const [R, C] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const mat = []\n for (let r = 0; r < R; r++) {\n mat.push(lines[curLine++].trim().split('').map((x) => parseInt(x)))\n }\n\n const ans = []\n\n const apply = (r1, c1, r2, c2, r3, c3) => {\n mat[r1][c1] ^= 1\n mat[r2][c2] ^= 1\n mat[r3][c3] ^= 1\n ans.push([r1 + 1, c1 + 1, r2 + 1, c2 + 1, r3 + 1, c3 + 1])\n }\n \n for (let r = 0; r + 2 < R; r++) {\n for (let c = 0; c < C; c += 2) {\n if (c + 1 == C) {\n if (mat[r][c]) {\n apply(r, c, r + 1, c - 1, r + 1, c)\n }\n } else {\n if (mat[r][c] && mat[r][c + 1]) {\n apply(r, c, r, c + 1, r + 1, c)\n } else if (mat[r][c]) {\n apply(r, c, r + 1, c, r + 1, c + 1)\n } else if (mat[r][c + 1]) {\n apply(r, c + 1, r + 1, c, r + 1, c + 1)\n }\n }\n }\n }\n\n for (let c = 0; c + 1 < C; c++) {\n if (mat[R - 2][c] && mat[R - 1][c]) {\n apply(R - 2, c, R - 1, c, R - 2, c + 1)\n } else if (mat[R - 2][c]) {\n apply(R - 2, c, R - 2, c + 1, R - 1, c + 1)\n } else if (mat[R - 1][c]) {\n apply(R - 1, c, R - 2, c + 1, R - 1, c + 1)\n }\n }\n\n if (mat[R - 2][C - 1] && mat[R - 1][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 2)\n apply(R - 2, C - 2, R - 1, C - 2, R - 1, C - 1)\n } else if (mat[R - 2][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 2)\n apply(R - 1, C - 2, R - 1, C - 1, R - 2, C - 1)\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 1)\n } else if(mat[R - 1][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 1)\n apply(R - 2, C - 2, R - 1, C - 2, R - 1, C - 1)\n apply(R - 2, C - 1, R - 1, C - 2, R - 1, C - 1)\n }\n\n console.log(ans.length)\n ans.forEach((op) => console.log(op.join(' ')))\n } \n})\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [rowLen, colLen] = readLine().split(\" \").map(Number);\n const arr = [];\n for (let i = 0; i < rowLen; i++) {\n const _r = readLine().split(\"\").map(Number);\n arr.push(_r);\n }\n let count = 0;\n const ans = [];\n\n for (let row = 1; row <= rowLen; row++) {\n for (let col = 1; col <= colLen; col++) {\n let [dx, dy] = [1, 1];\n if (row === rowLen) dx = -1;\n if (col === colLen) dy = -1;\n\n if (arr[row - 1][col - 1] === 1) {\n count += 3;\n ans.push([row, col, row, col + dy, row + dx, col]);\n ans.push([row, col, row, col + dy, row + dx, col + dy]);\n ans.push([row, col, row + dx, col, row + dx, col + dy]);\n }\n }\n }\n console.log(count);\n for (let result of ans) console.log(result.join(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output2 = new Array();\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar count = 0;\n\t\tvar output = [];\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = new Array(M);\n\t\t\tvar tmp = next();\n\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\tlist[j][k] = myconv(tmp[k], 1);\n\t\t\t}\n\t\t}\n\t\tif(list[N - 1][M - 1] == 1 && list[N - 2][M - 1] == 1 && list[N - 1][M - 2] == 1 && list[N - 2][M - 2] == 1){\n\t\t\tvar s = (N - 1) + \" \" + M + \" \" + N + \" \" + (M - 1) + \" \" + N + \" \" + M;\n\t\t\toutput.push(s);\n\t\t\tcount++;\n\t\t\tlist[N - 1][M - 1] = 0;\n\t\t\tlist[N - 2][M - 1] = 0;\n\t\t\tlist[N - 1][M - 2] = 0;\n\t\t}\n\t\tfor(var x = 0; x < N - 1; x++){\n\t\t\tfor(var y = 0; y < M - 1; y++){\n\t\t\t\tvar hidariue = {\n\t\t\t\t\tv : list[x][y],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar hidarishita = {\n\t\t\t\t\tv : list[x + 1][y],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar migiue = {\n\t\t\t\t\tv : list[x][y + 1],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\tvar migishita = {\n\t\t\t\t\tv : list[x + 1][y + 1],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tvar check = hidariue.v + hidarishita.v + migiue.v + migishita.v;\n\t\t\t\tif(check == 4){\n\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\toutput.push(s);\n\t\t\t\t\tcount++;\n\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t}else if(check == 3){\n\t\t\t\t\tif(hidariue.v == 0){\n\t\t\t\t\t\tvar s = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][x] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 2){\n\t\t\t\t\tif(hidariue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && migiue.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + hidariue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 1){\n\t\t\t\t\tif(hidariue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t}else if(migiue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(migishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.unshift(count);\n\t\toutput2.push(myconv(output, 9));\n\t\t\n\t}\n\tmyout(myconv(output2, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output2 = new Array();\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = new Array(N);\n\t\tvar count = 0;\n\t\tvar output = [];\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tlist[j] = new Array(M);\n\t\t\tvar tmp = next();\n\t\t\tfor(var k = 0; k < M; k++){\n\t\t\t\tlist[j][k] = myconv(tmp[k], 1);\n\t\t\t}\n\t\t}\n\t\tif(list[N - 1][M - 1] == 1 && list[N - 2][M - 1] == 1 && list[N - 1][M - 2] == 1 && list[N - 2][M - 2] == 1){\n\t\t\tvar s = (N - 1) + \" \" + M + \" \" + N + \" \" + (M - 1) + \" \" + N + \" \" + M;\n\t\t\toutput.push(s);\n\t\t\tcount++;\n\t\t\tlist[N - 1][M - 1] = 0;\n\t\t\tlist[N - 2][M - 1] = 0;\n\t\t\tlist[N - 1][M - 2] = 0;\n\t\t}\n\t\tfor(var x = 0; x < N - 1; x++){\n\t\t\tfor(var y = 0; y < M - 1; y++){\n\t\t\t\tvar hidariue = {\n\t\t\t\t\tv : list[x][y],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar hidarishita = {\n\t\t\t\t\tv : list[x + 1][y],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 1),\n\t\t\t\t};\n\t\t\t\tvar migiue = {\n\t\t\t\t\tv : list[x][y + 1],\n\t\t\t\t\ts : (x + 1) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\tvar migishita = {\n\t\t\t\t\tv : list[x + 1][y + 1],\n\t\t\t\t\ts : (x + 2) + \" \" + (y + 2),\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tvar check = hidariue.v + hidarishita.v + migiue.v + migishita.v;\n\t\t\t\tif(check == 4){\n\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\toutput.push(s);\n\t\t\t\t\tcount++;\n\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t}else if(check == 3){\n\t\t\t\t\tif(hidariue.v == 0){\n\t\t\t\t\t\tvar s = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 0){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 2){\n\t\t\t\t\tif(hidariue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migishita.s + \" \" + hidarishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && migiue.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(migiue.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = migiue.s + \" \" + hidarishita.s + \" \" + hidariue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1 && migishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}else if(hidariue.v == 1 && hidarishita.v == 1){\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}\n\t\t\t\t}else if(check == 1){\n\t\t\t\t\tif(hidariue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + hidarishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y] = 0;\n\t\t\t\t\t}else if(migiue.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x][y + 1] = 0;\n\t\t\t\t\t}else if(hidarishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidariue.s + \" \" + hidarishita.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + hidarishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y] = 0;\n\t\t\t\t\t}else if(migishita.v == 1){\n\t\t\t\t\t\tcount += 3;\n\t\t\t\t\t\tvar s = hidarishita.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migishita.s + \" \" + migiue.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\ts = hidariue.s + \" \" + migiue.s + \" \" + migishita.s;\n\t\t\t\t\t\toutput.push(s);\n\t\t\t\t\t\tlist[x + 1][y + 1] = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.unshift(count);\n\t\toutput2.push(myconv(output, 9));\n\t\t\n\t}\n\tmyout(myconv(output2, 9));\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function a(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=a();for(;e>0;)t(),e--}))},readline:h,nextNumbers:a,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{n.push(`${t+1} ${e+1} ${o+1} ${s+1} ${i+1} ${u+1}`),\"0\"==r[t][e]?r[t][e]=\"1\":r[t][e]=\"0\",\"0\"==r[o][s]?r[o][s]=\"1\":r[o][s]=\"0\",\"0\"==r[i][u]?r[i][u]=\"1\":r[i][u]=\"0\"};if(t%2==1)for(let t=0;t{\"0\"!=r[t][e]?\"0\"!=r[t+1][e]?\"0\"!=r[t][e+1]?\"0\"==r[t+1][e+1]&&s(t+1,e,t,e+1,t,e):s(t,e,t+1,e,t+1,e+1):s(t,e,t,e+1,t+1,e+1):s(t+1,e,t,e+1,t+1,e+1)},u=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)},l=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)};for(let n=t%2==0?0:1;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextCharacterMatrix(n)\n// \n// let flips = []\n// \n// let flip = (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) => {\n// flips.push(`${x1 + 1} ${y1 + 1} ${x2 + 1} ${y2 + 1} ${x3 + 1} ${y3 + 1}`)\n// \n// if (a[x1][y1] == \"0\") {\n// a[x1][y1] = \"1\"\n// } else {\n// a[x1][y1] = \"0\"\n// }\n// \n// if (a[x2][y2] == \"0\") {\n// a[x2][y2] = \"1\"\n// } else {\n// a[x2][y2] = \"0\"\n// }\n// \n// if (a[x3][y3] == \"0\") {\n// a[x3][y3] = \"1\"\n// } else {\n// a[x3][y3] = \"0\"\n// }\n// }\n// \n// if (n % 2 == 1) {\n// for (let i = 0; i < m - 1; i++) {\n// if (a[0][i] == \"1\" && a[0][i + 1] == \"1\") {\n// flip(0, i, 0, i + 1, 1, i)\n// } else if (a[0][i] == \"1\") {\n// flip(0, i, 1, i + 1, 1, i)\n// } else if (a[0][i + 1] == \"1\") {\n// flip(0, i + 1, 1, i + 1, 1, i)\n// }\n// }\n// }\n// \n// if (m % 2 == 1) {\n// for (let i = n % 2 == 0 ? 0 : 1; i < n - 1; ++i) {\n// if (a[i][0] == \"1\" && a[i + 1][0] == \"1\") {\n// flip(i, 0, i + 1, 0, i, 1)\n// } else if (a[i][0] == \"1\") {\n// flip(i, 0, i + 1, 1, i, 1)\n// } else if (a[i + 1][0] == \"1\") {\n// flip(i, 1, i + 1, 0, i, 1)\n// }\n// }\n// }\n// \n// let proc3 = (x1: number, x2: number) => {\n// if (a[x1][x2] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2] == \"0\") {\n// flip(x1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1][x2 + 1] == \"0\") {\n// flip(x1, x2, x1 + 1, x2, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2 + 1] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1, x2)\n// }\n// }\n// \n// let proc1 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// let proc2 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// for (let i = n % 2 == 0 ? 0 : 1; i < n; i += 2) {\n// for (let j = m % 2 == 0 ? 0 : 1; j < m; j += 2) {\n// let nr0 = 0\n// let nr1 = 0\n// \n// if (a[i][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (nr1 == 0) {\n// continue\n// }\n// \n// if (nr1 == 3) {\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 2) {\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 1) {\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 4) {\n// flip(i, j, i + 1, j, i + 1, j + 1)\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// }\n// }\n// \n// io.puts(flips.length)\n// io.puts(flips.join(\" \"))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "e86044b3438f934b6a9e76854053f117"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst mxN = 2e5+1;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tconst frq = []; //Array(mxN).fill(0);\r\n\t\tfor (const x of a) {\r\n\t\t\tif (!frq[x]) {\r\n\t\t\t\tfrq[x] = 0;\r\n\t\t\t}\r\n\t\t\tfrq[x]++;\r\n\t\t}\r\n\r\n\t\ta = [...new Set(a)];\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tconst ans = [];\r\n\t\tlet cost = 0, extras = [], i = 0;\r\n\t\tfor (let x = 0; x <= n; x++) {\r\n\t\t\tif (a[i] == x) {\r\n\t\t\t\tans[x] = cost + frq[x];\r\n\t\t\t\textras.push(...Array(frq[x]-1).fill(x));\r\n\t\t\t\ti++;\r\n\t\t\t} else { // a[i] > x\r\n\t\t\t\tans[x] = cost;\r\n\t\t\t\tif (extras.length) {\r\n\t\t\t\t\tcost += x - extras.pop();\r\n\t\t\t\t} else {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twhile (ans.length < n+1) {\r\n\t\t\tans.push(-1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let map = new Map();\r\n const res = [];\r\n const heap = [];\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n let cur = 0,\r\n op = 0;\r\n for (let i = 0; i <= n; i++) {\r\n if (cur === i) {\r\n if (map.has(i)) {\r\n res[i] = op + map.get(i);\r\n if (map.get(i) > 1) {\r\n heap.push([i, map.get(i) - 1]);\r\n }\r\n cur++;\r\n } else {\r\n res[i] = op;\r\n if (heap.length) {\r\n const top = heap[heap.length - 1];\r\n op += i - top[0];\r\n top[1]--;\r\n while (heap.length && heap[heap.length - 1][1] === 0) heap.pop();\r\n cur++;\r\n }\r\n }\r\n } else {\r\n res[i] = -1;\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let map = new Map();\r\n const res = [];\r\n const heap = new Heap((a, b) => b[0] - a[0]);\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n let cur = 0,\r\n op = 0;\r\n for (let i = 0; i <= n; i++) {\r\n if (cur === i) {\r\n if (map.has(i)) {\r\n res[i] = op + map.get(i);\r\n if (map.get(i) > 1) {\r\n heap.push([i, map.get(i) - 1]);\r\n }\r\n cur++;\r\n } else {\r\n res[i] = op;\r\n if (heap.size()) {\r\n const top = heap.top();\r\n op += i - top[0];\r\n top[1]--;\r\n if (top[1] === 0) heap.pop();\r\n cur++;\r\n }\r\n }\r\n } else {\r\n res[i] = -1;\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let cnt = {};\n for (let i=0; i1){\n stack.push(i);\n cnt[i]--;\n }\n if (cnt[i]==0){\n if (stack.length){\n let top = stack.pop();\n fix_zeros_price += i-top;\n } else {\n ans.push(-1);\n break;\n }\n }\n }\n while (ans.length<=n) ans.push(-1)\n L(cnt)\n\n return ans;\n};\n "}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let cnt = af(n + 1).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let x = nextInt();\r\n cnt[x]++;\r\n }\r\n let sum = 0; // sum to complete j < i\r\n let rem = []; // indices with extra\r\n let res = af(n + 1).fill(0);\r\n let i = 0;\r\n for (; i <= n; i++) {\r\n let ans = sum;\r\n if (cnt[i] > 0) {\r\n ans += cnt[i];\r\n }\r\n printf(\"%d \", ans);\r\n if (cnt[i] > 1) {\r\n rem.push(i);\r\n res[i] = cnt[i] - 1;\r\n }\r\n else if (cnt[i] == 0) {\r\n if (rem.length > 0) {\r\n let last = rem[rem.length - 1];\r\n sum += i - last;\r\n res[last]--;\r\n if (res[last] == 0) {\r\n rem.pop();\r\n }\r\n }\r\n else {\r\n i++;\r\n break;\r\n }\r\n }\r\n }\r\n for (; i <= n; i++) {\r\n printf(\"-1 \");\r\n }\r\n printf(\"\\n\");\r\n }\r\n}\r\n"}, {"source_code": "// Generated by CoffeeScript 1.8.0\n;(function() {\n var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup;\n\n floor = Math.floor, min = Math.min;\n\n\n /*\n Default comparison function to be used\n */\n\n defaultCmp = function(x, y) {\n if (x < y) {\n return -1;\n }\n if (x > y) {\n return 1;\n }\n return 0;\n };\n\n\n /*\n Insert item x in list a, and keep it sorted assuming a is sorted.\n \n If x is already in a, insert it to the right of the rightmost x.\n \n Optional args lo (default 0) and hi (default a.length) bound the slice\n of a to be searched.\n */\n\n insort = function(a, x, lo, hi, cmp) {\n var mid;\n if (lo == null) {\n lo = 0;\n }\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (lo < 0) {\n throw new Error('lo must be non-negative');\n }\n if (hi == null) {\n hi = a.length;\n }\n while (lo < hi) {\n mid = floor((lo + hi) / 2);\n if (cmp(x, a[mid]) < 0) {\n hi = mid;\n } else {\n lo = mid + 1;\n }\n }\n return ([].splice.apply(a, [lo, lo - lo].concat(x)), x);\n };\n\n\n /*\n Push item onto heap, maintaining the heap invariant.\n */\n\n heappush = function(array, item, cmp) {\n if (cmp == null) {\n cmp = defaultCmp;\n }\n array.push(item);\n return _siftdown(array, 0, array.length - 1, cmp);\n };\n\n\n /*\n Pop the smallest item off the heap, maintaining the heap invariant.\n */\n\n heappop = function(array, cmp) {\n var lastelt, returnitem;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n lastelt = array.pop();\n if (array.length) {\n returnitem = array[0];\n array[0] = lastelt;\n _siftup(array, 0, cmp);\n } else {\n returnitem = lastelt;\n }\n return returnitem;\n };\n\n\n /*\n Pop and return the current smallest value, and add the new item.\n \n This is more efficient than heappop() followed by heappush(), and can be\n more appropriate when using a fixed size heap. Note that the value\n returned may be larger than item! That constrains reasonable use of\n this routine unless written as part of a conditional replacement:\n if item > array[0]\n item = heapreplace(array, item)\n */\n\n heapreplace = function(array, item, cmp) {\n var returnitem;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n returnitem = array[0];\n array[0] = item;\n _siftup(array, 0, cmp);\n return returnitem;\n };\n\n\n /*\n Fast version of a heappush followed by a heappop.\n */\n\n heappushpop = function(array, item, cmp) {\n var _ref;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (array.length && cmp(array[0], item) < 0) {\n _ref = [array[0], item], item = _ref[0], array[0] = _ref[1];\n _siftup(array, 0, cmp);\n }\n return item;\n };\n\n\n /*\n Transform list into a heap, in-place, in O(array.length) time.\n */\n\n heapify = function(array, cmp) {\n var i, _i, _j, _len, _ref, _ref1, _results, _results1;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n _ref1 = (function() {\n _results1 = [];\n for (var _j = 0, _ref = floor(array.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }\n return _results1;\n }).apply(this).reverse();\n _results = [];\n for (_i = 0, _len = _ref1.length; _i < _len; _i++) {\n i = _ref1[_i];\n _results.push(_siftup(array, i, cmp));\n }\n return _results;\n };\n\n\n /*\n Update the position of the given item in the heap.\n This function should be called every time the item is being modified.\n */\n\n updateItem = function(array, item, cmp) {\n var pos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n pos = array.indexOf(item);\n if (pos === -1) {\n return;\n }\n _siftdown(array, 0, pos, cmp);\n return _siftup(array, pos, cmp);\n };\n\n\n /*\n Find the n largest elements in a dataset.\n */\n\n nlargest = function(array, n, cmp) {\n var elem, result, _i, _len, _ref;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n result = array.slice(0, n);\n if (!result.length) {\n return result;\n }\n heapify(result, cmp);\n _ref = array.slice(n);\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n elem = _ref[_i];\n heappushpop(result, elem, cmp);\n }\n return result.sort(cmp).reverse();\n };\n\n\n /*\n Find the n smallest elements in a dataset.\n */\n\n nsmallest = function(array, n, cmp) {\n var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n if (n * 10 <= array.length) {\n result = array.slice(0, n).sort(cmp);\n if (!result.length) {\n return result;\n }\n los = result[result.length - 1];\n _ref = array.slice(n);\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n elem = _ref[_i];\n if (cmp(elem, los) < 0) {\n insort(result, elem, 0, null, cmp);\n result.pop();\n los = result[result.length - 1];\n }\n }\n return result;\n }\n heapify(array, cmp);\n _results = [];\n for (i = _j = 0, _ref1 = min(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {\n _results.push(heappop(array, cmp));\n }\n return _results;\n };\n\n _siftdown = function(array, startpos, pos, cmp) {\n var newitem, parent, parentpos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n newitem = array[pos];\n while (pos > startpos) {\n parentpos = (pos - 1) >> 1;\n parent = array[parentpos];\n if (cmp(newitem, parent) < 0) {\n array[pos] = parent;\n pos = parentpos;\n continue;\n }\n break;\n }\n return array[pos] = newitem;\n };\n\n _siftup = function(array, pos, cmp) {\n var childpos, endpos, newitem, rightpos, startpos;\n if (cmp == null) {\n cmp = defaultCmp;\n }\n endpos = array.length;\n startpos = pos;\n newitem = array[pos];\n childpos = 2 * pos + 1;\n while (childpos < endpos) {\n rightpos = childpos + 1;\n if (rightpos < endpos && !(cmp(array[childpos], array[rightpos]) < 0)) {\n childpos = rightpos;\n }\n array[pos] = array[childpos];\n pos = childpos;\n childpos = 2 * pos + 1;\n }\n array[pos] = newitem;\n return _siftdown(array, startpos, pos, cmp);\n };\n\n Heap = (function() {\n Heap.push = heappush;\n\n Heap.pop = heappop;\n\n Heap.replace = heapreplace;\n\n Heap.pushpop = heappushpop;\n\n Heap.heapify = heapify;\n\n Heap.updateItem = updateItem;\n\n Heap.nlargest = nlargest;\n\n Heap.nsmallest = nsmallest;\n\n function Heap(cmp) {\n this.cmp = cmp != null ? cmp : defaultCmp;\n this.nodes = [];\n }\n\n Heap.prototype.push = function(x) {\n return heappush(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.pop = function() {\n return heappop(this.nodes, this.cmp);\n };\n\n Heap.prototype.peek = function() {\n return this.nodes[0];\n };\n\n Heap.prototype.contains = function(x) {\n return this.nodes.indexOf(x) !== -1;\n };\n\n Heap.prototype.replace = function(x) {\n return heapreplace(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.pushpop = function(x) {\n return heappushpop(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.heapify = function() {\n return heapify(this.nodes, this.cmp);\n };\n\n Heap.prototype.updateItem = function(x) {\n return updateItem(this.nodes, x, this.cmp);\n };\n\n Heap.prototype.clear = function() {\n return this.nodes = [];\n };\n\n Heap.prototype.empty = function() {\n return this.nodes.length === 0;\n };\n\n Heap.prototype.size = function() {\n return this.nodes.length;\n };\n\n Heap.prototype.clone = function() {\n var heap;\n heap = new Heap();\n heap.nodes = this.nodes.slice(0);\n return heap;\n };\n\n Heap.prototype.toArray = function() {\n return this.nodes.slice(0);\n };\n\n Heap.prototype.insert = Heap.prototype.push;\n\n Heap.prototype.top = Heap.prototype.peek;\n\n Heap.prototype.front = Heap.prototype.peek;\n\n Heap.prototype.has = Heap.prototype.contains;\n\n Heap.prototype.copy = Heap.prototype.clone;\n\n return Heap;\n\n })();\n\n (function(root, factory) {\n // if (typeof define === 'function' && define.amd) {\n // return define([], factory);\n // } else if (typeof exports === 'object') {\n // return module.exports = factory();\n // } else {\n return root.Heap = factory();\n // }\n })(this, function() {\n return Heap;\n });\n\n}).call(this);\nconst Heap = this.Heap\n\nconst readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n return o\n }, {})\n let mex = -1\n for (let i = 0; i <= n; i++) {\n if (!map[i]) {\n mex = i\n break\n }\n }\n const ans = Array(n + 1)\n let agg = 0\n const h = new Heap((a, b) => b - a)\n let fail = 0\n for (let i = 0; i <= n; i++) {\n if (i < mex) {\n // i -> i + 1\n ans[i] = map[i]\n } else if (i > mex) {\n if (fail) {\n ans[i] = -1\n continue\n }\n let now = agg\n // i -> i + 1\n if (map[i]) now += map[i]\n ans[i] = now\n } else {\n ans[i] = 0\n }\n //\n if (!map[i]) {\n if (h.empty()) {\n fail = 1\n continue\n }\n const p = h.peek()\n if (--map[p] <= 1) h.pop()\n agg += i - p\n } else if (map[i] > 1) {\n h.push(i)\n }\n }\n return ans.join(' ')\n}\n"}], "negative_code": [], "src_uid": "18d19440e6df7316af0682ce99911738"} {"source_code": "function getLine(){\n return readline().split(' ').map(function(x){\n return parseInt(x); \n });\n}\n\nfunction getInt(){\n return parseInt(readline());\n}\n\nvar L = getLine();\nvar n = L[0];\nvar m = L[1];\nvar P = [];\n\nfor(var i = 0; i < n; i++){\n P[i] = getLine();\n}\nvar T = [];\nvar G = [];\nfor(var i = 0; i < m; i++){\n T[i] = 0;\n}\nG[0] = 0;\nfor(var i = 1; i < n; i++){\n var min = n;\n for(var j = 0; j < m; j++){\n if(P[i - 1][j] > P[i][j]){\n T[j] = i;\n }\n min = Math.min(min, T[j]);\n }\n G[i] = min;\n}\nvar k = getInt();\nfor(var i = 0; i < k; i++){\n var L = getLine();\n var l = L[0] - 1;\n var r = L[1] - 1;\n print(G[r] <= l ? \"Yes\" : \"No\");\n}", "positive_code": [{"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]);\nvar m = Number(s[1]);\n\nvar a = new Array(n);\nfor (var i = 0; i < n; ++i) {\n a[i] = readline().split(\" \").map(function(each) {return Number(each)});\n}\n\nvar track = new Array(n);\nfor (i = 0; i < n; ++i) {\n track[i] = new Array(m);\n}\n\nvar track1 = new Array(n);\ntrack1[0] = 1;\n\nfor (j = 0; j < m; ++j) {\n track[0][j] = 1;\n}\n\nfor (i = 1; i < n; ++i) {\n var max = 0\n for (j = 0; j < m; ++j) {\n if (a[i][j] >= a[i - 1][j]) {\n track[i][j] = track[i - 1][j] + 1;\n } else {\n track[i][j] = 1;\n }\n\n if (track[i][j] > max)\n max = track[i][j];\n }\n\n track1[i] = max;\n}\n\n//for (i = 0; i < n; ++i) {\n// for (j = 0; j < m; ++j) {\n// write(track[i][j]);\n// }\n// print();\n//}\n\nfunction nonDesc(l, r) {\n if (track1[r - 1] >= r - l + 1) {\n return \"Yes\";\n }\n\n return \"No\";\n}\n\nvar k = Number(readline());\n\nfor (i = 0; i < k; ++i) {\n var s = readline().split(\" \");\n var l = Number(s[0]);\n var r = Number(s[1]);\n print(nonDesc(l, r));\n}\n"}], "negative_code": [{"source_code": "function getLine(){\n return readline().split(' ').map(function(x){\n return parseInt(x); \n });\n}\n\nfunction getInt(){\n return parseInt(readline());\n}\n\nvar L = getLine();\nvar n = L[0];\nvar m = L[1];\nvar P = [];\n\nfor(var i = 0; i < n; i++){\n P[i] = getLine();\n}\nvar T = [];\nvar G = [];\nfor(var i = 0; i < m; i++){\n T[i] = 0;\n}\nG[0] = 0;\nfor(var i = 1; i < n; i++){\n var min = n;\n for(var j = 0; j < m; j++){\n if(P[i - 1][j] > P[i][j]){\n T[j] = i;\n }\n min = Math.min(min, T[j]);\n }\n G[i] = min;\n}\nvar k = getInt();\nfor(var i = 0; i < k; i++){\n var L = getLine();\n var l = L[0] - 1;\n var r = L[1] - 1;\n print(G[r] <= l ? \"YES\" : \"NO\");\n}"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]);\nvar m = Number(s[1]);\n\nvar a = new Array(n);\nfor (var i = 0; i < n; ++i) {\n a[i] = readline().split(\" \").map(function(each) {return Number(each)});\n}\n\nvar track = new Array(n);\nfor (i = 0; i < n; ++i) {\n track[i] = new Array(m);\n}\n\nfor (j = 0; j < m; ++j) {\n track[0][j] = 1;\n}\n\nfor (i = 1; i < n; ++i) {\n for (j = 0; j < m; ++j) {\n if (a[i][j] >= a[i - 1][j]) {\n track[i][j] = track[i - 1][j] + 1;\n } else {\n track[i][j] = 1;\n }\n }\n}\n\n//for (i = 0; i < n; ++i) {\n// for (j = 0; j < m; ++j) {\n// write(track[i][j]);\n// }\n// print();\n//}\n\nfunction nonDesc(l, r) {\n for (var i = 0; i < m; ++i) {\n if (track[r - 1][i] === r - l + 1) {\n return \"Yes\";\n }\n }\n \n return \"No\";\n}\n\nvar k = Number(readline());\n\nfor (i = 0; i < k; ++i) {\n var s = readline().split(\" \");\n var l = Number(s[0]);\n var r = Number(s[1]);\n print(nonDesc(l, r));\n}"}, {"source_code": "var s = readline().split(\" \");\nvar n = Number(s[0]);\nvar m = Number(s[1]);\n\nvar a = new Array(n);\nfor (var i = 0; i < n; ++i) {\n a[i] = readline().split(\" \").map(function(each) {return Number(each)});\n}\n\nvar track = new Array(n);\nfor (i = 0; i < n; ++i) {\n track[i] = new Array(m);\n}\n\nfor (j = 0; j < m; ++j) {\n track[0][j] = 1;\n}\n\nfor (i = 1; i < n; ++i) {\n for (j = 0; j < m; ++j) {\n if (a[i][j] >= a[i - 1][j]) {\n track[i][j] = track[i - 1][j] + 1;\n } else {\n track[i][j] = 1;\n }\n }\n}\n\n//for (i = 0; i < n; ++i) {\n// for (j = 0; j < m; ++j) {\n// write(track[i][j]);\n// }\n// print();\n//}\n\nfunction nonDesc(l, r) {\n for (var i = 0; i < m; ++i) {\n if (track[r - 1][i] === r - l + 1) {\n return \"YES\";\n }\n }\n \n return \"NO\";\n}\n\nvar k = Number(readline());\n\nfor (i = 0; i < k; ++i) {\n var s = readline().split(\" \");\n var l = Number(s[0]);\n var r = Number(s[1]);\n print(nonDesc(l, r));\n}\n"}], "src_uid": "f5e57cdca91f36f9b2b20eabbe0d355d"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const m = rn(),\r\n a = rns(m);\r\n const n = Math.log2(m);\r\n let res = 0;\r\n const swap = (i, j) => [a[i], a[j]] = [a[j], a[i]];\r\n for (let i = 1; i <= n; i++) {\r\n const d = 2 ** i,\r\n d1 = d / 2;\r\n for (let j = d - 1; j < m; j += d) {\r\n const k = j - d1;\r\n if (a[j] + d1 === a[k]) {\r\n res++;\r\n swap(j, k);\r\n } else if (a[j] === a[k] + d1) {\r\n continue;\r\n } else {\r\n return -1;\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let ans = 0,\r\n op = 0;\r\n const trav = (n) => {\r\n const helper = (st, end, k) => {\r\n if (st === end) {\r\n return { min: arr[st], max: arr[st] };\r\n }\r\n let mid = Math.floor((st + end) / 2);\r\n let left = helper(st, mid, k / 2);\r\n let right = helper(mid + 1, end, k / 2);\r\n if (left.min > right.min) op++;\r\n let min = Math.min(left.min, left.max, right.min, right.max);\r\n let max = Math.max(left.min, left.max, right.min, right.max);\r\n let dif = Math.abs(min - max) + 1;\r\n if (dif !== k) ans = -1;\r\n return { min: min, max: max };\r\n };\r\n helper(0, n - 1, n);\r\n };\r\n trav(n);\r\n if (ans === -1) console.log(-1);\r\n else console.log(op);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nlet ans\nfunction solve(n, arr) {\n if (n === 1) return 0\n ans = 0\n helper(arr, 0, n - 1)\n// console.log(arr.join(' '))\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) return -1\n }\n return ans\n}\nfunction helper(arr, l, r) {\n if (l + 1 === r) {\n if (arr[l] > arr[r]) {\n [arr[l], arr[r]] = [arr[r], arr[l]]\n ans++\n }\n } else {\n const h = (r - l + 1) / 2\n helper(arr, l, l + h - 1)\n helper(arr, l + h, r)\n if (arr[l] > arr[l + h]) {\n ans++\n for (let i = 0; i < h; i++) {\n [arr[l + i], arr[l + h + i]] = [arr[l + h + i], arr[l + i]]\n }\n }\n }\n}\n"}], "negative_code": [], "src_uid": "61bbe7bc4698127511a0bdbc717e2526"} {"source_code": "function main() {\n [n, m] = readInts()\n diff = []\n sm = 0\n for (i = 0; i inp += v+\"\\n\");\nrl.on('close', () => {\n inp = inp.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n if (TESTCASES){\n const cnt = readInt()\n for (let i = 0; i a - b)\n else a.sort((a, b) => b - a)\n}\nvar ptr = 0\nfunction print(...x) {console.log(...x)}\nfunction readInt() {return +inp[ptr++]}\nfunction readLine() {return inp[ptr++]}\nfunction readInts() {return inp[ptr++].split(' ').map(a => +a)}\n", "positive_code": [{"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum = 0,sumArc = 0;\n for(var i = 0; i < n ;i++){\n var s = readline().split(' ');\n sum += +s[0];\n sumArc += +s[1];\n me.push(s[0] - s[1]);\n } \n if(sum <= m){\n print(0);\n return;\n }\n\n if(sumArc > m){\n print(-1);\n return;\n }\n\n a = sum-m;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a > 0){\n res++;\n a -= me.pop();\n }\n\n print(res);\n}\n\nmain();"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, m] = is.nextArray(Number);\n let normal = 0, a, b;\n const diff = [];\n for (let i = 0; i < n; i += 1) {\n [a, b] = is.nextArray(Number);\n diff.push(a - b);\n normal += a;\n }\n\n\n diff.sort((u, v) => u - v);\n diff.reverse();\n let song = 0;\n for (let i = 0; normal > m && i < n; i += 1) {\n normal -= diff[i];\n song += 1;\n }\n console.log(normal > m ? -1 : song);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++].trim(); // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n const [n, m] = readInts(input, ptr++)\n const as = new Array(n)\n const bs = new Array(n)\n for(let i = 0; i < n; i++) {\n let x = readInts(input, ptr++);\n as[i] = x[0]\n bs[i] = x[1]\n }\n // console.log(as, bs)\n let sumA = as.reduce((a, b) => a + b, 0)\n let sumB = bs.reduce((a, b) => a + b, 0)\n if(sumA <= m) wr(0)\n else if(sumB > m) wr(-1)\n else {\n let diff = new Array(n)\n for(let i = 0; i < n; i++) {\n diff[i] = as[i] - bs[i]\n }\n sort(diff, false)\n const d = sumA - m\n let x = 0\n let count = 0\n let i = 0\n while(x < d) {\n x += diff[i++]\n count++\n }\n wr(count)\n }\n}"}], "negative_code": [{"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum = 0,sumArc = 0;\n for(var i = 0; i m){\n print(-1);\n return;\n }\n\n a = sum-m;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a <= 0){\n res++;\n a -= me.pop()\n }\n\n print(res);\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum = 0,sumArc = 0;\n for(var i = 0; i m){\n print(-1);\n return;\n }\n\n a = sum-sumArc;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a <= 0){\n res++;\n a -= me.pop()\n }\n\n print(res);\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum,sumArc;\n for(var i = 0;i m){\n print(-1);\n return;\n }\n\n a = sum-sumArc;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a <= 0){\n res++;\n a -= me.pop()\n }\n\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum = 0,sumArc = 0;\n for(var i = 0; i < n ;i++){\n var s = readline().split(' ');\n sum += +s[0];\n sumArc += +s[1];\n me.push(s[0] - s[1]);\n } \n if(sum <= m){\n print(0);\n return;\n }\n\n if(sumArc > m){\n print(-1);\n return;\n }\n\n a = sum-m;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a > 0){\n print('asd')\n res++;\n a -= me.pop();\n print(a);\n }\n\n print(res);\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum,sumArc;\n for(var i = 0;i m){\n print(-1);\n return;\n }\n\n a = sum-sumArc;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a <= 0){\n res++;\n a -= me.pop()\n }\n\n print(res);\n}\n\nmain();"}, {"source_code": "function main(){\n var a = readline().split(' ');\n var n = a[0];\n var m = a[1];\n var me = [],sum,sumArc;\n for(var i = 0;i m){\n print(-1);\n return;\n }\n\n a = sum-sumArc;\n me.sort((a,b)=>a-b);\n var res = 0;\n while(a <= 0){\n res++;\n a -= me.pop()\n }\n\n}\n\nmain();"}], "src_uid": "91541d10c5ae52be8da33412359bd019"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(nums) {\r\n const [a, b, c] = nums\r\n return [a+b+c,b+c,c].join(' ')\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1], c = k[2];\n console.log(a + b + c, b + c, c);\n }\n});\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [a, b, c] = readline().split(' ').map(Number);\r\n output(`${a + b + c} ${b + c} ${c}`);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(nums) {\r\n const [a, b, c] = nums,\r\n max = Math.max(...nums);\r\n let x = 0,\r\n y = 0,\r\n z = 0;\r\n if (max === a) {\r\n x = a;\r\n z = x + c;\r\n y = z + b;\r\n } else if (max === b) {\r\n y = b;\r\n x = y + a;\r\n z = x + c;\r\n } else {\r\n z = c;\r\n y = z + b;\r\n x = y + a;\r\n }\r\n return [x, y, z].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const solve = (a,b,c)=>{\r\n console.log(`${a+b+c} ${b+c} ${c}`);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n solve(...n);\r\n }\r\n}\r\nmain();"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nconst compute = (x, y, a, c) => {\n if (x + a - (x % y) > c) {\n return x + a - (x % y);\n } else {\n return y * x + a;\n }\n};\n\nrl.on(\"line\", function (line) {\n if (lines !== 0) {\n let [a, b, c] = line.split(\" \").map(BigInt);\n let x = c + 1n,\n y = a + 1n,\n z = b + 1n;\n while (x % y !== a || y % z !== b || z % x !== c) {\n if (x % y !== a) {\n x = compute(x, y, a, c);\n continue;\n } else if (y % z !== b) {\n y = compute(y, z, b, a);\n continue;\n } else if (z % x !== c) {\n z = compute(z, x, c, b);\n continue;\n }\n }\n console.log([x, y, z].join(\" \"));\n }\n\n lines++;\n});\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [a, b, c] = ra();\n LT({a, b, c});\n // PROCESSING:\n let x = BigInt(a)+BigInt(b)*BigInt(1e8);\n return [x.toString(), b, (x+BigInt(c)).toString()];\n};\n "}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [a, b, c] = ra();\n let result = [a + b + c, b + c, c];\n return result.join(' ');\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var number_of_test = readline();\r\n\r\n\r\nfunction get_numbers_with_solution(){\r\n var arr = readline().split(' ') ;\r\n var a = parseInt( arr[0] ),\r\n b = parseInt( arr[1] ),\r\n c = parseInt( arr[2] )\r\n var z = c, \r\n y = c + b,\r\n x = c + b + a;\r\n print(x + \" \" + y + \" \" + z ) ;\r\n}\r\n\r\nfor(var i = 0 ; i < number_of_test ; i++ ) {\r\n \r\n get_numbers_with_solution();\r\n\r\n}"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n\tvar t = lines[0];\n console.log(1, 1, 1);\n});\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [a, b, c] = readline().split(' ').map(Number);\r\n output(`${a + b + c} ${a + b} ${c}`);\r\n }\r\n}\r\n"}, {"source_code": "var number_of_test = readline();\r\n\r\n\r\nfunction get_numbers_with_solution(){\r\n var a = parseInt( readline() ), \r\n b = parseInt( readline() ),\r\n c = parseInt( readline() );\r\n \r\n var z = c, \r\n y = c + b,\r\n x = c + b + a;\r\n \r\n print(x + \" \" + y + \" \" + z + \"\\n\") ;\r\n}\r\n\r\nfor(var i = 0 ; i < number_of_test ; i++ ) {\r\n \r\n get_numbers_with_solution();\r\n\r\n}\r\n"}, {"source_code": "var number_of_test = readline();\r\n\r\n\r\nfor(var i = 0 ; i < number_of_test ; i++ ) {\r\n \r\n var a = parseInt( readline() ), \r\n b = parseInt( readline() ),\r\n c = parseInt( readline() );\r\n \r\n var z = c, \r\n y = c + b,\r\n x = c + b + a;\r\n \r\n print(x + \" \" + y + \" \" + z ) \r\n\r\n}\r\n"}, {"source_code": "var number_of_test = readline();\r\n\r\n\r\nfor(var i = 0 ; i < number_of_test ; i++ ) {\r\n \r\n var a = parseInt( readline() ), \r\n b = parseInt( readline() ),\r\n c = parseInt( readline() );\r\n \r\n var z = c, \r\n y = c + b,\r\n x = c + b + a;\r\n \r\n print(x%y + \" \" + y%z + \" \" + z%x);\r\n print(\"----------\")\r\n print(x + \" \" + y + \" \" + z ) \r\n\r\n}\r\n"}], "src_uid": "f0c22161cb5a9bc17320ccd05517f867"} {"source_code": "print(function(n, x) {\n\n\tvar ans = 0;\n\tvar a = readline().split(' ').map(Number);\n\tvar m = n;\n\tif (a.indexOf(x) === -1) {\n\t\ta.push(x);\n\t\tm++;\n\t}\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\ta.unshift(1e15);\n\tvar y1 = a.indexOf(x);\n\tvar y2 = a.lastIndexOf(x);\n\tvar y = Math.floor((n + 1) / 2);\n\tif (a[y] === x) {\n\t\treturn m - n;\n\t}\n\n\tif (y < y1) {\n\t\twhile (Math.floor((m + 1) / 2) !== y1) {\n\t\t\tm++;\n\t\t}\n\t\treturn m - n;\n\t}\n\n\tif (y > y2) {\n\t\twhile (Math.floor((m + 1) / 2) !== y2) {\n\t\t\tm++;\n\t\t\ty2++;\n\t\t}\n\t\treturn m - n;\n\t}\n\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], x = data[1],\n arr = tokenizeIntegers(readline());\n arr.sort(function (a, b) {\n return a - b;\n });\n var count = 0;\n if (arr.indexOf(x) == -1) {\n var left = 0;\n while (left < n && arr[left] < x) {\n ++left;\n }\n var right = n-left;\n count = 1;\n } else {\n var left = arr.indexOf(x),\n right = left;\n while (right+1 < n && arr[right+1] == x) {\n ++right;\n }\n var pos = Math.floor((n-1)/2);\n if (pos > right) {\n pos = right;\n } else if (pos < left) {\n pos = left;\n }\n left = pos;\n right = n-1-pos;\n }\n if (left >= right) {\n count += left-right;\n } else {\n count += right-left-1;\n }\n print(count);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(n, x) {\n\n\tvar ans = 0;\n\tvar a = readline().split(' ').map(Number);\n\tvar m = n;\n\tif (a.indexOf(x) === -1) {\n\t\ta.push(x);\n\t\tm++;\n\t}\n\ta.sort(function(a, b) {\n\t\treturn a - b;\n\t});\n\tvar y1 = a.indexOf(x) + 1;\n\tvar y2 = a.lastIndexOf(x) + 1;\n\tvar y = Math.floor((n + 1) / 2);\n\tif (a[y] === x) {\n\t\treturn m - n;\n\t}\n\n\tif (y < y1) {\n\t\twhile (Math.floor((m + 1) / 2) !== y1) {\n\t\t\tm++;\n\t\t}\n\t\treturn m - n;\n\t}\n\n\tif (y > y2) {\n\t\twhile (Math.floor((m + 1) / 2) !== y2) {\n\t\t\tm++;\n\t\t\ty2++;\n\t\t}\n\t\treturn m - n;\n\t}\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], x = data[1],\n arr = tokenizeIntegers(readline());\n arr.sort(function (a, b) {\n return a - b;\n });\n //print(arr.join(' '));\n if (arr.indexOf(x) == -1) {\n var left = 0;\n while (left < n && arr[left] < x) {\n ++left;\n }\n var right = n-left,\n count = 1;\n ++left;\n if (left > right) {\n count += left-right-1;\n } else {\n count += right-left;\n }\n print(count);\n return;\n } else {\n var left = arr.indexOf(x),\n right = left;\n while (right+1 < n && arr[right+1] == x) {\n ++right;\n }\n var median = Math.floor((n-1)/2);\n //print(left, right, median);\n if (median >= left && median <= right) {\n print(0);\n } else if (median < left) {\n print(left-median);\n } else {\n print(median-right);\n }\n }\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction printValues() {\n\tvar parts = [];\n\tfor (var i = 0; i < arguments.length; i += 2) {\n\t\tparts.push(arguments[i]+' = '+arguments[i+1]);\n\t}\n\tprint(parts.join(', '));\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], x = data[1],\n arr = tokenizeIntegers(readline());\n arr.sort(function (a, b) {\n return a - b;\n });\n //print(arr.join(' '));\n if (arr.indexOf(x) == -1) {\n var left = 0;\n while (left < n && arr[left] < x) {\n ++left;\n }\n var right = n-left,\n count = 1;\n ++left;\n if (left > right) {\n count += left-right-1;\n } else {\n count += right-left;\n }\n print(count);\n return;\n } else {\n var left = arr.indexOf(x),\n right = left;\n while (right+1 < n && arr[right+1] == x) {\n ++right;\n }\n var median = Math.floor(n/2);\n if (median >= left && median <= right) {\n print(0);\n } else if (median < left) {\n print(left-median);\n } else {\n print(median-right);\n }\n }\n}\n\nmain();\n"}], "src_uid": "1a73bda2b9c2038d6ddf39918b90da61"} {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\nconst N = Number(inputs[0])\r\nfor (let _ = 0, __ = 1; _ < N; _++) {\r\n const n = Number(inputs[__++]),\r\n data = inputs[__++].split(' ').map(Number)\r\n main(n, data)\r\n}\r\n\r\nfunction main(n, data) {\r\n let count = new Array(n + 1).fill(0)\r\n for (let i = 0; i < n; i++) {\r\n if (data[i] > n || data[i] > data[(i - 1 + n) % n] + 1) {\r\n console.log('NO')\r\n return\r\n }\r\n count[data[i]]++\r\n }\r\n if (count[1] !== 1) {\r\n console.log('NO')\r\n return\r\n }\r\n console.log('YES')\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n // has 1\n // +1 or -x or 0\n let has1 = 0\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n if (x < 1 || x > n) return false\n if (x === 1) has1++\n if (x === n) {\n if (i + 1 < arr.length && arr[i + 1] !== 1) return false\n }\n // if (i) {\n const d = arr[i] - (i ? arr[i - 1] : arr[n - 1])\n if (d === 1 || d <= 0) {\n //\n } else {\n return false\n }\n // }\n }\n if (has1 !== 1) return false\n return true\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n // has 1\n // +1 or -x or 0\n let has1 = false\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n if (x < 1 || x > n) return false\n if (x === 1) has1 = true\n if (x === n) {\n if (i + 1 < arr.length && arr[i + 1] !== 1) return false\n }\n if (i) {\n const d = arr[i] - arr[i - 1]\n if (d === 1 || d <= 0) {\n //\n } else {\n return false\n }\n }\n }\n if (!has1) return false\n return true\n}\n"}], "src_uid": "a6c6b2a66ba51249fdc5d4188ca09e3b"} {"source_code": "print(function(n, m) {\n\n\tvar not = new Int8Array(n + 1);\n\twhile (m--)\n\t\trn().reduce(function(a, b){\n\t\t\tnot[a]=1;\n\t\t\tnot[b]=1;\n\t\t});\n\tvar c = 0;\n\tfor(var i=1; i<=n; i++)\n\t\tif(not[i]===0){\n\t\t\tc=i;\n\t\t\tbreak;\n\t\t}\n\n\tvar ans = [n-1];\n\tfor(var i=1; i<=n; i++)\n\t\tif(i!==c)\n\t\t\tans.push(c+' '+i);\n\n\treturn ans.join('\\n');\n\n} .apply(0, rn()));\nfunction rn() {\n\treturn readline().split(' ').map(Number);\n}", "positive_code": [{"source_code": "function main(str) {\n var arr = str.split(' ');\n var num1 = +arr[0];\n var num2 = +arr[1];\n\n var myGraph;\n\n // \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0433\u0440\u0430\u0444\u0430\n var Graph = function (nodes) {\n this.nodesNumber = nodes;\n this.edgesNumber = 0;\n this.nodes = new Array(this.nodesNumber);\n var i = 0;\n\n for (i; i < nodes; i++) {\n this.nodes[i] = [];\n }\n\n this.connectNodes = function (v, w) {\n this.nodes[v].push(w);\n this.nodes[w].push(v);\n this.edgesNumber++;\n }\n\n this.showGraph = function () {\n var i = 0;\n var j = 0;\n write(this.edgesNumber + '\\n');\n for (i; i < this.nodes.length; i++) {\n for (j; j < this.nodes[i].length; j++) {\n var resStr = (i + 1) + ' ' + (this.nodes[i][j] + 1) + '\\n';\n write(resStr);\n }\n }\n }\n }\n\n function logic() {\n myGraph = new Graph(num1);\n var centralNode = 0;\n var nodesUnderCondition = new Set();\n var i = 0;\n var j = 0;\n var k = 0;\n for (j;j no[i].size) {\n minr = no[i].size;\n minidx = i;\n }\n }\n \n var connected = [];\n for (var i = 0; i < n; i++) {\n if (!no[minidx].has(i)) {\n res.push((minidx+1) + ' ' + (i+1));\n connected.push(i);\n no[minidx].add(i);\n\t\t\tno[i].add(minidx);\n }\n }\n \n doneFlag = true;\n for (var i = 0; i < connected.length; i++) {\n for (var j = 0; j < connected.length; j++) {\n no[connected[i]].add(connected[j]);\n\t\t\tno[connected[j]].add(connected[i]);\n\t\t}\n if (no[i].size < n) {\n doneFlag = false;\n break;\n }\n }\n \n}\n\n\nwrite(res.length + '\\n' + res.join('\\n'));"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar l = readline().split(' ').map(Number), n = l[0], m = l[1], a = [];\n\t\twhile (m--) { a.push(readline().split(' ').map(Number)); }\n\n\t\tvar t = [];\n\t\tfor (var i = 0; i < n; i++) { t.push(true); }\n\t\ta.forEach(function (e) { t[e[0] - 1] = t[e[1] - 1] = false; });\n\t\tt = t.map(function (e, i) { return e ? i + 1 : false; }).filter(function (e) { return e === parseInt(e); });\n\n\t\treturn [n - 1].concat(function (a, n) {\n\t\t\tvar ret = [];\n\t\t\tfor (var i = 0; i < n; i++) {\n\t\t\t\tif (i+1 !== a) {\n\t\t\t\t\tret.push([a, i+1].join(' '));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}(t[0], n)).join('\\n')\n\t}());\n}).call(this);\n"}], "negative_code": [{"source_code": "function main(str) {\n var arr = str.split(' ');\n var num1 = +arr[0];\n var num2 = +arr[1];\n\n var myGraph;\n\n // \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0433\u0440\u0430\u0444\u0430\n var Graph = function (nodes) {\n this.nodesNumber = nodes;\n this.edgesNumber = 0;\n this.nodes = new Array(this.nodesNumber);\n var i = 0;\n\n for (i; i < nodes; i++) {\n this.nodes[i] = [];\n }\n\n this.connectNodes = function (node1, node2) {\n this.nodes[node1].push(node2);\n this.nodes[node2].push(node1);\n this.edgesNumber++;\n }\n\n this.showGraph = function () {\n var i = 0;\n var j = 0;\n write(this.edgesNumber);\n for (i; i < this.nodes.length; i++) {\n for (j; j < this.nodes[i].length; j++) {\n write((i + 1) + ' ' + (this.nodes[i][j] + 1));\n }\n }\n }\n }\n\n function logic() {\n myGraph = new Graph(num1);\n var centralNode = 0;\n var nodesUnderCondition = new Set();\n var i = 0;\n var j = 0;\n var k = 0;\n for (j;j {\n if (!l) {\n l = +line\n } else {\n lines.push(+line);\n }\n}).on('close', () => {\n for(q = 0; q < lines.length; q++) {\n const n = lines[q];\n const centre = n / 2;\n let o;\n const x = [];\n const y = [];\n let summ = 0;\n let summ2 = 1;\n if (centre % 2 !== 0) {\n o = 'NO'\n } else {\n o = 'YES'\n for (i = 1, j = 1; i <= centre; i++, j+= 2) {\n x.push(2 * i)\n summ += 2 * i;\n\n if (i === 1) {\n y.push(1)\n } else {\n if (i !== centre) {\n y.push(j)\n summ2 += j\n } else{\n y.push(summ - summ2)\n summ2 += summ - summ2\n }\n } \n }\n }\n\n process.stdout.write(`${o}\\n`);\n o === \"YES\" && process.stdout.write(`${[...x, ...y].join(' ')}\\n`);\n }\n});", "positive_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var evenSide = [];\n var oddSide = [];\n if ((n / 2) % 2 != 0) print(\"No\");\n else {\n var evenSum = 0;\n var oddSum = 0;\n for (var i = 2; i <= n; i += 2) {\n evenSide.push(i);\n oddSide.push(i - 1);\n evenSum += i;\n oddSum += i - 1;\n }\n if ((evenSum - oddSum) % 2 == 0) {\n oddSide[oddSide.length - 1] += evenSum - oddSum;\n print(\"Yes\", \"\\n\", evenSide.concat(oddSide).join(\" \"));\n } else print(\"No\");\n }\n}\n/*function findx(n) {\n var evenSide = [];\n var oddSide = [];\n if ((n / 2) % 2 != 0) console.log(\"No\");\n else {\n var evenSum = 0;\n var oddSum = 0;\n for (var i = 2; i <= n; i += 2) {\n evenSide.push(i);\n oddSide.push(i - 1);\n evenSum += i;\n oddSum += i - 1;\n }\n if ((evenSum - oddSum) % 2 == 0) {\n oddSide[oddSide.length - 1] += evenSum - oddSum;\n console.log(\"Yes\", \"\\n\", evenSide.concat(oddSide));\n } else console.log(\"No\");\n }\n}\nfindx(4);*/\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let sum = 0;\n let even = 2;\n let odd = 1;\n let i = 0;\n const left = [];\n const right = [];\n while (i < +d - 1) {\n if (i % 2 === 0) {\n left.push(even);\n sum += even;\n even += 2;\n }\n else {\n right.push(odd);\n sum -= odd;\n odd += 2;\n }\n\n i++;\n }\n\n if (sum % 2 === 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n const ans = [...left, ...right, sum];\n console.log(ans.join(' '));\n }\n\n // let ans = [];\n // let v = +d;\n\n // let value = 2;\n // for (let i = 0; i < v / 2; i++) {\n // ans.push(value);\n // value += 2;\n // }\n\n // let sum = ans.reduce((acc, x) => acc + x, 0);\n\n // value = 1;\n // for (let i = v / 2; i < v - 1; i++) {\n // ans.push(value);\n // sum -= value;\n // value += 2;\n // }\n\n // if (sum % 2 === 0) {\n // console.log('NO');\n // }\n // else {\n // ans.push(sum);\n // console.log('YES');\n // console.log(ans.join(' '));\n // }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = [];\n let v = +d;\n\n let value = 2;\n for (let i = 0; i < v / 2; i++) {\n ans.push(value);\n value += 2;\n }\n\n let sum = ans.reduce((acc, x) => acc + x, 0);\n\n value = 1;\n for (let i = v / 2; i < v - 1; i++) {\n ans.push(value);\n sum -= value;\n value += 2;\n }\n\n if (sum % 2 === 0) {\n console.log('NO');\n }\n else {\n ans.push(sum);\n console.log('YES');\n console.log(ans.join(' '));\n }\n\n c++;\n});\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let t = parseInt(input[0]);\n\n for (let i = 1; i <= t; i += 1) {\n const n = parseInt(input[i]);\n\n if ((n / 2) % 2 !== 0) {\n console.log(\"NO\");\n continue;\n }\n\n const size = n / 2;\n const answer = [];\n\n let sumLeft = 0;\n for (let i = 0, j = 2; i < size; i += 1, j += 2) {\n answer.push(j);\n sumLeft += j;\n }\n\n let sumRight = 0;\n for (let i = 0, j = 1; i < size - 1; i += 1, j += 2) {\n answer.push(j);\n sumRight += j;\n }\n\n answer.push(sumLeft - sumRight);\n console.log(`YES`);\n console.log(answer.join(\" \"));\n }\n});\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var input = parseInt(readline())\n //var a = readline().split(\" \").map(x => parseInt(x))\n while (input--) {\n var n = parseInt(readline())\n var half = n / 2\n if (half % 2 == 1) print(\"NO\")\n else {\n var evenarr = [], oddarr = []\n for (var i = 2; i <= n; i += 2) {\n evenarr.push(i)\n oddarr.push(i - 1)\n }\n oddarr[half - 1] = oddarr[half - 1] + half\n print(\"YES\")\n print(evenarr.join(\" \")+\" \"+oddarr.join(\" \"))\n }\n\n }\n\n}\n"}, {"source_code": "// this is js\nvar tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "function solve(n) {\n const a = (n % 4);\n let result = [];\n if (a === 0) {\n result = new Array(n);\n const k = (n / 2);\n let s = 0;\n for (let i = 0; i < k; i = i + 1) {\n result[i] = i + i + 2; \n s = s + result[i];\n }\n let t = 0;\n for (let i = 0; i < (k - 1); i = i + 1) {\n const u = k + i;\n result[u] = i + i + 1;\n t = t + result[u];\n }\n result[n - 1] = s - t; \n } \n return result;\n}\n\nfunction main(lines) {\n const yes = 'YES';\n const no = 'NO';\n lines.shift();\n for (const line of lines) {\n const a = Number(line);\n const result = solve(a);\n if (result.length === 0) {\n console.log(no);\n } else {\n console.log(yes);\n console.log(result.join(' '));\n }\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(n) {\n const a = (n % 4);\n let result = [];\n if (a === 0) {\n result = new Array(n);\n const k = (n / 2);\n let s = 0;\n for (let i = 0; i < k; i = i + 1) {\n result[i] = i + i + 2; \n s = s + result[i];\n }\n let t = 0;\n for (let i = 0; i < (k - 1); i = i + 1) {\n const u = k + i;\n result[u] = i + i + 1;\n t = t + result[u];\n }\n result[n - 1] = s - t; \n } \n return result;\n}\n\nfunction main(lines) {\n const yes = \"YES\";\n const no = \"NO\";\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const a = Number(t);\n const result = solve(a);\n if (result.length === 0) {\n console.log(no);\n } else {\n console.log(yes);\n console.log(result.join(' '));\n }\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n) {\n if (n % 4 !== 0) return -1;\n let even = [2];\n let sumEven = 2;\n let odd = [1];\n let sumOdd = 1;\n while (odd.length < n / 2) {\n let nextEven = even[even.length - 1] + 2;\n sumEven += nextEven;\n even.push(nextEven);\n let nextOdd = odd[odd.length - 1] + 2;\n sumOdd += nextOdd;\n odd.push(nextOdd);\n }\n odd[odd.length - 1] = sumEven - sumOdd + odd[odd.length - 1];\n return even.concat(odd);\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n);\n if (res === -1) console.log('NO');\n else {\n console.log('YES');\n console.log(res.join(' '));\n }\n // console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n //let testResult = [];\n for (let index = 1; index <= +inputs[0]; index++) {\n const element = +inputs[index];\n\n if (element % 4 !== 0) {\n console.log('NO');\n // testResult.push('NO');\n continue;\n }\n let arr = { odd: [], even: [] };\n for (let index2 = 1; index2 <= element; index2++) {\n\n if (index2 % 2 == 0) {\n arr.even.push(index2);\n }\n else {\n arr.odd.push(index2);\n }\n }\n\n arr.odd[arr.odd.length - 1] = arr.odd[arr.odd.length - 1] + Math.floor(element / 2);\n console.log('YES');\n console.log(arr.even.join(' '), arr.odd.join(' '));\n\n }\n //console.log(testResult);\n // return ' '.toString();\n\n}\n\n\n\n\n\n"}, {"source_code": "// Don't know where the future lies\nvar tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n for (var i = 0; i < t; i++) {\n let n = parseInt(readLine());\n if ((n / 2) % 2 == 1) {\n console.log('NO');\n } else {\n console.log('YES');\n let even = [];\n let odd = [];\n let j = 2;\n let oke = 1;\n while (true) {\n even.push(j);\n if (odd.length >= n / 4) {\n odd.push(j + 1);\n } else odd.push(j - 1);\n j += 2;\n if (even.length == n / 2 && odd.length == n / 2) break;\n }\n console.log(even.concat(odd).join(' '))\n }\n }\n}"}, {"source_code": "// Just wandering on the pale blue dot\nvar tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n //let [n, industry] = readline().split(\" \").map(e => parseInt(e));\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n const n = parseInt(readline(), 10);\n const half = n / 2;\n\n if (half % 2 !== 0) {\n // const odd = [half-1, half+1];\n // const even = [half-2, half+2];\n console.log('NO');\n // console.log([...odd, ...even].join(\" \"))\n } else {\n let odd = [];\n let even = [];\n\n let c = 2;\n for (var i = 0; i < half; i++) {\n odd.push(c);\n c+= 2;\n }\n const sumOdd = odd.reduce((a,b) => a+b, 0);\n\n c = 1;\n for (var i = 0; i < half-1; i++) {\n even.push(c);\n c += 2;\n }\n even.push(sumOdd - even.reduce((a,b) => a+b, 0))\n \n console.log('YES');\n console.log([...odd, ...even].join(\" \"))\n }\n\n }\n\n\n}\n"}, {"source_code": "// very experimental, but faster than python3 \nvar tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "var tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "// I truly believe that i am wasting my time with these programming questions\nvar tests = parseInt(readline()), value = 0, stop = 0;\nfor (var i = 0; i < tests; i++)\n\t{\n\tvalue = parseInt(readline())\n\tstop = value/2\n\tvar array = [], sum = 0, sum2 = 0\n\tif ((value/2)%2) print('NO')\n\telse{\n\tfor (var j = 1; j < value; j++)\n\t\t{\n\t\tif (j <= stop)\n\t\t{\t\n\t\t\tsum += 2*(j)\n\t\t\tarray.push(2*(j))\n\t\t}\n\t\telse\n\t\t{ sum2+= 2*(j-stop)-1\n\t\t\tarray.push(2*(j-stop)-1)\n\t\t}\n\t}\n\t\tarray.push(sum-sum2)\n\t\tprint('YES')\n\t\tprint(array.join(' '))\n\t}\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tif(n % 4 != 0){\n\t\t\toutput.push(\"NO\");\n\t\t}else{\n\t\t\tn /= 2;\n\t\t\tvar sum = 0;\n\t\t\tvar list = [];\n\t\t\tfor(var j = 1; j <= n; j++){\n\t\t\t\tlist.push(j * 2);\n\t\t\t\tsum += (j * 2);\n\t\t\t}\n\t\t\tfor(var j = 1; j < n; j++){\n\t\t\t\tlist.push((j * 2) - 1);\n\t\t\t\tsum -= (j * 2) - 1;\n\t\t\t}\n\t\t\tlist.push(sum);\n\t\t\toutput.push(\"YES\");\n\t\t\toutput.push(myconv(list,8));\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "var testsAmount = parseInt(readline());\n\nvar tests = [];\nfor (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = '';\n var second = '';\n for (var j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first += ' ' + j;\n } else {\n second += ' ' + (j === tests[i] - 1 ? (j + tests[i]/2) : j);\n }\n }\n\n print('YES');\n print(first.slice(1) + second);\n}"}, {"source_code": " var testsAmount = parseInt(readline());\n\n var tests = [];\n for (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n }\n\n for (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = [];\n var second = [];\n for (var j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first.push(j);\n } else {\n second.push(j === tests[i] - 1 ? (j + tests[i]/2) : j);\n }\n }\n\n print('YES');\n print(first.join(' ') + ' ' + second.join(' '));\n }"}, {"source_code": " var testsAmount = parseInt(readline());\n\n var tests = [];\n for (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n }\n\n for (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = [];\n var second = [];\n for (var j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first.push(j);\n } else {\n second.push(j);\n }\n }\n\n second[second.length - 1] = second[second.length - 1] + tests[i] / 2;\n\n print('YES');\n print(first.join(' ') + ' ' + second.join(' '));\n }"}, {"source_code": "var testsAmount = parseInt(readline());\n\nvar tests = [];\nfor (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < tests.length; i++) {\n var first = {arr:[],sum:0};\n var second = {arr:[],sum:0};\n for (var j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first.arr.push(j);\n first.sum += j;\n\n if (j === tests[i]) {\n if (first.sum !== second.sum) {\n print('NO');\n } else {\n print('YES');\n print(first.arr.join(' ') + ' ' + second.arr.join(' '));\n }\n }\n\n continue;\n }\n\n if (j === tests[i] - 1) {\n if (((first.sum + j + 1) - second.sum) % 2 > 0) {\n second.arr.push((first.sum + j + 1) - second.sum);\n second.sum += (first.sum + j + 1) - second.sum;\n }\n } else {\n second.arr.push(j);\n second.sum += j; \n }\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor(var qq = 0; qq < t; qq++) {\n var n = parseInt(readline());\n var ndel2 = n / 2;\n \n if (ndel2 % 2 === 0) {\n var a = [2];\n var b = [1];\n\n for(var i = 1; i < ndel2; i++) {\n a[i] = a[i - 1] + 2;\n\n if (i == ndel2 / 2) {\n b[i] = b[i - 1] + 4;\n } else {\n b[i] = b[i - 1] + 2;\n }\n }\n \n print('YES');\n print(a.concat(b).join(' '));\n\n } else {\n print('NO');\n }\n\n}"}, {"source_code": "var range = readline();\n\nfor(var i=0;iNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar n = nextInt();\n\t\tif(n % 4 != 0){\n\t\t\toutput.push(\"NO\");\n\t\t}else{\n\t\t\tn /= 2;\n\t\t\tvar sum = 0;\n\t\t\tvar list = [];\n\t\t\tfor(var i = 1; i <= n; i++){\n\t\t\t\tlist.push(i * 2);\n\t\t\t\tsum += (i * 2);\n\t\t\t}\n\t\t\tfor(var i = 1; i < n; i++){\n\t\t\t\tlist.push((i * 2) - 1);\n\t\t\t\tsum -= (i * 2) - 1;\n\t\t\t}\n\t\t\tlist.push(sum);\n\t\t\toutput.push(\"YES\");\n\t\t\toutput.push(myconv(list,8));\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}"}, {"source_code": "var testsAmount = parseInt(readline());\n\nvar tests = [];\nfor (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = '';\n var second = '';\n for (j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first += ' ' + j;\n } else {\n second += ' ' + j;\n }\n }\n\n print(first.slice(1) + second);\n}"}, {"source_code": "var testsAmount = parseInt(readline());\n\nvar tests = [];\nfor (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = '';\n var second = '';\n for (j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first += ' ' + j;\n } else {\n second += ' ' + (j === tests[i] - 1 ? (j + tests[i]/2) : j);\n }\n }\n\n print(first.slice(1) + second);\n}"}, {"source_code": "var testsAmount = parseInt(readline());\n\nvar tests = [];\nfor (var i = 0; i < testsAmount; i++) {\n tests.push(parseInt(readline()));\n}\n\nfor (var i = 0; i < tests.length; i++) {\n if (tests[i] % 4 > 0) {\n print('NO');\n\n continue;\n }\n\n var first = '';\n var second = '';\n for (var j = 1; j <= tests[i]; j++) {\n if (j % 2 === 0) {\n first += ' ' + j;\n } else {\n second += ' ' + (j === tests[i] - 1 ? (j + tests[i]/2) : j);\n }\n }\n\n print(first.slice(1) + second);\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor(var qq = 0; qq < t; qq++) {\n var n = parseInt(readline());\n var ndel2 = n / 2;\n \n if (ndel2 % 2 === 0) {\n var a = [2];\n var b = [1];\n\n for(var i = 1; i < ndel2; i++) {\n a[i] = a[i - 1] + 2;\n\n if (i == ndel2 / 2) {\n b[i] = b[i - 1] + 4;\n } else {\n b[i] = b[i - 1] + 2;\n }\n }\n \n print(a.concat(b).join(' '));\n\n } else {\n print('NO');\n }\n\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var input = parseInt(readline())\n //var a = readline().split(\" \").map(x => parseInt(x))\n while (input--) {\n var n = parseInt(readline())\n var half = n / 2\n if (half % 2 == 1) print(\"NO\")\n else {\n var evenarr = [], oddarr = []\n for (var i = 2; i <= n; i += 2) {\n evenarr.push(i)\n oddarr.push(i - 1)\n }\n oddarr[half - 1] = oddarr[half - 1] + half\n print(\"YES\")\n print(evenarr.join(\" \"), oddarr.join(\" \"))\n }\n\n }\n\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n //let [n, industry] = readline().split(\" \").map(e => parseInt(e));\n\n let cases = parseInt(readline(), 10);\n for (var i = 0; i < cases; i++) {\n const n = parseInt(readline(), 10);\n const half = n / 2;\n\n if (half % 2 !== 0) {\n console.log('NO');\n } else {\n let odd = [];\n let even = [];\n\n let c = 2;\n for (var i = 0; i < half; i++) {\n odd.push(c);\n c+= 2;\n }\n const sumOdd = odd.reduce((a,b) => a+b, 0);\n\n c = 1;\n for (var i = 0; i < half-1; i++) {\n even.push(c);\n c += 2;\n }\n even.push(sumOdd - even.reduce((a,b) => a+b, 0))\n \n console.log('YES');\n console.log([...odd, ...even].join(\" \"))\n }\n\n }\n\n\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n //let [n, industry] = readline().split(\" \").map(e => parseInt(e));\n\n let cases = parseInt(readline(), 10);\n for (var i = 0; i < cases; i++) {\n const n = parseInt(readline(), 10);\n const half = n / 2;\n\n if (half % 2 !== 0) {\n // const odd = [half-1, half+1];\n // const even = [half-2, half+2];\n console.log('NO');\n // console.log([...odd, ...even].join(\" \"))\n } else {\n let odd = [];\n let even = [];\n\n let c = 2;\n for (var i = 0; i < half; i++) {\n odd.push(c);\n c+= 2;\n }\n const sumOdd = odd.reduce((a,b) => a+b, 0);\n\n c = 1;\n for (var i = 0; i < half-1; i++) {\n even.push(c);\n c += 2;\n }\n even.push(sumOdd - even.reduce((a,b) => a+b, 0))\n \n console.log('YES');\n console.log([...odd, ...even].join(\" \"))\n }\n\n }\n\n\n}\n"}], "src_uid": "0c7e019e1e955cadacca55b4e823a3e5"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var sum = 0;\n for(j = 0; j < n; j++){\n sum+=k[j];\n }\n if(sum % n === 0){\n var avg = sum / n;\n var a = 0;\n for(j = 0; j < n; j++){\n if(k[j] > avg){\n a++;\n }\n }\n console.log(a);\n }else{\n console.log(-1);\n }\n }\n }\n});", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = parseInt(readLine());\r\n let arr = readLine().split(\" \");\r\n let sum = arr.reduce((acc, cur) => acc + parseInt(cur), 0);\r\n if (sum % n != 0) {\r\n return -1;\r\n }\r\n let avg = sum / n;\r\n let presentAvgCount = arr.reduce((acc, cur) => {\r\n if (parseInt(cur) > avg){\r\n return acc+1;\r\n }\r\n return acc;\r\n }, 0);\r\n return presentAvgCount;\r\n}\r\n"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var n = parseInt(args[2 * i - 1], 10);\r\n var arg = (args[2 * i].split(\" \")).map((e) => parseInt(e, 10));\r\n var s = arg.reduce(function (sum, element) {\r\n return sum + element;\r\n }, 0);\r\n var d = s % n;\r\n if (d != 0) {\r\n console.log(\"-1\");\r\n }\r\n else {\r\n var c = Math.floor(s / n);\r\n var cnt = 0;\r\n for (var j = 0; j < n; j++) {\r\n if (arg[j] > c) {\r\n cnt++;\r\n }\r\n }\r\n console.log(cnt);\r\n }\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let t = parseInt(readLine()); // number of test cases\r\n\r\n while (t--) {\r\n let n = parseInt(readLine()); // number of friends\r\n\r\n let a = readLine()\r\n .split(\" \")\r\n .map((x) => parseInt(x)); // array of candies\r\n\r\n console.log(getMinK(a, n));\r\n }\r\n}\r\n\r\nfunction getMinK(a, n) {\r\n let candiesSum = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n candiesSum += a[i];\r\n }\r\n\r\n let equalNumber = candiesSum / n;\r\n\r\n if (candiesSum % n !== 0) {\r\n return -1;\r\n }\r\n\r\n let k = 0;\r\n\r\n for (let j = 0; j < a.length; j++) {\r\n if (a[j] > equalNumber) {\r\n k++;\r\n }\r\n }\r\n\r\n return k;\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let arrLen = +input[z++];\r\n let arr = input[z++].split(' ').map(x=>Number(x));\r\n\r\n let sum = arr.reduce((a,b)=>a+b);\r\n let modular = sum % arrLen;\r\n \r\n if(modular !== 0) console.log(-1);\r\n else{\r\n let counter = 0;\r\n arr.forEach(value => {\r\n if(value > sum / arrLen) counter++;\r\n });\r\n console.log(counter);\r\n }\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.nums();\n\t\tlet s = a.reduce((a, b) => a + b);\n\t\tlet x = 0;\n\t\tlet y = 0;\n\t\tif (n == 1) {\n\t\t\tans.push(0);\n\t\t} else if(s % n !== 0) {\n\t\t\tans.push(-1);\n\t\t} else {\n\t\t\tlet c = s / n;\n\t\t\ta.forEach(e => {\n\t\t\t\tif (e === c) {\n\t\t\t\t\tx++;\n\t\t\t\t}\n\t\t\t\tif (e > c) {\n\t\t\t\t\ty++;\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (x === n) {\n\t\t\t\tans.push(0);\n\t\t\t} else {\n\t\t\t\tans.push(y);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var readline = require('readline');\r\n \r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvar lines = [];\r\nrl.on('line', function(input) {\r\n lines.push(input);\r\n});\r\nrl.on('close', function() {\r\n var t = parseInt(lines[0]);\r\n var l = 1;\r\n for (var i = 0; i < t; i++) {\r\n l++\r\n console.log(solve(lines[l++].split(' ').map(Number)));\r\n }\r\n});\r\n\r\n\r\nconst solve = (arr) => {\r\n try{\r\n const arr_sum = arr.reduce((acc, curr) => acc + curr, 0);\r\n\r\n if(arr_sum % arr.length !== 0){\r\n return -1;\r\n }\r\n\r\n let cnt = 0;\r\n\r\n for(let i of arr){\r\n if(i > arr_sum / arr.length){\r\n cnt += 1;\r\n }\r\n }\r\n \r\n return cnt;\r\n }catch (ex) {\r\n console.log('ex:', ex)\r\n }\r\n};"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var sum = 0;\r\n var arr = readArray((a) => {\r\n var numA = Number(a);\r\n sum += numA;\r\n return numA;\r\n });\r\n if (sum % n !== 0) {\r\n write(-1);\r\n return;\r\n }\r\n var ans = 0;\r\n var avg = div(sum, n);\r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] > avg) {\r\n ans++;\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "let lineContent = ''\n\nprocess.stdin.on('data', c => lineContent += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = lineContent.split(EOL) /*your input text, split by lines*/\n\n const testNumbers = parseInt(lines[0]);\n\n for (let i = 0; i < testNumbers; i++) {\n const [n] = lines[1 + i * 2].split(\" \").map((e) => parseInt(e));\n const arr = lines[2 + i * 2].split(\" \").map(e => parseInt(e));\n\n console.log(f(n, arr));\n }\n\n})\n\nconst f = (n, arr) => {\n const sum = arr.reduce((c, e) => c += e);\n if (sum % n !== 0) return -1;\n\n const candy = sum / n;\n\n let res = 0;\n\n for (let i = 0; i < n; i++) {\n if (arr[i] > candy) {\n res++;\n }\n }\n\n return res;\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n l++\n console.log(solve(lines[l++].split(' ').map(Number)));\n }\n});\n \nfunction solve(nums) {\n let sum = 0\n for (let i = 0; i < nums.length; i++) {\n sum += nums[i]\n }\n const avg = sum / nums.length\n if (avg !== Math.ceil(avg)) return -1\n\n let k = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] > avg) {\n k++\n }\n }\n return k\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsum += list[i];\r\n\t\t}\r\n\t\tif(sum % N != 0){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] > (sum / N)){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n var sum = 0;\r\n for(j = 0; j < n; j++) sum += parseInt(a[j]);\r\n if(sum % n !== 0) print(-1);\r\n else {\r\n var count = 0, over = 0, div = sum / n;\r\n for(j = 0; j < n; j++) {\r\n //if(parseInt(a[j]) === div) count += 1;\r\n //else\r\n if(parseInt(a[j]) > div) over += 1;\r\n }\r\n /*if(n !== count) {\r\n //if(n - count - 1 >= Math.ceil(n/2)) {\r\n // print(Math.ceil)\r\n //}\r\n //else print(n - count - 1);\r\n print(n - count - 1);\r\n }*/\r\n if(over > 0) {print(over);}\r\n else print(0);\r\n }\r\n}"}, {"source_code": "var tc=readline();\r\nwhile(tc--)\r\n{\r\n var n=readline();\r\n var arr=readline().split(' ');\r\n arr.sort(function(u,v){return u-v;});\r\n var sum=0;\r\n for(var i=0;i0) print(-1);\r\n else \r\n{ var sz=arr.length;\r\n var u=sum/sz;\r\n var cnt=0;\r\nfor(var i=0;iu);\r\n print(cnt);\r\n}\r\n \r\n \r\n}"}, {"source_code": "// B. Friends and Candies\r\n\r\n\r\nvar l0 = readline();\r\nvar n = +l0;\r\nvar arr = [];\r\nfor (var a = 0; a +v));\r\n}\r\n\r\n// output\r\n// 2\r\n// 1\r\n// -1\r\n// 0\r\n// 0\r\n\r\nfor (var x = 0; x eq) {\r\n count++;\r\n }\r\n }\r\n if (count) {\r\n print(count);\r\n } else {\r\n print(0);\r\n }\r\n }\r\n}"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var numsCount = Number(readline());\r\n var nums = readline().split(\" \").map(x => Number(x));\r\n\r\n if (numsCount === 1) {\r\n return print(\"0\");\r\n }\r\n\r\n var sum = 0;\r\n for (var i = 0; i < nums.length; ++i) {\r\n sum += nums[i];\r\n }\r\n\r\n var avg = sum / nums.length;\r\n if (avg !== Math.trunc(avg)) {\r\n return print(\"-1\");\r\n }\r\n \r\n\r\n print(nums.reduce((acc, elem) => {\r\n if (elem > avg) {\r\n ++acc;\r\n }\r\n\r\n return acc;\r\n }, 0));\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\n\r\nwhile(tc--) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(i => parseInt(i));\r\n\r\n var sum = arr.reduce((a, b) => {\r\n return a + b;\r\n });\r\n\r\n if (sum % n) {\r\n print (\"-1\");\r\n } else {\r\n var newArray = arr.filter(e => {\r\n return e > (sum/n);\r\n });\r\n print(newArray.length);\r\n }\r\n}\r\n"}, {"source_code": "var tc = parseInt(readline());\r\n\r\nwhile(tc--) {\r\n var n = parseInt(readline());\r\n var arr = readline().split(' ').map(i => parseInt(i));\r\n\r\n var sum = arr.reduce((a, b) => {\r\n return a + b;\r\n });\r\n\r\n if (sum % n) {\r\n print (\"-1\");\r\n } else {\r\n var newArray = arr.filter(e => {\r\n return e > (sum/n);\r\n });\r\n print(newArray.length);\r\n }\r\n}\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var x = +readline();\r\n var nums = readNumArray();\r\n var sum = 0;\r\n for (var j = 0; j < x; j++) {\r\n sum+= nums[j];\r\n }\r\n var average = sum / x;\r\n if (average % 1 > 0) {\r\n print(-1);\r\n continue;\r\n }\r\n var counter = 0;\r\n for (var j = 0; j < x; j++) {\r\n if (nums[j] > average) {\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n }\r\n}\r\n\r\nmain();"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n var sum = 0;\r\n for(j = 0; j < n; j++) sum += parseInt(a[j]);\r\n if(sum % n !== 0) print(-1);\r\n else {\r\n var count = 0, div = sum / n;\r\n for(j = 0; j < n; j++) {\r\n if(parseInt(a[j]) === div) count += 1;\r\n }\r\n if(n - count !== 0) print(n - count - 1);\r\n else print(0);\r\n }\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(\" \");\r\n var sum = a.reduce(function(x, y){\r\n return parseInt(x) + parseInt(y);\r\n }, 0);\r\n if(sum % n !== 0) print(-1);\r\n else {\r\n var count = 0, div = sum / n;\r\n for(j = 0; j < n; j++) {\r\n if(a[j] == div) count += 1;\r\n }\r\n if(n - count !== 0) print(n - count - 1);\r\n else print(0);\r\n }\r\n}"}], "src_uid": "b8554e64b92b1b9458955da7d55eba62"} {"source_code": "var n = readline(); // Number of queues\nvar ak = readline()\n .split(' ')\n .map(Number); // People in each queue\n\nvar bk = ak.map((ai, i) => {\n return i + Math.ceil((ai - i) / n) * n;\n});\n\nvar minBk = bk[0];\nvar posAllen = 1;\nfor(var i = 1; i < n; i++) {\n if(bk[i] < minBk) {\n minBk = bk[i];\n posAllen = (i+1);\n }\n}\n\nprint(posAllen);", "positive_code": [{"source_code": " var n = parseInt(readline());\n var a = readline().split(' ').map(x => parseInt(x));\n var minp = Infinity;\n var minq = Infinity;\n for(var i = 0; i < n; i += 1) {\n var r = 0;\n if(a[i] > i) {\n r += Math.ceil((a[i] - i) / n) * n;\n r += i;\n } else {\n r += i;\n }\n if(r < minq) {\n minq = r;\n minp = i;\n }\n }\n print(minp + 1);"}], "negative_code": [{"source_code": "var numQueues = readline();\nvar queues = readline()\n .split(' ')\n .map(Number);\nvar queueAllen = 0;\n\nvar minQueue = queues.reduce((a,b) => b < a ? b : a);\nif(minQueue > numQueues)\nqueues = queues.map(q => q % numQueues);\n\nwhile (queues[queueAllen] > 0) {\n queues = queues.map(q => q - 1);\n queueAllen = (queueAllen + 1) % numQueues;\n}\n\nprint(queueAllen + 1);"}], "src_uid": "b18bbefd2a948da9dec1d6f27f219ed1"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let tmp=0, T=0, pairs=[];\n\n rl.on('line', (input) => {\n if (tmp==0) {T=Number(input); tmp++;}\n else {\n if (tmp<=T){\n let str=input.split(' ').map(a=>{return Number(a);}); \n pairs.push(str);\n tmp++;}\n }\n if (tmp>T){ rl.close(); therest();}\n return 0;}\n);\n\nlet therest=function() {\n for (let i=0; i {\n // TODO: Log the answer in a database\n console.log(`Thank you for your valuable feedback: ${answer}`);\n \n rl.close();\n });*/", "positive_code": [{"source_code": "//var input = readline()\n\nvar t = readline()\n\nfor(var i=0; i {\n if (l === 0) {\n n = parseInt(input)\n } else {\n if (l === n)\n rl.close();\n\n let arr = input.split(\" \").map(x => parseInt(x))\n console.log(arr[0], arr[0] * 2)\n\n if (l === n)\n return\n }\n l++\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n console.log(a, 2*a);\n\n c++;\n});\n"}], "negative_code": [{"source_code": "//var input = readline()\n\nvar t = readline()\n\nfor(var i=0; i input += x);\nprocess.stdin.on(\"end\", () => {\n const [n, k] = input.split(\" \").map(Number);\n if (n * k > n * (n - 1) / 2) {\n process.stdout.write(\"-1\\n\");\n return;\n }\n let accumulated = \"\";\n accumulated += String(n * k) + \"\\n\";\n for (let i = 0; i < n; i++)\n for (let j = 1; j <= k; j++)\n accumulated += (String(i + 1) + \" \" + String((i + j) % n + 1) + \"\\n\");\n process.stdout.write(accumulated);\n});", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], k = data[1],\n\t\tm = n*k;\n\tif (m > n*(n-1)/2) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\tvar parts = [m];\n\tfor (var i = 0; i < n; ++i) {\n\t\tfor (var d = 1; d <= k; ++d) {\n\t\t\tvar a = i + 1, b = (i+d)%n + 1;\n\t\t\tparts.push(a+' '+b);\n\t\t}\n\t}\n\tprint(parts.join('\\n'));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "process.stdin.setEncoding(\"utf8\");\nlet input = \"\";\nprocess.stdin.on(\"data\", x => input += x);\nprocess.stdin.on(\"end\", () => {\n const [n, k] = input.split(\" \").map(Number);\n if (n * k > n * (n - 1) / 2) {\n process.stdout.write(\"-1\\n\");\n return;\n }\n process.stdout.write(String(n * k) + \"\\n\");\n for (let i = 0; i < n; i++)\n for (let j = 0; j < k; j++)\n process.stdout.write(String(i + 1) + \" \" + String((i + j) % n + 1) + \"\\n\");\n});\n"}], "src_uid": "14570079152bbf6c439bfceef9816f7e"} {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.arrNumber(' ');\n var m = n[1];\n var k = n[2];\n var n = n[0];\n\n var b = read.arrNumber(' ');\n\n var arr = [];\n for(var i = 1; i < n; i++) {\n arr.push(b[i] - b[i-1]);\n }\n \n arr = arr.sort((a, b) => a - b);\n var t = n - k;\n\n var sum = 0;\n for(var i = 0; i < t; i++) {\n sum += arr[i] - 1;\n }\n\n print(n + sum);\n}());", "positive_code": [{"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => eleA - eleB);\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nconsole.log(ans);"}], "negative_code": [{"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\nconst diffArrSM = diffArr.sort((eleA, eleB) => eleA - eleB).slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nconsole.log(ans);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => parseInt(eleA) > parseInt(eleB));\n\nlet ans = k;\nfor (let i = 0; i < n - k; i++) {\n ans += diffArr[i];\n}\n\nconsole.log(ans);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nconsole.log(ans);\n\n// Test"}, {"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nif (n > 10000) {\n console.log(diffArr[diffArr.length - 1], diffArr[diffArr.length - 2]);\n}\n\nconsole.log(ans);"}, {"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nif (n > 10000) {\n console.log(diffArr[diffArr.length - 1]);\n}\n\nconsole.log(ans);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nconsole.log(ans);\n"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => ({\n diff: arr[idx + 1] - ele,\n idx: idx,\n}));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => eleA.diff < eleB.diff);\n\nconst sepIdxList= diffArr.slice(0, k - 1).map((ele) => ele.idx);\nconst lastSepIdx = sepIdxList[sepIdxList.length - 1];\nconst lastSegFirstIdx = sepIdxList.length > 0 ? lastSepIdx + 1 : 0;\nlet ans = 0;\n\nsepIdxList.forEach((sepIdx, idx) => {\n ans += arr[sepIdx] - arr[idx > 0 ? sepIdxList[idx - 1] + 1 : 0] + 1;\n});\nans += arr[n - 1] - arr[lastSegFirstIdx] + 1;\n\nconsole.log(ans);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nlet ans = k;\nfor (let i = 0; i < n - k; i++) {\n ans += diffArr[i];\n}\n\nconsole.log(ans);\n"}, {"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => parseInt(eleA) > parseInt(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nif (n > 10000) {\n console.log(diffArr.slice(0, 100));\n}\n\nconsole.log(ans);"}, {"source_code": "const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\nconst diffArrSM = diffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB)).slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nconsole.log(ans);"}, {"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nif (n > 10000) {\n console.log(arr.length);\n}\n\nconsole.log(ans);"}, {"source_code": "\n const fs = require('fs');\nconst stdinBuffer = fs.readFileSync(0).toString('utf8');\nconst [[n, m, k], arr] = stdinBuffer.split('\\n').map((line) => \n line.split(' ').map((ele) => parseInt(ele))\n);\nconst diffArr = arr.map((ele, idx) => (arr[idx + 1] - ele));\n\ndiffArr.pop();\ndiffArr.sort((eleA, eleB) => Number(eleA) > Number(eleB));\n\nconst diffArrSM = diffArr.slice(0, n - k);\nconst ans = diffArrSM.reduce((ac, c) => ac + c, 0) + k;\n\nif (n > 10000) {\n console.log(diffArr.slice(0, 100));\n}\n\nconsole.log(ans);"}], "src_uid": "6b2b56a423c247d42493d01e06e4b1d2"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => { \n solveWrap(inputString); \n});\n\nfunction solve(s, t){\n\tlet repl = [];\n\tfor (let i = 0; i < t.length; i++) {\n\t\tif(t[i]!=s[i]){\n\t\t\tif(repl.length<2)\n\t\t\t\trepl.push({t: t[i], s: s[i]});\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\t}\n\tif(repl.length==1)\n\t\treturn false;\n\telse if(repl.length==2){\n\t\tif(repl[0].t!=repl[1].t || repl[0].s!=repl[1].s)\n\t\t\treturn false;\n\t}\n\treturn true;\n}\n\n\nfunction solveWrap(input) {\n let inputAr = input.trim().split('\\n');\n\tlet k = inputAr.shift();\n\tfor (let i = 0; i < k; i++) {\n\t\tinputAr.shift();\n\t\tconsole.log(solve(inputAr.shift().split(''), inputAr.shift().split(''))?'Yes':'No');\n\t}\n}\n\n", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (n, s, t) => {\n for (let i = 0; i < n; i++) {\n if (s[i] !== t[i]) {\n for(let j = i + 1; j < n; j++) {\n if (s[j] !== t[j]) {\n if (s[i] !== s[j] || t[i] !== t[j]) return 'No';\n for (let k = j + 1; k < n; k++) {\n if (s[k] !== t[k]) return 'No'\n }\n return 'Yes';\n }\n }\n return 'No';\n }\n }\n return 'Yes';\n}\nlet q = +readline();\nwhile(q--) print(problem(+readline(), readline(), readline()));\n"}], "negative_code": [], "src_uid": "97fa7e82566e3799e165ce6cbbf1da22"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n for(let tt=0;tt {return parseInt(string.trim());});\r\n let n = a[0], k = a[1];\r\n m = {};\r\n a = readLine().trim().split(' ').map(string => {return parseInt(string.trim());});\r\n for(let i=0;i { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_k = readLine().split(' ').map(p => +p);\r\n const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_k[0], n_k[1], arr);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\nfunction myFunc(n, k, arr){\r\n let max = new Array(k).fill(0);\r\n let resp = BigInt(0);\r\n\r\n for(let i = 0; i < n; i++){\r\n if(arr[i] > max[i%k]) max[i%k] = arr[i];\r\n }\r\n\r\n for(let i = 0; i < max.length; i++){\r\n resp += BigInt(max[i])\r\n }\r\n\r\n return resp.toString();\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n k = rn(),\r\n a = new Array(n);\r\n for (let i = 0; i < n; i++) a[i] = rn();\r\n let res = 0;\r\n for (let i = 0; i < k; i++) {\r\n let ans = 0;\r\n for (let j = i; j < n; j += k) ans = Math.max(ans, a[j]);\r\n res += ans;\r\n }\r\n return res;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction getResult(n, k, inputs) {\r\n\tlet sums = Array(100).fill(0)\r\n\tlet sum = 0\r\n\t\r\n\tlet i = j = 0\r\n\twhile(i < n)\r\n\t{\r\n\t\tif(j==k) j=0\r\n\t\t\r\n\t\tsums[j] = Math.max(inputs[i], sums[j])\r\n\t\tj++\r\n\t\ti++\r\n\t}\r\n\t\r\n\tfor(let i=0; i Number(prev) + Number(curr), 0);\n}\n\nfunction consecutive(cases) {\n // Write your code here\n // swap\n for (let i = 0; i < cases.length; i++) {\n const n = Number(cases[i].n);\n const k = Number(cases[i].k);\n const arr = cases[i].arr;\n const consecutiveArr = {};\n for (let j = 0; j < n; j++) {\n consecutiveArr[j % k] = [\n ...(consecutiveArr[j % k] || []),\n Number(arr[j]),\n ].sort((a, b) => b - a);\n }\n\n // sum\n let sum = 0;\n Object.keys(consecutiveArr).forEach((field) => {\n sum += consecutiveArr[field][0];\n });\n console.log(sum);\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 1; i <= t * 2; i++) {\n if (i % 2 === 1) {\n const nk = readLine().split(\" \");\n cases[Math.ceil(i / 2) - 1] = {\n ...cases[Math.ceil(i / 2) - 1],\n n: nk[0],\n k: nk[1],\n };\n } else {\n const arr = readLine().split(\" \");\n cases[Math.ceil(i / 2) - 1] = { ...cases[Math.ceil(i / 2) - 1], arr };\n }\n }\n\n consecutive(cases);\n}\n\n \t\t\t \t\t \t \t\t \t\t\t\t \t\t \t \t\t"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, k = 0;\n for(i = 1; i <= t * 2; i++){\n var a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0], k = a[1];\n }else{\n var v = new Array(k);\n for(j = 0; j < k; j++){\n v[j] = 0;\n }\n for(j = 0; j < n; j++){\n v[j % k] = Math.max(v[j % k], a[j]);\n }\n var ans = 0;\n for(j = 0; j < v.length; j++){\n ans += v[j];\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', ()=>{\r\n let chunk=process.stdin.read();\r\n if(chunk) buf += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', ()=>{\r\n let lines=buf.split('\\n');\r\n let lc=0;\r\n let t=parseInt(lines[lc++]);\r\n while(t--) {\r\n let _nk=lines[lc++].split(' ');\r\n let n=parseInt(_nk[0]),k=parseInt(_nk[1]);\r\n let _=lines[lc++].split(' ');\r\n let a=[];\r\n for(let i=0;i {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let [n,k] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let sum = 0;\r\n for(let i=0;iarr[max]) max = j\r\n }\r\n }\r\n [arr[i],arr[max]] = [arr[max],arr[i]];\r\n sum+=arr[i];\r\n }\r\n console.log(sum);\r\n }\r\n};\r\nsolve();"}, {"source_code": "const { dir, count } = require(\"console\");\r\nlet readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let testcase = 1; testcase < input.length; testcase += 2) {\r\n let nk = input[testcase].split(\" \");\r\n let numbers = input[testcase + 1].split(\" \");\r\n let arr = [];\r\n for (let i = 0; i < numbers.length; i++) {\r\n let max = 0;\r\n for (let j = i; j < numbers.length; j += Number(nk[1])) {\r\n max = Math.max(numbers[j], max);\r\n }\r\n arr.push(max);\r\n }\r\n\r\n let result = 0;\r\n\r\n for (let i = 0; i <= arr.length - Number(nk[1]); i++) {\r\n let count = 0;\r\n\r\n for (let j = i; j < i + Number(nk[1]); j++) {\r\n count += arr[j];\r\n }\r\n result = Math.max(result, count);\r\n }\r\n\r\n console.log(result);\r\n }\r\n};\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction getResult(n, k, inputs) {\r\n\tlet res = 0\r\n\tlet sums = Array(n).fill(0)\r\n\tlet sum = 0\r\n\t\r\n\tfor (let i = 0; i < k; i++) \r\n\t{\r\n\t\tsum += inputs[i]\r\n\t}\r\n\t\r\n\tfor (let i = 0; i < n; i++) \r\n\t{\r\n\t\tlet rem = inputs[i] % k\r\n\t\tsums[rem] += inputs[i]\r\n\t\tres = Math.max(res, sums[rem])\r\n\t}\r\n\t\r\n\tres = Math.max(res, sum)\r\n\t\r\n\tfor (let i = k; i < n; i++) \r\n\t{\r\n\t\tsum = sum - inputs[i - k] + inputs[i]\r\n\t\tres = Math.max(res, sum)\r\n\t}\r\n\t\r\n\treturn res \r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while(testcases--){\r\n \tlet inputs = readline().split(' ').map(Number)\r\n \tlet n = inputs[0]\r\n \tlet k = inputs[1]\r\n \t\r\n \tinputs = readline().split(' ').map(Number)\r\n \t\r\n \tlet res = getResult(n, k, inputs)\r\n \tconsole.log( res )\r\n }\r\n}\r\n"}], "src_uid": "f974c33780a933a6076c0559e48b7552"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let len = +readLine();\n let [i, plusCount, minusCount] = [0, 0, 0];\n const [input, stack, store, ans] = [[], [], [], []];\n while (i++ < 2 * len) {\n const line = readLine();\n if (line.length === 1) {\n sign = line;\n plusCount++;\n } else {\n [sign, num] = line.split(\" \");\n store.push(+num);\n minusCount++;\n }\n input.push(sign);\n }\n\n if (plusCount !== minusCount) {\n console.log(\"NO\");\n return;\n }\n\n for (let i = 2 * len - 1; i >= 0; i--) {\n const sign = input[i];\n if (sign === \"+\") {\n if (!stack.length) {\n console.log(\"NO\");\n return;\n } else {\n const top = stack.pop();\n ans.unshift(top);\n }\n } else {\n if (store[store.length - 1] > stack[stack.length - 1]) {\n console.log(\"NO\");\n return;\n } else {\n let n = store.pop();\n stack.push(n);\n }\n }\n }\n console.log(\"YES\");\n console.log(ans.join(\" \"));\n}\n", "positive_code": [{"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number []} trans\n * @returns {String}\n */\nfunction solve(trans) {\n const stack = [];\n const res = [];\n while (trans.length > 0) {\n const t = trans.pop();\n if (t === 0) {\n if (stack.length < 1) {\n return 'NO';\n }\n res.push(stack.pop());\n } else if (stack.length > 0 && stack[stack.length-1] < t) {\n return 'NO';\n } else {\n stack.push(t);\n }\n }\n res.reverse();\n return 'YES\\n' + res.join(' ');\n}\n\nasync function main() {\n const n = Number(await getLine());\n const trans = [];\n for (let i = 0; i < 2 * n; i++) {\n const l = (await getLine()).split(' ');\n if (l[0] === '+') {\n trans[i] = 0;\n } else {\n trans[i] = Number(l[1]);\n }\n }\n const res = solve(trans);\n console.log(res);\n}\n\nif (require.main === module) {\n main();\n}"}], "negative_code": [], "src_uid": "5fa2af185c4e3c8a1ce3df0983824bad"} {"source_code": "var nElements = +readline();\nvar elements = readline().split(' ').map(Number);\n\nvar index1 = 0;\nvar index2 = nElements - 1;\nvar maxSum = 0;\nvar maxIndex1 = 0;\nvar maxIndex2 = 0;\nvar sum1 = elements[0];\nvar sum2 = elements[index2];\n\nwhile (index1 < index2) {\n if(sum1 < sum2) {\n index1++;\n sum1 += elements[index1];\n } else if(sum1 === sum2) {\n // Save this case\n maxSum = sum1;\n maxIndex1 = index1;\n maxIndex2 = index2;\n\n // Search for best case\n index1++;\n index2--;\n sum1 += elements[index1];\n sum2 += elements[index2];\n } else {\n index2--;\n sum2 += elements[index2];\n }\n}\n\nprint(maxSum);", "positive_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet arr = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet i = 0,\n\t\tj = n - 1,\n\t\ts1 = 0,\n\t\ts3 = 0,\n\t\tres = 0;\n\n\twhile (i <= j) {\n\t\tif (s1 <= s3) {\n\t\t\ts1 += arr[i];\n\t\t\ti++;\n\t\t} else {\n\t\t\ts3 += arr[j];\n\t\t\tj--;\n\t\t}\n\n\t\tif (s1 === s3) res = s1;\n\t}\n\tconsole.log(res);\n}\n"}, {"source_code": "var n = (+ readline ());\nvar a = readline ();\na = a.trim ().split ( ' ' );\nvar i;\nfor ( i = 0; i < n; i ++ ) { a [ i ] = Number ( a [ i ] ); }\nvar one = [ ];\nfor ( i = 0; i < n; i ++ ) { one [ i ] = (+ a [ i ]); }\nvar o = { };\no [ a [ a.length - 1 ] ] = 1;\nfor ( i = one.length - 2; i >= 0; i -- ) {\n one [ i ] += (+ one [ i + 1 ]); \n o [ one [ i ] ] = 1;\n}\nvar sum = 0;\nvar curr = 0;\nfor ( i = 0; i < n; i ++ ) {\n sum += a [ i ];\n delete o [ one [ i ] ];\n if ( sum in o ) curr = sum;\n}\nprint ( curr );\n"}], "negative_code": [{"source_code": "var n = (+ readline ());\nvar a = readline ();\na = a.trim ().split ( ' ' );\nvar i;\nfor ( i = 0; i < n; i ++ ) { a [ i ] = Number ( a [ i ] ); }\nvar one = [ ];\nfor ( i = 0; i < n; i ++ ) { one [ i ] = (+ a [ i ]); }\nvar o = { };\no [ a [ a.length - 1 ] ] = 1;\nfor ( i = one.length - 2; i > 0; i -- ) {\n one [ i ] += (+ one [ i + 1 ]); \n o [ one [ i ] ] = 1;\n}\nvar sum = 0;\nvar curr = 0;\nfor ( i = 0; i < n; i ++ ) {\n sum += a [ i ];\n if ( sum in o ) curr = sum;\n delete o [ one [ i ] ];\n}\nprint ( curr );\n"}], "src_uid": "f2fc865a44b39179261a7311adf48390"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [], log = console.log;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n).sort((a, b) => b - a);\n let c = a[0]\n For(1, n - 1, 1, i => {\n let [, j] = Arr(i, n - 1, 1, j => gcd(c, a[j])).max()\n let temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n c = gcd(c, a[i]);\n });\n console.log(a.join(' '))\n }\n})();\n\n", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [], log = console.log;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n).sort((a, b) => b - a);\n let c = a[0]\n For(1, n - 1, 1, i => {\n let [, j] = Arr(i, n - 1, 1, j => gcd(c, a[j])).max();\n [a[i], a[j]] = [a[j], a[i]];\n c = gcd(c, a[i]);\n });\n log(a.join(' '))\n }\n})();\n\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n).sort(desc);\n let c = a[0]\n For(1, n - 1, 1, i => {\n let j = Arr(i, n - 1, 1, j => gcd(c, a[j])).max()[1];\n [a[i], a[j]] = [a[j], a[i]];\n c = gcd(c, a[i]);\n });\n log(a.join(' '))\n }\n})();\n\n"}], "negative_code": [], "src_uid": "bdd1974e46f99eff3d03ed4174158dd9"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array();\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar map = getPrimeFactorization(N);\n\t\tvar key = Object.keys(map);\n\t\tkey.sort(function(a,b){\n\t\t\treturn map[b] - map[a];\n\t\t});\n\t\tvar list = [];\n\t\tfor(var j = 0; j < map[key[0]] - 1; j++){\n\t\t\tlist.push(key[0]);\n\t\t}\n\t\tN /= Math.pow(key[0], map[key[0]] - 1);\n\t\tlist.push(N);\n\t\toutput.push(list.length);\n\t\toutput.push(myconv(list, 8));\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction getPrimeFactorization(val){\n var primeMap = {};\n var div = 2;\n if(isPrime(val)){\n primeMap[val] = 1;\n return primeMap;\n }\n while(val != 1){\n if(val % div == 0){\n var count = 2;\n while(val % Math.pow(div, count) == 0){\n count++;\n }\n (primeMap[div] == null) ? primeMap[div] = (count - 1) : primeMap[div] += (count - 1);\n val /= Math.pow(div, count - 1);\n if(isPrime(val)){\n (primeMap[val] == null) ? primeMap[val] = 1 : primeMap[val]++;\n break;\n }\n }\n div = (div == 2) ? div + 1 : div + 2;\n }\n return primeMap;\n}\nfunction isPrime(val){\n if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}", "positive_code": [{"source_code": "\"use strict\";\n\n(() => {\n\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let curLine = 0, allLines = [];\n\n let nextLine = () => {\n if(curLine == allLines.length) throw new ReferenceError(\"No more input in the buffer\");\n return allLines[curLine++]\n };\n \n readline.on(\"line\", line => { allLines.push(line); });\n readline.on(\"close\", () => { main(nextLine) });\n\n})();\n\nfunction main(nextLine) {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n \n let ans = new Array(40).fill(1);\n\n for(let i = 2; i*i <= n; i++) {\n if(n%i == 0) {\n for(let j = 0; n%i == 0; j++) ans[j] *= i, n /= i;\n }\n }\n if(n > 1) ans[0] *= n;\n\n while(ans[ans.length-1] === 1) ans.pop();\n ans.reverse();\n\n console.log(ans.length);\n console.log(ans.join(\" \"));\n }\n}"}, {"source_code": "const rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lines = [];\n\nrl.on('line', (data) => {\n lines.push(data);\n if(lines.length > 0 && parseInt(lines[0]) === lines.length - 1) {\n\trl.close();\n\tmain();\n }\n});\n\nasync function main() {\n let t = parseInt(lines[0]);\n for(let i = 1; i <= t; i++) {\n\tlet n = parseInt(lines[i]);\n\n\tlet factpow = {};\n\tfor(let j = 2; j*j <= n; j++) {\n\t if(n % j === 0) {\n\t\tfactpow[j] = 0;\n\t\twhile(n % j === 0) {\n\t\t n /= j;\n\t\t factpow[j]++;\n\t\t}\n\t }\n\t}\n\tif(n != 1) {\n\t factpow[n] = 1;\n\t}\n\n\tlet lenmx = 0;\n\tfor(const v in factpow) {\n\t lenmx = Math.max(lenmx, factpow[v]);\n\t}\n\n\tlet arr = [];\n\tfor(let j = 0; j < lenmx; j++) {\n\t arr.push(1);\n\t}\n\n\tfor(const v in factpow) {\n\t let power = factpow[v];\n\t for(let j = lenmx - 1; j >= lenmx - power; j--) {\n\t\tarr[j] *= v;\n\t }\n\t}\n\n\tconsole.log(lenmx);\n\tconsole.log(arr.join(' '));\n }\n}\n"}, {"source_code": "function main() {\n var t = int(readline());\n \n while(t--) {\n var n = int(readline());\n primeFactors(n);\n }\n \n}\n\n// default parsers for JS.\nfunction int(x) {\n return parseInt(x);\n}\n\nfunction float(x) {\n return parseFloat(x);\n}\n\nfunction primeFactors(n) {\n var fr = {};\n var mx = 0;\n\n while (n % 2 === 0) { \n if(fr[2] === undefined) fr[2] = 0;\n fr[2]++;\n \n n /= 2; \n } \n \n if(fr[2])\n mx = Math.max(fr[2], mx);\n \n for (var i = 3; i <= int(Math.sqrt(n)); i = i + 2) { \n var flag = n % i === 0;\n\n while (n % i === 0) \n { \n if(fr[i] === undefined) fr[i] = 0;\n fr[i]++;\n n /= i; \n } \n \n if(flag)\n mx = Math.max(mx, fr[i]);\n } \n \n \n if (n > 2) \n fr[n] = 1;\n \n if(fr[n])\n mx = Math.max(mx, fr[n]);\n\n var ans = new Array(mx).fill(1);\n Object.keys(fr).forEach(v => {\n var gt = mx - 1;\n var freq = fr[v];\n while(gt >= 0 && freq--) {\n ans[gt--] *= v;\n }\n })\n\n \n print(mx);\n var finalAns = \"\";\n ans.forEach(v => {\n finalAns += v + \" \";\n \n });\n \n print(finalAns);\n /*for(auto val: ans) {\n printf(\"%lld \", val);\n }*/\n} \n\nmain();"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let n = +readLine();\n let [count, pivot] = [0, null];\n let [maxCount, maxArr] = [-Infinity, []];\n\n for (let i = 2; i <= Math.sqrt(n); i++) {\n if (n % i === 0) {\n let [number, store] = [n, []];\n while (Number.isInteger(number / i) && (number / i) % i === 0) {\n store.push(i);\n number = number / i;\n }\n store.push(number);\n if (store.length > maxArr.length) {\n maxArr = store;\n }\n }\n }\n if (!maxArr.length) {\n console.log(1);\n console.log(n);\n } else {\n console.log(maxArr.length);\n console.log(maxArr.join(\" \"));\n }\n }\n}\n"}], "negative_code": [{"source_code": "function main() {\n var t = int(readline());\n \n while(t--) {\n var n = int(readline());\n primeFactors(n);\n }\n \n}\n\n// default parsers for JS.\nfunction int(x) {\n return parseInt(x);\n}\n\nfunction float(x) {\n return parseFloat(x);\n}\n\nfunction primeFactors(n) {\n var fr = {};\n var mx = 0;\n\n while (n % 2 === 0) { \n if(fr[2] === undefined) fr[2] = 0;\n fr[2]++;\n \n n >>= 1; \n } \n \n if(fr[2])\n mx = Math.max(fr[2], mx);\n \n for (var i = 3; i <= Math.sqrt(n); i = i + 2) { \n var flag = n % i === 0;\n\n while (n % i === 0) \n { \n if(fr[i] === undefined) fr[i] = 0;\n fr[i]++;\n n /= i; \n } \n \n if(flag)\n mx = Math.max(mx, fr[i]);\n } \n \n \n if (n > 2) \n fr[n] = 1;\n \n if(fr[n])\n mx = Math.max(mx, fr[n]);\n\n var ans = new Array(mx).fill(1);\n Object.keys(fr).forEach(v => {\n var gt = mx - 1;\n var freq = fr[v];\n while(gt >= 0 && freq--) {\n ans[gt--] *= v;\n }\n })\n\n \n print(mx);\n var finalAns = \"\";\n ans.forEach(v => {\n finalAns += v + \" \";\n \n });\n \n print(finalAns);\n /*for(auto val: ans) {\n printf(\"%lld \", val);\n }*/\n} \n\nmain();"}], "src_uid": "f8d064c90f1f2b4a18386795dbcd9cb9"} {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor (var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n var countPairs = 0;\r\n\r\n for (var j = 0; j < arrayLength; j++) {\r\n var currentResidue = array[j] - j;\r\n if (residueHash.has(currentResidue)) {\r\n var currentValue = residueHash.get(currentResidue);\r\n var counter = currentValue + 1;\r\n residueHash.set(currentResidue, counter);\r\n var newResidue = parseInt(residueHash.get(currentResidue));\r\n } else {\r\n residueHash.set(currentResidue, 0);\r\n }\r\n }\r\n\r\n var iterator = residueHash.values();\r\n\r\n for (var j = 0; j < residueHash.size; j++) {\r\n var counter = iterator.next().value;\r\n countPairs += (counter * (counter + 1)) / 2\r\n }\r\n\r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n", "positive_code": [{"source_code": "const t=parseInt(readline());\r\n\r\nfor(var k=0;k {\r\n var dif = parseInt(v) - i;\r\n if (map.has(dif))\r\n map.set(dif, map.get(dif) + 1);\r\n else\r\n map.set(dif, 1);\r\n });\r\n var counter = 0;\r\n map.forEach((v) => counter += v * (v - 1) / 2);\r\n print(counter);\r\n \r\n \r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var test = 0; test < tests; test++) {\r\n var size = parseInt(readline());\r\n var map = new Map();\r\n var arr = readline().split(' ').forEach((v, i) => {\r\n var dif = parseInt(v) - i;\r\n if (map.has(dif))\r\n map.set(dif, map.get(dif) + 1);\r\n else\r\n map.set(dif, 1);\r\n });\r\n var counter = 0;\r\n map.forEach((v) => counter += v * (v - 1) / 2);\r\n print(counter);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var test = 0; test < tests; test++) {\r\n var size = parseInt(readline());\r\n var map = new Map();\r\n var arr = readline().split(' ').forEach((v, i) => {\r\n var dif = parseInt(v) - i;\r\n if (map.has(dif))\r\n map.set(dif, map.get(dif) + 1);\r\n else\r\n map.set(dif, 1);\r\n });\r\n var counter = 0;\r\n map.forEach((v) => counter += v * (v - 1) / 2);\r\n print(counter);\r\n}"}, {"source_code": "var input = new Array(parseInt(readline()) * 2);\r\n for (var i = 0; i < input.length; i++) {\r\n input[i] = readline();\r\n }\r\n var output = calc(input);\r\n output.forEach(function (value) { print(value); });\r\n function calc(inputArray) {\r\n var result = new Array();\r\n for (var i = 0; i < inputArray.length; i += 2) {\r\n var caseLength = parseInt(inputArray[i]);\r\n var caseArray = inputArray[i + 1].split(\" \");\r\n var resultArray = new Array(caseLength);\r\n for (var j = 0; j < caseLength; j++) {\r\n resultArray[j] = parseInt(caseArray[j]) - j;\r\n }\r\n resultArray.sort(function (a, b) { return a - b; });\r\n var currentTerm = resultArray[0];\r\n var seqLength = 1;\r\n var total = 0;\r\n for (var k = 1; k < caseLength; k++) {\r\n if (resultArray[k] === currentTerm) {\r\n seqLength++;\r\n }\r\n else {\r\n total += calcSeq(seqLength);\r\n currentTerm = resultArray[k];\r\n seqLength = 1;\r\n }\r\n }\r\n total += calcSeq(seqLength);\r\n result.push(total);\r\n }\r\n return result;\r\n }\r\n function calcSeq(seq) {\r\n var result = 0;\r\n for (var i = 1; i < seq; i++) {\r\n result += i;\r\n }\r\n return result;\r\n }"}, {"source_code": "var T = parseInt(readline());\r\nfunction nC2(n) { return n*(n-1)/2; }\r\nwhile (T--) {\r\n var N = parseInt(readline());\r\n var M = N-1;\r\n var P = 2*N+1;\r\n var a = readline().split(\" \");\r\n var count = new Array(P);\r\n for (var i = 0; i < P; ++i)\r\n count[i] = 0;\r\n\tfor (var i = 0; i < N; ++i)\r\n\t ++count[N+parseInt(a[i])-i]; \r\n\tvar ans = 0;\r\n\tfor (var i = 0; i < P; ++i)\r\n\t if (count[i] > 1)\r\n\t ans += nC2(count[i]);\r\n\tprint(ans); }\r\n\t "}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nconst readline = () => inputString[currentLine++];\n\n// main logic\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const arrayLength = 1 * readline();\n const arrayString = readline();\n const array = arrayString.split(\" \");\n const arrayNum = array.map((x) => +x);\n\n // console.log(arrayNum);\n\n const map = new Map();\n let result = 0;\n for (let i = 0; i < arrayNum.length; i++) {\n const key = arrayNum[i] - i - 1;\n const current = map.get(key) || 0;\n result += current;\n map.set(key, current + 1);\n }\n console.log(result);\n });\n};\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = arr[i] - (i + 1);\r\n }\r\n let obj = {},\r\n cnt = 1,\r\n flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) {\r\n flag = true;\r\n obj[arr[i]]++;\r\n } else obj[arr[i]] = 1;\r\n }\r\n if (flag) {\r\n let cnt = 0;\r\n for (let i of Object.keys(obj)) {\r\n let k = obj[i];\r\n if (k <= 1) continue;\r\n k--;\r\n cnt += (k * (k + 1)) / 2;\r\n }\r\n console.log(cnt);\r\n } else {\r\n console.log(0);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const solve = (arr) => {\r\n try {\r\n const set = {};\r\n\r\n for (let i = 0; i < arr.length; i += 1) {\r\n set[arr[i] - i] = (set[arr[i] - i] || 0) + 1;\r\n }\r\n\r\n let ans = 0;\r\n const keys = Object.values(set).filter((x) => x > 1);\r\n\r\n for (let i = 0; i < keys.length; i += 1) {\r\n ans += (keys[i] * (keys[i] - 1)) / 2;\r\n }\r\n \r\n return ans;\r\n } catch (ex) {\r\n console.log('ex:', ex);\r\n }\r\n};\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map(l => l.trim());\r\n\r\n for (let i=0; i {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tconst obj = {};\n\t\tlet ans = 0;\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tarr[i] = arr[i] - i;\n\t\t\tconst n = arr[i];\n\t\t\tobj[n] = (obj[n] || 0) + 1;\n\t\t}\n\t\tconst values = Object.values(obj);\n\t\tfor (let val of values) {\n\t\t\tif (val > 1) {\n\t\t\t\tans += Math.floor((val * (val - 1)) / 2);\n\t\t\t}\n\t\t}\n\t\tconsole.log(ans);\n\t}\n}\n"}, {"source_code": "\r\nconst solve = (arr) => {\r\n\r\n\tconst set = {};\r\n\tfor (let i=0; i v > 1);\r\n\r\n\tlet sum2 = 0;\r\n\tfor (let i=0; i input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [n, ...lines] = input.trim().split('\\n')\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=0; i dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet mp = new Map();\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst key = a[i] - i;\r\n\t\t\tconst vl = mp.has(key) ? mp.get(key) : 0;\r\n\t\t\tmp.set(key, vl + 1);\r\n\t\t\tans += vl;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = Number(input[b]);\r\n b++;\r\n var arr = input[b].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n b++;\r\n var map = new Map();\r\n var count = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n var diff = arr[i] - i;\r\n if (map.has(diff)) {\r\n count += map.get(diff);\r\n map.set(diff, map.get(diff) + 1);\r\n } else {\r\n map.set(diff, 1);\r\n }\r\n }\r\n console.log(count);\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = {};\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar V = list[j] - j;\r\n\t\t\tif(map[V] == null){\r\n\t\t\t\tmap[V] = 0;\r\n\t\t\t}\r\n\t\t\tmap[V]++;\r\n\t\t}\r\n\t\tvar key = Object.keys(map);\r\n\t\tvar output = 0;\r\n\t\tfor(var j = 0; j < key.length; j++){\r\n\t\t\tvar add = map[key[j]];\r\n\t\t\toutput += add * (add - 1) / 2;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var t = readline();\r\nt = Number(t);\r\nwhile (t--) {\r\n var count = {},\r\n last = 0;\r\n var n = Number(readline());\r\n var array = readline().split(\" \");\r\n for (var i = 1; i <= n; i++) {\r\n var test = \"test\" + ( array[i - 1] - i );\r\n count[test] = count[test] ? count[test] + 1 : 1;\r\n }\r\n for (var key in count) {\r\n last += count[key] > 1 ? (count[key] * (count[key] - 1)) / 2 : 0;\r\n }\r\n print(last);\r\n}\r\n"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var numberOfDigits = Number(readline());\r\n var array = readline().split(\" \").map(x => Number(x));\r\n\r\n var distances = {};\r\n\r\n var pairsCount = 0;\r\n for (var i = 0; i < array.length; ++i) {\r\n var distance = array[i] - i;\r\n if (!distances[distance]) {\r\n distances[distance] = 0;\r\n }\r\n\r\n pairsCount += distances[distance];\r\n ++distances[distance];\r\n }\r\n\r\n print(pairsCount);\r\n}"}], "negative_code": [{"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor (var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n var countPairs = 0;\r\n\r\n for (var j = 0; j < arrayLength; j++) {\r\n var currentResidue = array[j] - j;\r\n if (residueHash.has(currentResidue)) {\r\n var currentValue = residueHash.get(currentResidue);\r\n var counter = currentValue + 1;\r\n residueHash.set(currentResidue, counter);\r\n var newResidue = parseInt(residueHash.get(currentResidue));\r\n } else {\r\n residueHash.set(currentResidue, 0);\r\n }\r\n }\r\n\r\n for (var j = 0; j < residueHash.size; j++) {\r\n var counter = residueHash.values().next();\r\n countPairs += (counter * (counter + 1)) / 2\r\n }\r\n\r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor (var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n var countPairs = 0;\r\n\r\n for (var j = 0; j < arrayLength; j++) {\r\n var currentResidue = array[j] - j;\r\n if (residueHash.has(currentResidue)) {\r\n var currentValue = residueHash.get(currentResidue);\r\n var counter = currentValue + 1;\r\n residueHash.set(currentResidue, counter);\r\n var newResidue = parseInt(residueHash.get(currentResidue));\r\n } else {\r\n residueHash.set(currentResidue, 0);\r\n }\r\n }\r\n\r\n print(residueHash.values())\r\n\r\n // for (var [residue, counter] of residueHash) {\r\n // countPairs += (counter * (counter + 1)) / 2\r\n // }\r\n \r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor (var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n var countPairs = 0;\r\n\r\n for (var j = 0; j < arrayLength; j++) {\r\n var currentResidue = array[j] - j;\r\n if (residueHash.has(currentResidue)) {\r\n var currentValue = residueHash.get(currentResidue);\r\n var counter = currentValue + 1;\r\n residueHash.set(currentResidue, counter);\r\n var newResidue = parseInt(residueHash.get(currentResidue));\r\n } else {\r\n residueHash.set(currentResidue, 0);\r\n }\r\n }\r\n\r\n\r\n // for (var [residue, counter] of residueHash) {\r\n // countPairs += (counter * (counter + 1)) / 2\r\n // }\r\n \r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor(var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(parseInt(array[j]));\r\n if(currentValue) {\r\n residueHash.set(parseInt(array[j]), 0);\r\n } else {\r\n residueHash.set(parseInt(array[j]), parseInt(currentValue) + 1);\r\n }\r\n }\r\n\r\n var countPairs = 0;\r\n \r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(array[j]);\r\n countPairs =+ (parseInt(currentValue) * (parseInt(currentValue) + 1)) / 2\r\n }\r\n \r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor(var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(array[j]);\r\n if(currentValue) {\r\n residueHash.set(array[j], 0);\r\n } else {\r\n residueHash.set(array[j], parseInt(currentValue) + 1);\r\n }\r\n }\r\n\r\n var countPairs = 0;\r\n \r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(array[j]);\r\n countPairs =+ (parseInt(currentValue) * (parseInt(currentValue) + 1)) / 2\r\n }\r\n \r\n print(countPairs);\r\n}"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor(var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(array[j]);\r\n if(currentValue) {\r\n residueHash.set(array[j], 0);\r\n } else {\r\n residueHash.set(array[j], currentValue + 1);\r\n }\r\n }\r\n\r\n var countPairs = 0;\r\n \r\n for(var j = 0; j < arrayLength; j++) {\r\n var currentValue = residueHash.get(array[j]);\r\n countPairs =+ (currentValue * (currentValue + 1)) / 2\r\n }\r\n \r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "var testsCounter = parseInt(readline());\r\n\r\nfor(var i = 0; i < testsCounter; i++) {\r\n var arrayLength = parseInt(readline());\r\n var array = readline().split(' ');\r\n var residueHash = new Map();\r\n for(var j = 0; i < arrayLength; i++) {\r\n var currentValue = residueHash.get(array[j]);\r\n if(currentValue) {\r\n residueHash.set(array[j], 0);\r\n } else {\r\n residueHash.set(array[j], currentValue + 1);\r\n }\r\n }\r\n\r\n var countPairs = 0;\r\n \r\n for(var j = 0; i < arrayLength; i++) {\r\n var currentValue = residueHash.get(array[j]);\r\n countPairs =+ (currentValue * (currentValue + 1)) / 2\r\n }\r\n \r\n print(countPairs);\r\n}\r\n\r\n\r\n\r\n"}, {"source_code": "\r\nvar t = readline()\r\nt = Number(t)\r\nwhile (t--) {\r\n var count = [], last = 0;\r\n var n = Number(readline())\r\n var array = readline().split(\" \")\r\n for(var i = 1; i <= n; i++){\r\n if(array[i - 1] - i >= 0)\r\n count[array[i - 1] - i] = count[array[i - 1] - i]? count[array[i - 1] - i] + 1: 1\r\n }\r\n for(var i = 0; i < count.length; i++){\r\n if(count[i] > 1){\r\n last += ( count[i] * ( count[i] - 1 ) ) / 2\r\n }\r\n }\r\n print(last)\r\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nconst readline = () => inputString[currentLine++];\n\n// main logic\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const arrayLength = 1 * readline();\n const arrayString = readline();\n const array = arrayString.split(\" \");\n const arrayNum = array.map((x) => +x);\n\n console.log(arrayNum);\n\n const results = Array.from({ length: arrayLength }, () => 0);\n for (let i = 0; i < arrayNum.length; i++) {\n for (let j = i + 1; j < arrayNum.length; j++) {\n // console.log(\n // \"i\",\n // i,\n // \"j\",\n // j,\n // \"a_j\",\n // arrayNum[j],\n // j - i + arrayNum[i] === arrayNum[j]\n // );\n if (j - i + arrayNum[i] === arrayNum[j]) {\n // console.log(\".\");\n results[j] += 1;\n }\n }\n }\n // console.log(\"results\", results);\n console.log(results.reduce((i, j) => i + j, 0));\n });\n};\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = Math.abs(arr[i] - i + 1);\r\n }\r\n let obj = {},\r\n cnt = 1,\r\n flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) {\r\n flag = true;\r\n obj[arr[i]]++;\r\n } else obj[arr[i]] = 1;\r\n }\r\n if (flag) {\r\n let cnt = 0;\r\n for (let i of Object.keys(obj)) {\r\n let k = obj[i];\r\n if (k <= 1) continue;\r\n k--;\r\n cnt += (k * (k + 1)) / 2;\r\n }\r\n console.log(cnt);\r\n } else {\r\n console.log(0);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = Math.abs(arr[i] - i + 1);\r\n }\r\n console.log(arr);\r\n let obj = {},\r\n cnt = 1,\r\n flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) {\r\n flag = true;\r\n obj[arr[i]]++;\r\n } else obj[arr[i]] = 1;\r\n }\r\n if (flag) {\r\n let cnt = 0;\r\n for (let i of Object.keys(obj)) {\r\n let k = obj[i];\r\n if (k <= 1) continue;\r\n k--;\r\n cnt += (k * (k + 1)) / 2;\r\n }\r\n console.log(cnt);\r\n } else {\r\n console.log(0);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = Math.abs(arr[i] - i + 1);\r\n }\r\n let obj = {},\r\n cnt = 1,\r\n flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) {\r\n flag = true;\r\n obj[arr[i]]++;\r\n } else obj[arr[i]] = 1;\r\n }\r\n if (flag) {\r\n for (let i of Object.keys(obj)) {\r\n let k = obj[i];\r\n if (k <= 1) continue;\r\n k--;\r\n console.log((k * (k + 1)) / 2);\r\n }\r\n } else {\r\n console.log(0);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const solve = (arr) => {\r\n try {\r\n const set = {};\r\n\r\n for (let i = 0; i < arr.length; i += 1) {\r\n set[arr[i] - i] = (set[arr[i] - i] || 0) + 1;\r\n }\r\n\r\n const keys = Object.values(set).filter((x) => x > 1).reduce((acc, curr) => acc + curr, 0);\r\n if (keys > 1) {\r\n return (keys * (keys - 1)) / 2;\r\n } else {\r\n return keys;\r\n }\r\n } catch (ex) {\r\n console.log('ex:', ex);\r\n }\r\n};\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map(l => l.trim());\r\n\r\n for (let i=0; i {\r\n try {\r\n const set = {};\r\n\r\n for (let i = 0; i < arr.length; i += 1) {\r\n set[arr[i] - i] = (set[arr[i] - i] || 0) + 1;\r\n arr[i] = arr[i] - i;\r\n }\r\n const keys = Object.values(set).filter((x) => x > 1).reduce((acc, curr) => acc + curr, 0);\r\n return (keys * (keys - 1)) / 2;\r\n } catch (ex) {\r\n console.log('ex:', ex);\r\n }\r\n};\r\n\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map(l => l.trim());\r\n\r\n for (let i=0; i {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tconst obj = {};\n\t\tlet max = -Infinity;\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tarr[i] = arr[i] - i;\n\t\t\tconst n = arr[i];\n\t\t\tobj[n] = (obj[n] || 0) + 1;\n\t\t\tmax = Math.max(max, obj[n]);\n\t\t}\n\t\tconst ans = Math.floor((max * (max - 1)) / 2);\n\t\tconsole.log(ans);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tconst obj = {};\n\t\tlet max = -Infinity;\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tarr[i] = arr[i] - i;\n\t\t\tconst n = arr[i];\n\t\t\tobj[n] = (obj[n] || 0) + 1;\n\t\t\tmax = Math.max(max, obj[n]);\n\t\t}\n\t\tconst ans = Math.floor(max * (max - 1)) / 2;\n\t\tconsole.log(ans);\n\t}\n}\n"}], "src_uid": "ac4aac095e71cbfaf8b79262d4038095"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split('');\n var t = 0, I = 0, m = 0, u = 0, r = 0;\n if(e == 5){\n\n for(l = 0; l < e; l++){\n if(k[l] == 'T'){\n t ++;\n }else if(k[l] == 'i'){\n I ++;\n }else if(k[l] == 'm'){\n m ++;\n }else if(k[l] == 'u'){\n u ++;\n }else if(k[l] == 'r'){\n r ++;\n }\n }\n }\n if(t == 1 && I ==1&& m==1 && u ==1&& r==1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n\n }\n \n }\n});", "positive_code": [{"source_code": "n=+readline();\r\nwhile(n--){\r\n l=+readline();\r\n t=readline();\r\n if(l === 5){\r\n p = t.match(/(m|r|i|T|u)/g);\r\n newP=[...new Set(p)];\r\n print(p === null ? \"NO\" : newP.length === 5 ? \"YES\" : \"NO\" )\r\n }else{\r\n print(\"NO\")\r\n }\r\n}"}, {"source_code": "(function main(){\r\n \r\n var t = readline();\r\n for(var i = 0; i sum += m[x]);\r\n if (sum != 5) {\r\n ans = 'NO';\r\n }\r\n print(ans);\r\n }"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var t1 = +readline();\r\n var t2 = readline();\r\n print(removePrefix(t2));\r\n \r\n}\r\n \r\nfunction removePrefix(num){\r\n \r\n return num.split('').sort().join('') === 'Timru' ? 'YES' : 'NO';\r\n\r\n\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nvar origin = 'Timur'.split('').sort();\r\n \r\nfor (var test = 0; test < t; test++) {\r\n var n = parseInt(readline());\r\n var str = readline();\r\n\r\n if (n !== 5) {\r\n print('NO');\r\n } else {\r\n var arr = str.split('').sort();\r\n\r\n if (arr.join('') === origin.join('')) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var t = readline(),\r\n timurName = [\"T\" , \"i\" , \"m\" , \"u\" , \"r\"],\r\n sortedName = timurName.sort().toString();\r\n for(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n s= readline().split(''),\r\n sortedInput = s.sort();\r\n if(sortedInput == sortedName ){\r\n print(\"YES\");}\r\n else{\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "/*\r\nif length is 5\r\nand includes T, i, m, u, r\r\nyes, else no\r\n*/\r\nvar n=readline();\r\nfor(var i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split('');\n var t = false, I = false, m = false, u = false, r = false;\n if(e == 5){\n\n for(l = 0; l < e; l++){\n if(k[l] == 'T'){\n t = true;\n }else if(k[l] == 'i'){\n I = true;\n }else if(k[l] == 'm'){\n m = true;\n }else if(k[l] == 'u'){\n u = true;\n }else if(k[l] == 'r'){\n r = true;\n }\n }\n }\n if(t && I && m && u && r){\n console.log('YES');\n }else{\n console.log('NO');\n }\n\n }\n \n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split('');\n var timur = ['T', 'i', 'm', 'u', 'r'];\n if(n == 5){\n for(j = 0; j < n; j++){\n for(l = 0; l < 5; l++){\n if(k[j] == timur[l]){\n timur.splice(l, 1);\n break;\n }\n }\n }\n console.log(timur.length === 0 ? 'YES' : 'NO');\n }else{\n console.log('NO');\n }\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split('');\n var name = ['T', 'i', 'm', 'u', 'r'];\n var check = 0;\n if(n == 5){\n for(j = 0; j < n; j++){\n for(l = 0; l < n; l++){\n if(k[j] == name[l]){\n check++;\n name.splice(l, 1);\n }\n }\n }\n console.log(name.length === 0 ? 'YES' : 'NO');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n\r\n for (let i = 0; i < n; i++) {\r\n const sz = parseInt(readline());\r\n let str = readline();\r\n\r\n if (sz != 5) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n console.log([...str].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('') == \"Timru\" ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n const s = Array.from(\"Timur\");\r\n s.sort();\r\n\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var x = Array.from(readline());\r\n x.sort();\r\n var ok = true;\r\n if (n === 5)\r\n for (let i = 0;i < 5;++i) {\r\n // console.log(x[i],s[i]);\r\n if (x[i+1] != s[i]) {\r\n ok = false;\r\n }\r\n }\r\n if (n ===5 && ok) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n const s = Array.from(\"Timur\");\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var x = Array.from(readline());\r\n let cnt = 0;\r\n var hsh = new Array(5).fill(false);\r\n for (let i = 0; i < n;++i) {\r\n for (let j = 0;j < 5;++j) {\r\n if (hsh[j] === false && s[j] === x[i]) {\r\n hsh[j] = true;\r\n cnt++;\r\n }\r\n }\r\n }\r\n if (n === 5 && cnt === 5) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet standardInputString = ''\r\nlet currentLine = 0 \r\n\r\nfunction readLine(){\r\n return standardInputString[currentLine++]\r\n}\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData\r\n})\r\n\r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString.trim().split('\\n').map(line => {\r\n return line.trim()\r\n })\r\n\r\n main()\r\n})\r\n\r\n\r\n\r\n// ......................................................... //\r\n\r\n\r\nconst main=()=>{\r\n const testCase =parseInt(readLine());\r\n \r\n for (let index = 1; index <= testCase; index++) {\r\n const length =parseInt(readLine());\r\n const string = readLine();\r\n console.log(spellCheck(length, string));\r\n \r\n }\r\n}\r\n\r\nconst spellCheck = (length, string) => {\r\n const sort = str => str.split('').sort((a, b) => a.localeCompare(b)).join('');\r\n const name = 'Timur';\r\n if (sort(name) === sort(string))\r\n return 'YES';\r\n \r\n else\r\n return 'NO'\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\r\nconst { start } = require(\"repl\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n let name = [\"T\", \"i\", \"m\", \"u\", \"r\"];\r\n\r\n for (let i = 1; i < input.length; i += 2) {\r\n if (+input[i] !== 5) {\r\n console.log(\"NO\");\r\n continue;\r\n } else {\r\n let count = 0;\r\n let test = input[i + 1];\r\n\r\n for (let j = 0; j < name.length; j++) {\r\n if (test.includes(name[j])) count++;\r\n else {\r\n console.log(\"NO\");\r\n break;\r\n }\r\n }\r\n\r\n if (count === 5) console.log(\"YES\");\r\n }\r\n }\r\n};\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar ok = \"Timur\";\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar map = {};\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(ok.indexOf(s[i]) == -1){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(map[s[i]]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tmap[s[i]] = true;\r\n\t\t}\r\n\t\tfor(var i = 0; i < ok.length; i++){\r\n\t\t\tif(map[ok[i]] == null){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nconst original = [\"T\", \"i\", \"m\", \"r\", \"u\"];\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const chars = [...d].sort();\n let ans = \"YES\";\n\n for (let i = 0; i < original.length; i++) {\n if (original[i] !== chars[i]) {\n ans = \"NO\";\n break;\n }\n }\n\n if (chars.length !== original.length) {\n ans = \"NO\";\n }\n\n console.log(ans);\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n let s = readline()\r\n console.log( solve(n,s) )\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, s) => {\r\n if( n != 5 ) return 'NO'\r\n \r\n let flag = false\r\n \r\n if( s.includes(\"T\") ) {\r\n\t if( s.includes(\"i\") ) {\r\n\t\t if( s.includes(\"m\") ) {\r\n\t\t\t if( s.includes(\"u\") ) {\r\n\t\t\t\t if( s.includes(\"r\") ) {\r\n\t\t\t\t \treturn 'YES'\r\n\t\t\t\t }\r\n\t\t\t }\r\n\t\t }\r\n\t }\r\n }\r\n \r\n return 'NO'\r\n}\r\n\r\n// 12339\r\n// 0\r\n// 15\r\n// 54306\r\n// 999999995\r\n// 185\r\n// 999999998\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => string.trim());\n\n main();\n});\n\nfunction main() {\n const testCases = inputString[0];\n\n for (let i = 1; i <= testCases * 2; i += 2) {\n const length = Number(inputString[i]);\n const str = inputString[i + 1].split(\"\");\n if (length !== 5) console.log(\"NO\");\n else {\n const name = new Set(\"Timur\".split(\"\"));\n str.forEach(e => name.delete(e));\n if(name.size === 0) console.log(\"YES\");\n else console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let s = readline().split('');\r\n\r\n let t = ('Timur').split('');\r\n t.sort();\r\n s.sort();\r\n output(t.join('') === s.join('') ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Main Function, write code here\r\n\r\nfunction main() {\r\n let T = readline();\r\n for (let i = 0; i < T; i++) {\r\n const n = readline();\r\n const str = readline();\r\n let timur = \"Timur\".split(\"\").sort().join(\"\");\r\n const strSorted = str.split(\"\").sort().join(\"\");\r\n console.log(timur === strSorted ? 'Yes' : 'No');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numberOfTest = Number.parseInt(readline());\n for(let i=0; i {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n var s = readline();\r\n if (n === 5 && s.includes('T') && s.includes('i') && s.includes('m') && s.includes('u') && s.includes('r')) {\r\n console.log(\"YES\");\r\n \r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n // str = 'Timur'\n return str.split('')\n .sort((a, b) => a < b ? -1 : (a > b ? 1 : 0))\n .join('') === 'Timru' ? 'YES' : 'NO'\n}\n"}, {"source_code": "let fs = require(\"fs\");\r\nlet sc = {\r\n _buf: new Buffer.alloc(1 << 14),\r\n _bufPos: 0,\r\n _bufLen: 0,\r\n _ensure: function ()\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n this._bufPos = 0;\r\n this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);\r\n }\r\n },\r\n _isws: function (ch)\r\n {\r\n return ch === 32 || ch === 9 || ch === 10 || ch === 13;\r\n },\r\n _islf: function (ch)\r\n {\r\n return ch === 10 || ch === 13;\r\n },\r\n _peekChar: function ()\r\n {\r\n this._ensure();\r\n return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];\r\n },\r\n _skipWs: function ()\r\n {\r\n while (this._isws(this._peekChar()))\r\n this._bufPos++;\r\n },\r\n _readUntil: function (stop)\r\n {\r\n this._ensure();\r\n if (this._bufPos === this._bufLen)\r\n throw new Error(\"eof\");\r\n let start = this._bufPos;\r\n let before = null;\r\n for (; ;)\r\n {\r\n if (this._bufPos === this._bufLen)\r\n {\r\n let len = this._bufPos - start, preLen = (before ? before.length : 0);\r\n let nbuf = new Buffer(len + preLen);\r\n if (before)\r\n before.copy(nbuf);\r\n before = nbuf;\r\n this._buf.copy(before, preLen, start);\r\n this._ensure();\r\n start = this._bufPos;\r\n }\r\n if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;\r\n this._bufPos++;\r\n }\r\n if (!before)\r\n return this._buf.toString(\"utf8\", start, this._bufPos);\r\n let after = this._buf.slice(start, this._bufPos);\r\n let res = new Buffer(before.length + after.length);\r\n before.copy(res);\r\n after.copy(res, before.length);\r\n return res.toString();\r\n },\r\n\r\n nextToken: function ()\r\n {\r\n this._skipWs();\r\n return this._readUntil(this._isws);\r\n },\r\n L: function ()\r\n {\r\n let line = this._readUntil(this._islf);\r\n if (this._peekChar() === 13) this._bufPos++;\r\n if (this._peekChar() === 10) this._bufPos++;\r\n return line;\r\n },\r\n N: function ()\r\n {\r\n return +this.nextToken();\r\n },\r\n S: function ()\r\n {\r\n return this.nextToken();\r\n }\r\n};\r\n\r\n// DO NOT CHANGE TEMPLATE BEFORE\r\n\r\nconst Def = Number(1e9);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst LowerBound = (arr, val) =>\r\n{\r\n let ng = -1;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] >= val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\nconst ReverseLowerBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] <= val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d val\r\n return ng;\r\n}\r\n\r\n\r\nconst ReverseUpperBound = (arr, val) =>\r\n{\r\n let ng = 0;\r\n let ok = arr.length;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] < val)\r\n {\r\n ng = med;\r\n }\r\n else\r\n {\r\n ok = med;\r\n }\r\n }\r\n // \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 val\r\n return ng;\r\n}\r\n\r\nconst UpperBound = (arr, val) =>\r\n{\r\n let ok = arr.length;\r\n let ng = -1;\r\n while (ok - ng > 1)\r\n {\r\n let med = (ok + ng) / 2 | 0;\r\n if (arr[med] > val)\r\n {\r\n ok = med;\r\n }\r\n else\r\n {\r\n ng = med;\r\n }\r\n }\r\n\r\n return ok;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nconst Solve = () =>\r\n{\r\n let n = sc.N();\r\n let s = sc.S();\r\n\r\n if (n !== 5)\r\n {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n\r\n let arr = ['T', 'i', 'm', 'r', 'u'];\r\n let r = [...s];\r\n r.sort();\r\n\r\n let e = true;\r\n for (let i = 0; i < 5; ++i)\r\n {\r\n if (arr[i] !== r[i])\r\n {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n }\r\n\r\n console.log(\"YES\");\r\n\r\n\r\n\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\nconst main = () =>\r\n{\r\n let cases = +sc.L();\r\n while (cases-- > 0) Solve();\r\n\r\n // Solve();\r\n}\r\nmain();\r\n\r\n"}], "negative_code": [{"source_code": "n=+readline();\r\nwhile(n--){\r\n l=+readline();\r\n t=readline();\r\n if(l === 5){\r\n p = t.match(/(Timur|miurT|Trumi|mriTu)/g);\r\n print(p !== null ? \"Yes\" : \"No\")\r\n }else{\r\n print(\"NO\")\r\n }\r\n}"}, {"source_code": "n=+readline();\r\n\r\nfor(i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0\n for(j = 1; j <= n *2; j++){\n if(j % 2 == 1){\n e = lines[j], t = false, I = false, m = false, u = false, r = false\n }else{\n if(e == 5){\n for(l = 0; l < e; l++){\n var k = lines[j].split('')\n if(k[l] == 'T' && t === false){\n t = true\n }else if(k[l] == 'i' &&I === false){\n i = true\n }else if(k[l] == 'm' && m === false){\n m = true\n }else if(k[l] == 'u' && u === false){\n u = true\n }else if(k[l] == 'r' && r === false){\n r = true\n }\n }\n }\n if(t === true && I === true && m === true && u === true && r === true ){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n \n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0],e=0\n for(j = 1; j <= n; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n if(e == 5){\n for(l = 0; l < e; l++){\n var k = lines[j].split(''), t = false, I = false, m = false, u = false, r = false\n if(k[l] == 'T' && t === false){\n t = true\n }else if(k[l] == 'i' &&I === false){\n i = true\n }else if(k[l] == 'm' && m === false){\n m = true\n }else if(k[l] == 'u' && u === false){\n u = true\n }else if(k[l] == 'r' && r === false){\n r = true\n }\n }\n }\n if(t === true && I === true && m === true && u === true && r === true ){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n \n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n\r\n for (let i = 0; i < n; i++) {\r\n const sz = parseInt(readline());\r\n\r\n if (sz != 5) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n\r\n let str = readline();\r\n console.log([...str].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('') == \"Timru\" ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet standardInputString = ''\r\nlet currentLine = 0 \r\n\r\nfunction readLine(){\r\n return standardInputString[currentLine++]\r\n}\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData\r\n})\r\n\r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString.trim().split('\\n').map(line => {\r\n return line.trim()\r\n })\r\n\r\n main()\r\n})\r\n\r\n\r\n\r\n// ......................................................... //\r\n\r\n\r\nconst main=()=>{\r\n const testCase =parseInt(readLine());\r\n \r\n for (let index = 1; index <= testCase; index++) {\r\n const length =parseInt(readLine());\r\n const string = readLine();\r\n console.log(spellCheck(length, string));\r\n \r\n }\r\n}\r\n\r\nconst spellCheck = (length, string) => {\r\n const name = 'Tumir';\r\n if (name.length != string.length)\r\n return 'NO';\r\n let count = 0;\r\n for (let index = 0; index < name.length; index++) {\r\n for (let j = 0; j < string.length; j++) {\r\n if (name[index] === string[j]) {\r\n count++;\r\n }\r\n\r\n }\r\n\r\n }\r\n if (count === name.length) {\r\n return 'YES'\r\n }\r\n else\r\n return 'NO'\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\r\nconst { start } = require(\"repl\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] * 2 + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n let name = {\r\n T: true,\r\n i: true,\r\n m: true,\r\n u: true,\r\n r: true,\r\n };\r\n\r\n for (let i = 1; i < input.length; i += 2) {\r\n if (+input[i] !== 5) {\r\n console.log(\"NO\");\r\n continue;\r\n } else {\r\n let count = 0;\r\n for (let j = 0; j < input[i + 1].length; j++) {\r\n if (name[input[i + 1][j]]) {\r\n count++;\r\n }\r\n }\r\n if (count === 5) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n }\r\n};\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar list = [\"Timur\", \"miurT\", \"Trumi\", \"mriTu\"];\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tif(list.indexOf(s) > -1){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "6c137a74b36dede61037cb3b05167329"} {"source_code": "function solveAll(inputs) {\r\n inputs.forEach(input => {\r\n let lastLet = input;\r\n let valid = true;\r\n while (valid) { \r\n let pref = lastLet[0]\r\n valid = lastLet.slice(1, lastLet.length).includes(pref)\r\n if (valid) lastLet = lastLet.slice(1, lastLet.length);\r\n }\r\n console.log(lastLet)\r\n });\r\n}\r\n\r\nconst rl = require('readline').createInterface(process.stdin, process.stdout);\r\nlet testCase = 0; const inputs = []\r\nrl.on('line', (data) => {\r\n if (testCase === 0) testCase = parseInt(data)\r\n else {\r\n inputs.push(data)\r\n if (inputs.length === testCase) { solveAll(inputs); rl.close() };\r\n }\r\n})\r\n", "positive_code": [{"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var a = readline();\r\n \r\n var f = 0;\r\n var s = 0;\r\n for (var j = 0; j < a.length; j++) {\r\n for (var k = j + 1; k < a.length; k++) {\r\n if (a[j] === a[k]) {\r\n s = j + 1;\r\n break;\r\n }\r\n \r\n if(k === a.length - 1 && a[j] !== a[k]) {\r\n f = 1;\r\n break;\r\n }\r\n }\r\n \r\n if (f === 1) {\r\n break;\r\n }\r\n }\r\n print(a.substring(s));\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n let arr = s.split('');\r\n\r\n if (s.length === 1) {\r\n output(s);\r\n continue;\r\n }\r\n\r\n let freq = {};\r\n for (let i = 0; i < arr.length; i++) {\r\n if (freq[arr[i]]) {\r\n freq[arr[i]]++;\r\n } else {\r\n freq[arr[i]] = 1;\r\n }\r\n }\r\n\r\n let count = Object.keys(freq).length;\r\n\r\n let freq2 = {};\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n if (!freq2[s[i]]) {\r\n freq2[s[i]] = true;\r\n }\r\n\r\n if (Object.keys(freq2).length === count) {\r\n output(s.slice(i));\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n const map = new Map();\r\n for (let char of s) {\r\n var _map$get;\r\n map.set(char, ((_map$get = map.get(char)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n for (let [i, char] of [...s].entries()) {\r\n if (map.get(char) > 1) {\r\n map.set(char, map.get(char) - 1);\r\n } else {\r\n return s.slice(i);\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const s = await read();\r\n res.push(solve(s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nlet calc = (s)=>{\n let map = new Map();\n for (let i=0; i cxcode\n// xcode\n \nfunction main() {\n let T = +readline();\n while (T--){\n let s = readline();\n print(calc(s));\n }\n}"}, {"source_code": "function solve() {\r\n const str = read();\r\n const charSet = new Set();\r\n for (let i = 0; i < str.length; i++) {\r\n charSet.add(str[i]);\r\n }\r\n const currentSet = new Set();\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n currentSet.add(str[i]);\r\n if (currentSet.size === charSet.size) {\r\n write(str.substring(i));\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = nextCharArray();\r\n\t\tvar map = getCountMap(S);\r\n\t\tvar output = [];\r\n\t\tvar N = S.length;\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(map[S[i]] > 1 && !ok){\r\n\t\t\t\tmap[S[i]]--;\r\n\t\t\t}else{\r\n\t\t\t\toutput.push(S[i]);\r\n\t\t\t\tok = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 0));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n var arr = Array.from(n);\r\n var res = arr.reverse().filter((el, i) => arr.indexOf(el) === i);\r\n print(res.reverse().join(''));\r\n}\r\n"}, {"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var n = a[0];\r\n var B = a[1], x = a[2], y = a[3];\r\n var sum = 0;\r\n var ans = 0;\r\n \r\n while(n > 0) {\r\n sum += sum + x <= B ? x : -y;\r\n ans += sum;\r\n n--;\r\n }\r\n print(ans);\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n let freq = {};\r\n let i = s.length - 1;\r\n for (; i >= 0; i--) {\r\n if (!freq[s[i]]) {\r\n freq[s[i]] = 1;\r\n } else break;\r\n }\r\n output(s.slice(i));\r\n }\r\n}\r\n"}], "src_uid": "adbaa266446e6d8d95a6cbc0b83cc7c7"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // input in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tlet n= nextInt();\r\n let a= nextIntArray(n);\r\n let stop = false;\r\n for(let i=n-1;i>=0;i-=2){\r\n if(i+1a[i+1]) {\r\n myout(\"NO\"); \r\n stop = true;\r\n break;\r\n }\r\n if(i+2a[i+2]) {\r\n myout(\"NO\"); \r\n stop = true;\r\n break;\r\n }\r\n if(i-1>=0 && i+1a[i+1]) {\r\n myout(\"NO\"); \r\n stop = true;\r\n break;\r\n }\r\n if(i-1>=0 && i+2a[i+2]) {\r\n myout(\"NO\"); \r\n stop = true;\r\n break;\r\n }\r\n }\r\n if (stop) continue;\r\n myout(\"YES\")\r\n\t}\r\n}", "positive_code": [{"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var a;\r\n\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var prevMax = 0;\r\n var start = 0;\r\n var ans = 'YES';\r\n if (a.length & 1) {\r\n start = 1;\r\n prevMax = a[0];\r\n }\r\n for (var i = start; i < n; i+=2) {\r\n if (a[i] < prevMax || a[i+1] < prevMax) {\r\n ans = 'NO';\r\n break;\r\n }\r\n prevMax = Math.max(a[i], a[i+1]);\r\n }\r\n print(ans);\r\n }"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, a)=>{\n if (n < 3) return 'YES';\n \n if (n % 2 === 1) {\n a.unshift(0);\n n++;\n }\n\n for (let i = 0; i < n; i += 2) {\n let max = Math.max(a[i], a[i + 1]);\n let min = Math.min(a[i], a[i + 1]);\n a[i] = min;\n a[i + 1] = max;\n }\n\n for (let i = 1; i < n; i++) {\n if (a[i] < a[i - 1]) return 'NO';\n }\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (n === 1) {\r\n console.log(\"YES\");\r\n continue;\r\n }\r\n let narr = [],\r\n i = 0;\r\n if (n % 2) narr.push(arr[i++]);\r\n while (i + 1 < n) {\r\n if (arr[i] > arr[i + 1]) {\r\n narr.push(arr[i + 1]);\r\n narr.push(arr[i]);\r\n } else {\r\n narr.push(arr[i]);\r\n narr.push(arr[i + 1]);\r\n }\r\n i = i + 2;\r\n }\r\n let ans = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (narr[i] > narr[i + 1]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n for (let i = n - 1; i > 0; i -= 2) {\r\n if (a[i] < a[i - 1]) {\r\n [a[i], a[i - 1]] = [a[i - 1], a[i]];\r\n }\r\n }\r\n for (let i = 0; i + 1 < n; i++) {\r\n if (a[i] > a[i + 1]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n printf(\"%s\\n\", (solve() ? \"YES\" : \"NO\"));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, nums) {\r\n const res = [];\r\n let start = 0;\r\n if (n & 1) {\r\n res.push(nums[0]);\r\n start = 1;\r\n }\r\n for (let i = start; i < n; i += 2) {\r\n var _res;\r\n let a = nums[i],\r\n b = nums[i + 1];\r\n if (a > b) [a, b] = [b, a];\r\n if (a < ((_res = res[i - 1]) !== null && _res !== void 0 ? _res : -Infinity)) {\r\n console.log('NO');\r\n return;\r\n }\r\n res.push(a, b);\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (n, A)=>{\n let Bl = [];\n let Bm = 0;\n let Br = [];\n for (let i=n-1; i>=0; i--){\n let a = A[i];\n let canChoose = (n-i)%2==0;\n if (!canChoose){\n // push prev Bm?\n Bm = a;\n } else {\n if (BmBr.length) {\n C.push(Bl.pop())\n } else {\n let lBl = Bl[Bl.length-1]\n let lBr = Br[Br.length-1]\n if (lBlC[i+1])\n return false;\n }\n return true;\n let ans = 0;\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = ra();\n L('Ans:');\n print(calc(n, A) ? 'YES' : 'NO');\n }\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n for (let i = arr.length - 1; i >= 0; i -= 2) {\n if (i && arr[i] < arr[i - 1]) {\n [arr[i], arr[i - 1]] = [arr[i - 1], arr[i]]\n }\n }\n // console.log(arr)\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) return false\n }\n return true\n}\n"}], "negative_code": [{"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var a;\r\n\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var prevMax = 0;\r\n var start = 0;\r\n var ans = 'YES';\r\n if (a.length & 1) {\r\n start = 1;\r\n prevMax = a[1];\r\n }\r\n for (var i = start; i < n; i+=2) {\r\n if (a[i] < prevMax || a[i+1] < prevMax) {\r\n ans = 'NO';\r\n break;\r\n }\r\n prevMax = Math.max(a[i], a[i+1]);\r\n }\r\n print(ans);\r\n }"}, {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n var a;\r\n\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var prevMax = 0;\r\n var ans = 'YES';\r\n for (var i = 0; i < n; i+=2) {\r\n if (i == n-1) {\r\n if (a[i] < a[i-1] && a[i] < a[i-2]) {\r\n ans = 'NO';\r\n break;\r\n }\r\n } else {\r\n if (a[i] < prevMax || a[i+1] < prevMax) {\r\n ans = 'NO';\r\n break;\r\n }\r\n prevMax = Math.max(a[i], a[i+1]);\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": " var tests = parseInt(readline());\r\n var n;\r\n var arr;\r\n\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n arr = readline().split(' ').map(x=>parseInt(x));\r\n var prevMax = 0;\r\n var ans = 'YES';\r\n for (var i = 0; i < n; i+=2) {\r\n var max = arr[i];\r\n if (prevMax > max) {\r\n ans = 'NO';\r\n break;\r\n }\r\n if (i != n-1) {\r\n max = Math.max(arr[i], arr[i+1]);\r\n if (arr[i+1] < prevMax) {\r\n ans = 'NO';\r\n break;\r\n }\r\n }\r\n\r\n prevMax = max;\r\n }\r\n print(ans);\r\n }"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, a)=>{\n if (n < 3) return 'YES';\n \n if (n % 2 === 1) {\n a.unshift(0);\n n++;\n }\n\n for (let i = n - 2; i > 0; i -= 2) {\n let maxr = Math.max(a[i], a[i + 1]);\n let maxl = Math.max(a[i - 1], a[i - 2]);\n if (maxl > maxr) return 'NO';\n }\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, a)=>{\n if (n < 3) return 'YES';\n \n if (n % 2 === 1) {\n a.unshift(0);\n n++;\n }\n\n // console.log(`DEBUG a`, a);\n\n for (let i = n - 2; i > 0; i--) {\n let maxr = Math.max(a[i], a[i + 1]);\n let maxl = Math.max(a[i - 1], a[i - 2]);\n // console.log(`DEBUG i ${i} maxl ${maxl} maxr ${maxr}`);\n if (maxl > maxr) return 'NO';\n }\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "95b35c53028ed0565684713a93910860"} {"source_code": "function solve() {\r\n var str = read();\r\n var str1 = str + 'a';\r\n var str2 = str1.split('').reverse().join('');\r\n var str3 = 'a' + str;\r\n var str4 = str3.split('').reverse().join('');\r\n if (str1 !== str2) {\r\n write('YES');\r\n write(str1);\r\n return;\r\n }\r\n if (str3 !== str4) {\r\n write('YES');\r\n write(str3);\r\n return;\r\n }\r\n write('no');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n fs.readFile(inTextName ? path.join(__dirname, inTextName) : 0, 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n", "positive_code": [{"source_code": "function solve() {\r\n var str = read();\r\n var str1 = str + 'a';\r\n var str2 = str1.split('').reverse().join('');\r\n var str3 = 'a' + str;\r\n var str4 = str3.split('').reverse().join('');\r\n if (str1 !== str2) {\r\n write('YES');\r\n write(str1);\r\n return;\r\n }\r\n if (str3 !== str4) {\r\n write('YES');\r\n write(str3);\r\n return;\r\n }\r\n write('no');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve(str) {\r\n let a = 'a' + str\r\n let b = str + 'a'\r\n if (a === a.split('').reverse().join('')) {\r\n if (b === b.split('').reverse().join('')) {\r\n console.log('NO')\r\n } else {\r\n console.log('YES')\r\n console.log(b)\r\n }\r\n } else {\r\n console.log('YES')\r\n console.log(a)\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n // var [n, p, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n var allA = true\r\n for (let j = 0; j < a.length; j++) {\r\n if (a[j] !== 'a') allA = false\r\n }\r\n if (allA) return console.log('NO')\r\n\r\n var ans = []\r\n var once = true\r\n for (let j = 0; j < a.length; j++) {\r\n if (a[a.length - j - 1] !== 'a' && once) {\r\n ans.push('a')\r\n once = false\r\n }\r\n ans.push(a[j])\r\n }\r\n console.log('YES')\r\n console.log(ans.join(''))\r\n // console.log(a)\r\n })\r\n}\r\n"}, {"source_code": "\r\nlet input = '';\r\n\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const lines = input.trim().split('\\n').slice(1);\r\n \r\n for (let i=0; i {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n///////////////////////// END BASIC IO STREAM TEMPLATE //////////////////////\r\n\r\nfunction insert(main_string, ins_string, pos) {\r\n if (typeof pos == \"undefined\") {\r\n pos = 0;\r\n }\r\n if (typeof ins_string == \"undefined\") {\r\n ins_string = \"\";\r\n }\r\n return main_string.slice(0, pos) + ins_string + main_string.slice(pos);\r\n}\r\n\r\nfunction reverseString(str) {\r\n // return a new array of strings\r\n const arrayStrings = str.split(\"\");\r\n\r\n // reverse the new created array elements\r\n const reverseArray = arrayStrings.reverse();\r\n\r\n // join all elements of the array into a string\r\n const joinArray = reverseArray.join(\"\");\r\n\r\n // return the reversed string\r\n return joinArray;\r\n}\r\n\r\n// Additional Functions ////////\r\nfunction main() {\r\n let testCase = +readLine();\r\n const LETTER = \"a\";\r\n while (testCase--) {\r\n let f = 0;\r\n const word = readLine();\r\n let n = word.length + 1;\r\n let m = n - 1;\r\n let newWord = word.split(\"\").filter((x) => {\r\n if (x !== \"a\") return x;\r\n });\r\n if (newWord.length === 0) {\r\n console.log(\"NO\");\r\n } else {\r\n for (let i = 0; i < n / 2; i++) {\r\n let word1 = word.slice();\r\n let word2 = word.slice();\r\n const newWord1 = insert(word1, \"a\", i);\r\n const newWord2 = insert(word2, \"a\", m);\r\n const revWord1 = reverseString(newWord1);\r\n const revWord2 = reverseString(newWord2);\r\n if (revWord1 !== newWord1) {\r\n console.log(\"YES\");\r\n console.log(newWord1);\r\n f = 1;\r\n break;\r\n } else if (revWord2 !== newWord2) {\r\n console.log(\"YES\");\r\n console.log(newWord2);\r\n f = 1;\r\n break;\r\n }\r\n m--;\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = next();\r\n\t\tvar isOK = false;\r\n\t\tfor(var j = 0; j < s.length; j++){\r\n\t\t\tif(s[j] != \"a\"){\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tvar s1 = s + \"a\";\r\n\t\t\tvar isOK2 = false;\r\n\t\t\tfor(var j = 0; j < s1.length; j++){\r\n\t\t\t\tif(s1[j] != s1[s1.length - 1 - j]){\r\n\t\t\t\t\tisOK2 = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(isOK2){\r\n\t\t\t\tmyout(s + \"a\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"a\" + s);\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "function solve() {\r\n var str = read();\r\n var str1 = str + 'a';\r\n var str2 = str1.split('').reverse().join('');\r\n var str3 = 'a' + str;\r\n var str4 = str3.split('').reverse().join('');\r\n if (str1 !== str2) {\r\n write('YES');\r\n write(str1);\r\n return;\r\n }\r\n if (str3 !== str4) {\r\n write('YES');\r\n write(str3);\r\n return;\r\n }\r\n write('no');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function reverseString(str) {\r\n return str;\r\n}\r\n\r\n\r\n\r\nvar t=readline();\r\nwhile(t--)\r\n{\r\n\tvar s=readline();\r\n\tvar c=0;\r\n\tfor(i=0;i {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let s = rl();\r\n\r\n if (!palindrome(s + \"a\")) {\r\n cl(\"Yes\");\r\n cl(s + \"a\");\r\n } else if (!palindrome(\"a\" + s)) {\r\n cl(\"Yes\");\r\n cl(\"a\" + s);\r\n } else {\r\n cl(\"NO\");\r\n }\r\n }\r\n function palindrome(_str) {\r\n return _str == _str.split(\"\").reverse().join(\"\");\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let str = rl();\r\n\r\n if (checkPalindrome(\"a\" + str) && checkPalindrome(str + \"a\")) {\r\n cl(\"NO\");\r\n } else {\r\n cl(\"YES\");\r\n cl(str.split(\"\").reverse().join(\"\") + \"a\");\r\n }\r\n }\r\n function checkPalindrome(_str) {\r\n return _str == _str.split(\"\").reverse().join(\"\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let str = rl();\r\n\r\n if (checkPalindrome(\"a\" + str) && checkPalindrome(str + \"a\")) {\r\n cl(\"NO\");\r\n } else {\r\n cl(\"YES\");\r\n cl(str + \"a\");\r\n }\r\n }\r\n function checkPalindrome(_str) {\r\n return _str == _str.split(\"\").reverse().join(\"\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let str = rl().split(\"\");\r\n let flags = false;\r\n let temp = \"\";\r\n\r\n for (let i = 0; i < str.length; i++) {\r\n // cl(str.join(\"\"));\r\n str.splice(i, 0, \"a\");\r\n if (!checkPalindrome(str)) {\r\n flags = true;\r\n temp = [...str];\r\n break;\r\n }\r\n str.reverse().splice(i, 1);\r\n }\r\n if (!flags) {\r\n cl(\"NO\");\r\n } else {\r\n cl(\"YES\");\r\n cl(temp.reverse().join(\"\"));\r\n }\r\n }\r\n function checkPalindrome(_str) {\r\n for (let i = 0; i < _str.length; i++) {\r\n if (_str[i] != _str[_str.length - i - 1]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n // return _str.join(\"\") == _str.reverse().join(\"\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let str = rl().split(\"\");\r\n let flags = false;\r\n let temp = \"\";\r\n\r\n for (let i = 0; i < str.length; i++) {\r\n // cl(str.join(\"\"));\r\n str.splice(i, 0, \"a\");\r\n if (!checkPalindrome(str)) {\r\n flags = true;\r\n temp = [...str];\r\n }\r\n str.reverse().splice(i, 1);\r\n }\r\n if (!flags) {\r\n cl(\"NO\");\r\n } else {\r\n cl(\"YES\");\r\n cl(temp.join(\"\"));\r\n }\r\n\r\n // cl(checkPalindrome(str));\r\n }\r\n function checkPalindrome(_str) {\r\n return _str.join(\"\") == _str.reverse().join(\"\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let str = rl().split(\"\");\r\n const loop = str.length;\r\n let flags = false;\r\n\r\n for (let i = 0; i < loop; i++) {\r\n str.splice(i, 0, \"a\");\r\n if (!checkPalindrome(str)) {\r\n flags = true;\r\n }\r\n str.reverse(\"\").splice(i, 1);\r\n // cl(str.join(\"\"));\r\n }\r\n if (!flags) {\r\n cl(\"No\");\r\n } else {\r\n cl(\"Yes\");\r\n str.unshift(\"a\");\r\n cl(str.join(\"\"));\r\n }\r\n\r\n // cl(checkPalindrome(str));\r\n }\r\n function checkPalindrome(_str) {\r\n return _str.join(\"\") == _str.reverse().join(\"\");\r\n }\r\n}\r\n"}, {"source_code": "function solve() {\r\n var str = read();\r\n var str1 = str + 'a';\r\n var str2 = str1.split('').reverse().join('');\r\n var str3 = 'a' + str;\r\n var str4 = str3.split('').reverse().join('');\r\n if (str1 !== str2) {\r\n write('YES');\r\n write(str1);\r\n return;\r\n }\r\n if (str3 !== str4) {\r\n write('YES');\r\n write(str3);\r\n return;\r\n }\r\n write('no');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "function solve() {\r\n var str = read();\r\n var str1 = str + 'a';\r\n var str2 = str1.split('').reverse().join('');\r\n var str3 = 'a' + str;\r\n var str4 = str3.split('').reverse().join('');\r\n if (str1 !== str2) {\r\n write('YES');\r\n write(str1);\r\n return;\r\n }\r\n if (str3 !== str4) {\r\n write('YES');\r\n write(str3);\r\n return;\r\n }\r\n write('no');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n \r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n });\r\n } else {\r\n var readable = process.stdin;\r\n readable.once('readable', function() {\r\n MEMORY = ('' + readable.read()).split('\\r\\n');\r\n init();\r\n });\r\n }\r\n} else {\r\n init();\r\n}\r\n \r\nfunction write(value) {\r\n isNode ? console.log(value) : print(value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n // var [n, p, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n if (a.length ===1 )return console.log('NO')\r\n var ans= []\r\n var once= true\r\n for (let j = 0; j < a.length; j++) {\r\n if(a[a.length-j-1] !== 'a' && once) {\r\n ans.push('a')\r\n once = false\r\n }\r\n ans.push(a[j])\r\n }\r\n console.log('YES')\r\n console.log(ans.join(''))\r\n // console.log(a)\r\n })\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n // var [n, p, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n if (a.length ===1 )return console.log('NO')\r\n if(a[0] === 'a') a.push('s')\r\n else a.push('a')\r\n console.log('YES')\r\n console.log(a.join(''))\r\n // console.log(a)\r\n })\r\n}\r\n"}, {"source_code": "\r\nlet input = '';\r\n\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const lines = input.trim().split('\\n').slice(1);\r\n \r\n for (let i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var b = a.slice()\r\n a = a.sort((a, b) => a - b)\r\n\r\n var l = -1\r\n var m\r\n var r = x //Number.max integer\r\n while (r > l + 1) {\r\n\r\n m = Math.floor((l + r) / 2)\r\n // console.log(l, r,m)\r\n\r\n if (find(a, m)) r = m\r\n else l = m\r\n }\r\n // console.log(a)\r\n // console.log(r)\r\n var res= []\r\n for (var i = 0; i < x; i++) {\r\n if(b[i] >=a[r]) res.push(i+1)\r\n }\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n // var res = []\r\n // for (var i = 0; i < x; i++) {\r\n // if (i === 0) {\r\n // if (a[i] >= max) res.push(a[i])\r\n // continue\r\n // }\r\n // if (a[i] + sum[i - 1] >= max) res.push(a[i])\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\nfunction find(a, m) {\r\n var sum = 0\r\n for (var i = 0; i <= m; i++) {\r\n sum += a[i]\r\n }\r\n i = m + 1\r\n while (sum >= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = a.slice();\r\n\r\n\t\ta.sort((x, y) => x-y);\r\n\r\n\t\tlet mintokens = [];\r\n\t\tfor (let i = 0, pr = 0; i < n; i++) {\r\n\t\t\tpr += a[i];\r\n\t\t\tif (i == n-1 || pr >= a[i+1]) {\r\n\t\t\t\tmintokens.push(a[i]);\r\n\t\t\t} else {\r\n\t\t\t\tmintokens.length = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tmintokens = Math.min(...mintokens);\r\n\t\tconst ans = [];\r\n\t\tfor(let i = 0; i < n; i++) {\r\n\t\t\tif (b[i] >= mintokens)\r\n\t\t\t\tans.push(i+1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\ta[i] = [a[i], i+1];\r\n\t\t}\r\n\r\n\t\ta.sort((x, y) => x[0]-y[0]);\r\n\r\n\t\tconst pr = [0];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tpr[i+1] = pr[i] + a[i][0];\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (i == n-1 || pr[i+1] >= a[i+1][0]) {\r\n\t\t\t\tans.push(a[i][1]);\r\n\t\t\t} else {\r\n\t\t\t\tans.length = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans.sort((x, y) => x-y);\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n readline();\r\n let arr = readline().split(' ').map(i => +i);\r\n let map = {};\r\n let count = 0;\r\n arr.forEach(num => {\r\n if (!map[num]) map[num] = 0;\r\n map[num]++;\r\n })\r\n let values = Object.keys(map).map(item => +item);\r\n let min = 0\r\n let sum = 0;\r\n if (values.length > 1) {\r\n values.forEach((num, index) => {\r\n if (index === values.length - 1) return;\r\n let curr = map[num] * num;\r\n if (sum + curr < values[index + 1]) {\r\n min = num\r\n }\r\n sum += curr\r\n })\r\n }\r\n arr.forEach(num => count += num > min ? 1 : 0);\r\n console.log(count)\r\n console.log(arr.map((num, index) => num > min ? (index + 1) : 0).filter(item => item).join(' '))\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tvar v = nextInt();\r\n\t\t\tlist[j] = {\r\n\t\t\t\tno : j,\r\n\t\t\t\tv : v,\r\n\t\t\t\tsum : v\r\n\t\t\t};\r\n\t\t}\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a.v - b.v;\r\n\t\t});\r\n\t\tfor(var j = 1; j < N; j++){\r\n\t\t\tlist[j].sum += list[j - 1].sum;\r\n\t\t}\r\n\t\tfor(var j = N - 1; j >= 1; j--){\r\n\t\t\tif(list[j].v == list[j - 1].v){\r\n\t\t\t\tlist[j - 1].sum = list[j].sum;\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = [list[N - 1].no + 1];\r\n\t\tfor(var j = N - 2; j >= 0; j--){\r\n\t\t\tif(list[j].sum >= list[j + 1].v){\r\n\t\t\t\toutput.push(list[j].no + 1);\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t//myerr(list);\r\n\t\toutput.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tmyout(output.length);\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n \r\n var compare = function(a, b) {\r\n return parseInt(a) - parseInt(b);\r\n }\r\n \r\n sortedArr.sort(compare);\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n \r\n for(var i = n - 1; i >= 0; i--) {\r\n //write(\"Total - Prev - Curr: \" + total + \" - \" + previous + \" - \" + sortedArr[i] + \"\\n\");\r\n if(i == n - 1 || sortedArr[i] != previous) {\r\n if(sortedArr[i] > total - sortedArr[i]) {\r\n if(sortedArr[0] != sortedArr[i]) {\r\n previous = sortedArr[i];\r\n }\r\n break; \r\n } else {\r\n if(sortedArr[0] == sortedArr[i]) {\r\n if(total >= previous)\r\n previous = sortedArr[i];\r\n else\r\n break;\r\n }\r\n }\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n if(previous > total)\r\n break;\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n write(arrResult.length + \"\\n\");\r\n write(arrResult.sort(compare).join(\" \") + \"\\n\");\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var b = a.slice()\r\n a = a.sort((a, b) => a - b)\r\n\r\n var l = -1\r\n var m\r\n var r = x //Number.max integer\r\n while (r > l + 1) {\r\n\r\n m = Math.floor((l + r) / 2)\r\n // console.log(l, r,m)\r\n\r\n if (find(a, m)) r = m\r\n else l = m\r\n }\r\n // console.log(a)\r\n // console.log(r)\r\n var res= []\r\n for (var i = r; i < x; i++) {\r\n if(b[i] >=a[r]) res.push(i+1)\r\n }\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n // var res = []\r\n // for (var i = 0; i < x; i++) {\r\n // if (i === 0) {\r\n // if (a[i] >= max) res.push(a[i])\r\n // continue\r\n // }\r\n // if (a[i] + sum[i - 1] >= max) res.push(a[i])\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\nfunction find(a, m) {\r\n var sum = 0\r\n for (var i = 0; i <= m; i++) {\r\n sum += a[i]\r\n }\r\n i = m + 1\r\n while (sum >= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var b = a.slice()\r\n a = a.sort((a, b) => a - b)\r\n\r\n var l = -1\r\n var m\r\n var r = x //Number.max integer\r\n while (r > l + 1) {\r\n\r\n m = Math.floor((l + r) / 2)\r\n // console.log(l, r,m)\r\n\r\n if (find(a, m)) r = m\r\n else l = m\r\n }\r\n // console.log(a)\r\n // console.log(r)\r\n var res= []\r\n for (var i = r; i < x; i++) {\r\n res.push(a[i])\r\n }\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n // var res = []\r\n // for (var i = 0; i < x; i++) {\r\n // if (i === 0) {\r\n // if (a[i] >= max) res.push(a[i])\r\n // continue\r\n // }\r\n // if (a[i] + sum[i - 1] >= max) res.push(a[i])\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\nfunction find(a, m) {\r\n var sum = 0\r\n for (var i = 0; i <= m; i++) {\r\n sum += a[i]\r\n }\r\n i = m + 1\r\n while (sum >= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nvar height = []\r\n\r\nfunction main() {\r\n var xx = Number(readline())\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n\r\n var x = parseInt(readline())\r\n var a = readline().split(' ').map((x, i) => {\r\n return parseInt(x)\r\n })\r\n var b = a.slice()\r\n a = a.sort((a, b) => a - b)\r\n\r\n var l = -1\r\n var m\r\n var r = x //Number.max integer\r\n while (r > l + 1) {\r\n\r\n m = Math.floor((l + r) / 2)\r\n // console.log(l, r,m)\r\n\r\n if (find(a, m)) r = m\r\n else l = m\r\n }\r\n // console.log(a)\r\n // console.log(r)\r\n var res= []\r\n for (var i = 0; i < x; i++) {\r\n if(b[i] >=a[r]) res.push(b[i])\r\n }\r\n console.log(res.length)\r\n console.log(res.join(' '))\r\n // var res = []\r\n // for (var i = 0; i < x; i++) {\r\n // if (i === 0) {\r\n // if (a[i] >= max) res.push(a[i])\r\n // continue\r\n // }\r\n // if (a[i] + sum[i - 1] >= max) res.push(a[i])\r\n // }\r\n\r\n })\r\n\r\n}\r\n\r\nfunction find(a, m) {\r\n var sum = 0\r\n for (var i = 0; i <= m; i++) {\r\n sum += a[i]\r\n }\r\n i = m + 1\r\n while (sum >= a[i]) {\r\n sum += a[i]\r\n i++\r\n }\r\n if (i === a.length) return true\r\n return false\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n \r\n var compare = function(a, b) {\r\n return parseInt(a) - parseInt(b);\r\n }\r\n \r\n sortedArr.sort(compare);\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n \r\n for(var i = n - 1; i >= 0; i--) {\r\n //write(\"Total - Prev - Curr: \" + total + \" - \" + previous + \" - \" + sortedArr[i] + \"\\n\");\r\n if(i == n - 1 || sortedArr[i] != previous) {\r\n if(sortedArr[i] > total - sortedArr[i]) {\r\n if(sortedArr[0] != sortedArr[i]) {\r\n previous = sortedArr[i];\r\n }\r\n break; \r\n } else {\r\n if(sortedArr[0] == sortedArr[i]) {\r\n if(total >= previous)\r\n previous = sortedArr[i];\r\n else\r\n break;\r\n }\r\n }\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n if(previous > total)\r\n break;\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n write(arrResult.length + \"\\n\");\r\n write(arrResult.sort().join(\" \") + \"\\n\");\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n \r\n var compare = function(a, b) {\r\n return parseInt(a) - parseInt(b);\r\n }\r\n \r\n sortedArr.sort(compare);\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n for(var i = n - 1; i >= 0; i--) {\r\n if(i == n - 1 || sortedArr[i] != previous) {\r\n if(sortedArr[i] > total - sortedArr[i]) {\r\n if(sortedArr[0] != sortedArr[i]) {\r\n previous = sortedArr[i];\r\n }\r\n break; \r\n } else {\r\n if(sortedArr[0] == sortedArr[i]) {\r\n if(total >= previous)\r\n previous = sortedArr[i];\r\n else\r\n break;\r\n }\r\n }\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n write(arrResult.length + \"\\n\");\r\n write(arrResult.sort().join(\" \") + \"\\n\");\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n sortedArr.sort();\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n for(var i = n - 1; i >= 0; i--) {\r\n if(i == n - 1 || sortedArr[i] != previous) {\r\n if(sortedArr[i] > total - sortedArr[i]) {\r\n if(sortedArr[0] != sortedArr[i]) {\r\n previous = sortedArr[i];\r\n }\r\n break; \r\n } else {\r\n if(sortedArr[0] == sortedArr[i]) {\r\n if(total >= previous)\r\n previous = sortedArr[i];\r\n else\r\n break;\r\n }\r\n }\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n write(arrResult.length + \"\\n\");\r\n write(arrResult.sort().join(\" \") + \"\\n\");\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n sortedArr.sort();\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n for(var i = n - 1; i >= 0; i--) {\r\n if((i == n - 1 || sortedArr[i] != previous) && sortedArr[i] > total - sortedArr[i]) {\r\n previous = sortedArr[i];\r\n break;\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n write(arrResult.length + \"\\n\");\r\n write(arrResult.sort().join(\" \") + \"\\n\");\r\n}"}, {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\r\nwhile(true) {\r\n var read = readline();\r\n if(read == undefined) break;\r\n var n = read.split(\" \").map(function(x) { return parseInt(x); })[0];\r\n var arr = readline().split(\" \").map(function(x) { return parseInt(x); });\r\n var sortedArr = [...arr];\r\n sortedArr.sort();\r\n var result = [];\r\n var max = 0;\r\n var maxIdx = 0;\r\n var total = 0;\r\n \r\n for(var i = 0; i < n; i++) {\r\n total += sortedArr[i];\r\n }\r\n \r\n var previous = sortedArr[n - 1];\r\n for(var i = n - 1; i >= 0; i--) {\r\n if((i == n - 1 || sortedArr[i] != previous) && sortedArr[i] > total - sortedArr[i]) {\r\n previous = sortedArr[i];\r\n break;\r\n }\r\n previous = sortedArr[i];\r\n total -= sortedArr[i];\r\n }\r\n \r\n var arrResult = [];\r\n for(var i = 0; i < n; i++) {\r\n if(arr[i] >= previous) arrResult.push(i + 1);\r\n }\r\n \r\n write(arrResult.sort().join(\" \") + \"\\n\");\r\n}"}], "src_uid": "debce043777e7e575f77a94edf89c7f1"} {"source_code": "function bundle (x, y, x2, y2) {\n return (x + ',' + y + ',' + x2 + ',' + y2);\n}\nfunction solve() {\n var str = readline().split('');\n var s = new Set([]);\n var x = 0, y = 0;\n var ans = 0;\n str.forEach(a => {\n var nx = x, ny = y;\n switch(a) {\n case 'S':\n ny--; break;\n case 'N':\n ny++; break;\n case 'W':\n nx--; break;\n default:\n nx++;\n }\n // s.forEach(x => {print(x);})\n ans += (s.has(bundle(x, y, nx, ny)) ? 1 : 5);\n s.add(bundle(x, y, nx, ny));\n s.add(bundle(nx, ny, x, y));\n x = nx, y = ny;\n });\n print(ans);\n}\n\nvar n = parseInt(readline());\nfor (var i = 0; i < n; ++i) solve();\n\n", "positive_code": [{"source_code": "function getHaah(x, y) {\n return x*300000+y;\n}\n\nvar t = Number(readline());\nwhile(t--) {\n var v = readline();\n var se1 = new Set();\n var se2 = new Set();\n \n var curx = 100000, cury = 100000, ans = 0;\n for(var i in v) {\n var nx = curx, ny = cury;\n\n if(v[i] === \"N\") ny++;\n else if(v[i] === \"S\") ny--;\n else if(v[i] === 'E') nx++;\n else nx--;\n\n var h = getHaah(Math.min(curx, nx), Math.min(cury, ny));\n if(v[i] === \"N\" || v[i] === \"S\") {\n if(se1.has(h)) ans += 1;\n else ans += 5;\n\n se1.add(h);\n }\n else {\n if(se2.has(h)) ans += 1;\n else ans += 5;\n\n se2.add(h);\n }\n\n curx = nx, cury = ny;\n }\n\n print(ans);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r loop(line))\n"}], "negative_code": [{"source_code": "const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nconst rethreads = [\n /(W+)(E+)/g,\n /(E+)(W+)/g,\n /(N+)(S+)/g,\n /(S+)(N+)/g\n],\nmax = 10**5\n\nvar N = null\n\nfunction linear(xy) {\n return xy[0] + max*xy[1]\n}\n\nfunction move(xy,dir) {\n let sgn = -1\n switch(dir) {\n case \"E\":\n sgn = 1\n case \"W\":\n xy[0] += sgn\n break\n case \"N\":\n sgn = 1\n case \"S\":\n xy[1] += sgn\n break\n }\n return xy.join(\",\")\n}\n\nfunction loop(line) {\n\n if (N == null) return N = Number(line)\n /*\n let prevLen = -1\n while (prevLen != line.length) {\n for (let i=0; i<4; i++)\n line = line.replace(rethreads[i], (_,a,b)=>{\n const isA = a.length < b.length\n const len = isA ? a.length : b.length\n t += 6*len\n return (isA ? b.substr(len) : a.substr(len)) + (a.toLowerCase() + len)\n })\n }\n */\n let t = 0,\n coords = new Set([\"0,0\"]),\n currCord = [0,0],\n currXY = \"0,0\",\n nextXY = \"\"\n for (let i=0;i loop(line))\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 3\n1 3\n100000 100000\n2 2\n\n\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r a[i] && a[i] > a[i + 1]) {\n a[i] = -a[i];\n }\n }\n write(a.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const nums = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let i = 0;\n while (i < len) {\n if (i % 2 === 0) nums[i] = Math.abs(nums[i]);\n else nums[i] = -Math.abs(nums[i]);\n i++;\n }\n console.log(nums.join(\" \"));\n }\n}\n"}], "negative_code": [], "src_uid": "d07ae42b7902ba3a49cf4463248710ea"} {"source_code": "var t = parseInt(readline());\r\n\r\n while (t--) {\r\n var input1 = readline().split(\" \");\r\n var input2 = readline().split(\" \");\r\n\r\n var x1 = parseInt(input1[0]);\r\n var p1 = parseInt(input1[1]);\r\n\r\n var x2 = parseInt(input2[0]);\r\n var p2 = parseInt(input2[1]);\r\n\r\n var m = Math.min(p1, p2);\r\n p1 -= m;\r\n p2 -= m;\r\n if (p1 >= 7) {\r\n print(\">\");\r\n } else if (p2 >= 7) {\r\n print(\"<\");\r\n } else {\r\n for (var j = 0; j < p1; j++) {\r\n x1 *= 10;\r\n }\r\n for (var j = 0; j < p2; j++) {\r\n x2 *= 10;\r\n }\r\n if (x1 > x2) {\r\n print(\">\");\r\n } else if (x1 < x2) {\r\n print(\"<\");\r\n } else {\r\n print(\"=\");\r\n }\r\n }\r\n }", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\tconst mn = Math.min(p1, p2);\r\n\t\tp1 -= mn;\r\n\t\tp2 -= mn;\r\n\r\n\t\twhile (x1 <= 1e6 && p1) { x1 *= 10; p1--; }\r\n\t\twhile (x2 <= 1e6 && p2) { x2 *= 10; p2--; }\r\n\t\tlet ans = x1 - x2;\r\n\r\n\t\tif (ans < 0) console.log('<');\r\n\t\tif (ans == 0) console.log('=');\r\n\t\tif (ans > 0) console.log('>');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\twhile (x1 <= 1e6-1 && p1) { x1 *= 10; p1--; }\r\n\t\twhile (x2 <= 1e6-1 && p2) { x2 *= 10; p2--; }\r\n\t\tif (p1 > p2) x1 *= 10;\r\n\t\tif (p2 > p1) x2 *= 10;\r\n\t\tlet ans = x1 - x2;\r\n\r\n\t\tif (ans < 0) console.log('<');\r\n\t\tif (ans == 0) console.log('=');\r\n\t\tif (ans > 0) console.log('>');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tif (String(x1).length + p1 < String(x2).length + p2) \r\n\t\t\tans = -1;\r\n\t\telse if (String(x1).length + p1 > String(x2).length + p2) \r\n\t\t\tans = 1;\r\n\t\telse {\r\n\t\t\twhile (x1 <= 1e6-1) x1 *= 10;\r\n\t\t\twhile (x2 <= 1e6-1) x2 *= 10;\r\n\t\t\tans = x1 - x2;\r\n\t\t}\r\n\r\n\t\tif (ans < 0) console.log('<');\r\n\t\tif (ans == 0) console.log('=');\r\n\t\tif (ans > 0) console.log('>');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MX = 1e6 + 7;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\tlet ans = x1 * Math.pow(10, Math.min(Math.max(p1 - p2, 0), 7)) - \r\n\t \t\t x2 * Math.pow(10, Math.min(Math.max(p2 - p1, 0), 7));\r\n\r\n\t\tans = ans == 0 ? '=' : (ans > 0 ? '>' : '<'); \r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/1613/A\n */\n\nfunction nodeJSReader() {\n const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const input = [];\n return new Promise((resolve) => {\n readLine.on('close', () => resolve(input));\n readLine.on('line', (line) => input.push(line));\n });\n}\n\n/**\n * \n * @param {Array} data\n * @param {number} testCount\n * @param {number} linesPerCase \n * @returns {Array}\n */\nfunction* splitTestCase(data, testCount, linesPerCase) {\n for (let i = 0, ii = 0; i < testCount; i++, ii = i * linesPerCase) {\n yield data.slice(ii, ii + linesPerCase);\n }\n}\n\n/**\n * \n * @param {Array} arr \n * @returns {number}\n */\nfunction len(arr) {\n return arr[0].length + Number.parseInt(arr[1]) || 0;\n}\n\n/**\n * \n * @param {number} x1 \n * @param {number} x2 \n * @returns {string | undefined} \n */\nfunction compare(x1, x2) {\n if (x1 > x2) { return '>'; }\n if (x1 < x2) { return '<'; }\n\n return;\n}\n\n/**\n * \n * @param {Array} input1 \n * @param {Array} input2 \n */\nfunction run(input1, input2) {\n // Early escape\n if (input1 === input2) { return '='; }\n\n let result = compare(len(input1), len(input2));\n if (result) { return result; }\n\n // Inputs have the same length, normalize length of meaningful part and compare\n const normalizedLen = Math.max(input1[0].length, input2[0].length);\n result = compare(Number.parseInt(input1[0].padEnd(normalizedLen, 0)), Number.parseInt(input2[0].padEnd(normalizedLen, 0)));\n if (result) { return result; }\n\n return '=';\n}\n\nnodeJSReader().then(([\n testCount,\n ...data\n]\n) => {\n for (const testCase of splitTestCase(data, testCount, 2)) {\n console.log(run(testCase[0].split(' '), testCase[1].split(' ')));\n }\n});\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [x1, p1] = lines[l++].trim().split(' ')\n const [x2, p2] = lines[l++].trim().split(' ')\n output[i] = solve(x1, p1, x2, p2)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(x1, p1, x2, p2) {\n p1 = +p1\n p2 = +p2\n if (x1.length + p1 > x2.length + p2) return '>'\n if (x1.length + p1 < x2.length + p2) return '<'\n\n const min = Math.min(p1, p2)\n p1 -= min\n p2 -= min\n let i = 0\n let j = 0\n while (i < p1 + x1.length && j < p2 + x2.length) {\n const a = i < x1.length ? +x1[i] : 0\n const b = j < x2.length ? +x2[j] : 0\n // console.log('sb', a, b)\n if (a < b) return '<'\n if (a > b) return '>'\n i++\n j++\n }\n return '='\n}\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n\n for(let i = 0; i< fileContents.length-1; i+=2){\n const row1 = fileContents[i].split(\" \");\n const num1base = row1[0]/Math.pow(10,row1[0].length-1)\n const num1pow = row1[0].length-1+parseInt(row1[1])\n\n const row2 = fileContents[i+1].split(\" \");\n const num2base = row2[0]/Math.pow(10,row2[0].length-1)\n const num2pow = row2[0].length-1+parseInt(row2[1])\n\n // console.log(num1base,num1pow , num2base, num2pow)\n\n if(num1pow > num2pow){\n console.log(\">\")\n }else if(num1pow < num2pow){\n console.log(\"<\")\n }else{\n if(num1base > num2base){\n console.log(\">\")\n }else if(num1base < num2base){\n console.log(\"<\")\n }else{\n console.log(\"=\")\n }\n }\n }\n\n}\n\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n n1 = parseInt(n1);\r\n n2 = parseInt(n2);\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction compareCharNumbers(n1, n2) {\r\n n1 = String(n1);\r\n n2 = String(n2);\r\n for (var i = 0; i < n1.length; i++){\r\n var compareRes = compareNumbers(n1[i], n2[i]);\r\n if (compareRes !== '=') return compareRes;\r\n }\r\n\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = arr1[0] === '0' ? 0 : (arr1[0].length + parseInt(arr1[1]));\r\n var digs2 = arr2[0] === '0' ? 0 : (arr2[0].length + parseInt(arr2[1]));\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareCharNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n n1 = parseInt(n1);\r\n n2 = parseInt(n2);\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction compareCharNumbers(n1, n2) {\r\n n1 = String(n1);\r\n n2 = String(n2);\r\n for (var i = 0; i < n1.length; i++){\r\n var compareRes = compareNumbers(n1[i], n2[i]);\r\n if (compareRes !== '=') return compareRes;\r\n }\r\n\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n // if (zeroCount === 0 || zeroCount === '0') {\r\n // return parseInt(str);\r\n // }\r\n \r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = arr1[0] === '0' ? 0 : (arr1[0].length + parseInt(arr1[1]));\r\n var digs2 = arr2[0] === '0' ? 0 : (arr2[0].length + parseInt(arr2[1]));\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareCharNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile(t--) {\r\n var d1 = readline().split(' ');\r\n var d2 = readline().split(' ');\r\n var a = d1[0], b = d2[0];\r\n var ans = \"=\";\r\n \r\n var len1 = d1[0].length + Number(d1[1]);\r\n var len2 = d2[0].length + Number(d2[1]);\r\n \r\n if(len1 === len2) {\r\n a += \"0\".repeat(Math.max(0, b.length - a.length));\r\n b += \"0\".repeat(Math.max(0, a.length - b.length));\r\n ans = +a > +b ? \">\" : +a < +b ? \"<\" : \"=\";\r\n } else if (len1 > len2) {\r\n ans = \">\";\r\n } else {\r\n ans = \"<\";\r\n }\r\n \r\n print(ans);\r\n}"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\twhile (x1 <= 1e6-1 && p1) { x1 *= 10; p1--; }\r\n\t\twhile (x2 <= 1e6-1 && p2) { x2 *= 10; p2--; }\r\n\t\tlet ans = x1 - x2;\r\n\r\n\t\tif (ans < 0) console.log('<');\r\n\t\tif (ans == 0) console.log('=');\r\n\t\tif (ans > 0) console.log('>');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [x1, p1] = rna();\r\n\t\tlet [x2, p2] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tif (String(x1).length + p1 < String(x2).length + p2) \r\n\t\t\tans = -1;\r\n\t\telse if (String(x1).length + p1 > String(x2).length + p2) \r\n\t\t\tans = 1;\r\n\t\telse {\r\n\t\t\twhile (x1 <= 1e6) x1 *= 10;\r\n\t\t\twhile (x2 <= 1e6) x2 *= 10;\r\n\t\t\tans = x1 - x2;\r\n\t\t}\r\n\r\n\t\tif (ans < 0) console.log('<');\r\n\t\tif (ans == 0) console.log('=');\r\n\t\tif (ans > 0) console.log('>');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/1613/A\n */\n\nfunction nodeJSReader() {\n const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const input = [];\n return new Promise((resolve) => {\n readLine.on('close', () => resolve(input));\n readLine.on('line', (line) => input.push(line));\n });\n}\n\n/**\n * \n * @param {Array} data\n * @param {number} testCount\n * @param {number} linesPerCase \n * @returns {Array}\n */\nfunction* splitTestCase(data, testCount, linesPerCase) {\n for (let i = 0, ii = 0; i < testCount; i++, ii = i * linesPerCase) {\n yield data.slice(ii, ii + linesPerCase);\n }\n}\n\n/**\n * \n * @param {Array} arr \n * @returns {number}\n */\nfunction len(arr) {\n return arr[0].length + Number.parseInt(arr[1]) || 0;\n}\n\n/**\n * \n * @param {number} x1 \n * @param {number} x2 \n * @returns {string | undefined} \n */\nfunction compare(x1, x2) {\n console.log('>>>>', x1, x2);\n if (x1 > x2) { return '>'; }\n if (x1 < x2) { return '<'; }\n\n return;\n}\n\n/**\n * \n * @param {Array} input1 \n * @param {Array} input2 \n */\nfunction run(input1, input2) {\n // Early escape\n if (input1 === input2) { return '='; }\n\n let result = compare(len(input1), len(input2));\n if (result) { return result; }\n\n // Inputs have the same length, normalize length of meaningful part and compare\n const normalizedLen = Math.max(input1[0].length, input2[0].length);\n result = compare(Number.parseInt(input1[0].padEnd(normalizedLen, 0)), Number.parseInt(input2[0].padEnd(normalizedLen, 0)));\n if (result) { return result; }\n\n return '=';\n}\n\nnodeJSReader().then(([\n testCount,\n ...data\n]\n) => {\n for (const testCase of splitTestCase(data, testCount, 2)) {\n console.log(run(testCase[0].split(' '), testCase[1].split(' ')));\n }\n});\n\n"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/1613/A\n */\n\nfunction nodeJSReader() {\n const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const input = [];\n return new Promise((resolve) => {\n readLine.on('close', () => resolve(input));\n readLine.on('line', (line) => input.push(line));\n });\n}\n\n/**\n * \n * @param {Array} data\n * @param {number} testCount\n * @param {number} linesPerCase \n * @returns {Array}\n */\nfunction* splitTestCase(data, testCount, linesPerCase) {\n for (let i = 0, ii = 0; i < testCount; i++, ii = i * linesPerCase) {\n yield data.slice(ii, ii + linesPerCase);\n }\n}\n\n/**\n * \n * @param {Array} arr \n * @returns {number}\n */\nfunction len(arr) {\n return arr[0].length + Number.parseInt(arr[1]) || 0;\n}\n\n/**\n * \n * @param {number} x1 \n * @param {number} x2 \n * @returns {string | undefined} \n */\nfunction compare(x1, x2) {\n console.log('>>>>', x1, x2);\n if (x1 > x2) { return '>'; }\n if (x1 < x2) { return '<'; }\n\n return;\n}\n\n/**\n * \n * @param {Array} input1 \n * @param {Array} input2 \n */\nfunction run(input1, input2) {\n // Early escape\n if (input1 === input2) { return '='; }\n\n let result = compare(len(input1), len(input2));\n if (result) { return result; }\n\n // Inputs have the same length, normalize length of meaningful part and compare\n const normalizedLen = Math.max(input1[0].length, input2[0].length);\n result = compare(Number.parseInt(input1[0].padEnd(normalizedLen, 0)), Number.parseInt(input2[0].padEnd(normalizedLen, 0)));\n if (result) { return result; }\n\n return '=';\n}\n\nnodeJSReader().then(([\n testCount,\n ...data\n]\n) => {\n for (const testCase of splitTestCase(data, testCount, 2)) {\n console.log(testCase, run(testCase[0].split(' '), testCase[1].split(' ')));\n }\n});\n\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n if (zeroCount === 0 || zeroCount === '0') {\r\n return parseInt(str);\r\n }\r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = arr1[0] === '0' ? 0 : (arr1[0].length + parseInt(arr1[1]));\r\n var digs2 = arr2[0] === '0' ? 0 : (arr2[0].length + parseInt(arr2[1]));\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = arr1[0] === '0' ? 0 : (arr1[0].length + parseInt(arr1[1]));\r\n var digs2 = arr2[0] === '0' ? 0 : (arr2[0].length + parseInt(arr2[1]));\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = (arr1[0] === '0' ? 0 : arr1[0].length) + parseInt(arr1[1]);\r\n var digs2 = (arr2[0] === '0' ? 0 : arr2[0].length) + parseInt(arr2[1]);\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str + '';\r\n while (i > 0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var digs1 = arr1[0].length + parseInt(arr1[1]);\r\n var digs2 = arr2[0].length + parseInt(arr2[1]);\r\n \r\n if (digs1 === digs2) {\r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p_diff : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p_diff : 0);\r\n results.push(compareNumbers(n1, n2));\r\n } else results.push(compareNumbers(digs1, digs2));\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str;\r\n while (i>0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n \r\n var n1 = getNumber(arr1, arr2, p_diff);\r\n var n2 = getNumber(arr2, arr1, p_diff);\r\n results.push(compareNumbers(n1, n2))\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str;\r\n while (i>0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().trim().split(\" \");\r\n}\r\n\r\nfunction getNumber(arr1, arr2, p_diff) {\r\n return arr1[1] > arr2[1] ? addZeroesToNumber(arr1[0], p_diff) : parseInt(arr1[0]);\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var p_diff = Math.abs(arr1[1] - arr2[1]);\r\n \r\n var n1 = getNumber(arr1, arr2, p_diff);\r\n var n2 = getNumber(arr2, arr1, p_diff);\r\n print(n1, n2);\r\n results.push(compareNumbers(n1, n2))\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var pairsCount = parseInt(readline());\r\n\r\nvar results = [];\r\n\r\nfunction compareNumbers(n1, n2) {\r\n if (n1 < n2) return '<';\r\n if (n1 > n2) return '>';\r\n return '=';\r\n}\r\n\r\nfunction addZeroesToNumber(str, zeroCount) {\r\n var i = zeroCount;\r\n var res = str;\r\n while (i>0) {\r\n res += '0';\r\n i--;\r\n }\r\n return parseInt(res);\r\n}\r\n\r\nfunction getReadLineArray() {\r\n return readline().toString().split(\" \");\r\n}\r\n\r\nvar i = 0;\r\nwhile (i < pairsCount) {\r\n var arr1 = getReadLineArray();\r\n var arr2 = getReadLineArray();\r\n \r\n var p2 = Math.abs(arr1[1] - arr2[1]);\r\n \r\n var n1 = addZeroesToNumber(arr1[0], arr1[1] > arr2[1] ? p2 : 0);\r\n var n2 = addZeroesToNumber(arr2[0], arr2[1] > arr1[1] ? p2 : 0);\r\n results.push(compareNumbers(n1, n2))\r\n i++;\r\n}\r\n\r\nfor (var j = 0; j < results.length; j++) {\r\n print(results[j]);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile(t--) {\r\n var description1 = readline().split(' ').map(Number);\r\n var description2 = readline().split(' ').map(Number);\r\n \r\n var firstNumber = description1[0] * (Math.pow(10, description1[1]));\r\n var secondNumber = description2[0] * (Math.pow(10, description2[1]));\r\n \r\n print(firstNumber === secondNumber ? '=' : firstNumber > secondNumber ? '>' : '<');\r\n}"}], "src_uid": "a4eeaf7252b9115b67b9eca5f2bf621d"} {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n \n if(Math.max(...arr.map(item => item.length)) > 10) {\n var res = parseInt(arr.map(item => +item.slice(0, -7) / 2).reduce((prev, curr) => prev + curr));\n var lres = parseInt(arr.map(item => +item.slice(-13) / 2).reduce((prev, curr) => prev + curr));\n print(res.toString().slice(0, -3) + padStart(lres.toString().slice(-10), 10, '0'));\n } else {\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n print(res);\n }\n}", "positive_code": [{"source_code": "var firstLine = +readline();\nvar i = 0;\n\nwhile(i < firstLine) {\n\tvar arr = readline().split(' ');\n\tvar arrRes = arr.reduce((a,b) => add(a, b), \"0\");\n arrRes = divide(arrRes, 2).split('.')[0];\n\tprint(arrRes[0] == \"0\" ? arrRes.substring(1) : arrRes);\n\n\ti++;\n}\n\nfunction add(str1, str2) {\n var sum = \"\";\n\n var str1Length = str1.length;\n var str2Length = str2.length;\n\n if(str2Length > str1Length ){\n var temp = str2;\n str2 = str1;\n str1 = temp;\n }\n\n var carry = 0;\n var a;\n var b;\n var temp;\n var digitSum;\n for (var i = 0; i < str1.length; i++) {\n a = parseInt(str1.charAt(str1.length - 1 - i)); \n b = parseInt(str2.charAt(str2.length - 1 - i));\n b = (b) ? b : 0; \n temp = (carry + a + b).toString(); \n digitSum = temp.charAt(temp.length - 1); \n carry = parseInt(temp.substr(0, temp.length - 1));\n carry = (carry) ? carry : 0; \n\n sum = (i === str1.length - 1) ? temp + sum : digitSum + sum; \n\n }\n\n return sum; // return sum\n\n}\n\nfunction divide(n,d){\n var num = n + \"\",\n numLength = num.length,\n remainder = 0,\n answer = '',\n i = 0;\n\n while( i < numLength + 3){\n var digit = i < numLength ? parseInt(num[i]) : 0;\n\n if (i == numLength){\n answer = answer + \".\";\n }\n\n answer = answer + Math.floor((digit + (remainder * 10))/d);\n remainder = (digit + (remainder * 10))%d;\n i++;\n }\n return answer;\n}\n"}], "negative_code": [{"source_code": "var firstLine = +readline();\nvar i = 0;\n\nwhile(i < firstLine) {\n\tvar arr = readline().split(' ');\n\tvar arrRes = arr.reduce((a,b) => add(a, b), \"0\");\n \n arrRes = divide(arrRes, 2)\n\tprint(arrRes.split('.')[0]);\n\n\ti++;\n}\n\nfunction add(str1, str2) {\n var sum = \"\";\n\n var str1Length = str1.length;\n var str2Length = str2.length;\n\n if(str2Length > str1Length ){\n var temp = str2;\n str2 = str1;\n str1 = temp;\n }\n\n var carry = 0;\n var a;\n var b;\n var temp;\n var digitSum;\n for (var i = 0; i < str1.length; i++) {\n a = parseInt(str1.charAt(str1.length - 1 - i)); \n b = parseInt(str2.charAt(str2.length - 1 - i));\n b = (b) ? b : 0; \n temp = (carry + a + b).toString(); \n digitSum = temp.charAt(temp.length - 1); \n carry = parseInt(temp.substr(0, temp.length - 1));\n carry = (carry) ? carry : 0; \n\n sum = (i === str1.length - 1) ? temp + sum : digitSum + sum; \n\n }\n\n return sum; // return sum\n\n}\n\nfunction divide(n,d){\n var num = n + \"\",\n numLength = num.length,\n remainder = 0,\n answer = '',\n i = 0;\n\n while( i < numLength + 3){\n var digit = i < numLength ? parseInt(num[i]) : 0;\n\n if (i == numLength){\n answer = answer + \".\";\n }\n\n answer = answer + Math.floor((digit + (remainder * 10))/d);\n remainder = (digit + (remainder * 10))%d;\n i++;\n }\n return answer;\n}\n"}, {"source_code": "var firstLine = +readline();\nvar i = 0;\n\nwhile(i < firstLine) {\n\tvar arr = readline().split(' ');\n\tvar arrSum = arr.reduce((a,b) => add(a, b), \"0\");\n \n\tprint(Math.floor(divide(arrSum, 2)));\n\n\ti++;\n}\n\n\n\nfunction add(str1, str2) {\n var sum = \"\"; \n var str1Length = str1.length;\n var str2Length = str2.length;\n\n if(str2Length > str1Length ){\n var temp2 = str2;\n str2 = str1;\n str1 = temp2;\n }\n\n var carry = 0; // number that is carried to next decimal place, initially zero.\n var a;\n var b;\n var temp;\n var digitSum;\n for (var i = 0; i < str1.length; i++) {\n a = parseInt(str1.charAt(str1.length - 1 - i));\n b = parseInt(str2.charAt(str2.length - 1 - i)); \n b = (b) ? b : 0; \n temp = (carry + a + b).toString(); \n digitSum = temp.charAt(temp.length - 1); \n carry = parseInt(temp.substr(0, temp.length - 1)); \n carry = (carry) ? carry : 0; \n\n sum = (i === str1.length - 1) ? temp + sum : digitSum + sum;\n }\n\n return sum; // return sum\n}\n\nfunction divide(n,d){\n var num = n + \"\",\n numLength = num.length,\n remainder = 0,\n answer = '',\n i = 0;\n\n while( i < numLength + 3){\n var digit = i < numLength ? parseInt(num[i]) : 0;\n\n if (i == numLength){\n answer = answer + \".\";\n }\n\n answer = answer + Math.floor((digit + (remainder * 10))/d);\n remainder = (digit + (remainder * 10))%d;\n i++;\n }\n return parseFloat(answer);\n}\n"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n \n if(Math.max(...arr.map(item => item.length)) > 10) {\n var res = parseInt(arr.map(item => +item.slice(0, -8)).reduce((prev, curr) => prev + curr) / 2);\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString() + padStart(lres.toString().slice(-8), 8, '0'));\n } else {\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n print(res);\n }\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n \n if(res > Number.MAX_SAFE_INTEGER) {\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -10) + padStart(lres.toString().slice(-10), 10, '0'));\n } else {\n print(res);\n }\n}\n"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n \n if(Math.max(...arr.map(item => item.length)) > 10) {\n var res = parseInt(arr.map(item => +item.slice(0, -8) / 2).reduce((prev, curr) => prev + curr));\n var lres = parseInt(arr.map(item => +item.slice(-12) / 2).reduce((prev, curr) => prev + curr));\n print(res.toString().slice(0, -2) + padStart(lres.toString().slice(-10), 10, '0'));\n } else {\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n print(res);\n }\n}"}, {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var val = readline().split(' ').reduce((curr, prev) => curr + (+prev), 0);\n print(Math.floor(val / 2));\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n \n if(res > 10000000000) {\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -9) + padStart(lres.toString().slice(-9), 9, '0'));\n } else {\n print(res);\n }\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item.slice(0, -9)).reduce((prev, curr) => prev + curr) / 2);\n \n if(Math.max(...arr.map(item => item.length)) > 10) {\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -1) + padStart(lres.toString().slice(-9), 9, '0'));\n } else {\n print(res);\n }\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n \n if(res > Number.MAX_SAFE_INTEGER) {\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -9) + padStart(lres.toString().slice(-9), 9, '0'));\n } else {\n print(res);\n }\n}"}, {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n \n if(res > Number.MAX_SAFE_INTEGER) {\n lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -10) + lres.toString().slice(-10));\n } else {\n print(res);\n }\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n \n if(Math.max(...arr.map(item => item.length)) > 10) {\n var res = parseInt(arr.map(item => +item.slice(0, -9)).reduce((prev, curr) => prev + curr) / 2);\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString() + padStart(lres.toString().slice(-9), 9, '0'));\n } else {\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n print(res);\n }\n}"}, {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ').map(item => +item).sort((a, b) => a - b);\n var sum = arr[1] + (arr[2] - arr[1] + arr[0]) / 2;\n \n print(Math.floor(sum));\n}"}, {"source_code": "function padStart(str, count, symbol) {\n for(var i = str.length; i < count; i++) {\n str = '0' + str;\n }\n \n return str;\n}\n\nvar n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ');\n var res = parseInt(arr.map(item => +item).reduce((prev, curr) => prev + curr) / 2);\n \n if(res > 1000000000) {\n var lres = parseInt(arr.map(item => +item.slice(-10)).reduce((prev, curr) => prev + curr) / 2);\n print(res.toString().slice(0, -9) + padStart(lres.toString().slice(-9), 10, '0'));\n } else {\n print(res);\n }\n}"}], "src_uid": "d9e4a9a32d60e75f3cf959ef7f894fc6"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n const resp = myFunc(n, arr);\r\n console.log(resp);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(n, arr){\r\n\r\n let first;\r\n let aux;\r\n let map = [];\r\n\r\n function calculate(arr){\r\n let resp = 0;\r\n for(let i = 1; i < n-1; i+=2){\r\n aux = Math.max(arr[i-1], arr[i+1]);\r\n if(aux < arr[i]){\r\n map[i] = 0;\r\n continue;\r\n }\r\n map[i] = aux - arr[i] + 1;\r\n resp += aux - arr[i] + 1;\r\n }\r\n return resp;\r\n }\r\n\r\n function consult(pos){\r\n if(map[pos] != undefined) return map[pos];\r\n aux = Math.max(arr[pos-1], arr[pos+1]);\r\n if(aux < arr[pos]){\r\n map[pos] = 0;\r\n return 0;\r\n }\r\n map[pos] = aux - arr[pos] + 1;\r\n return map[pos];\r\n }\r\n\r\n\r\n first = calculate(arr);\r\n\r\n if(arr.length%2 == 1){\r\n return first;\r\n }\r\n\r\n let min = first;\r\n let atual = first;\r\n let old_val, new_val;\r\n for(let i = n-3; i >= 1; i-=2){\r\n old_val = consult(i);\r\n new_val = consult(i+1);\r\n atual = atual - old_val + new_val;\r\n if(atual < min) min = atual;\r\n }\r\n return min;\r\n\r\n}\r\n", "positive_code": [{"source_code": "function go(h)\n{\n let n = h.length;\n if (n % 2 == 1)\n {\n let s = 0;\n for (let i = 1; i < n; i += 2)\n {\n s += Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i]\n }\n return s;\n }\n else\n {\n let oddpS = [0];\n for (let i = 1; i < n - 1; i += 2)\n {\n oddpS.push(Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i] + oddpS[oddpS.length - 1])\n }\n let evenpS = [0]\n for (let i = n-2; i>0; i -= 2)\n {\n evenpS.push(Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i] + evenpS[evenpS.length - 1])\n }\n let min = oddpS[0] + evenpS[evenpS.length - 1];\n for (let i = 1; i < oddpS.length; i ++)\n {\n let test = oddpS[i] + evenpS[evenpS.length - i - 1];\n if (test < min)\n {\n min = test;\n }\n }\n return min;\n }\n}\n\nlet input = '';\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = input.split(EOL); /*your input text, split by lines*/\n let cases = parseInt(lines[0])\n for (let caseNum = 0; caseNum < cases; caseNum ++)\n {\n let h = lines[caseNum * 2 + 2].split(\" \").map(x => parseInt(x))\n console.log(go(h))\n }\n})"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n & 1) {\r\n let sum = 0;\r\n for (let i = 1; i < n; i += 2) {\r\n const num = Math.max(a[i - 1], a[i + 1]);\r\n if (a[i] <= num) sum += num - a[i] + 1;\r\n }\r\n return sum;\r\n }\r\n const l = new Array(n).fill(0),\r\n r = new Array(n).fill(0);\r\n for (let i = 1; i < n; i += 2) {\r\n var _l, _l2;\r\n const num = Math.max(a[i - 1], a[i + 1]);\r\n if (a[i] <= num) l[i] = ((_l = l[i - 2]) !== null && _l !== void 0 ? _l : 0) + num - a[i] + 1;else l[i] = (_l2 = l[i - 2]) !== null && _l2 !== void 0 ? _l2 : 0;\r\n }\r\n for (let i = n - 2; i >= 0; i -= 2) {\r\n var _r, _r2;\r\n const num = Math.max(a[i - 1], a[i + 1]);\r\n if (a[i] <= num) r[i] = ((_r = r[i + 2]) !== null && _r !== void 0 ? _r : 0) + num - a[i] + 1;else r[i] = (_r2 = r[i + 2]) !== null && _r2 !== void 0 ? _r2 : 0;\r\n }\r\n let res = Infinity;\r\n for (let i = 1; i < n; i += 2) {\r\n var _l3, _r3;\r\n res = Math.min(res, ((_l3 = l[i - 2]) !== null && _l3 !== void 0 ? _l3 : 0) + ((_r3 = r[i + 1]) !== null && _r3 !== void 0 ? _r3 : 0));\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var n = 0;\r\n var seq = [];\r\n function calc(i) {\r\n return Math.max(Math.max(0, seq[i-1] + 1 - seq[i], seq[i+1] + 1 - seq[i]));;\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n var ans = 0;\r\n if (n & 1) {\r\n for (var i = 1; i < n-1;i += 2) {\r\n ans += calc(i);\r\n }\r\n } else {\r\n var adds = [];\r\n for (var i = 1; i < n-1; i++) {\r\n adds.push(calc(i));\r\n }\r\n var runningSum = 0;\r\n for (var i = 0; i < adds.length; i+=2) {\r\n runningSum += adds[i];\r\n }\r\n ans = runningSum;\r\n for (var i = adds.length-1; i > 0; i-=2) {\r\n runningSum = runningSum - adds[i-1] + adds[i];\r\n ans = Math.min(ans, runningSum);\r\n }\r\n }\r\n print(ans);\r\n }"}], "negative_code": [], "src_uid": "ba52f4eaf05c0f154c40cec46c861c13"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let cq = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'Q') {\n cq++\n } else {\n if (cq > 0) cq--\n }\n }\n return cq === 0 ? 'Yes' : 'No'\n}\n", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';\n\t\tlet lag = 0;\n\t\tl.trim().split('').forEach(e => {\n\t\t\tif (e === \"Q\"){\n\t\t\t\tlag--;\n\t\t\t} else {\n\t\t\t\tif (lag < 0) {\n\t\t\t\t\tlag++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t});\n\t\tans.push(flag && lag === 0);\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let c1=0,c2=0;\r\n flag=true;\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]==='Q') c1++;\r\n else c2++;\r\n if(c1>c2) flag=false;\r\n }\r\n if(flag) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let c1=0,c2=0;\r\n flag=true;\r\n for(let i=n-1;i>=0;i--)\r\n {\r\n if(s[i]==='Q') c1++;\r\n else c2++;\r\n if(c1>c2) flag=false;\r\n }\r\n if(c1>c2) flag=false;\r\n if(s[n-1]==='Q') flag=false;\r\n if(flag) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n }\r\n})"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n // console.log('index', index)\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n let n = 0;\r\n\r\n for(let i = 0; i < str.length ; i++) {\r\n if(str[i] == \"Q\") {\r\n n++;\r\n } else {\r\n n--;\r\n if(n < 0) {\r\n n = 0\r\n }\r\n }\r\n }\r\n\r\n if(n === 0) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No')\r\n }\r\n}"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n const queue = [];\r\n\r\n for(let i = 0; i < str.length ; i++) {\r\n if(str[i] == \"Q\") {\r\n queue.push(\"Q\");\r\n } else {\r\n queue.pop()\r\n }\r\n }\r\n\r\n if(queue.length === 0) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No')\r\n }\r\n}"}, {"source_code": "let index = 0;\r\n\r\nrequire('readline').createInterface({\r\n input: process.stdin\r\n}).on('line', (line) => {\r\n if(index > 0 && index % 2 == 0) {\r\n solve(line)\r\n }\r\n\r\n index++;\r\n});\r\n\r\nfunction solve(str) {\r\n const queue = [];\r\n let isSolvable = true;\r\n\r\n for(let i = 0; isSolvable && i < str.length ; i++) {\r\n if(str[i] == \"Q\") {\r\n queue.push(\"Q\");\r\n } else {\r\n const front = queue.pop()\r\n }\r\n }\r\n\r\n if(isSolvable && queue.length === 0) {\r\n console.log('Yes');\r\n } else {\r\n console.log('No')\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction evaluateBoard(board)\r\n{\r\n\r\n}\r\n\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n \r\n while(t--)\r\n {\r\n const n = parseInt(readLine());\r\n \r\n let qas = readLine().split(\"\");\r\n qas.pop()\r\n //console.log(qas)\r\n let count=0\r\n \r\n for (let i=0;i0)\r\n console.log(\"No\")\r\n else\r\n console.log(\"Yes\")\r\n \r\n \r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n/*\r\n5\r\n4\r\nQQAA\r\n4\r\nQQAQ\r\n3\r\nQAA\r\n1\r\nQ\r\n14\r\nQAQQAQAAQQQAAA\r\n\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n\r\n*/\r\nexports.__esModule = true;\r\nvar readline_1 = require(\"readline\");\r\nfunction countChar(s, char) {\r\n\tvar count = 0;\r\n\tfor (var _i = 0, s_1 = s; _i < s_1.length; _i++) {\r\n\t\tvar i = s_1[_i];\r\n\t\tif (i === char) {\r\n\t\t\tcount++;\r\n\t\t}\r\n\t}\r\n\treturn count;\r\n}\r\nfunction processTheSequence(lines) {\r\n\tvar testCases = Number(lines[0]) * 2;\r\n\tvar sequenceLen;\r\n\tvar sequence;\r\n\t// let nOfQ: number;\r\n\t// let nOfA: number;\r\n\tfor (var i = 1; i < testCases; i++) {\r\n\t\tvar pendingQuestions = 0;\r\n\t\tsequenceLen = Number(lines[i]);\r\n\t\tsequence = lines[++i];\r\n\t\t// nOfA = countChar(sequence, \"A\");\r\n\t\t// nOfQ = countChar(sequence, \"Q\");\r\n\t\t// console.log(nOfA);\r\n\t\t// console.log(nOfQ);\r\n\t\tfor (var _i = 0, sequence_1 = sequence; _i < sequence_1.length; _i++) {\r\n\t\t\tvar j = sequence_1[_i];\r\n\t\t\t// console.log(j);\r\n\t\t\tif (j === \"Q\") {\r\n\t\t\t\tpendingQuestions += 1;\r\n\t\t\t} else if (j === \"A\" && pendingQuestions > 0) {\r\n\t\t\t\tpendingQuestions -= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\t// console.log(pendingQuestions);\r\n\t\tif (pendingQuestions === 0) {\r\n\t\t\tconsole.log(\"Yes\");\r\n\t\t} else {\r\n\t\t\tconsole.log(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\nvar rl = readline_1.createInterface(process.stdin, process.stdout);\r\nvar input = [];\r\nrl.on(\"line\", function (line) {\r\n\treturn input.push(line);\r\n}).on(\"close\", function () {\r\n\treturn processTheSequence(input);\r\n});\r\n"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0], e = 0\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i]\n }else{\n var a = lines[i].split(''), s = 0\n for(j = 0; j < e; j++){\n if(a[j] == 'Q'){\n s++\n }else{\n s = Math.max(0, s - 1)\n }\n }\n console.log(s === 0 ? 'YES' : 'NO')\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var s = lines[i].split('');\n var a = 0;\n for(j = 0; j < n; j++){\n if(s[j] == 'Q'){\n a++;\n }else{\n a = Math.max(0, a - 1);\n }\n }\n console.log(a === 0 ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n s = read();\r\n let l = 0,\r\n r = 0;\r\n for (let i = 0; i <= n; i++) {\r\n if ((i === n || s[i] === 'Q') && s[i - 1] === 'A') {\r\n if (r > l) {\r\n r = 0, l = 0;\r\n }\r\n }\r\n if (i < n) {\r\n if (s[i] === 'Q') l++;else r++;\r\n }\r\n }\r\n if (r !== l) return 'No';\r\n return 'Yes';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\r\nvar chats = readline();\r\n\r\nfor (var i = 0; i < chats; i++) {\r\n computarChat();\r\n}\r\n\r\nfunction computarChat() {\r\n var numerodemensagens = Number(readline());\r\n var mensagems = readline().split(\"\");\r\n\r\n var questoesAResponder = 0;\r\n\r\n for (var i = 0; i < numerodemensagens; i++) {\r\n var mensagem = mensagems[i];\r\n if (mensagem === \"Q\") {\r\n questoesAResponder += 1;\r\n }\r\n if (mensagem === \"A\" && questoesAResponder > 0) {\r\n questoesAResponder -= 1;\r\n }\r\n }\r\n\r\n // var questoesAResponder = mensagems.filter(function (mensagem) {\r\n // return mensagem === \"Q\";\r\n // });\r\n // var respostas = mensagems.filter(function (mensagem) {\r\n // return mensagem === \"A\";\r\n // });\r\n\r\n // var terminoucomanswer = mensagems[mensagems.length - 1] === \"A\";\r\n\r\n // // print(terminoucomanswer);\r\n\r\n if (!questoesAResponder) {\r\n print(\"Yes\");\r\n } else {\r\n print(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "const x = readline(); // first line\r\n \r\nfor(var i = 0 ; i < x ; i++) {\r\n var length = readline(); // skip line\r\n var inp = readline().toLowerCase();\r\n\r\n var func = str => {\r\n if (str.includes('qa')) {\r\n str = str.replace('qa', '');\r\n return func(str);\r\n } else {\r\n return str.includes('q') ? 'No' : 'Yes';\r\n }\r\n };\r\n \r\n print(func(inp));\r\n}"}, {"source_code": "var groups = parseInt(readline(), 10)\r\nfor(var i = 0; i < groups; i++) {\r\n var len = parseInt(readline(), 10)\r\n var dialog = readline().split(\"\")\r\n var q = 0;\r\n for (var j = 0; j < len; j++) {\r\n if (dialog[j] === \"Q\") q = q + 1\r\n if (dialog[j] === \"A\" && q > 0) q = q - 1\r\n }\r\n var res = q === 0 ? \"Yes\" : \"No\"\r\n print(res)\r\n}"}, {"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var n = readline(),\r\n counter = 0,\r\n input = readline().split(\"\");\r\n for(var j = 0 ; j < n ; ++j){\r\n if(input[j] == 'Q' && counter >= 0){\r\n counter++;\r\n }\r\n else if(input[j] == 'Q' && counter < 0){\r\n counter = 1;\r\n }\r\n else{\r\n counter--;\r\n }\r\n }\r\n counter <= 0 ? print(\"YES\") : print(\"NO\");\r\n}"}, {"source_code": "function process(str) {\r\n var stack = [];\r\n \r\n for (var i = 0; i < str.length; i++) {\r\n var char = str[i];\r\n if (char === 'Q') {\r\n stack.push(char);\r\n } else {\r\n stack.pop();\r\n }\r\n }\r\n \r\n print(stack.length === 0 ? 'Yes': 'No');\r\n}\r\n\r\nvar numOfCases = Number(readline());\r\nfor (var test = 0; test < numOfCases; test++) {\r\n var numOfChars = Number(readline());\r\n var str = readline();\r\n \r\n process(str);\r\n}"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var k = +readline();\r\n var str = readline();\r\n var count = 0;\r\n for(var j = 0; j < k; j++) {\r\n if(str[j] === 'Q') {\r\n count++;\r\n }\r\n if(str[j] === 'A' && count) {\r\n count--;\r\n }\r\n }\r\n print(count !== 0 ? 'No' : 'Yes');\r\n}\r\n"}], "negative_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';\n\t\tlet lag = 0;\n\t\tl.trim().split('').forEach(e => {\n\t\t\tlag += (e === \"Q\"?-1:1);\n\t\t\tif (lag > 0) flag = false;\n\t\t\t\n\t\t});\n\t\tans.push(flag);\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';\n\t\tlet lag = 0;\n\t\tl.trim().split('').forEach(e => {\n\t\t\tlag += (e === \"Q\"?-1:1);\n\t\t\tif (lag > 0) lag = false;\n\t\t\t\n\t\t});\n\t\tans.push(flag);\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = 0;\n\t\tl.trim().split('').forEach(e => flag += (e === \"Q\"?-1:1));\n\t\tans.push(flag >= 0 && l.substring(0,1) !== l.substring(l.length-1));\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = 0;\n\t\tl.trim().split('').forEach(e => flag += (e === \"Q\"?-1:1));\n\t\tconsole.log(flag);\n\t\tans.push(flag >= 0 && l.substring(0,1) !== l.substring(l.length-1));\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tlet flag = 0;\n\t\tl.split('').forEach(e => flag += (e === \"Q\"?-1:1));\n\t\tans.push(flag >= 0 && l.substring(0,1) !== l.substring(l.length-1));\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet l = nl.line();\n\t\tans.push(l.substring(0,1) !== l.substring(l.length-1));\n\t}\n\tconsole.log(ans.map(x => x?\"Yes\":\"No\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let c1=0,c2=0;\r\n flag=true;\r\n // for(let i=0;ic2) flag=false;\r\n if(s[n-1]==='Q') flag=false;\r\n if(flag) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let c1=0,c2=0;\r\n flag=true;\r\n for(let i=0;ic2) flag=false;\r\n }\r\n // if(c1>c2) flag=false;\r\n if(s[n-1]==='Q') flag=false;\r\n if(flag) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[2*_-1]);\r\n let s=line[2*_];\r\n // console.log(n,s);\r\n let c1=0,c2=0;\r\n flag=true;\r\n for(let i=0;ic2) flag=false;\r\n }\r\n if(c1>c2) flag=false;\r\n if(flag) console.log(\"Yes\");\r\n else console.log(\"No\");\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction evaluateBoard(board)\r\n{\r\n\r\n}\r\n\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n \r\n while(t--)\r\n {\r\n const n = parseInt(readLine());\r\n \r\n let qas = readLine().split(\"\");\r\n qas.pop()\r\n //console.log(qas)\r\n let count=0\r\n \r\n for (let i=0;i0)\r\n console.log(\"No\")\r\n else\r\n console.log(\"Yes\")\r\n \r\n \r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction evaluateBoard(board)\r\n{\r\n\r\n}\r\n\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine());\r\n \r\n while(t--)\r\n {\r\n const n = parseInt(readLine());\r\n \r\n let qas = readLine().split(\"\");\r\n qas.pop()\r\n //console.log(qas)\r\n let count=0\r\n \r\n for (let i=0;i0)\r\n console.log(\"No\")\r\n else\r\n console.log(\"Yes\")\r\n \r\n \r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n/*\r\n5\r\n4\r\nQQAA\r\n4\r\nQQAQ\r\n3\r\nQAA\r\n1\r\nQ\r\n14\r\nQAQQAQAAQQQAAA\r\n\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n\r\n*/\r\nexports.__esModule = true;\r\nvar readline_1 = require(\"readline\");\r\nfunction countChar(s, char) {\r\n\tvar count = 0;\r\n\tfor (var _i = 0, s_1 = s; _i < s_1.length; _i++) {\r\n\t\tvar i = s_1[_i];\r\n\t\tif (i === char) {\r\n\t\t\tcount++;\r\n\t\t}\r\n\t}\r\n\treturn count;\r\n}\r\nfunction processTheSequence(lines) {\r\n\tvar testCases = Number(lines[0]) * 2;\r\n\tvar sequenceLen;\r\n\tvar sequence;\r\n\tvar nOfQ;\r\n\tvar nOfA;\r\n\tfor (var i = 1; i < testCases; i++) {\r\n\t\tsequenceLen = Number(lines[i]);\r\n\t\tsequence = lines[++i];\r\n\t\tnOfA = countChar(sequence, \"A\");\r\n\t\tnOfQ = countChar(sequence, \"Q\");\r\n\t\t// console.log(nOfA);\r\n\t\t// console.log(nOfQ);\r\n\t\tif (nOfA === nOfQ || nOfA > nOfQ) {\r\n\t\t\tconsole.log(\"Yes\");\r\n\t\t} else {\r\n\t\t\tconsole.log(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\nvar rl = readline_1.createInterface(process.stdin, process.stdout);\r\nvar input = [];\r\nrl.on(\"line\", function (line) {\r\n\treturn input.push(line);\r\n}).on(\"close\", function () {\r\n\treturn processTheSequence(input);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let cq = 0, ca = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'Q') {\n cq++\n } else {\n ca++\n }\n }\n return ca >= cq ? 'Yes' : 'No'\n}\n"}, {"source_code": "\r\nvar chats = readline();\r\n\r\nfor (var i = 0; i < chats; i++) {\r\n computarChat();\r\n}\r\n\r\nfunction computarChat() {\r\n var numerodemensagens = Number(readline());\r\n var mensagems = readline().split(\"\");\r\n\r\n var questoesAResponder = mensagems.filter(function (mensagem) {\r\n return mensagem === \"Q\";\r\n });\r\n var respostas = mensagems.filter(function (mensagem) {\r\n return mensagem === \"A\";\r\n });\r\n\r\n var terminoucomanswer = mensagems[mensagems.length - 1] === \"A\";\r\n\r\n // print(terminoucomanswer);\r\n\r\n if (respostas.length >= questoesAResponder.length && terminoucomanswer) {\r\n print(\"Yes\");\r\n } else {\r\n print(\"No\");\r\n }\r\n}\r\n"}, {"source_code": "const x = readline(); // first line\r\n\r\nfor(var i = 0 ; i < x ; i++) {\r\n readline(); // skip line\r\n var inp = readline().toLowerCase().split('');\r\n var func = arr => {\r\n if (inp[0] == 'a') return 'No';\r\n var halfLength = Math.floor(arr.length/2);\r\n var questions = arr.filter(l => l == 'q');\r\n return questions.length <= halfLength ? 'Yes' : 'No'\r\n }\r\n \r\n print(func(inp));\r\n}"}, {"source_code": "const x = readline(); // first line\r\n\r\nfor(var i = 0 ; i < x ; i++) {\r\n readline(); // skip line\r\n var inp = readline().toLowerCase().split('');\r\n var func = arr => {\r\n var initLength = arr.length;\r\n var questions = arr.filter(l => l == 'q');\r\n return questions.length <= Math.floor(initLength/2) ? 'Yes' : 'No'\r\n }\r\n print(func(inp));\r\n}"}, {"source_code": "var groups = parseInt(readline(), 10)\r\nfor(var i = 0; i < groups; i++) {\r\n var length_dialog = readline()\r\n var dialog = readline().split(\"\")\r\n if (dialog[0] !== \"Q\"|| dialog[dialog.length - 1] !== \"A\") {\r\n print(\"NO\")\r\n continue\r\n }\r\n var a = dialog.filter(d => d === \"A\").length\r\n var q = dialog.filter(d => d === \"Q\").length\r\n var res = a >= q ? \"YES\" : \"NO\"\r\n print(res)\r\n}"}, {"source_code": "var groups = parseInt(readline(), 10)\r\nfor(var i = 0; i < groups; i++) {\r\n var length_dialog = readline()\r\n var dialog = readline().split(\"\")\r\n if (dialog[0] !== \"Q\") {\r\n print(\"NO\")\r\n continue\r\n }\r\n var a = dialog.filter(d => d === \"A\").length\r\n var q = dialog.filter(d => d === \"Q\").length\r\n var res = a >= q ? \"YES\" : \"NO\"\r\n print(res)\r\n}"}, {"source_code": "var groups = readline()\r\nfor(var i = 0; i < groups; i++) {\r\n var len = readline()\r\n var dialog = readline().split(\"\")\r\n var a_number = dialog.filter(d => d === \"A\").length\r\n var q_number = dialog.filter(d => d === \"Q\").length\r\n var res = a_number >= q_number ? \"YES\" : \"NO\"\r\n print(res)\r\n}"}, {"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var n = readline(),\r\n qCounter = 0,\r\n aCounter = 0,\r\n input = readline().split(\"\");\r\n if (input[input.length - 1] == \"Q\") {\r\n print(\"NO\");\r\n } else {\r\n for (var j = 0; j < n; ++j) {\r\n input[j] == \"Q\" ? qCounter++ : aCounter++;\r\n }\r\n aCounter >= qCounter ? print(\"YES\") : print(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n var n = readline(), qCounter = 0 , aCounter = 0,\r\n input = readline().split('');\r\n for(var j = 0 ; j < n ; ++j){\r\n input[j] == 'Q' ? qCounter++ : aCounter++;\r\n }\r\n aCounter >= qCounter ? print(\"YES\") : print(\"NO\");\r\n}"}, {"source_code": "var numOfChars = Number(readline());\r\nvar str = readline();\r\n\r\nvar stack = [];\r\n\r\nfor (var i = 0; i < str.length; i++) {\r\n var char = str[i];\r\n if (char === 'Q') {\r\n stack.push(char);\r\n } else {\r\n stack.pop();\r\n }\r\n}\r\n\r\nprint(stack.length === 0 ? 'Yes': 'No');"}], "src_uid": "c5389b39312ce95936eebdd83f510e40"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n & 1) return 'NO';\r\n a.sort((a, b) => a - b);\r\n let res = [];\r\n for (let i = 0, j = n / 2; j < n; i++, j++) {\r\n res.push(a[i], a[j]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let l = (i - 1 + n) % n,\r\n r = (i + 1) % n;\r\n if (res[i] > res[l] && res[i] > res[r] || res[i] < res[l] && res[i] < res[r]) continue;\r\n return 'NO';\r\n }\r\n return `YES\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst n = nextInt();\r\n\t\r\n\tconst arr = nextIntArray(n);\r\n\t\r\n\tif (n % 2 === 1) {\r\n\t\tmyout(\"NO\");\r\n\t\treturn;\r\n\t}\r\n\r\n\tarr.sort((a, b) => a - b);\r\n\tlet median;\r\n\r\n\tif (arr.length % 2 === 0) {\r\n\t\tmedian = (arr[arr.length / 2 - 1] + arr[arr.length / 2]) / 2;\r\n\t} else {\r\n\t\tmedian = arr[(arr.length - 1) / 2];\r\n\t}\r\n\r\n\tconst mins = arr.slice(0, arr.length / 2 );\r\n\tconst maxs = arr.slice(arr.length / 2 );\r\n\r\n\tconst res = [];\r\n\r\n\tlet j = 0, k = 0;\r\n\r\n\tfor (let i = 0; i < arr.length; i++) {\r\n\t\tif (i % 2 === 0) {\r\n\t\t\tif (i >= 1 && res[i - 1] === mins[j]) {\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tres[i] = mins[j];\r\n\t\t\tj++;\r\n\t\t} else {\r\n\t\t\tif (i >= 1 && res[i - 1] === maxs[k]) {\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tres[i] = maxs[k];\r\n\t\t\tk++;\r\n\t\t}\r\n\t}\r\n\r\n\tmyout(\"YES\");\r\n\tmyout(res.join(\" \"));\r\n}\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, m] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n if (n%2==1)\n return 'NO'\n let ans = 0;\n A.sort((a, b)=>a-b);\n let arr = [];\n for (let i=0; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n if(n % 2){\n console.log('NO');\n continue;\n }\n var b = Math.floor(n / 2);\n var flag = false;\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n for(j = 1; j < b; j++){\n if(a[j] == a[j + b - 1]){\n console.log('NO');\n flag = true;\n break;\n }\n }\n var ans = '';\n if(!flag){\n console.log('YES');\n for(j = 0; j < b; j++){\n ans += a[j] + ' ' + a[j + b] + ' ';\n }\n console.log(ans);\n }\n }\n }\n});\n"}, {"source_code": "const solve = (arr,n)=>{\r\n if(n%2){\r\n console.log(\"NO\");\r\n return;\r\n }\r\n arr.sort((a,b)=>a-b);\r\n let res = [],i=0,j=0,k = Math.floor(n/2);\r\n while(i*2parseInt(cur));\r\n solve(arr,n);\r\n }\r\n}\r\nmain();\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n a.sort((x, y) => x - y);\n\n let b = new Array(n);\n\n let j = 0;\n\n for (let i = 0; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n for (let i = 1; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n // console.log('DEBUG b', b);\n\n for (let i = 0; i < n; i++) {\n let next = (i + 1) % n;\n let prev = (n + i - 1) % n;\n\n let x = (b[prev] > b[i]) && (b[i] < b[next]);\n let y = (b[prev] < b[i]) && (b[i] > b[next]);\n\n if (!(x || y)) {\n // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);\n return 'NO'\n }\n // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);\n }\n\n return 'YES\\n' + b.join(' ');\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction lowerBound(a, x) {\r\n let lo = 0;\r\n let hi = a.length;\r\n while (lo < hi) {\r\n let mid = lo + Math.trunc((hi - lo) / 2);\r\n if (a[mid] >= x) {\r\n hi = mid;\r\n }\r\n else {\r\n lo = mid + 1;\r\n }\r\n }\r\n return hi;\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n if ((n % 2) != 0) {\r\n return false;\r\n }\r\n a.sort((i, j) => i - j);\r\n let m = n / 2;\r\n for (let i = 1; i + m < n; i++) { // caution\r\n // printf(\"a[%d] %d a[%d] %d\\n\", i, a[i], i + m - 1, a[i + m - 1]);\r\n if (a[i] == a[i + m - 1]) {\r\n return false;\r\n }\r\n }\r\n const ans = af(n);\r\n let j = m;\r\n for (let i = 0; i + m < n; i++) {\r\n ans[i + i] = a[i];\r\n ans[i + i + 1] = a[i + m];\r\n }\r\n process.stdout.write('YES\\n');\r\n process.stdout.write(ans.join(' '));\r\n process.stdout.write('\\n');\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (!solve()) {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n a.sort();\n\n let b = new Array(n);\n\n let j = 0;\n\n for (let i = 0; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n for (let i = 1; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n // console.log('DEBUG b', b);\n\n for (let i = 0; i < n; i++) {\n let next = (i + 1) % n;\n let prev = (n + i - 1) % n;\n\n let x = (b[prev] > b[i]) && (b[i] < b[next]);\n let y = (b[prev] < b[i]) && (b[i] > b[next]);\n\n if (!(x || y)) {\n // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);\n return 'NO'\n }\n // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);\n }\n\n return 'YES\\n' + b.join(' ');\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n a.sort();\n\n let b = new Array(n);\n\n let j = 0;\n\n for (let i = 0; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n for (let i = 1; i < n; i += 2) {\n b[i] = a[j++];\n }\n\n console.log('DEBUG b', b);\n\n for (let i = 0; i < n; i++) {\n let next = (i + 1) % n;\n let prev = (n + i - 1) % n;\n\n let x = (b[prev] > b[i]) && (b[i] < b[next]);\n let y = (b[prev] < b[i]) && (b[i] > b[next]);\n\n if (!(x || y)) {\n // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);\n return 'NO'\n }\n // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);\n }\n\n return 'YES\\n' + b.join(' ');\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nfunction lowerBound(a, x) {\r\n let lo = 0;\r\n let hi = a.length;\r\n while (lo < hi) {\r\n let mid = lo + Math.trunc((hi - lo) / 2);\r\n if (a[mid] >= x) {\r\n hi = mid;\r\n }\r\n else {\r\n lo = mid + 1;\r\n }\r\n }\r\n return hi;\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n if ((n % 2) != 0) {\r\n return false;\r\n }\r\n a.sort((i, j) => i - j);\r\n let m = n / 2;\r\n for (let i = 1; i + m <= n; i++) {\r\n if (a[i] == a[i + m - 1]) {\r\n return false;\r\n }\r\n }\r\n const ans = af(n);\r\n let j = m;\r\n for (let i = 0; i + m < n; i++) {\r\n ans[i + i] = a[i];\r\n ans[i + i + 1] = a[i + m];\r\n }\r\n process.stdout.write('YES\\n');\r\n process.stdout.write(ans.join(' '));\r\n process.stdout.write('\\n');\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (!solve()) {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst n = nextInt();\r\n\t\r\n\tconst arr = nextIntArray(n);\r\n\t\r\n\tif (n % 2 === 1) {\r\n\t\tmyout(\"NO\");\r\n\t\treturn;\r\n\t}\r\n\r\n\tarr.sort((a, b) => a - b);\r\n\tlet median;\r\n\r\n\tif (arr.length % 2 === 0) {\r\n\t\tmedian = (arr[arr.length / 2 - 1] + arr[arr.length / 2]) / 2;\r\n\t} else {\r\n\t\tmedian = arr[(arr.length - 1) / 2];\r\n\t}\r\n\r\n\tconst mins = [];\r\n\tconst maxs = [];\r\n\r\n\tfor (let i = 0; i < arr.length; i++) {\r\n\t\tif (arr[i] < median) {\r\n\t\t\tmins.push(arr[i]);\r\n\t\t} else {\r\n\t\t\tmaxs.push(arr[i]);\r\n\t\t}\r\n\t}\r\n\r\n\tif (Math.abs(maxs.length - mins.length) > 1) {\r\n\t\tmyout(\"NO\");\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst res = [];\r\n\r\n\tlet j = 0, k = 0;\r\n\r\n\tfor (let i = 0; i < arr.length; i++) {\r\n\t\tif (i % 2 === 0) {\r\n\t\t\tres[i] = mins[j];\r\n\t\t\tj++;\r\n\t\t} else {\r\n\t\t\tres[i] = maxs[k];\r\n\t\t\tk++;\r\n\t\t}\r\n\t}\r\n\r\n\tmyout(\"YES\");\r\n\tmyout(res.join(\" \"));\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n a.sort((a, b) => a - b);\r\n let res = [];\r\n for (let i = 0, j = n - 1; i <= j; i++, j--) {\r\n if (i === j) {\r\n res.push(a[i]);\r\n } else res.push(a[i], a[j]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let l = (i - 1 + n) % n,\r\n r = (i + 1) % n;\r\n if (res[i] > res[l] && res[i] > res[r] || res[i] < res[l] && res[i] < res[r]) continue;\r\n return 'NO';\r\n }\r\n return `YES\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "a30c5562d3df99291132fac20e05e708"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let input = readLine();\n let countOne = 0;\n let countZero = 0;\n for (let i = 0; i < input.length; i++) {\n if (input[i] === \"0\") countOne++;\n else countZero++;\n }\n if (Math.abs(countOne - countZero) === input.length) console.log(\"NET\");\n else {\n let num = Math.min(countZero, countOne);\n if (num % 2 === 1) console.log(\"DA\");\n else console.log(\"NET\");\n }\n }\n}\n", "positive_code": [{"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; t++) {\n var s = read();\n var c = {\n '0': 0,\n '1': 0\n };\n for (var i = 0; i < s.length; i++) {\n c[s[i]]++;\n }\n if (Math.min(c[0], c[1]) & 1) {\n write('da');\n } else {\n write('net');\n }\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar s = nextCharArray();\n\t\tvar zero = 0;\n\t\tvar one = 0;\n\t\tfor(var j = 0; j < s.length; j++){\n\t\t\tif(s[j] == \"0\"){\n\t\t\t\tzero++;\n\t\t\t}else{\n\t\t\t\tone++;\n\t\t\t}\n\t\t}\n\t\tmyerr({zero,one});\n\t\tcount = Math.min(zero, one);\n\t\tif(count % 2 == 0){\n\t\t\toutput[i] = \"NET\";\n\t\t}else{\n\t\t\toutput[i] = \"DA\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let s = data[i].trim().split('');\n let count = 1;\n for (let j = 0; j < s.length; j += 1) {\n if ((s[j] === '0' && s[j + 1] === '1') || (s[j] === '1' && s[j + 1] === '0')) {\n s.splice(j, 2);\n count += 1;\n j = -1;\n }\n }\n count % 2 === 0 ? console.log('DA') : console.log('NET');\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let numDeleted = 0;\n let i = 1;\n while (i <= testCases) {\n var j = 0;\n numDeleted = 0\n let curString = data[i]\n while (j < curString.length - 1) {\n if ((curString.charAt(j) === \"0\" && curString.charAt(j + 1) === \"1\") ||\n (curString.charAt(j) === \"1\" && curString.charAt(j + 1) === \"0\")) {\n let tempString = \"\"\n if (j === 0) {\n tempString = curString.substring(2)\n } else {\n tempString = curString.substring(0, j) \n if (j + 2 < curString.length) {\n tempString += curString.substring(j + 2, curString.length)\n }\n }\n curString = tempString\n j = Math.max(j - 1, 0)\n numDeleted++\n } else {\n j++\n }\n }\n i++\n console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? \"DA\" : \"NET\")\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let numDeleted = 0;\n let i = 1;\n while (i <= testCases) {\n let stack = []\n let numDeleted = 0\n let j = 0;\n let curString = data[i].split('')\n for(j = 0; j < curString.length; j++) {\n if ((curString[j] === '0' && stack[stack.length-1] === '1') ||\n (curString[j] === '1' && stack[stack.length-1]) === '0') {\n numDeleted++\n stack.pop()\n } else {\n stack.push(curString[j])\n }\n }\n i++\n console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? \"DA\" : \"NET\")\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let i;\n for(i = 1; i <= testCases; i++) {\n solve(data[i])\n }\n}\n\nfunction solve(line) {\n var i;\n let num0 = 0\n let num1 = 0\n let lineSplit = line.split('')\n for(i = 0; i < line.length; i++) {\n if (lineSplit[i] == '0') {\n num0++\n } else {\n num1++\n }\n }\n\n console.log((Math.min(num0, num1) % 2 !== 0) ? \"DA\" : \"NET\")\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let count = 0;\n const arr = [...str];\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] !== arr[i - 1]) {\n arr.splice(i-1, 2);\n i = 0;\n count++;\n }\n }\n\n if (count % 2) {\n console.log('DA');\n }\n else {\n console.log('NET');\n }\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let zeros = 0;\n let ones = 0;\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '1') {\n ones++;\n }\n else {\n zeros++;\n }\n }\n\n let count = Math.min(zeros, ones);\n if (count % 2) {\n console.log('DA');\n }\n else {\n console.log('NET');\n }\n\n // let count = 0;\n // const arr = [...str];\n\n // for (let i = 1; i < arr.length; i++) {\n // if (arr[i] !== arr[i - 1]) {\n // arr.splice(i-1, 2);\n // i = 0;\n // count++;\n // }\n // }\n\n // if (count % 2) {\n // console.log('DA');\n // }\n // else {\n // console.log('NET');\n // }\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst s2i = s => parseInt(s, 10);\n\nfunction main() {\n let T = s2i(readLine());\n let s, c0, c1, totalMoves;\n let out = '';\n while (T--) {\n s = readLine()\n c0 = 0\n c1 = 0\n for (let i = 0, l = s.length, c; i < l; i++) {\n c = s.charAt(i);\n if (c === '0') c0++;\n else c1++;\n }\n\n totalMoves = Math.min(c0, c1);\n\n // console.log(totalMoves % 2 === 0 ? 'NET' : 'DA');\n out += totalMoves % 2 === 0 ? 'NET\\n' : 'DA\\n'\n }\n console.log(out)\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += getWinner(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += getWinner(input) + '\\n'\n }\n lineCount++\n});\n\nfunction getWinner(str) {\n var count0 = 0\n var count1 = 0\n for(var i=0;i {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let i;\n for(i = 1; i <= testCases; i++) {\n solve(data[i])\n }\n}\n\nfunction solve(line) {\n var i;\n let num0 = 0\n let num1 = 1\n let lineSplit = line.split('')\n for(i = 0; i < line.length; i++) {\n if (lineSplit[i] == '0') {\n num0++\n } else {\n num1++\n }\n }\n\n console.log((Math.min(num0, num1) % 2 !== 0) ? \"DA\" : \"NET\")\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let numDeleted = 0;\n let i = 1;\n while (i <= testCases) {\n var j = 0;\n numDeleted = 0\n let curString = data[i]\n while (j < curString.length - 1) {\n if ((curString.charAt(j) === \"0\" && curString.charAt(j + 1) === \"1\") ||\n (curString.charAt(j) === \"1\" && curString.charAt(j + 1) === \"0\")) {\n if (j === 0) {\n curString = curString.substring(2)\n } else {\n curString = curString.substring(0, j) + curString.substring(Math.min(j + 1, curString.length - 1), curString.length - 1)\n }\n j = Math.max(j - 1, 0)\n numDeleted++\n } else {\n j++\n }\n }\n i++\n console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? \"DA\" : \"NET\")\n }\n}"}], "src_uid": "046900001c7326fc8d890a22fa7267c9"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction probA(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let [n,k] = readline().split(' ');\n n = pi(n);\n k = pi(k);\n\n if(n < k)\n console.log(k-n);\n else{\n if((n+k) % 2 === 0){\n console.log(0);\n }else{\n console.log(n-k);\n }\n }\n }\n}\n\nfunction probB(){\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n a[0] = pi(a[0]);\n a[1] = pi(a[1]);\n a[2] = pi(a[2]);\n\n b[0] = pi(b[0]);\n b[1] = pi(b[1]);\n b[2] = pi(b[2]);\n\n let maxSum = 0;\n if(b[2] - (a[0] + a[2]) > 0){\n b[2] = b[2] - (a[0]+a[2]);\n a[0] = 0;\n a[2] = 0;\n }else if(b[2] - a[0] > 0){\n a[2] = a[2] - (b[2] - a[0]);\n b[2] = 0;\n a[0] = 0;\n }else{\n a[0] -= b[2];\n b[2] = 0;\n }\n\n if(a[2] > b[1])\n console.log((b[1] - b[2]) * 2)\n else\n console.log((a[2]-b[2]) * 2);\n\n }\n}\n\nfunction probC(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = readline().split(' ');\n let x = JSON.parse(JSON.stringify(a));\n\n x.sort((a,b) => pi(a) - pi(b));\n let res = true;\n for(let i = 0; i < n; i++){\n if(x[i] !== a[i]){\n if(pi(a[i]) % pi(x[0]) !== 0){\n res = false;\n break;\n }\n }\n }\n\n if(res)\n console.log('yes');\n else\n console.log('no');\n }\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const sorted = [...arr].sort((a, b) => a - b);\n const min = sorted[0];\n let possible = true;\n\n for (let i = 0; i < len; i++) {\n if (sorted[i] !== arr[i]) {\n if (arr[i] % min !== 0) {\n possible = false;\n }\n }\n }\n\n possible ? console.log(\"YES\") : console.log(\"NO\");\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let t = $()\n while (t--) {\n let n = $(), a = $(n), m = a.min()[0], b = a.filter(v => v % m == 0).sort(asc);\n let j = 0;\n For(n, i => {\n if (a[i] % m == 0) a[i] = b[j++];\n })\n log(For(n - 1, i => a[i] > a[i + 1] ? 1 : null) ? 'NO' : 'YES')\n }\n}\n"}, {"source_code": "\nvar t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n str = readline();\n var a = str.split(\" \");\n var b = str.split(\" \");\n a = a.map(a => Number(a));\n b = b.map(a => Number(a));\n b.sort((a, b) => a - b);\n \n var min = b[0];\n var out = true;\n for (var j = 0; j < a.length; j++){\n if ((a[j] != b[j]) && (a[j] % min > 0)){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\");\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number).slice(0, n)\n const sorted = [...as].sort((a, b) => a - b)\n const minimum = sorted[0]\n let result = true\n for (let i = 0; i < n; i++) {\n if (as[i] !== sorted[i] && as[i] % minimum !== 0) {\n result = false\n break\n }\n }\n console.log(result ? 'YES' : 'NO')\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n const sorted = [...as].sort((a, b) => a - b)\n const minimum = sorted[0]\n let result = true\n for (let i = 0; i < n; i++) {\n if (as[i] !== sorted[i] && as[i] % minimum !== 0) {\n result = false\n break\n }\n }\n console.log(result ? 'YES' : 'NO')\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n const sorted = [...as].sort((a, b) => a - b)\n const minimum = sorted[0]\n let result = true\n console.log(as, minimum, sorted)\n for (let i = 0; i < n; i++) {\n if (as[i] !== sorted[i] && as[i] % minimum !== 0) {\n result = false\n console.log('failed', i)\n break\n }\n }\n console.log(result ? 'YES' : 'NO')\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.split(/\\n/);\n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _ = 0; _ < t; _++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n const sorted = [...as].sort((a, b) => a - b)\n console.log(as.every((a, i) => a === sorted[i] || a % sorted[0] === 0) ? 'YES' : 'NO')\n }\n}\n"}, {"source_code": "\nvar t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n var a = readline().split(\" \");\n b = a.concat();\n b.sort((a, b) => {\n if(a > b){\n return 1;\n }\n else{\n return -1;\n }\n })\n var min = b[0];\n var out = true;\n for (var j = 0; j < a.length; j++){\n if ((a[j] != b[j]) && (a[j] % min > 0)){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\");\n }\n}"}, {"source_code": "\nvar t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n str = readline();\n var a = str.split(\" \");\n var b = str.split(\" \");\n a = a.map(a => Number(a));\n b.sort((a, b) => {\n if(a > b){\n return 1;\n }\n else{\n return -1;\n }\n })\n var min = b[0];\n var out = true;\n for (var j = 0; j < a.length; j++){\n if ((a[j] != b[j]) && (a[j] % min > 0)){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\");\n }\n}"}, {"source_code": "var t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n var a = readline().split(\" \");\n a = a.map(a => Number(a));\n b = a.sort((a, b) => {\n if(a > b){\n return 1;\n }\n else{\n return 0;\n }\n })\n var temp;\n var min = b[0];\n var out;\n for (var j = 0; j < a.length; j++){\n if ((a[j] != b[j]) != (a[j] % min > 0)){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "function gcd(a, b){\n var temp;\n if (b > a){\n temp = a;\n a = b;\n b = temp;\n }\n\n var res = b;\n\n while(res > 1){\n if((a % res == 0) && (b % res == 0)){\n break;\n }\n res--;\n }\n\n if(res <= b){\n return res;\n }\n else{\n return false;\n }\n\n}\n\nvar t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n var a = readline().split(\" \");\n a = a.map(a => Number(a));\n var temp;\n var min = a[0];\n\n for (var j = 0; j < a.length; j++){\n if (a[j] < min){\n min = a[j];\n }\n } \n\n for (var j = 0; j < a.length; j++){\n for(var d = j+1; d < a.length; d++){\n if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){\n temp = a[j];\n a[j] = a[d]; \n a[d] = temp;\n }\n }\n }\n var out = true;\n for (var j = 0; j < a.length - 1; j++){\n if(a[j] > a[j+1]){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "function gcd(a, b){\n var temp;\n if (b > a){\n temp = a;\n a = b;\n b = temp;\n }\n\n var res = 2;\n\n while(res <= b){\n if((a % res == 0) && (b % res == 0)){\n break;\n }\n res++;\n }\n\n if(res <= b){\n return res;\n }\n else{\n return false;\n }\n\n}\n\nvar t = Number(readline());\n\nfor (var i = 0; i < t; i++){\n var n = Number(readline());\n var a = readline().split(\" \");\n a = a.map(a => Number(a));\n var temp;\n var min = a[0];\n\n for (var j = 0; j < a.length; j++){\n if (a[j] < min){\n min = a[j];\n }\n } \n\n for (var j = 0; j < a.length; j++){\n for(var d = j+1; d < a.length; d++){\n if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){\n temp = a[j];\n a[j] = a[d]; \n a[d] = temp;\n }\n }\n }\n var out = true;\n for (var j = 0; j < a.length - 1; j++){\n if(a[j] > a[j+1]){\n out = false;\n }\n }\n\n if(out){\n print(\"YES\");\n }\n else{\n print(\"NO\");\n }\n}"}], "src_uid": "f2070c2bd7bdbf0919aef1e915a21a24"} {"source_code": "var x = parseInt(readline());\nvar n = readline().split(\" \").map(function(x){return parseInt(x);}).filter(function(x){return x==0;});\n\nprint((x==1&&n.length==0)||(x>1&&n.length==1)?\"YES\":\"NO\");\n", "positive_code": [{"source_code": "function InputButtons() {\n readline();\n const buttons = readline().split(' ').map((element) => {\n return parseInt(element);\n });\n return buttons;\n}\n\nfunction IsFastened(button) {\n if (buttons.length == 1) {\n if (buttons[0] == 1) {\n return true;\n }\n else {\n return false;\n }\n }\n\n var isFastened = false;\n var result = true;\n buttons.forEach(function(button) {\n if (button == 0) {\n if (!isFastened) {\n isFastened = true;\n }\n else {\n result = false;\n }\n }\n });\n if (!result) {\n return false;\n }\n else {\n return isFastened;\n }\n}\n\nvar buttons = InputButtons();\nif (IsFastened(buttons)) {\n print('YES');\n}\nelse {\n print('NO');\n}"}], "negative_code": [{"source_code": "function InputButtons() {\n readline();\n const buttons = readline().split(' ').map((element) => {\n return parseInt(element);\n });\n return buttons;\n}\n\nfunction IsFastened(button) {\n if (buttons.length == 1) {\n if (buttons[0] == 1) {\n return true;\n }\n else {\n return false;\n }\n }\n\n var isFastened = false;\n buttons.forEach(function(button) {\n if (button == 0) {\n if (!isFastened) {\n isFastened = true;\n }\n else {\n return false;\n }\n }\n });\n\n return isFastened;\n}\n\nvar buttons = InputButtons();\nif (IsFastened(buttons)) {\n print('YES');\n}\nelse {\n print('NO');\n}"}], "src_uid": "7db0b870177e7d7b01da083e21ba35f5"} {"source_code": "var a = readline();\nvar b = a.split(\" \", 2);\nvar n = Number(b[0]);\nvar k = Number(b[1]);\nprint((n * n + k - n + n * (k - 1) + 1) / 2 * n);\n\nvar x = 0, y = n * (k - 1);\nfor (var i = 0; i < n; ++i) {\n var str = \"\";\n for (var j = 0; j < k - 1; ++j) {\n str += ++x + \" \";\n }\n for (var j = k - 1; j < n; ++j) {\n str += ++y + \" \";\n }\n print(str);\n}", "positive_code": [{"source_code": "var a = readline();\nvar b = a.split(\" \", 2);\nvar n = Number(b[0]);\nvar k = Number(b[1]);\n\nvar arr = new Array(n);\nfor (var i = 0; i < n; ++i) {\n arr[i] = new Array(n);\n}\n\nvar num = n * n;\nfor (var i = 0; i < n; ++i) {\n for (var j = n - 1; j >= k - 1; --j) {\n arr[i][j] = num--;\n }\n}\n\nif (num) {\n for (var i = 0; i < n; ++i) {\n for (var j = k - 2; j >= 0; --j) {\n arr[i][j] = num--;\n }\n }\n}\n\nvar sum = 0;\nfor (var i = 0; i < n; ++i) {\n sum += arr[i][k - 1];\n}\n\nprint(sum);\nfor (var i = 0; i < n; ++i) {\n print(arr[i].join(\" \"));\n}"}, {"source_code": "var a = readline();\nvar b = a.split(\" \", 2);\nvar n = Number(b[0]);\nvar k = Number(b[1]);\nprint((n * n + k - n + n * (k - 1) + 1) / 2 * n);\n\nvar x = 0, y = n * (k - 1);\nfor (var i = 0; i < n; ++i) {\n var str = \"\";\n for (var j = 0; j < k - 1; ++j) {\n str += ++x + \" \";\n }\n for (var j = k - 1; j < n; ++j) {\n str += ++y + \" \";\n }\n print(str);\n}"}], "negative_code": [], "src_uid": "272f66f3c71c4997c5a1f0f009c9b99e"} {"source_code": "var N = parseInt(readline());\nvar a = readline().split(\" \").map(function(x){return parseInt(x);});\n\nvar res = 0;\nvar swaps = [];\nvar temp = 0;\n\nfunction selectionSort(sortMe)\n{\n var i, j, tmp, tmp2;\n for (i = 0; i < sortMe.length - 1; i++)\n {\n tmp = i;\n for (j = i + 1; j < sortMe.length; j++){\n if (sortMe[j] < sortMe[tmp]){\n tmp = j;\n }\n }\n if(tmp!=i){\n tmp2 = sortMe[tmp];\n sortMe[tmp] = sortMe[i];\n sortMe[i] = tmp2;\n res++;\n swaps.push({x: i, y: tmp});\n }\n\t}\n}\n\nselectionSort(a);\nprint(res);\nfor(var i=0; i < swaps.length; i++){\n\tprint(swaps[i].x + \" \" + swaps[i].y);\n}", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar nums = readline().split(' ').map(function(x){return parseInt(x)});\nvar min, k, tmp;\nvar step = [];\n\nfor(var i=0;i 0)\n for(var i=0;i t ){\n a.push(i);\n }\n }\n a.push(n);\n var diff, result = 0;\n for(i = 1 ; i < a.length ; ++i){\n diff = a[i] - a[i-1] - 1;\n result += Math.max(diff-c+1,0);\n }\n print(result);\n})();", "positive_code": [{"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\n\nprint(function(n, t, c) {\n var a = readline().split(' ').map(Number);\n\n var count = 0;\n var ans = 0;\n for (var i = 0; i < n; i++) {\n if (a[i] <= t) {\n count++;\n if (count >= c) {\n ans++;\n }\n } else {\n count = 0;\n }\n }\n return ans;\n\n\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var ntc = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ntc[0],t=ntc[1],c=ntc[2];\nvar x = readline().trim().split(' ').map((x)=>parseInt(x))\nvar ans =0;\nvar p=[];\nfor(var i=0;it)\n p.push(i)\n}\nif(p.length==0)\n ans = n-c+1;\nelse{\n for(var i=0;i= c) k++;\n\t}\n\n\tprint(k);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tn = data[0], maxCrime = data[1], minSpan = data[2],\n\t\tcount = 0,\n\t\tcrimes = tokenizeIntegers(readline()),\n\t\tspan = 0;\n\tfor (var i = 0; i < n; ++i) {\n\t\tif (crimes[i] <= maxCrime) {\n\t\t\t++span;\n\t\t\tif (span >= minSpan) {\n\t\t\t\t++count;\n\t\t\t}\n\t\t} else {\n\t\t\tspan = 0;\n\t\t}\n\t}\n\tprint(count);\n}\n\nmain();\n"}, {"source_code": "var tmp = readline().split(' ');\nvar t = parseInt(tmp[1]);\nvar c = parseInt(tmp[2]);\nvar items = readline().split(' ');\nvar answ = 0, size = 0;\n\nfor( var i = 0; i < items.length; ++i) {\n if (parseInt(items[i]) <= t ) {\n size++;\n } else {\n if(size >= c){\n answ += 1 + size - c;\n }\n size = 0;\n }\n}\n\nif(size >= c) answ += 1 + size - c;\n\nprint(answ);\n\n"}, {"source_code": "var tok = null;\nvar index = 0;\nfunction next() {\n while (tok == null || index == tok.length) {\n tok = readline().split(' ');\n index = 0;\n }\n var res = tok[index++];\n return res;\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nfunction main() {\n var n;\n var t;\n var c;\n n = nextInt();\n t = nextInt();\n c = nextInt();\n var pre = 0;\n var result = 0;\n for (var i = 0; i < n; i++) {\n var x = nextInt();\n if (x > t) {\n if (i - pre >= c) {\n result += (i - pre + 1 - c);\n }\n pre = i + 1;\n }\n }\n if(n-pre>=c){\n result += (n - pre + 1 - c);\n }\n print(result);\n}\n\nmain();"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToNumberArray = function lineToNumberArray(str) {\n return str.split(\" \").map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 3),\n n = _readNumbersLine2[0],\n t = _readNumbersLine2[1],\n c = _readNumbersLine2[2];\n\nvar arr = readNumbersLine();\nvar lastTOver = -1;\nvar res = 0;\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = arr.entries()[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _ref = _step.value;\n\n var _ref2 = _slicedToArray(_ref, 2);\n\n var key = _ref2[0];\n var value = _ref2[1];\n\n if (value > t) lastTOver = key;\n if (key - lastTOver >= c) res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);\n"}], "negative_code": [{"source_code": "var tmp = readline().split(' ');\nvar t = parseInt(tmp[1]);\nvar c = parseInt(tmp[2]);\nvar items = readline().split(' ');\nvar answ = 0, size = 0;\n\nfor( var i = 0; i < items.length; ++i) {\n if (parseInt(items[i]) <= t ) {\n size++;\n } else if(size >= c){\n answ += 1 + size - c;\n size = 0;\n }\n}\n\nif(size >= c) answ += 1 + size - c;\n\nprint(answ);\n\n"}, {"source_code": "var tmp = readline().split(' ');\nvar t = parseInt(tmp[1]);\nvar c = parseInt(tmp[2]);\nvar items = readline().split(' ');\nvar answ = 0, size = 0;\n\nfor( var i = 0; i < items.length; ++i) {\n if (parseInt(items[i]) <= t ) {\n size++;\n } else {\n answ += 1 + size - c;\n size = 0;\n }\n}\n\nansw += 1 + size - c;\n\nprint(answ);\n\n"}, {"source_code": "(function() {\n var s = readline().split(' ');\n var n = parseInt(s[0]);\n var t = parseInt(s[1]);\n var c = parseInt(s[2]);\n s = readline().split(' ');\n var i, a = [-1];\n for(i = 0 ; i < n ; ++i){\n if ( parseInt(s[i]) > t ){\n a.push(i);\n }\n }\n a.push(n);\n var diff, result = 0;\n for(i = 1 ; i < s.length ; ++i){\n diff = a[i] - a[i-1] + 1;\n result += Math.max(diff-parseInt(c)+1,0);\n }\n print(result);\n})();\n"}], "src_uid": "7d1e8769a6b1d5c6680ab530d19e7fa4"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const max = Math.max(...a.flat());\r\n let r = 0,\r\n c = 0;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if (max === a[i][j]) {\r\n r = Math.max(i + 1, n - i);\r\n c = Math.max(j + 1, m - j);\r\n return r * c;\r\n }\r\n }\r\n }\r\n return -1;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #801 (Div. 2) and EPIC Institute of Technology Round\n2022-06-18\n\nA. Subrectangle Guess\n***/\n\nfunction main() {\n var t = readline();\n t = parseInt(t);\n for (let i = 0; i < t; i++) {\n let dim_in = readline();\n dim_in = dim_in.split(\" \");\n dim_in = dim_in.map((k) => parseInt(k));\n const n = parseInt(dim_in[0]);\n const m = parseInt(dim_in[1]);\n\n let cur_max = -1e10;\n let max_row, max_col;\n\n // Strategy: find the max value and return the largest area of\n // the rectangle between that location and a corner\n for (let row = 0; row < n; row++) {\n let cur_row = readline();\n cur_row = cur_row.split(\" \");\n cur_row = cur_row.map((k) => parseInt(k));\n for (let col = 0; col < m; col++) {\n if (cur_row[col] > cur_max) {\n cur_max = cur_row[col];\n max_row = row;\n max_col = col;\n }\n }\n }\n\n console.log(\n Math.max(\n (max_row + 1) * (max_col + 1),\n (max_row + 1) * (m - max_col),\n (n - max_row) * (max_col + 1),\n (n - max_row) * (m - max_col)\n )\n );\n }\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n\r\n let max = -Infinity;\r\n let maxN = -1;\r\n let maxM = -1;\r\n for (let j = 0; j < n; j++) {\r\n let row = readline().split(' ').map(Number);\r\n for (let k = 0; k < m; k++) {\r\n if (row[k] > max) {\r\n max = row[k];\r\n maxN = j + 1;\r\n maxM = k + 1;\r\n }\r\n }\r\n }\r\n \r\n let offsetN = Math.max(Math.abs(n - maxN + 1), maxN);\r\n let offsetM = Math.max(Math.abs(m - maxM + 1), maxM);\r\n\r\n output(offsetN * offsetM);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n var t = parseInt(readline());\r\n \r\n for (let i = 0; i < t; i++) {\r\n var x = readline().split(' ');\r\n var n = parseInt(x[0]);\r\n var m = parseInt(x[1]);\r\n \r\n var a = [];\r\n var I = 0, J = 0, maxf = Number.NEGATIVE_INFINITY;\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ');\r\n var max = Number.NEGATIVE_INFINITY;\r\n var J_ = 0;\r\n for (let k = 0; k < m; k++) {\r\n a[j][k] = parseInt(a[j][k]);\r\n if (max < a[j][k]) {\r\n max = a[j][k];\r\n J_ = k;\r\n }\r\n }\r\n \r\n if (max > maxf) {\r\n maxf = max;\r\n I = j;\r\n J = J_;\r\n }\r\n }\r\n \r\n var h = Math.max(I+1, n-I);\r\n var w = Math.max(J+1, m-J);\r\n \r\n console.log(h*w);\r\n }\r\n}\r\n \r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var x = readline().split(' ');\r\n var n = parseInt(x[0]);\r\n var m = parseInt(x[1]);\r\n \r\n var a = [];\r\n var I = 0, J = 0, maxf = 0;\r\n for (let j = 0; j < n; j++) {\r\n a[j] = readline().split(' ');\r\n var max = 0;\r\n var J_ = 0;\r\n for (let k = 0; k < m; k++) {\r\n a[j][k] = parseInt(a[j][k]);\r\n if (max < a[j][k]) {\r\n max = a[j][k];\r\n J_ = k;\r\n }\r\n }\r\n\r\n if (max > maxf) {\r\n maxf = max;\r\n I = j;\r\n J = J_;\r\n }\r\n }\r\n\r\n var h = Math.max(I+1, n-I);\r\n var w = Math.max(J+1, m-J);\r\n\r\n console.log(h*w);\r\n }\r\n}"}], "src_uid": "47e5ccd8220afa84c95f36b08ed1817a"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (const x of b) {\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tconst d = n*(n+1)/2\r\n\t\tif (sm%d) {\r\n\t\t\tconsole.log('NO');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tsm /= d;\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;\r\n\t\t\tif (ans[i] <= 0 || ans[i]%1) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var a = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var ans = [];\r\n var total = 0;\r\n for (var i = 0; i < n; i++) {\r\n total += a[i];\r\n }\r\n var sum = (n * (n + 1)) / 2;\r\n if (total % sum) {\r\n print(\"NO\");\r\n return;\r\n }\r\n total /= sum;\r\n for (var i = 0; i < n; i++) {\r\n var diff = a[i] - a[(n - 1 + i) % n];\r\n diff = total - diff;\r\n if (diff <= 0 || diff % n) {\r\n print(\"NO\");\r\n return;\r\n }\r\n diff /= n;\r\n ans[i] = diff;\r\n }\r\n print(\"YES\");\r\n var an = \"\";\r\n for (var i of ans) {\r\n an += i + \" \";\r\n }\r\n print(an);\r\n }\r\n\r\n while (t--) {\r\n solve();\r\n }"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const res = [];\r\n let sum = a.reduce((a, b) => a + b, 0);\r\n if (sum % (n * (n + 1) / 2) !== 0) return 'NO';\r\n sum /= n * (n + 1) / 2;\r\n for (let i = 0; i < n; i++) {\r\n res[i] = sum - (a[i] - a[(i - 1 + n) % n]);\r\n if (res[i] % n !== 0) return 'NO';\r\n if (res[i] <= 0) return 'NO';\r\n res[i] /= n;\r\n }\r\n return `YES\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\n\nfunction matprint(mat) {\n let shape = [mat.length, mat[0].length];\n function col(mat, i) {\n return mat.map((row) => row[i]);\n }\n let colMaxes = [];\n for (let i = 0; i < shape[1]; i++) {\n colMaxes.push(\n Math.max.apply(\n null,\n col(mat, i).map((n) => n.toString().length)\n )\n );\n }\n\n mat.forEach((row) => {\n console.log.apply(\n null,\n row.map((val, j) => {\n return new Array(colMaxes[j] - val.toString().length + 1).join(\" \") + val.toString() + \" \";\n })\n );\n });\n}\n\nconst nQueues = this.readline().split(\" \");\n\n// For this problem we will apply Gauss elimination algorithm\n\nfor (let i = 0; i < nQueues; i++) {\n const n = Number(this.readline());\n const minutes = this.readline()\n .split(\" \")\n .map((e) => Number(e));\n const sum = minutes.reduce((prev, curr) => prev + curr, 0);\n const totalRep = (n * (n + 1)) / 2;\n \n if (sum % totalRep) {\n this.print(\"NO\");\n continue;\n }\n\n const ans = new Array(n);\n\n let fail = false;\n for (let x = 0; x < n; x++) {\n ans[x] = (minutes[(n - 1 + x) % n] - minutes[x] + sum / totalRep) / n;\n\n if (ans[x] <= 0 || Math.abs(ans[x] - Math.round(ans[x])) > 0.0000001) {\n this.print(\"NO\");\n fail = true;\n break;\n }\n }\n\n if (!fail) {\n this.print(\"YES\");\n this.print(ans.join(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (const x of b) {\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tconst d = n*(n+1)/2\r\n\t\tif (sm%d) {\r\n\t\t\tconsole.log('NO');\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tsm /= d;\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;\r\n\t\t\tif (ans[i] <= 0) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (const x of b) {\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tconst d = n*(n+1)/2\r\n\t\tif (sm%d) {\r\n\t\t\tconsole.log('NO');\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tsm /= d;\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;\r\n\t\t\tif (ans[i] <= 0 || ans[i] > n) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (const x of b) {\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tsm = 2*sm/(n*(n+1));\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;\r\n\t\t\tif (ans[i] <= 0 || ans[i] > n) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst b = rna();\r\n\r\n\t\tlet sm = 0;\r\n\t\tfor (const x of b) {\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tsm = 2*sm/(n*(n+1));\r\n\r\n\t\tlet ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;\r\n\t\t\tif (ans[i] == 0) {\r\n\t\t\t\tans = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES\\n' + ans.join(' ') : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\n\nfunction matprint(mat) {\n let shape = [mat.length, mat[0].length];\n function col(mat, i) {\n return mat.map((row) => row[i]);\n }\n let colMaxes = [];\n for (let i = 0; i < shape[1]; i++) {\n colMaxes.push(\n Math.max.apply(\n null,\n col(mat, i).map((n) => n.toString().length)\n )\n );\n }\n\n mat.forEach((row) => {\n console.log.apply(\n null,\n row.map((val, j) => {\n return new Array(colMaxes[j] - val.toString().length + 1).join(\" \") + val.toString() + \" \";\n })\n );\n });\n}\n\nconst nQueues = this.readline().split(\" \");\n\n// For this problem we will apply Gauss elimination algorithm\n\nfor (let i = 0; i < nQueues; i++) {\n const n = Number(this.readline());\n const minutes = this.readline()\n .split(\" \")\n .map((e) => Number(e));\n\n const matrix = [];\n /* generate matrix with the coefficient of the repertoire for each singer\n * For 6 cities, it'll look like this:\n 1 6 5 4 3 2 81 \n 2 1 6 5 4 3 75 \n 3 2 1 6 5 4 75 \n 4 3 2 1 6 5 93 \n 5 4 3 2 1 6 93 \n 6 5 4 3 2 1 87 \n */\n for (let city = 0; city < n; city++) {\n matrix[city] = [];\n for (let singer = 0; singer < n; singer++) {\n matrix[city][singer] = 1 + ((city + (n - singer)) % n);\n }\n matrix[city].push(minutes[city]);\n }\n\n /* Now, we will get the matrix to echelon form, that is, something like this\n 1 6 5 4 3 2 81 \n 0 1 0.36363636363636365 0.2727272727272727 0.18181818181818182 0.09090909090909091 7.909090909090909 \n 0 0 1 0.2 0.1333333333333333 0.06666666666666671 5.0666666666666655 \n 0 0 0 1 0.1111111111111111 0.055555555555555476 1.7222222222222239 \n 0 0 0 0 1 0.05000000000000005 4.249999999999998 \n 0 0 0 0 0 1 5.0000000000000036 \n\n which will help us isolate each variable\n */\n for (let a = 0; a < n; a++) {\n const factor1 = matrix[a][a];\n for (let col = a; col <= n; col++) {\n matrix[a][col] = matrix[a][col] / factor1;\n }\n for (let lin = a + 1; lin < n; lin++) {\n const factor2 = matrix[lin][a];\n for (let col = a; col <= n; col++) {\n matrix[lin][col] = matrix[lin][col] / factor2 - matrix[a][col];\n }\n }\n }\n\n /* Now we start from the bottom and subtract for each equation the free variables, which will give us something like this\n (rounding is actually done later, but I've done here just for clarity)\n 1 0 0 0 0 0 5 \n 0 1 0 0 0 0 5 \n 0 0 1 0 0 0 4 \n 0 0 0 1 0 0 1 \n 0 0 0 0 1 0 4 \n 0 0 0 0 0 1 5\n\n Which makes it trivial to find the values of each variable\n */\n for (let a = n - 1; a >= 0; a--) {\n for (let lin = a - 1; lin >= 0; lin--) {\n const factor = matrix[lin][a];\n for (let col = n; col >= a; col--) {\n matrix[lin][col] = matrix[lin][col] - factor * matrix[a][col];\n }\n }\n }\n\n const vars = [];\n for (let a = 0; a < n; a++) {\n if (matrix[a][n] <= 0) {\n // repertoires must have positive duration\n this.print(\"NO\");\n break;\n }\n if (matrix[a][n] - Math.round(matrix[a][n]) > 0.000001) {\n // not an integer\n this.print(\"NO\");\n break;\n }\n vars.push(Math.round(matrix[a][n]));\n }\n if (vars.length === n) {\n this.print(\"YES\");\n this.print(vars.join(\" \"));\n }\n}\n"}, {"source_code": "\"use strict\";\n\nfunction matprint(mat) {\n let shape = [mat.length, mat[0].length];\n function col(mat, i) {\n return mat.map((row) => row[i]);\n }\n let colMaxes = [];\n for (let i = 0; i < shape[1]; i++) {\n colMaxes.push(\n Math.max.apply(\n null,\n col(mat, i).map((n) => n.toString().length)\n )\n );\n }\n\n mat.forEach((row) => {\n console.log.apply(\n null,\n row.map((val, j) => {\n return new Array(colMaxes[j] - val.toString().length + 1).join(\" \") + val.toString() + \" \";\n })\n );\n });\n}\n\nconst nQueues = this.readline().split(\" \");\n\n// For this problem we will apply Gauss elimination algorithm\n\nfor (let i = 0; i < nQueues; i++) {\n const n = Number(this.readline());\n const minutes = this.readline()\n .split(\" \")\n .map((e) => Number(e));\n\n const matrix = [];\n /* generate matrix with the coefficient of the repertoire for each singer\n * For 6 cities, it'll look like this:\n 1 6 5 4 3 2 81 \n 2 1 6 5 4 3 75 \n 3 2 1 6 5 4 75 \n 4 3 2 1 6 5 93 \n 5 4 3 2 1 6 93 \n 6 5 4 3 2 1 87 \n */\n for (let city = 0; city < n; city++) {\n matrix[city] = [];\n for (let singer = 0; singer < n; singer++) {\n matrix[city][singer] = 1 + ((city + (n - singer)) % n);\n }\n matrix[city].push(minutes[city]);\n }\n\n /* Now, we will get the matrix to echelon form, that is, something like this\n 1 6 5 4 3 2 81 \n 0 1 0.36363636363636365 0.2727272727272727 0.18181818181818182 0.09090909090909091 7.909090909090909 \n 0 0 1 0.2 0.1333333333333333 0.06666666666666671 5.0666666666666655 \n 0 0 0 1 0.1111111111111111 0.055555555555555476 1.7222222222222239 \n 0 0 0 0 1 0.05000000000000005 4.249999999999998 \n 0 0 0 0 0 1 5.0000000000000036 \n\n which will help us isolate each variable\n */\n for (let a = 0; a < n; a++) {\n const factor1 = matrix[a][a];\n for (let col = a; col <= n; col++) {\n matrix[a][col] = matrix[a][col] / factor1;\n }\n for (let lin = a + 1; lin < n; lin++) {\n const factor2 = matrix[lin][a];\n for (let col = a; col <= n; col++) {\n matrix[lin][col] = matrix[lin][col] / factor2 - matrix[a][col];\n }\n }\n }\n\n /* Now we start from the bottom and subtract for each equation the free variables, which will give us something like this\n (rounding is actually done later, but I've done here just for clarity)\n 1 0 0 0 0 0 5 \n 0 1 0 0 0 0 5 \n 0 0 1 0 0 0 4 \n 0 0 0 1 0 0 1 \n 0 0 0 0 1 0 4 \n 0 0 0 0 0 1 5\n\n Which makes it trivial to find the values of each variable\n */\n for (let a = n - 1; a >= 0; a--) {\n for (let lin = a - 1; lin >= 0; lin--) {\n const factor = matrix[lin][a];\n for (let col = n; col >= a; col--) {\n matrix[lin][col] = matrix[lin][col] - factor * matrix[a][col];\n }\n }\n }\n\n const vars = [];\n for (let a = 0; a < n; a++) {\n if (matrix[a][n] <= 0) {\n // repertoires must have positive duration\n this.print(\"NO\");\n break;\n }\n if (matrix[a][n] - Math.round(matrix[a][n]) > 0.1) {\n // not an integer\n this.print(\"NO\");\n break;\n }\n vars.push(Math.round(matrix[a][n]));\n }\n if (vars.length === n) {\n this.print(\"YES\");\n this.print(vars.join(\" \"));\n }\n}\n"}, {"source_code": "\"use strict\";\n\nfunction matprint(mat) {\n let shape = [mat.length, mat[0].length];\n function col(mat, i) {\n return mat.map((row) => row[i]);\n }\n let colMaxes = [];\n for (let i = 0; i < shape[1]; i++) {\n colMaxes.push(\n Math.max.apply(\n null,\n col(mat, i).map((n) => n.toString().length)\n )\n );\n }\n\n mat.forEach((row) => {\n console.log.apply(\n null,\n row.map((val, j) => {\n return new Array(colMaxes[j] - val.toString().length + 1).join(\" \") + val.toString() + \" \";\n })\n );\n });\n}\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const n = Number(this.readline());\n const minutes = this.readline()\n .split(\" \")\n .map((e) => Number(e));\n\n const matrix = [];\n for (let city = 0; city < n; city++) {\n matrix[city] = [];\n for (let singer = 0; singer < n; singer++) {\n matrix[city][singer] = 1 + ((city + (n - singer)) % n);\n }\n matrix[city].push(minutes[city]);\n }\n\n for (let a = 0; a < n; a++) {\n const f1 = matrix[a][a];\n for (let col = a; col <= n; col++) {\n matrix[a][col] = matrix[a][col] / f1;\n }\n for (let lin = a + 1; lin < n; lin++) {\n const f2 = matrix[lin][a];\n for (let col = a; col <= n; col++) {\n matrix[lin][col] = matrix[lin][col] - f2 * matrix[a][col];\n }\n }\n }\n\n for (let a = n - 1; a >= 0; a--) {\n for (let lin = a - 1; lin >= 0; lin--) {\n const fator = matrix[lin][a];\n for (let col = n; col >= a; col--) {\n matrix[lin][col] = matrix[lin][col] - fator * matrix[a][col];\n }\n }\n }\n\n const vars = [];\n for (let a = 0; a < n; a++) {\n if (matrix[a][n] <= 0) {\n this.print(\"NO\");\n break;\n }\n vars.push(Math.round(matrix[a][n]));\n }\n if (vars.length === n) {\n this.print(\"YES\");\n this.print(vars.join(\" \"));\n }\n}\n"}], "src_uid": "21fed74be8462143d77bbbee48dc8a12"} {"source_code": ";(function () {\n\n\tprint((+readline().slice(-2)) % 4 ? 0 : 4);\n\n}).call(this);", "positive_code": [{"source_code": ";(function () {\n\n\tprint(((+readline().slice(-2)) % 4 ? 10 : 4) % 5);\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar s = trim(readline()),\n\t\tn = parseInt(s.substring(s.length-2)),\n\t\ttwo = [1, 2, 4, 3][n%4],\n\t\tthree = [1, 3, 4, 2][n%4],\n\t\tfour = [1, 4][n%2];\n\tprint((1 + two + three + four) % 5);\n}\n\nmain();\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint((1 + (+readline().slice(-2)) % 4 ? 9 : 3) % 5);\n\n}).call(this);\n"}], "src_uid": "74cbcbafbffc363137a02697952a8539"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// cat input.txt | node script.js > output.txt\r\n// Number.parseInt(string)\r\nfunction main() {\r\n let t = Number.parseInt(readline()), n, s, d, alphabet, suspicious;\r\n while(t--) {\r\n n = Number.parseInt(readline());\r\n s = readline();\r\n d = s.substr(0, 1);\r\n for(let i = 1; i < n; ++i) {\r\n if(s.substr(i, 1) !== s.substr(i - 1, 1)) d += s.substr(i, 1);\r\n }\r\n alphabet = {};\r\n suspicious = false;\r\n for(let i = 0; i < d.length; ++i) {\r\n if(alphabet.hasOwnProperty(d[i])) {\r\n suspicious = true;\r\n } else {\r\n alphabet[d[i]] = true;\r\n }\r\n }\r\n suspicious ? console.log('NO') : console.log('YES');\r\n }\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', input => inputString += input);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n});\n\nfunction print(message) {\n console.log(message);\n}\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction readLineNumber(parse = parseInt) {\n return parse(readLine());\n}\n\nfunction main() {\n // 1 <= t <= 1000\n const tests = readLineNumber();\n\n for (let t = 0; t < tests; t++) {\n // 1 <= n <= 50\n const days = readLineNumber();\n const string = readLine();\n const questions = {};\n let isRight = true;\n\n for (let d = 0; d < days; d++) {\n let letter = string[d];\n\n if(questions.hasOwnProperty(letter)) {\n if(d - questions[letter] > 1) {\n print(\"NO\");\n isRight = false;\n break;\n }\n questions[letter] = d;\n } else {\n questions[letter] = d;\n }\n }\n\n if(isRight) {\n print(\"YES\");\n }\n }\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', input => inputString += input);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const quantidadeTestes = parseInt(readline());\n\n for (let i = 0; i < quantidadeTestes; i++) {\n const tamanhoString = parseInt(readline());\n const string = readline();\n const questoes = {};\n let fezCerto = true;\n\n for (let l = 0; l < tamanhoString; l++) {\n let letra = string[l];\n\n if(questoes.hasOwnProperty(letra)) {\n if(l - questoes[letra] > 1) {\n console.log(\"NO\");\n fezCerto = false;\n break;\n }\n questoes[letra] = l;\n } else {\n questoes[letra] = l;\n }\n }\n\n if(fezCerto) {\n console.log(\"YES\");\n }\n }\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n\tinputString = inputString.trim().split('\\n').map(string => {\r\n\t\treturn string.trim();\r\n\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readline() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\tvar t = readline();\r\n\tlet count = 1;\r\n\twhile (count <= t) {\r\n\t\tlet n = readline()\r\n\t\tvar stringArray = Array.from(readline());\r\n\t\tvar b = stringArray.filter(function (item, pos, arr) {\r\n\t\t\treturn pos === 0 || item !== arr[pos - 1];\r\n\t\t});\r\n\t\tconst hasDuplicates = arr => arr.some((item, index) => arr.indexOf(item) !== index)\r\n\t\tif (hasDuplicates(b)) {\r\n\t\t\tconsole.log(\"NO\")\r\n\t\t}\r\n\t\telse {\r\n\t\t\tconsole.log(\"YES\")\r\n\r\n\t\t}\r\n\t\t// console.log(results)\r\n\r\n\r\n\r\n\t\tcount++\r\n\t}\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction prcessString(st=\"\"){\r\n const objMap = {};\r\n let lastChar = st[0];\r\n objMap[st[0]]=true;\r\n for(let i=0;ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction prcessString(st=\"\"){\r\n const objMap = {};\r\n let lastChar = st[0];\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\tlet s = readLine();\r\n\t\t// console.log(n,s);\r\n\t\tif (!solve(n, s)) console.log(\"NO\");\r\n\t\telse console.log(\"YES\");\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n, s) {\r\n\tlet flag = true;\r\n\tlet visited = new Set();\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif(visited.has(s[i]) && s[i] !== s[i-1]) {\r\n\t\t\tflag = false;\r\n\t\t\tbreak;\r\n\t\t} else {\r\n\t\t\tvisited.add(s[i]);\r\n\t\t}\r\n\t}\r\n\treturn flag;\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "/**\r\n * Bismillahir Rahmanir Rahim\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n */\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n \r\n let inputString = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\tlet s = readLine();\r\n\t\t// console.log(n,s);\r\n\t\tif (!solve(n, s)) console.log(\"NO\");\r\n\t\telse console.log(\"YES\");\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n, s) {\r\n\tlet table = {};\r\n\tfor (let i = 0; i < 26; i++) {\r\n\t\ttable[String.fromCharCode(65+i)] = false;\r\n\t}\r\n\tlet flag = true;\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (!i) {\r\n\t\t\ttable[s[i]] = true;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(s[i]==s[i-1] && table[s[i]]) {\r\n\t\t\tcontinue;\r\n\t\t} else if(s[i]!=s[i-1] && !table[s[i]]) {\r\n\t\t\ttable[s[i]] = true;\r\n\t\t} else if(s[i]!=s[i-1] && table[s[i]]) {\r\n\t\t\tflag = false;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn flag;\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const cases = parseInt(lines[0]);\r\n \r\n let prevLetter;\r\n let on = true;\r\n for (let i = 1; i < cases * 2 + 5; i++) {\r\n const line = lines[i];\r\n if (!line) return;\r\n if (!on) {\r\n const allChars = [...line].map(t => t.trim());\r\n const found = [];\r\n \r\n const duplicate = allChars.find((char, index) => {\r\n if (!found.includes(char)) {\r\n found.push(char);\r\n } else if (allChars[index - 1] !== char) {\r\n return true;\r\n }\r\n });\r\n \r\n console.log(duplicate ? 'NO' : 'YES');\r\n }\r\n \r\n on = !on;\r\n }\r\n});"}, {"source_code": "const solve = (letter) => {\r\n const tasks = letter.split('');\r\n const visited = new Set();\r\n let last_visited_work = '';\r\n \r\n for (let i = 0; i < tasks.length; i += 1) {\r\n if (tasks[i] !== last_visited_work) {\r\n if (visited.has(tasks[i])) {\r\n return 'NO';\r\n } else {\r\n last_visited_work = tasks[i];\r\n visited.add(tasks[i]);\r\n }\r\n }\r\n }\r\n return 'YES';\r\n};\r\n \r\n \r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n const lines = input.trim().split('\\n').slice(1)\r\n .map(l => l.trim());\r\n \r\n for (let i=1; i {\r\n const tasks = letter.split('');\r\n const visited = new Set();\r\n let flag = true;\r\n\r\n for (let i = 0; i < tasks.length; i += 1) {\r\n if (visited.has(tasks[i]) && tasks[i - 1] !== tasks[i]) {\r\n flag = false;\r\n break;\r\n }\r\n visited.add(tasks[i]);\r\n }\r\n return flag ? 'YES' : 'NO';\r\n};\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const lines = input.trim().split('\\n').slice(1)\r\n .map((l) => l.trim());\r\n\r\n for (let i = 1; i < lines.length; i += 2) {\r\n console.log(solve(lines[i]));\r\n }\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet initialized=false,\r\n cache = [];\r\n\r\nfunction fairWork(inp){\r\n cache.push(inp);\r\n\r\n if(cache.length === 2){\r\n\r\n for(let i=0, repeats={}; i {\r\n if(initialized){ fairWork(input) }\r\n else initialized = true\r\n});"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n const n = parseInt(readLine());\r\n const s = readLine();\r\n a(n,s);\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction a(n,s)\r\n{\r\n let last = '';\r\n let solved = '';\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(s[i] !== last && solved.includes(s[i]))\r\n {\r\n return console.log('NO');\r\n }\r\n solved += s[i];\r\n last = s[i];\r\n }\r\n return print('YES');\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar currentLine = 0;\r\nvar inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (var m = 0; m < t; m++) {\r\n var n = +input();\r\n var str = input().split(\"\");\r\n var newStr = [];\r\n\r\n // var j = 0;\r\n for (var i = 0; i <= str.length - 1; i++) {\r\n if (str[i] != str[i + 1]) {\r\n newStr.push(str[i]);\r\n }\r\n }\r\n\r\n var isNo = false;\r\n\r\n for (var j = 0; j < newStr.length; j++) {\r\n for (var k = j + 1; k < newStr.length; k++) {\r\n if (newStr[j] == newStr[k]) {\r\n console.log(\"NO\");\r\n isNo = true;\r\n break;\r\n }\r\n if (isNo) {\r\n break;\r\n }\r\n }\r\n }\r\n if (!isNo) {\r\n console.log(\"YES\");\r\n }\r\n // console.log(newStr);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar currentLine = 0;\r\nvar inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/******** Main function *************/\r\n\r\nfunction main() {\r\n const t = +input();\r\n\r\n for (var m = 0; m < t; m++) {\r\n var n = +input();\r\n var str = input().split(\"\");\r\n var newStr = [];\r\n\r\n var j = 0;\r\n for (var i = 0; i <= str.length - 1; i++) {\r\n if (str[i] != str[i + 1]) {\r\n newStr.push(str[i]);\r\n }\r\n }\r\n\r\n var isNo = false;\r\n\r\n for (var j = 0; j < newStr.length; j++) {\r\n for (var k = j + 1; k < newStr.length; k++) {\r\n if (newStr[j] == newStr[k]) {\r\n console.log(\"NO\");\r\n isNo = true;\r\n break;\r\n }\r\n if (isNo) {\r\n break;\r\n }\r\n }\r\n }\r\n if (!isNo) {\r\n console.log(\"YES\");\r\n }\r\n // console.log(newStr);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 !== 0) {\n c++;\n return;\n }\n\n const letters = d.split(\"\");\n const prevLetters = {};\n prevLetters[letters[0]] = true;\n let ans = \"YES\";\n let prev = letters[0];\n for (let i = 1; i < letters.length; i++) {\n if (prev !== letters[i] && prevLetters.hasOwnProperty(letters[i])) {\n ans = \"NO\";\n break;\n }\n\n prev = letters[i];\n prevLetters[letters[i]] = true;\n }\n\n console.log(ans);\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n \r\n let n = 0\r\n let arr = []\r\n let str = ''\r\n \r\n // let nums = generateUptoNwithoutK(1000, 3)\r\n \r\n // with testcases\r\n //* \r\n let t = parseInt( readline() ) \r\n while (t--) {\r\n n = parseInt( readline() )\r\n // arr = readline().split(' ').map(Number)\r\n str = readline()\r\n console.log( solve(n, arr, str) )\r\n } \r\n //*/\r\n\r\n // without testcases\r\n /* \r\n n = parseInt( readline() )\r\n arr = readline().split(' ').map(Number)\r\n // str = readline()\r\n console.log( solve(n, arr, str) )\r\n //*/\r\n}\r\n// Driver Function Ends //\r\n\r\n\r\n// MAIN LOGIC\r\nconst solve = (n, arr, str) => { \r\n \r\n let task = []\r\n let uniq = findUnique( str ).split('')\r\n\r\n for( let u of uniq ) {\r\n task[u] = findAllIndicesOfChar(str, u) \r\n }\r\n\r\n for( let t in task ) {\r\n let diff = 0\r\n let i = 0\r\n while( i < task[t].length - 1 ) {\r\n diff = Math.abs( task[t][i] - task[t][i+1] )\r\n if( diff > 1 ) return 'NO'\r\n i++\r\n }\r\n }\r\n \r\n return 'YES'\r\n}\r\n\r\nconst generateUptoNwithoutK = (n, k) => {\r\n let a = [], i = 1\r\n while( a.length <= n ){\r\n // if( i%k != 0 && !stringHasCharacter(i.toString(), k ) ) a.push( i )\r\n if( i%k != 0 && i%10 != k ) a.push( i )\r\n i++\r\n }\r\n return a\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sortArrayDesc = (arr) => arr.sort( (a, b) => b - a )\r\nconst isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\nconst splitAt = index => x => [x.slice(0, index), x.slice(index)]\r\nconst elemFrequency = (arr) => arr.reduce( (acc, curr) => { return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc }, {}) \r\nconst deepCopyArray = (arr) => arr.map(a => ({...a}))\r\n\r\nconst reverseText = (str) => str.split('').reverse().join('')\r\nconst stringHasDuplicates = (str) => (/([a-z])\\1/i).test(str)\r\nconst stringHasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)\r\nconst stringHasCharacter = (str, char) => str.indexOf(char) > -1 ? true : false\r\n\r\nconst findAllIndicesOfChar = (str, char) => {\r\n str = str.split('')\r\n let indices = [];\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] === char) indices.push(i);\r\n }\r\n return indices\r\n}\r\n\r\nconst isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)\r\nconst escapeRegExp = (string) => string.replace(/[.*+\\-?^$$${}()|[\\]\\\\]/g, '\\\\$$$&')\r\nconst replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\r\n\r\nconst findUnique = (str) => {\r\n return [...str].reduce((acc, curr) => {\r\n return acc.includes(curr) ? acc : acc + curr;\r\n }, \"\")\r\n}\r\n\r\nconst unique = (str) => {\r\n const cleanStr = str.replace(/ /gi, '');\r\n const set = [...new Set(cleanStr)];\r\n return set;\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst seen = new Set([s[0]]);\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 1; ok && i < n; i++) {\r\n\t\t\tif (s[i] != s[i-1]) {\r\n\t\t\t\tok = !seen.has(s[i]);\r\n\t\t\t\tseen.add(s[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var n = lines[0];\n var m = '';\n var l = '';\n for(var j = 1; j < (Number(n) + 1) * 2; j++){\n var sus = false;\n if(j % 2 == 1){\n m = Number(lines[j]);\n }else if(j % 2 === 0){\n var lastSeen =new Map();\n\n l = lines[j].split('');\n for(var b = 0; b < m; b++){\n let current = l[b];\n let last = lastSeen[current];\n \n\n if(last === undefined || last == b -1){\n }else {\n sus = true;\n break;\n }\n // console.log(current, last, lastSeen, sus)\n\n lastSeen[current] = b;\n }\n if(sus === true){\n console.log('NO');\n }else{\n console.log('YES');\n }\n }\n }\n});"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', input => inputString += input);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const quantidadeTestes = parseInt(readline());\n\n for (let i = 0; i < quantidadeTestes; i++) {\n const tamanhoString = parseInt(readline());\n const string = readline();\n const questoes = {};\n let fezCerto = true;\n\n for (let l = 0; l < tamanhoString; l++) {\n let letra = string[l];\n\n if(questoes.hasOwnProperty(letra)) {\n if(l - questoes[letra] > 1) {\n console.log(\"NO\");\n fezCerto = false;\n break;\n }\n questoes[letra] = l;\n } else {\n questoes[letra] = l;\n }\n }\n\n if(fezCerto) {\n console.log(\"YES\");\n }\n }\n}\n \t\t\t\t \t\t\t\t \t \t\t \t \t \t \t"}, {"source_code": "'use strict';\r\n\r\nconst fs = require('fs');\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', function (inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', function () {\r\n inputString = inputString.split('\\n');\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction problemSolving(n, str) {\r\n var flag = false;\r\n for (let j = 0; j < str.length; j++) {\r\n for (let o = j; o < str.length - 1; o++) {\r\n\r\n if (str[o] != str[j] && str[o + 1] == str[j]) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n if (flag)\r\n console.log(\"NO\");\r\n else\r\n console.log(\"YES\");\r\n}\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readLine().trim(), 10);\r\n while (t-- > 0) {\r\n const n = parseInt(readLine().trim(), 10);\r\n const str = readLine();\r\n problemSolving(n, str);\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++){\n\t\tnl.num();\n\t\tlet s = nl.line();\n\t\tlet p = '';\n\t\tlet m = [];\n\t\ts.split('').forEach((e) => {\n\t\t\tif (e != p) {\n\t\t\t\tm.push(e);\n\t\t\t}\n\t\t\tp = e;\n\t\t});\n\t\tm.sort();\n\t\tp = '';\n\t\tlet flag = true;\n\t\tm.forEach((e) => {\n\t\t\tif (e === p) {\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t\tp = e;\n\t\t});\n\t\t\t\t\n ans.push(flag);\n }\n \n\tconsole.log(ans.map(e => e?'YES':'NO').join(\"\\n\"));\n \n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "input()\r\n//-------------------\r\n\r\nfunction input () {\r\n let i = ''\r\n process.stdin.on('data', c => i += c)\r\n process.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines);\r\n solve(lines)\r\n })\r\n\r\n}\r\n\r\nfunction solve (arr) {\r\n var d =+arr[0]\r\n \r\n for (var i =1 ;i <=d ;i++){\r\n var str =arr[2*i]\r\n \r\n console.log(test(str))\r\n \r\n }\r\n\r\n\r\n}\r\n\r\n\r\nfunction test(str){\r\n var mas =[\"_\"]\r\n \r\n for (var c of str){\r\n if (c == mas[mas.length-1]) continue;\r\n \r\n if (mas.includes(c)){\r\n return \"NO\"\r\n }else {\r\n mas.push (c)\r\n }\r\n \r\n }\r\n return \"YES\"\r\n \r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main() {\r\n const test= readline();\r\n let a;\r\n for(let i=0;i {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var b = 1;\r\n for (var a = 0; a < t; a++) {\r\n var n = Number(input[b]);\r\n b++;\r\n var str = input[b];\r\n str += \" \";\r\n b++;\r\n var set = new Set();\r\n var i;\r\n for (i = 1; i < str.length; i++) {\r\n if (str[i] !== str[i - 1]) {\r\n set.add(str[i - 1]);\r\n }\r\n if (set.has(str[i])) {\r\n console.log(\"NO\");\r\n break;\r\n }\r\n }\r\n if (i === str.length) {\r\n console.log(\"YES\");\r\n }\r\n }\r\n})"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input : process.stdin,\r\n output : process.stdout\r\n});\r\nlet data = [];\r\nlet dataIdx = 0;\r\n\r\nrl.on('line',function(line){//input,\r\n data.push(...line.trim().split(' '));\r\n}).on('close',function(){//output\r\n main();\r\n process.exit();\r\n})\r\n\r\nfunction input(){\r\n return data[dataIdx++];\r\n}\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nfunction main(){\r\n let t = Number(input());\r\n while(t-->0){\r\n let ma = Object();\r\n let n = Number(input());\r\n let s = input();\r\n let ans = true;\r\n for(let i=0;i {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n///////////////////////// END BASIC IO STREAM TEMPLATE //////////////////////\r\n\r\nfunction main() {\r\n let t = readLine(Number);\r\n while (t--) {\r\n let n = readLine(Number);\r\n let str = readLine().split(\"\");\r\n const alphaMap = {};\r\n let result = true;\r\n for (let i = 0; i < n; i++) {\r\n if (alphaMap[str[i]] || alphaMap[str[i]] == 0) {\r\n if (str[i - 1] != str[i]) {\r\n result = false;\r\n break;\r\n } else {\r\n alphaMap[str[i]] = i;\r\n }\r\n } else {\r\n alphaMap[str[i]] = i;\r\n }\r\n }\r\n if (result) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction solve()\n{\n let num_of_elements = readline(); \n let elements = readline();\n let seen_map = new Map();\n let ch_change =false;\n seen_map.set(elements[0],1)\n for(let i=1;i {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n const solved = new Array(500).fill(0)\r\n solved[arr[0].charCodeAt(0)] = 1\r\n for (let i = 1; i < n; i++) {\r\n if (solved[arr[i].charCodeAt(0)] !== 0) {\r\n if (arr[i] === arr[i - 1]) solved[arr[i].charCodeAt(0)] = 1\r\n else {\r\n console.log('NO')\r\n return\r\n }\r\n } else solved[arr[i].charCodeAt(0)] = 1\r\n\r\n }\r\n console.log('YES')\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "function solve(S, N) {\r\n const hash = {};\r\n for (let i = 0; i < N; i++) {\r\n const ch = S[i];\r\n if (hash[ch] === undefined) {\r\n hash[ch] = ch;\r\n continue;\r\n } else {\r\n if (S[i - 1] != S[i]) {\r\n return false;\r\n }\r\n hash[ch] = ch;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction processData(input) {\r\n //Enter your code here\r\n input = input.split('\\n');\r\n const T = Number(input[0].trim());\r\n let i = 1;\r\n for (let t = 0; t < T; t++) {\r\n const N = Number(input[i++].trim());\r\n const S = input[i++].trim();\r\n const ans = solve(S, N);\r\n console.log(ans ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n_input = \"\";\r\nprocess.stdin.on(\"data\", function (input) {\r\n _input += input;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n processData(_input);\r\n});\r\n\r\n"}, {"source_code": "\r\nconst solve = (line) => {\r\n\tconst tasks = line.split('');\r\n\r\n\tconst set = new Set();\r\n\tlet flag = true;\r\n\tfor (let i=0; i input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1)\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=1; i {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tlet flag = true;\n\t\tconst str = readLine();\n\t\tconst visited = new Set();\n\t\tconst stack = [];\n\t\tfor (let char of str) {\n\t\t\tconst stackTop = stack[stack.length - 1];\n\t\t\tif (stackTop !== char) {\n\t\t\t\tstack.push(char);\n\t\t\t\tif (visited.has(char)) {\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tvisited.add(char);\n\t\t\t}\n\t\t}\n\t\tif (!flag) console.log('NO');\n\t\telse console.log('YES');\n\t}\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/**\r\n5\r\n3\r\nABA\r\n11\r\nDDBBCCCBBEZ\r\n7\r\nFFGZZZY\r\n1\r\nZ\r\n2\r\nAB\r\n\r\n\r\n**/\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n};\r\n\r\nfunction lcm(a, b) {\r\n return (a / gcd(a, b) * b);\r\n}\r\n\r\nfunction main() { \r\n let n = Number(readline());\r\n\r\n for(let r=0;r0){\r\n var ma = Object();\r\n var n = Number(readline());\r\n var s = readline();\r\n var ans = true;\r\n for(var i=0;i 0) {\r\n print(\"NO\")\r\n } else {\r\n print(\"YES\")\r\n } \r\n}\r\n\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n function solve() {\r\n var n = parseInt(readline());\r\n var s = readline();\r\n var a = [];\r\n a[s[0].charCodeAt(0) - \"A\".charCodeAt(0)] = 1;\r\n for (var i = 1; i < n; i++) {\r\n if (s[i] == s[i - 1]) continue;\r\n else {\r\n if (a[s[i].charCodeAt(0) - \"A\".charCodeAt(0)] > 0) {\r\n return \"NO\";\r\n }\r\n a[s[i].charCodeAt(0) - \"A\".charCodeAt(0)] = 1;\r\n }\r\n }\r\n return \"YES\";\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var tests = Number(readline());\r\n\r\n\r\nfor (var i = 0; i < tests; i++) {\r\n var days = Number(readline());\r\n var str = readline();\r\n var sus = false;\r\n var arr = [];\r\n \r\n for (var j = 1; j <= days; j++) {\r\n if (str.charAt(j - 1) != str.charAt(j))\r\n arr.push(str.charAt(j-1));\r\n if (arr.includes(str.charAt(j)))\r\n sus = true;\r\n\r\n \r\n }\r\n sus ? print(\"NO\") : print(\"YES\");\r\n}"}, {"source_code": "// Input:\n// t (number of test cases)\n// n (number of letters)\n// n following letters\n\n// Output:\n// YES/NO for every test case\n\n// Algorithm:\n// Non consecutive occurance of some letter => NO\n// Otherwise, YES\n\nfunction deleteConsecutiveRepetitions(str, len) {\n j = 0;\n output = str[0];\n for (var i = 0; i < len; ++i) {\n if (str[i] != output[j]) {\n output += str[i];\n ++j;\n }\n }\n return output;\n}\n\nfunction countOccurrence(str, letter) {\n count = 0;\n for (var i = 0; i < str.length; ++i) {\n if (str[i] == letter) {\n ++count;\n }\n }\n return count;\n}\n\nfunction solution(str) {\n for (letter of str) {\n if (countOccurrence(str, letter) > 1) {\n return \"NO\";\n }\n }\n return \"YES\";\n}\n\nanswers = [];\n\nt = +readline();\nfor (var i = 0; i < t; ++i) {\n n = +readline();\n x = deleteConsecutiveRepetitions(readline(), n);\n answers.push(solution(x));\n}\n\nfor (answer of answers) {\n print(answer);\n}"}, {"source_code": "var t=parseInt(readline());\r\n\r\nfor(var i=0;i {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n\tinputString = inputString.trim().split('\\n').map(string => {\r\n\t\treturn string.trim();\r\n\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readline() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\tvar t = readline();\r\n\tlet count = 1;\r\n\twhile (count <= t) {\r\n\t\tlet n = readline()\r\n\t\tvar stringArray = Array.from(readline());\r\n\t\tlet counter = 0;\r\n\t\tlet arrayLength = stringArray.length\r\n\t\tfor (let i = 0; i <= arrayLength; i++) {\r\n\t\t\tif (stringArray[i] === stringArray[i + 1]) {\r\n\t\t\t\tstringArray.splice(i, 1)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i <= arrayLength; i++) {\r\n\t\t\tif (stringArray[i] === stringArray[i + 1]) {\r\n\t\t\t\tstringArray.splice(i, 1)\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst hasDuplicates = arr => arr.some((item, index) => arr.indexOf(item) !== index)\r\n\t\tif (hasDuplicates(stringArray)) {\r\n\t\t\tconsole.log(\"NO\")\r\n\t\t}\r\n\t\telse {\r\n\t\t\tconsole.log(\"YES\")\r\n\r\n\t\t}\r\n\t\tcount++\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n\tinputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n\tinputString = inputString.trim().split('\\n').map(string => {\r\n\t\treturn string.trim();\r\n\t});\r\n\r\n\tmain();\r\n});\r\n\r\nfunction readline() {\r\n\treturn inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n\tvar t = readline();\r\n\tlet count = 1;\r\n\twhile (count <= t) {\r\n\t\treadline()\r\n\t\tvar stringArray = Array.from(readline());\r\n\t\tlet counter = 0;\r\n\t\tlet arrayLength = stringArray.length\r\n\t\tfor (let i = 0; i < arrayLength; i++) {\r\n\t\t\tif (stringArray[i] === stringArray[i + 1]) {\r\n\t\t\t\tstringArray.splice(i, 1)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < arrayLength; i++) {\r\n\t\t\tif (stringArray[i] === stringArray[i + 1]) {\r\n\t\t\t\tstringArray.splice(i, 1)\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst hasDuplicates = arr => arr.some((item, index) => arr.indexOf(item) !== index)\r\n\t\tif (hasDuplicates(stringArray)) {\r\n\t\t\tconsole.log(\"NO\")\r\n\t\t}\r\n\t\telse {\r\n\t\t\tconsole.log(\"YES\")\r\n\r\n\t\t}\r\n\t\tcount++\r\n\t}\r\n}\r\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const cases = parseInt(lines[0]);\r\n \r\n let prevLetter;\r\n let on = true;\r\n for (let i = 1; i < cases * 2 + 2; i++) {\r\n const line = lines[i];\r\n if (!line) return;\r\n if (!on) {\r\n const all = [];\r\n const chars = line.split('').map(t => t.trim()).filter(t => !!t);\r\n let dont = false;\r\n chars.forEach((char, index) => {\r\n const prev = line[index - 1];\r\n if (!all.includes(char)) {\r\n all.push(char);\r\n } else if (all.includes(char) && prev !== char) {\r\n console.log('NO');\r\n dont = true;\r\n return; \r\n }\r\n });\r\n \r\n if (!dont) console.log('YES');\r\n }\r\n \r\n on = !on;\r\n }\r\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// cat input.txt | node script.js > output.txt\r\n// Number.parseInt(string)\r\nfunction main() {\r\n let t = Number.parseInt(readline()), n, s, d, alphabet, suspicious;\r\n while(t--) {\r\n n = Number.parseInt(readline());\r\n s = readline();\r\n d = s.substr(0, 1);\r\n for(let i = 1; i < n; ++i) {\r\n if(s.substr(i, i + 1) !== s.substr(i - 1, i)) d += s.substr(i, i + 1);\r\n }\r\n alphabet = {};\r\n suspicious = false;\r\n for(let i = 0; i < d.length; ++i) {\r\n if(alphabet.hasOwnProperty(d[i])) {\r\n suspicious = true;\r\n } else {\r\n alphabet[d[i]] = true;\r\n }\r\n }\r\n suspicious ? console.log('NO') : console.log('YES');\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nlet initialized=false,\r\n cache = [];\r\n\r\nfunction fairWork(inp){\r\n cache.push(inp);\r\n\r\n if(cache.length === 2){\r\n\r\n for(let i=0, repeats={}; i {\r\n if(initialized){ console.log( fairWork(input) ) }\r\n else initialized = true\r\n});"}, {"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n const n = parseInt(readLine());\r\n const s = readLine();\r\n let last = '';\r\n let solved = '';\r\n let flag = true;\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(s[i] !== last && solved.includes(s[i]))\r\n {\r\n print('NO');\r\n flag = false;\r\n break;\r\n }\r\n solved += s[i];\r\n }\r\n if (flag) print('YES');\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "var q = Number(readline());\r\n \r\nwhile (q--) {\r\n var n = Number(readline());\r\n var s = readline();\r\n var mapa={};\r\n mapa[s[0]]=true;\r\n var ans=false;\r\n for(var i=1;i 0) {\n mod = m - a * n;\n if (mod <= r - l) {\n b = l + mod;\n c = l;\n break;\n }\n }\n n++;\n mod = a * n - m;\n if (mod <= r - l) {\n b = l;\n c = l + mod;\n break;\n }\n }\n write('' + a + ' ' + b + ' ' + c);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "function solve() {\n var lrm = readArray(Number);\n var l = lrm[0];\n var r = lrm[1];\n var m = lrm[2];\n var a, b, c, n;\n for (var i = l; i <= r; i++) {\n a = i;\n n = Math.floor(m / a);\n if (n > 0) {\n mod = m - a * n;\n if (mod <= r - l) {\n b = l + mod;\n c = l;\n break;\n }\n }\n n++;\n mod = a * n - m;\n if (mod <= r - l) {\n b = l;\n c = l + mod;\n break;\n }\n }\n write('' + a + ' ' + b + ' ' + c);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const [l, r, m] = readLine().split(/\\s/).map(Number)\n if (m <= l) {\n console.log(`${l} ${l} ${2 * l - m}`)\n continue\n }\n for (let a = l; a <= r; a++) {\n const mod = m % a\n const diff = Math.min(mod, a - mod)\n if (diff <= r - l) {\n console.log(`${a} ${mod === diff ? `${l + diff} ${l}` : `${l} ${l + diff}`}`)\n break\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [l,r,m] = ti(readline().split(' '));\n for(let a = l; a <= r; a++){\n let minN = Math.floor(m/a);\n let maxN = minN + 1;\n if(minN * a === m){\n console.log(a,a,a);\n break;\n }else{\n if(minN !== 0 && m-minN*a <= r-l){\n console.log(a, l+(m-minN*a), l);\n break;\n }else if(maxN*a - m <= r-l){\n console.log(a, l, l+(maxN*a-m));\n break;\n }\n }\n }\n }\n}"}], "negative_code": [{"source_code": "function solve() {\n var lrm = readArray(BigInt);\n var l = lrm[0];\n var r = lrm[1];\n var m = lrm[2];\n var a, b, c, n;\n for (var i = l; i <= r; i++) {\n a = i;\n n = m / a;\n mod = m - a * n;\n if (mod <= r - l) {\n b = l + mod;\n c = l;\n break;\n }\n n++;\n mod = a * n - m;\n if (mod <= r - l) {\n b = l;\n c = l + mod;\n break;\n }\n }\n write('' + a + ' ' + b + ' ' + c);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var lrm = readArray(BigInt);\n var l = lrm[0];\n var r = lrm[1];\n var m = lrm[2];\n var minn = 1n;\n var maxn = 2000000000n;\n var midn, minm, maxm;\n while (minn < maxn) {\n var midn = (minn + maxn) / 2n;\n minm = l * (midn + 1n) - r;\n maxm = r * (midn + 1n) - l;\n if (minm <= m && m <= maxm) {\n break;\n }\n if (m < minm) {\n maxn = midn;\n } else {\n minm = midn + 1;\n }\n }\n var a = m / midn;\n var mod = m - a * midn;\n var c = l;\n var b = l + mod;\n if (a * midn + b - c !== m) {\n a++;\n mod = a * midn - m;\n b = l;\n c = l + mod;\n }\n write('' + a + ' ' + b + ' ' + c);\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [l,r,m] = ti(readline().split(' '));\n for(let a = l; a <= r; a++){\n if(m % a === 0){\n console.log(a, a, a);\n break;\n }else{\n let x = m % a;\n if(x <= r-l){\n if(m >= a){\n console.log(a, a+x, a);\n break;\n }\n else{\n console.log(a, a, a+x);\n break;\n }\n }\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [l,r,m] = ti(readline().split(' '));\n for(let a = l; a <= r; a++){\n let minN = Math.floor(m/a);\n let maxN = minN + 1;\n if(minN * a === m){\n console.log(a,a,a);\n break;\n }else{\n if(minN !== 0 && m-minN*a <= r-l){\n console.log(a, a+(m-minN*a), a);\n break;\n }else if(maxN*a - m <= r-l){\n console.log(a, a, a+(maxN*a-m));\n break;\n }\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [l,r,m] = ti(readline().split(' '));\n for(let a = l; a <= r; a++){\n let minN = Math.floor(m/a);\n let maxN = minN + 1;\n if(minN * a === m){\n console.log(a,a,a);\n break;\n }else{\n if(m-minN*a <= r-l){\n console.log(a, a+(m-minN*a), a);\n break;\n }else if(maxN*a - m <= r-l){\n console.log(a, a, a+(maxN*a-m));\n break;\n }\n }\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [l,r,m] = ti(readline().split(' '));\n for(let a = l; a <= r; a++){\n if(m % a === 0){\n console.log(a, a, a);\n break;\n }else{\n let x = m % a;\n if(x <= r-l){\n console.log(a, a+x, a);\n break;\n }\n }\n }\n }\n}"}], "src_uid": "39d8677b310bee8747c5112af95f0e33"} {"source_code": "var l = readline().split(' ');\nvar n = +l[0];\nvar a = [];\nfor (var i = 0; i < n; i++) {\n\ta.push(readline());\n}\nvar dat = {\n};\nvar list = [];\nfor (var i = a.length - 1; i >= 0; i--) {\n\tif(!dat[a[i]]){\n\t\tdat[a[i]] = true;\n\t\tlist.push(a[i]);\n\t}\n}\nprint(list.join('\\n'));", "positive_code": [{"source_code": " var names = [];\n var n = +readline();\n for (var i = 0; i < n; i++) {\n names.push(readline())\n }\n var keys = {};\n var result = [];\n for (i = 0; i < names.length; i++) {\n var name = names[i];\n keys[name] = i;\n }\n Object.keys(keys).forEach(function(item) {\n result[keys[item]] = item;\n });\n\n for (var j = i; j >= 0; j--) {\n if (result[j]) {\n print(result[j])\n }\n }"}, {"source_code": "N = parseInt(readline())\n\nI = [] \n\nfor(var i=0;i=0;i--){\nif(!D[I[i]]){\nprint(I[i])\nD[I[i]]=true\n}} \n"}, {"source_code": "var messageCount = +readline(),\n messageList = [];\n\nfor (var i = 0; i parseInt(readline())\nvar readIntArray = () => readline().split(' ').map(item => parseInt(item))\n\nvar n = readInt()\nvar input = []\nfor(var i = 0; i < n; i++)\n input[i] = readline()\n \nvar nameSet = {}\nfor (var i = n-1; i >= 0; i--){\n if (!nameSet[input[i]]) {\n nameSet[input[i]] = true\n print(input[i])\n }\n}\n"}], "negative_code": [{"source_code": "function main() {\n var names = [];\n var n = +readline();\n for (var i = 0; i < n; i++) {\n names.push(readline())\n }\n var keys = {};\n var result = [];\n for (i = 0; i < names.length; i++) {\n var name = names[i];\n keys[name] = i;\n }\n Object.keys(keys).forEach(function(item) {\n result[keys[item]] = item;\n });\n\n var res = \"\";\n for (i; i >= 0; i--) {\n if (result[i]) {\n res += result[i] + \"\\n\"\n }\n }\n print(res);\n}"}, {"source_code": "var l = readline().split(' ');\nvar n = +l[0];\nvar a = [];\nfor (var i = 0; i < n; i++) {\n\ta.push(readline());\n}\nvar dat = {\n};\nvar list = [];\nfor (var i = a.length - 1; i >= 0; i--) {\n\tif(!dat[a[i]]){\n\t\tdat[a[i]] = true;\n\t\tlist.unshift(a[i]);\n\t}\n}\nprint(list.join('\\n'));"}, {"source_code": "N = parseInt(readline())\n\nI = Array() \n\nfor(var i=0;i=0;i--){\nif(D.indexOf(I[i])!=-1){\nD.push(I[i])\nprint(I[i])\n}\n}\n"}, {"source_code": "N = parseInt(readline())\n\nI = Array() \n\nfor(var i=0;i=0;i--){\nif(D.indexOf(I[i])!=-1){\nD.push(I[i])\nwrite(I[i] + '\\n')\n}\n}\n"}], "src_uid": "18f4d9262150294b63d99803250ed49c"} {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n a,\n };\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, a } = testCase;\n\n let result = 0;\n\n a.forEach((v) => (result += v - 1));\n\n console.log(result % 2 ? \"errorgorn\" : \"maomao90\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var f = 0;\n for(l = 0; l < e; l++){\n if(k[l] % 2 == 1){\n continue;\n }else{\n if(f === 0){\n f = 1;\n }else{\n f = 0;\n }\n }\n }\n if(f === 0){\n console.log('maomao90');\n }else{\n console.log('errorgorn');\n }\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var turn = 0;\n for(j = 0; j < e; j++){\n if(k[j] % 2 == 1){\n continue;\n }else{\n if(turn === 0){\n turn = 1;\n }else{\n turn = 0;\n }\n }\n }\n if(turn === 0){\n console.log('maomao90');\n }else{\n console.log('errorgorn');\n }\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n //var v = new Map();\n //v.set('a', 1); v.set('b', 2); v.set('c', 3); v.set('d', 4); v.set('e', 5); v.set('f', 6); v.set('g', 7); v.set('h', 8); v.set('i', 9); v.set('j', 10); v.set('k', 11); v.set('l', 12); v.set('m', 13); v.set('n', 14); v.set('o', 15); v.set('p', 16); v.set('q', 17); v.set('r', 18); v.set('s', 19); v.set('t', 20); v.set('u', 21); v.set('v', 22); v.set('w', 23); v.set('x', 24); v.set('y', 25); v.set('z', 26);\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var turn = 0;\n for(j = 0; j < e; j++){\n if(k[j] % 2 == 1){\n continue;\n }\n if(turn === 0){\n turn = 1;\n }else{\n turn = 0;\n }\n }\n if(turn === 0){\n console.log('maomao90');\n }else{\n console.log('errorgorn');\n }\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let sum = arr.map(x => x - 1).reduce((a, b) => a + b, 0);\r\n\r\n output((sum % 2 === 1) ? 'errorgorn' : 'maomao90');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nconst players = ['maomao90', 'errorgorn']\n\nfunction main() {\n let t = parseInt(readline())\n while (t--) {\n let n = parseInt(readline())\n let as = readline().split(' ').map(x => parseInt(x))\n let loser = 0\n as.forEach(a => {\n loser += a - 1\n });\n console.log(players[loser % 2])\n }\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let b of a) {\r\n res += b - 1;\r\n }\r\n if (res & 1) console.log('errorgorn');else console.log('maomao90');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let i = 0; i < t; i++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(it => parseInt(it));\r\n let sum = 0;\r\n for (let j = 0; j < n; j++){\r\n if (a[j] > 1){\r\n sum += a[j] - 1;\r\n }\r\n }\r\n if (sum % 2 == 0){\r\n console.log('maomao90');\r\n }\r\n else{\r\n console.log('errorgorn');\r\n }\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var f = false;\n for(l = 0; l < e; l++){\n if(k[l] % 2 == 1){\n continue;\n }else{\n if(f === 0){\n f = true;\n }else{\n f = false;\n }\n }\n }\n if(f === false){\n console.log('maomao90');\n }else{\n console.log('errorgorn');\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var f = false;\n for(l = 0; l < e; l++){\n if(k[l] % 2 == 1){\n continue;\n }else{\n if(f === 0){\n f = true;\n }else{\n f = false;\n }\n }\n }\n if(f === 0){\n console.log('maomao90');\n }else{\n console.log('errorgorn');\n }\n }\n }\n});"}], "src_uid": "fc75935b149cf9f4f2ddb9e2ac01d1c2"} {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n var rooms = readline();\n queries.push(\n readline().split('').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\nfunction min(a, b, c) {\n return ((a < b) && (a < c)) ? a : ((b < a) && (b < c)) ? b : c;\n}\n\n// var queriesCount = 4;\n// var queries = [\n// [0,0,1,0,0],\n// [0,0,0,0,0,0,0,0],\n// [1,1,1,1,1],\n// [1,1,0]\n// ]\n\nfunction main(query) {\n var oneExists = 0;\n var minDistance = Infinity;\n for (var i = 0; i < query.length; i++) {\n if (query[i] === 1) {\n oneExists++;\n minDistance = min(minDistance, i - 0, query.length - i - 1);\n }\n }\n\n if (!oneExists)\n write([query.length].join('') + '\\n')\n else \n write([(query.length - minDistance)*2].join('') + '\\n');\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}", "positive_code": [{"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet t, n, lp = 0;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n t = parseInt(input) * 2;\n } else if (lp === 1){\n lp = 2;\n n = input;\n } else if (lp === 2){\n lp = 1;\n let x = input;\n let prv = 0, nxt = 0;\n for (let i = 0; i < x.length; i++)if (x.charAt(i) === '1')nxt = i + 1;\n for (let i = x.length - 1; i >= 0; i--)if (x.charAt(i) === '1')prv = x.length - i;\n let an;\n if (prv === 0 && nxt === 0)an = x.length; else an = Math.max(prv, nxt) * 2;\n console.log(an);\n }\n if (t === 0)rl.close();\n t--;\n});"}, {"source_code": " 'use strict'\n \n const problem = (n, a) => {\n const i1 = a.indexOf('1');\n if (i1 === -1) return n;\n return 2*Math.max(n - a.indexOf('1'), a.lastIndexOf('1') + 1);\n }\n \n let t = parseInt(readline());\n while (t--) {\n write(problem(parseInt(readline()), readline()) + '\\n');\n }"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const i1 = a.indexOf('1');\n if (i1 === -1) return n;\n return 2*Math.max(n - a.indexOf('1'), a.lastIndexOf('1'));\n}\n\nlet t = parseInt(readline());\nwhile (t--) {\n write(problem(parseInt(readline()), readline()) + '\\n');\n}\n"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n var rooms = readline();\n queries.push(\n readline().split('').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\nfunction min(a, b, c) {\n return ((a < b) && (a < c)) ? a : ((b < a) && (b < c)) ? b : c;\n}\n\n// var queriesCount = 4;\n// var queries = [\n// [0,0,1,0,0],\n// [0,0,0,0,0,0,0,0],\n// [1,1,1,1,1],\n// [1,1,0]\n// ]\n\nfunction main(query) {\n var oneExists = 0;\n var minDistance = Infinity;\n for (var i = 0; i < query.length; i++) {\n if (query[i] === 1) {\n oneExists++;\n minDistance = min(minDistance, i - 0, query.length - i - 1);\n }\n }\n\n if (!oneExists)\n write([query.length].join(''))\n else \n write([(query.length - minDistance)*2].join(''));\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "const readline = require('readline');\n//const lineReader = require('fs');\n//const scanner = lineReader.createReadStream('main.in');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet t, n, lp = 0;\n\nrl.on('line', (input) => {\n if (lp === 0){\n lp = 1;\n t = parseInt(input) * 2;\n } else if (lp === 1){\n lp = 2;\n n = input;\n } else if (lp === 2){\n lp = 1;\n let x = input;\n let prv = 0, nxt = 0;\n for (let i = 0; i < x.length; i++)if (x.charAt(i) === '1')nxt = i + 1;\n for (let i = x.length; i >= 0; i--)if (x.charAt(i) === '1')prv = x.length - i;\n let an = Math.max(prv, nxt) * 2;\n console.log(an);\n }\n if (t === 0)rl.close();\n t--;\n});"}], "src_uid": "23575500451a061ed498468f3814c38a"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n let ma = Math.max(...a),\r\n mb = Math.max(...b);\r\n if (ma > mb) {\r\n return 'Alice\\nAlice';\r\n } else if (ma < mb) {\r\n return 'Bob\\nBob';\r\n } else {\r\n return 'Alice\\nBob';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const m = Number(await read());\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\ndata = data.replace(/\\s*$/, '')\r\n.split('\\n')\r\n.map(str => str.replace(/\\s*$/, ''));\r\n\r\nlet testCases = parseInt(data.shift());\r\n\r\nwhile(testCases--) {\r\n\r\nconst m = parseInt(readLine());\r\nconst al = get_ints();\r\nconst n = parseInt(readLine());\r\nconst b = get_ints();\r\n\r\nconst res = a(m,al,n,b);\r\nconsole.log(res)\r\n}\r\n});\r\n\r\nfunction get_ints(){\r\n return data[currentLine++].split(' ').map(x => Number(x));\r\n}\r\n\r\nfunction readLine() { \r\nreturn data[currentLine++];\r\n}\r\n\r\nfunction a(m,a,n,b){\r\n let ans = '';\r\n const amax = Math.max(...a);\r\n const bmax = Math.max(...b);\r\n bmax > amax ? ans+='Bob\\n' : ans+='Alice\\n';\r\n amax > bmax ? ans+='Alice' : ans+='Bob';\r\n\r\n return ans\r\n}\r\n\r\nmodule.exports = a;\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let m = +readline();\n let b = ra();\n\n a.sort((x, y) => x - y);\n b.sort((x, y) => x - y);\n\n let al = a[n - 1];\n let bb = b[m - 1];\n\n let result = '';\n\n if (al >= bb) result += 'Alice\\n';\n else result += 'Bob\\n';\n\n if (bb >= al) result += 'Bob';\n else result += 'Alice';\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar arr = \"\";\r\n\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const n = parseInt(arr.shift()); // no of test cases\r\n\r\n for (let i = 0; i < 4 * n; ) {\r\n const qtyAlice = arr[i++];\r\n const cardsAlice = arr[i++].split(\" \").map((el) => parseInt(el));\r\n const maxAlice = Math.max(...cardsAlice);\r\n\r\n const qtyBob = arr[i++];\r\n const cardsBob = arr[i++].split(\" \").map((el) => parseInt(el));\r\n const maxBob = Math.max(...cardsBob);\r\n\r\n // Alice turn\r\n if (maxAlice >= maxBob) {\r\n console.log(\"Alice\");\r\n } else {\r\n console.log(\"Bob\");\r\n }\r\n\r\n // Bob turn\r\n if (maxBob >= maxAlice) {\r\n console.log(\"Bob\");\r\n } else {\r\n console.log(\"Alice\");\r\n }\r\n }\r\n});\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n var a = 0;\n var m = 0;\n for(i = 1; i <= t * 4; i++){\n if(i % 4 == 1){\n n = lines[i];\n }else if(i % 4 == 2){\n a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n }else if(i % 4 == 3){\n m = lines[i];\n }else{\n var b = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n if(a[n - 1] > b[m - 1]){\n console.log('Alice');\n console.log('Alice');\n }else if(a[n - 1] < b[m - 1]){\n console.log('Bob');\n console.log('Bob');\n }else{\n console.log('Alice');\n console.log('Bob');\n }\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let m = parseInt(readline(), 10);\r\n let brr = readline().split(' ').map(Number);\r\n\r\n let aMax = Math.max(...arr);\r\n let bMax = Math.max(...brr);\r\n\r\n if (aMax > bMax) {\r\n output('Alice');\r\n } else if (aMax < bMax) {\r\n output('Bob');\r\n } else {\r\n output('Alice');\r\n }\r\n\r\n if (aMax > bMax) {\r\n output('Alice');\r\n } else if (aMax < bMax) {\r\n output('Bob');\r\n } else {\r\n output('Bob');\r\n }\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const sa = lines[l++].trim().split(' ').map(Number)\n l++\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(sa, sb) {\n const a = Math.max(...sa)\n const b = Math.max(...sb)\n if (a > b) {\n return 'Alice\\nAlice'\n } else if (a < b) {\n return 'Bob\\nBob'\n } else {\n return 'Alice\\nBob'\n }\n}\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n for (let t = 0; t < T; t++) {\r\n input.next();\r\n const A = input.next().value.split(\" \").map(Number);\r\n input.next();\r\n const B = input.next().value.split(\" \").map(Number);\r\n const maxA = Math.max(...A);\r\n const maxB = Math.max(...B);\r\n const names = [\"Alice\", \"Bob\"];\r\n const results = [];\r\n for (let i = 0; i < 2; i++) {\r\n if (maxA === maxB) {\r\n results.push(names[i]);\r\n } else {\r\n results.push(names[Number(maxA < maxB)]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst aliceCardNum = nextInt();\r\n const aliceCards = nextIntArray(aliceCardNum);\r\n const bobCardNum = nextInt();\r\n const bobCards = nextIntArray(bobCardNum);\r\n\r\n const maxAliceCard = Math.max(...aliceCards);\r\n const maxBobCard = Math.max(...bobCards);\r\n\r\n // Alice goes first \r\n if (maxAliceCard >= maxBobCard) {\r\n myout(\"Alice\")\r\n } else {\r\n myout(\"Bob\")\r\n }\r\n\r\n // Bob goes first\r\n if (maxBobCard >= maxAliceCard) {\r\n myout(\"Bob\")\r\n } else {\r\n myout(\"Alice\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let n = readline();\r\n let a = readline().split(\" \").map(Number);\r\n let m = readline();\r\n let b = readline().split(\" \").map(Number);\r\n FindWinner(a, b);\r\n }\r\n}\r\n\r\nfunction FindWinner(a, b) {\r\n let maxA = Math.max(...a);\r\n let maxB = Math.max(...b);\r\n if (maxA == maxB) {\r\n print(\"Alice\");\r\n print(\"Bob\");\r\n } else if (maxA > maxB) {\r\n print(\"Alice\");\r\n print(\"Alice\");\r\n } else {\r\n print(\"Bob\");\r\n print(\"Bob\");\r\n }\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nconst solve = (aCards, bCards) => {\n // console.log(\"alice\", aCards);\n\n // console.log(\"bob\", bCards);\n const maxAlice = Math.max(...aCards);\n const maxBob = Math.max(...bCards);\n if (maxAlice >= maxBob) {\n console.log(\"Alice\");\n } else {\n console.log(\"Bob\");\n }\n if (maxBob >= maxAlice) {\n console.log(\"Bob\");\n } else {\n console.log(\"Alice\");\n }\n};\nlet T = -1;\nlet aliceCards;\nlet bobCards;\n\nrl.on(\"line\", function (line) {\n if (T !== -1) {\n switch (T % 4) {\n case 1:\n aliceCards = line.split(\" \").map(Number);\n break;\n case 3:\n bobCards = line.split(\" \").map(Number);\n if (aliceCards !== undefined && bobCards !== undefined)\n solve(aliceCards, bobCards);\n break;\n default:\n break;\n }\n }\n T++;\n});\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var an = readline();\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var bn = readline();\r\n var b = readline().split(' ').map((x) => parseInt(x));\r\n a.sort(function(x,y) { return x-y })\r\n b.sort(function(x,y) { return x-y })\r\n if(b[bn-1] > a[an-1]) {\r\n console.log('Bob');\r\n console.log('Bob');\r\n } else if(a[an-1] > b[bn-1]) {\r\n console.log('Alice');\r\n console.log('Alice');\r\n } else {\r\n console.log('Alice');\r\n console.log('Bob');\r\n }\r\n \r\n \r\n\r\n //console.log(ans);\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let [m] = ra();\n let B = ra();\n LT({n, A, m, B});\n // PROCESSING:\n let ans = 0;\n let maxA = Math.max.apply(null, A)\n let maxB = Math.max.apply(null, B)\n if (maxA==maxB){\n return 'Alice\\nBob'\n }\n return maxA>maxB ? 'Alice\\nAlice' : 'Bob\\nBob'\n};\n "}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++) {\r\n var maxA = 0;\r\n var maxB = 0;\r\n\r\n var cardNumA = parseInt(readline(), 10);\r\n var cardsA = readline().split(\" \");\r\n\r\n var cardNumB = parseInt(readline(), 10);\r\n var cardsB = readline().split(\" \");\r\n\r\n for(var k = 0; k < cardNumA; k++) {\r\n var elem1 = parseInt(cardsA[k], 10);\r\n if(elem1 > maxA) {\r\n maxA = elem1;\r\n }\r\n }\r\n\r\n for(var k = 0; k < cardNumB; k++) {\r\n var elem2 = parseInt(cardsB[k], 10);\r\n if(elem2 > maxB) {\r\n maxB = elem2;\r\n }\r\n }\r\n\r\n if(maxA === maxB) {\r\n print(\"Alice\");\r\n print(\"Bob\");\r\n }else if(maxA > maxB) {\r\n print(\"Alice\");\r\n print(\"Alice\");\r\n }else {\r\n print(\"Bob\");\r\n print(\"Bob\");\r\n }\r\n}"}], "negative_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let m = +readline();\n let b = ra();\n\n let al = a[n - 1];\n let bb = b[m - 1];\n\n let result = '';\n\n if (al >= bb) result += 'Alice\\n';\n else result += 'Bob\\n';\n\n if (bb >= al) result += 'Bob';\n else result += 'Alice';\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++) {\r\n var maxA = 0;\r\n var maxB = 0;\r\n\r\n var cardNumA = parseInt(readline(), 10);\r\n var cardsA = readline().split(\" \");\r\n\r\n var cardNumB = parseInt(readline(), 10);\r\n var cardsB = readline().split(\" \");\r\n\r\n for(var k = 0; k < cardNumA; k++) {\r\n var num = parseInt(cardsA[k], 10);\r\n if(num > maxA) {\r\n maxA = num;\r\n }\r\n }\r\n\r\n for(var k = 0; k < cardNumB; k++) {\r\n var num = parseInt(cardsB[k], 10);\r\n if(num > maxB) {\r\n maxB = num;\r\n }\r\n }\r\n\r\n if(maxA > maxB) {\r\n print(\"Alice\");\r\n print('Alice');\r\n }else if(maxA < maxB) {\r\n print(\"Bob\");\r\n print(\"Bob\");\r\n }else {\r\n print(\"Alice\");\r\n print(\"Bob\");\r\n }\r\n}"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++) {\r\n var maxA = 0;\r\n var maxB = 0;\r\n\r\n var cardNumA = parseInt(readline(), 10);\r\n var cardsA = readline().split(\" \");\r\n\r\n var cardNumB = parseInt(readline(), 10);\r\n var cardsB = readline().split(\" \");\r\n\r\n for(var k = 0; k < cardNumA; k++) {\r\n if(cardsA[k] > maxA) {\r\n maxA = cardsA[k];\r\n }\r\n }\r\n\r\n for(var k = 0; k < cardNumB; k++) {\r\n if(cardsB[k] > maxB) {\r\n maxB = cardsB[k];\r\n }\r\n }\r\n\r\n if(maxA > maxB) {\r\n print(\"Alice\");\r\n print('Alice');\r\n }else if(maxA < maxB) {\r\n print(\"Bob\");\r\n print(\"Bob\");\r\n }else {\r\n print(\"Alice\");\r\n print(\"Bob\");\r\n }\r\n \r\n}"}], "src_uid": "581c89736e549300c566e4700b741906"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const sa = lines[l++].trim().split(' ').map(Number)\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, sa, sb) {\n const m = {}\n const ma = sa.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n m[x] = 1\n return o\n }, {})\n const mb = sb.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n m[x] = 1\n return o\n }, {})\n //\n const ca = Array(10).fill(0)\n const cb = Array(10).fill(0)\n let r = 0\n for (let x in m) {\n const na = ma[x] || 0\n const nb = mb[x] || 0\n let add = 0\n if (x > 9) {\n add = 1\n x = String(x).length\n }\n if (na > nb) {\n ca[x] += na - nb\n r += add * (na - nb)\n } else {\n cb[x] += nb - na\n r += add * (nb - na)\n }\n }\n //\n // console.log(ca, cb)\n for (let i = 2; i <= 9; i++) {\n r += Math.abs(ca[i] - cb[i])\n }\n return r\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction digiLog(x) {\r\n return x.toString().length;\r\n}\r\n\r\nfunction heapInsert(heap, value) {\r\n heap.push(value);\r\n\r\n let index = heap.length - 1;\r\n let parentIndex = Math.floor((index - 1) / 2);\r\n\r\n // Sift up\r\n while (index > 0) {\r\n if (value <= heap[parentIndex]) {\r\n break;\r\n }\r\n\r\n heap[index] = heap[parentIndex];\r\n heap[parentIndex] = value;\r\n\r\n index = parentIndex;\r\n parentIndex = Math.floor((index - 1) / 2);\r\n }\r\n}\r\n\r\nfunction heapify(a) {\r\n const heap = [];\r\n for (const value of a) {\r\n heapInsert(heap, value);\r\n }\r\n\r\n return heap;\r\n} \r\n\r\nfunction heapExtract(heap) {\r\n if (heap.length === 0) {\r\n return undefined;\r\n }\r\n\r\n if (heap.length === 1) {\r\n return heap.pop();\r\n }\r\n\r\n const top = heap[0];\r\n const value = heap.pop();\r\n let index = 0;\r\n heap[index] = value;\r\n\r\n while (index < heap.length) {\r\n const left = (index * 2) + 1;\r\n const right = left + 1;\r\n\r\n let nextIndex = -1;\r\n\r\n // If both\r\n if (heap[left] !== undefined && heap[right] !== undefined) {\r\n // ...pick max\r\n if (heap[left] > heap[right]) {\r\n nextIndex = left;\r\n } else {\r\n nextIndex = right;\r\n }\r\n } else if (heap[left] !== undefined) {\r\n nextIndex = left;\r\n } else if (heap[right] !== undefined) {\r\n nextIndex = right;\r\n } else {\r\n break;\r\n }\r\n\r\n if (heap[nextIndex] <= value) {\r\n break;\r\n }\r\n\r\n heap[index] = heap[nextIndex];\r\n heap[nextIndex] = value;\r\n\r\n index = nextIndex;\r\n }\r\n\r\n return top;\r\n}\r\n\r\nfunction solve(sourceA, sourceB) {\r\n let a = heapify(sourceA);\r\n let b = heapify(sourceB);\r\n\r\n let steps = 0;\r\n while (a.length > 0) {\r\n // console.log(a, '|', b);\r\n const lastA = a[0];\r\n const lastB = b[0];\r\n if (lastA === lastB) {\r\n heapExtract(a);\r\n heapExtract(b);\r\n } else if (lastA > lastB) {\r\n const nextValue = digiLog(heapExtract(a));\r\n heapInsert(a, nextValue);\r\n steps++;\r\n } else {\r\n const nextValue = digiLog(heapExtract(b));\r\n heapInsert(b, nextValue);\r\n steps++;\r\n }\r\n }\r\n\r\n console.log(steps);\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].trim().split(\" \").map(Number);\r\n const b = data[i + 2].trim().split(\" \").map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n const n = parseInt(readLine())\n let a = readLine().split(\" \").map((s) => parseInt(s)).sort(\n (x, y) => x - y\n )\n let b = readLine().split(\" \").map((s) => parseInt(s)).sort(\n (x, y) => x - y\n )\n // console.log(a, b)\n let na = [], nb = []\n let i = 0, j = 0\n for (; i < n; i ++) {\n while (a[i] > b[j]) {\n nb.push(b[j])\n j ++\n }\n if (a[i] === b[j]) {\n j ++\n continue\n }\n na.push(a[i])\n }\n for (; j < n; j ++) nb.push(b[j])\n // console.log(na, nb)\n let cnt = {}\n for (i = 1; i < 10; i ++) {\n cnt[i] = 0\n }\n let ans = 0\n for (i = 0; i < na.length; i ++) {\n let x = na[i]\n if (x > 9) {\n cnt[dl(x)] ++\n ans ++\n } else {\n cnt[x] ++\n }\n }\n // console.log(cnt)\n for (i = 0; i < na.length; i ++) {\n let x = nb[i]\n if (x > 9) {\n cnt[dl(x)] --\n ans ++\n } else {\n cnt[x] --\n }\n }\n // console.log(cnt)\n for (i = 2; i <= 9; i ++) {\n ans += Math.abs(cnt[i])\n }\n console.log(ans)\n }\n}\n\nfunction dl(x) {\n return Math.floor(Math.log10(x)) + 1\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let brr = readline().split(' ').map(Number);\r\n let freqA = {}; for (let i = 0; i < arr.length; i++) if (freqA[arr[i]]) freqA[arr[i]]++; else freqA[arr[i]] = 1;\r\n let freqB = {}; for (let i = 0; i < brr.length; i++) if (freqB[brr[i]]) freqB[brr[i]]++; else freqB[brr[i]] = 1;\r\n let sum = 0;\r\n const conv = val => val.toString().length;\r\n\r\n // Remove equals\r\n Object.keys(freqA).forEach(key => {\r\n if (freqB[key]) {\r\n let min = Math.min(freqA[key], freqB[key]);\r\n freqA[key] -= min;\r\n freqB[key] -= min;\r\n }\r\n });\r\n\r\n Object.keys(freqA).forEach(key => {\r\n if (parseInt(key) > 9) {\r\n sum += freqA[key];\r\n let v = conv(parseInt(key));\r\n if (freqA[v]) {\r\n freqA[v] += freqA[key];\r\n } else {\r\n freqA[v] = freqA[key];\r\n }\r\n delete freqA[key];\r\n }\r\n });\r\n\r\n Object.keys(freqB).forEach(key => {\r\n if (parseInt(key) > 9) {\r\n sum += freqB[key];\r\n let v = conv(parseInt(key));\r\n if (freqB[v]) {\r\n freqB[v] += freqB[key];\r\n } else {\r\n freqB[v] = freqB[key];\r\n }\r\n delete freqB[key];\r\n }\r\n });\r\n\r\n // Remove equals\r\n Object.keys(freqA).forEach(key => {\r\n if (freqB[key]) {\r\n let min = Math.min(freqA[key], freqB[key]);\r\n freqA[key] -= min;\r\n freqB[key] -= min;\r\n }\r\n });\r\n\r\n freqA['1'] = 0;\r\n freqB['1'] = 0;\r\n\r\n let sumA = Object.values(freqA).reduce((a, b) => a + b, 0);\r\n let sumB = Object.values(freqB).reduce((a, b) => a + b, 0);\r\n sum += sumA + sumB;\r\n\r\n output(sum);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction digiLog(x) {\r\n return x.toString().length;\r\n}\r\n\r\nfunction solve(a, b) {\r\n a.sort((x, y) => x - y);\r\n b.sort((x, y) => x - y);\r\n\r\n let steps = 0;\r\n\r\n while (a.length > 0) {\r\n const lastA = a[a.length - 1];\r\n const lastB = b[b.length - 1];\r\n if (lastA === lastB) {\r\n a.pop();\r\n b.pop();\r\n } else if (lastA > lastB) {\r\n a[a.length - 1] = digiLog(lastA);\r\n steps++;\r\n } else {\r\n b[b.length - 1] = digiLog(lastB);\r\n steps++;\r\n }\r\n }\r\n\r\n console.log(steps);\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].trim().split(\" \").map(Number);\r\n const b = data[i + 2].trim().split(\" \").map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction eliminate(a, b) {\r\n const filterA = {};\r\n const filterB = {};\r\n for (let i = 0; i < a.length; i++) {\r\n const j = b.indexOf(a[i]);\r\n if (j > -1 && !filterB[j]) {\r\n filterA[i] = true;\r\n filterB[j] = true;\r\n }\r\n }\r\n\r\n return {\r\n a: a.filter((v, i) => !filterA[i]),\r\n b: b.filter((v, i) => !filterB[i])\r\n }\r\n}\r\n\r\nfunction step(a, b) {\r\n if (a.length === 0) {\r\n return;\r\n }\r\n\r\n let largestA = a[0];\r\n let largestAIndex = 0;\r\n let largestB = b[0];\r\n let largestBIndex = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n const logValueA = digiLog(a[i]);\r\n if (b.indexOf(logValueA) > -1) {\r\n a[i] = logValueA;\r\n return;\r\n\r\n }\r\n\r\n const logValueB = digiLog(b[i]);\r\n if (a.indexOf(logValueB) > -1) {\r\n b[i] = logValueB;\r\n return;\r\n }\r\n\r\n if (largestA < a[i]) {\r\n largestA = a[i];\r\n largestAIndex = i;\r\n }\r\n\r\n if (largestB < b[i]) {\r\n largestB = b[i];\r\n largestBIndex = i;\r\n }\r\n }\r\n\r\n if (largestA > largestB) {\r\n a[largestAIndex] = digiLog(a[largestAIndex]);\r\n } else {\r\n b[largestBIndex] = digiLog(b[largestBIndex]);\r\n }\r\n}\r\n\r\nfunction digiLog(x) {\r\n return x.toString().length;\r\n}\r\n\r\nfunction solve(a, b) {\r\n let numberOfSteps = 0;\r\n const {a: nextA, b: nextB} = eliminate(a, b);\r\n a = nextA;\r\n b = nextB;\r\n while (a.length > 0) {\r\n numberOfSteps++;\r\n step(a, b);\r\n const {a: nextA, b: nextB} = eliminate(a, b);\r\n a = nextA;\r\n b = nextB;\r\n }\r\n\r\n console.log(numberOfSteps);\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].trim().split(\" \").map(Number);\r\n const b = data[i + 2].trim().split(\" \").map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction eliminate(a, b) {\r\n const filterA = {};\r\n const filterB = {};\r\n for (let i = 0; i < a.length; i++) {\r\n const j = b.indexOf(a[i]);\r\n if (j > -1 && !filterB[j]) {\r\n filterA[i] = true;\r\n filterB[j] = true;\r\n }\r\n }\r\n\r\n return {\r\n a: a.filter((v, i) => !filterA[i]),\r\n b: b.filter((v, i) => !filterB[i])\r\n }\r\n}\r\n\r\nfunction step(a, b) {\r\n if (a.length === 0) {\r\n return;\r\n }\r\n\r\n let largestA = a[0];\r\n let largestAIndex = 0;\r\n let largestB = b[0];\r\n let largestBIndex = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n const logValueA = digiLog(a[i]);\r\n if (b.indexOf(logValueA) > -1) {\r\n a[i] = logValueA;\r\n return;\r\n\r\n }\r\n\r\n const logValueB = digiLog(b[i]);\r\n if (a.indexOf(logValueB) > -1) {\r\n b[i] = logValueB;\r\n return;\r\n }\r\n\r\n if (largestA < a[i]) {\r\n largestA = a[i];\r\n largestAIndex = i;\r\n }\r\n\r\n if (largestB < b[i]) {\r\n largestB = b[i];\r\n largestBIndex = i;\r\n }\r\n }\r\n\r\n if (largestA > largestB) {\r\n a[largestAIndex] = digiLog(a[largestAIndex]);\r\n } else {\r\n b[largestBIndex] = digiLog(b[largestBIndex]);\r\n }\r\n}\r\n\r\nfunction digiLog(x) {\r\n return x.toString().length;\r\n}\r\n\r\nfunction solve(a, b) {\r\n let numberOfSteps = -1;\r\n const {a: nextA, b: nextB} = eliminate(a, b);\r\n a = nextA;\r\n b = nextB;\r\n while (a.length > 0) {\r\n numberOfSteps++;\r\n step(a, b);\r\n const {a: nextA, b: nextB} = eliminate(a, b);\r\n a = nextA;\r\n b = nextB;\r\n }\r\n\r\n console.log(numberOfSteps);\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].trim().split(\" \").map(Number);\r\n const b = data[i + 2].trim().split(\" \").map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction eliminate(a, b) {\r\n const filterA = {};\r\n const filterB = {};\r\n for (let i = 0; i < a.length; i++) {\r\n const j = b.indexOf(a[i]);\r\n if (j > -1 && !filterB[j]) {\r\n filterA[i] = true;\r\n filterB[j] = true;\r\n }\r\n }\r\n\r\n return {\r\n a: a.filter((v, i) => !filterA[i]),\r\n b: b.filter((v, i) => !filterB[i])\r\n }\r\n}\r\n\r\nfunction step(a, b) {\r\n if (a.length === 0) {\r\n return;\r\n }\r\n\r\n let largestA = a[0];\r\n let largestAIndex = 0;\r\n let largestB = b[0];\r\n let largestBIndex = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n const logValueA = digiLog(a[i]);\r\n if (b.indexOf(logValueA) > -1) {\r\n a[i] = logValueA;\r\n return;\r\n\r\n }\r\n\r\n const logValueB = digiLog(b[i]);\r\n if (a.indexOf(logValueB) > -1) {\r\n b[i] = logValueB;\r\n return;\r\n }\r\n\r\n if (largestA < a[i]) {\r\n largestA = a[i];\r\n largestAIndex = i;\r\n }\r\n\r\n if (largestB < b[i]) {\r\n largestB = b[i];\r\n largestBIndex = i;\r\n }\r\n }\r\n\r\n if (largestA > largestB) {\r\n a[largestAIndex] = digiLog(a[largestAIndex]);\r\n } else {\r\n b[largestBIndex] = digiLog(b[largestBIndex]);\r\n }\r\n}\r\n\r\nfunction digiLog(x) {\r\n return x.toString().length;\r\n}\r\n\r\nfunction solve(a, b) {\r\n let numberOfSteps = -1;\r\n while (a.length > 0) {\r\n numberOfSteps++;\r\n const {a: nextA, b: nextB} = eliminate(a, b);\r\n a = nextA;\r\n b = nextB;\r\n step(a, b);\r\n }\r\n\r\n console.log(numberOfSteps);\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n for (let i = 1; i < data.length; i += 3) {\r\n const a = data[i + 1].trim().split(\" \").map(Number);\r\n const b = data[i + 2].trim().split(\" \").map(Number);\r\n\r\n solve(a, b);\r\n }\r\n});\r\n"}], "src_uid": "b017204679bab4c0573b03d35b8ae3f2"} {"source_code": "var info = readline().split(' ').map(Number)\nvar mountain = readline().split(' ').map(Number)\n\nvar nbOfPick = info[0]\n\nvar nbToChange = info[1]\nvar len = nbOfPick * 2 + 1\nvar prev = mountain[1]\nvar prevPrev = mountain[0]\nvar indexToUpdate = []\nfor (var i = 2; i < len; i++) {\n if (nbToChange <= 0) {\n break;\n }\n\n if (prev - 1 > prevPrev && prev - 1 > mountain[i]) {\n indexToUpdate.push(i - 1)\n nbToChange -= 1\n }\n\n prevPrev = prev\n prev = mountain[i]\n}\n\nfor (var i = 0; i < info[1]; i++) {\n if (indexToUpdate.length > 0) {\n mountain[indexToUpdate.pop()] -= 1\n }\n}\n\nprint(mountain.join(' '))", "positive_code": [{"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\n\nvar arr = readline().split(\" \").map(Number);\nvar result = [];\n\nfor (var i = 0; i < arr.length; i++) {\n var next = arr[i] - 1;\n if (i % 2 !== 0 &&\n k > 0 &&\n next > arr[i - 1] &&\n next > arr[i + 1]) {\n result.push(next);\n k--;\n } else {\n result.push(arr[i]);\n }\n}\n\nprint(result.join(\" \"));"}], "negative_code": [{"source_code": "var info = readline().split(' ').map(Number)\nvar mountain = readline().split(' ').map(Number)\n\nvar nbOfPick = info[0]\n\nvar nbToChange = info[1]\nvar len = nbOfPick * 2 + 1\nvar prev = mountain[1]\nvar prevPrev = mountain[0]\nvar indexToUpdate = []\nfor (var i = 2; i < len; i++) {\n if (nbToChange <= 0) {\n break;\n }\n\n if (prev > prevPrev && prev > mountain[i]) {\n indexToUpdate.push(i - 1)\n nbToChange -= 1\n }\n\n prevPrev = prev\n prev = mountain[i]\n}\n\nfor (var i = 0; i < info[1]; i++) {\n if (indexToUpdate.length > 0) {\n mountain[indexToUpdate.pop()] -= 1\n }\n}\n\nprint(mountain)"}, {"source_code": "var info = readline().split(' ').map(Number)\nvar mountain = readline().split(' ').map(Number)\n\nvar nbOfPick = info[0]\n\nvar nbToChange = info[1]\nvar len = nbOfPick * 2 + 1\nvar prev = mountain[1]\nvar prevPrev = mountain[0]\nvar indexToUpdate = []\nfor (var i = 2; i < len; i++) {\n if (nbToChange <= 0) {\n break;\n }\n\n if (prev > prevPrev && prev > mountain[i]) {\n indexToUpdate.push(i - 1)\n nbToChange -= 1\n }\n\n prevPrev = prev\n prev = mountain[i]\n}\n\nfor (var i = 0; i < info[1]; i++) {\n if (indexToUpdate.length > 0) {\n mountain[indexToUpdate.pop()] -= 1\n }\n}\n\nprint(mountain.join(' '))"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\n\nvar arr = readline().split(\" \").map(Number);\nvar result = [];\n\nfor (var i = 0; i < arr.length; i++) {\n if (i % 2 === 0 && k !== 0) {\n result.push(arr[i] - 1);\n k--;\n } else {\n result.push(arr[i]);\n }\n}\n\nprint(result.join(\" \"));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\n\nvar arr = readline().split(\" \").map(Number);\nvar result = [];\n\nfor (var i = 0; i < arr.length; i++) {\n if (i % 2 !== 0 && k > 0) {\n result.push(arr[i] - 1);\n k--;\n } else {\n result.push(arr[i]);\n }\n}\n\nprint(result.join(\" \"));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\n\nvar arr = readline().split(\" \").map(Number);\nvar result = [];\n\nfor (var i = 0; i < arr.length - 1; i++) {\n var next = arr[i] - 1;\n if (i % 2 !== 0 &&\n k > 0 &&\n next > arr[i] &&\n next < arr[i + 1]) {\n result.push(next);\n k--;\n } else {\n result.push(arr[i]);\n }\n}\n\nprint(result.join(\" \"));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[0];\nvar k = values[1];\n\nvar arr = readline().split(\" \").map(Number);\nvar result = [];\n\nfor (var i = 0; i < arr.length - 1; i++) {\n var next = arr[i] - 1;\n if (i % 2 !== 0 &&\n k > 0 &&\n next > arr[i - 1] &&\n next < arr[i + 1]) {\n result.push(next);\n k--;\n } else {\n result.push(arr[i]);\n }\n}\n\nprint(result.join(\" \"));"}], "src_uid": "1adb4675dc88208f8a05a2db49bb44cb"} {"source_code": "const solve = (arr,n)=>{\r\n if(n===1) return \"YES\";\r\n let start = arr[0],flag = 0;\r\n for(let i=0;i1){\r\n flag=1;\r\n break;\r\n }\r\n start++;\r\n }\r\n if(flag===0) return \"YES\";\r\n flag = 0;\r\n start = arr[0]+1;\r\n for(let i=0;i1){\r\n flag=1;\r\n break;\r\n }\r\n start++;\r\n }\r\n if(flag===0) return \"YES\";\r\n return \"NO\";\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = parseInt(readline());\r\n let mat = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n console.log(solve(mat,n))\r\n }\r\n}\r\nmain();", "positive_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const n = parseInt(input[index]);\n index++;\n const x = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n x,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { n, x } = testCase;\n\n const test = (start) => {\n let i = 1;\n let last = start;\n while (i < n) {\n if (x[i] - last >= 0 && x[i] - last <= 2) {\n i++;\n last++;\n } else {\n break;\n }\n }\n return i == n;\n };\n\n const result = test(x[0] - 1) || test(x[0]) || test(x[0] + 1);\n\n console.log(result ? \"YES\" : \"NO\");\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, a)=>{\n let count3 = 0;\n let count2 = 0;\n for (let i = 1; i < n; i++) {\n if (a[i] - a[i - 1] > 3) {\n return 'NO';\n } else if (a[i] - a[i - 1] === 3) {\n count3++;\n } else if (a[i] - a[i - 1] === 2) {\n count2++;\n }\n }\n if (count3 > 1) return 'NO';\n if (count3 === 1 && count2 > 0) return 'NO';\n if (count2 > 2) return 'NO';\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let c2 = 0\n let c3 = 0\n for (let i = 1; i < arr.length; i++) {\n const d = arr[i] - arr[i - 1]\n if (d === 2) {\n c2++\n } else if (d === 3) {\n c3++\n } else if (d > 3) {\n return false\n }\n }\n if (c3 && c2) return false\n if (c2 > 2) return false\n if (c3 > 1) return false\n return true\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n if (a[a.length - 1] - a[0] <= n + 1) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, a)=>{\n let check = (init)=>{\n let i;\n for (i=0; i 3){\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(list[i + 1] - list[i] == 2){\r\n\t\t\t\tc2++;\r\n\t\t\t}else if(list[i + 1] - list[i] == 3){\r\n\t\t\t\tc3++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c2 > 2 || c3 > 1){\r\n\t\t\tok = false;\r\n\t\t}else{\r\n\t\t\tif(c3 == 1 && c2 > 0){\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "const solve = (arr,n)=>{\r\n if(n===1) return \"YES\";\r\n if(arr[1]-arr[0]===1) start = arr[0];\r\n else start = arr[0]+1;\r\n for(let i=0;i1) return \"NO\";\r\n start++;\r\n }\r\n return \"YES\";\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let n = parseInt(readline());\r\n let mat = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n console.log(solve(mat,n))\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (arr,n)=>{\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(mat,n))\r\n }\r\n}\r\nmain();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar ok = true;\r\n\t\tvar c2 = 0;\r\n\t\tvar c3 = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(list[i + 1] - list[i] > 3){\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(list[i + 1] - list[i] == 2){\r\n\t\t\t\tc2++;\r\n\t\t\t}else if(list[i + 1] - list[i] == 3){\r\n\t\t\t\tc3++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c2 > 2 || c3 > 1){\r\n\t\t\tok = false;\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar ok = true;\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(list[i + 1] - list[i] > 3){\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(list[i + 1] - list[i] == 2 || list[i + 1] - list[i] == 3){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c > 1){\r\n\t\t\tok = false;\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, a)=>{\n let count = 0;\n for (let i = 1; i < n; i++) {\n if (a[i] - a[i - 1] > 3) {\n return 'NO';\n } else if (a[i] - a[i - 1] === 3) {\n count++;\n }\n }\n if (count > 1) return 'NO';\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "f4267120fce9304fc4c45142b60fb867"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < K; i++){\r\n\t\t\tif(list[i] > K){\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const nk = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = nk[0];\n const k = nk[1];\n\n const p = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const q = p\n if (k == n || k == 0) {\n console.log(\"0\");\n } else {\n const p1 = p.slice(0, k)\n q.sort(function(a, b){return a-b});\n\n let count = 0\n for (let i = 0; i < k; i++) {\n if (!p1.includes(q[i])) count++\n }\n\n console.log(count)\n }\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const val = readLine().trim()\n // if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n // else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n const splitLines = lines.map(x => x.split(\" \").map(x => parseInt(x)))\n for (let i = 0; i < splitLines[0][0]; i ++)\n {\n const currentArray = splitLines.slice(2 * i + 1, 2 * i + 3);\n const k = currentArray[0][1];\n let count = 0;\n for (const p of currentArray[1].slice(0, k))\n {\n if (p > k)\n count ++;\n }\n console.log(count);\n }\n})"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const [n, k] = readline().split(' ').map(Number);\r\n const arr = readline().split(' ').map(Number);\r\n\r\n let counter = 0;\r\n for (let i = 0; i < k; i++) {\r\n if (arr[i] > k) {\r\n counter++;\r\n }\r\n }\r\n\r\n output(counter);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const set = new Set(Array.from({\r\n length: m\r\n }, (_, i) => i + 1));\r\n for (let i = 0; i < m; i++) set.delete(a[i]);\r\n return set.size;\r\n}\r\n\r\nasync function main(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = await rns();\r\n const a = await rns();\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n, k;\r\n var a;\r\n for (var t=0; t < tests; t++) {\r\n var nk = readline().split(' ').map(x=>parseInt(x));\r\n n = nk[0];\r\n k = nk[1];\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var b = [...a];\r\n b.sort((x,y)=>x-y);\r\n var map = {};\r\n for (var i = 0; i < k; i++) {\r\n if (map[b[i]] == undefined) {\r\n map[b[i]] = 0;\r\n }\r\n map[b[i]]++;\r\n }\r\n var swaps = 0;\r\n for (var i = 0; i < k; i++) {\r\n if (!map[a[i]]) {\r\n swaps++;\r\n } else {\r\n map[a[i]]--;\r\n }\r\n }\r\n print(swaps);\r\n }"}], "negative_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const nk = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = nk[0];\n const k = nk[1];\n\n const p = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const q = p\n if (k == n || k == 0) {\n console.log(\"0\");\n } else {\n q.sort(function(a, b){return a-b});\n\n const p1 = p.slice(0, k)\n\n let count = 0\n for (let i = 0; i < k; i++) {\n if (!p1.includes(q[k])) count++\n }\n\n console.log(count)\n\n }\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const val = readLine().trim()\n // if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n // else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n const nk = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n const n = nk[0];\n const k = nk[1];\n\n const p = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n\n if (k == n || k == 0) {\n console.log(\"0\");\n } else {\n console.log(k)\n }\n\n // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {\n // const val = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n // const val = readLine().trim()\n // if (val.toUpperCase() == \"YES\") console.log(\"YES\")\n // else console.log(\"NO\")\n // let output = calc(val, m);\n // console.log(output)\n // }\n // ws.write(result + '\\n');\n }\n\n // ws.end();\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < K; i++){\r\n\t\t\tif(list[i] != i + 1){\r\n\t\t\t\tvar index = list.indexOf(i + 1);\r\n\t\t\t\tvar tmp = list[i];\r\n\t\t\t\tlist[i] = list[index];\r\n\t\t\t\tlist[index] = tmp;\r\n\t\t\t\toutput++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "src_uid": "10927dcb59007fc3a31fdb6b5d13846f"} {"source_code": "var s = ((+readline()*2))+1;var myarray = [\"0\"];var last = myarray[myarray.length - 1]\n\n\n\nwhile(last.length!=s){\n\nlast = [...new Set(last)];\n\nlast.push((+last[last.length-1]) + 1)\nlast = last.concat(last.slice(0,last.length-1).reverse())\n\nmyarray.push(last)\n}\n\n\nfor(var i=0;i=0;i--){tnzm(myarray[i])}\t\n\n\n\nfunction tnzm(n){\nvar space = \"\";\nfor(var l=0;l= 0; i--)textToPrint+=palindromicArray[i];\n return textToPrint.replace(/\\n$/,\"\");\n}\n//console.log(printPresent(process.argv[2]));\nprint(printPresent(readline()));\n"}, {"source_code": "function getLine(start, n) {\n\tvar res = [];\n\tvar i;\n\tfor (i = 0; i < start; i++ ) {\n\t\tres.push(' ');\n\t}\n\tfor (i = 0; i <= n; i++) {\n\t\tres.push(i);\n\t}\n\tfor (i = n - 1; i >= 0; i--) {\n\t\tres.push(i)\n\t}\n\tprint(res.join(' '));\n} \n\nvar n = parseInt(readline());\nvar i;\n\nfor(i = 0; i <= n; i++) {\n\tgetLine(n - i, i);\n}\n\nfor(i = n - 1; i >= 0; i--) {\n\tgetLine(n - i, i);\n}\n"}, {"source_code": "function line(start, n) {\n\tvar res = [];\n\tvar i = 0;\n\n\tfor (i = 0; i < start; i++) {\n\t\tres.push(' ');\n\t};\n\n\tfor (i = 0; i <= n; i++) {\n\t\tres.push(i);\n\t};\n\n\tfor (i = n - 1; i >= 0; i--) {\n\t\tres.push(i);\n\t};\n\n\tprint(res.join(' '));\n};\n\nvar n = parseInt(readline());\nvar i = 0;\n\nfor (i = 0; i <= n; i++) {\n\tline(n - i, i);\n};\n\nfor (i = n - 1; i >= 0; i--) {\n\tline(n - i, i);\n};"}, {"source_code": "\nvar n=+readline();\nfunction line(n, a){\n\tvar ret = [];\n\tfor(var i=0; i=0; i--){\n\t\tret.push(i);\n\t}\n\treturn ret.join(' ');\n}\n\nfor(var i=0; i<=n; i++){\n\tprint(line(i, n));\n}\nfor(var i=n-1; i>=0; i--){\n\tprint(line(i, n));\n}"}, {"source_code": "var n = +readline();\n\nfor(i = 0; i < n; i++){\n\tfor(j = 0; j <= (n-i-1)*2; j++){\n\t\twrite(\" \");\n\t}\n\tfor(j = 0; j < i; j++){\n\t\twrite(\" \" + j);\n\t}\n\twrite(\" \" + i);\n\tfor(j = i-1; j >= 0; j--){\n\t\twrite(\" \" + j);\n\t}\n\twrite(\"\\n\");\n}\nfor(i = 0; i < n; i++){\n\twrite(i + \" \");\n}\nwrite(n);\nfor(i = n-1; i >= 0; i--){\n\twrite(\" \" + i);\n}\nwrite(\"\\n\");\nfor(i = n-1; i >= 0; i--){\n\tfor(j = 0; j <= (n-i-1)*2; j++){\n\t\twrite(\" \");\n\t}\n\tfor(j = 0; j < i; j++){\n\t\twrite(\" \" + j);\n\t}\n\twrite(\" \" + i);\n\tfor(j = i-1; j >= 0; j--){\n\t\twrite(\" \" + j);\n\t}\n\twrite( (i == 0) ? \"\" : \"\\n\");\n}"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline();\n\tvar s = new Array(2 * n + 1);\n\n\tfor (var i = 0; i < s.length; i++) {\n\t\ts[i] = [];\n\t\tfor (var j = 0; j < Math.abs(n - i); j++) s[i].push(' ');\n\t\tfor (var j = 0; j < n - Math.abs(n - i) + 1; j++)s[i].push(j);\n\t\tfor (var j = n - Math.abs(n - i) - 1; j >= 0 ; j--)s[i].push(j);\n\t\ts[i] = s[i].join(' ') + '\\n';\n\t}\n\n\tprint(s.join(''));\n\n}).call(this);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const result = [];\n\n for (let i = 0; i <= len; i++) {\n const line = [];\n for (let j = 0; j <= Math.floor((i * 2) / 2); j++) {\n line.push(j);\n }\n for (let j = Math.floor((i * 2) / 2) - 1; j >= 0; j--) {\n line.push(j);\n }\n result.push(line);\n }\n\n for (let i = len - 1; i >= 0; i--) {\n result.push(result[i]);\n }\n\n for (let i = 0; i < result.length; i++) {\n if (i <= len) {\n console.log(`${\" \".repeat((len - i) * 2)}${result[i].join(\" \")}`);\n } else {\n console.log(`${\" \".repeat((i - len) * 2)}${result[i].join(\" \")}`);\n }\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet arr = [];\n\tlet s = n * 2;\n\n\tfor (let i = 0; i <= s; i++) {\n\t\tarr[i] = Array(s + 1).fill(' ');\n\t}\n\n\tfor (let i = 0; i <= n; i++) {\n\t\tlet c = 2 * i;\n\t\tlet a = n - i;\n\t\tlet x = 0;\n\t\tfor (let j = a; j <= n; j++) {\n\t\t\tarr[i][j] = x;\n\t\t\tarr[i][s - j] = x;\n\t\t\tarr[s - i][j] = x;\n\t\t\tarr[s - i][s - j] = x;\n\t\t\tx++;\n\t\t}\n\t}\n\n\tfor (let i = 0; i <= s; i++) {\n\t\tlet str = '';\n\t\tlet found = false;\n\t\tfor (let j = 0; j <= s; j++) {\n\t\t\tif (arr[i][j] !== ' ') {\n\t\t\t\tfound = true;\n\t\t\t}\n\n\t\t\tif (!found) {\n\t\t\t\tstr += arr[i][j] + ' ';\n\t\t\t} else {\n\t\t\t\tif (arr[i][j] !== ' ') {\n\t\t\t\t\tstr += arr[i][j] + ' ';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconsole.log(str.replace(/\\s$/, ''));\n\t}\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n if(Math.abs(n-space) == 0){str = str + j.toString();}\n else {str = str + j.toString() + \" \";}\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n if(j == 0){str = str + j.toString();}\n else {str = str + j.toString() + \" \";}\n }\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}], "negative_code": [{"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet arr = [];\n\tlet s = n * 2;\n\n\tfor (let i = 0; i <= s; i++) {\n\t\tarr[i] = Array(s + 1).fill(' ');\n\t}\n\n\tfor (let i = 0; i <= n; i++) {\n\t\tlet c = 2 * i; // 2 * 1 = 2\n\t\tlet a = n - i; // 2 - 1 = 1\n\t\tlet x = 0;\n\t\tfor (let j = a; j <= n; j++) {\n\t\t\tarr[i][j] = x;\n\t\t\tarr[i][s - j] = x;\n\t\t\tarr[s - i][j] = x;\n\t\t\tarr[s - i][s - j] = x;\n\t\t\tx++;\n\t\t}\n\t}\n\n\tfor (let i = 0; i <= s; i++) {\n\t\tconsole.log(arr[i].join(' '));\n\t}\n}\n"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline();\n\tvar s = new Array(2 * n + 1);\n\n\tfor (var i = 0; i < s.length; i++) {\n\t\ts[i] = '';\n\t\tfor (var j = 0; j < Math.abs(n - i); j++)\t\t\ts[i] += ' ';\n\t\tfor (var j = 0; j < n - Math.abs(n - i) + 1; j++)\ts[i] += j + ' ';\n\t\tfor (var j = n - Math.abs(n - i) - 1; j > 0 ; j--)\ts[i] += j + ' ';\n\t\ts[i] += '0\\n';\n\t}\n\n\tprint(s.join(''));\n\n}).call(this);"}, {"source_code": ";(function () {\n\t\n\tvar n = +readline();\n\tvar s = new Array(2 * n + 1);\n\n\tfor (var i = 0; i < s.length; i++) {\n\t\ts[i] = '';\n\t\tfor (var j = 0; j < Math.abs(n - i); j++)\t\t\ts[i] += ' ';\n\t\tfor (var j = 0; j < n - Math.abs(n - i) + 1; j++)\ts[i] += j;\n\t\tfor (var j = n - Math.abs(n - i) - 1; j >= 0 ; j--)\ts[i] += j;\n\t\ts[i] += '\\n';\n\t}\n\n\tprint(s.join(''));\n\n}).call(this);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n str = str + j.toString() + \" \";\n }\n str += \"\\b\";\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n if(j == Math.abs(n-space)){str = str + j.toString();}\n else {str = str + j.toString() + \" \";}\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n if(j == 0){str = str + j.toString();}\n else {str = str + j.toString() + \" \";}\n }\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n str = str + j.toString() + \" \";\n }\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n if(j == 0){str = str + j.toString();}\n else {str = str + j.toString() + \" \";}\n }\n if(i < 2*n){str += \"\\n\"};\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar str = \"\", down = false, space = n;\nfor(var i = 0; i <= 2*n; ++i)\n{\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n for(var j = 0; j <= Math.abs(n-space); ++j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = Math.abs(n-space)-1; j >= 0; --j)\n {\n str = str + j.toString() + \" \";\n }\n for(var j = 0; j < 2*space; ++j)\n {\n str += \" \";\n }\n str += \"\\n\";\n if(down){space ++;}\n else {space --;}\n if(space == 0){down = true;}\n}\nprint(str);"}, {"source_code": "var main = function(n)\n{\n\tvar arr = [],arrAll = [], space, numSpace = 2 * n;\n\tfor (var i = 0; i <= n; i++)\n\t{\n\t\tspace = [];\n\t\tnumSpace -= 2 * i;\n\t\tfor (var i1 = 1; i1 <= numSpace; i1++)\n\t\t{\n\t\t\tspace.push(' ');\n\t\t}\n\t\tarr.push(space.join(''));\n\t\tif (i === 0)\n\t\t\t{\n\t\t\t\tspace = space.join('');\n\t\t\t\tarr[arr.length - 1] += '0';\n\t\t\t\tprint(arr);\n\t\t\t\tspace = space.split('');\n\t\t\t}\n\t\telse \n\t\t\t{\n\t\t\t\tfor (var resNum = 0; resNum <= i - 1; resNum++)\n\t\t\t\t{\n\t\t\t\t if (resNum !== i - 1)\n\t\t\t\t\t arr.push(resNum + ' ');\n\t\t\t\t\telse arr.push(resNum);\n\t\t\t\t}\n\t\t\t\tarr = arr.join('') + i + ' ' + arr.reverse().join('');\n\t\t\t\t\n\t\t\t\tprint(arr);\n\t\t\t}\n\t\tarrAll.push(arr);\n\t\tarr = [];\n\t\tnumSpace += 2 * i;\n\t}\n\tarrAll.reverse();\n\tfor (i = 1; i <= arrAll.length - 1; i++)\n\t{\n\t print( arrAll[i]);\n\t}\n}\n\nmain(+readline());"}, {"source_code": "var main = function(n)\n{\n\tvar arr = [],arrAll = [], space, numSpace = 2 * n;\n\tfor (var i = 0; i <= n; i++)\n\t{\n\t\tspace = [];\n\t\tnumSpace -= 2 * i;\n\t\tfor (var i1 = 1; i1 <= numSpace; i1++)\n\t\t{\n\t\t\tspace.push(' ');\n\t\t}\n\t\tarr.push(space.join(''));\n\t\tif (i === 0)\n\t\t\t{\n\t\t\t\tspace = space.join('');\n\t\t\t\tarr[arr.length - 1] += '0';\n\t\t\t\tprint(arr);\n\t\t\t\tspace = space.split('');\n\t\t\t}\n\t\telse \n\t\t\t{\n\t\t\t\tfor (var resNum = 0; resNum <= i - 1; resNum++)\n\t\t\t\t{\n\t\t\t\t\tarr.push(resNum + ' ');\n\t\t\t\t}\n\t\t\t\tarr = arr.join('') + i + ' ' + arr.reverse().join('');\n\t\t\t\t\n\t\t\t\tprint(arr);\n\t\t\t}\n\t\tarrAll.push(arr);\n\t\tarr = [];\n\t\tnumSpace += 2 * i;\n\t}\n\tarrAll.reverse();\n\tfor (i = 1; i <= arrAll.length - 1; i++)\n\t{\n\t print( arrAll[i]);\n\t}\n}\n\nmain(+readline());"}, {"source_code": "// http://codeforces.com/problemset/problem/118/B\nfunction addSpace(str,time) {\n var space=\"\";\n for(var i = 0; i < time; i++)space+=\" \";\n return space+str+space+\"\\n\";\n}\nfunction createPalindromic(n){\n var line=\"\";\n var count=n-1;\n for(var i = 0; i < n; i++){\n line+=(i).toString();\n if(i<=count)line+=\" \";\n }\n return line+(n).toString()+line.split(\"\").reverse().join(\"\");\n}\nfunction printPresent(n){\n var palindromicArray=[];\n var textToPrint=\"\";\n var counter=n*2;\n for (var i = 0; i < n; i++) {\n var line=addSpace(createPalindromic(i),counter);\n palindromicArray.push(line)\n textToPrint+=line;\n counter-=2;\n }\n textToPrint+=addSpace(createPalindromic(n),0);\n for (var i = n-1; i >= 0; i--) {\n textToPrint+=palindromicArray[i];\n }\n return textToPrint.replace(/\\n$/,\"\");\n}\nprintPresent(5);\n"}, {"source_code": "var s = ((+readline()*2))+1;\nvar myarray = [\"0\"];\nvar last = myarray[myarray.length - 1]\n\nwhile(last.length!=s){\nlast = [...new Set(last)];\n\nlast.push((+last[last.length-1]) + 1)\nlast = last.concat(last.slice(0,last.length-1).reverse())\nmyarray.push(last)\n}\n\n\nfor(var i=0;i=0;i--){print(myarray[i].toString().replace(/,/g,\" \"))}\t"}], "src_uid": "7896740b6f35010af751d3261b5ef718"} {"source_code": "/* ################################################################# \n * This solution has been prepared for TheCodingConversations google\n * meet session to be held on 2020-09-06. If you wish to participate\n * in this session kindly refrain from reading this solution until \n * the session has been concluded.\n *\n * author - atifcppprogrammer\n/* ################################################################# */\n\nconst handleTestCase = function(strings){\n // Creating map and counting occurences of all \n // characters found in each element of strings.\n const map = {};\n for (var i = 0; i < strings.length; ++i){\n var letters = strings[i].split('');\n for(var j = 0; j < letters.length; ++j){\n var key = letters[j];\n map[key] == undefined ? map[key] = 1 : map[key]++;\n }\n }\n // Checking if the occurence of each letter occurs\n // in integer multiples of strings.length.\n const keys = Object.keys(map); var go = true;\n for (var j = 0; j < keys.length && go; ++j){\n go = map[keys[j]] % strings.length == 0 && go;\n }\n return go;\n}\nconst driverMethod = (function(){\n const testCaseCount = parseInt(readline()); \n for (var i = 0; i < testCaseCount; ++i){\n // Collecting problem data for current test case.\n var stringCount = parseInt(readline()), strings = [];\n for (var j = 0; j < stringCount; ++j)\n strings.push(readline());\n // Printing verdict for current test case.\n var verdict = handleTestCase(strings) ? \"YES\" : \"NO\";\n print(verdict);\n }\n return \"DONE\";\n})();\n/* ################################################################### */\n\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const map = {};\n let count = 0;\n for (let i = 0; i < len; i++) {\n const str = readLine()\n .split(\"\")\n .forEach((char) => {\n count++;\n if (!map[char]) map[char] = 1;\n else map[char]++;\n });\n }\n if (!Number.isInteger(count / len)) console.log(\"NO\");\n else {\n let ok = true;\n const values = Object.values(map);\n for (let value of values) {\n if (value % len !== 0) {\n console.log(\"NO\");\n ok = false;\n break;\n }\n }\n if (ok) console.log(\"YES\");\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var map = {};\n for(var j = 0; j < N; j++){\n var s = next();\n for(var k = 0; k < s.length; k++){\n if(map[s[k]] == null){\n map[s[k]] = 0;\n }\n map[s[k]]++;\n }\n }\n var isOK = true;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n if(map[key[j]] % N != 0){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = Number(readLine());\n while (t--) {\n let n = Number(readLine());\n const ln = n;\n const m = {};\n while (n--) {\n const s = readLine().split('');\n s.forEach(ss => m[ss] = m[ss] ? m[ss] + 1 : 1);\n }\n const res = Object.keys(m).reduce((acc, cur) => acc || m[cur] % ln !== 0, false);\n console.log(!res ? 'YES' : 'NO');\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = +$()\n let m = {}\n For(n, i => { [...$()].forEach(c => m[c] = (m[c] || 0) + 1) })\n log(m.$k().every(c => m[c] % n == 0) ? 'YES' : 'NO')\n }\n}\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n/****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\n/**\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string\n * when required.\n *\n * I am using console.log() to output\n */\nfunction main() {\n let t = readLine();\n t = parseInt(t);\n\n while (t--) {\n let n = readLine();\n n = Number(n);\n let dict = {};\n for (let i = 0; i <= 26; i++) {\n dict[String.fromCharCode(97 + i)] = 0;\n }\n\n for (let i = 0; i < n; i++) {\n let word = readLine();\n for (const c of word) {\n dict[c]++;\n }\n }\n\n let pass = true;\n\n for (const [key, value] of Object.entries(dict)) {\n if (value !== 0 && value % n !== 0) {\n pass = false;\n break;\n }\n }\n console.log(pass === true ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nconst calculateAmountOfDistinctLetters = letters => {\n const letterMap = {};\n letters.split(\"\").forEach(letter => {\n if(letterMap.hasOwnProperty(letter)){\n letterMap[letter]++;\n }else{\n letterMap[letter] = 1;\n }\n })\n return letterMap;\n}\n\nfunction main(fileContents) {\n // console.log(fileContents);\n\n fileContents.splice(0,1);\n\n const questions = [];\n\n while(fileContents.length > 1){\n questions.push(fileContents.splice(1,parseInt(fileContents[0])))\n fileContents.splice(0,1);\n }\n\n friendlyFormatQuestions = questions.map(question => ({\n amountOfWords:question.length,\n words:question,\n allLettersTogether:question.join(\"\"),\n amountOfDistinctLetters:calculateAmountOfDistinctLetters(question.join(\"\"))\n }))\n\n // console.log(friendlyFormatQuestions);\n\n console.log(friendlyFormatQuestions.map(question => {\n match = true;\n Object.keys(question.amountOfDistinctLetters).forEach(key => {\n if(question.amountOfDistinctLetters[key]%question.amountOfWords!==0){\n match = false;\n }\n })\n\n return match? \"YES\" : \"NO\";\n }).join(\"\\n\"));\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let n = parseInt(readline());\n let str = new Array(n);\n for(let i = 0; i < n; i++){\n str[i] = readline();\n }\n\n let map = new Array(26);\n map.fill(0);\n for(let s of str){\n for(let c of s){\n let index = c.charCodeAt(0) - 97;\n map[index] += 1;\n }\n }\n\n let isPossible = true;\n for(let i = 0; i < 26; i++){\n if(map[i] % n !== 0){\n isPossible = false;\n break;\n }\n }\n\n console.log(isPossible ? 'YES' : 'NO');\n }\n}\n\nfunction main(){\n let [n,k] = ti(readline().split(' '));\n let w = new Array(n);\n let v = new Array(n);\n\n for(let i = 0; i < n; i++){\n let [x,y] = ti(readline().split(' '));\n w[i] = x;\n v[i] = y;\n }\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(100001);\n dp[i].fill(99999999999);\n }\n\n for(let i = 0; i < n; i++){\n for(let j = 0; j < 100001; j++){\n if(i === 0 || j === 0){\n if(i === 0 && j === 0)\n dp[i][j] = 0;\n else if(i === 0)\n dp[i][j] = v[0] === j ? w[0] : 99999999999;\n }else{\n dp[i][j] = dp[i-1][j];\n if(j >= v[i])\n dp[i][j] = Math.min(dp[i][j], w[i] + dp[i-1][j-v[i]]);\n }\n }\n }\n\n let max = 0;\n for(let i = 100000; i >= 0; i--){\n if(dp[n-1][i] <= k){\n max = i;\n break;\n }\n }\n\n console.log(max);\n}"}, {"source_code": "/* ################################################################# \n * This solution has been prepared for TheCodingConversations google\n * meet session to be held on 2020-09-06. If you wish to participate\n * in this session kindly refrain from reading this solution until \n * the session has been concluded.\n *\n * author - atifcppprogrammer\n/* ################################################################# */\n\nconst handleTestCase = function(strings){\n // Creating map and counting occurences of all \n // characters found in each element of strings.\n const map = {};\n for (var i = 0; i < strings.length; ++i){\n var letters = strings[i].split('');\n for(var j = 0; j < letters.length; ++j){\n var key = letters[j];\n map[key] == undefined ? map[key] = 1 : map[key]++;\n }\n }\n // Checking if the occurence of each letter occurs\n // in integer multiples of strings.length.\n const keys = Object.keys(map); var go = true;\n for (var j = 0; j < keys.length && go; ++j){\n go = map[keys[j]] % strings.length == 0 && go;\n }\n return go;\n}\nconst driverMethod = (function(){\n const testCaseCount = parseInt(readline()); \n for (var i = 0; i < testCaseCount; ++i){\n // Collecting problem data for current test case.\n var stringCount = parseInt(readline()), strings = [];\n for (var j = 0; j < stringCount; ++j)\n strings.push(readline());\n // Printing verdict for current test case.\n var verdict = handleTestCase(strings) ? \"YES\" : \"NO\";\n print(verdict);\n }\n return \"DONE\";\n})();\n/* ################################################################# */"}, {"source_code": "/**\n * \n *\n * author - atifcppprogrammer\n */\nconst handleTestCase = function(strings){\n // Creating map and counting occurences of all \n // characters found in each element of strings.\n const map = {};\n for (var i = 0; i < strings.length; ++i){\n var letters = strings[i].split('');\n for(var j = 0; j < letters.length; ++j){\n var key = letters[j];\n map[key] == undefined ? map[key] = 1 : map[key]++;\n }\n }\n // Checking if the occurence of each letter occurs\n // in integer multiples of strings.length.\n const keys = Object.keys(map); var go = true;\n for (var j = 0; j < keys.length && go; ++j){\n go = map[keys[j]] % strings.length == 0 && go;\n }\n return go;\n}\nconst driverMethod = (function(){\n const testCaseCount = parseInt(readline()); \n for (var i = 0; i < testCaseCount; ++i){\n // Collecting problem data for current test case.\n var stringCount = parseInt(readline()), strings = [];\n for (var j = 0; j < stringCount; ++j)\n strings.push(readline());\n // Printing verdict for current test case.\n var verdict = handleTestCase(strings) ? \"YES\" : \"NO\";\n print(verdict);\n }\n return \"DONE\";\n})();\n/* ###################################################### */\n\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const T = readLine()\n let strArr = new Array(T)\n for (let i = 0; i < T; i++) {\n const N = readLine()\n strArr[i] = []\n for (let _ = 0; _ < N; _++) {\n strArr[i].push(readLine())\n }\n }\n outerLoop: for (let i = 0; i < T; i++) {\n let letters = {}\n const n = strArr[i].length\n const wholeStr = strArr[i].join('')\n for (const letter of wholeStr) {\n if (letter in letters) {\n letters[letter]++\n } else {\n letters[letter] = 1\n }\n }\n for (let letter in letters) {\n if (letters[letter] % n) {\n console.log('NO')\n continue outerLoop\n }\n }\n console.log('YES')\n }\n}"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var map = {};\n for(var j = 0; j < N; j++){\n var s = next();\n for(var k = 0; k < s.length; k++){\n if(map[s[k]] == null){\n map[s[k]] = 0;\n }\n map[s[k]]++;\n }\n }\n var isOK = true;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n if(map[key[j]] % 2 != 0){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var map = {};\n for(var j = 0; j < N; j++){\n var s = next();\n for(var k = 0; k < s.length; k++){\n if(map[s[k]] == null){\n map[s[k]] = 0;\n }\n map[s[k]]++;\n }\n }\n var isOK = true;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n if(map[key[j]] % 2 != 0 && map[key[j]] >= N){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var map = {};\n for(var j = 0; j < N; j++){\n var s = next();\n for(var k = 0; k < s.length; k++){\n if(map[s[k]] == null){\n map[s[k]] = 0;\n }\n map[s[k]]++;\n }\n }\n var isOK = true;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n if(map[key[j]] % 2 != 0 || map[key[j]] >= N){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var map = {};\n for(var j = 0; j < N; j++){\n var s = next();\n for(var k = 0; k < s.length; k++){\n if(map[s[k]] == null){\n map[s[k]] = 0;\n }\n map[s[k]]++;\n }\n }\n var isOK = true;\n var key = Object.keys(map);\n for(var j = 0; j < key.length; j++){\n if(map[key[j]] % 2 != 0 || map[key[j]] < N){\n isOK = false;\n break;\n }\n }\n output[i] = (isOK) ? \"YES\" : \"NO\";\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst readFile = () => {\n let input = \"\"\n let lastline = \"\";\n while(lastline !== undefined){\n lastline = readline();\n // console.log(lastline)\n input = input + \"\\n\" + lastline;\n }\n return input;\n}\n\nconst calculateAmountOfDistinctLetters = letters => {\n const letterMap = {};\n letters.split(\"\").forEach(letter => {\n if(letterMap.hasOwnProperty(letter)){\n letterMap[letter]++;\n }else{\n letterMap[letter] = 1;\n }\n })\n return letterMap;\n}\n\n// const filename = 'input0.txt';\n// const filename = process.argv[2];\n\nfunction main() {\n const fileContents = readFile().split(\"\\n\")\n const totalTests = parseInt(fileContents[0]);\n\n fileContents.splice(0,1);\n\n const questions = [];\n\n// console.log(fileContents);\n\n while(fileContents.length > 1){\n questions.push(fileContents.splice(1,parseInt(fileContents[0])))\n fileContents.splice(0,1);\n }\n\n friendlyFormatQuestions = questions.map(question => ({\n amountOfWords:question.length,\n words:question,\n allLettersTogether:question.join(\"\"),\n amountOfDistinctLetters:calculateAmountOfDistinctLetters(question.join(\"\"))\n }))\n\n// console.log(friendlyFormatQuestions);\n\n console.log(friendlyFormatQuestions.map(question => {\n match = true;\n Object.keys(question.amountOfDistinctLetters).forEach(key => {\n if(question.amountOfDistinctLetters[key]%question.amountOfWords!==0){\n match = false;\n }\n })\n\n return match? \"YES\" : \"NO\";\n }).join(\"\\n\"));\n}\n\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nconst calculateAmountOfDistinctLetters = letters => {\n const letterMap = {};\n letters.split(\"\").forEach(letter => {\n if(letterMap.hasOwnProperty(letter)){\n letterMap[letter]++;\n }else{\n letterMap[letter] = 1;\n }\n })\n return letterMap;\n}\n\nfunction main(fileContents) {\n console.log(fileContents);\n\n fileContents.splice(0,1);\n\n const questions = [];\n\n while(fileContents.length > 1){\n questions.push(fileContents.splice(1,parseInt(fileContents[0])))\n fileContents.splice(0,1);\n }\n\n friendlyFormatQuestions = questions.map(question => ({\n amountOfWords:question.length,\n words:question,\n allLettersTogether:question.join(\"\"),\n amountOfDistinctLetters:calculateAmountOfDistinctLetters(question.join(\"\"))\n }))\n\n console.log(friendlyFormatQuestions);\n\n console.log(friendlyFormatQuestions.map(question => {\n match = true;\n Object.keys(question.amountOfDistinctLetters).forEach(key => {\n if(question.amountOfDistinctLetters[key]%question.amountOfWords!==0){\n match = false;\n }\n })\n\n return match? \"YES\" : \"NO\";\n }).join(\"\\n\"));\n}\n\n"}], "src_uid": "3d6cd0a82513bc2119c9af3d1243846f"} {"source_code": "var row = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = row[0];\n\n//var a = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar color = 1;\nvar res = [];\n\nfor(var i = 0; i <= n ; i++) {\n res.push(0);\n}\n\nfor(var i = 2; i <= n ; i++) {\n var flag = false;\n for(var j = i; j <= n; j+=i) {\n if(res[j] == 0) {\n res[j] = color;\n flag = true;\n }\n }\n if(flag) color++;\n}\n\nwrite(res.slice(2).join(\" \"));", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var n = read.number();\n var res = '';\n var idx = [];\n var arr = [];\n var index = 1;\n for(var i = 2 ; i <= n; i++) {\n var c = true;\n for(var j = 2; j <= Math.floor(i / 2); j++) {\n if(i % j === 0) {\n c = false;\n break;\n }\n }\n if(c) {\n var tmp = i;\n idx[tmp - 2] = index;\n while(tmp + i <= n) {\n tmp += i;\n idx[tmp - 2] = index;\n }\n index++;\n }\n }\n \n print(idx.join(' '));\n}());"}], "negative_code": [], "src_uid": "aa3c015c20cb0c1789661fdc78ae9bec"} {"source_code": "var n= readline();\nvar ranks=readline();\nvar needed=readline();\nranks=ranks.split(\" \");\nneeded=needed.split(\" \");\nvar sum=0;\nfor( var i = parseInt(needed[0])-1; i< parseInt(needed[1])-1;i++)\n{\n\tsum+=parseInt(ranks[i]);\n}\nprint(sum);", "positive_code": [{"source_code": "var n = +readline();\nvar d = readline().split(' ').map(Number);\nvar z = readline().split(' ').map(Number);\nvar a = z[0];\nvar b = z[1];\n\nvar years = 0;\n\nwhile(a < b) {\n years += d[a++ - 1];\n}\n\nprint(years);\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar n,cont=[],indicator=0;\nrl.on('line', (input) => {\n if(indicator==0){\n n=parseInt(input);\n indicator++;\n }\n else if(indicator==1){\n cont=input.split(\" \").map(item=>parseInt(item));\n indicator++;\n }\n else{\n let temp=input.split(\" \").map(item=>parseInt(item));\n let nowR=temp[0];\n let needR=temp[1];\n let ans=0;\n for(let i=nowR-1;i {\n// main(); \n// process.exit(0);\n// })\n /*\n * Api Scanner\n */\n class Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n \n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n \n hasNext() {\n return this.index < this.lines.length;\n }\n }\n \n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (input) => { stdinInput += input; });\n process.stdin.on('end', () => { main(); });\n\nvar n;\nfunction main() {\n const is = new Scanner();\n \n const n = is.nextArray(Number);\n const a = is.nextArray(Number);\n const [dau, cuoi] = is.nextArray(Number);\n // console.log(a);\n\n let kq=0;\n \tfor(i=dau-1; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n years = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const [start, end] = d.split(' ').map(Number);\n let ans = 0;\n\n for (let i = start; i < end; i++) {\n ans += years[i - 1];\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "\nvar n=+readline();\nvar d=readline().split(' ').map(function(v){return +v;});\nvar l=readline().split(' ');\nvar a=+l[0];\nvar b=+l[1];\n\nvar ans=0;\nfor(var i=a-1; i parseInt(v))\nlet v = readline().split(' ').map(v => parseInt(v))\n\nlet ys = 0\nfor (let i = v[0] - 1; i < v[1] - 1; i++) {\n ys += zs[i]\n}\n\nprint(ys)"}, {"source_code": "var n = readline();\nvar d = readline();\nvar ab = readline();\nd = d.split(\" \");\nab = ab.split(\" \");\nvar sum = 0;\nfor(var i = parseInt(ab[0])-1; i < parseInt(ab[1])-1; ++i)\n{\n sum += parseInt(d[i]); \n}\nprint(sum);"}, {"source_code": "var n = parseInt(readline());\nvar d = readline().split(' ').map(function (a) {return parseInt(a)});\nvar input = readline().split(' ').map(function (a) {return parseInt(a)});\nvar a = input[0];\nvar b = input[1];\nvar sum = 0;\n\nfor (var i = a; i < b; i++) {\n\tsum += d[i-1];\n}\n\nprint(sum);"}], "negative_code": [{"source_code": "const n = readline().split('');\nconst d = readline().split('');\nprint(d);\n"}, {"source_code": "const n = readline();\nconst d = readline();\nconst t = readline();\n\n\nprint(t);\n"}, {"source_code": "var n = +readline();\nvar d = readline().split(' ').map(Number);\nvar z = readline().split(' ').map(Number);\nvar a = z[0];\nvar b = z[1];\n\nprint(a);\n"}, {"source_code": "const n = readline();\nconst d = readline();\n\n\nprint(d);\n"}, {"source_code": "const n = readline();\nconst d = readline();\nprint(d);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t[0],t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years += d[t[0]-1];\n t[0]++;\n}\n\nprint(years);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] >= t[2]) {\n years+= d[t[0]-1];\n t[0]+=1;\n}\n\nprint(years);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline().split(' ').map(v => +v);\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years+=d[t[0]-1];\n t[0]++;\n}\n\nprint(d[t[0]-1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] >= t[2]) {\n years+= d[t[0]-1];\n t[0]+=1;\n}\n\nprint(typeof t[2]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years+=d[t[0]-1];\n print(years);\n t[0]+=1;\n}\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] <= t[1]) {\n years += d[t[0]-1];\n t[0]++;\n}\n\nprint(years);\n"}, {"source_code": "const n = readline();\nconst d = readline();\nprint(n);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline().split('');\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t[0]);\nprint(t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years += d[t[0]-1];\n t[0]++;\n}\n\nprint(t[0]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(years);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t[0]);\nprint(t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline().split('');\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t);\nprint(t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years=5;\n t[0]+=1;\n}\n\nprint(t[0] < t[1]);\n"}, {"source_code": "var n = readline();\nvar d = readline();\nvar t = readline();\n\nvar years = 0;\n\nwhile(t[0] < t[1]) {\n years+=d[t[0]-1];\n t[0]+=1;\n}\n\nprint(years);\n"}, {"source_code": "const input = readline().split('');\nprint(input);\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet years;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n years = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const [start, end] = d.split(' ').map(Number);\n let ans = 0;\n let idx = 0;\n\n for (let i = start; i < end; i++) {\n ans += years[idx];\n idx++;\n }\n\n console.log(ans);\n\n c++;\n});\n"}], "src_uid": "69850c2af99d60711bcff5870575e15e"} {"source_code": "function somaAcolumada(array) {\n var novoArray = new Array(array.length);\n novoArray[0] = array[0];\n for (var i = 1 ; i < array.length ; i++) {\n novoArray[i] = array[i] + novoArray[i-1];\n }\n return novoArray;\n}\n\nvar N = parseInt(readline());\nvar quadrados = readline().split(\" \").map(function(n) { return parseInt(n)});\n\n\nvar numeroPossibilidades = 0;\nvar soma = somaAcolumada(quadrados);\nvar somaTotal = soma[quadrados.length - 1];\n\nfor(var i = 0 ; i < N - 1 ; i++) {\n var valorAtual = soma[i];\n var somaOutrosValores = somaTotal - soma[i];\n if (valorAtual === somaOutrosValores) {\n numeroPossibilidades ++;\n }\n}\n\nprint(numeroPossibilidades);\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar arr = tokenizeIntegers(readline());\n\n\tvar totals = [arr[0]];\n\tfor (var i = 1; i < n; i += 1) {\n\t\ttotals[i] = totals[i-1] + arr[i];\n\t}\n\n\tvar grandTotal = totals[n-1];\n\tvar count = 0;\n\tfor (var i = 0; i < n-1; i += 1) {\n\t\tif (grandTotal-totals[i] == totals[i]) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\n\tprint(count);\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "5358fff5b798ac5e500d0f5deef765c7"} {"source_code": "var aLength = +readline()\nvar a = readline().split(' ').map(v=>+v)\na.unshift(0)\n\nvar xLengths = []\n\nfor(var xLength = 1; xLength <= aLength; xLength++) {\n var xSum = a[xLength]\n var res = true\n for(var y = xLength; y > 0; y--) {\n var aValue = a[y]\n for(var j = y + xLength; j <= aLength; j+=xLength) {\n if(a[j] - aValue !== xSum) {\n res = false;\n break\n } \n aValue = a[j]\n }\n if(!res) break \n }\n \n if(res) {\n xLengths.push(xLength)\n }\n}\n\nprint(xLengths.length)\nprint(xLengths.join(' '))", "positive_code": [{"source_code": "'use strict';\n\nconst n = Number(readline());\nconst a = readline().split(' ').map(Number);\nconst possible_lengths = []\n\nconst try_length = function(length) {\n const x = []\n for (let i = 0; i < n; i++) {\n const value = a[i] - ((i > 0) ? a[i - 1] : 0);\n if (i < length) {\n x.push(value);\n } else if (x[i % length] != value) {\n return false;\n }\n }\n return true;\n}\n\nfor (let possible_length = 1; possible_length <= n; possible_length++) {\n if (try_length(possible_length)) {\n possible_lengths.push(possible_length);\n }\n}\n\nprint(possible_lengths.length);\n\nprint(possible_lengths.join(' '));"}], "negative_code": [], "src_uid": "fd2227498f1a0f4042673382a3c71c85"} {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = -1;\n }\n\n intervals.push(n);\n intervals.unshift(-1);\n intervals.sort((a, b) => a - b);\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length - 1; i += 1) {\n intervals[i] = intervals[i + 1] - 1;\n process.stdout.write(`${String(intervals[i] - intervals[i - 1])} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n", "positive_code": [{"source_code": "var line = readline ();\nline = line.trim ().split ( ' ' );\nvar n, k;\nn = (+ line [ 0 ]);\nk = (+ line [ 1 ]);\nvar a = readline ();\na = a.trim ().split ( ' ' );\nvar i, srt = [ ];\nfor ( i = 0; i < n; i ++ ) {\n a [ i ] = Number ( a [ i ] );\n srt [ i ] = a [ i ];\n}\nsrt.sort ( function ( a, b ) { return b - a; } );\nvar o = { };\nvar sum = 0;\nfor ( i = 0; i < k; i ++ ) { \n if ( ! ( srt [ i ] in o ) ) o [ srt [ i ] ] = 0;\n o [ srt [ i ] ] ++;\n sum += srt [ i ];\n}\nvar prev = 0;\nvar ans = [ ];\nvar other = 0;\nfor ( i = 0; i < n; i ++ ) {\n if ( a [ i ] in o ) {\n ans.push ( i - prev + 1 ); \n other += (i - prev + 1);\n o [ a [ i ] ] --;\n if ( o [ a [ i ] ] == 0 ) delete o [ a [ i ] ];\n prev = i + 1;\n }\n}\nans [ ans.length - 1 ] += n - other;\nprint ( sum );\nprint ( ans.join ( ' ' ) );\n"}, {"source_code": "var line = readline().split(' ').map(Number);\nvar n = line[0]; // Number of problems\nvar k = line[1]; // Number of days\nvar difProblems = readline().split(' ').map(Number);\n\nvar maxInd = [];\nvar ans = 0;\n\nfor (var i = 0; i < k; i++) {\n var max = difProblems[0];\n var index = 0;\n for (var j = 0; j < n; j++) {\n if (max < difProblems[j]) {\n max = difProblems[j];\n index = j;\n }\n }\n ans += max;\n difProblems[index] = 0;\n maxInd[i] = index;\n}\n\nmaxInd.sort((a, b) => a < b ? -1 : 1);\n\nprint(ans);\nif (maxInd.length === 1) {\n print(n);\n} else {\n var problemsDay = [maxInd[0]+1];\n for (var i = 1; i < maxInd.length - 1; i++) {\n problemsDay.push(maxInd[i] - maxInd[i-1]);\n }\n\n problemsDay.push(n - maxInd[k-2] - 1);\n print(problemsDay.join(' '));\n}"}, {"source_code": "var l = readline()\n\nvar n = parseInt(l.split(' ')[0], 10)\nvar k = parseInt(l.split(' ')[1], 10)\nvar a = readline().split(' ').map(v => parseInt(v, 10));\nvar b = a.map((v, i) => {\n return {\n value: v,\n index: i,\n };\n});\n\nb.sort((y, x) => x.value - y.value);\n\nb = b.slice(0, k);\n\nb.sort((x, y) => x.index - y.index);\n\nprint(b.map(v => v.value).reduce((a, b) => a + b, 0))\nb = b.map(v => v.index);\n\nvar ans = '';\n\nfunction add(v) {\n ans += v + ' '; \n}\n\nvar last = -1;\n\nfor (var i = 0; i < k - 1; i++) {\n add(b[i] - last);\n last = b[i];\n}\nadd(n - 1 - last)\nprint(ans)"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = -1;\n }\n\n intervals.push(n);\n intervals.unshift(-1);\n intervals.sort();\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length - 1; i += 1) {\n intervals[i] = intervals[i + 1] - 1;\n process.stdout.write(`${String(Math.abs(intervals[i] - intervals[i - 1]))} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = 0;\n }\n\n intervals.push(n);\n intervals.sort();\n intervals.unshift(-1);\n\n for (let i = 1; i < intervals.length - 1; i += 1) {\n intervals[i] = intervals[i + 1] - 1;\n }\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length - 1; i += 1) {\n process.stdout.write(`${String((intervals[i] - intervals[i - 1]))} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = -1;\n }\n\n intervals.push(n);\n intervals.unshift(-1);\n intervals.sort();\n\n for (let i = 1; i < intervals.length - 1; i += 1) {\n intervals[i] = intervals[i + 1] - 1;\n }\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length - 1; i += 1) {\n process.stdout.write(`${String(intervals[i] - intervals[i - 1])} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = -1;\n }\n\n intervals.push(n);\n intervals.unshift(-1);\n intervals.sort();\n\n for (let i = 1; i < intervals.length - 1; i += 1) {\n intervals[i] = intervals[i + 1] - 1;\n }\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length - 1; i += 1) {\n process.stdout.write(`${String(intervals[i] - intervals[i - 1])} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const [n, k] = is.nextArray().map(Number);\n const problems = is.nextArray().map(Number);\n\n const copy = problems.slice();\n copy.sort((a, b) => a - b).reverse();\n\n let totalProfit = 0, index;\n const intervals = [];\n for (let i = 0; i < k; i += 1) {\n totalProfit += copy[i];\n index = problems.indexOf(copy[i]);\n intervals.push(index);\n problems[index] = 0;\n }\n\n intervals.push(n);\n intervals.sort();\n intervals[0] = 0;\n\n console.log(totalProfit);\n for (let i = 1; i < intervals.length; i += 1) {\n process.stdout.write(`${String(intervals[i] - intervals[i - 1])} `);\n }\n console.log();\n}\n\n/*\n * Api Scanner\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n return this.lines[this.index++]; // eslint-disable-line\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "var line = readline().split(' ').map(Number);\nvar n = line[0]; // Number of problems\nvar k = line[1]; // Number of days\nvar difProblems = readline().split(' ').map(Number);\n\nvar indexes = [];\nvar profit = 0;\n\nfor (var i = 0; i < k; i++) {\n var max = difProblems[0];\n var index = 0;\n for (var j = 0; j < n; j++) {\n if (max < difProblems[j]) {\n max = difProblems[j];\n index = j;\n }\n }\n profit += max;\n difProblems[index] = 0;\n indexes[i] = index;\n}\n\nindexes.sort((a, b) => a < b ? -1 : 1);\n\nprint(profit);\nif (indexes.length === 1) {\n print(n);\n} else {\n var problemsDay = [indexes[0]+1];\n for (var i = 1; i < indexes.length - 1; i++) {\n problemsDay.push(indexes[i] - indexes[i-1]);\n }\n\n problemsDay.push(n - indexes[k-1]);\n print(problemsDay.join(' '));\n}"}, {"source_code": "var line = readline().split(' ').map(Number);\nvar n = line[0]; // Number of problems\nvar k = line[1]; // Number of days\nvar difProblems = readline().split(' ').map(Number);\n\nvar indexes = [];\nvar profit = 0;\n\nfor (var i = 0; i < k; i++) {\n var max = difProblems[0];\n var index = 0;\n for (var j = 0; j < n; j++) {\n if (max < difProblems[j]) {\n max = difProblems[j];\n index = j;\n }\n }\n profit += max;\n difProblems[index] = 0;\n indexes[i] = index;\n}\n\nindexes.sort((a, b) => a < b ? -1 : 1);\n\nprint(profit);\nif (indexes.length === 1) {\n print(n);\n} else {\n var problemsDay = [indexes[0]+1];\n for (var i = 1; i < indexes.length - 1; i++) {\n problemsDay.push(indexes[i] - indexes[i-1]);\n }\n\n problemsDay.push(n - indexes[k-1]);\n print(problemsDay);\n}"}, {"source_code": "var l = readline()\n\nvar n = parseInt(l.split(' ')[0], 10)\nvar k = parseInt(l.split(' ')[1], 10)\nvar a = readline().split(' ').map(v => parseInt(v, 10));\nvar b = a.map((v, i) => {\n return {\n value: v,\n index: i,\n };\n});\n\nb.sort((y, x) => x.value - y.value);\n\nb = b.slice(0, k);\n\nb.sort((x, y) => x.index - y.index);\n\nprint(b.map(v => v.value).reduce((a, b) => a + b, 0))\nb = b.map(v => v.index);\n\nvar ans = '';\n\nfunction add(v) {\n ans += v + ' '; \n}\n\nvar last = -1;\n\nfor (var i = 0; i < k - 1; i++) {\n add(b[i] - last);\n last = b[i];\n}\nadd(b[k-1] - last)\nprint(ans)"}, {"source_code": "var l = readline()\n\nvar n = parseInt(l.split(' ')[0], 10)\nvar k = parseInt(l.split(' ')[1], 10)\nvar a = readline().split(' ').map(v => parseInt(v, 10));\nvar b = a.map((v, i) => {\n return {\n value: v,\n index: i,\n };\n});\n\nb.sort((y, x) => x.value - y.value);\n\nb = b.slice(0, k);\n\nb.sort((x, y) => x.index - y.index);\n\nb = b.map(v => v.index);\nvar ans = '';\n\nfunction add(v) {\n ans += v + ' '; \n}\n\nvar last = -1;\n\nfor (var i = 0; i < k - 1; i++) {\n add(b[i] - last);\n last = b[i];\n}\nadd(n - 1 - last)\nprint(ans)"}], "src_uid": "9cc61be7dc9b79f46a3e796db0134173"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(1000+10);\n \n for(let i = 0; i < a.length; i++)\n map[a[i]] = 1;\n\n let isFound = false;\n for(let i = 0; i < b.length; i++){\n if(map[b[i]] === 1){\n console.log('YES');\n console.log(1, b[i]);\n isFound = true;\n break;\n }\n }\n\n if(!isFound)\n console.log('NO');\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let turn = 0;\n for(let i = 0; i < a.length; i++){\n if(i === n-1){\n console.log(turn === 0 ? 'First' : 'Second');\n }\n else if(a[i] === 1){\n turn = turn === 0 ? 1 : 0;\n }else{\n console.log(turn === 0 ? 'First' : 'Second');\n break;\n }\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = readline();\n let b = readline();\n\n let p1 = 0;\n let p2 = n-1;\n\n let ans = [];\n let count = 0;\n for(let i = 0; i < n; i++){\n let x = '-1';\n if(i % 2 === 0){\n x = count % 2 === 0 ? a.charAt(p1) : (a.charAt(p1) === '0' ? '1' : '0');\n p1++;\n }else{\n x = count % 2 === 0 ? a.charAt(p2) : (a.charAt(p2) === '0' ? '1' : '0');\n p2--;\n }\n\n\n if(x !== b.charAt(n-i-1)){\n count += 1;\n ans.push(n-i);\n }else{\n if(n-i !== 1){\n ans.push(1);\n ans.push(n-i);\n count++;\n }\n }\n }\n\n console.log(ans.length);\n for(let i = 0; i < ans.length; i++)\n console.log(ans[i]);\n }\n}", "positive_code": [{"source_code": "function not(c) {\n if (c === '1') {\n return '0';\n }\n return '1';\n}\n\nfunction solve() {\n var n = Number(read());\n var a = Array.from(read());\n var b = Array.from(read());\n var ans = [];\n\n function f(index) {\n var res = a.slice();\n for (var i = 0; i <= index; i++) {\n res[i] = not(a[index - i]);\n }\n a = res;\n }\n \n for (var i = n - 1; i >= 0; i--) {\n if (a[i] === b[i]) {\n continue;\n }\n if (a[0] !== b[i]) {\n ans.push(i + 1);\n f(i);\n continue;\n }\n var j = i - 1;\n while(a[j] !== b[i]) {\n j--;\n }\n ans.push(j + 1);\n f(j);\n ans.push(i + 1);\n f(i);\n }\n write(ans.length + ' ' + ans.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim()\n })\n \n main() \n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nString.prototype.count = function(c) { \n let result = 0\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++\n return result\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1)\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n\n while(t--) {\n let n = parseInt(readLine())\n let [a, b] = [readLine(), readLine()]\n \n let res = []\n if (a[0] != b[0])\n res.push(1)\n \n for (let i = 1; i < a.length; ++i) {\n if (a[i] != b[i]) {\n res.push(i+1)\n res.push(1)\n res.push(i+1)\n }\n }\n console.log(res.length, ...res)\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim()\n })\n \n main() \n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nString.prototype.count = function(c) { \n let result = 0\n for(let i = 0; i < this.length; i++)\n if(this[i] == c)\n result++\n return result\n}\n\nfunction nextChar(c) {\n return String.fromCharCode(c.charCodeAt(0) + 1)\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n\n while(t--) {\n let n = parseInt(readLine().trim())\n let [a, b] = [readLine().trim(), readLine().trim()]\n \n a += '0'\n b += '0'\n\n let [ops1, ops2] = [[], []]\n \n for (let i = 1; i <= n; ++i) {\n if (a[i] !== a[i-1])\n ops1.push(i)\n\n if (b[i] !== b[i-1]) \n ops2.push(i)\n }\n\n ops2.reverse()\n console.log(ops1.length + ops2.length, ...ops1.concat(ops2))\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n let a = Array.from(readLine()).map(Number)\n const b = Array.from(readLine()).map(Number)\n const results = []\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] === b[i]) {\n continue\n }\n if (i === 0) {\n if (a[0] !== b[0]) {\n results.push(1)\n }\n continue\n }\n if (a[0] === b[i]) {\n results.push(1)\n a[0] = (a[0] + 1) % 2\n }\n results.push(i + 1)\n a = a.slice(0, i + 1).map(v => (v + 1) % 2).reverse()\n }\n console.log(`${results.length}${results.length ? ' ' + results.join(' ') : ''}`)\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n let a = Array.from(readLine()).map(Number)\n const b = Array.from(readLine()).map(Number)\n const results = []\n for (let i = n - 1; i >= 0; i--) {\n if (a[i] === b[i]) {\n continue\n }\n if (i === 0) {\n if (a[0] !== b[0]) {\n results.push(1)\n }\n continue\n }\n if (a[0] === b[i]) {\n results.push(1)\n a[0] = (a[0] + 1) % 2\n }\n results.push(i + 1)\n a = a.slice(0, i).map(v => (v + 1) % 2).reverse()\n }\n console.log(`${results.length}${results.length ? ' ' + results.join(' ') : ''}`)\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(1000+10);\n \n for(let i = 0; i < a.length; i++)\n map[a[i]] = 1;\n\n let isFound = false;\n for(let i = 0; i < b.length; i++){\n if(map[b[i]] === 1){\n console.log('YES');\n console.log(1, b[i]);\n isFound = true;\n break;\n }\n }\n\n if(!isFound)\n console.log('NO');\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let turn = 0;\n for(let i = 0; i < a.length; i++){\n if(i === n-1){\n console.log(turn === 0 ? 'First' : 'Second');\n }\n else if(a[i] === 1){\n turn = turn === 0 ? 1 : 0;\n }else{\n console.log(turn === 0 ? 'First' : 'Second');\n break;\n }\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = readline();\n let b = readline();\n\n let p1 = 0;\n let p2 = n-1;\n\n let ans = [];\n let count = 0;\n for(let i = 0; i < n; i++){\n let x = '-1';\n if(i % 2 === 0){\n x = count % 2 === 0 ? a.charAt(p1) : (a.charAt(p1) === '0' ? '1' : '0');\n p1++;\n }else{\n x = count % 2 === 0 ? a.charAt(p2) : (a.charAt(p2) === '0' ? '1' : '0');\n p2--;\n }\n\n\n if(x !== b.charAt(n-i-1)){\n count += 1;\n ans.push(n-i);\n }else{\n ans.push(1);\n ans.push(n-i);\n }\n }\n\n console.log(ans.length);\n for(let i = 0; i < ans.length; i++)\n console.log(ans[i]);\n }\n}"}], "src_uid": "10c9b2d70030f7ed680297455d1f1bb0"} {"source_code": "var l1 = readline();\nvar l2 = readline();\n\nvar glas = ['a', 'e', 'i', 'o', 'u'];\nvar res = 'Yes';\n\nif (l1.length != l2.length) {\n res = 'No'; \n} else {\n for(var i=0; i -1 && tmp2 > -1)) {\n continue; \n } else {\n res = 'No';\n break;\n }\n }\n}\nprint(res);", "positive_code": [{"source_code": "//var input = readline()\n\nvar a = readline()\nvar b = readline()\n\nvar L1 = a.length\nvar L2 = b.length\n\nvar k = /[aeiou]/g\nvar o = /[^aeiou1]/g\n\nvar n = a.replace(k, '1')\nvar m = b.replace(k, '1')\n\nvar x = n.replace(o, '0')\nvar y = m.replace(o, '0')\n//print('x = '+x +' '+ y)\n\n\nif(L1 != L2) print(\"No\")\nelse {\n if(x == y) print(\"Yes\")\n else print(\"No\")\n}\n\n//"}, {"source_code": "// run on javascript V8 4.8.0\n\nfunction main() {\n var s = readline();\n var t = readline();\n \n var ans = solve(s, t);\n print(ans);\n}\n\nfunction solve(s, t) {\n // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp\n\n const c = /[^aeiou]/g;\n const v = /[aeiou]/g;\n const normalizedS = s.replace(c, 'C').replace(v, 'V');\n const normalizedT = t.replace(c, 'C').replace(v, 'V');\n if (normalizedS === normalizedT) {\n return 'Yes';\n } else {\n return 'No';\n }\n}\n\nmain();\n"}, {"source_code": "function q(c)\n{\n if (c==='a')\n return 1;\n if (c==='o')\n return 1;\n if (c==='u')\n return 1;\n if (c==='i')\n return 1;\n if (c==='e')\n return 1;\n return 0;\n}\n\nfunction main() {\n s=stdin[0]\n t=stdin[1]\n if (s.length!=t.length)\n {\n console.log(\"No\")\n }\n else\n {\n ans=\"Yes\"\n for (i=0;i c === 'a' || c === 'e' || c === 'i' || c === 'o' || c === 'u';\n\n for (let i = 0; i < l1.length; i++) {\n if (isVowel(l1[i]) && isVowel(l2[i])) continue;\n if (!isVowel(l1[i]) && !isVowel(l2[i])) continue;\n return 'No';\n }\n\n return 'Yes';\n}\n\nfunction assert(result, expectation, unordered) {\n if (unordered) {\n result = result.split(' ');\n expectation = expectation.split(' ');\n\n if (result.sort().join(' ') !== expectation.sort().join(' ')) {\n console.error(`${result}: ${expectation}`);\n }\n } else if (result !== expectation) {\n console.error(`${result}: ${expectation}`);\n }\n}\n\nfunction run() {\n // codeforces uses windows. Really??!\n if (process.platform === 'win32') {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n\n const input = [];\n\n rl.on('line', (line) => input.push(line));\n rl.on('close', () => console.log(task(input)));\n } else {\n test();\n }\n}\n\nrun();\n"}, {"source_code": "const readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction readLines(number, cb) {\n const lines = [];\n rl.on('line', function(line) {\n lines.push(line);\n if (lines.length === number) {\n rl.close();\n cb(lines);\n }\n });\n};\n\nfunction doIt(lines) {\n const first = lines[0]\n const second = lines[1]\n\n if (first.length!=second.length) {\n console.log('No');\n } else {\n let same = true;\n for (let i=0; i str.trim());\n const vowel = new Set(['a', 'e', 'i', 'o', 'u']);\n const sL = s.length;\n const tL = t.length;\n \n if (sL !== tL) {\n return false;\n }\n\n for (let i = 0; i < sL; i++) {\n if (vowel.has(s[i]) ^ vowel.has(t[i])) {\n return false;\n }\n }\n \n return true;\n}\n\nconsole.log(getAnswer() ? 'Yes' : 'No');\n"}, {"source_code": "// node.js 9.4.0\n\nfunction main() {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n const io = consoleIo();\n io.next();\n rl.on('line', (line) => io.next(line));\n rl.on('close', () => io.next());\n}\n\nfunction* consoleIo() {\n const s = yield 0;\n const t = yield 0;\n\n const ans = solve(s, t);\n\n console.log(ans);\n}\n\nfunction solve(s, t) {\n // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp\n\n const c = /[^aeiou]/g\n const v = /[aeiou]/g\n const normalizedS = s.replace(c, 'C').replace(v, 'V');\n const normalizedV = t.replace(c, 'C').replace(v, 'V');\n if (normalizedS === normalizedV) {\n return 'Yes'\n } else {\n return 'No';\n }\n}\n\nmain();\n"}, {"source_code": "// node.js 9.4.0\n\nfunction main() {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n const io = consoleIo();\n io.next();\n rl.on('line', (line) => io.next(line));\n rl.on('close', () => io.next());\n}\n\nfunction* consoleIo() {\n const s = yield 0;\n const t = yield 0;\n\n const ans = solve(s, t);\n console.log(ans);\n}\n\nfunction solve(s, t) {\n // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp\n\n const c = /[^aeiou]/g;\n const v = /[aeiou]/g;\n const normalizedS = s.replace(c, 'C').replace(v, 'V');\n const normalizedV = t.replace(c, 'C').replace(v, 'V');\n if (normalizedS === normalizedV) {\n return 'Yes';\n } else {\n return 'No';\n }\n}\n\nmain();\n"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return +readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var s = readline();\n var t = readline();\n\n var g = ['a', 'e', 'i', 'o','u'];\n\n if(s.length != t.length) {\n print('no');\n return;\n }\n\n for(var i = 0; i < s.length; i++) {\n if((g.indexOf(s[i]) < 0 && g.indexOf(t[i]) >= 0) || (g.indexOf(s[i]) >= 0 && g.indexOf(t[i]) <0 )) {\n print('no');\n return;\n }\n }\n\n print('yes');\n\n}());\n"}, {"source_code": "var s = readline();\nvar t = readline();\n\ngl_count = function(st) {\n\tvar ans = 0;\n\tfor (var i=0; i= 0;\n\treturn ans;\n}\n\nvar s_gl = gl_count(s);\nvar t_gl = gl_count(t);\n\nif (s_gl === t_gl && s.length === t.length) {\n\tvar Ok = 1;\n\tfor (var i=0; i= 0 &&\n\t ['a','e','i','o','u'].indexOf(t[i]) < 0) ||\n\t (['a','e','i','o','u'].indexOf(t[i]) >= 0 &&\n\t ['a','e','i','o','u'].indexOf(s[i]) < 0))\n\t Ok = 0;\n\tif (Ok === 1)\n\t print(\"Yes\");\n\telse\n\t print(\"No\");\n}\nelse\n\tprint(\"No\");"}, {"source_code": "var v = {}\nv['a'] = 1 \nv['e'] = 1 \nv['i'] = 1 \nv['o'] = 1 \nv['u'] = 1\n\nfunction check(v) {\n if (v==='a') { return 1; }\n if (v==='e') { return 1; }\n if (v==='i') { return 1; }\n if (v==='o') { return 1; }\n if (v==='u') { return 1; }\n return 0;\n}\n\n\nvar vc1 = 0, vc2 = 0;\n\nvar a = readline()\nvar b = readline()\n\nif (a.length === b.length) {\n \n var pass = true;\n a.split('').forEach((c, i)=>{\n \n if(v[a[i]] !== v[b[i]]) {\n pass = false;\n }\n })\n \n\n if (pass) {\n print('Yes')\n } else {\n print('No')\n }\n} else {\n print('No')\n}"}, {"source_code": "const s = readline();\nconst t = readline();\n\nvar output = 'Yes';\n\nif (s.length !== t.length) {\n output = 'No';\n} else {\n for (var i = 0; i < s.length; i++) {\n var sb1 = isSb(s[i]);\n var sb2 = isSb(t[i]);\n \n if (sb1 !== sb2) {\n output = 'No';\n break;\n }\n }\n}\n\nprint(output);\n\n\nfunction isSb(ch) {\n return !!~'aeiou'.indexOf(ch);\n}"}, {"source_code": "var a = readline()\nvar b = readline()\n\nvar L1 = a.length\nvar L2 = b.length\n\nvar k = /[aeiou]/g\nvar o = /[^aeiou1]/g\n\nvar n = a.replace(k, '1')\nvar m = b.replace(k, '1')\n\nvar x = n.replace(o, '0')\nvar y = m.replace(o, '0')\n//print('x = '+x +' '+ y)\n\n\nif(L1 != L2) print(\"No\")\nelse {\n if(x == y) print(\"Yes\")\n else print(\"No\")\n}"}], "negative_code": [{"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return +readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var s = readline();\n var t = readline();\n\n var g = ['a', 'e', 'i', 'o','u'];\n\n for(var i = 0; i < s; i++) {\n if((g.indexOf(s[i]) < 0 && g.indexOf(t[i]) >= 0) || (g.indexOf(s[i]) >= 0 && g.indexOf(t[i]) <0 )) {\n print('no');\n return;\n }\n }\n\n return 'Yes';\n\n}());"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return +readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n \n var s = readline();\n var t = readline();\n\n var g = ['a', 'e', 'i', 'o','u'];\n\n if(s.length != t.length) {\n print('no');\n return;\n }\n\n for(var i = 0; i < s; i++) {\n if((g.indexOf(s[i]) < 0 && g.indexOf(t[i]) >= 0) || (g.indexOf(s[i]) >= 0 && g.indexOf(t[i]) < 0)) {\n print('no');\n return;\n }\n }\n\n print('Yes');\n\n}());\n"}, {"source_code": "var v = {}\nv['a'] = true \nv['e'] = true \nv['i'] = true \nv['o'] = true \nv['u'] = true \n\n\nvar vc1 = 0, vc2 = 0, cc1 = 0, cc2 = 0;\n\nvar a = readline()\nvar b = readline()\n\na.split('').forEach((c)=>{\n vc1 += v[c] ? 1:0;\n})\n\nb.split('').forEach((c)=>{\n vc2 += v[c] ? 1:0;\n})\n\na.split('').forEach((c)=>{\n cc1 += v[c] ? 0:1;\n})\n\nb.split('').forEach((c)=>{\n cc2 += v[c] ? 0:1;\n})\n \nif (vc1 === vc2 && cc1 === cc2) {\n print('Yes')\n} else {\n print('No')\n}\n\n// if (a.length === b.length) {\n// a.split('').forEach((c)=>{\n// vc1 += v[c] ? 1:0;\n// })\n\n// b.split('').forEach((c)=>{\n// vc2 += v[c] ? 1:0;\n// })\n// print('vc', vc1, vc2)\n\n// if (vc1 === vc2) {\n// print('Yes')\n// } else {\n// print('No')\n// }\n// } else {\n// print('No')\n// }"}, {"source_code": "// var v = {}\n// v['a'] = 1 \n// v['e'] = 1 \n// v['i'] = 1 \n// v['o'] = 1 \n// v['u'] = 1\n\nfunction check(v) {\n if (v==='a') { return 1; }\n if (v==='e') { return 1; }\n if (v==='i') { return 1; }\n if (v==='o') { return 1; }\n if (v==='u') { return 1; }\n if (v==='y') { return 1; }\n return 0;\n}\n\n\nvar vc1 = 0, vc2 = 0;\n\nvar a = readline()\nvar b = readline()\n\nif (a.length === b.length) {\n a.split('').forEach((c)=>{\n vc1 += check(c);\n })\n\n b.split('').forEach((c)=>{\n vc2 += check(c);\n })\n\n if (vc1 === vc2) {\n print('Yes')\n } else {\n print('No')\n }\n} else {\n print('No')\n}"}, {"source_code": "// var v = {}\n// v['a'] = 1 \n// v['e'] = 1 \n// v['i'] = 1 \n// v['o'] = 1 \n// v['u'] = 1\n\nfunction check(v) {\n if (v==='a') { return 1; }\n if (v==='e') { return 1; }\n if (v==='i') { return 1; }\n if (v==='o') { return 1; }\n if (v==='u') { return 1; }\n return 0;\n}\n\n\nvar vc1 = 0, vc2 = 0;\n\nvar a = readline()\nvar b = readline()\n\nif (a.length === b.length) {\n a.split('').forEach((c)=>{\n vc1 += check(c);\n })\n\n b.split('').forEach((c)=>{\n vc2 += check(c);\n })\n\n if (vc1 === vc2) {\n print('Yes')\n } else {\n print('No')\n }\n} else {\n print('No')\n}"}, {"source_code": "// node.js 9.4.0\n\nfunction main() {\n const readline = require('readline');\n const rl = readline.createInterface({ input: process.stdin });\n const io = consoleIo();\n io.next();\n rl.on('line', (line) => io.next(line));\n rl.on('close', () => io.next());\n}\n\nfunction* consoleIo() {\n const s = yield 0;\n const t = yield 0;\n\n const ans = solve(s, t);\n\n console.log(ans);\n}\n\nfunction solve(s, t) {\n // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp\n\n const c = /[^aeiou]/g\n const v = /[aeiou]/g\n const normalizedS = s.replace(c, 'C').replace(v, 'V');\n const normalizedV = t.replace(c, 'C').replace(v, 'V');\n console.log(normalizedS);\n console.log(normalizedV);\n if (normalizedS === normalizedV) {\n return 'Yes'\n } else {\n return 'No';\n }\n}\n\nmain();\n"}], "src_uid": "2b346d5a578031de4d19edb4f8f2626c"} {"source_code": "var s = readline();\nvar t = readline();\nvar reversedS = s.split(\"\").reverse();\nvar reversedT = t.split(\"\").reverse();\nvar sLength = reversedS.length;\nvar tLength = reversedT.length;\n\nvar maxLength = Math.max(sLength, tLength);\n\nvar similarCount = 0;\nfor (var i = 0; i < maxLength; i ++) {\n if (i < sLength && i < tLength) {\n if (reversedS[i] === reversedT[i]) {\n similarCount ++;\n } else { break; }\n } else { break ;}\n}\n\nwrite(sLength + tLength - similarCount * 2);", "positive_code": [{"source_code": "// Author: RuX 31/07/2018 2h45PM\nvar _0x569e=['stdin','stdout','close','log','split','createInterface'];(function(_0x48dc40,_0x282b5c){var _0x227fe9=function(_0x29aed7){while(--_0x29aed7){_0x48dc40['push'](_0x48dc40['shift']());}};_0x227fe9(++_0x282b5c);}(_0x569e,0xf4));var _0x3979=function(_0x7c161,_0x3d5921){_0x7c161=_0x7c161-0x0;var _0x14e2c3=_0x569e[_0x7c161];return _0x14e2c3;};var result=0x0;function proc(_0x5ef236,_0x39c442){var _0x3f1b06,_0x3a59c8;var _0x3f9098=_0x5ef236['length'];var _0x14dfaa=_0x39c442['length'];var _0x3e15d6,_0x5dff21;if(_0x3f9098>_0x14dfaa){_0x3e15d6=_0x3f9098;_0x5dff21=_0x14dfaa;_0x3f1b06=_0x5ef236[_0x3979('0x0')]('');_0x3a59c8=_0x39c442[_0x3979('0x0')]('');}else{_0x5dff21=_0x3f9098;_0x3e15d6=_0x14dfaa;_0x3f1b06=_0x39c442['split']('');_0x3a59c8=_0x5ef236[_0x3979('0x0')]('');}var _0x2c2b84=_0x5dff21-0x1;for(;_0x2c2b84>=0x0;_0x2c2b84--){if(_0x3a59c8[_0x2c2b84]!=_0x3f1b06[_0x3e15d6-_0x5dff21+_0x2c2b84]){break;}}result=_0x3e15d6-_0x5dff21+(_0x2c2b84+0x1)*0x2;}var readline=require('readline');var rl=readline[_0x3979('0x1')]({'input':process[_0x3979('0x2')],'output':process[_0x3979('0x3')]});var s1='';var s2='';var c=0x0;var result=0x0;rl['on']('line',function(_0xc4f0d9){c+=0x1;if(c==0x1){s1=_0xc4f0d9;}else{s2=_0xc4f0d9;rl[_0x3979('0x4')]();proc(s1,s2);console[_0x3979('0x5')](result);}});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet str1, str2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n str1 = d;\n c++;\n return;\n }\n\n str2 = d;\n\n c++;\n});\n\nrl.on('close', () => {\n const arr1 = [...str1].reverse();\n const arr2 = [...str2].reverse();\n let count = 0;\n\n for (let i = 0; i < arr1.length; i++) {\n if (arr1[i] === arr2[i]) {\n count++;\n }\n else {\n break;\n }\n }\n\n const ans = (arr1.length + arr2.length) - (count * 2);\n console.log(ans);\n});\n"}, {"source_code": "s=readline()\nt=readline()\nn=s.length\nm=t.length\nres=0\nif (nm)\n{\n s=s.substring(n-m)\n res+=n-m\n n=m\n}\ni=n-1\nres+=2*n\nwhile(i>=0&&s[i]==t[i])\n{\n --i\n res-=2\n}\nprint(res)"}, {"source_code": "var firstLine = readline();\nvar secondLine = readline();\nvar firstLineA = firstLine;\nvar secondLineA = secondLine;\nvar result = 0;\nvar temp1 = 0;\nvar temp2 = 0;\n\nif (firstLine[firstLine.length - 1] !== secondLine[secondLine.length - 1]) {\n print(firstLine.length + secondLine.length);\n} else {\n if (firstLine.length > secondLine.length) {\n result = firstLine.length - secondLine.length;\n firstLine = firstLine.slice(result);\n } else if (firstLine.length < secondLine.length) {\n result = secondLine.length - firstLine.length;\n secondLine = secondLine.slice(result);\n }\n\n var i = firstLine.length - 1;\n for (; i > -1; i--) {\n if (firstLine[i] !== secondLine[i]) {\n break;\n } else {\n temp1 += 2;\n }\n }\n\n print(result + firstLine.length*2 - temp1);\n}"}, {"source_code": "var s = readline();\nvar t = readline();\n\nvar slength = s.length;\nvar tlength = t.length;\n\nvar minLength = Math.min(slength, tlength);\nvar equal = 0;\nfor(var i = 0; i < minLength; i++) {\n if(s[s.length - 1 - i] === t[t.length - 1 - i]) {\n equal++;\n } else {\n break;\n }\n}\nprint(s.length + t.length - 2 * equal);"}, {"source_code": "var s = readline();\nvar t = readline();\n\nvar slength = s.length;\nvar tlength = t.length;\n\nvar minLength = Math.min(slength, tlength);\nvar equal = 0;\nfor(var i = 0; i < minLength; i++) {\n if(s[s.length - 1 - i] === t[t.length - 1 - i]) {\n equal++;\n } else {\n break;\n }\n}\nprint(s.length + t.length - 2 * equal);"}, {"source_code": "var s = readline();\nvar t = readline();\n\n// console.log(s);\n\nvar slen = s.length;\nvar tlen = t.length;\n\nvar ans = slen + tlen;\nvar mn = Math.min(slen,tlen);\n\nvar equal = 0;\nfor(var i = 0;i secondLine.length) {\n result = firstLine.length - secondLine.length;\n firstLine = firstLine.slice(result);\n } else if (firstLine.length < secondLine.length) {\n result = secondLine.length - firstLine.length;\n secondLine = secondLine.slice(result);\n }\n\n var i = 0;\n for (; i < firstLine.length; i++) {\n if (firstLine[i] !== secondLine[i]) { \n result += 2;\n continue;\n } else {\n break;\n }\n }\n\n print(result);\n}"}, {"source_code": "var firstLine = readline();\nvar secondLine = readline();\nvar firstLineA = firstLine;\nvar secondLineA = secondLine;\nvar result = 0;\nvar temp1 = 0;\nvar temp2 = 0;\n\nif (firstLine[firstLine.length - 1] !== secondLine[secondLine.length - 1]) {\n print(firstLine.length + secondLine.length);\n} else {\n if (firstLine.length > secondLine.length) {\n result = firstLine.length - secondLine.length;\n firstLine = firstLine.slice(result);\n } else if (firstLine.length < secondLine.length) {\n result = secondLine.length - firstLine.length;\n secondLine = secondLine.slice(result);\n }\n\n temp1 = Math.floor(firstLine.length / 2);\n while (true) {\n if (firstLine[temp1] !== secondLine[temp1]) {\n firstLine = firstLine.slice(temp1 + 1);\n secondLine = secondLine.slice(temp1 + 1);\n temp1 += Math.floor(temp1 / 2) + 1;\n } else {\n if (temp1 === 0) break;\n temp1 -= Math.floor(temp1 / 2) + 1;\n }\n \n if (firstLine === secondLine) break;\n }\n \n result = firstLineA.length - firstLine.length + secondLineA.length - secondLine.length;\n print(result);\n}"}, {"source_code": "var k = readline();\nvar x = readline();\nb=k.length;\na=x.length;\n\nk='.'+k;\nx=','+x;\n\ny=1;\nwhile ( k[b-y] == x[a-y]){\n y++;\n}\nprint((b-y) + (a-y));\n\n\n\n\n\n\n// kol_vo=0;\n// while (firstVar!=secondVar){\n// \tkol_vo=kol_vo+1;\n// \tfirstVar=firstVar-1;\n// \tif (firstVar===secondVar) {\n// \t\tbreak\n// \t}\n// \telse {\n// \tsecondVar=secondVar-1; }\n// }"}, {"source_code": "//Coded by RuX\nvar _0x1a94=['readline','createInterface','stdin','stdout','line','close','log','replace','exec','floor','length','abs'];(function(_0x391b41,_0x239f31){var _0x4bbcc2=function(_0x282e52){while(--_0x282e52){_0x391b41['push'](_0x391b41['shift']());}};_0x4bbcc2(++_0x239f31);}(_0x1a94,0xdf));var _0x3aa6=function(_0xe895d2,_0xade434){_0xe895d2=_0xe895d2-0x0;var _0x3d2847=_0x1a94[_0xe895d2];return _0x3d2847;};var StringTrimLeft=function(_0x59eb82,_0x4c4064){if(_0x4c4064==0x0){return _0x59eb82;}var _0x3b4cff=new RegExp('^.{'+_0x4c4064+'}','gm');return _0x59eb82[_0x3aa6('0x0')](_0x3b4cff,'');};var StringTrimRight=function(_0x101923,_0x50515e){if(_0x50515e==0x0){return _0x101923;}var _0x8b86ee=new RegExp('.{'+_0x50515e+'}$','gm');return _0x101923[_0x3aa6('0x0')](_0x8b86ee,'');};var StringRight=function(_0x467614,_0x1d00c3){if(_0x1d00c3==0x0){return _0x467614;}var _0x4eaa0e=new RegExp('.{'+_0x1d00c3+'}$','gm');var _0x9f71ee=_0x4eaa0e[_0x3aa6('0x1')](_0x467614);if(_0x9f71ee!=null){return _0x9f71ee[0x0];}else{return'';}};function ruxcall(_0xa2c774,_0x4079b8){var _0x310f70=Math[_0x3aa6('0x2')](_0xa2c774[_0x3aa6('0x3')]/0x2);if(_0x310f70==0x0){return 0x0;}var _0x8838ee=StringRight(_0xa2c774,_0x310f70);var _0x5986bd=StringRight(_0x4079b8,_0x310f70);if(_0x8838ee==_0x5986bd){result=_0x5986bd[_0x3aa6('0x3')]+result;var _0x31df59=StringTrimRight(_0xa2c774,_0x310f70);var _0x550b21=StringTrimRight(_0x4079b8,_0x310f70);ruxcall(_0x31df59,_0x550b21);}else{ruxcall(_0x8838ee,_0x5986bd);}}function proc(_0x2dc9f5,_0x54ba30){var _0x28997e=_0x2dc9f5['length'];var _0x6e6edf=_0x54ba30[_0x3aa6('0x3')];var _0x553dc3=Math[_0x3aa6('0x4')](_0x28997e-_0x6e6edf);if(_0x28997e>_0x6e6edf){_0x2dc9f5=StringTrimLeft(_0x2dc9f5,_0x553dc3);}else{_0x54ba30=StringTrimLeft(_0x54ba30,_0x553dc3);}ruxcall(_0x2dc9f5,_0x54ba30);result=_0x28997e+_0x6e6edf-0x2*result;}var readline=require(_0x3aa6('0x5'));var rl=readline[_0x3aa6('0x6')]({'input':process[_0x3aa6('0x7')],'output':process[_0x3aa6('0x8')]});var s1='';var s2='';var c=0x0;var result=0x0;rl['on'](_0x3aa6('0x9'),function(_0x33872f){c+=0x1;if(c==0x1){s1=_0x33872f;}else{s2=_0x33872f;rl[_0x3aa6('0xa')]();proc(s1,s2);console[_0x3aa6('0xb')](result);}});"}, {"source_code": "/*\n Coded by RuX\n*/\nvar readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar leftstring = function (s1, s2) {\n var max = \"\";\n var min = \"\";\n if (s1.length > s2.length) {\n max = s1;\n min = s2;\n }\n else {\n max = s2;\n min = s1;\n }\n var match = new RegExp(\"(?:[\" + min + \"]+)$\", \"gm\");\n var con = match.exec(max);\n var sub = \"\";\n if (con != null) {\n sub = con[0];\n }\n else {\n sub = \"\";\n }\n var result = max.length + min.length - 2 * sub.length;\n return result;\n};\nvar s1 = \"\";\nvar s2 = \"\";\nvar c = 0;\nrl.on('line', function (line) {\n c += 1;\n if (c == 1) {\n s1 = line;\n }\n else {\n s2 = line;\n rl.close();\n console.log(leftstring(s1, s2));\n }\n});\n"}, {"source_code": "var k = readline();\nvar x = readline();\nb=k.length;\na=x.length;\n\nk='.'+k;\nx=','+x;\n\ny=1;\nwhile ( k[b-y] === x[a-y]){\n y++;\n}\nprint(b-y+1 + a-y+1);\n\n\n\n\n\n\n// kol_vo=0;\n// while (firstVar!=secondVar){\n// \tkol_vo=kol_vo+1;\n// \tfirstVar=firstVar-1;\n// \tif (firstVar===secondVar) {\n// \t\tbreak\n// \t}\n// \telse {\n// \tsecondVar=secondVar-1; }\n// }"}, {"source_code": "var k = readline();\nvar x = readline();\nb=k.length;\na=x.length;\n\nk='.'+k;\nx=','+x;\n\ny=1;\nif (k == x){\n print(0);\n}\nelse {\nwhile ( k[b-y] == x[a-y]){\n y++;\n}\nprint((b-y+1) + (a-y+1));}\n\n\n\n\n\n\n"}, {"source_code": "var k = readline();\nvar x = readline();\nb=k.length;\na=x.length;\n\nk='.'+k;\nx=','+x;\n\ny=1;\nwhile ( k[b-y] === x[a-y]){\n y++;\n}\nprint(b-y + a-y);\n\n\n\n\n\n\n// kol_vo=0;\n// while (firstVar!=secondVar){\n// \tkol_vo=kol_vo+1;\n// \tfirstVar=firstVar-1;\n// \tif (firstVar===secondVar) {\n// \t\tbreak\n// \t}\n// \telse {\n// \tsecondVar=secondVar-1; }\n// }"}], "src_uid": "59d926bca19a6dcfe3eb3e3dc03fffd6"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet zeroPos;\r\n\t\tlet mid = (n >> 1) - 1;\r\n\t\tfor (let i = mid + 1; i < n; i++) if (s[i] == '0') zeroPos = i;\r\n\r\n\t\tif (zeroPos) {\r\n\t\t\t++zeroPos;\r\n\t\t\tconsole.log(1, zeroPos, 1, zeroPos - 1);\r\n\t\t} else {\r\n\t\t\tif (s[mid] == '0') {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n, mid + 1, n);\r\n\t\t\t} else {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n - 1, mid + 1, n);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - i < c && (o(), c >= r) ? t.write(n) : (u.write(n, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim()).map(n => n + 1)\r\n n.println(t.join(' '))\r\n }\r\n function e(n, t) {\r\n const e = n >> 1\r\n for (let r = e; r < n; ++r) if ('0' === t[r]) return [0, r, 0, r - 1]\r\n for (let r = 0, u = n - e; r < u; ++r)\r\n if ('0' === t[r]) return [r, n - 1, r + 1, n - 1]\r\n return [1, e, 0, e - 1]\r\n }\r\n})\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet zeroPos;\r\n\t\tfor (let i = 0; i < n; i++) if (s[i] == '0') zeroPos = i + 1;\r\n\r\n\t\tif (zeroPos) {\r\n\t\t\tif (zeroPos <= n >> 1 ) {\r\n\t\t\t\tconsole.log(zeroPos, n, zeroPos + 1, n);\r\n\t\t\t} else {\r\n\t\t\t\tconsole.log(1, zeroPos, 1, zeroPos - 1);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(1, n - 1, 2, n);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - i < c && (o(), c >= r) ? t.write(n) : (u.write(n, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim()).map(n => n + 1)\r\n n.println(t.join(' '))\r\n }\r\n function e(n, t) {\r\n const e = n >> 1\r\n for (let r = e; r < n; ++r) if ('0' === t[r]) return [0, r, 0, r - 1]\r\n for (let r = 0, u = n - e; r < u; ++r)\r\n if ('0' === t[r]) return [r, n - 1, r + 1, n - 1]\r\n return 1 & e ? [0, e + 2, 0, e] : [0, e + 1, 0, e - 1]\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - i < c && (o(), c >= r) ? t.write(n) : (u.write(n, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim()).map(n => n + 1)\r\n n.println(t.join(' '))\r\n }\r\n function e(n, t) {\r\n const e = n >> 1\r\n for (let r = e; r < n; ++r) if ('0' === t[r]) return [0, r, 0, r - 1]\r\n for (let r = 0, u = n - e; r < u; ++r)\r\n if ('0' === t[r]) return [r, n - 1, r + 1, n - 1]\r\n return 1 & e ? [0, e + 1, 0, e - 1] : [0, e + 2, 0, e]\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - i < c && (o(), c >= r) ? t.write(n) : (u.write(n, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim()).map(n => n + 1)\r\n n.println(t.join(' '))\r\n }\r\n function e(n, t) {\r\n const e = n >> 1\r\n for (let r = e; r < n; ++r) if ('0' === t[r]) return [0, r, 0, r - 1]\r\n for (let r = 0, u = n - e; r < u; ++r)\r\n if ('0' === t[r]) return [r, n - 1, r + 1, n - 1]\r\n return [-1, -1, -1, -1]\r\n }\r\n})\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n c('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n c(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(n) {\r\n const c = Buffer.byteLength(n, e)\r\n r - i < c && (o(), c >= r) ? t.write(n) : (u.write(n, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim()).map(n => n + 1)\r\n n.println(t.join(' '))\r\n }\r\n function e(n, t) {\r\n const e = n >> 1\r\n for (let r = e; r < n; ++r) if ('0' === t[r]) return [0, r - 1, 0, r]\r\n for (let r = 0, u = n - e; r < u; ++r)\r\n if ('0' === t[r]) return [r, n - 1, r + 1, n - 1]\r\n return [-1, -1, -1, -1]\r\n }\r\n})\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet zeroPos;\r\n\t\tlet mid = (n >> 1) - 1;\r\n\t\tfor (let i = mid + 1; i < n; i++) if (s[i] == '0') zeroPos = i;\r\n\t\tconsole.log(zeroPos);\r\n\r\n\t\tif (zeroPos) {\r\n\t\t\t++zeroPos;\r\n\t\t\tconsole.log(1, zeroPos, 1, zeroPos - 1);\r\n\t\t} else {\r\n\t\t\tif (s[mid] == '0') {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n, mid + 1, n);\r\n\t\t\t} else {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n - 1, mid + 1, n);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet zeroPos;\r\n\t\tlet mid = (n >> 1) - 1;\r\n\t\tfor (let i = mid + 1; i < n; i++) if (s[i] == '0') zeroPos = i;\r\n\r\n\t\tif (zeroPos) {\r\n\t\t\t++zeroPos;\r\n\t\t\tconsole.log(1, zeroPos - 1, 1, zeroPos);\r\n\t\t} else {\r\n\t\t\tif (s[mid] == '0') {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n, mid + 1, n);\r\n\t\t\t} else {\r\n\t\t\t\t++mid;\r\n\t\t\t\tconsole.log(mid, n - 1, mid + 1, n);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "eadc7f5e1043ac431984ec921c62892d"} {"source_code": "'use strict';\nvar n = parseInt(readline());\nvar max = -1;\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ').map(n => parseInt(n));\n max = Math.max(max, input[0] + input[1])\n}\nprint(max);", "positive_code": [{"source_code": "\nfunction main() {\n const cin = new Scanner();\n let a, b;\n let answer = 0;\n for (let t = cin.nextInt(); t !== 0; t -= 1) {\n [a, b] = cin.nextArray();\n answer = Math.max(answer, a + b);\n }\n console.log(answer);\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = Number) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); });\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n ans = Math.max(ans, a + b);\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "var n = +readline(), max = -1;\nwhile (n-->0){\n var ip = readline().split(' ').map(Number);\n max = Math.max(max,ip[0]+ip[1]);\n}\nprint(max);"}, {"source_code": "function main(){\n var n = parseInt(readline());\n var maxX = -1;\n var maxY = -1;\n var maxLength = 0;\n for(var i = 0; i < n; ++i){\n var point = readline().split(\" \").map(function(x) { return parseInt(x); });\n var x = point[0];\n var y = point[1];\n if(x + y> maxLength){\n maxLength = x + y;\n }\n }\n print(maxLength)\n}\n\n\nmain()"}, {"source_code": "var n = parseInt(readline());\nvar xYSum = 0;\n\nfor(var i = 0; i < n; i++)\n{\n var a = readline().split(\" \");\n var newXYSum = parseInt(a[0]) + parseInt(a[1]);\n\n if(newXYSum > xYSum)\n xYSum = newXYSum;\n}\n\nprint(xYSum);"}, {"source_code": "function Nur_Alam(){\n\n var n = readline();\n var c = -1;\n\n while(n--){\n var a= readline().split(' ').map(Number);\n c = Math.max(c, a[0]+a[1]);\n }\n print(c);\n}\n\nNur_Alam()\n"}, {"source_code": "var n = readline(); \nvar c = -1;\n\nwhile(n--){\n var a= readline().split(' ').map(Number);\n c = Math.max(c, a[0]+a[1]);\n}\nprint(c);"}, {"source_code": "function hlw_callme(){\n\n var n = readline();\n var c = -1;\n\n while(n--){\n var a= readline().split(' ').map(Number);\n c = Math.max(c, a[0]+a[1]);\n }\n print(c);\n}\n\nhlw_callme();"}], "negative_code": [{"source_code": "function main(){\n var n = parseInt(readline());\n var maxX = -1;\n var maxY = -1;\n var maxLength = 0;\n for(var i = 0; i < n; ++i){\n var point = readline().split(\" \").map(function(x) { return parseInt(x); });\n var x = point[0];\n var y = point[1];\n if(x * x + y * y > maxLength){\n maxLength = x * x + y * y;\n maxX = x;\n maxY = y;\n }\n }\n print(x + y)\n}\n\n\nmain()"}, {"source_code": "var ans = -1\nvar n = readline() \n\nfor(var i= 0; i < n; i++){\n var a = readline() \n var b = readline()\n\n var c = Math.max(c, a+b)\n}\nprint(c)"}, {"source_code": "var n = readline() \nvar c = -1\n\nfor(var i= 0; i < n; i++){\n var a = readline() \n var b = readline()\n\n c = Math.max(c, a+b)\n}\nprint(c)"}, {"source_code": "\nfunction main() {\n const cin = new Scanner();\n let a, b;\n let answer = 0;\n for (let t = cin.nextInt(); t !== 0; t -= 1) {\n [a, b] = cin.nextArray(Number);\n answer = Math.max(answer, a + b);\n }\n\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn = String) {\n const array = this.nextLine().split(' ');\n if (fn !== String)\n array.forEach((item, index, arr) => { arr[index] = fn(item); });\n return array;\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "src_uid": "7c41fb6212992d1b3b3f89694b579fea"} {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => {\n input += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n const numbers = input.split(\"\\n\")[1].split(\" \").map(Number);\n numbers.sort((a, b) => a - b);\n const n = numbers.length;\n const [third, second, first, ...theRest] = numbers.reverse();\n if (third >= first + second) {\n console.log(\"NO\");\n return;\n }\n console.log(\"YES\");\n console.log([first, third, second, ...theRest].join(\" \"));\n});", "positive_code": [{"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar n = +readline();\nvar A = readline().split(' ').map(value => +value);\nA.sort((a, b) => b - a);\n\nif (A[0] >= A[1] + A[2]) {\n write('NO');\n} else {\n var result = A.filter((v, i) => !(i%2)).concat(A.filter((v, i) => !!(i%2)).reverse());\n write('YES\\n');\n write(result.join(' '));\n}\n\n"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map((i) =>parseInt(i) );\n \narr.sort((a, b) => a - b);\n \nif (arr[n - 1] >= arr[n - 2] + arr[n - 3]) {\n print(\"NO\");\n} else {\n print(\"YES\");\n \n var output = `${arr[n-2]} ${arr[n-1]} ${arr[n-3]} `;\n \n arr = arr.splice(0, n-3);\n \n output += arr.join(\" \");\n \n print(output);\n}\n\n"}, {"source_code": "readline();\nvar arr = readline().split(' ').map(item => +item).sort((var1, var2) => var2 - var1);\nif (arr[0] < arr[1] + arr[2]) {\n print('YES');\n print([arr[2], arr[0], arr[1]].concat(arr.slice(3)).join(' '))\n} else {\n print('NO');\n}\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(function(i) { return parseInt(i); });\n\narr.sort();\n\nif (arr[n - 1] >= arr[n - 2] + arr[n - 3]) {\n print(\"NO\");\n} else {\n print(\"YES\");\n print(arr.join(\" \"))\n}"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map((i) =>parseInt(i) );\n \narr.sort((a, b) => a - b);\n\nif (arr[n - 1] >= arr[n - 2] + arr[n - 3]) {\n print(\"NO\");\n} else {\n print(\"YES\");\n print(arr.join(\" \"))\n}"}, {"source_code": "console.log(\"YES\");\nconsole.log(\"4 2 3\");"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => {\n input += data;\n});\n\nprocess.stdin.on(\"end\", () => {\n console.log(\"YES\");\n console.log(\"4 2 3\");\n});"}], "src_uid": "a5ee97e99ecfe4b72c0642546746842a"} {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n // input: require('fs').createReadStream('input.txt'),\r\n input: process.stdin,\r\n output: process.stdout\r\n // removeHistoryDuplicates: true\r\n});\r\n\r\nconst it = rl[Symbol.asyncIterator]();\r\n\r\nconst main = async () => {\r\n // let use_case;\r\n // while(true){use_case = await it.next();if(use_case.value !== '')break;}\r\n let t = (await it.next()).value;\r\n // let test_case = Number(t);\r\n let r_t= 1;\r\n while(t--)\r\n {\r\n let n;\r\n while(true){n = await it.next();if(n.value !== '')break;}\r\n // n = Number(n.value);\r\n let arr;\r\n while(true){arr = await it.next();if(arr.value !== '')break;}\r\n arr = arr.value.split(' ').map(x => Number(x))\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n console.log(count);\r\n // r_t++;\r\n }\r\n\r\n}\r\nmain();\r\n", "positive_code": [{"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n let resultString = \"\";\n \n for (let i=0; i {\n return +(string);\n });\n\n let result = [];\n\n let h = arr[0];\n let l = arr[0];\n let index = 0;\n\n result.push({\n h: h,\n l:l\n });\n\n for (let i = 1; i < lengthOfArr; i++) {\n let num = arr[i];\n\n if (num < h) {\n if (num < l) {\n l = num;\n result[index].l = l;\n }\n\n let prevWasHigher = true;\n \n do {\n if (index > 0 && result[index-1].h > l) {\n index--;\n result[index].h = h;\n result[index].l = l;\n\n result.pop();\n } else {\n prevWasHigher = false;\n } \n } while (prevWasHigher);\n }\n else {\n result[index] = {\n h:h,\n l:l\n };\n\n h = num;\n l = num;\n\n result.push({\n h: h,\n l:l\n });\n\n index++;\n }\n }\n \n resultString += result.length + \"\\n\";\n }\n\n console.log(resultString);\n //console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let result = [];\n\n let h = arr[0];\n let l = arr[0];\n let index = 0;\n\n result.push({\n h: h,\n l:l\n });\n\n for (let i = 1; i < lengthOfArr; i++) {\n let num = arr[i];\n\n if (num < h) {\n if (num < l) {\n l = num;\n result[index].l = l;\n }\n\n let prevWasHigher = true;\n \n do {\n if (index > 0 && result[index-1].h > l) {\n index--;\n result[index].h = h;\n result[index].l = l;\n\n result.pop();\n } else {\n prevWasHigher = false;\n } \n } while (prevWasHigher);\n }\n else {\n result[index] = {\n h:h,\n l:l\n };\n\n h = num;\n l = num;\n\n result.push({\n h: h,\n l:l\n });\n\n index++;\n }\n }\n \n console.log(result.length);\n }\n\n //console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n // input: require('fs').createReadStream('input.txt'),\r\n input: process.stdin,\r\n output: process.stdout,\r\n crlfDelay: Infinity,\r\n});\r\n\r\nconst it = rl[Symbol.asyncIterator]();\r\n\r\nconst main = async () => {\r\n let t = (await it.next()).value;\r\n while(t--)\r\n {\r\n let n = Number((await it.next()).value);\r\n let arr = (await it.next()).value.split(' ').map(x => Number(x))\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n console.log(count);\r\n }\r\n\r\n}\r\nmain();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet stdinInput = '';\r\n \r\nprocess.stdin.on('data', input => {\r\n stdinInput += input;\r\n})\r\n \r\nprocess.stdin.on('end', () => {\r\n main(stdinInput);\r\n})\r\n\r\nconst main = (data) => {\r\n data = data.split('\\n');\r\n let t = Number(data[0])\r\n // let test_case = Number(t);\r\n let line=1;\r\n let r_t= 1;\r\n while(t--)\r\n {\r\n const n = Number(data[line]);\r\n line++;\r\n let i_arr = (data[line]);\r\n line++;\r\n let arr = i_arr.split(' ').map( x => Number(x));\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n // count++;\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n console.log(count);\r\n // }\r\n r_t++;\r\n }\r\n\r\n}"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nclass DSU {\n constructor(n){\n this.parents = new Array(n).fill(0);\n this.rank = new Array(n).fill(0);\n for (let i=0; i0.5 ?\n new HeapNode(node1.value, node1.l, HeapNode.merge(node1.r, node2)) :\n new HeapNode(node1.value, HeapNode.merge(node1.l, node2), node1.r);\n }\n}\n\nconst calc = (n, P)=>{\n let dsu = new DSU(n);\n let heap = new Heap();\n for (let i=0; iel){\n max = Math.max(max, heap.top());\n dsu.unite(heap.pop(), el);\n }\n heap.push(max);\n }\n let set = new Set();\n for (let i=0; i {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testCount = +readline();\n\tlet resultString = \"\";\n\n\tfor (let i = 0; i < testCount; i++) {\n\t\tlet arrayLength = +readline();\n\t\tlet perm = readline()\n\t\t\t.split(\" \")\n\t\t\t.map((e) => +e);\n\n\t\tlet result = 0;\n\t\tlet biggest = perm.length;\n\n\t\tconst indexLookup = {};\n\t\tperm.forEach((e, i) => {\n\t\t\tindexLookup[e] = i;\n\t\t});\n\n\t\twhile (perm.length > 0) {\n\t\t\tlet index = indexLookup[biggest];\n\n\t\t\twhile (index >= perm.length) {\n\t\t\t\tbiggest--;\n\t\t\t\tindex = indexLookup[biggest];\n\t\t\t}\n\n\t\t\tlet end = perm.splice(index);\n\n\t\t\tif (end.length === 1) {\n\t\t\t\tresult++;\n\t\t\t} else {\n\t\t\t\tconst smallest = end.reduce((small, element) => {\n\t\t\t\t\treturn Math.min(small, element);\n\t\t\t\t}, Infinity);\n\t\t\t\tperm.push(smallest);\n\t\t\t\tindexLookup[smallest] = perm.length - 1;\n\t\t\t}\n\t\t\tbiggest--;\n\t\t}\n\n\t\tresultString += result + \"\\n\";\n\t}\n\n\tconsole.log(resultString);\n}\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testCount = +readline();\n\n\tfor (let i = 0; i < testCount; i++) {\n\t\tlet arrayLength = +readline();\n\t\tlet perm = readline()\n\t\t\t.split(\" \")\n\t\t\t.map((e) => +e);\n\n\t\tlet result = 0;\n\t\tlet biggest = perm.length;\n\n\t\tconst indexLookup = {};\n\t\tperm.forEach((e, i) => {\n\t\t\tindexLookup[e] = i;\n\t\t});\n\n\t\twhile (perm.length > 0) {\n\t\t\tlet index = indexLookup[biggest];\n\n\t\t\twhile (index >= perm.length) {\n\t\t\t\tbiggest--;\n\t\t\t\tindex = indexLookup[biggest];\n\t\t\t}\n\n\t\t\tlet end = perm.splice(index);\n\n\t\t\tif (end.length === 1) {\n\t\t\t\tresult++;\n\t\t\t} else {\n\t\t\t\tconst smallest = end.reduce((small, element) => {\n\t\t\t\t\treturn Math.min(small, element);\n\t\t\t\t}, Infinity);\n\t\t\t\tperm.push(smallest);\n\t\t\t\tindexLookup[smallest] = perm.length - 1;\n\t\t\t}\n\t\t\tbiggest--;\n\t\t}\n\n\t\tconsole.log(result);\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const st = [n - 1];\r\n const uf = new UnionFind(n);\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (a[i] > a[st[st.length - 1]]) {\r\n let t = st[st.length - 1];\r\n while (st.length && a[i] > a[st[st.length - 1]]) {\r\n const j = st.pop();\r\n uf.union(i, j);\r\n }\r\n st.push(t);\r\n }\r\n if (a[i] < a[st[st.length - 1]]) st.push(i);\r\n }\r\n const roots = new Set();\r\n for (let i = 0; i < n; i++) {\r\n roots.add(uf.find(i));\r\n }\r\n return roots.size;\r\n}\r\nclass UnionFind {\r\n constructor(n) {\r\n this.p = [...new Array(n).keys()];\r\n this.find = this.find.bind(this);\r\n this.union = this.union.bind(this);\r\n this.isConnect = this.isConnect.bind(this);\r\n }\r\n find(i) {\r\n const {\r\n p\r\n } = this;\r\n while (p[i] !== i) {\r\n p[i] = p[p[i]];\r\n i = p[i];\r\n }\r\n return p[i];\r\n }\r\n union(i, j) {\r\n const {\r\n p,\r\n find\r\n } = this;\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n }\r\n isConnect(i, j) {\r\n const {\r\n find\r\n } = this;\r\n const ri = find(i),\r\n rj = find(j);\r\n return ri === rj;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let max = -1,\r\n ans = 0;\r\n for (let i = 0; i < n; i++) {\r\n max = Math.max(arr[i], max);\r\n if (max === i + 1) ans++;\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n\r\nfor (var i = 0; i < tests; i++) {\r\n var n = parseInt(readline());\r\n var arr = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\n var el = arr[0];\r\n var min = el;\r\n var cuts = [];\r\n for (var j = 1; j < arr.length; j++) {\r\n min = Math.min(min, arr[j]);\r\n if (arr[j] > el) {\r\n cuts.push([min, el]);\r\n el = arr[j];\r\n min = el;\r\n }\r\n }\r\n cuts.push([min, el]);\r\n cuts.sort((a, b) => a[0] - b[0]);\r\n var sum = 1;\r\n var max = cuts[0][1];\r\n for (var j = 1; j < cuts.length; j++) {\r\n if (cuts[j][0] < max) max = Math.max(max, cuts[j][1]);\r\n else {\r\n sum++;\r\n max = cuts[j][1];\r\n }\r\n }\r\n print(sum);\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let result = 0;\n\n let componentArr = [];\n let unusedComponentID = 0;\n\n for (let id = 0; id < lengthOfArr; id++) {\n componentArr[id] = undefined;\n }\n\n for (let i = 0; i < lengthOfArr; i++) {\n for (let j = lengthOfArr-1; j > 0; j--) {\n if (i < j && arr[i] > arr[j]) {\n if (componentArr[i] === undefined && componentArr[j] === undefined) {\n componentArr[i] = unusedComponentID;\n componentArr[j] = unusedComponentID;\n unusedComponentID++;\n }\n else if (componentArr[j] === undefined) {\n componentArr[j] = componentArr[i];\n }\n else {\n for (let n=j+1; n {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let result = 0;\n\n let componentArr = [];\n let unusedComponentID = 0;\n\n for (let id = 0; id < lengthOfArr; id++) {\n componentArr[id] = undefined;\n }\n\n for (let i = 0; i < lengthOfArr; i++) {\n for (let j = lengthOfArr-1; j > 0; j--) {\n if (i < j && arr[i] > arr[j]) {\n if (componentArr[i] === undefined) {\n componentArr[i] = unusedComponentID;\n componentArr[j] = unusedComponentID;\n unusedComponentID++;\n }\n else if (componentArr[j] === undefined) {\n componentArr[j] = componentArr[i];\n }\n else {\n for (let n=j+1; n {\r\n const use_cases = await it.next();\r\n let t = use_cases.value;\r\n let test_case = Number(t);\r\n let r_t= 1;\r\n while(t--)\r\n {\r\n const n = Number((await it.next()).value);\r\n let arr = (await it.next()).value.split(' ').map( x => Number(x));\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n // count++;\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n // if(test_case === 100000)\r\n // {\r\n // if(r_t === 10922)\r\n // {\r\n // console.log(arr);\r\n // }\r\n // }else{\r\n console.log(count);\r\n // }\r\n r_t++;\r\n }\r\n\r\n}\r\nmain();\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n // input: require('fs').createReadStream('../input.txt')\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst it = rl[Symbol.asyncIterator]();\r\n\r\nconst main = async () => {\r\n const use_cases = await it.next();\r\n let t = use_cases.value;\r\n let test_case = Number(t);\r\n let r_t= 1;\r\n while(t--)\r\n {\r\n const n = Number((await it.next()).value);\r\n let arr = (await it.next()).value.split(' ').map( x => Number(x));\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n // count++;\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n if(test_case === 100000)\r\n {\r\n if(r_t === 10922)\r\n {\r\n console.log(arr);\r\n }\r\n }else{\r\n console.log(count);\r\n }\r\n r_t++;\r\n }\r\n\r\n}\r\nmain();\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n // input: require('fs').createReadStream('../input.txt')\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst it = rl[Symbol.asyncIterator]();\r\n\r\nconst main = async () => {\r\n const use_cases = await it.next();\r\n let t = use_cases.value;\r\n while(t--)\r\n {\r\n const n = Number((await it.next()).value);\r\n let arr = (await it.next()).value.split(' ').map( x => Number(x));\r\n let el = 0;\r\n let count = 0;\r\n let rem = 0;\r\n arr.forEach(element => {\r\n\r\n if(element > el)\r\n {\r\n // count++;\r\n rem = rem + (element - el - 1);\r\n\r\n el = element;\r\n }else{\r\n rem--;\r\n }\r\n\r\n if(rem === 0)\r\n {\r\n count++;\r\n }\r\n\r\n })\r\n console.log(count);\r\n }\r\n\r\n}\r\nmain();\r\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testCount = +readline();\n\n\tfor (let i = 0; i < testCount; i++) {\n\t\tlet arrayLength = +readline();\n\t\tlet perm = readline()\n\t\t\t.split(\" \")\n\t\t\t.map((e) => +e);\n\n\t\tlet n = 0;\n\n\t\tconst graph = {};\n\n\t\tperm.forEach((value, index) => {\n\t\t\tgraph[index] = { edges: [], index };\n\t\t});\n\n\t\tperm.forEach((value, i) => {\n\t\t\tperm.forEach((element, j) => {\n\t\t\t\tif (j > i && element < value) {\n\t\t\t\t\tgraph[i].edges.push(j);\n\t\t\t\t\tgraph[j].edges.push(i);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\twhile (perm.length > 0) {\n\t\t\tlet component = [graph[0]];\n\t\t\tlet j = 0;\n\t\t\twhile (component[j]) {\n\t\t\t\tconst { edges } = component[j];\n\t\t\t\tedges.forEach((edge) => {\n\t\t\t\t\tif (component.indexOf(graph[edge]) === -1) {\n\t\t\t\t\t\tcomponent.push(graph[edge]);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tn++;\n\n\t\t\tcomponent = component.sort(({ index }, { index: index2 }) => {\n\t\t\t\treturn index - index2;\n\t\t\t});\n\n\t\t\tfor (let k = component.length - 1; k >= 0; k--) {\n\t\t\t\tlet { index } = component[k];\n\t\t\t\tperm.splice(index, 1);\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(n);\n\t}\n}\n"}], "src_uid": "b371d47ea08091917ab632e559ee75c6"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar costs = {\n\t\tticket: data[0],\n\t\tline: data[1],\n\t\tbusesOrTrolleys: data[2],\n\t\tallLines: data[3] };\n\n\treadline();\n\tvar busCounts = tokenizeIntegers(readline()),\n\t\ttrolleyCounts = tokenizeIntegers(readline());\n\n\tvar best = costs.allLines;\n\tbest = Math.min(best, 2*costs.busesOrTrolleys);\n\n\tfunction bestCost(counts) {\n\t\tvar total = 0;\n\t\tfor (var countIndex = 0; countIndex < counts.length; ++countIndex) {\n\t\t\ttotal += Math.min(costs.line, counts[countIndex]*costs.ticket);\n\t\t}\n\t\treturn total;\n\t}\n\n\tbest = Math.min(best, costs.busesOrTrolleys +\n\t\t\tMath.min(bestCost(busCounts), bestCost(trolleyCounts)));\n\tbest = Math.min(best, bestCost(busCounts) + bestCost(trolleyCounts));\n\tprint(best);\n}\n\nmain();\n", "positive_code": [{"source_code": "(function main() {\n var c = readline().split(' ').map(function(i){return parseInt(i);});\n var n = readline().split(' ').map(function(i){return parseInt(i);});\n var a = readline().split(' ').map(function(i){return Math.min(parseInt(i) * c[0], c[1]);});\n var b = readline().split(' ').map(function(i){return Math.min(parseInt(i) * c[0], c[1]);});\n var s0 = Math.min(a.reduce(function(a, b){return a + b;}), c[2]);\n var s1 = Math.min(b.reduce(function(a, b){return a + b;}), c[2]); \n print(Math.min(s0 + s1, c[3]));\n})();"}], "negative_code": [], "src_uid": "11fabde93815c1805369bbbc5a40e2d8"} {"source_code": "/* Usage:\n 1) install: (for browser)\n \n $ npm install bignumber.js (for NodeJS)\n const BigNumber = require('bignumber.js');\n\n 2) let x = new BigNumber(123.4567);\n let y = BigNumber('123456.7e-3');\n let z = new BigNumber(x);\n x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true\n\n 3) To get the string value of a BigNumber use toString() or toFixed().\n Using toFixed() prevents exponential notation being returned, no matter how large or small the value.\n\n let x = new BigNumber('1111222233334444555566');\n x.toString(); // \"1.111222233334444555566e+21\"\n x.toFixed(); // \"1111222233334444555566\"\n\n 4) // Precision loss from using numeric literals with more than 15 significant digits.\n new BigNumber(1.0000000000000001) // '1'\n new BigNumber(88259496234518.57) // '88259496234518.56'\n new BigNumber(99999999999999999999) // '100000000000000000000'\n\n // Precision loss from using numeric literals outside the range of Number values.\n new BigNumber(2e+308) // 'Infinity'\n new BigNumber(1e-324) // '0'\n\n // Precision loss from the unexpected result of arithmetic with Number values.\n new BigNumber(0.7 + 0.1) // '0.7999999999999999'\n\n When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal toString() value.\n\n 5) BigNumbers can be created from values in bases from 2 to 36. See ALPHABET to extend this range.\n\n a = new BigNumber(1011, 2) // \"11\"\n b = new BigNumber('zz.9', 36) // \"1295.25\"\n c = a.plus(b) // \"1306.25\"\n\n 6) A BigNumber is immutable in the sense that it is not changed by its methods.\n\n 0.3 - 0.1 // 0.19999999999999998\n x = new BigNumber(0.3)\n x.minus(0.1) // \"0.2\"\n x // \"0.3\"\n\n 7) The methods that return a BigNumber can be chained.\n\n x.dividedBy(y).plus(z).times(9)\n x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()\n x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true\n x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true\n\n 8) As with JavaScript's Number type, there are toExponential, toFixed and toPrecision methods.\n\n x = new BigNumber(255.5)\n x.toExponential(5) // \"2.55500e+2\"\n x.toFixed(5) // \"255.50000\"\n x.toPrecision(5) // \"255.50\"\n x.toNumber() // 255.5\n\n 9) A base can be specified for toString.\n\n x.toString(16) // \"ff.8\"\n\n 10) isNaN and isFinite methods, as NaN and Infinity are valid BigNumber values.\n\n x = new BigNumber(NaN) // \"NaN\"\n y = new BigNumber(Infinity) // \"Infinity\"\n x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true\n\n 11) https://github.com/MikeMcl/bignumber.js\n\n 12) GCD for all numbers from big segment [a...b]:\n\n function nod(a, b) {\n while (a.gt(0) && b.gt(0)) {\n if (a.gt(b))\n a = a.mod(b);\n else\n b = b.mod(a);\n }\n return a.plus(b);\n }\n\n var nums = readline().split(' ').map(function(x) { return BigNumber(x) });\n var a = nums[0];\n var b = nums[1];\n var res = a;\n a = a.plus(1);\n while (a.lte(b) && res.gt(1)) {\n res = nod(res, a);\n a = a.plus(1);\n }\n print(res.toFixed());\n\n 13) \n*/\n\n;(function (globalObject) {\n 'use strict';\n\n var BigNumber,\n isNumeric = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/i,\n mathceil = Math.ceil,\n mathfloor = Math.floor,\n bignumberError = '[BigNumber Error] ',\n tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',\n BASE = 1e14,\n LOG_BASE = 14,\n MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1\n POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],\n SQRT_BASE = 1e7,\n MAX = 1E9; // 0 to MAX_INT32\n\n function clone(configObject) {\n var div, convertBase, parseNumeric,\n P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },\n ONE = new BigNumber(1),\n\n // The maximum number of decimal places for operations involving division.\n DECIMAL_PLACES = 1000, // 0 to MAX\n ROUNDING_MODE = 4, // 0 to 8\n\n // The exponent value at and beneath which toString returns exponential notation.\n TO_EXP_NEG = -1000, // 0 to -MAX\n // The exponent value at and above which toString returns exponential notation.\n TO_EXP_POS = 1000, // 0 to MAX\n MIN_EXP = -1e8, // -1 to -MAX\n MAX_EXP = 1e8, // 1 to MAX\n\n CRYPTO = false, // true or false\n MODULO_MODE = 1, // 0 to 9\n POW_PRECISION = 0, // 0 to MAX\n FORMAT = {\n prefix: '',\n groupSize: 3,\n secondaryGroupSize: 0,\n groupSeparator: ',',\n decimalSeparator: '.',\n fractionGroupSize: 0,\n fractionGroupSeparator: '\\xA0', // non-breaking space\n suffix: ''\n },\n ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n function BigNumber(n, b) {\n var alphabet, c, caseChanged, e, i, isNum, len, str,\n x = this;\n if (!(x instanceof BigNumber)) {\n return new BigNumber(n, b);\n }\n if (b == null) {\n if (n instanceof BigNumber) {\n x.s = n.s;\n x.e = n.e;\n x.c = (n = n.c) ? n.slice() : n;\n return;\n }\n isNum = typeof n == 'number';\n if (isNum && n * 0 == 0) {\n x.s = 1 / n < 0 ? (n = -n, -1) : 1;\n if (n === ~~n) {\n for (e = 0, i = n; i >= 10; i /= 10, e++);\n x.e = e;\n x.c = [n];\n return;\n }\n str = String(n);\n } else {\n str = String(n);\n if (!isNumeric.test(str)) return parseNumeric(x, str, isNum);\n x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;\n }\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n if ((i = str.search(/e/i)) > 0) {\n if (e < 0) e = i;\n e += +str.slice(i + 1);\n str = str.substring(0, i);\n } else if (e < 0) {\n e = str.length;\n }\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = String(n);\n if (b == 10) {\n x = new BigNumber(n instanceof BigNumber ? n : str);\n return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);\n }\n isNum = typeof n == 'number';\n if (isNum) {\n if (n * 0 != 0) return parseNumeric(x, str, isNum, b);\n x.s = 1 / n < 0 ? (str = str.slice(1), -1) : 1;\n if (BigNumber.DEBUG && str.replace(/^0\\.0*|\\./, '').length > 15) {\n throw Error\n (tooManyDigits + n);\n }\n isNum = false;\n } else {\n x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;\n }\n alphabet = ALPHABET.slice(0, b);\n e = i = 0;\n for (len = str.length; i < len; i++) {\n if (alphabet.indexOf(c = str.charAt(i)) < 0) {\n if (c == '.') {\n if (i > e) {\n e = len;\n continue;\n }\n } else if (!caseChanged) {\n if (str == str.toUpperCase() && (str = str.toLowerCase()) ||\n str == str.toLowerCase() && (str = str.toUpperCase())) {\n caseChanged = true;\n i = -1;\n e = 0;\n continue;\n }\n }\n return parseNumeric(x, String(n), isNum, b);\n }\n }\n str = convertBase(str, b, 10, x.s);\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n else e = str.length;\n }\n for (i = 0; str.charCodeAt(i) === 48; i++);\n for (len = str.length; str.charCodeAt(--len) === 48;);\n str = str.slice(i, ++len);\n if (str) {\n len -= i;\n if (isNum && BigNumber.DEBUG &&\n len > 15 && (n > MAX_SAFE_INTEGER || n !== mathfloor(n))) {\n throw Error\n (tooManyDigits + (x.s * n));\n }\n e = e - i - 1;\n if (e > MAX_EXP) {\n x.c = x.e = null;\n } else if (e < MIN_EXP) {\n x.c = [x.e = 0];\n } else {\n x.e = e;\n x.c = [];\n i = (e + 1) % LOG_BASE;\n if (e < 0) i += LOG_BASE;\n if (i < len) {\n if (i) x.c.push(+str.slice(0, i));\n for (len -= LOG_BASE; i < len;) {\n x.c.push(+str.slice(i, i += LOG_BASE));\n }\n str = str.slice(i);\n i = LOG_BASE - str.length;\n } else {\n i -= len;\n }\n for (; i--; str += '0');\n x.c.push(+str);\n }\n } else {\n x.c = [x.e = 0];\n }\n }\n\n BigNumber.clone = clone;\n BigNumber.ROUND_UP = 0;\n BigNumber.ROUND_DOWN = 1;\n BigNumber.ROUND_CEIL = 2;\n BigNumber.ROUND_FLOOR = 3;\n BigNumber.ROUND_HALF_UP = 4;\n BigNumber.ROUND_HALF_DOWN = 5;\n BigNumber.ROUND_HALF_EVEN = 6;\n BigNumber.ROUND_HALF_CEIL = 7;\n BigNumber.ROUND_HALF_FLOOR = 8;\n BigNumber.EUCLID = 9;\n\n BigNumber.config = BigNumber.set = function (obj) {\n var p, v;\n if (obj != null) {\n if (typeof obj == 'object') {\n if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n DECIMAL_PLACES = v;\n }\n if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {\n v = obj[p];\n intCheck(v, 0, 8, p);\n ROUNDING_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, 0, p);\n intCheck(v[1], 0, MAX, p);\n TO_EXP_NEG = v[0];\n TO_EXP_POS = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);\n }\n }\n if (obj.hasOwnProperty(p = 'RANGE')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, -1, p);\n intCheck(v[1], 1, MAX, p);\n MIN_EXP = v[0];\n MAX_EXP = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n if (v) {\n MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);\n } else {\n throw Error\n (bignumberError + p + ' cannot be zero: ' + v);\n }\n }\n }\n if (obj.hasOwnProperty(p = 'CRYPTO')) {\n v = obj[p];\n if (v === !!v) {\n if (v) {\n if (typeof crypto != 'undefined' && crypto &&\n (crypto.getRandomValues || crypto.randomBytes)) {\n CRYPTO = v;\n } else {\n CRYPTO = !v;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n } else {\n CRYPTO = v;\n }\n } else {\n throw Error\n (bignumberError + p + ' not true or false: ' + v);\n }\n }\n if (obj.hasOwnProperty(p = 'MODULO_MODE')) {\n v = obj[p];\n intCheck(v, 0, 9, p);\n MODULO_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'POW_PRECISION')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n POW_PRECISION = v;\n }\n if (obj.hasOwnProperty(p = 'FORMAT')) {\n v = obj[p];\n if (typeof v == 'object') FORMAT = v;\n else throw Error\n (bignumberError + p + ' not an object: ' + v);\n }\n if (obj.hasOwnProperty(p = 'ALPHABET')) {\n v = obj[p];\n if (typeof v == 'string' && !/^.$|[+-.\\s]|(.).*\\1/.test(v)) {\n ALPHABET = v;\n } else {\n throw Error\n (bignumberError + p + ' invalid: ' + v);\n }\n }\n } else {\n throw Error\n (bignumberError + 'Object expected: ' + obj);\n }\n }\n\n return {\n DECIMAL_PLACES: DECIMAL_PLACES,\n ROUNDING_MODE: ROUNDING_MODE,\n EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],\n RANGE: [MIN_EXP, MAX_EXP],\n CRYPTO: CRYPTO,\n MODULO_MODE: MODULO_MODE,\n POW_PRECISION: POW_PRECISION,\n FORMAT: FORMAT,\n ALPHABET: ALPHABET\n };\n };\n\n BigNumber.isBigNumber = function (v) {\n return v instanceof BigNumber || v && v._isBigNumber === true || false;\n };\n\n BigNumber.maximum = BigNumber.max = function () {\n return maxOrMin(arguments, P.lt);\n };\n\n BigNumber.minimum = BigNumber.min = function () {\n return maxOrMin(arguments, P.gt);\n };\n\n BigNumber.random = (function () {\n var pow2_53 = 0x20000000000000;\n var random53bitInt = (Math.random() * pow2_53) & 0x1fffff\n ? function () { return mathfloor(Math.random() * pow2_53); }\n : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +\n (Math.random() * 0x800000 | 0); };\n return function (dp) {\n var a, b, e, k, v,\n i = 0,\n c = [],\n rand = new BigNumber(ONE);\n if (dp == null) dp = DECIMAL_PLACES;\n else intCheck(dp, 0, MAX);\n k = mathceil(dp / LOG_BASE);\n if (CRYPTO) {\n if (crypto.getRandomValues) {\n a = crypto.getRandomValues(new Uint32Array(k *= 2));\n for (; i < k;) {\n v = a[i] * 0x20000 + (a[i + 1] >>> 11);\n if (v >= 9e15) {\n b = crypto.getRandomValues(new Uint32Array(2));\n a[i] = b[0];\n a[i + 1] = b[1];\n } else {\n c.push(v % 1e14);\n i += 2;\n }\n }\n i = k / 2;\n } else if (crypto.randomBytes) {\n a = crypto.randomBytes(k *= 7);\n for (; i < k;) {\n v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +\n (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +\n (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];\n if (v >= 9e15) {\n crypto.randomBytes(7).copy(a, i);\n } else {\n c.push(v % 1e14);\n i += 7;\n }\n }\n i = k / 7;\n } else {\n CRYPTO = false;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n }\n if (!CRYPTO) {\n for (; i < k;) {\n v = random53bitInt();\n if (v < 9e15) c[i++] = v % 1e14;\n }\n }\n k = c[--i];\n dp %= LOG_BASE;\n if (k && dp) {\n v = POWS_TEN[LOG_BASE - dp];\n c[i] = mathfloor(k / v) * v;\n }\n for (; c[i] === 0; c.pop(), i--);\n if (i < 0) {\n c = [e = 0];\n } else {\n for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);\n for (i = 1, v = c[0]; v >= 10; v /= 10, i++);\n if (i < LOG_BASE) e -= LOG_BASE - i;\n }\n rand.e = e;\n rand.c = c;\n return rand;\n };\n })();\n\n BigNumber.sum = function () {\n var i = 1,\n args = arguments,\n sum = new BigNumber(args[0]);\n for (; i < args.length;) sum = sum.plus(args[i++]);\n return sum;\n };\n\n convertBase = (function () {\n var decimal = '0123456789';\n function toBaseOut(str, baseIn, baseOut, alphabet) {\n var j,\n arr = [0],\n arrL,\n i = 0,\n len = str.length;\n for (; i < len;) {\n for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);\n arr[0] += alphabet.indexOf(str.charAt(i++));\n for (j = 0; j < arr.length; j++) {\n if (arr[j] > baseOut - 1) {\n if (arr[j + 1] == null) arr[j + 1] = 0;\n arr[j + 1] += arr[j] / baseOut | 0;\n arr[j] %= baseOut;\n }\n }\n }\n return arr.reverse();\n }\n return function (str, baseIn, baseOut, sign, callerIsToString) {\n var alphabet, d, e, k, r, x, xc, y,\n i = str.indexOf('.'),\n dp = DECIMAL_PLACES,\n rm = ROUNDING_MODE;\n if (i >= 0) {\n k = POW_PRECISION;\n POW_PRECISION = 0;\n str = str.replace('.', '');\n y = new BigNumber(baseIn);\n x = y.pow(str.length - i);\n POW_PRECISION = k;\n y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),\n 10, baseOut, decimal);\n y.e = y.c.length;\n }\n xc = toBaseOut(str, baseIn, baseOut, callerIsToString\n ? (alphabet = ALPHABET, decimal)\n : (alphabet = decimal, ALPHABET));\n e = k = xc.length;\n for (; xc[--k] == 0; xc.pop());\n if (!xc[0]) return alphabet.charAt(0);\n if (i < 0) {\n --e;\n } else {\n x.c = xc;\n x.e = e;\n x.s = sign;\n x = div(x, y, dp, rm, baseOut);\n xc = x.c;\n r = x.r;\n e = x.e;\n }\n d = e + dp + 1;\n i = xc[d];\n k = baseOut / 2;\n r = r || d < 0 || xc[d + 1] != null;\n r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (d < 1 || !xc[0]) {\n str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);\n } else {\n xc.length = d;\n if (r) {\n for (--baseOut; ++xc[--d] > baseOut;) {\n xc[d] = 0;\n if (!d) {\n ++e;\n xc = [1].concat(xc);\n }\n }\n }\n for (k = xc.length; !xc[--k];);\n for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));\n str = toFixedPoint(str, e, alphabet.charAt(0));\n }\n return str;\n };\n })();\n\n div = (function () {\n function multiply(x, k, base) {\n var m, temp, xlo, xhi,\n carry = 0,\n i = x.length,\n klo = k % SQRT_BASE,\n khi = k / SQRT_BASE | 0;\n for (x = x.slice(); i--;) {\n xlo = x[i] % SQRT_BASE;\n xhi = x[i] / SQRT_BASE | 0;\n m = khi * xlo + xhi * klo;\n temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;\n carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;\n x[i] = temp % base;\n }\n if (carry) x = [carry].concat(x);\n return x;\n }\n\n function compare(a, b, aL, bL) {\n var i, cmp;\n if (aL != bL) {\n cmp = aL > bL ? 1 : -1;\n } else {\n for (i = cmp = 0; i < aL; i++) {\n if (a[i] != b[i]) {\n cmp = a[i] > b[i] ? 1 : -1;\n break;\n }\n }\n }\n return cmp;\n }\n\n function subtract(a, b, aL, base) {\n var i = 0;\n for (; aL--;) {\n a[aL] -= i;\n i = a[aL] < b[aL] ? 1 : 0;\n a[aL] = i * base + a[aL] - b[aL];\n }\n for (; !a[0] && a.length > 1; a.splice(0, 1));\n }\n return function (x, y, dp, rm, base) {\n var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,\n yL, yz,\n s = x.s == y.s ? 1 : -1,\n xc = x.c,\n yc = y.c;\n if (!xc || !xc[0] || !yc || !yc[0]) {\n return new BigNumber(\n !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :\n xc && xc[0] == 0 || !yc ? s * 0 : s / 0\n );\n }\n q = new BigNumber(s);\n qc = q.c = [];\n e = x.e - y.e;\n s = dp + e + 1;\n if (!base) {\n base = BASE;\n e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);\n s = s / LOG_BASE | 0;\n }\n for (i = 0; yc[i] == (xc[i] || 0); i++);\n if (yc[i] > (xc[i] || 0)) e--;\n if (s < 0) {\n qc.push(1);\n more = true;\n } else {\n xL = xc.length;\n yL = yc.length;\n i = 0;\n s += 2;\n n = mathfloor(base / (yc[0] + 1));\n if (n > 1) {\n yc = multiply(yc, n, base);\n xc = multiply(xc, n, base);\n yL = yc.length;\n xL = xc.length;\n }\n xi = yL;\n rem = xc.slice(0, yL);\n remL = rem.length;\n for (; remL < yL; rem[remL++] = 0);\n yz = yc.slice();\n yz = [0].concat(yz);\n yc0 = yc[0];\n if (yc[1] >= base / 2) yc0++;\n do {\n n = 0;\n cmp = compare(yc, rem, yL, remL);\n if (cmp < 0) {\n rem0 = rem[0];\n if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);\n n = mathfloor(rem0 / yc0);\n if (n > 1) {\n if (n >= base) n = base - 1;\n prod = multiply(yc, n, base);\n prodL = prod.length;\n remL = rem.length;\n while (compare(prod, rem, prodL, remL) == 1) {\n n--;\n subtract(prod, yL < prodL ? yz : yc, prodL, base);\n prodL = prod.length;\n cmp = 1;\n }\n } else {\n if (n == 0) {\n cmp = n = 1;\n }\n prod = yc.slice();\n prodL = prod.length;\n }\n if (prodL < remL) prod = [0].concat(prod);\n subtract(rem, prod, remL, base);\n remL = rem.length;\n if (cmp == -1) {\n while (compare(yc, rem, yL, remL) < 1) {\n n++;\n subtract(rem, yL < remL ? yz : yc, remL, base);\n remL = rem.length;\n }\n }\n } else if (cmp === 0) {\n n++;\n rem = [0];\n }\n qc[i++] = n;\n if (rem[0]) {\n rem[remL++] = xc[xi] || 0;\n } else {\n rem = [xc[xi]];\n remL = 1;\n }\n } while ((xi++ < xL || rem[0] != null) && s--);\n more = rem[0] != null;\n if (!qc[0]) qc.splice(0, 1);\n }\n if (base == BASE) {\n for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);\n round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);\n } else {\n q.e = e;\n q.r = +more;\n }\n return q;\n };\n })();\n\n function format(n, i, rm, id) {\n var c0, e, ne, len, str;\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n if (!n.c) return n.toString();\n c0 = n.c[0];\n ne = n.e;\n if (i == null) {\n str = coeffToString(n.c);\n str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)\n ? toExponential(str, ne)\n : toFixedPoint(str, ne, '0');\n } else {\n n = round(new BigNumber(n), i, rm);\n e = n.e;\n str = coeffToString(n.c);\n len = str.length;\n if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {\n for (; len < i; str += '0', len++);\n str = toExponential(str, e);\n } else {\n i -= ne;\n str = toFixedPoint(str, e, '0');\n if (e + 1 > len) {\n if (--i > 0) for (str += '.'; i--; str += '0');\n } else {\n i += e - len;\n if (i > 0) {\n if (e + 1 == len) str += '.';\n for (; i--; str += '0');\n }\n }\n }\n }\n return n.s < 0 && c0 ? '-' + str : str;\n }\n\n function maxOrMin(args, method) {\n var n,\n i = 1,\n m = new BigNumber(args[0]);\n for (; i < args.length; i++) {\n n = new BigNumber(args[i]);\n if (!n.s) {\n m = n;\n break;\n } else if (method.call(m, n)) {\n m = n;\n }\n }\n return m;\n }\n\n function normalise(n, c, e) {\n var i = 1,\n j = c.length;\n for (; !c[--j]; c.pop());\n for (j = c[0]; j >= 10; j /= 10, i++);\n if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {\n n.c = n.e = null;\n } else if (e < MIN_EXP) {\n n.c = [n.e = 0];\n } else {\n n.e = e;\n n.c = c;\n }\n return n;\n }\n\n parseNumeric = (function () {\n var basePrefix = /^(-?)0([xbo])(?=\\w[\\w.]*$)/i,\n dotAfter = /^([^.]+)\\.$/,\n dotBefore = /^\\.([^.]+)$/,\n isInfinityOrNaN = /^-?(Infinity|NaN)$/,\n whitespaceOrPlus = /^\\s*\\+(?=[\\w.])|^\\s+|\\s+$/g;\n return function (x, str, isNum, b) {\n var base,\n s = isNum ? str : str.replace(whitespaceOrPlus, '');\n if (isInfinityOrNaN.test(s)) {\n x.s = isNaN(s) ? null : s < 0 ? -1 : 1;\n x.c = x.e = null;\n } else {\n if (!isNum) {\n s = s.replace(basePrefix, function (m, p1, p2) {\n base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;\n return !b || b == base ? p1 : m;\n });\n if (b) {\n base = b;\n s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');\n }\n if (str != s) return new BigNumber(s, base);\n }\n if (BigNumber.DEBUG) {\n throw Error\n (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);\n }\n x.c = x.e = x.s = null;\n }\n }\n })();\n\n function round(x, sd, rm, r) {\n var d, i, j, k, n, ni, rd,\n xc = x.c,\n pows10 = POWS_TEN;\n if (xc) {\n out: {\n for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);\n i = sd - d;\n if (i < 0) {\n i += LOG_BASE;\n j = sd;\n n = xc[ni = 0];\n rd = n / pows10[d - j - 1] % 10 | 0;\n } else {\n ni = mathceil((i + 1) / LOG_BASE);\n if (ni >= xc.length) {\n if (r) {\n for (; xc.length <= ni; xc.push(0));\n n = rd = 0;\n d = 1;\n i %= LOG_BASE;\n j = i - LOG_BASE + 1;\n } else {\n break out;\n }\n } else {\n n = k = xc[ni];\n for (d = 1; k >= 10; k /= 10, d++);\n i %= LOG_BASE;\n j = i - LOG_BASE + d;\n rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;\n }\n }\n r = r || sd < 0 ||\n xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);\n r = rm < 4\n ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&\n ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (sd < 1 || !xc[0]) {\n xc.length = 0;\n if (r) {\n sd -= x.e + 1;\n xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];\n x.e = -sd || 0;\n } else {\n xc[0] = x.e = 0;\n }\n return x;\n }\n if (i == 0) {\n xc.length = ni;\n k = 1;\n ni--;\n } else {\n xc.length = ni + 1;\n k = pows10[LOG_BASE - i];\n xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;\n }\n if (r) {\n for (; ;) {\n if (ni == 0) {\n for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);\n j = xc[0] += k;\n for (k = 1; j >= 10; j /= 10, k++);\n if (i != k) {\n x.e++;\n if (xc[0] == BASE) xc[0] = 1;\n }\n break;\n } else {\n xc[ni] += k;\n if (xc[ni] != BASE) break;\n xc[ni--] = 0;\n k = 1;\n }\n }\n }\n for (i = xc.length; xc[--i] === 0; xc.pop());\n }\n if (x.e > MAX_EXP) {\n x.c = x.e = null;\n } else if (x.e < MIN_EXP) {\n x.c = [x.e = 0];\n }\n }\n return x;\n }\n\n function valueOf(n) {\n var str,\n e = n.e;\n if (e === null) return n.toString();\n str = coeffToString(n.c);\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(str, e)\n : toFixedPoint(str, e, '0');\n return n.s < 0 ? '-' + str : str;\n }\n\n P.absoluteValue = P.abs = function () {\n var x = new BigNumber(this);\n if (x.s < 0) x.s = 1;\n return x;\n };\n\n P.comparedTo = function (y, b) {\n return compare(this, new BigNumber(y, b));\n };\n\n P.decimalPlaces = P.dp = function (dp, rm) {\n var c, n, v,\n x = this;\n if (dp != null) {\n intCheck(dp, 0, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), dp + x.e + 1, rm);\n }\n if (!(c = x.c)) return null;\n n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;\n if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);\n if (n < 0) n = 0;\n return n;\n };\n\n P.dividedBy = P.div = function (y, b) {\n return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);\n };\n\n P.dividedToIntegerBy = P.idiv = function (y, b) {\n return div(this, new BigNumber(y, b), 0, 1);\n };\n\n P.exponentiatedBy = P.pow = function (n, m) {\n var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,\n x = this;\n n = new BigNumber(n);\n if (n.c && !n.isInteger()) {\n throw Error\n (bignumberError + 'Exponent not an integer: ' + valueOf(n));\n }\n if (m != null) m = new BigNumber(m);\n nIsBig = n.e > 14;\n if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {\n y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));\n return m ? y.mod(m) : y;\n }\n nIsNeg = n.s < 0;\n if (m) {\n if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);\n isModExp = !nIsNeg && x.isInteger() && m.isInteger();\n if (isModExp) x = x.mod(m);\n } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0\n ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7\n : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {\n k = x.s < 0 && isOdd(n) ? -0 : 0;\n if (x.e > -1) k = 1 / k;\n return new BigNumber(nIsNeg ? 1 / k : k);\n } else if (POW_PRECISION) {\n k = mathceil(POW_PRECISION / LOG_BASE + 2);\n }\n if (nIsBig) {\n half = new BigNumber(0.5);\n if (nIsNeg) n.s = 1;\n nIsOdd = isOdd(n);\n } else {\n i = Math.abs(+valueOf(n));\n nIsOdd = i % 2;\n }\n y = new BigNumber(ONE);\n for (; ;) {\n if (nIsOdd) {\n y = y.times(x);\n if (!y.c) break;\n\n if (k) {\n if (y.c.length > k) y.c.length = k;\n } else if (isModExp) {\n y = y.mod(m);\n }\n }\n if (i) {\n i = mathfloor(i / 2);\n if (i === 0) break;\n nIsOdd = i % 2;\n } else {\n n = n.times(half);\n round(n, n.e + 1, 1);\n if (n.e > 14) {\n nIsOdd = isOdd(n);\n } else {\n i = +valueOf(n);\n if (i === 0) break;\n nIsOdd = i % 2;\n }\n }\n x = x.times(x);\n if (k) {\n if (x.c && x.c.length > k) x.c.length = k;\n } else if (isModExp) {\n x = x.mod(m);\n }\n }\n if (isModExp) return y;\n if (nIsNeg) y = ONE.div(y);\n return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;\n };\n\n P.integerValue = function (rm) {\n var n = new BigNumber(this);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(n, n.e + 1, rm);\n };\n\n P.isEqualTo = P.eq = function (y, b) {\n return compare(this, new BigNumber(y, b)) === 0;\n };\n\n P.isFinite = function () {\n return !!this.c;\n };\n\n P.isGreaterThan = P.gt = function (y, b) {\n return compare(this, new BigNumber(y, b)) > 0;\n };\n\n P.isGreaterThanOrEqualTo = P.gte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;\n\n };\n\n P.isInteger = function () {\n return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;\n };\n\n P.isLessThan = P.lt = function (y, b) {\n return compare(this, new BigNumber(y, b)) < 0;\n };\n\n P.isLessThanOrEqualTo = P.lte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;\n };\n\n P.isNaN = function () {\n return !this.s;\n };\n\n P.isNegative = function () {\n return this.s < 0;\n };\n\n P.isPositive = function () {\n return this.s > 0;\n };\n\n P.isZero = function () {\n return !!this.c && this.c[0] == 0;\n };\n\n P.minus = function (y, b) {\n var i, j, t, xLTy,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.plus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);\n if (!xc[0] || !yc[0]) {\n return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :\n ROUNDING_MODE == 3 ? -0 : 0);\n }\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (xLTy = a < 0) {\n a = -a;\n t = xc;\n } else {\n ye = xe;\n t = yc;\n }\n t.reverse();\n for (b = a; b--; t.push(0));\n t.reverse();\n } else {\n j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;\n for (a = b = 0; b < j; b++) {\n if (xc[b] != yc[b]) {\n xLTy = xc[b] < yc[b];\n break;\n }\n }\n }\n if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;\n b = (j = yc.length) - (i = xc.length);\n if (b > 0) for (; b--; xc[i++] = 0);\n b = BASE - 1;\n for (; j > a;) {\n if (xc[--j] < yc[j]) {\n for (i = j; i && !xc[--i]; xc[i] = b);\n --xc[i];\n xc[j] += BASE;\n }\n\n xc[j] -= yc[j];\n }\n for (; xc[0] == 0; xc.splice(0, 1), --ye);\n if (!xc[0]) {\n y.s = ROUNDING_MODE == 3 ? -1 : 1;\n y.c = [y.e = 0];\n return y;\n }\n return normalise(y, xc, ye);\n };\n\n P.modulo = P.mod = function (y, b) {\n var q, s,\n x = this;\n y = new BigNumber(y, b);\n if (!x.c || !y.s || y.c && !y.c[0]) {\n return new BigNumber(NaN);\n } else if (!y.c || x.c && !x.c[0]) {\n return new BigNumber(x);\n }\n if (MODULO_MODE == 9) {\n s = y.s;\n y.s = 1;\n q = div(x, y, 0, 3);\n y.s = s;\n q.s *= s;\n } else {\n q = div(x, y, 0, MODULO_MODE);\n }\n y = x.minus(q.times(y));\n if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;\n return y;\n };\n\n P.multipliedBy = P.times = function (y, b) {\n var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,\n base, sqrtBase,\n x = this,\n xc = x.c,\n yc = (y = new BigNumber(y, b)).c;\n if (!xc || !yc || !xc[0] || !yc[0]) {\n if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {\n y.c = y.e = y.s = null;\n } else {\n y.s *= x.s;\n if (!xc || !yc) {\n y.c = y.e = null;\n } else {\n y.c = [0];\n y.e = 0;\n }\n }\n return y;\n }\n e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);\n y.s *= x.s;\n xcL = xc.length;\n ycL = yc.length;\n if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;\n for (i = xcL + ycL, zc = []; i--; zc.push(0));\n base = BASE;\n sqrtBase = SQRT_BASE;\n for (i = ycL; --i >= 0;) {\n c = 0;\n ylo = yc[i] % sqrtBase;\n yhi = yc[i] / sqrtBase | 0;\n for (k = xcL, j = i + k; j > i;) {\n xlo = xc[--k] % sqrtBase;\n xhi = xc[k] / sqrtBase | 0;\n m = yhi * xlo + xhi * ylo;\n xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;\n c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;\n zc[j--] = xlo % base;\n }\n zc[j] = c;\n }\n if (c) {\n ++e;\n } else {\n zc.splice(0, 1);\n }\n return normalise(y, zc, e);\n };\n\n P.negated = function () {\n var x = new BigNumber(this);\n x.s = -x.s || null;\n return x;\n };\n\n P.plus = function (y, b) {\n var t,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.minus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return new BigNumber(a / 0);\n if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (a > 0) {\n ye = xe;\n t = yc;\n } else {\n a = -a;\n t = xc;\n }\n t.reverse();\n for (; a--; t.push(0));\n t.reverse();\n }\n a = xc.length;\n b = yc.length;\n if (a - b < 0) t = yc, yc = xc, xc = t, b = a;\n for (a = 0; b;) {\n a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;\n xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;\n }\n if (a) {\n xc = [a].concat(xc);\n ++ye;\n }\n return normalise(y, xc, ye);\n };\n\n P.precision = P.sd = function (sd, rm) {\n var c, n, v,\n x = this;\n if (sd != null && sd !== !!sd) {\n intCheck(sd, 1, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), sd, rm);\n }\n if (!(c = x.c)) return null;\n v = c.length - 1;\n n = v * LOG_BASE + 1;\n if (v = c[v]) {\n for (; v % 10 == 0; v /= 10, n--);\n for (v = c[0]; v >= 10; v /= 10, n++);\n }\n if (sd && x.e + 1 > n) n = x.e + 1;\n return n;\n };\n P.shiftedBy = function (k) {\n intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);\n return this.times('1e' + k);\n };\n P.squareRoot = P.sqrt = function () {\n var m, n, r, rep, t,\n x = this,\n c = x.c,\n s = x.s,\n e = x.e,\n dp = DECIMAL_PLACES + 4,\n half = new BigNumber('0.5');\n if (s !== 1 || !c || !c[0]) {\n return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);\n }\n s = Math.sqrt(+valueOf(x));\n if (s == 0 || s == 1 / 0) {\n n = coeffToString(c);\n if ((n.length + e) % 2 == 0) n += '0';\n s = Math.sqrt(+n);\n e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);\n\n if (s == 1 / 0) {\n n = '1e' + e;\n } else {\n n = s.toExponential();\n n = n.slice(0, n.indexOf('e') + 1) + e;\n }\n r = new BigNumber(n);\n } else {\n r = new BigNumber(s + '');\n }\n if (r.c[0]) {\n e = r.e;\n s = e + dp;\n if (s < 3) s = 0;\n for (; ;) {\n t = r;\n r = half.times(t.plus(div(x, t, dp, 1)));\n if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {\n if (r.e < e) --s;\n n = n.slice(s - 3, s + 1);\n if (n == '9999' || !rep && n == '4999') {\n if (!rep) {\n round(t, t.e + DECIMAL_PLACES + 2, 0);\n\n if (t.times(t).eq(x)) {\n r = t;\n break;\n }\n }\n dp += 4;\n s += 4;\n rep = 1;\n } else {\n if (!+n || !+n.slice(1) && n.charAt(0) == '5') {\n round(r, r.e + DECIMAL_PLACES + 2, 1);\n m = !r.times(r).eq(x);\n }\n break;\n }\n }\n }\n }\n\n return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);\n };\n\n P.toExponential = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp++;\n }\n return format(this, dp, rm, 1);\n };\n\n P.toFixed = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp = dp + this.e + 1;\n }\n return format(this, dp, rm);\n };\n\n P.toFormat = function (dp, rm, format) {\n var str,\n x = this;\n\n if (format == null) {\n if (dp != null && rm && typeof rm == 'object') {\n format = rm;\n rm = null;\n } else if (dp && typeof dp == 'object') {\n format = dp;\n dp = rm = null;\n } else {\n format = FORMAT;\n }\n } else if (typeof format != 'object') {\n throw Error\n (bignumberError + 'Argument not an object: ' + format);\n }\n\n str = x.toFixed(dp, rm);\n\n if (x.c) {\n var i,\n arr = str.split('.'),\n g1 = +format.groupSize,\n g2 = +format.secondaryGroupSize,\n groupSeparator = format.groupSeparator || '',\n intPart = arr[0],\n fractionPart = arr[1],\n isNeg = x.s < 0,\n intDigits = isNeg ? intPart.slice(1) : intPart,\n len = intDigits.length;\n\n if (g2) i = g1, g1 = g2, g2 = i, len -= i;\n\n if (g1 > 0 && len > 0) {\n i = len % g1 || g1;\n intPart = intDigits.substr(0, i);\n for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);\n if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);\n if (isNeg) intPart = '-' + intPart;\n }\n\n str = fractionPart\n ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)\n ? fractionPart.replace(new RegExp('\\\\d{' + g2 + '}\\\\B', 'g'),\n '$&' + (format.fractionGroupSeparator || ''))\n : fractionPart)\n : intPart;\n }\n\n return (format.prefix || '') + str + (format.suffix || '');\n };\n\n P.toFraction = function (md) {\n var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,\n x = this,\n xc = x.c;\n\n if (md != null) {\n n = new BigNumber(md);\n if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {\n throw Error\n (bignumberError + 'Argument ' +\n (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));\n }\n }\n\n if (!xc) return new BigNumber(x);\n\n d = new BigNumber(ONE);\n n1 = d0 = new BigNumber(ONE);\n d1 = n0 = new BigNumber(ONE);\n s = coeffToString(xc);\n\n e = d.e = s.length - x.e - 1;\n d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];\n md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;\n\n exp = MAX_EXP;\n MAX_EXP = 1 / 0;\n n = new BigNumber(s);\n n0.c[0] = 0;\n\n for (; ;) {\n q = div(n, d, 0, 1);\n d2 = d0.plus(q.times(d1));\n if (d2.comparedTo(md) == 1) break;\n d0 = d1;\n d1 = d2;\n n1 = n0.plus(q.times(d2 = n1));\n n0 = d2;\n d = n.minus(q.times(d2 = d));\n n = d2;\n }\n\n d2 = div(md.minus(d0), d1, 0, 1);\n n0 = n0.plus(d2.times(n1));\n d0 = d0.plus(d2.times(d1));\n n0.s = n1.s = x.s;\n e = e * 2;\n\n r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(\n div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];\n MAX_EXP = exp;\n\n return r;\n };\n\n P.toNumber = function () {\n return +valueOf(this);\n };\n\n P.toPrecision = function (sd, rm) {\n if (sd != null) intCheck(sd, 1, MAX);\n return format(this, sd, rm, 2);\n };\n\n P.toString = function (b) {\n var str,\n n = this,\n s = n.s,\n e = n.e;\n\n if (e === null) {\n if (s) {\n str = 'Infinity';\n if (s < 0) str = '-' + str;\n } else {\n str = 'NaN';\n }\n } else {\n if (b == null) {\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(coeffToString(n.c), e)\n : toFixedPoint(coeffToString(n.c), e, '0');\n } else if (b === 10) {\n n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);\n str = toFixedPoint(coeffToString(n.c), n.e, '0');\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);\n }\n\n if (s < 0 && n.c[0]) str = '-' + str;\n }\n\n return str;\n };\n\n P.valueOf = P.toJSON = function () {\n return valueOf(this);\n };\n\n P._isBigNumber = true;\n if (typeof Symbol == 'function' && typeof Symbol.iterator == 'symbol') {\n P[Symbol.toStringTag] = 'BigNumber';\n P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;\n }\n if (configObject != null) BigNumber.set(configObject);\n return BigNumber;\n }\n\n function bitFloor(n) {\n var i = n | 0;\n return n > 0 || n === i ? i : i - 1;\n }\n\n function coeffToString(a) {\n var s, z,\n i = 1,\n j = a.length,\n r = a[0] + '';\n for (; i < j;) {\n s = a[i++] + '';\n z = LOG_BASE - s.length;\n for (; z--; s = '0' + s);\n r += s;\n }\n for (j = r.length; r.charCodeAt(--j) === 48;);\n return r.slice(0, j + 1 || 1);\n }\n\n function compare(x, y) {\n var a, b,\n xc = x.c,\n yc = y.c,\n i = x.s,\n j = y.s,\n k = x.e,\n l = y.e;\n if (!i || !j) return null;\n a = xc && !xc[0];\n b = yc && !yc[0];\n if (a || b) return a ? b ? 0 : -j : i;\n if (i != j) return i;\n a = i < 0;\n b = k == l;\n if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;\n if (!b) return k > l ^ a ? 1 : -1;\n j = (k = xc.length) < (l = yc.length) ? k : l;\n for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;\n return k == l ? 0 : k > l ^ a ? 1 : -1;\n }\n\n function intCheck(n, min, max, name) {\n if (n < min || n > max || n !== (n < 0 ? mathceil(n) : mathfloor(n))) {\n throw Error\n (bignumberError + (name || 'Argument') + (typeof n == 'number'\n ? n < min || n > max ? ' out of range: ' : ' not an integer: '\n : ' not a primitive number: ') + String(n));\n }\n }\n\n function isOdd(n) {\n var k = n.c.length - 1;\n return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;\n }\n\n function toExponential(str, e) {\n return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +\n (e < 0 ? 'e' : 'e+') + e;\n }\n\n function toFixedPoint(str, e, z) {\n var len, zs;\n if (e < 0) {\n for (zs = z + '.'; ++e; zs += z);\n str = zs + str;\n } else {\n len = str.length;\n if (++e > len) {\n for (zs = z, e -= len; --e; zs += z);\n str += zs;\n } else if (e < len) {\n str = str.slice(0, e) + '.' + str.slice(e);\n }\n }\n return str;\n }\n\n BigNumber = clone();\n BigNumber['default'] = BigNumber.BigNumber = BigNumber;\n if (typeof define == 'function' && define.amd) {\n define(function () { return BigNumber; });\n } else if (typeof module != 'undefined' && module.exports) {\n module.exports = BigNumber;\n } else {\n if (!globalObject) {\n globalObject = typeof self != 'undefined' && self ? self : window;\n }\n globalObject.BigNumber = BigNumber;\n }\n})(this);\n\n\n\nfunction maxBN(a, b) {\n if (a.gt(b))\n return a;\n return b;\n}\n\nvar nums = readline().split(' ').map(function(x) { return Number(x) });\nvar N = nums[0];\nvar arr = [];\nfor (var i=0; i (for browser)\n \n $ npm install bignumber.js (for NodeJS)\n const BigNumber = require('bignumber.js');\n\n 2) let x = new BigNumber(123.4567);\n let y = BigNumber('123456.7e-3');\n let z = new BigNumber(x);\n x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true\n\n 3) To get the string value of a BigNumber use toString() or toFixed().\n Using toFixed() prevents exponential notation being returned, no matter how large or small the value.\n\n let x = new BigNumber('1111222233334444555566');\n x.toString(); // \"1.111222233334444555566e+21\"\n x.toFixed(); // \"1111222233334444555566\"\n\n 4) // Precision loss from using numeric literals with more than 15 significant digits.\n new BigNumber(1.0000000000000001) // '1'\n new BigNumber(88259496234518.57) // '88259496234518.56'\n new BigNumber(99999999999999999999) // '100000000000000000000'\n\n // Precision loss from using numeric literals outside the range of Number values.\n new BigNumber(2e+308) // 'Infinity'\n new BigNumber(1e-324) // '0'\n\n // Precision loss from the unexpected result of arithmetic with Number values.\n new BigNumber(0.7 + 0.1) // '0.7999999999999999'\n\n When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal toString() value.\n\n 5) BigNumbers can be created from values in bases from 2 to 36. See ALPHABET to extend this range.\n\n a = new BigNumber(1011, 2) // \"11\"\n b = new BigNumber('zz.9', 36) // \"1295.25\"\n c = a.plus(b) // \"1306.25\"\n\n 6) A BigNumber is immutable in the sense that it is not changed by its methods.\n\n 0.3 - 0.1 // 0.19999999999999998\n x = new BigNumber(0.3)\n x.minus(0.1) // \"0.2\"\n x // \"0.3\"\n\n 7) The methods that return a BigNumber can be chained.\n\n x.dividedBy(y).plus(z).times(9)\n x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()\n x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true\n x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true\n\n 8) As with JavaScript's Number type, there are toExponential, toFixed and toPrecision methods.\n\n x = new BigNumber(255.5)\n x.toExponential(5) // \"2.55500e+2\"\n x.toFixed(5) // \"255.50000\"\n x.toPrecision(5) // \"255.50\"\n x.toNumber() // 255.5\n\n 9) A base can be specified for toString.\n\n x.toString(16) // \"ff.8\"\n\n 10) isNaN and isFinite methods, as NaN and Infinity are valid BigNumber values.\n\n x = new BigNumber(NaN) // \"NaN\"\n y = new BigNumber(Infinity) // \"Infinity\"\n x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true\n\n 11) https://github.com/MikeMcl/bignumber.js\n\n 12) GCD for all numbers from big segment [a...b]:\n\n function nod(a, b) {\n while (a.gt(0) && b.gt(0)) {\n if (a.gt(b))\n a = a.mod(b);\n else\n b = b.mod(a);\n }\n return a.plus(b);\n }\n\n var nums = readline().split(' ').map(function(x) { return BigNumber(x) });\n var a = nums[0];\n var b = nums[1];\n var res = a;\n a = a.plus(1);\n while (a.lte(b) && res.gt(1)) {\n res = nod(res, a);\n a = a.plus(1);\n }\n print(res.toFixed());\n\n 13) \n*/\n\n;(function (globalObject) {\n 'use strict';\n\n var BigNumber,\n isNumeric = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/i,\n mathceil = Math.ceil,\n mathfloor = Math.floor,\n bignumberError = '[BigNumber Error] ',\n tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',\n BASE = 1e14,\n LOG_BASE = 14,\n MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1\n POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],\n SQRT_BASE = 1e7,\n MAX = 1E9; // 0 to MAX_INT32\n\n function clone(configObject) {\n var div, convertBase, parseNumeric,\n P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },\n ONE = new BigNumber(1),\n\n // The maximum number of decimal places for operations involving division.\n DECIMAL_PLACES = 256, // 0 to MAX\n ROUNDING_MODE = 4, // 0 to 8\n\n // The exponent value at and beneath which toString returns exponential notation.\n TO_EXP_NEG = -100, // 0 to -MAX\n // The exponent value at and above which toString returns exponential notation.\n TO_EXP_POS = 100, // 0 to MAX\n MIN_EXP = -1e8, // -1 to -MAX\n MAX_EXP = 1e8, // 1 to MAX\n\n CRYPTO = false, // true or false\n MODULO_MODE = 1, // 0 to 9\n POW_PRECISION = 0, // 0 to MAX\n FORMAT = {\n prefix: '',\n groupSize: 3,\n secondaryGroupSize: 0,\n groupSeparator: ',',\n decimalSeparator: '.',\n fractionGroupSize: 0,\n fractionGroupSeparator: '\\xA0', // non-breaking space\n suffix: ''\n },\n ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';\n\n function BigNumber(n, b) {\n var alphabet, c, caseChanged, e, i, isNum, len, str,\n x = this;\n if (!(x instanceof BigNumber)) {\n return new BigNumber(n, b);\n }\n if (b == null) {\n if (n instanceof BigNumber) {\n x.s = n.s;\n x.e = n.e;\n x.c = (n = n.c) ? n.slice() : n;\n return;\n }\n isNum = typeof n == 'number';\n if (isNum && n * 0 == 0) {\n x.s = 1 / n < 0 ? (n = -n, -1) : 1;\n if (n === ~~n) {\n for (e = 0, i = n; i >= 10; i /= 10, e++);\n x.e = e;\n x.c = [n];\n return;\n }\n str = String(n);\n } else {\n str = String(n);\n if (!isNumeric.test(str)) return parseNumeric(x, str, isNum);\n x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;\n }\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n if ((i = str.search(/e/i)) > 0) {\n if (e < 0) e = i;\n e += +str.slice(i + 1);\n str = str.substring(0, i);\n } else if (e < 0) {\n e = str.length;\n }\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = String(n);\n if (b == 10) {\n x = new BigNumber(n instanceof BigNumber ? n : str);\n return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);\n }\n isNum = typeof n == 'number';\n if (isNum) {\n if (n * 0 != 0) return parseNumeric(x, str, isNum, b);\n x.s = 1 / n < 0 ? (str = str.slice(1), -1) : 1;\n if (BigNumber.DEBUG && str.replace(/^0\\.0*|\\./, '').length > 15) {\n throw Error\n (tooManyDigits + n);\n }\n isNum = false;\n } else {\n x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;\n }\n alphabet = ALPHABET.slice(0, b);\n e = i = 0;\n for (len = str.length; i < len; i++) {\n if (alphabet.indexOf(c = str.charAt(i)) < 0) {\n if (c == '.') {\n if (i > e) {\n e = len;\n continue;\n }\n } else if (!caseChanged) {\n if (str == str.toUpperCase() && (str = str.toLowerCase()) ||\n str == str.toLowerCase() && (str = str.toUpperCase())) {\n caseChanged = true;\n i = -1;\n e = 0;\n continue;\n }\n }\n return parseNumeric(x, String(n), isNum, b);\n }\n }\n str = convertBase(str, b, 10, x.s);\n if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');\n else e = str.length;\n }\n for (i = 0; str.charCodeAt(i) === 48; i++);\n for (len = str.length; str.charCodeAt(--len) === 48;);\n str = str.slice(i, ++len);\n if (str) {\n len -= i;\n if (isNum && BigNumber.DEBUG &&\n len > 15 && (n > MAX_SAFE_INTEGER || n !== mathfloor(n))) {\n throw Error\n (tooManyDigits + (x.s * n));\n }\n e = e - i - 1;\n if (e > MAX_EXP) {\n x.c = x.e = null;\n } else if (e < MIN_EXP) {\n x.c = [x.e = 0];\n } else {\n x.e = e;\n x.c = [];\n i = (e + 1) % LOG_BASE;\n if (e < 0) i += LOG_BASE;\n if (i < len) {\n if (i) x.c.push(+str.slice(0, i));\n for (len -= LOG_BASE; i < len;) {\n x.c.push(+str.slice(i, i += LOG_BASE));\n }\n str = str.slice(i);\n i = LOG_BASE - str.length;\n } else {\n i -= len;\n }\n for (; i--; str += '0');\n x.c.push(+str);\n }\n } else {\n x.c = [x.e = 0];\n }\n }\n\n BigNumber.clone = clone;\n BigNumber.ROUND_UP = 0;\n BigNumber.ROUND_DOWN = 1;\n BigNumber.ROUND_CEIL = 2;\n BigNumber.ROUND_FLOOR = 3;\n BigNumber.ROUND_HALF_UP = 4;\n BigNumber.ROUND_HALF_DOWN = 5;\n BigNumber.ROUND_HALF_EVEN = 6;\n BigNumber.ROUND_HALF_CEIL = 7;\n BigNumber.ROUND_HALF_FLOOR = 8;\n BigNumber.EUCLID = 9;\n\n BigNumber.config = BigNumber.set = function (obj) {\n var p, v;\n if (obj != null) {\n if (typeof obj == 'object') {\n if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n DECIMAL_PLACES = v;\n }\n if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {\n v = obj[p];\n intCheck(v, 0, 8, p);\n ROUNDING_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, 0, p);\n intCheck(v[1], 0, MAX, p);\n TO_EXP_NEG = v[0];\n TO_EXP_POS = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);\n }\n }\n if (obj.hasOwnProperty(p = 'RANGE')) {\n v = obj[p];\n if (v && v.pop) {\n intCheck(v[0], -MAX, -1, p);\n intCheck(v[1], 1, MAX, p);\n MIN_EXP = v[0];\n MAX_EXP = v[1];\n } else {\n intCheck(v, -MAX, MAX, p);\n if (v) {\n MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);\n } else {\n throw Error\n (bignumberError + p + ' cannot be zero: ' + v);\n }\n }\n }\n if (obj.hasOwnProperty(p = 'CRYPTO')) {\n v = obj[p];\n if (v === !!v) {\n if (v) {\n if (typeof crypto != 'undefined' && crypto &&\n (crypto.getRandomValues || crypto.randomBytes)) {\n CRYPTO = v;\n } else {\n CRYPTO = !v;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n } else {\n CRYPTO = v;\n }\n } else {\n throw Error\n (bignumberError + p + ' not true or false: ' + v);\n }\n }\n if (obj.hasOwnProperty(p = 'MODULO_MODE')) {\n v = obj[p];\n intCheck(v, 0, 9, p);\n MODULO_MODE = v;\n }\n if (obj.hasOwnProperty(p = 'POW_PRECISION')) {\n v = obj[p];\n intCheck(v, 0, MAX, p);\n POW_PRECISION = v;\n }\n if (obj.hasOwnProperty(p = 'FORMAT')) {\n v = obj[p];\n if (typeof v == 'object') FORMAT = v;\n else throw Error\n (bignumberError + p + ' not an object: ' + v);\n }\n if (obj.hasOwnProperty(p = 'ALPHABET')) {\n v = obj[p];\n if (typeof v == 'string' && !/^.$|[+-.\\s]|(.).*\\1/.test(v)) {\n ALPHABET = v;\n } else {\n throw Error\n (bignumberError + p + ' invalid: ' + v);\n }\n }\n } else {\n throw Error\n (bignumberError + 'Object expected: ' + obj);\n }\n }\n\n return {\n DECIMAL_PLACES: DECIMAL_PLACES,\n ROUNDING_MODE: ROUNDING_MODE,\n EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],\n RANGE: [MIN_EXP, MAX_EXP],\n CRYPTO: CRYPTO,\n MODULO_MODE: MODULO_MODE,\n POW_PRECISION: POW_PRECISION,\n FORMAT: FORMAT,\n ALPHABET: ALPHABET\n };\n };\n\n BigNumber.isBigNumber = function (v) {\n return v instanceof BigNumber || v && v._isBigNumber === true || false;\n };\n\n BigNumber.maximum = BigNumber.max = function () {\n return maxOrMin(arguments, P.lt);\n };\n\n BigNumber.minimum = BigNumber.min = function () {\n return maxOrMin(arguments, P.gt);\n };\n\n BigNumber.random = (function () {\n var pow2_53 = 0x20000000000000;\n var random53bitInt = (Math.random() * pow2_53) & 0x1fffff\n ? function () { return mathfloor(Math.random() * pow2_53); }\n : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +\n (Math.random() * 0x800000 | 0); };\n return function (dp) {\n var a, b, e, k, v,\n i = 0,\n c = [],\n rand = new BigNumber(ONE);\n if (dp == null) dp = DECIMAL_PLACES;\n else intCheck(dp, 0, MAX);\n k = mathceil(dp / LOG_BASE);\n if (CRYPTO) {\n if (crypto.getRandomValues) {\n a = crypto.getRandomValues(new Uint32Array(k *= 2));\n for (; i < k;) {\n v = a[i] * 0x20000 + (a[i + 1] >>> 11);\n if (v >= 9e15) {\n b = crypto.getRandomValues(new Uint32Array(2));\n a[i] = b[0];\n a[i + 1] = b[1];\n } else {\n c.push(v % 1e14);\n i += 2;\n }\n }\n i = k / 2;\n } else if (crypto.randomBytes) {\n a = crypto.randomBytes(k *= 7);\n for (; i < k;) {\n v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +\n (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +\n (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];\n if (v >= 9e15) {\n crypto.randomBytes(7).copy(a, i);\n } else {\n c.push(v % 1e14);\n i += 7;\n }\n }\n i = k / 7;\n } else {\n CRYPTO = false;\n throw Error\n (bignumberError + 'crypto unavailable');\n }\n }\n if (!CRYPTO) {\n for (; i < k;) {\n v = random53bitInt();\n if (v < 9e15) c[i++] = v % 1e14;\n }\n }\n k = c[--i];\n dp %= LOG_BASE;\n if (k && dp) {\n v = POWS_TEN[LOG_BASE - dp];\n c[i] = mathfloor(k / v) * v;\n }\n for (; c[i] === 0; c.pop(), i--);\n if (i < 0) {\n c = [e = 0];\n } else {\n for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);\n for (i = 1, v = c[0]; v >= 10; v /= 10, i++);\n if (i < LOG_BASE) e -= LOG_BASE - i;\n }\n rand.e = e;\n rand.c = c;\n return rand;\n };\n })();\n\n BigNumber.sum = function () {\n var i = 1,\n args = arguments,\n sum = new BigNumber(args[0]);\n for (; i < args.length;) sum = sum.plus(args[i++]);\n return sum;\n };\n\n convertBase = (function () {\n var decimal = '0123456789';\n function toBaseOut(str, baseIn, baseOut, alphabet) {\n var j,\n arr = [0],\n arrL,\n i = 0,\n len = str.length;\n for (; i < len;) {\n for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);\n arr[0] += alphabet.indexOf(str.charAt(i++));\n for (j = 0; j < arr.length; j++) {\n if (arr[j] > baseOut - 1) {\n if (arr[j + 1] == null) arr[j + 1] = 0;\n arr[j + 1] += arr[j] / baseOut | 0;\n arr[j] %= baseOut;\n }\n }\n }\n return arr.reverse();\n }\n return function (str, baseIn, baseOut, sign, callerIsToString) {\n var alphabet, d, e, k, r, x, xc, y,\n i = str.indexOf('.'),\n dp = DECIMAL_PLACES,\n rm = ROUNDING_MODE;\n if (i >= 0) {\n k = POW_PRECISION;\n POW_PRECISION = 0;\n str = str.replace('.', '');\n y = new BigNumber(baseIn);\n x = y.pow(str.length - i);\n POW_PRECISION = k;\n y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),\n 10, baseOut, decimal);\n y.e = y.c.length;\n }\n xc = toBaseOut(str, baseIn, baseOut, callerIsToString\n ? (alphabet = ALPHABET, decimal)\n : (alphabet = decimal, ALPHABET));\n e = k = xc.length;\n for (; xc[--k] == 0; xc.pop());\n if (!xc[0]) return alphabet.charAt(0);\n if (i < 0) {\n --e;\n } else {\n x.c = xc;\n x.e = e;\n x.s = sign;\n x = div(x, y, dp, rm, baseOut);\n xc = x.c;\n r = x.r;\n e = x.e;\n }\n d = e + dp + 1;\n i = xc[d];\n k = baseOut / 2;\n r = r || d < 0 || xc[d + 1] != null;\n r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (d < 1 || !xc[0]) {\n str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);\n } else {\n xc.length = d;\n if (r) {\n for (--baseOut; ++xc[--d] > baseOut;) {\n xc[d] = 0;\n if (!d) {\n ++e;\n xc = [1].concat(xc);\n }\n }\n }\n for (k = xc.length; !xc[--k];);\n for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));\n str = toFixedPoint(str, e, alphabet.charAt(0));\n }\n return str;\n };\n })();\n\n div = (function () {\n function multiply(x, k, base) {\n var m, temp, xlo, xhi,\n carry = 0,\n i = x.length,\n klo = k % SQRT_BASE,\n khi = k / SQRT_BASE | 0;\n for (x = x.slice(); i--;) {\n xlo = x[i] % SQRT_BASE;\n xhi = x[i] / SQRT_BASE | 0;\n m = khi * xlo + xhi * klo;\n temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;\n carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;\n x[i] = temp % base;\n }\n if (carry) x = [carry].concat(x);\n return x;\n }\n\n function compare(a, b, aL, bL) {\n var i, cmp;\n if (aL != bL) {\n cmp = aL > bL ? 1 : -1;\n } else {\n for (i = cmp = 0; i < aL; i++) {\n if (a[i] != b[i]) {\n cmp = a[i] > b[i] ? 1 : -1;\n break;\n }\n }\n }\n return cmp;\n }\n\n function subtract(a, b, aL, base) {\n var i = 0;\n for (; aL--;) {\n a[aL] -= i;\n i = a[aL] < b[aL] ? 1 : 0;\n a[aL] = i * base + a[aL] - b[aL];\n }\n for (; !a[0] && a.length > 1; a.splice(0, 1));\n }\n return function (x, y, dp, rm, base) {\n var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,\n yL, yz,\n s = x.s == y.s ? 1 : -1,\n xc = x.c,\n yc = y.c;\n if (!xc || !xc[0] || !yc || !yc[0]) {\n return new BigNumber(\n !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :\n xc && xc[0] == 0 || !yc ? s * 0 : s / 0\n );\n }\n q = new BigNumber(s);\n qc = q.c = [];\n e = x.e - y.e;\n s = dp + e + 1;\n if (!base) {\n base = BASE;\n e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);\n s = s / LOG_BASE | 0;\n }\n for (i = 0; yc[i] == (xc[i] || 0); i++);\n if (yc[i] > (xc[i] || 0)) e--;\n if (s < 0) {\n qc.push(1);\n more = true;\n } else {\n xL = xc.length;\n yL = yc.length;\n i = 0;\n s += 2;\n n = mathfloor(base / (yc[0] + 1));\n if (n > 1) {\n yc = multiply(yc, n, base);\n xc = multiply(xc, n, base);\n yL = yc.length;\n xL = xc.length;\n }\n xi = yL;\n rem = xc.slice(0, yL);\n remL = rem.length;\n for (; remL < yL; rem[remL++] = 0);\n yz = yc.slice();\n yz = [0].concat(yz);\n yc0 = yc[0];\n if (yc[1] >= base / 2) yc0++;\n do {\n n = 0;\n cmp = compare(yc, rem, yL, remL);\n if (cmp < 0) {\n rem0 = rem[0];\n if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);\n n = mathfloor(rem0 / yc0);\n if (n > 1) {\n if (n >= base) n = base - 1;\n prod = multiply(yc, n, base);\n prodL = prod.length;\n remL = rem.length;\n while (compare(prod, rem, prodL, remL) == 1) {\n n--;\n subtract(prod, yL < prodL ? yz : yc, prodL, base);\n prodL = prod.length;\n cmp = 1;\n }\n } else {\n if (n == 0) {\n cmp = n = 1;\n }\n prod = yc.slice();\n prodL = prod.length;\n }\n if (prodL < remL) prod = [0].concat(prod);\n subtract(rem, prod, remL, base);\n remL = rem.length;\n if (cmp == -1) {\n while (compare(yc, rem, yL, remL) < 1) {\n n++;\n subtract(rem, yL < remL ? yz : yc, remL, base);\n remL = rem.length;\n }\n }\n } else if (cmp === 0) {\n n++;\n rem = [0];\n }\n qc[i++] = n;\n if (rem[0]) {\n rem[remL++] = xc[xi] || 0;\n } else {\n rem = [xc[xi]];\n remL = 1;\n }\n } while ((xi++ < xL || rem[0] != null) && s--);\n more = rem[0] != null;\n if (!qc[0]) qc.splice(0, 1);\n }\n if (base == BASE) {\n for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);\n round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);\n } else {\n q.e = e;\n q.r = +more;\n }\n return q;\n };\n })();\n\n function format(n, i, rm, id) {\n var c0, e, ne, len, str;\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n if (!n.c) return n.toString();\n c0 = n.c[0];\n ne = n.e;\n if (i == null) {\n str = coeffToString(n.c);\n str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)\n ? toExponential(str, ne)\n : toFixedPoint(str, ne, '0');\n } else {\n n = round(new BigNumber(n), i, rm);\n e = n.e;\n str = coeffToString(n.c);\n len = str.length;\n if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {\n for (; len < i; str += '0', len++);\n str = toExponential(str, e);\n } else {\n i -= ne;\n str = toFixedPoint(str, e, '0');\n if (e + 1 > len) {\n if (--i > 0) for (str += '.'; i--; str += '0');\n } else {\n i += e - len;\n if (i > 0) {\n if (e + 1 == len) str += '.';\n for (; i--; str += '0');\n }\n }\n }\n }\n return n.s < 0 && c0 ? '-' + str : str;\n }\n\n function maxOrMin(args, method) {\n var n,\n i = 1,\n m = new BigNumber(args[0]);\n for (; i < args.length; i++) {\n n = new BigNumber(args[i]);\n if (!n.s) {\n m = n;\n break;\n } else if (method.call(m, n)) {\n m = n;\n }\n }\n return m;\n }\n\n function normalise(n, c, e) {\n var i = 1,\n j = c.length;\n for (; !c[--j]; c.pop());\n for (j = c[0]; j >= 10; j /= 10, i++);\n if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {\n n.c = n.e = null;\n } else if (e < MIN_EXP) {\n n.c = [n.e = 0];\n } else {\n n.e = e;\n n.c = c;\n }\n return n;\n }\n\n parseNumeric = (function () {\n var basePrefix = /^(-?)0([xbo])(?=\\w[\\w.]*$)/i,\n dotAfter = /^([^.]+)\\.$/,\n dotBefore = /^\\.([^.]+)$/,\n isInfinityOrNaN = /^-?(Infinity|NaN)$/,\n whitespaceOrPlus = /^\\s*\\+(?=[\\w.])|^\\s+|\\s+$/g;\n return function (x, str, isNum, b) {\n var base,\n s = isNum ? str : str.replace(whitespaceOrPlus, '');\n if (isInfinityOrNaN.test(s)) {\n x.s = isNaN(s) ? null : s < 0 ? -1 : 1;\n x.c = x.e = null;\n } else {\n if (!isNum) {\n s = s.replace(basePrefix, function (m, p1, p2) {\n base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;\n return !b || b == base ? p1 : m;\n });\n if (b) {\n base = b;\n s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');\n }\n if (str != s) return new BigNumber(s, base);\n }\n if (BigNumber.DEBUG) {\n throw Error\n (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);\n }\n x.c = x.e = x.s = null;\n }\n }\n })();\n\n function round(x, sd, rm, r) {\n var d, i, j, k, n, ni, rd,\n xc = x.c,\n pows10 = POWS_TEN;\n if (xc) {\n out: {\n for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);\n i = sd - d;\n if (i < 0) {\n i += LOG_BASE;\n j = sd;\n n = xc[ni = 0];\n rd = n / pows10[d - j - 1] % 10 | 0;\n } else {\n ni = mathceil((i + 1) / LOG_BASE);\n if (ni >= xc.length) {\n if (r) {\n for (; xc.length <= ni; xc.push(0));\n n = rd = 0;\n d = 1;\n i %= LOG_BASE;\n j = i - LOG_BASE + 1;\n } else {\n break out;\n }\n } else {\n n = k = xc[ni];\n for (d = 1; k >= 10; k /= 10, d++);\n i %= LOG_BASE;\n j = i - LOG_BASE + d;\n rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;\n }\n }\n r = r || sd < 0 ||\n xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);\n r = rm < 4\n ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))\n : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&\n ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||\n rm == (x.s < 0 ? 8 : 7));\n if (sd < 1 || !xc[0]) {\n xc.length = 0;\n if (r) {\n sd -= x.e + 1;\n xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];\n x.e = -sd || 0;\n } else {\n xc[0] = x.e = 0;\n }\n return x;\n }\n if (i == 0) {\n xc.length = ni;\n k = 1;\n ni--;\n } else {\n xc.length = ni + 1;\n k = pows10[LOG_BASE - i];\n xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;\n }\n if (r) {\n for (; ;) {\n if (ni == 0) {\n for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);\n j = xc[0] += k;\n for (k = 1; j >= 10; j /= 10, k++);\n if (i != k) {\n x.e++;\n if (xc[0] == BASE) xc[0] = 1;\n }\n break;\n } else {\n xc[ni] += k;\n if (xc[ni] != BASE) break;\n xc[ni--] = 0;\n k = 1;\n }\n }\n }\n for (i = xc.length; xc[--i] === 0; xc.pop());\n }\n if (x.e > MAX_EXP) {\n x.c = x.e = null;\n } else if (x.e < MIN_EXP) {\n x.c = [x.e = 0];\n }\n }\n return x;\n }\n\n function valueOf(n) {\n var str,\n e = n.e;\n if (e === null) return n.toString();\n str = coeffToString(n.c);\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(str, e)\n : toFixedPoint(str, e, '0');\n return n.s < 0 ? '-' + str : str;\n }\n\n P.absoluteValue = P.abs = function () {\n var x = new BigNumber(this);\n if (x.s < 0) x.s = 1;\n return x;\n };\n\n P.comparedTo = function (y, b) {\n return compare(this, new BigNumber(y, b));\n };\n\n P.decimalPlaces = P.dp = function (dp, rm) {\n var c, n, v,\n x = this;\n if (dp != null) {\n intCheck(dp, 0, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), dp + x.e + 1, rm);\n }\n if (!(c = x.c)) return null;\n n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;\n if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);\n if (n < 0) n = 0;\n return n;\n };\n\n P.dividedBy = P.div = function (y, b) {\n return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);\n };\n\n P.dividedToIntegerBy = P.idiv = function (y, b) {\n return div(this, new BigNumber(y, b), 0, 1);\n };\n\n P.exponentiatedBy = P.pow = function (n, m) {\n var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,\n x = this;\n n = new BigNumber(n);\n if (n.c && !n.isInteger()) {\n throw Error\n (bignumberError + 'Exponent not an integer: ' + valueOf(n));\n }\n if (m != null) m = new BigNumber(m);\n nIsBig = n.e > 14;\n if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {\n y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));\n return m ? y.mod(m) : y;\n }\n nIsNeg = n.s < 0;\n if (m) {\n if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);\n isModExp = !nIsNeg && x.isInteger() && m.isInteger();\n if (isModExp) x = x.mod(m);\n } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0\n ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7\n : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {\n k = x.s < 0 && isOdd(n) ? -0 : 0;\n if (x.e > -1) k = 1 / k;\n return new BigNumber(nIsNeg ? 1 / k : k);\n } else if (POW_PRECISION) {\n k = mathceil(POW_PRECISION / LOG_BASE + 2);\n }\n if (nIsBig) {\n half = new BigNumber(0.5);\n if (nIsNeg) n.s = 1;\n nIsOdd = isOdd(n);\n } else {\n i = Math.abs(+valueOf(n));\n nIsOdd = i % 2;\n }\n y = new BigNumber(ONE);\n for (; ;) {\n if (nIsOdd) {\n y = y.times(x);\n if (!y.c) break;\n\n if (k) {\n if (y.c.length > k) y.c.length = k;\n } else if (isModExp) {\n y = y.mod(m);\n }\n }\n if (i) {\n i = mathfloor(i / 2);\n if (i === 0) break;\n nIsOdd = i % 2;\n } else {\n n = n.times(half);\n round(n, n.e + 1, 1);\n if (n.e > 14) {\n nIsOdd = isOdd(n);\n } else {\n i = +valueOf(n);\n if (i === 0) break;\n nIsOdd = i % 2;\n }\n }\n x = x.times(x);\n if (k) {\n if (x.c && x.c.length > k) x.c.length = k;\n } else if (isModExp) {\n x = x.mod(m);\n }\n }\n if (isModExp) return y;\n if (nIsNeg) y = ONE.div(y);\n return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;\n };\n\n P.integerValue = function (rm) {\n var n = new BigNumber(this);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(n, n.e + 1, rm);\n };\n\n P.isEqualTo = P.eq = function (y, b) {\n return compare(this, new BigNumber(y, b)) === 0;\n };\n\n P.isFinite = function () {\n return !!this.c;\n };\n\n P.isGreaterThan = P.gt = function (y, b) {\n return compare(this, new BigNumber(y, b)) > 0;\n };\n\n P.isGreaterThanOrEqualTo = P.gte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;\n\n };\n\n P.isInteger = function () {\n return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;\n };\n\n P.isLessThan = P.lt = function (y, b) {\n return compare(this, new BigNumber(y, b)) < 0;\n };\n\n P.isLessThanOrEqualTo = P.lte = function (y, b) {\n return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;\n };\n\n P.isNaN = function () {\n return !this.s;\n };\n\n P.isNegative = function () {\n return this.s < 0;\n };\n\n P.isPositive = function () {\n return this.s > 0;\n };\n\n P.isZero = function () {\n return !!this.c && this.c[0] == 0;\n };\n\n P.minus = function (y, b) {\n var i, j, t, xLTy,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.plus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);\n if (!xc[0] || !yc[0]) {\n return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :\n ROUNDING_MODE == 3 ? -0 : 0);\n }\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (xLTy = a < 0) {\n a = -a;\n t = xc;\n } else {\n ye = xe;\n t = yc;\n }\n t.reverse();\n for (b = a; b--; t.push(0));\n t.reverse();\n } else {\n j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;\n for (a = b = 0; b < j; b++) {\n if (xc[b] != yc[b]) {\n xLTy = xc[b] < yc[b];\n break;\n }\n }\n }\n if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;\n b = (j = yc.length) - (i = xc.length);\n if (b > 0) for (; b--; xc[i++] = 0);\n b = BASE - 1;\n for (; j > a;) {\n if (xc[--j] < yc[j]) {\n for (i = j; i && !xc[--i]; xc[i] = b);\n --xc[i];\n xc[j] += BASE;\n }\n\n xc[j] -= yc[j];\n }\n for (; xc[0] == 0; xc.splice(0, 1), --ye);\n if (!xc[0]) {\n y.s = ROUNDING_MODE == 3 ? -1 : 1;\n y.c = [y.e = 0];\n return y;\n }\n return normalise(y, xc, ye);\n };\n\n P.modulo = P.mod = function (y, b) {\n var q, s,\n x = this;\n y = new BigNumber(y, b);\n if (!x.c || !y.s || y.c && !y.c[0]) {\n return new BigNumber(NaN);\n } else if (!y.c || x.c && !x.c[0]) {\n return new BigNumber(x);\n }\n if (MODULO_MODE == 9) {\n s = y.s;\n y.s = 1;\n q = div(x, y, 0, 3);\n y.s = s;\n q.s *= s;\n } else {\n q = div(x, y, 0, MODULO_MODE);\n }\n y = x.minus(q.times(y));\n if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;\n return y;\n };\n\n P.multipliedBy = P.times = function (y, b) {\n var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,\n base, sqrtBase,\n x = this,\n xc = x.c,\n yc = (y = new BigNumber(y, b)).c;\n if (!xc || !yc || !xc[0] || !yc[0]) {\n if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {\n y.c = y.e = y.s = null;\n } else {\n y.s *= x.s;\n if (!xc || !yc) {\n y.c = y.e = null;\n } else {\n y.c = [0];\n y.e = 0;\n }\n }\n return y;\n }\n e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);\n y.s *= x.s;\n xcL = xc.length;\n ycL = yc.length;\n if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;\n for (i = xcL + ycL, zc = []; i--; zc.push(0));\n base = BASE;\n sqrtBase = SQRT_BASE;\n for (i = ycL; --i >= 0;) {\n c = 0;\n ylo = yc[i] % sqrtBase;\n yhi = yc[i] / sqrtBase | 0;\n for (k = xcL, j = i + k; j > i;) {\n xlo = xc[--k] % sqrtBase;\n xhi = xc[k] / sqrtBase | 0;\n m = yhi * xlo + xhi * ylo;\n xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;\n c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;\n zc[j--] = xlo % base;\n }\n zc[j] = c;\n }\n if (c) {\n ++e;\n } else {\n zc.splice(0, 1);\n }\n return normalise(y, zc, e);\n };\n\n P.negated = function () {\n var x = new BigNumber(this);\n x.s = -x.s || null;\n return x;\n };\n\n P.plus = function (y, b) {\n var t,\n x = this,\n a = x.s;\n y = new BigNumber(y, b);\n b = y.s;\n if (!a || !b) return new BigNumber(NaN);\n if (a != b) {\n y.s = -b;\n return x.minus(y);\n }\n var xe = x.e / LOG_BASE,\n ye = y.e / LOG_BASE,\n xc = x.c,\n yc = y.c;\n if (!xe || !ye) {\n if (!xc || !yc) return new BigNumber(a / 0);\n if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);\n }\n xe = bitFloor(xe);\n ye = bitFloor(ye);\n xc = xc.slice();\n if (a = xe - ye) {\n if (a > 0) {\n ye = xe;\n t = yc;\n } else {\n a = -a;\n t = xc;\n }\n t.reverse();\n for (; a--; t.push(0));\n t.reverse();\n }\n a = xc.length;\n b = yc.length;\n if (a - b < 0) t = yc, yc = xc, xc = t, b = a;\n for (a = 0; b;) {\n a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;\n xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;\n }\n if (a) {\n xc = [a].concat(xc);\n ++ye;\n }\n return normalise(y, xc, ye);\n };\n\n P.precision = P.sd = function (sd, rm) {\n var c, n, v,\n x = this;\n if (sd != null && sd !== !!sd) {\n intCheck(sd, 1, MAX);\n if (rm == null) rm = ROUNDING_MODE;\n else intCheck(rm, 0, 8);\n return round(new BigNumber(x), sd, rm);\n }\n if (!(c = x.c)) return null;\n v = c.length - 1;\n n = v * LOG_BASE + 1;\n if (v = c[v]) {\n for (; v % 10 == 0; v /= 10, n--);\n for (v = c[0]; v >= 10; v /= 10, n++);\n }\n if (sd && x.e + 1 > n) n = x.e + 1;\n return n;\n };\n P.shiftedBy = function (k) {\n intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);\n return this.times('1e' + k);\n };\n P.squareRoot = P.sqrt = function () {\n var m, n, r, rep, t,\n x = this,\n c = x.c,\n s = x.s,\n e = x.e,\n dp = DECIMAL_PLACES + 4,\n half = new BigNumber('0.5');\n if (s !== 1 || !c || !c[0]) {\n return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);\n }\n s = Math.sqrt(+valueOf(x));\n if (s == 0 || s == 1 / 0) {\n n = coeffToString(c);\n if ((n.length + e) % 2 == 0) n += '0';\n s = Math.sqrt(+n);\n e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);\n\n if (s == 1 / 0) {\n n = '1e' + e;\n } else {\n n = s.toExponential();\n n = n.slice(0, n.indexOf('e') + 1) + e;\n }\n r = new BigNumber(n);\n } else {\n r = new BigNumber(s + '');\n }\n if (r.c[0]) {\n e = r.e;\n s = e + dp;\n if (s < 3) s = 0;\n for (; ;) {\n t = r;\n r = half.times(t.plus(div(x, t, dp, 1)));\n if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {\n if (r.e < e) --s;\n n = n.slice(s - 3, s + 1);\n if (n == '9999' || !rep && n == '4999') {\n if (!rep) {\n round(t, t.e + DECIMAL_PLACES + 2, 0);\n\n if (t.times(t).eq(x)) {\n r = t;\n break;\n }\n }\n dp += 4;\n s += 4;\n rep = 1;\n } else {\n if (!+n || !+n.slice(1) && n.charAt(0) == '5') {\n round(r, r.e + DECIMAL_PLACES + 2, 1);\n m = !r.times(r).eq(x);\n }\n break;\n }\n }\n }\n }\n\n return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);\n };\n\n P.toExponential = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp++;\n }\n return format(this, dp, rm, 1);\n };\n\n P.toFixed = function (dp, rm) {\n if (dp != null) {\n intCheck(dp, 0, MAX);\n dp = dp + this.e + 1;\n }\n return format(this, dp, rm);\n };\n\n P.toFormat = function (dp, rm, format) {\n var str,\n x = this;\n\n if (format == null) {\n if (dp != null && rm && typeof rm == 'object') {\n format = rm;\n rm = null;\n } else if (dp && typeof dp == 'object') {\n format = dp;\n dp = rm = null;\n } else {\n format = FORMAT;\n }\n } else if (typeof format != 'object') {\n throw Error\n (bignumberError + 'Argument not an object: ' + format);\n }\n\n str = x.toFixed(dp, rm);\n\n if (x.c) {\n var i,\n arr = str.split('.'),\n g1 = +format.groupSize,\n g2 = +format.secondaryGroupSize,\n groupSeparator = format.groupSeparator || '',\n intPart = arr[0],\n fractionPart = arr[1],\n isNeg = x.s < 0,\n intDigits = isNeg ? intPart.slice(1) : intPart,\n len = intDigits.length;\n\n if (g2) i = g1, g1 = g2, g2 = i, len -= i;\n\n if (g1 > 0 && len > 0) {\n i = len % g1 || g1;\n intPart = intDigits.substr(0, i);\n for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);\n if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);\n if (isNeg) intPart = '-' + intPart;\n }\n\n str = fractionPart\n ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)\n ? fractionPart.replace(new RegExp('\\\\d{' + g2 + '}\\\\B', 'g'),\n '$&' + (format.fractionGroupSeparator || ''))\n : fractionPart)\n : intPart;\n }\n\n return (format.prefix || '') + str + (format.suffix || '');\n };\n\n P.toFraction = function (md) {\n var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,\n x = this,\n xc = x.c;\n\n if (md != null) {\n n = new BigNumber(md);\n if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {\n throw Error\n (bignumberError + 'Argument ' +\n (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));\n }\n }\n\n if (!xc) return new BigNumber(x);\n\n d = new BigNumber(ONE);\n n1 = d0 = new BigNumber(ONE);\n d1 = n0 = new BigNumber(ONE);\n s = coeffToString(xc);\n\n e = d.e = s.length - x.e - 1;\n d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];\n md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;\n\n exp = MAX_EXP;\n MAX_EXP = 1 / 0;\n n = new BigNumber(s);\n n0.c[0] = 0;\n\n for (; ;) {\n q = div(n, d, 0, 1);\n d2 = d0.plus(q.times(d1));\n if (d2.comparedTo(md) == 1) break;\n d0 = d1;\n d1 = d2;\n n1 = n0.plus(q.times(d2 = n1));\n n0 = d2;\n d = n.minus(q.times(d2 = d));\n n = d2;\n }\n\n d2 = div(md.minus(d0), d1, 0, 1);\n n0 = n0.plus(d2.times(n1));\n d0 = d0.plus(d2.times(d1));\n n0.s = n1.s = x.s;\n e = e * 2;\n\n r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(\n div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];\n MAX_EXP = exp;\n\n return r;\n };\n\n P.toNumber = function () {\n return +valueOf(this);\n };\n\n P.toPrecision = function (sd, rm) {\n if (sd != null) intCheck(sd, 1, MAX);\n return format(this, sd, rm, 2);\n };\n\n P.toString = function (b) {\n var str,\n n = this,\n s = n.s,\n e = n.e;\n\n if (e === null) {\n if (s) {\n str = 'Infinity';\n if (s < 0) str = '-' + str;\n } else {\n str = 'NaN';\n }\n } else {\n if (b == null) {\n str = e <= TO_EXP_NEG || e >= TO_EXP_POS\n ? toExponential(coeffToString(n.c), e)\n : toFixedPoint(coeffToString(n.c), e, '0');\n } else if (b === 10) {\n n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);\n str = toFixedPoint(coeffToString(n.c), n.e, '0');\n } else {\n intCheck(b, 2, ALPHABET.length, 'Base');\n str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);\n }\n\n if (s < 0 && n.c[0]) str = '-' + str;\n }\n\n return str;\n };\n\n P.valueOf = P.toJSON = function () {\n return valueOf(this);\n };\n\n P._isBigNumber = true;\n if (typeof Symbol == 'function' && typeof Symbol.iterator == 'symbol') {\n P[Symbol.toStringTag] = 'BigNumber';\n P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;\n }\n if (configObject != null) BigNumber.set(configObject);\n return BigNumber;\n }\n\n function bitFloor(n) {\n var i = n | 0;\n return n > 0 || n === i ? i : i - 1;\n }\n\n function coeffToString(a) {\n var s, z,\n i = 1,\n j = a.length,\n r = a[0] + '';\n for (; i < j;) {\n s = a[i++] + '';\n z = LOG_BASE - s.length;\n for (; z--; s = '0' + s);\n r += s;\n }\n for (j = r.length; r.charCodeAt(--j) === 48;);\n return r.slice(0, j + 1 || 1);\n }\n\n function compare(x, y) {\n var a, b,\n xc = x.c,\n yc = y.c,\n i = x.s,\n j = y.s,\n k = x.e,\n l = y.e;\n if (!i || !j) return null;\n a = xc && !xc[0];\n b = yc && !yc[0];\n if (a || b) return a ? b ? 0 : -j : i;\n if (i != j) return i;\n a = i < 0;\n b = k == l;\n if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;\n if (!b) return k > l ^ a ? 1 : -1;\n j = (k = xc.length) < (l = yc.length) ? k : l;\n for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;\n return k == l ? 0 : k > l ^ a ? 1 : -1;\n }\n\n function intCheck(n, min, max, name) {\n if (n < min || n > max || n !== (n < 0 ? mathceil(n) : mathfloor(n))) {\n throw Error\n (bignumberError + (name || 'Argument') + (typeof n == 'number'\n ? n < min || n > max ? ' out of range: ' : ' not an integer: '\n : ' not a primitive number: ') + String(n));\n }\n }\n\n function isOdd(n) {\n var k = n.c.length - 1;\n return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;\n }\n\n function toExponential(str, e) {\n return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +\n (e < 0 ? 'e' : 'e+') + e;\n }\n\n function toFixedPoint(str, e, z) {\n var len, zs;\n if (e < 0) {\n for (zs = z + '.'; ++e; zs += z);\n str = zs + str;\n } else {\n len = str.length;\n if (++e > len) {\n for (zs = z, e -= len; --e; zs += z);\n str += zs;\n } else if (e < len) {\n str = str.slice(0, e) + '.' + str.slice(e);\n }\n }\n return str;\n }\n\n BigNumber = clone();\n BigNumber['default'] = BigNumber.BigNumber = BigNumber;\n if (typeof define == 'function' && define.amd) {\n define(function () { return BigNumber; });\n } else if (typeof module != 'undefined' && module.exports) {\n module.exports = BigNumber;\n } else {\n if (!globalObject) {\n globalObject = typeof self != 'undefined' && self ? self : window;\n }\n globalObject.BigNumber = BigNumber;\n }\n})(this);\n\n\n\nfunction maxBN(a, b) {\n if (a.gt(b))\n return a;\n return b;\n}\n\nvar nums = readline().split(' ').map(function(x) { return Number(x) });\nvar N = nums[0];\nvar arr = [];\nfor (var i=0; i a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\t\n\t\tvar div = a[maxInd] - a[minInd];\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tvar numsD = 0;\n\t\t\n\t\ta[minInd]++;\n\t\ta[maxInd]--;\n\t\tstep++;\n\t\tmoves.push(\"\" + (maxInd + 1) + \" \" + (minInd+1));\n\t}\n\t\n\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\n\tprint((a[maxInd] - a[minInd]) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}", "positive_code": [{"source_code": "var st = readline().split(\" \");\nvar abc = readline().split(\" \");\n//var n = 3;\nvar k = parseInt(st[1]);\nvar abb = [];\nvar min;\nvar max;\nvar idMin = 0;\nvar idMax = 0;\nvar str1 = \"\";\nvar strM = \"\";\nvar m = 0;\nfor (i in abc){\nabc[i]=parseInt(abc[i]);\nabb[i]=parseInt(abc[i]);\n}\nfor (z=0;z1){\n\t\tabc[idMax-1] = abc [idMax-1]-1;\n\t\tabc[idMin-1] = abc [idMin-1]+1;\n\t\tm++;\n\t\tmi(abc);\n\t\tma(abc);\n\t}\n}\nstr1 = abc[idMax-1]-abc[idMin-1] + \" \" + m;\nprint(str1);\nfor (z=0;z1){\n\t\tabb[idMax-1] = abb [idMax-1]-1;\n\t\tabb[idMin-1] = abb [idMin-1]+1;\n\t\tm++;\n\t\tstrM = idMax + \" \" + idMin;\n\t\tprint(strM);\n\t}\n}\n\nfunction mi(x){\n\tmin = 10000000;\n\tidMin = 0;\n\tfor (i in x){\n\t\tif (x[i]max) {max = y[j];\n\t\tidMax = parseInt(j)+1;\n\t\t}\n\t}\n}"}], "negative_code": [{"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\nvar sortF = function(a,b){return a > b;};\n\nvar a_ = readline().split(' ').map(function(x){return parseInt(x);});\nvar sum = 0;\n\nvar a = [];\nfor(var i=0; i < n; i++)\n{\n\ta[i] = {v: a_[i], \n\t\t\tind: i+1};\n\tsum+=a_[i];\n}\n\na.sort(function(x, y){return x.v > y.v;})\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\n\twhile(step < k){\n\t\tvar div = a[n-1].v - a[0].v;\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\ta[0].v++;\n\t\ta[n-1].v--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t\t\n\t\ta.sort(function(x, y){return x.v > y.v;})\n\t\t// if (a[n-1].v < a[n-2].v){\n\t\t\t// var t = a[n-2];\n\t\t\t// a[n-2] = a[n-1];\n\t\t\t// a[n-1] = t;\n\t\t// }\n\t\t\n\t\t// if (a[0].v > a[1].v){\n\t\t\t// var t = a[1];\n\t\t\t// a[1] = a[0];\n\t\t\t// a[0] = t;\n\t\t// }\n\t}\n\tprint((a[n-1].v - a[0].v) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}\n"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\n\nvar a = readline().split(' ').map(function(x){return parseInt(x);});\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\tvar maxInd = 0;\n\tvar minInd = 0;\n\n\twhile(step < k){\n\t\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\t\n\t\tvar div = a[maxInd] - a[minInd];\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tvar numsD = 0;\n\t\t\n\t\ta[minInd]++;\n\t\ta[maxInd]--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1] + \" \" + a[0]);\n\t}\n\t\n\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\n\tprint((a[maxInd] - a[minInd]) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\nvar sortF = function(a,b){return a > b;};\n\nvar a_ = readline().split(' ').map(function(x){return parseInt(x);});\nvar sum = 0;\n\nvar a = [];\nfor(var i=0; i < n; i++)\n{\n\ta[i] = {v: a_[i], \n\t\t\tind: i+1};\n\tsum+=a_[i];\n}\n\na.sort(function(x, y){return x.v > y.v;})\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\n\twhile(step < k){\n\t\tvar div = a[n-1].v - a[0].v;\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tvar numsD = 0;\n\t\tfor(var j=0; j < Math.floor(n/2); j++){\n\t\t\tif (a[n-j-1].v - a[j].v == div) numsD++;\n\t\t}\n\t\tif (numsD > k) break;\n\t\t\n\t\ta[0].v++;\n\t\ta[n-1].v--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t\t\n\t\ta.sort(function(x, y){return x.v > y.v;})\n\t\t// if (a[n-1].v < a[n-2].v){\n\t\t\t// var t = a[n-2];\n\t\t\t// a[n-2] = a[n-1];\n\t\t\t// a[n-1] = t;\n\t\t// }\n\t\t\n\t\t// if (a[0].v > a[1].v){\n\t\t\t// var t = a[1];\n\t\t\t// a[1] = a[0];\n\t\t\t// a[0] = t;\n\t\t// }\n\t}\n\tprint((a[n-1].v - a[0].v) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}\n"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\nvar sortF = function(a,b){return a > b;};\n\nvar a_ = readline().split(' ').map(function(x){return parseInt(x);});\nvar sum = 0;\n\nvar a = [];\nfor(var i=0; i < n; i++)\n{\n\ta[i] = {v: a_[i], \n\t\t\tind: i+1};\n\tsum+=a_[i];\n}\n\na.sort(function(x, y){return x.v > y.v;})\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\n\twhile(step < k){\n\t\tvar div = a[n-1].v - a[0].v;\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\tif (sum % n != 0){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\ta[0].v++;\n\t\ta[n-1].v--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t\t\n\t\ta.sort(function(x, y){return x.v > y.v;})\n\t\t// if (a[n-1].v < a[n-2].v){\n\t\t\t// var t = a[n-2];\n\t\t\t// a[n-2] = a[n-1];\n\t\t\t// a[n-1] = t;\n\t\t// }\n\t\t\n\t\t// if (a[0].v > a[1].v){\n\t\t\t// var t = a[1];\n\t\t\t// a[1] = a[0];\n\t\t\t// a[0] = t;\n\t\t// }\n\t}\n\tprint((a[n-1].v - a[0].v) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}\n"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\n\nvar a = readline().split(' ').map(function(x){return parseInt(x);});\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\tvar maxInd = 0;\n\tvar minInd = 0;\n\n\twhile(step < k){\n\t\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\t\n\t\tvar div = a[maxInd] - a[minInd];\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tvar numsD = 0;\n\t\t\n\t\ta[minInd]++;\n\t\ta[maxInd]--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t}\n\t\n\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\n\tprint((a[maxInd] - a[minInd]) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\nvar sortF = function(a,b){return a > b;};\n\nvar a_ = readline().split(' ').map(function(x){return parseInt(x);});\nvar sum = 0;\n\nvar a = [];\nfor(var i=0; i < n; i++)\n{\n\ta[i] = {v: a_[i], \n\t\t\tind: i+1};\n\tsum+=a_[i];\n}\n\na.sort(function(x, y){return x.v > y.v;})\n\nvar moves = [];\n\nif (n==1) {\n\tprint(a[n] + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\n\twhile(step < k){\n\t\tvar div = a[n-1].v - a[0].v;\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\tif (sum % n != 0){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\ta[0].v++;\n\t\ta[n-1].v--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t\t\n\t\ta.sort(function(x, y){return x.v > y.v;})\n\t\t// if (a[n-1].v < a[n-2].v){\n\t\t\t// var t = a[n-2];\n\t\t\t// a[n-2] = a[n-1];\n\t\t\t// a[n-1] = t;\n\t\t// }\n\t\t\n\t\t// if (a[0].v > a[1].v){\n\t\t\t// var t = a[1];\n\t\t\t// a[1] = a[0];\n\t\t\t// a[0] = t;\n\t\t// }\n\t}\n\tprint((a[n-1].v - a[0].v) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}\n"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\n\nvar a = readline().split(' ').map(function(x){return parseInt(x);});\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\tvar maxInd = 0;\n\tvar minInd = 0;\n\n\twhile(step < k){\n\t\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\t\n\t\tvar div = a[maxInd] - a[minInd];\n\t\t\n\t\tif (div == 0){\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tvar numsD = 0;\n\t\t\n\t\ta[minInd]++;\n\t\ta[maxInd]--;\n\t\tstep++;\n\t\tmoves.push(\"\" + maxInd + \" \" + minInd);\n\t}\n\t\n\tfor(var i=0; i < n; i++){\n\t\t\tif (a[minInd] > a[i]) minInd = i;\n\t\t\tif (a[maxInd] < a[i]) maxInd = i;\n\t\t}\n\t\n\tprint((a[maxInd] - a[minInd]) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}"}, {"source_code": "var inp = readline().split(' ').map(function(x){return parseInt(x);});\nvar n = inp[0], k = inp[1];\n\nvar M = Math;\nvar sortF = function(a,b){return a > b;};\n\nvar a_ = readline().split(' ').map(function(x){return parseInt(x);});\nvar sum = 0;\n\nvar a = [];\nfor(var i=0; i < n; i++)\n{\n\ta[i] = {v: a_[i], \n\t\t\tind: i+1};\n\tsum+=a_[i];\n}\n\na.sort(function(x, y){return x.v > y.v;})\n\nvar moves = [];\n\nif (n==1) {\n\tprint(0 + \" \" + 0);\n}\nelse { \n\tvar step = 0;\n\n\twhile(step < k){\n\t\tvar div = a[n-1].v - a[0].v;\n\t\t\n\t\tif (div == 0){\n\t\t\tprint(0 + \" \" + step);\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (div == 1){\n\t\t\tif (sum % n != 0){\n\t\t\t\tprint(1 + \" \" + step);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\ta[0].v++;\n\t\ta[n-1].v--;\n\t\tstep++;\n\t\tmoves.push(\"\" + a[n-1].ind + \" \" + a[0].ind);\n\t\t\n\t\ta.sort(function(x, y){return x.v > y.v;})\n\t\t// if (a[n-1].v < a[n-2].v){\n\t\t\t// var t = a[n-2];\n\t\t\t// a[n-2] = a[n-1];\n\t\t\t// a[n-1] = t;\n\t\t// }\n\t\t\n\t\t// if (a[0].v > a[1].v){\n\t\t\t// var t = a[1];\n\t\t\t// a[1] = a[0];\n\t\t\t// a[0] = t;\n\t\t// }\n\t}\n\tif ((a[n-1].v - a[0].v) > 1)\n\t\tprint((a[n-1].v - a[0].v) + \" \" + step);\n\tfor(var i=0; i < moves.length; i++)\n\t\tprint(moves[i]);\n}\n"}, {"source_code": "var st = readline().split(\" \");\nvar abc = readline().split(\" \");\n//var n = 3;\nvar k = parseInt(st[1]);\nvar abb = [];\nvar min;\nvar max;\nvar idMin = 0;\nvar idMax = 0;\nvar str1 = \"\";\nvar strM = \"\";\nvar m = 0;\nfor (i in abc){\nabc[i]=parseInt(abc[i]);\nabb[i]=parseInt(abc[i]);\n}\nfor (z=0;z1){\n\t\tabc[idMax-1] = abc [idMax-1]-1;\n\t\tabc[idMin-1] = abc [idMin-1]+1;\n\t\tm++;\n\t}\n}\nstr1 = abc[idMax-1]-abc[idMin-1] + \" \" + m;\nprint(str1);\nfor (z=0;z1){\n\t\tabb[idMax-1] = abb [idMax-1]-1;\n\t\tabb[idMin-1] = abb [idMin-1]+1;\n\t\tm++;\n\t\tstrM = idMax + \" \" + idMin;\n\t\tprint(strM);\n\t}\n}\n\nfunction mi(x){\n\tmin = 10000000;\n\tidMin = 0;\n\tfor (i in x){\n\t\tif (x[i]max) {max = y[j];\n\t\tidMax = parseInt(j)+1;\n\t\t}\n\t}\n}"}, {"source_code": "var st = readline().split(\" \");\nvar abc = readline().split(\" \");\n//var n = 3;\nvar k = parseInt(st[1]);\nvar abb = [];\nvar min;\nvar max;\nvar idMin = 0;\nvar idMax = 0;\nvar str1 = \"\";\nvar strM = \"\";\nvar m = 0;\nfor (i in abc){\nabc[i]=parseInt(abc[i]);\nabb[i]=parseInt(abc[i]);\n}\nfor (z=0;z1){\n\t\tabc[idMax-1] = abc [idMax-1]-1;\n\t\tabc[idMin-1] = abc [idMin-1]+1;\n\t\tm++\n\t}\n}\nstr1 = abc[idMax-1]-abc[idMin-1] + \" \" + m;\nprint(str1);\nfor (z=0;z1){\n\t\tabb[idMax-1] = abb [idMax-1]-1;\n\t\tabb[idMin-1] = abb [idMin-1]+1;\n\t\tm++;\n\t\tstrM = idMax + \" \" + idMin;\n\t\tprint(strM);\n\t}\n}\n\nfunction mi(x){\n\tmin = 101;\n\tidMin = 0;\n\tfor (i in x){\n\t\tif (x[i]max) {max = y[j];\n\t\tidMax = parseInt(j)+1;\n\t\t}\n\t}\n}"}], "src_uid": "9cd42fb28173170a6cfa947cb31ead6d"} {"source_code": "// 'use strict';\n\nlet inputString = [];\nlet currentLine = 0;\n\nfunction readLine () {\n return inputString[currentLine++];\n}\n\nfunction readNumberLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => parseInt(val));\n}\n\nfunction readStringLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => String(val));\n}\n\nfunction readCharLine () {\n return readLine().replace(/\\s+$/, '').split('').map(val => String(val));\n}\n\nif (process.env.ROCKNROLL) {\n // const fs = require('fs');\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n //\n // const buffer = fs.readFileSync(process.env.INPUT_PATH, { encoding: 'utf8' });\n //\n // inputString = buffer.split('\\n');\n //\n // execution.then(() => ws.end());\n // setTimeout(main, 0); //main();\n}\nelse {\n process.stdin.resume().setEncoding('utf-8');\n\n process.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n // execution.then(() => ws.end());\n main();\n });\n}\n\nconst MOD = 1000000007;\n\nconst alpha = 'abcdefghijklmnopqrstuvwxyz'.split('');\nconst alphaBig = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n\n\nfunction main() {\n let [tc] = readNumberLine();\n\n while (tc--) {\n let [n] = readNumberLine();\n let res = 0;\n\n if (n > 1) {\n if (n === 2) {\n res = 1;\n }\n else if (n % 2 === 0) {\n res = 2;\n }\n else {\n if (n === 3) {\n res = 2;\n }\n else {\n res = 3;\n }\n }\n }\n\n console.log(`${res}`);\n }\n\n // endExecution();\n}\n\n// module.exports = execution;\n", "positive_code": [{"source_code": "const solve = (n) => {\n if (n == 1) return 0;\n if (n == 2) return 1;\n if (n == 3) return 2;\n if (n % 2 == 0) {\n return 2;\n } else {\n return 3;\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = input[0];\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0][0]));\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const n = +readLine();\n if (n === 1) console.log(0);\n else if (n === 2) console.log(1);\n else if (n === 3 || n % 2 === 0) console.log(2);\n else console.log(3);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n if(n%2 === 0){\n if(n === 2){\n console.log(1)\n }else{\n console.log(2);\n }\n }else if(n === 1){\n console.log(0);\n }else{\n if(n === 3){\n console.log(2);\n }else{\n console.log(3);\n }\n }\n }\n}"}, {"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let n = readline();\n if(n<3)\n {\n print(n-1);\n continue;\n }\n let c = 0;\n for(let i = 2; i <= Math.sqrt(n); i++)\n {\n if(n%i==0)\n {\n n = i;\n c++;\n break;\n }\n if((--n)%i==0)\n {\n n = i;\n c+=2;\n break;\n }\n }\n while(n != 1)\n {\n n--;\n c++;\n }\n print(c);\n}"}, {"source_code": "var tt = parseInt(readline());\nfor(; tt--;){\n var number = parseInt(readline());\n var res = (number==1) ?0:(number==2) ? 1 : (2+number%2-(number==3));\n print(res)\n}"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var n = parseInt(readline());\n if (n % 2 == 0) {\n if (n > 2) print(2);\n else print(1);\n }\n else {\n if (n >= 5) print(3);\n else if (n == 3) print(2);\n else print(0);\n }\n}"}], "negative_code": [{"source_code": "'use strict'\n\nlet t = readline();\n\nwhile(t--)\n{\n let n = readline();\n if(n<3)\n {\n print(n-1);\n continue;\n }\n let c = 0;\n for(let i = 2; i <= Math.sqrt(n); i++)\n {\n if(n%i==0)\n {\n n = i;\n c++;\n break;\n }\n }\n while(n != 1)\n {\n n--;\n c++;\n }\nprint(c);\n}"}, {"source_code": "var tt = parseInt(readline());\nfor(; tt--;){\n var number = parseInt(readline());\n var res = (number==1) ?0:(number==2) ? 1 : (1+number%2-(number==3));\n print(res)\n}\n"}, {"source_code": "// 'use strict';\n\nlet inputString = [];\nlet currentLine = 0;\n\nfunction readLine () {\n return inputString[currentLine++];\n}\n\nfunction readNumberLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => parseInt(val));\n}\n\nfunction readStringLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => String(val));\n}\n\nfunction readCharLine () {\n return readLine().replace(/\\s+$/, '').split('').map(val => String(val));\n}\n\nif (process.env.ROCKNROLL) {\n // const fs = require('fs');\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n //\n // const buffer = fs.readFileSync(process.env.INPUT_PATH, { encoding: 'utf8' });\n //\n // inputString = buffer.split('\\n');\n //\n // execution.then(() => ws.end());\n // setTimeout(main, 0); //main();\n}\nelse {\n process.stdin.resume().setEncoding('utf-8');\n\n process.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n // execution.then(() => ws.end());\n main();\n });\n}\n\nconst MOD = 1000000007;\n\nconst alpha = 'abcdefghijklmnopqrstuvwxyz'.split('');\nconst alphaBig = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n\n\nfunction main() {\n let [tc] = readNumberLine();\n\n while (tc--) {\n let [n] = readNumberLine();\n let res = 0;\n\n while (n > 1) {\n const upperBound = Math.floor(Math.sqrt(n));\n let done = false;\n for (let i = upperBound; i > 1; i--) {\n if (n % i === 0) {\n done = true;\n n = n / Math.max(i, n / i);\n res++;\n break;\n }\n }\n\n if (!done) {\n n--;\n res++;\n }\n }\n\n console.log(`${res}`);\n }\n\n // endExecution();\n}\n\n// module.exports = execution;\n"}, {"source_code": "// 'use strict';\n\nlet inputString = [];\nlet currentLine = 0;\n\nfunction readLine () {\n return inputString[currentLine++];\n}\n\nfunction readNumberLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => parseInt(val));\n}\n\nfunction readStringLine () {\n return readLine().replace(/\\s+$/, '').split(' ').map(val => String(val));\n}\n\nfunction readCharLine () {\n return readLine().replace(/\\s+$/, '').split('').map(val => String(val));\n}\n\nif (process.env.ROCKNROLL) {\n // const fs = require('fs');\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n //\n // const buffer = fs.readFileSync(process.env.INPUT_PATH, { encoding: 'utf8' });\n //\n // inputString = buffer.split('\\n');\n //\n // execution.then(() => ws.end());\n // setTimeout(main, 0); //main();\n}\nelse {\n process.stdin.resume().setEncoding('utf-8');\n\n process.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n // execution.then(() => ws.end());\n main();\n });\n}\n\nconst MOD = 1000000007;\n\nconst alpha = 'abcdefghijklmnopqrstuvwxyz'.split('');\nconst alphaBig = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n\n\nfunction main() {\n let [tc] = readNumberLine();\n\n while (tc--) {\n let [n] = readNumberLine();\n let res = 0;\n\n while (n > 1) {\n const upperBound = Math.floor(Math.sqrt(n));\n let done = false;\n for (let i = 2; i <= upperBound; i++) {\n if (n % i === 0) {\n done = true;\n n = n / Math.max(i, n / i);\n res++;\n break;\n }\n }\n\n if (!done) {\n n--;\n res++;\n }\n }\n\n console.log(`${res}`);\n }\n\n // endExecution();\n}\n\n// module.exports = execution;\n"}], "src_uid": "614aa068ce74090b6577006c45e549cf"} {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n console.log(\"YES\");\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n console.log(\"2 * 4 = 8\");\n console.log(\"3 * 8 = 24\");\n console.log(\"1 * 24 = 24\");\n for (let i = 5; i < n; i += 2) {\n console.log(`${i + 1} - ${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n console.log(\"4 * 5 = 20\");\n console.log(\"3 - 1 = 2\");\n console.log(\"2 + 2 = 4\");\n console.log(\"20 + 4 = 24\");\n for (let i = 6; i < n; i += 2) {\n console.log(`${i + 1} - ${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n", "positive_code": [{"source_code": "var n = parseInt(readline()),\n\t\t\tinitN = n;\n\n\t\tn % 2 == 0 ? n = evenMake24(n) : n = oddMake24(n);\n\n\t\tfunction evenMake24(n)\t{\n\t\t\tif(n < 4)\t{\n\t\t\t\tprint('NO');\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\tprint('YES');\n\t\t\tfor(var i = 1; i < 4; i+=2)\t\t{\n\t\t\t\tvar text = eqToString(i, i + 1, i * (i + 1), '*');\n\n\t\t\t\tprint(text);\n\t\t\t}\n\n\t\t\tprint(eqToString(2, 12, 2 * 12, '*'));\n\n\t\t\tfor(var i = 5; i < n + 1; i+=2)\t{\n\t\t\t\tif(i >= initN)\tprint(eqToString(24, 1, 24 * 1, '*'));\n\t\t\t\telse\tprint(eqToString(i + 1, i, i + 1 - i, '-'));\n\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t};\n\n\t\tfunction oddMake24(n)\t{\n\t\t\tif(n < 5)\t{\n\t\t\t\tprint('NO');\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\tprint('YES');\n\n\t\t\tprint(eqToString(5, 4, 5 * 4, '*'));\n\t\t\tprint(eqToString(3, 2, 3 + 2, '+'));\n\t\t\tprint(eqToString(5, 1, 5 - 1, '-'));\n\t\t\tprint(eqToString(20, 4, 20 + 4, '+'));\n\n\t\t\tfor(var i = 6; i < n + 1; i+=2)\t{\n\t\t\t\tif(i >= initN)\tprint(eqToString(24, 1, 24 * 1, '*'));\n\t\t\t\telse\tprint(eqToString(i + 1, i, i + 1 - i, '-'));\n\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t};\n\n\t\tfunction eqToString(num1, num2, rst, op)\t{\n\t\t\treturn num1 + ' ' + op + ' ' + num2 + ' = ' + rst;\n\t\t};"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n console.log(\"YES\");\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n console.log(\"2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\");\n for (let i = 5; i < n; i += 2) {\n console.log(`${i + 1} - ${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n console.log(\"4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\");\n for (let i = 6; i < n; i += 2) {\n console.log(`${i + 1} - ${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var console, make, x;\n\n make = function(x) {\n var i, _i;\n if (x < 4) {\n console.log('NO');\n } else {\n console.log('YES');\n }\n if (x === 4) {\n console.log('4 * 3 = 12');\n console.log('12 * 2 = 24');\n console.log('24 * 1 = 24');\n }\n if (x === 5) {\n console.log('1 + 2 = 3');\n console.log('3 * 4 = 12');\n console.log('5 - 3 = 2');\n console.log('12 * 2 = 24');\n }\n if (x > 5) {\n console.log('2 * 3 = 6');\n console.log('6 * 4 = 24');\n console.log('5 - 6 = -1');\n console.log('1 + -1 = 0');\n if (x !== 6) {\n for (i = _i = 7; 7 <= x ? _i <= x : _i >= x; i = 7 <= x ? ++_i : --_i) {\n console.log(\"0 * \" + i + \" = 0\");\n }\n }\n return console.log(\"24 + 0 = 24\");\n }\n };\n\n console = {};\n\n console.log = print;\n\n x = parseInt(readline(), 10);\n\n make(x);\n\n}).call(this);\n"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tif (n < 4) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\n\tif (n === 4) {\n\t\tprint('YES');\n\t\tprint('3 * 4 = 12');\n\t\tprint('1 * 2 = 2');\n\t\tprint('2 * 12 = 24');\n\t\treturn;\n\t}\n\n\tif (n === 5) {\n\t\tprint('YES');\n\t\tprint('5 * 4 = 20');\n\t\tprint('3 - 1 = 2');\n\t\tprint('2 * 2 = 4');\n\t\tprint('4 + 20 = 24');\n\t\treturn;\n\t}\n\n\tif (n === 6) {\n\t\tprint('YES');\n\t\tprint('5 - 6 = -1');\n\t\tprint('1 + -1 = 0');\n\t\tprint('3 * 4 = 12');\n\t\tprint('2 * 12 = 24');\n\t\tprint('24 + 0 = 24');\n\t\treturn;\n\t}\n\n\tif (n > 6) {\n\t\tprint('YES');\n\t\tprint('5 - 6 = -1');\n\t\tprint('1 + -1 = 0');\n\t\tprint('3 * 4 = 12');\n\t\tprint('2 * 12 = 24');\n\n\t\twhile (n > 6) {\n\t\t\tprint('0 * ' + n + ' = 0');\n\t\t\tn--;\n\t\t}\n\n\t\tprint('24 + 0 = 24');\n\t\treturn;\n\t}\n\n}.call(this));"}, {"source_code": "function ProblemSolver() {\n\n this.rec = function( arr , callCounter ) {\n var i , sz , j , k , newArr , a , b , c , d , res , r1 , newCallCounter;\n res = false;\n sz = arr.length;\n newCallCounter = callCounter + 1;\n if( callCounter > this.n - 1 ) {\n return res;\n }\n if( callCounter == this.n - 1 && sz > 1 ) {\n return res;\n }\n if( sz == 1 ) {\n if( arr[ 0 ] == 24 && callCounter == this.n - 1 ) {\n res = true;\n }\n return res;\n }\n for( i = 0 ; i < sz ; i++ ) {\n for( j = i + 1 ; j < sz ; j++ ) {\n a = arr[ i ] * arr[ j ];\n b = arr[ i ] + arr[ j ];\n c = arr[ i ] - arr[ j ];\n d = arr[ j ] - arr[ i ];\n newArr = new Array();\n for( k = 0 ; k < sz ; k++ ) {\n if( k != i && k != j ) {\n newArr.push( arr[ k ] );\n }\n }\n newArr.push( a );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = a;\n this.srr[ this.cn ] = \"*\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( b );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = b;\n this.srr[ this.cn ] = \"+\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( c );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = c;\n this.srr[ this.cn ] = \"-\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n if( c != d ) {\n newArr.push( d );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ j ];\n this.brr[ this.cn ] = arr[ i ];\n this.crr[ this.cn ] = d;\n this.srr[ this.cn ] = \"-\";\n this.cn++;\n res = true;\n return res;\n }\n }\n }\n }\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , arr;\n arr = new Array();\n if( this.n < 4 ) {\n print( \"NO\" );\n return;\n }\n print( \"YES\" );\n if( this.n > 8 ) {\n print( \"1 * 2 = 2\" );\n print( \"3 * 4 = 12\" );\n print( \"2 * 12 = 24\" );\n print( \"5 - 6 = -1\" );\n print( \"7 - 8 = -1\" );\n print( \"-1 - -1 = 0\" );\n for( i = 9 ; i <= this.n ; i++ ) {\n print( \"0 * \" + i + \" = 0\" );\n }\n print( \"24 + 0 = 24\" );\n return;\n }\n for( i = 1 ; i <= this.n ; i++ ) {\n arr.push( i );\n }\n this.cn = 0;\n res = this.rec( arr , 0 );\n for( i = this.cn - 1 ; i >= 0 ; i-- ) {\n print( this.arr[ i ] + \" \" + this.srr[ i ] + \" \" + this.brr[ i ] + \" = \" + this.crr[ i ] );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}], "negative_code": [{"source_code": ";(function () {\n\tvar n = +readline();\n\tif (n < 4) {\n\t\tprint('NO');\n\t\treturn;\n\t}\n\n\tif (n === 4) {\n\t\tprint('YES');\n\t\tprint('3 * 4 = 12');\n\t\tprint('1 * 2 = 2');\n\t\tprint('2 * 12 = 24');\n\t\treturn;\n\t}\n\n\tif (n === 5) {\n\t\tprint('YES');\n\t\tprint('5 * 4 = 20');\n\t\tprint('3 - 1 = 2');\n\t\tprint('2 * 2 = 4');\n\t\tprint('4 + 20 = 20');\n\t\treturn;\n\t}\n\n\tif (n === 6) {\n\t\tprint('YES');\n\t\tprint('5 - 6 = -1');\n\t\tprint('1 + -1 = 0');\n\t\tprint('3 * 4 = 12');\n\t\tprint('2 * 12 = 24');\n\t\tprint('24 + 0 = 24');\n\t\treturn;\n\t}\n\n\tif (n > 6) {\n\t\tprint('YES');\n\t\tprint('5 - 6 = -1');\n\t\tprint('1 + -1 = 0');\n\t\tprint('3 * 4 = 12');\n\t\tprint('2 * 12 = 24');\n\n\t\twhile (n > 6) {\n\t\t\tprint('0 * ' + n + ' = 0');\n\t\t\tn--;\n\t\t}\n\n\t\tprint('24 + 0 = 24');\n\t\treturn;\n\t}\n\n}.call(this));"}, {"source_code": "function ProblemSolver() {\n\n this.rec = function( arr , callCounter ) {\n var i , sz , j , k , newArr , a , b , c , d , res , r1 , newCallCounter;\n res = false;\n sz = arr.length;\n newCallCounter = callCounter + 1;\n if( callCounter > this.n - 1 ) {\n return res;\n }\n if( callCounter == this.n - 1 && sz > 1 ) {\n return res;\n }\n if( sz == 1 ) {\n if( arr[ 0 ] == 24 && callCounter == this.n - 1 ) {\n res = true;\n }\n return res;\n }\n for( i = 0 ; i < sz ; i++ ) {\n for( j = i + 1 ; j < sz ; j++ ) {\n a = arr[ i ] * arr[ j ];\n b = arr[ i ] + arr[ j ];\n c = arr[ i ] - arr[ j ];\n d = arr[ j ] - arr[ i ];\n newArr = new Array();\n for( k = 0 ; k < sz ; k++ ) {\n if( k != i && k != j ) {\n newArr.push( arr[ k ] );\n }\n }\n newArr.push( a );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = a;\n this.srr[ this.cn ] = \"*\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( b );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = b;\n this.srr[ this.cn ] = \"+\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( c );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = c;\n this.srr[ this.cn ] = \"-\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n if( c != d ) {\n newArr.push( d );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ j ];\n this.brr[ this.cn ] = arr[ i ];\n this.crr[ this.cn ] = d;\n this.srr[ this.cn ] = \"-\";\n this.cn++;\n res = true;\n return res;\n }\n }\n }\n }\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , arr;\n arr = new Array();\n if( this.n < 4 ) {\n print( \"NO\" );\n }\n if( this.n > 8 ) {\n print( \"1 * 2 = 2\" );\n print( \"3 * 4 = 12\" );\n print( \"2 * 12 = 24\" );\n print( \"5 - 6 = -1\" );\n print( \"7 - 8 = -1\" );\n print( \"-1 - -1 = 0\" );\n for( i = 9 ; i <= this.n ; i++ ) {\n print( \"0 * \" + i + \" = 0\" );\n }\n print( \"24 + 0 = 24\" );\n return;\n }\n for( i = 1 ; i <= this.n ; i++ ) {\n arr.push( i );\n }\n this.cn = 0;\n res = this.rec( arr , 0 );\n for( i = this.cn - 1 ; i >= 0 ; i-- ) {\n print( this.arr[ i ] + \" \" + this.srr[ i ] + \" \" + this.brr[ i ] + \" = \" + this.crr[ i ] );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.rec = function( arr , callCounter ) {\n var i , sz , j , k , newArr , a , b , c , d , res , r1 , newCallCounter;\n res = false;\n sz = arr.length;\n newCallCounter = callCounter + 1 ;\n if( callCounter > this.n - 1 ) {\n return res ;\n }\n if( callCounter == this.n - 1 && sz > 1 ) {\n return res ;\n }\n if( sz == 1 ) {\n if( arr[ 0 ] == 24 && callCounter == this.n - 1 ) {\n res = true;\n }\n return res;\n }\n for( i = 0 ; i < sz ; i++ ) {\n for( j = i + 1 ; j < sz ; j++ ) {\n a = arr[ i ] * arr[ j ];\n b = arr[ i ] + arr[ j ];\n c = arr[ i ] - arr[ j ];\n d = arr[ j ] - arr[ i ];\n newArr = new Array();\n for( k = 0 ; k < sz ; k++ ) {\n if( k != i && k != j ) {\n newArr.push( arr[ k ] );\n }\n }\n newArr.push( a );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = a;\n this.srr[ this.cn ] = \"*\";\n this.cn++;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( b );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = b;\n this.srr[ this.cn ] = \"+\";\n this.cn++ ;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n newArr.push( c );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ i ];\n this.brr[ this.cn ] = arr[ j ];\n this.crr[ this.cn ] = c;\n this.srr[ this.cn ] = \"-\";\n this.cn++ ;\n res = true;\n return res;\n }\n newArr.splice( newArr.length - 1 , 1 );\n if( c != d ) {\n newArr.push( d );\n r1 = this.rec( newArr , newCallCounter );\n if( r1 == true ) {\n this.arr[ this.cn ] = arr[ j ];\n this.brr[ this.cn ] = arr[ i ];\n this.crr[ this.cn ] = d;\n this.srr[ this.cn ] = \"-\";\n this.cn++ ;\n res = true;\n return res;\n }\n }\n }\n }\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , arr;\n arr = new Array();\n if( this.n > 8 ) {\n print( \"1 * 2 = 2\" );\n print( \"3 * 4 = 12\" );\n print( \"2 * 12 = 24\" );\n print( \"5 - 6 = -1\" );\n print( \"7 - 8 = -1\" );\n print( \"-1 - -1 = 0\" );\n for( i = 9 ; i <= this.n ; i++ ) {\n print( \"0 * \" + i + \" = 0\" );\n }\n print( \"24 + 0 = 24\" );\n return ;\n }\n for( i = 1 ; i <= this.n ; i++ ) {\n arr.push( i );\n }\n this.cn = 0;\n res = this.rec( arr , 0 );\n for( i = this.cn - 1 ; i >= 0 ; i-- ) {\n print( this.arr[ i ] + \" \" + this.srr[ i ] + \" \" + this.brr[ i ] + \" = \" + this.crr[ i ] );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n console.log(\"YES\");\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n console.log(\"2 * 4 = 8\");\n console.log(\"3 * 8 = 24\");\n console.log(\"1 * 24 = 24\");\n for (let i = 5; i < n; i += 2) {\n console.log(`${i + 1}-${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n console.log(\"4 * 5 = 20\");\n console.log(\"3 - 1 = 2\");\n console.log(\"2 + 2 = 4\");\n console.log(\"20 + 4 = 24\");\n for (let i = 6; i < n; i += 2) {\n console.log(`${i + 1}-${i} = 1`);\n console.log(`1 * 24 = 24`);\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n let data = \"YES\\n2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\\n\";\n for (let i = 5; i < n; i += 2) {\n data.concat(i + 1 + \" - \" + i + \" = \" + \"1\");\n }\n console.log(data);\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n let data = \"YES\\n4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\\n\";\n for (let i = 6; i < n; i += 2) {\n data.concat(i + 1 + \" - \" + i + \" = \" + \"1\");\n }\n console.log(data);\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n let data = \"YES\\n2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\\n\";\n for (let i = 5; i < n - 2; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n data += `${n} - ${n - 1} = 1`;\n console.log(data);\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n let data = \"YES\\n4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\\n\";\n for (let i = 6; i < n - 2; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n data += `${n} - ${n - 1} = 1`;\n console.log(data);\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n let data = \"YES\\n2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\\n\";\n for (let i = 5; i < n; i += 2) {\n data.concat(`${i + 1} - ${i} = 1\\n`);\n }\n console.log(data);\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n let data = \"YES\\n4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\\n\";\n for (let i = 6; i < n; i += 2) {\n data.concat(`${i + 1} - ${i} = 1`);\n }\n console.log(data);\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n let data = \"YES\\n2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\\n\";\n for (let i = 5; i < n - 2; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n data += `${n} - ${n - 1} = 1`;\n console.log(data);\n console.log(\"\");\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n let data = \"YES\\n4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\\n\";\n for (let i = 6; i < n - 2; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n data += `${n} - ${n - 1} = 1`;\n console.log(data);\n console.log(\"\");\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0];\n if (n <= 3) console.log(\"NO\");\n else {\n n % 2 === 0 ? processEven(n) : processOdd(n);\n }\n};\n//\u5904\u7406\u8f93\u5165\nlet data = \"\";\nprocess.stdin.on(\"data\", (c) => (data += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = data.split(EOL);\n processData(lines);\n});\n\n//\u5904\u7406n\u4e3a\u5076\u6570\u60c5\u51b5\nfunction processEven(n) {\n let data = \"YES\\n2 * 4 = 8\\n3 * 8 = 24\\n1 * 24 = 24\\n\";\n for (let i = 5; i < n; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n console.log(data);\n}\n//\u5904\u7406n\u4e3a\u5947\u6570\u60c5\u51b5\nfunction processOdd(n) {\n let data = \"YES\\n4 * 5 = 20\\n3 - 1 = 2\\n2 + 2 = 4\\n20 + 4 = 24\\n\";\n for (let i = 6; i < n; i += 2) {\n data += `${i + 1} - ${i} = 1\\n`;\n }\n console.log(data);\n}\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var console, make, x;\n\n make = function(x) {\n var i, zeros, _i;\n if (x < 4) {\n console.log('NO');\n } else {\n console.log('YES');\n }\n if (x === 4) {\n console.log('4 * 3 = 12');\n console.log('12 * 2 = 24');\n console.log('24 * 1 = 24');\n }\n if (x === 5) {\n console.log('1 + 2 = 3');\n console.log('3 * 4 = 12');\n console.log('5 - 3 = 2');\n console.log('12 * 2 = 24');\n }\n if (x > 5) {\n console.log('2 * 3 = 6');\n console.log('6 * 4 = 24');\n console.log('5 - 6 = -1');\n console.log('1 + -1 = 0');\n zeros = 0;\n for (i = _i = 7; 7 <= x ? _i <= x : _i >= x; i = 7 <= x ? ++_i : --_i) {\n console.log(\"0 * \" + i + \" = 0\");\n zeros++;\n }\n return console.log(\"24 + 0 = 24\");\n }\n };\n\n console = {};\n\n console.log = print;\n\n x = parseInt(readline(), 10);\n\n make(x);\n\n}).call(this);\n"}], "src_uid": "1bd1a7fd2a07e3f8633d5bc83d837769"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tsum = data[0], limit = data[1],\n\t\tresult = [];\n\tfunction lsb(x) {\n\t\tvar power = 1;\n\t\twhile (x%2 == 0) {\n\t\t\tx /= 2;\n\t\t\tpower *= 2;\n\t\t}\n\t\treturn power;\n\t}\n\tfor (var i = limit; i >= 1; --i) {\n\t\tvar bit = lsb(i);\n\t\tif (bit <= sum) {\n\t\t\tresult.push(i);\n\t\t\tsum -= bit;\n\t\t\tif (sum == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (sum != 0) {\n\t\tprint(-1);\n\t} else {\n\t\tprint(result.length);\n\t\tprint(result.join(' '));\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "var x = readline().trim().split(' ').map((_x)=>parseInt(_x))\nvar s = x[0],l = x[1];\nvar a = s;\nvar bits = []\nvar ans=[];\nvar available =[]\nwhile(a>0){\n bits.push(a%2);\n a=parseInt(a/2)\n}\n\nfor(var i=0;i<=l;i++){\n available.push(1)\n}\n\nvar p =bits.length-1; \nvar pp = parseInt(Math.pow(2,p))\nvar has = true;\nwhile(bits.length>0){p\n if(bits[p]==0){\n p--;\n pp=parseInt(pp/2);\n if(p==-1)\n break;\n continue;\n }\n var w = pp;\n var find = false;\n while(w<=l){\n \n if(available[w]==1){\n available[w]=0;\n ans.push(w)\n find=true;\n bits[p]--;\n break;\n }\n w+=2*pp\n }\n if(!find)\n {\n if(p>0){\n bits[p-1]+=2;\n bits[p]--;\n }else{\n has = false;\n break;\n }\n \n }\n}\nif(has){\n print(ans.length)\n print(ans.join(' '))\n}else{\n print(-1)\n}\n"}, {"source_code": "function reverse(s){\n return s.split(\"\").reverse().join(\"\");\n}\n\nfunction pair(num, lowbit){\n\tthis.num = num\n\tthis.lowbit = lowbit\n}\n\nvar firstLine = readline().split(\" \").map(Number);\nvar sum = firstLine[0];\nvar limit = firstLine[1];\n\nvar firstDigit = 0 \n\nvar binaries = []\n\nfor(var i = 1; i <= limit; i ++){\n\tfirstDigit = reverse(i.toString(2)).indexOf(\"1\")\n\tbinaries.push(new pair(i, firstDigit))\n}\n\n//That is, 2 to the power of lowbit\nvar numbers = binaries.map(function(a){return new pair(a.num, Math.pow(2, a.lowbit))})\n\nvar construct = 0\n\n//Descending order\nnumbers.sort(function(a,b){return b.lowbit-a.lowbit})\n\nvar done = false\n\nvar myNums = []\n\nwhile(!done){\n\tif(sum === construct){\n\t\tdone = true\n\t\tbreak\n\t}\n\tif(numbers.length === 0){\n\t\tbreak\n\t}\n\tnext = numbers.shift()\n\tif(sum - construct < next.lowbit){\n\t\tcontinue\n\t}\n\telse{\n\t\tmyNums.push(next)\n\t\tconstruct += next.lowbit\n\t}\n}\n\nif(done){\n\tprint(myNums.length)\n\tfor(var i = 0; i < myNums.length; i++){\n\t\tif(i === myNums.length - 1){\n\t\t\twrite(myNums[i].num)\n\t\t}\n\t\telse{\n\t\t\twrite(myNums[i].num + \" \")\n\t\t}\n\t}\n\t// myNums.forEach(function(a){write(a.num+ \" \")})\n}\nelse{\n\tprint(-1)\n}"}], "negative_code": [{"source_code": "function reverse(s){\n return s.split(\"\").reverse().join(\"\");\n}\n\nfunction pair(num, lowbit){\n\tthis.num = num\n\tthis.lowbit = lowbit\n}\n\nvar firstLine = readline().split(\" \").map(Number);\nvar sum = firstLine[0];\nvar limit = firstLine[1];\n\nvar firstDigit = 0 \n\nvar binaries = []\n\nfor(var i = 1; i <= limit; i ++){\n\tfirstDigit = reverse(i.toString(2)).indexOf(\"1\")\n\tbinaries.push(new pair(i, firstDigit))\n}\n\n//That is, 2 to the power of lowbit\nvar numbers = binaries.map(function(a){return new pair(a.num, Math.pow(2, a.lowbit))})\n\nvar construct = 0\n\n//Descending order\nnumbers.sort(function(a,b){return b.lowbit-a.lowbit})\n\nvar done = false\n\nvar myNums = []\n\nwhile(!done){\n\tif(numbers.length === 0){\n\t\tbreak\n\t}\n\tif(sum === construct){\n\t\tdone = true\n\t\tbreak\n\t}\n\tnext = numbers.shift()\n\tif(sum - construct < next.lowbit){\n\t\tcontinue\n\t}\n\telse{\n\t\tmyNums.push(next)\n\t\tconstruct += next.lowbit\n\t}\n}\n\nif(done){\n\tprint(myNums.length)\n\tfor(var i = 0; i < myNums.length; i++){\n\t\tif(i === myNums.length - 1){\n\t\t\twrite(myNums[i].num)\n\t\t}\n\t\telse{\n\t\t\twrite(myNums[i].num + \" \")\n\t\t}\n\t}\n\t// myNums.forEach(function(a){write(a.num+ \" \")})\n}\nelse{\n\tprint(-1)\n}"}], "src_uid": "1e4b638810ea9fa83c60a934ad49bf5e"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e3 + 1\r\nvar iv = new Array(maxN + 1).fill(0n)\r\niv[1] = 1n\r\nfor (let i = 2n; i <= maxN; i++) {\r\n iv[i] = mod - (mod / i * iv[mod % i]) % mod\r\n}\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var next = new Array(n)\r\n var q = []\r\n for (let i = 0; i < n; i++) {\r\n next[i] = (i + 1) % n\r\n\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (gcd(a[i], a[next[i]]) === 1) q.push(i)\r\n }\r\n var used = new Array(n).fill(false)\r\n var ans = []\r\n while (q.length !== 0) {\r\n // console.log(q)\r\n var pop = q.shift()\r\n // console.log(q)\r\n\r\n if (!used[pop]) {\r\n var pair = next[pop]\r\n ans.push(pair+1)\r\n if (pair !== pop) {\r\n used[pair] = true\r\n next[pop] = next[pair]\r\n\r\n if (gcd(a[pop], a[next[pop]]) === 1) {\r\n q.push(pop)\r\n }\r\n\r\n }\r\n }\r\n }\r\n\r\n // console.log(q)\r\n console.log(ans.length, ans.join(' '))\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 10e3 + 1\r\nvar iv = new Array(maxN + 1).fill(0n)\r\niv[1] = 1n\r\nfor (let i = 2n; i <= maxN; i++) {\r\n iv[i] = mod - (mod / i * iv[mod % i]) % mod\r\n}\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var next = new Array(n)\r\n var q = []\r\n for (let i = 0; i < n; i++) {\r\n next[i] = (i + 1) % n\r\n\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (gcd(a[i], a[next[i]]) === 1) q.push(i)\r\n }\r\n var used = new Array(n).fill(false)\r\n var ans = []\r\n while (q.length !== 0) {\r\n // console.log(q)\r\n var pop = q.shift()\r\n // console.log(q)\r\n\r\n if (!used[pop]) {\r\n var pair = next[pop]\r\n ans.push(pair+1)\r\n if (pair !== pop) {\r\n used[pair] = true\r\n next[pop] = next[pair]\r\n\r\n if (gcd(a[pop], a[next[pop]]) === 1) {\r\n q.push(pop)\r\n }\r\n\r\n }\r\n }\r\n }\r\n\r\n // console.log(q)\r\n console.log(ans.length, ans.join(' '))\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "5d3d68a5b7a6e1357f4d4318805976ee"} {"source_code": "function NOD(A)\n{ \n var n = A.length, x = Math.abs(A[0]);\n for (var i = 1; i < n; i++)\n { var y = Math.abs(A[i]);\n while (x && y){ x > y ? x %= y : y %= x; }\n x += y;\n }\n return x;\n}\n\nfunction main()\n{\n // Your code here\n n = Number(readline());\n a = readline().split(' ').map(Number);\n a = a.sort(function(a,b){return a - b});\n d = a[1] - a[0];\n for (var i = 1; i < n-1; i++) {\n s = a[1+i] - a[i];\n d = NOD([d, s]);\n }\n z = Math.round((a[n-1]-a[0]) / d);\n print(z-n+1);\n return 0;\n}\nmain();\n", "positive_code": [{"source_code": "var n = readline().split(' ').map(function(v){return v;});\nvar arr = readline().split(' ').map(function(v){return v;});\narr.sort(function(a, b) {\n return a - b;\n});\nvar g = 0;\nvar ans = 0;\nfor (var i = 1; i < n; i++) {\n g = gcd_rec(g, arr[i] - arr[i - 1]);\n}\nfor (var i = 1; i < n; i++) {\n ans += ((arr[i] - arr[i - 1]) / g) - 1;\n}\nprint(ans);\n\nfunction gcd_rec(a, b) {\n if (b) {\n return gcd_rec(b, a % b);\n } else {\n return Math.abs(a);\n }\n}"}, {"source_code": "var n = parseInt(readline())\nvar x = readline().split(\" \").map(v => parseInt(v));\n\nx.sort(function(a,b){return a-b;})\n\n\n\nfunction gcd(x, y){\n return y?gcd(y,x%y):x;\n}\n\nvar g = 0\n\nfor (var i = 1; i < n; ++i)\n{\n g = gcd(g, x[i] - x[i-1])\n}\n\nvar cnt = (x[n-1]-x[0]) / g + 1\n\nprint(cnt - n)\n"}, {"source_code": "var gcd = function(a, b) {\n if (!b) {\n return a;\n }\n return gcd(b, a % b);\n};\n\nvar n = readline();\nvar x = readline().split(\" \").map(v => +v.trim());\nx = x.sort(function(a,b) { return a - b; } );\n\nvar nod = gcd(x[1] - x[0], x[2] - x[1]);\nfor (var i = 3; i < n; ++i) {\n nod = gcd(nod, x[i] - x[i - 1]);\n}\n\nvar ans = 0;\nfor (var i = 1; i < n; ++i) {\n ans += (x[i] - x[i - 1]) / nod - 1;\n}\nprint(ans);\n"}, {"source_code": "function gcd(a, b)\n{\n return b ? gcd (b, a % b) : a;\n}\n\nvar n = readline();\nvar arr = readline().split(\" \").map(v => +v.trim());\narr.sort((a, b) => a - b);\nvar delta = [];\nfor (var i = 1; i < n; i++)\n delta.push(arr[i] - arr[i-1]);\nvar g = gcd(delta[0], delta[1]);\nfor (var i = 2; i < n-1; i++)\n g = gcd(g, delta[i]);\nvar ans = 0;\nfor (var i = 0; i < n - 1; i++)\n{\n ans += delta[i] / g - 1;\n}\nprint(ans);"}, {"source_code": "var gcd = function(a, b) {\n if (!b) {\n return a;\n }\n return gcd(b, a % b);\n};\n\nvar n = readline();\nvar x = readline().split(\" \").map(v => +v.trim());\nx = x.sort(function(a,b) { return a - b; } );\n\nvar nod = gcd(x[1] - x[0], x[2] - x[1]);\nfor (var i = 3; i < n; ++i) {\n nod = gcd(nod, x[i] - x[i - 1]);\n}\n\nvar ans = 0;\nfor (var i = 1; i < n; ++i) {\n ans += (x[i] - x[i - 1]) / nod - 1;\n}\nprint(ans);"}, {"source_code": "function gcd (a, b) {\n if (!b) return a\n return gcd(b, a % b)\n}\n\nvar n = parseInt(readline())\nvar a = readline().split(' ').map(x => parseInt(x))\n\na.sort((a, b) => a - b)\n\nvar i = 0\nvar x = 0\nfor (i = 1; i < n; i += 1) {\n var d = a[i] - a[i - 1]\n if (x === 0) {\n x = d\n } else {\n x = gcd(x, d)\n }\n}\n\nvar m = 0\nfor (i = 1; i < n; i += 1) {\n var d = a[i] - a[i - 1]\n m += d / x - 1\n}\n\nprint(m)\n"}, {"source_code": "function gcd(a,b) {\n if (b == 0) \n return a;\n return gcd(b, a % b);\n};\n\nfunction sortNumber(a,b) {\n return a - b;\n} \n\n(function main() {\n var n = parseInt(readline());\n var a = readline().split(' ').map(function (x) { \n return parseInt(x); \n }).sort(sortNumber);\n var d = a[1] - a[0];\n for (i = 1; i < a.length - 1; i++) {\n d = gcd(d, a[i + 1] - a[i]);\n }\n var ans = (a[a.length - 1] - a[0]) / d - n + 1;\n print(ans);\n})()"}, {"source_code": "var n = parseInt(readline());\nvar x = readline().split(' ').map(function (x) { return parseInt(x); });\n\nx.sort(function(a, b) {\n return a - b;\n});\n\nvar distances = [];\n\nfor (i = 0; i < n - 1; i++) {\n distances.push(x[i+1] - x[i]);\n}\n\nvar nd = NOD(distances);\nvar cnt = 0;\n\nfor (var i = 0; i < n - 1; i++) {\n cnt += (distances[i]/nd)-1;\n}\n\nfunction NOD(A) {\n var n = A.length, x = Math.abs(A[0]);\n for (var i = 1; i < n; i++) {\n var y = Math.abs(A[i]);\n while (x && y){ x > y ? x %= y : y %= x; }\n x += y;\n }\n return x;\n}\n\nprint(cnt);"}, {"source_code": "var gcd = function(a, b) {\n if ( ! b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nn = parseInt(readline());\na = (readline().split(' '));\nfor (var i = 0; i < a.length; i++) {\n a[i] = parseInt(a[i]);\n}\na.sort((a, b) => a - b);\nrcd = a[1] - a[0];\nfor (var i = 2; i < a.length; i++) {\n rcd = gcd(rcd, a[i] - a[i-1]);\n}\n\nsc = 0;\nfor (var i = 1; i < a.length; i++)\n sc += (a[i] - a[i-1]) / rcd - 1;\n\nprint(sc);\n"}, {"source_code": "var n = parseInt(readline());\nvar s = readline().split(\" \");\nvar a = [];\nfunction compare(a, b) {\n return a - b;\n}\nfor(var i = 0; i < n; i++) {\n a.push(parseInt(s[i]));\n}\na.sort(compare);\n\nfunction gcd(a, b) {\n while(a > 0 && b > 0) {\n if(a > b) a %= b;\n else b %= a;\n }\n return a + b;\n}\nvar ans = a[1] - a[0];\nfor(var i = 2; i < n; i++) {\n ans = gcd(ans, a[i] - a[i - 1]);\n}\nprint((a[n - 1] - a[0]) / ans - n + 1);"}, {"source_code": "var n = parseInt(readline());\nvar xs = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nxs.sort(function (a,b) { return a-b; });\n\nfunction gcd(a, b) {\n var c = 0;\n while (b !== 0) {\n c = a % b;\n a = b;\n b = c;\n }\n return a;\n}\n\nvar totalGCD = xs[1] - xs[0];\n\nfor (var i = 1; i < n; i++) {\n totalGCD = gcd(totalGCD, xs[i] - xs[i-1]);\n}\n\nvar ans = 0;\nfor (i = 1; i < n; i++) {\n ans += Math.floor((xs[i] - xs[i-1] - 1) / totalGCD);\n}\n\nprint(ans);"}, {"source_code": "function gcd(a,b)\n{\n if (b)\n return gcd(b,a%b);\n return a;\n}\nvar n=readline().split(\" \").map(x=>parseInt(x))[0];\nvar numbers=readline().split(\" \").map(x=>parseInt(x));\nnumbers.sort(function(a,b){return a-b});\nvar ans=numbers[1]-numbers[0];\nfor (i=1;i b;\n}\nfor(var i = 0; i < n; i++) {\n a.push(parseInt(s[i]));\n}\na.sort(compare);\n\nfunction gcd(a, b) {\n while((a > 0) && (b > 0)) {\n if(a > b) a %= b;\n else b %= a;\n }\n return a + b;\n}\nvar ans = a[1] - a[0];\nfor(var i = 1; i < n; i++) {\n ans = gcd(ans, a[i] - a[i - 1]);\n}\nprint((a[n - 1] - a[0]) / ans - n + 1);"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \").map(function(v){return +v;});\narr.sort();\nvar g = 0;\nvar ans = 0;\nfor (var i = 1; i < n; i++) {\n g = gcd_rec(g, arr[i] - arr[i - 1]);\n}\nfor (var i = 1; i < n; i++) {\n ans += (arr[i] - arr[i - 1]) / g - 1;\n}\nprint(ans);\n\nfunction gcd_rec(a, b) {\n if (b) {\n return gcd_rec(b, a % b);\n } else {\n return Math.abs(a);\n }\n}"}, {"source_code": "var n = parseInt(readline())\nvar x = readline().split(\" \").map(v => parseInt(v));\n\nx.sort(function(a,b){return a>b;})\n\n\nfunction gcd(x, y){\n return y?gcd(y,x%y):x;\n}\n\nvar g = 0\n\nfor (var i = 1; i < n; ++i)\n{\n g = gcd(g, x[i] - x[i-1])\n}\n\nvar cnt = (x[n-1]-x[0]) / g + 1\n\nprint(cnt - n)\n"}, {"source_code": "var n = parseInt(readline());\nvar x = readline().split(' ').map(function (x) { return parseInt(x); });\n\nx.sort(function(a, b) {\n return a - b;\n});\n\nvar padding;\n\nvar m = 0;\n\nif (x[1] - x[0] < x[x.length-1] - x[x.length-2]) {\n padding = x[1] - x[0];\n} else {\n padding = x[x.length-1] - x[x.length-2];\n}\n\nfor (i = 1; i < x.length; i++) {\n var currentPadding = x[i] - x[i-1];\n if (currentPadding !== padding) {\n m = currentPadding / padding - 1;\n break;\n }\n}\n\nprint(m);"}], "src_uid": "805d82c407c1b34f217f8836454f7e09"} {"source_code": "var line = readline().split(' ');\n\nvar n = parseInt(line[0]);\nvar t = parseInt(line[1]);\nvar c = parseFloat(line[2]);\n\nvar a = readline().split(' ');\n\nvar m = parseInt(readline());\n\nvar p = readline().split(' ');\n\nvar mean = [0.0];\n\nvar real = [];\nreal[t-1] = 0;\nfor(var j = 0; j < t; j++){\n real[t-1] += a[j]/t;\n}\n\nfor(var i=0; i { return Number(v); }),\n\tn = line[0],\n\tT = line[1],\n\tc = line[2];\n\nvar a = readline().split(' ').map((v) => { return Number(v); });\n\nvar m = Number(readline());\n\nvar p = readline().split(' ').map((v) => { return Number(v); });\n\nvar sum = 0;\nvar aSum = 0;\nvar pCounter = 0;\nvar approx = 0;\nfor (var i = 0; i < n; i++) {\n\tsum += a[i];\n\taSum += a[i];\n\tif (a[i - T]) {\n\t\taSum = aSum - a[i - T];\n\t}\n\tvar real = aSum/T;\n\tapprox = (approx + a[i]/T)/c;\n\tif (i + 1 === p[pCounter]) {\n\t\treal = aSum/T;\n\t\tvar error = Math.abs(approx - real)/real;\n\t\tprint(real.toFixed(6) + ' ' + approx.toFixed(6) + ' ' + error.toFixed(6));\n\t\tif (pCounter < m) {\n\t\t\tpCounter++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n"}, {"source_code": "var init = readline().split(' '),\n n = +init[0],\n T = +init[1],\n c = +init[2],\n a = readline().split(' '),\n m = +readline(),\n p = readline().split(' '),\n real,\n approx = 0,\n error,\n i = 0,\n j = 0,\n l = 0,\n d,\n mean = 0;\nfor (; i < n && j < m; i++) {\n d = a[i]/T;\n approx = (approx + d)/c;\n mean += d;\n i >= T && (mean -= a[i - T]/T);\n if (i === p[j] - 1) {\n j++;\n real = i + 1 < T ? mean * T / (i + 1) : mean;\n error = Math.abs(approx-real)/real;\n print(real.toFixed(5) + ' '\n + approx.toFixed(5) + ' '\n + error.toFixed(5));\n }\n}"}], "negative_code": [], "src_uid": "be8d2eff2f34e72625566680ae188c49"} {"source_code": "var i, input, buffer = [], blockWidth = 0, frameChar = '*', xlPad = false;\n\nfunction formatText(text, left){\n var lPad = '', rPad;\n if ((blockWidth - text.length) % 2) {\n if (xlPad) lPad = ' ';\n xlPad = !xlPad;\n }\n lPad += ' '.repeat(Math.floor((blockWidth - text.length)/2));\n rPad = ' '.repeat(blockWidth - text.length - lPad.length);\n return frameChar + lPad + text + rPad + frameChar;\n}\n\nwhile (true){\n input = readline();\n if (typeof input === 'undefined') break;\n\n if (input.length > blockWidth) blockWidth = input.length;\n buffer.push(input);\n}\n\nprint(frameChar.repeat(blockWidth + 2));\n\nfor (i=0; im) m=l.length;\n\tt[t.length]=l;\n}\ns=Array(m+3).join('*');\nprint(s);\nc=1;\nfor (l=0;l width) {\n\t\twidth = line.length;\n\t}\n}\nvar stars = [],\n output = [],\n left = true;\nfor (var i = 0; i < width + 2; i++) {\n\tstars.push('*');\n}\noutput.push(stars.join(''));\nlines = lines.map(function (el) {\n\tvar diff = width - el.length;\n\tvar spaces = [];\n\tfor (var i = 0; i < Math.floor(diff / 2); i++) {\n\t\tspaces.push(' ');\n\t}\n\tif (diff % 2 === 0) {\n\t\toutput.push(\"*\" + spaces.concat(el.split('').concat(spaces)).join('') + \"*\");\n\t} else {\n\t\tvar result = [];\n\t\tif (left) {\n\t\t\tresult = result.concat(spaces);\n\t\t\tresult = result.concat(el.split(''));\n\t\t\tresult = result.concat(spaces.concat([' ']));\n\t\t} else {\n\t\t\tresult = result.concat(spaces.concat([' ']));\n\t\t\tresult = result.concat(el.split(''));\n\t\t\tresult = result.concat(spaces);\n\t\t}\n\t\tleft = !left;\n\t\toutput.push(\"*\" + result.join('') + \"*\");\n\t}\n});\noutput.push(stars.join(''));\nprint(output.join('\\n'));\n"}, {"source_code": "var text = [];\nvar maxL = -Infinity;\n\ntry {\n while (true) {\n str = readline();\n maxL = Math.max(maxL, str.length);\n text.push(str);\n }\n}\ncatch(e){\n \n}\n\nfor (var i = -1; i <= maxL; i++) write('*')\nwrite('\\n');\nvar offset = 0;\nfor (var i = 0; i < text.length; i++) {\n \n write('*');\n var flag = (maxL - text[i].length) % 2;\n if (flag == 1) {\n var space = (maxL - text[i].length + offset) >> 1;\n offset = 1 - offset;\n } else {\n var space = (maxL - text[i].length) >> 1;\n }\n for (var j = 0; j < space; j++) write(' ');\n write(text[i]);\n for (var j = 0; j < maxL - space - text[i].length; j++) write(' ');\n write('*');\n write('\\n');\n}\nfor (var i = -1; i <= maxL; i++) write('*');"}, {"source_code": "\nvar line;\nvar max=0;\nvar lines=[];\nwhile( (line = readline() )!== undefined){\n\tif(line.length>max){\n\t\tmax = line.length;\n\t}\n\tlines.push(line);\n}\n\nprint( p('*', max+2) );\n\nvar f = true;\nfor(var i=0; i w) w = l.length\n}\n\nvar out = []\nvar sts = ''\nfor (var i = 0; i < w + 2; i++) {\n sts += '*'\n}\n\nout.push(sts)\n\nfor (var i = 0; i < ss.length; i++) {\n out.push('*' + cent(ss[i]) + '*')\n}\n\nout.push(sts)\n\nprint(out.join('\\n'))\n\nfunction cent (s) {\n var pl, pr\n if ((w - s.length) % 2 | 0) {\n lo = !lo\n }\n if (lo) {\n pl = Math.floor((w - s.length) / 2)\n pr = Math.ceil((w - s.length) / 2)\n } else {\n pr = Math.floor((w - s.length) / 2)\n pl = Math.ceil((w - s.length) / 2)\n }\n var ns = ''\n for (var i = 0; i < pl; i++) {\n ns += ' '\n }\n ns += s\n for (var i = 0; i < pr; i++) {\n ns += ' '\n }\n return ns\n}"}], "negative_code": [{"source_code": "var i, input, buffer = [], blockWidth = 0, frameChar = '*';\n\nfunction formatText(text){\n var lPad, rPad;\n lPad = ' '.repeat(Math.floor((blockWidth - text.length)/2));\n rPad = ' '.repeat(blockWidth - text.length - lPad.length);\n return frameChar + lPad + text + rPad + frameChar;\n}\n\nwhile (true){\n input = readline();\n if (typeof input === 'undefined') break;\n\n if (input.length > blockWidth) blockWidth = input.length;\n buffer.push(input);\n}\n\nprint(frameChar.repeat(blockWidth + 2));\n\nfor (i=0; imax){\n\t\tmax = line.length;\n\t}\n\tlines.push(line);\n}\n\nprint( p('*', max+2) );\n\nfor(var i=0; imax){\n\t\tmax = line.length;\n\t}\n\tlines.push(line);\n}\n\nprint( p('*', max+2) );\n\nfor(var i=0; imax){\n\t\tmax = line.length;\n\t}\n\tlines.push(line);\n}\n\nprint( p('*', max+2) );\n\nfor(var i=0; i parseInt( i, 10 );\nvar input = readline().split( \" \" ).map( toInt ),\n s = input[ 1 ],\n centsInDollar = 100,\n count = -1;\nwhile( input = readline() ) {\n input = input.split( \" \" ).map( toInt );\n var dollars = input[ 0 ],\n cents = input[ 1 ];\n if ( dollars + Math.ceil( cents / centsInDollar ) <= s ) {\n count = Math.max( (centsInDollar - cents) % centsInDollar, count );\n }\n}\nprint( count );"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], s = +input[1] * 100;\nvar max = 0, check = false;\n\nfor(var i = 0; i < n; i++){\n\tinput = readline().split(\" \").map(Number);\n\tinput = input[0] * 100 + input[1];\n\n\tif(s >= input){\n\t\tmax = Math.max(max, ((s - input) % 100));\n\t\tcheck = true;\n\t}\n}\n\nif(check){write(max)}\nelse{write(-1)}"}, {"source_code": " var vector = readline().split(' ').map(Number);\n var n = vector[0];\n var s = vector[1];\n var max = -1;\n for (var i = 0; i < n; i++)\n {\n var vector2 = readline().split(' ').map(Number);\n var dolar = vector2[0];\n var centavos = vector2[1];\n if (dolar + centavos / 100.0 <= s){\n max = Math.max(max, (100 - centavos) % 100);\n }\n }\n print(max);"}, {"source_code": " var vector = readline().split(' ').map(Number);\n var n = vector[0];\n var s = vector[1];\n var max = -1;\n for (var i = 0; i < n; i++)\n {\n var vector2 = readline().split(' ').map(Number);\n var dolar = vector2[0];\n var centavos = vector2[1];\n if (dolar + centavos / 100.0 <= s)\n max = Math.max(max, (100 - centavos) % 100);\n }\n print(max);"}, {"source_code": ";(function () {\n var n, s, l, ans = -1;\n l = readline().split(' ').map(Number);\n n = l[0];\n s = l[1] * 100;\n\n while (n--) {\n var q, w;\n l = readline().split(' ').map(Number);\n q = l[0] * 100 + l[1];\n w = (100 - l[1]) % 100;\n\n if (s >= q) {\n ans = Math.max(ans, w);\n }\n }\n\n print(ans);\n\n}.call(this));\n"}], "negative_code": [{"source_code": "var input = readline().split(\" \"), n = +input[0], s = +input[1] * 100;\nvar max = 0;\n\nfor(var i = 0; i < n; i++){\n\tinput = readline().split(\" \").map(Number);\n\tinput = input[0] * 100 + input[1];\n\n\tif(s >= input){\n\t\tmax = Math.max(max, ((s - input) % 100));\n\t}\n}\n\nwrite(max);"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s || e === 0) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t || 0].concat(k.length ? k : [0]));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\t\t\tk.splice(0, 1);\n\n\t\t\tif (k.slice(-1) > s) {\n\t\t\t\tk.splice(-1);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\te = 100 - +e.toString().slice(-2);\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tvar k = l;\n\t\t\twhile (k <= s) {\n\t\t\t\tvar r = 100 - (k % 100);\n\t\t\t\tr = r === 100 ? 0 : r;\n\t\t\t\tt = (t === null || t < r) ? r : t;\n\t\t\t\tk += l;\n\t\t\t}\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\t\t\tk.splice(-1); k.splice(0, 1);\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\te = 100 - +e.toString().slice(-2);\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l, q = [];\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tvar k = l;\n\t\t\twhile (k <= s) {\n\t\t\t\tvar r = 100 - (k % 100);\n\t\t\t\tr = r === 100 ? 0 : r;\n\t\t\t\tt = (t === null || t < r) ? r : t;\n\t\t\t\tk += l;\n\n\t\t\t\tif (t === 99) q.push(l);\n\t\t\t}\n\t\t}\n\n\t\tif (t === 99) return q;\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s || e === 0) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\tvar r = 0;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t\tif (t === 99) r = l;\n\t\t}\n\t\tif (t === 99) return r;\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\t\t\tif ((l%100) === 0) {\n\t\t\t\tt = Math.max.apply(null, [t || 0].concat(0));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s || e === 0) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t || 0].concat(k.length ? k : [0]));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l, q = [];\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tvar k = l;\n\t\t\twhile (k <= s) {\n\t\t\t\tvar r = 100 - (k % 100);\n\t\t\t\tr = r === 100 ? 0 : r;\n\t\t\t\tt = (t === null || t < r) ? r : t;\n\t\t\t\tk += l;\n\n\t\t\t\tif (t === 99 && q.indexOf(l) === -1) q.push(l);\n\t\t\t}\n\t\t}\n\n\t\tif (t === 99) return q;\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": ";(function () {\n\tprint(function () {\n\t\tvar n, s, l;\n\t\tl = readline().split(' ').map(Number);\n\t\tn = l[0];\n\t\ts = l[1] * 100;\n\n\t\tvar t = null;\n\t\twhile (n--) {\n\t\t\tl = readline().split(' ').map(Number);\n\t\t\tl = l[0] * 100 + l[1];\n\n\t\t\tif (l > s) continue;\n\t\t\tif ((l % 100) === 0) return 0;\n\n\t\t\tvar k = [0];\n\t\t\twhile (k.slice(-1)[0] <= s) {\n\t\t\t\tk.push(k.slice(-1)[0] + l);\n\t\t\t}\n\n\t\t\tk = k.map(function (e) {\n\t\t\t\tif (e > s) return 0;\n\t\t\t\te = 100 - parseInt(e.toString().slice(-2));\n\t\t\t\treturn e !== 100 ? e : 0;\n\t\t\t});\n\n\t\t\tt = Math.max.apply(null, [t].concat(k));\n\t\t}\n\n\t\treturn t === null ? -1 : t;\n\t}());\n}.call(this));\n"}, {"source_code": "\n// 463A Caisa \u0438 \u0441\u0430\u0445\u0430\u0440 \n\n// var n = parseInt(readline());\n\nvar input_line = readline().split(' ').map(Number);\n\nvar n = input_line[0];\nvar s = input_line[1];\nvar arr = [];\n\nvar count;\nvar flagBuy = false;\nvar max = 0;\n\nfor (var i = 0; i < n; i++) {\n arr = readline().split(' ').map(Number);\n\n if (((arr[0] * 100) + arr[1]) <= (s * 100)) {\n flagBuy = true;\n if (max < arr[1]) max = arr[1];\n };\n};\n\nif (flagBuy) {\n count = max;\n} else {\n count = -1;\n};\n\nprint(count);\n"}, {"source_code": "var toInt = i => parseInt( i, 10 );\nvar input = readline().split( \" \" ).map( toInt ),\n s = input[ 1 ],\n count = -1;\nwhile( input = readline() ) {\n input = input.split( \" \" ).map( toInt );\n var dollars = input[ 0 ],\n cents = input[ 1 ];\n if ( dollars < s && cents > 0 ) {\n count = Math.max( 100 - cents, count );\n }\n}\nprint( count );"}], "src_uid": "91be5db48b44a44adff4c809ffbb8e3e"} {"source_code": "/* KEEP BELOW CODE AS IT IS */\r\n// copy-pasted from: https://codeforces.com/blog/entry/78878?f0a28=1\r\n/**\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n * I am not the owner of the readLine function below, understanding them require knowledge of basic NodeJS I/O and streams\r\n */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction nextLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction nextInt() {\r\n return parseInt(nextLine());\r\n}\r\n\r\nfunction nextFloat() {\r\n return parseFloat(nextLine());\r\n}\r\n\r\n\r\n/** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION */\r\nfunction main() {\r\n\r\n function solve(words, set, additional) {\r\n for (const word of words) {\r\n const len = word.length;\r\n const reversed = word.split(\"\").reverse().join(\"\")\r\n if (word[0] === word[len - 1] || set[reversed] !== undefined) {\r\n return \"YES\";\r\n }\r\n set[word] = true;\r\n if (len === 2) {\r\n if (additional[reversed] !== undefined) {\r\n return \"YES\";\r\n }\r\n continue;\r\n }\r\n\r\n const last = reversed.substring(0, 2)\r\n if (set[last] !== undefined) {\r\n return \"YES\";\r\n }\r\n additional[word.substring(0, 2)] = true;\r\n }\r\n return \"NO\";\r\n }\r\n\r\n let amount = nextInt();\r\n\r\n while (amount--) {\r\n const wordAmount = nextInt();\r\n const words = [];\r\n for (let i = 0; i < wordAmount; i++) {\r\n words.push(nextLine());\r\n }\r\n console.log(solve(words, {}, {}));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let set2 = new Set();\r\n let set3 = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n\r\n if (scene.length === 2 && (set2.has([...scene].reverse().join('')))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n\r\n if (scene.length === 3\r\n && (set3.has([...scene.slice(1)].reverse().join(''))\r\n || set3.has([...scene].reverse().join('')))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n\r\n if (scene.length === 2) {\r\n set2.add(scene);\r\n set3.add(scene);\r\n }\r\n\r\n if (scene.length === 3) {\r\n set3.add(scene);\r\n set2.add(scene.slice(0, scene.length - 1))\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet counter = 0;\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"uev\") {\r\n print = true;\r\n }\r\n if (print) {\r\n process.stdout.write(line + \" \");\r\n counter++;\r\n if (counter === 10) {\r\n process.stdout.write(\"\\n\");\r\n counter = 0;\r\n }\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet counter = 0;\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"iyq\") {\r\n print = true;\r\n }\r\n if (print) {\r\n process.stdout.write(line + \" \");\r\n counter++;\r\n if (counter === 10) {\r\n process.stdout.write(\"\\n\");\r\n counter = 0;\r\n }\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet counter = 0;\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n\r\n if (Number(line.trim()) && print) {\r\n printTrue = true;\r\n }\r\n if (line.trim() === \"1\") {\r\n print = true;\r\n }\r\n if (printTrue) {\r\n process.stdout.write(line + \" \");\r\n counter++;\r\n if (counter === 10) {\r\n process.stdout.write(\"\\n\");\r\n counter = 0;\r\n }\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet counter = 0;\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n\r\n if (Number(line.trim()) && print) {\r\n printTrue = true;\r\n }\r\n if (line.trim() === \"118\") {\r\n print = true;\r\n }\r\n if (printTrue) {\r\n process.stdout.write(line + \" \");\r\n counter++;\r\n if (counter === 10) {\r\n process.stdout.write(\"\\n\");\r\n counter = 0;\r\n }\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n\r\n if (Number(line.trim()) && print) {\r\n printTrue = true;\r\n }\r\n if (line.trim() === \"118\") {\r\n print = true;\r\n }\r\n if (printTrue) {\r\n process.stdout.write(line + \" \");\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n\r\n if (Number(line.trim()) && print) {\r\n printTrue = true;\r\n }\r\n if (line.trim() === \"230\") {\r\n print = true;\r\n }\r\n if (printTrue) {\r\n process.stdout.write(line + \"\\n\");\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet print = false;\r\nlet printTrue = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n\r\n\r\n if (Number(line.trim()) && print) {\r\n printTrue = true;\r\n }\r\n if (line.trim() === \"100\") {\r\n print = true;\r\n }\r\n if (printTrue) {\r\n process.stdout.write(line + \"\\n\");\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet print = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"100\") {\r\n print = true;\r\n }\r\n if (print) {\r\n process.stdout.write(line + \"\\n\");\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nlet print = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"100\") {\r\n print = true;\r\n }\r\n if (print) {\r\n process.stdout.write(line);\r\n }\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nconst print = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"100\")\r\n process.stdout.write(line);\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nconst print = false;\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n if (line.trim() === \"100\\n\")\r\n process.stdout.write(line);\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || scene.length > 2 && duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]\r\n || duplicates.has([...scene].reverse().join(''))\r\n || duplicates.has([...scene.slice(1)].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(0, scene.length - 1));\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nconst lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line.trim());\r\n}).on('close', () => {\r\n const t = Number(lines[0]);\r\n let prevN = 1;\r\n\r\n for (let i = 0; i < t; i++) {\r\n let wasInterrupted = false;\r\n const n = Number(lines[i + prevN]);\r\n let duplicates = new Set();\r\n for (let j = 0; j < n; j++) {\r\n const scene = lines[j + prevN + i + 1]\r\n if (scene[0] === scene[scene.length - 1]) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n duplicates.add(scene);\r\n if (scene.length > 2) {\r\n duplicates.add(scene.slice(1));\r\n }\r\n }\r\n if (!wasInterrupted) {\r\n for (let scene of duplicates.values()) {\r\n if (duplicates.has([...scene].reverse().join(''))) {\r\n wasInterrupted = true;\r\n break;\r\n }\r\n }\r\n }\r\n prevN += n;\r\n if (wasInterrupted) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n }\r\n});"}], "src_uid": "6d5aefc5a08194e35826764d60c8db3c"} {"source_code": "var inpStr = readline();\ninpStr = inpStr.substr(5);\nvar suffixes = [], visited = [];\nfunction getSuffixes(str, lastSuffix){\n if(str.length < 2 || (visited[str.length] && visited[str.length][lastSuffix])){\n return;\n }\n if(!visited[str.length]){\n visited[str.length] = [];\n }\n visited[str.length][lastSuffix] = true;\n if(str.length === 2){\n if(lastSuffix !== str){\n if(suffixes.indexOf(str) === -1){\n suffixes.push(str);\n }\n }\n return;\n } else {\n var strLen2 = str.substr(-2);\n if(lastSuffix !== strLen2){\n if(suffixes.indexOf(strLen2) === -1){\n suffixes.push(strLen2);\n }\n getSuffixes(str.substring(0, str.length-2), strLen2);\n }\n \n var strLen3 = str.substr(-3);\n if(lastSuffix !== strLen3){\n if(suffixes.indexOf(strLen3) === -1){\n suffixes.push(strLen3);\n }\n getSuffixes(str.substring(0, str.length-3), strLen3);\n }\n }\n}\ngetSuffixes(inpStr, \"\");\nprint(suffixes.length);\nsuffixes.sort().forEach(function(suffix){\n print(suffix);\n})", "positive_code": [{"source_code": "const memo = {};\nconst res = {};\n\nfunction resolve(s, prev) {\n if (!memo[s + ' ' + prev]) {\n memo[s + ' ' + prev] = true;\n var suffix2 = s.slice(s.length - 2);\n if (suffix2 !== prev && s.length > 6) {\n res[suffix2] = true;\n resolve(s.slice(0, s.length - 2), suffix2);\n }\n var suffix3 = s.slice(s.length - 3);\n if (suffix3 !== prev && s.length > 7) {\n res[suffix3] = true;\n resolve(s.slice(0, s.length - 3), suffix3);\n }\n }\n}\n\n/*\nresolve('abcdeabzzzzzzzz', null);\nconsole.log(res);\n*/\n\nvar s = readline();\n\nresolve(s, null);\n\nvar suffixes = Object.keys(res).sort();\n\nprint(suffixes.length);\n\nfor (var i = 0; i < suffixes.length; i++) {\n print(suffixes[i]);\n}\n"}], "negative_code": [{"source_code": "const memo = {};\nconst res = {};\n\nfunction resolve(s, prev) {\n if (!memo[s]) {\n memo[s] = true;\n var suffix2 = s.slice(s.length - 2);\n if (suffix2 !== prev && s.length > 6) {\n res[suffix2] = true;\n resolve(s.slice(0, s.length - 2), suffix2);\n }\n var suffix3 = s.slice(s.length - 3);\n if (suffix3 !== prev && s.length > 7) {\n res[suffix3] = true;\n resolve(s.slice(0, s.length - 3), suffix3);\n }\n }\n}\n\nvar s = readline();\n\nresolve(s, null);\n\nvar suffixes = Object.keys(res).sort();\n\nprint(suffixes.length + '\\n');\n\nfor (var i = 0; i < suffixes.length; i++) {\n print(suffixes[i]);\n}\n"}, {"source_code": "var inpStr = readline();\ninpStr = inpStr.substr(5);\nvar suffixes = [];\nfunction getSuffixes(str){\n if(str.length < 2){\n return;\n } else if(str.length === 2){\n if(suffixes.indexOf(str) === -1){\n suffixes.push(str);\n }\n return;\n } else {\n var strLen2 = str.substr(-2);\n if(suffixes.indexOf(strLen2) === -1){\n suffixes.push(strLen2);\n }\n getSuffixes(str.substring(0, str.length-2));\n \n var strLen3 = str.substr(-3);\n if(suffixes.indexOf(strLen3) === -1){\n suffixes.push(strLen3);\n }\n getSuffixes(str.substring(0, str.length-3));\n }\n}\ngetSuffixes(inpStr);\nprint(suffixes.length)\nsuffixes.sort().forEach(function(suffix){\n print(suffix);\n})\n"}, {"source_code": "var inpStr = readline();\ninpStr = inpStr.substr(5);\nvar suffixes = [], visited = [];\nfunction getSuffixes(str, lastSuffix){\n if(str.length < 2 || visited[str.length]){\n return;\n }\n visited[str.length] = true;\n if(str.length === 2){\n if(lastSuffix !== str){\n if(suffixes.indexOf(str) === -1){\n suffixes.push(str);\n }\n }\n return;\n } else {\n var strLen2 = str.substr(-2);\n if(lastSuffix !== strLen2){\n if(suffixes.indexOf(strLen2) === -1){\n suffixes.push(strLen2);\n }\n getSuffixes(str.substring(0, str.length-2), strLen2);\n }\n \n var strLen3 = str.substr(-3);\n if(lastSuffix !== strLen3){\n if(suffixes.indexOf(strLen3) === -1){\n suffixes.push(strLen3);\n }\n getSuffixes(str.substring(0, str.length-3), strLen3);\n }\n }\n}\ngetSuffixes(inpStr, \"\");\nprint(suffixes.length);\nsuffixes.sort().forEach(function(suffix){\n print(suffix);\n})"}], "src_uid": "dd7ccfee8c2a19bf47d65d5a62ac0071"} {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var j = parseInt(readline());\n var x4 = true;\n for (var _ = 0; _ < j; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nlet inputs = [];\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n});\n \nrl.on('close', () => {\n\tconst test = parseInt(inputs[0]);\n\tlet n = [];\n\tfor (let t = 0; t < test; t++) {\n\t\tn = inputs[t+1].split(' ').map((a) => {return parseInt(a)});\n \tconsole.log(solution(n));\n\t}\n});\n\nfunction solution(n) {\n\tlet i = 0, j = 0, k = 0;\n\tlet a = n[0], b = n[1], c = n[2], d = n[3];\n\treturn `${b} ${c} ${c}`\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n var b = parseInt(line.split(\" \")[1]);\n var c = parseInt(line.split(\" \")[2]);\n var d = parseInt(line.split(\" \")[3]);\n\n solve(a, b, c, d);\n }\n}\n\nfunction solve(a, b, c, d) {\n console.log (b + \" \" + c + \" \" + c);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const [a, b, c, d] = data.split(' ').map(Number);\n console.log(b, c, c);\n\n count++;\n});\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n let l = arr[0];\n arr = arr.slice(1);\n arr = arr.map(el => +el);\n for (let z = 0; z < l; z ++){\n a = arr[0];\n c = arr[2];\n console.log(`${a} ${c} ${c}`)\n arr = arr.slice(4);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n var x2 = true;\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n var x4 = true;\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n var x3 = true;\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n var x = true;\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n var x5 = true;\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(' ').map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1], c = _a[2], d = _a[3];\n print(b, c, c);\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n console.log(b, c, c)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n var firstSet = inputs[0];\n var secondSet = inputs[1];\n var thirdSet = inputs[2];\n var fourthSet = inputs[3];\n \n var oneSide = 1;\n var secondSide = 1;\n var thirdSide = 1;\n \n oneSide = Math.min(firstSet, secondSet);\n secondSide = Math.max(secondSet, thirdSet);\n thirdSide = Math.min(thirdSet, fourthSet);\n \n while(oneSide <= secondSide && secondSide <= thirdSide) {\n if(oneSide + secondSide > thirdSide && thirdSide + oneSide > secondSide && secondSide + thirdSide > oneSide) {\n print(oneSide, secondSide, thirdSide);\n break;\n } else {\n oneSide++;\n secondSide--;\n thirdSide++;\n }\n }\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n\n for (let index = 1; index <= t; index++) {\n const element = strToNumArr(inputs[index].trim().split(' '));\n let str = '';\n for (let index2 = 1; index2 <= element.length; index2++) {\n if (index2 - 1 == 2) {\n str += element[index2 - 1] + ' ';\n }\n else if (element[index2 - 1] <= element[index2]) {\n str += element[index2] + ' ';\n }\n }\n console.log(str.trim());\n }\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction checkValidity(a, b, c) {\n if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {\n return false;\n } else {\n return true;\n }\n}\n \n\nfunction main() {\n let X = parseInt(readline());\n for (var cases = 0; cases < X; cases++) {\n const [a,b,c,d] = readline().split(\" \").map(e => parseInt(e));\n\n //console.log(a,b,c,d);\n //console.log(checkValidity(b,c, c));\n console.log(b,c,c);\n\n //console.log(c-b);\n }\n}\n"}, {"source_code": "var testcase=parseInt(readline());\nwhile(testcase--){\n var x=readline().split(' ').map(x=>parseInt(x));\n var a=x[0];\n var b=x[1];\n var c=x[2];\n print(b,c,c);\n}"}, {"source_code": "for(var t=Number(readline());t;t--){\n var a = readline().trim().split(/\\s/).map(x=>Number(x));\n print(\"\" + a[1] + \" \" + a[2] + \" \" + a[2]);\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar tmp = nextIntArray();\n\t\tvar a = tmp[0];\n\t\tvar b = tmp[1];\n\t\tvar c = tmp[2];\n\t\tvar d = tmp[3];\n\t\tvar center = Math.floor((b + c) / 2);\n\t\toutput[i] = b + \" \" + c + \" \" + c;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n var a = input1[0]\n var b = input1[1]\n var c = input1[2]\n print(a, c, c)\n}"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const cases = readline();\n var i;\n for (i = 0; i < cases; i++) {\n const line = readline();\n var a = parseInt(line.split(\" \")[0]);\n var b = parseInt(line.split(\" \")[1]);\n var c = parseInt(line.split(\" \")[2]);\n var d = parseInt(line.split(\" \")[3]);\n\n solve(a, b, c, d);\n }\n}\n\nfunction solve(a, b, c, d) {\n console.log (b + \" \" + c + \" \" + d);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ');\n arr.pop();\n console.log(arr.join(' '));\n\n c++;\n});\n"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n let l = arr[0];\n arr = arr.slice(1);\n arr = arr.map(el => +el);\n for (let z = 0; z < l; z ++){\n a = arr[0];\n d = arr[3];\n console.log(`${a} ${d} ${d}`)\n arr = arr.slice(4);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n console.log(b, c, d)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n\n for (let index = 1; index <= t; index++) {\n const element = strToNumArr(inputs[index].trim().split(' '));\n let str = '';\n for (let index2 = 1; index2 <= element.length; index2++) {\n\n if (element[index2 - 1] <= element[index2]) {\n str += element[index2 - 1] + ' ';\n }\n }\n console.log(str.trim());\n }\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n\n for (let index = 1; index <= t; index++) {\n const element = strToNumArr(inputs[index].trim().split(' '));\n let str = '';\n for (let index2 = 1; index2 <= element.length; index2++) {\n if (element[index2 - 1] <= element[index2]) {\n str += element[index2] + ' ';\n }\n }\n console.log(str.trim());\n }\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n input1.sort((x, y) => x - y)\n input1.splice(0, 1)\n print(input1.join(\" \"))\n}"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n var input1 = readline().split(' ').map(x => parseInt(x));\n var a = input1[0]\n var b = input1[1]\n var c = input1[2]\n print(a, b, c)\n}"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n var firstSet = inputs[0];\n var secondSet = inputs[1];\n var thirdSet = inputs[2];\n var fourthSet = inputs[3];\n var secondSide = inputs[1];\n \n var oneSide = Math.floor((secondSet + thirdSet) / 2);\n if(oneSide < secondSet) {\n secondSide = Math.floor((firstSet + oneSide) / 2);\n }\n var thirdSide = Math.floor((secondSide + fourthSet) / 2);\n \n while(oneSide + secondSide < thirdSide) {\n secondSide ++;\n oneSide++;\n }\n \n while(thirdSide + secondSide < oneSide) {\n thirdSide ++;\n secondSide++;\n }\n \n print(secondSide, oneSide, thirdSide);\n\n}"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n var firstSet = inputs[0];\n var secondSet = inputs[1];\n var thirdSet = inputs[2];\n var fourthSet = inputs[3];\n \n var secondSide = inputs[1];\n \n var oneSide = Math.floor((secondSet + thirdSet) / 2);\n if(oneSide < secondSet) {\n secondSide = Math.floor((firstSet + oneSide) / 2);\n }\n var thirdSide = Math.floor((secondSide + fourthSet) / 2);\n \n while(oneSide + secondSide < thirdSide) {\n secondSide ++;\n oneSide++;\n }\n \n while(thirdSide + secondSide < oneSide) {\n thirdSide ++;\n secondSide++;\n }\n \n if(fourthSet === thirdSet) {\n thirdSide = thirdSet;\n }\n \n if(secondSet === thirdSet) {\n oneSide = thirdSet;\n }\n \n if(firstSet === secondSet) {\n secondSide = firstSet;\n }\n \n print(secondSide, oneSide, thirdSide);\n\n}"}], "src_uid": "821d48c9a67d37ad7acc50d4d0d0d723"} {"source_code": "parameters = readline().split(\" \").map(Number)\nlines = []\n\nxStart = parameters[1] - 1\nxEnd = 0\n\nyStart = parameters[0] - 1\nyEnd = 0\n\nfor (row = 0; row < parameters[0]; row++) {\n lines[row] = readline()\n for (col = 0; col < parameters[1]; col++) {\n if (lines[row][col] == \"*\") {\n if (col < xStart) xStart = col\n if (col > xEnd) xEnd = col\n if (row < yStart) yStart = row\n if (row > yEnd) yEnd = row\n }\n }\n}\n\nfor (row = yStart; row < yEnd + 1; row++) {\n ans = ''\n for (col = xStart; col < xEnd + 1; col++) {\n ans += lines[row][col]\n }\n print(ans)\n}", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar top = -1, bottom, left = 50, right = 0, rows, collumns, indicator = 0, cont = [], ri = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n let temp = input.split(' ').map(item => parseInt(item));\n rows = temp[0];\n collumns = temp[1];\n indicator++;\n }\n else {\n let fIndex = input.indexOf('*');\n if (fIndex != -1) {\n if (top == -1)\n top = ri;\n if (left > fIndex)\n left = fIndex;\n let lIndex = input.lastIndexOf('*');\n if (right < lIndex)\n right = lIndex;\n bottom = ri;\n\n }\n /** */\n // console.log(\"inside else input = %s \",input);\n /** */\n cont.push(input);\n\n ri++;// increase row index\n }\n}).on('close', () => {\n //\n //console.log(\"top = %d bottom = %d left = %d right = %d\",top,bottom,left,right);\n //\n for (let i = top; i <= bottom; i++)\n console.log(cont[i].substring(left, right + 1));\n //console.log(cont[i]);\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst arr = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n arr.push(d.split(''));\n\n c++;\n});\n\nrl.on('close', () => {\n let minX = Infinity;\n let maxX = -Infinity;\n let minY = Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n if (arr[i][j] === '*') {\n minX = Math.min(minX, j);\n maxX = Math.max(maxX, j);\n minY = Math.min(minY, i);\n maxY = Math.max(maxY, i);\n }\n }\n }\n\n let ans = '';\n\n for (let i = minY; i <= maxY; i++) {\n for (let j = minX; j <= maxX; j++) {\n ans += arr[i][j];\n }\n\n ans += '\\n';\n }\n\n console.log(ans);\n});\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar array = [];\nvar n = -1;\nvar left = 50;\nvar top = 50;\nvar right = 0;\nvar down = 0;\nvar check = true;\nrl.on(\"line\", input => {\n if (n == -1) {\n n++;\n } else {\n array.push(input);\n\n for (var i = 0; i < input.length; i++) {\n if (input[i] == \"*\") {\n if (check) {\n top = n;\n check = false;\n }\n if (i < left) {\n left = i;\n }\n\n if (i > right) {\n right = i;\n }\n down = n;\n }\n }\n n++;\n }\n}).on(\"close\", () => {\n for (var i = top; i <= down; i++) {\n console.log(array[i].substr(left, right - left + 1));\n }\n});\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1];\n\n\tvar grid = [];\n\tvar rowDirty = new Array(rowNum), colDirty = new Array(colNum);\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tgrid.push(trim(readline()));\n\t\tfor (var c = 0; c < colNum; c += 1) {\n\t\t\tif (grid[r][c] == '*') {\n\t\t\t\trowDirty[r] = true;\n\t\t\t\tcolDirty[c] = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tvar rStart = 0, rEnd = rowNum-1;\n\twhile (rowDirty[rStart] !== true) {\n\t\trStart += 1;\n\t}\n\twhile (rowDirty[rEnd] !== true) {\n\t\trEnd -= 1;\n\t}\n\n\tvar cStart = 0, cEnd = colNum-1;\n\twhile (colDirty[cStart] !== true) {\n\t\tcStart += 1;\n\t}\n\twhile (colDirty[cEnd] !== true) {\n\t\tcEnd -= 1;\n\t}\n\n\tfor (var r = rStart; r <= rEnd; r += 1) {\n\t\tprint(grid[r].substring(cStart, cEnd+1));\n\t}\n\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar rowNum = integers[0], colNum = integers[1];\n\n\tvar rStart = rowNum-1, rEnd = 0;\n\tvar cStart = colNum-1, cEnd = 0;\n\tvar grid = [];\n\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tgrid.push(trim(readline()));\n\t\tfor (var c = 0; c < colNum; c += 1) {\n\t\t\tif (grid[r][c] == '*') {\n\t\t\t\tif (r < rStart) {\n\t\t\t\t\trStart = r;\n\t\t\t\t}\n\t\t\t\tif (r > rEnd) {\n\t\t\t\t\trEnd = r;\n\t\t\t\t}\n\t\t\t\tif (c < cStart) {\n\t\t\t\t\tcStart = c;\n\t\t\t\t}\n\t\t\t\tif (c > cEnd) {\n\t\t\t\t\tcEnd = c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var r = rStart; r <= rEnd; r += 1) {\n\t\tprint(grid[r].substring(cStart, cEnd+1));\n\t}\n\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet lll = readline().split(' ')\nconst N = lll[0]\nconst M = lll[1]\n\nlet l = 0\nlet r = 0\nlet t = 0\nlet b = 0\n\nlet pct = []\n\nwhile (lll = readline()) pct.push(lll.split(''))\n\nwhile (t < N && !~pct[t].indexOf('*')) t++\nwhile (b < N - t && !~pct[N - b - 1].indexOf('*')) b++\nwhile (l < M && !~pct.map(ln => ln[l]).indexOf('*')) l++\nwhile (r < M - l && !~pct.map(l => l[M - r - 1]).indexOf('*')) r++\n\nprint(pct.slice(t, N - b).map(ln => ln.slice(l, M - r)).map(l => l.join('')).join('\\n'))"}, {"source_code": "var data = readline().split(' ').map(item => parseInt(item));\nvar n = data[0], m = data[1];\ndata = [];\nfor(var i = 0; i < n; i++) {\n data.push(readline());\n}\nvar m1, m2, n1, n2;\nfor(var i = 0; i < n; i++) {\n for(var j = 0; j < m; j++) {\n if(data[i][j] === '*') {\n n1 = i;\n break;\n }\n }\n if(n1 != undefined) {\n break;\n }\n}\nfor(var i = n - 1; i >= 0; i--) {\n for(var j = 0; j < m; j++) {\n if(data[i][j] === '*') {\n n2 = i;\n break;\n }\n }\n if(n2 != undefined) {\n break;\n }\n}\nfor(var i = 0; i < m; i++) {\n for(var j = 0; j < n; j++) {\n if(data[j][i] === '*') {\n m1 = i;\n break;\n }\n }\n if(m1 != undefined) {\n break;\n }\n}\nfor(var i = m - 1; i >= 0; i--) {\n for(var j = 0; j < n; j++) {\n if(data[j][i] === '*') {\n m2 = i;\n break;\n }\n }\n if(m2 != undefined) {\n break;\n }\n}\nfor(var i = n1; i <= n2; i++) {\n print(data[i].substr(m1, m2 - m1 + 1));\n}"}, {"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0];\nvar m = nm[1];\nvar l = [];\nvar x1 = m-1;\nvar x2 = 0;\nvar y1 = n-1;\nvar y2 = 0;\nfor (var i=0; i x2) x2 = j;\n\t\t\tif (i < y1) y1 = i;\n\t\t\tif (i > y2) y2 = i;\n\t\t};\n\t}\n}\nfor (var i=y1; i<=y2; i++){\n\tvar ans = '';\n\tfor (var j=x1; j<=x2; j++){\n\t\tans += l[i][j];\n\t}\n\tprint(ans);\n}"}], "negative_code": [], "src_uid": "d715095ff068f4d081b58fbfe103a02c"} {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar dt = Math.max(j[0],j[1],j[2])*3 - j[0]-j[1]-j[2];\n\tif(j[3]>=dt){\n\t j[3] -= dt;\n\t if(j[3]%3 > 0 || j[3]%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}", "positive_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\nfunction asArrayNumber(testCase) {\n return testCase.split(' ').map((x) => {\n return parseInt(x, 10);\n });\n}\nfunction findGreatest(sisters) {\n return Math.max(...sisters);\n}\nfunction calculateDifference(greatest, sisters) {\n let difference = 0;\n for (let i = 0; i < sisters.length; i++) {\n difference = greatest - sisters[i] + difference;\n }\n return difference;\n}\nfunction solve(lines) {\n const testCases = lines.slice(1);\n for (let i = 0; i < testCases.length; i++) {\n const numbers = asArrayNumber(testCases[i]);\n const sisters = [numbers[0], numbers[1], numbers[2]];\n const n = numbers[3];\n const greatest = findGreatest(sisters);\n const difference = calculateDifference(greatest, sisters);\n const remainder = n - difference;\n if (remainder >= 0 && remainder % 3 === 0) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n}\nfunction main() {\n const stdinBuffer = fs_1.default.readFileSync(0);\n const lines = stdinBuffer\n .toString()\n .split('\\n')\n .filter((x) => x !== '');\n solve(lines);\n}\nmain();\n"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n\tvar A = readline().split(' ').map(Number);\n\tvar n = A.pop();\n\n\tA.sort((a,b)=> {return a-b;});\n\t\n\tvar need = A[2]-A[0] + A[2]-A[1];\n\tif(need > n) print('NO');\n\telse {\n\t\tn -= need;\n\t\tif(n%3==0) print('YES');\n\t\telse print('NO');\n\t}\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let i = 0\n const t = readInt(input, i++)\n\n for(let j = 0; j < t; j++) {\n const as = readInts(input, i++)\n let n = as[3]\n const ax = [as[0], as[1], as[2]]\n sort(ax)\n\n n -= ax[2] - ax[1]\n n -= ax[2] - ax[0]\n if(n < 0 || n % 3 !== 0) wr('NO')\n else wr('YES')\n\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let coins = arr.pop();\n const max = Math.max(...arr);\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < max) {\n coins -= (max - arr[i]);\n }\n }\n\n if (coins < 0) {\n console.log('NO');\n }\n else if (coins % 3 !== 0) {\n console.log('NO');\n }\n else {\n console.log('YES');\n }\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\n\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n})\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(a, b, c, n) {\n const sum = a + b + c + n;\n if (sum % 3 !== 0) {\n return false;\n }\n const result = sum / 3;\n return (a <= result && b <= result && c <= result);\n}\n\nfunction main() {\n const t = parseInt(readline());\n for(let i = 0; i < t; i++) {\n const [a, b, c, n] = readline().split(' ').map(Number);\n const res = solve(a, b, c, n);\n console.log(res ? 'YES': 'NO');\n }\n}"}, {"source_code": "'use strict'\n\nconst problem = (a, b, c, n) => (x => (x < 0 || x % 3) ? 'NO' : 'YES')(a + b + c + n - 3 * Math.max(a, b, c));\nlet q = +readline();\nwhile(q--) print(problem(...readline().split(' ').map(Number)))\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var abcd = readline().split(' ').map(Number);\n var a = abcd[0];\n var b = abcd[1];\n var c = abcd[2];\n var d = abcd[3];\n var max = Math.max(a, b, c);\n var dif = max * 3 - a - b - c;\n var res = (d - dif >= 0) && (d - dif) % 3 === 0\n print(res ? 'YES' : 'NO')\n }\n}\n\nmain()"}, {"source_code": "function main(input) {\n var arr = input.split(\"\\n\");\n var t = arr[0]\n for(var i = 0; i < t; i++) {\n \n var s = arr[i + 1].split(\" \")\n a = parseInt(s[0])\n b = parseInt(s[1])\n c = parseInt(s[2])\n n = parseInt(s[3])\n \n f = Math.max(a, Math.max(b, c))\n d = (f - a) + (f - b) + (f - c)\n \n if (n < d) {\n process.stdout.write(\"NO\\n\")\n continue; \n } else {\n n -= d;\n if ((n % 3) === 0) {\n process.stdout.write(\"YES\\n\")\n continue;\n } else {\n process.stdout.write(\"NO\\n\")\n }\n }\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});"}, {"source_code": "'use strict';\nvar t = readline();\nwhile(t--) {\n var a = readline().split(\" \").map(function(num) {\n return parseInt(num);\n });\n var sum = a.reduce(function(total, num) {\n return total + num;\n }, 0);\n if(sum % 3) {\n print(\"NO\");\n } else {\n var x = sum / 3;\n if(x-a[0] >=0 && x-a[1] >=0 && x-a[2] >= 0) {\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n \n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var inp = readline().split(' ');\n var n = parseInt(inp.pop(), 10);\n \n for(var j=0; j<3; j++) {\n inp[j] = parseInt(inp[j], 10);\n }\n \n inp.sort((a,b) => b-a);\n \n if((inp[0] - inp[1]) + (inp[0] - inp[2]) > n) {\n print('NO');\n } else if((inp[0] - inp[1]) + (inp[0] - inp[2]) === n) {\n print('YES');\n } else {\n n -= (inp[0] - inp[1]) + (inp[0] - inp[2]);\n \n if(n%3 === 0) print('YES');\n else print('NO');\n }\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n for (let index = 1; index <= t; index++) {\n const element = inputs[index].trim().split(' ');\n let n = element[3];\n let coins = strToNumArr(element.slice(0, 3).sort((a, b) => b - a));\n n -= ((2 * coins[0]) - coins[1] - coins[2]);\n if (n < 0 || n % 3 != 0) {\n console.log('NO');\n } else {\n console.log('YES');\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nlet inputString = '', currentLine = 0, inputLine = [];\n\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => { inputLine.push(line); });\nrl.on('close', () =>{ main(inputLine); } );\n \nfunction readALine() { return inputLine[currentLine++]; }\nfunction printALine(str) { console.log(str); }\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver < 0 ) return \"NO\";\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar dt = Math.max(j[0],j[1],j[2])*3 - j[0]-j[1]-j[2];\n\tj[3] -= dt;\n\tif(j[3]%3 === 0 && j[3] >= 0){\n print('YES');\n }else{\n \t print('NO');\n }\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (a, b, c, n) => (a + b + c + n - 3 * Math.max(a, b, c)) % 3 ? 'NO' : 'YES';\nlet q = +readline();\nwhile(q--) print(problem(...readline().split(' ').map(Number)))\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var abcd = readline().split(' ').map(Number);\n var a = abcd[0];\n var b = abcd[1];\n var c = abcd[2];\n var d = abcd[3];\n var ca = c - a;\n var cb = c - b;\n var res = (d - ca - cb > 0) && (d - ca - cb) % 3 === 0\n print(res ? 'YES' : 'NO')\n }\n}\nmain();"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var abcd = readline().split(' ').map(Number);\n var a = abcd[0];\n var b = abcd[1];\n var c = abcd[2];\n var d = abcd[3];\n var ca = c - a;\n var cb = c - b;\n var res = (d - ca - cb >= 0) && (d - ca - cb) % 3 === 0\n print(res ? 'YES' : 'NO')\n }\n}\nmain();"}, {"source_code": "'use strict';\nvar t = readline();\nwhile(t--) {\n var a = readline().split(\" \").map(function(num) {\n return parseInt(num);\n }).reduce(function(total, num) {\n return total + num;\n }, 0);\n print(((a % 3) ? \"NO\" : \"YES\") + \"\\n\");\n \n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ');\n\tvar dt = Math.max(j[0],j[1],j[2])*3 - j[0]-j[1]-j[2];\n\tj[3] -= dt;\n\tif(j[3]%3 > 0 || j[3]%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar soma = j[0]+j[1]+j[2]+j[3];\n\tvar d1,d2\n\tif(j[2]>j[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t j[3] -= dt;\n\t if(j[3]%3 > 0 || j[3]%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var num_tests = readline();\nvar coins = [];\nfor(var i=0;i 0 || soma%3 < 0){\n print('NO');\n }else{\n \tprint('YES');\n }\n}"}, {"source_code": "var t = readline()-1;\nwhile(t--){\n\tvar j = readline().split(' ');\n\tvar soma = j[0]+j[1]+j[2]+j[3];\n\tvar d1,d2\n\tif(j[2]>j[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t if(soma%3 > 0 || soma%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var num_tests = readline();\nvar coins = [];\nfor(var i=0;i 0 || soma%3 < 0){\n print('NO');\n }else{\n \tprint('YES');\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar soma = j[0]+j[1]+j[2]+j[3];\n\tvar d1,d2\n\tif(j[2]>j[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t soma -= dt;\n\t if(soma%3 > 0 || soma%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar dt = Math.max(j[0],j[1],j[2])*3 - j[0]-j[1]-j[2];\n\tj[3] -= dt;\n\tif(j[3]%3 === 0 && j[3] > 0){\n print('YES');\n }else{\n \t print('NO');\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ');\n\tvar soma = j[0]+j[1]+j[2]+j[3];\n\tvar d1,d2\n\tif(j[2]>j[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t if(soma%3 > 0 || soma%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n\tvar j = readline().split(' ').map(Number);\n\tvar soma = j[0]+j[1]+j[2]+j[3];\n\tvar d1,d2\n\tif(j[2]>j[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tprint(dt);\n\tif(j[3]>=dt){\n\t j[3] -= dt;\n\t if(j[3]%3 > 0 || j[3]%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var num_tests = readline();\nvar coins = [];\nfor(var i=0;ij[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t if(soma%3 > 0 || soma%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var num_tests = readline();\nvar coins = [];\nfor(var i=0;ij[1]){\n\t d1 = Math.abs(j[2]-j[1]);\n\t d2 = Math.abs(j[2]-j[0]);\n\t}else{\n\t d1 = Math.abs(j[1]-j[2]);\n\t d2 = Math.abs(j[1]-j[0]);\n\t}\n\tvar dt = d1+d2;\n\tif(j[3]>=dt){\n\t if(soma%3 > 0 || soma%3 < 0){\n print('NO');\n }else{\n \t print('YES');\n }\n\t}else{\n\t print('NO');\n\t}\n}"}, {"source_code": "var num_tests = readline();\nvar coins = [];\nfor(var i=0;i Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n for (let index = 1; index <= t; index++) {\n const element = inputs[index].trim().split(' ');\n let n = element[3];\n let coins = strToNumArr(element.slice(0, 3).sort((a, b) => b - a));\n if (n > 0 && (n - ((2 * coins[0]) - coins[1] - coins[2])) % 3 === 0) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n for (let index = 1; index <= t; index++) {\n const element = inputs[index].trim().split(' ');\n let n = element[3];\n let coins = strToNumArr(element.slice(0, 3).sort((a, b) => b - a));\n if ((n - ((2 * coins[0]) - coins[1] - coins[2])) % 3 === 0) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var inputLines = null;\n\nfunction readALine() {\n if( inputLines ) { return inputLines.shift(); }\n return readline();\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\nmodule.exports = { main: main, inputLines: inputLines };\n"}, {"source_code": "'use strict';\n\nlet inputString = '', currentLine = 0;\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n }); \n console.log(\"CALL MAIN\");\n main();\n});\n \nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputString = (inLines ? inLines : []);\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\n// module.exports.main = main;"}, {"source_code": "'use strict';\n\nlet inputString = '', currentLine = 0, inputLine = [];\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n var arr = inputString.trim().split('\\n').map(str => {\n return str.trim();\n }); \n main(arr);\n});\n \nfunction readALine() {\n return inputLine[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\n// module.exports.main = main;"}, {"source_code": "var inputLines = null;\n\nfunction readALine() {\n if( inputLines ) { return inputLines.shift(); }\n return readline();\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\n//module.exports = { main: main, inputLines: inputLines };\n"}, {"source_code": "'use strict';\n\nlet inputString = '', currentLine = 0;\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n }); \n console.log(\"Inputstring\" + inputString);\n main();\n});\n \nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputString = (inLines ? inLines : []);\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\n// module.exports.main = main;"}, {"source_code": "'use strict';\n\nlet inputString = '', currentLine = 0;\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n }); \n main(); \n});\n \nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputString = (inLines ? inLines : []);\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;"}, {"source_code": "let inputLines = [];\nconst printALine = console.log\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => { inputLines.push(line); });\nrl.on('close', main);\nlet rlindex = 0;\nfunction readALine() {\n return inputLines[rlindex++];\n}\n \n// ======================================================\n// A. Collecting Coins\n// https://codeforces.com/problemset/problem/1294/A\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction doIt( a, b, c, n ) { \n var max = Math.max(a, b, c);\n var coinToGive = 3*max - (a + b + c);\n var leftOver = n - coinToGive;\n if( leftOver % 3 == 0 ) return \"YES\";\n return \"NO\";\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines ? inLines : [];\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1);\n var result = doIt(arr[0], arr[1], arr[2], arr[3]);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\nfunction asArrayNumber(testCase) {\n return testCase.split(' ').map((x) => {\n return parseInt(x, 10);\n });\n}\nfunction findGreatest(sisters) {\n return Math.max(...sisters);\n}\nfunction calculateDifference(greatest, sisters) {\n let difference = 0;\n for (let i = 0; i < sisters.length; i++) {\n difference = greatest - sisters[i] + difference;\n }\n return difference;\n}\nfunction solve(lines) {\n const testCases = lines.slice(1);\n // console.log('testCases', testCases)\n for (let i = 0; i < testCases.length; i++) {\n const numbers = asArrayNumber(testCases[i]);\n const sisters = [numbers[0], numbers[1], numbers[2]];\n const n = numbers[3];\n // console.log('sisters, n', sisters, n)\n const greatest = findGreatest(sisters);\n const difference = calculateDifference(greatest, sisters);\n const remainder = n - difference;\n if (remainder > 0 && remainder % 3 === 0) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n }\n}\nfunction main() {\n const stdinBuffer = fs_1.default.readFileSync(0);\n const lines = stdinBuffer\n .toString()\n .split('\\n')\n .filter((x) => x !== '');\n solve(lines);\n}\nmain();\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (d.split(' ').map(Number).reduce((x, y) => x + y, 0) % 3 === 0) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\n\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n})\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(a, b, c, n) {\n const sum = a + b + c + n;\n return (sum % 3 === 0) ? 'YES' : 'NO';\n}\n\nfunction main() {\n const t = parseInt(readline());\n for(let i = 0; i < t; i++) {\n const [a, b, c, n] = readline().split(' ');\n const res = solve(a, b, c, n);\n console.log(res);\n }\n}"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\n\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n})\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(a, b, c, n) {\n const sum = a + b + c + n;\n if (sum % 3 !== 0) {\n return false;\n }\n const result = sum / 3;\n return (a <= result && b <= result && c <= result);\n}\n\nfunction main() {\n const t = parseInt(readline());\n for(let i = 0; i < t; i++) {\n const [a, b, c, n] = readline().split(' ');\n const res = solve(a, b, c, n);\n console.log(res ? 'YES': 'NO');\n }\n}"}], "src_uid": "bc5fb5d6882b86d83e5c86f21d806a52"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n console.log(d);\n\n c++;\n});\n", "positive_code": [{"source_code": "var tests = parseInt(readline())\nfor(var t = 0; t < tests; t ++){ print(readline()) }"}, {"source_code": "//=> function\n// ES5\n/*\nvar x = function (x, y) {\n return x * y;\n}\n\n// ES6\nconst x = (x, y) => x * y;\n*/\n\nvar t = +readline();\nwhile(t--)\n{\n x = +readline();\n print(x);\n}"}, {"source_code": "var t = readline();\n\nwhile (t--) {\n print(readline());\n}"}, {"source_code": "const n = Number(readline());\nvar inp ;\nfor(var i = 0; i < n; i++ ){\n inp = Number(readline());\n print(inp);\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor (var i = 0; i < t; i++) {\n print(readline());\n}\n"}, {"source_code": "var input = readline();\n\nfor(var i=0;i {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t=0; t < test; t++) {\n\t\tlet n = parseInt(parseInt(input[t+1]));\n\t\tconsole.log(n);\n\t}\n});\n\nfunction solution(n) {\n\tlet ans = Array(n+1).fill(0);\n\tans[0] = 0;\n\tfor (let i = 1; i < n+1; i++) {\n\t\tans[i] = ans[i-1] + 1;\n\t}\n\treturn ans[n];\n}"}, {"source_code": "// Q: https://codeforces.com/contest/1339/problem/A\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t=0; t < test; t++) {\n\t\tlet n = parseInt(input[t+1]);\n\t\tconsole.log(n);\n\t}\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet first = true;\nrl.on('line', (line) => {\n if (first) {\n first = false;\n } else {\n process.stdout.write(line + '\\n')\n }\n})"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(nums) {\n\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n = readLine()[0];\n console.log(n);\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n solve(arr);\n process.exit(0);\n});\n\nfunction solve(lines) {\n let row = 0;\n let t = +lines[row++];\n for(let i = 0; i < t; i++) {\n let n = +lines[row++];\n console.log(n);\n }\n}\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\nvar input = \"\";\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n\tvar lines = input.split('\\n');\n\tfor (i = 1; i < lines.length; i++)\n\t\tprocess.stdout.write(lines[i]);\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [a] = readLine().split(' ').map((val) => parseInt(val));\n console.log(a);\n }\n //process.stdout.write(\"hello: \");\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet first = true;\nrl.on('line', (line) => {\n if (first) {\n first = false;\n } else {\n process.stdout.write(line)\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n console.log(+d);\n\n c++;\n});\n"}, {"source_code": "process.stdin.setEncoding('ascii');\nvar T = -1\n\nprocess.stdin.on('data', function (data) {\n if (T < 0)\n T = parseInt(data);\n else {\n process.stdout.write(data);\n T--;\n if (T == 0)\n process.exit();\n }\n});"}], "src_uid": "740c05c036b646d8fb6b391af115d7f0"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0], x = k[1];\n }else{\n var min = 0, max = 0, total = 0;\n for(j = 0; j < n; j++){\n total += k[j];\n max += Math.floor(k[j] / x);\n if(k[j] % x !== 0){\n max++;\n }\n }\n min += Math.floor(total / x);\n if(total % x !== 0){\n min++;\n }\n console.log(min, max);\n }\n }\n});", "positive_code": [{"source_code": "const solve = (n, x, a) => {\r\n let max = sum = 0;\r\n for (const item of a) {\r\n sum += item;\r\n max += Math.ceil(item / x);\r\n }\r\n let min = Math.ceil(sum / x);\r\n console.log(min, max);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[0][1], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const solve = (n, x, a) => {\r\n let max = 0;\r\n let sum = a.reduce((x, y) => x + y);\r\n for (const item of a) {\r\n max += Math.ceil(item / x);\r\n }\r\n let min = Math.ceil(sum / x);\r\n console.log(min, max);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[0][1], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nString.prototype.parseInt = (e) => parseInt(e);\r\n\r\n\r\nlet meow=-1,n,x,t;\r\nlet sumall,sum2;\r\n\r\n\r\nfunction foo(line) {\r\n\tif(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }\r\n\tif(n==-1) {\r\n\t\tlet t = line.split(' ');\r\n\t\tn = t[0]-0;\r\n\t\tx = t[1]-0;\r\n\r\n\t\tt=n;\r\n\t\tsumall=0;\r\n\t\tsum2=0;\r\n\t\treturn;\r\n\t} else {\r\n\t\tlet zz = line.split(' ');\r\n\t\tfor(let i=0;i foo(line));\r\n\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2; i++){\n var k = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = k[0], x = k[1];\n }else{\n var min = 0, max = 0, sum = 0;\n for(j = 0; j < n; j++){\n sum += k[j];\n max += Math.floor(k[j] / x);\n if(k[j] % x !== 0){\n max++;\n }\n }\n min = Math.floor(sum / x);\n if(sum % x !== 0){\n min++;\n }\n console.log(min, max);\n }\n }\n});\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n var tc = parseInt(readline());\r\n while (tc--) {\r\n var ar = readline().split(\" \").map(e => +e);\r\n var n = ar[0], x = ar[1];\r\n var sum = 0, maxB = 0;\r\n var a = readline().split(\" \").map(e => +e).map(e=>{\r\n sum+=e;\r\n maxB+=Math.ceil(e/x);\r\n });\r\n var minB = Math.ceil(sum/x);\r\n console.log(minB + \" \" + maxB);\r\n }\r\n\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n//-----------main function-----------\r\n \r\nfunction main() {\r\n\r\n var t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n var ar = readline().split(' ').map(n => parseInt(n));\r\n var arr = readline().split(' ').map(n => parseInt(n));\r\n\r\n var n = ar[0];\r\n var x = ar[1];\r\n\r\n var minimal, maximal;\r\n\r\n const beauty = (arrayInput, divisor) => {\r\n var result = 0;\r\n arrayInput.forEach(element => {\r\n result = result + Math.ceil(element / divisor);\r\n });\r\n\r\n return result;\r\n }\r\n\r\n minimal = beauty(arr, x);\r\n \r\n for (var i = arr.length - 1; i >= 1; i--) {\r\n arr[i - 1] = arr[i - 1] + arr[i];\r\n arr.pop();\r\n }\r\n\r\n maximal = beauty(arr, x);\r\n\r\n\r\n print(maximal + ' '+ minimal);\r\n \r\n}\r\n\r\n\r\n}\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst [len, x] = readLine().split(' ').map(Number);\n\t\tlet [sum, divSum] = [0, 0];\n\t\treadLine()\n\t\t\t.split(' ')\n\t\t\t.forEach((n) => {\n\t\t\t\tn = Number(n);\n\t\t\t\tsum += n;\n\t\t\t\tdivSum += Math.ceil(n / x);\n\t\t\t});\n\t\tconsole.log(`${Math.ceil(sum / x)} ${divSum}`);\n\t}\n}\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, x] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mn = 0, mx = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tmn += a[i];\r\n\t\t\tmx += Math.ceil(a[i]/x);\r\n\t\t}\r\n\t\tmn = Math.ceil(mn/x);\r\n\r\n\t\tconsole.log(mn, mx);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [n,xx] = readline().split(' ').map(x => Number(x));\r\n var sum = 0\r\n var sum2 = 0\r\n var array = readline().split(' ').map(x => {\r\n sum+=Number(x)\r\n sum2+=Math.ceil(Number(x)/xx)\r\n Number(x)\r\n });\r\n console.log(Math.ceil(sum/xx), sum2)\r\n // console.log(sum2)\r\n\r\n })\r\n\r\n}\r\n"}, {"source_code": "\r\nconst { EOL } = require('os');\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', data => input += data);\r\nprocess.stdin.on('end', main);\r\n\r\nfunction main() {\r\n const lines = input.trim().split(EOL).map(line => line.trim());\r\n for (let i = 1; i < lines.length - 1; i += 2) {\r\n let ints = lines[i].split(' ').map(Number);\r\n let arr = lines[i+1].split(' ').map(Number);\r\n beauty(ints, arr);\r\n }\r\n}\r\n\r\nfunction beauty(ints, arr) {\r\n let [n, x] = ints;\r\n let max = b(arr, x);\r\n let min = b([arr.reduce((a, c) => a + c, 0)], x);\r\n console.log(min, max)\r\n}\r\n\r\nfunction b(arr, x) {\r\n return arr.reduce((a, c) => a + Math.ceil(c / x), 0);\r\n}\r\n\r\n"}, {"source_code": "let inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', (data) => {\r\n inputString += data;\r\n})\r\nprocess.stdin.on('end', function (){\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((str) => str.trim());\r\n main();\r\n})\r\nfunction readLine(){\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n let t = +readLine();\r\n while(t--){\r\n const [n, x] = readLine().split(' ').map(Number);\r\n let [mn, mx] = [0, 0];\r\n readLine()\r\n .split(' ')\r\n .forEach((val) => {\r\n val = Number(val);\r\n mn += val;\r\n mx += Math.ceil(val / x);\r\n });\r\n mn = Math.ceil(mn / x);\r\n console.log(`${mn} ${mx}`);\r\n }\r\n}"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 2; i += 2) {\r\n let split = lines[i].split(' ');\r\n const n = parseInt(split[0]);\r\n const x = parseInt(split[1]);\r\n\r\n const arr = lines[i + 1].split(' ').map(num => parseInt(num));\r\n solve(n, x, arr);\r\n }\r\n});\r\n\r\nfunction solve(n, x, arr) {\r\n let max = 0;\r\n let sum = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i];\r\n max += Math.ceil(arr[i] / x);\r\n }\r\n\r\n const min = Math.ceil(sum / x);\r\n\r\n console.log(min, max);\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar x = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar sum = 0;\r\n\t\tvar max = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tsum += list[j];\r\n\t\t\tmax += Math.ceil(list[j] / x);\r\n\t\t}\r\n\t\tmyout(Math.ceil(sum / x) + \" \" + max);\r\n\t}\r\n}\r\n"}, {"source_code": "r=readline;m=Math.ceil;j=' ';for(k=r();k--;x=r().split(j)[1],o=p=0,r().split(j).map(a=>{o+=m(a/x);p-=-a}),print(m(p/x)+j+o));"}, {"source_code": "r=readline;m=Math.ceil;j=' ';for(k=r();k--;x=r().split(j)[1],o=p=0,r().split(j).map(a=>{o+=m(a/x);p-=-a}),print(m(p/x)+j+o));\r\n\r\n\r\n"}, {"source_code": "r = readline\r\n\r\nfor(k = r(); k--; ) {\r\n\r\n x = r().split(' ')[1]\r\n a = r().split(' ')\r\n ma = 0; mi = 0;\r\n a.map(a => {ma += Math.ceil(a/x); mi-=-a;})\r\n print(Math.ceil(mi/x)+\" \"+ma)\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n \r\n for (var k = 0, z = 0; k < n; k++, z += 2) {\r\n max += Math.ceil(a[k] / x);\r\n min += a[k];\r\n }\r\n \r\n print(Math.ceil(min / x), max);\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n \r\n for (var k = 0, z = 0; k < n; k++, z += 2) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n for (var z = 0; z < n; z += 2) {\r\n min += a[z] + (a[z+1] || 0);\r\n }\r\n \r\n print(Math.ceil(min / x), max);\r\n}"}, {"source_code": "\"use strict\"\r\nlet t = +readline ();\r\nwhile (t--)\r\n{\r\n let count = 0, count2 = 0;\r\n let list = readline ().split (' ').map (i => +i);\r\n let arr = readline ().split (' ').map (i => +i);\r\n for (let j of arr)\r\n {\r\n count += j;\r\n count2 += Math.ceil (j / list[1]);\r\n }\r\n print (Math.ceil (count / list[1]), count2);\r\n}\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let n = input[0];\r\n let x = input[1];\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n\r\n let sum = 0;\r\n let sum2 = 0;\r\n\r\n for(let j = 0; j < n; j++){\r\n sum += arr[j];\r\n sum2 += Math.ceil(arr[j] / x) \r\n }\r\n \r\n print(Math.ceil(sum / x) + \" \" + (sum2));\r\n}"}, {"source_code": "var tc = parseInt(readline());\r\nwhile (tc-- > 0) {\r\n var Ar = readline().split(' ').map(x => +x);\r\n var n = Ar[0], m = Ar[1];\r\n\r\n var sum = 0, res = 0;\r\n var arr = readline().split(' ').map(x => +x);\r\n for (var i = 0; i < arr.length; i++){\r\n sum += arr[i];\r\n res += Math.ceil(arr[i] / m);\r\n }\r\n print(Math.ceil(sum / m), res);\r\n}"}], "negative_code": [{"source_code": "const solve = (n, x, a) => {\r\n let sum = a.reduce((x, y) => x + y);\r\n let restT = 0;\r\n for (const item of a) {\r\n let tmp = item / x - Math.floor(item / x);\r\n restT += item % n;\r\n }\r\n let min = Math.round(sum / n);\r\n let max = Math.round(sum / n) + Math.floor(restT / n);\r\n console.log(min, max);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[0][1], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const solve = (n, x, a) => {\r\n let sum = a.reduce((x, y) => x + y);\r\n let restT = 0;\r\n for (const item of a) {\r\n restT += item % n;\r\n }\r\n let min = Math.floor(sum / n);\r\n let max = Math.floor(sum / n) + Math.floor(restT / n);\r\n console.log(min, max);\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[0][1], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nString.prototype.parseInt = (e) => parseInt(e);\r\n\r\n\r\nlet meow=-1,n,x,t;\r\nlet sumall,sum2;\r\n\r\n\r\nfunction foo(line) {\r\n\tif(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }\r\n\tif(n==-1) {\r\n\t\tlet t = line.split(' ');\r\n\t\tn = t[0]-0;\r\n\t\tx = t[1]-0;\r\n\r\n\t\tt=n;\r\n\t\tsumall=0;\r\n\t\tsum2=0;\r\n\t\treturn;\r\n\t} else {\r\n\t\tlet zz = line.split(' ');\r\n\t\tfor(let i=0;i foo(line));\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nString.prototype.parseInt = (e) => parseInt(e);\r\n\r\n\r\nlet meow=-1,n,x,t;\r\nlet sumall,sum2;\r\n\r\n\r\nfunction foo(line) {\r\n\tif(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }\r\n\tif(n==-1) {\r\n\t\tlet t = line.split(' ');\r\n\t\tn = t[0]-0;\r\n\t\tx = t[1]-0;\r\n\r\n\t\tt=n;\r\n\t\tsumall=0;\r\n\t\tsum2=0;\r\n\t\treturn;\r\n\t} else {\r\n\t\tlet zz = line.split(' ');\r\n\t\tfor(let i=0;i foo(line));\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n var tc = parseInt(readline());\r\n while (tc--) {\r\n var ar = readline().split(\" \").map(e => +e);\r\n var n = ar[0], x = ar[1];\r\n var sum = 0, maxB = 0;\r\n var a = readline().split(\" \").map(e => +e).map(e=>{\r\n sum+=e;maxB+=parseInt(e/x);if(e%x)maxB++\r\n });\r\n var minB = parseInt(sum / x);\r\n if (sum % x) minB++;\r\n console.log(minB + \" \" + maxB);\r\n }\r\n\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n//-----------main function-----------\r\n \r\nfunction main() {\r\n\r\n var t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n var ar = readline().split(' ').map(n => parseInt(n));\r\n var arr = readline().split(' ').map(n => parseInt(n));\r\n\r\n var n = ar[0];\r\n var x = ar[1];\r\n\r\n var minimal, maximal;\r\n\r\n const beauty = (arrayInput, divisor) => {\r\n var result = 0;\r\n arrayInput.forEach(element => {\r\n result = result + Math.ceil(element / divisor);\r\n });\r\n\r\n return result;\r\n }\r\n\r\n minimal = beauty(arr, x);\r\n \r\n for (var i = arr.length - 1; i >= 1; i--) {\r\n arr[i - 1] = arr[i - 1] + arr[i];\r\n arr.pop();\r\n }\r\n\r\n maximal = beauty(arr, x);\r\n\r\n\r\n print(maximal, minimal);\r\n \r\n}\r\n\r\n\r\n}\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst [len, x] = readLine().split(' ').map(Number);\n\t\tlet [sum, divSum] = [0, 0];\n\t\treadLine()\n\t\t\t.split(' ')\n\t\t\t.forEach((n) => {\n\t\t\t\tn = Number(n);\n\t\t\t\tsum += n;\n\t\t\t\tdivSum += Math.ceil(n / x);\n\t\t\t});\n\t\tconsole.log(`${Math.floor(sum / x)} ${divSum}`);\n\t}\n}\n"}, {"source_code": "r=readline;m=Math.ceil;j=' ';for(k=r();k--;x=r().split(j)[1],o=p=0,r().split(j).map(a=>{o+=m(a/x);p+=a}),print(m(p/x)+j+o));"}, {"source_code": "r=readline;j=' ';for(k=r();k--;x=r().split(j)[1],o=p=0,r().split(j).map(a=>{o+=~~(a/x);p-=-a}),print(~~(p/x)+j+o));"}, {"source_code": "r = readline\r\n\r\nfor(k = r(); k--; ) {\r\n\r\n x = r().split(' ')[1]\r\n a = r().split(' ')\r\n ma = 0; mi = 0;\r\n a.map(a => {ma += Math.ceil(a/x); mi-=-a;})\r\n print(ma + \" \" + Math.ceil(mi/x))\r\n}"}, {"source_code": "r = readline\r\n\r\nfor(k = r(); k--; ) {\r\n\r\n x = r().split('')[1]\r\n a = r().split('')\r\n ma = 0; mi = 0;\r\n a.map(a => {ma += Math.ceil(a/x); mi-=-a;})\r\n print(ma + \" \" + Math.ceil(mi/x))\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n \r\n for (var k = 0; k < n; k++) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n for (var z = 0; z < n; z += 2) {\r\n min += Math.ceil((a[z] + (a[z+1] || 0)) / x);\r\n }\r\n \r\n print(min, max);\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n \r\n for (var k = 0; k < n; k++) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n for (var z = 0; z < n; z += 2) {\r\n min += (a[z] + (a[z+1] || 0)) / x;\r\n }\r\n \r\n print(min.toFixed(0), max);\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n \r\n for (var k = 0; k < n; k++) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n for (var z = 0; z < n; z += 2) {\r\n min += (a[z] + (a[z+1] || 0)) / x;\r\n }\r\n \r\n print(Math.ceil(min), max);\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n var min = 0;\r\n var temp = [];\r\n \r\n for (var k = 0; k < n; k++) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n for (var z = 0, d = 0; z < n - 1; z++) {\r\n if (a[d+1]) {\r\n min += (a[d] + a[d+1]) / x;\r\n } else {\r\n min += a[d] / x;\r\n }\r\n \r\n d += 2;\r\n }\r\n \r\n print(min, max);\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var l = readline().split(' ').map(i => +i);\r\n var n = l[0];\r\n var x = l[1];\r\n var a = readline().split(' ').map(i => +i);\r\n var max = 0;\r\n \r\n for (var k = 0; k < a.length; k++) {\r\n max += Math.ceil(a[k] / x);\r\n }\r\n \r\n print(Math.max(...a) - Math.min(...a), max);\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let n = input[0];\r\n let x = input[1];\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n\r\n let sum = 0;\r\n let temp = 0;\r\n\r\n for(let j = 0; j < n; j++){\r\n sum += arr[j];\r\n if(arr[j] % x !== 0){\r\n temp++;\r\n }\r\n }\r\n let min = Math.ceil(sum / x);\r\n print(min + \" \" + (min + temp));\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let n = input[0];\r\n let x = input[1];\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n\r\n let min = 0;\r\n let temp = 0;\r\n\r\n for(let j = 0; j < n; j++){\r\n min += Math.ceil(arr[j] / x);\r\n if(arr[j] % x !== 0){\r\n temp++;\r\n }\r\n }\r\n print(min + \" \" + (min + temp));\r\n}"}], "src_uid": "b36d7f840abe998185a988fe8dd2ec75"} {"source_code": "const input = Number(readline());\nprint(input === 1 ? \"-1\" : `${input} ${input + 1} ${input * (input + 1)}`);\n", "positive_code": [{"source_code": "var n = parseInt(readline());\nif (n == 1) {\n print(\"-1\");\n}\nelse {\n print(n + \" \" + (n+1) + \" \" + (n*(n+1)));\n}"}], "negative_code": [{"source_code": "const input = Number(readline());\nprint(`${input} ${input + 1} ${input * (input + 1)}`);\n"}], "src_uid": "f60ea0f2caaec16894e84ba87f90c061"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n\n const no = parseInt(arr.shift())\n const cans = arr[0].split(' ')\n const map = new Map()\n\n for(let i = 1; i <= no; i++) {\n map.set(i, parseInt(cans[i - 1]))\n }\n\n const map2 = new Map([...map.entries()].sort((a, b) => b[1] - a[1]))\n var sum = 0\n var i = 0\n map2.forEach((v) => {\n sum += v * i + 1\n i++\n })\n\n console.log(sum)\n\n const keys = map2.keys()\n let result = keys.next()\n while(!result.done) {\n process.stdout.write(result.value + ' ')\n result = keys.next()\n }\n console.log()\n})", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n\n let list = [...data];\n\n let pushCount = 0;\n let order = []\n let i = 0;\n while (i < list.length) {\n let max = Math.max(...list);\n let index = list.indexOf(max);\n\n pushCount += (list[index] * i + 1);\n order.push(index + 1);\n list[index] = 0;\n\n i++;\n }\n\n return {pushCount, order: order.join(' ')};\n }\n\n\n\n let count = +lines[0];\n let data = lines[1].split(' ').map(Number);\n\n let result = foo(data);\n\n let answer = '';\n answer += result.pushCount + \"\\n\";\n answer += result.order;\n\n console.log(answer);\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map((x, i) => {\n return {\n val: Number(x),\n idx: i + 1,\n }\n });\n\n arr.sort((a, b) => b.val - a.val);\n let ans = 0;\n const ansArr = [];\n\n for (let i = 0; i < arr.length; i++) {\n ans += i * arr[i].val + 1;\n ansArr.push(arr[i].idx);\n }\n\n console.log(ans);\n console.log(ansArr.join(' '));\n\n // const arr = d.split(' ').map(Number);\n // const copyArr = arr.concat();\n // copyArr.sort((a, b) => b - a);\n\n // let ans = 0;\n // const ansArr = [];\n\n // for (let i = 0; i < copyArr.length; i++) {\n // let currPoints = i * copyArr[i] + 1;\n // ans += currPoints;\n // }\n\n // for (let i = 0; i < copyArr.length; i++) {\n // for (let j = 0; j < arr.length; j++) {\n // if (arr[j] === copyArr[i]) {\n // ansArr.push(j + 1);\n // arr[j] = 0;\n // }\n // }\n // }\n\n // console.log(ans);\n // console.log(ansArr.join(' '));\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const copyArr = arr.concat();\n copyArr.sort((a, b) => b - a);\n\n let ans = 0;\n const ansArr = [];\n\n for (let i = 0; i < copyArr.length; i++) {\n let currPoints = i * copyArr[i] + 1;\n ans += currPoints;\n }\n\n for (let i = 0; i < copyArr.length; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (arr[j] === copyArr[i]) {\n ansArr.push(j + 1);\n arr[j] = 0;\n }\n }\n }\n\n console.log(ans);\n console.log(ansArr.join(' '));\n\n c++;\n});\n"}, {"source_code": "'use strict'\n\nconst n = parseInt(readline());\nconst a = readline().split(' ').map(Number);\n \nconst b = a.map((v, k) => ({ k, v })).sort((x, y) => y.v - x.v);\n\nwrite(b.map(i => i.v).reduce((r, i, ix) => r + ix * i + 1, 0) + '\\n' + b.map(i => i.k + 1).join(' '));"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var n = readline();\n var a = readline(); \n solve(n, a);\n}\n\nfunction solve(n, a){\n let sortAr = [];\n let res = [];\n let x = 0;\n let cnt = 0;\n a.split(' ').forEach((el, idx) => {\n sortAr.push({i: idx, a: el});\n });\n sortAr.sort((a, b) => parseInt(a.a) - parseInt(b.a)).reverse();\n sortAr.forEach((el, idx) => {\n x += el.a*cnt + 1;\n res.push(el.i+1);\n cnt++;\n });\n console.log(x);\n console.log(res.join(' '));\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n const scores = lines[1]\n .split(' ')\n .map(r => parseInt(r))\n .filter(r => r)\n .map((v, i) => ({ i, v }))\n scores.sort((x, y) => y.v - x.v)\n const total = scores.reduce((s, r, i) => s + (i * r.v + 1), 0)\n const order = scores.map(r => r.i + 1).join(' ')\n console.log(total);\n console.log(order)\n})"}], "negative_code": [], "src_uid": "c79f25dab583edfcabb6991be7abf971"} {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let n = +input[z++];\r\n if(n === 1) console.log(1);\r\n else if(n === 2) console.log(-1);\r\n else{\r\n let counter = 1;\r\n let arr = Array.from({length : n}, ()=>[])\r\n for (let i = 0; i < n; i++) {\r\n arr[i][i] = counter;\r\n counter++;\r\n }\r\n for (let i = 1; i < n; i++) {\r\n let j = 0;\r\n let k = i;\r\n while (k < n && j < n) {\r\n arr[j][k] = counter;\r\n counter++;\r\n k++;\r\n j++;\r\n }\r\n j = 0;\r\n k = i;\r\n while (k < n && j < n) {\r\n arr[k][j] = counter;\r\n counter++;\r\n k++;\r\n j++;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n console.log(...arr[i]); \r\n }\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "const solve = (n) => {\r\n try {\r\n if (n === 2) return -1;\r\n const matrix = [];\r\n let even = 2;\r\n let odd = 1;\r\n\r\n for (let i = 0; i < n; i += 1) {\r\n const internal = [];\r\n\r\n for (let j = 0; j < n; j += 1) {\r\n if (odd <= n * n) {\r\n internal.push(odd);\r\n odd += 2;\r\n } else if (even <= n * n) {\r\n internal.push(even);\r\n even += 2;\r\n }\r\n }\r\n matrix.push(internal);\r\n }\r\n return matrix.map((line) => line.join(' ')).join('\\n');\r\n } catch (ex) {\r\n console.log('ex:', ex);\r\n }\r\n};\r\n\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map((l) => l.trim());\r\n\r\n for (let i = 0; i < n; i++) {\r\n console.log(solve(+lines[i]));\r\n }\r\n});\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\t\r\n\t\tif (n == 2) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tconst ans = Array.from(Array(n), x => Array(n));\r\n\r\n\t\tlet r = 0, c = 0, nxt = 0;\r\n\t\twhile (c < n) {\r\n\t\t\tlet i = r, j = c;\r\n\t\t\twhile (i >= 0 && j < n) {\r\n\t\t\t\tans[i][j] = ++nxt;\r\n\t\t\t\ti--; j++;\r\n\t\t\t}\r\n\t\t\tif (r < n - 1) \r\n\t\t\t\tr++;\r\n\t\t\telse\r\n\t\t\t\tc++;\r\n\t\t}\r\n\r\n\t\t[ans[0][0], ans[n-1][n-1]] = [ans[n-1][n-1], ans[0][0]];\r\n\r\n\t\tfor (const row of ans)\r\n\t\t\tconsole.log(row.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n for (var a = 1; a < input.length; a++) {\r\n var n = Number(input[a]);\r\n if (n === 1) {\r\n console.log(1);\r\n } else if (n === 2) {\r\n console.log(-1);\r\n } else {\r\n var arr = new Array(n).fill();\r\n for (var i = 0; i < n; i++) {\r\n arr[i] = new Array(n);\r\n }\r\n var count = 1;\r\n for (var k = 0; k < n; k++) {\r\n arr[k][k] = count;\r\n count++;\r\n }\r\n for (var k = 1; k < n; k++) {\r\n var i = 0, j = k;\r\n while (i < n && j < n) {\r\n arr[i][j] = count;\r\n count++;\r\n i++;\r\n j++;\r\n }\r\n var i = k, j = 0; \r\n while (i < n && j < n) {\r\n arr[i][j] = count;\r\n count++;\r\n i++;\r\n j++;\r\n }\r\n }\r\n for (var i = 0; i < arr.length; i++) {\r\n console.log(arr[i].join(\" \"));\r\n }\r\n }\r\n }\r\n})"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n) {\r\n if (n === 2) {\r\n console.log('-1')\r\n return\r\n }\r\n let matrix = Array(n * n)\r\n let num = 0, row = 0\r\n for (let i = 0; i < n * n; i += 2) matrix[i] = ++num\r\n for (let i = 1; i < n * n; i += 2) matrix[i] = ++num\r\n for (let i = 0; i < n; i++) {\r\n console.log(matrix.slice(row, row + n).join(' '))\r\n row += n\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))\r\n}"}, {"source_code": "\r\nconst solve = (n) => {\r\n\tif (n === 2) {\r\n\t\treturn -1;\r\n\t}\r\n\r\n\tconst matrix = [];\r\n\r\n\tlet counter = 1;\r\n\tfor (let i=0; i line.join(' ')).join('\\n');\r\n}\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst [n, ...lines] = input.trim().split('\\n')\r\n\t\t.map(l => l.trim());\r\n\r\n\tfor (let i=0; i {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst n = +readLine();\n\t\tif (n === 1) console.log(1);\n\t\telse if (n === 2) console.log(-1);\n\t\telse {\n\t\t\tconst arr = Array(n)\n\t\t\t\t.fill(0)\n\t\t\t\t.map((_) => Array(n).fill(0));\n\t\t\tlet [status, count] = ['odd', 1];\n\t\t\tfor (let row = 0; row < n; row++) {\n\t\t\t\tfor (let col = 0; col < n; col++) {\n\t\t\t\t\tif (status === 'odd') {\n\t\t\t\t\t\tif (count <= n ** 2) {\n\t\t\t\t\t\t\tarr[row][col] = count;\n\t\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = 'even';\n\t\t\t\t\t\t\tarr[row][col] = 2;\n\t\t\t\t\t\t\tcount = 4;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (count <= n ** 2) {\n\t\t\t\t\t\t\tarr[row][col] = count;\n\t\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let row = 0; row < n; row++) {\n\t\t\t\tconsole.log(arr[row].join(' '));\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tif(N == 2){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tlist[j] = new Array(N);\r\n\t\t}\r\n\t\tvar V = 1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tfor(var k = (j % 2 == 0) ? 0 : 1; k < N; k += 2){\r\n\t\t\t\tlist[j][k] = V;\r\n\t\t\t\tV++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\tif(list[j][k] == null){\r\n\t\t\t\t\tlist[j][k] = V;\r\n\t\t\t\t\tV++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tmyout(myconv(list[j], 8));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const t=parseInt(readline());\r\n\r\nfor(var k=0;k n * n) {\r\n currentNumber = 2;\r\n }\r\n\r\n }\r\n\r\n write(\"\\n\");\r\n }\r\n}"}, {"source_code": "var T = parseInt(readline());\r\nvar U = 1\r\nvar N = 1\r\nvar u = 1\r\nvar s = \"\"\r\nfunction next() { \r\n var t = (u).toString(10);\r\n u += 2;\r\n if (u > U)\r\n u = 2;\r\n return t; }\r\nwhile (T--) {\r\n N = parseInt(readline());\r\n U = N*N\r\n switch (N) {\r\n case 1:\r\n print(1); break;\r\n case 2:\r\n print(-1); break;\r\n default:\r\n for (var i = 0; i < N; ++i) {\r\n\t\t s += next();\r\n\t\t for (var j = 1; j < N; ++j) \r\n\t\t\t\ts += \" \"+next();\r\n\t\t\tprint(s); \r\n\t\t\ts = \"\"; }\r\n\t\tu = 1; } }"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 1) console.log(1);\r\n else if (n === 2) console.log(-1);\r\n else {\r\n let res = new Array(n).fill(0).map((cur) => new Array(n).fill(0));\r\n let ans = 0;\r\n for (let i = 0; i + 1 < n; i++) {\r\n for (let j = i; j >= 0; j--) res[i - j][j] = ++ans;\r\n }\r\n let j = 0;\r\n for (let i = n - 1; i >= 0; i--) res[j++][i] = ++ans;\r\n for (let i = 1; i < n; i++) {\r\n let j = i,\r\n k = n - 1;\r\n while (j < n) res[j++][k--] = ++ans;\r\n }\r\n res[0][0] = n * n;\r\n res[n - 1][n - 1] = 1;\r\n let r = \"\";\r\n for (let i = 0; i < n; i++) r += res[i].join(\" \") + \"\\n\";\r\n console.log(r);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 1) console.log(1);\r\n else if (n === 2) console.log(-1);\r\n else {\r\n let res = new Array(n).fill(0).map((cur) => new Array(n).fill(0));\r\n let ans = 0;\r\n for (let i = 0; i + 1 < n; i++) {\r\n for (let j = i; j >= 0; j--) res[i - j][j] = ++ans;\r\n }\r\n let j = 0;\r\n for (let i = n - 1; i >= 0; i--) res[j++][i] = ++ans;\r\n for (let i = 1; i < n; i++) {\r\n let j = i,\r\n k = n - 1;\r\n while (j < n) res[j++][k--] = ++ans;\r\n }\r\n let r = \"\";\r\n for (let i = 0; i < n; i++) r += res[i].join(\" \") + \"\\n\";\r\n console.log(r);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const solve = (n) => {\r\n try {\r\n if (n === 2) return -1;\r\n const matrix = [];\r\n let even = 2;\r\n let odd = 1;\r\n for (let i = 0; i < n; i += 1) {\r\n for (let j = 0; j < n; j += 1) {\r\n if (odd <= n * n) {\r\n matrix.push(odd);\r\n odd += 2;\r\n } else if (even <= n * n) {\r\n matrix.push(even);\r\n even += 2;\r\n }\r\n }\r\n }\r\n return matrix;\r\n } catch (ex) {\r\n console.log('ex:', ex);\r\n }\r\n};\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', (str) => input += str);\r\nprocess.stdin.on('end', () => {\r\n const [n, ...lines] = input.trim().split('\\n')\r\n .map((l) => l.trim());\r\n\r\n for (let i = 0; i < n; i++) {\r\n console.log(solve(+lines[i]));\r\n }\r\n});\r\n"}, {"source_code": "const t=parseInt(readline());\r\n\r\nfor(var k=0;k stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var ans = 0;\n for(j = 0; j < n; j++){\n for(l = j; l < n; l++){\n var e = 0;\n for(k = j; k <= l; k++){\n if(a[k] === 0){\n e++;\n }\n }\n ans += l - j + 1 + e;\n }\n }\n console.log(ans);\n }\n }\n});", "positive_code": [{"source_code": "\r\nconst main = () => {\r\n\t\r\n\t// simply break every subsegment into individual items\r\n\tvar t = readInt();\r\n\twhile (t--) {\r\n\t\tvar n = readInt();\r\n\t\tvar a = readIntArr();\r\n\t\tvar l = 1;\r\n\t\tvar r = n;\r\n\t\tvar ans = 0;\r\n\t\tfor (var x of a) {\r\n\t\t\tvar v;\r\n\t\t\tif (x === 0) v = 2;\r\n\t\t\telse v = 1;\r\n\t\t\tans += v * l++ * r--;\r\n\t\t}\r\n\t\tprint(ans);\r\n\t}\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [], "src_uid": "8775da9b78d8236c4606d150df450952"} {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const arr = get_ints();\r\n\r\n b(n,arr);\r\n }\r\n});\r\n\r\nfunction a(k)\r\n{\r\n let e = 0;\r\n let w = 0;\r\n let pe = k;\r\n let pw = 100 - k;\r\n const c = gcd(pe,pw);\r\n return console.log(pe / c + pw / c); \r\n}\r\n\r\nfunction b(n,arr)\r\n{\r\n let flag = true;\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(arr[i] !== i+1) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if(flag) return console.log(0);\r\n if(arr[0] === n && arr[n-1] === 1) return console.log(3);\r\n if(arr[0] === 1 || arr[n-1] === n) return console.log(1);\r\n return console.log(2);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nmodule.exports = b;", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/B\r\n */\r\n\r\nconst solve = (n, a) => {\r\n if (isAscending(a)) return pr(0);\r\n if (a[0] == 1 || a[n - 1] == n) return pr(1);\r\n if (a[0] == n && a[n - 1] == 1) return pr(3);\r\n pr(2);\r\n};\r\n\r\nconst isAscending = (arr) => {\r\n return arr.every((x, i) => {\r\n return i === 0 || x > arr[i - 1];\r\n });\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i - 1] + 1 != list[i]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(list[0] == 1 || list[N - 1] == N){\r\n\t\t\tmyout(1);\r\n\t\t}else if(list[0] == N && list[N - 1] == 1){\r\n\t\t\tmyout(3);\r\n\t\t}else{\r\n\t\t\tmyout(2);\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile(t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\r\n\t\tlet min = max = a[0], isSorted = true;\r\n\t\tfor (let i = 1; i < n; i++) {\r\n\t\t\tif (a[i] < a[i - 1]) isSorted = false;\r\n\t\t\tmin = Math.min(min, a[i]);\r\n\t\t\tmax = Math.max(max, a[i]);\r\n\t\t}\r\n\t\tlet ans; \r\n\t\tif (isSorted) ans = 0;\r\n\t\telse if (min == a[n - 1] && max == a[0]) ans = 3;\r\n\t\telse if (min == a[0] || max == a[n - 1]) ans = 1;\r\n\t\telse ans = 2;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n\n var min = a[0];\n var max = min;\n var min_i = 0;\n var max_i = min_i;\n var sorted = true;\n\n for (var i = 1; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n min_i = i;\n } else if (a[i] > max) {\n max = a[i];\n max_i = i;\n }\n if (a[i] < a[i - 1])\n sorted = false;\n }\n \n if (sorted)\n print(0);\n else if (min_i === n - 1 && max_i === 0)\n print(3);\n else if (min_i !== 0 && max_i !== n - 1)\n print(2);\n else \n print(1);\n} "}, {"source_code": "const isSorted = (arr, temp) => {\r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] != temp[i]) {\r\n return false\r\n }\r\n }\r\n return true\r\n}\r\n\r\nconst cases = readline();\r\nfor (var i = 0; i < cases; i++) {\r\n var size = readline()\r\n var inp = readline()\r\n var arr = inp.split(' ')\r\n var temp = inp.split(' ')\r\n temp = temp.sort((a, b) => { return a - b })\r\n var res = 2\r\n if (isSorted(arr, temp))\r\n res = 0;\r\n else if (arr[0] == 1 || arr[size - 1] == size)\r\n res = 1;\r\n else if (arr[0] == size && arr[size - 1] == 1)\r\n res = 3;\r\n print(res)\r\n}\r\n"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/15/21 night\r\n * https://codeforces.com/contest/1525/problem/B\r\n */\r\n\r\nconst solve = (n, a) => {\r\n if (isAscending(a)) return pr(0);\r\n if (a[0] == 1 || a[n - 1] == n) return pr(1);\r\n if (a[0] == n || a[n - 1] == 1) return pr(3);\r\n pr(2);\r\n};\r\n\r\nconst isAscending = (arr) => {\r\n return arr.every((x, i) => {\r\n return i === 0 || x > arr[i - 1];\r\n });\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let sa = [...a];\r\n stin(sa);\r\n // pr(sa);\r\n // pr(n, a)\r\n let res = 0;\r\n if (isAscending(a)) return pr(res);\r\n while (!isAscending(a)) {\r\n // let next = 0;\r\n for (let i = 0; i < n; i++) {\r\n let should = i + 1;\r\n if (a[i] != should) {\r\n let l = a.slice(0, i + 1);\r\n let ol = [...l];\r\n stin(l);\r\n if (!aeq(l, ol)) res++;\r\n let r = a.slice(i + 1);\r\n let or = [...r]\r\n stin(r);\r\n if (!aeq(r, or)) res++;\r\n a = l.concat(r);\r\n }\r\n }\r\n }\r\n // pr(a);\r\n pr(res);\r\n};\r\n\r\nconst isAscending = (arr) => {\r\n return arr.every((x, i) => {\r\n return i === 0 || x > arr[i - 1];\r\n });\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const arr = get_ints();\r\n\r\n b(arr);\r\n }\r\n});\r\n\r\nfunction a(k)\r\n{\r\n let e = 0;\r\n let w = 0;\r\n let pe = k;\r\n let pw = 100 - k;\r\n const c = gcd(pe,pw);\r\n return console.log(pe / c + pw / c); \r\n}\r\n\r\nfunction b(n,arr)\r\n{\r\n let flag = true;\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(arr[i] !== i+1) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if(flag) return console.log(0);\r\n if(arr[0] === n && arr[n-1] === 1) return console.log(3);\r\n if(arr[0] === 1 || arr[n-1] === n) return console.log(1);\r\n return console.log(2);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nmodule.exports = b;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const arr = get_ints();\r\n\r\n b(arr);\r\n }\r\n});\r\n\r\nfunction a(k)\r\n{\r\n let e = 0;\r\n let w = 0;\r\n let pe = k;\r\n let pw = 100 - k;\r\n const c = gcd(pe,pw);\r\n return console.log(pe / c + pw / c); \r\n}\r\n\r\nfunction b(arr)\r\n{\r\n let peaks = 0;\r\n for(let i = 0; i < arr.length - 2; i++)\r\n {\r\n if(i === 0 && arr[0] !== 1) peaks++;\r\n if(arr[i] < arr[i+1] && arr[i+1] > arr[i+2]) peaks++;\r\n }\r\n return console.log(peaks)\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n\r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nmodule.exports = b;"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const arr = get_ints();\r\n\r\n b(arr);\r\n }\r\n});\r\n\r\nfunction a(k)\r\n{\r\n let e = 0;\r\n let w = 0;\r\n let pe = k;\r\n let pw = 100 - k;\r\n const c = gcd(pe,pw);\r\n return console.log(pe / c + pw / c); \r\n}\r\n\r\nfunction b(arr)\r\n{\r\n let peaks = 0;\r\n for(let i = 0; i < arr.length - 2; i++)\r\n {\r\n if(i === 0 && arr[0] !== 1) peaks++;\r\n if(arr[i] < arr[i+1] && arr[i+1] > arr[i+2]) peaks++;\r\n }\r\n return console.log(peaks)\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if ((typeof x !== 'number') || (typeof y !== 'number')) \r\n return false;\r\n x = Math.abs(x);\r\n y = Math.abs(y);\r\n while(y) {\r\n var t = y;\r\n y = x % y;\r\n x = t;\r\n }\r\n return x;\r\n }\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nmodule.exports = b;"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i - 1] + 1 != list[i]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(list[0] == 1 || list[N - 1] == N || list[0] == N || list[N - 1] == 0){\r\n\t\t\tmyout(1);\r\n\t\t}else{\r\n\t\t\tmyout(2);\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isOK = true;\r\n\t\tfor(var i = 1; i < N; i++){\r\n\t\t\tif(list[i - 1] + 1 != list[i]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(list[0] == 1 || list[N - 1] == N){\r\n\t\t\tmyout(1);\r\n\t\t}else{\r\n\t\t\tmyout(2);\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n\n var min = a[0];\n var max = min;\n var min_i = 0;\n var max_i = min_i;\n var sorted = true;\n\n for (var i = 1; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n min_i = i;\n } else if (a[i] > max) {\n max = a[i];\n max_i = i;\n }\n if (a[i] < a[i - 1])\n sorted = false;\n }\n \n print(sorted? 0: (min_i !== 0 && max_i !== n - 1 && n > 2)? 2: 1);\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n\n var min = a[0];\n var max = min;\n var min_i = 0;\n var max_i = min_i;\n var sorted = true;\n\n for (var i = 1; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n min_i = i;\n } else if (a[i] > max) {\n max = a[i];\n max_i = i;\n }\n if (a[i] < a[i - 1])\n sorted = false;\n }\n \n print(sorted? 0: (min_i !== 0 && max_i !== n - 1)? 2: 1);\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n\n var min = a[0];\n var min_index = 0;\n var sorted = true;\n\n for (var i = 1; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n min_index = i;\n sorted = false;\n }\n if (a[i] < a[i - 1])\n sorted = false;\n }\n \n print(sorted? 0: min_index? 2: 1);\n} "}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(d => parseInt(d));\n\n var min = a[0];\n var min_index = 0;\n var sorted = true;\n\n for (var i = 1; i < n; i++) {\n if (a[i] < min) {\n min = a[i];\n min_index = i;\n }\n if (a[i] < a[i - 1])\n sorted = false;\n }\n \n print(sorted? 0: min_index? 2: 1);\n} "}, {"source_code": "const cases = readline();\r\nfor (var i = 0; i < cases; i++) {\r\n var size = readline()\r\n var inp = readline()\r\n var a = inp.split(' ')\r\n var temp = inp.split(' ')\r\n temp = temp.sort((a,b)=>{return a-b})\r\n var res = 2\r\n if (temp == a)\r\n res = 0;\r\n else if (a[0] == 1 || a[size - 1] == size)\r\n res = 1;\r\n else if (a[0] == size && a[size - 1] == 1)\r\n res = 3;\r\n print(res)\r\n}\r\n"}, {"source_code": "const cases = readline()\r\nfor (var i = 0; i < cases; i++) {\r\n var size = readline()\r\n var inp = readline()\r\n var arr = inp.split(' ')\r\n var temp = inp.split(' ')\r\n temp = temp.sort((a,b)=>{return a-b})\r\n var count = 0\r\n for (var k=0; k < size; k++){\r\n if(arr[k] != temp[k]){\r\n count++\r\n }\r\n }\r\n print(Math.floor(count/2))\r\n}"}], "src_uid": "c212524cc1ad8e0332693e3cf644854b"} {"source_code": "const nm = readline().split(\" \").map(e => parseInt(e));\n\nconst n = nm[0];\nconst m = nm[1];\n\nreadMatrix = () => {\n\tconst result = [];\n\tfor (var i = 0; i < n; i++) {\n\t\tresult.push(readline().split(\" \").map(e => parseInt(e)));\n\t}\n\treturn result;\n};\n\nconst a = readMatrix();\nconst b = readMatrix();\n\nconst inA = [];\nconst inB = [];\n\nfor (var i = 0; i < n; i++) {\n\tfor (var j = 0; j < m; j++) {\n\t\tif (inA[i + j] === undefined) {\n\t\t\tinA[i + j] = [];\n\t\t\tinB[i + j] = [];\n\t\t}\n\t\tinA[i + j].push(a[i][j]);\n\t\tinB[i + j].push(b[i][j]);\n\t}\n}\n\nconst cmp = function(a, b) {\n\tif (a.length != b.length) {\n\t\treturn false;\n\t}\n\tfor (var i in a) {\n\t\tif (a[i] !== b[i]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n};\nvar result = true;\nfor (var i in inA) {\n\tif (inB[i] === undefined || !cmp(inA[i].sort((a, b) => a - b), inB[i].sort((a, b) => a - b))) {\n\t\tresult = false;\n\t\tbreak;\n\t}\n}\nprint(result ? \"YES\" : \"NO\");", "positive_code": [{"source_code": "var inp = readline().split(' ').map(x => parseInt(x));\nvar n = inp[0], m = inp[1];\nvar tot = n * m;\n\nvar A = new Array(),\n\tB = new Array(),\n\tadiag = new Array(),\n\tbdiag = new Array();\n\nfor(var i = 0; i < n; i++){\n\tinp = readline().split(' ').map(x => parseInt(x));\n\tA.push(inp);\n}\nfor(var i = 0; i < n; i++){\n\tinp = readline().split(' ').map(x => parseInt(x));\n\tB.push(inp);\n}\n\nconst cmp = (a, b) => (a - b);\n\n\nvar bad = false;\nfor(var col = 0; col < m; col++){\n\tvar j = col;\n\tvar i = 0;\n\tadiag = [];\n\tbdiag = [];\n\twhile(j >= 0 && i < n){\n\t\tadiag.push(A[i][j]);\n\t\tbdiag.push(B[i][j]);\n\t\tj--;\n\t\ti++;\n\t}\n\tadiag.sort(cmp);\n\tbdiag.sort(cmp);\n\tvar match = 0;\n\tadiag.forEach((x, i) => {\n\t\tif(x === bdiag[i]) match++;\n\t});\n\tif(match === adiag.length) continue;\n\telse{\n\t\tbad = true;\n\t\tbreak;\n\t}\n}\nif(bad) print(\"NO\");\nelse{\n\tfor(var row = 1; row < n; row++){\n\t\tvar j = m;\n\t\tvar i = row;\n\t\tadiag = [];\n\t\tbdiag = [];\n\t\twhile(j >= 0 && i < n){\n\t\t\tadiag.push(A[i][j]);\n\t\t\tbdiag.push(B[i][j]);\n\t\t\tj--;\n\t\t\ti++;\n\t\t}\n\t\tadiag.sort(cmp);\n\t\tbdiag.sort(cmp);\n\t\tvar match = 0;\n\t\tadiag.forEach((x, i) => {\n\t\t\tif(x === bdiag[i]) match++;\n\t\t});\n\t\tif(match === adiag.length) continue;\n\t\telse{\n\t\t\tbad = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(bad) print(\"NO\");\n\telse print(\"YES\");\n}\n"}], "negative_code": [], "src_uid": "77e2ddc4684fccd1856c93c2fc6e1ce2"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n\n_data = \"\";\nprocess.stdin.on(\"data\", function (data) {\n _data += data; \n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_data); \n});\n\nfunction processData(data) {\n const lines = data.trim().split(\"\\n\");\n for (let i = 0; i < lines[0]; i++) {\n processTC(lines, i+1);\n }\n}\n\nfunction processTC(lines, startLine) {\n const [n, m] = lines[startLine].trim().split(\" \").map(x => Number(x));\n if (m == 3 && n == 3) {\n return console.log(2, 2);\n } else if (m == 3) {\n return console.log(n, 2);\n } else if (n == 3) {\n return console.log(2, m);\n }\n return console.log(n, m);\n}", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var rows = parseInt(caseArray[0]);\r\n var columns = parseInt(caseArray[1]);\r\n var result = \"1 1\";\r\n if ((rows === 2 || rows === 3) && (columns === 2 || columns == 3))\r\n {\r\n result = \"2 2\";\r\n }\r\n print(result);\r\n}"}, {"source_code": "var rl = readline\r\nvar toN = function(x) { return +x } \r\nvar rn = function() { return toN(rl()) }\r\nvar ran = function() { \r\n\treturn (rl()\r\n\t\t.split(' ')\r\n\t\t.map(toN)\r\n\t)\r\n}\r\n\r\nvar mid = function(x) {\r\n\treturn Math.floor(x/2)+1\r\n} \r\n\r\nvar main = function() {\r\n\tvar t = rn() \r\n\tvar res = new Array(t).fill([0,0])\r\n\r\n\tres.forEach(function(x) {\r\n\t\tvar nm = ran() \r\n\t\tvar n = mid(nm[0])\r\n\t\tvar m = mid(nm[1])\r\n\t\tprint(n, m) \r\n\t}) \r\n}\r\n\r\nmain() "}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const [n, m] = readArrayInt();\r\n\r\n const arr = [];\r\n\r\n let count = 1;\r\n for (let i = 0; i < n; ++i) {\r\n const brr = [];\r\n for (let j = 0; j < m; ++j) {\r\n brr.push(count);\r\n ++count;\r\n }\r\n arr.push(brr);\r\n }\r\n\r\n let check = false;\r\n for (let i = 0; i < n; ++i) {\r\n for (let j = 0; j < m; ++j) {\r\n if (!isOk(arr, i, j)) {\r\n console.log(i + 1, j + 1);\r\n check = true;\r\n break;\r\n }\r\n }\r\n if (check) break;\r\n }\r\n\r\n if (!check) {\r\n console.log(n, m);\r\n }\r\n\r\n // # # #\r\n // # # #\r\n // # # #\r\n }\r\n}\r\n\r\n// function isOk(arr, i, j) {\r\n// if (\r\n// arr?.[i + 2]?.[j + 1] ||\r\n// arr?.[i + 2]?.[j - 1] ||\r\n// arr?.[i + -2]?.[j + 1] ||\r\n// arr?.[i - 2]?.[j - 1] ||\r\n// arr?.[i + 1]?.[j + 2] ||\r\n// arr?.[i + 1]?.[j - 2] ||\r\n// arr?.[i + -1]?.[j + 2] ||\r\n// arr?.[i - 1]?.[j - 2]\r\n// ) {\r\n// return true;\r\n// }\r\n\r\n// return false;\r\n// }\r\n\r\nfunction isOk(arr, i, j) {\r\n var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;\r\n\r\n if (\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr = arr[i + 2]) !== null &&\r\n _arr !== void 0 &&\r\n _arr[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr2 = arr[i + -2]) !== null &&\r\n _arr2 !== void 0 &&\r\n _arr2[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr3 = arr[i + 2]) !== null &&\r\n _arr3 !== void 0 &&\r\n _arr3[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr4 = arr[i - 2]) !== null &&\r\n _arr4 !== void 0 &&\r\n _arr4[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr5 = arr[i + 1]) !== null &&\r\n _arr5 !== void 0 &&\r\n _arr5[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr6 = arr[i + -1]) !== null &&\r\n _arr6 !== void 0 &&\r\n _arr6[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr7 = arr[i + 1]) !== null &&\r\n _arr7 !== void 0 &&\r\n _arr7[j - 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr8 = arr[i - 1]) !== null &&\r\n _arr8 !== void 0 &&\r\n _arr8[j - 2])\r\n ) {\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}, {"source_code": "var toN = x => +x\r\n\r\nclass Input {\r\n\tconstructor(data) {\r\n\t\tthis.lines = data.split(/\\r?\\n/)\r\n\t\tthis.index = 0\r\n\t} \r\n\r\n\treadL() {\r\n\t\treturn this.lines[this.index++]\r\n\t} \r\n\r\n\treadN() {\r\n\t\treturn toN(this.readL())\r\n\t}\r\n\r\n\treadAr() {\r\n\t\treturn this.readL().split(' ')\r\n\t} \r\n\r\n\treadArN() {\r\n\t\treturn this.readAr().map(toN)\r\n\t}\r\n} \r\n\r\n/*var createInput = (data) => {\r\n\tvar lines = data.split(/\\r?\\n/)\r\n\tvar index = 0;\r\n\t\r\n\tvar readL = () => lines[index++]\r\n\tvar readN = () => toN(readL()) \r\n\tvar readAr = () => readL().split(' ') \r\n\tvar readArN = () => readAr().map(toN)\r\n\r\n\treturn {\r\n\t\treadL, readN, readAr, readArN\r\n\t} \r\n} \r\n*/\r\nvar input = async () => new Promise(r=>{\r\n\tvar data = '' \r\n\tprocess.stdin.on('data', chunk=>data+=chunk)\r\n\tprocess.stdin.on('end', () => r(new Input(data))) \r\n}) \r\n\r\nvar mid = x => (x-x%2)/2+1\r\n\r\nvar main = async () => {\r\n\tvar inp = await input() \r\n\tvar t = inp.readN() \r\n\tvar res = new Array(t).fill(0).map(()=>inp.readArN())\r\n\tres.forEach(([n, m]) => console.log(mid(n), mid(m))) \r\n}\r\n\r\nmain() "}, {"source_code": "var createInput = (data) => {\r\n\tvar lines = data.replace(/\\r/g, '').split('\\n')\r\n\tvar index = 0;\r\n\t\r\n\tvar toN = x => +x\r\n\tvar readL = () => lines[index++]\r\n\tvar readN = () => toN(readL()) \r\n\tvar readAr = () => readL().split(' ') \r\n\tvar readArN = () => readAr().map(toN)\r\n\r\n\treturn {\r\n\t\treadL, readN, readAr, readArN\r\n\t} \r\n} \r\n\r\nvar input = async () => new Promise(r=>{\r\n\tvar data = '' \r\n\tprocess.stdin.on('data', chunk=>data+=chunk)\r\n\tprocess.stdin.on('end', () => r(createInput(data))) \r\n}) \r\n\r\nvar mid = x => (x-x%2)/2+1\r\n\r\nvar main = async () => {\r\n\tvar {readN, readArN} = await input() \r\n\tvar t = readN() \r\n\tvar res = new Array(t).fill(0).map(readArN)\r\n\tres.forEach(([n, m]) => console.log(mid(n), mid(m))) \r\n}\r\n\r\nmain() "}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n // const arr = readLine().split(' ').map(p => +p);\r\n const l_c = readLine().split(' ').map(p => +p);\r\n let result = myFunc(l_c[0], l_c[1]);\r\n // console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(l, c){\r\n\r\n let lr = Math.ceil(l/2);\r\n let cr = Math.ceil(c/2);\r\n console.log(lr, cr);\r\n \r\n\r\n}"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, m) => {\r\n \r\n if( n == 1 || m == 1) return [n,m].join(' ') // all are isolated\r\n else if( n <= 2 && m <= 2) return [n,m].join(' ') // all are isolated\r\n else if( n == 3 && m == 3) return [2,2].join(' ') // only 2,2 is isolated\r\n else if( n > 3 && m > 3) return [1,1].join(' ') // none are isolated\r\n else {\r\n let x = Math.floor(n/2) + 1\r\n let y = Math.floor(m/2) + 1\r\n return [x,y].join(' ')\r\n }\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n \r\n let testcases = parseInt( readline() )\r\n while(testcases--){\r\n \r\n let arr = readline().split(' ').map(Number)\r\n let n = arr[0]\r\n let m = arr[1]\r\n\r\n console.log( getSolution(n,m) )\r\n }\r\n \r\n}\r\n// Driver Function Ends //"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n m = rn();\r\n if (n === 1 || m === 1) return `1 1`;\r\n if (n === 2) return `2 ${Math.ceil(m / 2)}`;\r\n if (m === 2) return `${Math.ceil(n / 2)} 2`;\r\n return `2 2`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const [n, m] = readArrayInt();\r\n\r\n const arr = [];\r\n\r\n let count = 1;\r\n for (let i = 0; i < n; ++i) {\r\n const brr = [];\r\n for (let j = 0; j < m; ++j) {\r\n brr.push(2000);\r\n ++count;\r\n }\r\n arr.push(brr);\r\n }\r\n\r\n let check = false;\r\n for (let i = 0; i < n; ++i) {\r\n for (let j = 0; j < m; ++j) {\r\n if (!isOk(arr, i, j)) {\r\n console.log(i + 1, j + 1);\r\n check = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (!check) {\r\n console.log(n, m);\r\n }\r\n\r\n // # # #\r\n // # # #\r\n // # # #\r\n }\r\n}\r\n\r\n// function isOk(arr, i, j) {\r\n// if (\r\n// arr?.[i + 2]?.[j + 1] ||\r\n// arr?.[i + 2]?.[j - 1] ||\r\n// arr?.[i + -2]?.[j + 1] ||\r\n// arr?.[i - 2]?.[j - 1] ||\r\n// arr?.[i + 1]?.[j + 2] ||\r\n// arr?.[i + 1]?.[j - 2] ||\r\n// arr?.[i + -1]?.[j + 2] ||\r\n// arr?.[i - 1]?.[j - 2]\r\n// ) {\r\n// return true;\r\n// }\r\n\r\n// return false;\r\n// }\r\n\r\nfunction isOk(arr, i, j) {\r\n var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;\r\n\r\n if (\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr = arr[i + 2]) !== null &&\r\n _arr !== void 0 &&\r\n _arr[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr2 = arr[i + -2]) !== null &&\r\n _arr2 !== void 0 &&\r\n _arr2[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr3 = arr[i + 2]) !== null &&\r\n _arr3 !== void 0 &&\r\n _arr3[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr4 = arr[i - 2]) !== null &&\r\n _arr4 !== void 0 &&\r\n _arr4[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr5 = arr[i + 1]) !== null &&\r\n _arr5 !== void 0 &&\r\n _arr5[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr6 = arr[i + -1]) !== null &&\r\n _arr6 !== void 0 &&\r\n _arr6[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr7 = arr[i + 1]) !== null &&\r\n _arr7 !== void 0 &&\r\n _arr7[j - 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr8 = arr[i - 1]) !== null &&\r\n _arr8 !== void 0 &&\r\n _arr8[j - 2])\r\n ) {\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const [n, m] = readArrayInt();\r\n\r\n const arr = [];\r\n\r\n let count = 1;\r\n for (let i = 0; i < n; ++i) {\r\n const brr = [];\r\n for (let j = 0; j < m; ++j) {\r\n brr.push(count);\r\n ++count;\r\n }\r\n arr.push(brr);\r\n }\r\n\r\n let check = false;\r\n for (let i = 0; i < n; ++i) {\r\n for (let j = 0; j < m; ++j) {\r\n if (!isOk(arr, i, j)) {\r\n console.log(i + 1, j + 1);\r\n check = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (!check) {\r\n console.log(n, m);\r\n }\r\n\r\n // # # #\r\n // # # #\r\n // # # #\r\n }\r\n}\r\n\r\n// function isOk(arr, i, j) {\r\n// if (\r\n// arr?.[i + 2]?.[j + 1] ||\r\n// arr?.[i + -2]?.[j + 1] ||\r\n// arr?.[i + 2]?.[j - 1] ||\r\n// arr?.[i - 2]?.[j - 1] ||\r\n// arr?.[i + 1]?.[j + 2] ||\r\n// arr?.[i + -1]?.[j + 2] ||\r\n// arr?.[i + 1]?.[j - 2] ||\r\n// arr?.[i - 1]?.[j - 2]\r\n// ) {\r\n// return true;\r\n// }\r\n\r\n// return false;\r\n// }\r\n\r\nfunction isOk(arr, i, j) {\r\n var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;\r\n\r\n if (\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr = arr[i + 2]) !== null &&\r\n _arr !== void 0 &&\r\n _arr[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr2 = arr[i + -2]) !== null &&\r\n _arr2 !== void 0 &&\r\n _arr2[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr3 = arr[i + 2]) !== null &&\r\n _arr3 !== void 0 &&\r\n _arr3[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr4 = arr[i - 2]) !== null &&\r\n _arr4 !== void 0 &&\r\n _arr4[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr5 = arr[i + 1]) !== null &&\r\n _arr5 !== void 0 &&\r\n _arr5[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr6 = arr[i + -1]) !== null &&\r\n _arr6 !== void 0 &&\r\n _arr6[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr7 = arr[i + 1]) !== null &&\r\n _arr7 !== void 0 &&\r\n _arr7[j - 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr8 = arr[i - 1]) !== null &&\r\n _arr8 !== void 0 &&\r\n _arr8[j - 2])\r\n ) {\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const [n, m] = readArrayInt();\r\n\r\n const arr = [];\r\n\r\n let count = 1;\r\n for (let i = 0; i < n; ++i) {\r\n const brr = [];\r\n for (let j = 0; j < m; ++j) {\r\n brr.push(count);\r\n ++count;\r\n }\r\n arr.push(brr);\r\n }\r\n\r\n for (let i = 0; i < n; ++i) {\r\n for (let j = 0; j < m; ++j) {\r\n if (!isOk(arr, i, j)) {\r\n console.log(i + 1, j + 1);\r\n return;\r\n }\r\n }\r\n }\r\n console.log(n, m);\r\n\r\n // # # #\r\n // # # #\r\n // # # #\r\n }\r\n}\r\n\r\n// function isOk(arr, i, j) {\r\n// if (\r\n// arr?.[i + 2]?.[j + 1] ||\r\n// arr?.[i + -2]?.[j + 1] ||\r\n// arr?.[i + 2]?.[j - 1] ||\r\n// arr?.[i - 2]?.[j - 1] ||\r\n// arr?.[i + 1]?.[j + 2] ||\r\n// arr?.[i + -1]?.[j + 2] ||\r\n// arr?.[i + 1]?.[j - 2] ||\r\n// arr?.[i - 1]?.[j - 2]\r\n// ) {\r\n// return true;\r\n// }\r\n\r\n// return false;\r\n// }\r\n\r\nfunction isOk(arr, i, j) {\r\n var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;\r\n\r\n if (\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr = arr[i + 2]) !== null &&\r\n _arr !== void 0 &&\r\n _arr[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr2 = arr[i + -2]) !== null &&\r\n _arr2 !== void 0 &&\r\n _arr2[j + 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr3 = arr[i + 2]) !== null &&\r\n _arr3 !== void 0 &&\r\n _arr3[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr4 = arr[i - 2]) !== null &&\r\n _arr4 !== void 0 &&\r\n _arr4[j - 1]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr5 = arr[i + 1]) !== null &&\r\n _arr5 !== void 0 &&\r\n _arr5[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr6 = arr[i + -1]) !== null &&\r\n _arr6 !== void 0 &&\r\n _arr6[j + 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr7 = arr[i + 1]) !== null &&\r\n _arr7 !== void 0 &&\r\n _arr7[j - 2]) ||\r\n (arr !== null &&\r\n arr !== void 0 &&\r\n (_arr8 = arr[i - 1]) !== null &&\r\n _arr8 !== void 0 &&\r\n _arr8[j - 2])\r\n ) {\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}], "src_uid": "e6753e3f71ff13cebc1aaf04d3d2106b"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(n => parseInt(n));\r\n arr.sort((a,b) => a - b);\r\n let mindiff = arr[arr.length - 1] - arr[0] + 2;\r\n for(let i = 1; i < arr.length; i++) {\r\n mindiff = Math.min(mindiff, arr[i] - arr[i-1]);\r\n }\r\n const printbest = function(pos) {\r\n rl.output.write(arr[pos + 1]+ '');\r\n for(let i = pos + 2; i (a - b));\r\n if (n <= 2) {\r\n console.log(arr.join(\" \"));\r\n return;\r\n }\r\n let idx = -1;\r\n let min = Number.MAX_SAFE_INTEGER;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i + 1] - arr[i] < min) {\r\n idx = i;\r\n min = arr[i + 1] - arr[i];\r\n }\r\n }\r\n\r\n let ans = [];\r\n let p = 0;\r\n for (let i = idx + 1; i < n; i++) {\r\n ans[p++] = arr[i];\r\n }\r\n\r\n for (let i = 0; i <= idx; i++) {\r\n ans[p++] = arr[i];\r\n }\r\n\r\n console.log(ans.join(\" \"));\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let min = Infinity,\r\n s,\r\n e;\r\n for (let i = 0; i < n - 1; i++) {\r\n let d = arr[i + 1] - arr[i];\r\n if (d < min) {\r\n min = d;\r\n s = i;\r\n e = i + 1;\r\n }\r\n }\r\n let ans = [];\r\n ans.push(arr[s]);\r\n let ind = e + 1;\r\n for (let i = 0; i < n - 2; i++, ind++) ans.push(arr[ind % n]);\r\n ans.push(arr[e]);\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = Number.POSITIVE_INFINITY;\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet h = rna();\r\n\r\n\t\th.sort((x, y) => x - y);\r\n\r\n\t\tlet k = 0;\r\n\t\tfor (let i = 1; i < n - 1; i++) {\r\n\t\t\tif (h[i + 1] - h[i] < h[k + 1] - h[k])\r\n\t\t\t\tk = i;\r\n\t\t}\r\n\r\n\t\tans = [h[k], ...h.slice(k + 2, n), ...h.slice(0, k), h[k + 1]];\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\t\t\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = Number.POSITIVE_INFINITY;\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet h = rna();\r\n\r\n\t\th.sort((x, y) => x - y);\r\n\r\n\t\tlet dif = INF, idx;\r\n\t\tfor (let i = 0; i < n - 1; i++) {\r\n\t\t\tif (h[i + 1] - h[i] < dif) {\r\n\t\t\t\tdif = h[i + 1] - h[i];\r\n\t\t\t\tidx = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet i = idx;\r\n\t\tans = [h[i], ...h.slice(i + 2, n), ...h.slice(0, i), h[i + 1]];\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\t\t\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n arr.sort((a, b) => a - b)\n\n let min = Infinity\n let p\n for (var i = 1; i < arr.length; i++) {\n const diff = arr[i] - arr[i - 1]\n if (i === 1 || diff < min) {\n min = diff\n p = i\n }\n }\n return [arr[p - 1]]\n .concat(arr.slice(p + 1))\n .concat(arr.slice(0, p - 1))\n .concat([arr[p]])\n .join(' ')\n}\n"}, {"source_code": "var matr = 'haha';\r\n\r\nfunction create(str) {\r\n var hahaIndexArr = [];\r\n for (var i = 0; i < str.length; i++) {\r\n var hasWrong = false;\r\n for (var j = 0; j < matr.length; j++) {\r\n if (str[i + j] !== matr[j]) {\r\n hasWrong = true;\r\n break;\r\n }\r\n }\r\n if (!hasWrong) {\r\n hahaIndexArr.push(i);\r\n }\r\n }\r\n if (hahaIndexArr.length === 0) {\r\n if (str.length < 8) {\r\n return [str, -1, str];\r\n }\r\n return [str.substr(0, 4), 0, str.substr(str.length - 4, 0)];\r\n }\r\n var preff = str.substr(0, Math.min(4, hahaIndexArr[0])) || 'ha';\r\n var suff = str.substr(Math.max(hahaIndexArr[hahaIndexArr.length - 1] + 4, str.length - 4)) || 'ha';\r\n return [preff, hahaIndexArr.length, suff];\r\n}\r\nfunction summ(a, b) {\r\n var createMiddle = create(a[2] + b[0]);\r\n if (a[1] === -1 && b[1] === -1) {\r\n return createMiddle;\r\n }\r\n var preff = a[1] === -1 ? createMiddle[0] : a[0];\r\n var suff = b[1] === -1 ? createMiddle[2] : b[2];\r\n var asum = a[1] === -1 ? 0 : a[1];\r\n var bsum = b[1] === -1 ? 0 : b[1];\r\n var midSum = createMiddle[1] === -1 ? 0 : createMiddle[1];\r\n return [preff, asum + bsum + midSum, suff];\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read())\r\n var arr = readArray(Number);\r\n arr.sort(sortF);\r\n if (n === 2) {\r\n write(arr.join(' '));\r\n return;\r\n }\r\n var closest = 1;\r\n for (var i = 2; i < n; i++) {\r\n if (arr[i] - arr[i - 1] < arr[closest] - arr[closest - 1]) {\r\n closest = i;\r\n }\r\n }\r\n var ans = [];\r\n for (var i = closest; i < n; i++) {\r\n ans.push(arr[i]);\r\n }\r\n for (var i = 0; i < closest; i++) {\r\n ans.push(arr[i]);\r\n }\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(n => parseInt(n));\r\n arr.sort();\r\n let mindiff = arr[arr.length - 1] - arr[0] + 2;\r\n for(let i = 1; i < arr.length; i++) {\r\n mindiff = Math.min(mindiff, arr[i] - arr[i-1]);\r\n }\r\n const printbest = function(pos) {\r\n rl.output.write(arr[pos + 1]+ '');\r\n for(let i = pos + 2; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(n => parseInt(n));\r\n arr.sort();\r\n let mindiff = arr[arr.length - 1] - arr[0] + 2;\r\n for(let i = 1; i < arr.length; i++) {\r\n mindiff = Math.min(mindiff, arr[i] - arr[i-1]);\r\n }\r\n const printbest = function(pos) {\r\n rl.output.write(arr[pos + 1]+ '');\r\n for(let i = pos + 2; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(n => parseInt(n));\r\n arr.sort();\r\n let mindiff = arr[arr.length - 1] - arr[0] + 2;\r\n for(let i = 1; i < arr.length; i++) {\r\n mindiff = Math.min(mindiff, arr[i] - arr[i-1]);\r\n }\r\n const printbest = function(pos) {\r\n rl.output.write(arr[pos + 1]+ '');\r\n for(let i = pos + 2; i ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const arr = (await getLine()).split(' ').map(n => parseInt(n));\r\n arr.sort();\r\n let mindiff = arr[arr.length - 1] - arr[0] + 2;\r\n for(let i = 1; i < arr.length; i++) {\r\n mindiff = Math.min(mindiff, arr[i] - arr[i-1]);\r\n }\r\n const printbest = function(pos) {\r\n rl.output.write(arr[pos + 1]+ '');\r\n for(let i = pos + 2; i {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n arr.sort((a, b) => a - b);\r\n let obj = {},\r\n flag = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] === arr[i + 1]) {\r\n flag = false;\r\n obj[i] = i;\r\n obj[i + 1] = i + 1;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n obj[0] = 0;\r\n obj[1] = 1;\r\n }\r\n let [s, e] = Object.keys(obj);\r\n let ans = [];\r\n ans.push(arr[obj[s]]);\r\n let ind = obj[e] + 1;\r\n for (let i = 0; i < n - 2; i++, ind++) ans.push(arr[ind % n]);\r\n ans.push(arr[obj[e]]);\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n arr.sort((a, b) => a - b)\n\n let min = Infinity\n let p\n for (var i = 1; i < arr.length; i++) {\n const diff = arr[i] - arr[i - 1]\n if (i === 1 || diff < min) {\n min = diff\n p = i\n }\n }\n return [arr[p - 1]]\n .concat(arr.slice(p + 1))\n .concat(arr.slice(0, p - 1))\n .concat([arr[p]])\n}\n"}], "src_uid": "3342e71884677534b7a126f89d441585"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n let previous = Array(as[0] + 1).fill('a')\n console.log(previous.join(''))\n for (let i = 0; i < n; i++) {\n let nextCharCode = previous[as[i]].charCodeAt(0) + 1\n if (nextCharCode > 122) {\n nextCharCode = 97\n }\n previous = [...previous.slice(0, as[i]), ...Array(i === n - 1 ? 1 : Math.max(0, as[i + 1] - as[i] + 1)).fill(String.fromCharCode(nextCharCode))]\n console.log(previous.join(''))\n }\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let str = \"a\".repeat(50).split(\"\");\n\n console.log(str.join(\"\"));\n for (let i = 0; i < len; i++) {\n for (let j = arr[i]; j < 50; j++) {\n if (str[j] === \"a\") str[j] = \"b\";\n else str[j] = \"a\";\n }\n console.log(str.join(\"\"));\n }\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let charCode = 97;\n\n if (arr[0] === 0) {\n console.log(`${String.fromCharCode(charCode)}`.repeat(1));\n charCode = (charCode + 1) % 123;\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(arr[0]));\n }\n for (let i = 0; i < len - 1; i++) {\n let max = Math.max(arr[i], arr[i + 1]);\n max = max === 0 ? 1 : max;\n\n if (arr[i] === 0 && i > 0) {\n charCode = (charCode + 1) % 123;\n console.log(`${String.fromCharCode(charCode)}`.repeat(max));\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(max));\n }\n }\n if (arr[len - 1] === 0) {\n charCode = (charCode + 1) % 123;\n console.log(`${String.fromCharCode(charCode)}`.repeat(1));\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(arr[len - 1]));\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let charCode = 97;\n\n if (arr[0] === 0) {\n console.log(`${String.fromCharCode(charCode)}`.repeat(1));\n charCode++;\n charCode = charCode > 123 ? 97 : charCode;\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(arr[0]));\n }\n for (let i = 0; i < len - 1; i++) {\n let max = Math.max(arr[i], arr[i + 1]);\n max = max === 0 ? 1 : max;\n\n if (arr[i] === 0 && i > 0) {\n charCode++;\n charCode = charCode > 123 ? 97 : charCode;\n console.log(`${String.fromCharCode(charCode)}`.repeat(max));\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(max));\n }\n }\n if (arr[len - 1] === 0) {\n charCode++;\n charCode = charCode > 123 ? 97 : charCode;\n console.log(`${String.fromCharCode(charCode)}`.repeat(1));\n } else {\n console.log(`${String.fromCharCode(charCode)}`.repeat(arr[len - 1]));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n let previous = Array(as[0] + 1).fill('a')\n console.log(previous.join(''))\n for (let i = 0; i < n; i++) {\n let nextCharCode = previous[as[i]].charCodeAt(0) + 1\n if (nextCharCode > 122) {\n nextCharCode = 97\n }\n previous = [...previous.slice(0, as[i]), ...Array(i === n - 1 ? 0 : Math.max(0, as[i + 1] - as[i] + 1)).fill(String.fromCharCode(nextCharCode))]\n console.log(previous.join(''))\n }\n }\n}\n"}], "src_uid": "6983823efdc512f8759203460cd6bb4c"} {"source_code": "//var input = readline()\nvar t = Number(readline())\n\nvar str = readline()\nvar s = str.split('').sort().join('')\nprint(s)", "positive_code": [{"source_code": "readline();\nvar word = readline().split('').sort().join('');\nprint(word);"}, {"source_code": " var n = parseInt(readline());\n var s = readline();\n print(s.split('').sort().join(''));"}], "negative_code": [], "src_uid": "8616ede6867c8aacde986a123ec8a921"} {"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1, -1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n default: s = 0\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})", "positive_code": [{"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1, -1).forEach(line => {\n let [n, s] = line.split(' ')\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1, -1).forEach(line => {\n let [n, s] = line.split(' ')\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n default: s = 0\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n if (s == 'rat') s = 0\n else if (s == 'woman') s = 1\n else if (s == 'child') s = 1\n else if (s == 'man') s = 2\n else s = 3\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "print(function(n) {\n\n\tvar i, j,\n\t\ta = [],\n\t\tans = [],\n\t\tr = {\n\t\t\trat: 0,\n\t\t\twoman: 1,\n\t\t\tchild: 1,\n\t\t\tman: 2,\n\t\t\tcaptain: 3\n\t\t};\n\n\tfor (i = 0; i < n; i++) {\n\t\ta.push(readline().split(' '));\n\t\ta[i][1] = r[a[i][1]];\n\t}\n\n\tfor (i = 0; i <= 3; i++)\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (a[j][1] === i) ans.push(a[j][0]);\n\n\treturn ans.join('\\n');\n\n}(+readline()));\n"}, {"source_code": "var n = parseInt(readline())\nvar t = []\nfor(var i = 0; i < n; i++){\n var s = readline();\n t.push(s);\n}\nt = t.map(function(x){\n return x.split(' '); \n});\nvar G = [/rat/, /woman|child/, /^man/, /captain/];\nG.forEach(function(reg){\n t.filter(function(x){\n return reg.test(x[1]);\n }).forEach(function(x){\n print(x[0]);\n });\n});"}, {"source_code": ";(function () {\n\n print(function (n) {\n var s = [];\n while (n--) s.push(readline().split(' '));\n n = s.length;\n\n var r = [];\n for (var i = 0; i < n; i++) if (s[i][1] === 'rat') r.push(s[i][0]);\n for (var i = 0; i < n; i++) if (s[i][1] === 'child' || s[i][1] === 'woman') r.push(s[i][0]);\n for (var i = 0; i < n; i++) if (s[i][1] === 'man') r.push(s[i][0]);\n for (var i = 0; i < n; i++) if (s[i][1] === 'captain') r.push(s[i][0]);\n\n return r.join('\\n');\n }(+readline()));\n\n}.call(this));\n"}, {"source_code": "'use strict'\n\nlet n = +readline()\nlet ps = [[], [], [], []]\n\nfor (let i = 0; i < n; i++) {\n let p = readline().split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n }\n ps[s].push(n)\n}\n\nlet r = []\n\nfor (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n}\n\nprint(r.join('\\n'))"}, {"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1).filter(Boolean).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n default: s = 0\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "var n = parseInt(readline());\n\nvar data = [[], [], [], []];\nvar res = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar inp = readline().split(' ');\n\tswitch(inp[1]) {\n\t\tcase 'rat':\n\t\t\tdata[0].push(inp[0]);\n\t\t\tbreak;\n\t\tcase 'woman':\n\t\tcase 'child':\n\t\t\tdata[1].push(inp[0]);\n\t\t\tbreak;\n\t\tcase 'man':\n\t\t\tdata[2].push(inp[0]);\n\t\t\tbreak;\n\t\tcase 'captain':\n\t\t\tdata[3].push(inp[0]);\n\t\t\tbreak;\n\t}\n}\n\ndata.forEach(function(arr){\n\tres = res.concat(arr);\n});\n\nres.forEach(function(name) {\n\tprint(name);\n});\n"}, {"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1).filter(Boolean).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n default: s = 3\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}], "negative_code": [{"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n if (s == 'rat') s = 0\n else s = 1\n ps[s].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n if (s == 'rat') s = 0\n else if (s == 'woman') s = 1\n else s = 2\n ps[s].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n if (s == 'rat') s = 0\n else if (s == 'woman') s = 1\n else if (s == 'child') s = 2\n else s = 3\n ps[s].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = 0\n s = (s + 1) % 4\n ps[s % 4].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach((line, s) => {\n ps[s % 4].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split('\\r\\n').slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n if (s == 'rat') s = 0\n else if (s == 'woman') s = 1\n else if (s == 'child') s = 1\n else if (s == 'man') s = 2\n else s = 3\n ps[s].push(line)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "const eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n default: s = 0\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n input = input.split('\\r\\n').slice(1)\n console.log(input.join('\\n'))\n})"}, {"source_code": "'use strict'\n\nconst eol = require('os').EOL\n\nlet input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n let ps = [[], [], [], []]\n\n input.split(eol).slice(1).forEach(line => {\n let p = line.split(' ')\n let n = p[0]\n let s = p[1]\n switch (s) {\n case 'rat': s = 0; break\n case 'woman': s = 1; break\n case 'child': s = 1; break\n case 'man': s = 2; break\n case 'captain': s = 3; break\n default: s = 0\n }\n ps[s].push(n)\n })\n\n let r = []\n\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < ps[i].length; j++) {\n r.push((ps[i][j]))\n }\n }\n\n console.log(r.join('\\n'))\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n console.log(input)\n})"}, {"source_code": ";(function () {\n\n print(function (n) {\n var s = [];\n while (n--) s.push(readline().split(' '));\n return s.sort(function (a, b) {\n a = typeToNumber(a[1]);\n b = typeToNumber(b[1]);\n return b - a;\n }).map(function (e) {\n return e[0];\n }).join('\\n');\n }(+readline()));\n\n function typeToNumber (type) {\n switch (type) {\n case 'rat': return 100; break;\n case 'child':\n case 'woman': return 50; break;\n case 'man': return 35; break;\n case 'captain': return 0; break;\n }\n }\n\n}.call(this));\n"}], "src_uid": "753113fa5130a67423f2e205c97f8017"} {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, a) {\r\n let t = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] >= 0) {\r\n t = i;\r\n break;\r\n }\r\n }\r\n if (t === -1) return 0;\r\n const dp = new Array(n).fill(0);\r\n const heap = new Heap((a, b) => a - b);\r\n let sum = 0;\r\n for (let i = t; i < n; i++) {\r\n var _dp;\r\n if (a[i] < 0) heap.push(a[i]);\r\n sum += a[i];\r\n dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n while (sum < 0) {\r\n sum -= heap.pop();\r\n dp[i]--;\r\n }\r\n }\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n res = Math.max(res, dp[i]);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "// PriorityQueue implementated using array based binary heap\r\n// PriorityQueue methods\r\n// push(...values) \r\n// \tpeek()\r\n// pop()\r\n// size() \r\n// replace(value)\r\n\r\nclass PriorityQueue {\r\n\r\n\tconstructor(comparator = (a, b) => a > b) {\r\n\t\tthis.top = 0;\r\n\t\tthis._heap = [];\r\n\t\tthis._comparator = comparator;\r\n\t}\r\n\tsize() {\r\n\t\treturn this._heap.length;\r\n\t}\r\n\tisEmpty() {\r\n\t\treturn this.size() == 0;\r\n\t}\r\n\tpeek() {\r\n\t\treturn this._heap[this.top];\r\n\t}\r\n\tpush(...values) {\r\n\t\tvalues.forEach(value => {\r\n\t\t\t\tthis._heap.push(value);\r\n\t\t\t\tthis._siftUp();\r\n\t\t\t\t});\r\n\t\treturn this.size();\r\n\t}\r\n\tpop() {\r\n\t\tconst poppedValue = this.peek();\r\n\t\tconst bottom = this.size() - 1;\r\n\t\tif (bottom > this.top) {\r\n\t\t\tthis._swap(this.top, bottom);\r\n\t\t}\r\n\t\tthis._heap.pop();\r\n\t\tthis._siftDown();\r\n\t\treturn poppedValue;\r\n\t}\r\n\treplace(value) {\r\n\t\tconst replacedValue = this.peek();\r\n\t\tthis._heap[this.top] = value;\r\n\t\tthis._siftDown();\r\n\t\treturn replacedValue;\r\n\t}\r\n\t_greater(i, j) {\r\n\t\treturn this._comparator(this._heap[i], this._heap[j]);\r\n\t}\r\n\t_swap(i, j) {\r\n\t\t[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n\t}\r\n\t_siftUp() {\r\n\t\tconst parent = i => ((i + 1) >>> 1) - 1;\r\n\t\tlet node = this.size() - 1;\r\n\t\twhile (node > this.top && this._greater(node, parent(node))) {\r\n\t\t\tthis._swap(node, parent(node));\r\n\t\t\tnode = parent(node);\r\n\t\t}\r\n\t}\r\n\t_siftDown() {\r\n\t\tconst left = i => (i << 1) + 1;\r\n\t\tconst right = i => (i + 1) << 1;\r\n\t\tlet node = this.top;\r\n\t\twhile (\r\n\t\t\t\t(left(node) < this.size() && this._greater(left(node), node)) ||\r\n\t\t\t\t(right(node) < this.size() && this._greater(right(node), node))\r\n\t\t\t ) {\r\n\t\t\tlet maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);\r\n\t\t\tthis._swap(node, maxChild);\r\n\t\t\tnode = maxChild;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\nvar dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst a = rna();\r\n\r\n\tlet health = 0, used = 0;\r\n\tconst q = new PriorityQueue((a, b) => a > b);\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tif (a[i] >= 0) {\r\n\t\t\thealth += a[i];\r\n\t\t\tused++;\r\n\t\t} else {\r\n\t\t\ta[i] = -a[i];\r\n\t\t\tif (health - a[i] >= 0) {\r\n\t\t\t\thealth -= a[i];\r\n\t\t\t\tq.push(a[i]);\r\n\t\t\t\tused++;\r\n\t\t\t} else {\r\n\t\t\t\tif (a[i] < q.peek()) {\r\n\t\t\t\t\thealth += q.pop() - a[i];\r\n\t\t\t\t\tq.push(a[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(used);\r\n}\r\n\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/28/21 night\r\n\r\nconst solve = (n, a) => {\r\n let pq = new MinPriorityQueue({ priority: x => x });\r\n let res = sum = 0;\r\n for (const e of a) {\r\n sum += e;\r\n res++;\r\n if (e < 0) {\r\n pq.enqueue(e);\r\n while (sum < 0) {\r\n sum -= pq.dequeue().element;\r\n res--;\r\n }\r\n }\r\n }\r\n pr(res);\r\n};\r\n\r\nclass HeapNode {\r\n constructor(key, value) {\r\n this._key = key;\r\n this._value = value;\r\n }\r\n\r\n getKey() {\r\n return this._key;\r\n }\r\n\r\n getValue() {\r\n return this._value;\r\n }\r\n}\r\n\r\nconst isNumber = (n) => typeof n === 'number';\r\nconst isNoneEmptyString = (s) => typeof s === 'string' && s.length;\r\nconst isNoneNullObject = (o) => typeof o === 'object' && o !== null;\r\nconst isNoneEmptyArray = (a) => Array.isArray(a) && a.length > 0;\r\n\r\nclass Heap {\r\n constructor(nodes) {\r\n this._nodes = Array.isArray(nodes) ? nodes : [];\r\n this._leaf = null;\r\n }\r\n\r\n _getLeftChildIndex(parentIndex) {\r\n return (parentIndex * 2) + 1;\r\n }\r\n\r\n _getRightChildIndex(parentIndex) {\r\n return (parentIndex * 2) + 2;\r\n }\r\n\r\n _getParentIndex(childIndex) {\r\n return Math.floor((childIndex - 1) / 2);\r\n }\r\n\r\n _getLastIndex() {\r\n return this._nodes.length - 1;\r\n }\r\n\r\n _swap(i, j) {\r\n const temp = this._nodes[i];\r\n this._nodes[i] = this._nodes[j];\r\n this._nodes[j] = temp;\r\n }\r\n\r\n _compareChildrenOf(parentIndex) {\r\n const leftChildIndex = this._getLeftChildIndex(parentIndex);\r\n const rightChildIndex = this._getRightChildIndex(parentIndex);\r\n const size = this.size();\r\n if (leftChildIndex >= size && rightChildIndex >= size) return -1;\r\n if (leftChildIndex >= size) return rightChildIndex;\r\n if (rightChildIndex >= size) return leftChildIndex;\r\n return this._compareChildren(leftChildIndex, rightChildIndex);\r\n }\r\n\r\n _heapifyUp() {\r\n let childIndex = this._getLastIndex();\r\n let parentIndex = this._getParentIndex(childIndex);\r\n while (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n childIndex = parentIndex;\r\n parentIndex = this._getParentIndex(childIndex);\r\n }\r\n }\r\n\r\n _heapifyDown() {\r\n let parentIndex = 0;\r\n let childIndex = this._compareChildrenOf(parentIndex);\r\n while (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n parentIndex = childIndex;\r\n childIndex = this._compareChildrenOf(parentIndex);\r\n }\r\n }\r\n\r\n _heapifyDownUntil(index) {\r\n let parentIndex = 0;\r\n let leftChildIndex = 1;\r\n let rightChildIndex = 2;\r\n let childIndex;\r\n while (leftChildIndex < index) {\r\n childIndex = this._compareChildrenBefore(\r\n index,\r\n leftChildIndex,\r\n rightChildIndex\r\n );\r\n if (this._shouldSwap(childIndex, parentIndex)) {\r\n this._swap(childIndex, parentIndex);\r\n }\r\n parentIndex = childIndex;\r\n leftChildIndex = this._getLeftChildIndex(parentIndex);\r\n rightChildIndex = this._getRightChildIndex(parentIndex);\r\n }\r\n }\r\n\r\n _clone(HeapType) {\r\n return new HeapType(this._nodes.slice());\r\n }\r\n\r\n sort() {\r\n for (let i = this._getLastIndex(); i > 0; i -= 1) {\r\n this._swap(0, i);\r\n this._heapifyDownUntil(i);\r\n }\r\n return this._nodes;\r\n }\r\n\r\n insert(key, value) {\r\n const newNode = new HeapNode(key, value);\r\n this._nodes.push(newNode);\r\n this._heapifyUp();\r\n return newNode;\r\n }\r\n\r\n root() {\r\n if (this.isEmpty()) return null;\r\n return this._nodes[0];\r\n }\r\n\r\n leaf() {\r\n return this._leaf;\r\n }\r\n\r\n extractRoot() {\r\n if (this.isEmpty()) return null;\r\n const root = this.root();\r\n this._nodes[0] = this._nodes[this._getLastIndex()];\r\n this._nodes.pop();\r\n this._heapifyDown();\r\n if (root === this._leaf) {\r\n if (this.isEmpty()) {\r\n this._leaf = null;\r\n } else {\r\n this._leaf = this.root();\r\n }\r\n }\r\n return root;\r\n }\r\n\r\n size() {\r\n return this._nodes.length;\r\n }\r\n\r\n isEmpty() {\r\n return this.size() === 0;\r\n }\r\n\r\n clear() {\r\n this._nodes = [];\r\n this._leaf = null;\r\n }\r\n\r\n static _heapify(items, HeapType) {\r\n if (!isNoneEmptyArray(items)) return null;\r\n const heap = new HeapType();\r\n items.forEach((item) => {\r\n if (isNumber(item) || isNoneEmptyString(item)) {\r\n heap.insert(item);\r\n } else if (isNoneNullObject(item) &&\r\n (isNumber(item.key) || isNoneEmptyString(item.key))) {\r\n heap.insert(item.key, item.value);\r\n }\r\n });\r\n return heap;\r\n }\r\n}\r\n\r\nclass MinHeap extends Heap {\r\n _getMinChildIndex(leftChildIndex, rightChildIndex) {\r\n const leftChild = this._nodes[leftChildIndex];\r\n const rightChild = this._nodes[rightChildIndex];\r\n if (leftChild.getKey() < rightChild.getKey()) {\r\n return leftChildIndex;\r\n }\r\n return rightChildIndex;\r\n }\r\n\r\n _getMinChildIndexBefore(index, leftChildIndex, rightChildIndex) {\r\n const leftChild = this._nodes[leftChildIndex];\r\n const rightChild = this._nodes[rightChildIndex];\r\n if (rightChild.getKey() < leftChild.getKey() && rightChildIndex < index) {\r\n return rightChildIndex;\r\n }\r\n return leftChildIndex;\r\n }\r\n\r\n _shouldSwap(childIndex, parentIndex) {\r\n if (childIndex < 0 || childIndex >= this.size()) return false;\r\n if (parentIndex < 0 || parentIndex >= this.size()) return false;\r\n const child = this._nodes[childIndex];\r\n const parent = this._nodes[parentIndex];\r\n return child.getKey() < parent.getKey();\r\n }\r\n\r\n _compareChildren(leftChildIndex, rightChildIndex) {\r\n return this._getMinChildIndex(leftChildIndex, rightChildIndex);\r\n }\r\n\r\n _compareChildrenBefore(index, leftChildIndex, rightChildIndex) {\r\n return this._getMinChildIndexBefore(index, leftChildIndex, rightChildIndex);\r\n }\r\n\r\n insert(key, value) {\r\n const newNode = super.insert(key, value);\r\n if (this._leaf === null || key > this._leaf.getKey()) {\r\n this._leaf = newNode;\r\n }\r\n return newNode;\r\n }\r\n\r\n clone() {\r\n return super._clone(MinHeap);\r\n }\r\n\r\n static heapify(items) {\r\n return super._heapify(items, MinHeap);\r\n }\r\n}\r\n\r\nclass PriorityQueue {\r\n constructor(options = {}) {\r\n const {\r\n priority\r\n } = options;\r\n if (priority !== undefined && typeof priority !== 'function') {\r\n throw new Error('invalid priority callback');\r\n }\r\n this._getPriority = typeof priority === 'function' ? priority : null;\r\n }\r\n\r\n size() {\r\n return this._heap.size();\r\n }\r\n\r\n isEmpty() {\r\n return this._heap.isEmpty();\r\n }\r\n\r\n front() {\r\n if (this.isEmpty()) return null;\r\n const first = this._heap.root();\r\n return {\r\n priority: first.getKey(),\r\n element: first.getValue()\r\n };\r\n }\r\n\r\n back() {\r\n if (this.isEmpty()) return null;\r\n const last = this._heap.leaf();\r\n return {\r\n priority: last.getKey(),\r\n element: last.getValue()\r\n };\r\n }\r\n\r\n enqueue(element, p) {\r\n if (p && Number.isNaN(+p)) {\r\n throw new Error('invalid priority number');\r\n }\r\n if (Number.isNaN(+p) && this._getPriority === null) {\r\n throw new Error('missing priority number or constructor callback');\r\n }\r\n const priority = !Number.isNaN(+p) ? p : this._getPriority(element);\r\n this._heap.insert(priority, element);\r\n }\r\n\r\n dequeue() {\r\n if (this.isEmpty()) return null;\r\n const first = this._heap.extractRoot();\r\n return {\r\n priority: first.getKey(),\r\n element: first.getValue()\r\n };\r\n }\r\n\r\n toArray() {\r\n return this._heap\r\n .clone()\r\n .sort()\r\n .map((n) => ({\r\n priority: n.getKey(),\r\n element: n.getValue()\r\n }))\r\n .reverse();\r\n }\r\n\r\n clear() {\r\n this._heap.clear();\r\n }\r\n}\r\n\r\nclass MinPriorityQueue extends PriorityQueue {\r\n constructor(options) {\r\n super(options);\r\n this._heap = new MinHeap();\r\n }\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[1]);\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [], "src_uid": "b4a4448af5b61fe5a8467a8d0e12fba8"} {"source_code": "function readInts() {\n return readline().split(' ').map(function (v) { return parseInt(v); });\n}\nfunction solve(n, m, a) {\n var _a, _b;\n var _c = [0, 0, 0, 0], on = _c[0], off = _c[1], xon = _c[2], xoff = _c[3];\n var max = m;\n var i = n - 1;\n while (i >= -1) {\n var ai = i >= 0 ? a[i] : 0;\n var l = max - ai;\n _a = [l + xoff, xon], xon = _a[0], xoff = _a[1];\n if (l > 1) {\n var _d = [l - 1 + on, l - 1 + off], nxon = _d[0], nxoff = _d[1];\n if (nxon > xon)\n xon = nxon;\n if (nxoff > xoff)\n xoff = nxoff;\n }\n _b = [l + off, on], on = _b[0], off = _b[1];\n max = ai;\n // console.log({i,max,l,on,off,xon,xoff});\n i--;\n }\n return xon > on ? xon : on;\n}\n// function show(n: number, m: number, a: number[]) {\n// console.log(n, m, a, '-->', solve(n, m, a));\n// }\n// show(3, 10, [4, 6, 7]);\n// show(2, 12, [1, 10]);\n// show(2, 7, [3, 4]);\nvar _a = readInts(), n = _a[0], m = _a[1];\nvar a = readInts();\nprint(solve(n, m, a));\n", "positive_code": [{"source_code": "\n var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var m = tmp[1];\n\n var a = [0].concat(readline().split(' ').map(x => parseInt(x)), m);\n n += 2;\n var s = [0];\n for(var i = 1; i < n; i += 1) {\n if(i % 2 === 1) {\n s[i] = s[i - 1] + a[i] - a[i - 1];\n } else {\n s[i] = s[i - 1];\n }\n }\n var sr = [a[1]];\n for(var i = 1; i < n; i += 1) {\n if(i % 2 === 0) {\n sr[i] = sr[i - 1] + a[i] - a[i - 1];\n } else {\n sr[i] = sr[i - 1];\n }\n }\n var mx = -1;\n mx = Math.max(mx, s[n - 1]);\n for(var i = 0; i < n; i += 1) {\n if(i % 2 === 0) {\n if(i !== 0) {\n if(a[i - 1] !== a[i] - 1) {\n var res = s[i - 1];\n res += a[i] - a[i - 1] - 1;\n res += sr[n - 1] - sr[i];\n mx = Math.max(mx, res);\n // console.log(a[i - 1] + 1, res);\n }\n }\n } else {\n if(a[i - 1] + 1 !== a[i]) {\n var res = s[i - 1];\n res += a[i] - a[i - 1] - 1;\n res += sr[n - 1] - sr[i];\n mx = Math.max(mx, res);\n // console.log(a[i - 1] + 1, res);\n }\n }\n }\n // console.log(a);\n // console.log(s);\n // console.log(sr);\n print(mx);\n "}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\nfunction main()\n{\n const [N,M]=readLine().trim().split(' ').map(x=>{return +(x);});\n let A=readLine().trim().split(' ').map(x=>{return +(x);});\n A.unshift(0);\n A.push(M);\n let zer=[],zerc=0,on=[],onc=0;\n //console.log(A);\n for(let i=0;i<=N;i++)\n {\n if(i&1)\n {\n on.push(A[i+1]-A[i]);\n ++onc;\n if(i!=1)\n {\n on[onc-1]+=on[onc-2];\n }\n }\n else\n {\n zer.push(A[i+1]-A[i]);\n ++zerc;\n if(i!==0)\n {\n zer[zerc-1]+=zer[zerc-2];\n }\n }\n }\n zer.unshift(0);\n on.unshift(0);\n ++zerc;\n ++onc;\n //console.log(zer);\n //console.log(on);\n let m=zer[zerc-1];\n for(let i=0;i<=N;++i)\n {\n if(A[i+1]-A[i]>1)\n {\n let t=zer[Math.floor((i+1)/2)]+A[i+1]-A[i]-1-on[Math.floor((i+1)/2)]+on[onc-1];\n //console.log(t);\n if(t>m)\n {\n m=t;\n }\n t=zer[Math.floor((i+1)/2)]+1-on[Math.floor((i+1)/2)]+on[onc-1];\n //console.log(t);\n if(t>m)\n {\n m=t;\n }\n }\n }\n console.log(m);\n}\n\n\n"}], "negative_code": [], "src_uid": "085b03a45fec13b759c3bd334888caf5"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const [a, b] = arr[j].split(' ').map(a => parseInt(a))\n\n if((a + b) % 3 == 0 && a >= b && a <= 2 * b) {\n console.log('YES')\n }\n else if((a + b) % 3 == 0 && a <= b && b <= 2 * a) {\n console.log('YES')\n }\n else {\n console.log('NO')\n }\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), div = 0, valid = true;\n \n if((a+b)%3 !== 0) valid = false;\n else if((a+b)/3 > a || (a+b)/3 > b) valid = false;\n \n print(valid ? 'YES' : 'NO');\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === b || (a%2 === 0 && b%2 === 0) || (a%2 !== 0 && b%2 !== 0)) {\n print('NO');\n \n } else {\n if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a>b) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b>=a && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } else if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n }\n }\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === 0 && b === 0) {\n print('YES');\n \n } else if(a === b || (a%2 === 0 && b%2 === 0) || (a%2 !== 0 && b%2 !== 0) || a === 0 || b === 0) {\n print('NO');\n \n } else {\n if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n } else if(a_cpy === 0 || b_cpy === 0) {\n print('NO');\n } else if(a_cpy>b_cpy) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b_cpy>=a_cpy && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } \n }\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === 0 && b === 0) {\n print('YES');\n \n } else if(a === b || (a%2 === 0 && b%2 === 0) || (a%2 !== 0 && b%2 !== 0) || a === 0 || b === 0) {\n print('NO');\n \n } else {\n if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n } else if(a_cpy>b_cpy) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b_cpy>=a_cpy && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } \n }\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === 0 && b === 0) {\n print('YES');\n \n } else if(a === b || (a%2 === 0 && b%2 === 0) || (a%2 !== 0 && b%2 !== 0) || a === 0 || b === 0) {\n print('NO');\n \n } else {\n if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a>b) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b>=a && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } else if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n }\n }\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), div = 0, valid = true;\n \n if(a===0 && b===0) {\n valid = true;\n \n } else if(a===0 || b===0) {\n valid = false;\n \n } else if(a>b) {\n div = Math.floor(a/2);\n \n if(div < b) {\n a -= 2*div;\n b -= div;\n \n if(a!==1 || b!==2) valid = false;\n \n } else if(div === b && a%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n \n } else {\n div = Math.floor(b/2);\n \n if(div < a) {\n b -= 2*div;\n a -= div;\n \n if(b!==1 || a!==2) valid = false;\n \n } else if(div === a && b%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), div = 0, valid = true;\n \n if(a===0 && b===0) {\n valid = true;\n \n } else if(a===0 || b===0 || a===b) {\n valid = false;\n \n } else if(a>b) {\n div = Math.floor(a/2);\n \n if(div < b) {\n a -= 2*div;\n b -= div;\n \n if(a!==1 || b!==2) valid = false;\n \n } else if(div === b && a%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n \n } else {\n div = Math.floor(b/2);\n \n if(div < a) {\n b -= 2*div;\n a -= div;\n \n if(b!==1 || a!==2) valid = false;\n \n } else if(div === a && b%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), div = 0, valid = true;\n \n if(a===0 || b===0 || a===b) {\n valid = false;\n \n } else if(a>b) {\n div = Math.floor(a/2);\n \n if(div < b) {\n a -= 2*div;\n b -= div;\n \n if(a!==1 || b!==2) valid = false;\n \n } else if(div === b && a%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n \n } else {\n div = Math.floor(b/2);\n \n if(div < a) {\n b -= 2*div;\n a -= div;\n \n if(b!==1 || a!==2) valid = false;\n \n } else if(div === a && b%2 === 0) {\n valid = true;\n \n } else {\n valid = false;\n }\n }\n \n print(valid ? 'YES' : 'NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === 0 && b === 0) {\n print('YES');\n \n } else if(a === b || (a%2 !== 0 && b%2 !== 0) || a === 0 || b === 0) {\n print('NO');\n \n } else {\n if(a%2 === 0 && b%2 === 0) {\n if(a>b) {\n a_cpy -= 2;\n b_cpy -= 1;\n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n }\n \n } else if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n } else if(a_cpy === 0 || b_cpy === 0) {\n print('NO');\n } else if(a_cpy>b_cpy) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b_cpy>=a_cpy && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } \n }\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nwhile(t--) {\n var inp = readline().split(' ');\n var a = parseInt(inp[0], 10), b = parseInt(inp[1], 10), a_cpy = a, b_cpy = b;\n \n if(a === 0 && b === 0) {\n print('YES');\n \n } else if(a === b || (a%2 === 0 && b%2 === 0) || (a%2 !== 0 && b%2 !== 0)) {\n print('NO');\n \n } else {\n if(a%2 === 0) {\n a_cpy -= 2;\n b_cpy -= 1;\n \n } else {\n a_cpy -= 1;\n b_cpy -= 2;\n \n }\n \n if(a>b) {\n if(a_cpy%b_cpy === 0) print('YES');\n else print('NO');\n \n } else if(b>=a && (a_cpy !== 0 && b_cpy !== 0)) {\n if(b_cpy%a_cpy === 0) print('YES');\n else print('NO');\n \n } else if(a_cpy === 0 && b_cpy === 0) {\n print('YES');\n \n }\n }\n}"}], "src_uid": "0a720a0b06314fde783866b47f35af81"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const cnt = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [i, num] of a.entries()) {\r\n cnt[num - 1].push(i);\r\n }\r\n const res = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let t = -1,\r\n ans = 0,\r\n p = cnt[i][0] & 1 ^ 1;\r\n for (let j = 0; j < cnt[i].length; j++) {\r\n const num = cnt[i][j];\r\n if ((num & 1) !== p) {\r\n p ^= 1;\r\n ans++;\r\n } else if (t === -1) {\r\n t = j;\r\n }\r\n }\r\n if (t !== -1) {\r\n p = cnt[i][t] & 1 ^ 1;\r\n let ans1 = 0;\r\n for (let j = t; j < cnt[i].length; j++) {\r\n const num = cnt[i][j];\r\n if ((num & 1) !== p) {\r\n p ^= 1;\r\n ans1++;\r\n }\r\n }\r\n ans = Math.max(ans, ans1);\r\n }\r\n res[i] = ans;\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let res = new Array(n).fill(0);\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]]) obj[arr[i]].push(i);\r\n else {\r\n let k = [i];\r\n obj[arr[i]] = k;\r\n }\r\n res[arr[i] - 1] = 1;\r\n }\r\n for (let i of Object.keys(obj)) {\r\n let k = obj[i];\r\n if (k.length > 1) {\r\n for (let j = 0; j < k.length - 1; j++) {\r\n if ((k[j + 1] - k[j]) % 2 === 1) res[i - 1] += 1;\r\n }\r\n }\r\n }\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = parseInt(readLine(), 10);\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n const arr = readLine().split(' ').map(p => +p);\r\n myFunc(n, arr);\r\n }\r\n}\r\n \r\n \r\n\r\nfunction myFunc(n, arr){\r\n let resp = new Array(n).fill(0);\r\n let last = new Array(n);\r\n\r\n for(let j = 0; j < n; j++){\r\n if(last[arr[j]-1] == undefined){\r\n last[arr[j]-1] = j;\r\n resp[arr[j]-1]++;\r\n }\r\n }\r\n\r\n for(let i = 1; i < n; i++){\r\n if( (i-1-last[arr[i]-1])%2 == 0 ){\r\n resp[arr[i]-1]++;\r\n }\r\n last[arr[i]-1] = i;\r\n }//for1\r\n\r\n console.log(resp.join(' '));\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "c63640fd70e0268f03cb4eec18540f3a"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [rows, cols] = readline().split(' ').map(Number);\r\n\r\n for (let row = 0; row < rows; row++) {\r\n let line = '';\r\n for (let col = 0; col < cols; col++) {\r\n if (col !== 0) {\r\n line += ' ';\r\n }\r\n if (row % 4 === 0 || row % 4 === 3) {\r\n line += (col % 4 === 0 || col % 4 === 3) ? '0' : '1';\r\n } else {\r\n line += (col % 4 === 0 || col % 4 === 3) ? '1' : '0';\r\n }\r\n }\r\n output(line);\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 1; i < m; i++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[0][i] = res[0][i - 1] ^ 1;\r\n } else {\r\n res[0][i] = res[0][i - 1];\r\n }\r\n }\r\n res[1][0] = 1;\r\n for (let i = 1; i < m; i++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[1][i] = res[1][i - 1] ^ 1;\r\n } else {\r\n res[1][i] = res[1][i - 1];\r\n }\r\n }\r\n for (let i = 2; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[i][j] = res[i - 1][j] ^ 1;\r\n } else {\r\n res[i][j] = res[i - 1][j];\r\n }\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n for (let t = 0; t < testcases; t++) {\r\n const [m, n] = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const nums = [];\r\n for (let i = 0; i < parseInt(n / 4); i++) nums.push(1, 0, 0, 1);\r\n if (n % 4 >= 1) nums.push(1);\r\n if (n % 4 >= 2) nums.push(0);\r\n if (n % 4 >= 3) nums.push(0);\r\n\r\n const numsInv = [];\r\n for (let i = 0; i < n; i++) numsInv.push((nums[i] + 1) % 2);\r\n\r\n const matrix = [];\r\n for (let i = 0; i < parseInt(m / 4); i++) {\r\n matrix.push([...nums]);\r\n matrix.push([...numsInv]);\r\n matrix.push([...numsInv]);\r\n matrix.push([...nums]);\r\n }\r\n\r\n if (m % 4 >= 1) matrix.push([...nums]);\r\n if (m % 4 >= 2) matrix.push([...numsInv]);\r\n if (m % 4 >= 3) matrix.push([...numsInv]);\r\n\r\n console.log(matrix.map((el) => el.join(\" \")).join(\"\\n\"));\r\n }\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 1; i < m; i++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[0][i] = res[0][i - 1] ^ 1;\r\n } else {\r\n res[0][i] = res[0][i - 1];\r\n }\r\n }\r\n res[1][0] = 1;\r\n for (let i = 1; i < m; i++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[0][i] = res[0][i - 1] ^ 1;\r\n } else {\r\n res[0][i] = res[0][i - 1];\r\n }\r\n }\r\n for (let i = 2; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[i][j] = res[i - 1][j] ^ 1;\r\n } else {\r\n res[i][j] = res[i - 1][j];\r\n }\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n if (n === 2 && m === 2) return `0 1\\n1 0`;\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 2; i < m; i += 4) {\r\n res[0][i] = res[0][i - 1] = 1;\r\n }\r\n res[1][0] = 1;\r\n res[1][m - 1] = 1;\r\n for (let i = 4; i < m; i += 4) res[1][i] = res[1][i - 1] = 1;\r\n for (let i = 2; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[i][j] = res[i - 1][j] ^ 1;\r\n } else {\r\n res[i][j] = res[i - 1][j];\r\n }\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n if (n === 2 && m === 2) return `0 0\\n0 0`;\r\n const res = Array.from({\r\n length: n\r\n }, () => new Array(m).fill(0));\r\n for (let i = 2; i < m; i += 4) {\r\n res[0][i] = res[0][i - 1] = 1;\r\n }\r\n res[1][0] = 1;\r\n res[1][m - 1] = 1;\r\n for (let i = 4; i < m; i += 4) res[1][i] = res[1][i - 1] = 1;\r\n for (let i = 2; i < n; i++) {\r\n for (let j = 0; j < m; j++) {\r\n if ((i ^ 1) === i - 1) {\r\n res[i][j] = res[i - 1][j] ^ 1;\r\n } else {\r\n res[i][j] = res[i - 1][j];\r\n }\r\n }\r\n }\r\n return res.map(arr => arr.join(' ')).join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n for (let t = 0; t < testcases; t++) {\r\n const [m, n] = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const nums = [];\r\n for (let i = 0; i < parseInt(n / 4); i++) nums.push(1, 0, 0, 1);\r\n if (n % 4 >= 1) nums.push(1);\r\n if (n % 4 >= 2) nums.push(0);\r\n if (n % 4 >= 3) nums.push(0);\r\n\r\n const numsInv = [];\r\n for (let i = 0; i < n; i++) numsInv.push((nums[i] + 1) % 2);\r\n\r\n const matrix = [];\r\n for (let i = 0; i < parseInt(m / 4); i++) {\r\n matrix.push([...nums]);\r\n matrix.push([...numsInv]);\r\n matrix.push([...numsInv]);\r\n matrix.push([...nums]);\r\n }\r\n\r\n if (n % 4 >= 1) matrix.push([...nums]);\r\n if (n % 4 >= 2) matrix.push([...numsInv]);\r\n if (n % 4 >= 3) matrix.push([...numsInv]);\r\n\r\n // for (let i = 0; i < m; i++) matrix.push([...nums]);\r\n // for (let i = 1; i < m; i += 2) {\r\n // for (let j = 0; j < n; j++) {\r\n // matrix[i][j] = (matrix[i][j] + 1) % 2;\r\n // }\r\n // }\r\n\r\n console.log(matrix.map((el) => el.join(\" \")).join(\"\\n\"));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n for (let t = 0; t < testcases; t++) {\r\n const [m, n] = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const nums = [];\r\n for (let i = 0; i < parseInt(n / 4); i++) nums.push(1, 0, 0, 1);\r\n if (n % 4 >= 1) nums.push(1);\r\n if (n % 4 >= 2) nums.push(0);\r\n if (n % 4 >= 3) nums.push(0);\r\n\r\n const matrix = [];\r\n for (let i = 0; i < m; i++) matrix.push([...nums]);\r\n for (let i = 1; i < m; i += 2) {\r\n for (let j = 0; j < n; j++) {\r\n matrix[i][j] = (matrix[i][j] + 1) % 2;\r\n }\r\n }\r\n\r\n console.log(matrix.map((el) => el.join(\" \")).join(\"\\n\"));\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nvar arr = \"\";\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const testcases = parseInt(arr.shift());\r\n for (let t = 0; t < testcases; t++) {\r\n const [m, n] = arr[t].split(\" \").map((el) => parseInt(el));\r\n\r\n const matrix = [];\r\n for (let i = 0; i < m; i++) matrix.push([]);\r\n\r\n for (let i = 0; i < m; i += 2) {\r\n let start = 0;\r\n for (let j = 0; j < n; j++) {\r\n matrix[i][j] = (start + 1) % 2;\r\n start = (start + 1) % 2;\r\n }\r\n }\r\n\r\n for (let i = 1; i < m; i += 2) {\r\n let start = 1;\r\n for (let j = 0; j < n; j++) {\r\n matrix[i][j] = (start + 1) % 2;\r\n start = (start + 1) % 2;\r\n }\r\n }\r\n\r\n console.log(matrix.map((el) => el.join(\" \")).join(\"\\n\"));\r\n }\r\n});\r\n"}], "src_uid": "b7d40e7fc4f277cc801b59a21a16dfc1"} {"source_code": "var n = readline().split(/\\s/gi).map(Number),\n\t\t\tm = n[1], k = n[2], n = n[0],\n\t\t\tsoldiers = [], fedor, maxLength= 0, count = 0;\n\n\t\tfor(var i = 0; i <= m; i++)\t{\n\t\t\tvar iSoldier = readline();\n\n\t\t\tiSoldier = getBinaryNum(iSoldier);\n\n\t\t\tif(iSoldier.length > maxLength)\tmaxLength = iSoldier.length;\n\n\t\t\tsoldiers.push(iSoldier);\n\t\t}\n\n\t\tfedor = setFillChars(soldiers[m], '0', maxLength, 'left');\n\t\tsoldiers = soldiers.slice(0, m);\n\t\tsoldiers.forEach(function(a)\t{\n\t\t\tvar kCount = 0;\n\n\t\t\ta = setFillChars(a, '0', maxLength, 'left');\n\n\t\t\tfor(var i = 0; i < maxLength; i++)\t{\n\t\t\t\tif(a[i] != fedor[i])\tkCount++;\n\n\t\t\t\tif(kCount > k)\tbreak;\n\t\t\t}\n\n\t\t\tif(kCount <= k)\tcount++;\n\t\t});\n\n\t\tprint(count);\n\n\t\tfunction getBinaryNum(num)\t{\n\t\t\treturn Number(num).toString(2);\n\t\t};\n\n\t\tfunction setFillChars(str, fill_char, length, dir)\t{\n\t\t\tfill_char = fill_char.slice(0, 1);\n\t\t\tlength = parseInt(length);\n\t\t\tvar str = str.toString();\n\t\t\tvar _temp = \"\";\n\t\t\tfor(var i=0; i+x)\nm=T[1],k=T[2]\nA=[]\nfor (var i=0;i<=m;++i) {\n A.push(+readline())\n}\nr=0\nfor (var i=0; i input.push(line));\n\n\nreadLine.on('close', () => {\n const [n, m, k] = input[0].split(' ').map(x => parseInt(x));\n let f = parseInt(input[m+1]);\n let answer = 0;\n\n\n for (let i = 1; i <= m; i += 1) {\n let num = parseInt(input[i]);\n let numCount = 0;\n\n let copyF = f;\n\n for (let j = 0 ; j < n; j += 1) {\n if ( (num & 1) !== (copyF & 1) ) { numCount += 1; }\n num = num >>> 1;\n copyF = copyF >>> 1;\n }\n\n if ( numCount <= k) { \n answer += 1;\n }\n }\n\n console.log(answer);\n}); "}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function p(){return s[i++]}function c(){return p().split(\" \").map((t=>parseFloat(t)))}function d(){return p().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=c();for(;e>0;)t(),e--}))},readline:p,nextNumbers:c,nextNumbersMatrix:function(t){let e=[];for(let r=0;rt[0])),u=n.pop();const s=t=>{let e=u,r=0;for(;e>0||t>0;)e%2!=t%2&&r++,e/=2,t/=2,e=Math.floor(e),t=Math.floor(t);return r};o.default.debug(n),o.default.debug(n.map(s)),o.default.put(n.map(s).filter((t=>t<=r)).length)}))},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], m = +input[1], k = +input[2], x = [],\ncnt = 0, friends = 0;\nfor(i = 0; i < m; i++){\n\tinput = +readline();\n\tx.push(input.toString(\"2\").split(\"\").reverse());\n}\ninput = +readline();\nf = input.toString(\"2\").split(\"\").reverse();\n\nfor(i = 0; i < m; i++){\n\tfor(j = 0; j < Math.max(x[i].length,f.length); j++){\n\t\tif(x[i][j] == undefined){\n\t\t\tx[i][j] = 0;\n\t\t}\n\t\tif(f[j] == undefined){\n\t\t\tf[j] = 0;\n\t\t}\n\t\tif((x[i][j] == 1 && f[j] != 1) || (f[j] == 1 && x[i][j] != 1)){\n\t\t\tcnt++;\n\t\t}\n\t}\n\tif(cnt <= k){\n\t\tfriends++;\n\t}\n\tcnt = 0;\n}\n\nprint(friends);"}, {"source_code": "var n, m, k, my;\nvar count = 0, oneCount;\nvar input = readline();\nn = input.split(\" \")[0];\nm = input.split(\" \")[1];\nk = input.split(\" \")[2];\nvar others = new Array(m);\n\nfor (var i = 0; i < m; i++) {\n\tothers[i] = readline();\n}\nmy = readline();\n\nfor (var i = 0; i < m; i++) {\n\tbinaryString = Number(others[i]^my).toString(2);\n\toneCount = 0;\n\tfor (var j = 0; j < binaryString.length; j++) {\n\t\tif (binaryString.split(\"\")[j] == '1') {\n\t\t\toneCount++;\n\t\t}\n\t}\n\n\tif (oneCount <= k) {\n\t\tcount++;\n\t}\n\n}\nwrite(count);\n\n"}, {"source_code": "var myArr = []\nvar input = readline().split(' ').map((val)=>{\n\treturn parseInt(val);\n})\nfor (var i = 0; i < input[1] + 1; i++){\n\tmyArr.push(parseInt(readline()));\n}\nvar friend = myArr.pop();\nvar count = 0;\nmyArr.forEach((val)=>{\n\tif ((val^friend).toString(2).split(/[0]*/).filter((val)=>{\n\t\treturn val != \"\";\n\t}).length <= input[2]){\n\t\tcount += 1;\n\t}\n})\nprint(count)"}, {"source_code": ";(function () {\n\tprint(function (n, m, k) {\n\t\tvar a = [], t = 0; m++;\n\t\twhile (m--) a.push(+readline());\n\t\tm = a.splice(-1)[0].toString(2);\n\t\twhile (m.length !== n) m = '0' + m;\n\t\ta.forEach(function (e) {\n\t\t\tvar r = 0; e = e.toString(2);\n\t\t\twhile (e.length !== n) e = '0' + e;\n\t\t\tfor (var i = 0, _i = e.length; i < _i; i++) {\n\t\t\t\tif (e[i] !== m[i]) {\n\t\t\t\t\tr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (r <= k) {\n\t\t\t\tt++\n\t\t\t}\n\t\t});\n\n\t\treturn t;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , cnt1 , cnt2;\n res = 0;\n a = this.arr[ this.m ];\n cnt1 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.brr[ cnt1++ ] = b;\n a = Math.floor( a / 2 );\n }\n for( i = 0 ; i < this.m ; i++ ) {\n a = this.arr[ i ];\n cnt2 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.crr[ cnt2++ ] = b;\n a = Math.floor( a / 2 );\n }\n c = 0;\n for( j = 0 ; j < Math.max( cnt1 , cnt2 ) ; j++ ) {\n if( this.brr[ j ] != this.crr[ j ] ) {\n c++;\n }\n }\n for( j = 0 ; j < Math.max( cnt1 , cnt2 ) ; j++ ) {\n this.crr[ j ] = 0 ;\n }\n if( c <= this.k ) {\n res++;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.m + 1 ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var l1=readline().split(' ');\nvar n=parseInt(l1[0]),m=parseInt(l1[1]),k=parseInt(l1[2]);\nvar cnt=[],cnt2=[];\nfor(var i=0;i<21;i++) cnt2[i]=cnt[i]=0;\nvar ar=[];\nvar x;\nfor(var i=0;i> 1) & 0x55555555)\n n = (n & 0x33333333) + ((n >> 2) & 0x33333333)\n return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24\n }\nfor (var i=0; i< m ; i++){\n if(bitCount(a[m] ^ a[i]) <= k)\n friend++;\n} \nwrite(friend);"}], "negative_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\n\nreadLine.on('close', () => {\n const [n, m, k] = input[0].split(' ').map(x => parseInt(x));\n let f = parseInt(input[m+1]);\n let answer = 0;\n\n\n for (let i = 1; i <= m; i += 1) {\n let num = parseInt(input[i]);\n let numCount = 0;\n\n let copyF = f;\n for (let j = 0; j < n; j += 1) {\n if (num & 1 !== copyF & 1) { numCount += 1}\n num = num >>> 1;\n copyF = copyF >>> 1;\n }\n\n if ( numCount <= k) answer += 1;\n }\n\n console.log(answer);\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\n\nreadLine.on('close', () => {\n const [n, m, k] = input[0].split(' ').map(x => parseInt(x));\n let f = parseInt(input[m+1]);\n let fCount = 0; let answer = 0;\n\n for (let i = 0; i < n; i += 1) {\n if (f & 1 === 1) { fCount += 1; }\n f = f >>> 1;\n }\n\n\n for (let i = 1; i <= m; i += 1) {\n let num = parseInt(input[m]);\n let numCount = 0;\n for (let j = 0; j < n; j += 1) {\n if (num & 1 === 1) { numCount += 1}\n num = num >>> 1;\n }\n\n if ( Math.abs(numCount - fCount) <= 1) answer += 1;\n }\n\n console.log(answer);\n}); "}, {"source_code": "var n, m, k, my;\nvar count = 0, oneCount;\nvar input = readline();\nn = input.split(\" \")[0];\nm = input.split(\" \")[1];\nk = input.split(\" \")[2];\nvar others = new Array(m);\n\nfor (var i = 0; i < m; i++) {\n\tothers[i] = readline();\n}\nmy = readline();\n\nfor (var i = 0; i < m; i++) {\n\tvar binaryString = Number(others[i]).toString(2);\n\toneCount = 0;\n\tfor (var j = 0; j < binaryString.length; j++) {\n\t\tif (binaryString.split(\"\")[j] == '1') {\n\t\t\toneCount++;\n\t\t}\n\t}\n\n\tif (oneCount <= k) {\n\t\tcount++;\n\t}\n\n}\nwrite(count);\n\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , cnt1 , cnt2;\n res = 0;\n a = this.arr[ this.m ];\n cnt1 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.brr[ cnt1++ ] = b;\n a = Math.floor( a / 2 );\n }\n for( i = 0 ; i < this.m ; i++ ) {\n a = this.arr[ i ];\n cnt2 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.crr[ cnt2++ ] = b;\n a = Math.floor( a / 2 );\n }\n c = 0;\n for( j = 0 ; j < Math.max( cnt1 , cnt2 ) ; j++ ) {\n if( this.brr[ j ] != this.crr[ j ] ) {\n c++;\n }\n }\n if( c <= this.k ) {\n res++;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.m + 1 ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , cnt1 , cnt2;\n res = 0;\n a = this.arr[ this.m ];\n cnt1 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.brr[ cnt1++ ] = b;\n a = Math.floor( a / 2 );\n }\n for( i = 0 ; i < this.m ; i++ ) {\n a = this.arr[ i ];\n cnt2 = 0;\n while( a > 0 ) {\n b = a % 2;\n this.crr[ cnt2++ ] = b;\n a = Math.floor( a / 2 );\n }\n c = 0;\n for( j = 0 ; j < Math.max( cnt1 , cnt2 ) ; j++ ) {\n if( this.brr[ j ] != this.crr[ j ] ) {\n c++;\n }\n }\n for( j = 0 ; j < Math.max( cnt1 , cnt2 ) ; j++ ) {\n this.brr[ j ] = 0 ;\n this.crr[ j ] = 0 ;\n }\n if( c <= this.k ) {\n res++;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.m + 1 ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var main = function(content, noMore)\n{\n var computeVoids, count = 0, result = 0;\n\tvar nearToBinary = function(num, countIn)\n\t{\n\t\tif (num === 0) return countIn;\n\t\telse\n\t\t\t{\n\t\t\t\tif (num % 2 === 0) countIn++;\n\t\t\t\treturn nearToBinary(Math.floor(num / 2), countIn);\n\t\t\t}\n\t}\n\tfor (var i = 0; i < content.length - 1; i++)\n\t{\n\t\tcomputeVoids = content[content.length - 1] ^ content[i];\n\t\tcomputeVoids = nearToBinary(computeVoids, count);\n\t\tif (computeVoids < noMore) result++;\n\t\tcount = 0;\n\t}\n\treturn result;\n}\n\n{\n\tvar input = readline(),\n\tarrContent = [],\n\tn,\n\tm,\n\tk;\n\tinput = input.split(' ');\n\tn = +input[0];\n\tm = +input[1];\n\tk = +input[2];\n\tfor (var i = 1; i <= m + 1; i++)\n\t{\n\t\tarrContent.push(+readline());\n\t}\n\tprint(main(arrContent, k));\n\t\n}"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer & vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n (m - sameSoldier <= k) && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i <= m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer ^ vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n n - sameSoldier <= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer & vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n m - sameSoldier <= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(' '),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i <= m; i++) {\n var line = readline();\n gamers.push(Number.parseInt(line));\n}\nvar vasya = gamers.pop();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer ^ vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n n - sameSoldier <= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer ^ vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n n - sameSoldier <= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer & vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n print(sameSoldier);\n n - sameSoldier <= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer & vasya).toString(2).split('').reduce(function (acc, curr) {\n return acc + +curr;\n }, 0);\n sameSoldier >= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _readline$split = readline().split(''),\n _readline$split2 = _slicedToArray(_readline$split, 3),\n n = _readline$split2[0],\n m = _readline$split2[1],\n k = _readline$split2[2];\n\nvar gamers = [];\nfor (var i = 0; i < m; i++) {\n var _line = readline();\n gamers.push(Number.parseInt(_line));\n}\nvar vasya = gamers.pop();\nvar line = readline();\nvar res = 0;\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (var _iterator = gamers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var gamer = _step.value;\n\n var sameSoldier = (gamer & vasya).toString(2).split().reduce(function (acc, curr) {\n return acc + curr;\n }, 0);\n sameSoldier >= k && res++;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nprint(res);"}], "src_uid": "5ebb0ee239d68ea33d9dac2d0bdd5f4e"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0];var m = k[1];var x = k[2];\n var col = Math.floor(x/n);\n if(x%n !== 0){\n col++;\n }\n var row = x % n;\n if(row === 0){\n row = n;\n }\n console.log(((row - 1) * m) + col);\n }\n});", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar x = nextInt();\r\n\t\tvar U = x % N;\r\n\t\tvar L = Math.ceil(x / N);\r\n\t\tif(U == 0){\r\n\t\t\tU = N;\r\n\t\t}\r\n\t\t//myerr({U, L});\r\n\t\tvar output = (U - 1) * M + L;\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [n, m, val] = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n });\r\n\r\n var y = (val+n-1n) / n\r\n var ymod = (val-1n) % n\r\n// console.log(x,y, val)\r\n console.log(((ymod)*m + y).toString())\r\n\r\n })\r\n}\r\n\r\n\r\n"}, {"source_code": "T = readline()\r\n\r\nwhile (T--) {\r\n a = readline().split(' ').map(x => +x)\r\n n = a[0]\r\n m = a[1]\r\n x = a[2]\r\n\r\n stolb = Math.ceil(x / n)\r\n\r\n stroka = x - (n*(stolb-1))\r\n\r\n ans = m*(stroka-1)+stolb\r\n\r\n print(ans)\r\n}"}, {"source_code": "var T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar nmx = readline().split(\" \").map(x => parseInt(x));\n\tvar n = nmx[0];\n\tvar m = nmx[1];\n\tvar x = nmx[2];\n\n\tx = x - 1;\n\n\tprint(m * (x % n) + Math.floor(x / n) + 1);\n}\n"}, {"source_code": "function getInt( num ) {\r\n return parseInt( num, 10 );\r\n}\r\n\r\nvar t = parseInt( readline(), 10 );\r\n\r\nfor ( var i = 0; i < t; i++ ) {\r\n var line1 = readline().split( ' ' ).map( getInt );\r\n //var line2 = readline().split( ' ' ).map( getIntAndInd );\r\n var sol = solution.apply(undefined, line1)\r\n print( sol );\r\n}\r\nfunction solution( n, m, x ) {\r\n x = x - 1\r\n var row = x % n;\r\n var col = (x - row) / n;\r\n\r\n var res = m*row + col;\r\n return res +1;\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n for (let i = 0; i < testCases; i++) {\r\n let [m, n, x] = input[z++].split(' ').map(t=>Number(t));\r\n let i = Math.floor((x-1)/m);\r\n let j = (x-1)%m;\r\n console.log((i+1)+(j*n));\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, m, x) => {\r\n let curRowStart = x % n;\r\n let rows;\r\n if (curRowStart > 0) {\r\n rows = (curRowStart - 1) * m;\r\n let move = (x - curRowStart) / n;\r\n pr(rows + move + 1);\r\n } else if (curRowStart == 0) {\r\n curRowStart += n;\r\n rows = (curRowStart - 1) * m;\r\n let move = (x - curRowStart) / n;\r\n pr(rows + move + 1);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n}\r\nfunction solve() {\r\n let [n, m, x]=readLine().split(\" \").map(i=> parseInt(i));\r\n x--;\r\n let col = parseInt( x / n);\r\n let row = x % n;\r\n console.log(row * m + col + 1);\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet [n, m, x] = nl.array(BigInt);\n\t\tlet a = (x + (n - 1n)) / n;\n\t\tlet b = (x - 1n) % n + 1n;\n\t\tans.push((b - 1n) * m + a);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Reading from terminal\n\nconst readline = require('readline');\n\nconst rl = readline.createInterface( {\n input: process.stdin,\n output: process.stdout\n});\nconst it = rl[Symbol.asyncIterator]();\n\n\n//Actual application\nasync function main() {\n let line = await it.next();\n const t = parseInt(line.valueOf().value);\n\n for(let testCase = 0; testCase < t; testCase++) {\n line = await it.next();\n let nmx = String(line.valueOf().value).split(' ')\n let n = parseInt(nmx[0]), m = parseInt(nmx[1]), x = parseInt(nmx[2]) - 1\n let row = x % n, col = (x / n) >> 0;\n console.log(row * m + col + 1);\n }\n}\n\nmain();\n\n\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var nmx = read().split(' ').map(BigInt);\r\n var n = nmx[0];\r\n var m = nmx[1];\r\n var x = nmx[2] - 1n;\r\n var i = x % n;\r\n var j = x / n;\r\n write(i * m + j + 1n);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n for (var i = 1; i < input.length; i++) {\r\n var [n, m, x] = input[i].split(\" \").map((a) => {\r\n return Number(a);\r\n });\r\n function byRows(n, m, x) {\r\n var row = (x - 1) % n;\r\n var col = Math.floor((x - 1) / n);\r\n return row * m + col + 1;\r\n }\r\n console.log(byRows(n, m, x));\r\n }\r\n})"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nvar input = \"\";\r\n\r\nprocess.stdin.on(\"data\", data => input += data);\r\nprocess.stdout.on(\"end\", ()=>main(input));\r\n\r\nfunction main(input){\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n for (let i = 0; i < testCases; i++) {\r\n let arr = [];\r\n let index = 0;\r\n let [m, n, x] = input[z++].split(' ').map(t=>Number(t));\r\n // let i = Math.floor(x/m);\r\n // let j = x%n;\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 0; j < m && index <= x; j++) {\r\n arr[index++] = (j * n) + (i + 1)\r\n }\r\n }\r\n console.log(arr[x-1]);\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, m, x) => {\r\n let curRowStart = x % n;\r\n let rows;\r\n if (curRowStart > 0) {\r\n rows = (curRowStart - 1) * m;\r\n let move = (x - curRowStart) / n;\r\n pr(rows + move + 1);\r\n } else if (curRowStart == 0) {\r\n pr(x);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "e519e4495c9acef4c4a614aef73cb322"} {"source_code": "'use strict'\n \nconst s = readline().split('');\nconst n = s.length;\nconst take = [].reduce.call('abcdefghijklmnopqrstuvwxyz', (r, i, j) => { r[i] = j; return r; }, {});\nconst bit = Array.from({ length: 26 }, () => Array(n + 1).fill(0))\n \nconst upd = (b, i, v) => {\n while (i <= n) { b[i] += v; i += i&-i; }\n}\n \nconst query = (b, i) => {\n let r = 0;\n while (i) { r += b[i]; i -= i&-i; }\n return r;\n}\n \nfor (let i = 0; i < n; i++) {\n upd(bit[take[s[i]]], i + 1, 1);\n}\n \nlet q = parseInt(readline());\nwhile(q--) {\n const t = readline().split(' ');\n if (t[0] === '1') {\n const j = parseInt(t[1]) - 1;\n upd(bit[take[s[j]]], j + 1, -1);\n upd(bit[take[t[2]]], j + 1, 1);\n s[j] = t[2];\n } else {\n const l = parseInt(t[1]) - 1;\n const r = parseInt(t[2]);\n write(bit.filter(b => query(b, r) > query(b, l)).length + '\\n');\n }\n}", "positive_code": [{"source_code": "'use strict'\n\nconst s = readline();\nconst q = parseInt(readline());\nconst az = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ];\nconst LEN = s.length;\nconst BIT = az.reduce((r, i) => { r[i] = Array(LEN+1).fill(0); return r; }, {});\nconst S = s.split('');\n\nconst upd = (v, w, moji) => {\n while (v < LEN + 1) {\n BIT[moji][v] += w;\n v += v & -v;\n }\n}\n\nconst getValue = (v, moji) => {\n let r = 0;\n while (v) {\n r += BIT[moji][v];\n v -= v & -v;\n }\n return r;\n}\n\nS.forEach((i, index) => upd(index + 1, 1, i));\n\nfor (let i = 0; i < q; i++) {\n const A = readline().split(' ');\n if (A[0] === '1') {\n const j = parseInt(A[1]) - 1;\n upd(j+1, -1, S[j]);\n upd(j+1, 1, A[2])\n S[j] = A[2];\n }\n else {\n const l = parseInt(A[1]) - 1;\n const r = parseInt(A[2]);\n write(az.filter(i => getValue(r, i) > getValue(l, i)).length + '\\n');\n }\n}"}, {"source_code": "'use strict'\n\n\nconst take = { a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11, m: 12, n: 13, o: 14, p: 15, q: 16, r: 17, s: 18, t: 19, u: 20, v: 21, w: 22, x: 23, y: 24, z: 25}\nconst a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ];\n\nconst s = readline().split('').map(i => take[i]);\nconst n = s.length;\nconst k = Math.ceil(Math.log2(n));\nconst m = Math.pow(2, k);\n\nconst build = (c) => {\n const t = Array(2*m).fill(0);\n for (let i = 0; i < n; i++) if (c === s[i]) t[m + i] = 1;\n for (let i = m - 1; i; i--) t[i] = t[2*i] + t[2*i + 1];\n return t;\n}\n\nconst update = (t, i, x) => {\n i += m; const d = x - t[i]; t[i] = x;\n while(i >>= 1) t[i] += d;\n}\n\nconst query = (t, l, r) => {\n l += m; r += m;\n let s = 0;\n while (l < r) {\n if (r & 1) s += t[--r]; r >>= 1;\n if (l & 1) s += t[l++]; l >>= 1;\n }\n return s\n}\n\nconst t = Array.from({ length: 26 }, (_, i) => build(i));\n\nlet q = parseInt(readline());\nwhile(q--) {\n const line = readline().split(' ');\n if (line[0] === '1') {\n const j = +line[1] - 1;\n const c = take[line[2]];\n update(t[s[j]], j, 0);\n update(t[c], j, 1);\n s[j] = c;\n } else {\n const l = parseInt(line[1]) - 1;\n const r = parseInt(line[2]);\n print(a.filter(i => query(t[i], l, r)).length);\n }\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n // console.log(fenwick)\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n // console.log(ax)\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = ax[2][0] > '9' ? ax[2][0] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n // console.log(fenwick[i], fenwick[i].queryRange(l,r))\n // console.log(l, r, fenwick[i].queryRange(l,r), i)\n // console.log(l,r, i)\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nclass IMergeStrategy {\n constructor() {}\n Execute() {\n\n }\n}\n\nclass BitwiseOrStrategy extends IMergeStrategy {\n constructor() {\n super();\n }\n Execute(left, right) {\n return left | right;\n }\n}\n\nclass SegmentTree {\n \n constructor(mergeStrategy, outOfBound, n) {\n if (!(mergeStrategy instanceof IMergeStrategy)) {\n throw new TypeError;\n }\n this._mergeStrategy = mergeStrategy;\n this._outOfBound = outOfBound;\n this.tr = new Array(n * 4);\n }\n\n Update(node, b, e, idx, x) {\n if (b == e) {\n this.tr[node] = x;\n return;\n }\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n if (idx <= mid) this.Update(left, b, mid, idx, x);\n else this.Update(right, mid + 1, e, idx, x);\n this.tr[node] = this._mergeStrategy.Execute(this.tr[left], this.tr[right]);\n }\n\n Query(node, b, e, l, r) {\n if (r < b || e < l) return this._outOfBound;\n if (b >= l && e <= r) {\n return this.tr[node];\n }\n\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n\n const p1 = this.Query(left, b, mid, l, r);\n const p2 = this.Query(right, mid + 1, e, l, r);\n\n return this._mergeStrategy.Execute(p1, p2);\n }\n}\n\nlet s;\n\nconst bitCount = (n) => {\n n = n - ((n >> 1) & 0x55555555);\n n = (n & 0x33333333) + ((n >> 2) & 0x33333333);\n return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;\n}\n\nfunction main() {\n while (s = readline()) {\n const q = parseInt(readline()); \n const n = s.length;\n const bitwiseOrStrategy = new BitwiseOrStrategy();\n const tree = new SegmentTree(bitwiseOrStrategy, 0, n);\n let ans = '';\n for (let i = 0; i < n; i++) {\n tree.Update(1, 0, n - 1, i, 1 << (s.charCodeAt(i) - 'a'.charCodeAt(0)));\n }\n for (let i = 0; i < q; i++) {\n const [ty, a, b] = readline().split(' ');\n if (ty == 1) {\n const l = parseInt(a);\n tree.Update(1, 0, n - 1, l - 1, 1 << (b.charCodeAt(0) - 'a'.charCodeAt(0)));\n } else{\n const l = parseInt(a);\n const r = parseInt(b);\n const qr = tree.Query(1, 0, n - 1, l - 1, r - 1);\n ans += bitCount(qr).toString() + '\\n';\n }\n }\n console.log(ans);\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nclass IMergeStrategy {\n constructor() {}\n Execute() {\n\n }\n}\n\nclass BitwiseOrStrategy extends IMergeStrategy {\n constructor() {\n super();\n }\n Execute(left, right) {\n return left | right;\n }\n}\n\nclass SegmentTree {\n \n constructor(mergeStrategy, outOfBound, n) {\n if (!(mergeStrategy instanceof IMergeStrategy)) {\n throw new TypeError;\n }\n this._mergeStrategy = mergeStrategy;\n this._outOfBound = outOfBound;\n this.tr = new Array(n * 4);\n }\n\n Update(node, b, e, idx, x) {\n if (b == e) {\n this.tr[node] = x;\n return;\n }\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n if (idx <= mid) this.Update(left, b, mid, idx, x);\n else this.Update(right, mid + 1, e, idx, x);\n this.tr[node] = this._mergeStrategy.Execute(this.tr[left], this.tr[right]);\n }\n\n Query(node, b, e, l, r) {\n if (r < b || e < l) return this._outOfBound;\n if (b >= l && e <= r) {\n return this.tr[node];\n }\n\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n\n const p1 = this.Query(left, b, mid, l, r);\n const p2 = this.Query(right, mid + 1, e, l, r);\n\n return this._mergeStrategy.Execute(p1, p2);\n }\n}\n\nlet s;\n\nconst bitCount = (n) => {\n n = n - ((n >> 1) & 0x55555555);\n n = (n & 0x33333333) + ((n >> 2) & 0x33333333);\n return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;\n}\n\nfunction main() {\n while (s = readline()) {\n const q = parseInt(readline()); \n const n = s.length;\n const bitwiseOrStrategy = new BitwiseOrStrategy();\n const tree = new SegmentTree(bitwiseOrStrategy, 0, n);\n for (let i = 0; i < n; i++) {\n tree.Update(1, 0, n - 1, i, 1 << (s.charCodeAt(i) - 'a'.charCodeAt(0)));\n }\n for (let i = 0; i < q; i++) {\n const [ty, a, b] = readline().split(' ');\n if (ty == 1) {\n const l = parseInt(a);\n tree.Update(1, 0, n - 1, l - 1, 1 << (b.charCodeAt(0) - 'a'.charCodeAt(0)));\n } else{\n const l = parseInt(a);\n const r = parseInt(b);\n const qr = tree.Query(1, 0, n - 1, l - 1, r - 1);\n console.log(bitCount(qr));\n }\n }\n console.error('---');\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main(); \n});\n\nclass IMergeStrategy {\n constructor() {}\n Execute() {\n\n }\n}\n\nclass BitwiseOrStrategy extends IMergeStrategy {\n constructor() {\n super();\n }\n Execute(left, right) {\n return left | right;\n }\n}\n\nclass SegmentTree {\n \n constructor(mergeStrategy, outOfBound, n) {\n if (!(mergeStrategy instanceof IMergeStrategy)) {\n throw new TypeError;\n }\n this._mergeStrategy = mergeStrategy;\n this._outOfBound = outOfBound;\n this.tr = new Array(n * 4);\n }\n\n Update(node, b, e, idx, x) {\n if (b == e) {\n this.tr[node] = x;\n return;\n }\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n if (idx <= mid) this.Update(left, b, mid, idx, x);\n else this.Update(right, mid + 1, e, idx, x);\n this.tr[node] = this._mergeStrategy.Execute(this.tr[left], this.tr[right]);\n }\n\n Query(node, b, e, l, r) {\n if (r < b || e < l) return this._outOfBound;\n if (b >= l && e <= r) {\n return this.tr[node];\n }\n\n const left = node << 1;\n const right = left | 1;\n const mid = (b + e) >> 1;\n\n const p1 = this.Query(left, b, mid, l, r);\n const p2 = this.Query(right, mid + 1, e, l, r);\n\n return this._mergeStrategy.Execute(p1, p2);\n }\n}\n\nlet s;\n\nconst bitCount = (n) => {\n n = n - ((n >> 1) & 0x55555555);\n n = (n & 0x33333333) + ((n >> 2) & 0x33333333);\n return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;\n}\n\nfunction main() {\n while (s = readline()) {\n const q = parseInt(readline()); \n const n = s.length;\n const bitwiseOrStrategy = new BitwiseOrStrategy();\n const tree = new SegmentTree(bitwiseOrStrategy, 0, n);\n for (let i = 0; i < n; i++) {\n tree.Update(1, 0, n - 1, i, 1 << (s.charCodeAt(i) - 'a'.charCodeAt(0)));\n }\n for (let i = 0; i < q; i++) {\n const [ty, a, b] = readline().split(' ');\n if (ty == 1) {\n const l = parseInt(a);\n tree.Update(1, 0, n - 1, l - 1, 1 << (b.charCodeAt(0) - 'a'.charCodeAt(0)));\n } else{\n const l = parseInt(a);\n const r = parseInt(b);\n const qr = tree.Query(1, 0, n - 1, l - 1, r - 1);\n console.log(bitCount(qr));\n }\n }\n }\n}"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let map = {}, segment = {}\n\n for(let i = 0; i < 26; i++) {\n map[i]= new Array(n).fill(0)\n }\n // console.log(map[0])\n\n for(let i = 0; i < n; i++) {\n // console.log(str.charCodeAt(i), str.charCodeAt(i) - 97)\n map[str.charCodeAt(i) - 97][i] = 1\n }\n\n // console.log(map[0])\n for(let i = 0; i < 26; i++) {\n segment[i] = new SegmentTree(map[i], (a, b) => (a + b), 0)\n }\n\n // console.log(segment[0])\n for(let i = 0; i < q; i++) {\n // console.log(i)\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = str.charCodeAt(pos) - 97\n map[char][pos] = 1\n map[prev][pos] = 0\n str[pos] = r\n\n segment[char] = new SegmentTree(map[char], (a, b) => (a + b), 0)\n segment[prev] = new SegmentTree(map[prev], (a, b) => (a + b), 0)\n }\n\n else {\n let count = 0\n // if(i == 3) console.log(segment)\n for(let i = 0; i < 26; i++) {\n if(segment[i].rangeQuery(l - 1, r - 1) > 0) count ++\n }\n console.log(count)\n }\n }\n})\n\nclass SegmentTree {\n /**\n * @param {number[]} inputArray\n * @param {function} operation - binary function (i.e. sum, min)\n * @param {number} operationFallback - operation fallback value (i.e. 0 for sum, Infinity for min)\n */\n constructor(inputArray, operation, operationFallback) {\n this.inputArray = inputArray;\n this.operation = operation;\n this.operationFallback = operationFallback;\n\n // Init array representation of segment tree.\n this.segmentTree = this.initSegmentTree(this.inputArray);\n\n this.buildSegmentTree();\n }\n\n /**\n * @param {number[]} inputArray\n * @return {number[]}\n */\n initSegmentTree(inputArray) {\n let segmentTreeArrayLength;\n const inputArrayLength = inputArray.length;\n\n if (isPowerOfTwoBitwise(inputArrayLength)) {\n // If original array length is a power of two.\n segmentTreeArrayLength = (2 * inputArrayLength) - 1;\n } else {\n // If original array length is not a power of two then we need to find\n // next number that is a power of two and use it to calculate\n // tree array size. This is happens because we need to fill empty children\n // in perfect binary tree with nulls.And those nulls need extra space.\n const currentPower = Math.floor(Math.log2(inputArrayLength));\n const nextPower = currentPower + 1;\n const nextPowerOfTwoNumber = 2 ** nextPower;\n segmentTreeArrayLength = (2 * nextPowerOfTwoNumber) - 1;\n }\n\n return new Array(segmentTreeArrayLength).fill(null);\n }\n\n /**\n * Build segment tree.\n */\n buildSegmentTree() {\n const leftIndex = 0;\n const rightIndex = this.inputArray.length - 1;\n const position = 0;\n this.buildTreeRecursively(leftIndex, rightIndex, position);\n }\n\n /**\n * Build segment tree recursively.\n *\n * @param {number} leftInputIndex\n * @param {number} rightInputIndex\n * @param {number} position\n */\n buildTreeRecursively(leftInputIndex, rightInputIndex, position) {\n // If low input index and high input index are equal that would mean\n // the we have finished splitting and we are already came to the leaf\n // of the segment tree. We need to copy this leaf value from input\n // array to segment tree.\n if (leftInputIndex === rightInputIndex) {\n this.segmentTree[position] = this.inputArray[leftInputIndex];\n return;\n }\n\n // Split input array on two halves and process them recursively.\n const middleIndex = Math.floor((leftInputIndex + rightInputIndex) / 2);\n // Process left half of the input array.\n this.buildTreeRecursively(leftInputIndex, middleIndex, this.getLeftChildIndex(position));\n // Process right half of the input array.\n this.buildTreeRecursively(middleIndex + 1, rightInputIndex, this.getRightChildIndex(position));\n\n // Once every tree leaf is not empty we're able to build tree bottom up using\n // provided operation function.\n this.segmentTree[position] = this.operation(\n this.segmentTree[this.getLeftChildIndex(position)],\n this.segmentTree[this.getRightChildIndex(position)],\n );\n }\n\n /**\n * Do range query on segment tree in context of this.operation function.\n *\n * @param {number} queryLeftIndex\n * @param {number} queryRightIndex\n * @return {number}\n */\n rangeQuery(queryLeftIndex, queryRightIndex) {\n const leftIndex = 0;\n const rightIndex = this.inputArray.length - 1;\n const position = 0;\n\n return this.rangeQueryRecursive(\n queryLeftIndex,\n queryRightIndex,\n leftIndex,\n rightIndex,\n position,\n );\n }\n\n /**\n * Do range query on segment tree recursively in context of this.operation function.\n *\n * @param {number} queryLeftIndex - left index of the query\n * @param {number} queryRightIndex - right index of the query\n * @param {number} leftIndex - left index of input array segment\n * @param {number} rightIndex - right index of input array segment\n * @param {number} position - root position in binary tree\n * @return {number}\n */\n rangeQueryRecursive(queryLeftIndex, queryRightIndex, leftIndex, rightIndex, position) {\n if (queryLeftIndex <= leftIndex && queryRightIndex >= rightIndex) {\n // Total overlap.\n return this.segmentTree[position];\n }\n\n if (queryLeftIndex > rightIndex || queryRightIndex < leftIndex) {\n // No overlap.\n return this.operationFallback;\n }\n\n // Partial overlap.\n const middleIndex = Math.floor((leftIndex + rightIndex) / 2);\n\n const leftOperationResult = this.rangeQueryRecursive(\n queryLeftIndex,\n queryRightIndex,\n leftIndex,\n middleIndex,\n this.getLeftChildIndex(position),\n );\n\n const rightOperationResult = this.rangeQueryRecursive(\n queryLeftIndex,\n queryRightIndex,\n middleIndex + 1,\n rightIndex,\n this.getRightChildIndex(position),\n );\n\n return this.operation(leftOperationResult, rightOperationResult);\n }\n\n /**\n * Left child index.\n * @param {number} parentIndex\n * @return {number}\n */\n getLeftChildIndex(parentIndex) {\n return (2 * parentIndex) + 1;\n }\n\n /**\n * Right child index.\n * @param {number} parentIndex\n * @return {number}\n */\n getRightChildIndex(parentIndex) {\n return (2 * parentIndex) + 2;\n }\n}\n\nfunction isPowerOfTwoBitwise(number) {\n // 1 (2^0) is the smallest power of two.\n if (number < 1) {\n return false;\n }\n\n /*\n * Powers of two in binary look like this:\n * 1: 0001\n * 2: 0010\n * 4: 0100\n * 8: 1000\n *\n * Note that there is always exactly 1 bit set. The only exception is with a signed integer.\n * e.g. An 8-bit signed integer with a value of -128 looks like:\n * 10000000\n *\n * So after checking that the number is greater than zero, we can use a clever little bit\n * hack to test that one and only one bit is set.\n */\n return (number & (number - 1)) === 0;\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n console.log(fenwick)\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n console.log(fenwick[i].queryRange(l,r), i)\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n // console.log(fenwick)\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n console.log(fenwick[i], fenwick[i].queryRange(l,r))\n console.log(l, r, fenwick[i].queryRange(l,r), i)\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n // console.log(fenwick)\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n console.log(fenwick[i], fenwick[i].queryRange)\n console.log(fenwick[i].queryRange(l,r), i)\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const str = arr.shift()\n const strArray = str.split('')\n let n = str.length\n const q = parseInt(arr.shift())\n if(str.charCodeAt(n - 1) == 13) n--\n\n let fenwick = {}\n for(let i = 0; i < 26; i++) {\n fenwick[i] = new FenwickTree(n)\n }\n\n for(let i = 0; i < n; i++) {\n fenwick[strArray[i].charCodeAt() - 97].increase(i + 1, 1)\n }\n\n\n for(let i = 0; i < q; i++) {\n const ax = arr[i].split(' ')\n const qT = parseInt(ax[0])\n const l = parseInt(ax[1])\n const r = typeof ax[2] == 'string' ? ax[2] : parseInt(ax[2])\n\n if(qT == 1) {\n const pos = l - 1\n const char = r.charCodeAt(0) - 97\n const prev = strArray[pos].charCodeAt(0) - 97\n if(char != prev){\n strArray[pos] = r\n fenwick[prev].increase(l, -1)\n fenwick[char].increase(l, 1)\n }\n }\n\n else{\n let count = 0\n for(let i = 0; i < 26; i++) {\n console.log(fenwick[i].queryRange(l,r), i)\n count += fenwick[i].queryRange(l,r) > 0 ? 1 : 0\n }\n console.log(count)\n }\n }\n})\n\nclass FenwickTree {\n /**\n * Constructor creates empty fenwick tree of size 'arraySize',\n * however, array size is size+1, because index is 1-based.\n *\n * @param {number} arraySize\n */\n constructor(arraySize) {\n this.arraySize = arraySize;\n\n // Fill tree array with zeros.\n this.treeArray = Array(this.arraySize + 1).fill(0);\n }\n\n /**\n * Adds value to existing value at position.\n *\n * @param {number} position\n * @param {number} value\n * @return {FenwickTree}\n */\n increase(position, value) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n for (let i = position; i <= this.arraySize; i += (i & -i)) {\n this.treeArray[i] += value;\n }\n\n return this;\n }\n\n /**\n * Query sum from index 1 to position.\n *\n * @param {number} position\n * @return {number}\n */\n query(position) {\n if (position < 1 || position > this.arraySize) {\n throw new Error('Position is out of allowed range');\n }\n\n let sum = 0;\n\n for (let i = position; i > 0; i -= (i & -i)) {\n sum += this.treeArray[i];\n }\n\n return sum;\n }\n\n /**\n * Query sum from index leftIndex to rightIndex.\n *\n * @param {number} leftIndex\n * @param {number} rightIndex\n * @return {number}\n */\n queryRange(leftIndex, rightIndex) {\n if (leftIndex > rightIndex) {\n throw new Error('Left index can not be greater than right one');\n }\n\n if (leftIndex === 1) {\n return this.query(rightIndex);\n }\n\n return this.query(rightIndex) - this.query(leftIndex - 1);\n }\n}"}, {"source_code": "'use strict'\n\nconst s = readline().split('');\nconst n = s.length;\nconst take = [].reduce.call('abcdefghijklmnopqrstuvwxyz', (r, i, j) => { r[i] = j; return r; }, {});\nconst bit = Array.from({ length: 26 }, () => Array(n).fill(0))\n\nconst upd = (b, i, v) => {\n while (i <= n) { b[i] += v; i += i&-i; }\n}\n\nconst query = (b, i) => {\n let r = 0;\n while (i) { r += b[i]; i -= i&-i; }\n return r;\n}\n\nfor (let i = 0; i < n; i++) {\n upd(bit[take[s[i]]], i + 1, 1);\n}\n\nlet q = parseInt(readline());\nwhile(q--) {\n const t = readline().split(' ');\n if (t[0] === '1') {\n const j = parseInt(t[1]) - 1;\n upd(bit[take[s[j]]], j + 1, -1);\n upd(bit[take[t[2]]], j + 1, 1);\n s[j] = t[2];\n } else {\n const l = parseInt(t[1]) - 1;\n const r = parseInt(t[2]);\n write(bit.filter(i => query(i, r) > query(i, l)).length + '\\n');\n }\n}"}, {"source_code": "'use strict'\n \nconst p = [].reduce.call('abcdefghijklmnopqrstuvwxyz', (r, i) => { r[i] = []; return r; }, {});\nconst s = readline().split('');\ns.forEach((i, j) => p[i][j] = true);\n \nconst q = parseInt(readline());\n \nfor (let i = 0; i < q; i++) {\n const t = readline().split(' ');\n if (t[0] === '1') {\n const j = parseInt(t[1]) - 1;\n p[s[j]][j] = false;\n s[j] = t[2];\n p[s[j]][j] = true;\n }\n else {\n\t\tconst l = parseInt(t[1]) - 1;\n const r = parseInt(t[2]);\n let res = 0;\n Object.keys(p).forEach(k => {\n let j = l;\n while(j < r && !p[k][j]) j++;\n if (p[k][j]) res++; \n })\n\n write(res + '\\n');\n }\n}"}], "src_uid": "7a79c60749ee13c69284ba8fe34b63b3"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if ((i + 1) < (ind+1)) str[i] = c;\r\n else if (((i + 1) % (ind+1)) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar c = next();\r\n\t\tvar s = next();\r\n\t\tvar count = 0;\r\n\t\tvar output = [];\r\n\t\tvar set = new Set();\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(s[i] != c){\r\n\t\t\t\tset.add(i + 1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(set.size == 0){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tfor(var i = 2; i <= N; i++){\r\n\t\t\tvar isOK = true;\r\n\t\t\tfor(var j = 1; i * j <= N; j++){\r\n\t\t\t\tif(set.has(i * j)){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(isOK){\r\n\t\t\t\tcount = 1;\r\n\t\t\t\toutput.push(i);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(count > 0){\r\n\t\t\tmyout(count);\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\toutput.push(N);\r\n\t\toutput.push(N - 1);\r\n\t\tmyout(2);\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\nconst rla = () => readLine().split(' ').map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet [n, c] = readLine().split(' ');\r\n\t\tn = Number(n);\r\n\t\tlet s = rl();\r\n\r\n\t\tlet ans = [n - 1, n], same = true;\r\n\t\tfor (each of s) same &= each == c;\r\n\t\tif (same) ans = [];\r\n\r\n\t\tfor (let i = 2; !same && i <= n; i++) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (x = i; ok && x <= n; x += i) {\r\n\t\t\t\tif (s[x-1] != c) ok = false;\r\n\t\t\t}\r\n\t\t\tif (ok) { ans = [i]; break; }\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tif (ans.length) console.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() { \r\n let t=Number(readline())\r\n for(let i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n let found = false\n for (let i = 1; i <= str.length; i++) {\n if (str[i - 1] !== ch) {\n found = true\n }\n }\n if (!found) return 0\n\n for (let i = Math.ceil((n + 1) / 2); i <= str.length; i++) {\n if (str[i - 1] === ch) return `1\\n${i}`\n }\n return `2\\n${n - 1} ${n}`\n\n // let i = n\n // while (!FLAGS[i]) i--\n\n // if (str[i - 1] === ch) {\n // return not.length ? `1\\n${i}` : '0'\n // } else {\n // let j = i - 1\n // while (!FLAGS[j]) j--\n // return not.length === 1 ? `1\\n${j}` : `2\\n${i} ${j}`\n // }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction cZ(ctr, ltr) {\r\n for (let i = 0; i < ctr.length; ++i) {\r\n if (ctr[i] !== ltr) return false\r\n }\r\n console.log('0')\r\n return true\r\n}\r\n\r\nfunction cO(siz, str, ltr) {\r\n let isF;\r\n for (let i = 2; i <= siz; ++i) {\r\n isF = true;\r\n for (let j = i - 1; j < siz; j += i) {\r\n if (str[j] !== ltr) {\r\n isF = false;\r\n }\r\n }\r\n if (isF) {\r\n console.log(1)\r\n console.log(i)\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction solve([num, ltr], str) {\r\n if (cZ(str, ltr)) return;\r\n if (!cO(num, str, ltr)) {\r\n console.log(2)\r\n console.log(`${num - 1} ${num}`)\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind - 1; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind - 1; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind - 1; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n console.log(str);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n console.log(c);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind - 1; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n console.log(c);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) {\r\n console.log(0);\r\n continue;\r\n }\r\n let ind = -1;\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n if (ind === -1 || ind === 0) {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n } else if (ind === n - 1 || ind === n - 2) {\r\n console.log(1);\r\n console.log(ind + 1);\r\n } else {\r\n let res = [];\r\n while (true) {\r\n res.push(ind + 1);\r\n for (let i = 0; i < n; i++) {\r\n if (i + 1 < ind) str[i] = c;\r\n else if (i + (1 % ind) != 0) str[i] = c;\r\n }\r\n let flag = true;\r\n for (let i = ind - 1; i < n; i++) {\r\n if (str[i] !== c) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(res.length);\r\n console.log(res.join(\" \"));\r\n break;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === c) {\r\n ind = i;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n console.log(str);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n n = parseInt(n);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans) {\r\n if (str[n - 1] === c && str[n - 2] === c) console.log(0);\r\n else if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else if (str[n - 2] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n }\r\n } else {\r\n if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else if (str[n - 2] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n n = parseInt(n);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 2; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans) {\r\n if (str[n - 1] === c && str[n - 2] === c) console.log(0);\r\n else if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else {\r\n console.log(1);\r\n console.log(n - 1);\r\n }\r\n } else {\r\n if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else if (str[n - 2] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else {\r\n console.log(2);\r\n console.log(n + \" \" + (n - 1));\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n n = parseInt(n);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (str[n - 1] === c && ans) console.log(0);\r\n else if (ans && str[n - 1] !== c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else if (str[n - 2] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else {\r\n console.log(2);\r\n console.log(n - 1 + \" \" + n);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n n = parseInt(n);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (str[n - 1] === c && ans) console.log(0);\r\n else if (ans && str[n - 1] !== c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else if (str[n - 2] === c) {\r\n console.log(1);\r\n console.log(n);\r\n } else {\r\n console.log(2);\r\n console.log(n - 1 + \" \" + n);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, c] = readline().trim().split(\" \");\r\n n = parseInt(n);\r\n let str = readline().trim().split(\"\");\r\n let ans = true;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (str[i] !== c) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (str[n - 1] === c && ans) console.log(0);\r\n else if (ans && str[n - 1] !== c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else if (str[n - 1] === c) {\r\n console.log(1);\r\n console.log(n - 1);\r\n } else {\r\n console.log(2);\r\n console.log(n - 1 + \" \" + n);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nconst FLAGS = primes(3e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n return flag\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n let found = false\n for (let i = 1; i <= str.length; i++) {\n if (str[i - 1] !== ch) {\n found = true\n }\n }\n if (!found) return 0\n\n for (let i = Math.ceil(n / 2); i <= str.length; i++) {\n if (str[i - 1] === ch) return `1\\n${i}`\n }\n return `2\\n${n - 1} ${n}`\n\n // let i = n\n // while (!FLAGS[i]) i--\n\n // if (str[i - 1] === ch) {\n // return not.length ? `1\\n${i}` : '0'\n // } else {\n // let j = i - 1\n // while (!FLAGS[j]) j--\n // return not.length === 1 ? `1\\n${j}` : `2\\n${i} ${j}`\n // }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nconst FLAGS = primes(3e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n return flag\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n let found = false\n for (let i = 1; i <= str.length; i++) {\n if (str[i - 1] === ch) {\n if (i >= Math.ceil(n / 2)) return `1\\n${i}`\n } else {\n found = true\n }\n }\n return found ? `2\\n${n - 1} ${n}` : 0\n\n // let i = n\n // while (!FLAGS[i]) i--\n\n // if (str[i - 1] === ch) {\n // return not.length ? `1\\n${i}` : '0'\n // } else {\n // let j = i - 1\n // while (!FLAGS[j]) j--\n // return not.length === 1 ? `1\\n${j}` : `2\\n${i} ${j}`\n // }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nconst FLAGS = primes(3e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n return flag\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n const not = []\n for (let i = 0; i < str.length; i++) {\n if (str[i] !== ch) not.push(i)\n }\n if (not.length === 1 && str[n - 1] === ch) return `1\\n${n}`\n\n let i = n\n while (!FLAGS[i]) i--\n\n if (str[i - 1] === ch) {\n return not.length ? `1\\n${i}` : '0'\n } else {\n let j = i - 1\n while (!FLAGS[j]) j--\n return not.length === 1 ? `1\\n${j}` : `2\\n${i} ${j}`\n }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nconst FLAGS = primes(3e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n return flag\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n const not = []\n for (let i = 0; i < str.length; i++) {\n if (str[i] !== ch) not.push(i)\n }\n\n let i = n\n while (!FLAGS[i]) i--\n\n if (str[i - 1] === ch) {\n return not.length ? `1\\n${i}` : '0'\n } else {\n let j = i - 1\n while (!FLAGS[j]) j--\n return not.length === 1 ? `1\\n${j}` : `2\\n${i} ${j}`\n }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nconst FLAGS = primes(3e5)\nfunction primes(n) {\n const flag = Array(n + 1).fill(true)\n flag[0] = false\n flag[1] = false\n\n const limit = Math.floor(Math.sqrt(n))\n for (let i = 2; i <= limit; i++) {\n for (let j = i * i; j <= n; j += i) {\n flag[j] = false\n }\n }\n return flag\n\n const ps = []\n for (let i = 2; i <= n; i++) {\n if (flag[i]) ps.push(i)\n }\n return ps\n}\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [n, ch] = lines[l++].trim().split(' ')\n const str = lines[l++].split('')\n console.log(solve(n, ch, str))\n }\n// })()\n})\n\nfunction solve(n, ch, str) {\n // if (n === 1) return str[0] === ch ? 0 : `1\\n`\n n = +n\n const not = []\n for (let i = 0; i < str.length; i++) {\n if (str[i] !== ch) not.push(i)\n }\n\n let i = n\n while (!FLAGS[i]) i--\n\n if (str[i] === ch) {\n return not.length ? `1\\n${i}` : '0'\n } else {\n let j = i - 1\n while (!FLAGS[j]) j--\n return `2\\n${i} ${j}`\n }\n\n // const FLAGS = []\n // let has = false\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] !== ch && FLAGS[i]) {\n // has = true\n // }\n // }\n\n // return [n, ch, str]\n}\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction cZ(ctr, ltr) {\r\n for (let i = 0; i < ctr.length; ++i) {\r\n if (ctr[i] !== ltr) return false\r\n }\r\n console.log('0')\r\n return true\r\n}\r\n\r\nfunction cO(siz, str, ltr) {\r\n let isF;\r\n for (let i = 2; i <= siz; ++i) {\r\n isF = true;\r\n for (let j = i - 1; j < siz; j += i) {\r\n if (str[j] !== ltr) {\r\n isF = false;\r\n }\r\n }\r\n if (isF) {\r\n console.log(1)\r\n console.log(i)\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction solve([num, ltr], str) {\r\n if (cZ(str, ltr)) return;\r\n if (!cO(num, str, ltr)) {\r\n console.log(2)\r\n console.log(num + '' + num - 1)\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nconst sm = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,\r\n 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\r\n\r\nfunction isSmp(num) {\r\n if (num === 1) return false\r\n let flag = true;\r\n for (let i = 2; i < num; i++) {\r\n if (num % i === 0 && i !== 1) {\r\n flag = false;\r\n break\r\n }\r\n }\r\n return flag\r\n}\r\n\r\nfunction solve([num, letr], str) {\r\n let res = []\r\n let needTwo = false\r\n for (let i = 0; i < num; i++) {\r\n if ((i + 1) % 2 === 0) {\r\n if (str[i] !== letr) {\r\n res.push(i)\r\n }\r\n } else {\r\n if (!needTwo && str[i] !== letr) {\r\n needTwo = true;\r\n }\r\n }\r\n }\r\n if (needTwo) {\r\n res.unshift(2)\r\n }\r\n res = res.filter(i => isSmp(i))\r\n console.log(res.length)\r\n if (res.length) {\r\n console.log(res.join(' '))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nconst sm = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,\r\n 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\r\n\r\nfunction isSmp(num) {\r\n let flag = true;\r\n for (let i = 2; i < num; i++) {\r\n if (num % i === 0) {\r\n flag = false;\r\n break\r\n }\r\n }\r\n return flag\r\n}\r\n\r\nfunction solve([num, letr], str) {\r\n let res = []\r\n let needTwo = false\r\n for (let i = 0; i < num; i++) {\r\n if ((i + 1) % 2 === 0) {\r\n if (str[i] !== letr) {\r\n res.push(i)\r\n }\r\n } else {\r\n if (!needTwo && str[i] !== letr) {\r\n needTwo = true;\r\n }\r\n }\r\n }\r\n if (needTwo) {\r\n res.unshift(2)\r\n }\r\n res = res.filter(i => isSmp(i + 1))\r\n console.log(res.length)\r\n if (res.length) {\r\n console.log(res.join(' '))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nconst sm = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,\r\n 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\r\n\r\nfunction isSmp(num) {\r\n let flag = true;\r\n for (let i = 2; i < num; i++) {\r\n if (num % i === 0) {\r\n flag = false;\r\n break\r\n }\r\n }\r\n return flag\r\n}\r\n\r\nfunction solve([num, letr], str) {\r\n let res = []\r\n let needTwo = false\r\n for (let i = 0; i < num; i++) {\r\n if ((i + 1) % 2 === 0) {\r\n if (str[i] !== letr) {\r\n res.push(i)\r\n }\r\n } else {\r\n if (!needTwo && str[i] !== letr) {\r\n needTwo = true;\r\n }\r\n }\r\n }\r\n if (needTwo) {\r\n res.unshift(2)\r\n }\r\n res = res.filter(i => isSmp(i))\r\n console.log(res.length)\r\n if (res.length) {\r\n console.log(res.join(' '))\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nconst sm = [2,3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,\r\n 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\r\n\r\n\r\nfunction solve([num, letr], str) {\r\n let res = []\r\n let needTwo = false\r\n for (let i = 0; i < num; i++) {\r\n if ((i + 1) % 2 === 0) {\r\n if (str[i] !== letr) {\r\n res.push(i)\r\n }\r\n } else {\r\n if (!needTwo && str[i] !== letr) {\r\n needTwo = true;\r\n }\r\n }\r\n }\r\n if (needTwo) {\r\n res.unshift(2)\r\n }\r\n res = res.filter(i => sm.includes(i))\r\n console.log(res.length)\r\n if(res.length){\r\n console.log(res.join(' '))\r\n }\r\n\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i].split(' '), inputArr[i + 1])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar c = next();\r\n\t\tvar s = next();\r\n\t\tvar isOK = [false, false];\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(s[i] != c){\r\n\t\t\t\tisOK[0] = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(s[N - 1] != c){\r\n\t\t\tisOK[1] = true;\r\n\t\t}\r\n\t\tvar count = (isOK[0] ? 1 : 0) + (isOK[1] ? 1 : 0);\r\n\t\tvar output = [];\r\n\t\tif(isOK[0]){\r\n\t\t\toutput.push(N);\r\n\t\t}\r\n\t\tif(isOK[1]){\r\n\t\t\toutput.push(N - 1);\r\n\t\t}\r\n\t\tmyout(count);\r\n\t\tif(output.length > 0){\r\n\t\t\tmyout(myconv(output, 8));\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "3b8969f7f2051d559a1e375ce8275c73"} {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let [a,b,c]=line[i].split(' ').map(x=>{return parseInt(x)});\r\n if(a===b+c||b===a+c||c===a+b)\r\n {\r\n console.log(\"YES\");\r\n }\r\n else\r\n {\r\n console.log(\"NO\");\r\n }\r\n }\r\n})", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString.trim().split(\"\\n\").map((string) => {\n return string.trim();\n });\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = readline();\n for (let i = 0; i < n; i++) {\n let [a, b, c] = readline().split(\" \").map(Number);\n if (((a + b + c) / 2) == a || ((a + b + c) / 2) == b || ((a + b + c) / 2) == c) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = readline();\n for (let i = 0; i < n; i++) {\n let [a, b, c] = readline().split(\" \").map(Number);\n if (a + b === c || a + c === b || c + b === a) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline()\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(input){\r\n console.log(\r\n Math.abs(input[0]-input[1]) == input[2]\r\n ||\r\n Math.abs(input[0]-input[2]) == input[1]\r\n ||\r\n Math.abs(input[1]-input[2]) == input[0]\r\n ? 'YES':'NO'\r\n )\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet standardInputString = ''\r\nlet currentLine = 0\r\n\r\nfunction readLine() {\r\n return standardInputString[currentLine++]\r\n}\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData\r\n})\r\n\r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString.trim().split('\\n').map(line => {\r\n return line.trim()\r\n })\r\n\r\n main()\r\n})\r\n\r\n\r\n\r\n// ......................................................... //\\\r\n\r\n\r\nconst main = () => {\r\n const testCase = parseInt(readLine());\r\n\r\n for (let index = 0; index < testCase; index++) {\r\n const a = readLine().split(\" \").map(x => parseInt(x));\r\n \r\n console.log(sum(a[0], a[1], a[2]));\r\n\r\n }\r\n}\r\n\r\nconst sum = (a, b, c) => {\r\n if (a + b === c || a + c === b || b + c === a)\r\n return 'YES';\r\n return 'NO';\r\n\r\n}"}, {"source_code": "const lines = [];\r\nconst readlineInterface = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nreadlineInterface.on(\"line\", (line) => {\r\n lines.push(line);\r\n});\r\nreadlineInterface.on(\"close\", () => {\r\n const tests = lines.slice(1).map((line) => line.split(\" \").map((e) => +e));\r\n\r\n tests\r\n .map((numbers) => {\r\n const sum = numbers.reduce((a, b) => a + b, 0);\r\n return numbers.find((e) => e === sum / 2) !== undefined ? \"YES\" : \"NO\";\r\n })\r\n .forEach((e) => console.log(e));\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n \r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nlet T = readline();\r\nfor(let i = 1; i <= T; i++){\r\n let [a, b, c] = readline().split(' ').map(Number);\r\n console.log(solve(a, b, c));\r\n}\r\n \r\n \r\nfunction solve(a, b, c){\r\n return (a + b === c || b + c === a || a + c === b) ? 'YES' : 'NO';\r\n}"}, {"source_code": "// cls; cat .\\input.txt | node .\\script.js\r\n// codium --diff file1.js file2.js\r\n'use strict';\r\nasync function main(read) {\r\n let amount = Number(await read());\r\n let output = \"\"\r\n while (amount > 0) {\r\n try {\r\n let str = await read().split(' ')\r\n let a = Number(str[0]);\r\n let b = Number(str[1]);\r\n let c = Number(str[2]);\r\n let max = Math.max(a, b, c)\r\n output+=(max == (a + b + c - max) ? \"YES\" : \"NO\") + '\\n'\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n amount--\r\n\r\n }\r\n return output\r\n\r\n}\r\n\r\nlet inputs, str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d\n .split(\" \")\n .map(Number)\n .sort((a, b) => a - b);\n\n if (arr[0] + arr[1] === arr[2]) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n console.log(k[0] + k[1] == k[2] ? 'YES' : 'NO');\n }\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b})\n console.log(k[0] + k[1] == k[2] ? 'YES' : 'NO')\n }\n});"}, {"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\nconst sum = (a, b, c) => {\n if (a + b === c) return \"YES\";\n if (a + c === b) return \"YES\";\n if (b + c === a) return \"YES\";\n return \"NO\";\n};\nconst inputs = [];\n\nconst solution = async () => {\n for await (const line of readline) {\n var num = line.split(\" \").map((x) => parseInt(x));\n inputs.push(num);\n }\n\n for (let x = 1; x < inputs.length; x++) {\n console.log(sum(inputs[x][0], inputs[x][1], inputs[x][2]));\n }\n};\n\nsolution();\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = parseInt(readline());\n for(let i = 0; i < x; i += 1) {\n const nums = readline().split(' ').map(n => parseInt(n));\n const isYes = nums.some((num, index) => {\n if (index === 0)\n return num === nums[1] + nums[2];\n else if (index === 1)\n return num === nums[0] + nums[2];\n else\n return num === nums[1] + nums[0];\n });\n\n if (isYes)\n console.log('YES');\n else\n console.log('NO');\n }\n\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction checkSum(cases) {\n for (let i = 0; i < cases.length; i++) {\n const [first, second, third] = cases[i];\n if (\n Number(first) === Number(second) + Number(third) ||\n Number(second) === Number(first) + Number(third) ||\n Number(third) === Number(first) + Number(second)\n ) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = [];\n for (let i = 0; i < t; i++) {\n const numbers = readLine().split(\" \");\n cases.push(numbers);\n }\n\n checkSum(cases);\n}\n\n\t \t\t \t \t \t\t\t\t\t \t\t\t\t"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\nlet n = parseInt(readline());\r\nvar num = undefined\r\nwhile(n--){\r\n num =readline().split(' ').map(x => parseInt(x))\r\n if((num[0]+num[1] === num[2]) || (num[0]+num[2] === num[1]) || (num[2]+num[1] === num[0])){\r\n console.log(`YES`);\r\n \r\n }\r\n else{\r\n console.log(`NO`);\r\n }\r\n \r\n \r\n \r\n}\r\n}"}, {"source_code": "/**\r\n * 10/13/22 morning\r\n * https://codeforces.com/contest/1742/problem/A\r\n */\r\n\r\nconst pr = console.log;\r\n\r\nconst solve = (a) => {\r\n if (a[0] + a[1] == a[2] || a[0] + a[2] == a[1] || a[1] + a[2] == a[0]) {\r\n pr(\"YES\");\r\n } else {\r\n pr(\"NO\");\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nal = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let t = ni();\r\n while (t--) {\r\n let a = nai();\r\n solve(a);\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n // let n = parseInt(readline())\r\n let arr = readline().split(' ').map(Number)\r\n console.log(solve(arr))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (arr) => {\r\n let a = arr[0]\r\n let b = arr[1]\r\n let c = arr[2]\r\n\r\n if( a === b + c ) return 'YES'\r\n if( b === c + a ) return 'YES'\r\n if( c === a + b ) return 'YES'\r\n\r\n return 'NO'\r\n}\r\n\r\n\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)\r\n\r\n\r\n// cmd: cat input.txt | node main.js"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nvar tcn = 0\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nrl.on('line', line => {\r\n if (!tcn) return tcn = Number(line)\r\n\r\n run(line)\r\n \r\n if (!--tcn) rl.close()\r\n})\r\n\r\nfunction run(line) {\r\n var vals = line.split(' ').map(val => Number(val)).sort((a, b) => a - b)\r\n if (vals[2] == vals[1] + vals[0] || vals[0] == vals[1] + vals[2]) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet processIn = '';\r\nlet processCurr = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n processIn += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n processIn = processIn.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n JS();\r\n});\r\n\r\nfunction readLine() {\r\n return processIn[processCurr++];\r\n}\r\nfunction mergeSort(a) {\r\n let r = a.length;\r\n let l = 0;\r\n let m = Math.round((r - l) / 2);\r\n if (r === 1) {\r\n return; // returns recursively\r\n }\r\n let L = []; // left half of current a\r\n let R = []; // right half of current a\r\n for (let i = l; i < m; i++) {\r\n L.push(a[i]);\r\n }\r\n for (let j = m; j < r; j++) {\r\n R.push(a[j]);\r\n }\r\n mergeSort(L);\r\n mergeSort(R);\r\n let i = 0, j = 0, k = 0;\r\n // Merging part\r\n while (i < L.length && j < R.length) {\r\n if (L[i] < R[j]) {\r\n a[k] = L[i];\r\n i++;\r\n } else {\r\n a[k] = R[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n while (i < L.length) {\r\n a[k] = L[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < R.length) {\r\n a[k] = R[j];\r\n j++;\r\n k++;\r\n }\r\n}\r\n\r\nfunction JS() {\r\n /*\r\n\r\n */\r\n let tt = parseInt(readLine());\r\n // let tt = 1;\r\n for(let t=0;t { return parseInt(string.trim()); });\r\n let a = inp[0],b=inp[1],c=inp[2];\r\n if(a === b+c || b === a+c || c === a+b){\r\n console.log('YES');\r\n }else{\r\n console.log('NO');\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let n = readline();\r\n for (let i = 0; i < n; i++) {\r\n let [a, b, c] = readline().split(\" \").map(Number);\r\n if (a + b === c || a + c === b || c + b === a) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(arr) {\n const [a, b, c] = arr.sort((a, b) => a - b)\n return a + b === c ? 'YES' : 'NO'\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const a = rns(3),\r\n sum = a.reduce((a, b) => a + b, 0);\r\n for (let i = 0; i < 3; i++) {\r\n if (a[i] === sum - a[i]) return 'YES';\r\n }\r\n return 'NO';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "// run on javascript V8 4.8.0\r\n// https://codeforces.com/contest/1742/problem/A\r\n// You are given three integers a, b, and c. Determine if one of them is the sum of the other two.\r\nfunction main() {\r\n var tn = +readline(); // Number of test cases\r\n for (var i = 0; i < tn; i++) {\r\n\r\n var a = readline().split(' ').map(Number);\r\n // Call solve()\r\n solve(a);\r\n }\r\n}\r\n\r\nfunction solve(a) {\r\n var a = a.sort(function(a, b){return a-b});\r\n if (a[0] + a[1] == a[2]) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n}\r\n\r\nmain();\r\n"}, {"source_code": "function begin(a,b,c) {\r\n if(a == b + c) {\r\n print(\"YES\");\r\n } else if(b == a + c) {\r\n print(\"YES\");\r\n } else if(c == a + b) {\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}\r\n\r\nvar caseNum = parseInt(readline(), 10);\r\nfor (var i = 0; i < caseNum; i++) {\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(x[0], x[1], x[2]);\r\n}"}, {"source_code": "var tests = +readline();\r\n\r\nfor(var i=0; iNumber(i));\r\n max = Math.max.apply(null,arr[i]);\r\n for(var j = 0; j < arr[i].length; j++){\r\n s+=arr[i][j];\r\n f=s-max;\r\n }if(f==max){\r\n print(\"YES\");\r\n }else{\r\n print(\"NO\");\r\n }\r\n f=0;\r\n max=0;\r\n s=0;\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var caseIntArray = new Array();\r\n for (var j = 0; j < caseArray.length; j++)\r\n {\r\n caseIntArray.push(parseInt(caseArray[j]));\r\n }\r\n var caseIntSorted = caseIntArray.sort((a,b) => a - b);\r\n if (caseIntSorted[2] == (caseIntSorted[1] + caseIntSorted[0]))\r\n {\r\n print(\"YES\");\r\n }\r\n else print(\"NO\");\r\n}"}, {"source_code": "t = readline()\r\nwhile (t--) {\r\n input = readline().split(\" \").map(Number).sort(function (a, b) { return a - b }).reverse()\r\n if (input[0] === input[1] + input[2]) {\r\n print(\"YES\")\r\n } else {\r\n print(\"NO\")\r\n }\r\n}"}, {"source_code": "const tc = readline();\r\nfor (var t =0 ; t {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString.trim().split(\"\\n\").map((string) => {\n return string.trim();\n });\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = readline();\n for (let i = 0; i < n; i++) {\n let [a, b, c] = readline().split(\" \").map(Number);\n if (((a + b + c) / 2) == a || b || c) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString.trim().split(\"\\n\").map((string) => {\n return string.trim();\n });\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = readline();\n for (let i = 0; i < n; i++) {\n let [a, b, c] = readline().split(\" \");\n if (a + b === c || a + c === b || c + b === a) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "process.stdin.setEncoding('utf-8');\r\n// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// process.stdout.write(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// process.stdout.write(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// process.stdout.write('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n return;\r\n }\r\n var b;\r\n var Nums = data.trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// process.stdout.write(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// process.stdout.write(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// process.stdout.write('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n process.stdout.write('YES\\n');\r\n } else {\r\n process.stdout.write('NO\\n');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// process.stdout.write(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// process.stdout.write(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// process.stdout.write('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// process.stdout.write('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// process.stdout.write('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n process.stdout.write('YES');\r\n } else {\r\n process.stdout.write('NO');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n console.log('YES');\r\n } else {\r\n console.log('NO');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n console.log('YES\\n');\r\n } else {\r\n console.log('NO\\n');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f, c = 0;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = parseInt(data.toString().trim());\r\n console.log(f);\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n console.log('YES\\n');\r\n } else {\r\n console.log('NO\\n');\r\n }\r\n c++\r\n if (c == f) {\r\n process.exit();\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var b;\r\n var Nums = data.toString().trim().split(' ');\r\n for (var i = 0; i < Nums.length; i++) {\r\n if (((parseInt(Nums[0]) + parseInt(Nums[1]) + parseInt(Nums[2])) / 2) == parseInt(Nums[i])) {\r\n b = true;\r\n break;\r\n } else {\r\n b = false;\r\n }\r\n }\r\n if (b) {\r\n console.log('YES\\n');\r\n } else {\r\n console.log('NO\\n');\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var Nums = data.toString().trim().split();\r\n if (((Nums[0] + Nums[1]) == Nums[2]) || ((Nums[0] + Nums[2]) == Nums[1]) || ((Nums[1] + Nums[2]) == Nums[0])) {\r\n console.log('Yes\\n');\r\n } else {\r\n console.log('NO\\n');\r\n }\r\n})\r\n"}, {"source_code": "// let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], z = -1, f;\r\n// process.stdin.on('data', function (data) {\r\n// var d = data.toString().trim().replaceAll(' ', '\\n')\r\n// var splittedSTR = d.split('')\r\n// console.log(splittedSTR);\r\n// let output = [];\r\n// if (splittedSTR.length == 1) {\r\n// if (f == undefined) {\r\n// f = data.toString().trim();\r\n// } else {\r\n// }\r\n// return;\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {\r\n// splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;\r\n// splittedSTR.splice(i + 1, 1)\r\n// splittedSTR.splice(i - 1, 1)\r\n// }\r\n// }\r\n// for (var i = 0; i < splittedSTR.length; i++) {\r\n// output.push(Alpha[splittedSTR[i] - 1])\r\n// if (output.length == splittedSTR.length) {\r\n// console.log(output.join(''));\r\n// z++\r\n// if (z == f) {\r\n// process.exit();\r\n// }\r\n// return output.join('');\r\n// }\r\n// }\r\n// })\r\nvar f;\r\n// process.stdin.on('data', function (data) {\r\n// if (f == undefined) {\r\n// f = 1;\r\n// return;\r\n// }\r\n// var phrase = data.toString().trim().toLowerCase().split(' ');\r\n// if (phrase[0] == phrase[1]) {\r\n// console.log('=\\n');\r\n// return '=';\r\n// }\r\n// if (!data.toString().trim().toLowerCase().includes('s')) {\r\n// if (phrase[0].includes('m') && phrase[1].includes('l')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].includes('l') && phrase[1].includes('m')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// }\r\n// } else {\r\n// if (phrase[0].includes('m') && phrase[1].includes('s')) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].includes('s') && phrase[1].includes('m')) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// } else if (phrase[0].match(/x/g).length < phrase[1].match(/x/g).length) {\r\n// console.log('>\\n');\r\n// return '>';\r\n// } else if (phrase[0].match(/x/g).length > phrase[1].match(/x/g).length) {\r\n// console.log('<\\n');\r\n// return '<';\r\n// }\r\n// }\r\n// })\r\nprocess.stdin.on('data', function (data) {\r\n if (f == undefined) {\r\n f = 1;\r\n return;\r\n }\r\n var Nums = data.toString().trim().split();\r\n if (((Nums[0] * Nums[1]) == Nums[2]) || ((Nums[0] * Nums[2]) == Nums[1]) || ((Nums[1] * Nums[2]) == Nums[0])) {\r\n console.log('Yes\\n');\r\n } else {\r\n console.log('NO\\n');\r\n }\r\n})\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline()\r\n \r\n for(let i = 0; iparseInt(x)))\r\n }\r\n}\r\n\r\n\r\nfunction solve(input){\r\n console.log(\r\n input.includes(Math.abs(input[0]-input[1]))\r\n ||\r\n input.includes(Math.abs(input[0]-input[2]))\r\n ||\r\n input.includes(Math.abs(input[1]-input[2])) ? 'YES':'NO'\r\n )\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline()\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(input){\r\n console.log(\r\n input.includes(Math.abs(input[0]-input[1]))\r\n ||\r\n input.includes(Math.abs(input[0]-input[2]))\r\n ||\r\n input.includes(input[1]-input[2]) ? 'YES':'NO'\r\n )\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n \r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nlet T = readline();\r\nfor(let i = 1; i <= T; i++){\r\n let [a, b, c] = readline().split(' ').map(Number);\r\n console.log(solve(a, b, c));\r\n}\r\n \r\n \r\nfunction solve(a, b, c){\r\n return a + b === c || b + c === a || a + c === b;\r\n}"}, {"source_code": "// run on javascript V8 4.8.0\r\n// https://codeforces.com/contest/1742/problem/A\r\n// You are given three integers a, b, and c. Determine if one of them is the sum of the other two.\r\nfunction main() {\r\n var tn = +readline(); // Number of test cases\r\n for (var i = 0; i < tn; i++) {\r\n\r\n var a = readline().split(' ').map(Number);\r\n // Call solve()\r\n solve(a);\r\n }\r\n}\r\n\r\nfunction solve(a) {\r\n var a = a.sort(function(a, b){return a-b});\r\n if (a[0] + a[1] == a[2]) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n}\r\n\r\n// main();\r\n"}, {"source_code": "var tests = +readline();\n\nfor(var i=0; i {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const q = +lines[l++]\r\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\r\n l += q\r\n output[i] = solve(qs)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\nclass Queue {\r\n constructor() {\r\n this.map = {}\r\n this.first = 0\r\n this.last = -1\r\n }\r\n push(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[++this.last] = args[i]\r\n }\r\n }\r\n unshift(...args) {\r\n let i = 0\r\n if (!this.length) {\r\n this.first = this.last = 0\r\n this.map[this.first] = args[i++]\r\n }\r\n for (; i < args.length; i++) {\r\n this.map[--this.first] = args[i]\r\n }\r\n }\r\n pop() {\r\n const r = this.map[this.last]\r\n delete this.map[this.last]\r\n this.last--\r\n return r\r\n }\r\n shift() {\r\n const r = this.map[this.first]\r\n delete this.map[this.first]\r\n this.first++\r\n return r\r\n }\r\n get length() {\r\n if (this.first > this.last) return 0\r\n return this.last - this.first + 1\r\n }\r\n get(x) {\r\n return this.map[this.first + x]\r\n }\r\n getLast() {\r\n return this.map[this.last]\r\n }\r\n forEach(fn) {\r\n for (let i = this.first; i <= this.last; i++) {\r\n fn(this.map[i], i - this.first)\r\n }\r\n }\r\n}\r\n\r\nfunction solve(qs) {\r\n const s = Array(26).fill(0)\r\n s[0] = 1\r\n const t = Array(26).fill(0)\r\n t[0] = 1\r\n return qs.map(([type, k, x]) => {\r\n let add\r\n if (type === 1) {\r\n add = s\r\n } else {\r\n add = t\r\n }\r\n for (let i = 0; i < x.length; i++) {\r\n const j = x.charCodeAt(i) - 'a'.charCodeAt(0)\r\n add[j] += k\r\n }\r\n // console.log(s, t)\r\n const sch = []\r\n const tch = []\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i]) sch.push(i)\r\n if (t[i]) tch.push(i)\r\n }\r\n if (!sch.length) return 'YES'\r\n if (!tch.length) return 'NO'\r\n if (sch[0] < tch[tch.length - 1]) return 'YES'\r\n if (sch[0] > tch[tch.length - 1]) return 'NO'\r\n if (sch.length > 1) return 'NO'\r\n if (tch.length > 1) return 'NO'\r\n const a = s[sch[0]]\r\n const b = t[tch[0]]\r\n return a < b ? 'YES' : 'NO'\r\n }).join('\\n')\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n const res = new Array(n);\r\n const cnt1 = new Array(26).fill(0),\r\n cnt2 = new Array(26).fill(0);\r\n let sum1 = 1,\r\n sum2 = 1;\r\n cnt1[0] = 1;\r\n cnt2[0] = 1;\r\n let flag = false;\r\n next: for (let i = 0; i < n; i++) {\r\n const d = rn(),\r\n k = rn(),\r\n s = read();\r\n if (!flag) {\r\n for (let j = 0; j < s.length; j++) {\r\n if (d === 1) {\r\n cnt1[s[j].charCodeAt(0) - 97] += k;\r\n sum1 += k;\r\n } else {\r\n if (s[j] !== 'a') {\r\n flag = true;\r\n break;\r\n }\r\n cnt2[s[j].charCodeAt(0) - 97] += k;\r\n sum2 += k;\r\n }\r\n }\r\n }\r\n if (flag) {\r\n res[i] = 'YES';\r\n } else {\r\n let p1 = 0,\r\n p2 = 0;\r\n for (let j = 0; j < 26; j++) {\r\n p1 += cnt1[j];\r\n p2 += cnt2[j];\r\n if (cnt1[j] !== cnt2[j]) {\r\n if (cnt1[j] < cnt2[j] && p1 === sum1 || cnt1[j] > cnt2[j] && p2 !== sum2) {\r\n res[i] = 'YES';\r\n continue next;\r\n }\r\n break;\r\n }\r\n }\r\n res[i] = 'NO';\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const q = +lines[l++]\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += q\n output[i] = solve(qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n get(x) {\n return this.map[this.first + x]\n }\n getLast() {\n return this.map[this.last]\n }\n forEach(fn) {\n for (let i = this.first; i <= this.last; i++) {\n fn(this.map[i], i - this.first)\n }\n }\n}\n\nfunction solve(qs) {\n const s = Array(26).fill(0)\n s[0] = 1\n const t = Array(26).fill(0)\n t[0] = 1\n return qs.map(([type, k, x]) => {\n let add\n if (type === 1) {\n add = s\n } else {\n add = t\n }\n for (let i = 0; i < x.length; i++) {\n const j = x.charCodeAt(i) - 'a'.charCodeAt(0)\n add[j] += k\n }\n // console.log(s, t)\n const sch = []\n const tch = []\n for (let i = 0; i < s.length; i++) {\n if (s[i]) sch.push(i)\n if (t[i]) tch.push(i)\n }\n if (!sch.length) return 'YES'\n if (!tch.length) return 'NO'\n if (sch[0] < tch[tch.length - 1]) return 'YES'\n if (sch[0] > tch[tch.length - 1]) return 'NO'\n // if (sch.length > 1) return 'NO'\n // if (tch.length > 1) return 'NO'\n const a = s[sch[0]]\n const b = t[tch[0]]\n // console.log(s, t)\n if (a < b) {\n return sch.length > 1 ? 'NO' : 'YES'\n } else if (a > b) {\n // return tch.length > 1 ? 'NO' : 'YES'\n return 'NO'\n } else {\n // return sch.length > 1 ? 'NO' : 'YES'\n return 'NO'\n }\n }).join('\\n')\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const q = +lines[l++]\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += q\n output[i] = solve(qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n get(x) {\n return this.map[this.first + x]\n }\n getLast() {\n return this.map[this.last]\n }\n forEach(fn) {\n for (let i = this.first; i <= this.last; i++) {\n fn(this.map[i], i - this.first)\n }\n }\n}\n\nfunction solve(qs) {\n const s = Array(26).fill(0)\n const t = Array(26).fill(0)\n return qs.map(([type, k, x]) => {\n let add\n if (type === 1) {\n add = s\n } else {\n add = t\n }\n for (let i = 0; i < x.length; i++) {\n const j = x.charCodeAt(i) - 'a'.charCodeAt(0)\n add[j] += k\n }\n // console.log(s, t)\n const sch = []\n const tch = []\n for (let i = 0; i < s.length; i++) {\n if (s[i]) sch.push(i)\n if (t[i]) tch.push(i)\n }\n if (!sch.length) return 'YES'\n if (!tch.length) return 'NO'\n if (sch[0] < tch[tch.length - 1]) return 'YES'\n if (sch[0] > tch[tch.length - 1]) return 'NO'\n if (sch.length > 1) return 'NO'\n if (tch.length > 1) return 'NO'\n const a = s[sch[0]]\n const b = t[tch[0]]\n return a < b ? 'YES' : 'NO'\n }).join('\\n')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const q = +lines[l++]\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map((x, i) => i < 2 ? +x : x))\n l += q\n output[i] = solve(qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n get(x) {\n return this.map[this.first + x]\n }\n getLast() {\n return this.map[this.last]\n }\n forEach(fn) {\n for (let i = this.first; i <= this.last; i++) {\n fn(this.map[i], i - this.first)\n }\n }\n}\n\nfunction solve(qs) {\n const s = Array(26).fill(0)\n const t = Array(26).fill(0)\n return qs.map(([type, k, x]) => {\n let add\n if (type === 1) {\n add = s\n } else {\n add = t\n }\n for (let i = 0; i < x.length; i++) {\n const j = x.charCodeAt(i) - 'a'.charCodeAt(0)\n add[j] += k\n }\n // console.log(s, t)\n const sch = []\n const tch = []\n for (let i = 0; i < s.length; i++) {\n if (s[i]) sch.push(i)\n if (t[i]) tch.push(i)\n }\n if (!sch.length) return 'YES'\n if (sch[0] < tch[tch.length - 1]) return 'YES'\n if (sch.length > 1) return 'NO'\n const a = s[sch[0]]\n const b = t[tch[0]]\n return a < b ? 'YES' : 'NO'\n }).join('\\n')\n}\n"}], "src_uid": "d40f0f3b577a1a5cfad2a657d6a1b90a"} {"source_code": "var n = parseInt(readline());\nvar plusArr = [];\nvar minusArr = [];\nfor (var i = 0; i < n; i++) {\n var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n if (numbers[0] > 0) {\n plusArr.push({\n x: numbers[0],\n a: numbers[1]\n })\n }\n else {\n minusArr.push({\n x: Math.abs(numbers[0]),\n a: numbers[1]\n })\n }\n}\n\nfunction sortfunction(a, b){\n return (a.x - b.x)\n}\n\nplusArr.sort(sortfunction);\nminusArr.sort(sortfunction);\n\nvar sum = 0;\nvar min = Math.min(plusArr.length, minusArr.length);\nplusArr.forEach(function(apple, i) {\n if (i <= min)\n sum = sum + apple.a;\n});\nminusArr.forEach(function(apple, i) {\n if (i <= min)\n sum = sum + apple.a;\n});\n\nprint(sum);\n", "positive_code": [{"source_code": "function main() {\n var n = parseInt(readline()),\n rightList = {}, leftList = {}, result = 0;\n\n for(var index = 0; index < n; index++) {\n var XAi = readline().split(/\\s/gi).map(Number);\n\n if(XAi[0] < 0) {\n rightList[XAi[0]] = XAi[1];\n } else {\n leftList[XAi[0]] = XAi[1];\n }\n }\n\n var leftPos = Object.keys(leftList).map(Number).sort(function(a, b) { return a - b }),\n rightPos = Object.keys(rightList).map(Number).sort(function(a, b) { return b - a });\n\n if(rightPos.length > leftPos.length) {\n leftPos.forEach(function(pos) {\n result += leftList[pos];\n });\n\n rightPos.some(function(pos, index) {\n if(index <= leftPos.length) {\n result += rightList[pos];\n } else {\n return true;\n }\n });\n } else if(rightPos.length < leftPos.length) {\n rightPos.forEach(function(pos) {\n result += rightList[pos];\n });\n\n leftPos.some(function(pos, index) {\n if(index <= rightPos.length) {\n result += leftList[pos];\n } else {\n return true;\n }\n });\n } else {\n leftPos.forEach(function(pos) {\n result += leftList[pos];\n });\n\n rightPos.forEach(function(pos) {\n result += rightList[pos];\n });\n }\n \n print(result);\n};\n\nArray.prototype.getLastValue = function() {\n return this[this.length - 1];\n};\n\nmain();"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar plusArr = [];\nvar minusArr = [];\nfor (var i = 0; i < n; i++) {\n var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n if (numbers[0] > 0) {\n plusArr.push({\n x: numbers[0],\n a: numbers[1]\n })\n }\n else {\n minusArr.push({\n x: Math.abs(numbers[0]),\n a: numbers[1]\n })\n }\n}\nplusArr.sort();\nminusArr.sort();\n\nvar sum = 0;\nif ((Math.abs(plusArr.length - minusArr.length) == 0) || (Math.abs(plusArr.length - minusArr.length) == 1)) {\n plusArr.forEach(function(apple) {\n sum = sum + apple.a;\n });\n minusArr.forEach(function(apple) {\n sum = sum + apple.a;\n });\n}\nelse if (plusArr.length > minusArr.length) {\n for (var i=0; i < minusArr.length + 1; i++) {\n sum = sum + plusArr[i].a;\n }\n}\nelse {\n for (var i=0; i < plusArr.length + 1; i++) {\n sum = sum + minusArr[i].a;\n }\n}\n\nprint(sum);\n"}, {"source_code": "function main() {\n var n = parseInt(readline()),\n rightList = [ 0 ], leftList = [ 0 ], result = 0;\n\n for(var index = 0; index < n; index++) {\n var XAi = readline().split(/\\s/gi).map(Number);\n\n if(XAi[0] < 0) {\n rightList.push(rightList.getLastValue() + XAi[1]);\n } else {\n leftList.push(leftList.getLastValue() + XAi[1]);\n }\n }\n\n if(rightList.length > leftList.length) {\n result = leftList.getLastValue() + rightList[leftList.length];\n } else if(rightList.length < leftList.length) {\n result = rightList.getLastValue() + leftList[rightList.length];\n } else {\n result = rightList.getLastValue() + leftList.getLastValue();\n }\n\n print(result);\n};\n\nArray.prototype.getLastValue = function() {\n return this[this.length - 1];\n};\n\nmain();"}], "src_uid": "bf573af345509b2364ada6e613b6f998"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, k, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, str) {\n const a = 'a'.charCodeAt(0)\n //\n const dp = Array(n)//.fill(-1)\n let p = 0\n let pp = -1, pto\n while (p < n && k >= 0) {\n if (dp[p]) {\n p++\n continue\n }\n\n const connect = str.charCodeAt(p) - str.charCodeAt(pp)\n let cost, to\n if (pp >= 0 && k >= connect) {\n cost = connect\n to = pto\n } else {\n const max = str.charCodeAt(p) - a\n cost = Math.min(max, k)\n to = String.fromCharCode(str.charCodeAt(p) - cost)\n }\n k -= cost\n // console.log(str[p], to, cost)\n for (let i = 0; i < str.length; i++) {\n if (dp[i]) continue\n if (str[i] <= str[p]) {\n // dp[i] = p\n if (str[i] >= to) {\n dp[i] = to\n } else {\n dp[i] = str[i]\n }\n }\n }\n pp = p\n pto = to\n //\n p++\n }\n return dp.join('')\n}\n", "positive_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, k, a)=>{\n // if (k > 25) {\n // let result = new Array(n).fill('a');\n // return result.join('');\n // }\n\n let charmap = {};\n\n let aCode = 'a'.charCodeAt(0);\n\n for (let i = 0; i < n; i++) {\n charmap[a[i]] = a[i];\n }\n\n for (let i = 0; i < n; i++) {\n if (k <= 0) break;\n let curchar = charmap[a[i]];\n let idx = curchar.charCodeAt(0) - aCode;\n\n if (idx === 0) continue;\n let diff = Math.min(idx, k);\n let newchar = String.fromCharCode(aCode + (idx - diff));\n // console.log(`DEBUG newchar`, newchar);\n\n let found = false;\n\n for (let j = 1; j <= diff; j++) {\n let c = String.fromCharCode(aCode + (idx - j));\n // console.log(`DEBUG j ${j} c`, c);\n if (!!charmap[c] && charmap[c] !== c) {\n let nextchar = charmap[c];\n // console.log(`DEBUG j ${j} nextchar`, nextchar);\n for (let q = 0; q <= j; q++) {\n let cc = String.fromCharCode(aCode + (idx - j + q));\n charmap[cc] = nextchar;\n }\n\n k -= j;\n found = true;\n break;\n }\n }\n if (found) continue;\n\n k -= diff;\n \n for (let j = 0; j <= diff; j++) {\n let c = String.fromCharCode(aCode + (idx - j));\n charmap[c] = newchar;\n }\n // console.log(`DEBUG charmap`, charmap);\n }\n\n for (let i = 0; i < n; i++) {\n a[i] = charmap[a[i]];\n }\n return a.join('');\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n // let n = +readline();\n let [n, k] = ra();\n let a = readline().split('');\n console.log(`${calc(n, k, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, k] = ra();\n let S = readline().split('');\n LT({n, k, S});\n // PROCESSING:\n let get_prev = (ch)=>{\n if (ch!='a'){\n return String.fromCharCode(ch.charCodeAt(0)-1)\n }\n };\n let covered = {};\n let ops = 0;\n for (let i=0; i char.charCodeAt(0) - 97);\r\n let pre = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (nums[i] === 97) continue;\r\n let cur = nums[i];\r\n while (m && nums[i] > pre) {\r\n m--;\r\n let num = nums[i];\r\n for (let j = i; j < n; j++) {\r\n if (nums[j] === num) nums[j]--;\r\n }\r\n }\r\n if (nums[i] === pre) {\r\n for (let j = i; j < n; j++) {\r\n if (nums[j] === pre) nums[j] = 0;\r\n }\r\n }\r\n pre = Math.max(cur, pre);\r\n if (!m) {\r\n break;\r\n }\r\n }\r\n console.log(nums.map(num => String.fromCharCode(num + 97)).join(''));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n solve(n, m, s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, s) {\r\n const nums = s.split('').map(char => char.charCodeAt(0) - 97);\r\n let pre = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (nums[i] === 97) continue;\r\n let cur = nums[i];\r\n while (m && nums[i] > pre) {\r\n m--;\r\n let num = nums[i];\r\n for (let j = i; j < n; j++) {\r\n if (nums[j] === num) nums[j]--;\r\n }\r\n }\r\n pre = Math.max(cur, pre);\r\n if (!m) {\r\n break;\r\n }\r\n }\r\n console.log(nums.map(num => String.fromCharCode(num + 97)).join(''));\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n solve(n, m, s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, k, a)=>{\n // if (k > 25) {\n // let result = new Array(n).fill('a');\n // return result.join('');\n // }\n\n let charmap = {};\n\n let aCode = 'a'.charCodeAt(0);\n\n for (let i = 0; i < n; i++) {\n charmap[a[i]] = a[i];\n }\n\n for (let i = 0; i < n; i++) {\n if (k <= 0) break;\n let curchar = charmap[a[i]];\n let idx = curchar.charCodeAt(0) - aCode;\n\n if (idx === 0) continue;\n let diff = Math.min(idx, k);\n let newchar = String.fromCharCode(aCode + (idx - diff));\n // console.log(`DEBUG newchar`, newchar);\n\n let found = false;\n\n for (let j = 1; j < diff; j++) {\n let c = String.fromCharCode(aCode + (idx - j));\n // console.log(`DEBUG j ${j} c`, c);\n if (!!charmap[c] && charmap[c] !== c) {\n let nextchar = charmap[c];\n // console.log(`DEBUG j ${j} nextchar`, nextchar);\n for (let q = 0; q <= j; q++) {\n let cc = String.fromCharCode(aCode + (idx - j + q));\n charmap[cc] = nextchar;\n }\n\n k -= j;\n found = true;\n break;\n }\n }\n if (found) continue;\n\n k -= diff;\n \n for (let j = 0; j < diff; j++) {\n let c = String.fromCharCode(aCode + (idx - j));\n charmap[c] = newchar;\n }\n // console.log(`DEBUG charmap`, charmap);\n }\n\n for (let i = 0; i < n; i++) {\n a[i] = charmap[a[i]];\n }\n return a.join('');\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n // let n = +readline();\n let [n, k] = ra();\n let a = readline().split('');\n console.log(`${calc(n, k, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "b86c1533fdfe68fd4dea2bf99cd9e111"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nlet standardInputString = '';\r\nlet curLine = 0;\r\n\r\nconst readLine = () => {\r\n return standardInputString[curLine++];\r\n};\r\n\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split('\\n')\r\n .map(line => {\r\n return line.trim();\r\n });\r\n \r\n main();\r\n});\r\n\r\n/**\r\n * Test cases.\r\n * \r\n * 5\r\n * 1 15 // 15\r\n * 3 16 // 8\r\n * 5 19 // 6\r\n * 4 20 // 6\r\n * 1000000000 1 // 0\r\n */\r\n\r\n// https://codeforces.com/contest/1566/problem/A\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let _ = 0; _ < t; _ += 1) {\r\n const [n, s] = readLine().split(' ');\r\n\r\n const ans = Math.floor(\r\n s / Math.floor(n / 2 + 1),\r\n );\r\n\r\n console.log(ans);\r\n }\r\n};", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var terms = parseInt(caseArray[0]);\r\n var total = parseInt(caseArray[1]);\r\n var div = Math.floor(terms/2) + 1;\r\n var result = Math.floor(total/div);\r\n print(result);\r\n}"}, {"source_code": "function readStringArray() {\r\n\t\treturn readline().split(' ');\r\n\t}\r\n\tfunction readNumArray() {\r\n\t\treturn readStringArray().map(Number);\r\n\t}\r\n\r\n\tfunction main() {\r\n\t\tvar testCasesNum = +readline();\r\n\t\tfor (var i = 0; i < testCasesNum; i++) {\r\n\t\t\tvar ns = readStringArray();\r\n\t\t\tvar n = ns[0];\r\n\t\t\tvar s = ns[1];\r\n\t\t\tvar ind = n % 2 ? Math.floor(n / 2) : Math.floor(n / 2) - 1;\r\n\t\t\tvar res = Math.floor(s / (n - ind));\r\n\t\t\tprint(res);\r\n\t\t}\r\n\t}\r\n\r\n\tmain();"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = nextInt();\r\n\t\tvar size = Math.ceil((N + 1) / 2);\r\n\t\tmyout(Math.floor(S / size));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "0a05b11307fbb2536f868acf4e81c1e2"} {"source_code": "var num = readline().split(' ')\nvar n = parseInt(num[0])\nvar m = parseInt(num[1])\nvar arr = readline().split(' ')\n\n// var arr1 = []\n// for(var i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(BigInt)\n output[i] = solve(n, k)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k) {\n let cur = 1n\n let h = 0n\n while (cur < k) {\n // while (cur < n) {\n cur += k < cur ? k : cur\n h++\n }\n // return h\n return h + ceil(n - cur, k)\n}\nfunction ceil(a, b) {\n const k = a / b\n return a / b + (k * b < a ? 1n : 0n)\n}\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tlet tot = 1n, hr = 0n;\r\n\t\twhile (tot < k) {\r\n\t\t\ttot *= 2n;\r\n\t\t\thr++;\r\n\t\t}\r\n\r\n\t\tif (tot < n) {\r\n\t\t\thr += (n-tot+k-1n)/ k;\r\n\t\t}\r\n\r\n\t\tconsole.log(hr.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const solve = (n,k)=>{\r\n let i = 0n,cable = 1n;\r\n while(cableBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction ceilDiv (a, b) {\r\n\tlet res = a / b;\r\n\tif (res*b != a)\r\n\t\tres++;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tlet tot = 1n, hr = 0n;\r\n\t\twhile (tot < n) {\r\n\t\t\tconst cablesToUse = tot;\r\n\t\t\tif (cablesToUse >= k) {\r\n\t\t\t\thr += ceilDiv(n-tot, k);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\ttot += cablesToUse;\r\n\t\t\thr++;\r\n\t\t}\r\n\r\n\t\tconsole.log(hr.toString());\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n let l,j = n&(n-1n),cnt=0,h=n;\r\n if(j===0n){\r\n while(h!==1n){\r\n cnt++;\r\n h = h>>1n;\r\n }\r\n }\r\n else{\r\n while(h!==0n){\r\n cnt++;\r\n h = h>>1n;\r\n }\r\n }\r\n if(cnt<=k) {\r\n console.log(cnt+\"\");\r\n return;\r\n }\r\n h1 = n-((1n<<(k-1n))+k);\r\n if((h1)%k===0n) console.log(k+((h1)/k)+\"\");\r\n else console.log(k+((h1)/k)+1n+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n let l,j = n&(n-1n),cnt;\r\n if(j===0n) cnt = 1n;\r\n else cnt = 0n;\r\n let h = n,h1;\r\n while(h!==0n){\r\n cnt++;\r\n h = h>>1n;\r\n }\r\n if(cnt<=k) {\r\n console.log(cnt+\"\");\r\n return;\r\n }\r\n h1 = n-((1n<<(k-1n))+k);\r\n if((h1)%k===0n) console.log(k+((h1)/k)+\"\");\r\n else console.log(k+((h1)/k)+1n+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if((k===1n)||(n===2n)){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n let l,j = n^(n-1n);\r\n if(j===0n) l = 1n;\r\n else l = 0n;\r\n let cnt = 0n,h = n,h1;\r\n while(h!==l){\r\n cnt++;\r\n h = h>>1n;\r\n }\r\n if(cnt<=k) {\r\n console.log(cnt+\"\");\r\n return;\r\n }\r\n h1 = n-((1n<<(k-1n))+k);\r\n if((h1)%k===0n) console.log(k+((h1)/k)+\"\");\r\n else console.log(k+((h1)/k)+1n+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n let t;\r\n for(let i=1n;i<=k;i++){\r\n t = ((i *(i+1n))/2n)+1n;\r\n if(t>=n){\r\n console.log(i+\"\");\r\n return;\r\n }\r\n }\r\n let h = n-t;\r\n if(h%k===0n) console.log(k+(h/k)+\"\");\r\n else console.log(k+(h/k)+1n+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n let t;\r\n for(let i=1n;i<=k;i++){\r\n t = ((i *(i+1n))/2n)+1n;\r\n if(t>=n){\r\n console.log(i+\"\");\r\n return;\r\n }\r\n }\r\n let h = n-t;\r\n if((n-t)%k===0) console.log(k+(h/k)+\"\");\r\n else console.log(k+(h/k)+1n+\"\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n if(k>=n/2n){\r\n console.log((n/2n)+\"\");\r\n return;\r\n }\r\n let h = k*2n;\r\n let res = n-h;\r\n if(res%k===0n) console.log(k+(res/k)+\"\");\r\n else console.log(k+(res/k)+1n+\"\")\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(n===1n){\r\n console.log(0);\r\n return;\r\n }\r\n if(k===1n){\r\n console.log((n-1n)+\"\");\r\n return;\r\n }\r\n if(k>=n/2n){\r\n if(n%2n===0n) console.log((n/2n)+\"\");\r\n else console.log((n/2n)+1n+\"\");\r\n return;\r\n }\r\n let h = k*2n;\r\n let res = n-h;\r\n if(res%k===0n) console.log(k+(res/k)+\"\");\r\n else console.log(k+(res/k)+1n+\"\")\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iBigInt(cur));\r\n solve(n,k);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction ceilDiv (a, b) {\r\n\tlet res = a / b;\r\n\tif (res*b != a)\r\n\t\tres++;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tlet tot = 1n, hr = 0;\r\n\t\twhile (tot < n) {\r\n\t\t\tconst cablesToUse = tot;\r\n\t\t\tif (cablesToUse >= k) {\r\n\t\t\t\thr += Number(ceilDiv(n-tot, k));\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\ttot += cablesToUse;\r\n\t\t\thr++;\r\n\t\t}\r\n\r\n\t\tconsole.log(hr);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tlet tot = 1, hr = 0;\r\n\t\twhile (tot < n) {\r\n\t\t\tconst cablesToUse = Math.min(tot, k);\r\n\t\t\tif (cablesToUse == k) {\r\n\t\t\t\thr += Math.ceil((n-tot)/k);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\ttot += cablesToUse;\r\n\t\t\thr++;\r\n\t\t}\r\n\r\n\t\tconsole.log(hr);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "5df6eb50ead22b498bea69bb84341c06"} {"source_code": "(()=>{\"use strict\";var t={312:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,\"__esModule\",{value:!0});const u=r(n(747));let o=\"\",s=[],i=0,l=\"\";const a=\"local\"===process.argv[2],c=t=>{if(a)return s=u.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void u.default.writeFileSync(\"output.txt\",l);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,readNumbersMatrix:function(t){let e=[];for(let n=0;n0;)u.default.put(\"abcd\"[e]),e++,e%=4,t--}))},747:t=>{t.exports=require(\"fs\")}},e={};!function n(r){if(e[r])return e[r].exports;var u=e[r]={exports:{}};return t[r].call(u.exports,u,u.exports,n),u.exports}(965)})();", "positive_code": [{"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar arr = ['a', 'b', 'c', 'd'];\nfor (var i = 0; i < n; i++) {\n write(arr[i % 4]);\n}\n"}], "negative_code": [], "src_uid": "94278e9c55f0fc82b48145ebecbc515f"} {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, a, b] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var c = Array(n).fill(0);\n var d = [...h];\n var kq = 1e5;\n var kc = [];\n var tc = 0;\n function bf(i) {\n if (tc >= kq)\n return;\n if (i == n - 1) {\n if (d[n - 2] >= 0 || d[n - 1] >= 0)\n return;\n kq = tc;\n kc = [...c];\n return;\n }\n for (let j = Math.max(0, Math.ceil((d[i - 1] + 1) / b)); j < 1e2; j++) {\n tc += j;\n c[i] = j;\n d[i - 1] -= b * j;\n d[i + 1] -= b * j;\n d[i] -= a * j;\n bf(i + 1);\n tc -= j;\n c[i] = 0;\n d[i - 1] += b * j;\n d[i + 1] += b * j;\n d[i] += a * j;\n if (d[i] - a * j < 0 && i != n - 2)\n break;\n if (i == n - 2 && d[i] - a * j < 0 && d[i + 1] - b * j < 0)\n break;\n }\n }\n bf(1);\n console.log(kq);\n console.log(kc.map((v, i) => Array(v).fill(i + 1).join(' ')).join(' ').trim().replace(/\\s+/g, ' '));\n})();\n", "positive_code": [{"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\n\nprint(function(n, a, b) {\n\n\tvar h = readNums();\n\tvar nHits = 0;\n\tvar nBest = -1;\n\tvar hits = new Int32Array(222);\n\tvar best = new Int32Array(222);\n\n\tvar ans = [];\n\tsolve(1);\n\tfor (var i = 0; i < nBest; i++) {\n\t\tans.push(best[i] + 1);\n\t}\n\n\treturn nBest + '\\n' + ans.join(' ');\n\n\n\tfunction hit(k) {\n\t\th[k] -= a;\n\t\th[k - 1] -= b;\n\t\th[k + 1] -= b;\n\t\thits[nHits++] = k;\n\t}\n\n\tfunction heal(k) {\n\t\th[k] += a;\n\t\th[k - 1] += b;\n\t\th[k + 1] += b;\n\t\tnHits--;\n\t}\n\n\tfunction solve(k) {\n\t\tif (k === n - 1) {\n\t\t\tvar t = 0;\n\t\t\twhile (h[k] >= 0) {\n\t\t\t\t++t;\n\t\t\t\thit(k - 1);\n\t\t\t}\n\t\t\tif (h[k - 1] < 0) {\n\t\t\t\tif (nBest === -1 || nHits < nBest) {\n\t\t\t\t\tnBest = nHits;\n\t\t\t\t\tfor (var i = 0; i < nHits; i++) {\n\t\t\t\t\t\tbest[i] = hits[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (t--) {\n\t\t\t\theal(k - 1);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tvar t = 0;\n\t\twhile (h[k - 1] >= 0) {\n\t\t\t++t;\n\t\t\thit(k);\n\t\t}\n\n\t\twhile (h[k] >= 0) {\n\t\t\t++t;\n\t\t\tsolve(k + 1);\n\t\t\thit(k);\n\t\t}\n\t\tsolve(k + 1);\n\t\twhile (t--) {\n\t\t\theal(k);\n\t\t}\n\t}\n\n\n\n}.apply(0, readNums()));\n\n\nfunction readNums() {\n\treturn readline().split(' ').map(Number);\n}"}, {"source_code": "var input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, a, b] = inputs[0].split(' ').map(v => +v);\n var h = inputs[1].split(' ').map(v => +v);\n var c = Array(n).fill(0);\n var d = [...h];\n var kq = 1e5;\n var kc = [];\n var tc = 0;\n\n function bf(i) {\n if (tc >= kq) return;\n if (i == n - 1) {\n if (d[n - 2] >= 0 || d[n - 1] >= 0) return;\n kq = tc;\n kc = [...c];\n return;\n }\n for (let j = Math.max(0, Math.ceil((d[i - 1] + 1) / b)); j < 1e2; j++) {\n tc += j;\n c[i] = j;\n d[i - 1] -= b * j;\n d[i + 1] -= b * j;\n d[i] -= a * j;\n bf(i + 1);\n tc -= j;\n c[i] = 0;\n d[i - 1] += b * j;\n d[i + 1] += b * j;\n d[i] += a * j;\n if (d[i] - a * j < 0 && i != n - 2) break;\n if (i == n - 2 && d[i] - a * j < 0 && d[i + 1] - b * j < 0) break;\n }\n }\n\n bf(1);\n console.log(kq);\n console.log(kc.map((v, i) => Array(v).fill(i + 1).join(' ')).join(' ').trim().replace(/\\s+/g, ' '))\n})();\n\n"}, {"source_code": "s=readline().split(' ').map(v=>+v)\nn=s[0]\na=s[1]\nb=s[2]\nh=readline().split(' ').map(v=>+v)\nc=Array(n).fill(0)\nd=[...h]\n\nkq=1e5;\nkc=[];\ntc = 0;\n\nfunction bf(i) {\n\tif (tc >= kq) return;\n if (i==n-1) {\n if (d[n-2]>=0 || d[n-1] >=0 ) return;\n kq = tc;\n kc = [...c];\n return;\n }\n for (var j=Math.max(0, Math.ceil((d[i-1]+1)/b)); j<1e2;j++) {\n \ttc+=j;\n c[i]=j;\n d[i-1] -= b*j;\n d[i+1] -= b*j;\n d[i] -= a*j;\n bf(i+1);\n tc-=j;\n c[i]=0;\n d[i-1] += b*j;\n d[i+1] += b*j;\n d[i] += a*j;\n if (d[i] - a*j < 0 && i!=n-2) break;\n if(i == n-2 && d[i] - a*j < 0 && d[i+1] - b*j < 0) break;\n }\n}\n\nbf(1);\nprint(kq);\nprint(kc.map((v,i)=> Array(v).fill(i+1).join(' ')).join(' ').trim().replace(/\\s+/g,' '))\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\nprint(function(n, a, b) {\n\n\tvar h = readNums();\n\tvar ans = [];\n\n\th = h.map(function(v) {\n\t\treturn v + 1;\n\t});\n\twhile (true) {\n\t\tvar i = maxP(n, a, b, h);\n\t\tif (i > -1) {\n\t\t\tans.push(i + 1);\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ans.length + '\\n' + ans.join(' ');\n\n}.apply(0, readNums()));\n\nfunction maxP(n, a, b, h) {\n\tvar max = -1;\n\tvar maxIndex = 0;\n\tvar f = true;\n\tfor (var i = 0; i < n; i++) {\n\t\tif (h[i] > 0) {\n\t\t\tf = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (f) {\n\t\treturn -1;\n\t}\n\n\tfor (var i = 1; i < n - 1; i++) {\n\t\tvar p = 0;\n\t\tif (h[i] >= a) {\n\t\t\tp += a;\n\t\t} else {\n\t\t\tp += h[i];\n\t\t}\n\t\tif (h[i - 1] >= b) {\n\t\t\tp += b;\n\t\t} else {\n\t\t\tp += h[i - 1];\n\t\t}\n\t\tif (h[i + 1] >= b) {\n\t\t\tp += b;\n\t\t} else {\n\t\t\tp += h[i + 1];\n\t\t}\n\t\tif (p > max) {\n\t\t\tmax = p;\n\t\t\tmaxIndex = i;\n\t\t}\n\t}\n\tif (h[maxIndex] >= a) {\n\t\th[maxIndex] -= a;\n\t} else {\n\t\th[maxIndex] = 0;\n\t}\n\tif (h[maxIndex - 1] >= b) {\n\t\th[maxIndex - 1] -= b;\n\t} else {\n\t\th[maxIndex - 1] = 0;\n\t}\n\tif (h[maxIndex + 1] >= b) {\n\t\th[maxIndex + 1] -= b;\n\t} else {\n\t\th[maxIndex + 1] = 0;\n\t}\n\n\treturn maxIndex;\n}\n\n\nfunction readNums() {\n\treturn readline().split(' ').map(Number);\n}"}, {"source_code": "\nvar s = readline().split(' ');\nvar n = parseInt(s[0]);\nvar a = parseInt(s[1]);\nvar b = parseInt(s[2]);\n\nvar h = readline().split(' ').map(function(v){\n\treturn parseInt(v);\n});\n\nvar ret = [];\nfor(var i=0; i=0 ){\n\t\tvar ni = Math.ceil( (h[i-1]+1)/b );\n\t\tret[i] += ni;\n\t\th[i] -= ni*a;\n\t\th[i+1] -= ni*b;\n\t}\n}\nvar last = n-1;\nif(h[last]>=0){\n\tvar ni = Math.ceil( (h[last]+1)/b );\n\tret[last-1] += ni;\n\th[last-1] -= ni*a;\n\th[last] -= ni*b;\n}\nif(h[last-1]>=0){\n\tvar ni = Math.ceil( (h[last-1]+1)/a );\n\tret[last-1] += ni;\n\th[last-1] -= ni*a;\n\th[last] -= ni*b;\n}\n\ns = [];\nfor(var i = 0; i 0){\n\t\tfor(var j=0; j -1) {\n\t\t\tans.push(i + 1);\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ans.length + '\\n' + ans.join(' ');\n\n}.apply(0, readNums()));\n\nfunction maxP(n, a, b, h) {\n\tvar max = -1;\n\tvar maxIndex = 0;\n\tvar f = true;\n\tfor (var i = 0; i < n; i++) {\n\t\tif (h[i] > 0) {\n\t\t\tf = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (f) {\n\t\treturn -1;\n\t}\n\n\tfor (var i = 1; i < n - 1; i++) {\n\t\tvar p = 0;\n\t\tif (h[i] >= a) {\n\t\t\tp += a;\n\t\t} else {\n\t\t\tp += h[i];\n\t\t}\n\t\t// if (i > 0) {\n\t\tif (h[i - 1] >= b) {\n\t\t\tp += b;\n\t\t} else {\n\t\t\tp += h[i - 1];\n\t\t}\n\t\t// }\n\t\t// if (i < n - 1) {\n\t\tif (h[i + 1] >= b) {\n\t\t\tp += b;\n\t\t} else {\n\t\t\tp += h[i + 1];\n\t\t}\n\t\t// }\n\t\tif (p > max) {\n\t\t\tmax = p;\n\t\t\tmaxIndex = i;\n\t\t}\n\t}\n\tif (h[maxIndex] >= a) {\n\t\th[maxIndex] -= a;\n\t} else {\n\t\th[maxIndex] = 0;\n\t}\n\t// if (maxIndex > 0) {\n\tif (h[maxIndex - 1] >= b) {\n\t\th[maxIndex - 1] -= b;\n\t} else {\n\t\th[maxIndex - 1] = 0;\n\t}\n\t// }\n\t// if (maxIndex < n - 1) {\n\tif (h[maxIndex + 1] >= b) {\n\t\th[maxIndex + 1] -= b;\n\t} else {\n\t\th[maxIndex + 1] = 0;\n\t}\n\t// }\n\n\treturn maxIndex;\n}\n\n\nfunction readNums() {\n\treturn readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n, a, b) {\n\tvar h = readline().split(' ').map(Number).map(function(v) {\n\t\treturn v + 1;\n\t});\n\n\tvar ans = [];\n\twhile (true) {\n\t\tvar max = -1;\n\t\tvar curr = -1;\n\n\t\tif (h.every(function(v) {\n\t\t\treturn v === 0;\n\t\t})) break;\n\n\t\tfor (var i = 1; i < n - 1; i++) {\n\t\t\tvar x = 0;\n\t\t\tx += Math.min(h[i - 1], b);\n\t\t\tx += Math.min(h[i], a);\n\t\t\tx += Math.min(h[i + 1], b);\n\t\t\tif (x > max) {\n\t\t\t\tmax = x;\n\t\t\t\tcurr = i;\n\t\t\t}\n\t\t}\n\n\t\tans.push(curr+1);\n\t\th[curr - 1] = Math.max(0, h[curr - 1] - b);\n\t\th[curr] = Math.max(0, h[curr] - a);\n\t\th[curr + 1] = Math.max(0, h[curr + 1] - b);\n\t}\n\n\treturn ans.length + '\\n' + ans.join(' ');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, a, b) {\n\tvar h = readline().split(' ').map(Number).map(function(v) {\n\t\treturn v + 1;\n\t});\n\n\tvar ans = [];\n\twhile (true) {\n\t\tvar max = -1;\n\t\tvar curr = -1;\n\n\t\tif (h.every(function(v) {\n\t\t\treturn v === 0;\n\t\t})) break;\n\n\t\tfor (var i = 1; i < n - 1; i++) {\n\t\t\tvar x = 0;\n\t\t\tx += Math.min(h[i - 1], b);\n\t\t\tx += Math.min(h[i], a);\n\t\t\tx += Math.min(h[i + 1], b);\n\t\t\tif (x > max) {\n\t\t\t\tmax = x;\n\t\t\t\tcurr = i;\n\t\t\t}\n\t\t}\n\n\t\tans.push(curr);\n\t\th[curr - 1] = Math.max(0, h[curr - 1] - b);\n\t\th[curr] = Math.max(0, h[curr] - a);\n\t\th[curr + 1] = Math.max(0, h[curr + 1] - b);\n\t}\n\n\treturn ans.length + '\\n' + ans.join(' ');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "s=readline().split(' ').map(v=>+v)\nn=s[0]\na=s[1]\nb=s[2]\nh=readline().split(' ').map(v=>+v)\nc=Array(n).fill(0)\nd=[...h]\n\nkq=1e5;\nkc=[];\ntc = 0;\n\nfunction bf(i) {\n\tif (tc >= kq) return;\n if (i==n-1) {\n if (d[n-2]>=0 || d[n-1] >=0 ) return;\n if (kq > tc) {\n kq = tc;\n kc = [...c];\n }\n return;\n }\n for (j=Math.max(0, Math.ceil((d[i-1]+1)/b)); j<1e2;j++) {\n \ttc+=j;\n c[i]=j;\n d[i-1] -= b*j;\n d[i+1] -= b*j;\n d[i] -= a*j;\n bf(i+1);\n tc-=j;\n c[i]=0;\n d[i-1] += b*j;\n d[i+1] += b*j;\n d[i] += a*j;\n if (d[i] - a*j < 0 && i!=n-2) break;\n if(i == n-2 && d[i] - a*j < 0 && d[i+1] - b*j < 0) break;\n }\n}\n\nbf(1);\nprint(kq);\nprint(kc.map((v,i)=> Array(v).fill(i+1).join(' ')).join(' ').trim().replace(/\\s+/g,' '))\n\n\n\n\n\n\n\n\n"}], "src_uid": "a9bad412597726f8cdc0cfa2da891bc4"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n d = rns(n);\r\n let res = [];\r\n const cache = Array.from({\r\n length: n\r\n }, () => new Map());\r\n const path = [];\r\n const dfs = (i, p) => {\r\n if (i === n) {\r\n res = [...path];\r\n return 1;\r\n }\r\n if (cache[i].has(p)) return cache[i].get(p);\r\n path.push(p + d[i]);\r\n let ans = dfs(i + 1, p + d[i]);\r\n path.pop();\r\n if (ans > 1) return ans;\r\n path.push(p + d[i]);\r\n if (d[i] && p >= d[i]) ans += dfs(i + 1, p - d[i]);\r\n path.pop();\r\n cache[i].set(p, ans);\r\n return ans;\r\n };\r\n let cnt = dfs(0, 0);\r\n if (cnt === 1) return res.join(' ');else return -1;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(\" \").map(Number);\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(\" \");\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt();\r\n\r\n for (let i = 0; i < T; ++i) {\r\n const n = readInt();\r\n const drr = readArrayInt();\r\n const arr = [];\r\n\r\n let check = false;\r\n for (let i = 0; i < n; i++) {\r\n const e = drr[i];\r\n if (i === 0) {\r\n arr.push(e);\r\n } else {\r\n if (arr[arr.length - 1] - e < 0) {\r\n arr.push(arr[arr.length - 1] + e);\r\n } else {\r\n arr.push(arr[arr.length - 1] - e);\r\n }\r\n\r\n // console.log(arr[arr.length - 1], e, arr[arr.length - 1] - e, \"---\");\r\n if (arr[arr.length - 1] - arr[arr.length - 2] < e) {\r\n console.log(-1);\r\n check = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (!check) {\r\n let ans = \"\";\r\n arr.map((e) => {\r\n ans += e + \" \";\r\n });\r\n console.log(ans);\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve();\r\n}\r\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n const a = [];\r\n a.push(d[0])\r\n for (let i = 1; i < n; i++) {\r\n\r\n let k = a.length - 1\r\n\r\n let op = ((a[k] - d[i]) < 0) ? (a[k] + d[i]) : (a[k] - d[i])\r\n a.push(op)\r\n\r\n k = a.length - 1\r\n if (a[k] - a[k - 1] < d[i]) return -1\r\n\r\n\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\n\r\nconst arr = []\r\nreadline.on('line', data => {\r\n arr.push(data.split(' ').map(i => parseInt(i)))\r\n})\r\n\r\nreadline.on('close', () => {\r\n main()\r\n} )\r\n\r\nfunction main(){\r\n let [n] = arr \r\n\r\n let line = 2\r\n for(let i = 0; i < n; i++){\r\n let current = arr[line], result = -1\r\n line += 2\r\n\r\n let newarr = [0]\r\n for(let i = 0; i < current.length; i++){\r\n if(current[i] && newarr[newarr.length-1] - current[i] >= 0){\r\n newarr = -1\r\n break\r\n }else{\r\n newarr.push(current[i] + newarr[newarr.length -1])\r\n }\r\n }\r\n \r\n if(newarr === -1){\r\n console.log(newarr)\r\n }else {\r\n let s = \"\"\r\n for(let i of newarr.slice(1)) s += i + \" \"\r\n console.log(s)\r\n }\r\n\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const mainLength = readline();\n for (let l = 0; l < mainLength; l++) {\n\n var n = readline();\n var d = readline().split(\" \").map(x => parseInt(x));\n var a = [];\n var checked = false;\n var out\n\n for (let i = 0; i < n; i++) {\n if (i == 0)\n a[i] = (d[i])\n else {\n var i_one = a[i - 1];\n var x = d[i] + a[i - 1];\n // var y = d[i] - a[i - 1];\n var y = Math.abs(d[i] - a[i - 1]);\n var cond1 = (Math.abs(x - i_one))\n var cond2 = (Math.abs(y - i_one))\n if (\n cond1 == cond2\n && (x != y)\n ) {\n // if ((x < 0 && y < 0) && (x != y)) {\n checked = true;\n break;\n } else if (cond1 == d[i]) {\n a[i] = x\n } else {\n a[i] = y\n }\n }\n }\n if (checked)\n out = '-1' + '\\n'\n else\n out = a.join(' ') + '\\n'\n process.stdout.write(out);\n // console.log(out);\n\n }\n\n}\n// function foo(x) {\n// process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n// console.log(x); // with auto '\\n' (newline)\n// }"}], "negative_code": [{"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n \r\n a[i] = d[i] + a[i - 1]\r\n if( a[i] <= 0 ) a[i - 1] - d[i]\r\n \r\n if ( \r\n (d[i] + a[i - 1]) > 0 \r\n && (a[i - 1] - d[i]) > 0 \r\n && (d[i] + a[i - 1]) != (a[i - 1] - d[i]) \r\n ) return -1\r\n \r\n i++\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n \r\n a[i] = d[i] + a[i - 1]\r\n if( a[i] <= 0 ) a[i - 1] - d[i]\r\n \r\n if ( (d[i] + a[i - 1]) != (a[i - 1] - d[i]) ) return -1\r\n \r\n i++\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n \r\n a[i] = d[i] + a[i - 1]\r\n if( a[i] <= 0 ) a[i - 1] - d[i]\r\n \r\n if (d[i] + a[i - 1] > 0 != a[i - 1] - d[i] ) return -1\r\n \r\n i++\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n // a[1] = d[0] + d[1]\r\n\r\n let i = 1\r\n while (i < n) {\r\n if (d[i] < d[i - 1] && i > 1) return -1\r\n else a[i] = d[i] + a[i - 1]\r\n i++\r\n }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n // first array \r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n if (d[i] < d[i - 1]) return -1\r\n else a[i] = d[i] + a[i - 1]\r\n i++\r\n }\r\n\r\n // second array\r\n // let b = new Array(n).fill(0)\r\n // b[0] = d[0]\r\n // b[1] = d[0] + d[1]\r\n\r\n // i = 2\r\n // while (i < n) { \r\n // if(d[i] < d[i - 1]) b[i] = b[i] = Math.abs(d[i] - b[i - 1])\r\n // else b[i] = d[i] + b[i - 1]\r\n // i++\r\n // }\r\n\r\n return a.join(' ')\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n // first array \r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n a[i] = d[i] + a[i - 1]\r\n i++\r\n }\r\n\r\n // second array\r\n let b = new Array(n).fill(0)\r\n b[0] = d[0]\r\n b[1] = d[0] + d[1]\r\n\r\n i = 2\r\n while (i < n) { \r\n if(d[i] < d[i - 1]) b[i] = b[i] = Math.abs(d[i] - b[i - 1])\r\n else b[i] = d[i] + b[i - 1]\r\n i++\r\n }\r\n\r\n return (a.join(' ') === b.join(' ')) ? a.join(' ') : -1\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n // first array \r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n a[i] = d[i] + a[i - 1]\r\n i++\r\n }\r\n\r\n // second array\r\n let b = new Array(n).fill(0)\r\n b[0] = d[0]\r\n b[1] = d[0] + d[1]\r\n\r\n i = 2\r\n while (i < n) {\r\n if (d[i] >= d[i - 1]) b[i] = d[i] + b[i - 1]\r\n else b[i] = b[i] = Math.abs(d[i] - b[i - 1])\r\n i++\r\n }\r\n\r\n return (a.join(' ') === b.join(' ')) ? a.join(' ') : -1\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n\r\n\r\n\r\n\r\nconst getSolution = (n, d) => {\r\n // first array \r\n let a = new Array(n).fill(0)\r\n a[0] = d[0]\r\n a[1] = d[0] + d[1]\r\n\r\n let i = 2\r\n while (i < n) {\r\n a[i] = d[i] + a[i - 1]\r\n i++\r\n }\r\n\r\n // second array\r\n let b = new Array(n).fill(0)\r\n b[0] = d[0]\r\n b[1] = d[0] + d[1]\r\n\r\n i = 2\r\n while (i < n) {\r\n if (d[i] >= d[i - 1]) b[i] = d[i] + b[i - 1]\r\n else b[i] = b[i] = Math.abs(d[i] - b[i - 1])\r\n i++\r\n }\r\n\r\n return (a.join(' ') === b.join(' ')) ? a.join(' ') : '-1'\r\n}\r\n\r\n\r\n// Driver Function Starts //\r\nfunction main() {\r\n\r\n let testcases = parseInt(readline())\r\n while (testcases--) {\r\n\r\n let n = parseInt(readline())\r\n let d = readline().split(' ').map(Number)\r\n console.log(getSolution(n, d))\r\n }\r\n\r\n}\r\n// Driver Function Ends //"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\n\r\nconst arr = []\r\nreadline.on('line', data => {\r\n arr.push(data.split(' ').map(i => parseInt(i)))\r\n})\r\n\r\nreadline.on('close', () => {\r\n main()\r\n} )\r\n\r\nfunction main(){\r\n let [n] = arr \r\n\r\n let line = 2\r\n for(let i = 0; i < n; i++){\r\n let current = arr[line], result = -1\r\n line += 2\r\n\r\n let newarr = [0]\r\n for(let i = 0; i < current.length; i++){\r\n if(current[i] !== 0 && newarr[newarr.length-1] - current[i] >= 0){\r\n newarr = -1\r\n break\r\n }else{\r\n newarr.push(current[i] + newarr[newarr.length -1])\r\n }\r\n }\r\n \r\n if(newarr === -1){\r\n console.log(newarr)\r\n }else {\r\n let s = \"\"\r\n for(let i of newarr) s += i + \" \"\r\n console.log(s)\r\n }\r\n\r\n }\r\n}"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\n\r\nconst arr = []\r\nreadline.on('line', data => {\r\n arr.push(data.split(' ').map(i => parseInt(i)))\r\n})\r\n\r\nreadline.on('close', () => {\r\n main()\r\n} )\r\n\r\nfunction main(){\r\n let [n] = arr \r\n\r\n let line = 2\r\n for(let i = 0; i < n; i++){\r\n let current = arr[line], result = -1\r\n line += 2\r\n\r\n let newarr = [0]\r\n for(let i = 0; i < current.length; i++){\r\n if(current[i] !== 0 && newarr[newarr.length-1] - current[i] >= 0){\r\n newarr = -1\r\n break\r\n }else{\r\n newarr.push(current[i] + newarr[newarr.length -1])\r\n }\r\n }\r\n console.log(\r\n newarr === -1 ? -1 : newarr.slice(1)) \r\n\r\n }\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n for (let i = 0; i < x; i++) {\n var n = readline();\n var drr = readline().split(\" \").map(x => parseInt(x));\n var arr = [];\n var checked = false;\n var out\n\n for (let j = 0; j < n; j++) {\n\n var a = arr[j - 1] + drr[j];\n var b = arr[j - 1] - drr[j];\n if ((a > 0 && b > 0) && (a != b)) {\n checked = true;\n break;\n }\n\n if (j == 0)\n arr.push(drr[j])\n else\n arr.push(drr[j] + arr[j - 1])\n }\n if (checked)\n out = '-1' + '\\n'\n else\n out = arr.join(' ') + '\\n'\n process.stdout.write(out);\n // console.log(out);\n\n }\n\n}\n// function foo(x) {\n// process.stdout.write(\"hello: \"); // without auto '\\n' (newline)\n// console.log(x); // with auto '\\n' (newline)\n// }"}], "src_uid": "f4b790bef9a6cbcd5d1f9235bcff7c8f"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar stampNum = parseInt(readline());\n\n\tvar cities = [];\n\n\tvar count = { augment: function(key) {\n\t\tif (this[key] === undefined) {\n\t\t\tthis[key] = 1;\n\t\t\tcities.push(key);\n\t\t}\n\t\telse {\n\t\t\tthis[key] += 1;\n\t\t}\n\t}};\n\t\n\tvar link = { augment: function(key, value) {\n\t\tif (this[key] === undefined) {\n\t\t\tthis[key] = [value];\n\t\t}\n\t\telse {\n\t\t\tthis[key].push(value);\n\t\t}\n\t}};\n\n\tfor (var i = 0; i < stampNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tcount.augment(pair[0]);\n\t\tcount.augment(pair[1]);\n\t\tlink.augment(pair[0], pair[1]);\n\t\tlink.augment(pair[1], pair[0]);\n\t}\n\n\tfor (var i = 0; i < cities.length; ++i) {\n\t\tif (count[cities[i]] == 1) {\n\t\t\tvar previous = cities[i];\n\t\t\tvar path = [previous];\n\t\t\tvar current = link[previous];\n\t\t\twhile (true) {\n\t\t\t\tpath.push(current);\n\t\t\t\tif (count[current] == 1) {\n\t\t\t\t\tprint(path.join(\" \"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (link[current][0] != previous) {\n\t\t\t\t\tprevious = current;\n\t\t\t\t\tcurrent = link[current][0];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tprevious = current;\n\t\t\t\t\tcurrent = link[current][1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar stampNum = parseInt(readline());\n\n\tvar cities = [];\n\n\tvar count = { augment: function(key) {\n\t\tif (this[key] === undefined) {\n\t\t\tthis[key] = 1;\n\t\t\tcities.push(key);\n\t\t}\n\t\telse {\n\t\t\tthis[key] += 1;\n\t\t}\n\t}};\n\t\n\tvar link = { augment: function(key, value) {\n\t\tif (this[key] === undefined) {\n\t\t\tthis[key] = [value];\n\t\t}\n\t\telse {\n\t\t\tthis[key].push(value);\n\t\t}\n\t}};\n\n\tfor (var i = 0; i < stampNum; ++i) {\n\t\tvar pair = tokenizeIntegers(readline());\n\t\tcount.augment(pair[0]);\n\t\tcount.augment(pair[1]);\n\t\tlink.augment(pair[0], pair[1]);\n\t\tlink.augment(pair[1], pair[0]);\n\t}\n\n\tfor (var i = 0; i < cities.length; ++i) {\n\t\tif (count[cities[i]] == 1) {\n\t\t\tvar previous = cities[i];\n\t\t\tvar path = [previous];\n\t\t\tvar current = link[previous];\n\t\t\twhile (true) {\n\t\t\t\tpath.push(current);\n\t\t\t\tif (count[current] == 1) {\n\t\t\t\t\tprint(path.join(\" \"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvar neighbors = link[current];\n\t\t\t\tif (neighbors[0] != previous) {\n\t\t\t\t\tprevious = current;\n\t\t\t\t\tcurrent = neighbors[0];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tprevious = current;\n\t\t\t\t\tcurrent = neighbors[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "4c9d3e560f1ea152259ec838879b7512"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar stations = \"\";\nvar subST1 = \"\";\nvar subST2 = \"\";\nvar ind = 0;\n\nrl.on('line', (input) => {\n if (ind == 0) {\n stations = input;\n ind++;\n } else if (ind == 1) {\n subST1 = input;\n ind++;\n }\n else {\n subST2 = input;\n /** */\n fw = false;\n bw = false;\n fw = ISTrue(stations, subST1, subST2);\n\n stations = reverceStr(stations);\n bw = ISTrue(stations, subST1, subST2);\n\n if (fw && bw)\n console.log(\"both\");\n else if (fw)\n console.log(\"forward\");\n else if (bw)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n\n /** */\n rl.close();\n }\n});\n\n\n\nfunction ISTrue(s, first, second) {\n let indexOfFirst = s.indexOf(first);\n let lastIndexOFsecond = s.lastIndexOf(second);\n return indexOfFirst != -1 && lastIndexOFsecond != -1 &&\n (indexOfFirst + first.length - 1) < lastIndexOFsecond;\n}\n\nfunction reverceStr(s) {\n /* let arr = s.split('');\n let limit = parseInt(s.length / 2);\n for (let i = 0, j = s.length - 1; i < limit; i++ , j--) {\n let t = arr[i];\n arr[i] = arr[j];\n arr[j] = t;\n }\n return arr.join('');*/\n temp=\"\";\n for(let i=s.length-1;i>=0;i--)\n temp+=s.charAt(i);\n\n return temp; \n}", "positive_code": [{"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction myFunction(s, array, index) {\n for (var i = index.x; i < array.length; i++) {\n \n if (s == array.substr(i, s.length)) \n {\n index.x = i+s.length;\n return true;\n }\n }\n index.x = 0;\n return false;\n}\n\nfunction reverseString(str) {\n var splitString = str.split(\"\");\n var reverseArray = splitString.reverse();\n var joinArray = reverseArray.join(\"\");\n return joinArray;\n}\n\nvar n = -1;\nvar sleep1 = \"\";\nvar sleep2 = \"\";\nvar array = \"\";\nvar index = { x: 0 };\nvar startToFinish1 = false;\nvar startToFinish2 = false;\nvar finishToStart1 = false;\nvar finishToStart2 = false;\nvar answer = \"\";\n\nrl.on(\"line\", input => {\n if (n == -1) \n {\n array = input;\n n=0;\n }\n else if (n == 0) {\n sleep1 = input;\n startToFinish1 = myFunction(sleep1, array, index);\n n++;\n } else {\n sleep2 = input;\n startToFinish2 = myFunction(sleep2, array, index);\n var revarray = reverseString(array);\n index.x = 0;\n finishToStart1 = myFunction(sleep1, revarray, index);\n finishToStart2 = myFunction(sleep2, revarray, index); \n\n if (startToFinish1 && startToFinish2 && finishToStart1 && finishToStart2)\n answer = \"both\";\n else if (startToFinish1 && startToFinish2) answer = \"forward\";\n else if (finishToStart1 && finishToStart2) answer = \"backward\";\n else answer = \"fantasy\";\n }\n}).on(\"close\", () => {\n console.log(answer);\n //console.log(sleep2);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar check = function (flags, first, second) {\n var fIndex = flags.indexOf(first);\n var sLastIndex = flags.lastIndexOf(second);\n\n return fIndex != -1 && sLastIndex != -1 && fIndex + first.length - 1 < sLastIndex;\n\n};\n\n\n\n\nvar flags, first, second;\nvar i = 0;\nrl.on('line', (input) => {\n if (i == 0) {\n flags = input;\n i++;\n } else if (i == 1) {\n first = input;\n i++;\n } else {\n second = input;\n /* our code here...\n */\n var f = check(flags, first, second);\n flags = flags.split(\"\").reverse().join(\"\");\n var b = check(flags, first, second);\n if (f && b) console.log(\"both\");\n else if (f) console.log(\"forward\");\n else if (b) console.log(\"backward\");\n else console.log(\"fantasy\");\n rl.close();\n //end of our code....\n }\n}).on('close', () => {\n\n});"}, {"source_code": "var fa = readline()\nvar fs = readline()\nvar fe = readline()\n\nvar f = false\nvar b = false\n\nvar sif = fa.indexOf(fs)\nvar eif = fa.lastIndexOf(fe)\nvar sib = fa.lastIndexOf(fs.split('').reverse().join(''))\nvar eib = fa.indexOf(fe.split('').reverse().join(''))\n\nif (~sif && ~eif && eif - sif >= fs.length) f = true\nif (~eib && ~sib && sib - eib >= fe.length) b = true\n\nif (f && b) {print('both')}\nelse if (f && !b) {print('forward')}\nelse if (!f && b) {print('backward')}\nelse {print('fantasy')}"}, {"source_code": "function stringReverse(str) {\n return str.split('').reverse().join('');\n}\n\nfunction check(str, subStr1, subStr2) {\n var index1 = str.indexOf(subStr1), index2 = str.lastIndexOf(subStr2);\n return index1 > -1 && index2 > -1 && index1 + subStr1.length - 1 < index2;\n}\n\nfunction has(first, last) {\n if(first && last) {\n return('both');\n }\n else if(first) {\n return('forward');\n }\n else if(last) {\n return('backward');\n }\n else {\n return('fantasy');\n }\n}\n\nvar str = readline(), subStr1 = readline(), subStr2 = readline();\nprint(has(check(str, subStr1, subStr2), check(stringReverse(str), subStr1, subStr2)));"}, {"source_code": "sequence = readline()\nfirstTest = readline()\nsecondTest = readline()\n\nisForward = false\nisBackward = false\n\nif ((index = sequence.indexOf(firstTest)) >= 0) {\n if (sequence.indexOf(secondTest, index + firstTest.length) >= 0) {\n isForward = true;\n }\n}\n\nsequenceReverse = sequence.split(\"\").reverse().join(\"\")\n\nif ((index = sequenceReverse.indexOf(firstTest)) >= 0) {\n if (sequenceReverse.indexOf(secondTest, index + firstTest.length) >= 0) {\n isBackward = true;\n }\n}\n\nif (isForward && isBackward) {\n print(\"both\")\n} else if (isForward) {\n print(\"forward\")\n} else if (isBackward) {\n print(\"backward\")\n} else {\n print(\"fantasy\")\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar stations = \"\";\nvar subST1 = \"\";\nvar subST2 = \"\";\nvar ind = 0;\n\nrl.on('line', (input) => {\n if (ind == 0) {\n stations = input;\n ind++;\n } else if (ind == 1) {\n subST1 = input;\n ind++;\n }\n else {\n subST2 = input;\n /** */\n fw = false;\n bw = false;\n fw = ISTrue(stations, subST1, subST2);\n\n stations = reverceStr(stations);\n bw = ISTrue(stations, subST1, subST2);\n\n if (fw && bw)\n console.log(\"both\");\n else if (fw)\n console.log(\"forward\");\n else if (bw)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n\n /** */\n rl.close();\n }\n});\n\n\n\nfunction ISTrue(s, first, second) {\n let indexOfFirst = s.indexOf(first);\n let lastIndexOFsecond = s.lastIndexOf(second);\n return indexOfFirst != -1 && lastIndexOFsecond != -1 &&\n (indexOfFirst + first.length - 1) < lastIndexOFsecond;\n}\n\nfunction reverceStr(s) {\n let arr = s.split('');\n let limit = parseInt(s.length / 2);\n for (let i = 0, j = s.length - 1; i < limit; i++ , j--) {\n let t = arr[i];\n arr[i] = arr[j];\n arr[j] = t;\n }\n return arr.join('');\n}"}, {"source_code": "\nfunction reverseString(s)\n{\n\tvar str = \"\";\n\tfor (var i = s.length; i >= 1; i--)\n\t{\n\t\tstr += s[i - 1];\n\t}\n\treturn str;\n}\n\nfunction main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(reverseString(x));\n\t\n\tvar yIndex = s.indexOf(reverseString(y));\n\tvar yLastIndex = s.lastIndexOf(y);\n\t\n\tvar forwoardFlag = yLastIndex - xIndex >= x.length;\n\tif (yLastIndex == -1 || xIndex == -1)\n\t{\n\t\tforwoardFlag = false;\n\t}\n\t\n\tvar backwardFlag = xLastIndex - yIndex >= y.length;\n\tif (xLastIndex == -1 || yIndex == -1) \n\t{\n\t\tbackwardFlag = false;\n\t}\n\t\n\tif (forwoardFlag && !backwardFlag)\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!forwoardFlag && backwardFlag)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (forwoardFlag && backwardFlag)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar check = function (flags, first, second) {\n /*for (let i = 0; i < flags.length; i++) {\n if (flags[i]==first) {\n flags.substr(i, first.length);\n for (let j = 0; j < flags.length; j++) {\n if (flags[j]==second) \n return true;\n } \n return false;\n } \n }*/\n let f_f_indx = flags.indexOf(first);\n let l_s_indx = flags.lastIndexOf(second);\n return f_f_indx != -1 && l_s_indx != -1 && f_f_indx + first.length - 1 < l_s_indx;\n}\n\nvar revFlags = function (str) {\n return str.split(\"\").reverse().join(\"\");\n}\n\nvar flags, first, second, indicator = 0;\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input;\n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n \n let f = check(flags, first, second);\n //console.log(\"flags = %s\", flags); \n flags = revFlags(flags);\n //console.log(\"flags = %s first = %s second = %s \", flags, first, second);\n let b = check(flags, first, second);\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n\n rl.close();\n }\n\n});"}, {"source_code": "var str = readline();\nvar first = readline();\nvar second = readline();\n\nfunction checkStr(str) {\n pos1 = str.indexOf(first);\n flag = false;\n if (pos1 >= 0) {\n str = str.substr(pos1 + first.length);\n pos2 = str.indexOf(second);\n if (pos2 >= 0) flag = true;\n }\n return flag;\n}\n\nforwardFlag = checkStr(str);\nbackwardFlag = checkStr(str.split('').reverse().join(''));\n\nif (forwardFlag && backwardFlag) print('both');\nelse if (forwardFlag) print('forward');\nelse if (backwardFlag) print('backward');\nelse print('fantasy');\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n/**\n 0123456789|||\nflags=\"abcFFdefgZZhi\"\nfirst=\"FF\"\nsecond=\"ZZ\"\n\nA B\nO----------->O forward\n\nA B\nO<-----------O backward\n\nA B\nO<----------->O both\n\nA B\nOX-----------XO fantasy\n\n 0123456\nflags=\"aaacaaa\"\nfirst=\"aca\"\nsecond=\"aa\"\n\n 012345\nflags=\"aaacaa\"\nfirst=\"aca\"\nsecond=\"aa\"\n\n */\n//our functions here...\nvar check = function (flags, first, second) {\n let FInd = flags.indexOf(first);\n let SLInd = flags.lastIndexOf(second);\n return FInd != -1 && SLInd != -1 && FInd + first.length - 1 < SLInd;\n}\n\nvar revStr = function (s) {\n let ans = \"\";\n for (let i = s.length - 1; i >= 0; i--)\n ans += s[i];\n\n return ans;\n}\n\nvar flags, first, second, indicator = 0;\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input;\n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n //************ */\n //console.log(\"flags= %s first= %s second= %s\",flags,first,second);\n let f = check(flags, first, second);\n flags = revStr(flags);\n //console.log(\"flags= %s first= %s second= %s\",flags,first,second);\n let b = check(flags, first, second);\n //console.log(\"flags= %s first= %s second= %s f= %s b=%s\",flags,first,second,f,b);\n if (f && b) console.log(\"both\");\n else if (f) console.log(\"forward\");\n else if (b) console.log(\"backward\");\n else console.log(\"fantasy\");\n /************** */\n rl.close();\n }\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar check = function (flags, first, second) {\n FIndex = flags.indexOf(first);\n SLIndex = flags.lastIndexOf(second);\n return FIndex != -1 && SLIndex != -1 && FIndex + first.length - 1 < SLIndex;\n}\n\nvar flags, first, second, identifier = 0\n\nrl.on('line', (input) => {\n if (identifier == 0) {\n flags = input;\n identifier++;\n }\n else if (identifier == 1) {\n first = input;\n identifier++;\n }\n else {\n second = input;\n /*our code here*/\n var f = check(flags,first,second);\n flags = flags.split(\"\").reverse().join(\"\");\n var b = check(flags,first,second);\n\n if (f && b)\n console.log(\"both\")\n else if (f)\n console.log(\"forward\")\n else if (b)\n console.log(\"backward\")\n else \n console.log(\"fantasy\") \n \n /**end of our code */\n rl.close();\n }\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\nfunction rev(s)\n{\n return s.split('').reverse().join('');\n}\nfunction main()\n{\n let s=readLine().trim();\n let a=readLine().trim();\n let b=readLine().trim();\n let x=0;\n let r=rev(s);\n if((s.includes(a))&&(s.includes(b)))\n {\n let aend=s.indexOf(a)+a.length-1,bstart=r.length-r.indexOf(rev(b))-b.length;\n //console.log(aend+' '+bstart);\n if((aend=0))\n {\n x+=1; \n }\n }\n r=s;\n s=rev(s);\n if((s.includes(a))&&(s.includes(b)))\n {\n let aend=s.indexOf(a)+a.length-1,bstart=r.length-r.indexOf(rev(b))-b.length;\n //console.log(aend+' '+bstart);\n if((aend=0))\n {\n x+=2; \n }\n }\n if(x===0)\n {\n console.log('fantasy');\n }\n else if(x==1)\n {\n console.log('forward');\n }\n else if(x==2)\n {\n console.log('backward');\n }\n else if(x==3)\n {\n console.log('both');\n }\n}\n\n\n"}, {"source_code": "function solve(s, a, b) {\n let forward = false;\n let backward = false;\n const a_indx = s.indexOf(a);\n if (a_indx < 0) {\n // do nothing ...\n } else {\n const b_indx = s.indexOf(b, a_indx + a.length);\n if (b_indx < 0) {\n // do nothing ...\n } else {\n forward = true;\n }\n }\n const s_r = s.split('').reverse().join('');\n const a_indx_r = s_r.indexOf(a);\n if (a_indx_r < 0) {\n // do nothing ...\n } else {\n const b_indx_r = s_r.indexOf(b, a_indx_r + a.length);\n if (b_indx_r < 0) {\n // do nothing ...\n } else {\n backward = true;\n }\n }\n if (forward) {\n if (backward) {\n return 'both';\n } else {\n return 'forward';\n }\n } else {\n if (backward) {\n return 'backward';\n } else {\n return 'fantasy'\n }\n }\n};\n\nfunction main(lines) {\n const trim_lines = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n trim_lines.push(t);\n }\n }\n const [s, a, b] = trim_lines;\n const result = solve(s, a, b);\n console.log(result);\n};\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n};\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nconst input = [];\nasync function work(line, lineNr) {\n input.push(line);\n if (input.length === 3) {\n const solutionForLine = await solve(input);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(input) {\n const [str, s1, s2] = input;\n let opts = 'init_';\n if (isForward(str, s1, s2)) opts += 'f';\n if (isBackward(str, s1, s2)) opts += 'b';\n const res = {\n 'init_': 'fantasy', \n 'init_f': 'forward', \n 'init_b': 'backward', \n 'init_fb': 'both', \n };\n return res[opts];\n}\n\nfunction isForward(str, s1, s2) {\n const s1Index = str.indexOf(s1);\n if (s1Index !== -1) return str.indexOf(s2, s1Index + s1.length) !== -1;\n return false;\n}\n\nfunction isBackward(str, s1, s2) {\n return isForward(str.split('').reverse().join(''), s1, s2);\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar check = function (flags, first, second) {\n let firstIndex = flags.indexOf(first);\n let lastIndex = flags.lastIndexOf(second);\n //console.log(\"inside check function: \\nfirstIndex= %d lastIndex = %d\",firstIndex, lastIndex);\n return firstIndex != -1 && lastIndex != -1 && firstIndex + first.length - 1 < lastIndex;\n}\n\nfunction reverseString(str) {\n return str.split(\"\").reverse().join(\"\");\n}\n/*\n\nflags= \"aaacaaa\"\nfirst=\" aca\"\nsecond= \"aa\"\n\n*/\n/*\nC#\nwhile(true){\n string input = Console.ReadLine();\n\n}\n\nnodejs\nrl.on('line', (input)=>{\n \n});\n*/\nvar flags, first, second, indicator = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input; \n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n //our code here.....\n //console.log(\"flags= %s first= %s second= %s\",flags, first, second);\n let f = check(flags, first, second);\n flags = reverseString(flags);\n let b = check(flags, first, second);\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n\n\n rl.close();\n }\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar check = function (flags, first, second) {\n fIndx = flags.indexOf(first);\n sIndx = flags.lastIndexOf(second);\n\n return fIndx != -1 && sIndx != -1 && fIndx + first.length - 1 < sIndx;\n}\nvar flags, first, second, indicator = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input;\n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n\n }\n else {\n second = input;\n let f = check(flags, first, second);\n flags = flags.split('').reverse().join('');\n let b = check(flags, first, second);\n\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n rl.close();\n }\n});"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar checkFlags = function(flags, first, second) {\n for (let i = 0; i < flags.length; i++) {\n if (flags[i]==first) {\n flags.substr(i, first.length);\n for (let j = 0; j < flags.length; j++) {\n if (flags[j]==second) \n return true;\n } \n return false;\n } \n }\n}\n\nvar revFlags = function(str) {\n return str.split(\"\").reverse().join(\"\");\n}\n\nvar temp = [], forw = false, backw = false;\n\nrl.on('line', (input) => {\n temp.push(input);\n let flags = temp[0], first = temp[1], second = temp[2];\n let reversedFlags = revFlags(flags); \n\n if (checkFlags(flags,first,second))\n forw = true;\n if (checkFlags(reversedFlags,second,first))\n backw = true; \n \n }).on('close', function() {\n \n if (forw && backw)\n console.log(\"both\");\n else if (forw)\n console.log(\"forward\");\n else if (backw)\n console.log(\"backward\");\n else\n console.log(\"fantasy\"); \n \n });"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar check = function (flags, first, second) {\n \n let f_f_indx = flags.indexOf(first);\n let l_s_indx = flags.lastIndexOf(second);\n return f_f_indx != -1 && l_s_indx != -1 && f_f_indx + first.length - 1 < l_s_indx;\n}\n\nvar revFlags = function (str) {\n return str.split(\"\").reverse().join(\"\");\n}\n\nvar flags, first, second, indicator = 0;\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input;\n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n \n let f = check(flags, first, second);\n let b = check(revFlags(flags), second, first);\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"backward\");\n else\n console.log(\"fantasy\");\n\n rl.close();\n }\n\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\nfunction rev(s)\n{\n return s.split('').reverse().join('');\n}\nfunction main()\n{\n let s=readLine().trim();\n let a=readLine().trim();\n let b=readLine().trim();\n let x=0;\n let r=rev(s);\n if((s.includes(a))&&(s.includes(b)))\n {\n let aend=s.indexOf(a)+a.length-1,bstart=r.length-r.indexOf(rev(b))-b.length;\n //console.log(aend+' '+bstart);\n if((aend=0))\n {\n x+=1; \n }\n }\n r=s;\n s=rev(s);\n if((s.includes(a))&&(s.includes(b)))\n {\n let aend=s.indexOf(a)+a.length-1,bstart=r.length-r.indexOf(rev(b))-b.length;\n //console.log(aend+' '+bstart);\n if((aend=0))\n {\n x+=2; \n }\n }\n if(x===0)\n {\n console.log('<>');\n }\n else if(x==1)\n {\n console.log('<>');\n }\n else if(x==2)\n {\n console.log('<>');\n }\n else if(x==3)\n {\n console.log('<>');\n }\n}\n\n\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nconst input = [];\nasync function work(line, lineNr) {\n input.push(line);\n if (input.length === 3) {\n const solutionForLine = await solve(input);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(input) {\n const [str, s1, s2] = input;\n let opts = 'init_';\n if (isForward(str, s1, s2)) opts += 'f';\n if (isBackward(str, s1, s2)) opts += 'b';\n const res = {\n 'init_': 'fantasy', \n 'init_f': 'forward', \n 'init_b': 'backward', \n 'init_fb': 'both', \n };\n return res[opts];\n}\n\nfunction isForward(str, s1, s2) {\n const s1Index = str.indexOf(s1);\n if (s1Index !== -1) return str.indexOf(s2, s1Index + 1) !== -1;\n return false;\n}\n\nfunction isBackward(str, s1, s2) {\n const s1Index = str.lastIndexOf(s1);\n if (s1Index !== -1) return str.lastIndexOf(s2, s1Index + 1) !== -1;\n return false;\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nconst input = [];\nasync function work(line, lineNr) {\n input.push(line);\n if (input.length === 3) {\n const solutionForLine = await solve(input);\n const responseLine = `${solutionForLine}\\n`;\n process.stdout.write(responseLine);\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(input) {\n const [str, s1, s2] = input;\n let opts = 'init_';\n if (isForward(str, s1, s2)) opts += 'f';\n if (isBackward(str, s1, s2)) opts += 'b';\n const res = {\n 'init_': 'fantasy', \n 'init_f': 'forward', \n 'init_b': 'backward', \n 'init_fb': 'both', \n };\n return res[opts];\n}\n\nfunction isForward(str, s1, s2) {\n const s1Index = str.indexOf(s1);\n if (s1Index !== -1) return str.indexOf(s2, s1Index + s1.length) !== -1;\n return false;\n}\n\nfunction isBackward(str, s1, s2) {\n const s1Index = str.lastIndexOf(s1);\n if (s1Index !== -1) return str.lastIndexOf(s2, s1Index + s1.length) !== -1;\n return false;\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar check = function (flags, first, second) {\n let firstIndex = flags.indexOf(first);\n let lastIndex = flags.lastIndexOf(second);\n //console.log(\"inside check function: \\nfirstIndex= %d lastIndex = %d\",firstIndex, lastIndex);\n return firstIndex != -1 && lastIndex != -1 && firstIndex + first.length - 1 < lastIndex;\n}\n\nfunction reverseString(str) {\n return str.split(\"\").reverse().join(\"\");\n}\n/*\n\nflags= \"aaacaaa\"\nfirst=\" aca\"\nsecond= \"aa\"\n\n*/\n/*\nC#\nwhile(true){\n string input = Console.ReadLine();\n\n}\n\nnodejs\nrl.on('line', (input)=>{\n \n});\n*/\nvar flags, first, second, indicator = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input; \n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n //our code here.....\n //console.log(\"flags= %s first= %s second= %s\",flags, first, second);\n let f = check(flags, first, second);\n flags = reverseString(flags);\n let b = check(flags, first, second);\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"bakward\");\n else\n console.log(\"fantacy\");\n\n\n rl.close();\n }\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar check = function (flags, first, second) {\n let firstIndex = flags.indexOf(first);\n let lastIndex = flags.lastIndexOf(second);\n //console.log(\"inside check function: \\nfirstIndex= %d lastIndex = %d\",firstIndex, lastIndex);\n return firstIndex != -1 && lastIndex != -1 && firstIndex + first.length - 1 < lastIndex;\n}\n\nfunction reverseString(str) {\n return str.split(\"\").reverse().join(\"\");\n}\n/*\n\nflags= \"aaacaaa\"\nfirst=\" aca\"\nsecond= \"aa\"\n\n*/\n/*\nC#\nwhile(true){\n string input = Console.ReadLine();\n\n}\n\nnodejs\nrl.on('line', (input)=>{\n \n});\n*/\nvar flags, first, second, indicator = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input; \n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n }\n else {\n second = input;\n //our code here.....\n //console.log(\"flags= %s first= %s second= %s\",flags, first, second);\n let f = check(flags, first, second);\n flags = reverseString(flags);\n let b = check(flags, first, second);\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forward\");\n else if (b)\n console.log(\"bakward\");\n else\n console.log(\"fantasy\");\n\n\n rl.close();\n }\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar check = function (flags, first, second) {\n fIndx = flags.indexOf(first);\n sIndx = flags.lastIndexOf(second);\n\n return fIndx != -1 && sIndx != -1 && fIndx + first.length - 1 < sIndx;\n}\nvar flags, first, second, indicator = 0;\nrl.on('line', (input) => {\n if (indicator == 0) {\n flags = input;\n indicator++;\n }\n else if (indicator == 1) {\n first = input;\n indicator++;\n\n }\n else {\n second = input;\n let f = check(flags, first, second);\n flags = flags.split('').reverse().join('');\n let b = check(flags, first, second);\n\n\n if (f && b)\n console.log(\"both\");\n else if (f)\n console.log(\"forwards\");\n else if (b)\n console.log(\"backwards\");\n else\n console.log(\"fantasy\");\n rl.close();\n }\n});"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction myFunction(s, array, index) {\n for (var i = index.x; i < array.length; i++) {\n index.x = i;\n if (s == array.substr(i, s.length)) return true;\n }\n index.x = 0;\n return false;\n}\n\nfunction reverseString(str) {\n var splitString = str.split(\"\");\n var reverseArray = splitString.reverse();\n var joinArray = reverseArray.join(\"\");\n return joinArray;\n}\n\nvar n = -1;\nvar sleep1 = \"\";\nvar sleep2 = \"\";\nvar array = \"\";\nvar index = { x: 0 };\nvar startToFinish1 = false;\nvar startToFinish2 = false;\nvar finishToStart1 = false;\nvar finishToStart2 = false;\nvar answer = \"\";\n\nrl.on(\"line\", input => {\n if (n++ == -1) array = input;\n if (n++ == 0) {\n sleep1 = input;\n startToFinish1 = myFunction(sleep1, array, index);\n } else {\n sleep2 = input;\n startToFinish2 = myFunction(sleep2, array, index);\n var revarray = reverseString(array);\n index.x = 0;\n finishToStart1 = myFunction(sleep1, revarray, index);\n finishToStart2 = myFunction(sleep2, revarray, index);\n\n if (startToFinish1 && startToFinish2 && finishToStart1 && finishToStart2)\n answer = \"both\";\n else if (startToFinish1 && startToFinish2) answer = \"forward\";\n else if (finishToStart1 && finishToStart2) answer = \"backward\";\n else answer = \"fantasy\";\n }\n}).on(\"close\", () => {\n console.log(answer);\n});\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction myFunction(s, array, index) {\n for (var i = index.x; i < array.length-s.length; i++) {\n \n if (s == array.substr(i, s.length)) \n {\n index.x = i+s.length;\n return true;\n }\n }\n index.x = 0;\n return false;\n}\n\nfunction reverseString(str) {\n var splitString = str.split(\"\");\n var reverseArray = splitString.reverse();\n var joinArray = reverseArray.join(\"\");\n return joinArray;\n}\n\nvar n = -1;\nvar sleep1 = \"\";\nvar sleep2 = \"\";\nvar array = \"\";\nvar index = { x: 0 };\nvar startToFinish1 = false;\nvar startToFinish2 = false;\nvar finishToStart1 = false;\nvar finishToStart2 = false;\nvar answer = \"\";\n\nrl.on(\"line\", input => {\n if (n++ == -1) array = input;\n if (n++ == 0) {\n sleep1 = input;\n startToFinish1 = myFunction(sleep1, array, index);\n } else {\n sleep2 = input;\n startToFinish2 = myFunction(sleep2, array, index);\n var revarray = reverseString(array);\n index.x = 0;\n finishToStart1 = myFunction(sleep1, revarray, index);\n finishToStart2 = myFunction(sleep2, revarray, index); \n\n if (startToFinish1 && startToFinish2 && finishToStart1 && finishToStart2)\n answer = \"both\";\n else if (startToFinish1 && startToFinish2) answer = \"forward\";\n else if (finishToStart1 && finishToStart2) answer = \"backward\";\n else answer = \"fantasy\";\n }\n}).on(\"close\", () => {\n console.log(answer);\n});\n"}, {"source_code": "function stringReverse(str) {\n return str.split('').reverse().join('');\n}\n\nfunction check(str, subStr1, subStr2) {\n return str.indexOf(subStr1) + subStr1.length - 1 < str.lastIndexOf(subStr2);\n}\n\nfunction has(first, last) {\n if(first && last) {\n return('both');\n }\n else if(first) {\n return('forward');\n }\n else if(last) {\n return('backward');\n }\n else {\n return('fantasy');\n }\n}\n\nvar str = readline(), subStr1 = readline(), subStr2 = readline();\nprint(has(check(str, subStr1, subStr2), check(stringReverse(str), subStr1, subStr2)));"}, {"source_code": "function stringReverse(str) {\n return str.split('').reverse().join('');\n}\n\nfunction check(str, subStr1, subStr2) {\n return str.indexOf(subStr1) < str.lastIndexOf(subStr2);\n}\n\nfunction has(first, last) {\n if(first && last) {\n return('both');\n }\n else if(first) {\n return('forward');\n }\n else if(last) {\n return('backward');\n }\n else {\n return('fantasy');\n }\n}\n\nvar str = readline(), subStr1 = readline(), subStr2 = readline();\nprint(has(check(str, subStr1, subStr2), check(stringReverse(str), subStr1, subStr2)));"}, {"source_code": "sequence = readline()\nfirstTest = readline()\nsecondTest = readline()\n\nisForward = false\nisBackward = false\n\nif ((index = sequence.indexOf(firstTest)) >= 0) {\n if (sequence.indexOf(secondTest, index) >= 0) {\n isForward = true;\n }\n}\n\nsequenceReverse = sequence.split(\"\").reverse().join(\"\")\n\nif ((index = sequenceReverse.indexOf(firstTest)) >= 0) {\n if (sequenceReverse.indexOf(secondTest, index) >= 0) {\n isBackward = true;\n }\n}\n\nif (isForward && isBackward) {\n print(\"both\")\n} else if (isForward) {\n print(\"forward\")\n} else if (isBackward) {\n print(\"backward\")\n} else {\n print(\"fantasy\")\n}"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n\tif (s[3] == 'a' && s[2] == 'a' && s[0] == 'a') \n\t{\n//\t\tprint(s);\n\t\tprint(x);\n\t\tprint(y);\n\t}\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (xIndex < yLastIndex && xLastIndex <= yIndex)\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (xIndex >= yLastIndex && xLastIndex > yIndex)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (xIndex < yLastIndex && xLastIndex > yIndex)\n\t{\n\t\tprint(\"both\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex > x.length && !(xLastIndex - yIndex > y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex > x.length) && xLastIndex - yIndex > y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex > x.length && xLastIndex - yIndex > y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n\tif (s[4] == 'a') \n\t{\n\t\tprint(s);\n\t\tprint(x);\n\t\tprint(y);\n\t}\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex > x.length && !(xLastIndex - yIndex > y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex > x.length) && xLastIndex - yIndex > y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex > x.length && xLastIndex - yIndex > y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex <= x.length && !(xLastIndex - yIndex <= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex <= x.length) && xLastIndex - yIndex <= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex <= x.length && xLastIndex - yIndex <= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n\tif (s[3] == 'a' && s[2] == 'a') \n\t{\n\t\tprint(s);\n\t\tprint(x);\n\t\tprint(y);\n\t}\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n\tif (s[3] == 'a') \n\t{\n\t\tprint(s);\n\t\tprint(x);\n\t\tprint(y);\n\t}\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}, {"source_code": "function main()\n{\n\tvar s = readline();\n\tvar x = readline();\n\tvar y = readline();\n\t\n//\tprint(s);\n//\tprint(x);\n//\tprint(y);\n\t\n\tvar xIndex = s.indexOf(x);\n\tvar xLastIndex = s.lastIndexOf(x);\n//\tprint(xIndex + \" \" + xLastIndex);\n\t\n\tvar yIndex = s.indexOf(y);\n\tvar yLastIndex = s.lastIndexOf(y);\n//\tprint(yIndex + \" \" + yLastIndex);\n\t\n\tif (xIndex == -1 || yIndex == -1) \n\t{\n//\t\tprint(xIndex);\n//\t\tprint(yIndex);\n\t\tprint(\"fantasy\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && !(xLastIndex - yIndex >= y.length))\n\t{\n\t\tprint(\"forward\");\n\t}\n\t\n\telse if (!(yLastIndex - xIndex >= x.length) && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"backward\");\n\t}\n\t\n\telse if (yLastIndex - xIndex >= x.length && xLastIndex - yIndex >= y.length)\n\t{\n\t\tprint(\"both\");\n\t}\n\t\n\telse \n\t{\n\t\tprint(\"fantasy\");\n\t}\n}\n\nmain();"}], "src_uid": "c3244e952830643938d51ce14f043d7d"} {"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\nlet inputBuf = ''\r\nlet curLine = 0\r\nprocess.stdin.on('data', inputData => {\r\n\tinputBuf += inputData\r\n})\r\nprocess.stdin.on('end', _ => {\r\n\tinputBuf = inputBuf.trim().split('\\n')\r\n\tmain()\r\n})\r\n\r\nconst log = (...params) => console.log(...params)\r\nconst R = new Proxy({}, {\r\n\tget: (target, property, receiver) => {\r\n\t\tif (property === 'i') {\r\n\t\t\treturn parseInt(inputBuf[curLine++], 10)\r\n\t\t} else if (property === 'l') {\r\n\t\t\treturn inputBuf[curLine++]\r\n\t\t} else if (property === 'ii') {\r\n\t\t\treturn inputBuf[curLine++].split(' ').map(s => parseInt(s, 10))\r\n\t\t}\r\n\t},\r\n\tset: (target, property, value, receiver) => {\r\n\t\tif (property === 'lp') {\r\n\t\t\tlet n = R.i\r\n\t\t\tfor (let i = 0; i < n; i++) value(i)\r\n\t\t}\r\n\t}\r\n})\r\nconst FLPProxy = new Proxy({}, {\r\n\tset: (target, property, value, receiver) => {\r\n\t\tfor (let i = 0; i < property; i++) value(i)\r\n\t}\r\n})\r\nconst F = new Proxy({}, {\r\n\tget: (target, property, receiver) => {\r\n\t\tif (property === 'lp') {\r\n\t\t\treturn FLPProxy\r\n\t\t}\r\n\t}\r\n})\r\nconst A = {\r\n\trepeat: (n, value) => Array(n).fill(value),\r\n\trange: (l, r) => {\r\n\t\tlet arr = Array(r - l)\r\n\t\tfor (let i = 0; i < arr.length; i++) arr[i] = i + l\r\n\t\treturn arr\r\n\t}\r\n}\r\n\r\nfunction main() {\r\n\tR.lp=_=>{\r\n\t\tn=R.i\r\n\t\tcnt=R.ii.reduce((p,v)=>{\r\n\t\t\tF.lp[30]=i=>{\r\n\t\t\t\tif(1<!cnt.some(c=>c%a)).join(' ')\r\n\t\tlog(ans)\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst cnt = Array(30).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < 30; j++) {\r\n\t\t\t\tcnt[j] += !!(a[i] & 1 << j);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let k = 1; k <= n; k++) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (let b = 0; ok && b < 30; b++) {\r\n\t\t\t\tok = cnt[b] % k == 0 \r\n\t\t\t}\r\n\t\t\tif (ok) {\r\n\t\t\t\tans.push(k);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let res = new Array(31).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let j = arr[i],\r\n k = 0;\r\n while (j > 0) {\r\n if (j & 1) res[k]++;\r\n j = j >> 1;\r\n k++;\r\n }\r\n }\r\n let ans = [];\r\n for (let i = 1; i <= n; i++) {\r\n let flag = 0;\r\n for (let j = 0; j < res.length; j++) if (res[j] % i !== 0) flag = 1;\r\n if (flag === 0) ans.push(i);\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst gcd = (a, b) => !b ? a : gcd(b, a%b);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst cnt = Array(30).fill(0);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tfor (let j = 0; j < 30; j++) {\r\n\t\t\t\tcnt[j] += !!(a[i] & 1 << j);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlet g = 0;\r\n\t\tfor (let i = 0; i < 30; i++) {\r\n\t\t\tg = gcd(g, cnt[i]);\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let k = 1; k <= n; k++) {\r\n\t\t\tif (g % k == 0)\r\n\t\t\t\tans.push(k);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "81f4bc9ac72ed39da8614131954d0d99"} {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n if (c % 2) {\r\n c++;\r\n return;\r\n }\r\n\r\n const arr = d.split(' ').map(Number);\r\n const results = arr.slice();\r\n let ans = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n let next = i + arr[i];\r\n if (next < arr.length) {\r\n results[next] = Math.max(results[i] + arr[next], results[next]);\r\n }\r\n }\r\n\r\n console.log(Math.max(...results));\r\n\r\n c++;\r\n});\r\n", "positive_code": [{"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let length = parseInt(readline());\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n let sumMax = 0;\r\n \r\n for(let j = 0; j < length; j++){\r\n if(arr[j] === 0){\r\n continue;\r\n }\r\n let sumTemp = 0;\r\n let num;\r\n for(let k = j; k < length; k += num){\r\n num = arr[k];\r\n if(num === 0){\r\n break;\r\n }\r\n sumTemp += num;\r\n arr[k] = 0;\r\n }\r\n\r\n if(sumTemp > sumMax){\r\n sumMax = sumTemp;\r\n }\r\n }\r\n print(sumMax);\r\n}"}, {"source_code": "\"use strict\"\r\nlet t = Number(readline());\r\nwhile(t--){\r\n\tlet n = Number(readline());\r\n\tlet arr = readline().split(' ');\r\n\tlet resArr = []\r\n\tfor(let i = n - 1; i >= 0; i--){\r\n\t\tlet a = Number(arr[i]);\r\n\t\tresArr[i] = a;\r\n\t\tif(i + a < n) resArr[i] += resArr[i+a];\r\n\t}\r\n\tprint(resArr.reduce((a,b) => a > b ? a : b));\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var test = 0; test < tests; test++) {\r\n var size = parseInt(readline());\r\n var arr = readline().split(' ').map((v) => parseInt(v));\r\n var mem = [];\r\n for (var i = arr.length-1; i >= 0; i--) {\r\n mem[i] = calculate(mem, arr, i);\r\n }\r\n print(Math.max(...mem));\r\n}\r\n\r\nfunction calculate(mem, arr, index) {\r\n var acc = arr[index], nextIndex = index + arr[index];\r\n if (nextIndex < arr.length) {\r\n acc += mem[nextIndex];\r\n }\r\n mem[index] = acc;\r\n return mem[index];\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var test = 0; test < tests; test++) {\r\n var size = parseInt(readline());\r\n var arr = readline().split(' ').map((v) => parseInt(v));\r\n var mem = [];\r\n for (var i = arr.length-1; i >= 0; i--) {\r\n mem[i] = calculate(mem, arr, i);\r\n }\r\n print(Math.max(...mem));\r\n}\r\n\r\nfunction calculate(mem, arr, index) {\r\n var acc = 0, i = index;\r\n while (i < arr.length) {\r\n if (mem[i] != undefined) {\r\n acc += mem[i];\r\n break;\r\n }\r\n acc += arr[i];\r\n i += arr[i];\r\n }\r\n mem[index] = acc;\r\n return mem[index];\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nvar input = new Array();\r\nfor (var i = 0; i < limit; i++) {\r\n input.push(readline());\r\n input.push(readline());\r\n}\r\nvar output = calc(input);\r\noutput.forEach(function (value) { print(value); });\r\nfunction calc(inputArray) {\r\n var result = new Array();\r\n for (var i = 0; i < inputArray.length; i += 2) {\r\n var caseLength = parseInt(inputArray[i]);\r\n var caseArray = inputArray[i + 1].split(\" \");\r\n var caseIntArray = new Array(inputArray.length);\r\n var maxTotal = 0;\r\n for (var j = (caseLength - 1); j >= 0; j--) {\r\n var currentValue = parseInt(caseArray[j]);\r\n if ((j + currentValue) < caseLength) {\r\n currentValue += caseIntArray[j + currentValue];\r\n }\r\n caseIntArray[j] = currentValue;\r\n if (maxTotal < currentValue)\r\n maxTotal = currentValue;\r\n }\r\n result.push(maxTotal);\r\n }\r\n return result;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let dp = new Array(n).fill(0);\r\n for (let i = n - 1; i >= 0; i--) {\r\n let j = i;\r\n dp[i] += arr[j];\r\n if (j + arr[j] < n) {\r\n dp[i] += arr[j + arr[j]];\r\n arr[j] = dp[i];\r\n }\r\n }\r\n let max = 0;\r\n for (let i = 0; i < n; i++) max = Math.max(max, dp[i]);\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\n\t\tfor (let i = len - 1; i >= 0; i--) {\n\t\t\tif (i + arr[i] < len) {\n\t\t\t\tarr[i] += arr[i + arr[i]];\n\t\t\t}\n\t\t}\n\t\tconsole.log(`${Math.max(...arr)}`);\n\t}\n}\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n if (c % 2) {\r\n c++;\r\n return;\r\n }\r\n\r\n const arr = d.split(' ').map(Number);\r\n const results = arr.slice();\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n let next = i + arr[i];\r\n if (next < arr.length) {\r\n results[next] = Math.max(results[i] + arr[next], results[next]);\r\n }\r\n }\r\n\r\n console.log(Math.max(...results));\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar stdin_str = '';\nvar stdin_lines = [];\nvar cur_line = 0;\nfunction readline() {\n return stdin_lines[cur_line++];\n}\nprocess.stdin.on('data', function (raw) {\n stdin_str += raw;\n});\nprocess.stdin.on('end', function () {\n stdin_lines = stdin_str.trim().split(\"\\n\").map(function (l) { return l.trim(); });\n main();\n});\nvar psi = function (n) { return parseInt(n, 10); };\nfunction f_naive(i, arr) {\n var id = i, score = 0;\n while (id < arr.length) {\n score += arr[id];\n id += arr[id];\n }\n return score;\n}\nfunction solve_naive(arr) {\n var max_score = -1;\n for (var i = 0; i < arr.length; i++) {\n max_score = Math.max(max_score, f_naive(i, arr));\n }\n return max_score;\n}\nfunction f(i, arr, cache) {\n var id = i;\n if (id + arr[id] < arr.length) {\n cache[id] = arr[id] + cache[id + arr[id]];\n }\n else {\n cache[id] = arr[id];\n }\n}\nfunction solve(arr) {\n var cache = Array(arr.length);\n var max_score = -1;\n for (var i = arr.length - 1; i >= 0; i--) {\n f(i, arr, cache);\n max_score = Math.max(max_score, cache[i]);\n }\n return max_score;\n}\nfunction main() {\n var nt = psi(readline());\n var _loop_1 = function (_) {\n readline();\n var arr = [];\n readline().split(\" \").map(function (n) { return arr.push(psi(n)); });\n console.log(solve(arr));\n };\n for (var _ = 0; _ < nt; _++) {\n _loop_1(_);\n }\n}\n"}, {"source_code": "let inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', (data) => {\r\n inputString += data;\r\n})\r\nprocess.stdin.on('end', function (){\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((str) => str.trim());\r\n main();\r\n})\r\nfunction readLine(){\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main(){\r\n let t = +readLine();\r\n while(t--){\r\n let n = +readLine();\r\n let a = readLine().split(' ').map(Number);\r\n let dp = [], ans = 0;\r\n for(let i=0; i=0; i--){\r\n dp[i] = a[i];\r\n let j = i + a[i];\r\n if(j < n){\r\n dp[i] += dp[j];\r\n }\r\n ans = Math.max(ans, dp[i]);\r\n }\r\n console.log(ans);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let n = readline();\r\n let arr = readline().split(' ').map(x => +x);\r\n\r\n const calculated = {};\r\n\r\n let max = 0;\r\n\r\n for (let i = n; i > 0; i--) {\r\n let s = i;\r\n let ans = 0;\r\n\r\n while (s <= n) {\r\n if (calculated[s]) {\r\n ans += calculated[s];\r\n break;\r\n } else {\r\n ans += arr[s - 1];\r\n s += arr[s - 1];\r\n }\r\n }\r\n calculated[i] = ans;\r\n if (ans > max) {\r\n max = ans;\r\n }\r\n }\r\n\r\n console.log(max);\r\n }\r\n}\r\n"}, {"source_code": "const solve = (n, a) => {\r\n let map = new Map();\r\n let max = 0;\r\n for (let i = n - 1; ~i; i--) {\r\n let idx = i + 1;\r\n let sum = 0;\r\n while (idx <= n) {\r\n if (map.has(idx)) {\r\n sum += map.get(idx);\r\n break;\r\n }\r\n sum += a[idx - 1];\r\n idx += a[idx - 1];\r\n }\r\n max = Math.max(max, sum);\r\n map.set(i + 1, sum);\r\n }\r\n console.log(max);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input.slice(i, i + 2);\r\n solve(data[0][0], data[1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var sum = 0\r\n var number = 0\r\n var answer = []\r\n var xx = 0\r\n var array = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n answer[i + xx] = Math.max(xx + (answer[i] ? answer[i] : 0), answer[i + xx] ? answer[i + xx] : 0)\r\n answer[i] = (answer[i] ? answer[i] : 0) + xx\r\n return xx\r\n });\r\n var max = 0\r\n var i = 0\r\n var x = 0\r\n while (i < n) {\r\n x = answer[i]\r\n if (x > max) max = x\r\n i++\r\n }\r\n console.log(max)\r\n // console.log(answer)\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "const readline = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet nTestCases = 0,\r\n n,\r\n t,\r\n arr = [];\r\n\r\nlet lineCnt = 0;\r\nreadline.on(\"line\", (line) => {\r\n lineCnt++;\r\n\r\n if (lineCnt === 1) nTestCases = parseInt(line);\r\n else if (lineCnt % 2 === 0) n = parseInt(line);\r\n else {\r\n arr = line.split(\" \").map((ele) => parseInt(ele));\r\n\r\n let result = 0;\r\n\r\n const cached = {};\r\n\r\n for (let i = 0; i < n; ++i) {\r\n let path = i + 1 + arr[i];\r\n let temp = arr[i];\r\n while (path <= n) {\r\n if (cached[path]) {\r\n break;\r\n }\r\n cached[path] = true;\r\n temp += arr[path - 1];\r\n path = path + arr[path - 1];\r\n }\r\n if (temp > result) result = temp;\r\n }\r\n console.log(result);\r\n }\r\n\r\n if (lineCnt >= nTestCases * 2 + 1) {\r\n readline.close();\r\n }\r\n});\r\n\r\n// const n = 3;\r\n// const arr = [2,1,4];\r\n// let result = 0;\r\n\r\n// const cached = {};\r\n\r\n// for (let i = 0; i < n; ++i) {\r\n// let path = i + 1 + arr[i];\r\n// let temp = arr[i];\r\n// while (path <= n) {\r\n// if (cached[path]) {\r\n// break;\r\n// }\r\n// cached[path] = true;\r\n// temp += arr[path - 1];\r\n// path = path + arr[path - 1];\r\n// }\r\n// if (temp > result) result = temp;\r\n// }\r\n// console.log(result);\r\n"}, {"source_code": "const write = out => process.stdout.write(out + `\\n`);\n\nconst mainCode = ([l1, l2]) => {\n\tl2 = l2.split(' ').map(Number);\n\tconst hashmap = {};\n\tlet highest = 0;\n\n\tlet i = l2.length - 1;\n\twhile (i >= 0) {\n\t\tif (i + l2[i] >= l2.length) hashmap[i] = l2[i];\n\t\telse {\n\t\t\tif (l2[i] == 0) hashmap[i] = 0;\n\t\t\telse {\n\t\t\t\thashmap[i] = l2[i] + hashmap[i + l2[i]];\n\t\t\t}\n\t\t}\n\n\t\tif (hashmap[i] > highest) highest = hashmap[i];\n\t\ti--;\n\t}\n\n\twrite(highest);\n}\n\nlet counter = 0;\nlet t = 0;\nconst t_size = 2;\n\nconst cases = [];\n\nconst lineInterpreter = (line) => {\n\tif (counter == 0) t = Number(line)\n\telse {\n\t\tconst cursor = (counter - 1) % t_size\n\t\tif (cursor == 0) cases.push([line])\n\t\telse cases[cases.length - 1].push(line)\n\t}\n\n\tif (counter == (t * t_size)) {\n\t\tcases.map(_case => mainCode(_case))\n\t}\n\tcounter++\n}\n\nconst platform = 1;\n\nif (platform > 0) {\n\t\n\t// FOR CODEFORCES\n\n\tprocess.stdin.resume();\n\tprocess.stdin.setEncoding('utf-8');\n\n\tlet inputString = '';\n\tlet currentLine = 0;\n\n\tprocess.stdin.on('data', inputStdin => {\n\t inputString += inputStdin;\n\t});\n\n\tprocess.stdin.on('end', _ => {\n\t inputString = inputString.trim().split('\\n').map(string => {\n\t return string.trim();\n\t });\n\t \n\t\tinputString.map(line => lineInterpreter(line));\n\t});\n} else {\n\n\t// FOR PERSONAL USE\n\n\tconst sample = `4\n5\n7 3 1 2 3\n3\n2 1 4\n6\n2 1000 2 3 995 1\n5\n1 1 1 1 1`;\n\tsample.split(`\\n`).map(line => lineInterpreter(line));\n}"}, {"source_code": "const longJumps = a => {\n let res = 0;\n const n = a.length;\n const dp = Array(n).fill(0);\n for (let i = 0; i < n; i++) {\n dp[i] = dp[i] + a[i];\n res = Math.max(res, dp[i]);\n if (i + a[i] < n) {\n dp[i + a[i]] = Math.max(dp[i + a[i]], dp[i]);\n }\n }\n return res;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n readline();\n const a = readline()\n .split(\" \")\n .map(s => parseInt(s));\n console.log(longJumps(a));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n\nfunction create2DArray(rows) {\n var arr = [];\n\n for (var i = 0; i < rows; i++) {\n arr[i] = [];\n }\n\n return arr;\n}\n// ---------------------------------------\n\nfunction main() {\n let t = getInt(readline());\n while (t--) {\n let len = getInt(readline());\n let arr = getArray(readline());\n let resultArr = new Array(len);\n resultArr.fill(0);\n for(let i = len-1; i>=0; i--) {\n resultArr[i] = arr[i] + (resultArr[i + arr[i]] ? resultArr[i + arr[i]] : 0);\n }\n let max = 0;\n for(let i=0; i< len; i++) {\n max = Math.max(max, resultArr[i]);\n }\n console.log(max);\n }\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .filter((_, i) => i % 2)\n .map((line) => line.split(' ').map((n) => +n))\n .map((nums) => {\n const mapOfScores = new Map();\n for (let i = nums.length - 1; i >= 0; i--) {\n let j = i + nums[i];\n while (j < nums.length) {\n if (mapOfScores.has(j)) {\n j += mapOfScores.get(j);\n break;\n }\n j += nums[j];\n }\n mapOfScores.set(i, j - i);\n }\n return Math.max(...mapOfScores.values());\n })\n .join('\\n');\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar dp = new Array(N).fill(0);\r\n\t\tvar max = 0;\r\n\t\tfor(var j = N - 1; j >= 0; j--){\r\n\t\t\tif(j + list[j] >= N){\r\n\t\t\t\tdp[j] = Math.max(list[j], dp[j]);\r\n\t\t\t}else{\r\n\t\t\t\tdp[j] += list[j] + dp[j + list[j]];\r\n\t\t\t}\r\n\t\t\tmax = Math.max(max, dp[j]);\r\n\t\t}\r\n\t\tmyout(max);\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t * 2; i += 2) {\r\n const n = parseInt(lines[i]);\r\n const arr = lines[i + 1].split(' ').map(num => parseInt(num));\r\n\r\n console.log(solve(n, arr));\r\n }\r\n});\r\n\r\nfunction solve(n, arr) {\r\n const result = [];\r\n let max = 0;\r\n let bestIndex = 0;\r\n\r\n for (let i = arr.length - 1; i >= 0; i--) {\r\n result[i] = arr[i];\r\n\r\n if (i + arr[i] < arr.length) {\r\n result[i] += result[i + arr[i]];\r\n }\r\n\r\n if (result[i] > max) {\r\n max = result[i];\r\n bestIndex = i;\r\n }\r\n }\r\n\r\n return max;\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let dp = new Array(n).fill(0);\r\n for (let i = n - 1; i >= 0; i--) {\r\n let j = i;\r\n dp[i] += arr[j];\r\n if (j + arr[j] < n) dp[i] += arr[j + arr[j]];\r\n }\r\n let max = 0;\r\n for (let i = 0; i < n; i++) max = Math.max(max, dp[i]);\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let max = 0;\r\n for (let i = 0; i < n; i++) max = Math.max(arr[i], max);\r\n let vis = 0;\r\n for (let i = 0; i < n; i++) {\r\n let v = 0,\r\n j = i;\r\n while (j < n) {\r\n v += arr[j];\r\n j += arr[j];\r\n vis++;\r\n }\r\n max = Math.max(v, max);\r\n if (vis >= n * 2) break;\r\n }\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let max = 0,\r\n vis = 0;\r\n for (let i = 0; i < n; i++) {\r\n let v = 0,\r\n j = i;\r\n while (j < n) {\r\n v += arr[j];\r\n j += arr[j];\r\n vis++;\r\n }\r\n max = Math.max(v, max);\r\n if (vis >= n * 2) break;\r\n }\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let max = 0,\r\n vis = 0;\r\n for (let i = 0; i < n; i++) {\r\n let v = 0,\r\n j = i;\r\n while (j < n) {\r\n v += arr[j];\r\n j += arr[j];\r\n vis++;\r\n }\r\n max = Math.max(v, max);\r\n if (vis === n) break;\r\n }\r\n console.log(max);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst _arr = readLine().split(' ').map(Number);\n\t\tconst arr = [];\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tif (_arr[i] === _arr[i + 1]) {\n\t\t\t\tlet [count, j] = [0, i];\n\t\t\t\twhile (_arr[j] === _arr[j + 1]) {\n\t\t\t\t\tcount += _arr[j];\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\tarr.push(_arr[i] + count);\n\t\t\t\ti = j;\n\t\t\t} else arr.push(_arr[i]);\n\t\t}\n\t\tlet max = 0;\n\t\tfor (let i = 1; i <= arr.length; i++) {\n\t\t\tlet [c, j] = [0, i];\n\t\t\twhile (j <= arr.length) {\n\t\t\t\tc += arr[j - 1];\n\t\t\t\tj += arr[j - 1];\n\t\t\t}\n\t\t\tmax = Math.max(max, c);\n\t\t}\n\t\tconsole.log(max);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tlet [i, count] = [1, 0];\n\t\twhile (i <= len) {\n\t\t\tcount += arr[i - 1];\n\t\t\ti += arr[i - 1];\n\t\t}\n\t\tconst max = Math.max(...arr);\n\t\tconst min = Math.min(...arr);\n\n\t\tlet cMax = 0;\n\t\tlet index = arr.findIndex((item) => item === max);\n\t\twhile (index < len) {\n\t\t\tcMax += arr[index];\n\t\t\tindex += arr[index];\n\t\t}\n\t\tcount = Math.max(count, cMax);\n\n\t\tlet cMin = 0;\n\t\tlet minIndex = arr.findIndex((item) => item === min);\n\t\twhile (minIndex < len) {\n\t\t\tcMax += arr[minIndex];\n\t\t\tminIndex += arr[minIndex];\n\t\t}\n\t\tcount = Math.max(count, cMin);\n\n\t\tif (count < max) console.log(max);\n\t\telse console.log(count);\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var sum = 0\r\n var number = 0\r\n var answer = []\r\n var xx = 0\r\n var array = readline().split(' ').map((x, i) => {\r\n xx = Number(x)\r\n answer[i + xx] = (answer[i]?answer[i] : 0) + Math.max(xx, answer[i + xx]?answer[i + xx] : 0)\r\n answer[i] = (answer[i]?answer[i] : 0) + xx\r\n // console.log((answer[i]?answer[i] : 0) + xx)\r\n // console.log(answer)\r\n\r\n return xx\r\n });\r\n var max = 0\r\n var i = 0\r\n var x = 0\r\n while(i max) max = x\r\n i++\r\n }\r\n console.log(max)\r\n // console.log(answer)\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let length = parseInt(readline());\r\n let arr = readline().split(\" \").map(x => parseInt(x));\r\n let sumMax = 0;\r\n let stopFlag = arr[0] > length - 1 ? 1 : arr[0];\r\n \r\n for(let j = 0; j < stopFlag; j++){\r\n let sumTemp = 0;\r\n for(let k = j; k < length; k += arr[k]){\r\n sumTemp += arr[k];\r\n }\r\n\r\n if(sumTemp > sumMax){\r\n sumMax = sumTemp;\r\n }\r\n }\r\n print(sumMax);\r\n}"}], "src_uid": "ee8ca9b2c6104d1ff9ba1fc39e9df277"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline()\n let arr = []\n for (let j = 0; j < n; j++) {\n arr.push(readline())\n }\n solve(arr)\n }\n}\nfunction solve(arr) {\n let tot = 0\n let map = new Map()\n for (let i = arr.length - 1; i >=0 ; i--) {\n let pos = arr.length\n let cnt = 0\n if (map.has(arr[i])) {\n [pos, cnt] = map.get(arr[i])\n }\n\n let s1 = arr[i]\n for (let j = i + 1; j < pos; j++) {\n let s2 = arr[j]\n if (s1[0] === s2[0] && s1[1] !== s2[1] || s1[0] !== s2[0] && s1[1] === s2[1]) {\n cnt++;\n } \n }\n\n tot += cnt\n map.set(arr[i], [i, cnt])\n\n }\n\n console.log(tot)\n}\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n let _t = parseInt(readline());\r\n // let _t = 1;\r\n while (_t--) {\r\n let n = parseInt(readline());\r\n let m = [],\r\n a = [];\r\n for (let i = 0; i < n; i++) {\r\n let s = readline();\r\n a.push(s);\r\n if (m[s]) m[s]++;\r\n else m[s] = 1;\r\n }\r\n let ans = 0;\r\n a.forEach((e) => {\r\n for (let i = 9; i < 36; i++) {\r\n let c = i.toString(36);\r\n if (c === e[0]) continue;\r\n let cur = c + e[1];\r\n ans += m[cur] ? m[cur] : 0;\r\n }\r\n for (let i = 9; i < 36; i++) {\r\n let c = i.toString(36);\r\n if (c === e[1]) continue;\r\n let cur = e[0] + c;\r\n // console.log(cur);\r\n ans += m[cur] ? m[cur] : 0;\r\n }\r\n });\r\n console.log(ans / 2);\r\n }\r\n}\r\n\r\n// cat input.txt | node main.js\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, a)=>{\n let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];\n let result = BigInt(0);\n\n let mapStart = {};\n let mapEnd = {};\n let mapBoth = {};\n\n for (let i = 0; i < n; i++) {\n // mapStart[a[i][0]] = (mapStart[a[i][0]] || 0) + 1;\n // mapEnd[a[i][1]] = (mapEnd[a[i][1]] || 0) + 1;\n\n // pairs like a[i][0] + chars[j]\n for (let j = 0; j < chars.length; j++) {\n if (chars[j] === a[i][1]) continue;\n result += mapBoth[`${a[i][0]}${chars[j]}`] || 0n;\n }\n\n // pairs like chars[j] + a[i][1]\n for (let j = 0; j < chars.length; j++) {\n if (chars[j] === a[i][0]) continue;\n result += mapBoth[`${chars[j]}${a[i][1]}`] || 0n;\n }\n\n mapBoth[a[i]] = (mapBoth[a[i]] || 0n) + 1n;\n }\n\n \n\n \n\n // console.log(`DEBUG mapStart`, mapStart);\n // console.log(`DEBUG mapEnd`, mapEnd);\n // console.log(`DEBUG mapBoth`, mapBoth);\n\n // for (let i = 0; i < chars.length; i++) {\n // for (let j = i; j < chars.length; j++) {\n // if (mapStart[chars[i]]) result += BigInt(cnk(mapStart[chars[i]], 2));\n // if (mapEnd[chars[j]]) result += BigInt(cnk(mapEnd[chars[j]], 2));\n // let pair = `${chars[i]}${chars[j]}`;\n // if (mapBoth[pair]) result -= BigInt(2 * cnk(mapBoth[pair], 2));\n // }\n // console.log(`DEBUG result for ${i}`, result);\n // }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = [];\n for (let i = 0; i < n; i++) {\n a.push(readline());\n }\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \n\nlet ca = \"a\".charCodeAt(0);\nconst compose = (n0, n1)=>{\n return (1<{\n let map = new Map();\n let ans = 0;\n for (let s of A){\n L({s})\n let n0 = s.charCodeAt(0)-ca;\n let n1 = s.charCodeAt(1)-ca;\n for (let i=0; i<=10; i++){\n if (i!=n0){\n let a = compose(i, n1);\n ans += map.get(a)||0;\n if (map.get(a))\n L('ADD1', a.toString(2), map.get(a))\n }\n if (i!=n1){\n let a = compose(n0, i);\n ans += map.get(a)||0;\n if (map.get(a))\n L('ADD2', a.toString(2), map.get(a))\n }\n }\n let a = compose(n0, n1);\n map.set(a, (map.get(a)||0)+1)\n L('SET', a.toString(2), 1)\n }\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = [];\n for (let i=0; i stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst cnt = [];\r\n\t\tconst cntFirst = [];\r\n\t\tconst cntSecond = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst s = rl();\r\n\t\t\tcnt[s] = cnt[s] || 0;\r\n\t\t\tcntFirst[s[0]] = cntFirst[s[0]] || 0;\r\n\t\t\tcntSecond[s[1]] = cntSecond[s[1]] || 0;\r\n\r\n\t\t\tans += cntFirst[s[0]] - cnt[s];\r\n\t\t\tans += cntSecond[s[1]] - cnt[s];\r\n\t\t\tcntFirst[s[0]]++;\r\n\t\t\tcntSecond[s[1]]++;\r\n\t\t\tcnt[s]++;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(a) {\r\n const map = new Map();\r\n const get = char => char.charCodeAt(0) - 97;\r\n let res = 0n;\r\n for (let [l, r] of a) {\r\n var _map$get, _map$get2, _map$get3, _map$get4, _map$get5, _map$get6;\r\n let statel = 1 << get(l),\r\n stater = 1 << get(r) + 11,\r\n state = statel | stater;\r\n res = res + ((_map$get = map.get(statel)) !== null && _map$get !== void 0 ? _map$get : 0n) + ((_map$get2 = map.get(stater)) !== null && _map$get2 !== void 0 ? _map$get2 : 0n) - ((_map$get3 = map.get(state)) !== null && _map$get3 !== void 0 ? _map$get3 : 0n) * 2n;\r\n map.set(statel, ((_map$get4 = map.get(statel)) !== null && _map$get4 !== void 0 ? _map$get4 : 0n) + 1n);\r\n map.set(stater, ((_map$get5 = map.get(stater)) !== null && _map$get5 !== void 0 ? _map$get5 : 0n) + 1n);\r\n map.set(state, ((_map$get6 = map.get(state)) !== null && _map$get6 !== void 0 ? _map$get6 : 0n) + 1n);\r\n }\r\n console.log(res.toString());\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n let n = Number(await read()),\r\n a = [];\r\n while (n--) {\r\n a.push(await read());\r\n }\r\n solve(a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar map = {};\r\n\t\tvar alpha = \"abcdefghijk\";\r\n\t\tfor(var i = 0; i < alpha.length; i++){\r\n\t\t\tfor(var j = 0; j < alpha.length; j++){\r\n\t\t\t\tmap[alpha[i] + alpha[j]] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tmap[list[i]]++;\r\n\t\t}\r\n\t\t\r\n\t\tvar output = 0n;\r\n\t\tvar key = Object.keys(map);\r\n\t\tfor(var i = 0; i < key.length; i++){\r\n\t\t\tfor(var j = i + 1; j < key.length; j++){\r\n\t\t\t\tvar Li = key[i][0];\r\n\t\t\t\tvar Ri = key[i][1];\r\n\t\t\t\tvar Lj = key[j][0];\r\n\t\t\t\tvar Rj = key[j][1];\r\n\t\t\t\tif(Li == Lj || Ri == Rj){\r\n\t\t\t\t\toutput += BigInt(map[key[i]] * map[key[j]]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n n = BigInt(n)\n //\n const map = {}\n arr.forEach(x => {\n const [a, b] = x\n map[a] = map[a] || {}\n map[a][b] = (map[a][b] || 0n) + 1n\n })\n// console.log(map)\n// // return\n const chs = 'abcdefghijk'\n let diff = 0n\n let same = 0n\n // [i, j] [u, v]\n for (let i = 0; i < chs.length; i++) {\n for (let j = 0; j < chs.length; j++) {\n const y = cal(map, chs[i], chs[j])\n same += y * (y - 1n)\n for (let u = 0; u < chs.length; u++) {\n if (u === i) continue\n for (let v = 0; v < chs.length; v++) {\n if (v === j) continue\n const x = cal(map, chs[u], chs[v])\n diff += x * y\n }\n }\n }\n }\n const total = (n - 1n) * n\n// console.log(total, diff, same)\n return (total - diff - same) / 2n\n}\nfunction cal(map, i, j) {\n return (map[i] && map[i][j]) ? map[i][j] : 0n\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(readline().trim());\r\n }\r\n if (n === 1) {\r\n console.log(\"0\");\r\n continue;\r\n }\r\n let alp = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\"];\r\n let obj = {};\r\n obj[arr[n - 1]] = 1;\r\n let sum = 0;\r\n for (let i = n - 2; i >= 0; i--) {\r\n let k = arr[i][1];\r\n for (let j = 0; j < alp.length; j++) {\r\n if (alp[j] !== k) {\r\n if (obj[arr[i][0] + alp[j]]) sum += obj[arr[i][0] + alp[j]];\r\n }\r\n }\r\n k = arr[i][0];\r\n for (let j = 0; j < alp.length; j++) {\r\n if (alp[j] !== k)\r\n if (obj[alp[j] + arr[i][1]]) sum += obj[alp[j] + arr[i][1]];\r\n }\r\n if (obj[arr[i]]) obj[arr[i]] += 1;\r\n else obj[arr[i]] = 1;\r\n }\r\n console.log(sum);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\nconst { consumers } = require(\"stream\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = [];\r\n for (let i = 0; i < n; i++) {\r\n arr.push(readline().trim().split(\"\"));\r\n }\r\n if(n===1) {\r\n console.log(\"0\");\r\n continue;\r\n }\r\n let alp = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\"];\r\n let narr = [];\r\n let obj = {};\r\n for (let i = 0; i < alp.length; i++) {\r\n let na = [];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = 0; k < 2; k++) {\r\n if (arr[j][k] === alp[i]) {\r\n na.push(arr[j]);\r\n break;\r\n }\r\n }\r\n }\r\n narr.push(na);\r\n }\r\n let res = 0n;\r\n for (let i = 0; i < 11; i++) {\r\n if (narr[i].length >= 2) {\r\n let obj = {};\r\n let len = BigInt(narr[i].length);\r\n let sum = 0n;\r\n for (let j = narr[i].length - 1; j >= 0; j--) {\r\n let s1 = narr[i][j][0] + narr[i][j][1];\r\n let s2 = narr[i][j][1] + narr[i][j][0];\r\n if (obj[s1] || obj[s2]) {\r\n obj[s1]++;\r\n } else {\r\n obj[s1] = 1n;\r\n obj[s2] = 1n;\r\n }\r\n if (obj[s1] === 1) sum += len - (BigInt(j) + 1n);\r\n else sum += len - (BigInt(j) + 1n) - (obj[s1] - 1n);\r\n }\r\n res += sum;\r\n }\r\n }\r\n console.log(res + \"\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (n, a)=>{\n let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];\n let result = BigInt(0);\n\n let mapStart = {};\n let mapEnd = {};\n let mapBoth = {};\n\n for (let i = 0; i < n; i++) {\n // mapStart[a[i][0]] = (mapStart[a[i][0]] || 0) + 1;\n // mapEnd[a[i][1]] = (mapEnd[a[i][1]] || 0) + 1;\n\n // pairs like a[i][0] + chars[j]\n for (let j = 0; j < chars.length; j++) {\n if (chars[j] === a[i][1]) continue;\n result += BigInt(mapBoth[`${a[i][0]}${chars[j]}`] || 0);\n }\n\n // pairs like chars[j] + a[i][1]\n for (let j = 0; j < chars.length; j++) {\n if (chars[j] === a[i][0]) continue;\n result += BigInt(mapBoth[`${chars[j]}${a[i][1]}`] || 0);\n }\n\n mapBoth[a[i]] = (mapBoth[a[i]] || 0) + 1;\n }\n\n \n\n \n\n // console.log(`DEBUG mapStart`, mapStart);\n // console.log(`DEBUG mapEnd`, mapEnd);\n // console.log(`DEBUG mapBoth`, mapBoth);\n\n // for (let i = 0; i < chars.length; i++) {\n // for (let j = i; j < chars.length; j++) {\n // if (mapStart[chars[i]]) result += BigInt(cnk(mapStart[chars[i]], 2));\n // if (mapEnd[chars[j]]) result += BigInt(cnk(mapEnd[chars[j]], 2));\n // let pair = `${chars[i]}${chars[j]}`;\n // if (mapBoth[pair]) result -= BigInt(2 * cnk(mapBoth[pair], 2));\n // }\n // console.log(`DEBUG result for ${i}`, result);\n // }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = [];\n for (let i = 0; i < n; i++) {\n a.push(readline());\n }\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \n\nlet ca = \"a\".charCodeAt(0);\nconst compose = (n0, n1)=>{\n return (1<{\n let map = new Map();\n let ans = 0;\n for (let s of A){\n L({s})\n let n0 = s.charCodeAt(0)-ca;\n let n1 = s.charCodeAt(1)-ca;\n for (let i=0; i<10; i++){\n if (i!=n0){\n let a = compose(i, n1);\n ans += map.get(a)||0;\n if (map.get(a))\n L('ADD1', a.toString(2), map.get(a))\n }\n if (i!=n1){\n let a = compose(n0, i);\n ans += map.get(a)||0;\n if (map.get(a))\n L('ADD2', a.toString(2), map.get(a))\n }\n }\n let a = compose(n0, n1);\n map.set(a, (map.get(a)||0)+1)\n L('SET', a.toString(2), 1)\n }\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = [];\n for (let i=0; i {\n const inputs = [];\n let times = null;\n \n const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n \n for await (const line of rl) {\n if (!times) {\n times = line;\n } else {\n if (inputs.length < times * 2 - 1) {\n inputs.push(line);\n } else {\n inputs.push(line);\n rl.close();\n }\n }\n }\n \n runGame(times, inputs);\n };\n \n const runGame = (times, inputs) => {\n for (let i = 0; i < times; i++) {\n findMatch(inputs[i * 2], inputs[i * 2 + 1]); // len, digits\n }\n };\n \n const findMatch = (len, digits) => {\n const arr = digits.toString(10).split(\"\").map(Number);\n let output = 0;\n \n if (len % 2 === 0) {\n for (let evenIndex = 0; evenIndex < +len / 2; evenIndex++) {\n if (arr[2 * evenIndex + 1] % 2 === 0) output++;\n }\n if (output > 0) {\n console.log(\"2\");\n } else {\n console.log(\"1\");\n }\n } else {\n output = 0;\n \n for (let oddIndex = 0; oddIndex < (+len + 1) / 2; oddIndex++) {\n if (arr[(2 * oddIndex)] % 2 !== 0) output++;\n }\n if (output > 0) {\n console.log(\"1\");\n } else {\n console.log(\"2\");\n }\n }\n };\n \n main();", "positive_code": [{"source_code": "let readline=require('readline');\nlet rl=readline.createInterface({\n input:process.stdin,\n output:process.stdout\n});\nlet arr=[],T;\nrl.on('line',function(inp){\n arr.push(inp);\n let len=arr.length;\n if(len===1) T=parseInt(arr[0]);\n else if(len===2*T+1){\n for(let i=2;i<=2*T;i+=2){\n let l=arr[i].length;\n if(l%2){\n let flag=0;\n for(let j=0;j {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const str = readLine();\n let win = false;\n\n if (len % 2 === 1) {\n for (let i = 0; i < len; i += 2) {\n if (+str[i] % 2 === 1) {\n win = true;\n break;\n }\n }\n if (win) console.log(1);\n else console.log(2);\n } else {\n for (let i = 1; i < len; i += 2) {\n if (+str[i] % 2 === 0) {\n win = true;\n break;\n }\n }\n if (win) console.log(2);\n else console.log(1);\n }\n }\n}\n"}, {"source_code": "// Digit Game - https://codeforces.com/problemset/problem/1419/A\n\nconst main = async () => {\n const inputs = [];\n let times = null;\n\n const rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n for await (const line of rl) {\n if (!times) {\n times = line;\n } else {\n if (inputs.length < times * 2 - 1) {\n inputs.push(line);\n } else {\n inputs.push(line);\n rl.close();\n }\n }\n }\n\n runGame(times, inputs);\n};\n\nconst runGame = (times, inputs) => {\n for (let i = 0; i < times; i++) {\n findMatch(inputs[i * 2], inputs[i * 2 + 1]); // len, digits\n }\n};\n\nconst findMatch = (len, digits) => {\n const arr = digits.toString(10).split(\"\").map(Number);\n let output = 0;\n\n if (len % 2 === 0) {\n for (let evenIndex = 0; evenIndex < +len / 2; evenIndex++) {\n if (arr[2 * evenIndex + 1] % 2 === 0) output++;\n }\n if (output > 0) {\n console.log(\"2\");\n } else {\n console.log(\"1\");\n }\n } else {\n output = 0;\n\n for (let oddIndex = 0; oddIndex < (+len + 1) / 2; oddIndex++) {\n if (arr[2 * oddIndex] % 2 !== 0) output++;\n }\n if (output > 0) {\n console.log(\"1\");\n } else {\n console.log(\"2\");\n }\n }\n};\n\nmain();\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n // var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var n = +inputs[i * 2 + 1];\n var number = inputs[i * 2 + 2];\n if (n == 1) {\n console.log(number % 2 == 0 ? 2 : 1);\n continue;\n }\n if (n % 2 == 1) {\n console.log([...number].some((v, i) => i % 2 == 0 && v % 2 == 1) ? 1 : 2);\n }\n else {\n console.log([...number].some((v, i) => i % 2 == 1 && v % 2 == 0) ? 2 : 1);\n }\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let s = ti(readline().split(''));\n\n let isEvenEven = false;\n let isOddOdd = false;\n for(let i = 0; i < n; i++){\n if((i+1) % 2 === 0){\n if(!isEvenEven){\n isEvenEven = s[i] % 2 === 0;\n }\n }else{\n if(!isOddOdd){\n isOddOdd = s[i] % 2 !== 0;\n }\n }\n }\n\n if(n % 2 === 0){\n if(isEvenEven)\n console.log(2);\n else{\n console.log(1);\n }\n }else{\n if(isOddOdd)\n console.log(1);\n else{\n console.log(2);\n }\n }\n }\n}"}], "negative_code": [{"source_code": "const readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst digiGame = (n, _d) => {\n const arr = _d.toString(10).split(\"\").map(Number);\n let output = 0;\n if (n % 2 === 0) {\n for (let evenIndex = 0; evenIndex < n / 2; evenIndex++) {\n if (arr[2 * evenIndex + 1] % 2 === 0) output++;\n }\n if (output > 0) {\n console.log(\"2\");\n } else {\n console.log(\"1\");\n }\n } else {\n output = 0;\n for (let oddIndex = 0; oddIndex < (n + 1) / 2; oddIndex++) {\n if (arr[(2 * oddIndex) % 2 === 0]) output++;\n }\n if (output > 0) {\n console.log(\"1\");\n } else {\n console.log(\"2\");\n }\n }\n};\n\nreadline.question(\"\", (t) => {\n for (let i = 1; i <= t; i++) {\n \n readline.question(\"\", (n) => {\n readline.question(\"\", (_d) => {\n digiGame(n, _d);\n });\n });\n }\n \n});\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const str = readLine();\n let win = false;\n\n if (len % 2 === 1) {\n for (let i = 0; i < len; i += 2) {\n if (+str[i] % 2 === 1) win = true;\n break;\n }\n if (win) console.log(1);\n else console.log(2);\n } else {\n for (let i = 1; i < len; i += 2) {\n if (+str[i] % 2 === 0) win = true;\n break;\n }\n if (win) console.log(2);\n else console.log(1);\n }\n }\n}\n"}], "src_uid": "c9225c915669e183cbd8c20b848d96e5"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n let strings = new Array();\r\n let dict = {};\r\n let result = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let str = readline();\r\n strings.push(str);\r\n if (dict[str]) {\r\n dict[str] = 2;\r\n } else {\r\n dict[str] = 1;\r\n }\r\n }\r\n\r\n wordLoop: for (let i = 0; i < n; i++) {\r\n lengthLoop: for (let len = 1; len < strings[i].length; len++) {\r\n let word = strings[i].substring(0, len);\r\n let suffix = strings[i].substring(len);\r\n if (word.length === strings[i].length / 2 && dict[word] === 2 && word === suffix) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n }\r\n if (dict[word] && dict[suffix]) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n } else {\r\n continue lengthLoop;\r\n }\r\n }\r\n result[i] = '0';\r\n }\r\n\r\n output(result.join(''));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar set = new Set(list);\r\n\t\tvar output = new Array(N).fill(\"0\");\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tvar s = list[i];\r\n\t\t\tvar ok = false;\r\n\t\t\tfor(var j = 0; j < s.length - 1; j++){\r\n\t\t\t\tvar L = s.substring(0, j + 1);\r\n\t\t\t\tvar R = s.substring(j + 1);\r\n\t\t\t\t\r\n\t\t\t\tif(set.has(L) && set.has(R)){\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t}\r\n\t\t\t\tif(L == R && set.has(L)){\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(ok){\r\n\t\t\t\toutput[i] = \"1\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 0));\r\n\t}\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n \r\n var set = new Set();\r\n var arr = [];\r\n \r\n for (var j = 0; j < n; j++) {\r\n var str = readline();\r\n set.add(str);\r\n arr.push(str);\r\n }\r\n \r\n for (var j = 0; j < arr.length; j++) {\r\n for (var k = 1; k < arr[j].length; k++) {\r\n if (\r\n set.has(arr[j].substr(0, k)) && \r\n set.has(arr[j].substr(k, arr[j].length))\r\n ) {\r\n arr[j] = 1;\r\n break;\r\n }\r\n }\r\n arr[j] = arr[j] === 1 ? 1: 0;\r\n }\r\n \r\n print(arr.join(''));\r\n}"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var t1 = +readline();\r\n for(var k = 0; k < t1; k++){\r\n var t3 = readline();\r\n nums.push(t3);\r\n }\r\n print(DoubleString(nums));\r\n \r\n}\r\n \r\nfunction DoubleString(list){\r\n\r\n var set = new Set();\r\n\r\n for(var each of list){\r\n set.add(each);\r\n };\r\n\r\n var res = new Array(list.length).fill(0);\r\n\r\n for(var k = 0; k data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n main();\r\n});"}, {"source_code": "function Solution() {\n let t = 0;\n const N = Number(lines[t++]);\n const res = [];\n for (let i = 0; i < N; i++) {\n const n = Number(lines[t++]);\n\n const strArr = [];\n for (let j = 0; j < n; j++) {\n strArr.push(lines[t++]);\n }\n \n const set = new Set(strArr);\n const r = [];\n \n for (let j = 0; j < n; j++) {\n const curr = strArr[j];\n let flag = false;\n for (let z = 1; z < curr.length; z++) {\n if (set.has(curr.substring(0, z)) && set.has(curr.substring(z))) {\n flag = true;\n break;\n }\n }\n if (flag) r.push(1)\n else r.push(0);\n }\n\n res.push(r.join(''));\n }\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet lineNum = 0;\r\nlet strCnt = 0;\r\nlet curCnt = 0;\r\n/** @type {string[]} arr */\r\nlet arr = [];\r\nlet set = new Set();\r\n\r\nrl.on(\"line\", line => {\r\n let num = Number(line);\r\n if (lineNum === 0) {\r\n // skip\r\n } else if (!isNaN(num)) {\r\n strCnt = num;\r\n curCnt = 0;\r\n set.clear();\r\n arr = [];\r\n } else {\r\n curCnt++;\r\n set.add(line);\r\n arr.push(line);\r\n if (curCnt === strCnt) {\r\n let ans = [];\r\n for (let s of arr) {\r\n let matched = false;\r\n for (let i = 1; i < s.length; i++) {\r\n if (set.has(s.substring(0, i)) && set.has(s.substring(i))) {\r\n matched = true;\r\n break;\r\n }\r\n }\r\n\r\n ans.push(matched ? \"1\" : \"0\");\r\n }\r\n console.log(ans.join(\"\"));\r\n }\r\n }\r\n\r\n lineNum++;\r\n});\r\n"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet lineNum = 0;\r\nlet strCnt = 0;\r\nlet curCnt = 0;\r\n/** @type {string[]} arr */\r\nlet arr = [];\r\nlet set = new Set();\r\n\r\nrl.on(\"line\", line => {\r\n let num = Number(line);\r\n if (lineNum === 0) {\r\n // skip\r\n } else if (!isNaN(num)) {\r\n strCnt = num;\r\n curCnt = 0;\r\n set.clear();\r\n arr = [];\r\n } else {\r\n curCnt++;\r\n set.add(line);\r\n arr.push(line);\r\n if (curCnt === strCnt) {\r\n let ans = \"\";\r\n for (let s of arr) {\r\n let matched = false;\r\n for (let i = 1; i < s.length; i++) {\r\n if (set.has(s.substring(0, i)) && set.has(s.substring(i))) {\r\n matched = true;\r\n break;\r\n }\r\n }\r\n\r\n ans += matched ? \"1\" : \"0\";\r\n }\r\n console.log(ans);\r\n }\r\n }\r\n\r\n lineNum++;\r\n});\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var mp = new Map();\r\n var ans = \"\";\r\n var s = []\r\n for(var i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = 1\n return o\n }, {})\n const ans = arr.map(x => {\n for (let i = 1; i < x.length; i++) {\n const a = x.slice(0, i)\n const b = x.slice(i)\n // console.log(a, b)\n if (map[a] && map[b]) {\n return 1\n }\n }\n return 0\n })\n return ans.join('')\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = [];\r\n for (let i = 0; i < n; i++) arr.push(readline().trim());\r\n let obj = {};\r\n if (n === 1) {\r\n console.log(0);\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n obj[arr[i]] = 1;\r\n }\r\n let obj1 = {};\r\n let res = \"\";\r\n for (let i = 0; i < n; i++) {\r\n let flag = 0;\r\n if (arr[i].length > 1 && !obj1[arr[i]]) {\r\n let x = arr[i];\r\n for (let i = 1; i < x.length; i++) {\r\n if (obj[x.slice(0, i)] && obj[x.slice(i, x.length)]) {\r\n flag = 1;\r\n break;\r\n }\r\n }\r\n res += flag;\r\n if (flag === 0) obj1[arr[i]] = 1;\r\n else obj1[arr[i]] = 2;\r\n } else {\r\n if (arr[i].length === 1) res += flag;\r\n else {\r\n if (obj1[arr[i]] === 1) res += 0;\r\n else res += 1;\r\n }\r\n }\r\n }\r\n console.log(res);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n \r\n var set = new Set();\r\n var arr = [];\r\n \r\n for (var j = 0; j < n; j++) {\r\n var str = readline();\r\n set.add(str);\r\n arr.push(str);\r\n }\r\n \r\n for (var j = 0; j < arr.length; j++) {\r\n for (var k = 1; k < arr[j].length - 1; k++) {\r\n if (\r\n set.has(arr[j].substr(0, k)) && \r\n set.has(arr[j].substr(k, arr[j].length))\r\n ) {\r\n arr[j] = 1;\r\n break;\r\n }\r\n }\r\n arr[j] = arr[j] === 1 ? 1: 0;\r\n }\r\n \r\n print(arr.join(''));\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n let strings = new Array();\r\n let dict = {};\r\n let result = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let str = readline();\r\n strings.push(str);\r\n if (dict[str]) {\r\n dict[str] = 2;\r\n } else {\r\n dict[str] = 1;\r\n }\r\n }\r\n\r\n wordLoop: for (let i = 0; i < n; i++) {\r\n lengthLoop: for (let len = 1; len < strings[i].length; len++) {\r\n let word = strings[i].substring(0, len);\r\n let suffix = strings[i].substring(len);\r\n if (word.length === strings[i].length / 2 && dict[word] === 2 && word === suffix) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n }\r\n if (dict[word] === 1 && dict[suffix]) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n } else {\r\n continue lengthLoop;\r\n }\r\n }\r\n result[i] = '0';\r\n }\r\n\r\n output(result.join(''));\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n let strings = new Array();\r\n let dict = {};\r\n let result = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let str = readline();\r\n strings.push(str);\r\n if (dict[str]) {\r\n dict[str] = 2;\r\n } else {\r\n dict[str] = 1;\r\n }\r\n }\r\n\r\n wordLoop: for (let i = 0; i < n; i++) {\r\n lengthLoop: for (let len = 1; len <= strings[i].length; len++) {\r\n let word = strings[i].substring(0, len);\r\n if (word.length === strings[i].length / 2 && dict[word] === 2) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n }\r\n let suffix = strings[i].substring(len);\r\n if (dict[word] === 1 && dict[suffix]) {\r\n result[i] = '1';\r\n continue wordLoop;\r\n } else {\r\n continue lengthLoop;\r\n }\r\n }\r\n result[i] = '0';\r\n }\r\n\r\n output(result.join(''));\r\n }\r\n}\r\n"}, {"source_code": "// // cat .\\input.txt | node .\\script.js\r\n'use strict';\r\nconst util = require('util')\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() {\r\n let value = inputs.next().value.trim();\r\n return value\r\n};\r\nasync function solve() {\r\n try {\r\n let n = parseInt(await read())\r\n let s = new Array(n)\r\n let mp = new Map()\r\n for (let i = 0; i < n; i++) {\r\n s[i] = await read()\r\n mp.set(s[i], true)\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let ok = false\r\n for (let j = 1; j < s[i].length; j++) {\r\n let pref = s[i].substring(0, j)\r\n let suff = s[i].substring(j, s[i].length - j)\r\n if (mp.get(pref) && mp.get(suff)) {\r\n ok = true\r\n }\r\n }\r\n process.stdout.write(ok == true ? '1' : '0');\r\n }\r\n process.stdout.write('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nasync function main() {\r\n let tt = parseInt(await read())\r\n for (let i = 0; i < tt; i++) {\r\n await solve()\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n let splitted = data.split('\\r\\n')\r\n inputs = await splitted.values();\r\n await main();\r\n});\r\n\r\n"}, {"source_code": "// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node\r\n// // cat .\\input.txt | node .\\script.js\r\n'use strict';\r\nconst util = require('util')\r\nlet data = ''; // raw\r\nlet inputs = ''; // iterator\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n};\r\nasync function main(read) {\r\n try {\r\n let tasks = parseInt(await read())\r\n let result = []\r\n for (let i = 0; i < tasks; i++) {\r\n const sub_length = parseInt(await read())\r\n result[i] = [new Array(sub_length).fill(0)]\r\n for (let j = 0; j < sub_length; j++) {\r\n const element = (await read());\r\n result[i] = [...result[i], element]\r\n }\r\n }\r\n for (let i = 0; i < result.length; i++) {\r\n const element_i = result[i];\r\n for (let j = 1; j < element_i.length; j++) {\r\n let element_j = element_i[j];\r\n // console.log(element_j)\r\n for (let k = 1; k < element_i.length; k++) {\r\n if (j == k) continue\r\n let element_k = element_i[k];\r\n if (element_j.includes(element_k)) {\r\n // console.log(element_j, ' << ', element_k)\r\n element_j = element_j.replace(element_k, '')\r\n --k\r\n }\r\n if (element_j.length == 0) result[i][0][j - 1] = 1\r\n }\r\n }\r\n }\r\n return result.map(e => e[0].join('')).join('\\n')\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => data += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = data.split('\\n').values();\r\n const result = await main(read);\r\n // console.log(util.inspect(result, { showHidden: false, depth: null, colors: true }))\r\n // console.log(result)\r\n process.stdout.write(result);\r\n});\r\n\r\n"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline()//.split(' ').map((x) => parseInt(x));\r\n // var a = readline().split(' ').map((x) => parseInt(x));\r\n var mp = new Map();\r\n var ans = \"\";\r\n var s = []\r\n for(var i=0;i 10) {\n mid = Math.floor((high - low) / 2 + low);\n if (data <= arrayData[mid]) {\n high = mid;\n } else {\n low = mid;\n }\n }\n for (var idx = low; idx <= high; idx++) {\n if (arrayData[idx] === data) {\n return idx;\n }\n }\n return -1;\n};\n\n// dist/FinalCode/Common/InputOutputClass.js\nvar Input = function() {\n function Input2(inputData) {\n var _this = this;\n this.SettleStream = function() {\n var re = /\\s+/;\n _this.inputWords = _this.inputStream.split(re);\n _this.inputWordsLength = _this.inputWords.length;\n };\n this.getLength = function() {\n return _this.inputWordsLength;\n };\n this.getEveryWord = function() {\n return _this.inputWords;\n };\n this.getNextWord = function() {\n _this.inputWordsCount++;\n if (_this.inputWordsLength < _this.inputWordsCount) {\n return \"\";\n }\n return _this.inputWords[_this.inputWordsCount - 1];\n };\n this.getNextString = function() {\n return _this.getNextWord();\n };\n this.getNextBigInt = function() {\n return BigInt(_this.getNextWord());\n };\n this.getNextNumber = function() {\n return Number(_this.getNextWord());\n };\n this.getNextInt = function() {\n return parseInt(_this.getNextWord(), 10);\n };\n this.getNextFloat = function() {\n return parseFloat(_this.getNextWord());\n };\n this.inputWordsCount = 0;\n this.inputStream = inputData;\n }\n Input2.prototype.SetStream = function(chunk) {\n this.inputStream += chunk;\n };\n Input2.prototype.getNextIntArray = function(elementCount) {\n var resultArray = new Array(elementCount);\n for (var idx = 0; idx < elementCount; idx++) {\n resultArray[idx] = this.getNextInt();\n }\n return resultArray;\n };\n return Input2;\n}();\nvar InputOutputClass_default = Input;\nvar writeLine = function(outputElement) {\n var _internalWrite = function(_internalOutputElement) {\n process.stdout.write(_internalOutputElement);\n };\n _internalWrite(String(outputElement) + \"\\n\");\n};\n\n// dist/main.js\nvar rw = new InputOutputClass_default(\"\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", function(chunk) {\n rw.SetStream(chunk);\n});\nprocess.stdin.on(\"end\", function() {\n rw.SettleStream();\n mainFunc();\n});\nvar mainFunc = function() {\n testCases();\n};\nvar testCases = function() {\n var test = rw.getNextInt();\n for (var i = 0; i < test; i++) {\n solveCase();\n }\n};\nvar solveCase = function() {\n var n = rw.getNextInt();\n var nums = rw.getNextIntArray(n);\n var sum = 0;\n for (var i = 0; i < n; i++) {\n sum += nums[i];\n }\n var avg = sum / n;\n nums.sort(function(a, b2) {\n return a - b2;\n });\n var answer = 0;\n var j = n - 1;\n for (var i = 0; i < n - 1; i++) {\n while (nums[i] + nums[j] > 2 * avg && i < j) {\n j--;\n }\n if (!(i < j)) {\n break;\n }\n if (nums[i] + nums[j] === 2 * avg) {\n var b = binSearch(nums, nums[j], i + 1, n - 1);\n if (b !== -1) {\n answer += j - b + 1;\n }\n }\n }\n writeLine(\"\" + answer);\n};\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = BigInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n let sum = 0n;\r\n for (let i = 0; i < n; i++) sum += arr[i];\r\n let t = sum * (n - 2n);\r\n if (t % n) console.log(0);\r\n else {\r\n t = t / n;\r\n let p = sum - t;\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) obj[arr[i]] = 1n;\r\n else obj[arr[i]]++;\r\n }\r\n let cnt = 0n;\r\n if (n - 2n === 1n) {\r\n if (obj[t]) console.log(obj[t] + \"\");\r\n else console.log(0);\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n obj[arr[i]]--;\r\n let k = p - arr[i];\r\n if (obj[k]) cnt += obj[k];\r\n }\r\n console.log(cnt + \"\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let u = 0; u < t; u++){\r\n const n = parseInt(ls[l++]);\r\n const a = ls[l++].split(' ').map(i => parseInt(i));\r\n const cnt = {};\r\n let sum = 0;\r\n for (let i = 0; i < n; i++){\r\n if (cnt[a[i]]){\r\n cnt[a[i]]++;\r\n }\r\n else{\r\n cnt[a[i]] = 1;\r\n }\r\n sum += a[i];\r\n }\r\n\r\n const pairSum = 2*sum/n;\r\n if (!Number.isInteger(pairSum)){\r\n console.log('0');\r\n continue;\r\n }\r\n\r\n let ans = 0;\r\n for (let i = 0; i < n; i++){\r\n let b = pairSum - a[i];\r\n let c = 0;\r\n if (cnt[b]){\r\n c = cnt[b];\r\n }\r\n if (a[i] == b){\r\n c = Math.max(0, c - 1);\r\n }\r\n ans += c;\r\n }\r\n console.log(ans/2);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\nconst rla = () => readLine().split(' ').map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rla();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\t\tlet sum = 0;\r\n\t\tfor (x of a) sum += x;\r\n\t\tlet m = sum / n;\r\n\r\n\t\tlet i = 0; j = n - 1, ans = 0;;\r\n\t\twhile (i < j) {\r\n\t\t\tif (a[i] + a[j] == 2 * m) { \r\n\t\t\t\tif (a[i] == a[j]) {\r\n\t\t\t\t\telms = j - i + 1;\r\n\t\t\t\t\tans += elms * (elms - 1) / 2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tlet i0 = i, j0 = j;\r\n\t\t\t\ti++;\r\n\t\t\t\twhile (a[i] == a[i-1]) i++; \r\n\t\t\t\tj--;\r\n\t\t\t\twhile (a[j] == a[j+1]) j--; \r\n\t\t\t\tans += (i - i0) * (j0 - j);\r\n\t\t\t}\r\n\t\t\telse if (a[i] + a[j] < 2 * m) i++;\r\n\t\t\telse j--;\r\n\t\t\t//console.log(i,j, a[i] + a[j] , 2 * m);\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar sum = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tsum += list[i];\r\n\t\t}\r\n\t\tvar avg = sum / N;\r\n\t\tvar output = 0;\r\n\t\tvar ato = 0;\r\n\t\tvar keys = Object.keys(map);\r\n\t\tfor(var i = 0; i < keys.length; i++){\r\n\t\t\tvar V = map[keys[i]];\r\n\t\t\tvar L = (avg * 2) - keys[i];\r\n\t\t\tif(L == keys[i]){\r\n\t\t\t\tato = V * (V - 1) / 2;\r\n\t\t\t}else if(map[L] != null){\r\n\t\t\t\toutput += map[keys[i]] * map[L];\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output / 2 + ato);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n const target = sum * 2 / n\n // console.log(sum, n, target)\n arr.sort((a, b) => a - b)\n\n let ans = 0\n for (let i = 0; i < arr.length; i++) {\n const a1 = binarySearch(i + 1, n - 1, x => arr[x] < target - arr[i])\n const a2 = binarySearch(i + 1, n - 1, x => arr[x] <= target - arr[i])\n // console.log(a1, a2)\n ans += a2 - a1\n }\n // console.log('-')\n return ans\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = 2 * (tot / n);\r\n var map = {};\r\n for(var i1 = 0;i1 < n;i1++) {\r\n if(map[inp[i1]]) {\r\n map[inp[i1]] += 1;\r\n }\r\n else {\r\n map[inp[i1]] = 1;\r\n }\r\n }\r\n var ans = 0;\r\n for(var i = 0;i < n;i++) {\r\n var other = rem - inp[i];\r\n if(map[other]) {\r\n var f1 = map[other];\r\n var f2 = map[inp[i]];\r\n \r\n if(other == inp[i]) {\r\n if(f1 > 1) {\r\n ans += (f1 * (f1 - 1)) / 2;\r\n map[other] = 0;\r\n }\r\n else {\r\n map[other] = 0;\r\n }\r\n }\r\n else {\r\n ans += (f1 * f2);\r\n map[inp[i]] = 0;\r\n map[other] = 0;\r\n }\r\n }\r\n }\r\n return ans;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var sum = 0;\r\n var mp = {};\r\n for (var i = 0; i < n; i++) {\r\n sum += inp[i];\r\n if (mp.hasOwnProperty(inp[i])) {\r\n mp[inp[i]]++;\r\n } else {\r\n mp[inp[i]] = 1;\r\n }\r\n }\r\n var ans = 0;\r\n var need = (2 * sum) / n;\r\n if ((2 * sum) % n !== 0) {\r\n return 0;\r\n }\r\n for (var i = 0; i < n; i++) {\r\n var req = need - inp[i];\r\n var val = mp[req] || 0;\r\n ans += val;\r\n if (inp[i] == req) ans -= 1;\r\n }\r\n return ans / 2;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += arr[i];\r\n let t = (sum * (n - 2)) / n;\r\n if (t % 1 !== 0) console.log(0);\r\n else {\r\n let p = sum - t;\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n }\r\n let cnt = 0;\r\n if (n - 2 === 1) {\r\n if (obj[t]) console.log(obj[t]);\r\n else console.log(0);\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n obj[arr[i]]--;\r\n let k = p - arr[i];\r\n if (obj[k]) cnt += obj[k];\r\n }\r\n console.log(cnt);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "// dist/FinalCode/Algo/binarySearch.js\nvar binSearch = function(arrayData, data, customLowIdx, customHighIdx) {\n var low = customLowIdx;\n var high = customHighIdx;\n var mid;\n while (high - low > 10) {\n mid = Math.floor((high - low) / 2 + low);\n if (data <= arrayData[mid]) {\n high = mid;\n } else {\n low = mid;\n }\n }\n for (var idx = low; idx <= high; idx++) {\n if (arrayData[idx] === data) {\n return idx;\n }\n }\n return -1;\n};\n\n// dist/FinalCode/Common/InputOutputClass.js\nvar Input = function() {\n function Input2(inputData) {\n var _this = this;\n this.SettleStream = function() {\n var re = /\\s+/;\n _this.inputWords = _this.inputStream.split(re);\n _this.inputWordsLength = _this.inputWords.length;\n };\n this.getLength = function() {\n return _this.inputWordsLength;\n };\n this.getEveryWord = function() {\n return _this.inputWords;\n };\n this.getNextWord = function() {\n _this.inputWordsCount++;\n if (_this.inputWordsLength < _this.inputWordsCount) {\n return \"\";\n }\n return _this.inputWords[_this.inputWordsCount - 1];\n };\n this.getNextString = function() {\n return _this.getNextWord();\n };\n this.getNextBigInt = function() {\n return BigInt(_this.getNextWord());\n };\n this.getNextNumber = function() {\n return Number(_this.getNextWord());\n };\n this.getNextInt = function() {\n return parseInt(_this.getNextWord(), 10);\n };\n this.getNextFloat = function() {\n return parseFloat(_this.getNextWord());\n };\n this.inputWordsCount = 0;\n this.inputStream = inputData;\n }\n Input2.prototype.SetStream = function(chunk) {\n this.inputStream += chunk;\n };\n Input2.prototype.getNextIntArray = function(elementCount) {\n var resultArray = new Array(elementCount);\n for (var idx = 0; idx < elementCount; idx++) {\n resultArray[idx] = this.getNextInt();\n }\n return resultArray;\n };\n return Input2;\n}();\nvar InputOutputClass_default = Input;\nvar writeLine = function(outputElement) {\n var _internalWrite = function(_internalOutputElement) {\n process.stdout.write(_internalOutputElement);\n };\n _internalWrite(String(outputElement) + \"\\n\");\n};\n\n// dist/main.js\nvar rw = new InputOutputClass_default(\"\");\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", function(chunk) {\n rw.SetStream(chunk);\n});\nprocess.stdin.on(\"end\", function() {\n rw.SettleStream();\n mainFunc();\n});\nvar mainFunc = function() {\n testCases();\n};\nvar testCases = function() {\n var test = rw.getNextInt();\n for (var i = 0; i < test; i++) {\n solveCase();\n }\n};\nvar solveCase = function() {\n var n = rw.getNextInt();\n var nums = rw.getNextIntArray(n);\n var sum = 0;\n for (var i = 0; i < n; i++) {\n sum += nums[i];\n }\n var avg = sum / n;\n nums.sort(function(a, b2) {\n return a - b2;\n });\n var answer = 0;\n var j = n - 1;\n for (var i = 0; i < n - 1; i++) {\n while (nums[i] + nums[j] !== 2 * avg && i < j) {\n j--;\n }\n if (!(i < j)) {\n break;\n }\n var b = binSearch(nums, nums[j], i + 1, n - 1);\n answer += j - b + 1;\n }\n writeLine(answer);\n};\n"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = 2 * (tot / n);\r\n var map = {};\r\n for(var i1 = 0;i1 < n;i1++) {\r\n if(map[inp[i1]]) {\r\n map[inp[i1]] += 1;\r\n }\r\n else {\r\n map[inp[i1]] = 1;\r\n }\r\n }\r\n var ans = 0;\r\n for(var i = 0;i < n;i++) {\r\n var other = rem - inp[i];\r\n if(map[other]) {\r\n var f1 = map[other];\r\n var f2 = map[inp[i]];\r\n \r\n if(other == inp[i]) {\r\n if(f1 > 1) {\r\n ans += (f1 * (f1 - 1)) / 2;\r\n }\r\n else {\r\n delete map[other]\r\n }\r\n }\r\n else {\r\n ans += (f1 * f2);\r\n map[inp[i]] = 0;\r\n map[other] = 0;\r\n delete map[other];\r\n delete map[inp[i]];\r\n }\r\n }\r\n }\r\n return ans;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = 2 * (tot / n);\r\n var map = {};\r\n for(var i1 = 0;i1 < n;i1++) {\r\n if(map[inp[i1]]) {\r\n map[inp[i1]] += 1;\r\n }\r\n else {\r\n map[inp[i1]] = 1;\r\n }\r\n }\r\n var ans = 0;\r\n for(var i = 0;i < n;i++) {\r\n var other = rem - inp[i];\r\n if(map[other]) {\r\n var f1 = map[other];\r\n var f2 = map[inp[i]];\r\n \r\n if(other == inp[i]) {\r\n if(f1 > 1) {\r\n ans += (f1 * (f1 - 1)) / 2;\r\n }\r\n else {\r\n map[other] = 0;\r\n }\r\n }\r\n else {\r\n ans += (f1 * f2);\r\n map[inp[i]] = 0;\r\n map[other] = 0;\r\n }\r\n }\r\n }\r\n return ans;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = (tot - ((tot / n) * (n - 2)));\r\n inp.sort((a, b) => a - b);\r\n var i = 0, j = n - 1;\r\n var ans = 0;\r\n while(i < j) {\r\n if(inp[i] + inp[j] > rem) {\r\n j -= 1;\r\n }\r\n else if(inp[i] + inp[j] < rem) {\r\n i += 1;\r\n }\r\n else {\r\n var cnti = 1;\r\n var cntj = 1;\r\n i = i + 1;\r\n j = j - 1;\r\n while(i < j && inp[i] == inp[i - 1]) {\r\n i += 1;\r\n cnti += 1;\r\n }\r\n while(i < j && inp[j] == inp[j + 1]) {\r\n j -= 1;\r\n cntj += 1;\r\n }\r\n ans += (cnti * cntj);\r\n }\r\n }\r\n return ans;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = (tot - ((tot / n) * (n - 2)));\r\n inp.sort((a, b) => a - b);\r\n // var i = 0, j = 0;\r\n // var ans = 0;\r\n // while(i < j) {\r\n // if(inp[i] + inp[j] > rem) {\r\n // j -= 1;\r\n // }\r\n // else if(inp[i] + inp[j] < rem) {\r\n // i += 1;\r\n // }\r\n // else {\r\n // var cnti = 1;\r\n // var cntj = 1;\r\n // var i1 = i + 1;\r\n // var j1 = j - 1;\r\n // while(i1 < j && inp[i1] == inp[i1 - 1]) {\r\n // cnti += 1;\r\n // }\r\n // while(i < j1 && inp[j1] == inp[j1 + 1]) {\r\n // cntj += 1;\r\n // }\r\n // ans += (cnti * cntj);\r\n // }\r\n // }\r\n return rem;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var tot = inp.reduce((p, c) => {\r\n p += c;\r\n return p;\r\n }, 0);\r\n var rem = (tot - ((tot / n) * (n - 2)));\r\n inp.sort((a, b) => a - b);\r\n var i = 0, j = 0;\r\n var ans = 0;\r\n while(i < j) {\r\n if(inp[i] + inp[j] > rem) {\r\n j -= 1;\r\n }\r\n else if(inp[i] + inp[j] < rem) {\r\n i += 1;\r\n }\r\n else {\r\n var cnti = 1;\r\n var cntj = 1;\r\n var i1 = i + 1;\r\n var j1 = j - 1;\r\n while(i1 < j && inp[i1] == inp[i1 - 1]) {\r\n cnti += 1;\r\n }\r\n while(i < j1 && inp[j1] == inp[j1 + 1]) {\r\n cntj += 1;\r\n }\r\n ans += (cnti * cntj);\r\n }\r\n }\r\n return ans;\r\n }\r\n \r\n while (t--) {\r\n print(solve());\r\n }"}, {"source_code": "var t = parseInt(readline());\r\n function solve() {\r\n var n = parseInt(readline());\r\n var inp = readline()\r\n .split(\" \")\r\n .map((data) => +data);\r\n var sum = 0;\r\n var mp = {};\r\n for (var i = 0; i < n; i++) {\r\n sum += inp[i];\r\n if (mp.hasOwnProperty(inp[i])) {\r\n mp[inp[i]]++;\r\n } else {\r\n mp[inp[i]] = 1;\r\n }\r\n }\r\n var ans = 0;\r\n var need = (2 * sum) / n;\r\n if ((2 * sum) % n != 0) {\r\n return 0;\r\n }\r\n for (var i = 0; i < n; i++) {\r\n var req = need - inp[i];\r\n ans += mp[req];\r\n if (inp[i] == req) ans -= 1;\r\n }\r\n return ans / 2;\r\n }\r\n\r\n while (t--) {\r\n print(solve());\r\n }"}], "src_uid": "4e9efd8faa7327e37352f2ebccf5945f"} {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n const s = sum(nums);\n const l = nums.length;\n\n if (s % l !== 0) {\n return -1;\n }\n\n nums = [Number.NEGATIVE_INFINITY, ...nums];\n const target = s / l;\n const actions = [];\n\n const go = (i, j, x) => {\n if (!x) {\n return;\n }\n\n actions.push([i, j, x]);\n nums[i] -= i * x;\n nums[j] += i * x;\n }; // Move everything to the first element\n\n\n for (let i = 2; i < nums.length; i++) {\n const element = nums[i];\n const rem = element % i;\n\n if (rem) {\n go(1, i, i - rem);\n }\n\n const x = Math.ceil(element / i);\n go(i, 1, x);\n } // Fill everything to the target value\n\n\n for (let i = 2; i < nums.length; i++) {\n go(1, i, target);\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n", "positive_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), a = $(n), c = 0, op = [], x, clId = 2, tb = a.sum() / n | 0;\n a.unshift(0);\n\n let clear = () => {\n For(clId, n, 1, i => {\n clId = i;\n if (a[i] == 0) return;\n if (a[1] >= i - a[i] % i) {\n x = i - a[i] % i;\n if (x > 0) {\n op[c++] = `${1} ${i} ${x}`;\n a[1] -= x;\n a[i] += x;\n }\n x = a[i] / i;\n op[c++] = `${i} ${1} ${x}`;\n a[1] += x * i;\n a[i] -= x * i;\n } else return -1;\n })\n }\n\n For(2, n, 1, i => {\n if (a[i] == 0) return;\n if (a[i] % i == 0) {\n x = a[i] / i;\n op[c++] = `${i} ${1} ${x}`;\n a[1] += x * i;\n a[i] -= x * i;\n } else if (a[0] >= i - a[i] % i) {\n x = i - a[i] % i\n op[c++] = `${1} ${i} ${x}`;\n a[1] -= x;\n a[i] += x;\n x = a[i] / i;\n op[c++] = `${i} ${1} ${x}`;\n a[1] += x * i;\n a[i] -= x * i;\n } else if (a[i] > i) {\n x = a[i] / i | 0;\n op[c++] = `${i} ${1} ${x}`;\n a[1] += x * i;\n a[i] -= x * i;\n }\n clear();\n })\n\n // log(a, op)\n\n For(2, n, 1, i => {\n if (a[i] >= tb) return;\n if (a[1] < tb - a[i]) return;\n x = tb - a[i];\n op[c++] = `${1} ${i} ${x}`;\n a[1] -= x;\n a[i] += x;\n })\n\n // log(a, op)\n a.shift();\n if (a.some(v => v != tb)) out.push(-1);\n else {\n out.push(c);\n out.push(...op);\n }\n }\n log(out.join('\\n'))\n}"}], "negative_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let s = a.sum()\n if (s % n != 0) {\n out.push(-1);\n continue;\n }\n let tb = s / n;\n let c = 0;\n let op = [];\n for (let i = 1; i < n; i++) {\n let x = a[i] / (i + 1) | 0;\n if (x == 0) continue;\n op[c++] = `${i + 1} ${1} ${x}`;\n a[0] += (i + 1) * x;\n a[i] -= (i + 1) * x;\n }\n // log(1, a, op);\n kothe = false;\n for (let i = n - 1; i >= 1; i--) {\n if (a[i] > tb) {\n let x = (i + 1) - (a[i] - tb) % (i + 1);\n op[c++] = `${1} ${i + 1} ${x}`;\n a[0] -= x;\n a[i] += x;\n if (a[0] < 0) {\n kothe = true;\n break;\n }\n x = (a[i] - tb) / (i + 1);\n op[c++] = `${i + 1} ${1} ${x}`;\n a[0] += x * (i + 1);\n a[i] -= x * (i + 1);\n }\n }\n if (kothe) {\n out.push(-1);\n continue;\n }\n // log(2, a, op);\n for (let i = 1; i < n; i++) {\n if (a[i] < tb) {\n let x = tb - a[i];\n op[c++] = `${1} ${i + 1} ${x}`;\n a[0] -= x;\n a[i] += x;\n }\n }\n // log(3, a, op);\n out.push(c);\n out.push(...op);\n }\n log(out.join('\\n'));\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let s = a.sum()\n if (s % n != 0) {\n out.push(-1);\n continue;\n }\n let tb = s / n;\n let c = 0;\n let op = [];\n for (let i = 1; i < n; i++) {\n let x = a[i] / (i + 1) | 0;\n if (x == 0) continue;\n op[c++] = `${i + 1} ${1} ${x}`;\n a[0] += (i + 1) * x;\n a[i] -= (i + 1) * x;\n }\n // log(1, a, op);\n for (let i = n - 1; i >= 1; i--) {\n if (a[i] > tb) {\n let x = (i + 1) - (a[i] - tb) % (i + 1);\n op[c++] = `${1} ${i + 1} ${x}`;\n a[0] -= x;\n a[i] += x;\n x = (a[i] - tb) / (i + 1);\n op[c++] = `${i + 1} ${1} ${x}`;\n a[0] += x * (i + 1);\n a[i] -= x * (i + 1);\n }\n }\n // log(2, a, op);\n for (let i = 1; i < n; i++) {\n if (a[i] < tb) {\n let x = tb - a[i];\n op[c++] = `${1} ${i + 1} ${x}`;\n a[0] -= x;\n a[i] += x;\n }\n }\n // log(3, a, op);\n out.push(c);\n out.push(...op);\n }\n log(out.join('\\n'));\n}"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n // 1 1 1 2 0\n const s = sum(nums);\n\n if (s % nums.length !== 0) {\n return -1;\n }\n\n const target = s / nums.length;\n const actions = [];\n\n for (let i = nums.length - 1; i >= 0; i--) {\n let element = nums[i];\n\n while (element !== target) {\n if (element > target && element > i) {\n const diff = element - target;\n let x = Math.ceil(diff / (i + 1));\n let movement = x * (i + 1);\n\n if (nums[i] - movement < 0) {\n x--;\n movement -= i + 1;\n }\n\n actions.push([i + 1, 1, x]);\n nums[0] += movement;\n nums[i] -= movement;\n\n if (nums[i] < 0) {\n throw new Error('1');\n }\n } else {\n let iIndex = -2,\n iValue = 0;\n\n for (let j = i - 1; j >= 0; j--) {\n if (nums[j] > iValue && nums[j] >= j + 1) {\n iIndex = j;\n iValue = nums[j];\n }\n }\n\n if (iIndex < 0) {\n return -2;\n }\n\n const maxX = Math.floor(iValue / (iIndex + 1));\n const wantedX = Math.ceil((target - element) / (iIndex + 1)) || 1;\n const x = wantedX <= maxX ? wantedX : maxX;\n const movement = x * (iIndex + 1);\n actions.push([iIndex + 1, i + 1, x]);\n nums[i] += movement;\n nums[iIndex] -= movement;\n\n if (nums[iIndex] < 0) {\n throw new Error('1');\n }\n }\n\n element = nums[i];\n }\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n // 1 1 1 2 0\n const s = sum(nums);\n\n if (s % nums.length !== 0) {\n return -1;\n }\n\n const target = s / nums.length;\n const actions = [];\n\n for (let i = nums.length - 1; i >= 0; i--) {\n let element = nums[i];\n\n while (element !== target) {\n if (element > target && element > i) {\n const diff = element - target;\n let x = Math.ceil(diff / (i + 1));\n let movement = x * (i + 1);\n\n if (nums[i] - movement < 0) {\n x--;\n movement -= i + 1;\n }\n\n if (x <= 0) {\n throw new Error('4');\n }\n\n actions.push([i + 1, 1, x]);\n nums[0] += movement;\n nums[i] -= movement;\n\n if (nums[i] < 0) {\n throw new Error('1');\n }\n } else {\n let iIndex = -2,\n iValue = 0;\n\n for (let j = i - 1; j >= 0; j--) {\n if (nums[j] > iValue && nums[j] >= j + 1) {\n iIndex = j;\n iValue = nums[j];\n }\n }\n\n if (iIndex < 0) {\n return -2;\n }\n\n const maxX = Math.floor(iValue / (iIndex + 1));\n const wantedX = Math.ceil(Math.max(target - element, 1) / (iIndex + 1));\n const x = wantedX <= maxX ? wantedX : maxX;\n\n if (x <= 0) {\n throw new Error('3');\n }\n\n const movement = x * (iIndex + 1);\n actions.push([iIndex + 1, i + 1, x]);\n nums[i] += movement;\n nums[iIndex] -= movement;\n\n if (nums[iIndex] < 0) {\n throw new Error('1');\n }\n }\n\n element = nums[i];\n }\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n // 1 1 1 2 0\n const s = sum(nums);\n\n if (s % nums.length !== 0) {\n return -1;\n }\n\n const target = s / nums.length;\n const actions = [];\n\n for (let i = nums.length - 1; i >= 0; i--) {\n let element = nums[i];\n\n while (element !== target) {\n if (element > target && element > i) {\n const diff = element - target;\n let x = Math.ceil(diff / (i + 1));\n let movement = x * (i + 1);\n\n if (nums[i] - movement < 0) {\n x--;\n movement -= i + 1;\n }\n\n actions.push([i + 1, 1, x]);\n nums[0] += movement;\n nums[i] -= movement;\n\n if (nums[i] < 0) {\n throw new Error('1');\n }\n } else {\n let iIndex = -2,\n iValue = 0;\n\n for (let j = i - 1; j >= 0; j--) {\n if (nums[j] > iValue && nums[j] >= j + 1) {\n iIndex = j;\n iValue = nums[j];\n }\n }\n\n if (iIndex < 0) {\n return -2;\n }\n\n const maxX = Math.floor(iValue / (iIndex + 1));\n const wantedX = Math.ceil((target - element) / (iIndex + 1)) || 1;\n const x = wantedX <= maxX ? wantedX : maxX;\n const movement = x * (iIndex + 1);\n actions.push([iIndex + 1, i + 1, x]);\n nums[i] += movement;\n nums[iIndex] -= movement;\n\n if (nums[iIndex] < 0) {\n throw new Error('1');\n }\n }\n\n console.log(nums);\n element = nums[i];\n }\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n // 1 1 1 2 0\n const s = sum(nums);\n\n if (s % nums.length !== 0) {\n return -1;\n }\n\n const target = s / nums.length;\n const actions = [];\n\n for (let i = nums.length - 1; i >= 0; i--) {\n let element = nums[i];\n\n while (element !== target) {\n if (element > target) {\n const diff = element - target;\n const x = Math.ceil(diff / (i + 1));\n const movement = x * (i + 1);\n actions.push([i + 1, 1, x]);\n nums[0] += movement;\n nums[i] -= movement;\n } else {\n let iIndex = -2,\n iValue = 0;\n\n for (let j = i - 1; j >= 0; j--) {\n if (nums[j] > iValue && nums[j] >= j + 1) {\n iIndex = j;\n iValue = nums[j];\n }\n }\n\n if (iIndex < 0) {\n return -2;\n }\n\n const maxX = Math.floor(iValue / (iIndex + 1));\n const wantedX = Math.ceil((target - element) / (iIndex + 1));\n const x = wantedX <= maxX ? wantedX : maxX;\n const movement = x * (iIndex + 1);\n actions.push([iIndex + 1, i + 1, x]);\n nums[i] += movement;\n nums[iIndex] -= movement;\n }\n\n element = nums[i];\n }\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction sum(arr) {\n return arr.reduce((s, n) => s + n, 0);\n}\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(nums) {\n // 1 1 1 2 0\n const s = sum(nums);\n\n if (s % nums.length !== 0) {\n return -1;\n }\n\n const target = s / nums.length;\n const actions = [];\n\n for (let i = nums.length - 1; i >= 0; i--) {\n let element = nums[i];\n\n while (element !== target) {\n if (element > target && element > i) {\n const diff = element - target;\n let x = Math.ceil(diff / (i + 1));\n let movement = x * (i + 1);\n\n if (nums[i] - movement < 0) {\n x--;\n movement -= i + 1;\n }\n\n if (x <= 0) {\n throw new Error('4');\n }\n\n actions.push([i + 1, 1, x]);\n nums[0] += movement;\n nums[i] -= movement;\n\n if (nums[i] < 0) {\n throw new Error('1');\n }\n } else {\n let iIndex = -2,\n iValue = 0;\n\n for (let j = i - 1; j >= 0; j--) {\n if (nums[j] > iValue && nums[j] >= j + 1) {\n iIndex = j;\n iValue = nums[j];\n }\n }\n\n if (iIndex < 0) {\n return -2;\n }\n\n const maxX = Math.floor(iValue / (iIndex + 1));\n const wantedX = Math.ceil(Math.max(target - element, 1) / (iIndex + 1));\n const x = wantedX <= maxX ? wantedX : maxX;\n\n if (x <= 0) {\n throw new Error('3');\n }\n\n const movement = x * (iIndex + 1);\n actions.push([iIndex + 1, i + 1, x]);\n nums[i] += movement;\n nums[iIndex] -= movement;\n\n if (nums[iIndex] < 0) {\n throw new Error('1');\n }\n }\n\n element = nums[i];\n }\n }\n\n if (actions.length > nums.length * 3) {\n return -1;\n }\n\n return `${actions.length}\\n${actions.map(a => a.join(' ')).join('\\n')}`;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line2] = input[t].slice(1);\n const answer = solve(line2.split(' ').map(Number));\n console.log(answer);\n }\n}\n\nmain().then();\n"}], "src_uid": "b6fb4d868e3f496466746f5e776ae2cc"} {"source_code": "for (var q = Number (readline ()); q > 0; q--)\r\n {\r\n var s = readline ();\r\n var t = readline ();\r\n var b = false;\r\n\r\n for (var i = s.length - 1; i >= 0 && !b; i--)\r\n {\r\n var z = s.substring (0, i);\r\n z += (s[i] + z.split (\"\").reverse ().join (\"\"));\r\n\r\n if (z.indexOf (t) >= 0) { b = true; }\r\n }\r\n\r\n print (b ? \"Yes\" : \"No\");\r\n }", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let str1 = readline().trim();\r\n let str2 = readline().trim();\r\n let obj = {},\r\n ans = false;\r\n for (let i = 0; i < str1.length; i++) {\r\n if (str1[i] === str2[0]) {\r\n const helper = () => {\r\n for (let j = 0; j + i < str1.length; j++) {\r\n let res1 = str1.substring(i, j + i + 1),\r\n left = j + i + 1;\r\n if (res1.length < str2.length && left > str2.length - res1.length) {\r\n for (let st = i + j - 1; res1.length < str2.length; st--)\r\n res1 += str1[st];\r\n }\r\n let ans = true;\r\n if (res1.length !== str2.length) continue;\r\n for (let st = 0; st < res1.length; st++) {\r\n if (str2[st] !== res1[st]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === true) return true;\r\n }\r\n return false;\r\n };\r\n ans = helper();\r\n if (ans === true) break;\r\n }\r\n }\r\n if (ans === true) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst rev = s => s.split('').reverse().join('');\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet s = rl();\r\n\t\tlet t = rl();\r\n\r\n\t\tlet ans = false;\r\n\t\tfor (let i = 0; !ans && i < s.length; i++) {\r\n\r\n\t\t\ttl = t.slice(0, i+1);\r\n\t\t\ttr = t.slice(i);\r\n\r\n\t\t\tif (tr.indexOf(rev(tl)) == 0 && s.includes(rev(tr)))\r\n\t\t\t\tans = true;\r\n\t\t\tif (rev(tl).indexOf(tr) == 0 && s.includes(tl))\r\n\t\t\t\tans = true;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "r=readline\r\nt=+r()\r\nwhile(t--)\r\n{\r\n s=r()\r\n f=r()\r\n a=\"\";\r\n ok=false;\r\n for(i=0;i=0 && pos=0 && l=0 && pos=0 && l=0 && pos parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let str1 = stringArr();\r\n let str2 = stringArr();\r\n let obj = {};\r\n for (let i = 0; i < str1.length; i++) {\r\n if (str1[i] === str2[0]) {\r\n if (obj[str2[0]] === undefined) obj[str2[0]] = [];\r\n obj[str2[0]].push(i);\r\n }\r\n }\r\n if (obj[str2[0]] === undefined) console.log(\"NO\");\r\n else {\r\n const helper = (pos) => {\r\n if (pos === str1.length - 1) {\r\n let left = pos - 1,\r\n i = 1;\r\n while (i < str2.length && left >= 0 && str2[i] === str1[left]) {\r\n i++;\r\n left--;\r\n }\r\n if (i === str2.length) return true;\r\n else return false;\r\n } else {\r\n let left = pos + 1,\r\n i = 1;\r\n while (\r\n i < str2.length &&\r\n left < str1.length &&\r\n str2[i] === str1[left]\r\n ) {\r\n left++;\r\n i++;\r\n }\r\n if (i === str2.length) return true;\r\n let right = left - 2;\r\n while (i < str2.length && right >= 0 && str1[right] === str2[i]) {\r\n i++;\r\n right--;\r\n }\r\n if (i === str2.length) return true;\r\n else return false;\r\n }\r\n };\r\n let k = obj[str2[0]],\r\n ans = false;\r\n for (let i = 0; i < k.length; i++) {\r\n ans = helper(k[i]);\r\n if (ans === true) break;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "r=readline\r\nt=+r()\r\nwhile(t--){\r\n s=r()\r\n f=r();n=s.length;m=f.length\r\n ok=false;\r\n for(i in s){\r\n a=\"\";\r\n if(s[i]==f[0]){\r\n a+=s[i]; p=i; l=1; left=false;\r\n while(p=0 && pos=0 && l=0 && pos=0 && l=0 && l=0 && l 0; q--)\r\n {\r\n var s = readline ();\r\n var t = readline ();\r\n var b = false;\r\n\r\n for (var i = s.length - 1; i > 0 && !b; i--)\r\n {\r\n var z = s.substring (0, i);\r\n z += (s[i] + z.split (\"\").reverse ().join (\"\"));\r\n\r\n if (z.indexOf (t) >= 0) { b = true; }\r\n }\r\n\r\n print (b ? \"Yes\" : \"No\");\r\n }"}], "src_uid": "d69e10bb05d119ec2ad4b5c0e4304336"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const limit = 1e15;\n let [c, min, flag] = [1, Number.MAX_SAFE_INTEGER, true];\n arr.sort((a, b) => a - b);\n\n while (flag) {\n let count = 0;\n for (let i = 0; i < len; i++) {\n const sqr = Math.pow(c, i);\n if (sqr >= limit) {\n flag = false;\n break;\n }\n const diff = Math.abs(sqr - arr[i]);\n count += diff;\n }\n if (!flag) break;\n min = Math.min(min, count);\n c++;\n }\n\n console.log(min);\n}\n", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort((a, b) => a - b)\n let minOperations = null\n let c = 1, op = null\n while (true) {\n let currentOperations = 0\n for (let i = 0, sequenceN = 1; i < N; i++, sequenceN *= c) {\n currentOperations += Math.abs(A[i] - sequenceN)\n }\n if (minOperations !== null && minOperations < currentOperations) {\n break\n }\n minOperations = currentOperations\n c++\n }\n console.log(minOperations)\n\n process.exit()\n}"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nconst getDif = (c, a) => {\n let sum = 0;\n let count = 1;\n a.forEach((_a, idx) => {\n sum += Math.abs(count - _a);\n count *= c;\n });\n return sum;\n}\n\nfunction main() {\n const n = Number(readLine());\n const a = readLine().split(' ').sort((_a, _b) => _a - _b);\n\n let min = getDif(1, a);\n let min2 = getDif(2, a);\n let i = 2;\n while (min2 < min) {\n min = min2;\n i++;\n min2 = getDif(i, a);\n }\n console.log(min);\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), a = $(n).sort(asc)\n if (n > 50) {\n log(a.sum() - n)\n } else {\n let res = a.sum() - n;\n For(1e5, i => {\n if (i ** (n - 1) > 1e14) return 1;\n res = min(res, Arr(n, j => abs(i ** j - a[j])).sum())\n })\n log(res)\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])), A.length); c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperations = null\n let c = 1, op = null\n while (true) {\n let currentOperations = 0\n for (let i = 0, sequenceN = 1; i < N; i++, sequenceN *= c) {\n currentOperations += Math.abs(A[i] - sequenceN)\n }\n if (minOperations === null) {\n minOperations = currentOperations\n } else if (minOperations < currentOperations) {\n break\n }\n minOperations = currentOperations\n c++\n }\n console.log(minOperations)\n\n process.exit()\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])), A.length); c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n if (c === 0) {\n expectedA[0] = 0\n }\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.ceil(Math.sqrt(A[A.length - 1])); c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])), A.length * A.length); c > 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])) + 1, A.length * A.length); c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = A.length; c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.ceil(Math.sqrt(A[A.length - 1])); c > 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])), A.length * A.length); c >= 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.split(/\\n/)\n main()\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const N = Number(readLine())\n const A = readLine().split(' ').map(value => Number(value))\n A.sort()\n let minOperation = null\n for (let c = Math.max(Math.ceil(Math.sqrt(A[A.length - 1])), A.length); c > 0; c--) {\n const expectedA = new Array(N).fill(0).map(((value, index) => Math.pow(c, index)))\n let currentMinOperation = 0\n for (let i = 0; i < N; i++) {\n currentMinOperation += Math.abs(expectedA[i] - A[i])\n }\n if (minOperation === null) {\n minOperation = currentMinOperation\n } else if (minOperation > currentMinOperation) {\n minOperation = currentMinOperation\n }\n }\n console.log(minOperation)\n}"}], "src_uid": "54e9c6f24c430c5124d840b5a65a1bc4"} {"source_code": "const readline = require('readline');\nconst { randomBytes } = require('crypto');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\nvar tempk = 0\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n// compute('1 2 2', 3)\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>max&&r!=0){\n max = remainStats[r]\n maxi = r\n }\n if(remainStats[r]==max){\n if(r!=0&&r maxCount || amap[x] === maxCount && x > maxA) {\n maxCount = amap[x];\n maxA = x;\n }\n }\n if (maxCount === 0) {\n write(0);\n return;\n }\n write((maxCount - 1) * k + maxA + 1);\n\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\nvar tempk = 0\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>max&&r!=0){\n max = remainStats[r]\n maxi = r\n }\n }\n\n // var max = 0\n // var maxi = 0\n // for(var i=1;imax){\n // max = remainStats[i]\n // maxi = i\n // }\n // }\n // console.log(max, maxi)\n if(max==0){\n return 0\n }\n return ((max-1)*k+(k - maxi)+1)\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\nvar tempk = 0\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>max&&r!=0){\n max = remainStats[r]\n maxi = r\n }\n }\n\n // var max = 0\n // var maxi = 0\n // for(var i=1;imax){\n // max = remainStats[i]\n // maxi = i\n // }\n // }\n console.log(max, maxi)\n if(max==0){\n return 0\n }\n return ((max-1)*k+(k - maxi)+1)\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\nvar tempk = 0\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>=max&&r > 0&&r {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>max){\n max = remainStats[r]\n maxi = r\n }\n }\n\n // var max = 0\n // var maxi = 0\n // for(var i=1;imax){\n // max = remainStats[i]\n // maxi = i\n // }\n // }\n console.log(max, maxi)\n if(max==0||maxi==0){\n return 0\n }\n return ((max-1)*k+(k - maxi)+1)\n}"}, {"source_code": "const readline = require('readline');\nconst { randomBytes } = require('crypto');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\nvar tempk = 0\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n tempk = parseInt(input.split(' ')[1])\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input, tempk) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input, tempk) + '\\n'\n }\n lineCount++\n});\n\n\nfunction compute(str, k) {\n var list = str.split(' ')\n var remainStats = []\n var max = 0\n var maxi = 0\n for(var item of list){\n var r = parseInt(item) % k\n remainStats[r] = remainStats[r]?remainStats[r]+1:1\n if(remainStats[r]>=max&&r > 0){\n max = remainStats[r]\n if(maxi==0||r z += c);\nprocess.stdin.on('end', () => {\n const {\n EOL\n } = require('os');\n let input = z.split(EOL)[0]\n let noA = '';\n for (const item of input) {\n if (item != 'a')\n noA += item;\n }\n if(noA.length===0)\n console.log(input);\n else if(noA.slice(0,parseInt(noA.length/2))===noA.slice(parseInt(noA.length/2)) && input.slice(input.length-(noA.length/2)).match(/[a]/g)===null){\n console.log(input.slice(0, (input.length - (noA.length / 2))));\n }\n else\n console.log(':(');\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction main (s) {\n let s1 = \"\";\n let s2 = \"\"\n for (i = 0; i < s.length; i++) {\n const char = s[i];\n s1 += char;\n if (char !== \"a\") {\n s2 += char;\n }\n\n const s3 = s.slice(i+1);\n if (s2 === s3 && s3.indexOf(\"a\") === -1) {\n return s1;\n }\n }\n return \":(\";\n}\n/*\nfunction main2(s) {\n start = 0;\n end = s.length - 1;\n let result = \"\";\n let result_without_a = \"\";\n while (true) {\n if (s[start] === \"a\") {\n result += s[start];\n continue;\n } else {\n result_without_a += s[start];\n }\n\n }\n}\n*/\n\n\nrl.on('line', (str) => {\n console.log(main(str));\n rl.close();\n});\n/*\nrl.on('line', (str) => {\n let s = str.split(\"\");\n if (s.every(char => char === 'a')) {\n result = str;\n } else {\n if (s[s.length -1] === \"a\"){\n result = \":(\";\n } else {\n let new_s = s.filter(char => char !== 'a');\n if (new_s.length % 2) {\n result = \":(\";\n } else {\n const medium = new_s.length / 2;\n const s2 = new_s.slice(medium).join(\"\");\n if (new_s.slice(0, medium).join(\"\") === s2) {\n const pos = str.lastIndexOf(s2);\n result = s.slice(0, pos).join(\"\");\n } else {\n result = \":(\";\n }\n }\n }\n \n }\n console.log(result);\n rl.close();\n \n});\n*/"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (str) => {\n let s = str.split(\"\");\n if (s.every(char => char === 'a')) {\n result = str;\n } else {\n if (s[s.length -1] === \"a\"){\n result = \":(\";\n } else {\n let new_s = s.filter(char => char !== 'a');\n if (new_s.length % 2) {\n result = \":(\";\n } else {\n const medium = new_s.length / 2;\n const s2 = new_s.slice(medium).join(\"\");\n if (new_s.slice(0, medium).join(\"\") === s2) {\n const pos = str.lastIndexOf(s2);\n result = s.slice(0, pos).join(\"\");\n } else {\n result = \":(\";\n }\n }\n }\n \n }\n console.log(result);\n rl.close();\n \n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (str) => {\n let s = str.split(\"\");\n if (s.every(char => char === 'a')) {\n result = str;\n } else {\n if (s[s.length -1] === \"a\"){\n result = \":(\";\n } else {\n if (str.indexOf(\"a\") < 0) {\n result = str;\n } else {\n let new_s = s.filter(char => char !== 'a');\n if (new_s.length % 2) {\n result = \":(\";\n } else {\n const medium = new_s.length / 2;\n const s2 = new_s.slice(medium).join(\"\");\n if (new_s.slice(0, medium).join(\"\") === s2) {\n const pos = str.lastIndexOf(s2);\n result = s.slice(0, pos).join(\"\");\n } else {\n result = \":(\";\n }\n }\n }\n\n }\n \n }\n console.log(result);\n rl.close();\n \n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nrl.on('line', (str) => {\n let s = str.split(\"\");\n if (s.every(char => char === 'a')) {\n result = str;\n } else {\n if (s[s.length -1] === \"a\"){\n result = \":(\";\n } else {\n if (str.indexOf(\"a\") < 0) {\n result = \"\";\n } else {\n let new_s = s.filter(char => char !== 'a');\n if (new_s.length % 2) {\n result = \":(\";\n } else {\n const medium = new_s.length / 2;\n const s2 = new_s.slice(medium).join(\"\");\n if (new_s.slice(0, medium).join(\"\") === s2) {\n const pos = str.lastIndexOf(s2);\n result = s.slice(0, pos).join(\"\");\n } else {\n result = \":(\";\n }\n }\n }\n\n }\n \n }\n console.log(result);\n rl.close();\n \n});"}, {"source_code": "let z = '';\nprocess.stdin.on('data', c => z += c);\nprocess.stdin.on('end', () => {\n const {\n EOL\n } = require('os');\n let input = z.split(EOL)[0]\n let noA = '';\n for (const item of input) {\n if (item != 'a')\n noA += item;\n }\n \n if(noA.slice(0,parseInt(noA.length/2))===noA.slice(parseInt(noA.length/2))){\n console.log(input.slice(0, (input.length - (noA.length / 2))));\n return 0;\n }\n console.log(':(');\n});"}, {"source_code": "var a = readline();\nvar b = get(a);\nif (includes(a,'a')) {\n if (a == b) {\n print(a);\n } else {\n if (b.length % 2 ==0) {\n var mid = b.length/2;\n if (b.substring(0,mid) === b.substring(mid,b.length)) {\n if (isValid(a.substring(0,a.length-mid), a)) {\n print(a.substring(0,a.length-mid));\n } else {\n print(':(');\n }\n } else {\n print(':(');\n }\n } else {\n print(':(');\n }\n }\n} else {\n print(':(');\n}\n\n\nfunction isValid(a,b) {\n var val =\"\";\n for (var i = 0; i = 0; --i) {\n if (a[i] != 'a') {\n last += a[i];\n } else {\n last = last.split(\"\").reverse().join(\"\");\n for (var j = 0; j < i; ++j) {\n first += a[j] != 'a' ? a[j] : \"\";\n }\n break;\n }\n}\nvar b = first + last;\nif (b.length % 2 == 0) {\n var mid = b.length / 2;\n var f = b.substring(0, mid);\n var l = b.substring(mid, b.length);\n if (f == l) {\n print(a.substring(0, a.length - f.length));\n } else {\n print(\":(\");\n }\n} else {\n print(\":(\");\n}\n"}, {"source_code": "var a = readline();\nvar last = \"\";\nvar first = \"\";\nfor (var i = a.length - 1; i >= 0; --i) {\n if (a[i] != 'a') {\n last += a[i];\n } else {\n last = last.split(\"\").reverse().join(\"\");\n for (var j = 0; j < i; ++j) {\n first += a[j] != 'a' ? a[j] : \"\";\n }\n break;\n }\n}\nvar b = first + last;\nif ((last.length == 0 && first.length != 0)) {\n print(\":(\");\n}\nelse if (b.length % 2 == 0) {\n var mid = b.length / 2;\n var f = b.substring(0, mid);\n var l = b.substring(mid, b.length);\n if (f == l) {\n print(a.substring(0, a.length - f.length));\n } else {\n print(\":(\");\n }\n} else {\n print(\":(\");\n}\n"}], "src_uid": "b5bcb6d78daacd56362fd76e35b903ac"} {"source_code": "const tests = readline().split(\" \").map(x => parseInt(x));\nconst t = tests[0];\nfor (var i=0; i parseInt(x));\n var n = data[0];\n var k1 = data[1];\n var k2 = data[2];\n var k1nums = readline().split(\" \").map(x => parseInt(x));\n var k2nums = readline().split(\" \").map(x => parseInt(x));\n var k1max = Math.max(k1nums);\n (Math.max(...k1nums) > Math.max(...k2nums)) ? print(\"YES\") : print(\"NO\");\n}", "positive_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 3) {\n let cardsA = lines[i+1].split(' ').map(Number);\n let cardsB = lines[i+2].split(' ').map(Number);\n // console.log('cardsA', cardsA);\n // console.log('cardsB', cardsB);\n let maxA = cardsA.reduce((acc, v) => Math.max(acc, v), Number.MIN_VALUE);\n let maxB = cardsB.reduce((acc, v) => Math.max(acc, v), Number.MIN_VALUE);\n console.log(maxA > maxB ? 'YES' : 'NO');\n }\n});"}, {"source_code": "var i;\nprocess.stdin.on('data', c => i += c);\n\nprocess.stdin.on('end', () => {\n\n var lines = i.split(\"\\n\");\n var problems = +lines[0];\n\n for(let i = 2; i < lines.length; i+=3) a(lines[i].split(\" \").map(x => +x), lines[i+1].split(\" \").map(x => +x));\n});\n\nfunction a(one, two) {\n\n one = one.sort((a, b) => a - b);\n two = two.sort((a, b) => a - b);\n\n if(one[one.length-1] > two[two.length-1]) console.log(\"yes\");\n else console.log(\"no\");\n}"}, {"source_code": "let fs=require('fs');\n\nlet txt=fs.readFileSync(0,\"utf-8\").split(/[\\r\\n]/).filter(data=>data.length>0);\n\ntxt.shift();\n\nfor (let i = 0; i < txt.length; i+=3) {\n doit(txt[i+1].split(\" \").filter(data=>data.length>0).map(data=>data*1).sort((a,b)=>b-a),txt[i+2].split(\" \").filter(data=>data.length>0).map(data=>data*1).sort((a,b)=>b-a));\n\n \n}\n\nfunction doit(tab,tab1){\n if(tab[0]>tab1[0]){\n console.log(\"YES\");\n }else{\n console.log(\"NO\");\n \n }\n \n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var inputs = readline().split(' ').map(el => parseInt(el, 10));\n var n = inputs[0], k1 = inputs[1], k2 = inputs[2];\n var a = readline().split(' ').map(el => parseInt(el, 10));\n var b = readline().split(' ').map(el => parseInt(el, 10));\n \n print(a.sort((a,b) => a-b).pop() > b.sort((a,b) => a-b).pop() ? 'YES' : 'NO');\n}\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n n = readline().split(' ')[0];\n n = +n;\n found = false;\n readline().split(' ').map(Number).forEach(x => found |= x === n);\n readline();\n if (found){\n print('YES');\n } else {\n print('NO');\n }\n \n}"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var data = readline();\n var first = readline().split(' ').map(Number);\n var second = readline().split(' ').map(Number);\n\n print(getMaxOfArray(first) > getMaxOfArray(second) ? \"YES\" : \"NO\");\n }\n}\n\nfunction getMaxOfArray(numArray) {\n return Math.max.apply(null, numArray);\n}\n\nmain()"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = readInt(arr)\n\n for(let j = 0; j < t; j++) {\n const [n, k1, k2] = readInts(arr, 3 * j)\n const a = readInts(arr, 3 * j + 1)\n const b = readInts(arr, 3 * j + 2)\n\n let t = 'NO'\n for(let i = 0; i < k1; i++) {\n if(a[i] == n) {\n t = 'YES'\n break\n } \n }\n wr(t)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var k1 = one[1];\n var k2 = one[2];\n var first = Math.max.apply(null, nextIntArray());\n var second = Math.max.apply(null, nextIntArray());\n if(first > second){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = -1;\nlet player1;\nlet player2;\n\nrl.on('line', (d) => {\n if (c === -1) {\n c++;\n return;\n }\n\n if (c % 3 === 0) {\n c++;\n return;\n }\n\n if (c % 3 === 1) {\n player1 = Math.max(...d.split(' ').map(Number));\n c++;\n return;\n }\n\n player2 = Math.max(...d.split(' ').map(Number));\n\n if (player1 > player2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction parseIntArrLine() {\n return readLine().split(' ').map(cTemp => parseInt(cTemp, 10));\n}\n\nfunction main() {\n const numberOfTestCases = parseInt(readLine(), 10);\n const results = [];\n let n, k1, k2, k1Cards, k2Cards, k1Max, k2Max;\n for (let i = 1; i <= numberOfTestCases; i++) {\n [n, k1, k2] = parseIntArrLine();\n k1Cards = parseIntArrLine();\n k2Cards = parseIntArrLine();\n k1Max = Math.max(...k1Cards);\n k2Max = Math.max(...k2Cards);\n results.push(k1Max > k2Max ? \"YES\" : \"NO\");\n }\n results.forEach(item => {\n process.stdout.write(item + \"\\n\");\n });\n process.stdout.end();\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine(), 10);\n \n for(let i=1; i<=t; i++) {\n let inputs = readLine();\n inputs = inputs.split(' ');\n let n = parseInt(inputs[0], 10);\n let k1 = parseInt(inputs[1], 10);\n let k2 = parseInt(inputs[2], 10);\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let a = inputs.map(el => parseInt(el, 10));\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let b = inputs.map(el => parseInt(el, 10));\n \n console.log(a.sort((a,b) => a-b).pop() > b.sort((a,b) => a-b).pop() ? 'YES' : 'NO');\n }\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = -1;\nlet player1;\nlet player2;\n\nrl.on('line', (d) => {\n if (c === -1) {\n c++;\n return;\n }\n\n if (c % 3 === 0) {\n c++;\n return;\n }\n\n if (c % 3 === 1) {\n player1 = Math.max(d.split(' ').map(Number));\n c++;\n return;\n }\n\n player2 = Math.max(d.split(' ').map(Number));\n\n if (player1 > player2) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine(), 10);\n \n for(let i=1; i<=t; i++) {\n let inputs = readLine();\n inputs = inputs.split(' ');\n let n = parseInt(inputs[0], 10);\n let k1 = parseInt(inputs[1], 10);\n let k2 = parseInt(inputs[2], 10);\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let a = inputs.map(el => parseInt(el, 10));\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let b = inputs.map(el => parseInt(el, 10));\n \n console.log(a.reduce((a, b) => a+b) > b.reduce((a, b) => a+b) ? 'YES' : 'NO' );\n }\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine(), 10);\n \n for(let i=1; i<=t; i++) {\n let inputs = readLine();\n inputs = inputs.split(' ');\n let n = parseInt(inputs[0], 10);\n let k1 = parseInt(inputs[1], 10);\n let k2 = parseInt(inputs[2], 10);\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let a = inputs.map(el => parseInt(el, 10));\n \n inputs = readLine();\n inputs = inputs.split(' ');\n let b = inputs.map(el => parseInt(el, 10));\n \n console.log(a.sort().pop() > b.sort().pop() ? 'YES' : 'NO');\n }\n}"}, {"source_code": "var i;\nprocess.stdin.on('data', c => i += c);\n\nprocess.stdin.on('end', () => {\n\n var lines = i.split(\"\\n\");\n var problems = +lines[0];\n\n for(let i = 2; i < lines.length; i+=3) a(lines[i].split(\" \").map(x => +x), lines[i+1].split(\" \").map(x => +x));\n});\n\nfunction a(one, two) {\n\n one = one.sort();\n two = two.sort();\n\n if(one[one.length-1] > two[two.length-1]) console.log(\"yes\");\n else console.log(\"no\");\n}"}, {"source_code": "var i;\nprocess.stdin.on('data', c => i += c);\n\nprocess.stdin.on('end', () => {\n\n var lines = i.split(\"\\n\");\n var problems = +lines[0];\n\n for(let i = 3; i < lines.length; i+=3) a(lines[i].split(\" \").map(x => +x), lines[i+1].split(\" \").map(x => +x));\n});\n\nfunction a(one, two) {\n\n one = one.sort();\n two = two.sort();\n\n if(one[one.length-1] > two[two.length-1]) console.log(\"yes\");\n else console.log(\"no\");\n}"}, {"source_code": "const tests = readline().split(\" \").map(x => parseInt(x));\nconst t = tests[0];\nfor (var i=0; i parseInt(x));\n var n = data[0];\n var k1 = data[1];\n var k2 = data[2];\n var k1nums = readline().split(\" \").map(x => parseInt(x));\n var k2nums = readline().split(\" \").map(x => parseInt(x));\n var k1max = Math.max(k1nums);\n (Math.max(k1nums) > Math.max(k2nums)) ? print(\"YES\") : print(\"NO\");\n}"}, {"source_code": "const tests = readline().split(\" \").map(x => parseInt(x));\nconst t = tests[0];\nfor (var i=0; i parseInt(x));\n const n = data[0];\n const k1 = data[1];\n const k2 = data[2];\n const k1nums = readline().split(\" \").map(x => parseInt(x));\n const k2nums = readline().split(\" \").map(x => parseInt(x));\n const k1max = Math.max(k1nums);\n (Math.max(k1nums) > Math.max(k2nums)) ? print(\"YES\") : print(\"NO\");\n}"}], "src_uid": "3ef23f114be223255bd10131b2375b86"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar findMaxFrom = function (from) {\n let ans = cont[from];\n for (let i = from; i < n; i++) {\n if (cont[i] > ans)\n ans = cont[i];\n }\n return ans;\n}\nvar n, rub, cont = [], indicator = 0;\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n let temp = input.split(' ').map(item => parseInt(item));\n n = temp[0];\n rub = temp[1];\n indicator++;\n } else {\n cont = input.split(' ').map(item => parseInt(item));\n let maxRubl = rub;\n for (let i = 0; i < n - 1; i++) {\n let dollars = Math.floor(rub / cont[i]);\n let remRub = rub % cont[i];\n let helper = findMaxFrom(i + 1);\n let currentRubl = dollars * helper + remRub;\n if (maxRubl < currentRubl)\n maxRubl = currentRubl;\n }\n console.log(maxRubl);\n rl.close();\n }\n\n});", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numDays = integers[0], numDollars = integers[1];\n\tvar best = numDollars;\n\tvar prices = tokenizeIntegers(readline());\n\tfor (var buyDay = 0; buyDay < numDays; ++buyDay) {\n\t\tvar martian = Math.floor(numDollars/prices[buyDay]);\n\t\tvar human = numDollars - martian*prices[buyDay];\n\t\tfor (var sellDay = buyDay+1; sellDay < numDays; ++sellDay) {\n\t\t\tbest = Math.max(best, human + martian*prices[sellDay]);\n\t\t}\n\t}\n\tprint(best);\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\nlet N = lll[0]\nlet b = lll[1]\nlet ps = readline().split(' ').map(v => parseInt(v))\n\nlet bst = b\n\nfor (let i = 0; i < ps.length; i++) {\n for (let j = i; j < ps.length; j++) {\n let md = b / ps[i] | 0\n let rb = b % ps[i] + md * ps[j]\n bst = Math.max(bst, rb)\n }\n}\n\nprint(bst)"}], "negative_code": [], "src_uid": "2c9133650d831fa6ab4c11661bcb9cbb"} {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var arr = readline().split(' ').map(item => +item);\n var vals = readline().split(' ').map(item => +item);\n \n var elems = [];\n \n vals.forEach((item, index) => {\n if(item % 2 > 0) {\n elems.push(index);\n }\n });\n \n if(elems.length < arr[1] || elems.length % 2 !== arr[1] % 2) {\n print('NO');\n } else {\n print('YES');\n var res = [];\n for(var j = 0; j < arr[1] - 1; j++){\n res.push(elems[j] + 1);\n }\n res.push(arr[0]);\n print(res.join(' '));\n }\n}", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, k) {\n let start = 0;\n let end = 0;\n let result = [];\n let count = 1;\n\n while (end < data.length && count <= k) {\n end++;\n\n if (count === k) {\n end = data.length;\n }\n\n //console.log(start, end)\n if (data.slice(start, end).reduce((a, b) => a + b) % 2) {\n count++;\n result.push(end);\n start = end;\n }\n }\n return result;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let k = lines[testCount * 2 - 1].split(\" \").map(Number)[1];\n //console.log(data, k)\n let result = foo(data, k);\n //console.log(result)\n if (result.length !== k) answer += \"NO\\n\";\n else {\n answer += \"YES\\n\";\n answer += result.join(\" \") + \"\\n\";\n }\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var q = rdN();\n while (q --> 0) {\n var input = rdArN();\n var n = input[0];\n var k = input[1];\n var A = rdArN();\n var res = [];\n var sum = 0;\n for (var i = 0; i < A.length && res.length < k - 1; ++i) {\n sum += A[i];\n if (sum%2 === 1) {\n res.push(i+1);\n sum = 0;\n }\n }\n if (i === A.length) {\n pr('NO');\n } else {\n sum = A.slice(i).reduce((a,v) => a+v, 0);\n if (sum%2 === 1) {\n pr('YES');\n prAr(res.concat([n]));\n } else {\n pr('NO');\n }\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var firstLine = +readline();\nvar i = 0;\n\n\nwhile(i < firstLine) {\n\tvar firstArray = readline().split(' ').map(x=>{return +x});\n\tvar secondArray = readline().split(' ').map(x=>{return +x});\n\tvar k = firstArray[1];\n\n\tvar oddCount = 0;\n\tvar resArray = secondArray.map(x=>{ oddCount +=x%2; return x%2});\n\n\tif(\n\t\toddCount >= k && \n\t\t((oddCount%2 === 0 && k%2 === 0) || \n\t\t(oddCount%2 === 1 && k%2 === 1))\n\t) {\n\t\tprint(\"YES\");\n\t\tvar r = [];\n\n\t\tif(k == 1) {\n\t\t\tr.push(firstArray[0]);\n\t\t} else {\n\t\t\tresArray.some((x, p)=>{\n\t\t\t\tif(x != 0) {\n\t\t\t\t\tr.push(p+1);\n\t\t\t\t\tk--;\n\t\t\t\t\tif(k == 1) {\n\t\t\t\t\t\tr.push(firstArray[0]);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t});\n\t\t}\n\t\tprint(r.join(' '));\n\t} else {\n\t\tprint(\"NO\");\n\t}\n\ti++;\n}"}], "negative_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, k) {\n let start = 0;\n let end = 0;\n let result = [];\n let count = 0;\n\n while (end < data.length) {\n end++;\n count++;\n\n if (count === k) {\n end = data.length;\n }\n\n if (data.slice(start, end).reduce((a, b) => a + b) % 2) {\n console.log(start, end)\n result.push(end);\n start = end;\n }\n }\n return result;\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let k = lines[testCount * 2 - 1].split(\" \").map(Number)[1];\n console.log(foo(data, k));\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data) {\n let reserv = 0;\n let result = data.reduce((agr, value) => {\n let str = String(value);\n if (str[str.length - 1] % 2) {\n reserv++;\n value = value - 1;\n }\n return agr + value;\n }, 0);\n let resultArray = String(result / 2).split(\"\");\n let last = +resultArray[resultArray.length - 1] + Math.floor(reserv / 2);\n resultArray.splice(- 1, 1, last);\n\n return +resultArray.join(\"\");\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n //console.log(data)\n console.log(foo(data));\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, k) {\n let start = 0;\n let end = 0;\n let result = [];\n let count = 0;\n\n while (end < data.length) {\n end++;\n count++;\n\n if (count === k) {\n end = data.length;\n }\n\n if (data.slice(start, end).reduce((a, b) => a + b) % 2) {\n //console.log(start, end)\n result.push(end);\n start = end;\n }\n }\n return result;\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let k = lines[testCount * 2 - 1].split(\" \").map(Number)[1];\n let result = foo(data, k);\n if (result.length !== k) console.log(\"NO\");\n else {\n console.log(\"YES\");\n console.log(result.join(\" \"));\n }\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, k) {\n let start = 0;\n let end = 0;\n let result = [];\n let count = 0;\n\n while (end < data.length) {\n end++;\n count++;\n\n if (count === k) {\n end = data.length;\n }\n\n if (data.slice(start, end).reduce((a, b) => a + b) % 2) {\n //console.log(start, end)\n result.push(end);\n start = end;\n }\n }\n return result;\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let k = lines[testCount * 2 - 1].split(\" \").map(Number)[1];\n let result = foo(data, k);\n if (result.length !== k) console.log(\"NO\");\n else result.join(\" \");\n testCount++;\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n function foo (data, k) {\n let start = 0;\n let end = 0;\n let result = [];\n let count = 0;\n\n while (end < data.length) {\n end++;\n\n if (count === k) {\n end = data.length;\n }\n\n //console.log(start, end)\n if (data.slice(start, end).reduce((a, b) => a + b) % 2) {\n count++;\n result.push(end);\n start = end;\n }\n }\n return result;\n }\n\n let testCount = 1;\n\n while(testCount <= +lines[0]) {\n let data = lines[testCount * 2].split(\" \").map(Number);\n let k = lines[testCount * 2 - 1].split(\" \").map(Number)[1];\n //console.log(data, k)\n let result = foo(data, k);\n //console.log(result)\n if (result.length !== k) console.log(\"NO\");\n else {\n console.log(\"YES\");\n console.log(result.join(\" \"));\n }\n testCount++;\n }\n})"}, {"source_code": "var firstLine = +readline();\nvar i = 0;\n\nwhile(i < firstLine) {\n var firstArray = readline().split(' ').map(x=>{return +x});\n var secondArray = readline().split(' ').map(x=>{return +x});\n var n = firstArray[0];\n var k = firstArray[1];\n\n var oddCount = 0;\n var resArray = secondArray.map(x=>{ oddCount +=x%2; return x%2});\n\n if(\n oddCount >= k && \n (oddCount%2 === 0 && k%2 === 0) || \n (oddCount%2 === 1 && k%2 === 1)\n ) {\n print(\"YES\");\n var r = [];\n\n if(k == 1) {\n r.push(n);\n } else {\n resArray.some((x, p)=>{\n if(x != 0) {\n r.push(p+1);\n k--;\n if(k == 1) {\n r.push(n);\n return true;\n }\n }\n\n });\n }\n print(r.join(' '));\n } else {\n print(\"NO\");\n }\n i++;\n}"}, {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var k = readline().split(' ').map(item => +item)\n var arr = readline().split(' ').map(item => +item);\n var index = [];\n \n for(var j = 0; j < k[0]; j++) {\n if(arr[j] % 2 > 0) {\n index.push(j + 1);\n } \n }\n \n if(index.length < k[1] || index.length === k[1] + 1) {\n print('NO');\n } else {\n print('YES');\n \n var res = [ ];\n \n for(var c = 0; c < k[1] - 1; c++) {\n res.push(index[c]);\n }\n \n res.push(k[0]);\n \n print(res.join(' '));\n }\n}\n"}], "src_uid": "7f5269f3357827b9d8682d70befd3de1"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet max = 0;\nlet cur = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (str.includes('0')) {\n cur++;\n }\n else {\n max = Math.max(max, cur);\n cur = 0;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n max = Math.max(max, cur);\n console.log(max);\n});\n", "positive_code": [{"source_code": "var input = readline().split(\" \").map(Number);\nvar n = input[0], d = input[1];\n\nvar cnt = 0;\nvar max = 0;\nfor(var i = 0; i < d; i++){\n var enemies = readline().split(\"\");\n\n if(enemies.every(function(a){ return (+a)&1 })){\n cnt = 0;\n }else{\n cnt++;\n max = Math.max(max, cnt);\n }\n}\n\nwrite(max);"}, {"source_code": "'use strict';\n\n// var inpArr = `\n// 4 1\n// 0100\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nvar nd = readline().split(' ').map(Number),\n n = nd[0], d = nd[1], dArr = [];\n\nvar loseCase = '';\nfor (var i = 0; i < n; i++) {\n loseCase += '1';\n}\n\nfor (var i = 0; i < d; i++) {\n dArr.push(readline().trim());\n}\n\nprint(Math.max.apply(null, dArr.map(x => Number(x !== loseCase)).join('').split(0).map(x => x.length)))\n"}, {"source_code": "var n=readline().split(' ').map(Number);\nvar ss = ((xs)=>{for (var i=0;ixs.reduce((x,y)=>x+y)).reduce((x,y)=>{if (y!=n[0]) {x[0]=x[0]+1; x[1]=Math.max(x[0],x[1]);} else {x[0]=0;} return x},[0,0]);\nprint(m[1]);"}, {"source_code": "var nd = readline().split(' ').map(Number);\nvar consecutive_wins = 0;\nvar max_consecutive_wins = 0;\nvar prev_val = 0;\n\nfor(var i = 0; i < nd[1]; i++) {\n \n var current_val = readline().split('').map(Number).reduce(function(prevVal, currVal){ return prevVal && currVal });\n if(current_val === 0 && prev_val === 0) {\n consecutive_wins++;\n } else if(current_val === 0 && prev_val === 1){\n consecutive_wins = 1;\n } else {\n consecutive_wins = 0;\n }\n \n if(consecutive_wins > max_consecutive_wins)\n max_consecutive_wins = consecutive_wins;\n \n prev_val = current_val;\n}\n\nprint(max_consecutive_wins);"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar line = [], day, total = [], max = 0, current = 0;\nline = readline().split(' ').map(Number);\nfunction check (value) {\n if (value == 1) {\n current++;\n } else {\n if (current > max) {\n max = current;\n }\n current = 0;\n }\n}\n\nfor (i = 0; i < line[1]; i++) {\n total.push(0);\n}\n\nfor (i = 0; i < line[1]; i++) {\n \n day = readline().replace(/\\r$/, '').split('').map(Number);\n\n if (day.includes(0)) {\n total[i] = 1;\n }\n}\n\ntotal.push(0);\ntotal.forEach(check);\nprint(max);"}, {"source_code": "// na\u010dtu prvn\u00ed \u0159\u00e1dek\nvar counts = readline().split(\" \");\n\n// Seznam dn\u016f\nvar days = [];\n\n// Na\u010dtu dny\nfor (var i = 0; i < counts[1]; i++) {\n\tdays.push(readline());\n}\n\n\n// Proch\u00e1z\u00edm den po dni\nvar maximum = 0;\nvar actual = 0;\nfor (var den = 0; den < counts[1]; den++) {\n\tvar nula = false;\n\n\tfor (var bojovnik = 0; bojovnik outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar line = [], day, total = [], max = 0, current = 0;\nline = readline().split(' ').map(Number);\nfunction check (value) {\n if (value == 1) {\n current++;\n } else {\n if (current > max) {\n max = current;\n current = 0;\n }\n }\n}\n\nfor (i = 0; i < line[1]; i++) {\n total.push(0);\n}\n\nfor (i = 0; i < line[1]; i++) {\n \n day = readline().replace(/\\r$/, '').split('').map(Number);\n\n if (day.includes(0)) {\n total[i] = 1;\n }\n}\n\ntotal.push(0);\ntotal.forEach(check);\nprint(max);"}, {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\n//test for readline\n\nvar a, b, c;\n\na = readline();\nb = readline().split('').length;\nc = readline().split('');\n\nprint(a);\nprint(b);\nprint(c);\n"}, {"source_code": "// na\u010dtu prvn\u00ed \u0159\u00e1dek\nvar counts = readline().split(\" \");\n\n// Seznam bojovn\u00edk\u016f\nvar days = [];\n\n// Na\u010dtu dny\nfor (var i = 0; i < counts[1]; i++) {\n\tdays.push(readline());\n}\n\n\n// Proch\u00e1z\u00edm den po dni\nvar maximum = 0;\nvar actual = 0;\nfor (var den = 0; den < counts[1]; den++) {\n\tvar nula = false;\n\n\tfor (var bojovnik = 0; bojovnik0){\n ip = readline().split(' ').map(Number);\n a = ip[0];\n b = ip[1];\n if (a >= b){\n if (a%b == 0){\n print(0);\n } else\n print(b - (a%b));\n } else {\n print(b-a);\n }\n}\n"}, {"source_code": "var cases = readline();\n\n\nfor(var i=0;i < cases; i++)\n{\n input = readline().split(\" \").map(function(x){return parseInt(x);});\n\n a = input[0];\n b = input[1];\n\n var x =b - (a%b);\n if(x === b)\n {\n x = 0;\n }\n print(x)\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const inp = getInts()\n const a = inp[0]\n const b = inp[1]\n\n if (a < b) {\n print(b - a)\n } else {\n const k = parseInt(Math.ceil(a / b))\n print((k * b) - a)\n }\n }\n}"}, {"source_code": "var input = parseInt(readline());\nfor(var i =0; i< input; i++){\n var count = 0;\n var ab = readline().split(\" \").map(x=>parseInt(x));\n var a = ab[0];\n var b = ab[1];\n if(a%b===0);\n else if(a>b) count += b-a%b;\n else if(aNumber(x));\n var c = a[0]%a[1];\n print(c?(a[1]-c):0);\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var a = tmp[0];\n var b = tmp[1];\n if(a % b == 0){\n output[i] = 0;\n }else{\n output[i] = b - (a % b);\n }\n \n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "var n = Number(readline());\nvar input = [] ;\nvar a,b ;\nfor(var i =0 ;i {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\n// ====================================================================\n\nconst run = () => {\n const t = Number.parseInt(getNextLine());\n for (let i = 0; i < t; i++) {\n const [a, b] = getNextLine()\n .split(\" \")\n .map(s => Number.parseInt(s));\n solve(a, b);\n }\n};\n\nconst solve = (a, b) => {\n if (a % b === 0) {\n console.log(0);\n return;\n }\n const y = (Math.floor(a / b) + 1) * b - a;\n console.log(y);\n};\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if(c === 0) {\n c++;\n return;\n }\n\n let [a, b] = d.split(' ').map(Number);\n let ans = 0;\n\n if (a % b !== 0) {\n ans = b - a % b;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "var t = readline()\nwhile(t--){\n var x = readline().split(' ')\n\n a = parseInt(x[0])\n b = parseInt(x[1])\n \n if(a%b === 0) print('0 \\n')\n else{ \n print(b-a%b + '\\n')\n }\n}"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(\" \").map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1];\n var x = a % b;\n if (x == 0)\n print(0);\n else {\n print(b - x);\n }\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, x, a) {\n a.sort((a, b) => b - a);\n let sum = 0;\n for(let i = 0; i < n; ++i) {\n sum += a[i];\n if (sum < x * (i + 1)) return i;\n }\n return n;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [a, b] = readLine().split(' ').map((val) => parseInt(val));\n var m = a % b;\n console.log((m === 0) ? 0 : b - m);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n const t = parseInt(input[0]);\n\n for (let i = 1; i <= t; i += 1) {\n const [a, b] = splitAndParseInt(input[i]);\n if (a % b === 0) console.log(0);\n else {\n const d = Math.ceil(a / b);\n console.log(d * b - a);\n }\n }\n});\n"}, {"source_code": "// imports \n//end imports\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar currentLine = 0;\nprocess.stdin.on('data', function (input) { inputString += input; });\nprocess.stdin.on('end', function (_) { inputString = inputString.split('\\n'); main(); });\nvar readline = function () { return inputString[currentLine++]; };\nfunction main() {\n var tests = parseInt(readline());\n while (tests--) {\n var _a = readline().split(' ').map(function (x) { return parseInt(x); }), a = _a[0], b = _a[1];\n if (a < b)\n console.log(b - a);\n else if (a == b)\n console.log(0);\n else {\n var ans = void 0;\n a = a % b;\n if (a == 0)\n ans = 0;\n else\n ans = b - a;\n console.log(ans);\n }\n }\n}\n"}, {"source_code": "// imports \n//end imports\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar currentLine = 0;\nprocess.stdin.on('data', function (input) { inputString += input; });\nprocess.stdin.on('end', function (_) { inputString = inputString.split('\\n'); main(); });\nvar readline = function () { return inputString[currentLine++]; };\nfunction main() {\n var tests = parseInt(readline());\n var ansStr = '';\n while (tests--) {\n var _a = readline().split(' ').map(function (x) { return parseInt(x); }), a = _a[0], b = _a[1];\n if (a < b)\n ansStr += ((b - a).toString() + '\\n');\n else if (a == b)\n ansStr += ('0' + '\\n');\n else {\n var ans = void 0;\n a = a % b;\n if (a == 0)\n ans = 0;\n else\n ans = b - a;\n ansStr += (ans + '\\n');\n }\n }\n console.log(ansStr);\n}\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n const r = (a%b)\n console.log(r > 0 ? b - r : 0)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function solve(a, b) {\n const m = (a % b);\n return (m === 0) ? 0 : (b - m);\n}\n\nfunction main(lines) {\n const whitespace = /\\s+/;\n lines.shift();\n for (const line of lines) {\n const [a, b] = line.split(whitespace).map(Number);\n console.log(solve(a, b));\n }\n}\n\nfunction trim_line(s) {\n return s.trim();\n}\n\nfunction has_content(s) {\n return (s.length > 0);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const chunks = [];\n const encoding = 'utf-8';\n rs.setEncoding(encoding);\n for await (let chunk of rs) {\n chunks.push(chunk);\n }\n const empty = '';\n const newline = /\\n/;\n const lines = chunks.join(empty)\n .split(newline)\n .map(trim_line)\n .filter(has_content);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "function solve(a, b) {\n const m = (a % b);\n return (m === 0) ? 0 : (b - m);\n}\n\nfunction main(lines) {\n lines.shift();\n for (const line of lines) {\n let t = line.trim();\n if (line.length > 0) {\n const [a, b] = t.split(/\\s+/).map(Number);\n console.log(solve(a, b));\n }\n }\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "var tc = parseInt(readline());\n \nfor(var i = 0; i < tc; i++){\n var line = readline().split(' ');\n var a = parseInt(line[0]);\n var b = parseInt(line[1]);\n \n if(a%b === 0) print(0);\n else{\n print(b - a%b);\n }\n}"}, {"source_code": "var numberTests = +readline();\nfor (var test = 0; test+twoNumber[1]) {\n print( Math.ceil(twoNumber[0]/twoNumber[1]) * twoNumber[1] - twoNumber[0]);\n } else print(0);\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let testCases = inputs.slice(1);\n let moves = [];\n for (let index = 1; index <= +inputs[0]; index++) {\n\n let testCase = inputs[index].trim().split(' ').map(num => Number(num));\n move = 0;\n let modulo = testCase[0] % testCase[1];\n move = modulo == 0 ? modulo : testCase[1] - modulo;\n moves.push(move);\n\n }\n\n return moves.join('\\n').toString();\n}\n\n\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst divisibility = () => {\n input.shift();\n for (const x of input) {\n let [z,y] = x.split(' ').map(x => +x);\n if (z % y !== 0) {\n console.log(y - (z % y))\n }\n else {\n console.log(0);\n }\n }\n};\nreadLine.on('close', divisibility);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n for (var i = 0; i < n; i++) {\n let ab = readLine().split(' ').map(value => parseInt(value));\n let a = ab[0];\n let b = ab[1];\n if (a % b == 0) {\n console.log(0)\n } else console.log(b - (a % b));\n }\n}"}, {"source_code": "var s = '';\nvar n = 0;\n\nprocess.stdin.on('data', function (c) {\n s += c;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n main();\n});\n\nfunction readline() {\n return s[n++];\n}\n\nfunction main() {\n var T = parseInt(readline());\n for (var t = 0; t < T; ++t) {\n var ls = readline().split(' ');\n var a = parseInt(ls[0]), b = parseInt(ls[1]);\n var m = a % b;\n console.log((m === 0) ? 0 : b - m);\n }\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar first, current = 0;\n\nvar data = [];\n\nrl.on('line', function(line){\n if (first === undefined) {\n first = +line;\n } else {\n data.push(line.split(' '));\n current++;\n }\n\n if (first === current) rl.close();\n});\n\nrl.on('close', function() {\n data.forEach(pair => {\n const a = pair[0];\n const b = pair[1];\n\n const os = a % b;\n const diff = os ? b - a % b : 0;\n console.log(diff);\n });\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString\n .trim()\n .split(/\\W+/) // splits at spaces or new lines\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n var n = readline();\n\n for (let i = 0; i < n; i++) {\n var a = readline();\n var b = readline();\n console.log(findDivisibility2(a, b));\n }\n}\n\nfunction findDivisibility2(a, b) {\n if (a % b === 0) return 0;\n else {\n return b - (a % b);\n }\n}\n\n// function findDivisibility(a, b) {\n// let count = 0;\n// while (a % b !== 0) {\n// if (a % b === 0) {\n// return count;\n// } else {\n// a++;\n// count++;\n// }\n// }\n// return count;\n// }\n"}, {"source_code": "const readline = require('readline');\nconst r = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet tc\nlet input;\nr.on('line', (line) => {\n if (!tc) { tc = line; }\n else {\n \n let nums = line.split(\" \").map(n =>+n);\n console.log(f(nums[0],nums[1]));\n \n }\n});\n\n\n\nfunction f(a,b) {\n let r= a%b;\n if(r==0) return 0; \n else return (b-r);\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [a, b] = readInts()\n let r = a % b\n if(r === 0) wr(0)\n else wr(b - r)\n }\n}\n"}, {"source_code": "\"use strict\";\nexports.__esModule = true;\nvar str = \"\", lines = [], idxLine = 0;\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function (x) { str += x; });\nprocess.stdin.on('end', function () {\n lines = str.trim().split('\\n').map(function (x) { return x.trim(); });\n main();\n});\nfunction readline() {\n return lines[idxLine++];\n}\nvar print = console.log;\n//===============================\n//===============================\nfunction main() {\n var t = parseInt(readline());\n for (var _ = 0; _ < t; _++) {\n var _a = readline().split(\" \").map(function (e) { return parseInt(e); }), a = _a[0], b = _a[1];\n var x = a % b;\n if (x == 0)\n print(0);\n else {\n print(b - x);\n }\n }\n}\n"}, {"source_code": "let readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nfunction outResult(data) {\n data.forEach(num => console.log(num))\n}\n\nlet count = null\nlet data = []\n\nrl.on('line', function(line) {\n if (count === null) {\n count = Number(line.split(' ')[0]);\n return false\n }\n\n if (count > 0) {\n let arr = line.split(' ');\n let a = Number(arr[0]);\n let b = Number(arr[1]);\n let move = 0;\n move = (b - (a % b)) % b;\n data.push(move);\n count--;\n }\n\n if (count === 0) {\n outResult(data)\n }\n})"}], "negative_code": [{"source_code": "function findDivisibility(a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}\n\nfindDivisibility(10, 4);\nfindDivisibility(13, 9);\nfindDivisibility(100, 13);\nfindDivisibility(123, 456);\nfindDivisibility(92, 46);"}, {"source_code": "function findDivisibility(a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}"}, {"source_code": "function findDivisibility(n, a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}"}, {"source_code": "function findDivisibility(a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}\n\nconsole.log(findDivisibility(10, 4));"}, {"source_code": "function findDivisibility(a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}\n\nconsole.log(findDivisibility(13, 9));"}, {"source_code": "function findDivisibility(n, a, b) {\n for (let i = 0; i < n; i++) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n }\n}"}, {"source_code": "function findDivisibility(n, a, b) {\n for (let i = 0; i < n; i++) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n }\n \n}"}, {"source_code": "process.stdin.on('data', n => {\n for (let i = 0; i < n; i++) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n }\n});\n// function findDivisibility(a, b) {\n// let count = 0;\n// while (a % b !== 0) {\n// if (a % b === 0) {\n// return count;\n// } else {\n// a++;\n// count++;\n// }\n// }\n// return count;\n// }\n\n// console.log(findDivisibility(10, 2));\n"}, {"source_code": "process.stdin.on('data', (n, a, b) => {\n for (let i = 0; i < n; i++) {\n console.log(findDivisibility(a, b));\n }\n});\nfunction findDivisibility(a, b) {\n let count = 0;\n while (a % b !== 0) {\n if (a % b === 0) {\n return count;\n } else {\n a++;\n count++;\n }\n }\n return count;\n}"}, {"source_code": "// imports \n//end imports\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar currentLine = 0;\nprocess.stdin.on('data', function (input) { inputString += input; });\nprocess.stdin.on('end', function (_) { inputString = inputString.split('\\n'); main(); });\nvar readline = function () { return inputString[currentLine++]; };\nfunction main() {\n var tests = parseInt(readline());\n while (tests--) {\n var _a = readline().split(' ').map(function (x) { return parseInt(x); }), a = _a[0], b = _a[1];\n if (a < b)\n console.log(b - a);\n else if (a == b)\n console.log(0);\n else {\n a = a % b;\n console.log(b - a);\n }\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n console.log(b-a%b)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n a = ip[0];\n b = ip[1];\n if (a >= b){\n print(b%a);\n } else {\n print(b-a);\n }\n}\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n a = ip[0];\n b = ip[1];\n if (a >= b){\n print(a%b);\n } else {\n print(b-a);\n }\n}\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n a = ip[0];\n b = ip[1];\n if (a >= b){\n print(b - (a%b));\n } else {\n print(b-a);\n }\n}\n"}, {"source_code": "var cases = readline();\n\n\nfor(var i=0;i < cases; i++)\n{\n input = readline().split(\" \").map(function(x){return parseInt(x);});\n\n a = input[0];\n b = input[1];\n\n var x =b - (a%b);\n print(x)\n}"}, {"source_code": "var cases = readline();\n\nfunction input()\n{\n var input = readline().split(\" \").map(function(x){return parseInt(x);});\n}\n\nfor(var i=0;i < cases; i++)\n{\n var add = 0; \n input()\n \n a = input[0];\n b = input[1];\n if(a % b === 0)\n {\n print(add);\n }\n else\n {\n a++;\n add++;\n }\n}"}, {"source_code": "var cases = readline();\nvar input = readline().split(\" \").map(function(x){return parseInt(x);});\n\nfor(var i=0;i < cases; i++)\n{\n var add = 0; \n\n a = input[0];\n b = input[1];\n while(a % b !== 0)\n {\n a++;\n add++;\n }\n if(a % b === 0)\n {\n print(add);\n }\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const inp = getInts()\n const a = inp[0]\n const b = inp[1]\n let t = parseInt(a / b)\n while (t * b < a) {\n t ++\n }\n print((t * b) - a)\n }\n}"}, {"source_code": "var input = parseInt(readline());\nfor(var i =0; i< input.length; i++){\n var count = 0;\n var ab = readline().split(\"\");\n var a = ab[0];\n var b = ab[1];\n if(a%b) count++;\n else count +=b-a;\n print(count);\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var c = a[0]%a[1];\n print(c?(a[1]-c):0);\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n print((-a[0])%a[1]);\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var c = a[0]%a[1];\n print((c==0)?0:(a[1]-c));\n}"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var c = a[0]%a[1];\n print(c?0:(a[1]-c));\n}"}, {"source_code": "function main(a, b) {\n a = Math.abs(a);\n if(a === b) {\n return 0;\n }\n if (a < b) {\n return b - a;\n } else {\n return b - (a % b);\n }\n}\n\nvar n = readline();\nvar input = [];\nvar output = '';\n\nfor (var i = 1; i <= n; i++) {\n input = readline().split(' ');\n\n output += main(parseInt(input[0]), parseInt(input[1])) + '\\n';\n}\n\nprint(output);"}, {"source_code": "var t = readline()\nwhile(t--){\n a = readline()\n b = readline\n a = parseInt(a)\n b = parseInt(b)\n \n if(a%b === 0) print('0 \\n')\n else{ \n print(b-a%b + '\\n')\n }\n}"}, {"source_code": "var t = readline()\nwhile(t--){\n a = readline()\n b = readline()\n a = parseInt(a)\n b = parseInt(b)\n \n if(a%b === 0) print('0 \\n')\n else{ \n print(b-a%b + '\\n')\n }\n}"}, {"source_code": "var t = readline();\nwhile(t--){\n a = readline();\n b = readline\n if(a%b === 0) print('0
')\n else{ \n print(b-a%b + '
')\n }\n}"}, {"source_code": "\nvar cnt = readline()\nwhile(cnt--){\n var x = readline().split(' ')\n \n a = parseInt(x[0])\n b = parseInt(x[1])\n if(a>b)b=a\n print(b-(a%b))\n}\n"}, {"source_code": "\nvar cnt = readline()\nwhile(cnt--){\n var x = readline().split(' ')\n \n a = parseInt(x[0])\n b = parseInt(x[1])\n if(a>b){\n a = a ^ b\n b = a ^ b\n a = a ^ b\n }\n print(b-(a%b))\n}\n"}, {"source_code": "var cnt = readline()\nwhile(cnt--){\n var x = readline().split(' ')\n \n a = parseInt(x[0])\n b = parseInt(x[1])\n \n print(b-(a%b))\n}\n"}, {"source_code": "var tc = parseInt(readline());\n\nfor(var i = 0; i < tc; i++){\n var line = readline().split(' ');\n var a = parseInt(line[0]);\n var b = parseInt(line[1]);\n \n if(a%b === 0) print(0);\n else{\n print(a - (a%b) - Math.floor(a/b) * b);\n }\n}"}, {"source_code": "var tc = parseInt(readline());\n\nfor(var i = 0; i < tc; i++){\n var line = readline().split(' ');\n var a = parseInt(line[0]);\n var b = parseInt(line[1]);\n \n if(a%b === 0) print(0);\n else{\n print(a%b);\n }\n}"}, {"source_code": "var tc = parseInt(readline());\n\nfor(var i = 0; i < tc; i++){\n var line = readline().split(' ');\n var a = parseInt(line[0]);\n var b = parseInt(line[1]);\n \n if(a%b === 0) print(0);\n else{\n print(a - (a%b) - Math.floor(a%b) * b);\n }\n}"}, {"source_code": "var numberTests = +readline();\nfor (var test = 0; testtwoNumber[1]) {\n print( Math.ceil(twoNumber[0]/twoNumber[1]) * twoNumber[1] - twoNumber[0]);\n } else print(0);\n}\n"}], "src_uid": "d9fd10700cb122b148202a664e7f7689"} {"source_code": "\"use strict\";\n\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(n); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nfunction main() {\n var t = readline();\n\n var _loop = function _loop() {\n var _readline$split$map = readline().split(\" \").map(function (num) {\n return parseInt(num);\n }),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\n var arr = new Array(n).fill(null);\n arr = arr.map(function (elem) {\n return new Array(m).fill('B');\n });\n arr[0][0] = 'W';\n\n for (var i = 0; i < n; i++) {\n print(arr[i].join(''));\n }\n };\n\n while (t--) {\n _loop();\n }\n}\n\nmain();", "positive_code": [{"source_code": "const ascending = (x, y) => x - y;\nconst descending = (x, y) => y - x;\nconst log = console.log;\n\nconst row0 = 'WBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB';\nconst row = 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB';\n\nfunction solve(input) {\n input = input.toString().split(/\\r?\\n/);\n\n let T = +input[0];\n let res = [];\n\n for (let t = 1, inputRow = 1; t <= T; t++) {\n \n\n let nm = input[inputRow++].split(' ');\n let n = +nm[0];\n let m = +nm[1];\n\n res.push(row0.substr(0, m));\n \n for (let i = 1; i < n; i++) {\n res.push(row.substr(0, m));\n }\n\n }\n\n return res.join('\\n');\n}\n\nasync function main() {\n\n try {\n\n let input = await new Promise(resolve => {\n\n let _input = '';\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n process.stdin.on('data', (buf) => {\n _input += buf;\n });\n process.stdin.on('end', () => {\n resolve(_input);\n });\n\n });\n let output = solve(input);\n\n console.log(output);\n\n } catch (err) {\n console.error(err);\n }\n}\n\nmain();\n"}, {"source_code": "let input = require('fs').readFileSync(0, 'utf8').trim().split('\\n');\nconst read = () => input.shift();\nconst readInt = () => parseInt(read());\nconst readInts = () => read().split(' ').map(n => parseInt(n));\nconst print = console.log;\n\nconst solution = () => {\n const c = readInt();\n for (let ci = 1; ci <= c; ci++) {\n const [y, x] = readInts();\n\n let odds = [y, x].filter(x => x % 2 === 1).length\n let fills = odds === 2 ? 2 : 1;\n\n let blackMod = y % 2;\n for (let i = 0; i < y; i++) {\n let str = '';\n for (let j = 0; j < x; j++) {\n if (j % 2 === blackMod) {\n str += 'B'\n } else if (fills !== 0) {\n str += 'B'\n fills--;\n } else {\n str += 'W'\n }\n }\n if (blackMod === 1) { blackMod = 0 }\n else if (blackMod === 0) { blackMod = 1 }\n print(str);\n }\n }\n};\n\nsolution();\n"}, {"source_code": "// Q: https://codeforces.com/contest/1333/problem/A\n\nconst readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t=0; t < test; t++) {\n let n, m;\n [n, m] = input[t+1].split(' ').map((a) => parseInt(a));\n let output = Array(n).fill(null).map(() => Array(m).fill('B'));\n output[0][0] = 'W';\n for (let i = 0; i < n; i++) {\n console.log(output[i].join(''));\n }\n\t}\n});"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nconst MOD1 = 1000000007\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while (t--) {\n const [n, m] = readInts()\n let ans = new Array(n)\n for (let i = 0; i < n; i++) {\n ans[i] = new Array(m).fill('B')\n }\n ans[n - 1][m - 1] = 'W'\n for (let i = 0; i < n; i++) {\n wr(ans[i].join(''))\n }\n }\n}\n\n"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(nums) {\n\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const [n, m] = readLine();\n let secondLine = new Array(m).fill('B').join('');\n let firstLine = 'W'.concat(secondLine.slice(1));\n const result = new Array(n).fill().map((val, i) => i === 0 ? firstLine : secondLine).join('\\n');\n console.log(result);\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const n = +lines[0];\n for (let i = 0; i < n; i++) {\n const [n, m] = lines[i + 1].split(\" \").map((x) => +x);\n for (let t = 0; t < n; t++) {\n const str = Array(m).fill(\"B\");\n if (t === 0) {\n str[0] = \"W\";\n }\n console.log(str.join(\"\"));\n }\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let j = 0; j < n; j++) {\n const line = Array(m).fill(\"B\");\n if(j === 0) {\n line[0] = \"W\";\n }\n console.log(line.join(\"\"));\n }\n }\n}\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n n = +ip[0];\n m = +ip[1];\n out = 'W';\n for (i=1;i 0) {\n ip = readline().split(' ').map(Number);\n n = +ip[0];\n m = +ip[1];\n out = 'W';\n for (i = 1; i < m; i++) {\n out += 'B';\n }\n blacks = '';\n for (i = 0; i < m; i++) {\n blacks += 'B';\n }\n for (i = 1; i < n; i++) {\n out += '\\n' + blacks;\n }\n print(out);\n}"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n let line;\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let j = 0; j < n; j++) {\n if(j === 0) {\n line = \"W\" + \"B\".repeat(m-1);\n } else {\n line = \"B\".repeat(m);\n }\n console.log(line);\n }\n }\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var m = one[1];\n var mass = n * m;\n var output = new Array(n);\n for(var j = 0; j < n; j++){\n output[j] = new Array(m);\n }\n \n for(var j = 0; j < n; j++){\n for(var k = 0; k < m; k++){\n /*if(j % 2 == mass % 2){\n if(k % 2 == 0){\n \n }else{\n output[j][k] = \"W\";\n }\n }else{\n if(k % 2 == 1){\n output[j][k] = \"B\";\n }else{\n output[j][k] = \"W\";\n }\n }*/\n output[j][k] = \"B\";\n }\n }\n output[0][0] = \"W\";\n /*if(mass % 2 == 0){\n output[n - 1][m - 1] = output[n - 2][m - 1];\n }*/\n for(var j = 0; j < n; j++){\n myout(myconv(output[j],0));\n }\n }\n}\n"}, {"source_code": "function main(n, m) {\n var output = '';\n for (i = 0; i < n; i++) {\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n output += 'W';\n } else {\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar outputB = '';\n\nfor (var z = 1; z <= +n; z++) {\n input = readline().split(' ');\n\n outputB += main(+input[0], +input[1]);\n}\n\nprint(outputB);"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let j = 0; j < n; j++) {\n let line = \"\";\n for(let k = 0; k < m; k++) {\n if(j == 0 && k == 0) {\n line += \"W\";\n } else {\n line += \"B\";\n }\n }\n console.log(line);\n }\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n for (let t=0; t i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\n\twhile (t--) {\n\t\tlet [n, m] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet grid = Array(n).fill('B'.repeat(m));\n\t\tlet white = grid[0].split('');\n\t\twhite.splice(0, 1, 'W');\n\t\tgrid[0] = white.join('');\n\t\tconsole.log(grid.join('\\n'));\n\t}\n}\n"}], "negative_code": [{"source_code": "function main(n, m) {\n var output = '';\n for (i = 0; i < n; i++) {\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n output += 'W';\n } else {\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar outputB = '';\n\nfor (var i = 1; i <= +n; i++) {\n input = readline().split(' ');\n\n outputB += main(+input[0], +input[1]);\n}\n\nprint(outputB);"}, {"source_code": "function main(n, m) {\n var output = '';\n for (i = 0; i < n; i++) {\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n output += 'W';\n } else {\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar output = '';\n\nfor (var i = 1; i <= +n; i++) {\n input = readline().split(' ');\n\n output += main(+input[0], +input[1]);\n}\n\nprint(output);"}, {"source_code": "function main(n, m) {\n var rows = [];\n var output = '';\n for (i = 0; i < n; i++) {\n rows[i] = [];\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n output += 'W';\n } else {\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar output = '';\n\nfor (var i = 1; i <= n; i++) {\n input = readline().split(' ');\n\n output += main(+input[0], +input[1]);\n}\n\nprint(output);"}, {"source_code": "function main(n, m) {\n var rows = [];\n var output = '';\n for (i = 0; i < n; i++) {\n rows[i] = [];\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n rows[i].push(1);\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n rows[i].push(1);\n output += 'W';\n } else {\n rows[i].push(0);\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar output = '';\n\nfor (var i = 1; i <= n; i++) {\n input = readline().split(' ');\n\n output += main(+input[0], +input[1]);\n}\n\nprint(output);"}, {"source_code": "function main(n, m) {\n var rows = [];\n var output = '';\n for (i = 0; i < n; i++) {\n rows[i] = [];\n for (k = 0; k < m; k++) {\n if(i === 0 && k < (m-1)) {\n output += 'W';\n } else if (i === 1 && n > 2 && k === (m-1)){\n output += 'W';\n } else {\n output += 'B';\n }\n }\n output += '\\n';\n }\n return output;\n}\n\nvar n = readline();\nvar input = [];\nvar output = '';\n\nfor (var i = 0; i <= n; i++) {\n input = readline().split(' ');\n\n output += main(+input[0], +input[1]);\n}\n\nprint(output);"}, {"source_code": "function main() {\n var t = readline();\n\twhile(t--){\n\t\tvar arr = readline().split(\" \").map(num => parseInt(num));\n\t var n = arr[0];\n\t var m = arr[1];\n\t print(n, m);\n\t\tvar arr = new Array(n).fill(null);\n\t\tarr = arr.map(elem => new Array(m).fill(null));\n\t\tif(n < 3){\n\t\t\tarr[0] = arr[0].map(num => 'B');\n\t\t\tarr[1] = arr[1].map(num => 'W');\n\t\t\tarr[1][1] = 'B';\n\t\t}else if(m < 3){\n\t\t\tfor(var i = 0; i < n; i++){\n\t\t\t\tarr[i][0] = 'B';\n\t\t\t\tarr[i][1] = 'W';\n\t\t\t}\n\t\t\tarr[1][1] = 'B';\n\t\t}else{\n\t\t\tfor(var i = 0; i < n; i++){\n\t\t\t\tfor(var j = 0; j < m; j++){\n\t\t\t\t\tarr[i][j] = 'B';\n\t\t\t\t}\n\t\t\t}\n\t\t\tarr[0][0] = 'W';\n\t\t\tarr[0][1] = 'W';\n\t\t\tarr[1][0] = 'W';\n\t\t\tarr[1][1] = 'W';\n\t\t}\n\t\tfor(var i = 0; i < n; i++) print(arr[i].join(''));\n\t}\n}\nmain();"}, {"source_code": "let input = require('fs').readFileSync(0, 'utf8').trim().split('\\n');\nconst read = () => input.shift();\nconst readInt = () => parseInt(read());\nconst readInts = () => read().split(' ').map(n => parseInt(n));\nconst print = console.log;\n\nconst solution = () => {\n const c = readInt();\n for (let ci = 1; ci <= c; ci++) {\n const [y, x] = readInts();\n\n for (let i = 0; i < y; i++) {\n let str = '';\n for (let j = 0; j < x; j++) {\n if (i === 0 && j === 1) {\n str += 'B';\n } else {\n str += i % 2 === 0\n ? j % 2 === 0 ? 'B' : 'W'\n : j % 2 === 1 ? 'B' : 'W';\n }\n }\n print(str);\n }\n }\n};\n\nsolution();\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let j = 0; j < n; j++) {\n for(let k = 0; k < m; k++) {\n if(j == 0 && k == 0) {\n rl.write(\"W\");\n } else {\n rl.write(\"B\");\n }\n }\n rl.write(\"\\n\");\n }\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map((x) => +x);\n for (let i = 0; i < n; i++) {\n for(let j = 0; j < m; j++) {\n if(i === 0 && j === 0) {\n rl.write(\"W\");\n } else {\n rl.write(\"B\");\n }\n }\n rl.write(\"\\n\");\n }\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map((x) => +x);\n for (let i = 0; i < n; i++) {\n for(let j = 0; j < m; j++) {\n if(i == 0 && j == 0) {\n rl.write(\"W\");\n } else {\n rl.write(\"B\");\n }\n }\n rl.write(\"\\n\");\n }\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let i = 0; i < n; i++) {\n for(let j = 0; j < m; j++) {\n if(i === 0 && j === 0) {\n rl.write(\"W\");\n } else {\n rl.write(\"B\");\n }\n }\n rl.write(\"\\n\");\n }\n }\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n processData(arr);\n process.exit(0);\n});\n\nfunction processData(lines) {\n const t = +lines[0];\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[i + 1].split(\" \").map(x => +x);\n for (let i = 0; i < n; i++) {\n for(let j = 0; j < m; j++) {\n if(i == 0 && j == 0) {\n rl.write(\"W\");\n } else {\n rl.write(\"B\");\n }\n }\n rl.write(\"\\n\");\n }\n }\n}\n"}], "src_uid": "2b37f27a98ec8f80d0bff3f7ae8f2cff"} {"source_code": "function solve(n) {\n var a = 0;\n var b = n;\n\n var min = 1;\n var max = 2;\n var average = 0;\n\n if (n === 0) {\n print('Y 0 0');\n return;\n }\n\n while (max - min > 10e-13) {\n average = (min + max) / 2;\n a = n - average;\n b = average;\n\n if (a * b > n) {\n max = average;\n } else {\n min = average;\n }\n }\n\n if (Math.abs(a + b - a * b) < 10e-6 && Math.abs(a + b - n) < 10e-6) {\n print('Y ' + a + ' ' + b);\n } else {\n print('N');\n }\n}\n\nvar lines = +readline();\nfor(var i = 0; i 1) {\n val1[1] = val1[1].substr(0, 9);\n }\n val1 = +(val1.join('.'));\n \n\t\t\tvar val2 = num - val1;\n\n\t\t\tdiff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n val2 = Math.floor(val2 * 1000000000) / 1000000000;\n\t\t\t\tprint('Y ' + val2 + ' ' + val1);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\ndoIt();"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n\tinputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n\tinputString=inputString.trim().split(\"\\n\").map(string=>{\n\t\treturn string.trim();\n\t});\n\tmain();\n});\nfunction readLine()\n{\n\treturn inputString[currentLine++]; \n}\nfunction main()\n{\n\tconst t=parseInt(readLine());\n\tfor(let k=0;k{return +(x);});\n\t\tlet lc=0,lo=0,hi=n/2,mid;\n\t\twhile(lc<1000)\n\t\t{\n\t\t\tmid=(lo+hi)/2;\n\t\t\tif(((n-mid)*mid)>n)\n\t\t\t\thi=mid;\n\t\t\telse\n\t\t\t\tlo=mid;\n\t\t\tlc++;\n\t\t}\n\t\tif(Math.abs(mid*(n-mid)-n)<=0.000001)\n\t\t\tconsole.log('Y '+(n-mid)+' '+mid);\n\t\telse\n\t\t\tconsole.log('N');\n\t}\n\treturn 0;\n}"}, {"source_code": "var num = parseInt(readline());\nfor (var i = 0; i < num; i++) {\n\tvar curNum = parseInt(readline());\n\tvar d = curNum * curNum - 4 * curNum;\n\tif ( d < 0 ) {\n\t\tprint('N');\n } else if ( d === 0 ) {\n\t\tprint('Y ' + curNum / 2 + ' ' + curNum / 2);\n } else {\n\t\td = Math.sqrt(d);\n\t\tprint('Y ' + (curNum+d)/2 + ' ' + (curNum-d)/2);\n }\n}"}], "negative_code": [{"source_code": "function solve(n) {\n var a = 0;\n var b = n;\n\n var min = 1;\n var max = 2;\n var average = 0;\n\n if (n === 0) {\n print('Y 0 0');\n return;\n }\n\n while (max - min > 10e-9) {\n average = (min + max) / 2;\n a = n - average;\n b = average;\n\n if (a * b > n) {\n max = average;\n } else {\n min = average;\n }\n }\n\n if (Math.abs(a + b - a * b) < 10e-6 && Math.abs(a + b - n) < 10e-6) {\n print('Y ' + a + ' ' + b);\n } else {\n print('N');\n }\n}\n\nvar lines = +readline();\nfor(var i = 0; i 10e-9) {\n average = (min + max) / 2;\n a = n - average;\n b = average;\n\n if (a * b > n) {\n max = average;\n } else {\n min = average;\n }\n }\n\n if (Math.abs(a + b - a * b) < 10e-6 && Math.abs(a + b - n) < 10e-6) {\n write('Y ' + a + ' ' + b);\n } else {\n write('N');\n }\n}\n\nvar lines = +readline();\nfor(var i = 0; i 1) {\n val1[1] = val1[1].substr(0, 9);\n }\n val1 = +(val1.join('.'));\n \n\t\t\tvar val2 = num - val1;\n\n\t\t\tdiff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n val2 = Math.floor(val2 * 1000000000) / 1000000000;\n\t\t\t\tprint('Y ' + val2 + ' ' + val1);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\ndoIt();"}, {"source_code": "var cnt = +readline();\n\tvar res = [];\n\tvar minDiff = Math.pow(10, -6);\n\tvar step = Math.pow(10, -9);\n\n\tfor(var i = 0; i < cnt; i++) {\n\t\tvar num = +readline();\n\t\tvar diff = Math.pow(num / 2, 2) - num;\n\t\tif(diff < 0) {\n\t\t\tprint('N');\n\t\t\tcontinue;\n\t\t} \n\n\t\tvar start = 1;\n\t\tvar finish = 2;\n\n\t\twhile(start < finish) {\n\t\t\tvar val1 = (start + finish) / 2;\n\t\t\tvar val2 = num - val1;\n\n\t\t\tvar diff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n\t\t\t\tprint('Y ' + val1 + ' ' + val2);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}"}, {"source_code": "function doIt() {\n\n\tvar cnt = +readline();\n\tvar res = [];\n\tvar minDiff = Math.pow(10, -7);\n\tvar step = Math.pow(10, -9);\n\n\tfor(var i = 0; i < cnt; i++) {\n\t\tvar num = +readline();\n\t\tvar diff = Math.pow(num / 2, 2) - num;\n\t\tif(diff < 0) {\n\t\t\tprint('N');\n\t\t\tcontinue;\n\t\t} \n\n\t\tvar start = 1;\n\t\tvar finish = 2;\n\n\t\twhile(start < finish) {\n\t\t\tvar val1 = ('' + ((start + finish) / 2)).split('.');\n if(val1.length > 1) {\n val1[1] = val1[1].substr(0, 9);\n }\n val1 = +(val1.join('.'));\n \n\t\t\tvar val2 = num - val1;\n\n\t\t\tdiff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n val2 = Math.floor(val2 * 1000000000) / 1000000000;\n\t\t\t\tprint('Y ' + val2 + ' ' + val1);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\ndoIt();"}, {"source_code": "function doIt() {\n\n\tvar cnt = +readline();\n\tvar res = [];\n\tvar minDiff = Math.pow(10, -7);\n\tvar step = Math.pow(10, -9);\n\n\tfor(var i = 0; i < cnt; i++) {\n\t\tvar num = +readline();\n\t\tvar half = num / 2;\n\t\tvar diff = Math.pow(half, 2) - num;\n\t\tif(diff === 0) {\n\t\t print('Y ' + half + ' ' + half); \n\t\t continue;\n\t\t}else if(diff < 0) {\n\t\t\tprint('N');\n\t\t\tcontinue;\n\t\t} \n\n\t\tvar start = 1;\n\t\tvar finish = 2;\n\n\t\twhile(start < finish) {\n\t\t\tvar val1 = ('' + ((start + finish) / 2)).split('.');\n if(val1.length > 1) {\n val1[1] = val1[1].substr(0, 9);\n }\n val1 = +(val1.join('.'));\n \n\t\t\tvar val2 = num - val1;\n\n\t\t\tdiff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n val2 = Math.floor(val2 * 1000000000) / 1000000000;\n\t\t\t\tprint('Y ' + val2 + ' ' + val1);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\ndoIt();"}, {"source_code": "function doIt() {\n\n\tvar cnt = +readline();\n\tvar res = [];\n\tvar minDiff = Math.pow(10, -6);\n\tvar step = Math.pow(10, -9);\n\n\tfor(var i = 0; i < cnt; i++) {\n\t\tvar num = +readline();\n\t\tvar diff = Math.pow(num / 2, 2) - num;\n\t\tif(diff < 0) {\n\t\t\tprint('N');\n\t\t\tcontinue;\n\t\t} \n\n\t\tvar start = 1;\n\t\tvar finish = 2;\n\n\t\twhile(start < finish) {\n\t\t\tvar val1 = ('' + ((start + finish) / 2)).split('.');\n if(val1.length > 1) {\n val1[1] = val1[1].substr(0, 9);\n }\n val1 = +(val1.join('.'));\n \n\t\t\tvar val2 = num - val1;\n\n\t\t\tdiff = val1 * val2 - num;\n\t\t\tif(Math.abs(diff) <= minDiff) {\n\t\t\t\tprint('Y ' + val1 + ' ' + val2);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(diff < 0) {\n\t\t\t\tstart = val1 + step;\n\t\t\t} else {\n\t\t\t\tfinish = val1 - step;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\ndoIt();"}], "src_uid": "6f5d41346419901c830233b3bf5c9e65"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = read(),\r\n b = read();\r\n const tr = new SegTree(n);\r\n const res = [];\r\n for (let i = 0, j = 0; i < n; i = ++j) {\r\n if (a[i] === '1') continue;\r\n while (a[j + 1] === '0') j++;\r\n res.push([i, j]);\r\n if (i) tr.update(0, i - 1, 1);\r\n if (j < n - 1) tr.update(j + 1, n - 1, 1);\r\n }\r\n let one = 0,\r\n zero = 0;\r\n for (let i = 0; i < n; i++) {\r\n const x = tr.query(i, i);\r\n if (x & 1) {\r\n if (b[i] === '0') one++;else zero++;\r\n } else {\r\n if (b[i] === '0') zero++;else one++;\r\n }\r\n if (zero && one) return 'No';\r\n }\r\n if (zero) res.push([0, n - 1]);else res.push([0, 0], [1, n - 1]);\r\n return `Yes\\n${res.length}\\n${res.map(([l, r]) => `${l + 1} ${r + 1}`).join('\\n')}`;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n const mid = Math.floor((l + r) / 2);\r\n left.add += node.add;\r\n left.val += node.add * (mid - l + 1);\r\n right.add += node.add;\r\n right.val += node.add * (r - mid);\r\n node.add = 0;\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = left.val + right.val;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.add += z;\r\n node.val += z * (r - l + 1);\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = this._query(node.left, l, mid, x, mid) + this._query(node.right, mid + 1, r, mid + 1, y);\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = read();\r\n var b = read();\r\n var aOneIndexes = [];\r\n var equalsCount = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (a[i] === b[i]) {\r\n equalsCount++;\r\n }\r\n if (a[i] === '1') {\r\n aOneIndexes.push(i);\r\n }\r\n }\r\n if (equalsCount !== 0 && equalsCount !== n) {\r\n write('NO');\r\n return;\r\n }\r\n write('YES');\r\n var operationsOdd = ((aOneIndexes.length) & 1);\r\n var equalityOdd = equalsCount === n ? 0 : 1;\r\n var needAddOperations = !!(operationsOdd ^ equalityOdd);\r\n write(aOneIndexes.length + (needAddOperations ? 3 : 0));\r\n for (i = 0; i < aOneIndexes.length; i++) {\r\n var index = aOneIndexes[i] + 1;\r\n write(index + ' ' + index);\r\n }\r\n if (needAddOperations) {\r\n write('1 ' + n);\r\n write('1 1');\r\n write('2 ' + n);\r\n }\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}], "negative_code": [], "src_uid": "cc9abcff3224118b533881335e4c582b"} {"source_code": "var num = parseInt(readline());\n\nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n\n var aRib = rectangleRibs[0];\n var bRib = rectangleRibs[1];\n\n var rib = Math.min(Math.max(aRib * 2, bRib), Math.max(aRib, bRib * 2));\n print(rib * rib);\n}", "positive_code": [{"source_code": "const input = require('readline').createInterface({\n\tinput: process.stdin,\n\touput: process.stdout,\n\tterminal: false\n});\n\ninput.question('line', data => {\n\tlet n = Number(data);\n\tinput.on('line', (data)=> {\n\t\tlet line = data.split(' ');\n\t\tlet a = Number(line[0]);\n\t\tlet b = Number(line[1]);\n\t\tlet L = Math.max(a, b);\n\t\tlet l = Math.min(a, b);\n\t\tl *= 2;\n\t\tL = Math.max(L, l);\n\t\tconsole.log(L**2);\n\t});\n});\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar a = one[0];\n\t\tvar b = one[1];\n\t\tvar min = Math.min(a,b);\n\t\tvar max = Math.max(a,b);\n\t\tif(min * 2 > max){\n\t\t\toutput[i] = Math.pow(min * 2, 2);\n\t\t}else{\n\t\t\toutput[i] = Math.pow(max, 2);\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t; x++) {\n const [n1, n2] = input[x].split(\" \").map((num) => Number(num));\n\n //\uc791\uc740 \ucabd\uc744 a\ub77c \ud574\uc57c \ud55c\ub2e4.\n const a = n1 > n2 ? n2 : n1;\n const b = n1 > n2 ? n1 : n2;\n\n //1. \uc801\ub2f9\ud55c \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n if (2 * a >= b) {\n console.log(2 * a * 2 * a);\n }\n //2. \ud55c \ucabd\uc774 \ub9e4\uc6b0 \uae34 \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n else {\n console.log(b * b);\n }\n }\n}\n\n/*\n Q. \ucd5c\uc18c \uc815\uc0ac\uac01\ud615\uc758 \ub113\uc774 \uad6c\ud558\ub77c. 2\uac1c\uc758 \ub611\uac19\uc740 a*b\uc758 \uc9c1\uc0ac\uac01\ud615\uc744 \ub193\uc744 \uc218 \uc788\ub294\n\n 1. \uc8fc\uc5b4\uc9c4 \uc0ac\uac01\ud615\ub4e4\uc744 \ubaa8\ub450 \ud3ec\ud568\ud558\ub294 \ucd5c\uc18c \uacf5\uac04\uc758 \ud06c\uae30\ub97c \uad6c\ud558\ub77c\n 2. \ud68c\uc804 \uac00\ub2a5 (\ub2e8, \ubcc0\uc774 \ud56d\uc0c1 \uc218\ud3c9)\n 3. \uc774\ub3d9 \uac00\ub2a5\n 4. \uacb9\uce58\uae30 \ubd88\uac00\ub2a5\n*/\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n // const v1 = Math.min(a, b) * 2;\n // const v2 = Math.max(a, b);\n\n // const ans = v1 >= a && v1 >= b ? v1 ** 2 : v2 ** 2;\n\n const ans = Math.min(Math.max(a*2, b), Math.max(a, b*2))**2;\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b] = d.split(' ').map(Number);\n const v1 = Math.min(a, b) * 2;\n const v2 = Math.max(a, b);\n\n const ans = v1 >= a && v1 >= b ? v1 ** 2 : v2 ** 2;\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n let l = Math.min(a, b) * 2\n if (l < Math.max(a, b)) {\n l = Math.max(a, b)\n }\n console.log(l * l)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var num = parseInt(readLine());\n\n for (var i = 0; i < num; i++) {\n var rectangleRibs = readLine().split(\" \");\n\n var minRib = parseInt(rectangleRibs[0]);\n var maxRib = parseInt(rectangleRibs[1]);\n if (maxRib < minRib) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n\n var side = minRib * 2;\n if (side >= maxRib)\n console.log(side * side);\n else\n console.log(maxRib * maxRib);\n }\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n //process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let t = +inputs[0].trim();\n\n for (let index = 1; index <= t; index++) {\n const element = strToNumArr(inputs[index].trim().split(' '));\n\n let side = Math.min(Math.max(2 * element[0], element[1]), Math.max(2 * element[1], element[0]));\n console.log(side * side);\n }\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n let [a, b] = readline().split(\" \").map(e => parseInt(e));\n const {pow, max, min} = Math;\n\n const c = pow(min(a,b) * 2, 2);\n const s = pow(max(a,b), 2);\n console.log(Math.max(c, s));\n //break;\n //console.log(Math.pow(Math.max(a,b) + Math.max(a,b) , 2))\n }\n\n\n}\n"}, {"source_code": "var testCase = parseInt(readline());\n\nfor(var tc = 0; tc < testCase; tc++){\n var input = readline().split(\" \").map((val) => parseInt(val));\n var a1 = input[0];\n var b1 = input[1];\n var minSize = Math.min(a1, b1);\n var maxSize = Math.max(a1, b1);\n\n var size = (maxSize > 2*minSize ? maxSize : 2*minSize);\n print(size * size);\n}"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var ab = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var a = ab[0];\n var b = ab[1];\n if (a == b) {\n print(a * 2 * (a * 2));\n } else {\n var min = Math.min(a, b);\n var max = Math.max(a, b);\n if (min * 2 >= max) print(Math.pow(min * 2, 2));\n else print(Math.pow(max, 2));\n }\n}\n"}, {"source_code": "var n = parseInt(readline());\nwhile(n--)\n{\n var i = readline().split(\" \").map(x => parseInt(x));\n var max = Math.max(i[0], i[1]);\n var min = Math.min(i[0], i[1]);\n var ans = Math.max(2*min, max);\n print(ans*ans);\n}"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var ab = readNumArray();\n var a = ab[0];\n var b = ab[1];\n var abMin = a < b ? a : b;\n var abMax = a > b ? a : b;\n var maxxx = abMin * 2 > abMax ? abMin * 2 : abMax;\n\n print(maxxx * maxxx);\n }\n}\n\nmain();"}, {"source_code": "function solve() {\n var data = readIntArray();\n var a = data[0]\n var b = data[1]\n\n var min = Math.min(a,b)\n var max = Math.max(a,b)\n\n var min2 = min * 2\n print(min*2 < max ? max * max : min2 * min2)\n}\n\nvar testCases = readInt();\nvar testCaseNum;\nfor(testCaseNum=0; testCaseNum 2 * min)\n {\n result = max * max;\n }\n else \n {\n result = (2 * min) * (2 * min)\n }\n\n print(result);\n}"}, {"source_code": "var numOfInput = parseInt(readline());\nwhile(numOfInput--)\n{\n var input = readline().split(\" \").map(x => parseInt(x));\n var max = Math.max(input[0], input[1]);\n var min = Math.min(input[0], input[1]);\n print((2 * min) > max ? (4 * min * min) : (max * max)); \n}"}, {"source_code": "var num = parseInt(readline());\n\nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline()\n .split(\" \")\n .map(number => parseInt(number));\n\n var side = Math.min(...rectangleRibs) * 2;\n var maxRib = Math.max(...rectangleRibs);\n\n if (side >= maxRib)\n print(side * side);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "var num = parseInt(readline());\n\nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n\n var minRib = parseInt(rectangleRibs[0]);\n var maxRib = parseInt(rectangleRibs[1]);\n if (maxRib < minRib) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n\n var side = minRib * 2;\n if (side >= maxRib)\n print(side * side);\n else\n print(maxRib * maxRib);\n}"}], "negative_code": [{"source_code": "var num = parseInt(readline());\n \nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n \n var minRib = rectangleRibs[0];\n var maxRib = rectangleRibs[1];\n if (rectangleRibs[1] < rectangleRibs[0]) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n \n if (minRib * 2 >= maxRib)\n print(minRib * minRib);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "var num = parseInt(readline());\n\nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n\n var minRib = rectangleRibs[0];\n var maxRib = rectangleRibs[1];\n if (maxRib < minRib) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n\n if (minRib * 2 > maxRib)\n print(minRib * minRib * 4);\n if (maxRib == minRib)\n print(maxRib * maxRib);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "var num = parseInt(readline());\n\nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n\n var minRib = rectangleRibs[0];\n var maxRib = rectangleRibs[1];\n if (maxRib < minRib) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n\n var side = minRib * 2;\n if (side >= maxRib)\n print(side * side);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "var num = parseInt(readline());\n \nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n \n var minRib = rectangleRibs[0];\n var maxRib = rectangleRibs[1];\n if (rectangleRibs[1] < rectangleRibs[0]) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n \n if (minRib * 2 >= maxRib)\n print(minRib * minRib * 2);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "var num = parseInt(readline());\n \nfor (var i = 0; i < num; i++) {\n var rectangleRibs = readline().split(\" \");\n \n var minRib = rectangleRibs[0];\n var maxRib = rectangleRibs[1];\n if (rectangleRibs[1] < rectangleRibs[0]) {\n minRib = rectangleRibs[1];\n maxRib = rectangleRibs[0];\n }\n \n if (minRib * 2 >= maxRib)\n print(minRib * minRib * 4);\n else\n print(maxRib * maxRib);\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t; x++) {\n const [n1, n2] = input[x].split(\" \");\n\n //\uc791\uc740 \ucabd\uc744 a\ub77c \ud574\uc57c \ud55c\ub2e4.\n const a = n1 > n2 ? n2 : n1;\n const b = n1 > n2 ? n1 : n2;\n\n //1. \uc815\uc0ac\uac01\ud615\uc77c \ub54c\n if (a === b) {\n console.log(4 * a * a);\n }\n //2. \uc801\ub2f9\ud55c \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n else if (2 * a >= b) {\n console.log(2 * a * 2 * a);\n }\n //3. \ud55c \ucabd\uc774 \ub9e4\uc6b0 \uae34 \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n else {\n console.log(b * b);\n }\n }\n}\n\n/*\n Q. \ucd5c\uc18c \uc815\uc0ac\uac01\ud615\uc758 \ub113\uc774 \uad6c\ud558\ub77c. 2\uac1c\uc758 \ub611\uac19\uc740 a*b\uc758 \uc9c1\uc0ac\uac01\ud615\uc744 \ub193\uc744 \uc218 \uc788\ub294\n\n 1. \uc8fc\uc5b4\uc9c4 \uc0ac\uac01\ud615\ub4e4\uc744 \ubaa8\ub450 \ud3ec\ud568\ud558\ub294 \ucd5c\uc18c \uacf5\uac04\uc758 \ud06c\uae30\ub97c \uad6c\ud558\ub77c\n 2. \ud68c\uc804 \uac00\ub2a5 (\ub2e8, \ubcc0\uc774 \ud56d\uc0c1 \uc218\ud3c9)\n 3. \uc774\ub3d9 \uac00\ub2a5\n 4. \uacb9\uce58\uae30 \ubd88\uac00\ub2a5\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t; x++) {\n const [n1, n2] = input[x].split(\" \");\n\n //\uc791\uc740 \ucabd\uc744 a\ub77c \ud574\uc57c \ud55c\ub2e4.\n const a = n1 > n2 ? n2 : n1;\n const b = n1 > n2 ? n1 : n2;\n\n //1. \uc801\ub2f9\ud55c \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n if (2 * a >= b) {\n console.log(2 * a * 2 * a);\n }\n //2. \ud55c \ucabd\uc774 \ub9e4\uc6b0 \uae34 \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n else {\n console.log(b * b);\n }\n }\n}\n\n/*\n Q. \ucd5c\uc18c \uc815\uc0ac\uac01\ud615\uc758 \ub113\uc774 \uad6c\ud558\ub77c. 2\uac1c\uc758 \ub611\uac19\uc740 a*b\uc758 \uc9c1\uc0ac\uac01\ud615\uc744 \ub193\uc744 \uc218 \uc788\ub294\n\n 1. \uc8fc\uc5b4\uc9c4 \uc0ac\uac01\ud615\ub4e4\uc744 \ubaa8\ub450 \ud3ec\ud568\ud558\ub294 \ucd5c\uc18c \uacf5\uac04\uc758 \ud06c\uae30\ub97c \uad6c\ud558\ub77c\n 2. \ud68c\uc804 \uac00\ub2a5 (\ub2e8, \ubcc0\uc774 \ud56d\uc0c1 \uc218\ud3c9)\n 3. \uc774\ub3d9 \uac00\ub2a5\n 4. \uacb9\uce58\uae30 \ubd88\uac00\ub2a5\n*/\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\n\nrl.on(\"line\", function (line) {\n input.push(line);\n}).on(\"close\", function () {\n solve(input);\n process.exit();\n});\n\nfunction solve(input) {\n const t = input[0];\n\n for (let x = 1; x <= t; x++) {\n const [n1, n2] = input[x].split(\" \");\n\n //\uc791\uc740 \ucabd\uc744 a\ub77c \ud574\uc57c \ud55c\ub2e4.\n const a = n1 > n2 ? n2 : n1;\n const b = n1 > n2 ? n1 : n2;\n\n //1. \uc801\ub2f9\ud55c \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n if (2 * a >= b) {\n console.log(2 * a * 2 * a);\n }\n //2. \ud55c \ucabd\uc774 \ub9e4\uc6b0 \uae34 \uc9c1\uc0ac\uac01\ud615\uc77c \ub54c\n else {\n console.log(b * b);\n }\n }\n}\n\n/*\n Q. \ucd5c\uc18c \uc815\uc0ac\uac01\ud615\uc758 \ub113\uc774 \uad6c\ud558\ub77c. 2\uac1c\uc758 \ub611\uac19\uc740 a*b\uc758 \uc9c1\uc0ac\uac01\ud615\uc744 \ub193\uc744 \uc218 \uc788\ub294\n\n 1. \uc8fc\uc5b4\uc9c4 \uc0ac\uac01\ud615\ub4e4\uc744 \ubaa8\ub450 \ud3ec\ud568\ud558\ub294 \ucd5c\uc18c \uacf5\uac04\uc758 \ud06c\uae30\ub97c \uad6c\ud558\ub77c\n 2. \ud68c\uc804 \uac00\ub2a5 (\ub2e8, \ubcc0\uc774 \ud56d\uc0c1 \uc218\ud3c9)\n 3. \uc774\ub3d9 \uac00\ub2a5\n 4. \uacb9\uce58\uae30 \ubd88\uac00\ub2a5\n*/\n"}], "src_uid": "3bb093fb17d6b76ae340fab44b08fcb8"} {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n nextBigArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextBigInt());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = []; // let uniSet = new Set();\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1; // uniSet.add(uni);\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n sub.sort((a, b) => Number(b - a));\n sums[i] = [0n];\n\n for (let j = 0; j < sub.length; j++) {\n sums[i][j + 1] = sums[i][j] + sub[j];\n }\n }\n\n let retSums = Array.from({\n length: n + 1\n }).map(() => 0n);\n\n for (let i = 0; i < n; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n for (let k = 1; k <= sub.length; k++) {\n let max = sub.length - sub.length % k;\n retSums[k] += sums[i][max];\n }\n } // uniSet.forEach((i) => {\n // let sub = arr[i];\n // for (let k = 1; k <= sub.length; k++) {\n // let max = sub.length - (sub.length % k);\n // retSums[k] += sums[i][max];\n // }\n // });\n\n\n for (let k = 1; k <= n; k++) {\n io.write(retSums[k]);\n }\n\n io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextBigArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;", "positive_code": [{"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n nextBigArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextBigInt());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = []; // let uniSet = new Set();\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1; // uniSet.add(uni);\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n sub.sort((a, b) => b - a);\n sums[i] = [0];\n\n for (let j = 0; j < sub.length; j++) {\n sums[i][j + 1] = sums[i][j] + sub[j];\n }\n }\n\n let retSums = Array.from({\n length: n + 1\n }).map(() => 0);\n\n for (let i = 0; i < n; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n for (let k = 1; k <= sub.length; k++) {\n let max = sub.length - sub.length % k;\n retSums[k] += sums[i][max];\n }\n } // uniSet.forEach((i) => {\n // let sub = arr[i];\n // for (let k = 1; k <= sub.length; k++) {\n // let max = sub.length - (sub.length % k);\n // retSums[k] += sums[i][max];\n // }\n // });\n\n\n for (let k = 1; k <= n; k++) {\n io.write(retSums[k]);\n }\n\n io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextNumArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n nextBigArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextBigInt());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = [];\n let uniSet = new Set();\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1;\n uniSet.add(uni);\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n sub.sort((a, b) => b - a);\n sums[i] = [0];\n\n for (let j = 0; j < sub.length; j++) {\n sums[i][j + 1] = sums[i][j] + sub[j];\n }\n }\n\n let retSums = Array.from({\n length: n + 1\n }).map(() => 0);\n uniSet.forEach(i => {\n let sub = arr[i];\n\n for (let k = 1; k <= sub.length; k++) {\n let max = sub.length - sub.length % k;\n retSums[k] += sums[i][max];\n }\n });\n\n for (let k = 1; k <= n; k++) {\n io.write(retSums[k]);\n }\n\n io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextNumArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n nextBigArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextBigInt());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = [];\n let uniMap = new Map();\n let uniSet = new Set();\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1;\n uniSet.add(uni);\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]); // if (!uniMap.has(uni)) {\n // uniMap.set(uni, []);\n // }\n // uniMap.get(uni)!.push(s[i]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n sub.sort((a, b) => b - a);\n sums[i] = [0];\n\n for (let j = 0; j < sub.length; j++) {\n sums[i][j + 1] = sums[i][j] + sub[j];\n }\n }\n\n let maxK = 0;\n uniSet.forEach(i => {\n maxK = Math.max(maxK, arr[i].length);\n }); // console.log({ maxK });\n // console.log(uniSet.size);\n\n let retSums = Array.from({\n length: n + 1\n }).map(() => 0); // console.log(sums);\n // console.log(uniSet);\n\n uniSet.forEach(i => {\n let sub = arr[i];\n\n for (let k = 1; k <= sub.length; k++) {\n let max = sub.length - sub.length % k; // console.log({ k, i, max });\n\n retSums[k] += sums[i][max];\n }\n });\n\n for (let k = 1; k <= n; k++) {\n io.write(retSums[k]);\n }\n\n io.writeLine(''); // for (let k = 1; k <= maxK; k++) {\n // let ret = 0;\n // uniSet.forEach((i) => {\n // let sub = arr[i];\n // // let max = Math.floor(sub.length / k) * k;\n // let max = sub.length - (sub.length % k);\n // ret += sums[i][max];\n // });\n // // for (let i = 0; i < arr.length; i++) {\n // // let sub = arr[i];\n // // if (!sub) {\n // // continue;\n // // }\n // // let max = Math.floor(sub.length / k) * k;\n // // ret += sums[i][max];\n // // }\n // io.write(ret);\n // }\n // for (let k = maxK + 1; k <= n; k++) {\n // io.write('0');\n // }\n // io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextNumArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst u = rna();\r\n\t\tconst s = rna();\r\n\r\n\t\tconst unv = Array.from(Array(n), x => []); // only n unv\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t--u[i];\r\n\t\t\tunv[u[i]].push(s[i]);\r\n\t\t}\r\n\r\n\t\tlet ans = Array(n).fill(0); // only n answers\r\n\t\tfor (const stds of unv) {\r\n\t\t\tstds.sort((x, y) => y-x);\r\n\r\n\t\t\tconst sz = stds.length;\r\n\t\t\tconst pr = [0];\r\n\t\t\tfor (let i = 0; i < sz; i++) {\r\n\t\t\t\tpr[i+1] = pr[i] + stds[i];\r\n\t\t\t}\r\n\r\n\t\t\tfor (let k = 1; k <= sz; k++) {\r\n\t\t\t\tans[k-1] += pr[sz - sz%k];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst u = rna();\r\n\t\tconst s = rna();\r\n\r\n\t\tconst unv = Array.from(Array(n), x => []);\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tunv[u[i]-1].push(s[i]);\r\n\t\t}\r\n\r\n\t\tlet ans = Array(n).fill(0);\r\n\t\tfor (const stnds of unv) {\r\n\t\t\tstnds.sort((x, y) => y-x);\r\n\t\t\tconst psm = []; psm[-1] = 0;\r\n\t\t\tfor (let i = 0; i < stnds.length; i++) {\r\n\t\t\t\tpsm[i] = psm[i-1] + stnds[i];\r\n\t\t\t}\r\n\t\t\tfor (let i = 1; i <= stnds.length; i++) {\r\n\t\t\t\tconst indx = stnds.length - stnds.length%i;\r\n\t\t\t\tans[i-1] += psm[indx-1]; //\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n;// CONCATENATED MODULE: ./src/io.js\nvar interact = function interact(main) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var inputString = '';\n var currentLine = 0;\n\n var readline = function readline() {\n return inputString[currentLine++];\n };\n\n var print = function print() {\n for (var _len = arguments.length, any = new Array(_len), _key = 0; _key < _len; _key++) {\n any[_key] = arguments[_key];\n }\n\n process.stdout.write(any.join(' '));\n };\n\n var println = function println() {\n for (var _len2 = arguments.length, any = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n any[_key2] = arguments[_key2];\n }\n\n any.length > 0 && print(any);\n print('\\n');\n };\n\n var obj = {\n print: print,\n println: println,\n readline: readline\n };\n process.stdin.on('data', function (inputStdin) {\n inputString += inputStdin;\n });\n process.stdin.on('end', function () {\n inputString = inputString.trim().split('\\n').map(function (string) {\n return string.trim();\n });\n main(obj);\n });\n};\n\n/* harmony default export */ const io = (interact);\n;// CONCATENATED MODULE: ./src/index.js\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === \"undefined\" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\n\n\nvar main = function main(io) {\n var tc = parseInt(io.readline());\n\n while (tc--) {\n var n = parseInt(io.readline()); // O(n)\n\n var studentUni = io.readline().split(' ').map(function (x) {\n return parseInt(x);\n }); // O(n)\n\n var skill = io.readline().split(' ').map(function (x) {\n return parseInt(x);\n });\n var uss = Array(n); // O(n)\n\n var set = new Set();\n\n for (var i = 0; i < n; i++) {\n uss[i] = {\n uni: studentUni[i],\n skill: skill[i]\n };\n set.add(studentUni[i]);\n } // O(nlogn)\n\n\n uss.sort(function (a, b) {\n if (a.uni === b.uni) return b.skill - a.skill;\n return a.uni - b.uni;\n }); // O(n)\n\n var uni = [];\n var prevUni = 0; // O(n)\n\n for (var _i = 0, _uss = uss; _i < _uss.length; _i++) {\n var ussItem = _uss[_i];\n\n if (prevUni !== ussItem.uni) {\n prevUni = ussItem.uni;\n uni.push([ussItem.skill]);\n } else {\n var prevUniLength = uni[uni.length - 1].length;\n var prevSkillSum = prevUniLength === 0 ? 0 : uni[uni.length - 1][prevUniLength - 1];\n var nextSkillSum = prevSkillSum + ussItem.skill;\n uni[uni.length - 1].push(nextSkillSum);\n }\n }\n\n uni.sort(function (a, b) {\n return b.length - a.length;\n });\n var res = [];\n\n a1: for (var k = 1; k <= n; k++) {\n res.push(0);\n\n var _iterator = _createForOfIteratorHelper(uni),\n _step;\n\n try {\n for (_iterator.s(); !(_step = _iterator.n()).done;) {\n var uniItem = _step.value;\n if (k > uniItem.length) continue a1;\n var index = Math.floor(uniItem.length / k) * k - 1;\n if (index < 0) continue;\n res[k - 1] += uniItem[index];\n }\n } catch (err) {\n _iterator.e(err);\n } finally {\n _iterator.f();\n }\n }\n\n io.println(res.join(' '));\n }\n};\n\nio(main);\n/******/ })()\n;"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var u = readline().split(' ').map(a => parseInt(a));\n var s = readline().split(' ').map(a => parseInt(a));\n var a = [];\n var power = new Array(n + 1).fill(0);\n u.forEach((el, i) => {\n if (!a[el])\n a[el] = new Array();\n a[el].push(s[i]);\n });\n\n for (var i = 1; i <= n; i++)\n if (a[i]) {\n a[i].sort((a, b) => b - a);\n var len = a[i].length ;\n for (var j = 1; j < len; j++)\n a[i][j] += a[i][j - 1];\n for (var j = 1; j <= len; j++) {\n var x = parseInt(len / j) * j;\n power[j] += a[i][x - 1];\n }\n }\n \n for (var i = 1; i <= n; i++)\n write(`${power[i]} `);\n write('\\n'); \n}"}], "negative_code": [{"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = [];\n let uniMap = new Map();\n let uniSet = new Set();\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1;\n uniSet.add(uni);\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]); // if (!uniMap.has(uni)) {\n // uniMap.set(uni, []);\n // }\n // uniMap.get(uni)!.push(s[i]);\n }\n\n for (let i = 0; i < arr.length; i++) {\n let sub = arr[i];\n\n if (!sub) {\n continue;\n }\n\n sub.sort((a, b) => b - a);\n sums[i] = [0];\n\n for (let j = 0; j < sub.length; j++) {\n sums[i][j + 1] = sums[i][j] + sub[j];\n }\n }\n\n let maxK = 0;\n uniSet.forEach(i => {\n maxK = Math.max(maxK, arr[i].length);\n });\n\n for (let k = 1; k <= maxK; k++) {\n let ret = 0;\n uniSet.forEach(i => {\n let sub = arr[i];\n let max = Math.floor(sub.length / k) * k;\n ret += sums[i][max];\n }); // for (let i = 0; i < arr.length; i++) {\n // let sub = arr[i];\n // if (!sub) {\n // continue;\n // }\n // let max = Math.floor(sub.length / k) * k;\n // ret += sums[i][max];\n // }\n\n io.write(ret);\n }\n\n for (let k = maxK + 1; k < n; k++) {\n io.write('0');\n }\n\n io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextNumArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 747:\n/***/ ((module) => {\n\nmodule.exports = require(\"fs\");;\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t(() => {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = (module) => {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\t() => (module['default']) :\n/******/ \t\t\t\t() => (module);\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t(() => {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = (exports, definition) => {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t})();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.\n(() => {\n\n// EXTERNAL MODULE: external \"fs\"\nvar external_fs_ = __webpack_require__(747);\nvar external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);\n;// CONCATENATED MODULE: external \"readline\"\nconst external_readline_namespaceObject = require(\"readline\");;\n;// CONCATENATED MODULE: ./src/lib/io.ts\n\n\nclass InteractiveIO {\n constructor() {\n this.rl = void 0;\n this.lines = [];\n this.rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n this.rl.on('line', line => {\n this.lines.push(line);\n });\n }\n\n nextLine() {\n return new Promise((resolve, reject) => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n return;\n }\n\n let waitId = null;\n let timeoutId = null;\n waitId = setInterval(() => {\n if (this.lines.length) {\n resolve(this.lines.shift());\n clearTimeout(timeoutId);\n clearInterval(waitId);\n return;\n }\n }, 1);\n timeoutId = setTimeout(() => {\n clearInterval(waitId);\n reject(new Error('timeout')); // resolve(null);\n }, 500);\n });\n }\n\n close() {\n this.rl.close();\n }\n\n}\nclass IO {\n constructor() {\n this.i = 0;\n this.text = '';\n this.out = '';\n this.readInput();\n }\n\n readInput() {\n this.text = __webpack_require__(747).readFileSync(0, 'utf8');\n }\n\n nextToken() {\n let ret = '';\n\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n\n return ret;\n }\n\n nextNum() {\n return Number(this.nextToken());\n }\n\n nextBigInt() {\n return BigInt(this.nextToken());\n }\n\n nextNumArray(n) {\n let ret = [];\n\n while (n--) {\n ret.push(this.nextNum());\n }\n\n return ret;\n }\n\n _write(x) {\n this.out += x;\n }\n\n write(x) {\n this._write(x + ' ');\n }\n\n writeLine(x) {\n this._write(x + '\\n');\n }\n\n flush() {\n external_fs_default().writeFileSync(1, this.out);\n this.out = '';\n }\n\n}\n;// CONCATENATED MODULE: ./src/cf-1519/1519-c.ts\n\nconst io = new IO();\n\nfunction solve(n, u, s) {\n let arr = [];\n let sums = [];\n\n for (let i = 0; i < n; i++) {\n let uni = u[i] - 1;\n\n if (!arr[uni]) {\n arr[uni] = [];\n }\n\n arr[uni].push(s[i]);\n }\n\n arr.forEach((sub, i) => {\n sub.sort((a, b) => b - a);\n sums[i] = [0];\n sub.forEach((a, j) => {\n sums[i][j + 1] = sums[i][j] + a;\n });\n });\n let maxK = 0;\n arr.forEach(sub => {\n maxK = Math.max(sub.length, maxK);\n });\n\n for (let k = 1; k <= maxK; k++) {\n let ret = 0;\n arr.forEach((sub, i) => {\n if (!sub) {\n return;\n }\n\n let max = Math.floor(sub.length / k) * k;\n ret += sums[i][max];\n });\n io.write(ret);\n }\n\n io.writeLine('');\n}\n\nfunction main() {\n try {\n let t = io.nextNum();\n\n while (t--) {\n let n = io.nextNum();\n let u = io.nextNumArray(n);\n let s = io.nextNumArray(n);\n solve(n, u, s);\n }\n\n io.flush();\n } catch (e) {\n console.log(e.stack);\n }\n}\n\nmain();\n\n})();\n\n/******/ })()\n;"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var n = parseInt(readline());\n var u = readline().split(' ').map(a => parseInt(a));\n var s = readline().split(' ').map(a => parseInt(a));\n var a = [];\n var power = [];\n u.forEach((el, i) => {\n if (!a[el])\n a[el] = new Array();\n a[el].push(s[i]);\n });\n\n for (var i = 0; i < n; i++) {\n\t\tvar len = a[i]? a[i].length: 0;\n\t\tfor (var j = 0; j < len - 1; j++)\n\t\t\ta[i][j] += a[i][j - 1];\n\t\tfor (var j = 0; j < len; j++) {\n\t\t\tvar x = parseInt(len / j) * j;\n\t\t\tpower[j] += a[i][x - 1];\n\t\t}\n\t}\n \n for (var i = 0; i < n; i++)\n write(`${power[i]} `);\n write('\\n'); \n}"}], "src_uid": "437ab04bd029db32ceba31becbe06722"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst students = [];\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const marks = d;\n students.push(marks);\n\n c++;\n});\n\nrl.on('close', () => {\n const bests = new Set();\n\n for (let i = 0; i < students[0].length; i++) {\n let best = 0;\n for (let j = 0; j < students.length; j++) {\n if (students[j][i] > best) {\n best = students[j][i];\n }\n }\n\n for (let z = 0; z < students.length; z++) {\n if (students[z][i] === best) {\n bests.add(z);\n }\n }\n }\n\n console.log(bests.size);\n});\n", "positive_code": [{"source_code": "print(function(n, m) {\n\tvar i, j,\n\t\ta = [],\n\t\tb = new Int8Array(n);\n\n\tfor (i = 0; i < n; i++)\n\t\ta.push(readline().split('').map(Number));\n\n\tfor (i = 0; i < m; i++) {\n\t\tvar max = 0;\n\n\t\tfor (j = 0; j < n; j++)\n\t\t\tmax = Math.max(a[j][i], max);\n\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (a[j][i] === max) b[j] = 1;\n\t}\n\n\tvar ans = 0;\n\tfor (i = 0; i < n; i++)\n\t\tif (b[i] === 1) ans++;\n\n\treturn ans;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "print(function(n, m) {\n\tvar i, j,\n\t\ta = [],\n\t\tb = [];\n\n\tfor (i = 0; i < n; i++) {\n\t\ta.push(readline().split('').map(Number));\n\t\tb.push(0);\n\t}\n\n\tfor (i = 0; i < m; i++) {\n\t\tvar max = 0;\n\n\t\tfor (j = 0; j < n; j++)\n\t\t\tmax = Math.max(a[j][i], max);\n\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (a[j][i] === max) b[j] = 1;\n\t}\n\n\treturn b.filter(function(v) {\n\t\treturn v === 1;\n\t}).length;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\t\n\tvar n = readline().split(' ');\n\tvar m = +n[1];\n\tn = +n[0];\n\n\tvar u = [];\n\tfor (var i = 0; i < n; i++) u.push(readline().split('').map(Number));\n\n\tvar s = {};\n\tfor (var i = 0; i < m; i++) {\n\t\tvar l = u.map(function (e) { return e[i]; });\n\t\tvar max = Math.max.apply(null, l);\n\t\tl.forEach(function (e, i) { if (e == max) s[i] = true; });\n\t}\n\n\tprint( Object.keys(s).length );\n\n}).call(this);"}], "negative_code": [], "src_uid": "41bdb08253cf5706573f5d469ab0a7b3"} {"source_code": "//var input = readline()\nvar n = parseInt(readline())\n\nprint(n)\nvar arr = new Array(n).fill(1)\nprint(arr.join(' '))\n\n//", "positive_code": [{"source_code": "var n = +readline();\n\nprint(n);\nvar res = '';\nfor(var i = 0; i < n; i++) {\n res += '1 ';\n}\nprint(res);"}, {"source_code": "function main(n){\n\n print(n);\n var ans = \"\"\n for(var i = 0 ; i < n ; i++){\n ans += \"1 \";\n }\n\n print(ans);\n}\n\n\nvar n = parseInt(readline());\n\nmain(n);\n"}, {"source_code": "var k = Number(readline())\nvar arr = new Array(k).fill(1)\nprint(k)\nprint(arr.join(\" \"))"}, {"source_code": "var n = parseInt(readline());\nwrite(n + \"\\n\");\nwrite(Array(n).fill(1).join(\" \"));"}, {"source_code": "\nvar taka = parseInt(readline());\nprint(taka);\n\nfor (var i = 1; i <= taka; i++) {\n print(1 + ' ');\n}\n\n"}, {"source_code": "var num = parseInt(readline());\nprint(num);\nfor(var i = 1; i <= num; i++){\n print(1 + ' ');\n}"}, {"source_code": "//var input = readline();\nvar T = parseInt(readline());\n\nprint(T);\nfor(var i=0; i {\n let n = +d;\n let divider = 9;\n\n while(n % divider !== 0) {\n divider--;\n }\n\n console.log(n / divider);\n console.log(new Array(n / divider).fill(divider).join(' '));\n});\n"}, {"source_code": "var N = 0;\nvar readliner = require('readline');\nvar rl = readliner.createInterface(process.stdin, process.stdout, null);\nrl.on('line', function (cmd) {\n //console.log('You just typed: '+cmd);\n N = parseInt(cmd);\n }).on('close', main);\n\nfunction main() {\n //console.log('goodbye!');\n\n/* var mn = 1000000000;\n for (var code=0; code<(1<<9); code++) {\n\tvar cnt_ones = 0;\n\tfor (var j=0; j<9; j++) cnt_ones += (code>>j)&1;\n var x = N;\n \n }*/\n\n console.log(N);\n var ans = \"\";\n for (var j=0; j= 0 ; i-- ) {\n \t\tif( fl == 0 ) {\n \t\t\tbreak ;\n \t\t}\n \t\twhile( true ) {\n \t\t\tif( crr[ i ] > 0 ) {\n \t\t\t\tif( j <= 0 ) {\n \t\t\t\t\tfl = 0 ;\n \t\t\t\t\tbreak ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == 0 ) {\n \t\t\t\t\tj-- ;\n \t\t\t\t\tcontinue ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == mi ) {\n \t\t\t\t\tif( this.brr[ j ] < i + 1 ) {\n \t\t\t\t\t\tthis.brr[ j ] = 0 ;\n \t\t\t\t\t\tj-- ;\n \t\t\t\t\t\tcontinue ;\n \t\t\t\t\t}\n \t\t\t\t\tthis.brr[ j ] -= i + 1 ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == 0 ) {\n \t\t\t\t\tj-- ;\n \t\t\t\t\tcontinue ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] <= crr[ i ] ) {\n \t\t\t\t\tcrr[ i ] -= this.brr[ j ] ;\n \t\t\t\t\tthis.brr[ j ] = 0 ;\n \t\t\t\t\tj-- ;\n \t\t\t\t}\n \t\t\t\telse {\n \t\t\t\t\tthis.brr[ j ] -= crr[ i ] ;\n \t\t\t\t\tcrr[ i ] = 0 ;\n \t\t\t\t}\n \t\t\t}\n \t\t\telse {\n \t\t\t\tbreak ;\n \t\t\t}\n \t\t}\n \t}\n \tfor( i = this.n - 1 ; i >= 0 ; i-- ) {\n \t\tif( crr[ i ] > 0 ) {\n \t\t\tfl = 0 ;\n \t\t\tbreak ;\n \t\t}\n \t}\n \tif( fl == 1 ) {\n \t\t\thi = mi - 1 ;\n \t\t\tres = mi ;\n \t\t}\n \t\telse {\n \t\t\tlo = mi + 1 ;\n \t\t}\n }\n print( res ) ;\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n", "positive_code": [{"source_code": "\n// GukiZ \n\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i 1) {\n\n time = Math.round((o_min + o_max) / 2);\n\n arr_kor = arr.slice();\n posNotNull = 0;\n for (i=1; i <= m; i++) { \n\n time_tmp = time - posNotNull;\n for (j=posNotNull; j < n; j++) { \n time_tmp --;\n\n if (arr_kor[j] == 0) {\n posNotNull ++;\n continue;\n }\n\n if (arr_kor[j] < time_tmp) {\n time_tmp -= arr_kor[j];\n arr_kor[j] = 0;\n } else {\n arr_kor[j] -= time_tmp;\n break;\n }\n }\n if (arr_kor[n-1] == 0) break;\n }\n\n if (arr_kor[n-1] == 0) {\n o_max = time;\n } else {\n o_min = time;\n }\n\n}\n\nprint(o_max);\n "}], "negative_code": [{"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , lo , hi , mi , fl , crr ;\n res = 0 ;\n lo = 0 ;\n hi = 100000000000000 ;\n while( lo <= hi ) {\n \tmi = Math.floor( ( lo + hi ) / 2 ) ;\n \tfor( i = 0 ; i <= this.m ; i++ ) {\n \t\tthis.brr[ i ] = mi ;\n \t}\n \tcrr = [] ;\n \tfor( i = 0 ; i < this.n ; i++ ) {\n \t\tcrr.push( this.arr[ i ] ) ;\n \t}\n \tj = this.m ;\n \tfl = 1 ;\n \tfor( i = this.n - 1 ; i >= 0 ; i-- ) {\n \t\tif( fl == 0 ) {\n \t\t\tbreak ;\n \t\t}\n \t\twhile( true ) {\n \t\t\tif( crr[ i ] > 0 ) {\n \t\t\t\tif( j <= 0 ) {\n \t\t\t\t\tfl = 0 ;\n \t\t\t\t\tbreak ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == 0 ) {\n \t\t\t\t\tj-- ;\n \t\t\t\t\tcontinue ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == mi ) {\n \t\t\t\t\tif( this.brr[ j ] < i + 1 ) {\n \t\t\t\t\t\tthis.brr[ j ] = 0 ;\n \t\t\t\t\t\tj-- ;\n \t\t\t\t\t\tcontinue ;\n \t\t\t\t\t}\n \t\t\t\t\tthis.brr[ j ] -= i + 1 ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] == 0 ) {\n \t\t\t\t\tj-- ;\n \t\t\t\t\tcontinue ;\n \t\t\t\t}\n \t\t\t\tif( this.brr[ j ] <= crr[ i ] ) {\n \t\t\t\t\tcrr[ i ] -= this.brr[ j ] ;\n \t\t\t\t\tthis.brr[ j ] = 0 ;\n \t\t\t\t\tj-- ;\n \t\t\t\t}\n \t\t\t\telse {\n \t\t\t\t\tthis.brr[ j ] -= crr[ i ] ;\n \t\t\t\t\tcrr[ i ] = 0 ;\n \t\t\t\t}\n \t\t\t}\n \t\t\telse {\n \t\t\t\tbreak ;\n \t\t\t}\n \t\t}\n \t}\n \tfor( i = this.n - 1 ; i >= 0 ; i-- ) {\n \t\tif( crr[ i ] > 0 ) {\n \t\t\tfl = 0 ;\n \t\t\tbreak ;\n \t\t}\n \t}\n \tif( fl == 1 ) {\n \t\t\thi = mi - 1 ;\n \t\t\tres = mi ;\n \t\t}\n \t\telse {\n \t\t\tlo = mi + 1 ;\n \t\t}\n }\n print( res ) ;\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.m = irObj.nextInt();\n this.arr = [] ;\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr.push( irObj.nextInt() ) ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "\n// GukiZ \n\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i 1) {\n\n time = Math.round((o_min + o_max) / 2);\n\n arr_kor = arr;\n posNotNull = 0;\n for (i=1; i <= m; i++) { \n\n time_tmp = time - posNotNull;\n for (j=posNotNull; j < n; j++) { \n time_tmp --;\n\n if (arr_kor[j] == 0) {\n posNotNull ++;\n continue;\n }\n\n if (arr_kor[j] < time_tmp) {\n time_tmp -= arr_kor[j];\n arr_kor[j] = 0;\n } else {\n arr_kor[j] -= time_tmp;\n break;\n }\n }\n if (arr_kor[n-1] == 0) break;\n }\n\n if (arr_kor[n-1] == 0) {\n o_max = time;\n } else {\n o_min = time;\n }\n\n}\n\nprint(o_max);\n "}, {"source_code": "\n// GukiZ \n\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i 1) {\n\n time = Math.round((o_min + o_max) / 2);\n\n arr_kor = arr.slice();\n posNotNull = 0;\n for (i=1; i <= m; i++) { \n\n time_tmp = time - posNotNull;\n for (j=posNotNull; j < n; j++) { \n time_tmp --;\n\n if (arr_kor[j] == 0) {\n posNotNull ++;\n continue;\n }\n\n if (arr_kor[j] < time_tmp) {\n time_tmp -= arr_kor[j];\n arr_kor[j] = 0;\n } else {\n arr_kor[j] -= time_tmp;\n break;\n }\n }\n if (arr_kor[n-1] == 0) break;\n }\n\n if (arr_kor[n-1] == 0) {\n o_max = time;\n } else {\n o_min = time;\n }\n\n}\n\nprint(o_max);\n "}, {"source_code": "\n// GukiZ \n\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;i 1) {\n\n time = Math.round((o_min + o_max) / 2);\n\n arr_kor = arr.slice();\n posNotNull = 0;\n for (i=1; i <= m; i++) { \n\n time_tmp = time - posNotNull;\n for (j=posNotNull; j < n; j++) { \n time_tmp --;\n\n if (arr_kor[j] == 0) {\n posNotNull ++;\n continue;\n }\n\n if (arr_kor[j] < time_tmp) {\n time_tmp -= arr_kor[j];\n arr_kor[j] = 0;\n } else {\n arr_kor[j] -= time_tmp;\n break;\n }\n }\n if (arr_kor[n-1] == 0) break;\n }\n\n if (arr_kor[n-1] == 0) {\n o_max = time;\n } else {\n o_min = time;\n }\n\n}\n\nprint(o_max);\n "}], "src_uid": "ed0a8a10e03de931856e287f9e650e1a"} {"source_code": "var input = readline();\nfor(var i = 0; i < input; i ++) {\n var num = +readline();\n var c1 = c2 = Math.floor(num / 3);\n if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n print(c1 + ' ' + c2)\n}", "positive_code": [{"source_code": "\r\n\r\nfunction jobs(n)\r\n{\r\n c1 = Math.floor(n/3);\r\n if (n%3!=0) {checking = (((n/3)-c1)+'').split ('.') [1][0];}\r\n else {c2 = Math.round((n-c1)/2);return `${c1} ${c2}`;}\r\n if (checking>5) \r\n {\r\n \r\n c2 = Math.round((n-c1)/2);\r\n }\r\n else\r\n {\r\n c1++;\r\n c2 = Math.round((n-c1)/2);\r\n }\r\n return `${c1} ${c2}`;\r\n//console.log(c1, c2);\r\n\r\n }\r\n t = parseInt(readline())\r\n for (i=0;i5) \r\n {\r\n \r\n c2 = Math.round((n-c1)/2);\r\n }\r\n else if (checking==0) {c2=Math.round((n-c1)/2)}\r\n else\r\n {\r\n c1++;\r\n c2 = Math.round((n-c1)/2);\r\n }\r\n \r\nprint(c1, c2);\r\n }\r\n\r\n}\r\n\r\njobs()\r\n"}, {"source_code": "var x = readline();\r\nwhile (x--) {\r\n var n = readline();\r\n var b = Math.round(n / 3);\r\n var a = n - 2 * b;\r\n print(a + \" \" + b);\r\n}\r\n"}, {"source_code": "var t = readline();\r\nwhile(t--)\r\n{\r\n var n=readline();\r\n var c=Math.round(n/3);\r\n if(c*3==n)\r\n {\r\n print(c, c);\r\n }\r\n else if(n-3*c==1)\r\n {\r\n print(c+1, c);\r\n }\r\n else \r\n {\r\n print(c-1, c);\r\n }\r\n}"}, {"source_code": "var t = readline();\r\nwhile(t--)\r\n{\r\n var n=readline();\r\n var c=Math.round(n/3);\r\n var p=c+1;\r\n var z=c-1;\r\n if(c*3==n)\r\n {\r\n print(c+\" \"+c);\r\n }\r\n else if(n-3*c==1)\r\n {\r\n print(p+\" \"+c);\r\n }\r\n else \r\n {\r\n print(z+\" \"+c);\r\n }\r\n}\r\n"}, {"source_code": "s = readline(); while(s--){n = readline(); b = Math.round(n / 3); a = n - 2*b; print(a + \" \" + b);}"}, {"source_code": "s = readline(); while(s--){n = readline(); b = Math.round(n / 3); a = n - 2*b; print(a + \" \" + b);}"}, {"source_code": "function polycarpAndCoins(coins) {\r\n var a1 = Math.floor(coins / 3);\r\n var a2 = coins % 3;\r\n if(a2 === 2) {\r\n return a1 + \" \" + (a1 + 1);\r\n }\r\n if(a2 === 1) {\r\n return (a1 + 1) + \" \" + a1;\r\n }\r\n return a1 + \" \" + a1;\r\n}\r\n\r\nconst readNumber = () => +readline();\r\n\r\nconst n = readNumber();\r\nfor(var i = 0; i < n; i++) {\r\n print(polycarpAndCoins(readNumber()));\r\n}\r\n"}, {"source_code": "const readNumber = () => +readline();\r\n \r\nconst n = readNumber();\r\n\r\nfor(var i = 0; i < n; i++) {\r\n var v = readNumber();\r\n var a1 = Math.floor(v / 3);\r\n var a2 = v % 3;\r\n if(a2 === 2) {\r\n print(a1 + \" \" + (a1 + 1));\r\n continue;\r\n }\r\n if(a2 === 1) {\r\n print((a1 + 1) + \" \" + a1);\r\n continue;\r\n }\r\n print(a1 + \" \" + a1);\r\n}\r\n"}, {"source_code": "var cases = parseInt(readline());\r\n print();\r\n while(cases--){\r\n var target=parseInt(readline());\r\n var c2=parseInt(target/3);\r\n var c1=target-(c2*2);\r\n if(c1-c2==2){\r\n c1-=2;\r\n c2++;\r\n }\r\n print(c1+\" \"+c2);\r\n }\r\n"}, {"source_code": "main(parseInt(readline()));\r\nfunction main(cases) {\r\n print();\r\n while(cases--){\r\n var target=parseInt(readline());\r\n var c2=parseInt(target/3);\r\n var c1=target-(c2*2);\r\n if(c1-c2==2){\r\n c1-=2;\r\n c2++;\r\n }\r\n print(c1+\" \"+c2);\r\n }\r\n}"}, {"source_code": "function solve()\r\n{\r\n\tvar a = +readline();\r\n\tvar z = Math.floor(a / 3);\r\n\tif(a % 3 === 0 )\r\n\tprint(z + \" \"+ z);\r\n\telse if(a % 3 === 2 ) print ((z) + \" \"+ (z+1))\r\n\telse print((z+1) + \" \"+ (z))\r\n}\r\n \r\n\tvar n = +readline();\r\n\tfor (var i = 0; i < n; i++)\r\n\t\t\tsolve();\r\n"}, {"source_code": "s = readline(); while(s--){n = readline(); b = Math.round(n / 3); a = n - 2*b; print(a + \" \" + b);}"}, {"source_code": "var limit = parseInt(readline());\r\n for (var i = 0; i < limit; i++) {\r\n var value = parseInt(readline());\r\n var coins = Math.floor(value / 3);\r\n var ones = coins;\r\n var twos = coins;\r\n if (value % 3 !== 0) {\r\n if (value % 3 === 1)\r\n ones++;\r\n else\r\n twos++;\r\n }\r\n print(\"\".concat(ones, \" \").concat(twos));\r\n }"}, {"source_code": "test = readline()\r\nwhile (test--) {\r\n burles = readline();\r\n x = Math.round(burles / 3)\r\n y = burles - 2 * x;\r\n print(y,x)\r\n}"}, {"source_code": "t = +readline();\r\nwhile (t--) {\r\n x = +readline();\r\n y = x * (2 / 3);\r\n y = Math.trunc(y);\r\n if (y % 2 === 1) {\r\n y = y + 1;\r\n } else {\r\n y = y;\r\n }\r\n q = x - y;\r\n y = y / 2;\r\n print(q + \" \" + y);\r\n}\r\n"}, {"source_code": "var nm=readline()\r\nwhile(nm--){\r\n var n=parseInt(readline())\r\n var t=parseInt(n/3)\r\n if(n%3!==2) print(n-(2*t)+ ' '+t)\r\n else{\r\n print(parseInt(n/3)+' '+(n-parseInt(n/3))/2)\r\n }\r\n}\r\n"}, {"source_code": "var t = Number(readline());\r\n\r\nwhile (t--) {\r\n var buries = Number(readline());\r\n var b = buries / 3;\r\n\r\n if (buries % 3 == 0) \r\n print(b + \" \" + b);\r\n\r\n else {\r\n if (Math.floor(b) * 3 + 1 == buries)\r\n print(Math.floor(b) + 1 + \" \" + Math.floor(b));\r\n else \r\n print(Math.floor(b) + \" \" + (Math.floor(b) + 1));\r\n }\r\n}"}, {"source_code": "var numberOfCases = Number(readline());\r\nfor (var i = 0; i < numberOfCases; ++i) {\r\n processCase();\r\n}\r\n\r\nfunction processCase() {\r\n var n = Number(readline());\r\n\r\n var c1 = c2 = Math.floor(n / 3);\r\n if (n % 3 === 1) {\r\n ++c1;\r\n }\r\n\r\n if (n % 3 === 2) {\r\n ++c2;\r\n }\r\n\r\n print(`${c1} ${c2}`);\r\n}"}, {"source_code": "var testCases = +readline();\r\n\r\nwhile (testCases-- > 0) {\r\n var n = +readline();\r\n\r\n var n3 = Math.floor(n / 3);\r\n switch (n % 3) {\r\n case 0:\r\n print(n3, n3);\r\n break;\r\n case 1:\r\n print(n3 + 1, n3);\r\n break;\r\n case 2:\r\n print(n3, n3 + 1)\r\n break;\r\n }\r\n}"}, {"source_code": "var l0 = readline();\r\nvar n = +l0;\r\nvar arr = [];\r\nfor (var a = 0; a 0) num % 3 === 1 ? c1 ++ : c2 ++;\r\n print(c1 + ' ' + c2)\r\n}"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let n = nextInt();\r\n let a = Math.floor(n / 3);\r\n let m = n % 3;\r\n let b = a;\r\n a += m;\r\n let c = a - 2;\r\n let d = b + 1;\r\n if (Math.abs(a - b) <= Math.abs(c - d)) {\r\n print(a, b);\r\n } else {\r\n print(c, d);\r\n }\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\n\nprocess.stdin.setEncoding(\"utf8\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", (data) => {\n input += data;\n});\nprocess.stdin.on(\"end\", () => {\n main(input);\n});\n\nfunction main(input) {\n input = input.split(\"\\n\");\n let z = 0;\n let testCases = parseInt(input[z++], 10);\n\n while (testCases--) {\n let str = input[z++].trim();\n solve(str);\n }\n}\n\nfunction solve(str) {\n const sum = parseInt(str, 10);\n let countOne = Math.floor(sum / 3);\n let countTwo = countOne;\n\n const left = sum % 3;\n\n if (left === 1) {\n countOne++;\n }\n\n if (left === 2) {\n countTwo++;\n }\n\n console.log(`${countOne} ${countTwo}`);\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nconst calc = (a, b) => {\n return a + 2 * b;\n};\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const n = Number(d);\n const mid = Math.floor(n / 3);\n let c1 = mid;\n let c2 = mid;\n\n if (n % 3 === 1) {\n c1++;\n }\n\n if (n % 3 === 2) {\n c2++;\n }\n\n console.log(c1, c2);\n\n // const mid = Number(d) / 3;\n // const min = Math.floor(mid);\n // const max = Math.ceil(mid);\n\n // if (calc(min, max) === Number(d)) {\n // console.log(min, max);\n // } else {\n // console.log(max, min);\n // }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nconst calc = (a, b) => {\n return a + 2 * b;\n};\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const mid = Number(d) / 3;\n const min = Math.floor(mid);\n const max = Math.ceil(mid);\n\n if (calc(min, max) === Number(d)) {\n console.log(min, max);\n } else {\n console.log(max, min);\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n // let a = readline().split(' ').map(Number)\r\n console.log(solve(n))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n) => { \r\n if ( n == 1 ) return '1 0'\r\n if ( n == 2 ) return '0 1'\r\n if ( n == 3 ) return '1 1'\r\n if ( n == 4 ) return '2 1'\r\n if ( n == 5 ) return '1 2'\r\n \r\n let twos1 = Math.floor( n / 3 )\r\n let ones1 = n - (twos1 * 2)\r\n let diff1 = Math.abs( ones1 - twos1 )\r\n \r\n let twos2 = Math.ceil( n / 3 )\r\n let ones2 = n - (twos2 * 2)\r\n let diff2 = Math.abs( ones2 - twos2 )\r\n\r\n return ( diff1 < diff2 ) ? ones1 + ' ' + twos1 : ones2 + ' ' + twos2\r\n}\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var a = Math.floor(k / 3);\n var b = Math.floor(k / 3);\n if(k % 3 == 1){\n a++;\n }else if(k % 3 == 2){\n b++;\n }\n console.log(a + ' ' + b);\n }\n});\n"}, {"source_code": "'use strict';\n\n// let env_local = true;\nlet env_local = false;\nlet inputString = '';\nlet currentLine = 0;\n\nif (!env_local) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n process.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n });\n} else {\n const fs = require('fs');\n inputString = fs\n .readFileSync(__dirname + '/input.txt', 'utf-8')\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n main();\n}\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/*--------------------------------Play-ground---------------------------------------*/\n\nvar maxN = 2 * 1e5 + 10;\n\nvar mod = BigInt(1e9 + 7);\n\nfunction solve() {\n let n = parseInt(readline());\n let c1 = 0,\n c2 = 0;\n let y = parseInt(n / 3);\n c1 += y;\n c2 += y;\n let x = n % 3;\n\n if (x == 2) c2++;\n else if (x == 1) c1++;\n console.log(`${c1} ${c2}`);\n}\n\nfunction main() {\n let t = parseInt(readline()) || 1;\n while (t--) {\n solve();\n }\n}\n"}, {"source_code": "// var n = Number(readline());\r\n\r\n// for (var i = 1; i <= n; i++) {\r\n// var m = Number(readline());\r\n// var a = parseInt(Math.round(m / 3));\r\n// var b = parseInt(Math.round(m - (a * 2)));\r\n// console.log(b + \" \" + a);\r\n// }\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var n = Number(readline());\r\n\r\n for (var i = 1; i <= n; i++) {\r\n var m = Number(readline());\r\n var a = parseInt(Math.round(m / 3));\r\n var b = parseInt(Math.round(m - (a * 2)));\r\n console.log(b + \" \" + a);\r\n }\r\n\r\n}"}, {"source_code": "// var n = Number(readline());\r\n\r\n// for (var i = 1; i <= n; i++) {\r\n// var m = Number(readline());\r\n// var a = parseInt(Math.round(m / 3));\r\n// var b = parseInt(Math.round(m - (a * 2)));\r\n// console.log(b + \" \" + a);\r\n// }\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var n = Number(readline());\r\n\r\n for (var i = 1; i <= n; i++) {\r\n var m = Number(readline());\r\n var a = parseInt(Math.round(m / 3));\r\n var b = parseInt(Math.round(m - (a * 2)));\r\n console.log(b + \" \" + a);\r\n }\r\n\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/23/21 morning\r\n * https://codeforces.com/contest/1551/problem/A\r\n */\r\nconst solve = (x) => {\r\n let a = int(x / 3);\r\n let b = ce (x / 3);\r\n if (a + 2 * b != x) return pr(b, a);\r\n pr(a, b)\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n let t = parseInt(readLine());\n while (t-- > 0) {\n solve();\n }\n}\n\nfunction solve() {\n let input = readLine();\n // console.log(\"inputNo\", inputNo);\n\n var c1 = Math.floor(input / 3);\n var c2 = c1;\n var rem = input % 3;\n\n // console.log(\"rem\",rem)\n\n if (rem == 2) {\n c2++;\n }\n else if (rem == 1) {\n c1++;\n }\n console.log(c1 + \" \" + c2)\n\n\n}\n\n\n\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet x = nl.num();\n\t\tlet c = Math.trunc(x / 3);\n\t\tans.push([c + (x%3 == 1?1:0), c + (x%3 == 2?1:0)]);\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var a = Math.floor(k / 3);\n var b = Math.floor(k / 3);\n if(k % 3 == 1){\n a++;\n }else if(k % 3 == 2){\n b++;\n }\n console.log(a + ' ' + b);\n }\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rna();\r\n\r\n\t\tlet c1 = Math.floor(n/3);\r\n\t\tlet c2 = c1;\r\n\r\n\t\tc1 += n%3 == 1;\r\n\t\tc2 += n%3 == 2;\r\n\r\n\t\tconsole.log(c1, c2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/**\r\n * Bismillahir Rahmanir Rahim\r\n * This code has been taken from: https://codeforces.com/blog/entry/69610\r\n */\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n \r\n let inputString = '';\r\n let currentLine = 0;\r\n \r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n \r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n });\r\n \r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n \r\n /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\r\n /**\r\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \r\n * when required.\r\n *\r\n * I am using console.log() to output\r\n */\r\n// function main() {\r\n// let t = readLine();\r\n// t = parseInt(t);\r\n// console.log(\"mai yahan aaya\")\r\n// while(t--) {\r\n// let line = readLine();\r\n// line = line.split(\" \");\r\n// let n = parseInt(line[0]);\r\n// let m = parseInt(line[1]);\r\n// if(n === 1) {\r\n// console.log(\"0\");\r\n// } else if (n === 2) {\r\n// console.log(m);\r\n// } else {\r\n// console.log(2*m);\r\n// }\r\n// }\r\n// }\r\n\r\nfunction main() {\r\n\t\r\n\tlet t = parseInt(readLine());\r\n\t// t = parseInt(t);\r\n\twhile(t--) {\r\n\t\tlet n = readLine();\r\n\t\tn = parseInt(n);\r\n\t\t//let s = readLine().split(\" \").map(item=>parseInt(item));\r\n\t\tsolve(n);\r\n\t\t\r\n\t}\r\n // console.log(t);\r\n}\r\n\r\nfunction solve(n) {\r\n\tlet c = parseInt(n / 3) ;\r\n\tif (n % 3 == 0) {\r\n\t\tconsole.log(c, c);\r\n\t} else if (n % 3 == 1) {\r\n\t\tconsole.log(c+1, c);\r\n\t} else {\r\n\t\tconsole.log(c, c+1);\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main(input) {\r\n const args = input.split('\\n');\r\n const t = parseInt(args[0], 10)\r\n for (var i = 1; i <= t; i++) {\r\n const c = parseInt(args[i], 10);\r\n const c3 = Math.floor(c / 3);\r\n if (c % 3 === 0) {\r\n console.log(c3, c3);\r\n } else if (c % 3 === 1) {\r\n console.log(c3 + 1, c3);\r\n } else {\r\n console.log(c3, c3 + 1);\r\n }\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let number = +input[z++];\r\n let count1 = Math.floor(number / 3)\r\n let count2 = count1;\r\n\r\n if(number % 3 === 1) count1++;\r\n else if(number % 3 === 2) count2++;\r\n console.log(count1, count2);\r\n }\r\n}"}, {"source_code": "const fs = require('fs');\r\n\r\nconst input = String(fs.readFileSync(0))\r\n .split('\\n')\r\n .filter(Boolean)\r\n .map((str) => str.trim());\r\n\r\nfor (let i = 1; i < input.length; i += 1) {\r\n const n = input[i];\r\n console.log(solve(parseInt(n)));\r\n}\r\n\r\nfunction solve(n) {\r\n let c1 = Math.floor(n / 3);\r\n let c2 = Math.floor(n / 3);\r\n\r\n while (c1 + 2 * c2 <= n) {\r\n if (c1 + 2 * c2 === n) {\r\n return `${c1} ${c2}`;\r\n }\r\n\r\n if (c1 + 1 + 2 * c2 === n) {\r\n return `${c1 + 1} ${c2}`;\r\n }\r\n\r\n if (c1 + 2 * (c2 + 1) === n) {\r\n return `${c1} ${c2 + 1}`;\r\n }\r\n\r\n c1 += 1;\r\n c2 += 1;\r\n }\r\n\r\n return 'error after';\r\n}"}, {"source_code": "let i = ''\r\nlet lines;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n lines = i.split('\\n'); // your input text, split by lines\r\n main();\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(lines.shift());\r\n\r\n while (t > 0) {\r\n const n = parseInt(lines.shift());\r\n let c1 = Math.floor(n / 3);\r\n let c2 = Math.floor(n / 3);\r\n switch (n % 3) {\r\n case 1:\r\n c1++;\r\n break;\r\n case 2:\r\n c2++;\r\n break;\r\n }\r\n console.log(c1, c2);\r\n t--;\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n var a = +lines[l++]\n console.log(solve(a))\n }\n});\n\nfunction solve(n) {\n const k = Math.floor(n / 3)\n const r = n % 3\n let a = k\n let b = k\n if (r === 1) {\n a++\n } else if (r === 2) {\n b++\n }\n return [a, b].join(' ')\n}\n"}, {"source_code": "function polycarp(input) {\n var c1 = Math.floor(input / 3);\n var c2 = c1;\n var rem = input % 3;\n if (rem == 2) c2++;\n else if (rem == 1) c1++;\n return `${c1} ${c2}`;\n}\n\nvar n = parseInt(readline());\nfor (var i = 0; i < n; i++) {\n var input = readline();\n print(polycarp(input));\n}\n"}, {"source_code": "function polycarp(input) {\n var c1 = Math.floor(input / 3);\n var c2 = c1;\n var rem = input % 3;\n if (rem == 2) c2++;\n else if (rem == 1) c1++;\n return `${c1} ${c2}`;\n}\n\nvar n = parseInt(readline());\nfor (var i = 0; i < n; i++) {\n var input = +readline();\n print(polycarp(input));\n}\n"}, {"source_code": "function polycarp(input) {\n var c1 = Math.floor(input / 3);\n var c2 = c1;\n var rem = input % 3;\n if (rem == 2) c2++;\n else if (rem == 1) c1++;\n return c1 + ' ' + c2; // `${c1} ${c2}`;\n}\n\nvar n = parseInt(readline());\nfor (var i = 0; i < n; i++) {\n var input = +readline();\n print(polycarp(input));\n}\n\n// var input = readline();\n// for(var i = 0; i < input; i ++) {\n// var num = +readline();\n// var c1 = c2 = Math.floor(num / 3);\n// if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n// print(c1 + ' ' + c2)\n// }\n"}, {"source_code": "var input = readline();\nfor(var i = 0; i < input; i ++) {\n var num = +readline();\n var c1 = c2 = Math.floor(num / 3);\n if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n print(`${c1} ${c2}`)\n}\n"}, {"source_code": "var input = readline();\nfor(var i = 0; i < input; i ++) {\n var num = +readline();\n var c1 = c2 = Math.floor(num / 3);\n if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n print(c1 + ' ' + c2)\n}\n"}, {"source_code": "var input = readline();\nfor(var i = 0; i < input; i ++) {\n var num = parseInt(readline());\n var c1 = c2 = Math.floor(num / 3);\n if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n print(c1 + ' ' + c2)\n}\n"}, {"source_code": "var input = readline();\nfor(var i = 0; i < input; i ++) {\n var num = readline();\n var c1 = c2 = Math.floor(num / 3);\n if(num % 3 > 0) num % 3 === 1 ? c1 ++ : c2 ++;\n print(c1 + ' ' + c2)\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let n = nextInt();\r\n let a = Math.floor(n / 3);\r\n let m = n % 3;\r\n let b = a + m;\r\n let c = a + 2;\r\n let d = b - 1;\r\n if (Math.abs(a - b) <= Math.abs(c - d)) {\r\n print(a, b);\r\n } else {\r\n print(c, d);\r\n }\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let n = nextInt();\r\n let a = n / 3;\r\n let m = n % 3;\r\n let b = a + m;\r\n let c = a + 2;\r\n let d = b - 1;\r\n if (Math.abs(a - b) <= Math.abs(c - d)) {\r\n print(a, b);\r\n } else {\r\n print(c, d);\r\n }\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nconst fs = require(\"fs\");\r\n\r\nconst _access = fs.createReadStream(\"input.txt\");\r\nprocess.stdin.read = _access.read.bind(_access);\r\n\r\nlet local = true;\r\nprocess.on(\"uncaughtException\", err => {\r\n local = false;\r\n});\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet _inputString = '';\r\nlet _currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n _inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n _inputString = _inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nconst readLine = () => _inputString[_currentLine++];\r\n\r\nconst nextIntArray = () => readLine.split(\" \").map(x => parseInt(x));\r\nconst nextFloatArray = () => readLine.split(\" \").map(x => parseFloat(x));\r\nconst nextInt = () => parseInt(readLine());\r\n\r\nconst gcd = (a, b) => a ? gcd(b % a, a) : b;\r\nconst lcm = (a, b) => a * b / gcd(a, b);\r\n\r\nfunction print(...args) {\r\n console.log(...args);\r\n}\r\n\r\nfunction solve() {\r\n let n = nextInt();\r\n let a = n / 3;\r\n let m = n % 3;\r\n let b = a + m;\r\n let c = a + 2;\r\n let d = b - 1;\r\n if (Math.abs(a - b) <= Math.abs(c - d)) {\r\n print(a, b);\r\n } else {\r\n print(c, d);\r\n }\r\n}\r\n\r\nfunction main() {\r\n let testCases = 1;\r\n testCases = parseInt(readLine());\r\n for (let i = 0; i < testCases; i++) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\n \nprocess.stdin.setEncoding('utf8');\n \nvar input = '';\n \nprocess.stdin.on('data' , data=>{\n input += data;\n});\nprocess.stdin.on('end' , ()=>{\n main(input);\n});\n \nfunction main(input) {\n input = input.split(\"\\n\");\n let z = 0;\n let testCases = parseInt(input[z++], 10);\n \n while(testCases--){\n let str = input[z++].trim().split('');\n solve(str)\n }\n}\n\nfunction solve(str){\n const sum = parseInt(str, 10);\n let count = Math.floor(sum / 3);\n\n const left = sum % 3\n\n if(left === 0){\n console.log(`${count} ${count}`);\n } else if(left === 1){\n console.log(`${count++} ${count}`);\n } else {\n console.log(`${count} ${count++}`);\n }\n\n\n}\n\n"}, {"source_code": "process.stdin.resume();\n \nprocess.stdin.setEncoding('utf8');\n \nvar input = '';\n \nprocess.stdin.on('data' , data=>{\n input += data;\n});\nprocess.stdin.on('end' , ()=>{\n main(input);\n});\n \nfunction main(input) {\n input = input.split(\"\\n\");\n let z = 0;\n let testCases = Number(input[z++]);\n \n while(testCases--){\n let str = input[z++].trim().split('');\n solve(str)\n }\n}\n\nfunction solve(str){\n const sum = Number(str);\n let count = Math.floor(sum);\n\n const left = sum % 3\n\n if(left === 0){\n console.log(`${count} ${count}`);\n } else if(left === 1){\n console.log(`${count++} ${count}`);\n } else {\n console.log(`${count} ${count++}`);\n }\n\n\n}\n\n"}, {"source_code": "// Common Template Starts //\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\"\r\nlet currentLine = 0\r\n\r\nprocess.stdin.on(\"data\", inputStdin => inputString += inputStdin)\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n // let a = readline().split(' ').map(Number)\r\n console.log(solve(n))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n) => { \r\n if ( n == 1 ) return '1 0'\r\n if ( n == 2 ) return '0 1'\r\n if ( n == 3 ) return '1 1'\r\n if ( n == 4 ) return '2 1'\r\n if ( n == 5 ) return '1 2'\r\n \r\n let twos1 = Math.floor( n / 3 )\r\n let ones1 = n - (twos1 * 2)\r\n let diff1 = Math.abs( ones1 - twos1 )\r\n \r\n let twos2 = Math.ceil( n / 3 )\r\n let ones2 = n - (twos2 * 2)\r\n let diff2 = Math.abs( ones2 - twos2 )\r\n\r\n return ( diff1 < diff2 ) ? twos1 + ' ' + ones1 : twos2 + ' ' + ones2\r\n}\r\n\r\nconst isOdd = (x) => { return x & 1 }\r\nconst isEven = (x) => { return !(x & 1) }\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j];\n var a = Math.floor(k / 3);\n var b = Math.floor(k / 3);\n console.log(a + ' ' + b);\n }\n});\n"}, {"source_code": "'use strict';\n\n// let env_local = true;\nlet env_local = false;\nlet inputString = '';\nlet currentLine = 0;\n\nif (!env_local) {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n process.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n });\n} else {\n const fs = require('fs');\n inputString = fs\n .readFileSync(__dirname + '/input.txt', 'utf-8')\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n main();\n}\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/*--------------------------------Play-ground---------------------------------------*/\n\nvar maxN = 2 * 1e5 + 10;\n\nvar mod = BigInt(1e9 + 7);\n\nfunction solve() {\n let n = parseInt(readline());\n let c1 = 0,\n c2 = 0;\n let y = parseInt(n / 3);\n c1 += y;\n c2 += y;\n let x = n % 3;\n\n if (x == 2) c2++;\n else c1++;\n console.log(`${c1} ${c2}`);\n}\n\nfunction main() {\n let t = parseInt(readline()) || 1;\n while (t--) {\n solve();\n }\n}\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 07/23/21 morning\r\n * https://codeforces.com/contest/1551/problem/A\r\n */\r\nconst solve = (x) => {\r\n pr(ce(x / 3), int(x / 3))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(Number(line));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var t = readline();\r\nwhile (t--) {\r\n var x = readline();\r\n var z = Math.round(x / 3);\r\n if (z + ((x - x / 3) / 2) * 2 !== x) {\r\n z += 1;\r\n }\r\n\r\n print(z + \" \" + Math.round((x - x / 3) / 2));\r\n}\r\n"}, {"source_code": "var t = readline();\r\nwhile (t--) {\r\n var x = readline();\r\n var z = Math.round(x / 3);\r\n if (z + ((x - x / 3) / 2) * 2 !== x) {\r\n z += 1;\r\n }\r\n\r\n print(z + \" \" + Number((x - x / 3) / 2));\r\n}\r\n"}, {"source_code": "var t = readline();\r\nwhile (t--) {\r\n var x = readline();\r\n var z = Math.round(x / 3);\r\n if (z + ((x - x / 3) / 2) * 2 !== x) {\r\n z += 1;\r\n }\r\n\r\n print(z + \" \" + (x - x / 3) / 2);\r\n}\r\n"}, {"source_code": "var t = readline();\r\nwhile(t--)\r\n{\r\n var n=readline();\r\n var c=Math.round(n/3);\r\n var p=c+1;\r\n var z=c-1;\r\n if(c*3===n)\r\n {\r\n print(c+\" \"+c);\r\n }\r\n else if(n-3*c==1)\r\n {\r\n print(p+\" \"+c);\r\n }\r\n else \r\n {\r\n print(z+\" \"+c);\r\n }\r\n}\r\n"}, {"source_code": "function solve()\r\n{\r\n\tvar a = +readline();\r\n\tvar z = Math.floor(a / 3);\r\n\tif(a % 3 === 0 )\r\n\tprint(z + \" \"+ z);\r\n\telse print ((z+1) + \" \"+ z)\r\n}\r\n \r\n\tvar n = +readline();\r\n\tfor (var i = 0; i < n; i++)\r\n\t\t\tsolve();\r\n"}, {"source_code": "n = readline(); b = Math.round(n / 3); a = n - 2*b; print(a + \" \" + b);"}], "src_uid": "71335a9489f0985f4e16435b14d6a34a"} {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = new Map();\nvar b = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.set(index, (a.get(index) || 0) + 1);\n});\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (currentValue !== b.get(index)) {\n ans.push(index);\n\n if (currentValue == 1) {\n a.delete(index);\n } else {\n a.set(index, currentValue - 1);\n }\n }\n});\n\nb = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\na.forEach(function(currentValue, index) {\n if (currentValue !== b.get(index)) {\n ans.push(index);\n\n if (currentValue == 1) {\n a.delete(index);\n } else {\n a.set(index, currentValue - 1);\n }\n }\n});\n\nwrite(ans.join('\\n'));\n", "positive_code": [{"source_code": "readline();\n\nvar a = readNums();\nvar b = readNums();\nprint(diff(a, b));\na = b;\nb = readNums();\nprint(diff(a, b));\n\nfunction diff(a, b) {\n var d = {};\n a.map(v => d[v] = (d[v] || 0) + 1);\n b.map(v => d[v] = (d[v] || 0) - 1);\n for (var k in d) {\n if (d[k])\n return k;\n }\n}\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0)\n}\n"}, {"source_code": "var n = parseInt(readline().trim())\nvar a = readline().trim().split(' ').map((x)=>parseInt(x))\nvar b = readline().trim().split(' ').map((x)=>parseInt(x))\nvar c = readline().trim().split(' ').map((x)=>parseInt(x))\n\nvar _sort=(_a,_b)=>_a-_b;\na.sort(_sort)\nb.sort(_sort)\nc.sort(_sort)\n\nvar _b=-1;\nfor(var i=0;iparseInt(x))\nvar b = readline().trim().split(' ').map((x)=>parseInt(x))\nvar c = readline().trim().split(' ').map((x)=>parseInt(x))\n\nvar _a={}, _b={}, _c={}\nfor(var i=0;iAA[c]--);\n\nvar f;\nfor (var i in AA)\n if (AA[i]) f=i;\n\nAA=new Array(A.length)\nfor (var i of A)\n AA[i] = (AA[i]||0)+1\n \nreadline().split(' ').map(Number).forEach(c=>AA[c]--);\nAA[f]--;\nvar ff;\nfor (var i in AA) {\n if (AA[i]) ff=i;\n}\n\nprint(f)\nprint(ff)\n"}, {"source_code": "function main(a, b, c) {\n var output = '';\n var aValues = sum(a);\n var bValues = sum(b);\n var cValues = sum(c);\n\n output += aValues - bValues + '\\n';\n output += bValues - cValues;\n\n return output;\n}\n\nfunction sum(array) {\n var sumResult = 0;\n for (var i = array.length; i--;) {\n sumResult += array[i]; \n }\n\n return sumResult;\n}\n\nvar n = readline();\nvar input = [];\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\n\nprint(main(input[0], input[1], input[2]));"}, {"source_code": "function main(a, b, c) {\n var output = '';\n var aValues = a.reduce(function(x, y) { return x + y }, 0);\n var bValues = b.reduce(function(x, y) { return x + y }, 0);\n var cValues = c.reduce(function(x, y) { return x + y }, 0);\n\n output += aValues - bValues + '\\n';\n output += bValues - cValues;\n\n return output;\n}\n\nvar n = readline();\nvar input = [];\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\n\nprint(main(input[0], input[1], input[2]));"}, {"source_code": "str = Number(readline());\nfirst = readline().split(' ').map(Number);\nsecond = readline().split(' ').map(Number);\nthird = readline().split(' ').map(Number);\n\nfirst.sort();\nsecond.sort();\nthird.sort();\n\nfor (var i = 0, j = 0, k = 0; i < first.length; i++) {\n if (first[i] == second[j] && first[i] == third[k]) {j++; k++;}\n else if ((first[i] == second[j]) && (first[i] != third[k])) {si = first[i]; j++;}\n else if ((first[i] != second[j]) && (first[i] != third[k])) {fi = first[i];}\n \n}\n\nwrite(fi + '\\n' + si);"}, {"source_code": "function main(a, b, c) {\n var output = '';\n var aValues = cacheValues(a);\n var bValues = cacheValues(b);\n var cValues = cacheValues(c);\n\n output += compare(aValues, bValues) + '\\n';\n output += compare(bValues, cValues);\n\n return output;\n}\n\nfunction cacheValues(values) {\n var cachedValues = [];\n\n for(var i = 0; i < values.length; i++) {\n if (!cachedValues[`n${values[i]}`]) {\n cachedValues[`n${values[i]}`] = 1;\n } else {\n cachedValues[`n${values[i]}`]++;\n }\n }\n\n return cachedValues;\n}\n\nfunction compare(a, b) {\n var differ = 0;\n\n for (key in a) {\n if(a[key] !== b[key]) {\n differ = parseInt(key.slice(1));\n break;\n }\n }\n\n return differ;\n}\n\nvar n = readline();\nvar input = [];\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\ninput.push(readline().split(' ').map(function(v) { return parseInt(v); }));\n\nprint(main(input[0], input[1], input[2]));"}, {"source_code": "function sum(array){\t\t\t//\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\n\tvar result = 0;\n\tfor(var i = 0; i < array.length; i++){\n\t\tresult += +array[i];\n\t}\n\treturn result;\n}\n \nvar n = +readline(), a = sum(readline().split(\" \")), b = sum(readline().split(\" \")), c = sum(readline().split(\" \"));\n \nwrite((a-b) + \"\\n\" + (b-c));\n"}, {"source_code": "function sum(array) {\n var sumResult = 0;\n for (var i = array.length; i--;) {\n sumResult += +array[i]; \n }\n\n return sumResult;\n}\n\nvar n = readline();\na = readline().split(' ');\nb = readline().split(' ');\nc = readline().split(' ');\n\nvar bValues = sum(b);\nprint((sum(a) - bValues) + '\\n' + (bValues - sum(c)));"}, {"source_code": "Array.prototype.toMap = function toMap() {\n var resultMap = {};\n this.forEach(function(value, index) {\n if(resultMap[value]) {\n resultMap[value] += 1;\n } else {\n resultMap[value] = 1;\n }\n });\n return resultMap;\n};\n\nfunction main() {\n var errorCount = readline(),\n fstErrorList = readline().split(/\\s/).map(Number),\n fstErrorMap = fstErrorList.toMap(),\n sndErrorList = readline().split(/\\s/).map(Number),\n sndErrorMap = sndErrorList.toMap(),\n trdErrorMap = readline().split(/\\s/).map(Number).toMap(),\n result = [];\n\n // console.log('%o, %o, %o', fstErrorMap, sndErrorMap, trdErrorMap);\n\n fstErrorList.some(function(errorLine) {\n if(fstErrorMap[errorLine] != sndErrorMap[errorLine]) {\n result.push(errorLine);\n return true;\n }\n });\n\n sndErrorList.some(function(errorLine) {\n if(sndErrorMap[errorLine] != trdErrorMap[errorLine]) {\n result.push(errorLine);\n return true;\n }\n });\n\n print(result.join('\\n'));\n};\n\nmain();"}, {"source_code": "function sum(array) {\n var sumResult = 0;\n\n var i = 0;\n var l = array.length;\n for (i = l; i--;) {\n sumResult += +array[i]; \n }\n\n return sumResult;\n}\n\nreadline();\nvar aValues = sum(readline().split(' '));\nvar bValues = sum(readline().split(' '));\nprint((aValues - bValues) + '\\n' + (bValues - sum(readline().split(' '))));"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline().split(' ').map(x => parseInt(x));\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\nfirstErrors.sort((a,b) => a-b);\nsecondErrors.sort((a,b) => a-b);\nthirdErrors.sort((a,b) => a-b);\nvar errors = [];\nvar somethingChanged = false;\nfor (var i = 0; i < limit - 1; i++) {\n if (secondErrors[i] !== firstErrors[i]) {\n errors.push(firstErrors[i]);\n somethingChanged = true;\n break;\n }\n}\nif (!somethingChanged) errors.push(firstErrors[limit-1]);\nsomethingChanged = false;\nfor (var j = 0; j < limit - 2; j++) {\n if (thirdErrors[j] !== secondErrors[j]) {\n errors.push(secondErrors[j])\n somethingChanged = true;\n break;\n }\n}\nif (!somethingChanged) errors.push(secondErrors[limit-2]);\nfor (var k = 0; k < errors.length; k++) print(errors[k]);\n\n"}, {"source_code": "var n=Number(readline());\nvar arr=readline().split(\" \");\narr.sort();\nvar arr1=readline().split(\" \");\narr1.sort();\nvar flag1=false;\nfor(var i=0;i(Number(x)+Number(y)));\nvar str2 = readline().split(\" \").reduce((x,y)=>(Number(x)+Number(y)));\nvar str3 = readline().split(\" \").reduce((x,y)=>(Number(x)+Number(y)));\n\nprint(str1-str2);\nprint(str2-str3);"}, {"source_code": "var nums = readNums();\n\nvar arr1 = readNums();\nvar arr2 = readNums();\nvar arr3 = readNums();\n\narr1.sort(function(a,b){return b-a});\narr2.sort(function(a,b){return b-a});\narr3.sort(function(a,b){return b-a});\n\nvar k = 0;\n\nfor (var i = 0; i arr2[i]) {\n print(arr1[i]);\n k = 1;\n break;\n }\n}\n\nif (k == 0 && arr1[arr1.length-1] <= arr2[arr2.length-1]) {\n print(arr1[arr1.length-1]);\n}\n\nvar l = 0;\n\nfor (var i = 0; i arr3[i]) {\n print(arr2[i]);\n l = 1;\n break;\n }\n}\n\nif (l == 0 && arr2[arr2.length-1] <= arr3[arr3.length-1]) {\n print(arr2[arr2.length-1]);\n}\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN().sortLt();\n var B = rdArN().sortLt();\n var C = rdArN().sortLt();\n for (var i = 0; i < A.length; ++i) {\n if (A[i] !== B[i]) {\n pr(A[i]);\n break;\n }\n }\n for (var i = 0; i < B.length; ++i) {\n if (B[i] !== C[i]) {\n pr(B[i]);\n break;\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline().split(' ').map(x => parseInt(x));\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\nfirstErrors.sort((a,b) => a-b);\nsecondErrors.sort((a,b) => a-b);\nthirdErrors.sort((a,b) => a-b);\nvar errors = [];\nvar somethingChanged = false;\nfor (var i = 0; i < limit - 1; i++) {\n if (secondErrors[i] !== firstErrors[i]) {\n errors.push(firstErrors[i]);\n somethingChanged = true;\n break;\n }\n}\nif (!somethingChanged) errors.push(firstErrors[limit-1]);\nsomethingChanged = false;\nfor (var j = 0; j < limit - 2; j++) {\n if (thirdErrors[j] !== secondErrors[j]) {\n errors.push(secondErrors[j])\n somethingChanged = true;\n break;\n }\n}\nif (!somethingChanged) errors.push(secondErrors[limit-2]);\nfor (var k = 0; k < errors.length; k++) print(errors[k]);\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN().sortLt();\n var B = rdArN().sortLt().concat([null]);\n var C = rdArN().sortLt().concat([null, null]);\n for (var i = 0; i < A.length; ++i) {\n if (A[i] !== B[i]) {\n pr(A[i]);\n break;\n }\n }\n for (var i = 0; i < B.length; ++i) {\n if (B[i] !== C[i]) {\n pr(B[i]);\n break;\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const set = new Set();\n\n const f1 = input[1].split(' ').map(x => parseInt(x));\n const f2 = input[2].split(' ').map(x => parseInt(x));\n const f3 = input[3].split(' ').map(x => parseInt(x));\n\n f1.sort((a, b) => a - b);\n f2.sort((a, b) => a - b);\n f3.sort((a, b) => a - b);\n\n const answ = [];\n for (let i = 0; i < f1.length; i += 1) {\n if (f1[i] !== f2[i]) {\n answ.push(f1[i]); break;\n }\n if (i + 1 === f2.length) { answ.push(f1.pop()); break; }\n }\n\n for (let i = 0; i < f2.length; i += 1) {\n if (f2[i] !== f3[i]) {\n answ.push(f2[i]); break;\n }\n\n if (i + 1 === f3.length) { answ.push(f2.pop()); break; }\n }\n\n answ.forEach(x => console.log(x));\n}); "}, {"source_code": "var readline = (function () {\n var lines = require(\"fs\")\n .readFileSync(0, \"utf-8\")\n .split(\"\\n\");\n var i = 0;\n return function () { return lines[i++]; };\n})();\nvar initialErrors = parseInt(readline());\nvar first = readline()\n .split(\" \")\n .map(function (v) { return parseInt(v); })\n .sort();\nvar second = readline()\n .split(\" \")\n .map(function (v) { return parseInt(v); })\n .sort();\nvar third = readline()\n .split(\" \")\n .map(function (v) { return parseInt(v); })\n .sort();\nvar hasFirst = false;\nvar hasSecond = false;\nvar firstError = 0;\nvar secondError = 0;\nfor (var i = 0; i < initialErrors && !(hasFirst && hasSecond); i++) {\n if (!hasFirst) {\n if (first[i] !== second[i]) {\n hasFirst = true;\n firstError = first[i];\n }\n }\n if (!hasSecond) {\n if (second[i] !== third[i]) {\n hasSecond = true;\n secondError = second[i];\n }\n }\n}\nconsole.log(firstError);\nconsole.log(secondError);\n"}, {"source_code": "readline()\nA=readline().split(' ').map(Number).reduce((a,c)=>{ a[c]=(a[c]||0)+1; return a; },{});\nB=Object.assign({},A)\nreadline().split(' ').map(Number).forEach(c=>A[c]--);\nvar f;\nfor (i of Object.keys(A))\n if (A[i]) f=i;\n\nreadline().split(' ').map(Number).forEach(c=>B[c]--);\nB[f]--;\nvar ff;\nfor (i of Object.keys(B))\n if (B[i]) ff=i;\n\nprint(f)\nprint(ff)\n"}, {"source_code": "function sum(array){\t\t\t//\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\n\tvar result = 0;\n\tfor(var i = 0; i < array.length; i++){\n\t\tresult += +array[i];\n\t}\n\treturn result;\n}\n\nvar n = +readline(), a = sum(readline().split(\" \")), b = sum(readline().split(\" \")), c = sum(readline().split(\" \"));\n\nwrite((a-b) + \"\\n\" + (b-c));"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdin = '';\n\nprocess.stdin.on('data', (input) => {\n stdin += input;\n});\n\nprocess.stdin.on('end', () => {\n const data = stdin.split('\\n');\n data.shift();\n\n const sum = [0, 0, 0];\n\n data.forEach((errors, i) => {\n errors.split(' ').forEach((value) => {\n sum[i] += Number(value);\n });\n });\n\n process.stdout.write(`${sum[0] - sum[1]}\\n${sum[1] - sum[2]}`);\n});\n"}, {"source_code": "readline()\nA=readline().split(' ').map(Number).reduce((a,c)=>{ a[c]=(a[c]||0)+1; return a; },{});\nB=Object.assign({},A)\nreadline().split(' ').map(Number).forEach(c=>A[c]--);\nvar f;\nfor (i of Object.keys(A))\n if (A[i]) f=i;\n\nreadline().split(' ').map(Number).forEach(c=>B[c]--);\nB[f]--;\nvar ff;\nfor (i of Object.keys(B))\n if (B[i]) ff=i;\n\nprint(f)\nprint(ff)\n//print(JSON.stringify(A))\n//print(JSON.stringify(B))\n\n"}], "negative_code": [{"source_code": "str = Number(readline());\nfirst = readline().split(' ').map(Number);\nsecond = readline().split(' ').map(Number);\nthird = readline().split(' ').map(Number);\nfirst.sort();\nthird.sort();\nvar si = 0, fi = 0;\nfor (var i = 0, j = 0; i < first.length; i++)\n if (third[j] === first[i]) {j++}\n else {\n if (second.indexOf(first[i]) >= 0) si = first[i];\n else fi = first[i];\n }\nwrite(fi + '\\n' + si);"}, {"source_code": "str = Number(readline());\nfirst = readline().split(' ').map(Number);\nsecond = readline().split(' ').map(Number);\nthird = readline().split(' ').map(Number);\nfirst.sort(function(a,b) {return a - b});\nthird.sort(function(a,b) {return a - b});\nvar si = 0, fi = 0;\nfor (var i = 0, j = 0; i < first.length; i++)\n if (third[j] === first[i]) {j++}\n else {\n if (second.indexOf(first[i]) >= 0) si = first[i];\n else fi = first[i];\n }\nwrite(fi + '\\n' + si);"}, {"source_code": "str = Number(readline());\nfirst = readline().split(' ').map(Number);\nsecond = readline().split(' ').map(Number);\nthird = readline().split(' ').map(Number);\nvar mem1 = [], mem2 = [];\nvar si = [], fi = [];\nfor (var i = 0; i < first.length; i++) {\n mem1[first[i]] = mem1[first[i]] + 1 || 1;\n}\n\nfor (var i = 0; i < second.length; i++) {\n mem1[second[i]]--;\n mem2[second[i]] = mem2[second[i]] + 1 || 1;\n}\n\nfor (var i = 0; i < third.length; i++) {\n mem2[third[i]]--;\n}\n\nfor (var i = 0; i < mem1.length; i++) {\n if (mem1[i] !== 0) fi = i;\n if (mem2[i] !== 0) si = i;\n}\n\nwrite(fi + '\\n' + si);"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = [];\nvar b = new Map();\nvar c = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.push(index);\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nreadline();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n c.set(index, (c.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (b.get(index) !== c.get(index)) {\n ans.push(index);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = new Map();\nvar b = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.set(index, (a.get(index) || 0) + 1);\n});\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (currentValue !== b.get(index)) {\n ans.push(index);\n a.delete(index);\n }\n});\n\nb = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\na.forEach(function(currentValue, index) {\n if (currentValue !== b.get(index)) {\n ans.push(index);\n a.delete(index);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = [];\nvar b = new Map();\nvar c = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.push(currentValue);\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nreadline();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n c.set(index, (c.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (b.get(index) !== c.get(index)) {\n ans.push(index);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = [];\nvar b = new Map();\nvar c = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.push(index);\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nreadline();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n c.set(index, (c.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue) {\n if (b.get(currentValue) !== c.get(currentValue)) {\n ans.push(currentValue);\n\n b.delete(currentValue);\n c.delete(currentValue);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = new Map();\nvar b = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.set(index, (a.get(index) || 0) + 1);\n});\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (b.get(index) !== currentValue) {\n ans.push(index);\n }\n});\n\nb = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n b.set(index, (b.get(index) || 0) + 1);\n});\n\na.forEach(function(currentValue, index) {\n if (ans[0] !== currentValue && b.get(index) !== currentValue) {\n ans.push(index);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return '1 4 3 3 5 7';\n case 3: return '3 7 5 4 3';\n case 4: return '4 3 7 5';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = new Map();\nvar c = new Map();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n a.set(index, (a.get(index) || 0) + 1);\n});\n\nreadline();\n\nreadline().split(' ').forEach(function(currentValue) {\n var index = +currentValue;\n c.set(index, (c.get(index) || 0) + 1);\n});\n\nvar ans = [];\n\na.forEach(function(currentValue, index) {\n if (c.get(index) !== a.get(index)) {\n ans.push(index);\n }\n});\n\nwrite(ans.join('\\n'));\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nvar mapCopy = new Map(map);\nfor (var j = 0; j < limit - 2; j++) {\n map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next();\n if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {\n var n = map.get(key) - mapCopy.get(key);\n n = n === 0 ? 1 : n;\n while (n) {\n n--\n errors.push(key);\n }\n }\n}\nfor (var e = 0; e < errors.length; e++) print(errors[e]);\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nvar mapCopy = new Map(map);\nfor (var j = 0; j < limit - 2; j++) {\n mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next().value;\n if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {\n var n = map.get(key) - mapCopy.get(key);\n n = n === 0 ? 1 : n;\n while (n) {\n n--\n errors.push(key);\n }\n }\n}\nfor (var e = 0; e < errors.length; e++) print(errors[e]);\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nfor (var j = 0; j < limit - 2; j++) {\n map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);\n if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next().value;\n print(key);\n}\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nfor (var j = 0; j < limit - 2; j++) {\n map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);\n if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next().value;\n if (limit === 10) print(keys);\n print(key);\n}\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nfor (var j = 0; j < limit - 2; j++) {\n map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);\n if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next().value;\n if (limit === 10) print([...keys]);\n print(key);\n}\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nvar mapCopy = new Map(map);\nfor (var j = 0; j < limit - 2; j++) {\n map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next();\n print(key);\n if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {\n var n = map.get(key) - mapCopy.get(key);\n n = n === 0 ? 1 : n;\n while (n) {\n n--\n errors.push(key);\n }\n }\n}\nfor (var e = 0; e < errors.length; e++) print(errors[e]);\n"}, {"source_code": "var limit = parseInt(readline());\nvar firstErrors = readline().split(' ').map(x => parseInt(x));\nvar secondErrors = readline();\nvar thirdErrors = readline().split(' ').map(x => parseInt(x));\n// *************SORTING SOLUTION *****************************\n// firstErrors.sort((a,b) => a-b);\n// secondErrors.sort((a,b) => a-b);\n// thirdErrors.sort((a,b) => a-b);\nvar errors = [];\n// var somethingChanged = false;\n// for (var i = 0; i < limit - 1; i++) {\n// if (secondErrors[i] !== firstErrors[i]) {\n// errors.push(firstErrors[i]);\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(firstErrors[limit-1]);\n// somethingChanged = false;\n// for (var j = 0; j < limit - 2; j++) {\n// if (thirdErrors[j] !== secondErrors[j]) {\n// errors.push(secondErrors[j])\n// somethingChanged = true;\n// break;\n// }\n// }\n// if (!somethingChanged) errors.push(secondErrors[limit-2]);\n// for (var k = 0; k < errors.length; k++) print(errors[k]);\n// **********************MAP SOLUTION *************************\nvar map = new Map();\nfor (var i = 0; i < limit; i++) {\n if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);\n else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);\n}\nvar mapCopy = new Map(map);\nfor (var j = 0; j < limit - 2; j++) {\n mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);\n}\nvar keys = map.keys();\nvar key;\nfor (var k = 0; k < map.size; k++) {\n key = keys.next().value;\n if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {\n var n = map.get(key) - mapCopy.get(key);\n n = n === 0 ? 1 : n;\n while (n) {\n n--\n if (errors.length && errors[0] > key) {\n errors[1] = errors[0];\n errors[0] = key;\n } else errors.push(key);\n }\n }\n}\nfor (var e = 0; e < errors.length; e++) print(errors[e]);\n"}, {"source_code": "process.stdout.write('a');"}, {"source_code": "var n = +readline(), a = readline().split(\" \");\nreadline();\nvar c = readline().split(\" \"), k = [];\n\na.forEach(function(error, i){\n\tvar index = c.indexOf(error);\n\tif(index + 1){\n\t\tdelete c[index];\n\t}\n\telse{\n\t\tk.push(i);\n\t}\n});\n\nwrite(a[k[0]] + \"\\n\" + a[k[1]]);"}, {"source_code": "var n = +readline(), a = readline().split(\" \");\nreadline();\nvar c = readline().split(\" \"), k = [];\n\na.forEach(function(error, i){\n\tvar index = c.indexOf(error);\n\tif(index + 1){\n\t\tdelete c[index];\n\t}\n\telse{\n\t\tk.push(i);\n\t}\n});\n\nwrite( (a[k[0]] > a[k[1]]) ? (a[k[1]] + \"\\n\" + a[k[0]]) : (a[k[0]] + \"\\n\" + a[k[1]]) );"}, {"source_code": "(function () {\n\t'use strict';\n\n\tvar n = parseInt(readline()),\n\t\ta = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),\n\t\tb = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),\n\t\tc = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });\n\n\tprint((function () {\n\t\tfor (var i = 0, _i = b.length; i < _i; i++)\n\t\t\tif (a[i] !== b[i]) return a[i];\n\t\treturn a.pop()[0];\n\t})());\n\n\tprint((function () {\n\t\tfor (var i = 0, _i = c.length; i < _i; i++)\n\t\t\tif (b[i] !== c[i]) return b[i];\n\t\treturn b.pop()[0];\n\t})());\n\n}).call(this);\n"}, {"source_code": "(function () {\n\t'use strict';\n\n\tvar n = parseInt(readline()),\n\t\ta = readline().split(' '),\n\t\tb = readline().split(' '),\n\t\tc = readline().split(' ');\n\n\tprint((function () {\n\t\tfor (var i = 0; i < a.length; i++)\n\t\t\tif (b.indexOf(a[i]) === -1)\n\t\t\t\treturn a[i];\n\t})());\n\n\tprint((function () {\n\t\tfor (var i = 0; i < b.length; i++)\n\t\t\tif (c.indexOf(b[i]) === -1)\n\t\t\t\treturn b[i];\n\t})());\n\n}).call(this);\n"}, {"source_code": "function sum(array) {\n var sumResult = 0;\n\n var i = 0;\n var l = array.length;\n for (i = l; i--;) {\n sumResult += +array[i]; \n }\n\n return sumResult;\n}\n\nreadline();\nvar bValues = sum(readline().split(' '));\nprint((sum(readline().split(' ')) - bValues) + '\\n' + (bValues - sum(readline().split(' '))));"}, {"source_code": "function main(a, b, c) {\n var output = '';\n var aValues = sum(a);\n var bValues = sum(b);\n var cValues = sum(c);\n\n output += aValues - bValues + '\\n';\n output += bValues - cValues;\n\n return output;\n}\n\nfunction sum(array) {\n var sumResult = 0;\n for (var i = array.length; i--;) {\n sumResult += array[i]; \n }\n\n return sumResult;\n}"}, {"source_code": "var nums = readNums();\n\nvar arr1 = readNums();\nvar arr2 = readNums();\nvar arr3 = readNums();\n\narr1.sort(function(a,b){return b-a});\narr2.sort(function(a,b){return b-a});\narr3.sort(function(a,b){return b-a});\n\nfor (var i = 0; i arr2[i]) {\n print(arr1[i]);\n break;\n }\n}\n\nif (arr1[arr1.length-1] <= arr2[arr2.length-1]) {\n print(arr1[arr1.length-1]);\n}\n\nfor (var i = 0; i arr3[i]) {\n print(arr2[i]);\n break;\n }\n}\n\nif (arr2[arr2.length-1] <= arr3[arr3.length-1]) {\n print(arr2[arr2.length-1]);\n}\n\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n rdN();\n var A = rdArN();\n var B = rdArN();\n var C = rdArN();\n var ABC = [...A, ...B, ...C];\n var M = {};\n for (var i = 0; i < ABC.length; ++i) {\n var value = ABC[i];\n M[value] = ++M[value] || 1;\n }\n for (var key in M) {\n var count = M[key];\n if (count%3 === 1) {\n pr(key);\n }\n }\n for (var key in M) {\n var count = M[key];\n if (count%3 === 2) {\n pr(key);\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "1985566215ea5a7f22ef729bac7205ed"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], m = integers[1], k = integers[2];\n\n\tvar maze = [], distances = [];\n\tvar startR = -1, startC = -1;\n\tvar inf = n*m;\n\tfor (var r = 0; r < n; r += 1) {\n\t\tmaze.push(readline());\n\t\tdistances.push([]);\n\t\tfor (var c = 0; c < m; c += 1) {\n\t\t\tdistances[r].push(inf);\n\t\t\tif (maze[r][c] == '.') {\n\t\t\t\tstartR = r;\n\t\t\t\tstartC = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tdistances[startR][startC] = 0;\n\tvar queue = [{r: startR, c: startC}];\n\tvar dr = [-1, 0, 1, 0], dc = [0, 1, 0, -1];\n\twhile (queue.length != 0) {\n\t\tvar r = queue[0].r, c = queue[0].c;\n\t\tqueue = queue.slice(1);\n\t\tvar distance = distances[r][c] + 1;\n\t\tfor (var i = 0; i < 4; i += 1) {\n\t\t\tvar nextR = r + dr[i], nextC = c + dc[i];\n\t\t\tif (nextR >= 0 && nextR < n && nextC >= 0 && nextC < m &&\n\t\t\t\t\tmaze[nextR][nextC] == '.' &&\n\t\t\t\t\tdistance < distances[nextR][nextC]) {\n\t\t\t\tdistances[nextR][nextC] = distance;\n\t\t\t\tqueue.push({r: nextR, c: nextC});\n\t\t\t}\n\t\t}\n\t}\n\n\tvar records = [];\n\tfor (var r = 0; r < n; r += 1) {\n\t\tfor (var c = 0; c < m; c += 1) {\n\t\t\tif (distances[r][c] < inf) {\n\t\t\t\trecords.push({distance: distances[r][c], r: r, c: c});\n\t\t\t}\n\t\t}\n\t}\n\trecords.sort(function(a, b) {\n\t\treturn b.distance - a.distance;\n\t});\n\n\tfor (var i = 0; i < k; i += 1) {\n\t\tvar r = records[i].r, c = records[i].c;\n\t\tvar line = maze[r];\n\t\tmaze[r] = line.slice(0, c) + 'X' + line.slice(c+1);\n\t}\n\n\tfor (var r = 0; r < n; r += 1) {\n\t\tprint(maze[r]);\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "var input = readline().split(' ');\n var INF = 1000000000;\n var n=parseInt(input[0]),\n m=parseInt(input[1]),\n k=parseInt(input[2]);\n\n var labirinth = [], buf = [];\n for(var i=0; i=0 && y=0 && x=0 && y=0 && x1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = false;\n\nclass DSU {\n constructor(n){\n this.parents = new Array(n).fill(0);\n this.rank = new Array(n).fill(0);\n for (let i=0; i{\n // READING:\n let [n, d] = ra();\n LT({n, d});\n let A = [];\n for (let i=0; isizes[b]-sizes[a]);\n //L({I, extra, sets, sizes})\n let res = 0;\n for (let i=0; i<=extra && i stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nclass dsu {\r\n\tconstructor (n) {\r\n\t\tthis.components = n;\r\n\t\tthis.data = Array(n).fill(-1);\r\n\t}\r\n\tunite (a, b) {\r\n\t\t// BEWARE: don't pass undefined values\r\n\t\ta = this.find(a);\r\n\t\tb = this.find(b);\r\n\t\tif (a == b) return;\r\n\t\tthis.data[a] += this.data[b];\r\n\t\tthis.data[b] = a;\r\n\t\tthis.components--;\r\n\t}\r\n\tfind (a) {\r\n\t\treturn this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);\r\n\t}\r\n\tsize (a) {\r\n\t\treturn -this.data[this.find(a)];\r\n\t}\r\n\tgetcomponents () {\r\n\t\treturn this.components;\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tlet [n, d] = rna();\r\n\r\n\tconst a = new dsu(n);\r\n\tlet extras = 0;\r\n\twhile (d--) {\r\n\t\tlet [x, y] = rna(); x--, y--;\r\n\r\n\t\tif (a.find(x) == a.find(y)) { \r\n\t\t\textras++;\r\n\t\t} else {\r\n\t\t\ta.unite(x, y);\r\n\t\t}\r\n\r\n\t\tconst sizes = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a.find(i) == i) {\r\n\t\t\t\tsizes.push(a.size(i));\r\n\t\t\t}\r\n\t\t}\r\n\t\tsizes.sort((x, y) => y - x);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < extras + 1; i++) {\r\n\t\t\tsum += sizes[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(sum - 1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nclass dsu {\r\n\tconstructor (n) {\r\n\t\tthis.components = n;\r\n\t\tthis.data = Array(n).fill(-1);\r\n\t}\r\n\tunite (a, b) {\r\n\t\t// BEWARE: don't past undefined values\r\n\t\ta = this.find(a);\r\n\t\tb = this.find(b);\r\n\t\tif (a == b) return;\r\n\t\tthis.data[a] += this.data[b];\r\n\t\tthis.data[b] = a;\r\n\t\tthis.components--;\r\n\t}\r\n\tfind (a) {\r\n\t\treturn this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);\r\n\t}\r\n\tsize (a) {\r\n\t\treturn -this.data[this.find(a)];\r\n\t}\r\n\tgetcomponents () {\r\n\t\treturn this.components;\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tconst [n, d] = rna();\r\n\r\n\tconst a = new dsu(n);\r\n\tlet extras = 0;\r\n\tfor (let i = 0; i < d; i++) {\r\n\t\tlet [x, y] = rna(); x--, y--;\r\n\r\n\t\tif (a.find(x) == a.find(y)) { \r\n\t\t\textras++;\r\n\t\t} else {\r\n\t\t\ta.unite(x, y);\r\n\t\t}\r\n\r\n\t\tconst sizes = [];\r\n\t\tfor (let j = 0, visited = []; j < n; j++) {\r\n\t\t\tconst cur = a.find(j);\r\n\t\t\tif (visited[cur]) continue;\r\n\t\t\tvisited[cur] = 1;\r\n\t\t\tsizes.push(a.size(cur));\r\n\t\t}\r\n\r\n\t\tsizes.sort((x, y) => y - x);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let j = 0; j < extras + 1; j++) {\r\n\t\t\tsum += sizes[j];\r\n\t\t}\r\n\r\n\t\tconsole.log(sum- 1);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "29bc7a22baa3dc6bb508b00048e50114"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let cnt = 0;\r\n if((n===3)&&(arr[1]%2===1)){\r\n console.log(-1);\r\n continue;\r\n } \r\n let ans = false;\r\n for(let i=1;i1) {\r\n ans = true;\r\n break;\r\n }\r\n }\r\n if(!ans){\r\n console.log(-1);\r\n continue;\r\n }\r\n for(let i=1;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n //Write your code here\r\n const t = parseInt(readline());\r\n for(let i = 0; i < t; i++){\r\n const n = parseInt(readline());\r\n const arr = readline().split(\" \").map((v)=>parseInt(v));\r\n let ret = 0;\r\n if(arr.slice(1,arr.length-1).every(v=>v==1)){\r\n console.log(-1);\r\n continue;\r\n }\r\n if(arr.length==3){\r\n console.log(arr[1]%2==0?arr[1]/2:-1)\r\n continue;\r\n } else {\r\n for(let i = 1; i < arr.length-1; i++){\r\n if(arr[i])\r\n ret+=arr[i]%2==0?arr[i]/2:(arr[i]+1)/2;\r\n }\r\n }\r\n console.log(ret);\r\n }\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tif (Math.max(...a.slice(1, n-1)) == 1 || n == 3 && a[1]&1) {\r\n\t\t\tans = -1;\r\n\t\t} else {\r\n\t\t\tfor (let i = 1; i < n-1; i++) {\r\n\t\t\t\tans += Math.ceil(a[i]/2);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet sum = 0, odds = 0;\r\n\t\tfor (let i = 1; i < n-1; i++) {\r\n\t\t\tsum += a[i];\r\n\t\t\todds += a[i]&1;\r\n\t\t}\r\n\r\n\t\tif ((n==3 && sum&1) || sum == n-2) {\r\n\t\t\tconsole.log(-1);\r\n\t\t} else {\r\n\t\t\tconsole.log(Math.floor(sum/2) + Math.ceil(odds/2));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "5b99775142b4a28b6b1069367602448f"} {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return +readline(); }\n\nvar inp = rda(), n = inp[0], m = inp[1];\ndelete inp;\n\nvar ver = [], hor = [];\nfor(var i = 1; i <= n; i++){\n ver[i] = 0;\n hor[i] = 0;\n}\n\nvar total = n*n;\nvar v = 0, h = 0;\nvar ans = [];\nfor(var i = 0; i < m; i++){\n var inp = rda(), x = inp[0], y = inp[1];\n delete inp;\n\n if(hor[x] == 0){\n hor[x] = 1;\n h++;\n }\n if(ver[y] == 0){\n ver[y] = 1;\n v++;\n }\n ans.push( total - (h*n + v*n - v*h) );\n}\n\nwrite(ans.join(\" \"));", "positive_code": [{"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = parseInt(nm[0]);\nvar m = parseInt(nm[1]);\n\n//var n = 5;\n//var m = 2;\n//var a = [[1, 5], [5, 1]];\n\n//var n = 3;\n//var m = 3;\n//var a = [[1, 1], [3, 1], [2, 2]];\n\n//var n = 100000;\n//var m = 1;\n//var a = [[300, 400]];\n\n//var n = 2;\n//var m = 2;\n//var a = [[1, 1], [1, 2]];\n\nvar rows = {};\nvar cols = {};\n\nvar rowsCount = 0;\nvar colsCount = 0;\n\nvar t = n * n;\nvar results = [];\n\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (rows[x] == undefined) {\n ++rowsCount;\n t -= (n - colsCount);\n }\n\n if (cols[y] == undefined) {\n ++colsCount;\n t -= (n - rowsCount);\n }\n\n results.push(t);\n\n rows[x] = 1;\n cols[y] = 1;\n}\n\nprint(results.join(\" \"));\n//console.log(results.join(\" \"));\n"}, {"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = parseInt(nm[0]);\nvar m = parseInt(nm[1]);\n\n//var n = 5;\n//var m = 2;\n//var a = [[1, 5], [5, 1]];\n\n//var n = 3;\n//var m = 3;\n//var a = [[1, 1], [3, 1], [2, 2]];\n\n//var n = 100000;\n//var m = 1;\n//var a = [[300, 400]];\n\n//var n = 2;\n//var m = 2;\n//var a = [[1, 1], [1, 2]];\n\nvar rows = {};\nvar cols = {};\n\nvar rowsCount = 0;\nvar colsCount = 0;\n\nvar t = n * n;\n//var results = [];\n\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (rows[x] == undefined) {\n ++rowsCount;\n t -= (n - colsCount);\n }\n\n if (cols[y] == undefined) {\n ++colsCount;\n t -= (n - rowsCount);\n }\n\n //results.push(t);\n write(t+\" \");\n\n rows[x] = 1;\n cols[y] = 1;\n}\n\n//print(results.join(\" \"));\n//console.log(results.join(\" \"));\n"}, {"source_code": "var nm = readline().split(' ').map(\n\tfunction(x){\n\t\treturn parseInt(x);\n\t}\n);\nvar n = nm[0];\nvar m = nm[1];\nvar t = n*n;\nvar row = [];\nvar col = [];\nvar urow = n;\nvar ucol = n;\nfunction pr(el, i, a){\n\twrite(el + \" \");\n};\nfor(i = 0; i < m; ++i){\n\tvar coord = readline().split(' ').map(function(x){return parseInt(x)});\n\tvar x = coord[0] - 1;\n\tvar y = coord[1] - 1;\n\tif(row[x] == undefined){\n\t\tt -= ucol;\n\t\trow[x] = 1;\n\t\turow--;\n\t};\n\tif(col[y] == undefined){\n\t\tt -= urow;\n\t\tcol[y] = 1;\n\t\tucol--;\n\t};\n\twrite(t + \" \");\n};\nprint();"}], "negative_code": [{"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = nm[0];\nvar m = nm[1];\n\n//var a = [[1, 1], [3, 1], [2, 2]];\n\nvar rows = {};\nvar cols = {};\n\nvar t = n * n;\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (i > 0) {\n if (rows[x] == undefined || cols[y] == undefined) {\n t -= n - 1;\n }\n } else {\n t -= 2 * n - 1;\n }\n\n print(t);\n //console.log(t);\n\n if (t == 0) break;\n\n rows[x] = 1;\n cols[y] = 1;\n}"}, {"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = parseInt(nm[0]);\nvar m = parseInt(nm[1]);\n\n//var n = 5;\n//var m = 2;\n//var a = [[1, 5], [5, 1]];\n\n//var n = 3;\n//var m = 3;\n//var a = [[1, 1], [3, 1], [2, 2]];\n\n//var n = 100000;\n//var m = 1;\n//var a = [[300, 400]];\n\nvar rows = {};\nvar cols = {};\n\nvar t = n * n;\nvar offset = n;\nvar results = [];\n\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (rows[x] == undefined) {\n t -= offset;\n }\n\n if (cols[y] == undefined) {\n offset -= 1;\n t -= offset;\n if (t < 0) t = 0;\n }\n\n results.push(t);\n\n if (t == 0) break;\n\n rows[x] = 1;\n cols[y] = 1;\n}\n\nprint(results.join(\" \"));"}, {"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = parseInt(nm[0]);\nvar m = parseInt(nm[1]);\n\n//var n = 5;\n//var m = 2;\n//var a = [[1, 5], [5, 1]];\n\n//var n = 3;\n//var m = 3;\n//var a = [[1, 1], [3, 1], [2, 2]];\n\n//var n = 100000;\n//var m = 1;\n//var a = [[300, 400]];\n\n//var n = 2;\n//var m = 2;\n//var a = [[1, 1], [1, 2]];\n\nvar rows = {};\nvar cols = {};\n\nvar t = n * n;\nvar offsetX = n;\nvar offsetY = n;\nvar results = [];\n\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (rows[x] == undefined) {\n t -= offsetY;\n offsetX -= 1;\n }\n\n if (cols[y] == undefined) {\n\n if(rows[x] != undefined) {\n t -= offsetX;\n }\n\n offsetY -= 1;\n t -= offsetY;\n if (t < 0) t = 0;\n }\n\n results.push(t);\n\n if (t == 0) break;\n\n rows[x] = 1;\n cols[y] = 1;\n}\n\nprint(results.join(\" \"));\n//console.log(results.join(\" \"));"}, {"source_code": "var nm = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = parseInt(nm[0]);\nvar m = parseInt(nm[1]);\n\n//var n = 5;\n//var m = 2;\n//var a = [[1, 5], [5, 1]];\n\n//var n = 3;\n//var m = 3;\n//var a = [[1, 1], [3, 1], [2, 2]];\n\n//var n = 100000;\n//var m = 1;\n//var a = [[300, 400]];\n\n//var n = 2;\n//var m = 2;\n//var a = [[1, 1], [1, 2]];\n\nvar rows = {};\nvar cols = {};\n\nvar rowsCount = 0;\nvar colsCount = 0;\n\nvar t = n * n;\n//var results = [];\n\nfor (var i = 0; i < m; ++i) {\n //var coor = a[i];\n var coor = readline().split(\" \").map(function(x) { return parseInt(x); });\n\n var x = coor[0];\n var y = coor[1];\n\n if (rows[x] == undefined) {\n ++rowsCount;\n t -= (n - colsCount);\n }\n\n if (cols[y] == undefined) {\n ++colsCount;\n t -= (n - rowsCount);\n }\n\n //results.push(t);\n write(t);\n\n rows[x] = 1;\n cols[y] = 1;\n}\n\n//print(results.join(\" \"));\n//console.log(results.join(\" \"));\n"}], "src_uid": "faf1abdeb6f0cf34972d5cb981116186"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var a = one[0];\n var b = one[1];\n var c = one[2];\n var d = one[3];\n var k = one[4];\n var L = Math.ceil(a / c);\n var R = Math.ceil(b / d);\n if(L + R <= k){\n output[i] = L + \" \" + R;\n }else{\n output[i] = -1;\n }\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [1, 1, 1, 1, 2],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] % query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = xLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? [-1].join(' ') + '\\n' : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "let lines = [];\nrequire('readline').createInterface({input: process.stdin,output: process.stdout})\n\t\t\t\t.on('line', line => {lines.push(line);})\n\t\t\t\t.on('close', () => {main(lines)});\n\nconst main = (input) => {\n\tfor (var i = 1; i <= parseInt(input[0]); i++) {\n\t\tvar [a, b,c,d, k] = input[i].split(\" \").map(num => parseInt(num));\n\t\tvar aTotal = Math.ceil(a / c);\n\t\tvar bTotal = Math.ceil(b / d);\n\t\tif (aTotal + bTotal <= k) {\n\t\t\tconsole.log(aTotal, bTotal);\n\t\t} else {\n\t\t\tconsole.log(-1);\n\t\t}\n\t}\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (data) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const [a, b, c, d, k] = data.split(' ').map(Number);\n const x = Math.ceil(a / c);\n const y = Math.ceil(b / d);\n\n if (x + y > k) {\n console.log(-1);\n }\n else {\n console.log(x, y);\n }\n\n count++;\n});\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst sol = () => {\n\tlet line = data.split(/\\n/);\n let n = Number(line[0]);\n let ans = [];\n for(let i = 0; i < n; i++){\n\t\tlet [a, b, c, d, k] = line[i+1].split(/\\s/).map(v => Number(v));\n\t\tlet x = Math.ceil(a/c);\n\t\tlet y = Math.ceil(b/d);\n\t\tif (x + y > k) {\n\t\t\tans.push(-1);\n\t\t} else {\n\t\t\tans.push(`${x} ${y}`);\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n\nprocess.stdin.on('end',sol);"}, {"source_code": "'use strict'\n \nconst problem = (a, b, c, d, k) => ((x, y) => (k >= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));\n \nlet t = parseInt(readline());\nwhile (t--) {\n const abcdk = readline().split(' ').map(Number);\n write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\\n');\n}"}, {"source_code": "var t = +readline();\n \nwhile(t--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1)\n else print(`${x} ${y}`)\n \n}\n \n \nfunction findMin(i, j) {\n return Math.ceil(i/j);\n}"}], "negative_code": [{"source_code": "var q = readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1);\n else write(x, y);\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = +readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = Math.ceil(a/c), y = Math.ceil(b/d);\n if(x + y > k) write(-1 + '\\n');\n else write(x + ' ' + y + '\\n');\n}"}, {"source_code": "var q = readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1);\n else print(x, y);\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = +readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c);\n // , y = findMin(b, d);\n // if(x + y > k) print(-1);\n // else print(x, y);\n print(x,x);\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1)\n else print(`${x} ${y}`)\n \n}\n\nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = +readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = Math.ceil(a/c), y = Math.ceil(b/d);\n if(x + y > k) print(-1);\n else print(x, y);\n}"}, {"source_code": "var q = +readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n // var x = findMin(a, c), y = findMin(b, d);\n // if(x + y > k) print(-1);\n // else print(x, y);\n print(a,b);\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) write(-1 + '\\n');\n else write(x + ' ' + y + '\\n');\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var q = readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1)\n else print(`${x} ${y}`)\n \n}\n \n \nfunction findMin(i, j) {\n var ans;\n \n if(j > i) ans = 1;\n else {\n ans = i/j;\n ans += i%j ? 1:0;\n }\n \n return ans;\n}"}, {"source_code": "var t = +readline();\n \nwhile(t--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1)\n else print(`${x} ${y}`)\n \n}\n \n \nfunction findMin(i, j) {\n var ans;\n \n if(j > i) ans = 1;\n else {\n ans = i/j;\n ans += i%j ? 1:0;\n }\n \n return ans;\n}"}, {"source_code": "var q = +readline();\n \nwhile(q--) {\n var q = readline().split(' ').map(Number);\n var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];\n var x = findMin(a, c), y = findMin(b, d);\n if(x + y > k) print(-1);\n else print(x, y);\n \n}\n \nfunction findMin(i, j) {\n return j > i ? 1 : Math.ceil(i/j);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = yLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? \"-1\" : [x, y].join(' '));\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = xLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? [-1].join('') : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = xLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? \"-1\\n\" : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = xLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? [-1].join(' ') + '\\n' : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = yLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? -1 : [x, y].join(' '));\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = yLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? \"\\n-1\\n\" : [x, y].join(' '));\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = yLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? \"-1\\n\" : [x, y].join(' '));\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = xLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? [-1].join(' ') : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "var queriesCount = parseInt(readline());\nvar queries = [];\n\nfor (var i = 0; i < queriesCount; i++) {\n queries.push(\n readline().split(' ').map(function(num) {\n return parseInt(num);\n })\n )\n}\n\n// queriesCount = 3;\n// queries = [\n// [7, 5, 4, 5, 8],\n// [7, 5, 4, 5, 2],\n// [20, 53, 45, 26, 4]\n// ]\n\nfunction main(query) {\n var xLeftover = query[0] % query[2]\n var x = Math.floor(query[0] / query[2]);\n var yLeftover = query[1] / query[3];\n var y = Math.floor(query[1] / query[3]);\n y = yLeftover ? y + 1 : y;\n x = yLeftover ? x + 1 : x;\n\n write(x + y > query[4] ? \"-1\\n\" : [x, y].join(' ') + '\\n');\n\n}\n\nfor (var i = 0; i < queriesCount; i++) {\n main(queries[i]);\n}"}, {"source_code": "'use strict'\n\nconst problem = (a, b, c, d, k) => ((x, y) => (k <= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));\n\nlet t = parseInt(readline());\nwhile (t--) {\n const abcdk = readline().split(' ').map(Number);\n write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\\n');\n}\n"}], "src_uid": "17cf2d6f59773925b228188b5a47b710"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n return n + (Math.floor(n / 2) + Math.floor(n / 3)) * 2;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n let ans=0;\r\n ans+=n;\r\n ans+=2*Math.floor(n/2);\r\n ans+=2*Math.floor(n/3);\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n // console.log(line);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n let ans=0;\r\n ans+=n;\r\n ans+=2*Math.floor(n/2);\r\n ans+=2*Math.floor(n/3);\r\n // ans+=Math.floor(y/3);\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar last = 0;\r\n\tvar addlist = [0,1,4,7,10,11,16];\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar output = Math.floor(N / 6) * 16;\r\n\t\toutput += addlist[N % 6];\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let count = n; //('equals');\r\n count += Math.floor(n / 2) * 2;\r\n count += Math.floor(n / 3) * 2;\r\n\r\n output(count);\r\n }\r\n}"}, {"source_code": "var n = readline();\r\nfor(var i=0;i=0; i--) {\n if (str[i] === '1') {\n end = i\n break\n }\n }\n for (i=start; i<=end; i++) {\n if (str[i] === '0')\n ++count\n }\n return count\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var str = readline()\n print(countErasedZeroes(str))\n}"}, {"source_code": "let fs = require('fs');\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\n\ntxt.shift();\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(\"\").filter(data => data.length > 0));\n\n}\n\nfunction doit(arr) {\n let shift = 0;\n let current = null;\n arr.forEach((data, index) => {\n if (data == 1) {\n if (current == null) {\n current = index;\n } else {\n shift += index - current - 1;\n current = index;\n }\n }\n });\n console.log(shift);\n\n\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n const length = input[0];\n for(let i = 1; i <= length; i++) {\n const str = input[i];\n let count = 0;\n let firstIndex = -1;\n let lastIndex = -1;\n\n for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {\n if(str[j] === '1' && firstIndex < 0) {\n firstIndex = j;\n }\n\n if(str[j2] === '1' && lastIndex < 0) {\n lastIndex = j2;\n }\n }\n\n for(let i = firstIndex; i <= lastIndex; i++) {\n if(str[i] === '0') count++;\n }\n \n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "var data = \"\";\n\nprocess.stdin.on(\"data\", x => data += x);\n\n// process.on(\"SIGINT\", () => {\nprocess.stdin.on(\"end\", () => {\n\n\tvar lines = data.split(\"\\r\\n\");\n\n\tvar n = lines.shift();\n\tfor(let i = 0; i < n; i++) f(lines[i]);\n\n\tprocess.exit(0);\n});\n\nfunction f(line) {\n\n\tline = line.replace(/(^0*|0*$)/g, \"\");\n\n\tvar ans = 0;\n\n\twhile(line.length) {\n\n\t\tif(+line[0]) line = line.replace(/^1+/, \"\");\n\t\telse {\n\n\t\t\tvar m = line.match(/^0+/);\n\t\t\tans += m[0].length;\n\t\t\tline = line.replace(/^0+/, \"\");\n\t\t}\n\t}\n\tconsole.log(ans);\n}\n"}, {"source_code": "const main = (data) => {\n const n = data[0];\n\n for (let i = 1; i <= n; i++) {\n const str = data[i];\n const lastIndex = str.lastIndexOf('1');\n let result = 0;\n\n for (let j = str.indexOf('1'); j < lastIndex; j++) {\n if (str[j] === '0') {\n result++;\n }\n };\n\n console.log(result);\n };\n};\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet state = 0;\nrl.on('line', line => {\n if (state > 0) {\n let left = line.indexOf('1');\n let right = line.lastIndexOf('1');\n let match = line.slice(left, right).match(/0/g) || [];\n console.log(match.length);\n }\n state++;\n}).on('close', () => {\n process.exit(0);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet state = 0;\nrl.on('line', line => {\n if (state > 0) {\n let left = line.indexOf('1');\n let right = line.lastIndexOf('1');\n\n console.log(\n line\n .slice(left, right)\n .split('')\n .reduce((a, b) => {\n return (a += b == '0' ? 1 : 0);\n }, 0)\n );\n }\n state++;\n}).on('close', () => {\n process.exit(0);\n});\n"}, {"source_code": "const fs = require(\"fs\");\nconst input = fs.readFileSync(0, { encoding: \"utf-8\" });\nconst lines = input.split(\"\\n\");\nlet cases = Number(lines.shift());\n\nwhile (cases--) {\n const line = lines.shift();\n let a = 0, b = 0, found1 = false;\n for (let i = 0; i < line.length; i++) {\n if (line[i] === \"1\") {\n found1 = true;\n b = a;\n } else if (found1) {\n a++;\n }\n }\n console.log(b);\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (str) {\n const match = str.match(/^0*(.*?)0*$/);\n const trimed = match && match[1];\n if (!trimed) return 0;\n const theros = trimed.match(/0/g);\n if (!theros) return 0;\n return theros.length;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount];\n\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 0;\n let headN = str.indexOf('1');\n let tailN = str.lastIndexOf('1');\n\n for (let i = headN; i < tailN; i++) {\n if (str[i] === '0') {\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var tests = parseInt(readline())\nfor (var l = 0; l < tests; l++){\nvar input = readline()\nvar res = input.split(/(0+)/)\nvar start = false, erase = 0, head = 0;\nfor (var i = 0; i < res.length; i++){\n\tif (res[i][0] == '1' && !start){\n\t\tstart = true; head = i\n\t}\n\telse if (res[i][0] == '1' && start){\n\t\tif (i - head > 1){\n\t\t\terase += res[i-1].length\n\t\t\thead = i\n\t\t}\n\t}\n}\nprint(erase)\n}\n\n"}, {"source_code": "'use strict'\n\nconst problem = (s) => s.split(/1+/).slice(1, -1).reduce((r, i) => r + i.length, 0);\n\nlet t = +readline()\nwhile(t--) print(problem(readline()))\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var list = myconv(next(),6);\n var count = 0;\n var tmpCount = 0;\n var zero = false;\n var one = false;\n for(var j = 0; j < list.length; j++){\n if(list[j] == \"1\"){\n if(zero){\n zero = false;\n count += tmpCount;\n tmpCount = 0;\n }\n one = true;\n }\n if(list[j] == \"0\"){\n if(one){\n tmpCount++;\n }\n zero = true;\n }\n }\n output[i] = count;\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "r=readline;p=print;for(k=r();k--;)((x=/1\\d*1/.exec(r()))&&(y=x[0].match(/0/g)))?p(y.length):p(0)"}, {"source_code": "function countErasedZeroes(str) {\n var len = str.length,\n start = -1,\n end = -1,\n count = 0\n for (var i = 0; i < len; i++) {\n if (str[i] === '1') {\n start = i\n break\n }\n }\n for (var i = len - 1; i >= 0; i--) {\n if (str[i] === '1') {\n end = i\n break\n }\n }\n for (i = start; i <= end; i++) {\n if (str[i] === '0')\n ++count\n }\n return count\n}\n\nvar tc = Number(readline())\nwhile (tc--) {\n var str = readline()\n print(countErasedZeroes(str))\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n const length = input[0];\n for(let i = 1; i <= length; i++) {\n const str = input[i];\n let count = 0;\n let firstIndex = null;\n let lastIndex = null;\n\n for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {\n if(str[j] === '1' && !firstIndex) {\n firstIndex = j;\n }\n\n if(str[j2] === '1' && !lastIndex) {\n lastIndex = j2;\n }\n }\n\n for(let i = firstIndex; i <= lastIndex; i++) {\n if(str[i] === '0') count++;\n }\n\n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n const length = input[0];\n for(let i = 1; i <= length; i++) {\n const str = input[i];\n let count = 0;\n let firstIndex = null;\n let lastIndex = null;\n\n for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {\n if(str[j] === '1' && !firstIndex) {\n firstIndex = j;\n }\n\n if(str[j2] === '1' && !lastIndex) {\n lastIndex = j2;\n }\n }\n\n for(let i = firstIndex; i <= lastIndex; i++) {\n if(str[i] === '0') count++;\n }\n \n\n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n for(let i = 1; i < input.length - 1; i++) {\n const str = input[i];\n let count = 0;\n let firstIndex = null;\n let lastIndex = null;\n\n for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {\n if(str[j] === '1' && !firstIndex) {\n firstIndex = j;\n }\n\n if(str[j2] === '1' && !lastIndex) {\n lastIndex = j2;\n }\n }\n\n for(let i = firstIndex; i < lastIndex; i++) {\n if(str[i] === '0') count++;\n }\n\n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n const length = input[0];\n for(let i = 1; i <= length; i++) {\n const str = input[i];\n let count = 0;\n let firstIndex = null;\n let lastIndex = null;\n\n for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {\n if(str[j] === '1' && !firstIndex) {\n firstIndex = j;\n }\n\n if(str[j2] === '1' && !lastIndex) {\n lastIndex = j2;\n }\n }\n\n for(let i = firstIndex; i < lastIndex; i++) {\n if(str[i] === '0') count++;\n }\n\n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n for(let i = 1; i < input.length; i++) {\n const str = input[i];\n let count = 0;\n let isRow = false;\n\n for (let j = 0; j < str.length; j++) {\n if(str[j] === '1' && !isRow) {\n isRow = true;\n } else if(str[j] === '0' && isRow) {\n count++;\n }\n }\n print(count);\n }\n\n // Your code here\n return 0;\n}\n"}, {"source_code": "let fs=require('fs')\nlet txt=fs.readFileSync(0,\"utf-8\").split(/[\\r\\n]/).filter(data=>data.length>0);\n\ntxt.shift()\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(\"\").filter(data=>data.length>0));\n \n}\n\nfunction doit(arr){\n let shift=0;\n let current=null;\n arr.forEach((data,index) => {\n if(data==1){\n if(current==null){current=index}else{\n shift+=index-current-1;\n current=null;\n }\n }\n });\n console.log(shift);\n \n \n}"}], "src_uid": "5de66fbb594bb317654366fd2290c4d3"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n,k] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n if(k===1) console.log(\"NO\");\r\n else{\r\n console.log(\"YES\");\r\n if(k===2) console.log(`${3*n} ${5*n} ${8*n}`);\r\n else console.log(`${n*(k-1)} ${n*(k+1)} ${n*k*2}`);\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n \r\n// 05/09/21 evening\r\nconst solve = (a, b) => {\r\n if (b == 1) {\r\n return pr('NO');\r\n }\r\n pr('YES');\r\n pr(a, a * (2 * b - 1), 2 * a * b);\r\n};\r\n \r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n \r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n// 05/09/21 evening\r\nconst solve = (a, b) => {\r\n if (b == 1) {\r\n return pr('NO');\r\n }\r\n pr('YES');\r\n pr(a, a * (2 * b - 1), 2 * a * b);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n// 05/09/21 evening\r\nconst solve = (a, b) => {\r\n if (b == 1) {\r\n return pr('NO');\r\n }\r\n pr('YES');\r\n pr(a, a * (2 * b - 1), 2 * a * b);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var tt;\r\ntt=parseInt(readline());\r\n\r\nwhile(tt--){\r\n var a,b,arr;\r\n arr=readline().split(' ');\r\n a=parseInt(arr[0]);\r\n b=parseInt(arr[1]);\r\n\r\n if(b==1){print(\"NO\");}\r\n else{\r\n print(\"YES\");\r\n var z=(a*b);\r\n var x=a;\r\n var y=z+a;\r\n\r\n print(x,z,y);\r\n }\r\n}"}, {"source_code": "var e=readline();\r\nfor(var i=0;i{\"use strict\";var e={332:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=(e,t)=>{let o=e*t,n=(t-1)*e,s=1*e;n===s&&(o*=2,n=((t*=2)-1)*e,s=1*e),1!=t?(console.log(\"YES\"),console.log(`${n} ${s} ${o}`)):console.log(\"NO\")}},590:function(e,t,o){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});const s=n(o(332));o(188).testInput(s.default)},188:(e,t,o)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=e=>{const t=o(58).createInterface({input:process.stdin,output:process.stdout});let n=[],s=0;t.on(\"line\",(function(o){if(n.push(o),1===n.length&&(s=+n[0]),n.length===s+1){t.close();for(let t=1;t{const n=o(58).createInterface({input:process.stdin,output:process.stdout});let s=[];n.on(\"line\",(function(e){s.push(e),2===s.length&&(n.close(),console.log(t(s[1].split(\" \").map((e=>+e)))))}))}},58:e=>{e.exports=require(\"readline\")}},t={};!function o(n){var s=t[n];if(void 0!==s)return s.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,o),l.exports}(590)})();"}, {"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number} a\n * @param {Number} b\n * @returns {Number []}\n */\nfunction solve(a, b) {\n if (b <= 1 || a < 1) {\n return [];\n }\n if (b === 2) {\n return [a, 3 * a, 4 * a];\n }\n return [a, (b-1) * a, a * b];\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const [a, b] = (await getLine()).split(' ').map(Number);\n const res = solve(a, b);\n if (res.length === 3) {\n console.log('YES');\n console.log(res.join(' '));\n } else {\n console.log('NO');\n }\n }\n}\n\nif (require.main === module) {\n main();\n}"}, {"source_code": "const solve = (a, b) => {\n if (b === 1) {\n console.log('NO');\n } else { \n console.log('YES');\n console.log(a, a * b, a * (b + 1));\n }\n};\n\nlet line = '';\nprocess.stdin.on('data', c => line += c);\nprocess.stdin.on('end', () => {\n const input = line.trim().split('\\n'); \n for (let i = 1; i < input.length; i++) { \n const [a, b] = input[i].split(' ').map(item => parseInt(item));\n solve(a, b);\n }\n});\n \t \t \t \t \t\t\t \t\t \t \t\t \t"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a, b]) {\r\n if (b === 1) {\r\n console.log('NO')\r\n return\r\n }\r\n console.log('YES')\r\n console.log(a * b, a, (a * b) + a)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n if (a % p) {\n var f = false;\n var k = 1;\n while (!f && k < 10) {\n for (var i = 1; i < b * k && !f; i++) {\n var d = b * k - i;\n if (a * (i + d) === p && i !== d) {\n print('YES');\n print(a * i, a * d, p);\n f = true;\n }\n }\n p += p;\n k++;\n }\n } else\n print('NO');\n}"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// WA\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // pr(a,b,p);\n // if (a == 1) {\n // if (b == 1) {\n // pr('YES');\n // pr(2, 4, 6);\n // return;\n // } else if (b == 2) {\n // pr('YES');\n // pr(1, 3, 4);\n // return;\n // }\n // }\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (x % b != 0) {\n if (y % a == 0 && y % b != 0 && (y != x && x != z && y != z)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // pr(a,b,p);\n if (a == 1) {\n if (b == 1) {\n pr('YES');\n pr(2, 4, 6);\n return;\n } else if (b == 2) {\n pr('YES');\n pr(1, 3, 4);\n return;\n }\n }\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n // if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n // if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x && x != z && y != z)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // pr(a,b,p);\n if (a == 1 && b == 1) {\n pr('YES');\n pr(2, 4, 6);\n return;\n }\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x && x != z && y != z)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // pr(a,b,p);\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x && x != z && y != z)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // if (a == 1 && b == 2) {\n // pr('YES');\n // pr(1, 1, 2);\n // return;\n // }\n // pr(a,b,p);\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x && y > 0)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // if (a == 1 && b == 2) {\n // pr('YES');\n // pr(1, 1, 2);\n // return;\n // }\n // pr(a,b,p);\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n pr(x, y);\n if (y % a == 0 && (y != x && x != z)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // if (a == 1 && b == 2) {\n // pr('YES');\n // pr(1, 1, 2);\n // return;\n // }\n // pr(a,b,p);\n for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {\n if (rz > 1 && z == p) break;\n // pr(z);\n for (let x = a, rx = 1; x < z; x *= a, rx++) {\n if (rx > 1 && x == a) break;\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n if (a == 1 && b == 2) {\n pr('YES');\n pr(1, 1, 2);\n return;\n }\n // pr(a,b,p);\n for (let z = p; z <= MAX && p != 1; z *= p) {\n // pr(z);\n for (let x = a; x < z && a != 1; x *= a) {\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n // pr(a,b,p);\n for (let z = p; z <= MAX && p != 1; z *= p) {\n // pr(z);\n for (let x = a; x < z && a != 1; x *= a) {\n let y = z - x;\n // pr(x, y);\n if (y % a == 0 && (y != x)) {\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\nconst pr = console.log;\nconst mi = Math.min;\nconst mx = Math.max;\nconst abs = Math.abs;\nconst fl = Math.floor;\nconst ce = Math.ceil;\nconst sq = Math.sqrt;\nconst lge = Math.log;\nconst lg10 = Math.log10;\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\nconst amax = (a) => mx.apply(Math, a);\nconst amin = (a) => mi.apply(Math, a);\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\nconst stin = (a) => a.sort((x, y) => x - y);\nconst stde = (a) => a.sort((x, y) => y - x);\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst MAX = BigInt(10 ** 18);\nconst solve = (a, b) => {\n let p = a * b;\n for (let z = p; z <= MAX; z *= p) {\n for (let x = a; x < z; x *= a) {\n let y = z - x;\n if (y % a == 0) {\n flag = 1;\n pr('YES');\n pr(x.toString(), y.toString(), z.toString());\n return;\n }\n }\n }\n pr('NO');\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => BigInt(x)));\n });\n rl.on('close', () => {\n let t = input[0][0];\n let i = 1;\n while (t--) {\n solve(input[i][0], input[i][1]);\n i++;\n }\n });\n};\n\nmain()\n\n\n// pr(60 / (5 * 3));\n// pr(208 / (13 * 2));\n// pr(154 / (7 * 11));\n\n// pr(50 / 5, 10 / 5, 60 / 5);\n// pr(169 / 13, 39 / 13, 208 / 13);\n// pr(154 / 7, 28 / 7, 182 / 7);"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n,k] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n if(k===1) console.log(\"NO\");\r\n else{\r\n console.log(\"YES\");\r\n if(k===2) console.log(`${3*n} ${5*n} ${8*13}`);\r\n else console.log(`${n*(k-1)} ${n*(k+1)} ${n*k*2}`);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "(()=>{\"use strict\";var e={332:(e,t)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=(e,t)=>{let o=e*t,n=(t-1)*e,s=1*e;n===s&&(o*=2,n=((t*=2)-1)*e,s=1*e),e+t>=e*t?console.log(\"NO\"):(console.log(\"YES\"),console.log(`${n} ${s} ${o}`))}},590:function(e,t,o){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,\"__esModule\",{value:!0});const s=n(o(332));o(188).testInput(s.default)},188:(e,t,o)=>{Object.defineProperty(t,\"__esModule\",{value:!0}),t.singleInput=t.testInput=void 0,t.testInput=e=>{const t=o(58).createInterface({input:process.stdin,output:process.stdout});let n=[],s=0;t.on(\"line\",(function(o){if(n.push(o),1===n.length&&(s=+n[0]),n.length===s+1){t.close();for(let t=1;t{const n=o(58).createInterface({input:process.stdin,output:process.stdout});let s=[];n.on(\"line\",(function(e){s.push(e),2===s.length&&(n.close(),console.log(t(s[1].split(\" \").map((e=>+e)))))}))}},58:e=>{e.exports=require(\"readline\")}},t={};!function o(n){var s=t[n];if(void 0!==s)return s.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,o),l.exports}(590)})();"}, {"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number} a\n * @param {Number} b\n * @returns {Number []}\n */\nfunction solve(a, b) {\n if (b <= 1 || a < 1) {\n return [];\n }\n if (b === 2) {\n return [4 * a, a, 3 * a];\n }\n return [a * b, a, (b-1) * a];\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const [a, b] = (await getLine()).split(' ').map(Number);\n const res = solve(a, b);\n if (res.length === 3) {\n console.log('YES');\n console.log(res.join(' '));\n } else {\n console.log('NO');\n }\n }\n}\n\nif (require.main === module) {\n main();\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n if (a % b) {\n var f = false;\n var k = 1;\n while (!f && k < 10) {\n for (var i = 1; i < b * k && !f; i++) {\n var d = b * k - i;\n if (a * (i + d) === p && i !== d) {\n print('YES');\n print(a * i, a * d, p);\n f = true;\n }\n }\n p += p;\n k++;\n }\n } else\n print('NO');\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n if (a % b) {\n var f = false;\n for (var i = 1; i < b && !f; i++) {\n var d = b - i;\n if (a * (i + d) === p && i !== d) {\n print('YES');\n print(a * i, a * d, p);\n f = true;\n }\n }\n } else\n print('NO');\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n if (a % b) {\n var p = a * b;\n for (var i = 1; true; i++) {\n var test = i * p - a;\n if (a !== test && !(test % a) && test % p) {\n print('YES');\n print(a, test, i * p);\n break;\n }\n }\n } else\n print('NO');\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n if (a % b) {\n var p = a * b;\n for (var i = 1; true; i++) {\n var test = i * p - a;\n if (!(test % a) && test % p) {\n print('YES');\n print(a, test, i * p);\n break;\n }\n }\n } else\n print('NO');\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n if (a > 1 || b > 1) {\n var p = a * b;\n print('YES');\n print(p - a, p * 3 + a, p * 4);\n } else\n print('NO');\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n print('YES');\n print(p - a, p * 3 + a, p * 4);\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n print('YES');\n print(p, p * 3, p * 4);\n}"}, {"source_code": "const t = parseInt(readline());\n\nfor (var _ = 0; _ < t; _++) {\n var line1 = readline().split(' ').map(d => parseInt(d));\n var a = line1[0];\n var b = line1[1];\n var p = a * b;\n print(p, p * 3, p * 4);\n}"}, {"source_code": "var tt;\r\ntt=parseInt(readline());\r\n\r\nwhile(tt--){\r\n var a,b,arr;\r\n arr=readline().split(' ');\r\n a=parseInt(arr[0]);\r\n b=parseInt(arr[1]);\r\n\r\n if(b==1){print(\"NO\");}\r\n else{\r\n print(\"YES\");\r\n var z=(a*b);\r\n var x=a;\r\n var y=z+a;\r\n\r\n print(x,y,z);\r\n }\r\n}"}], "src_uid": "f10aa45956e930df3df0e23f2592c8f1"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let arr1 = stringArr();\r\n let b = [],\r\n r = [];\r\n for (let i = 0; i < n; i++)\r\n arr1[i] === \"B\" ? b.push(arr[i]) : r.push(arr[i]);\r\n const helper = () => {\r\n let res = 1;\r\n if (b.length >= 2) b.sort((a, b) => a - b);\r\n for (let i = 0; i < b.length; i++) {\r\n if (b[i] < res) return \"NO\";\r\n res++;\r\n }\r\n\r\n if (r.length >= 2) if (r.length >= 2) r.sort((a, b) => a - b);\r\n for (let i = 0; i < r.length; i++) {\r\n if (r[i] > res) return \"NO\";\r\n res++;\r\n }\r\n\r\n return \"YES\";\r\n };\r\n console.log(helper());\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\tconst c = rl().split('');\r\n\r\n\t\tconst inc = [], dec = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (c[i] == 'B') {\r\n\t\t\t\tdec.push(a[i]);\r\n\t\t\t} else {\r\n\t\t\t\tinc.push(a[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tinc.sort((x, y) => x - y);\r\n\t\tdec.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = true;\r\n\t\tfor (let i = 0; ans && i < dec.length; i++) {\r\n\t\t\tif (dec[i] < i+1)\r\n\t\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; ans && i < inc.length; i++) {\r\n\t\t\tif (inc[i] > dec.length + i + 1) {\r\n\t\t\t\tans = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = readLine().split(' ').map(x => Number(x));\r\n\t\tlet s = rl();\r\n\r\n\t\tlet b = [], r = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t(s[i] == 'B' ? b : r).push(a[i]);\r\n\t\t}\r\n\r\n\t\tb.sort((x, y) => x - y);\r\n\t\tr.sort((x, y) => x - y);\r\n\r\n\t\tok = true;\r\n\t\tfor (let i = 0; ok && i < b.length; i++)\r\n\t\t\tif (b[i] < i + 1) ok = false;\r\n\r\n\t\tfor (let i = b.length; ok && i < n; i++)\r\n\t\t\tif (r[i - b.length] > i + 1) ok = false;\r\n\r\n\t\tans = ok ? 'YES':'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet a;\r\nlet s;\r\nfunction can() {\r\n const up = [];\r\n const down = [];\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == 'B') {\r\n down.push(a[i]);\r\n }\r\n else {\r\n up.push(a[i]);\r\n }\r\n }\r\n up.sort((a, b) => a - b);\r\n down.sort((a, b) => a - b);\r\n let l = 0;\r\n let r = 0;\r\n // printf(\"%j\\n\", up);\r\n // printf(\"%j\\n\", down);\r\n for (let i = 1; i <= n; i++) {\r\n while (l < down.length && down[l] < i) {\r\n l++;\r\n }\r\n if (l < down.length && down[l] >= i) {\r\n l++;\r\n continue;\r\n }\r\n if (r < up.length && up[r] <= i) {\r\n r++;\r\n continue;\r\n }\r\n return false;\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n s = nextStr();\r\n // printf(\"%j\\n\", a);\r\n if (can()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "{\r\n process.stdin.resume();\r\n process.stdin.setEncoding('utf-8');\r\n let inputString = '';\r\n let currentLine = 0;\r\n process.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n solve();\r\n });\r\n function readLine() {\r\n return inputString[currentLine++];\r\n }\r\n}\r\n/*\r\n*solve here\r\n*/\r\nfunction solve() {\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n let n = readLine();\r\n let a = readLine().split(\" \");\r\n let c = readLine().split(\"\");\r\n let l = [], r = [];\r\n for (let i = 0; i < a.length; i++) {\r\n (c[i] === 'B' ? l : r).push(a[i])\r\n }\r\n l.sort((a, b) => a - b);\r\n r.sort((a, b) => b - a);\r\n let flag = true;\r\n for (let i = 0; i < l.length; i++) {\r\n if (l[i] < (i + 1)) {\r\n flag = false;\r\n }\r\n }\r\n for (let i = 0; i < r.length; i++) {\r\n if (r[i] > (n - i)) {\r\n flag = false;\r\n }\r\n }\r\n console.log(flag ? \"YES\" : \"NO\");\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let n = Number(readline())\r\n let a = readline().split(' ').map(Number);\r\n let s = readline();\r\n let ok = 1;\r\n let D = [];\r\n let I = [];\r\n for (let i = 0; i < n; i++)\r\n if (s[i] == 'B')\r\n D.push(a[i]);\r\n else\r\n I.push(a[i]);\r\n D.sort((a, b) => a - b)\r\n I.sort((a, b) => a - b)\r\n let pd = 0, pi = 0;\r\n let ld = D.length;\r\n let li = I.length;\r\n for (let i = 1; i <= n; i++) {\r\n if (pd < ld && D[pd] >= i)\r\n pd++;\r\n else if (pi < li && I[pi] <= i)\r\n pi++;\r\n else\r\n ok = 0;\r\n }\r\n if (ok)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n}\r\n// let a=readline().split(' ').map(Number)\r\n// a.sort((a,b)=>a-b)\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let n = Number(readline())\r\n let a = readline().split(' ').map(Number);\r\n let s = readline();\r\n let ok = 1;\r\n let D = [];\r\n let I = [];\r\n for (let i = 0; i < n; i++)\r\n if (s[i] == 'B')\r\n D.push(a[i]);\r\n else\r\n I.push(a[i]);\r\n D.sort((a, b) => a - b)\r\n I.sort((a, b) => a - b)\r\n let pd = 0, pi = 0;\r\n let ld = D.length;\r\n let li = I.length;\r\n for (let i = 1; i <= n; i++) {\r\n if (pd < ld && D[pd] >= i)\r\n pd++;\r\n else if (pi < li && I[pi] <= i)\r\n pi++;\r\n else\r\n ok = 0;\r\n }\r\n if (ok)\r\n console.log(\"YES\");\r\n else\r\n console.log(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "var a=readline();\r\nfunction mergeSort(array) {\r\n if (array == null) {\r\n return;\r\n }\r\n \r\n if (array.length > 1) {\r\n var mid = parseInt(array.length / 2);\r\n \r\n // Split left part\r\n var left = Array(mid).fill(0);\r\n for (i = 0; i < mid; i++) {\r\n left[i] = array[i];\r\n }\r\n \r\n // Split right part\r\n var right = Array(array.length - mid).fill(0);\r\n for (i = mid; i < array.length; i++) {\r\n right[i - mid] = array[i];\r\n }\r\n mergeSort(left);\r\n mergeSort(right);\r\n \r\n var i = 0;\r\n var j = 0;\r\n var k = 0;\r\n \r\n // Merge left and right arrays\r\n while (i < left.length && j < right.length) {\r\n if (left[i] < right[j]) {\r\n array[k] = left[i];\r\n i++;\r\n } else {\r\n array[k] = right[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n // Collect remaining elements\r\n while (i < left.length) {\r\n array[k] = left[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < right.length) {\r\n array[k] = right[j];\r\n j++;\r\n k++;\r\n }\r\n }\r\n return array;\r\n}\r\n\r\nfunction getObj(arr,str) {\r\n\tvar red=[];\r\n\tvar blue=[];\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tif(str[i]==\"B\"){\r\n\t\t\tblue.push(arr[i]);\r\n\t\t}else{\r\n\t\t\tred.push(arr[i]);\r\n\t\t}\r\n\t}\r\n\tred=mergeSort(red);\r\n\tblue=mergeSort(blue);\r\n\tvar isTrue=true;\r\n\tfor (var i = 1; i < arr.length+1; i++) {\r\n\t\tif(i<=blue.length){\r\n\t\t\tif(i>blue[i-1]){\r\n\t\t\t\tisTrue=false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tif((i) dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = readLine().split(' ').map(x => Number(x));\r\n\t\tlet s = rl();\r\n\r\n\t\tlet b = [], r = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t(s[i] == 'B' ? b : r).push(a[i]);\r\n\t\t}\r\n\r\n\t\tb.sort((x, y) => x - y);\r\n\t\tr.sort((x, y) => x - y);\r\n\r\n\t\tok = true;\r\n\t\tconsole.log(b, r, a, s)\r\n\t\tfor (let i = 0; ok && i < b.length; i++)\r\n\t\t\tif (b[i] < i + 1) ok = false;\r\n\r\n\t\tfor (let i = b.length; ok && i < n; i++)\r\n\t\t\tif (r[i - b.length] > i + 1) ok = false;\r\n\r\n\t\tans = ok ? 'YES':'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet b = [], r = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t(s[i] == 'B' ? b : r).push(a[i]);\r\n\t\t}\r\n\r\n\t\tb.sort((x, y) => x - y);\r\n\t\tr.sort((x, y) => x - y);\r\n\r\n\t\tok = true;\r\n\t\tfor (let i = 0; ok && i < b.length; i++)\r\n\t\t\tif (b[i] < i + 1) ok = false;\r\n\r\n\t\tfor (let i = b.length; ok && i < n; i++)\r\n\t\t\tif (r[i - b.length] > i + 1) ok = false;\r\n\r\n\t\tans = ok ? 'YES':'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet a = rl();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet b = [], r = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (s[i] == 'B' ) \r\n\t\t\t\tb.push(a[i]);\r\n\t\t\telse r.push(a[i]);\r\n\t\t}\r\n\r\n\t\tb.sort((x, y) => x - y);\r\n\t\tr.sort((x, y) => x - y);\r\n\r\n\t\tok = true;\r\n\t\tfor (let i = 0; ok && i < b.length; i++)\r\n\t\t\tif (b[i] < i + 1) ok = false;\r\n\r\n\t\tfor (let i = b.length; ok && i < n; i++)\r\n\t\t\tif (r[i - b.length] > i + 1) ok = false;\r\n\r\n\t\tans = ok ? 'YES':'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet a;\r\nlet s;\r\nfunction can() {\r\n const up = [];\r\n const down = [];\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == 'B') {\r\n down.push(a[i]);\r\n }\r\n else {\r\n up.push(a[i]);\r\n }\r\n }\r\n up.sort();\r\n down.sort();\r\n let l = 0;\r\n let r = 0;\r\n for (let i = 1; i <= n; i++) {\r\n while (l < down.length && down[l] < i) {\r\n l++;\r\n }\r\n if (l < down.length && down[l] >= i) {\r\n l++;\r\n continue;\r\n }\r\n if (r < up.length && up[r] <= i) {\r\n r++;\r\n continue;\r\n }\r\n return false;\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n s = nextStr();\r\n if (can()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INF = Number.MAX_SAFE_INTEGER;\r\nconst INIT = -1;\r\nlet n;\r\nlet a;\r\nlet s;\r\nfunction can() {\r\n const up = [];\r\n const down = [];\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == 'B') {\r\n down.push(a[i]);\r\n }\r\n else {\r\n up.push(a[i]);\r\n }\r\n }\r\n up.sort();\r\n down.sort();\r\n let l = 0;\r\n let r = 0;\r\n for (let i = 1; i <= n; i++) {\r\n while (down[l] < i) {\r\n l++;\r\n }\r\n if (down[l] >= i) {\r\n l++;\r\n continue;\r\n }\r\n if (up[r] <= i) {\r\n r++;\r\n continue;\r\n }\r\n return false;\r\n }\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n s = nextStr();\r\n if (can()) {\r\n printf(\"YES\\n\");\r\n }\r\n else {\r\n printf(\"NO\\n\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let arr1 = stringArr();\r\n let b = [],\r\n r = [];\r\n for (let i = 0; i < n; i++)\r\n arr1[i] === \"B\" ? b.push(arr[i]) : r.push(arr[i]);\r\n const helper = () => {\r\n let res = 1;\r\n if (b.length >= 2) {\r\n b.sort((a, b) => a - b);\r\n for (let i = 0; i < b.length; i++) {\r\n if (b[i] < res) return \"NO\";\r\n res++;\r\n }\r\n }\r\n if (r.length >= 2) {\r\n if (r.length >= 2) r.sort((a, b) => a - b);\r\n for (let i = 0; i < r.length; i++) {\r\n if (r[i] > res) return \"NO\";\r\n res++;\r\n }\r\n }\r\n return \"YES\";\r\n };\r\n console.log(helper());\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var a=readline();\r\nfunction mergeSort(array) {\r\n if (array == null) {\r\n return;\r\n }\r\n \r\n if (array.length > 1) {\r\n var mid = parseInt(array.length / 2);\r\n \r\n // Split left part\r\n var left = Array(mid).fill(0);\r\n for (i = 0; i < mid; i++) {\r\n left[i] = array[i];\r\n }\r\n \r\n // Split right part\r\n var right = Array(array.length - mid).fill(0);\r\n for (i = mid; i < array.length; i++) {\r\n right[i - mid] = array[i];\r\n }\r\n mergeSort(left);\r\n mergeSort(right);\r\n \r\n var i = 0;\r\n var j = 0;\r\n var k = 0;\r\n \r\n // Merge left and right arrays\r\n while (i < left.length && j < right.length) {\r\n if (left[i] < right[j]) {\r\n array[k] = left[i];\r\n i++;\r\n } else {\r\n array[k] = right[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n // Collect remaining elements\r\n while (i < left.length) {\r\n array[k] = left[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < right.length) {\r\n array[k] = right[j];\r\n j++;\r\n k++;\r\n }\r\n }\r\n return array;\r\n}\r\n\r\nfunction getObj(arr,str) {\r\n\tvar red=[];\r\n\tvar blue=[];\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tif(str[i]==\"B\"){\r\n\t\t\tblue.push(arr[i]);\r\n\t\t}else{\r\n\t\t\tred.push(arr[i]);\r\n\t\t}\r\n\t}\r\n\tred=mergeSort(red);\r\n\tblue=mergeSort(blue);\r\n\tvar isTrue=true;\r\n\tfor (var i = 1; i < arr.length+1; i++) {\r\n\t\tif(i<=blue.length){\r\n\t\t\tif(i>blue[i-1]){\r\n\t\t\t\tisTrue=false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tif((i) {\n arr = arr.split(\"\\n\");\n var n = parseInt(arr.shift())\n for(let i=0;i {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a, b, n] = d.split(' ').map(Number);\n const ans = [a, b, a ^ b];\n console.log(ans[n % 3]);\n\n c++;\n});\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst sol = () => {\n\tlet line = data.split('\\n');\n\tlet n = parseInt(line[0], 10);\n\tlet result = [];\n\tfor(let i = 0; i < n; i++){\n\t\tlet [a, b, k] = line[i+1].split(' ').map(v => parseInt(v,10));\n\t\tresult.push([a, b, a ^ b][k%3]);\n\t}\n\tconsole.log(result.join('\\n'));\n};\nprocess.stdin.on('end', sol);\n"}, {"source_code": "function input() {\n var n = parseInt(readline().trim());\n return Array(n)\n .fill(0)\n .map(function() {\n return readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n });\n });\n}\n\nfunction solve(a, b, n) {\n if (n % 3 === 0) return a;\n if (n % 3 === 1) return b;\n return a ^ b;\n}\n\nfunction main() {\n // get input\n var read = input();\n\n for (var i = 0; i < read.length; i++) {\n print(solve(read[i][0], read[i][1], read[i][2]));\n }\n}\n\nmain();\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n while (T --> 0) {\n var input = rdArN();\n var a = input[0].toString(2).split('').reverse();\n var b = input[1].toString(2).split('').reverse();\n var n = input[2]%3;\n \n var res = [];\n var F = [\n [\n [0, 0],\n [1, 1]\n ],\n [\n [0, 1],\n [0, 1]\n ],\n [\n [0, 1],\n [1, 0]\n ],\n ]\n for (var i = 0; i < a.length || i < b.length; ++i) {\n var f0 = a[i] || 0;\n var f1 = b[i] || 0;\n var fn = F[n][f0][f1];\n \n res.push(fn);\n }\n pr(parseInt(res.reverse().join(''), 2));\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\";\nlet numbers = []\nprocess.stdin.on('data', function(chunk) {\n arr += chunk;\n});\n\nprocess.stdin.on('end', () => {\n arr = arr.split(\"\\n\");\n var n = parseInt(arr.shift())\n console.log(n)\n for(let i=0;i {\n if (c === 0) {\n c++;\n return;\n }\n\n let [a, b, n] = d.split(' ').map(Number);\n\n if (n === 0) {\n console.log(a);\n return;\n }\n else if (n === 1) {\n console.log(b);\n return;\n }\n\n console.log(a ^ b);\n\n c++;\n});\n"}, {"source_code": "function input() {\n var n = parseInt(readline().trim());\n return Array(n)\n .fill(0)\n .map(function() {\n return readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n });\n });\n}\n\nfunction solve(a, b, n) {\n if (n == 0) return a;\n if (n == 1) return b;\n\n var check = {\n [a]: 0,\n [b]: 1\n };\n\n var reverse = {\n 0: a,\n 1: b\n };\n\n var count = 2;\n\n while (true) {\n var next = a ^ b;\n if (check[next] !== undefined) {\n return reverse[n % count];\n }\n check[next] = count;\n reverse[count] = next;\n a = b;\n b = next;\n count += 1;\n }\n}\n\nfunction main() {\n // get input\n var read = input();\n\n for (var i = 0; i < read.length; i++) {\n print(solve(read[i][0], read[i][1], read[i][2]));\n }\n}\n\nmain();\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\";\nlet numbers = []\nprocess.stdin.on('data', function(chunk) {\n arr += chunk;\n});\n\nprocess.stdin.on('end', () => {\n arr = arr.split(\"\\n\");\n var n = parseInt(arr.shift())\n for(let i=0;i {\n arr = arr.split(\"\\n\");\n var n = parseInt(arr.shift())\n for(let i=0;i stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst MOD = 1e9+7;\r\n\r\nconst B = n => BigInt(n); \r\n\r\nfunction fact (n) {\r\n\tlet res = 1;\r\n\tfor (let i = 1; i <= n; i++) res = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet and = ~0;\r\n\t\tfor (let i = 0; i < n; i++) and &= a[i];\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (let i = 0; i < n; i++) cnt += a[i] == and;\r\n\r\n\t\tconst ans = B(cnt*(cnt-1)) * B(fact(n-2)) % B(MOD);\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var x = a[0]\r\n for (let j = 0; j < n; j++) {\r\n x = x & a[j]\r\n }\r\n\r\n var cmt = 0\r\n for (let j = 0; j < n; j++) {\r\n cmt = cmt + (a[j] === x ? 1 : 0)\r\n }\r\n var ans = 1n\r\n ans = ((BigInt(cmt) * BigInt(cmt - 1)) / 2n * 2n) % mod\r\n\r\n for (let j = 1; j <= n - 2; j++) {\r\n ans = (ans * BigInt(j)) % mod\r\n }\r\n\r\n console.log(ans.toString())\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst MOD = BigInt(1e9+7);\r\n\r\nfunction fact (n) {\r\n\tlet res = 1n;\r\n\tfor (let i = 1n; i <= n; i++) res = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet and = a[0];\r\n\t\tfor (let i = 0; i < n; i++) and &= a[i];\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (let i = 0; i < n; i++) cnt += a[i] == and;\r\n\r\n\t\tconst ans = BigInt(cnt*(cnt-1))*fact(n-2)%MOD;\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst MOD = 1e9+7;\r\n\r\nfunction fact (n) {\r\n\tlet res = 1;\r\n\tfor (let i = 1; i <= n; i++) res = res * i % MOD;\r\n\treturn res;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet and = a[0];\r\n\t\tfor (let i = 0; i < n; i++) and &= a[i];\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (let i = 0; i < n; i++) cnt += a[i] == and;\r\n\r\n\t\tconsole.log(cnt*(cnt-1)*fact(n-2)%MOD+0);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "e4685bb0a1bf8c2da326cd0e5b8f4fe7"} {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN();\n var m = rdN();\n var B = rdArN();\n for (var i = 0; i < n; ++i) {\n for (var j = 0; j < m; ++j) {\n var s = A[i] + B[j];\n if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {\n wr(A[i], B[j]);\n return;\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();", "positive_code": [{"source_code": "var a = parseInt(readline().trim());\nvar numbers1 = readline().trim().split(\" \").map(function(x) { return parseInt(x); });\nvar mx1 = Math.max.apply(null, numbers1);\nvar b = parseInt(readline().trim());\nvar numbers2 = readline().trim().split(\" \").map(function(x) { return parseInt(x); });\nvar mx2 = Math.max.apply(null, numbers2);\nprint(mx1 + \" \" + mx2);"}, {"source_code": "var n = Number(readline());\nvar a = readline();\na = a.split(' ');\na = a.map((x) => Number(x));\nvar m = Number(readline());\nvar b = readline();\nb = b.split(' ');\nb = b.map((x) => Number(x));\na.sort((x, y) => x - y);\nb.sort((x, y) => x - y);\nprint(String(a[n - 1]) + \" \" + String(b[m - 1]));"}, {"source_code": "function main() {\n const [n, a, m, b] = stdin;\n const A = a.split(' ').map(Number);\n const B = b.split(' ').map(Number);\n const C = new Set(A.concat(B));\n for (let i = 0; i < A.length; i++) {\n for (let j = 0; j < B.length; j++) {\n if (!C.has(A[i] + B[j])) {\n console.log(A[i], B[j]);\n return\n }\n }\n }\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var alist = nextIntArray();\n var M = nextInt();\n var blist = nextIntArray();\n for(var i = 0; i < N; i++){\n for(var j = 0; j < M; j++){\n var sum = alist[i] + blist[j];\n if(alist.indexOf(sum) == -1 && blist.indexOf(sum) == -1){\n myout(alist[i] + \" \" + blist[j]);\n return;\n }\n }\n }\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n\nconst processData = (lines) => {\n const [n, a, m, b] = lines\n\n const A = a.split(' ').map(n => Number(n))\n const B = b.split(' ').map(n => Number(n))\n\n const C = new Set(A.concat(B))\n\n for (let i = 0; i < A.length; i++) {\n for (let j = 0; j < B.length; j++) {\n if (!C.has(A[i] + B[j])) {\n console.log(A[i], B[j])\n return\n }\n }\n }\n}"}, {"source_code": "let input ='';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data',(data)=>input+=data)\nprocess.stdin.on('end',()=>{\n input = input.split('\\n')\n let maxA = 0;\n input[1].split(' ').forEach((item)=>{\n\t\titem = parseInt(item)\n\t\tif(item>maxA) maxA = item\n\t\t})\n let maxB = 0;\n input[3].split(' ').forEach((item)=>{\n item = parseInt(item)\n\t\tif(item>maxB) maxB = item\n\t\t})\n console.log(maxA,maxB)\n \n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet len1, len2, arr1 = [], arr2 = []\n\nrl.question('', (answer) => {\n len1 = Number(answer);\n rl.question('', (answer) => {\n arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))\n\n rl.question('', (answer) => {\n len2 = Number(answer);\n rl.question('', (answer) => {\n arr2 = (answer.split(' ').slice(0, len2)).map((x) => Number(x));\n //here call function\n console.log(check(arr1, arr2).join(' '));\n })\n });\n\n })\n});\n\n\nfunction check(a, b) {\n// console.log('*************');\n// console.log(arr1);\n// console.log(arr2);\n for (let i = 0; i < a.length; i++) {\n for (let k = 0; k < b.length; k++) {\n const sum = a[i] + b[k]\n if (!a.includes(sum) && !b.includes(sum)) {\n return [a[i], b[k]]\n }\n }\n }\n return [];\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet a, b;\n\nrl.on('line', (d) => {\n if (c === 1) {\n a = d.split(' ').map(Number).sort((a, b) => b - a)[0];\n }\n\n if (c === 3) {\n b = d.split(' ').map(Number).sort((a, b) => b - a)[0];\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(a, b);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', function (arr1Size) {\n rl.question('', function (arr1) {\n rl.question('', function (arr2Size) {\n rl.question('', function (arr2) {\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1Size = Number(arr1Size)\n arr2Size = Number(arr2Size)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n console.log(notBelongs[0].join(' ').trim())\n });\n });\n });\n});"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });;\nvar m = readline();\nvar b = readline().split(\" \").map(function(x) { return parseInt(x); });;\n\nvar flag = 0;\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++) {\n\n var sum = parseInt(a[i]) + parseInt(b[j]);\n if(!a.includes(sum) && !b.includes(sum)){\n print(a[i] + ' ' + b[j]);\n flag = 1;\n break;\n }\n else\n continue;\n } \n if(flag == 1)\n break;\n}"}, {"source_code": "function input() {\n return [\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n }),\n parseInt(readline().trim()),\n readline()\n .trim()\n .split(\" \")\n .map(function(i) {\n return parseInt(i);\n })\n ];\n}\n\nfunction main() {\n // get input\n var read = input();\n var a = read[1];\n var b = read[3];\n\n var done = false;\n\n a.forEach(function(i) {\n if (done) return 0;\n b.forEach(function(j) {\n if (done) return 0;\n if (a.indexOf(i + j) < 0 && b.indexOf(i + j) < 0) {\n print(i, j);\n done = true;\n }\n });\n });\n}\n\nmain();\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var a = rdArN().sortGt()[0];\n var m = rdN();\n var b = rdArN().sortGt()[0];\n wr(a, b);\n \n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const f = parseInt(readLine().split(' '), 10)\n \n const firstL = readLine().split(' ').map(item => parseInt(item,10))\n const s = parseInt(readLine().split(' '), 10)\n const secondL = readLine().split(' ').map(item => parseInt(item,10))\n \n let uniqueSum = 0\n \n for(let i = 1; i < f ; i++){\n let current = firstL[i]\n let index = i\n \n while(index >= 0 && current < firstL[index - 1]){\n firstL[index] = firstL[index - 1]\n index--\n }\n firstL[index] = current\n }\n for(let j = 1; j < s; j++){\n let current = secondL[j];\n let index = j;\n \n while(index >= 0 && current < secondL[index -1 ]){\n secondL[index] = secondL[index -1 ];\n index--\n }\n }\n \n let array = [firstL.pop(), secondL.pop()];\n \n console.log(array.join(' '))\n \n}"}, {"source_code": "//var input = readline()\n\nvar Max = -9, MAX =-9; \nvar t = parseInt(readline());\nvar ar = readline().split(' ').map(x => parseInt(x));\nMax = Math.max(...ar);\n\nvar k = parseInt(readline());\nvar arr = readline().split(' ').map(x => parseInt(x));\nMAX = Math.max(...arr);\n\nprint(Max +' ' + MAX);\n\n//"}], "negative_code": [{"source_code": "var n = readline();\nvar a = readline().split(' ');\nvar m = readline();\nvar b = readline().split(' ');\nvar flag = 0;\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++) {\n\n var sum = parseInt(a[i]) + parseInt(b[j]);\n if(!a.includes(sum) || !b.includes(sum)){\n print(a[i] + ' ' + b[j]);\n flag = 1;\n break;\n }\n else\n continue;\n } \n if(flag == 1)\n break;\n}"}, {"source_code": "var n = readline();\nvar a = readline().split(' ');\nvar m = readline();\nvar b = readline().split(' ');\nvar flag = 0;\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < m; j++) {\n\n var sum = parseInt(a[i]) + parseInt(b[j]);\n if(!a.includes(sum) && !b.includes(sum)){\n print(a[i] + ' ' + b[j]);\n flag = 1;\n break;\n }\n else\n continue;\n } \n if(flag == 1)\n break;\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN();\n var m = rdN();\n var B = rdArN();\n for (var i = 0; i < n; ++i) {\n for (var j = 0; j < m; ++j) {\n var s = A[i] + B[j];\n if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {\n wr(A[i], B[i]);\n return;\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var A = rdArN();\n var m = rdN();\n var B = rdArN();\n for (var i = 0; i < n; ++i) {\n for (var j = i; j < m; ++j) {\n var s = A[i] + B[j];\n if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {\n wr(A[i], B[i]);\n return;\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "var n = Number(readline());\nvar a = readline();\na = a.split(' ');\na = a.map((x) => Number(x));\nvar m = Number(readline());\nvar b = readline();\nb = b.split(' ');\nb = b.map((x) => Number(x));\na.sort((x) => Number(x));\nb.sort((x) => Number(x));\nprint(String(a[n - 1]) + \" \" + String(b[m - 1])); "}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n\nconst processData = (lines) => {\n const [n, a, m, b] = lines\n\n const A = a.split(' ').map(n => Number(n))\n const B = b.split(' ').map(n => Number(n))\n\n const C = new Set(A.concat(B))\n\n for (let i = 0; i < A.length; i++) {\n for (let j = 0; j < B.length; j++) {\n if (C.has(A[i] + B[j])) {\n console.log(A[i], ' ', B[j])\n return\n }\n }\n }\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n\nconst processData = (lines) => {\n const [n, a, m, b] = lines\n\n const A = a.split(' ').map(n => Number(n))\n const B = b.split(' ').map(n => Number(n))\n\n const C = new Set(A.concat(B))\n\n for (let i = 0; i < A.length; i++) {\n for (let j = 0; j < B.length; j++) {\n if (!C.has(A[i] + B[j])) {\n console.log(A[i], ' ', B[j])\n return\n }\n }\n }\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet len1, len2, arr1 = [], arr2 = []\n\nrl.question('enter arr 1 length?', (answer) => {\n len1 = Number(answer);\n rl.question('enter arr 1 values?', (answer) => {\n arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))\n\n rl.question('enter arr 2 length?', (answer) => {\n len2 = Number(answer);\n rl.question('enter arr 2 values?', (answer) => {\n arr2 = (answer.split(' ').slice(0, len1)).map((x) => Number(x));\n //here call function\n console.log(check(arr1, arr2));\n })\n });\n\n })\n});\n\n\nfunction check(a, b) {\n for (let i = 0; i < a.length; i++) {\n for (let k = 0; k < b.length; k++) {\n const sum = a[i] + b[k]\n if (!a.includes(sum) && !b.includes(sum)) {\n return [a[i], b[k]]\n }\n }\n }\n return [];\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet len1, len2, arr1 = [], arr2 = []\n\nrl.question('', (answer) => {\n len1 = Number(answer);\n rl.question('', (answer) => {\n arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))\n\n rl.question('', (answer) => {\n len2 = Number(answer);\n rl.question('', (answer) => {\n arr2 = (answer.split(' ').slice(0, len1)).map((x) => Number(x));\n //here call function\n console.log(check(arr1, arr2).join(' '));\n })\n });\n\n })\n});\n\n\nfunction check(a, b) {\n for (let i = 0; i < a.length; i++) {\n for (let k = 0; k < b.length; k++) {\n const sum = a[i] + b[k]\n if (!a.includes(sum) && !b.includes(sum)) {\n return [a[i], b[k]]\n }\n }\n }\n return [];\n}\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('arr1Size ? ', function (arr1Size) {\n rl.question('arr1 ? ', function (arr1) {\n rl.question('arr2Size ? ', function (arr2Size) {\n rl.question('arr2 ? ', function (arr2) {\n console.log(arr1Size,arr1 ,arr2Size,arr2, \"wwww\")\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1Size = Number(arr1Size)\n arr2Size = Number(arr2Size)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n console.log(notBelongs[0].join(' ').trim())\n });\n });\n });\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('arr1Size ? ', function (arr1Size) {\n rl.question('arr1 ? ', function (arr1) {\n rl.question('arr2Size ? ', function (arr2Size) {\n rl.question('arr2 ? ', function (arr2) {\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1Size = Number(arr1Size)\n arr2Size = Number(arr2Size)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n console.log(notBelongs[0].join(' ').trim())\n });\n });\n });\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('arr1Size ? ', function (arr1Size) {\n rl.question('arr1 ? ', function (arr1) {\n rl.question('arr2Size ? ', function (arr2Size) {\n rl.question('arr2 ? ', function (arr2) {\n console.log(arr1Size,arr1 ,arr2Size,arr2, \"wwww\")\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n console.log(notBelongs[0].join(' ').trim())\n });\n });\n });\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('arr1Size ? ', function (arr1Size) {\n rl.question('arr1 ? ', function (arr1) {\n rl.question('arr2Size ? ', function (arr2Size) {\n rl.question('arr2 ? ', function (arr2) {\n console.log(arr1Size,arr1 ,arr2Size,arr2, \"wwww\")\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n console.log(notBelongs[0]);\n return\n });\n });\n });\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('arr1Size ? ', function (arr1Size) {\n rl.question('arr1 ? ', function (arr1) {\n rl.question('arr2Size ? ', function (arr2Size) {\n rl.question('arr2 ? ', function (arr2) {\n console.log(arr1Size,arr1 ,arr2Size,arr2, \"wwww\")\n let notBelongs = [];\n arr1 = arr1.split(' ').map(Number)\n arr2 = arr2.split(' ').map(Number)\n arr1.map(aNum => {\n arr2.map(bNum => {\n if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {\n notBelongs.push([aNum, bNum]);\n }\n });\n });\n notBelongs[0].join(' ').trim()\n });\n });\n });\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const f = parseInt(readLine().split(' '), 10)\n \n const firstL = readLine().split(' ').map(item => parseInt(item,10))\n const s = parseInt(readLine().split(' '), 10)\n const secondL = readLine().split(' ').map(item => parseInt(item,10))\n \n let uniqueSum = 0\n \n for(let i = 1; i < f ; i++){\n let current = firstL[i]\n let index = i\n \n while(index >= 0 && current < firstL[index - 1]){\n firstL[index] = firstL[index - 1]\n index--\n }\n firstL[index] = current\n }\n for(let j = 1; j < s; j++){\n let current = secondL[j];\n let index = j;\n \n while(index >= 0 && current < secondL[index -1 ]){\n secondL[index] = secondL[index -1 ];\n index--\n }\n }\n \n uniqueSum = firstL.pop() + secondL.pop()\n console.log(uniqueSum)\n \n}"}], "src_uid": "ec09b2df4ed3abbca4c47f48f12010ca"} {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var n = readline(),\r\n a = readline().split(' ') ,\r\n eCounter = 0 , oCounter = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n if(a[j]%2 === 0 ){\r\n eCounter++;\r\n }\r\n else{\r\n oCounter++;\r\n }\r\n }\r\n if(oCounter > eCounter){\r\n print(eCounter);\r\n }\r\n else{\r\n print(oCounter);\r\n }\r\n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n \n var e = 0\n for(j =1; j <= n * 2;j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var even = 0\n var odd = 0\n var k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(k[l] % 2 === 0){\n even++\n }else{\n odd++\n }\n }\n console.log(Math.min(odd, even))\n }\n }\n \n});\n"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n \n var e = 0\n for(j =1; j <= n * 2;j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var even = 0\n var odd = 0\n var k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(k[l] % 2 === 0){\n even++\n }else{\n odd++\n }\n }\n console.log(Math.min(odd, even))\n }\n }\n \n});"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n var e = 0\r\n for(j = 1; j <= n * 2; j++){\r\n if(j % 2 == 1){\r\n e = lines[j]\r\n }else{\r\n var a = 0\r\n var b = 0\r\n var k = lines[j].split(' ').map(Number)\r\n for(l = 0; l < e; l++){\r\n if(k[l] % 2 == 1){\r\n a ++\r\n }else{\r\n b++\r\n }\r\n }\r\n console.log(Math.min(a,b))\r\n\r\n }\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "//Bismillah\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//started here\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let m = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n let result;\r\n let even = [];\r\n let odd = [];\r\n for (let i = 0; i < m.length; i++) {\r\n if (m[i] % 2 == 0) {\r\n even.push(m[i]);\r\n } else {\r\n odd.push(m[i]);\r\n }\r\n }\r\n\r\n if (even.length === 0 || odd.length === 0) {\r\n result = 0;\r\n } else if (odd.length > even.length) {\r\n result = even.length;\r\n } else if (even.length > odd.length) {\r\n result = odd.length;\r\n } else if (odd.length === even.length) {\r\n result = even.length;\r\n }\r\n\r\n console.log(result);\r\n}\r\n \r\n}"}, {"source_code": "//Bismillah\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n let t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let m = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n let result;\r\n let even = [];\r\n let odd = [];\r\n for (let i = 0; i < m.length; i++) {\r\n if (m[i] % 2 == 0) {\r\n even.push(m[i]);\r\n } else {\r\n odd.push(m[i]);\r\n }\r\n }\r\n\r\n if (even.length === 0 || odd.length === 0) {\r\n result = 0;\r\n } else if (odd.length > even.length) {\r\n result = even.length;\r\n } else if (even.length > odd.length) {\r\n result = odd.length;\r\n } else if (odd.length === even.length) {\r\n result = even.length;\r\n }\r\n\r\n console.log(result);\r\n}\r\n \r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var ans = 0;\n for(j = 0; j < n; j++){\n if(a[j] % 2 == 1){\n ans++;\n }\n }\n console.log(Math.min(ans, n - ans));\n }\n }\n});\n"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var od = 0;\n var ev = 0;\n for(j = 0; j < e; j++){\n if(k[j] % 2 == 1){\n od++;\n }else{\n ev++;\n }\n }\n console.log(Math.min(od, ev));\n }\n }\n});\n\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let odd = arr.filter(x => x % 2 === 1).length;\r\n let even = arr.filter(x => x % 2 === 0).length;\r\n\r\n if (odd > even) {\r\n output(arr.length - odd);\r\n } else {\r\n output(arr.length - even);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\n \r\nconst conIO = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n \r\nconIO.setPrompt('');\r\n \r\nfunction reallyAwkward(n) {\r\n conIO.once('line', () => {\r\n conIO.once('line', arr => {\r\n arr = arr.split(' ');\r\n let oddCnt = 0, evenCnt = 0;\r\n arr.forEach(x => x % 2 === 0 ? ++evenCnt : ++oddCnt);\r\n console.log(Math.min(oddCnt, evenCnt));\r\n if (n != 1)\r\n reallyAwkward(n - 1);\r\n else conIO.close();\r\n });\r\n });\r\n}\r\n \r\nconIO.once('line', n => {\r\n reallyAwkward(n);\r\n});"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let ans1 = 0;\n let ans2 = 0;\n for (let i=0; i {\n resolvePromise = res;\n });\n\n function waitUntilDone() {\n return donePromise;\n }\n\n /**\n * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }\n */\n const stack = [];\n let pc = -1;\n\n function finished() {\n if (pc >= instructions.length) {\n return true;\n }\n return false;\n }\n\n function checkFinished() {\n // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);\n if (pc >= instructions.length) {\n return true;\n }\n if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {\n return true;\n }\n return false;\n }\n\n function getNextInstructionContext() {\n if (!stack.length) {\n return {\n index: ++pc,\n }\n }\n const lastStack = stack[stack.length - 1];\n if (lastStack.pointer === lastStack.instructionCount) {\n lastStack.pointer = 0;\n lastStack.iteration = lastStack.iteration + 1;\n }\n if (lastStack.count === lastStack.iteration) {\n stack.pop();\n pc = lastStack.basePointer + lastStack.instructionCount + 1;\n return {\n index: pc,\n }\n }\n\n lastStack.pointer = lastStack.pointer + 1;\n return {\n index: lastStack.basePointer + lastStack.pointer,\n context: {\n namedPath: [...lastStack.context.namedPath, lastStack.iteration]\n }\n }\n }\n\n function pushRepeatToStack(instruction, index, context) {\n stack.push({\n type: 'repeat',\n count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],\n iteration: 0,\n basePointer: index,\n pointer: 0,\n instructionCount: instruction.instructionCount,\n context: {\n namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],\n }\n })\n setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);\n }\n\n function nextInstruction() {\n if (finished()) {\n // console.warn('Calling nextInstruction after finished, something is wrong');\n return;\n }\n while (true) {\n const { index, context } = getNextInstructionContext();\n const instruction = instructions[index];\n\n // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);\n switch (instruction.type) {\n case 'number':\n case 'array':\n return {\n ...instruction,\n namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,\n }\n case 'repeat':\n pushRepeatToStack(instruction, index, context);\n break;\n default:\n // console.warn('Unclear instruction, abort');\n return;\n }\n }\n }\n\n function getIn(object, path) {\n for (let i = 0; i < path.length; ++i) {\n object = object[path[i]];\n }\n return object;\n }\n\n function setIn(object, path, value) {\n for (let i = 0; i < path.length - 1; ++i) {\n if (object[path[i]] == null) {\n object[path[i]] = {};\n }\n object = object[path[i]];\n }\n object[path[path.length - 1]] = value;\n }\n\n rl.on('line', line => {\n if (finished()) {\n return;\n }\n const { type, namedPath } = nextInstruction();\n switch (type) {\n case 'number':\n if (namedPath) {\n setIn(mappedVariables, namedPath, parseInt(line));\n }\n break;\n case 'array':\n if (namedPath) {\n setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));\n }\n break;\n default:\n // console.warn(`Value unread, received type ${type}.`);\n }\n\n if (checkFinished()) {\n resolvePromise(mappedVariables);\n rl.close();\n }\n });\n return {\n waitUntilDone,\n };\n}\n\nfunction solve({numbers}) {\n if (numbers.length === 1) {\n return 1;\n } else if (numbers.length === 2) {\n return (numbers[0] + numbers[1]) % 2 === 0 ? 0 : 2;\n }\n\n /**\n * Min case:\n * 1 2 3\n * [0, 1, 2] length = 3\n */\n\n const chunks = [0];\n for (let i = 1; i < numbers.length; ++i) {\n if ((numbers[i] + numbers[i - 1]) % 2 !== 0) {\n chunks.push(i);\n }\n }\n let firstSum = 0;\n for (let i = 0; i < chunks.length; i = i + 2) {\n if (i === chunks.length - 1) {\n firstSum = firstSum + numbers.length - chunks[i];\n } else {\n firstSum = firstSum + chunks[i + 1] - chunks[i];\n }\n }\n\n let secondSum = 0;\n for (let i = 1; i < chunks.length; i = i + 2) {\n if (i === chunks.length - 1) {\n secondSum = secondSum + numbers.length - chunks[i];\n } else {\n secondSum = secondSum + chunks[i + 1] - chunks[i];\n }\n }\n\n return Math.min(firstSum, secondSum);\n}\n(async function main() {\n const reader = createCLIReader([\n { type: 'number', namedVariable: 'numberOfTestCase' },\n { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },\n { type: 'number', namedVariable: 'testCaseLength' },\n { type: 'array', namedVariable: 'numbers' }\n ]);\n const schema = await reader.waitUntilDone();\n\n for (let i = 0; i < schema.numberOfTestCase; ++i) {\n console.log(solve(schema.testCase[i]));\n }\n})();\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n\r\n let t = readSingleInt();\r\n while(t--)\r\n {\r\n let n = readSingleInt();\r\n let ar = readIntArray();\r\n let cnt =0;\r\n ar.forEach(n=> cnt += n&1)\r\n console.log(Math.min(n-cnt,cnt));\r\n\r\n }\r\n\r\n}"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n const results = [];\r\n for (let tc = 0; tc < T; tc++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const evenCnt = A.reduce((acc, v) => acc + ((v & 1) === 0 ? 1 : 0), 0);\r\n const oddCnt = N - evenCnt;\r\n results.push(Math.min(N - evenCnt, N - oddCnt));\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "function solve() {\r\n const n = Number(read());\r\n const a = readArray(Number);\r\n let oddCount = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] & 1) {\r\n oddCount++;\r\n }\r\n }\r\n write(Math.min(oddCount, n - oddCount));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let odd = 0,\r\n even = 0;\r\n for (let num of a) {\r\n if (num & 1) odd++;else even++;\r\n }\r\n return Math.min(odd, even);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "\r\n /////////////////////////// JavaScript Lover /////////////////////////////////////\r\n //////////////////// ShixyCat //////////////////////////////\r\n \r\n \r\nvar n = readline()\r\nfor(var k=0; k +x)\r\n sumOne = 0\r\n sumTwo = 0\r\n for(i=0; i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var even = 0\n var odd = 0\n var e = 0\n for(j =1; j <= n * 2;j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(k[l] % 2 === 0){\n even++\n }else{\n odd++\n }\n }\n console.log(Math.min(odd, even))\n }\n }\n \n});"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n var e = 0\r\n for(j = 1; j <= n * 2; j++){\r\n if(j % 2 == 1){\r\n e = lines[j]\r\n }else{\r\n var a = 0\r\n var k = lines[j].split(' ').map(Number)\r\n for(l = 0; l < e; l++){\r\n if(k[l] % 2 == 1){\r\n a ++\r\n }\r\n }\r\n console.log(a)\r\n\r\n }\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n var e = 0\r\n for(j = 1; j <= n * 2; j++){\r\n if(j % 2 == 1){\r\n e = lines[j]\r\n }else{\r\n var a = 0\r\n var k = lines[j].split(' ').map(Number)\r\n for(l = 0; l < e; l++){\r\n if(k % 2 == 1){\r\n a ++\r\n }\r\n }\r\n console.log(a)\r\n\r\n }\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n var n = lines[0]\r\n var e = 0\r\n for(j = 1; j <= n * 2; j++){\r\n if(j % 2 == 1){\r\n e = lines[j]\r\n }else{\r\n var a = 0\r\n var k = lines[j].split(' ').map(Number)\r\n for(l = 0; l < e; l++){\r\n if(k % 2 == 1){\r\n a ++\r\n }\r\n }\r\n }\r\n console.log(a)\r\n }\r\n\r\n});\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0\n \n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var s = 0\n var a = lines[j].split(' ').map(Number)\n for(k = 0; k < e; k++){\n if(a[k] % 2 == 1 && a[k + 1] % 2 === 0 || a[k] % 2 === 0 && a[k + 1] % 2 == 1 ){\n s++\n k++\n }else{\n continue;\n }\n }\n console.log(s)\n }else{\n e = lines[j]\n }\n }\n}); \n"}, {"source_code": "//Bissmillah.\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\nlet t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let m = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n let result;\r\n let even = [];\r\n let odd = [];\r\n for (let i = 0; i < m.length; i++) {\r\n if (m[i] % 2 == 0) {\r\n even.push(m[i]);\r\n } else {\r\n odd.push(m[i]);\r\n }\r\n }\r\n\r\n if (even.length === 0 || odd.length === 0) {\r\n result = 0;\r\n } else if (even.length > odd.length) {\r\n result = odd.length;\r\n } else {\r\n result = 0;\r\n }\r\n\r\n console.log(result);\r\n}\r\n \r\n}"}, {"source_code": "//Bissmillah.\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\nlet t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let m = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n let result;\r\n let even = [];\r\n let odd = [];\r\n for (let i = 0; i < m.length; i++) {\r\n if (m[i] % 2 == 0) {\r\n even.push(m[i]);\r\n } else {\r\n odd.push(m[i]);\r\n }\r\n }\r\n\r\n if (even.length === 0 || odd.length === 0) {\r\n result = 0;\r\n } else if (odd.length > even.length) {\r\n result = even.length;\r\n } else if (even.length > odd.length) {\r\n result = odd.length;\r\n } else if (odd.length === even.length) {\r\n result = m.length;\r\n }\r\n\r\n console.log(result);\r\n}\r\n \r\n}"}, {"source_code": "//Bissmillah.\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\nlet t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n let n = parseInt(readline());\r\n let m = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n let result;\r\n let even = [];\r\n let odd = [];\r\n for (let i = 0; i < m.length; i++) {\r\n if (m[i] % 2 == 0) {\r\n even.push(m[i]);\r\n } else {\r\n odd.push(m[i]);\r\n }\r\n }\r\n\r\n if (even.length == 0 || odd.length == 0) {\r\n result = 0;\r\n } else if (odd.length > even.length) {\r\n result = even.length;\r\n } else if (even.length > odd.length) {\r\n result = odd.length;\r\n } else {\r\n result = 0;\r\n }\r\n\r\n console.log(result);\r\n}\r\n \r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let odd = arr.filter(x => x % 2 === 1).length;\r\n let even = arr.filter(x => x % 2 === 0).length;\r\n\r\n if (odd > even) {\r\n output(arr.length - even);\r\n } else {\r\n output(arr.length - odd);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\n\r\nconst conIO = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconIO.setPrompt('');\r\n\r\nfunction reallyAwkward(n) {\r\n conIO.once('line', () => {\r\n conIO.once('line', arr => {\r\n arr = arr.split(' ');\r\n let oddCnt = 0, evenCnt = 0;\r\n arr.forEach(x => x % 2 == 0 ? ++evenCnt : ++oddCnt);\r\n conIO.write(Math.min(oddCnt, evenCnt) + '\\n');\r\n if (n != 1)\r\n reallyAwkward(n - 1);\r\n else conIO.close();\r\n });\r\n });\r\n}\r\n\r\nconIO.once('line', n => {\r\n reallyAwkward(n);\r\n});"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let ans = 0;\n for (let i=0; i {\n console.log(`Received: ${line}`);\n });\n})();\n"}, {"source_code": "\r\n /////////////////////////// JavaScript Lover /////////////////////////////////////\r\n //////////////////// ShixyCat //////////////////////////////\r\n \r\n \r\nvar n = readline()\r\nfor(var k=0; k -1; l--)\n\t\t\tif (t[l]) break;\n\t\tif (!t[l]) l = -1;\n\n\t\tif (r == -1 && l == -1) {\n\t\t\tif (p == 0) {\n\t\t\t\tstr += 'R';\n\t\t\t\tp++;\n\t\t\t}\n\n\t\t\tif (p == (n-1)) {\n\t\t\t\tstr += 'L';\n\t\t\t\tp--;\n\t\t\t}\n\t\t} else {\n\t\t\tif (r > l) {\n\t\t\t\tstr += 'R';\n\t\t\t\tp++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tstr += 'L';\t\n\t\t\t\tp--;\n\t\t\t}\n\t\t}\n\n\t}\n\n\tprint(str);\n\n}).call(this)"}, {"source_code": "var\n num = parseInt(readline()),\n k = readline().split(\" \"),\n sum = 0,\n length = k.length - 1\n pos = 0,\n cur = 0,\n str = \"\"\n;\n\nfor(var i in k) {\n k[i] = parseInt(k[i]);\n sum += k[i];\n}\n\nwhile(1){\n\n if (k[pos] > 0) {\n str += \"P\";\n cur ++;\n k[pos]--;\n if (cur == sum) break;\n }\n\n if (pos == length) {\n pos -= 1;\n str += \"L\";\n continue;\n }\n\n if (pos > 0 && k[pos-1] > 0) {\n pos--;\n str += \"L\";\n } else {\n pos++;\n str += \"R\";\n }\n}\n\nprint(str);"}, {"source_code": "function main(){\n var i, n = parseInt(readline());\n var a = readline().split(' ');\n for(i = 0 ; i < n ; ++i){\n a[i] = parseInt(a[i]);\n }\n var last = 0, str = \"\";\n for(i = 0 ; i < n - 1 ; ++i){\n if ( i ){\n str+=\"R\";\n }\n while ( a[i] > 0 ){\n str += \"P\";\n --a[i];\n if ( a[i] > 0 ){\n str += \"RL\";\n }\n }\n\n }\n if ( a[n-1] > 0 ){\n str += \"R\";\n }\n while( a[n-1] > 0 ){\n str += \"P\";\n --a[n-1];\n if ( a[n-1] > 0 ){\n str += \"LR\";\n }\n }\n print(str);\n}\nmain();"}, {"source_code": "var n = 0;\nvar arr;\nvar ans = \"\";\n\nn = readline();\narr = readline().split(\" \");\n\nfor(var i=0; i0) {\n if(!first) {\n if(i==0) {\n ans += 'RL';\n } else {\n ans += 'LR';\n }\n }\n first = false;\n ans += \"P\";\n arr[i]--;\n }\n if(i max){max = mas[i];}\n}\nmax *= 2;\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0 && i != 0){mas[i] --; str += \"P\";}\n if(i != n-1){str += \"R\";}\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0 && i != n-1){mas[i] --; str += \"P\";}\n if(i != 0){str += \"L\";}\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}], "negative_code": [{"source_code": "var n = parseInt( readline() );\nvar m0 = readline().split(' ').map(function(v){ return parseInt(v); });\nvar m1 = [];\nfor(var i=0; i0) {\n if(!first) {\n if(i==0) {\n ans += 'RL';\n } else {\n ans += 'LR';\n }\n }\n first = !first;\n ans += \"P\";\n arr[i]--;\n }\n if(i max){max = mas[i];}\n}\nmas[0] --;\nstr = \"P\";\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0 && i != 0){mas[i] --; str += \"P\";}\n if(i != n-1){str += \"R\";}\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0 && i != n-1){mas[i] --; str += \"P\";}\n if(i != 0){str += \"L\";}\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nvar str = \"\";\nmas = mas.split(\" \");\nvar max = 0;\nfor(var i = 0; i < n; ++i)\n{\n mas[i] = parseInt(mas[i]);\n if(mas[i] > max){max = mas[i];}\n}\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0 && i != 0){mas[i] --; str += \"P\";}\n if(i != n-1){str += \"R\";}\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0 && i != n-1){mas[i] --; str += \"P\";}\n if(i != 0){str += \"L\";}\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nvar str = \"\";\nmas = mas.split(\" \");\nvar max = 0;\nfor(var i = 0; i < n; ++i)\n{\n mas[i] = parseInt(mas[i]);\n if(mas[i] > max){max = mas[i];}\n}\nmas[0] --;\nstr = \"P\";\nmax *= 2;\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0 && i != 0){mas[i] --; str += \"P\";}\n if(i != n-1){str += \"R\";}\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0 && i != n-1){mas[i] --; str += \"P\";}\n if(i != 0){str += \"L\";}\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nvar str = \"\";\nmas = mas.split(\" \");\nvar max = 0;\nfor(var i = 0; i < n; ++i)\n{\n mas[i] = parseInt(mas[i]);\n if(mas[i] > max){max = mas[i];}\n}\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0){mas[i] --; str += \"P\";}\n if(i != n-1){str += \"R\";}\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0){mas[i] --; str += \"P\";}\n if(i != 0){str += \"L\";}\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nvar str = \"\";\nmas = mas.split(\" \");\nvar max = 0;\nfor(var i = 0; i < n; ++i)\n{\n mas[i] = parseInt(mas[i]);\n if(mas[i] > max){max = mas[i];}\n}\nwhile(max != 0)\n{\n for(var i = 0; i < n; ++i)\n {\n if(mas[i] != 0){mas[i] --; str += \"P\";}\n str += \"R\";\n }\n max --;\n if(max == 0){break;}\n for(var i = n-1; i >= 0; --i)\n {\n if(mas[i] != 0){mas[i] --; str += \"P\";}\n str += \"L\";\n }\n max --;\n if(max == 0){break;}\n}\nprint(str);"}, {"source_code": "var line1 = readline().split(' ');\nvar n = parseInt(line1[0]);\nvar line2 = readline().split(' ');\n\tvar total = [], put=[];\n\tvar total_sum=0, put_sum=0;\n\n\tfor (var i=0; i < n; i++){\n\ttotal[i] = parseInt(line2[i]);\n\ttotal_sum+=total[i];\n\tput[i] = 0;\n\t}\n\n\nvar max = Math.max.apply(null, total); \nres='';\n\n\nfor (var i=0; i < max; i++) {\n\n\tfor (var k=0; k < n; k++){\n\n\t\tif ( i%2==0) {\n\n\t\t\tif (put[k] < total[k] && res.slice(-1)!='P'){\n\t\t\tres+='P';\n\t\t\tput_sum++;\n\t\t\t}\n\n\t\t\tif (put_sum < total_sum && k!=n-1){\n\t\t\n\t\t\tres+='R'\n\n\t\t\t}\n\n\t\t}\n\n\t\telse{\n\n\t\t\tif (put[n-k-1] < total[n-k-1] && res.slice(-1)!='P') {\n\t\t\tres+='P';\n\t\t\tput_sum++;\n\t\t\t}\n\n\t\t\tif (put_sum < total_sum && k!=n-1) {\n\t\t\n\t\t\tres+='L'\n\n\t\t\t}\n\n\n\t\t}\n\n\t\t\n\t\n\n\t}\n\n}\n\n\n\nprint(res);"}, {"source_code": "var line1 = readline().split(' ');\nvar n = parseInt(line1[0]);\nvar line2 = readline().split(' ');\n\tvar total = [], put=[];\n\n\tfor (var i=0; i < n; i++){\n\ttotal[i] = parseInt(line2[i]);\n\tput[i] = 0;\n\t}\n\n\nvar max = Math.max.apply(null, total); \nres='';\n\n\nfor (var i=0; i < max; i++){\n\n\tfor (var k=0; k < n; k++){\n\n\t\tif (put[k] < total[k] && res.slice(-1)!='P') res+='P';\n\t\tif ( (k!=n-1) && i%2==0) res+='R'\n\t\t\telse if ( (k!=n-1) && i%2==1) res+='L';\n\n\t}\n\n\n}\n\n\n\nprint(res);"}, {"source_code": "var line1 = readline().split(' ');\nvar n = parseInt(line1[0]);\nvar line2 = readline().split(' ');\n\tvar total = [], put=[];\n\n\tfor (var i=0; i < n; i++){\n\ttotal[i] = parseInt(line2[i]);\n\tput[i] = 0;\n\t}\n\n\nvar max = Math.max.apply(null, total); \t\t\t\tprint(max+\"\\n\");\n\nres='';\n\n\nfor (var i=0; i < max; i++){\n\n\tfor (var k=0; k < n; k++){\n\n\t\tif (put[k] < total[k] && res.slice(-1)!='P') res+='P';\n\t\tif ( (k!=n-1) && i%2==0) res+='R'\n\t\t\telse if ( (k!=n-1) && i%2==1) res+='L';\n\n\t}\n\n\n}\n\n\n\nprint(res);"}, {"source_code": "var n = parseInt( readline() );\nvar m0 = readline().split(' ').map(function(v){ return parseInt(v); });\nvar m1 = [];\nfor(var i=0; i parseInt(v))\nlet H = lll[0]\nlet W = lll[1]\n\nlet ph = -1\nwhile (ph++ < 30) {\n let ch = Math.pow(2, ph)\n if (ch > H || ch * 0.8 > W) {ph--; break}\n}\nlet ch = Math.pow(2, ph)\n\nlet pw = -1\nwhile (pw++ < 30) {\n let cw = Math.pow(2, pw)\n if (cw > W || cw * 0.8 > H) {pw--; break}\n}\nlet cw = Math.pow(2, pw)\n\nlet sh = ch * Math.min(ch * 1.25, W)\nlet sw = cw * Math.min(cw * 1.25, H)\n\nif (sh > sw) {\n print(ch + ' ' + Math.floor(Math.min(ch * 1.25, W)))\n} else if (sw > sh) {\n print(Math.floor(Math.min(cw * 1.25, H)) + ' ' + cw)\n} else {\n print(ch > cw * 1.25 ? ch + ' ' + Math.floor(Math.min(ch * 1.25, W)) : Math.floor(Math.min(cw * 1.25, H)) + ' ' + cw)\n}", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction solve(height, width) {\n\tvar subHeight = Math.pow(2, Math.floor(Math.log(height) / Math.log(2)));\n\twhile (true) {\n\t\tvar subWidth = Math.min(width, Math.floor(5*subHeight/4));\n\t\tif (subWidth >= Math.ceil(4*subHeight/5)) {\n\t\t\treturn { height: subHeight, width: subWidth,\n\t\t\t\t\t getArea: function() {\n\t\t\t\t\t\t return this.height * this.width;\n\t\t\t\t\t },\n\t\t\t\t\t toString: function() {\n\t\t\t\t\t\t return this.height+\" \"+this.width;\n\t\t\t\t\t },\n\t\t\t\t\t rotate: function() {\n\t\t\t\t\t\t var temp = this.height;\n\t\t\t\t\t\t this.height = this.width;\n\t\t\t\t\t\t this.width = temp;\n\t\t\t\t\t }\n\t\t\t};\n\t\t}\n\t\tsubHeight /= 2;\n\t}\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar height = data[0], width = data[1];\n\n\tvar solutionA = solve(height, width), areaA = solutionA.getArea(),\n\t\tsolutionB = solve(width, height), areaB = solutionB.getArea();\n\tsolutionB.rotate();\n\n\tif (areaA > areaB || (areaA == areaB && solutionA.height > solutionB.height)) {\n\t\tprint(solutionA.toString());\n\t}\n\telse {\n\t\tprint(solutionB.toString());\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction solve(height, width) {\n\tvar subHeight = Math.pow(2, Math.floor(Math.log(height) / Math.log(2)));\n\twhile (true) {\n\t\tvar subWidth = Math.min(width, Math.floor(5*subHeight/4));\n\t\tif (subWidth >= Math.ceil(4*subHeight/5)) {\n\t\t\treturn { height: subHeight, width: subWidth,\n\t\t\t\t\t getArea: function() {\n\t\t\t\t\t\t return this.height * this.width;\n\t\t\t\t\t },\n\t\t\t\t\t toString: function() {\n\t\t\t\t\t\t return this.height+\" \"+this.width;\n\t\t\t\t\t },\n\t\t\t\t\t rotate: function() {\n\t\t\t\t\t\t var temp = this.height;\n\t\t\t\t\t\t this.height = this.width;\n\t\t\t\t\t\t this.width = temp;\n\t\t\t\t\t }\n\t\t\t};\n\t\t}\n\t\tsubHeight /= 2;\n\t}\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar height = data[0], width = data[1];\n\tvar solutionA = solve(height, width), areaA = solutionA.getArea(),\n\t\tsolutionB = solve(width, height), areaB = solutionB.getArea();\n\n\tsolutionA.rotate();\n\n\tif (areaA > areaB || (areaA == areaB && solutionA.height > solutionB.height)) {\n\t\tprint(solutionA.toString());\n\t}\n\telse {\n\t\tprint(solutionB.toString());\n\t}\n}\n\nmain();\n"}], "src_uid": "57d2eb75a14f1b66009bdb503fd31f91"} {"source_code": "var N = 1e6 + 5;\nvar p = new Int8Array( N );\n\np[0] = p[1] = 1;\n\nfor( var j = 2; j*2 < N; j++ )\n\tp[ j*2 ] = 1;\n\nfor( var i = 3; i < N; i+=2 )\n\tif( !p[i] )\n\t\tfor( var j = i*i; j < N; j+=i )\n\t\t\tp[ j ] = 1;\n\n\nreadline();\nvar ret = readline()\n\t\t\t.split(' ')\n\t\t\t.map(Math.sqrt)\n\t\t\t.map(function(v){\n\t\t\t\treturn v%1===0&&p[v]===0 ? 'YES' : 'NO';\n\t\t\t});\n\nprint(ret.join('\\n'));", "positive_code": [{"source_code": "var prime = new Array(Math.pow(10, 6));\nprime[0] = true;\nprime[1] = true;\n\nvar tPrimes = new Set();\n\nfunction getAllPrimes(){\n for(var i = 2; i <= Math.pow(10, 6); i++){\n if(prime[i] === undefined){\n // number is unmarked so we know it's prime\n prime[i] = true;\n var j = i * i;\n while(j <= Math.pow(10, 6)){\n prime[j] = false;\n j = j + i;\n }\n }\n }\n}\n\nfunction getAllTPrimes(){\n for(var i = 2; i < prime.length; i++){\n if(prime[i] === true) {\n tPrimes.add(i * i);\n }\n }\n}\n\ngetAllPrimes();\ngetAllTPrimes();\n\nfunction isTPrime(number){\n if(tPrimes.has(number)){\n print(\"YES\");\n }\n else {\n print(\"NO\");\n }\n}\n\nconst line1 = readline();\nconst line2 = readline().split(\" \").map(x => parseInt(x));\nfor(var i = 0; i < line2.length; i++){\n isTPrime(line2[i]);\n}"}, {"source_code": "var i, j, l,\n\tsqrt = Math.sqrt,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 4; j < N; j += 2)\n\tp[j] = 1;\n\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n\tif (!p[i])\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\nreadline();\nprint(readline().replace(/\\s*\\d+/g, function(v) {\n\tv = sqrt(+v);\n\treturn v % 1 === 0 && p[v] === 0 ? 'YES\\n' : 'NO\\n';\n}));"}, {"source_code": "var i, j, l,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 2; j * 2 < N; j++)\n\tp[j * 2] = 1;\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n\tif (!p[i])\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\nreadline();\nprint(readline().split(' ').map(function(v) {\n\tv = Math.sqrt(v);\n\treturn v % 1 === 0 && p[v] === 0 ? 'YES' : 'NO';\n}).join('\\n'));\n"}, {"source_code": "var i, j, l,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 2; j * 2 < N; j++)\n\tp[j * 2] = 1;\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n\tif (!p[i])\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\nreadline();\nprint(readline().split(' ').map(Math.sqrt).map(function(v) {\n\treturn v % 1 === 0 && p[v] === 0 ? 'YES' : 'NO';\n}).join('\\n'));"}, {"source_code": "var i, j, l,\n sqrt = Math.sqrt,\n N = 1e6 + 5,\n p = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 4; j < N; j += 2)\n p[j] = 1;\n\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n if (!p[i])\n for (var j = i * i; j < N; j += i)\n p[j] = 1;\n\nvar n = readline();\nvar a = readline().split(' ');\nvar ans = [];\nfor (var i = 0; i < n; i++) {\n var v = sqrt(a[i]);\n ans.push(v % 1 === 0 && p[v] === 0 ? 'YES' : 'NO');\n}\nprint(ans.join('\\n'));"}, {"source_code": "var i, j, l,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N),\n\tq = {};\n\np[0] = p[1] = 1;\nq[4] = true;\n\nfor (i = 3; i < N; i += 2)\n\tif (!p[i]) {\n\t\tq[i * i] = true;\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\t}\n\nreadline();\nprint(readline().split(' ').map(function(v) {\n\treturn q[v] ? 'YES' : 'NO';\n}).join('\\n'));"}, {"source_code": "var N = 1e6 + 5;\nvar p = new Int8Array( N );\n\np[0] = p[1] = 1;\n\nfor( var j = 2; j*2 < N; j++ )\n\tp[ j*2 ] = 1;\n\nfor( var i = 3; i < N; i+=2 )\n\tif( !p[i] )\n\t\tfor( var j = 2; j*i < N; j++ )\n\t\t\tp[ j*i ] = 1;\n\n\nreadline();\nvar ret = readline()\n\t\t\t.split(' ')\n\t\t\t.map(Math.sqrt)\n\t\t\t.map(function(v){\n\t\t\t\treturn v%1===0&&p[v]===0 ? 'YES' : 'NO';\n\t\t\t});\n\nprint(ret.join('\\n'));"}, {"source_code": "var N = 1e6 + 5;\nvar p = new Int8Array( N );\n\np[0] = p[1] = 1;\n\nfor( var j = 2; j*2 < N; j++ )\n\tp[ j*2 ] = 1;\n\nfor( var i = 3; i < N; i++ )\n\tif( !p[i] )\n\t\tfor( var j = 2; j*i < N; j++ )\n\t\t\tp[ j*i ] = 1;\n\n\nreadline();\nvar ret = readline()\n\t\t\t.split(' ')\n\t\t\t.map(Math.sqrt)\n\t\t\t.map(function(v){\n\t\t\t\treturn p[v]===0 ? 'YES' : 'NO';\n\t\t\t});\n\nprint(ret.join('\\n'));"}, {"source_code": "var N = 1e6 + 5;\nvar p = new Int8Array( N );\n\np[0] = p[1] = 1;\n\nfor( var j = 2; j*2 < N; j++ )\n\tp[ j*2 ] = 1;\n\nfor( var i = 3, l=Math.sqrt(N); i < l; i+=2 )\n\tif( !p[i] )\n\t\tfor( var j = i*i; j < N; j+=i )\n\t\t\tp[ j ] = 1;\n\n\nreadline();\nvar ret = readline()\n\t\t\t.split(' ')\n\t\t\t.map(Math.sqrt)\n\t\t\t.map(function(v){\n\t\t\t\treturn v%1===0&&p[v]===0 ? 'YES' : 'NO';\n\t\t\t});\n\nprint(ret.join('\\n'));\n"}, {"source_code": "var i, j, l,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N),\n\tq = {};\n\np[0] = p[1] = 1;\nq[4] = true;\n\nfor (i = 3; i < N; i += 2)\n\tif (!p[i]) {\n\t\tq[i * i] = true;\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\t}\n\nreadline();\nprint(readline().split(' ').map(function(v) {\n\treturn q[v] ? 'YES' : 'NO';\n}).join('\\n'));"}, {"source_code": "var i, j, l,\n\tsqrt = Math.sqrt,\n\tN = 1e6 + 5,\n\tp = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 4; j < N; j += 2)\n\tp[j] = 1;\n\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n\tif (!p[i])\n\t\tfor (var j = i * i; j < N; j += i)\n\t\t\tp[j] = 1;\n\nreadline();\nprint(readline().split(' ').map(function(v) {\n\tv = sqrt(+v);\n\treturn v % 1 === 0 && p[v] === 0 ? 'YES' : 'NO';\n}).join('\\n'));"}, {"source_code": "var N = 1e6 + 5;\nvar p = new Int8Array( N );\n\np[0] = p[1] = 1;\n\nfor( var j = 2; j*2 < N; j++ )\n\tp[ j*2 ] = 1;\n\nfor( var i = 3; i < N; i+=2 )\n\tif( !p[i] )\n\t\tfor( var j = 2; j*i < N; j++ )\n\t\t\tp[ j*i ] = 1;\n\n\nreadline();\nvar ret = readline()\n\t\t\t.split(' ')\n\t\t\t.map(Math.sqrt)\n\t\t\t.map(function(v){\n\t\t\t\treturn p[v]===0 ? 'YES' : 'NO';\n\t\t\t});\n\nprint(ret.join('\\n'));"}, {"source_code": "var i, j, l,\n sqrt = Math.sqrt,\n N = 1e6 + 5,\n p = new Int8Array(N);\n\np[0] = p[1] = 1;\nfor (j = 4; j < N; j += 2)\n p[j] = 1;\n\nfor (i = 3, l = Math.sqrt(N); i < l; i += 2)\n if (!p[i])\n for (var j = i * i; j < N; j += i)\n p[j] = 1;\n\nvar n=readline();\nvar a=readline().split(' ')\nvar ans='';\nfor(var i=0; i {\n const sqrt = parseInt(Math.sqrt(num));\n if (num === 1) {\n write('NO\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nfunction primesNums(map) {\n const N = 1e12;\n const sN = Math.trunc(Math.sqrt(N)) + 10;\n\n const nums = new Array(sN).fill(true);\n nums[0] = false;\n nums[1] = false;\n\n let i = 2;\n while (i <= sN) {\n if (nums[i]) {\n map.add(i);\n let j = i + i;\n nums[j] = false;\n while (j <= sN) {\n nums[j] = false;\n j += i;\n }\n nums[j] = false;\n }\n i += 1;\n }\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n const nums = splitAndParseInt(input[1]);\n\n const primes = new Set();\n primesNums(primes);\n\n nums.forEach((x) => {\n const sqrt = Math.sqrt(x);\n if (primes.has(sqrt)) console.log(`YES`);\n else console.log(\"NO\");\n });\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nfunction findAllSimple(map) {\n const N = 1000000000000;\n\n const nums = Array(1000001).fill(true);\n let i = 2; nums[0] = false; nums[1] = false;\n while (i**2 <= 1000000000001) {\n if (nums[i]) {\n map.add(i);\n let j = i ** 2;\n while (j <= 1000001) {\n nums[j] = false;\n j += i;\n }\n }\n i += 1;\n }\n}\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const primeNumbers = new Set();\n\n findAllSimple(primeNumbers);\n \n input[1].split(' ').forEach(x => {\n if (primeNumbers.has(Math.sqrt(x))) console.log(`YES`);\n else console.log('NO');\n });\n}); "}, {"source_code": "var n = parseInt(readline(), 10);\nvar inp = readline().split(' ');\n\nfor(var i=0; i 25) {\n n+=2;\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n }\n})();"}, {"source_code": "'use strict'\nfunction isSimple(num, checkTo) {\n if (num === 2 || num === 3) {\n return true;\n }\n for (let i = 2; i < 4; i++) {\n if (Math.pow(i, num) % num !== i % num) {\n return false;\n }\n }\n return true;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n const sqrt = Math.sqrt(num);\n if (num === 1) {\n write('NO\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt, sqrt + 1)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 2;\n let sqrtI = Math.sqrt(array[i]);\n while(sqrtI) {\n if (sqrtI === parseInt(sqrtI) && n <= 3) {\n n++;\n sqrtI = Math.sqrt(sqrtI);\n } else {\n sqrtI = 0;\n }\n }\n \n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n if (array[i] % 2 === 0 && array[i] !== 4) {\n write('NO');\n break;\n }\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n if (array[i] > 25) {\n n++;\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\nfunction isSimple(num, checkTo) {\n if (num === 2 || num === 3) {\n return true;\n }\n for (let i = 2; i < 4; i++) {\n if (Math.pow(i, num) % num !== i % num) {\n return false;\n }\n }\n return true;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n const sqrt = Math.sqrt(num);\n if (num === 1) {\n write('YES\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt, sqrt + 1)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\nfunction isSimple(num, checkTo) {\n let counter = 0;\n if (num === 2 || num === 3) {\n return true;\n }\n for (let i = 2; i < 5; i++) {\n if (Math.pow(i, num) % num !== i % num) {\n counter++;\n }\n }\n if (counter > 1) {\n return false;\n }\n return true;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n const sqrt = Math.sqrt(num);\n if (num === 1) {\n write('NO\\n');\n } else if(num ===999966000289) {\n write('YES\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt, sqrt + 1)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 2;\n let sqrtI = Math.sqrt(array[i]);\n while(sqrtI) {\n if (sqrtI === parseInt(sqrtI) && n <= 3) {\n n++;\n if (Math.sqrt(sqrtI) === parseInt(Math.sqrt(sqrtI))) {\n sqrtI = Math.sqrt(sqrtI);\n }\n } else {\n if (n <= 3 && sqrtI % 2 === 0 && array[i] !== 4) {\n n++;\n }\n sqrtI = 0;\n }\n }\n \n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n if (array[i] > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n if (array[i] % 2 === 0 && array[i] !== 4) {\n write('NO');\n return;\n }\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n if (array[i] > 25) {\n n++;\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n if (array[i] > 25) {\n n++;\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 2;\n let sqrtI = Math.sqrt(array[i]);\n while(sqrtI) {\n if (sqrtI === parseInt(sqrtI) && n <= 3) {\n n++;\n sqrtI = Math.sqrt(sqrtI);\n if (n <= 3 && sqrtI % 2 === 0 && sqrtI !== 4) {\n n++;\n }\n } else {\n sqrtI = 0;\n }\n }\n \n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 2;\n let sqrtI = Math.sqrt(array[i]);\n while(sqrtI) {\n if (sqrtI === parseInt(sqrtI) && n <= 3) {\n n++;\n sqrtI = Math.sqrt(sqrtI);\n } else {\n if (n <= 3 && sqrtI % 2 === 0 && sqrtI !== 4) {\n n++;\n }\n sqrtI = 0;\n }\n }\n \n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n if (array[i] % 2 === 0 && array[i] !== 4) {\n write('NO\\n');\n } else {\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n if (array[i] > 25) {\n n++;\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n }\n})();"}, {"source_code": "'use strict'\nfunction isSimple(num, checkTo) {\n for (let i = 2; i < checkTo; i++) {\n if (Math.pow(i, num) % num !== i % num) {\n return false;\n }\n }\n return true;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n if (isSimple(Math.sqrt(num), Math.sqrt(num + 1))) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 0;\n if (array[i] % 2 === 0 && array[i] !== 4) {\n write('NO\\n');\n } else {\n for (let j = 1; j <= 25 && n <=3; j++) {\n if (array[i] % j === 0) {\n n++;\n }\n }\n let sqrtI = Math.sqrt(array[i]);\n if (sqrtI=== parseInt(sqrtI) && sqrtI > 25) {\n n++;\n }\n if (array[i] > 25 && sqrtI === parseInt(sqrtI) && sqrtI > 25) {\n n+=2;\n } else if (array[i] > 25) {\n n++;\n }\n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n }\n})();"}, {"source_code": "'use strict'\nlet r;\nfunction getReshetoNum(maxNum) {\n r = new Array(maxNum + 1);\n r[0] = 0;\n r[1] = 0;\n for (let i = 2; i <= Math.sqrt(maxNum + 1); i++) {\n if (r[i] === undefined) {\n for (let j = i + i; j <= maxNum; j += i) {\n r[j] = 1;\n }\n }\n }\n}\n\ngetReshetoNum(1000000);\n\nfunction isSimple(num) {\n\n if (r[num] === undefined) {\n return true;\n }\n return false;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n const sqrt = Math.sqrt(num);\n if (num === 1) {\n write('NO\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\nfunction isSimple(num, checkTo) {\n if (num === 2 || num === 3) {\n return true;\n }\n for (let i = 2; i < 4; i++) {\n if (Math.pow(i, num) % num !== i % num) {\n return false;\n }\n }\n return true;\n}\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nreadline();\nlet array = readline().getNumArray();\narray.map((num) => {\n const sqrt = Math.sqrt(num);\n if (num === 1) {\n write('NO\\n');\n } else if(num ===999966000289) {\n write('YES\\n');\n } else if (sqrt * sqrt === num && isSimple(sqrt, sqrt + 1)) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n});"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n readline();\n let array = readline().getNumArray();\n for (let i = 0; i < array.length; i++) {\n let n = 2;\n let sqrtI = Math.sqrt(array[i]);\n while(sqrtI) {\n if (sqrtI === parseInt(sqrtI) && n <= 3) {\n n++;\n sqrtI = Math.sqrt(sqrtI);\n } else {\n sqrtI = 0;\n }\n\n if (n <= 3 && sqrtI % 2 === 0 && sqrtI !== 4) {\n n++;\n }\n\n }\n \n if (n === 3) {\n write('YES\\n');\n } else {\n write('NO\\n');\n }\n }\n})();"}, {"source_code": "var n = parseInt(readline(), 10);\nvar inp = readline().split(' ');\n\nfor(var i=0; i parseInt(x));\n}\n\nfunction primesNums(map) {\n const N = 1e12 + 10;\n const sN = Math.trunc(Math.sqrt(N));\n\n const nums = new Array(sN).fill(true);\n nums[0] = false;\n nums[1] = false;\n\n let i = 2;\n while (i <= sN) {\n if (nums[i]) {\n map.add(i);\n let j = i + i;\n while (j <= sN) {\n nums[j] = false;\n j += j;\n }\n }\n i += 1;\n }\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n const nums = splitAndParseInt(input[1]);\n\n const primes = new Set();\n primesNums(primes);\n\n nums.forEach((x) => {\n const sqrt = Math.sqrt(x);\n\n if (primes.has(sqrt)) console.log(`YES`);\n else console.log(\"NO\");\n });\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nfunction findAllSimple(map) {\n const N = 1000001;\n\n const nums = Array(N).fill(true);\n let i = 2; nums[0] = false; nums[1] = false;\n while (i**2 <= N) {\n if (nums[i]) {\n map.add(i);\n let j = i ** 2;\n while (j <= N) {\n nums[j] = false;\n j += i;\n }\n }\n i += 1;\n }\n}\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const primeNumbers = new Set();\n\n findAllSimple(primeNumbers);\n\n input[1].split(' ').forEach(x => {\n if (primeNumbers.has(Math.sqrt(x))) console.log(`YES`);\n else console.log('NO');\n });\n}); "}], "src_uid": "6cebf9af5cfbb949f22e8b336bf07044"} {"source_code": "T = readline()\r\nwhile(T--){\r\n nn = readline()\r\n\r\n nk = readline().split(' ').map(el => +el)\r\n n = nk[0]\r\n k = nk[1]\r\n\r\n x = readline().split(' ').map(el => +el)\r\n obj ={}\r\n for(i = 0; i< n; i++){\r\n obj[x[i]] = i\r\n }\r\n\r\n obj2 ={}\r\n for(i = x.length-1; i>=0 ; i--){\r\n obj2[x[i]] = i\r\n }\r\n\r\n\r\n while(k--){\r\n\r\n ans = 'NO'\r\n ab = readline().split(' ').map(el => +el)\r\n a = ab[0]\r\n b = ab[1]\r\n\r\n\r\n if(obj2[a] != undefined){\r\n if(obj[b] > obj2[a])\r\n ans = 'YES'\r\n }\r\n print(ans)\r\n }\r\n}", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n// console.log(input)\r\nvar T = readline();\r\n// var inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var nul = readline();\r\n var [n,k] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var mx = new Map();\r\n var mn = new Map();\r\n var cnt = 0;\r\n var ans = 1;\r\n for(var i=0;i parseInt(x));\r\n\r\n if(!mx.has(b) || !mx.has(c)) console.log(\"No\");\r\n else if(mx.get(b) >= mn.get(c)) console.log(\"Yes\")\r\n else console.log(\"No\")\r\n }\r\n // console.log(ans)\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const l = new Map(),\r\n r = new Map();\r\n for (let [i, num] of a.entries()) {\r\n var _l$get, _r$get;\r\n l.set(num, Math.min((_l$get = l.get(num)) !== null && _l$get !== void 0 ? _l$get : Infinity, i));\r\n r.set(num, Math.max((_r$get = r.get(num)) !== null && _r$get !== void 0 ? _r$get : -Infinity, i));\r\n }\r\n let res = [];\r\n for (let [start, end] of b) {\r\n if (!l.has(start) || !l.has(end)) res.push('NO');else {\r\n if (l.get(start) <= r.get(end)) {\r\n res.push('YES');\r\n } else {\r\n res.push('NO');\r\n }\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const map = {}\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n map[x] = map[x] || []\n map[x].push(i)\n }\n return qs.map(([a, b]) => {\n if (!map[a] || !map[b]) return 'NO'\n a = map[a][0]\n b = map[b][map[b].length - 1]\n return a < b ? 'YES' : 'NO'\n }).join('\\n')\n}\n"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar t = readInt();\r\n\tvar allans = [];\r\n\tfor (var zz = 0; zz < t; zz++) {\r\n\t\treadline();\r\n\t\tvar input = readIntArr();\r\n\t\tvar n = input[0];\r\n\t\tvar q = input[1];\r\n\t\tvar u = readIntArr();\r\n\t\tvar firstIdx = new Object();\r\n\t\tvar lastIdx = new Object();\r\n\t\tvar vi = new Set();\r\n\t\tfor (var i = 0; i < n; i++) {\r\n\t\t\tvar z = u[i];\r\n\t\t\tif (!vi.has(z)) {\r\n\t\t\t\tfirstIdx[z] = i;\r\n\t\t\t\tvi.add(z);\r\n\t\t\t}\r\n\t\t\tlastIdx[z] = i;\r\n\t\t}\r\n\t\tfor (var yy = 0; yy < q; yy++) {\r\n\t\t\tinput = readIntArr();\r\n\t\t\tvar a = input[0];\r\n\t\t\tvar b = input[1];\r\n\t\t\tif (!vi.has(a) || !vi.has(b)) {\r\n\t\t\t\tallans.push('NO');\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar aFirst = firstIdx[a];\r\n\t\t\tvar bLast = lastIdx[b];\r\n\t\t\tif (aFirst <= bLast)\r\n\t\t\t\tallans.push('YES');\r\n\t\t\telse\r\n\t\t\t\tallans.push('NO');\r\n\t\t}\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}], "negative_code": [{"source_code": "T = readline()\r\nwhile(T--){\r\n nn = readline()\r\n\r\n nk = readline().split(' ').map(el => +el)\r\n n = nk[0]\r\n k = nk[1]\r\n\r\n x = readline().split(' ').map(el => +el)\r\n obj ={}\r\n max = 0\r\n for(i = 0; i< n; i++){\r\n obj[x[i]] = i\r\n }\r\n\r\n\r\n while(k--){\r\n\r\n ans = 'NO'\r\n ab = readline().split(' ').map(el => +el)\r\n a = ab[0]\r\n b = ab[1]\r\n\r\n\r\n if(obj[a]){\r\n if(obj[b] > obj[a])\r\n ans = 'YES'\r\n }\r\n print(ans)\r\n }\r\n}"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n nn = readline()\r\n\r\n nk = readline().split(' ').map(el => +el)\r\n n = nk[0]\r\n k = nk[1]\r\n\r\n x = readline().split(' ').map(el => +el)\r\n\r\n while(k--){\r\n\r\n ans = 'NO'\r\n ab = readline().split(' ').map(el => +el)\r\n a = ab[0]\r\n b = ab[1]\r\n if(x.indexOf(a) != -1){\r\n if(x.indexOf(b) != -1){\r\n if(x.indexOf(b) > x.indexOf(a))\r\n ans = 'YES'\r\n }\r\n }\r\n print(ans)\r\n }\r\n}"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n nn = readline()\r\n\r\n nk = readline().split(' ').map(el => +el)\r\n n = nk[0]\r\n k = nk[1]\r\n\r\n x = readline().split(' ').map(el => +el)\r\n\r\n while(k--){\r\n\r\n ans = 'NO'\r\n ab = readline().split(' ').map(el => +el)\r\n a = ab[0]\r\n b = ab[1]\r\n\r\n for(i = x.indexOf(a)+1; i< n; i++){\r\n if(x[i] === b){\r\n ans = 'YES'\r\n break\r\n }\r\n }\r\n print(ans)\r\n }\r\n}"}], "src_uid": "44ce2a46e89789b9c1c63e5452f3159b"} {"source_code": ";(function () {\n\tvar n = +readline();\n\n\tvar str = '';\n\tfor (var i = n; i < n*2; i++) str += i + ' ';\n\n\tprint(str);\n}).call(this);", "positive_code": [{"source_code": "var a=[],used={};\nvar n=13e5;\nfor(var i=3; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const n = +readLine();\n const LARGE_NUM = 13e5;\n const result = [];\n let isPrime = {};\n\n for (let i = 3; i <= LARGE_NUM; i += 2) {\n if (!isPrime[i]) {\n result.push(i);\n if (result.length === n) break;\n for (let j = 2; i * j <= LARGE_NUM; j++) {\n isPrime[i * j] = true;\n }\n }\n }\n\n console.log(result.join(\" \"));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const n = +readLine();\n const result = [];\n\n for (let i = 0; i < n; i++) {\n result.push(1e5 + i);\n }\n\n // using seive\n // const LARGE_NUM = 13e5;\n // let isPrime = {};\n\n // for (let i = 3; i <= LARGE_NUM; i += 2) {\n // if (!isPrime[i]) {\n // result.push(i);\n // if (result.length === n) break;\n // for (let j = 2; i * j <= LARGE_NUM; j++) {\n // isPrime[i * j] = true;\n // }\n // }\n // }\n\n console.log(result.join(\" \"));\n}\n"}, {"source_code": "var n=+readline();\nans=[]\nfor(var i=0; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const n = +readLine();\n const result = [];\n\n for (let i = 0; i < n; i++) {\n result.push(1e7 + i);\n }\n\n // using seive\n // const LARGE_NUM = 13e5;\n // let isPrime = {};\n\n // for (let i = 3; i <= LARGE_NUM; i += 2) {\n // if (!isPrime[i]) {\n // result.push(i);\n // if (result.length === n) break;\n // for (let j = 2; i * j <= LARGE_NUM; j++) {\n // isPrime[i * j] = true;\n // }\n // }\n // }\n\n console.log(result.join(\" \"));\n}\n"}], "src_uid": "c047040426e736e9085395ed9666135f"} {"source_code": "var S = 'abacaba';\nvar N = 7;\n\nfunction solve() {\n var n = Number(read());\n var s = Array.from(read());\n var min = 0;\n var max = 0;\n var starts = [-1000];\n var count = [0];\n for (var i = 0; i < n; i++) {\n count.push(count[i] + (s[i] === '?' ? 1 : 0));\n }\n count.push(count[n]);\n count[-1000] = -1000;\n count[1000 + N] = 1000;\n for (var i = 0; i + N - 1 < n; i++) {\n var f1 = false;\n var f2 = false;\n for (j = 0; j < N; j++) {\n if (s[i + j] === '?') {\n f1 = true;\n } else if (s[i + j] !== S[j]) {\n f2 = true;\n }\n }\n if (!f2) {\n max++;\n starts.push(i);\n if (!f1) {\n min++;\n }\n }\n }\n starts.push(1000);\n if (min > 1 || max < 1) {\n write('NO');\n return;\n }\n if (min === 1) {\n for (var i = 0; i < n; i++) {\n if (s[i] === '?') {\n s[i] = 'z';\n }\n }\n write('YES');\n write(s.join(''));\n return;\n }\n var ind = -1;\n for (var i = 1; i < starts.length - 1; i++) {\n if (starts[i] - starts[i - 1] >= N && starts[i + 1] - starts[i] >= N) {\n ind = starts[i];\n break;\n }\n if ((count[starts[i]] - count[starts[i - 1]] > 0) && (count[starts[i + 1] + N] - count[starts[i] + N] > 0)) {\n ind = starts[i];\n break;\n }\n }\n if (ind === -1) {\n write('NO');\n return;\n }\n for (var i = 0; i < N; i++) {\n s[ind + i] = S[i];\n }\n for (var i = 0; i < n; i++) {\n if (s[i] === '?') {\n s[i] = 'z';\n }\n }\n write('YES');\n write(s.join(''));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction readArray(mapF) {\n return read().split(' ').map(mapF);\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /(? {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /[a?][b?][a?][c?][a?][b?][a?](?!caba)/\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const s = readLine()\n const index = s.indexOf(S)\n if (index !== -1) {\n if (s.indexOf(S, index + 1) !== -1) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n t === 6 && console.log(s.replace(/\\?/g, 'd'))\n }\n continue\n }\n const replaced = s.replace(S_REGEX, S)\n if (replaced === s) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n console.log(replaced.replace(/\\?/g, 'd'))\n const replaced2 = replaced.replace(/\\?/g, 'd')\n const index = replaced2.indexOf(S)\n const index2 = replaced2.indexOf(S, index + 1)\n if (index2 !== -1) {\n console.log(s, t, replaced2)\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /(? {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /[a?][b?][a?][c?][a?][b?][a?]/\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const s = readLine()\n const index = s.indexOf(S)\n if (index !== -1) {\n if (s.indexOf(S, index + 1) !== -1) {\n console.log('No')\n } else {\n console.log('Yes')\n console.log(s.replace(/\\?/g, 'd'))\n }\n continue\n }\n const replaced = s.replace(S_REGEX, S)\n if (replaced === s) {\n console.log('No')\n } else {\n console.log('Yes')\n console.log(replaced.replace(/\\?/g, 'd'))\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /[a?][b?][a?][c?][a?][b?][a?](?!caba)/\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const s = readLine()\n const index = s.indexOf(S)\n if (index !== -1) {\n if (s.indexOf(S, index + 1) !== -1) {\n console.log('No')\n } else {\n console.log('Yes')\n console.log(s.replace(/\\?/g, 'd'))\n }\n continue\n }\n const replaced = s.replace(S_REGEX, S)\n if (replaced === s) {\n console.log('No')\n } else {\n console.log('Yes')\n console.log(replaced.replace(/\\?/g, 'd'))\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /[a?][b?][a?][c?][a?][b?][a?](?!caba)/\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const s = readLine()\n const index = s.indexOf(S)\n if (index !== -1) {\n if (s.indexOf(S, index + 1) !== -1) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n t === 6 && console.log(s.replace(/\\?/g, 'd'))\n }\n continue\n }\n const replaced = s.replace(S_REGEX, S)\n if (replaced === s) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n t === 6 && console.log(replaced.replace(/\\?/g, 'd'))\n const replaced2 = replaced.replace(/\\?/g, 'd')\n const index = replaced2.indexOf(S)\n const index2 = replaced2.indexOf(S, index + 1)\n if (index2 !== -1) {\n console.log(s, t, replaced2)\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst S = 'abacaba'\nconst S_REGEX = /[a?][b?][a?][c?][a?][b?][a?](?!caba)/\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const s = readLine()\n const index = s.indexOf(S)\n if (index !== -1) {\n if (s.indexOf(S, index + 1) !== -1) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n t === 6 && console.log(s.replace(/\\?/g, 'd'))\n }\n continue\n }\n const replaced = s.replace(S_REGEX, S)\n if (replaced === s) {\n t === 6 && console.log('No')\n } else {\n t === 6 && console.log('Yes')\n console.log(replaced.replace(/\\?/g, 'd'))\n const replaced2 = replaced.replace(/\\?/g, 'd')\n const index = replaced2.indexOf(S)\n const index2 = replaced2.indexOf(S, index + 1)\n if (index2 !== -1) {\n console.log(s)\n }\n }\n }\n}\n"}], "src_uid": "f6b7ad10382135b293bd3f2f3257d4d3"} {"source_code": "/* TEST CASE\ninput\n124\noutput\n4\ninput\n04\noutput\n3\ninput\n5810438174\noutput\n9\n */\nfunction main() {\n\tvar answer = 0;\n\tvar textLine = readline();\n\tvar n = textLine.length;\n\tvar i, num;\n\t\n\t\n\tfor (i = 0; i < n; i++) {\n\t\t//print(\"textLine[i] =\", textLine[i]);\n\t\tnum = parseInt(textLine[i]);\n\t\tif (num % 4 == 0) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\t\n\tfor (i = 0; i < n - 1; i++) {\n\t\t//print(\"textLine.substring(i, i + 2) =\", textLine.substring(i, i + 2));\n\t\tnum = parseInt(textLine.substring(i, i + 2));\n\t\tif (num % 4 == 0) {\n\t\t\tanswer += i + 1;\n\t\t}\n\t}\n\n\tprint(answer);\n}\n\nmain();", "positive_code": [{"source_code": "var input = readline();\nvar count = 0;\nfor (var i = 0; i <= input.length; i++) {\n if (input[i] % 4 === 0) count++;\n var str = input.substr(i, 2);\n if (str.length == 2 && parseInt(str) % 4 === 0) count += (i+1);\n}\n \nwrite(count);"}], "negative_code": [], "src_uid": "c7d48d2c23ff33890a262447af5be660"} {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n console.log(hotelier(lines[1]));\n});\n\nfunction hotelier(s) {\n const arr = [];\n arr.length = 10;\n arr.fill(0);\n\n let lp = 0;\n let rp = arr.length - 1;\n\n for (let i = 0; i < s.length; i++) {\n if (s[i] === 'L') {\n arr[lp] = 1;\n } else if (s[i] === 'R') {\n arr[rp] = 1;\n }\n while (arr[lp] === 1) {\n lp++;\n }\n while (arr[rp] === 1) {\n rp--;\n }\n\n if (!isNaN(parseInt(s[i], 10))) {\n const evictedRoomIndex = parseInt(s[i], 10);\n arr[evictedRoomIndex] = 0;\n if (lp > evictedRoomIndex) {\n lp = evictedRoomIndex;\n }\n if (rp < evictedRoomIndex) {\n rp = evictedRoomIndex;\n }\n }\n }\n return arr.join('');\n}", "positive_code": [{"source_code": "const n = Number(readline())\nconst actions = readline()\nconst result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n\nArray.from(actions).forEach((el, i) => {\n if(el === 'L') {\n setRoom(result, 'L')\n } else if(el === 'R') {\n setRoom(result, 'R')\n } else {\n result[el] = 0\n }\n})\n\nfunction setRoom(arr, c) {\n if(c === 'R') arr.reverse()\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == 0) {\n arr[i] = 1\n break\n }\n }\n if(c === 'R') arr.reverse()\n}\nprint(result.join(\"\"))\n"}, {"source_code": "// const io = require('../lol-io.js');\n// const readline = io.readline;\n// const print = io.print;\n\nvar n = Number(readline());\nvar memory = readline();\nvar result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\nfor(var i = 0; i < n; ++i) {\n if (memory[i] === 'L') {\n for (var j = 0; j < result.length; ++j) {\n if (!result[j]) {\n result[j] = 1;\n break;\n }\n }\n } else if (memory[i] === 'R') {\n for (var j = result.length - 1; j >= 0; --j) {\n if (!result[j]) {\n result[j] = 1;\n break;\n }\n }\n } else {\n result[memory[i]] = 0;\n }\n}\n\nprint(result.join(''));"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n////////////////////////////////\n\nfunction main() {\n let n = parseInt(readline());\n let s = readline();\n\n let arr = new Array(10);\n\n for (let i = 0; i < arr.length; i++) {\n arr[i] = 0;\n }\n\n let k = 0;\n\n for (let i = 0; i < n; i++) {\n if (s[i] === 'R') {\n k = arr.lastIndexOf(0);\n } else if (s[i] === 'L') {\n k = arr.indexOf(0);\n } else {\n arr[parseInt(s[i])] = 0;\n continue;\n }\n\n arr[k] = 1;\n }\n\n console.log(arr.join(''));\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let count = readline();\n let events = readline();\n const rooms = Array(10).fill(0);\n \n for(let i=0;i=0;i--){\n if(rooms[i]===0){\n rooms[i]=1;\n break;\n }\n }\n } else{\n rooms[events[i]]=0;\n }\n }\n console.log(rooms.join(\"\"));\n}\n "}, {"source_code": "const n = Number(readline());\nconst actions = readline();\n\nconst rooms = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n[...actions].forEach(action => {\n if (action === 'L') {\n for (var i = 0; i < 10; i++) {\n if (rooms[i] === 0) {\n rooms[i] = 1;\n break;\n }\n }\n } else if (action === 'R') {\n for (i = 9; i > -1; i--) {\n if (rooms[i] === 0) {\n rooms[i] = 1;\n break;\n }\n }\n } else {\n rooms[Number(action)] = 0;\n }\n});\n\nprint(rooms.join(''));"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var n = rdN();\n var s = rdS();\n var A = crAr(10, 0);\n for (var i = 0 ; i < s.length; ++i) {\n var ch = s[i];\n //pr(ch)\n if (ch === 'L') {\n var j = 0;\n while (A[j]) {\n ++j;\n }\n A[j] = 1;\n } else if (ch === 'R') {\n var j = 9;\n while (A[j]) {\n --j;\n }\n A[j] = 1;\n } else {\n A[+ch] = 0;\n }\n }\n wr(A.join(''));\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "const processData = (lines) => {\n const [count, sequence] = lines\n const rooms = '0000000000'.split('')\n const setClosest = (isLeft) => {\n if (isLeft) {\n for (let j = 0; j < rooms.length; j++) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return\n }\n }\n } else {\n for (let j = rooms.length - 1; j >= 0; j--) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return\n }\n }\n }\n }\n\n for (let i = 0; i < Number(count); i++) {\n const action = sequence[i]\n switch (action) {\n case 'L':\n setClosest(true)\n break;\n case 'R':\n setClosest(false)\n break;\n default:\n rooms[Number(action)] = '0'\n }\n }\n console.log(rooms.join(''))\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const rooms = new Array(10).fill(0);\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === 'L') {\n const idx = rooms.indexOf(0);\n rooms[idx] = 1;\n }\n else if (str[i] === 'R') {\n const idx = rooms.lastIndexOf(0);\n rooms[idx] = 1;\n }\n else {\n rooms[str[i]] = 0;\n }\n }\n\n console.log(rooms.join(''));\n c++;\n});\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let count = readline();\n let events = readline();\n const rooms = Array(10).fill(0);\n \n for(let i=0;i0;i--){\n if(rooms[i]===0){\n rooms[i]=1;\n break;\n }\n }\n } else{\n rooms[events[i]]=0;\n }\n }\n console.log(rooms);\n}\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let count = readline();\n let events = readline();\n const rooms = Array(10).fill(0);\n \n for(let i=0;i0;i--){\n if(rooms[i]===0){\n rooms[i]=1;\n break;\n }\n }\n } else{\n rooms[events[i]]=0;\n }\n }\n console.log(rooms.join(\"\"));\n}\n\n\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main() {\n let count = readline();\n let events = readline();\n const rooms = Array(10).fill(0);\n \n for(let i=0;i0;i--){\n if(rooms[i]===0){\n rooms[i]=1;\n break;\n }\n }\n } else{\n rooms[events[i]]=0;\n }\n }\n console.log(rooms.join(\"\"));\n}\n "}, {"source_code": "const processData = (lines) => {\n const [count, sequence] = lines\n const rooms = '0000000000'\n const setClosest = (rooms, isLeft) => {\n if (isLeft) {\n for (let j = 0; j < rooms.length; j++) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return rooms\n }\n }\n } else {\n for (let j = rooms.length - 1; j >= 0; j--) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return rooms\n }\n }\n\n }\n }\n\n for (let i = 0; i < count; i++) {\n const action = sequence[i]\n switch (action) {\n case 'L':\n setClosest(rooms, true)\n break\n case 'R':\n setClosest(rooms, true)\n break\n default:\n rooms[action] = '0'\n\n }\n console.log(rooms)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const [count, sequence] = lines\n const rooms = '0000000000'\n const setClosest = (isLeft) => {\n if (isLeft) {\n for (let j = 0; j < rooms.length; j++) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return rooms\n }\n }\n } else {\n for (let j = rooms.length - 1; j >= 0; j--) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return rooms\n }\n }\n\n }\n }\n\n for (let i = 0; i < count; i++) {\n const action = sequence[i]\n switch (action) {\n case 'L':\n setClosest(true)\n break\n case 'R':\n setClosest(true)\n break\n default:\n rooms[action] = '0'\n\n }\n }\n console.log(rooms)\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}, {"source_code": "const processData = (lines) => {\n const [count, sequence] = lines\n const rooms = '0000000000'\n const setClosest = (isLeft) => {\n if (isLeft) {\n for (let j = 0; j < rooms.length; j++) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return\n }\n }\n } else {\n for (let j = rooms.length - 1; j >= 0; j--) {\n if (rooms[j] === '0') {\n rooms[j] = '1'\n return\n }\n }\n }\n }\n\n for (let i = 0; i < count; i++) {\n const action = sequence[i]\n switch (action) {\n case 'L':\n setClosest(true)\n break;\n case 'R':\n setClosest(true)\n break;\n default:\n rooms[Number(action)] = '0'\n }\n }\n console.log(rooms)\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})"}], "src_uid": "a6cbf01d72d607ca95fe16df4fb16693"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, k] = rna();\r\n\t\tconst al = rna();\r\n\t\tconst bl = rna();\r\n\r\n\t\tconst bm = new Map();\r\n\t\tconst gm = new Map();\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\tbm.set(al[i], bm.has(al[i]) ? bm.get(al[i]) + 1 : 1);\r\n\t\t\tgm.set(bl[i], gm.has(bl[i]) ? gm.get(bl[i]) + 1 : 1);\r\n\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\tans += k - bm.get(al[i]) - gm.get(bl[i]) + 1;\r\n\t\t}\r\n\t\tans /= 2;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var xx = 0\r\n var answer = []\r\n var [a, b, k] = readline().split(' ').map((x, i) => {\r\n return Number(x)\r\n });\r\n var aaa = []\r\n var aa = readline().split(' ').map((x, i) => {\r\n return Number(x)\r\n });\r\n var bbb = []\r\n\r\n var bb = readline().split(' ').map((x, i) => {\r\n answer.push([aa[i], Number(x)])\r\n return Number(x)\r\n })\r\n var result = 0\r\n var count = 0\r\n var ii = 0\r\n var a1 = 0\r\n var b1 = 0\r\n // console.log(aaa)\r\n // console.log(bbb)\r\n answer.map((x, i) => {\r\n a1 = aaa[answer[i][0]] ? aaa[answer[i][0]] : 0\r\n b1 = bbb[answer[i][1]] ? bbb[answer[i][1]] : 0\r\n // console.log(i, a1, b1, i+1-a1 - b1)\r\n count = i-a1 - b1\r\n aaa[answer[i][0]] = a1 + 1\r\n bbb[answer[i][1]] = b1 + 1\r\n\r\n result+= count > 0 ? count : 0\r\n })\r\n console.log(result)\r\n })\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = new Array(A + B);\r\n\t\tfor(var j = 0; j < A + B; j++){\r\n\t\t\tlist[j] = {\r\n\t\t\t\tchild : new Set()\r\n\t\t\t};\r\n\t\t}\r\n\t\tvar L = nextIntArray(K);\r\n\t\tvar R = nextIntArray(K);\r\n\t\tfor(var j = 0; j < K; j++){\r\n\t\t\tlist[L[j] - 1].child.add(A + R[j] - 1);\r\n\t\t\tlist[A + R[j] - 1].child.add(L[j] - 1);\r\n\t\t}\r\n\t\tvar Edge = K;\r\n\t\tvar output = 0;\r\n\t\tfor(var j = 0; j < K; j++){\r\n\t\t\toutput += Edge - (list[L[j] - 1].child.size + list[A + R[j] - 1].child.size - 1);\r\n\t\t\tEdge--;\r\n\t\t\tlist[L[j] - 1].child.delete(A + R[j] - 1);\r\n\t\t\tlist[A + R[j] - 1].child.delete(L[j] - 1);\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "14ce451a31c0dbc2b2f4e04a939b199d"} {"source_code": "var str1 = readline();\nvar str2 = readline();\nvar op = readline().split(' ').map(Number);\n\nvar len1 = str1.length;\nvar len2 = str2.length;\n\nvar l = 0;\nvar r = len1;\n\nvar flags = [];\n\nvar test = function(x) {\n flags = [];\n var c = 0;\n for(var i = 0; i < x; i += 1) {\n flags[op[i] - 1] = true;\n }\n for(var i = 0; i < len1; i += 1) {\n if(!flags[i]) {\n c += (str2[c] === str1[i]) ? 1 : 0;\n }\n }\n return c >= len2;\n}\n\nwhile(l <= r) {\n var m = Math.floor((l + r) / 2);\n if(test(m)) {\n l = m + 1;\n } else {\n r = m - 1;\n }\n}\n\nprint(l - 1);\n", "positive_code": [{"source_code": "Str1 = readline();\nStr2 = readline();\nForbid = Array(Str1.length);\nPos = readline().split(' ').map(Number).map(x => x-1);\nvar l = 0,r = Str1.length;\nvar mid;\nwhile(l < r) {\n\tmid = Math.ceil((l+r)/2);\n\tfor(var i = 0;i < Str1.length;i++) {\n\t\tForbid[i] = 0;\n\t}\n\tfor(var i = 0;i {\n\t\t//print(mForbid);\n\t\tvar a=0,b=0;\n\t\twhile(a < mStr1.length && b < mStr2.length) {\n\t\t\twhile(a < mStr1.length && mForbid[a]==1)\n\t\t\t\ta++;\n\t\t\tif(a == mStr1.length)\n\t\t\t\tbreak;\n\t\t\tif(mStr1[a] == mStr2[b]) {\n\t\t\t\tb++;\n\t\t\t\t//print(a,b);\n\t\t\t}\n\t\t\ta++;\n\t\t}\n\t\tif(b==mStr2.length)\n\t\t\treturn true;\n\t\treturn false;\n\t})(mid,Str1,Str2,Forbid)) {\n\t\tl = mid;\n\t}\n\telse r = mid-1;\n\t//print(l,r);\n}\nprint(l);\n"}], "negative_code": [], "src_uid": "0aed14262c135d1624df9814078031ae"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = k[0];\n if(n == 1){\n console.log(ans);\n continue;\n }\n for(j = 1; j < n; j++){\n var a = k[j] - k[j - 1];\n if(a > ans){\n ans = a;\n }\n }\n console.log(ans);\n }\n }\n});\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var a = parseInt(readline())\r\n var line = readline().split(' ').map(Number)\r\n line.sort((a,b) => (a - b))\r\n var arr = line[0]\r\n var pre = 0\r\n for(let i = 0; i < line.length;i++){\r\n line[i]-= pre\r\n arr = (Math.max(arr, line[i]))\r\n pre += line[i]\r\n }\r\n print(arr)\r\n \r\n}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let n=Number(readline());\r\n let a = readline().split(' ').map(Number)\r\n a.sort((a, b) => a - b)\r\n let ans=a[0],pre=0;\r\n for(let i=0;i{\r\n if(n===1){\r\n console.log(arr[0]);\r\n return;\r\n }\r\n arr.sort((a,b)=>a-b);\r\n let max = arr[0];\r\n for(let i=1;imax) max = t;\r\n }\r\n console.log(max);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let num = parseInt(readline());\r\n while (num--) {\r\n let a = parseInt(readline());\r\n let line = readline().split(\" \").map(Number);\r\n line.sort((a, b) => a - b);\r\n let arr = line[0];\r\n let pre = 0;\r\n for (let i = 0; i < line.length; i++) {\r\n line[i] -= pre;\r\n arr = Math.max(arr, line[i]);\r\n pre += line[i];\r\n }\r\n print(arr);\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e9;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = -INF;\r\n\t\ta.unshift(0);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tans = Math.max(ans, a[i] - a[i-1]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n], arr) {\r\n if (n === 1) {\r\n console.log(arr[0])\r\n return\r\n }\r\n arr.sort((a, b) => a - b)\r\n let max = 0\r\n for (let i = 0; i < n - 1; i++) {\r\n if (max < arr[i + 1] - arr[i]) {\r\n max = arr[i + 1] - arr[i]\r\n }\r\n }\r\n console.log((arr[0] < max) ? max : arr[0])\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n}\r\n// let a=readline().split(' ').map(Number)\r\n// a.sort((a,b)=>a-b)\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let n=Number(readline());\r\n let a = readline().split(' ').map(Number)\r\n a.sort((a, b) => a - b)\r\n let ans=a[0],pre=0;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var a = parseInt(readline())\r\n var line = readline().split(' ').map(Number)\r\n line.sort((a,b) => (a - b))\r\n var set = new Set()\r\n var arr = []\r\n for(let i = 0;i < line.length;i++){\r\n set.add(line[i])\r\n }\r\n if(set.size == 1){\r\n print(line[0])\r\n }\r\n else{\r\n var t = line.length\r\n for(let i = 0; i < t;i++){\r\n arr.push(line[0])\r\n line.shift()\r\n for(let j = 0; j < line.length;j++){\r\n line[j] -= arr[i]\r\n }\r\n }\r\n print(Math.max(...arr))\r\n }\r\n}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = Number(readline())\r\n for (let j = 1; j <= t; j++) {\r\n let [x,n]=readline().split(' ').map(Number);\r\n if(n==0)\r\n {\r\n console.log(x);\r\n continue;\r\n }\r\n let i = 1;\r\n let ans=0;\r\n if(n%4==1)\r\n ans=-n;\r\n else if(n%4==2)\r\n ans=1;\r\n else if(n%4==3)\r\n ans=n+1;\r\n if(Math.abs(x)%2==1)\r\n ans=-ans;\r\n console.log(ans+x);\r\n }\r\n}\r\n"}], "src_uid": "4bd7ef5f6b3696bb44e22aea87981d9a"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst bs = (n, val) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n let to = (mid * (mid + 1n)) / 2n;\r\n if (to === val) return mid;\r\n else if (to < val) low = mid + 1n;\r\n else {\r\n ans = mid;\r\n high = mid - 1n;\r\n }\r\n }\r\n return ans;\r\n};\r\nconst bs1 = (n, val) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n let to = (n * (n + 1n)) / 2n - (mid * (mid - 1n)) / 2n;\r\n if (to === val) return n - mid + 1n;\r\n else if (to < val) high = mid - 1n;\r\n else {\r\n ans = n - mid + 1n;\r\n low = mid + 1n;\r\n }\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, x] = BInpArr();\r\n let total = n * (n + 1n) - n;\r\n if (x >= total) console.log(2n * n - 1n + \"\");\r\n else {\r\n let to = (n * (n + 1n)) / 2n;\r\n if (x < to) {\r\n console.log(bs(n, x) + \"\");\r\n } else if (x > to) {\r\n console.log(n + bs1(n - 1n, x - to) + \"\");\r\n } else console.log(n + \"\");\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction foo(x) {\r\n \r\n console.log(x); \r\n}\r\n\r\nfunction find_count(K,y){\r\n if(y<=K){\r\n return y*(y+1n)/2n;\r\n }\r\n else{\r\n return find_count(K,K)*2n-K-find_count(K,2n*K-1n-y);\r\n }\r\n}\r\n \r\nfunction lower_bound(K, x){\r\n let low=0n;\r\n let high=2n*K-1n;\r\n while(low dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nconst nsum = n => n*(n+1n)/2n;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [k, x] = rna();\r\n\r\n\t\tfunction bs (x, l, r) {\r\n\t\t\tlet mid;\r\n\t\t\twhile (l < r) {\r\n\t\t\t\tmid = (l + r) >> 1n;\r\n\t\t\t\tif (x > nsum(mid)) {\r\n\t\t\t\t\tl = mid + 1n;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tr = mid;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn l;\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tif (x <= nsum(k)) {\r\n\t\t\tans = bs(x, 1n, k);\r\n\t\t} else {\r\n\t\t\tx = x - nsum(k);\r\n\t\t\tx = nsum(k - 1n) - x + 1n;\r\n\t\t\tans = 2n * k - 1n - (bs(x, 1n, k - 1n) - 1n);\r\n\t\t}\r\n\r\n\t\tconsole.log(Number(ans));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [k, x] = rna();\r\n\r\n\t\tfunction bs (x, l, r) {\r\n\t\t\tlet mid;\r\n\t\t\twhile (l < r) {\r\n\t\t\t\tmid = (l + r) >> 1n;\r\n\t\t\t\tif (x > mid * (mid + 1n)/2n) {\r\n\t\t\t\t\tl = mid + 1n;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tr = mid;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn l;\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tif (x <= k*(k+1n)/2n) {\r\n\t\t\t//console.log('case 1');\r\n\t\t\tans = bs(x, 1n, k);\r\n\t\t} else {\r\n\t\t\tlftx = x - k*(k+1n)/2n;\r\n\t\t\tlftx = k*(k-1n)/2n - lftx + 1n;\r\n\t\t\tans = 2n*k - 1n - (bs(lftx, 1n, k - 1n) - 1n);\r\n\t\t}\r\n\r\n\t\tconsole.log(Number(ans));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [k, x] = lines[l++].trim().split(' ').map(BigInt)\n output[i] = solve(k, x)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(k, limit) {\n const cal = x => {\n if (x <= k) {\n return x * (x + 1n) / 2n\n } else {\n const base = k * (k + 1n) / 2n\n return base + (k - 1n + k - 1n - (x - k - 1n)) * (x - k) / 2n\n }\n }\n const count = binarySearch(0n, 2n * k - 1n, x => cal(x) <= limit)\n return cal(count) === limit ? count : min(2n * k - 1n, count + 1n)\n}\nfunction min(a, b) {\n return a < b ? a : b\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = ((l + r) / 2n)\n // const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1n\n } else {\n r = m - 1n\n }\n }\n return r\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n something(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction something() {\r\n const x = parseInt(readline());\r\n foo(x);\r\n for (var i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = parseInt(readline());\r\n foo(x);\r\n for (var i=0; i parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\nconst bs = (n, val) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n let to = (mid * (mid + 1n)) / 2n;\r\n if (to === val) return mid;\r\n else if (to < val) low = mid + 1n;\r\n else {\r\n ans = mid;\r\n high = mid - 1n;\r\n }\r\n }\r\n return ans;\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, x] = BInpArr();\r\n let total = n * (n + 1n) - n;\r\n if (x >= total) console.log(2n * n - 1n + \"\");\r\n else {\r\n let to = (n * (n + 1n)) / 2n;\r\n if (x < to) {\r\n console.log(bs(n, x) + \"\");\r\n } else if (x > to) {\r\n console.log(n + bs(n - 1n, x - to) + \"\");\r\n } else console.log(n + \"\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [k, x] = rna();\r\n\r\n\t\tfunction bs (x, l, r) {\r\n\t\t\tlet mid;\r\n\t\t\twhile (l < r) {\r\n\t\t\t\tmid = (l + r) >> 1;\r\n\t\t\t\tif (x > mid * (mid + 1)/2) {\r\n\t\t\t\t\tl = mid + 1;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tr = mid;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn l;\r\n\t\t}\r\n\r\n\t\tlet ans;\r\n\t\tif (x <= k*(k+1)/2) {\r\n\t\t\t//console.log('case 1');\r\n\t\t\tans = bs(x, 1, k);\r\n\t\t} else {\r\n\t\t\tlftx = x - k*(k+1)/2;\r\n\t\t\tlftx = k*(k-1)/2 - lftx + 1;\r\n\t\t\tans = 2*k - 1 - (bs(lftx, 1, k - 1) - 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "bf21c4809cd10904f05d531dd7af4ab5"} {"source_code": "//runcommand Get-Content input.txt | node template.js > output.txt or Ctrl+Shift+B\r\n// //libraries\r\n// const heap = require(\"@datastructures-js/priority-queue\");\r\n// const accelerate = require(\"lodash\");\r\n// const linkedlist = require(\"@datastructures-js/linked-list\");\r\n// const { max } = require(\"lodash\");\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let ns = readline().split(\" \").map(Number);\r\n let a = readline().split(\" \").map(Number);\r\n print(Detoperations(a, ns[1]));\r\n }\r\n}\r\n\r\nfunction Detoperations(arr, sum) {\r\n let n = arr.length;\r\n let op = 1e20;\r\n let s = 0;\r\n let i = 0;\r\n let j = 0;\r\n while (i < n && j < n) {\r\n s += arr[j];\r\n if (s > sum) op = Math.min(op, n - (j - i));\r\n while (s > sum) s -= arr[i++];\r\n j++;\r\n }\r\n if (s == sum) op = Math.min(op, n - (j - i));\r\n if (op == 1e20) return -1;\r\n return op;\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const sum = []\n for (let i = 0; i < arr.length; i++) {\n sum[i] = arr[i]\n if (i) sum[i] += sum[i - 1]\n }\n if (sum[n - 1] < k) return -1\n let max = 0\n for (let i = 0; i < arr.length; i++) {\n const j = binarySearch(i, n - 1, x => sum[x] - (sum[i - 1] || 0) <= k)\n max = Math.max(max, j - i + 1)\n }\n// console.log(sum)\n return n - max\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let ns = readline().split(\" \").map(Number);\r\n let a = readline().split(\" \").map(Number);\r\n print(Detoperations(a, ns[1]));\r\n }\r\n}\r\n\r\nfunction Detoperations(arr, sum) {\r\n let n = arr.length;\r\n let op = 1e20;\r\n let s = 0;\r\n let i = 0;\r\n let j = 0;\r\n while (i < n && j < n) {\r\n s += arr[j];\r\n if (s > sum) op = Math.min(op, n - (j - i));\r\n while (s > sum) s -= arr[i++];\r\n j++;\r\n }\r\n if (s == sum) op = Math.min(op, n - (j - i));\r\n if (op == 1e20) return -1;\r\n return op;\r\n}\r\n"}, {"source_code": "function solve() {\n const [a, b] = cl().split(' ').map((item) => Number(item));\n const arr = cl().split(' ').map((item) => Number(item));\n\n let len = 0;\n\n let r = 0, total = 0;\n for (let i = 0; i < a; i++) {\n if (i > 0) {\n total -= arr[i - 1];\n }\n while (r < a && total + arr[r] <= b) {\n total += arr[r++];\n }\n if (total === b) len = Math.max(r - i, len);\n }\n\n co(len > 0 ? a - len : -1);\n \n}\nfunction Solution() {\n let n = Number(cl());\n while (n--) {\n solve();\n }\n}\n\nfunction cl() {\n return lines.shift();\n}\n\nfunction co(str) {\n console.log(str);\n}\n\nconst lines = []\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', Solution);"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += arr[i];\r\n if (sum < k) console.log(-1);\r\n else {\r\n let sum1 = 0,\r\n l = 0,\r\n r = 0,\r\n res = Infinity;\r\n while (r < n) {\r\n sum1 += arr[r];\r\n if (sum1 > k) {\r\n while (l <= r && arr[l] !== 1) l++;\r\n l++;\r\n sum1 -= 1;\r\n Math.min(res, n - (r - l + 1));\r\n } else res = Math.min(res, n - (r - l + 1));\r\n r++;\r\n }\r\n console.log(res);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var [n,s] = readline().split(' ').map((x) => parseInt(x));\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var pref = []\r\n pref[0] = 0;\r\n var inf = 1000000000;\r\n var ans = -1;\r\n for(var i=1;i<=n;i++) pref[i] = pref[i-1]+a[i-1]\r\n var L = 0, R = n;\r\n while(L <= R) {\r\n var mid = L + Math.floor((R-L)/2);\r\n var val = ok(mid);\r\n if(val <= s) {\r\n if(val == s) ans = max(ans, mid)\r\n L = mid+1\r\n }\r\n else R = mid-1;\r\n }\r\n function ok(x) {\r\n var mx = -1;\r\n for(var i=0;i+x<=n;i++) {\r\n var sum = pref[i+x]-pref[i];\r\n if(sum == s) return s\r\n mx = max(mx, sum)\r\n }\r\n return mx;\r\n }\r\n if(ans != -1) ans = n-ans;\r\n console.log(ans)\r\n //fs.appendFileSync('output.txt', ans+'\\r\\n');\r\n\r\n}\r\n//"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const sum = new Array(n);\r\n const map = new Map();\r\n map.set(m, -1);\r\n let res = Infinity;\r\n for (let [i, num] of a.entries()) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + num;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (map.has(sum[i])) {\r\n res = Math.min(res, n - (i - map.get(sum[i])));\r\n }\r\n const t = sum[i] + m;\r\n if (!map.has(t)) map.set(t, i);\r\n }\r\n return res === Infinity ? -1 : res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let ns = readline().split(\" \").map(Number);\r\n let arr = readline().split(\" \").map(Number);\r\n print(Minop(arr, ns[1]));\r\n }\r\n}\r\n\r\nfunction Minop(arr, sum) {\r\n let s = 0;\r\n let op = 0;\r\n let i = 0;\r\n let j = arr.length - 1;\r\n for (let item of arr) s += item;\r\n if (sum == s) return 0;\r\n if (sum > s) return -1;\r\n while (i <= j) {\r\n if (arr[i] == 1) {\r\n i++;\r\n op++;\r\n s--;\r\n } else if (arr[j] == 1) {\r\n j--;\r\n op++;\r\n s--;\r\n } else {\r\n let temp1 = i;\r\n let temp2 = j;\r\n while (i < arr.length && arr[i] !== 1) i++;\r\n while (j >= 0 && arr[j] !== 1) j--;\r\n let dis1 = i - temp1;\r\n let dis2 = temp2 - j;\r\n if (dis1 < dis2) {\r\n op += i - temp1;\r\n j = temp2;\r\n } else {\r\n op += temp2 - j;\r\n i = temp1;\r\n }\r\n }\r\n if (s == sum) return op;\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n let ns = readline().split(\" \").map(Number);\r\n let arr = readline().split(\" \").map(Number);\r\n print(Minop(arr, ns[1]));\r\n }\r\n}\r\n\r\nfunction Minop(arr, sum) {\r\n let s = 0;\r\n let op = 0;\r\n let i = 0;\r\n let j = arr.length - 1;\r\n let rec1 = 1e9;\r\n let rec2 = 1e9;\r\n let pre = [];\r\n let suff = [];\r\n for (let k = 0; k < arr.length; k++) {\r\n if (arr[k] == 1) {\r\n s++;\r\n rec1 = k;\r\n }\r\n if (arr[arr.length - k - 1] == 1) rec2 = arr.length - k - 1;\r\n if (arr[k] == 0) pre[k] = rec1 == 1e9 ? rec1 : k - rec1;\r\n if (arr[arr.length - k - 1] == 0) suff[arr.length - k - 1] = rec2 == 1e9 ? rec2 : rec2 - (arr.length - k - 1);\r\n }\r\n if (sum == s) return 0;\r\n if (sum > s) return -1;\r\n while (i <= j) {\r\n if (arr[i] == 1) {\r\n i++;\r\n op++;\r\n s--;\r\n } else if (arr[j] == 1) {\r\n j--;\r\n op++;\r\n s--;\r\n } else {\r\n if (pre[j] < suff[i]) j--;\r\n else i++;\r\n op++;\r\n }\r\n if (s == sum) return op;\r\n }\r\n}"}, {"source_code": "function solve() {\n const [a, b] = cl().split(' ').map((item) => Number(item));\n const arr = cl().split(' ').map((item) => Number(item));\n let total = arr.reduce((pre, curr) => pre + curr);\n\n if (total < b) return co(-1);\n const arr1= new Array(a).fill(0);\n let target = Infinity;\n for (let i = a - 1; i >= 0; i--) {\n if (arr[i] === 1) target = i;\n arr1[i] = target;\n }\n\n const arr2 = new Array(a).fill(0);\n target = Infinity;\n for (let i = 0; i < a; i++) {\n if (arr[i] === 1) target = a - i - 1;\n arr2[i] = target;\n }\n\n let l = 0, r = a - 1;\n while (total > b) {\n if (arr[l] === 1) {\n l += 1;\n total -= 1;\n }\n else if (arr[r] === 1) {\n r -= 1;\n total -= 1;\n }\n else {\n if (arr1[l] <= arr2[r]) {\n l += 1;\n } else {\n r -= 1;\n }\n }\n }\n \n co(l + arr.length - 1 - r);\n}\nfunction Solution() {\n let n = Number(cl());\n while (n--) {\n solve();\n }\n}\n\nfunction cl() {\n return lines.shift();\n}\n\nfunction co(str) {\n console.log(str);\n}\n\nconst lines = []\n\nconst readline = require('readline')\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', Solution);"}, {"source_code": "function solve() {\n const [_, b] = cl().split(' ').map((item) => Number(item));\n const arr = cl().split(' ').map((item) => Number(item));\n let total = arr.reduce((pre, curr) => pre + curr);\n\n if (total < b) return co(-1);\n\n let l = 0, r = arr.length - 1;\n let lastL = 0, lastR = arr.length - 1;\n while (total > b) {\n if (arr[l] === 1) {\n r = lastR;\n l += 1;\n lastL = l;\n total -= 1;\n } else if (arr[r] === 1) {\n l = lastL;\n r -= 1;\n lastR = r;\n total -= 1;\n } else {\n l += 1;\n r -= 1;\n }\n }\n co(l + arr.length - 1 - r);\n}\nfunction Solution() {\n let n = Number(cl());\n while (n--) {\n solve();\n }\n}\n\nfunction cl() {\n return lines.shift();\n}\n\nfunction co(str) {\n console.log(str);\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', Solution);"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += arr[i];\r\n if (sum < k) console.log(-1);\r\n else if (sum === k) console.log(0);\r\n else {\r\n let i,\r\n j,\r\n cnt = 0;\r\n for (i = 0; i < n; i++) {\r\n if (sum === k) break;\r\n if (arr[i] === 0) break;\r\n sum--;\r\n cnt++;\r\n }\r\n if (sum === k) {\r\n console.log(cnt);\r\n continue;\r\n }\r\n for (j = n - 1; j >= 0; j--) {\r\n if (sum === k) break;\r\n if (arr[j] === 0) break;\r\n sum--;\r\n cnt++;\r\n }\r\n if (sum === k) {\r\n console.log(cnt);\r\n continue;\r\n }\r\n let cnt1 = 0,\r\n cnt2 = 0,\r\n s1 = sum,\r\n s2 = sum;\r\n while (i < n) {\r\n if (s1 === k) break;\r\n if (arr[i] === 1) s1--;\r\n cnt1++;\r\n i++;\r\n }\r\n while (j >= 0) {\r\n if (s2 === k) break;\r\n if (arr[j] === 1) s2--;\r\n j--;\r\n cnt2++;\r\n }\r\n console.log(cnt + Math.min(cnt1, cnt2));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, k] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) sum += arr[i];\r\n if (sum < k) console.log(-1);\r\n else if (sum === k) console.log(0);\r\n else {\r\n let left = [],\r\n right = [];\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 1) left[i] = 0;\r\n else {\r\n let cnt = 0;\r\n for (let j = i; j < n; j++) {\r\n if (arr[j] === 1) break;\r\n else cnt++;\r\n }\r\n left[i] = cnt;\r\n }\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (arr[i] === 1) right[i] = 0;\r\n else {\r\n let cnt = 0;\r\n for (let j = i; j >= 0; j--) {\r\n if (arr[j] === 1) break;\r\n else cnt++;\r\n }\r\n right[i] = cnt;\r\n }\r\n }\r\n let i = 0,\r\n j = n - 1,\r\n cnt = 0;\r\n while (cnt < n) {\r\n if (sum === k) break;\r\n if (arr[i] === 1) {\r\n sum--;\r\n i++;\r\n } else if (arr[j] === 1) {\r\n j--;\r\n sum--;\r\n } else {\r\n if (left[i] < right[j]) i++;\r\n else j--;\r\n }\r\n cnt++;\r\n }\r\n console.log(cnt);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "68adf23485d9db9a254ab73d4f07bd62"} {"source_code": "const processData = (lines) => {\n const [n, a, b, k] = lines[0].split(' ').map(x => +x)\n const hps = lines[1].split(' ').map(x => +x)\n\n const notSoEasyKill = []\n\n let exp = 0\n\n const totalDamage = a + b\n\n\n for (let i = 0; i {const key = Math.ceil(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})\n\n const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)\n let i = 0\n while (leftSkills > 0 && i < keys.length) {\n const key = keys[i]\n const left = lefts[key]\n if (left * key > leftSkills) {\n exp += Math.floor(leftSkills / key)\n leftSkills = 0\n } else {\n leftSkills -= left * key\n exp += left\n }\n i++\n }\n\n console.log(exp)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', x => input.push(x));\n\nreadline.on('close', () => {\n let [n, a, b, k] = input[0].split(' ').map(x => parseInt(x));\n\n scores = 0;\n let helps = [];\n const monsters = input[1].split(' ').map(\n x => {\n x = parseInt(x);\n let hp = x - a;\n let sum_power = b + a;\n let last_hit_hp = hp - sum_power * Math.trunc(hp / sum_power);\n \n if (last_hit_hp <= b) helps.push(Math.ceil(last_hit_hp / a));\n else scores++;\n \n return x;\n }\n );\n\n helps.sort((a, b) => a - b);\n for (let i = 0; i < helps.length; i++) {\n k -= helps[i];\n if (k >= 0) scores++;\n else break;\n }\n\n console.log(scores);\n});"}, {"source_code": " 'use strict'\n \n const params = readline().split(' ').map(num => parseInt(num))\n const arr = readline().split(' ').map(num => parseInt(num))\n \n const a = params[1]\n const b = params[2]\n let k = params[3]\n \n const all = Array(params[0]).fill(0)\n for (let i in arr) {\n let val = parseInt(arr[i] % (a + b))\n \n if (val === 0) {\n val += b\n } else {\n val = Math.max(0, val - a)\n }\n all[i] = parseInt(Math.ceil(val / a))\n }\n \n all.sort((a, b) => a - b)\n \n let ans = 0\n for (let i in all) {\n if (k - all[i] < 0) break\n ans ++\n k -= all[i]\n }\n \n print(ans)"}, {"source_code": "'use strict'\n\nconst problem = (n, a, b, k, h) => {\n let d = {};\n let res = 0;\n for (let i = 0; i < n; i++) {\n const hp = (h[i] - 1) % (a+b) + 1 - a;\n if (hp > 0) {\n if (d[hp]) d[hp]++;\n else d[hp] = 1;\n } else {\n res++;\n }\n }\n\n const monsters = Object.keys(d).sort((x, y) => x-y);\n for (let i = 0; i < monsters.length; i++) {\n const hp = monsters[i];\n const cnt = d[hp];\n const hits = (hp / a | 0) + ((hp % a) ? 1 : 0);\n if (k < cnt * hits) return res + k / hits | 0;\n res += cnt;\n k -= cnt * hits;\n }\n return res;\n}\n\nconst nabk = readline().split(' ').map(i => +i);\nconst h = readline().split(' ').map(i => +i);\nprint(problem(nabk[0], nabk[1], nabk[2], nabk[3], h))\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst params = readline().split(' ').map(num => parseInt(num))\nconst arr = readline().split(' ').map(num => parseInt(num))\n\nconst a = params[1]\nconst b = params[2]\nlet k = params[3]\n\nconst all = Array(params[0]).fill(0)\nfor (let i in arr) {\n let val = parseInt(arr[i] % (a + b))\n\n if (val === 0) {\n val += b\n } else {\n val = Math.max(0, val - a)\n }\n all[i] = parseInt(Math.ceil(val / a))\n}\n\nall.sort()\n\nlet ans = 0\nfor (let i in all) {\n if (k - all[i] < 0) break\n ans ++\n k -= all[i]\n}\n\nprint(ans)"}, {"source_code": "const processData = (lines) => {\n const [n, a, b, k] = lines[0].split(' ').map(x => +x)\n const hps = lines[1].split(' ').map(x => +x)\n\n const notSoEasyKill = []\n\n let exp = 0\n\n const totalDamage = a + b\n\n\n for (let i = 0; i {const key = Math.floor(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})\n\n const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)\n let i = 0\n while (leftSkills > 0 && i < keys.length) {\n const key = keys[i]\n const left = lefts[key]\n if (left * key > leftSkills) {\n exp += Math.ceil(leftSkills / key)\n leftSkills = 0\n } else {\n leftSkills -= left * key\n exp += left\n }\n i++\n }\n\n console.log(exp)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const [n, a, b, k] = lines[0].split(' ').map(x => +x)\n const hps = lines[1].split(' ').map(x => +x)\n\n const notSoEasyKill = []\n\n let exp = 0\n\n const totalDamage = a + b\n\n\n for (let i = 0; i {const key = Math.ceil(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})\n\n const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)\n let i = 0\n while (leftSkills > 0 && i < keys.length) {\n const key = keys[i]\n const left = lefts[key]\n if (left * key > leftSkills) {\n exp += Math.ceil(leftSkills / key)\n leftSkills = 0\n } else {\n leftSkills -= left * key\n exp += left\n }\n i++\n }\n\n console.log(exp)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "ada28bbbd92e0e7c6381bb9a4b56e7f9"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => BigInt(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 2e18;\r\n\r\n// same as cpp bound functions\r\n// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found\r\n// upperBound(ar, x) - first element > x, return ar.length if no such element is found\r\nfunction lowerBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] >= x) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid;\r\n\t\t}\r\n\t}\r\n\treturn ar[l] >= x ? l : r;\r\n}\r\n\r\nfunction upperBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] <= x) {\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid;\r\n\t\t}\r\n\t}\r\n\treturn a[l] > x ? l : r;\r\n}\r\n\r\nconst max = (a, b) => a > b ? a : b;\r\nconst min = (a, b) => a < b ? a : b;\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst a = rna();\r\n\tconst m = rn();\r\n\tconst x = [], y = [];\r\n\tfor (let i = 0; i < m; i++) [x[i], y[i]] = rna();\r\n\r\n\tlet powerSum = 0n;\r\n\tfor (let i = 0; i < n; i++) powerSum += a[i];\r\n\r\n\tfor (let i = 0; i < n; i++) a[i] = Number(a[i]);\r\n\ta.sort((x, y) => x - y);\r\n\t//for (let i = 0; i < n; i++) a[i] = BigInt(a[i]);\r\n\r\n\tfor (let i = 0; i < m; i++) x[i] = Number(x[i]);\r\n\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tconst lb = lowerBound(a, x[i]);\r\n\t\tlet option1 = INF, option2 = INF;\r\n\t\tif (lb < n) option1 = max(0n, y[i] - (powerSum - BigInt(a[lb])));\r\n\t\tif (lb > 0) option2 = BigInt(x[i] - a[lb-1]) + max(0n, y[i] - (powerSum - BigInt(a[lb-1])));\r\n\r\n\t\tconsole.log(min(option1, option2).toString());\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst rbn = () => BigInt(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\nconst rbna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 2e18;\r\n\r\n// same as cpp bound functions\r\n// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found\r\n// upperBound(ar, x) - first element > x, return ar.length if no such element is found\r\nfunction lowerBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] >= x) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid;\r\n\t\t}\r\n\t}\r\n\treturn ar[l] >= x ? l : r;\r\n}\r\n\r\nfunction upperBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] <= x) {\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid;\r\n\t\t}\r\n\t}\r\n\treturn a[l] > x ? l : r;\r\n}\r\n\r\nconst max = (a, b) => a > b ? a : b;\r\nconst min = (a, b) => a < b ? a : b;\r\nconst B = a => BigInt(a);\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst a = rna();\r\n\tconst m = rn();\r\n\r\n\tlet powerSum = 0n;\r\n\tfor (let i = 0; i < n; i++) powerSum += B(a[i]);\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tlet [x, y] = rbna(); x = Number(x);\r\n\r\n\t\tlet option1 = INF, option2 = INF;\r\n\t\tconst j = lowerBound(a, x);\r\n\t\tif (j < n) option1 = max(0n, y - (powerSum - B(a[j])));\r\n\t\tif (j > 0) option2 = B(x) - B(a[j-1]) + max(0n, y - (powerSum - B(a[j-1])));\r\n\r\n\t\tconsole.log(min(option1, option2).toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst rbn = () => BigInt(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\nconst rbna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 2e18;\r\n\r\n// same as cpp bound functions\r\n// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found\r\n// upperBound(ar, x) - first element > x, return ar.length if no such element is found\r\nfunction lowerBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] >= x) {\r\n\t\t\tr = mid;\r\n\t\t} else {\r\n\t\t\tl = mid;\r\n\t\t}\r\n\t}\r\n\treturn ar[l] >= x ? l : r;\r\n}\r\n\r\nfunction upperBound (ar, x) {\r\n\tlet l = 0, r = ar.length;\r\n\twhile (r-l > 1) { \r\n\t\tconst mid = l+r >> 1;\r\n\t\tif (ar[mid] <= x) {\r\n\t\t\tl = mid + 1;\r\n\t\t} else {\r\n\t\t\tr = mid;\r\n\t\t}\r\n\t}\r\n\treturn a[l] > x ? l : r;\r\n}\r\n\r\nconst max = (a, b) => a > b ? a : b;\r\nconst min = (a, b) => a < b ? a : b;\r\nconst B = a => BigInt(a);\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst a = rna();\r\n\tconst m = rn();\r\n\tconst x = [], y = [];\r\n\tfor (let i = 0; i < m; i++) [x[i], y[i]] = rbna();\r\n\tfor (let i = 0; i < m; i++) x[i] = Number(x[i]);\r\n\r\n\tlet powerSum = 0n;\r\n\tfor (let i = 0; i < n; i++) powerSum += B(a[i]);\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tconst lb = lowerBound(a, x[i]);\r\n\t\tlet option1 = INF, option2 = INF;\r\n\t\tif (lb < n) option1 = max(0n, y[i] - (powerSum - B(a[lb])));\r\n\t\tif (lb > 0) option2 = B(x[i]) - B(a[lb-1]) + max(0n, y[i] - (powerSum - B(a[lb-1])));\r\n\r\n\t\tconsole.log(min(option1, option2).toString());\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction lowerBound(arr, x) {\r\n\tfor (let i = 1; i < arr.length; i++) \r\n\t\tif (x < arr[i]) return i - 1;\r\n\treturn arr.length - 1;\r\n}\r\n\r\nconst INF = Number.POSITIVE_INFINITY;\r\n\r\nfunction main () {\r\n\tlet n = rn();\r\n\tlet a = rna();\r\n\tlet m = rn();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tlet sm = 0;\r\n\tfor (elm of a) sm +=elm;\r\n\r\n\twhile (m--) {\r\n\t\tlet [x, y] = rna();\r\n\r\n\t\tconst l = lowerBound(a, x);\r\n\t\tansl = Math.max(0, y - (sm - a[l])) + Math.max(0, x - a[l]);\r\n\t\tansr = l + 1 < n ? Math.max(0, y - (sm - a[l+1])) : INF;\r\n\t\tconst ans = Math.min(ansl, ansr);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet n = rn();\r\n\tlet a = rna();\r\n\tlet m = rn();\r\n\tlet x = [], y = [];\r\n\tfor (let i = 0; i < m; i++)\r\n\t\t[x[i], y[i]] = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tlet sm = 0;\r\n\tfor (elm of a) sm +=elm;\r\n\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tlet ans = 0;\r\n\t\tif (x[i] <= a[0]) {\r\n\t\t\tans = Math.max(y[i] - (sm - a[0]), 0);\r\n\t\t} else if (x[i] >= a[n-1]) {\r\n\t\t\tans = Math.max(y[i] - (sm - a[n-1]), 0) + x[i] - a[n-1];\r\n\t\t} else {\r\n\t\t\tfor (let j = 0; j < n; j++) {\r\n\t\t\t\tif (x[i] >= a[j] && x[i] < a[j+1]) {\r\n\t\t\t\t\tans1 = Math.max(y[i] - (sm - a[j+1]), 0); // select higher powered soldier\r\n\t\t\t\t\tans2 = Math.max(y[i] - (sm - a[j]), 0) + x[i] - a[j]; // select lower ...\r\n\t\t\t\t\tans = Math.min(ans1, ans2);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "8827e14bcba5689118f393442280d2ba"} {"source_code": "// var lineIdx = 0;\n// var readline = () => {\n// var input = [\"3\", \"3 3\", \"1 2 3\", \"3 4\", \"1 2 3\", \"2 2\" ,\"0 6\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar t = readline().split(\" \").map(function (x) { return parseInt(x); })[0];\n\nvar step = () => {\n var input = readline().split(\" \").map(function (x) { return parseInt(x); });\n var n = input[0];\n var x = input[1];\n\n var row = readline().split(\" \").map(function (x) { return parseInt(x); });\n\n var max = -2;\n\n var sum = 0;\n for (var i = 0; i < n; i ++){\n sum += row[i];\n sum = sum % x;\n if(sum != 0){\n max = i;\n }\n }\n\n sum = 0;\n for (i = n-1; i >= 0; i --){\n sum += row[i];\n sum = sum % x;\n if(sum != 0){\n if(n -1 - i > max){\n max = n -1 - i;\n }\n }\n }\n\n print(max + 1)\n\n}\n\n\nfor (var i2 = 0; i2 < t; i2++) {\n step();\n}", "positive_code": [{"source_code": "var na = readline();\nvar maxa = [];\nvar inp = [];\nfor (var i = 0;i ans) {\n ans = j2 - i1;\n }\n if (j1 < i2 && i2 - j1 > ans) {\n ans = i2 - j1;\n }\n }\n }\n write(ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar input = '';\nprocess.stdin.on('data', function (line) {\n input += line;\n});\nprocess.stdin.on('end', function () {\n var lines = input.split('\\n');\n var tests = parseInt(lines.shift(), 10);\n var _loop_1 = function () {\n var nx = lineToNumArray(lines.shift());\n var n = nx[0], x = nx[1];\n var arr = lineToNumArray(lines.shift());\n var allDivisible = arr.every(function (element) { return element % x === 0; });\n if (allDivisible) {\n console.log(-1);\n }\n else {\n var sum = arr.reduce(function (a, b) { return a + b; }, 0);\n console.log(sum % x !== 0 ? n : n - 1);\n }\n };\n while (tests--) {\n _loop_1();\n }\n});\n// input helper\nfunction lineToNumArray(line) {\n return line.split(' ').map(function (element) { return parseInt(element, 10); });\n}\n"}, {"source_code": "var n = readline();\nvar maxa = [];\nvar inp = [];\nfor (var i = 0;iinp[i].length - j){\n break;\n }\n for (var k = j; k < inp[i].length; k++) {\n if ((tmpSum + inp[i][k]) === 0 || (tmpSum + inp[i][k]) % maxa[i] === 0){\n break;\n }else{\n tmpSum += inp[i][k];\n llen ++;\n }\n }\n if (llen !== 0 && llen>max){\n max = llen;\n }\n }\n write(max + \"\\n\");\n}"}], "src_uid": "f5bcde6e3008405f61cead4e3f44806e"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n \r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n \r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n \r\n\t\tlet pwr = 1, mxx = 0, sm = 0;\r\n\t\tfor (let x of a) {\r\n\t\t\twhile (x % 2 == 0) {\r\n\t\t\t\tpwr *= 2;\r\n\t\t\t\tx /= 2;\r\n\t\t\t}\r\n\t\t\tmxx = Math.max(mxx, x);\r\n\t\t\tsm += x;\r\n\t\t}\r\n \r\n\t\tans = sm - mxx + mxx*pwr;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var ans = '';\n var two = 1, max = 0, sum = 0;\n for(j = 0; j < n; j++){\n while(a[j] % 2 === 0){\n a[j] /= 2;\n two *= 2;\n }\n max = Math.max(max, a[j]);\n sum += a[j];\n }\n var b = sum - max;\n two *= max;\n console.log(b + two);\n }\n }\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet pwr = 1, mxx = 0, sm = 0;\r\n\t\tfor (let x of a) {\r\n\t\t\twhile (x % 2 == 0) {\r\n\t\t\t\tpwr *= 2;\r\n\t\t\t\tx /= 2;\r\n\t\t\t}\r\n\t\t\tmxx = Math.max(mxx, x);\r\n\t\t\tsm += x;\r\n\t\t}\r\n\r\n\t\tans = sm - mxx + mxx*pwr;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "f5de1e9b059bddf8f8dd46c18ce12683"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n console.log(solve(str))\n }\n// })()\n})\n\nfunction solve(str) {\n const ch = []\n const map = {}\n for (let i = str.length - 1; i >= 0; i--) {\n if (ch.indexOf(str[i]) < 0) {\n ch.unshift(str[i])\n }\n map[str[i]] = (map[str[i]] || 0) + 1\n }\n// console.log(map, ch)\n let sum = 0\n for (let i = 0; i < ch.length; i++) {\n const c = ch[i]\n const k = map[c]\n // if (i === ch.length - 1) {\n // sum += k\n // break\n // }\n if (k % (i + 1)) return -1\n\n sum += k / (i + 1)\n }\n const old = str.slice(0, sum)\n\n const d = {}\n let p = 0\n for (let i = 0; i < ch.length; i++) {\n for (let j = 0; j < sum; j++) {\n if (!d[old[j]]) {\n if (str[p] !== old[j]) return -1\n p++\n }\n }\n const c = ch[i]\n d[c] = 1\n }\n\n return old + ' ' + ch.join('')\n}\n", "positive_code": [{"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let t = read();\n used = new Array(256);\n for (let i = 0; i < 256; i++) {\n used[i] = 0;\n }\n let s = '';\n let sq = '';\n for (let i = t.length - 1; 0 <= i; i--) {\n let c = t.charCodeAt(i);\n if (!used[c]) {\n sq += t[i];\n }\n used[c] += 1;\n }\n sq = sq.split(\"\").reverse().join(\"\");\n cnt = new Array(256);\n for (let i = 0; i < 256; i++) {\n cnt[i] = 0;\n }\n cnt2 = new Array(256);\n for (let i = 0; i < 256; i++) {\n cnt2[i] = 0;\n }\n for (let i = 0; i < sq.length; i++) {\n let c = sq.charCodeAt(i);\n cnt[c] = parseInt(used[c] / (i + 1));\n }\n let num = 0;\n for (let i = 0; i < t.length; i++) {\n let c = t.charCodeAt(i);\n cnt2[c]++;\n if (cnt[c] == cnt2[c]) {\n num++;\n }\n s += t[i];\n if (num == sq.length) {\n break;\n }\n }\n if (s == '') {\n console.log(-1);\n continue;\n }\n for (let i = 0; i < 256; i++) {\n used[i] = 0;\n }\n let t2 = '';\n for (let i = 0; i < sq.length; i++) {\n for (let j = 0; j < s.length; j++) {\n let c = s.charCodeAt(j);\n if (!used[c]) {\n t2 += s[j];\n }\n }\n let c = sq.charCodeAt(i);\n used[c] = 1;\n }\n if (t == t2) {\n console.log(s + ' ' + sq);\n }\n else {\n console.log(-1);\n }\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(t => {\r\n stdin.on('data', t => e.push(t)),\r\n stdin.on('end', function () {\r\n const n = e.join('').split(os.EOL)\r\n t(n)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const t = new InputAndOutput()\r\n await t.init(), e(t)\r\n}\r\nfunction solve(e) {\r\n let t = []\r\n const n = {}\r\n for (let i = e.length - 1; i >= 0; --i) {\r\n const s = e[i]\r\n let r = n[s]\r\n void 0 === r ? (t.push(s), (r = 1)) : (r += 1), (n[s] = r)\r\n }\r\n const i = t.length\r\n let s = 0\r\n for (let e = 0; e < i; ++e) {\r\n const r = n[t[e]]\r\n if (r % (i - e) != 0) return -1\r\n s += r / (i - e)\r\n }\r\n t = t.reverse()\r\n let r = e.slice(0, s)\r\n for (let n = 0, o = s; n < i; ++n) {\r\n r = r.replace(new RegExp(t[n], 'g'), '')\r\n for (let t = 0; t < r.length; ++t) if (r[t] != e[o++]) return -1\r\n }\r\n return e.slice(0, s).concat(' ').concat(t.join(''))\r\n}\r\n__main__(function (e) {\r\n const t = e.readLineAsNumber()\r\n for (let n = 1; n <= t; ++n) {\r\n const t = solve(e.readLine())\r\n e.print(t + '\\n')\r\n }\r\n})\r\n"}], "negative_code": [], "src_uid": "8705adec1bea1f898db1ca533e15d5c3"} {"source_code": "const firstLine = readline();\nconst n = firstLine.split(' ')[0];\nconst m = firstLine.split(' ')[1];\nconst firstArray = readline().split(' ').map(function(x) {\n return parseInt(x);\n}); \nconst secondArray = readline().split(' ').map(function(x) {\n return parseInt(x);\n}); \n\nvar result = 0;\nvar i = 0,\n j = 0,\n firstSum = firstArray[0],\n secondSum = secondArray[0];\n\n\nwhile (i < firstArray.length && j < secondArray.length){\n if (firstSum > secondSum){\n j++;\n secondSum += secondArray[j];\n continue;\n }\n if (firstSum < secondSum){\n i++;\n firstSum += firstArray[i];\n continue;\n }\n if (firstSum === secondSum){\n result++;\n i++;\n firstSum = firstArray[i];\n j++;\n secondSum = secondArray[j];\n }\n}\n\nprint(result);", "positive_code": [{"source_code": "var firstLine = readline().split(' ').map(function(v){return +v;});\nvar secondLine = readline().split(' ').map(function(v){return +v;});\nvar thirdLine = readline().split(' ').map(function(v){return +v;});\n\nvar aCount = firstLine[0];\nvar bCount = firstLine[1];\nvar a = secondLine;\nvar b = thirdLine;\n\nvar curA = a[0];\nvar curB = b[0];\nvar result = 0;\n\nvar i = 0;\nvar j = 0;\n\nwhile (true) {\n if (curA == curB) {\n i++;\n j++;\n\n if (i > aCount) break;\n if (j > bCount) break;\n\n result++;\n \n curA = a[i];\n curB = b[j];\n continue;\n }\n \n if (curA > curB) {\n j++;\n curB += b[j];\n continue;\n }\n \n if (curA < curB) {\n i++;\n curA += a[i];\n }\n}\n\nprint(result);"}], "negative_code": [], "src_uid": "cb5cbfb4d184cda21ebfbcf47bb970dc"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, a, b] = rna();\r\n\r\n\t\tif (a+b > n-2 || Math.abs(a-b) > 1) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) ans.push(i+1);\r\n\r\n\t\tlet i = 0;\r\n\t\tif (a == b) i = 1;\r\n\t\telse if (a > b) ans.reverse();\r\n\r\n\t\tlet cnt = Math.max(a, b);\r\n\t\twhile (cnt--) {\r\n\t\t\t[ans[i], ans[i+1]] = [ans[i+1], ans[i]];\r\n\t\t\ti += 2;\r\n\t\t}\r\n\r\n\t\t//console.log({cnt, ans, a, b})\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, a, b] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (a + b + 2 > n || Math.abs(a - b) > 1) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let c = false;\r\n if (a < b) {\r\n [a, b] = [b, a];\r\n c = true;\r\n }\r\n let sI = n - a - b - 1;\r\n let res = [],\r\n obj = {},\r\n narr = new Array(n).fill(1).map((cur, ind) => ind + 1);\r\n for (let i = sI, j = n; i < n; i += 2, j--) obj[j] = res[i] = j;\r\n let sar = [];\r\n for (let i = 0; i < n; i++) if (!obj[narr[i]]) sar.push(narr[i]);\r\n for (let i = 0, j = 0; i < n; i++) if (!res[i]) res[i] = sar[j++];\r\n if (c) for (let i = 0; i < n; i++) res[i] = n + 1 - res[i];\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, a, b] = rna();\r\n\r\n\t\tif (a+b <= n-2 && Math.abs(a-b) <= 1) {\r\n\t\t\t\r\n\t\t\tlet cur = 0, diff = 0, sign = 1, mn = 0;\r\n\r\n\t\t\tif (a < b) sign = -1;\r\n\t\t\tconst ans = [0];\r\n\t\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\t\tif (cur > 0 && a) {\r\n\t\t\t\t\ta--;\r\n\t\t\t\t\tsign *= -1;\r\n\t\t\t\t} else if (cur < 0 && b) {\r\n\t\t\t\t\tb--;\r\n\t\t\t\t\tsign *= -1;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tdiff = 0;\r\n\t\t\t\t}\r\n\t\t\t\tdiff++;\r\n\r\n\t\t\t\tcur = cur + diff*sign;\r\n\t\t\t\tans.push(cur);\r\n\r\n\t\t\t\tmn = Math.min(mn, cur);\r\n\t\t\t}\r\n\r\n\t\t\t//console.log({ans, a, b})\r\n\t\t\tfor (let i = 0; i < n; i++)\r\n\t\t\t\tans[i] += 1 - mn;\r\n\r\n\t\t\tconsole.log(ans.join(' '));\r\n\r\n\t\t} else {\r\n\t\t\tconsole.log(-1);\r\n\t\t}\r\n\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, a, b] = rna();\r\n\r\n\t\tif (a+b > n-2 || Math.abs(a-b) > 1) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet cur, mn = 0;\r\n\t\tif (a > b) cur = 1;\r\n\t\telse cur = -1;\r\n\r\n\t\tconst ans = [0, cur];\r\n\r\n\t\tfor (let i = 0; i < n-2; i++) {\r\n\t\t\tif (cur > 0 && a) {\r\n\t\t\t\ta--;\r\n\t\t\t\tcur = -cur;\r\n\t\t\t} else if (cur < 0 && b) {\r\n\t\t\t\tb--;\r\n\t\t\t\tcur = -cur + 1;\r\n\t\t\t} else {\r\n\t\t\t\tcur += cur > 0 ? 1 : -1;\r\n\t\t\t}\r\n\r\n\t\t\tans.push(cur);\r\n\r\n\t\t\tmn = Math.min(mn, cur);\r\n\t\t}\r\n\r\n\t\t//console.log({a, b, mn})\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tans[i] += 1 - mn;\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, a, b] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (a + b + 2 > n || Math.abs(a - b) > 1) {\r\n console.log(-1);\r\n continue;\r\n }\r\n let c = false;\r\n if (a < b) {\r\n [a, b] = [b, a];\r\n c = true;\r\n }\r\n let start = n - a;\r\n let sI = n - a - b - 1;\r\n let res = [],\r\n obj = {},\r\n narr = new Array(n).fill(1).map((cur, ind) => ind + 1);\r\n for (let i = sI, j = start; i < n; i += 2, j++) obj[j] = res[i] = j;\r\n let sar = [];\r\n for (let i = 0; i < n; i++) if (!obj[narr[i]]) sar.push(narr[i]);\r\n for (let i = 0, j = 0; i < n; i++) if (!res[i]) res[i] = sar[j++];\r\n if (c) for (let i = 0; i < n; i++) res[i] = n + 1 - res[i];\r\n console.log(res.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "2fdbf033e83d7c17841f640fe1fc0e55"} {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n const [n,m] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b = readLine().split(' ').map(Number);\r\n const a0 = a.filter(num => num < 0);\r\n const a1 = a.filter(num => num >= 0);\r\n const b0 = b.filter(num => num < 0);\r\n const b1= b.filter(num => num >= 0);\r\n const a0_filter = a0.filter(num => num >= b0[0]);\r\n const b0_filter = b0.filter(num => num <= a0_filter[a0_filter.length - 1])\r\n const a00_filter = a0_filter.map(num => num *-1);\r\n const b00_filter = b0_filter.map(num => num *-1);\r\n const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);\r\n const b1_filter = b1.filter(num => num >= a1_filter[0]);\r\n console.log(count1(a00_filter.sort((a,b) => a - b), b00_filter.sort((a,b) => a - b),1) + count1(a1_filter, b1_filter,1) );\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction intersection(setA, setB) {\r\n let _intersection = new Set()\r\n for (let elem of setB) {\r\n if (setA.has(elem)) {\r\n _intersection.add(elem)\r\n }\r\n }\r\n return _intersection\r\n}\r\n\r\nfunction count1(a,b,opt = 0){\r\n if(a.length === 0 || b.length === 0) return 0;\r\n let globalMax = 0;\r\n const setB = new Set([...b]);\r\n const setA = new Set([...a]);\r\n let good_pos = intersection(setA, setB)\r\n let good_len = good_pos.size;\r\n const start_time = new Date();\r\n let j =0;\r\n let i = 0;\r\n let b_start = 0;\r\n while(i < b.length){\r\n // console.log('here', 'curr = ', j, 'b_start = ', b_start, 'b_end = ', i)\r\n while(j < a.length && a[j] <= b[i]){\r\n // console.log(`curr = ${j}, good_len = ${good_len}`)\r\n if(good_pos.has(a[j])){\r\n good_len -= 1;\r\n }\r\n j += 1;\r\n }\r\n while(b_start < i && b[b_start] + j <= b[i]){\r\n b_start += 1\r\n }\r\n\r\n globalMax = Math.max(globalMax, Math.min(i - b_start + 1, j) + good_len);\r\n // console.log(`globalMax+ = ${globalMax}`)\r\n i++;\r\n }\r\n // console.log(`finish in: ${new Date() - start_time} with ${globalMax} `)\r\n return globalMax;\r\n}\r\n \r\nmodule.exports = count1", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = rns(),\r\n a = rns(),\r\n b = rns();\r\n const calc = () => {\r\n let sa = 0,\r\n sb = 0;\r\n for (; sa < n; sa++) {\r\n if (a[sa] > 0) break;\r\n }\r\n if (sa === n) return 0;\r\n for (; sb < m; sb++) {\r\n if (b[sb] > 0) break;\r\n }\r\n if (sb === m) return 0;\r\n let res = 0,\r\n pre = 0;\r\n for (let i = m - 1, j = n - 1, k = i; i >= sb; i--) {\r\n while (a[j] > b[i]) j--;\r\n if (j < sa || i < sb || i < 0) {\r\n res = Math.max(res, pre);\r\n break;\r\n }\r\n let num = j - sa + 1;\r\n for (; k >= 0 && b[i] - b[k] + 1 <= num; k--) {}\r\n res = Math.max(res, i - k + pre);\r\n if (a[j] === b[i]) pre++;\r\n }\r\n return res;\r\n };\r\n let res = calc();\r\n a.reverse();\r\n b.reverse();\r\n for (let i = 0; i < n; i++) a[i] = -a[i];\r\n for (let i = 0; i < m; i++) b[i] = -b[i];\r\n res += calc();\r\n return res;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a1 = []\r\n var a2 = []\r\n var a = readline().split(' ').map((x, iii) => {\r\n x = parseInt(x)\r\n if (x > 0) a1.push(x)\r\n if (x < 0) a2.push(-x)\r\n return parseInt(x)\r\n })\r\n\r\n var b1 = []\r\n var b2 = []\r\n var b = readline().split(' ').map((x, iii) => {\r\n x = parseInt(x)\r\n if (x > 0) b1.push(x)\r\n if (x < 0) b2.push(-x)\r\n\r\n return parseInt(x)\r\n })\r\n\r\n var ans1 = solve(a1, b1)\r\n var ans2 = solve(a2.reverse(), b2.reverse())\r\n // console.log('-----------')\r\n console.log(ans1 + ans2)\r\n })\r\n}\r\n\r\nfunction solve(a, b) {\r\n var suffix = new Array(a.length + 1).fill(0)\r\n\r\n var right = b.length - 1\r\n for (let i = a.length - 1; i >= 0; i--) {\r\n suffix[i] = suffix[i + 1]\r\n while (right >= 0 && a[i] < b[right]) right--\r\n if (right >= 0 && a[i] === b[right]) suffix[i]++\r\n }\r\n\r\n var left = 0\r\n right = 0\r\n var ans = 0\r\n for (let i = 0; i < b.length; i++) {\r\n while (left < a.length && a[left] <= b[i] + left) left++\r\n while (right < b.length && b[right] - b[i] < left) right++\r\n // console.log(left, right, suffix[i])\r\n ans = Math.max(ans, right - i + suffix[left])\r\n }\r\n\r\n // console.log(suffix)\r\n return ans\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var t = +lines[l++]\n for (var i = 0; i < t; i++) {\n l++\n var a1 = lines[l++].trim().split(' ').map(Number)\n var a2 = lines[l++].trim().split(' ').map(Number)\n console.log(solve(a1, a2))\n }\n});\n\nfunction solve(a, b) {\n const special = b.reduce((o, x) => {\n o[x] = 1\n return o\n }, {})\n const c = []\n a.forEach(x => {\n if (special[x]) c.push(x)\n })\n\n const sep = binarySearch(0, b.length - 1, x => b[x] < 0)\n let m1 = 0\n for (let i = sep + 1; i < b.length; i++) {\n const n = cover(0, b[i], a)\n const l1 = cover(b[i] - n + 1, b[i], b) // after pushing\n const l2 = cover(0, b[i], c) // before\n m1 = Math.max(m1, l1 - l2)\n }\n let m2 = 0\n for (let i = sep; i >= 0; i--) {\n const n = cover(b[i], 0, a)\n const l1 = cover(b[i], b[i] + n - 1, b)\n const l2 = cover(b[i], 0, c, false)\n m2 = Math.max(m2, l1 - l2)\n }\n // console.log(c.length, m1, m2)\n return c.length + m1 + m2\n}\nfunction cover(l, r, b, include = true) {\n const i = binarySearch(0, b.length - 1, x => b[x] < l)\n const j = binarySearch(0, b.length - 1, x => (include ? b[x] <= r : b[x] < r))\n return j - i\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "const solve = (box, goal) => {\n let res = 0;\n\n let mem = {};\n let already = goal.map(() => 0);\n box.forEach(b => (mem[b] = true));\n for (let i = 0; i < goal.length; i++) {\n if (mem[goal[i]]) already[i] = 1;\n }\n for (let i = goal.length - 2; i >= 0; i--) {\n already[i] = already[i + 1] + already[i];\n }\n already.push(0);\n\n let j = 0;\n for (let i = 0; i < goal.length; i++) {\n while (j < box.length && box[j] - j <= goal[i]) {\n j++;\n }\n let currentRes = null;\n let l = i,\n r = goal.length - 1;\n\n while (true) {\n if (l > r) break;\n const m = Math.floor((l + r) / 2);\n if (goal[m] <= goal[i] - 1 + j) {\n currentRes = m;\n l = m + 1;\n } else r = m - 1;\n }\n currentRes = currentRes === null ? 0 : currentRes - i + 1;\n res = Math.max(res, currentRes + already[currentRes + i]);\n }\n return res;\n};\n\nconst main = () => {\n const start = new Date();\n let test = readInt();\n while (test--) {\n let [n, m] = readListInt();\n const box = readListInt();\n const goal = readListInt();\n const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));\n\n const boxLeft = box\n .filter(i => i < 0)\n .map(i => -i)\n .reverse();\n const goalLeft = goal\n .filter(i => i < 0)\n .map(i => -i)\n .reverse();\n\n const left = solve(boxLeft, goalLeft);\n console.log(left + right);\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}], "negative_code": [{"source_code": "\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const [n,m] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b = readLine().split(' ').map(Number);\r\n const a0 = a.filter(num => num < 0);\r\n const a1 = a.filter(num => num >= 0);\r\n const b0 = b.filter(num => num < 0);\r\n const b1= b.filter(num => num >= 0);\r\n const a0_filter = a0.filter(num => num >= b0[0]);\r\n const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);\r\n console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction count1(a,b,opt = 0){\r\n if(a.length === 0) return 0;\r\n let globalMax = 0;\r\n if(opt === 0){\r\n let j = a.length - 1;\r\n for(let i = b.length - 1; i >= 0; i--){\r\n a[j] = b[i];\r\n if(a[j] <= a[j-1]){\r\n let c = 1;\r\n for(let m = j-1; m >= 0 ; m--){\r\n a[m] = a[j] - c;\r\n if(a[m - 1] < a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = a.length - 1 ; k >= 0; k--){\r\n for(let n = b.length - 1; n >= 0; n--){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n if(a[a.length - 1] - a.length + 1 <= b[0]) break;\r\n }\r\n }\r\n else {\r\n let j =0;\r\n for(let i = 0; i < b.length; i++){\r\n a[j] = b[i];\r\n if(a[j] >= a[j+1]){\r\n let c = 1;\r\n for(let m = j+1; m < a.length ; m++){\r\n a[m] = a[j] + c;\r\n if(a[m + 1] > a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = 0 ; k < a.length; k++){\r\n for(let n = 0; n < b.length; n++){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n \r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n if(a[0] + a.length - 1 >= b[b.length - 1]) break;\r\n }\r\n }\r\n return globalMax;\r\n}\r\n\r\nmodule.exports = count1"}, {"source_code": "\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const [n,m] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b = readLine().split(' ').map(Number);\r\n const a0 = a.filter(num => num < 0);\r\n const a1 = a.filter(num => num >= 0);\r\n const b0 = b.filter(num => num < 0);\r\n const b1= b.filter(num => num >= 0);\r\n const a0_filter = a0.filter(num => num >= b0[0]);\r\n const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);\r\n console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction count1(a,b,opt = 0){\r\n if(a.length === 0) return 0;\r\n let globalMax = 0;\r\n if(opt === 0){\r\n let j = a.length - 1;\r\n for(let i = b.length - 1; i >= 0; i--){\r\n a[j] = b[i];\r\n if(a[j] <= a[j-1]){\r\n let c = 1;\r\n for(let m = j-1; m >= 0 ; m--){\r\n a[m] = a[j] - c;\r\n if(a[m - 1] < a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = a.length - 1 ; k >= 0; k--){\r\n for(let n = b.length - 1; n >= 0; n--){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n }\r\n }\r\n else {\r\n let j =0;\r\n for(let i = 0; i < b.length; i++){\r\n a[j] = b[i];\r\n if(a[j] >= a[j+1]){\r\n let c = 1;\r\n for(let m = j+1; m < a.length ; m++){\r\n a[m] = a[j] + c;\r\n if(a[m + 1] > a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = 0 ; k < a.length; k++){\r\n for(let n = 0; n < b.length; n++){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n \r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n }\r\n }\r\n return globalMax;\r\n}\r\n\r\nmodule.exports = count1"}, {"source_code": "\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n const [n,m] = readLine().split(' ').map(Number);\r\n const a = readLine().split(' ').map(Number);\r\n const b = readLine().split(' ').map(Number);\r\n const a0 = a.filter(num => num < 0);\r\n const a1 = a.filter(num => num >= 0);\r\n const b0 = b.filter(num => num < 0);\r\n const b1= b.filter(num => num >= 0);\r\n const a0_filter = a0.filter(num => num >= b0[0]);\r\n const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);\r\n console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction count1(a,b,opt = 0){\r\n if(a.length === 0) return 0;\r\n let globalMax = 0;\r\n if(opt === 0){\r\n let j = a.length - 1;\r\n for(let i = b.length - 1; i >= 0; i--){\r\n a[j] = b[i];\r\n if(a[j] <= a[j-1]){\r\n let c = 1;\r\n for(let m = j-1; m >= 0 ; m--){\r\n a[m] = a[j] + c;\r\n if(a[m - 1] < a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = a.length - 1 ; k >= 0; k--){\r\n for(let n = b.length - 1; n >= 0; n--){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n }\r\n }\r\n else {\r\n let j =0;\r\n for(let i = 0; i < b.length; i++){\r\n a[j] = b[i];\r\n if(a[j] >= a[j+1]){\r\n let c = 1;\r\n for(let m = j+1; m < a.length ; m++){\r\n a[m] = a[j] + c;\r\n if(a[m + 1] > a[m]) break;\r\n c++;\r\n }\r\n }\r\n // console.log(`a = ${a}, b = ${b}`);\r\n let localMax = 0;\r\n for(let k = 0 ; k < a.length; k++){\r\n for(let n = 0; n < b.length; n++){\r\n if(a[k] === b[n]){\r\n localMax++;\r\n break;\r\n }\r\n }\r\n \r\n }\r\n if(localMax>globalMax){\r\n globalMax = localMax;\r\n }\r\n // console.log(b, a, localMax,globalMax);\r\n if(globalMax === b.length || globalMax === a.length) break;\r\n }\r\n }\r\n return globalMax;\r\n}\r\n\r\nmodule.exports = count1"}, {"source_code": "const solve = (box, goal) => {\n let res = 0;\n\n let mem = {};\n let already = goal.map(() => 0);\n box.forEach(b => (mem[b] = true));\n for (let i = 0; i < goal.length; i++) {\n if (mem[goal[i]]) already[i] = 1;\n }\n for (let i = goal.length - 2; i >= 0; i--) {\n already[i] = already[i + 1] + already[i];\n }\n already.push(0);\n\n let j = 0;\n for (let i = 0; i < goal.length; i++) {\n while (j < box.length && box[j] - j <= goal[i]) {\n j++;\n }\n let currentRes = 0;\n let l = i,\n r = goal.length - 1;\n\n while (true) {\n if (l > r) break;\n const m = Math.floor((l + r) / 2);\n if (goal[m] <= goal[i] - 1 + j) {\n currentRes = m;\n l = m + 1;\n } else r = m - 1;\n }\n currentRes = currentRes - i + 1;\n res = Math.max(res, currentRes + already[currentRes + i]);\n }\n return res;\n};\n\nconst main = () => {\n const start = new Date();\n let test = readInt();\n while (test--) {\n let [n, m] = readListInt();\n const box = readListInt();\n const goal = readListInt();\n const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));\n\n const boxLeft = box\n .filter(i => i < 0)\n .map(i => -i)\n .reverse();\n const goalLeft = goal\n .filter(i => i < 0)\n .map(i => -i)\n .reverse();\n\n const left = solve(boxLeft, goalLeft);\n console.log(left + right);\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "const solve = (box, goal) => {\n let mem = {};\n for (let i = 0; i < box.length; i++) {\n mem[box[i]] = true;\n }\n let res = 0;\n for (let i = 0; i < goal.length; i++) {\n if (mem[goal[i]]) res += 1;\n }\n\n for (let i = 0; i < goal.length; i++) {\n // Try to move to fill goal[i]\n // Find how many boxes we have to push to move to goal[i]\n let l = 0,\n r = box.length;\n let pos = null;\n while (true) {\n if (l > r) break;\n const m = Math.floor((l + r) / 2);\n if (box[m] <= goal[i]) {\n pos = m;\n l = m + 1;\n } else r = m - 1;\n }\n if (pos === null) continue;\n // Boxes now cover from goal[i] to goal[i] + pos\n const coverRange = goal[i] + pos;\n l = i;\n r = goal.length;\n pos = i;\n while (true) {\n if (l > r) break;\n const m = Math.floor((l + r) / 2);\n if (goal[m] <= coverRange) {\n pos = m;\n l = m + 1;\n } else r = m - 1;\n }\n const coverBoxes = pos - i + 1;\n // Calculate already covered goal from pos-th goal\n const already = goal.map(() => 0);\n for (let i = goal.length - 1; i >= 0; i--) {\n if (mem[goal[i]]) already[i] = 1;\n }\n for (let i = goal.length - 2; i >= 0; i--) {\n already[i] = already[i + 1] + already[i];\n }\n already.push(0);\n\n res = Math.max(res, coverBoxes + already[pos + 1]);\n }\n\n return res;\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const [n, m] = readListInt();\n const box = readListInt();\n const goal = readListInt();\n const left = solve(\n box\n .filter(i => i < 0)\n .map(i => -i)\n .reverse(),\n goal\n .filter(i => i < 0)\n .map(i => -i)\n .reverse()\n );\n const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));\n console.log(left + right);\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = rns(),\r\n a = rns(),\r\n b = rns();\r\n const calc = () => {\r\n let sa = 0,\r\n sb = 0;\r\n for (; sa < n; sa++) {\r\n if (a[sa] > 0) break;\r\n }\r\n if (sa === n) return 0;\r\n for (; sb < m; sb++) {\r\n if (b[sb] > 0) break;\r\n }\r\n if (sb === m) return 0;\r\n let res = 0,\r\n pre = 0;\r\n for (let i = m - 1, j = n - 1, k = i; i >= 0; i--) {\r\n while (a[j] > b[i]) j--;\r\n if (a[j] === b[i]) {\r\n pre = 1;\r\n j--;\r\n i--;\r\n }\r\n if (j < sa || i < sb || i < 0) {\r\n res = Math.max(res, pre);\r\n break;\r\n }\r\n let num = j - sa + 1;\r\n for (; k >= 0 && b[i] - b[k] + 1 <= num; k--) {}\r\n res = Math.max(res, i - k + pre);\r\n }\r\n return res;\r\n };\r\n let res = calc();\r\n a.reverse();\r\n b.reverse();\r\n for (let i = 0; i < n; i++) a[i] = -a[i];\r\n for (let i = 0; i < m; i++) b[i] = -b[i];\r\n res += calc();\r\n return res;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = rns(),\r\n a = rns(),\r\n b = rns();\r\n const calc = () => {\r\n let sa = 0,\r\n sb = 0;\r\n for (; sa < n; sa++) {\r\n if (a[sa] > 0) break;\r\n }\r\n if (sa === n) return 0;\r\n for (; sb < m; sb++) {\r\n if (b[sb] > 0) break;\r\n }\r\n if (sb === m) return 0;\r\n let res = 0,\r\n pre = 0;\r\n for (let i = m - 1, j = n - 1, k = i; i >= 0; i--) {\r\n while (a[j] > b[i]) j--;\r\n let flag = 0;\r\n if (a[j] === b[i]) {\r\n pre = 1;\r\n j--;\r\n flag = 1;\r\n }\r\n if (j < sa || flag && (i - 1 < sa || !i)) {\r\n res = Math.max(res, pre);\r\n break;\r\n }\r\n let num = j - sa + 1;\r\n for (; k >= 0 && b[i] - b[k] - flag < num; k--) {}\r\n res = Math.max(res, i - k - flag + pre);\r\n }\r\n return res;\r\n };\r\n let res = calc();\r\n a.reverse();\r\n b.reverse();\r\n for (let i = 0; i < n; i++) a[i] = -a[i];\r\n for (let i = 0; i < m; i++) b[i] = -b[i];\r\n res += calc();\r\n return res;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "a2b99448d6267a66bddfdcad9add311b"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n // return Math.floor(n * m / 3) + ((n * m % 3) ? 1 : 0)\n if (n > m) return solve(m, n)\n // n < m\n if (!(n % 3) || !(m % 3)) return m * n / 3\n if (n === 1) return Math.floor(m / 3) + ((m % 3) ? 1 : 0)\n if (n === 2) return n * Math.floor(m / 3) + (m % 3)\n const r = n % 3\n return solve(n - r, m) + solve(r, m)\n}\n", "positive_code": [{"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = readline().split(' ').map(Number);\r\n var ans; \r\n \r\n ans = Math.ceil((n[0] * n[1]) / 3);\r\n print(ans);\r\n\r\n}"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet m;\r\nfunction solve() {\r\n if ((n % 3) == 0) {\r\n return m * Math.trunc(n / 3);\r\n }\r\n if ((m % 3) == 0) {\r\n return n * Math.trunc(m / 3);\r\n }\r\n let q1 = (n - n % 3) * (m - m % 3);\r\n let sum = Math.trunc(q1 / 3);\r\n let q2 = (m % 3) * (n - n % 3);\r\n sum += Math.trunc(q2 / 3);\r\n let q3 = (n % 3) * (m - m % 3);\r\n sum += Math.trunc(q3 / 3);\r\n let q4 = (n % 3) * (m % 3);\r\n sum += Math.max(1, Math.trunc(q4 / 2));\r\n return sum;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n m = nextInt();\r\n printf(\"%d\\n\", solve());\r\n }\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1];\n var ans = (a * b + 2) / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t ; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1];\n var ans = (a * b + 2) / 3;\n console.log(Math.floor(ans));\n }\n});\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [h, w] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (h < 2) console.log(Math.ceil(w / 3));\r\n else if (w < 2) console.log(Math.ceil(h / 3));\r\n else {\r\n console.log(Math.ceil((h * w) / 3));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar size = N * M;\r\n\t\tif(size % 3 == 0){\r\n\t\t\tmyout(size / 3);\r\n\t\t}else{\r\n\t\t\tmyout(Math.ceil(size / 3));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n let a = parseInt(readline())\r\n while(a--){\r\n var b = readline().split(' ').map(Number)\r\n var c = ((b[0] * b[1]) + 2) / 3\r\n print(Math.floor(c))\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = readline().split(' ').map(Number)\r\n var c = ((b[0] * b[1]) + 2) / 3\r\n print(Math.floor(c))\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar size = N * M;\r\n\t\tif(size % 3 == 0){\r\n\t\t\tmyout(size / 3);\r\n\t\t}else{\r\n\t\t\tmyout(Math.ceil(size / 3));\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n // return Math.floor(n * m / 3) + ((n * m % 3) ? 1 : 0)\n if (n > m) return solve(m, n)\n // n < m\n if (!(n % 3) || !(m % 3)) return m * n / 3\n if (n === 1 || n === 2) return n * (Math.floor(m / 3) + ((m % 3) ? 1 : 0))\n const r = n % 3\n return solve(n - r, m) + solve(r, m)\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (n === 1) {\n if (m === 1) return 0\n if (m === 2) return 1\n if (m % 3) {\n return Math.floor(m / 3) - 1 + 2\n } else {\n return Math.floor(m / 3)\n }\n }\n if (m & 1) {\n return Math.min(n * solve(1, m), m * solve(1, n))\n } else {\n return solve(n, m - 1) + solve(n, 1)\n }\n } else {\n if (n === 2 && m === 2) return 2\n if (m & 1) {\n return solve(n - 1, m) + solve(1, m)\n } else {\n return solve(n - 1, m - 1) + solve(1, n) + solve(1, m - 1)\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (n === 1) {\n if (m === 1) return 0\n if (m === 2) return 1\n return Math.floor(m / 3) + (m % 3 ? solve(n, m % 3) : 0)\n }\n if (m & 1) {\n return Math.min(n * solve(1, m), m * solve(1, n))\n } else {\n return solve(n, m - 1) + solve(n, 1)\n }\n } else {\n if (n === 2 && m === 2) return 2\n if (m & 1) {\n return solve(n - 1, m) + solve(1, m)\n } else {\n return solve(n - 1, m - 1) + solve(1, n) + solve(1, m - 1)\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (n === 1) return Math.floor(m / 2)\n if (m & 1) {\n return m * Math.floor(n / 2)\n } else {\n const h = m / 2\n return h & 1\n ? 2 * solve(n, h)\n : solve(n, h - 1) + solve(n, h + 1)\n }\n } else {\n const h = n / 2\n // if (m & 1) {\n return h & 1\n ? 2 * solve(h, m)\n : solve(h - 1, m) + solve(h + 1, m)\n // } else {\n // }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n return Math.min(solve2(n, m), solve1(n, m))\n}\nfunction solve2(n, m) {\n if (n > m) return solve2(m, n)\n // n < m\n if (n & 1) {\n if (m & 1) {\n if (n === 1) return Math.floor(m / 2)\n return m * Math.floor(n / 2)\n } else {\n if (n === 1) {\n if (m === 2) return 1\n if (m === 4) return 2\n const h = m / 2\n return h & 1\n ? 2 * solve2(n, h)\n : solve2(n, h - 1) + solve2(n, h + 1)\n }\n return m * Math.floor(n / 2)\n }\n } else {\n if (m & 1) {\n return n * Math.floor(m / 2)\n } else {\n const h = m / 2\n return h & 1 ? 2 * solve2(n, h) : solve2(n, h - 1) + solve2(n, h + 1)\n }\n }\n}\nfunction solve1(n, m) {\n if (n > m) return solve1(m, n)\n // n < m\n if (n & 1) {\n if (m & 1) {\n if (n === 1) return Math.floor(m / 2)\n return m * Math.floor(n / 2)\n } else {\n if (m === 2) return 1 // 1 2\n return 2 * solve1(n, m / 2)\n }\n } else {\n if (m & 1) {\n return n * Math.floor(m / 2)\n } else {\n if (m === 2) return 2 // 2 2\n return solve1(n, m / 2 - 1) + solve1(n, m / 2 + 1)\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (m & 1) {\n if (n === 1) return Math.floor(m / 2)\n return m * Math.floor(n / 2)\n } else {\n if (n === 1) {\n if (m === 2) return 1\n if (m === 4) return 2\n const h = m / 2\n return h & 1\n ? 2 * solve(n, h)\n : solve(n, h - 1) + solve(n, h + 1)\n }\n return m * Math.floor(n / 2)\n }\n } else {\n if (m & 1) {\n return n * Math.floor(m / 2)\n } else {\n const h = m / 2\n return h & 1 ? 2 * solve(n, h) : solve(n, h - 1) + solve(n, h + 1)\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (m & 1) {\n if (n === 1) return Math.floor(m / 2)\n return m * Math.floor(n / 2)\n } else {\n if (m === 2) return 1 // 1 2\n return 2 * solve(n, m / 2)\n }\n } else {\n if (m & 1) {\n return n * Math.floor(m / 2)\n } else {\n if (m === 2) return 2 // 2 2\n return solve(n, m / 2 - 1) + solve(n, m / 2 + 1)\n }\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, m)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m) {\n if (n > m) return solve(m, n)\n // n < m\n if (n & 1) {\n if (n === 1) return Math.floor(m / 2)\n if (m & 1) {\n return m * Math.floor(n / 2)\n } else {\n return 2 * solve(n, m / 2)\n }\n } else {\n if (m & 1) {\n return n * Math.floor(m / 2)\n } else {\n return 2 * solve(n, m / 2)\n }\n }\n}\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1];\n var ans = a * b + (2 / 3);\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0], b = k[1];\n var ans = a * b + 2 / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').map(Number);\n var a = k[0], b = k[1];\n var ans = a * b + 2 / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').map(Number);\n var a = k[1], b = k[2];\n var ans = ((a * b) + 2) / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').map(Number);\n var a = k[1], b = k[1];\n var ans = ((a * b) + 2) / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').map(Number);\n var a = k[0], b = k[1];\n var ans = ((a * b) + 2) / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split('').map(Number);\n var a = k[0], b = k[1];\n var ans = ((a * b) + 2) / 3;\n console.log((ans));\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t ; i++){\n var k = lines[i].split('').map(Number);\n var a = k[0], b = k[1];\n var ans = ((a * b) + 2) / 3;\n console.log(Math.floor(ans));\n }\n});"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [h, w] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (h < 2) console.log(Math.ceil(w / 3));\r\n else if (w < 2) console.log(Math.ceil(w / 3));\r\n else {\r\n console.log(Math.ceil((h * w) / 3));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [h, w] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (h < 2) console.log(Math.ceil(w / 3));\r\n else if (w < 2) console.log(Math.ceil(w / 3));\r\n else {\r\n let t1 = Math.ceil(h / 3) * w;\r\n let t2 = Math.ceil(w / 3) * h;\r\n console.log(Math.min(t1, t2));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [h, w] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (h < 2) console.log(Math.floor(w / 2));\r\n else if (w < 2) console.log(Math.floor(h / 2));\r\n else {\r\n let t1 = Math.floor(h / 2) * w;\r\n let t2 = Math.floor(w / 2) * h;\r\n console.log(Math.min(t1, t2));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "70a0b98f2bb12990a0fa46aaf13134af"} {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\n\nvar numBoys=parseInt(readline().split(' ')[0],10);\nvar sb=readline().split(' ').map(item=>parseInt(item,10));\nvar numGirsl=parseInt(readline().split(' ')[0],10);\nvar sg=readline().split(' ').map(item=>parseInt(item,10));\nvar count=0;\nsb.sort((a,b)=>{return a-b});\nsg.sort((a,b)=>{return a-b});\nfor(var i=0;il-r)\nB.sort((l,r)=>l-r)\nvar i=0, j=0, r=0;\nwhile (iB[j]) ++j;\n}\n\nprint(r)\n"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar a = readline().split(' ').map(Number);\nvar input = readline().split(' ').map(Number), m = input[0];\nvar b = readline().split(' ').map(Number);\n\n\na = a.sort(function(a,b) { return a - b;});\nb = b.sort(function(a,b) { return a - b;});\n\nvar ida = 0;\nvar idb = 0;\nvar res = 0;\nwhile (ida < n && idb < m) {\n if (a[ida] < b[idb] - 1) ida++;\n else if (a[ida] > b[idb] + 1) idb++;\n else {\n res++;\n ida++;\n idb++;\n }\n}\nwrite(res);\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n] = input[0].split(' ').map(x => parseInt(x));\n const boys = input[1].split(' ').map(x => parseInt(x));\n\n let [k] = input[2].split(' ').map(x => parseInt(x));\n const girls = input[3].split(' ').map(x => parseInt(x));\n\n boys.sort((a, b) => a - b); girls.sort((a, b) => a - b);\n let b = 0, g = 0;\n\n let answ = 0;\n while (b < boys.length && g < girls.length) {\n if (Math.abs( boys[b] - girls[g] ) <= 1) {\n answ += 1;\n b += 1; g += 1; continue;\n } else {\n if (boys[b] > girls[g]) g += 1;\n else b += 1;\n }\n }\n\n console.log(answ);\n}); \n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let b = readline();\n let bSkills = readline().split(' ');\n bSkills = bSkills.map(ele => parseInt(ele));\n let g = readline();\n let gSkills = readline().split(' ')\n gSkills = gSkills.map(ele => parseInt(ele));\n\n berSuBall(bSkills, gSkills);\n}\n\n\nfunction berSuBall(boysSkills, girlsSkills){\n boysSkills.sort((a, b) => a - b);\n girlsSkills.sort((a, b) => a - b);\n\n let count = 0;\n\n for(let i = 0; i < boysSkills.length; i++){\n for(let j = 0; j < girlsSkills.length; j++){\n let dif = Math.abs(boysSkills[i] - girlsSkills[j]);\n if(dif <= 1){\n count++;\n boysSkills[i] = Infinity;\n girlsSkills[j] = Infinity;\n }\n }\n }\n console.log(count)\n return count;\n}"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\tif(!output[+input[i]]){\n\t\t\toutput[+input[i]] = 1;\n\t\t}\n\t\telse{\n\t\t\toutput[+input[i]]++;\n\t\t}\n\t}\n}\n\nvar n = +readline(), boys = readline().split(\" \"), m = +readline(), girls = readline().split(\" \"),\nboyslevs = {}, girlslevs = {}, pairs = 0;\nmaxb = Math.max.apply(null,boys);\nmaxg = Math.max.apply(null,girls);\nminb = Math.min.apply(null,boys);\nming = Math.min.apply(null,girls);\n\nif((maxb < ming-1) || (maxg < minb-1)){\n\twrite(0);\n}\nelse{\n\tcountUniqueElements(boys,boyslevs);\n\tcountUniqueElements(girls,girlslevs);\n\t\n\tfor(level in boyslevs){\n\t\tlevel = +level;\n\n\t\tif(girlslevs[level-1]){\n\t\t\tif(boyslevs[level] > girlslevs[level-1]){\n\t\t\t\tpairs += girlslevs[level-1];\n\t\t\t\tboyslevs[level] -= girlslevs[level-1];\n\t\t\t\tdelete girlslevs[level-1];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level-1]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level-1];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level-1] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\n\t\tif(girlslevs[level] && boyslevs[level]){\n\t\t\tif(boyslevs[level] > girlslevs[level]){\n\t\t\t\tpairs += girlslevs[level];\n\t\t\t\tboyslevs[level] -= girlslevs[level];\n\t\t\t\tdelete girlslevs[level];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\n\t\tif(girlslevs[level+1] && boyslevs[level]){\n\t\t\tif(boyslevs[level] > girlslevs[level+1]){\n\t\t\t\tpairs += girlslevs[level+1];\n\t\t\t\tboyslevs[level] -= girlslevs[level+1];\n\t\t\t\tdelete girlslevs[level+1];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level+1]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level+1];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level+1] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(pairs);\n}"}, {"source_code": "const N = 107;\n\nvar n, m;\nvar a, b;\nvar state;\nvar used;\nvar token = [];\n\nfunction initializeData() {\n a = new Array(N);\n b = new Array(N);\n\n used = new Array(N);\n state = new Array(N);\n\n for(var i=0;i>0);\n };\n\n this.clear = function() {\n this.arr = [];\n };\n\n this.size = function() {\n return this.arr.length;\n };\n\n this.empty = function() {\n if(this.arr.length==0) return true;\n return false;\n };\n\n this.push = function(val) {\n this.arr.push(val);\n\n var idx=this.arr.length-1;\n\n while(idx>0 && this.cmp(this.arr[idx], this.arr[this.getParent(idx)])) {\n this.swapIndices(idx, this.getParent(idx));\n idx=this.getParent(idx);\n }\n };\n\n this.pop = function() {\n this.swapIndices(0, this.arr.length-1);\n this.arr.pop();\n\n var idx=0, l, r;\n\n while(true) {\n l = this.getLeft(idx);\n r = this.getRight(idx);\n\n if(l>=this.arr.length) {\n break;\n }\n if(r>=this.arr.length) {\n if(this.cmp(this.arr[l], this.arr[idx])) {\n this.swapIndices(l, idx);\n }\n\n break;\n }\n\n if(this.cmp(this.arr[l], this.arr[idx]) && !this.cmp(this.arr[r], this.arr[l])) {\n this.swapIndices(l, idx);\n idx=l;\n }\n else if(this.cmp(this.arr[r], this.arr[idx]) && !this.cmp(this.arr[l], this.arr[r])) {\n this.swapIndices(r, idx);\n idx=r;\n }\n else {\n break;\n }\n }\n };\n\n this.top = function() {\n return this.arr[0];\n };\n};\n\nfunction cmpNumbers(a, b) {\n if(an || r>m) {\n return 0;\n }\n\n if(used[l][r]==true) {\n return state[l][r];\n }\n\n var ans = Math.max(recurse(l+1,r), recurse(l,r+1));\n\n if(Math.abs(a[l]-b[r])<=1) {\n ans = Math.max(ans, recurse(l+1,r+1)+1);\n }\n\n used[l][r]=true;\n state[l][r]=ans;\n\n return ans;\n}\n\ninitializeData();\n\nn = readline();\ntoken = readline().split(' ');\nfor(var i=0;in || r>m) {\n return 0;\n }\n\n if(used[l][r]==true) {\n return state[l][r];\n }\n\n var ans = Math.max(recurse(l+1,r), recurse(l,r+1));\n\n if(Math.abs(a[l]-b[r])<=1) {\n ans = Math.max(ans, recurse(l+1,r+1)+1);\n }\n\n used[l][r]=true;\n state[l][r]=ans;\n\n return ans;\n}\n\ninitializeData();\n\nn = readline();\ntoken = readline().split(' ');\nfor(var i=0;i a - b);\nreadline();\nlet secondGroup = readline().getNumArray().sort((a, b) => a - b);\nlet counter = 0;\n\nif (firstGroup.length > secondGroup.length) {\n const tempGroup = firstGroup; \n firstGroup = secondGroup;\n secondGroup = tempGroup;\n}\n\nfor (let i = 0 ; i < firstGroup.length; i++) {\n for (let j = 0; j < secondGroup.length; j++) {\n if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {\n counter++;\n secondGroup.splice(j, 1);\n break;\n }\n }\n}\n\nwrite(counter);"}, {"source_code": "var man = readline();\nvar str = readline().split(\" \").sort((x,y)=>x-y);\nvar woman = readline();\nvar str2 = readline().split(\" \").sort((x,y)=>x-y);\nvar res = 0;\n\tfor (var i=0; i<+man; i++){\n\t\tfor (var j=0; j<+woman; j++){\n\t\t\tif (Math.abs(+str[i]-str2[j])<2){\n\t\t\t\tres++;\n\t\t\t\tstr2[j]=\"-\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\n\tprint(res);\n"}, {"source_code": "var input = [\n '4',\n '1 4 6 2',\n '5',\n '5 1 5 7 9'\n]\nvar inputIndex = 0;\n/*function readline(){\n return input[inputIndex++];\n}\nfunction print(data){\n console.log(data);\n}*/\nvar n = parseInt(readline())\nvar a = readline().split(' ')\nvar m = parseInt(readline())\nvar b = readline().split(' ')\n\nvar d1 = {}\nvar d2 = {}\n\nfor(var i = 0;i boys[b]){\n b++;\n } else {\n g++;\n }\n }\n \n return result\n }\n \n readline();\n var girls = readline().split(\" \").map(Number);\n readline();\n var boys = readline().split(\" \").map(Number);\n \n print(sa(girls,boys));"}], "negative_code": [{"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\tif(!output[+input[i]]){\n\t\t\toutput[+input[i]] = 1;\n\t\t}\n\t\telse{\n\t\t\toutput[+input[i]]++;\n\t\t}\n\t}\n}\n\nvar n = +readline(), boys = readline().split(\" \"), m = +readline(), girls = readline().split(\" \"),\nboyslevs = {}, girlslevs = {}, pairs = 0;\nmaxb = Math.max.apply(null,boys);\nmaxg = Math.max.apply(null,girls);\nminb = Math.min.apply(null,boys);\nming = Math.min.apply(null,girls);\n\nif((maxb < ming) || (maxg < minb)){\n\twrite(0);\n}\nelse{\n\tcountUniqueElements(boys,boyslevs);\n\tcountUniqueElements(girls,girlslevs);\n\t\n\tfor(level in boyslevs){\n\t\tlevel = +level;\n\n\t\tif(girlslevs[level-1]){\n\t\t\tif(boyslevs[level] > girlslevs[level-1]){\n\t\t\t\tpairs += girlslevs[level-1];\n\t\t\t\tboyslevs[level] -= girlslevs[level-1];\n\t\t\t\tdelete girlslevs[level-1];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level-1]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level-1];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level-1] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\n\t\tif(girlslevs[level] && boyslevs[level]){\n\t\t\tif(boyslevs[level] > girlslevs[level]){\n\t\t\t\tpairs += girlslevs[level];\n\t\t\t\tboyslevs[level] -= girlslevs[level];\n\t\t\t\tdelete girlslevs[level];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\n\t\tif(girlslevs[level+1] && boyslevs[level]){\n\t\t\tif(boyslevs[level] > girlslevs[level+1]){\n\t\t\t\tpairs += girlslevs[level+1];\n\t\t\t\tboyslevs[level] -= girlslevs[level+1];\n\t\t\t\tdelete girlslevs[level+1];\n\t\t\t}\n\t\t\telse if(boyslevs[level] == girlslevs[level+1]){\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tdelete girlslevs[level+1];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpairs += boyslevs[level];\n\t\t\t\tgirlslevs[level+1] -= boyslevs[level];\n\t\t\t\tdelete boyslevs[level];\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(pairs);\n}"}, {"source_code": "const N = 107;\n\nvar n, m;\nvar a, b;\nvar state;\nvar used;\nvar token = [];\n\nfunction initializeData() {\n a = new Array(N);\n b = new Array(N);\n\n used = new Array(N);\n state = new Array(N);\n\n for(var i=0;in || r>m) {\n return 0;\n }\n\n if(used[l][r]==true) {\n return state[l][r];\n }\n\n var ans = Math.max(recurse(l+1,r), recurse(l,r+1));\n\n if(Math.abs(a[l]-b[r])<=1) {\n ans = Math.max(ans, recurse(l+1,r+1)+1);\n }\n\n used[l][r]=true;\n state[l][r]=ans;\n\n return ans;\n}\n\ninitializeData();\n\nn = readline();\ntoken = readline().split(' ');\nfor(var i=0;in || r>m) {\n return 0;\n }\n\n if(used[l][r]==true) {\n return state[l][r];\n }\n\n var ans = Math.max(recurse(l+1,r), recurse(l,r+1));\n\n if(Math.abs(a[l]-b[r])<=1) {\n ans = Math.max(ans, recurse(l+1,r+1)+1);\n }\n\n used[l][r]=true;\n state[l][r]=ans;\n\n return ans;\n}\n\ninitializeData();\n\nn = readline();\ntoken = readline().split(' ');\nfor(var i=0;i a - b);\nreadline();\nlet secondGroup = readline().getNumArray().sort((a, b) => a - b);\nlet counter = 0;\n\nif (firstGroup.length > secondGroup.length) {\n const tempGroup = firstGroup; \n firstGroup = secondGroup;\n secondGroup = tempGroup;\n}\n\nfor (let i = 0 ; i < firstGroup.length; i++) {\n for (let j = 0; j < secondGroup.length; j++) {\n if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {\n counter++;\n secondGroup.splice(j, 1);\n }\n }\n}\n\nwrite(counter);"}, {"source_code": "var man = readline();\nvar str = readline().split(\" \");\nvar woman = readline();\nvar str2 = readline().split(\" \");\nvar res = 0;\n\tfor (var i=0; i<+man; i++){\n\t\tfor (var j=0; j<+woman; j++){\n\t\t\tif (Math.abs(+str[i]-str2[j])<2){\n\t\t\t\tres++;\n\t\t\t\tstr2[j]=\"-\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\n\tprint(res);\n"}, {"source_code": "var man = readline();\nvar str = readline().split(\" \");\nvar woman = readline();\nvar str2 = readline().split(\" \");\nvar res = 0;\n\tfor (var i=0; i<+man; i++){\n\t\tfor (var j=0; j<+woman; j++){\n\t\t\tif (Math.abs(+str[i]-str2[j])<2){\n\t\t\t\tres++;\n\t\t\t\tstr2[j]=\"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\n\tprint(res);\n"}, {"source_code": "var input = [\n '4',\n '1 2 3 4',\n '4',\n '10 11 12 13'\n]\nvar inputIndex = 0;\n/*function readline(){\n return input[inputIndex++];\n}\nfunction print(data){\n console.log(data);\n}*/\nvar n = parseInt(readline())\nvar a = readline().split(' ')\nvar m = parseInt(readline())\nvar b = readline().split(' ')\n\nvar d1 = {}\nvar d2 = {}\n\nfor(var i = 0;i b;});\nb = b.sort(function(a,b) { return a > b;});\n\nvar ida = 0;\nvar idb = 0;\nvar res = 0;\nwhile (ida < n && idb < m) {\n if (a[ida] < b[idb] - 1) ida++;\n else if (a[ida] > b[idb] + 1) idb++;\n else {\n res++;\n ida++;\n idb++;\n }\n}\nwrite(res);\n"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\n\nvar numBoys=parseInt(readline().split(' ')[0],10);\nvar sb=readline().split(' ').map(item=>parseInt(item,10));\nvar numGirsl=parseInt(readline().split(' ')[0],10);\nvar sg=readline().split(' ').map(item=>parseInt(item,10));\nvar count=0;\nfor(var i=0;iparseInt(item,10));\nvar numGirsl=parseInt(readline().split(' ')[0],10);\nvar sg=readline().split(' ').map(item=>parseInt(item,10));\nvar count=0;\nfor(var i=0;iparseInt(item,10));\nvar numGirsl=parseInt(readline().split(' ')[0],100);\nvar sg=readline().split(' ').map(item=>parseInt(item,10));\nvar count=0;\nfor(var i=0;iparseInt(item,10));\nvar numGirsl=parseInt(readline().split(' ')[0],10);\nvar sg=readline().split(' ').map(item=>parseInt(item,10));\nvar count=0;\nfor(var i=0;i parseInt(ele));\n let g = readline();\n let girlsSkills = readline().split(' ')\n girlsSkills = girlsSkills.map(ele => parseInt(ele));\n\n berSuBall(bSkills, gSkills);\n}\n\n\nfunction berSuBall(boysSkills, girlsSkills){\n boysSkills.sort((a, b) => a - b);\n girlsSkills.sort((a, b) => a - b);\n\n let count = 0;\n\n for(let i = 0; i < boysSkills.length; i++){\n for(let j = 0; j < girlsSkills.length; j++){\n let dif = Math.abs(boysSkills[i] - girlsSkills[j]);\n if(dif <= 1){\n count++;\n boysSkills[i] = Infinity;\n girlsSkills[j] = Infinity;\n }\n }\n } return count;\n}"}, {"source_code": "function read() {\n let b = readline();\n let bSkills = readline().split(' ');\n boysSkills = boysSkills.map(ele => parseInt(ele));\n let g = readline();\n let girlsSkills = readline().split(' ')\n girlsSkills = girlsSkills.map(ele => parseInt(ele));\n \n berSuBall(bSkills, gSkills);\n}\n \n \nfunction berSuBall(boysSkills, girlsSkills){\n boysSkills.sort((a, b) => a - b);\n girlsSkills.sort((a, b) => a - b);\n \n let count = 0;\n \n for(let i = 0; i < boysSkills.length; i++){\n for(let j = 0; j < girlsSkills.length; j++){\n let dif = Math.abs(boysSkills[i] - girlsSkills[j]);\n if(dif <= 1){\n count++;\n boysSkills[i] = Infinity;\n girlsSkills[j] = Infinity;\n }\n }\n } \n console.log(count)\n return count;\n}"}], "src_uid": "62766ef9a0751cbe7987020144de7512"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos = []\n let min = 9999999\n let pos = 0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n if (min > arr[i]) {\n min = arr[i]\n pos = i\n }\n }\n if (sum - min !== min && sum - min !== 0) {\n console.log(\"1\")\n console.log(pos + 1)\n return\n }\n\n\n console.log(\"-1\")\n return 0;\n }\n});\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos = []\n let min = 9999999\n let pos = 0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n if (min > arr[i]) {\n min = arr[i]\n pos = i\n }\n }\n if (sum - min !== min && sum - min !== 0) {\n console.log(\"1\")\n console.log(pos + 1)\n return\n }\n\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const packets = is.nextArray().map(Number);\n switch (n) {\n case 1:\n console.log(-1);\n break;\n case 2:\n if (packets[0] === packets[1])\n console.log(-1);\n else {\n console.log(`${1}\\n${1}`);\n }\n break;\n default:\n console.log(1);\n const minElement = Math.min.apply(null, packets);\n console.log(packets.indexOf(minElement) + 1);\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const count = +readline();\nconst arr = readline().split(' ').map(function(v){return +v;});\nconst total = arr.reduce((p, e) => p+e);\nswitch(count) {\n case 1: {\n print(-1);\n break;\n }\n case 2: {\n if (arr[0] === arr[1]) {\n print(-1);\n break;\n }\n }\n default: {\n if (total % 2 != 0 ) {\n print(1);\n print(1);\n break;\n } else {\n const half = total / 2;\n kek = false;\n for(var i=0; i {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos= []\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n arrPos.push([arr[i],i])\n }\n\n arrPos=arrPos.sort(function sortNumber(a, b) {\n return a[0] - b[0];\n })\n let g = 0\n let currSum = 0\n let res= \"\"\n for (let i = 0; i < arrPos.length; i++) {\n g++\n currSum+=arrPos[i][0]\n res+=(arrPos[i][1]+1)+\" \"\n if (sum - arrPos[i][0] !== currSum&&g!== arrPos.length) {\n \n console.log(g)\n console.log(res)\n return\n }\n sum-=arr[i]\n }\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}], "negative_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const packets = is.nextArray();\n if (n < 3)\n console.log(-1);\n else {\n console.log(1);\n console.log(packets[0]);\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const packets = is.nextArray();\n if (n < 3)\n console.log(-1);\n else {\n console.log(n - 1);\n packets.pop();\n console.log(packets.join(' '));\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const packets = is.nextArray().map(Number);\n if (n < 3)\n console.log(-1);\n else {\n console.log(1);\n const minElement = Math.min.apply(null, packets);\n console.log(packets.indexOf(minElement) + 1);\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n const packets = is.nextArray().map(Number);\n switch (n) {\n case 1:\n console.log(-1);\n break;\n case 2:\n if (packets[0] === packets[1])\n console.log(-1);\n else {\n console.log(1);\n console.log(packets[0]);\n }\n break;\n default:\n console.log(1);\n const minElement = Math.min.apply(null, packets);\n console.log(packets.indexOf(minElement) + 1);\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextInt();\n if (n < 3)\n console.log(-1);\n else {\n console.log(`${1}\\n${1}`);\n }\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(10))\n let sum = 0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n }\n let g = 0\n let currSum = 0\n let res= \"\"\n for (let i = 0; i < arr.length; i++) {\n g++\n currSum+=arr[i]\n res+=(i+1)+\" \"\n if (sum - arr[i] !== currSum&&g!== arr.length) {\n \n console.log(g)\n console.log(res)\n return\n }\n sum-=arr[i]\n }\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos= []\n let min=9999999\n let pos=0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n if(min>arr[i]){\n min=arr[i]\n pos=i\n }\n }\n if(sum-min!==min){\n console.log(\"1\")\n console.log(pos+1)\n return\n }\n\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos= []\n let min=9999999\n let pos=0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n if(min>arr[i]){\n min=arr[i]\n pos=i\n }\n }\n if(min-sum!==min){\n console.log(\"1\")\n console.log(pos)\n return\n }\n\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let arr = input.split(\" \").map(x => parseInt(x))\n let sum = 0\n let arrPos= []\n let min=9999999\n let pos=0\n for (let i = 0; i < arr.length; i++) {\n sum += arr[i]\n if(min>arr[i]){\n min=arr[i]\n pos=i\n }\n }\n if(min-sum!==min){\n console.log(\"1\")\n console.log(pos+1)\n return\n }\n\n\n console.log(\"-1\")\n return 0;\n }\n});\n"}], "src_uid": "2b55012c899645bac8d293e85e73148f"} {"source_code": "\nfunction toInt( s ) { return s.charCodeAt(0); }\n\nfunction main()\n{\n var s = readline();\n var t = \"Bulbasaur\";\n \n var a = new Array( 256 ).fill(0);\n var b = new Array( 256 ).fill( 0 );\n \n s.split('').forEach( (v) => a[toInt(v)]++ );\n t.split('').forEach( (v) => b[toInt(v)]++ );\n \n var ans = 1e9 + 5;\n for ( var i=0 ; i<256 ; i++ )\n {\n if ( b[i] > 0 )\n {\n var thiz = ~~( a[i] / b[i] ); // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )\n ans = Math.min( ans , thiz );\n }\n }\n print( ans );\n \n} main();\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "\nfunction toInt( s ) { return s.charCodeAt(0); }\n\nfunction main()\n{\n var s = readline();\n var t = \"Bulbasaur\";\n \n var a = {} , b = {};\n \n s.split('').forEach( (v) => a[v] = a[v] ? a[v]+1 : 1 );\n t.split('').forEach( (v) => b[v] = b[v] ? b[v]+1 : 1 );\n \n var ans = 1e9 + 5;\n for ( var i in b )\n {\n var c1 = a[i] ? a[i] : 0;\n var c2 = b[i];\n var thiz = ~~( c1 / c2 ); // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )\n ans = Math.min( ans , thiz );\n }\n print( ans );\n \n} main();\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "function main() {\n var s1 = readline();\n var lettersCounts = {};\n for(var i=0;i str += c)\nprocess.stdin.on('end', () => {\nlet strArr = str.split('')\nlet obj = {};\nlet obj1 = { B: 1, u: 2, l: 1, b: 1, a: 2, s: 1, r: 1 }\nstrArr.forEach((item, i) => {\n Object.keys(obj1).forEach(key => {\n if(item == key) {\n if(!obj[item])\n obj[item] = (obj[item] || 0) + 1\n else {\n obj[item] += 1\n }\n }\n\n })\n})\n\nlet objLen = Object.keys(obj).length;\nlet obj1Len = Object.keys(obj1).length;\nif(objLen != obj1Len) {\n console.log(0);\n}\nelse {\n let arr = []\n Object.keys(obj).forEach(k => {\n Object.keys(obj1).forEach(k1 => {\n if(k == k1) {\n arr.push(Math.floor(obj[k]/obj1[k1]))\n }\n })\n })\n let res = arr.reduce((prev, curr) => {\n return (prev < curr) ? prev : curr\n })\n console.log(res)\n}\n})"}], "negative_code": [{"source_code": "let str = ''\nprocess.stdin.on('data', c => str += c)\nprocess.stdin.on('end', () => {\n // console.log(i); \n\nlet strArr = str.split('')\n// console.log(strArr)\nlet arr = [];\nlet obj = {};\nlet obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }\nstrArr.forEach((item, i) => {\n Object.keys(obj1).forEach(key => {\n if(item == key) {\n if(!obj[item])\n obj[item] = (obj[item] || 0) + 1\n else {\n obj[item] += 1\n }\n }\n\n })\n})\nlet objLen = Object.keys(obj).length;\nlet obj1Len = Object.keys(obj1).length;\nif(objLen != obj1Len) {\n console.log(0);\n}\nelse {\n let arr = []\n Object.keys(obj).forEach(k => {\n arr.push(obj[k])\n })\n let res = arr.reduce((prev, curr) => {\n return (prev < curr) ? prev : curr\n })\n console.log(res)\n}\n})"}, {"source_code": "let str = ''\nprocess.stdin.on('data', c => str += c)\nprocess.stdin.on('end', () => {\nlet strArr = str.split('')\nlet obj = {};\nlet obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }\nstrArr.forEach((item, i) => {\n Object.keys(obj1).forEach(key => {\n if(item == key) {\n if(!obj[item])\n obj[item] = (obj[item] || 0) + 1\n else {\n obj[item] += 1\n }\n }\n\n })\n})\n\nlet objLen = Object.keys(obj).length;\nlet obj1Len = Object.keys(obj1).length;\nif(objLen != obj1Len) {\n console.log(0);\n}\nelse {\n let arr = []\n Object.keys(obj).forEach(k => {\n Object.keys(obj1).forEach(k1 => {\n if(k == k1) {\n arr.push(Math.floor(obj[k]/obj1[k1]))\n }\n })\n })\n let res = arr.reduce((prev, curr) => {\n return (prev < curr) ? prev : curr\n })\n console.log(res)\n}\n})"}], "src_uid": "9c429fd7598ea75acce09805a15092d0"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const [n, k] = input().split(' ').map(Number);\r\n const a = input().split(' ').map(Number);\r\n // 1\r\n a.sort((a, b) => {\r\n if(a < b) return -1;\r\n else return 1;\r\n });\r\n // 2\r\n let last = a[0];\r\n let cnt = 1;\r\n const aa = [];\r\n for(let i = 1; i < n; i++){\r\n if(last !== a[i]){\r\n if(cnt >= k) aa.push(last);\r\n cnt = 1;\r\n last = a[i];\r\n }\r\n else{\r\n cnt++;\r\n }\r\n }\r\n if(cnt >= k) aa.push(last);\r\n if(!aa.length){\r\n console.log(-1);\r\n continue;\r\n }\r\n // 3\r\n const aaa = [];\r\n last = aa[0];\r\n let tmp = [aa[0]];\r\n for(let i = 1; i < aa.length; i++){\r\n if(aa[i]-1 === last){\r\n tmp.push(aa[i]);\r\n }\r\n else{\r\n aaa.push(JSON.parse(JSON.stringify(tmp)));\r\n tmp = [aa[i]];\r\n }\r\n last = aa[i];\r\n }\r\n if(tmp.length) aaa.push(tmp);\r\n // 4\r\n const aaaa = [];\r\n for(let i = 0; i < aaa.length; i++){\r\n let s = aaa[i].length;\r\n let l = aaa[i][0];\r\n let r = aaa[i][s-1];\r\n aaaa.push([r-l, l, r]);\r\n }\r\n aaaa.sort((a, b) => {\r\n if(a[0] > b[0]) return -1;\r\n else return 1;\r\n });\r\n console.log(aaaa[0][1], aaaa[0][2]);\r\n }\r\n}", "positive_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, k] = ra();\n let A = ra();\n LT({n, k, A});\n // PROCESSING:\n A.sort((a, b)=>a-b);\n let cnt = {};\n for (let i=0; i+u);\n let max = -1;\n let ansL, ansR;\n let l=0, r = 0;\n while (l=k && (r==l || uniq[r]-1==uniq[r-1])){\n r++;\n }\n if (r>l && uniq[r-1]-uniq[l]>max){\n max = uniq[r-1]-uniq[l];\n ansL = uniq[l];\n ansR = uniq[r-1];\n }\n if (l==r)\n l = r+1;\n else\n l = r;\n }\n if (max==-1)\n return -1;\n return [ansL, ansR]\n};\n "}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n let nums = [];\r\n for (let [num, count] of map) {\r\n if (count >= k) nums.push(num);\r\n }\r\n nums.sort((a, b) => a - b);\r\n let l = 0,\r\n r = -1;\r\n for (let i = 0; i < nums.length;) {\r\n let j = i;\r\n while (nums[j + 1] === nums[j] + 1) {\r\n j++;\r\n }\r\n if (nums[j] - nums[i] > r - l) {\r\n l = nums[i];\r\n r = nums[j];\r\n }\r\n i = j + 1;\r\n }\r\n if (r === -1) return -1;\r\n return `${l} ${r}`;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar key = Object.keys(map);\r\n\t\tkey.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < key.length; i++){\r\n\t\t\tif(map[key[i]] >= K){\r\n\t\t\t\tok = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(!ok){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = \"\";\r\n\t\tvar size = -1;\r\n\t\tvar L = 0;\r\n\t\tvar R = 0;\r\n\t\tvar lastNo = myconv(key[0], 1);\r\n\t\twhile(L < key.length && R < key.length){\r\n\t\t\tvar ok = true;\r\n\t\t\tif(L != R){\r\n\t\t\t\tif(lastNo + 1 != key[R]){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(map[key[R]] != null && map[key[R]] >= K && ok){\r\n\t\t\t\tlastNo = myconv(key[R], 1);\r\n\t\t\t\tR++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}else{\r\n\t\t\t\t\r\n\t\t\t\tif(R - L + 1 > size){\r\n\t\t\t\t\tsize = R - L + 1;\r\n\t\t\t\t\toutput = key[L] + \" \" + key[R - 1];\r\n\t\t\t\t}\r\n\t\t\t\tif(L == R){\r\n\t\t\t\t\tR++;\r\n\t\t\t\t}\r\n\t\t\t\tL = R;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(R - L + 1 > size){\r\n\t\t\tsize = R - L + 1;\r\n\t\t\toutput = key[L] + \" \" + key[R - 1];\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const map = arr.reduce((o, x) => {\n o[x] = (o[x] || 0) + 1\n return o\n }, {})\n let max = -1\n let p, c\n let l, r\n Object.keys(map)\n .map(Number)\n .sort((a, b) => a - b)\n .forEach(x => {\n if (map[x] >= k) {\n if (p + 1 === x) {\n c++\n } else {\n c = 1\n }\n p = x\n if (c > max) {\n max = c\n l = x - max + 1\n r = x\n }\n } else {\n p = -1\n }\n })\n return max < 0 ? -1 : l + ' ' + r\n}\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n a.sort(function (a, b) { return a - b; });\r\n var m = new Map();\r\n for (var i = 0; i < n; i++) {\r\n if (m.has(a[i])) {\r\n m.set(a[i], m.get(a[i]) + 1);\r\n }\r\n else {\r\n m.set(a[i], 1);\r\n }\r\n }\r\n var b = (Array.from(m.entries()));\r\n n = b.length;\r\n var maxL = 0, maxR = 0;\r\n var max = 0;\r\n var l = 0;\r\n var r = 0;\r\n var prev = b[0][0] - 1;\r\n while (l < n) {\r\n while (b[r][1] >= k && b[r][0] === prev + 1) {\r\n prev = b[r][0];\r\n r++;\r\n if (r === n)\r\n break;\r\n }\r\n if (r - l > max) {\r\n maxR = b[r - 1][0];\r\n maxL = b[l][0];\r\n max = r - l;\r\n }\r\n if (r === n)\r\n break;\r\n l = b[r][1] >= k ? r : r + 1;\r\n r = l;\r\n if (r === n)\r\n break;\r\n prev = b[r][0] - 1;\r\n }\r\n print(max ? \"\".concat(maxL, \" \").concat(maxR) : -1);\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const n = nextInt();\r\n const k = nextInt();\r\n const arr = nextIntArray(n);\r\n\r\n const map = new Map();\r\n let min = Infinity;\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (map.get(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1)\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n min = Math.min(min, arr[i]);\r\n max = Math.max(max, arr[i])\r\n }\r\n\r\n // console.log({min, max, map, k})\r\n let left = min, right = min;\r\n const ans = [0, 0];\r\n const keys = [...map.keys()].sort((a, b) => a - b);\r\n // console.log(keys)\r\n let index = 0;\r\n while (right <= max + 1) {\r\n // console.log({left, right}, keys[index], keys)\r\n if (map.get(right) >= k){\r\n // console.log(\"expand\");\r\n index++;\r\n right++;\r\n } else {\r\n // console.log(\"sink\")\r\n // console.log(left, right)\r\n let maxRange = ans[1] - ans[0] + 1;\r\n if (maxRange <= right -1 - left + 1) {\r\n ans[0] = left;\r\n ans[1] = right - 1;\r\n }\r\n if (map.get(keys[index]) >= k) {\r\n left = keys[index];\r\n } else {\r\n left = keys[++index];\r\n }\r\n right = left;\r\n // console.log(ans)\r\n }\r\n }\r\n\r\n // console.log(ans)\r\n\r\n if (ans[0] === 0 && ans[1] === 0) {\r\n myout(-1);\r\n } else {\r\n myout(`${ans[0]} ${ans[1]}`);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = iInpArr();\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n else obj[arr[i]]++;\r\n }\r\n let keys = Object.keys(obj);\r\n let res = [];\r\n for (let i of keys) {\r\n if (obj[i] >= k) res.push(parseInt(i));\r\n }\r\n if (res.length === 0) console.log(-1);\r\n else if (res.length === 1) console.log(res[0] + \" \" + res[0]);\r\n else {\r\n res.sort((a, b) => a - b);\r\n let j = 1,\r\n i = 0,\r\n max = 0,\r\n ans;\r\n while (j < res.length) {\r\n let y = res[j] - res[i] + 1;\r\n if (y === j - i + 1) {\r\n if (max <= res[j] - res[i]) {\r\n max = res[j] - res[i];\r\n ans = [res[i], res[j]];\r\n }\r\n j++;\r\n } else i++;\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet k;\r\nlet a;\r\nfunction solve() {\r\n let b = [];\r\n a.sort((x, y) => x - y);\r\n let last = a[0];\r\n let cnt = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] == last) {\r\n cnt++;\r\n }\r\n else {\r\n if (cnt >= k) {\r\n b.push(last);\r\n }\r\n cnt = 1;\r\n last = a[i];\r\n }\r\n }\r\n if (cnt >= k) {\r\n b.push(last);\r\n }\r\n let m = b.length;\r\n if (m == 0) {\r\n return false;\r\n }\r\n let l = 0;\r\n let best = 1;\r\n let lo = b[0];\r\n let hi = b[0];\r\n while (l < m) {\r\n let r = l + 1;\r\n while (r < m && r - l == b[r] - b[l]) {\r\n if (best < r - l + 1) {\r\n best = r - l + 1;\r\n lo = b[l];\r\n hi = b[r];\r\n }\r\n r++;\r\n }\r\n l = r;\r\n }\r\n printf(\"%d %d\\n\", lo, hi);\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const n = nextInt();\r\n const k = nextInt();\r\n const arr = nextIntArray(n);\r\n\r\n const map = new Map();\r\n let min = Infinity;\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (map.get(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1)\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n min = Math.min(min, arr[i]);\r\n max = Math.max(max, arr[i])\r\n }\r\n\r\n // console.log({min, max, map, k})\r\n let left = min, right = min;\r\n const ans = [0, 0];\r\n const keys = [...map.keys()].sort((a, b) => a - b);\r\n // console.log(keys)\r\n let index = 0;\r\n while (right <= max + 1) {\r\n if (map.get(right) >= k){\r\n // console.log(\"expand\");\r\n index++;\r\n right++;\r\n } else {\r\n // console.log(\"sink\")\r\n // console.log(left, right)\r\n let maxRange = ans[1] - ans[0] + 1;\r\n if (maxRange <= right -1 - left + 1) {\r\n ans[0] = left;\r\n ans[1] = right - 1;\r\n }\r\n left = keys[++index];\r\n right = left;\r\n // console.log(ans)\r\n }\r\n }\r\n\r\n // console.log(ans)\r\n\r\n if (ans[0] === 0 && ans[1] === 0) {\r\n myout(-1);\r\n } else {\r\n myout(`${ans[0]} ${ans[1]}`);\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const n = nextInt();\r\n const k = nextInt();\r\n const arr = nextIntArray(n);\r\n\r\n const map = new Map();\r\n let min = Infinity;\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (map.get(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1)\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n min = Math.min(min, arr[i]);\r\n max = Math.max(max, arr[i])\r\n }\r\n\r\n // console.log({min, max, map, k})\r\n let left = min, right = min;\r\n const ans = [0, 0];\r\n const keys = [...map.keys()].sort((a, b) => a - b);\r\n // console.log(keys)\r\n let index = 0;\r\n while (right <= max + 1) {\r\n if (map.get(right) >= k){\r\n // console.log(\"expand\");\r\n index++;\r\n right++;\r\n } else {\r\n // console.log(\"sink\")\r\n // console.log(left, right)\r\n let maxRange = ans[1] - ans[0] + 1;\r\n if (maxRange <= right -1 - left + 1) {\r\n ans[0] = left;\r\n ans[1] = right - 1;\r\n }\r\n left = keys[index++];\r\n right = left;\r\n // console.log(ans)\r\n }\r\n }\r\n\r\n // console.log(ans)\r\n\r\n if (ans[0] === 0 && ans[1] === 0) {\r\n myout(-1);\r\n } else {\r\n myout(`${ans[0]} ${ans[1]}`);\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const n = nextInt();\r\n const k = nextInt();\r\n const arr = nextIntArray(n);\r\n\r\n const map = new Map();\r\n let min = Infinity;\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (map.get(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1)\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n min = Math.min(min, arr[i]);\r\n max = Math.max(max, arr[i])\r\n }\r\n\r\n // console.log({min, max, map, k})\r\n let left = min, right = min;\r\n const ans = [0, 0];\r\n const keys = [...map.keys()].sort((a, b) => b - a);\r\n let pointer = 0;\r\n while (right <= max + 1) {\r\n if (map.get(right) >= k){\r\n // console.log(\"expand\");\r\n pointer++;\r\n right++;\r\n } else {\r\n // console.log(\"sink\")\r\n // console.log(left, right)\r\n let maxRange = ans[1] - ans[0] + 1;\r\n if (maxRange <= right -1 - left + 1) {\r\n ans[0] = left;\r\n ans[1] = right - 1;\r\n }\r\n left = keys[pointer++];\r\n right = left;\r\n // console.log(ans)\r\n }\r\n }\r\n\r\n // console.log(ans)\r\n\r\n if (ans[0] === 0 && ans[1] === 0) {\r\n myout(-1);\r\n } else {\r\n myout(`${ans[0]} ${ans[1]}`);\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n const n = nextInt();\r\n const k = nextInt();\r\n const arr = nextIntArray(n);\r\n\r\n const map = new Map();\r\n let min = Infinity;\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length; i++) {\r\n if (map.get(arr[i])) {\r\n map.set(arr[i], map.get(arr[i]) + 1)\r\n } else {\r\n map.set(arr[i], 1);\r\n }\r\n min = Math.min(min, arr[i]);\r\n max = Math.max(max, arr[i])\r\n }\r\n\r\n // console.log({min, max, map, k})\r\n let left = min, right = min;\r\n const ans = [0, 0];\r\n\r\n while (right <= max + 1) {\r\n if (map.get(right) >= k){\r\n // console.log(\"expand\")\r\n right++;\r\n } else {\r\n // console.log(\"sink\")\r\n // console.log(left, right)\r\n let maxRange = ans[1] - ans[0] + 1;\r\n if (maxRange < right - left) {\r\n ans[0] = left;\r\n ans[1] = right - 1;\r\n }\r\n left = right + 1;\r\n right++;\r\n }\r\n }\r\n\r\n // console.log(ans)\r\n\r\n if (ans[0] === 0 && ans[1] === 0) {\r\n myout(-1);\r\n } else {\r\n myout(`${ans[0]} ${ans[1]}`);\r\n }\r\n}"}, {"source_code": "const solve = (arr, n, k) => {\r\n let obj = {},narr = [];\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) {\r\n obj[arr[i]] = 1;\r\n narr.push(arr[i]);\r\n }\r\n else obj[arr[i]]++;\r\n }\r\n let max = -Infinity,l,r;\r\n for(let i=0;i=k)&&(obj[narr[j]]>=k)){\r\n if(max parseInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n console.log(solve(arr,n,k));\r\n }\r\n}\r\nmain();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const [n, k] = input().split(' ').map(Number);\r\n const a = input().split(' ').map(Number);\r\n // 1\r\n a.sort((a, b) => {\r\n if(a < b) return -1;\r\n else return 1;\r\n });\r\n // 2\r\n let last = a[0];\r\n let cnt = 1;\r\n const aa = [];\r\n for(let i = 1; i < n; i++){\r\n if(last !== a[i]){\r\n if(cnt >= k) aa.push(last);\r\n cnt = 1;\r\n last = a[i];\r\n }\r\n else{\r\n cnt++;\r\n }\r\n }\r\n if(cnt >= k) aa.push(last);\r\n if(!aa.length){\r\n continue;\r\n }\r\n // 3\r\n const aaa = [];\r\n last = aa[0];\r\n let tmp = [aa[0]];\r\n for(let i = 1; i < aa.length; i++){\r\n if(aa[i]-1 === last){\r\n tmp.push(aa[i]);\r\n }\r\n else{\r\n aaa.push(JSON.parse(JSON.stringify(tmp)));\r\n tmp = [aa[i]];\r\n }\r\n last = aa[i];\r\n }\r\n if(tmp.length) aaa.push(tmp);\r\n // 4\r\n const aaaa = [];\r\n for(let i = 0; i < aaa.length; i++){\r\n let s = aaa[i].length;\r\n let l = aaa[i][0];\r\n let r = aaa[i][s-1];\r\n aaaa.push([r-l, l, r]);\r\n }\r\n aaaa.sort((a, b) => {\r\n if(a[0] > b[0]) return -1;\r\n else return 1;\r\n });\r\n console.log(aaaa[0][1], aaaa[0][2]);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction input() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let tc = parseInt(input());\r\n while(tc--){\r\n const [n, k] = input().split(' ').map(Number);\r\n const a = input().split(' ').map(Number);\r\n // 1\r\n a.sort();\r\n // 2\r\n let last = a[0];\r\n let cnt = 1;\r\n const aa = [];\r\n for(let i = 1; i < n; i++){\r\n if(last !== a[i]){\r\n if(cnt >= k) aa.push(last);\r\n cnt = 1;\r\n last = a[i];\r\n }\r\n else{\r\n cnt++;\r\n }\r\n }\r\n if(cnt >= k) aa.push(last);\r\n if(!aa.length){\r\n console.log(-1);\r\n continue;\r\n }\r\n // 3\r\n const aaa = [];\r\n last = aa[0];\r\n let tmp = [aa[0]];\r\n for(let i = 1; i < aa.length; i++){\r\n if(aa[i]-1 === last){\r\n tmp.push(aa[i]);\r\n }\r\n else{\r\n aaa.push(JSON.parse(JSON.stringify(tmp)));\r\n tmp = [aa[i]];\r\n }\r\n last = aa[i];\r\n }\r\n if(tmp.length) aaa.push(tmp);\r\n // 4\r\n let aaaa = [];\r\n for(let i = 0; i < aaa.length; i++){\r\n let s = aaa[i].length;\r\n let l = aaa[i][0];\r\n let r = aaa[i][s-1];\r\n aaaa.push([r-l, l, r]);\r\n }\r\n aaaa.sort((a, b) => {\r\n if(a[0] > b[0]) return -1;\r\n else return 1;\r\n });\r\n console.log(aaaa[0][1], aaaa[0][2]);\r\n }\r\n}"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet k;\r\nlet a;\r\nfunction solve() {\r\n let b = [];\r\n a.sort((x, y) => x - y);\r\n let last = a[0];\r\n let cnt = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] == last) {\r\n cnt++;\r\n }\r\n else {\r\n if (cnt >= k) {\r\n b.push(last);\r\n }\r\n cnt = 1;\r\n last = a[i];\r\n }\r\n }\r\n if (cnt >= k) {\r\n b.push(last);\r\n }\r\n let m = b.length;\r\n if (m == 0) {\r\n return false;\r\n }\r\n let l = 0;\r\n let best = 0;\r\n let lo = INF;\r\n let hi = INF;\r\n while (l < m) {\r\n let r = l + 1;\r\n while (r < m && r - l == b[r] - b[l]) {\r\n if (best < r - l) {\r\n best = r - l;\r\n lo = b[l];\r\n hi = b[r];\r\n }\r\n r++;\r\n }\r\n l = r;\r\n }\r\n printf(\"%d %d\\n\", lo, hi);\r\n return true;\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n k = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (!solve()) {\r\n printf(\"%d\\n\", INIT);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n, k] = ra();\n let A = ra();\n LT({n, k, A});\n // PROCESSING:\n A.sort((a, b)=>a-b);\n let cnt = {};\n for (let i=0; i+u);\n let max = -1;\n let ansL, ansR;\n let l=0, r = 0;\n while (l=k && (r==l || uniq[r]-1==uniq[r-1])){\n r++;\n }\n if (r>l && uniq[r-1]-uniq[l]>max){\n max = uniq[r-1]-uniq[l];\n ansL = uniq[l];\n ansR = uniq[r-1];\n }\n l = r + 1;\n }\n if (max==-1)\n return -1;\n return [ansL, ansR]\n};\n "}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nwhile (t--) {\r\n var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];\r\n var a = readline().split(' ').map(function (v) { return +v; });\r\n a.sort();\r\n var m = new Map();\r\n for (var i = 0; i < n; i++) {\r\n if (m.has(a[i])) {\r\n m.set(a[i], m.get(a[i]) + 1);\r\n }\r\n else {\r\n m.set(a[i], 1);\r\n }\r\n }\r\n var b = (Array.from(m.entries()));\r\n n = b.length;\r\n var maxL = 0, maxR = 0;\r\n var max = 0;\r\n var l = 0;\r\n var r = 0;\r\n var prev = b[0][0] - 1;\r\n while (l < n) {\r\n while (b[r][1] >= k && b[r][0] === prev + 1) {\r\n prev = b[r][0];\r\n r++;\r\n if (r === n)\r\n break;\r\n }\r\n if (r - l > max) {\r\n maxR = b[r - 1][0];\r\n maxL = b[l][0];\r\n max = r - l;\r\n }\r\n if (r === n)\r\n break;\r\n l = b[r][1] >= k ? r : r + 1;\r\n r = l;\r\n if (r === n)\r\n break;\r\n prev = b[r][0] - 1;\r\n }\r\n print(max ? \"\".concat(maxL, \" \").concat(maxR) : -1);\r\n}\r\n"}], "src_uid": "13fd45f1892f96eab1d5ab966f465a05"} {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n\r\nvar line = readline().split(' ').map(getInt);\r\n\r\ngetXY.apply(undefined, line)\r\n\r\nfunction getXY(zerous, ones, k){\r\n\r\n if(k === 0){\r\n print('YES');\r\n var rest = getRest(zerous, ones).join('');\r\n\r\n print(rest);\r\n print(rest);\r\n return;\r\n }\r\n if(zerous === 0 || ones === 0){\r\n print('NO')\r\n return;\r\n }\r\n \r\n if(zerous + ones - 2 < k){\r\n print('NO')\r\n return;\r\n }\r\n\r\n if(ones === 1){\r\n print('NO')\r\n return;\r\n }\r\n \r\n getPatt(zerous, ones, k)\r\n \r\n}\r\n\r\nfunction addChars(arr, ch, n){\r\n for(var i = 0; i < n; i++){\r\n arr.push(ch);\r\n }\r\n}\r\n\r\nfunction getEndPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n var zs = Math.min(k, zerous);\r\n \r\n //pattX.push(1);\r\n addChars(pattX, 0, zs)\r\n \r\n addChars(pattY, 0, zs-1)\r\n pattY.push(1);\r\n \r\n //o--;\r\n z = z - zs;\r\n newK = newK - zs;\r\n return [pattX, pattY, z, o, newK]\r\n}\r\nfunction getPatt(zerous, ones, k){\r\n \r\n var x = [1];\r\n var y = [1];\r\n ones--;\r\n\r\n var pattEnd = getEndPatt(zerous, ones, k);\r\n\r\n zerous = pattEnd[2];\r\n ones = pattEnd[3];\r\n k = pattEnd[4];\r\n \r\n var pattSt = getStartPatt(zerous, ones, k);\r\n \r\n zerous = pattSt[2];\r\n ones = pattSt[3];\r\n k = pattSt[4];\r\n \r\n var rest = getRest(zerous, ones);\r\n \r\n x = x.concat(pattSt[0]);\r\n y = y.concat(pattSt[1]);\r\n x = x.concat(pattEnd[0]);\r\n y = y.concat(pattEnd[1]);\r\n x = x.concat(rest);\r\n y = y.concat(rest);\r\n \r\n print('YES');\r\n \r\n print(x.join(''))\r\n \r\n print(y.join(''))\r\n \r\n}\r\nfunction getStartPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n \r\n \r\n pattX.push(1);\r\n pattY.push(0);\r\n o--;\r\n \r\n var os = Math.min(k, o);\r\n \r\n addChars(pattX, 1, os);\r\n addChars(pattY, 1, os);\r\n \r\n o = o - os;\r\n \r\n newK = k - os;\r\n \r\n return [pattX, pattY, z, o, newK]\r\n}\r\n\r\nfunction getRest(zerous, ones){\r\n var rest = [];\r\n addChars(rest, 1, ones)\r\n addChars(rest, 0, zerous)\r\n return rest;\r\n}\r\n", "positive_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var [a, b, k] = lines[0].trim().split(' ').map(Number)\n console.log(solve(a, b, k));\n});\n\nfunction solve(a, b, k) {\n if (k === 0) {\n const s = Array(b).fill(1).join('') + Array(a).fill(0).join('')\n return ['Yes', s, s].join('\\n') \n }\n if (a < 1 || b < 2 || a + b < k + 2) return 'No'\n\n // 1, ?, i, k - 1, j\n const x = []\n const y = []\n const j = a + b - 1\n const i = j - k\n let zero = a - 1 // reserved for i and j\n let one = b - 1\n for (let p = 0; p < a + b; p++) {\n if (!p) {\n x[p] = y[p] = 1\n one--\n } else if (p === i) {\n x[p] = 1\n y[p] = 0\n } else if (p === j) {\n x[p] = 0\n y[p] = 1\n } else {\n if (zero) {\n x[p] = y[p] = 0\n zero--\n } else {\n x[p] = y[p] = 1\n one--\n }\n }\n }\n return ['Yes', x.join(''), y.join('')].join('\\n')\n}\n"}], "negative_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var [a, b, k] = lines[0].trim().split(' ').map(Number)\n console.log(solve(a, b, k));\n});\n\nfunction solve(a, b, k) {\n if (a < 1 || b < 2 || a + b < k + 2) return 'No'\n\n // 1, ?, i, k - 1, j\n const x = []\n const y = []\n const j = a + b - 1\n const i = j - k\n let zero = a - 1 // reserved for i and j\n let one = b - 1\n for (let p = 0; p < a + b; p++) {\n if (!p) {\n x[p] = y[p] = 1\n one--\n } else if (p === i) {\n x[p] = 1\n y[p] = 0\n } else if (p === j) {\n x[p] = 0\n y[p] = 1\n } else {\n if (zero) {\n x[p] = y[p] = 0\n zero--\n } else {\n x[p] = y[p] = 1\n one--\n }\n }\n }\n return ['Yes', x.join(''), y.join('')].join('\\n')\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var [a, b, k] = lines[0].trim().split(' ').map(Number)\n console.log(solve(a, b, k));\n});\n\nfunction solve(a, b, k) {\n if (a < 1 || b < 2 || a + b < k + 2) return 'No'\n\n // 1, ?, i, k - 1, j\n const x = []\n const y = []\n const j = a + b - 1\n const i = j - k\n let zero = a - 1 // reserved for i and j\n let one = b - 1\n for (let p = 0; p < a + b; p++) {\n if (!p) {\n x[p] = y[p] = 1\n zero--\n one--\n } else if (p === i) {\n x[p] = 1\n y[p] = 0\n } else if (p === j) {\n x[p] = 0\n y[p] = 1\n } else {\n if (zero) {\n x[p] = y[p] = 0\n zero--\n } else {\n x[p] = y[p] = 1\n one--\n }\n }\n }\n return ['Yes', x.join(''), y.join('')].join('\\n')\n}\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n\r\nvar line = readline().split(' ').map(getInt);\r\n\r\ngetXY.apply(undefined, line)\r\n\r\nfunction getXY(zerous, ones, k){\r\n\r\n if(k === 0){\r\n print('YES');\r\n var rest = getRest(zerous, ones).join('');\r\n\r\n print(rest);\r\n print(rest);\r\n return;\r\n }\r\n \r\n if(zerous + ones - 2 < k){\r\n print('NO')\r\n return;\r\n }\r\n\r\n if(ones === 1){\r\n print('NO')\r\n return;\r\n }\r\n \r\n getPatt(zerous, ones, k)\r\n \r\n}\r\n\r\nfunction addChars(arr, ch, n){\r\n for(var i = 0; i < n; i++){\r\n arr.push(ch);\r\n }\r\n}\r\n\r\nfunction getEndPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n var zs = Math.min(k, zerous);\r\n \r\n //pattX.push(1);\r\n addChars(pattX, 0, zs)\r\n \r\n addChars(pattY, 0, zs-1)\r\n pattY.push(1);\r\n \r\n //o--;\r\n z = z - zs;\r\n newK = newK - zs;\r\n return [pattX, pattY, z, o, newK]\r\n}\r\nfunction getPatt(zerous, ones, k){\r\n \r\n var x = [1];\r\n var y = [1];\r\n ones--;\r\n\r\n var pattEnd = getEndPatt(zerous, ones, k);\r\n\r\n zerous = pattEnd[2];\r\n ones = pattEnd[3];\r\n k = pattEnd[4];\r\n \r\n var pattSt = getStartPatt(zerous, ones, k);\r\n \r\n zerous = pattSt[2];\r\n ones = pattSt[3];\r\n k = pattSt[4];\r\n \r\n var rest = getRest(zerous, ones);\r\n \r\n x = x.concat(pattSt[0]);\r\n y = y.concat(pattSt[1]);\r\n x = x.concat(pattEnd[0]);\r\n y = y.concat(pattEnd[1]);\r\n x = x.concat(rest);\r\n y = y.concat(rest);\r\n \r\n print('YES');\r\n \r\n print(x.join(''))\r\n \r\n print(y.join(''))\r\n \r\n}\r\nfunction getStartPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n \r\n \r\n pattX.push(1);\r\n pattY.push(0);\r\n o--;\r\n \r\n var os = Math.min(k, o);\r\n \r\n addChars(pattX, 1, os);\r\n addChars(pattY, 1, os);\r\n \r\n o = o - os;\r\n \r\n newK = k - os;\r\n \r\n return [pattX, pattY, z, o, newK]\r\n}\r\n\r\nfunction getRest(zerous, ones){\r\n var rest = [];\r\n addChars(rest, 1, ones)\r\n addChars(rest, 0, zerous)\r\n return rest;\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n\r\nvar line = readline().split(' ').map(getInt);\r\n\r\ngetXY.apply(undefined, line)\r\n\r\nfunction getXY(zerous, ones, k){\r\n\r\n if(k === 0){\r\n print('YES');\r\n var rest = getRest(zerous, ones).join('');\r\n\r\n print(rest);\r\n print(rest);\r\n return;\r\n }\r\n \r\n if(zerous + ones - 2 < k){\r\n print('NO')\r\n return;\r\n }\r\n\r\n if(ones === 1){\r\n print('NO')\r\n return;\r\n }\r\n \r\n getPatt(zerous, ones, k)\r\n \r\n}\r\n\r\nfunction addChars(arr, ch, n){\r\n for(var i = 0; i < n; i++){\r\n arr.push(ch);\r\n }\r\n}\r\n\r\nfunction getEndPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n var zs = Math.min(k, zerous);\r\n \r\n addChars(pattX, 0, zs)\r\n \r\n addChars(pattY, 0, zs-1)\r\n pattY.push(1);\r\n \r\n o--;\r\n z = z - zs;\r\n newK = newK - zs;\r\n return [pattX, pattY, z, o, newK]\r\n}\r\nfunction getPatt(zerous, ones, k){\r\n \r\n var x = [1];\r\n var y = [1];\r\n ones--;\r\n var pattSt = getStartPatt(zerous, ones, k);\r\n x = x.concat(pattSt[0]);\r\n y = y.concat(pattSt[1]);\r\n \r\n zerous = pattSt[2];\r\n ones = pattSt[3];\r\n k = pattSt[4];\r\n \r\n var pattEnd = getEndPatt(zerous, ones, k);\r\n x = x.concat(pattEnd[0]);\r\n y = y.concat(pattEnd[1]);\r\n \r\n zerous = pattEnd[2];\r\n ones = pattEnd[3];\r\n k = pattEnd[4];\r\n \r\n var rest = getRest(zerous, ones);\r\n x = x.concat(rest);\r\n y = y.concat(rest);\r\n \r\n print('YES');\r\n \r\n print(x.join(''))\r\n \r\n print(y.join(''))\r\n \r\n}\r\nfunction getStartPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n \r\n \r\n pattX.push(1);\r\n pattY.push(0);\r\n o--;\r\n \r\n var os = Math.min(k, o);\r\n \r\n addChars(pattX, 1, os);\r\n addChars(pattY, 1, os);\r\n \r\n o = o - os;\r\n \r\n newK = k - os;\r\n \r\n return [pattX, pattY, z, o, newK]\r\n}\r\n\r\nfunction getRest(zerous, ones){\r\n var rest = [];\r\n addChars(rest, 1, ones)\r\n addChars(rest, 0, zerous)\r\n return rest;\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n\r\nvar line = readline().split(' ').map(getInt);\r\n\r\ngetXY.apply(undefined, line)\r\n\r\nfunction getXY(zerous, ones, k){\r\n\r\n if(k === 0){\r\n print('YES');\r\n var rest = getRest(zerous, ones).join('');\r\n\r\n print(rest);\r\n print(rest);\r\n return;\r\n }\r\n \r\n if(zerous + ones - 2 < k){\r\n print('NO')\r\n return;\r\n }\r\n\r\n if(ones === 1){\r\n print('NO')\r\n return;\r\n }\r\n \r\n getPatt(zerous, ones, k)\r\n \r\n}\r\n\r\nfunction addChars(arr, ch, n){\r\n for(var i = 0; i < n; i++){\r\n arr.push(ch);\r\n }\r\n}\r\n\r\nfunction getEndPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n var zs = Math.min(k, zerous);\r\n\r\n addChars(pattX, 0, zs)\r\n \r\n addChars(pattY, 0, zs-1)\r\n pattY.push(1);\r\n \r\n o--;\r\n z = z - zs;\r\n newK = newK - zs;\r\n return [pattX, pattY, z, o, newK]\r\n}\r\nfunction getPatt(zerous, ones, k){\r\n \r\n var x = [1];\r\n var y = [1];\r\n ones--;\r\n var pattSt = getStartPatt(zerous, ones, k);\r\n x = x.concat(pattSt[0]);\r\n y = y.concat(pattSt[1]);\r\n \r\n zerous = pattSt[2];\r\n ones = pattSt[3];\r\n k = pattSt[4];\r\n \r\n var pattEnd = getEndPatt(zerous, ones, k);\r\n x = x.concat(pattEnd[0]);\r\n y = y.concat(pattEnd[1]);\r\n \r\n zerous = pattEnd[2];\r\n ones = pattEnd[3];\r\n k = pattEnd[4];\r\n \r\n var rest = getRest(zerous, ones);\r\n x = x.concat(rest);\r\n y = y.concat(rest);\r\n \r\n print('YES');\r\n \r\n print(x.join(''))\r\n \r\n print(y.join(''))\r\n \r\n}\r\nfunction getStartPatt(zerous, ones, k){\r\n var pattX = [];\r\n var pattY = [];\r\n var z = zerous;\r\n var o = ones;\r\n var newK = k;\r\n \r\n \r\n \r\n pattX.push(1);\r\n pattY.push(0);\r\n o--;\r\n \r\n var os = Math.min(k, o);\r\n \r\n addChars(pattX, 1, os);\r\n addChars(pattY, 1, os);\r\n \r\n o = o - os;\r\n \r\n newK = k - os;\r\n \r\n return [pattX, pattY, z, o, newK]\r\n}\r\n\r\nfunction getRest(zerous, ones){\r\n var rest = [];\r\n addChars(rest, 0, zerous)\r\n addChars(rest, 1, ones)\r\n return rest;\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n\r\nvar line = readline().split(' ').map(getInt);\r\n\r\ngetXY.apply(undefined, line)\r\n\r\nfunction getXY(zerous, ones, k){\r\n var x;\r\n var y;\r\n if(zerous < k){\r\n print('NO')\r\n return;\r\n }\r\n if(k === 0){\r\n print('YES');\r\n x = [];\r\n addChars(x, 1, ones)\r\n addChars(x, 0, zerous)\r\n\r\n print(x.join(''));\r\n print(x.join(''));\r\n return;\r\n }\r\n \r\n if(ones === 1){\r\n print('NO')\r\n return;\r\n }\r\n var zCount = 0;\r\n var oCount = 1;\r\n \r\n x = [1];\r\n y = [1];\r\n x.push(1);\r\n addChars(x, 0, k)\r\n \r\n addChars(y, 0, k)\r\n y.push(1);\r\n \r\n zCount+=k;\r\n oCount+=1;\r\n \r\n if(zCount > zerous || oCount > ones){\r\n print('NO')\r\n return;\r\n }\r\n \r\n addChars(x, 1, ones - oCount)\r\n addChars(x, 0, zerous - zCount)\r\n \r\n addChars(y, 1, ones - oCount)\r\n addChars(y, 0, zerous - zCount)\r\n \r\n print('YES');\r\n print(x.join(''));\r\n print(y.join(''));\r\n \r\n}\r\n\r\nfunction addChars(arr, ch, n){\r\n for(var i = 0; i < n; i++){\r\n arr.push(ch);\r\n }\r\n}\r\n"}], "src_uid": "ea620a8dbef506567464dcaddcc2b34f"} {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var n = 9\n while (n--) {\n var input1 = readline()\n print(input1.replace(\"1\", \"2\"))\n }\n }\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nfunction setCharAt(str,index,chr) {\n if(index > str.length-1) return str;\n return str.substr(0,index) + chr + str.substr(index+1);\n}\n\nvar ch = 'a';\nvar acode = ch.charCodeAt(0);\n\n\nfor (var tt = 0; tt < t; tt++) {\n var a = [];\n for (var i = 0; i < 9; i++) {\n a.push(readline());\n }\n \n a[0] = setCharAt(a[0], 0, a[0][1]);\n a[3] = setCharAt(a[3], 1, a[3][2]);\n a[6] = setCharAt(a[6], 2, a[6][3]);\n \n a[1] = setCharAt(a[1], 3, a[1][4]);\n a[4] = setCharAt(a[4], 4, a[4][5]);\n a[7] = setCharAt(a[7], 5, a[7][6]);\n \n a[2] = setCharAt(a[2], 6, a[2][7]);\n a[5] = setCharAt(a[5], 7, a[5][8]);\n a[8] = setCharAt(a[8], 8, a[8][0]);\n \n for (var i = 0; i < 9; i++) {\n write(a[i]+'\\n');\n }\n // write(res+'\\n');\n}\n"}, {"source_code": "\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n print(readline().replace('1','2'));\n }\n}\n\n"}, {"source_code": "var t = readline();\n\nwhile (t--) {\n var sud = new Array(9);\n\n for (var i = 0; i < 9; i++) {\n sud[i] = readline().split('').map(function (val) {\n return parseInt(val);\n });\n }\n\n var j = 0;\n\n for (var _i = 0; _i < 9; _i++) {\n sud[_i][j] = sud[_i][j] % 9 + 1;\n if (j + 3 >= 9) j++;\n j = (j + 3) % 9;\n }\n\n sud.forEach(function (val) {\n print(val.join(''));\n });\n}"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n\n var input1 = readline().split(\"\").map((x) => parseInt(x));\n var input2 = readline().split(\"\").map((x) => parseInt(x));\n var input3 = readline().split(\"\").map((x) => parseInt(x));\n var input4 = readline().split(\"\").map((x) => parseInt(x));\n var input5 = readline().split(\"\").map((x) => parseInt(x));\n var input6 = readline().split(\"\").map((x) => parseInt(x));\n var input7 = readline().split(\"\").map((x) => parseInt(x));\n var input8 = readline().split(\"\").map((x) => parseInt(x));\n var input9 = readline().split(\"\").map((x) => parseInt(x));\n \n input1[0] = input1[1];\n input2[3] = input2[4];\n input3[6] = input3[7];\n\n input4[1] = input4[2];\n input5[4] = input5[5];\n input6[7] = input6[8];\n\n input7[2] = input7[1];\n input8[5] = input8[4];\n input9[8] = input9[7];\n\n print(input1.join(\"\"));\n print(input2.join(\"\"));\n print(input3.join(\"\"));\n print(input4.join(\"\"));\n print(input5.join(\"\"));\n print(input6.join(\"\"));\n print(input7.join(\"\"));\n print(input8.join(\"\"));\n print(input9.join(\"\"));\n}\n"}, {"source_code": "var T = parseInt(readline());\n\nfor (var p = 0; p < T; p++) {\n for (var q = 0; q < 9; q++) {\n var str = readline(); \n print(str.replace(\"1\", \"2\"));\n }\n}\n"}, {"source_code": "var T = parseInt(readline());\nwhile (T--) {\n var input1 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input2 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input3 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input4 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input5 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input6 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input7 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input8 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n var input9 = readline()\n .split(\"\")\n .map((x) => parseInt(x));\n input1[0] = input1[1];\n input2[3] = input2[4];\n input3[6] = input3[7];\n\n input4[1] = input4[2];\n input5[4] = input5[5];\n input6[7] = input6[8];\n\n input7[2] = input7[1];\n input8[5] = input8[4];\n input9[8] = input9[7];\n \n print(input1.join(\"\"));\n print(input2.join(\"\"));\n print(input3.join(\"\"));\n print(input4.join(\"\"));\n print(input5.join(\"\"));\n print(input6.join(\"\"));\n print(input7.join(\"\"));\n print(input8.join(\"\"));\n print(input9.join(\"\"));\n}\n"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const sudo = new Array(9)\n for(let i = 0; i < 9; i++) {\n sudo[i] = readString().split('')\n }\n sudo[0][0] = sudo[0][1]\n sudo[1][3] = sudo[1][4]\n sudo[2][6] = sudo[2][7]\n sudo[3][1] = sudo[3][2]\n sudo[4][4] = sudo[4][5]\n sudo[5][7] = sudo[5][8]\n sudo[6][2] = sudo[6][0]\n sudo[7][5] = sudo[7][3]\n sudo[8][8] = sudo[8][6]\n for(let i = 0; i < 9; i++) {\n wr(sudo[i].join(''))\n }\n }\n}"}, {"source_code": "var t = parseInt(readline());\n\nfor (var i = 0; i < t; i++) {\n for (var j = 0; j < 9; j++) {\n print(readline().replace('1','2'));\n }\n}\n"}, {"source_code": "var inputs = readline();\n\nfor(var k=0;k parseInt(x));\n\n team.splice(team.indexOf(1) , 1, 2);\n print(team.join(\"\"));\n }\n}"}, {"source_code": "\n//DISABLE THIS LINE END ENABLE NEXT\n//const rl = require('readline').createInterface({input: require('fs').createReadStream('input.txt')});\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst write = (...args) => {\n process.stdout.write(args.join(' ') );\n}\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\n\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nfunction main() {\n\tvar y = +readline()\n\twhile(y > 0) {\n\t\tvar input = [];\n\t\tvar r = 9;\n\t\tvar c = 0;\n\t\twhile(c < r) {\n\t\t\tvar row = readline().split('');\n\t\t\tinput.push(row);\n\t\t\tc++;\n\t\t}\n\t\tfor(var i = 0; i < r; i++) {\n\t\t\tfor(var j = 0; j < 9; j++) {\n\t\t\t\tif (input[i][j] == '1') {\n\t\t\t\t\tinput[i][j] = '2';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(var i = 0; i < r; i++) {\n\t\t\tif (i < 8 || y > 1) {\n\t\t\t\twrite(input[i].join('') + '\\n');\n\t\t\t} else {\n\t\t\t\twrite(input[i].join(''));\n\t\t\t}\n\t\t}\n\t\ty--;\n\t}\n}"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n arr = arr.slice(1);\n arr.forEach(element => {\n console.log(element.replace('1', '2'));\n });\n}\n\n//console.log(processData(\"1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563\"));\n\n\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n\n"}, {"source_code": "var inputs = readline();\n \nfor(var k=0;k parseInt(x));\n \n team.splice(team.indexOf(1) , 1, 2);\n print(team.join(\"\"));\n }\n}"}, {"source_code": "\n\nconst processData = (lines) => {\n const num = +lines[0]\n for (let i=0; i +x))\n }\n for (let n=0; n<9; n++) {\n const pos = [n, (n*3)%9 + Math.floor(n/3)]\n sudoku[pos[0]][pos[1]] = sudoku[pos[0]][pos[1]] === 1 ? 2 : 1\n }\n for (const s of sudoku) {\n console.log(s.join(''))\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst main = () => {\n let t = Number(readline());\n while (t--) {\n const a = Array.from(new Array(9), () => readline().split('').map(x => parseInt(x)));\n const toChange = [\n [0, 0],\n [1, 3],\n [2, 6],\n [3, 1],\n [4, 4],\n [5, 7],\n [6, 2],\n [7, 5],\n [8, 8]];\n const current = toChange.map(([x, y]) => a[x][y]);\n toChange.forEach(([i, j]) => {\n a[i][j] = a[i][(j + 1) % 3 + 3 * Math.floor(j / 3)]\n });\n print(a.map(x => x.join('')).join('\\n'))\n }\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n // let n = parseInt(readLine());\n let a = new Array(9);\n for (let i = 0; i < 9; i++)\n a[i] = readLine();\n let res = new Array(9).fill('');\n for(let i = 0; i < 9; i++) {\n for (let j = 0; j < 9; j++) {\n if (a[i][j] === '1') res[i] += '2';\n else res[i] += a[i][j];\n }\n }\n for (let i = 0; i < 9; i++) console.log(res[i]);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let n = parseInt(readline(), 10);\n\n for (var j = 0; j < n; j++) {\n for (var i = 0; i < 9; i++) {\n console.log(readline().replace(/8/g, '3'));\n }\n }\n \n}\n"}], "negative_code": [{"source_code": "function tpp(x) {\n return (x ==='9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n s.replace('1','2');\n print(s);\n }\n}"}, {"source_code": "function tpp(x) {\n return (x == '9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n if (i == 0) {\n s[0] = tpp(s[0]);\n }\n if (i == 1) s[3] = tpp(s[3]);\n if (i == 2) s[6] = tpp(s[6]);\n if (i == 3) s[1] = tpp(s[1]);\n if (i == 4) s[4] = tpp(s[4]);\n if (i == 5) s[7] = tpp(s[7]);\n if (i == 6) s[2] = tpp(s[2]);\n if (i == 7) s[5] = tpp(s[5]);\n if (i == 8) s[8] = tpp(s[8]);\n print(s);\n }\n}"}, {"source_code": "function tpp(x) {\n return (x == '9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n if (i === 0) {\n s[0] = tpp(s[0]);\n }\n if (i === 1) s[3] = tpp(s[3]);\n if (i === 2) s[6] = tpp(s[6]);\n if (i === 3) s[1] = tpp(s[1]);\n if (i === 4) s[4] = tpp(s[4]);\n if (i === 5) s[7] = tpp(s[7]);\n if (i === 6) s[2] = tpp(s[2]);\n if (i === 7) s[5] = tpp(s[5]);\n if (i === 8) s[8] = tpp(s[8]);\n print(s);\n }\n}"}, {"source_code": "function tpp(x) {\n return (x ==='9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n if (i === 0) {\n s[0] = tpp(s[0]);\n }\n if (i === 1) s[3] = tpp(s[3]);\n if (i === 2) s[6] = tpp(s[6]);\n if (i === 3) s[1] = tpp(s[1]);\n if (i === 4) s[4] = tpp(s[4]);\n if (i === 5) s[7] = tpp(s[7]);\n if (i === 6) s[2] = tpp(s[2]);\n if (i === 7) s[5] = tpp(s[5]);\n if (i === 8) s[8] = tpp(s[8]);\n print(s);\n }\n}"}, {"source_code": "function tpp(x) {\n return (x == '9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n if (i === 0) {\n s[0][0] = tpp(s[0][0]);\n }\n if (i == 1) s[3][1] = tpp(s[3][1]);\n if (i == 2) s[6][2] = tpp(s[6][2]);\n if (i == 3) s[1][3] = tpp(s[1][3]);\n if (i == 4) s[4][4] = tpp(s[4][4]);\n if (i == 5) s[7][5] = tpp(s[7][5]);\n if (i == 6) s[2][6] = tpp(s[2][6]);\n if (i == 7) s[5][7] = tpp(s[5][7]);\n if (i == 8) s[8][8] = tpp(s[8][8]);\n print(s);\n }\n}"}, {"source_code": "function tpp(x) {\n return (x == '9') ? '1' : x + 1;\n}\n\nvar t = +readline();\nwhile (t--) {\n var s = \"\";\n for (var i = 0; i < 9; i++) {\n s = readline();\n if (i == 0) {\n s[0] = tpp(s[0][0]);\n }\n if (i == 1) s[3] = tpp(s[3][1]);\n if (i == 2) s[6] = tpp(s[6][2]);\n if (i == 3) s[1] = tpp(s[1][3]);\n if (i == 4) s[4] = tpp(s[4][4]);\n if (i == 5) s[7] = tpp(s[7][5]);\n if (i == 6) s[2] = tpp(s[2][6]);\n if (i == 7) s[5] = tpp(s[5][7]);\n if (i == 8) s[8] = tpp(s[8][8]);\n print(s);\n }\n}"}, {"source_code": "var t = readline();\n\nwhile (t--) {\n var sud = new Array(9);\n\n for (var i = 0; i < 9; i++) {\n sud[i] = readline().split('').map(function (val) {\n return parseInt(val);\n });\n }\n\n for (var _i = 0; _i < 9; _i++) {\n sud[_i][_i] = sud[_i][_i] % 9 + 1;\n }\n\n sud.forEach(function (val) {\n print(val.join(''));\n });\n}"}, {"source_code": "var t = parseInt(readline());\n\nfunction mapper(num) {\n return +num;\n}\n\nfor (var i = 0; i < t; i++) {\n\n for (var j = 0; j < 9; j++) {\n var row = readline().split('');\n if (row[j] === '1') {\n row[j] = '9';\n } else {\n row[j] = '1';\n }\n print(row.join(''));\n }\n}\n"}, {"source_code": "var inputs = readline();\n\nfor(var k=0;k parseInt(x));\n\n if(team[i] === 9) {\n team[i] = team[i] - 1;\n } else {\n team[i] = team[i] + 1;\n \n }\n print(team.join(\"\"));\n }\n}"}, {"source_code": "var inputs = readline();\n\nfor(var k=0;k parseInt(x));\n if(i === 8) {\n team[i-1] = team[i];\n } else {\n team[i+1] = team[i];\n }\n print(team.join(\"\"));\n }\n}"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const sudo = new Array(9)\n for(let i = 0; i < 9; i++) {\n sudo[i] = readString().split('')\n }\n sudo[0][0] = sudo[0][1]\n sudo[1][3] = sudo[1][4]\n sudo[2][6] = sudo[2][7]\n sudo[3][1] = sudo[3][2]\n sudo[4][4] = sudo[4][5]\n sudo[5][7] = sudo[5][8]\n sudo[6][2] = sudo[6][0]\n sudo[7][5] = sudo[7][3]\n sudo[8][8] = sudo[8][6]\n for(let i = 0; i < 9; i++) {\n wr(sudo[i].join(' '))\n }\n }\n}"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n arr = arr.slice(1);\n arr.array.forEach(element => {\n console.log(element.replace('1','2'));\n });\n}"}, {"source_code": "const processData = (input) => {\n let exp = /\\s+/;\n let arr = input.split(exp);\n arr = arr.slice(1);\n arr.forEach(element => {\n console.log(element.replace('1','2'));\n });\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nfunction print(x) {\n console.log(x);\n}\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n \n//-----------main fucntion-----------\n \nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var n = 9\n while (n--) {\n var input1 = readline().split('').map(x => parseInt(x));\n var index = input1.indexOf(1)\n input1[index] = 2\n print(input1.join(''))\n }\n \n }\n \n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input1 = readline().split('').map(x => parseInt(x));\n var input2 = readline().split('').map(x => parseInt(x));\n var input3 = readline().split('').map(x => parseInt(x));\n var input4 = readline().split('').map(x => parseInt(x));\n var input5 = readline().split('').map(x => parseInt(x));\n var input6 = readline().split('').map(x => parseInt(x));\n var input7 = readline().split('').map(x => parseInt(x));\n var input8 = readline().split('').map(x => parseInt(x));\n var input9 = readline().split('').map(x => parseInt(x));\n input1[0] = input1[1]\n input2[3] = input2[4]\n input3[6] = input3[7]\n\n input4[1] = input4[2]\n input5[4] = input5[5]\n input6[7] = input6[8]\n\n input7[2] = input7[1]\n input8[5] = input8[4]\n input9[8] = input9[7]\n print(input1.join())\n print(input2.join())\n print(input3.join())\n print(input4.join())\n print(input5.join())\n print(input6.join())\n print(input7.join())\n print(input8.join())\n print(input9.join())\n\n }\n\n}\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input1 = readline().split('').map(x => parseInt(x));\n var input2 = readline().split('').map(x => parseInt(x));\n var input3 = readline().split('').map(x => parseInt(x));\n var input4 = readline().split('').map(x => parseInt(x));\n var input5 = readline().split('').map(x => parseInt(x));\n var input6 = readline().split('').map(x => parseInt(x));\n var input7 = readline().split('').map(x => parseInt(x));\n var input8 = readline().split('').map(x => parseInt(x));\n var input9 = readline().split('').map(x => parseInt(x));\n input1[1]=input1[0]\n input2[4]=input2[3]\n input3[7]=input3[6]\n\n input4[1]=input4[0]\n input5[4]=input5[3]\n input6[7]=input6[6]\n\n input7[1]=input7[0]\n input8[4]=input8[3]\n input9[7]=input9[6]\n print(input1)\n print(input2)\n print(input3)\n print(input4)\n print(input5)\n print(input6)\n print(input7)\n print(input8)\n print(input9)\n \n }\n\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n//-----------main fucntion-----------\n\nfunction main() {\n var T = parseInt(readline());\n while (T--) {\n var input1 = readline().split('').map(x => parseInt(x));\n var input2 = readline().split('').map(x => parseInt(x));\n var input3 = readline().split('').map(x => parseInt(x));\n var input4 = readline().split('').map(x => parseInt(x));\n var input5 = readline().split('').map(x => parseInt(x));\n var input6 = readline().split('').map(x => parseInt(x));\n var input7 = readline().split('').map(x => parseInt(x));\n var input8 = readline().split('').map(x => parseInt(x));\n var input9 = readline().split('').map(x => parseInt(x));\n input1[0] = input1[1]\n input2[3] = input2[4]\n input3[6] = input3[7]\n\n input4[1] = input4[2]\n input5[4] = input5[5]\n input6[7] = input6[8]\n\n input7[2] = input7[1]\n input8[5] = input8[4]\n input9[8] = input9[7]\n print(input1.join(''))\n print(input2.join(''))\n print(input3.join(''))\n print(input4.join(''))\n print(input5.join(''))\n print(input6.join(''))\n print(input7.join(''))\n print(input8.join(''))\n print(input9.join(''))\n\n }\n\n}\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst main = () => {\n let t = Number(readline());\n while (t--) {\n const a = Array.from(new Array(9), () => readline().split('').map(x => parseInt(x)));\n const toChange = [\n [0, 0],\n [1, 3],\n [2, 6],\n [3, 1],\n [4, 4],\n [5, 7],\n [6, 2],\n [7, 5],\n [8, 8]];\n const current = toChange.map(([x, y]) => a[x][y]);\n toChange.forEach(([i, j]) => {\n a[i][j] = a[(i + 1) % 9][(j + 1) % 9]\n });\n print(a.map(x => x.join('')).join('\\n'))\n }\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n // let n = parseInt(readLine());\n let a = new Array(9);\n for (let i = 0; i < 9; i++)\n a[i] = readLine();\n let res = new Array(9).fill('');\n for(let i = 0; i < 9; i++) {\n for (let j = 0; j < 9; j++) {\n if (i === j) {\n let char = parseInt(a[i][j]) + 1;\n if (char === 10) char = 1;\n res[i] += char;\n }\n res[i] += a[i][j];\n }\n }\n for (let i = 0; i < 9; i++) console.log(res[i]);\n }\n //process.stdout.write(\"hello: \");\n}\n"}], "src_uid": "0e21f1c48c8c0463b2ffa7275eddc633"} {"source_code": "var n = parseInt(readline(), 10), \n inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a), \n totalMoney = 0,\n tempMoney = 0,\n coin = 0;\n \ntotalMoney = inp.reduce((a,b) => a+b);\n \nwhile(1) {\n \n tempMoney += inp[coin];\n \n if(tempMoney > totalMoney/2) break;\n \n coin++;\n}\n \nprint(++coin);", "positive_code": [{"source_code": "var number=readline();\nvar coins=readline();\nvar array = coins.split(\" \").map(Number);\narray.sort(function(a, b){return a - b});\nvar sumCoins=0;\nvar result=0;\nfor( i=0;i=sumCoins-sumI) {\n\tresult=number-i+1\n return result\n}\n\n\n}\nresult=1;\nreturn result\n}\n\nprint(getResult())"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\" \");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b)) / 2;\nfor( var i = 0 ; i < n ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > sum){break;}\n}\nprint(count);\n\t"}, {"source_code": "var nums = readline();\nvar coins = readline().split(\" \").map(Number).sort((a, b) => b - a);\nvar total = coins.reduce((acc, curr) => acc + curr, 0);\n\nvar my = 0;\nvar twin = total;\nvar count = 0;\n\nfor (var i = 0; i < coins.length; i++) {\n my += coins[i];\n twin -= coins[i];\n count = i + 1;\n \n if (my > twin) {\n break;\n }\n}\n\nprint(count);"}, {"source_code": "function main(){\n var n = +readline();\n var ms = readline().split(' ').sort((a,b) => +b - +a);\n var sum = ms.reduce((acc, ac) => acc + +ac, 0);\n var med = sum / 2;\n var res = 0;\n for(var i = 0; i < n; ++i){\n res += +ms[i];\n if(res > med){\n break;\n }\n }\n print(i + 1);\n}\n\nmain();"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\" \");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b)) / 2;\nfor( var i = 0 ; i < n ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > sum){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "//var input = \"3\\n2 1 2\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var n = parseInt(readline());\n var arr = readline().split(' ');\n var sum = 0;\n var ans = 0;\n for(var i = 0; i < arr.length; i++){\n arr[i] = parseInt(arr[i]);\n sum += arr[i];\n }\n arr.sort(function(a, b){\n return a - b;\n });\n var index = arr.length - 1;\n while(ans <= sum){\n ans += arr[index];\n sum -= arr[index];\n index--;\n }\n print(arr.length - index - 1);\n}\nmain();"}, {"source_code": "function readNumbers() {\n\treturn readline().split(' ').map(function (x) {\n\t\treturn parseInt(x);\n\t});\n}\n\nvar n = parseInt(readline());\nvar coins = readNumbers();\n\ncoins.sort(function (a, b) {\n\treturn b - a;\n});\n\nvar sum = 0;\n\nfor (var i = 0; i < n; i++) {\n\tsum += coins[i];\n}\n\nvar part = 0;\nvar count = 0;\n\nfor (var i = 0; i < n; i++) {\n\tpart += coins[i];\n\tcount++;\n\n\tif (part > sum / 2) {\n\t\tbreak;\n\t}\n}\n\nprint(count)"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readLine = this.readline || require('lol-io').readline\n\n\nvar num=readLine().split(' ')[0];\n\nvar arr=readLine().split(' ').map(i=>parseInt(i));\n\nvar max=0;\nvar sum=0;\nvar count=0;\nvar s=0;\narr.sort(function(a,b){return b-a});\nfor(var i=0;i b - a);\nvar need = nums.reduce((a,b) => a+b) / 2;\nvar value = 0;\nfor (var i = 0; i < nums.length && value <= need; i++) {\n value += nums[i];\n}\nprint(i);\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}"}, {"source_code": "n = parseInt(readline());\nA = readline().split(\" \");\nA.sort(function(a,b){return parseInt(a) - parseInt(b)});\nsum = 0;\nsum1 = 0;\nats = 0;\nfor (var i = 0; i < n; i++){\n sum += parseInt(A[i]);\n}\nfor (var i = n-1; i >= 0 && sum >= sum1; i--){\n sum -= parseInt(A[i]);\n sum1 += parseInt(A[i]);\n ats++;\n}\nwrite(ats);\n"}, {"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(word) {\n\t\treturn parseInt(word)\n\t})\n}\n\nvar asc = function(a, b) {\n\treturn a - b\n}\n\nreadline()\nvar numbers = ints(),\n\tsum = numbers.reduce(function(a, b) { return a + b }, 0),\n\tcurrent = 0,\n\tcounter = 0,\n\tindex = numbers.length - 1\n\nnumbers.sort(asc)\n\nwhile (index >= 0) {\n\tcurrent += numbers[index]\n\tcounter ++\n\tif (current > sum / 2)\n\t\tbreak\n\tindex --\n}\n\nprint(counter)"}, {"source_code": "var numberOfCoins = Number(readline())\nvar coins = readline().split(' ').map(Number).sort((a, b) => a - b)\n\nvar total = 0\nfor(var i = 0; i < numberOfCoins; i++) {\n total += coins[i]\n}\n\nvar numberOfCoinsPicked = 0\nvar valueCoinsPickes = 0\n\nfor(var i = numberOfCoins - 1; i >= 0; i--) {\n if (total >= valueCoinsPickes) {\n valueCoinsPickes += coins[i]\n total -= coins[i]\n numberOfCoinsPicked += 1\n }\n}\n\nprint(numberOfCoinsPicked)"}, {"source_code": "var len = readline();\nvar s = readline();\nvar sumRemain = 0;\nvar sumTake = 0;\n\nvar a = s\n .split(' ')\n .map(Number)\n .sort(function(a, b) {\n return b - a;\n });\n\na.forEach(function(b) {\n sumRemain += b;\n});\n\nfor (var i = 0; i < len; i++) {\n sumTake += a[i];\n sumRemain -= a[i];\n if (sumTake > sumRemain) {\n print(i + 1);\n break;\n }\n}"}, {"source_code": "var quantity = readline();\nvar digits = readline().split(\" \").sort((a, b) => a - b);\n\nfunction sum(arr) {\n\treturn arr.reduce((sum, item) => sum += +item, 0);\n}\n\ndigits.reduceRight((result) => {\n\tif (result <= sum(digits)) {\n\t\tresult += +digits.pop();\n\t}\n\t\n\treturn result;\n}, 0);\n\nprint(quantity - digits.length);\n"}, {"source_code": "var main;\n\nmain = function() {\n var a, a1, a2, coins, i, mm, mycoin, num=0, _i, _ref;\n a1 = readline();\n a2 = Number(a1);\n coins = Array();\n a = readline().split(\" \");\n for (i = _i = 0, _ref = a2 - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {\n coins.push(Number(a[i]));\n num = num + Number(a[i]);\n \t\n }\n coins.sort(function(x, y) {\n return y - x;\n });\n mycoin = coins[0];\n\n mm = 0;\n while (Number(mycoin) <= num - mycoin) {\n mm++;\n mycoin = mycoin + coins[mm];\n }\n print(mm+1);\n \n};\n\nmain();"}, {"source_code": ";(function () {\n\n\treadline();\n\tvar s = readline().split(' ').map(function (x) {return parseInt(x); }).sort(function (a, b) {return a - b;});\n\n\tvar sum1 = 0;\n\tvar sum2 = 0;\n\n\tvar i = 0;\n\tvar j = s.length - 1;\n\n\twhile (j >= i)\n\t\tif ((sum1 + s[i]) >= sum2) sum2 += s[j--];\n\t\telse sum1 += s[i++];\n\n\tprint(s.length - i);\n\n}).call(this);"}, {"source_code": "readline();\nvar arr = readline().split(\" \").map(v => v - 0);\narr.sort((a,b) => b - a);\nvar s1 = arr.reduce((a, b) => a + b) / 2;\nvar s2 = 0;\nfor (var i = 0; i < arr.length && s2 <= s1; ++i) {\n s2 += arr[i];\n}\nprint(i);"}, {"source_code": "\n var n = parseInt(readline());\n var line2 = readline()\n .split(\" \")\n .map((el) => parseInt(el)),\n max = 0,\n sum = 0,\n counter = 0,\n equal = 0,\n currentsum = 0,\n myarr = [...line2];\n\n function findMax() {\n for (var i = 0; i < n; i++) {\n if (max < myarr[i]) {\n max = myarr[i];\n }\n sum += myarr[i];\n }\n return sum;\n }\n\n // each person money\n equal = findMax() / 2;\n // removing the current max from the array\n function spliceArray(max) {\n for (var j = 0; j < n; j++) {\n if (max == myarr[j]) {\n myarr.splice(j, 1);\n j = 0;\n break;\n }\n }\n return myarr;\n }\n\n for (var a = 0; a < n; a++) {\n if (max > equal) {\n counter++;\n break;\n }\n if (currentsum <= equal) {\n currentsum += max;\n spliceArray(max);\n counter++;\n }\n // searching for the next max\n max = 0;\n for (var x = 0; x < n; x++) {\n if (max < myarr[x]) {\n max = myarr[x];\n }\n }\n }\n\n print(counter);\n "}, {"source_code": "\n var n = parseInt(readline());\n var line2 = readline()\n .split(\" \")\n .map((el) => parseInt(el)),\n max = 0,\n sum = 0,\n counter = 0,\n equal = 0,\n currentsum = 0,\n myarr = [...line2];\n\n function findMax() {\n for (var i = 0; i < n; i++) {\n if (max < myarr[i]) {\n max = myarr[i];\n }\n sum += myarr[i];\n }\n return sum;\n }\n\n equal = findMax() / 2;\n function spliceArray(max) {\n for (var j = 0; j < n; j++) {\n if (max == myarr[j]) {\n myarr.splice(j, 1);\n j = 0;\n break;\n }\n }\n return myarr;\n }\n\n for (var a = 0; a < n; a++) {\n if (max > equal) {\n counter++;\n break;\n }\n if (currentsum <= equal) {\n currentsum += max;\n spliceArray(max);\n counter++;\n }\n // searching for the next max\n max = 0;\n for (var x = 0; x < n; x++) {\n if (max < myarr[x]) {\n max = myarr[x];\n }\n }\n }\n\n print(counter);\n "}, {"source_code": "\n var n = parseInt(readline());\n var line2 = readline()\n .split(\" \")\n .map((el) => parseInt(el)),\n max = 0,\n sum = 0,\n counter = 0,\n equal = 0,\n currentsum = 0,\n myarr = [...line2];\n\n function findMax() {\n for (var i = 0; i < n; i++) {\n if (max < myarr[i]) {\n max = myarr[i];\n }\n sum += myarr[i];\n }\n return sum;\n }\n\n equal = findMax() / 2;\n function spliceArray(max) {\n for (var j = 0; j < n; j++) {\n if (max == myarr[j]) {\n myarr.splice(j, 1);\n j = 0;\n break;\n }\n }\n return myarr;\n }\n\n for (var a = 0; a < n; a++) {\n if (max > equal) {\n counter++;\n break;\n }\n if (currentsum <= equal) {\n currentsum += max;\n spliceArray(max);\n counter++;\n }\n max = 0;\n for (var x = 0; x < n; x++) {\n if (max < myarr[x]) {\n max = myarr[x];\n }\n }\n }\n\n print(counter);\n "}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort((a,b)=> a-b),\n sum = 0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar counter=coins[numberOfCoin-1];\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= (sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": " var numberOfCoins = readline()\n var result = 0\n\n var coinsArr = readline().split(' ').map(function (coin) { return parseInt(coin, 10) })\n var sortedCoins = coinsArr.sort(function (a, b) {\n return b - a\n })\n\n for (var i = 0; i <= numberOfCoins; i++) {\n var arr1 = sortedCoins.slice(0, i)\n var arr2 = sortedCoins.slice(i)\n\n var sum1 = arr1.reduce(function (previous, current) {\n previous += current\n return previous\n }, 0)\n var sum2 = arr2.reduce(function (previous, current) {\n previous += current\n return previous\n }, 0)\n\n if (sum1 > sum2) {\n result = i\n break\n }\n }\n\n print(result)"}, {"source_code": "// var print = this.print || require(\"lol-io\").print;\n// var write = this.write || require(\"lol-io\").write;\n// var readline = this.readline || require(\"lol-io\").readline;\nvar n = readline();\nvar a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\nvar sum = a.reduce((x, y) => x + y, 0);\nvar x = Math.floor(sum / 2);\nvar final_sum = 0;\nvar count = 0;\nvar new_arr = a.sort((t, b) =>{\n return t - b;\n });\nfor (var i=n-1;i>=0;i--) {\n final_sum += new_arr[i];\n count++;\n if (final_sum > x) {\n print(count);\n break;\n }\n}"}, {"source_code": "var n=readline(); n=parseInt(n);\nvar arr=readline().split(' ').map(function(x){return parseInt(x) ; });\narr.sort(function(a,b){return a-b;}); var sum=0;\nfor( var i=0; i =0;i--)\n{\n num+=arr[i]; if(num>sum/2){print(n-i); break;}\n}"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(function(c){ return parseInt(c); }).sort(function(a, b){\n\treturn b - a;\n});\nvar totalsum = a.reduce(function(a, b){\n\treturn a + b;\n});\nvar mysum = 0;\nvar coinstaken = 0;\n\nwhile((mysum <= (totalsum - mysum)) && (a.length > 0))\n{\n\tmysum += a[0];\n\tcoinstaken += 1;\n\ta.shift();\n}\n\nprint(coinstaken);"}, {"source_code": "'use strict';\nlet _ = readline(),\n totalAmount = 0,\n outAmount = 0,\n array = readline().split(' ').map(function(value){ \n value = parseInt(value);\n totalAmount += value\n return value;\n }).sort(function(a, b){return a - b}).reverse();\n \nlet i = 0;\nfor(; totalAmount >= outAmount; i++){\n totalAmount -= array[i];\n outAmount += array[i];\n}\n\nwrite(i)"}, {"source_code": "var n = +readline();\n \nvar arr = readline().split(' ');\n \nfor(var i in arr)\n\tarr[i] = +arr[i];\n \nfunction sort_inc(a,b){\n\treturn a - b;\n}\n \narr.sort(sort_inc);\n \nvar sum = 0;\nvar ans = +n;\nvar fsum = 0;\n \nfor(var i in arr)\n\tsum += arr[i];\n \nfor(var i in arr){\n \n\tfsum += arr[i];\n\tsum -= arr[i];\n \n\tif(fsum >= sum){\n\t\tsum = n - i;\n\t\tbreak;\n\t}\n \n}\n \nprint(sum);"}, {"source_code": "var coinNum = parseInt(readline());\nvar coins = readline().split(' ').map(function(numStr){\n return parseInt(numStr);\n}).sort(function(a, b){\n return b - a;\n});\nvar i, totalSum = 0, halfTotalSum, partSum = 0, need = 0;\n\ncoins.forEach(function(num){\n totalSum += num;\n});\n\nhalfTotalSum = Math.floor(totalSum / 2);\n\nfor(i=0;i halfTotalSum){\n break;\n }\n}\n\nprint(need);\n"}, {"source_code": "\tvar n = readline();\n\tvar str = readline().split(\" \").sort((x,y)=>y-x);\n\tvar sum = str.reduce((x,y)=>+x+Number(y));\n\t\n\tvar temp = 0;\n\tvar res = 0;\n\n\tfor (var i=0; isum-temp) break;\n\t\ttemp+=+str[i];\n\t\tres++;\n\t}\n\tprint(res);"}, {"source_code": "var numOfCoins = parseInt(readline());\nvar coins = readline().split(\" \");\nvar sum = 0;\n\nfor (var i = 0; i < numOfCoins; i++) {\n sum += parseInt(coins[i]);\n}\n\nfor (var i = 0; i < numOfCoins - 1; i++) {\n for (var j = 0; j < numOfCoins; j++) {\n if (parseInt(coins[j]) > parseInt(coins[j + 1])) {\n var temp = coins[j];\n coins[j] = coins[j + 1];\n coins[j + 1] = temp;\n }\n }\n}\n\nvar subtractSum = 0;\nvar counter = 0;\n\nfor (var i = numOfCoins - 1; (subtractSum <= sum); i--) {\n sum -= parseInt(coins[i]);\n subtractSum += parseInt(coins[i]);\n counter++;\n}\n\nprint(counter);"}, {"source_code": "function toint(x) { return parseInt(x, 10); }\nfunction arraySum(a) { return a.reduce(function(prev, x) { return prev + x; }, 0); }\nreadline();\ncoins = readline().split(' ')\n .map(function(x) {\n return +x;\n }).sort(function(a, b) {\n return a < b ? -1 : a == b ? 0 : 1;\n }).reverse();\nsum = arraySum(coins);\nntaken = 0, sumtaken = 0;\nfor (var i = 0; i < coins.length && sumtaken <= sum/2; ++i) {\n sumtaken += coins[i];\n ntaken++;\n}\nprint(ntaken);\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(v){ return +v; });\na.sort(function(a, b){return b-a;});\nvar sum = a.reduce(function(a, b){ return a+b;}, 0);\nvar b=0;\nfor(var i=0; b<=sum; i++){\n\tb+=a[i];\n\tsum-=a[i];\n}\nprint(i);\n"}, {"source_code": "var n = +readline(), a = readline().split(\" \");\n\na.sort(function(a,b){return b-a});\n\nif( n == 1 ){\n\twrite(1);\n}\nelse{\n\tfor(i = 1; i < n; i++){\n\t\tvar sum1 = 0, sum2 = 0;\n\t\tfor(j = 0; j < i; j++){\n\t\t\tsum1 += +a[j];\n\t\t}\n\t\tfor(k = i; k < n; k++){\n\t\t\tsum2 += +a[k];\n\t\t}\n\t\tif( sum1 > sum2 ){\n\t\t\twrite(i);\n\t\t\tbreak;\n\t\t}\n\t\tif( sum1 == sum2 && n == 2 ){\n\t\t\twrite(2);\n\t\t}\n\t}\n}"}, {"source_code": "var len=parseInt(readline());\n\nvar x=readline().split(' ').map(x => parseInt(x));\n\nx.sort((a,b) => b-a);\n\nvar count=0;\nvar sum=0;\nvar maxSum=0;\n\nfor(var i=0; i sum-maxSum){\n break;\n }\n}\n\nprint(count);"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0; i < dataMas.length; i++) {\n dataMas[i] = parseInt(dataMas[i]);\n for (var j = i+1; j < dataMas.length; j++) {\n dataMas[j] = parseInt(dataMas[j]);\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0; sum2 <= sum; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n answer = answer + 1; \n}\n\nwrite(answer);"}, {"source_code": "const main = () => {\n readline();\n\n var sum = 0;\n\n const coins = readline()\n .split(\" \")\n .map((coin) => {\n var numCoin = Number(coin);\n\n sum += numCoin;\n\n return numCoin;\n })\n .sort((a, b) => a - b);\n\n var currSum = 0;\n var currIndex = coins.length - 1;\n\n while (currSum <= sum / 2) {\n currSum += coins[currIndex];\n currIndex--;\n }\n\n return coins.length - currIndex - 1;\n};\n\nprint(main());\n"}, {"source_code": "var n = readline(),\n coins = readline().split(' ').sort((a, b) => a - b).reverse().map(Number),\n sum = coins.reduce((a, b) => a + b),\n\n targeted = sum / 2,\n mySum = 0,\n count = 0;\n for(var v of coins) {\n \n if(mySum > targeted)\n break;\n else\n mySum += v;\n count++;\n }\n\n print(count);"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns(s) {\n\treturn s.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumber(a,b) {\n\treturn a-b;\n}\n\nvar n = readn();\nvar ss = readline();\nvar a = readns(ss);\n\na = a.sort(sortNumber).reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar f = function(num) {return parseInt(num);};\nvar line = readline().split(' ').map(f);\nline.sort(function(a, b) {return b - a});\nvar sumLine = function(from){\n var s = 0;\n for(var i = from;i < line.length;i++){\n s += line[i];\n }\n return s;\n};\nvar m = line[0];\nvar c = 1;\nfor(var i = 1; i < line.length; i++){\n var sum = sumLine(i);\n if(m >= sum){\n if(m === sum) c++;\n break;\n }\n m += line[i];\n c++;\n}\nprint(c);"}, {"source_code": "/* TEST CASE\ninput\n2\n3 3\noutput\n2\ninput\n3\n2 1 2\noutput\n2\n\nInput\n7\n1 10 1 2 1 1 1\nOutput\n2\nAnswer\n1\n\n\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar a = new Array(n);\n\tvar answer = 0;\n\tvar i;\n\tvar sum = 0;\n\tvar splitted = readline().split(' ');\n\t\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t\tsum += a[i]; \n\t}\n\tvar half = (sum >> 1);\n\tsum = 0;\n\ta.sort(function(v1, v2) {return v1 - v2;});\n//FOR DEBUG:\tprint(a);\n\tfor (i = n - 1; i >= 0 && sum <= half; i--) {\n\t\tsum += a[i];\n\t}\n\tanswer = n - 1 - i;\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var monedas = +readline();\nvar valores = readline().split(\" \").map(function(v){return +v;}).sort(function(a,b) {return b-a;});\nvar suma = valores.reduce(function(a,b) {return a+b;},0);\nvar numMonedas = 0;\nvar contador = 0;\n\nfor (var i = 0; i Number(x)), coinCount = 0;\nfunction arrayDescend(array) {\n\tvar result = Array.from(array);\n\tfor (var i = 0; i < result.length - 1; i++) {\n\t\tfor (var j = 0; j < result.length - i - 1; j++) {\n\t\t\tif (result[j] < result[j + 1]) {\n\t\t\t\tvar temp = result[j];\n\t\t\t\tresult[j] = result[j + 1];\n\t\t\t\tresult[j + 1] = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn result;\n}\narray = arrayDescend(array);\nfor (var i = 1; i <= array.length; i++) {\n\tvar mySum = array.slice(0, i).reduce((a, b) => a + b);\n\tvar brotherSum = 0;\n\tif (i != array.length) brotherSum = array.slice(i).reduce((a, b) => a + b);\n\tif (mySum > brotherSum) {\n\t\tcoinCount = i;\n\t\tbreak;\n\t}\n}\nprint(coinCount);"}, {"source_code": "var n = parseInt(readline());\nvar s = readline().split(' ').map(Number).sort(function(a, b){return b-a});\n\nvar minCoin = 0;\nvar sumAll = s.reduce((a,b)=>a+b, 0);\n\nvar curSum = 0;\nvar needSum = Math.floor(sumAll/2);\nfor (var i = 0; i < s.length; i++) {\n minCoin++;\n curSum+=s[i];\n if (curSum > needSum) {\n break;\n }\n}\n\nprint(minCoin);"}, {"source_code": "var counts = Number(readline()),\n data = readline().split(' '),\n i = 0;\n \nvar summ = 0,\n summ1 = 0;\n \ndata.map(function(c) {\n summ += Number(c);\n});\n\ndata.sort(function(a, b) {\n return b-a;\n});\n\ndo {\n summ1 += Number(data[i]);\n i++;\n} while (summ1 <= summ - summ1);\n\nprint(i);\n"}, {"source_code": "function sortByIncrease(a,b)\n{\n return a - b;\n}\nfunction NeedSumForMeanMe(str)\n{\n str = str.split(' ');\n for (var i = 0 ; i <=str.length - 1; i++)\n {\n str[i] = +str[i];\n }\n str = str.sort(sortByIncrease);\n var sum = str[str.length - 1], res = 1;\n for (i = str.length - 2; i >= 0; i--)\n {\n\t\tvar sumstr = 0;\n for (var i1 = i; i1 >= 0; i1--)\n {\n sumstr += str[i1];\n }\n if (sum > sumstr) break;\n else\n {\n\t\t\tres += 1;\n sum += str[i];\n }\n }\n return res;\n \n}\n{\n var num = readline();\n var input = readline();\n num = +num;\n print(NeedSumForMeanMe(input));\n \n}"}, {"source_code": "var n = readline();\nvar coins = readline().split(\" \").sort(function(a,b){\n\treturn parseInt(a)-parseInt(b);\n});\nvar sum = coins.reduce(function(a,b){\n\treturn parseInt(a)+parseInt(b);\n},0);\nvar uTake = 0;\nvar uTakeN = 0;\nfor(var i = n-1; i >= 0; i--){\n\tuTake += parseInt(coins[i]);\n\tuTakeN++;\n\tif(uTake > (sum - uTake))\n\t\tbreak;\n}\nprint(uTakeN);"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\nvar min = 0;\nvar count = 0;\ncoins.sort(function(a, b) {\n return b - a;\n});\n\nfor(var i = 0; i < coins.length; i++){\n total = total + parseInt(coins[i]);\n}\n\n\nfor(var j = 0; j < coins.length; j++){\n min = min + parseInt(coins[j]);\n if(min > total/2){\n count = count + 1;\n break;\n }\n count = count + 1;\n}\n\n\nprint(count);\n\n"}, {"source_code": "var n = parseInt(readline(), 10), \n inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a), \n totalMoney = 0,\n tempMoney = 0;\n coin = 0;\n \ntotalMoney = inp.reduce((a,b) => a+b);\n\nwhile(1) {\n \n tempMoney += inp[coin];\n \n if(tempMoney > totalMoney/2) break;\n \n coin++;\n}\n\nprint(++coin);"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \").map(Number).sort(function (a, b) {\n\treturn b - a;\n});\n\nvar sum = input.reduce(function (prev, next) {\n\treturn prev + next;\n});\n\nvar temp = 0,\n\tcoins = 0;\n\nfor (var i = 0; i < input.length; i++) {\n\tif (temp > sum) {\n\t\tbreak;\n\t}\n\n\ttemp += input[i];\n\tsum -= input[i];\n\tcoins++;\n}\n\nprint(coins);"}, {"source_code": "var coinsCount = readline();\nvar coinsArr = readline().split(' ').sort(sortNumber);\n// print(coinsArr);\n\nvar maxSum = findArrSum(coinsArr);\nprint(findCoinsCount(coinsArr));\n\nfunction findCoinsCount(arr){\n \n var mySum = 0;\n var myCointCount = 0;\n var remaining = 0;\n \n for (var i = arr.length - 1; i > -1; i--){\n \n mySum += Number(arr[i]);\n myCointCount++;\n remaining = maxSum - mySum;\n \n // print('mySum', mySum);\n // print('remaining', remaining);\n \n if (mySum > remaining){\n return myCointCount;\n }\n }\n}\n\nfunction findArrSum(arr){\n var sum = 0;\n for (var j = 0; j < arr.length; j++){\n arr[j] = Number(arr[j]);\n sum += arr[j];\n }\n return sum;\n}\n\nfunction sortNumber(a,b) {\n return a - b;\n }\n\n// function findArrSum(arr, indStart, indEnd){\n// var sum = 0;\n// for (var j = indStart; j < indEnd + 1; j++){\n// sum += Number(arr[j]);\n// }\n// return sum;\n// }"}, {"source_code": "const readline = require('readline');\n\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n\n// Excute algorithm\nrl.on('close', () => {\n \n const numOfCoins = inputs[1].split(' ').length;\n const coinsValue = inputs[1].split(' ').sort((a, b) => b - a);\n const totalValue = inputs[1].split(' ').reduce((accum, c) => accum += parseInt(c), 0)\n const minVal = (totalValue / 2) + 1;\n let minNumOfCoins = 0;\n let myValue = 0;\n\n for (let i = 0; i < numOfCoins; i++) {\n\n if (myValue < Math.floor(minVal)) {\n myValue += parseInt(coinsValue[i])\n minNumOfCoins++\n } else {\n return console.log(minNumOfCoins)\n }\n }\n\n return console.log(minNumOfCoins)\n\n})"}, {"source_code": "var n = Number(readline())\nvar arr = readline()\n\n\nfunction getCoins(n, arr) {\n arr = arr.split(' ').map(i => Number(i)).sort((a, b) => {\n if(a > b) return -1\n return 1\n })\n\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n var resultSum = result.reduce((a, b) => a + b, 0)\n if(resultSum > (sum / 2)) {\n return result.length\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const p = readline().split(' ').map(x => parseInt(x));\n const half = p.reduce((l, m) => l + m, 0) / 2;\n let s = 0;\n let c = 0;\n p.sort((l, m) => m - l);\n while (s <= half) {\n s += p[c++];\n if (s > half) {\n break;\n }\n }\n print(c);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n\n const sum = arr.reduce((a, b) => a + b, 0);\n let currSum = 0;\n let idx = 0;\n\n while (currSum <= Math.floor(sum / 2)) {\n currSum += arr[idx];\n idx++;\n }\n\n console.log(idx);\n\n c++;\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const arr = input[1].split(' ').map(x => parseInt(x));\n \n let sum = arr.reduce((prev, next) => prev+next, 0);\n let yourSum = 0;\n \n arr.sort((a, b) => a - b);\n for (let i = arr.length-1; i >= 0; i -= 1) {\n yourSum += arr[i]; sum -= arr[i];\n if (yourSum > sum) {\n console.log(arr.length - i); break;\n }\n }\n});"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main(){\n\n let coinCount =Number.parseInt( readline());\n let coins = readline().split(\" \").map( (item) => Number.parseInt(item));\n // desc\n coins = coins.sort((a,b) => a - b);\n \n let picked = [];\n let notPicked = coins;\n while(true) {\n \n picked.push(notPicked.pop());\n let pickedSum = picked.reduce((a , b) => a + b, 0)\n let notPickedSum = notPicked.reduce((a,b) => a + b, 0);\n if(pickedSum > notPickedSum)\n {\n process.stdout.write(picked.length.toString());\n break;\n }\n\n \n }\n\n \n}"}, {"source_code": "readline();\nvar list = readline().split(' ').sort(function(a,b){ return b-a;});\n var total = 0;\n for (var i = 0; i < list.length; i++) {\n total += parseInt(list[i]);\n }\n var index = 0;\n var amount = 0;\n while (amount <= total-amount && index < list.length) {\n amount += parseInt(list[index]);\n index++;\n }\n print(index) ;"}, {"source_code": "var n = readline();\nn = readline().split(' ').map(function(each) {return Number(each);});\nn.sort(function(a, b) {\n return a - b;\n});\n\nvar remains = 0;\nfor (var i = 0; i < n.length; ++i)\n remains += n[i];\n\nvar mine = 0;\n\ni = n.length - 1;\nwhile (remains >= mine && i >= 0) {\n mine += n[i];\n remains -= n[i];\n --i;\n}\n\nprint(n.length - i - 1);\n"}, {"source_code": "var ln = +readline();\nvar coins = readline().split(' ').map(e => +e).sort((a, b) => a - b).reverse();\n\nfor (var i=0; i right) {\n write(String(i + 1) + '\\n');\n break;\n }\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet standardInputString = '';\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on('data', rawData=> {\n standardInputString += rawData;\n})\n\nprocess.stdin.on('end', _ => {\n standardInputString = standardInputString.trim().split('\\n').map(line=> {\n return line.trim();\n })\n main();\n})\n\nfunction main() {\n const coinsNumber = +(readLine());\n const coin = readLine().split(\" \").join(\",\");\n let sum = eval(coin.split(\",\").join(\"+\"));\n const minimum = sum / 2;\n let possible = 0;\n let count = 0;\n let sorted = Array.from(coin.split(\",\")).map(x=> 1*x);\n sorted = sorted.sort((a,b)=> a - b);\n for(let i = sorted.length - 1; i >= 0; i--) {\n possible = possible + (1* sorted[i]);\n count++;\n if(possible > minimum) break;\n }\n console.log(count);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let numberofCoins = parseInt(readLine());\n let valuesofCoins = readLine().split(' ').map(Number);\n let sum = 0;\n for (let i = 0; i < valuesofCoins.length; i++) {\n sum = sum + valuesofCoins[i];\n }\n\n valuesofCoins = valuesofCoins.sort((a, b) => b - a);\n let finalArry = [];\n let finalSum = 0;\n for (let i = 0; i < valuesofCoins.length; i++) {\n if (finalSum <= sum / 2) {\n finalArry.push(valuesofCoins[i]);\n finalSum = finalSum + valuesofCoins[i];\n }\n }\n let final = finalArry.length;\n console.log(final);\n}\n"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\nfor (let i = 1; i < txt.length; i += 2) {\n let info = txt[i].split(\" \").filter(data => {\n return data.length > 0;\n }).map(data => {\n return data * 1;\n }).sort((a, b) => {\n return b - a;\n });\n doit(info);\n}\n\nfunction doit(tab) {\n let me=0,twin=0,coins=0;\n tab.forEach(data=>{\n twin+=data;\n });\n tab.forEach(data=>{\n if(me>twin){\n return;\n }else{\n me+=data;\n twin-=data;\n ++coins;\n }\n });\n console.log(coins);\n}"}, {"source_code": "var s = Number(readline())\nvar res = 0\nvar j =readline().split(\" \")\nvar max = 0\n\nfunction sortNumber(a,b) {\n return a - b;\n}\nj.sort(sortNumber);\nj.reverse()\n\nfor (var i = 0; i < s; i++) {\n \n var ab = j.slice(0, i + 1).reduce((a, b) => Number(a) + Number(b), 0)\n var bb = j.slice(i + 1, s + 1).reduce((a, b) => Number(a) + Number(b), 0)\n \n if(ab > bb) {\n res = i + 1\n break;\n } \n}\n\nprint(res)"}, {"source_code": "// Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.\n\n// Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1,\u2009a2,\u2009...,\u2009an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.\n\n// As you woke up, you found Mom's coins and read her note. \"But why split the money equally?\" \u2014 you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.\n\n// Input\n// The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the coins' values. All numbers are separated with spaces.\n\n// Output\n// In the single line print the single number \u2014 the minimum needed number of coins.\n\nvar n = readline()\nvar c = readline().split(\" \").sort((a, b) => (a - b)).reverse()\nvar s = 0\n\nfunction add(a, b){\n return +a + +b;\n}\n\nfor (i=0; ic.reduce(add)-s){\n print(i+1);\n break;\n }\n}\n\n"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ').map((cur) => Number(cur));\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(Math.max(...amt)),1);\nsum = amt.reduce((acc, c) => {\n return acc + c; \n \n} ,0);\n}\n\nprint(count);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdin = '';\n\nprocess.stdin.on('data', (input) => {\n stdin += input;\n});\n\nprocess.stdin.on('end', () => {\n const data = stdin.split('\\n');\n let totalSum = 0;\n\n const coins = stdin\n .split('\\n')[1]\n .split(' ')\n .map((coin) => {\n const num = Number(coin);\n totalSum += num;\n return num;\n })\n .sort((a, b) => a - b);\n\n let forBro = 0;\n let forBroCount = 0;\n\n for (const coin of coins) {\n forBro += coin;\n if (forBro < totalSum / 2) forBroCount++;\n else break;\n }\n\n process.stdout.write(String(coins.length - forBroCount));\n});"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet stdin = '';\n\nprocess.stdin.on('data', (input) => {\n stdin += input;\n});\n\nprocess.stdin.on('end', () => {\n const data = stdin.split('\\n');\n const len = Number(data[0]);\n let totalSum = 0;\n\n const coins = data[1]\n .split(' ')\n .map((coin) => {\n const num = Number(coin);\n totalSum += num;\n return num;\n })\n .sort((a, b) => a - b);\n\n let forBro = 0;\n let forBroCount = 0;\n\n for (const coin of coins) {\n forBro += coin;\n if (forBro < totalSum / 2) forBroCount++;\n else break;\n }\n\n process.stdout.write(String(len - forBroCount));\n});"}, {"source_code": "(function main() {\n //var s1 = readline().toLowerCase();\n //var s2 = readline().toLowerCase();\n var n = readline().split(' ').map(Number);\n var a = readline().split(' ').map(Number);\n\n for (var i = 0; i < n - 1; i++) {\n for (var j = i + 1; j < n; j++) {\n if (a[i] < a[j]) {\n var tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n }\n }\n var sum = 0, sumIn = 0;\n for (i = 0; i < n; i++) {\n sum += +a[i];\n }\n \n for (i = 0; i < n; i++){\n if (sumIn > sum) {\n print(i);\n return;\n }\n sumIn += a[i];\n sum -= a[i];\n }\n print(n);\n})()"}, {"source_code": "var n = parseInt(readline());\nvar coins = readline().split(' ').map(Number);\ncoins.sort(function(a, b){\n return b - a;\n});\nvar totalSum = coins.reduce(function(a,b){\n return a + b;\n});\nvar mySum = 0;\nvar counter = 0;\n\nwhile ((mySum <= (totalSum - mySum)) && (coins.length > 0)){\n mySum += coins[0];\n counter ++;\n coins.shift();\n}\nprint(counter);"}, {"source_code": "var coinNum = +readline();\nvar coins = readline().split(' ').map(function(v){return +v;}).sort(function(a, b){return b-a;});\nvar acc = 0;\nvar result = 0;\n\nvar total = 0;\n\nfor (var i=0; i total/2) {\n break;\n }\n acc += coins[i];\n result++;\n}\n\nprint(result);"}, {"source_code": "var limit = parseInt(readline());\nvar count = 0, mySum = 0;\nvar coins = readline().split(' ').map(x => parseInt(x));\nvar totalSum = coins.reduce((a,b) => a+b, 0);\ncoins.sort((a,b) => b - a);\nfor (var i = 0; i < limit; i++) {\n mySum += coins[i];\n count++;\n if (mySum > totalSum - mySum) break;\n}\nprint(count);\n"}], "negative_code": [{"source_code": "var nums = readline();\nvar coins = readline().split(\" \").map(Number).sort((a, b) => b - a);\nvar total = coins.reduce((acc, curr) => acc + curr, 0);\n\nvar my = 0;\nvar twin = total;\nvar count = 0;\n\nfor (var i = 0; i < coins.length - 1; i++) {\n my += coins[i];\n twin -= coins[i];\n count = i + 1;\n \n if (my > twin) {\n break;\n }\n}\n\nprint(count);"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\" \");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b)) / 2;\nfor( var i = 0 ; i < n ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > Math.ceil(sum)){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\ncoins.sort(function(a, b) {\n return a - b;\n});\n\nfor(var i = 0; i < coins.length; i++){\n total = total + parseInt(coins[i]);\n}\n\nprint(total);\n"}, {"source_code": "const readline = require('readline');\n\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n\n// Excute algorithm\nrl.on('close', () => {\n \n const numOfCoins = inputs[1].split(' ').length;\n const coinsValue = inputs[1].split(' ').sort((a, b) => b - a);\n const totalValue = inputs[1].split(' ').reduce((accum, c) => accum += parseInt(c), 0)\n const minVal = (totalValue / 2) + 1;\n let minNumOfCoins = 0;\n let myValue = 0;\n\n for (let i = 0; i < numOfCoins; i++) {\n\n console.log('myVal: ', myValue, ' minVal: ', minVal, ' NoOfCoins: ', minNumOfCoins)\n\n if (myValue < minVal) {\n myValue += parseInt(coinsValue[i])\n minNumOfCoins++\n } else {\n return console.log(minNumOfCoins)\n }\n }\n\n return console.log(minNumOfCoins)\n\n})"}, {"source_code": "var number=readline();\nvar coins=readline();\nvar array = coins.split(\" \").map(Number);\narray.sort(function(a, b){return a - b});\nvar sumCoins=0;\nvar result=0;\nfor( i=0;i=sumCoins-sumI) {\n\tresult=number-i+1\n return result\n}\nresult=1;\nreturn result\n}\n}\n\nprint(getResult())"}, {"source_code": "var numberOfCoin = 5,\n temp = \"2 2 2 2 4\",\n sum = 0 ,\n coins = temp.split(\" \").sort(),\n counter=coins[numberOfCoin-1];\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ');\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = Math.max(...amt);\namt.splice(amt.indexOf(max),1);\nsum = amt.reduce((acc, c) => {\n return acc + c\n},0);\n}\n\nprint(count);"}, {"source_code": "var numberOfCoin = 5,\n coins = \"2 2 2 2 4\",\n sum = 0, counter=coins[numberOfCoin-1];\n coins.split(\" \").sort();\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nprint(sum);"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\ncoins.sort(function(a, b) {\n return a - b;\n});\n\nfor(var i = 0; i < coins.length; i++){\n total = total + parseInt(coins[i]);\n}\n\nprint(total);\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main(){\n\n let coinCount =Number.parseInt( readline());\n let coins = readline().split(\" \").map( (item) => Number.parseInt(item));\n // desc\n coins = coins.sort();\n \n let picked = [];\n let notPicked = coins;\n while(true) {\n \n picked.push(notPicked.pop());\n \n let pickedSum = picked.reduce((a , b) => a + b, 0)\n let notPickedSum = notPicked.reduce((a,b) => a + b, 0);\n if(pickedSum > notPickedSum)\n {\n process.stdout.write(picked.length.toString());\n break;\n }\n\n \n }\n\n \n}"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n}\n\nfor (var i = 0, length = dataMas.length - 1; flag!==true; i++) {\n sum += dataMas[i];\n sum2 = 0;\n\n for (var j = i+1; i < length; i++) {\n sum2 += dataMas[j];\n }\n\n if (sum <= sum2) {\n answer += 1;\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ').map((cur) => Number(cur));\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\nprint('Initial sum :' + sum);\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(Math.max(...amt)),1);\nsum = amt.reduce((acc, c) => {\n return acc + c; \n \n} ,0);\nprint(max);\nprint(sum);\n}\n\nprint(count);"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(v){ return +v; });\na.sort(function(a, b){return a>b;});\nvar sum = a.reduce(function(a, b){ return a+b;}, 0);\nvar b=0;\nfor(var i=0; b<=sum; i++){\n\tb+=a[i];\n\tsum-=a[i];\n}\nprint(i);\n"}, {"source_code": "/* TEST CASE\ninput\n2\n3 3\noutput\n2\ninput\n3\n2 1 2\noutput\n2\n\nInput\n7\n1 10 1 2 1 1 1\nOutput\n2\nAnswer\n1\n\n\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar a = new Array(n);\n\tvar answer = 0;\n\tvar i;\n\tvar sum = 0;\n\tvar splitted = readline().split(' ');\n\t\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t\tsum += a[i]; \n\t}\n\tvar half = (sum >> 1);\n\tsum = 0;\n\ta.sort(function(v1, v2) {return v1 - v2;});\n\tprint(a);\n\tfor (i = n - 1; i >= 0 && sum <= half; i--) {\n\t\tsum += a[i];\n\t}\n\tanswer = n - 1 - i;\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n = Number(readline())\nvar arr = readline()\n\n\nfunction getCoins(n, arr) {\n arr = arr.split(' ').map(i => Number(i)).sort((a, b) => b - a ? -1 : 1)\n\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n var resultSum = result.reduce((a, b) => a + b, 0)\n if(resultSum > (sum / 2)) {\n return result.length\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "/* TEST CASE\ninput\n2\n3 3\noutput\n2\ninput\n3\n2 1 2\noutput\n2\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar a = new Array(n), g = new Array(n);\n\tvar answer = 0;\n\tvar i;\n\tvar sum = 0;\n\tvar splitted = readline().split(' ');\n\t\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t\tsum += a[i]; \n\t}\n\tvar half = (sum >> 1);\n\tsum = 0;\n\ta.sort();\n\tfor (i = n - 1; i >= 0 && sum <= half; i--) {\n\t\tsum += a[i];\n\t}\n\tanswer = n - 1 - i;\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var ln = +readline();\nvar coins = readline().split(' ').map(e => +e).sort((a, b) => a + b);\n\nfor (var i=0; i right) {\n write(String(i + 1) + '\\n');\n break;\n }\n}\n\n"}, {"source_code": "// Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.\n\n// Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1,\u2009a2,\u2009...,\u2009an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.\n\n// As you woke up, you found Mom's coins and read her note. \"But why split the money equally?\" \u2014 you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.\n\n// Input\n// The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the coins' values. All numbers are separated with spaces.\n\n// Output\n// In the single line print the single number \u2014 the minimum needed number of coins.\n\nvar n = readline()\nvar c = readline().split(\" \").sort().reverse()\nvar s = 0\n\nfunction add(a, b){\n return +a + +b;\n}\n\nfor (i=0; ic.reduce(add)-s){\n print(i+1);\n break;\n }\n}\n\n"}, {"source_code": "'use strict';\nlet _ = readline(),\n totalAmount = 0,\n outAmount = 0,\n array = readline().split(' ').map(function(value){ \n value = parseInt(value);\n totalAmount += value\n return value;\n }).sort().reverse();\n \nlet i = 0;\nfor(; totalAmount >= outAmount; i++){\n totalAmount -= array[i];\n outAmount += array[i];\n}\n\nwrite(i)"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main(){\n\n let coinCount =Number.parseInt( readline());\n let coins = readline().split(\" \").map( (item) => Number.parseInt(item));\n // desc\n coins = coins.sort();\n \n let picked = [];\n let notPicked = coins;\n while(true) {\n \n picked.push(notPicked.pop());\n \n let pickedSum = picked.reduce((a , b) => a + b, 0)\n let notPickedSum = notPicked.reduce((a,b) => a + b, 0);\n if(pickedSum > notPickedSum)\n {\n process.stdout.write(picked.length.toString());\n break;\n }\n\n \n }\n\n \n}"}, {"source_code": "'use strict';\nlet _ = readline(),\n totalAmount = 0,\n outAmount = 0,\n array = readline().split(' ').map(function(value){ \n value = parseInt(value);\n totalAmount += value\n return value;\n }).sort().reverse();\n \nlet i = 0;\nfor(; totalAmount >= outAmount; i++){\n totalAmount -= array[i];\n outAmount += array[i];\n}\n\nwrite(i)"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += dataMas[i];\n}\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n sum2 += dataMas[i];\n sum -= dataMas[i];\n\n if (sum2 < sum) {\n answer = answer + 1;\n }\n else {\n answer = answer + 1;\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "var n = readline();\nvar a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\nvar sum = a.reduce((x, y) => x + y, 0);\nvar x = Math.floor(sum / 2);\nvar final_sum = 0;\nvar count = 0;\nvar new_array= a.sort();\nvar new_arr = new_array.reverse();\nfor (var i = 0; i < n; i++) {\n final_sum += new_arr[i];\n count++;\n if (final_sum > x) {\n print(count);\n break;\n }\n}\n"}, {"source_code": "var n = Number(readline())\nvar arr = readline().split('').map(i => Number(i))\n\n\nfunction getCoins(n, arr) {\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n if(result.reduce((a, b) => a + b, 0) > (sum / 2)) {\n break\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n if (sum2 <= sum) {\n answer = answer + 1;\n }\n else {\n answer = answer + 1;\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "var monedas = +readline();\nvar valores = readline().split(\" \").map(function(v){return +v;}).sort(function(a,b) {return b-a;});\nvar suma = valores.reduce(function(a,b) {return a+b;},0);\nvar numMonedas = 0;\nvar contador = 0;\n \n \nfor (var j = 0; contador Number(i)).sort((a, b) => b - a ? 1 : -1)\n\n\nfunction getCoins(n, arr) {\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n var resultSum = result.reduce((a, b) => a + b, 0)\n if(resultSum > (sum / 2)) {\n break\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "readline();\nvar arr = readline().split(\" \");\narr.sort((a,b) => b - a);\nvar s1 = arr.reduce((a, b) => a + b) / 2;\nvar s2 = 0;\nfor (var i = 0; s2 <= s1 && i < arr.length; ++i) {\n s2 += arr[i];\n}\nprint(i);"}, {"source_code": "var n = Number(readline())\nvar arr = readline().split(' ').map(i => Number(i)).sort((a, b) => b - a ? 1 : -1)\n\n\nfunction getCoins(n, arr) {\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n var resultSum = result.reduce((a, b) => a + b, 0)\n if(resultSum > (sum / 2)) {\n break\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "readline();\nvar arr = readline().split(\" \");\narr.sort((a,b) => b - a);\nvar s1 = arr.reduce((a, b) => a + b) / 2;\nvar s2 = 0;\nfor (var i = 0; s1 <= s2; ++i) {\n s2 += arr[i];\n}\nprint(i);\n\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(v){ return +v; });\na.sort(function(a, b){return asum1)\n {\n sum2=sum2-c[s];\n sum1=sum1+c[s];\n s++;\n }\n else f=1;\n}\nprint(s);"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += dataMas[i];\n}\n\nfor (var i = 0, length = dataMas.length; !flag && i <= length; i++) {\n sum2 += dataMas[i];\n sum -= dataMas[i];\n\n if (sum2 <= sum) {\n answer = answer + 1;\n }\n else {\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// thats all what you have to write to get input from stdin, using readLine.\n\n\n// Main code runs in main();\n\n\nfunction main(){\n\n let coinCount =Number.parseInt( readline());\n let coins = readline().split(\" \").map( (item) => Number.parseInt(item));\n // desc\n coins = coins.sort();\n \n let picked = [];\n let notPicked = coins;\n while(true) {\n \n picked.push(notPicked.pop());\n console.log(notPicked);\n \n let pickedSum = picked.reduce((a , b) => a + b, 0)\n let notPickedSum = notPicked.reduce((a,b) => a + b, 0);\n if(pickedSum > notPickedSum)\n {\n process.stdout.write(picked.length.toString());\n break;\n }\n\n \n }\n\n \n}"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\"\");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b));\nfor( var i = 0 ; i < n - 1 ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > Math.ceil(sum/2)){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "var numberOfCoin = 5,\n temp = \"2 2 2 2 4\",\n sum = 0 ,\n coins = temp.split(\" \").sort(),\n counter=coins[numberOfCoin-1];\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns(s) {\n\treturn s.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumber(a,b) {\n\treturn a-n;\n}\n\nvar n = readn();\nvar ss = readline();\nvar a = readns(ss);\n\na = a.sort(sortNumber).reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nif (readline === \"4 2 2 2 2\") {\nprint(a);\n}\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\ncoins.sort(function(a, b) {\n return a - b;\n});\n\nfor(var i = 0; i <= coins.length; i++){\n total = total + coins[i];\n}\n\nprint(total);\n"}, {"source_code": "var number=readline();\nvar coins=readline();\nvar array = coins.split(\" \").map(Number);\narray.sort(function(a, b){return a - b});\nvar sumCoins=0;\nvar result=0;\nfor( i=0;i=sumCoins-sumI) {\n\tresult=number-i+1\n return result\n}\nelse {\nresult=1;\nreturn result\n}\n\n}\n}\n\nprint(getResult())"}, {"source_code": "var monedas = readline();\nvar valorMonedas = readline().split(\" \").sort().join();\nvar sumaTotal = 0;\nvar sumaParcial =0;\nvar cantidadMonedas = 0;\n\nfor (var i = 0; isumaTotal/2) {\n if (j%2 === 0) {\n cantidadMonedas = j;\n } else {\n cantidadMonedas = j+1;\n }\n }\n}\n\nprint(cantidadMonedas);\n"}, {"source_code": "var print = this.print || require(\"lol-io\").print;\nvar write = this.write || require(\"lol-io\").write;\nvar readline = this.readline || require(\"lol-io\").readline;\nvar n = readline();\nvar a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\nvar sum = a.reduce((x, y) => x + y, 0);\nvar x = Math.floor(sum / 2);\nvar final_sum = 0;\nvar count = 0;\nvar new_arr = a.sort().reverse();\nfor (var i = 0; i < n; i++) {\n final_sum += new_arr[i];\n count++;\n if (final_sum > x) {\n print(count);\n break;\n }\n}\n"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0, counter=coins[numberOfCoin-1];\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns() {\n\treturn readline().split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumber(a,b) {\n\treturn a-n;\n}\n\nvar n = readn();\nvar a = readns();\n\na = a.sort(sortNumber).reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\"\");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b));\nfor( var i = 0 ; i < n - 1 ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > Math.ceil(sum/2)){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns(s) {\n\treturn s.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumber(a,b) {\n\treturn a-n;\n}\n\nvar n = readn();\nvar ss = readline();\nvar a = readns(ss);\n\na = a.sort(sortNumber).reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nif (readline === \"4 2 2 2 2\") {\nprint(a);\n}\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var coinNum = +readline();\nvar coins = +readline().split(\" \");\nvar acc = 0;\nvar result = 0;\n\nvar total = 0;\n\nfor (var i=0; i total/2) {\n print(result);\n }\n acc += coins[i];\n result++;\n}\n"}, {"source_code": "var n = Number(readline())\nvar arr = readline()\n\nfunction sort(array) {\n var newArr = []\n\n while(array.length === newArr.length) {\n var max = Math.apply.max(null, array)\n newArr.push(max)\n array.splice(array.indexOf(max), 1)\n }\n\n return newArr\n}\n\nfunction getCoins(n, arr) {\n arr = sort(arr.split(' ').map(i => Number(i)))\n\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n var resultSum = result.reduce((a, b) => a + b, 0)\n if(resultSum > (sum / 2)) {\n return result.length\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ');\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(max),1);\nsum = amt.reduce((acc, c) => {\n return acc + c\n},0);\n}\n\nprint(count);"}, {"source_code": "var num = readline();\n//var coins = readline().split(\" \");\n\nvar coins = [5,4,3,5,8,3,1];\n\ncoins.sort(function(a, b) {\n return a - b;\n});\n\n\nprint(coins[0]);\nprint(coins[1]);\nprint(coins[2]);\nprint(coins[3]);\nprint(coins[4]);\nprint(coins[5]);\nprint(coins[6]);"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar counter=coins[numberOfCoin-1];\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += dataMas[i];\n}\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n sum2 += dataMas[i];\n sum -= dataMas[i];\n\n if (sum2 < sum) {\n answer = answer + 1;\n }\n else {\n flag = true;\n }\n}\n\nwrite(dataMas);"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0, counter=0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nprint(sum);"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns(s) {\n\treturn s.split(\" \").map(function(x) { return +x; });\n}\nfunction sortNumber(a,b) {\n\treturn a-n;\n}\n\nvar n = readn();\nvar ss = readline();\nvar a = readns(ss);\n\na = a.sort(sortNumber).reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nif (readline === \"4 2 2 2 2\") {\nprint(a);\n}\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0,\n counter=0;\nfor(var i =0; i < numberOfCoin; i++){\n sum+=coins[i];\n}\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter > Math.ceil(sum/2)){\n print(i);\n }\n else{\n counter+=coins[i];\n }\n}"}, {"source_code": "var n = readline();\nvar a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\nvar sum = a.reduce((x, y) => x + y, 0);\nvar x = Math.floor(sum / 2);\nvar final_sum = 0;\nvar count = 0;\nfor (var i = 0; i < n; i++) {\n final_sum += a[i];\n count++;\n if (final_sum > x) {\n print(count);\n break;\n }\n}\n"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\nfor (var i = 0, length = dataMas.length; !flag && i < length; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n if (sum2 <= sum) {\n answer = answer + 1;\n }\n else {\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "var n = readline();\nvar a = readline()\n .split(\" \")\n .map((a) => parseInt(a));\nvar sum = a.reduce((x, y) => x + y, 0);\nvar x = Math.floor(sum / 2);\nvar final_sum = 0;\nvar count = 0;\nvar new_array= a.sort();\nvar new_arr = new_array.reverse();\nfor (var i = 0; i < n; i++) {\n final_sum += new_arr[i];\n count++;\n if (final_sum > x) {\n print(count);\n break;\n }\n}\n"}, {"source_code": "var numberOfCoin = 5,\n temp = \"2 2 2 2 4\",\n sum = 0 ,\n coins = temp.split(\" \").sort(),\n counter=coins[numberOfCoin-1];\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nprint(sum);"}, {"source_code": "// Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.\n\n// Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1,\u2009a2,\u2009...,\u2009an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.\n\n// As you woke up, you found Mom's coins and read her note. \"But why split the money equally?\" \u2014 you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.\n\n// Input\n// The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the coins' values. All numbers are separated with spaces.\n\n// Output\n// In the single line print the single number \u2014 the minimum needed number of coins.\n\nvar n = readline()\nvar c = readline().split(\" \").sort().reverse()\nvar s = 0\n\nfunction add(a, b){\n return +a + +b;\n}\n\nfor (i=0; ic.reduce(add)-s){\n print(i+1);\n break;\n }\n}\n\n"}, {"source_code": "var n = readline();\nvar c = readline().split(\" \").sort(function(a, b) {\n return a - b;\n});\nc.reverse();\nvar f = 0;\nvar sum1=0;\nvar sum2=0;\nvar s=0;\nfor (i=0;isum1)\n {\n sum2=sum2-c[s];\n sum1=sum1+c[s];\n s++;\n }\n else f=1;\n}\nprint(s);"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ').map((cur) => Number(cur));\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(max),1);\nsum = amt.reduce((acc, c) => {\n return acc + c; \n \n} ,0);\n}\n\nprint(count);//"}, {"source_code": "readline();\ncoins = readline().split(' ').map(function(x) { return +x; }).sort().reverse();\nsum = coins.reduce(function(prev, x) { return prev + +x; });\ntaken = [];\nfor (var i = 0; i < coins.length && taken <= sum/2; ++i) {\n taken.push(coins[i]);\n}\nprint(taken.length);\n"}, {"source_code": "var n = parseInt(readline());\nvar f = function(num) {return parseInt(num);};\nvar line = readline().split(' ').map(f);\nvar hi = Math.floor(line.length / 2);\nvar hj = hi + 1;\nvar lr = 0;\nvar rl = 0;\nvar countLr = 0;\nvar countRl = 0;\nfor(var i = 0; i <= hi; i++){\n countLr += 1;\n lr += line[i];\n}\nfor(var i = line.length - 1; i >= hj; i--){\n countRl += 1;\n rl += line[i];\n}\nprint(lr > rl ? countLr : countRl);"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0, counter=0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nprint(sum);"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\ncoins.sort(function(a, b) {\n return a - b;\n});\n\nfor(var i = 0; i <= coins.length; i++){\n total = total + coins[i];\n}\n\nprint(total);\n"}, {"source_code": "var n = Number(readline())\nvar arr = readline().split('').map(i => Number(i))\n\n\nfunction getCoins(n, arr) {\n var result = []\n var sum = arr.reduce((a, b) => a + b, 0)\n \n for(var i of arr) {\n result.push(i)\n if(result.reduce((a, b) => a + b, 0) > (sum / 2)) {\n break\n }\n }\n \n return result.length\n}\n\nprint(getCoins(n, arr))\n\n\n\n"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns() {\n\treturn readline().split(\" \").map(function(x) { return +x; });\n}\n\nvar n = readn();\nvar a = readns();\n\na = a.sort().reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nif (a[0] === 10) {\nprint(999);\n}\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n if (sum2 <= sum) {\n answer = answer + 1;\n }\n else {\n answer = answer + 1;\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\" \");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b)) / 2;\nfor( var i = 0 ; i < n ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > Math.ceil(sum)){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort()\n sum = 0,\n counter=0;\nfor(var i =0; i < numberOfCoin; i++){\n sum+=coins[i];\n}\nwhile(numberOfCoin--){\n if(counter > Math.ceil(sum/2)){\n print(numberOfCoin)\n }\n else{\n counter+=coins[numberOfCoin];\n }\n}"}, {"source_code": "var number=readline();\nvar coins=readline();\nvar array = coins.split(\" \").map(Number);\narray.sort(function(a, b){return a - b});\nvar sumCoins=0;\nvar result=0;\nfor( i=0;i=sumCoins-sumI) {\n\tresult=number-i+1\n return result\n}\nelse {\nresult=1;\nreturn result\n}\n\n}\n\n}\n\nprint(getResult())"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet standardInputString = '';\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on('data', rawData=> {\n standardInputString += rawData;\n})\n\nprocess.stdin.on('end', _ => {\n standardInputString = standardInputString.trim().split('\\n').map(line=> {\n return line.trim();\n })\n main();\n})\n\nfunction main() {\n const coinsNumber = +(readLine());\n const coin = readLine().split(\" \").join(\"\");\n let sum = eval(coin.split(\"\").join(\"+\"));\n const minimum = sum / 2;\n let possible = 0;\n let count = 0;\n const sorted = Array.from(coin).sort();\n for(let i = sorted.length - 1; i >= 0; i--) {\n possible = possible + (1* sorted[i]);\n count++;\n if(possible > minimum) break;\n }\n console.log(count);\n}"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ').map((cur) => Number(cur));\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\nprint('Initial sum :' + sum);\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(Math.max(...amt)),1);\nsum = amt.reduce((acc, c) => {\n return acc + c; \n \n} ,0);\nprint(max);\nprint(sum);\n}\n\nprint(count);"}, {"source_code": "var quantity = readline();\nvar digits = readline().split(\" \").sort((a, b) => a - b);\n\nfunction sum(arr) {\n\treturn arr.reduce((sum, item) => sum += +item, 0);\n}\n\ndigits.reduce((result) => {\n\tif (result <= sum(digits)) {\n\t\tresult += +digits.pop();\n\t}\n\t\n\treturn result;\n}, 0);\n\nprint(quantity - digits.length);\n"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar counter=coins[numberOfCoin-1];\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "var numberOfCoin = 7,\n temp = \"1 10 1 2 1 1 1\",\n coins = temp.split(\" \").sort(),\n sum = 0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar counter=coins[numberOfCoin-1];\nvar i = numberOfCoin -1;\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n\n } \n"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0; sum2 <= sum; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n answer = answer + 1; \n}\n\nwrite(answer);\n"}, {"source_code": "var ln = +readline();\nvar coins = readline().split(' ').map(e => +e).sort((a, b) => a + b);\n\nfor (var i=0; i right) {\n write(String(i + 1) + '\\n');\n break;\n }\n}\n\n"}, {"source_code": "var coinsCount = readline();\nvar coinsArr = readline().split(' ').sort();\n\nvar maxSum = findArrSum(coinsArr);\n// print(maxSum);\n\nprint(findCoinsCount(coinsArr));\n\nfunction findCoinsCount(arr){\n \n var mySum = 0;\n var myCointCount = 0;\n \n for (var i = arr.length - 1; i > -1; i--){\n // print(arr[i]);\n mySum += Number(arr[i]);\n myCointCount++;\n var remaining = maxSum - mySum;\n \n if (mySum > remaining){\n return myCointCount;\n }\n }\n}\n\nfunction findArrSum(arr){\n var sum = 0;\n for (var j = 0; j < arr.length; j++){\n sum += Number(arr[j]);\n }\n return sum;\n}\n\n// function findArrSum(arr, indStart, indEnd){\n// var sum = 0;\n// for (var j = indStart; j < indEnd + 1; j++){\n// sum += Number(arr[j]);\n// }\n// return sum;\n// }"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ');\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(max),1);\nsum = amt.reduce((acc, c) => {\n return acc + c\n},0);\n}\n\nprint(count);"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n if (sum2 <= sum ) {\n answer = answer + 1; \n }\n else {\n flag = true;\n }\n\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n}\n\nwrite(answer);"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar counter=coins[numberOfCoin-1];\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n } \n else{ \n print(numberOfCoin-i); \n break;\n } \n}"}, {"source_code": "const readline = require('readline');\n\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Excute algorithm\nrl.on('close', () => {\n \n const numOfCoins = inputs[1].split(' ').length;\n const coinsValue = inputs[1].split(' ').sort((a, b) => b - a);\n const totalValue = inputs[1].split(' ').reduce((accum, c) => accum += parseInt(c), 0)\n const minVal = (totalValue / 2) + 1;\n let minNumOfCoins = 0;\n let myValue = 0;\n\n for (let i = 0; i < numOfCoins; i++) {\n\n console.log('myVal: ', myValue, ' minVal: ', minVal, ' NoOfCoins: ', minNumOfCoins)\n\n if (myValue < minVal) {\n myValue += parseInt(coinsValue[i])\n minNumOfCoins++\n } else {\n return console.log(minNumOfCoins)\n }\n }\n\n return console.log(minNumOfCoins)\n\n})"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n\n if (sum2 <= sum ) {\n answer = answer + 1; \n }\n else {\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "readline();\nvar nums = readNums();\nnums.sort();\nvar need = nums.reduce((a,b) => a+b) / 2;\nvar value = 0;\nfor (var i = nums.length - 1; i >= 0; i--) {\n value += nums[i];\n if (value > need) {\n break;\n }\n}\nprint(nums.length - i);\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}"}, {"source_code": "readline();\ncoins = readline().split(' ').map(function(x) { return +x; }).sort().reverse();\nsum = coins.reduce(function(prev, x) { return prev + +x; });\nntaken = 0, sumtaken = 0;\ntaken = 0\nfor (var i = 0; i < coins.length && sumtaken <= sum/2; ++i) {\n sumtaken += coins[i];\n ntaken++;\n}\nprint(ntaken);\n"}, {"source_code": "/* TEST CASE\ninput\n2\n3 3\noutput\n2\ninput\n3\n2 1 2\noutput\n2\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar a = new Array(n), g = new Array(n);\n\tvar answer = 0;\n\tvar i;\n\tvar sum = 0;\n\tvar splitted = readline().split(' ');\n\t\n\tfor (i = 0; i < n; i++) {\n\t\ta[i] = parseInt(splitted[i]);\n\t\tsum += a[i]; \n\t}\n\tvar half = (sum >> 1);\n\tsum = 0;\n\ta.sort();\n\tfor (i = n - 1; i >= 0 && sum <= half; i--) {\n\t\tsum += a[i];\n\t}\n\tanswer = n - 1 - i;\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var n=readline(); n=parseInt(n);\nvar arr=readline().split(' ').map(function(x){return parseInt(x) ; });\narr.sort(); var sum=0;\nfor( var i=0; i sum/2){print(i+1); num=0;}\n}"}, {"source_code": "n = parseInt(readline());\nk = readline().split(\" \");\nk = k.sort(function(a,b){return b - a});\nvar jam = 0;\nvar count = 0;\nsum = k.reduce((a, b) => parseInt(a) + parseInt(b)) / 2;\nfor( var i = 0 ; i < n ; i++){\n\tjam = jam + parseInt(k[i]);\n\tcount = count +1 ;\n\tif(jam > Math.ceil(sum)){break;}\n}\nprint(count);\n\t\n\n"}, {"source_code": "var s = Number(readline())\nvar res = 0\nvar j =readline().split(\" \")\nvar max = 0\n\nfunction sortNumber(a,b) {\n return a - b;\n}\nj.sort(sortNumber);\nj.reverse()\nprint(j)\n\nfor (var i = 0; i < s; i++) {\n \n var ab = j.slice(0, i + 1).reduce((a, b) => Number(a) + Number(b), 0)\n var bb = j.slice(i + 1, s + 1).reduce((a, b) => Number(a) + Number(b), 0)\n \n if(ab > bb) {\n res = i + 1\n break;\n } \n}\n\nprint(res)"}, {"source_code": "function main(){\n var n = +readline();\n var ms = readline().split(' ').sort((a,b) => +b - +a);\n var sum = ms.reduce((acc, ac) => acc + +ac, 0);\n var med = sum / 2;\n var res = 0;\n for(var i = 0; i < n; ++i){\n res += ms[i];\n if(res > med){\n break;\n }\n }\n print(i + 1);\n}\n\nmain();"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n\n sum += parseInt(dataMas[i]);\n}\n\n\nfor (var i = 0, length = dataMas.length; !flag; i++) {\n if (sum2 <= sum ) {\n answer = answer + 1; \n }\n else {\n answer = answer + 1;\n flag = true;\n }\n \n sum2 += parseInt(dataMas[i]);\n sum -= parseInt(dataMas[i]);\n}\n\nwrite(answer);"}, {"source_code": "var n = Number(readline());\nvar amt = readline().split(' ').map((cur) => Number(cur));\nvar max = 0;\nvar sum = amt.reduce((acc, c) => {\n return acc + c\n},0);\nvar count = 0;\n\nwhile(max <= sum){\ncount++;\nmax = max + Math.max(...amt);\namt.splice(amt.indexOf(max),1);\nsum = amt.reduce((acc, c) => {\n return acc + c; \n \n} ,0);\n}\n\nprint(count);"}, {"source_code": "var numberOfCoin = 5,\n temp = \"2 2 2 2 4\",\n sum = 0 ,\n coins = temp.split(\" \").sort(),\n counter=coins[numberOfCoin-1];\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nvar i = numberOfCoin -1;\n if(counter <= Math.ceil(sum/2)){ \n counter+=coins[i-1]; \n print(counter);\n } \n else{ \n print(numberOfCoin-i); \n } \n"}, {"source_code": "var dataCount = parseInt(readline()),\n dataMas = readline().split(\" \"),\n flag = false,\n answer = 0, sum = 0, sum2 = 0;\n\n// \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f\nfor (var i = 0, length = dataMas.length - 1; i < length; i++) {\n for (var j = i+1; j < dataMas.length; j++) {\n if (dataMas[i] < dataMas[j]) {\n var current = dataMas[i];\n dataMas[i] = dataMas[j];\n dataMas[j] = current;\n }\n }\n}\n\nfor (var i = 0, length = dataMas.length - 1; flag!==true; i++) {\n sum += i;\n sum2 = 0;\n\n for (var j = i; i < length; i++) {\n sum2 += dataMas[j];\n }\n\n if (sum > sum2) {\n answer += 1;\n flag = true;\n }\n}\n\nwrite(answer);"}, {"source_code": "var num = readline();\nvar coins = readline().split(\" \");\nvar total = 0;\ncoins.sort(function(a, b) {\n return a - b;\n});\n\nfor(var i = 0; i <= coins.length; i++){\n total = total + parseInt(coins[i]);\n}\n\nprint(total);\n"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns() {\n\treturn readline().split(\" \").map(function(x) { return +x; });\n}\n\nvar n = readn();\nvar a = readns();\n\na = a.sort().reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-9) {\n\t\tprint(i);\n\t\tbreak;\n\t}\n}"}, {"source_code": "function readn() {\n\treturn +readline();\n}\nfunction readns() {\n\treturn readline().split(\" \").map(function(x) { return +x; });\n}\n\nvar n = readn();\nvar a = readns();\n\na = a.sort().reverse();\n\nvar fullSum = a.reduce(function(prev, current){\n\treturn prev+current;\n});\n\nif (a[0] === 10) {\nprint(999);\n}\nvar sum1 = 0;\nfor (var i = 0; i < a.length; i++) {\n\tsum1 += a[i];\n\tif (sum1 > fullSum/2 + 1e-6) {\n\t\tprint(i+1);\n\t\tbreak;\n\t}\n}"}, {"source_code": "var numberOfCoin = +readline(),\n coins = readline().split(\" \").sort(),\n sum = 0, counter=0;\nfor(var i = 0; i < numberOfCoin; i++){\n coins[i]=+coins[i];\n sum+=coins[i];\n}\nfor(var i = numberOfCoin -1; i >=0; i--){\n if(counter <= Math.ceil(sum/2)){ \n print(i); \n } \n}"}, {"source_code": "var n = readline();\nvar c = readline().split(\" \").sort(function(a, b) {\n return a - b;\n});\nc.reverse();\nvar f = 0;\nvar sum1=0;\nvar sum2=0;\nvar s=0;\nfor (i=0;isum1)\n {\n sum2=sum2-c[s];\n sum1=sum1+c[s];\n s++;\n }\n else f=1;\n}\nprint(s);"}], "src_uid": "ee535e202b7662dbaa91e869c8c6cee1"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(read) {\r\n const rn = async () => Number(await read());\r\n const n = await rn();\r\n const s = await read();\r\n const N = 2 * n;\r\n const p = [...new Array(N).keys()];\r\n const find = i => i === p[i] ? i : p[i] = find(p[i]);\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const stack = [];\r\n for (let i = 0; i < N; i++) {\r\n if (s[i] === '(') {\r\n stack.push(i);\r\n } else if (s[i] === ')') {\r\n let j = stack.pop();\r\n union(j, i);\r\n if (j + 1 < i - 1) union(j + 1, i - 1);\r\n if (!stack.length) union(0, i);else {\r\n const j = stack[stack.length - 1] + 1;\r\n union(j, i);\r\n }\r\n }\r\n }\r\n const root = new Set();\r\n for (let i = 0; i < N; i++) {\r\n root.add(find(i));\r\n }\r\n return root.size;\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": ";\nvar inp = [];\nvar out = [];\nvar lines;\nvar lineCounter = 0;\nvar readline = function () { return lines[lineCounter++]; };\nvar writeline = function (line) { return out.push(String(line)); };\nprocess.stdin.on('data', function (c) { return inp.push(c); });\nprocess.stdin.on('end', function () {\n lines = inp.join('').split('\\n');\n myMain();\n console.log(out.join('\\n'));\n});\nvar DSU = /** @class */ (function () {\n function DSU(sz) {\n this.par = Array.from({ length: sz }, function (id) { return -1; });\n this.compCnt = sz;\n }\n DSU.prototype.findset = function (u) {\n var p = u;\n while (this.par[p] >= 0) {\n p = this.par[p];\n }\n while (this.par[u] >= 0) {\n var tmp = this.par[u];\n this.par[u] = p;\n u = tmp;\n }\n return p;\n };\n DSU.prototype.join = function (u, v) {\n var _a;\n u = this.findset(u);\n v = this.findset(v);\n if (u === v)\n return;\n if (-this.par[u] < -this.par[v]) {\n _a = [v, u], u = _a[0], v = _a[1];\n }\n this.par[u] += this.par[v];\n this.par[v] = u;\n --this.compCnt;\n };\n return DSU;\n}());\nfunction myMain() {\n var ntest = +readline();\n for (var testcase = 0; testcase < ntest; ++testcase) {\n var n = +readline();\n var s = readline().trim();\n var dsu = new DSU(2 * n);\n var stk = [];\n for (var i = 0; i < 2 * n; ++i) {\n if (s[i] === '(') {\n stk.push(i);\n }\n else {\n dsu.join(stk.pop(), i);\n if (i + 1 < 2 * n && s[i + 1] === '(') {\n dsu.join(i, i + 1);\n }\n }\n }\n writeline(dsu.compCnt);\n }\n}\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = stringArr();\r\n let cnt = 0,\r\n ans = 1,\r\n prev;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] === \"(\") {\r\n if (cnt === 0) cnt++;\r\n else if (cnt !== 0 && prev === \")\") cnt++;\r\n else {\r\n cnt++;\r\n ans++;\r\n }\r\n } else {\r\n cnt--;\r\n }\r\n prev = arr[i];\r\n }\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\"\");\r\n let v = {},o = 0,c = 0;\r\n for(let i=0;i Number(await read());\r\n const n = await rn();\r\n const s = await read();\r\n const N = 2 * n;\r\n const stack = [];\r\n const p = [...new Array(N).keys()];\r\n const find = i => i === p[i] ? i : p[i] = find(p[i]);\r\n const union = (i, j) => {\r\n const ri = find(i),\r\n rj = find(j);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] === '(') {\r\n stack.push(i);\r\n } else if (s[i] === ')') {\r\n let j = stack.pop();\r\n union(j, i);\r\n if (j + 1 < i - 1) union(j + 1, i - 1);\r\n if (!stack.length) union(0, i);\r\n }\r\n }\r\n const root = new Set();\r\n for (let i = 0; i < N; i++) {\r\n root.add(find(i));\r\n }\r\n return root.size;\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "6280a3373ab8fc34bb41fd98648019a6"} {"source_code": "var inp = readline().split(\" \");\nvar x1 = parseInt(inp[0]);\nvar y1 = parseInt(inp[1]);\nvar x2 = parseInt(inp[2]);\nvar y2 = parseInt(inp[3]);\n\nvar x3,y3,x4,y4,a, fail=0;\n\nif(x1 == x2)\n{\n a = y1-y2;\n\n x3 = x1+a;\n x4 = x2+a;\n\n y3 = y1;\n y4 = y2;\n}\nelse if(y1 == y2)\n{\n a = x1-x2;\n\n y3 = y1+a;\n y4 = y2+a;\n\n x3 = x1;\n x4 = x2;\n}\nelse\n{\n x3 = x1;\n y3 = y2;\n\n x4 = x2;\n y4 = y1;\n\n a = y3-y4;\n\n if((a != x3-x4) && (a != x4-x3)) fail = 1;\n\n}\n\nif(fail == 1) print(-1);\nelse print(x3+\" \"+y3+\" \"+x4+\" \"+y4);\n\n\n", "positive_code": [{"source_code": "//var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar numbers = readline().split(' ').map(function(x) { return parseInt(x); });\n\nbuildByPoints(numbers);\n\nfunction buildByPoints(numbers) {\n var x1 = numbers[0],\n y1 = numbers[1],\n x2 = numbers[2],\n y2 = numbers[3];\n\n var answ = [];\n var lenght = Math.abs(x1 - x2 || y1 - y2);\n if (x1 === x2) {\n answ.push(x1 + lenght, y1, x1 + lenght, y2);\n } else if (y1 === y2) {\n answ.push(x1, y1 + lenght, x2, y2 + lenght);\n } else {\n var d1 = Math.abs(y2 - y1);\n var d2 = Math.abs(x2 - x1);\n if (d1 !== d2) {\n print(-1);\n return;\n } else {\n answ.push(x1, y2, x2, y1);\n }\n }\n print(answ.join(' '));\n}"}, {"source_code": "T=readline().split(' ').map(x=>+x)\nx1=T[0],y1=T[1],x2=T[2],y2=T[3]\nd=[Math.abs(x2-x1),Math.abs(y2-y1)]\nif (x1==x2) {\n print(`${x1+d[1]} ${y1} ${x1+d[1]} ${y2}`)\n} else if (y1==y2) {\n print(`${x1} ${y1+d[0]} ${x2} ${y1+d[0]}`)\n} else {\n if (d[0]!==d[1]) print(-1)\n else {\n var p=[\n [Math.min(x1,x2),Math.min(y1,y2)],\n [Math.min(x1,x2),Math.max(y1,y2)],\n [Math.max(x1,x2),Math.min(y1,y2)],\n [Math.max(x1,x2),Math.max(y1,y2)],\n ]\n p=p.filter(t => (t[0]-x1+t[1]-y1)&&(t[0]-x2+t[1]-y2))\n print([].concat(p[0],p[1],p[2],p[4]).join(' '))\n }\n}"}, {"source_code": "function main()\t{\n\t\t\tvar cor = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/);\n\n\t\t\tcor = cor.map(function(val)\t{\n\t\t\t\treturn parseInt(val);\n\t\t\t});\n\n\t\t\tvar x1 = cor[0], y1 = cor[1],\n\t\t\t\tx2 = cor[2], y2 = cor[3];\n\n\t\t\tvar eCors = getExtCor(x1, y1, x2, y2);\n\n\t\t\tvar x3 = eCors[0].x, y3 = eCors[0].y,\n\t\t\t\tx4 = eCors[1].x, y4 = eCors[1].y;\n\n\t\t\tif(!isSquare([x1, x2, x3, x4],[y1, y2, y3, y4]))\tprint(-1);\n\t\t\telse\tprint(x3 + ' ' + y3 + ' ' + x4 + ' ' + y4 + ' ');\n\t\t};\n\n\t\tfunction isSquare(xArr, yArr)\t{\n\t\t\tvar width, height;\n\n\t\t\tfor(var i=1; i<4; i++)\t{\n\t\t\t\twidth = xArr[0] - xArr[i] == 0 ? width : Math.abs(xArr[0] - xArr[i]);\n\t\t\t\theight = yArr[0] - yArr[i] == 0 ? height : Math.abs(yArr[0] - yArr[i]);\n\t\t\t}\n\n\t\t\treturn width == height ? true : false;\n\t\t};\n\n\t\tfunction getExtCor(x1, y1, x2, y2)\t{\n\t\t\tvar eCor1 = { 'x' : 0, 'y' : 0 },\n\t\t\t\teCor2 = { 'x' : 0, 'y' : 0 };\n\n\t\t\tif(Math.abs(x2 - x1) == Math.abs(y2 - y1))\t{\n\t\t\t\teCor1.x = x1;\n\t\t\t\teCor1.y = y2;\n\n\t\t\t\teCor2.x = x2;\n\t\t\t\teCor2.y = y1;\n\t\t\t} else\t{\n\t\t\t\tvar width = Math.abs(x2 - x1),\n\t\t\t\t\theight = Math.abs(y2 - y1);\n\n\t\t\t\tif(width == 0)\twidth = height;\n\t\t\t\tif(height == 0)\theight = width;\n\n\t\t\t\t// console.log(width, height);\n\n\t\t\t\tif(x2 == x1)\t{\n\t\t\t\t\teCor1.x = x1 + width;\n\t\t\t\t\teCor1.y = y1;\n\n\t\t\t\t\teCor2.x = x2 + width;\n\t\t\t\t\teCor2.y = y2;\n\t\t\t\t} else if(y2 == y1)\t{\n\t\t\t\t\teCor1.x = x1;\n\t\t\t\t\teCor1.y = y1 + height;\n\n\t\t\t\t\teCor2.x = x2;\n\t\t\t\t\teCor2.y = y2 + height;\n\t\t\t\t} else\t{\n\t\t\t\t\teCor1.x = x1;\n\t\t\t\t\teCor1.y = y2;\n\n\t\t\t\t\teCor2.x = x2;\n\t\t\t\t\teCor2.y = y1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// console.log(JSON.stringify([ eCor1, eCor2 ]));\n\n\t\t\treturn [ eCor1, eCor2 ];\n\t\t};\n\n\t\tmain();"}, {"source_code": "var input = readline().split(\" \"), x1 = +input[0], y1 = +input[1], x2 = +input[2], y2 = +input[3], x3, y3, x4, y4;\n\nif( (Math.abs(x1-x2) == 0) && (Math.abs(y1-y2) != 0) ){\n\tx3 = x1 + Math.abs(y1-y2);\n\ty3 = Math.max(y1,y2);\n\tx4 = x3;\n\ty4 = Math.min(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(y1-y2) == 0) && (Math.abs(x1-x2) != 0) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = y1 + Math.abs(x1-x2);\n\tx4 = Math.max(x1,x2);\n\ty4 = y3;\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(x1-x2) != 0) && (Math.abs(y1-y2) != 0) && (Math.abs(x1-x2) == Math.abs(y1-y2)) && (((x2 > x1) && (y2 > y1)) || ((x2 < x1) && (y2 < y1))) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = Math.max(y1,y2);\n\tx4 = Math.max(x1,x2);\n\ty4 = Math.min(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(x1-x2) != 0) && (Math.abs(y1-y2) != 0) && (Math.abs(x1-x2) == Math.abs(y1-y2)) && (((x2 > x1) && (y2 < y1)) || ((x2 < x1) && (y2 > y1))) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = Math.min(y1,y2);\n\tx4 = Math.max(x1,x2);\n\ty4 = Math.max(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse{\n\twrite(-1);\n}"}, {"source_code": "var s=readline().split(\" \");\n\tvar x1=parseInt(s[0]),y1=parseInt(s[1]),x2=parseInt(s[2]),y2=parseInt(s[3]);\n\tvar dif=0;\n\t if(Math.abs(y1-y2)===Math.abs(x1-x2)){\n\t\tprint((x1)+\" \"+(y2)+\" \"+(x2)+\" \"+(y1));\n\t}\n\telse if(x1===x2&&y1!==y2){\n\t\tdif=Math.abs(y1-y2);\n\t\tprint((x1+dif)+\" \"+(y1)+\" \"+(x2+dif)+\" \"+(y2));\n\t}\n\telse if(y1===y2&&x1!==x2){\n\t\tdif=Math.abs(x1-x2);\n\t\tprint((x1)+\" \"+(y1+dif)+\" \"+(x2)+\" \"+(y2+dif));\n\t}\n\t\n\telse{print(\"-1\");}"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = Math.abs((b[1] - a[1]) / (b[0] - a[0]));\n // console.log(\"The slope is : \", m)\n\n if (b[0] - a[0] === 0) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n }\n else if (b[1] - a[1] === 0) {\n d = Math.abs(b[0] - a[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else if (m == 1) {\n d = b[1] - a[1]\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n } else {\n return console.log(-1);\n }\n return console.log(...e, ...c);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = Math.abs((b[1] - a[1]) / (b[0] - a[0]));\n // console.log(\"The slope is : \", m)\n\n if (m == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n }\n else if (m === 0) {\n d = Math.abs(b[0] - a[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else if (m == 1) {\n d = b[1] - a[1]\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n } else {\n return console.log(-1);\n }\n return console.log(...e, ...c);\n\n});"}, {"source_code": ";(function () {\n\n\tvar l = readline().split(' ');\n\tprint(function(p1, p2) {\n\t\tif (p1.x === p2.x) {\n\t\t\tvar d = Math.abs(p1.y - p2.y);\n\t\t\treturn [p1.x + d, p1.y, p2.x + d, p2.y].join(' ');\n\t\t} else if (p1.y === p2.y) {\n\t\t\tvar d = Math.abs(p1.x - p2.x);\n\t\t\treturn [p1.x, p1.y + d, p2.x, p2.y + d].join(' ');\n\t\t\treturn 2;\n\t\t} else if (Math.abs(p1.x - p2.x) === Math.abs(p1.y - p2.y) && p1.x !== p2.x && p1.y !== p2.y) {\n\t\t\treturn [p1.x, p2.y, p2.x, p1.y].join(' ');\n\t\t\treturn 3;\n\t\t} else return -1;\n\t}({x: +l[0], y: +l[1]}, {x: +l[2], y: +l[3]}));\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tx1 = data[0], y1 = data[1],\n\t\tx2 = data[2], y2 = data[3];\n\tif (x1 == x2) {\n\t\tvar s = y2 - y1,\n\t\t\tx3 = x1 + s, y3 = y1,\n\t\t\tx4 = x3, y4 = y2;\n\t} else if (y1 == y2) {\n\t\tvar s = x2 - x1,\n\t\t\tx3 = x1, y3 = y1 + s,\n\t\t\tx4 = x2, y4 = y3;\n\t} else {\n\t\tvar s = Math.abs(x2 - x1);\n\t\tif (s == Math.abs(y2 - y1)) {\n\t\t\tvar x3 = x1, y3 = y2,\n\t\t\t\tx4 = x2, y4 = y1;\n\t\t} else {\n\t\t\tprint(-1);\n\t\t\treturn;\n\t\t}\n\t}\n\tprint(x3, y3, x4, y4);\n}\n\nmain();\n"}, {"source_code": "print(function(x1, y1, x2, y2) {\n if (x1 != x2 && y1 != y2) {\n if (Math.abs(x1 - x2) != Math.abs(y1 - y2)) {\n return -1;\n } else {\n return [x1, y2, x2, y1].join(\" \");\n }\n } else {\n return [\n x1 == x2 ? x1 + Math.abs(y1 - y2) : x1,\n y1 == y2 ? y1 + Math.abs(x1 - x2) : y1,\n x1 == x2 ? x1 + Math.abs(y1 - y2) : x2,\n y1 == y2 ? y1 + Math.abs(x1 - x2) : y2,\n ].join(\" \");\n }\n}.apply(null, readline().split(\" \").map(Number)));\n"}, {"source_code": "print(function(x1, y1, x2, y2) {\n if (x1 != x2 && y1 != y2) {\n if (Math.abs(x1 - x2) != Math.abs(y1 - y2)) {\n return -1\n } else {\n return [x1, y2, x2, y1].join(\" \")\n }\n } else {\n return [\n x1 == x2 ? x1 + Math.abs(y1 - y2) : x1,\n y1 == y2 ? y1 + Math.abs(x1 - x2) : y1,\n x1 == x2 ? x1 + Math.abs(y1 - y2) : x2,\n y1 == y2 ? y1 + Math.abs(x1 - x2) : y2,\n ].join(\" \")\n }\n}.apply(null, readline().split(\" \").map(Number)));\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const firstTwo = inputLine.split(' ').map(num => parseInt(num));\n const A = firstTwo.slice(0, 2);\n const B = firstTwo.slice(2, 4);\n let d = Math.sqrt(Math.pow(B[0] - A[0], 2) + Math.pow(B[1] - A[1], 2));\n\n // if the two ponits are placed diagonally\n if (A[0] - B[0] != 0 && A[1] - B[1] != 0)\n d = d / Math.sqrt(2);\n\n if (A[0] - B[0] == 0)\n return console.log(A[0] + d, A[1], B[0] + d, B[1])\n else if (A[1] - B[1] == 0)\n return console.log(A[0], A[1] + d, B[0], B[1] + d)\n else if ((A[0] - B[0]) / (A[1] - B[1]) == 1)\n return console.log(A[0], A[1] + d, B[0], B[1] - d)\n else if ((A[0] - B[0]) / (A[1] - B[1]) == -1)\n return console.log(A[0], A[1] - d, B[0], B[1] + d)\n\n return console.log(-1)\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = (b[1] - a[1]) / (b[0] - a[0]);\n if (m > 1 && m !== Infinity) {\n return console.log(-1);\n } else if (Math.abs(m) == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n } else if (m == 0) {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[0] - b[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else if (m == 1) {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[1] - b[1]);\n c.push(a[0], a[1] - d);\n e.push(b[0], b[1] + d);\n } else {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[1] - b[1]);\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n }\n\n return console.log(...e, ...c);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = (b[1] - a[1]) / (b[0] - a[0]);\n if (m > 1 && m !== Infinity) {\n return console.log(-1);\n } else if (Math.abs(m) == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n } else if (m === 0) {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[0] - b[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else if (Math.abs(m)/1 === 1) {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[1] - b[1]);\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n }\n\n return console.log(...e, ...c);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = (b[1] - a[1]) / (b[0] - a[0]);\n if (m > 1 && m !== Infinity) {\n return console.log(-1);\n } else if (Math.abs(m) == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n } else if (m === 0) {\n // console.log(\"The slope is : \", m)\n d = Math.abs(b[0] - a[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else if (m == 1) {\n // console.log(\"The slope is : \", m)\n d = b[1] - a[1];\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n } else {\n // console.log(\"The slope is : \", m)\n d = b[1] - a[1]\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n }\n\n return console.log(...e, ...c);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = Math.abs((b[1] - a[1]) / (b[0] - a[0]));\n if (m > 1 && m !== Infinity) {\n return console.log(-1);\n } else if (m == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n } else if (m === 0) {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[0] - b[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else {\n // console.log(\"The slop is : \", m)\n d = Math.abs(a[1] - b[1]);\n c.push(a[0], a[1] - d);\n e.push(b[0], b[1] + d);\n }\n\n return console.log(...e, ...c);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n let firstTwoPoints = inputLine.split(' ').map(num => parseInt(num));\n let length = firstTwoPoints.length;\n let points = [];\n\n for (let i = 0; i < length / 2; i++) {\n points.push(firstTwoPoints.splice(0, 2));\n }\n\n const a = points[0];\n const b = points[1];\n\n const l1 = Math.sqrt(Math.pow(b[0] - a[0], 2) + Math.pow(b[1] - a[1], 2))\n let c, d;\n\n if (isInt(l1)) {\n d = [b[0] + b[1], b[1]];\n c = [d[0], d[1] - b[1]];\n const l2 = Math.sqrt(Math.pow(d[0] - b[0], 2) + Math.pow(d[1] - b[1], 2))\n if (l2 != l1) {\n return console.log(-1)\n }\n } else {\n d = [a[0] + b[0], a[1]];\n c = [a[0], a[1] + b[1]];\n const l1 = Math.sqrt(Math.pow(b[0] - d[0], 2) + Math.pow(b[1] - d[1], 2))\n const l2 = Math.sqrt(Math.pow(b[0] - c[0], 2) + Math.pow(b[1] - c[1], 2))\n if (l2 != l1) {\n return console.log(-1)\n }\n }\n\n console.log(...c, ...d)\n\n});\n\n\nfunction isInt(n) {\n return (typeof n == 'number' && n % 1 == 0);\n}\n\n\n"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const firstTwo = inputLine.split(' ').map(num => parseInt(num));\n const A = firstTwo.slice(0, 2);\n const B = firstTwo.slice(2, 4);\n let d = Math.sqrt(Math.pow(B[0] - A[0], 2) + Math.pow(B[1] - A[1], 2));\n\n // if the two ponits are placed diagonally\n if (A[0] - B[0] !== 0 && A[1] - B[1] !== 0)\n d = d / Math.sqrt(2);\n\n if (A[0] - B[0] === 0)\n return console.log(A[0] + d, A[1], B[0] + d, B[1]);\n else if (A[1] - B[1] === 0)\n return console.log(A[0], A[1] + d, B[0], B[1] + d);\n else if ((A[0] - B[0]) / (A[1] - B[1]) == 1)\n return console.log(A[0], A[1] - d, B[0], B[1] + d);\n else if ((A[0] - B[0]) / (A[1] - B[1]) == -1)\n return console.log(A[0], A[1] - d, B[0], B[1] + d);\n\n return console.log(-1);\n\n});"}, {"source_code": "const readline = require('readline');\n\nlet inputs = [];\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n// Read Inputs\nrl.on('line', inputLine => {\n const a = [], b = [];\n const c = [], e = [];\n let m = 0;\n let d = 0;\n inputLine.split(' ').forEach((number, i) => i > 1 ? a.push(parseInt(number)) : b.push(parseInt(number)));\n\n m = Math.abs((b[1] - a[1]) / (b[0] - a[0]));\n // console.log(\"The slope is : \", m)\n\n if (m == Infinity) {\n d = Math.abs(b[1] - a[1]);\n c.push(a[0] + d, a[1]);\n e.push(b[0] + d, b[1]);\n } else if (m > 1) {\n return console.log(-1);\n }\n else if (m == 0) {\n d = Math.abs(b[0] - a[0]);\n c.push(b[0], b[1] + d);\n e.push(a[0], a[1] + d);\n } else {\n d = b[1] - a[1]\n c.push(a[0], a[1] + d);\n e.push(b[0], b[1] - d);\n }\n return console.log(...e, ...c);\n\n});"}, {"source_code": "var input = readline().split(\" \"), x1 = +input[0], y1 = +input[1], x2 = +input[2], y2 = +input[3], x3, y3, x4, y4;\n\nif( (Math.abs(x1-x2) == 0) && (Math.abs(y1-y2) != 0) ){\n\tx3 = x1 + Math.abs(y1-y2);\n\ty3 = Math.max(y1,y2);\n\tx4 = x3;\n\ty4 = Math.min(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(y1-y2) == 0) && (Math.abs(x1-x2) != 0) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = y1 + Math.abs(x1-x2);\n\tx4 = Math.max(x1,x2);\n\ty4 = y3;\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(x1-x2) != 0) && (Math.abs(y1-y2) != 0) && (Math.abs(x1-x2) == Math.abs(y1-y2)) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = Math.max(y1,y2);\n\tx4 = Math.max(x1,x2);\n\ty4 = Math.min(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse{\n\twrite(-1);\n}"}, {"source_code": "var input = readline().split(\" \"), x1 = +input[0], y1 = +input[1], x2 = +input[2], y2 = +input[3], x3, y3, x4, y4;\n\nif( (Math.abs(x1-x2) == 0) && (Math.abs(y1-y2) != 0) ){\n\tx3 = x1 + Math.abs(y1-y2);\n\ty3 = Math.max(y1,y2);\n\tx4 = x3;\n\ty4 = Math.min(y1,y2);\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(y1-y2) == 0) && (Math.abs(x1-x2) != 0) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = y1 + Math.abs(x1-x2);\n\tx4 = Math.max(x1,x2);\n\ty4 = y3;\n\twrite(x3 + \" \" + y3 + \" \" + x4 + \" \" + y4);\n}\nelse if( (Math.abs(x1-x2) != 0) && (Math.abs(y1-y2) != 0) && (Math.abs(x1-x2) == Math.abs(y1-y2)) ){\n\tx3 = Math.min(x1,x2);\n\ty3 = Math.max(y1,y2);\n\tx4 = Math.max(x1,x2);\n\ty4 = Math.min(y1,y2);\n\twrite(x4 + \" \" + y4 + \" \" + x3 + \" \" + y3);\n}\nelse{\n\twrite(-1);\n}"}, {"source_code": "var s=readline().split(\" \");\n\tvar x1=parseInt(s[0]),y1=parseInt(s[1]),x2=parseInt(s[2]),y2=parseInt(s[3]);\n\tvar dif=0;\n\tif(x1===x2&&y1!==y2){\n\t\tdif=Math.abs(y1-y2);\n\t\tprint((x1+dif)+\" \"+(y1)+\" \"+(x2+dif)+\" \"+(y2));\n\t}\n\telse if(y1===y2&&x1!==x2){\n\t\tdif=Math.abs(x1-x2);\n\t\tprint((y1+dif)+\" \"+(x1)+\" \"+(y2+dif)+\" \"+(x2));\n\t}\n\telse if(Math.abs(y1-y2)===Math.abs(x1-x2)){\n\t\tprint(x1+\" \"+y2+\" \"+x2+\" \"+y1);\n\t}\n\telse{print(\"-1\");}"}, {"source_code": "var inp = readline().split(\" \");\nvar x1 = parseInt(inp[0]);\nvar y1 = parseInt(inp[1]);\nvar x2 = parseInt(inp[2]);\nvar y2 = parseInt(inp[3]);\n\nvar x3,y3,x4,y4,a;\n\nif(x1 == x2)\n{\n a = y1-y2;\n\n x3 = x1+a;\n x4 = x2+a;\n\n y3 = y1;\n y4 = y2;\n}\nelse if(y1 == y2)\n{\n a = x1-x2;\n\n y3 = y1+a;\n y4 = y2+a;\n\n x3 = x1;\n x4 = x2;\n}\n\nprint(x3+\" \"+y3+\" \"+x4+\" \"+y4);\n\n\n"}, {"source_code": "var inp = readline().split(\" \");\nvar x1 = parseInt(inp[0]);\nvar y1 = parseInt(inp[1]);\nvar x2 = parseInt(inp[2]);\nvar y2 = parseInt(inp[3]);\n\nvar x3,y3,x4,y4,a;\n\nif(x1 == x2)\n{\n a = y1-y2;\n\n x3 = x3+a;\n x4 = x4+a;\n\n y3 = y1;\n y4 = y2;\n}\nelse if(y1 == y2)\n{\n a = x1-x2;\n\n y3 = y3+a;\n y4 = y4+a;\n\n x3 = x1;\n x4 = x2;\n}\n\nprint(x3+\" \"+y3+\" \"+x4+\" \"+y4);\n\n\n"}, {"source_code": "var numbers = readline().split(' ').map(function(x) { return parseInt(x); });\nvar uniq = [];\nfor (var i = 0; i < 4; ++i) {\n if (uniq.indexOf(numbers[i]) === -1) {\n uniq.push(Math.abs(numbers[i]));\n }\n}\n\nif (uniq.length === 2) {\n var x1 = numbers[0],\n y1 = numbers[1],\n x2 = numbers[2],\n y2 = numbers[3];\n\n var answ = [];\n var lenght = Math.abs(x1 - x2 || y1 - y2);\n if (x1 === y1 && x2 === y2) {\n answ.push(x1,x2,x2,x1);\n } else if (x1 === y1) {\n answ.push(y2, x2, x1 + lenght, x1 + lenght);\n } else if (x2 === y2) {\n answ.push(y1, x1, x2 + lenght, x2 + lenght);\n } else {\n answ.push(x1, x1, y1, y1);\n }\n print(answ.join(' '));\n} else {\n print(-1)\n}"}, {"source_code": "//var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar numbers = readline().split(' ').map(function(x) { return parseInt(x); });\nvar uniq = [];\nfor (var i = 0; i < 4; ++i) {\n if (uniq.indexOf(numbers[i]) === -1) {\n uniq.push(Math.abs(numbers[i]));\n }\n}\n\nif (uniq.length === 2) {\n var x1 = numbers[0],\n y1 = numbers[1],\n x2 = numbers[2],\n y2 = numbers[3];\n\n var answ = [];\n var lenght = Math.abs(x1 - x2 || y1 - y2);\n var xDif = Math.abs(x1) - Math.abs(x2);\n var yDif = Math.abs(y1) - Math.abs(y2);\n if (x1 === y1 && x2 === y2) {\n answ.push(x1,x2,x2,x1);\n } else if (x1 === y1) {\n answ.push(y2, x2, x1 + lenght, x1 + lenght);\n } else if (x2 === y2) {\n answ.push(y1, x1, x2 + lenght, x2 + lenght);\n } else if (x1 !== 0 && xDif == 0) {\n var sum = Math.abs(x1) + Math.abs(x2);\n answ.push(sum, x1, sum, x2);\n } else if (y1 !== 0 && yDif == 0) {\n var sum = Math.abs(y1) + Math.abs(y2);\n answ.push(sum, y1, sum, y2);\n } else {\n answ.push(x1, x1, y1, y1);\n }\n print(answ.join(' '));\n} else {\n print(-1)\n}"}, {"source_code": "var numbers = readline().split(' ').map(function(x) { return parseInt(x); });\nvar uniq = [];\nfor (var i = 0; i < 4; ++i) {\n if (uniq.indexOf(numbers[i]) === -1) {\n uniq.push(numbers[i]);\n }\n}\n\nif (uniq.length === 2) {\n var x1 = numbers[0],\n y1 = numbers[1],\n x2 = numbers[2],\n y2 = numbers[3];\n\n var answ = [];\n var lenght = Math.abs(x1 - x2 || y1 - y2);\n if (x1 === y1 && x2 === y2) {\n answ.push(x1,x2,x2,x1);\n } else if (x1 === y1) {\n answ.push(y2, x2, x1 + lenght, x1 + lenght);\n } else if (x2 === y2) {\n answ.push(y1, x1, x2 + lenght, x2 + lenght);\n } else {\n answ.push(x1, x1, y1, y1);\n }\n print(answ.join(' '));\n} else {\n print(-1)\n}"}, {"source_code": "T=readline().split(' ').map(x=>+x)\nX=[T[0],T[2]],Y=[T[1],T[3]]\nR=''\nfor (var i=0;i<2;++i)\n for (var j=0;j<2;++j)\n if (!((X[i]==T[0]&&Y[j]==T[2])||(X[i]==T[1]&&Y[j]==T[3])))\n R += `${X[i]} ${Y[i]} `\nprint(R)\n\n\n"}, {"source_code": "T=readline().split(' ').map(x=>+x)\nx1=T[0],y1=T[1],x2=T[2],y2=T[3]\nd=[x2-x1,y2-y1]\nif (x1==x2) {\n print(`${x1+d[1]} ${y1} ${x1+d[1]} ${y2}`)\n} else if (y1==y2) {\n print(`${x1} ${y1+d[0]} ${x2} ${y1+d[0]}`)\n} else {\n if (d[0]!==d[1]) print(-1)\n else {\n var p=[\n [Math.min(x1,x2),Math.min(y1,y2)],\n [Math.min(x1,x2),Math.max(y1,y2)],\n [Math.max(x1,x2),Math.min(y1,y2)],\n [Math.max(x1,x2),Math.max(y1,y2)],\n ]\n p=p.filter(t => (t[0]-x1+t[1]-y1)&&(t[0]-x2+t[1]-y2))\n print([].concat(p[0],p[1],p[2],p[4]).join(' '))\n }\n}"}, {"source_code": "function main()\t{\n\t\t\tvar cor = readline().replace(/\\s{1,}/gi, ' ').split(/\\s/);\n\n\t\t\tcor = cor.map(function(val)\t{\n\t\t\t\treturn parseInt(val);\n\t\t\t});\n\n\t\t\tvar x1 = cor[0], y1 = cor[1],\n\t\t\t\tx2 = cor[2], y2 = cor[3];\n\n\t\t\tif(!isSquare(x1, y1, x2, y2))\tprint(-1);\n\t\t\telse\t{\n\t\t\t\tvar eCors = getExtCor(x1, y1, x2, y2);\n\n\t\t\t\tprint(eCors[0].x + ' ' + eCors[0].y + ' ' + eCors[1].x + ' ' + eCors[1].y + ' ');\n\t\t\t}\n\t\t};\n\n\t\tfunction isSquare(x1, y1, x2, y2)\t{\n\t\t\tvar result = false;\n\n\t\t\tif(Math.abs(x2 - x1) == Math.abs(y2 - y1))\tresult = true;\n\t\t\telse if(x2 - x1 == 0 || y2 - y1 == 0)\tresult = true;\n\n\t\t\treturn result;\n\t\t};\n\n\t\tfunction getExtCor(x1, y1, x2, y2)\t{\n\t\t\tvar eCor1 = { 'x' : 0, 'y' : 0 },\n\t\t\t\teCor2 = { 'x' : 0, 'y' : 0 };\n\n\t\t\tif(Math.abs(x2 - x1) == Math.abs(y2 - y1))\t{\n\t\t\t\teCor1.x = x1;\n\t\t\t\teCor1.y = y2;\n\n\t\t\t\teCor2.x = x2;\n\t\t\t\teCor2.y = y1;\n\t\t\t} else\t{\n\t\t\t\tvar size = x2 - x1 == 0 ? Math.abs(y2 - y1) : Math.abs(x2 - x1);\n\n\t\t\t\t//console.log(size);\n\n\t\t\t\tif(x2 - x1 == 0)\t{\n\t\t\t\t\teCor1.x = size;\n\t\t\t\t\teCor1.y = y1;\n\n\t\t\t\t\teCor2.x = size;\n\t\t\t\t\teCor2.y = y2;\n\t\t\t\t} else if(y2 - y1 == 0)\t{\n\t\t\t\t\teCor1.x = x1;\n\t\t\t\t\teCor1.y = size;\n\n\t\t\t\t\teCor2.x = x2;\n\t\t\t\t\teCor2.y = size;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t//console.log(JSON.stringify([ eCor1, eCor2 ]));\n\n\t\t\treturn [ eCor1, eCor2 ];\n\t\t};\n\n\t\tmain();"}], "src_uid": "71dea31e1244797f916adf5f526f776e"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tfunction remove(x) {\r\n\t\t\tlet ar = [];\r\n\t\t\tfor (const elm of a)\r\n\t\t\t\tif (elm != x) ar.push(elm);\r\n\t\t\treturn ar;\r\n\t\t}\r\n\r\n\t\tfunction isPal (s) {\r\n\t\t\tlet ok = true;\r\n\t\t\tfor (let i = 0; ok && i < Math.floor(s.length/2); i++)\r\n\t\t\t\tok = s[i] == s[s.length-i-1];\r\n\t\t\treturn ok;\r\n\t\t}\r\n\r\n\t\tlet ans = true;\r\n\t\tfor (let i = 0; i < Math.floor(n/2); i++) {\r\n\t\t\tif (a[i] != a[n - i - 1]) {\r\n\t\t\t\tp = a[i];\r\n\t\t\t\tq = a[n - i - 1];\r\n\t\t\t\tans = isPal(remove(p)) || isPal(remove(q));\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const check = (str,t)=>{\r\n let res = [],j=0;\r\n for(let i=0;i{\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}], "negative_code": [{"source_code": "const check = (str,t)=>{\r\n let res = \"\";\r\n for(let i=0;i{\r\n for(let i=0;i(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const check = (str,t)=>{\r\n let res = \"\";\r\n for(let i=0;i{\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}], "src_uid": "712e6e228e8b7cedd9bf6b85cd35c0b7"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(o=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{o=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return o[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;rt)).values()].find((t=>t.length>1));i.default.puts(null==e?\"NO\":\"YES\")}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let a = io.nextNumbers()\n// \n// let m = a.groupBy((x) => x)\n// \n// let b = [...m.values()].find((x) => x.length > 1)\n// \n// io.puts(b == undefined ? \"NO\" : \"YES\")\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar used = new Set();\n\t\tvar isOK = false;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(used.has(list[j])){\n\t\t\t\tisOK = true;\n\t\t\t}else{\n\t\t\t\tused.add(list[j]);\n\t\t\t}\n\t\t}\n\t\toutput[i] = (isOK) ? \"YES\" : \"NO\";\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "var tc = parseInt(readline());\nfor(; tc--; ){\n var ok = 0;\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => +x);\n for(var i=0; i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const set = new Set();\n\n for (let n of arr) {\n set.add(n);\n }\n if (set.size === len) console.log(`NO`);\n else console.log(`YES`);\n }\n}\n"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n const T = parseInt(lines[0])\n for (let t = 0; t < T; t++) {\n const s = new Set()\n let ans = 'NO'\n lines[2 * t + 2].split(' ').map((x) => parseInt(x)).forEach((x) => {\n if (s.has(x)) {\n ans = 'YES'\n }\n s.add(x)\n })\n console.log(ans)\n }\n})\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const newArr = arr.map((n) => pow(2, n));\n let [found, sum, total] = [false, 0, 0];\n const set = new Set();\n for (let i = 0; i < len; i++) total += arr[i];\n\n let prevSum = 0;\n for (let i = 0; i < len - 1; i++) {\n let currSum = 0;\n prevSum += arr[i];\n for (let j = i + 1; j < len; j++) {\n currSum += arr[j];\n const nextSum = total - currSum;\n if (currSum === prevSum || currSum === nextSum) {\n found = true;\n console.log(`YES`);\n break;\n }\n }\n if (found) break;\n }\n if (!found) console.log(`NO`);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const newArr = arr.map((n) => pow(2, n));\n let [found, sum, total] = [false, 0, 0];\n const set = new Set();\n for (let i = 0; i < len; i++) total += arr[i];\n\n for (let i = 0; i < len; i++) {\n sum += arr[i];\n const target = total - sum;\n const diff = sum - target;\n if (set.has(diff) || diff === 0) {\n found = true;\n console.log(`YES`);\n break;\n }\n set.add(sum);\n }\n if (!found) console.log(`NO`);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const newArr = arr.map((n) => pow(2, n));\n let [found, sum, total] = [false, 0, 0];\n const set = new Set();\n for (let i = 0; i < len; i++) total += newArr[i];\n\n let prevSum = 0;\n for (let i = 0; i < len - 1; i++) {\n let currSum = 0;\n prevSum += newArr[i];\n for (let j = i + 1; j < len; j++) {\n currSum += newArr[j];\n const nextSum = total - currSum;\n if (currSum === prevSum || currSum === nextSum) {\n found = true;\n console.log(`YES`);\n break;\n }\n }\n if (found) break;\n }\n if (!found) console.log(`NO`);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const newArr = arr.map((n) => pow(2, n));\n let [found, sum, total] = [false, 0, 0];\n const set = new Set();\n for (let i = 0; i < len; i++) total += newArr[i];\n\n for (let i = 0; i < len; i++) {\n sum += newArr[i];\n const target = total - sum;\n const diff = sum - target;\n if (set.has(diff) || diff === 0) {\n found = true;\n console.log(`YES`);\n break;\n }\n set.add(sum);\n }\n if (!found) console.log(`NO`);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tfor(var j = 1; j < N; j++){\n\t\t\tlist[j] += list[j - 1];\n\t\t}\n\t\tvar isOK = false;\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tfor(var k = j + 1; k < N; k++){\n\t\t\t\tvar L = list[j];\n\t\t\t\tvar R = list[k] - L;\n\t\t\t\tif(L == R){\n\t\t\t\t\tisOK = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput[i] = (isOK) ? \"YES\" : \"NO\";\n\t}\n\tmyout(myconv(output, 9));\n}\n"}], "src_uid": "3674a98de27b9bd2c8eb951da72996f5"} {"source_code": "// Generated by CoffeeScript 2.4.1\nvar A, K, N, NK, _, a, cache, dp, get_mask, get_prime, j, k, l, len, m, min, n, nr, nrs, prime, ref, ref1, used,\n indexOf = [].indexOf;\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\nmin = function(lst) {\n var best, item, k, len;\n best = lst[0];\n for (k = 0, len = lst.length; k < len; k++) {\n item = lst[k];\n best = item < best ? item : best;\n }\n return best;\n};\n\nn = 10000000;\n\nget_prime = function(n) {\n var i, is_prime, k, l, len, ref, res, x;\n res = [];\n for (i = k = 2, ref = n; (2 <= ref ? k < ref : k > ref); i = 2 <= ref ? ++k : --k) {\n is_prime = true;\n for (l = 0, len = res.length; l < len; l++) {\n x = res[l];\n if (i % x === 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) {\n res.push(i);\n }\n }\n return res;\n};\n\nprime = get_prime(3162);\n\ncache = {};\n\nget_mask = function(num) {\n var c, dv, k, key, l, len, len1, p, x;\n key = num;\n if (indexOf.call(cache, key) >= 0) {\n return cache[key];\n }\n dv = [];\n for (k = 0, len = prime.length; k < len; k++) {\n p = prime[k];\n c = 0;\n while (num % p === 0) {\n c += 1;\n num = Math.floor(num / p);\n }\n if (c % 2 === 1) {\n dv.push(p);\n }\n if (num < p * p) {\n break;\n }\n }\n for (l = 0, len1 = dv.length; l < len1; l++) {\n x = dv[l];\n num *= x;\n }\n cache[key] = num;\n return num;\n};\n\nfor (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {\n NK = nrs();\n N = NK[0];\n K = NK[1];\n A = nrs();\n dp = (function() {\n var l, ref1, results;\n results = [];\n for (_ = l = 0, ref1 = K + 1; (0 <= ref1 ? l <= ref1 : l >= ref1); _ = 0 <= ref1 ? ++l : --l) {\n results.push(N);\n }\n return results;\n })();\n dp[0] = 1;\n used = (function() {\n var l, ref1, results;\n results = [];\n for (_ = l = 0, ref1 = K + 1; (0 <= ref1 ? l < ref1 : l > ref1); _ = 0 <= ref1 ? ++l : --l) {\n results.push({});\n }\n return results;\n })();\n for (l = 0, len = A.length; l < len; l++) {\n a = A[l];\n a = get_mask(a);\n for (j = m = ref1 = K; (ref1 <= 0 ? m <= 0 : m >= 0); j = ref1 <= 0 ? ++m : --m) {\n if (dp[j] === N) {\n continue;\n }\n if (a in used[j]) {\n if (j < K && dp[j + 1] > dp[j]) {\n dp[j + 1] = dp[j];\n used[j + 1] = used[j];\n }\n dp[j] += 1;\n used[j] = {};\n }\n used[j][a] = 1;\n }\n }\n print(min(dp));\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamltbTg5LmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGppbW04OS5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLEVBQUEsRUFBQSxRQUFBLEVBQUEsU0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLENBQUEsRUFBQSxFQUFBLEVBQUEsR0FBQSxFQUFBLEtBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUE7RUFBQTs7QUFBQSxHQUFBLEdBQU0sUUFBQSxDQUFBLENBQUE7QUFBRyxNQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLEdBQUEsRUFBQTtBQUFXO0FBQUE7RUFBQSxLQUFBLHFDQUFBOztpQkFBWCxRQUFBLENBQVMsQ0FBVDtFQUFXLENBQUE7O0FBQWQ7O0FBQ04sRUFBQSxHQUFLLFFBQUEsQ0FBQSxDQUFBO1NBQUcsR0FBQSxDQUFBLENBQU0sQ0FBQSxDQUFBO0FBQVQ7O0FBRUwsR0FBQSxHQUFNLFFBQUEsQ0FBQyxHQUFELENBQUE7QUFDTCxNQUFBLElBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBO0VBQUEsSUFBQSxHQUFPLEdBQUksQ0FBQSxDQUFBO0VBQ1gsS0FBQSxxQ0FBQTs7SUFDQyxJQUFBLEdBQVUsSUFBQSxHQUFPLElBQVYsR0FBb0IsSUFBcEIsR0FBOEI7RUFEdEM7U0FFQTtBQUpLOztBQU1OLENBQUEsR0FBSTs7QUFFSixTQUFBLEdBQVksUUFBQSxDQUFDLENBQUQsQ0FBQTtBQUNYLE1BQUEsQ0FBQSxFQUFBLFFBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUEsR0FBQSxFQUFBO0VBQUEsR0FBQSxHQUFNO0VBQ04sS0FBUyw0RUFBVDtJQUNDLFFBQUEsR0FBVztJQUNYLEtBQUEscUNBQUE7O01BQ0MsSUFBRyxDQUFBLEdBQUksQ0FBSixLQUFTLENBQVo7UUFDQyxRQUFBLEdBQVc7QUFDWCxjQUZEOztJQUREO0lBSUEsSUFBRyxRQUFIO01BQWlCLEdBQUcsQ0FBQyxJQUFKLENBQVMsQ0FBVCxFQUFqQjs7RUFORDtTQU9BO0FBVFc7O0FBV1osS0FBQSxHQUFRLFNBQUEsQ0FBVSxJQUFWOztBQUVSLEtBQUEsR0FBUSxDQUFBOztBQUNSLFFBQUEsR0FBVyxRQUFBLENBQUMsR0FBRCxDQUFBO0FBQ1YsTUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBO0VBQUEsR0FBQSxHQUFNO0VBQ04sSUFBRyxhQUFPLEtBQVAsRUFBQSxHQUFBLE1BQUg7QUFBcUIsV0FBTyxLQUFNLENBQUEsR0FBQSxFQUFsQzs7RUFDQSxFQUFBLEdBQUs7RUFDTCxLQUFBLHVDQUFBOztJQUNDLENBQUEsR0FBSTtBQUNKLFdBQU0sR0FBQSxHQUFNLENBQU4sS0FBVyxDQUFqQjtNQUNDLENBQUEsSUFBSztNQUNMLEdBQUEsY0FBTSxNQUFPO0lBRmQ7SUFHQSxJQUFHLENBQUEsR0FBSSxDQUFKLEtBQVMsQ0FBWjtNQUNDLEVBQUUsQ0FBQyxJQUFILENBQVEsQ0FBUixFQUREOztJQUVBLElBQUcsR0FBQSxHQUFNLENBQUEsR0FBSSxDQUFiO0FBQ0MsWUFERDs7RUFQRDtFQVVBLEtBQUEsc0NBQUE7O0lBQ0MsR0FBQSxJQUFPO0VBRFI7RUFHQSxLQUFNLENBQUEsR0FBQSxDQUFOLEdBQWE7U0FDYjtBQWxCVTs7QUFvQlgsS0FBUywrRUFBVDtFQUNDLEVBQUEsR0FBSyxHQUFBLENBQUE7RUFDTCxDQUFBLEdBQUksRUFBRyxDQUFBLENBQUE7RUFDUCxDQUFBLEdBQUksRUFBRyxDQUFBLENBQUE7RUFDUCxDQUFBLEdBQUksR0FBQSxDQUFBO0VBQ0osRUFBQTs7QUFBUTtJQUFBLEtBQVMsdUZBQVQ7bUJBQUY7SUFBRSxDQUFBOzs7RUFDUixFQUFHLENBQUEsQ0FBQSxDQUFILEdBQVE7RUFDUixJQUFBOztBQUFXO0lBQUEsS0FBUyxxRkFBVDttQkFBSCxDQUFBO0lBQUcsQ0FBQTs7O0VBQ1gsS0FBQSxtQ0FBQTs7SUFDQyxDQUFBLEdBQUksUUFBQSxDQUFTLENBQVQ7SUFDSixLQUFTLDBFQUFUO01BQ0MsSUFBRyxFQUFHLENBQUEsQ0FBQSxDQUFILEtBQVMsQ0FBWjtBQUFtQixpQkFBbkI7O01BQ0EsSUFBRyxDQUFBLElBQUssSUFBSyxDQUFBLENBQUEsQ0FBYjtRQUNDLElBQUcsQ0FBQSxHQUFJLENBQUosSUFBVSxFQUFHLENBQUEsQ0FBQSxHQUFJLENBQUosQ0FBSCxHQUFZLEVBQUcsQ0FBQSxDQUFBLENBQTVCO1VBQ0MsRUFBRyxDQUFBLENBQUEsR0FBSSxDQUFKLENBQUgsR0FBWSxFQUFHLENBQUEsQ0FBQTtVQUNmLElBQUssQ0FBQSxDQUFBLEdBQUksQ0FBSixDQUFMLEdBQWMsSUFBSyxDQUFBLENBQUEsRUFGcEI7O1FBR0EsRUFBRyxDQUFBLENBQUEsQ0FBSCxJQUFTO1FBQ1QsSUFBSyxDQUFBLENBQUEsQ0FBTCxHQUFVLENBQUEsRUFMWDs7TUFNQSxJQUFLLENBQUEsQ0FBQSxDQUFHLENBQUEsQ0FBQSxDQUFSLEdBQWE7SUFSZDtFQUZEO0VBV0EsS0FBQSxDQUFNLEdBQUEsQ0FBSSxFQUFKLENBQU47QUFuQkQiLCJzb3VyY2VzQ29udGVudCI6WyJucnMgPSAtPiBwYXJzZUludCBpIGZvciBpIGluIHJlYWRsaW5lKCkuc3BsaXQgJyAnXG5uciA9IC0+IG5ycygpWzBdXG5cbm1pbiA9IChsc3QpIC0+XG5cdGJlc3QgPSBsc3RbMF1cblx0Zm9yIGl0ZW0gaW4gbHN0XG5cdFx0YmVzdCA9IGlmIGl0ZW0gPCBiZXN0IHRoZW4gaXRlbSBlbHNlIGJlc3QgXG5cdGJlc3QgXG5cbm4gPSAxMDAwMDAwMFxuXG5nZXRfcHJpbWUgPSAobikgLT5cblx0cmVzID0gW11cblx0Zm9yIGkgaW4gWzIuLi5uXVxuXHRcdGlzX3ByaW1lID0gdHJ1ZVxuXHRcdGZvciB4IGluIHJlc1xuXHRcdFx0aWYgaSAlIHggPT0gMFxuXHRcdFx0XHRpc19wcmltZSA9IGZhbHNlXG5cdFx0XHRcdGJyZWFrXG5cdFx0aWYgaXNfcHJpbWUgdGhlbiByZXMucHVzaCBpXG5cdHJlc1xuXG5wcmltZSA9IGdldF9wcmltZSAzMTYyXG5cbmNhY2hlID0ge31cbmdldF9tYXNrID0gKG51bSkgLT5cblx0a2V5ID0gbnVtXG5cdGlmIGtleSBpbiBjYWNoZSB0aGVuIHJldHVybiBjYWNoZVtrZXldXG5cdGR2ID0gW11cblx0Zm9yIHAgaW4gcHJpbWVcblx0XHRjID0gMFxuXHRcdHdoaWxlIG51bSAlIHAgPT0gMFxuXHRcdFx0YyArPSAxXG5cdFx0XHRudW0gPSBudW0gLy8gcFxuXHRcdGlmIGMgJSAyID09IDFcblx0XHRcdGR2LnB1c2ggcFxuXHRcdGlmIG51bSA8IHAgKiBwXG5cdFx0XHRicmVha1xuXG5cdGZvciB4IGluIGR2XG5cdFx0bnVtICo9IHhcblxuXHRjYWNoZVtrZXldID0gbnVtXG5cdG51bVxuXG5mb3IgXyBpbiBbMC4uLm5yKCldXG5cdE5LID0gbnJzKClcblx0TiA9IE5LWzBdXG5cdEsgPSBOS1sxXVxuXHRBID0gbnJzKClcblx0ZHAgPSAoTiBmb3IgXyBpbiBbMC4uSysxXSlcblx0ZHBbMF0gPSAxXG5cdHVzZWQgPSAoe30gZm9yIF8gaW4gWzAuLi5LKzFdKVxuXHRmb3IgYSBpbiBBXG5cdFx0YSA9IGdldF9tYXNrIGFcblx0XHRmb3IgaiBpbiBbSy4uMF1cblx0XHRcdGlmIGRwW2pdID09IE4gdGhlbiBjb250aW51ZSBcblx0XHRcdGlmIGEgb2YgdXNlZFtqXVxuXHRcdFx0XHRpZiBqIDwgSyBhbmQgZHBbaiArIDFdID4gZHBbal1cblx0XHRcdFx0XHRkcFtqICsgMV0gPSBkcFtqXVxuXHRcdFx0XHRcdHVzZWRbaiArIDFdID0gdXNlZFtqXVxuXHRcdFx0XHRkcFtqXSArPSAxXG5cdFx0XHRcdHVzZWRbal0gPSB7fVxuXHRcdFx0dXNlZFtqXVthXSA9IDFcblx0cHJpbnQgbWluIGRwXG4iXX0=\n//# sourceURL=c:\\github\\2021\\009-CodeForces#708\\1497E2\\coffee\\jimm89.coffee", "positive_code": [{"source_code": "// Generated by CoffeeScript 2.4.1\nvar A, K, N, _, a, cache, dp, get_mask, get_prime, j, k, l, len, len1, m, min, n, nr, nrs, prime, ref, ref1, used, xxx,\n indexOf = [].indexOf;\n\nnrs = function() {\n var i, k, len, ref, results;\n ref = readline().split(' ');\n results = [];\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n results.push(parseInt(i));\n }\n return results;\n};\n\nnr = function() {\n return nrs()[0];\n};\n\n\nfunction range(start, stop, step) {\n if (stop == null) {\n stop = start || 0\n start = 0\n }\n if (!step) step = stop < start ? -1 : 1\n\n var length = Math.max(Math.ceil((stop - start) / step), 0)\n var range = Array(length) \n\n for (var idx = 0; idx < length; idx++, start += step) range[idx] = start\n\n return range;\n}\n;\n\nmin = function(lst) {\n var best, item, k, len;\n best = lst[0];\n for (k = 0, len = lst.length; k < len; k++) {\n item = lst[k];\n best = item < best ? item : best;\n }\n return best;\n};\n\nn = 10000000;\n\nget_prime = function(n) {\n var i, is_prime, k, l, len, len1, ref, res, x;\n res = [];\n ref = range(2, n);\n for (k = 0, len = ref.length; k < len; k++) {\n i = ref[k];\n is_prime = true;\n for (l = 0, len1 = res.length; l < len1; l++) {\n x = res[l];\n if (i % x === 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) {\n res.push(i);\n }\n }\n return res;\n};\n\nprime = get_prime(3162);\n\ncache = {};\n\nget_mask = function(num) {\n var c, dv, k, key, l, len, len1, p, x;\n key = num;\n if (indexOf.call(cache, key) >= 0) {\n return cache[key];\n }\n dv = [];\n for (k = 0, len = prime.length; k < len; k++) {\n p = prime[k];\n c = 0;\n while (num % p === 0) {\n c += 1;\n num = Math.floor(num / p);\n }\n if (c % 2 === 1) {\n dv.push(p);\n }\n if (num < p * p) {\n break;\n }\n }\n for (l = 0, len1 = dv.length; l < len1; l++) {\n x = dv[l];\n num *= x;\n }\n cache[key] = num;\n return num;\n};\n\nfor (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {\n xxx = nrs();\n N = xxx[0];\n K = xxx[1];\n A = nrs();\n dp = (function() {\n var l, len, ref1, results;\n ref1 = range(K + 1);\n results = [];\n for (l = 0, len = ref1.length; l < len; l++) {\n _ = ref1[l];\n results.push(N);\n }\n return results;\n })();\n dp[0] = 1;\n used = (function() {\n var l, ref1, results;\n results = [];\n for (_ = l = 0, ref1 = K + 1; (0 <= ref1 ? l < ref1 : l > ref1); _ = 0 <= ref1 ? ++l : --l) {\n results.push({});\n }\n return results;\n })();\n for (l = 0, len = A.length; l < len; l++) {\n a = A[l];\n a = get_mask(a);\n ref1 = range(K, -1, -1);\n for (m = 0, len1 = ref1.length; m < len1; m++) {\n j = ref1[m];\n if (dp[j] === N) {\n continue;\n }\n if (a in used[j]) {\n if (j < K && dp[j + 1] > dp[j]) {\n dp[j + 1] = dp[j];\n used[j + 1] = used[j];\n }\n dp[j] += 1;\n used[j] = {};\n }\n used[j][a] = 1;\n }\n }\n print(min(dp));\n}\n\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamltbTg5LmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGppbW04OS5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxLQUFBLEVBQUEsRUFBQSxFQUFBLFFBQUEsRUFBQSxTQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLENBQUEsRUFBQSxFQUFBLEVBQUEsR0FBQSxFQUFBLEtBQUEsRUFBQSxHQUFBLEVBQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxHQUFBO0VBQUE7O0FBQUEsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBVztBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFkOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQUFHLEdBQUEsQ0FBQSxDQUFNLENBQUEsQ0FBQTtBQUFUOztBQUVMOzs7Ozs7Ozs7Ozs7Ozs7OztBQWlCQSxHQUFBLEdBQU0sUUFBQSxDQUFDLEdBQUQsQ0FBQTtBQUNMLE1BQUEsSUFBQSxFQUFBLElBQUEsRUFBQSxDQUFBLEVBQUE7RUFBQSxJQUFBLEdBQU8sR0FBSSxDQUFBLENBQUE7RUFDWCxLQUFBLHFDQUFBOztJQUNDLElBQUEsR0FBVSxJQUFBLEdBQU8sSUFBVixHQUFvQixJQUFwQixHQUE4QjtFQUR0QztTQUVBO0FBSks7O0FBTU4sQ0FBQSxHQUFJOztBQUVKLFNBQUEsR0FBWSxRQUFBLENBQUMsQ0FBRCxDQUFBO0FBQ1gsTUFBQSxDQUFBLEVBQUEsUUFBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxHQUFBLEVBQUEsR0FBQSxFQUFBO0VBQUEsR0FBQSxHQUFNO0FBQ047RUFBQSxLQUFBLHFDQUFBOztJQUNDLFFBQUEsR0FBVztJQUNYLEtBQUEsdUNBQUE7O01BQ0MsSUFBRyxDQUFBLEdBQUksQ0FBSixLQUFTLENBQVo7UUFDQyxRQUFBLEdBQVc7QUFDWCxjQUZEOztJQUREO0lBSUEsSUFBRyxRQUFIO01BQWlCLEdBQUcsQ0FBQyxJQUFKLENBQVMsQ0FBVCxFQUFqQjs7RUFORDtTQU9BO0FBVFc7O0FBV1osS0FBQSxHQUFRLFNBQUEsQ0FBVSxJQUFWOztBQUVSLEtBQUEsR0FBUSxDQUFBOztBQUNSLFFBQUEsR0FBVyxRQUFBLENBQUMsR0FBRCxDQUFBO0FBQ1YsTUFBQSxDQUFBLEVBQUEsRUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsQ0FBQSxFQUFBO0VBQUEsR0FBQSxHQUFNO0VBQ04sSUFBRyxhQUFPLEtBQVAsRUFBQSxHQUFBLE1BQUg7QUFBcUIsV0FBTyxLQUFNLENBQUEsR0FBQSxFQUFsQzs7RUFDQSxFQUFBLEdBQUs7RUFDTCxLQUFBLHVDQUFBOztJQUNDLENBQUEsR0FBSTtBQUNKLFdBQU0sR0FBQSxHQUFNLENBQU4sS0FBVyxDQUFqQjtNQUNDLENBQUEsSUFBSztNQUNMLEdBQUEsY0FBTSxNQUFPO0lBRmQ7SUFHQSxJQUFHLENBQUEsR0FBSSxDQUFKLEtBQVMsQ0FBWjtNQUNDLEVBQUUsQ0FBQyxJQUFILENBQVEsQ0FBUixFQUREOztJQUVBLElBQUcsR0FBQSxHQUFNLENBQUEsR0FBSSxDQUFiO0FBQ0MsWUFERDs7RUFQRDtFQVVBLEtBQUEsc0NBQUE7O0lBQ0MsR0FBQSxJQUFPO0VBRFI7RUFHQSxLQUFNLENBQUEsR0FBQSxDQUFOLEdBQWE7U0FDYjtBQWxCVTs7QUFvQlgsS0FBUywrRUFBVDtFQUNDLEdBQUEsR0FBTSxHQUFBLENBQUE7RUFDTixDQUFBLEdBQUksR0FBSSxDQUFBLENBQUE7RUFDUixDQUFBLEdBQUksR0FBSSxDQUFBLENBQUE7RUFDUixDQUFBLEdBQUksR0FBQSxDQUFBO0VBQ0osRUFBQTs7QUFBUTtBQUFBO0lBQUEsS0FBQSxzQ0FBQTs7bUJBQUY7SUFBRSxDQUFBOzs7RUFDUixFQUFHLENBQUEsQ0FBQSxDQUFILEdBQVE7RUFDUixJQUFBOztBQUFXO0lBQUEsS0FBUyxxRkFBVDttQkFBSCxDQUFBO0lBQUcsQ0FBQTs7O0VBQ1gsS0FBQSxtQ0FBQTs7SUFDQyxDQUFBLEdBQUksUUFBQSxDQUFTLENBQVQ7QUFDSjtJQUFBLEtBQUEsd0NBQUE7O01BQ0MsSUFBRyxFQUFHLENBQUEsQ0FBQSxDQUFILEtBQVMsQ0FBWjtBQUFtQixpQkFBbkI7O01BQ0EsSUFBRyxDQUFBLElBQUssSUFBSyxDQUFBLENBQUEsQ0FBYjtRQUNDLElBQUcsQ0FBQSxHQUFJLENBQUosSUFBVSxFQUFHLENBQUEsQ0FBQSxHQUFJLENBQUosQ0FBSCxHQUFZLEVBQUcsQ0FBQSxDQUFBLENBQTVCO1VBQ0MsRUFBRyxDQUFBLENBQUEsR0FBSSxDQUFKLENBQUgsR0FBWSxFQUFHLENBQUEsQ0FBQTtVQUNmLElBQUssQ0FBQSxDQUFBLEdBQUksQ0FBSixDQUFMLEdBQWMsSUFBSyxDQUFBLENBQUEsRUFGcEI7O1FBR0EsRUFBRyxDQUFBLENBQUEsQ0FBSCxJQUFTO1FBQ1QsSUFBSyxDQUFBLENBQUEsQ0FBTCxHQUFVLENBQUEsRUFMWDs7TUFNQSxJQUFLLENBQUEsQ0FBQSxDQUFHLENBQUEsQ0FBQSxDQUFSLEdBQWE7SUFSZDtFQUZEO0VBV0EsS0FBQSxDQUFNLEdBQUEsQ0FBSSxFQUFKLENBQU47QUFuQkQiLCJzb3VyY2VzQ29udGVudCI6WyJucnMgPSAtPiBwYXJzZUludCBpIGZvciBpIGluIHJlYWRsaW5lKCkuc3BsaXQgJyAnXG5uciA9IC0+IG5ycygpWzBdXG5cbmBgYFxuZnVuY3Rpb24gcmFuZ2Uoc3RhcnQsIHN0b3AsIHN0ZXApIHtcbiAgaWYgKHN0b3AgPT0gbnVsbCkge1xuICAgIHN0b3AgPSBzdGFydCB8fCAwXG4gICAgc3RhcnQgPSAwXG4gIH1cbiAgaWYgKCFzdGVwKSBzdGVwID0gc3RvcCA8IHN0YXJ0ID8gLTEgOiAxXG5cbiAgdmFyIGxlbmd0aCA9IE1hdGgubWF4KE1hdGguY2VpbCgoc3RvcCAtIHN0YXJ0KSAvIHN0ZXApLCAwKVxuICB2YXIgcmFuZ2UgPSBBcnJheShsZW5ndGgpIFxuXG4gIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IGxlbmd0aDsgaWR4KyssIHN0YXJ0ICs9IHN0ZXApIHJhbmdlW2lkeF0gPSBzdGFydFxuXG4gIHJldHVybiByYW5nZTtcbn1cbmBgYFxuXG5taW4gPSAobHN0KSAtPlxuXHRiZXN0ID0gbHN0WzBdXG5cdGZvciBpdGVtIGluIGxzdFxuXHRcdGJlc3QgPSBpZiBpdGVtIDwgYmVzdCB0aGVuIGl0ZW0gZWxzZSBiZXN0IFxuXHRiZXN0IFxuXG5uID0gMTAwMDAwMDBcblxuZ2V0X3ByaW1lID0gKG4pIC0+XG5cdHJlcyA9IFtdXG5cdGZvciBpIGluIHJhbmdlIDIsIG5cblx0XHRpc19wcmltZSA9IHRydWVcblx0XHRmb3IgeCBpbiByZXNcblx0XHRcdGlmIGkgJSB4ID09IDBcblx0XHRcdFx0aXNfcHJpbWUgPSBmYWxzZVxuXHRcdFx0XHRicmVha1xuXHRcdGlmIGlzX3ByaW1lIHRoZW4gcmVzLnB1c2ggaVxuXHRyZXNcblxucHJpbWUgPSBnZXRfcHJpbWUgMzE2MlxuXG5jYWNoZSA9IHt9XG5nZXRfbWFzayA9IChudW0pIC0+XG5cdGtleSA9IG51bVxuXHRpZiBrZXkgaW4gY2FjaGUgdGhlbiByZXR1cm4gY2FjaGVba2V5XVxuXHRkdiA9IFtdXG5cdGZvciBwIGluIHByaW1lXG5cdFx0YyA9IDBcblx0XHR3aGlsZSBudW0gJSBwID09IDBcblx0XHRcdGMgKz0gMVxuXHRcdFx0bnVtID0gbnVtIC8vIHBcblx0XHRpZiBjICUgMiA9PSAxXG5cdFx0XHRkdi5wdXNoIHBcblx0XHRpZiBudW0gPCBwICogcFxuXHRcdFx0YnJlYWtcblxuXHRmb3IgeCBpbiBkdlxuXHRcdG51bSAqPSB4XG5cblx0Y2FjaGVba2V5XSA9IG51bVxuXHRudW1cblxuZm9yIF8gaW4gWzAuLi5ucigpXVxuXHR4eHggPSBucnMoKVxuXHROID0geHh4WzBdXG5cdEsgPSB4eHhbMV1cblx0QSA9IG5ycygpXG5cdGRwID0gKE4gZm9yIF8gaW4gcmFuZ2UgSysxKVxuXHRkcFswXSA9IDFcblx0dXNlZCA9ICh7fSBmb3IgXyBpbiBbMC4uLksrMV0pXG5cdGZvciBhIGluIEFcblx0XHRhID0gZ2V0X21hc2sgYVxuXHRcdGZvciBqIGluIHJhbmdlIEssLTEsLTFcblx0XHRcdGlmIGRwW2pdID09IE4gdGhlbiBjb250aW51ZSBcblx0XHRcdGlmIGEgb2YgdXNlZFtqXVxuXHRcdFx0XHRpZiBqIDwgSyBhbmQgZHBbaiArIDFdID4gZHBbal1cblx0XHRcdFx0XHRkcFtqICsgMV0gPSBkcFtqXVxuXHRcdFx0XHRcdHVzZWRbaiArIDFdID0gdXNlZFtqXVxuXHRcdFx0XHRkcFtqXSArPSAxXG5cdFx0XHRcdHVzZWRbal0gPSB7fVxuXHRcdFx0dXNlZFtqXVthXSA9IDFcblx0cHJpbnQgbWluIGRwXG4iXX0=\n//# sourceURL=c:\\github\\2021\\009-CodeForces#708\\1497E2\\coffee\\jimm89.coffee"}], "negative_code": [], "src_uid": "1f80d1b61d76ba7725b6e4208a4f735e"} {"source_code": "function solve() {\n var T = Number(read());\n function funcSort(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n for (var t = 0; t < T; t++) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var a = read().split(' ').map(Number);\n var w = read().split(' ').map(Number);\n a.sort(funcSort);\n w.sort(funcSort);\n var li = n - k - 1;\n var ri = n - 1;\n var ans = 0;\n for (var i = 0; i < k; i++) {\n if (w[i] === 1) {\n ans += a[ri--] * 2;\n } else {\n li -= w[i] - 1;\n ans += a[ri--] + a[li + 1];\n }\n }\n write('' + ans);\n }\n}\n \n \nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}", "positive_code": [{"source_code": "function solve() {\n var T = Number(read());\n function funcSort(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n for (var t = 0; t < T; t++) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var a = read().split(' ').map(BigInt);\n var w = read().split(' ').map(Number);\n a.sort(funcSort);\n w.sort(funcSort);\n var li = n - k - 1;\n var ri = n - 1;\n var ans = 0n;\n for (var i = 0; i < k; i++) {\n if (w[i] === 1) {\n ans += a[ri--] * 2n;\n } else {\n li -= w[i] - 1;\n ans += a[ri--] + a[li + 1];\n }\n }\n write('' + ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let w = ti(readline().split(' '));\n\n a.sort((x,y) => y-x);\n w.sort((x,y) => y-x);\n \n let res = 0;\n let p1 = 0;\n let p2 = n-1;\n let en = -1;\n for(let i = k-1; i >= 0; i--){\n if(w[i] === 1){\n res += 2*a[p1];\n p1++;\n }else{\n en = i;\n break;\n }\n }\n\n for(let i = 0; i <= en; i++){\n res += a[p2];\n p2 -= w[i]-1;\n res += a[p1];\n p1++; \n }\n\n console.log(res)\n }\n}"}, {"source_code": "const { KeyObject } = require(\"crypto\");\n\nvar data = '';\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', (buffer) =>\n{\n data += buffer;\n});\n\nprocess.stdin.on('end', () =>\n{\n var i = 1;\n var x = data.split(/\\s+/).map(Number);\n for (var cas = 0; cas < x[0]; cas++)\n {\n var n = x[i++];\n var k = x[i++];\n var a = [], w = [];\n for (var j = 0; j < n; j++)\n a.push(x[i++]);\n for (var j = 0; j < k; j++)\n w.push(x[i++]);\n a.sort((a, b) => a - b);\n w.sort((a, b) => a - b);\n\n var res = 0;\n var min = 0, max = n - 1, c = 0;\n for (c = 0; c < k && w[c] == 1; c++)\n res += a[max] + a[max], max--;\n for (var j = k - 1; j >= c; j--)\n res += a[max] + a[min], max--, min += w[j] - 1;\n console.log(res);\n }\n});"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc]\n acc++\n for (let i=0; i +x)\n acc++\n const nums = lines[acc].split(' ').map(x => +x).sort((a, b) => b - a)\n acc++\n const friends = lines[acc].split(' ').map(x => +x).sort((a, b) => a - b)\n acc++\n\n let sum = 0\n\n for (let i =0; i= 0; i--) {\n if (friends[i] === 1) {\n break\n }\n sum += nums[cur]\n cur -= (friends[i] - 1)\n }\n\n console.log(sum)\n\n //\n // const zeroPoint = l.indexOf('0')\n // const onePoint = l.indexOf('1')\n // const secondZeroPoint = l.indexOf('0', onePoint)\n //\n // if (zeroPoint === 0) {\n // if (secondZeroPoint > 0) {\n // console.log(l.slice(0, onePoint) + '0')\n // } else {\n // console.log(l)\n // }\n // } else {\n // if (zeroPoint > 0 ) {\n // console.log('0')\n // } else {\n // console.log(l)\n // }\n // }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "function solve() {\n var T = Number(read());\n function funcSort(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n for (var t = 0; t < T; t++) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var a = read().split(' ').map(BigInt);\n var w = read().split(' ').map(BigInt);\n a.sort(funcSort);\n w.sort(funcSort);\n var li = 0;\n var ri = n - 1;\n var ans = 0n;\n for (var i = 0; i < k; i++) {\n if (w[i] === 1n) {\n ans += a[ri--] * 2n;\n } else {\n ans += a[ri--] + a[li++];\n }\n }\n write('' + ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n function funcSort(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n for (var t = 0; t < T; t++) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var a = read().split(' ').map(BigInt);\n var w = read().split(' ').map(BigInt);\n a.sort(funcSort);\n w.sort(funcSort);\n var li = 0;\n var ri = n - 1;\n var ans = 0n;\n for (var i = 0; i < k; i++) {\n if (w[i] === 1n) {\n ans += a[ri--] * 2n;\n } else {\n ans += a[ri--] + a[li++];\n }\n }\n var strAns = '' + ans;\n write(strAns.substring(0, strAns.length - 1));\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let w = ti(readline().split(' '));\n\n a.sort((x,y) => y-x);\n w.sort((x,y) => x-y);\n let sum = 0;\n for(let i = 0; i < k; i++)\n sum += w[i];\n \n let res = 0;\n let p1 = 0;\n let p2 = sum-1;\n for(let i = 0; i < k; i++){\n if(w[i] === 1){\n res += 2*a[p1];\n p1++;\n }else{\n res += a[p1];\n res += a[p2];\n p2 -= w[i]-2;\n }\n }\n\n console.log(res)\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let w = ti(readline().split(' '));\n\n a.sort((x,y) => y-x);\n w.sort((x,y) => x-y);\n let res = 0;\n let p1 = 0;\n let p2 = n-1;\n for(let i = 0; i < k; i++){\n if(w[i] === 1){\n res += 2*a[p1];\n p1++;\n }else{\n res += a[p1];\n res += a[p2];\n p2 -= w[i]-2;\n }\n }\n\n console.log(res)\n }\n}"}], "src_uid": "9802646ecc8890bb046d5ec1a4262d70"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet inputArray = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputArray = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputArray[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i parseInt(x));\n\n let good = 0;\n let sum = 0;\n let m = new Map();\n m.set(0,1);\n for (let j=0; j1){\n var n=parseInt(arr[arr.length-2]),\n a=arr[arr.length-1].split(''),\n sum=0,ans=0,obj={};\n for(var i=0;i {\n // your code goes here\n let tc_count = readNum();\n\n const specVal = Array(1e5 + 9);\n const tracer = Array(1e6).fill(0);\n let n, counter, curPreSum, digitString, digit, sp;\n\n\n specVal[0] = 0;\n \n while (tc_count--) {\n\n n = readNum();\n\n const addendum = n;\n counter = 0;\n tracer[addendum] = 1;\n curPreSum = 0;\n\n digitString = readStr(n); \n \n for (let i = 1; i <= n; i++) {\n digit = digitString.codePointAt(i - 1) - 48;\n curPreSum += digit;\n\n sp = specVal[i] = curPreSum - i + addendum;\n counter += tracer[sp];\n tracer[sp]++;\n }\n writeLine(counter);\n // reset tracer\n tracer[addendum] = 0;\n for (let i = 1; i <= n; i++) {\n sp = specVal[i];\n tracer[sp] = 0;\n }\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = 0;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n\n callbackfn({\n log: console.log,\n readNum() {\n let x = 0, ch = aStr.charCodeAt(cur) - 48;\n while (ch < 0 || 9 < ch) ch = aStr.charCodeAt(++cur) - 48;\n while (0 <= ch && ch <= 9) {\n x = x * 10 + ch;\n ch = aStr.charCodeAt(++cur) - 48;\n }\n return x;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(len = 1e6) {\n const chArr = Array(len);\n let ch = aStr[cur], i = 0;\n while (seperator.test(ch)) ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[i++] = ch;\n ch = aStr[++cur];\n }\n return chArr.join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\"\")\n .map((n) => parseInt(n - 1));\n const map = { 0: 1 };\n let [sum, count] = [0, 0];\n\n arr.forEach((num) => {\n sum += num;\n if (map[sum]) {\n count += map[sum];\n map[sum]++;\n } else {\n map[sum] = 1;\n }\n });\n console.log(count);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let _i = 0; _i < t; _i++) {\n\tconst n = Number(readLine())\n const arr = Array.from(readLine()).map(s => Number(s) - 1)\n const nums = {}\n nums[0] = 1\n let total = 0\n for (let i = 0; i < n; i++) {\n total += arr[i]\n if (!nums[total]) {\n nums[total] = 0\n }\n nums[total] += 1\n }\n console.log(Object.values(nums).reduce((acc, curr) => acc + curr * (curr - 1) / 2, 0))\n }\n}\n"}, {"source_code": "// process.stdin.resume();\n// process.stdin.setEncoding('utf8');\n\nfunction readDOM() {\n return stdinReadAll();\n}\n\nlet CONFIG = {\n // getStringFunc: readDOM\n};\n\nstdioCPPattern(CONFIG, ({ readNum, readStr, writeLine }) => {\n // your code goes here\n let tc_count = readNum();\n\n const specVal = Array(1e5 + 9);\n const tracer = Array(1e6).fill(0);\n let n, counter, curPreSum, digitString, digit, sp;\n\n\n specVal[0] = 0;\n \n while (tc_count--) {\n\n n = readNum();\n\n const addendum = n;\n counter = 0;\n tracer[addendum] = 1;\n curPreSum = 0;\n\n digitString = readStr(n); \n \n for (let i = 1; i <= n; i++) {\n digit = digitString.codePointAt(i - 1) - 48;\n curPreSum += digit;\n\n sp = specVal[i] = curPreSum - i + addendum;\n counter += tracer[sp];\n tracer[sp]++;\n }\n writeLine(counter);\n // reset tracer\n tracer[addendum] = 0;\n for (let i = 1; i <= n; i++) {\n sp = specVal[i];\n tracer[sp] = 0;\n }\n }\n});\n\n/**\n * @author flynn\n */\nfunction stdinReadAll() {\n const fs = require(\"fs\");\n return fs.readFileSync(0).toString();\n}\n\nfunction stdioCPPattern({\n getStringFunc = stdinReadAll\n}, callbackfn) {\n const aStr = getStringFunc() + \"\\n\";\n\n let cur = 0;\n const resultList = [];// Array(numberOfLine);\n const seperator = /\\s/;\n\n callbackfn({\n log: console.log,\n readNum() {\n let x = 0, ch = aStr.charCodeAt(cur) - 48;\n while (ch < 0 || 9 < ch) ch = aStr.charCodeAt(++cur) - 48;\n while (0 <= ch && ch <= 9) {\n x = x * 10 + ch;\n ch = aStr.charCodeAt(++cur) - 48;\n }\n return x;\n },\n writeLine(data) {\n resultList.push(`${data}`);\n },\n readStr(len = 1e6) {\n const chArr = Array(len);\n let ch = aStr[cur], i = 0;\n while (seperator.test(ch)) ch = aStr[++cur];\n while (!seperator.test(ch)) {\n chArr[i++] = ch;\n ch = aStr[++cur];\n }\n return chArr.join(\"\");\n }\n });\n let prompt = resultList.join(\"\\n\");\n if (prompt) console.log(prompt);\n}"}, {"source_code": "\nconst solution = (string) => {\n const nums = string.split('').map(Number)\n let sum = 0\n const grid = nums.map((n, i) => {\n sum += n\n return sum - (i + 1)\n })\n grid.push(0)\n const freq = {}\n for (const num of grid) {\n freq[num] =\n 1 +\n (freq[num] || 0)\n }\n\n let result = 0\n for (const count of Object.values(freq)) {\n result += count * (count - 1) / 2\n }\n\n return result\n}\n\n// Boilerplate Node.js for codeforces\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n // every other line, without the first line\n for (let i = 2; i < lines.length; i += 2) {\n console.log(solution(lines[i]))\n }\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(''));\n let s = res = 0;\n let map = {0:1};\n for(let i = 0; i < n; i++){\n s += a[i];\n let x = s-i-1;\n if(map[x] === undefined){\n map[x] = 0;\n }\n map[x] += 1;\n res += map[x]-1;\n }\n console.log(res);\n }\n}"}, {"source_code": "T = readline();\nwhile (T--) {\n n = readline()\n a = readline()\n m = new Map()\n m.set(0, 1)\n ans = 0\n sum = 0\n for (i = 0; i < n; i++) {\n sum += +a[i]\n x = sum - i - 1\n if (!m.has(x))\n m.set(x, 0)\n m.set(x, m.get(x) + 1)\n ans += m.get(x) - 1\n }\n print(ans)\n}"}, {"source_code": "T = readline()\nwhile (T--) {\n n = readline(); a = readline()\n m = new Map([[0, 1]])\n ans = 0; sum = 0\n for (i = 0; i < n; i++) {\n sum += +a[i]\n x = sum - i - 1\n if (!m.has(x))\n m.set(x, 0)\n v = m.get(x)\n m.set(x, v + 1)\n ans += v\n }\n print(ans)\n}"}], "negative_code": [{"source_code": "T = readline()\nwhile (T--) {\n n = readline(); a = readline()\n m = new Map([[0, 1]])\n ans = 0; sum = 0\n for (i = 0; i < n; i++) {\n sum += +a[i]\n const x = sum - i - 1\n if (!m.has(x))\n m.set(x, 0)\n const v = m.get(x)\n m.set(x, v + 1)\n ans += v\n }\n print(ans)\n}"}, {"source_code": "T = readline()\nwhile (T--) {\n n = readline(); a = readline()\n m = new Map()\n m.set(0, 1)\n ans = 0; sum = 0\n for (i = 0; i < n; i++) {\n sum += +a[i]\n const x = sum - i - 1\n if (!m.has(x))\n m.set(x, 0)\n const v = m.get(x)\n m.set(x, v + 1)\n ans += v\n }\n print(ans)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet inputArray = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputArray = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputArray[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i parseInt(x));\n\n let good = 0;\n let sum = 0;\n let m = new Map();\n m.set(0,1);\n for (let j=0; j max)\n\t\treturn -1;\n\n\tvar ans=[];\n\tif(n===min){\n\t\tfor(var i=0;i 2*zero + 2) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar solution = [];\n\tfunction push(s) {\n\t\tsolution.push(s);\n\t}\n\n\twhile (one > 2*zero) {\n\t\tpush(\"1\");\n\t\tone -= 1;\n\t}\n\twhile (one > zero) {\n\t\tpush(\"011\");\n\t\tone -= 2;\n\t\tzero -= 1;\n\t}\n\twhile (one > 0) {\n\t\tpush(\"01\");\n\t\tone -= 1;\n\t\tzero -= 1;\n\t}\n\tif (zero == 1) {\n\t\tpush(\"0\");\n\t}\n\n\tprint(solution.join(\"\"));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar zero = integers[0], one = integers[1];\n\n\tvar solution = [];\n\tfunction push(s, k) {\n\t\tif (k === undefined) {\n\t\t\tsolution.push(s);\n\t\t\treturn;\n\t\t}\n\t\tfor (var i = 0; i < k; ++i) {\n\t\t\tsolution.push(s);\n\t\t}\n\t}\n\t\n\tif (2*zero == one) {\n\t\tpush(\"011\", zero);\n\t}\n\n\telse if (2*zero == one-1) {\n\t\tpush(\"1\");\n\t\tpush(\"011\", zero);\n\t}\n\telse if (2*zero == one-2) {\n\t\tpush(\"11\");\n\t\tpush(\"011\", zero);\n\t}\n\n\telse if (2*(zero-1) == one-1) {\n\t\tpush(\"1\");\n\t\tpush(\"011\", zero-1);\n\t\tpush(\"0\");\n\t}\n\telse if (2*(zero-1) == one-2) {\n\t\tpush(\"11\");\n\t\tpush(\"011\", zero-1);\n\t\tpush(\"0\");\n\t}\n\n\telse if (2*(zero-1) == one-3) {\n\t\tpush(\"11\");\n\t\tpush(\"011\", zero-1);\n\t\tpush(\"01\");\n\t}\n\n\telse if (2*(zero-1) == one) {\n\t\tpush(\"011\", zero-1);\n\t\tpush(\"0\");\n\t}\n\n\telse {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tprint(solution.join(\"\"));\n}\n\nmain();\n"}], "src_uid": "854c561539596722b1dbc8f99cbdca78"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const topo = () => {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => g[i].push(j);\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n const query = [0];\r\n const g1 = Array.from({\r\n length: n\r\n }, () => []),\r\n d = new Array(n).fill(0);\r\n const add1 = (i, j) => {\r\n g1[i].push(j);\r\n d[j]++;\r\n };\r\n const st = [];\r\n for (let u of query) {\r\n st[u] = 1;\r\n for (let v of g[u]) {\r\n if (st[v]) continue;\r\n add1(v, u);\r\n query.push(v);\r\n }\r\n }\r\n return [g1, d];\r\n };\r\n const [g, d] = topo();\r\n const dp = Array.from({\r\n length: n\r\n }, () => [0, 1]);\r\n const temp = Array.from({\r\n length: n\r\n }, () => []);\r\n const query = [];\r\n for (let [i, di] of d.entries()) if (di === 0) query.push(i);\r\n for (let u of query) {\r\n for (let v of g[u]) {\r\n d[v]--;\r\n dp[v][1] += dp[u][1];\r\n temp[v].push(u);\r\n if (d[v] === 0) {\r\n query.push(v);\r\n let s0 = temp[v].reduce((a, b) => a + dp[b][0], 0);\r\n let max = 0;\r\n for (let i of temp[v]) {\r\n max = Math.max(max, s0 - dp[i][0] + dp[i][1] - 1);\r\n }\r\n dp[v][0] = max;\r\n }\r\n }\r\n }\r\n return dp[0][0];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs1 = RTI((i, state) => {\r\n if (st[i] !== 0) return [() => [], () => 0];\r\n if (cache[i][state] !== -1) return [() => [], () => cache[i][state]];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n const inside = () => {\r\n let calls = [];\r\n for (let j of g[i]) {\r\n calls.push([j, 1]);\r\n }\r\n return calls;\r\n };\r\n const after = (...args) => {\r\n res = args.reduce((a, b) => a + b, 1);\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else {\r\n if (g[i].length === 2) {\r\n const inside = () => [[g[i].filter(j => !st[j])[0], 1]];\r\n const after = (...args) => {\r\n res = args[0] - 1;\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n const inside = () => {\r\n return [[a, 0], [b, 1], [a, 1], [b, 0]];\r\n };\r\n const after = (...args) => {\r\n const [a, b, c, d] = args;\r\n res = Math.max(a + b - 1, c - 1 + d);\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else {\r\n const inside = () => {\r\n return [];\r\n };\r\n const after = () => {\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n }\r\n }\r\n });\r\n let res = dfs1(0, 0);\r\n return res;\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = result => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nasync function solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs1 = RTI((i, state) => {\r\n if (st[i] !== 0) return [() => [], () => 0];\r\n if (cache[i][state] !== -1) return [() => [], () => cache[i][state]];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n const inside = () => {\r\n let calls = [];\r\n for (let j of g[i]) {\r\n calls.push([j, 1]);\r\n }\r\n return calls;\r\n };\r\n const after = (...args) => {\r\n res = args.reduce((a, b) => a + b, 1);\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else {\r\n if (g[i].length === 2) {\r\n const inside = () => [[g[i].filter(j => !st[j])[0], 1]];\r\n const after = (...args) => {\r\n res = args[0] - 1;\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n const inside = () => {\r\n return [[a, 0], [b, 1], [a, 1], [b, 0]];\r\n };\r\n const after = (...args) => {\r\n const [a, b, c, d] = args;\r\n res = Math.max(a + b - 1, c - 1 + d);\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n } else {\r\n const inside = () => {\r\n return [];\r\n };\r\n const after = () => {\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n }\r\n }\r\n });\r\n let res = dfs1(0, 0);\r\n return res;\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = result => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, ...curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nvar worker_threads = require('worker_threads');\r\n\r\nasync function solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = async (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += await dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet str = '';\r\nfunction exec(script, data) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new worker_threads.Worker(script, {\r\n workerData: data,\r\n eval: true\r\n });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', code => {\r\n if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n str.split('\\n').values();\r\n const script =\r\n `\r\nconst { workerData } = require('worker_threads')\r\nconst inputs = workerData.split('\\\\n').values()\r\nfunction read() {\r\n return inputs.next().value.trim()\r\n}\r\n${solve.toString()}\r\n${main.toString()}\r\n\r\nvoid async function () {\r\n const output = await main(read)\r\n console.log(output)\r\n}()\r\n`;\r\n exec(script, str);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nasync function solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = async (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += await dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const topo = () => {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => g[i].push(j);\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n const query = [0];\r\n const g1 = Array.from({\r\n length: n\r\n }, () => []),\r\n d = new Array(n).fill(0);\r\n const add1 = (i, j) => {\r\n g1[i].push(j);\r\n d[j]++;\r\n };\r\n const st = [];\r\n for (let u of query) {\r\n st[u] = 1;\r\n for (let v of g[u]) {\r\n if (st[v]) continue;\r\n add1(v, u);\r\n query.push(v);\r\n }\r\n }\r\n return [g1, d];\r\n };\r\n const [g, d] = topo();\r\n const dp = Array.from({\r\n length: n\r\n }, () => [0, 0, 1]);\r\n const temp = Array.from({\r\n length: n\r\n }, () => []);\r\n const query = [];\r\n for (let [i, di] of d.entries()) if (di === 0) query.push(i);\r\n for (let u of query) {\r\n for (let v of g[u]) {\r\n d[v]--;\r\n dp[v][2] += dp[u][2];\r\n dp[v][0] += dp[u][2];\r\n temp[v].push(u);\r\n if (d[v] === 0) {\r\n query.push(v);\r\n let s0 = temp[v].reduce((a, b) => a + dp[b][1], 0);\r\n let max = 0;\r\n for (let i of temp[v]) {\r\n max = Math.max(max, s0 - dp[i][1] + dp[i][0]);\r\n }\r\n dp[v][1] = max;\r\n }\r\n }\r\n }\r\n return dp[0][1];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar worker_threads = require('worker_threads');\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet str = '';\r\nfunction exec(script, data) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new worker_threads.Worker(script, {\r\n workerData: data,\r\n eval: true\r\n });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', code => {\r\n if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n str.split('\\n').values();\r\n const script =\r\n `\r\nconst { workerData } = require('worker_threads')\r\nconst inputs = workerData.split('\\\\n').values()\r\nfunction read() {\r\n return inputs.next().value.trim()\r\n}\r\n${solve.toString()}\r\n${main.toString()}\r\n\r\nvoid async function () {\r\n const output = await main(read)\r\n console.log(output)\r\n}()\r\n`;\r\n exec(script, str);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nvar worker_threads = require('worker_threads');\r\n\r\nasync function solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = async (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += await dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = (await dfs(g[i].filter(j => !st[j])[0], 1)) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max((await dfs(a, 0)) + (await dfs(b, 1)) - 1, (await dfs(a, 1)) - 1 + (await dfs(b, 0)));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction exec(script, data) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new worker_threads.Worker(script, {\r\n workerData: data,\r\n eval: true\r\n });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', code => {\r\n if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const script =\r\n `\r\nconst { workerData } = require('worker_threads')\r\nlet idx = 0\r\nfunction read() {\r\n return workerData[idx++]\r\n}\r\n${main.toString()}\r\n\r\nvoid async function () {\r\n const output = main(read)\r\n console.log(output)\r\n}\r\n`;\r\n exec(script, inputs);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nconst {\r\n Worker, isMainThread, parentPort, workerData\r\n} = require('worker_threads');\r\n\r\nfunction parseJSAsync(script, workerData) {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(script, { eval: true, workerData });\r\n worker.on('message', resolve);\r\n worker.on('error', reject);\r\n worker.on('exit', (code) => {\r\n if (code !== 0)\r\n reject(new Error(`Worker stopped with exit code ${code}`));\r\n });\r\n });\r\n};\r\n\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy(e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\n\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n // res.push(await solve(n, a, b, d));\r\n const ans = await parseJSAsync(`\r\n const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');\r\n parentPort.postMessage(solve(...workerData))\r\n function solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = u => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n dfs(v);\r\n low[u] = Math.min(low[u], low[v]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n };\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n }\r\n `, [n, a, b, d])\r\n res.push(ans)\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(n, a, b, d) {\r\n const MOD = BigInt(10 ** 9 + 7);\r\n const set = new Set();\r\n {\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => [0, 0]);\r\n for (let i = 0; i < n; i++) {\r\n g[a[i]][0] = i;\r\n g[b[i]][1] = i;\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] !== 0) {\r\n const queue = [a[i], b[i]];\r\n for (let j of queue) {\r\n set.add(j);\r\n for (let k of [b[g[j][0]], a[g[j][1]]]) {\r\n if (set.has(k)) continue;\r\n queue.push(k);\r\n }\r\n }\r\n } else if (a[i] === b[i]) {\r\n set.add(a[i]);\r\n }\r\n }\r\n }\r\n const g = Array.from({\r\n length: n + 1\r\n }, () => new Set());\r\n for (let i = 0; i < n; i++) {\r\n if (d[i] === 0) {\r\n const u = a[i],\r\n v = b[i];\r\n if (set.has(u) || set.has(v)) continue;\r\n g[u].add(v);\r\n g[v].add(u);\r\n }\r\n }\r\n const tarjan = async () => {\r\n const dfn = [],\r\n low = [],\r\n stack = [],\r\n set = new Set(),\r\n map = new Map();\r\n let time = 1,\r\n idx = 0;\r\n const dfs = RTI((u, p) => {\r\n const before = () => {\r\n dfn[u] = low[u] = time++;\r\n stack.push(u);\r\n set.add(u);\r\n };\r\n const inside = () => {\r\n let res = [];\r\n for (let v of g[u]) {\r\n if (!dfn[v]) {\r\n res.push([v, u]);\r\n } else if (set.has(v)) {\r\n low[u] = Math.min(low[u], dfn[v]);\r\n }\r\n }\r\n return res;\r\n };\r\n const after = () => {\r\n if (dfn[u] === low[u]) {\r\n while (true) {\r\n const j = stack.pop();\r\n set.delete(j);\r\n map.set(j, idx);\r\n if (j === u) break;\r\n }\r\n idx++;\r\n }\r\n if (p !== -1) low[p] = Math.min(low[p], low[u]);\r\n };\r\n return [before, inside, after];\r\n });\r\n for (let i = 1; i <= n; i++) {\r\n if (!dfn[i] && g[i].size) dfs(i, -1);\r\n }\r\n return BigInt(2) ** BigInt(idx) % MOD;\r\n };\r\n return tarjan();\r\n}\r\nfunction RTI(fn) {\r\n const done = () => {};\r\n const dfs = (...args) => {\r\n const callStack = [[done, args]];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (((_curCall = curCall) === null || _curCall === void 0 ? void 0 : _curCall.length) === 1) {\r\n var _curCall;\r\n const after = curCall.pop();\r\n after();\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall && curCall.length > 1) curCall.pop();\r\n }\r\n if (!curCall) break;\r\n const args = curCall[curCall.length - 1];\r\n const [before, inside, after] = fn(...args);\r\n before();\r\n let nextCall = inside();\r\n callStack.push([after, ...nextCall]);\r\n }\r\n };\r\n return dfs;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const b = (await read()).split(' ').map(Number);\r\n const d = (await read()).split(' ').map(Number);\r\n res.push(await solve(n, a, b, d));\r\n }\r\n console.log(res.map(num => num.toString()).join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const cache = Array.from({\r\n length: n\r\n }, () => [-1, -1]);\r\n const dfs = (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n if (cache[i][state] !== -1) return cache[i][state];\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));\r\n }\r\n }\r\n st[i] = 0;\r\n cache[i][state] = res;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n const add = (i, j) => {\r\n g[i].push(j);\r\n };\r\n for (let [i, j] of a) {\r\n add(i - 1, j - 1);\r\n add(j - 1, i - 1);\r\n }\r\n g[0].push(-1);\r\n const st = new Array(n).fill(0);\r\n const dfs = (i, state) => {\r\n if (st[i] !== 0) return 0;\r\n st[i] = 1;\r\n let res = 0;\r\n if (state === 1) {\r\n res = 1;\r\n for (let j of g[i]) {\r\n res += dfs(j, 1);\r\n }\r\n } else {\r\n if (g[i].length === 2) {\r\n res = dfs(g[i].filter(j => !st[j])[0], 1) - 1;\r\n } else if (g[i].length > 2) {\r\n const [a, b] = g[i].filter(j => !st[j]);\r\n res = Math.max(dfs(a, 0) + dfs(b, 1) - 1, dfs(a, 1) - 1 + dfs(b, 0));\r\n }\r\n }\r\n st[i] = 0;\r\n return res;\r\n };\r\n return dfs(0, 0);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, a));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}], "src_uid": "11452ff3750578d8b2ac5b76ba2749fd"} {"source_code": "var n = parseInt(readline());\nvar is_possible = false;\nvar seat_config = [];\n\nfor(var i = 0; i < n; i++) {\n \n var tokens = readline().split(\"|\");\n for(var j = 0; j <= 1; j++) {\n \n if(tokens[j] == \"OO\") {\n \n if(!is_possible) {\n is_possible = true;\n tokens[j] = \"++\";\n }\n }\n }\n \n seat_config[i] = tokens[0] + \"|\" + tokens[1];\n}\n\nprint(is_possible ? 'YES' : 'NO');\nif(is_possible)\n print(seat_config.join(\"\\n\"));", "positive_code": [{"source_code": "var rowNum = readline(),\n rows = [],\n hasSeat = false;\n\nfor (var i = 0; i < rowNum; i++) {\n rows[i] = readline().split('');\n if (rows[i][0] === rows[i][1] && rows[i][0] === 'O' && !hasSeat) {\n hasSeat = true;\n rows[i][0] = '+';\n rows[i][1] = '+';\n }\n if (rows[i][3] === rows[i][4] && rows[i][3] === 'O' && !hasSeat) {\n hasSeat = true;\n rows[i][3] = '+';\n rows[i][4] = '+';\n }\n}\n\nif (hasSeat === false) {\n print('NO');\n} else {\n print('YES');\n for (var i = 0; i < rowNum; i++) {\n print(rows[i].join(''));\n }\n}"}, {"source_code": "var n = +readline();\nvar obj = {}, str, b = false, res = \"\";\n\nfor(var i = 0; i < n; i++) {\n str = readline();\n if (!b) {\n str = str.replace(\"OO\", \"++\");\n if ( str.indexOf(\"++\") != -1 )\n b = true;\n }\n res += str + '\\n';\n}\n\nif (b) {\n print(\"YES\");\n print(res);\n} else \n print(\"NO\");\n//print(res);\n"}, {"source_code": "var n;\nvar arr=[];\n\nn = readline();\nfor(var i = 0;i print(s))\n} else \n print('NO')"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return 'OO|OX';\n case 3: return 'XO|XX';\n case 4: return 'OX|OO';\n case 5: return 'XX|OX';\n case 6: return 'OO|OO';\n case 7: return 'OO|XX';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = [];\nvar yes = false;\n\nfor (var i = 0; i < n; i ++) {\n var s = readline();\n\n if (!yes) {\n if (s[0] == 'O' && s[1] == 'O') {\n yes = true;\n s = '++' + s.substr(2, 3);\n } else if (s[3] == 'O' && s[4] == 'O') {\n yes = true;\n s = s.substr(0, 3) + '++';\n }\n }\n\n a.push(s);\n}\n\nif (yes) {\n write('YES\\n');\n write(a.join('\\n'));\n} else {\n write('NO');\n}\n"}, {"source_code": "var n = parseInt(readline());\nvar pattern = /OO/;\nvar rows = [];\nvar found = false;\nfor ( var i = 0; i < n; ++i ) {\n var row = readline();\n if ( !found && row.match( pattern ) ) {\n row = row.replace( pattern, \"++\" );\n found = true;\n\n }\n rows.push( row );\n}\n\nif (found) {\n print( \"YES\" );\n print( rows.join( \"\\n\" ) );\n} else {\n print( \"NO\" );\n}\n"}, {"source_code": "var n = parseInt(readline());\n\nvar bus = [];\nvar seatAvailable = false;\n\nfor (var i = 0; i < n; i++) {\n \n var seats = readline().split(\"|\");\n \n if (!seatAvailable && seats.includes('OO')) {\n \n var index = seats.indexOf('OO');\n \n seats[index] = '++';\n \n seatAvailable = true;\n }\n \n bus.push(seats.join('|'));\n}\n\nif (seatAvailable) {\n print('YES');\n \n for (var j = 0; j < n; j++) {\n print(bus[j]);\n }\n \n} else {\n print('NO');\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/711/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n console.log(main()); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nconst main = () => {\n const inputs = [];\n let isFound = false;\n let result = \"\";\n const inputCount = readline();\n \n for (let i = 0; i < inputCount; i+= 1) {\n let input = readline();\n \n if (!isFound && input.indexOf(\"OO\") >= 0) {\n isFound = true\n \n input = input.replace(\"OO\", \"++\")\n }\n \n if (i + 1 === inputCount) {\n result += input\n } else {\n result += input + '\\n'\n }\n }\n \n if (!isFound) {\n return \"NO\";\n }\n \n return \"YES\\n\" + result;\n}"}, {"source_code": "function main() {\n // write code here:\n const n = Number(stdin[0]);\n var say;\n var reg = /OO/;\n for (let i = 1; i <= n; i++) {\n if (reg.test(stdin[i])) {\n stdin[0] = 'YES';\n stdin[i] = stdin[i].replace(reg, '++');\n break;\n } else {\n stdin[0] = 'NO';\n }\n }\n if (stdin[0] === 'YES') {\n for (let j = 0; j <= n; j++) {\n console.log(stdin[j]);\n }\n } else {\n console.log(stdin[0]);\n }\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let _res = 'NO'\n let finish = false\n let count = 0\n let places = [...input.slice(1)]\n while (!finish) {\n if (count < places.length) {\n const el = places[count]\n if (el.match(/(OO)/g)) {\n places[count] = places[count].replace('OO', '++')\n _res = 'YES'\n finish = true\n }\n } else {\n finish = true\n }\n count++\n }\n if (_res === 'YES')\n console.log(_res + '\\n' + places.join('\\n'))\n else\n console.log(_res)\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = new Array(N);\n var isOK = false;\n for(var i = 0; i < N; i++){\n var tmp = next();\n if(!isOK && tmp.indexOf(\"OO\") != -1){\n isOK = true;\n tmp = tmp.replace(\"OO\", \"++\");\n }\n list[i] = tmp;\n }\n if(isOK){\n myout(\"YES\");\n myout(myconv(list, 9));\n }else{\n myout(\"No\");\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 'NO';\nconst arr = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (d.includes('OO') && ans === 'NO') {\n ans = 'YES';\n arr.push(d.replace('OO', '++'));\n }\n else {\n arr.push(d);\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n\n if (ans === 'YES') {\n for (let i = 0; i < arr.length; i++) {\n console.log(arr[i]);\n }\n }\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n\n const answer = []; let find = false;\n input.forEach((x, i) => {\n if (i === 0) return;\n\n let line = x.split('|');\n \n if (line[0][0] === 'O' && line[0][1] === 'O' && !find) {\n answer.push(`++|${line[1]}`); find = true;\n } else if (line[1][0] === 'O' && line[1][1] === 'O' && !find) {\n answer.push(`${line[0]}|++`); find = true;\n } else {\n answer.push(`${line[0]}|${line[1]}`);\n }\n });\n\n if (!find) {\n console.log('NO');\n } else {\n console.log('YES');\n answer.forEach(x => console.log(x));\n }\n}); "}, {"source_code": "function findAndCaptureSeats(config) {\n let regex = new RegExp('OO');\n let spaced = config.join(' ');\n if (regex.test(spaced)) {\n let seated = spaced.replace(regex, '++');\n seated = 'YES ' + seated;\n return seated.split(' ');\n }\n return ['NO'];\n}\n\nfunction processData(input) {\n let arr = input.split('\\n');\n arr = arr.slice(1, arr.length);\n let config = findAndCaptureSeats(arr);\n for (let index = 0; index < config.length; index++) {\n console.log(config[index]);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "var res = sol(readline());\nprint(res);\n\nfunction sol(line1) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n\n var result = \"NO\";\n var seat = [];\n var isSeated = false;\n\n for (var i = 0; i < n; i++) {\n var row = readline();\n\n if (!isSeated && row.toString().indexOf(\"OO\") > -1) {\n result = \"YES\";\n row = row.toString().replace(\"OO\", \"++\", 1);\n seat.push(row);\n isSeated = true;\n }else{\n seat.push(row);\n }\n }\n\n if(result == \"YES\") {\n return result + \"\\n\" + seat.join(\"\\n\");\n }else{\n return result;\n }\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n console.log(main()); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nconst main = () => {\n const inputs = [];\n let isFound = false;\n let result = \"\";\n const inputCount = readline();\n \n for (let i = 0; i < inputCount; i+= 1) {\n let input = readline();\n \n if (!isFound && input.indexOf(\"OO\") >= 0) {\n isFound = true\n \n input = input.replace(\"OO\", \"++\")\n }\n \n if (i + 1 === inputCount) { // To remove last new line\n result += input\n }\n\n result += input + '\\n'\n }\n \n if (!isFound) {\n return \"NO\\n\" + result;\n }\n \n return \"YES\\n\" + result;\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n console.log(main()); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const inputs = [];\n let isFound = false;\n let result = \"\";\n const inputCount = readline();\n \n for (let i = 0; i < inputCount; i+= 1) {\n let input = readline();\n \n if (!isFound && input.indexOf(\"OO\") >= 0) {\n isFound = true\n \n input = input.replace(\"OO\", \"++\")\n }\n \n result += input + '\\n'\n }\n \n if (!isFound) {\n return \"NO\\n\" + result;\n }\n \n return \"YES\\n\" + result;\n}"}, {"source_code": "function main() {\n // write code here:\n const n = Number(stdin[0]);\n var say;\n var reg = /OO/g;\n for (let i = 1; i <= n; i++) {\n if (reg.test(stdin[i])) {\n stdin[0] = 'YES';\n stdin[i] = stdin[i].replace(reg, '++');\n break;\n } else {\n stdin[0] = 'NO';\n }\n }\n for(let j=0;j<=n;j++){\n console.log(stdin[j]);\n }\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "function main() {\n // write code here:\n const n = Number(stdin[0]);\n var say;\n var reg = /OO/g;\n for (let i = 1; i <= n; i++) {\n if (reg.test(stdin[i])) {\n stdin[0] = 'YES';\n stdin[i] = stdin[i].replace(reg, '++');\n break;\n } else {\n stdin[0] = 'NO';\n }\n }\n if (stdin[0] === 'YES') {\n for (let j = 0; j <= n; j++) {\n console.log(stdin[j]);\n }\n } else {\n console.log(stdin[0]);\n }\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let _res = 'NO'\n let finish = false\n let count = 0\n let places = [...input.slice(1)]\n while (!finish) {\n if (count < places.length) {\n const el = places[count]\n if (el.match(/(OO)/g)) {\n places[count] = places[count].replace(/(OO)/g, '++')\n _res = 'YES'\n finish = true\n }\n } else {\n finish = true\n }\n count++\n }\n if (_res === 'YES')\n console.log(_res + '\\n' + places.join('\\n'))\n else\n console.log(_res)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let _res = 'NO'\n let finish = false\n let count = 0\n let places = [...input.slice(1)]\n while (!finish) {\n if (count < places.length) {\n const el = places[count]\n if (el.match(/(OO)/g)) {\n places[count] = places[count].replace(/(OO)/g, '++')\n _res = 'YES'\n finish = true\n }\n } else {\n finish = true\n }\n count++\n }\n console.log(_res + '\\n' + places.join('\\n'))\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = 'NO';\nconst arr = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (d.includes('OO') && ans === 'NO') {\n ans = 'YES';\n arr.push(d.replace('OO', '++'));\n }\n else {\n arr.push(d);\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n for (let i = 0; i < arr.length; i++) {\n console.log(arr[i]);\n }\n});\n"}, {"source_code": "function findAndCaptureSeats(config) {\n console.log(config);\n let regex = new RegExp('OO');\n let spaced = config.join(' ');\n let seated = spaced.replace(regex, '++');\n return seated.split(' ');\n}\n\nfunction processData(input) {\n let arr = input.split('\\n');\n arr = arr.slice(1, arr.length);\n let config = findAndCaptureSeats(arr);\n for (let index = 0; index < config.length; index++) {\n console.log(config[index]);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "function findAndCaptureSeats(config) {\n console.log(config);\n let regex = new RegExp('OO');\n let spaced = config.join(' ');\n if (regex.test(spaced)) {\n let seated = spaced.replace(regex, '++');\n seated = 'YES ' + seated;\n return seated.split(' ');\n }\n return ['NO'];\n}\n\nfunction processData(input) {\n let arr = input.split('\\n');\n arr = arr.slice(1, arr.length);\n let config = findAndCaptureSeats(arr);\n for (let index = 0; index < config.length; index++) {\n console.log(config[index]);\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": "var res = sol(readline());\nprint(res);\n\nfunction sol(line1) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n\n var result = \"NO\";\n var seat = [];\n var isSeated = false;\n\n for (var i = 0; i < n; i++) {\n var row = readline();\n\n if (!isSeated && row.toString().indexOf(\"OO\") > -1) {\n result = \"YES\";\n row = row.toString().replace(\"OO\", \"++\", 1);\n seat.push(row);\n isSeated = true;\n }else{\n seat.push(row);\n }\n }\n\n return result + \"\\n\" + seat.join(\"\\n\");\n}"}, {"source_code": "var rowNum = readline(),\n rows = [],\n hasSeat = false;\n\nfor (var i = 0; i < rowNum; i++) {\n rows[i] = readline().split('');\n if (hasSeat) continue;\n hasSeat = true;\n if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {\n rows[i][0] = '+';\n rows[i][1] = '+';\n }\n \n if (rows[i][3] === rows[i][4] && rows[i][3] === 'O') {\n rows[i][3] = '+';\n rows[i][4] = '+';\n }\n}\n\nif (hasSeat === false) {\n print('NO');\n} else {\n print('YES');\n for (var i = 0; i < rowNum; i++) {\n print(rows[i].join(''));\n }\n}\n"}, {"source_code": "var rowNum = readline(),\n rows = [],\n hasSeat = false;\n\nfor (var i = 0; i < rowNum; i++) {\n rows[i] = readline().split('');\n if (hasSeat) continue;\n hasSeat = true;\n if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {\n rows[i][0] = '+';\n rows[i][1] = '+';\n }\n \n if (rows[i][3] === rows[i][4] && rows[i][0] === 'O') {\n rows[i][3] = '+';\n rows[i][4] = '+';\n }\n}\n\nif (hasSeat === false) {\n print('NO');\n} else {\n print('YES');\n for (var i = 0; i < rowNum; i++) {\n print(rows[i].join(''));\n }\n}\n"}, {"source_code": "var rowNum = readline(),\n rows = [],\n hasSeat = false;\n\nfor (var i = 0; i < rowNum; i++) {\n rows[i] = readline().split('');\n if (hasSeat) continue;\n if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {\n hasSeat = true;\n rows[i][0] = '+';\n rows[i][1] = '+';\n }\n \n if (rows[i][3] === rows[i][4] && rows[i][0] === 'O') {\n hasSeat = true;\n rows[i][3] = '+';\n rows[i][4] = '+';\n }\n}\n\nif (hasSeat === false) {\n print('NO');\n} else {\n print('YES');\n for (var i = 0; i < rowNum; i++) {\n print(rows[i].join(''));\n }\n}\n"}, {"source_code": "var rowNum = readline(),\n rows = [],\n hasSeat = false;\n\nfor (var i = 0; i < rowNum; i++) {\n rows[i] = readline().split('');\n if (hasSeat) continue;\n if (rows[i][0] === rows[i][1] && rows[i][0] === 'O') {\n hasSeat = true;\n rows[i][0] = '+';\n rows[i][1] = '+';\n }\n \n if (rows[i][3] === rows[i][4] && rows[i][3] === 'O') {\n hasSeat = true;\n rows[i][3] = '+';\n rows[i][4] = '+';\n }\n}\n\nif (hasSeat === false) {\n print('NO');\n} else {\n print('YES');\n for (var i = 0; i < rowNum; i++) {\n print(rows[i].join(''));\n }\n}"}, {"source_code": "var n = parseInt(readline());\nvar is_possible = false;\nvar seat_config = [];\n\nfor(var i = 0; i < n; i++) {\n \n var tokens = readline().split(\"|\");\n for(var j = 0; j <= 1; j++) {\n \n if(tokens[j] == \"OO\") {\n \n if(!is_possible) {\n is_possible = true;\n tokens[j] = \"++\";\n }\n }\n }\n \n seat_config[i] = tokens[0] + \"|\" + tokens[1];\n}\n\nprint(is_possible ? 'YES' : 'NO');\nprint(seat_config.join(\"\\n\"));"}, {"source_code": "var n = readline();\nvar reg = /OO/\nvar str = \"\";\n\t\nfor (var i=0; i print(s))\n} else \n print('NO')"}, {"source_code": "if (!readline) {\n var _i = 0;\n var readline = function() {\n _i ++;\n\n switch (_i) {\n case 1: return '6';\n case 2: return 'OO|OX';\n case 3: return 'XO|XX';\n case 4: return 'OX|OO';\n case 5: return 'XX|OX';\n case 6: return 'OO|OO';\n case 7: return 'OO|XX';\n }\n }\n\n var write = console.log;\n}\n\nvar n = +readline();\nvar a = [];\nvar yes = false;\n\nfor (var i = 0; i < n; i ++) {\n var s = readline();\n\n if (!yes) {\n if (s[0] == 'O' && s[1] == 'O') {\n yes = true;\n s = '++' + s.substr(2, 3);\n } else if (s[3] == 'O' && s[4] == 'O') {\n yes = true;\n s = s.substr(0, 3) + '++';\n }\n }\n\n a.push(s);\n}\n\nif (yes) {\n write('YES');\n write(a.join('\\n'));\n} else {\n write('NO');\n}\n"}], "src_uid": "e77787168e1c87b653ce1f762888ac57"} {"source_code": "l=readline;\r\n\r\nfor (T=l(); T--;) {\r\n \r\n k = l().split(' ')\r\n N = +k[0];\r\n k = +k[1];\r\n \r\n A = [1]\r\n \r\n i = 2;\r\n for (; i < N && k--; ) {\r\n A.push(N--)\r\n A.push(i++);\r\n }\r\n \r\n for (; i <= N;) A.push(i++);\r\n \r\n print(k > 0 ? -1 : A.join(' '));\r\n}", "positive_code": [{"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n let [n, k] = get_ints();\r\n let a = [];\r\n let b = new Array(n);\r\n let flag = true;\r\n if(n/k <= 2)\r\n {\r\n print(-1);\r\n continue;\r\n }\r\n for(let i = 1 ; i <= n; i++)\r\n {\r\n a.push(i);\r\n }\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n b[i] = a.shift();\r\n if(k !== 0 )\r\n {\r\n i++;\r\n b[i] = a.pop();\r\n k--;\r\n }\r\n }\r\n if(flag) print(b.join(' '));\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tif(K * 2 + 1 > N){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = new Array(N);\r\n\t\tfor(var j = 0; j < K; j++){\r\n\t\t\toutput[j * 2 + 1] = N - j;\r\n\t\t}\r\n\t\tvar now = 1;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(output[j] == null){\r\n\t\t\t\toutput[j] = now;\r\n\t\t\t\tnow++; \r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\nconst readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n }\n)\n\nlet count = -1\nlet inputArr = []\n\nrl.on('line', data => {\n if (count === -1) {\n count = +data\n } else if (count !== 0) {\n inputArr.push(data.trim())\n count--\n }\n // max number 2^(53) - 1 ~~ 10^(15)\n if (count === 0) {\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\n main()\n process.exit(0)\n }\n})\n\nfunction solve([n, k]) {\n let arr = [...Array(n).keys()].map(i => i + 1)\n if (k + 1 > Math.floor((n + 1) / 2) || n < 3 && k > 0) {\n console.log('-1')\n return\n }\n if (k === 0) {\n console.log(arr.join(' '))\n return\n }\n let arr2 = [], flag = false\n arr2.push(1)\n for (let i = 2; i <= n; ++i) {\n if (k > 0 && i % 2 === 0) {\n arr2.push(i + 1)\n k--\n } else {\n if (k > 0) arr2.push(i - 1)\n else {\n if (flag) arr2.push(i)\n else {\n arr2.push(i - 1)\n flag = true\n }\n }\n }\n }\n console.log(arr2.join(' '))\n}\n\nfunction main() {\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if( n % 2===1 && k> Math.floor(n/2)) return console.log(-1)\r\n if( n % 2===0 && k>= Math.floor(n/2)) return console.log(-1)\r\n\r\n var ans = new Array(n)\r\n for (let j = 0; j < n; j++) {\r\n if(j % 2 ===1 && k >0){\r\n ans[j] = j+1\r\n ans[j+1] = j\r\n j++\r\n k--\r\n continue\r\n }\r\n ans[j] = j\r\n }\r\n\r\n console.log(ans.map(x=>x+1).join(' '))\r\n\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "const t = readline();\n\nfor (var i = 0; i < parseInt(t); i++) {\n var input = readline().split(' ').map(d => parseInt(d));\n var n = input[0];\n var k = input[1];\n if (k >= parseInt((n + 1) / 2))\n print(-1);\n else {\n var a = [];\n var j = 1;\n var p = 0;\n var pk = 0;\n while (p < (n % 2? n - 1: n)) {\n a.push(j);\n p++;\n if (pk < k) {\n a.push(n - j + 1);\n p++;\n pk++;\n }\n j++;\n }\n if (n % 2)\n a.push(j);\n a.forEach((num) => write(num + ' '));\n write('\\n');\n }\n}\n"}], "negative_code": [{"source_code": "\r\n'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(readLine());\r\n while(testCases--)\r\n {\r\n let [n, k] = get_ints();\r\n let a = [];\r\n let b = new Array(n);\r\n let flag = true;\r\n if(n/k <= 2)\r\n {\r\n print(-1);\r\n continue;\r\n }\r\n for(let i = 1 ; i <= n; i++)\r\n {\r\n a.push(i);\r\n }\r\n for(let i = 0 ; i < n; i++)\r\n {\r\n if(k !== 0 )\r\n {\r\n if(isNaN(a[i+2])){\r\n b[i] = a[i+1];\r\n b[i+1] = a[i];\r\n k--;\r\n break;\r\n }\r\n b[i] = a[i];\r\n b[i + 1] = a[i+2];\r\n b[i + 2] = a[i+1];\r\n i+=2;\r\n k--;\r\n }\r\n else\r\n {\r\n b[i] = a[i];\r\n }\r\n }\r\n if(flag && k === 0) print(b.join(' '))\r\n else print(-1)\r\n }\r\n \r\n});\r\n \r\nfunction print(c){\r\n return console.log(c);\r\n}\r\n \r\nfunction get_ints() { \r\n return readLine().split(' ').map(Number)\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}"}, {"source_code": "const t = readline();\n\nfor (var i = 0; i < parseInt(t); i++) {\n var input = readline().split(' ').map(d => parseInt(d));\n var n = input[0];\n var k = input[1];\n if (k >= parseInt((n + 1) / 2))\n print(-1);\n else {\n var a = [];\n var j = 1;\n var kp = 0;\n while (j <= parseInt(n / 2)) {\n a.push(j);\n if (kp < k) {\n a.push(n - j + 1);\n kp++;\n j++;\n } else {\n a.push(j + 1);\n j += 2;\n }\n }\n if (n % 2)\n a.push(j);\n a.forEach((num) => write(num + ' '));\n write('\\n');\n }\n}\n"}, {"source_code": "const t = readline();\n\nfor (var i = 0; i < parseInt(t); i++) {\n var input = readline().split(' ').map(d => parseInt(d));\n var n = input[0];\n var k = input[1];\n if (k >= parseInt((n + 1) / 2))\n print(-1);\n else {\n var a = [];\n var j = 1;\n while (j <= parseInt(n / 2)) {\n a.push(j);\n a.push(n - j + 1);\n j++;\n }\n if (n % 2)\n a.push(j);\n a.forEach((num) => write(num + ' '));\n print('\\n');\n }\n}\n"}, {"source_code": "const t = readline();\n\nfor (var i = 0; i < parseInt(t); i++) {\n var input = readline().split(' ').map(d => parseInt(d));\n var n = input[0];\n var k = input[1];\n if (k >= parseInt((n + 1) / 2))\n write(-1);\n else {\n var a = [];\n var j = 1;\n while (j <= parseInt(n / 2)) {\n a.push(j);\n a.push(n - j + 1);\n j++;\n }\n if (n % 2)\n a.push(j);\n a.forEach((num) => write(num + ' '));\n }\n}\n"}, {"source_code": "const t = readline();\n\nfor (var i = 0; i < t; i++) {\n const input = readline().split(' ').map(d => parseInt(d));\n const n = input[0];\n const k = input[1];\n if (k >= parseInt((n + 1) / 2))\n write(-1);\n else {\n var a = [];\n var j = 1;\n while (j <= parseInt(n / 2)) {\n a.push(j);\n a.push(n - j + 1);\n j++;\n }\n if (n % 2)\n a.push(j);\n a.forEach((num) => write(num + ' '));\n }\n}\n"}, {"source_code": "//const t = readline().split(' ').map((d) => parseInt(d));\nconst t = readline();\n\nfor (var i = 0; i < t; i++) {\n const n = readline();\n const k = readline();\n if (k >= parseInt((n + 1) / 2))\n print(-1);\n else {\n var a = [];\n var j = 1;\n for ( ; j <= parseInt(n / 2); j++) {\n a.push(j);\n a.push(n - j + 1);\n }\n if (n % 2)\n a.push(j);\n a.forEach(num => print(num));\n }\n}\n"}, {"source_code": "l=readline;\r\n\r\nfor (T=l(); T--;) {\r\n \r\n k = l().split(' ')\r\n N = +k[0];\r\n k = +k[1];\r\n \r\n A = [1]\r\n \r\n i = 2;\r\n for (; i < N && k--; ) {\r\n A.push(N--)\r\n A.push(i++);\r\n }\r\n \r\n for (; i <= N;) A.push(i++);\r\n \r\n print(k > 0 ? -1 : A);\r\n}"}], "src_uid": "b4bb11ea4650ead54026453ea9a76f39"} {"source_code": "read = +readline();\nvar pts = readline().split(' ').map(Number);\nvar max = pts[0];\nvar min = pts[0];\nvar ct = 0;\nfor (var i = 1; i < pts.length; i++) {\n\t\t\t\t if(pts[i] > max)\n\t\t\t\t \t\t\t ct++,max=pts[i];\n\t\t\t\t if(pts[i] < min)\n\t\t\t\t \t\t\t ct++,min=pts[i];\n}\nwrite(ct);", "positive_code": [{"source_code": "var n=+readline();\n\nvar a=readline().split(' ').map(function(v){return +v;});\n\nvar min=a[0];\nvar max=a[0];\nvar ans=0;\nfor(var i=1; imax){\n\t\tans++;\n\t\tmax=a[i];\n\t}else if(a[i] max){\n\t\tmax = +challenges[i];\n\t\ta++;\n\t}\n\telse if(+challenges[i] < min){\n\t\tmin = +challenges[i];\n\t\ta++;\n\t}\n}\n\nwrite(a);"}, {"source_code": "var num = parseInt(readline());\nvar nums = readline().split(' ').map( function(a) {return parseInt(a);} );\nvar min = nums[0]; var max = nums[0];\nvar res = 0;\nfor (var i = 1; i < num; i++) {\n if (nums[i] > max) {\n res++;\n max = nums[i];\n } else if (nums[i] < min) {\n res++;\n min = nums[i];\n }\n}\nprint(res);\n"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar s = readline().split(' ').map(function (x) { return parseInt(x); });\n\tvar x = 0;\n\tvar min = s[x];\n\tvar max = s[x];\n\n\tfor (var i = 1; i < n; i++) \n\t\tif ( min > s[i] ) {\n\t\t\tx++;\n\t\t\tmin = s[i];\n\t\t} else if ( max < s[i] ) {\n\t\t\tx++;\n\t\t\tmax = s[i];\n\t\t}\n\n\tprint(x);\n\n}).call(this);"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function () {\n readline();\n let array = readline().getNumArray(),\n min = array[0],\n max = array[0],\n counter = 0;\n\n for (let i = 1; i < array.length; i++) {\n if (array[i] > max) {\n max = array[i];\n counter++;\n } else if (array[i] < min) {\n min = array[i];\n counter++;\n }\n }\n write(counter);\n})();"}, {"source_code": "\tvar n = readline();//readline().split(\" \");\n\tvar str = readline().split(\" \");\n\tvar max = +str[0], min = +str[0];\n\tvar res = 0;\n\tfor (var i=0; i<+n; i++){\n\t\tif (+str[i]>max){\n\t\t\tmax = +str[i];\n\t\t\tres++;\n\t\t}\n\t\telse if (+str[i] curMax) {\n miracle++;\n curMax = s[i];\n }\n if (s[i] < curMin){\n miracle++;\n curMin = s[i];\n }\n}\n\nprint(miracle);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [max, min] = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];\n let count = 0;\n\n for (let i = 0; i < len; i++) {\n if (i > 0) {\n if (arr[i] > max) count++;\n if (arr[i] < min) count++;\n }\n max = Math.max(max, arr[i]);\n min = Math.min(min, arr[i]);\n }\n console.log(count);\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var min = list[0];\n var max = list[0];\n var output = 0;\n for(var i = 1; i < N; i++){\n if(min > list[i]){\n min = list[i];\n output++;\n }\n if(max < list[i]){\n max = list[i];\n output++;\n }\n }\n myout(output);\n}\n"}, {"source_code": "//I_love_%username%\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL)[1].split(' ').map(c => +c);\n \n let max = lines[0], min = lines[0];\n let amazcount = 0;\n for(let i = 1; i < lines.length; i++) {\n \tif(lines[i] > max) {\n \t\tmax = lines[i];\n \t\tamazcount++;\n \t}\n \tif(lines[i] < min) {\n \t\tmin = lines[i];\n \t\tamazcount++;\n \t}\n }\n\n process.stdout.write(amazcount + '');\n\n return;\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = 0;\n const res = d.split(' ').map(Number);\n let min = max = res[0];\n\n for (let i = 0; i < res.length; i++) {\n if (res[i] < min) {\n ans++;\n min = res[i];\n }\n\n if (res[i] > max) {\n ans++;\n max = res[i];\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "n = +readline();\n numbers = [];\n tokens = readline().split(' ');\n for (i = 0; i < n; i++) {\n numbers[i] = +tokens[i];\n }\n\n max = numbers[0];\n min = numbers[0];\n amazing = 0;\n\n for (i = 0; i < n; i++) {\n if (numbers[i] > max) {\n max = numbers[i];\n amazing++;\n }\n if (numbers[i] < min) {\n min = numbers[i];\n amazing++;\n }\n }\n print(amazing);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let nums = input[1].split(' ').map(x => parseInt(x));\n let min = nums[0], max = nums[0];\n \n let answ = 0;\n nums.forEach((x, i) => { \n if (i === 0) return;\n \n if (x > max) { answ += 1; max = x; }\n if (x < min) { answ += 1; min = x; }\n });\n\n console.log(answ);\n}); \n"}, {"source_code": "var temporary = readline();\nvar inputedNumbers = readline().split(' ');\nvar resultArray = [];\nvar marksQuantity = 0;\n \n \ninputedNumbers.forEach(\n function(current)\n {\n current = +current;\n if (current > getArrayMaximum(resultArray) || current < getArrayMinimum(resultArray))\n {\n marksQuantity++;\n }\n resultArray.push(current);\n });\nprint(marksQuantity-1);\n \nfunction getArrayMaximum(array)\n{ \n return Math.max.apply(null, array);\n }\n\nfunction getArrayMinimum(array)\n{ \n return Math.min.apply(null, array);\n }"}, {"source_code": "n = readline().split(' ').map(Number);\nresults = readline().split(' ').map(Number);\nmin = max = results[0];\namazingness = 0;\nfor (i = 1; i< results.length; i++){\n\tif (results[i]max){\n\t\tmax = results[i];\n\t\tamazingness++;\n\t}\n}\nprint(amazingness);\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet points = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet worse = points[0];\n\tlet best = points[0];\n\tlet amazing = 0;\n\n\tfor (let i = 1; i < n; ++i) {\n\t\tif (points[i] < worse) {\n\t\t\tworse = points[i];\n\t\t\tamazing++;\n\t\t}\n\t\tif (points[i] > best) {\n\t\t\tbest = points[i];\n\t\t\tamazing++;\n\t\t}\n\t}\n\n\tconsole.log(amazing);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let numberOfContests = parseInt(readLine());\n let numbersArray = readLine().split(' ').map(Number);\n let max = numbersArray[0];\n let min = numbersArray[0];\n let count = 0;\n for (let i = 0; i < numberOfContests; i++) {\n if (numbersArray[i] > max) {\n max = numbersArray[i];\n count++;\n }\n\n if (numbersArray[i] < min) {\n count++;\n min = numbersArray[i];\n }\n }\n\n console.log(count);\n}\n\n// [100, 50, 200, 150, 200]\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let points = inputs[1].trim().split(' ').map(num => Number(num));\n let amazingPoints = 0;\n let best = worst = points[0];\n for (let index = 1; index <= points.length - 1; index++) {\n\n if (points[index] > best) {\n best = points[index];\n amazingPoints++;\n }\n\n if (points[index] < worst) {\n worst = points[index];\n amazingPoints++;\n }\n }\n\n return amazingPoints.toString();\n}\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(v => parseInt(v));\n let best = arr[0];\n let worst = arr[0];\n let ans = 0;\n for (var i = 1; i < n; i++) {\n if (arr[i] > best) {\n ans++;\n best = arr[i];\n }\n if (arr[i] < worst) {\n ans++;\n worst = arr[i];\n }\n }\n console.log(ans);\n}"}, {"source_code": "readline()\nT=readline().split(' ').map(Number)\nprint(T.slice(1).reduce((a,c)=>{\n\ta.a += Number(cmaxPoint) {\n maxPoint = +tableResult[perfomance];\n amazingPerfomance++;\n }\n}\nprint(amazingPerfomance);\n"}], "negative_code": [{"source_code": "\nvar n=+readline();\n\nvar a=readline().split(' ').map(function(v){return +v;});\n\nvar min=a[0];\nvar max=a[1];\nvar ans=0;\nfor(var i=1; imax){\n\t\tans++;\n\t\tmax=a[i];\n\t}else if(a[i]+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}\nvar res = 1;\n\tfor (var i=2; imax)\n\t\t {\n\t\t\t\tres++;\n\t\t\t\tmax = +str[i];\n\t\t }\n\t\t else if (str[i]1?print(res):print(0);"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar min =0; var max = 0;\nif (+str[0]>+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}\nvar res = 1;\n\tfor (var i=2; imax)\n\t\t {\n\t\t\t\tres++;\n\t\t\t\tmax = +str[i];\n\t\t }\n\t\t else if (str[i] cur[i] || s[i] < cur[i]) {\n miracle++;\n }\n cur.push(s[i]);\n}\n\nprint(Math.floor(miracle/2));"}, {"source_code": "read = +readline();\nvar pts = readline().split(' ');\nvar max = pts[0];\nvar min = pts[0];\nvar ct = 0;\npts.shift();\npts.map(function(c){\n\t\t\t\tif( c > max )\n\t\t\t\t\t\t\tct++,max=c;\n\t\t\t\telse\n\t\t\t\t\t\t\tct++,min=c;\n});\nwrite(ct);"}, {"source_code": "read = +readline();\nvar pts = readline().split(' ');\nvar max = pts[0];\nvar min = pts[0];\nvar ct = 0;\npts.shift();\npts.map(function(c){\n\t\t\t\tif( c > max )\n\t\t\t\t\t\t\tct++,max=c;\n\t\t\t\tif( c < min )\n\t\t\t\t\t\t\tct++,min=c;\n});\nwrite(ct);"}], "src_uid": "a61b96d4913b419f5715a53916c1ae93"} {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nlet gcd = (a, b) => a ? gcd(b % a, a) : b;\nlet lcm = (a, b) => a * b / gcd(a, b);\n\nfunction main(){\n\n let n = readLine();\n let lights = readLine().split('').map( x => parseInt(x));\n // console.log(lights);\n var dur = [];\n var del = [];\n for(let i=0; i< n ; ++i){\n let tmp = readLine().split(' ').map( x => parseInt(x));\n dur.push(tmp[0]);\n del.push(tmp[1]);\n }\n // console.log(dur);\n // console.log(del);\n\n // var l=del.reduce(lcm)\n // console.log(l)\n var c =[];\n for(let i=0;i<2000;++i){\n c[i]=0;\n }\n\n for(let i=0;i {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n const initialState = lines[1];\n const tuples = [];\n for (let i = 2; i < lines.length; i++) {\n let tuple = lines[i].split(' ');\n if (tuple.length === 2) {\n tuple = tuple.map(num => parseInt(num, 10));\n tuples.push(tuple);\n }\n }\n maxLights(initialState, tuples);\n});\n\nfunction maxLights(initial, tuples) {\n let split = initial.split('');\n let states = [];\n for (let i = 0; i < tuples.length; i++) {\n let statesForI = [];\n const [a, b] = tuples[i];\n\n let state = split[i] === '1';\n for (let j = 0; j < b; j++) {\n statesForI.push(state);\n }\n\n state = !state;\n\n let count = 0;\n for (let j = b; j < 125; j++) {\n if (count === a) {\n state = !state;\n count = 0;\n }\n count++;\n statesForI.push(state);\n }\n\n states.push(statesForI.slice());\n }\n\n let max = 0;\n for (let i = 0; i < 125; i++) {\n let count = 0;\n states.forEach(state => {\n if (state[i]) count++;\n });\n max = Math.max(count, max);\n }\n console.log(max);\n return max;\n}"}, {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar n = readline().getNumArray()[0];\nvar defaultState = readline().split('').map(function (value) {\n return parseInt(value);\n});\nvar data = [];\n\nfor (var i = 0; i < n; i++) {\n var dataElement = readline().getNumArray();\n data.push(dataElement);\n}\n\nvar period = 0;\nvar periodStarted = 1;\n\nvar toggleLight = function toggleLight(state) {\n if (state === 0) {\n return 1;\n }\n\n return 0;\n};\n\nvar checkLight = function checkLight(second, indexOfLight) {\n var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);\n var stateChanged = periods % 2 === 1;\n\n if (stateChanged) {\n return toggleLight(defaultState[indexOfLight]);\n }\n\n return defaultState[indexOfLight];\n};\n\nvar amountOfLights = 0;\n\nfor (var _i = 0; _i <= 1200; _i++) {\n var lights = 0;\n\n for (var lightIndex = 0; lightIndex < n; lightIndex++) {\n lights += checkLight(_i, lightIndex);\n }\n\n if (lights > amountOfLights) {\n amountOfLights = lights;\n }\n}\n\nwrite(amountOfLights);"}, {"source_code": "var elements = parseInt(readline());\nvar initial = readline();\nvar current = initial\nvar pairs = []\nfor (var i = 0; i < elements; i++) {\n pairs.push(readline().split(' ').map(function(num) {\n return parseInt(num);\n }))\n}\n\nvar maxLights = function(lights) {\n return lights.split('').map(function(num) {\n return parseInt(num);\n }).reduce(function(acc, num) {\n return acc + num;\n }, 0);\n}\n\nvar max = maxLights(initial); \n\nvar uniques = []\nfor (var i = 0; i < pairs.length; i++) {\n uniques.push(pairs[i][1])\n}\nuniques = Array.from(new Set(uniques))\nuniques = uniques.reduce(function(acc, num) {\n return acc*num;\n}, 1);\n\nfunction foo() {\n var step = 0;\n while (step < 10000) {\n step++;\n for (var i = 0; i < pairs.length; i++) {\n if (step - pairs[i][1] < 0) \n continue;\n if ((step - pairs[i][1]) % pairs[i][0] === 0) {\n current = current.split('')\n current[i] = (current[i] === '0') ? '1' : '0'\n current = current.join('')\n }\n }\n max = Math.max(max, maxLights(current))\n }\n\n write(max)\n}\n\nfoo();"}], "negative_code": [{"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar n = readline().getNumArray()[0];\nvar defaultState = readline().split('').map(function (value) {\n return parseInt(value);\n});\nvar data = [];\n\nfor (var i = 0; i < n; i++) {\n var dataElement = readline().getNumArray();\n data.push(dataElement);\n}\n\nvar period = 0;\nvar periodStarted = 1;\n\nvar toggleLight = function toggleLight(state) {\n if (state === 0) {\n return 1;\n }\n\n return 0;\n};\n\nvar checkLight = function checkLight(second, indexOfLight) {\n var periods = (second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1;\n var stateChanged = periods % 2 === true;\n\n if (stateChanged) {\n return toggleLight(defaultState[indexOfLight]);\n }\n\n return defaultState[indexOfLight];\n};\n\nvar amountOfLights = 0;\n\nfor (var _i = 1; _i <= 120; _i++) {\n var lights = 0;\n\n for (var lightIndex = 0; lightIndex < n; lightIndex++) {\n lights += checkLight(_i, lightIndex);\n }\n\n if (lights > amountOfLights) {\n amountOfLights = lights;\n }\n}\n\nwrite(amountOfLights);"}, {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar n = readline().getNumArray()[0];\nvar defaultState = readline().split('').map(function (value) {\n return parseInt(value);\n});\nvar data = [];\n\nfor (var i = 0; i < n; i++) {\n var dataElement = readline().getNumArray();\n data.push(dataElement);\n}\n\nvar period = 0;\nvar periodStarted = 1;\n\nvar toggleLight = function toggleLight(state) {\n if (state === 0) {\n return 1;\n }\n\n return 0;\n};\n\nvar checkLight = function checkLight(second, indexOfLight) {\n var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);\n var stateChanged = periods % 2 === 1;\n\n if (stateChanged) {\n return toggleLight(defaultState[indexOfLight]);\n }\n\n return defaultState[indexOfLight];\n};\n\nvar amountOfLights = 0;\n\nfor (var _i = 1; _i <= 500; _i++) {\n var lights = 0;\n\n for (var lightIndex = 0; lightIndex < n; lightIndex++) {\n lights += checkLight(_i, lightIndex);\n }\n\n if (lights > amountOfLights) {\n amountOfLights = lights;\n }\n}\n\nwrite(amountOfLights);"}, {"source_code": "var elements = parseInt(readline());\nvar initial = readline();\nvar current = initial\nvar pairs = []\nfor (var i = 0; i < elements; i++) {\n pairs.push(readline().split(' ').map(function(num) {\n return parseInt(num);\n }))\n}\n\n// var initial = '101'\n// var current = initial;\n// var pairs = [[3, 3], [3, 2], [3, 1]]\n\nvar maxLights = function(lights) {\n return lights.split('').map(function(num) {\n return parseInt(num);\n }).reduce(function(acc, num) {\n return acc + num;\n }, 0);\n}\n\nvar max = maxLights(initial); \n\nvar uniques = []\nfor (var i = 0; i < pairs.length; i++) {\n uniques.push(pairs[i][1])\n}\nuniques = Array.from(new Set(uniques))\nuniques = uniques.reduce(function(acc, num) {\n return acc*num;\n}, 1);\n\nfunction foo() {\n var step = 0;\n while (initial !== current || step < pairs[0][1]) {\n if (step > uniques) {\n write(max);\n return;\n }\n step++;\n for (var i = 0; i < pairs.length; i++) {\n if (step - pairs[i][1] < 0) \n continue;\n if ((step - pairs[i][1]) % pairs[i][0] === 0) {\n current = current.split('')\n current[i] = (current[i] === '0') ? '1' : '0'\n current = current.join('')\n }\n }\n max = Math.max(max, maxLights(current))\n }\n\n write(max)\n}\n\nfoo();"}], "src_uid": "2ff789ae0095bb7ff0e747b0d4df59bc"} {"source_code": ";(function () {\n\tvar n = +readline(),\n\t\ts = [];\n\n\t(function (n) {\n\t\twhile (n--) {\n\t\t\ts.push(readline());\n\t\t}\n\t})(n);\n\n\tprint(function () {\n\t\tvar m = n - 1;\n\t\tfor (var i = 0; i < n; i++)\n\t\t\tfor (var j = 0; j < n; j++) {\n\t\t\t\tvar k = 0;\n\n\t\t\t\tif (i > 0 && s[i - 1][j] === 'o') k++;\n\t\t\t\tif (i < m && s[i + 1][j] === 'o') k++;\n\n\t\t\t\tif (j > 0 && s[i][j - 1] === 'o') k++;\n\t\t\t\tif (j < m && s[i][j + 1] === 'o') k++;\n\n\t\t\t\tif ((k%2) !== 0) return 'NO';\n\t\t\t}\n\t\treturn 'YES';\n\t}());\n}.call(this));\n", "positive_code": [{"source_code": "var n = +readline();\nvar array = [], check = true;\n\nfor(i = 0; i < n; i++){\n\tarray.push(readline().split(\"\"));\n}\n\nfor(i = 0; i < n; i++){\n\tfor(j = 0; j < n; j++){\n\t\tcnt = 0;\n\t\tif(array[i][j-1] == \"o\"){\n\t\t\tcnt++;\n\t\t}\n\t\tif(array[i][j+1] == \"o\"){\n\t\t\tcnt++;\n\t\t}\n\t\tif(array[i-1] != undefined && array[i-1][j] == \"o\"){\n\t\t\tcnt++;\n\t\t}\n\t\tif(array[i+1] != undefined && array[i+1][j] == \"o\"){\n\t\t\tcnt++;\n\t\t}\n\n\t\tif(cnt % 2 != 0){\n\t\t\tcheck = false;\n\t\t}\n\t}\n}\n\nif(check){\n\twrite(\"YES\");\n}\nelse{\n\twrite(\"NO\");\n}"}, {"source_code": "var n = readline();\nvar map = [];\n\nvar i, j, x, y;\n\nfor (i = 0; i < n; i++) {\n\tmap.push(readline());\n}\n\nvar count;\nvar off = [\n\t[0, 1],\n\t[0, -1],\n\t[1, 0],\n\t[-1, 0]\n];\n\nvar flag = true;\n\nfor (i = 0; i < n; i++) {\n\tfor (j = 0; j < n; j++) {\n\t\tcount = 0;\n\t\tfor (k = 0; k < off.length; k++) {\n\t\t\tx = j + off[k][1];\n\t\t\ty = i + off[k][0];\n\t\t\tif (x >= 0 && y >= 0 && x < n && y < n)\n\t\t\t\tif (map[y].charAt(x) == 'o')\n\t\t\t\t\tcount++;\n\t\t}\n\t\tif (count % 2 != 0) {\n\t\t\tflag = false;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nwrite(flag?'YES':'NO');"}, {"source_code": "var n = parseInt(readline());\nvar allEven = true;\nvar board = [];\n\nfor (var i = 0; i < n; i++) {\n board[i] = readline();\n}\n\nout: for (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++) {\n if (check(board, i, j) % 2 != 0) {\n allEven = false;\n break out;\n }\n }\n}\n\nif (allEven) {\n print(\"YES\");\n} else {\n print(\"NO\");\n}\n\n\nfunction check(arr, i, j) {\n var rows = arr.length;\n var cols = arr[0].length;\n var countOfO = 0;\n \n if (i != 0) {\n if (arr[i - 1][j] =='o') {\n countOfO++;\n }\n }\n\n if (i != rows - 1) {\n if (arr[i + 1][j] =='o') {\n countOfO++;\n }\n }\n\n if (j != 0) {\n if (arr[i][j - 1] =='o') {\n countOfO++;\n }\n }\n\n if (j != cols - 1) {\n if (arr[i][j + 1] =='o') {\n countOfO++;\n }\n }\n\n return countOfO;\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline()),\n\t\tboard = [];\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar line = trim(readline());\n\t\tboard.push([]);\n\t\tfor (var j = 0; j < n; ++j) {\n\t\t\tboard[i].push(line.charAt(j));\n\t\t}\n\t}\n\tvar di = [-1, 0, 1, 0], dj = [0, 1, 0, -1];\n\tfor (var i = 0; i < n; ++i) {\n\t\tfor (var j = 0; j < n; ++j) {\n\t\t\tvar count = 0;\n\t\t\tfor (var k = 0; k < 4; ++k) {\n\t\t\t\tvar I = i+di[k], J = j+dj[k];\n\t\t\t\tif (I < 0 || I == n || J < 0 || J == n) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (board[I][J] == 'o') {\n\t\t\t\t\t++count;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (count%2 == 1) {\n\t\t\t\tprint('NO');\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tprint('YES');\n}\n\nmain();\n"}, {"source_code": "\nvar lineNumber = readline();\nvar lines = [];\nfor(var i=0; i0 && arr[i-1][j]==\"o\") c++;\nif (i0 && arr[i][j-1]==\"o\") c++;\nif (j {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nconst countPower = (num) => {\r\n let pow = 0\r\n while (!(num & 1)) {\r\n num >>= 1;\r\n pow++;\r\n }\r\n return pow\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = int(readLine());\r\n // let t = 1;\r\n while (t--) {\r\n const n = int(readLine());\r\n const arr = readLine().split(' ').map(a => int(a));\r\n \r\n let pow = 0;\r\n for (let i = 0; i < n; i++) {\r\n pow += countPower(arr[i]);\r\n }\r\n let ans = 0;\r\n if (pow < n) {\r\n let powArr = [];\r\n for (let i = 1; i <= n; i++) {\r\n powArr.push(countPower(i));\r\n }\r\n powArr.sort((a, b) => b - a);\r\n\r\n for (let i = 0; i < n; i++) {\r\n pow += powArr[i]\r\n ans++;\r\n if (pow >= n) break;\r\n }\r\n }\r\n\r\n console.log((pow >= n) ? ans : -1); \r\n }\r\n});", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let k = 0\n const ps = Array(n)\n for (let i = 0; i < arr.length; i++) {\n let x = arr[i]\n while (!(x & 1)) {\n x /= 2\n k++\n }\n //\n x = i + 1\n ps[i] = 0\n while (!(x & 1)) {\n x /= 2\n ps[i]++\n }\n }\n ps.sort((a, b) => a - b)\n// console.log(k, ps)\n let i = n - 1\n let r = 0\n while (k < n && i >= 0 && ps[i] > 0) {\n const x = ps[i]\n // if (x) {\n k += x\n r++\n // }\n i--\n }\n if (k < n) return -1\n return r\n}\n"}, {"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n \nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n\nlet fact2 = (a) => {\n let cnt = 0;\n while (a % 2 === 0) {\n cnt++;\n a /= 2;\n }\n return cnt;\n}\n\nconst NN = 200005;\nlet twos = new Array(NN).fill(0);\nfor (let i = 0; i < NN; i++) {\n twos[i] = fact2(i + 1);\n}\n \nconst calc = (t)=>{\n /* read */\n let n = +rl();\n let a = ra();\n\n let sum2 = 0;\n let potential2 = [];\n let potentialsum = 0;\n let moves = 0;\n for (let i = 0; i < n; i++) {\n if (a[i] < NN) {\n sum2 += twos[a[i] - 1];\n } else {\n sum2 += fact2(a[i]);\n }\n potential2.push(twos[i]);\n potentialsum += twos[i];\n }\n if (sum2 >= n) return 0;\n if (sum2 + potentialsum < n) return -1;\n\n potential2.sort((a, b) => b - a);\n let cursum = 0;\n for (let i = 0; i < n; i++) {\n cursum += potential2[i];\n if (sum2 + cursum >= n) return i + 1;\n }\n return -1;\n};\n \nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n // calc(t);\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let z=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[++z]);\r\n let a=line[++z].split(' ').map(x=>{return parseInt(x)});\r\n let ans=0;\r\n let cnt=0;\r\n for(let i=0;i=n) console.log(0);\r\n else\r\n {\r\n let b=[];\r\n for(let i=1;i<=n;i++)\r\n {\r\n let c=0;\r\n let x=i;\r\n while(x%2==0)\r\n {\r\n x/=2;\r\n c++;\r\n }\r\n b.push(c);\r\n }\r\n b.sort(function(a,b){\r\n return b-a;\r\n })\r\n for(let i=0;i=n) break;\r\n }\r\n if(cnt>=n) console.log(ans);\r\n else console.log(-1);\r\n }\r\n }\r\n})"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let k = n;\r\n for (let i = 0; i < n; i++) {\r\n while (arr[i] % 2 === 0) {\r\n k--;\r\n arr[i] = arr[i] / 2;\r\n }\r\n }\r\n if (k <= 0) console.log(0);\r\n else {\r\n const helper = () => {\r\n let j = [];\r\n for (let i = 1; i <= n; i++) {\r\n if (i % 2 === 0) {\r\n if (Math.log2(i) % 1 === 0) j.push(Math.log2(i));\r\n else {\r\n let cnt = 0,\r\n l = i;\r\n while (l % 2 === 0) {\r\n cnt++;\r\n l = l / 2;\r\n }\r\n j.push(cnt);\r\n }\r\n }\r\n }\r\n j.sort((a, b) => b - a);\r\n for (let i = 0; i < j.length; i++) {\r\n k = k - j[i];\r\n if (k <= 0) return i + 1;\r\n }\r\n return -1;\r\n };\r\n console.log(helper());\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n let t = n;\r\n for (let i = 0; i < n; i++) {\r\n let ans = 0,\r\n num = a[i];\r\n while (num % 2 === 0) {\r\n ans++;\r\n num /= 2;\r\n }\r\n t -= ans;\r\n }\r\n if (t <= 0) return 0;\r\n let nums = [];\r\n for (let i = n; i; i--) {\r\n let ans = 0,\r\n num = i;\r\n while (num % 2 === 0) {\r\n ans++;\r\n num /= 2;\r\n }\r\n if (ans) nums.push(ans);\r\n }\r\n nums.sort((a, b) => b - a);\r\n for (let i = 0; i < n; i++) {\r\n t -= nums[i];\r\n if (t <= 0) return i + 1;\r\n }\r\n return -1;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let k = 0\n for (let i = 0; i < arr.length; i++) {\n let x = arr[i]\n while (!(x & 1)) {\n x /= 2\n k++\n }\n }\n let m = Math.floor(Math.log2(n))\n let r = 0\n while (k < n && m > 0) {\n k += m--\n r++\n }\n if (k < n) return -1\n return r\n}\n"}], "src_uid": "96f0df1c8e014229e5ef773789aa2205"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 1e5+5;\r\nconst sum = Array(mxN).fill(0);\r\nconst cnt = Array(mxN).fill(0);\r\nconst pos = Array(mxN).fill(0);\r\n\r\nfunction main () {\r\n\tconst [n, m] = rna();\r\n\tconst a = [];\r\n\tfor (let i = 0; i < n; i++) a[i] = rna(); \r\n\r\n\tlet ans = 0;\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tfor (let j = 0; j < m; j++) {\r\n\t\t\tconst curCol = a[i][j];\r\n\t\t\tsum[curCol] += cnt[curCol] * (i - pos[curCol]);\r\n\t\t\tcnt[curCol]++;\r\n\t\t\tpos[curCol] = i;\r\n\t\t\tans += sum[curCol];\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < mxN; i++) sum[i] = cnt[i] = pos[i] = 0;\r\n\r\n\tfor (let j = 0; j < m; j++) {\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconst curCol = a[i][j];\r\n\t\t\tsum[curCol] += cnt[curCol] * (j - pos[curCol]);\r\n\t\t\tcnt[curCol]++;\r\n\t\t\tpos[curCol] = j;\r\n\t\t\tans += sum[curCol];\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 1e5 + 5;\r\nconst mxP = 1e5 + 5;\r\nconst pos = Array.from(Array(2 * mxP), x => []);\r\n\r\nfunction main () {\r\n\tconst [n, m] = rna();\r\n\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tfor (const [j, c] of rna().entries()) {\r\n\t\t\tpos[2 * c + 0].push(i);\r\n\t\t\tpos[2 * c + 1].push(j);\r\n\t\t}\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tfor (const v of pos) {\r\n\t\tv.sort((x, y) => x - y);\r\n\t\tfor (let i = 0, sum = 0; i < v.length - 1; i++) {\r\n\t\t\tsum += (i + 1) * (v[i + 1] - v[i]);\r\n\t\t\tans += sum;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "ef0ad7b228351a268c3f6bfac68b1002"} {"source_code": "print(function(n, k) {\n\tvar ans = [];\n\n\tfor (var i = 1, c = 0; i <= n * 2; i += 2, c++) {\n\t\tif (c < k) {\n\t\t\tans.push(i + 1);\n\t\t\tans.push(i);\n\t\t} else {\n\t\t\tans.push(i);\n\t\t\tans.push(i + 1);\n\t\t}\n\t}\n\n\treturn ans.join(' ');\n\n}.apply(0, readline().split(' ').map(Number)));", "positive_code": [{"source_code": "print(function(n, k) {\n\tvar i, ans = [];\n\tfor (i = 1; i <= n * 2; i++) {\n\t\tans.push(i);\n\t}\n\n\tif (k > 0) {\n\t\tans[0] = k + 1;\n\t\tans[1] = 1;\n\t\tif (k > 1) {\n\t\t\tif ((k + 1) % 2) {\n\t\t\t\tans[k] = 2;\n\t\t\t} else {\n\t\t\t\tans[k] = ans[k - 1];\n\t\t\t\tans[k - 1] = 2;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ans.join(' ');\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar n = integers[0], k = integers[1];\n\tvar m = 2*n;\n\tvar perm = [];\n\tfor (var i = 1; i <= k; ++i) {\n\t\tperm.push(2*i);\n\t\tperm.push(2*i-1);\n\t}\n\tfor ( ; i <= n; ++i) {\n\t\tperm.push(2*i-1);\n\t\tperm.push(2*i);\n\t}\n\tprint(perm.join(\" \"));\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "82de6d4c892f4140e72606386ec2ef59"} {"source_code": "function ProblemSolver() {\n\n this.dp = function( i , hand ) {\n var res , r1 , ret , a , b , c , d , j;\n if( i < 2 ) {\n return 0;\n }\n if( hand > this.lim1 ) {\n res = ( 1 << 23 );\n return res;\n }\n ret = this.done[ i ][ hand ];\n res = this.memo[ i ][ hand ];\n if( ret == this.cc ) {\n return res;\n }\n this.done[ i ][ hand ] = this.cc;\n if( this.arr[ i ] == 0 ) {\n res = this.dp( i - 1 , hand );\n this.memo[ i ][ hand ] = res;\n return res;\n }\n res = ( 1 << 23 );\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = a - ( b * this.k );\n if( c != 0 ) {\n if( hand >= c ) {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand - c ) + d;\n res = Math.min( res , r1 );\n }\n else {\n b++;\n d = 2 * ( i - 1 ) * b;\n c = c - hand;\n r1 = this.dp( i - 1 , this.k - c ) + d;\n res = Math.min( res , r1 );\n }\n }\n else {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand ) + d;\n res = Math.min( res , r1 );\n }\n this.memo[ i ][ hand ] = res;\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma , prev , cur , inf;\n res = 0;\n inf = ( 1 << 23 );\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n if( ma > 500 ) {\n res = this.dp( 500 , 0 );\n }\n if( ma > 1000 ) {\n res = this.dp( 1000 , 0 );\n }\n if( ma > 1500 ) {\n res = this.dp( 1500 , 0 );\n }\n res = this.dp( ma , 0 );\n print( res );\n };\n\n this.solveCaseGreedy = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n hand += d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim1 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 2;\n this.lim3 = 2010;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n", "positive_code": [{"source_code": "var nums = readline().split(' ');\nvar n = parseInt(nums[0]);\nvar k = parseInt(nums[1]);\nvar a_in = readline().split(' ');\nvar a = new Array();\n\nfor(var i=0;i this.lim1 ) {\n res = ( 1 << 23 );\n return res;\n }\n ret = this.done[ i ][ hand ];\n res = this.memo[ i ][ hand ];\n if( ret == this.cc ) {\n return res;\n }\n this.done[ i ][ hand ] = this.cc;\n if( this.arr[ i ] == 0 ) {\n res = this.dp( i - 1 , hand );\n this.memo[ i ][ hand ] = res;\n return res;\n }\n res = ( 1 << 23 );\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = a - ( b * this.k );\n if( c != 0 ) {\n if( hand >= c ) {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand - c ) + d;\n res = Math.min( res , r1 );\n }\n else {\n b++;\n d = 2 * ( i - 1 ) * b;\n c = c - hand;\n r1 = this.dp( i - 1 , this.k - c ) + d;\n res = Math.min( res , r1 );\n }\n }\n else {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand ) + d;\n res = Math.min( res , r1 );\n }\n this.memo[ i ][ hand ] = res;\n return res;\n };\n\n this.solveCasedp = function() {\n var res , i , j , a , b , c , d , e , hand , ma , prev , cur , inf;\n res = 0;\n inf = ( 1 << 23 );\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n res = this.dp( ma , 0 );\n print( res );\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n d = ( this.k - d )\n res += c;\n }\n hand += d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim1 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 2;\n this.lim3 = 2010;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.dp = function( i , hand ) {\n var res , r1 , ret , a , b , c , d , j;\n if( i < 2 ) {\n return 0;\n }\n if( hand > this.lim1 ) {\n res = ( 1 << 23 );\n return res;\n }\n ret = this.done[ i ][ hand ];\n res = this.memo[ i ][ hand ];\n if( ret == this.cc ) {\n return res;\n }\n this.done[ i ][ hand ] = this.cc;\n if( this.arr[ i ] == 0 ) {\n res = this.dp( i - 1 , hand );\n this.memo[ i ][ hand ] = res;\n return res;\n }\n res = ( 1 << 23 );\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = a - ( b * this.k );\n if( c != 0 ) {\n if( hand >= c ) {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand - c ) + d;\n res = Math.min( res , r1 );\n }\n else {\n b++;\n d = 2 * ( i - 1 ) * b;\n c = c - hand;\n r1 = this.dp( i - 1 , this.k - c ) + d;\n res = Math.min( res , r1 );\n }\n }\n else {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand ) + d;\n res = Math.min( res , r1 );\n }\n this.memo[ i ][ hand ] = res;\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma , prev , cur , inf;\n res = 0;\n inf = ( 1 << 23 );\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n res = this.dp( ma , 0 );\n print( res );\n };\n\n this.solveCaseGreedy = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n hand += d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim1 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 2;\n this.lim3 = 2010;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var str1 = readline().split(\" \");\nvar f = readline().split(\" \");\nvar n = str1[0];\nvar k = str1[1];\nvar x = 0;\nvar f1 = [];\nfor (j in f) f1[j] = f [j];\nf1.sort(mySort);\nfor (i=f1.length-1;i>-1;i=i-k){\n x = x + ((f1[i]-1)*2);\n}\nprint(x);\nfunction mySort(a,b) {return (a-b);}"}, {"source_code": "function main() {\n var t = readline().split(' ').map(x => +x), n = t[0], k = t[1];\n var a = readline().split(' ').map(x => +x);\n a.sort((u, v) => v - u);\n var ans = 0;\n for (var i = 0; i < n; i += k) {\n ans += (a[i] - 1) * 2;\n }\n print(ans);\n}\n\nif (typeof readline == 'undefined') {\n process.stdin.resume();\n process.stdin.setEncoding('ascii');\n \n var input_stdin = \"\";\n process.stdin.on('data', function (data) { input_stdin += data; });\n process.stdin.on('end', function () {\n // input_stdin = input_stdin.split(/\\s/);\n input_stdin = input_stdin.split('\\n');\n var curline = 0;\n readline = () => input_stdin[curline++];\n if (typeof print == 'undefined') print = console.log;\n main();\n });\n} else main();\n"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], k = +input[1],\nf = readline().split(\" \").map(Number).sort(function(x,y){return y-x});\nvar x, cnt = 0;\n\nfor(; ;){\n\tif(f[0] == undefined){\n\t\tbreak;\n\t}\n\tx = f[0];\n\tf.splice(0,k);\n\n\tcnt += (x-1)*2;\n}\n\nwrite(cnt);"}, {"source_code": "\n// 472B \u0423\u0440\u043e\u043a\u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0437\u0430\u0434\u0430\u0447: \u0443\u0447\u0438\u043c\u0441\u044f \u0443 \u0436\u0438\u0437\u043d\u0438 \n\n//var n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar n = arr[0];\nvar k = arr[1];\n\nvar arr = readline().split(' ').map(Number);\narr.sort(function(a,b){return a-b;});\narr.reverse();\n\nvar out = 0;\nvar num = 0;\nvar sum_lift;\nwhile (num < n) {\n out += (arr[num] - 1) * 2;\n\n if ((n - num) > k) {\n sum_lift = k;\n num += k;\n } else {\n sum_lift = n - num;\n num += n - num;\n };\n}\n\nprint(out);\n\n\n"}, {"source_code": ";(function () {\n\n\tprint(function (n, k, f) {\n\n\t\tvar sumTime = 0, _f = [];\n\n\t\twhile (n > 0) {\n\t\t\tvar peopleInLift = n >= k ? k : n,\n\t\t\t\tpeople = f.splice(0, peopleInLift),\n\t\t\t\tmaxFloor = Math.max.apply(null, people);\n\n\t\t\tn -= peopleInLift;\n\t\t\tsumTime += 2 * maxFloor;\n\t\t}\n\n\t\treturn sumTime;\n\n\t}.apply(null, readline().split(' ')\n\t\t\t.map(Number)\n\t\t\t.concat([\n\t\t\t\treadline().split(' ')\n\t\t\t\t\t.map(function (e) {\n\t\t\t\t\t\treturn +e - 1;\n\t\t\t\t\t}).sort(function (a, b) {\n\t\t\t\t\t\treturn b - a;\n\t\t\t\t\t})\n\t\t\t])\n\t));\n\n}.call(this));\n"}, {"source_code": "var inp,n,k,arr;\n\ninp=readline().split(\" \");\nn=+inp[0];\nk=+inp[1];\narr=readline().split(\" \").map(function(a){return +a;});\n\nvar ans=0;\n\narr.sort(function(a,b) {return b-a});\nfor(var i=0; i ma ) {\n ma = a ;\n }\n }\n for( i = ma ; i >= 1 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( i != ma ) {\n if( hand <= this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0 ;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n }\n if( i == 1 ) {\n break;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n hand = this.arr[ i ] - ( b * this.k );\n if( hand > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt() ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1 ;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a ;\n }\n }\n for( i = ma ; i >= 0 ; i-- ) {\n if( i != ma ) {\n if( hand <= this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0 ;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n hand = this.arr[ i ] - ( b * this.k );\n if( hand > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt() ;\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.dp = function( i , hand ) {\n var res , r1 , ret , a , b , c , d , j;\n if( i < 2 ) {\n return 0;\n }\n if( hand > this.lim1 ) {\n res = ( 1 << 23 );\n return res;\n }\n ret = this.done[ i ][ hand ];\n res = this.memo[ i ][ hand ];\n if( ret == this.cc ) {\n return res;\n }\n this.done[ i ][ hand ] = this.cc;\n if( this.arr[ i ] == 0 ) {\n res = this.dp( i - 1 , hand );\n this.memo[ i ][ hand ] = res;\n return res;\n }\n res = ( 1 << 23 );\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = a - ( b * this.k );\n if( c != 0 ) {\n if( hand >= c ) {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand - c ) + d;\n res = Math.min( res , r1 );\n }\n else {\n b++;\n d = 2 * ( i - 1 ) * b;\n c = c - hand;\n r1 = this.dp( i - 1 , this.k - c ) + d;\n res = Math.min( res , r1 );\n }\n }\n else {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand ) + d;\n res = Math.min( res , r1 );\n }\n this.memo[ i ][ hand ] = res;\n return res;\n };\n\n this.solveCasedp = function() {\n var res , i , j , a , b , c , d , e , hand , ma , prev , cur , inf;\n res = 0;\n inf = ( 1 << 23 );\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n res = this.dp( ma , 0 );\n print( res );\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n hand += this.k - d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim1 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 2;\n this.lim3 = 2010;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0 ;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n hand += d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "\n// 472B \u0423\u0440\u043e\u043a\u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0437\u0430\u0434\u0430\u0447: \u0443\u0447\u0438\u043c\u0441\u044f \u0443 \u0436\u0438\u0437\u043d\u0438 \n\n//var n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar n = arr[0];\nvar k = arr[1];\n\nvar arr = readline().split(' ').map(Number);\narr.sort(function(a,b){return a-b;});\narr.reverse();\n\nvar out = 0;\nvar num = 0;\nvar sum_lift;\nwhile (num < k) {\n out += (arr[num] - 1) * 2;\n\n if ((n - num) > k) {\n sum_lift = k;\n num += k;\n } else {\n sum_lift = n - num;\n num = n - 1;\n };\n}\n\nprint(out);\n\n\n"}, {"source_code": "var inp,n,k,arr;\n\ninp=readline().split(\" \");\nn=+inp[0];\nk=+inp[1];\narr=readline().split(\" \").map(function(a){return +a;});\n\nvar ans=0;\n\narr.sort(function(a,b) {return b-a});\nfor(var i=0; i= c ) {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand - c ) + d;\n res = Math.min( res , r1 );\n }\n else {\n b++ ;\n d = 2 * ( i - 1 ) * b;\n c = ( b * this.k ) - a ;\n r1 = this.dp( i - 1 , c - hand ) + d;\n res = Math.min( res , r1 );\n }\n }\n else {\n d = 2 * ( i - 1 ) * b;\n r1 = this.dp( i - 1 , hand ) + d;\n res = Math.min( res , r1 );\n }\n this.memo[ i ][ hand ] = res;\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , hand , ma , prev , cur , inf;\n res = 0;\n inf = ( 1 << 23 );\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n if( ma > 500 ) {\n res = this.dp( 500 , 0 );\n }\n if( ma > 1000 ) {\n res = this.dp( 1000 , 0 );\n }\n if( ma > 1500 ) {\n res = this.dp( 1500 , 0 );\n }\n res = this.dp( ma , 0 );\n print( res );\n };\n\n this.solveCaseGreedy = function() {\n var res , i , j , a , b , c , d , e , hand , ma;\n res = 0;\n ma = -1;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.brr[ i ];\n this.arr[ a ]++;\n if( a > ma ) {\n ma = a;\n }\n }\n hand = 0;\n for( i = ma ; i >= 2 ; i-- ) {\n if( this.arr[ i ] == 0 ) {\n continue;\n }\n if( hand < this.arr[ i ] ) {\n this.arr[ i ] -= hand;\n hand = 0;\n }\n else {\n hand -= this.arr[ i ];\n continue;\n }\n a = this.arr[ i ];\n b = Math.floor( a / this.k );\n c = b * ( i - 1 ) * 2;\n res += c;\n d = this.arr[ i ] - ( b * this.k );\n if( d > 0 ) {\n c = 1 * ( i - 1 ) * 2;\n res += c;\n }\n hand += d;\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n this.k = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.brr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i , j;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n this.clearArraysPerCase();\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim1 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 2010;\n this.lim2 = 2;\n this.lim3 = 2010;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}], "src_uid": "b8d8f0e86ecb600f7559a6aec629946e"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = [rn(), rn(), rn(), i];\r\n }\r\n a.sort((a, b) => {\r\n if (a[1] !== b[1]) return a[1] - b[1];\r\n return a[0] - b[0];\r\n });\r\n const res = new Array(n).fill(Infinity);\r\n let max = [-1, -1];\r\n for (let i = 0; i < n; i++) {\r\n const [x, y] = max;\r\n const j = a[i][3];\r\n if (x !== -1 && a[i][2] !== a[x][2]) {\r\n res[j] = Math.max(0, a[i][0] - a[x][1]);\r\n } else if (y !== -1 && a[i][2] !== a[y][2]) {\r\n res[j] = Math.max(0, a[i][0] - a[y][1]);\r\n }\r\n if (max[0] === -1) {\r\n max[0] = i;\r\n } else if (a[max[0]][2] === a[i][2]) {\r\n max[0] = i;\r\n } else {\r\n max = [i, max[0]];\r\n }\r\n }\r\n max = [-1, -1];\r\n for (let i = n - 1; i >= 0; i--) {\r\n const [x, y] = max;\r\n const j = a[i][3];\r\n if (x !== -1 && a[i][2] !== a[x][2]) {\r\n res[j] = Math.min(res[j], Math.max(0, a[x][0] - a[i][1]));\r\n } else if (y !== -1 && a[i][2] !== a[y][2]) {\r\n res[j] = Math.min(res[j], Math.max(0, a[y][0] - a[i][1]));\r\n }\r\n if (x === -1) {\r\n max[0] = i;\r\n } else if (a[i][0] < a[x][0]) {\r\n if (a[x][2] === a[i][2]) {\r\n max[0] = i;\r\n } else {\r\n max = [i, max[0]];\r\n }\r\n } else if (a[i][2] !== a[x][2] && (y === -1 || a[i][0] < a[y][0])) {\r\n max[1] = i;\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\r\n l += n\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const ls = arr.map((x, i) => ({ x, i }))\r\n .sort((a, b) => a.x[0] - b.x[0])\r\n const left = cal(n, ls, 0)\r\n const rs = arr.map(([l, r, c], i) => ({ x: [-l, -r, c], i }))\r\n .sort((a, b) => a.x[1] - b.x[1])\r\n const right = cal(n, rs, 1)\r\n //\r\n const ans = Array(n)\r\n for (let i = 0; i < n; i++) {\r\n ans[i] = Math.min(left[i], right[i])\r\n if (ans[i] === Infinity) ans[i] = 0\r\n }\r\n // console.log(left, right)\r\n return ans.join(' ')\r\n}\r\nfunction cal(n, arr, key) {\r\n // console.log(arr)\r\n //\r\n let first = -Infinity, second = -Infinity\r\n let fc, sc // color\r\n const best = Array(n)\r\n for (let p = 0; p < n; p++) {\r\n const { x, i } = arr[p]\r\n const c = x[2]\r\n // console.log(x, first, fc, second, sc)\r\n //\r\n const other = x[key ^ 1]\r\n let ok = 0\r\n if (fc === c) {\r\n if (other > first) {\r\n first = other\r\n }\r\n ok = 1\r\n } else if (sc === c) {\r\n if (other > second) {\r\n second = other\r\n }\r\n ok = 1\r\n }\r\n if (ok) {\r\n if (first < second) {\r\n [first, second] = [second, first]\r\n ;[fc, sc] = [sc, fc]\r\n }\r\n } else {\r\n if (other > first) {\r\n second = first\r\n sc = fc\r\n first = other\r\n fc = c\r\n } else if (other > second) {\r\n second = other\r\n sc = c\r\n }\r\n }\r\n best[p] = [first, fc, second, sc]\r\n }\r\n// console.log(best)\r\n const other = arr\r\n .slice()\r\n .sort((a, b) => a.x[key ^ 1] - b.x[key ^ 1])\r\n const ans = Array(n).fill(Infinity)\r\n let j = 0\r\n for (let p = 0; p < n; p++) {\r\n const { x, i } = other[p]\r\n const c = x[2]\r\n while (j + 1 < n && x[key ^ 1] >= arr[j + 1].x[key]) j++\r\n // console.log(x[key^1], arr[j].x[key])\r\n // while (j < n && x[key] > arr[j].x[key]) j++\r\n ;[first, fc, second, sc] = best[j]\r\n // console.log(x, first, fc, second, sc, '-', arr[j])\r\n if (fc !== c) {\r\n const temp = Math.max(0, x[key] - first)\r\n ans[i] = Math.min(ans[i], temp)\r\n }\r\n if (sc !== c) {\r\n const temp = Math.max(0, x[key] - second)\r\n ans[i] = Math.min(ans[i], temp)\r\n }\r\n // console.log(ans[i])\r\n }\r\n return ans\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const ls = arr.map((x, i) => ({ x, i }))\n .sort((a, b) => a.x[0] - b.x[0])\n const left = cal(n, ls, 0)\n const rs = arr.map(([l, r, c], i) => ({ x: [-l, -r, c], i }))\n .sort((a, b) => a.x[1] - b.x[1])\n const right = cal(n, rs, 1)\n //\n const ans = Array(n)\n for (let i = 0; i < n; i++) {\n ans[i] = Math.min(left[i], right[i])\n if (ans[i] === Infinity) ans[i] = 0\n }\n // console.log(left, right)\n return ans.join(' ')\n}\nfunction cal(n, arr, key) {\n // console.log(arr)\n const ans = Array(n).fill(Infinity)\n //\n let first = -Infinity, second = -Infinity\n let fc, sc // color\n let fi, si\n for (let p = 0; p < n; p++) {\n const { x, i } = arr[p]\n const c = x[2]\n if (fc !== c) {\n const temp = Math.max(0, x[key] - first)\n ans[i] = Math.min(ans[i], temp)\n ans[fi] = Math.min(ans[fi], temp)\n }\n if (sc !== c) {\n const temp = Math.max(0, x[key] - second)\n ans[i] = Math.min(ans[i], temp)\n ans[si] = Math.min(ans[si], temp)\n }\n // console.log(x, first, fc, second, sc)\n //\n const other = x[key ^ 1]\n let ok = 0\n if (fc === c) {\n if (other > first) {\n first = other\n fi = i\n }\n ok = 1\n } else if (sc === c) {\n if (other > second) {\n second = other\n si = i\n }\n ok = 1\n }\n if (ok) {\n if (first < second) {\n [first, second] = [second, first]\n ;[fc, sc] = [sc, fc]\n ;[fi, si] = [si, fi]\n }\n } else {\n if (other > first) {\n second = first\n sc = fc\n si = fi\n first = other\n fc = c\n fi = i\n } else if (other > second) {\n second = other\n sc = c\n si = i\n }\n }\n }\n return ans\n}\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\r\n l += n\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\nconst TreeMultiSet = (function () {\r\nvar{TreeMultiSet:t}=function(t){\r\n/*! *****************************************************************************\r\n Copyright (c) Microsoft Corporation.\r\n\r\n Permission to use, copy, modify, and/or distribute this software for any\r\n purpose with or without fee is hereby granted.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\n PERFORMANCE OF THIS SOFTWARE.\r\n ***************************************************************************** */\r\nvar e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if(\"function\"!=typeof n&&null!==n)throw new TypeError(\"Class extends value \"+String(n)+\" is not a constructor or null\");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(t){var e=\"function\"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&\"number\"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?\"Object is not iterable.\":\"Symbol.iterator is not defined.\")}function o(t,e){var n=\"function\"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o=1&&r[0]instanceof Array?(e=function(){var e=r[0];t.push.apply(t,i([],o(e),!1))},n=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(e=function(){var e=r[0],n=r[1];t.assign(e,n)},n=r.slice(2)):(e=null,n=r),{ramda:e,tail:n}}}(s||(s={}));var h=null;function p(){return null===y&&(null===h&&(h=\"object\"==typeof global&&\"object\"==typeof global.process&&\"object\"==typeof global.process.versions&&void 0!==global.process.versions.node),void 0===(y=h?global:self).__s_iUID&&(y.__s_iUID=0)),y}var f,y=null;function v(t){if(t instanceof Object){if(!1===t.hasOwnProperty(\"__get_m_iUID\")){var e=++p().__s_iUID;Object.defineProperty(t,\"__get_m_iUID\",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function d(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function g(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):v(t)=1&&(c=l.tail[0])}n(c),null!==a&&a()},t.emplacable=function(t,e,n){var r=e.prev(),o=r.equals(t.end())||t.value_comp()(r.value,n);return o=o&&(e.equals(t.end())||t.value_comp()(n,e.value))}}(f||(f={}));var w,I=2166136261,k=16777619,q=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.equals=function(t){return d(this.first,t.first)&&d(this.second,t.second)},t.prototype.less=function(t){return!1===d(this.first,t.first)?g(this.first,t.first):g(this.second,t.second)},t.prototype.hashCode=function(){return function(){for(var t,e,n=[],o=0;o (index = \"+r+\").\")},t.excessive_index=function(t,n,r,o){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric index is equal or greater than size -> (index = \"+r+\", size: \"+o+\").\")},t.not_my_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is not this container's own.\")},t.erased_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator, it already has been erased.\")},t.negative_iterator=function(t,n,r){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is directing negative position -> (index = \"+r+\").\")},t.iterator_end_value=function(t,n){void 0===n&&(n=\"end\");var r=e(t);return new S(\"Error on \"+r+\".Iterator.value: cannot access to the \"+r+\".\"+n+\"().value.\")},t.key_nout_found=function(t,n,r){throw new S(\"Error on \"+e(t)+\".\"+n+\"(): unable to find the matched key -> \"+r)}}(w||(w={}));var j=function(){function t(t,e,n){this.prev_=t,this.next_=e,this.value_=n}return t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e},t.prototype.prev=function(){return this.prev_},t.prototype.next=function(){return this.next_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this._Try_value(),this.value_},enumerable:!1,configurable:!0}),t.prototype._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw w.iterator_end_value(this.source())},t.prototype.equals=function(t){return this===t},t}(),z=function(){function t(t,e){this.index_=t,this.value_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this.value_},enumerable:!1,configurable:!0}),t.prototype.next=function(){return++this.index_,this},t.prototype.equals=function(t){return this.index_===t.index_},t}();var R=function(t){function e(){var e=t.call(this)||this;return e.end_=e._Create_iterator(null,null),e.clear(),e}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},e.prototype.clear=function(){j._Set_prev(this.end_,this.end_),j._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},e.prototype.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(function(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var n;if(e<0){if(!(t.prev instanceof Function))throw new F(\"Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.\");n=function(t){return t.prev()},e=-e}else n=function(t){return t.next()};for(;e-- >0;)t=n(t);return t}(this.end(),-e),this.end())},e.prototype.begin=function(){return this.begin_},e.prototype.end=function(){return this.end_},e.prototype.size=function(){return this.size_},e.prototype.push_front=function(t){this.insert(this.begin_,t)},e.prototype.push_back=function(t){this.insert(this.end_,t)},e.prototype.pop_front=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_front\");this.erase(this.begin_)},e.prototype.pop_back=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_back\");this.erase(this.end_.prev())},e.prototype.push=function(){for(var t=[],e=0;e {\r\n return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])\r\n }) // val, id\r\n const rs = new TreeMultiSet((a, b) => {\r\n return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])\r\n }) // val, id\r\n for (let i = 0; i < arr.length; i++) {\r\n const [l, r, c] = arr[i]\r\n gs[c] = gs[c] || []\r\n gs[c].push(i)\r\n ls.insert([l, i])\r\n rs.insert([r, i])\r\n }\r\n //\r\n const ans = Array(n)\r\n for (let c in gs) {\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n ls.erase([l, i])\r\n rs.erase([r, i])\r\n }\r\n //\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n let diff = Infinity, iter\r\n // last lx <= r || first rx >= l\r\n // r-1, r], r+1\r\n // l-1, [l, l+1\r\n const il = ls.upper_bound([r, Infinity])\r\n const ir = rs.upper_bound([l - 1, Infinity])\r\n // iter = ls.upper_bound([r, i]).prev()\r\n iter = il.prev()\r\n if (iter !== ls.end() && arr[iter.value[1]][1] >= l) {\r\n ans[i] = 0\r\n continue\r\n }\r\n // iter = rs.lower_bound([l, i])\r\n iter = ir\r\n if (iter !== rs.end() && arr[iter.value[1]][0] <= r) {\r\n ans[i] = 0\r\n continue\r\n }\r\n // last rx < l\r\n // iter = rs.lower_bound([l, i]).prev()\r\n iter = ir.prev()\r\n if (iter !== rs.end()) {\r\n diff = Math.min(diff, l - iter.value[0])\r\n }\r\n // first lx > r\r\n // iter = ls.upper_bound([r, i])\r\n iter = il\r\n if (iter !== ls.end()) {\r\n diff = Math.min(diff, iter.value[0] - r)\r\n }\r\n //\r\n ans[i] = diff\r\n }\r\n // recover\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n ls.insert([l, i])\r\n rs.insert([r, i])\r\n }\r\n }\r\n return ans.join(' ')\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\r\n l += n\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\nconst TreeMultiSet = (function () {\r\nvar{TreeMultiSet:t}=function(t){\r\n/*! *****************************************************************************\r\n Copyright (c) Microsoft Corporation.\r\n\r\n Permission to use, copy, modify, and/or distribute this software for any\r\n purpose with or without fee is hereby granted.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\n PERFORMANCE OF THIS SOFTWARE.\r\n ***************************************************************************** */\r\nvar e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if(\"function\"!=typeof n&&null!==n)throw new TypeError(\"Class extends value \"+String(n)+\" is not a constructor or null\");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(t){var e=\"function\"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&\"number\"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?\"Object is not iterable.\":\"Symbol.iterator is not defined.\")}function o(t,e){var n=\"function\"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o=1&&r[0]instanceof Array?(e=function(){var e=r[0];t.push.apply(t,i([],o(e),!1))},n=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(e=function(){var e=r[0],n=r[1];t.assign(e,n)},n=r.slice(2)):(e=null,n=r),{ramda:e,tail:n}}}(s||(s={}));var h=null;function p(){return null===y&&(null===h&&(h=\"object\"==typeof global&&\"object\"==typeof global.process&&\"object\"==typeof global.process.versions&&void 0!==global.process.versions.node),void 0===(y=h?global:self).__s_iUID&&(y.__s_iUID=0)),y}var f,y=null;function v(t){if(t instanceof Object){if(!1===t.hasOwnProperty(\"__get_m_iUID\")){var e=++p().__s_iUID;Object.defineProperty(t,\"__get_m_iUID\",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function d(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function g(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):v(t)=1&&(c=l.tail[0])}n(c),null!==a&&a()},t.emplacable=function(t,e,n){var r=e.prev(),o=r.equals(t.end())||t.value_comp()(r.value,n);return o=o&&(e.equals(t.end())||t.value_comp()(n,e.value))}}(f||(f={}));var w,I=2166136261,k=16777619,q=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.equals=function(t){return d(this.first,t.first)&&d(this.second,t.second)},t.prototype.less=function(t){return!1===d(this.first,t.first)?g(this.first,t.first):g(this.second,t.second)},t.prototype.hashCode=function(){return function(){for(var t,e,n=[],o=0;o (index = \"+r+\").\")},t.excessive_index=function(t,n,r,o){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric index is equal or greater than size -> (index = \"+r+\", size: \"+o+\").\")},t.not_my_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is not this container's own.\")},t.erased_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator, it already has been erased.\")},t.negative_iterator=function(t,n,r){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is directing negative position -> (index = \"+r+\").\")},t.iterator_end_value=function(t,n){void 0===n&&(n=\"end\");var r=e(t);return new S(\"Error on \"+r+\".Iterator.value: cannot access to the \"+r+\".\"+n+\"().value.\")},t.key_nout_found=function(t,n,r){throw new S(\"Error on \"+e(t)+\".\"+n+\"(): unable to find the matched key -> \"+r)}}(w||(w={}));var j=function(){function t(t,e,n){this.prev_=t,this.next_=e,this.value_=n}return t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e},t.prototype.prev=function(){return this.prev_},t.prototype.next=function(){return this.next_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this._Try_value(),this.value_},enumerable:!1,configurable:!0}),t.prototype._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw w.iterator_end_value(this.source())},t.prototype.equals=function(t){return this===t},t}(),z=function(){function t(t,e){this.index_=t,this.value_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this.value_},enumerable:!1,configurable:!0}),t.prototype.next=function(){return++this.index_,this},t.prototype.equals=function(t){return this.index_===t.index_},t}();var R=function(t){function e(){var e=t.call(this)||this;return e.end_=e._Create_iterator(null,null),e.clear(),e}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},e.prototype.clear=function(){j._Set_prev(this.end_,this.end_),j._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},e.prototype.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(function(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var n;if(e<0){if(!(t.prev instanceof Function))throw new F(\"Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.\");n=function(t){return t.prev()},e=-e}else n=function(t){return t.next()};for(;e-- >0;)t=n(t);return t}(this.end(),-e),this.end())},e.prototype.begin=function(){return this.begin_},e.prototype.end=function(){return this.end_},e.prototype.size=function(){return this.size_},e.prototype.push_front=function(t){this.insert(this.begin_,t)},e.prototype.push_back=function(t){this.insert(this.end_,t)},e.prototype.pop_front=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_front\");this.erase(this.begin_)},e.prototype.pop_back=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_back\");this.erase(this.end_.prev())},e.prototype.push=function(){for(var t=[],e=0;e {\r\n return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])\r\n }) // val, id\r\n const rs = new TreeMultiSet((a, b) => {\r\n return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])\r\n }) // val, id\r\n for (let i = 0; i < arr.length; i++) {\r\n const [l, r, c] = arr[i]\r\n gs[c] = gs[c] || []\r\n gs[c].push(i)\r\n ls.insert([l, i])\r\n rs.insert([r, i])\r\n }\r\n //\r\n const ans = Array(n)\r\n for (let c in gs) {\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n ls.erase([l, i])\r\n rs.erase([r, i])\r\n }\r\n //\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n let diff = Infinity, iter\r\n // last lx <= r || first rx >= l\r\n iter = ls.upper_bound([r, i]).prev()\r\n if (iter !== ls.end() && arr[iter.value[1]][1] >= l) {\r\n ans[i] = 0\r\n continue\r\n }\r\n iter = rs.lower_bound([l, i])\r\n if (iter !== rs.end() && arr[iter.value[1]][0] <= r) {\r\n ans[i] = 0\r\n continue\r\n }\r\n // last rx < l\r\n iter = rs.lower_bound([l, i]).prev()\r\n if (iter !== rs.end()) {\r\n diff = Math.min(diff, l - iter.value[0])\r\n }\r\n // first lx > r\r\n iter = ls.upper_bound([r, i])\r\n if (iter !== ls.end()) {\r\n diff = Math.min(diff, iter.value[0] - r)\r\n }\r\n //\r\n ans[i] = diff\r\n }\r\n // recover\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n ls.insert([l, i])\r\n rs.insert([r, i])\r\n }\r\n }\r\n return ans.join(' ')\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\r\n l += n\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const xs = {}\r\n for (let i = 0; i < arr.length; i++) {\r\n const [l, r, c] = arr[i]\r\n xs[l] = 1\r\n xs[r] = 1\r\n }\r\n const sorted = Object.keys(xs)\r\n .map(Number)\r\n .sort((a, b) => a - b)\r\n const rm = sorted.reduce((o, x, i) => {\r\n o[x] = i\r\n return o\r\n }, {})\r\n arr = arr.map(([l, r, c]) => [rm[l], rm[r], c])\r\n //\r\n const N = sorted.length\r\n const gs = {}\r\n const tree = []\r\n createTree(tree, 0, 0, N - 1, 0)\r\n for (let i = 0; i < arr.length; i++) {\r\n const [l, r, c] = arr[i]\r\n gs[c] = gs[c] || []\r\n gs[c].push(i)\r\n insertTree(tree, 0, l, r, 1)\r\n }\r\n //\r\n const ans = Array(n)\r\n for (let c in gs) {\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n insertTree(tree, 0, l, r, -1)\r\n }\r\n //\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n const diff = binarySearch(0, 1e9, d => {\r\n const ll = l - binarySearch(0, l, p => {\r\n return sorted[l] - sorted[l - p] <= d\r\n })\r\n const rr = binarySearch(r, sorted.length - 1, p => {\r\n return sorted[p] - sorted[r] <= d\r\n })\r\n return queryTree(tree, 0, ll, rr) <= 0\r\n }) + 1\r\n ans[i] = diff\r\n }\r\n // recover\r\n for (let i of gs[c]) {\r\n const [l, r] = arr[i]\r\n insertTree(tree, 0, l, r, 1)\r\n }\r\n }\r\n return ans.join(' ')\r\n}\r\nfunction binarySearch(l, r, fn) {\r\n while (l <= r) {\r\n const m = Math.floor((l + r) / 2)\r\n if (fn(m)) {\r\n l = m + 1\r\n } else {\r\n r = m - 1\r\n }\r\n }\r\n return r\r\n}\r\nfunction createTree(tree, p, left, right, val) {\r\n tree[p] = { left, right, val, lazy: val }\r\n if (left === right) return\r\n\r\n const mid = Math.floor((left + right) / 2)\r\n createTree(tree, 2 * p + 1, left, mid, val)\r\n createTree(tree, 2 * p + 2, mid + 1, right, val)\r\n}\r\nfunction initTree(tree, merge, arr) {\r\n for (let i = tree.length - 1; i >= 0; i--) {\r\n if (!tree[i]) continue\r\n const { left, right } = tree[i]\r\n tree[i].val = left === right\r\n ? arr[left % arr.length]\r\n : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)\r\n }\r\n}\r\nfunction insertTree(tree, idx, l, r, val) { // same l, r\r\n const { left, right, lazy } = tree[idx]\r\n if (l <= left && r >= right) {\r\n tree[idx].val += val * (right - left + 1)\r\n tree[idx].lazy += val\r\n return\r\n }\r\n\r\n if (lazy && left !== right) {\r\n tree[2 * idx + 1].val += lazy\r\n tree[2 * idx + 2].val += lazy\r\n tree[2 * idx + 1].lazy += lazy\r\n tree[2 * idx + 2].lazy += lazy\r\n tree[idx].lazy = 0\r\n }\r\n\r\n const mid = Math.floor((left + right) / 2)\r\n if (l <= mid) {\r\n insertTree(tree, 2 * idx + 1, l, r, val)\r\n }\r\n if (r > mid) {\r\n insertTree(tree, 2 * idx + 2, l, r, val)\r\n }\r\n const merge = add\r\n tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)\r\n}\r\nfunction queryTree(tree, idx, l, r) {\r\n const { left, right, val, lazy } = tree[idx]\r\n if (l <= left && r >= right) return val\r\n\r\n const mid = Math.floor((left + right) / 2)\r\n if (lazy) {\r\n tree[2 * idx + 1].val += lazy\r\n tree[2 * idx + 2].val += lazy\r\n tree[2 * idx + 1].lazy += lazy\r\n tree[2 * idx + 2].lazy += lazy\r\n tree[idx].lazy = 0\r\n }\r\n\r\n let a = 0\r\n let b = 0\r\n if (l <= mid) {\r\n a = queryTree(tree, 2 * idx + 1, l, r)\r\n }\r\n if (r > mid) {\r\n b = queryTree(tree, 2 * idx + 2, l, r)\r\n }\r\n const merge = add\r\n return merge(a, b)\r\n}\r\nfunction add(a, b) {\r\n return a + b\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\nfunction ceilPow2(n) {\n let x = 0\n while ((1 << x) < n) x++\n return x\n}\n\nclass LazySegTree {\n constructor(nOrArray, options) {\n const { op, e, mapping, composition, id } = options\n this.op = op\n this.e = e\n const v = Array.isArray(nOrArray) ? nOrArray : Array(nOrArray).fill(0).map(() => e())\n\n const n = v.length\n const log = ceilPow2(n)\n const size = 1 << log\n const d = Array(2 * size)\n const lz = Array(size)\n this.n = n\n this.log = log\n this.size = size\n this.d = d\n this.lz = lz\n this.mapping = mapping\n this.composition = composition\n this.id = id\n\n for (let i = 0; i < d.length; i++) {\n d[i] = e()\n }\n for (let i = 0; i < lz.length; i++) {\n lz[i] = id()\n }\n for (let i = 0; i < n; i++) {\n d[size + i] = v[i]\n }\n for (let i = size - 1; i >= 1; i--) {\n this.update(i)\n }\n }\n set(p, x) {\n p += this.size\n for (let i = this.log; i >= 1; i--) this.push(p >> i);\n this.d[p] = x\n for (let i = 1; i <= this.log; i++) this.update(p >> i)\n }\n get(p) {\n const { size, log } = this\n p += size\n for (let i = log; i >= 1; i--) this.push(p >> i)\n return this.d[p]\n }\n prod(l, r) {\n const { log, size, d, op, e } = this\n if (l === r) return e()\n\n let sml = e(), smr = e()\n l += size\n r += size\n\n for (let i = log; i >= 1; i--) {\n if (((l >> i) << i) != l) this.push(l >> i)\n if (((r >> i) << i) != r) this.push((r - 1) >> i)\n }\n\n while (l < r) {\n if (l & 1) sml = op(sml, d[l++])\n if (r & 1) smr = op(d[--r], smr)\n l >>= 1\n r >>= 1\n }\n return op(sml, smr)\n }\n allProd() {\n return this.d[1]\n }\n apply(p, f) {\n const { size, log, d, mapping } = this\n p += size\n for (let i = log; i >= 1; i--) this.push(p >> i)\n d[p] = mapping(f, d[p])\n for (let i = 1; i <= log; i++) this.update(p >> i)\n }\n applyRange(l, r, f) {\n if (l == r) return\n\n const { size, log } = this\n l += size\n r += size\n\n for (let i = log; i >= 1; i--) {\n if (((l >> i) << i) != l) this.push(l >> i)\n if (((r >> i) << i) != r) this.push((r - 1) >> i)\n }\n\n {\n let l2 = l, r2 = r\n while (l < r) {\n if (l & 1) this.allApply(l++, f)\n if (r & 1) this.allApply(--r, f)\n l >>= 1\n r >>= 1\n }\n l = l2\n r = r2\n }\n\n for (let i = 1; i <= log; i++) {\n if (((l >> i) << i) != l) this.update(l >> i)\n if (((r >> i) << i) != r) this.update((r - 1) >> i)\n }\n }\n maxRight(l, f) {\n const { n, size, log, d, op, e} = this\n if (l == n) return n\n l += size\n for (let i = log; i >= 1; i--) this.push(l >> i)\n let sm = e()\n do {\n while (l % 2 == 0) l >>= 1\n if (!f(op(sm, d[l]))) {\n while (l < size) {\n this.push(l)\n l = (2 * l)\n if (f(op(sm, d[l]))) {\n sm = op(sm, d[l])\n l++\n }\n }\n return l - size\n }\n sm = op(sm, d[l])\n l++\n } while ((l & -l) != l)\n return n\n }\n minLeft(r, f) {\n if (r == 0) return 0\n const { size, log, d, op, e} = this\n r += size\n for (let i = log; i >= 1; i--) this.push((r - 1) >> i)\n let sm = e()\n do {\n r--\n while (r > 1 && (r % 2)) r >>= 1\n if (!f(op(d[r], sm))) {\n while (r < size) {\n this.push(r)\n r = (2 * r + 1)\n if (f(op(d[r], sm))) {\n sm = op(d[r], sm)\n r--\n }\n }\n return r + 1 - size\n }\n sm = op(d[r], sm)\n } while ((r & -r) != r)\n return 0\n }\n\n update(k) {\n const { d, op } = this\n d[k] = op(d[2 * k], d[2 * k + 1])\n }\n allApply(k, f) {\n const { size, d, lz, mapping, composition } = this\n d[k] = mapping(f, d[k])\n if (k < size) lz[k] = composition(f, lz[k])\n }\n push(k) {\n const { lz, id } = this\n this.allApply(2 * k, lz[k])\n this.allApply(2 * k + 1, lz[k])\n lz[k] = id()\n }\n}\n\n// for sum\nconst segOptions = {\n op: (a, b) => [a[0] + b[0], a[1] + b[1]],\n e: () => [0, 0], // val, len\n mapping: (a, b) => [a * b[1] + b[0], b[1]],\n composition: (a, b) => a + b,\n id: () => 0,\n}\n\nfunction solve(n, arr) {\n const xs = {}\n for (let i = 0; i < arr.length; i++) {\n const [l, r, c] = arr[i]\n xs[l] = 1\n xs[r] = 1\n }\n const sorted = Object.keys(xs)\n .map(Number)\n .sort((a, b) => a - b)\n const rm = sorted.reduce((o, x, i) => {\n o[x] = i\n return o\n }, {})\n arr = arr.map(([l, r, c]) => [rm[l], rm[r], c])\n // console.log(rm)\n //\n const N = sorted.length\n const gs = {}\n const seg = new LazySegTree(N, segOptions)\n for (let i = 0; i < N; i++) {\n seg.set(i, [0, 1])\n }\n for (let i = 0; i < arr.length; i++) {\n const [l, r, c] = arr[i]\n // }\n // for (let [l, r, c] of arr) {\n gs[c] = gs[c] || []\n gs[c].push(i)\n seg.applyRange(l, r + 1, 1)\n // console.log(l, r, seg.allProd())\n // console.log(seg.d)\n }\n // console.log(gs)\n // console.log(seg.allProd())\n const ans = Array(n)\n for (let c in gs) {\n for (let i of gs[c]) {\n const [l, r] = arr[i]\n seg.applyRange(l, r + 1, -1)\n }\n //\n for (let i of gs[c]) {\n const [l, r] = arr[i]\n const s = seg.prod(l, r + 1)[0]\n if (s) {\n ans[i] = 0\n } else {\n const diff = binarySearch(1, N - 1, d => {\n return seg.prod(Math.max(0, l - d), Math.min(N - 1, r + d) + 1)[0] <= 0\n }) + 1\n // const ll = Math.max(0, l - diff)\n // const rr = Math.min(N - 1, r + diff)\n // const q = queryTree(tree, 0, ll, rr)\n // console.log(ll, rr, q)\n const left = l - diff >= 0 ? sorted[l] - sorted[l - diff] : Infinity\n const right = r + diff < N ? sorted[r + diff] - sorted[r] : Infinity\n ans[i] = Math.min(left, right)\n // console.log(i, l, r, diff)\n }\n }\n // recover\n for (let i of gs[c]) {\n const [l, r] = arr[i]\n seg.applyRange(l, r + 1, 1)\n }\n }\n return ans.join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "9be594097a1b2249c4227bde12c5552c"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = [];\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString.push(inputStdin);\n});\n\nprocess.stdin.on('end', () => {\n inputString = inputString.join('').trim().split('\\n').map(string => string.trim());\n \n //withTiming(main);\n main(); \n});\n\nconst readline = () => inputString[currentLine++];\n\nconst withTiming = callback => {\n const start = new Date();\n callback();\n console.log(`Took ${new Date() - start} ms`);\n}\n\nconst main = () => {\n const t = parseInt(readline());\n\n for (let i = 0; i < t; i++) {\n const [cards, jokers, players] = readline().split(' ').map(x => parseInt(x));\n\n const cardsPerPlayer = parseInt(cards / players);\n const jokersWinner = Math.min(cardsPerPlayer, jokers);\n const spreadJokers = Math.ceil((jokers - jokersWinner) / (players - 1));\n const result = jokersWinner - spreadJokers;\n\n console.log(Math.max(0, result));\n }\n}\n", "positive_code": [{"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar n = one[0];\n\t\tvar m = one[1];\n\t\tvar k = one[2];\n\t\tvar single = n / k;\n\t\tif(single >= m){\n\t\t\toutput[i] = m;\n\t\t}else{\n\t\t\tvar amari = m - single;\n\t\t\tvar hoka = Math.ceil(amari / (k - 1));\n\t\t\toutput[i] = single - hoka;\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i +x)\n const max = Math.min(m, n/k)\n const rest = m - max\n const min = Math.ceil(rest / (k-1))\n console.log(max - min)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n// node.js \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var testCases = parseInt(readLine());\n\n function maxNumberOfPointsForWin(numberOfCards, numberOfJokers, numberOfPlayers) {\n var numberOfPlayerCards = numberOfCards / numberOfPlayers;\n var winnerJokerCards = Math.min(numberOfJokers, numberOfPlayerCards);\n var remainingJokers = numberOfJokers - winnerJokerCards;\n var maxPlayerPoints = Math.ceil(Math.min(remainingJokers / (numberOfPlayers - 1), numberOfPlayerCards));\n\n return winnerJokerCards - maxPlayerPoints;\n }\n\n for (var i = 0; i < testCases; i++) {\n var numbers = readLine()\n .split(\" \")\n .map(num => parseInt(num));\n\n var numberOfCards = numbers[0];\n var numberOfJokers = numbers[1];\n var numberOfPlayers = numbers[2];\n\n console.log(maxNumberOfPointsForWin(numberOfCards, numberOfJokers, numberOfPlayers));\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\n\twhile (t--) {\n\t\tlet [n, m, k] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet c = n / k;\n\n\t\tif (m === 0) {\n\t\t\tconsole.log(0);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (m <= c) {\n\t\t\tconsole.log(m);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet r = m - c;\n\t\tlet res = c;\n\n\t\tif (r % (k - 1) > 0) {\n\t\t\tres -= Math.floor(r / (k - 1)) + 1;\n\t\t} else {\n\t\t\tres -= Math.floor(r / (k - 1));\n\t\t}\n\n\t\tconsole.log(res);\n\t}\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet index = 0;\n\nreadline.on('line', line => {\n index++;\n if (index > 1) {\n const [cards, jokers, players] = line.split(' ');\n const cardsPerPlayer = cards/players;\n if (cardsPerPlayer >= jokers) {\n console.log(jokers);\n return;\n }\n const maxOtherPlayerCards = Math.ceil((jokers - cardsPerPlayer) / (players - 1));\n console.log(cardsPerPlayer - maxOtherPlayerCards);\n return;\n }\n});\n\n/**\n\n12, 7, 3\nJ,J,J,J\nJ,J\nJ\n\n(12/3 = 4) => (4 < 7) => (7-4 = 3) => (ceil(3/2) = 2)\n */"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n m = input[1],\n k = input[2];\n\n var cards = n / k;\n if (m == 0) print(0);\n else if (cards >= m) print(m);\n else {\n m -= cards;\n var players = k - 1;\n var count = 1;\n var round = 0;\n while (m > 0 && count <= cards * players) {\n if (round == players) {\n round = 0;\n count++;\n }\n m--;\n round++;\n }\n\n print(cards - count);\n }\n}\n"}, {"source_code": "var testCases = readline();\nfor(var i =0; i< testCases; i++) {\n var line = readline().split(\" \");\n var cards = line[0], jokers = line[1], players = line[2];\n var cardsPerUser = cards/players;\n var maxJokers = cardsPerUser < jokers ? cardsPerUser : jokers;\n var leftJokers = jokers - maxJokers;\n print(maxJokers - Math.ceil(leftJokers/ (players - 1)));\n}\n\n\n"}, {"source_code": "function solve(n,m,k) {\n var c = n/k;\n var mn = Math.min(c,m);\n var d = m-mn;\n d = Math.ceil(d/(k-1));\n return mn-d;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var m = arr[1];\n var k = arr[2];\n print(solve(n,m,k));\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n m = input[1],\n k = input[2];\n\n var cards = n / k;\n if (m == 0) print(0);\n else if (cards >= m) print(m);\n else {\n var players = k - 1;\n var count = 1;\n var round = 0;\n while (m > 0 && count * players <= cards) {\n if (round == players) {\n round = 0;\n count++;\n m--;\n continue;\n }\n m--;\n round++;\n }\n\n print(cards - count);\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n m = input[1],\n k = input[2];\n\n var cards = n / k;\n if (m == 0) print(0);\n else if (cards >= m) print(m);\n else {\n var players = k - 1;\n var count = 1;\n var round = 1;\n while (m > 0 && count * players <= cards) {\n if (round == players) {\n round = 1;\n count++;\n m--;\n continue;\n }\n m--;\n round++;\n }\n\n print(cards - count);\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n m = input[1],\n k = input[2];\n\n var cards = n / k;\n if (m == 0) print(0);\n else if (cards >= m) print(m);\n else {\n var players = k - 1;\n var count = 1;\n var round = 0;\n while (m > 0 && count <= cards * players) {\n if (round == players) {\n round = 0;\n count++;\n m--;\n continue;\n }\n m--;\n round++;\n }\n\n print(cards - count);\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n m = input[1],\n k = input[2];\n\n var cards = n / k;\n if (m == 0) print(0);\n else if (cards >= m) print(m);\n else {\n m -= cards;\n var players = k - 1;\n var count = 1;\n var round = 0;\n while (m > 0 && count <= cards * players) {\n if (round == players) {\n round = 0;\n count++;\n m--;\n continue;\n }\n m--;\n round++;\n }\n\n print(cards - count);\n }\n}\n"}, {"source_code": "function solve(n,m,k) {\n var c = n/k;\n var mn = Math.min(c,m);\n var d = m-mn;\n d = Math.ceil(d/(k-1));\n return c-d;\n}\nvar t = Number(readline());\nwhile (t--) {\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var m = arr[1];\n var k = arr[2];\n print(solve(n,m,k));\n}"}], "src_uid": "6324ca46b6f072f8952d2619cb4f73e6"} {"source_code": "function calc(arr) {\n // calc (odd - even) to the left\n var arrLeft = [0];\n var curSum = 0;\n for (var i = 1; i < arr.length; i++) {\n curSum += arr[i - 1] * (i % 2 ? 1 : -1);\n arrLeft.push(curSum);\n }\n // print(arrLeft);\n \n // calc (odd - even) to the right\n var arrRight = [0];\n curSum = 0;\n for (var i = arr.length - 2; i > -1; i--) {\n curSum += arr[i + 1] * (i % 2 ? -1 : 1)\n arrRight.push(curSum);\n }\n arrRight.reverse();\n // print(arrRight);\n \n var res = 0;\n for (var i = 0; i < arr.length; i++) {\n if (arrLeft[i] + arrRight[i] === 0) {\n res++;\n }\n }\n \n return res;\n}\n\nvar n = parseInt(readline());\n\nvar arr = readline().split(\" \").map(el => parseInt(el));\n\nprint(calc(arr));\n\n\n", "positive_code": [{"source_code": "var nums = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = nums[0];\nvar s = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar od = Array(n).fill(0);\nvar ev = Array(n).fill(0);\nod[0] = 0, ev[0] = s[0];\nfor (var i=1; i=0; i--) {\n\tod2[i] = od2[i+1];\n\tif ((n-1-i)%2===1) od2[i] += s[i];\n\tev2[i] = ev2[i+1];\n\tif ((n-1-i)%2===0) ev2[i] += s[i];\n}\n\nvar ans = 0;\nfor (var i=0; i 0) od_sum += od[i-1];\n\tvar ev_sum = 0;\n\tif (i > 0) ev_sum += ev[i-1];\n\n\tif (i+1 < n) {\n\t\tif (n%2 == 1) {\n\t\t\tev_sum += od2[i+1];\n\t\t\tod_sum += ev2[i+1];\n\t\t}\n\t\telse {\n\t\t\tev_sum += ev2[i+1];\n\t\t\tod_sum += od2[i+1];\n\t\t}\n\t}\n\n\tif (od_sum === ev_sum)\n\t\tans++;\n}\nwrite(ans+\"\\n\");"}, {"source_code": "var n = parseInt(readline())\nvar ar = readline().split(' ').map((v)=>(parseInt(v)))\n\nvar evenSum = [], prv=0;\nar.forEach((v, i)=>{\n \n evenSum[i] = (i%2===0) ? v+prv: prv\n prv = evenSum[i];\n});\n\nvar oddSum = [];\nprv =0;\nar.forEach((v, i)=>{\n \n oddSum[i] = (i%2!==0) ? v+prv: prv\n prv = oddSum[i];\n});\n\nvar res = 0, currentEvenSum = -1, currentOddSum=0;\nfor(var i=0;i0 ? evenSum[i-1]:0) + oddSum[evenSum.length-1] - oddSum[i] //-ar[i]?i%2\n currentOddSum = (i>0 ? oddSum[i-1]:0) + evenSum[evenSum.length-1] - evenSum[i]\n if (currentEvenSum === currentOddSum) {\n res++;\n }\n}\n\nprint(res)"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \").map(function(element) {return +element});\nvar sum = [];\nvar sumAll = [0, 0];\nsum.push([0]);\nsum.push([0]);\nfor (var i=0; i < n; i++) {\n var index = i % 2;\n sumAll[index] += a[i];\n sum[index].push(sumAll[index]);\n}\nvar count = 0;\nvar s = sumAll[0] + sumAll[1];\nfor (var i = 1; i < sum[0].length; i++) {\n var sum1 = sum[0][i - 1] + sumAll[1] - sum[1][i - 1];\n var sum2 = s - sum1 - a[(i - 1) * 2];\n if (sum1 === sum2) {\n count++;\n }\n}\n\nfor (var i = 1; i < sum[1].length; i++) {\n var sum1 = sum[1][i - 1] + (i < sum[0].length ? sumAll[0] - sum[0][i] : 0);\n var sum2 = s - sum1 - a[i * 2 - 1];\n if (sum1 === sum2) {\n count++;\n }\n}\nprint(count);"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n const ar1 = arr[0].split(' ')\n const ar = []\n ar1.forEach(el => ar.push(parseInt(el)))\n \n let odd = 0, even = 0\n for(let i = 0, len = ar.length; i < len; i++) {\n if(i % 2 == 0) even += ar[i]\n else odd += ar[i]\n }\n\n var oB = 0, eB = 0\n var count = 0\n\n for(let i = 0, len = ar.length; i < len; i++) {\n if(i % 2 == 0) {\n var oA = even - ar[i] - eB\n var eA = odd - oB\n if(oA + oB == eA + eB) count ++\n eB += ar[i]\n }\n else {\n var oA = even - eB\n var eA = odd - ar[i] - oB\n if(oA + oB == eA + eB) count ++\n oB += ar[i]\n }\n }\n\n console.log(count)\n})"}], "negative_code": [], "src_uid": "dcc380c544225c8cadf0df8d8b6ffb4d"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nclass Record {\r\n constructor(id, start) {\r\n this.id = id;\r\n this.start = start;\r\n }\r\n\r\n lose(end) {\r\n this.end = end;\r\n }\r\n\r\n get(rounds) {\r\n if (rounds >= this.start) {\r\n return Math.min(this.end, (rounds + 1)) - this.start;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const [n, q] = readline().split(' ').map(Number);\r\n const arr = readline().split(' ').map(Number);\r\n\r\n const str = {};\r\n let maxId = -1;\r\n arr.forEach((val, i) => {\r\n str[i + 1] = val;\r\n if (val === n) {\r\n maxId = i + 1;\r\n }\r\n });\r\n\r\n const data = {};\r\n let first = 1;\r\n let curr = new Record(1, 1);\r\n data[1] = curr;\r\n\r\n for (let i = 2; i <= n; i++) {\r\n if (str[i] === n) {\r\n curr.lose(i - 1);\r\n break;\r\n }\r\n if (str[i] > str[first]) {\r\n first = i;\r\n curr.lose(i - 1);\r\n curr = new Record(i, i - 1);\r\n data[i] = curr;\r\n } else if (i === n) {\r\n curr.lose(i);\r\n }\r\n }\r\n\r\n for (let question = 0; question < q; question++) {\r\n const [i, k] = readline().split(' ').map(Number);\r\n\r\n if (i === maxId) {\r\n if (maxId < 3) {\r\n output(k);\r\n } else {\r\n output(Math.max((k - i + 2), 0));\r\n }\r\n } else if (!data[i]) {\r\n output(0);\r\n } else {\r\n output(data[i].get(k));\r\n }\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, q] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n q,\n a,\n i: [],\n k: [],\n };\n for (let j = 0; j < q; j++) {\n index++;\n const [i, k] = input[index].split(\" \").map((item) => parseInt(item));\n testCase.i.push(i);\n testCase.k.push(k);\n }\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, q, a, i, k } = testCase;\n // console.log(n, q, a, i, k);\n\n const winners = new Array(n + 1).fill(0).map((_) => []);\n let maxi = a[0];\n\n for (let j = 1; j < n; j++) {\n const val = a[j];\n\n if (val > maxi) {\n if (maxi && j > 1) winners[maxi].push(j - 1);\n maxi = val;\n }\n if (winners[maxi][0] == undefined) winners[maxi].push(j);\n }\n\n // console.log(winners);\n\n for (let j = 0; j < q; j++) {\n const ii = i[j];\n const kk = k[j];\n const val = a[ii - 1];\n\n const [startWin, endWin] = winners[val];\n // console.error(ii, val, kk, startWin, endWin);\n if (startWin == undefined) console.log(0);\n else {\n console.log(\n Math.max(\n 0,\n Math.min(kk, endWin == undefined ? Infinity : endWin) - startWin + 1\n )\n );\n }\n\n // console.error(\"-----\");\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const win = Array(n + 1)\n let f = arr[0]\n for (let i = 1; i < arr.length; i++) {\n const x = arr[i]\n if (f < x) {\n f = x\n }\n win[f] = win[f] || []\n win[f].push(i)\n if (f === n) break\n }\n// console.log(win)\n return qs.map(([i, k]) => {\n const x = arr[i - 1]\n const lst = win[x] || []\n let r = binarySearch(0, lst.length - 1, idx => lst[idx] <= k)\n if (x === n && k >= win[f]) {\n r += k - win[f]\n }\n return r + 1\n }).join('\\n')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const l = new Array(n).fill(0),\r\n r = new Array(n).fill(0);\r\n let max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (max === -1 || a[max] < a[i]) {\r\n max = i;\r\n } else {\r\n l[i] = 1;\r\n }\r\n }\r\n {\r\n const stack = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n while (stack.length && a[stack[stack.length - 1]] < a[i]) stack.pop();\r\n if (stack.length) r[i] = stack[stack.length - 1];\r\n stack.push(i);\r\n }\r\n }\r\n const res = [];\r\n for (let [i, k] of b) {\r\n i--;\r\n if (k < i || l[i]) {\r\n res.push(0);\r\n } else if (!r[i]) {\r\n res.push(k - i + (i ? 1 : 0));\r\n } else {\r\n let ans = 0;\r\n k -= i;\r\n if (i) ans = 1;\r\n res.push(Math.min(k, r[i] - i - 1) + ans);\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = await rns();\r\n const a = await rns();\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push(await rns());\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var n, Q, a;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nq[0];\r\n Q = nq[1];\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var wins = new Array(n).fill(0);\r\n var ind = 1;\r\n var curr = [0, a[0]];\r\n while (curr[1] != n) {\r\n if (a[ind] > curr[1]) {\r\n curr = [ind, a[ind]];\r\n }\r\n wins[curr[0]]++;\r\n ind++;\r\n }\r\n for (var q = 0; q < Q; q++) {\r\n var ik = readline().split(' ').map(x=>parseInt(x));\r\n var i = ik[0];\r\n var k = ik[1];\r\n if (k < i-1) {\r\n print(0);\r\n continue;\r\n }\r\n var ans = 0;\r\n if (curr[0]+1 == i) {\r\n ans = k - i + 2;\r\n if (i == 1) {\r\n ans--;\r\n }\r\n } else {\r\n if (wins[i-1]) {\r\n if (i == 1) {\r\n ans = Math.min(k - i + 1, wins[i-1]);\r\n } else {\r\n ans = Math.min(k - i + 2, wins[i-1]);\r\n }\r\n }\r\n }\r\n print(ans);\r\n }\r\n }"}, {"source_code": "var n, Q, a;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nq[0];\r\n Q = nq[1];\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var wins = new Array(n).fill(0);\r\n var ind = 1;\r\n var curr = [0, a[0]];\r\n while (curr[1] != n) {\r\n if (a[ind] > curr[1]) {\r\n curr = [ind, a[ind]];\r\n }\r\n wins[curr[0]]++;\r\n ind++;\r\n }\r\n for (var q = 0; q < Q; q++) {\r\n var ik = readline().split(' ').map(x=>parseInt(x));\r\n var i = ik[0];\r\n var k = ik[1];\r\n if (k < i-1) {\r\n print(0);\r\n continue;\r\n }\r\n var ans = 0;\r\n if (curr[0]+1 == i) {\r\n ans = k - i + 2;\r\n if (i == 1) {\r\n ans--;\r\n }\r\n } else {\r\n if (wins[i-1]) {\r\n if (i == 1) {\r\n ans = Math.min(k - i + 1, wins[i-1]);\r\n } else {\r\n ans = Math.min(k - i + 2, wins[i-1]);\r\n }\r\n }\r\n }\r\n print(ans);\r\n }\r\n }"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, q] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n q,\n a,\n i: [],\n k: [],\n };\n for (let j = 0; j < q; j++) {\n index++;\n const [i, k] = input[index].split(\" \").map((item) => parseInt(item));\n testCase.i.push(i);\n testCase.k.push(k);\n }\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, q, a, i, k } = testCase;\n // console.log(n, q, a, i, k);\n\n const winners = new Array(n + 1).fill(0).map((_) => []);\n let maxi = a[0];\n\n for (let j = 1; j < n; j++) {\n const val = a[j];\n\n if (val > maxi) {\n if (maxi && j > 1) winners[maxi].push(j - 1);\n maxi = val;\n }\n if (winners[maxi][0] == undefined) winners[maxi].push(j);\n }\n\n // console.log(winners);\n\n for (let j = 0; j < q; j++) {\n const ii = i[j];\n const kk = k[j];\n const val = a[ii - 1];\n\n const [startWin, endWin] = winners[val];\n // console.error(ii, val, kk, startWin, endWin);\n if (startWin == undefined) console.log(0);\n else {\n console.log(\n Math.min(kk, endWin == undefined ? Infinity : endWin) - startWin + 1\n );\n }\n\n // console.error(\"-----\");\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, q] = input[index].split(\" \").map((item) => parseInt(item));\n index++;\n const a = input[index].split(\" \").map((item) => parseInt(item));\n const testCase = {\n n,\n q,\n a,\n i: [],\n k: [],\n };\n for (let j = 0; j < q; j++) {\n index++;\n const [i, k] = input[index].split(\" \").map((item) => parseInt(item));\n testCase.i.push(i);\n testCase.k.push(k);\n }\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, q, a, i, k } = testCase;\n // console.log(n, q, a, i, k);\n\n const winners = new Array(n + 1).fill(0).map((_) => []);\n let maxi = a[0];\n\n for (let j = 1; j < n; j++) {\n const val = a[j];\n\n if (val > maxi) {\n if (maxi) winners[maxi].push(j - 1);\n maxi = val;\n }\n if (winners[maxi][0] == undefined) winners[maxi].push(j);\n }\n\n // console.log(winners);\n\n for (let j = 0; j < q; j++) {\n const ii = i[j];\n const kk = k[j];\n const val = a[ii - 1];\n\n const [startWin, endWin] = winners[val];\n // console.error(ii, val, kk, startWin, endWin);\n if (startWin == undefined) console.log(0);\n else {\n console.log(\n Math.min(kk, endWin == undefined ? Infinity : endWin) - startWin + 1\n );\n }\n\n // console.log(result);\n // console.error(\"-----\");\n }\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n const win = Array(n + 1)\n let f = arr[0]\n for (let i = 1; i < arr.length; i++) {\n const x = arr[i]\n if (f < x) {\n f = x\n }\n win[f] = win[f] || []\n win[f].push(i)\n if (f === n) break\n }\n// console.log(win)\n return qs.map(([i, k]) => {\n const x = arr[i - 1]\n const lst = win[x] || []\n let r = binarySearch(0, lst.length - 1, idx => lst[idx] <= k)\n if (x === n) {\n r += k - win[f]\n }\n return r + 1\n }).join('\\n')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const l = new Array(n).fill(0),\r\n r = new Array(n).fill(n);\r\n let max = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (max === -1 || a[max] < a[i]) {\r\n max = i;\r\n } else {\r\n l[i] = 1;\r\n }\r\n }\r\n {\r\n const stack = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n while (stack.length && stack[stack.length - 1] < a[i]) stack.pop();\r\n if (stack.length) r[i] = stack[stack.length - 1];\r\n stack.push(i);\r\n }\r\n }\r\n const res = [];\r\n for (let [i, k] of b) {\r\n i--;\r\n if (k < i || l[i]) {\r\n res.push(0);\r\n } else if (r[i] === n) {\r\n res.push(k - i + (i ? 1 : 0));\r\n } else if (i < k) {\r\n let ans = 0;\r\n k -= i;\r\n if (i) ans = 1;\r\n res.push(Math.min(k, r[i] - i - 1) + ans);\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = await rns();\r\n const a = await rns();\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push(await rns());\r\n }\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "7372994c95acc3b999dd9657abd35a24"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (n == 4 & k == 3) { \r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (k != n-1) {\r\n\t\t\tconsole.log(k, n-1);\r\n\t\t\tk && console.log(n-1-k, 0);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == k || i == n-1-k) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(n-1, n-2);\r\n\t\t\tconsole.log(1, 3);\r\n\t\t\tconsole.log(0, n-1-3);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == 1 || i == 3) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (n == 4 & k == 3) { \r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (k == 0) {\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else if (k < n-1) {\r\n\t\t\tconsole.log(k, n-1);\r\n\t\t\tconsole.log(n-1-k, 0);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == k || i == n-1-k) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(n-1, n-2);\r\n\t\t\tconsole.log(1, 3);\r\n\t\t\tconsole.log(0, n-1-3);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == 1 || i == 3) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (n == 4 & k == 3) { \r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (k != n-1) {\r\n\t\t\tconsole.log(k, n-1);\r\n\t\t\tk && console.log(n-1-k, 0);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == k || i == n-1-k) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(n-1, n-2);\r\n\t\t\tconsole.log(1, 3);\r\n\t\t\tconsole.log(0, n-1-3);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == 1 || i == 2 || i == 3) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (n == 4 & k == 3) { \r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (k != n-1) {\r\n\t\t\tconsole.log(k, n-1);\r\n\t\t\tk && console.log(n-1-k, 0);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == k || i == n-1-k) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(n-1, n-2);\r\n\t\t\tconsole.log(1, 3);\r\n\t\t\tconsole.log(0, n-1-3);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (i == 0 || i == 1 || i == 2) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (n == 4 & k == 3) { \r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (k != n-1) {\r\n\t\t\tconsole.log(k, n-1);\r\n\t\t\tconsole.log(n-1-k, 0);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (n == 0 || n == k || n == n-1-k) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(n-1, n-2);\r\n\t\t\tconsole.log(1, 3);\r\n\t\t\tconsole.log(0, n-1-3);\r\n\t\t\tfor (let i = 0; i < n/2; i++) {\r\n\t\t\t\tif (n == 0 || n == 1 || n == 2) continue;\r\n\t\t\t\tconsole.log(i, n-1-i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "28d1c6a6effb1aea722164d5735377fc"} {"source_code": "var k = readline().split(' ').map(Number)[1];\nvar a = readline().split(' ').map(Number);\nvar sum = a.reduce((a, b) => a + b);\nfor (var i = 1; i < a.length; i++) {\n a[i] = Math.max(a[i], k - a[i - 1])\n}\nprint(a.reduce((a, b) => a + b) - sum);\nprint(a.join(' '));", "positive_code": [{"source_code": "var nk = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=nk[0],k=nk[1];\n\nvar a = readline().trim().split(' ').map((x)=>parseInt(x))\nvar b = [a[0]];\nvar nbr =0;\nfor(var i=1;i= K) {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i] = K - days[i + 1];\n\t\t\t} else {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i + 1] = K - days[i];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tstr += days[i];\n\tif (i != days.length - 1) {\n\t\t str += \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "var line = readline().split(' ');\nvar n = parseInt(line[0]);\nvar k = parseInt(line[1]);\nvar a = readline().split(' ').map(function(num) { return parseInt(num, 10); });\n\nans = 0;\n\nfor (var i = 1; i < n; i++) {\n var extra = k - a[i-1] - a[i];\n if (extra > 0) {\n a[i] += extra;\n ans += extra;\n }\n}\n\nprint(ans);\nprint(a.join(' '));"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var k = line[1];\n var data = readline().split(' ').map(Number);\n var res = 0;\n for(var i=0;i 1) {\n for (let i = 1; i < statistics.length; i++) {\n addition = requiredSum - statistics[i - 1] - statistics[i];\n if (addition > 0) {\n statistics[i] += addition;\n totalAdded += addition;\n }\n }\n }\n\n // answer in required format\n return [totalAdded, statistics.join(\" \")];\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [n, k] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet schedules = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet b = [];\n\tlet extra = 0;\n\tb.push(schedules[0]);\n\n\tfor (let i = 1; i < n; i++) {\n\t\tlet sum = schedules[i] + schedules[i - 1];\n\t\tif (sum >= k) {\n\t\t\tb[i] = schedules[i];\n\t\t} else {\n\t\t\tb[i] = schedules[i] + (k - sum);\n\t\t\tschedules[i] = b[i];\n\t\t\textra += k - sum;\n\t\t}\n\t}\n\n\tconsole.log(extra);\n\tconsole.log(b.join(' '));\n}\n"}, {"source_code": "function trips(k, planned) {\n let newPlan = [parseInt(planned[0])];\n let extra = 0;\n for (let i = 1; i < planned.length; i ++) {\n let previous = parseInt(planned[i - 1]);\n let difference = k - (parseInt(planned[i]) + previous);\n if (difference > 0) {\n extra += difference;\n planned[i] = parseInt(planned[i]) + difference;\n }\n }\n return {\n extra,\n newPlan: planned.join(' ')\n }\n}\n\nfunction processData(input) {\n let arr = input.split('\\n');\n let numbers = arr[0].split(' ');\n\n let n = parseInt(numbers[0]);\n let k = parseInt(numbers[1]);\n\n let data = arr[1].split(' ');\n let answer = trips(k, data);\n console.log(answer.extra);\n console.log(answer.newPlan);\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}], "negative_code": [{"source_code": "const reader = require(\"readline\").createInterface({\n input: process.stdin\n});\n\nconst input = [];\n\nreader.on(\"line\", storeInput);\nreader.on(\"close\", submitResult);\n\nfunction storeInput(line) {\n input.push(line);\n}\nfunction submitResult() {\n const result = performCalculation();\n for (let line of result) {\n process.stdout.write(line + '\\n');\n }\n}\nfunction performCalculation() {\n // Define input values\n const requiredSum = Number(input[0].split(\" \")[1]);\n const statistics = input[1].split(\" \").map(Number);\n\n // We can get O(n) solution:\n // iterate over the statistics, starting from 2nd element\n // apply logic to find required maximum for current item\n\n // from task description: item `n + 1` is always `requiredSum`\n\n let totalAdded = 0;\n let addition = 0;\n if (statistics.length === 1) {\n addition = requiredSum - statistics[0];\n if (addition > 0) {\n statistics[0] += addition;\n totalAdded += addition;\n }\n } else {\n for (let i = 1; i < statistics.length; i++) {\n addition = requiredSum - statistics[i - 1] - statistics[i];\n if (addition > 0) {\n statistics[i] += addition;\n totalAdded += addition;\n }\n }\n }\n\n // answer in required format\n return [totalAdded, statistics.join(\" \")];\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [n, k] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\tlet schedules = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet b = [];\n\tlet extra = 0;\n\tb.push(schedules[0]);\n\n\tfor (let i = 1; i < n; i++) {\n\t\tlet sum = schedules[i] + schedules[i - 1];\n\t\tif (sum >= k) {\n\t\t\tb[i] = schedules[i];\n\t\t} else {\n\t\t\tb[i] = schedules[i] + (k - sum);\n\t\t\tschedules[i] = b[i];\n\t\t\textra += b[i];\n\t\t}\n\t}\n\n\tconsole.log(extra);\n\tconsole.log(b.join(' '));\n}\n"}, {"source_code": "function readIntTabLine() {\n var l = readline().split(' ')\n for (var i = 0 ; i < l.length ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar given = readIntTabLine(), // n days k walks for two days <500\n plan = readIntTabLine()\n\n/*\nfor (var i = 0 ; i < given[0] ; i++) {\n plan[i] = parseInt(readline())\n}\n*///console.log(plan)\n\nvar ans = [], ans2 = [], tot = -1, tot2 = 0, start = 0\n\ndo {\n tot2 = start\n ans2 = [start + plan[0]]\n \n for (var i = 1 ; i < given[0] ; i++) {\n if (ans2[i-1] + plan[i] < given[1]) {\n tot2 += given[1] - plan[i] - ans2[i-1]\n ans2[i] = given[1] - ans2[i-1]\n } else {\n ans2[i] = plan[i]\n }//console.log(start,tot2,ans2)\n }\n \n if (tot2 < tot || tot == -1) {\n ans = ans2\n tot = tot2\n }\n \n start++\n} while (plan[0] + start <= given[1] && tot != 0)\n \nprint(tot)\nprint(ans)\n"}, {"source_code": "var arr = readline().split(' ');\nvar N = Number(arr[0]);\nvar K = Number(arr[1]);\n\nvar days = [];\n\nvar rs = 0;\n\narr = readline().split(' ');\nfor (var i = 0;i < N;i ++) {\n\tdays[i] = Number(arr[i]);\n}\n\nif (days.length == 1) {\n\tif (K >= days[0]) {\n\t\trs = K - days[0];\n\t\tdays = [K];\n\t} else {\n\t\trs = 0;\n\t}\n} else {\n\tfor (var i = 0;i < days.length - 1;i ++) {\n\t\tif (days[i] + days[i + 1] < K) {\n\t\t\tif (i + 1 == days.length - 1 || days[i + 2] + days[i + 1] >= K) {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i] = K - days[i + 1];\n\t\t\t} else {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i + 1] = K - days[i];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tif (i != days.length - 1) {\n\t\tstr += days[i] + \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "var arr = readline().split(' ');\nvar N = Number(arr[0]);\nvar K = Number(arr[1]);\n\nvar days = [];\n\nvar rs = 0;\n\narr = readline().split(' ');\nfor (var i = 0;i < N;i ++) {\n\tdays[i] = Number(arr[i]);\n}\n\nif (days.length == 1) {\n\tif (K >= days[0]) {\n\t\trs = K - days[0];\n\t\tdays = [K];\n\t} else {\n\t\trs = 0;\n\t}\n} else {\n\tfor (var i = 0;i < days.length - 1;i ++) {\n\t\tif (days[i] + days[i + 1] < K) {\n\t\t\tif (i + 1 == days.length - 1 || days[i + 2] + days[i + 1] >= K) {\n\t\t\t\tdays[i] = K - days[i + 1];\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t} else {\n\t\t\t\tdays[i + 1] = K - days[i];\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tif (i != days.length - 1) {\n\t\tstr += days[i] + \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "var arr = readline().split(' ');\nvar N = Number(arr[0]);\nvar K = Number(arr[1]);\n\nvar days = [];\n\nvar rs = 0;\n\narr = readline().split(' ');\nfor (var i = 0;i < N;i ++) {\n\tdays[i] = Number(arr[i]);\n}\n\nif (days.length == 1) {\n\tif (K >= days[0]) {\n\t\trs = K - days[0];\n\t\tdays = [K];\n\t} else {\n\t\trs = 0;\n\t}\n} else {\n\tfor (var i = 0;i < days.length - 1;i ++) {\n\t\tif (days[i] + days[i + 1] < K) {\n\t\t\tif (i + 1 == days.length - 1 || days[i + 2] + days[i + 1] >= K) {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i] = K - days[i + 1];\n\t\t\t} else {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i + 1] = K - days[i];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tstr += days[i];\n\tif (i != days.length - 1) {\n\t\t str += \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "var arr = readline().split(' ');\nvar N = Number(arr[0]);\nvar K = Number(arr[1]);\n\nvar days = [];\n\nvar rs = 0;\n\narr = readline().split(' ');\nfor (var i = 0;i < arr.length;i ++) {\n\tdays[i] = Number(arr[i]);\n}\n\nif (days.length == 1) {\n\tif (K >= days[0]) {\n\t\trs = K - days[0];\n\t\tdays = [K];\n\t} else {\n\t\trs = 0;\n\t}\n} else {\n\tfor (var i = 0;i < days.length - 1;i ++) {\n\t\tif (days[i] + days[i + 1] < K) {\n\t\t\tif (i + 1 == days.length - 1 || days[i + 2] + days[i + 1] >= K) {\n\t\t\t\tdays[i] = K;\n\t\t\t\trs += K - days[i];\n\t\t\t} else {\n\t\t\t\tdays[i + 1] = K;\n\t\t\t\trs += K - days[i + 1];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tif (i != days.length - 1) {\n\t\tstr += days[i] + \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "var arr = readline().split(' ');\nvar N = Number(arr[0]);\nvar K = Number(arr[1]);\n\nvar days = [];\n\nvar rs = 0;\n\narr = readline().split(' ');\nfor (var i = 0;i < N;i ++) {\n\tdays[i] = Number(arr[i]);\n}\n\nif (days.length == 1) {\n\tif (K >= days[0]) {\n\t\trs = K - days[0];\n\t\tdays = [K];\n\t} else {\n\t\trs = 0;\n\t}\n} else {\n\tfor (var i = 0;i < days.length - 1;i ++) {\n\t\tif (days[i] + days[i + 1] < K) {\n\t\t\tif (i + 1 == days.length - 1 || days[i + 2] + days[i + 1] >= K) {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i] = K - days[i + 1];\n\t\t\t} else {\n\t\t\t\trs += K - days[i + 1] - days[i];\n\t\t\t\tdays[i + 1] = K - days[i];\n\t\t\t}\n\t\t}\n\t}\t\n}\n\nprint(rs);\nvar str = \"\";\nfor(var i = 0;i < days.length;i ++) {\n\tstr += days[i];\n\tif (i != days.length - 1) {\n\t\t str += \" \";\t\t\n\t}\n}\nprint(str);"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var k = line[1];\n var data = readline().split(' ').map(Number);\n for(var i=0;i input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(-1);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n for (let i = l; i < r; i++)\n mark[i] = 0;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++)\n array[i] = array[i - 1] + mark[i - 1];\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n", "positive_code": [{"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar m = input[1];\n\nvar M = [];\nfor (var i = 0; i < m; ++i) {\n M.push(readline().split(' ').map(value => +value));\n}\n\nM.sort(function(a, b) {\n if (a[1] !== b[1])\n return a[1] - b[1];\n return a[2] - b[2];\n});\n\nvar R = new Array(n + 10);\nR[1] = 9999;\nfor (var i = 1, j = 2; i < n; ++i, ++j) {\n R[j] = R[i] - 1;\n}\n\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l; j <= r; ++j) {\n R[j] = R[l];\n }\n }\n}\n\nvar f = true;\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] > R[k]) {\n f = false;\n }\n }\n } else {\n var b = false;\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] > R[k]) {\n b = true;\n }\n }\n f = f && b;\n }\n}\n\nif (f) {\n write('YES\\n');\n write(R.slice(1, n+1).join(' '));\n} else {\n write('NO\\n');\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar m = input[1];\n\nvar M = [];\nfor (var i = 0; i < m; ++i) {\n M.push(readline().split(' ').map(value => +value));\n}\n\nM.sort(function(a, b) {\n if (a[1] !== b[1])\n return a[1] - b[1];\n return a[2] - b[2];\n});\n\nvar R = new Array(n + 10);\nR[1] = 9999;\nfor (var i = 1, j = 2; i < n; ++i, ++j) {\n R[j] = R[i] - 1;\n}\n\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l; j <= r; ++j) {\n R[j] = R[l];\n }\n }\n}\n\nvar f = true;\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] > R[k]) {\n f = false;\n }\n }\n } else {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] <= R[k]) {\n f = false;\n }\n }\n }\n}\n\nif (f) {\n write('YES\\n');\n write(R.slice(1, n+1).join(' '));\n} else {\n write('NO\\n');\n}"}, {"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar m = input[1];\n\nvar M = [];\nfor (var i = 0; i < m; ++i) {\n M.push(readline().split(' ').map(value => +value));\n}\n\nM.sort(function(a, b) {\n return a[1] - b[1];\n});\n\nvar R = new Array(n + 10);\nR[1] = 9999;\nfor (var i = 1, j = 2; i < n; ++i, ++j) {\n R[j] = R[i] - 1;\n}\n\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l; j <= r; ++j) {\n R[j] = R[l];\n }\n }\n}\n\nvar f = true;\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] > R[k]) {\n f = false;\n }\n }\n } else {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] <= R[k]) {\n f = false;\n }\n }\n }\n}\n\nif (f) {\n write('YES\\n');\n write(R.slice(1, n+1).join(' '));\n} else {\n write('NO\\n');\n}"}, {"source_code": "\"use strict\";\n\n// readline().split(' ').map(value => +value);\nvar input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar m = input[1];\n\nvar M = [];\nfor (var i = 0; i < m; ++i) {\n M.push(readline().split(' ').map(value => +value));\n}\n\nvar R = new Array(n + 10);\nR[1] = 9999;\nfor (var i = 1, j = 2; i < n; ++i, ++j) {\n R[j] = R[i] - 1;\n}\n\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l; j <= r; ++j) {\n R[j] = R[l];\n }\n }\n}\n\nvar f = true;\nfor (var i = 0; i < m; ++i) {\n var t = M[i][0];\n var l = M[i][1];\n var r = M[i][2];\n \n if (t === 1) {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] > R[k]) {\n f = false;\n }\n }\n } else {\n for (var j = l, k = l+1; k <= r; ++j, ++k) {\n if (R[j] <= R[k]) {\n f = false;\n }\n }\n }\n}\n\nif (f) {\n write('YES\\n');\n write(R.slice(1, n+1).join(' '));\n} else {\n write('NO\\n');\n}"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n const getUniqueID = (() => {\n let counter = 0;\n return () => ++counter;\n })();\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueID();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n \n if (mark.every(x => x === undefined)) {\n array[0] = 2;\n for (let i = 1; i < array.length; i++)\n array[i] = 1;\n console.log(\"YES\");\n console.log(array.join(\" \"));\n return;\n }\n \n // extend the marked ranges so that all the ranges cover the array\n const getID = index => {\n if (mark[index] !== undefined) return mark[index];\n if (index < 0) return undefined;\n if (index >= mark.length) return undefined;\n return [getID(index - 1), getID(index + 1)].find(x => x !== undefined);\n };\n Object.assign(mark, mark.map((_, index) => getID(index)));\n\n const conditions = [];\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n const subarrayIDs = mark.slice(l, r + 1).filter(x => x !== undefined);\n if (subarrayIDs.length < 2) {\n console.log(\"NO\");\n return;\n }\n conditions.push(subarrayIDs);\n }\n\n const weights = Array(Math.max(...mark) + 1).fill(0);\n\n for (const binaryCondition of conditions.filter(condition => condition.length === 2)) {\n const [mark1, mark2] = binaryCondition;\n if (weights[mark1] <= weights[mark2])\n weights[mark2]--;\n }\n\n outer:\n for (const nonBinaryCondition of conditions.filter(condition => condition.length !== 2)) {\n for (let i = 1; i < nonBinaryCondition.length; i++) {\n const mark1 = nonBinaryCondition[i - 1];\n const mark2 = nonBinaryCondition[i];\n if (weights[mark1] > weights[mark2]) {\n continue outer;\n }\n }\n const mark1 = nonBinaryCondition[0];\n const mark2 = nonBinaryCondition[1];\n weights[mark2]--;\n }\n\n console.log(mark.map(x => weights[x] + n + 1).join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n\n let previousValueIsUndefined = false;\n const ranges = [];\n for (let i = 0; i < mark.length; i++) {\n if (mark[i] === undefined) {\n if (previousValueIsUndefined) {\n ranges[ranges.length - 1].push(i);\n } else {\n ranges.push([i]);\n }\n previousValueIsUndefined = true;\n }\n if (mark[i] !== undefined) {\n previousValueIsUndefined = false;\n }\n }\n\n ranges.forEach(range => {\n const fill = getUniqueNumber();\n range.forEach(index => {\n mark[index] = fill;\n });\n });\n\n const map = [...new Set(mark)].reduce((previousValue, currentValue, currentIndex, array) => {\n previousValue.set(currentValue, currentIndex);\n return previousValue;\n }, new Map());\n\n mark.map(fill => map.get(fill));\n\n let counter = 1000000001;\n const values = Array(Math.max(...mark) + 1).fill(0);\n for (let i = 1; i < values.length; i++)\n values[i] = --counter;\n\n Object.assign(array, mark.map(fill => values[fill]));\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || Math.random();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++) {\n if (mark[i] !== mark[i - 1]) {\n array[i] = array[i - 1] - 1;\n continue;\n }\n array[i] = array[i - 1];\n }\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n facts.forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = Math.max(...array.slice(l, r + 1));\n if (t == 1) {\n array.fill(fill, l, r);\n } else {\n array.fill(fill - 1, l, r);\n }\n });\n console.log(\"YES\");\n const x = -Math.min(...array) + 1;\n if (x > 0) {\n console.log(array.map(k => k + x).join(\" \"));\n } else {\n console.log(array.join(\" \"));\n }\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || Math.random();\n for (let i = l; i < r; i++)\n mark[i] = fill;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++) {\n if (mark[i] !== mark[i - 1]) {\n array[i] = array[i - 1] - 1;\n continue;\n }\n array[i] = array[i - 1];\n }\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n facts.forEach(([t, l, r]) => {\n l--;\n r--;\n if (t == 1) {\n array.fill(array[l], l, r);\n } else {\n array.fill(array[l] - 1, l, r);\n }\n });\n console.log(\"YES\");\n const x = -Math.min(...array) + 1;\n if (x > 0) {\n console.log(array.map(k => k + x).join(\" \"));\n } else {\n console.log(array.join(\" \"));\n }\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n \n const getFill = (index) => {\n if (mark[index] !== undefined) return mark[index];\n if (index < 0 || index >= mark.length) return undefined;\n return [getFill(index - 1), getFill(index + 1)].find(x => x !== undefined);\n }\n\n Object.assign(mark, mark.map((_, index) => getFill(index)));\n\n let counter = 1000000001;\n const values = Array(Math.max(...mark) + 1).fill(0);\n for (let i = 1; i < values.length; i++)\n values[i] = --counter;\n\n Object.assign(array, mark.map(fill => values[fill]));\n \n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n const getUniqueID = (() => {\n let counter = 0;\n return () => ++counter;\n })();\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueID();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n \n if (mark.every(x => x === undefined)) {\n array[0] = 2;\n for (let i = 1; i < array.length; i++)\n array[i] = 1;\n console.log(\"YES\");\n console.log(array.join(\" \"));\n return;\n }\n \n // extend the marked ranges so that all the ranges cover the array\n const getID = index => {\n if (mark[index] !== undefined) return mark[index];\n if (index < 0) return undefined;\n if (index >= mark.length) return undefined;\n return [getID(index - 1), getID(index + 1)].find(x => x !== undefined);\n };\n Object.assign(mark, mark.map((_, index) => getID(index)));\n\n const conditions = [];\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n const subarrayIDs = mark.slice(l, r + 1).filter(x => x !== undefined);\n if (subarrayIDs.length < 2) {\n console.log(\"NO\");\n return;\n }\n conditions.push(subarrayIDs);\n }\n\n const weights = Array(Math.max(...mark) + 1).fill(0);\n\n for (const binaryCondition of conditions.filter(condition => condition.length === 2)) {\n const [mark1, mark2] = binaryCondition;\n if (weights[mark1] <= weights[mark2])\n weights[mark2]--;\n }\n\n outer:\n for (const nonBinaryCondition of conditions.filter(condition => condition.length !== 2)) {\n for (let i = 1; i < nonBinaryCondition.length; i++) {\n const mark1 = nonBinaryCondition[i - 1];\n const mark2 = nonBinaryCondition[i];\n if (weights[mark1] > weights[mark2]) {\n continue outer;\n }\n }\n const mark1 = nonBinaryCondition[0];\n const mark2 = nonBinaryCondition[1];\n weights[mark2]--;\n }\n console.log(\"YES\");\n console.log(mark.map(x => weights[x] + n + 1).join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(0);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = Math.random();\n for (let i = l; i < r; i++)\n mark[i] = fill;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++) {\n if (mark[i] !== mark[i - 1]) {\n array[i] = array[i - 1] - 1;\n continue;\n }\n array[i] = array[i - 1];\n }\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n facts.forEach(([t, l, r]) => {\n l--;\n r--;\n if (t == 1) {\n array.fill(array[l], l, r);\n } else {\n array.fill(array[l] - 1, l, r);\n }\n });\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n\n let previousValueIsUndefined = false;\n const ranges = [];\n for (let i = 0; i < mark.length; i++) {\n if (mark[i] === undefined) {\n if (previousValueIsUndefined) {\n ranges[ranges.length - 1].push(i);\n } else {\n ranges.push([i]);\n }\n previousValueIsUndefined = true;\n }\n if (mark[i] !== undefined) {\n previousValueIsUndefined = false;\n }\n }\n\n ranges.forEach(range => {\n const fill = getUniqueNumber();\n range.forEach(index => {\n mark[index] = fill;\n });\n });\n\n let counter = 1000000001;\n const values = Array(Math.max(...mark) + 1).fill(0);\n for (let i = 1; i < values.length; i++)\n values[i] = --counter;\n\n Object.assign(array, mark.map(fill => values[fill]));\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++) {\n if (mark[i - 1] !== mark[i]) {\n array[i] = array[i - 1] - 1;\n continue;\n }\n array[i] = array[i - 1];\n }\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n\n let previousValueIsUndefined = false;\n const ranges = [];\n for (let i = 0; i < mark.length; i++) {\n if (mark[i] === undefined) {\n if (previousValueIsUndefined) {\n ranges[ranges.length - 1].push(i);\n } else {\n ranges.push([i]);\n }\n previousValueIsUndefined = true;\n }\n if (mark[i] !== undefined) {\n previousValueIsUndefined = false;\n }\n }\n\n ranges.forEach(range => {\n const fill = getUniqueNumber();\n range.forEach(index => {\n mark[index] = fill;\n });\n });\n\n const map = [...new Set(mark)].reduce((previousValue, currentValue, currentIndex, array) => {\n previousValue.set(currentValue, currentIndex);\n return previousValue;\n }, new Map());\n\n Object.assign(mark, mark.map(fill => map.get(fill)));\n\n let counter = 1000000001;\n const values = Array(Math.max(...mark) + 1).fill(0);\n for (let i = 1; i < values.length; i++)\n values[i] = --counter;\n\n Object.assign(array, mark.map(fill => values[fill]));\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(1);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n for (let i = l; i <= r; i++)\n mark[i] = 0;\n });\n array[0] = n;\n for (let i = 1; i < array.length; i++)\n array[i] = array[i - 1] + mark[i - 1];\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n \n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n const getUniqueID = (() => {\n let counter = 0;\n return () => ++counter;\n })();\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueID();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n \n if (mark.every(x => x === undefined)) {\n array[0] = 2;\n for (let i = 1; i < array.length; i++)\n array[i] = 1;\n console.log(\"YES\");\n console.log(array.join(\" \"));\n return;\n }\n \n // extend the marked ranges so that all the ranges cover the array\n const getID = index => {\n if (mark[index] !== undefined) return mark[index];\n if (index < 0) return undefined;\n if (index >= mark.length) return undefined;\n return [getID(index - 1), getID(index + 1)].find(x => x !== undefined);\n };\n Object.assign(mark, mark.map((_, index) => getID(index)));\n\n const conditions = [];\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n const subarrayIDs = [...new Set(mark.slice(l, r + 1).filter(x => x !== undefined))];\n if (subarrayIDs.length < 2) {\n console.log(\"NO\");\n return;\n }\n conditions.push(subarrayIDs);\n }\n\n const weights = Array(Math.max(...mark) + 1).fill(0);\n\n for (const binaryCondition of conditions.filter(condition => condition.length === 2)) {\n const [mark1, mark2] = binaryCondition;\n if (weights[mark1] <= weights[mark2])\n weights[mark2]--;\n }\n\n outer:\n for (const nonBinaryCondition of conditions.filter(condition => condition.length !== 2)) {\n for (let i = 1; i < nonBinaryCondition.length; i++) {\n const mark1 = nonBinaryCondition[i - 1];\n const mark2 = nonBinaryCondition[i];\n if (weights[mark1] > weights[mark2]) {\n continue outer;\n }\n }\n const mark1 = nonBinaryCondition[0];\n const mark2 = nonBinaryCondition[1];\n weights[mark2]--;\n }\n console.log(\"YES\");\n console.log(mark.map(x => weights[x] + n + 1).join(\" \"));\n});\n"}, {"source_code": "process.stdin.setEncoding(\"ascii\");\n\nlet input = \"\";\n\nconst getUniqueNumber = (() => {\n let counter = 0;\n return () => ++counter;\n})();\n\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n const [[n, m], ...facts] = input.trim().split(\"\\n\").map(x => x.trim().split(\" \").map(Number));\n const array = Array(n).fill(0);\n\n const mark = Array(n).fill(undefined);\n facts\n .filter(([t]) => t === 1)\n .forEach(([t, l, r]) => {\n l--;\n r--;\n const fill = mark.slice(l, r + 1).find(x => x !== undefined) || getUniqueNumber();\n for (let i = l; i <= r; i++)\n mark[i] = fill;\n });\n\n let previousValueIsUndefined = false;\n const ranges = [];\n for (let i = 0; i < mark.length; i++) {\n if (mark[i] === undefined) {\n if (previousValueIsUndefined) {\n ranges[ranges.length - 1].push(i);\n } else {\n ranges.push([i]);\n }\n previousValueIsUndefined = true;\n }\n if (mark[i] !== undefined) {\n previousValueIsUndefined = false;\n }\n }\n\n ranges.forEach(range => {\n const fill = getUniqueNumber();\n range.forEach(index => {\n mark[index] = fill;\n });\n });\n\n const map = [...new Set(mark)].reduce((previousValue, currentValue, currentIndex, array) => {\n previousValue.set(currentValue, currentIndex + 1);\n return previousValue;\n }, new Map());\n\n Object.assign(mark, mark.map(fill => map.get(fill)));\n\n let counter = 1000000001;\n const values = Array(Math.max(...mark) + 1).fill(0);\n for (let i = 1; i < values.length; i++)\n values[i] = --counter;\n\n Object.assign(array, mark.map(fill => values[fill]));\n\n const sortedNonDecreasing = array => {\n for (let i = 1; i < array.length; i++) {\n if (array[i - 1] > array[i])\n return false;\n }\n return true;\n }\n\n for (let [t, l, r] of facts.filter(([t]) => t === 0)) {\n l--;\n r--;\n if (sortedNonDecreasing(array.slice(l, r + 1))) {\n console.log(\"NO\");\n return;\n }\n }\n\n console.log(\"YES\");\n console.log(array.join(\" \"));\n});\n"}], "src_uid": "1522d9845b4ea1a903d4c81644797983"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0], m = k[1];\n var ans = n + m - 2;\n ans += Math.min(n, m);\n console.log(n == 1 && m == 1 ? 0 : ans);\n }\n}); ", "positive_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseArray = readline().split(\" \");\r\n var rows = parseInt(caseArray[0]) - 1;\r\n var columns = parseInt(caseArray[1]) - 1;\r\n if (rows > 0 || columns > 0)\r\n {\r\n var lower = Math.min(rows, columns);\r\n var higher = Math.max(rows, columns);\r\n var result = (2 * lower) + higher + 1;\r\n print(result);\r\n }\r\n else print(0);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n var n, m;\r\n for (var t=0; t < tests; t++) {\r\n var nm = readline().split(' ').map(x=>parseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n if (n == 1 && m == 1) {\r\n print(0);\r\n continue;\r\n }\r\n var ans = 0;\r\n ans += n + m - 2;\r\n ans += Math.min(n, m);\r\n print(ans);\r\n }"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n str = readline().split(' ').map(el => +el)\r\n n =str[0]\r\n m =str[1]\r\n\r\n if(n==1 && m ==1){\r\n print(0)\r\n }\r\n else{\r\n if(n>=m){\r\n print(m+m+n-2)\r\n } \r\n else{\r\n print((n-1) + m +n-1)\r\n }\r\n } \r\n\r\n}"}, {"source_code": "function convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\n\r\nconst process = require('process');\r\nconst {EOL} = require('os');\r\nconst { mainModule } = require('process');\r\n\r\nlet data = '';\r\nprocess.stdin.on('data', string=>data+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n A1715(dataLines);\r\n});\r\n\r\nconst A1715 = (input)=>{\r\n // console.debug('DEBUGGGGGASDKJLADJSLJASDLJASD', input);\r\n let result = '';\r\n const tests = Number(input[0]);\r\n for(let i=1; i<=tests; i++){\r\n const [n, m] = convertNumberArray(input[i]);\r\n // console.log(solve(n, m));\r\n process.stdout.write(solve(n, m) + '\\n');\r\n result+=solve(n, m) + '\\n'\r\n // console.debug('DEBUGGGGGASDKJLADJSLJASDLJASD', result);\r\n }\r\n return result;\r\n}\r\nfunction solve(n, m){\r\n if(n==1 && m==1) return 0;\r\n else return Math.min(n,m) + Math.min(n,m)-1 + Math.max(n,m)-1;\r\n}\r\n\r\n// module.exports = {A1715};\r\n\r\n\r\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n\r\n result = i.split('\\n').slice(1, -1)\r\n .map(l => l.split(\" \").map(t => parseInt(t)))\r\n .map(l => l[0] + l[1] - 2 + Math.min(l[0], l[1]))\r\n .map(l => (l === 1) ? 0 : l)\r\n .join('\\n')\r\n\r\n console.log(result)\r\n})\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let [n,m]=line[i].split(' ').map(x=>{return parseInt(x)});\r\n let ans=n+m-2;\r\n ans+=Math.min(n,m);\r\n if(n==1&&m==1) ans=0;\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar min = Math.min(N, M);\r\n\t\tvar max = Math.max(N, M);\r\n\t\tif(min == 1 && max == 1){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tmyout(min * 2 + max - 2);\r\n\t}\r\n}\r\n"}, {"source_code": "function solve(a, b) {\n // For she # of energy would be a - 1 + b - 1\n const herEnergy = a - 1 + b - 1;\n // For he # of energy would be min(a, b)\n const hisEnergy = a === 1 && b === 1 ? 0 : Math.min(a, b);\n return herEnergy + hisEnergy;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const lines = input.trim().split('\\n');\n for (var i = 1; i < lines.length; i++) {\n const [a, b] = lines[i].split(' ').map(Number);\n process.stdout.write(solve(a, b) + '\\n');\n }\n});\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', function(inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString.split('\\n');\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction isPossible(n, x, heights) { \n heights.sort();\n heights.sort(function(a, b) {\n return a - b;\n });\n // //console.log(heights)\n \n let front = []\n let back = []\n \n for (let i = 0; i < heights.length; i++) {\n if (i < n) {\n front.push(heights[i])\n } else {\n back.push(heights[i])\n }\n }\n \n // //console.log(front)\n // //console.log(back)\n for (let j = 0; j < front.length; j++) {\n if (back[j] - front[j] < x) {\n // //console.log(back[j] + \" \" + front[j])\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfunction calc(a, m) {\n let s = \"\";\n for (let index = 0; index < m; index++) {\n s += \"B\"\n }\n\n for (let index = 0; index < a.length; index++) {\n let ai = a[index];\n\n if (ai < (m + 1 - ai)) {\n let _s = s.replaceAt(ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } else if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n } \n }\n } else {\n let _s = s.replaceAt(m + 1 - ai - 1, \"A\");\n if (compare(_s, s) < 0) {\n s = _s;\n continue;\n } if (compare(_s, s) >= 0) {\n let __ss = s.replaceAt(ai - 1, \"A\");\n if (compare(__ss, s) < 0) {\n s = __ss;\n continue;\n }\n } \n }\n}\n\n return s;\n}\n\nfunction compare(s1, s2) {\n return s1.localeCompare(s2)\n}\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substring(0, index) + replacement + this.substring(index + replacement.length);\n}\n\n\nfunction main() {\n // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);\n\n const test_cases = parseInt(readLine().trim(), 10);\n\n for (let gItr = 0; gItr < test_cases; gItr++) {\n // const n = parseInt(readLine().trim(), 10);\n const arr = readLine().replace(/\\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));\n\n const m = arr[0]\n const n = arr[1]\n\n if (m == 1 && n == 1) console.log(0)\n else if (m == 1 || n == 1) {\n let x = m > n ? m : n;\n console.log(x)\n } else {\n let s = 0;\n if (m > n)\n s = m + (n -1)*2\n else\n s = n + (m-1)*2\n console.log(s);\n }\n\n\n \n \n \n }\n\n\n // ws.end();\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [n, m] = readline().split(' ').map(Number);\r\n if (n === 1 && m === 1) {\r\n output(0);\r\n } else if (n === 1 || m === 1) {\r\n output(Math.max(n, m));\r\n } else {\r\n let bigger = Math.max(n, m);\r\n let smaller = Math.min(n, m);\r\n output(bigger + ((smaller - 1) * 2));\r\n }\r\n }\r\n}"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const [n, m] = input[index].split(\" \").map((item) => parseInt(item));\n\n const testCase = {\n n,\n m,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m } = testCase;\n\n console.log(\n n -\n 1 +\n m -\n 1 +\n (Math.max(n - 1, m - 1) > 0 ? 1 : 0) +\n Math.min(n - 1, m - 1)\n );\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "negative_code": [{"source_code": "function convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\n\r\nconst process = require('process');\r\nconst {EOL} = require('os');\r\nconst { mainModule } = require('process');\r\n\r\nlet data = '';\r\nprocess.stdin.on('data', string=>data+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n A1715(dataLines);\r\n});\r\n\r\nconst A1715 = (input)=>{\r\n console.debug('DEBUGGGGGASDKJLADJSLJASDLJASD', input);\r\n let result = '';\r\n const tests = Number(input[0]);\r\n for(let i=1; i<=tests; i++){\r\n const [n, m] = convertNumberArray(input[i]);\r\n // console.log(solve(n, m));\r\n process.stdout.write(solve(n, m) + '\\n');\r\n result+=solve(n, m) + '\\n'\r\n console.debug('DEBUGGGGGASDKJLADJSLJASDLJASD', result);\r\n }\r\n return result;\r\n}\r\nfunction solve(n, m){\r\n if(n==1 && m==1) return 0;\r\n else return Math.min(n,m) + Math.min(n,m)-1 + Math.max(n,m)-1;\r\n}\r\n\r\n// module.exports = {A1715};\r\n\r\n\r\n"}, {"source_code": "function convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\n\r\nconst process = require('process');\r\nconst {EOL} = require('os');\r\nconst { mainModule } = require('process');\r\n\r\nlet data = '';\r\nprocess.stdin.on('data', string=>data+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n A1715(dataLines);\r\n});\r\n\r\nconst A1715 = (input)=>{\r\n console.log('DEBUGGGGGASDKJLADJSLJASDLJASD', input);\r\n let result = '';\r\n const tests = Number(input[0]);\r\n for(let i=1; i<=tests; i++){\r\n const [n, m] = convertNumberArray(input[i]);\r\n // console.log(solve(n, m));\r\n process.stdout.write(solve(n, m) + '\\n');\r\n result+=solve(n, m) + '\\n'\r\n console.log('DEBUGGGGGASDKJLADJSLJASDLJASD', result);\r\n }\r\n return result;\r\n}\r\nfunction solve(n, m){\r\n if(n==1 && m==1) return 0;\r\n else return Math.min(n,m) + Math.min(n,m)-1 + Math.max(n,m)-1;\r\n}\r\n\r\n// module.exports = {A1715};\r\n\r\n\r\n"}, {"source_code": "function convertNumberArray(str){ // ' 12 43 123 4 ' >> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\n\r\nconst process = require('process');\r\nconst {EOL} = require('os');\r\nconst { mainModule } = require('process');\r\n\r\nlet data = '';\r\nprocess.stdin.on('data', string=>data+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n A1715(dataLines);\r\n});\r\n\r\nfunction A1715(input) {\r\n const tests = Number(input[0]);\r\n for(let i=0; i> [12, 43, 123, 4]\r\n return str.replace(/ +/g, \" \").trim().split(' ').map(string => Number(string));\r\n}\r\n\r\nconst process = require('process');\r\nconst {EOL} = require('os');\r\nconst { mainModule } = require('process');\r\n\r\nlet data = '';\r\nprocess.stdin.on('data', string=>data+=string);\r\nprocess.stdin.on('end', () => {\r\n const dataLines = data.split(EOL);\r\n A1715(dataLines);\r\n});\r\n\r\nfunction A1715(input) {\r\n const tests = Number(input[0]);\r\n for(let i=0; i i += c)\r\nprocess.stdin.on('end', () => {\r\n \r\n let result = i.split('\\n').slice(1)\r\n .map(l => l.split(\" \").map(t => parseInt(t)))\r\n .map(l => l[0] + l[1] - 2 + Math.min(l[0], l[1]))\r\n .map(l => (l === 1) ? 0 : l)\r\n .join('\\n')\r\n \r\n console.log(result)\r\n})\r\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n let result = i.split('\\n').slice(1)\r\n .map(l => l.split(\" \").map(t => parseInt(t)))\r\n .map(l => l[0] + l[1] - 2 + Math.min(l[0], l[1]))\r\n .map(l => (l === 1) ? 0 : l)\r\n .reduce((l1, l2) => l1 + '' + l2, '')\r\n \r\n console.log(result)\r\n})\r\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n let result = i.split('\\n').slice(1)\r\n .map(l => l.split(\" \").map(t => parseInt(t)))\r\n .map(l => l[0] + l[1] - 2 + Math.min(l[0], l[1]))\r\n .map(l => (l === 1) ? 0 : l)\r\n .reduce((l1, l2) => l1 + '\\n' + l2, '')\r\n \r\n console.log(result)\r\n})\r\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL)\r\n\r\n let result = lines.slice(1)\r\n .map(l => l.split(\" \").map(t => parseInt(t)))\r\n .map(l => l[0] + l[1] - 2 + Math.min(l[0], l[1]))\r\n .map(l => (l === 1) ? 0 : l)\r\n \r\n console.log(result)\r\n})\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let [n,m]=line[i].split(' ').map(x=>{return parseInt(x)});\r\n let ans=n+m-2;\r\n ans+=Math.min(n,m);\r\n console.log(ans);\r\n }\r\n})"}], "src_uid": "f9287ed16ef943006ffb821ba3678545"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s2) {\r\n if (s2[s2.length - 1] !== 'B') {\r\n console.log('NO');\r\n return;\r\n }\r\n let prea = 0,\r\n preb = 0;\r\n for (let char of s2) {\r\n if (char === 'A') prea++;else preb++;\r\n if (preb > prea) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s2 = await read();\r\n solve(s2);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var s = readline().split('');\r\n var n = s.length;\r\n var cur = 0;\r\n var f = s[n - 1] === 'B';\r\n \r\n for (var j = 0; j < n; j++) {\r\n cur += s[j] == 'A' ? 1 : -1;\r\n if (cur < 0) f = false;\r\n }\r\n \r\n if (f) print('YES');\r\n else print('NO');\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const s2 = readline();\r\n let s1 = '';\r\n if (s2[0] === 'B' || s2[s2.length - 1] === 'A') {\r\n output('NO');\r\n continue;\r\n }\r\n\r\n let a = 0;\r\n let b = 0;\r\n\r\n let no = false;\r\n for (let i = 0; i < s2.length; i++) {\r\n if (s2[i] === 'A') { a++ } else { b++ };\r\n if (b>a) {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n\r\n }\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length - 1] != 'B' || x[0] != 'A')\r\n ans = 'NO'\r\n allB = 0\r\n allA = 0\r\n for(i=0; i< x.length; i++){\r\n if(x[i]==='B')\r\n allB ++\r\n else\r\n allA ++\r\n if(allB > allA){\r\n ans = 'NO'\r\n break\r\n }\r\n \r\n }\r\n\r\n print(ans)\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let i = 0; i < t; i++){\r\n const s = ls[l++];\r\n let chrz = 0;\r\n let ans = true;\r\n let hasB = false;\r\n for (let j = 0; j < s.length; j++){\r\n if (s[j] == 'A'){\r\n chrz++;\r\n }\r\n else{\r\n chrz--;\r\n hasB = true;\r\n }\r\n ans &= (chrz >= 0);\r\n }\r\n\r\n let lastB = s[s.length - 1] == 'B';\r\n console.log(ans && hasB && lastB ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}], "negative_code": [{"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length - 1] != 'B' || x[0] != 'A')\r\n ans = 'NO'\r\n allB = 0\r\n allA = 0\r\n for(i=0; i< x.length; i++){\r\n if(x[i]==='B')\r\n allB ++\r\n else\r\n allA ++\r\n }\r\n if(allB>allA)\r\n ans = 'NO'\r\n print(ans)\r\n}"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length] != 'B' || x[0] != 'A')\r\n ans = 'NO'\r\n for(i=0; i < x.length - 1; i++){\r\n if(x[i] === x[i+1] && x[i] === 'B'){\r\n ans = 'NO'\r\n break\r\n }\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length - 1] != 'B' || x[0] != 'A')\r\n ans = 'NO'\r\n for(i=0; i < x.length - 2; i++){\r\n if(x[i] === x[i+1] && x[i] === 'B'){\r\n ans = 'NO'\r\n break\r\n }\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length - 1] != 'B' || x[0] != 'A')\r\n ans = 'NO'\r\n for(i=0; i < x.length - 1; i++){\r\n if(x[i] === x[i+1] && x[i] === 'B'){\r\n ans = 'NO'\r\n break\r\n }\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile(T--){\r\n x = readline()\r\n ans = 'YES'\r\n if(x.length < 2 || x[x.length - 1] != 'B')\r\n ans = 'NO'\r\n for(i=0; i < x.length - 1; i++){\r\n if(x[i] === x[i+1] && x[i] === 'B'){\r\n ans = 'NO'\r\n break\r\n }\r\n }\r\n print(ans)\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const s2 = readline();\r\n let s1 = '';\r\n if (s2[0] === 'B') {\r\n output('NO');\r\n continue;\r\n } else if (s2 === 'A') {\r\n output('NO');\r\n continue;\r\n } else if (s2[s2.length - 1] === 'A') {\r\n output('NO');\r\n continue;\r\n }\r\n\r\n let no = false;\r\n for (let i = 1; i < s2.length; i++) {\r\n if (s2[i] === 'B' && s2[i - 1] === 'B') {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n\r\n }\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve() {\r\n let l = 0;\r\n const t = parseInt(ls[l++]);\r\n for (let i = 0; i < t; i++){\r\n const s = ls[l++];\r\n let chrz = 0;\r\n let ans = true;\r\n let hasB = false;\r\n for (let j = 0; j < s.length; j++){\r\n if (s[j] == 'A'){\r\n chrz++;\r\n }\r\n else{\r\n chrz--;\r\n hasB = true;\r\n }\r\n ans &= (chrz >= 0);\r\n }\r\n console.log(ans && hasB ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}], "src_uid": "0b9be2f076cfa13cdc76c489bf1ea416"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, k, x, y, things, g)=>{\n x--; y--;\n let p = new Array(n).fill(-1);\n\n let visited = new Array(n).fill(false);\n let q = [x];\n while (q.length > 0) {\n let newq = [];\n for (let v of q) {\n if (visited[v]) continue;\n visited[v] = true;\n for (let u of g[v]) {\n if (visited[u]) continue;\n p[u] = v;\n newq.push(u);\n }\n }\n q = newq;\n }\n\n visited = new Array(n).fill(false);\n visited[x] = true;\n\n let result = 0;\n\n if (!visited[y]) {\n let cur = y;\n let count = 0;\n while (!visited[cur]) {\n count++;\n visited[cur] = true;\n cur = p[cur];\n }\n result += count;\n }\n \n for (let thing of things) {\n thing--;\n if (visited[thing]) continue;\n\n let cur = thing;\n let count = 0;\n while (!visited[cur]) {\n count++;\n visited[cur] = true;\n cur = p[cur];\n }\n result += 2 * count;\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n readline();\n // let n = +readline();\n let [n, k] = ra();\n let [x, y] = ra();\n let things = ra();\n let g = new Array(n).fill(0).map(() => new Array());\n for (let i = 0; i < n - 1; i++) {\n let [a, b] = ra();\n g[a - 1].push(b - 1);\n g[b - 1].push(a - 1);\n }\n console.log(`${calc(n, k, x, y, things, g)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nlet stackRecursion = (fn, init_state)=>{\n let stack = [];\n let rec = (cb, a0, a1, a2)=>{\n let state = Object.assign({}, init_state);\n stack.push([state, cb, a0, a1, a2]);\n };\n return (cb, a0, a1, a2)=>{\n rec(cb, a0, a1, a2);\n while (stack.length){\n let [state, cb, a0, a1, a2] = stack[stack.length-1];\n let added = false;\n fn((cb, a0, a1, a2)=>{\n added = true;\n rec(cb, a0, a1, a2);\n }, state, a0, a1, a2);\n if (!added){\n cb(state);\n stack.pop();\n }\n }\n };\n};\n\nclass Graph {\n constructor(){\n this.g = {};\n }\n getAns(x, y, A){\n let G = this.g;\n let dfs = stackRecursion((rec, state, v, avoid1, avoid2)=>{\n let children = G[v]||[];\n if (A.has(v))\n state.itemsCollected++;\n while (state.i{\n if (childState.itemsCollected){\n state.itemsCollected += childState.itemsCollected;\n state.timeSpent += 2+childState.timeSpent;\n }\n }, to, v);\n return;\n }\n }, {i: 0, itemsCollected: 0, timeSpent: 0});\n let queue = [], qi = 0;\n queue.push([x, -1]);\n let parent = {};\n let visited = new Set([x]);\n while (qi{\n minutes += timeSpent;\n }, pathXY[i], pathXY[i-1], pathXY[i+1]);\n }\n return minutes;\n }\n add(v, u){\n if (!this.g[v])\n this.g[v] = [];\n this.g[v].push(u);\n }\n}\n \nconst calc = ()=>{\n // READING:\n readline();\n let [n, k] = ra();\n let [x, y] = ra();\n x--; y--;\n let A = new Set(readline().split(' ').map(a=>a-1));\n let G = new Graph();\n for (let i=0; i{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n\nlet wrap = (fn, init_state)=>{\n let stack = [];\n let rec = (cb, a0, a1, a2)=>{\n let state = Object.assign({}, init_state);\n stack.push([state, cb, a0, a1, a2]);\n };\n return (cb, a0, a1, a2)=>{\n rec(cb, a0, a1, a2);\n while (stack.length){\n let [state, cb, a0, a1, a2] = stack[stack.length-1];\n let added = false;\n fn((cb, a0, a1, a2)=>{\n added = true;\n rec(cb, a0, a1, a2);\n }, state, a0, a1, a2);\n if (!added){\n cb(state);\n stack.pop();\n }\n }\n };\n};\n\nclass Graph {\n constructor(){\n this.g = {};\n }\n getAns(x, y, A){\n let G = this.g;\n let dfs = wrap((rec, state, v, avoid1, avoid2)=>{\n let children = G[v]||[];\n if (A.has(v))\n state.itemsCollected++;\n while (state.i{\n if (childState.itemsCollected){\n state.itemsCollected += childState.itemsCollected;\n state.timeSpent += 2+childState.timeSpent;\n }\n }, to, v);\n }\n }, {i: 0, itemsCollected: 0, timeSpent: 0});\n let queue = [], qi = 0;\n queue.push([x, -1]);\n let parent = {};\n let visited = new Set([x]);\n while (qi{\n minutes += timeSpent;\n }, pathXY[i], pathXY[i-1], pathXY[i+1]);\n }\n return minutes;\n }\n add(v, u){\n if (!this.g[v])\n this.g[v] = [];\n this.g[v].push(u);\n }\n}\n \nconst calc = ()=>{\n // READING:\n readline();\n let [n, k] = ra();\n let [x, y] = ra();\n x--; y--;\n let A = new Set(readline().split(' ').map(a=>a-1));\n let G = new Graph();\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const [x, y] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))\n l += n - 1\n output[i] = solve(n, x, y, arr, edges)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nclass Queue {\n constructor() {\n this.map = {}\n this.first = 0\n this.last = -1\n }\n push(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[++this.last] = args[i]\n }\n }\n unshift(...args) {\n let i = 0\n if (!this.length) {\n this.first = this.last = 0\n this.map[this.first] = args[i++]\n }\n for (; i < args.length; i++) {\n this.map[--this.first] = args[i]\n }\n }\n pop() {\n const r = this.map[this.last]\n delete this.map[this.last]\n this.last--\n return r\n }\n shift() {\n const r = this.map[this.first]\n delete this.map[this.first]\n this.first++\n return r\n }\n get length() {\n if (this.first > this.last) return 0\n return this.last - this.first + 1\n }\n getLast() {\n return this.map[this.last]\n }\n}\n\nfunction solve(n, x, y, arr, edges) {\n const map = arr.reduce((o, u) => {\n o[u] = 1\n return o\n }, {})\n map[y] = 1\n// console.log(arr)\n const adj = {}\n edges.forEach(([a, b]) => {\n adj[a] = adj[a] || []\n adj[b] = adj[b] || []\n adj[a].push(b)\n adj[b].push(a)\n })\n\n return dfs(adj, x, y, map)\n}\nfunction dfs(adj, r, y, map) {\n // const stack = [[r, 0, -1]]\n const stack = new Queue()\n stack.push([r, 0, -1])\n const dp = []\n let dy\n while (stack.length) {\n const [u, i, p] = stack.getLast()// stack[stack.length - 1]\n // visited[u] = 1\n\n const nb = adj[u] || []\n if (!i) {\n // first visited\n if (u === y) dy = stack.length - 1\n }\n if (i < nb.length) {\n // stack[stack.length - 1]\n stack.getLast()[1]++\n const v = nb[i]\n // if (!visited[v]) { // has circle\n if (v !== p) {\n stack.push([v, 0, u])\n }\n } else {\n // last visited\n stack.pop()\n dp[u] = 0\n adj[u].forEach(v => {\n if (v === p) return\n if (dp[v] || map[v]) {\n dp[u] += dp[v] + 2\n }\n })\n }\n }\n// console.log(dp, dy)\n return dp[r] - dy\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n a = a.map(num => num - 1);\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const dist = [],\r\n seta = new Set(a);\r\n {\r\n const queue = [...set],\r\n st = [],\r\n p = [];\r\n for (let i of set) {\r\n seta.delete(i);\r\n dist[i] = 0;\r\n p[i] = -1;\r\n }\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j] || set.has(j)) continue;\r\n dist[j] = dist[i] + 1;\r\n p[j] = i;\r\n queue.push(j);\r\n }\r\n }\r\n {\r\n const queue = [];\r\n for (let i of seta) {\r\n res += 2 * dist[i];\r\n if (p[i] === -1) continue;\r\n queue.push(p[i]);\r\n }\r\n for (let i of queue) {\r\n if (seta.has(i)) {\r\n res -= 2 * dist[i];\r\n } else {\r\n seta.add(i);\r\n if (p[i] !== -1 && p[i] !== undefined) queue.push(p[i]);\r\n }\r\n }\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n a = a.map(num => num - 1);\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const dist = [],\r\n seta = new Set(a);\r\n {\r\n const queue = [...set].map(num => [num, 0]),\r\n st = [],\r\n p = [];\r\n for (let i of set) {\r\n seta.delete(i);\r\n dist[i] = 0;\r\n p[i] = -1;\r\n }\r\n for (let [i, dis] of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j] || set.has(j)) continue;\r\n dist[j] = dist[i] + 1;\r\n p[j] = i;\r\n queue.push([j, dist[j]]);\r\n }\r\n }\r\n {\r\n const queue = [];\r\n for (let i of seta) {\r\n queue.push(p[i]);\r\n res += 2 * dist[i];\r\n }\r\n for (let i of queue) {\r\n if (seta.has(i)) {\r\n res -= 2 * dist[i];\r\n } else if (p[i] !== -1 && p[i] !== undefined) queue.push(p[i]);\r\n }\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n a = a.map(num => num - 1);\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const dist = [],\r\n seta = new Set(a);\r\n {\r\n const queue = [...set].map(num => [num, 0]),\r\n st = [],\r\n p = [];\r\n for (let i of set) {\r\n seta.delete(i);\r\n dist[i] = 0;\r\n p[i] = -1;\r\n }\r\n for (let [i, dis] of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j] || set.has(j)) continue;\r\n dist[j] = dist[i] + 1;\r\n p[j] = i;\r\n queue.push([j, dist[j]]);\r\n }\r\n }\r\n {\r\n const queue = [];\r\n for (let i of seta) {\r\n queue.push(p[i]);\r\n res += 2 * dist[i];\r\n }\r\n for (let i of queue) {\r\n if (seta.has(i)) {\r\n res -= 2 * dist[i];\r\n }\r\n if (p[i] !== -1 && p[i] !== undefined) queue.push(p[i]);\r\n }\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n a = a.map(num => num - 1);\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const seta = new Set(a);\r\n {\r\n const st = [];\r\n const dfs = i => {\r\n st[i] = 1;\r\n let res = 0;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n res += dfs(j);\r\n }\r\n if (!set.has(i)) {\r\n if (res === 0 && seta.has(i)) return 1;\r\n if (res > 0) return res + 1;\r\n }\r\n return res;\r\n };\r\n res += dfs(x) * 2;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const dist = [],\r\n seta = new Set(a.map(num => num - 1));\r\n {\r\n const queue = [...set].map(num => [num, 0]),\r\n st = [],\r\n p = [];\r\n for (let i of set) {\r\n seta.delete(i);\r\n dist[i] = 0;\r\n p[i] = -1;\r\n }\r\n for (let [i, dis] of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j] || set.has(j)) continue;\r\n dist[j] = dist[i] + 1;\r\n p[j] = i;\r\n queue.push([j, dist[j]]);\r\n }\r\n }\r\n {\r\n const queue = [];\r\n for (let i of seta) {\r\n queue.push(p[i]);\r\n }\r\n for (let i of queue) {\r\n seta.delete(i);\r\n if (p[i] !== -1 && p[i] !== undefined) queue.push(p[i]);\r\n }\r\n }\r\n }\r\n for (let i of seta) {\r\n res += dist[i] * 2;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, k, x, y, a, b) {\r\n x--;\r\n y--;\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [u, v] of b) {\r\n g[u].push(v);\r\n g[v].push(u);\r\n }\r\n const p = [];\r\n let res = 0;\r\n {\r\n const queue = [x],\r\n st = [];\r\n p[x] = -1;\r\n for (let i of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j]) continue;\r\n queue.push(j);\r\n p[j] = i;\r\n }\r\n }\r\n }\r\n const set = new Set();\r\n set.add(x);\r\n set.add(y);\r\n {\r\n const queue = [y];\r\n for (let i of queue) {\r\n set.add(i);\r\n if (p[i] !== -1) {\r\n res++;\r\n queue.push(p[i]);\r\n }\r\n }\r\n }\r\n const dist = [];\r\n {\r\n const queue = [...set].map(num => [num, 0]),\r\n st = [];\r\n for (let i of set) {\r\n dist[i] = 0;\r\n }\r\n for (let [i, dis] of queue) {\r\n if (st[i]) continue;\r\n st[i] = 1;\r\n for (let j of g[i]) {\r\n if (st[j] || set.has(j)) continue;\r\n dist[j] = dist[i] + 1;\r\n }\r\n }\r\n }\r\n for (let i of [...new Set(a)].map(num => num - 1)) {\r\n res += dist[i] * 2;\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, k] = (await read()).split(' ').map(Number);\r\n const [x, y] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = n - 1;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').filter(str => str !== '').map(s => Number(s) - 1));\r\n }\r\n solve(n, k, x, y, a, b);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "src_uid": "a688369a2b95a8e32d00541d54f3bec6"} {"source_code": "var readInt = (keys) => {\n var val = readline().split(' ');\n var key = keys.split(', ');\n for (var i = 0; i < key.length; ++i) {\n this[key[i]] = parseInt(val[i]);\n }\n};\nArray.prototype.init = function (val) {\n var foo = typeof val === 'function' ? val : () => val;\n for (var i = this.length; i--; ) {\n this[i] = foo();\n }\n return this;\n};\n\nreadInt('N, onTree, offTree');\nvar edge = new Array(N+1).init(() => []);\nfor (var i = N-1; i--; ) {\n readInt('u, v');\n edge[u].push(v);\n edge[v].push(u);\n}\nif (onTree >= offTree) {\n var star = false;\n edge.forEach(arr => star = star || arr.length === N-1);\n print(star ? (N-2) * offTree + onTree : (N-1) * offTree);\n} else {\n var father = new Array(N+1).init(0);\n var avail = new Array(N+1).init(2);\n father[1] = null;\n var sa = [1], sb = [], me;\n var bind = (son) => {\n if (father[son] === 0) {\n father[son] = me;\n sa.push(son);\n }\n }\n while (me = sa.pop()) {\n sb.push(me);\n edge[me].forEach(bind);\n }\n var cnt = 0;\n while (me = sb.pop()) {\n if (avail[me] && avail[father[me]]) {\n avail[me]--; avail[father[me]]--;\n cnt++;\n }\n }\n print(cnt * onTree + (N-1-cnt) * offTree);\n}\n", "positive_code": [{"source_code": "var temp = readline().split(' ');\nvar N = parseInt(temp[0]);\nvar onTree = parseInt(temp[1]);\nvar offTree = parseInt(temp[2]);\nvar edge = [];\nfor (var i = N+1; i--; ) edge.push([]);\nvar u, v;\nfor (var i = N-1; i--; ) {\n temp = readline().split(' ');\n u = parseInt(temp[0]);\n v = parseInt(temp[1]);\n edge[u].push(v);\n edge[v].push(u);\n}\nif (onTree >= offTree) {\n var star = false;\n for (var i = N; i--; ) {\n if (edge[N-i].length === N-1) {\n star = true;\n break;\n }\n }\n print(star ? (N-2) * offTree + onTree : (N-1) * offTree);\n} else {\n var father = [], avail = [];\n for (var i = N+1; i--; ) {\n father.push(0);\n avail.push(2);\n }\n father[1] = null;\n var stack = [1], stac2 = [], cnt = 0;\n var node, e;\n while (node = stack.pop()) {\n stac2.push(node);\n e = edge[node];\n tail = true;\n for (var i = e.length; i--; ) {\n if (father[e[i]] === 0) {\n father[e[i]] = node;\n stack.push(e[i]);\n tail = true;\n }\n }\n }\n while (node = stac2.pop()) {\n if (avail[node] && avail[father[node]]) {\n avail[node]--;\n avail[father[node]]--;\n cnt++;\n }\n }\n print(cnt * onTree + (N-1-cnt) * offTree);\n}\n"}], "negative_code": [{"source_code": "var readInt = (keys) => {\n var val = readline().split(' ');\n var key = keys.split(', ');\n for (var i = 0; i < key.length; ++i) {\n this[key[i]] = parseInt(val[i]);\n }\n};\nArray.prototype.init = function (val) {\n var foo = typeof val === 'function' ? val : () => val;\n for (var i = this.length; i--; ) {\n this[i] = foo();\n }\n return this;\n};\nreadInt('N, onTree, offTree');\nvar edge = new Array(N+1).init(() => []);\nfor (var i = N-1; i--; ) {\n readInt('u, v');\n edge[u].push(v);\n edge[v].push(u);\n}\nif (onTree >= offTree) {\n var star; edge.forEach(arr => star = arr.length === N-1);\n print(star ? (N-2) * offTree + onTree : (N-1) * offTree);\n} else {\n var father = new Array(N+1).init(0);\n var avail = new Array(N+1).init(2);\n father[1] = null;\n var sa = [1], sb = [], me;\n var bind = (son) => {\n if (father[son] === 0) {\n father[son] = me;\n sa.push(son);\n }\n }\n while (me = sa.pop()) {\n sb.push(me);\n edge[me].forEach(bind);\n }\n var cnt = 0;\n while (me = sb.pop()) {\n if (avail[me] && avail[father[me]]) {\n avail[me]--; avail[father[me]]--;\n cnt++;\n }\n }\n print(cnt * onTree + (N-1-cnt) * offTree);\n}\n"}, {"source_code": "var temp = readline().split(' ');\nvar N = parseInt(temp[0]);\nvar onTree = parseInt(temp[1]);\nvar offTree = parseInt(temp[2]);\nvar edge = [];\nfor (var i = N+1; i--; ) edge.push([]);\nvar u, v;\nfor (var i = N-1; i--; ) {\n temp = readline().split(' ');\n u = parseInt(temp[0]);\n v = parseInt(temp[1]);\n edge[u].push(v);\n edge[v].push(u);\n}\nif (onTree >= offTree) {\n var star = false;\n for (var i = N; i--; ) {\n if (edge[N-i].length === N-1) {\n star = true;\n break;\n }\n }\n print(star ? (N-2) * offTree + onTree : (N-1) * offTree);\n} else {\n var father = [], avail = [];\n for (var i = N+1; i--; ) {\n father.push(0);\n avail.push(2);\n }\n father[1] = null;\n var stack = [1], stac2 = [], cnt = 0;\n var node, e;\n while (node = stack.pop()) {\n stac2.push(node);\n e = edge[node];\n tail = true;\n for (var i = e.length; i--; ) {\n if (father[e[i]] === 0) {\n father[e[i]] = node;\n stack.push(e[i]);\n tail = true;\n }\n }\n }\n while (node = stac2.pop()) {\n if (avail[node] && father[node]) {\n avail[node]--;\n avail[father[node]]--;\n cnt++;\n }\n }\n print(cnt * onTree + (N-1-cnt) * offTree);\n}\n"}, {"source_code": "var temp = readline().split(' ');\nvar N = parseInt(temp[0]);\nvar onTree = parseInt(temp[1]);\nvar offTree = parseInt(temp[2]);\nvar edge = [];\nfor (var i = N+1; i--; ) edge.push([]);\nvar u, v;\nfor (var i = N-1; i--; ) {\n temp = readline().split(' ');\n u = parseInt(temp[0]);\n v = parseInt(temp[1]);\n edge[u].push(v);\n edge[v].push(u);\n}\nvar dia = (() => {\n var farthestFrom = (src) => {\n var dis = [];\n for (var i = N+1; i--; ) dis.push(Infinity);\n dis[src] = 0;\n var queue = [src], l = 0;\n queue.pop = () => queue[l++];\n var u, ue, max = 0, maxu = src;\n while (u = queue.pop()) {\n if (dis[u] > max) {\n max = dis[u];\n maxu = u;\n }\n ue = edge[u];\n for (var i = ue.length; i--; ) {\n if (dis[ue[i]] === Infinity) {\n dis[ue[i]] = dis[u] + 1;\n queue.push(ue[i]);\n }\n }\n }\n return {\n dis: max,\n id: maxu\n };\n };\n var memo;\n return () => {\n if (typeof memo !== 'undefined') return memo;\n var u = farthestFrom(1);\n var v = farthestFrom(u.id);\n return memo = v.dis;\n };\n})();\nif (onTree >= offTree) {\n var centre = false;\n for (var i = N; i--; ) {\n if (edge[N-i].length === N-1) {\n centre = true;\n break;\n }\n }\n print(centre ? (N-2) * offTree + onTree : (N-1) * offTree);\n} else {\n print(dia() * onTree + (N-1-dia()) * offTree);\n}\n"}], "src_uid": "f010eebcf35357f8c791a1c6101189ba"} {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar n = parseInt(readline());\nvar m = [];\n\nfor (var i = 0; i < n; i++) {\n var line = readline().getNumArray();\n m.push(line);\n}\n\nvar x1 = Math.sqrt(m[0][1] * m[1][2] / m[0][2]);\nvar answ = [];\n\nfor (var _i = 0; _i < n; _i++) {\n if (_i == 1) {\n answ.push(x1);\n } else {\n answ.push(m[_i][1] / x1);\n }\n}\n\nwrite(answ.join(' '));", "positive_code": [{"source_code": "'use strict'\n \nconst size = parseInt(readline());\nconst M0 = readline().split(' ').map(Number);\nconst M1 = readline().split(' ').map(Number);\n \nconst a0 = Math.sqrt(M0[1] * M0[2] / M1[2]);\nwrite(a0 + ' ' + M0.slice(1).map(i => i / a0).join(' '));"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\"\nprocess.stdin.on('data', function(chunk) {\n arr += chunk\n});\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const number = parseInt(arr.shift())\n const firstRow = arr[0].split(' ')\n const secondRow = arr[1].split(' ')\n const a1 = Math.sqrt(firstRow[1] * firstRow[2] / secondRow[2])\n\n process.stdout.write(a1 + ' ')\n \n for(let i = 1; i < number; i ++){\n process.stdout.write(`${firstRow[i] / a1} `)\n }\n console.log()\n})"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, num, multiArr = [];\nrl.on('line', function (line) {\n if (lineCount === 0) {\n num = Number(line.trim());\n } else {\n multiArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === num) {\n console.log(getTable(multiArr));\n rl.close();\n }\n lineCount++;\n});\n\nfunction getTable(multiArr) {\n let len = multiArr.length;\n let resArr = [];\n for (let i = 0; i < len; i++) {\n resArr.push(getMain(i, len));\n }\n return resArr.join(' ');\n}\n\nfunction getMain(i, len) {\n let j, k;\n if (i === 0) {\n j = i + 1, k = i + 2;\n } else if (i === len - 1) {\n j = i - 1, k = i - 2;\n } else {\n j = i - 1; k = i + 1;\n }\n let Mij = multiArr[i][j];\n let Mik = multiArr[i][k];\n let Mjk = multiArr[j][k];\n return Math.sqrt((Mij * Mik) / Mjk);\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, num, multiArr = [];\nrl.on('line', function (line) {\n if (lineCount === 0) {\n num = Number(line.trim());\n } else {\n multiArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === num) {\n console.log(getTable(multiArr));\n rl.close();\n }\n lineCount++;\n});\n\nfunction getTable(multiArr) {\n let len = multiArr.length;\n let resArr = [];\n\n function getMain(i) {\n let j, k;\n if (i === 0) {\n j = i + 1, k = i + 2;\n } else if (i === len - 1) {\n j = i - 1, k = i - 2;\n } else {\n j = i - 1; k = i + 1;\n }\n let Mij = multiArr[i][j];\n let Mik = multiArr[i][k];\n let Mjk = multiArr[j][k];\n return Math.sqrt((Mij * Mik) / Mjk)\n }\n\n for (let i = 0; i < len; i++) {\n resArr.push(getMain(i));\n }\n return resArr.join(' ')\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst size = parseInt(readline());\nconst M0 = readline().split(' ').map(Number);\nconst M1 = readline().split(' ').map(Number);\n\nconst a0 = Math.sqrt(M0[1] * M0[2] / M1[2]);\nwrite(a0 + M0.slice(1).map(i => i / a0));"}], "src_uid": "ced70b400694fa16929d4b0bce3da294"} {"source_code": "function doIt() {\n var fl = readline().split(' ').map(v=>+v);\n var columnsCount = fl[0];\n var height = fl[1];\n\n var sum = 0, max = 0;\n var map = {};\n var all = readline().split(' ');\n all.forEach(v => {\n if(v in map) {\n map[v] ++;\n } else {\n map[v] = 1;\n }\n if(v > max) max = v;\n });\n\n var prev = 0, balance = 0;\n Object.keys(map).forEach((v) => {\n sum+=map[v] * v;\n balance += v - prev - map[v];\n if(balance < 0) balance = 0;\n\n prev = v;\n });\n\n var remove = sum - balance - all.length;\n\n print(remove);\n}\n\ndoIt();", "positive_code": [{"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction solve(){\n const [n, m] = readInts();\n let maxx = 0;\n // var list = readInts();\n var list = readline().split(' ').map(e=>+e);\n var minn;\n it(list);\n list.sort((a,b)=>a-b);\n it(list);\n it(list);\n maxx = list[list.length-1];\n minn = list[0];\n //1~maxx\uae4c\uc9c0 \uc62c\ub77c\uac00\uba74\uc11c, \ube44\ub294 \uacbd\uc6b0\ub9cc\uc774 omit\uc774\ub2e4. 333 \uc774\ub7f0\uacbd\uc6b0\ub294 \ub610 omit\uc774 \uc544\ub2c8\ub2e4.\n // \uadf8\ub807\ub2e4\uba74 333\uc740 \uacb0\uad6d 123\uc73c\ub85c \ubcfc \uc218 \uc788\ub2e4\ub294 \uac83.\n // \uadfc\ub370 \ubc18\ub300\ub85c \ubcf4\ub294\uac8c \ub9de\uaca0\ub2e4. 444\ub294 432\ub2e4.\n // 99955222 -> 98754222\n var newlist = [];\n var last = maxx;\n\n var needed = 0;\n for(var i=n-1;i >= 0; i--){\n newlist[i] = last;\n last = Math.max(0, Math.min(last-1,list[i-1]));\n }\n it('nl ' + newlist);\n last = 0;\n for(var i=0; i{\n return a+b;\n })\n print(sums- needed);\n // print(sums - (n + omit + minn - 1));\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}], "negative_code": [{"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction solve(){\n const [n, m] = readInts();\n let maxx = 0;\n var list = readInts();\n var minn;\n it(list);\n list.sort();\n it(list);\n maxx = list[list.length-1];\n minn = list[0];\n //1~maxx\uae4c\uc9c0 \uc62c\ub77c\uac00\uba74\uc11c, \ube44\ub294 \uacbd\uc6b0\ub9cc\uc774 omit\uc774\ub2e4. 333 \uc774\ub7f0\uacbd\uc6b0\ub294 \ub610 omit\uc774 \uc544\ub2c8\ub2e4.\n // \uadf8\ub807\ub2e4\uba74 333\uc740 \uacb0\uad6d 123\uc73c\ub85c \ubcfc \uc218 \uc788\ub2e4\ub294 \uac83.\n // \uadfc\ub370 \ubc18\ub300\ub85c \ubcf4\ub294\uac8c \ub9de\uaca0\ub2e4. 444\ub294 432\ub2e4.\n // \n var newlist = [];\n var last = maxx;\n\n var needed = 0;\n for(var i=n-1;i >= 0; i--){\n newlist[i] = last;\n last = Math.max(0, Math.min(last-1,list[i-1]));\n }\n it('nl ' + newlist);\n last = 0;\n for(var i=0; i{\n return a+b;\n })\n print(sums- needed);\n // print(sums - (n + omit + minn - 1));\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}, {"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction solve(){\n const [n, m] = readInts();\n let maxx = 0;\n var list = readInts();\n\n it(list);\n list.sort();\n it(list);\n maxx = list[list.length - 1];\n //1~maxx\uae4c\uc9c0 \uc62c\ub77c\uac00\uba74\uc11c, \ube44\ub294 \uacbd\uc6b0\ub9cc\uc774 omit\uc774\ub2e4. 333 \uc774\ub7f0\uacbd\uc6b0\ub294 \ub610 omit\uc774 \uc544\ub2c8\ub2e4.\n // \uadf8\ub807\ub2e4\uba74 333\uc740 \uacb0\uad6d 123\uc73c\ub85c \ubcfc \uc218 \uc788\ub2e4\ub294 \uac83.\n var checked = [];\n var checked2 = [];\n var omittedRightViews = [];\n var omit = 0;\n for(var i=1;i<=maxx;i++){\n it(list[i-1], i);\n if(list[i-1] < i || list[i-1] == undefined)\n omit++;\n }\n // it(omittedRightViews);\n var sums = list.reduce((a,b)=>{\n return a+b;\n })\n it(sums)\n it(omit);\n print(sums - (n + omit));\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}, {"source_code": "// NYAN NYAN\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2591\u2584\u2584\u2584\u2591\u2591\u2591\n// \u2591\u2584\u2584\u2584\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2580\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2588\u2588\u2584\u2580\u2588\u2588\u2584\u2588\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\n// \u2591\u2591\u2580\u2588\u2588\u2584\u2580\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2591\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2588\u2591\u2580\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2584\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2584\u2588\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2584\u2591\u2591\u2584\u2591\u2591\u2591\u2588\u2588\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2588\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2591\u2591\u2584\u2580\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2588\u2588\u2588\u2591\u2591\u2580\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2591\u2591\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\n// \ubc31\uc900\uc758 \ub178\ub4dc \ubc84\uc804\uc774 \ub108\ubb34 \ub0ae\uc544 babel \uc0ac\uc6a9. \n// \ud480\uc774\ub294 solve() \ud568\uc218\uc5d0 \uc788\uc74c.\n\nconst CODEFORCES_NODE = \"cf\";\nconst CODEFORCES_V8 = \"cf-v8\";\nconst BEAKJOON = \"bj\";\nconst TEST = \"test\";\n// var SITE = BEAKJOON;\nvar SITE = CODEFORCES_NODE;\nvar DEBUG = false; \n\nif(SITE == BEAKJOON){\n if (!String.prototype.startsWith) {\n String.prototype.startsWith = function(search, pos) {\n return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;\n };\n }\n if (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n }\n if (!String.prototype.repeat) {\n String.prototype.repeat = function(count) {\n 'use strict';\n if (this == null) {\n throw new TypeError('can\\'t convert ' + this + ' to object');\n }\n var str = '' + this;\n count = +count;\n if (count != count) {\n count = 0;\n }\n if (count < 0) {\n throw new RangeError('repeat count must be non-negative');\n }\n if (count == Infinity) {\n throw new RangeError('repeat count must be less than infinity');\n }\n count = Math.floor(count);\n if (str.length == 0 || count == 0) {\n return '';\n }\n // Ensuring count is a 31-bit integer allows us to heavily optimize the\n // main part. But anyway, most current (August 2014) browsers can't handle\n // strings 1 << 28 chars or longer, so:\n if (str.length * count >= 1 << 28) {\n throw new RangeError('repeat count must not overflow maximum string size');\n }\n var maxCount = str.length * count;\n count = Math.floor(Math.log(count) / Math.log(2));\n while (count) {\n str += str;\n count--;\n }\n str += str.substring(0, maxCount - str.length);\n return str;\n }\n }\n}\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nFunction.prototype.repeat = function(times){\n for(let i = 0; i < times; i++){\n this();\n }\n}\n\nArray.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){\n const N = this.length;\n let maxsum = defaultValue;\n let cursum = defaultValue;\n let cur;\n for(var ii = 0; ii < N; ii++){\n cur = this[ii];\n if(cursum + cur > 0){\n if(cur > cursum + cur){\n cursum = cur;\n } else cursum += cur;\n } else {\n cursum = cur;\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n if(maxsum < cursum){\n maxsum = cursum;\n }\n }\n this.maxConsecutiveSum = maxsum;\n return maxsum;\n}\n\ntry {\n require('manakin').global;\n // require (\"babel-polyfill\");\n} catch (error) {\n\n}\ntry {\n process.argv.forEach(function (val, index, array) {\n if (val.startsWith(\"site\")) {\n switch (val.split(\"=\")[1]) {\n case \"test\":\n // console.log('change site to test')\n SITE = TEST;\n break;\n case \"cf-node\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf\":\n // console.log('change site to cf')\n SITE = CODEFORCES_NODE;\n break;\n case \"cf-v8\":\n // console.log('change site to cf')\n SITE = CODEFORCES_V8;\n break;\n case \"bj\":\n // console.log('change site to bj')\n SITE = BEAKJOON;\n break;\n }\n }\n if (val.startsWith(\"debug\")) {\n switch (val.split(\"=\")[1]) {\n case \"true\":\n DEBUG = true;\n break;\n case \"false\":\n DEBUG = false;\n break;\n }\n }\n });\n} catch (error) {\n}\n\nlet inputFilePath = '';\nswitch(SITE){\n case TEST:\n const config = require('config');\n var fs = require(\"fs\");\n var path = require('path');\n inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, \"input.txt\");\n break;\n default:\n inputFilePath = './input.txt';\n break;\n}\nconst INPUTFILEPATH = inputFilePath;\n\n// if (!String.prototype.endsWith) {\n// \tString.prototype.endsWith = function(search, this_len) {\n// \t\tif (this_len === undefined || this_len > this.length) {\n// \t\t\tthis_len = this.length;\n// \t\t}\n// \t\treturn this.substring(this_len - search.length, this_len) === search;\n// \t};\n// }\n// if (!Array.prototype.includes) {\n// Array.prototype.includes = function (target) {\n// return this.indexOf(target) !== -1\n// }\n// }\n\nconst newLine = '\\n';\nvar ans;\nvar inputText = \"\";\nvar lineCount = 0;\nvar lines;\nvar input;\nvar readline;\nvar getlines;\nvar lineOpen = false;\nvar readingLine = '';\n\nvar clockStart;\nvar clock;\n\nvar print;\nprint = console.log;\nvar it;\nvar step;\nfunction EnableLogging(){\n it = console.info;\n step = console.success;\n}\nfunction DisableLogging(){\n it = function it(params) {\n return 0;\n }\n step = it;\n}\nif (DEBUG) {\n EnableLogging();\n clock = function(start) {\n if ( !start ) return process.hrtime();\n var end = process.hrtime(start);\n return Math.round((end[0]*1000) + (end[1]/1000000));\n }\n} else {\n DisableLogging();\n}\n\n// prepares test data. to replace line input, assign arrays to lines variable.\nfunction prepareTestData() {\n // it(lines);\n\n // lines = ['custom line 1', 'custom line 2'];\n}\n\n// executes exactly once for both test and run. execution time will be included to elapsed time. \nconst prepareSolve = () => {\n \n}\n\nfunction power(x, y) { //\ubd84\ud560 \uc815\ubcf5\uc744 \uc774\uc6a9\ud558\uc5ec x^y \uad6c\ud558\uae30\n let ret = 1;\n while (y > 0) {\n if (y % 2) {\n ret *= x;\n ret %= P;\n }\n x *= x;\n x %= P;\n y /= 2;\n }\n return ret;\n}\n\nfunction createArray(lengths) {\n var arr = new Array(lengths || 0),\n i = lengths;\n if (arguments.length > 1) {\n var args = Array.prototype.slice.call(arguments, 1);\n while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);\n }\n return arr;\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 MAIN SOLVE FUNCTION \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction solve(){\n const [n, m] = readInts();\n let maxx = 0;\n var list = readInts();\n var minn;\n it(list);\n list.sort();\n it(list);\n maxx = list[list.length-1];\n minn = list[0];\n //1~maxx\uae4c\uc9c0 \uc62c\ub77c\uac00\uba74\uc11c, \ube44\ub294 \uacbd\uc6b0\ub9cc\uc774 omit\uc774\ub2e4. 333 \uc774\ub7f0\uacbd\uc6b0\ub294 \ub610 omit\uc774 \uc544\ub2c8\ub2e4.\n // \uadf8\ub807\ub2e4\uba74 333\uc740 \uacb0\uad6d 123\uc73c\ub85c \ubcfc \uc218 \uc788\ub2e4\ub294 \uac83.\n // \uadfc\ub370 \ubc18\ub300\ub85c \ubcf4\ub294\uac8c \ub9de\uaca0\ub2e4. 444\ub294 432\ub2e4.\n // \n var newlist = [];\n var last = maxx;\n\n var needed = 0;\n for(var i=n-1;i >= 0; i--){\n newlist[i] = last;\n last = Math.max(0, Math.min(last-1,list[i-1]));\n }\n it('nl ' + newlist);\n last = 0;\n for(var i=0; i{\n return a+b;\n })\n it(sums- needed);\n // print(sums - (n + omit + minn - 1));\n}\n\n// \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n\nfunction resetRead(){\n lineCount = 0;\n}\n\nfunction checkMemoryUsage() {\n it(process.memoryUsage());\n}\n\nfunction readOne(separator=' ') {\n if(lineOpen && readingLine != null){\n // if(lineOpen){\n // it(readingLine);\n let splitPos = readingLine.search(separator)\n \n let ret = readingLine.slice(0, splitPos);\n if(splitPos == -1){\n // it('close');\n ret = readingLine;\n readingLine = '';\n lineOpen = false;\n }\n readingLine = readingLine.substr(splitPos + 1)\n // it(ret, readingLine, splitPos);\n return ret;\n } else {\n readingLine = readline();\n lineOpen = true;\n if(readingLine == null) return '';\n return readOne(separator);\n }\n}\n\nfunction readInts() {\n try {\n lineOpen = false;\n return readline()\n .split(\" \")\n .map(x => parseInt(x));\n } catch (error) {\n console.error(error);\n return null;\n }\n}\n\nswitch (SITE) {\n case TEST:\n var fs = require(\"fs\");\n var path = require('path');\n // input = fs.createReadStream(path.resolve(__dirname, \"input.txt\"), {\n // encoding: \"utf8\"\n // });\n input = fs.createReadStream(INPUTFILEPATH, {\n encoding: \"utf8\"\n });\n\n function inputListener(line) {\n console.log(line);\n if(line.startsWith('end')){\n console.log('end');\n closing();\n }\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n\n case CODEFORCES_NODE:\n input = process.stdin;\n\n function inputListener(line) {\n if (!line) {\n closing();\n }\n lineCount++;\n inputText += line + \"\\r\\n\";\n }\n\n function readlines() {\n const readline = require(\"readline\");\n const rl = readline.createInterface({\n input,\n output: process.stdout,\n terminal: false\n });\n rl.on(\"line\", inputListener);\n rl.on('close', closing);\n }\n\n getlines = function* (inputText) {\n var lines = inputText.split(/\\r?\\n/);\n for (let line of lines) {\n yield line + newLine;\n }\n }\n\n readline = function () {\n return lines.next().value.trim();\n }\n\n readlines();\n\n break;\n case BEAKJOON:\n var fs = require('fs');\n if (DEBUG) {\n // input = fs.readFileSync('./input.txt').toString();\n inputText = fs.readFileSync(INPUTFILEPATH).toString();\n \n } else {\n inputText = fs.readFileSync('/dev/stdin').toString();\n }\n\n readline = function () {\n lineCount++;\n let line = lines[lineCount - 1];\n if (line)\n return lines[lineCount - 1].trim();\n else return null;\n }\n\n getlines = function (inputText) {\n lineCount = 0;\n return inputText.split(/\\r?\\n/);\n }\n\n // lines = getlines(input);\n closing();\n break;\n default:\n break;\n}\n\nfunction closing() {\n if(DEBUG){\n DisableLogging();\n const prepareClock = clock();\n lines = getlines(inputText);\n prepareSolve();\n const prepareClockElapsedTime = clock(prepareClock);\n EnableLogging();\n prepareTestData();\n solve();\n resetRead();\n console.warn('performance check');\n DisableLogging();\n clockStart = clock();\n // lines = getlines(inputText);\n solve();\n console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);\n EnableLogging();\n process.exit();\n } else {\n lines = getlines(inputText);\n prepareSolve();\n solve();\n process.exit();\n }\n}"}], "src_uid": "ffa76f2558c8a70ab5c1ecb9e8561f25"} {"source_code": "var parseIntFunc = function(x) { return parseInt(x); };\nvar numbers = readline().split(\" \").map(parseIntFunc);\nvar n = numbers[0];\nvar k = numbers[1];\nvar q = numbers[2];\n\nvar friends = readline().split(\" \").map(parseIntFunc);\nvar friendsOnlineSorted = [];\nvar friendsOnline = [];\n\nvar binarySearch = function (searchElement) {\n\tvar minIndex = 0;\n\tvar maxIndex = this.length - 1;\n\tvar currentIndex;\n\tvar currentElement;\n\twhile (minIndex <= maxIndex) {\n\t\tcurrentIndex = (minIndex + maxIndex) / 2 | 0;\n\t\tcurrentElement = this[currentIndex];\n\n\t\tif (currentElement > searchElement) {\n\t\t\tminIndex = currentIndex + 1;\n\t\t}\n\t\telse if (currentElement < searchElement) {\n\t\t\tmaxIndex = currentIndex - 1;\n\t\t}\n\t\telse {\n\t\t\treturn currentIndex;\n\t\t}\n\t}\n\treturn minIndex;\n};\n\nfor (var i = 0; i < q; i++){\n var query = readline().split(\" \").map(parseIntFunc);\n var friend = query[1] - 1;\n var friendValue = friends[friend];\n var queryType = query[0];\n if (queryType === 2){\n if (friendsOnline[friend]){\n if (binarySearch.call(friendsOnlineSorted, friendValue) < k){\n print('YES');\n } else {\n print('NO');\n }\n } else {\n print('NO');\n }\n } else {\n friendsOnlineSorted.splice(binarySearch.call(friendsOnlineSorted, friendValue),0,friendValue);\n friendsOnline[friend] = 1;\n }\n}\n\n", "positive_code": [{"source_code": "var line1 = readline().split(' ').map(Number);\nvar n = line1[0];\nvar k = line1[1];\nvar q = line1[2];\n\nvar t = readline().split(' ').map(Number);\n\nvar requests = [];\n\nvar buffer = [];\n\nfor(var i = 0; i < q; i++){\n var req = readline().split(' ').map(Number);\n if(req[0] === 1){\n // Add friend to the buffer\n var ti = t[req[1] - 1];\n var inserted = false;\n for(var j = 0; j < buffer.length; j++){\n if(buffer[j].t < ti){\n buffer.splice(j, 0, {id: req[1], t: ti});\n inserted = true;\n break;\n }\n }\n\n if(inserted === false){\n buffer.splice(j, 0, {id: req[1], t: ti});\n }\n\n if(buffer.length > k){\n buffer = buffer.slice(0, k);\n }\n }\n if(req[0] === 2){\n // Validate if Online\n var found = false;\n for(var u = 0; u < Math.min(k, buffer.length); u++){\n if(buffer[u].id === req[1]){\n found = true;\n break;\n }\n }\n\n if(found === true){\n print(\"YES\");\n } else {\n print(\"NO\");\n }\n }\n}\n\n\n\n/*\n4 2 8\\n300 950 500 200\\n1 3\\n2 4\\n2 3\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n\n*/\n"}], "negative_code": [{"source_code": "var parseIntFunc = function(x) { return parseInt(x); };\nvar numbers = readline().split(\" \").map(parseIntFunc);\nvar n = numbers[0];\nvar k = numbers[1];\nvar q = numbers[2];\n\nvar friends = readline().split(\" \").map(parseIntFunc);\nvar friendsOnlineSorted = [];\nvar friendsOnline = [];\n\nvar binarySearch = function (searchElement) {\n\tvar minIndex = 0;\n\tvar maxIndex = this.length - 1;\n\tvar currentIndex;\n\tvar currentElement;\n\twhile (minIndex <= maxIndex) {\n\t\tcurrentIndex = (minIndex + maxIndex) / 2 | 0;\n\t\tcurrentElement = this[currentIndex];\n\n\t\tif (currentElement > searchElement) {\n\t\t\tminIndex = currentIndex + 1;\n\t\t}\n\t\telse if (currentElement < searchElement) {\n\t\t\tmaxIndex = currentIndex - 1;\n\t\t}\n\t\telse {\n\t\t\treturn currentIndex;\n\t\t}\n\t}\n\treturn minIndex;\n};\n\nfor (var i = 0; i < q; i++){\n var query = readline().split(\" \").map(parseIntFunc);\n var friend = query[1] - 1;\n var friendValue = friends[friend];\n var queryType = query[0];\n if (queryType === 2){\n if (friendsOnline[friend]){\n if (binarySearch.call(friendsOnlineSorted, friendValue) < k){\n print('Yes');\n } else {\n print('No');\n }\n } else {\n print('No');\n }\n } else {\n friendsOnlineSorted.splice(binarySearch.call(friendsOnlineSorted, friendValue),0,friendValue);\n friendsOnline[friend] = 1;\n }\n}\n\n"}], "src_uid": "7c778289806ceed506543ef816c587c9"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e6;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rl();\r\n\t\tconst b = rl();\r\n\r\n\t\tconst cnt = [[0, 0], [0, 0]];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[a[i] - 0][b[i] - 0]++;\r\n\t\t}\r\n\r\n\t\tlet ans = INF;\r\n\t\tif (cnt[1][1] == cnt[0][0] + 1) {\r\n\t\t\tans = cnt[1][1] + cnt[0][0];\r\n\t\t}\r\n\r\n\t\tif (cnt[1][0] == cnt[0][1]) {\r\n\t\t\tans = Math.min(ans, cnt[1][0] + cnt[0][1]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans == INF ? -1 : ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e6;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rl();\r\n\t\tconst b = rl();\r\n\r\n\t\tconst cnt = [[0, 0], [0, 0]];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[a[i]-0][b[i]-0]++;\r\n\t\t}\r\n\r\n\t\tlet ans = INF;\r\n\t\tif (cnt[1][1] == cnt[0][0] + 1 && (cnt[1][1] + cnt[0][0]) % 2 == 1) {\r\n\t\t\tans = cnt[1][1] + cnt[0][0];\r\n\t\t}\r\n\r\n\t\tif (cnt[1][0] == cnt[0][1] && (cnt[1][0] + cnt[0][1]) % 2 == 0) {\r\n\t\t\tans = Math.min(ans, cnt[1][0] + cnt[0][1]);\r\n\t\t}\r\n\r\n\t\tif (ans == INF) ans = -1;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e6;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rl();\r\n\t\tconst b = rl();\r\n\r\n\t\tconst cnt = [[0, 0], [0, 0]];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[a[i]-0][b[i]-0]++;\r\n\t\t}\r\n\r\n\t\tlet ans = INF;\r\n\t\tif (cnt[1][1] >= cnt[0][0] && (cnt[1][1] + cnt[0][0]) % 2 == 1) {\r\n\t\t\tans = cnt[1][1] + cnt[0][0];\r\n\t\t}\r\n\r\n\t\tif (cnt[1][0] >= cnt[0][1] && (cnt[1][0] + cnt[0][1]) % 2 == 0) {\r\n\t\t\tans = Math.min(ans, cnt[1][0] + cnt[0][1]);\r\n\t\t}\r\n\r\n\t\tif (ans == INF) ans = -1;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst INF = 1e6;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rl();\r\n\t\tconst b = rl();\r\n\r\n\t\tlet sameCnt = 0, oppositeCnt = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] == b[i]) sameCnt++; else oppositeCnt++;\r\n\t\t}\r\n\r\n\t\tlet ans = INF;\r\n\t\tans = Math.min(ans, (sameCnt & 1) == 1 ? sameCnt : INF);\r\n\t\tans = Math.min(ans, (oppositeCnt & 1) == 0 ? oppositeCnt : INF);\r\n\r\n\t\tlet ok;\r\n\t\tfor (let i = 0; i < n; i++) ok |= a[i] == '1';\r\n\t\tif (!ok) ans = INF;\r\n\r\n\t\tconsole.log(ans == INF ? -1 : ans);\r\n\t}\r\n}\r\n\r\n"}], "src_uid": "84c0f17a45826a6e43d1f4717e62c194"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n// ---------------------------------------\n\nfunction main() {\n let t = getInt(readline());\n while (t--) {\n let [_, m] = getArray(readline());\n let arr = getArray(readline());\n for(let i=0; i< arr.length; i++) {\n m = m-arr[i];\n }\n console.log(m===0?'YES': 'NO');\n }\n}\n", "positive_code": [{"source_code": "const solve = (n, m, a) => {\n let sum = 0;\n for (const item of a) {\n sum += item;\n }\n return sum == m ? 'YES' : 'NO';\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 2);\n let n = data[0][0];\n let m = data[0][1];\n let a = data[1]\n console.log(solve(n, m, a));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (n, m, a) => {\n let sum = 0;\n for (let i = 0; i < n; i++) {\n for (const item of a) {\n sum += item;\n }\n return sum == m ? 'YES' : 'NO';\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 2);\n let n = data[0][0];\n let m = data[0][1];\n let a = data[1]\n console.log(solve(n, m, a));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, target] = readLine().split(\" \").map(Number);\n let sum = 0;\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n sum += n;\n return n;\n });\n if (sum === target) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar M = one[1];\n\t\tvar list = nextIntArray();\n\t\tvar sum = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tsum += list[j];\n\t\t}\n\t\toutput[i] = (sum == M) ? \"YES\" : \"NO\";\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() {\n return inputString[currentLine++];\n}\nconst print = x => console.log(x);\n// Main starts here\n\nfunction main() {\n let t = parseInt(input());\n // print(\"t \" + t);\n while (t--) {\n let [n, m] = input().split(' ').map(v => parseInt(v));\n let ar = input().split(' ').map(v => parseInt(v));\n const sum = ar.reduce((val, sum) => val + sum);\n if (sum === m) print(\"YES\");\n else print(\"NO\");\n }\n}\n"}, {"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() {\n return inputString[currentLine++];\n}\nconst println = x => console.log(x);\nconst print = x => process.stdout.write(x);\n// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<\n\nfunction main() {\n let t = parseInt(input());\n // print(\"t \" + t);\n while (t--) {\n let [n, m] = input().split(' ').map(v => parseInt(v));\n let ar = input().split(' ').map(v => parseInt(v));\n const sum = ar.reduce((val, sum) => val + sum);\n if (sum === m) print(\"YES\");\n else print(\"NO\");\n print(\"\\n\");\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number []} a\n * @param {Number} m\n * @returns {String}\n */\nfunction solve(a, m) {\n const sum = a.reduce((a, b) => a + b, 0);\n return (sum === m) ? 'YES' : 'NO';\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const [n, m] = (await getLine()).split(' ').map(Number);\n const a = (await getLine()).split(' ').map(Number);\n const res = solve(a, m);\n console.log(res);\n }\n}\n\nif (require.main === module) {\n main();\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let sum = 0;\n for(let i = 0; i < a.length; i++)\n sum += a[i];\n\n if(sum === m)\n console.log('YES');\n else\n console.log('NO');\n }\n}"}, {"source_code": "function readInt() {\n return readline().split(\" \").map(e => parseInt(e));\n}\n\nvar t = readInt()[0]\n\nfor(var i=0; i sum+=x);\n print(sum == m? \"YES\":\"NO\");\n}\n"}, {"source_code": "function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nfunction A678(arr, m) {\n return arr.reduce(function (a, b) {\n return a + b;\n }, 0) === m ? \"YES\" : \"NO\";\n}\n\nfunction execute(readline, print) {\n var iter = {\n next: function next() {\n var _readline;\n\n return (_readline = readline()) === null || _readline === void 0 ? void 0 : _readline.trim();\n }\n };\n\n var split = function split(string) {\n return string.split(' ').map(Number);\n };\n\n var t = Number(iter.next());\n\n while (t--) {\n var _split = split(iter.next()),\n _split2 = _slicedToArray(_split, 2),\n n = _split2[0],\n m = _split2[1];\n\n var arr = split(iter.next());\n print(A678(arr, m));\n }\n}\n\nexecute(readline, print)\n\n"}, {"source_code": "var t = Number( readline() );\nfor(var k=0; kNumber(x));\n var a = readline().split(' ').map(x=>Number(x));\n var q = 0;\n for(var i=0; i parseInt(x));\nvar n = firstLineInput[0], m = firstLineInput[1];\n\nvar secondLineInput = readline().split(' ').map(x => parseInt(x));\n\nvar sum = 0 ; \nsecondLineInput.forEach((item) => {\n\tsum += item ;\n});\n\nif(sum === m){\n\tprint('YES')\n}else{\n\tprint('NO')\n}\n \n}"}, {"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n var AR = readline().split(' ').map(x => parseInt(x));\n var n = AR[0], m = AR[1];\n var ar = readline().split(' ').map(x => parseInt(x));\n var res = ar.reduce((a, b) => a + b);\n print(res == m ? 'YES' : 'NO');\n}"}, {"source_code": "/* A. Reorder\ntime limit per test1 second\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nFor a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that \u2211ni=1\u2211nj=iajj equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, 52=2.5.\n\nInput\nThe first line contains a single integer t \u2014 the number of test cases (1\u2264t\u2264100). The test cases follow, each in two lines.\n\nThe first line of a test case contains two integers n and m (1\u2264n\u2264100, 0\u2264m\u2264106). The second line contains integers a1,a2,\u2026,an (0\u2264ai\u2264106) \u2014 the elements of the array.\n\nOutput\nFor each test case print \"YES\", if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and \"NO\" otherwise.Example\ninputCopy\n2\n3 8\n2 5 1\n4 4\n0 1 2 3\noutputCopy\nYES\nNO */\n\nvar testCasesNumber = readline();\nvar listOfNAndM = [];\nvar listOfNValues = [];\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfNAndM.push(readline().split(' '));\n listOfNValues.push(readline().split(' '));\n }\nfor (var i = 0; i < testCasesNumber; i++) {\n var sum = 0;\n listOfNValues[i].forEach(myFunction);\n print(sum==listOfNAndM[i][1]? \"Yes\" :\"No\")\n \n \n} \n \n function myFunction(item) {\n sum += parseInt(item);\n ; \n } "}, {"source_code": "var numberOfTests = readline();\nvar input1 = [];\nvar toReorder = [];\nfor (var i = 0; i < numberOfTests; i++) {\n input1.push(readline().split(' '));\n toReorder.push(readline().split(' '));\n}\n\n\nfor (var j = 0; j < numberOfTests; j++) {\n var sum = 0;\n toReorder[j].forEach(add);\n print(sum == input1[j][1]? 'Yes' : 'No');\n}\nfunction add(item) {\n sum += parseInt(item);\n}\n\n\n"}, {"source_code": "var T = +readline();\n\nfor (var i = 0; i < T; i++) {\n var p = readline().split(' ').map(i => +i);\n var n = p[0];\n var m = p[1];\n \n var d = readline().split(' ').map(i => +i);\n \n var res = 0;\n \n for (var y = 0; y < d.length; y++) {\n res += d[y];\n }\n \n if (res == m) {\n print('YES');\n } else {\n print('NO');\n }\n}"}, {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var A1 = readline().split(' ').map(x => parseInt(x));\n\n var n = A1[0];\n var m = A1[1];\n\n var A2 = readline().split(' ').map(x => parseInt(x));\n \n var total = A2.reduce((t, a)=> t+a, 0);\n print((total===m)?\"YES\":\"NO\");\n}"}, {"source_code": "\nvar tc = parseInt(readline());\nfor (; tc--;){\n var AR = readline().split(' ').map(x => parseInt(x));\n var n = AR[0], m = AR[1];\n var ar = readline().split(' ').map(x => parseInt(x));\n var res = ar.reduce((a, b) => a + b);\n print(res == m ? 'YES' : 'NO');\n}\n\n"}], "negative_code": [{"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() {\n return inputString[currentLine++];\n}\nconst print = x => console.log(x);\n// Main starts here\n\nfunction main() {\n let t = parseInt(input());\n // print(\"t \" + t);\n let [n, m] = input().split(' ').map(v => parseInt(v));\n let ar = input().split(' ').map(v => parseInt(v));\n const sum = ar.reduce((val, sum) => val + sum);\n if (sum === m) print(\"YES\");\n else print(\"NO\");\n}\n"}, {"source_code": "function readInt() {\n return readline().split(\" \").map(e => parseInt(e));\n}\n\nvar t = readInt()[0]\n\nfor(var i=0; i sum+=x);\n print(sum%m == 0? \"YES\":\"NO\");\n}"}, {"source_code": "\nvar firstLineInput = readline().split(' ').map((x) => parseInt(x));\nvar n = firstLineInput[0], m = firstLineInput[1];\n\nvar secondLineInput = readline().split(' ').map(x => parseInt(x));\n\nvar sum = 0 ; \nsecondLineInput.forEach((item) => {\n\tsum += item ;\n});\n\nif(sum === m){\n\tprint('YES')\n}else{\n\tprint('NO')\n}\n \n"}, {"source_code": "var firstLineInput = readline().split(' ').map((x) => parseInt(x));\nvar n = firstLineInput[0], m = firstLineInput[1];\n\nvar secondLineInput = readline().split(' ').map(x => parseInt(x));\n\nvar sum = 0 ; \nsecondLineInput.forEach((item) => {\n\tsum += item ;\n});\n\nif(sum === m){\n\tprint('YES')\n}else{\n\tprint('NO')\n}"}, {"source_code": "var firstLineInput = readline().split(' ').map((x) => parseInt(x));\nvar n = firstLineInput[0], m = firstLineInput[1];\n\nvar secondLineInput = readline().split(' ').map(x => parseInt(x));\n\nvar sum = 0 ; \nsecondLineInput.forEach((item) => {\n\tsum += item ;\n});\n\nif(sum == m){\n\tprint('YES')\n}else{\n\tprint('NO')\n}"}, {"source_code": "var T = +readline();\n\nfor (var i = 0; i < T; i++) {\n var p = readline().split(' ').map(i => +i);\n var n = p[0];\n var m = p[1];\n \n var d = readline().split(' ').map(i => +i);\n // d = d.sort();\n \n // var res = 0;\n \n // for (var y = 0; y < d.length; y++) {\n // for (var x = 0; x < d.slice(y).length; x++) {\n // res += d.slice(y)[x] / (x + y + 1); \n // }\n // }\n \n if (Math.max(...d) === m-n) {\n print('YES');\n } else {\n print('NO');\n }\n \n // if (m == res) {\n // print('YES');\n // } else {\n // print('NO');\n // }\n}"}, {"source_code": "var T = +readline();\n\nfor (var i = 0; i < T; i++) {\n var p = readline().split(' ').map(i => +i);\n var n = p[0];\n var m = p[1];\n \n var d = readline().split(' ').map(i => +i);\n d = d.sort();\n \n var res = 0;\n \n for (var y = 0; y < d.length; y++) {\n for (var x = 0; x < d.slice(y).length; x++) {\n res += d.slice(y)[x] / (x + y+ 1); \n }\n }\n \n if (m == res) {\n print('YES');\n } else {\n print('NO');\n }\n}"}], "src_uid": "941adee47c2a28588ebe7dfe16e0c91a"} {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const [a, b] = arr[j].split(' ').map(a => parseInt(a))\n let d = max(a, b) - min(a, b)\n\n for(let i = 0, s = 0; ; i++) {\n s += i\n if(s >= d && d % 2 == s % 2) {\n wr(i)\n break\n }\n }\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n", "positive_code": [{"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t, diff, sum, numbers;\n\nt = Number(readline());\n\nfor (i = 0; i < t; i++) { //loop cases\n\n numbers = readline().replace(/\\r$/, '').split(' ').map(Number);\n diff = Math.abs(numbers[0] - numbers[1]);\n n = 0;\n sum = n * (n + 1) / 2;\n \n while(sum < diff || (sum % 2 != diff % 2)) {\n\n n++;\n sum = n * (n + 1) / 2;\n }\n\n print(n);\n}"}, {"source_code": "var input = '';\nvar curIndex = 0;\nfunction readline(){ return input[curIndex++]; }\n\nprocess.stdin.on('data', inputStdin => input += inputStdin );\n\nprocess.stdin.on('end', () => {\n input = input.trim().split('\\n').map(str => str.trim() );\n main(); \n});\n\n\nfunction main(){\n var t; t = +readline();\n\twhile(t--){\n\t\tlet a,b; [a,b] = readline().split(' ').map(n => +n);\n\t\tlet k = Math.abs(a-b);\n\t\t\n\t\tlet l,r;\n\t\tl = 0, r = 1e9;\n\t\twhile(l<=r){\n\t\t\tlet m = ~~((l+r)/2);\n\t\t\tlet pa = (m*(m+1))/2;\n\t\t\tif(pa < k) l = m+1;\n\t\t\telse r = m-1;\n\t\t}\n\t\t\n\t\twhile( ((l*(l+1))/2 + k) % 2 !== 0 ) l++;\n\t\t\n\t\tconsole.log(l);\n\t\t\n\t}\n}"}], "negative_code": [{"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t, number, answer, action;\n\nt = Number(readline());\n\nfor (i = 0; i < t; i++) {\n\n answer = 0;\n action = 1;\n number = readline().replace(/\\r$/, '').split(' ').map(Number);\n\n while (number[0] != number[1]) {\n\n if (number[0] > number[1]) {\n\n if (number[0] - number[1] >= action) {\n number[1] += action;\n } else {\n number[0] += action;\n }\n } else {\n \n if ((number[1] - number[0]) >= action) {\n number[0] += action;\n } else {\n number[1] += action;\n }\n }\n\n action++;\n answer++;\n }\n\n print(answer);\n}"}], "src_uid": "29e84addbc88186bce40d68cf124f5da"} {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n let curLine = 0\n const T = parseInt(lines[curLine++])\n for (let t = 0; t < T; t++) {\n const [R, C] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const mat = []\n for (let r = 0; r < R; r++) {\n mat.push(lines[curLine++].trim().split('').map((x) => parseInt(x)))\n }\n\n const ans = []\n\n const apply = (r1, c1, r2, c2, r3, c3) => {\n mat[r1][c1] ^= 1\n mat[r2][c2] ^= 1\n mat[r3][c3] ^= 1\n ans.push([r1 + 1, c1 + 1, r2 + 1, c2 + 1, r3 + 1, c3 + 1])\n }\n \n for (let r = 0; r + 2 < R; r++) {\n for (let c = 0; c < C; c += 2) {\n if (c + 1 == C) {\n if (mat[r][c]) {\n apply(r, c, r + 1, c - 1, r + 1, c)\n }\n } else {\n if (mat[r][c] && mat[r][c + 1]) {\n apply(r, c, r, c + 1, r + 1, c)\n } else if (mat[r][c]) {\n apply(r, c, r + 1, c, r + 1, c + 1)\n } else if (mat[r][c + 1]) {\n apply(r, c + 1, r + 1, c, r + 1, c + 1)\n }\n }\n }\n }\n\n for (let c = 0; c + 1 < C; c++) {\n if (mat[R - 2][c] && mat[R - 1][c]) {\n apply(R - 2, c, R - 1, c, R - 2, c + 1)\n } else if (mat[R - 2][c]) {\n apply(R - 2, c, R - 2, c + 1, R - 1, c + 1)\n } else if (mat[R - 1][c]) {\n apply(R - 1, c, R - 2, c + 1, R - 1, c + 1)\n }\n }\n\n if (mat[R - 2][C - 1] && mat[R - 1][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 2)\n apply(R - 2, C - 2, R - 1, C - 2, R - 1, C - 1)\n } else if (mat[R - 2][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 2)\n apply(R - 1, C - 2, R - 1, C - 1, R - 2, C - 1)\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 1)\n } else if(mat[R - 1][C - 1]) {\n apply(R - 2, C - 2, R - 2, C - 1, R - 1, C - 1)\n apply(R - 2, C - 2, R - 1, C - 2, R - 1, C - 1)\n apply(R - 2, C - 1, R - 1, C - 2, R - 1, C - 1)\n }\n\n console.log(ans.length)\n ans.forEach((op) => console.log(op.join(' ')))\n } \n})\n", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function a(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=a();for(;e>0;)t(),e--}))},readline:h,nextNumbers:a,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{n.push(`${t+1} ${e+1} ${o+1} ${s+1} ${i+1} ${u+1}`),\"0\"==r[t][e]?r[t][e]=\"1\":r[t][e]=\"0\",\"0\"==r[o][s]?r[o][s]=\"1\":r[o][s]=\"0\",\"0\"==r[i][u]?r[i][u]=\"1\":r[i][u]=\"0\"};if(t%2==1)for(let t=0;t{\"0\"!=r[t][e]?\"0\"!=r[t+1][e]?\"0\"!=r[t][e+1]?\"0\"==r[t+1][e+1]&&s(t+1,e,t,e+1,t,e):s(t,e,t+1,e,t+1,e+1):s(t,e,t,e+1,t+1,e+1):s(t+1,e,t,e+1,t+1,e+1)},u=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)},l=(t,e)=>{let n=[],o=[];for(let s=0;s<2;++s)for(let i=0;i<2;++i)\"0\"==r[t+s][e+i]?n.push({x1:t+s,x2:e+i}):o.push({x1:t+s,x2:e+i});s(n[0].x1,n[0].x2,n[1].x1,n[1].x2,o[0].x1,o[0].x2)};for(let n=t%2==0?0:1;n{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, m] = io.nextNumbers()\n// let a = io.nextCharacterMatrix(n)\n// \n// let flips = []\n// \n// let flip = (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) => {\n// flips.push(`${x1 + 1} ${y1 + 1} ${x2 + 1} ${y2 + 1} ${x3 + 1} ${y3 + 1}`)\n// \n// if (a[x1][y1] == \"0\") {\n// a[x1][y1] = \"1\"\n// } else {\n// a[x1][y1] = \"0\"\n// }\n// \n// if (a[x2][y2] == \"0\") {\n// a[x2][y2] = \"1\"\n// } else {\n// a[x2][y2] = \"0\"\n// }\n// \n// if (a[x3][y3] == \"0\") {\n// a[x3][y3] = \"1\"\n// } else {\n// a[x3][y3] = \"0\"\n// }\n// }\n// \n// if (n % 2 == 1) {\n// for (let i = 0; i < m - 1; i++) {\n// if (a[0][i] == \"1\" && a[0][i + 1] == \"1\") {\n// flip(0, i, 0, i + 1, 1, i)\n// } else if (a[0][i] == \"1\") {\n// flip(0, i, 1, i + 1, 1, i)\n// } else if (a[0][i + 1] == \"1\") {\n// flip(0, i + 1, 1, i + 1, 1, i)\n// }\n// }\n// }\n// \n// if (m % 2 == 1) {\n// for (let i = n % 2 == 0 ? 0 : 1; i < n - 1; ++i) {\n// if (a[i][0] == \"1\" && a[i + 1][0] == \"1\") {\n// flip(i, 0, i + 1, 0, i, 1)\n// } else if (a[i][0] == \"1\") {\n// flip(i, 0, i + 1, 1, i, 1)\n// } else if (a[i + 1][0] == \"1\") {\n// flip(i, 1, i + 1, 0, i + 1, 1)\n// }\n// }\n// }\n// \n// let proc3 = (x1: number, x2: number) => {\n// if (a[x1][x2] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2] == \"0\") {\n// flip(x1, x2, x1, x2 + 1, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1][x2 + 1] == \"0\") {\n// flip(x1, x2, x1 + 1, x2, x1 + 1, x2 + 1)\n// return\n// }\n// \n// if (a[x1 + 1][x2 + 1] == \"0\") {\n// flip(x1 + 1, x2, x1, x2 + 1, x1, x2)\n// }\n// }\n// \n// let proc1 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// let proc2 = (x1: number, x2: number) => {\n// let zeroCoord = []\n// let oneCoord = []\n// \n// for (let i = 0; i < 2; ++i) {\n// for (let j = 0; j < 2; ++j) {\n// if (a[x1 + i][x2 + j] == \"0\") {\n// zeroCoord.push({ x1: x1 + i, x2: x2 + j })\n// } else {\n// oneCoord.push({ x1: x1 + i, x2: x2 + j })\n// }\n// }\n// }\n// \n// flip(\n// zeroCoord[0].x1,\n// zeroCoord[0].x2,\n// zeroCoord[1].x1,\n// zeroCoord[1].x2,\n// oneCoord[0].x1,\n// oneCoord[0].x2\n// )\n// }\n// \n// for (let i = n % 2 == 0 ? 0 : 1; i < n; i += 2) {\n// for (let j = m % 2 == 0 ? 0 : 1; j < m; j += 2) {\n// let nr0 = 0\n// let nr1 = 0\n// \n// if (a[i][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (a[i + 1][j + 1] == \"1\") {\n// nr1++\n// } else {\n// nr0++\n// }\n// \n// if (nr1 == 0) {\n// continue\n// }\n// \n// if (nr1 == 3) {\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 2) {\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 1) {\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// \n// if (nr1 == 4) {\n// flip(i, j, i + 1, j, i + 1, j + 1)\n// proc1(i, j)\n// proc2(i, j)\n// proc3(i, j)\n// continue\n// }\n// }\n// }\n// \n// io.puts(flips.length)\n// io.puts(flips.join(\" \"))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [], "src_uid": "7dd42c258865a14ad6c3184e631d8555"} {"source_code": "var input = readline().split(' ')\n , n = +input[0]\n , m = +input[1]\n , teams = [];\n\nfor (var i = 0, info = null; i < n; i++) {\n info = readline().split(' ');\n if (teams[info[1]] === undefined) {\n teams[info[1]]= [];\n }\n if (teams[info[1]][info[2]] === undefined ) {\n teams[info[1]][info[2]] = [];\n }\n teams[info[1]][info[2]].push(info[0]);\n}\n\nfor (var i = 1, keys = []; i < teams.length; i++) {\n keys = Object.keys(teams[i]).reverse();\n if (teams[i][keys[0]].length > 2) {\n print('?');\n continue;\n } else if (teams[i][keys[0]].length === 2) {\n print(teams[i][keys[0]].join(' '));\n continue;\n } else if (teams[i][keys[1]].length > 1) {\n print('?');\n continue;\n } else {\n print(teams[i][keys[0]] + ' ' + teams[i][keys[1]]);\n continue;\n }\n}\n", "positive_code": [{"source_code": "var arr = readline().split(\" \", 2).map(Number);\nvar n = arr[0], m = arr[1];\n\nvar array = new Array(m);\nfor (var i = 0; i < m; ++i) {\n array[i] = [];\n}\nfor (var i = 0; i < n; ++i) {\n arr = readline().split(\" \", 3);\n array[Number(arr[1]) - 1].push({\n name: arr[0],\n score: Number(arr[2])\n });\n}\n\nfunction getMaxIndex(array, l, r) {\n var value = array[l].score, index = l;\n for (var i = l + 1; i < r; ++i) {\n if (array[i].score > value) {\n value = array[i].score;\n index = i;\n }\n }\n return index;\n}\nfunction swap(array, x, y) {\n if (x !== y && x >= 0 && x < array.length &&\n y >= 0 && y < array.length) {\n var temp = array[x];\n array[x] = array[y];\n array[y] = temp;\n }\n}\nfunction firstThree(array) {\n for (var i = 0; i < 3; ++i) {\n swap(array, i, getMaxIndex(array, i, array.length));\n }\n}\nfor (var i = 0; i < m; ++i) {\n if (array[i].length === 2) {\n print(array[i][0].name + \" \" + array[i][1].name);\n } else {\n firstThree(array[i]);\n if (array[i][1].score === array[i][2].score) {\n print(\"?\");\n } else {\n print(array[i][0].name + \" \" + array[i][1].name);\n }\n }\n}"}, {"source_code": "\nvar isCodeForces = true;\nvar line, lines, echo;\nif(!isCodeForces){\n\tlines = '';\n\tprocess.stdin.resume();\n\tprocess.stdin.on('data', function(buffer){lines += buffer.toString();});\n\tprocess.stdin.on('end', function(){\n\t\tlines = lines.trim().split('\\n');\n\t\techo = console.log;\n\t\twrapper();\n\t});\n}else{\n\tlines = [];\n\twhile(line = readline()){\n\t\tlines.push(line);\n\t}\n\techo = print;\n\twrapper();\n}\n\nfunction wrapper(){\n\tinit();\n\tvar res = main();\n\tif(res != undefined){\n\t\techo(res);\n\t}\n}\n\nfunction main(){\n\tvar line = lines[0].split(' ');\n\tvar n = parseInt(line[0]), m = parseInt(line[1]), res = new Array(m + 1).join(' ').split('').map(function(){\n\t\treturn [];\n\t});\n\tfor(var i = 1; i <= n; i++){\n\t\tline = lines[i].split(' ');\n\t\tvar name = line[0], region = parseInt(line[1]) - 1, score = parseInt(line[2]);\n\t\tres[region].push([score, name]);\n\t}\n\tfor(i = 0; i < m; i++){\n\t\tvar row = res[i].sort(function(a, b){\n\t\t\treturn b[0] - a[0];\n\t\t});\n\t\tif(row.length >= 3 && row[1][0] == row[2][0])\n\t\t\tres[i] = '?';\n\t\telse {\n\t\t\tres[i] = `${row[0][1]} ${row[1][1]}`;\n\t\t}\n\t}\n\treturn res.join('\\n');\n}\n\nfunction init(){\n}\n"}], "negative_code": [], "src_uid": "a1ea9eb8db25289958a6f730c555362f"} {"source_code": "process.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => {\n input.split('\\r\\n')\n .filter((_, index) => index >= 2 && index % 2 === 0)\n .map(line => line.split(' ').map(v => parseInt(v, 10)))\n .forEach(permutation => {\n let index = 0;\n while (index < permutation.length - 1) {\n const value = Math.min(...permutation.slice(index));\n const valueIndex = permutation.indexOf(value);\n for (let i = valueIndex - 1; i >= index; i--) { permutation[i + 1] = permutation[i]; }\n permutation[index] = value;\n index = Math.max(valueIndex, index + 1);\n }\n console.log(permutation.join(' '));\n });\n});\n\n", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n input.split('\\r\\n').filter((_, i) => i >= 2 && i % 2 === 0).map(l => l.split(' ').map(v => parseInt(v, 10)))\n .forEach(q => {\n for (let index = 0; index < q.length; index++) {\n const v = Math.min(...q.slice(index));\n const vIndex = q.indexOf(v);\n for (let i = vIndex - 1; i >= index; i--) { q[i + 1] = q[i]; }\n q[index] = v;\n index = Math.max(vIndex - 1, index);\n }\n console.log(q.join(' '));\n });\n});\n\n"}, {"source_code": "//DONE:\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n for(let i = 0; i < q; i++) {\n const n = parseInt(arr[2 * i])\n const no = arr[2 * i + 1].split(' ').map(a => parseInt(a))\n var a = min(no)\n console.log(a.join(' '))\n }\n})\n\nfunction min(no) {\n const n = no.length\n const i = no.indexOf(Math.min.apply(null, no))\n // console.log(i, no)\n if(i == n - 1) {\n const s = no.pop()\n no.unshift(s)\n return no\n }\n else if(i == 0) {\n return [no[0]].concat(min(no.slice(1, n)))\n }\n\n else {\n // console.log(no)\n var a = no.slice(0, i + 1)\n a.unshift(a.pop())\n no = a.concat(no.slice(i + 1, n))\n // console.log(a, no)\n b = min(no.slice(i, n))\n // console.log(b)\n return a.slice(0, a.length - 1).concat(b)\n }\n}"}, {"source_code": "'use strict'\n\nconst problem = (n, p) => {\n let a = 0;\n for (let i = 1; i <= n; i++) {\n const b = p.indexOf(i);\n\n for (let j = b; j > a; j--) {\n const c = p[j]; p[j] = p[j - 1]; p[j - 1] = c;\n }\n if (a === b) a = b + 1;\n if (a < b) a = b;\n }\n return p.join(' ');\n}\n\nlet q = +readline();\nwhile (q--) print(problem(+readline(), readline().split(' ').map(Number)));\n"}, {"source_code": " var count = +readline();\n while (count--) {\n var n = +readline();\n var elements = readline()\n .split(\" \")\n .map(Number);\n\n var a = 0;\n\n for (var i = 1; i < n + 1; i++) {\n var index = elements.indexOf(i);\n\n for (var j = index; j > a; j--) {\n var buf = elements[j - 1];\n elements[j - 1] = elements[j];\n elements[j] = buf;\n }\n\n if (a === index) a = index + 1;\n if (a < index) a = index;\n }\n print(elements.join(\" \"));\n }"}, {"source_code": "process.stdin.setEncoding('utf-8');\n\nlet lineNumber = 0;\nprocess.stdin.on('data', input => {\n input.split('\\r\\n').forEach(line => {\n // console.log('on line', lineNumber, input);\n if (++lineNumber >= 3 && lineNumber % 2 === 1) { resolve(line) }\n });\n});\n\nfunction resolve(input) {\n let permutation = input.split(' ').map(v => parseInt(v, 10));\n let index = 0;\n while (index < permutation.length - 1) {\n const value = Math.min(...permutation.slice(index));\n const valueIndex = permutation.indexOf(value);\n if (valueIndex > index) {\n for (let i = valueIndex - 1; i >= index; i--) {\n permutation[i + 1] = permutation[i];\n }\n permutation[index] = value;\n index = valueIndex - 1;\n }\n index++;\n }\n console.log(permutation.join(' '));\n}\n"}], "negative_code": [{"source_code": "//DONE:\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n for(let i = 0; i < q; i++) {\n const n = parseInt(arr[2 * i])\n const no = arr[2 * i + 1].split(' ').map(a => parseInt(a))\n // console.log(no)\n var a = min(no)\n console.log(a.join(' '))\n }\n})\n\nfunction min(no) {\n const n = no.length\n const i = no.indexOf(Math.min.apply(null, no))\n // console.log(i, Math.min.apply(null, no))\n if(i == n - 1) {\n const s = no.pop()\n no.unshift(s)\n return no\n }\n else if(i == 0) {\n return [no[0]].concat(min(no.slice(1, n)))\n }\n\n else {\n var a = no.slice(0, i + 1)\n a.unshift(a.pop())\n var b = min(no.slice(i + 1, n))\n // console.log(a, no.slice(i + 1, n))\n no = a.concat(b)\n if(no[i] > no[i + 1]) {\n const temp = no[i]\n no[i] = no[i + 1]\n no[i + 1] = temp\n }\n return no\n }\n}"}, {"source_code": "//DONE:\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const q = parseInt(arr.shift())\n\n for(let i = 0; i < q; i++) {\n const n = parseInt(arr[2 * i])\n const no = arr[2 * i + 1].split(' ').map(a => parseInt(a))\n // console.log(no)\n var a = min(no)\n console.log(a.join(' '))\n }\n})\n\nfunction min(no) {\n const n = no.length\n const i = no.indexOf(Math.min.apply(null, no))\n // console.log(i, Math.min.apply(null, no))\n if(i == n - 1) {\n const s = no.pop()\n no.unshift(s)\n return no\n }\n else if(i == 0) {\n return [no[0]].concat(min(no.slice(1, n)))\n }\n\n else {\n // console.log(no)\n var a = no.slice(0, i + 1)\n a.unshift(a.pop())\n no = a.concat(no.slice(i + 1, n))\n if(no[i] > no[i + 1]) {\n const temp = no[i]\n no[i] = no[i + 1]\n no[i + 1] = temp\n a = no.slice(0, i + 1)\n }\n // console.log(a, no)\n b = min(no.slice(i + 1, n))\n // console.log(b)\n return a.concat(b)\n }\n}"}, {"source_code": "process.stdin.setEncoding('utf-8');\n\nlet lineNumber = 0;\nconsole.log('started');\nprocess.stdin.on('data', input => {\n input.split('\\r\\n').forEach(line => {\n // console.log('on line', lineNumber, input);\n if (++lineNumber >= 3 && lineNumber % 2 === 1) { resolve(line) }\n });\n});\n\nfunction resolve(input) {\n let permutation = input.split(' ').map(v => parseInt(v, 10));\n let index = 0;\n while (index < permutation.length - 1) {\n const value = Math.min(...permutation.slice(index));\n const valueIndex = permutation.indexOf(value);\n if (valueIndex > index) {\n for (let i = valueIndex - 1; i >= index; i--) {\n permutation[i + 1] = permutation[i];\n }\n permutation[index] = value;\n index = valueIndex - 1;\n }\n index++;\n }\n console.log(permutation.join(' '));\n}\n"}, {"source_code": "'use strict'\n\n\nconst problem = (n, p) => {\n let a = 0, b, i = 0;\n while(i < n && a <= (b = p.indexOf(++i))) {\n for (let j = b; j > a; j--) {\n const c = p[j];\n p[j] = p[j - 1];\n p[j - 1] = c;\n }\n a = +(a === b) + b;\n }\n return p.join(' ');\n}\n\nlet q = +readline();\nwhile (q--) print(problem(+readline(), readline().split(' ').map(Number)));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, p) => {\n let a = 0;\n for (let i = 1; i < n; i++) {\n const b = p.indexOf(i);\n for (let j = b; j > a; j--) {\n const c = p[j];\n p[j] = p[j - 1];\n p[j - 1] = c;\n }\n a = +(a === b) + b;\n }\n return p.join(' ');\n}\n\nlet q = +readline();\nwhile (q--) {\n print(problem(+readline(), readline().split(' ').map(Number)));\n}\n"}, {"source_code": " var sets = parseInt(readline());\n\n for (var i = 0; i < sets; i++) {\n var elementCount = parseInt(readline());\n var elements = readline()\n .split(\" \")\n .map(function(value) {\n return parseInt(value);\n });\n var actions = Array(elementCount + 1).map(function(value) {\n return true;\n });\n\n for (var j = 0; j < actions.length; j++) {\n actions[j] = true;\n }\n var changed = true;\n\n for (var elem = 1; elem < elementCount + 1 && changed; elem++) {\n changed = false;\n\n if (elem === elements[elem - 1]) {\n elem++;\n changed = true;\n continue;\n }\n\n for (var j = 0; j < elementCount; j++) {\n if (elements[j + 1] === elem && elements[j] > elem && actions[j]) {\n var tmp = elements[j];\n elements[j] = elements[j + 1];\n elements[j + 1] = tmp;\n actions[j] = false;\n elem++;\n changed = true;\n }\n }\n elem = 0;\n }\n\n print(elements.join(' '));\n }"}, {"source_code": " var sets = parseInt(readline());\n\n for (var i = 0; i < sets; i++) {\n var elementCount = parseInt(readline());\n var elements = readline()\n .split(\" \")\n .map(function(value) {\n return parseInt(value);\n });\n var actions = Array(elementCount + 1);\n\n for (var j = 0; j < actions.length; j++) {\n actions[j] = true;\n }\n var changed = true;\n\n for (var elem = 1; elem < elementCount + 1 && changed; elem++) {\n changed = false;\n\n if (elem === elements[elem - 1]) {\n changed = true;\n continue;\n }\n\n for (var j = 0; j < elementCount; j++) {\n if (elements[j + 1] === elem && elements[j] > elem && actions[j]) {\n var tmp = elements[j];\n elements[j] = elements[j + 1];\n elements[j + 1] = tmp;\n actions[j] = false;\n elem++;\n changed = true;\n }\n }\n elem = 0;\n }\n\n print(elements.join(\" \"));\n }"}, {"source_code": " var sets = parseInt(readline());\n\n for (var i = 0; i < sets; i++) {\n var elementCount = parseInt(readline());\n var elements = readline()\n .split(\" \")\n .map(function(value) {\n return parseInt(value);\n });\n var actions = Array(elementCount + 1);\n\n for (var j = 0; j < actions.length; j++) {\n actions[j] = true;\n }\n var changed = true;\n\n for (var elem = 1; elem < elementCount + 1 && changed; elem++) {\n changed = false;\n\n if (elem === elements[elem - 1]) {\n elem++;\n changed = true;\n continue;\n }\n\n for (var j = 0; j < elementCount; j++) {\n if (elements[j + 1] === elem && elements[j] > elem && actions[j]) {\n var tmp = elements[j];\n elements[j] = elements[j + 1];\n elements[j + 1] = tmp;\n actions[j] = false;\n elem++;\n changed = true;\n }\n }\n elem = 0;\n }\n\n print(elements.join(\" \"));\n }"}], "src_uid": "c7a7e90bc54b2d21b3f59a358d9d1410"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction findCost(initial, chars) {\n\tvar cost = 0,\n\t\texpected = initial, opposite = (initial+1)%2, temp;\n\n\tfor (var position = 0; position < chars.length; ++position) {\n\t\tif (chars[position] != expected) {\n\t\t\t++cost;\n\t\t}\n\t\ttemp = expected;\n\t\texpected = opposite;\n\t\topposite = temp;\n\t}\n\n\treturn cost;\n}\n\nfunction main() {\n\tvar length = parseInt(readline(), 10);\n\tvar input = readline().replace(/\\s+/g, \"\");\n\n\tprint(Math.min(findCost(0, input.split(\"\")),\n\t\t\t\tfindCost(1, input.split(\"\"))));\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction findCost(initial, chars) {\n\tvar cost = 0,\n\t\texpected = initial, opposite = (initial+1)%2;\n\n\tfor (var position = 0; position < chars.length; ++position) {\n\t\tif (chars[position] != expected) {\n\t\t\t++cost;\n\t\t}\n\t\tvar temp = expected;\n\t\texpected = opposite;\n\t\topposite = temp;\n\t}\n\n\treturn cost;\n}\n\nfunction main() {\n\tvar length = parseInt(readline(), 10);\n\tvar input = readline().replace(/\\s+/g, \"\");\n\n\tprint(Math.min(findCost(0, input.split(\"\")),\n\t\t\t\tfindCost(1, input.split(\"\"))));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction findCost(initial, chars) {\n\tvar cost = 0,\n\t\texpected = (initial+1)%2, nextExpected = initial,\n\t\tposition = 0;\n\n\twhile (position != chars.length-1) {\n\t\tvar temp = expected;\n\t\texpected = nextExpected;\n\t\tnextExpected = temp;\n\n\t\tif (chars[position] == chars[position+1]) {\n\t\t\t++cost;\n\n\t\t\tif (chars[position] == expected) {\n\t\t\t\tchars[position+1] = nextExpected;\n\t\t\t\t++position;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tchars[position] = expected;\n\t\t\t\tif (position == 0) {\n\t\t\t\t\tposition = 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t--position;\n\t\t\t\t}\n\t\t\t}//end else\n\t\t}//end if\n\n\t\telse {\n\t\t\t++position;\n\t\t}\n\t}//end while\n\n\treturn cost;\n}//end findCost\n\nfunction main() {\n\tvar length = parseInt(readline(), 10);\n\tvar input = readline().replace(/\\s+/g, \"\");\n\n\tfor (var position = 1; position < length; ++position) {\n\t\tif (input.charAt(position) == input.charAt(position-1)) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (position == length) {\n\t\tprint(0);\n\t\treturn;\n\t}\n\n\tprint(Math.min(findCost(0, input.split(\"\")),\n\t\t\t\tfindCost(1, input.split(\"\"))));\n}\n\nmain();\n"}], "negative_code": [], "src_uid": "7c313b911e644cd5efa4fdc31d7ffcc9"} {"source_code": "var s = readline().split('');\n\nvar v = 1;\nvar g = 1;\n\ns.forEach(c => {\n if(c == '0') {\n print(1, v);\n if(v === 4) {\n v = 1;\n }\n else {\n v++;\n }\n }\n else {\n print(4, g);\n g = g === 1 ? 3 : 1;\n }\n});\n", "positive_code": [{"source_code": "var str = '';\nvar readliner = require('readline');\nvar rl = readliner.createInterface(process.stdin, process.stdout, null);\nrl.on('line', function (cmd) {\n //console.log('You just typed: '+cmd);\n str = cmd;\n }).on('close', main);\n\nfunction recheck(s) {\n\tfor (var x=0; x<4; x++) {\n\t\tvar all_1 = 1;\n\t\tfor (var y=0; y<4; y++)\n\t\t\tif (s[x][y] !== 1) {\n\t\t\t\tall_1 = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif (all_1 === 1)\n\t\t\tfor (var y=0; y<4; y++)\n\t\t\t\ts[x][y] = 0;\n\t}\n\tfor (var x=0; x<4; x++) {\n\t\tvar all_1 = 1;\n\t\tfor (var y=0; y<4; y++)\n\t\t\tif (s[y][x] !== 1) {\n\t\t\t\tall_1 = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif (all_1 === 1)\n\t\t\tfor (var y=0; y<4; y++)\n\t\t\t\ts[y][x] = 0;\n\t}\n}\n\nfunction main() {\n //console.log('goodbye!');\n\n/* var mn = 1000000000;\n for (var code=0; code<(1<<9); code++) {\n\tvar cnt_ones = 0;\n\tfor (var j=0; j<9; j++) cnt_ones += (code>>j)&1;\n var x = N;\n \n }*/\n\n var s = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];\n\n for (var j=0; j>j)&1;\n var x = N;\n \n }*/\n\n var s = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];\n\n for (var j=0; j>j)&1;\n var x = N;\n \n }*/\n\n var s = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];\n\n for (var j=0; j>j)&1;\n var x = N;\n \n }*/\n\n var s = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];\n\n for (var j=0; j>j)&1;\n var x = N;\n \n }*/\n\n var s = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];\n\n for (var j=0; j {\n\tinputBuf.push(line);\n}).on('close', () => {\n\tmain();\n});\n", "positive_code": [{"source_code": "var n=readline();\nvar a=readline().split(' ');\na=a.slice(0,n);\nvar cnt= [];\ncnt.length=2;\nfor(var k=0; k<2; k++){\n cnt[k] = [];\n cnt[k].length=(1<<20)+3;\n cnt[k].fill(0);\n}\n\ncnt[1][0]=1;\nvar res=0;\nvar x=0;\nfor(var i=0; i 0 && r > mid) {\r\n res.push(l--, r--);\r\n }\r\n if (n & 1) res.push(1);\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "var numOfCases = Number(readline());\r\n \r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var l1 = Number(readline());\r\n \r\n var result = process(l1);\r\n print(result);\r\n}\r\n \r\nfunction process(max) {\r\n var perm = [];\r\n var next = Math.floor(max / 2 + 1);\r\n \r\n for (var i = 0; i < max; i++) {\r\n var numToInsert = i + 1;\r\n if (numToInsert < next) {\r\n perm[(i * 2) + 1] = numToInsert;\r\n } else {\r\n perm[(numToInsert-next) * 2] = numToInsert;\r\n }\r\n }\r\n \r\n return perm.join(' ');\r\n}\r\n"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var k = +readline();\r\n var ans = Math.floor(k / 2) + 1;\r\n var temp = [];\r\n for(var j = 0, jj = 1; j < k; j++) {\r\n if(j % 2 === 0) {\r\n temp.push(ans);\r\n ans++;\r\n continue;\r\n }\r\n temp.push(jj);\r\n jj++;\r\n }\r\n print(temp.join(' '));\r\n}"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j < Math.floor(k / 2); j++){\n s += (a + j) + ' ' + Number(j + 1) + ' '\n }\n if(k % 2 == 1){\n s += k;\n }\n console.log(s)\n }\n});"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n let ans='';\r\n let a=new Array(n);\r\n let x;\r\n if(n&1) x=Math.floor((n+1)/2);\r\n else x=Math.floor((n+2)/2);\r\n let z=x;\r\n for(let i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t * 2; i++){\n var n = lines[i];\n var a = Math.floor(n / 2) + 1;\n var ans = '';\n for(j = 0; j < Math.floor(n / 2); j++){\n ans += (a + j) + ' ' + (j + 1) + ' ';\n }\n if(n % 2 == 1){\n ans += n;\n }\n console.log(ans);\n }\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(max) {\r\n const perm = [];\r\n const next = Math.floor(max / 2 + 1);\r\n \r\n for (let i = 0; i < max; i++) {\r\n const numToInsert = i + 1;\r\n if (numToInsert < next) {\r\n perm[(i * 2) + 1] = numToInsert;\r\n } else {\r\n perm[(numToInsert-next) * 2] = numToInsert;\r\n }\r\n }\r\n \r\n cl(perm.join(' '));\r\n}\r\n\r\nfunction main() {\r\n const numOfCases = rlsn();\r\n \r\n for (let testCase = 0; testCase < numOfCases; testCase++) {\r\n const l1 = rlsn();\r\n \r\n solve(l1);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inStr = '';\r\nlet curLine = 0;\r\nconst cl = console.log;\r\n\r\nprocess.stdin.on('data', function(inStdin) {inStr += inStdin;});\r\nprocess.stdin.on('end', function() {inStr = inStr.split('\\n');main();});\r\n\r\nfunction readline() {return inStr[curLine++].replace(/\\s+$/g, '');}\r\nfunction rlsn() {return Number(readline());}\r\nfunction rlarrstr() {return readline().split(' ');}\r\nfunction rlarrn() {return rlarrstr().map(Number);}\r\nfunction makeFreqMap(str) {const m={};for (let char of str) m[char]=m[char]+1||1;return m;}\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const r = []\n if (n & 1) {\n // for (let i = 0; i < (n - 1) / 2; i++) {\n for (let i = (n - 1) / 2 - 1; i >= 0; i--) {\n r.push(i + 1, i + (n + 1) / 2)\n }\n // r.push((n + 1) / 2)\n r.push(n)\n } else {\n // for (let i = 0; i < n / 2; i++) {\n for (let i = n / 2 - 1; i >= 0; i--) {\n r.push(i + 1, i + n / 2 + 1)\n }\n }\n return r.join(' ')\n}\n"}], "negative_code": [{"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j < Math.floor(k / 2); j++){\n s += (a + j) + ' ' + Number(j + 1) + ' '\n }\n if(n % 2 == 1){\n s += k;\n }\n console.log(s)\n }\n});\n\n"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j <= Math.floor(k / 2); j++){\n s += (a + j) + ' ' + Number(j + 1) + ' '\n }\n \n console.log(s)\n }\n});\n\n"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j < Math.floor(k / 2); j++){\n s += (a + j) + ' ' + Number(j + 1) + ' '\n }\n \n console.log(s)\n }\n});\n\n"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j < Math.floor(k / 2); j++){\n s += (a + j) + ' ' + j + 1 + ' '\n }\n \n console.log(s)\n }\n});\n\n"}, {"source_code": "let ryan = '';//.map(saer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(i = 1; i <= n * 2; i++){\n var k = lines[i], a = Math.floor(k / 2) + 1, s = ''\n for(j = 0; j < Math.floor(k / 2); j++){\n s += (a + j) + ' ' + j + ' '\n }\n \n console.log(s)\n }\n});\n\n"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n e = ''\n for(l = 1; l <= k; l++){\n e += l + ' '\n }\n console.log(e)\n }\n \n\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j], e = ''\n for(j = 1; j <= k; j++){\n e += j + ' '\n }\n console.log(e)\n }\n \n\n});"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n let ans='';\r\n let a=new Array(n);\r\n let x=Math.floor((n+1)/2);\r\n let z=x;\r\n for(let i=0;i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var a = lines[0].split(' ').map(Number);\n var months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n var n = a[0], m = a[1];\n if(months[n] == 31){\n console.log(m > 5 ? 6 : 5);\n }else if(months[n] == 30){\n console.log(m == 7 ? 6 : 5);\n }else{\n console.log(m == 1 ? 4 : 5);\n }\n});"}, {"source_code": "var numOfCases = Number(readline());\r\n \r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var l1 = Number(readline());\r\n \r\n var result = process(l1);\r\n print(result);\r\n}\r\n \r\nfunction process(max) {\r\n var perm = [];\r\n var next = Math.ceil(max / 2 + 1);\r\n \r\n for (var i = 0; i < max; i++) {\r\n var numToInsert = i + 1;\r\n if (numToInsert < next) {\r\n perm[i * 2] = numToInsert;\r\n } else {\r\n perm[(numToInsert - next) * 2 + 1] = numToInsert;\r\n }\r\n }\r\n \r\n return perm.join(' ');\r\n}\r\n"}, {"source_code": "var numOfCases = Number(readline());\r\n \r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var l1 = Number(readline());\r\n \r\n var result = process(l1);\r\n print(result);\r\n}\r\n \r\nfunction process(max) {\r\n const perm = [];\r\n var l = 0, r = max - 1;\r\n \r\n var midIndex = Math.floor(max / 2);\r\n perm[midIndex] = 1;\r\n \r\n var ml = midIndex - 1,\r\n mr = midIndex + 1;\r\n \r\n for (var i = 2; i <= max; i++) {\r\n if ((i + 4) % 4 === 2) {\r\n perm[l] = i;\r\n l++;\r\n } else if ((i + 4) % 4 === 3) {\r\n perm[r] = i;\r\n r--;\r\n } else if ((i + 4) % 4 === 0) {\r\n perm[ml] = i;\r\n ml--;\r\n } else if ((i + 4) % 4 === 1) {\r\n perm[mr] = i;\r\n mr++;\r\n }\r\n }\r\n \r\n return perm.join(' ');\r\n}"}, {"source_code": "var numOfCases = Number(readline());\r\n \r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var l1 = Number(readline());\r\n \r\n var result = process(l1);\r\n print(result);\r\n}\r\n \r\nfunction process(max) {\r\n const perm = [];\r\n var l = 0, r = max - 1;\r\n \r\n var midIndex = Math.floor(max / 2);\r\n perm[midIndex] = 1;\r\n \r\n var ml = midIndex - 1,\r\n mr = midIndex + 1;\r\n \r\n for (var i = 2; i <= max; i++) {\r\n if ((i + 4) % 4 === 2) {\r\n perm[l] = i;\r\n l++;\r\n } else if ((i + 4) % 4 === 3) {\r\n perm[r] = i;\r\n r--;\r\n } else if ((i + 4) % 4 === 0) {\r\n perm[ml] = i;\r\n ml--;\r\n } else if ((i + 4) % 4 === 1) {\r\n perm[mr] = i;\r\n mr++;\r\n }\r\n }\r\n print(perm)\r\n \r\n return perm.join(' ');\r\n}"}], "src_uid": "0d5f4320fc2c7662d21e09a51baf21db"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst INF = Infinity;\r\nlet n;\r\nlet a;\r\nfunction caseI() {\r\n const b = [...a];\r\n b.sort((x, y) => x - y);\r\n return Math.ceil(b[0] / 2) + Math.ceil(b[1] / 2);\r\n}\r\nfunction caseII() {\r\n let best = INF;\r\n for (let i = 1; i + 1 < n; i++) {\r\n let l = a[i - 1];\r\n let r = a[i + 1];\r\n if (l < r) {\r\n [l, r] = [r, l];\r\n }\r\n let t = r;\r\n let diff = l - r;\r\n t += Math.ceil(diff / 2);\r\n best = Math.min(best, t);\r\n }\r\n return best;\r\n}\r\nfunction caseIII() {\r\n let best = INF;\r\n for (let i = 1; i < n; i++) {\r\n let l = a[i - 1];\r\n let r = a[i];\r\n if (l < r) {\r\n [l, r] = [r, l];\r\n }\r\n if (r + r <= l) {\r\n let t = Math.ceil(l / 2);\r\n best = Math.min(best, t);\r\n continue;\r\n }\r\n let t = Math.ceil((l + r) / 3);\r\n best = Math.min(best, t);\r\n }\r\n return best;\r\n}\r\nfunction main() {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n let ans = INF;\r\n ans = Math.min(ans, caseI());\r\n ans = Math.min(ans, caseII());\r\n ans = Math.min(ans, caseIII());\r\n printf(\"%d\\n\", ans);\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sorted = arr.slice().sort((a, b) => a - b)\n const first = sorted[0]\n const second = sorted[1]\n //\n const i1 = []\n const i2 = []\n arr.forEach((x, i) => {\n if (x === first) i1.push(i)\n if (x === second) i2.push(i)\n })\n //\n let min = Infinity\n let ps\n if (first === second) {\n // same\n for (let i = 1; i < i1.length; i++) {\n if (i1[i] - i1[i - 1] < min) {\n min = i1[i] - i1[i - 1]\n ps = [i1[i - 1], i1[i]]\n }\n }\n } else {\n // diff\n for (let i = 0; i < i2.length; i++) {\n if (Math.abs(i2[i] - i1[0]) < min) {\n min = Math.abs(i2[i] - i1[0])\n ps = [i1[0], i2[i]]\n }\n }\n }\n //\n let a = arr[ps[0]]\n let b = arr[ps[1]]\n// return\n let ans = helper(min, a, b)\n// console.log(a, b, min, ans)\n for (let i = 1; i < arr.length; i++) {\n // console.log(ans, i)\n ans = Math.min(ans, helper(1, arr[i - 1], arr[i]))\n }\n for (let i = 2; i < arr.length; i++) {\n ans = Math.min(ans, helper(2, arr[i - 2], arr[i]))\n }\n return ans\n}\nfunction helper(min, a, b) {\n if (min === 2) {\n // x . x\n if (a > b) {\n [a, b] = [b, a]\n }\n // a <= b\n return a + Math.ceil((b - a) / 2)\n } else if (min === 1) {\n // x x\n if (a > b) {\n [a, b] = [b, a]\n }\n let ans = 0, now\n // a <= b\n now = Math.min(a, b - a)\n a -= now\n b -= 2 * now\n ans += now\n // ==\n now = Math.floor(a / 3)\n a = a - 3 * now\n b = b - 3 * now\n ans += now * 2\n //\n now = Math.floor(b / 2)\n a -= now\n if (a < 0) a = 0\n b -= 2 * now\n ans += now\n //\n if (a === 2 && b === 2) {\n return ans + 2\n } else if (a === 0 && b === 0) {\n return ans\n } else {\n return ans + 1\n }\n } else {\n // x . . x\n return Math.ceil(a / 2) + Math.ceil(b / 2)\n }\n}\n"}, {"source_code": "var n = parseInt(readline());\r\n var a = readline().split(' ').map(x=>parseInt(x));\r\n \r\n var minVal = Math.min(...a);\r\n var b = [...a];\r\n b.splice(b.indexOf(minVal), 1);\r\n var minVal2 = Math.min(...b);\r\n\r\n var minShots = Math.ceil(minVal/2) + Math.ceil(minVal2/2);\r\n\r\n for (var i = 0; i < n-2; i++) {\r\n var shots = Math.ceil((a[i] + a[i+2]) / 2);\r\n minShots = Math.min(shots, minShots);\r\n }\r\n\r\n for (var i = 0; i < n-1; i++) {\r\n var min = Math.min(a[i], a[i+1]);\r\n var max = Math.max(a[i], a[i+1]);\r\n var shots;\r\n\r\n if (2 * min <= max) {\r\n shots = Math.ceil(max/2);\r\n } else {\r\n shots = Math.ceil((max+min) / 3);\r\n }\r\n minShots = Math.min(shots, minShots);\r\n }\r\n \r\n print(minShots);"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, aaa)=>{\n if (n === 1) return Math.ceil(a[0] / 2);\n let a = [...aaa];\n let sorted = aaa.sort((x, y) => x - y);\n let result = Math.ceil(sorted[0] / 2) + Math.ceil(sorted[1] / 2);\n for (let i = 1; i < n; i++) {\n let max = Math.max(a[i], a[i - 1]);\n let min = Math.min(a[i], a[i - 1]);\n\n if (2 * min <= max) {\n result = Math.min(result, Math.ceil(max / 2));\n continue;\n }\n\n let diff = max - min;\n let localres = diff;\n\n let x = max - 2 * diff;\n let y = min - diff;\n localres += Math.ceil((x + y) / 3);\n result = Math.min(result, localres);\n }\n\n for (let i = 2; i < n; i++) {\n let xsteps = div(a[i], 2);\n let ysteps = div(a[i - 2], 2);\n let x = a[i] % 2;\n let y = a[i - 2] % 2;\n let localres = xsteps + ysteps;\n if (x === 1 || y === 1) {\n localres += 1;\n }\n result = Math.min(result, localres);\n }\n\n return result;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, nums) {\r\n let res = Infinity;\r\n {\r\n const [a1, a2] = nums.map(num => Math.ceil(num / 2)).sort((a, b) => a - b);\r\n res = a1 + a2;\r\n }\r\n {\r\n for (let i = 1; i < n; i++) {\r\n let a = nums[i - 1],\r\n b = nums[i];\r\n if (b < a) [a, b] = [b, a];\r\n if (a <= b / 2) {\r\n res = Math.min(res, Math.ceil(b / 2));\r\n } else {\r\n const x = Math.ceil((2 * b - a) / 3),\r\n y = Math.ceil((a - x) / 2);\r\n res = Math.min(res, x + y);\r\n }\r\n if (i < n - 1) {\r\n let a = nums[i - 1],\r\n b = nums[i + 1];\r\n if (b < a) [a, b] = [b, a];\r\n res = Math.min(res, Math.ceil(Math.max(a, b)));\r\n res = Math.min(res, a + Math.ceil((b - a) / 2));\r\n }\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (n, A)=>{\n let ans;\n // try two minimums\n let sA = A.slice().sort((a, b)=>a-b);\n ans = Math.ceil(sA[0]/2)+Math.ceil(sA[1]/2);\n let check = (a, b)=>{ // bb)\n return check(b, a);\n L({a, b})\n if (b>100){\n let third = Math.floor(b/3);\n return third+check(a-third, b-third*2);\n }\n while (a>0 || b>0){\n if (a>b){\n a-=2;\n b--;\n } else {\n b-=2;\n a--;\n }\n ans++;\n }\n return ans;\n };\n let checkTripple = (a, b)=>{\n if (a>b)\n return checkTripple(b, a);\n let diff = b-a;\n let rm = Math.ceil(diff/2);\n b -= rm*2;\n return rm + Math.max(a, b);\n }\n // try all adjastent pairs\n for (let i=0; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, aaa)=>{\n if (n === 1) return Math.ceil(a[0] / 2);\n let a = [...aaa];\n let sorted = aaa.sort((x, y) => x - y);\n // console.log('DEBUG a', a);\n let result = Math.ceil(sorted[0] / 2) + Math.ceil(sorted[1] / 2);\n // console.log('DEBUG result', result);\n for (let i = 1; i < n; i++) {\n let minTogether = Math.min(div(a[i], 3), div(a[i - 1], 3));\n let x = a[i] - minTogether * 3;\n let y = a[i - 1] - minTogether * 3;\n if (x > y) {\n let tmp = x;\n x = y;\n y = tmp;\n }\n // console.log(`DEBUG pairs i ${i} x ${x} y ${y}`);\n let localres = minTogether * 2;\n if (x === 1 || x === 0) {\n localres += Math.ceil(y / 2);\n } else if (x === 2) {\n let ysteps = Math.ceil(y / 2);\n if (ysteps < 2) ysteps++;\n localres += ysteps;\n }\n // console.log(`DEBUG pairs i ${i} localres`, localres);\n result = Math.min(result, localres);\n\n // option 2\n let max = Math.max(a[i], a[i - 1]);\n let min = Math.min(a[i], a[i - 1]);\n let maxsteps = div(max, 2);\n max = max % 2;\n min -= maxsteps;\n let alternateres = maxsteps;\n if (min > 0) {\n alternateres += Math.ceil(min / 2);\n } else if (max > 0) {\n alternateres++;\n }\n // console.log(`DEBUG pairs i ${i} alternateres`, alternateres);\n result = Math.min(result, alternateres);\n }\n\n for (let i = 2; i < n; i++) {\n let xsteps = div(a[i], 2);\n let ysteps = div(a[i - 2], 2);\n let x = a[i] % 2;\n let y = a[i - 2] % 2;\n let localres = xsteps + ysteps;\n if (x === 1 || y === 1) {\n localres += 1;\n }\n // console.log(`DEBUG triplets i ${i} localres`, localres);\n result = Math.min(result, localres);\n }\n\n return result;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, aaa)=>{\n if (n === 1) return Math.ceil(a[0] / 2);\n let a = [...aaa];\n let sorted = aaa.sort((x, y) => x - y);\n // console.log('DEBUG a', a);\n let result = Math.ceil(sorted[0] / 2) + Math.ceil(sorted[1] / 2);\n // console.log('DEBUG result', result);\n for (let i = 1; i < n; i++) {\n let minTogether = Math.min(div(a[i], 3), div(a[i - 1], 3));\n let x = a[i] - minTogether * 3;\n let y = a[i - 1] - minTogether * 3;\n if (x > y) {\n let tmp = x;\n x = y;\n y = tmp;\n }\n // console.log(`DEBUG pairs i ${i} x ${x} y ${y}`);\n let localres = minTogether * 2;\n if (x === 1 || x === 0) {\n localres += Math.ceil(y / 2);\n } else if (x === 2) {\n let ysteps = Math.ceil(y / 2);\n if (ysteps < 2) ysteps++;\n localres += ysteps;\n }\n // console.log(`DEBUG pairs i ${i} localres`, localres);\n result = Math.min(result, localres);\n\n // option 2\n let max = Math.max(a[i], a[i - 1]);\n let min = Math.min(a[i], a[i - 1]);\n let maxsteps = div(max, 2);\n max = max % 2;\n min -= maxsteps;\n let alternateres = maxsteps;\n if (min > 0) {\n alternateres += Math.ceil(min / 2);\n } else if (max > 0) {\n alternateres++;\n }\n // console.log(`DEBUG pairs i ${i} alternateres`, alternateres);\n result = Math.min(result, alternateres);\n }\n\n for (let i = 2; i < n; i++) {\n let xsteps = div(a[i], 2);\n let ysteps = div(a[i - 2], 2);\n let x = a[i] % 2;\n let y = a[i - 2] % 2;\n let localres = xsteps + ysteps;\n if (x === 1 || y === 1) {\n localres += 1;\n }\n // console.log(`DEBUG triplets i ${i} localres`, localres);\n result = Math.min(result, localres);\n }\n\n return result;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, aaa)=>{\n if (n === 1) return Math.ceil(a[0] / 2);\n let a = [...aaa];\n let sorted = aaa.sort((x, y) => x - y);\n // console.log('DEBUG a', a);\n let result = Math.ceil(sorted[0] / 2) + Math.ceil(sorted[1] / 2);\n // console.log('DEBUG result', result);\n for (let i = 1; i < n; i++) {\n let minTogether = Math.min(div(a[i], 3), div(a[i - 1], 3));\n let x = a[i] - minTogether * 3;\n let y = a[i - 1] - minTogether * 3;\n if (x > y) {\n let tmp = x;\n x = y;\n y = tmp;\n }\n let localres = minTogether * 2;\n if (x === 1 || x === 0) {\n localres += Math.ceil(y / 2);\n } else if (x === 2) {\n let ysteps = Math.ceil(y / 2);\n if (ysteps < 2) ysteps++;\n localres += ysteps;\n }\n // console.log(`DEBUG pairs i ${i} localres`, localres);\n result = Math.min(result, localres);\n }\n\n for (let i = 2; i < n; i++) {\n let xsteps = div(a[i], 2);\n let ysteps = div(a[i - 2], 2);\n let x = a[i] % 2;\n let y = a[i - 2] % 2;\n let localres = xsteps + ysteps;\n if (x === 1 || y === 1) {\n localres += 1;\n }\n // console.log(`DEBUG triplets i ${i} localres`, localres);\n result = Math.min(result, localres);\n }\n\n return result;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, aaa)=>{\n if (n === 1) return Math.ceil(a[0] / 2);\n let a = [...aaa];\n let sorted = aaa.sort((x, y) => x - y);\n // console.log('DEBUG a', a);\n let result = Math.ceil(sorted[0] / 2) + Math.ceil(sorted[1] / 2);\n for (let i = 1; i < n; i++) {\n let minTogether = Math.min(div(a[i], 3), div(a[i - 1], 3));\n let x = a[i] - minTogether * 3;\n let y = a[i - 1] - minTogether * 3;\n if (x > y) {\n let tmp = x;\n x = y;\n y = tmp;\n }\n let localres = minTogether * 2;\n if (x === 1) {\n localres += Math.ceil(y / 2);\n } else if (x === 2) {\n let ysteps = Math.ceil(y / 2);\n if (ysteps < 2) ysteps++;\n localres += ysteps;\n }\n result = Math.min(result, localres);\n }\n\n for (let i = 2; i < n; i++) {\n let xsteps = div(a[i], 2);\n let ysteps = div(a[i - 2], 2);\n let x = a[i] % 2;\n let y = a[i - 2] % 2;\n let localres = xsteps + ysteps;\n if (x === 1 || y === 1) {\n localres += 1;\n }\n result = Math.min(result, localres);\n }\n\n return result;\n};\n\nfunction main() {\n // let T = +readline();\n // for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n // }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, nums) {\r\n let res = Infinity;\r\n {\r\n const [a1, a2] = nums.map(num => Math.ceil(num / 2)).sort((a, b) => a - b);\r\n res = a1 + a2;\r\n }\r\n {\r\n for (let i = 1; i < n; i++) {\r\n let a = nums[i - 1],\r\n b = nums[i];\r\n if (b < a) [a, b] = [b, a];\r\n if (a <= b / 2) {\r\n res = Math.min(res, Math.ceil(b / 2));\r\n } else {\r\n const x = Math.ceil((2 * b - a) / 3),\r\n y = Math.ceil((a - x) / 2);\r\n res = Math.min(res, x + y);\r\n }\r\n if (i < n - 1) {\r\n res = Math.min(res, Math.ceil(Math.max(nums[i - 1], nums[i + 1])));\r\n }\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();"}, {"source_code": "'use strict';\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst lines = []\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (n, A)=>{\n let ans;\n // try two minimums\n let sA = A.slice().sort((a, b)=>a-b);\n ans = Math.ceil(sA[0]/2)+Math.ceil(sA[1]/2);\n let check = (a, b)=>{ // b100){\n let third = Math.floor(b/3);\n return third+check(a-third, b-third*2);\n }\n while (a>0 || b>0){\n if (a>b){\n a-=2;\n b--;\n } else {\n b-=2;\n a--;\n }\n ans++;\n }\n return ans;\n };\n let checkTripple = (a, b)=>{\n if (a>b)\n return checkTripple(b, a);\n let diff = b-a;\n let rm = Math.ceil(diff/2);\n b -= rm*2;\n return rm + Math.max(a, b);\n }\n // try all adjastent pairs\n for (let i=0; i {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nconst pcalc = function(){\n print(calc.apply(null, arguments)); }\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\n// SOLUTION\n \nconst calc = (n, A)=>{\n let ans;\n // try two minimums\n let sA = A.slice().sort((a, b)=>a-b);\n ans = Math.ceil(sA[0]/2)+Math.ceil(sA[1]/2);\n let check = (a, b)=>{ // b100){\n let third = Math.floor(b/3);\n return third+check(a-third, b-third*2);\n }\n while (a>0 || b>0){\n if (a>b){\n a-=2;\n b--;\n } else {\n b-=2;\n a--;\n }\n ans++;\n }\n return ans;\n };\n // try all adjastent pairs\n for (let i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sorted = arr.slice().sort((a, b) => a - b)\n const first = sorted[0]\n const second = sorted[1]\n //\n const i1 = []\n const i2 = []\n arr.forEach((x, i) => {\n if (x === first) i1.push(i)\n if (x === second) i2.push(i)\n })\n //\n let min = Infinity\n let ps\n if (first === second) {\n // same\n for (let i = 1; i < i1.length; i++) {\n if (i1[i] - i1[i - 1] < min) {\n min = i1[i] - i1[i - 1]\n ps = [i1[i - 1], i1[i]]\n }\n }\n } else {\n // diff\n for (let i = 0; i < i2.length; i++) {\n if (Math.abs(i2[i] - i1[0]) < min) {\n min = Math.abs(i2[i] - i1[0])\n ps = [i1[0], i2[i]]\n }\n }\n }\n //\n let a = arr[ps[0]]\n let b = arr[ps[1]]\n// return\n let ans = helper(min, a, b)\n// console.log(a, b, min, ans)\n for (let i = 1; i < arr.length; i++) {\n // console.log(ans, i)\n ans = Math.min(ans, helper(1, arr[i - 1], arr[i]))\n }\n for (let i = 2; i < arr.length; i++) {\n ans = Math.min(ans, helper(2, arr[i - 2], arr[i]))\n }\n return ans\n}\nfunction helper(min, a, b) {\n if (min === 2) {\n // x . x\n if (a > b) {\n [a, b] = [b, a]\n }\n // a <= b\n return a + Math.ceil((b - a) / 2)\n } else if (min === 1) {\n // x x\n if (a > b) {\n [a, b] = [b, a]\n }\n // a <= b\n let ans = Math.floor(a / 3)\n a = a - 3 * ans\n b = b - 3 * ans\n ans *= 2\n //\n let bb = Math.floor(b / 2)\n a -= bb\n if (a < 0) a = 0\n b -= 2 * bb\n ans += bb\n //\n if (a === 2 && b === 2) {\n return ans + 2\n } else if (a === 0 && b === 0) {\n return ans\n } else {\n return ans + 1\n }\n } else {\n // x . . x\n return Math.ceil(a / 2) + Math.ceil(b / 2)\n }\n}\n"}], "src_uid": "f4a7c573ca0c129f241b415577a76ac2"} {"source_code": "var input = readline().split(' ').map(Number), n = input[0];\nvar snow = [];\nvar check = [];\nvar comps = 0;\nvar doneFlag = false;\nwhile (n--) {\n input = readline().split(' ').map(Number);\n var a = input[0];\n var b = input[1]; \n check[snow.length] = false;\n snow.push([a,b]);\n}\n\nvar visited = [];\nvisited.push(0);\n\nwhile (!doneFlag) {\n \n while (visited.length) {\n var idx = visited.splice(0,1)[0];\n var element = snow[idx];\n check[idx] = true;\n for (var i = 0; i < snow.length; i++) {\n if ((snow[i][0] == element[0] || snow[i][1] == element[1]) && !check[i]) visited.push(i);\n }\n }\n comps++;\n \n doneFlag = true;\n for (var i = 0; i < snow.length; i++) {\n if (check[i] === false) { \n doneFlag = false; \n visited.push(i); \n break;\n }\n }\n}\n\nwrite(comps - 1);", "positive_code": [{"source_code": "var n = readline();\nn = parseInt(n, 10);\n\nvar visited = [];\nfor(var i = 0; i < n; i++) {\n visited.push(false);\n}\n \nvar x = [];\nvar y = [];\n \nfor(var i = 0; i < n; i++) {\n var input = readline().split(' ');\n _x = parseInt(input[0], 10);\n _y = parseInt(input[1], 10);\n x.push(_x);\n y.push(_y);\n}\n\nfunction adjacent(index) {\n if (!visited[index]) {\n visited[index] = true;\n for(var i = 0; i < n; i++) {\n if (x[index] == x[i] || y[index] == y[i]) {\n adjacent(i);\n }\n }\n }\n}\n\nvar drift = -1;\nfor(var i = 0; i < n; i++) {\n if (!visited[i]) {\n drift += 1;\n adjacent(i);\n }\n}\n\nprint(drift);"}, {"source_code": "(function(){print(function(e){var t=[];while(e--){t.push(function(){var e=readline().split(\" \").map(Number);return{x:e[0],y:e[1],v:1e10}}())}e=t.length;(function(){var e=true,n=1;while(e){e=false;for(var r=0,i=t.length;r 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar n = parseInt(readline());\nvar arr = [];\nfor (var i = 0; i < n; i++) {\n var _readline$split$map = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n x = _readline$split$map2[0],\n y = _readline$split$map2[1];\n\n arr.push({ x: x, y: y, visited: false });\n}\n\nvar amountOfGroups = 0;\n\n// \u0411\u0435\u0436\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u043b\u0435\u0442\u043a\u0430\u043c.\nfor (var _i = 0; _i < n; _i++) {\n if (arr[_i].visited) {\n continue;\n }\n // \u0415\u0441\u043b\u0438 \u043a\u043b\u0435\u043d\u043a\u0430 \u043d\u0435 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0430 \u0431\u0435\u0440\u0435\u043c \u0432 \u0440\u0430\u0431\u043e\u0442\u0443\n // \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0440\u0443\u043f\u043f \u043d\u0430 1\n amountOfGroups++;\n var q = new Queue();\n q.enqueue(_i);\n\n while (!q.isEmpty()) {\n var currentCell = q.dequeue();\n for (var j = 0; j < n; j++) {\n if (!arr[j].visited && (arr[currentCell].x === arr[j].x || arr[currentCell].y === arr[j].y)) {\n arr[j].visited = true;\n q.enqueue(j);\n }\n }\n }\n}\n\nwrite(amountOfGroups - 1);\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "var lines = parseInt(readline());\nvar points = [];\nfor (var i = 0; i < lines; i++) {\n var text = readline();\n points.push(text.split(' ')); \n}\n\nprint(findComponents(points));\n\nfunction findComponents(data) {\n \tvar G = createGraph(data);\n \t\n \tvar count = 0;\n \tvar queue = [];\n\n \tG.forEach(function(node, i) {\n \t\tif (!node.selected) {\n \t\t\tif (i > 0) count++;\n \t\t\tqueue.push(node);\n \t\t\tBFS();\n \t\t}\n \t});\n\n\n\n \treturn count;\n\n\n\n \tfunction BFS() {\n \t\t\n \t if (!queue.length) return;\n \t \n \t var node = queue.pop();\n \t node.selected = true;\n \t node.edges.forEach(function(item) {\n \t \t\tif (!G[item].selected) queue.push(G[item]);\n \t })\n \t \n \t return BFS();\n \t}\n\n\n \tfunction createGraph(data) {\n \t\tvar columns = {};\n \t\tvar rows = {};\n\n \t\tdata.forEach((point, i) => {\n \t\t\tif (!rows[point[0]]) rows[point[0]] = {};\n \t\t\trows[point[0]][i] = 1;\n \t\t\t\n \t\t\tif (!columns[point[1]]) columns[point[1]] = {};\n \t\t\tcolumns[point[1]][i] = 1;\n \t\t\t\n \t\t});\n\n \n\n \t\treturn data.map(function(point, i) {\n \t\t\tvar edges = Object.keys((rows[point[0]] || {})).concat(Object.keys(columns[point[1]] || {}));\n \t\t\treturn {id: i, edges: edges};\n \t\t \n \t\t});\n\n \t}\n}"}, {"source_code": "// author: Oscar Ramos\n\n/// Source Code\n// const input = require('competitive-programming-js').inputReader\n// const { forn, vector, range } = require('../utils/utils')\n// \n// const n = input.readNumber()\n// \n// const coords = []\n// forn(n, () => {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n// \n// const visited = vector(n, false)\n// \n// let ans = -1\n// \n// const dfs = i => {\n// if (!visited[i]) {\n// visited[i] = true\n// forn(n, (j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// dfs(j)\n// }\n// }))\n// }\n// }\n// \n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// }\n// dfs(i)\n// })\n// \n// console.log(ans)\n// \n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let s=-1;const p=t=>{a[t]||(a[t]=!0,n(i,n=>{f[t][0]!==f[n][0]&&f[t][1]!==f[n][1]||p(n)}))};n(i,n=>{a[n]||(s+=1),p(n)}),console.log(s)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction dsu(n){\n this.parent = new Array(n);\n for(let i = 0; i < n; i++)\n this.parent[i] = i;\n\n this.find = (x) => {\n if(this.parent[x] === x)\n return this.parent[x];\n\n return this.find(this.parent[x]);\n }\n\n this.union = (x,y) => {\n this.parent[this.find(x)] = this.find(y);\n }\n}\n\nfunction main(){\n let n = pi(readline());\n let mapX = new Array(1005);\n let mapY = new Array(1005);\n mapX.fill(-1);\n mapY.fill(-1);\n let uf = new dsu(n);\n\n for(let i = 0; i < n; i++){\n let [x,y] = ti(readline().split(' '));\n if(mapX[x] !== -1){\n uf.union(mapX[x], i);\n }else{\n mapX[x] = i;\n }\n\n if(mapY[y] !== -1){\n uf.union(mapY[y], i);\n }else{\n mapY[y] = i;\n }\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(uf.parent[i] === i)\n res += 1;\n \n console.log(res-1);\n}"}], "negative_code": [{"source_code": "// author: Oscar Ramos\n\n/// Source Code\n// const input = require('competitive-programming-js').inputReader\n// const { forn, vector, range } = require('../utils/utils')\n//\n// const n = input.readNumber()\n//\n// const coords = []\n// forn(n, () => {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n//\n// const visited = vector(n, false)\n//\n// let ans = -1\n//\n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// }\n// range(i, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// })\n//\n//\n// console.log(ans)\n//\n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1),o(n,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)})}),100===i&&530===f[0][0]&&(p-=1),28===i&&462===f[0][0]&&(p-=1),100===i&&594===f[0][0]&&(p-=1),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n//\n// const visited = vector(n, false)\n//\n// let ans = -1\n//\n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// visited[i] = true\n// range(i + 1, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// }\n// })\n//...\n//\n// console.log(ans)\n//\n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1,a[n]=!0,o(n+1,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)}))}),100===i&&530===f[0][0]&&(p-=1),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n//\n// const visited = vector(n, false)\n//\n// let ans = -1\n//\n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// visited[i] = true\n// range(i + 1, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// }\n// })\n//...\n//\n// console.log(ans)\n//\n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1,a[n]=!0,o(n+1,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)}))}),100===i&&530===f[0][0]&&(p-=1),28===i&&462===f[0][0]&&(p-=1),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n// \n// const visited = vector(n, false)\n// \n// let ans = -1\n// \n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// visited[i] = true\n// range(i + 1, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// }\n// })\n// \n// console.log(ans)\n// \n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1,a[n]=!0,o(n+1,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)}))}),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n// \n// const visited = vector(n, false)\n// \n// let ans = -1\n// \n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// }\n// range(i, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// })\n// \n// console.log(ans)\n// \n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1),o(n,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)})}),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n// const [x, y] = input.readNumberArray()\n// coords.push([x, y])\n// })\n//\n// const visited = vector(n, false)\n//\n// let ans = -1\n//\n// forn(n, i => {\n// if (!visited[i]) {\n// ans += 1\n// range(i, n).map(j => {\n// if (coords[i][0] === coords[j][0] ||\n// coords[i][1] === coords[j][1]) {\n// visited[j] = true\n// }\n// })\n// }\n// })\n//\n//\n// console.log(ans)\n//\n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let p=-1;n(i,n=>{a[n]||(p+=1,o(n,i).map(t=>{f[n][0]!==f[t][0]&&f[n][1]!==f[t][1]||(a[t]=!0)}))}),100===i&&530===f[0][0]&&(p-=1),28===i&&462===f[0][0]&&(p-=1),100===i&&594===f[0][0]&&(p-=1),console.log(p)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction dsu(n){\n this.parent = new Array(n);\n for(let i = 0; i < n; i++)\n this.parent[i] = i;\n\n this.find = (x) => {\n if(this.parent[x] === x)\n return this.parent[x];\n\n return this.find(this.parent[x]);\n }\n\n this.union = (x,y) => {\n this.parent[this.find(x)] = this.find(y);\n }\n}\n\nfunction main(){\n let n = pi(readline());\n let mapX = new Array(1005);\n let mapY = new Array(1005);\n mapX.fill(-1);\n mapY.fill(-1);\n let uf = new dsu(n);\n\n for(let i = 0; i < n; i++){\n let [x,y] = ti(readline().split(' '));\n if(mapX[x] !== -1){\n uf.union(mapX[x], i);\n }else{\n mapX[x] = i;\n }\n\n if(mapY[y] !== -1){\n uf.union(mapY[y], i);\n }else{\n mapY[y] = i;\n }\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(uf.parent[i] === i)\n res += 1;\n \n console.log(Math.floor(res / 2));\n}"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar n = parseInt(readline());\nvar arr = [];\nfor (var i = 0; i < n; i++) {\n var _readline$split$map = readline().split(' ').map(function (v) {\n return parseInt(v);\n }),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n x = _readline$split$map2[0],\n y = _readline$split$map2[1];\n\n arr.push({ x: x, y: y, visited: false });\n}\n\nvar amountOfGroups = 0;\n\n// \u0411\u0435\u0436\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u043b\u0435\u0442\u043a\u0430\u043c.\nfor (var _i = 0; _i < n; _i++) {\n if (arr[_i].visited) {\n continue;\n }\n // \u0415\u0441\u043b\u0438 \u043a\u043b\u0435\u043d\u043a\u0430 \u043d\u0435 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0430 \u0431\u0435\u0440\u0435\u043c \u0432 \u0440\u0430\u0431\u043e\u0442\u0443\n // \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0440\u0443\u043f\u043f \u043d\u0430 1\n amountOfGroups++;\n for (var j = 0; j < n; j++) {\n if (arr[_i].x === arr[j].x || arr[_i].y === arr[j].y) {\n arr[j].visited = true;\n }\n }\n}\n\nwrite(amountOfGroups - 1);\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}], "src_uid": "cb4dbff31d967c3dab8fe0495eb871dc"} {"source_code": "function solve() {\n n = Number(read());\n var firstNotOne = n - 1;\n var found = false;\n\n readArray(function(elem, i) {\n if (elem !== '1' && !found) {\n firstNotOne = i;\n found = true;\n }\n });\n write((firstNotOne & 1) ? 'Second' : 'First');\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const n = Number(readLine())\n const as = readLine().split(/\\s/).map(Number)\n const i = as.findIndex(a => a > 1)\n console.log(i < 0 ? as.length % 2 === 0 ? 'Second' : 'First' : i % 2 === 0 ? 'First' : 'Second')\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(1000+10);\n \n for(let i = 0; i < a.length; i++)\n map[a[i]] = 1;\n\n let isFound = false;\n for(let i = 0; i < b.length; i++){\n if(map[b[i]] === 1){\n console.log('YES');\n console.log(1, b[i]);\n isFound = true;\n break;\n }\n }\n\n if(!isFound)\n console.log('NO');\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let turn = 0;\n for(let i = 0; i < a.length; i++){\n if(i === n-1){\n console.log(turn === 0 ? 'First' : 'Second');\n }\n else if(a[i] === 1){\n turn = turn === 0 ? 1 : 0;\n }else{\n console.log(turn === 0 ? 'First' : 'Second');\n break;\n }\n }\n }\n}"}], "negative_code": [{"source_code": "function solve() {\n n = Number(read());\n var firstNotOne = n - 1;\n var found = false;\n\n readArray(function(elem, i) {\n if (elem !== '1' && !found) {\n firstNotOne = i;\n found = true;\n }\n });\n write(firstNotOne + ' ' + ((firstNotOne & 1) ? 'Second' : 'First'));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n\n let map = new Array(1000+10);\n \n for(let i = 0; i < a.length; i++)\n map[a[i]] = 1;\n\n let isFound = false;\n for(let i = 0; i < b.length; i++){\n if(map[b[i]] === 1){\n console.log('YES');\n console.log(1, b[i]);\n isFound = true;\n break;\n }\n }\n\n if(!isFound)\n console.log('NO');\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n\n let turn = 0;\n for(let i = 0; i < a.length; i++){\n if(a[i] === 1){\n if(i === n-1){\n console.log(turn === 0 ? 'First' : 'Second');\n }\n else{\n turn = turn === 0 ? 1 : 0;\n }\n }else{\n if(i < n-1){\n if(i+1 === n-1){\n turn = turn;\n }else{\n if(a[i+1] === 1){\n turn = turn === 0 ? 1 : 0;\n }\n }\n }else{\n console.log(turn === 0 ? 'First' : 'Second');\n }\n }\n }\n }\n}"}], "src_uid": "0c9030689394ad4e126e5b8681f1535c"} {"source_code": "const n = Number(readline());\nconst arr = readline().split(\" \").map(x => Number(x));\nfindLength: for (var length = n;; length >>= 1)\n findBegin: for (var begin = 0; begin < n; begin = end) {\n var end = begin + length;\n for (var i = begin + 1; i < end; i++)\n if (arr[i - 1] > arr[i]) continue findBegin;\n print(length);\n break findLength;\n }\n", "positive_code": [{"source_code": "function issorted(arr){\n\tfor (i=1; i+arr[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction check(arr){\n\tif(issorted(arr)) {\n\t\treturn arr.length;\n\t} else {\n\t\treturn Math.max(check(arr.splice(arr.length/2)), check(arr));\n\t}\n}\n\nreadline();\nvar arr = readline().split(' ');\nprint(check(arr));"}, {"source_code": "let i = '';\n\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n \n var n = Number(lines[0]);\n var t = lines[1].split(' ');\n t = t.map(x=>Number(x));\n \n console.log(minSorted(t, 0, n-1)); \n})\n\nfunction minSorted(u, x, y) {\n var length = y-x+1;\n\tvar middle = x+length/2-1;\n\tif(isSorted(u,x,y)) return length;\n\telse return Math.max(minSorted(u,x,middle),minSorted(u,middle+1,y));\n}\n\nfunction isSorted(u, x, y) {\n for (var i=x+1;i<=y;i++) {\n if(u[i] i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL) ;\n\n let size=0;\n const thanosArray = lines[1].split(' ');\n thanosArray.map((v,i,a)=>a[i]=Number(v));\n const isSorted = arr => arr.every((v,i,a) => !i || a[i-1] <= v);\n const setSize =num=> size =(size>=num)?size:num;\n \n const splitArray=array=>{\n if (array.length==0)\n return;\n if (isSorted(array)){\n return setSize(array.length);\n }\n else {\n let half_length = Math.ceil(array.length / 2); \n let leftSide = array.splice(0,half_length);\n \n splitArray(leftSide);\n splitArray(array);\n }\n \n }\n \n splitArray(thanosArray)\n \n console.log(size)\n\n})"}, {"source_code": "var lengthA = readline();\nvar line2 = readline(); \nvar arr = line2.split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start < end) {\n if (arr[start] <= arr[start + 1])\n start++;\n else break;\n }\n\n return start === end ? true : false;\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const n = parseInt(arr[0])\n\n const a = arr[1].split(' ').map(a => parseInt(a))\n\n let ans = 1\n if(n == 1) {\n console.log(1)\n return\n }\n for(let i = 1; i < n; i++) {\n if(n >= 2 && a[i] >= a[i - 1] && (i + 1) % 2 == 0) ans = max(ans, 2)\n if(i >= 3 && n >= 4 && a[i] >= a[i - 1] && a[i - 1] >= a[i - 2] && a[i - 2] >= a[i - 3] && (i + 1) % 4 == 0) ans = max(ans, 4)\n if(i >= 7 && n >= 8 && a[i] >= a[i - 1] && a[i - 1] >= a[i - 2] && a[i - 2] >= a[i - 3] && a[i - 3] >= a[i - 4] && a[i - 4] >= a[i - 5] && a[i - 5] >= a[i - 6] && a[i - 6] >= a[i - 7] && (i + 1) % 8 == 0) ans = max(ans, 8)\n let flag = true\n if(i == 15) {\n for(let j = 1; j < n; j++) {\n if(a[j] < a[j - 1]) {\n flag = false\n break\n }\n }\n }\n if(flag && i == 15) {\n ans = 16\n }\n }\n wr(ans)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n main(lines);\n})\n\nfunction main(lines) {\n\tlet n = parseInt(lines[0]);\n\tlet a = lines[1].split(' ').map(v => {return parseInt(v)});\n\tconsole.log(helper(a, 0, n-1))\n\n}\n\nfunction helper(arr, a, b) {\n\n\t// console.log(`calling helper ${a} ${b}`);\n\tif(isArraySorted(arr, a, b)) {\n\t\treturn b-a+1;\n\t} else {\n\t\tlet mid = Math.floor((a+b)/2);\n\t\treturn Math.max(helper(arr, a, mid), helper(arr, mid+1, b));\n\t}\n\n}\nfunction isArraySorted(arr, a, b) {\n\n\tif(a === b) {\n\t\treturn true;\n\t}\n\tfor(let i = a+1; i<=b; i++) {\n\t\tif(arr[i] < arr[i-1]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n\n}\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst isSorted = (arr, l, r) => {\n for (let i = l; i < r; i += 1) {\n if (arr[i] > arr[i + 1]) {\n return false;\n }\n }\n\n return true;\n};\n\nconst getMaxArrayLength = (arr) => {\n const wrapper = (l, r) => {\n if (r <= l) {\n return 1;\n }\n\n if (isSorted(arr, l, r)) {\n return r - l + 1;\n }\n\n\n const half = Math.floor((r + l) / 2);\n\n const left = wrapper(l, half);\n const right = wrapper(half + 1, r);\n\n return Math.max(left, right);\n };\n\n return wrapper(0, arr.length - 1);\n};\n\nlet n = -1;\nreadline.on('line', (line) => {\n if (n === -1) {\n n = Number(line);\n } else {\n const numbers = line.split(' ').map(v => Number(v));\n console.log(getMaxArrayLength(numbers));\n }\n});\n"}, {"source_code": "readline();\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar sort = function(a) {\n var c = JSON.parse(JSON.stringify(a));\n var sorted = c.sort(function(a,b){\n return a - b;\n });\n \n if (JSON.stringify(a) == JSON.stringify(sorted)) {\n // the array is sorted\n return a.length;\n } else {\n // if the array is not sorted\n // do recursion\n var first = a.splice(0, a.length / 2);\n var firstAns = sort(first);\n var secondAns = sort(a);\n return Math.max(firstAns, secondAns);\n }\n \n}\nwrite(sort(a));\n"}, {"source_code": "readline();\nvar inputs = readline().split(\" \").map((x) => parseInt(x));\n\nfunction isSorted(array) {\n var limit = array.length - 1;\n for (var i = 0; i < limit; i++) {\n var current = array[i], next = array[i + 1];\n if (current > next) { return false; }\n }\n return true;\n \n}\n\nfunction thanosSort(start, end) {\n if(start === end) {\n return 1;\n }\n \n var sliceInputs = inputs.slice(start, end);\n if(isSorted(sliceInputs)) {\n return sliceInputs.length;\n }\n \n var mid = Math.floor((start+end)/ 2);\n return Math.max(thanosSort(start, mid), thanosSort(mid, end));\n}\n\nvar count = thanosSort(0, inputs.length);\nprint(count);"}, {"source_code": "(function() {\n var read = {\n number: function() {\n return +readline();\n },\n arr: function(divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function(divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber(' ');\n\n\n function isSorted(arr) {\n for(var i = 1; i < arr.length; i++) {\n if(arr[i] < arr[i - 1]) {\n return false;\n }\n }\n return true;\n }\n\n if(isSorted(a)) {\n print(a.length);\n return;\n }\n\n var res = 1;\n\n function getPol(arr) {\n var arr1 = arr.slice(0, arr.length/2);\n if(isSorted(arr1)) {\n res = arr1.length;\n return;\n }\n\n var arr2 = arr.slice(arr.length/2, arr.length);\n if(isSorted(arr2)) {\n res = arr2.length;\n return;\n }\n \n if(arr2.length > 1 ) {\n getPol(arr1);\n getPol(arr2);\n }\n }\n \n\n getPol(a);\n print(res);\n}());\n"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(function(item){return parseInt(item,10)});\n// var n= 8;\n// var arr = [11, 12, 1, 2, 13, 14, 3, 4];\nvar kol = 1, max = 1;\nfor(var i = 0; i < n; i++){\n var l = i+1, k = 0;\n while (l % 2 == 0){\n k++;\n l = Math.floor(l / 2);\n }\n l = Math.pow(2, k);\n while (l > 0){\n if (kol>= l){\n if(l > max){\n max = l;\n }\n }\n l = Math.floor(l /2);\n }\n if (arr[i] <= arr[i+1]){\n kol++;\n } else{\n kol = 1;\n }\n}\nprint(max);"}, {"source_code": "\t(function main(){\n\t\tfunction sort(n, arr){\n\t\t\tfunction assessmentSort(arr, begin, end){\n\t\t\t\tvar assessment = 0;\n\t\t\t\tvar count = 0;\n\t\t\t\tfor(i = begin+1; i < end; i++){\n\t\t\t\t\tcount++;\n\t\t\t\t\tif(arr[i-1]>arr[i]){\n\t\t\t\t\t\tassessment += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn assessment;\n\t\t\t}\n\t\t\tvar begin = 0; var end = n;\n\t\t\tvar assessment = assessmentSort(arr, begin, end);\n\t\t\twhile(assessment>0){\n\t\t\t\tvar separate = (end - begin)/2 + begin;\n\t\t\t\tvar assessment1 = assessmentSort(arr, begin, separate);\n\t\t\t\tvar assessment2 = assessmentSort(arr, separate, end);\n\t\t\t\tif(assessment1>assessment2){\n\t\t\t\t\tbegin = separate;\n\t\t\t\t\tassessment = assessment2\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tend = end - (end - begin)/2;\n\t\t\t\t\tassessment = assessment1\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebugger;\n\t\t\treturn end - begin;\n\t\t\t\n\t\t}\n\t\tprint(sort(readline()-0, (readline()).split(\" \").map(i=>i-0)))\n\t})();"}, {"source_code": " var sizeOfArray = readline();\n var arr = readline().split(\" \").map(string => parseInt(string)); \n \n print(thanosSort(arr));\n\n\nfunction thanosSort(arr) {\n if (isSorted(arr)) {\n return arr.length;\n }\n var newArr1 = arr.slice(0, arr.length / 2);\n var newArr2 = arr.slice(arr.length / 2);\n\n var sortedLength1 = thanosSort(newArr1);\n var sortedLength2 = thanosSort(newArr2);\n\n return Math.max(sortedLength1, sortedLength2);\n}\n\nfunction isSorted(arr) {\n for (var i = 0; i < arr.length - 1; i++) {\n if (arr[i] > arr[i + 1]) {\n return false;\n }\n }\n return true;\n}"}, {"source_code": "var len = parseInt(readline());\nvar mas = readline().split(' ');\n\nfunction isSorted(mas, len, subLen) {\n\n var k = len / subLen;\n for (var i = 0; i < k; i++) {\n\n var begin = i * subLen + 1;\n var end = (i + 1) * subLen;\n var sorted = true;\n for (var j = begin; j < end; j++) {\n if ( parseInt(mas[j-1]) > parseInt(mas[j]) ) {\n sorted = false;\n break;\n }\n }\n if (sorted) {\n return true;\n }\n\n }\n return false;\n}\n\nvar subLen = len;\nwhile (subLen > 0) {\n \n if (isSorted(mas, len, subLen)) {\n break;\n }\n subLen /= 2;\n}\nprint(subLen);"}, {"source_code": "const n = Number(readline());\nconst arr = readline().split(\" \").map(x => Number(x));\nfindLength: for (var length = n;; length >>= 1)\n findBegin: for (var begin = 0; begin < n; begin = end) {\n var end = begin + length;\n for (var i = begin + 1; i < end; i++)\n if (arr[i - 1] > arr[i]) continue findBegin;\n print(length);\n break findLength;\n }\n"}], "negative_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL) ;\n\n let size=0;\n const thanosArray = lines[1].split(' ');\n thanosArray.map((v,i,a)=>a[i]=Number(v));\n const isSorted = arr => arr.every((v,i,a) => !i || a[i-1] <= v);\n const setSize =num=> size =(size>=num)?size:num;\n \n const splitArray=array=>{\n if (array.length==0)\n return;\n if (isSorted(array))\n return setSize(array.length);\n \n else {\n let half_length = Math.ceil(array.length / 2); \n let leftSide = array.splice(0,half_length);\n let rightSide = array.splice(half_length,array.length);\n\n splitArray(leftSide);\n splitArray(rightSide);\n }\n \n }\n \n splitArray(thanosArray)\n \n console.log(size)\n\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n main(lines);\n})\n\nfunction main(lines) {\n\tlet n = parseInt(lines[0]);\n\tlet a = lines[1].split(' ').map(v => {return parseInt(v)});\n\tconsole.log(helper(a, 0, n-1))\n\n}\n\nfunction helper(arr, a, b) {\n\tif(isArraySorted(arr, a, b)) {\n\t\treturn b-a+1;\n\t} else {\n\t\tmid = (a+b)/2;\n\t\treturn Math.max(helper(arr, a, mid), helper(arr, mid+1, b));\n\t}\n\n}\nfunction isArraySorted(arr, a, b) {\n\n\tif(a === b) {\n\t\treturn true;\n\t}\n\tfor(let i = a+1; i<=b; i++) {\n\t\tif(arr[i] < arr[i-1]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n\n}\n\n"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(function(item){return parseInt(item,10)});\nvar kol = 1, max = 1;\nfor(var i = 0; i < n; i++){\n var l = i+1, k = 0;\n while (l > 1){\n k++;\n l /= 2;\n }\n l = Math.pow(2, k);\n if (kol>= l){\n if(l > max){\n max = l;\n }\n }\n if (arr[i] < arr[i+1]){\n kol++;\n } else{\n kol = 1;\n }\n}\nprint(max);"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(function(item){return parseInt(item,10)});\nvar kol = 1, max = 1;\nfor(var i = 0; i < n; i++){\n var l = i+1, k = 0;\n while (l > 1){\n k++;\n l /= 2;\n }\n l = Math.pow(2, k);\n if (kol>= l){\n if(l > max){\n max = l;\n }\n }\n if (arr[i] <= arr[i+1]){\n kol++;\n } else{\n kol = 1;\n }\n}\nprint(max);"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map((item) => {return parseInt(item,10)});\nvar kol = 1, max = 1;\nfor(var i = 0; i < n; i++){\n var l = i+1, k = 0;\n while (l > 1){\n k++;\n l /= 2;\n }\n l = Math.pow(2, k);\n if (kol>= l){\n if(l > max){\n max = l;\n }\n }\n if (arr[i] < arr[i+1]){\n kol++;\n } else{\n kol = 1;\n }\n}\nprint(max);"}, {"source_code": "\nfunction sort(n, arr){\n\tfunction assessmentSort(arr, begin, end){\n\t\tvar assessment = 0;\n\t\tfor(var i = begin+1; i < end; i++){\n\t\t\tif(arr[i-1]>arr[i]){\n\t\t\t\tassessment += 1;\n\t\t\t}\n\t\t}\n\t\treturn assessment;\n\t}\n\tvar begin = 0; var end = arr.length;\n\tvar assessment = assessmentSort(arr, begin, end);\n\twhile(assessment>0){\n\t\tvar separate = end/2;\n\t\tvar assessment1 = assessmentSort(arr, begin, separate);\n\t\tvar assessment2 = assessmentSort(arr, separate, end);\n\t\tif(assessment1>assessment2){\n\t\t\tbegin = separate;\n\t\t\tassessment = assessment2\n\t\t}\n\t\telse {\n\t\t\tend = separate;\n\t\t\tassessment = assessment1\n\t\t}\n\t}\n\treturn end - begin;\n\t\n}\n\n\nprint(sort(readline(), (readline()).split(\" \")))"}, {"source_code": "\tfunction sort(n, arr){\n\t\tfunction assessmentSort(arr, begin, end){\n\t\t\tvar assessment = 0;\n\t\t\tvar count = 0;\n\t\t\tfor(i = begin+1; i < end; i++){\n\t\t\t\tcount++;\n\t\t\t\tif(arr[i-1]>arr[i]){\n\t\t\t\t\tassessment += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn assessment;\n\t\t}\n\t\tvar begin = 0; var end = arr.length;\n\t\tvar assessment = assessmentSort(arr, begin, end);\n\t\twhile(assessment>0){\n\t\t\tvar separate = end/2;\n\t\t\tvar assessment1 = assessmentSort(arr, begin, separate);\n\t\t\tvar assessment2 = assessmentSort(arr, separate, end);\n\t\t\tif(assessment1>assessment2){\n\t\t\t\tbegin = separate;\n\t\t\t\tassessment = assessment2\n\t\t\t}\n\t\t\telse {\n\t\t\t\tend = separate;\n\t\t\t\tassessment = assessment1\n\t\t\t}\n\t\t}\n\t\treturn end - begin;\n\t\t\n\t}\n\tprint(sort(readline(), (readline()).split(\" \").map(i=>i-0)))"}, {"source_code": "\tfunction sort(n, arr){\n\t\tfunction assessmentSort(arr, begin, end){\n\t\t\tvar assessment = 0;\n\t\t\tvar count = 0;\n\t\t\tfor(i = begin+1; i < end; i++){\n\t\t\t\tcount++;\n\t\t\t\tif(arr[i-1]>arr[i]){\n\t\t\t\t\tassessment += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn assessment;\n\t\t}\n\t\tvar begin = 0; var end = n;\n\t\tvar assessment = assessmentSort(arr, begin, end);\n\t\twhile(assessment>0){\n\t\t\tvar separate = end/2;\n\t\t\tvar assessment1 = assessmentSort(arr, begin, separate);\n\t\t\tvar assessment2 = assessmentSort(arr, separate, end);\n\t\t\tif(assessment1>assessment2){\n\t\t\t\tbegin = separate;\n\t\t\t\tassessment = assessment2\n\t\t\t}\n\t\t\telse {\n\t\t\t\tend = end - (end - begin)/2;\n\t\t\t\tassessment = assessment1\n\t\t\t}\n\t\t}\n\t\treturn end - begin;\n\t\t\n\t}\n\tprint(sort(readline()-0, (readline()).split(\" \").map(i=>i-0)))"}, {"source_code": "function issorted(arr){\n\tfor (i=1; i+arr[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction check(arr){\n\tmaxLength=1;\n\tif(issorted(arr)) {\n\t\tmaxLength=(maxLength > arr.length) ? maxLength:arr.length;\n\t} else {\n\t\tcheck(arr.splice(arr.length/2));\n\t\tcheck(arr);\n\t}\n\treturn maxLength;\n}\n\nreadline();\nvar arr = readline().split(' ');\nprint(check(arr));"}, {"source_code": "function issorted(arr){\n\tfor (i=1; i+arr[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction check(arr){\n\tprint(arr, issorted(arr));\n\tif(issorted(arr)) {\n\t\treturn arr.length;\n\t} else {\n\t\treturn Math.max(check(arr.splice(arr.length/2)), check(arr));\n\t}\n}\n\nreadline();\nvar arr = readline().split(' ');\nprint(check(arr));"}, {"source_code": "var lengthA = readline();\nprint(lengthA)\nvar line2 = readline(); \nprint(line2)\nvar arr = line2.split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start <= end) {\n if (arr[start] < arr[start + 1])\n start++;\n else break;\n }\n\n if(start === end) \n return true \n else return false;\n}"}, {"source_code": "var lengthA = readline();\nvar line2 = readline(); \nvar arr = line2.split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start <= end) {\n if (arr[start] < arr[start + 1])\n start++;\n else break;\n }\n\n if(start === end) \n return true \n else return false;\n}"}, {"source_code": "var lengthA = readline();\nvar line2 = readline(); \nvar arr = line2.split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start < end) {\n if (arr[start] < arr[start + 1])\n start++;\n else break;\n }\n\n if(start === end) \n return true \n else return false;\n}"}, {"source_code": "var lengthA = readline();\nprint(lengthA)\nvar line2 = readline(); \nprint(line2)\nvar arr = line2.split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start < end) {\n if (arr[start] < arr[start + 1])\n start++;\n else break;\n }\n\n if(start === end) \n return true \n else return false;\n}"}, {"source_code": "var lengthA = readline();\n\nvar arr = readline().split(\" \").map(_ => parseInt(_))\n\nprint(thanosSort(arr, 0, arr.length-1));\n\nfunction thanosSort(arr, start, end) {\n\n var lengthOfArray = (end - start + 1);\n\n if (isSorted(arr, start, end)) return lengthOfArray\n\n var mid = start + Math.floor(lengthOfArray / 2);\n\n var left = thanosSort(arr, start, mid - 1),\n right = thanosSort(arr, mid, end);\n\n return Math.max(left, right);\n}\n\nfunction isSorted(arr, start, end) {\n while (start < end) {\n if (arr[start] < arr[start + 1])\n start++;\n else break;\n }\n\n if(start === end) \n return true \n else return false;\n}"}, {"source_code": "\nvar sort = function(a) {\n\n var c = JSON.parse(JSON.stringify(a));\n var sorted = c.sort(function(a,b){\n return a - b;\n });\n \n if (JSON.stringify(a) == JSON.stringify(sorted)) {\n // the array is sorted\n return a.length;\n } else {\n // if the array is not sorted\n // do recursion\n var first = a.splice(0, a.length / 2);\n var firstAns = sort(first);\n var secondAns = sort(a);\n return Math.max(firstAns, secondAns);\n }\n \n}\n"}, {"source_code": "\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nprint(a);"}, {"source_code": "readline();\nvar inputs = readline().split(\" \").map((x) => parseInt(x));\n\nfunction isSorted(array) {\n var limit = array.length - 1;\n for (var i = 0; i < limit; i++) {\n var current = array[i], next = array[i + 1];\n if (current > next) { return false; }\n }\n return true;\n \n}\n\nfunction thanosSort(start, end) {\n if(start === end) {\n return 1;\n }\n \n var sliceInputs = inputs.slice(start, end);\n if(isSorted(sliceInputs)) {\n return sliceInputs.length;\n }\n \n var mid = Math.floor((start+end)/ 2);\n return Math.max(thanosSort(start, mid -1), thanosSort(mid, end));\n}\n\nvar count = thanosSort(0, inputs.length);\nprint(count);"}, {"source_code": "readline();\nvar inputs = readline().split(\" \").map((x) => parseInt(x));\n\nfunction isSorted(array) {\n var limit = array.length - 1;\n for (var i = 0; i < limit; i++) {\n var current = array[i], next = array[i + 1];\n if (current > next) { return false; }\n }\n return true;\n \n}\n\nfunction thanosSort(start, end) {\n if(start === end) {\n return 1;\n }\n \n var sliceInputs = inputs.slice(start, end);\n if(isSorted(sliceInputs)) {\n return sliceInputs.length;\n }\n \n var mid = Math.floor((start+end)/ 2);\n return Math.max(thanosSort(start, mid -1), thanosSort(mid, end));\n}\n\nvar count = thanosSort(0, inputs.length - 1);\nprint(count);"}], "src_uid": "e5c68be38968fbc9677f3c1adddaff58"} {"source_code": "function gcd(a, b) {\n [b, a] = [Math.min(Math.abs(a), Math.abs(b)), Math.max(Math.abs(a), Math.abs(b))]\n while (true) {\n if (!b) return a;\n a %= b;\n if (!a) return b;\n b %= a;\n }\n}\n\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n res = arr[0]\n arr.forEach(qwe => {\n res = gcd(res, qwe)\n });\n for (let i of arr) {\n let qwe = Math.floor(i / res)\n while (qwe % 6 === 0 && qwe != 1) qwe /= 6;\n while (qwe % 2 === 0 && qwe != 1) qwe /= 2;\n while (qwe % 3 === 0 && qwe != 1) qwe /= 3;\n if (qwe != 1) {\n console.log(\"NO\")\n return 0;\n }\n }\n console.log(\"YES\")\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}", "positive_code": [{"source_code": "var n = +readline(), a = readline().split(\" \").map(Number);\nvar check = true;\n\nfor(var i = 0; i < n; i++){\n\tfor(;;){\n\t\tif(a[i] % 2 == 0){\n\t\t\ta[i] /= 2;\n\t\t}\n\t\telse{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor(;;){\n\t\tif(a[i] % 3 == 0){\n\t\t\ta[i] /= 3;\n\t\t}\n\t\telse{\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfor(var i = 0; i < n-1; i++){\n\tif(a[i] != a[i+1]){\n\t\twrite(\"No\");\n\t\tcheck = false;\n\t\tbreak;\n\t}\n}\n\nif(check){\n\twrite(\"Yes\");\n}"}, {"source_code": "function gcd(a, b) {\n [b, a] = [Math.min(Math.abs(a), Math.abs(b)), Math.max(Math.abs(a), Math.abs(b))]\n while (true) {\n if (!b) return a;\n a %= b;\n if (!a) return b;\n b %= a;\n }\n}\n\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n res = arr[0]\n arr.forEach(qwe => {\n res = gcd(res, qwe)\n });\n while (res % 6 === 0 && res != 1) res /= 6;\n while (res % 2 === 0 && res != 1) res /= 2;\n while (res % 3 === 0 && res != 1) res /= 3;\n //console.log(res)\n for (let i of arr) {\n let two = 1,\n three = 1\n while (i % (two * 2) === 0) two *= 2;\n while (i % (three * 3) === 0) three *= 3;\n //console.log(res * two * three, i)\n if (res * two * three != i) {\n console.log(\"No\")\n return 0\n }\n }\n console.log(\"Yes\")\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "var n = +readline(), arr = readline().split(\" \").map(Number);\nfor(var i =0;i a * b / gcd(a, b);\n\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n res = 1\n arr.forEach(qwe => {\n res = nok(res, qwe)\n });\n for (let i of arr) {\n let qwe = Math.floor(res / i)\n while (qwe % 6 === 0 && qwe != 1) qwe /= 6;\n while (qwe % 2 === 0 && qwe != 1) qwe /= 2;\n while (qwe % 3 === 0 && qwe != 1) qwe /= 3;\n if (qwe != 1) {\n console.log(\"NO\")\n return 0;\n }\n }\n console.log(\"YES\")\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "function gcd(a, b) {\n [b, a] = [Math.min(Math.abs(a), Math.abs(b)), Math.max(Math.abs(a), Math.abs(b))]\n while (true) {\n if (!b) return a;\n a %= b;\n if (!a) return b;\n b %= a;\n }\n}\n\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n res = 1\n arr.forEach(qwe => {\n res = gcd(res, qwe)\n });\n for (let i of arr) {\n let qwe = Math.floor(i / res)\n while (qwe % 6 === 0 && qwe != 1) qwe /= 6;\n while (qwe % 2 === 0 && qwe != 1) qwe /= 2;\n while (qwe % 3 === 0 && qwe != 1) qwe /= 3;\n if (qwe != 1) {\n console.log(\"NO\")\n return 0;\n }\n }\n console.log(\"YES\")\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "function gcd(a, b) {\n [b, a] = [Math.min(Math.abs(a), Math.abs(b)), Math.max(Math.abs(a), Math.abs(b))]\n while (true) {\n if (!b) return a;\n a %= b;\n if (!a) return b;\n b %= a;\n }\n}\n\nconst mainFunction = (lines) => {\n let arr = lines[1].split(\" \").map(Number),\n res = 1\n arr.forEach(qwe => {\n res = gcd(res, qwe)\n });\n while (res % 6 === 0 && res != 1) res /= 6;\n while (res % 2 === 0 && res != 1) res /= 2;\n while (res % 3 === 0 && res != 1) res /= 3;\n for (let i of arr) {\n let two = 1,\n three = 1\n while (i % (two * 2) === 0) two *= 2;\n while (i % (three * 3) === 0) three *= 3;\n if (res * two * three != i) {\n console.log(\"NO\")\n return 0\n }\n }\n console.log(\"YES\")\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "function factorization(a){\n\tvar da = {1:true};\n\tfor(var i = 2; i < a; i++){\n\t\tif( a%i == 0 ){\n\t\t\tda[i] = true;\n\t\t\ta = a/i;\n\t\t\ti = 1;\n\t\t}\n\t}\n\tda[a] = true;\n\treturn da;\n}\n\nfunction NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true,fact;\n\nfor(i = 0; i < n; i++){\n\tif(a[i] == 1 || a[i] == 2 || a[i] == 3){\n\t\ta.splice(i,1);\n\t}\n}\n\nif(a.length == 0){\n\twrite(\"Yes\");\n}\nelse if(a.length == 1){\n\tfact = factorization(a[0]);\n\n\tif(Object.keys(fact).length == 2){\n\t\tif(fact[2] == undefined && fact[3] == undefined){\n\t\t\twrite(\"No\");\n\t\t}\n\t\telse{\n\t\t\twrite(\"Yes\");\n\t\t}\n\t}\n\telse if(Object.keys(fact).length == 3){\n\t\tif(fact[2] && fact[3]){\n\t\t\twrite(\"Yes\");\n\t\t}\n\t\telse{\n\t\t\twrite(\"Yes\");\n\t\t}\n\t}\n\telse{\n\t\twrite(\"No\");\n\t}\n}\nelse{\n\tnod = NOD(a);\n\n\tif(nod == 1){\n\t\tfor(i = 0; i < a.length; i++){\n\t\t\tfact = factorization(a[i]);\n\t\t\tif(Object.keys(fact).length == 1){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if(Object.keys(fact).length == 2){\n\t\t\t\tif(fact[2] == undefined && fact[3] == undefined){\n\t\t\t\t\twrite(\"No\");\n\t\t\t\t\tcheck = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(Object.keys(fact).length == 3){\n\t\t\t\tif(fact[2] && fact[3]){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\twrite(\"No\");\n\t\t\t\t\tcheck = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif(check){\n\t\t\twrite(\"Yes\");\n\t\t}\n\t}\n\telse{\n\t\tfor(i = 0; i < a.length; i++){\n\t\t\tx = a[i] / nod;\n\n\t\t\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif(check){\n\t\t\twrite(\"Yes\");\n\t\t}\n\t}\n}"}, {"source_code": "function NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true;\n\nnod = NOD(a);\n\nfor(i = 0; i < n; i++){\n\tx = a[i] / nod;\n\n\tif(x == 1){\n\t\tcontinue;\n\t}\n\t\n\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\twrite(\"No\");\n\t\tcheck = false;\n\t\tbreak;\n\t}\n}\n\nif(check){\n\twrite(\"Yes\");\n}"}, {"source_code": "function factorization(a){\n\tvar da = {1:true};\n\tfor(var i = 2; i < a; i++){\n\t\tif( a%i == 0 ){\n\t\t\tda[i] = true;\n\t\t\ta = a/i;\n\t\t\ti = 1;\n\t\t}\n\t}\n\tda[a] = true;\n\treturn da;\n}\n\nfunction NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true,fact;\n\nnod = NOD(a);\n\nif(nod == 1){\n\tfor(i = 0; i < n; i++){\n\t\tfact = factorization(a[i]);\n\t\tif(Object.keys(fact).length == 1){\n\t\t\tcontinue;\n\t\t}\n\t\telse if(Object.keys(fact).length == 2){\n\t\t\tif(fact[2] == undefined || fact[3] == undefined){\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if(Object.keys(fact).length == 3){\n\t\t\tif(fact[2] && fact[3]){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\twrite(\"No\");\n\t\t\tcheck = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}\nelse{\n\tfor(i = 0; i < n; i++){\n\t\tx = a[i] / nod;\n\n\t\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\t\twrite(\"No\");\n\t\t\tcheck = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}"}, {"source_code": "function NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true;\n\nnod = NOD(a);\n\nfor(i = 0; i < n; i++){\n\tx = a[i] / nod;\n\n\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\twrite(\"No\");\n\t\tcheck = false;\n\t\tbreak;\n\t}\n}\n\nif(check){\n\twrite(\"Yes\");\n}"}, {"source_code": "function factorization(a){\n\tvar da = {1:true};\n\tfor(var i = 2; i < a; i++){\n\t\tif( a%i == 0 ){\n\t\t\tda[i] = true;\n\t\t\ta = a/i;\n\t\t\ti = 1;\n\t\t}\n\t}\n\tda[a] = true;\n\treturn da;\n}\n\nfunction NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true,fact;\n\nnod = NOD(a);\n\nif(nod == 1){\n\tfor(i = 0; i < n; i++){\n\t\tfact = factorization(a[i]);\n\t\tif(Object.keys(fact).length == 1){\n\t\t\tcontinue;\n\t\t}\n\t\telse if(Object.keys(fact).length == 2){\n\t\t\tif(fact[2] == undefined && fact[3] == undefined){\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if(Object.keys(fact).length == 3){\n\t\t\tif(fact[2] && fact[3]){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\twrite(\"No\");\n\t\t\tcheck = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}\nelse{\n\tfor(i = 0; i < n; i++){\n\t\tx = a[i] / nod;\n\n\t\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\t\twrite(\"No\");\n\t\t\tcheck = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}"}, {"source_code": "function factorization(a){\n\tvar da = {1:true};\n\tfor(var i = 2; i < a; i++){\n\t\tif( a%i == 0 ){\n\t\t\tda[i] = true;\n\t\t\ta = a/i;\n\t\t\ti = 1;\n\t\t}\n\t}\n\tda[a] = true;\n\treturn da;\n}\n\nfunction NOD(A){\n\tvar n = A.length, x = Math.abs(A[0]);\n\tfor (var i = 1; i < n; i++){\n\t\tvar y = Math.abs(A[i]);\n\t\twhile (x && y){ x > y ? x %= y : y %= x; }\n\t\tx += y;\n\t}\n\treturn x;\n}\n\nvar n = +readline(), a = readline().split(\" \").map(Number);\nvar nod, x, check = true,fact;\n\nnod = NOD(a);\n\nif(nod == 1){\n\tfor(i = 0; i < n; i++){\n\t\tif(a[i] == 2 || a[i] == 3){\n\t\t\tcontinue;\n\t\t}\n\t\telse{\n\t\t\tfact = factorization(a[i]);\n\t\t\tif(Object.keys(fact).length == 2){\n\t\t\t\tif(fact[2] == undefined || fact[3] == undefined){\n\t\t\t\t\twrite(\"No\");\n\t\t\t\t\tcheck = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(Object.keys(fact).length == 3){\n\t\t\t\tif(fact[2] && fact[3]){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\twrite(\"No\");\n\t\t\t\t\tcheck = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\twrite(\"No\");\n\t\t\t\tcheck = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}\nelse{\n\tfor(i = 0; i < n; i++){\n\t\tx = a[i] / nod;\n\n\t\tif(((x % 2) != 0) && ((x % 3) != 0)){\n\t\t\twrite(\"No\");\n\t\t\tcheck = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(check){\n\t\twrite(\"Yes\");\n\t}\n}"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number);\nvar check = true;\n\nfor(var i = 0; i < n; i++){\n\tfor(;;){\n\t\tif(a[i] % 2 == 0){\n\t\t\ta[i] /= 2;\n\t\t}\n\t\telse{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor(;;){\n\t\tif(a[i] % 3 == 0){\n\t\t\ta[i] /= 3;\n\t\t}\n\t\telse{\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfor(var i = 0; i < n-1; i++){\n\tif(a[i] != a[i+1]){\n\t\twrite(\"No\");\n\t\tcheck = false;\n\t}\n}\n\nif(check){\n\twrite(\"Yes\");\n}"}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var a, gcd, n;\n\n n = parseInt(readline());\n\n a = readline().split(' ').map(function(item) {\n return parseInt(item);\n });\n\n gcd = null;\n\n (function() {\n var i, j, len, v;\n for (i = j = 0, len = a.length; j < len; i = ++j) {\n v = a[i];\n while (v % 2 === 0) {\n v /= 2;\n }\n while (v % 3 === 0) {\n v /= 3;\n }\n if (gcd == null) {\n gcd = v;\n } else if (gcd !== v) {\n print('No');\n return;\n }\n print(v);\n }\n return print('Yes');\n })();\n\n}).call(this);\n"}], "src_uid": "2bb893703cbffe9aeaa0bed02f42a05c"} {"source_code": "\n//var input = readline()\nvar t = readline()\n\nvar x = 0, y = 0\nfor(var i=0; i {\n\tif (numLines == 0) {\n\t\tn = parseInt(line)\n\t} else {\n\t\tconst coordinate = line.split(' ').map(Number);\n\t\t[obelisks, clues][numLines > n ? 1 : 0].push({\n\t\t\tx: coordinate[0],\n\t\t\ty: coordinate[1]\n\t\t})\n\t}\n\tnumLines++\n}).on('close', () => {\n\tconst p = obelisks.sort((a, b) => a.x - b.x || a.y - b.y).shift()\n\tconst q = clues.sort((a, b) => b.x - a.x || b.y - a.y).shift()\n\tconsole.log(`${p.x + q.x} ${p.y + q.y}`)\n})"}, {"source_code": "// https://codeforces.com/contest/1091/problem/B\n// Big O:\n// Time complexity:\n// Space complexity:\n\n// Read input\nvar readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfObelisks;\nlet obelisksCoordinates = [];\nlet cluesCoordinates = [];\nrl.on('line', (input) => {\n if (numberOfObelisks) {\n const isReadingObelisksCoordinates = obelisksCoordinates.length < numberOfObelisks;\n if (isReadingObelisksCoordinates) {\n obelisksCoordinates.push(getCoordinate(input));\n } else {\n cluesCoordinates.push(getCoordinate(input));\n }\n } else {\n numberOfObelisks = parseInt(input);\n }\n\n if (cluesCoordinates.length === numberOfObelisks) {\n console.log(findTreasure(obelisksCoordinates, cluesCoordinates));\n rl.close();\n }\n});\n\nfunction getCoordinate(input) {\n const positions = input.split(\" \").map(Number);\n const coordinate = new Coordinate(positions[0], positions[1]);\n return coordinate;\n}\n\n// Problem\nclass Coordinate {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n\n addCoordinate(coordinate) {\n return new Coordinate(this.x + coordinate.x, this.y + coordinate.y);\n }\n\n equal(coordinate) {\n return this.x === coordinate.x && this.y === coordinate.y;\n }\n\n toString() {\n return `${this.x}, ${this.y}`;\n }\n}\n\nfunction findTreasure(obelisksCoordinates, cluesCoordinates) {\n const cluesDictionary = getCluesDictionary(cluesCoordinates);\n\n for (let clue of cluesCoordinates) {\n const firstObelisk = obelisksCoordinates[0];\n const treasure = firstObelisk.addCoordinate(clue);\n const treasureFound = treasureMatch(treasure, obelisksCoordinates, cluesDictionary);\n if (treasureFound) {\n return `${treasure.x} ${treasure.y}`;\n }\n }\n\n return \"\";\n}\n\nfunction treasureMatch(treasure, obelisksCoordinates, cluesDictionary) {\n for (let obelisk of obelisksCoordinates) {\n const x = treasure.x - obelisk.x;\n const y = treasure.y - obelisk.y;\n\n const possibleClue = new Coordinate(x, y);\n if (cluesDictionary[possibleClue.toString()] === undefined) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction getCluesDictionary(cluesCoordinates) {\n const cluesDictionary = {};\n for (let i = 0; i < cluesCoordinates.length; i++) {\n const currentClue = cluesCoordinates[i].toString();\n cluesDictionary[currentClue] = i;\n }\n\n return cluesDictionary;\n}\n\n\n// console.log(findTreasure([new Coordinate(2, 5), new Coordinate(-6, 4)], [new Coordinate(7, -2), new Coordinate(-1, -3)]))\n"}, {"source_code": "// https://codeforces.com/contest/1091/problem/B\n// Big O:\n// Time complexity: O(n^2)\n// Space complexity: O(n)\n\n// Read input\nvar readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfObelisks;\nlet obelisksCoordinates = [];\nlet cluesCoordinates = [];\nrl.on('line', (input) => {\n if (!numberOfObelisks) {\n numberOfObelisks = parseInt(input);\n return;\n }\n\n readCoordinates(input);\n\n if (cluesCoordinates.length === numberOfObelisks) {\n console.log(findTreasure(obelisksCoordinates, cluesCoordinates));\n rl.close();\n }\n});\n\nfunction readCoordinates(input) {\n const isReadingObelisksCoordinates = obelisksCoordinates.length < numberOfObelisks;\n if (isReadingObelisksCoordinates) {\n obelisksCoordinates.push(getCoordinate(input));\n } else {\n cluesCoordinates.push(getCoordinate(input));\n }\n}\n\nfunction getCoordinate(input) {\n const positions = input.split(\" \").map(Number);\n const coordinate = new Coordinate(positions[0], positions[1]);\n return coordinate;\n}\n\n// Problem\nclass Coordinate {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n\n addCoordinate(coordinate) {\n return new Coordinate(this.x + coordinate.x, this.y + coordinate.y);\n }\n\n equal(coordinate) {\n return this.x === coordinate.x && this.y === coordinate.y;\n }\n\n toString() {\n return `${this.x} ${this.y}`;\n }\n}\n\nfunction findTreasure(obelisksCoordinates, cluesCoordinates) {\n const cluesIndexes = getCluesIndexes(cluesCoordinates);\n const firstObelisk = obelisksCoordinates[0];\n\n for (let clue of cluesCoordinates) {\n const treasureCoordinate = firstObelisk.addCoordinate(clue);\n const treasureFound = isTreasureAtCoordinate(treasureCoordinate, obelisksCoordinates, cluesIndexes);\n if (treasureFound) {\n return treasureCoordinate.toString();\n }\n }\n\n return \"\";\n}\n\nfunction getCluesIndexes(cluesCoordinates) {\n const cluesDictionary = {};\n for (let i = 0; i < cluesCoordinates.length; i++) {\n const currentClue = cluesCoordinates[i].toString();\n cluesDictionary[currentClue] = i;\n }\n\n return cluesDictionary;\n}\n\nfunction isTreasureAtCoordinate(treasureCoordinate, obelisksCoordinates, cluesIndexes) {\n for (let obelisk of obelisksCoordinates) {\n // Check if there is a clue that points to the treasure for the current obelisk\n const x = treasureCoordinate.x - obelisk.x;\n const y = treasureCoordinate.y - obelisk.y;\n const possibleClue = new Coordinate(x, y);\n if (cluesIndexes[possibleClue.toString()] === undefined) {\n return false;\n }\n }\n\n return true;\n}"}, {"source_code": "// https://codeforces.com/contest/1091/problem/B\n// Big O:\n// Time complexity: O(n^2)\n// Space complexity: O(n)\n\n// Read input\nvar readline = require(\"readline\");\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfObelisks;\nlet obelisksCoordinates = [];\nlet cluesCoordinates = [];\nrl.on('line', (input) => {\n if (!numberOfObelisks) {\n numberOfObelisks = parseInt(input);\n return;\n }\n\n readCoordinates(input);\n\n if (cluesCoordinates.length === numberOfObelisks) {\n console.log(findTreasure(obelisksCoordinates, cluesCoordinates));\n rl.close();\n }\n});\n\nfunction readCoordinates(input) {\n const isReadingObelisksCoordinates = obelisksCoordinates.length < numberOfObelisks;\n if (isReadingObelisksCoordinates) {\n obelisksCoordinates.push(getCoordinate(input));\n } else {\n cluesCoordinates.push(getCoordinate(input));\n }\n}\n\nfunction getCoordinate(input) {\n const positions = input.split(\" \").map(Number);\n const coordinate = new Coordinate(positions[0], positions[1]);\n return coordinate;\n}\n\n// Problem\nclass Coordinate {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n\n addCoordinate(coordinate) {\n return new Coordinate(this.x + coordinate.x, this.y + coordinate.y);\n }\n\n equal(coordinate) {\n return this.x === coordinate.x && this.y === coordinate.y;\n }\n\n toString() {\n return `${this.x} ${this.y}`;\n }\n}\n\nfunction findTreasure(obelisksCoordinates, cluesCoordinates) {\n const cluesIndexes = getCluesIndexes(cluesCoordinates);\n const firstObelisk = obelisksCoordinates.shift();\n\n for (let clue of cluesCoordinates) {\n const treasureCoordinate = firstObelisk.addCoordinate(clue);\n const treasureFound = isTreasureAtCoordinate(treasureCoordinate, obelisksCoordinates, cluesIndexes);\n if (treasureFound) {\n return treasureCoordinate.toString();\n }\n }\n\n return \"\";\n}\n\nfunction getCluesIndexes(cluesCoordinates) {\n const cluesDictionary = {};\n for (let i = 0; i < cluesCoordinates.length; i++) {\n const currentClue = cluesCoordinates[i].toString();\n cluesDictionary[currentClue] = i;\n }\n\n return cluesDictionary;\n}\n\nfunction isTreasureAtCoordinate(treasureCoordinate, obelisksCoordinates, cluesIndexes) {\n for (let obelisk of obelisksCoordinates) {\n // Check if there is a clue that points to the treasure for the current obelisk\n const x = treasureCoordinate.x - obelisk.x;\n const y = treasureCoordinate.y - obelisk.y;\n const possibleClue = new Coordinate(x, y);\n if (cluesIndexes[possibleClue.toString()] === undefined) {\n return false;\n }\n }\n\n return true;\n}"}, {"source_code": "//var input = readline()\nvar t = parseInt(readline());\n \nvar x = 0, y = 0;\nfor(var i=0; i parseInt(x));\n var a = ar[0], b = ar[1];\n x += a , y += b;\n}\nprint(x/t +' '+ y/t);\n\n//"}, {"source_code": "\n//var input = readline()\nvar t = readline()\n\nvar x = 0, y = 0\nfor(var i=0; i {\n if (parseInt(elem.split('-')[1]) % 2 === 1) {\n answer.push(elem.split('')[0]);\n }\n });\n return [...new Set(answer)].sort().join('');\n}\n\nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n output += answer(str) + '\\n';\n}\nwrite(output);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\nfunction main()\n{\n let n = Number(readline());\n while(n--) {\n let a = Array.from(readline());\n let liters = new Set();\n while(a.length > 0) {\n if(a[0] == a[1]) {\n a.splice(0, 2);\n } else {\n liters.add(a[0]);\n a.splice(0, 1);\n }\n }\n liters=Array.from(liters);\n liters.sort();\n for(let l of liters)\n {\n process.stdout.write(l);\n }\n process.stdout.write('\\n');\n }\n return 0;\n}\n \n "}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\nlet input = \"\";\nprocess.stdin.on(\"data\", x => input += x);\nprocess.stdin.on(\"end\", () => {\n\tconsole.log(input\n\t\t.split(\"\\n\")\n\t\t.filter(x => x !== \"\")\n\t\t.filter((_, i) => i !== 0)\n\t\t.map(string =>\n\t\t\t[...new Set([...string.match(/(.)\\1{0,}/g)\n\t\t\t\t.filter(x => x.length % 2 !== 0)\n\t\t\t\t.join(\"\")])].sort().join(\"\")\n\t\t)\n\t\t.join(\"\\n\"));\n});"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\nfunction main()\n{\n let n = Number(readline());\n while(n--) {\n let a = Array.from(readline());\n let liters = new Set();\n while(a.length > 0) {\n if(a[0] == a[1]) {\n a.splice(0, 2);\n } else {\n liters.add(a[0]);\n a.splice(0, 1);\n }\n }\n for(let l of liters)\n {\n process.stdout.write(l);\n }\n process.stdout.write('\\n');\n }\n return 0;\n}\n \n "}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\nfunction main()\n{\n let n = Number(readline());\n while(n--) {\n let a = Array.from(readline());\n let liters = [];\n while(a.length > 0) {\n if(a[0] == a[1]) {\n a.splice(0, 2);\n } else {\n liters.push(a[0]);\n a.splice(0, 1);\n }\n }\n liters.sort((a, b) => {\n return a.charCodeAt(0) - b.charCodeAt(0);\n })\n for(let l of liters)\n {\n process.stdout.write(l);\n }\n process.stdout.write('\\n');\n }\n return 0;\n}\n \n "}, {"source_code": "var testCases = readline();\nwhile(testCases--){\n var input = readline();\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++;\n } else {\n output+=curr;\n }\n }\n output = output.split(\"\").sort().join(\"\");\n print(output); \n}"}, {"source_code": "function answer (input) {\n var charArr = input.split('');\n var res = [];\n for (var i =0;i < charArr.length; i++){\n if (charArr[i] === charArr[i+1]) {\n i++;\n } else {\n res.push(charArr[i]);\n }\n }\n return res.sort().join(\"\")\n}\n \nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n output += answer(str) + '\\n';\n}\nwrite(output);"}, {"source_code": "var testCases = readline();\nwhile(testCases--){\n var input = readline();\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++ \n } else {\n output+=curr;\n }\n }\n output = output.split(\"\").sort().join(\"\");\n print(output); \n}"}, {"source_code": "function answer (input) {\n var charArr = input.split('');\n var res = [];\n for (var i =0;i < charArr.length; i++){\n if (charArr[i] === charArr[i+1]) {\n i++;\n } else {\n res.push(charArr[i]);\n }\n }\n return res.sort().join(\"\")\n}\n \nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n print(str)\n output += answer(str) + '\\n';\n}\nwrite(output);"}, {"source_code": "var testCases = readline();\nvar input1 = readline();\nvar input2 = readline();\nvar input3 = readline();\nvar input4 = readline();\nvar inputs = [input1,input2,input3,input4];\n\ninputs.forEach(function (input) {\n var start = 0;\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n if (curr !== input[i+1]) {\n output+=curr; \n }\n } \n print(output);\n});"}, {"source_code": "var testCases = readline();\nvar input1 = readline();\nvar input2 = readline();\nvar input3 = readline();\nvar input4 = readline();\nvar inputs = [input1,input2,input3,input4];\n\ninputs.forEach(function (input) {\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++ \n } else {\n output+=curr;\n }\n }\n output = output.split(\"\").sort().join(\"\");\n print(output);\n});"}, {"source_code": "const testCases = readline();\nconst input1 = readline();\nconst input2 = readline();\nconst input3 = readline();\nconst input4 = readline();\nconst inputs = [input1,input2,input3,input4];\ninputs.forEach(input => print(input))"}, {"source_code": "function answer (input) {\n var charArr = input.split('');\n write(charArr)\n var res = [];\n for (var i =0;i < charArr.length; i++){\n if (charArr[i] === charArr[i+1]) {\n i++;\n } else {\n res.push(charArr[i]);\n }\n }\n return res.sort().join(\"\")\n}\n \nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n output += answer(str) + '\\n';\n}\nwrite(output);"}, {"source_code": "var testCases = readline();\nvar input1 = readline();\nvar input2 = readline();\nvar input3 = readline();\nvar input4 = readline();\nvar inputs = [input1,input2,input3,input4];\n\ninputs.forEach(function (input) {\n var start = 0;\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++ \n } else {\n output+=curr;\n }\n }\n output.split(\"\").sort();\n print(output);\n});"}, {"source_code": "function answer (input) {\n var charArr = input.split('');\n var res = [];\n for (var i =0;i < charArr.length; i++){\n if (charArr[i] === charArr[i+1]) {\n i++;\n } else {\n res.push(charArr[i]);\n }\n }\n return res.sort().join(\"\")\n}\n \nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n write(str)\n output += answer(str) + '\\n';\n}\nwrite(output);"}, {"source_code": "var testCases = readline();\nvar input1 = readline();\nvar input2 = readline();\nvar input3 = readline();\nvar input4 = readline();\nvar inputs = [input1,input2,input3,input4];\n\ninputs.forEach(function (input) {\n var start = 0;\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++ \n } else {\n output+=curr;\n }\n }\n output = output.split(\"\").sort().join(\"\");\n print(output);\n});"}, {"source_code": "function answer (input) {\n var charArr = input.split('');\n var res = [];\n for (var i =0;i < charArr.length; i++){\n if (charArr[i] === charArr[i+1]) {\n i++;\n } else {\n res.push(charArr[i]);\n }\n }\n return res.sort().join(\"\")\n}\n \nvar t = parseInt(readline());\nvar output = '';\nfor (var i = 0; i < t; i++) {\n var str = readline();\n write(str)\n output += answer(str) + '\\n';\n}\n"}, {"source_code": "var testCases = readline();\nvar input1 = readline();\nvar input2 = readline();\nvar input3 = readline();\nvar input4 = readline();\nvar inputs = [input1,input2,input3,input4];\n\ninputs.forEach(function (input) {\n var start = 0;\n var output = \"\";\n for (var i =0;i< input.length ;i++) {\n var curr = input[i];\n var next = input[i+1];\n if (curr === next) {\n i++ \n } else {\n output+=curr;\n }\n }\n output = output.split(\"\").sort();\n print(output);\n});"}], "src_uid": "586a15030f4830c68f2ea1446e80028c"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n let o = new Array(10);\n let z = new Array(10);\n o.fill(0);\n z.fill(0);\n for(let i = 0; i < m; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(b[i] & t !== 0)\n o[j] = 1;\n else\n z[j] = 1;\n\n t << 1;\n }\n }\n\n let c = new Array(10);\n for(let i = 0; i < n; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(a[i] & t !== 0){\n if(z[j] === 1)\n c[j] = 0;\n else\n c[j] = 1;\n }\n t << 1;\n }\n }\n\n let res = 0;\n for(let i = 9; i >= 0; i--){\n res += pi(c[i])*Math.pow(2,9-i);\n }\n console.log(res);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t){\n t--;\n let [n,k,z] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n // pre -> 0,1 -> right,left\n let dp = new Array(z+1);\n for(let i = 0; i < z+1; i++){\n dp[i] = new Array(n);\n dp[i].fill(-1);\n }\n \n let solve = (i,j,index,pre) => {\n if(index < 0 || index >= n)\n return 0;\n if(i > k)\n return 0;\n if(dp[j][index] !== -1)\n return dp[j][index];\n if(pre){\n return dp[j][index] = a[index] + solve(i+1, j, index+1, 0);\n }else{\n return dp[j][index] = a[index] + Math.max(j < z ? solve(i+1,j+1,index-1,1) : 0, solve(i+1,j,index+1,0));\n }\n }\n\n console.log(solve(0,0,0,1));\n }\n}\n\nfunction D(){\n let t = pi(readline());\n while(t){\n t--;\n let [n,k] = ti(readline().split(' '));\n let mat = new Array(n);\n for(let i = 0; i < n; i++)\n mat[i] = new Array(n);\n\n let x = Math.floor(k/n);\n let i = 0;\n let j = 0;\n let c = 0;\n while(i < n){\n while(c < x){\n if(j+c >= n)\n mat[i][j+c-n] = 1;\n else\n mat[i][j+c] = 1;\n c++;\n }\n c = 0;\n i++;\n j++;\n }\n\n for(let i = 0; i < n; i++)\n for(let j = 0; j < n; j++)\n if(mat[i][j] === undefined)\n mat[i][j] = 0;\n\n if(k%n !== 0){\n let m = k%n;\n let st = -1;\n for(let i = 0; i < n; i++){\n if(mat[0][i] === 0){\n st = i;\n break;\n }\n }\n for(let i = 0; i < n; i++){\n if(m === 0)\n break;\n for(let j = 0; j < n; j++){\n if(mat[i][j] === 0 && j === st){\n mat[i][j] = 1;\n st += 1;\n if(st >= n) st = 0;\n m -= 1;\n break;\n }\n }\n }\n }\n\n if(k%n === 0)\n console.log(0);\n else\n console.log(2);\n for(let i = 0; i < n; i++)\n console.log(mat[i].join(''));\n }\n}", "positive_code": [{"source_code": "function solve() {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var ans = [];\n var r = [];\n var c = [];\n for (var i = 0; i < n; i++) {\n r.push(0);\n c.push(0);\n ans.push([]);\n for (var j = 0; j < n; j++) {\n ans[i].push(0);\n }\n }\n var mr = n - 1;\n var mc = n - 1;\n while (k) {\n k--;\n mr = (mr + 1) % n;\n mc = (mc + 1) % n;\n if (ans[mr][mc]) {\n mc = (mc + 1) % n;\n }\n ans[mr][mc] = 1;\n r[mr]++;\n c[mc]++;\n }\n var minr = r[0];\n var maxr = r[0];\n var minc = c[0];\n var maxc = c[0];\n for (var i = 0; i < n; i++) {\n if (r[i] > maxr) {\n maxr = r[i];\n }\n if (r[i] < minr) {\n minr = r[i];\n }\n if (c[i] > maxc) {\n maxc = c[i];\n }\n if (c[i] < minc) {\n minc = c[i];\n }\n }\n write((maxr - minr) * (maxr - minr) + (maxc - minc) * (maxc - minc));\n for (var i = 0; i < n; i++) {\n write(ans[i].join(''));\n }\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "const process = require('process');\n \nlet inp = \"\";\nprocess.stdin.on('data', chunk => inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n let ic = 0;\n for (let ntest = +inp[ic++]; ntest--; ) {\n let [n, r] = inp[ic++].trim().split(' ').map(x => +x);\n let a = [];\n for (let i = 0; i < n; ++i) {\n let row = [];\n for (let f = 0;f < n; ++f) row.push(0);\n a.push(row);\n }\n\n let d = Math.floor(r / n);\n for (let r = 0; r < n; ++r) {\n for (let i = 0; i < d; ++i) {\n let c = (r + i) % n;\n a[r][c] = 1;\n }\n }\n let rem = r % n;\n for (let i = 0; i < rem; ++i) {\n let c = (i + d) % n;\n a[i][c] = 1;\n }\n\n console.log(rem ? 2 : 0);\n console.log(a.map(row => row.join('')).join('\\n'));\n }\n});\n"}], "negative_code": [{"source_code": "const process = require('process');\n \nlet inp = \"\";\nprocess.stdin.on('data', chunk => inp += chunk);\nprocess.stdin.on('end', () => {\n inp = inp.split('\\n');\n let ic = 0;\n for (let ntest = +inp[ic++]; ntest--; ) {\n let [n, r] = inp[ic++].trim().split(' ').map(x => +x);\n let a = [];\n for (let i = 0; i < n; ++i) {\n let row = [];\n for (let f = 0;f < n; ++f) row.push(0);\n a.push(row);\n }\n\n let d = Math.floor(r / n);\n for (let r = 0; r < n; ++r) {\n for (let i = 0; i < d; ++i) {\n let c = (r + i) % n;\n a[r][c] = 1;\n }\n }\n let rem = r % n;\n for (let i = 0; i < rem; ++i) {\n let c = (i + d) % n;\n a[i][c] = 1;\n }\n\n console.log(rem ? 2 : 0);\n console.log(a.map(row => row.join(' ')).join('\\n'));\n }\n});\n"}], "src_uid": "0f18382d450be90edf1fd1a3770b232b"} {"source_code": "var l1 = readline().split(' ');\nvar l2 = readline().split(' ');\nvar n = l1[0];\nvar str = l2[0];\nvar ans = [];\nfor(var i=0; immaxX){\n\t\t\tmmaxX=x;\n\t\t}\n\t}\n}\nx=-1;\ny=maxY*2+3;\nfor(var i = 0; immaxY){\n\t\t\tmmaxY=y;\n\t\t}\n\t}else{\n\t\tif(str[i-1]!=\"[\"){\n\t\t\tx-=3;\n\t\t}\n\t\tans[y][x+3]=\"-\";ans[y][x+4]=\"+\";\n\t\tx+=4;y+=1;\n\t}\n}\nfor(var i = 0; i maxlevel) maxlevel = level;\n level++;\n }else{\n level--;\n levels[i] = level;\n }\n}\n\nvar s = [];\nvar cells = maxlevel * 2 + 3;\nvar c = 0;\nfor(var i = 0; i < n; i++){\n var ns = [];\n \n if(a[i] == \"]\" && a[i - 1] == \"[\"){\n var ns = [];\n for(var j = 0; j < cells; j++){\n if(j == levels[i]){\n ns[j] = \"-\";\n }else if(j == maxlevel * 2 + 2 - levels[i]){\n ns[j] = \"-\";\n }else{\n ns[j] = \" \";\n }\n }\n s[c] = ns.join(\"\");\n c++;\n }\n \n var ns = [];\n var pluses = [];\n var opened = false;\n for(var j = 0; j < cells; j++){\n if(j == levels[i]){\n ns[j] = \"+\";\n opened = true;\n }else if(j == maxlevel * 2 + 2 - levels[i]){\n ns[j] = \"+\";\n opened = false;\n }else if(opened){\n ns[j] = \"|\";\n }else if(i > 0 && a[i - 1] == \"[\" && (j == levels[i - 1] || j == maxlevel * 2 + 2 - levels[i - 1])){\n ns[j] = \"-\";\n }else if(i > 0 && a[i + 1] == \"]\" && (j == levels[i + 1] || j == maxlevel * 2 + 2 - levels[i + 1])){\n ns[j] = \"-\";\n }else{\n ns[j] = \" \";\n }\n }\n s[c] = ns.join(\"\");\n c++;\n \n if(a[i] == \"[\" && a[i + 1] == \"]\"){\n var ns = [];\n for(var j = 0; j < cells; j++){\n if(j == levels[i]){\n ns[j] = \"-\";\n }else if(j == maxlevel * 2 + 2 - levels[i]){\n ns[j] = \"-\";\n }else{\n ns[j] = \" \";\n }\n }\n s[c] = ns.join(\"\");\n c++;\n for(var j = 0; j < cells; j++){\n ns[j] = \" \";\n }\n s[c] = ns.join(\"\");\n c++;\n }\n}\n\nfor(var i = 0; i < cells; i++){\n var sd = \"\";\n for(var j = 0; j < c; j++){\n sd += s[j][i];\n }\n print(sd);\n}"}, {"source_code": "readline();\nvar brackets = readline().split(\"\"),\n\tmaxDeep = getMaxDeep(brackets),\n\trenderDeep = 1 + maxDeep*2,\n\tmatrix;\n\nfunction getMaxDeep(brackets) {\n\tvar deep = 0;\n\treturn brackets.reduce(function (maxDeep, bracket) {\n\t\tbracket === \"[\" ? ++deep : --deep;\n\t\treturn deep > maxDeep ? deep : maxDeep;\n\t}, 1);\n}\n\nfunction getMatrix(brackets) {\n\tvar matrix = [],\n\t\tpointer = 0,\n\t\tdeep = 1,\n\t\ti;\n\n\tfor(i = 0; i < renderDeep; i++) {\n\t\tmatrix[i] = [];\n\t}\n\n\tbrackets.forEach(function (bracket, index) {\n\t\tvar height = renderDeep - (deep - 1)*2,\n\t\t\ttop = (renderDeep - height)/2,\n\t\t\tbottom = height + top - 1;\n\n\t\tif(bracket === \"[\"){\n\t\t\tif(brackets[index - 1] !== \"[\") createLine(pointer);\n\t\t\tcreateLine(pointer + 1)\t;\n\t\t\tcreateLine(pointer + 2);\n\t\t} else {\n\t\t\tif(brackets[index - 1] !== \"]\") createLine(pointer);\n\t\t\tcreateLine(pointer + 1);\n\t\t}\n\n\t\tmatrix.forEach(function (line, index) {\n\t\t\tif(index === top || index === bottom) {\n\t\t\t\tif(bracket === \"[\") {\n\t\t\t\t\tline[pointer] = \"+\";\n\t\t\t\t\tline[pointer + 1] = \"-\";\n\t\t\t\t} else {\n\t\t\t\t\tline[pointer] = \"-\";\n\t\t\t\t\tline[pointer + 1] = \"+\";\n\t\t\t\t}\n\t\t\t} else if(index > top && index < bottom){\n\t\t\t\tif(bracket === \"[\") {\n\t\t\t\t\tline[pointer] = \"|\";\n\t\t\t\t} else {\n\t\t\t\t\tline[pointer + 1] = \"|\";\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif(bracket === \"[\") {\n\t\t\tif(brackets[index + 1] === \"[\") {\n\t\t\t\tpointer += 1;\n\t\t\t\tdeep++;\n\t\t\t} else {\n\t\t\t\tpointer += 3;\n\t\t\t}\n\t\t} else {\n\t\t\tif(brackets[index + 1] === \"]\") {\n\t\t\t\tpointer += 1;\n\t\t\t\tdeep--;\n\t\t\t} else {\n\t\t\t\tpointer += 2;\n\t\t\t}\n\t\t}\n\t});\n\n\tfunction createLine(pointer) {\n\t\tmatrix.forEach(function (line) {\n\t\t\tline[pointer] = \" \";\n\t\t});\n\t}\n\n\treturn matrix;\n}\n\nfunction printMatrix(matrix) {\n\tmatrix.forEach(function (line) {\n\t\tprint(line.join(\"\"));\n\t});\n}\n\nmatrix = getMatrix(brackets, maxDeep);\nprintMatrix(matrix);"}], "negative_code": [], "src_uid": "7d9fb64a0a324a51432fbb01b4cc2c0e"} {"source_code": ";(function () {\n\n print(function (m, n) {\n var s = m;\n for (var i = m - 1; i >= 1; i--) {\n s -= Math.pow(i / m, n);\n }\n\n return s;\n }.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));", "positive_code": [{"source_code": "function read_int() {\n return readline().split(\" \").map(function (x) { return parseInt(x); });\n}\nfunction read_float() {\n return readline().split(\" \").map(function (x) { return parseFloat(x); });\n}\nfunction read() {\n return readline().split(' ');\n}\nvar x=read();\nvar m=x[0]*1.0;\nvar n=x[1]*1.0;\nvar ans=m;\nfor (var i=1;i= 1; --k) {\n\t\tvar curr = Math.pow((k-1)/m, n);\n\t\tmean += (prev-curr)*k;\n\t\tprev = curr;\n\t}\n\tprint(mean);\n}\n\nmain();\n"}], "negative_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tm = data[0], n = data[1],\n\t\ttrialNum = 0.5*Math.pow(10, 8)/n,\n\t\ttotal = 0;\n\tfor (var t = 0; t < trialNum; ++t) {\n\t\tvar max = 0;\n\t\tfor (var i = 0; i < n; ++i) {\n\t\t\tmax = Math.max(max, 1 + Math.floor(Math.random()*m));\n\t\t}\n\t\ttotal += max;\n\t}\n\tprint(total / trialNum);\n}\n\nmain();\n"}], "src_uid": "f70ac2c4e0f62f9d6ad1e003aedd86b2"} {"source_code": "!function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&\"object\"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,\"default\",{enumerable:!0,value:t}),2&r&&\"string\"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,\"a\",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p=\"\",e(e.s=2)}([function(module,exports,__webpack_require__){\"use strict\";var test=function(s){try{eval(s)}catch(t){return!1}return!0};exports.init=function(t){if(test(\"process.versions.node\")){var r=[],e=0;exports.gets=function(){return e>1;--n>=0;)this.inc(this.data[n])}}return t.prototype.size=function(){return this.data.length},t.prototype.top=function(){return i(this.data.length>0),this.data[0]},t.prototype.insert=function(t){var r=[t,this.data.length];return this.data.push(r),this.dec(r),r},t.prototype.remove=function(t){var r=t[1];i(t===this.data[r]),t=this.data.pop(),r0;){var e=r-1>>1;if(!this.cmp(t[0],this.data[e][0]))break;this.data[r]=this.data[e],this.data[r][1]=r,r=e}this.data[r]=t,t[1]=r},t.prototype.inc=function(t){var r=t[1];for(i(t===this.data[r]);;){var e=1+(r<<1);if(e>=this.data.length)break;if(e+10;){var b=l.top()[0];if(!isFinite(h[b]))break;l.remove(l.top());for(var _=0,m=i[b];_ 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":4,\"../stack\":5}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item, priority) {\n var node = new Node({\n item: item,\n priority: priority\n });\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n\n if (priority >= this.firstItemLink.getValue().priority) {\n // \u0412\u043f\u0435\u0440\u0435\u0434\n node.setNext(this.firstItemLink);\n this.firstItemLink = node;\n } else if (priority <= this.lastItemLink.getValue().priority) {\n // \u041d\u0430\u0437\u0430\u0434\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n } else {\n // \u0412 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443\n var currentNode = this.firstItemLink;\n while (currentNode) {\n var nextNode = currentNode.getNext();\n if (priority >= nextNode.getValue().priority) {\n currentNode.setNext(node);\n node.setNext(nextNode);\n currentNode = null;\n } else {\n currentNode = nextNode;\n }\n }\n }\n }\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue().item;\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],6:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar PriorityQueue = require('../libs/priority-queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return parseInt(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return parseInt(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n w = _readline$split$map4[2];\n\n if (a !== b) G.addEdge(a, b, w);\n}\n\nvar pq = new PriorityQueue(n * n);\nvar distances = {};\nvar prev = {};\n\n// for(let i = 1; i<=n; i++) {\n// prev[i] = null;\n// distances[i] = Infinity;\n// }\n\ndistances[1] = 0;\npq.enqueue(1, 0);\n\nvar explored = new Set();\n\nvar _loop = function _loop() {\n var node = pq.dequeue();\n\n explored.add(node);\n // console.log('\u041e\u0442\u043a\u0440\u044b\u043b \u043d\u043e\u0434\u0443 \u0438 \u043e\u0442\u043c\u0435\u0442\u0438\u043b \u043a\u0430\u043a \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u0443\u044e', node, ' \u0421\u043e\u0441\u0435\u0434\u0438', G.edges[node].map(({node}) => node).join(','));/**/\n G.edges[node].forEach(function (neighbor) {\n\n // if (!explored.has(neighbor.node)) {\n // console.log('\u041e\u0442\u043a\u0440\u044b\u043b \u043d\u043e\u0434\u0443', neighbor);\n var alt = distances[node] + neighbor.weight;\n\n if (distances[neighbor.node] === undefined || distances[neighbor.node] > alt) {\n // console.log('\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u043e\u0434\u0443', neighbor, '\u0412 \u043e\u0447\u0435\u0440\u0435\u0434\u044c');\n distances[neighbor.node] = alt;\n prev[neighbor.node] = node;\n pq.enqueue(neighbor.node, -1 * distances[neighbor.node]);\n // console.log('priority of node', distances[neighbor.node], JSON.stringify(pq.container));\n }\n // } else {\n // // console.log('\u0421\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u0438\u0434\u0442\u0438 \u043d\u0430 \u043d\u043e\u0434\u0443', neighbor.node, '\u043d\u043e \u043e\u043d\u0430 \u0443\u0436\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430');\n // }\n });\n};\n\nwhile (!pq.isEmpty()) {\n _loop();\n}\n\nif (prev[n]) {\n var path = n;\n var currNode = n;\n while (prev[currNode]) {\n path = prev[currNode] + ' ' + path;\n currNode = prev[currNode];\n }\n\n write(path);\n} else {\n write('-1');\n}\n\n},{\"../libs/graph\":1,\"../libs/priority-queue\":3}]},{},[6]);\n"}, {"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var i=n[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var i in t)r.d(e,i,function(n){return t[n]}.bind(null,i));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=2)}([function(t,n,r){\"use strict\";n.gets=function(){try{return readline,readline}catch(t){}try{process.versions.node}catch(t){return function(){return std.in.getline()}}var t=null,n=0;return function(){if(null===t){var e=r(1).readFileSync(\"/dev/stdin\");\"\"===(t=String(e).split(\"\\n\"))[t.length-1]&&t.pop()}return n>1;--e>=0;)this.inc(this.data[e])}}return t.prototype.size=function(){return this.data.length},t.prototype.top=function(){return i(this.data.length>0),this.data[0]},t.prototype.insert=function(t){var n=[t,this.data.length];return this.data.push(n),this.dec(n),n},t.prototype.remove=function(t){var n=t[1];i(t===this.data[n]),t=this.data.pop(),n0;){var r=n-1>>1;if(!this.cmp(t[0],this.data[r][0]))break;this.data[n]=this.data[r],this.data[n][1]=n,n=r}this.data[n]=t,t[1]=n},t.prototype.inc=function(t){var n=t[1];for(i(t===this.data[n]);;){var r=1+(n<<1);if(r>=this.data.length)break;if(r+10;){var S=b.top()[0];if(!isFinite(y[S]))break;b.remove(b.top());for(var w=0,x=d[S];w> 1; --i >= 0;)\\n this.inc(this.data[i]);\\n }\\n }\\n size() {\\n return this.data.length;\\n }\\n top() {\\n _util__WEBPACK_IMPORTED_MODULE_0__[\\\"assert\\\"](this.data.length > 0);\\n return this.data[0];\\n }\\n insert(x) {\\n const it = [x, this.data.length];\\n this.data.push(it);\\n this.dec(it);\\n return it;\\n }\\n remove(it) {\\n const i = it[1];\\n _util__WEBPACK_IMPORTED_MODULE_0__[\\\"assert\\\"](it === this.data[i]);\\n it = this.data.pop();\\n if (i < this.data.length) {\\n this.data[i] = it;\\n it[1] = i;\\n this.inc(it);\\n }\\n }\\n dec(it) {\\n let i = it[1];\\n _util__WEBPACK_IMPORTED_MODULE_0__[\\\"assert\\\"](it === this.data[i]);\\n while (i > 0) {\\n const p = (i - 1) >> 1;\\n if (!this.cmp(it[0], this.data[p][0]))\\n break;\\n this.data[i] = this.data[p];\\n this.data[i][1] = i;\\n i = p;\\n }\\n this.data[i] = it;\\n it[1] = i;\\n }\\n inc(it) {\\n let i = it[1];\\n _util__WEBPACK_IMPORTED_MODULE_0__[\\\"assert\\\"](it === this.data[i]);\\n for (;;) {\\n let j = (i << 1) + 1;\\n if (j >= this.data.length)\\n break;\\n if (j + 1 < this.data.length && this.cmp(this.data[j + 1][0], this.data[j][0]))\\n j++;\\n if (!this.cmp(this.data[j][0], it[0]))\\n break;\\n this.data[i] = this.data[j];\\n this.data[i][1] = i;\\n i = j;\\n }\\n this.data[i] = it;\\n it[1] = i;\\n }\\n}\\n\\n\\n//# sourceURL=webpack:///./build/_/ds/heap.js?\");\n\n/***/ }),\n\n/***/ \"./build/_/io.js\":\n/*!***********************!*\\\n !*** ./build/_/io.js ***!\n \\***********************/\n/*! no static exports found */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\neval(\"\\nexports.gets = (() => {\\n try {\\n readline;\\n return readline;\\n }\\n catch (err) { }\\n try {\\n process.versions.node;\\n }\\n catch (err) {\\n return () => std.in.getline();\\n }\\n let lines = null;\\n let i = 0;\\n return () => {\\n if (lines === null) {\\n const b = __webpack_require__(/*! fs */ \\\"fs\\\").readFileSync('/dev/stdin');\\n lines = String(b).split('\\\\n');\\n if (lines[lines.length - 1] === '')\\n lines.pop();\\n }\\n return i < lines.length ? lines[i++] : null;\\n };\\n})();\\n\\n\\n//# sourceURL=webpack:///./build/_/io.js?\");\n\n/***/ }),\n\n/***/ \"./build/_/util.js\":\n/*!*************************!*\\\n !*** ./build/_/util.js ***!\n \\*************************/\n/*! exports provided: assert, make_array, build_array */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\neval(\"__webpack_require__.r(__webpack_exports__);\\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \\\"assert\\\", function() { return assert; });\\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \\\"make_array\\\", function() { return make_array; });\\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \\\"build_array\\\", function() { return build_array; });\\nconst assert = (c, s) => {\\n if (!c) {\\n s = (s === undefined ? '' : ': ' + s);\\n throw new Error('Assertion failed' + s);\\n }\\n};\\nconst make_array = (n, x) => new Array(n).fill(x);\\nconst build_array = (n, f) => {\\n const a = new Array(n);\\n for (let i = 0; i < n; i++)\\n a[i] = f(i);\\n return a;\\n};\\n\\n\\n//# sourceURL=webpack:///./build/_/util.js?\");\n\n/***/ }),\n\n/***/ \"./build/a.js\":\n/*!********************!*\\\n !*** ./build/a.js ***!\n \\********************/\n/*! no exports provided */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\neval(\"__webpack_require__.r(__webpack_exports__);\\n/* harmony import */ var _io__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_/io */ \\\"./build/_/io.js\\\");\\n/* harmony import */ var _io__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_io__WEBPACK_IMPORTED_MODULE_0__);\\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_/util */ \\\"./build/_/util.js\\\");\\n/* harmony import */ var _ds_heap__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_/ds/heap */ \\\"./build/_/ds/heap.js\\\");\\n\\n\\n\\nlet S;\\nS = _io__WEBPACK_IMPORTED_MODULE_0__[\\\"gets\\\"]().split(' ').map((s) => +s);\\nconst N = S[0];\\nconst M = S[1];\\nconst E = _util__WEBPACK_IMPORTED_MODULE_1__[\\\"build_array\\\"](N, () => []);\\nfor (let i = 0; i < M; i++) {\\n S = _io__WEBPACK_IMPORTED_MODULE_0__[\\\"gets\\\"]().split(' ').map((s) => +s);\\n const a = S[0] - 1;\\n const b = S[1] - 1;\\n const c = S[2];\\n E[a].push([b, c]);\\n E[b].push([a, c]);\\n}\\nconst D = _util__WEBPACK_IMPORTED_MODULE_1__[\\\"make_array\\\"](N, Infinity);\\nconst P = _util__WEBPACK_IMPORTED_MODULE_1__[\\\"make_array\\\"](N, -1);\\nconst cmp = (a, b) => D[a] < D[b];\\nconst H = new _ds_heap__WEBPACK_IMPORTED_MODULE_2__[\\\"BinaryHeap\\\"](cmp);\\nconst I = _util__WEBPACK_IMPORTED_MODULE_1__[\\\"build_array\\\"](N, (u) => H.insert(u));\\nconst update = (u, p, d) => {\\n if (d < D[u]) {\\n D[u] = d;\\n P[u] = p;\\n H.dec(I[u]);\\n }\\n};\\nupdate(0, 0, 0);\\nwhile (H.size() > 0) {\\n const it = H.top();\\n H.remove(it);\\n const u = it[0];\\n for (const e of E[u]) {\\n const v = e[0];\\n const w = e[1];\\n update(v, u, D[u] + w);\\n }\\n}\\nif (!Number.isFinite(D[N - 1])) {\\n print('-1');\\n}\\nelse {\\n const p = [];\\n for (let u = N - 1;;) {\\n p.push(u + 1);\\n if (u === 0)\\n break;\\n u = P[u];\\n }\\n p.reverse();\\n print(p.join(' '));\\n}\\n\\n\\n//# sourceURL=webpack:///./build/a.js?\");\n\n/***/ }),\n\n/***/ \"fs\":\n/*!*********************!*\\\n !*** external \"fs\" ***!\n \\*********************/\n/*! no static exports found */\n/***/ (function(module, exports) {\n\neval(\"module.exports = require(\\\"fs\\\");\\n\\n//# sourceURL=webpack:///external_%22fs%22?\");\n\n/***/ })\n\n/******/ });"}, {"source_code": "'use strict';\n\n//const PriorityQueue = require('priorityqueuejs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\n/**\n * Expose `PriorityQueue`.\n */\n// module.exports = PriorityQueue;\n\n/**\n * Initializes a new empty `PriorityQueue` with the given `comparator(a, b)`\n * function, uses `.DEFAULT_COMPARATOR()` when no function is provided.\n *\n * The comparator function must return a positive number when `a > b`, 0 when\n * `a == b` and a negative number when `a < b`.\n *\n * @param {Function}\n * @return {PriorityQueue}\n * @api public\n */\n\nfunction PriorityQueue(comparator) {\n this._comparator = comparator || PriorityQueue.DEFAULT_COMPARATOR;\n this._elements = [];\n}\n\nPriorityQueue.DEFAULT_COMPARATOR = function(a, b) {\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n } else {\n a = a.toString();\n b = b.toString();\n\n if (a == b) return 0;\n\n return (a > b) ? 1 : -1;\n }\n};\n\n\nPriorityQueue.prototype.isEmpty = function() {\n return this.size() === 0;\n};\n\n\nPriorityQueue.prototype.peek = function() {\n if (this.isEmpty()) throw new Error('PriorityQueue is empty');\n\n return this._elements[0];\n};\n\n\nPriorityQueue.prototype.deq = function() {\n var first = this.peek();\n var last = this._elements.pop();\n var size = this.size();\n\n if (size === 0) return first;\n\n this._elements[0] = last;\n var current = 0;\n\n while (current < size) {\n var largest = current;\n var left = (2 * current) + 1;\n var right = (2 * current) + 2;\n\n if (left < size && this._compare(left, largest) >= 0) {\n largest = left;\n }\n\n if (right < size && this._compare(right, largest) >= 0) {\n largest = right;\n }\n\n if (largest === current) break;\n\n this._swap(largest, current);\n current = largest;\n }\n\n return first;\n};\n\n\nPriorityQueue.prototype.enq = function(element) {\n var size = this._elements.push(element);\n var current = size - 1;\n\n while (current > 0) {\n var parent = Math.floor((current - 1) / 2);\n\n if (this._compare(current, parent) <= 0) break;\n\n this._swap(parent, current);\n current = parent;\n }\n\n return size;\n};\n\n\nPriorityQueue.prototype.size = function() {\n return this._elements.length;\n};\n\n\nPriorityQueue.prototype.forEach = function(fn) {\n return this._elements.forEach(fn);\n};\n\n\nPriorityQueue.prototype._compare = function(a, b) {\n return this._comparator(this._elements[a], this._elements[b]);\n};\n\n\nPriorityQueue.prototype._swap = function(a, b) {\n var aux = this._elements[a];\n this._elements[a] = this._elements[b];\n this._elements[b] = aux;\n};\n\n\nlet nodes, edges;\nlet edgeList = [];\n\nconst getInput = () => {\n const lineInput = readline().split(\" \").map(Number);\n nodes = lineInput[0], edges = lineInput[1];\n\n edgeList = new Array(nodes + 1);\n for(let i = 0; i < nodes + 1; i++){\n edgeList[i] = new Array();\n edgeList[i].push(0);\n }\n\n for(let i = 0; i < edges; i++){\n const lineInput = readline().split(\" \").map(Number);\n let node1 = lineInput[0], node2 = lineInput[1], weight = lineInput[2];\n\n edgeList[node1].push({\"to\": node2, \"weight\": weight});\n edgeList[node2].push({\"to\": node1, \"weight\": weight});\n }\n};\n\nconst dijkstra = (source, destination) => {\n let distance = new Array(nodes + 1).fill(INF);\n let pQueue = new PriorityQueue(function(v1, v2) {\n return v2.weight - v1.weight;\n });\n let visited = new Array(nodes + 1).fill(false);\n let parent = new Array(nodes + 1).fill(-1);\n\n distance[source] = 0;\n pQueue.enq({node: source, weight: 0});\n\n while(!pQueue.isEmpty()) {\n const { node, weight } = pQueue.peek();\n pQueue.deq();\n\n if(weight === INF)\n break;\n if(visited[node]) continue;\n visited[node] = true;\n\n for(let edge of edgeList[node]){\n const {to, weight: currentWeight } = edge;\n\n if(distance[to] > weight + currentWeight){\n distance[to] = weight + currentWeight;\n pQueue.enq({node: to, weight: distance[to]})\n parent[to] = node;\n }\n }\n\n }\n \n if(distance[destination] === INF)\n return \"-1\";\n\n let path = \"\";\n let currentNode = destination\n while(parent[currentNode] !== -1){\n path += currentNode.toString() + \" \";\n currentNode = parent[currentNode];\n }\n path += currentNode.toString();\n path = path.split(\" \").reverse().join(\" \");\n\n return path;\n}\n\nfunction main() {\n getInput();\n const result = dijkstra(1, nodes);\n console.log(result);\n}\n"}, {"source_code": "!function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&\"object\"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,\"default\",{enumerable:!0,value:t}),2&r&&\"string\"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,\"a\",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p=\"\",e(e.s=2)}([function(module,exports,__webpack_require__){\"use strict\";var test=function(s){try{eval(s)}catch(t){return!1}return!0};exports.init=function(t){if(test(\"process.versions.node\")){var r=[],e=0;exports.gets=function(){return e>1;--n>=0;)this.inc(this.data[n])}}return t.prototype.size=function(){return this.data.length},t.prototype.top=function(){return i(this.data.length>0),this.data[0]},t.prototype.insert=function(t){var r=[t,this.data.length];return this.data.push(r),this.dec(r),r},t.prototype.remove=function(t){var r=t[1];i(t===this.data[r]),t=this.data.pop(),r0;){var e=r-1>>1;if(!this.cmp(t[0],this.data[e][0]))break;this.data[r]=this.data[e],this.data[r][1]=r,r=e}this.data[r]=t,t[1]=r},t.prototype.inc=function(t){var r=t[1];for(i(t===this.data[r]);;){var e=1+(r<<1);if(e>=this.data.length)break;if(e+10;){var b=l.top()[0];if(!isFinite(h[b]))break;l.remove(l.top());for(var _=0,m=i[b];_ {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\n/**\n * Expose `PriorityQueue`.\n */\n// module.exports = PriorityQueue;\n\n/**\n * Initializes a new empty `PriorityQueue` with the given `comparator(a, b)`\n * function, uses `.DEFAULT_COMPARATOR()` when no function is provided.\n *\n * The comparator function must return a positive number when `a > b`, 0 when\n * `a == b` and a negative number when `a < b`.\n *\n * @param {Function}\n * @return {PriorityQueue}\n * @api public\n */\n\nfunction PriorityQueue(comparator) {\n this._comparator = comparator || PriorityQueue.DEFAULT_COMPARATOR;\n this._elements = [];\n}\n\nPriorityQueue.DEFAULT_COMPARATOR = function(a, b) {\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n } else {\n a = a.toString();\n b = b.toString();\n\n if (a == b) return 0;\n\n return (a > b) ? 1 : -1;\n }\n};\n\n\nPriorityQueue.prototype.isEmpty = function() {\n return this.size() === 0;\n};\n\n\nPriorityQueue.prototype.peek = function() {\n if (this.isEmpty()) throw new Error('PriorityQueue is empty');\n\n return this._elements[0];\n};\n\n\nPriorityQueue.prototype.deq = function() {\n var first = this.peek();\n var last = this._elements.pop();\n var size = this.size();\n\n if (size === 0) return first;\n\n this._elements[0] = last;\n var current = 0;\n\n while (current < size) {\n var largest = current;\n var left = (2 * current) + 1;\n var right = (2 * current) + 2;\n\n if (left < size && this._compare(left, largest) >= 0) {\n largest = left;\n }\n\n if (right < size && this._compare(right, largest) >= 0) {\n largest = right;\n }\n\n if (largest === current) break;\n\n this._swap(largest, current);\n current = largest;\n }\n\n return first;\n};\n\n\nPriorityQueue.prototype.enq = function(element) {\n var size = this._elements.push(element);\n var current = size - 1;\n\n while (current > 0) {\n var parent = Math.floor((current - 1) / 2);\n\n if (this._compare(current, parent) <= 0) break;\n\n this._swap(parent, current);\n current = parent;\n }\n\n return size;\n};\n\n\nPriorityQueue.prototype.size = function() {\n return this._elements.length;\n};\n\n\nPriorityQueue.prototype.forEach = function(fn) {\n return this._elements.forEach(fn);\n};\n\n\nPriorityQueue.prototype._compare = function(a, b) {\n return this._comparator(this._elements[a], this._elements[b]);\n};\n\n\nPriorityQueue.prototype._swap = function(a, b) {\n var aux = this._elements[a];\n this._elements[a] = this._elements[b];\n this._elements[b] = aux;\n};\n\n\nlet nodes, edges;\nlet edgeList = [];\n\nconst getInput = () => {\n const lineInput = readline().split(\" \").map(Number);\n nodes = lineInput[0], edges = lineInput[1];\n\n edgeList = new Array(nodes + 1);\n for(let i = 0; i < nodes + 1; i++){\n edgeList[i] = new Array();\n edgeList[i].push(0);\n }\n\n for(let i = 0; i < edges; i++){\n const lineInput = readline().split(\" \").map(Number);\n let node1 = lineInput[0], node2 = lineInput[1], weight = lineInput[2];\n\n edgeList[node1].push({\"to\": node2, \"weight\": weight});\n edgeList[node2].push({\"to\": node1, \"weight\": weight});\n }\n};\n\nconst dijkstra = (source, destination) => {\n let distance = new Array(nodes + 1).fill(INF);\n let pQueue = new PriorityQueue(function(v1, v2) {\n return v2.weight - v1.weight;\n });\n let visited = new Array(nodes + 1).fill(false);\n let parent = new Array(nodes + 1).fill(-1);\n\n distance[source] = 0;\n pQueue.enq({node: source, weight: 0});\n\n while(!pQueue.isEmpty()) {\n const { node, weight } = pQueue.peek();\n pQueue.deq();\n\n if(weight === INF)\n break;\n if(visited[node]) continue;\n visited[node] = true;\n\n for(let edge of edgeList[node]){\n const {to, weight: currentWeight } = edge;\n\n if(distance[to] > weight + currentWeight){\n distance[to] = weight + currentWeight;\n pQueue.enq({node: to, weight: distance[to]})\n parent[to] = node;\n }\n }\n\n }\n \n if(distance[destination] === INF)\n return \"-1\";\n\n let path = \"\";\n let currentNode = destination\n while(parent[currentNode] !== -1){\n path += currentNode.toString() + \" \";\n currentNode = parent[currentNode];\n }\n path += currentNode.toString();\n path = path.split(\"\").reverse().join(\"\");\n\n return path;\n}\n\nfunction main() {\n getInput();\n const result = dijkstra(1, nodes);\n console.log(result);\n}\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\nvar w = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n\n if (w[n] === undefined || w[n] > w[node] + weight) {\n w[n] = w[node] + weight;\n p[n] = node;\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nif (explored.has(n)) {\n var _node = p[n];\n var path = [n];\n\n while (_node) {\n path.push(_node);\n _node = p[_node];\n }\n\n write(path.reverse().join(' '));\n} else {\n write(-1);\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\nvar w = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n\n if (w[n] === undefined || w[n] > w[node] + weight) {\n w[n] = w[node] + weight;\n p[n] = node;\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nvar node = p[n];\nvar path = [n];\n\nwhile (node) {\n path.push(node);\n node = p[node];\n}\n\nwrite(path.reverse().join(' '));\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar w = {};\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n w[i] = Number.MAX_SAFE_INTEGER;\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n if (weight + w[node] < w[n]) {\n w[n] = weight + w[node];\n p[n] = node;\n explored.delete(n);\n q.enqueue(n);\n } else if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nif (explored.has(n)) {\n var _node = p[n];\n var path = [n];\n\n while (_node) {\n path.push(_node);\n _node = p[_node];\n }\n\n write(path.reverse().join(' '));\n} else {\n write(-1);\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n w = _readline$split$map4[2];\n\n if (a !== b) G.addEdge(a, b, w);\n}\n\nif (n === 50000 && m === 99998) {\n write('TEST');\n} else {\n (function () {\n\n var q = new Queue();\n var p = {};\n var w = {};\n\n w[1] = 0;\n p[1] = undefined;\n q.enqueue(1);\n\n var _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n if (w[n] === undefined || weight + w[node] < w[n]) {\n w[n] = weight + w[node];\n p[n] = node;\n q.enqueue(n);\n }\n });\n };\n\n while (!q.isEmpty()) {\n _loop();\n }\n\n if (p[n]) {\n var _node = p[n];\n var path = n;\n\n while (_node) {\n path = _node + ' ' + path;\n _node = p[_node];\n }\n\n write(path);\n } else {\n write(-1);\n }\n })();\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":4,\"../stack\":5}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar PriorityQueue = function () {\n function PriorityQueue(maxSize) {\n _classCallCheck(this, PriorityQueue);\n\n // Set default max size if not provided\n if (isNaN(maxSize)) {\n maxSize = 10;\n }\n this.maxSize = maxSize;\n // Init an array that'll contain the queue values.\n this.container = [];\n }\n // Helper function to display all values while developing\n\n\n _createClass(PriorityQueue, [{\n key: \"display\",\n value: function display() {\n console.log(this.container);\n }\n // Checks if queue is empty\n\n }, {\n key: \"isEmpty\",\n value: function isEmpty() {\n return this.container.length === 0;\n }\n // checks if queue is full\n\n }, {\n key: \"isFull\",\n value: function isFull() {\n return this.container.length >= this.maxSize;\n }\n }, {\n key: \"enqueue\",\n value: function enqueue(data, priority) {\n // Check if Queue is full\n if (this.isFull()) {\n console.log(\"Queue Overflow!\");\n return;\n }\n var currElem = new this.Element(data, priority);\n var addedFlag = false;\n // Since we want to add elements to end, we'll just push them.\n for (var i = 0; i < this.container.length; i++) {\n if (currElem.priority < this.container[i].priority) {\n this.container.splice(i, 0, currElem);\n addedFlag = true;break;\n }\n }\n if (!addedFlag) {\n this.container.push(currElem);\n }\n }\n }, {\n key: \"dequeue\",\n value: function dequeue() {\n // Check if empty\n if (this.isEmpty()) {\n console.log(\"Queue Underflow!\");\n return;\n }\n return this.container.pop();\n }\n }, {\n key: \"peek\",\n value: function peek() {\n if (this.isEmpty()) {\n console.log(\"Queue Underflow!\");\n return;\n }\n return this.container[this.container.length - 1];\n }\n }, {\n key: \"clear\",\n value: function clear() {\n this.container = [];\n }\n }]);\n\n return PriorityQueue;\n}();\n\nPriorityQueue.prototype.Element = function () {\n function _class(data, priority) {\n _classCallCheck(this, _class);\n\n this.data = data;\n this.priority = priority;\n }\n\n return _class;\n}();\n\nmodule.exports = PriorityQueue;\n\n},{}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],6:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar PriorityQueue = require('../libs/priority-queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n if (n === 5000 && m === 99998) {} else G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n w = _readline$split$map4[2];\n\n if (n === 5000 && m === 99998) {} else if (a !== b) G.addEdge(a, b, w);\n}\n\nvar pq = new PriorityQueue(n * n);\nvar distances = {};\nvar prev = {};\n\nfor (var _i2 = 1; _i2 <= n; _i2++) {\n prev[_i2] = null;\n distances[_i2] = Infinity;\n}\n\ndistances[1] = 0;\npq.enqueue(1, 0);\n\nvar _loop = function _loop() {\n var node = pq.dequeue().data;\n\n G.edges[node].forEach(function (neighbor) {\n var alt = distances[node] + neighbor.weight;\n\n if (distances[neighbor.node] > alt) {\n distances[neighbor.node] = alt;\n prev[neighbor.node] = node;\n pq.enqueue(neighbor.node, distances[neighbor.node]);\n }\n });\n};\n\nwhile (!pq.isEmpty()) {\n _loop();\n}\n\nif (distances[n]) {\n var path = n;\n var currNode = n;\n while (prev[currNode]) {\n path = prev[currNode] + ' ' + path;\n currNode = prev[currNode];\n }\n\n write(path);\n} else {\n write('-1');\n}\n\n},{\"../libs/graph\":1,\"../libs/priority-queue\":3}]},{},[6]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w2 = _readline$split$map4[2];\n\n G.addEdge(a, b, _w2);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\nvar w = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n var _w = weight + w[node];\n if (w[n] === undefined || _w < w[n]) {\n w[n] = _w;\n p[n] = node;\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nif (explored.has(n)) {\n var _node = p[n];\n var path = [n];\n\n while (_node) {\n path.push(_node);\n _node = p[_node];\n }\n\n write(path.reverse().join(' '));\n} else {\n write(-1);\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = [[]];\n nodes.forEach(function (node) {\n _this.edges.push([]);\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n w = _readline$split$map4[2];\n\n if (a !== b) G.addEdge(a, b, w);\n}\n\nif (n === 50000 && m === 99998) {\n write('TEST');\n} else {\n (function () {\n\n var q = new Queue();\n var p = {};\n var w = {};\n\n w[1] = 0;\n p[1] = undefined;\n q.enqueue(1);\n\n var _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n if (w[n] === undefined || weight + w[node] < w[n]) {\n w[n] = weight + w[node];\n p[n] = node;\n q.enqueue(n);\n }\n });\n };\n\n while (!q.isEmpty()) {\n _loop();\n }\n\n if (p[n]) {\n var _node = p[n];\n var path = n;\n\n while (_node) {\n path = _node + ' ' + path;\n _node = p[_node];\n }\n\n write(path);\n } else {\n write(-1);\n }\n })();\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar w = {};\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n w[i] = Number.MAX_SAFE_INTEGER;\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n if (weight + w[node] < w[n]) {\n w[n] = weight + w[node];\n p[n] = node;\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nif (explored.has(n)) {\n var _node = p[n];\n var path = [n];\n\n while (_node) {\n path.push(_node);\n _node = p[_node];\n }\n\n write(path.reverse().join(' '));\n} else {\n write(-1);\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = {};\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar explored = new Set();\nvar p = {};\nvar w = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\nexplored.add(1);\n\nvar _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n if (!explored.has(n)) {\n explored.add(n);\n q.enqueue(n);\n }\n\n if (w[n] === undefined || w[n] > w[node] + weight) {\n w[n] = w[node] + weight;\n p[n] = node;\n }\n });\n};\n\nwhile (!q.isEmpty()) {\n _loop();\n}\n\nvar node = p[5];\nvar path = [5];\n\nwhile (node) {\n path.push(node);\n node = p[node];\n}\n\nwrite(path.reverse().join(' '));\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}, {"source_code": "(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i 0 && arguments[0] !== undefined ? arguments[0] : [];\n var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n _classCallCheck(this, Graph);\n\n this.directed = directed;\n this.nodes = nodes;\n this.edges = [];\n nodes.forEach(function (node) {\n _this.edges[node] = [];\n });\n }\n\n _createClass(Graph, [{\n key: 'addNode',\n value: function addNode(node) {\n // is it required ?\n if (this.edges[node]) {\n throw new Error('Graph.prototype.addNode: node is already exists');\n return;\n }\n\n this.nodes.push(node);\n this.edges[node] = [];\n }\n }, {\n key: 'addEdge',\n value: function addEdge(node1, node2) {\n var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n\n this.edges[node1].push({ node: node2, weight: weight });\n\n if (!this.directed) {\n this.edges[node2].push({ node: node1, weight: weight });\n }\n }\n }, {\n key: 'display',\n value: function display() {\n var _this2 = this;\n\n if (!console || !console.log) {\n return;\n }\n\n var graph = \"\";\n this.nodes.forEach(function (node) {\n graph += node + \"->\" + _this2.edges[node].map(function (n) {\n return n.node;\n }).join(\", \") + \"\\n\";\n });\n console.log(graph);\n }\n }, {\n key: 'BFS',\n value: function BFS(node) {\n var q = new Queue();\n var explored = new Set();\n q.enqueue(node);\n explored.add(node);\n while (!q.isEmpty()) {\n var t = q.dequeue();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n q.enqueue(n);\n });\n }\n }\n }, {\n key: 'DFS',\n value: function DFS(node) {\n var s = new Stack();\n var explored = new Set();\n s.push(node);\n explored.add(node);\n\n while (!s.isEmpty()) {\n var t = s.pop();\n this.edges[t].forEach(function (n) {\n if (explored.has(n)) {\n return;\n }\n\n explored.add(n);\n s.push(n);\n });\n }\n }\n }]);\n\n return Graph;\n}();\n\nmodule.exports = Graph;\n\n},{\"../queue\":3,\"../stack\":4}],2:[function(require,module,exports){\n\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = function () {\n function Node(value) {\n _classCallCheck(this, Node);\n\n this.value = value;\n this.nextNode = null;\n this.prevNode = null;\n }\n\n _createClass(Node, [{\n key: \"getValue\",\n value: function getValue() {\n return this.value;\n }\n }, {\n key: \"setValue\",\n value: function setValue(value) {\n this.value = value;\n }\n }, {\n key: \"setNext\",\n value: function setNext(nextNodeLink) {\n this.nextNode = nextNodeLink;\n }\n }, {\n key: \"setPrev\",\n value: function setPrev(prevNodeLink) {\n this.prevNode = prevNodeLink;\n }\n }, {\n key: \"getNext\",\n value: function getNext() {\n return this.nextNode;\n }\n }, {\n key: \"getPrev\",\n value: function getPrev() {\n return this.prevNode;\n }\n }]);\n\n return Node;\n}();\n\nmodule.exports = Node;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Queue = function () {\n function Queue() {\n _classCallCheck(this, Queue);\n\n this.firstItemLink = null;\n this.lastItemLink = null;\n }\n\n _createClass(Queue, [{\n key: 'enqueue',\n value: function enqueue(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.lastItemLink = node;\n this.firstItemLink = node;\n } else {\n this.lastItemLink.setNext(node);\n this.lastItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'dequeue',\n value: function dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n if (this.lastItemLink === this.firstItemLink) {\n this.lastItemLink = null;\n }\n\n var firstItem = this.firstItemLink;\n\n this.firstItemLink = this.firstItemLink.getNext();\n\n return firstItem.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.firstItemLink;\n }\n }]);\n\n return Queue;\n}();\n\nmodule.exports = Queue;\n\n},{\"../node\":2}],4:[function(require,module,exports){\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Node = require('../node');\n\nvar Stack = function () {\n function Stack() {\n _classCallCheck(this, Stack);\n\n this.topItemLink = null;\n }\n\n _createClass(Stack, [{\n key: 'push',\n value: function push(item) {\n var node = new Node(item);\n\n if (this.isEmpty()) {\n this.topItemLink = node;\n } else {\n node.setPrev(this.topItemLink);\n this.topItemLink = node;\n }\n\n return node;\n }\n }, {\n key: 'pop',\n value: function pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n var topItemLink = this.topItemLink;\n\n this.topItemLink = this.topItemLink.getPrev();\n\n return topItemLink.getValue();\n }\n }, {\n key: 'isEmpty',\n value: function isEmpty() {\n return !this.topItemLink;\n }\n }]);\n\n return Stack;\n}();\n\nmodule.exports = Stack;\n\n},{\"../node\":2}],5:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar Graph = require('../libs/graph');\nvar Queue = require('../libs/queue');\n\nvar _readline$split$map = readline().split(' ').map(function (n) {\n return Number(n);\n}),\n _readline$split$map2 = _slicedToArray(_readline$split$map, 2),\n n = _readline$split$map2[0],\n m = _readline$split$map2[1];\n\nvar G = new Graph();\nfor (var i = 1; i <= n; i++) {\n G.addNode(i);\n}\n\nfor (var _i = 0; _i < m; _i++) {\n var _readline$split$map3 = readline().split(' ').map(function (n) {\n return Number(n);\n }),\n _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),\n a = _readline$split$map4[0],\n b = _readline$split$map4[1],\n _w = _readline$split$map4[2];\n\n if (a !== b) G.addEdge(a, b, _w);\n}\n\nvar q = new Queue();\nvar p = {};\nvar w = {};\n\nw[1] = 0;\np[1] = undefined;\nq.enqueue(1);\n\nif (n === 50000 && m === 99998) {\n write('TEST');\n} else {\n var _loop = function _loop() {\n var node = q.dequeue();\n\n G.edges[node].forEach(function (_ref) {\n var n = _ref.node,\n weight = _ref.weight;\n\n // w[node] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e node\n // w[n] - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u043e n\n // weight - \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 node \u0434\u043e n\n if (w[n] === undefined || weight + w[node] < w[n]) {\n w[n] = weight + w[node];\n p[n] = node;\n q.enqueue(n);\n }\n });\n };\n\n while (!q.isEmpty()) {\n _loop();\n }\n\n if (p[n]) {\n var _node = p[n];\n var path = n;\n\n while (_node) {\n path = _node + ' ' + path;\n _node = p[_node];\n }\n\n write(path);\n } else {\n write(-1);\n }\n}\n\n},{\"../libs/graph\":1,\"../libs/queue\":3}]},{},[5]);\n"}], "src_uid": "bda2ca1fd65084bb9d8659c0a591743d"} {"source_code": "var numGoals = readline();\nvar teams = [[],[]];\nvar goal;\nfor(var i = numGoals; i; i--){\n\tgoal = readline();\n\tif(!teams[0].length){\n\t\tteams[0].push(goal);\n\t} else if(goal == teams[0][0]){\n\t\tteams[0].push(goal);\n\t} else{\n\t\tteams[1].push(goal);\n\t}\n}\n\nprint(teams[0].length > teams[1].length? teams[0][0] : teams[1][0]);", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n/*\nvar indicator = 0, cont = new Map(), maxScore = 0, winner = \"\";\n\nrl.on('line', (input) => {\n if (indicator == 0)\n indicator++;\n else {\n if (cont.has(input))\n cont.set(input, cont.get(input)+1);\n else \n cont.set(input, 1);\n \n if (maxScore < cont.get(input)) {\n maxScore = cont.get(input);\n winner = input;\n }\n \n } \n\n }).on('close',()=> {\n console.log(winner);\n // console.log(cont);\n });\n*/\n\nvar indicator = 0, team1Name = \"\", team2Name = \"\", score1 = 0, score2 = 0;\n\nrl.on('line', (input)=> {\n if (indicator == 0)\n indicator++;\n else {\n if (input == team1Name)\n score1++;\n else if (input == team2Name)\n score2++;\n else if (team1Name == \"\") {\n team1Name = input;\n score1++;\n }\n else {\n team2Name = input;\n score2++;\n } \n } \n}).on('close', function() {\n console.log((score1 > score2) ? team1Name : team2Name);\n});\n"}, {"source_code": "var n = +readline();\nvar cnt = {};\nwhile (n--) {\n\tvar name = readline();\n\tif (!cnt[name]) cnt[name] = 0;\n\tcnt[name]++;\n}\n\n\nvar ans = '';\nvar max = 0;\nfor (var name in cnt)\n\tif (cnt[name] > max)\n\t\tmax = cnt[name], ans = name;\n\nprint(ans);"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n const scores = {};\n while (t--) {\n const score = readLine();\n if (!scores[score]) scores[score] = 1;\n else scores[score]++;\n }\n const keys = Object.keys(scores);\n if (keys.length === 1) console.log(keys[0]);\n else {\n const [k1, k2] = keys;\n if (scores[k1] > scores[k2]) {\n console.log(k1);\n } else {\n console.log(k2);\n }\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require('constants');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar n,maxScore=0,myMap={},indicator=SSL_OP_SSLEAY_080_CLIENT_DH_BUG,ans=\"\";\n\nrl.on('line', (input) => {\n if(indicator==0){\n n= parseInt(input);\n indicator++;\n }\n else{\n if(input in myMap)\n myMap[input]++;\n else\n myMap[input]=1;\n if(maxScore{\n console.log(ans);\n });"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn();\n\nvar t1, t2, s1 = 0, s2 = 0;\n\nfor(var i = 0; i < n; i++){\n var name = readline();\n if(!t1){\n t1 = name;\n s1++;\n }\n if(!t2 && t1 != name){\n t2 = name;\n s2++;\n }\n\n if(name == t1) s1++;\n if(name == t2) s2++;\n}\n\nvar ans;\nif(s1 > s2){\n ans = t1;\n}else{\n ans = t2;\n}\n\nwrite(ans);"}, {"source_code": "var n = +readline();\nvar teams={};\nfor (var i = 0; i < n; i++) {\n\tvar element = readline();\n\tif(teams[element]){\n\t\tteams[element] +=1;\n\t} else {\n\t\tteams[element]=1;\n\t}\n}\nprint(\n\tteams[Object.keys(teams)[0]] > (teams[Object.keys(teams)[1]]|| 0)\n\t ? Object.getOwnPropertyNames(teams)[0]\n\t : Object.getOwnPropertyNames(teams)[1]\n\t );\n"}, {"source_code": "var readline = require('readline'),\n rl = readline.createInterface(process.stdin, process.stdout);\n/*\nvar n=0;\n \nrl.on('line', function (line) {\nvar counter=0;\nvar teams1=[];\nvar Fcount=0;\nvar Fteam=0;\n if (arr.length == 0) {\n arr = line.split(' ').map(item => { return parseInt(item) });\n n = arr[0];\n \n }\n else {\n\n if (++counter < n) {\n teams1.push(line.split(' ').map(item => { return parseInt(item) }))\n Fteam=teams1[0];\n\n }\n else {\n teams1.push(line.split(' ').map(item => { return parseInt(item) }));\n }\n for(let i in teams1){\n if(teams1[i]==Fteam)\n Fcount++;\n else {\n Steam=teams1[i] ;\n Scount++;\n }\n if(Fcount>Scount)\n console.log(Fteam);\n else console.log(Steam);\n rl.close();\n }\n\n\n }\n\n}\n\n);\n*/\nvar n = -1;\nvar dict = {};\nrl.on('line', function (line) {\n if (n == -1)\n n = parseInt(line);\n else if (n > 1) {\n if (line in dict)\n dict[line]++;\n else dict[line] = 1;\n n--;\n\n }\n else {\n if (line in dict)\n dict[line]++;\n else dict[line] = 1;\n var ans,score=0;\n for (var key in dict ){\n var value = dict[key];\n if(score {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nconst store = {};\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\n\tlet map = {};\n\tlet maxTeam = { score: 0, team: '' };\n\n\twhile (n--) {\n\t\tlet team = readLine();\n\t\tmap[team] = (map[team] || 0) + 1;\n\n\t\tif (map[team] > maxTeam.score) {\n\t\t\tmaxTeam = { score: map[team], team };\n\t\t}\n\t}\n\n\tconsole.log(maxTeam.team);\n}\n"}, {"source_code": "var n = +readline();\nvar counter = {};\nfor (var i = 0; i < n; i++) {\n var name = readline();\n if (!counter[name]) {\n counter[name] = 0\n }\n counter[name] += 1\n}\nvar command_names = Object.keys(counter);\nprint(command_names[Number(command_names.length == 2 && counter[command_names[1]] > counter[command_names[0]])]);"}, {"source_code": "var n = +readline();\nvar counter = {};\nvar command_names = [];\nfor (var i = 0; i < n; i++) {\n var command_name = readline();\n if (counter[command_name]) {\n counter[command_name] += 1\n } else {\n command_names.push(command_name);\n counter[command_name] = 1\n }\n}\nif (command_names.length == 1 || counter[command_names[0]] > counter[command_names[1]]) {\n print(command_names[0])\n} else {\n print(command_names[1])\n}"}, {"source_code": "var numberOfGoal = Number(readline())\n\nvar scores = {}\nfor (var i = 0; i < numberOfGoal; i++) {\n var goal = readline()\n var scored = scores[goal]\n if (scored == null) {\n scores[goal] = 1\n } else {\n scored += 1\n scores[goal] = scored\n }\n}\nvar team = Object.keys(scores)\n\nvar scoreTeamOne = scores[team[0]] || 0\nvar scoreTeamTwo = scores[team[1]] || 0\n\nif (scoreTeamOne > scoreTeamTwo) {\n print(team[0])\n} else {\n print(team[1])\n}"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar k1n = '', k1s = 0;\n\tvar k2n = '', k2s = 0;\n\n\twhile (n--) {\n\t\tvar s = readline();\n\n\t\tif (k1n === '' || k1n === s) {\n\t\t\tk1n = s;\n\t\t\tk1s++;\n\t\t} else {\n\t\t\tk2n = s;\n\t\t\tk2s++;\n\t\t}\n\t}\n\n\tprint(k1s > k2s ? k1n : k2n);\n\n}).call(this)"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let stringsArray = [];\n let n = parseInt(readLine());\n for (let i = 0; i < n; i++) {\n stringsArray.push(readLine());\n }\n let first = [];\n let second = [];\n for (let i = 0; i < n; i++) {\n let x = stringsArray[0];\n stringsArray.forEach((team) => {\n if (team === x) {\n first.push(team);\n } else {\n second.push(team);\n }\n });\n }\n if (first.length > second.length) {\n console.log(first[0]);\n } else {\n console.log(second[0]);\n }\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numGoals = parseInt(readline());\n\tvar teamGoals = {},\n\t\tteamNames = [];\n\tfor (var lineIndex = 0; lineIndex < numGoals; ++lineIndex) {\n\t\tvar teamName = trim(readline());\n\t\tif (teamGoals[teamName] === undefined) {\n\t\t\tteamNames.push(teamName);\n\t\t\tteamGoals[teamName] = 1;\n\t\t}\n\t\telse {\n\t\t\tteamGoals[teamName] += 1;\n\t\t}\n\t}\n\tif (teamNames.length == 1) {\n\t\tprint(teamNames[0]);\n\t}\n\telse {\n\t\tprint(teamNames[teamGoals[teamNames[0]] > teamGoals[teamNames[1]] ? \n\t\t\t\t0 : 1]);\n\t}\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet N = +readline()\nlet lll\nlet s = {}\nwhile (lll = readline()) {\n s[lll] = s[lll] || 0\n s[lll]++\n}\n\nlet ts = Object.keys(s)\nprint(!(s[ts[0]] < s[ts[1]]) ? ts[0] : ts[1])"}, {"source_code": "var lineas = readline();\nvar equipo1 = [];\nvar equipo2 = [];\nfor (var i = 0; i < lineas; i++){\n var palabra = readline();\n if (i === 0) {\n equipo1.push(palabra);\n continue;\n }\n if (equipo1[0] == palabra) {\n equipo1.push(palabra);\n } else {\n equipo2.push(palabra);\n }\n}\nequipo1.length > equipo2.length ? print(equipo1[0]) : print(equipo2[0]);"}, {"source_code": "var tokenizer;\nvar index = 0;\n\nfunction next(){\n while(tokenizer == null || index == tokenizer.length){\n tokenizer = readline().split(\" \");\n index = 0;\n }\n var res = tokenizer[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction nextFloat(){\n return parseFloat(next());\n}\n\nfunction solve(){\n var n = nextInt();\n var a = {};\n for(var i = 0; i < n; ++i){\n var s = next();\n if(s in a){\n a[s]++;\n } else {\n a[s] = 1;\n }\n }\n var min = 0;\n var winner;\n for(var team in a){\n if(a[team] > min){\n winner = team;\n min = a[team];\n }\n }\n print(winner);\n}\nsolve();"}, {"source_code": "var n = readline();\na = readline();\nvar res1 = 1;\nvar res2 = 0;\nfor(i = 1; i < n; i++){\n s = readline();\n if(a != s){\n b = s;\n res2++;\n }\n else{\n res1++;\n }\n}\nprint((res1 > res2)? a : b);"}, {"source_code": "var n = readline();\nteama = readline();\nvar one = 1; \nvar two = 0;\t\n\tfor (var i=1; i<+n; i++){\n\t\ttemp = readline();\n\t\tif (temp!=teama)\t{\n\t\t\tteamb = temp;\n\t\t\ttwo++;\n\t\t}\n\t\telse one++;\n\t}\nprint((one>two)? teama:teamb)"}, {"source_code": "var number = +readline();\nvar name;\nvar teamNames = [];\nvar winner;\nvar k;\nvar max = 0;\n\nwhile (number--) {\n\tname = readline();\n\tteamNames.push(name);\n}\nif (teamNames.length === 1){\n winner = teamNames[0];\n}\nteamNames.sort();\nfor (var i = 0; i max) {\n\t\t\t\tmax = k,\n\t\t\t\twinner = teamNames[i];\n\t\t\t}\n\t\t}\n}\nprint(winner);\n"}, {"source_code": "var n = parseInt(readline());\nvar hash = {};\nvar max = 0;\nvar winner = \"\";\nfor (var i = 0; i < n; i++) {\n\tvar team = readline();\n\tif (hash[team]) {\n\t\thash[team]++;\n\t} else {\n\t\thash[team] = 1;\n\t}\n}\n\nfor (var key in hash) {\n\tif (hash.hasOwnProperty(key)) {\n\t\tif (hash[key] > max) {\n\t\t\tmax = hash[key];\n\t\t\twinner = key;\n\t\t}\n\t}\n}\n\nprint(winner);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar indicator = 0, cont = new Map(), maxScore = 0, winner = \"\";\n\nrl.on('line', (input) => {\n if (indicator == 0)\n indicator++;\n else {\n if (cont.has(input))\n cont.set(input, cont.get(input)+1);\n else \n cont.set(input, 1);\n \n if (maxScore < cont.get(input)) {\n maxScore = cont.get(input);\n winner = input;\n }\n \n } \n\n }).on('close',()=> {\n console.log(winner);\n // console.log(cont);\n });\n"}, {"source_code": "var nums = parseInt(readline());\n\nvar obj = {};\n\nwhile (nums--){\n var winner = readline();\n \n if (!(winner in obj)) {\n obj[winner] = 1;\n } else {\n obj[winner]++;\n }\n}\n\n\n\nvar teams = Object.keys(obj);\nif (teams.length === 1 || obj[teams[0]] > obj[teams[1]]) {\n print(teams[0])\n} else {\n print(teams[1]);\n}"}, {"source_code": "var nums = parseInt(readline());\n\nvar obj = {};\n\nfor (var i = 0; i < nums; i++) {\n var winner = readline();\n \n if (!(winner in obj)) {\n obj[winner] = 1;\n } else {\n obj[winner]++;\n }\n}\n\n\n\nvar teams = Object.keys(obj);\nif (teams.length === 1 || obj[teams[0]] > obj[teams[1]]) {\n print(teams[0])\n} else {\n print(teams[1]);\n}"}, {"source_code": "//var input = \"5\\nA\\nABA\\nABA\\nA\\nA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var n = readline();\n var commands = {};\n var arr = [];\n for(var i = 0; i < n; i++){\n var str = readline();\n if(arr.indexOf(str) == -1)\n arr.push(str);\n if(!(str in commands))\n commands[str] = 1;\n else\n commands[str]++;\n }\n if(arr.length == 1)\n print(arr[0]);\n else if(commands[arr[0]] > commands[arr[1]])\n print(arr[0]);\n else\n print(arr[1]);\n}\nmain();"}], "negative_code": [{"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return Number(readline()); }\n\nvar n = rdn();\n\nvar t1, t2, s1 = 0, s2 = 0;\n\nfor(var i = 0; i < n; i++){\n var name = readline();\n if(!t1){\n t1 = name;\n s1++;\n }\n if(!t2){\n t2 = name;\n s2++\n }\n\n if(name == t1) s1++;\n if(name == t2) s2++;\n}\n\nvar ans;\nif(s1 > s2){\n ans = t1;\n}else{\n ans = t2;\n}\n\nwrite(ans);"}, {"source_code": "var n = +readline();\nvar teams={};\nfor (var i = 0; i < n; i++) {\n\tvar element = readline();\n\tif(teams[element]){\n\t\tteams[element] +=1;\n\t} else {\n\t\tteams[element]=1;\n\t}\n}\nprint(\n\tteams[Object.keys(teams)[0]] > teams[Object.keys(teams)[1]]|| 0\n\t ? Object.getOwnPropertyNames(teams)[0]\n\t : Object.getOwnPropertyNames(teams)[1]\n\t );\n"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar k1n = '', k1s = 0;\n\tvar k2n = '', k2s = 0;\n\n\twhile (n--) {\n\t\tvar s = readline();\n\n\t\tif (k1n === '' && k1n === s) {\n\t\t\tk1n = s;\n\t\t\tk1s++;\n\t\t} else {\n\t\t\tk2n = s;\n\t\t\tk2s++;\n\t\t}\n\t}\n\n\tprint(k1s > k2s ? k1n : k2n);\n\n}).call(this)"}, {"source_code": "var n = Number(readline());\nteama = readline();\nvar one = 0; \nvar two = 0;\t\n\tfor (var i=0; itwo)? teama:teamb)\n"}, {"source_code": "n = Number(readline());\nteama = readline();\nteamb=\"\";\none = 0; \ntwo = 0;\nres = 0;\t\n\tfor (var i=0; itwo? teama:teamb)\n"}, {"source_code": "var n = Number(readline());\nteama = readline();\nvar teamb;\nvar one = 0; \nvar two = 0;\t\n\tfor (var i=0; itwo)? teama:teamb)\n"}, {"source_code": "var n = Number(readline());\nteama = readline();\nvar one = 1; \nvar two = 0;\t\n\tfor (var i=0; itwo)? teama:teamb)\n"}, {"source_code": "'use strict';\nvar football43A = function() {\nvar number = +readline();\nvar name;\nvar teamNames = [];\nvar winner;\nvar k;\nvar max = 0;\n\nwhile (number--) {\n\tname = readline();\n\tteamNames.push(name);\n}\nteamNames.sort();\nfor (var i = 0; i max) {\n\t\t\t\tmax = k,\n\t\t\t\twinner = teamNames[i];\n\t\t\t}\n\t\t}\n}\nreturn winner;\n}\nfootball43A();\n"}, {"source_code": "'use strict';\nvar football43A = function() {\nvar number = +readline();\nvar name;\nvar teamNames = [];\nvar winner;\nvar k;\nvar max = 0;\n\nwhile (number--) {\n\tname = readline();\n\tteamNames.push(name);\n}\nteamNames.sort();\nfor (var i = 0; i max) {\n\t\t\t\tmax = k,\n\t\t\t\twinner = teamNames[i];\n\t\t\t}\n\t\t}\n}\nprint(winner);\n}\nfootball43A();\n"}, {"source_code": "'use strict';\nvar number = +readline();\nvar name;\nvar teamNames = [];\nvar winner;\nvar k;\nvar max = 0;\n\nwhile (number--) {\n\tname = readline();\n\tteamNames.push(name);\n}\nteamNames.sort();\nfor (var i = 0; i max) {\n\t\t\t\tmax = k,\n\t\t\t\twinner = teamNames[i];\n\t\t\t}\n\t\t}\n}\nprint(winner);\n"}, {"source_code": "var nums = parseInt(readline());\n\nvar obj = {};\n\nfor (var i = 0; i < nums; i++) {\n var winner = readline();\n \n if (!(winner in obj)) {\n obj[winner] = 1;\n } else {\n obj[winner]++;\n }\n}\n\nvar teams = Object.keys(obj);\nif (obj[teams[0]] > obj[teams[1]]) {\n print(teams[0])\n} else {\n print(teams[1]);\n}"}, {"source_code": "//var input = \"5\\nA\\nABA\\nABA\\nA\\nA\";\n//var index = 0;\n//\n//function readline(){\n// var data = input.split('\\n');\n// if(index < data.length)\n// return data[index++];\n//}\n//\n//function print(output){\n// console.log(output);\n//}\n\nfunction main(){\n var n = readline();\n var commands = {};\n var arr = [];\n for(var i = 0; i < n; i++){\n var str = readline();\n if(arr.indexOf(str) == -1)\n arr.push(str);\n if(!(str in commands))\n commands[str] = 1;\n else\n commands[str]++;\n }\n if(commands[arr[0]] > commands[arr[1]])\n print(arr[0]);\n else\n print(arr[1]);\n}\nmain();"}], "src_uid": "e3dcb1cf2186bf7e67fd8da20c1242a9"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar s = nextCharArray();\n\t\tvar N = s.length;\n\t\tvar a = 0;\n\t\tvar b = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(s[j] == \"A\"){\n\t\t\t\ta++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(s[j] == \"B\"){\n\t\t\t\tb++;\n\t\t\t\tif(a > 0){\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput[i] = b % 2 + a;\n\t}\n\tmyout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "\nvar tc = parseInt(readline());\nfor (; tc--;){\n var str = readline();\n var ar = [];\n for (var i = 0; i < str.length; i++) {\n ar.push(str[i]);\n if (ar.length > 1) {\n var Last = ar[ar.length - 2] + ar[ar.length - 1];\n \n while (Last === \"AB\" || Last === \"BB\") {\n ar.pop(); ar.pop();\n Last = ar[ar.length - 2] + ar[ar.length - 1];\n }\n }\n }\n print(ar.length);\n}\n\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = [];\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line;\n return;\n }\n\n data.push(line);\n \n if(lineNum - 1 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(data) { \n data.forEach(srt => {\n\n let stack = [];\n for(let i = 0; i < srt.length; i++) {\n stack.push(srt[i]);\n if(stack.length > 1) {\n let stackLast = stack[stack.length - 2] + stack[stack.length - 1];\n while(stackLast === \"AB\" || stackLast === \"BB\") {\n stack.pop();\n stack.pop();\n stackLast = stack[stack.length - 2] + stack[stack.length - 1];\n }\n }\n }\n console.log(stack.length)\n\n })\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const str = readLine();\n const stack = [];\n\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n if (stack[stack.length - 1] + char === \"AB\" || stack[stack.length - 1] + char === \"BB\") {\n stack.pop();\n } else {\n stack.push(char);\n }\n }\n console.log(stack.length);\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n// alpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = +$()\n while (t--) {\n let s = $()\n let n = s.length;\n let sa = Arr(n, i => 0)\n let sb = Arr(n, i => 0)\n if (s[0] == 'A') { sa[0] = 1; sb[0] = 1e6 }\n else { sb[0] = 1; sa[0] = 1e6 }\n For(1, n - 1, i => {\n if (s[i] == 'A') {\n sa[i] = sa[i - 1] + 1;\n sb[i] = sb[i - 1] + 1;\n } else {\n // if (s[i-1] == 'B') {\n // sa[i]\n // }\n sb[i] = sb[i - 1] - 1;\n if (sb[i] < 0) sb[i] = 1;\n sa[i] = sa[i - 1] - 1;\n if (sa[i] < 0) { sa[i] = 1e6; sb[i] = 1; }\n }\n })\n // log(sa)\n // log(sb)\n log(min(sa[n - 1], sb[n - 1]))\n }\n}\n"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 1) {\n const str = input[i];\n\n let countA = 0,\n countB = 0;\n let answer = 0;\n for (const char of [...str]) {\n if (char === \"A\") {\n countA += 1;\n } else if (countA > 0) {\n answer += 1;\n countA -= 1;\n } else {\n countB += 1;\n }\n }\n\n console.log(countA + (countB % 2))\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = readLine();\n for (let i = 0; i < numCases; i++) {\n let input = readLine();\n let toBeRemoved = 0;\n let beginningB = 0;\n let overhangA = 0;\n for (let k = 0; k < input.length; k++) {\n const letter = input[k];\n if (letter === 'A') {\n overhangA++;\n }\n else if (letter === 'B' && overhangA > 0) {\n overhangA--;\n toBeRemoved += 2;\n } else {\n beginningB++;\n }\n }\n console.log(overhangA + (beginningB % 2 === 0 ? 0 : 1));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n ABBB();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction ABBB(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let s = readline().split('');\n let st = [];\n let i = 0;\n while(i < s.length){\n if(s[i] === 'A'){\n st.push(s[i]);\n i++;\n }else{\n if(st[st.length-1] === 'A'){\n st.pop();\n i++;\n }else{\n st.push(s[i]);\n i++;\n }\n }\n }\n\n let countA = 0;\n let countB = 0;\n if(st.length > 0){\n while(st.length > 0){\n if(st.pop() === 'A')\n countA++;\n else\n countB++;\n }\n }\n console.log(countA + countB % 2);\n }\n}"}], "negative_code": [{"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 1) {\n const str = input[i];\n\n // AABBBABBBB\n const stack = [];\n let answer = 0,\n countB = 0;\n let countA = [...str].reduce((count, char) => {\n if (char === \"A\") count += 1;\n return count;\n }, 0);\n for (const char of [...str]) {\n if (char === \"A\") {\n stack.push(\"A\");\n countB = 0;\n } else {\n\n if (stack.length > 0) {\n stack.pop();\n answer += 2;\n countA -= 1;\n } else {\n countB += 1;\n\n if (countB % 2 === 0) {\n answer += 2;\n countB -= 2;\n }\n }\n }\n }\n\n if (countA === 0) {\n const res = str.length - answer;\n console.log(res % 2);\n } else console.log(str.length - answer);\n }\n});\n"}], "src_uid": "ee295fd90ee9283709447481f172c73c"} {"source_code": "'use strict';\n/*\nlet input = `\n5\n1 1 5 1 1\n`.trim().split('\\n');\nfunction readline() {\n\treturn input.shift();\n}\nfunction print(message) {\n\tconsole.log(message);\n}*/\n\n\n//code\nvar n = Number(readline());\nvar inputArr = readline().split(' ').map(Number);\nvar modifiedSum = 0;\nfor (var i = 0; i < n; i++) {\n\tmodifiedSum += inputArr[i] - 1;\n\tprint((modifiedSum%2 === 0) ? 2 : 1);\n}", "positive_code": [{"source_code": "/*\n The idea to solve this problem is basically we count the needed movement\n to complete the game in each test. Complete means no players can move anymore. \n \n Since peter move initially, so in order to win, the movement needed to complete\n the game must be odd.\n*/\n\nvar n = parseInt(readline());\nvar cycles = readline().split(' ').map(Number);\nvar move = 0;\n\nfor(var i = 0; i < n; i++) {\n \n move += cycles[i] - 1; // the movement needed to reduce cycle value into 1, note that the rule to breakdown is 1 <= p < x, so the movement needed will always follow this pattern (for any x value) \n if(move % 2)\n print(1);\n else\n print(2);\n}"}, {"source_code": "var n = readline();\nvar arr = readline().split(' ').map(Number);\n\nvar cycle = 0;\n for(var i = 0; i < n; i++){\n cycle += arr[i] - 1;\n if( cycle %2 == 0 ) {\n\n print(2);\n } else {\n\n print(1);\n }\n }"}, {"source_code": "/*\n The idea to solve this problem is basically we count the needed movement\n to complete the game in each test. Complete means no players can move anymore. \n \n Since peter move initially, so in order to win, the movement needed to complete\n the game must be even.\n*/\n\nvar n = parseInt(readline());\nvar cycles = readline().split(' ').map(Number);\nvar move = 0;\n\nfor(var i = 0; i < n; i++) {\n \n move += cycles[i] - 1; // the movement needed to reduce cycle value into 1, note that the rule to breakdown is 1 <= p < x, so the movement needed will always follow this pattern (for any x value) \n if(move % 2)\n print(1);\n else\n print(2);\n}"}], "negative_code": [], "src_uid": "3a767b3040f44e3e2148cdafcb14a241"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst p = rna();\r\n\r\n\t\tconst ansl = [], ansr = [];\r\n\r\n\t\tfor (let i = 0, cur = 1e6; i < n; i++) {\r\n\t\t\tif (p[i] < cur) {\r\n\t\t\t\tansl.push(p[i]);\r\n\t\t\t\tcur = p[i];\r\n\t\t\t} else {\r\n\t\t\t\tansr.push(p[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ansl.reverse().join(' '), ansr.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n let n = Number(readline()), p = readline().split(\" \");\r\n let ans = p[0], head = ans;\r\n p = p.slice(1);\r\n \r\n for(const num of p) {\r\n if(parseInt(num) < parseInt(head)) {\r\n ans = num + \" \" + ans;\r\n head = num;\r\n }else {\r\n ans += \" \" + num;\r\n } \r\n }\r\n console.log(ans);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nclass node {\r\n constructor(val) {\r\n this.val = val;\r\n this.next = null;\r\n }\r\n}\r\nclass dequeue {\r\n constructor() {\r\n this.head = null;\r\n this.tail = null;\r\n }\r\n front(val) {\r\n if (!this.head) return (this.head = this.tail = new node(val));\r\n let newNode = new node(val);\r\n newNode.next = this.head;\r\n return (this.head = newNode);\r\n }\r\n back(val) {\r\n if (!this.tail) return (this.head = this.tail = new node(val));\r\n let newNode = new node(val);\r\n this.tail.next = newNode;\r\n return (this.tail = newNode);\r\n }\r\n print() {\r\n let res = \"\",\r\n p = this.head;\r\n while (p) {\r\n res += p.val + \" \";\r\n p = p.next;\r\n }\r\n console.log(res);\r\n }\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n if (arr[0] === 1) console.log(arr.join(\" \"));\r\n else {\r\n let res = new dequeue(),\r\n min = arr[0];\r\n for (let i = 0; i < n; i++) {\r\n if (min > arr[i]) {\r\n res.front(arr[i]);\r\n min = arr[i];\r\n } else res.back(arr[i]);\r\n }\r\n res.print();\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nclass LinkedList {\r\n constructor(value) {\r\n this.head = {\r\n value: value,\r\n next: null\r\n };\r\n this.tail = this.head;\r\n this.length = 1;\r\n }\r\n append(value) {\r\n const newNode = {\r\n value: value,\r\n next: null\r\n }\r\n if(!this.head.value) {\r\n this.head.value = value;\r\n return;\r\n }\r\n this.tail.next = newNode;\r\n this.tail = newNode;\r\n this.length++;\r\n return this;\r\n }\r\n prepend(value) {\r\n const newNode = {\r\n value: value,\r\n next: null\r\n }\r\n if(!this.head.value) {\r\n this.head.value = value;\r\n return;\r\n }\r\n newNode.next = this.head;\r\n this.head = newNode;\r\n this.length++;\r\n return this;\r\n }\r\n printList() {\r\n const array = [];\r\n let currentNode = this.head;\r\n while(currentNode !== null){\r\n array.push(currentNode.value)\r\n currentNode = currentNode.next\r\n }\r\n return array;\r\n }\r\n }\r\n\r\n\r\nfunction main() {\r\n const t = parseInt(readline());\r\n for (let i = 0; i < t; i++){\r\n const n = parseInt(readline());\r\n const list = new LinkedList();\r\n readline().split(' ').map((str) => {\r\n const item = parseInt(str);\r\n if(!list.head || item <= list.head.value){\r\n list.prepend(item);\r\n }else{\r\n list.append(item);\r\n }\r\n });\r\n console.log(list.printList().join(' '))\r\n }\r\n\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), p = readline().split(\" \");\r\n let str = p.shift(), ans = str;\r\n \r\n for(const num of p) {\r\n if(num + str[0] < str.slice(0, num.length + 1)) {\r\n str = num + str\r\n ans = num + \" \" + ans;\r\n }else {\r\n str += num;\r\n ans += \" \" + num;\r\n } \r\n }\r\n console.log(ans);\r\n }\r\n }"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), p = readline().split(\" \");\r\n let head = p[0];\r\n for(let i = 1; i < n; i++) {\r\n if(p[i] < head) {\r\n head = p[i];\r\n p.splice(i, 1);\r\n p.unshift(head);\r\n }\r\n }\r\n console.log(p.join(\" \")); \r\n }\r\n }\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n "}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), p = readline().split(\" \");\r\n let str = p.shift();\r\n for(const num of p) {\r\n if(num < str[0]) str = num + str;\r\n else str += num;\r\n }\r\n console.log(str);\r\n }\r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n let p = readline().split(\" \"), min = Number(p.join(\"\")), myArrs = [[p.shift()]];\r\n for(const num of p) {\r\n const myNewArrs = [];\r\n for(const arr of myArrs) {\r\n if(arr.length == n) {\r\n let str = arr.join(\"\");\r\n min = Math.min(Number(str + num), Number(num + str), min);\r\n }\r\n myNewArrs.push(arr.concat([num]));\r\n myNewArrs.push([num].concat(arr));\r\n }\r\n myArrs = myNewArrs;\r\n }\r\n console.log(String(min).split(\"\").join(\" \")); \r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline());\r\n let p = readline().split(\" \"), min = Number(p.join(\"\")), myArrs = [p.shift()];\r\n for(const num of p) {\r\n const myNewArrs = [];\r\n for(const arr of myArrs) {\r\n if(arr.length == n) {\r\n let str = arr.join(\"\");\r\n min = Math.min(Number(str + num), Number(num + str), min);\r\n }\r\n myNewArrs.push(arr.concat([num]));\r\n myNewArrs.push([num].concat(arr));\r\n }\r\n myArrs = myNewArrs;\r\n }\r\n console.log(String(min).split(\"\").join(\" \")); \r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = Number(readline());\r\n for(let i = 0; i < t; i++) {\r\n const n = Number(readline()), p = readline().split(\" \"), arr = [p[0]];\r\n let min = Number(p.join(\"\"));\r\n function permutations(p, index, arr, n) {\r\n for(let option = 0; option < 2; option++) {\r\n if(index == n) {\r\n min = Math.min(min, Number(arr.join(\"\")));\r\n return;\r\n }\r\n if(option == 0) {\r\n permutations(p, index + 1, [p[index]].concat(arr), n);\r\n }\r\n if(option == 1) {\r\n permutations(p, index + 1, arr.concat([p[index]]), n); \r\n }\r\n }\r\n return\r\n }\r\n permutations(p, 1, arr, n);\r\n console.log(min);\r\n \r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let min = Infinity,\r\n ind = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] < min) {\r\n ind = i;\r\n min = arr[i];\r\n }\r\n }\r\n if (arr[0] > min) {\r\n let res = [];\r\n res.push(arr[ind]);\r\n for (let i = 0; i < n; i++) {\r\n if (ind !== i) res.push(arr[i]);\r\n }\r\n console.log(res.join(\" \"));\r\n } else console.log(arr.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let min = Infinity,\r\n ind = 0;\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] < min) {\r\n ind = i;\r\n min = arr[i];\r\n }\r\n }\r\n if (arr[0] > min) {\r\n [arr[0], arr[ind]] = [arr[ind], arr[0]];\r\n }\r\n console.log(arr.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[0] > arr[i + 1]) {\r\n let k = i + 1,\r\n j = i + 1;\r\n while (j < n) {\r\n if (arr[k] > arr[j]) k = j;\r\n j++;\r\n }\r\n [arr[i], arr[k]] = [arr[k], arr[i]];\r\n break;\r\n }\r\n }\r\n console.log(arr.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i] > arr[i + 1]) {\r\n let k = i + 1,\r\n j = i + 1;\r\n while (j < n) {\r\n if (arr[k] > arr[j]) k = j;\r\n j++;\r\n }\r\n [arr[i], arr[k]] = [arr[k], arr[i]];\r\n break;\r\n }\r\n }\r\n console.log(arr.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "5afa0e4f34ab8c8c67bc8ecb7d6d2d7a"} {"source_code": "//NYTransport.js\n\"use strict\"\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n arr2=[],\n x,y,i;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = nb.split(' ');\n arr2 = TC.split(' ');\n y = Number(arr[1]); //dest\n i=0;\n while(i y-1){\n console.log(\"NO\");\n rl.close();\n break;\n }\n }\n });\n});", "positive_code": [{"source_code": "var input = readline().split(\" \").map((x) => parseInt(x));\nvar location = readline().split(\" \").map((x) => parseInt(x));\nvar position = input[1];\nvar counter = 1;\nvar found = false;\n\nif(position > location.length) {\n print(\"YES\");\n} else {\n while(counter < location.length) {\n counter = counter + location[counter - 1];\n \n if(counter === position) {\n print(\"YES\");\n found = true;\n break;\n }\n }\n\n if(!found) {\n print(\"NO\");\n }\n}\n"}, {"source_code": "(function() {\n var values = readline().split(\" \").map(Number);\n var n = values[0] - 1;\n var k = values[1];\n var arr = readline().split(\" \").map(Number);\n var save = 1;\n \n for (var i = 1; i <= arr.length && save <= n; i++) {\n save = arr[save - 1] + save;\n if (save === k) {\n print(\"YES\");\n return;\n }\n }\n \n print(\"NO\");\n})();"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = false;\nvar i = 0;\nwhile (i process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n input = input.split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});"}, {"source_code": "var input1 = readline().split(\" \"), input2 = readline().split(\" \");\nvar n = +input1[0], t = +input1[1] - 1, cells = [];\nfor(i = 0; i < n-1; i++){\n\tcells.push(i + +input2[i]);\n}\ncells.push(0);\n\nif(cells.indexOf(t) + 1){\n\tfor(i = 0; ; ){\n\t\ti = cells[i];\n\t\tif(i == t){\n\t\t\twrite(\"YES\");\n\t\t\tbreak;\n\t\t}\n\t\telse if( i > t){\n\t\t\twrite(\"NO\");\n\t\t\tbreak;\n\t\t}\n\t}\n}\nelse{\n\twrite(\"NO\");\n}"}, {"source_code": "nt = readline().split(' ').map(Number); n=nt[0]; t=nt[1]; x=1;\na = readline().split(' ').map(Number);\nwhile(x process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\n\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n // input = input.split(/\\r?\\n/);\n // getline = () => input.shift();\n input = input.split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});\n\n\nfunction main() {\n let n = parseInt(read()),\n t = parseInt(read());\n\n let arr = [];\n for (let i = 0; i < n - 1; i++) {\n let x = parseInt(read());\n arr.push(x);\n }\n\n let p = 0;\n while (p < t - 1) {\n p += arr[p];\n }\n if (p === t - 1) {\n writeline(\"YES\");\n } else {\n writeline(\"NO\");\n }\n\n return 0;\n}\n"}, {"source_code": "\"use strict\"\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n arr2=[],\n x,y,i;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = nb.split(' ');\n arr2 = TC.split(' ');\n y = Number(arr[1]); //dest\n i=0;\n while(i y-1){\n console.log(\"NO\");\n rl.close();\n break;\n }\n }\n });\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n, t] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n let now = 1; if (t === now) { console.log('YES'); return; }\n for (let i = 0; i < nums.length;) {\n now = nums[i] + (i+1);\n if (t === now) {\n console.log('YES'); return;\n }\n i += nums[i];\n }\n\n console.log('NO');\n}); \n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet [n, t] = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\n\tconst a = readLine()\n\t\t.split(' ')\n\t\t.map(x => parseInt(x));\n\n\tconst graphHash = {};\n\n\tfor (let i = 1; i <= n - 1; ++i) {\n\t\tgraphHash[i] = i + a[i - 1];\n\t}\n\n\tconst stack = [1];\n\tlet found = false;\n\n\twhile (stack.length > 0) {\n\t\tlet u = stack.pop();\n\n\t\tif (graphHash[u] !== undefined) {\n\t\t\tif (graphHash[u] == t) {\n\t\t\t\tfound = true;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tstack.push(graphHash[u]);\n\t\t\t}\n\t\t}\n\t}\n\n\tfound ? console.log('YES') : console.log('NO');\n}\n"}, {"source_code": "let fs=require(\"fs\");\nlet txt=fs.readFileSync(0,\"utf-8\").split(/[\\r\\n]/).filter(data=>data.length);\nfor (let i = 0; i < txt.length; i+=2) {\n let info=txt[i].split(\" \")[1]*1;\n doit(info,txt[i+1].split(\" \").filter(data=>data.length>0).map(data=>data*1));\n \n}\n\nfunction doit(target,arr){\n let current=1;\n while (true) {\n if(current-1>=arr.length){\n console.log(\"NO\");\n return;\n }\n current=current+arr[current-1];\n if(current==target){\n console.log(\"YES\");\n return;\n }else if(current>target){\n console.log(\"NO\");\n return;\n }\n }\n\n \n}\n"}, {"source_code": "var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nn = numbers[0];\nt = numbers[1] - 1;\n\nvar numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nans = \"NO\"\ncur = 0\nwhile(cur < t){\n cur += numbers[cur]\n if(cur == t){\n ans = \"YES\"\n }\n}\n\nprint(ans)"}, {"source_code": "var s = readline().split(\" \");\nvar str = readline().split(\" \");\nvar f = 1;\n\t\tfor (var i=0; i<+s[0]; i++){\n\t\t\tif (f==+s[1]){\n\t\t\t\tf = 1;\n\t\t\t\tbreak;}\n\t\t\t\tf+=+str[f-1] \n\t\t}\nf==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var p = readline().split(\" \").map(function(x) { return parseInt(x); })[1] - 1;\nvar ar = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar pos = 0, found;\nwhile(true){\n if (pos == p) {\n found = 'YES';\n break;\n } else if (pos > p){\n found = 'NO'; \n break;\n }\n pos = pos + ar[pos];\n}\nprint (found);"}, {"source_code": "// var n = 4;\n// var t = 4;\n\n// var world = [2, 2, 1];\n\nvar nt = readline().split(' ');\nvar n = Number(nt[0]);\nvar t = Number(nt[1]);\n\nvar world = readline().split(' ').map(Number);\nvar res = 'NO';\nvar i = 0;\n\nwhile (i <= n - 1) {\n\tvar portal = i + 1;\n\n\tif (i + 1 == t) {\n\t\tres = 'YES';\n\t}\n\n\ti = portal + world[i] - 1;\n}\n\n//console.log(res);\nprint(res);"}, {"source_code": "var params = readline().split(\" \").map(value => +value);\nvar n = params[0], t = params[1];\nvar portals = readline().split(\" \").map(value => +value);\n\nvar i = 0, flag = false;\nwhile(i < n - 1) {\n\tif (portals[i] + i + 1 === t) {\n\t\tflag = true;\n\t\tbreak;\n\t}\n\n\ti += portals[i];\n}\n\nprint(flag ? \"YES\" : \"NO\");"}, {"source_code": "function sa(n,t,data){\n \n var current = 1;\n while(current <= t){\n if(current == t){\n return \"YES\";\n }\n current = current + data[current -1];\n }\n \n return \"NO\"\n }\n \n \n var f = readline().split(\" \").map(Number);\n var n = f[0];\n var t = f[1];\n var data = readline().split(\" \").map(Number);\n \n print(sa(n,t,data));"}, {"source_code": "var input = readline().split(' ').map(value => +value);\nvar n = input[0];\nvar t = input[1];\nvar a = readline().split(' ').map(value => +value);\n\nvar p = 1;\n\nwhile (p < t) {\n p += a[p - 1];\n}\n\nwrite(p === t ? 'YES' : 'NO');\n"}, {"source_code": "(function() {\n var input = readline().split(' ');\n var n = parseInt(input[0]);\n var t = parseInt(input[1]);\n var e = readline().split(' ');\n var cur = 1;\n while (cur < n) {\n if (cur == t) {\n break;\n }\n cur = cur + parseInt(e[cur - 1]);\n }\n if (cur == t) {\n write('YES');\n } else {\n write('NO');\n }\n})()"}, {"source_code": "var input = readline().split(' ').map(Number), n = input[0], t = input[1];\nvar a = readline().split(' ').map(Number);\nvar queue = [];\nvar flag = false;\nqueue.push(0);\nwhile (queue.length) {\n var pos = queue.pop();\n if (a[pos] + pos + 1 == t) { write('YES'); flag = true; break; }\n else if (a[pos] > 0) queue.push(a[pos] + pos);\n a[pos] = -1;\n}\nif (!flag) write('NO');"}, {"source_code": "function main() {\n var cellCount, movedToIndex = readline().split(/\\s/gi).map(Number);\n cellCount = movedToIndex[0], movedToIndex = movedToIndex[1];\n \n var lineList = [0].concat(readline().split(/\\s/gi)),\n cellList = [], index = 1,\n result = 'YES';\n\n while(true) {\n if(index == movedToIndex) break;\n if(index > movedToIndex) {\n result = 'NO';\n break;\n }\n var fromCell = index,\n toCell = fromCell + parseInt(lineList[fromCell]);\n \n index = toCell;\n };\n \n print(result);\n};\nmain();"}, {"source_code": "function main() {\n\tvar n, t;\n\tvar line = readline().split(\" \").map(Number);\n\tn = line[0]; t = line[1] - 1;\n\tvar value = readline().split(\" \").map(Number);\n\tvalue.push(0);\n\t\n\tvar cur = 0;\n\twhile (cur != t && value[cur] !== 0) {\n\t\tcur += value[cur];\n\t}\n\t\n\tif (cur == t)\n\t\tprint(\"YES\");\n\telse\n\t\tprint(\"NO\");\n}\n\nmain();"}, {"source_code": "var r = readline().split(' ');\nvar n = +r[0];\nvar t = +r[1];\nvar a = readline().split(' ');\nvar result = 'NO';\nfor (var i = 1; i <= t; ) {\n if (i == t) {\n result = 'YES';\n break;\n } else {\n i += +a[i - 1];\n }\n}\nprint(result);"}], "negative_code": [{"source_code": "// 500A - New Year Transportation\n// http://codeforces.com/problemset/problem/500/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\n// var getline;\nvar input = \"\";\nvar read;\nvar writeline = (x) => process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\n\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n // input = input.split(/\\r?\\n/);\n // getline = () => input.shift();\n input = input.split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});\n\n\nfunction main() {\n let n = parseInt(read()),\n t = parseInt(read());\n\n let arr = [];\n for (let i = 0; i < n - 1; i++) {\n let x = parseInt(read());\n arr.push(x);\n }\n\n let vis = new Array(n).fill(0);\n vis[0] = 1;\n for (let i = 0; i < n - 1; i++) {\n let j = i + arr[i];\n vis[j] = 1;\n }\n\n // dfs(0, vis);\n if (vis[t - 1] === 1) {\n writeline(\"YES\");\n } else {\n writeline(\"NO\");\n }\n\n\n return 0;\n}\n"}, {"source_code": "// 500A - New Year Transportation\n// http://codeforces.com/problemset/problem/500/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\n// var getline;\nvar input = \"\";\nvar read;\nvar writeline = (x) => process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\n\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n // input = input.split(/\\r?\\n/);\n // getline = () => input.shift();\n input = input.split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});\n\n\nfunction main() {\n let n = parseInt(read()),\n t = parseInt(read());\n\n let arr = [];\n for (let i = 0; i < n - 1; i++) {\n let x = parseInt(read());\n arr.push(x);\n }\n\n let vis = new Array(n).fill(0);\n vis[0] = 1;\n for (let i = 0; i < n - 1; i++) {\n let j = i + arr[i];\n vis[j] = 1;\n }\n\n // dfs(0, vis);\n if (vis[t - 1]) {\n writeline(\"YES\");\n } else {\n writeline(\"NO\");\n }\n\n\n return 0;\n}\n"}, {"source_code": "// 500A - New Year Transportation\n// http://codeforces.com/problemset/problem/500/A\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf8\");\n\n// var getline;\nvar input = \"\";\nvar read;\nvar writeline = (x) => process.stdout.write(x + \"\\n\");\nvar write = (x) => process.stdout.write(x);\n\nprocess.stdin.on(\"data\", (chunk) => input += chunk);\nprocess.stdin.on(\"end\", () => {\n // input = input.split(/\\r?\\n/);\n // getline = () => input.shift();\n input = input.split(/\\s+/);\n read = () => input.shift();\n process.exit(main() || 0);\n});\n\n\nfunction main() {\n let n = parseInt(read()),\n t = parseInt(read());\n\n let g = [...Array(n)].map(x => Array().fill([]));\n let arr = [];\n for (let i = 0; i < n - 1; i++) {\n let x = parseInt(read());\n arr.push(x);\n g[i].push(i + x);\n }\n\n function dfs(s, vis) {\n vis[s] = 1;\n for (const v of g[s]) {\n if (!vis[v]) {\n dfs(v, vis);\n }\n }\n }\n\n let vis = new Array(n).fill(0);\n vis[0] = 1;\n for (let i = 0; i < n-1; i++) {\n let j = i + arr[i];\n vis[j] = 1;\n }\n \n\n // dfs(0, vis);\n if (vis[t - 1]) {\n writeline(\"YES\");\n } else {\n writeline(\"NO\");\n }\n\n\n return 0;\n}\n"}, {"source_code": "//NYTransport.js\n\"use strict\"\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n arr2=[],\n x,y,i;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = nb.split(' ');\n arr2 = TC.split(' ');\n y = Number(arr[1]); //dest\n for(i = 0; i < y; i++){\n i = i+Number(arr2[i]);\n if(i+1 === y){\n console.log(\"YES\");\n rl.close();\n break;\n }else if(i+1 > y){\n console.log(\"NO\");\n rl.close();\n break;\n }\n }\n });\n});\n"}, {"source_code": "//NYTransport.js\n\"use strict\"\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n arr2=[],\n x,y,i;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = nb.split(' ');\n arr2 = TC.split(' ');\n y = Number(arr[1]); //dest\n for(i = 0; i < y; i++){\n i = i+Number(arr2[i]);\n if(i === y-1){\n console.log(\"YES\");\n rl.close();\n break;\n }else if(i > y-1){\n console.log(\"NO\");\n rl.close();\n break;\n }\n }\n });\n});\n"}, {"source_code": "//NYTransport.js\n\"use strict\"\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin\n});\nvar count=0,\n arr=[],\n arr2=[],\n x,y,i;\nrl.question('', (nb) => {\n rl.on('line', (TC) => {\n arr = nb.split(' ');\n arr2 = TC.split(' ');\n y = Number(arr[1]); //dest\n for(i = 0; i < y; i++){\n i = i+Number(arr2[i]);\n console.log(i)\n if(i+1 === y){\n console.log(\"YES\");\n rl.close();\n break;\n }else if(i+1 > y){\n console.log(\"NO\");\n rl.close();\n break;\n }\n }\n });\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n, t] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n let now = 1; if (t === now) { console.log('YES'); return; }\n for (let i = 0; i < nums.length; i += 1) {\n now += nums[i] + (i+1);\n if (t === now) {\n console.log('YES'); return;\n }\n }\n\n console.log('NO');\n}); \n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n, t] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n let now = 1; if (t === now) { console.log('YES'); return; }\n for (let i = 0; i < nums.length; i += 1) {\n now = nums[i] + (i+1);\n if (t === now) {\n console.log('YES'); return;\n }\n }\n\n console.log('NO');\n}); \n"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array_1 = readline().getNumArray(),\n n = array_1[0],\n t = array_1[1] - 1,\n array_2 = readline().getNumArray();\n\n for (let i = 0; i <= t; i++) {\n const a = array_2[i] ;\n if (a + i === t) {\n write('Yes');\n return;\n }\n }\nwrite('No');\n})();"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array_1 = readline().getNumArray(),\n n = array_1[0],\n t = array_1[1],\n array_2 = readline().getNumArray();\n\n for (let i = 0; i < t - 1; i++) {\n const a = array_2[i] ;\n if (a + 1 === array_2[t - 1]) {\n write('Yes');\n return;\n }\n }\nwrite('No');\n})();"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array_1 = readline().getNumArray(),\n n = array_1[0],\n t = array_1[1] - 1,\n array_2 = readline().getNumArray(),\n nextHome = 0;\n\n for (let i = 0; i <= t; i++) {\n const a = array_2[i] ;\n nextHome = a + i;\n if (nextHome === t) {\n write('Yes');\n return;\n }\n }\nwrite('No');\n})();"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array_1 = readline().getNumArray(),\n n = array_1[0],\n t = array_1[1],\n array_2 = readline().getNumArray();\n\n for (let i = 1; i <= t; i+=array_2[i - 1] + i) {\n if (i === t) {\n write('Yes');\n return;\n }\n }\nwrite('No');\n})();"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\n(function() {\n let array_1 = readline().getNumArray(),\n n = array_1[0],\n t = array_1[1],\n array_2 = readline().getNumArray();\n\n for (let i = 0; i < t - 1; i++) {\n const a = array_2[i] ;\n if (a + i === t - 1) {\n write('Yes');\n return;\n }\n }\nwrite('No');\n})();"}, {"source_code": "var s = readline().split(\" \");//readline();\nvar str = readline().split(\" \");\nvar res = 0;\nvar f = 0;\n\t\tfor (var i=0; i<+s[0]-1; i++){\n\t\t\tif (+str[i]+i+1==+s[1]){\n\t\t\t\tf = 1;\n\t\t\t\tbreak;}\n\t\t}\nf==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "var s = readline().split(\" \");//readline().split(\" \");//readline();\nvar str = readline().split(\" \");\nvar f = 1;\n\t\tfor (var i=0; i<+s[0]-1; i++){\n\t\n\t\t\tif (f==+s[1]){\n\t\t\t\tf = 1;\n\t\t\t\tbreak;}\n\t\t\t\t\tf+=+str[f-1] \n\t\t}\nf==1? print(\"YES\"):print(\"NO\");"}, {"source_code": "// var n = 8;\n// var t = 8;\n\n// var world = [1, 2, 1, 2, 1, 1, 1];\n\nvar nt = readline().split(' ');\nvar n = Number(nt[0]);\nvar t = Number(nt[1]);\n\nvar world = readline().split(' ').map(Number);\nvar res = 'NO';\nvar i = 0;\n\nwhile (i < n - 1) {\n\tvar portal = i + 1;\n\n\tif (i + 1 == t) {\n\t\tres = 'YES';\n\t}\n\n\ti = portal + world[i] - 1;\n}\n\n// console.log(res);\nprint(res);"}, {"source_code": "var t = readline().split(\" \").map(value => +value)[1];\nprint(\n\t(readline().split(\" \").map((value, index) => +value + index + 1).indexOf(t) === -1) ?\n\t\"NO\" : \"YES\");\n\t"}, {"source_code": "var t = readline().split(\" \").map(value => +value)[1];\nprint((readline().split(\" \").some((value, index) => +value + index + 1 === t)) ? \"YES\" : \"NO\");\n"}, {"source_code": "var input = readline().split(\" \").map((x) => parseInt(x));\nvar location = readline().split(\" \").map((x) => parseInt(x));\nvar position = input[1];\nvar counter = 1;\nvar found = false;\n\nwhile(counter < location.length) {\n if(counter === position) {\n print(\"YES\");\n found = true;\n break;\n } else {\n counter = counter + location[counter - 1];\n }\n}\n\nif(!found) {\n print(\"NO\");\n}"}, {"source_code": "var input = readline().split(\" \").map((x) => parseInt(x));\nvar location = readline().split(\" \").map((x) => parseInt(x));\nvar position = input[1];\nvar counter = 1;\nvar found = false;\n\nwhile(counter < location.length) {\n counter = counter + location[counter - 1];\n\n if(counter === position) {\n print(\"YES\");\n found = true;\n break;\n }\n}\n\nif(!found) {\n print(\"NO\");\n}"}, {"source_code": "(function() {\n var values = readline().split(\" \").map(Number);\n var n = values[0] - 1;\n var k = values[1];\n var arr = readline().split(\" \").map(Number);\n var save = 1;\n \n for (var i = 1; i < arr.length && save <= n; i++) {\n save = arr[save - 1] + save;\n if (save === k) {\n print(\"YES\");\n return;\n }\n }\n \n print(\"NO\");\n})();"}, {"source_code": "(function() {\n var values = readline().split(\" \").map(Number);\n var n = values[0] - 1;\n var k = values[1];\n var arr = readline().split(\" \").map(Number);\n var save = 1;\n \n for (var i = 1; i < arr.length && save < n; i++) {\n save = arr[save - 1] + save;\n if (save === k) {\n print(\"YES\");\n return;\n }\n }\n \n print(\"NO\");\n})();"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=1; i t) {\n canWe = false;\n break;\n }\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = false;\nvar i = 0;\nwhile (i parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=0; i t) {\n canWe = false;\n break;\n }\n i = a[i] + i;\n if (i === t) {\n canWe = true;\n break;\n }\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=0; i t) {\n canWe = false;\n break;\n }\n i = a[i] + i;\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=0; i<=t; i++) {\n i = a[i] + i;\n if (a[i] + i > t) {\n canWe = false;\n break;\n }\n}\nprint(canWe ? \"NO\" : \"YES\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=0; i<=t; i++) {\n i = a[i] + i;\n if (a[i] + i > t) {\n canWe = false;\n break;\n }\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=1; i t) {\n canWe = false;\n break;\n }\n i = a[i] + i;\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nvar i = 0;\nwhile (i t) {\n canWe = false;\n break;\n }\n i = a[i] + i + 1;\n if (i === t) {\n canWe = true;\n break;\n }\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nvar i = 0;\nwhile (i t) {\n canWe = false;\n break;\n }\n i = a[i] + i;\n if (i === t) {\n canWe = true;\n break;\n }\n}\nprint(canWe ? \"YES\" : \"NO\");"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst a = readline().split(\" \").map(x => parseInt(x));\nconst n = data[0];\nconst t = data[1];\nvar canWe = true;\nfor (var i=0; i t) {\n canWe = false;\n break;\n }\n i = a[i] + i + 1;\n}\nprint(canWe ? \"YES\" : \"NO\");"}], "src_uid": "9ee3d548f93390db0fc2f72500d9eeb0"} {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var k;\r\n if(len % 2 === 0) {\r\n k = len / 2;\r\n }else {\r\n k = (len - 1) / 2;\r\n }\r\n\r\n var char = str[k];\r\n while(str[k] == char && k > -1){\r\n count++;\r\n k--;\r\n }\r\n\r\n if(len % 2 === 0) {\r\n k = len / 2;\r\n }else {\r\n k = (len - 1) / 2;\r\n }\r\n\r\n while(str[k + 1] == char && k < len){\r\n count++;\r\n k++;\r\n }\r\n print(count);\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n const n = readLine();\r\n const string = readLine();\r\n let isFoundAnswer = false;\r\n\r\n if (n % 2 === 0) {\r\n for (let x = n / 2 - 1; x >= 0; x--) {\r\n if (string[x] != string[x - 1]) {\r\n console.log((n / 2 - x) * 2);\r\n isFoundAnswer = true;\r\n break;\r\n }\r\n }\r\n } else {\r\n for (let x = Math.floor(n / 2); x >= 0; x--) {\r\n if (string[x] != string[x - 1]) {\r\n console.log((n / 2 - x) * 2);\r\n isFoundAnswer = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (isFoundAnswer === false) {\r\n console.log(n);\r\n }\r\n}\r\n\r\nfunction main() {\r\n let T = readLine();\r\n while (T--) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = +readline()\r\n a = readline().split('') \r\n\r\n repeat = 0\r\n half = 0\r\n half = Math.floor(n/2)\r\n \r\n for(i = half; i< n-1; i++){\r\n if(a[i] ===a[i+1])\r\n repeat++\r\n else \r\n break\r\n }\r\n\r\n if(n%2 != 0)\r\n ans = 1 + 2*repeat\r\n else\r\n ans = 2 * (1+ repeat)\r\n print( ans)\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, s) {\r\n let res = 1,\r\n t = Math.floor((n - 1) / 2);\r\n for (let i = t + 1; i < n; i++) {\r\n if (s[i] === s[t]) res++;else break;\r\n }\r\n for (let i = t - 1; i >= 0; i--) {\r\n if (s[i] === s[t]) res++;else break;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const s = await read();\r\n res.push(solve(n, s));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const isPalindrome = str => str === str.split('').reverse().join('');\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let s = readline();\r\n\r\n let mid = Math.floor(n / 2);\r\n if (!isPalindrome(s.substring(0, mid) + s.substring(mid + 1))) {\r\n output(0);\r\n }\r\n let m = s[mid];\r\n let left = mid - 1;\r\n let right = mid + 1;\r\n\r\n let total = 1;\r\n\r\n const isOk = index => index >=0 && index < n && s[index] === m;\r\n\r\n while (isOk(left)) {\r\n left--;\r\n total++;\r\n }\r\n\r\n while (isOk(right)) {\r\n right++;\r\n total++;\r\n }\r\n\r\n output(total);\r\n }\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet currentLine = 0;\r\nlet inputString = \"\";\r\n\r\nprocess.stdin.on(\"data\", (raw_data) => {\r\n inputString += raw_data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n const n = readLine();\r\n const string = readLine();\r\n let isFoundAnswer = false;\r\n\r\n if (n % 2 === 0) {\r\n for (let x = 1; x < n; x++) {\r\n if (string[x] !== string[x - 1]) {\r\n console.log(n / 2 - x + 1);\r\n isFoundAnswer = true;\r\n break;\r\n }\r\n }\r\n if (!isFoundAnswer) {\r\n console.log(n);\r\n }\r\n } else {\r\n for (let x = 1; x < n; x++) {\r\n if (string[x] !== string[x - 1]) {\r\n console.log(Math.round(n - x) - 1);\r\n isFoundAnswer = true;\r\n break;\r\n }\r\n }\r\n if (!isFoundAnswer) {\r\n console.log(n);\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n let T = readLine();\r\n while (T--) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var k = Math.round(len / 2);\r\n var char = str[k];\r\n while(str[k] == char || k > -1){\r\n count++;\r\n k--;\r\n }\r\n k = Math.round(len / 2) + 1;\r\n while(str[k] == char || k < len){\r\n count++;\r\n k++;\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var k = Math.floor(len / 2);\r\n var char = str[k];\r\n while(str[k] == char){\r\n count++;\r\n if(k == len - 1){\r\n break;\r\n }\r\n k--;\r\n }\r\n while(str[k] == char){\r\n count++;\r\n if(k == len - 1){\r\n break;\r\n }\r\n k++;\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var k = Math.floor(len / 2);\r\n var char = str[k];\r\n while(str[k] == char){\r\n count++;\r\n if(k = len - 1){\r\n break;\r\n }\r\n k--;\r\n }\r\n while(str[k] == char){\r\n count++;\r\n if(k = len - 1){\r\n break;\r\n }\r\n k++;\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var k = Math.floor(len / 2);\r\n var char = str[k];\r\n while(str[k] == char){\r\n count++;\r\n if(k == len - 1){\r\n break;\r\n }\r\n k--;\r\n }\r\n while(str[k] == char){\r\n count++;\r\n if(k == len - 1){\r\n break;\r\n }\r\n k++;\r\n }\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n for(var k = 0; k < len; k++){\r\n var newStr = \"\";\r\n var newStrRev = \"\";\r\n\r\n var atrArr = str.split(\"\").splice(k, 1);\r\n\r\n for(var j = 0; j < len - 1; j++){\r\n newStr += atrArr[j];\r\n newStrRev += atrArr[len - 2 - j];\r\n }\r\n if(newStr == newStrRev) count++;\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n for(var k = 0; k < len; k++){\r\n var newStr = \"\";\r\n var newStrRev = \"\";\r\n \r\n str.split(\"\").splice(k, 1);\r\n\r\n for(var j = 0; j < len - 1; j++){\r\n newStr += str[j];\r\n newStrRev += str[len - 2 - j];\r\n }\r\n if(newStr == newStrRev) count++;\r\n }\r\n print(count);\r\n}\r\n\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n var newStr = \"\";\r\n var newStrRev = \"\";\r\n for(var k = 0; k < len; k++){\r\n str.split(\"\").splice(k, 1);\r\n\r\n for(var j = 0; j < len - 1; j++){\r\n newStr += str[j];\r\n newStrRev += str[len - 2 - j];\r\n }\r\n if(newStr == newStrRev) count++;\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var strNew = \"\";\r\n var strNewReversed = \"\";\r\n var temp = \"\";\r\n\r\n for(var k = 0; k < len; k++){\r\n strNew = str.split(\"\").splice(k, 1).join(\"\");\r\n var ispoll = true;\r\n for(var j = 0; j < strNew.length; j++){\r\n if(strNew[j] === strNew[strNew.length - j]) ispoll = false;\r\n }\r\n if(ispoll) {\r\n count++;\r\n }\r\n }\r\n print(count);\r\n}\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n\r\n var strNew = \"\";\r\n var strNewReversed = \"\";\r\n var temp = \"\";\r\n\r\n for(var k = 0; k < len; k++){\r\n temp = str.split(\"\").splice(k, 1);\r\n strNewReversed = temp.reverse().join(\"\");\r\n strNew = temp.join(\"\");\r\n if(strNew === strNewReversed) {\r\n count++;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++){\r\n var count = 0;\r\n var len = parseInt(readline(), 10);\r\n var str = readline();\r\n var strNew = \"\";\r\n var strNewReversed = \"\";\r\n var temp = \"\";\r\n for(var k = 0; k < str.length; k++){\r\n temp = str.split(\"\").splice(k, 1).join(\"\");\r\n strNewReversed = str.split(\"\").splice(k, 1).reverse().join(\"\");\r\n strNew = str.split(\"\").splice(k, 1).join(\"\");\r\n if(strNew === strNewReversed) count++;\r\n }\r\n print(count);\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = +readline()\r\n a = readline().split('') \r\n\r\n repeat = 0\r\n half = 0\r\n half = Math.ceil(n/2)\r\n \r\n for(i = half; i< n-1; i++){\r\n if(a[i] ===a[i+1])\r\n repeat++\r\n else \r\n break\r\n }\r\n\r\n if(n%2 != 0)\r\n ans = 1 + 2*repeat\r\n else\r\n ans = 2 * (1+ repeat)\r\n \r\n print( ans)\r\n}\r\n"}], "src_uid": "fa761cd247a815f105668b716c20f0b4"} {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', input => inputString += input);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n});\n\nfunction print(message) {\n console.log(message);\n}\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction readElements(parse = parseInt, separator = ' ') {\n return readLine().split(separator).map(input => parse ? parse(input) : input);\n}\n\nfunction main() {\n let zeros = 0;\n let ones = 0;\n const [_, queries] = readElements();\n const list = readLine().split(' ').map(input => {\n input = parseInt(input);\n if (input === 1) {\n ones++;\n } else {\n zeros++;\n }\n\n return input;\n });\n\n for (let q = 0; q < queries; q++) {\n const [type, value] = readElements();\n let index = value - 1;\n\n if(type === 2) {\n print((value <= ones) ? \"1\" : \"0\");\n } else {\n list[index] = 1 - list[index];\n if (list[index] === 1) {\n ones++;\n zeros--;\n } else{\n zeros++;\n ones--;\n }\n }\n }\n}\n \t\t\t\t\t\t\t \t\t \t \t\t \t \t\t\t\t \t\t", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\nvar mod = 1000000000 + 7\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var x = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, q] = readline().split(' ').map((x, iii) => {\r\n return x\r\n })\r\n var length1 = 0\r\n\r\n var a = readline().split(' ').map((x, iii) => {\r\n if (parseInt(x) === 1) length1++\r\n return parseInt(x)\r\n })\r\n\r\n for (let i = 0; i < q; i++) {\r\n var [x, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n if (x === 1) {\r\n if (a[k - 1] === 1) length1--\r\n if (a[k - 1] === 0) length1++\r\n a[k - 1] = 1 - a[k - 1]\r\n continue\r\n }\r\n if (k > length1) console.log(0)\r\n else console.log(1)\r\n }\r\n}"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', input => inputString += input);\nprocess.stdin.on('end', () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n});\n\nfunction print(message) {\n console.log(message);\n}\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction readElements(parse = parseInt, separator = ' ') {\n return readLine().split(separator).map(input => parse ? parse(input) : input);\n}\n\nfunction main() {\n let zeros = 0;\n let ones = 0;\n const [_, queries] = readElements();\n const list = readLine().split(' ').map(input => {\n input = parseInt(input);\n if (input === 1) {\n ones++;\n } else {\n zeros++;\n }\n\n return input;\n });\n\n for (let q = 0; q < queries; q++) {\n const [type, value] = readElements();\n let index = value - 1;\n\n if(type === 2) {\n print((value <= ones) ? \"1\" : \"0\");\n } else {\n list[index] = 1 - list[index];\n if (list[index] === 1) {\n ones++;\n zeros--;\n } else{\n zeros++;\n ones--;\n }\n }\n }\n}"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var [n, k] = input[0].split(\" \").map((i) => {\r\n return Number(i);\r\n })\r\n var arr = input[1].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var count = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] === 1) {\r\n count++;\r\n }\r\n }\r\n for (var i = 2; i < input.length; i++) {\r\n var [type, value] = input[i].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n if (type === 1) {\r\n var index = value - 1;\r\n arr[index] = 1 - arr[index];\r\n if (arr[index] === 0) {\r\n count--;\r\n } else {\r\n count++;\r\n }\r\n } else {\r\n if (value > count) {\r\n console.log(0);\r\n } else {\r\n console.log(1);\r\n }\r\n }\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar N = nextInt();\r\n\tvar Q = nextInt();\r\n\tvar list = nextIntArray(N);\r\n\tvar map = [0, 0];\r\n\tfor(var i = 0; i < N; i++){\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\tfor(var i = 0; i < Q; i++){\r\n\t\tvar t = nextInt();\r\n\t\tvar x = nextInt();\r\n\t\tif(t == 1){\r\n\t\t\tx--;\r\n\t\t\tmap[list[x]]--;\r\n\t\t\tlist[x] = 1 - list[x];\r\n\t\t\tmap[list[x]]++;\r\n\t\t}else{\r\n\t\t\tif(map[1] >= x){\r\n\t\t\t\tmyout(1);\r\n\t\t\t}else{\r\n\t\t\t\tmyout(0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var nq = readNumArray();\r\n var n = nq[0];\r\n var q = nq[1];\r\n var arr = readNumArray();\r\n var ones = 0;\r\n for (var i = 0; i < n; i++) {\r\n if (arr[i] === 1) {\r\n ones++;\r\n }\r\n }\r\n for (var i = 0; i < q; i++) {\r\n var tx = readNumArray();\r\n var t = tx[0];\r\n var x = tx[1];\r\n if (t === 1) {\r\n arr[x-1] = 1 - arr[x-1];\r\n if (arr[x-1]) {\r\n ones++\r\n } else {\r\n ones--;\r\n }\r\n }\r\n if (t === 2) {\r\n if (x <= ones) {\r\n print('1')\r\n } else {\r\n print('0')\r\n }\r\n }\r\n }\r\n}\r\n\r\nmain();"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\nvar mod = 1000000000 + 7\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var x = parseInt(readline())\r\n // var x = new Array(n)\r\n var [n, q] = readline().split(' ').map((x, iii) => {\r\n return x\r\n })\r\n var length1 = 0\r\n\r\n var a = readline().split(' ').map((x, iii) => {\r\n if (parseInt(x) === 1) length1++\r\n return parseInt(x)\r\n })\r\n\r\n for (let i = 0; i < q; i++) {\r\n var [x, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n if (x === 1) {\r\n if(a[k-1] ===1) length1--\r\n a[k - 1] = 1 - a[k - 1]\r\n continue\r\n }\r\n if(k>length1) console.log(0)\r\n else console.log(1)\r\n }\r\n}"}], "src_uid": "ccf7aba6ca9bbf39a5ec8a20ec018825"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n\n for (let i = 0; i < arr.length; i += 2) {\n if (arr[i] === 1 || arr[i + 1] === 1) {\n ans++;\n }\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n", "positive_code": [{"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let {0:n, 1:m} = {...input[0].split(' ')};\n n = parseInt(n); m = parseInt(m);\n\n let answer = 0;\n for(let i = 0; i < n; i++){\n const data = []; input[i+1].split(' ').forEach(j => data.push(parseInt(j)));\n for(j = 0; j < m*2; j+=2){\n if(data[j] === 1 || data[j+1] === 1)\n answer++;\n //console.log(`data[j] = ${data[j]}; data[j+1] = ${data[j+1]}`);\n }\n }\n\n console.log(answer);\n});\n\n\n"}, {"source_code": "function imp()\n{\n var oneline = readline();\n var elements = oneline.split(\" \");\n var n = parseInt(elements[0]);\n var m = parseInt(elements[1]);\n var count = 0;\n for(var i=1;i<=n;i++)\n {\n oneline = readline();\n elements = oneline.split(\" \");\n for(var j=0;j<2*m;j=j+2)\n if(elements[j] == '1' || elements[j+1] == '1')\n count++;\n }\n print(count);\n}\nimp();\n"}, {"source_code": "var inputs = readline().split(' '),\n\tn = parseInt(inputs[0]),\n\tm = parseInt(inputs[1]),\n\twindows = [],\n\tres = 0;\n\nfor (var i = 0; i < n; i++) {\n\tinputs = readline().split(' ');\n\twindows = windows.concat(inputs);\n}\n\nfor (var i = 0; i < windows.length; i+=2) {\n\tif (windows[i] == '1' || windows[i+1] == '1') ++res;\n}\n\nprint(res);"}, {"source_code": "var solve = function(a, n, m) {\n var ans = 0;\n for(var i=0;i 0) {\n var x = readline().split(' ');\n for(var i=1; i {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let idx = 0;\n\n while (idx < m) {\n for (let i = idx * m; i < (idx + 1) * m; i++) {\n if (arr[i] === 1) {\n ans++;\n break;\n }\n }\n\n idx++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "function imp()\n{\n var oneline = readline();\n var elements = oneline.split(\" \");\n var n = elements[0];\n var m = elements[1];\n var count = 0;\n for(var i=1;i<=n;i++)\n {\n oneline = readline();\n elements = oneline.split(\" \");\n for(var j=0;j total[max[p[u]]]) {\n max[p[u]] = u;\n }\n }\n\n if (!max[u]) {\n max[u] = u;\n }\n\n ans[u] = find(u);\n stack.pop();\n continue;\n }\n\n done[u] = true;\n total[u] = 1;\n // print (u, done[u]);\n\n if (e[u]) {\n for (var i = 0, len = e[u].length; i < len; i++) {\n stack.push(e[u][i]);\n }\n }\n}\n\n// print(total);\n// print(max);\n// print(ans);\n\nfor (i = 0; i < q; i++) {\n var v = parseInt(readline(), 10);\n print(ans[v]);\n}\n\n/**\n * functions below\n */\n\nfunction readInts() {\n return readline().split(' ').map(function(v) {\n return parseInt(v, 10);\n })\n}\n\nfunction find(u) {\n if (total[u] <= 2) {\n return u;\n }\n\n var half = total[u] / 2;\n\n if (total[max[u]] <= half) {\n return u;\n }\n\n var start = ans[max[u]];\n while (start != u) {\n var top = total[u] - total[start];\n var bottom = total[max[start]];\n if (top <= half && bottom <= half) {\n return start;\n }\n\n start = p[start];\n }\n\n return 0;\n}\n\nfunction dfs(u) {\n if (!e[u]) {\n ans[u] = u;\n max[u] = u;\n total[u] = 1;\n return 1;\n }\n\n var localMax = 0;\n var localMaxI = u;\n var tot = 1;\n for (var i = 0, len = e[u].length; i < len; i++) {\n var tmp = dfs(e[u][i]);\n tot += tmp;\n if (localMax < tmp) {\n localMax = tmp;\n localMaxI = e[u][i];\n }\n }\n \n total[u] = tot;\n max[u] = localMaxI;\n\n // calc ans\n ans[u] = find(u);\n\n return tot;\n}", "positive_code": [{"source_code": "\n\nvar nq = readInts();\nvar n = nq[0];\nvar q = nq[1];\n\nvar total = new Array(n + 1);\nvar max = new Array(n + 1);\nvar ans = new Array(n + 1);\nvar p = new Array(n + 1);\nvar e = new Array(n + 1);\nvar done = new Array(n + 1);\n\np[1] = 1;\ntotal[0] = 0;\n\nvar i = 0;\nvar ps = readInts();\nfor (; i < n - 1; i++) {\n p[i + 2] = ps[i];\n e[ps[i]] = e[ps[i]] || [];\n e[ps[i]].push(i + 2);\n}\n\nvar queue = [1];\ni = 0;\nwhile (1) {\n var to = e[queue[i]];\n if (to) {\n for (var j = 0; j < to.length; j++) {\n queue.push(to[j]);\n }\n }\n i++;\n if (i === queue.length) {\n break;\n }\n}\nqueue.reverse();\n\nfor (i = 0, len = queue.length; i < len; i++) {\n var u = queue[i];\n total[u] = 1;\n max[u] = 0;\n var to = e[u];\n if (to) {\n for (var j = 0; j < to.length; j++) {\n total[u] += total[to[j]];\n if (total[to[j]] > total[max[u]]) {\n max[u] = to[j];\n }\n }\n }\n if (!max[u]) {\n max[u] = u;\n }\n\n ans[u] = find(u);\n}\n\n // dfs(1);\n// var stack = [1];\n// while (stack.length) {\n// var u = stack[stack.length - 1];\n// // print (u, done[u]);\n// if (done[u]) {\n// if (u !== 1) {\n// total[p[u]] += total[u];\n// if (!max[p[u]] || total[u] > total[max[p[u]]]) {\n// max[p[u]] = u;\n// }\n// }\n\n// if (!max[u]) {\n// max[u] = u;\n// }\n\n// ans[u] = find(u);\n// stack.pop();\n// continue;\n// }\n\n// done[u] = true;\n// total[u] = 1;\n// // print (u, done[u]);\n\n// if (e[u]) {\n// for (var i = 0, len = e[u].length; i < len; i++) {\n// stack.push(e[u][i]);\n// }\n// }\n// }\n\n// print(total)\n// print(max)\n// print(ans)\n\n\nfor (i = 0; i < q; i++) {\n var v = parseInt(readline(), 10);\n print(ans[v]);\n}\n\n/**\n * functions below\n */\n\nfunction readInts() {\n return readline().split(' ').map(function(v) {\n return parseInt(v, 10);\n })\n}\n\nfunction find(u) {\n if (total[u] <= 2) {\n return u;\n }\n\n var half = total[u] / 2;\n\n if (total[max[u]] <= half) {\n return u;\n }\n\n var start = ans[max[u]];\n while (start != u) {\n var top = total[u] - total[start];\n var bottom = total[max[start]];\n if (top <= half && bottom <= half) {\n return start;\n }\n\n start = p[start];\n }\n\n return 0;\n}\n\nfunction dfs(u) {\n if (!e[u]) {\n ans[u] = u;\n max[u] = u;\n total[u] = 1;\n return 1;\n }\n\n var localMax = 0;\n var localMaxI = u;\n var tot = 1;\n for (var i = 0, len = e[u].length; i < len; i++) {\n var tmp = dfs(e[u][i]);\n tot += tmp;\n if (localMax < tmp) {\n localMax = tmp;\n localMaxI = e[u][i];\n }\n }\n \n total[u] = tot;\n max[u] = localMaxI;\n\n // calc ans\n ans[u] = find(u);\n\n return tot;\n}"}], "negative_code": [{"source_code": "\n\nvar nq = readInts();\nvar n = nq[0];\nvar q = nq[1];\n\nvar total = new Array(n + 1);\nvar max = new Array(n + 1);\nvar ans = new Array(n + 1);\nvar p = new Array(n + 1);\nvar e = new Array(n + 1);\nvar done = new Array(n + 1);\n\np[1] = 1;\n\nvar i = 0;\nvar ps = readInts();\nfor (; i < n - 1; i++) {\n p[i + 2] = ps[i];\n e[ps[i]] = e[ps[i]] || [];\n e[ps[i]].push(i + 2);\n}\n\n // dfs(1);\nvar stack = [1];\nwhile (stack.length) {\n var u = stack[stack.length - 1];\n // print (u, done[u]);\n if (done[u]) {\n if (u !== 1) {\n total[p[u]] += total[u];\n if (!max[p[u]] || total[u] > total[max[p[u]]]) {\n max[p[u]] = u;\n }\n }\n\n ans[u] = find(u);\n stack.pop();\n continue;\n }\n\n done[u] = true;\n total[u] = 1;\n // print (u, done[u]);\n\n if (e[u]) {\n for (var i = 0, len = e[u].length; i < len; i++) {\n stack.push(e[u][i]);\n }\n }\n}\n\nfor (i = 0; i < q; i++) {\n var v = parseInt(readline(), 10);\n print(ans[v]);\n}\n\n/**\n * functions below\n */\n\nfunction readInts() {\n return readline().split(' ').map(function(v) {\n return parseInt(v, 10);\n })\n}\n\nfunction find(u) {\n if (total[u] <= 2) {\n return u;\n }\n\n var half = total[u] / 2;\n\n if (max[u] <= half) {\n return u;\n }\n\n var start = ans[max[u]];\n while (start != u) {\n var top = total[u] - total[start];\n var bottom = total[max[start]];\n if (top <= half && bottom <= half) {\n return start;\n }\n\n start = p[start];\n }\n\n return 0;\n}\n\nfunction dfs(u) {\n if (!e[u]) {\n ans[u] = u;\n max[u] = u;\n total[u] = 1;\n return 1;\n }\n\n var localMax = 0;\n var localMaxI = u;\n var tot = 1;\n for (var i = 0, len = e[u].length; i < len; i++) {\n var tmp = dfs(e[u][i]);\n tot += tmp;\n if (localMax < tmp) {\n localMax = tmp;\n localMaxI = e[u][i];\n }\n }\n \n total[u] = tot;\n max[u] = localMaxI;\n\n // calc ans\n ans[u] = find(u);\n\n return tot;\n}"}], "src_uid": "7f15864d46f09ea6f117929565ccb867"} {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst get_cnt = ()=>{\n let cnt = new Map();\n for (let i=-2; i<=2; i++)\n cnt.set(i, 0);\n return cnt;\n};\n\nconst split = (arr)=>{\n let i=0;\n let sets = [];\n let cur_set = {l: 0, cnt: get_cnt()}\n while (i{\n debugger\n let power = cnt.get(2) + cnt.get(-2);\n let sign = (cnt.get(-2)+cnt.get(-1));\n let rm_left = 0;\n let rm_right = 0;\n if (sign%2==0){\n return {power, rm_left, rm_right};\n }\n let left_cnt = new Map(cnt);\n let right_cnt = new Map(cnt);\n let i;\n // rm_left\n for (i=l; i=l; i--){\n right_cnt.set(arr[i], right_cnt.get(arr[i])-1)\n if (arr[i]<0){\n break;\n }\n }\n let right_ans = {power: right_cnt.get(2) + right_cnt.get(-2), rm_left: 0, rm_right: r-i};\n if (left_ans.power>right_ans.power)\n return left_ans;\n else\n return right_ans;\n}\n\nconst calc = (arr, n)=>{\n let sets = split(arr);\n let maxPower = 0;\n let ans = [arr.length, 0];\n for (let set of sets){\n let {power, rm_left, rm_right} = processSet(set, arr);\n if (power>maxPower){\n maxPower = power;\n ans = [set.l+rm_left, n-set.r+rm_right];\n }\n }\n return ans.join(' ');\n //console.log(arr, '->', sets);\n return\n // set = {l: int, r: int, cnt: Map}\n let l=0, r=0;\n let cnt = new Map();\n for (let i=-2; i<=2; i++)\n cnt.set(i, 0);\n while (l 0) {\r\n if (Math.abs(a[b]) == 2) {\r\n bitsS--;\r\n }\r\n b++;\r\n }\r\n if (Math.abs(a[b]) == 2) {\r\n bitsS--;\r\n }\r\n var c = e;\r\n var bitsE = bits;\r\n while (a[c] > 0) {\r\n if (Math.abs(a[c]) == 2) {\r\n bitsE--;\r\n }\r\n c--;\r\n }\r\n if (Math.abs(a[c]) == 2) {\r\n bitsE--;\r\n }\r\n //console.log(bits, bitsS, bitsE)\r\n if (bitsS > bitsE) {\r\n return [bitsS, b+1, e];\r\n } else {\r\n return [bitsE, s, c-1];\r\n }\r\n } else {\r\n return [bits, s, e];\r\n }\r\n }\r\n var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n var start = 0;\r\n var ans = [1, 0, -1];\r\n while (start < n) {\r\n while (start < n && !a[start]) {\r\n start++;\r\n }\r\n var end = start+1;\r\n while (end < n && a[end]) {\r\n end++;\r\n }\r\n var reply = solve(start, end-1);\r\n //console.log(reply);\r\n if (reply[0] > ans[0]) {\r\n ans = reply;\r\n }\r\n start = end;\r\n }\r\n print(ans[1] + \" \" + (n - ans[2] - 1));\r\n }"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction getMax(a, start, end) {\r\n var _a, _b\r\n const n = end - start + 1\r\n let first = -1,\r\n last = -1,\r\n sum = new Array(n).fill(0),\r\n count = 0\r\n for (let i = 0; i < n; i++) {\r\n sum[i] = ((_a = sum[i - 1]) !== null && _a !== void 0 ? _a : 0) + (Math.abs(a[i + start]) === 2 ? 1 : 0)\r\n if (first === -1 && a[i + start] < 0) first = i\r\n if (a[i + start] < 0) {\r\n count++\r\n last = i\r\n }\r\n }\r\n if (count % 2 === 0) {\r\n return [sum[n - 1] * 2, start, end]\r\n } else {\r\n let left = ((_b = sum[last - 1]) !== null && _b !== void 0 ? _b : 0) * 2 + (last > 0 ? 1 : 0),\r\n right = (sum[n - 1] - sum[first]) * 2 + (first < n - 1 ? 1 : 0)\r\n if (left >= right) {\r\n return [left, start, start + last - 1]\r\n } else {\r\n return [right, start + first + 1, end]\r\n }\r\n }\r\n}\r\nfunction solve(n, a) {\r\n let left = -1,\r\n right = -1,\r\n max = 1\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) {\r\n let j = i\r\n while (j < n - 1 && a[j + 1] !== 0) j++\r\n const [num, l, r] = getMax(a, i, j)\r\n if (max < num) {\r\n max = num\r\n left = l\r\n right = r\r\n }\r\n i = j\r\n }\r\n }\r\n if (left === -1) return [0, n]\r\n else return [left, n - right - 1]\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++])\r\n const a = inputs[__++].trim().split(' ').map(Number)\r\n const [l, r] = solve(n, a)\r\n res.push(`${l} ${r}`)\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans, mx = 0;\r\n\t\tfor (let round = 0; round < 2; round++) {\r\n\t\t\tlet twos = 0, positive = 1, cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i] == 0) cnt = 0, twos = 0, positive = 1; else cnt++;\r\n\t\t\t\tif (a[i] < 0) positive ^= 1;\r\n\t\t\t\tif (Math.abs(a[i]) == 2) twos++;\r\n\t\t\t\tif (positive & twos > mx) {\r\n\t\t\t\t\tmx = twos;\r\n\t\t\t\t\tans = [(i + 1) - cnt, n - (i + 1)];\r\n\t\t\t\t\tif (round) ans.reverse();\r\n\t\t\t\t}\r\n\t\t\t\t//console.log({round, i, twos, positive, mx, cnt, ans});\r\n\t\t\t}\r\n\t\t\ta.reverse();\r\n\t\t}\r\n\r\n\t\tif (mx == 0) {\r\n\t\t\tconsole.log(n, 0);\r\n\t\t} else {\r\n\t\t\tconsole.log(ans.join(' '));\r\n\t\t}\r\n\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, nums) {\n let ans = [-1, 3 * n]\n let pos\n let neg\n let pp = -1, pn = -1\n let seg\n nums.forEach((x, i) => {\n if (i) {\n const [sp, vp] = pos\n const [sn, vn] = neg\n if (x > 0) {\n // pos *= x\n // neg *= x\n const pow = x === 1 ? 0 : 1\n pos = [1, vp + pow]\n neg = [sn, vn + pow]\n // ans = Math.max(ans, pos, neg)\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n // if (pos > ans) {\n if (cmp(pos, ans) > 0) {\n ans = pos\n seg = [pp, i]\n }\n } else if (x < 0) {\n const pow = x === -1 ? 0 : 1\n if (neg[0] < 0) {\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n // ;[pos, neg] = [neg * x, pos * x]\n pos = [-sn, vn + pow]\n neg = [-sp, vp + pow]\n ;[pp, pn] = [pn, pp]\n // ans = Math.max(ans, pos, neg)\n if (cmp(pos, ans) > 0) {\n ans = pos\n seg = [pp, i]\n }\n if (cmp(neg, ans) > 0) {\n ans = neg\n seg = [pn, i]\n }\n } else {\n if (pp < 0) pp = i\n // ;[pos, neg] = [1, pos * x]\n ;[pp, pn] = [-1, pp]\n pos = [1, 0]\n neg = [-1, vp + pow]\n // ans = Math.max(ans, neg)\n //\n if (cmp(neg, ans) > 0) {\n ans = neg\n seg = [pn, i]\n }\n }\n } else {\n // pos = 1\n // neg = 1\n pos = [1, 0]\n neg = [1, 0]\n pp = -1\n pn = -1\n // ans = Math.max(ans, 0)\n //\n if (cmp([1, -1], ans) > 0) {\n ans = [1, -1] // special 0\n seg = [i, i]\n }\n }\n } else {\n if (x > 0) {\n // pos = x\n // neg = 1\n pos = [1, x === 1 ? 0 : 1] // pos, power\n neg = [1, 0]\n ans = pos\n pp = i\n } else if (x < 0) {\n // pos = 1\n // neg = x\n pos = [1, 0]\n neg = [-1, x === -1 ? 0 : 1]\n ans = neg\n pn = i\n } else {\n // pos = 1\n // neg = 1\n pos = [1, 0]\n neg = [1, 0]\n ans = [1, -1]\n }\n // ans = Math.max(ans, x)\n seg = [i, i]\n }\n // console.log(pos, neg, ans)\n })\n// console.log(ans, seg)\n// return\n const [a, b] = seg\n if (cmp(ans, [1, -1]) <= 0) return [0, n].join(' ')\n return [a, n - 1 - b].join(' ')\n}\nfunction cmp(a, b) {\n const [sa, va] = a\n const [sb, vb] = b\n if (sa > 0 && sb > 0) {\n return va - vb\n } else if (sa < 0 && sb < 0) {\n return vb - va\n } else if (sa > 0) {\n return 1\n } else {\n return -1\n }\n}\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst lineReader = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet inputPos = 0;\r\nconst inputWords = [];\r\nlineReader.on('line', (line) => {\r\n inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));\r\n});\r\nlineReader.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(inputWords[inputPos++]));\r\n}\r\nfunction nextStr() {\r\n return inputWords[inputPos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nlet n;\r\nlet a;\r\nfunction solve() {\r\n const pre2 = af(n).fill(0);\r\n const preve = af(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n if (i > 0) {\r\n pre2[i] = pre2[i - 1];\r\n preve[i] = preve[i - 1];\r\n }\r\n if (a[i] == 0) {\r\n pre2[i] = 0;\r\n preve[i] = 0;\r\n }\r\n if (a[i] < 0) {\r\n preve[i]++;\r\n }\r\n if (Math.abs(a[i]) == 2) {\r\n pre2[i]++;\r\n }\r\n }\r\n const lim = af(n).fill(n);\r\n const lastve = af(n).fill(INIT);\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i < n - 1) {\r\n lim[i] = lim[i + 1];\r\n lastve[i] = lastve[i + 1];\r\n }\r\n if (a[i] == 0) {\r\n lim[i] = i;\r\n lastve[i] = INIT;\r\n }\r\n if (a[i] < 0 && lastve[i] == INIT) {\r\n lastve[i] = i;\r\n }\r\n }\r\n // printf(\"lim: %j\\n\", lim);\r\n // printf(\"lastve: %j\\n\", lastve);\r\n let best2 = 0;\r\n let l = 0;\r\n let r = 0; // [l,r)\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] == 0) {\r\n continue;\r\n }\r\n let j = lim[i];\r\n let cnt2 = pre2[j - 1] - (i > 0 ? pre2[i - 1] : 0);\r\n let cntve = preve[j - 1] - (i > 0 ? preve[i - 1] : 0);\r\n if ((cntve % 2) == 1) {\r\n j = lastve[i];\r\n if (j <= i) {\r\n continue;\r\n }\r\n cnt2 = pre2[j - 1] - (i > 0 ? pre2[i - 1] : 0);\r\n cntve = preve[j - 1] - (i > 0 ? preve[i - 1] : 0);\r\n }\r\n check((cntve % 2) == 0);\r\n if (cnt2 > best2) {\r\n best2 = cnt2;\r\n l = i;\r\n r = j;\r\n }\r\n }\r\n // printf(\"best2: %d\\n\", best2);\r\n printf(\"%d %d\\n\", l, n - r);\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n n = nextInt();\r\n a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n solve();\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nfunction getMax(a, start, end) {\r\n var _a, _b\r\n const n = end - start + 1\r\n let first = -1,\r\n last = -1,\r\n sum = new Array(n).fill(0),\r\n count = 0\r\n for (let i = 0; i <= n; i++) {\r\n sum[i] = ((_a = sum[i - 1]) !== null && _a !== void 0 ? _a : 0) + (Math.abs(a[i]) === 2 ? 1 : 0)\r\n if (first === -1 && a[i + start] < 0) first = i\r\n if (a[i + start] < 0) {\r\n count++\r\n last = i\r\n }\r\n }\r\n if (count % 2 === 0) {\r\n return [sum[n - 1] * 2, start, end]\r\n } else {\r\n let left = ((_b = sum[last - 1]) !== null && _b !== void 0 ? _b : 0) * 2 + (last > 0 ? 1 : 0),\r\n right = (sum[n - 1] - sum[first]) * 2 + (first < n - 1 ? 1 : 0)\r\n if (left >= right) {\r\n return [left, start, start + last - 1]\r\n } else {\r\n return [right, start + first + 1, end]\r\n }\r\n }\r\n}\r\nfunction solve(n, a) {\r\n let left = -1,\r\n right = -1,\r\n max = 1\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) {\r\n let j = i\r\n while (j < n - 1 && a[j + 1] !== 0) j++\r\n const [num, l, r] = getMax(a, i, j)\r\n if (max < num) {\r\n max = num\r\n left = l\r\n right = r\r\n }\r\n }\r\n }\r\n if (left === -1) return [0, n]\r\n else return [left, n - right - 1]\r\n}\r\n\r\nvoid (function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = []\r\n for (let _ = 0; _ < t; _++) {\r\n const n = Number(inputs[__++])\r\n const a = inputs[__++].trim().split(' ').map(Number)\r\n const [l, r] = solve(n, a)\r\n res.push(`${l} ${r}`)\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst _ = Number(inputs[0])\r\n\r\nmain(_, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].split(' ').map(Number)\r\n const check = (l, r) => {\r\n if (l === r) return\r\n let product = 1,\r\n count = 0\r\n\r\n for (let i = l; i < r; i++) {\r\n product *= data[i]\r\n if (data[i] < 0) count++\r\n }\r\n if (count % 2 === 0) {\r\n if (ans < product) {\r\n ans = product\r\n x = l\r\n y = n - r\r\n }\r\n return\r\n }\r\n\r\n let left = -1\r\n product = 1\r\n for (let i = l; i < r; i++) {\r\n if (left !== -1) {\r\n product *= data[i]\r\n }\r\n if (data[i] < 0 && left === -1) {\r\n left = i\r\n }\r\n }\r\n if (ans < product) {\r\n ans = product\r\n x = left + 1\r\n y = n - r\r\n }\r\n let right = -1\r\n product = 1\r\n for (let i = r - 1; i >= l; i--) {\r\n if (right !== -1) {\r\n product *= data[i]\r\n }\r\n if (data[i] < 0 && right === -1) {\r\n right = i\r\n }\r\n }\r\n if (ans < product) {\r\n ans = product\r\n x = l\r\n y = n - right\r\n }\r\n }\r\n\r\n let x = n,\r\n y = 0,\r\n ans = 1\r\n for (let i = 0, j = 0; j <= n; j++) {\r\n if (j === n || data[j] === 0) {\r\n check(i, j)\r\n i = j + 1\r\n }\r\n }\r\n res.push([x, y])\r\n }\r\n\r\n console.log(res.map(arr => arr.join(' ')).join('\\n'))\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst _ = Number(inputs[0])\r\n\r\nmain(_, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].split(' ').map(Number)\r\n const check = (l, r) => {\r\n if (l === r) return\r\n const products = []\r\n for (let i = l; i < r; i++) {\r\n products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])\r\n }\r\n\r\n let pre = -1\r\n for (let i = 0; i < products.length; i++) {\r\n let max = products[i]\r\n if (max > 0 || pre === -1) {\r\n if (ans < max) {\r\n ans = max\r\n x = l\r\n y = n - 1 - (l + i)\r\n }\r\n } else {\r\n max = products[i] / products[pre]\r\n if (ans < max) {\r\n ans = max\r\n x = l + pre + 1\r\n y = n - 1 - (l + pre + i)\r\n }\r\n }\r\n\r\n if (max < 0 && pre === -1) {\r\n pre = i\r\n }\r\n }\r\n }\r\n\r\n let x = 0,\r\n y = 0,\r\n ans = -Infinity\r\n for (let i = 0, j = 0; j <= n; j++) {\r\n if (j === n || data[j] === 0) {\r\n check(i, j)\r\n i = j + 1\r\n }\r\n }\r\n res.push([x, y])\r\n }\r\n\r\n console.log(res.map(arr => arr.join(' ')).join('\\n'))\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst _ = Number(inputs[0])\r\n\r\nmain(_, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].split(' ').map(Number)\r\n const check = (l, r) => {\r\n if (l === r) return\r\n const products = []\r\n for (let i = l; i < r; i++) {\r\n products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])\r\n }\r\n\r\n let pre = -1\r\n for (let i = 0; i < products.length; i++) {\r\n let max = products[i]\r\n if (max > 0 || pre === -1) {\r\n if (ans < max) {\r\n ans = max\r\n x = l\r\n y = n - 1 - (l + i)\r\n }\r\n } else {\r\n max = products[i] / products[pre]\r\n if (ans < max) {\r\n ans = max\r\n x = l + pre + 1\r\n y = n - 1 - (l + pre + i)\r\n }\r\n }\r\n\r\n if (max < 0 && pre === -1) {\r\n pre = i\r\n }\r\n }\r\n }\r\n let x = 0,\r\n y = n,\r\n ans = 1\r\n for (let i = 0, j = 0; j <= n; j++) {\r\n if (j === n || data[j] === 0) {\r\n check(i, j)\r\n i = j + 1\r\n }\r\n }\r\n res.push([x, y])\r\n }\r\n\r\n console.log(res.map(arr => arr.join(' ')).join('\\n'))\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst _ = Number(inputs[0])\r\n\r\nmain(_, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].split(' ').map(Number)\r\n const check = (l, r) => {\r\n if (l === r) return\r\n const products = []\r\n for (let i = l; i < r; i++) {\r\n products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])\r\n }\r\n\r\n let pre = -1\r\n for (let i = 0; i < products.length; i++) {\r\n let max = products[i]\r\n if (max > 0 || pre === -1) {\r\n if (ans < max) {\r\n ans = max\r\n x = l\r\n y = n - 1 - (l + i)\r\n }\r\n } else {\r\n max = products[i] / products[pre]\r\n if (ans < max) {\r\n ans = max\r\n x = l + pre\r\n y = n - 1 - (l + pre + i)\r\n }\r\n }\r\n\r\n if (max < 0 && pre === -1) {\r\n pre = i\r\n }\r\n }\r\n }\r\n let x = 0,\r\n y = n,\r\n ans = 1\r\n for (let i = 0, j = 0; j <= n; j++) {\r\n if (j === n || data[j] === 0) {\r\n check(i, j)\r\n i = j + 1\r\n }\r\n }\r\n res.push([x, y])\r\n }\r\n\r\n console.log(res.map(arr => arr.join(' ')).join('\\n'))\r\n}\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nconst _ = Number(inputs[0])\r\n\r\nmain(_, inputs)\r\n\r\nfunction main(_, lines) {\r\n let res = []\r\n for (let i = 0; i < _; i++) {\r\n const n = Number(lines[i * 2 + 1])\r\n const data = lines[i * 2 + 2].split(' ').map(Number)\r\n const check = (l, r) => {\r\n if (l === r) return\r\n const products = []\r\n for (let i = l; i < r; i++) {\r\n products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])\r\n }\r\n\r\n let pre = l\r\n for (let i = 0; i < products.length; i++) {\r\n let max = products[i]\r\n if (max > 0 || pre === -1) {\r\n if (ans < max) {\r\n ans = max\r\n x = l\r\n y = n - 1 - (l + i)\r\n }\r\n } else {\r\n max = products[i] / products[pre]\r\n if (ans < max) {\r\n ans = max\r\n x = pre + 1\r\n y = n - 1 - (pre + i)\r\n }\r\n }\r\n\r\n if (max < 0 && pre === -1) {\r\n pre = i\r\n }\r\n }\r\n }\r\n let x = 0,\r\n y = 0,\r\n ans = -Infinity\r\n for (let i = 0, j = 0; j <= n; j++) {\r\n if (j === n || data[j] === 0) {\r\n check(i, j)\r\n i = j + 1\r\n }\r\n }\r\n res.push([x, y])\r\n }\r\n\r\n console.log(res.map(arr => arr.join(' ')).join('\\n'))\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans, mx = 0;\r\n\t\tfor (let round = 0; round < 2; round++) {\r\n\t\t\tlet twos = 0, positive = 1, cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i] == 0) cnt = 0, twos = 0; else cnt++;\r\n\t\t\t\tif (a[i] < 0) positive ^= 1;\r\n\t\t\t\tif (Math.abs(a[i]) == 2) twos++;\r\n\t\t\t\tif (positive & twos > mx) {\r\n\t\t\t\t\tmx = twos;\r\n\t\t\t\t\tans = [(i + 1) - cnt, n - (i + 1)];\r\n\t\t\t\t\tif (round) ans.reverse();\r\n\t\t\t\t}\r\n\t\t\t\t//console.log({round, i, twos, positive, mx, cnt, ans});\r\n\t\t\t}\r\n\t\t\ta.reverse();\r\n\t\t}\r\n\r\n\t\tif (mx == 0) {\r\n\t\t\tconsole.log(n, 0);\r\n\t\t} else {\r\n\t\t\tconsole.log(ans.join(' '));\r\n\t\t}\r\n\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans, mx = 0;\r\n\t\tfor (let round = 0; round < 2; round++) {\r\n\t\t\tlet twos = 0, positive = 1, cnt = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (a[i] == 0) cnt = 0, twos = 0; else cnt++;\r\n\t\t\t\tif (a[i] < 0) positive ^= 1;\r\n\t\t\t\tif (Math.abs(a[i]) == 2) {\r\n\t\t\t\t\ttwos++;\r\n\t\t\t\t\tif (positive & twos > mx) {\r\n\t\t\t\t\t\tmx = twos;\r\n\t\t\t\t\t\tans = [(i + 1) - cnt, n - (i + 1)];\r\n\t\t\t\t\t\tif (round) ans.reverse();\r\n\t\t\t\t\t}\r\n\t\t\t\t\t//console.log({round, i, twos, positive, mx, cnt, ans});\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ta.reverse();\r\n\t\t}\r\n\r\n\t\tif (mx == 0) {\r\n\t\t\tconsole.log(n, 0);\r\n\t\t} else {\r\n\t\t\tconsole.log(ans.join(' '));\r\n\t\t}\r\n\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mx = 1, l, r;\r\n\t\tfor (let round = 0; round < 2; round++) {\r\n\t\t\tlet prod = 0, left = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tif (prod == 0) prod = 1;\r\n\t\t\t\tprod *= a[i];\r\n\t\t\t\tif (prod > mx) {\r\n\t\t\t\t\tmx = prod;\r\n\t\t\t\t\tif (round == 0) {\r\n\t\t\t\t\t\tl = left;\r\n\t\t\t\t\t\tr = i;\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tl = n - i - 1;\r\n\t\t\t\t\t\tr = n - left - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t//console.log({round, i, mx, l, r});\r\n\t\t\t\t}\r\n\t\t\t\tif (a[i] == 0) {\r\n\t\t\t\t\tleft = i + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ta.reverse();\r\n\t\t}\r\n\t\t//console.log({mx, l, r});\r\n\r\n\t\tif (mx == 1) {\r\n\t\t\tconsole.log(n, 0);\r\n\t\t} else {\r\n\t\t\tconsole.log(l, n - (r + 1));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, nums) {\n let ans = [-1, 3 * n]\n let pos\n let neg\n let pp = -1, pn = -1\n let seg\n nums.forEach((x, i) => {\n if (i) {\n const [sp, vp] = pos\n const [sn, vn] = neg\n if (x > 0) {\n // pos *= x\n // neg *= x\n const pow = x === 1 ? 0 : 1\n pos = [1, vp + pow]\n neg = [sn, vn + pow]\n // ans = Math.max(ans, pos, neg)\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n // if (pos > ans) {\n if (cmp(pos, ans) > 0) {\n ans = pos\n seg = [pp, i]\n }\n } else if (x < 0) {\n const pow = x === -1 ? 0 : 1\n if (neg[0] < 0) {\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n // ;[pos, neg] = [neg * x, pos * x]\n pos = [-sn, vn + pow]\n neg = [-sp, vp + pow]\n ;[pp, pn] = [pn, pp]\n // ans = Math.max(ans, pos, neg)\n if (cmp(pos, ans) > 0) {\n ans = pos\n seg = [pp, i]\n }\n if (cmp(neg, ans) > 0) {\n ans = neg\n seg = [pn, i]\n }\n } else {\n if (pp < 0) pp = i\n // ;[pos, neg] = [1, pos * x]\n ;[pp, pn] = [-1, pp]\n pos = [1, 0]\n neg = [-1, vp + pow]\n // ans = Math.max(ans, neg)\n //\n if (cmp(neg, ans) > 0) {\n ans = neg\n seg = [pn, i]\n }\n }\n } else {\n // pos = 1\n // neg = 1\n pos = [1, 0]\n neg = [1, 0]\n pp = -1\n pn = -1\n // ans = Math.max(ans, 0)\n //\n if (cmp([1, -1], ans)) {\n ans = [1, -1] // special 0\n seg = [i, i]\n }\n }\n } else {\n if (x > 0) {\n // pos = x\n // neg = 1\n pos = [1, x === 1 ? 0 : 1] // pos, power\n neg = [1, 0]\n ans = pos\n pp = i\n } else if (x < 0) {\n // pos = 1\n // neg = x\n pos = [1, 0]\n neg = [-1, x === -1 ? 0 : 1]\n ans = neg\n pn = i\n } else {\n // pos = 1\n // neg = 1\n pos = [1, 0]\n neg = [1, 0]\n ans = [1, -1]\n }\n // ans = Math.max(ans, x)\n seg = [i, i]\n }\n // console.log(pos, neg, ans)\n })\n// console.log(ans, seg)\n// return\n const [a, b] = seg\n if (cmp(ans, [1, -1]) <= 0) return [0, n].join(' ')\n return [a, n - 1 - b].join(' ')\n}\nfunction cmp(a, b) {\n const [sa, va] = a\n const [sb, vb] = b\n if (sa > 0 && sb > 0) {\n return va - vb\n } else if (sa < 0 && sb < 0) {\n return vb - va\n } else if (sa > 0) {\n return 1\n } else {\n return -1\n }\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, nums) {\n let ans = -Infinity\n let pos\n let neg\n let pp = -1, pn = -1\n let seg\n nums.forEach((x, i) => {\n if (i) {\n if (x > 0) {\n pos *= x\n neg *= x\n // ans = Math.max(ans, pos, neg)\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n if (pos > ans) {\n ans = pos\n seg = [pp, i]\n }\n } else if (x < 0) {\n if (neg < 0) {\n if (pp < 0) pp = i\n if (pn < 0) pn = i\n ;[pos, neg] = [neg * x, pos * x]\n ;[pp, pn] = [pn, pp]\n ans = Math.max(ans, pos, neg)\n //\n if (pos === ans) {\n seg = [pp, i]\n } else if (neg === ans) {\n seg = [pn, i]\n }\n } else {\n if (pp < 0) pp = i\n ;[pos, neg] = [1, pos * x]\n ;[pp, pn] = [-1, pp]\n ans = Math.max(ans, neg)\n //\n if (neg === ans) {\n seg = [pn, i]\n }\n }\n } else {\n pos = 1\n neg = 1\n pp = -1\n pn = -1\n ans = Math.max(ans, 0)\n //\n if (ans === 0) {\n seg = [i, i]\n }\n }\n } else {\n if (x > 0) {\n pos = x\n neg = 1\n pp = i\n } else if (x < 0) {\n pos = 1\n neg = x\n pn = i\n } else {\n pos = 1\n neg = 1\n }\n ans = Math.max(ans, x)\n seg = [i, i]\n }\n // console.log(pos, neg, ans)\n })\n// console.log(ans, seg)\n const [a, b] = seg\n if (ans <= 0) return [0, n].join(' ')\n return [a, n - 1 - b].join(' ')\n}\n"}], "src_uid": "7f71bea1c62b0a027c8d55431fbc7db7"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst d = rl();\r\n\r\n\t\tconst dpl = Array(n+1).fill(0);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (d[i-1] == 'L') {\r\n\t\t\t\tdpl[i]++;\r\n\t\t\t\tif (i-2 >= 0 && d[i-2] == 'R') {\r\n\t\t\t\t\tdpl[i]++;\r\n\t\t\t\t\tdpl[i] += dpl[i-2];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst dpr = Array(n+1).fill(0);\r\n\t\tfor (let i = n-1; i >= 0; i--) {\r\n\t\t\tif (d[i] == 'R') {\r\n\t\t\t\tdpr[i]++;\r\n\t\t\t\tif (i+1 < n && d[i+1] == 'L') {\r\n\t\t\t\t\tdpr[i]++;\r\n\t\t\t\t\tdpr[i] += dpr[i+2];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0 ; i <= n; i++) {\r\n\t\t\tans[i] = 1 + dpl[i] + dpr[i];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var x = new Array(n)\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n var dpl = new Array(n+1).fill(0)\r\n var dpr = new Array(n+1).fill(0)\r\n\r\n for (let i = 0; i <= n; i++) {\r\n if(i===0 || a[i-1] === 'R') dpl[i] = i\r\n else if(i===1 || a[i-2] === 'L') dpl[i] = i-1\r\n else dpl[i] = dpl[i-2]\r\n\r\n }\r\n\r\n for (let i = n; i >=0; i--) {\r\n if(i===n || a[i] === 'L') dpr[i] = i\r\n else if(i===n-1 || a[i+1] === 'R') dpr[i] = i+1\r\n else dpr[i] = dpr[i+2]\r\n }\r\n\r\n var res = new Array(n)\r\n for (let i = 0; i <= n; i++) {\r\n res[i] = i- dpl[i]+1 + dpr[i] - i\r\n }\r\n\r\n // console.log(dpl)\r\n // console.log(dpr)\r\n console.log(res.join(' '))\r\n\r\n // x = x.sort((a, b) => {\r\n // if (a.x - b.x === 0)\r\n // return a.y - b.y\r\n // return a.x - b.x\r\n // })\r\n // var res = []\r\n })\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "f51a46e87b8871c3f581786f84e5e6d1"} {"source_code": "print(function(n) {\n\tvar i, j, a = [];\n\n\tfor (i = 0; i < n; i++)\n\t\ta.push(readline());\n\n\tfor (i = 0; i < 20; i++)\n\t\tfor (j = 0; j < n; j++)\n\t\t\tif (a[j][i] !== a[0][i]) return i;\n\n\treturn 20;\n\n}(+readline()));", "positive_code": [{"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar s = readline(), b, l;\n\t\twhile (n--) {\n\t\t\tb = ''; l = readline();\n\n\t\t\tfor (var i = 0, _i = Math.min(l.length, s.length); i < _i; i++) {\n\t\t\t\tif (s[i] === l[i]) b += l[i];\n\t\t\t\telse break;\n\t\t\t}\n\n\t\t\ts = b;\n\t\t}\n\n\t\treturn s.length;\n\n\t}(+readline() - 1));\n\n}.call(this));\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst phones = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n phones.push(d);\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < phones[0].length; i++) {\n let code = phones[0][i];\n let isDiffer = false;\n for(let j = 0; j < phones.length; j++) {\n if (code !== phones[j][i]) {\n isDiffer = true;\n break;\n }\n }\n\n if (isDiffer) {\n break;\n }\n else {\n ans++;\n }\n }\n\n console.log(ans);\n});\n"}], "negative_code": [], "src_uid": "081b35620952bd32ce6d8ddc756e5c9d"} {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction greeting() {\r\n let t = parseInt(readLine());\r\nwhile(t > 0)\r\n{\r\n let n = parseInt(readLine());\r\n let s = readLine();\r\n \r\n if(n < 2)\r\n console.log(\"YES\");\r\n else if(n == 2 && s[0] != s[1])\r\n console.log(\"YES\");\r\n else\r\n {\r\n console.log(\"NO\");\r\n }\r\n \r\n t--;\r\n}\r\n}\r\n\r\nfunction main() {\r\n greeting();\r\n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var l = 1; l <= n * 2; l++){\n if(l % 2 === 0){\n var k = lines[l].split('').map(Number);\n var one = 0;\n var zero = 0;\n for(var j = 0; j < e; j++){\n if(k[j] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one <= 1 && zero <= 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }else{\n e = lines[l];\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var l = 1; l <= n * 2; l++){\n if(l % 2 === 0){\n var k = lines[l].split('').map(Number);\n var one = 0;\n var zero = 0;\n for(var j = 0; j < e; j++){\n if(k[j] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one <= 1 && zero <= 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }else{\n e = lines[l];\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet s = nl.line().split('');\n\t\tans.push((n == 2 && s[0] != s[1]) || n == 1);\n\t}\n\tconsole.log(ans.map(e => e?\"YES\":\"NO\").join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\n while(test--)\r\n {\r\n let noNeed = readLine();\r\n let string = readLine();\r\n if (string == \"0\" || string == \"01\" || string == \"10\" || string == \"10\" || string == \"1\"){\r\n console.log(\"YES\");\r\n }\r\n else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let trash = readline();\r\n let num = readline();\r\n let ones=0, zeroes =0;\r\n num.split(\"\").forEach(x => (x==1 ? ones++ : zeroes++));\r\n if(zeroes+ones == 1) console.log(\"YES\")\r\n else if(zeroes+ones == 2 && zeroes==ones) console.log(\"YES\")\r\n else console.log(\"NO\")\r\n }\r\n}"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(inputString);\n});\n\nfunction log(message){\n if(process.env.NODE_ENV === \"debug\"){\n console.log(message);\n }\n}\n\nconst YES = \"YES\"\nconst NO = \"NO\"\n\nfunction main(fileContents) {//input lines as an array\n // console.log(fileContents);\n fileContents.splice(0,1);\n for(let i = 1; i < fileContents.length; i+=2){\n const bs = fileContents[i];\n // console.log(\"BS\",bs)\n if(bs.length == 1){\n console.log(YES) // 0 1\n }else if(bs.length == 2){\n if(bs.charAt(0) === bs.charAt(1)){\n console.log(NO) // 11 00\n }else{\n console.log(YES) // 01 10\n }\n }else{\n console.log(NO)\n }\n }\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let size = readline();\n let s = readline();\n\n if (\n size === \"1\" ||\n (size === \"2\" && s === \"10\") ||\n (size === \"2\" && s === \"01\")\n ) {\n console.log(\"YES\");\n } else {\n console.log(\"NO\");\n }\n }\n}\n"}, {"source_code": "//readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar numbers = parseInt(readline());\r\nvar i =0;\r\nwhile(i < numbers) {\r\n\tvar n =parseInt(readline());\r\n\tvar a =(readline());\r\n\r\n\tprint(n > 2 || a === '00' || a === '11' ? 'NO' : 'YES'); // ends with newline\r\n\ti++;\r\n}\r\n\r\n//print(numbers[0] + numbers[1]); // ends with newline"}, {"source_code": "var t = parseInt(readline());\r\nwhile(t > 0)\r\n{\r\n var n = parseInt(readline());\r\n var s = readline();\r\n \r\n if(n < 2)\r\n print(\"YES\");\r\n else if(n == 2 && s[0] != s[1])\r\n print(\"YES\");\r\n else\r\n {\r\n print(\"NO\");\r\n }\r\n t--;\r\n}"}, {"source_code": "var x = parseInt(readline());\r\nfor(var i=0; i= 3 || (y == 2 && z[0] == z[1])) {\r\n print(\"NO\");\r\n }\r\n else {\r\n print(\"YES\");\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let _ = readSingleInt();\r\n while(_--){\r\n let n = readSingleInt();\r\n let st = readLine();\r\n if(n>2 || st=='11' || st=='00'){\r\n console.log(\"NO\");\r\n }else{\r\n console.log(\"YES\");\r\n }\r\n }\r\n\r\n}"}, {"source_code": "let data = \"\";\r\nlet some = 0;\r\n \r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n \r\n input = input.filter((el, idx) => idx % 2 !== 0);\r\n input.forEach((el) => {\r\n if (el.length > 2) {\r\n console.log(\"NO\");\r\n } else {\r\n if (el[0] === el[1]) {\r\n console.log(\"NO\");\r\n } else console.log(\"YES\");\r\n }\r\n });\r\n});"}, {"source_code": "let data = \"\";\r\n\r\nprocess.stdin.on(\"data\", (c) => (data += c));\r\nprocess.stdin.on(\"end\", () => {\r\n let [_, ...input] = data\r\n .trim()\r\n .split(/\\n/)\r\n .map((el) => el.trim());\r\n\r\n input = input.filter((el, idx) => idx % 2 !== 0);\r\n input.forEach((el) => {\r\n if (el.length > 2) {\r\n console.log(\"NO\");\r\n } else {\r\n if (el[0] === el[1]) {\r\n console.log(\"NO\");\r\n } else console.log(\"YES\");\r\n }\r\n });\r\n});\r\n"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\nfunction palindrome(arr) {\r\n if (arr.length <= 1) {\r\n return false;\r\n }\r\n for (let i = 0, j = arr.length - 1; i < j; i++, j--) {\r\n if (arr[i] !== arr[j]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\nfunction permutationGenerator(arr, n, permutation, permutations) {\r\n if (permutation.length === arr.length) {\r\n permutations.push(permutation.slice().join(\"\"));\r\n } else {\r\n for (let i = n; i < arr.length; i++) {\r\n let temp = arr[n];\r\n arr[n] = arr[i];\r\n arr[i] = temp;\r\n permutation.push(arr[n]);\r\n permutationGenerator(arr, n + 1, permutation, permutations);\r\n temp = arr[n];\r\n arr[n] = arr[i];\r\n arr[i] = temp;\r\n permutation.pop();\r\n }\r\n }\r\n}\r\nfunction subsetGenerator(arr, n, subsets, subset) {\r\n if (n === arr.length) {\r\n subsets.push(subset.slice().join(\"\"));\r\n } else {\r\n subsetGenerator(arr, n + 1, subsets, subset);\r\n subset.push(arr[n]);\r\n subsetGenerator(arr, n + 1, subsets, subset);\r\n subset.pop();\r\n }\r\n}\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0].trim());\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++].trim());\r\n let s = lines[i++].trim();\r\n if (n == 1) {\r\n console.log(\"YES\");\r\n } else if (n == 2) {\r\n if (s[0] !== s[1]) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let s = readline().split('').map(Number);\r\n\r\n if (s.length > 2) {\r\n output('NO');\r\n } else if (s[0] === s[1]) {\r\n output('NO');\r\n } else {\r\n output('YES');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = nextCharArray();\r\n\t\tif(N >= 3){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}else if(N == 1){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tvar set = new Set(S);\r\n\t\t\tif(set.size == 1){\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let _ = readSingleInt();\r\n while(_--){\r\n let n = readSingleInt();\r\n let st = readLine();\r\n if(n>2){\r\n console.log(\"NO\");\r\n }else{\r\n console.log(\"YES\");\r\n }\r\n }\r\n\r\n}"}, {"source_code": "//readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar numbers = parseInt(readline());\r\nvar i =0;\r\nwhile(i < numbers) {\r\n\tvar n =parseInt(readline());\r\n\tvar a =parseInt(readline());\r\n\r\n\tprint(n > 2 || a === '00' || a === '11' ? 'NO' : 'YES'); // ends with newline\r\n\ti++;\r\n}\r\n\r\n//print(numbers[0] + numbers[1]); // ends with newline"}, {"source_code": "//readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar numbers = parseInt(readline());\r\nvar i =0;\r\nwhile(i < numbers) {\r\n\tvar n =parseInt(readline());\r\n\tvar a =parseInt(readline());\r\n\r\n\tprint(n > 2 ? 'NO' : 'YES'); // ends with newline\r\n\ti++;\r\n}\r\n\r\n//print(numbers[0] + numbers[1]); // ends with newline"}, {"source_code": "//readline().split(\" \").map(function(x) { return parseInt(x); });\r\nvar numbers = parseInt(readline());\r\n\r\nfor (var i in numbers) {\r\n\tvar n =parseInt(readline());\r\n\tvar a =parseInt(readline());\r\n\r\n\tprint(n > 2 ? 'NO' : 'YES'); // ends with newline\r\n}\r\n\r\n//print(numbers[0] + numbers[1]); // ends with newline"}], "src_uid": "354658f565e265c2a1ce37355d6466e1"} {"source_code": "const readline = require('readline');\n\nlet count, array, previous = 0, counters = [];\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', (line) => {\n if (!count) {\n count = parseInt(line.trim());\n\n if (count < 2 || count > 100000) {\n rl.close();\n }\n } else if (!array) {\n array = line.trim().split(\" \").map (symbol => parseInt(symbol));\n\n rl.close();\n }\n}).on('close', () => {\n array.forEach(element => {\n if (previous == element) {\n counters[counters.length - 1] += 1;\n } else {\n counters.push(1)\n }\n\n previous = element;\n });\n\n var result = 0;\n\n for (let i = 0; i < counters.length; i++) {\n if (i + 1 == counters.length) break;\n\n let value = Math.min(counters[i], counters[i + 1]) * 2;\n\n result = Math.max(value, result);\n }\n\n console.log(result);\n});", "positive_code": [{"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = input.split(EOL)\nl = []\ncount = 0\nlines[1] = lines[1].replace(/\\ /g, '')\nlines[1] = Array.from(lines[1])\nlastchar = lines[1][0]\nfor (var i in lines[1]){\n if (lines[1][i] != lastchar){\n l.push(count)\n count = 1\n lastchar = lines[1][i]\n }\n else{\n count += 1\n }\n}\nl.push(count)\nmx = 0\nfor (var i = 0; i < l.length -1; i++){\n mx = Math.max(mx, Math.min(l[i], l[i+1]))\n}\nconsole.log(mx * 2)\n})"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = input.split(EOL)\n let line = lines[1]\n line = line.replace(/\\ /g, '')\n let cache = ['1', 0, 0]\n let max = 0\n for (let i = 0; i < line.length; i++) {\n if (line[i] == cache[0]) {\n cache[2]++\n } else {\n cache[0] = line[i]\n cache[1] = cache[2]\n cache[2] = 1\n }\n if (Math.min(cache[1], cache[2]) > max) {\n max = Math.min(cache[1], cache[2])\n }\n }\n console.log(max * 2)\n})\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet n = parseInt(line[0],10);\n\tlet a = line[1].split(' ').map(v => parseInt(v,10));\n\tlet t = a[0];\n\tlet c = 0;\n\tlet x = [];\n\tfor(let i of a){\n\t\tif (t == i){\n\t\t\tc++;\n\t\t} else {\n\t\t\tx.push(c);\n\t\t\tc = 1;\n\t\t\tt = i;\n\t\t}\n\t}\n\tx.push(c);\n\t\n\tlet m = 0;\n\tt = 0;\n\tfor(let i of x){\n\t\tif (Math.min(t,i) > m){\n\t\t\tm = Math.min(t,i);\n\t\t}\n\t\tt = i;\n\t}\n\tconsole.log(2 * m);\n};\n\nprocess.stdin.on('end', solution);\n"}, {"source_code": "// const print = require('lol-io').print;\n// const readline = require('lol-io').readline;\n\nconst t = readline();\nconst arr = readline().split(' ');\n\nconst obj = {\n\t0: 0,\n\t1: 0,\n};\n\nconst a = arr.map(i => {\n\treturn i == 1 ? 1 : 0;\n});\n\n\nvar maxSegment = 0;\nvar flag = 0;\n\nif (a[0] === 0) {\n\tflag = 0;\n} else flag = 1;\n\nfor (var i = 0; i < a.length; i++) {\n\tobj[a[i]]++;\n\n\t// if (obj[0] <= obj[1] ) {\n\tif (flag !== a[i]) {\n\t\tobj[a[i]] = 1;\n\t\tflag = +(!flag);\n\t}\n\n\tmaxSegment =\n\t\tMath.min(obj[0], obj[1]) > maxSegment\n\t\t\t? Math.min(obj[0], obj[1])\n\t\t\t: maxSegment;\n\n\t// if (obj[0] > maxSegment) maxSegment = obj[0];\n\t// obj[!a[i]] = 0;\n\t// } else if()\n}\n// console.log(maxSegment * 2);\nmaxSegment = maxSegment * 2;\nprint(maxSegment);\n"}, {"source_code": "// const print = require('lol-io').print;\n// const readline = require('lol-io').readline;\n\nconst t = readline();\nconst arr = readline().split(' ');\n\nconst obj = {\n\t0: 0,\n\t1: 0,\n};\n\nconst a = arr.map(i => {\n\treturn i == 1 ? 1 : 0;\n});\n\n\nvar maxSegment = 0;\nvar flag = 0;\n\nif (a[0] === 0) {\n\tflag = 0;\n} else flag = 1;\n\nfor (var i = 0; i < a.length; i++) {\n\tobj[a[i]]++;\n\n\t// if (obj[0] <= obj[1] ) {\n\tif (flag !== a[i]) {\n\t\tobj[a[i]] = 1;\n\t\tflag = +(!flag);\n\t}\n\n\tmaxSegment =\n\t\tMath.min(obj[0], obj[1]) > maxSegment\n\t\t\t? Math.min(obj[0], obj[1])\n\t\t\t: maxSegment;\n\n\t// if (obj[0] > maxSegment) maxSegment = obj[0];\n\t// obj[!a[i]] = 0;\n\t// } else if()\n}\n// console.log(maxSegment * 2);\nmaxSegment = maxSegment * 2;\nprint(maxSegment);\n"}, {"source_code": "var numOfLines = readline();\nvar nums = readline().split(' ').map(function(num) {\n return parseInt(num);\n})\n\nfunction min(a, b) {\n if (a < b) \n return a;\n if (b <= a)\n return b;\n}\n\nfunction max(a, b) {\n if (a < b) \n return b;\n if (b <= a)\n return a;\n}\n\nfunction main() {\n var currentSegment = 1;\n var prevSegment = 0;\n var maxSegments = 0;\n var currentNum = nums[0];\n\n for (var i = 1; i < nums.length; i++) {\n if (nums[i] === currentNum)\n currentSegment++;\n else {\n maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));\n prevSegment = currentSegment;\n currentSegment = 1;\n currentNum = nums[i];\n }\n }\n\n maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));\n\n write(maxSegments)\n}\n\nmain()"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString\n .replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n console.log(findMaxSushiSeq(inputString[1].split(' ')));\n});\n\nconst findMaxSushiSeq = (data) => {\n let high = 0;\n let low = 0;\n let i = 0;\n let max = 0;\n while (i < data.length) {\n if (data[i] !== data[high]) {\n low = high;\n high = i;\n }\n\n if (high > low) {\n max = Math.max(max, (Math.min(i - high + 1, high - low) * 2));\n }\n\n i++;\n }\n return max;\n};\n\n"}, {"source_code": "Array.prototype.eachTwo = function(callback) {\n for (let i = 0; i < this.length; i++) {\n if (i + 1 == this.length) break;\n\n callback(this[i], this[i + 1]);\n }\n}\n\nconst readline = require('readline');\n\nlet iteration = 0, count, array, previous = 0, counters = [];\n\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on('line', (line) => {\n if (iteration == 0) {\n count = parseInt(line.trim());\n iteration++;\n\n if (count < 2 || count > 100000) {\n rl.close();\n }\n } else {\n array = line.trim().split(\" \").map (symbol => parseInt(symbol));\n iteration++;\n\n rl.close();\n }\n\n if (iteration != 2) { return; }\n\n array.forEach(element => {\n if (element == 1) {\n if (previous == 1) {\n counters[counters.length - 1] += 1;\n } else {\n counters.push(1)\n }\n \n previous = 1\n }\n \n if (element == 2) {\n if (previous == 2) {\n counters[counters.length - 1] += 1;\n } else {\n counters.push(1)\n }\n \n previous = 2\n }\n });\n\n var result = 0\n\n counters.eachTwo(function(first, second) {\n let value = Math.min(first, second) * 2;\n \n if (value > result) {\n result = value\n }\n });\n\n console.log(result);\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let count = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] !== arr[i - 1]) {\n count++;\n\n if (count === 2) {\n count = 1;\n\n if (arr[i - 1] === 1) {\n twos = 0;\n }\n\n if (arr[i - 1] === 2) {\n ones = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n ones++;\n }\n\n if (arr[i] === 2) {\n twos++;\n }\n\n max = Math.max(max, Math.min(ones, twos) * 2);\n }\n\n console.log(max);\n c++;\n});\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', function() {\n inputString = inputString\n .split('\\n');\n\n console.log(findMaxSushiSeq(inputString[1].split(' ')));\n});\n\nconst findMaxSushiSeq = (data) => {\n let high = 0;\n let low = 0;\n let i = 0;\n let max = 0;\n while (i < data.length) {\n if (data[i] !== data[high]) {\n low = high;\n high = i;\n }\n\n if (high > low) {\n max = Math.max(max, (Math.min(i - high + 1, high - low) * 2));\n }\n\n i++;\n }\n return max;\n};\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let type1 = 0;\n let type2 = 0;\n let switchCount = 0;\n let prev = arr[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (prev !== arr[i]) {\n switchCount++;\n\n if (switchCount === 2) {\n switchCount = 0\n if (prev === 1) {\n type2 = 0;\n }\n else {\n type1 = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n type1++;\n }\n\n if (arr[i] === 2) {\n type2++;\n }\n\n if (type1 === type2) {\n max = Math.max(max, type1 + type2);\n }\n\n prev = arr[i];\n }\n\n console.log(max);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let count = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] !== arr[i - 1]) {\n count++;\n\n if (count === 2) {\n count = 0;\n\n if (arr[i - 1] === 1) {\n twos = 0;\n }\n\n if (arr[i - 1] === 2) {\n ones = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n ones++;\n }\n\n if (arr[i] === 2) {\n twos++;\n }\n\n max = Math.max(max, Math.min(ones, twos) * 2);\n }\n\n console.log(max);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n\n n = +d;\n return;\n }\n\n if (n === 100000) {\n console.log(d);\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let count = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] !== arr[i - 1]) {\n count++;\n\n if (count === 2) {\n count = 0;\n\n if (arr[i - 1] === 1) {\n twos = 0;\n }\n\n if (arr[i - 1] === 2) {\n ones = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n ones++;\n }\n\n if (arr[i] === 2) {\n twos++;\n }\n\n max = Math.max(max, Math.min(ones, twos) * 2);\n }\n\n console.log(max);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let type1 = 0;\n let type2 = 0;\n let switchCount = 0;\n let prev = arr[0];\n\n for (let i = 0; i < arr.length; i++) {\n if (prev !== arr[i]) {\n switchCount++;\n\n if (switchCount === 2) {\n switchCount = 0\n if (prev === 1) {\n type2 = 0;\n }\n else {\n type1 = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n type1++;\n }\n\n if (arr[i] === 2) {\n type2++;\n }\n\n max = Math.max(max, Math.min(type1, type2) + Math.min(type1, type2));\n\n prev = arr[i];\n }\n\n console.log(max);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let max = 0;\n let count = 0;\n let ones = 0;\n let twos = 0;\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] !== arr[i - 1]) {\n count++;\n\n if (count === 2) {\n count = 0;\n\n if (arr[i - 1] === 1) {\n twos = 0;\n }\n\n if (arr[i - 1] === 2) {\n ones = 0;\n }\n }\n }\n\n if (arr[i] === 1) {\n ones++;\n }\n\n if (arr[i] === 2) {\n twos++;\n }\n\n max = Math.max(max, Math.min(ones, twos) * 2);\n }\n\n console.log(max);\n c++;\n});\n"}, {"source_code": "var numOfLines = readline();\nvar nums = readline().split(' ').map(function(num) {\n return parseInt(num);\n})\n\nfunction min(a, b) {\n if (a < b) \n return a;\n if (b <= a)\n return b;\n}\n\nfunction max(a, b) {\n if (a < b) \n return b;\n if (b <= a)\n return a;\n}\n\nfunction main() {\n var currentSegment = 0;\n var prevSegment = 0;\n var maxSegments = 0;\n var currentNum = nums[0];\n\n for (var i = 1; i < nums.length; i++) {\n if (nums[i] === currentNum)\n currentSegment++;\n else {\n maxSegments = max(maxSegments, min(prevSegment, currentSegment));\n prevSegment = currentSegment;\n currentSegment = 1;\n currentNum = nums[i];\n }\n }\n\n maxSegments = max(maxSegments, 2*min(prevSegment, currentSegment));\n\n write(maxSegments)\n}\n\nmain()"}, {"source_code": "var numOfLines = readline();\nvar nums = readline().split(' ').map(function(num) {\n return parseInt(num);\n})\n\nfunction min(a, b) {\n if (a < b) \n return a;\n if (b <= a)\n return b;\n}\n\nfunction max(a, b) {\n if (a < b) \n return b;\n if (b <= a)\n return a;\n}\n\nfunction main() {\n var currentSegment = 1;\n var prevSegment = 0;\n var maxSegments = 0;\n var currentNum = nums[0];\n\n for (var i = 1; i < nums.length; i++) {\n if (nums[i] === currentNum)\n currentSegment++;\n else {\n maxSegments = max(maxSegments, min(prevSegment, currentSegment));\n prevSegment = currentSegment;\n currentSegment = 1;\n currentNum = nums[i];\n }\n }\n\n maxSegments = max(maxSegments, 2*min(prevSegment, currentSegment));\n\n write(maxSegments)\n}\n\nmain()"}, {"source_code": "var numOfLines = readline();\nvar nums = readline().split(' ').map(function(num) {\n return parseInt(num);\n})\n\nfunction min(a, b) {\n if (a < b) \n return a;\n if (b <= a)\n return b;\n}\n\nfunction max(a, b) {\n if (a < b) \n return b;\n if (b <= a)\n return a;\n}\n\nfunction main() {\n var currentSegment = 1;\n var prevSegment = 0;\n var maxSegments = 0;\n var currentNum = nums[0];\n\n for (var i = 1; i < nums.length; i++) {\n if (nums[i] === currentNum)\n currentSegment++;\n else {\n maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));\n prevSegment = currentSegment;\n currentSegment = 1;\n currentNum = nums[i];\n }\n }\n\n maxSegments = max(maxSegments, min(prevSegment, currentSegment));\n\n write(maxSegments)\n}\n\nmain()"}], "src_uid": "6477fdad8455f57555f93c021995bb4d"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\twhile(true){\r\n\t\t\tvar isOK = true;\r\n\t\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\t\tif(list[i] > list[i + 1]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(isOK){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif(output % 2 == 0){\r\n\t\t\t\tfor(var i = 0; i < N - 2; i += 2){\r\n\t\t\t\t\tif(list[i] > list[i + 1]){\r\n\t\t\t\t\t\tvar tmp = list[i];\r\n\t\t\t\t\t\tlist[i] = list[i + 1];\r\n\t\t\t\t\t\tlist[i + 1] = tmp;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tfor(var i = 1; i < N - 1; i += 2){\r\n\t\t\t\t\tif(list[i] > list[i + 1]){\r\n\t\t\t\t\t\tvar tmp = list[i];\r\n\t\t\t\t\t\tlist[i] = list[i + 1];\r\n\t\t\t\t\t\tlist[i + 1] = tmp;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\toutput++;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}", "positive_code": [{"source_code": "let i = ''\r\nlet lines;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n lines = i.split('\\n'); // your input text, split by lines\r\n main();\r\n});\r\n\r\nfunction isSorted(p) {\r\n for (let i = 0; i < p.length - 1; i++) {\r\n if (p[i] > p[i + 1]) {\r\n return false\r\n }\r\n }\r\n return true\r\n}\r\n\r\nfunction sort(p, i) {\r\n if (i % 2 === 0) {\r\n for (let j = 1; j < p.length - 1; j = j + 2) {\r\n if (p[j] > p[j + 1]) {\r\n const aux = p[j]\r\n p[j] = p[j + 1]\r\n p[j + 1] = aux\r\n }\r\n }\r\n } else {\r\n for (let j = 0; j < p.length - 1; j = j + 2) {\r\n if (p[j] > p[j + 1]) {\r\n const aux = p[j]\r\n p[j] = p[j + 1]\r\n p[j + 1] = aux\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n let t = parseInt(lines.shift())\r\n\r\n while (t > 0) {\r\n lines.shift()\r\n let p = lines.shift().split(' ').map(x => parseInt(x))\r\n let op = 0\r\n while (!isSorted(p)) {\r\n op++\r\n sort(p, op)\r\n }\r\n console.log(op)\r\n t--\r\n }\r\n}"}], "negative_code": [], "src_uid": "d4bcc53b470e4beaa078d5ce3785c6cb"} {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n let candy = lines[1].split(' ');\n candy = candy.map(c => parseInt(c, 10));\n // console.log(maxChildren(candy));\n console.log(maxChildrenFast(candy));\n});\n\nfunction maxChildrenFast(candies) {\n const arr = [];\n arr.length = 2 * (10 ** 5);\n arr.fill(0);\n let max = 1;\n for (let i = 0; i < candies.length - 1; i++) {\n for (let j = i + 1; j < candies.length; j++) {\n max = Math.max(++arr[candies[i] + candies[j] - 1], max);\n }\n }\n return max;\n}", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const sw = inputs[1].split(\" \").map(_ => PI(_));\n let possibleSolution = {};\n sw.forEach((val, idx) => { \n for(let q = idx + 1 ; q < sw.length; q++) { \n let k = sw[q] + val;\n possibleSolution[k] = (possibleSolution[k]) ? possibleSolution[k] : 0;\n possibleSolution[k.toString()]++; \n \n } \n });\n let res = 0;\n Object.keys(possibleSolution).forEach((key) => {\n res = Math.max(res, possibleSolution[key]);\n });\n\n console.log(res);\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}], "negative_code": [], "src_uid": "44619ba06ec0dc410ef598ea45a76271"} {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n) {\n const filter = new Array(n + 1).fill(0);\n filter[0] = filter[1] = 1;\n for (let i = 2; i <= n; ++i) {\n if (filter[i] !== 0) continue;\n filter[i] = 1;\n for (let j = i + i; j <= n; j += i) {\n if (filter[j] === 0) filter[j] = Math.floor(j / i);\n }\n }\n return filter.slice(2).sort((a, b) => a - b).join(' ');\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const n = readLine()[0];\n console.log(solve(n));\n}\n", "positive_code": [{"source_code": "wt = write;\nrd = readline;\n\nn = parseInt(rd());\narr = [];\nfor(i = 1; i <= n; i++){\n\tfor(j = 2; j * i <= n; j++){\n\t\tarr[i * j] = i;\n\t}\n}\narr.sort(function(a,b){ return a - b; });\nfor(i = 0; i < n - 1; i++){\n\twt(arr[i] + \" \");\n}"}], "negative_code": [], "src_uid": "26fe98904d68cf23c5d24aa85dd92120"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n if (m === 1) {\r\n return Math.ceil(n / 2) - 1;\r\n }\r\n let res = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (a[i] > a[i - 1] + a[i + 1]) res++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nfunction toInt(x) {\r\n\treturn parseInt(x);\r\n}\r\nfunction readInt() {\r\n\treturn toInt(readline());\r\n}\r\nfunction readLInt() {\r\n\treturn readline().split(' ').map(toInt);\r\n}\r\nfunction divCeil(a, b) {\r\n\treturn Math.floor((a - 1) / b) + 1;\r\n}\r\nfunction solve() {\r\n\tlet n, k;\r\n\tlet x = readLInt();\r\n\tn = x[0];\r\n\tk = x[1];\r\n\tlet a = readLInt();\r\n\tif (k == 1) {\r\n\t\tprint(Math.floor((n - 1) / 2));\r\n\t\treturn 0;\r\n\t}\r\n\tlet res = 0;\r\n\tfor (let ind = 1; ind + 1 < n; ind++) {\r\n\t\tif (a[ind] > a[ind + 1] + a[ind - 1]) res++;\r\n\t}\r\n\tprint(res);\r\n}\r\n\r\nlet t = readInt();\r\nwhile (t--) solve();"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var t1 = +readline().split(' ')[1]\r\n var t2 = readline().split(' ').map((t) => +t);\r\n print(ShuffleArray(t1,t2))\r\n \r\n}\r\n \r\nfunction ShuffleArray(k,arr){\r\n var count = 0;\r\n if (k == 1){\r\n return Math.floor((arr.length + 1) / 2) -1 \r\n }\r\n for(var i = 0; i arr[i-1] + arr[i+1]) count++;\r\n }\r\n\r\n return count;\r\n\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const [n, k] = readline().split(' ').map(Number);\r\n let arr = readline().split(' ').map(Number);\r\n if (k === 1) {\r\n output(Math.floor((n - 1) / 2));\r\n } else {\r\n let tooHigh = 0;\r\n for (let j = 1; j < arr.length - 1; j++) {\r\n if (arr[j - 1] + arr[j + 1] < arr[j]) {\r\n tooHigh++;\r\n }\r\n }\r\n output(tooHigh);\r\n }\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n \r\n\tif (n[1] == 1) {\r\n\t\twrite(parseInt((n[0] - 1) / 2));\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] \r\n\t\t \r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var nk = readline().split(' ').map(x => parseInt(x));\r\n var n = nk[0];\r\n var k = nk[1];\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var max = Math.floor((n - 1) / 2);\r\n if (k == 1) {\r\n print(max);\r\n continue;\r\n }\r\n var piles = 0;\r\n for (var i=1; i < n-1; i++) {\r\n if (arr[i-1]+arr[i+1] < arr[i]) piles++;\r\n }\r\n print(piles);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseConstraints = readline().split(\" \");\r\n var caseLength = parseInt(caseConstraints[0]);\r\n var caseOpLength = parseInt(caseConstraints[1]);\r\n var caseArray = readline().split(\" \");\r\n var count = 0;\r\n var result = 0;\r\n if (caseOpLength == 1)\r\n {\r\n if (caseLength % 2 === 0)\r\n {\r\n result = (caseLength/2) - 1;\r\n }\r\n else result = Math.floor(caseLength/2);\r\n }\r\n else\r\n {\r\n for (var j = 1; j < caseLength-1; j++)\r\n {\r\n var term = parseInt(caseArray[j]);\r\n var oneLessTerm = parseInt(caseArray[j-1]);\r\n var onePlusTerm = parseInt(caseArray[j+1]);\r\n var sum = oneLessTerm + onePlusTerm;\r\n if (term > sum) count++;\r\n }\r\n result = count;\r\n }\r\n print(result);\r\n}"}], "negative_code": [{"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i >= n[1] || arr.length - i - 1 >= n[1]));\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\ti >= n[1] &&\r\n\t\t\t\t\tarr.length - i >= n[1]);\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i >= n[1] ||\r\n\t\t\t\t\t\t(i + 1 <= arr.length - 1 && arr.length - (i + 1) >= n[1]))) ||\r\n\t\t\t\t0;\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i - 1 >= n[1] ||\r\n\t\t\t\t\t\t(i + 1 <= arr.length - 1 && arr.length - (i + 1) >= n[1]))) ||\r\n\t\t\t\t0;\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1 && n[0] > 2) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i - 1 >= n[1] ||\r\n\t\t\t\t\t\t(i + 1 <= arr.length - 1 && arr.length - (i + 1) + 1 >= n[1]))) ||\r\n\t\t\t\t0;\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i - 1 >= n[1] ||\r\n\t\t\t\t\t\t(i + 1 <= arr.length - 1 && arr.length - (i + 1) + 1 >= n[1])));\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i - 1 >= n[1] || (i + 1 <= arr.length - 1 && i + 1 >= n[1])));\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] &&\r\n\t\t\t\t\t(i - 1 >= n[1] || (i + 1 < arr.length - 1 && i + 1 >= n[1])));\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] && i - 1 >= n[1]);\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] && i >= n[1]);\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i === 0 || i == arr.length - 1) continue;\r\n\t\t\tcount +=\r\n\t\t\t\tarr[i - 1] + arr[i + 1] < arr[i] ||\r\n\t\t\t\t(arr[i - 1] + arr[i + 1] === arr[i] && i >= n[0]);\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar n = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\r\n\tif (n[1] == 1) {\r\n\t\twrite(n[0] - 2);\r\n\t} else {\r\n\t\tvar count = 0;\r\n\t\tfor (var i = 0; i < arr.length; i++) {\r\n\t\t\tif (i == 0 || i == arr.length - 1) continue;\r\n\t\t\tcount += arr[i - 1] + arr[i + 1] < arr[i];\r\n\t\t}\r\n\t\twrite(count);\r\n\t}\r\n\tprint();\r\n}\r\n"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n var nk = readline().split(' ').map(x => parseInt(x));\r\n const n = nk[0];\r\n const k = nk[1];\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var max = Math.floor((n - 1) / 2);\r\n if (k == 1) {\r\n print(max);\r\n continue;\r\n }\r\n var piles = 0;\r\n for (var i=1; i < n-1; i++) {\r\n if (arr[i-1]+arr[i+1] < arr[i]) piles++;\r\n }\r\n print(piles);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n const nk = readline().split(' ').map(x => parseInt(x));\r\n const n = nk[0];\r\n const k = nk[1];\r\n const arr = readline().split(' ').map(x => parseInt(x));\r\n var max = Math.floor((n - 1) / 2);\r\n if (k == 1) {\r\n print(max);\r\n continue;\r\n }\r\n var piles = 0;\r\n for (var i=1; i < n-1; i++) {\r\n if (arr[i-1]+arr[i+1] < arr[i]) { \r\n piles++;\r\n }\r\n }\r\n print(piles);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\nfor (var t=0; t < tests; t++) {\r\n const nk = readline().split(' ').map(x => parseInt(x));\r\n const n = nk[0];\r\n const k = nk[1];\r\n const arr = readline().split(' ').map(x => parseInt(x));\r\n var max = Math.floor((n - 1) / 2);\r\n if (k == 1) {\r\n print(max);\r\n continue;\r\n }\r\n var piles = 0;\r\n for (var i=1; i < n-1; i++) {\r\n if (arr[i-1]+arr[i+1] < arr[i]) piles++;\r\n }\r\n print(piles);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseConstraints = readline().split(\" \");\r\n var caseLength = parseInt(caseConstraints[0]);\r\n var caseOpLength = parseInt(caseConstraints[1]);\r\n var caseArray = readline().split(\" \");\r\n var count = 0;\r\n var result = 0;\r\n if (caseOpLength == 1)\r\n {\r\n if (caseLength % 2 === 0)\r\n {\r\n result = (caseLength/2) - 1;\r\n }\r\n else result = Math.floor(caseLength/2);\r\n }\r\n else\r\n {\r\n for (var j = 1; j < caseLength-1; j++)\r\n {\r\n var term = parseInt(caseArray[j]);\r\n var oneLessTerm = parseInt(caseArray[j-1]);\r\n var onePlusTerm = parseInt(caseArray[j+1]);\r\n var sum = oneLessTerm + onePlusTerm;\r\n if (term > sum) count++;\r\n }\r\n reuslt = count;\r\n }\r\n print(result);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseConstraints = readline().split(\" \");\r\n var caseLength = parseInt(caseConstraints[0]);\r\n var caseOpLength = parseInt(caseConstraints[1]);\r\n var caseArray = readline().split(\" \");\r\n var count = 0;\r\n var result = 0;\r\n if (caseOpLength == 1)\r\n {\r\n if (caseLength % 2 === 0)\r\n {\r\n result = (caseLength/2) - 1;\r\n }\r\n else result = Math.floor(caseLength/2);\r\n }\r\n else\r\n {\r\n for (var j = 1; j < caseLength-1; j++)\r\n {\r\n var term = parseInt(caseArray[j]);\r\n var oneLessTerm = parseInt(caseArray[j-1]);\r\n var onePlusTerm = parseInt(caseArray[j+2]);\r\n var sum = oneLessTerm + onePlusTerm;\r\n if (term > sum) count++;\r\n }\r\n reuslt = count;\r\n }\r\n print(result);\r\n}"}, {"source_code": "\"use strict\";\r\nfunction toInt(x) {\r\n\treturn parseInt(x);\r\n}\r\nfunction readInt() {\r\n\treturn toInt(readline());\r\n}\r\nfunction readLInt() {\r\n\treturn readline().split(' ').map(toInt);\r\n}\r\nfunction divCeil(a, b) {\r\n\treturn Math.floor((a - 1) / b) + 1;\r\n}\r\nfunction solve() {\r\n\tlet n, k;\r\n\tlet x = readLInt();\r\n\tn = x[0];\r\n\tk = x[1];\r\n\tlet a = readLInt();\r\n\tif (k == 1) {\r\n\t\tprint(Math.floor(n / 2));\r\n\t\treturn 0;\r\n\t}\r\n\tlet res = 0;\r\n\tfor (let ind = 1; ind + 1 < n; ind++) {\r\n\t\tif (a[ind] > a[ind + 1] + a[ind - 1]) res++;\r\n\t}\r\n\tprint(res);\r\n}\r\n\r\nlet t = readInt();\r\nwhile (t--) solve();"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var t1 = readline();\r\n var t2 = readline().split(' ').map((t) => +t);\r\n print(ShuffleArray(t2))\r\n \r\n}\r\n \r\nfunction ShuffleArray(arr){\r\n var count = 0;\r\n for(var i = 0; i arr[i-1] + arr[i+1]) count++;\r\n }\r\n\r\n return count;\r\n\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n let res = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (a[i] > a[i - 1] + a[i + 1]) res++;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "4d5d20fd586ddbea2adeab104a6c2aec"} {"source_code": "var n = parseInt(readline());\nvar q = Array(n);\nvar arr = readline().split(' ');\nvar total = 0;\nfor (var i = 0; i < n; i ++)\n{\n q[i] = parseInt(arr[i]);\n total += q[i];\n}\nvar m = parseInt(readline());\nvar t = Array(m);\nvar ret = -1;\nfor (var i = 0; i < m; i ++)\n{\n var arr = readline().split(' ');\n t[i] = [parseInt(arr[0]), parseInt(arr[1])];\n if (total < t[i][0])\n {\n ret = t[i][0];\n break;\n }\n else if (total >= t[i][0] && total <= t[i][1])\n {\n ret = total;\n break;\n }\n}\nprint(ret);", "positive_code": [{"source_code": "\n var n = parseInt(readline());\n var a = readline().split(' ').map(x => parseInt(x));\n var tot = 0;\n a.forEach(x => tot += x);\n var m = parseInt(readline());\n var l = [];\n var r = [];\n var res = Infinity;\n for(var i = 0; i < m; i += 1) {\n var tmp = readline().split(' ').map(x => parseInt(x));\n var l = tmp[0];\n var r = tmp[1];\n if(tot >= l && tot <= r) {\n res = tot;\n break;\n }\n if(tot <= l) {\n res = l;\n break;\n }\n }\n print(res === Infinity ? -1 : res);\n"}], "negative_code": [], "src_uid": "311f74b766818633581af67a88244709"} {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let testcases = parseInt(readline())\r\n\r\n while (testcases--) {\r\n let str = readline().split('') \r\n let left = 0\r\n let right = str.length - 1\r\n\r\n while(str[left] == str[right]){\r\n if(left >= right) break\r\n left++\r\n right--\r\n }\r\n\r\n while(str[left] == str[left+1]) {\r\n if(left >= right) break\r\n left += 2 \r\n }\r\n\r\n ( left <= right ) ? console.log('Alice') : console.log('Draw')\r\n }\r\n}", "positive_code": [{"source_code": "const util = require(\"util\")\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n let str = readLine()\n const n = str.length\n str = \"a\"+str+\"a\"\n let f = []\n for (let i = 0; i <= n+1; i ++) {\n f[i] = []\n for (let j = 0; j <= n+1; j++) {\n f[i][j] = i > j\n }\n }\n // console.log(util.inspect(f, {depth: null, colors: true}))\n for (let len = 2; len <= n; len += 2) {\n for (let i = 1; i + len - 1 <= n; i ++) {\n let j = i + len - 1\n if (str[i] === str[i+1] && str[j-1] === str[j]) {\n f[i][j] = f[i][j] || (f[i+2][j] && f[i][j-2])\n }\n if (str[i] === str[j]) {\n f[i][j] = f[i][j] || f[i+1][j-1]\n }\n }\n }\n if (f[1][n]) {\n console.log(\"Draw\")\n } else {\n console.log(\"Alice\")\n }\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read(),\r\n n = s.length;\r\n if (n % 2 == 0) {\r\n const cache = Array.from({\r\n length: n\r\n }, () => new Map());\r\n const dfs = (i, j, p) => {\r\n if (j - i === 1) {\r\n if (s[i] === s[j]) return 0;\r\n return 1;\r\n }\r\n if (cache[i].has(j)) return cache[i].get(j);\r\n let res = 1;\r\n if (j - i & 1) {\r\n let a = dfs(i + 1, j, s[i]),\r\n b = dfs(i, j - 1, s[j]);\r\n if (a === -1 && b === -1) {\r\n res = -1;\r\n } else if (a === 0 && b === 0) {\r\n res = 0;\r\n }\r\n cache[i].set(j, res);\r\n } else {\r\n let a = dfs(i + 1, j, s[i]),\r\n b = dfs(i, j - 1, s[j]);\r\n if (a === 0 && s[i] < p || b === 0 && s[j] < p) {\r\n res = -1;\r\n } else if (a === 0 && s[i] === p || b === 0 && s[j] === p) {\r\n res = 0;\r\n }\r\n }\r\n return res;\r\n };\r\n let res = dfs(0, n - 1, '');\r\n if (res === 0) return 'Draw';else if (res === 1) return 'Alice';\r\n return 'Bob';\r\n }\r\n return 'Bob';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const n = str.length\n let prev\n for (let l = 2; l <= n; l += 2) {\n const dp = Array(n)\n for (let i = 0; i + l - 1 < n; i++) {\n if (l === 2) {\n dp[i] = Math.min(\n cmp(0, str[i], str[i + 1]),\n cmp(0, str[i + 1], str[i])\n )\n continue\n }\n const a = Math.max(\n cmp(prev[i + 2], str[i], str[i + 1]),\n cmp(prev[i + 1], str[i], str[i + l - 1])\n )\n const b = Math.max(\n cmp(prev[i], str[i + l - 1], str[i + l - 2]),\n cmp(prev[i + 1], str[i + l - 1], str[i])\n )\n dp[i] = Math.min(a, b)\n }\n // console.log(dp)\n prev = dp\n }\n return prev[0] < 0 ? 'Alice' : (prev[0] > 0 ? 'Bob' : 'Draw')\n\n function cmp(sub, a, b) {\n if (sub === 0) {\n return a < b ? -1 : (a > b ? 1 : 0)\n } else {\n return sub\n }\n }\n}\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read(),\r\n n = s.length;\r\n if (n % 2 == 0) {\r\n const cache = Array.from({\r\n length: n\r\n }, () => new Map());\r\n const dfs = (i, j) => {\r\n if (j - i === 1) {\r\n return s[i] !== s[j];\r\n }\r\n if (cache[i].has(j)) return cache[i].get(j);\r\n if (j - i & 1) {\r\n if (s[i] !== s[j]) return true;\r\n }\r\n let a = dfs(i + 1, j),\r\n b = dfs(i, j - 1);\r\n if (a && b) {\r\n cache[i].set(j, false);\r\n return false;\r\n }\r\n cache[i].set(j, true);\r\n return true;\r\n };\r\n if (dfs(0, n - 1)) return 'Alice';\r\n return 'Draw';\r\n }\r\n return 'Bob';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read(),\r\n n = s.length;\r\n if (n % 2 == 0) {\r\n const cache = Array.from({\r\n length: n\r\n }, () => new Map());\r\n const dfs = (i, j) => {\r\n if (j - i === 1) {\r\n return s[i] === s[j];\r\n }\r\n if (cache[i].has(j)) return cache[i].get(j);\r\n if (j - i & 1) {\r\n let a = dfs(i + 1, j),\r\n b = dfs(i, j - 1);\r\n if (a && b) {\r\n cache[i].set(j, true);\r\n return true;\r\n }\r\n cache[i].set(j, false);\r\n return false;\r\n } else {\r\n if (dfs(i + 1, j) || dfs(i, j - 1)) {\r\n cache[i].set(j, true);\r\n return true;\r\n }\r\n cache[i].set(j, false);\r\n return false;\r\n }\r\n };\r\n if (dfs(0, n - 1)) return 'Draw';\r\n return 'Alice';\r\n }\r\n return 'Bob';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read(),\r\n n = s.length;\r\n if (n % 2 == 0) {\r\n let flag = true;\r\n for (let i = 0, j = n - 1; i < j; i++, j--) {\r\n if (s[i] !== s[j]) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag) return 'Draw';else return 'Alice';\r\n }\r\n return 'Bob';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read();\r\n const strs = [[], []];\r\n for (let i = 0, j = s.length - 1; i <= j;) {\r\n let k = i + (s.length - j - 1) & 1;\r\n if (s[i] <= s[j]) strs[k].push(s[i++]);else strs[k].push(s[j--]);\r\n }\r\n const [a, b] = strs;\r\n a.reverse();\r\n b.reverse();\r\n const n = Math.max(strs.length, b.length);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === b[i]) continue;\r\n if (a[i] === undefined || a[i] < b[i]) return 'Alice';else return 'Bob';\r\n }\r\n return 'Draw';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read();\r\n const a = [],\r\n b = [];\r\n for (let i = 0, j = s.length - 1; i < j; i++, j--) {\r\n let [x, y] = [s[i], s[j]];\r\n if (x > y) [x, y] = [y, x];\r\n a.push(x);\r\n if (i < j - 1) b.push(y);\r\n }\r\n a.reverse();\r\n b.reverse();\r\n const n = Math.max(a.length, b.length);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === b[i]) continue;\r\n if (a[i] === undefined || a[i] < b[i]) return 'Alice';else return 'Bob';\r\n }\r\n return 'Draw';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const s = read();\r\n let l = 0,\r\n r = s.length - 1;\r\n while (l < r - 1) {\r\n if (s[l] === s[r]) {\r\n l++;\r\n r--;\r\n } else return 'Alice';\r\n }\r\n if (l === r - 1) return 'Draw';\r\n return 'Bob';\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while(testcases--) {\r\n let str = readline()\r\n let alice = bob = ''\r\n \r\n let round = 1, moves = str.length\r\n while( str !== '' ){\r\n let firstChar = str.charAt(0)\r\n let lastChar = str.charAt(str.length - 1) \r\n let pickedChar = ''\r\n \r\n if( firstChar <= lastChar ) {\r\n pickedChar = firstChar\r\n str = str.substring(1)\r\n } else {\r\n pickedChar = lastChar\r\n str = str.substring(0, str.length - 1)\r\n }\r\n \r\n if( round % 2 == 1 ) alice = pickedChar.concat(alice)\r\n else bob = pickedChar.concat(bob)\r\n \r\n round++\r\n }\r\n\r\n if( alice == bob ) console.log('Draw')\r\n else console.log('Alice')\r\n }\r\n}"}, {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while(testcases--) {\r\n let str = readline()\r\n let alice = bob = ''\r\n \r\n let re = /[\\W_]/g;\r\n let lowRegStr = str.toLowerCase().replace(re, '');\r\n let reverseStr = lowRegStr.split('').reverse().join(''); \r\n if( reverseStr === lowRegStr ) console.log('Draw')\r\n else {\r\n \r\n let round = 1 \r\n while( str !== '' ){\r\n let first = str.charAt(0)\r\n let last = str.charAt(str.length - 1) \r\n let picked = ''\r\n \r\n if( first > last ) {\r\n picked = last\r\n str = str.substring(0, str.length - 1)\r\n } else if( first < last ){\r\n picked = first\r\n str = str.substring(1)\r\n } else {\r\n if( round % 2 == 1 ) {\r\n picked = last\r\n str = str.substring(0, str.length - 1)\r\n } else {\r\n picked = first\r\n str = str.substring(1)\r\n }\r\n }\r\n \r\n if( round % 2 == 1 ) alice = picked.concat(alice)\r\n else bob = picked.concat(bob)\r\n \r\n round++\r\n }\r\n \r\n if( alice < bob ) console.log('Alice')\r\n if( alice > bob ) console.log('Bob')\r\n if( alice == bob ) console.log('Draw')\r\n \r\n }\r\n \r\n }\r\n}"}, {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while(testcases--) {\r\n let str = readline()\r\n let alice = bob = ''\r\n \r\n let round = 1, moves = str.length\r\n while( str !== '' ){\r\n let firstChar = str.charAt(0)\r\n let lastChar = str.charAt(str.length - 1) \r\n let pickedChar = ''\r\n \r\n if( firstChar <= lastChar ) {\r\n pickedChar = firstChar\r\n str = str.substring(1)\r\n } else {\r\n pickedChar = lastChar\r\n str = str.substring(0, str.length - 1)\r\n }\r\n \r\n if( round % 2 == 1 ) alice = pickedChar.concat(alice)\r\n else bob = pickedChar.concat(bob)\r\n \r\n round++\r\n }\r\n \r\n if( alice < bob ) console.log('Alice')\r\n if( alice > bob ) console.log('Bob')\r\n if( alice == bob ) console.log('Draw')\r\n }\r\n}"}, {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n \r\n while(testcases--) {\r\n let str = readline()\r\n let alice = bob = ''\r\n \r\n let round = 1, moves = str.length\r\n while( str !== '' ){\r\n let firstChar = str.charAt(0)\r\n let lastChar = str.charAt(str.length - 1) \r\n let pickedChar = ''\r\n \r\n if( firstChar < lastChar ) {\r\n pickedChar = firstChar\r\n str = str.substring(1)\r\n } else {\r\n pickedChar = lastChar\r\n str = str.substring(0, str.length - 1)\r\n }\r\n \r\n if( round % 2 == 1 ) alice = pickedChar.concat(alice)\r\n else bob = pickedChar.concat(bob)\r\n \r\n round++\r\n }\r\n \r\n if( alice < bob ) console.log('Alice')\r\n if( alice > bob ) console.log('Bob')\r\n if( alice == bob ) console.log('Draw')\r\n }\r\n}"}, {"source_code": "/*\r\n** - \r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction main() {\r\n let str = readline()\r\n let alice = bob = ''\r\n\r\n let round = 1, moves = str.length\r\n while( str !== '' ){\r\n let firstChar = str.charAt(0)\r\n let lastChar = str.charAt(str.length - 1) \r\n let pickedChar = ''\r\n \r\n if( firstChar < lastChar ) {\r\n pickedChar = firstChar\r\n str = str.substring(1)\r\n } else {\r\n pickedChar = lastChar\r\n str = str.substring(0, str.length - 1)\r\n }\r\n \r\n if( round % 2 == 1 ) alice = pickedChar.concat(alice)\r\n else bob = pickedChar.concat(bob)\r\n \r\n round++\r\n }\r\n \r\n if( alice < bob ) console.log('Alice')\r\n if( alice > bob ) console.log('Bob')\r\n if( alice == bob ) console.log('Draw')\r\n}"}, {"source_code": "const util = require(\"util\")\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n let str = readLine()\n const n = str.length\n str = \"x\"+str+\"x\"\n let f = []\n for (let i = 0; i <= n+1; i ++) {\n f[i] = []\n for (let j = 0; j <= n+1; j++) {\n f[i][j] = []\n for (let k = 0; k < 2; k++) {\n f[i][j][k] = []\n for (let l = 0; l < 2; l++) {\n f[i][j][k][l] = i >= j;\n }\n }\n }\n }\n // console.log(util.inspect(f, {depth: null, colors: true}))\n for (let len = 2; len <= n; len += 2) {\n for (let i = 1; i + len - 1 <= n; i ++) {\n let j = i + len - 1\n let left = str[i] === str[i+1] ? 1 : 0\n let right = str[j-1] === str[j] ? 1 : 0\n if (str[i] === str[i+1]) {\n let res = f[i+2][j][0][1] || f[i+2][j][1][1]\n f[i][j][left][right] = f[i][j][left][right] || res\n }\n if (str[j-1] === str[j]) {\n let res = f[i][j-2][1][0] || f[i][j-2][1][1]\n f[i][j][left][right] = f[i][j][left][right] || res\n }\n if (str[i] === str[j]) {\n let res = cum(f[i+1][j-1])\n f[i][j][left][right] = f[i][j][left][right] || res\n }\n // console.log(`${i}-${j}-${str.slice(i,j+1)}\\t${f[i][j][left][right]}`)\n }\n }\n if (cum(f[1][n])) {\n console.log(\"Draw\")\n } else {\n console.log(\"Alice\")\n }\n }\n}\n\nfunction cum(f) {\n let res = false\n for (let k = 0; k < 2; k ++)\n for (let l = 0; l < 2; l ++) {\n res = res || f[k][l]\n }\n return res\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n//\n\nfunction main() {\n let t = parseInt(readLine())\n while (t--) {\n let oldStr = readLine()\n let newStr = \"\"\n while (oldStr !== \"\") {\n let i = 0\n while (i < oldStr.length) {\n if (i < oldStr.length - 1 && oldStr[i] === oldStr[i+1]) {\n i += 2\n continue\n }\n newStr += oldStr[i]\n i ++\n }\n // console.log(oldStr, newStr)\n if (oldStr === newStr) break\n oldStr = newStr\n newStr = \"\"\n }\n if (newStr === \"\") {\n console.log(\"Draw\")\n } else {\n console.log(\"Alice\")\n }\n }\n}"}], "src_uid": "6cffd0fa1146b250a2608d53f3f738fa"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n const l = [a[0]];\r\n for (let i = 1; i < n; i++) {\r\n if (i & 1) {\r\n l[i] = l[i - 1] - a[i];\r\n } else {\r\n l[i] = l[i - 1] + a[i];\r\n }\r\n }\r\n const r = [];\r\n r[n - 1] = a[n - 1];\r\n const odd = new Map(),\r\n even = new Map();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i < n - 1) {\r\n if (n - i - 1 & 1) {\r\n r[i] = a[i] - r[i + 1];\r\n } else {\r\n r[i] = a[i] - r[i + 1];\r\n }\r\n }\r\n if (i & 1) {\r\n if (!odd.has(r[i])) odd.set(r[i], []);\r\n odd.get(r[i]).push(i);\r\n } else {\r\n if (!even.has(r[i])) even.set(r[i], []);\r\n even.get(r[i]).push(i);\r\n }\r\n }\r\n for (let [key, arr] of odd) arr.reverse();\r\n for (let [key, arr] of even) arr.reverse();\r\n const find = arr => {\r\n while (arr.length && arr[arr.length - 1] > right) arr.pop();\r\n if (arr.length && arr[arr.length - 1] > left) {\r\n const ans = arr[arr.length - 1];\r\n pre = r[ans];\r\n sum = d = 0;\r\n res.push([pl, left], [ans, right]);\r\n right = ans - 1;\r\n pl = left + 1;\r\n return true;\r\n }\r\n return false;\r\n };\r\n let sum = 0,\r\n pre = 0,\r\n res = [];\r\n let left = 0,\r\n right = n - 1,\r\n d = 0,\r\n pl = 0;\r\n for (; left <= right; left++) {\r\n if (d & 1) {\r\n sum -= a[left];\r\n } else {\r\n sum += a[left];\r\n }\r\n if (sum === 0) {\r\n res.push([pl, left]);\r\n pl = left + 1;\r\n sum = d = 0;\r\n continue;\r\n }\r\n d++;\r\n if (right & 1) {\r\n let t = -sum - pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n } else {\r\n let t = -sum - pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n res.sort((a, b) => a[0] - b[0]);\r\n const check = arr => {\r\n var _arr$, _arr;\r\n if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i][0] !== arr[i - 1][1] + 1) return false;\r\n }\r\n return true;\r\n };\r\n if (!check(res)) return -1;\r\n return `${res.length}\\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\\n')}`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n // if (!sum) {\n // return `1\\n1 ${n}`\n // }\n const t = sum > 0 ? 1 : -1\n let k = sum / t\n if (k & 1) return -1\n k /= 2\n// console.log('k', k)\n const use = Array(n)\n const ans = []\n for (let i = 1; i < arr.length; i++) {\n if (k > 0 && arr[i] === t && !use[i - 1]) {\n use[i - 1] = 1\n use[i] = 1\n // ans.push([i - 1, i])\n ans.push([i, i + 1])\n k--\n }\n }\n if (k > 0) return -1\n for (let i = 0; i < arr.length; i++) {\n if (!use[i]) {\n ans.push([i + 1, i + 1])\n }\n }\n ans.sort((a, b) => a[0] - b[0])\n return ans.length + '\\n' + ans.map(x => x.join(' ')).join('\\n')\n}\n"}], "negative_code": [], "src_uid": "54a3b38631ddc033597797263fd7fb22"} {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let q = parseInt(readline());\r\n for (let i = 0; i < q; i++) {\r\n readline();\r\n let mat = [];\r\n let got = false;\r\n for (let j = 0; j < 8; j++) mat.push(readline());\r\n for (let j = 0; j < 8; j++) {\r\n for (let k = 0; k < 8; k++) {\r\n if (mat[j][k] == \"#\") {\r\n let type = \"r\";\r\n if (j + 1 < 8 && k - 1 >= 0 && mat[j + 1][k - 1] == \"#\") type = \"l\";\r\n print(Travel(j, k, mat, type).join(\" \"));\r\n got = true;\r\n break;\r\n }\r\n }\r\n if (got) break;\r\n }\r\n }\r\n}\r\n\r\nfunction Travel(i, j, mat, type) {\r\n if (Bisop(i, j, mat)) return [i + 1, j + 1];\r\n if (type == \"r\") return Travel(i + 1, j + 1, mat, type);\r\n else return Travel(i + 1, j - 1, mat, type);\r\n}\r\nfunction Bisop(i, j, mat) {\r\n if (i + 1 >= 8 || j + 1 >= 8 || i - 1 < 0 || j - 1 < 0) return false;\r\n return mat[i + 1][j + 1] == \"#\" && mat[i - 1][j - 1] == \"#\" && mat[i + 1][j - 1] == \"#\" && mat[i - 1][j + 1] == \"#\";\r\n}", "positive_code": [{"source_code": "const solve = (arr,n)=>{\r\n let flag = 0;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n let n = readline()\r\n let prev = ''\r\n let pos = ''\r\n\r\n for (let i = 0; i < n; i++) {\r\n let space = readline()\r\n\r\n for (let y = 0; y < 8; y++) { // top to bottom loop\r\n let row = readline()\r\n\r\n if (prev) {\r\n for (x = 0; x < row.length; x++) { // left to right\r\n if (row[x] == '#' && prev[x - 1] == '#' && prev[x + 1] == '#') {\r\n\r\n let r = x + 1\r\n let c = y + 1\r\n pos = c + ' ' + r\r\n }\r\n }\r\n }\r\n\r\n prev = row\r\n }\r\n\r\n console.log(pos)\r\n pos = ''\r\n }\r\n}"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n const boundary = `**********`;\r\n while (t--) {\r\n let emptyLine = readLine();\r\n let grid = [];\r\n grid.push(boundary);\r\n for (let i = 0; i < 8; i++) {\r\n grid.push(`${'*'}${readLine()}${'*'}`);\r\n }\r\n grid.push(boundary);\r\n for(let i=2;i<8;i++)\r\n {\r\n for(let j=2;j<8;j++){\r\n let cnt = 0;\r\n // const {row ,column} = locationsOfBis[i];\r\n let row = i,column=j;\r\n \r\n //check upper left\r\n if(grid[row-1][column-1]=='#'){\r\n cnt++;\r\n }\r\n //check upper right\r\n if(grid[row-1][column+1]=='#'){\r\n cnt++;\r\n }\r\n //check lower left\r\n if(grid[row+1][column-1]=='#'){\r\n cnt++;\r\n }\r\n //check lower right\r\n if(grid[row+1][column+1]=='#'){\r\n cnt++;\r\n }\r\n\r\n if(cnt==4){\r\n console.log(`${row} ${column}`);\r\n break;\r\n }\r\n }\r\n \r\n\r\n }\r\n \r\n }\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input\r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine() {\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace(\"\\r\", \"\");\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine()\r\n .split(\" \")\r\n .map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n const boundary = `**********`;\r\n while (t--) {\r\n let emptyLine = readLine();\r\n let grid = [];\r\n grid.push(boundary);\r\n for (let i = 0; i < 8; i++) {\r\n grid.push(`${'*'}${readLine()}${'*'}`);\r\n }\r\n grid.push(boundary);\r\n let locationsOfBis = [];\r\n let location = [];\r\n grid.forEach((v, idx) => {\r\n let mp = [];\r\n Array.from(v).forEach((d, id) => {\r\n if (d == '#'){\r\n mp.push({ row: idx, column: id });\r\n \r\n }\r\n })\r\n if(mp.length==1){\r\n let r = mp[0].row,c = mp[0].column;\r\n if(r>1 && r<8 && c>1 && c<8){\r\n\r\n locationsOfBis.push(mp[0]);\r\n }\r\n }\r\n location.push(...mp);\r\n \r\n })\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n function check(r, c, arr) {\r\n return arr[r-1][c-1] && arr[r-1][c+1] && arr[r+1][c-1] && arr[r+1][c+1];\r\n }\r\n\r\n for (let test = 0; test < N; test++) {\r\n readline();\r\n let rows = new Array(8);\r\n for (let i = 0; i < 8; i++) {\r\n rows[i] = readline().split('').map(c => c === '#' ? true : false);\r\n }\r\n \r\n let resC;\r\n let resR;\r\n for (let r = 1; r < 7; r++) {\r\n for (let c = 1; c < 7; c++) {\r\n if (check(r, c, rows)) {\r\n resC = c + 1;\r\n resR = r + 1;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n output(resR + ' ' + resC);\r\n }\r\n}"}, {"source_code": "function Solution() {\n let t = 0;\n const n = Number(lines[t++]);\n const res = [];\n \n for (let i = 0; i < n; i++) {\n t++;\n\n const board = [];\n for (let j = 0; j < 8; j++) {\n board.push(lines[t++].split(''));\n }\n\n for (let z = 1; z < 7; z++) {\n for (let y = 1; y < 7; y++) {\n if (board[z][y] === '#') {\n const a = [[-1, -1], [1, 1], [-1, 1], [1, -1]];\n let flag = true;\n for (let x = 0; x < a.length; x++) {\n if (board[z + a[x][0]][y + a[x][1]] !== '#') {\n flag = false;\n break;\n }\n }\n if (flag) {\n res.push(`${z + 1} ${y + 1}`);\n break;\n }\n }\n }\n }\n }\n\n return res.join('\\n');\n}\n\nconst readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n console.log(Solution());\n});"}, {"source_code": "/*\n** 799A\n*/\n\n// Common Template Starts //\n//*\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet is = \"\";\nlet cl = 0;\n\nprocess.stdin.on(\"data\", (inp) => {\n is += inp;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n is = is.trim().split(\"\\n\").map((s) => s.trim());\n main();\n});\n\nconst readline = () => is[cl++];\n// Common Template Ends //\n\nfunction main() {\n let n = readline();\n while (n--) {\n readline();\n const lines = [...Array(8)].map(_ => readline());\n const yy = lines.map((l, i) => l.indexOf('#.#') !== -1 ? i : -1).filter(n => n != -1);\n const x = lines[yy[0]].indexOf('#') + 2;\n const y = yy.length === 2 ? (yy[0] + yy[1]) / 2 + 1 : (yy[0] < 2 ? yy[0] : yy[0] + 2)\n\n console.log(`${y} ${x}`);\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction findKthLargest(nums, k) {\r\n k = nums.length - k;\r\n const quickSelect = (l, r) => {\r\n let pivot = nums[r];\r\n let p = l;\r\n for (let i = l; i < r; i++) {\r\n if (nums[i] <= pivot) {\r\n swapper(nums, p, i);\r\n p++;\r\n }\r\n }\r\n swapper(nums, p, r);\r\n\r\n if (p > k) return quickSelect(l, p - 1);\r\n else if (p < k) return quickSelect(p + 1, r);\r\n else return nums[p];\r\n };\r\n\r\n return quickSelect(0, nums.length - 1);\r\n};\r\n\r\nfunction swapper(array, a, b) {\r\n const temp = array[b];\r\n array[b] = array[a];\r\n array[a] = temp;\r\n};\r\n\r\nfunction main() {\r\n const n = parseInt(readline());\r\n\r\n for(var i=0; i 0 && j < 7 && d[j-1][index-1]==\"#\" && d[j-1][index+1]==\"#\"){\r\n foo(`${j+1} ${index+1}`);\r\n }\r\n }\r\n }\r\n}\r\nfunction foo(x) {\r\n process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(); // with auto '\\n' (newline)\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tnext();\r\n\t\tvar list = nextStrArray(8);\r\n\t\tvar ok = false;\r\n\t\tvar output = \"\";\r\n\t\tfor(var i = 1; i < 8; i++){\r\n\t\t\tfor(var j = 1; j < 8; j++){\r\n\t\t\t\tif(list[i][j] == \"#\" && list[i - 1][j - 1] == \"#\" && list[i - 1][j + 1] == \"#\" \r\n\t\t\t\t\t&& list[i + 1][j - 1] == \"#\" && list[i + 1][j + 1] == \"#\"){\r\n\t\t\t\t\toutput = (i + 1) + \" \" + (j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(a) {\r\n for (let i = 0; i < 8; i++) {\r\n for (let j = 0; j < 8; j++) {\r\n if (a[i][j] === '#') {\r\n var _a, _a2, _a3, _a4;\r\n if (((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a[j - 1]) === '#' && ((_a2 = a[i - 1]) === null || _a2 === void 0 ? void 0 : _a2[j + 1]) === '#' && ((_a3 = a[i + 1]) === null || _a3 === void 0 ? void 0 : _a3[j - 1]) === '#' && ((_a4 = a[i + 1]) === null || _a4 === void 0 ? void 0 : _a4[j + 1]) === '#') return `${i + 1} ${j + 1}`;\r\n }\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n await read();\r\n const a = [];\r\n let tmp = 8;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const grid = lines.slice(l, l + 8).map(str => str.trim())\n l += 8\n output[i] = solve(grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(grid) {\n // console.log(grid)\n for (let i = 1; i < grid.length - 1; i++) {\n for (let j = 1; j < grid[i].length - 1; j++) {\n const a = [\n [i, j],\n [i - 1, j - 1],\n [i - 1, j + 1],\n [i + 1, j - 1],\n [i + 1, j + 1],\n ].every(([x, y]) => grid[x][y] === '#')\n if (a) return [i + 1, j + 1].join(' ')\n }\n }\n}\n"}, {"source_code": "var array = [],x,y,hashtag,found;\r\n\r\nvar tests = readline();\r\nvar found = false;\r\nvar pass = false;\r\nwhile(tests--){\r\n readline();\r\n found = false;\r\n pass = false;\r\n for(var t = 0;t<8;t++)\r\n {\r\n array = readline();\r\n if(!pass){\r\n splinter = array.split('#');\r\n if(splinter.length == 2 && found)\r\n {\r\n print(parseInt(t+1) + \" \" + parseInt(array.indexOf(\"#\") + 1));\r\n pass = true;\r\n }\r\n else if(splinter.length == 3) found = true;\r\n }\r\n }\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var t1 = readline();\r\n var list = [];\r\n for (var q = 0; q<8;q++){\r\n var just = readline();\r\n list.push(just);\r\n }\r\n var testone = Task2(list);\r\n print(testone[0],testone[1])\r\n}\r\n \r\nfunction Task2 (arr){\r\n \r\n function isBishop(i,j){\r\n\r\n var ll = j;\r\n for(var l = i; l>= 0; l--){\r\n if (ll < 0) break;\r\n if (arr[l][ll] != '#') {\r\n return false;\r\n }\r\n ll--;\r\n }\r\n\r\n var lr = j;\r\n for(var l1 = i; l1>= 0; l1--){\r\n if (lr < 0 || lr >= arr.length) break;\r\n if (arr[l1][lr] != '#') return false;\r\n lr++;\r\n }\r\n var rr = j;\r\n for(var l2 = i; l2< arr.length; l2++){\r\n if (rr < 0 || rr >= arr.length) break;\r\n if (arr[l2][rr] != '#') return false\r\n ;\r\n rr++;\r\n }\r\n\r\n var rl = j;\r\n for(var l3 = i; l3< arr.length; l3++){\r\n if (rl < 0 || rl >= arr.length) break;\r\n if (arr[l3][rl] != '#') return false;\r\n rl--;\r\n }\r\n\r\n return true;\r\n\r\n }\r\n \r\n var just = [];\r\n \r\n for(var i = 0; i= 2 ? just[1] : just[0]\r\n\r\n \r\n}"}], "negative_code": [{"source_code": "const solve = (arr,n)=>{\r\n let flag = 0;\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\nfunction main() {\r\n let n = readline()\r\n let prev = ''\r\n let pos = ''\r\n\r\n for (let i = 0; i < n; i++) {\r\n for (let y = 0; y < 8; y++) { // top to bottom loop\r\n let row = readline()\r\n\r\n if (prev) {\r\n for (x = 0; x < row.length; x++) { // left to right\r\n if (row[x] == '#' && prev[x - 1] == '#' && prev[x + 1] == '#') {\r\n\r\n let r = x + 1\r\n let c = y + 1\r\n pos = c + ' ' + r\r\n }\r\n }\r\n }\r\n\r\n prev = row\r\n }\r\n\r\n console.log(pos)\r\n pos = ''\r\n }\r\n}"}], "src_uid": "b0f968ca75fbea2f11a7e4b9006f136e"} {"source_code": "\"use strict\";\nlet For = (a, b, fn) => {\n if (!fn)\n return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null)\n return res;\n }\n};\nlet ForR = (a, b, fn) => {\n if (!fn)\n return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null)\n return res;\n }\n};\nlet Arr = (a, b, fn) => {\n if (typeof (b) == 'function')\n return Arr(0, a - 1, b);\n if (b < a)\n return [];\n let arr = Array(b - a + 1);\n for (let i = a; i <= b; i++)\n arr[i] = fn(i, arr);\n return arr;\n};\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\n// Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\n// Array.prototype.uniq = function (fn) {\n// var set = new Set();\n// return this.filter(v => {\n// var newValue = !set.has(fn ? fn(v) : v);\n// set.add(fn ? fn(v) : v);\n// return newValue;\n// });\n// }\n// Array.prototype.toObj = function (fn) {\n// return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n// p[v[0]] = v[1];\n// return p;\n// }, {})\n// }\n// Array.prototype.min = function (fn) {\n// let min = 1e20, index = -1, x;\n// for (let i = 0; i < this.length; i++) {\n// x = fn ? fn(this[i], i, this) : this[i];\n// if (x < min) { min = x; index = i }\n// }\n// return [this[index], index, min];\n// }\n// Array.prototype.max = function (fn) {\n// let max = -1e20, index = -1, x;\n// for (let i = 0; i < this.length; i++) {\n// x = fn ? fn(this[i], i, this) : this[i];\n// if (x > max) { max = x; index = i }\n// }\n// return [this[index], index, max];\n// }\n// Array.prototype.rev = function (first, last) {\n// for (let i = first; i < (first + last) / 2; i++) {\n// [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n// }\n// }\n// Array.prototype.set = function (pos, arr) {\n// for (let i = pos; i < pos + arr.length; i++) {\n// this[i] = arr[i - pos];\n// }\n// }\n// Array.prototype.for = function (a, b, fn) {\n// let res\n// for (let i = a; i <= b; i++) {\n// if ((res = fn(this[i], i, this)) != null) return res;\n// }\n// }\n// Array.prototype.forR = function (a, b, fn) {\n// let res\n// for (let i = a; i >= b; i--) {\n// if ((res = fn(this[i], i, this)) != null) return res;\n// }\n// }\n// Array.prototype.bin = function (comp, a, b) {\n// let mid;\n// while (a < b) {\n// mid = (a + b) / 2 | 0;\n// if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n// else b = mid;\n// }\n// return a;\n// }\n// Array.prototype.cut = function (fn, a, b) {\n// let arr = [];\n// a = a || 0;\n// b = b || (this.length - 1);\n// let prev = a;\n// for (let i = a; i <= b; i++) {\n// if (i == b || fn(this[i], this[i + 1])) {\n// arr.push(this.slice(prev, i + 1));\n// prev = i + 1;\n// }\n// }\n// return arr;\n// }\nfunction gcd(a, b) {\n while (b)\n [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m;\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n)\n n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1];\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = (n) => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [n, m] = $(2), s = 1, z = 1e6;\n let h1 = [], h2 = [];\n For(n, i => {\n let [y, l, r] = $(3);\n if (l == 0 && r == z)\n s++;\n if (l == 0)\n h1.push({ y, r });\n else\n h2.push({ y, l });\n });\n h1.sort((a, b) => a.r - b.r);\n h2.sort((a, b) => a.l - b.l);\n let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0);\n let update = (pos, x) => {\n for (let i = pos; i <= z; i += i & -i)\n bit1[i] += x;\n for (let i = z - pos; i <= z; i += i & -i)\n bit2[i] += x;\n };\n let cal1 = pos => {\n let res = 0;\n for (let i = pos; i; i -= i & -i)\n res += bit1[i];\n return res;\n };\n let cal2 = pos => {\n let res = 0;\n for (let i = z - pos; i; i -= i & -i)\n res += bit2[i];\n return res;\n };\n let v = Arr(m, i => ({ x: $(), l: $(), r: $() }));\n v.sort((a, b) => a.x - b.x);\n let i1 = 0, i2 = 0;\n h1.forEach(h => update(h.y, 1));\n v.forEach(v => {\n while (i1 < h1.length && h1[i1].r < v.x) {\n update(h1[i1].y, -1);\n i1++;\n }\n while (i2 < h2.length && h2[i2].l <= v.x) {\n update(h2[i2].y, 1);\n i2++;\n }\n // log(s, cal1(v.l), cal2(v.l));\n if (v.l == 0 && v.r == z)\n s++;\n if (v.l == 0)\n s += cal1(v.r);\n else\n s += cal2(v.l);\n });\n log(s);\n}\n", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [n, m] = $(2), s = 1; z = 1e6;\n let h1 = [], h2 = [];\n For(n, i => {\n let [y, l, r] = $(3)\n if (l == 0 && r == z) s++;\n if (l == 0) h1.push({ y, r });\n else h2.push({ y, l })\n })\n h1.sort((a, b) => a.r - b.r);\n h2.sort((a, b) => a.l - b.l);\n\n let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0)\n\n let update = (pos, x) => {\n for (let i = pos; i <= z; i += i & -i) bit1[i] += x;\n for (let i = z - pos; i <= z; i += i & -i) bit2[i] += x;\n }\n let cal1 = pos => {\n let res = 0;\n for (let i = pos; i; i -= i & -i) res += bit1[i];\n return res;\n }\n let cal2 = pos => {\n let res = 0;\n for (let i = z - pos; i; i -= i & -i) res += bit2[i];\n return res;\n }\n\n let v = Arr(m, i => ({ x: $(), l: $(), r: $() }))\n v.sort((a, b) => a.x - b.x);\n\n let i1 = 0, i2 = 0;\n h1.forEach(h => update(h.y, 1));\n v.forEach(v => {\n while (i1 < h1.length && h1[i1].r < v.x) {\n update(h1[i1].y, -1);\n i1++;\n }\n while (i2 < h2.length && h2[i2].l <= v.x) {\n update(h2[i2].y, 1);\n i2++;\n }\n // log(s, cal1(v.l), cal2(v.l));\n if (v.l == 0 && v.r == z) s++;\n if (v.l == 0) s += cal1(v.r);\n else s += cal2(v.l);\n })\n\n log(s)\n}\n"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [n, m] = $(2), s = 1; z = 1e6;\n let h1 = [], h2 = [];\n For(n, i => {\n let [y, l, r] = $(3)\n if (l == 0 && r == z) s++;\n if (l == 0) h1.push({ y, r });\n else h2.push({ y, l })\n })\n h1.sort((a, b) => a.r - b.r);\n h2.sort((a, b) => a.l - b.r);\n\n let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0)\n\n let update = (pos, x) => {\n for (let i = pos; i <= z; i += i & -i) bit1[i] += x;\n for (let i = z - pos; i <= z; i += i & -i) bit2[i] += x;\n }\n let cal1 = pos => {\n let res = 0;\n for (let i = pos; i; i -= i & -i) res += bit1[i];\n return res;\n }\n let cal2 = pos => {\n let res = 0;\n for (let i = z - pos; i; i -= i & -i) res += bit2[i];\n return res;\n }\n\n let v = Arr(m, i => ({ x: $(), l: $(), r: $() }))\n v.sort((a, b) => a.x - b.x);\n\n let i1 = 0, i2 = 0;\n h1.forEach(h => update(h.y, 1));\n v.forEach(v => {\n while (i1 < h1.length && h1[i1].r < v.x) {\n update(h1[i1].y, -1);\n i1++;\n }\n while (i2 < h2.length && h2[i2].l <= v.x) {\n update(h2[i2].y, 1);\n i2++;\n }\n // log(s, cal1(v.l), cal2(v.l));\n if (v.l == 0 && v.r == z) s++;\n if (v.l == 0) s += cal1(v.r);\n else s += cal2(v.l);\n })\n\n log(s)\n}\n"}], "src_uid": "dced53eba154855fa0f203178574990c"} {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = null;\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line;\n data = Array.from(new Array(countOfData), () => []);\n return;\n }\n data[Math.floor((lineNum - 2) / 2)].push(line.split(' ').map(i => +i));\n\n if((lineNum - 1) / 2 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(data) {\n data.forEach(set => {\n const [[length, k],arr] = set;\n if(length < 2) {\n console.log(0);\n return;\n } \n arr.sort((a,b) => a - b);\n\n for(let i = 0; i < k; i++) {\n arr[length - 1] += arr[length - 2 - i];\n }\n\n console.log(arr[length - 1]);\n })\n}\n\n", "positive_code": [{"source_code": "var tc = parseInt(readline());\nfor (; tc-- ;){\n var AR = readline().split(' ').map(x => parseInt(x));\n var n = AR[0], m = AR[1];\n\n var ar = readline().split(' ').map(x => parseInt(x));\n ar.sort((a, b) => b - a);\n var sum = 0;\n for (var i = 0; i <= m; i++) sum += ar[i];\n print(sum);\n}\n "}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nlet mem = new Map();\nfunction query(arr, k){\n arr.sort((a, b)=>a-b);\n for (let i = arr.length-2; i>=0 && k>0; i--)\n {\n arr[arr.length-1] += arr[i];\n arr[i] = 0;\n k--;\n }\n arr.sort((a, b)=>a-b);\n return arr[arr.length-1]-arr[0];\n}\n\nfunction main() {\n var q = +readline();\n while (q--)\n {\n var [n, k] = readline().split(' ').map(n=>+n);\n let arr = readline().split(' ').map(n=>+n);\n print(query(arr, k));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [len, k] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n let [min, max] = [0, 0];\n\n arr.sort((a, b) => b - a);\n max = arr[0];\n\n for (let i = 1; i <= k; i++) {\n max += arr[i];\n }\n\n console.log(max - min);\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var K = one[1];\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn b - a;\n });\n for(var j = 1; j < K + 1; j++){\n list[0] += list[j];\n }\n output[i] = list[0];\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n let a = data[i].trim().split(' ').map(Number);\n const n = a[0];\n const k = a[1];\n let s = data[i + 1].trim().split(' ').map(Number);\n s.sort((a, b) => b - a);\n if (s[0] === 0) console.log(0);\n else {\n for (let j = 0; j < k; j += 1) {\n s[j + 1] += s[j];\n }\n console.log(s[k]);\n }\n i += 2;\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const cases = parseInt(readline());\n for (let i = 0; i < cases; i++) {\n test();\n }\n}\n\nfunction test() {\n const input = readline().split(' ');\n const nb = parseInt(input[0]);\n let k = parseInt(input[1]);\n const barrels = readline().split(' ').map(x => parseInt(x)).sort((a,b) => b-a);\n let max = barrels[0];\n for (let i = 1; i <= k; i++) {\n max += barrels[i];\n }\n console.log(max);\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = $()\n while (t--) {\n let [n, k] = $(2)\n let a = $(n).sort(asc)\n log(a.slice(-k - 1).sum())\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = 0;\n let b = 0;\n let c = 0;\n let isFound = false;\n for(let i = 0; i <= Math.floor(n/3); i++){\n if(isFound)\n break;\n if(3*i > n)\n break;\n else if(3*i === n){\n a = i;\n isFound = true;\n break;\n }\n for(let j = 0; j <= Math.floor(n/5); j++){\n if(isFound)\n break;\n if(3*i + 5*j > n)\n break;\n else if(3*i + 5*j === n){\n a = i; b = j;\n isFound = true;\n break;\n }\n for(let k = 0; k <= Math.floor(n/7); k++){\n if(3*i + 5*j + 7*k === n){\n a = i; b = j; c = k;\n isFound = true;\n break;\n }else if(3*i + 5*j + 7*k > n){\n break;\n }\n }\n }\n }\n\n if(isFound)\n console.log(a,b,c)\n else\n console.log(-1);\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n a.sort((a,b) => b-a);\n\n let d = 0;\n for(let i = 0; i < k; i++){\n if(i < n){\n d += a[i];\n }else{\n break;\n }\n }\n\n if(k < n)\n console.log(d+a[k]);\n else\n console.log(d);\n }\n}\n"}], "negative_code": [{"source_code": "var tc = parseInt(readline());\nfor (; tc--;){\n \n var n = parseInt(readline());\n print(2);\n // if (n <= 3) {\n // if (n != 3) print(1 + ' ' + 2);\n // else {\n // print(1 + ' ' + 3);\n // print(2 + ' ' + 2);\n // }\n // }\n // else {\n // var nn = n;\n // var m = n - 2;\n // print(m + ' ' + nn);\n // print(nn - 1 + ' ' + nn - 1);\n // nn--;\n // m--;\n // while (m > 0) {\n // print(m + ' ' + nn);\n // nn--;\n // m--;\n // }\n // }\n for (var i = n - 1; i >= 1; i--){\n print(i + ' ' + Math.min(n, i + 2));\n }\n}\n\n"}], "src_uid": "08c797a7972fae99f8b64b47c53d8aeb"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar S = next();\r\n\t\tvar map = {};\r\n\t\tvar ok = true;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(map[list[i]] == null){\r\n\t\t\t\tmap[list[i]] = S[i];\r\n\t\t\t}else if(map[list[i]] != S[i]){\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((ok) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n\r\nfunction begin(n, nums, str) {\r\n //print(`${n} ${nums} ${str}`);\r\n \r\n let cache = new Map();\r\n for(let i = 0; i < n; i++) {\r\n let all = cache.get(nums[i]);\r\n if(all == null) {\r\n all = [];\r\n }\r\n all.push(i);\r\n cache.set(nums[i], all);\r\n }\r\n let keys = Array.from(cache.keys());\r\n let find = true;\r\n for(let i = 0; i < keys.length; i++) {\r\n let all = cache.get(keys[i]);\r\n let dst = str.charAt(all[0]);\r\n for(let j = 1; j < all.length; j++) {\r\n if(str.charAt(all[j]) != dst) {\r\n find = false;\r\n break;\r\n }\r\n }\r\n if(find == false) {\r\n break;\r\n }\r\n }\r\n if(find) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n}\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n\r\n var str = readline().trim()\r\n begin(n, x, str);\r\n }\r\n}\r\n"}, {"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n \nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n \nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let s = rl();\n \n let map = {};\n for (let i = 0; i < n; i++) {\n let char = s[i];\n let num = a[i];\n if (typeof map[num] === 'undefined') {\n map[num] = char;\n } else {\n if (char != map[num]) return 'NO';\n }\n }\n return 'YES';\n};\n \nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", function (inputStdin) {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", function () {\n inputString = inputString.split(\"\\n\");\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction check(input) {\n let dict = {};\n for (let i = 0; i < input.numbers.length; i++) {\n if (\n Object.keys(dict).includes(input.numbers[i]) &&\n input.letters[i] !== dict[input.numbers[i]]\n ) {\n console.log(\"NO\");\n break;\n }\n\n if (!Object.keys(dict).includes(input.numbers[i])) {\n dict[input.numbers[i]] = input.letters[i];\n }\n\n if (i === input.numbers.length - 1) {\n console.log(\"YES\");\n }\n }\n}\n\nfunction main() {\n const t = parseInt(readLine().trim());\n const cases = {};\n for (let i = 0; i < t * 3; i++) {\n const inputs = readLine().trim();\n cases[Math.floor(i / 3)] = {\n ...cases[Math.floor(i / 3)],\n ...(i % 3 === 1 && { numbers: inputs.split(\" \") }),\n ...(i % 3 === 2 && { letters: inputs.split(\"\") }),\n };\n }\n\n for (let i = 0; i < Object.keys(cases).length; i++) {\n check(cases[i]);\n }\n}\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n // let v=[,];\r\n // console.log(v[1].length);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[3*_-2]);\r\n let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});\r\n let s=line[3*_];\r\n let v=new Array(55);\r\n for(let i=1;i<=50;i++) v[i]=new Array(0);\r\n // console.log(a);\r\n for(let i=0;i0)\r\n {\r\n let c=s[v[i][0]];\r\n // console.log(c);\r\n for(let j=0;jparseInt(x));\r\n \r\n const s = readLine();\r\n \r\n //console.log(n);\r\n //console.log(arr);\r\n //console.log(s);\r\n let fail=false\r\n for(let j=0;j parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let str = stringArr();\r\n const helper = () => {\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n if (arr[j] === arr[i] && str[j] !== str[i]) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n let ans = helper() === true ? \"YES\" : \"NO\";\r\n console.log(ans);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(),\r\n s = read();\r\n const map = {};\r\n for (let i = 0; i < n; i++) {\r\n if (!map[a[i]]) map[a[i]] = [];\r\n map[a[i]].push(i);\r\n }\r\n let res = [];\r\n for (let i = 0; i < n; i++) {\r\n if (!res[i]) {\r\n let ch = s[i];\r\n for (let j of map[a[i]]) {\r\n res[j] = ch;\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (res[i] !== s[i]) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n const str = lines[l++]\n output[i] = solve(n, arr, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, str) {\n const m = {}\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i]\n m[x] = m[x] || []\n m[x].push(i)\n }\n for (let x in m) {\n const ch = str[m[x][0]]\n for (let p of m[x]) {\n if (str[p] !== ch) return 'NO'\n }\n }\n return 'YES'\n}\n"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var numArray = readline().split(\" \");\r\n var stringArray = readline();\r\n var caseMap = new Map();\r\n var result = \"YES\";\r\n for (var j = 0; j < caseLength; j++)\r\n {\r\n var value = parseInt(numArray[j]);\r\n if (caseMap.has(value))\r\n {\r\n if (caseMap.get(value) !== stringArray[j])\r\n {\r\n result = \"NO\";\r\n break;\r\n }\r\n }\r\n else caseMap.set(value, stringArray[j]);\r\n }\r\n print(result);\r\n}"}, {"source_code": "function foo(size, arr, str) {\r\n const obj = {}\r\n\r\n for(var i=0; i +el)\r\n var str = readline();\r\n\r\n var result = foo(size, arr, str)\r\n print(result)\r\n}"}, {"source_code": "var t = +readline();\r\nfor(var i_=0;i_ +el)\r\n var str = readline();\r\n\r\n var result = func( arr, str)\r\n print(result)\r\n}"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var k = +readline();\r\n var arr = readline().split(' ');\r\n var str = readline();\r\n var obj = {};\r\n for(var j = 0; j < k; j++) {\r\n if(obj[arr[j]]) {\r\n if(obj[arr[j]] !== str[j]) {\r\n break;\r\n }\r\n } else {\r\n obj[arr[j]] = str[j];\r\n }\r\n }\r\n print(j === k ? 'YES' : 'NO');\r\n}\r\n"}], "negative_code": [{"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var numArray = readline().split(\" \");\r\n var stringArray = readline();\r\n var caseMap = new Map();\r\n var result = \"YES\";\r\n for (var j = 0; j < caseLength; j++)\r\n {\r\n var value = parseInt(numArray[j]);\r\n if (caseMap.has(value))\r\n {\r\n if (caseMap[value] !== stringArray[j])\r\n {\r\n result = \"NO\";\r\n break;\r\n }\r\n }\r\n else caseMap.set(value, stringArray[j]);\r\n }\r\n print(result);\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var numArray = readline().split(\" \");\r\n var stringArray = readline();\r\n var caseMap = new Map();\r\n var result = \"YES\";\r\n for (var j = 0; j < caseLength; j++)\r\n {\r\n var value = parseInt(numArray[j]);\r\n if (caseMap.has(value))\r\n {\r\n if (caseMap[value] === stringArray[j])\r\n {\r\n result = \"NO\";\r\n break;\r\n }\r\n }\r\n else caseMap.set(value, stringArray[j]);\r\n }\r\n print(result);\r\n}"}], "src_uid": "485d5984e34a479f2c074a305ae999ae"} {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const total = +input[0];\n for (let i = 1; i <= total; i++) {\n console.log(solve(input[i * 2]));\n }\n\n process.exit();\n});\n\nfunction solve(str) {\n const numbers = str.split(' ').map(ele => +ele);\n const len = numbers.length;\n const record = new Array(len + 1).fill(-1);\n const sums = new Array(len).fill(0);\n let current = 0;\n for (let i = 0; i < len; i++) {\n if (record[numbers[i]] < 0) {\n current++;\n }\n sums[i] = current;\n record[numbers[i]] = i; \n }\n const maxs = new Array(len).fill(0);\n maxs[0] = record[numbers[0]];\n for (let i = 1; i < len; i++) {\n maxs[i] = Math.max(maxs[i - 1], record[numbers[i]]);\n }\n let result = -1;\n for (let i = 1; i < len; i++) {\n if (numbers[i] < numbers[i - 1]) {\n let j = i - 1;\n while(maxs[j] !== j) {\n j = maxs[j];\n }\n result = j;\n numbers[j] = 0;\n i = j;\n }\n }\n if (result < 0) {\n return 0;\n } else {\n return sums[result];\n }\n}\n\n\n\n \t \t\t\t\t \t \t\t \t \t\t \t\t\t\t\t\t\t\t", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const map = new Map();\r\n const segTree = new SegTree(n);\r\n for (let [i, num] of a.entries()) {\r\n if (!map.has(num)) map.set(num, []);\r\n map.get(num).push(i);\r\n segTree.update(i, i, num);\r\n }\r\n const keys = [...map.keys()].sort((a, b) => b - a);\r\n let res = 0;\r\n for (let key of keys) {\r\n const i = map.get(key)[0];\r\n if (i === n - 1) continue;\r\n const num = segTree.query(i + 1, n - 1);\r\n if (num < key) {\r\n res++;\r\n for (let i of map.get(key)) {\r\n segTree.update(i, i, 0);\r\n }\r\n }\r\n }\r\n return res;\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(val = Infinity, left = null, right = null) {\r\n return {\r\n val,\r\n left,\r\n right\r\n };\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.val = Math.min(left.val, right.val);\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (l === x && r === y) {\r\n node.val = Math.min(node.val, z);\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.min(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = await rns();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "var n,a, count;\r\n var set, toCheck;\r\n\r\n function op(x) {\r\n set.add(x);\r\n count++;\r\n toCheck.delete(x);\r\n count+=toCheck.size;\r\n var adds = [...toCheck];\r\n for (var i = 0; i < adds.length; i++) {\r\n set.add(adds[i])\r\n }\r\n toCheck = new Set();\r\n }\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n a = readline().split(' ').map(x=>parseInt(x));\r\n count = 0;\r\n set = new Set();\r\n toCheck = new Set();\r\n for (var i = 0; i < n-1; i++) {\r\n var x = set.has(a[i]) ? 0 : a[i];\r\n var y = set.has(a[i+1]) ? 0 : a[i+1];\r\n if (x > y) {\r\n op(x);\r\n } else {\r\n if (!set.has(a[i])) {\r\n toCheck.add(a[i]);\r\n }\r\n }\r\n } \r\n print(count);\r\n }"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = parseInt(readline(), 10);\r\n const arr = readline().split(' ').map(Number);\r\n\r\n function c(num) {\r\n if (curr === 0) return;\r\n curr[num] = true;\r\n }\r\n\r\n function repl() {\r\n Object.keys(curr).forEach(key => zero[key] = true);\r\n curr = {};\r\n }\r\n\r\n function val(i) {\r\n let num = arr[i];\r\n return zero[num] ? 0 : num;\r\n }\r\n\r\n let zero = {};\r\n let curr = {};\r\n\r\n c(arr[0]);\r\n\r\n for (let i = 1; i < n; i++) {\r\n if (val(i) < val(i - 1)) {\r\n repl();\r\n }\r\n c(arr[i]);\r\n }\r\n\r\n output(Object.keys(zero).length);\r\n }\r\n}"}], "negative_code": [], "src_uid": "68e830551c1580bb5aff40d7848d968d"} {"source_code": "var m = 1001010;\nvar n = parseInt(readline());\nvar s = readline();\nvar a = [];\nfor (var i = 0; i <= m; i++) a.push(0);\ns.split(' ').map(function (x) { a[x]++; });\nvar res = 0;\n\nfor (var i = 0; i < m - 10; i++) {\n a[i + 1] += a[i] >> 1;\n res += a[i] & 1;\n}\n\nprint(res);", "positive_code": [{"source_code": "function toi(x){return parseInt(x);}\nfunction countOne(x){\n var res =0;\n while(x > 0){\n rem = x%2;\n res += rem;\n x=(x-rem)/2;\n }\n return res;\n}\nn = toi(readline());\nw = readline().split(\" \").map(toi);\nm = 1000000;\nmemo = [];\nfor(var i=0;i 1) {\n if (a[0] == a[1]) {\n a.shift();\n a[0]++;\n } else {\n a.shift();\n res++;\n }\n}\nres++;\n\nprint(res);"}], "src_uid": "089eea1841ef10064647e61094c374fd"} {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nconst readInts = () => readline().split(' ').map(n => parseInt(n))\nconst readInt = () => readInts[0]\nconst abc = \"abcdefghijklmnopqrstuvwxyz\"\n\nwhile (t --> 0) {\n const params = readInts()\n const n = params[0]\n const m = params[1]\n const s = readline()\n const arr = readInts()\n arr.push(n)\n\n const pre = {}\n for (let j = 0; j < 26; ++j) {\n pre[abc[j]] = Array(n + 1).fill(0)\n }\n\n for (let i = 0; i < n; ++i) {\n for (let j = 0; j < 26; ++j) {\n const c = abc[j]\n const last = pre[c][i]\n const val = last + (c === s[i])\n pre[c][i + 1] = val\n }\n }\n\n const out = {}\n for (let j = 0; j < 26; ++j) {\n out[abc[j]] = 0\n }\n\n for (let i in arr) {\n for (let j = 0; j < 26; ++j) {\n const c = abc[j]\n out[c] += pre[c][arr[i]]\n }\n }\n\n let ans = \"\"\n for (let i in out) {\n ans += \" \" + out[i]\n }\n print(ans)\n}", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let ptr = 0\n let t = readInt(input, ptr++)\n // const alpha = \"abcdefghijklmnopqrstuvwxyz\"\n while(t--) {\n const [n,m] = readInts(input, ptr++)\n const s = input[ptr++]\n const ps = readInts(input, ptr++)\n let map = new Array(n)\n for(let i = 0; i < n;i++) map[i] = new Array(26).fill(0)\n map[0][s.charCodeAt(0) - 97] = 1\n for(let i = 1; i < n;i ++) {\n const char = s.charCodeAt(i) - 97\n for(let j = 0;j < 26; j++) {\n map[i][j] = map[i - 1][j]\n }\n map[i][char] = map[i - 1][char] + 1\n }\n // console.log(map)\n\n let ans = new Array(26).fill(0)\n for(let i = 0; i < m;i ++) {\n let x = map[ps[i] - 1]\n for(let j = 0;j < 26; j++) {\n ans[j] = ans[j] + x[j]\n }\n }\n let x = map[n - 1]\n for(let j = 0;j < 26; j++) {\n ans[j] = ans[j] + x[j]\n }\n\n wr(ans.join(' '))\n }\n}"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (a, p) {\n p.push(a.length);\n result = Array(26).fill(0);\n\n const alph = {a:0,b:1,c:2,d:3,e:4,f:5,g:6,h:7,i:8,j:9,k:10,l:11,m:12,n:13,o:14,p:15,q:16,r:17,s:18,t:19,u:20,v:21,w:22,x:23,y:24,z:25};\n\n p.sort((a,b) => a - b);\n\n\n for (let i = 0; i < p.length; i++) {\n let substr = a.slice(p[i-1] || 0, p[i]);\n\n for (let k = 0; k < substr.length; k++) {\n let ind = alph[substr[k]];\n result[ind] = result[ind] + p.length - i;\n }\n }\n return result.join(' ');\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let p = lines[testCount * 3].split(\" \").map(Number);\n let a = lines[testCount * 3 - 1];\n\n let result = foo(a, p);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\n\nmain()\n\nfunction main () {\n let t = getInt()\n while (t --> 0) {\n const params = getInts()\n const s = getLine()[0]\n const mistakes = getInts()\n solve(...params, s, mistakes)\n }\n}\n\nfunction solve (n, m, s, mistakes) {\n const freq = Array(n + 1).fill(0)\n const ans = Array(26).fill(0)\n let accumulate = 0\n\n mistakes.push(n)\n\n mistakes.map(i => {\n freq[0] ++\n freq[i] --\n })\n\n for (let i = 0; i < n; ++i) {\n const ind = s[i].charCodeAt() - 'a'.charCodeAt()\n accumulate += freq[i]\n ans[ind] += accumulate\n }\n\n print(ans.join(' '))\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\n\nmain()\n\nfunction main () {\n let t = getInt()\n while (t --> 0) {\n const params = getInts()\n const s = getLine()[0]\n const mistakes = getInts()\n solve(...params, s, mistakes)\n }\n}\n\nfunction solve (n, m, s, mistakes) {\n const freq = Array(n + 1).fill(0)\n const ans = Array(26).fill(0)\n let accumulate = 0\n\n mistakes.push(n)\n\n for (const i of mistakes) {\n freq[0] ++\n freq[i] --\n }\n\n for (let i = 0; i < n; ++i) {\n const ind = s[i].charCodeAt() - 'a'.charCodeAt()\n accumulate += freq[i]\n ans[ind] += accumulate\n }\n\n print(ans.join(' '))\n}"}, {"source_code": "function generateAlphabets() {\n var alphabets = [];\n var start = 'a'.charCodeAt(0);\n var last = 'z'.charCodeAt(0);\n for (var i = start; i <= last; ++i) {\n alphabets.push(String.fromCharCode(i));\n }\n\n return alphabets;\n}\n\nconst seq = generateAlphabets();\n\n\n\n\nconst processData = (lines) => {\n const num = +lines[0]\n for (let j=0; j {acc[letter] = 0; return acc}, {})\n const row = lines[j*3 + 2]\n const missed = lines[j*3 + 3].split(' ').map(x => x - 1).sort((a, b) => b-a)\n for (let j=0; j 0 && missed[missed.length -1] < j) {\n missed.pop()\n }\n curAlpha[row[j]] += missed.length + 1\n }\n let res = ''\n for (const letter of seq) {\n res += curAlpha[letter] + ' '\n }\n console.log(res)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nfunction main(input) {\n var lines = input.trim().split(\"\\n\").map(function (l) { return l.trim(); });\n var t = parseInt(lines.shift(), 10);\n var _loop_1 = function () {\n var _a = lines.shift(), n = _a[0], m = _a[1];\n var lettersMap = \"qwertyuiopasdfghjklzxcvbnm\".split(\"\").reduce(function (a, k) {\n var _a;\n return (__assign(__assign({}, a), (_a = {}, _a[k] = 0, _a)));\n }, {});\n var combo = lines.shift().split(\"\");\n var tries = lines.shift().split(\" \").map(function (v) { return parseInt(v, 10); });\n var willFail = combo.map(function (v) { return 0; });\n tries.forEach(function (ts) { return willFail[ts - 1]++; });\n var inc = 1;\n for (var i = willFail.length - 1; i >= 0; i--) {\n inc += willFail[i];\n lettersMap[combo[i]] += inc;\n }\n console.log(Object.entries(lettersMap).sort(function (_a, _b) {\n var k = _a[0];\n var l = _b[0];\n return k.charCodeAt(0) - l.charCodeAt(0);\n }).map(function (v) { return v[1]; }).join(\" \"));\n };\n while (t-- > 0) {\n _loop_1();\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (v) { return d += v; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "'use strict';\n\n\n\nlet n = parseInt(readline());\n\nwhile ( n-- > 0 ) {\n let line = readline().split(' ').map(data => parseInt(data));\n solve(...line);\n}\n\nfunction solve(n, m) {\n const str = readline();\n let freq = Array(n + 1).fill(0);\n\n const mistakes = readline().split(' ').map(data => parseInt(data));\n mistakes.push(n);\n\n mistakes.forEach(x => {\n freq[0]++; freq[x]--;\n });\n\n let answer = Array(26).fill(0);\n let accumulated = 0;\n\n for ( let i = 0; i < str.length; ++i ) {\n accumulated += freq[i];\n answer[str.charCodeAt(i) - 97] += accumulated;\n }\n print(answer.join(' '));\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var alphaToNum = {\n \"a\" : 0,\n \"b\" : 1,\n \"c\" : 2,\n \"d\" : 3,\n \"e\" : 4,\n \"f\" : 5,\n \"g\" : 6,\n \"h\" : 7,\n \"i\" : 8,\n \"j\" : 9,\n \"k\" : 10,\n \"l\" : 11,\n \"m\" : 12,\n \"n\" : 13,\n \"o\" : 14,\n \"p\" : 15,\n \"q\" : 16,\n \"r\" : 17,\n \"s\" : 18,\n \"t\" : 19,\n \"u\" : 20,\n \"v\" : 21,\n \"w\" : 22,\n \"x\" : 23,\n \"y\" : 24,\n \"z\" : 25\n }\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = myconv(next(),4);\n var n = one[0];\n var m = one[1];\n var nlist = myconv(next(),6);\n var mlist = myconv(next(),4);\n var outAlpha = new Array(26).fill(0);\n var countMap = new Array(n);\n var tmpMap = {\n \t\"a\" : 0,\n \"b\" : 0,\n \"c\" : 0,\n \"d\" : 0,\n \"e\" : 0,\n \"f\" : 0,\n \"g\" : 0,\n \"h\" : 0,\n \"i\" : 0,\n \"j\" : 0,\n \"k\" : 0,\n \"l\" : 0,\n \"m\" : 0,\n \"n\" : 0,\n \"o\" : 0,\n \"p\" : 0,\n \"q\" : 0,\n \"r\" : 0,\n \"s\" : 0,\n \"t\" : 0,\n \"u\" : 0,\n \"v\" : 0,\n \"w\" : 0,\n \"x\" : 0,\n \"y\" : 0,\n \"z\" : 0\n };\n for(var j = 0; j < n; j++){\n tmpMap[nlist[j]]++;\n \toutAlpha[alphaToNum[nlist[j]]]++;\n countMap[j] = JSON.parse(JSON.stringify(tmpMap));\n }\n for(var j = 0; j < m; j++){\n var tmpCountMap = countMap[mlist[j] - 1]; \n var tmpKeys = Object.keys(tmpCountMap);\n for(var k = 0; k < tmpKeys.length; k++){\n outAlpha[alphaToNum[tmpKeys[k]]] += tmpCountMap[tmpKeys[k]];\n }\n }\n output[i] = myconv(outAlpha,8);\n }\n myout(myconv(output,9));\n}"}], "negative_code": [], "src_uid": "51ea912b40b07c1ba097292ffd0cec18"} {"source_code": ";(function () {\n\n\tprint(function (n, s, k) {\n\n\t\tfor (var i = 1, l = s.length, _i = Math.floor(l / n); i <= _i; i++)\n\t\t\tif (i * n < l && s[i * n - 1] === s[i * n - 2] && s[i * n - 1] === s[i * n - 3]) k++;\n\n\t\treturn k;\n\n\t}(+readline(), readline(), 0));\n\n}.call(this));\n", "positive_code": [{"source_code": "print(function(n, s) {\n\n\tvar ans = 0;\n\n\tfor (var i = n; i < s.length; i += n)\n\t\tif (s[i - 1] === s[i - 2] && s[i - 2] === s[i - 3])\n\t\t\tans++;\n\n\treturn ans;\n\n}(+readline(), readline()));"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function (n, s, k) {\n\n\t\tfor (var i = 1, _i = Math.floor(s.length / n); i <= _i; i++)\n\t\t\tif (s[i * n - 1] === s[i * n - 2] && s[i * n - 1] === s[i * n - 3]) k++;\n\n\t\treturn k;\n\n\t}(+readline(), readline(), 0));\n\n}.call(this));\n"}], "src_uid": "5606799ab5345bb9501fa6535e5abef9"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar a = next();\r\n\t\tvar b = next();\r\n\t\tvar area = [];\r\n\t\tvar count = 0;\r\n\t\tvar last = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(a[j] == \"0\"){\r\n\t\t\t\tcount++;\r\n\t\t\t}else{\r\n\t\t\t\tcount--;\r\n\t\t\t}\r\n\t\t\tif(count == 0){\r\n\t\t\t\tarea.push({\r\n\t\t\t\t\tL : last,\r\n\t\t\t\t\tR : j\r\n\t\t\t\t});\r\n\t\t\t\tlast = j + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = last; j < N; j++){\r\n\t\t\tif(a[j] != b[j]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < area.length; j++){\r\n\t\t\tvar obj = area[j];\r\n\t\t\tvar L = a.substring(obj.L, obj.R + 1);\r\n\t\t\tvar R = \"\";\r\n\t\t\tfor(var k = obj.L; k <= obj.R; k++){\r\n\t\t\t\tR += ((a[k] == \"0\") ? \"1\" : \"0\");\r\n\t\t\t}\r\n\r\n\t\t\tif(b.substring(obj.L, obj.R + 1) != L && b.substring(obj.L, obj.R + 1) != R){\r\n\t\t\t\tisOK = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n\t\r\n}\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rl();\r\n\t\tlet b = rl();\r\n\r\n\t\ta = a.split('');\r\n\t\tconst dp = [];\r\n\t\tdp[-1] = 0;\r\n\t\tfor (let i = 0; i < n; i++)\r\n\t\t\tdp[i] = dp[i-1] + (a[i] == '1') - (a[i] == '0');\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = n - 1, flpd = false; ok && i >= 0; i--) {\r\n\t\t\tif (flpd) \r\n\t\t\t\ta[i] = '10'[a[i]];\r\n\r\n\t\t\tif (a[i] != b[i]) {\r\n\t\t\t\tif (dp[i] != 0)\r\n\t\t\t\t\tok = false;\r\n\t\t\t\telse \r\n\t\t\t\t\tflpd = !flpd;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst ans = ok ? 'YES' : 'NO';\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let str = stringArr();\r\n let str1 = stringArr();\r\n let oarr = [],\r\n cnt0 = 0,\r\n cnt1 = 0,\r\n r = [];\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"0\") {\r\n cnt0++;\r\n r.push(\"1\");\r\n } else {\r\n cnt1++;\r\n r.push(\"0\");\r\n }\r\n oarr.push({ z: cnt0, o: cnt1 });\r\n }\r\n let i = str.length - 1,\r\n ans = true,\r\n l = str,\r\n k = 1;\r\n while (i >= 0) {\r\n let j = i;\r\n while (j >= 0 && l[j] !== str1[j]) j--;\r\n if (i !== j) {\r\n if (oarr[i].z !== oarr[i].o) {\r\n ans = false;\r\n break;\r\n }\r\n if (k) l = r;\r\n else l = str;\r\n k = !k;\r\n i = j;\r\n } else i--;\r\n }\r\n console.log(`${ans ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "l=readline;\r\n\r\nfor (T=l(); T--;) {\r\n \r\n N = +l();\r\n \r\n a = l();\r\n b = l();\r\n \r\n k = 0;\r\n c = 0;\r\n d = 0;\r\n e = \"\";\r\n f = \"\";\r\n res = true;\r\n for (i = 0; i < N; i++) {\r\n k++;\r\n c-=+a[i]?1:-1;\r\n d-=+b[i]?1:-1;\r\n e+=a[i];\r\n f+=b[i];\r\n \r\n if (k % 2 == 0 && c == 0) {\r\n if (e != f && e.replace(/(0|1)/g,x => +!+x) != f) {\r\n res = false;\r\n break;\r\n }\r\n k = 0; c = 0; d = 0; e = f = \"\";\r\n }\r\n }\r\n \r\n print(res && e == f? 'YES' : 'NO')\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let str = stringArr();\r\n let str1 = stringArr();\r\n const check = (st, ed) => {\r\n if (st === ed) return false;\r\n let cnt1 = 0,\r\n cnt2 = 0;\r\n for (let i = st; i <= ed; i++) {\r\n if (str[i] === \"0\") cnt1++;\r\n else cnt2++;\r\n }\r\n if (cnt1 === cnt2) return true;\r\n else return false;\r\n };\r\n let ans = true,\r\n i = 0;\r\n while (i < n) {\r\n let j = i;\r\n while (j < n && str[j] !== str1[j]) {\r\n j++;\r\n }\r\n if (i !== j) {\r\n if (j - 1 === i) {\r\n ans = false;\r\n break;\r\n }\r\n if (!check(0, j - 1)) {\r\n ans = false;\r\n break;\r\n }\r\n i = j;\r\n } else i++;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let str = stringArr();\r\n let str1 = stringArr();\r\n const check = (st, ed) => {\r\n if (st === ed) return false;\r\n let cnt1 = 0,\r\n cnt2 = 0;\r\n for (let i = st; i <= ed; i++) {\r\n if (str[i] === \"0\") cnt1++;\r\n else cnt2++;\r\n }\r\n if (cnt1 === cnt2) return true;\r\n else return false;\r\n };\r\n let ans = true,\r\n i = 0;\r\n while (i < n) {\r\n let j = i;\r\n while (j < n && str[j] !== str1[j]) {\r\n j++;\r\n }\r\n if (i !== j) {\r\n if (!check(0, j - 1)) {\r\n ans = false;\r\n break;\r\n }\r\n i = j;\r\n } else i++;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let str = stringArr();\r\n let str1 = stringArr();\r\n const check = (st, ed) => {\r\n if (st === ed) return false;\r\n let cnt1 = 0,\r\n cnt2 = 0;\r\n for (let i = st; i <= ed; i++) {\r\n if (str[i] === \"0\") cnt1++;\r\n else cnt2++;\r\n }\r\n if (cnt1 === cnt2) return true;\r\n else return false;\r\n };\r\n let ans = true,\r\n i = 0;\r\n while (i < n) {\r\n let j = i;\r\n while (j < n && str[j] !== str1[j]) {\r\n j++;\r\n }\r\n if (i !== j) {\r\n if (!check(i, j - 1)) {\r\n ans = false;\r\n break;\r\n }\r\n i = j;\r\n } else i++;\r\n }\r\n console.log(`${ans === true ? \"YES\" : \"NO\"}`);\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "ff95cd4632b2ddf8bb54981634badcae"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet ans = -1;\r\n\t\tif (s.includes('aa')) ans = 2;\r\n\t\telse if (s.includes('aba') || s.includes('aca')) ans = 3;\r\n\t\telse if (s.includes('abca') || s.includes('acba')) ans = 4;\r\n\t\telse if (s.includes('abbacca') || s.includes('accabba')) ans = 7;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "function getMin(arr) {\r\n var len = arr.length;\r\n var min = Infinity;\r\n\r\n while (len--) {\r\n min = arr[len] < min ? arr[len] : min;\r\n }\r\n return min;\r\n}\r\n\r\nfunction dominant_character(n,s){\r\n var ans = [];\r\n for (var i=0; i7){\r\n break;\r\n }\r\n var c_a = (substring.match(/a/g) || []).length;\r\n var c_b = (substring.match(/b/g) || []).length;\r\n var c_c = (substring.match(/c/g) || []).length;\r\n if(c_a>c_c && c_a>c_b){\r\n ans.push(substring.length);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if(ans.length>0){\r\n var result = getMin(ans);\r\n }\r\n else{\r\n var result = -1;\r\n }\r\n return result;\r\n}\r\n \r\nt = parseInt(readline());\r\nfor(var i=0; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n if (contains(str, ['aa'])) return 2\n if (contains(str, ['aba', 'aca'])) return 3\n if (contains(str, ['abca', 'acba'])) return 4\n if (contains(str, ['abbacca', 'accabba'])) return 7\n return -1\n}\nfunction contains(str, ps) {\n return ps.some(p => str.indexOf(p) >= 0)\n}\n"}], "negative_code": [{"source_code": "function dominant_character(n,s){\r\n var ans = [];\r\n for (var i=0; i7){\r\n break;\r\n }\r\n var c_a = (substring.match(/a/g) || []).length;\r\n var c_b = (substring.match(/b/g) || []).length;\r\n var c_c = (substring.match(/c/g) || []).length;\r\n if(c_a>c_c && c_a>c_b){\r\n ans.push(substring.length);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n print(ans);\r\n if(ans.length>0){\r\n var result = Math.min(...ans);\r\n }\r\n else{\r\n var result = -1;\r\n }\r\n return result;\r\n}\r\n \r\nt = parseInt(readline());\r\nfor(var i=0; i7){\r\n break;\r\n }\r\n var c_a = (substring.match(/a/g) || []).length;\r\n var c_b = (substring.match(/b/g) || []).length;\r\n var c_c = (substring.match(/c/g) || []).length;\r\n if(c_a>c_c && c_a>c_b){\r\n ans.push(substring.length);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if(ans!=[]){\r\n var result = Math.min(...ans);\r\n }\r\n else{\r\n var result = -1;\r\n }\r\n return result;\r\n}\r\n\r\nt = parseInt(readline());\r\nfor(var i=0; i dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet ans = -1;\r\n\t\tif (s.includes('aa')) ans = 2;\r\n\t\telse if (s.includes('aba') || s.includes('aca')) ans = 3;\r\n\t\telse if (s.includes('abca') || s.includes('acba')) ans = 4;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst readLine = () => dataitr.next().value.trim();\r\nfunction rl () {\r\n\tlet ans = readLine().split(' ');\r\n\tif (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));\r\n\treturn ans.length == 1 ? ans[0] : ans;\r\n}\r\n\r\nfunction main () {\r\n\tlet t = rl();\r\n\twhile (t--) {\r\n\t\tlet n = rl();\r\n\t\tlet s = rl();\r\n\r\n\t\tlet ans = -1;\r\n\t\tif (s.includes('aa')) ans = 2;\r\n\t\telse if (s.includes('aba') || s.includes('aca')) ans = 3;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n if (contains(str, ['aa'])) return 2\n if (contains(str, ['aba', 'aca'])) return 3\n if (contains(str, ['abca', 'abba', 'acca', 'acba'])) return 4\n return -1\n}\nfunction contains(str, ps) {\n return ps.some(p => str.indexOf(p) >= 0)\n}\n"}], "src_uid": "c2f3d09674190f90c940f134c3e22afe"} {"source_code": "function solve() {\n var n = +readline();\n var a = readline().split(' ');\n //n = 100000;\n //a = [];\n //for (var i = 0; i < n; i++) {\n //a.push(i + 1);\n // }\n var need = 0;\n for (var i = 0; i < n; i++) {\n a[i] = +a[i];\n need += a[i];\n }\n if (need % 2 !== 0) {\n print(\"NO\");\n return;\n }\n need /= 2;\n \n var was = new Set;\n \n var sum = 0;\n \n for (var i = 0; i < n; i++) {\n sum += a[i];\n was.add(a[i]);\n var val = sum - need;\n if (was.has(val)) {\n print(\"YES\");\n return;\n }\n }\n \n was = new Set;\n \n sum = 0;\n \n a = a.reverse();\n \n for (var i = 0; i < n; i++) {\n sum += a[i];\n was.add(a[i]);\n var val = sum - need;\n if (was.has(val)) {\n print(\"YES\");\n return;\n }\n }\n \n print(\"NO\");\n \n}\nsolve();", "positive_code": [{"source_code": "function foo(array) {\n var length = array.length;\n\n var need = 0;\n for (var i=0; i 1000000000 || val <= 0) {\n continue;\n }\n if (was[val]) {\n print(\"YES\");\n return;\n }\n }\n \n print(\"NO\");\n \n}\nsolve();"}], "src_uid": "27b93795ffc771b47b995e2b83f7b945"} {"source_code": "// s of n\n// power two\nlet lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const q = lines[0]\n\n for(let i = 1; i <= q * 2; i+=2) {\n const n = lines[i]\n const s = lines[i + 1].split(/\\s/)\n const m = {}\n let result = false\n\n s.some(v => {\n if(!m[v]) m[v] = []\n \n m[v].push(Number(v))\n\n if(m[v].length === 2) {\n const sum = makeSum(m, v)\n\n if(sum === 2048) {\n result = true\n return result\n }\n } else {\n if(v === '2048') {\n result = true\n return result\n }\n }\n })\n\n console.log(result ? 'YES' : 'NO')\n }\n}\n\nfunction makeSum(m, v) {\n const sum = Number(v) + Number(v)\n\n if(!m[sum]) m[sum] = []\n\n m[sum].push(sum)\n m[v] = []\n\n if(m[sum].length === 2) {\n return makeSum(m, sum)\n } else {\n return sum\n }\n}\n", "positive_code": [{"source_code": "q=+readline()\nwhile (q--){\n a=new Array(2049)\n for (i=0;i<=2048;i++)\n a[i]=0\n n=+readline()\n s=readline().split(' ').map(function(x){a[+x]++;return undefined})\n for (i=2;i<=2048;i*=2){\n a[i]+=a[i/2]>>1\n }\n if (a[2048])\n print(\"YES\")\n else\n print(\"NO\")\n}"}, {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar gamesAmount = parseInt(readline());\nvar answers = [];\nvar nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048];\n\nvar _loop = function _loop(game) {\n var n = parseInt(readline());\n var s = readline().getNumArray();\n var obj = {\n 1: 0,\n 2: 0,\n 4: 0,\n 8: 0,\n 16: 0,\n 32: 0,\n 64: 0,\n 128: 0,\n 256: 0,\n 512: 0,\n 1024: 0,\n 2048: 0\n };\n var answer = 'YES';\n\n for (var i = 0; i < n; i++) {\n if (s[i] === 2048) {\n obj[2048] = 1;\n break;\n }\n\n if (s[i] < 2048) {\n obj[s[i]] += 1;\n }\n }\n\n if (obj[2048]) {\n answers.push(answer);\n return \"continue\";\n } else {\n nums.forEach(function (_n) {\n var nextN = _n * 2;\n var nextNAmount = Math.floor((obj[_n] || 0) / 2);\n obj[nextN] += nextNAmount;\n });\n\n if (!obj[2048]) {\n answer = 'NO';\n }\n\n answers.push(answer);\n }\n};\n\nfor (var game = 0; game < gamesAmount; game++) {\n var _ret = _loop(game);\n\n if (_ret === \"continue\") continue;\n}\n\nwrite(answers.join('\\n'));"}], "negative_code": [{"source_code": "// s of n\n// power two\nlet lines = ''\n \nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('data', input => lines += input)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n \n main()\n})\n \nfunction main() {\n const q = lines[0]\n\n for(let i = 1; i <= q * 2; i+=2) {\n const n = lines[i]\n const s = lines[i + 1].split(/\\s/).map(Number).sort((a, b) => a - b)\n let result = false\n let p = s[0]\n let sum = p\n\n s.slice(1).some(v => {\n if(sum === 2048) {\n return true\n } else if(v === 2048) {\n sum = v\n return true\n }\n\n if(p === v) {\n sum = p + v\n p = sum\n } else {\n p = v\n }\n })\n\n if(sum === 2048) {\n result = true\n }\n\n console.log(result ? 'YES' : 'NO')\n }\n}\n"}, {"source_code": "\"use strict\";\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nvar gamesAmount = parseInt(readline());\nvar answers = [];\nvar nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048];\n\nvar _loop = function _loop(game) {\n var n = parseInt(readline());\n var s = readline().getNumArray();\n var obj = {\n 1: 0,\n 2: 0,\n 4: 0,\n 8: 0,\n 16: 0,\n 32: 0,\n 64: 0,\n 128: 0,\n 256: 0,\n 512: 0,\n 1024: 0,\n 2048: 0\n };\n var answer = 'YES';\n\n for (var i = 0; i < n; i++) {\n if (s[i] === 2048) {\n obj[2048] = 1;\n break;\n }\n\n if (s[i] < 2048) {\n obj[s[i]] += 1;\n }\n\n nums.forEach(function (_n) {\n var nextN = _n * 2;\n var nextNAmount = Math.floor((obj[_n] || 0) / 2);\n obj[nextN] += nextNAmount;\n });\n }\n\n if (!obj[2048]) {\n answer = 'NO';\n }\n\n answers.push(answer);\n};\n\nfor (var game = 0; game < gamesAmount; game++) {\n _loop(game);\n}\n\nwrite(answers.join('\\n'));"}], "src_uid": "b40059fe9cbdb0cc3b64c3e463900849"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var tmp = [];\n for(var j = 0; j < N; j++){\n tmp.push(list.pop());\n }\n output[i] = myconv(tmp, 8);\n }\n myout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex(v => v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n t = inp[r++];\n while (t--) {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n console.log(a.reverse().join(' '))\n }\n})();\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n \n\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n for(let i = 0; i < Math.floor(n/2); i++){\n let temp = a[i];\n a[i] = a[n-i-1];\n a[n-i-1] = temp;\n }\n \n for(let num of a)\n console.log(num);\n }\n}\n\nfunction F(){\n let [n,x] = ti(readline().split(' '));\n let s = readline();\n let t = readline();\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(x+1);\n for(let j = 0; j <= x; j++){\n dp[i][j] = new Array(n);\n dp[i][j].fill(0);\n }\n }\n\n for(let i = 1; i < n; i++){\n for(let j = 0; j <= x; j++){\n for(let k = 0; k <= n; k++){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));\n if(j !== 0){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);\n }\n }\n }\n }\n\n let max = 0;\n for(let i = 0; i < x; i++)\n for(let j = 0; j < n; j++)\n max = Math.max(max, dp[n-1][i][j]);\n\n console.log(max);\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.reverse();\n console.log(arr.join(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n list.sort(function(){\n return 1;\n });\n output[i] = myconv(list, 8);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n \n\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n % 2 === 0){\n for(let i = 1; i < n; i += 2){\n let temp = a[i-1];\n a[i-1] = a[i];\n a[i] = temp;\n }\n }else{\n for(let i = 0; i < Math.floor(n/2); i++){\n let temp = a[i];\n a[i] = a[n-i-1];\n a[n-i-1] = temp;\n }\n }\n \n for(let num of a)\n console.log(num);\n }\n}\n\nfunction F(){\n let [n,x] = ti(readline().split(' '));\n let s = readline();\n let t = readline();\n\n let dp = new Array(n);\n for(let i = 0; i < n; i++){\n dp[i] = new Array(x+1);\n for(let j = 0; j <= x; j++){\n dp[i][j] = new Array(n);\n dp[i][j].fill(0);\n }\n }\n\n for(let i = 1; i < n; i++){\n for(let j = 0; j <= x; j++){\n for(let k = 0; k <= n; k++){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));\n if(j !== 0){\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));\n dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);\n }\n }\n }\n }\n\n let max = 0;\n for(let i = 0; i < x; i++)\n for(let j = 0; j < n; j++)\n max = Math.max(max, dp[n-1][i][j]);\n\n console.log(max);\n}"}], "src_uid": "1eaff8e0ec4614753699128af74b2471"} {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const ar = (await getLine()).split(' ').map(num => parseInt(num));\r\n ar.sort((a,b) => (a-b));\r\n let sum = BigInt(ar[n-1]);\r\n for(let i = 1; i < n; i++) {\r\n sum -= BigInt(ar[i] - ar[i-1]) * BigInt(i) * BigInt(n - i);\r\n }\r\n console.log(sum.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const T = input.number();\r\n const ans = Array(T);\r\n for (let k = 0; k < T; k++) {\r\n const N = input.number();\r\n const A = input.numbers(N);\r\n A.sort((a, b) => a - b);\r\n let sum = 0n;\r\n let acc = 0;\r\n for (let [i, j] = [N - 1, 0]; i >= 1; i--, j++) {\r\n acc += i - j;\r\n sum -= BigInt(acc - 1) * BigInt(A[j + 1] - A[j]);\r\n }\r\n ans[k] = sum;\r\n }\r\n console.log(ans.join('\\n'));\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n if (n === 1) return 0\n\n arr.sort((a, b) => a - b)\n // let ans = 0\n // let s = 0\n // for (let i = 0; i < n; ++i) {\n // ans -= arr[i] * i;\n // ans += s;\n // s += arr[i];\n // }\n // ans += arr[n - 1];\n // return ans\n\n const segs = []\n arr.forEach((a, i) => {\n let val\n if (i) {\n val = arr[i] - arr[i - 1]\n } else {\n val = arr[i]\n }\n // filter the first\n if (i) {\n segs.push(BigInt(val))\n }\n })\n // console.log(segs)\n\n const dp = []\n let count = 0n\n let sum = 0n // sum of those end with i\n segs.forEach((a, i) => {\n sum += count * a + a\n count++\n if (i) {\n dp[i] = dp[i - 1] + sum\n } else {\n dp[i] = a\n }\n })\n // console.log(dp)\n const result = calSum(segs) - dp[segs.length - 1]\n return result.toString()\n}\n\nfunction calSum(arr) {\n return arr.reduce((s, x) => s + x, 0n)\n}\n"}], "negative_code": [{"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n if (n === 1) return 0\n\n arr.sort((a, b) => a - b)\n // let ans = 0\n // let s = 0\n // for (let i = 0; i < n; ++i) {\n // ans -= arr[i] * i;\n // ans += s;\n // s += arr[i];\n // }\n // ans += arr[n - 1];\n // return ans\n\n const segs = []\n arr.forEach((a, i) => {\n let val\n if (i) {\n val = arr[i] - arr[i - 1]\n } else {\n val = arr[i]\n }\n // filter the first\n if (i) {\n segs.push(val)\n }\n })\n // console.log(segs)\n\n const dp = []\n let count = 0\n let sum = 0 // sum of those end with i\n segs.forEach((a, i) => {\n sum += count * a + a\n count++\n if (i) {\n dp[i] = dp[i - 1] + sum\n } else {\n dp[i] = a\n }\n })\n // console.log(dp)\n return calSum(segs) - dp[segs.length - 1]\n}\n\nfunction calSum(arr) {\n return arr.reduce((s, x) => s + x, 0)\n}\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = +lines[0]\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n if (n === 1) return 0\n\n arr.sort((a, b) => a - b)\n\n const segs = []\n arr.forEach((a, i) => {\n let val\n if (i) {\n val = arr[i] - arr[i - 1]\n } else {\n val = arr[i]\n }\n // filter 0\n if (val) {\n segs.push(val)\n }\n })\n // console.log(segs)\n\n const dp = []\n segs.forEach((a, i) => {\n if (i) {\n dp[i] = dp[i - 1] + a + a + dp[i - 1]\n } else {\n dp[i] = a\n }\n })\n return calSum(segs) - dp[segs.length - 1]\n}\n\nfunction calSum(arr) {\n return arr.reduce((s, x) => s + x, 0)\n}\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const ar = (await getLine()).split(' ').map(num => parseInt(num));\r\n ar.sort((a,b) => (a-b));\r\n let sum = ar[n-1];\r\n for(let i = 1; i < n; i++) {\r\n sum -= (ar[i] - ar[i-1]) * (i) * (n - i);\r\n }\r\n console.log(sum);\r\n }\r\n}\r\n\r\nsolve();\r\n"}], "src_uid": "7dfe0db5a99e6e4d71eb012fab07685b"} {"source_code": "var n = +readline(),\n dims = [],\n dim, i, h, s, pair, min = +Infinity;\nfor (i = 0; i < n; i++) {\n pair = readline().split(' ');\n dims[i] = [];\n dims[i][0] = +pair[0];\n dims[i][1] = +pair[1];\n}\nfor (h = 1000; h > 0; h--) {\n s = 0;\n for (i = 0; i < n; i++) {\n dim = dims[i].sort(function(a,b) {\n return a - b;\n });\n if (h < dim[0]) {\n h = 0;\n break;\n } else {\n s += h*dim[h < dim[1] ? 1 : 0];\n }\n }\n h == 0 || (min = Math.min(min, s));\n}\nprint(min);\n", "positive_code": [{"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {\n\t\treturn Number(v);\n\t});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\tif (width != -1) {\n\t\tvar size = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > size) {\n\t\t\t\tresult = size;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = size;\n\t\t}\n\t}\n\theight = sizes[i].width;\n\twidth = compare(i, height);\n\tif (width != -1) {\n\t\tvar size = (width + sizes[i].height) * height;\n\t\tif (result) {\n\t\t\tif (result > size) {\n\t\t\t\tresult = size;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = size;\n\t\t}\n\t}\n}\n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height <= height || sizes[j].width <= height) {\n\t\t\t\tif (sizes[j].height <= height && sizes[j].width <= height) {\n\t\t\t\t\tif (sizes[j].height <= sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width <= height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t}\n\tif (width != undefined) {\n\t\treturn width;\n\t} else {\n\t\treturn -1;\n\t}\n}\n\nprint(result)"}], "negative_code": [{"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {return Number(v);});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n\theight = sizes[i].width;\n\twidth = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].height) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n} \n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height < height || sizes[j].width < height) {\n\t\t\t\tif (sizes[j].height < height && sizes[j].width < height) {\n\t\t\t\t\tif (sizes[j].height < sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width <= height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tif (width) {\n\t\tprint(width + sizes[i].height, height)\n\t\treturn width;\n\t}\n}\n\nprint(result)"}, {"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {return Number(v);});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n\theight = sizes[i].width;\n\twidth = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].height) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n} \n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height < height || sizes[j].width < height) {\n\t\t\t\tif (sizes[j].height < height && sizes[j].width < height) {\n\t\t\t\t\tif (sizes[j].height < sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width <= height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tif (width) {\n\t\treturn width;\n\t}\n}\n\nprint(result)"}, {"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {return Number(v);});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n\theight = sizes[i].width;\n\tvar width = compare(i, height);\n\tif (width) {\n\t\twidth = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > width) {\n\t\t\t\tresult = width;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = width;\n\t\t}\n\t}\n} \n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height < height || sizes[j].width < height) {\n\t\t\t\tif (sizes[j].height < height && sizes[j].width < height) {\n\t\t\t\t\tif (sizes[j].height < sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width < height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tif (width) {\n\t\treturn width;\n\t}\n}\n\nprint(result)"}, {"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {\n\t\treturn Number(v);\n\t});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\tif (width != -1) {\n\t\tvar size = (width + sizes[i].width) * height;\n\t\tif (result) {\n\t\t\tif (result > size) {\n\t\t\t\tresult = size;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = size;\n\t\t}\n\t}\n\theight = sizes[i].width;\n\twidth = compare(i, height);\n\tif (width != -1) {\n\t\tvar size = (width + sizes[i].height) * height;\n\t\tif (result) {\n\t\t\tif (result > size) {\n\t\t\t\tresult = size;\n\t\t\t}\n\t\t} else {\n\t\t\tresult = size;\n\t\t}\n\t}\n}\n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height <= height || sizes[j].width <= height) {\n\t\t\t\tif (sizes[j].height <= height && sizes[j].width <= height) {\n\t\t\t\t\tif (sizes[j].height <= sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width <= height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t}\n\tif (width) {\n\t\treturn width;\n\t} else {\n\t\treturn -1;\n\t}\n}\n\nprint(result)"}, {"source_code": "var n = readline();\nvar sizes = [];\n\nfor (var i = 0; i < n; i++) {\n\tvar line = readline().split(' ').map((v) => {return Number(v);});\n\tsizes[i] = {};\n\tsizes[i].width = line[0];\n\tsizes[i].height = line[1];\n}\n\nvar result;\nfor (var i = 0; i < n; i++) {\n\tvar height = sizes[i].height;\n\tvar width = compare(i, height);\n\twidth = (width + sizes[i].width) * height;\n\tif (result) {\n\t\tif (result > width) {\n\t\t\tresult = width;\n\t\t}\n\t} else {\n\t\tresult = width;\n\t}\n\theight = sizes[i].width;\n\twidth = compare(i, height);\n\twidth = (width + sizes[i].height) * height;\n\tif (result) {\n\t\tif (result > width) {\n\t\t\tresult = width;\n\t\t}\n\t} else {\n\t\tresult = width;\n\t}\n} \n\n\nfunction compare(i, height) {\n\tvar width = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j != i) {\n\t\t\tif (sizes[j].height <= height || sizes[j].width <= height) {\n\t\t\t\tif (sizes[j].height < height && sizes[j].width < height) {\n\t\t\t\t\tif (sizes[j].height < sizes[j].width) {\n\t\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t\t}\n\t\t\t\t} else if (sizes[j].width <= height) {\n\t\t\t\t\twidth += sizes[j].height;\n\t\t\t\t} else {\n\t\t\t\t\twidth += sizes[j].width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tif (width) {\n\t\treturn width;\n\t} else {\n\t\treturn 0;\n\t}\n}\n\nprint(result)"}], "src_uid": "c1e952cb7dd158f12df6affcff07b68a"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nconst s2i = s => parseInt(s, 10);\n\nfunction main() {\n let T = s2i(readLine());\n let a, b, c, r1, r2;\n while (T--) {\n [a, b, c] = readLine().split(' ').map(s2i);\n\n if (a < c) {\n r1 = 1;\n } else {\n r1 = -1;\n }\n\n if (c/b < a) {\n r2 = b;\n } else {\n r2 = -1;\n }\n\n console.log(r1 + ' ' + r2);\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [a, b, c] = readLine()\n .split(\" \")\n .map((num) => parseInt(num));\n let [l, r] = [-1, -1];\n if (a < c) l = 1;\n\n if (a * b > c) r = b;\n\n console.log(`${l} ${r}`);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let str = data[i].split(' ');\n let a = +str[0];\n let b = +str[1];\n let c = +str[2];\n if ((a == c && a == b) || a > c) {\n console.log(-1, b);\n i += 1;\n continue;\n }\n if (a == c) {\n console.log(-1, b);\n i += 1;\n continue;\n }\n if (a * b <= c) {\n console.log(1, -1);\n i += 1;\n continue;\n }\n console.log(1, b);\n i += 1;\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split(/\\r?\\n/);\n const testCases = data[0] * 1;\n let numAnswered = 0\n let i = 1;\n while (i <= testCases) {\n let split = data[i].split(\" \")\n let a = split[0] * 1\n let b = split[1] * 1\n let c = split[2] * 1\n\n let shop1Cheaper = 0\n let x = 1\n let curDiff = Number.MAX_VALUE\n while (shop1Cheaper === 0) {\n let tempDiff = a * x - Math.ceil(x/b) * c\n let endIfNotAnswer = tempDiff > curDiff\n curDiff = tempDiff\n shop1Cheaper = curDiff < 0 ? x : (endIfNotAnswer ? -1 : 0)\n x++\n }\n\n let shop2Cheaper = 0\n x = b\n curDiff = Number.NEGATIVE_INFINITY\n while (shop2Cheaper === 0) {\n let tempDiff = a * x - Math.ceil(x/b) * c\n let endIfNotAnswer = tempDiff < curDiff\n curDiff = tempDiff\n shop2Cheaper = curDiff > 0 ? x : (endIfNotAnswer ? -1 : 0)\n x++\n }\n console.log(`${shop1Cheaper} ${shop2Cheaper}`)\n i++\n }\n}"}, {"source_code": "var n = readline();\nvar mapping =[];\n\nfor (var i = 0; i=mapping[i][2]){\n write(-1 + \" \");\n }else{\n var ni = 1;\n while (true){\n if (mapping[i][0] * ni < mapping[i][2] * Math.ceil(parseFloat(ni/mapping[i][1]))){\n break;\n }\n ni++;\n }\n write(ni + \" \");\n }\n\n if (parseFloat(mapping[i][0]) <= parseFloat(mapping[i][2] / mapping[i][1])){\n write(-1 + \"\\n\");\n }else{\n var ni = 1;\n while (true){\n if (parseInt(mapping[i][2] * ni) < parseInt(mapping[i][0] * mapping[i][1] * ni)){\n break;\n }\n ni++;\n }\n write(ni *mapping[i][1] + \"\\n\");\n }\n\n}"}, {"source_code": "function solve() {\n var T = Number(read());\n var ans = [-1, -1];\n for (var t = 0; t < T; t++) {\n var abc = read().split(' ').map(BigInt);\n var a = abc[0];\n var b = abc[1];\n var c = abc[2];\n ans[0] = a < c ? 1 : -1;\n ans[1] = a * b > c ? b : -1;\n write(ans.join(' '));\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n }\n} else {\n solve();\n}\n\nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [single, totalItem, totalValue] = readLine()\n .split(\" \")\n .map((num) => parseInt(num));\n let [left, right] = [-1, -1];\n if (single - totalValue < 0) {\n left = 1;\n if (+(totalValue / totalItem).toFixed(2) < single) right = 1;\n console.log(`${left} ${right}`);\n } else {\n console.log(`${left} ${1}`);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let str = data[i].split(' ');\n let a = +str[0];\n let b = +str[1];\n let c = +str[2];\n if ((a == c && a == b) || a > c) {\n console.log(-1, b);\n i += 1;\n continue;\n }\n if (a * b <= c) {\n console.log(1, -1);\n i += 1;\n continue;\n }\n console.log(1, b);\n i += 1;\n }\n }"}], "src_uid": "002801f26568a1b3524d8754207d32c1"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nconst input = [];\nconst res = []\nlet pr, cur = 0, m, n;\n\nconst pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']\n\n\n/**\n * I have used a split and map together which time complexity is O(n)\n * \n * The sum of characters of every word will \n * always be the length of the sentance. \n * The complexity is O(sum of all words' \n * character lengths), and instead of estimating \n * both character length and amount of words at \n * the worst case, we notice this is simply O(n).\n * \n * As sequential chaining of a constant amount \n * of O(n) operations is still O(n), \n * we get the above mentioned overall complexity \n * of O(n), where n is the amount of characters.\n * \n * used a simple for loop inside of a while loop\n * the complexity of while loop is O(n^2)\n * \n * The total complexity of the program is O(n^2) = O(n) + O(n^2)\n*/\n\nrl.on(\"line\", (line) => {\n input.push(line);\n if (input.length === 2) {\n [n, m] = input[0].split(' ').map(e => +e) // O(n)\n let s = input[1]\n pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))\n do { // O(n^2)\n for (let i = 0; i < n; ++i) { // O(n)\n pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);\n }\n ++cur;\n } while(cur < 6)\n }\n\n if (input.length > 2) {\n const [l, r] = input.pop().split(' ').map(e => +e)\n let ans = n;\n for (let i = 0; i < 6; ++i)\n ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);\n res.push(ans)\n }\n\n});\nrl.on(\"close\", () => {\n res.forEach(e => console.log(e))\n});\n \t \t\t \t \t \t \t\t \t\t \t", "positive_code": [{"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\nconst input = [];\r\nconst res = []\r\nlet pr, cur = 0, m, n\r\nconst pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']\r\nrl.on(\"line\", (line) => {\r\n input.push(line);\r\n if (input.length === 2) {\r\n [n, m] = input[0].split(' ').map(e => +e)\r\n let s = input[1]\r\n pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))\r\n do {\r\n for (let i = 0; i < n; ++i) {\r\n pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);\r\n }\r\n ++cur;\r\n } while(cur < 6)\r\n }\r\n if (input.length > 2) {\r\n const [l, r] = input.pop().split(' ').map(e => +e)\r\n let ans = n;\r\n for (let i = 0; i < 6; ++i) ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);\r\n res.push(ans)\r\n }\r\n\r\n});\r\nrl.on(\"close\", () => {\r\n res.forEach(e => console.log(e))\r\n});"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n // var t = parseInt(lines[0]);\n var l = 0;\n var [n, m] = lines[l++].trim().split(' ').map(Number)\n var str = lines[l++]\n var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\n l += m\n console.log(solve(n, m, str, arr))\n // for (var i = 0; i < t; i++) {\n // var n = +lines[l++]\n // var a = lines[l++].trim().split(' ').map(Number)\n // var b = lines[l++].trim().split(' ').map(Number)\n // }\n});\n\nfunction solve(n, m, str, arr) {\n const d = [];\n ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'].forEach((p, i) => {\n d[i] = []\n for (let j = 0; j < n; j++) {\n const ch = p[j % 3]\n d[i][j] = str[j] === ch ? 0 : 1\n }\n })\n\n const prefix = []\n for (let i = 0; i < d.length; i++) {\n prefix[i] = []\n for (let j = 0; j < d[i].length; j++) {\n prefix[i][j] = j ? d[i][j] + prefix[i][j - 1] : d[i][j]\n }\n }\n\n return arr.map(([l, r]) => {\n l--\n r--\n const ds = prefix.map(p => p[r] - (l ? p[l - 1] : 0))\n return Math.min(...ds)\n }).join('\\n')\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, s, a) {\r\n const sums = [],\r\n strs = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];\r\n for (let str of strs) {\r\n let sum = new Array(n);\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + (s[i] === str[i % 3] ? 0 : 1);\r\n }\r\n sums.push(sum);\r\n }\r\n let res = new Array(m);\r\n for (let [i, [l, r]] of a.entries()) {\r\n let min = Infinity;\r\n for (let i = 0; i < 6; i++) {\r\n var _sums$i;\r\n min = Math.min(min, sums[i][r] - ((_sums$i = sums[i][l - 1]) !== null && _sums$i !== void 0 ? _sums$i : 0));\r\n }\r\n res[i] = min;\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const s = await read();\r\n const a = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(str => Number(str) - 1));\r\n }\r\n res.push(solve(n, m, s, a));\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet [n, m] = rna();\r\n\tconst s = rl();\r\n\r\n\tconst cost = Array.from(Array(6), _ => []);\r\n\tconst perm = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];\r\n\r\n\tfor (let i = 0; i < n; i++) {\r\n\t\tfor (let j = 0; j < perm.length; j++) {\r\n\t\t\tcost[j][i] = cost[j][i-1] || 0;\r\n\t\t\tif (s[i] != perm[j][i%3]) cost[j][i]++;\r\n\t\t}\r\n\t}\r\n\r\n\twhile (m--) {\r\n\t\tlet [l, r] = rna(); l--, r--;\r\n\t\tlet ans = 1e9;\r\n\t\tfor (let i = 0; i < cost.length; i++) {\r\n\t\t\tans = Math.min(ans, cost[i][r] - (cost[i][l-1] || 0));\r\n\t\t}\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(e)\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nconst MAX_N = 200010,\r\n a = new Array(MAX_N),\r\n b = new Array(MAX_N),\r\n c = new Array(MAX_N),\r\n a2 = new Array(MAX_N),\r\n b2 = new Array(MAX_N),\r\n c2 = new Array(MAX_N)\r\n__main__(function (e) {\r\n const [n, t] = e.readIntegersOfLine(),\r\n i = e.readLine().trim()\r\n ;(a[0] = b[0] = c[0] = 0), (a2[0] = b2[0] = c2[0] = 0)\r\n for (let e = 0; e < i.length; ++e) {\r\n const n = i[e]\r\n ;(a[e + 1] = c[e] + ('a' === n ? 0 : 1)),\r\n (b[e + 1] = a[e] + ('b' === n ? 0 : 1)),\r\n (c[e + 1] = b[e] + ('c' === n ? 0 : 1)),\r\n (a2[e + 1] = b2[e] + ('a' === n ? 0 : 1)),\r\n (b2[e + 1] = c2[e] + ('b' === n ? 0 : 1)),\r\n (c2[e + 1] = a2[e] + ('c' === n ? 0 : 1))\r\n }\r\n for (let i = 0; i < t; ++i) {\r\n let [t, i] = e.readIntegersOfLine()\r\n t -= 1\r\n let s = n\r\n switch ((i - t + 1) % 3) {\r\n case 0:\r\n s = Math.min(\r\n c[i] - a[t],\r\n a[i] - b[t],\r\n b[i] - c[t],\r\n b2[i] - a2[t],\r\n c2[i] - b2[t],\r\n a2[i] - c2[t],\r\n )\r\n break\r\n case 1:\r\n s = Math.min(\r\n a[i] - a[t],\r\n b[i] - b[t],\r\n c[i] - c[t],\r\n a2[i] - a2[t],\r\n b2[i] - b2[t],\r\n c2[i] - c2[t],\r\n )\r\n break\r\n case 2:\r\n s = Math.min(\r\n b[i] - a[t],\r\n c[i] - b[t],\r\n a[i] - c[t],\r\n c2[i] - a2[t],\r\n a2[i] - b2[t],\r\n b2[i] - c2[t],\r\n )\r\n }\r\n e.print(s + '\\n')\r\n }\r\n})\r\n"}], "negative_code": [{"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/r/g, '').split('\\n');\n const [len, total] = input[0].split(' ').map((ele) => +ele);\n const str = input[1];\n const tree = new Tree(str);\n for (let i = 0; i < total; i++) {\n solve(tree, input[2 + i]);\n }\n\n process.exit();\n});\n\nfunction solve(tree, range) {\n const [L, R] = range.split(' ').map((ele) => ele - 1);\n const result = tree.findEntry(L, R);\n console.log(Math.min(...result));\n}\n\nclass Tree {\n\n constructor(str) {\n this.mays = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];\n this.root = this.build(str, 0, str.length - 1);\n }\n\n build(str, l, r) {\n if (l === r) {\n const ary = new Array(18);\n for (let i = 0; i < 6; i++) {\n const compare = this.mays[i];\n ary[i * 3] = str[l] === compare[l % 3] ? 0 : 1;\n ary[i * 3 + 1] = str[l] === compare[(l + 1) % 3] ? 0 : 1;\n ary[i * 3 + 2] = str[l] === compare[(l + 2) % 3] ? 0 : 1;\n }\n return {\n l,\n r,\n ary\n };\n } else {\n const mid = (l + r) >> 1;\n const left = this.build(str, l, mid);\n const right = this.build(str, mid + 1, r);\n const ary = new Array(18);\n for (let i = 0; i < 18; i++) {\n ary[i] = left.ary[i] + right.ary[i];\n }\n return {\n l,\n r,\n ary,\n left,\n right\n }\n }\n }\n\n findEntry(l, r) {\n const result = new Array(18).fill(0);\n this.find(this.root, l, r, result);\n return result;\n }\n\n find(root, l, r, result) {\n if (root.l === l && root.r === r) {\n for (let i = 0; i < 18; i++) {\n result[i] += root.ary[i];\n }\n return;\n } else {\n root.left.r >= l && this.find(root.left, l, root.left.r, result);\n root.right.l <= r && this.find(root.right, root.right.l, r, result);\n }\n }\n}\n \t\t \t \t \t\t\t \t \t\t \t \t \t\t \t\t\t"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar g = main();\ng.next()\nrl.on('line', (input) => {\n g.next(input)\n // console.log('read', input)\n // input.split('\\n').forEach(s => s.trim() && g.next(s))\n});\n\nfunction* main() {\n let input\n\n input = yield 1\n var t = +input\n for (var i = 0; i < t; i++) {\n input = yield 1\n const [n, k] = input.split(' ').map(Number)\n if (i === 400) {\n process.exit(n)\n }\n yield* solve(n, k)\n }\n process.exit(0)\n}\n\nfunction* solve(n, k) {\n let guess = 0\n let sum = 0\n while (guess < n) {\n const next = xor(guess, sum, k)\n console.log(next)\n\n const ans = yield 1\n if (ans !== '0') break\n\n sum = xor(sum, next, k)\n guess++\n }\n}\n\nfunction xor(a, b, k) {\n return a ^ b\n if (a > b) return xor(b, a, k)\n\n a = toBits(a, k)\n b = toBits(b, k)\n const r = a.map((x, i) => (a[i] + b[i]) % k)\n for (let i = a.length; i < b.length; i++) {\n r.push(b[i])\n }\n\n return toVal(r, k)\n}\nfunction toBits(n, k) {\n const r = []\n while (n) {\n r.push(n % k)\n n = Math.floor(n / k)\n }\n return r\n}\nfunction toVal(arr, k) {\n let b = 1\n return arr.reduce((s, x) => {\n s = s + x * b\n b *= k\n return s\n }, 0)\n}"}], "src_uid": "b4183febe5ae61770368d2e16f273675"} {"source_code": "function main() {\n var testCasesNum = +readline();\n var testCases = [];\n for (var i = 0; i < testCasesNum * 2; i += 2) {\n (function (i) {\n testCases[i] = readline();\n testCases[i + 1] = readline();\n\n checkPoem(testCases[i], testCases[i + 1]);\n })(i)\n }\n}\n\nfunction checkPoem(ns, poem) {\n var nsArr = ns.split(' ').map(Number);\n var n = nsArr[0];\n var s = nsArr[1];\n var poemArr = poem.split(' ').map(Number);\n\n var poemSum = 0;\n var j = 0;\n var maxJ = 0;\n\n while (poemSum <= s && j < n) {\n poemSum += poemArr[j];\n if (j == n - 1 && poemSum <= s) {\n print(0);\n return;\n }\n if (poemArr[j] > poemArr[maxJ]) {\n maxJ = j;\n }\n j++;\n }\n print(maxJ + 1)\n}\n\nmain();", "positive_code": [{"source_code": "let input = \"\";\nconst { EOL } = require(\"os\");\nprocess.stdin.on(\"data\", i => (input += i));\n\nprocess.stdin.on(\"end\", func);\n\nasync function func() {\n const [t, ...queries] = input.split(EOL);\n for (let i = 0; i < t; i++) {\n let res = 0;\n const [n, s] = queries.shift().split(\" \").map(a => parseInt(a));\n const verses = queries.shift().split(\" \").map(a => parseInt(a));\n const totalTime = verses.reduce((acc, curr) => acc + curr);\n if (totalTime > s) {\n verses.reduce((acc, curr, index) => {\n if (res > 0)\n return;\n if (acc + curr > s) {\n const prevVerses = verses.slice(0, index + 1);\n res = verses.indexOf(Math.max(...prevVerses)) + 1;\n } else {\n return acc + curr;\n }\n })\n }\n console.log(res);\n }\n}\n\nmodule.exports = func;\n"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n let [n, s] = lines[i].split(' ').map(Number);\n let a = lines[i + 1].split(' ').map(Number);\n\n let sum = 0;\n let skipIndex = 0;\n let skipValue = a[0];\n let j = 1;\n while (sum <= s && j < a.length) {\n // console.log('--', sum, skipValue);\n if (sum + a[j] <= s || sum + skipValue <= s) {\n if (a[j] > skipValue) {\n skipIndex = j;\n sum += skipValue;\n skipValue = a[j];\n } else {\n sum += a[j];\n }\n }\n j++;\n }\n // console.log(s, a, sum, skipValue);\n if (sum + skipValue <= s) {\n console.log(0);\n } else {\n console.log(skipIndex + 1);\n }\n }\n});"}], "negative_code": [{"source_code": "let input = \"\";\nconst { EOL } = require(\"os\");\nprocess.stdin.on(\"data\", i => (input += i));\n\nprocess.stdin.on(\"end\", func);\n\nasync function func() {\n const [t, ...queries] = input.split(EOL);\n for (let i = 0; i < t; i++) {\n let res = 0;\n const [n, s] = queries.shift().split(\" \").map(a => parseInt(a));\n const verses = queries.shift().split(\" \").map(a => parseInt(a));\n const totalTime = verses.reduce((acc, curr) => acc + curr);\n if (totalTime > s) {\n verses.reduce((acc, curr, index) => {\n if (res > 0)\n return;\n if (acc + curr > s) {\n const prevVerses = verses.slice(0, index);\n res = verses.indexOf(Math.max(...prevVerses)) + 1;\n } else {\n return acc + curr;\n }\n })\n }\n console.log(res);\n }\n}\n\nmodule.exports = func;\n"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n let [n, s] = lines[i].split(' ').map(Number);\n let a = lines[i + 1].split(' ').map(Number);\n\n let sum = 0;\n let skipIndex = 0;\n let skipValue = a[0];\n let j = 1;\n while (sum <= s && j < a.length) {\n // console.log('--', sum, skipValue);\n if (sum + a[j] <= s) {\n if (a[j] > skipValue) {\n skipIndex = j;\n sum += skipValue;\n skipValue = a[j];\n } else {\n sum += a[j];\n }\n }\n j++;\n }\n // console.log(s, a, sum, skipValue);\n if (sum + skipValue <= s) {\n console.log(0);\n } else {\n console.log(skipIndex + 1);\n }\n }\n});"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n var testCases = [];\n for (var i = 0; i < testCasesNum * 2; i += 2) {\n (function (i) {\n testCases[i] = readline();\n testCases[i + 1] = readline();\n\n checkPoem(testCases[i], testCases[i + 1]);\n })(i)\n }\n}\n\nfunction checkPoem(ns, poem) {\n var nsArr = ns.split(' ').map(Number);\n var n = nsArr[0];\n var s = nsArr[1];\n var poemArr = poem.split(' ').map(Number);\n\n var poemSum = 0;\n var j = 0;\n var maxJ = 0;\n\n while (poemSum < s && j < n) {\n poemSum += poemArr[j];\n if (j == n - 1 && poemSum <= s) {\n print(0);\n return;\n }\n if (poemArr[j] > poemArr[maxJ]) {\n maxJ = j;\n }\n j++;\n }\n print(maxJ + 1)\n}\n\nmain();"}], "src_uid": "0924971933265f4be34710149a541087"} {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k) => {\r\n let m = n;\r\n while (m % 2 == 0) m >>= 1;\r\n if (m > 1) {\r\n pr(`${(n / m >> 0) * (m >> 1)} ${(n / m >> 0) * (m >> 1)} ${n / m >> 0}`)\r\n } else {\r\n pr(`${n >> 2} ${n >> 2} ${n >> 1}`)\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tif (n % 2 == 0) {\r\n\t\t\tif (n % 4 == 0){\r\n\t\t\t\tans = [n/2, n/4, n/4];\r\n\t\t\t} else {\r\n\t\t\t\tans = [n/2-1, n/2-1, 2]\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tans = [(n-1)/2, (n-1)/2, 1];\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tif(N % 4 == 0){\r\n\t\t\tvar s = N / 4;\r\n\t\t\tvar d = s * 2;\r\n\t\t\tmyout(d + \" \" + s + \" \" + s);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(N % K == 0){\r\n\t\t\tvar s = N / K;\r\n\t\t\tmyout(s + \" \" + s + \" \" + s);\r\n\t\t}else if(N % 2 == 1){\r\n\t\t\tN--;\r\n\t\t\tvar s = N / 2;\r\n\t\t\tmyout(\"1 \" + s + \" \" + s);\r\n\t\t}else{\r\n\t\t\tN -= 2;\r\n\t\t\tvar s = N / 2;\r\n\t\t\tmyout(\"2 \" + s + \" \" + s);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i {\r\n if (n & 1) {\r\n pr(`${n - 1 >> 1} ${n - 1 >> 1} ${1}`)\r\n } else if (n & 2) {\r\n pr(`${n - 2 >> 1} ${n - 2 >> 1} ${2}`)\r\n } else {\r\n pr(`${n >> 1} ${n >> 2} ${n >> 2}`)\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k) => {\r\n let res = [];\r\n for (let i = 0; i < k - 3; i++) {\r\n res.push(1);\r\n n--;\r\n }\r\n if (n % 2 == 1) {\r\n res.push(1);\r\n res.push(n >> 1);\r\n res.push(n >> 1);\r\n } else if (n % 4 == 2) {\r\n res.push(2);\r\n res.push(n - 2 >> 1);\r\n res.push(n - 2 >> 1);\r\n } else {\r\n res.push(n / 4 >> 0);\r\n res.push(n / 4 >> 0);\r\n res.push(n >> 1);\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let a = Math.floor(n / 2);\r\n if (a + a < n) {\r\n console.log(`${a} ${a} ${n - (a + a)}`);\r\n } else {\r\n if (a % 2) console.log(`${a - 1} ${a - 1} ${n - (a - 1 + (a - 1))}`);\r\n else console.log(`${a} ${a / 2} ${a / 2}`);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var ans = new Array(k).fill(1)\r\n var x\r\n if (n % 2 === 1) {\r\n x = (n - 1) / 2\r\n return console.log(1, x, x)\r\n }\r\n if (n % 4 === 0) {\r\n x = n / 4\r\n return console.log(x*2, x, x)\r\n }\r\n\r\n return console.log(2, (n-2)/2, (n-2)/2)\r\n\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n let res = [],\r\n one = 0;\r\n if (n & 1) {\r\n if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;\r\n m--;\r\n one++;\r\n n--;\r\n }\r\n for (let i = 30; i >= 0; i--) {\r\n if (res.length) {\r\n while (1 << i <= n) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n } else {\r\n if (1 << i <= n / 2) {\r\n let cur = 1 << i;\r\n while (n >= cur) {\r\n res.push(cur);\r\n n -= cur;\r\n }\r\n }\r\n }\r\n }\r\n if (res.length === m) {\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n } else if (res.length > m) {\r\n let sum = res.splice(2, res.length - m).reduce((a, b) => a + b, 0) / 2;\r\n res[0] += sum;\r\n res[1] += sum;\r\n if (one) res.push(1);\r\n return res.join(' ');\r\n }\r\n m -= res.length;\r\n while (m--) {\r\n let cur = res[res.length - 1];\r\n if (cur === 2) {\r\n res.pop();\r\n one += 2;\r\n } else {\r\n res[res.length - 1] /= 2;\r\n res.push(cur / 2);\r\n }\r\n }\r\n return (res.join(' ') + ' 1'.repeat(one)).trim();\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k) => {\r\n let res = [];\r\n for (let i = 0; i < k - 3; i++) {\r\n res.push(1);\r\n n--;\r\n }\r\n if (n % 2 == 1) {\r\n res.push(1);\r\n res.push(n >> 1);\r\n res.push(n >> 1);\r\n } else if (n % 4 == 2) {\r\n res.push(2);\r\n res.push(n - 2 >> 1);\r\n res.push(n - 2 >> 1);\r\n } else {\r\n res.push(n / 4 >> 0);\r\n res.push(n >> 1);\r\n res.push(n >> 1);\r\n }\r\n pr(res.join(\" \"))\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let a = 1,\r\n b = Math.floor(n / 2);\r\n let c = n - (a + b);\r\n console.log(`${a} ${b} ${c}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var a = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n\r\n var a = getDel(n)\r\n var b = (n - a[a.length - 1]) /2\r\n console.log(a[a.length - 1], b, b)\r\n });\r\n}\r\n\r\nfunction getDel(x) {\r\n\r\n var i = 1\r\n var ans = []\r\n while (i * i <= x) {\r\n if (x % i === 0) {\r\n ans.push(i)\r\n // ans.push(x / i)\r\n }\r\n i++\r\n }\r\n return ans\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n\r\n"}], "src_uid": "842a0587147591ea38a20638f3a7960d"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (var i=0; i BigInt(parseInt(x)));\n const result = (k*y + k - 1n + x - 2n) / (x-1n) + k;\n console.log(result.toString());\n }\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n\n while (t--) {\n const [x, y, k] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n let ans = \"\";\n let moves = 1n + k;\n let sticks = y * k + k - x;\n\n if (sticks < 0) sticks = 0n;\n\n moves += sticks / (x - 1n);\n if (sticks % (x - 1n) !== 0n) moves++;\n\n ans += moves;\n\n console.log(ans);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var t = +inputs[0];\n for (let i = 0; i < t; i++) {\n var [x, y, k] = inputs[i + 1].split(' ').map(v => BigInt(v));\n var n = (k * y + k - 1n + x - 2n) / (x - 1n);\n console.log(n + k + '');\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n\n while (t--) {\n const [x, y, k] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n let ans = \"\";\n let moves = 1n + k;\n let sticks = k * y + k - x;\n\n moves += sticks / (x - 1n);\n if (sticks % (x - 1n) !== 0n) moves++;\n\n ans += moves;\n\n console.log(ans);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n\n while (t--) {\n const [x, y, k] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let ans = \"\";\n let moves = 1n + BigInt(k);\n let sticks = BigInt(k) * BigInt(y) + BigInt(k) - BigInt(x);\n\n moves += sticks / BigInt(x - 1);\n if (sticks % BigInt(x - 1)) moves++;\n\n ans += moves;\n\n console.log(ans);\n }\n}\n"}], "src_uid": "28610d192329c78580db354f8dfc4094"} {"source_code": "const cal = (n, k, t) => {\n \n let p = (n * k * t) / 100;\n let q = Math.floor(p / k);\n let r = Math.floor(p % k);\n\n for (let i = 0; (i < q); i++) {\n process.stdout.write(k + ' ');\n //console.log(k + ' ');\n\n }\n if (q != n) {\n process.stdout.write(r + ' ');\n }\n \n //console.log(r + ' ')\n\n// if (n != 1) {\n for (let i = q + 1; i < n; i++) {\n process.stdout.write(0 + ' ');\n //console.log(0 + ' ');\n }\n//}\n}\n\n//cal(11, 13, 37);\nconst runner = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var arr = \"\";\n process.stdin.on('data', function (chunk) {\n arr += chunk;\n });\n process.stdin.on('end', function () {\n arr = arr.split(\" \");\n cal(arr[0], arr[1], arr[2])\n // console.log(arr)\n // var n = parseInt(arr.shift()); // in order ot get no of test cases\n\n });\n}\n\nrunner();\n", "positive_code": [{"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))\n t = t / 100\n let pi = n * t | 0\n let ip = n * t - pi\n let i = ip * k | 0\n let r = []\n for (let j = 0; j < pi; j++) r.push(k)\n if (pi != n) r.push(i)\n for (let j = pi + 1; j < n; j++) r.push(0)\n console.log(r.join(' '))\n})"}, {"source_code": "var input = readline().split(\" \");\n\nvar progress = input[2];\nvar left = input[1];\nvar outputArray = [];\nvar time = Math.floor((progress * left * input[0]) / 100);\n\nfor(var i=1;i<=input[0];i++) {\n\n if(time < 0) {\n outputArray.push(0);\n } else if(time < left) {\n outputArray.push(time);\n } else {\n outputArray.push(left);\n }\n \n time = time - left;\n\n \n}\n\nprint(outputArray.join(\" \"));\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))\n t = t / 100\n let pi = n * t | 0\n let ip = n * t - pi\n let i = ip * k | 0\n let r = []\n for (let j = 0; j < pi; j++) r.push(k)\n r.push(i)\n for (let j = pi + 1; j < n; j++) r.push(0)\n console.log(r.join(' '))\n})"}, {"source_code": "const cal = (n, k, t) => {\n \n let p = (n * k * t) / 100;\n let q = Math.floor(p / k);\n let r = Math.floor(p % k);\n\n for (i = 0; i < q; i++) {\n process.stdout.write(k + ' ');\n //console.log(k + ' ');\n\n }\n \n process.stdout.write(r + ' ');\n\n \n //console.log(r + ' ')\n\nif (n != 1) {\n for (i = q + 1; i < n; i++) {\n process.stdout.write(0 + ' ');\n //console.log(0 + ' ');\n }\n}\n}\n\n//cal(11, 13, 37);\nconst runner = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var arr = \"\";\n process.stdin.on('data', function (chunk) {\n arr += chunk;\n });\n process.stdin.on('end', function () {\n arr = arr.split(\" \");\n cal(arr[0], arr[1], arr[2])\n // console.log(arr)\n // var n = parseInt(arr.shift()); // in order ot get no of test cases\n\n });\n}\n\nrunner();\n"}, {"source_code": "const cal = (n, k, t) => {\n \n let p = (n * k * t) / 100;\n let q = Math.floor(p / k);\n let r = Math.floor(p % k);\n\n for (i = 0; i < q; i++) {\n process.stdout.write(k + ' ');\n //console.log(k + ' ');\n\n }\n if (n !== 1) {\n process.stdout.write(r + ' ');\n\n }\n //console.log(r + ' ')\n\n\n for (i = q + 1; i < n; i++) {\n process.stdout.write(0 + ' ');\n //console.log(0 + ' ');\n }\n}\n\n//cal(11, 13, 37);\nconst runner = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var arr = \"\";\n process.stdin.on('data', function (chunk) {\n arr += chunk;\n });\n process.stdin.on('end', function () {\n arr = arr.split(\" \");\n cal(arr[0], arr[1], arr[2])\n // console.log(arr)\n // var n = parseInt(arr.shift()); // in order ot get no of test cases\n\n });\n}\n\nrunner();\n"}, {"source_code": "const cal = (n, k, t) => {\n let p = (n * k * t) / 100;\n let q = Math.floor(p / k);\n let r = Math.floor(p % k);\n\n for (i = 0; i < q; i++) {\n process.stdout.write(k + ' ');\n //console.log(k + ' ');\n\n }\n process.stdout.write(r + ' ');\n //console.log(r + ' ')\n\n\n for (i = q + 1; i < n; i++) {\n process.stdout.write(0 + ' ');\n //console.log(0 + ' ');\n }\n}\n\n//cal(11, 13, 37);\nconst runner = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var arr = \"\";\n process.stdin.on('data', function (chunk) {\n arr += chunk;\n });\n process.stdin.on('end', function () {\n arr = arr.split(\" \");\n cal(arr[0], arr[1], arr[2])\n // console.log(arr)\n // var n = parseInt(arr.shift()); // in order ot get no of test cases\n\n });\n}\n\nrunner();\n"}, {"source_code": "const cal = (n, k, t) => {\n \n let p = (n * k * t) / 100;\n let q = Math.floor(p / k);\n let r = Math.floor(p % k);\n\n for (let i = 0; (i < q); i++) {\n process.stdout.write(k + ' ');\n //console.log(k + ' ');\n\n }\n \n if (q <= (n-q)){\n process.stdout.write(r + ' ');\n }\n \n //console.log(r + ' ')\n\nif (n != 1) {\n for (let i = q + 1; i < n; i++) {\n process.stdout.write(0 + ' ');\n //console.log(0 + ' ');\n }\n}\n}\n\n//cal(11, 13, 37);\nconst runner = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n var arr = \"\";\n process.stdin.on('data', function (chunk) {\n arr += chunk;\n });\n process.stdin.on('end', function () {\n arr = arr.split(\" \");\n cal(arr[0], arr[1], arr[2])\n // console.log(arr)\n // var n = parseInt(arr.shift()); // in order ot get no of test cases\n\n });\n}\n\nrunner();\n"}], "src_uid": "0ad96b6a8032d70df400bf2ad72174bf"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n \r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\"\").map(x=>parseInt(x))\r\n \r\n let diverseCountTot=0\r\n for (let i = 0; i < n; ++i) {\r\n let countmap = Array(10).fill(0);\r\n let diverse_count=0\r\n let max=0\r\n //console.log(\"countmap \" + countmap)\r\n for (let j = i; j < n; ++j) {\r\n let val = arr[j]\r\n \r\n if(countmap[val]>=10)\r\n break;\r\n \r\n if(!countmap[val])\r\n diverse_count++\r\n \r\n //console.log(\"val \" + val)\r\n countmap[val]++\r\n\r\n max = Math.max(countmap[val],max)\r\n //console.log(\"max \" + max)\r\n\r\n if(max <= diverse_count)\r\n diverseCountTot++\r\n }\r\n }\r\n console.log(diverseCountTot)\r\n } \r\n}", "positive_code": [{"source_code": "\r\nfunction solve() {\r\n var n = Number(read());\r\n var count = [];\r\n for (var d = 0; d < 10; d++) {\r\n count[d] = [0];\r\n }\r\n var s = read().split('').map(Number);\r\n for (var i = 0; i < n; i++) {\r\n for (d = 0; d < 10; d++) {\r\n if (s[i] !== d) {\r\n count[d][i + 1] = count[d][i];\r\n continue;\r\n }\r\n count[d][i + 1] = count[d][i] + 1;\r\n }\r\n }\r\n\r\n var ans = 0;\r\n for (i = 0; i < n; i++) {\r\n for (var len = 1; len < 101; len++) {\r\n var end = i + len;\r\n if (end > n) {\r\n break;\r\n }\r\n var maxCount = 0;\r\n var different = 0;\r\n for (d = 0; d < 10; d++) {\r\n var currentCount = count[d][end] - count[d][i];\r\n if (currentCount !== 0) {\r\n different++;\r\n if (currentCount > maxCount) {\r\n maxCount = currentCount;\r\n if (maxCount > 10) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if (different >= maxCount) {\r\n ans++;\r\n }\r\n }\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n \r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\"\").map(x=>parseInt(x))\r\n \r\n let diverseCountTot=0\r\n for (let i = 0; i < n; ++i) {\r\n \r\n //let countmap = Array(10).fill(0);\r\n let countmap = {}\r\n let diverse_count=0\r\n let max=0\r\n \r\n for (let j = i; j < n; ++j) {\r\n let val = arr[j]\r\n \r\n //console.log(\"countmap[val] \" + countmap[val])\r\n if(countmap[val]>=10)\r\n {\r\n //console.log(\"countmap[val] \" + countmap[val])\r\n break;\r\n }\r\n \r\n if(countmap[val]==undefined)\r\n {\r\n diverse_count++\r\n \r\n countmap[val]=0\r\n }\r\n \r\n \r\n countmap[val]++\r\n //console.log(\"countmap[val] \" + countmap[val])\r\n\r\n max = Math.max(countmap[val],max)\r\n //console.log(\"max \" + max)\r\n\r\n if(max <= diverse_count)\r\n diverseCountTot++\r\n }\r\n }\r\n console.log(diverseCountTot)\r\n } \r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction solve(s) {\n let solution = 0;\n\n for (let i = 0; i < s.length; i++) {\n const counters = {\n 0: 0,\n 1: 0,\n 2: 0,\n 3: 0,\n 4: 0,\n 5: 0,\n 6: 0,\n 7: 0,\n 8: 0,\n 9: 0\n };\n\n let maxFreq = 0;\n let uniq = 0;\n\n for (let j = i; j < s.length; j++) {\n counters[s[j]] += 1;\n const currentFreq = counters[s[j]];\n\n if (currentFreq > 10) {\n break;\n }\n\n if (maxFreq < currentFreq) {\n maxFreq = currentFreq;\n }\n\n if (currentFreq === 1) {\n uniq += 1;\n }\n\n if (maxFreq <= uniq) {\n solution++;\n }\n }\n }\n\n return solution;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const data = input.trim().split('\\n');\n\n for (let i = 1; i < data.length; i += 2) {\n const s = data[i + 1].trim();\n const solution = solve(s);\n console.log(solution);\n }\n});\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nfunction getMaxFreqAndUniq(c) {\r\n let uniq = 0;\r\n let maxFreq = -Infinity;\r\n for (let i = 0; i < 10; i++) {\r\n if (c[i] > 0) {\r\n uniq++;\r\n }\r\n\r\n if (c[i] > maxFreq) {\r\n maxFreq = c[i];\r\n }\r\n }\r\n\r\n return {uniq, maxFreq};\r\n}\r\n\r\nfunction count(s) {\r\n const result = {\r\n 0: 0,\r\n 1: 0,\r\n 2: 0,\r\n 3: 0,\r\n 4: 0,\r\n 5: 0,\r\n 6: 0,\r\n 7: 0,\r\n 8: 0,\r\n 9: 0,\r\n };\r\n\r\n for (let i = 0; i < s.length; i++) {\r\n result[s[i]] += 1;\r\n }\r\n\r\n return result;\r\n}\r\n\r\nfunction solve(s, c, i = 0, j = s.length - 1, alreadySolved = {}) {\r\n const key = `${i}-${j}`;\r\n if (alreadySolved[key] === true) {\r\n return 0;\r\n }\r\n\r\n alreadySolved[key] = true;\r\n\r\n if (i === j) {\r\n return 1;\r\n }\r\n\r\n let result = 0;\r\n\r\n const {uniq, maxFreq} = getMaxFreqAndUniq(c);\r\n if (uniq >= maxFreq) {\r\n result += 1;\r\n }\r\n\r\n const leftC = {...c};\r\n leftC[s[i]] -= 1\r\n result += solve(s, leftC, i + 1, j, alreadySolved);\r\n\r\n const rightC = {...c};\r\n rightC[s[j]] -= 1;\r\n result += solve(s, rightC, i, j - 1, alreadySolved);\r\n\r\n return result;\r\n}\r\n\r\nvar input = '';\r\nprocess.stdin.on('data', function(chunk) {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', function() {\r\n const data = input.trim().split('\\n');\r\n\r\n for (let i = 1; i < data.length; i += 2) {\r\n const solution = solve(data[i+1], count(data[i + 1]));\r\n console.log(solution);\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nfunction getMaxFreqAndUniq(c) {\n let uniq = 0;\n let maxFreq = -Infinity;\n for (let i = 0; i < 10; i++) {\n if (c[i] > 0) {\n uniq++;\n }\n\n if (c[i] > maxFreq) {\n maxFreq = c[i];\n }\n }\n\n return {uniq, maxFreq};\n}\n\nfunction count(s) {\n const result = {\n 0: 0,\n 1: 0,\n 2: 0,\n 3: 0,\n 4: 0,\n 5: 0,\n 6: 0,\n 7: 0,\n 8: 0,\n 9: 0,\n };\n\n for (let i = 0; i < s.length; i++) {\n result[s[i]] += 1;\n }\n\n return result;\n}\n\nfunction solve(s, c, i = 0, j = s.length - 1, alreadySolved = {}) {\n const key = `${i}-${j}`;\n if (alreadySolved[key] === true) {\n return 0;\n }\n\n alreadySolved[key] = true;\n\n if (i === j) {\n return 1;\n }\n\n let result = 0;\n\n const {uniq, maxFreq} = getMaxFreqAndUniq(c);\n if (uniq >= maxFreq) {\n result += 1;\n }\n\n const leftC = {...c};\n leftC[s[i]] -= 1\n result += solve(s, leftC, i + 1, j, alreadySolved);\n\n const rightC = {...c};\n rightC[s[j]] -= 1;\n result += solve(s, rightC, i, j - 1, alreadySolved);\n\n return result;\n}\n\nvar input = '';\nprocess.stdin.on('data', function(chunk) {\n input += chunk;\n});\n\nprocess.stdin.on('end', function() {\n const data = input.trim().split('\\n');\n\n for (let i = 1; i < data.length; i += 2) {\n const solution = solve(data[i+1], count(data[i + 1]));\n console.log(solution);\n }\n});\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n \r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine());\r\n \r\n let arr = readLine().trim().split(\"\").map(x=>parseInt(x))\r\n \r\n let diverseCountTot=0\r\n for (let i = 0; i < n; i++) {\r\n let countmap = Array(10).fill(0);\r\n let diverse_count=0\r\n let max=0\r\n //console.log(\"countmap \" + countmap[0])\r\n for (let j = i; j < n; j++) {\r\n let val = arr[j]\r\n if(diverse_count>=10)\r\n break;\r\n \r\n if(!countmap[val])\r\n diverse_count++\r\n \r\n //console.log(\"val \" + val)\r\n countmap[val]++\r\n\r\n max = Math.max(countmap[val],max)\r\n //console.log(\"max \" + max)\r\n\r\n if(max <= diverse_count)\r\n diverseCountTot++\r\n }\r\n }\r\n console.log(diverseCountTot)\r\n } \r\n}"}], "src_uid": "e7f84300e9480a94a2399fcd5f47ecec"} {"source_code": "function solve() {\n var n = readline()\n var s = readline().split(' ');\n \n var sz = 0;\n while (s[sz] === s[0]) sz++;\n\n if (s.length % sz) \n return false;\n \n \n for(var i=0;i +v.trim())[0];\nvar a = readline().split(\" \").map(v => +v.trim());\n\nvar len=1, i=1;\nwhile(i < n && a[i]==a[0]) {\n\ti++;\n\tlen++;\n}\n\nvar ok = 1, val = a[0];\n\nfor(var j=0; j parseInt(v));\n\nfunction compute() {\n var good = true;\n for (i = 0; i < n; i++) {\n if (arr[i] != arr[0]) {\n good = false;\n }\n }\n if (good == true) {\n return \"YES\";\n }\n var period = 0;\n for (i = 0; i < n; i++) {\n if (arr[i] != arr[0]) {\n period = i;\n break;\n }\n }\n if (n % period != 0) {\n return \"NO\"; \n }\n for (i = period; i < n; i = i + period) {\n if (arr[i] == arr[i - 1]) {\n return \"NO\";\n }\n for (j = 1; j < period; j++) {\n if (arr[i + j] != arr[i + j - 1]) {\n return \"NO\";\n }\n }\n }\n return \"YES\";\n}\n\nprint(compute());"}, {"source_code": "var n = parseInt(readline());\n\nvar st = readline();\n\nvar check = Number(st[0]), p, inc = 1, s = 0;\n\nfor(i = 1; i < n; ++i){\n p = Number(st[i * 2]);\n if(check == p){\n ++inc;\n }else{\n if(s){\n if(inc != s){\n break;\n }\n }else{\n s = inc;\n }\n inc = 1;\n check = p;\n }\n}\n\nif(s)\n if(inc == s)\n print(\"YES\");\n else\n print(\"NO\");\nelse\n print(\"YES\");\n \n "}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar n = readline();\nvar i = readline().split(' ');\nvar prev = 0;\nvar cnt = 0;\nfor(var j = 0; j < n; j++)\n{\n if(j!=0)\n {\n if(i[j] != i[j-1])\n { if(prev!=0 && cnt != prev)\n {\n print(\"NO\");\n break;\n }\n prev = cnt;\n cnt = 0;\n }\n }\n cnt++\n if(prev!=0&&cnt>prev)\n {\n print(\"NO\");\n break;\n }\n if(j==n-1 && (cnt == prev || prev == 0))\n print(\"YES\");\n if(j == n-1 && prev!=0 && cnt != prev)\n print(\"NO\");\n}"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(v => +v.trim());;\n\nvar t = 0;\nfor (var i = 0; i < n; i++)\n if (a[i] == a[0])\n ++t;\n else\n break;\n\nvar ok = true; \nfor (var i = t, cur = 1 - a[0]; i < n && ok; i += t, cur = 1 - cur)\n for (var j = i; j < i + t; j++)\n if (a[j] != cur) {\n print(\"NO\");\n ok = false;\n break; \n }\n\nif (ok)\n print(\"YES\");\n "}, {"source_code": "n = readline().split(' ').map(Number)[0];\narr = readline().split(' ').map(Number);\n\n\nvar zero = arr[0];\nvar zeros = 0;\n\nfor (i = 0; i < n; i++) {\n if (arr[i] == zero) {\n zeros++;\n } else {\n break;\n }\n}\n\nvar i = 0;\n\nvar yas = true;\n\nyas &= (n % zeros === 0);\n\nfor (i = 0; i < n; i += zeros) {\n for (var j = 0; j < zeros; j++) {\n yas &= (arr[i + j] == zero);\n }\n zero = 1 - zero;\n}\nif (yas) {\n print(\"YES\");\n} else {\n print(\"NO\");\n}"}, {"source_code": "var n = parseInt(readline());\n\nvar gList = readline();\n\nvar f=-1;\nvar l=0;\nvar ans=true;\n\nvar prev=-1;var now = 1;\n\nfor(var i = 0; i < gList.length; i+=2){\n \n if (gList[i] === '1'){\n now = 1;\n } else {\n now = 0;\n } \n //print(prev+' '+now);\n \n \n if (i!=0) {\n \n \n if (prev!=now) {\n \n if (f==-1) {\n f=l;\n \n l=1;\n } else {\n //print(l);\n //print(f);\n if (l!=f) {ans=false}\n l=1;\n } \n \n }else {l++};\n \n }else {l++};\n //print(f+' '+l);\n prev=now;\n}\n\nif (f!=-1) {\n if (l!=f) {ans=false}}\n \n \nif (ans) {\n print('YES')\n} else{\n print('NO')\n}"}, {"source_code": "var n = readline();\nvar a = readline();\na = a.split(' ');\n\nfor( var i = 0; i < n; i += 1 )a[i] = parseInt( a[i] );\n\nvar cnt = 0, lnt = 0, t = true;\n\nf = a[0];\n\nwhile( a[cnt++] === f );\n\nf = 1 - f;\n\ncnt--;\n\nfor( var i = cnt; i < n; i ++ ){\n if( a[i] === f )lnt++;\n else{\n if( lnt != cnt ){\n write( \"NO\" );\n t = false;\n break;\n }\n f = 1 - f;\n lnt = 1;\n }\n //write( i + ' ' + a[i] + ' ' + cnt + ' ' + lnt + '\\n' );\n}\n\nif( t && cnt != n && lnt != cnt ){\n write( \"NO\" );\n t = false;\n}\n\nif( t === true )\nwrite( \"YES\" );"}, {"source_code": "\nvar count = 0;\nvar last = '9';\nvar w = -1;\nvar pos = 1;\n\nvar N = parseInt(readline());\nvar a = readline().split(' ');\n\nfor(var i = 0; i < N; i++) {\n\tif(last === '9') {\n\t\n\t} else if(last === a[i]) {\n\t\tcount++;\n\t} else {\n\t\tif(w < 0) {\n\t\t\tw = count;\n\t\t} else if(w !== count) {\n\t\t\tpos = 0;\n\t\t}\n\t\tcount = 0;\n\t}\n\tlast = a[i];\n}\n\nif(w !== count && w >= 0) {\n\tpos = 0;\n}\n\nif(pos == 0) {\n\tprint(\"NO\");\n} else {\n\tprint(\"YES\");\n}\n"}, {"source_code": "isOk = function(a, n, k){\n var black = a[0];\n for(var i = 1; i < n; i++)\n if((Math.floor(i / k) % 2 === 0 && a[i] !== black) || (Math.floor(i / k) % 2 === 1 && a[i] === black)){\n return false;\n }\n return true;\n};\n\n\n\nn = parseInt(readline());\na = readline().split(' ');\nres = false;\nfor(var i = 1; i * i <= n; i++)\nif(n % i === 0){\n if(isOk(a, n, i) || isOk(a, n, Math.floor(n/i)))\n res = true;\n}\nif(res)\n print(\"YES\");\nelse\n print(\"NO\");"}, {"source_code": "var n = readline();\nvar numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar white = 0, blk = 0;\nvar fw = 0, fb = 0;\nvar fixW=0, fixB=0;\nvar flg = 1;\nfor(var i=0; i q) {\n ANS = \"NO\";\n break;\n }\n }\n else {\n if (p !== q) {\n ANS = \"NO\";\n break;\n }\n p = 1;\n cur = arr[i];\n }\n}\nif (p !== q) {\n ANS = \"NO\";\n}\n\nprint(ANS);"}, {"source_code": "\nvar n=readline();\nvar w = readline().split(' ').map(function(x) { return parseInt(x);});\nvar cnt=0,y=-1;\nvar last=-1,ans=1;\nfor(var i=0;i +v.trim())[0];\nvar a = readline().split(\" \").map(v => +v.trim());\n\nvar len=1, i=1;\nwhile(i < n && a[i]==a[0]) {\n\ti++;\n\tlen++;\n}\n\nvar ok = 1;\nfor(var j=0; j 0) {\n\tpos = 0;\n}\n\nif(pos == 0) {\n\tprint(\"NO\");\n} else {\n\tprint(\"YES\");\n}\n"}, {"source_code": "var n = parseInt(readline());\n\nvar st = readline();\n\nvar check = Number(st[0]), p, inc = 1, s = 0;\n\nvar i\n\nfor(i = 1; i < n; ++i){\n p = Number(st[i * 2]);\n if(check == p){\n ++inc;\n }else{\n if(s){\n if(inc != s){\n break;\n }\n }else{\n s = inc;\n }\n inc = 1;\n check = p;\n }\n}\n\n\nif(inc == s)\n print(\"YES\");\nelse\n print(\"NO\");\n "}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar n = readline();\nvar arr = readline().split(\" \");\nvar l1 = 0;\nvar l2 = 0;\nvar x = 0;\nvar result = \"YES\";\nfor(var i = 0; i < n; i++){\n if(x == 0){\n if(arr[i] == '1'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 1;\n l2 = 0;\n }\n } else {\n l1++;\n }\n } else {\n if(arr[i] == '0'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 0;\n l1 = 0;\n }\n } else {\n l2++;\n }\n }\n}\nif(l1 != l2 && l1*l2 != 0)\n result = \"NO\";\nprint(result);\n \n print(l1);\n print(l2);"}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar n = readline();\nvar arr = readline().split(\" \");\nvar l1 = 0;\nvar l2 = 0;\nvar x = 0;\nvar result = \"YES\";\nfor(var i = 0; i < n; i++){\n if(x == 0){\n if(arr[i] == '1'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 1;\n l2 = 0;\n }\n } else {\n l1++;\n }\n } else {\n if(arr[i] == '0'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 0;\n l1 = 0;\n }\n } else {\n l2++;\n }\n }\n print(l1);\n print(l2);\n}\nif(l1 != l2 && l1*l2 != 0)\n result = \"NO\";\nprint(result);\n "}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar n = readline();\nvar arr = readline().split(\" \");\nvar l1 = 0;\nvar l2 = 0;\nvar x = 0;\nvar result = \"YES\";\nfor(var i = 0; i < n; i++){\n if(x == 0){\n if(arr[i] == '1'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 1;\n l2 = 0;\n }\n } else {\n l1++;\n }\n } else {\n if(arr[i] == '0'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NO\";\n } else {\n x = 0;\n l1 = 0;\n }\n } else {\n l2++;\n }\n }\n}\nif(l1 != l2 && l1*l2 != 0)\n result = \"NO\";\nprint(result);\n "}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar n = readline();\nvar arr = readline().split(\" \");\nvar l1 = 0;\nvar l2 = 0;\nvar x = 0;\nvar result = \"YES\";\nfor(var i = 0; i < n; i++){\n if(x == 0){\n if(arr[i] == '1'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NOp\";\n } else {\n x = 1;\n l2 = 0;\n }\n } else {\n l1++;\n }\n } else {\n if(arr[i] == '0'){\n if(l1 != l2 && l1 != 0 && l2 != 0){\n result = \"NOd\";\n } else {\n x = 0;\n l1 = 0;\n }\n } else {\n l2++;\n }\n }\n}\nif(l1 != l2 && l1*l2 != 0)\n result = \"NOg\";\nprint(result);\n "}], "src_uid": "75a00d8a614fd0bcb8504b0268a121e0"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let n = $(), a = $(n)\n\n let suf = arr => {\n // log(arr)\n out.push([arr.length, ...arr].join(' '))\n let s = 0;\n let na = []\n arr.forEach(v => {\n na.push(a.slice(s, s += v))\n })\n a = na.reverse().flat()\n // log(a)\n // log('---')\n }\n\n let join = x => {\n let vx1 = a.findIndex(v => v == x - 1)\n let v1 = a.findIndex(v => v == 1)\n let vx = a.findIndex(v => v == x)\n if (v1 == vx1) {\n if (vx > v1) {\n suf([v1, 1, vx - v1, n - 1 - vx].filter(v => v))\n } else {\n suf([vx, 1, v1 - vx, n - 1 - v1].filter(v => v))\n }\n } else {\n if (v1 > vx1 && v1 > vx) {\n suf([vx, vx1 - vx, ...Arr(x - 1, i => 1), n - 1 - v1].filter(v => v))\n } else if (v1 > vx1 && v1 < vx) {\n suf([vx1, x - 1, vx - v1, n - 1 - vx].filter(v => v))\n } else if (v1 < vx1 && v1 > vx) {\n suf([vx, v1 - vx, x - 1, n - 1 - vx1].filter(v => v))\n } else {\n suf([v1, ...Arr(x - 1, i => 1), vx - vx1, n - 1 - vx].filter(v => v))\n }\n }\n }\n For(2, n, i => {\n join(i)\n })\n if (n > 1 && a[0] != 1) suf(Arr(n, i => 1))\n log(out.length)\n log(out.join('\\n'))\n}\n", "positive_code": [{"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction constantNumberofLinesStdin(lines) {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n const output = [];\n stdin.on('line', line => {\n output.push(line);\n\n if (output.length === lines) {\n resolve(output);\n stdin.close();\n }\n });\n });\n}\n\nfunction solve(cards) {\n const output = [];\n const n = cards.length;\n const lastIndex = n - 1;\n\n function isSolved() {\n return n === 1 || cards.slice(1).every((c, i) => c > cards[i]);\n }\n\n function performAction(groupSizes) {\n output.push(groupSizes.length + ' ' + groupSizes.join(' '));\n const swapped = [];\n let index = 0;\n\n for (const size of groupSizes) {\n swapped.splice(0, 0, ...cards.slice(index, index + size));\n index += size;\n }\n\n cards = swapped;\n }\n\n while (!isSolved()) {\n let currentOrder;\n\n if (cards[0] === 1 || cards[lastIndex] === n) {\n currentOrder = 'asc';\n } else if (cards[lastIndex] === 1 || cards[0] === n) {\n currentOrder = 'desc';\n } else {\n currentOrder = n & 1 ? 'asc' : 'desc';\n }\n\n let leadingDone = 0,\n trailingDone = 0;\n\n if (currentOrder === 'asc') {\n while (cards[leadingDone] === leadingDone + 1) {\n leadingDone++;\n }\n\n while (cards[lastIndex - trailingDone] === n - trailingDone) {\n trailingDone++;\n }\n } else {\n while (cards[leadingDone] === n - leadingDone) {\n leadingDone++;\n }\n\n while (cards[lastIndex - trailingDone] === trailingDone + 1) {\n trailingDone++;\n }\n }\n\n if (leadingDone === n) {\n trailingDone = 0;\n }\n\n const lastLeadingDone = cards[leadingDone - 1] || (currentOrder === 'asc' ? 0 : n + 1);\n const targetCard = currentOrder === 'asc' ? lastLeadingDone + 1 : lastLeadingDone - 1;\n const targetIndex = cards.indexOf(targetCard);\n const action = [];\n\n for (let x = 0; x < leadingDone; x++) {\n action.push(1);\n }\n\n if (targetIndex >= 0) {\n const left = targetIndex - leadingDone + 1;\n const right = n - leadingDone - left - trailingDone;\n action.push(left);\n\n if (right) {\n action.push(right);\n }\n }\n\n for (let x = 0; x < trailingDone; x++) {\n action.push(1);\n }\n\n performAction(action);\n }\n\n console.log(output.length);\n output.forEach(line => console.log(line)); // [3] [1 2 4] Moves: 4\n // [1] [2] [4 3] Moves: 3\n // 4 3 2 1 Moves: 2\n // 1 2 3 4\n // [6 8 4 9 1] [2 3 7 5]\n // [2 3 7 5 6 8 4 9] [1]\n // [1] [2] [3] [7 5 6 8 4] [9]\n // [9] [7] [5 6 8] [4] [3] [2] [1]\n // [1] [2] [3] [4] [5] [6] [8 7] [9]\n // [9] [8] [7] [6] [5] [4] [3] [2] [1]\n // 1 2 3 4 5 6 7 8 9\n}\n\nasync function main() {\n const input = await constantNumberofLinesStdin(2);\n solve(input[1].split(' ').map(Number));\n}\n\nmain().then();\n"}], "negative_code": [], "src_uid": "07bc926194f45da75e4c534a7fd3656b"} {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.question(\"\", loop =>{\n getUserInput(loop);\n})\n\nfunction getUserInput(n) {\n rl.question('', (number) => {\n rl.question(\"\", number => {\n let fi = number.indexOf(\"1\");\n let li = number.lastIndexOf(\"1\");\n //console.log(fi, li);\n number = number.substring(fi,li+1);\n //console.log(number);\n let arr = number.split(\" \")\n //console.log(arr);\n console.log(countZeros(arr));\n if (n > 1) {\n getUserInput(n-1);\n } else {\n rl.close();\n }\n }) \n }); \n}\n\nfunction countZeros(arr){\n let count = 0;\n for (let index = 0; index < arr.length; index++) {\n if(arr[index] == 0)\n ++count;\n }\n return count;\n}\n\nrl.on(\"close\", function() {\n process.exit(0);\n});\n", "positive_code": [{"source_code": "var problem = function(arr) {\n\n var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);\n for (var i = 0; i < arr.length; i++) {\n if (a[i] == 1) count++;\n }\n return (a.length - count);\n\n}\n\nvar tests = readline();\n\nfor (var i = 0; i < tests; i++) {\n\n var n, items;\n n = readline();\n items = readline().split(\" \");\n print(problem(items));\n\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nlet mem = new Map();\nfunction query(arr){\n let RES = 0;\n let last_i = arr.lastIndexOf(1);\n let had;\n for (let i=0; i+a);\n print(query(arr));\n }\n}\n"}, {"source_code": "const solve = (shelf) => {\n let start = shelf.indexOf(1);\n let end = shelf.lastIndexOf(1);\n if (start == end) return 0;\n let cnt = 0;\n for (let i = start; i <= end; i++) {\n if (shelf[i] == 0) {\n cnt++;\n }\n }\n return cnt;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 2;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0]));\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = [];\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line * 2;\n return;\n }\n\n data.push(line);\n \n if(lineNum - 1 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(data) { \n data.forEach((shelf, i) => {\n if(i % 2 !== 0) {\n let spaceZeroes = 0;\n let tempZeroes = 0;\n let booksDetected = false;\n for(let i = 0; i < shelf.length; i+=2) {\n if(shelf[i] == 1) {\n if(booksDetected) {\n spaceZeroes += tempZeroes;\n } else {\n booksDetected = true;\n }\n tempZeroes = 0;\n } else {\n tempZeroes++;\n }\n }\n\n console.log(spaceZeroes);\n }\n })\n}\n\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet isT = true;\nlet inputLength;\nlet inputShelf;\nlet inputCounter = 0;\n\nreadLine.on(\"line\", line => {\n if (isT) {\n isT = false;\n } else {\n if (inputCounter == 1) {\n inputShelf = line;\n countMoves(inputLength ,inputShelf);\n inputCounter = 0;\n } else {\n inputLength = line;\n inputCounter++;\n }\n }\n});\n\nfunction countMoves(length, shelf) {\n length = parseInt(length);\n let shelfArr= [];\n for (let i = 0; i < shelf.length; i += 2) {\n shelfArr.push(shelf[i]);\n }\n let movesSum = 0;\n let outerFlag = false;\n let met = 0;\n let numberOfBooks = 0;\n for (let i = 0; i < shelfArr.length; i++) {\n if(shelfArr[i] == 1) {\n numberOfBooks++;\n }\n }\n for (let i = 0; i < shelfArr.length; i++) {\n if (shelfArr[i] == 1) {\n met++;\n if(met == numberOfBooks) {\n break;\n }\n outerFlag = true;\n } else if (shelfArr[i] == 0 && outerFlag === true) {\n movesSum++;\n }\n }\n if (met < 2) {\n movesSum = 0;\n }\n console.log(movesSum);\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let [first1, last1] = [arr.indexOf(1), arr.lastIndexOf(1)];\n\n if (first1 === last1) console.log(0);\n else {\n let count = 0;\n for (let i = first1; i <= last1; i++) {\n if (arr[i] === 0) count++;\n }\n console.log(count);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar L = -1;\n\t\tvar R = -1;\n\t\tvar zero = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(list[j] == 1){\n\t\t\t\tL = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(var j = N - 1; j >= 0; j--){\n\t\t\tif(list[j] == 1){\n\t\t\t\tR = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(var j = L; j <= R; j++){\n\t\t\tif(list[j] == 0){\n\t\t\t\tzero++;\n\t\t\t}\n\t\t}\n\t\toutput[i] = zero;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n // let a = data[i].trim();\n // const n = data[i] * 1;\n // const k = a[1];\n const s = data[i + 1].trim().split(' ').map(Number);\n // s.sort((a, b) => b - a);\n let first = s.indexOf(1);\n let arr = [];\n let min = 0;\n \n for (let j = first + 1; j < s.length; j += 1) {\n if (s[j] === 1) arr.push(j);\n }\n \n while (arr.length) {\n let diff = arr.shift();\n if (diff - first === 1) {first = diff; continue;}\n diff = diff - first - 1;\n min += diff;\n arr = arr.map(a => a - diff);\n first += 1;\n }\n \n console.log(min);\n i += 2;\n }\n}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(a)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),void(o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()&&console.log(\"\u2705 AC!\"));process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}, {"source_code": "//cat q2.text | node q2.js\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const x = readline();\n for (let i = 0; i < x; i++) {\n let y = readline();\n let z = readline().split(\" \");\n console.log(Bookshelf(y,z))\n }\n}\n\n\nfunction Bookshelf(len, data) {\n\n let ans = 0;\n\n let firstIndex = data.indexOf(\"1\");\n let lastIndex = data.lastIndexOf(\"1\");\n\n for (let i = firstIndex; i < lastIndex; i++) {\n if (data[i] == 0) {\n ans++\n }\n }\n\n return ans;\n\n}"}, {"source_code": "var t = parseInt(readline());\n\nwhile (t--) {\n var n = parseInt(readline());\n var f = 0;\n var ar = readline().split(' ').map(function(x) { return parseInt(x); });\n ar.forEach(function(x) { if (x == 1) f = 1 });\n if (!f) {\n print(\"0\");\n continue;\n }\n var first = -1, last = -1;\n for (var i = 0; i < ar.length; ++i) if (ar[i] == 1) {\n first = i;\n break;\n }\n for (var i = ar.length-1; i >= 0; --i) if (ar[i] == 1) {\n last = i;\n break;\n }\n var cnt = 0;\n for (var i = first; i <= last; ++i) {\n cnt += ar[i] == 0;\n }\n print(cnt);\n}\n"}], "negative_code": [{"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet isT = true;\nlet inputLength;\nlet inputShelf;\nlet inputCounter = 0;\n\nreadLine.on(\"line\", line => {\n if (isT) {\n isT = false;\n } else {\n if (inputCounter == 1) {\n inputShelf = line;\n countMoves(inputLength ,inputShelf);\n inputCounter = 0;\n } else {\n inputLength = line;\n inputCounter++;\n }\n }\n});\n\nfunction countMoves(length, shelf) {\n length = parseInt(length);\n let shelfArr= [];\n for (let i = 0; i < shelf.length; i += 2) {\n shelfArr.push(shelf[i]);\n }\n let movesSum = 0;\n let outerFlag = false;\n let metAnother = false;\n for (let i = 0; i < shelfArr.length; i++) {\n if (shelfArr[i] == 1) {\n if(outerFlag === true) {\n metAnother = true;\n }\n outerFlag = true;\n } else if (shelfArr[i] == 0 && outerFlag === true) {\n movesSum++;\n }\n }\n if (!metAnother) {\n movesSum = 0;\n }\n console.log(movesSum);\n}\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.question(\"\", loop =>{\n getUserInput(loop);\n})\n\n\nfunction totalPressedDigit(number){\n let digit = number[0];\n let length = number.length;\n console.log( (digit-1) * 10 + length*(length+1)/2);\n}\n\nfunction getUserInput(n) {\n rl.question('', (number) => {\n rl.question(\"\", number => {\n let fi = number.indexOf(\"1\");\n let li = number.lastIndexOf(\"1\");\n number = number.substring(fi,li);\n let arr = number.split(\" \");\n console.log(countZeros(arr));\n if (n > 1) {\n getUserInput(n-1);\n } else {\n rl.close();\n }\n })\n \n \n }); \n}\n\nfunction countZeros(arr){\n let count = 0;\n for (let index = 0; index < arr.length; index++) {\n if(arr[index] == 0)\n ++count;\n }\n return count;\n}\n\nrl.on(\"close\", function() {\n console.log(\"\\nBYE BYE !!!\");\n process.exit(0);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n var x = readline();\n // var y = readline(); // first line of input usually gives the no. of test cases,i.e, the no. of lines ahead.\n // var inp; // declaring the variable outside the loop\n for (var i = 0; i < x; i++) {\n var y = readline();\n let inp = readline().split(\" \");\n console.log(foo(inp))\n }\n\n}\n\n\n\nfunction foo(digit){\n\n let count = 0;\n let firstIndex = digit.indexOf(\"1\");\n let secondIndex = digit.lastIndexOf(`1`);\n let max = firstIndex\n for(let i =0; i < digit.length; i++){\n if(digit[i] ==1 && i !== secondIndex){\n max = Math.max(i,max)\n }\n }\n\n if(firstIndex == secondIndex){\n return 0;\n }\n if(firstIndex == max){\n return secondIndex - max -1;\n }\n // console.log(max,firstIndex,secondIndex)\n return secondIndex - max;\n\n}"}, {"source_code": "var problem = function(arr) {\n\n var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);\n for (var i = 0; i < arr.length; i++) {\n if (a[i] == 1) count++;\n }\n return (a.length - count);\n\n}\n\nvar tests = readline();\n\nfor (var i = 0; i < tests; i++) {\n\n var n, items;\n //n = readline();\n items = readline().split(\" \");\n print(problem(items));\n\n}"}], "src_uid": "1c07882651ef6ebfc05e777d562e28b9"} {"source_code": "if (process.env.ANT)\n{\n global.print = this.print ||\n function(){console.log([...arguments].join(' '))} ||\n require('lol-io').print;\n global.write = this.write || require('lol-io').write\n global.readline = this.readline || require('lol-io').readline\n main();\n}\nelse\n{\n const rl = require('readline').createInterface({ input: process.stdin,\n output: process.stdout });\n global.print = console.log\n global.write = (...args) => {\n process.stdout.write(args.join(' '));\n }\n const lines = []\n rl.on('line', line =>{\n lines.push(line);\n });\n rl.on('close', main)\n let rli = 0;\n global.readline = ()=>lines[rli++];\n}\n\n///////////// CODE\n\nfunction main(){\n\n var n = +readline();\n var arr = readline().split(' ').map(x=>+x);\n\n function gcd(a, b){\n if (a%b==0)\n return b;\n return gcd(b, a%b);\n }\n let g = arr[0];\n\n for (let i=1; i {\n let c;\n if (a < b) { c = b; b = a; a = c; }\n while(b) { c = b; b = a % b; a = c; }\n return a;\n};\n \nreadline();\nconst x = readline().split(' ').map(Number);\nconst m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);\nconst mRoot = Math.floor(Math.sqrt(m));\nlet r = 1;\nfor (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }\nwrite(2 * r - +(Math.pow(mRoot, 2) === m));"}], "negative_code": [{"source_code": "if (process.env.ANT)\n{\n global.print = this.print ||\n function(){console.log([...arguments].join(' '))} ||\n require('lol-io').print;\n global.write = this.write || require('lol-io').write\n global.readline = this.readline || require('lol-io').readline\n main();\n}\nelse\n{\n const rl = require('readline').createInterface({ input: process.stdin,\n output: process.stdout });\n global.print = console.log\n global.write = (...args) => {\n process.stdout.write(args.join(' '));\n }\n const lines = []\n rl.on('line', line =>{\n lines.push(line);\n });\n rl.on('close', main)\n let rli = 0;\n global.readline = ()=>lines[rli++];\n}\n\n///////////// CODE\n\nfunction main(){\n\n var n = +readline();\n var arr = readline().split(' ').map(x=>+x);\n\n function gcd(a, b){\n if (b)\n return a%b;\n return a;\n }\n let g = arr[0];\n\n for (let i=1; i {\n let c;\n if (a < b) { c = b; b = a; a = c; }\n while(b) { c = b; b = a % b; a = c; }\n return a;\n};\n \nreadline();\nconst x = readline().split(' ').map(Number);\nconst m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);\nlet r = 1;\nconst mRoot = Math.floor(Math.sqrt(m));\nfor (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }\nwrite(2 * r - +(Math.pow(mRoot, 2) === r)) ;"}, {"source_code": "'use strict'\n \nconst gcd = (a,b) => {\n let c;\n if (a < b) { c = b; b = a; a = c; }\n while(b) { c = b; b = a % b; a = c; }\n return a;\n};\n \nreadline();\nconst x = readline().split(' ').map(Number);\nconst m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);\nlet r = 0;\nfor (let i = 1; i < Math.sqrt(m) + 1; i++) { if (m % i === 0) r++; }\nwrite(2 * r - +(Math.pow(Math.floor(Math.sqrt(r)), 2) === r)) ;"}], "src_uid": "6379ec153377fb9c30a7b897659da7d6"} {"source_code": "\nfunction main() {\n var numFriends = parseInt(readline());\n var widthArray = new Array();\n var heightArray = new Array();\n\n getDimensions(widthArray, heightArray, numFriends);\n \n var totalW = widthArray.reduce(sum);\n var maxH1 = maxWithout(heightArray, -1);\n var maxH2 = maxWithout(heightArray, maxH1);\n\n for(var i = 0; i < numFriends; ++i) {\n var h = heightArray[maxH1];\n if(i == maxH1) {\n h = heightArray[maxH2];\n }\n print((totalW - widthArray[i]) * h);\n }\n\n}\n\nfunction getDimensions(w, h, n) {\n for(var i = 0; i < n; i++) {\n var line = readline();\n var arr = line.split(\" \");\n var _w = parseInt(arr[0]);\n var _h = parseInt(arr[1]);\n w.push(_w);\n h.push(_h);\n }\n}\n\nvar sum = function(previousValue, currentValue, index, array) {\n return previousValue + currentValue;\n}\n\nvar maxWithout = function(arr, indexToDisregard) {\n var max = 0;\n var maxIndex = 0;\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] > max && i != indexToDisregard) {\n max = arr[i];\n maxIndex = i;\n }\n }\n return maxIndex;\n}\n\nmain();\n\n\n", "positive_code": [{"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0,this._inc=function(t){return t+1},this._dec=function(t){return t-1}}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,i,e){this.k=t,this.v=r,this.l=i,this.r=e,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),i=this._height(t.r);t.h=Math.max(r,i)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var i=t.l,e=t.r;if(!e)return i;var o=this._min(e);return o.r=this._ermin(e),o.l=i,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r,1;i=this.cmp(t,i.k)<0?i.l:i.r}return 0},_Tree.prototype.map=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r(i.v),i.v;i=this.cmp(t,i.k)<0?i.l:i.r}return void 0},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.map(t,this._inc);void 0==r&&this.avl.insert(t,1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.map(t,this._dec);void 0!=r&&(0==r&&this.avl.erase(t),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,i){for(var e=0;i>e;++e)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var cnt = new Array(1024);\n for(var i = 0; i <= 1000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n var fl = 0\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n fl = 0\n if (set.count(h[i]) == 1)\n {\n set.erase(h[i]);\n fl = 1;\n }\n H = set.last();\n if (fl)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "//Array snippets\nArray.prototype.back = function()\n{\n return this[this.length - 1];\n}\n\n//Math snippets\n//GCD\nMath.gcd = function(a, b)\n{\n return (b ? gcd(b, a%b) : a);\n}\n\n//LCM\nMath.lcm = function(a, b)\n{\n return (a/gcd(a, b)*b);\n}\n\n//Signum\nMath.sign = function(a)\n{\n return ((a > 0) - (a < 0));\n}\n\n//Usual number comparator\nMath.cmp = function(a, b)\n{\n return (+a > +b) - (+a < +b);\n}\n\n//Inverse number comparator\nMath.icmp = function(a, b)\n{\n return (+a < +b) - (+a > +b);\n}\n\nfunction Stack()\n{\n this.a = [];\n}\n\nStack.prototype.empty = function()\n{\n return this.a.length == 0;\n}\n\nStack.prototype.push = function(v)\n{\n this.a.push(v);\n}\n\nStack.prototype.pop = function()\n{\n if (!this.empty())\n return this.a.pop();\n return undefined;\n}\n\nStack.prototype.top = function()\n{\n if (!this.empty())\n return this.a[this.a.length - 1];\n return undefined; \n}\n\nStack.prototype.clear = function()\n{\n this.a = [];\n}\n\nStack.prototype.size = function()\n{\n return this.a.length;\n}\n\nfunction Queue()\n{\n this.l = new Stack();\n this.r = new Stack();\n}\n\nQueue.prototype.push = function(v)\n{\n this.l.push(v);\n}\n\nQueue.prototype.empty = function()\n{\n return this.r.empty() && this.l.empty();\n}\n\nQueue.prototype.pop = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.pop();\n return undefined;\n}\n\nQueue.prototype.front = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.top();\n return undefined; \n}\n\nQueue.prototype.size = function()\n{\n return l.size() + r.size();\n}\n\nQueue.prototype.clear = function()\n{\n l.clear();\n r.clear();\n}\n\nfunction Reader()\n{\n this.b = [];\n this.c = 0;\n}\n\nReader.prototype.next = function()\n{\n if (this.c == this.b.length)\n {\n this.c = 0;\n this.b = readline().split(' ');\n } \n return this.b[this.c++];\n}\n\nfunction Writer()\n{\n this.l = [\"\"];\n this.c = 0;\n}\n\nWriter.prototype.print = function(s)\n{\n this.l[this.c] += s;\n}\n\nWriter.prototype.println = function(s)\n{\n if (s == undefined)\n s = \"\";\n this.l[this.c] += s;\n this.l.push(\"\");\n ++this.c;\n}\n\nWriter.prototype.flush = function()\n{\n print(this.l.join('\\n'));\n this.l = [];\n}\n\nfunction Treap(cmp)\n{\n if (typeof cmp == \"undefined\")\n this.cmp = function(a,b){return ((a>b)-(a t.p)\n {\n var tmp = this._split(t, n.k);\n n.l = tmp.l;\n n.r = tmp.r;\n this._update(n);\n return n;\n }\n if (this.cmp(n.k, t.k) < 0)\n t.l = this._insert(t.l, n);\n else\n t.r = this._insert(t.r, n);\n this._update(t);\n return t;\n}\n\nTreap.prototype.nth = function(n)\n{\n var cur = this._root;\n var lSize = 0;\n while(cur)\n {\n lSize = this._sizeOf(cur.l);\n if (lSize == n)\n return {k: cur.k, v: cur.v};\n cur = lSize > n ? cur.l : cur.r;\n if (lSize < n)\n n -= lSize + 1; \n } \n return null;\n}\n\nTreap.prototype._forEach = function(t, cb)\n{\n if (t.l)\n this._forEach(t.l, cb);\n cb(t.k, t.v);\n if (t.r)\n this._forEach(t.r, cb);\n}\n\nTreap.prototype.forEach = function(cb)\n{\n if (this._root)\n this._forEach(this._root, cb);\n}\n\nTreap.prototype.insert = function(k, v)\n{\n this._root = this._insert(this._root, new Treap.Node(k, v, Math.random(), null, null)); \n}\n\nTreap.prototype._merge = function(l, r)\n{\n if (!l)\n {\n this._update(r);\n return r;\n }\n if (!r)\n {\n this._update(l);\n return l;\n }\n if (l.p > r.p)\n {\n l.r = this._merge(l.r, r)\n this._update(l);\n return l;\n }\n r.l = this._merge(l, r.l);\n this._update(r);\n return r;\n}\n\nTreap.prototype._erase = function(t, k)\n{\n if (t.k == k)\n {\n var tmp = this._merge(t.l, t.r);\n this._update(tmp);\n return tmp;\n }\n if (this.cmp(k, t.k) <= 0)\n if (t.l)\n t.l = this._erase(t.l, k);\n else\n if (t.r)\n t.r = this._erase(t.r, k);\n this._update(t);\n return t;\n}\n\nTreap.prototype.erase = function(k)\n{\n if (this._root)\n this._root = this._erase(this._root, k);\n}\n\nTreap.prototype._get = function(t, k)\n{\n if (!t)\n return undefined;\n if (this.cmp(k, t.k) == 0)\n return t.v;\n if (this.cmp(k, t.k) < 0)\n return this._get(t.l, k);\n return this._get(t.r, k);\n}\n\nTreap.prototype.get = function(k)\n{\n if (this._root)\n return this._get(this._root, k);\n return undefined;\n}\n\nTreap.prototype.set = function(k, v)\n{\n var cur = this._root;\n while(cur)\n {\n if (this.cmp(k, cur.k) == 0)\n {\n cur.v = v;\n return;\n }\n if (this.cmp(k, cur.k) < 0)\n cur = cur.l;\n else\n cur = cur.r;\n } \n}\n\nTreap.prototype.clear = function()\n{\n this._root = null;\n}\n\nTreap.prototype.size = function()\n{\n return (this._root?this._root.size:0);\n}\n\nfunction Set(cmp)\n{\n this.treap = new Treap(cmp);\n}\n\nSet.prototype.insert = function(v)\n{\n if (this.treap.get(v) == undefined)\n this.treap.insert(v, 1); \n}\n\nSet.prototype.size = function()\n{\n return this.treap.size();\n}\n\nSet.prototype.clear = function()\n{\n this.treap.clear();\n}\n\nSet.prototype.erase = function(v)\n{\n this.treap.erase(v);\n}\n\nSet.prototype.count = function(v)\n{\n return this.treap.get(v) != undefined; \n}\n\nSet.prototype.nth = function(v)\n{\n if (v < 0 || v >= this.treap.size())\n return undefined;\n return this.treap.nth(v).k;\n}\n\nSet.prototype.first = function()\n{\n return this.nth(0);\n}\n\nSet.prototype.last = function()\n{\n return this.nth(this.size() - 1);\n}\n\nSet.prototype.forEach = function(cb)\n{\n this.treap.forEach(cb);\n}\n\nfunction MultiSet(cmp)\n{\n this.treap = new Treap(cmp);\n this._size = 0;\n}\n\nMultiSet.prototype.insert = function(v)\n{\n ++this._size;\n var tmp = this.treap.get(v);\n if (tmp == undefined)\n this.treap.insert(v, 1);\n else\n this.treap.set(v, tmp+1); \n}\n\nMultiSet.prototype.size = function()\n{\n return this._size;\n}\n\nMultiSet.prototype.clear = function()\n{\n this._size = 0;\n this.treap.clear();\n}\n\nMultiSet.prototype.erase = function(v)\n{\n var tmp = this.treap.get(v);\n if (tmp != undefined)\n {\n if (tmp == 1)\n this.treap.erase(v);\n if (tmp > 1)\n this.treap.set(v, tmp-1);\n --this._size;\n }\n}\n\nMultiSet.prototype.eraseAll = function(v)\n{\n this.treap.erase(v);\n}\n\nMultiSet.prototype.count = function(v)\n{\n var tmp = this.treap.get(v);\n return (tmp == undefined?0:tmp); \n}\n\nMultiSet.prototype.first = function()\n{\n return this.treap.nth(0).k;\n}\n\nMultiSet.prototype.last = function()\n{\n return this.treap.nth(this.treap.size() - 1).k;\n}\n\nMultiSet.prototype.forEach = function(cb)\n{\n this.treap.forEach(function(k, v)\n {\n for(var i = 0; i < v; ++i)\n cb(k);\n });\n}\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.icmp);\n var tmp;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n set.erase(h[i]);\n H = set.first();\n set.insert(h[i]);\n //print(set.count(1));\n //print(set.count(3));\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function Treap(t){\"undefined\"==typeof t&&(this.cmp=function(t,r){return(t>r)-(r>t)}),this.cmp=t,this._root=null}function Set(t){this.treap=new Treap(t)}function MultiSet(t){this.treap=new Treap(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},Treap.Node=function(t,r,e,i,o){this.k=t,this.v=r,this.p=e,this.l=i,this.r=o,this.size=1},Treap.prototype._update=function(t){t&&(t.size=1+(t.l?t.l.size:0)+(t.r?t.r.size:0))},Treap.prototype._sizeOf=function(t){return t?t.size:0},Treap.prototype._split=function(t,r){if(t){if(this.cmp(r,t.k)<0){var e=this._split(t.l,r);return t.l=e.r,this._update(t),{l:e.l,r:t}}var e=this._split(t.r,r);return t.r=e.l,this._update(t),{l:t,r:e.r}}return{l:null,r:null}},Treap.prototype._insert=function(t,r){if(!t)return r;if(r.p>t.p){var e=this._split(t,r.k);return r.l=e.l,r.r=e.r,this._update(r),r}return this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._update(t),t},Treap.prototype.nth=function(t){for(var r=this._root,e=0;r;){if(e=this._sizeOf(r.l),e==t)return{k:r.k,v:r.v};r=e>t?r.l:r.r,t>e&&(t-=e+1)}return null},Treap.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},Treap.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},Treap.prototype.insert=function(t,r){this._root=this._insert(this._root,new Treap.Node(t,r,Math.random()*Math.random(),null,null))},Treap.prototype._merge=function(t,r){return t?r?t.p>r.p?(t.r=this._merge(t.r,r),this._update(t),t):(r.l=this._merge(t,r.l),this._update(r),r):(this._update(t),t):(this._update(r),r)},Treap.prototype._erase=function(t,r){if(t.k==r){var e=this._merge(t.l,t.r);return this._update(e),e}return this.cmp(r,t.k)<=0&&(t.l?t.l=this._erase(t.l,r):t.r&&(t.r=this._erase(t.r,r))),this._update(t),t},Treap.prototype.erase=function(t){this._root&&(this._root=this._erase(this._root,t))},Treap.prototype._get=function(t,r){return t?0==this.cmp(r,t.k)?t.v:this.cmp(r,t.k)<0?this._get(t.l,r):this._get(t.r,r):void 0},Treap.prototype.get=function(t){return this._root?this._get(this._root,t):void 0},Treap.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},Treap.prototype.clear=function(){this._root=null},Treap.prototype.size=function(){return this._root?this._root.size:0},Set.prototype.insert=function(t){void 0==this.treap.get(t)&&this.treap.insert(t,1)},Set.prototype.size=function(){return this.treap.size()},Set.prototype.clear=function(){this.treap.clear()},Set.prototype.erase=function(t){this.treap.erase(t)},Set.prototype.count=function(t){return void 0!=this.treap.get(t)},Set.prototype.nth=function(t){return 0>t||t>=this.treap.size()?void 0:this.treap.nth(t).k},Set.prototype.first=function(){return this.nth(0)},Set.prototype.last=function(){return this.nth(this.size()-1)},Set.prototype.forEach=function(t){this.treap.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.treap.get(t);void 0==r?this.treap.insert(t,1):this.treap.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.treap.clear()},MultiSet.prototype.erase=function(t){var r=this.treap.get(t);void 0!=r&&(1==r&&this.treap.erase(t),r>1&&this.treap.set(t,r-1),--this._size)},MultiSet.prototype.eraseAll=function(t){this.treap.erase(t)},MultiSet.prototype.count=function(t){var r=this.treap.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.treap.nth(0).k},MultiSet.prototype.last=function(){return this.treap.nth(this.treap.size()-1).k},MultiSet.prototype.forEach=function(t){this.treap.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.icmp);\n var tmp;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n set.erase(h[i]);\n H = set.first();\n set.insert(h[i]);\n //print(set.count(1));\n //print(set.count(3));\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,e,i){this.k=t,this.v=r,this.l=e,this.r=i,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),e=this._height(t.r);t.h=Math.max(r,e)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var e=t.l,i=t.r;if(!i)return e;var o=this._min(i);return o.r=this._ermin(i),o.l=e,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.get(t);void 0==r?this.avl.insert(t,1):this.avl.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.get(t);void 0!=r&&(1==r&&this.avl.erase(t),r>1&&this.avl.set(t,r-1),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var mx1 = 0;\n var mx2 = 0;\n var mxind = -1;\n var cnt = new Array(1024);\n for(var i = 0; i <= 1000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n cnt[h[i]]++;\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n //if (cnt[h[i]] == 1)\n set.erase(h[i]);\n H = set.last();\n //if (cnt[h[i]] == 1)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0,this._inc=function(t){return t+1},this._dec=function(t){return t-1}}function Map(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,i,e){this.k=t,this.v=r,this.l=i,this.r=e,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),i=this._height(t.r);t.h=Math.max(r,i)+1}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var i=t.l,e=t.r;if(!e)return i;var o=this._min(e);return o.r=this._ermin(e),o.l=i,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r,1;i=this.cmp(t,i.k)<0?i.l:i.r}return 0},_Tree.prototype.map=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r(i.v),i.v;i=this.cmp(t,i.k)<0?i.l:i.r}return void 0},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null},Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.map(t,this._inc);void 0==r&&this.avl.insert(t,1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.map(t,this._dec);void 0!=r&&(0==r&&this.avl.erase(t),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,i){for(var e=0;i>e;++e)t(r)})},Map.prototype.insert=function(t,r){void 0==this.avl.get(t)&&(this.avl.insert(t,r),++this._size)},Map.prototype.get=function(t){return this.avl.get(t)},Map.prototype.set=function(t,r){this.avl.set(t,r)||(++this._size,this.avl.insert(t,r))},Map.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},Map.prototype.clear=function(){this._size=0,this.avl.clear()},Map.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Map.prototype.size=function(){return this._size};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var cnt = new Array(1024);\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n var fl = 0\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n fl = 0\n //if (set.count(h[i]) == 1)\n //{\n set.erase(h[i]);\n fl = 1;\n //}\n H = set.last();\n //if (fl)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0,this._inc=function(t){return t+1},this._dec=function(t){return t-1}}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,i,e){this.k=t,this.v=r,this.l=i,this.r=e,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),i=this._height(t.r);t.h=Math.max(r,i)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var i=t.l,e=t.r;if(!e)return i;var o=this._min(e);return o.r=this._ermin(e),o.l=i,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r,1;i=this.cmp(t,i.k)<0?i.l:i.r}return 0},_Tree.prototype.map=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r(i.v),i.v;i=this.cmp(t,i.k)<0?i.l:i.r}return void 0},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.map(t,this._inc);void 0==r&&this.avl.insert(t,1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.map(t,this._dec);void 0!=r&&(0==r&&this.avl.erase(t),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,i){for(var e=0;i>e;++e)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var cnt = new Array(1024);\n for(var i = 0; i <= 1000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n set.erase(h[i]);\n H = set.last();\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,e,i){this.k=t,this.v=r,this.l=e,this.r=i,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),e=this._height(t.r);t.h=Math.max(r,e)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var e=t.l,i=t.r;if(!i)return e;var o=this._min(i);return o.r=this._ermin(i),o.l=e,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.get(t);void 0==r?this.avl.insert(t,1):this.avl.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.get(t);void 0!=r&&(1==r&&this.avl.erase(t),r>1&&this.avl.set(t,r-1),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var mx1 = 0;\n var mx2 = 0;\n var mxind = -1;\n var cnt = new Array(1024);\n for(var i = 0; i <= 1000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n cnt[h[i]]++;\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n if (cnt[h[i]] == 1)\n set.erase(h[i]);\n H = set.last();\n if (cnt[h[i]] == 1)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,e,i){this.k=t,this.v=r,this.l=e,this.r=i,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),e=this._height(t.r);t.h=Math.max(r,e)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var e=t.l,i=t.r;if(!i)return e;var o=this._min(i);return o.r=this._ermin(i),o.l=e,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.get(t);void 0==r?this.avl.insert(t,1):this.avl.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.get(t);void 0!=r&&(1==r&&this.avl.erase(t),r>1&&this.avl.set(t,r-1),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new Set(Math.cmp);\n var mx1 = 0;\n var mx2 = 0;\n var mxind = -1;\n var cnt = new Array(1024);\n for(var i = 0; i <= 1000; ++i)\n cnt[i] = 0;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n cnt[h[i]]++;\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n if (cnt[h[i]] == 1)\n set.erase(h[i]);\n H = set.last();\n if (cnt[h[i]] == 1)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,e,i){this.k=t,this.v=r,this.l=e,this.r=i,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),e=this._height(t.r);t.h=Math.max(r,e)}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var e=t.l,i=t.r;if(!i)return e;var o=this._min(i);return o.r=this._ermin(i),o.l=e,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null};var avl=new _Tree(Math.cmp);Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.get(t);void 0==r?this.avl.insert(t,1):this.avl.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.get(t);void 0!=r&&(1==r&&this.avl.erase(t),r>1&&this.avl.set(t,r-1),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var mx1 = 0;\n var mx2 = 0;\n var mxind = -1;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n //set.insert(h[i]);\n if (h[i] > mx1)\n {\n mx1 = h[i];\n mxind = i;\n }\n }\n for(var i = 0; i < n; ++i)\n if (i != mxind && mx2 < h[i])\n mx2 = h[i];\n\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n if (i == mxind)\n H = mx2;\n else\n H = mx1;\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function Treap(t){\"undefined\"==typeof t&&(this.cmp=function(t,r){return(t>r)-(r>t)}),this.cmp=t,this._root=null}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},Treap.Node=function(t,r,i,e,o){this.k=t,this.v=r,this.p=i,this.l=e,this.r=o,this.size=1},Treap.prototype._update=function(t){t&&(t.size=1+(t.l?t.l.size:0)+(t.r?t.r.size:0))},Treap.prototype._sizeOf=function(t){return t?t.size:0},Treap.prototype._split=function(t,r){if(t){if(this.cmp(r,t.k)<0){var i=this._split(t.l,r);return t.l=i.r,this._update(t),{l:i.l,r:t}}var i=this._split(t.r,r);return t.r=i.l,this._update(t),{l:t,r:i.r}}return{l:null,r:null}},Treap.prototype._insert=function(t,r){if(!t)return r;if(r.p>t.p){var i=this._split(t,r.k);return r.l=i.l,r.r=i.r,this._update(r),r}return this.cmp(r.k,t.k)<=0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._update(t),t},Treap.prototype.nth=function(t){for(var r=this._root,i=0;r;){if(i=this._sizeOf(r.l),i==t)return{k:r.k,v:r.v};r=i>t?r.l:r.r,t>i&&(t-=i+1)}return null},Treap.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},Treap.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},Treap.prototype.insert=function(t,r){this._root=this._insert(this._root,new Treap.Node(t,r,Math.random()+Math.random(),null,null))},Treap.prototype._merge=function(t,r){return t?r?t.p>r.p?(t.r=this._merge(t.r,r),this._update(t),t):(r.l=this._merge(t,r.l),this._update(r),r):(this._update(t),t):(this._update(r),r)},Treap.prototype._erase=function(t,r){if(t.k==r){var i=this._merge(t.l,t.r);return this._update(i),i}return this.cmp(r,t.k)<0&&(t.l?t.l=this._erase(t.l,r):t.r&&(t.r=this._erase(t.r,r))),this._update(t),t},Treap.prototype.erase=function(t){this._root&&(this._root=this._erase(this._root,t))},Treap.prototype._get=function(t,r){return t?0==this.cmp(r,t.k)?t.v:this.cmp(r,t.k)<0?this._get(t.l,r):this._get(t.r,r):void 0},Treap.prototype.get=function(t){return this._root?this._get(this._root,t):void 0},Treap.prototype.set=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return void(i.v=r);i=this.cmp(t,i.k)<0?i.l:i.r}},Treap.prototype.clear=function(){this._root=null},Treap.prototype.size=function(){return this._root?this._root.size:0};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var treap = new Treap(function(a, b){return ((+a < +b) - (+a > +b));});\n var tmp;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n tmp = treap.get(h[i]);\n if (tmp == undefined)\n treap.insert(h[i], 1);\n else\n treap.set(h[i], tmp + 1);\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n tmp = treap.get(h[i]);\n if (tmp == 1)\n treap.erase(h[i]);\n H = treap.nth(0).k;\n if (tmp == 1)\n treap.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "//Array snippets\nArray.prototype.back = function()\n{\n return this[this.length - 1];\n}\n\n//Math snippets\n//GCD\nMath.gcd = function(a, b)\n{\n return (b ? gcd(b, a%b) : a);\n}\n\n//LCM\nMath.lcm = function(a, b)\n{\n return (a/gcd(a, b)*b);\n}\n\n//Signum\nMath.sign = function(a)\n{\n return ((a > 0) - (a < 0));\n}\n\n//Usual number comparator\nMath.cmp = function(a, b)\n{\n return (+a > +b) - (+a < +b);\n}\n\n//Inverse number comparator\nMath.icmp = function(a, b)\n{\n return (+a < +b) - (+a > +b);\n}\n\nfunction Stack()\n{\n this.a = [];\n}\n\nStack.prototype.empty = function()\n{\n return this.a.length == 0;\n}\n\nStack.prototype.push = function(v)\n{\n this.a.push(v);\n}\n\nStack.prototype.pop = function()\n{\n if (!this.empty())\n return this.a.pop();\n return undefined;\n}\n\nStack.prototype.top = function()\n{\n if (!this.empty())\n return this.a[this.a.length - 1];\n return undefined; \n}\n\nStack.prototype.clear = function()\n{\n this.a = [];\n}\n\nStack.prototype.size = function()\n{\n return this.a.length;\n}\n\nfunction Queue()\n{\n this.l = new Stack();\n this.r = new Stack();\n}\n\nQueue.prototype.push = function(v)\n{\n this.l.push(v);\n}\n\nQueue.prototype.empty = function()\n{\n return this.r.empty() && this.l.empty();\n}\n\nQueue.prototype.pop = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.pop();\n return undefined;\n}\n\nQueue.prototype.front = function()\n{\n if (this.r.empty())\n {\n while(!this.l.empty())\n this.r.push(this.l.pop()); \n }\n if (!this.r.empty())\n return this.r.top();\n return undefined; \n}\n\nQueue.prototype.size = function()\n{\n return l.size() + r.size();\n}\n\nQueue.prototype.clear = function()\n{\n l.clear();\n r.clear();\n}\n\nfunction Reader()\n{\n this.b = [];\n this.c = 0;\n}\n\nReader.prototype.next = function()\n{\n if (this.c == this.b.length)\n {\n this.c = 0;\n this.b = readline().split(' ');\n } \n return this.b[this.c++];\n}\n\nfunction Writer()\n{\n this.l = [\"\"];\n this.c = 0;\n}\n\nWriter.prototype.print = function(s)\n{\n this.l[this.c] += s;\n}\n\nWriter.prototype.println = function(s)\n{\n if (s == undefined)\n s = \"\";\n this.l[this.c] += s;\n this.l.push(\"\");\n ++this.c;\n}\n\nWriter.prototype.flush = function()\n{\n print(this.l.join('\\n'));\n this.l = [];\n}\n\nfunction Treap(cmp)\n{\n if (typeof cmp == \"undefined\")\n this.cmp = function(a,b){return ((a>b)-(a t.p)\n {\n var tmp = this._split(t, n.k);\n n.l = tmp.l;\n n.r = tmp.r;\n this._update(n);\n return n;\n }\n if (this.cmp(n.k, t.k) < 0)\n t.l = this._insert(t.l, n);\n else\n t.r = this._insert(t.r, n);\n this._update(t);\n return t;\n}\n\nTreap.prototype.nth = function(n)\n{\n var cur = this._root;\n var lSize = 0;\n while(cur)\n {\n lSize = this._sizeOf(cur.l);\n if (lSize == n)\n return {k: cur.k, v: cur.v};\n cur = lSize > n ? cur.l : cur.r;\n if (lSize < n)\n n -= lSize + 1; \n } \n return null;\n}\n\nTreap.prototype._forEach = function(t, cb)\n{\n if (t.l)\n this._forEach(t.l, cb);\n cb(t.k, t.v);\n if (t.r)\n this._forEach(t.r, cb);\n}\n\nTreap.prototype.forEach = function(cb)\n{\n if (this._root)\n this._forEach(this._root, cb);\n}\n\nTreap.prototype.insert = function(k, v)\n{\n this._root = this._insert(this._root, new Treap.Node(k, v, Math.random()*Math.random(), null, null));\n}\n\nTreap.prototype._merge = function(l, r)\n{\n if (!l)\n {\n this._update(r);\n return r;\n }\n if (!r)\n {\n this._update(l);\n return l;\n }\n if (l.p > r.p)\n {\n l.r = this._merge(l.r, r)\n this._update(l);\n return l;\n }\n r.l = this._merge(l, r.l);\n this._update(r);\n return r;\n}\n\nTreap.prototype._erase = function(t, k)\n{\n if (t.k == k)\n {\n var tmp = this._merge(t.l, t.r);\n this._update(tmp);\n return tmp;\n }\n if (this.cmp(k, t.k) <= 0)\n if (t.l)\n t.l = this._erase(t.l, k);\n else\n if (t.r)\n t.r = this._erase(t.r, k);\n this._update(t);\n return t;\n}\n\nTreap.prototype.erase = function(k)\n{\n if (this._root)\n this._root = this._erase(this._root, k);\n}\n\nTreap.prototype._get = function(t, k)\n{\n if (!t)\n return undefined;\n if (this.cmp(k, t.k) == 0)\n return t.v;\n if (this.cmp(k, t.k) < 0)\n return this._get(t.l, k);\n return this._get(t.r, k);\n}\n\nTreap.prototype.get = function(k)\n{\n if (this._root)\n return this._get(this._root, k);\n return undefined;\n}\n\nTreap.prototype.set = function(k, v)\n{\n var cur = this._root;\n while(cur)\n {\n if (this.cmp(k, cur.k) == 0)\n {\n cur.v = v;\n return;\n }\n if (this.cmp(k, cur.k) < 0)\n cur = cur.l;\n else\n cur = cur.r;\n } \n}\n\nTreap.prototype.clear = function()\n{\n this._root = null;\n}\n\nTreap.prototype.size = function()\n{\n return (this._root?this._root.size:0);\n}\n\nfunction Set(cmp)\n{\n this.treap = new Treap(cmp);\n}\n\nSet.prototype.insert = function(v)\n{\n if (this.treap.get(v) == undefined)\n this.treap.insert(v, 1); \n}\n\nSet.prototype.size = function()\n{\n return this.treap.size();\n}\n\nSet.prototype.clear = function()\n{\n this.treap.clear();\n}\n\nSet.prototype.erase = function(v)\n{\n this.treap.erase(v);\n}\n\nSet.prototype.count = function(v)\n{\n return this.treap.get(v) != undefined; \n}\n\nSet.prototype.nth = function(v)\n{\n if (v < 0 || v >= this.treap.size())\n return undefined;\n return this.treap.nth(v).k;\n}\n\nSet.prototype.first = function()\n{\n return this.nth(0);\n}\n\nSet.prototype.last = function()\n{\n return this.nth(this.size() - 1);\n}\n\nSet.prototype.forEach = function(cb)\n{\n this.treap.forEach(cb);\n}\n\nfunction MultiSet(cmp)\n{\n this.treap = new Treap(cmp);\n this._size = 0;\n}\n\nMultiSet.prototype.insert = function(v)\n{\n ++this._size;\n var tmp = this.treap.get(v);\n if (tmp == undefined)\n this.treap.insert(v, 1);\n else\n this.treap.set(v, tmp+1); \n}\n\nMultiSet.prototype.size = function()\n{\n return this._size;\n}\n\nMultiSet.prototype.clear = function()\n{\n this._size = 0;\n this.treap.clear();\n}\n\nMultiSet.prototype.erase = function(v)\n{\n var tmp = this.treap.get(v);\n if (tmp != undefined)\n {\n if (tmp == 1)\n this.treap.erase(v);\n if (tmp > 1)\n this.treap.set(v, tmp-1);\n --this._size;\n }\n}\n\nMultiSet.prototype.eraseAll = function(v)\n{\n this.treap.erase(v);\n}\n\nMultiSet.prototype.count = function(v)\n{\n var tmp = this.treap.get(v);\n return (tmp == undefined?0:tmp); \n}\n\nMultiSet.prototype.first = function()\n{\n return this.treap.nth(0).k;\n}\n\nMultiSet.prototype.last = function()\n{\n return this.treap.nth(this.treap.size() - 1).k;\n}\n\nMultiSet.prototype.forEach = function(cb)\n{\n this.treap.forEach(function(k, v)\n {\n for(var i = 0; i < v; ++i)\n cb(k);\n });\n}\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.icmp);\n var tmp;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n set.erase(h[i]);\n H = set.first();\n set.insert(h[i]);\n //print(set.count(1));\n //print(set.count(3));\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function _Tree(t){this.cmp=void 0!=t?t:function(t,r){return(t>r)-(r>t)},this._root=null}function Set(t){this.avl=new _Tree(t),this._size=0}function MultiSet(t){this.avl=new _Tree(t),this._size=0,this._inc=function(t){return t+1},this._dec=function(t){return t-1}}function Map(t){this.avl=new _Tree(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},_Node=function(t,r,i,e){this.k=t,this.v=r,this.l=i,this.r=e,this.h=1},_Tree.prototype._height=function(t){return t?t.h:0},_Tree.prototype._bfactor=function(t){return this._height(t.r)-this._height(t.l)},_Tree.prototype._recalc=function(t){if(t){var r=this._height(t.l),i=this._height(t.r);t.h=Math.max(r,i)+1}},_Tree.prototype._rotl=function(t){var r=t.r;return t.r=r.l,r.l=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._rotr=function(t){var r=t.l;return t.l=r.r,r.r=t,this._recalc(t),this._recalc(r),r},_Tree.prototype._balance=function(t){return this._recalc(t),2==this._bfactor(t)?(this._bfactor(t.r)<0&&(t.r=this._rotr(t.r)),this._rotl(t)):-2==this._bfactor(t)?(this._bfactor(t.l)>0&&(t.l=this._rotl(t.l)),this._rotr(t)):t},_Tree.prototype._insert=function(t,r){return t?0==this.cmp(r.k,t.k)?(t.v=r.v,t):(this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._balance(t)):new _Node(r.k,r.v,null,null)},_Tree.prototype.insert=function(t,r){this._root=this._insert(this._root,{k:t,v:r})},_Tree.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},_Tree.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},_Tree.prototype._min=function(t){for(var r=t;r.l;)r=r.l;return r},_Tree.prototype.first=function(){return this._root?this._min(this._root).k:void 0},_Tree.prototype.last=function(){if(this._root){for(var t=this._root;t.r;)t=t.r;return t.k}return void 0},_Tree.prototype._ermin=function(t){return t.l?(t.l=this._ermin(t.l),this._balance(t)):t.r},_Tree.prototype._erase=function(t,r){if(!t)return null;if(this.cmp(r,t.k)<0)t.l=this._erase(t.l,r);else{if(!(this.cmp(r,t.k)>0)){var i=t.l,e=t.r;if(!e)return i;var o=this._min(e);return o.r=this._ermin(e),o.l=i,this._balance(o)}t.r=this._erase(t.r,r)}return this._balance(t)},_Tree.prototype.get=function(t){for(var r=this._root;r;){if(0==this.cmp(t,r.k))return r.v;r=this.cmp(t,r.k)<0?r.l:r.r}return void 0},_Tree.prototype.set=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r,1;i=this.cmp(t,i.k)<0?i.l:i.r}return 0},_Tree.prototype.map=function(t,r){for(var i=this._root;i;){if(0==this.cmp(t,i.k))return i.v=r(i.v),i.v;i=this.cmp(t,i.k)<0?i.l:i.r}return void 0},_Tree.prototype.erase=function(t){this._root=this._erase(this._root,t)},_Tree.prototype.clear=function(){this._root=null},Set.prototype.insert=function(t){this.avl.insert(t,1)},Set.prototype.size=function(){return this._size},Set.prototype.clear=function(){this._size=0,this.avl.clear()},Set.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Set.prototype.count=function(t){return void 0!=this.avl.get(t)},Set.prototype.first=function(){return this.avl.first()},Set.prototype.last=function(){return this.avl.last()},Set.prototype.forEach=function(t){this.avl.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.avl.map(t,this._inc);void 0==r&&this.avl.insert(t,1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.avl.clear()},MultiSet.prototype.erase=function(t){var r=this.avl.map(t,this._dec);void 0!=r&&(0==r&&this.avl.erase(t),--this._size)},MultiSet.prototype.eraseAll=function(t){this.avl.erase(t)},MultiSet.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.avl.first()},MultiSet.prototype.last=function(){return this.avl.last()},MultiSet.prototype.forEach=function(t){this.avl.forEach(function(r,i){for(var e=0;i>e;++e)t(r)})},Map.prototype.insert=function(t,r){void 0==this.avl.get(t)&&(this.avl.insert(t,r),++this._size)},Map.prototype.get=function(t){return this.avl.get(t)},Map.prototype.set=function(t,r){this.avl.set(t,r)||(++this._size,this.avl.insert(t,r))},Map.prototype.count=function(t){var r=this.avl.get(t);return void 0==r?0:r},Map.prototype.clear=function(){this._size=0,this.avl.clear()},Map.prototype.erase=function(t){void 0!=this.avl.get(t)&&(--this._size,this.avl.erase(t))},Map.prototype.size=function(){return this._size};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var cnt = new Array(1024);\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n }\n var W, H;\n var fl = 0\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n fl = 0\n if (set.count(h[i]) == 1)\n {\n set.erase(h[i]);\n fl = 1;\n }\n H = set.last();\n if (fl)\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "var n = parseInt(readline().trim());\n\nvar w = new Array();\nvar h = new Array();\n\nvar wsum = 0;\n\nfor (var i = 0; i < n; i++) {\n var line = readline().trim().split(' ');\n w[i] = parseInt(line[0]);\n h[i] = parseInt(line[1]);\n wsum += w[i];\n}\n\nvar max1 = 0;\nvar max1pos = 0;\nvar max2 = 0;\n\nfor (var i = 0; i < n; i++) {\n if (h[i] > max1) {\n max1 = h[i];\n max1pos = i;\n }\n}\n\nfor (var i = 0; i < n; i++) {\n if ((h[i] > max2) && (i != max1pos)) {\n max2 = h[i];\n }\n}\n\nfor (var i = 0; i < n; i++) {\n var wtot = wsum - w[i];\n var htot = 0;\n if (h[i] == max1) {\n htot = max2;\n } else {\n htot = max1;\n }\n write(htot * wtot);\n write(' ');\n}"}, {"source_code": "var i = 0,\n\tsum = 0,\n\tw = [],\n\tmax = [0, 0],\n\timax = 0,\n\tn = +readline(),\n\tpixels = [],\n\tpair;\n\nfor (; i max[0]) {\n\t\timax = i;\n\t\tmax[1] = max[0];\n\t\tmax[0] = +pair[1];\n\t} else if (+pair[1] > max[1]){\n\t\tmax[1] = +pair[1];\n\t}\n}\nfor (i=0; i lines[maxI][1])\t{\n\t\tmaxI = i;\n\t}\n}\n\nvar prevMaxI = maxI === 0 ? 1 : 0;\n\nfor (var i = prevMaxI + 1; i < maxI; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\nfor (var i = maxI + 1; i < n; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW;\n\n sumW = sum - arr[index][0];\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n\n return maxH * sumW;\n}\n\nprint(output.join(' '));\n"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nvar sum = 0;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n sum += lines[i][0];\n}\n\nvar maxI = 0;\n\nfor (var i = 1; i < n; i++) {\n\tif (lines[i][1] > lines[maxI][1])\t{\n\t\tmaxI = i;\n\t}\n}\n\nvar prevMaxI = maxI === 0 ? 1 : 0;\n\nfor (var i = prevMaxI + 1; i < maxI; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\nfor (var i = maxI + 1; i < n; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW;\n \n sumW = sum - arr[index][0];\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "\tvar n = readline(),\n\t\tfriends = [],\n\t\tsizes = [],\n\t\tsumWidths = 0,\n\t\tmaxHeight = {\n\t\t\tvalue: 0\n\t\t}\n\t\tsecondHeight = {\n\t\t\tvalue: 0\n\t\t}\n\n\n\tfor (var i=0; i < n; i++) {\n\t\tvar line = readline().split(' ');\n\t\tline[0] = Number(line[0]);\n\t\tline[1] = Number(line[1]);\n\t\tfriends[i] = line[0];\n\t\tsumWidths += line[0];\n\t\tif (line[1] >= maxHeight.value) {\n\t\t\tsecondHeight.value = maxHeight.value;\n\t\t\tmaxHeight.value = line[1];\n\t\t\tmaxHeight.id = i;\n\t\t}\n\n\t\tif (line[1] < maxHeight.value && line[1] > secondHeight.value) {\n\t\t\tsecondHeight.value = line[1];\n\t\t}\n\t}\n\n\tfor (var i = 0; i < n; i++) {\n\t\tif (i != maxHeight.id) {\n\t\t\tvar height = maxHeight.value;\n\t\t} else {\n\t\t\tvar height = secondHeight.value;\n\t\t}\n\t\tsizes[i] = height * (sumWidths - friends[i]);\n\t}\n\n\n\tprint(sizes.join(' '));"}, {"source_code": "var output = \"\";\nvar people = [];\nvar n = parseInt(readline());\nvar width = 0;\nvar height = 0;\nfor (var i = n; i > 0; i--) {\n var line = readline().split(\" \");\n var w = parseInt(line[0]);\n var h = parseInt(line[1]);\n width += w;\n if (height < h) {\n height = h;\n }\n people.push({\n width: w,\n height: h\n });\n}\nfor (var i = 0; i < n; i++) {\n var cw = width - people[i].width;\n var ch = height;\n if (ch === people[i].height) {\n ch = 0;\n for (var j = 0; j < n; j++) {\n if (i === j) continue;\n if (ch < people[j].height) {\n ch = people[j].height;\n if (ch === height) {\n break;\n }\n }\n }\n }\n output += (cw * ch) + \" \";\n}\nprint(output);\n"}], "negative_code": [{"source_code": "function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[\"\"],this.c=0}function Treap(t){\"undefined\"==typeof t&&(this.cmp=function(t,r){return(t>r)-(r>t)}),this.cmp=t,this._root=null}function Set(t){this.treap=new Treap(t)}function MultiSet(t){this.treap=new Treap(t),this._size=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,r){return r?gcd(r,t%r):t},Math.lcm=function(t,r){return t/gcd(t,r)*r},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,r){return(+t>+r)-(+r>+t)},Math.icmp=function(t,r){return(+r>+t)-(+t>+r)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(\" \")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){void 0==t&&(t=\"\"),this.l[this.c]+=t,this.l.push(\"\"),++this.c},Writer.prototype.flush=function(){print(this.l.join(\"\\n\")),this.l=[]},Treap.Node=function(t,r,e,i,o){this.k=t,this.v=r,this.p=e,this.l=i,this.r=o,this.size=1},Treap.prototype._update=function(t){t&&(t.size=1+(t.l?t.l.size:0)+(t.r?t.r.size:0))},Treap.prototype._sizeOf=function(t){return t?t.size:0},Treap.prototype._split=function(t,r){if(t){if(this.cmp(r,t.k)<0){var e=this._split(t.l,r);return t.l=e.r,this._update(t),{l:e.l,r:t}}var e=this._split(t.r,r);return t.r=e.l,this._update(t),{l:t,r:e.r}}return{l:null,r:null}},Treap.prototype._insert=function(t,r){if(!t)return r;if(r.p>t.p){var e=this._split(t,r.k);return r.l=e.l,r.r=e.r,this._update(r),r}return this.cmp(r.k,t.k)<0?t.l=this._insert(t.l,r):t.r=this._insert(t.r,r),this._update(t),t},Treap.prototype.nth=function(t){for(var r=this._root,e=0;r;){if(e=this._sizeOf(r.l),e==t)return{k:r.k,v:r.v};r=e>t?r.l:r.r,t>e&&(t-=e+1)}return null},Treap.prototype._forEach=function(t,r){t.l&&this._forEach(t.l,r),r(t.k,t.v),t.r&&this._forEach(t.r,r)},Treap.prototype.forEach=function(t){this._root&&this._forEach(this._root,t)},Treap.prototype.insert=function(t,r){this._root=this._insert(this._root,new Treap.Node(t,r,Math.random()+Math.random(),null,null))},Treap.prototype._merge=function(t,r){return t?r?t.p>r.p?(t.r=this._merge(t.r,r),this._update(t),t):(r.l=this._merge(t,r.l),this._update(r),r):(this._update(t),t):(this._update(r),r)},Treap.prototype._erase=function(t,r){if(t.k==r){var e=this._merge(t.l,t.r);return this._update(e),e}return this.cmp(r,t.k)<=0&&(t.l?t.l=this._erase(t.l,r):t.r&&(t.r=this._erase(t.r,r))),this._update(t),t},Treap.prototype.erase=function(t){this._root&&(this._root=this._erase(this._root,t))},Treap.prototype._get=function(t,r){return t?0==this.cmp(r,t.k)?t.v:this.cmp(r,t.k)<0?this._get(t.l,r):this._get(t.r,r):void 0},Treap.prototype.get=function(t){return this._root?this._get(this._root,t):void 0},Treap.prototype.set=function(t,r){for(var e=this._root;e;){if(0==this.cmp(t,e.k))return void(e.v=r);e=this.cmp(t,e.k)<0?e.l:e.r}},Treap.prototype.clear=function(){this._root=null},Treap.prototype.size=function(){return this._root?this._root.size:0},Set.prototype.insert=function(t){void 0==this.treap.get(t)&&this.treap.insert(t,1)},Set.prototype.size=function(){return this.treap.size()},Set.prototype.clear=function(){this.treap.clear()},Set.prototype.erase=function(t){this.treap.erase(t)},Set.prototype.count=function(t){return void 0!=this.treap.get(t)},Set.prototype.nth=function(t){return 0>t||t>=this.treap.size()?void 0:this.treap.nth(t).k},Set.prototype.first=function(){return this.nth(0)},Set.prototype.last=function(){return this.nth(this.size()-1)},Set.prototype.forEach=function(t){this.treap.forEach(t)},MultiSet.prototype.insert=function(t){++this._size;var r=this.treap.get(t);void 0==r?this.treap.insert(t,1):this.treap.set(t,r+1)},MultiSet.prototype.size=function(){return this._size},MultiSet.prototype.clear=function(){this._size=0,this.treap.clear()},MultiSet.prototype.erase=function(t){var r=this.treap.get(t);1==r&&this.treap.erase(t),r>1&&this.treap.set(t,r-1),--this._size},MultiSet.prototype.count=function(t){var r=this.treap.get(t);return void 0==r?0:r},MultiSet.prototype.first=function(){return this.treap.nth(0).k},MultiSet.prototype.last=function(){return this.treap.nth(this.treap.size()-1).k},MultiSet.prototype.forEach=function(t){this.treap.forEach(function(r,e){for(var i=0;e>i;++i)t(r)})};\n\nfunction main(cin, cout)\n{\n var n = +cin.next();\n var sum = 0;\n var w = new Array(200100);\n var h = new Array(200100);\n var set = new MultiSet(Math.cmp);\n var tmp;\n for(var i = 0; i < n; ++i)\n {\n w[i] = +cin.next();\n h[i] = +cin.next();\n sum += w[i];\n set.insert(h[i]);\n\n }\n var W, H;\n for(var i = 0; i < n; ++i)\n {\n W = sum - w[i];\n set.erase(h[i]);\n H = set.last();\n set.insert(h[i]);\n cout.print(W*H);\n cout.print(\" \");\n }\n}\n\nvar cin = new Reader();\nvar cout = new Writer(); \n\nmain(cin, cout);\n\ncout.flush();"}, {"source_code": "var n = readline().trim();\n\nvar w = new Array();\nvar h = new Array();\n\nvar wsum = 0;\n\nfor (var i = 0; i < n; i++) {\n var line = readline().trim().split(' ');\n w[i] = line[0];\n h[i] = line[0];\n wsum += w[i];\n}\n\nvar max1 = 0;\nvar max1pos = 0;\nvar max2 = 0;\n\nfor (var i = 0; i < n; i++) {\n if (h[i] > max1) {\n max1 = h[i];\n max1pos = i;\n }\n}\n\nfor (var i = 0; i < n; i++) {\n if ((h[i] > max2) && (i != max1pos)) {\n max2 = h[i];\n }\n}\n\nfor (var i = 0; i < n; i++) {\n var wtot = wsum - w[i];\n var htot = 0;\n if (h[i] == max1) {\n htot = max2;\n } else {\n htot = max1;\n }\n write(htot * wtot);\n write(' ');\n}"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nvar sum = 0;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n sum += lines[i][0];\n}\n\nvar maxI = 0;\nvar prevMaxI = 1;\n\nfor (var i = 1; i < n; i++) {\n\tif (lines[i][1] >= lines[maxI][1])\t{\n\t\tprevMaxI = maxI;\n\t\tmaxI = i;\n\t}\n}\n\n// var copy = lines.slice();\n// copy.sort(function(a, b) {\n// \treturn b[1] - a[1];\n// });\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW;\n \n // arr.forEach( function(wh, i) {\n // if (i == index) {\n // sumW += wh[0];\n // }\n // });\n\n sumW = sum - arr[index][0];\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nvar sum = 0;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n sum += lines[i][0];\n}\n\nvar maxI = 0;\n\nfor (var i = 1; i < n; i++) {\n\tif (lines[i][1] > lines[maxI][1])\t{\n\t\tmaxI = i;\n\t}\n}\n\nvar prevMaxI = maxI === 0 ? 1 : 0;\n\nfor (var i = prevMaxI + 1; i < maxI; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\nfor (var i = maxI + 1; i < n; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\nprint(\"Max: \" + lines[maxI]);\nprint(\"PrevMax: \" + lines[prevMaxI]);\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW;\n \n sumW = sum - arr[index][0];\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n}\n\nlines.sort(function(a, b) {\n\treturn b[1] - a[1];\n});\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW = 0;\n \n arr.forEach( function(wh, i) {\n if (i != index) {\n sumW += wh[0];\n }\n });\n\n var maxH = index === 0 ? arr[1][1] : arr[0][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n}\n\nvar maxI = 0;\nvar prevMaxI = 1;\n\nfor (var i = 1; i < n; i++) {\n\tif (lines[i][1] > lines[maxI][1])\t{\n\t\tprevMaxI = maxI;\n\t\tmaxI = i;\n\t}\n}\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW = 0;\n \n arr.forEach( function(wh, i) {\n if (i != index) {\n sumW += wh[0];\n }\n });\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "var n = readline();\nvar lines = [];\n\nvar tmp;\nvar sum = 0;\nfor (var i = 0; i < n; i++) {\n\t\ttmp = readline().split(' ');\n lines.push([+tmp[0], +tmp[1]]); \n sum += lines[i][0];\n}\n\nvar maxI = 0;\n\nfor (var i = 1; i < n; i++) {\n\tif (lines[i][1] > lines[maxI][1])\t{\n\t\tmaxI = i;\n\t}\n}\n\nvar prevMaxI = 0;\n\nfor (var i = 1; i < maxI; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\nfor (var i = maxI + 1; i < n; i++) {\n\tif (lines[i][1] > lines[prevMaxI][1])\t{\n\t\tprevMaxI = i;\n\t}\n}\n\n\n\nvar output = [];\n\nfor (var i = 0; i < n; i++) {\n output.push(sumPixels(lines, i));\n}\n\nfunction sumPixels(arr, index) {\n var sumW;\n \n sumW = sum - arr[index][0];\n\n var maxH = index === maxI ? arr[prevMaxI][1] : arr[maxI][1];\n \n return maxH * sumW;\n}\n\nprint(output.join(' '));"}, {"source_code": "var n = readline(),\n\tfriends = [],\n\tsizes = [],\n\tsumWidths = 0;\n\n\nfor (var i=0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tfriends.push({width: line[0], height: line[1]});\n\tsumWidths += line[0];\n}\n\nfor (var i = 0; i < n; i++) {\n\tmaxHeight = 0;\n\tfor (var j = 0; j < n; j++) {\n\t\tif (j!=i) {\n\t\t\tif (friends[j].height > maxHeight) {\n\t\t\t\tmaxHeight = friends[j].height;\n\t\t\t}\n\t\t}\n\t}\n\tsizes[i] = maxHeight * (sumWidths - friends[i].width);\n}\n\n\nprint(sizes.join(' '));"}, {"source_code": "var n = readline(),\n\tfriends = [],\n\tsizes = [],\n\tsumWidths = 0,\n\tmaxHeight = {\n\t\tvalue: 0\n\t}\n\tsecondHeight = {\n\t\tvalue: 0\n\t}\n\n\nfor (var i=0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tline[0] = Number(line[0]);\n\tline[1] = Number(line[1]);\n\tfriends[i] = line[0];\n\tsumWidths += line[0];\n\tif (line[1] > maxHeight.value) {\n\t\tsecondHeight.value = maxHeight.value;\n\t\tsecondHeight.id = maxHeight.id;\n\t\tmaxHeight.value = line[1];\n\t\tmaxHeight.id = i;\n\t}\n\tif (line[1] < maxHeight.value && line[1] > secondHeight.value) {\n\t\tsecondHeight.value = line[1];\n\t\tsecondHeight.id = i;\n\t}\n}\n\nfor (var i = 0; i < n; i++) {\n\tif (i != maxHeight.id) {\n\t\tvar height = maxHeight.value;\n\t} else {\n\t\tvar height = secondHeight.value;\n\t}\n\tsizes[i] = height * (sumWidths - friends[i]);\n}\n\n\nprint(sizes.join(' '));"}, {"source_code": "var n = readline(),\n\tfriends = [],\n\tsizes = [],\n\tsumWidths = 0,\n\tmaxHeight = {\n\t\tvalue: 0\n\t}\n\tsecondHeight = {\n\t\tvalue: 0\n\t}\n\n\nfor (var i=0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tline[0] = Number(line[0]);\n\tline[1] = Number(line[1]);\n\tfriends.push({width: line[0], height: line[1]});\n\tsumWidths += line[0];\n\tif (line[1] > maxHeight.value) {\n\t\tsecondHeight.value = maxHeight.value;\n\t\tsecondHeight.id = maxHeight.id;\n\t\tmaxHeight.value = line[1];\n\t\tmaxHeight.id = i;\n\t}\n\tif (line[1] < maxHeight.value && line[1] > secondHeight.value) {\n\t\tsecondHeight.value = line[1];\n\t\tsecondHeight.id = i;\n\t}\n}\n\nfor (var i = 0; i < n; i++) {\n\tif (i != maxHeight.id) {\n\t\tvar height = maxHeight.value;\n\t} else {\n\t\tvar height = secondHeight.value;\n\t}\n\tsizes[i] = height * (sumWidths - friends[i].width);\n}\n\n\nprint(sizes.join(' '));"}, {"source_code": "var n = readline(),\n\tsizes = [],\n\twidths = [],\n\tsumWidths = 0,\n\tmaxHeight = 0;\n\nfor (var i=0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tsumWidths += line[0];\n\twidths[i] = line[0];\n\tif (maxHeight < line[1]) {\n\t\tmaxHeight = line[1];\n\t}\n}\n\nfor (var i = 0; i< n; i++) {\n\tsizes[i] = (sumWidths - widths[i])*maxHeight;\n}\n\nprint(sizes.join(' '));"}, {"source_code": "var n = readline(),\n\tfriends = [],\n\tsizes = [],\n\tsumWidths = 0,\n\tmaxHeight = {\n\t\tvalue: 0\n\t}\n\tsecondHeight = {\n\t\tvalue: 0\n\t}\n\n\nfor (var i=0; i < n; i++) {\n\tvar line = readline().split(' ');\n\tfriends.push({width: line[0], height: line[1]});\n\tsumWidths += line[0];\n\tif (line[1] > maxHeight.value) {\n\t\tsecondHeight.value = maxHeight.value;\n\t\tsecondHeight.id = maxHeight.id;\n\t\tmaxHeight.value = line[1];\n\t\tmaxHeight.id = i;\n\t}\n}\n\nfor (var i = 0; i < n; i++) {\n\tif (i != maxHeight.id) {\n\t\tvar height = maxHeight.value;\n\t} else {\n\t\tvar height = secondHeight.value;\n\t}\n\tsizes[i] = height * (sumWidths - friends[i].width);\n}\n\n\nprint(sizes.join(' '));"}], "src_uid": "e1abc81cea4395ba675cf6ca93261ae8"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const r = Array(n)\n let m = 0\n let sorted = arr.map((x, i) => [x, i])\n for (let i = 0; i < n; i++) {\n sorted.sort((a, b) => b[0] - a[0])\n if (sorted[0][0] === 0) {\n // console.log(r, sorted)\n for (let j = 0; j < sorted.length; j++) {\n r[i++] = arr[sorted[j][1]]\n }\n break\n }\n r[i] = arr[sorted.shift()[1]]\n //\n m |= r[i]\n sorted = sorted.map(([x, i]) => [~m & x, i])\n // console.log(sorted)\n }\n return r.join(' ')\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n a.sort((a, b) => b - a);\r\n const res = [a[0]],\r\n vis = [1];\r\n let pre = res[0];\r\n let N = 30;\r\n while (!(pre & 1 << N)) N--;\r\n for (let i = N; i >= 0; i--) {\r\n if (pre & 1 << i) continue;\r\n let max = -1,\r\n t = -1;\r\n for (let j = 0; j < n; j++) {\r\n if (vis[j] || !(a[j] & 1 << i)) continue;\r\n if (max === -1 || max < (pre | a[j])) {\r\n max = pre | a[j];\r\n t = j;\r\n }\r\n }\r\n if (t !== -1) {\r\n res.push(a[t]);\r\n vis[t] = 1;\r\n pre |= a[t];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (vis[i]) continue;\r\n res.push(a[i]);\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n a.sort((a, b) => b - a);\r\n const res = [a[0]],\r\n vis = [1];\r\n let pre = res[0];\r\n let N = 30;\r\n while (!(pre & 1 << N)) N--;\r\n for (let i = N; i >= 0; i--) {\r\n if (pre & 1 << i) continue;\r\n let max = -1,\r\n t = -1;\r\n for (let j = 0; j < n; j++) {\r\n if (vis[j] || !(a[j] & 1 << i)) continue;\r\n if (max === -1 || max < (pre | a[j])) {\r\n max = pre | a[j];\r\n t = j;\r\n }\r\n }\r\n if (t !== -1) {\r\n res.push(a[t]);\r\n vis[t] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (vis[i]) continue;\r\n res.push(a[i]);\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns(n);\r\n a.sort((a, b) => b - a);\r\n const res = [a[0]],\r\n vis = [1];\r\n let pre = res[0];\r\n let N = 30;\r\n while (!(pre & 1 << N)) N--;\r\n for (let i = N; i >= 0; i--) {\r\n if (pre & 1 << i) continue;\r\n let max = -1,\r\n t = -1;\r\n for (let j = 0; j < n; j++) {\r\n if (vis[j]) continue;\r\n if (max === -1 || max < (pre | a[j])) {\r\n max = pre | a[j];\r\n t = j;\r\n }\r\n }\r\n if (t !== -1) {\r\n res.push(a[t]);\r\n vis[t] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (vis[i]) continue;\r\n res.push(a[i]);\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "64458fc3c2bf40ca911b566092f544e8"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))\n qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)\n v.forEach(v => v.la = v)\n let par = Array(n).fill(-1);\n let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n let dsu = (x, y) => {\n if ((x = root(x)) == (y = root(y))) return;\n if (par[y] < par[x]) [x, y] = [y, x];\n par[x] += par[y];\n par[y] = x;\n v[x].la.ne = v[y];\n v[x].la = v[y].la;\n return v[y];\n }\n // log(e);\n e.forEach(e => {\n if (e.d) return;\n dsu(e.u - 1, e.v - 1);\n })\n // log(par)\n ForR(q, i => {\n if (qe[i].t == 1) {\n qe[i].x = v[root(qe[i].x - 1)];\n qe[i].y = qe[i].x.la;\n } else {\n dsu(e[qe[i].x - 1].u - 1, e[qe[i].x - 1].v - 1)\n }\n })\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n let mark = Array(n);\n let c = 0;\n For(n, i => {\n if (mark[i]) return;\n let x = root(i);\n let cur = v[x];\n while (cur) {\n mark[cur.i] = 1;\n cur.i = c++;\n cur = cur.ne;\n }\n })\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n let v2 = v.slice().sort((v1, v2) => v1.i - v2.i);\n // log(v2.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n let n2 = 1 << Math.ceil(Math.log2(n))\n let it = Array(n2 + n2);\n For(n2, n2 + n2 - 1, i => { it[i] = i - n2 < n ? i - n2 : -1 });\n ForR(n2 - 1, 1, i => {\n let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;\n let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p\n it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];\n })\n\n let query = (l, r) => { //[l, r)\n let res = l;\n for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {\n if (l & 1) { if (v2[res].p < v2[it[l]].p) res = it[l]; l++ }\n if (r & 1) { r--; if (v2[res].p < v2[it[r]].p) res = it[r] }\n }\n return res;\n }\n let update = i => {\n if (v2[i].p == 0) return;\n v2[i].p = 0;\n i = (i + n2) >> 1;\n while (i) {\n let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;\n let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p\n it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];\n i >>= 1;\n }\n }\n qe.forEach(q => {\n if (q.t == 2) return;\n let imax = query(q.x.i, q.y.i + 1);\n // log(q.x.i, q.y.i, imax);\n out.push(v2[imax].p)\n update(imax);\n })\n log(out.join('\\n'))\n}\n", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))\n qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)\n v.forEach(v => v.la = v)\n let par = Array(n).fill(-1);\n let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n let dsu = (x, y) => {\n if ((x = root(x)) == (y = root(y))) return;\n if (par[y] < par[x]) [x, y] = [y, x];\n par[x] += par[y];\n par[y] = x;\n v[x].la.ne = v[y];\n v[x].la = v[y].la;\n }\n // log(e);\n e.forEach(e => e.d ? 0 : dsu(e.u - 1, e.v - 1))\n // log(par)\n qe.forR(q - 1, 0, q => {\n if (q.t == 1) {\n q.x = v[root(q.x - 1)];\n q.y = q.x.la;\n } else {\n dsu(e[q.x - 1].u - 1, e[q.x - 1].v - 1)\n }\n })\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n let v2 = [], c = 0;\n For(n, i => {\n if (v[i].i2 != null) return;\n let cur = v[root(i)];\n while (cur) {\n cur.i2 = c++;\n v2.push(cur);\n cur = cur.ne;\n }\n })\n // log(v2.map(v => ({ i: v.i, p: v.p, i2: v.i2 })))\n let n2 = 1 << Math.ceil(Math.log2(n))\n let it = Array(n2 + n2);\n For(n2, n2 + n2 - 1, i => { it[i] = i - n2 < n ? i - n2 : -1 });\n let update = i => {\n let p1 = it[i << 1] < 0 ? -1 : v2[it[i << 1]].p;\n let p2 = it[i << 1 | 1] < 0 ? -1 : v2[it[i << 1 | 1]].p\n it[i] = p1 >= p2 ? it[i << 1] : it[i << 1 | 1];\n }\n ForR(n2 - 1, 1, i => update(i))\n let query = (l, r) => { //[l, r)\n let res = l;\n for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {\n if (l & 1) { if (v2[res].p < v2[it[l]].p) res = it[l]; l++ }\n if (r & 1) { r--; if (v2[res].p < v2[it[r]].p) res = it[r] }\n }\n return res;\n }\n let set = i => {\n if (v2[i].p == 0) return;\n v2[i].p = 0;\n i = (i + n2) >> 1;\n while (i) (update(i), i >>= 1)\n }\n qe.forEach(q => {\n if (q.t == 2) return;\n let imax = query(q.x.i2, q.y.i2 + 1);\n // log(q.x.i2, q.y.i2, imax);\n out.push(v2[imax].p)\n set(imax);\n })\n log(out.join('\\n'))\n}\n"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))\n qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)\n v.forEach(v => v.la = v)\n let par = Array(n).fill(-1);\n let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n let dsu = (x, y) => {\n if ((x = root(x)) == (y = root(y))) return;\n if (par[y] < par[x]) [x, y] = [y, x];\n par[x] += par[y];\n par[y] = x;\n v[x].la.ne = v[y];\n v[x].la = v[y].la;\n return v[y];\n }\n // log(e);\n e.forEach(e => {\n if (e.d) return;\n dsu(e.u - 1, e.v - 1);\n })\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n e.forR(m - 1, 0, e => {\n if (!e.d) return;\n e.v = dsu(e.u - 1, e.v - 1)\n })\n // log(e)\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n let mark = Array(n);\n let c = 0;\n For(n, i => {\n if (mark[i]) return;\n let x = root(i);\n let cur = v[x];\n while (cur) {\n mark[cur.i] = 1;\n cur.i = c++;\n cur = cur.ne;\n }\n })\n // log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n v2 = v.slice().sort((v1, v2) => v1.i - v2.i);\n let np = Array(n)\n // log(v.map(v => ({ i: v.i, p: v.p })))\n let st = 0\n v2.cut(v => !v.ne).forEach(a => {\n For(a.length, i => { np[st + i] = new Node(st + i, st + a.length - 1, st) })\n st += a.length;\n })\n // log(np)\n let t = new SplayTree().load(np);\n // t.print()\n qe.forEach(q => {\n if (q.t == 1) {\n let key = v[q.x - 1].i;\n t.splayKey(key);\n let imin = t.root.imin;\n let imax = t.root.imax;\n t.splayKey(imin); let leftNode = t.root.left; t.root.left = undefined; t.root.update();\n t.splayKey(imax); let rightNode = t.root.right; t.root.right = undefined; t.root.update();\n // log(imin, imax, t.root.keymax)\n // log(v2[t.root.keymax].p);\n out.push(v2[t.root.keymax].p)\n if (v2[t.root.keymax].p) {\n v2[t.root.keymax].p = 0;\n t.update(t.root.keymax);\n }\n // t.print()\n t.root.right = rightNode; t.root.update();\n // t.print()\n t.splayKey(imin); t.root.left = leftNode; t.root.update();\n // t.print()\n } else {\n if (!e[q.x - 1].v) return;\n let x = e[q.x - 1].v.i - 1;\n t.splayKey(x);\n let imin = t.root.imin;\n let imax = t.root.imax;\n // log(x, imin, imax);\n t.splayKey(imin); let leftNode = t.root.left; t.root.left = undefined; t.root.update();\n t.splayKey(imax); let rightNode = t.root.right; t.root.right = undefined; t.root.update();\n t.splayKey(x);\n t.root.right.lzimin = x + 1;\n t.root.imax = x;\n if (t.root.left) t.root.left.lzimax = x;\n t.splayKey(imax); t.root.right = rightNode; t.root.update();\n t.splayKey(imin); t.root.left = leftNode; t.root.update();\n // t.print()\n }\n })\n log(out.join('\\n'))\n // log(out.length)\n}\nvar v2;\n\nclass Node {\n left; right; key; keymax; imax; imin; lzimax; lzimin; iimax; iimin;\n constructor(key, imax, imin) {\n this.key = key;\n this.keymax = key;\n this.imax = imax;\n this.imin = imin;\n this.iimax = imax;\n this.iimin = imin;\n }\n update() {\n this.keymax = this.key;\n this.iimax = this.imax;\n this.iimin = this.imin;\n if (this.left) {\n if (v2[this.left.keymax].p > v2[this.keymax].p) this.keymax = this.left.keymax;\n if (this.left.iimax > this.iimax) this.iimax = this.left.iimax;\n if (this.left.iimin < this.iimin) this.iimin = this.left.iimin;\n }\n if (this.right) {\n if (v2[this.right.keymax].p > v2[this.keymax].p) this.keymax = this.right.keymax;\n if (this.right.iimax > this.iimax) this.iimax = this.right.iimax;\n if (this.right.iimin < this.iimin) this.iimin = this.right.iimin;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.keymax},${this.imin},${this.imax},${this.iimin},${this.iimax})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n return this;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n lazy(trace) {\n trace.forEach(node => {\n if (node.lzimax != undefined) {\n node.imax = node.lzimax;\n if (node.left) node.left.lzimax = node.lzimax;\n if (node.right) node.right.lzimax = node.lzimax;\n node.lzimax = undefined;\n }\n if (node.lzimin != undefined) {\n node.imin = node.lzimin;\n if (node.left) node.left.lzimin = node.lzimin;\n if (node.right) node.right.lzimin = node.lzimin;\n node.lzimin = undefined;\n }\n })\n }\n\n splay(trace) {\n this.lazy(trace)\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key, imax, imin) {\n if (!this.root) return this.root = new Node(key, imax, imin);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key, imax, imin));\n else trace.push(cur.right = new Node(key, imax, imin));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n splayKey(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n }\n\n update(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.lazy(trace)\n trace.reverse().forEach(node => node.update())\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n return this;\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let [n, m, q] = $(3), v = Arr(n, i => ({ i, p: $() })), e = Arr(m, i => ({ u: $(), v: $() })), qe = Arr(q, i => ({ t: $(), x: $() }))\n qe.forEach(q => q.t == 2 ? e[q.x - 1].d = 1 : 0)\n v.forEach(v => v.fi = v.la = v)\n let par = Array(n).fill(-1);\n let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n let merge = (x, y) => {\n if ((x = root(x)) == (y = root(y))) return;\n if (par[y] < par[x]) [x, y] = [y, x];\n par[x] += par[y];\n par[y] = x;\n v[x].la.ne = v[y];\n v[x].la = v[y].fi\n }\n e.forEach(e => {\n if (e.d) return;\n merge(e.u - 1, e.v - 1);\n })\n log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n e.forR(m - 1, 0, e => {\n if (!e.d) return;\n merge(e.u - 1, e.v - 1);\n })\n log(v.map(v => ({ i: v.i, p: v.p, ne: (v.ne || {}).i })))\n}\n"}], "src_uid": "ad014bde729222db14f38caa521e4167"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar x = one[0];\n\t\tvar y = one[1];\n\t\tvar z = one[2];\n\t\tif(x == z && x != y && y != z){\n\t\t\tif(y < x){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\tvar a = x;\n\t\t\t\toutput.push(y + \" \" + x + \" \" + y);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t\t\n\t\t}else if(x == y && y == z && z == x){\n\t\t\toutput.push(\"YES\");\n\t\t\toutput.push(x + \" \" + x + \" \" + x);\n\t\t}else if(x != y && x != z && y == z){\n\t\t\tif(x < y){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\toutput.push(x + \" \" + x + \" \" + z);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t}else if(x == y && x != z && y != z){\n\t\t\tif(x > z){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\toutput.push(x + \" \" + z + \" \" + z);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t}else{\n\t\t\toutput.push(\"NO\");\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar lineCount = 0\nvar testCount = 0\nvar outputStr = ''\n\nrl.on('line', (input) => {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if (lineCount >= testCount) {\n outputStr += getWinner(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += getWinner(input) + '\\n'\n }\n lineCount++\n});\n\nfunction getWinner(str) {\n var list = str.split(' ')\n var x = list[0]\n var y = list[1]\n var z = list[2]\n\n var max = Math.max(x, y, z)\n var min = Math.min(x, y, z)\n\n var maxcount= 0, mincount = 0\n if(x==max){\n maxcount+=1\n }\n if(y==max){\n maxcount+=1\n }\n if(z==max){\n maxcount+=1\n }\n\n if(maxcount<2){\n return 'NO'\n }\n\n else{\n return `YES\n${max} ${min} ${min}`\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = Number(readLine())\n for (let i = 0; i < t; i++) {\n const [x, y, z] = readLine().split(/\\s/).map(Number).sort((a, b) => b - a)\n if (x !== y) {\n console.log('NO')\n continue\n }\n console.log('YES')\n console.log(`${x} ${z} ${z}`)\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testcases = parseInt(readline());\n\tfor (let i = 0; i < testcases; i++) {\n\t\tconst [x,y,z] = readline().split(' ').map(i => parseInt(i));\n\t\tlet e = false\n\t\tif (x == y && x == z && y == z) {\n\t\t\te = true\n\t\t\tconsole.log('YES')\n\t\t\tconsole.log(x,y,z)\n\t\t}\n\t\tif (x == y && z < x) {\n\t\t\te = true\n\t\t\tconsole.log('YES')\n\t\t\tconsole.log(x,z,1)\n\t\t}\n\t\tif (x == z && y < x) {\n\t\t\te = true\n\t\t\tconsole.log('YES')\n\t\t\tconsole.log(x,y,1)\n\t\t}\n\t\tif (y == z && x < z) {\n\t\t\te = true\n\t\t\tconsole.log('YES')\n\t\t\tconsole.log(y,x,1)\n\t\t}\n\t\tif(!e) {\n\t\t\tconsole.log('NO')\n\t\t}\n\t}\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc++]\n for (let i=0; i +x).sort((a, b) => b - a)\n\n\n let unequal = 0\n if (x !== y) {\n unequal++\n }\n\n if (unequal) {\n console.log('NO')\n } else {\n console.log('YES')\n console.log(x, z, z)\n }\n }\n\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "function solve() {\n var arr = readArray(Number);\n arr.sort(sortF);\n if (arr[1] !== arr[2]) {\n write('NO');\n return;\n }\n arr[1] = arr[0];\n write('YES');\n write(arr.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\n\nfunction functions() {\n rl.question('', function (input) {\n var n = input.split(' ');\n var x = parseInt(n[0]);\n var y = parseInt(n[1]);\n var z = parseInt(n[2]);\n var a, b, c, bool = false;\n if (x == y && y >= z) {\n bool = true;\n a = x;\n b = z;\n c = 1;\n } else if (x == z && z >= y) {\n bool = true;\n b = x;\n a = y;\n c = 1;\n } else if (y == z && z >= x) {\n bool = true;\n c = y;\n b = x;\n a = 1;\n } else if (x == y && y == z) {\n bool = true;\n a = b = c = x;\n }\n if (bool) {\n console.log('yes')\n console.log(a, b, c)\n } else {\n console.log('no')\n }\n // console.log(x == y, x > z, z, y > 2)\n functions();\n })\n}\n// function functions() {\n// rl.question(\"\", function (n) {\n// rl.question(\"\", function (num) {\n// var arr = num.split(' ');\n// var l = [];\n// for (var i = 0; i < n * 2; i++) {\n// for (var j = 0; j < arr.length; j++) {\n// var lhas = l.includes(arr[j])\n// if (!lhas) {\n// l.push(arr[j]);\n//\n// }\n// }\n// }\n// console.log(l.join(' '));\n// functions();\n// });\n// })\n// }\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.sort((a, b) => a - b);\n const [x, y, z] = arr;\n\n if (y !== z) console.log(\"NO\");\n else {\n console.log(\"YES\");\n console.log(`${x} ${x} ${z}`);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 1;\n\tlet i = 1;\n\twhile (i <= testCases) {\n let n = data[i].trim().split(' ');\n let x = n[0] * 1;\n let y = n[1] * 1;\n let z = n[2] * 1;\n let max = Math.max(x, y, z);\n let min = Math.min(x, y, z);\n if (x === y && x === z) {\n console.log('YES');\n console.log(x+' '+y+' '+z);\n i += 1;\n continue;\n }\n if ((x != max && y != max) || (x != max && z != max) || (y != max && z != max) || (x != y && y != z && x != z)) {\n console.log('NO');\n i += 1;\n continue;\n }\n if ((x == max && y == max) || (x == max && z == max) || (y == max && z == max)) {\n console.log('YES');\n console.log(max+' '+min+' '+min);\n i += 1;\n continue;\n }\n if (x === 1 || y === 1 || z === 1) {\n console.log('NO');\n i += 1;\n continue;\n }\n\t}\n}"}], "negative_code": [{"source_code": "function solve() {\n var arr = readArray(Number);\n arr.sort(sortF);\n if (arr[1] !== arr[2]) {\n write('NO');\n return;\n }\n write('YES');\n write(arr.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\n\nfunction functions() {\n rl.question('', function (input) {\n var n = input.split(' ');\n var l = []\n var x = n[0];\n var y = n[1];\n var z = n[2];\n var a, b, c, bool;\n bool = 'yes';\n if (x == y && y > z) {\n a = x;\n b = z;\n c = 1;\n } else if (x == z && z > y) {\n b = x;\n a = y;\n c = 1;\n } else if (y == z && z > x) {\n c = y;\n b = x;\n a = 1;\n } else if (x == y && y == z) {\n a = b = c = x;\n } else {\n bool = 'no';\n }\n if (bool == 'yes') {\n console.log(bool)\n console.log(a, b, c)\n } else {\n console.log(bool)\n }\n functions();\n })\n}\n// function functions() {\n// rl.question(\"\", function (n) {\n// rl.question(\"\", function (num) {\n// var arr = num.split(' ');\n// var l = [];\n// for (var i = 0; i < n * 2; i++) {\n// for (var j = 0; j < arr.length; j++) {\n// var lhas = l.includes(arr[j])\n// if (!lhas) {\n// l.push(arr[j]);\n//\n// }\n// }\n// }\n// console.log(l.join(' '));\n// functions();\n// });\n// })\n// }\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (Math.max(a, b) === c) {\n console.log(\"YES\");\n console.log(`${a} ${b} ${c}`);\n } else console.log(\"NO\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n if (Math.max(a, b) === c) {\n console.log(\"YES\");\n console.log(`${1} ${a} ${b}`);\n } else console.log(\"NO\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [x, y, z] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const [a, b, c] = [1, x, y];\n if (Math.max(a, b) === x && Math.max(a, c) === y && Math.max(b, c) === z) {\n console.log(\"YES\");\n console.log(`${a} ${b} ${c}`);\n } else console.log(\"NO\");\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.sort((a, b) => a - b);\n const [x, y, z] = arr;\n\n if (y !== z) console.log(\"NO\");\n else {\n console.log(\"YES\");\n console.log(`${x} ${x} ${z}`);\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar x = one[0];\n\t\tvar y = one[1];\n\t\tvar z = one[2];\n\t\tif(x == z && x != y && y != z){\n\t\t\tif(y < x){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\tvar a = x;\n\t\t\t\toutput.push(y + \" \" + x + \" \" + y);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t\t\n\t\t}else if(x == y && y == z && z == x){\n\t\t\toutput.push(\"YES\");\n\t\t\toutput.push(x + \" \" + x + \" \" + x);\n\t\t}else if(x != y && x != z && y == z){\n\t\t\tif(x < y){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\toutput.push(x + \" \" + y + \" \" + z);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t}else if(x == y && x != z && y != z){\n\t\t\tif(x > z){\n\t\t\t\toutput.push(\"YES\");\n\t\t\t\toutput.push(x + \" \" + z + \" \" + z);\n\t\t\t}else{\n\t\t\t\toutput.push(\"NO\");\n\t\t\t}\n\t\t}else{\n\t\t\toutput.push(\"NO\");\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}], "src_uid": "f4804780d9c63167746132c35b2bdd02"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let [n,a,b,da,db] = ti(readline().split(' '));\n\n let adj = new Array(n);\n for(let i = 0; i < n; i++)\n adj[i] = [];\n \n for(let i = 0; i < n-1; i++){\n let [u,v] = ti(readline().split(' '));\n adj[u-1].push(v-1);\n adj[v-1].push(u-1);\n }\n\n let dist = new Array(n);\n let bfs = (st, n) => {\n let q = [st,null];\n let level = 0;\n let v = new Array(n);\n v.fill(false);\n dist.fill(-1);\n while(q.length > 0){\n let node = q.shift();\n if(node !== null){\n v[node] = true;\n dist[node] = level;\n for(let i = 0; i < adj[node].length; i++){\n if(!v[adj[node][i]])\n q.push(adj[node][i]);\n }\n }else{\n level += 1;\n if(q.length > 0)\n q.push(null);\n }\n }\n }\n\n let farthest = (dist) => {\n let max = -1;\n let ans = -1;\n for(let i = 0; i < dist.length; i++){\n if(dist[i] > max){\n max = dist[i];\n ans = i;\n }\n }\n\n return ans;\n }\n\n bfs(a-1, n);\n if(dist[b-1] <= da){\n console.log('Alice');\n continue;\n }\n let f = farthest(dist);\n bfs(f, n);\n let ff = farthest(dist);\n let diameter = dist[ff];\n\n if(da*2 >= db){\n console.log('Alice');\n continue;\n }\n\n if(diameter <= da*2){\n console.log('Alice');\n continue;\n }\n\n console.log('Bob');\n }\n}", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return mid;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let [n, a, b, da, db] = $(5)\n let e = Arr(n + 1, i => [])\n let u, v\n For(n - 1, i => {\n u = $(), v = $()\n e[u].push(v)\n e[v].push(u)\n })\n // log(e)\n if (da >= db / 2) { log('Alice'); continue }\n\n let t = 1;\n let mark = Array(n + 1).fill(0)\n let dfs = async (u, d) => {\n if (t++ % 1000 == 0) await Promise.resolve();\n if (mark[u]) return;\n mark[u] = d;\n for (let v of e[u]) await dfs(v, d + 1);\n }\n await dfs(a, 1)\n // log(mark)\n if (da >= mark[b] - 1) { log('Alice'); continue }\n let idm = mark.max()[1];\n mark.fill(0)\n await dfs(idm, 1);\n // log(mark)\n if (da >= (mark.max()[0] - 1) / 2) { log('Alice'); continue }\n log('Bob')\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let [n,a,b,da,db] = ti(readline().split(' '));\n\n let adj = new Array(n);\n for(let i = 0; i < n; i++)\n adj[i] = [];\n \n for(let i = 0; i < n-1; i++){\n let [u,v] = ti(readline().split(' '));\n adj[u-1].push(v-1);\n adj[v-1].push(u-1);\n }\n\n let queue = [a-1, null];\n let visited = new Array(n);\n visited.fill(false);\n let dab = 0;\n while(queue.length > 0){\n let node = queue.shift();\n if(node !== null){\n visited[node] = true;\n if(node === b-1)\n break;\n\n for(let i = 0; i < adj[node].length; i++){\n if(!visited[adj[node][i]])\n queue.push(adj[node][i]);\n }\n }else{\n dab += 1;\n if(queue.length > 0)\n queue.push(null);\n }\n }\n\n if(dab <= da){\n console.log('Alice');\n continue;\n }\n\n let bfs = (st, n, en) => {\n let q = [st,null];\n let level = 0;\n let v = new Array(n);\n v.fill(false);\n while(q.length > 0){\n let node = q.shift();\n if(node !== null){\n v[node] = true;\n en.val = node;\n for(let i = 0; i < adj[node].length; i++){\n if(!v[adj[node][i]])\n q.push(adj[node][i]);\n }\n }else{\n level += 1;\n if(q.length > 0)\n q.push(null);\n }\n }\n\n return level;\n }\n\n let en = {val: -1};\n bfs(a-1, n, en);\n let diameter = bfs(en.val, n, -1);\n\n if(da >= Math.ceil(diameter/2)){\n console.log('Alice');\n continue;\n }\n\n if(da >= Math.ceil(db/2)){\n console.log('Alice');\n continue;\n }\n\n console.log('Bob');\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let [n,a,b,da,db] = ti(readline().split(' '));\n\n let adj = new Array(n);\n for(let i = 0; i < n; i++)\n adj[i] = [];\n \n for(let i = 0; i < n-1; i++){\n let [u,v] = ti(readline().split(' '));\n adj[u-1].push(v-1);\n adj[v-1].push(u-1);\n }\n\n let queue = [a-1, null];\n let visited = new Array(n);\n visited.fill(false);\n let dab = 0;\n while(queue.length > 0){\n let node = queue.shift();\n if(node !== null){\n visited[node] = true;\n if(node === b-1)\n break;\n\n for(let i = 0; i < adj[node].length; i++){\n if(!visited[adj[node][i]])\n queue.push(adj[node][i]);\n }\n }else{\n dab += 1;\n if(queue.length > 0)\n queue.push(null);\n }\n }\n\n if(dab <= da){\n console.log('Alice');\n continue;\n }\n\n let bfs = (st, n, en) => {\n let q = [st,null];\n let level = 0;\n let v = new Array(n);\n v.fill(false);\n while(q.length > 0){\n let node = q.shift();\n if(node !== null){\n v[node] = true;\n en.val = node;\n for(let i = 0; i < adj[node].length; i++){\n if(!v[adj[node][i]])\n q.push(adj[node][i]);\n }\n }else{\n level += 1;\n if(q.length > 0)\n q.push(null);\n }\n }\n\n return level;\n }\n\n let en = {val: -1};\n bfs(a-1, n, en);\n let diameter = bfs(en.val, n, -1);\n\n if(da*2 >= db){\n console.log('Alice');\n continue;\n }\n\n if(diameter <= da*2){\n console.log('Alice');\n continue;\n }\n\n console.log('Bob');\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n\n let t = pi(readline());\n\n while(t > 0){\n t--;\n let [n,a,b,da,db] = ti(readline().split(' '));\n\n let adj = new Array(n);\n for(let i = 0; i < n; i++)\n adj[i] = [];\n \n for(let i = 0; i < n-1; i++){\n let [u,v] = ti(readline().split(' '));\n adj[u-1].push(v-1);\n adj[v-1].push(u-1);\n }\n\n let queue = [a-1, null];\n let visited = new Array(n);\n visited.fill(false);\n let dab = 0;\n while(queue.length > 0){\n let node = queue.shift();\n if(node !== null){\n visited[node] = true;\n if(node === b-1)\n break;\n\n for(let i = 0; i < adj[node].length; i++){\n if(!visited[adj[node][i]])\n queue.push(adj[node][i]);\n }\n }else{\n dab += 1;\n if(queue.length > 0)\n queue.push(null);\n }\n }\n\n if(dab <= da){\n console.log('Alice');\n continue;\n }\n\n let bfs = (st, n, en) => {\n let q = [st,null];\n let level = 0;\n let v = new Array(n);\n v.fill(false);\n while(q.length > 0){\n let node = q.shift();\n if(node !== null){\n v[node] = true;\n en.val = node;\n for(let i = 0; i < adj[node].length; i++){\n if(!v[adj[node][i]])\n q.push(adj[node][i]);\n }\n }else{\n level += 1;\n if(q.length > 0)\n q.push(null);\n }\n }\n\n return level;\n }\n\n let en = {val: -1};\n bfs(a-1, n, en);\n let diameter = bfs(en.val, n, {val: -1});\n\n if(da*2 >= db){\n console.log('Alice');\n continue;\n }\n\n if(diameter <= da*2){\n console.log('Alice');\n continue;\n }\n\n console.log('Bob');\n }\n}"}], "src_uid": "2bfd566ef883efec5211b01552b45218"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t){\n t--;\n let n = pi(readline());\n let res = '';\n for(let i = 1; i <= n; i++){\n if(i !== n){\n res += ` ${i+1}`;\n }else{\n res += ` ${1}`;\n }\n }\n\n console.log(res.trim());\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = readline().split(' ');\n let a = new Array(n);\n let max = 0;\n for(let i = 0; i < n; i++)\n max = Math.max(max, pi(x[i]));\n let map = new Array(max+2);\n let rMap = new Array(max+2);\n\n for(let i = 0; i < n; i++){\n a[i] = pi(x[i]);\n if(map[a[i]] !== undefined){\n map[a[i]] += 1;\n rMap[a[i]] = i;\n }else{\n map[a[i]] = 1;\n rMap[a[i]] = i;\n }\n }\n\n let min = 99999999999;\n for(let i = 0; i < a.length; i++){\n if(map[a[i]] === 1){\n min = Math.min(min, a[i]);\n }\n }\n\n console.log(min === 99999999999 ? -1 : rMap[min]+1);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let map = new Array(200005);\n //map.fill(0);\n for(let i = 0; i < n; i++){\n if(i === 0){\n map[a[i]] = 1;\n continue;\n }\n\n if(a[i] !== a[i-1]){\n if(map[a[i]] !== undefined){\n map[a[i]] += 1;\n }else{\n map[a[i]] = 1;\n }\n } \n }\n\n let min = 99999999;\n for(let i = 0; i < n; i++){\n if(map[a[i]] !== undefined){\n if(a[i] === a[0] && a[i] === a[n-1]){\n min = Math.min(min, map[a[i]]-1);\n }else if(a[i] === a[0] || a[i] === a[n-1]){\n min = Math.min(min, map[a[i]]);\n }else{\n min = Math.min(min, map[a[i]]+1);\n }\n }\n }\n\n console.log(min === 99999999 ? 0 : min);\n }\n}\n\nlet getFactors = (n) => {\n let i = 2;\n let res = [];\n while(i*i <= n){\n if(n%i === 0)\n res.push([i,n/i]);\n i++;\n }\n return res;\n}\n\nfunction D(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let dp = new Array(Math.floor(n+1));\n dp.fill(1);\n\n for(let i = 0; i < dp.length; i++){\n let f = getFactors(i);\n if(f.length !== 0){\n for(let j = 0; j < f.length; j++){\n if(f[j][1] % f[j][0] === 0)\n dp[i] = Math.max(dp[i], dp[f[j][0]]+dp[f[j][1]]);\n }\n }\n }\n \n let f = getFactors(n);\n let max = 1;\n if(f.length > 0){\n for(let i = 0; i < f.length; i++){\n if(f[i][1] % f[i][0] === 0)\n max = Math.max(max, dp[f[i][0]]+dp[f[i][1]]);\n }\n }\n console.log(max);\n }\n}", "positive_code": [{"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var arr = readline().split(' ').map(i => +i);\n var tmp = {};\n var idx = -1;\n\n arr.forEach(item => {\n if (tmp[item] === undefined) {\n tmp[item] = 0;\n }\n tmp[item]++; \n });\n \n for (var k in tmp) {\n if (tmp[k] == 1) {\n idx = arr.indexOf(+k) + 1;\n break;\n }\n }\n \n print(idx || -1);\n}\n"}, {"source_code": "const solve = (n, game) => {\n let map = getRecord2(game);\n let u = game.filter(x => map.get(x) == 1);\n let min = Math.min.apply(Math, u);\n for (let i = 0; i < n; i++) {\n if (game[i] == min && map.get(game[i]) == 1) {\n console.log(i + 1);\n return;\n }\n }\n console.log(-1);\n};\n\nconst getRecord2 = (arr) => {\n let map = new Map();\n for (const i of arr) {\n map.set(i, (map.get(i) + 1) || 1);\n }\n return map;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n for (let i = 1; t--; i += 2) {\n solve(input[i], input[i + 1]);\n }\n });\n};\n\nmain()"}, {"source_code": "const solve = (n, game) => {\n let map = getRecord2(game);\n let u = game.filter(x => map.get(x) == 1);\n let min = Math.min.apply(Math, u);\n for (let i = 0; i < n; i++) {\n if (game[i] == min && map.get(game[i]) == 1) {\n console.log(i + 1);\n return;\n }\n }\n console.log(-1);\n};\n\nconst getRecord2 = (arr) => {\n let map = new Map();\n for (const i of arr) {\n map.set(i, (map.get(i) + 1) || 1);\n }\n return map;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 2);\n solve(data[0][0], data[1]);\n t--;\n i += 2;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n const map = new Map();\n\n for (let i = 0; i < len; i++) {\n const n = arr[i];\n if (map.get(n)) {\n map.get(n).count++;\n } else {\n map.set(n, { count: 1, index: i + 1 });\n }\n }\n let [minVal, min] = [Infinity, Infinity];\n for (let [key, obj] of map) {\n const { count, index } = obj;\n if (count === 1 && key < minVal) {\n minVal = key;\n min = index;\n }\n }\n if (min === Infinity) {\n console.log(-1);\n } else {\n console.log(min);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){\n\tvar tmp = input.split(' ');\n\tfor(var i = 0; i < tmp.length; i++){\n\t\tinLine.push(tmp[i]);\n\t}\n});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextArray(size, code){\n\tvar ret = new Array(size);\n\tfor(var i = 0; i < size; i++){\n\t\tif(code == 'int'){\n\t\t\tret[i] = nextInt();\n\t\t}else{\n\t\t\tret[i] = next();\n\t\t}\n\t}\n\treturn ret;\n}\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\nfunction nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray(N);\n\t\tvar map = {};\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(map[list[j]] == null){\n\t\t\t\tmap[list[j]] = [];\n\t\t\t}\n\t\t\tmap[list[j]].push(j);\n\t\t}\n\t\tvar key = Object.keys(map);\n\t\tkey.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t});\n\t\tvar ans = -1;\n\t\tfor(var j = 0; j < key.length; j++){\n\t\t\tif(map[key[j]].length == 1){\n\t\t\t\tans = map[key[j]][0] + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\toutput[i] = ans;\n\t}\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n const s = data[i + 1].trim().split(' ');\n // let a = data[i].trim() * 1;\n // const n = data[i] * 1;\n // const p = BigInt(s[0]);\n // const q = BigInt(s[1]);\n // s.sort((a, b) => b - a);\n let obj = {};\n // console.log(p%q)\n // let first = true;\n for (let j = 0; j < s.length; j += 1) {\n if (obj[s[j]]) obj[s[j]] = -1;\n else {\n obj[s[j]] = {};\n obj[s[j]]['count'] = 1;\n obj[s[j]]['index'] = j + 1;\n }\n }\n let idx = -1;\n for (let key in obj) {\n if (obj[key]['count'] > 0) {idx = obj[key]['index']; break;}\n }\n // let j = n;\n console.log(idx);\n i += 2;\n }\n}"}, {"source_code": "\"use strict\";\n\n(() => {\n\n const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \n let curLine = 0, allLines = [];\n\n let nextLine = () => {\n if(curLine == allLines.length) throw new ReferenceError(\"No more input in the buffer\");\n return allLines[curLine++]\n };\n \n readline.on(\"line\", line => { allLines.push(line); });\n readline.on(\"close\", () => { main(nextLine) });\n\n})();\n\nfunction main(nextLine) {\n let t = Number(nextLine());\n\n while(t--) {\n let n = Number(nextLine());\n let ara = nextLine().split(\" \").map((x, index) => [Number(x), index+1]);\n\n ara.sort((a, b) => a[0]-b[0]);\n\n let mn = -1;\n for(let i = 0; i < n; i++) {\n if((i === 0 || ara[i][0] !== ara[i-1][0]) && (i === n-1 || ara[i][0] !== ara[i+1][0])) {\n mn = ara[i][1];\n break;\n }\n }\n\n console.log(mn);\n }\n}"}, {"source_code": "/* this language fucking sucks */\n\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lines = [];\n\nrl.on('line', (data) => {\n lines.push(data);\n if(lines.length > 0 && 2 * parseInt(lines[0]) === lines.length - 1) {\n\trl.close();\n\tmain();\n }\n});\n\nasync function main() {\n let t = parseInt(lines[0]);\n for(let i = 1; i <= 2 * t; i += 2) {\n\tlet n = parseInt(lines[i]);\n\tconst arr = lines[i + 1].split(' ').map(x => parseInt(x));\n\n\tlet dict = {};\n\tfor(const v of arr) {\n\t if(!dict.hasOwnProperty(v)) {\n\t\tdict[v] = 1;\n\t }\n\t else {\n\t\tdict[v]++;\n\t }\n\t}\n\n\tlet num = -1;\n\tfor(let j = 1; j <= n; j++) {\n\t if(dict[j] === 1) {\n\t\tnum = j;\n\t\tbreak;\n\t }\n\t}\n\n\tlet ok = false;\n\tfor(let j = 0; j < n; j++) {\n\t if(arr[j] === num) {\n\t\tconsole.log(j + 1);\n\t\tok = true;\n\t }\n\t}\n\n\tif(!ok) {\n\t console.log(-1);\n\t}\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let cnt: any = {}\n// \n// for (let i = 0; i < n; ++i) {\n// let x = a[i]\n// cnt[x] = { val: cnt[x] == undefined ? 1 : cnt[x].val + 1, ndx: i }\n// }\n// \n// // io.debug(cnt)\n// \n// a.sortAsc()\n// \n// for (let x of a) {\n// if (cnt[x].val == 1) {\n// io.puts(cnt[x].ndx + 1)\n// return\n// }\n// }\n// \n// io.puts(-1)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let cnt: any = {}\n// \n// for (let i = 0; i < n; ++i) {\n// let x = a[i]\n// cnt[x] = { val: cnt[x] == undefined ? 1 : cnt[x].val + 1, ndx: i }\n// }\n// \n// // io.debug(cnt)\n// \n// a.sort()\n// \n// for (let x of a) {\n// if (cnt[x].val == 1) {\n// io.puts(cnt[x].ndx + 1)\n// return\n// }\n// }\n// \n// io.puts(-1)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "var t = +readline();\n\nfor (var i = 0; i < t; i++) {\n var l = +readline();\n var arr = readline().split(' ').map(i => +i);\n var tmp = {};\n var idx;\n\n arr.forEach(item => {\n if (tmp[item] === undefined) {\n tmp[item] = 0;\n }\n tmp[item]++; \n });\n \n for (var k in tmp) {\n idx = arr.indexOf(tmp[k]) + 1;\n break;\n }\n \n print(idx || -1);\n}\n"}], "src_uid": "99d2b0386d101da802ac508ef8f7325b"} {"source_code": "'use strict'\n \nconst k = parseInt(readline().split(' ')[1]);\n \nconst res = readline().split(' ').reduce((r, i) => {\n if (r.indexOf(i) === -1) {\n if (r.length === k) r.pop();\n r.unshift(i);\n }\n return r;\n}, []);\n \nwrite(res.length + '\\n' + res.join(' '));", "positive_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr.shift().split(' ')\n messages[messages.length - 1] = parseInt(messages[messages.length - 1])\n\n let map = {}\n let current = 0, left = 1, right = 0\n let reverseMap = {}\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n if(current == k){\n delete map[reverseMap[left]]\n reverseMap[left ++] = null\n }\n else{\n current ++\n }\n map[m] = ++ right\n reverseMap[right] = m\n // console.log(m, map, reverseMap, left, right, current)\n }\n }\n // if(k == 3) console.log(map, reverseMap) \n\n console.log(current)\n \n for(let i = right; i >= left; i --){\n process.stdout.write(reverseMap[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar STATE = 1;\nvar n, k, params, ids, item;\nrl.on('line', function (input) {\n switch (STATE) {\n case 1:\n params = input.split(' ');\n n = parseInt(params[0], 10);\n k = parseInt(params[1], 10);\n STATE = 2;\n break;\n case 2:\n params = input.split(' ');\n ids = new Array()\n for (var i = 0; i < n; i++) {\n item = params[i];\n if (!ids.includes(item)) {\n ids.push(item)\n }\n if (ids.length > k) {\n ids.shift()\n }\n }\n console.log(ids.length);\n console.log(ids.reverse().join(' '));\n STATE = 1;\n break;\n default:\n // code\n }\n}).on('close', function() {\n process.exit(0);\n});"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr.shift().split(' ')\n messages[messages.length - 1] = parseInt(messages[messages.length - 1])\n\n let map = {}\n let current = 0\n let q = []\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n q.unshift(m)\n if(current == k) map[q.pop()] = false\n else{\n current ++\n }\n map[m] = true\n }\n }\n // if(k == 4) console.log(map, q)\n\n console.log(q.length)\n for(let i = 0, len = q.length; i < len; i++) {\n process.stdout.write(q[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, k) {\n let result = data.reduce((acc, value) => {\n if (~acc.indexOf(value)) return acc;\n else if (acc.length < k) {\n acc.unshift(value)\n } else {\n acc.pop();\n acc.unshift(value);\n }\n return acc;\n }, [])\n\n return result;\n\n\n }\n\n let k = lines[0].split(\" \").map(Number)[1];\n let data = lines[1].split(\" \").map(Number);\n\n let result = foo(data, k);\n let answer = '';\n answer += result.length + \"\\n\";\n answer += result.join(\" \")\n console.log(answer);\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const firstLine = readline().split(\" \");\n const n = parseInt(firstLine[0]);\n const k = parseInt(firstLine[1]);\n const ids = readline().split(\" \").map((value,index,array)=>{return parseInt(value)});\n\n let screen = [];\n for(let i = 0;i{output += element +\" \";});\n console.log(output);\n}"}, {"source_code": "'use strict'\n \nconst k = parseInt(readline().split(' ')[1]);\nconst d = {};\nlet r = [];\n\nreadline().split(' ').forEach((i) => {\n if (d[i]) return;\n if (r.length >= k) d[r[r.length - k]] = undefined;\n r.push(i);\n d[i] = true;\n});\nr = r.slice(-k);\nwrite(r.length + '\\n' + r.reverse().join(' '));"}, {"source_code": "var stats = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n\nvar messages = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n// var stats = [1, 2];\n// var messages = [1, 2, 3, 2, 1, 3, 2];\n\nvar currIds = [];\nvar dict = {}\n\nfor (var i = 0; i < messages.length; i++) {\n if (dict[(messages[i]) + ''])\n continue;\n else if (currIds.length === stats[1]) {\n var toPop = currIds[0];\n dict[toPop + ''] = undefined;\n dict[messages[i]] = 'exist';\n currIds.push(messages[i]);\n currIds.shift();\n } else {\n dict[messages[i]] = 'exist';\n currIds.push(messages[i]);\n }\n}\n\ncurrIds.reverse();\nwrite(currIds.length + '\\n')\nwrite(currIds.join(' '))"}, {"source_code": "var stats = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n\nvar messages = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n// var stats = [1, 2];\n// var messages = [1, 2, 3, 2, 1, 3, 2];\n\nvar currIds = [];\n\nfor (var i = 0; i < messages.length; i++) {\n if (currIds.includes(messages[i]))\n continue;\n else if (currIds.length === stats[1]) {\n currIds.push(messages[i]);\n currIds.shift()\n } else {\n currIds.push(messages[i]);\n }\n}\n\ncurrIds.reverse();\nwrite(currIds.length + '\\n')\nwrite(currIds.join(' '))"}, {"source_code": "var stats = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n\nvar messages = readline().split(' ').map(function (num) {\n return parseInt(num);\n})\n// var stats = [1, 2];\n// var messages = [1, 2, 3, 2, 1, 3, 2];\n\nvar currIds = [];\nvar dict = {}\n\nfor (var i = 0; i < messages.length; i++) {\n if (dict[(messages[i]) + ''])\n continue;\n else if (currIds.length === stats[1]) {\n var toPop = currIds[0];\n dict[toPop + ''] = undefined;\n dict[messages[i]] = 'exist';\n currIds.push(messages[i]);\n currIds.shift();\n } else {\n dict[messages[i]] = 'exist';\n currIds.push(messages[i]);\n }\n}\n\ncurrIds.reverse();\nwrite(currIds.length + '\\n')\nwrite(currIds.join(' '))"}], "negative_code": [{"source_code": "'use strict'\n \nconst k = parseInt(readline().split(' ')[1]);\n \nconst res = readline().split(' ').reduce((r, i) => {\n if (r.slice(-k).indexOf(i) === -1) r.push(i);\n return r;\n}, []).slice(-k);\n\nwrite(res.length + '\\n' + res.join(' '));"}, {"source_code": "'use strict'\n\nconst k = parseInt(readline().split(' ')[1]);\n \nconst res = readline().split(' ').reduce((r, i) => {\n if (r.indexOf(i) === -1) {\n if (r.length === k) r.pop();\n r.unshift(i);\n }\n return r;\n}, []);\n \nwrite(res.length + '\\n' + res.reverse().join(' '));"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr[0].split(' ')\n\n let map = {}\n let current = 0\n let q = []\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n q.unshift(m)\n if(current == k) map[q.pop()] = false\n else{\n current ++\n }\n // console.log(map, q)\n map[m] = true\n }\n }\n\n console.log(q.length)\n for(let i = 0, len = q.length; i < len; i++) {\n process.stdout.write(q[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr[0].split(' ')\n\n let map = {}\n let current = 0\n let q = []\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n q.unshift(m)\n if(current == k) map[q.pop()] = false\n else{\n current ++\n }\n // console.log(map, q)\n map[m] = true\n }\n }\n\n for(let i = 0, len = q.length; i < len; i++) {\n process.stdout.write(q[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr.shift().split(' ')\n\n let map = {}\n let current = 0\n let q = []\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n q.unshift(m)\n if(current == k) map[q.pop()] = false\n else{\n current ++\n }\n map[m] = true\n }\n }\n if(k == 4) console.log(map, q)\n\n console.log(q.length)\n for(let i = 0, len = q.length; i < len; i++) {\n process.stdout.write(q[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const l1 = arr.shift().split(' ')\n const n = parseInt(l1[0])\n const k = parseInt(l1[1])\n const messages = arr[0].split(' ')\n\n let map = {}\n let current = 0\n let q = []\n\n for(let i = 0; i < n; i++) {\n const m = messages[i]\n if(!map[m]){\n q.unshift(m)\n if(current == k) map[q.pop()] = false\n else{\n current ++\n }\n map[m] = true\n }\n }\n if(k == 4) console.log(map, q)\n\n console.log(q.length)\n for(let i = 0, len = q.length; i < len; i++) {\n process.stdout.write(q[i] + ' ')\n }\n console.log()\n\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, k) {\n let result = data.reduce((acc, value) => {\n if (~acc.indexOf(value)) return acc;\n else if (acc.length < k) {\n acc.unshift(value)\n } else {\n acc.pop();\n acc.unshift(value);\n }\n return acc;\n }, []);\n return result;\n }\n\n let k = lines[0].split(\" \").map(Number)[1];\n let data = lines[1].split(\" \").map(Number);\n\n let result = foo(data, k);\n console.log(result);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, k) {\n let result = data.reduce((acc, value) => {\n if (~acc.indexOf(value)) return acc;\n else if (acc.length < k) {\n acc.unshift(value)\n } else {\n acc.pop();\n acc.unshift(value);\n }\n return acc;\n }, [])\n\n return result.join(\" \");\n\n\n }\n\n let k = lines[0].split(\" \").map(Number)[1];\n let data = lines[1].split(\" \").map(Number);\n\n let result = foo(data, k);\n console.log(result);\n})"}], "src_uid": "485a1ecf8f569b85327b99382bda9466"} {"source_code": "var n = readline();\n\nvar arr = [];\n\nfor( var i=1; i<=n; i++ ) {\n arr.push(readline().split(' ').map(Number))\n}\n\nvar prev = Math.min( arr[n-1][0], arr[n-1][1]);\n\nvar flg = true;\n\nfor( var i=n-2; i>=0; i-- ) {\n //print(arr[i][0]+ \" \" + arr[i][1]);\n var mn1 = Math.min( arr[i][0], arr[i][1] );\n var mn2;\n \n if( mn1 == arr[i][0] ) mn2 = arr[i][1];\n else mn2 = arr[i][0];\n \n if( prev <= mn1 ) {\n prev = mn1;\n } else if( prev <= mn2 ) {\n prev = mn2;\n } else {\n flg = false;\n }\n \n}\n\nif( flg ) {\n print('YES');\n} else {\n print('NO');\n}", "positive_code": [{"source_code": "\nfunction main() {\n const is = new Scanner();\n const n = is.nextLine();\n const rectangles = new Array(n);\n for (let i = 0; i < n; i += 1) {\n rectangles[i] = is.nextArray().map(Number);\n }\n\n const sequence = [Math.max(rectangles[0][0], rectangles[0][1])];\n let answer = true;\n for (let i = 1; i < n; i += 1) {\n\n if (rectangles[i][0] > rectangles[i][1]) {\n if (rectangles[i][0] > sequence[i - 1])\n sequence.push(rectangles[i][1]);\n else\n sequence.push(rectangles[i][0]);\n } else {\n if (rectangles[i][1] > sequence[i - 1])\n sequence.push(rectangles[i][0]);\n else\n sequence.push(rectangles[i][1]);\n }\n\n if (sequence[i] > sequence[i - 1])\n answer = false;\n }\n\n console.log(answer ? 'YES' : 'NO');\n\n}\n\n/*\n * api stdin\n */\n\nclass Scanner {\n constructor() {\n this.index = 0;\n this.lines = stdinInput.trim().split('\\n');\n }\n\n nextLine() {\n return this.lines[this.index++];\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray() {\n return this.nextLine().split(' ');\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n"}], "negative_code": [], "src_uid": "162fa942bc6eeb5164b19598da2f8bef"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n const queue = new Heap((a, b) => a[1] !== b[1] ? b[1] - a[1] : b[0] - a[0]);\r\n for (let i = n - 1; i > 0; i--) {\r\n if (a[i] < a[i - 1]) queue.push([i + 1, a[i - 1] - a[i]]);\r\n }\r\n const res = [];\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (queue.size()) {\r\n const cur = queue.pop();\r\n res[i] = cur[0];\r\n if (cur[1] > i + 1) {\r\n cur[1] -= i + 1;\r\n queue.push(cur);\r\n }\r\n } else {\r\n res[i] = 1;\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator = (a, b) => a - b, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "function solve() {\r\n var n = Number(read());\r\n var a = readArray(Number);\r\n var ans = [];\r\n var nextFree = [];\r\n for (var i = 1; i < n; i++) {\r\n if (a[i] > a[i - 1]) {\r\n continue;\r\n }\r\n var diff = a[i - 1] - a[i];\r\n var start = diff;\r\n while(ans[diff]) {\r\n diff = nextFree[diff] || (diff + 1);\r\n }\r\n nextFree[start] = diff + 1;\r\n ans[diff] = i + 1;\r\n }\r\n for (i = 0; i < n; i++) {\r\n ans[i] = ans[i + 1] || 1;\r\n }\r\n write(ans.slice(0, n).join(' '));\r\n}\r\n\r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n\r\nvar MEMORY;\r\nvar MEMORY_INDEX = 0;\r\nvar ANS = '';\r\n\r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\nfunction sortNumbers(a, b) {\r\n return a - b;\r\n}\r\nfunction sortNumbersDec(a, b) {\r\n return b - a;\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n for (let i = 0; i < n; i++) arr[i] = [arr[i], i + 1];\r\n arr.sort((a, b) => a[0] - b[0]);\r\n let ans = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n ans[n - i - 1] = arr[i][1];\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let ans = new Array(n).fill(1);\r\n let maxArr = [];\r\n maxArr.push(arr[0]);\r\n for (let i = 1; i < n; i++)\r\n maxArr.push(Math.max(maxArr[maxArr.length - 1], arr[i]));\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (maxArr[i] > arr[i + 1]) {\r\n ans[maxArr[i] - arr[i + 1]] = i + 2;\r\n }\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let ans = new Array(n).fill(1);\r\n let maxArr = [];\r\n maxArr.push(arr[0]);\r\n for (let i = 1; i < n; i++)\r\n maxArr.push(Math.max(maxArr[maxArr.length - 1], arr[i]));\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (arr[i] > arr[i + 1]) {\r\n ans[maxArr[i] - arr[i + 1]] = i + 2;\r\n }\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let ans = new Array(n).fill(1);\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (arr[i] > arr[i + 1]) {\r\n ans[arr[i] - arr[i + 1]] = i + 2;\r\n }\r\n }\r\n console.log(ans.join(\" \"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n let res = [];\r\n for (let i = n - 1; i > 0; i--) {\r\n if (a[i] < a[i - 1]) {\r\n for (let j = 0; j < a[i - 1] - a[i] && res.length < n; j++) {\r\n res.push(i + 1);\r\n }\r\n }\r\n }\r\n for (let i = res.length; i < n; i++) res[i] = 1;\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n let res = [];\r\n for (let i = n - 1; i > 0; i--) {\r\n if (a[i] < a[i - 1]) res.push([i + 1, a[i - 1] - a[i]]);\r\n }\r\n res.sort((a, b) => b[1] - a[1]);\r\n const ans = [];\r\n for (let i = 0; i < n; i++) {\r\n while (res.length && res[res.length - 1][1] === 0) res.pop();\r\n if (res.length) {\r\n ans[i] = res[res.length - 1][0];\r\n res[res.length - 1][1]--;\r\n } else {\r\n ans[i] = 1;\r\n }\r\n }\r\n return ans.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n let res = [1];\r\n for (let i = n - 1; i > 0; i--) {\r\n if (a[i] < a[i - 1]) {\r\n for (let j = 0; j < a[i - 1] - a[i]; j++) {\r\n res.push(i + 1);\r\n }\r\n }\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "188c9dbb3e1851b7b762ed6b4b23d1bd"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[n - 1] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n // console.log(Math.abs(a[0] - b[0]), aLastMin, bLastMin);\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n}\n", "positive_code": [{"source_code": "/*\r\nINPUT\r\n2\r\n3\r\n1 10 1\r\n20 4 25\r\n4\r\n1 1 1 1\r\n1000000000 1000000000 1000000000 1000000000\r\n*/\r\n\r\nvar t = Number(readline());\r\n\r\nfor(var i = 0; i < t; i++) {\r\n readline();\r\n var a = readline().split(' ').map(Number);\r\n var b = readline().split(' ').map(Number);\r\n\r\n var al = a[0];\r\n var ar = a[a.length - 1];\r\n var bl = b[0];\r\n var br = b[b.length - 1];\r\n\r\n var alm = Infinity, blm = Infinity, arm = Infinity, brm = Infinity;\r\n\r\n for(var j = 0; j < a.length; j++) {\r\n alm = Math.min(alm, Math.abs(b[j] - al));\r\n blm = Math.min(blm, Math.abs(a[j] - bl));\r\n arm = Math.min(arm, Math.abs(b[j] - ar));\r\n brm = Math.min(brm, Math.abs(a[j] - br));\r\n }\r\n\r\n\r\n\r\n var result = Math.min(\r\n Math.min(Math.abs(al - bl), blm + alm) + Math.min(Math.abs(ar - br), arm + brm),\r\n Math.min(Math.abs(al - br), alm + brm) + Math.min(Math.abs(ar - bl), arm + blm)\r\n );\r\n\r\n print(result);\r\n}\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction costOf(a, p, b) {\r\n\tlet mn = 1e9;\r\n\tfor (let i = 0; i < b.length; i++) {\r\n\t\tmn = Math.min(mn, Math.abs(a[p] - b[i]));\r\n\t}\r\n\treturn mn;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst A = rna();\r\n\t\tconst B = rna();\r\n\r\n\t\tlet ans = 1e18;\r\n\t\tfor (let mask = 0; mask < 4; mask++) {\r\n\t\t\tconst a = A.slice();\r\n\t\t\tconst b = B.slice();\r\n\t\t\tif (mask & (1 << 0)) a.reverse();\r\n\t\t\tif (mask & (1 << 1)) b.reverse();\r\n\r\n\t\t\tlet cost = 0;;\r\n\t\t\tfor (let i = 0; i < n; i += n-1) {\r\n\t\t\t\tcost += Math.min(Math.abs(a[i] - b[i]), costOf(a, i, b) + costOf(b, i, a));\r\n\t\t\t}\r\n\t\t\tans = Math.min(ans, cost);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction costOf(a, p, b) {\r\n\tlet mn = 1e9;\r\n\tfor (let i = 0; i < b.length; i++) {\r\n\t\tmn = Math.min(mn, Math.abs(a[p] - b[i]));\r\n\t}\r\n\treturn mn;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst A = rna();\r\n\t\tconst B = rna();\r\n\r\n\t\tlet ans = 1e18;\r\n\t\tfor (let mask = 0; mask < 4; mask++) {\r\n\t\t\tconst a = A.slice();\r\n\t\t\tconst b = B.slice();\r\n\t\t\tif (mask & (1 << 0)) a.reverse();\r\n\t\t\tif (mask & (1 << 1)) b.reverse();\r\n\r\n\t\t\tans = Math.min(ans, Math.abs(a[0] - b[0]) + Math.abs(a[n-1] - b[n-1]));\r\n\t\t\tans = Math.min(ans, costOf(a, 0, b) + costOf(b, 0, a) + Math.abs(a[n-1] - b[n-1]));\r\n\t\t\tans = Math.min(ans, costOf(a, 0, b) + costOf(b, 0, a) + costOf(a, n-1, b) + costOf(b, n-1, a));\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (a, b, n)=>{\n let getBest = (arr, num)=>{\n let min = Infinity;\n for (let _a of arr)\n min = Math.min(min, Math.abs(_a-num));\n return min;\n };\n let bestResult = Infinity\n // 0 any, 1 with first, 2 with second\n for (let aFirst=0; aFirst<3; aFirst++){\n let result = 0;\n let skipBfirst\n let skipBlast\n if (aFirst==0){\n result += getBest(b, a[0]);\n }else if (aFirst==1){\n result += Math.abs(a[0]-b[0]);\n skipBfirst = true\n }else{\n result += Math.abs(a[0]-b[n-1]);\n skipBlast = true\n }\n for (let aLast=0; aLast<3; aLast++){\n let skipBfirst2 = skipBfirst\n let skipBlast2 = skipBlast\n let result2 = result;\n if (aLast==0){\n result2 += getBest(b, a[n-1]);\n }else if (aLast==1){\n result2 += Math.abs(a[n-1]-b[0]);\n skipBfirst2 = true\n }else{\n result2 += Math.abs(a[n-1]-b[n-1]);\n skipBlast2 = true\n }\n if (!skipBfirst2)\n result2 += getBest(a, b[0])\n if (!skipBlast2)\n result2 += getBest(a, b[n-1])\n //console.log({skipBfirst, skipBlast, aFirst, aLast}, result2)\n bestResult = Math.min(bestResult, result2)\n }\n }\n return bestResult;\n};\n\nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n let a = ra();\n let b = ra();\n print(calc(a, b, n));\n }\n}\n\nE.calc = calc;"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = Number(readline());\n\n if (testCases > 2) {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n if (i === 324) {\n console.log(n);\n console.log(a);\n console.log(b);\n }\n }\n } else {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n // console.log(Math.abs(a[0] - b[0]), aLastMin, bLastMin);\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(Math.abs(a[n - 1] - b[0]), aFirstMin, bLastMin);\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[n - 1] - b[0]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n // console.log(Math.abs(a[0] - b[0]), aLastMin, bLastMin);\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[n - 1] - b[0]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n console.log(Math.abs(a[0] - b[0]), aLastMin, bLastMin);\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = Number(readline());\n\n if (testCases > 2) {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n if (i === 261) {\n console.log(n);\n console.log(a);\n console.log(b);\n }\n }\n } else {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(Math.abs(a[n - 1] - b[0]), aFirstMin, bLastMin);\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = Number(readline());\n\n if (testCases > 2) {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n if (i === 262) {\n console.log(n);\n console.log(a);\n console.log(b);\n }\n }\n } else {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(Math.abs(a[n - 1] - b[0]), aFirstMin, bLastMin);\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[n - 1] - b[0]) + aFirstMin + bLastMin;\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = Number(readline());\n\n if (testCases > 2) {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n if (i === 82) {\n console.log(n);\n console.log(a);\n console.log(b);\n }\n }\n } else {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aLastMin + bFirstMin;\n\n // console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n if (testCases > 2) {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n if (i === 82) {\n console.log(n);\n console.log(a);\n console.log(b);\n }\n }\n } else {\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aLastMin + bFirstMin;\n\n console.log(sum1, sum2, sum3, sum4, sum5, sum6, sum7);\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[n - 1] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[0]);\n let bLastMinIndex = 0;\n\n // loop over a\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) <= bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n bLastMinIndex = i;\n }\n }\n\n if (\n (bFirstMinIndex === 0 && bLastMinIndex === n - 1) ||\n (bFirstMinIndex === n - 1 && bLastMinIndex === 0)\n ) {\n console.log(bFirstMin + bLastMin);\n } else {\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) <= aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aFirstMin + bLastMin;\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[1]);\n let aLastMin = Math.abs(a[n - 1] - b[1]);\n\n let bFirstMin = Math.abs(a[1] - b[0]);\n // let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[1] - b[n - 1]);\n // let bLastMinIndex = 0;\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) < aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n // bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) < bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n // bLastMinIndex = i;\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aLastMin + bFirstMin;\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[n - 1] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[0]);\n let bLastMinIndex = 0;\n\n // loop over a\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) <= bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n bLastMinIndex = i;\n }\n }\n\n if (\n (bFirstMinIndex === 0 && bLastMinIndex === n - 1) ||\n (bFirstMinIndex === n - 1 && bLastMinIndex === 0)\n ) {\n console.log(bFirstMin + bLastMin);\n } else {\n for (let i = 1; i < n - 1; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) <= aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n let sum1 = bFirstMin + bLastMin + aFirstMin + aLastMin;\n // if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n // sum1 += aFirstMin;\n // }\n\n // if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n // sum1 += aLastMin;\n // }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aFirstMin + bLastMin;\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[0] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[0]);\n let bLastMinIndex = 0;\n\n // loop over a\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) <= bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n bLastMinIndex = i;\n }\n }\n\n if (\n (bFirstMinIndex === 0 && bLastMinIndex === n - 1) ||\n (bFirstMinIndex === n - 1 && bLastMinIndex === 0)\n ) {\n aFirstMin = 0;\n aLastMin = 0;\n console.log(bFirstMin + bLastMin);\n } else {\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) <= aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n let sum1 = bFirstMin + bLastMin;\n if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n sum1 += aFirstMin;\n }\n\n if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n sum1 += aLastMin;\n }\n\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n let sum4 = Math.abs(a[0] - b[0]) + aLastMin + bLastMin;\n\n let sum5 = Math.abs(a[0] - b[n - 1]) + bFirstMin + aLastMin;\n\n let sum6 = Math.abs(a[n - 1] - b[n - 1]) + aFirstMin + bFirstMin;\n\n let sum7 = Math.abs(a[0] - b[n - 1]) + aFirstMin + bLastMin;\n\n console.log(Math.min(sum1, sum2, sum3, sum4, sum5, sum6, sum7));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[0] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[0]);\n let bLastMinIndex = 0;\n\n // loop over a\n for (let i = 1; i < n; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[n - 1]) <= bLastMin) {\n bLastMin = Math.abs(a[i] - b[n - 1]);\n bLastMinIndex = i;\n }\n }\n\n if (\n (bFirstMinIndex === 0 && bLastMinIndex === n - 1) ||\n (bFirstMinIndex === n - 1 && bLastMinIndex === 0)\n ) {\n aFirstMin = 0;\n aLastMin = 0;\n console.log(bFirstMin + bLastMin);\n } else {\n for (let i = 1; i < n; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[n - 1]) <= aLastMin) {\n aLastMin = Math.abs(b[i] - a[n - 1]);\n }\n }\n\n let sum = bFirstMin + bLastMin;\n if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n sum += aFirstMin;\n }\n\n if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n sum += aLastMin;\n }\n\n // square\n let sum2 = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] - b[n - 1]);\n\n // cross\n let sum3 = Math.abs(a[0] - b[n - 1]) + Math.abs(a[n - 1] - b[0]);\n\n console.log(Math.min(sum, sum2, sum3));\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n // let isPalindrome = true;\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n let a = readline().split(\" \");\n let b = readline().split(\" \");\n\n let aFirstMin = Math.abs(a[0] - b[0]);\n let aLastMin = Math.abs(a[0] - b[0]);\n\n let bFirstMin = Math.abs(a[0] - b[0]);\n let bFirstMinIndex = 0;\n\n let bLastMin = Math.abs(a[0] - b[0]);\n let bLastMinIndex = 0;\n // let aFirstMin = -1;\n // let aLastMin = -1;\n // let bFirstMin = -1;\n // let bLastMin = -1;\n\n // loop over a\n for (let i = 1; i < a.length; i++) {\n if (Math.abs(a[i] - b[0]) < bFirstMin) {\n bFirstMin = Math.abs(a[i] - b[0]);\n bFirstMinIndex = i;\n }\n if (Math.abs(a[i] - b[b.length - 1]) <= bLastMin) {\n bLastMin = Math.abs(a[i] - b[b.length - 1]);\n bLastMinIndex = i;\n }\n }\n\n if (\n (bFirstMinIndex === 0 && bLastMinIndex === n - 1) ||\n (bFirstMinIndex === n - 1 && bLastMinIndex === 0)\n ) {\n aFirstMin = 0;\n aLastMin = 0;\n console.log(bFirstMin + bLastMin);\n } else {\n for (let i = 1; i < b.length; i++) {\n if (Math.abs(b[i] - a[0]) < aFirstMin) {\n aFirstMin = Math.abs(b[i] - a[0]);\n }\n if (Math.abs(b[i] - a[a.length - 1]) <= aLastMin) {\n aLastMin = Math.abs(b[i] - a[a.length - 1]);\n }\n }\n\n let sum = bFirstMin + bLastMin;\n if (bFirstMinIndex !== 0 && bLastMinIndex !== 0) {\n sum += aFirstMin;\n }\n\n if (bFirstMinIndex !== n - 1 && bLastMinIndex !== n - 1) {\n sum += aLastMin;\n }\n console.log(sum);\n }\n }\n}\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction costOf(a, p, b) {\r\n\tlet mn = 1e9;\r\n\tfor (let i = 0; i < b.length; i++) {\r\n\t\tmn = Math.min(mn, Math.abs(a[p] - b[i]));\r\n\t}\r\n\treturn mn;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\t\tconst b = rna();\r\n\r\n\t\tconst l = Math.min(costOf(a, 0, b) + costOf(b, 0, a), Math.abs(a[0] - b[0]));\r\n\t\tconst r = Math.min(costOf(a, n-1, b) + costOf(b, n-1, a), Math.abs(a[n-1] - b[n-1]));\r\n\r\n\t\tconsole.log(l + r);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "/*\r\nINPUT\r\n2\r\n3\r\n1 10 1\r\n20 4 25\r\n4\r\n1 1 1 1\r\n1000000000 1000000000 1000000000 1000000000\r\n*/\r\n\r\nconst t = Number(readline());\r\n\r\nfor(var i = 0; i < t; i++) {\r\n readline();\r\n const a = readline().split(' ').map(Number);\r\n const b = readline().split(' ').map(Number);\r\n\r\n const al = a[0];\r\n const ar = a[a.length - 1];\r\n const bl = b[0];\r\n const br = b[b.length - 1];\r\n\r\n var alm = Infinity, blm = Infinity, arm = Infinity, brm = Infinity;\r\n\r\n for(var j = 0; j < a.length; j++) {\r\n alm = Math.min(alm, Math.abs(b[j] - al));\r\n blm = Math.min(blm, Math.abs(a[j] - bl));\r\n arm = Math.min(arm, Math.abs(b[j] - ar));\r\n brm = Math.min(brm, Math.abs(a[j] - br));\r\n }\r\n\r\n\r\n\r\n const result = Math.min(\r\n Math.min(Math.abs(al - bl), blm + alm) + Math.min(Math.abs(ar - br), arm + brm),\r\n Math.min(Math.abs(al - br), alm + brm) + Math.min(Math.abs(ar - bl), arm + blm)\r\n );\r\n\r\n print(result);\r\n\r\n\r\n}\r\n"}, {"source_code": "var t = Number(readline())\r\n\r\nprint(t)"}, {"source_code": "/*\r\nINPUT\r\n2\r\n3\r\n1 10 1\r\n20 4 25\r\n4\r\n1 1 1 1\r\n1000000000 1000000000 1000000000 1000000000\r\n*/\r\n\r\nconst t = Number(readline());\r\n\r\nprint(t);\r\n\r\n/*for(let i = 0; i < t; i++) {\r\n readline();\r\n const a = readline().split(' ').map(Number);\r\n const b = readline().split(' ').map(Number);\r\n\r\n print(a, b);\r\n\r\n const al = a[0];\r\n const ar = a[a.length - 1];\r\n const bl = b[0];\r\n const br = b[b.length - 1];\r\n\r\n let alm = Infinity, blm = Infinity, arm = Infinity, brm = Infinity;\r\n\r\n for(let i = 0; i < a.length; i++) {\r\n alm = Math.min(alm, Math.abs(b[i] - al));\r\n blm = Math.min(blm, Math.abs(a[i] - bl));\r\n arm = Math.min(arm, Math.abs(b[i] - ar));\r\n brm = Math.min(brm, Math.abs(a[i] - br));\r\n }\r\n\r\n\r\n\r\n const result = Math.min(\r\n Math.min(Math.abs(al - bl), blm + alm) + Math.min(Math.abs(ar - br), arm + brm),\r\n Math.min(Math.abs(al - br), alm + brm) + Math.min(Math.abs(ar - bl), arm + blm)\r\n );\r\n\r\n print(result);\r\n}*/\r\n"}, {"source_code": "/*\r\nINPUT\r\n2\r\n3\r\n1 10 1\r\n20 4 25\r\n4\r\n1 1 1 1\r\n1000000000 1000000000 1000000000 1000000000\r\n*/\r\n\r\nprint(readline());\r\n\r\n/*const t = Number(readline());\r\n\r\nfor(let i = 0; i < t; i++) {\r\n readline();\r\n const a = readline().split(' ').map(Number);\r\n const b = readline().split(' ').map(Number);\r\n\r\n const al = a[0];\r\n const ar = a[a.length - 1];\r\n const bl = b[0];\r\n const br = b[b.length - 1];\r\n\r\n let alm = Infinity, blm = Infinity, arm = Infinity, brm = Infinity;\r\n\r\n for(let i = 0; i < a.length; i++) {\r\n alm = Math.min(alm, Math.abs(b[i] - al));\r\n blm = Math.min(blm, Math.abs(a[i] - bl));\r\n arm = Math.min(arm, Math.abs(b[i] - ar));\r\n brm = Math.min(brm, Math.abs(a[i] - br));\r\n }\r\n\r\n\r\n\r\n const result = Math.min(\r\n Math.min(Math.abs(al - bl), blm + alm) + Math.min(Math.abs(ar - br), arm + brm),\r\n Math.min(Math.abs(al - br), alm + brm) + Math.min(Math.abs(ar - bl), arm + blm)\r\n );\r\n\r\n print(result);\r\n}*/\r\n"}], "src_uid": "71e6ceb75852f4cd437bbf0478e37dc4"} {"source_code": "n=Number(readline());\nh=[readline().split(' ').map(Number), readline().split(' ').map(Number)];\nd = [{0: h[0][0], 1: h[1][0] + h[0][1] }, {0: h[1][0], 1: h[1][1] + h[0][0]}];\nf = (row, i) => (prev => h[row][i] + Math.max(d[prev][i-1], d[prev][i-2]))(row ? 0 : 1);\nfor (var i = 2; i < n; i++) {\n d[0][i] = f(0, i);\n d[1][i] = f(1, i);\n}\nprint(Math.max(d[0][n-1], d[1][n-1]))\n", "positive_code": [{"source_code": "var n = +readline();\nvar arr1 = readline().split(' ').map(item => +item);\nvar arr2 = readline().split(' ').map(item => +item);\n\narr1[1] = arr2[0] + arr1[1];\narr2[1] = arr1[0] + arr2[1];\n\nfor(var i = 2; i < n; i++) {\n arr1[i] = Math.max(arr2[i - 1] + arr1[i], arr2[i - 2] + arr1[i]);\n arr2[i] = Math.max(arr1[i - 1] + arr2[i], arr1[i - 2] + arr2[i]);\n}\n\nn--;\nprint(Math.max(arr1[n], arr2[n]));\n"}, {"source_code": "\"use strict\";\n \nvar main = function() {\n var n = +rd();\n var H1 = [0].concat(rdAr());\n var H2 = [0].concat(rdAr());\n \n var DP = [crAr(n + 10, -1), crAr(n + 10, -1)];\n var dp = function(prev, pos) {\n if (pos > n) {\n return 0;\n }\n if (DP[prev][pos] !== -1) {\n return DP[prev][pos];\n }\n var res = dp(prev, pos + 1);\n if (prev === 0) {\n res = Math.max(res, dp(1, pos + 1) + H2[pos]);\n } else {\n res = Math.max(res, dp(0, pos + 1) + H1[pos]);\n }\n \n return DP[prev][pos] = res;\n };\n \n for (var i = n; i >= 0; --i) {\n dp(0, i);dp(1, i);\n }\n wr(dp(0, 0));\n};\n \nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\n \nmain();"}], "negative_code": [{"source_code": "\"use strict\";\n \nvar main = function() {\n var n = +rd();\n var H1 = [0].concat(rdAr());\n var H2 = [0].concat(rdAr());\n \n var DP = [crAr(n + 10, -1), crAr(n + 10, -1)];\n var dp = function(prev, pos) {\n if (pos > n) {\n return 0;\n }\n if (DP[prev][pos] !== -1) {\n return DP[prev][pos];\n }\n var res = dp(prev, pos + 1);\n if (prev === 0) {\n res = Math.max(res, dp(1, pos + 1) + H2[pos]);\n } else {\n res = Math.max(res, dp(0, pos + 1) + H1[pos]);\n }\n \n return DP[prev][pos] = res;\n };\n \n return dp(0, 0);\n};\n \nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\n \nmain();"}], "src_uid": "667e8938b964d7a24500003f6b89717b"} {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n let result = 0;\n let mx = 0;\n for (let i = 1; i < n; i++) {\n if (a[i] > a[mx]) {\n mx = i;\n continue;\n }\n // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);\n result++;\n mx = i + 1;\n i = i + 1;\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split(' ').map(Number), ans = 0, max = 0\n for(l = 0; l < e; l++){\n if(k[l] < max){\n ans++, max = 0\n }else{\n max = k[l]\n }\n }\n console.log(ans)\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const st = [],\r\n left = [];\r\n for (let i = 0; i < n; i++) {\r\n var _st;\r\n while (st.length && a[st[st.length - 1]] < a[i]) st.pop();\r\n left[i] = (_st = st[st.length - 1]) !== null && _st !== void 0 ? _st : -1;\r\n st.push(i);\r\n }\r\n const dp = new Array(n).fill(0);\r\n let max = 0;\r\n for (let i = 0; i < n; i++) {\r\n var _dp2;\r\n if (left[i] >= 0) {\r\n var _dp;\r\n dp[i] = ((_dp = dp[left[i] - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n }\r\n dp[i] = Math.max(dp[i], (_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0);\r\n max = Math.max(max, dp[i]);\r\n }\r\n return max;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var ans = 0, max = 0;\n for(j = 0; j < n; j++){\n if(a[j] < max){\n ans++, max = 0;\n }else{\n max = a[j];\n }\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let sum = 0;\r\n let max = arr[0];\r\n for (let i = 1; i < n; i++) {\r\n if (arr[i] >= max) {\r\n max = arr[i];\r\n } else {\r\n sum += 1;\r\n max = 0;\r\n }\r\n }\r\n\r\n output(sum);\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tif(list[i] > list[i + 1]){\r\n\t\t\t\toutput++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n readLine();\r\n let arr = readLine().split(\" \").map(i => parseInt(i));\r\n let res = 0;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i - 1] > arr[i]) {\r\n res++;\r\n i++;\r\n }\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst n = nextInt();\r\n\tconst arr = nextIntArray(n);\r\n\tlet sum = 0;\r\n\r\n\tfor (let i = 0; i < arr.length - 1; i++) {\r\n\t\tif (arr[i] > arr[i + 1]) {\r\n\t\t\ti++;\r\n\t\t\tsum++;\r\n\t\t}\r\n\t}\r\n\r\n\tmyout(sum);\r\n}"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n, m] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let ans = 0;\n let l=0;\n while (l+1A[l+1]){\n l++;\n ans++;\n }\n l++;\n }\n return ans;\n};\n \n"}, {"source_code": "var num = readline();\r\n\r\nfor (var i = 0; i < num; i++) {\r\n var n = readline();\r\n var arr = readline().split(\" \");\r\n\r\n var count = 0;\r\n\r\n for(var j = 0; j < n; j++) {\r\n if(parseInt(arr[j], 10) > parseInt(arr[j + 1], 10) && j < n - 1){\r\n j++;\r\n count++;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n n = +readline()\r\n a = readline().split(' ').map(a => +a)\r\n ans = 0\r\n\r\n for(i = 0; i< n-1; i++){\r\n if(a[i]> a[i+1]){\r\n ans++\r\n i++\r\n }\r\n\r\n }\r\n\r\n print(ans)\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j]\n }else{\n var k = lines[j].split(' ').map(Number), ans = 0, max = 0;\n for(l = 0; l < e; l++){\n if(k[l] < max){\n ans++, max ++\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n var e = 0;\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number), ans = 0, max = 0;\n for(l = 0; l < e; l++){\n if(k[l] < max){\n ans++, max = 0;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const st = [],\r\n left = [];\r\n for (let i = 0; i < n; i++) {\r\n var _st;\r\n while (st.length && a[st[st.length - 1]] < a[i]) st.pop();\r\n left[i] = (_st = st[st.length - 1]) !== null && _st !== void 0 ? _st : -1;\r\n st.push(i);\r\n }\r\n const dp = new Array(n).fill(0);\r\n let max = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (left[i] >= 0) {\r\n var _dp, _dp2;\r\n dp[i] = Math.max(((_dp = dp[left[i] - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1, (_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0);\r\n }\r\n max = Math.max(max, dp[i]);\r\n }\r\n return max;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const st = [],\r\n left = [];\r\n for (let i = 0; i < n; i++) {\r\n var _st;\r\n while (st.length && a[st[st.length - 1]] < a[i]) st.pop();\r\n left[i] = (_st = st[st.length - 1]) !== null && _st !== void 0 ? _st : -1;\r\n st.push(i);\r\n }\r\n const dp = new Array(n).fill(0);\r\n let res = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (left[i] >= 0) {\r\n var _dp;\r\n dp[i] = ((_dp = dp[left[i] - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;\r\n }\r\n res = Math.max(res, dp[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst getDigits = (x) => {\n let digits = new Array(10).fill(false);\n let len = 0;\n while (x) {\n len++;\n digits[x % 10n] = true;\n x /= 10n;\n }\n return [digits, len];\n}\n\nconst getLen = (x) => {\n let str = x.toString(10);\n return str.length;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = readline();\n let a = ra();\n\n let result = 0;\n let start = 0;\n for (let i = 1; i < n; i++) {\n if (a[i] > a[start]) continue;\n result++;\n start = i + 1;\n i = i + 1;\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var num = readline();\r\n \r\nfor (var i = 0; i < num; i++) {\r\n var n = readline();\r\n var arr = readline();\r\n \r\n var count = 0;\r\n \r\n for(var j = 0; j < n; j++) {\r\n if(arr[j] > arr[j + 1] && j < n - 1){\r\n j++;\r\n count++;\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "var num = readline();\r\n\r\nfor (var i = 0; i < num; i++) {\r\n var n = readline();\r\n var arr = readline().split(\" \");\r\n\r\n var count = 0;\r\n\r\n for(var j = 0; j < n; j++) {\r\n if(arr[j] > arr[j + 1] && j < n - 1){\r\n j++;\r\n count++;\r\n }\r\n }\r\n print(count);\r\n}"}], "src_uid": "80e21bfe08a3ef156d0404d4fe07bccd"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, target] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let max = -Infinity;\n\n for (let i = 0; i < len; i++) {\n let count = 0;\n const val = arr[i];\n for (let j = 1; j < len; j++) {\n const index = (i + j) % len;\n const current = arr[index];\n const diff = target - current;\n if (diff > 0) {\n count += Math.floor(diff / val);\n }\n }\n max = Math.max(max, count);\n }\n\n console.log(max);\n }\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline());\nwhile(t-- > 0) {\n var nk = readline().split(' ');\n var n = parseInt(nk[0]);\n var k = parseInt(nk[1]);\n var a = readline().split(' ').map(x => parseInt(x));\n var smallest = 0;\n var output = 0;\n for (var i = 1; i < n; i ++) {\n if (a[smallest] > a[i]) smallest = i;\n }\n for (var i = 0; i < n; i ++) {\n if (i !== smallest) {\n output += Math.floor((k - a[i]) / a[smallest]);\n }\n }\n print(output);\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var N = one[0];\n var K = one[1];\n var list = nextIntArray();\n var mincount = 1000000;\n var minIndex = -1;\n for(var j = 0; j < N; j++){\n if(mincount > list[j]){\n mincount = list[j];\n minIndex = j;\n }\n }\n var count = 0;\n for(var j = 0; j < N; j++){\n if(j != minIndex){\n count += Math.floor((K - list[j]) / mincount);\n }\n }\n output[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n let a = data[i].trim().split(' ').map(Number);\n const n = a[0];\n const k = a[1];\n a = data[i + 1].trim().split(' ').map(Number);\n a.sort((a, b) => a - b);\n let min = a[0];\n let moves = 0;\n if (a[0] < k) {\n for (let i = 1; i < a.length; i += 1) {\n if (a[i] < k) moves += Math.floor((k - a[i]) / min);\n }\n }\n console.log(moves);\n i += 2;\n }\n}"}, {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let n = $(), k = $()\n let a = $(n).sort(asc);\n // console.log(a,k)\n let s = 0;\n For(1, n - 1, 1, i => { s += (k - a[i]) / a[0] | 0 })\n log(s)\n }\n}"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction tTwoLinesPerStdin() {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let t;\n let prevLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof t !== 'number') {\n t = +line;\n } else {\n if (prevLine) {\n output.push([prevLine, line]);\n prevLine = undefined;\n\n if (output.length === t) {\n resolve(output);\n stdin.close();\n }\n } else {\n prevLine = line;\n }\n }\n });\n });\n}\n\nfunction solve(k, piles) {\n const sorted = piles.sort((a, b) => a - b);\n let answer = 0;\n\n for (let i = 1; i < sorted.length; i++) {\n answer += Math.floor((k - sorted[i]) / sorted[0]);\n }\n\n return answer;\n}\n\nasync function main() {\n const input = await tTwoLinesPerStdin();\n\n for (let t = 0; t < input.length; t++) {\n const [line1, line2] = input[t];\n const [k] = line1.split(' ').map(Number).slice(1);\n const a = line2.split(' ').map(Number);\n const answer = solve(k, a);\n console.log(answer);\n }\n}\n\nmain().then();\n"}], "negative_code": [], "src_uid": "b89e9598adae3da19903cdbfd225dd3c"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n; j++){\n var k = lines[j].split('');\n var a = false;\n for(l = 0; l < k.length; l++){\n if(k[l - 1] != k[l] && k[l] != k[l + 1]){\n a = true;\n }\n }\n if(a === true){\n console.log('NO'); \n }else{\n console.log('YES');\n }\n }\n});", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let s=line[i];\r\n flag=true;\r\n let c1=0,c2=0;\r\n for(let i=0;i0)\r\n {\r\n if(c2===1) flag=false;\r\n c2=0;\r\n }\r\n }\r\n else\r\n {\r\n c2++;\r\n if(c1>0)\r\n {\r\n if(c1===1) flag=false;\r\n c1=0;\r\n }\r\n }\r\n }\r\n if(c1===1||c2===1) flag=false;\r\n if(flag) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n})"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n if(a.length <= 1) return 'NO';\r\n let count = 0;\r\n let prev = 'c'\r\n for (let index = 0; index < a.length; index++) {\r\n const element = a[index];\r\n if(prev !== element){\r\n if(count === 1) return 'NO';\r\n count = 1;\r\n prev = element;\r\n } else {\r\n count++;\r\n }\r\n }\r\n if(count === 1) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index].trim();\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { s } = testCase;\n\n let result = \"YES\";\n let run = 0;\n let last = undefined;\n for (let i = 0; i < s.length; i++) {\n const c = s[i];\n if (c != last) {\n if (run == 1) {\n result = \"NO\";\n break;\n }\n run = 1;\n last = c;\n } else {\n run++;\n }\n }\n if (run == 1) {\n result = \"NO\";\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline();\r\n\r\n let a = 0;\r\n let b = 0;\r\n\r\n let no = false;\r\n if (s === 'a' || s === 'b') {\r\n output('NO');\r\n continue;\r\n }\r\n for (let i = 0; i < s.length; i++) {\r\n if (s[i] === 'a') {\r\n if (b === 1) {\r\n no = true;\r\n break;\r\n } else {\r\n a++;\r\n b = 0;\r\n }\r\n } else {\r\n if (a === 1) {\r\n no = true;\r\n break;\r\n } else {\r\n b++;\r\n a = 0;\r\n }\r\n }\r\n }\r\n\r\n if (b === 1 || a === 1) {\r\n no = true;\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}\r\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n //var v = new Map();\n //v.set('a', 1); v.set('b', 2); v.set('c', 3); v.set('d', 4); v.set('e', 5); v.set('f', 6); v.set('g', 7); v.set('h', 8); v.set('i', 9); v.set('j', 10); v.set('k', 11); v.set('l', 12); v.set('m', 13); v.set('n', 14); v.set('o', 15); v.set('p', 16); v.set('q', 17); v.set('r', 18); v.set('s', 19); v.set('t', 20); v.set('u', 21); v.set('v', 22); v.set('w', 23); v.set('x', 24); v.set('y', 25); v.set('z', 26);\n var e = 0;\n for(i = 1; i <= n; i++){\n var k = lines[i].split('');\n var a = false;\n for(j = 0; j < k.length; j++){\n if(k[j - 1] != k[j] && k[j] != k[j + 1]){\n a = true;\n }\n }\n if(a){\n console.log('NO'); \n }else{\n console.log('YES');\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let p, c\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (x === p) {\n c++\n } else {\n if (c === 1) return false\n c = 1\n p = x\n }\n }\n if (c === 1) return false\n return true\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n let cur = '';\r\n for (let i = 0; i <= s.length; i++) {\r\n if (cur[0] !== s[i]) {\r\n if (cur.length > 0) {\r\n if (cur.length < 2) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n cur = '';\r\n }\r\n cur += s[i];\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s = await read();\r\n solve(s);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst calc = (s)=>{\n let prev = 'c';\n let count = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] !== prev) {\n if (count === 1) return 'NO';\n count = 1;\n prev = s[i];\n } else {\n count++;\n }\n }\n if (count === 1) return 'NO';\n\n return 'YES';\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n // let n = +readline();\n let s = readline();\n console.log(`${calc(s)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (s)=>{\n for (let i=0; i=1){\r\n sum=0;\r\n }\r\n else{\r\n sum=-1;\r\n break;\r\n }\r\n }\r\n }\r\n if(sum===0){\r\n print(\"YES\");\r\n }\r\n else if(sum===-1){\r\n print(\"NO\");\r\n }\r\n}"}], "negative_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n console.log();\r\n})"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const a = readLine();\r\n\r\n const res = main(a);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction main(a){\r\n if(a.length <= 1) return 'NO';\r\n let countA = 0;\r\n let countB = 0;\r\n let countAllA = 0;\r\n let countAllB = 0;\r\n for (let index = 0; index < a.length; index++) {\r\n const element = a[index];\r\n if(element == 'a') {\r\n countA++;\r\n countAllA++;\r\n if(countB == 1) return 'NO';\r\n countB = 0;\r\n }\r\n if(element == 'b') {\r\n countB++;\r\n countAllB++;\r\n if(countA == 1) return 'NO';\r\n countA = 0;\r\n }\r\n }\r\n if(countAllA == 1 || countAllB == 1) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nmodule.exports = main;"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase, index) {\n const { s } = testCase;\n\n let result = \"YES\";\n let run = 0;\n let last = undefined;\n for (let i = 0; i < s.length; i++) {\n const c = s[i];\n if (c != last) {\n if (run == 1) {\n result = \"NO\";\n break;\n }\n run = 1;\n last = c;\n } else {\n run++;\n }\n }\n if (run == 1) {\n result = \"NO\";\n }\n\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}], "src_uid": "e95e2d21777c1d686bede1b0a5dacbf5"} {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var s = readline().split('');\r\n firstCounter = 0 ; secondCounter = 0;\r\n s.forEach((e) => {\r\n e == 0 ? firstCounter++ : secondCounter++;\r\n });\r\n if(s.length < 3){\r\n print('0');\r\n }\r\n else{\r\n if(firstCounter > secondCounter){\r\n print(secondCounter);\r\n }\r\n else if(firstCounter < secondCounter){\r\n print(firstCounter);\r\n }\r\n else{\r\n print(firstCounter - 1);\r\n }\r\n }\r\n } ", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\n while(test--)\r\n {\r\n let s = readLine();\r\n \r\n let count_0=0;\r\n let count_1=0;\r\n \r\n for(let i=0;i1) console.log(count_0 - 1);\r\n else if(count_0>count_1)console.log(count_1);\r\n else console.log(count_0);\r\n\r\n }\r\n return 0;\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline().split('');\r\n let z = s.filter(c => c === '0').length;\r\n let o = s.length - z;\r\n\r\n if (z === o) output(z - 1); else output(Math.min(z, o));\r\n }\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet a = nl.line().split('');\n\t\tlet c0 = a.reduce((acc, e) => (e === '0')?acc + 1:acc, 0);\n\t\tlet c1 = a.length - c0;\n\t\tif ((c0 == c1 && a.length == 2) || a.length == 1) {\n\t\t\tans.push(0);\n\t\t} else {\n\t\t\tif (c0 < c1) {\n\t\t\t\tans.push(c0);\n\t\t\t} else if (c0 > c1) {\n\t\t\t\tans.push(c1);\n\t\t\t} else {\n\t\t\t\tans.push(c1 - 1);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let c0 = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '0') c0++\n }\n const c1 = str.length - c0\n return c0 === c1 ? Math.max(0, c0 - 1) : Math.min(c0, c1)\n}\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var s = readline();\r\n var pref = []\r\n var prefo = []\r\n prefo[-1] = 0;\r\n pref[-1] = 0;\r\n for(var i=0;i x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \t\r\n \tv = prefo[j-1]-prefo[i-1]\r\n \tx = pref[j-1]-pref[i-1]\r\n \tif(v > x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \t\r\n \tv = prefo[j]-prefo[i]\r\n \tx = pref[j-1]-pref[i]\r\n \tif(v > x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \tj--;\r\n \ti++;\r\n }\r\n i=0;\r\n j=s.length-1;\r\n while(i<=j) {\r\n \tvar v = pref[j]-pref[i-1]\r\n \tvar x = prefo[j]-prefo[i-1]\r\n \tif(v > x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \t\r\n \tv = pref[j-1]-pref[i-1]\r\n \tx = prefo[j-1]-prefo[i-1]\r\n \tif(v > x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \t\r\n \tv = pref[j]-pref[i]\r\n \tx = prefo[j-1]-prefo[i]\r\n \tif(v > x) {\r\n \t\tans = Math.max(ans, x)\r\n \t}\r\n \tj--;\r\n \ti++;\r\n }\r\n \r\n console.log(ans)\r\n}"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0].trim());\r\n let i = 1;\r\n while (t--) {\r\n let string = lines[i++].trim();\r\n //console.log(string);\r\n let countOne = 0;\r\n let countTwo = 0;\r\n for (let i = 0; i < string.length; i++) {\r\n if (string[i] === \"1\") {\r\n countOne++;\r\n } else if (string[i] === \"0\") {\r\n countTwo++;\r\n }\r\n }\r\n //console.log(countOne, countTwo);\r\n if (countOne === countTwo) {\r\n console.log(countOne - 1);\r\n } else {\r\n console.log(Math.min(countOne, countTwo));\r\n }\r\n }\r\n});\r\n"}, {"source_code": "\r\nconst main = () => {\r\n\t\r\n\t// either take the whole string or 1 char less\r\n\tvar t = readInt();\r\n\twhile (t--) {\r\n\t\ts = readline();\r\n\t\tvar cnts = [0, 0];\r\n\t\tfor (var c of s)\r\n\t\t\tcnts[parseInt(c)]++;\r\n\t\tvar a = cnts[0];\r\n\t\tvar b = cnts[1];\r\n\t\tif (a > b) {\r\n\t\t\tvar temp = a;\r\n\t\t\ta = b;\r\n\t\t\tb = temp;\r\n\t\t}\r\n\t\tif (a === b)\r\n\t\t\tvar ans = a - 1;\r\n\t\telse\r\n\t\t\tans = a;\r\n\t\tprint(ans);\r\n\t}\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "var lines = parseInt(readline());\r\n\r\nfor (var i = 0; i < lines; i++) {\r\n print(minority(readline()));\r\n}\r\n\r\nfunction minority(s) {\r\n var zeros = 0;\r\n for (var i = 0; i < s.length; i++) {\r\n if (s[i] == \"0\") zeros++;\r\n }\r\n var ones = s.length - zeros;\r\n if (ones == zeros) return Math.max(0, zeros - 1);\r\n return Math.min(ones, zeros);\r\n}"}, {"source_code": "t= parseInt(readline()) ; \r\nwhile (t--) {\r\n\ts = readline (); \r\n\ta = 0 , b = 0 ; \r\n\tfor ( i = 0 ; i < s.length ; i ++ ) \r\n\t (s[i] == '1') ? a++ : b++ ; \r\n\t (a == b ) ? print(Math.min(a,b) -1 ) : print(Math.min(a,b)); \r\n\t}\r\n\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var one = 0;\n var zero = 0;\n for(var l = 0; l < k.length; l++){\n if(k[l] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(k.length / 2 - 1);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var one = 0;\n var zero = 0;\n var k = lines[j].split('').map(Number);\n for(var l = 0; l < k.length; l++){\n if(k[l] === 0){\n zero++;\n }else{\n one++;\n }\n }\n if(zero > one){\n console.log(one);\n }else if(zero < one){\n console.log(zero);\n }else{\n console.log(Math.floor(k.length / 2) - 1);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var h = lines[j].split('').map(Number);\n var zero = 0;\n var one = 0;\n for(k = 0; k < h.length; k++){\n if(h[k] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(h.length / 2 - 1);\n }\n }\n});"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main(){\r\n let t = readLine();\r\n while(t--){\r\n let s = readLine();\r\n let n = 0,m = 0;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '1') n++;\r\n else m++;\r\n }\r\n if(m == n && m == 1) console.log(0);\r\n else if(m == n && m > 1) console.log(m - 1);\r\n else if(m > n) console.log(n);\r\n else console.log(m);\r\n \r\n }\r\n return 0;\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tif(S.length <= 2){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar one = 0;\r\n\t\tvar zero = 0;\r\n\t\tfor(var i = 0; i < S.length; i++){\r\n\t\t\tif(S[i] == \"1\"){\r\n\t\t\t\tone++;\r\n\t\t\t}else{\r\n\t\t\t\tzero++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(one == zero){\r\n\t\t\tone--;\r\n\t\t}\r\n\t\tmyout(Math.min(one, zero));\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input =(readline());\r\n let z=0, o=0;\r\n input.split(\"\").forEach(x => x == \"0\" ? z++ : o++);\r\n if(z==o){\r\n console.log(z-1);\r\n }else{\r\n console.log(Math.min(z,o)) \r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var s = readline().split('');\r\n firstCounter = 0 ; secondCounter = 0;\r\n s.forEach((e) => {\r\n e == 0 ? firstCounter++ : secondCounter++;\r\n });\r\n if(s.length < 3){\r\n print('0');\r\n }\r\n else{\r\n if(firstCounter > secondCounter){\r\n print(secondCounter);\r\n }\r\n else if(firstCounter < secondCounter){\r\n print(firstCounter);\r\n }\r\n else{\r\n print('0');\r\n }\r\n }\r\n } "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var one = 0;\n var zero = 0;\n for(var l = 0; l < k.length; l++){\n if(k[l] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var one = 0;\n var zero = 0;\n if(k[j] == 1){\n one++;\n }else{\n zero++;\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var one = 0;\n var zero = 0;\n var k = lines[j].split('').map(Number);\n for(var l = 0; l < k.length; l++){\n if(k[l] === 0){\n zero++;\n }else{\n one++;\n }\n }\n if(zero > one){\n console.log(one);\n }else if(zero < one){\n console.log(zero);\n }else if(zero == one && k.length > 2){\n console.log(1);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var one = 0;\n var zero = 0;\n var k = lines[j].split('').map(Number);\n for(var l = 0; l < k.length; l++){\n if(k[l] === 0){\n zero++;\n }else{\n one++;\n }\n }\n var o = lines[j];\n if(zero > one){\n console.log(one);\n }else if(zero < one){\n console.log(zero);\n }else if(o == 1100){\n console.log(1);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var one = 0;\n var zero = 0;\n var k = lines[j].split('').map(Number);\n for(var l = 0; l < k.length; l++){\n if(k[l] === 0){\n zero++;\n }else{\n one++;\n }\n }\n if(zero > one){\n console.log(one);\n }else if(zero < one){\n console.log(zero);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var h = lines[j].split('').map(Number);\n var zero = 0;\n var one = 0;\n for(k = 0; k < h.length; k++){\n if(h[k] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var h = lines[j].split(' ').map(Number);\n var zero = 0;\n var one = 0;\n for(k = 0; k < h.length; k++){\n if(h[k] == 1){\n one++;\n }else{\n zero++;\n }\n }\n if(one > zero){\n console.log(zero);\n }else if(one < zero){\n console.log(one);\n }else{\n console.log(0);\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n let t = readLine();\r\n while(t--){\r\n let s = readLine();\r\n let i = 0;\r\n let j = 0;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '1')\r\n i++;\r\n else\r\n j++\r\n }\r\n if(j == i && j == 1)\r\n console.log(0);\r\n else if(j == i && j > 1)\r\n console.log(j - 1);\r\n else if(j > i)\r\n console.log(i);\r\n else \r\n console.log(j);\r\n }\r\n return 0;\r\n}"}, {"source_code": "function main(){\r\n let t = readLine();\r\n while(t--){\r\n let s = readLine();\r\n let i = 0;\r\n let j = 0;\r\n for(let i = 0; i < s.length; i++){\r\n if(s[i] == '1')\r\n i++;\r\n else\r\n j++\r\n }\r\n if(j == i && j == 1)\r\n console.log(0);\r\n else if(j == i && j > 1)\r\n console.log(j - 1);\r\n else if(j > i)\r\n console.log(i);\r\n else \r\n console.log(j);\r\n }\r\n return 0;\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar one = 0;\r\n\t\tvar zero = 0;\r\n\t\tfor(var i = 0; i < S.length; i++){\r\n\t\t\tif(S[i] == \"1\"){\r\n\t\t\t\tone++;\r\n\t\t\t}else{\r\n\t\t\t\tzero++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(one == zero){\r\n\t\t\tmyout(0);\r\n\t\t}else{\r\n\t\t\tmyout(Math.min(one, zero));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input =(readline());\r\n let z=0, o=0;\r\n input.split(\"\").forEach(x => x == \"0\" ? z++ : o++);\r\n console.log((z==o ? 0 : Math.min(z,o)))\r\n }\r\n}"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nfunction main() {\r\n let test = readLine();\r\n while(test--)\r\n {\r\n let s = readLine();\r\n let count0 = 0;\r\n let count1 = 0;\r\n if (s === '01' || s === '10') {\r\n console.log(0);\r\n }\r\n else{\r\n for (let index = 0; index < s.length; index++) {\r\n if (s[index] === '0') {\r\n count0++;\r\n }\r\n else{\r\n count1++;\r\n }\r\n \r\n }\r\n console.log(Math.min(count0, count1));\r\n }\r\n }\r\n return 0;\r\n}"}], "src_uid": "62f5798bdcea237c0df9b4cd288b97de"} {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline().split(\" \").map(Number);\n const origArr = [...numbers];\n\n let lastChanged = -1;\n for (let i = 1; i < numbers.length - 1; i++) {\n if (numbers[i - 1] < numbers[i] && numbers[i] > numbers[i + 1]) {\n if (lastChanged == i-1) {\n numbers[i - 1] = numbers[i];\n lastChanged = i-1;\n } else {\n numbers[i + 1] = numbers[i];\n lastChanged = i+1;\n }\n }\n }\n\n let nops = 0;\n for (let i = 0; i < origArr.length; i++) {\n if (numbers[i] != origArr[i]) nops++;\n }\n\n this.print(nops);\n this.print(numbers.join(\" \"));\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let ops = 0;\r\n for (let i = 1; i < arr.length - 1; i++) {\r\n if (arr[i-1] < arr[i] && arr[i] > arr[i+1]) {\r\n let val = Math.max(arr[i], arr[i+2] ? arr[i+2] : 0);\r\n ops++;\r\n arr[i+1] = val;\r\n }\r\n }\r\n\r\n output(ops);\r\n output(arr.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let sum = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (a[i] > a[i - 1] && a[i] > a[i + 1]) {\r\n var _a;\r\n a[i + 1] = Math.max(a[i], (_a = a[i + 2]) !== null && _a !== void 0 ? _a : -Infinity);\r\n sum++;\r\n }\r\n }\r\n return `${sum}\\n${a.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\n\nconst { checkPrime } = require('crypto');\nconst { Z_FIXED } = require('zlib');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, A)=>{\n let cnt = 0;\n for (let i=1; iA[i-1] && A[i]>A[i+1]){\n cnt++;\n A[i+1] = Math.max(A[i], i arr[j+1]) {\r\n arr[j+1]=Math.max(arr[j],arr[j+2] ? arr[j+2] : arr[j])\r\n count+=1\r\n }\r\n }\r\n print(count)\r\n return arr.join(' ')\r\n }\r\n "}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/* \r\n** tip1 - JS read may be string lol\r\n*/\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n /* */\r\n var nums = readline().split(' ').map(num => Number(num));\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n let i = 1 , prev = false , ct = 0\r\n while(iparseInt(v[i])){\r\n v[i] = v[i+1]\r\n }\r\n i++;\r\n ct++\r\n prev = false;\r\n }else{\r\n if(i+1parseInt(v[i+1])){\r\n prev = true\r\n }\r\n }\r\n i++\r\n }\r\n console.log(ct)\r\n console.log(v.join(\" \"))\r\n }\r\n \r\n}\r\n\r\n\r\n"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n if (i === 3110) {\r\n console.log(nums.join('9'));\r\n return;\r\n }\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(nums.join('9'));\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(nums.join('9'));\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(nums.join('0'));\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(nums.join(' '));\r\n console.log(-Object.keys(result).length);\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(-Object.keys(result).length);\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n if (i === 3110) {\r\n console.log(-1);\r\n return;\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(-1);\r\n return;\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(1);\r\n return;\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n if (i === 2) console.log(1);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(1);\r\n return;\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n console.log(1);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n console.log(1);\r\n return;\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n return;\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var cases = readline();\r\n \r\n for (var i = 0; i < cases; ++ i) {\r\n readline();\r\n var nums = readline().split(' ');\r\n var result = {};\r\n for (var j = 1; j < nums.length - 1; ++ j) {\r\n if (nums[j - 1] < nums[j] && nums[j] > nums[j + 1]) {\r\n if (result[j - 1]) {\r\n nums[j - 1] = nums[j]; \r\n } else {\r\n nums[j + 1] = nums[j];\r\n result[j + 1] = true; \r\n }\r\n }\r\n }\r\n console.log(Object.keys(result).length);\r\n console.log(nums.join(' '));\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n let i = 1 , prev = false , ct = 0\r\n while(iv[i]){\r\n v[i] = v[i+1]\r\n }\r\n i++;\r\n ct++\r\n prev = false;\r\n }else{\r\n if(i+1v[i+1]){\r\n prev = true\r\n }\r\n }\r\n i++\r\n }\r\n console.log(ct)\r\n console.log(v.join(\" \"))\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let t = parseInt(readline())\r\n while(t--){\r\n let n = parseInt(readline())\r\n let v = readline().split(\" \")\r\n let i = 1 , prev = false , ct = 0\r\n while(iv[i]){\r\n v[i] = v[i+1]\r\n }\r\n i++;\r\n ct++\r\n prev = false;\r\n }else{\r\n if(i+1v[i+1]){\r\n prev = true\r\n }\r\n }\r\n i++\r\n }\r\n console.log(ct)\r\n console.log(v)\r\n }\r\n \r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let ops = 0;\r\n for (let i = 1; i < arr.length - 1; i++) {\r\n if (arr[i-1] < arr[i] && arr[i] > arr[i+1]) {\r\n let val = Math.max(arr[i-1], arr[i+1]);\r\n ops++;\r\n arr[i] = val;\r\n }\r\n }\r\n\r\n output(ops);\r\n output(arr.join(' '));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let sum = 0;\r\n for (let i = 1; i < n - 1; i++) {\r\n if (a[i] > a[i - 1] && a[i] > a[i + 1]) {\r\n a[i + 1] = Math.max(a[i], a[i + 2]);\r\n sum++;\r\n }\r\n }\r\n return `${sum}\\n${a.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline().split(\" \").map(Number);\n const origArr = [...numbers];\n\n let lastChanged = false;\n for (let i = 1; i < numbers.length - 1; i++) {\n if (numbers[i - 1] < numbers[i] && numbers[i] > numbers[i + 1]) {\n if (lastChanged) {\n numbers[i - 1] = numbers[i];\n lastChanged = false;\n } else {\n numbers[i + 1] = numbers[i];\n lastChanged = true;\n }\n } else {\n lastChanged = false;\n }\n }\n\n let nops = 0;\n for (let i = 0; i < origArr.length; i++) {\n if (numbers[i] != origArr[i]) nops++;\n }\n\n this.print(nops);\n this.print(numbers.join(\" \"));\n}\n"}, {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline().split(\" \").map(Number);\n const origArr = [...numbers];\n\n let lastChanged = false;\n for (let i = 1; i < numbers.length - 1; i++) {\n if (numbers[i - 1] < numbers[i] && numbers[i] > numbers[i + 1]) {\n if (lastChanged) {\n numbers[i - 1] = numbers[i];\n lastChanged = false;\n } else {\n numbers[i + 1] = numbers[i];\n lastChanged = true;\n }\n }\n }\n\n let nops = 0;\n for (let i = 0; i < origArr.length; i++) {\n if (numbers[i] != origArr[i]) nops++;\n }\n\n this.print(nops);\n this.print(numbers.join(\" \"));\n}\n"}, {"source_code": "\"use strict\";\n\nconst nQueues = Number(this.readline().split(\" \"));\n\nfor (let i = 0; i < nQueues; i++) {\n const size = Number(this.readline().split(\" \"));\n const numbers = this.readline().split(\" \").map(Number);\n const origArr = [...numbers];\n\n let lastChanged = false;\n for (let i = 1; i < numbers.length - 1; i++) {\n if (numbers[i - 1] < numbers[i] && numbers[i] > numbers[i + 1]) {\n if (lastChanged || numbers[i + 1] > numbers[i - 1]) {\n numbers[i - 1] = numbers[i];\n lastChanged = false;\n } else {\n numbers[i + 1] = numbers[i];\n lastChanged = true;\n }\n }\n }\n\n let nops = 0;\n for (let i = 0; i < origArr.length; i++) {\n if (numbers[i] != origArr[i]) nops++;\n }\n\n this.print(nops);\n this.print(numbers.join(\" \"));\n}\n"}, {"source_code": "var t = readline()\r\nfor (var i = 0; i arr[j+1]) {\r\n arr[j+1]=Math.max(arr[j],arr[j+2])\r\n count+=1\r\n }\r\n }\r\n \r\n return arr.join('') + ' ' + count\r\n }\r\n "}, {"source_code": "var t = readline()\r\nfor (var i = 0; i arr[j+1]) {\r\n arr[j+1]=Math.max(arr[j],arr[j+2])\r\n count+=1\r\n }\r\n }\r\n print(arr, count)\r\n }\r\n "}], "src_uid": "255abf8750541f54d8ff0f1f80e1f8e7"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2 ; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ans = 0, max = 0;\n for(j = n- 1; j >= 0; j--){\n if(k[j] > max){\n max = k[j];\n ans++;\n }\n }\n console.log(ans-1);\n }\n }\n});\n", "positive_code": [{"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = readline();\r\n var a = readline().split(' ').map(Number);\r\n var s = -1, ans = -1;\r\n \r\n for(var j = n; j >= 0; j--) {\r\n if (a[j] > s) {\r\n s = a[j];\r\n ans++;\r\n }\r\n }\r\n print(ans);\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve([n], arr) {\r\n let count = 1, max = arr[n - 1]\r\n for (let i = n - 1; i >= 0; --i) {\r\n if (arr[i] > max) {\r\n max = arr[i]\r\n count++\r\n }\r\n }\r\n console.log(count - 1)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "async function solve() {\n let T = await int()\n while (T > 0) {\n await line()\n const a = await ints()\n const maxes = makeMaxes(a)\n let value = 0\n let i = maxes[0] + 1\n while (i < a.length) {\n value++\n i = maxes[i] + 1\n }\n print(value)\n T--\n }\n}\n\nfunction makeMaxes(a) {\n const maxes = new Array(a.length)\n let i = a.length - 1\n let m = i\n while (i >= 0) {\n if (a[i] > a[m]) m = i\n maxes[i] = m\n i--\n }\n return maxes\n}\n\n// read the input\nconst readline = require('readline')\nconst _lines = []\nlet _lineIndex = 0\nlet _ended = false\nconst _rl = readline.createInterface(process.stdin)\n_rl.on('line', (line) => _lines.push(line))\n_rl.on('end', () => (ended = true))\nconst wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))\nconst line = async () => {\n while (!_ended && _lines.length <= _lineIndex) await wait(10)\n const result = _lines[_lineIndex].trim()\n _lines[_lineIndex] = null\n _lineIndex++\n return result\n}\nconst words = async () => (await line()).split(' ')\nconst chars = async () => (await line()).split('')\nconst int = async () => parseInt(await line())\nconst ints = async () => (await words()).map((x) => parseInt(x))\nconst big = async () => BigInt(await line())\nconst bigs = async () => (await words()).map((x) => BigInt(x))\n\nconst print = console.log\n\nsolve()\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = 0;\r\n\t\tlet x = a[n-1];\r\n\t\tfor (let i = n - 1; i >= 0; i--) {\r\n\t\t\tif (x < a[i]) { x = a[i]; ans++; }\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve([n], arr) {\r\n const tmpCopy = arr.slice().sort((a, b) => a - b)\r\n const mid = Math.ceil(arr.length / 2)\r\n const pos = arr.indexOf(tmpCopy[mid])\r\n let count = 0\r\n for (let i = 0; i < pos; ++i) {\r\n if (arr[i] < tmpCopy[mid]) {\r\n count++\r\n }\r\n }\r\n console.log(count)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}], "src_uid": "451b381cc8738bebec4eeb0f02dc7849"} {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n return [prevNode, nextNode];\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = cur.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n return [prevNode, nextNode];\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inp = input.split(/\\D+/m).map(v => +v);\n var n = inp[0], q = inp[1];\n var arr = inp.slice(2, 2 + n).sort((a, b) => b - a);\n var sk = new SkipList(16);\n var skdif = new SkipList(16);\n arr.forEach(v => sk.insert(v));\n Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n for (let i = 0; i < q; i++) {\n let type = inp[2 + n + i * 2];\n let x = inp[2 + n + i * 2 + 1];\n if (type) {\n var [prevNode, nextNode] = sk.insert(x);\n if (prevNode && nextNode) {\n skdif.remove(nextNode.key - prevNode.key);\n skdif.insert(nextNode.key - x);\n skdif.insert(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.insert(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.insert(x - prevNode.key);\n }\n }\n else {\n var [prevNode, nextNode] = sk.remove(x);\n if (prevNode && nextNode) {\n skdif.insert(nextNode.key - prevNode.key);\n skdif.remove(nextNode.key - x);\n skdif.remove(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.remove(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.remove(x - prevNode.key);\n }\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n }\n})();", "positive_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), b = a.slice(), qa = Array(q);\n For(q, i => {\n qa[i] = { t: $(), x: $() }\n if (qa[i].t == 1) b.push(qa[i].x)\n });\n let m = {}, d = 0;\n b.sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);\n let n2 = 1 << Math.ceil(Math.log2(b.length));\n let it = Array(n2 * 2);\n a.forEach(v => it[n2 - 1 + m[v]] = { max: v, min: v, maxGap: 0 })\n For(n2, n2 + n2 - 1, i => { it[i] = it[i] || { max: 0, min: 1e10, maxGap: 0 } })\n let update = i => {\n let l = it[i << 1], r = it[i << 1 | 1];\n it[i] = {\n max: max(l.max, r.max),\n min: min(l.min, r.min),\n maxGap: max(l.maxGap, r.maxGap, r.min != 1e10 && l.max ? r.min - l.max : 0)\n }\n }\n ForR(n2 - 1, 1, i => { update(i) })\n log(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);\n qa.forEach(q => {\n let i = n2 - 1 + m[q.x], t = it[i]\n if (q.t == 0) { t.max = 0; t.min = 1e10; t.maxGap = 0 }\n else { t.max = q.x; t.min = q.x; t.maxGap = 0 }\n while (i > 1) update(i >>= 1);\n log(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);\n })\n // log(out.join('\\n'))\n}"}, {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n return [prevNode, nextNode];\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = cur.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n return [prevNode, nextNode];\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\D+/m).map(v => +v);\n var n = inputs[0], q = inputs[1];\n var arr = inputs.slice(2, 2 + n).sort((a, b) => b - a);\n var sk = new SkipList(20);\n var skdif = new SkipList(20);\n for (let i = 0; i < n; i++) {\n sk.insert(arr[i]);\n }\n Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n for (let i = 0; i < q; i++) {\n let type = inputs[2 + n + i * 2];\n let x = inputs[2 + n + i * 2 + 1];\n if (type) {\n var [prevNode, nextNode] = sk.insert(x);\n if (prevNode && nextNode) {\n skdif.remove(nextNode.key - prevNode.key);\n skdif.insert(nextNode.key - x);\n skdif.insert(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.insert(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.insert(x - prevNode.key);\n }\n }\n else {\n var [prevNode, nextNode] = sk.remove(x);\n if (prevNode && nextNode) {\n skdif.insert(nextNode.key - prevNode.key);\n skdif.remove(nextNode.key - x);\n skdif.remove(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.remove(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.remove(x - prevNode.key);\n }\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n }\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n a.forEach(v => t.insert(v))\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n // this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n // this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n // this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n // update(key, value) {\n // if (!this.root) return;\n // var trace = [];\n // var cur = this.root;\n // while (cur) {\n // trace.push(cur);\n // if (cur.key == key) break;\n // cur = key < cur.key ? cur.left : cur.right;\n // }\n // cur.value = value;\n // this.splay(trace);\n // }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n a.forEach(v => t.insert(v))\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n // if (this.left && this.right) {\n // this.max = Math.max(this.key, this.left.max, this.right.max);\n // this.min = Math.min(this.key, this.left.min, this.right.min);\n // this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n // } else if (this.left) {\n // this.max = Math.max(this.key, this.left.max);\n // this.min = Math.min(this.key, this.left.min);\n // this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n // } else if (this.right) {\n // this.max = Math.max(this.key, this.right.max);\n // this.min = Math.min(this.key, this.right.min);\n // this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n // } else {\n // this.max = this.key;\n // this.min = this.key;\n // this.maxGap = 0;\n // }\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n // update(key, value) {\n // if (!this.root) return;\n // var trace = [];\n // var cur = this.root;\n // while (cur) {\n // trace.push(cur);\n // if (cur.key == key) break;\n // cur = key < cur.key ? cur.left : cur.right;\n // }\n // cur.value = value;\n // this.splay(trace);\n // }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), b = a.slice(), qa = Array(q);\n For(q, i => {\n qa[i] = { t: $(), x: $() }\n if (qa[i].t == 1) b.push(qa[i].x)\n });\n let m = {}, d = 0;\n b.sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);\n let n2 = 1 << Math.ceil(Math.log2(b.length));\n let it = Array(n2 * 2);\n a.forEach(v => it[n2 - 1 + m[v]] = { max: v, min: v, maxGap: 0 })\n For(n2, n2 + n2 - 1, i => { it[i] = it[i] || { max: 0, min: 1e10, maxGap: 0 } })\n let update = i => {\n let l = it[i << 1], r = it[i << 1 | 1];\n it[i] = {\n max: max(l.max, r.max),\n min: min(l.min, r.min),\n maxGap: max(l.maxGap, r.maxGap, r.min != 1e10 && l.max ? r.min - l.max : 0)\n }\n }\n ForR(n2 - 1, 1, i => { update(i) })\n out.push(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);\n qa.forEach(q => {\n let i = n2 - 1 + m[q.x], t = it[i]\n if (q.t == 0) { t.max = 0; t.min = 1e10; t.maxGap = 0 }\n else { t.max = q.x; t.min = q.x; t.maxGap = 0 }\n while (i > 1) update(i >>= 1);\n out.push(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);\n })\n log(out.join('\\n'))\n}"}, {"source_code": "class Node {\n left; right; key; min; max;\n constructor(key) {\n this.key = key;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : -1e10, this.right ? this.right.max : -1e10);\n this.maxGap = Math.max(this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0, this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0)\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `${this.key},${this.min},${this.max}` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push[cur.left = new Node(key)];\n else trace.push[cur.right = new Node(key)];\n cur.update();\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n res() {\n if (!this.root) return 0;\n return (this.root.max - this.root.min - this.root.maxGap) || 0\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}\n\n// var t = new SplayTree();\n// var arr = Array(10).fill(0).map(v => Math.random() * 100 | 0);\n// arr.forEach(v => {\n// t.insert(v);\n// t.print();\n// });\n// console.log('---');\n// arr.forEach(v => {\n// t.remove(v);\n// t.print();\n// })\n\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inp = input.split(/\\D+/m).map(v => +v), r = 0;\n var n = inp[r++], q = inp[r++];\n var arr = inp.slice(r, r = r + n).sort((a, b) => a - b);\n var t = new SplayTree();\n arr.forEach(v => t.insert(v));\n console.log(t.res());\n for (let i = 0; i < q; i++) {\n let type = inp[r++];\n let x = inp[r++];\n if (type) t.insert(x);\n else t.remove(x);\n console.log(t.res());\n }\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n // a.forEach(v => t.insert(v))\n t.load(a.sort(asc).map(v => new Node(v)))\n // t.print()\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n }\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n this.root.update()\n s += ++k;\n }\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n a.forEach(v => t.insert(v))\n // t.load(a.sort(asc).map(v => new Node(v)))\n // t.print()\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n s += ++k;\n }\n }\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n return [prevNode, nextNode];\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = cur.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n return [prevNode, nextNode];\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var sk = new SkipList(20);\n var skdif = new SkipList(20);\n for (let i = n - 1; i >= 0; i--) {\n sk.insert(arr[i]);\n if (i > 0) skdif.insert(arr[i] - arr[i - 1]);\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n var [prevNode, nextNode] = sk.insert(x);\n if (prevNode && nextNode) {\n skdif.remove(nextNode.key - prevNode.key);\n skdif.insert(nextNode.key - x);\n skdif.insert(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.insert(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.insert(x - prevNode.key);\n }\n }\n else {\n var [prevNode, nextNode] = sk.remove(x);\n if (prevNode && nextNode) {\n skdif.insert(nextNode.key - prevNode.key);\n skdif.remove(nextNode.key - x);\n skdif.remove(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.remove(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.remove(x - prevNode.key);\n }\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n }\n})();"}, {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++) this.head.next[i] = null;\n }\n\n insert(key, search = false) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = node.next[0];\n if (search) return [prevNode, nextNode];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n return [prevNode, nextNode];\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return [];\n cur.next[0] = node.next[0];\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = cur.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n return [prevNode, nextNode];\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inp = input.split(/\\D+/m).map(v => +v);\n var n = inp[0], q = inp[1];\n var arr = inp.slice(2, 2 + n).sort((a, b) => b - a);\n var sk = new SkipList(16);\n var skdif = new SkipList(16);\n arr.forEach(v => sk.insert(v));\n Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n for (let i = 0; i < q; i++) {\n let t = inp[2 + n + i * 2];\n let x = inp[2 + n + i * 2 + 1];\n if (t) {\n var [prevNode, nextNode] = sk.insert(x);\n if (prevNode && nextNode) {\n skdif.remove(nextNode.key - prevNode.key);\n skdif.insert(nextNode.key - x);\n skdif.insert(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.insert(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.insert(x - prevNode.key);\n }\n }\n else {\n var [prevNode, nextNode] = sk.remove(x);\n if (prevNode && nextNode) {\n skdif.insert(nextNode.key - prevNode.key);\n skdif.remove(nextNode.key - x);\n skdif.remove(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.remove(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.remove(x - prevNode.key);\n }\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n }\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n a.forEach(v => t.insert(v))\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n // update(key, value) {\n // if (!this.root) return;\n // var trace = [];\n // var cur = this.root;\n // while (cur) {\n // trace.push(cur);\n // if (cur.key == key) break;\n // cur = key < cur.key ? cur.left : cur.right;\n // }\n // cur.value = value;\n // this.splay(trace);\n // }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "class Node {\n next; key;\n constructor(key, MAX_LAYER) {\n this.key = key;\n this.next = Array(MAX_LAYER);\n }\n}\n\nclass SkipList {\n head; MAX_LAYER; maxNode;\n constructor(MAX_LAYER = 3) {\n this.MAX_LAYER = MAX_LAYER;\n this.head = new Node(-1e10, MAX_LAYER);\n for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;\n }\n\n insert(key) {\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = new Node(key);\n if (this.maxNode && this.maxNode.key < key) this.maxNode = node;\n node.next[0] = cur.next[0];\n cur.next[0] = node;\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = node.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (Math.random() < 0.5) break;\n while (cur.next[i] === undefined) {\n cur = trace.pop();\n }\n node.next[i] = cur.next[i];\n cur.next[i] = node;\n }\n return [prevNode, nextNode];\n }\n\n remove(key) {\n if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;\n var cur = this.head;\n var layer = this.MAX_LAYER - 1;\n var trace = [];\n while (layer >= 0) {\n while (cur.next[layer] && cur.next[layer].key < key) {\n cur = cur.next[layer];\n }\n if (trace[trace.length - 1] != cur) trace.push(cur);\n layer--;\n }\n var node = cur.next[0];\n if (!node || node.key != key) return;\n cur.next[0] = node.next[0];\n var prevNode = cur != this.head ? cur : undefined;\n var nextNode = cur.next[0];\n for (let i = 1; i < this.MAX_LAYER; i++) {\n if (node.next[i] === undefined) break;\n while (cur.next[i] != node) {\n cur = trace.pop();\n }\n cur.next[i] = node.next[i];\n }\n return [prevNode, nextNode];\n }\n\n min() {\n return (this.head.next[0] || {}).key;\n }\n\n max() {\n if (this.maxNode) return this.maxNode.key;\n var cur = this.head;\n for (let i = this.MAX_LAYER - 1; i >= 0; i--) {\n while (cur.next[i]) cur = cur.next[i];\n }\n if (cur != this.head) this.maxNode = cur;\n return cur != this.head ? cur.key : undefined;\n }\n\n print() {\n for (let i = 0; i < this.MAX_LAYER; i++) {\n let arr = [];\n let cur = this.head.next[i];\n while (cur) {\n arr.push(cur.key);\n cur = cur.next[i];\n }\n console.log(`Layer ${i}: ${arr.join(' ')}`)\n }\n }\n}\n\n// var t = Date.now();\n// var sk = new SkipList(20);\n// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);\n// arr.forEach(v => sk.insert(v));\n// console.log(Date.now() - t);\n// arr.forEach(v => sk.remove(v));\n// console.log(Date.now() - t);\n\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n await inputPromise;\n var inputs = input.split(/\\D+/m).map(v => +v);\n var [n, q] = inputs.slice(0, 2)\n var arr = inputs.slice(2, 2 + n).sort((a, b) => a - b);\n var sk = new SkipList(20);\n var skdif = new SkipList(20);\n for (let i = n - 1; i >= 0; i--) {\n sk.insert(arr[i]);\n if (i > 0) skdif.insert(arr[i] - arr[i - 1]);\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs.slice(2 + n + i * 2, 2 + n + i * 2 + 2)\n if (type) {\n var [prevNode, nextNode] = sk.insert(x);\n if (prevNode && nextNode) {\n skdif.remove(nextNode.key - prevNode.key);\n skdif.insert(nextNode.key - x);\n skdif.insert(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.insert(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.insert(x - prevNode.key);\n }\n }\n else {\n var [prevNode, nextNode] = sk.remove(x);\n if (prevNode && nextNode) {\n skdif.insert(nextNode.key - prevNode.key);\n skdif.remove(nextNode.key - x);\n skdif.remove(x - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n skdif.remove(nextNode.key - x);\n }\n else if (prevNode && !nextNode) {\n skdif.remove(x - prevNode.key);\n }\n }\n console.log((sk.max() - sk.min() - skdif.max()) || 0);\n }\n})();"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n a.forEach(v => t.insert(v))\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n // toString() {\n // return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n // }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n // update(key, value) {\n // if (!this.root) return;\n // var trace = [];\n // var cur = this.root;\n // while (cur) {\n // trace.push(cur);\n // if (cur.key == key) break;\n // cur = key < cur.key ? cur.left : cur.right;\n // }\n // cur.value = value;\n // this.splay(trace);\n // }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n // a.forEach(v => t.insert(v))\n t.load(a.sort(asc).map(v => new Node(v)))\n // t.print()\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n s += ++k;\n }\n }\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n var append = arr[0] == 72992;\n t.load(arr);\n // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n if (append) console.log(q);\n for (let i = 0; i < q; i++) {\n console.log('???');\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(\"???2\");\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn, init) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);\n if (b < a) return [];\n let arr = Array(b - a + 1).fill(0);\n if (init) init(arr);\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n// let p = [2, 3, 5];\n// for (let i = 6; i < 1e5; i += 6) {\n// let j, x = i + 1;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// x = i + 5;\n// for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;\n// if (x % p[j] != 0) p.push(x);\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $(), q = $(), a = $(n), t = new SplayTree();\n // a.forEach(v => t.insert(v))\n t.load(a.sort(asc).map(v => new Node(v)))\n // t.print()\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n For(q, i => {\n let ty = $(), x = $()\n if (ty == 0) t.remove(x);\n else t.insert(x);\n out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n });\n log(out.join('\\n'))\n}\n\nclass Node {\n left; right; key; max; min; maxGap;\n constructor(key) {\n this.key = key;\n this.max = key;\n this.min = key;\n this.maxGap = 0;\n }\n update() {\n if (this.left && this.right) {\n this.max = Math.max(this.key, this.left.max, this.right.max);\n this.min = Math.min(this.key, this.left.min, this.right.min);\n this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)\n } else if (this.left) {\n this.max = Math.max(this.key, this.left.max);\n this.min = Math.min(this.key, this.left.min);\n this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);\n } else if (this.right) {\n this.max = Math.max(this.key, this.right.max);\n this.min = Math.min(this.key, this.right.min);\n this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);\n } else {\n this.max = this.key;\n this.min = this.key;\n this.maxGap = 0;\n }\n }\n toString() {\n return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')\n }\n}\n\nclass SplayTree {\n root;\n constructor(node) {\n this.root = node;\n }\n\n uptree(x, p, g) {\n if (!g) {\n // lazy update p, x\n if (p.left == x) {\n p.left = x.right;\n x.right = p;\n } else {\n p.right = x.left;\n x.left = p;\n }\n p.update(); x.update();\n return x;\n }\n // lazy update g, p, x\n if (g.left == p && p.left == x) {\n g.left = p.right;\n p.right = g;\n p.left = x.right;\n x.right = p;\n } else if (g.right == p && p.right == x) {\n g.right = p.left;\n p.left = g;\n p.right = x.left;\n x.left = p;\n } else if (g.left == p) {\n p.right = x.left;\n x.left = p;\n g.left = x.right;\n x.right = g;\n } else {\n p.left = x.right;\n x.right = p;\n g.right = x.left;\n x.left = g;\n }\n g.update(); p.update(); x.update();\n return x;\n }\n\n splay(trace) {\n var x = trace.pop();\n while (true) {\n var p = trace.pop();\n var g = trace.pop();\n if (!p) return this.root = x;\n if (!g || !trace.length) return this.root = this.uptree(x, p, g);\n if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);\n else trace[trace.length - 1].right = x = this.uptree(x, p, g);\n }\n }\n\n insert(key) {\n if (!this.root) return this.root = new Node(key);\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n cur = key < cur.key ? cur.left : cur.right;\n }\n cur = trace[trace.length - 1];\n if (key < cur.key) trace.push(cur.left = new Node(key));\n else trace.push(cur.right = new Node(key));\n this.splay(trace);\n }\n\n join(tree) {\n if (!this.root) return this.root = tree.root;\n var trace = [this.root];\n var cur = this.root;\n while (cur.right) trace.push(cur = cur.right);\n this.splay(trace);\n this.root.right = tree.root;\n this.root.update();\n }\n\n remove(key) {\n if (!this.root) return;\n var trace = [];\n var cur = this.root;\n while (cur) {\n trace.push(cur);\n if (cur.key == key) break;\n cur = key < cur.key ? cur.left : cur.right;\n }\n if (trace[trace.length - 1].key != key) return;\n this.splay(trace);\n var tree = new SplayTree(this.root.right);\n this.root = this.root.left;\n this.join(tree);\n }\n\n load(nodes) {\n if (!nodes.length) return;\n this.root = nodes[0];\n let s = 1, k = 1;\n while (s < nodes.length) {\n let end = Math.min(s + k, nodes.length - 1);\n this.root = nodes[s];\n this.root.left = nodes[s - k];\n for (let i = end - 1; i >= s; i--) {\n nodes[i].right = nodes[i + 1];\n nodes[i].update();\n s += ++k;\n }\n this.root.update()\n }\n }\n\n print() {\n console.log(this.root ? this.root.toString() : undefined);\n }\n}"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new AVLTree();\n var tdif = new AVLTree();\n t.load(arr, [], true);\n tdif.load(Array(n - 1).fill(0).map((v, i) => arr[i + 1] - arr[i]).sort((a, b) => a - b), [], true);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.remove(nextNode.key - prevNode.key);\n tdif.insert(nextNode.key - node.key);\n tdif.insert(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.insert(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.insert(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.insert(nextNode.key - prevNode.key);\n tdif.remove(nextNode.key - node.key);\n tdif.remove(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.remove(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.remove(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(t.max() - t.min() - tdif.max());\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nvar AVLTree = eval(`\n(function () { 'use strict';\n\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print (root, printNode) {\n if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive (parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft (node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight (node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree (comparator, noDuplicates) {\n if ( noDuplicates === void 0 ) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy () {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear () {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains (key) {\n if (this._root){\n var node = this._root;\n var comparator = this._comparator;\n while (node){\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next (node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev (node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach (callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range (low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at (index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty () {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop () {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find (key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert (key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent= null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0){ node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left= newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove (key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key= max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key= min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key= min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left= null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load (keys, values, presort) {\n if ( keys === void 0 ) keys = [];\n if ( values === void 0 ) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1 () {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString (printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})()\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n var append = arr[0] == 72992 ? 99997 : 0;\n t.load(arr);\n // for (let i = 0; i < arr.length; i++)\n // t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n if (append) console.log(append)\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.load(arr);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort();\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n if (arr[0] == 72992) {\n console.log(99998)\n console.log(99997)\n return;\n }\n t.load(arr);\n // for (let i = 0; i < arr.length; i++)\n // t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new AVLTree();\n var dif = new Heap(n + 10);\n for (let i = 0; i < n; i++) {\n t.insert(arr[i]);\n if (i > 0)\n dif.pushKey(arr[i] - arr[i - 1]);\n }\n console.log(t.max() - t.min() - dif.h[0].key);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n dif.popKey(nextNode.key - prevNode.key);\n dif.pushKey(nextNode.key - node.key);\n dif.pushKey(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n dif.pushKey(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n dif.pushKey(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n dif.pushKey(nextNode.key - prevNode.key);\n dif.popKey(nextNode.key - node.key);\n dif.popKey(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n dif.popKey(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n dif.popKey(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(dif.size ? t.max() - t.min() - dif.h[0].key : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass Heap {\n constructor(MAX_LENGTH = 100000) {\n this.h = Array(MAX_LENGTH);\n this.size = 0;\n this.map = {};\n }\n pushKey(key) {\n if (!this.map[key])\n this.map[key] = [];\n var node = { key: key };\n this.map[key].push(node);\n this.push(node);\n }\n push(node) {\n this.h[this.size] = node;\n node.id = this.size;\n this.size++;\n while (true) {\n if (node.id == 0)\n break;\n var parentId = (node.id - 1) >> 1;\n if (this.h[parentId].key < node.key) {\n this.h[node.id] = this.h[parentId];\n this.h[node.id].id = node.id;\n this.h[parentId] = node;\n node.id = parentId;\n }\n else\n break;\n }\n }\n popKey(key) {\n var _a;\n this.pop((_a = this.map[key].pop()) === null || _a === void 0 ? void 0 : _a.id);\n }\n pop(id = 0) {\n var popNode = this.h[id];\n this.size--;\n this.h[id] = this.h[this.size];\n this.h[id].id = id;\n var node = this.h[id];\n while (true) {\n var childId = node.id * 2 + 1;\n if (childId >= this.size)\n break;\n if (childId < this.size - 1 && this.h[childId].key < this.h[childId + 1].key)\n childId++;\n if (this.h[childId].key <= node.key)\n break;\n this.h[node.id] = this.h[childId];\n this.h[node.id].id = node.id;\n this.h[childId] = node;\n node.id = childId;\n }\n while (true) {\n if (node.id == 0)\n break;\n var parentId = (node.id - 1) >> 1;\n if (this.h[parentId].key < node.key) {\n this.h[node.id] = this.h[parentId];\n this.h[node.id].id = node.id;\n this.h[parentId] = node;\n node.id = parentId;\n }\n else\n break;\n }\n return popNode;\n }\n}\nvar AVLTree = eval(`\n(function () { 'use strict';\n\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print (root, printNode) {\n if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive (parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft (node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight (node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree (comparator, noDuplicates) {\n if ( noDuplicates === void 0 ) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy () {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear () {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains (key) {\n if (this._root){\n var node = this._root;\n var comparator = this._comparator;\n while (node){\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next (node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev (node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach (callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range (low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at (index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty () {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop () {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find (key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert (key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent= null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0){ node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left= newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove (key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key= max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key= min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key= min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left= null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load (keys, values, presort) {\n if ( keys === void 0 ) keys = [];\n if ( values === void 0 ) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1 () {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString (printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})()\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new RBTree();\n var tdif = new RBTree();\n for (let i = 0; i < n; i++) {\n t.insert(arr[i]);\n if (i > 0)\n tdif.insert(arr[i] - arr[i - 1]);\n }\n console.log(tdif.size ? t.max() - t.min() - tdif.max() : 0);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.remove(nextNode.key - prevNode.key);\n tdif.insert(nextNode.key - node.key);\n tdif.insert(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.insert(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.insert(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.insert(nextNode.key - prevNode.key);\n tdif.remove(nextNode.key - node.key);\n tdif.remove(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.remove(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.remove(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(tdif.size ? t.max() - t.min() - tdif.max() : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nvar RBTree = eval(`(function () {\n 'use strict';\n\n var BLACK = 1;\n var RED = 0;\n\n var Node = /** @class */ (function () {\n function Node(color, key, data, parent, left, right) {\n if (parent === void 0) { parent = null; }\n if (left === void 0) { left = null; }\n if (right === void 0) { right = null; }\n this.color = BLACK;\n this.color = color;\n this.parent = parent;\n this.left = left;\n this.right = right;\n this.key = key;\n this.data = data;\n }\n return Node;\n }());\n\n var nil = new Node(BLACK);\n var DEFAULT_COMPARE = function (a, b) { return a - b; };\n var Tree = /** @class */ (function () {\n function Tree(comparator) {\n if (comparator === void 0) { comparator = DEFAULT_COMPARE; }\n this._compare = DEFAULT_COMPARE;\n this._size = 0;\n this._compare = comparator;\n this._root = nil;\n this._size = 0;\n }\n Object.defineProperty(Tree.prototype, \"root\", {\n get: function () {\n return this._root;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Tree.prototype, \"size\", {\n get: function () {\n return this._size;\n },\n enumerable: true,\n configurable: true\n });\n Tree.prototype.isEmpty = function () {\n return this._root === nil;\n };\n Tree.prototype.find = function (key) {\n var compare = this._compare;\n var cmp, x = this._root;\n while (x !== nil) {\n cmp = compare(key, x.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n x = x.left;\n else\n x = x.right;\n }\n return x === nil ? null : x;\n };\n Tree.prototype.leftRotate = function (x) {\n var y = x.right;\n x.right = y.left;\n if (y.left !== nil)\n y.left.parent = x;\n y.parent = x.parent;\n if (x.parent === nil)\n this._root = y;\n else if (x === x.parent.left)\n x.parent.left = y;\n else\n x.parent.right = y;\n y.left = x;\n x.parent = y;\n };\n Tree.prototype.rightRotate = function (x) {\n var y = x.left;\n x.left = y.right;\n if (y.right !== nil)\n y.right.parent = x;\n y.parent = x.parent;\n if (x.parent === nil)\n this._root = y;\n else if (x === x.parent.right)\n x.parent.right = y;\n else\n x.parent.left = y;\n y.right = x;\n x.parent = y;\n };\n Tree.prototype.insertFixup = function (x) {\n this._size++;\n x.color = RED;\n var root = this._root;\n while (x !== root && x.parent.color == RED) {\n if (x.parent === x.parent.parent.left) {\n var y = x.parent.parent.right;\n if (y.color == RED) {\n x.parent.color = BLACK;\n y.color = BLACK;\n x.parent.parent.color = RED;\n x = x.parent.parent;\n }\n else {\n if (x === x.parent.right) {\n x = x.parent;\n this.leftRotate(x);\n }\n x.parent.color = BLACK;\n x.parent.parent.color = RED;\n this.rightRotate(x.parent.parent);\n }\n }\n else {\n var y = x.parent.parent.left;\n if (y.color === RED) {\n x.parent.color = BLACK;\n y.color = BLACK;\n x.parent.parent.color = RED;\n x = x.parent.parent;\n }\n else {\n if (x === x.parent.left) {\n x = x.parent;\n this.rightRotate(x);\n }\n x.parent.color = BLACK;\n x.parent.parent.color = RED;\n this.leftRotate(x.parent.parent);\n }\n }\n }\n root.color = BLACK;\n };\n Tree.prototype.insert = function (key, data) {\n var y = nil;\n var x = this._root;\n var cmp = 0;\n var compare = this._compare;\n while (x !== nil) {\n y = x;\n cmp = compare(key, x.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n x = x.left;\n else\n x = x.right;\n }\n var nz = new Node(BLACK, key, data, y, nil, nil);\n if (y === nil)\n this._root = nz;\n else if (cmp < 0)\n y.left = nz;\n else\n y.right = nz;\n this.insertFixup(nz);\n return nz;\n };\n Tree.prototype.remove = function (key) {\n var x = this._root;\n var compare = this._compare;\n while (x !== nil) {\n var cmp = compare(key, x.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n x = x.left;\n else\n x = x.right;\n }\n if (x === nil)\n return null;\n this._size--;\n return this.deleteSubtree(x);\n };\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n Tree.prototype.pop = function () {\n var min = this.minNode();\n if (min)\n this.deleteSubtree(min);\n return min;\n };\n Tree.prototype.deleteSubtree = function (z) {\n var y;\n if (z.left === nil || z.right === nil)\n y = z; // y has a nil node as a child\n else { // find tree successor with a nil node as a child\n y = z.right;\n while (y.left !== nil)\n y = y.left;\n }\n // x is y's only child\n var x = y.left !== nil ? y.left : y.right;\n x.parent = y.parent;\n if (y.parent === nil)\n this._root = x;\n else {\n if (y === y.parent.left)\n y.parent.left = x;\n else\n y.parent.right = x;\n }\n if (y !== z)\n z.key = y.key;\n if (y.color === BLACK)\n this.deleteFixup(x);\n return z;\n };\n Tree.prototype.deleteFixup = function (x) {\n var root = this._root;\n while (x !== root && x.color === BLACK) {\n if (x === x.parent.left) {\n var w = x.parent.right;\n if (w.color === RED) {\n w.color = BLACK;\n x.parent.color = RED;\n this.leftRotate(x.parent);\n w = x.parent.right;\n }\n if (w.left.color === BLACK && w.right.color === BLACK) {\n w.color = RED;\n x = x.parent;\n }\n else {\n if (w.right.color === BLACK) {\n w.left.color = BLACK;\n w.color = RED;\n this.rightRotate(w);\n w = x.parent.right;\n }\n w.color = x.parent.color;\n x.parent.color = BLACK;\n w.right.color = BLACK;\n this.leftRotate(x.parent);\n x = root;\n }\n }\n else {\n var w = x.parent.left;\n if (w.color === RED) {\n w.color = BLACK;\n x.parent.color = RED;\n this.rightRotate(x.parent);\n w = x.parent.left;\n }\n if (w.right.color === BLACK && w.left.color === BLACK) {\n w.color = RED;\n x = x.parent;\n }\n else {\n if (w.left.color == BLACK) {\n w.right.color = BLACK;\n w.color = RED;\n this.leftRotate(w);\n w = x.parent.left;\n }\n w.color = x.parent.color;\n x.parent.color = BLACK;\n w.left.color = BLACK;\n this.rightRotate(x.parent);\n x = root;\n }\n }\n }\n x.color = BLACK;\n };\n Tree.prototype.max = function () {\n var x = this._root;\n while (x !== nil && x.right !== nil)\n x = x.right;\n return x === nil ? null : x.key;\n };\n Tree.prototype.min = function () {\n var x = this._root;\n while (x !== nil && x.left !== nil)\n x = x.left;\n return x === nil ? null : x.key;\n };\n /**\n * @return {Node|null}\n */\n Tree.prototype.minNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t !== nil)\n while (t.left !== nil)\n t = t.left;\n return t === nil ? null : t;\n };\n /**\n * @return {Node|null}\n */\n Tree.prototype.maxNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t !== nil)\n while (t.right !== nil)\n t = t.right;\n return t === nil ? null : t;\n };\n /**\n * @param {Key} key\n * @return {Boolean}\n */\n Tree.prototype.contains = function (key) {\n var current = this._root;\n var compare = this._compare;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return true;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return false;\n };\n /**\n * @param {Visitor} visitor\n * @param {*=} ctx\n * @return {SplayTree}\n */\n Tree.prototype.forEach = function (visitor, ctx) {\n var current = this._root;\n var Q = []; /* Initialize stack s */\n var done = false;\n while (!done) {\n if (current !== nil) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length !== 0) {\n current = Q.pop();\n visitor.call(ctx, current);\n current = current.right;\n }\n else\n done = true;\n }\n }\n return this;\n };\n /**\n * Returns node at given index\n * @param {number} index\n * @return {?Node}\n */\n Tree.prototype.at = function (index) {\n var current = this._root, done = false, i = 0;\n var Q = [];\n while (!done) {\n if (current !== nil) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = Q.pop();\n if (i === index)\n return current;\n i++;\n current = current.right;\n }\n else\n done = true;\n }\n }\n return null;\n };\n /**\n * @param {Key} low\n * @param {Key} high\n * @param {Function} fn\n * @param {*?} ctx\n * @return {SplayTree}\n */\n Tree.prototype.range = function (low, high, fn, ctx) {\n var Q = [];\n var compare = this._compare;\n var node = this._root, cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n }\n else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n }\n else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node))\n return this; // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n /**\n * Returns array of keys\n * @return {Array}\n */\n Tree.prototype.keys = function () {\n var keys = [];\n this.forEach(function (_a) {\n var key = _a.key;\n return keys.push(key);\n });\n return keys;\n };\n /**\n * Returns array of all the data in the nodes\n * @return {Array}\n */\n Tree.prototype.values = function () {\n var values = [];\n this.forEach(function (_a) {\n var data = _a.data;\n return values.push(data);\n });\n return values;\n };\n /**\n * @param {Node} d\n * @return {Node|nil}\n */\n Tree.prototype.next = function (d) {\n var root = this._root;\n var successor = nil;\n if (d.right !== nil) {\n successor = d.right;\n while (successor.left !== nil)\n successor = successor.left;\n return successor;\n }\n var comparator = this._compare;\n while (root !== nil) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0) {\n successor = root;\n root = root.left;\n }\n else\n root = root.right;\n }\n return successor === nil ? null : successor;\n };\n /**\n * @param {Node} d\n * @return {Node|nil}\n */\n Tree.prototype.prev = function (d) {\n var root = this._root;\n var predecessor = nil;\n if (d.left !== nil) {\n predecessor = d.left;\n while (predecessor.right !== nil)\n predecessor = predecessor.right;\n return predecessor;\n }\n var comparator = this._compare;\n while (root !== nil) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n root = root.left;\n else {\n predecessor = root;\n root = root.right;\n }\n }\n return predecessor === nil ? null : predecessor;\n };\n Tree.prototype.clear = function () {\n this._root = nil;\n this._size = 0;\n return this;\n };\n Tree.nil = nil;\n return Tree;\n }());\n return Tree\n})()`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.load(arr);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n var append = arr[0] == 72992;\n t.load(arr);\n // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n if (append) console.log(q);\n for (let i = 0; i < q; i++) {\n if (append) console.log('???');\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (append) console.log(type, x, arr.includes(x));\n if (type)\n t.insert(x);\n else\n t.remove(x);\n if(append) console.log(\"???2\");\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.load(arr);\n // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new AVLTree();\n var tdif = new AVLTree();\n t.load(arr);\n tdif.load(Array(n - 1).fill(0).map((v, i) => arr[i + 1] - arr[i]));\n console.log(t.max() - t.min() - tdif.max());\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.remove(nextNode.key - prevNode.key);\n tdif.insert(nextNode.key - node.key);\n tdif.insert(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.insert(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.insert(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.insert(nextNode.key - prevNode.key);\n tdif.remove(nextNode.key - node.key);\n tdif.remove(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.remove(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.remove(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(t.max() - t.min() - tdif.max());\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nvar AVLTree = eval(`\n(function () { 'use strict';\n\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print (root, printNode) {\n if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive (parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft (node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight (node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree (comparator, noDuplicates) {\n if ( noDuplicates === void 0 ) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy () {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear () {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains (key) {\n if (this._root){\n var node = this._root;\n var comparator = this._comparator;\n while (node){\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next (node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev (node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach (callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range (low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at (index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty () {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop () {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find (key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert (key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent= null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0){ node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left= newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove (key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key= max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key= min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key= min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left= null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load (keys, values, presort) {\n if ( keys === void 0 ) keys = [];\n if ( values === void 0 ) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1 () {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString (printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})()\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new SplayTree();\n var tdif = new SplayTree();\n for (let i = 0; i < n; i++) {\n t.insert(arr[i]);\n if (i > 0)\n tdif.insert(arr[i] - arr[i - 1]);\n }\n console.log(t.max() - t.min() - tdif.max());\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.remove(nextNode.key - prevNode.key);\n tdif.insert(nextNode.key - node.key);\n tdif.insert(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.insert(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.insert(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.insert(nextNode.key - prevNode.key);\n tdif.remove(nextNode.key - node.key);\n tdif.remove(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.remove(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.remove(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(t.max() - t.min() - tdif.max());\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nvar SplayTree = eval(`\n(function () {\n var Node = /** @class */ (function () {\n function Node(key, data) {\n this.next = null;\n this.key = key;\n this.data = data;\n this.left = null;\n this.right = null;\n }\n return Node;\n }());\n\n /* follows \"An implementation of top-down splaying\"\n * by D. Sleator March 1992\n */\n function DEFAULT_COMPARE(a, b) {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n /**\n * Simple top down splay, not requiring i to be in the tree t.\n */\n function splay(i, t, comparator) {\n var N = new Node(null, null);\n var l = N;\n var r = N;\n while (true) {\n var cmp = comparator(i, t.key);\n //if (i < t.key) {\n if (cmp < 0) {\n if (t.left === null)\n break;\n //if (i < t.left.key) {\n if (comparator(i, t.left.key) < 0) {\n var y = t.left; /* rotate right */\n t.left = y.right;\n y.right = t;\n t = y;\n if (t.left === null)\n break;\n }\n r.left = t; /* link right */\n r = t;\n t = t.left;\n //} else if (i > t.key) {\n }\n else if (cmp > 0) {\n if (t.right === null)\n break;\n //if (i > t.right.key) {\n if (comparator(i, t.right.key) > 0) {\n var y = t.right; /* rotate left */\n t.right = y.left;\n y.left = t;\n t = y;\n if (t.right === null)\n break;\n }\n l.right = t; /* link left */\n l = t;\n t = t.right;\n }\n else\n break;\n }\n /* assemble */\n l.right = t.left;\n r.left = t.right;\n t.left = N.right;\n t.right = N.left;\n return t;\n }\n function insert(i, data, t, comparator) {\n var node = new Node(i, data);\n if (t === null) {\n node.left = node.right = null;\n return node;\n }\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp >= 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n return node;\n }\n function split(key, v, comparator) {\n var left = null;\n var right = null;\n if (v) {\n v = splay(key, v, comparator);\n var cmp = comparator(v.key, key);\n if (cmp === 0) {\n left = v.left;\n right = v.right;\n }\n else if (cmp < 0) {\n right = v.right;\n v.right = null;\n left = v;\n }\n else {\n left = v.left;\n v.left = null;\n right = v;\n }\n }\n return { left: left, right: right };\n }\n function merge(left, right, comparator) {\n if (right === null)\n return left;\n if (left === null)\n return right;\n right = splay(left.key, right, comparator);\n right.left = left;\n return right;\n }\n var Tree = /** @class */ (function () {\n function Tree(comparator) {\n if (comparator === void 0) { comparator = DEFAULT_COMPARE; }\n this._root = null;\n this._size = 0;\n this._comparator = comparator;\n }\n /**\n * Inserts a key, allows duplicates\n */\n Tree.prototype.insert = function (key, data) {\n this._size++;\n return this._root = insert(key, data, this._root, this._comparator);\n };\n /**\n * Adds a key, if it is not present in the tree\n */\n Tree.prototype.add = function (key, data) {\n var node = new Node(key, data);\n if (this._root === null) {\n node.left = node.right = null;\n this._size++;\n this._root = node;\n }\n var comparator = this._comparator;\n var t = splay(key, this._root, comparator);\n var cmp = comparator(key, t.key);\n if (cmp === 0)\n this._root = t;\n else {\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp > 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n this._size++;\n this._root = node;\n }\n return this._root;\n };\n /**\n * @param {Key} key\n * @return {Node|null}\n */\n Tree.prototype.remove = function (key) {\n this._root = this._remove(key, this._root, this._comparator);\n };\n /**\n * Deletes i from the tree if it's there\n */\n Tree.prototype._remove = function (i, t, comparator) {\n var x;\n if (t === null)\n return null;\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp === 0) { /* found it */\n if (t.left === null) {\n x = t.right;\n }\n else {\n x = splay(i, t.left, comparator);\n x.right = t.right;\n }\n this._size--;\n return x;\n }\n return t; /* It wasn't there */\n };\n /**\n * Removes and returns the node with smallest key\n */\n Tree.prototype.pop = function () {\n var node = this._root;\n if (node) {\n while (node.left)\n node = node.left;\n this._root = splay(node.key, this._root, this._comparator);\n this._root = this._remove(node.key, this._root, this._comparator);\n return { key: node.key, data: node.data };\n }\n return null;\n };\n /**\n * Find without splaying\n */\n Tree.prototype.findStatic = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return current;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return null;\n };\n Tree.prototype.find = function (key) {\n if (this._root) {\n this._root = splay(key, this._root, this._comparator);\n if (this._comparator(key, this._root.key) !== 0)\n return null;\n }\n return this._root;\n };\n Tree.prototype.contains = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return true;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return false;\n };\n Tree.prototype.forEach = function (visitor, ctx) {\n var current = this._root;\n var Q = []; /* Initialize stack s */\n var done = false;\n while (!done) {\n if (current !== null) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length !== 0) {\n current = Q.pop();\n visitor.call(ctx, current);\n current = current.right;\n }\n else\n done = true;\n }\n }\n return this;\n };\n\n Tree.prototype.range = function (low, high, fn, ctx) {\n var Q = [];\n var compare = this._comparator;\n var node = this._root;\n var cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n }\n else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n }\n else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node))\n return this; // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n /**\n * Returns array of keys\n */\n Tree.prototype.keys = function () {\n var keys = [];\n this.forEach(function (_a) {\n var key = _a.key;\n return keys.push(key);\n });\n return keys;\n };\n /**\n * Returns array of all the data in the nodes\n */\n Tree.prototype.values = function () {\n var values = [];\n this.forEach(function (_a) {\n var data = _a.data;\n return values.push(data);\n });\n return values;\n };\n Tree.prototype.min = function () {\n if (this._root)\n return this.minNode(this._root).key;\n return null;\n };\n Tree.prototype.max = function () {\n if (this._root)\n return this.maxNode(this._root).key;\n return null;\n };\n Tree.prototype.minNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.left)\n t = t.left;\n return t;\n };\n Tree.prototype.maxNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.right)\n t = t.right;\n return t;\n };\n /**\n * Returns node at given index\n */\n Tree.prototype.at = function (index) {\n var current = this._root;\n var done = false;\n var i = 0;\n var Q = [];\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = Q.pop();\n if (i === index)\n return current;\n i++;\n current = current.right;\n }\n else\n done = true;\n }\n }\n return null;\n };\n Tree.prototype.next = function (d) {\n var root = this._root;\n var successor = null;\n if (d.right) {\n successor = d.right;\n while (successor.left)\n successor = successor.left;\n return successor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0) {\n successor = root;\n root = root.left;\n }\n else\n root = root.right;\n }\n return successor;\n };\n Tree.prototype.prev = function (d) {\n var root = this._root;\n var predecessor = null;\n if (d.left !== null) {\n predecessor = d.left;\n while (predecessor.right)\n predecessor = predecessor.right;\n return predecessor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n root = root.left;\n else {\n predecessor = root;\n root = root.right;\n }\n }\n return predecessor;\n };\n Tree.prototype.clear = function () {\n this._root = null;\n this._size = 0;\n return this;\n };\n Tree.prototype.toList = function () {\n return toList(this._root);\n };\n /**\n * Bulk-load items. Both array have to be same size\n */\n Tree.prototype.load = function (keys, values, presort) {\n if (values === void 0) { values = []; }\n if (presort === void 0) { presort = false; }\n var size = keys.length;\n var comparator = this._comparator;\n // sort if needed\n if (presort)\n sort(keys, values, 0, size - 1, comparator);\n if (this._root === null) { // empty tree\n this._root = loadRecursive(keys, values, 0, size);\n this._size = size;\n }\n else { // that re-builds the whole tree from two in-order traversals\n var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);\n size = this._size + size;\n this._root = sortedListToBST({ head: mergedList }, 0, size);\n }\n return this;\n };\n Tree.prototype.isEmpty = function () { return this._root === null; };\n Object.defineProperty(Tree.prototype, \"size\", {\n get: function () { return this._size; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Tree.prototype, \"root\", {\n get: function () { return this._root; },\n enumerable: true,\n configurable: true\n });\n Tree.prototype.toString = function (printNode) {\n if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }\n var out = [];\n printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n };\n Tree.prototype.update = function (key, newKey, newData) {\n var comparator = this._comparator;\n var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;\n if (comparator(key, newKey) < 0) {\n right = insert(newKey, newData, right, comparator);\n }\n else {\n left = insert(newKey, newData, left, comparator);\n }\n this._root = merge(left, right, comparator);\n };\n Tree.prototype.split = function (key) {\n return split(key, this._root, this._comparator);\n };\n return Tree;\n }());\n function loadRecursive(keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = new Node(key, data);\n node.left = loadRecursive(keys, values, start, middle);\n node.right = loadRecursive(keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n function createList(keys, values) {\n var head = new Node(null, null);\n var p = head;\n for (var i = 0; i < keys.length; i++) {\n p = p.next = new Node(keys[i], values[i]);\n }\n p.next = null;\n return head.next;\n }\n function toList(root) {\n var current = root;\n var Q = [];\n var done = false;\n var head = new Node(null, null);\n var p = head;\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = p = p.next = Q.pop();\n current = current.right;\n }\n else\n done = true;\n }\n }\n p.next = null; // that'll work even if the tree was empty\n return head.next;\n }\n function sortedListToBST(list, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var left = sortedListToBST(list, start, middle);\n var root = list.head;\n root.left = left;\n list.head = list.head.next;\n root.right = sortedListToBST(list, middle + 1, end);\n return root;\n }\n return null;\n }\n function mergeLists(l1, l2, compare) {\n var head = new Node(null, null); // dummy\n var p = head;\n var p1 = l1;\n var p2 = l2;\n while (p1 !== null && p2 !== null) {\n if (compare(p1.key, p2.key) < 0) {\n p.next = p1;\n p1 = p1.next;\n }\n else {\n p.next = p2;\n p2 = p2.next;\n }\n p = p.next;\n }\n if (p1 !== null) {\n p.next = p1;\n }\n else if (p2 !== null) {\n p.next = p2;\n }\n return head.next;\n }\n function sort(keys, values, left, right, compare) {\n if (left >= right)\n return;\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n while (true) {\n do\n i++;\n while (compare(keys[i], pivot) < 0);\n do\n j--;\n while (compare(keys[j], pivot) > 0);\n if (i >= j)\n break;\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n return Tree;\n\n})();\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new SplayTree();\n var tdif = new SplayTree();\n for (let i = 0; i < n; i++) {\n t.insert(arr[i]);\n if (i > 0)\n tdif.insert(arr[i] - arr[i - 1]);\n }\n console.log(t.max() - t.min() - tdif.max());\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.remove(nextNode.key - prevNode.key);\n tdif.insert(nextNode.key - node.key);\n tdif.insert(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.insert(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.insert(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n tdif.insert(nextNode.key - prevNode.key);\n tdif.remove(nextNode.key - node.key);\n tdif.remove(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n tdif.remove(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n tdif.remove(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(t.max() - t.min() - tdif.max());\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\n// var AVLTree = eval(`\n// (function () { 'use strict';\n// /**\n// * Prints tree horizontally\n// * @param {Node} root\n// * @param {Function(node:Node):String} [printNode]\n// * @return {String}\n// */\n// function print (root, printNode) {\n// if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n// var out = [];\n// row(root, '', true, function (v) { return out.push(v); }, printNode);\n// return out.join('');\n// }\n// /**\n// * Is the tree balanced (none of the subtrees differ in height by more than 1)\n// * @param {Node} root\n// * @return {Boolean}\n// */\n// function isBalanced(root) {\n// if (root === null) { return true; } // If node is empty then return true\n// // Get the height of left and right sub trees\n// var lh = height(root.left);\n// var rh = height(root.right);\n// if (Math.abs(lh - rh) <= 1 &&\n// isBalanced(root.left) &&\n// isBalanced(root.right)) { return true; }\n// // If we reach here then tree is not height-balanced\n// return false;\n// }\n// /**\n// * The function Compute the 'height' of a tree.\n// * Height is the number of nodes along the longest path\n// * from the root node down to the farthest leaf node.\n// *\n// * @param {Node} node\n// * @return {Number}\n// */\n// function height(node) {\n// return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n// }\n// function loadRecursive (parent, keys, values, start, end) {\n// var size = end - start;\n// if (size > 0) {\n// var middle = start + Math.floor(size / 2);\n// var key = keys[middle];\n// var data = values[middle];\n// var node = { key: key, data: data, parent: parent };\n// node.left = loadRecursive(node, keys, values, start, middle);\n// node.right = loadRecursive(node, keys, values, middle + 1, end);\n// return node;\n// }\n// return null;\n// }\n// function markBalance(node) {\n// if (node === null) { return 0; }\n// var lh = markBalance(node.left);\n// var rh = markBalance(node.right);\n// node.balanceFactor = lh - rh;\n// return Math.max(lh, rh) + 1;\n// }\n// function sort(keys, values, left, right, compare) {\n// if (left >= right) { return; }\n// // eslint-disable-next-line no-bitwise\n// var pivot = keys[(left + right) >> 1];\n// var i = left - 1;\n// var j = right + 1;\n// // eslint-disable-next-line no-constant-condition\n// while (true) {\n// do { i++; } while (compare(keys[i], pivot) < 0);\n// do { j--; } while (compare(keys[j], pivot) > 0);\n// if (i >= j) { break; }\n// var tmp = keys[i];\n// keys[i] = keys[j];\n// keys[j] = tmp;\n// tmp = values[i];\n// values[i] = values[j];\n// values[j] = tmp;\n// }\n// sort(keys, values, left, j, compare);\n// sort(keys, values, j + 1, right, compare);\n// }\n// // function createNode (parent, left, right, height, key, data) {\n// // return { parent, left, right, balanceFactor: height, key, data };\n// // }\n// /**\n// * @typedef {{\n// * parent: ?Node,\n// * left: ?Node,\n// * right: ?Node,\n// * balanceFactor: number,\n// * key: Key,\n// * data: Value\n// * }} Node\n// */\n// /**\n// * @typedef {*} Key\n// */\n// /**\n// * @typedef {*} Value\n// */\n// /**\n// * Default comparison function\n// * @param {Key} a\n// * @param {Key} b\n// * @returns {number}\n// */\n// function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n// /**\n// * Single left rotation\n// * @param {Node} node\n// * @return {Node}\n// */\n// function rotateLeft (node) {\n// var rightNode = node.right;\n// node.right = rightNode.left;\n// if (rightNode.left) { rightNode.left.parent = node; }\n// rightNode.parent = node.parent;\n// if (rightNode.parent) {\n// if (rightNode.parent.left === node) {\n// rightNode.parent.left = rightNode;\n// } else {\n// rightNode.parent.right = rightNode;\n// }\n// }\n// node.parent = rightNode;\n// rightNode.left = node;\n// node.balanceFactor += 1;\n// if (rightNode.balanceFactor < 0) {\n// node.balanceFactor -= rightNode.balanceFactor;\n// }\n// rightNode.balanceFactor += 1;\n// if (node.balanceFactor > 0) {\n// rightNode.balanceFactor += node.balanceFactor;\n// }\n// return rightNode;\n// }\n// function rotateRight (node) {\n// var leftNode = node.left;\n// node.left = leftNode.right;\n// if (node.left) { node.left.parent = node; }\n// leftNode.parent = node.parent;\n// if (leftNode.parent) {\n// if (leftNode.parent.left === node) {\n// leftNode.parent.left = leftNode;\n// } else {\n// leftNode.parent.right = leftNode;\n// }\n// }\n// node.parent = leftNode;\n// leftNode.right = node;\n// node.balanceFactor -= 1;\n// if (leftNode.balanceFactor > 0) {\n// node.balanceFactor -= leftNode.balanceFactor;\n// }\n// leftNode.balanceFactor -= 1;\n// if (node.balanceFactor < 0) {\n// leftNode.balanceFactor += node.balanceFactor;\n// }\n// return leftNode;\n// }\n// // function leftBalance (node) {\n// // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n// // return rotateRight(node);\n// // }\n// // function rightBalance (node) {\n// // if (node.right.balanceFactor === 1) rotateRight(node.right);\n// // return rotateLeft(node);\n// // }\n// var AVLTree = function AVLTree (comparator, noDuplicates) {\n// if ( noDuplicates === void 0 ) noDuplicates = false;\n// this._comparator = comparator || DEFAULT_COMPARE;\n// this._root = null;\n// this._size = 0;\n// this._noDuplicates = !!noDuplicates;\n// };\n// var prototypeAccessors = { size: { configurable: true } };\n// /**\n// * Clear the tree\n// * @return {AVLTree}\n// */\n// AVLTree.prototype.destroy = function destroy () {\n// return this.clear();\n// };\n// /**\n// * Clear the tree\n// * @return {AVLTree}\n// */\n// AVLTree.prototype.clear = function clear () {\n// this._root = null;\n// this._size = 0;\n// return this;\n// };\n// /**\n// * Number of nodes\n// * @return {number}\n// */\n// prototypeAccessors.size.get = function () {\n// return this._size;\n// };\n// /**\n// * Whether the tree contains a node with the given key\n// * @param{Key} key\n// * @return {boolean} true/false\n// */\n// AVLTree.prototype.contains = function contains (key) {\n// if (this._root){\n// var node = this._root;\n// var comparator = this._comparator;\n// while (node){\n// var cmp = comparator(key, node.key);\n// if (cmp === 0) { return true; }\n// else if (cmp < 0) { node = node.left; }\n// else { node = node.right; }\n// }\n// }\n// return false;\n// };\n// /* eslint-disable class-methods-use-this */\n// /**\n// * Successor node\n// * @param{Node} node\n// * @return {?Node}\n// */\n// AVLTree.prototype.next = function next (node) {\n// var successor = node;\n// if (successor) {\n// if (successor.right) {\n// successor = successor.right;\n// while (successor.left) { successor = successor.left; }\n// } else {\n// successor = node.parent;\n// while (successor && successor.right === node) {\n// node = successor; successor = successor.parent;\n// }\n// }\n// }\n// return successor;\n// };\n// /**\n// * Predecessor node\n// * @param{Node} node\n// * @return {?Node}\n// */\n// AVLTree.prototype.prev = function prev (node) {\n// var predecessor = node;\n// if (predecessor) {\n// if (predecessor.left) {\n// predecessor = predecessor.left;\n// while (predecessor.right) { predecessor = predecessor.right; }\n// } else {\n// predecessor = node.parent;\n// while (predecessor && predecessor.left === node) {\n// node = predecessor;\n// predecessor = predecessor.parent;\n// }\n// }\n// }\n// return predecessor;\n// };\n// /* eslint-enable class-methods-use-this */\n// /**\n// * Callback for forEach\n// * @callback forEachCallback\n// * @param {Node} node\n// * @param {number} index\n// */\n// /**\n// * @param{forEachCallback} callback\n// * @return {AVLTree}\n// */\n// AVLTree.prototype.forEach = function forEach (callback) {\n// var current = this._root;\n// var s = [], done = false, i = 0;\n// while (!done) {\n// // Reach the left most Node of the current Node\n// if (current) {\n// // Place pointer to a tree node on the stack\n// // before traversing the node's left subtree\n// s.push(current);\n// current = current.left;\n// } else {\n// // BackTrack from the empty subtree and visit the Node\n// // at the top of the stack; however, if the stack is\n// // empty you are done\n// if (s.length > 0) {\n// current = s.pop();\n// callback(current, i++);\n// // We have visited the node and its left\n// // subtree. Now, it's right subtree's turn\n// current = current.right;\n// } else { done = true; }\n// }\n// }\n// return this;\n// };\n// AVLTree.prototype.range = function range (low, high, fn, ctx) {\n// var this$1 = this;\n// var Q = [];\n// var compare = this._comparator;\n// var node = this._root, cmp;\n// while (Q.length !== 0 || node) {\n// if (node) {\n// Q.push(node);\n// node = node.left;\n// } else {\n// node = Q.pop();\n// cmp = compare(node.key, high);\n// if (cmp > 0) {\n// break;\n// } else if (compare(node.key, low) >= 0) {\n// if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n// }\n// node = node.right;\n// }\n// }\n// return this;\n// };\n// /**\n// * Returns all keys in order\n// * @return {Array}\n// */\n// AVLTree.prototype.keys = function keys () {\n// var current = this._root;\n// var s = [], r = [], done = false;\n// while (!done) {\n// if (current) {\n// s.push(current);\n// current = current.left;\n// } else {\n// if (s.length > 0) {\n// current = s.pop();\n// r.push(current.key);\n// current = current.right;\n// } else { done = true; }\n// }\n// }\n// return r;\n// };\n// AVLTree.prototype.values = function values () {\n// var current = this._root;\n// var s = [], r = [], done = false;\n// while (!done) {\n// if (current) {\n// s.push(current);\n// current = current.left;\n// } else {\n// if (s.length > 0) {\n// current = s.pop();\n// r.push(current.data);\n// current = current.right;\n// } else { done = true; }\n// }\n// }\n// return r;\n// };\n// /**\n// * Returns node at given index\n// * @param{number} index\n// * @return {?Node}\n// */\n// AVLTree.prototype.at = function at (index) {\n// // removed after a consideration, more misleading than useful\n// // index = index % this.size;\n// // if (index < 0) index = this.size - index;\n// var current = this._root;\n// var s = [], done = false, i = 0;\n// while (!done) {\n// if (current) {\n// s.push(current);\n// current = current.left;\n// } else {\n// if (s.length > 0) {\n// current = s.pop();\n// if (i === index) { return current; }\n// i++;\n// current = current.right;\n// } else { done = true; }\n// }\n// }\n// return null;\n// };\n// /**\n// * Returns node with the minimum key\n// * @return {?Node}\n// */\n// AVLTree.prototype.minNode = function minNode () {\n// var node = this._root;\n// if (!node) { return null; }\n// while (node.left) { node = node.left; }\n// return node;\n// };\n// /**\n// * Returns node with the max key\n// * @return {?Node}\n// */\n// AVLTree.prototype.maxNode = function maxNode () {\n// var node = this._root;\n// if (!node) { return null; }\n// while (node.right) { node = node.right; }\n// return node;\n// };\n// /**\n// * Min key\n// * @return {?Key}\n// */\n// AVLTree.prototype.min = function min () {\n// var node = this._root;\n// if (!node) { return null; }\n// while (node.left) { node = node.left; }\n// return node.key;\n// };\n// /**\n// * Max key\n// * @return {?Key}\n// */\n// AVLTree.prototype.max = function max () {\n// var node = this._root;\n// if (!node) { return null; }\n// while (node.right) { node = node.right; }\n// return node.key;\n// };\n// /**\n// * @return {boolean} true/false\n// */\n// AVLTree.prototype.isEmpty = function isEmpty () {\n// return !this._root;\n// };\n// /**\n// * Removes and returns the node with smallest key\n// * @return {?Node}\n// */\n// AVLTree.prototype.pop = function pop () {\n// var node = this._root, returnValue = null;\n// if (node) {\n// while (node.left) { node = node.left; }\n// returnValue = { key: node.key, data: node.data };\n// this.remove(node.key);\n// }\n// return returnValue;\n// };\n// /**\n// * Find node by key\n// * @param{Key} key\n// * @return {?Node}\n// */\n// AVLTree.prototype.find = function find (key) {\n// var root = this._root;\n// // if (root === null) return null;\n// // if (key === root.key) return root;\n// var subtree = root, cmp;\n// var compare = this._comparator;\n// while (subtree) {\n// cmp = compare(key, subtree.key);\n// if (cmp === 0) { return subtree; }\n// else if (cmp < 0) { subtree = subtree.left; }\n// else { subtree = subtree.right; }\n// }\n// return null;\n// };\n// /**\n// * Insert a node into the tree\n// * @param{Key} key\n// * @param{Value} [data]\n// * @return {?Node}\n// */\n// AVLTree.prototype.insert = function insert (key, data) {\n// var this$1 = this;\n// if (!this._root) {\n// this._root = {\n// parent: null, left: null, right: null, balanceFactor: 0,\n// key: key, data: data\n// };\n// this._size++;\n// return this._root;\n// }\n// var compare = this._comparator;\n// var node = this._root;\n// var parent= null;\n// var cmp = 0;\n// if (this._noDuplicates) {\n// while (node) {\n// cmp = compare(key, node.key);\n// parent = node;\n// if (cmp === 0) { return null; }\n// else if (cmp < 0) { node = node.left; }\n// else { node = node.right; }\n// }\n// } else {\n// while (node) {\n// cmp = compare(key, node.key);\n// parent = node;\n// if (cmp <= 0){ node = node.left; } //return null;\n// else { node = node.right; }\n// }\n// }\n// var newNode = {\n// left: null,\n// right: null,\n// balanceFactor: 0,\n// parent: parent, key: key, data: data\n// };\n// var newRoot;\n// if (cmp <= 0) { parent.left= newNode; }\n// else { parent.right = newNode; }\n// while (parent) {\n// cmp = compare(parent.key, key);\n// if (cmp < 0) { parent.balanceFactor -= 1; }\n// else { parent.balanceFactor += 1; }\n// if (parent.balanceFactor === 0) { break; }\n// else if (parent.balanceFactor < -1) {\n// // inlined\n// //var newRoot = rightBalance(parent);\n// if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n// newRoot = rotateLeft(parent);\n// if (parent === this$1._root) { this$1._root = newRoot; }\n// break;\n// } else if (parent.balanceFactor > 1) {\n// // inlined\n// // var newRoot = leftBalance(parent);\n// if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n// newRoot = rotateRight(parent);\n// if (parent === this$1._root) { this$1._root = newRoot; }\n// break;\n// }\n// parent = parent.parent;\n// }\n// this._size++;\n// return newNode;\n// };\n// /**\n// * Removes the node from the tree. If not found, returns null.\n// * @param{Key} key\n// * @return {?Node}\n// */\n// AVLTree.prototype.remove = function remove (key) {\n// var this$1 = this;\n// if (!this._root) { return null; }\n// var node = this._root;\n// var compare = this._comparator;\n// var cmp = 0;\n// while (node) {\n// cmp = compare(key, node.key);\n// if (cmp === 0) { break; }\n// else if (cmp < 0) { node = node.left; }\n// else { node = node.right; }\n// }\n// if (!node) { return null; }\n// var returnValue = node.key;\n// var max, min;\n// if (node.left) {\n// max = node.left;\n// while (max.left || max.right) {\n// while (max.right) { max = max.right; }\n// node.key = max.key;\n// node.data = max.data;\n// if (max.left) {\n// node = max;\n// max = max.left;\n// }\n// }\n// node.key= max.key;\n// node.data = max.data;\n// node = max;\n// }\n// if (node.right) {\n// min = node.right;\n// while (min.left || min.right) {\n// while (min.left) { min = min.left; }\n// node.key= min.key;\n// node.data = min.data;\n// if (min.right) {\n// node = min;\n// min = min.right;\n// }\n// }\n// node.key= min.key;\n// node.data = min.data;\n// node = min;\n// }\n// var parent = node.parent;\n// var pp = node;\n// var newRoot;\n// while (parent) {\n// if (parent.left === pp) { parent.balanceFactor -= 1; }\n// else { parent.balanceFactor += 1; }\n// if (parent.balanceFactor < -1) {\n// // inlined\n// //var newRoot = rightBalance(parent);\n// if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n// newRoot = rotateLeft(parent);\n// if (parent === this$1._root) { this$1._root = newRoot; }\n// parent = newRoot;\n// } else if (parent.balanceFactor > 1) {\n// // inlined\n// // var newRoot = leftBalance(parent);\n// if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n// newRoot = rotateRight(parent);\n// if (parent === this$1._root) { this$1._root = newRoot; }\n// parent = newRoot;\n// }\n// if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n// pp = parent;\n// parent = parent.parent;\n// }\n// if (node.parent) {\n// if (node.parent.left === node) { node.parent.left= null; }\n// else { node.parent.right = null; }\n// }\n// if (node === this._root) { this._root = null; }\n// this._size--;\n// return returnValue;\n// };\n// /**\n// * Bulk-load items\n// * @param{Array}keys\n// * @param{Array}[values]\n// * @return {AVLTree}\n// */\n// AVLTree.prototype.load = function load (keys, values, presort) {\n// if ( keys === void 0 ) keys = [];\n// if ( values === void 0 ) values = [];\n// if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n// var size = keys.length;\n// if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n// this._root = loadRecursive(null, keys, values, 0, size);\n// markBalance(this._root);\n// this._size = size;\n// return this;\n// };\n// /**\n// * Returns true if the tree is balanced\n// * @return {boolean}\n// */\n// AVLTree.prototype.isBalanced = function isBalanced$1 () {\n// return isBalanced(this._root);\n// };\n// /**\n// * String representation of the tree - primitive horizontal print-out\n// * @param{Function(Node):string} [printNode]\n// * @return {string}\n// */\n// AVLTree.prototype.toString = function toString (printNode) {\n// return print(this._root, printNode);\n// };\n// Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n// AVLTree.default = AVLTree;\n// return AVLTree;\n// })()\n// `);\nvar SplayTree = eval(`\n(function () {\n var Node = /** @class */ (function () {\n function Node(key, data) {\n this.next = null;\n this.key = key;\n this.data = data;\n this.left = null;\n this.right = null;\n }\n return Node;\n }());\n\n /* follows \"An implementation of top-down splaying\"\n * by D. Sleator March 1992\n */\n function DEFAULT_COMPARE(a, b) {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n /**\n * Simple top down splay, not requiring i to be in the tree t.\n */\n function splay(i, t, comparator) {\n var N = new Node(null, null);\n var l = N;\n var r = N;\n while (true) {\n var cmp = comparator(i, t.key);\n //if (i < t.key) {\n if (cmp < 0) {\n if (t.left === null)\n break;\n //if (i < t.left.key) {\n if (comparator(i, t.left.key) < 0) {\n var y = t.left; /* rotate right */\n t.left = y.right;\n y.right = t;\n t = y;\n if (t.left === null)\n break;\n }\n r.left = t; /* link right */\n r = t;\n t = t.left;\n //} else if (i > t.key) {\n }\n else if (cmp > 0) {\n if (t.right === null)\n break;\n //if (i > t.right.key) {\n if (comparator(i, t.right.key) > 0) {\n var y = t.right; /* rotate left */\n t.right = y.left;\n y.left = t;\n t = y;\n if (t.right === null)\n break;\n }\n l.right = t; /* link left */\n l = t;\n t = t.right;\n }\n else\n break;\n }\n /* assemble */\n l.right = t.left;\n r.left = t.right;\n t.left = N.right;\n t.right = N.left;\n return t;\n }\n function insert(i, data, t, comparator) {\n var node = new Node(i, data);\n if (t === null) {\n node.left = node.right = null;\n return node;\n }\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp >= 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n return node;\n }\n function split(key, v, comparator) {\n var left = null;\n var right = null;\n if (v) {\n v = splay(key, v, comparator);\n var cmp = comparator(v.key, key);\n if (cmp === 0) {\n left = v.left;\n right = v.right;\n }\n else if (cmp < 0) {\n right = v.right;\n v.right = null;\n left = v;\n }\n else {\n left = v.left;\n v.left = null;\n right = v;\n }\n }\n return { left: left, right: right };\n }\n function merge(left, right, comparator) {\n if (right === null)\n return left;\n if (left === null)\n return right;\n right = splay(left.key, right, comparator);\n right.left = left;\n return right;\n }\n var Tree = /** @class */ (function () {\n function Tree(comparator) {\n if (comparator === void 0) { comparator = DEFAULT_COMPARE; }\n this._root = null;\n this._size = 0;\n this._comparator = comparator;\n }\n /**\n * Inserts a key, allows duplicates\n */\n Tree.prototype.insert = function (key, data) {\n this._size++;\n return this._root = insert(key, data, this._root, this._comparator);\n };\n /**\n * Adds a key, if it is not present in the tree\n */\n Tree.prototype.add = function (key, data) {\n var node = new Node(key, data);\n if (this._root === null) {\n node.left = node.right = null;\n this._size++;\n this._root = node;\n }\n var comparator = this._comparator;\n var t = splay(key, this._root, comparator);\n var cmp = comparator(key, t.key);\n if (cmp === 0)\n this._root = t;\n else {\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp > 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n this._size++;\n this._root = node;\n }\n return this._root;\n };\n /**\n * @param {Key} key\n * @return {Node|null}\n */\n Tree.prototype.remove = function (key) {\n this._root = this._remove(key, this._root, this._comparator);\n };\n /**\n * Deletes i from the tree if it's there\n */\n Tree.prototype._remove = function (i, t, comparator) {\n var x;\n if (t === null)\n return null;\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp === 0) { /* found it */\n if (t.left === null) {\n x = t.right;\n }\n else {\n x = splay(i, t.left, comparator);\n x.right = t.right;\n }\n this._size--;\n return x;\n }\n return t; /* It wasn't there */\n };\n /**\n * Removes and returns the node with smallest key\n */\n Tree.prototype.pop = function () {\n var node = this._root;\n if (node) {\n while (node.left)\n node = node.left;\n this._root = splay(node.key, this._root, this._comparator);\n this._root = this._remove(node.key, this._root, this._comparator);\n return { key: node.key, data: node.data };\n }\n return null;\n };\n /**\n * Find without splaying\n */\n Tree.prototype.findStatic = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return current;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return null;\n };\n Tree.prototype.find = function (key) {\n if (this._root) {\n this._root = splay(key, this._root, this._comparator);\n if (this._comparator(key, this._root.key) !== 0)\n return null;\n }\n return this._root;\n };\n Tree.prototype.contains = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return true;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return false;\n };\n Tree.prototype.forEach = function (visitor, ctx) {\n var current = this._root;\n var Q = []; /* Initialize stack s */\n var done = false;\n while (!done) {\n if (current !== null) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length !== 0) {\n current = Q.pop();\n visitor.call(ctx, current);\n current = current.right;\n }\n else\n done = true;\n }\n }\n return this;\n };\n\n Tree.prototype.range = function (low, high, fn, ctx) {\n var Q = [];\n var compare = this._comparator;\n var node = this._root;\n var cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n }\n else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n }\n else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node))\n return this; // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n /**\n * Returns array of keys\n */\n Tree.prototype.keys = function () {\n var keys = [];\n this.forEach(function (_a) {\n var key = _a.key;\n return keys.push(key);\n });\n return keys;\n };\n /**\n * Returns array of all the data in the nodes\n */\n Tree.prototype.values = function () {\n var values = [];\n this.forEach(function (_a) {\n var data = _a.data;\n return values.push(data);\n });\n return values;\n };\n Tree.prototype.min = function () {\n if (this._root)\n return this.minNode(this._root).key;\n return null;\n };\n Tree.prototype.max = function () {\n if (this._root)\n return this.maxNode(this._root).key;\n return null;\n };\n Tree.prototype.minNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.left)\n t = t.left;\n return t;\n };\n Tree.prototype.maxNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.right)\n t = t.right;\n return t;\n };\n /**\n * Returns node at given index\n */\n Tree.prototype.at = function (index) {\n var current = this._root;\n var done = false;\n var i = 0;\n var Q = [];\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = Q.pop();\n if (i === index)\n return current;\n i++;\n current = current.right;\n }\n else\n done = true;\n }\n }\n return null;\n };\n Tree.prototype.next = function (d) {\n var root = this._root;\n var successor = null;\n if (d.right) {\n successor = d.right;\n while (successor.left)\n successor = successor.left;\n return successor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0) {\n successor = root;\n root = root.left;\n }\n else\n root = root.right;\n }\n return successor;\n };\n Tree.prototype.prev = function (d) {\n var root = this._root;\n var predecessor = null;\n if (d.left !== null) {\n predecessor = d.left;\n while (predecessor.right)\n predecessor = predecessor.right;\n return predecessor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n root = root.left;\n else {\n predecessor = root;\n root = root.right;\n }\n }\n return predecessor;\n };\n Tree.prototype.clear = function () {\n this._root = null;\n this._size = 0;\n return this;\n };\n Tree.prototype.toList = function () {\n return toList(this._root);\n };\n /**\n * Bulk-load items. Both array have to be same size\n */\n Tree.prototype.load = function (keys, values, presort) {\n if (values === void 0) { values = []; }\n if (presort === void 0) { presort = false; }\n var size = keys.length;\n var comparator = this._comparator;\n // sort if needed\n if (presort)\n sort(keys, values, 0, size - 1, comparator);\n if (this._root === null) { // empty tree\n this._root = loadRecursive(keys, values, 0, size);\n this._size = size;\n }\n else { // that re-builds the whole tree from two in-order traversals\n var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);\n size = this._size + size;\n this._root = sortedListToBST({ head: mergedList }, 0, size);\n }\n return this;\n };\n Tree.prototype.isEmpty = function () { return this._root === null; };\n Object.defineProperty(Tree.prototype, \"size\", {\n get: function () { return this._size; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Tree.prototype, \"root\", {\n get: function () { return this._root; },\n enumerable: true,\n configurable: true\n });\n Tree.prototype.toString = function (printNode) {\n if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }\n var out = [];\n printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n };\n Tree.prototype.update = function (key, newKey, newData) {\n var comparator = this._comparator;\n var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;\n if (comparator(key, newKey) < 0) {\n right = insert(newKey, newData, right, comparator);\n }\n else {\n left = insert(newKey, newData, left, comparator);\n }\n this._root = merge(left, right, comparator);\n };\n Tree.prototype.split = function (key) {\n return split(key, this._root, this._comparator);\n };\n return Tree;\n }());\n function loadRecursive(keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = new Node(key, data);\n node.left = loadRecursive(keys, values, start, middle);\n node.right = loadRecursive(keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n function createList(keys, values) {\n var head = new Node(null, null);\n var p = head;\n for (var i = 0; i < keys.length; i++) {\n p = p.next = new Node(keys[i], values[i]);\n }\n p.next = null;\n return head.next;\n }\n function toList(root) {\n var current = root;\n var Q = [];\n var done = false;\n var head = new Node(null, null);\n var p = head;\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = p = p.next = Q.pop();\n current = current.right;\n }\n else\n done = true;\n }\n }\n p.next = null; // that'll work even if the tree was empty\n return head.next;\n }\n function sortedListToBST(list, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var left = sortedListToBST(list, start, middle);\n var root = list.head;\n root.left = left;\n list.head = list.head.next;\n root.right = sortedListToBST(list, middle + 1, end);\n return root;\n }\n return null;\n }\n function mergeLists(l1, l2, compare) {\n var head = new Node(null, null); // dummy\n var p = head;\n var p1 = l1;\n var p2 = l2;\n while (p1 !== null && p2 !== null) {\n if (compare(p1.key, p2.key) < 0) {\n p.next = p1;\n p1 = p1.next;\n }\n else {\n p.next = p2;\n p2 = p2.next;\n }\n p = p.next;\n }\n if (p1 !== null) {\n p.next = p1;\n }\n else if (p2 !== null) {\n p.next = p2;\n }\n return head.next;\n }\n function sort(keys, values, left, right, compare) {\n if (left >= right)\n return;\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n while (true) {\n do\n i++;\n while (compare(keys[i], pivot) < 0);\n do\n j--;\n while (compare(keys[j], pivot) > 0);\n if (i >= j)\n break;\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n return Tree;\n\n})();\n`);\nvar SplayTree = eval(`\n(function () {\n var Node = /** @class */ (function () {\n function Node(key, data) {\n this.next = null;\n this.key = key;\n this.data = data;\n this.left = null;\n this.right = null;\n }\n return Node;\n }());\n\n /* follows \"An implementation of top-down splaying\"\n * by D. Sleator March 1992\n */\n function DEFAULT_COMPARE(a, b) {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n /**\n * Simple top down splay, not requiring i to be in the tree t.\n */\n function splay(i, t, comparator) {\n var N = new Node(null, null);\n var l = N;\n var r = N;\n while (true) {\n var cmp = comparator(i, t.key);\n //if (i < t.key) {\n if (cmp < 0) {\n if (t.left === null)\n break;\n //if (i < t.left.key) {\n if (comparator(i, t.left.key) < 0) {\n var y = t.left; /* rotate right */\n t.left = y.right;\n y.right = t;\n t = y;\n if (t.left === null)\n break;\n }\n r.left = t; /* link right */\n r = t;\n t = t.left;\n //} else if (i > t.key) {\n }\n else if (cmp > 0) {\n if (t.right === null)\n break;\n //if (i > t.right.key) {\n if (comparator(i, t.right.key) > 0) {\n var y = t.right; /* rotate left */\n t.right = y.left;\n y.left = t;\n t = y;\n if (t.right === null)\n break;\n }\n l.right = t; /* link left */\n l = t;\n t = t.right;\n }\n else\n break;\n }\n /* assemble */\n l.right = t.left;\n r.left = t.right;\n t.left = N.right;\n t.right = N.left;\n return t;\n }\n function insert(i, data, t, comparator) {\n var node = new Node(i, data);\n if (t === null) {\n node.left = node.right = null;\n return node;\n }\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp >= 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n return node;\n }\n function split(key, v, comparator) {\n var left = null;\n var right = null;\n if (v) {\n v = splay(key, v, comparator);\n var cmp = comparator(v.key, key);\n if (cmp === 0) {\n left = v.left;\n right = v.right;\n }\n else if (cmp < 0) {\n right = v.right;\n v.right = null;\n left = v;\n }\n else {\n left = v.left;\n v.left = null;\n right = v;\n }\n }\n return { left: left, right: right };\n }\n function merge(left, right, comparator) {\n if (right === null)\n return left;\n if (left === null)\n return right;\n right = splay(left.key, right, comparator);\n right.left = left;\n return right;\n }\n var Tree = /** @class */ (function () {\n function Tree(comparator) {\n if (comparator === void 0) { comparator = DEFAULT_COMPARE; }\n this._root = null;\n this._size = 0;\n this._comparator = comparator;\n }\n /**\n * Inserts a key, allows duplicates\n */\n Tree.prototype.insert = function (key, data) {\n this._size++;\n return this._root = insert(key, data, this._root, this._comparator);\n };\n /**\n * Adds a key, if it is not present in the tree\n */\n Tree.prototype.add = function (key, data) {\n var node = new Node(key, data);\n if (this._root === null) {\n node.left = node.right = null;\n this._size++;\n this._root = node;\n }\n var comparator = this._comparator;\n var t = splay(key, this._root, comparator);\n var cmp = comparator(key, t.key);\n if (cmp === 0)\n this._root = t;\n else {\n if (cmp < 0) {\n node.left = t.left;\n node.right = t;\n t.left = null;\n }\n else if (cmp > 0) {\n node.right = t.right;\n node.left = t;\n t.right = null;\n }\n this._size++;\n this._root = node;\n }\n return this._root;\n };\n /**\n * @param {Key} key\n * @return {Node|null}\n */\n Tree.prototype.remove = function (key) {\n this._root = this._remove(key, this._root, this._comparator);\n };\n /**\n * Deletes i from the tree if it's there\n */\n Tree.prototype._remove = function (i, t, comparator) {\n var x;\n if (t === null)\n return null;\n t = splay(i, t, comparator);\n var cmp = comparator(i, t.key);\n if (cmp === 0) { /* found it */\n if (t.left === null) {\n x = t.right;\n }\n else {\n x = splay(i, t.left, comparator);\n x.right = t.right;\n }\n this._size--;\n return x;\n }\n return t; /* It wasn't there */\n };\n /**\n * Removes and returns the node with smallest key\n */\n Tree.prototype.pop = function () {\n var node = this._root;\n if (node) {\n while (node.left)\n node = node.left;\n this._root = splay(node.key, this._root, this._comparator);\n this._root = this._remove(node.key, this._root, this._comparator);\n return { key: node.key, data: node.data };\n }\n return null;\n };\n /**\n * Find without splaying\n */\n Tree.prototype.findStatic = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return current;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return null;\n };\n Tree.prototype.find = function (key) {\n if (this._root) {\n this._root = splay(key, this._root, this._comparator);\n if (this._comparator(key, this._root.key) !== 0)\n return null;\n }\n return this._root;\n };\n Tree.prototype.contains = function (key) {\n var current = this._root;\n var compare = this._comparator;\n while (current) {\n var cmp = compare(key, current.key);\n if (cmp === 0)\n return true;\n else if (cmp < 0)\n current = current.left;\n else\n current = current.right;\n }\n return false;\n };\n Tree.prototype.forEach = function (visitor, ctx) {\n var current = this._root;\n var Q = []; /* Initialize stack s */\n var done = false;\n while (!done) {\n if (current !== null) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length !== 0) {\n current = Q.pop();\n visitor.call(ctx, current);\n current = current.right;\n }\n else\n done = true;\n }\n }\n return this;\n };\n\n Tree.prototype.range = function (low, high, fn, ctx) {\n var Q = [];\n var compare = this._comparator;\n var node = this._root;\n var cmp;\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n }\n else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n }\n else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node))\n return this; // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n /**\n * Returns array of keys\n */\n Tree.prototype.keys = function () {\n var keys = [];\n this.forEach(function (_a) {\n var key = _a.key;\n return keys.push(key);\n });\n return keys;\n };\n /**\n * Returns array of all the data in the nodes\n */\n Tree.prototype.values = function () {\n var values = [];\n this.forEach(function (_a) {\n var data = _a.data;\n return values.push(data);\n });\n return values;\n };\n Tree.prototype.min = function () {\n if (this._root)\n return this.minNode(this._root).key;\n return null;\n };\n Tree.prototype.max = function () {\n if (this._root)\n return this.maxNode(this._root).key;\n return null;\n };\n Tree.prototype.minNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.left)\n t = t.left;\n return t;\n };\n Tree.prototype.maxNode = function (t) {\n if (t === void 0) { t = this._root; }\n if (t)\n while (t.right)\n t = t.right;\n return t;\n };\n /**\n * Returns node at given index\n */\n Tree.prototype.at = function (index) {\n var current = this._root;\n var done = false;\n var i = 0;\n var Q = [];\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = Q.pop();\n if (i === index)\n return current;\n i++;\n current = current.right;\n }\n else\n done = true;\n }\n }\n return null;\n };\n Tree.prototype.next = function (d) {\n var root = this._root;\n var successor = null;\n if (d.right) {\n successor = d.right;\n while (successor.left)\n successor = successor.left;\n return successor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0) {\n successor = root;\n root = root.left;\n }\n else\n root = root.right;\n }\n return successor;\n };\n Tree.prototype.prev = function (d) {\n var root = this._root;\n var predecessor = null;\n if (d.left !== null) {\n predecessor = d.left;\n while (predecessor.right)\n predecessor = predecessor.right;\n return predecessor;\n }\n var comparator = this._comparator;\n while (root) {\n var cmp = comparator(d.key, root.key);\n if (cmp === 0)\n break;\n else if (cmp < 0)\n root = root.left;\n else {\n predecessor = root;\n root = root.right;\n }\n }\n return predecessor;\n };\n Tree.prototype.clear = function () {\n this._root = null;\n this._size = 0;\n return this;\n };\n Tree.prototype.toList = function () {\n return toList(this._root);\n };\n /**\n * Bulk-load items. Both array have to be same size\n */\n Tree.prototype.load = function (keys, values, presort) {\n if (values === void 0) { values = []; }\n if (presort === void 0) { presort = false; }\n var size = keys.length;\n var comparator = this._comparator;\n // sort if needed\n if (presort)\n sort(keys, values, 0, size - 1, comparator);\n if (this._root === null) { // empty tree\n this._root = loadRecursive(keys, values, 0, size);\n this._size = size;\n }\n else { // that re-builds the whole tree from two in-order traversals\n var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);\n size = this._size + size;\n this._root = sortedListToBST({ head: mergedList }, 0, size);\n }\n return this;\n };\n Tree.prototype.isEmpty = function () { return this._root === null; };\n Object.defineProperty(Tree.prototype, \"size\", {\n get: function () { return this._size; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Tree.prototype, \"root\", {\n get: function () { return this._root; },\n enumerable: true,\n configurable: true\n });\n Tree.prototype.toString = function (printNode) {\n if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }\n var out = [];\n printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n };\n Tree.prototype.update = function (key, newKey, newData) {\n var comparator = this._comparator;\n var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;\n if (comparator(key, newKey) < 0) {\n right = insert(newKey, newData, right, comparator);\n }\n else {\n left = insert(newKey, newData, left, comparator);\n }\n this._root = merge(left, right, comparator);\n };\n Tree.prototype.split = function (key) {\n return split(key, this._root, this._comparator);\n };\n return Tree;\n }());\n function loadRecursive(keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = new Node(key, data);\n node.left = loadRecursive(keys, values, start, middle);\n node.right = loadRecursive(keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n function createList(keys, values) {\n var head = new Node(null, null);\n var p = head;\n for (var i = 0; i < keys.length; i++) {\n p = p.next = new Node(keys[i], values[i]);\n }\n p.next = null;\n return head.next;\n }\n function toList(root) {\n var current = root;\n var Q = [];\n var done = false;\n var head = new Node(null, null);\n var p = head;\n while (!done) {\n if (current) {\n Q.push(current);\n current = current.left;\n }\n else {\n if (Q.length > 0) {\n current = p = p.next = Q.pop();\n current = current.right;\n }\n else\n done = true;\n }\n }\n p.next = null; // that'll work even if the tree was empty\n return head.next;\n }\n function sortedListToBST(list, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var left = sortedListToBST(list, start, middle);\n var root = list.head;\n root.left = left;\n list.head = list.head.next;\n root.right = sortedListToBST(list, middle + 1, end);\n return root;\n }\n return null;\n }\n function mergeLists(l1, l2, compare) {\n var head = new Node(null, null); // dummy\n var p = head;\n var p1 = l1;\n var p2 = l2;\n while (p1 !== null && p2 !== null) {\n if (compare(p1.key, p2.key) < 0) {\n p.next = p1;\n p1 = p1.next;\n }\n else {\n p.next = p2;\n p2 = p2.next;\n }\n p = p.next;\n }\n if (p1 !== null) {\n p.next = p1;\n }\n else if (p2 !== null) {\n p.next = p2;\n }\n return head.next;\n }\n function sort(keys, values, left, right, compare) {\n if (left >= right)\n return;\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n while (true) {\n do\n i++;\n while (compare(keys[i], pivot) < 0);\n do\n j--;\n while (compare(keys[j], pivot) > 0);\n if (i >= j)\n break;\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n return Tree;\n\n})();\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);\n var t = new AVLTree();\n var dif = new Heap();\n var mapId = {};\n for (let i = 0; i < n; i++) {\n t.insert(arr[i]);\n if (i > 0)\n dif.pushKey(arr[i] - arr[i - 1]);\n }\n console.log(t.max() - t.min() - dif.h[0].key);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type) {\n t.insert(x);\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n dif.popKey(nextNode.key - prevNode.key);\n dif.pushKey(nextNode.key - node.key);\n dif.pushKey(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n dif.pushKey(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n dif.pushKey(node.key - prevNode.key);\n }\n }\n else {\n var node = t.find(x);\n var prevNode = t.prev(node);\n var nextNode = t.next(node);\n if (prevNode && nextNode) {\n dif.pushKey(nextNode.key - prevNode.key);\n dif.popKey(nextNode.key - node.key);\n dif.popKey(node.key - prevNode.key);\n }\n else if (!prevNode && nextNode) {\n dif.popKey(nextNode.key - node.key);\n }\n else if (prevNode && !nextNode) {\n dif.popKey(node.key - prevNode.key);\n }\n t.remove(x);\n }\n console.log(dif.size ? t.max() - t.min() - dif.h[0].key : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass Heap {\n constructor(MAX_LENGTH = 100000) {\n this.h = Array(MAX_LENGTH);\n this.size = 0;\n this.map = {};\n }\n pushKey(key) {\n if (!this.map[key])\n this.map[key] = [];\n var node = { key: key };\n this.map[key].push(node);\n this.push(node);\n }\n push(node) {\n this.h[this.size] = node;\n node.id = this.size;\n this.size++;\n while (true) {\n if (node.id == 0)\n break;\n var parentId = (node.id - 1) >> 1;\n if (this.h[parentId].key < node.key) {\n this.h[node.id] = this.h[parentId];\n this.h[node.id].id = node.id;\n this.h[parentId] = node;\n node.id = parentId;\n }\n else\n break;\n }\n }\n popKey(key) {\n var _a;\n this.pop((_a = this.map[key].pop()) === null || _a === void 0 ? void 0 : _a.id);\n }\n pop(id = 0) {\n var popNode = this.h[id];\n this.size--;\n this.h[id] = this.h[this.size];\n this.h[id].id = id;\n var node = this.h[id];\n while (true) {\n var childId = node.id * 2 + 1;\n if (childId >= this.size)\n break;\n if (childId < this.size - 1 && this.h[childId].key < this.h[childId + 1].key)\n childId++;\n if (this.h[childId].key <= node.key)\n break;\n this.h[node.id] = this.h[childId];\n this.h[node.id].id = node.id;\n this.h[childId] = node;\n node.id = childId;\n }\n while (true) {\n if (node.id == 0)\n break;\n var parentId = (node.id - 1) >> 1;\n if (this.h[parentId].key < node.key) {\n this.h[node.id] = this.h[parentId];\n this.h[node.id].id = node.id;\n this.h[parentId] = node;\n node.id = parentId;\n }\n else\n break;\n }\n return popNode;\n }\n}\nvar AVLTree = eval(`\n(function () { 'use strict';\n\n /**\n * Prints tree horizontally\n * @param {Node} root\n * @param {Function(node:Node):String} [printNode]\n * @return {String}\n */\n function print (root, printNode) {\n if ( printNode === void 0 ) printNode = function (n) { return n.key; };\n\n var out = [];\n row(root, '', true, function (v) { return out.push(v); }, printNode);\n return out.join('');\n }\n\n\n /**\n * Is the tree balanced (none of the subtrees differ in height by more than 1)\n * @param {Node} root\n * @return {Boolean}\n */\n function isBalanced(root) {\n if (root === null) { return true; } // If node is empty then return true\n\n // Get the height of left and right sub trees\n var lh = height(root.left);\n var rh = height(root.right);\n\n if (Math.abs(lh - rh) <= 1 &&\n isBalanced(root.left) &&\n isBalanced(root.right)) { return true; }\n\n // If we reach here then tree is not height-balanced\n return false;\n }\n\n /**\n * The function Compute the 'height' of a tree.\n * Height is the number of nodes along the longest path\n * from the root node down to the farthest leaf node.\n *\n * @param {Node} node\n * @return {Number}\n */\n function height(node) {\n return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;\n }\n\n\n function loadRecursive (parent, keys, values, start, end) {\n var size = end - start;\n if (size > 0) {\n var middle = start + Math.floor(size / 2);\n var key = keys[middle];\n var data = values[middle];\n var node = { key: key, data: data, parent: parent };\n node.left = loadRecursive(node, keys, values, start, middle);\n node.right = loadRecursive(node, keys, values, middle + 1, end);\n return node;\n }\n return null;\n }\n\n\n function markBalance(node) {\n if (node === null) { return 0; }\n var lh = markBalance(node.left);\n var rh = markBalance(node.right);\n\n node.balanceFactor = lh - rh;\n return Math.max(lh, rh) + 1;\n }\n\n\n function sort(keys, values, left, right, compare) {\n if (left >= right) { return; }\n\n // eslint-disable-next-line no-bitwise\n var pivot = keys[(left + right) >> 1];\n var i = left - 1;\n var j = right + 1;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n do { i++; } while (compare(keys[i], pivot) < 0);\n do { j--; } while (compare(keys[j], pivot) > 0);\n if (i >= j) { break; }\n\n var tmp = keys[i];\n keys[i] = keys[j];\n keys[j] = tmp;\n\n tmp = values[i];\n values[i] = values[j];\n values[j] = tmp;\n }\n\n sort(keys, values, left, j, compare);\n sort(keys, values, j + 1, right, compare);\n }\n\n // function createNode (parent, left, right, height, key, data) {\n // return { parent, left, right, balanceFactor: height, key, data };\n // }\n\n /**\n * @typedef {{\n * parent: ?Node,\n * left: ?Node,\n * right: ?Node,\n * balanceFactor: number,\n * key: Key,\n * data: Value\n * }} Node\n */\n\n /**\n * @typedef {*} Key\n */\n\n /**\n * @typedef {*} Value\n */\n\n /**\n * Default comparison function\n * @param {Key} a\n * @param {Key} b\n * @returns {number}\n */\n function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }\n\n\n /**\n * Single left rotation\n * @param {Node} node\n * @return {Node}\n */\n function rotateLeft (node) {\n var rightNode = node.right;\n node.right = rightNode.left;\n\n if (rightNode.left) { rightNode.left.parent = node; }\n\n rightNode.parent = node.parent;\n if (rightNode.parent) {\n if (rightNode.parent.left === node) {\n rightNode.parent.left = rightNode;\n } else {\n rightNode.parent.right = rightNode;\n }\n }\n\n node.parent = rightNode;\n rightNode.left = node;\n\n node.balanceFactor += 1;\n if (rightNode.balanceFactor < 0) {\n node.balanceFactor -= rightNode.balanceFactor;\n }\n\n rightNode.balanceFactor += 1;\n if (node.balanceFactor > 0) {\n rightNode.balanceFactor += node.balanceFactor;\n }\n return rightNode;\n }\n\n\n function rotateRight (node) {\n var leftNode = node.left;\n node.left = leftNode.right;\n if (node.left) { node.left.parent = node; }\n\n leftNode.parent = node.parent;\n if (leftNode.parent) {\n if (leftNode.parent.left === node) {\n leftNode.parent.left = leftNode;\n } else {\n leftNode.parent.right = leftNode;\n }\n }\n\n node.parent = leftNode;\n leftNode.right = node;\n\n node.balanceFactor -= 1;\n if (leftNode.balanceFactor > 0) {\n node.balanceFactor -= leftNode.balanceFactor;\n }\n\n leftNode.balanceFactor -= 1;\n if (node.balanceFactor < 0) {\n leftNode.balanceFactor += node.balanceFactor;\n }\n\n return leftNode;\n }\n\n\n // function leftBalance (node) {\n // if (node.left.balanceFactor === -1) rotateLeft(node.left);\n // return rotateRight(node);\n // }\n\n\n // function rightBalance (node) {\n // if (node.right.balanceFactor === 1) rotateRight(node.right);\n // return rotateLeft(node);\n // }\n\n\n var AVLTree = function AVLTree (comparator, noDuplicates) {\n if ( noDuplicates === void 0 ) noDuplicates = false;\n\n this._comparator = comparator || DEFAULT_COMPARE;\n this._root = null;\n this._size = 0;\n this._noDuplicates = !!noDuplicates;\n };\n\n var prototypeAccessors = { size: { configurable: true } };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.destroy = function destroy () {\n return this.clear();\n };\n\n\n /**\n * Clear the tree\n * @return {AVLTree}\n */\n AVLTree.prototype.clear = function clear () {\n this._root = null;\n this._size = 0;\n return this;\n };\n\n /**\n * Number of nodes\n * @return {number}\n */\n prototypeAccessors.size.get = function () {\n return this._size;\n };\n\n\n /**\n * Whether the tree contains a node with the given key\n * @param{Key} key\n * @return {boolean} true/false\n */\n AVLTree.prototype.contains = function contains (key) {\n if (this._root){\n var node = this._root;\n var comparator = this._comparator;\n while (node){\n var cmp = comparator(key, node.key);\n if (cmp === 0) { return true; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n }\n return false;\n };\n\n\n /* eslint-disable class-methods-use-this */\n\n /**\n * Successor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.next = function next (node) {\n var successor = node;\n if (successor) {\n if (successor.right) {\n successor = successor.right;\n while (successor.left) { successor = successor.left; }\n } else {\n successor = node.parent;\n while (successor && successor.right === node) {\n node = successor; successor = successor.parent;\n }\n }\n }\n return successor;\n };\n\n\n /**\n * Predecessor node\n * @param{Node} node\n * @return {?Node}\n */\n AVLTree.prototype.prev = function prev (node) {\n var predecessor = node;\n if (predecessor) {\n if (predecessor.left) {\n predecessor = predecessor.left;\n while (predecessor.right) { predecessor = predecessor.right; }\n } else {\n predecessor = node.parent;\n while (predecessor && predecessor.left === node) {\n node = predecessor;\n predecessor = predecessor.parent;\n }\n }\n }\n return predecessor;\n };\n /* eslint-enable class-methods-use-this */\n\n\n /**\n * Callback for forEach\n * @callback forEachCallback\n * @param {Node} node\n * @param {number} index\n */\n\n /**\n * @param{forEachCallback} callback\n * @return {AVLTree}\n */\n AVLTree.prototype.forEach = function forEach (callback) {\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n // Reach the left most Node of the current Node\n if (current) {\n // Place pointer to a tree node on the stack\n // before traversing the node's left subtree\n s.push(current);\n current = current.left;\n } else {\n // BackTrack from the empty subtree and visit the Node\n // at the top of the stack; however, if the stack is\n // empty you are done\n if (s.length > 0) {\n current = s.pop();\n callback(current, i++);\n\n // We have visited the node and its left\n // subtree. Now, it's right subtree's turn\n current = current.right;\n } else { done = true; }\n }\n }\n return this;\n };\n\n\n AVLTree.prototype.range = function range (low, high, fn, ctx) {\n var this$1 = this;\n\n var Q = [];\n var compare = this._comparator;\n var node = this._root, cmp;\n\n while (Q.length !== 0 || node) {\n if (node) {\n Q.push(node);\n node = node.left;\n } else {\n node = Q.pop();\n cmp = compare(node.key, high);\n if (cmp > 0) {\n break;\n } else if (compare(node.key, low) >= 0) {\n if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned\n }\n node = node.right;\n }\n }\n return this;\n };\n\n\n /**\n * Returns all keys in order\n * @return {Array}\n */\n AVLTree.prototype.keys = function keys () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.key);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n AVLTree.prototype.values = function values () {\n var current = this._root;\n var s = [], r = [], done = false;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n r.push(current.data);\n current = current.right;\n } else { done = true; }\n }\n }\n return r;\n };\n\n\n /**\n * Returns node at given index\n * @param{number} index\n * @return {?Node}\n */\n AVLTree.prototype.at = function at (index) {\n // removed after a consideration, more misleading than useful\n // index = index % this.size;\n // if (index < 0) index = this.size - index;\n\n var current = this._root;\n var s = [], done = false, i = 0;\n\n while (!done) {\n if (current) {\n s.push(current);\n current = current.left;\n } else {\n if (s.length > 0) {\n current = s.pop();\n if (i === index) { return current; }\n i++;\n current = current.right;\n } else { done = true; }\n }\n }\n return null;\n };\n\n\n /**\n * Returns node with the minimum key\n * @return {?Node}\n */\n AVLTree.prototype.minNode = function minNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node;\n };\n\n\n /**\n * Returns node with the max key\n * @return {?Node}\n */\n AVLTree.prototype.maxNode = function maxNode () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node;\n };\n\n\n /**\n * Min key\n * @return {?Key}\n */\n AVLTree.prototype.min = function min () {\n var node = this._root;\n if (!node) { return null; }\n while (node.left) { node = node.left; }\n return node.key;\n };\n\n\n /**\n * Max key\n * @return {?Key}\n */\n AVLTree.prototype.max = function max () {\n var node = this._root;\n if (!node) { return null; }\n while (node.right) { node = node.right; }\n return node.key;\n };\n\n\n /**\n * @return {boolean} true/false\n */\n AVLTree.prototype.isEmpty = function isEmpty () {\n return !this._root;\n };\n\n\n /**\n * Removes and returns the node with smallest key\n * @return {?Node}\n */\n AVLTree.prototype.pop = function pop () {\n var node = this._root, returnValue = null;\n if (node) {\n while (node.left) { node = node.left; }\n returnValue = { key: node.key, data: node.data };\n this.remove(node.key);\n }\n return returnValue;\n };\n\n\n /**\n * Find node by key\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.find = function find (key) {\n var root = this._root;\n // if (root === null) return null;\n // if (key === root.key) return root;\n\n var subtree = root, cmp;\n var compare = this._comparator;\n while (subtree) {\n cmp = compare(key, subtree.key);\n if (cmp === 0) { return subtree; }\n else if (cmp < 0) { subtree = subtree.left; }\n else { subtree = subtree.right; }\n }\n\n return null;\n };\n\n\n /**\n * Insert a node into the tree\n * @param{Key} key\n * @param{Value} [data]\n * @return {?Node}\n */\n AVLTree.prototype.insert = function insert (key, data) {\n var this$1 = this;\n\n if (!this._root) {\n this._root = {\n parent: null, left: null, right: null, balanceFactor: 0,\n key: key, data: data\n };\n this._size++;\n return this._root;\n }\n\n var compare = this._comparator;\n var node = this._root;\n var parent= null;\n var cmp = 0;\n\n if (this._noDuplicates) {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp === 0) { return null; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n } else {\n while (node) {\n cmp = compare(key, node.key);\n parent = node;\n if (cmp <= 0){ node = node.left; } //return null;\n else { node = node.right; }\n }\n }\n\n var newNode = {\n left: null,\n right: null,\n balanceFactor: 0,\n parent: parent, key: key, data: data\n };\n var newRoot;\n if (cmp <= 0) { parent.left= newNode; }\n else { parent.right = newNode; }\n\n while (parent) {\n cmp = compare(parent.key, key);\n if (cmp < 0) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor === 0) { break; }\n else if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n break;\n }\n parent = parent.parent;\n }\n\n this._size++;\n return newNode;\n };\n\n\n /**\n * Removes the node from the tree. If not found, returns null.\n * @param{Key} key\n * @return {?Node}\n */\n AVLTree.prototype.remove = function remove (key) {\n var this$1 = this;\n\n if (!this._root) { return null; }\n\n var node = this._root;\n var compare = this._comparator;\n var cmp = 0;\n\n while (node) {\n cmp = compare(key, node.key);\n if (cmp === 0) { break; }\n else if (cmp < 0) { node = node.left; }\n else { node = node.right; }\n }\n if (!node) { return null; }\n\n var returnValue = node.key;\n var max, min;\n\n if (node.left) {\n max = node.left;\n\n while (max.left || max.right) {\n while (max.right) { max = max.right; }\n\n node.key = max.key;\n node.data = max.data;\n if (max.left) {\n node = max;\n max = max.left;\n }\n }\n\n node.key= max.key;\n node.data = max.data;\n node = max;\n }\n\n if (node.right) {\n min = node.right;\n\n while (min.left || min.right) {\n while (min.left) { min = min.left; }\n\n node.key= min.key;\n node.data = min.data;\n if (min.right) {\n node = min;\n min = min.right;\n }\n }\n\n node.key= min.key;\n node.data = min.data;\n node = min;\n }\n\n var parent = node.parent;\n var pp = node;\n var newRoot;\n\n while (parent) {\n if (parent.left === pp) { parent.balanceFactor -= 1; }\n else { parent.balanceFactor += 1; }\n\n if (parent.balanceFactor < -1) {\n // inlined\n //var newRoot = rightBalance(parent);\n if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }\n newRoot = rotateLeft(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n } else if (parent.balanceFactor > 1) {\n // inlined\n // var newRoot = leftBalance(parent);\n if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }\n newRoot = rotateRight(parent);\n\n if (parent === this$1._root) { this$1._root = newRoot; }\n parent = newRoot;\n }\n\n if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }\n\n pp = parent;\n parent = parent.parent;\n }\n\n if (node.parent) {\n if (node.parent.left === node) { node.parent.left= null; }\n else { node.parent.right = null; }\n }\n\n if (node === this._root) { this._root = null; }\n\n this._size--;\n return returnValue;\n };\n\n\n /**\n * Bulk-load items\n * @param{Array}keys\n * @param{Array}[values]\n * @return {AVLTree}\n */\n AVLTree.prototype.load = function load (keys, values, presort) {\n if ( keys === void 0 ) keys = [];\n if ( values === void 0 ) values = [];\n\n if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }\n var size = keys.length;\n if (presort) { sort(keys, values, 0, size - 1, this._comparator); }\n this._root = loadRecursive(null, keys, values, 0, size);\n markBalance(this._root);\n this._size = size;\n return this;\n };\n\n\n /**\n * Returns true if the tree is balanced\n * @return {boolean}\n */\n AVLTree.prototype.isBalanced = function isBalanced$1 () {\n return isBalanced(this._root);\n };\n\n\n /**\n * String representation of the tree - primitive horizontal print-out\n * @param{Function(Node):string} [printNode]\n * @return {string}\n */\n AVLTree.prototype.toString = function toString (printNode) {\n return print(this._root, printNode);\n };\n\n Object.defineProperties( AVLTree.prototype, prototypeAccessors );\n\n AVLTree.default = AVLTree;\n\n return AVLTree;\n\n})()\n`);\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n t.load(arr);\n // for (let i = 0; i < arr.length; i++)\n // t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n for (let i = 0; i < q; i++) {\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}, {"source_code": "\"use strict\";\nvar input = '';\nvar inputResolve;\nvar inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => {\n inputResolve();\n});\n(async () => {\n var time = Date.now();\n await inputPromise;\n var inputs = input.split(/\\r?\\n/);\n var [n, q] = inputs[0].split(' ').map(v => +v);\n var arr = inputs[1].split(' ').map(v => +v);\n var t = new BSTree();\n var append = arr[0] == 72992;\n t.load(arr);\n // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);\n console.log(t.root.max - t.root.min - t.root.maxGap);\n if (append) console.log(q);\n for (let i = 0; i < q; i++) {\n if (append) console.log('???');\n let [type, x] = inputs[i + 2].split(' ').map(v => +v);\n if (type)\n t.insert(x);\n else\n t.remove(x);\n if(append) console.log(\"???2\");\n console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);\n }\n})();\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this); }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this); }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this); }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n};\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {});\n};\nclass BSNode {\n constructor(key) {\n this.key = key;\n this.size = 1;\n this.min = key;\n this.max = key;\n this.maxGap = 0;\n }\n update() {\n this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);\n this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);\n this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);\n this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);\n }\n rotateRight() {\n var left = this.left;\n if (!left)\n return;\n this.left = left.right;\n left.right = this;\n this.update();\n left.update();\n }\n rotateLeft() {\n var right = this.right;\n if (!right)\n return;\n this.right = right.left;\n right.left = this;\n this.update();\n right.update();\n }\n print() {\n if (this.left) {\n process.stdout.write(\"left \");\n this.left.print();\n }\n process.stdout.write(this.key + ',' + this.size + ' ');\n if (this.right) {\n process.stdout.write(\"right \");\n this.right.print();\n }\n }\n}\nclass BSTree {\n constructor(root) {\n this.root = root;\n }\n load(keys) {\n keys.sort((a, b) => a - b);\n var nodes = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n nodes[i] = new BSNode(keys[i]);\n if (i > 0) {\n nodes[i].left = nodes[i - 1];\n nodes[i].update();\n }\n }\n this.root = nodes[keys.length - 1];\n }\n at(index) {\n var node = this.root;\n while (node) {\n var sizeLeft = node.left ? node.left.size : 0;\n if (sizeLeft == index)\n return node;\n if (index < sizeLeft)\n node = node.left;\n else {\n node = node.right;\n index -= sizeLeft + 1;\n }\n }\n return undefined;\n }\n key(index) {\n var _a;\n return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;\n }\n balance(node, parent) {\n var left = node.left;\n var right = node.right;\n var sizeLeft = left ? left.size : 0;\n var sizeRight = right ? right.size : 0;\n var sizeLeftLeft = left && left.left ? left.left.size : 0;\n var sizeLeftRight = left && left.right ? left.right.size : 0;\n var sizeRightLeft = right && right.left ? right.left.size : 0;\n var sizeRightRight = right && right.right ? right.right.size : 0;\n var dif = Math.abs(sizeLeft - sizeRight);\n if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {\n node.rotateRight();\n if (!parent)\n this.root = left;\n else {\n if (parent.left == node)\n parent.left = left;\n else\n parent.right = left;\n }\n return this.balance(left, parent);\n }\n else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {\n node.rotateLeft();\n if (!parent)\n this.root = right;\n else {\n if (parent.left == node)\n parent.left = right;\n else\n parent.right = right;\n }\n return this.balance(right, parent);\n }\n return node;\n }\n insert(key) {\n if (!this.root)\n return this.root = new BSNode(key);\n var trace = [this.root];\n var node = this.root;\n while (true) {\n if (key < node.key) {\n if (!node.left) {\n node.left = new BSNode(key);\n break;\n }\n node = node.left;\n trace.push(node);\n }\n else {\n if (!node.right) {\n node.right = new BSNode(key);\n break;\n }\n node = node.right;\n trace.push(node);\n }\n }\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n join(tree) {\n if (!this.root)\n return this.root = tree.root;\n var node = this.root;\n var right = node.right;\n while (right) {\n node.rotateLeft();\n node = right;\n right = right.right;\n }\n node.right = tree.root;\n node.update();\n this.root = node;\n this.balance(this.root);\n }\n remove(key) {\n var trace = [];\n var node = this.root;\n while (node && node.key != key) {\n trace.push(node);\n if (key < node.key)\n node = node.left;\n else\n node = node.right;\n }\n if (!node)\n return;\n var newTree = new BSTree(node.left);\n newTree.join(new BSTree(node.right));\n if (!trace[trace.length - 1])\n return this.root = newTree.root;\n if (trace[trace.length - 1].left == node)\n trace[trace.length - 1].left = newTree.root;\n else\n trace[trace.length - 1].right = newTree.root;\n while (trace.length) {\n node = trace.pop();\n node.update();\n this.balance(node, trace[trace.length - 1]);\n }\n }\n print() {\n console.log(this.root ? this.root.print() : undefined);\n }\n}\n"}], "src_uid": "ef6535b1788c59146d5782041188920d"} {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nconst integerRegex = /-?\\d+/g;\r\nconst decimalRegex = /-?\\d+(?:\\.\\d+)?/g;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n readIntegersOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(integerRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n readNumsOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(decimalRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solution1(io) {\r\n const INF = 1e10 + 1;\r\n const [N, M] = io.readIntegersOfLine();\r\n const D = new Array(N);\r\n const G = new Array(N);\r\n const visited = new Array(N);\r\n for (let i = 0; i < N; ++i) {\r\n G[i] = new Array(N);\r\n for (let j = 0; j < N; ++j)\r\n G[i][j] = INF;\r\n }\r\n for (let i = 0; i < M; ++i) {\r\n const [a, b, c] = io.readIntegersOfLine();\r\n G[a][b] = Math.min(G[a][b], c);\r\n }\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j) {\r\n D[j] = G[i][j];\r\n visited[j] = false;\r\n }\r\n while (true) {\r\n let x = -1;\r\n for (let j = 0; j < N; ++j) {\r\n if (visited[j])\r\n continue;\r\n if (x === -1 || D[j] < D[x])\r\n x = j;\r\n }\r\n if (x === -1)\r\n break;\r\n visited[x] = true;\r\n const nextCity = (x + 1) % N;\r\n if (D[nextCity] > D[x] + 1)\r\n D[nextCity] = D[x] + 1;\r\n for (let j = 0; j < N; ++j) {\r\n const y = (D[x] + j) % N;\r\n if (D[y] > D[x] + G[x][j])\r\n D[y] = D[x] + G[x][j];\r\n }\r\n }\r\n D[i] = 0;\r\n io.print(D.join(' '));\r\n io.print('\\n');\r\n }\r\n}\r\n__main__(function (io) {\r\n solution1(io);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nconst integerRegex = /-?\\d+/g;\r\nconst decimalRegex = /-?\\d+(?:\\.\\d+)?/g;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n readIntegersOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(integerRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n readNumsOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(decimalRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solve() { }\r\n__main__(function (io) {\r\n const INF = 1e10 + 1;\r\n const [N, M] = io.readIntegersOfLine();\r\n const D = new Array(N);\r\n const G = new Array(N);\r\n const visited = new Array(N);\r\n for (let i = 0; i < N; ++i) {\r\n G[i] = new Array(N);\r\n for (let j = 0; j < N; ++j)\r\n G[i][j] = INF;\r\n }\r\n for (let i = 0; i < M; ++i) {\r\n const [a, b, c] = io.readIntegersOfLine();\r\n G[a][b] = Math.min(G[a][b], c);\r\n }\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j) {\r\n D[j] = G[i][j];\r\n visited[j] = false;\r\n }\r\n while (true) {\r\n let x = -1;\r\n for (let j = 0; j < N; ++j) {\r\n if (visited[j])\r\n continue;\r\n if (x === -1 || D[j] < D[x])\r\n x = j;\r\n }\r\n if (x === -1)\r\n break;\r\n visited[x] = true;\r\n const nextCity = (x + 1) % N;\r\n if (D[nextCity] > D[x] + 1)\r\n D[nextCity] = D[x] + 1;\r\n for (let j = 0; j < N; ++j) {\r\n const y = (D[x] + j) % N;\r\n if (D[y] > D[x] + G[x][j])\r\n D[y] = D[x] + G[x][j];\r\n }\r\n }\r\n D[i] = 0;\r\n io.print(D.join(' '));\r\n io.print('\\n');\r\n }\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nconst integerRegex = /-?\\d+/g;\r\nconst decimalRegex = /-?\\d+(?:\\.\\d+)?/g;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n readIntegersOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(integerRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n readNumsOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(decimalRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solve() { }\r\n__main__(function (io) {\r\n const INF = 1e10 + 1;\r\n const [N, M] = io.readIntegersOfLine();\r\n const D = new Array(N);\r\n const G = new Array(N);\r\n const W = new Array(N);\r\n const visited = new Array(N);\r\n for (let i = 0; i < N; ++i) {\r\n G[i] = [];\r\n W[i] = new Array(N);\r\n for (let j = 0; j < N; ++j)\r\n W[i][j] = INF;\r\n }\r\n for (let i = 0; i < M; ++i) {\r\n const [a, b, c] = io.readIntegersOfLine();\r\n W[a][b] = Math.min(W[a][b], c);\r\n G[a].push(b);\r\n }\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j) {\r\n D[j] = W[i][j];\r\n visited[j] = false;\r\n }\r\n while (true) {\r\n let x = -1;\r\n for (let j = 0; j < N; ++j) {\r\n if (visited[j])\r\n continue;\r\n if (x === -1 || D[j] < D[x])\r\n x = j;\r\n }\r\n if (x === -1)\r\n break;\r\n visited[x] = true;\r\n const nextCity = (x + 1) % N;\r\n if (D[nextCity] > D[x] + 1)\r\n D[nextCity] = D[x] + 1;\r\n for (const j of G[i]) {\r\n const y = (D[x] + j) % N;\r\n if (D[y] > D[x] + G[x][j])\r\n D[y] = D[x] + G[x][j];\r\n }\r\n }\r\n D[i] = 0;\r\n io.print(D.join(' '));\r\n io.print('\\n');\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nObject.defineProperty(exports, '__esModule', { value: true });\r\n\r\nvar os = require('os');\r\n\r\nconst stdin = process.stdin;\r\nconst stdout = process.stdout;\r\nconst integerRegex = /-?\\d+/g;\r\nconst decimalRegex = /-?\\d+(?:\\.\\d+)?/g;\r\nclass InputAndOutput {\r\n constructor() {\r\n this.lineIndex = 0;\r\n this.lines = [];\r\n }\r\n dried() {\r\n return this.lineIndex >= this.lines.length;\r\n }\r\n readLine() {\r\n const line = this.lines[this.lineIndex];\r\n this.lineIndex += 1;\r\n return line;\r\n }\r\n readIntegersOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(integerRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n readNumsOfLine() {\r\n const line = this.readLine();\r\n const m = line.match(decimalRegex);\r\n if (m == null)\r\n return [];\r\n return m.map(x => Number(x));\r\n }\r\n print(content) {\r\n stdout.write(content);\r\n }\r\n async init() {\r\n const lines = await this.readLines();\r\n this.lines = lines;\r\n }\r\n readLines() {\r\n const buffers = [];\r\n return new Promise(resolve => {\r\n stdin.on('data', (buffer) => buffers.push(buffer));\r\n stdin.on('end', function () {\r\n const inputs = buffers.join('');\r\n const lines = inputs.split(os.EOL);\r\n resolve(lines);\r\n });\r\n });\r\n }\r\n}\r\nasync function __main__(handle) {\r\n const io = new InputAndOutput();\r\n await io.init();\r\n handle(io);\r\n}\r\n\r\nfunction solve() { }\r\nconst INF = 1e10 + 1;\r\nconst MAX_N = 600 + 10;\r\nconst visited = new Array(MAX_N);\r\nconst D = new Array(MAX_N);\r\nconst G = new Array(MAX_N);\r\nfor (let i = 0; i < G.length; ++i)\r\n G[i] = new Array(MAX_N);\r\n__main__(function (io) {\r\n const [N, M] = io.readIntegersOfLine();\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j)\r\n G[i][j] = INF;\r\n G[i][i] = 0;\r\n }\r\n for (let i = 0; i < M; ++i) {\r\n const [a, b, c] = io.readIntegersOfLine();\r\n G[a][b] = Math.min(G[a][b], c);\r\n }\r\n for (let i = 0; i < N; ++i) {\r\n for (let j = 0; j < N; ++j) {\r\n D[j] = G[i][j];\r\n visited[j] = false;\r\n }\r\n while (true) {\r\n let x = -1;\r\n for (let j = 0; j < N; ++j) {\r\n if (visited[j])\r\n continue;\r\n if (x === -1 || D[j] < D[x])\r\n x = j;\r\n }\r\n if (x === -1)\r\n break;\r\n visited[x] = true;\r\n const d = D[x];\r\n for (let j = 0; j < N; ++j) {\r\n const y = (D[x] + j) % N;\r\n D[y] = Math.min(D[y], d + j);\r\n }\r\n }\r\n io.print(String(D[0]));\r\n for (let j = 1; j < N; ++j)\r\n io.print(' ' + D[j]);\r\n io.print('\\n');\r\n }\r\n});\r\n"}], "src_uid": "58b9ec7ff9718ceae1aa3d4503c8cbed"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n const even = [];\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n even[find(u, p1)] = 1;\r\n even[find(v, p1)] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (even[find(i, p1)]) {\r\n flag[i] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let t = m;\r\n while (t--) {\r\n const [u, v, w] = (await read()).split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(await read());\r\n while (t--) {\r\n const [u, v] = (await read()).split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n //\r\n async function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n const even = [];\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n even[find(u, p1)] = 1;\r\n even[find(v, p1)] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (even[find(i, p1)]) {\r\n flag[i] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let t = m;\r\n while (t--) {\r\n const [u, v, w] = (await read()).split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(await read());\r\n while (t--) {\r\n const [u, v] = (await read()).split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nreadline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n let i = 0;\r\n async function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n const even = [];\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n even[find(u, p1)] = 1;\r\n even[find(v, p1)] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (even[find(i, p1)]) {\r\n flag[i] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let t = m;\r\n while (t--) {\r\n const [u, v, w] = (await read()).split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(await read());\r\n while (t--) {\r\n const [u, v] = (await read()).split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n async function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n const even = [];\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n even[find(u, p1)] = 1;\r\n even[find(v, p1)] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (even[find(i, p1)]) {\r\n flag[i] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nfunction main(inputs) {\r\n const [n, m] = inputs[0].trim().split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let i = 1,\r\n t = m;\r\n while (t--) {\r\n const [u, v, w] = inputs[i++].trim().split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(inputs[i++].trim());\r\n while (t--) {\r\n const [u, v] = inputs[i++].trim().split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n const even = [];\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n even[find(u, p1)] = 1;\r\n even[find(v, p1)] = 1;\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (even[find(i, p1)]) {\r\n flag[i] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let t = m;\r\n while (t--) {\r\n const [u, v, w] = (await read()).split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(await read());\r\n while (t--) {\r\n const [u, v] = (await read()).split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nfunction read() {\r\n return new Promise(function (resolve, reject) {\r\n rl.on('line', line => resolve(line.trim()));\r\n });\r\n}\r\nmain(read);\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, m, edges, querys) {\r\n const ps = Array.from({\r\n length: 30\r\n }, () => [...new Array(n).keys()]),\r\n ps1 = Array.from({\r\n length: 29\r\n }, () => [...new Array(n).keys()]),\r\n flag = [];\r\n const find = (i, p) => {\r\n if (p[i] !== i) p[i] = find(p[p[i]], p);\r\n return p[i];\r\n };\r\n const union = (i, j, p) => {\r\n const ri = find(i, p),\r\n rj = find(j, p);\r\n if (ri !== rj) p[rj] = ri;\r\n };\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let [u, v, c] of edges) {\r\n add(u, v, c);\r\n add(v, u, c);\r\n }\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i) {\r\n union(j, l, p);\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p1 = ps1[i];\r\n for (let j = 0; j < n; j++) {\r\n for (let k = h[j]; k !== -1; k = ne[k]) {\r\n const l = e[k];\r\n if (l < j) continue;\r\n if (w[k] & 1 << i + 1) union(j, l, p1);\r\n }\r\n }\r\n for (let [u, v, c] of edges) {\r\n if (!(c & 1)) {\r\n flag[find(u, p1)] = 1;\r\n flag[find(v, p1)] = 1;\r\n }\r\n }\r\n }\r\n let res = [];\r\n for (let [u, v] of querys) {\r\n let ans = 2;\r\n for (let i = 0; i < 30; i++) {\r\n const p = ps[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 0;\r\n break;\r\n }\r\n }\r\n if (ans !== 2) {\r\n res.push(ans);\r\n continue;\r\n }\r\n if (flag[u]) {\r\n res.push(1);\r\n continue;\r\n }\r\n for (let i = 0; i < 29; i++) {\r\n const p = ps1[i];\r\n const ru = find(u, p),\r\n rv = find(v, p);\r\n if (ru === rv) {\r\n ans = 1;\r\n break;\r\n }\r\n }\r\n res.push(ans);\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nfunction main(inputs) {\r\n const [n, m] = inputs[0].trim().split(' ').map(Number);\r\n const edges = [],\r\n querys = [];\r\n let i = 1,\r\n t = m;\r\n while (t--) {\r\n const [u, v, w] = inputs[i++].trim().split(' ').map(Number);\r\n edges.push([u - 1, v - 1, w]);\r\n }\r\n t = Number(inputs[i++].trim());\r\n while (t--) {\r\n const [u, v] = inputs[i++].trim().split(' ').map(Number);\r\n querys.push([u - 1, v - 1]);\r\n }\r\n solve(n, m, edges, querys);\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nmain(inputs);\r\n"}], "src_uid": "a3e89153f98c139d7e84f2307b128b24"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet n = rn();\r\n\t\tlet q = rna();\r\n\r\n\t\tlet mnavl = [], mxavl = [];\r\n\t\tlet ansmn = [], ansmx = [];\r\n\t\tlet mx = 0;\r\n\t\tfor (let i = 0, k = 0; i < n; i++) {\r\n\t\t\tif (q[i] > mx) {\r\n\t\t\t\tansmn.push(q[i]);\r\n\t\t\t\tansmx.push(q[i]);\r\n\t\t\t\tmx++;\r\n\t\t\t\twhile (mx < q[i]) { \r\n\t\t\t\t\tmnavl.push(mx);\r\n\t\t\t\t\tmxavl.push(mx);\r\n\t\t\t\t\tmx++; \r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tansmn.push(mnavl[k++]);\r\n\t\t\t\tansmx.push(mxavl.pop());\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(ansmn.join(' '));\r\n\t\tconsole.log(ansmx.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const solve = a => {\n const res = [];\n const cache = new Set();\n for (let i = 0; i < a.length; i++) {\n res.push(null);\n if (i === 0 || a[i] !== a[i - 1]) {\n res[i] = a[i];\n cache.add(res[i]);\n }\n }\n\n const min = [...res];\n let count = 1;\n for (let i = 0; i < a.length; i++) {\n if (res[i] !== null) continue;\n while (cache.has(count)) count++;\n min[i] = count;\n count++;\n }\n\n const max = [...res];\n const stack = [];\n for (let i = 0; i < a.length; i++) {\n if (i === 0) {\n for (let j = 1; j < res[i]; j++) stack.push(j);\n } else if (a[i] !== a[i - 1]) {\n for (let j = a[i - 1] + 1; j < a[i]; j++) stack.push(j);\n }\n\n if (res[i] !== null) continue;\n max[i] = stack.pop();\n }\n\n return [min, max];\n};\n\nconst main = () => {\n let t = readInt();\n while (t--) {\n const n = readInt();\n const a = readListInt();\n const [min, max] = solve(a);\n console.log(min.join(\" \"));\n console.log(max.join(\" \"));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var j = 1;\r\n for (let i = 0; i < t; i++) {\r\n var len = Number(input[j]);\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n })\r\n j++;\r\n function findMin(arr, len) {\r\n var result = new Array(len).fill(0);\r\n result[0] = arr[0];\r\n var set = new Set();\r\n set.add(arr[0]);\r\n for (var i = 1; i < arr.length; i++) {\r\n if (arr[i] !== arr[i - 1]) {\r\n result[i] = arr[i];\r\n set.add(arr[i]);\r\n }\r\n }\r\n var count = 1;\r\n for (var i = 0; i < result.length; i++) {\r\n if (result[i] === 0) {\r\n result[i] = count;\r\n count++;\r\n } \r\n while (set.has(count)) {\r\n count++;\r\n }\r\n }\r\n return result.join(\" \");\r\n }\r\n function findMax(arr, len) {\r\n var result = new Array(len).fill(0);\r\n result[0] = arr[0];\r\n var set = new Set();\r\n set.add(arr[0]);\r\n for (var i = 1; i < arr.length; i++) {\r\n if (arr[i] !== arr[i - 1]) {\r\n result[i] = arr[i];\r\n set.add(arr[i]);\r\n }\r\n }\r\n var list = [];\r\n var count = 1;\r\n for (var i = 0; i < result.length; i++) {\r\n if (result[i] !== 0) {\r\n while (count < result[i]) {\r\n if (!set.has(count)) {\r\n list.push(count);\r\n }\r\n count++;\r\n }\r\n count++;\r\n } else {\r\n result[i] = list.pop();\r\n }\r\n }\r\n return result.join(\" \");\r\n }\r\n console.log(findMin(arr, len));\r\n console.log(findMax(arr, len));\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var fixed = new Array(n).fill(false)\r\n fixed[0] = true\r\n for (let i = 1; i < n; i++) {\r\n if(a[i]!==a[i-1]) fixed[i] = true\r\n\r\n }\r\n\r\n var set1 = new RBTree(function(a, b) { return a - b; })\r\n var set2 = new RBTree(function(a, b) { return a - b; })\r\n var ans1 = new Array(n).fill(0)\r\n var ans2 = new Array(n).fill(0)\r\n for (let i = 1; i <= n; i++) {\r\n set1.insert(i)\r\n set2.insert(i)\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if(fixed[i]){\r\n ans1[i] = a[i]\r\n ans2[i] = a[i]\r\n set1.remove(a[i])\r\n set2.remove(a[i])\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if(!fixed[i]){\r\n ans1[i] = set1.min()\r\n set1.remove(ans1[i])\r\n ans2[i] = set2.upperBound(a[i]).prev()\r\n set2.remove(ans2[i])\r\n // set1.remove(ans1[i])\r\n }\r\n }\r\n\r\n console.log(ans1.join(' '))\r\n console.log(ans2.join(' '))\r\n })\r\n}\r\n\r\n// start binary search tree\r\n\r\nfunction TreeBase() {}\r\n\r\n// removes all nodes from the tree\r\nTreeBase.prototype.clear = function() {\r\n this._root = null;\r\n this.size = 0;\r\n};\r\n\r\n// returns node data if found, null otherwise\r\nTreeBase.prototype.find = function(data) {\r\n var res = this._root;\r\n\r\n while(res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if(c === 0) {\r\n return res.data;\r\n }\r\n else {\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// returns iterator to node if found, null otherwise\r\nTreeBase.prototype.findIter = function(data) {\r\n var res = this._root;\r\n var iter = this.iterator();\r\n\r\n while(res !== null) {\r\n var c = this._comparator(data, res.data);\r\n if(c === 0) {\r\n iter._cursor = res;\r\n return iter;\r\n }\r\n else {\r\n iter._ancestors.push(res);\r\n res = res.get_child(c > 0);\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\n// Returns an iterator to the tree node at or immediately after the item\r\nTreeBase.prototype.lowerBound = function(item) {\r\n var cur = this._root;\r\n var iter = this.iterator();\r\n var cmp = this._comparator;\r\n\r\n while(cur !== null) {\r\n var c = cmp(item, cur.data);\r\n if(c === 0) {\r\n iter._cursor = cur;\r\n return iter;\r\n }\r\n iter._ancestors.push(cur);\r\n cur = cur.get_child(c > 0);\r\n }\r\n\r\n for(var i=iter._ancestors.length - 1; i >= 0; --i) {\r\n cur = iter._ancestors[i];\r\n if(cmp(item, cur.data) < 0) {\r\n iter._cursor = cur;\r\n iter._ancestors.length = i;\r\n return iter;\r\n }\r\n }\r\n\r\n iter._ancestors.length = 0;\r\n return iter;\r\n};\r\n\r\n// Returns an iterator to the tree node immediately after the item\r\nTreeBase.prototype.upperBound = function(item) {\r\n var iter = this.lowerBound(item);\r\n var cmp = this._comparator;\r\n\r\n while(iter.data() !== null && cmp(iter.data(), item) === 0) {\r\n iter.next();\r\n }\r\n\r\n return iter;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.min = function() {\r\n var res = this._root;\r\n if(res === null) {\r\n return null;\r\n }\r\n\r\n while(res.left !== null) {\r\n res = res.left;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns null if tree is empty\r\nTreeBase.prototype.max = function() {\r\n var res = this._root;\r\n if(res === null) {\r\n return null;\r\n }\r\n\r\n while(res.right !== null) {\r\n res = res.right;\r\n }\r\n\r\n return res.data;\r\n};\r\n\r\n// returns a null iterator\r\n// call next() or prev() to point to an element\r\nTreeBase.prototype.iterator = function() {\r\n return new Iterator(this);\r\n};\r\n\r\n// calls cb on each node's data, in order\r\nTreeBase.prototype.each = function(cb) {\r\n var it=this.iterator(), data;\r\n while((data = it.next()) !== null) {\r\n if(cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n// calls cb on each node's data, in reverse order\r\nTreeBase.prototype.reach = function(cb) {\r\n var it=this.iterator(), data;\r\n while((data = it.prev()) !== null) {\r\n if(cb(data) === false) {\r\n return;\r\n }\r\n }\r\n};\r\n\r\n\r\nfunction Iterator(tree) {\r\n this._tree = tree;\r\n this._ancestors = [];\r\n this._cursor = null;\r\n}\r\n\r\nIterator.prototype.data = function() {\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns first node\r\n// otherwise, returns next node\r\nIterator.prototype.next = function() {\r\n if(this._cursor === null) {\r\n var root = this._tree._root;\r\n if(root !== null) {\r\n this._minNode(root);\r\n }\r\n }\r\n else {\r\n if(this._cursor.right === null) {\r\n // no greater node in subtree, go up to parent\r\n // if coming from a right child, continue up the stack\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if(this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n }\r\n else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while(this._cursor.right === save);\r\n }\r\n else {\r\n // get the next node from the subtree\r\n this._ancestors.push(this._cursor);\r\n this._minNode(this._cursor.right);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\n// if null-iterator, returns last node\r\n// otherwise, returns previous node\r\nIterator.prototype.prev = function() {\r\n if(this._cursor === null) {\r\n var root = this._tree._root;\r\n if(root !== null) {\r\n this._maxNode(root);\r\n }\r\n }\r\n else {\r\n if(this._cursor.left === null) {\r\n var save;\r\n do {\r\n save = this._cursor;\r\n if(this._ancestors.length) {\r\n this._cursor = this._ancestors.pop();\r\n }\r\n else {\r\n this._cursor = null;\r\n break;\r\n }\r\n } while(this._cursor.left === save);\r\n }\r\n else {\r\n this._ancestors.push(this._cursor);\r\n this._maxNode(this._cursor.left);\r\n }\r\n }\r\n return this._cursor !== null ? this._cursor.data : null;\r\n};\r\n\r\nIterator.prototype._minNode = function(start) {\r\n while(start.left !== null) {\r\n this._ancestors.push(start);\r\n start = start.left;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\nIterator.prototype._maxNode = function(start) {\r\n while(start.right !== null) {\r\n this._ancestors.push(start);\r\n start = start.right;\r\n }\r\n this._cursor = start;\r\n};\r\n\r\n\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n}\r\n\r\nNode.prototype.get_child = function(dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function(dir, val) {\r\n if(dir) {\r\n this.right = val;\r\n }\r\n else {\r\n this.left = val;\r\n }\r\n};\r\n\r\n\r\nfunction Node(data) {\r\n this.data = data;\r\n this.left = null;\r\n this.right = null;\r\n this.red = true;\r\n}\r\n\r\nNode.prototype.get_child = function(dir) {\r\n return dir ? this.right : this.left;\r\n};\r\n\r\nNode.prototype.set_child = function(dir, val) {\r\n if(dir) {\r\n this.right = val;\r\n }\r\n else {\r\n this.left = val;\r\n }\r\n};\r\n\r\nfunction RBTree(comparator) {\r\n this._root = null;\r\n this._comparator = comparator;\r\n this.size = 0;\r\n}\r\n\r\nRBTree.prototype = new TreeBase();\r\n\r\n// returns true if inserted, false if duplicate\r\nRBTree.prototype.insert = function(data) {\r\n var ret = false;\r\n\r\n if(this._root === null) {\r\n // empty tree\r\n this._root = new Node(data);\r\n ret = true;\r\n this.size++;\r\n }\r\n else {\r\n var head = new Node(undefined); // fake tree root\r\n\r\n var dir = 0;\r\n var last = 0;\r\n\r\n // setup\r\n var gp = null; // grandparent\r\n var ggp = head; // grand-grand-parent\r\n var p = null; // parent\r\n var node = this._root;\r\n ggp.right = this._root;\r\n\r\n // search down\r\n while(true) {\r\n if(node === null) {\r\n // insert new node at the bottom\r\n node = new Node(data);\r\n p.set_child(dir, node);\r\n ret = true;\r\n this.size++;\r\n }\r\n else if(is_red(node.left) && is_red(node.right)) {\r\n // color flip\r\n node.red = true;\r\n node.left.red = false;\r\n node.right.red = false;\r\n }\r\n\r\n // fix red violation\r\n if(is_red(node) && is_red(p)) {\r\n var dir2 = ggp.right === gp;\r\n\r\n if(node === p.get_child(last)) {\r\n ggp.set_child(dir2, single_rotate(gp, !last));\r\n }\r\n else {\r\n ggp.set_child(dir2, double_rotate(gp, !last));\r\n }\r\n }\r\n\r\n var cmp = this._comparator(node.data, data);\r\n\r\n // stop if found\r\n if(cmp === 0) {\r\n break;\r\n }\r\n\r\n last = dir;\r\n dir = cmp < 0;\r\n\r\n // update helpers\r\n if(gp !== null) {\r\n ggp = gp;\r\n }\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n }\r\n\r\n // update root\r\n this._root = head.right;\r\n }\r\n\r\n // make root black\r\n this._root.red = false;\r\n\r\n return ret;\r\n};\r\n\r\n// returns true if removed, false if not found\r\nRBTree.prototype.remove = function(data) {\r\n if(this._root === null) {\r\n return false;\r\n }\r\n\r\n var head = new Node(undefined); // fake tree root\r\n var node = head;\r\n node.right = this._root;\r\n var p = null; // parent\r\n var gp = null; // grand parent\r\n var found = null; // found item\r\n var dir = 1;\r\n\r\n while(node.get_child(dir) !== null) {\r\n var last = dir;\r\n\r\n // update helpers\r\n gp = p;\r\n p = node;\r\n node = node.get_child(dir);\r\n\r\n var cmp = this._comparator(data, node.data);\r\n\r\n dir = cmp > 0;\r\n\r\n // save found node\r\n if(cmp === 0) {\r\n found = node;\r\n }\r\n\r\n // push the red node down\r\n if(!is_red(node) && !is_red(node.get_child(dir))) {\r\n if(is_red(node.get_child(!dir))) {\r\n var sr = single_rotate(node, dir);\r\n p.set_child(last, sr);\r\n p = sr;\r\n }\r\n else if(!is_red(node.get_child(!dir))) {\r\n var sibling = p.get_child(!last);\r\n if(sibling !== null) {\r\n if(!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {\r\n // color flip\r\n p.red = false;\r\n sibling.red = true;\r\n node.red = true;\r\n }\r\n else {\r\n var dir2 = gp.right === p;\r\n\r\n if(is_red(sibling.get_child(last))) {\r\n gp.set_child(dir2, double_rotate(p, last));\r\n }\r\n else if(is_red(sibling.get_child(!last))) {\r\n gp.set_child(dir2, single_rotate(p, last));\r\n }\r\n\r\n // ensure correct coloring\r\n var gpc = gp.get_child(dir2);\r\n gpc.red = true;\r\n node.red = true;\r\n gpc.left.red = false;\r\n gpc.right.red = false;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // replace and remove if found\r\n if(found !== null) {\r\n found.data = node.data;\r\n p.set_child(p.right === node, node.get_child(node.left === null));\r\n this.size--;\r\n }\r\n\r\n // update root and make it black\r\n this._root = head.right;\r\n if(this._root !== null) {\r\n this._root.red = false;\r\n }\r\n\r\n return found !== null;\r\n};\r\n\r\nfunction is_red(node) {\r\n return node !== null && node.red;\r\n}\r\n\r\nfunction single_rotate(root, dir) {\r\n var save = root.get_child(!dir);\r\n\r\n root.set_child(!dir, save.get_child(dir));\r\n save.set_child(dir, root);\r\n\r\n root.red = true;\r\n save.red = false;\r\n\r\n return save;\r\n}\r\n\r\nfunction double_rotate(root, dir) {\r\n root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));\r\n return single_rotate(root, dir);\r\n}\r\n\r\n//end binary search tree\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n\r\n var answer = new Array(n).fill(0)\r\n var used = new Array(n).fill(false)\r\n var count = 1\r\n var met = 1\r\n answer[0] = a[0];\r\n used[a[0]] = true\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] !== a[i - 1]) {\r\n answer[i] = a[i]\r\n used[a[i]] = true\r\n }\r\n }\r\n var count = 1\r\n for (let i = 0; i < n; i++) {\r\n if (answer[i] === 0) {\r\n while (used[count]) count++\r\n answer[i] = count\r\n used[count] = true\r\n }\r\n }\r\n console.log(answer.join(' '))\r\n\r\n answer = new Array(n).fill(0)\r\n var used = new Array(n).fill(false)\r\n var count = 1\r\n var met = 1\r\n answer[0] = a[0];\r\n used[a[0]] = true\r\n for (let i = 1; i < n; i++) {\r\n if (a[i] !== a[i - 1]) {\r\n answer[i] = a[i]\r\n used[a[i]] = true\r\n }\r\n }\r\n var lower = 0\r\n var count = a[0]-1\r\n var prev = a[0]-1\r\n var max = a[0]\r\n for (let i = 0; i < n; i++) {\r\n if (answer[i] === 0) {\r\n answer[i] = count\r\n count--\r\n } else {\r\n // console.log(count, lower)\r\n if(count === lower){\r\n lower = prev\r\n count = answer[i]-1\r\n }\r\n prev = answer[i]\r\n }\r\n }\r\n console.log(answer.join(' '))\r\n\r\n })\r\n}\r\n\r\n"}], "src_uid": "6e7b8742906ce40458d920121c33c54f"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,-1,-1,0,1,1,1,0];\r\n\tvar dx = [-1,0,1,1,1,0,-1,-1];\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar list = new Array(H);\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tlist[i] = new Array(W);\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tif(list[i][0] == null){\r\n\t\t\t\tlist[i][0] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = i + dy[j];\r\n\t\t\t\t\tvar x = 0 + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(list[i][W - 1] == null){\r\n\t\t\t\tlist[i][W - 1] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = i + dy[j];\r\n\t\t\t\t\tvar x = (W - 1) + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyerr(list);\r\n\t\tfor(var i = 0; i < W; i++){\r\n\t\t\tif(list[0][i] == null){\r\n\t\t\t\tlist[0][i] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = 0 + dy[j];\r\n\t\t\t\t\tvar x = i + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(list[H - 1][i] == null){\r\n\t\t\t\tlist[H - 1][i] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = (H - 1) + dy[j];\r\n\t\t\t\t\tvar x = i + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(list[i][j] == null){\r\n\t\t\t\t\tlist[i][j] = \"0\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tmyout(myconv(list[i], 0));\r\n\t\t}\r\n\t\tmyout(\"\");\r\n\t}\r\n}", "positive_code": [{"source_code": "let i = '';\r\n\r\nfunction insertOne(x, y, arr) {\r\n let willInsert = true;\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y-1] !== undefined && arr[x-1][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y-1] !== undefined && arr[x][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y-1] !== undefined && arr[x+1][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y] !== undefined && arr[x-1][y] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y] !== undefined && arr[x][y] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y] !== undefined && arr[x+1][y] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y+1] !== undefined && arr[x-1][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y+1] !== undefined && arr[x][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y+1] !== undefined && arr[x+1][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (willInsert) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction createArrayWithZeros(width, height) {\r\n const arr = [];\r\n for(let i = 0; i < height; i++) {\r\n arr[i] = [];\r\n for(let j = 0; j < width; j++) {\r\n arr[i][j] = 0;\r\n }\r\n }\r\n return arr;\r\n}\r\n\r\nfunction printArr(width, height, arr) {\r\n for(let i = 0; i < height; i++) {\r\n let string = '';\r\n for(let j = 0; j < width; j++) {\r\n string += arr[i][j];\r\n }\r\n console.log(string);\r\n }\r\n console.log('\\n');\r\n}\r\n\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n const size = lines[0];\r\n for(let j = 1; j <= size; j++) {\r\n let num = lines[j];\r\n const sizes = num.split(' ');\r\n const height = sizes[0];\r\n const width = sizes[1];\r\n const table = createArrayWithZeros(width, height);\r\n \r\n for(let x = 0; x < height; x++) {\r\n for(let y = 0; y < width; y++) {\r\n if (x === 0 || y === 0 || x === height-1 || y === width-1) {\r\n table[x][y] = insertOne(x, y, table); \r\n }\r\n }\r\n }\r\n \r\n printArr(width, height, table);\r\n }\r\n})"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \n \nfunction main() {\n const n = Number(readline());\n\n for(let i = 0; i < n; i ++) {\n const [h, w] = readline().split(\" \").map(Number);\n\n let result = \"\";\n\n for(let j = 0; j < h; j++){\n for(let k = 0; k < w; k++){\n if(j == 0 || j == h-1) {\n if(k % 2 == 0) result += \"1\";\n else result += \"0\";\n } else if (j % 2 != 0 || j == 1 || j == h-2) {\n result += \"0\";\n } else if (k == 0 || k == w-1) {\n result += \"1\";\n } else {\n result += \"0\";\n }\n }\n console.log(result);\n result = \"\";\n }\n \n console.log(\" \");\n }\n}\n\n\n\n"}, {"source_code": "let input = '';\nprocess.stdin.on('data', chunk => input += chunk);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = input.split(EOL);\n const count = parseInt(lines[0]);\n for (let i = 1; i <= count; ++i) {\n solve(lines[i]);\n }\n});\n\nfunction solve(question) {\n let [, h, w] = question.match(/(\\d+) (\\d+)/);\n h = parseInt(h);\n w = parseInt(w);\n\n for (let y = 0; y < h; ++y) {\n line = '';\n if (h % 2 === 0 && y === h - 2) {\n for (let x = 0; x < w; ++x) {\n line += '0'; \n }\n } else if (y % 2 === 0 || y === h - 1) {\n for (let x = 0; x < w; ++x) {\n if (w % 2 === 0 && x === w - 2) {\n line += '0';\n } else if ((x === 0 || x === w - 1 || y === 0 || y === h - 1) && (x % 2 === 0 || x === w - 1)) {\n line += '1';\n } else {\n line += '0';\n }\n }\n } else {\n for (let x = 0; x < w; ++x) {\n line += '0';\n }\n }\n console.log(line);\n }\n console.log();\n}\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar dy = [-1,-1,-1,0,1,1,1,0];\r\n\tvar dx = [-1,0,1,1,1,0,-1,-1];\r\n\twhile(hasNext()){\r\n\t\tvar H = nextInt();\r\n\t\tvar W = nextInt();\r\n\t\tvar list = new Array(H);\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tlist[i] = new Array(W);\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tif(list[i][0] == null){\r\n\t\t\t\tlist[i][0] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = i + dy[j];\r\n\t\t\t\t\tvar x = 0 + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(list[i][W - 1] == null){\r\n\t\t\t\tlist[i][W - 1] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = i + dy[j];\r\n\t\t\t\t\tvar x = (W - 1) + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < W; i++){\r\n\t\t\tif(list[0][i] == null){\r\n\t\t\t\tlist[0][i] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = 0 + dy[j];\r\n\t\t\t\t\tvar x = j + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(list[H - 1][i] == null){\r\n\t\t\t\tlist[H - 1][i] = \"1\";\r\n\t\t\t\tfor(var j = 0; j < dy.length; j++){\r\n\t\t\t\t\tvar y = (H - 1) + dy[j];\r\n\t\t\t\t\tvar x = j + dx[j];\r\n\t\t\t\t\tif(y >= 0 && y < H && x >= 0 && x < W){\r\n\t\t\t\t\t\tlist[y][x] = \"0\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tfor(var j = 0; j < W; j++){\r\n\t\t\t\tif(list[i][j] == null){\r\n\t\t\t\t\tlist[i][j] = \"0\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = 0; i < H; i++){\r\n\t\t\tmyout(myconv(list[i], 0));\r\n\t\t}\r\n\t\tmyout(\"\");\r\n\t}\r\n}"}, {"source_code": "let i = '';\r\n\r\nfunction insertOne(x, y, arr) {\r\n let willInsert = true;\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y-1] !== undefined && arr[x-1][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y-1] !== undefined && arr[x][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y-1] !== undefined && arr[x+1][y-1] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y] !== undefined && arr[x-1][y] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y] !== undefined && arr[x][y] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y] !== undefined && arr[x+1][y] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (arr[x-1] !== undefined && arr[x-1][y+1] !== undefined && arr[x-1][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x] !== undefined && arr[x][y+1] !== undefined && arr[x][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n if (arr[x+1] !== undefined && arr[x+1][y+1] !== undefined && arr[x+1][y+1] === 1) {\r\n willInsert = false;\r\n }\r\n \r\n if (willInsert) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction createArrayWithZeros(width, height) {\r\n const arr = [];\r\n for(let i = 0; i < height; i++) {\r\n arr[i] = [];\r\n for(let j = 0; j < width; j++) {\r\n arr[i][j] = 0;\r\n }\r\n }\r\n return arr;\r\n}\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n const size = lines[0];\r\n for(let j = 1; j <= size; j++) {\r\n let num = lines[j];\r\n const sizes = num.split(' ');\r\n const height = sizes[0];\r\n const width = sizes[1];\r\n const table = createArrayWithZeros(width, height);\r\n \r\n for(let x = 0; x < height; x++) {\r\n for(let y = 0; y < width; y++) {\r\n if (x === 0 || y === 0 || x === height-1 || y === width-1) {\r\n table[x][y] = insertOne(x, y, table); \r\n }\r\n }\r\n }\r\n \r\n console.log(table);\r\n }\r\n})"}], "src_uid": "730cc4be2656c1dcdbda220b8778cdbf"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar k = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar p = [];\r\n\t\tvar output = \"\";\r\n\t\tfor(var i = 0; i < k; i++){\r\n\t\t\tif(s[i] == \"1\" || s[i] == \"4\" || s[i] == \"6\" || s[i] == \"8\" || s[i] == \"9\"){\r\n\t\t\t\toutput = \"1\\n\" + s[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(p.indexOf(s[i]) != -1){\r\n\t\t\t\toutput = \"2\\n\" + s[i] + s[i];\r\n\t\t\t}else{\r\n\t\t\t\tp.push(s[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif(output == \"\"){\r\n\t\t\tfor(var i = 0; i < (1 << p.length); i++){\r\n\t\t\t\tvar v = 0;\r\n\t\t\t\tfor(var j = 0; j < p.length; j++){\r\n\t\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\t\tv *= 10;\r\n\t\t\t\t\t\tv += myconv(p[j], 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(v >= 10 && !isPrime(v)){\r\n\t\t\t\t\toutput = \"2\\n\" + v;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction isPrime(val){\r\n\tif(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\r\n\t\treturn false;\r\n\t}else if(val == 2){\r\n\t\treturn true;\r\n\t}\r\n\tvar root = Math.floor(Math.sqrt(val));\r\n\tfor(var i = 3; i <= root; i += 2){\r\n\t\tif(val % i == 0){\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\treturn true;\r\n}", "positive_code": [{"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst MAX = 100;\r\nconst prime = Array.from({ length: MAX }).fill(true);\r\nconst nonprime = [];\r\nfunction sieve() {\r\n nonprime.push('1'); // neither prime nor composite\r\n prime[0] = prime[1] = false;\r\n for (let i = 2; i < MAX; i++) {\r\n if (prime[i]) {\r\n for (let j = i; i * j < MAX; j++) {\r\n prime[i * j] = false;\r\n }\r\n }\r\n else {\r\n let j = i;\r\n let t = [];\r\n while (j > 0) {\r\n t.push(String(j % 10));\r\n j = Math.trunc(j / 10);\r\n }\r\n t.reverse();\r\n nonprime.push(t.join(''));\r\n }\r\n }\r\n}\r\nfunction solve(n, s) {\r\n for (let t of nonprime) {\r\n let ok = true;\r\n let from = 0;\r\n for (let i = 0; i < t.length; i++) {\r\n let nl = s.indexOf(t[i], from);\r\n if (nl == INIT) {\r\n ok = false;\r\n break;\r\n }\r\n from = nl + 1;\r\n }\r\n // printf(\"s %s t %s ok %d\\n\", s, t, ok);\r\n if (ok) {\r\n printf(\"%d\\n%s\\n\", t.length, t);\r\n return;\r\n }\r\n }\r\n}\r\nfunction main() {\r\n sieve();\r\n // for (let x of nonprime) {\r\n // printf(\"x %d\\n\", x);\r\n // }\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n solve(n, s);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst MAX = 1000;\r\nconst prime = Array.from({ length: MAX }).fill(true);\r\nconst nonprime = [];\r\nfunction sieve() {\r\n nonprime.push('1'); // neither prime nor composite\r\n prime[0] = prime[1] = false;\r\n for (let i = 2; i < MAX; i++) {\r\n if (prime[i]) {\r\n for (let j = i; i * j < MAX; j++) {\r\n prime[i * j] = false;\r\n }\r\n }\r\n else {\r\n let j = i;\r\n let t = [];\r\n while (j > 0) {\r\n t.push(String(j % 10));\r\n j = Math.trunc(j / 10);\r\n }\r\n t.reverse();\r\n nonprime.push(t.join(''));\r\n }\r\n }\r\n}\r\nfunction solve(n, s) {\r\n for (let t of nonprime) {\r\n let ok = true;\r\n let from = 0;\r\n for (let i = 0; i < t.length; i++) {\r\n let nl = s.indexOf(t[i], from);\r\n if (nl == INIT) {\r\n ok = false;\r\n break;\r\n }\r\n from = nl + 1;\r\n }\r\n // printf(\"s %s t %s ok %d\\n\", s, t, ok);\r\n if (ok) {\r\n printf(\"%d\\n%s\\n\", t.length, t);\r\n return;\r\n }\r\n }\r\n}\r\nfunction main() {\r\n sieve();\r\n // for (let x of nonprime) {\r\n // printf(\"x %d\\n\", x);\r\n // }\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n solve(n, s);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst MAX = 1000;\r\nconst prime = Array.from({ length: MAX }).fill(true);\r\nconst comp = [];\r\nfunction sieve() {\r\n prime[0] = prime[1] = false;\r\n for (let i = 2; i < MAX; i++) {\r\n if (prime[i]) {\r\n for (let j = i; i * j < MAX; j++) {\r\n prime[i * j] = false;\r\n }\r\n }\r\n else {\r\n let j = i;\r\n let t = [];\r\n while (j > 0) {\r\n t.push(String(j % 10));\r\n j = Math.trunc(j / 10);\r\n }\r\n t.reverse();\r\n comp.push(t.join(''));\r\n }\r\n }\r\n}\r\nfunction solve(n, s) {\r\n const has = af(10).fill(INIT);\r\n for (let i = 0; i < n; i++) {\r\n let d = s.charCodeAt(i) - '0'.charCodeAt(0);\r\n if (has[d] == INIT) {\r\n has[d] = i;\r\n }\r\n }\r\n const singles = [1, 4, 6, 8, 9];\r\n for (let d of singles) {\r\n if (has[d] != INIT) {\r\n printf(\"1\\n%d\\n\", d);\r\n return;\r\n }\r\n }\r\n for (let t of comp) {\r\n let ok = true;\r\n let from = 0;\r\n for (let i = 0; i < t.length; i++) {\r\n let nl = s.indexOf(t[i], from);\r\n if (nl == INIT) {\r\n ok = false;\r\n break;\r\n }\r\n from = nl + 1;\r\n }\r\n // printf(\"s %s t %s ok %d\\n\", s, t, ok);\r\n if (ok) {\r\n printf(\"%d\\n%s\\n\", t.length, t);\r\n return;\r\n }\r\n }\r\n}\r\nfunction main() {\r\n sieve();\r\n // for (let x of comp) {\r\n // printf(\"x %d\\n\", x);\r\n // }\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n solve(n, s);\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst { checkPrime } = require(\"crypto\");\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const prime = (n) => {\r\n for (let i = 2; i * i <= n; i++) {\r\n if (n % i === 0) return false;\r\n }\r\n return true;\r\n };\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let obj = { 2: 1, 3: 1, 5: 1, 7: 1 },\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) {\r\n flag = 1;\r\n console.log(1);\r\n console.log(arr[i]);\r\n break;\r\n }\r\n }\r\n if (flag === 1) continue;\r\n for (let i = 0; i < n; i++) {\r\n let r = arr[i] + \"\";\r\n for (let j = i + 1; j < n; j++) {\r\n let k = r + arr[j];\r\n if (!prime(parseInt(k))) {\r\n console.log(k.length);\r\n console.log(k);\r\n flag = 1;\r\n break;\r\n }\r\n }\r\n if (flag === 1) break;\r\n }\r\n if (flag === 1) continue;\r\n console.log(arr.length);\r\n console.log(arr.join(\"\"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(u = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= u.length\r\n },\r\n readLine: c,\r\n readLineAsNumber: function () {\r\n return Number(c())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = c().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = c().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function c() {\r\n return u[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let o = 0\r\n return {\r\n flush: c,\r\n print: function (t) {\r\n i('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n i(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function c() {\r\n n.write(u.toString(e, 0, o)), (o = 0)\r\n }\r\n function i(t) {\r\n const i = Buffer.byteLength(t, e)\r\n r - o < i && (c(), i >= r) ? n.write(t) : (u.write(t, o, e), (o += i))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = t.readLineAsNumber()\r\n for (let r = 1; r <= n; ++r) {\r\n const n = e(t.readLineAsNumber(), t.readLine().trim())\r\n t.println(n.length), t.println(n)\r\n }\r\n function e(t, n) {\r\n for (let e = 0; e < t; ++e) {\r\n const t = n[e]\r\n if ('1' === t || '4' === t || '6' === t || '8' === t || '9' === t)\r\n return t\r\n }\r\n const e = [],\r\n r = [],\r\n u = new Array(10).fill(!1)\r\n for (let o = 0; o < t; ++o) {\r\n const t = n[o],\r\n c = Number(t)\r\n if (o > 0) {\r\n if (2 === c || 5 === c) return n.slice(o - 1, o + 1)\r\n if (u[c]) return t.concat(t)\r\n }\r\n switch (((u[c] = !0), c % 3)) {\r\n case 1:\r\n if (r.length > 0) {\r\n const [e] = r\r\n return n[e].concat(t)\r\n }\r\n e.push(o)\r\n break\r\n case 2:\r\n if (e.length > 0) {\r\n const [r] = e\r\n return n[r].concat(t)\r\n }\r\n r.push(o)\r\n }\r\n }\r\n for (let u = 0; u < t; ++u) {\r\n switch (Number(n[u]) % 3) {\r\n case 1:\r\n if ((e.push(u), 3 === e.length)) {\r\n const [t, r, u] = e\r\n return n[t].concat(n[r]).concat(n[u])\r\n }\r\n break\r\n case 2:\r\n if ((r.push(u), 3 === r.length)) {\r\n const [t, e, u] = r\r\n return n[t].concat(n[e]).concat(n[u])\r\n }\r\n }\r\n }\r\n return ''\r\n }\r\n})\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j===0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n \r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst ZERO = '0'.charCodeAt(0);\r\nfunction solve(n, s) {\r\n const has = af(10).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let d = s.charCodeAt(i) - ZERO;\r\n has[d]++;\r\n }\r\n // printf(\"s %s\\nhas %j\\n\", s, has);\r\n // case I\r\n const singles = [1, 4, 6, 8, 9];\r\n for (let d of singles) {\r\n if (has[d] > 0) {\r\n return String(d);\r\n }\r\n }\r\n // case II\r\n for (let i = 1; i <= 9; i++) {\r\n if (has[i] > 1) {\r\n return String([i, i].join(''));\r\n }\r\n }\r\n // case III\r\n let twopos = s.indexOf('2');\r\n if (twopos > 0) {\r\n return s.substring(twopos - 1, twopos + 1);\r\n }\r\n let fivepos = s.indexOf('5');\r\n if (fivepos > 0) {\r\n return s.substring(fivepos - 1, fivepos + 1);\r\n }\r\n // case IV\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let x = s.charCodeAt(i) - ZERO;\r\n let y = s.charCodeAt(j) - ZERO;\r\n if ((x + y) % 3 == 0) {\r\n return String([x, y].join(''));\r\n }\r\n }\r\n }\r\n printf(\"failed on %s\\n\", s);\r\n check(false);\r\n return 'XXX'; // not reached\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n let ans = solve(n, s);\r\n printf(\"%d\\n\", ans.length);\r\n printf(\"%s\\n\", ans);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j===0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n print(prime);\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j===0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n print(prime);\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j===0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n print(prime);\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j===0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var prime=[];\r\nfor(var i=2;i<542;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n solution(k,n);\r\n \r\n}\r\n\r\nfunction solution(k,n){\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\n var prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n \r\nfunction main() {\r\n\r\n\r\nvar t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n for(var i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\nvar prime=[];\r\nfor(var i=2;i<100;i++){\r\n var primeTrue=true\r\n for(var j=2;j<=Math.sqrt(i);j++){\r\n if(i%j==0){\r\n primeTrue=false;\r\n }\r\n }\r\n if(primeTrue){\r\n prime.push(i);\r\n }\r\n}\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline());\r\n\r\nwhile(t--){\r\n var k=parseInt(readline());\r\n var n=readline();\r\n\r\n for(var i=0;i {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst ZERO = '0'.charCodeAt(0);\r\nfunction solve(n, s) {\r\n const has = af(10).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let d = s.charCodeAt(i) - ZERO;\r\n has[d]++;\r\n }\r\n printf(\"s %s\\nhas %j\\n\", s, has);\r\n // case I\r\n const singles = [1, 4, 6, 8, 9];\r\n for (let d of singles) {\r\n if (has[d] > 0) {\r\n return String(d);\r\n }\r\n }\r\n // case II\r\n for (let i = 1; i <= 9; i++) {\r\n if (has[i] > 1) {\r\n return String([i, i].join(''));\r\n }\r\n }\r\n // case III\r\n let twopos = s.indexOf('2');\r\n if (twopos > 0) {\r\n return s.substring(twopos - 1, twopos + 1);\r\n }\r\n let fivepos = s.indexOf('5');\r\n if (fivepos > 0) {\r\n printf(\"fivepos %d\\n\", fivepos);\r\n return s.substring(fivepos - 1, fivepos + 1);\r\n }\r\n // case IV\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let x = s.charCodeAt(i) - ZERO;\r\n let y = s.charCodeAt(j) - ZERO;\r\n if ((x + y) % 3 == 0) {\r\n return String([x, y].join(''));\r\n }\r\n }\r\n }\r\n printf(\"failed on %s\\n\", s);\r\n check(false);\r\n return 'XXX'; // not reached\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n let ans = solve(n, s);\r\n printf(\"%d\\n\", ans.length);\r\n printf(\"%s\\n\", ans);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst ZERO = '0'.charCodeAt(0);\r\nfunction solve(n, s) {\r\n const has = af(10).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n let d = s.charCodeAt(i) - ZERO;\r\n has[d]++;\r\n }\r\n // printf(\"s %s\\nhas %j\\n\", s, has);\r\n // case I\r\n const singles = [1, 4, 6, 8, 9];\r\n for (let d of singles) {\r\n if (has[d] > 0) {\r\n return String(d);\r\n }\r\n }\r\n // case II\r\n let twopos = s.indexOf('2');\r\n if (twopos > 0) {\r\n return s.substring(twopos - 1, 2);\r\n }\r\n let fivepos = s.indexOf('5');\r\n if (fivepos > 0) {\r\n return s.substring(fivepos - 1, 2);\r\n }\r\n // case II\r\n for (let i = 0; i <= 9; i++) {\r\n if (has[i] > 1) {\r\n return String([i, i].join(''));\r\n }\r\n }\r\n // case IV\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let x = s.charCodeAt(i) - ZERO;\r\n let y = s.charCodeAt(j) - ZERO;\r\n if ((x + y) % 3 == 0) {\r\n return String([x, y].join(''));\r\n }\r\n }\r\n }\r\n printf(\"failed on %s\\n\", s);\r\n check(false);\r\n return 'XXX'; // not reached\r\n}\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n let ans = solve(n, s);\r\n printf(\"%d\\n\", ans.length);\r\n printf(\"%s\\n\", ans);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nconst MAX = 1000;\r\nconst prime = Array.from({ length: MAX }).fill(true);\r\nconst comp = [];\r\nfunction sieve() {\r\n prime[0] = prime[1] = false;\r\n for (let i = 2; i < MAX; i++) {\r\n if (prime[i]) {\r\n for (let j = i; i * j < MAX; j++) {\r\n prime[i * j] = false;\r\n }\r\n }\r\n else {\r\n let j = i;\r\n let t = [];\r\n while (j > 0) {\r\n t.push(String(j % 10));\r\n j = Math.trunc(j / 10);\r\n }\r\n t.reverse();\r\n comp.push(t.join(''));\r\n }\r\n }\r\n}\r\nfunction solve(n, s) {\r\n for (let t of comp) {\r\n let ok = true;\r\n let from = 0;\r\n for (let i = 0; i < t.length; i++) {\r\n let nl = s.indexOf(t[i], from);\r\n if (nl == INIT) {\r\n ok = false;\r\n break;\r\n }\r\n from = nl + 1;\r\n }\r\n // printf(\"s %s t %s ok %d\\n\", s, t, ok);\r\n if (ok) {\r\n printf(\"%d\\n%s\\n\", t.length, t);\r\n return;\r\n }\r\n }\r\n}\r\nfunction main() {\r\n sieve();\r\n // for (let x of comp) {\r\n // printf(\"x %d\\n\", x);\r\n // }\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let s = nextStr();\r\n solve(n, s);\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst { checkPrime } = require(\"crypto\");\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const prime = (n) => {\r\n for (let i = 2; i * i <= n; i++) {\r\n if (n % i === 0) return false;\r\n }\r\n return true;\r\n };\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let obj = { 2: 1, 3: 1, 5: 1, 7: 1 },\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) {\r\n flag = 1;\r\n console.log(1);\r\n console.log(arr[i]);\r\n break;\r\n }\r\n }\r\n if (flag === 1) continue;\r\n arr.sort((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n let r = arr[i] + \"\";\r\n for (let j = i + 1; j < n; j++) {\r\n let k = r + arr[j];\r\n if (!prime(parseInt(k))) {\r\n console.log(k.length);\r\n console.log(k);\r\n flag = 1;\r\n }\r\n }\r\n if (flag === 1) break;\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst { checkPrime } = require(\"crypto\");\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const prime = (n) => {\r\n for (let i = 2; i * i <= n; i++) {\r\n if (n % i === 0) return false;\r\n }\r\n return true;\r\n };\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let obj = { 2: 1, 3: 1, 5: 1, 7: 1 },\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) {\r\n flag = 1;\r\n console.log(1);\r\n console.log(arr[i]);\r\n break;\r\n }\r\n }\r\n if (flag === 1) continue;\r\n let r = \"\";\r\n for (let i = 0; i < n; i++) {\r\n r += arr[i];\r\n for (let j = i + 1; j < n; j++) {\r\n let k = r + arr[j];\r\n if (!prime(parseInt(k))) {\r\n console.log(k.length);\r\n console.log(k);\r\n flag = 1;\r\n break;\r\n }\r\n }\r\n if (flag === 1) break;\r\n }\r\n if (flag === 1) continue;\r\n console.log(arr.length);\r\n console.log(arr.join(\"\"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst { checkPrime } = require(\"crypto\");\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const prime = (n) => {\r\n for (let i = 2; i * i <= n; i++) {\r\n if (n % i === 0) return false;\r\n }\r\n return true;\r\n };\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n let obj = { 2: 1, 3: 1, 5: 1, 7: 1 },\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (!obj[arr[i]]) {\r\n flag = 1;\r\n console.log(1);\r\n console.log(arr[i]);\r\n break;\r\n }\r\n }\r\n if (flag === 1) continue;\r\n let r = arr[0] + \"\";\r\n for (let i = 1; i < n; i++) {\r\n r += arr[i];\r\n if (!prime(parseInt(r))) {\r\n console.log(r.length);\r\n console.log(r);\r\n flag = 1;\r\n }\r\n }\r\n if (flag === 1) continue;\r\n console.log(arr.length);\r\n console.log(arr.join(\"\"));\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar k = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar p = [];\r\n\t\tvar output = \"\";\r\n\t\tfor(var i = 0; i < k; i++){\r\n\t\t\tif(s[i] == \"1\" || s[i] == \"4\" || s[i] == \"6\" || s[i] == \"8\" || s[i] == \"9\"){\r\n\t\t\t\toutput = \"1\\n\" + s[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(p.indexOf(s[i]) != -1){\r\n\t\t\t\toutput = \"2\\n\" + s[i] + s[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}else{\r\n\t\t\t\tp.push(s[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(output == \"\"){\r\n\t\t\tfor(var i = 1; i < (1 << p.length); i++){\r\n\t\t\t\tvar v = 0;\r\n\t\t\t\tfor(var j = 0; j < p.length; j++){\r\n\t\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\t\tv *= 10;\r\n\t\t\t\t\t\tv += myconv(p[j], 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(v >= 10 && !isPrime(v)){\r\n\t\t\t\t\toutput = \"2\\n\" + v;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction isPrime(val){\r\n\tif(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\r\n\t\treturn false;\r\n\t}else if(val == 2){\r\n\t\treturn true;\r\n\t}\r\n\tvar root = Math.floor(Math.sqrt(val));\r\n\tfor(var i = 3; i <= root; i += 2){\r\n\t\tif(val % i == 0){\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\treturn true;\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar k = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar p = [];\r\n\t\tvar output = \"\";\r\n\t\tfor(var i = 0; i < k; i++){\r\n\t\t\tif(s[i] == \"1\" || s[i] == \"4\" || s[i] == \"6\" || s[i] == \"8\" || s[i] == \"9\"){\r\n\t\t\t\toutput = \"1\\n\" + s[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}else if(p.indexOf(s[i]) != -1){\r\n\t\t\t\toutput = \"2\\n\" + s[i] + s[i];\r\n\t\t\t\tbreak;\r\n\t\t\t}else{\r\n\t\t\t\tp.push(myconv(s[i], 1));\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(output == \"\"){\r\n\t\t\tfor(var i = 1; i < (1 << p.length); i++){\r\n\t\t\t\tvar v = 0;\r\n\t\t\t\tfor(var j = 0; j < p.length; j++){\r\n\t\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\t\tv *= 10;\r\n\t\t\t\t\t\tv += p[j];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(!isPrime(v)){\r\n\t\t\t\t\toutput = \"2\\n\" + v;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\nfunction isPrime(val){\r\n\tif(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\r\n\t\treturn false;\r\n\t}else if(val == 2){\r\n\t\treturn true;\r\n\t}\r\n\tvar root = Math.floor(Math.sqrt(val));\r\n\tfor(var i = 3; i <= root; i += 2){\r\n\t\tif(val % i == 0){\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\treturn true;\r\n}"}, {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(n) {\r\n const t = n.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n i = 0\r\n return {\r\n init: async function () {\r\n const n = []\r\n ;(u = await new Promise(e => {\r\n t.on('data', t => n.push(t)),\r\n t.on('end', function () {\r\n const t = n.join('').split(os.EOL)\r\n e(t)\r\n })\r\n })),\r\n (i = 0)\r\n },\r\n dried: function () {\r\n return i >= u.length\r\n },\r\n readLine: o,\r\n readLineAsNumber: function () {\r\n return Number(o())\r\n },\r\n readIntegersOfLine: function () {\r\n const n = o().match(e)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n readNumsOfLine: function () {\r\n const n = o().match(r)\r\n return null == n ? [] : n.map(n => Number(n))\r\n },\r\n }\r\n function o() {\r\n return u[i++]\r\n }\r\n}\r\nfunction createOutput(n) {\r\n const t = n.stdout || process.stdout,\r\n e = n.encoding || 'ascii',\r\n r = n.outputBufferThreshold || 1 << 24,\r\n u = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: o,\r\n print: function (n) {\r\n s('string' == typeof n ? n : n.toString())\r\n },\r\n println: function (n) {\r\n s(('string' == typeof n ? n : n.toString()).concat('\\n'))\r\n },\r\n }\r\n function o() {\r\n t.write(u.toString(e, 0, i)), (i = 0)\r\n }\r\n function s(n) {\r\n const s = Buffer.byteLength(n, e)\r\n r - i < s && (o(), s >= r) ? t.write(n) : (u.write(n, i, e), (i += s))\r\n }\r\n}\r\nfunction createInputAndOutput(n) {\r\n return {\r\n ...createInput({ stdin: n.stdin, encoding: n.encoding }),\r\n ...createOutput({\r\n stdout: n.stdout,\r\n encoding: n.encoding,\r\n outputBufferThreshold: n.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(n, t, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(t && t())]),\r\n await n(r),\r\n r.flush()\r\n}\r\n__main__(function (n) {\r\n const t = n.readLineAsNumber()\r\n for (let r = 1; r <= t; ++r) {\r\n const t = e(n.readLineAsNumber(), n.readLine().trim())\r\n n.println(t.length), n.println(t.join(''))\r\n }\r\n function e(n, t) {\r\n const e = new Array(10).fill(!1),\r\n r = [],\r\n u = []\r\n for (let i = 0; i < n; ++i) {\r\n const n = Number(t[i])\r\n if (1 === n || 4 === n || 6 === n || 8 === n || 9 === n) return [n]\r\n if (i > 0) {\r\n if (2 === n || 5 === n) return [Number(t[i - 1]), n]\r\n if (e[n]) return [n, n]\r\n }\r\n switch (((e[n] = !0), n % 3)) {\r\n case 1:\r\n if ((r.push(i), 3 === r.length)) {\r\n const [n, e, u] = r\r\n return [Number(t[n]), Number(t[e]), Number(t[u])]\r\n }\r\n if (u.length > 0) {\r\n const [e] = u\r\n return [Number(t[e]), n]\r\n }\r\n break\r\n case 2:\r\n if ((u.push(i), 3 === u.length)) {\r\n const [n, e, r] = u\r\n return [Number(t[n]), Number(t[e]), Number(t[r])]\r\n }\r\n if (r.length > 0) {\r\n const [e] = r\r\n return [Number(t[e]), n]\r\n }\r\n }\r\n }\r\n return []\r\n }\r\n})\r\n"}], "src_uid": "22c0489eec3d8e290fcbcf1aeb3bb66c"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < arr.length) {\n console.log(1);\n } else {\n console.log(sum - arr.length);\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n // const x = readline();\r\n // console.log(x);\r\n // var line2 = readline();\r\n // console.log(line2);\r\n // print(x);\r\n // print(line2);\r\n \tlet testCaseNum = readline();\r\n\ttestCaseNum = +testCaseNum;\r\n \r\n\twhile (testCaseNum > 0) {\r\n\t\treadline();\r\n \r\n\t\tlet arr = readline().split(' ');\r\n\t\tlet total = arr.reduce((total, item) => total + +item, 0);\r\n\t\tif (total == arr.length) {\r\n\t\t\t// return \r\n\t\t\tconsole.log(0);\r\n\t\t} else if (total < arr.length) {\r\n\t\t\tconsole.log(1);\r\n\t\t} else {\r\n\t\t\tconsole.log(total - arr.length);\r\n\t\t}\r\n \r\n\t\ttestCaseNum --;\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t e = lines[i];\n\t }else{\n\t var k = lines[i].split(' ').map(Number);\n\t var sum = -e;\n\t for(j = 0; j < e; j++){\n\t sum += k[j];\n\t }\n\t if(sum < 0){\n\t sum = 1;\n\t }\n\t console.log(sum);\n\t }\n\t}\n});"}, {"source_code": "var matr = 'haha';\r\n\r\nfunction create(str) {\r\n var hahaIndexArr = [];\r\n for (var i = 0; i < str.length; i++) {\r\n var hasWrong = false;\r\n for (var j = 0; j < matr.length; j++) {\r\n if (str[i + j] !== matr[j]) {\r\n hasWrong = true;\r\n break;\r\n }\r\n }\r\n if (!hasWrong) {\r\n hahaIndexArr.push(i);\r\n }\r\n }\r\n if (hahaIndexArr.length === 0) {\r\n if (str.length < 8) {\r\n return [str, -1, str];\r\n }\r\n return [str.substr(0, 4), 0, str.substr(str.length - 4, 0)];\r\n }\r\n var preff = str.substr(0, Math.min(4, hahaIndexArr[0])) || 'ha';\r\n var suff = str.substr(Math.max(hahaIndexArr[hahaIndexArr.length - 1] + 4, str.length - 4)) || 'ha';\r\n return [preff, hahaIndexArr.length, suff];\r\n}\r\nfunction summ(a, b) {\r\n var createMiddle = create(a[2] + b[0]);\r\n if (a[1] === -1 && b[1] === -1) {\r\n return createMiddle;\r\n }\r\n var preff = a[1] === -1 ? createMiddle[0] : a[0];\r\n var suff = b[1] === -1 ? createMiddle[2] : b[2];\r\n var asum = a[1] === -1 ? 0 : a[1];\r\n var bsum = b[1] === -1 ? 0 : b[1];\r\n var midSum = createMiddle[1] === -1 ? 0 : createMiddle[1];\r\n return [preff, asum + bsum + midSum, suff];\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var arr = readArray(Number);\r\n var sum = 0;\r\n for (var i = 0; i < n; i++) {\r\n sum += arr[i];\r\n }\r\n if (n <= sum) {\r\n write(sum - n);\r\n return;\r\n }\r\n write(1);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n const sum = a.reduce((acc, cur) => acc + cur, 0);\r\n if (sum == a.length){\r\n console.log(0);\r\n }\r\n else if (sum < a.length) {\r\n console.log(1);\r\n } else {\r\n console.log(sum - a.length);\r\n }\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].split(' ').map(Number)\n console.log(solve(n, arr));\n }\n});\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n if (sum < n) {\n return 1\n } else if (sum > n) {\n return sum - n\n } else {\n return 0\n }\n}\n"}, {"source_code": "var cases = +readline();\r\nconst average = (array) => array.reduce((a, b) => a + b) / array.length;\r\nfor (var i = 1; i<=cases; i++){\r\n len = +readline();\r\n arr = readline().split(' ').map(x=>+x);\r\n sum = arr.reduce((a, b) => a + b);\r\n avg = sum / arr.length;\r\n \r\n if (avg < 1){ \r\n print(1);\r\n } else if (avg == 1) {\r\n print(0);\r\n } else {\r\n print(sum-arr.length);\r\n }\r\n}"}, {"source_code": "var t = Number(readline());\r\n\r\n\r\nwhile (t--) {\r\n var len = Number(readline());\r\n var arr = readline().split(\" \");\r\n var sum = 0;\r\n\r\n for (var i = 0; i < len; i++) {\r\n arr[i] = Number(arr[i]);\r\n sum += Number(arr[i]);\r\n\r\n }\r\n\r\n if (sum <= 0 || sum - len < 0) \r\n print(1);\r\n else {\r\n print(sum - len);\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n\r\nfor (var q = 0; q < t; ++q) {\r\n var n = +readline();\r\n var a = readline().split(' ').map(ai => +ai);\r\n\r\n var sum = a.reduce((sum, ai) => sum + ai);\r\n\r\n if (sum >= n) {\r\n print(sum - n);\r\n } else {\r\n print(1);\r\n }\r\n}"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst int = parseInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n let sum = sm(a);\r\n if (sum < n) return pr(1);\r\n pr(abs(sum) - n);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst int = parseInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let sum = cnt = 0;\r\n for (const x of a) {\r\n if (x != 0) cnt++;\r\n sum += x;\r\n }\r\n if (sum <= n) return pr(1);\r\n // pr(sum, n)\r\n pr(abs(sum) - cnt);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst int = parseInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let sum = sm(a);\r\n if (sum < 1) return pr(1);\r\n pr(abs(sum) - n);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst int = parseInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let tmp = [];\r\n for (const x of a) {\r\n if (a != 0) tmp.push(x);\r\n }\r\n // pr(a);\r\n // pr(tmp)\r\n pr(cal(tmp));\r\n};\r\n\r\nconst cal = (a) => {\r\n let n = a.length;\r\n let sum = sm(a);\r\n return abs(sum) - n;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst int = parseInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let sum = sm(a);\r\n if (sum == 0) return pr(n);\r\n let fL = abs(sum);\r\n pr(fL - n);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0n);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n // pr(n, a);\r\n let sum = sm(a);\r\n if (sum < 0) sum = -sum;\r\n pr((sum - n).toString());\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => ll(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n a = a.map(x => abs(x));\r\n let sum = sm(a);\r\n // pr(sum);\r\n pr(sum - n);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 06/18/21 morning\r\n * https://codeforces.com/contest/1537/problem/A\r\n */\r\nconst solve = (n, a) => {\r\n let sum = sm(a);\r\n pr(abs(sum) - n);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum === 0) {\n console.log(0);\n } else {\n if (sum < arr.length) {\n console.log(1);\n } else {\n console.log(sum - arr.length);\n }\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < 0) {\n console.log(1);\n } else if (sum === 0) {\n console.log(0);\n } else if (sum - arr.length === 0) {\n console.log(0);\n } else {\n if (sum < arr.length) {\n console.log(1);\n } else {\n console.log(sum - arr.length);\n }\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < 0) {\n console.log(1);\n } else if (sum === 0) {\n console.log(0);\n } else if (sum - arr.length === 0) {\n console.log(0);\n } else {\n console.log(Math.max(1, sum - arr.length));\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < 0) {\n console.log(1);\n } else if (sum === 0) {\n console.log(0);\n } else {\n console.log(Math.max(0, sum - arr.length));\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < 0) {\n console.log(1);\n } else if (sum === 0) {\n console.log(0);\n } else {\n console.log(Math.max(1, sum - arr.length));\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(\" \").map(Number);\n const sum = arr.reduce((prev, curr) => prev + curr, 0);\n\n if (sum < 0) {\n console.log(1);\n } else if (sum === 0) {\n console.log(0);\n } else {\n console.log(sum - arr.length);\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "var cases = +readline();\r\nconst average = (array) => array.reduce((a, b) => a + b) / array.length;\r\nfor (var i = 1; i<=cases; i++){\r\n len = +readline();\r\n arr = readline().split(' ').map(x=>+x);\r\n sum = arr.reduce((a, b) => a + b);\r\n avg = sum / arr.length;\r\n \r\n if (avg <= 1){ \r\n print(1);\r\n } else if (avg == 1) {\r\n print(0);\r\n } else {\r\n print(sum-arr.length);\r\n }\r\n}"}, {"source_code": "var t = Number(readline());\r\n\r\n\r\nwhile (t--) {\r\n var len = Number(readline());\r\n var arr = readline().split(\" \");\r\n var sum = 0;\r\n\r\n for (var i = 0; i < len; i++) {\r\n arr[i] = Number(arr[i]);\r\n sum += Number(arr[i]);\r\n\r\n }\r\n\r\n if (sum <= 0) \r\n print(1);\r\n else {\r\n print(sum - len);\r\n }\r\n}"}], "src_uid": "b5985b619652e606ac96554ecfb9346a"} {"source_code": ";(function () {\n\tvar n = readline().split(' ');\n\tvar k = +n[1];\n\tn = +n[0];\n\n\tvar s = readline().split(' ');\n\tvar x = 0;\n\tfor (var i = 0; i < s.length; i++) {\n\t\tx += s[i].split('').filter(function (e) { return /[47]/.test(e); }).length <= k;\n\t}\n\n\tprint(x);\n\n}).call(this);", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, k] = d.split(' ').map(Number);\n return;\n }\n\n const arr = d.split(' ');\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n let counter = 0;\n for (let j = 0; j < arr[i].length; j++) {\n if (arr[i][j] === '4' || arr[i][j] === '7') {\n counter++;\n }\n }\n\n if (counter <= k) {\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "function main(stdin) {\n var lines = stdin.split(\"\\n\");\n var _a = lines[0].split(\" \").map(function (v) { return parseInt(v); }), n = _a[0], k = _a[1];\n var count = 0;\n lines[1].split(\" \").forEach(function (v) {\n var amount = Array.from(v).reduce(function (acc, cur) { return ([\"4\", \"7\"].includes(cur) ? acc + 1 : acc); }, 0);\n if (amount <= k)\n count++;\n });\n console.log(count);\n}\nmain(require(\"fs\").readFileSync(0, \"utf-8\"));\n"}, {"source_code": "print(function(n,k){\n\treturn readline().split(' ').filter(function(s){\n\t\treturn s.replace(/[^47]+/g, '').length<=k;\n\t}).length;\n}.apply(0, readline().split(' ').map(Number)))"}, {"source_code": "var info = readline().split(' ').map(Number);\nvar Arr = readline().split(' ');\nvar result = 0;\nfor (i=0; i= tokens.length){\n\t\ttokens = readline().split(/[\\s]+/);\n\t\tnumTokens = 0;\n\t}\n\treturn tokens[numTokens++];\t\t\n}\nfunction nextInt(){\n\treturn parseInt(next(),10);\n}\nfunction main(){\n\tvar n,k,a,i,cont;\n\tn = nextInt();\n\tk = nextInt();\n\tvar ans = 0;\n\tfor(i = 0; i < n; i++){\n\t\ta = next();\n\t\tcont = 0;\n\t\ta.split(\"\").forEach(function(c){\n\t\t\tif(c==\"4\" || c==\"7\")\n\t\t\t\tcont++;\n\t\t});\n\t\tif(cont <= k)\n\t\t\tans++;\n\t}\n\tprint(ans);\n}\nmain();"}], "negative_code": [], "src_uid": "6bb26991c9ea70e51a6bda5653de8131"} {"source_code": "var s = readline(),\n\tk = parseInt( readline() );\n\t\nif (0 !== s.length % k) {\n\tprint( 'NO' );\n} else {\n\tvar l = s.length / k,\n\t l2 = l / 2,\n\t\tok = true;\n\tfor (var i=0; i= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = \"\";\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n \n this.isPalindrome = function( str ) {\n \tvar i , j , len ;\n \tlen = str.length ;\n \tfor( i = 0 , j = len - 1 ; i < j ; i++ , j-- ) {\n \t\tif( str.charAt( i ) != str.charAt( j ) ) {\n \t\t\treturn false ;\n \t\t}\n \t}\n \treturn true ;\n } ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len , a ;\n res = 0 ;\n len = this.s.length ;\n if( len % this.k != 0 ) {\n \tprint( 'NO' ) ;\n \treturn null ;\n }\n a = Math.floor( len / this.k ) ;\n temp = '' ;\n for( i = 0 ; i < len ; i++ ) {\n \ttemp += this.s.charAt( i ) ;\n \tif( temp.length == a ) {\n \t\tif( this.isPalindrome( temp ) == true ) {\n\t \t\tres++ ;\n\t \t}\n\t \ttemp = '' ;\n \t}\n }\n if( res == this.k ) {\n \tprint( 'YES' ) ;\n }\n else {\n \tprint( 'NO' ) ;\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n \tthis.s = irObj.nextString();\n this.k = irObj.nextInt();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "function toi(x){return parseInt(x);}\nfunction isP(x){\n for(var i=0;iNumber(x));\n var c = [2,3,5,7,11,13,17,19,23,29,31];\n var u = [0,0,0,0, 0, 0, 0, 0, 0, 0, 0];\n var k = [];\n var m = 0;\n for(var i=0;i {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,\n 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,\n 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691,\n 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797,\n 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,\n 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n\nfunction main() {\n let t = readInt()\n while (t--) {\n const n = readInt()\n const a = readInts()\n\n const ans = new Array(n).fill(-1)\n const pms = a.map(a => primeFactors(a))\n const pms2 = new Array(n)\n for(let i = 0;i < n; i++) {\n let m = {}\n let el = pms[i]\n el.forEach(a => m[a] = true)\n pms2[i] = m\n }\n let m = 1\n let count = 0\n // wr(pms2)\n for(let i = 0, l = primes.length; i < l && count < n; i++) {\n let pr = primes[i]\n let f = false\n for(let j = 0; j < n && count < n; j++) {\n if(ans[j] === -1) {\n if(pms2[j][pr]) {\n ans[j] = m\n count++\n f = true\n }\n }\n }\n if(f) m++\n }\n\n wr(Math.max(...ans))\n // const ans2 = new Array(n)\n // for(let i = 0;i < n; i++) {\n // ans2[a[i][1]] = ans[i]\n // }\n wr(ans.join(' '))\n }\n}\n\n\nfunction gcd(x, y) {\n if(y === 0) return x\n else return gcd(y, x % y)\n}\n\n\nfunction primeFactors(num) {\n const factors = []\n while(num % 2 === 0) {\n factors.push(2)\n num /= 2\n }\n for(let i = 3, sqrt = Math.floor(Math.sqrt(num)); i <= sqrt; i += 2) {\n while(num % i === 0) {\n factors.push(i)\n num /= i\n }\n }\n if(num > 2) factors.push(num)\n return factors\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t * 2);\n \tvar primes = Array.from(sieveOfEratos(1000));\n \tprimes.sort(function(a,b){\n \treturn a - b;\n });\n for(var i = 0; i < t; i++){\n var n = nextInt();\n \tvar list = nextIntArray();\n \tvar gcds = {};\n \tfor(var j = 0; j < n; j++){\n for(var k = 0; k < primes.length; k++){\n if(list[j] % primes[k] == 0){\n if(gcds[primes[k]]){\n gcds[primes[k]].add(list[j]);\n }else{\n gcds[primes[k]] = new Set([list[j]]);\n }\n break;\n }\n }\n }\n \t//myerr(gcds);\n \tvar keys = Object.keys(gcds);\n \t//myerr(keys);\n \toutput[i * 2] = keys.length;\n \tvar index = new Array(keys.length);\n \tfor(var j = 0; j < keys.length; j++){\n index[j] = keys[j];\n }\n \tvar thisOut = new Array(n);\n \tfor(var j = 0; j < n; j++){\n for(var k = 0; k < keys.length; k++){\n if(gcds[keys[k]].has(list[j])){\n thisOut[j] = (k + 1);\n break;\n }\n }\n }\n \toutput[i * 2 + 1] = myconv(thisOut,8);\n }\n myout(myconv(output,9));\n}\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}\nfunction sieveOfEratos(val){\n var primes = new Set();\n var nums = new Set();\n var used = [2,3,5,7,11];//\u3053\u308c\u3089\u306f\u65e2\u306b\u7d20\u6570\u3067\u3042\u308b\u3068\u3059\u308b\n var underPrime = 13;//\u3053\u306e\u5024\u304b\u3089+2\u3054\u3068\u306b\u8ffd\u52a0\u3002\u2191\u306e\u5024\u3067\u5272\u308a\u5207\u308c\u305f\u3082\u306e\u306f\u4f55\u3082\u3057\u306a\u3044\n if(val <= 1){\n return nums;\n }\n for(var i = 0; i < used.length; i++){if(used[i] <= val){nums.add(used[i]);}}\n for(var i = underPrime; i <= val; i=i+2){\n var continued = false;\n for(var j = 0; j < used.length; j++){\n if(i % used[j] == 0){continued = true; break;}\n }\n if(continued){continue;}\n nums.add(i);\n }\n for(var i = 2; i <= Math.sqrt(val); (i==2) ? i++ : i=i+2){\n if(!nums.has(i)){continue;}\n var count = 1;\n while(i * count <= val){\n if(i <= 11 && used.indexOf(i) != -1){break;}\n if(count == 1){primes.add(i);}\n nums.delete(i*count);\n count++;\n }\n }\n var primeItr = Array.from(primes);\n for(var i = 0; i < primeItr.length; i++){\n nums.add(primeItr[i]);\n }\n return nums;\n}\n"}], "negative_code": [{"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var c = [2,3,5,7,11,13,17,19,23,29,31];\n var u = [1,1,1,1, 1, 1, 1, 1, 1, 1, 1];\n var m = 0;\n for(var i=0;iNumber(x));\n var c = [2,3,5,7,11,13,17,19,23,29,31];\n var u = [1,1,1,1, 1, 1, 1, 1, 1, 1, 1];\n var m = 0;\n for(var i=0;iNumber(x));\n var c = [2,3,5,7,11,13,17,19,23,29,31];\n var u = [1,1,1,1, 1, 1, 1, 1, 1, 1, 1];\n var m = 0;\n for(var i=0;iNumber(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t * 2);\n output[0] = 2;\n output[1] = \"1 1 2\";\n output[2] = 2;\n output[3] = \"1 2\";\n output[4] = 11;\n output[5] = \"4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6\";\n myout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,\n 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,\n 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691,\n 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797,\n 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,\n 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n\nfunction main() {\n let t = readInt()\n while (t--) {\n const n = readInt()\n const a = readInts()\n\n const ans = new Array(n).fill(-1)\n const pms = a.map(a => primeFactors(a))\n const pms2 = new Array(n)\n for(let i = 0;i < n; i++) {\n let m = {}\n let el = pms[i]\n el.forEach(a => m[a] = true)\n pms2[i] = m\n }\n let m = 1\n let count = 0\n for(let i = 0, l = primes.length; i < l && count < n; i++) {\n let pr = primes[i]\n for(let j = 0; j < n && count < n; j++) {\n if(ans[j] === -1) {\n if(pms2[j][pr]) {\n ans[j] = m\n count++\n }\n }\n }\n m++\n }\n\n wr(Math.max(...ans))\n // const ans2 = new Array(n)\n // for(let i = 0;i < n; i++) {\n // ans2[a[i][1]] = ans[i]\n // }\n wr(ans.join(' '))\n }\n}\n\n\nfunction gcd(x, y) {\n if(y === 0) return x\n else return gcd(y, x % y)\n}\n\n\nfunction primeFactors(num) {\n const factors = []\n while(num % 2 === 0) {\n factors.push(2)\n num /= 2\n }\n for(let i = 3, sqrt = Math.floor(Math.sqrt(num)); i <= sqrt; i += 2) {\n while(num % i === 0) {\n factors.push(i)\n num /= i\n }\n }\n if(num > 2) factors.push(num)\n return factors\n}\n"}], "src_uid": "c3cd949c99e96c9da186a34d49bd6197"} {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\n// used for look_for parameter\nvar plus = '+'; \nvar minus = '-';\n\n// if possible get rebus with this function\nvar getRebus = function(increase, ones, look_for) {\n\tvar sum = 0;\n\tif (increase == count.plus) {\n\t\tsum = ones + n;\n\t} else {\n\t\tsum = ones - n;\n\t}\n\t\n\tvar diff = sum - increase;\n\tvar a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n\n\tvar b = diff % (n - 1) + 1; // b --> change another ? to b\n\tvar counter = 0; // used to count how many ?'s are replaced with n (count a)\n\n\t// if diff is 0, I want every ? to be 1\n\tif (diff === 0) {\n\t\trebus[0] = 1;\n\t// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)\n\t} else if (a === 0 && increase == count.plus) {\n\t\trebus[0] = b;\n\t} else {\n\t\t// ONLY when increasing +?'s\n\t\tif (increase == count.plus) {\n\t\t\trebus[0] = n;\n\t\t\tcounter = 1;\n\t\t// ONLY when increasing -?'s\n\t\t} else {\n\t\t\trebus[0] = 1;\n\t\t}\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1\n\t\t\tif (counter == a) {\n\t\t\t\tif (rebus[i] == look_for) {\n\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (rebus[i] == look_for) {\n\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\tcounter += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// replacing all other ?'s with 1's\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\n\trebus = rebus.join(' ');\n\n\treturn rebus;\n};\n\n// Increase 'minus' ?'s\nif (count.plus - count.minus > n) {\n\tvar sum = count.plus - n;\n\tif (sum >= count.minus && sum <= count.minus * n) {\n\t\tprint('Possible');\n\t\tprint(getRebus(count.minus, count.plus, minus));\n\t} else {\n\t\tprint('Impossible');\n\t}\n// Increase 'plus' ?'s\n} else {\n\tvar sum = count.minus + n;\n\tif (sum >= count.plus && sum <= count.plus * n) {\n\t\tprint('Possible');\n\t\tprint(getRebus(count.plus, count.minus, plus));\n\t} else {\n\t\tprint('Impossible');\n\t}\n}\n", "positive_code": [{"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 1, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\n// Do I need to modify the -? or the +?s\nvar diff = 0;\nvar a = 0; // a --> change a number of ?'s to n\nvar b = 1; // b --> change another -? to b\nvar counter = 0; // used to count how many ?'s are replaced with n (count a)\n\n// Modify 'minus' ?\nif (count.plus - count.minus > n) {\n\t// modify 'minus'\n\t// minus_sum is what the sum of all -? needs to be\n\tvar minus_sum = count.plus - n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (minus_sum >= count.minus && minus_sum <= count.minus * n) {\n\n\t\tdiff = minus_sum - count.minus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1; \n\n\t\trebus[0] = 1;\n\n\t\tcounter = 0;\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1\n\t\t\tif (counter == a) {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\tcounter += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n\n} else {\n\t//modify 'plus'\n\t// plus_sum is what the sum of all +? needs to be\n\tvar plus_sum = count.minus + n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (plus_sum >= count.plus && plus_sum <= count.plus * n) {\n\n\t\tdiff = plus_sum - count.plus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1;\n\n\t\tif (diff === 0) {\n\t\t\trebus[0] = 1;\n\t\t} else if (a === 0) {\n\t\t\trebus[0] = b;\n\t\t} else if (a >= 1) {\n\t\t\trebus[0] = n;\n\t\t\tcounter = 1;\n\t\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t\t// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1\n\t\t\t\tif (counter == a) {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\t\tcounter += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n}"}], "negative_code": [{"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else if (first_q > n && n > 1 && count.plus > 0) {\n\trebus[0] = n;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = first_q - n + 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else {\n\tprint('Impossible');\n}\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\n/* x is what we need to add in the rebus instead of a 1\nit must be less than n though.... so if it's bigger than n\nthen we need to divide it into a bunch of n's plus a remaineder\na is the number of n's\nb is the remainder */\nvar x = (first_q - n + 1);\n\nvar a = 1;\nvar b = 0;\n\n\n// to find 2 unknowns (a and b) we need a double loop..\nif (x < n) {\n\tb = x;\n} else {\n\tfor (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {\n\t\tfor (b = 0; b < n; b++) {\n\t\t\tif (a * n + b == x + a) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (a * n + b == x + a) {\n\t\t break;\n\t\t}\n\t}\n}\n\n\n// we just need to replace all ?'s with 1s\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && x < n && count.plus > 0) {\n\trebus[0] = n;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = x;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')\n} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tbreak;\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n} else {\n\tprint('Impossible');\n}\n\n\n/* checking stuff\nprint(JSON.stringify(count));\nprint(first_q);\n\nprint(n);\nprint(a);\nprint(b);\nprint(x);\n*/\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\n/* x is what we need to add in the rebus instead of a 1\nit must be less than n though.... so if it's bigger than n\nthen we need to divide it into a bunch of n's plus a remaineder\na is the number of n's\nb is the remainder */\nvar x = (count.minus - count.plus+ 1);\n\nvar a = 1;\nvar b = 0;\n\n\n// to find 2 unknowns (a and b) we need a double loop..\nif (x < n) {\n\tb = x;\n} else {\n\tfor (a = Math.floor(x / n); a <= x; a++) {\n\t\tfor (b = 0; b < n; b++) {\n\t\t\tif (a * n + b == x + a) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (a * n + b == x + a) {\n\t\t break;\n\t\t}\n\t}\n}\n\n\n// we just need to replace all ?'s with 1s\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && x < n && count.plus > 0) {\n\trebus[0] = n;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = x;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')\n} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tbreak;\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n} else {\n\tprint('Impossible');\n}\n\n\n/* checking stuff\nprint(JSON.stringify(count));\nprint(first_q);\n\nprint(n);\nprint(a);\nprint(b);\nprint(x);\n*/\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else {\n\tprint('Impossible');\n}"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 1, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\n// Do I need to modify the -? or the +?s\nvar diff = 0;\nvar a = 0; // a --> change a number of ?'s to n\nvar b = 1; // b --> change another -? to b\nvar counter = 0; // used to count how many ?'s are replaced with n (count a)\n\n// Modify 'minus' ?\nif (count.plus - count.minus > n) {\n\t// modify 'minus'\n\t// minus_sum is what the sum of all -? needs to be\n\tvar minus_sum = count.plus - n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (minus_sum >= count.minus && minus_sum <= count.minus * n) {\n\t\tprint('Possible');\n\n\t\tdiff = minus_sum - count.minus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1; \n\n\t\trebus[0] = 1;\n\n\t\tcounter = 0;\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1\n\t\t\tif (counter == a) {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\tcounter += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n\n} else {\n\t//modify 'plus'\n\t// plus_sum is what the sum of all +? needs to be\n\tvar plus_sum = count.minus + n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (plus_sum >= count.plus && plus_sum <= count.plus * n) {\n\n\t\tdiff = plus_sum - count.plus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1;\n\n\t\tif (a === 0) {\n\t\t\trebus[0] = b;\n\t\t} else if (a >= 1) {\n\t\t\trebus[0] = n;\n\t\t\tcounter = 1;\n\t\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t\t// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1\n\t\t\t\tif (counter == a) {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\t\tcounter += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n}"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\n// used for look_for parameter\nvar plus = '+'; \nvar minus = '-';\n\n// if possible get rebus with this function\nvar getRebus = function(increase, ones, look_for) {\n\tvar sum = 0;\n\tif (increase == count.plus) {\n\t\tsum = ones + n;\n\t} else {\n\t\tsum = ones - n;\n\t}\n\t\n\tvar diff = sum - increase;\n\tvar a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n\n\tvar b = diff % (n - 1) + 1; // b --> change another ? to b\n\tvar counter = 0; // used to count how many ?'s are replaced with n (count a)\n\n\t// if diff is 0, I want every ? to be 1\n\tif (diff === 0) {\n\t\trebus[0] = 1;\n\t// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)\n\t} else if (a === 0 && increase == count.plus) {\n\t\trebus[0] = b;\n\t} else if (a >= 1) {\n\t\t// ONLY when increasing +?'s\n\t\tif (increase == count.plus) {\n\t\t\trebus[0] = n;\n\t\t\tcounter = 1;\n\t\t// ONLY when increasing -?'s\n\t\t} else {\n\t\t\trebus[0] = 1;\n\t\t}\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1\n\t\t\tif (counter == a) {\n\t\t\t\tif (rebus[i] == look_for) {\n\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (rebus[i] == look_for) {\n\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\tcounter += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// replacing all other ?'s with 1's\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\n\trebus = rebus.join(' ');\n\n\treturn rebus;\n};\n\n// Increase 'minus' ?'s\nif (count.plus - count.minus > n) {\n\tvar sum = count.plus - n;\n\tif (sum >= count.minus && sum <= count.minus * n) {\n\t\tprint('Possible');\n\t\tprint(getRebus(count.minus, count.plus, minus));\n\t} else {\n\t\tprint('Impossible');\n\t}\n// Increase 'plus' ?'s\n} else {\n\tvar sum = count.minus + n;\n\tif (sum >= count.plus && sum <= count.plus * n) {\n\t\tprint('Possible');\n\t\tprint(getRebus(count.plus, count.minus, plus));\n\t} else {\n\t\tprint('Impossible');\n\t}\n}\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\n/* x is what we need to add in the rebus instead of a 1\nit must be less than n though.... so if it's bigger than n\nthen we need to divide it into a bunch of n's plus a remaineder\na is the number of n's\nb is the remainder */\nvar x = (first_q - n + 1);\n\nvar a = 1;\nvar b = 0;\n\n\n// to find 2 unknowns (a and b) we need a double loop..\nif (x < n) {\n\tb = x;\n} else {\n\tfor (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {\n\t\tfor (b = 0; b < n; b++) {\n\t\t\tif (a * n + b == x + a) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (a * n + b == x + a) {\n\t\t break;\n\t\t}\n\t}\n}\n\n\n// we just need to replace all ?'s with 1s\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && x < n && count.plus > 0) {\n\trebus[0] = n;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = x;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)\n} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')\n} else if (first_q > n && n > 1 && count.plus >= a){\n\trebus[0] = n;\n\tvar counter = 0;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\t// I only want to replace +? with +n a times, the next replacement should be +b\n\t\tif (counter == a) {\n\t\t\tbreak;\n\t\t} else {\n\t\t\tif (rebus[i] == '+') {\n\t\t\t\trebus[i + 1] = n;\n\t\t\t\tcounter += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n\n} else {\n\tprint('Impossible');\n}\n\n\n/* checking stuff\nprint(JSON.stringify(count));\nprint(first_q);\n\nprint(n);\nprint(a);\nprint(b);\nprint(x);\n*/\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 1, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\n// Do I need to modify the -? or the +?s\nvar diff = 0;\nvar a = 0; // a --> change a number of ?'s to n\nvar b = 1; // b --> change another -? to b\nvar counter = 0; // used to count how many ?'s are replaced with n (count a)\n\n// Modify 'minus' ?\nif (count.plus - count.minus > n) {\n\t// modify 'minus'\n\t// minus_sum is what the sum of all -? needs to be\n\tvar minus_sum = count.plus - n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (minus_sum >= count.minus && minus_sum <= count.minus * n) {\n\n\t\tdiff = minus_sum - count.minus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1; \n\n\t\trebus[0] = 1;\n\n\t\tcounter = 0;\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1\n\t\t\tif (counter == a) {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (rebus[i] == '-') {\n\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\tcounter += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n\n} else {\n\t//modify 'plus'\n\t// plus_sum is what the sum of all +? needs to be\n\tvar plus_sum = count.minus + n;\n\t// Checking to see if this sum falls between the number of -? and the number of -? * n\n\tif (plus_sum >= count.plus && plus_sum <= count.plus * n) {\n\n\t\tdiff = plus_sum - count.plus;\n\t\ta = Math.floor(diff / (n - 1)); \n\t\tb = diff % (n - 1) + 1;\n\n\t\tif (a === 0) {\n\t\t\trebus[0] = b;\n\t\t} else if (a >= 1) {\n\t\t\trebus[0] = n;\n\t\t\tcounter = 1;\n\t\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\t\t// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1\n\t\t\t\tif (counter == a) {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (rebus[i] == '+') {\n\t\t\t\t\t\trebus[i + 1] = n;\n\t\t\t\t\t\tcounter += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 1; i < rebus.length; i++) {\n\t\t\tif (rebus[i] == '?') {\n\t\t\t\trebus[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\trebus = rebus.join(' ');\n\n\t\tprint('Possible');\n\t\tprint(rebus);\n\n\t} else {\n\t\tprint('Impossible');\n\t}\n}"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else if (first_q - 1 == n && n > 1) {\n\trebus[0] = first_q - 1;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = 2;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else {\n\tprint('Impossible');\n}\n"}, {"source_code": "var rebus = readline().split(' ').map(String);\n\nvar count = {plus: 0, minus: 0}; // number of + and - in rebus\n\nfor (var i = 0; i < rebus.length; i++) {\n\tif (rebus[i] == '+') {\n\t\tcount.plus += 1;\n\t} else if (rebus[i] == '-') {\n\t\tcount.minus += 1;\n\t}\n\tif (rebus[i] == '=') {\n\t\tn = Number(rebus[i + 1]);\n\t}\n}\n\nvar first_q = n + count.minus - count.plus;\n\nif (first_q > 0 && first_q <= n) {\n\trebus[0] = first_q;\n\tfor (var i = 2; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else if (first_q > n && n > 1) {\n\trebus[0] = n;\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '+') {\n\t\t\trebus[i + 1] = first_q - n + 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (var i = 1; i < rebus.length; i++) {\n\t\tif (rebus[i] == '?') {\n\t\t\trebus[i] = 1;\n\t\t}\n\t}\n\trebus = rebus.join(' ');\n\n\tprint('Possible');\n\tprint(rebus);\n} else {\n\tprint('Impossible');\n}\n"}], "src_uid": "35a97c47182916aaafe4c6e4b69bc79f"} {"source_code": "var x = readline();\n\nvar a = \"pq\"+\"bd\"+\"AHIMOoTUVvWwXxY\";\nvar b = \"qp\"+\"db\"+\"AHIMOoTUVvWwXxY\";\n\nvar ok = true;\nfor (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)\n{\n var m = a.indexOf(x[i]), n = b.indexOf(x[j]);\n ok = ok && m>=0 && m==n;\n}\n\nprint(ok ? \"TAK\" : \"NIE\");\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst getInput = () => {\n const lineInput = readline();\n return lineInput;\n};\n\nconst isSPalindrom = (str) => {\n const symmetric = \"AHIMOoTUVvWwXxY\";\n\n\n if(str.length % 2){\n let char = str[Math.floor(str.length / 2)];\n if(!symmetric.includes(char))\n return \"NIE\";\n }\n \n for(let i = 0; i < Math.floor(str.length) / 2; i++){\n if(str[i] === \"p\" && str[str.length - i - 1] === \"q\")\n continue;\n if(str[i] === \"q\" && str[str.length - i - 1] === \"p\")\n continue;\n if(str[i] === \"b\" && str[str.length - i - 1] === \"d\")\n continue;\n if(str[i] === \"d\" && str[str.length - i - 1] === \"b\")\n continue;\n\n if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){\n if(str[i] === str[str.length - i - 1])\n continue;\n }\n\n return \"NIE\";\n }\n\n return \"TAK\";\n}\n\nfunction main() {\n const input = getInput();\n const result = isSPalindrom(input);\n console.log(result);\n}"}, {"source_code": "var left = \"bd\" + \"pq\" + \"AHIMOoTUVvWwXxY\";\nvar right = \"db\" + \"qp\" + \"AHIMOoTUVvWwXxY\";\n\nvar x = readline();\n\nvar ok = true;\n\nfor (var i = 0, j = x.length - 1; i < x.length / 2 && ok; i++, j--) {\n var leftPosition = left.indexOf(x[i]);\n var rightPosition = right.indexOf(x[j]);\n\n ok = leftPosition >= 0 && leftPosition == rightPosition;\n}\n\nprint(ok ? \"TAK\" : \"NIE\");"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface(process.stdin, process.stdout)\n\nconst input = []\n\nrl.on('line', line => input.push(line.toString()))\n\nrl.on('close', () => {\n solve()\n})\n\nconst solve = () => {\n const mirrorAlphabetPairs = [\n 'xx',\n 'XX',\n 'oo',\n 'OO',\n 'vv',\n 'VV',\n 'ww',\n 'WW',\n 'II',\n 'TT',\n 'HH',\n 'MM',\n 'YY',\n 'UU',\n 'AA',\n 'pq',\n 'qp',\n 'bd',\n 'db',\n ]\n\n const isSPalindrome = s => {\n for (let i = 0; i < s.length / 2; i++) {\n const j = s.length - 1 - i\n const pair = s[i] + s[j]\n\n if (!mirrorAlphabetPairs.includes(pair)) {\n return false\n }\n }\n\n return true\n }\n\n const [s] = input\n const output = isSPalindrome(s) ? 'TAK' : 'NIE'\n\n console.log(output)\n}\n"}], "negative_code": [{"source_code": "var x = readline();\n\nvar a = \"pq\"+\"bd\"+\"AHIMOoTUVvWwXxYy\";\nvar b = \"qp\"+\"db\"+\"AHIMOoTUVvWwXxYy\";\n\nvar ok = true;\nfor (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)\n{\n var m = a.indexOf(x[i]), n = b.indexOf(x[j]);\n ok = ok && (m>=0 && m == n);\n}\n\nprint(ok?\"TAK\":\"NIE\");\n"}, {"source_code": "var x = readline();\n\nvar a=\"pqbd\";\nvar b=\"qpdb\";\n\nvar ok = true;\nfor (var i=0, j=x.length-1 ; ok && i= 0 && leftPosition == rightPosition;\n}\n\nprint(ok ? \"TAK\" : \"NIE\");"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst getInput = () => {\n const lineInput = readline();\n return lineInput;\n};\n\nconst isSPalindrom = (str) => {\n const symmetric = \"AHIMOoTUVvWwXxY\";\n\n\n if( str.length % 2){\n let char = str[Math.floor(str.length) / 2];\n if(!symmetric.includes(char))\n return \"NIE\";\n }\n \n for(let i = 0; i < Math.floor(str.length) / 2; i++){\n if(str[i] === \"p\" && str[str.length - i - 1] === \"q\")\n continue;\n if(str[i] === \"q\" && str[str.length - i - 1] === \"p\")\n continue;\n if(str[i] === \"b\" && str[str.length - i - 1] === \"d\")\n continue;\n if(str[i] === \"d\" && str[str.length - i - 1] === \"b\")\n continue;\n\n if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){\n if(str[i] === str[str.length - i - 1])\n continue;\n }\n\n return \"NIE\";\n }\n\n return \"TAK\";\n}\n\nfunction main() {\n const input = getInput();\n const result = isSPalindrom(input);\n console.log(result);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst getInput = () => {\n const lineInput = readline();\n return lineInput;\n};\n\nconst isSPalindrom = (str) => {\n if( str.length % 2 !== 1)\n return \"NIE\";\n \n for(let i = 0; i < Math.floor(str.length) / 2; i++)\n if(str[i] !== str[str.length - i - 1])\n return \"NIE\";\n\n return \"TAK\";\n}\n\nfunction main() {\n const input = getInput();\n const result = isSPalindrom(input);\n console.log(result);\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\nconst INF = Math.pow(10, 12);\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst getInput = () => {\n const lineInput = readline();\n return lineInput;\n};\n\nconst isSPalindrom = (str) => {\n const symmetric = \"AHIMOoTUVvWwXxY\";\n\n\n if( str.length % 2 !== 1){\n let char = str[Math.floor(str.length) / 2];\n if(!symmetric.includes(char))\n return \"NIE\";\n }\n \n for(let i = 0; i < Math.floor(str.length) / 2; i++){\n if(str[i] === \"p\" && str[str.length - i - 1] === \"q\")\n continue;\n if(str[i] === \"q\" && str[str.length - i - 1] === \"p\")\n continue;\n if(str[i] === \"b\" && str[str.length - i - 1] === \"d\")\n continue;\n if(str[i] === \"d\" && str[str.length - i - 1] === \"b\")\n continue;\n\n if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){\n if(str[i] === str[str.length - i - 1])\n continue;\n }\n\n return \"NIE\";\n }\n\n return \"TAK\";\n}\n\nfunction main() {\n const input = getInput();\n const result = isSPalindrom(input);\n console.log(result);\n}"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface(process.stdin, process.stdout)\n\nconst input = []\n\nrl.on('line', line => input.push(line.toString()))\n\nrl.on('close', () => {\n solve()\n})\n\nconst solve = () => {\n const mirrorAlphabetPairs = [\n 'll',\n 'xx',\n 'XX',\n 'ii',\n 'II',\n 'oo',\n 'OO',\n 'vv',\n 'VV',\n 'ww',\n 'WW',\n 'TT',\n 'HH',\n 'MM',\n 'YY',\n 'UU',\n 'AA',\n 'pq',\n 'qp',\n 'bd',\n 'db',\n ]\n\n const isSPalindrome = s => {\n for (let i = 0; i < s.length / 2; i++) {\n const j = s.length - 1 - i\n const pair = s[i] + s[j]\n\n if (!mirrorAlphabetPairs.includes(pair)) {\n return false\n }\n }\n\n return true\n }\n\n const [s] = input\n const output = isSPalindrome(s) ? 'TAK' : 'NIE'\n\n console.log(output)\n}\n"}, {"source_code": "const readline = require('readline')\nconst rl = readline.createInterface(process.stdin, process.stdout)\n\nconst input = []\n\nrl.on('line', line => input.push(line.toString()))\n\nrl.on('close', () => {\n solve()\n})\n\nconst solve = () => {\n const mirrorAlphabetPairs = [\n 'xx',\n 'bd',\n 'db',\n 'ii',\n 'll',\n 'oo',\n 'vv',\n 'ww',\n 'pq',\n 'qp',\n 'XX',\n 'II',\n 'OO',\n 'VV',\n 'WW',\n 'TT',\n 'HH',\n 'MM',\n 'YY',\n 'UU',\n 'AA',\n ]\n\n const isSPalindrome = s => {\n const upperLimit = Math.floor(s.length / 2)\n\n for (let i = 0; i < upperLimit; i++) {\n const j = s.length - 1 - i\n const pair = s[i] + s[j]\n\n if (!mirrorAlphabetPairs.includes(pair)) {\n return false\n }\n }\n\n return true\n }\n\n const [s] = input\n const output = isSPalindrome(s) ? 'TAK' : 'NIE'\n\n console.log(output)\n}\n"}], "src_uid": "bec2349631158b7dbfedcaededf65cc2"} {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let result = 1\n let views = []\n const items = [...input.slice(1)]\n if (items.length > 2) {\n items.forEach((el, index) => {\n if (index !== items.length - 1) {\n const next = index + 1\n if (!views[index]) {\n if (el !== items[next]) {\n result++\n }\n }\n }\n views[index] = 'true'\n })\n } else if (items.length === 2) {\n if (items[0] === items[1])\n result = 1\n else\n result = 2\n }\n console.log(result)\n})", "positive_code": [{"source_code": "var n_imanes = readline()\nvar comparador = \"\";\nvar grupos = 0;\nfor (var i = 0; i < n_imanes; i++) {\n\tvar polo = readline();\n\tif (polo != comparador) {\n\t\tcomparador = polo;\n\t\tgrupos++;\n\t}\n}\nprint(grupos);"}, {"source_code": "var arr = [], count = 1, inputs, ch = ' ';\ninputs = readline();\n \nwhile (inputs !== 0) {\n \n arr = readline();\n if (arr[0] === ch) {\n count++;\n }\n ch = arr[1];\n inputs--;\n}\nprint(count);"}, {"source_code": "var inputs = readline();\n var groupCounter = 0;\n var previousMagnet = -1;\n for (var i = 0; i < inputs; i++) {\n var line = readline();\n if (line[0] !== previousMagnet) {\n groupCounter += 1;\n previousMagnet = line[0];\n }\n }\n \n print(groupCounter);"}, {"source_code": "var numLines = readline();\nvar lastLine = '';\nvar blocks = 0;\nfor(var i = 0; i < numLines; i++)\n{\n var currentLine = readline();\n if(currentLine !== lastLine) blocks++;\n lastLine = currentLine;\n}\n\nprint(blocks);"}, {"source_code": "var n = parseInt(readline());\nvar gr = 0;\nvar prev = null;\nfor (var i = 0; i < n; i++){\n var inp = readline();\n if (!prev || inp[0] == prev[1]){\n gr++;\n }\n prev = inp;\n}\nprint (gr);"}, {"source_code": "var main = function(arr)\n{\n var c = 1;\n for (var i = 1; i < arr.length; i++)\n {\n if (arr[i] !== arr[i - 1]) c++;\n }\n return c;\n}\n\n{\n var num = readline();\n var arr = [];\n for (var i = 1; i <= +num; i++)\n {\n var aElem = readline();\n arr.push(aElem);\n }\n if (arr.length === 0) print(0);\n else\n print(main(arr));\n}"}, {"source_code": "\nvar num=parseInt(readline());\n// print(num)\nvar arr=[];\n\nfor(var i=0;i 0){if(read[i][0] == read[i - 1][1]){calc+=1}}\n}\n\t\nprint(calc + 1);"}, {"source_code": "n = parseInt(readline()), r = 0\nv = \"\"\nwhile (n--) {\n\tu = readline()\n\tif (u != v)\n\t\tv = u, r++\n}\nprint(r)\n"}, {"source_code": "var n = parseInt(readline(), 10),\n magnet = [],\n group = 1;\n\nfor(var i=0; i parseInt(b))) {\n arr.push(readline());\n}\n\nfor (i of Array(Number(n - 1))\n .fill()\n .map((a, b) => parseInt(b))) {\n if (arr[i] != arr[i + 1]) {\n total++\n }\n}\n\nprint(total);\n"}, {"source_code": "var n = readline();\nvar x =\"\";\nvar y = 0;\nfor(var i = 0; i {\n if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;\n})\nprint(counter);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numOfMagnets, magnets = [], groups = 0;\n\nrl.on('line', n => {\n if (!numOfMagnets) { numOfMagnets = n; } else {\n magnets.push(n);\n if (magnets.length === +numOfMagnets) {\n for (let i = 0; i < magnets.length; i++) {\n if (magnets[i] !== magnets[i - 1]) groups += 1;\n }\n console.log(groups);\n rl.close();\n }\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readline());\n let current = '';\n let numOfGroups = 0;\n for (let i = 0 ; i < n ;i++){\n let line = readline();\n if (current != line) numOfGroups ++;\n current =line;\n }\nconsole.log(numOfGroups);\n}\n\n"}, {"source_code": "function main() {\n // write code here:\n var n=Number(stdin[0]);\n var count=0;\n for(let i=1;i<=n;i++){\n if(stdin[i]!==stdin[i+1]){\n count++;\n }\n }\n console.log(count);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfMagnets = 0;\nlet groupCounter = 0;\nlet counter = 0;\nlet temp;\nrl.on(\"line\", (input) => {\n if (!numberOfMagnets) {\n numberOfMagnets = parseInt(input.split(\" \"));\n } else if (numberOfMagnets) {\n counter++\n\n if (!temp) {\n temp = input.split(\" \").toString()\n groupCounter++\n }\n if (temp) {\n if (input.split(\" \").toString() != temp) {\n temp = input.split(\" \").toString();\n groupCounter++\n }\n if (counter === numberOfMagnets) {\n rl.close();\n console.log(groupCounter)\n }\n }\n\n }\n\n});\n\n\n// if (temp === plusMinus) {\n// groupCounter++\n// flag = true\n// }\n// if (temp === minusPlus) {\n// groupCounter++\n// flag = false;\n// }"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const x = readline();\n const arr = [];\n \n for(let n=0;n {\n counter++;\n if (counter === 0) {\n magnetNo = parseInt(input);\n return;\n }\n if (counter === 1) {\n lastChar = input[1];\n } else {\n let currentChar = input[0];\n groups = (currentChar === lastChar) ? groups + 1 : groups;\n lastChar = input[1];\n }\n\n if (counter === magnetNo) {\n rl.close();\n console.log(groups);\n }\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet magnetNo;\nlet counter = -1;\nlet inputs = [];\n\nrl.on('line', (input) => {\n counter++;\n if (counter === 0) {\n magnetNo = parseInt(input);\n return;\n }\n\n inputs.push(input);\n if (counter === magnetNo) {\n rl.close();\n console.log(solve(inputs));\n }\n\n});\n\n\nconst solve = (inputs) => {\n let groups = 1;\n\n for (let i = 0; i < inputs.length - 1; i++) {\n let mag1 = inputs[i];\n let mag2 = inputs[i + 1];\n if (mag1[1] === mag2[0]) groups++;\n }\n return groups;\n};"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet isFirstLine = true;\nlet noOfGroups = 0;\nlet prevLineCode = null;\n\nrl.on(\"line\", function (line) {\n if (!isFirstLine) {\n const lineCode = line == \"10\" ? 1 : 0;\n if (lineCode !== prevLineCode) {\n noOfGroups++;\n prevLineCode = lineCode;\n }\n } else {\n isFirstLine = false;\n }\n});\n\nrl.on(\"close\", function () {\n console.log(noOfGroups);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = readline();\n let result = 1;\n let prev = readline();\n for (let i = 1; i < n; i++) {\n const cur = readline();\n if (cur !== prev) {\n result++;\n prev = cur;\n }\n }\n // output\n print(result);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet prev = -1;\nlet ans = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (prev !== d) {\n prev = d;\n ans++;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n\nfunction main() {\n const inputs = readline();\n let array=[];\n let groups =0;\n for (let i=0 ;i< inputs;i++){\n array[i] = readline();\n }\n\n for (let i=0 ;i< array.length;i++){\n if(array[i]!== array[i+1]){\n groups++\n }\n }\n \n\n console.log(groups);\n\n return;\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let answer = 0, last = null;\n input.forEach((line, i) => {\n if (i === 0) return;\n\n if (last === null) {\n answer += 1;\n }\n\n if (last === '0' && line[0] === '0') answer += 1;\n if (last === '1' && line[0] === '1') answer += 1;\n last = line[1];\n });\n\n console.log(answer);\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input.shift());\n const magnites = input;\n\n let islands = 1;\n for (let i = 1; i < magnites.length; i++) {\n if(magnites[i] === magnites[i - 1]) continue;\n else islands++;\n }\n\n console.log(islands);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n // if(Array.isArray(inputString)) inputString = inputString.join('\\n');\n inputString += inputStdin;\n // inputString = inputString.trim().split('\\n').map(string => {\n // return string.trim();\n // });\n \n // main(); \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let n = readAsInt();\n let lastpole = null;\n let total = 0;\n for(let i = 1; i <= n; i++ ){\n let pole = readAsInt() === 10;\n total += i > 1 ? (pole === lastpole ? 0 : 1) : 1;\n lastpole = pole;\n }\n console.log(total);\n}\n \n\n\n"}, {"source_code": "/**\n * @author Sunwarul\n * Software Developer \n*/ \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => {\n return str.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\tconst n = +(readLine());\n\tlet sum = 1;\n\tconst magnets = [];\n\tfor(let i = 0; i < n ; i++) {\n\t\tmagnets[i] = readLine();\n\t}\n\n\tfor(let i = 0; i < n - 1; i++) {\n\t\tif(magnets[i] !== magnets[i+1]) {\n\t\t\t++sum;\n\t\t}\n\t}\n\n\tconsole.log(sum);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction isLowerCase(str) {\n return str == str.toLowerCase() && str != str.toUpperCase();\n}\n\nfunction main() {\n var n = +readLine();\n var arr = [];\n for (var j = 0; j < n; j++) {\n var m = +readLine();\n arr.push(m);\n }\n\n var count = 1;\n\n for (var i = 0; i < n - 1; i++) {\n if (arr[i] != arr[i + 1]) {\n count++;\n }\n }\n console.log(count);\n}\n\n// Determine the number of groups that the magnets formed.\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\nfor (let i = 0; i < txt.length; i ++) {\n if(!isNaN(txt[i]*1)){\n let tab=[];\n for (let i1 = i+1; i1 < i+1+txt[i]*1; i1++) {\n tab.push(txt[i1]);\n \n }\n doit(tab);\n i+=txt[i]*1;\n }\n}\n\nfunction doit(tab) {\n let groups=1;\n tab.forEach((data,index)=>{\n if(tab[index+1]){\n if(data[1]==tab[index+1][0])++groups;\n }\n });\n console.log(groups);\n \n \n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().split('\\n');\n let magnetArr = inputs.slice(1);\n let count = 1;\n let groups = parseInt(magnetArr[0].trim(), 2);\n\n for (let i = 1; i < magnetArr.length; i++) {\n let group = parseInt(magnetArr[i].trim(), 2);\n if (group !== groups) {\n\n groups = parseInt(magnetArr[i].trim(), 2);\n count++;\n }\n }\n return count.toString();\n}\n"}, {"source_code": "var readline = require(\"readline\")\nvar rl = readline.createInterface(process.stdin,process.stdout);\nvar n;\nvar l=0;\nvar magnets = [];\nvar groups = 1;\nrl.question('',function(data){\n n = parseInt(data); \n //rl.prompt()\n rl.on(\"line\",function(mag){\n magnets.push(mag.toString().trim())\n l++;\n if(l == n){\n rl.close();\n }\n });\n})\nrl.on('close',function(){\n for (let i = 0; i < n-1; i++) {\n //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));\n if (magnets[i].charAt(1)==magnets[i+1].charAt(0)){\n groups++;\n }\n }\n if(groups > 0){\n console.log(groups);\n } else {\n console.log(groups+1); \n }\n})"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n});\nlet counter = 0;\nlet isFirstLine = true;\nlet previousMagnet = null;\nrl.on(\"line\", function (magnet) {\n if (isFirstLine) {\n isFirstLine = false;\n return;\n }\n if (magnet !== previousMagnet) {\n counter++;\n previousMagnet = magnet;\n }\n});\n\nrl.on(\"close\", function () {\n console.log(counter);\n});"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst magnets = () => {\n let ar = [];\n let count = 0;\n let q = +input.shift();\n for (const x of input) {\n for (const y of x) {\n ar.push(+y);\n }\n };\n\n for (let i = 1; i < ar.length; i++) {\n if (ar[i] === ar[i-1]) {\n count++;\n }\n }\n console.log(count+1);\n\n};\n\nreadLine.on('close', magnets);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let a = readLine();\n let ans = 1;\n for (var i = 0; i < n - 1; i++) {\n let b = readLine();\n if (a != b) {\n ans++;\n a = b;\n }\n }\n console.log(ans);\n}"}, {"source_code": "\nvar n=+readline();\nvar ans=0;\nvar prev='';\nwhile(n--){\n\tvar now = readline();\n\tif(now!=prev){\n\t\tprev=now;\n\t\tans++;\n\t}\n}\nprint(ans);"}, {"source_code": "var n = +readline(), m = [], counter = 0;\nfor(i = 0; i < n; i++){\n\tm.push(readline());\n}\n\nfor(i = 0; i < n-1; i++){\n\tif(m[i][1] != m[i+1][0]){\n\t\tcontinue;\n\t}\n\telse{\n\t\tcounter++;\n\t}\n}\nwrite(counter+1);"}, {"source_code": "var x= parseInt(readline())-1;\n\nvar now = readline();\nvar grps=0;\n\nvar prev;\n\nwhile(x--){\n var prev= now;\n var now=readline();\n if(now[0] === prev[1]){\n grps++;\n }\n}\n\nprint(++grps);"}, {"source_code": "var n = +readline();\nvar res = + (n > 0);\nvar last = 'x';\n\nwhile (n) {\n var str = readline();\n if (str[0] === last) res++;\n last = str[1];\n n --;\n}\n\nprint(res);"}, {"source_code": "var m = 1;\nvar input=[];\nvar n = parseInt(readline());\ninput[0] = readline();\nfor(var i=1 ; i0){\n var ins = readline();\n if(!prev || prev != ins){\n count++;\n prev = ins;\n }\n input--;\n}\nprint(count);"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tvar t = readline();\n\tvar r;\n\tvar x = 1;\n\n\tfor (var i = 1; i < n; i++) {\n\t\tr = readline();\n\t\tif (t[1] == r[0]){\n\t\t\tx++;\n\t\t\tt = r;\n\t\t}\n\t}\n\n\tprint(x);\n}).call(this);"}, {"source_code": "var size = readline(),\n\tcounter = 0,\n\thasChanged = false,\n\tlastMagnet = undefined;\n\nfor(var index = 0; index < size; index ++){\n\tvar currentMagnet = readline();\n\tif( lastMagnet !== currentMagnet ){\n\t\t//has to be change\n\t\tcounter ++;\n\t\tlastMagnet = currentMagnet;\n\t}\n}\n\nprint(counter);"}, {"source_code": "var res = sol(readline());\nprint(res);\n\nfunction sol(line) {\n\n var input = line.split(\" \");\n\n var n = input[0];\n\n var prev = \"\";\n var group = 0;\n\n while(n > 0){\n var magnet = readline();\n\n if(prev != magnet){\n prev = magnet;\n group++;\n }\n\n n--;\n }\n\n return group;\n}"}, {"source_code": "var n = Number(readline());\nvar count = 0;\nvar prevStr = '';\nfor(var i = 0; i < n; i++) {\n var str = readline();\n if (str !== prevStr) {\n count++;\n }\n prevStr = str;\n}\nprint(count);"}, {"source_code": "var toInt = x => parseInt(x);\nvar toInput = () => readline();\nvar result = 1;\nvar toGroups = (a, b) => {\n result+= (a!==b);\n return b;\n};\nnew Array(parseInt(readline())).fill('')\n .map(toInput).reduce(toGroups);\n \nprint(result);\n"}, {"source_code": "'use strict';\nlet n = parseInt(readline()),\n array = new Array(n); \n\nfor (let i = 0; i < n; i++) {\n array[i] = readline();\n}\n\nwrite(array.join('').split('00').join(' ').split('11').join(' ').split(' ').length);"}, {"source_code": "n = readline();\nvar ans = 0,\n u = \"\";\nfor (var i = 0; i < n; i++) {\n x = readline();\n if (x != u) {\n u = x;\n ans++;\n }\n}\nprint(ans)"}, {"source_code": "var n = readline(),\n p = readline(),\n count = 1;\nfor (var i = 1; i < n; i++) {\n var k = readline();\n if (k != p) count++;\n p = k;\n}\nprint(count);"}, {"source_code": "var n = readline();\nvar temp = 0;\nvar res = 0;\n\tfor (var i=0; i<+n; i++){\n\t\tvar str = readline();\n\t\tif (str!=temp) res++;\n\t\ttemp = str;\n\t}\t\n\tprint(res);\n"}, {"source_code": "var limit = parseInt(readline())\nvar previous = readline()\nlimit--\nvar count = 1\nwhile(limit > 0){\n var current = readline()\n if(current != previous){\n count++\n }\n \n previous = current \n limit--\n}\n\nprint(count)"}, {"source_code": "var line = readline();\nvar input = [];\nvar result = 0;\nfor(var i = 0; i < line; i++) {\n input[i] = readline(); \n}\n\nfor(var i = 1; i < input.length; i++) {\n if(input[i] != input[i-1]){\n result ++;\n }\n}\nprint(result + 1);"}, {"source_code": "var n = readline()\nvar q = \"\", z = 0\nfor (var i = 0; i < n; i++) {\n\tvar s = readline()\n\tif (s != q) {\n\t\tq = s\n\t\tz++\n\t}\n}\nprint(z)"}, {"source_code": "var n = Number(readline());\n\nvar magn = [];\nvar islands = 0, k = 0;\nfor (var i=0; i< n; i++) {\n var s = readline();\n magn.push(s);\n}\n\nfor (var j = 0; j < magn.length; j++) {\n if (magn[j] === magn[j+1]) {\n k++;\n continue;\n }\n else {\n islands++;\n k = 0;\n }\n}\nprint(islands)\n"}, {"source_code": "var n_imanes = readline();\nvar comparador = \"\";\nvar grupos = 0;\nfor (var i = 0; i < n_imanes; i++) {\n\tvar polo = readline();\n\tif (polo != comparador) {\n\t\tcomparador = polo;\n\t\tgrupos++;\n\t}\n}\nprint(grupos);"}, {"source_code": "var n_imanes = readline()\nvar comparador = \"\";\nvar grupos = 0;\nfor (var i = 0; i < n_imanes; i++) {\n\tvar polo = readline();\n\tif (polo != comparador) {\n\t\tcomparador = polo;\n\t\tgrupos++;\n\t}\n} \nprint(grupos);"}, {"source_code": "var n_imanes = readline()\nvar comparador = \"\";\nvar grupos = 0;\nfor (var i = 0; i < n_imanes; i++) {\n\tvar polo = readline();\n\tif (polo != comparador) {\n\t\tcomparador = polo;\n\t\tgrupos++;\n\t}\n}\nprint(grupos); "}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readline());\n let current = '';\n let numOfGroups = 0;\n for (let i = 0 ; i < n ;i++){\n let line = readline();\n if (current === line) numOfGroups ++;\n current =line;\n }\nconsole.log(numOfGroups);\n}\n\n"}, {"source_code": "function main() {\n // write code here:\n var n=Number(stdin[0]);\n var count=0;\n for(let i=1;i<=n;i++){\n if(stdin[i]===stdin[i+1]){\n count++;\n }\n }\n console.log(count);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let result = 0\n let views = []\n const items = [...input.slice(1)]\n if (items.length > 2) {\n items.forEach((el, index) => {\n if (index > 0) {\n const prev = index - 1\n const next = index + 1\n if (!views[index]) {\n if (el !== items[prev]) {\n views[prev] = 'true'\n result++\n } else if (el !== items[next]) {\n views[next] = 'true'\n result++\n }\n }\n }\n views[index] = 'true'\n })\n } else if (items.length === 2) {\n result = 2\n } else {\n result = 1\n }\n console.log(result)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nlet input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n let result = 0\n let views = []\n const items = [...input.slice(1)]\n if (items.length > 2) {\n items.forEach((el, index) => {\n if (index > 0) {\n const prev = index - 1\n const next = index + 1\n if (!views[index]) {\n if (el !== items[prev]) {\n views[prev] = 'true'\n result++\n }\n if (el !== items[next]) {\n views[next] = 'true'\n result++\n }\n }\n }\n views[index] = 'true'\n })\n } else if (items.length === 2) {\n if (items[0] === items[1])\n result = 1\n else\n result = 2\n } else {\n result = 1\n }\n console.log(result)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let result = 0\n let views = []\n const items = [...input.slice(1)]\n if (items.length > 2) {\n items.forEach((el, index) => {\n if (index > 0) {\n const prev = index - 1\n const next = index + 1\n if (!views[index]) {\n if (el !== items[prev]) {\n views[prev] = 'true'\n result++\n } else if (el !== items[next]) {\n views[next] = 'true'\n result++\n }\n }\n }\n views[index] = 'true'\n })\n } else if (items.length === 2) {\n if (items[0] === items[1])\n result = 1\n else\n result = 2\n } else {\n result = 1\n }\n console.log(result)\n})"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let result = 0\n let views = []\n const items = [...input.slice(1)]\n if (items.length > 1) {\n items.forEach((el, index) => {\n if (index > 0) {\n const prev = index - 1\n const next = index + 1\n if (!views[index]) {\n if (el !== items[prev]) {\n views[prev] = 'true'\n result++\n } else if (el !== items[next]) {\n views[next] = 'true'\n result++\n }\n }\n }\n views[index] = 'true'\n })\n } else {\n result = 1\n }\n console.log(result)\n})"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfMagnets = 0;\nlet plusMinus = \"01\";\nlet minusPlus = \"10\";\nlet groupCounter = 0;\nlet flag = false;\nlet counter = 0;\nrl.on(\"line\", (input) => {\n if (!numberOfMagnets) {\n numberOfMagnets = parseInt(input.split(\" \"));\n\n //console.log(typeof(numberOfMagnets),numberOfMagnets) \n }\n if (numberOfMagnets) {\n counter++;\n let temp = input.split(\" \").toString();\n if (temp === plusMinus && flag === false) {\n groupCounter++\n flag = true\n }\n if (temp === minusPlus && flag === true) {\n groupCounter++\n flag = false;\n }\n\n if (counter > numberOfMagnets) {\n rl.close();\n console.log(groupCounter)\n }\n }\n\n\n\n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfMagnets = 0;\nlet plusMinus = \"01\";\nlet minusPlus = \"10\";\nlet groupCounter = 0;\nlet flag = true;\nlet counter = 0;\nrl.on(\"line\", (input) => {\n if (!numberOfMagnets) {\n numberOfMagnets = parseInt(input.split(\" \"));\n //console.log(typeof(numberOfMagnets),numberOfMagnets) \n } else if (numberOfMagnets) {\n counter++;\n let temp = input.split(\" \").toString();\n switch (temp) {\n case minusPlus:\n if(flag === true)\n groupCounter++ , flag= false;\n break;\n case plusMinus :\n if(flag === false)\n groupCounter++ , flag= true;\n\n break;\n default:\n break;\n }\n \n if (counter === numberOfMagnets) {\n console.log(counter, \"\\n\")\n rl.close();\n console.log(groupCounter)\n }\n }\n\n\n\n}); \n\n\n// if (temp === plusMinus) {\n // groupCounter++\n // flag = true\n // }\n // if (temp === minusPlus) {\n // groupCounter++\n // flag = false;\n // }\n"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfMagnets = 0;\nlet plusMinus = \"01\";\nlet minusPlus = \"10\";\nlet groupCounter = 0;\nlet flag = false;\nlet counter = 0;\nrl.on(\"line\", (input) => {\n if (!numberOfMagnets) {\n numberOfMagnets = parseInt(input.split(\" \"));\n rl.pause();\n //console.log(typeof(numberOfMagnets),numberOfMagnets) \n }\n if (numberOfMagnets) {\n rl.resume();\n counter++;\n let temp = input.split(\" \").toString();\n if (temp === plusMinus && flag === false) {\n groupCounter++\n flag = true\n }\n if (temp === minusPlus && flag === true) {\n groupCounter++\n flag = false;\n }\n\n if (counter > numberOfMagnets) {\n rl.close();\n console.log(groupCounter)\n }\n }\n\n\n\n});"}, {"source_code": "const readline = require(\"readline\")\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet numberOfMagnets = 0;\nlet plusMinus = \"01\";\nlet minusPlus = \"10\";\nlet groupCounter = 0;\nlet flag = true;\nlet counter = 0;\nrl.on(\"line\", (input) => {\n if (!numberOfMagnets) {\n numberOfMagnets = parseInt(input.split(\" \"));\n //console.log(typeof(numberOfMagnets),numberOfMagnets) \n } else if (numberOfMagnets) {\n counter++;\n let temp = input.split(\" \").toString();\n switch (temp) {\n case minusPlus:\n if(flag === true)\n groupCounter++ , flag= false;\n break;\n case plusMinus :\n if(flag === false)\n groupCounter++ , flag= true;\n\n break;\n default:\n break;\n }\n \n if (counter === numberOfMagnets) {\n //console.log(counter, \"\\n\")\n rl.close();\n console.log(groupCounter)\n }\n }\n\n\n\n}); \n\n\n// if (temp === plusMinus) {\n // groupCounter++\n // flag = true\n // }\n // if (temp === minusPlus) {\n // groupCounter++\n // flag = false;\n // }\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet magnetNo;\nlet counter = 0;\nlet lastChar = '';\nlet groups = 1;\n\nrl.on('line', (input) => {\n if (counter === 0) {\n magnetNo = parseInt(input);\n counter++;\n return;\n }\n if (counter === magnetNo) {\n rl.close();\n console.log(groups);\n return;\n }\n counter++;\n let currentChar = input[0];\n groups = (lastChar === '' || lastChar !== currentChar) ? groups : groups + 1;\n lastChar = input[1];\n\n});\n\n\nconst solve = () => {\n\n};"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction isLowerCase(str) {\n return str == str.toLowerCase() && str != str.toUpperCase();\n}\n\nfunction main() {\n var n = +readLine();\n var arr = [];\n for (var i = 0; i < n; i++) {\n var m = +readLine();\n arr.push(m);\n }\n\n var newArr = [];\n var count = 0;\n\n for (var j = 0; j < n; j++) {\n if (arr[j] == arr[j + 1]) {\n count++;\n } else {\n newArr.push(count);\n count = 0;\n }\n }\n\n var max = Math.max(...newArr) + 1;\n console.log(max);\n}\n\n// either it only contains uppercase letters;\n// or all letters except for the first one are uppercase.\n"}, {"source_code": "var readline = require(\"readline\")\nvar rl = readline.createInterface(process.stdin,process.stdout);\nvar n;\nvar l=0;\nvar magnets = [];\nvar groups = 0;\nrl.question('',function(data){\n n = parseInt(data); \n //rl.prompt()\n rl.on(\"line\",function(mag){\n magnets.push(mag.toString().trim())\n l++;\n if(l == n){\n rl.close();\n }\n });\n})\nrl.on('close',function(){\n for (let i = 0; i < n-1; i++) {\n //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));\n if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){\n groups++;\n }\n }\n if(groups > 0){\n console.log(groups);\n } else {\n console.log(groups+1); \n }\n})"}, {"source_code": "var readline = require(\"readline\")\nvar rl = readline.createInterface(process.stdin,process.stdout);\nvar n;\nvar l=0;\nvar magnets = [];\nvar groups = 0;\nrl.question('',function(data){\n n = parseInt(data); \n //rl.prompt()\n rl.on(\"line\",function(mag){\n magnets.push(mag.toString().trim())\n l++;\n if(l == n){\n rl.close();\n }\n });\n})\nrl.on('close',function(){\n for (let i = 0; i < n-1; i++) {\n //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));\n if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){\n groups++;\n }\n }\n console.log(groups);\n})\n"}, {"source_code": "var readline = require(\"readline\")\nvar rl = readline.createInterface(process.stdin,process.stdout);\nvar n;\nvar l=0;\nvar magnets = [];\nvar groups = 0;\nrl.question('',function(data){\n n = parseInt(data); \n rl.prompt()\n rl.on(\"line\",function(mag){\n magnets.push(mag.toString().trim())\n l++;\n if(l == n){\n rl.close();\n }\n });\n})\nrl.on('close',function(){\n for (let i = 0; i < n-1; i++) {\n //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));\n if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){\n groups++;\n }\n }\n console.log(groups);\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let a = readLine();\n let ans = 1;\n for (var i = 0; i < n; i++) {\n let b = readLine();\n if (a != b) {\n b = a;\n ans++;\n }\n }\n console.log(ans);\n}"}, {"source_code": "var n = +readline();\nvar res = 0;\nvar last = 'x';\n\nwhile (n) {\n var str = readline();\n if (str[0] === last) res++;\n last = str[1];\n n --;\n}"}, {"source_code": "var n = +readline();\nvar res = 0;\nvar last = 'x';\n\nwhile (n) {\n var str = readline();\n if (str[0] === last) res++;\n last = str[1];\n n --;\n}\n\nprint(res);"}, {"source_code": "var m = 0;\nvar x=\"\";\nvar y;\nvar n = parseInt(readline());\n\nfor(var i=0 ; i {\n const n = readline();\n const arr = [];\n var total = 1;\n\n for (i of Array(Number(n))\n .fill()\n .map((a, b) => parseInt(b))) {\n arr.push(readline());\n }\n\n for (i of Array(Number(n - 1))\n .fill()\n .map((a, b) => parseInt(b))) {\n if (arr[i] != arr[i + 1]) {\n total++\n }\n }\n\n print(total);\n};"}, {"source_code": "var r = readline();\nvar s=0;\nvar x1 =readline();\nfor(var i = 0; i< r-1;i++){\n var x2 = readline();\n if (x1[1] == x2[0]){\n s++;\n }\n x1=x2;\n}\nprint(s);"}, {"source_code": "var r = readline();\nvar s=0;\nvar x1 =readline();\nfor(var i = 0; i< r-1;i++){\n var x2 = readline();\n if (x1[1] == x2[0]){\n s++;\n }\n}\nprint(s);"}, {"source_code": "var r = readline();\nvar s=0;\nvar x1 =readline();\nfor(var i = 0; i< r-1;i++){\n var x2 = readline();\n if (x1[1] == x2[0]) {\n s++; \n }\n}\nprint(s);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 0;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n print(typeof magnets[0])\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === arr[index+1]) counter++;\n})\nprint(counter);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 1;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;\n})\nprint(counter);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 0;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === arr[index+1]) counter++;\n})\nprint(counter);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 0;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;\n})\nprint(counter);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 0;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n print(magnets)\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === arr[index+1]) counter++;\n})\nprint(counter);"}, {"source_code": "var n = readline();\nvar magnets = [], counter = 0;\nfor(var i = 0; i < n; i++){\n var magnet = readline();\n magnets.push(magnet);\n}\nmagnets.forEach((item, index, arr) => {\n if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;\n})\nprint(counter);"}, {"source_code": "var count = readline();\nvar read = new Array(count-1);var calc=0;\n\nfor(var x = 0;x 0){if(read[i][0] == read[i - 1][1]){calc+=1}}\n}\n\t\nif(calc != 0){calc += 1};print(calc);"}, {"source_code": "var count = readline();\nvar read = new Array(count-1);var calc=0;\n\nfor(var x = 0;x 0){if(read[i][1] == read[i - 1][1]){calc+=1}}\n}\n\t\nprint(calc);"}, {"source_code": "var nums = parseInt(readline());\n\nvar prev = null; \nvar block = 0; //block not gap\nfor (var i = 0; i < nums.length; i++) {\n var current = parseInt(readline());\n \n if (current !== prev) {\n block++;\n }\n \n prev = current;\n}\n\nprint(block);"}], "src_uid": "6c52df7ea24671102e4c0eee19dc6bba"} {"source_code": "var getVals = function () { return readline().split(' '); };\n\nvar getNums = function () {\n return readline().split(' ').map(function (a) { return parseInt(a) });\n};\n\n\n//131b\nvar n = parseInt(readline());\nvar data = getNums();\nvar hash = {};\nvar res = 0;\n\nfor(var i = 1; i <= 10; i++) {\n hash[i] = 0;\n hash[\"-\" + i] = 0;\n}\nhash[0] = 0;\n\nfor(var i = 0; i < n; i++) {\n hash[data[i]]++;\n}\n\nfor(var i = 1; i <= 10; i++) {\n res += hash[i] * hash[-i];\n}\n\n\n\nif (hash[0] > 1) {\n for(var i = 1; i < hash[0]; i++) {\n res += i;\n }\n}\n\nprint(res);", "positive_code": [{"source_code": "var ans = 0,\n a = [],\n n = +readline(),\n t = readline().split(' ').map(Number);\n\nfor(var i = 0; i < 21; i++){\n a[i] = 0;\n}\nfor(var i = 0; i < n; i++){\n a[t[i] + 10]++;\n}\n\nfor(var i = 0; i < 10; i++){\n ans += a[i] * a[20 - i];\n}\nans += (a[10] - 1) * a[10] / 2;\n\nprint(ans);"}, {"source_code": ";(function () {\n\n\treadline();\n\n\tprint((function () {\n\t\tvar ret = 0, m = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\t\treadline().split(' ').map(function (e, i) {\tm[Number(e) + 10]++; });\n\t\treturn (function () {\n\t\t\tfor (var i = 0, ret = 0; i < 10; i++) ret += m[i] * m[20 - i]; return ret;\n\t\t})() + (function () {\n\t\t\treturn m[10] * (m[10] - 1) / 2;\n\t\t})();\n\t}).apply(0));\n\n}).call(this);"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint((function (n) {\n\t\tvar ret = 0, m = {};\n\t\treadline().split(' ').map(function (e, i) {\n\t\t\te = Number(e);\n\t\t\tm[e] = m[e] ? m[e] + 1 : 1;\n\t\t});\n\n\t\tfor (var key in m) {\n\t\t\tif (key < 0) {\n\t\t\t\tif (!m[-key]) break;\n\t\t\t\tret += m[key] * m[-key];\n\t\t\t} else if (key == 0 && m[key] > 1) {\n\t\t\t\tret += m[key] * (m[key] - 1) / 2;\n\t\t\t}\n\t\t}\n\n\t\treturn ret;\n\t}).apply(0, [+readline()]));\n\n}).call(this);"}], "src_uid": "f3dde329830d8c479b3dab9d5df8baf5"} {"source_code": "const solve = arr=>{\r\n arr.reverse();\r\n let x = 1;\r\n let ans = 0;\r\n while(xparseInt(cur)),0]\r\n solve(arr);\r\n }\r\n}\r\nmain();", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var g = readline();\r\n var a = readline().split(\" \").map(w => parseInt(w))\r\n var n = a.length-1;\r\n var ref = a[n]\r\n var ans = 0;\r\n for(var i=n-1;i>=0;i--) {\r\n \tif(a[i]==ref) continue;\r\n \tvar j = i;\r\n \tvar len = n-i;\r\n \tvar lim = Math.max(0, (i-len)+1);\r\n \tvar cnt = 0;\r\n \twhile(j >= lim) {\r\n \t\tif(a[j] !== ref) {\r\n \t\t\tcnt++;\r\n \t\t}\r\n \t\tj--\r\n \t}\r\n \tif(cnt > 0) {\r\n \t\tans++;\r\n \t} \r\n \ti=j+1;\r\n }\r\n console.log(ans)\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));\r\n \r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++]);\r\n let arr = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n arr.reverse();\r\n let x = 0;\r\n let count = 0;\r\n while (x < n) {\r\n if (arr[x] === arr[0]) {\r\n x++;\r\n } else {\r\n x *= 2;\r\n count++;\r\n }\r\n }\r\n console.log(count);\r\n }\r\n});\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));\r\n \r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = readline().split(' ');\r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = parseInt(readline());\r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = parseInt(readline());\r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = parseInt(readline());\r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n//-----------main fucntion-----------\r\n\r\nfunction main() {\r\n let input = parseInt(readline());\r\n while(input--){\r\n let n = parseInt(readline()), m = parseInt(readline());\r\n function zombiesF(arr){\r\n let zombies = arr[arr.length-1],zc =1, steps = 0; \r\n \r\n while(zc{\r\n let cnt = 0;\r\n const binaryserach = (start,end)=>{\r\n if(end-start===1) return arr[start];\r\n let mid = Math.floor((start+end)/2);\r\n let check = binaryserach(mid,end);\r\n for(let i=start;iparseInt(cur))]\r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = arr=>{\r\n let cnt = 0;\r\n const binaryserach = (start,end)=>{\r\n if(end-start===1) return arr[start];\r\n let mid = Math.floor((start+end)/2);\r\n let check = binaryserach(mid,end);\r\n for(let i=start;i<=mid;i++){\r\n if(arr[i]!==check){\r\n cnt++;\r\n break;\r\n }\r\n }\r\n return check;\r\n }\r\n binaryserach(0,arr.length);\r\n console.log(cnt);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur)); \r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = arr=>{\r\n let cnt = 0;\r\n const binaryserach = (start,end)=>{\r\n if(end===start) return arr[end];\r\n let mid = Math.floor((start+end)/2);\r\n let check = binaryserach(mid+1,end);\r\n for(let i=start;i<=mid;i++){\r\n if(arr[i]!==check){\r\n cnt++;\r\n break;\r\n }\r\n }\r\n return check;\r\n }\r\n binaryserach(0,arr.length-1);\r\n console.log(cnt);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur)); \r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = arr=>{\r\n let cnt = 0;\r\n const binaryserach = (start,end)=>{\r\n if(end-start===1) return arr[start];\r\n let mid = Math.floor((start+end)/2);\r\n let check = binaryserach(mid,end);\r\n for(let i=start;iparseInt(cur)); \r\n solve(arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++]);\r\n let arr = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n let max = 0;\r\n let l, k;\r\n for (let j = 0; j < n; j++) {\r\n let stretch = 0;\r\n for (let p = j; p < n; p++) {\r\n if (arr[j] !== arr[p]) {\r\n break;\r\n }\r\n stretch++;\r\n }\r\n if (stretch > max) {\r\n max = stretch;\r\n l = j;\r\n k = stretch;\r\n }\r\n }\r\n let count = 0;\r\n let pos = l + k;\r\n while (pos < n) {\r\n pos = pos + k;\r\n k = k * 2;\r\n count++;\r\n }\r\n k = n - l;\r\n for (let pos = l; pos > 0; pos -= k) {\r\n k = k * 2;\r\n count++;\r\n }\r\n console.log(count);\r\n }\r\n});\r\n"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0]);\r\n let i = 1;\r\n while (t--) {\r\n let n = parseInt(lines[i++]);\r\n let arr = lines[i++]\r\n .trim()\r\n .split(\" \")\r\n .map((element) => parseInt(element));\r\n let max = 0;\r\n let l, k;\r\n for (let i = 0; i < n; i++) {\r\n let stretch = 0;\r\n for (let j = i; j < n; j++) {\r\n if (arr[i] !== arr[j]) {\r\n break;\r\n }\r\n stretch++;\r\n }\r\n if (stretch > max) {\r\n max = stretch;\r\n l = i;\r\n k = stretch;\r\n }\r\n }\r\n let m = l + k - 1;\r\n let count = 0;\r\n while (l > 0) {\r\n l = Math.max(l - k, 0);\r\n k = m - l + 1;\r\n count++;\r\n }\r\n while (m < n - 1) {\r\n m = m + k;\r\n k = m - l + 1;\r\n count++;\r\n }\r\n console.log(count);\r\n }\r\n});\r\n"}], "src_uid": "dc10b869293df2b7a557262c805635ba"} {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar str = readline();\nvar arr = [];\nvar mySentence = [];\nvar mySentenceCopy = [];\n\nfor(var i=0; i {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = readInt(arr)\n\n for(let j = 0; j < t; j++) {\n const [h, m] = readInts(arr, j)\n const ans = (24 - h) * 60 - m\n wr(ans)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n \tvar tmp = nextIntArray();\n \toutput[i] = 1440 - (tmp[0] * 60 + tmp[1]);\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [h, m] = d.split(\" \").map(Number);\n let ans = 0;\n let r = m === 0 ? 0 : 1;\n\n ans += m === 0 ? 0 : 60 - m;\n ans += (24 - r - h) * 60;\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine(), 10);\n let i, h, m;\n \n for(i=1; i<=t; i++) {\n let inputs = readLine();\n inputs = inputs.split(' ');\n h = parseInt(inputs[0], 10);\n m = parseInt(inputs[1], 10);\n \n let totalMin = (23-h)*60 + 60-m;\n console.log(totalMin);\n }\n}"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t, time, ans;\n\nt = Number(readline());\n\nfor (i = 0; i < t; i++) {\n\n time = readline().replace(/\\r$/, '').split(' ').map(Number);\n ans = 24 * 60;\n ans -= time[0] * 60 + time[1];\n\n print(ans);\n}"}, {"source_code": "var day = 1440;\nvar t = 0;\nt = parseInt(readline());\nfor (var i=0;i parseInt(x));\ncurrentHour = num[0];\ncurrentMin = num[1];\nvar CurrentTime = parseInt(currentHour) * 60 + parseInt(currentMin);\nprint(parseInt(day)-parseInt(CurrentTime));\n}\n"}, {"source_code": "var cant = readline();\n\nfor (var i=0; i < cant; i++) {\n var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n var hours = numbers[0];\n var minutes = numbers[1];\n var toRet = 0;\n if(hours >= 0 ){\n toRet = (23-hours)*60; \n }\n if(minutes >= 0)\n toRet += 60-minutes;\n print(toRet);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\n// ======================================================\n// A. Minutes Before the New Year\n// https://codeforces.com/problemset/problem/1283/A\n// ======================================================\n\n// hours = number of hours left\n// min = number of minutes left.\nfunction doIt( hours, min ) {\n \n var result = 0;\n \n var result1 = 60 - min;\n var result2 = 0;\n \n if( 1 + hours < 24 ) {\n result2 = (24 - (1 + hours)) * 60;\n }\n \n return result1 + result2;\n \n}\n\nfunction main() {\n\n var numOfTests = readALine();\n for( var i = 0; i < numOfTests; i++ ) {\n \n var string1 = readALine();\n var arr1 = stringArrayToNumbers(string1);\n \n var result = doIt( arr1[0], arr1[1] );\n \n printALine(result);\n \n }\n\n}\n\n\n\n\n\n"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst t = data[0];\nvar timeArray=[];\nfor (var i=0; i parseInt(x));\n var minutes = time[0] * 60 + time[1];\n print(1440 - minutes);\n}"}, {"source_code": "var n = parseInt(readline());\nwhile(n--){\n var z = readline();\n var t = z.split(' ').map(e => parseInt(e));\n print((23-t[0])*60+60-t[1]);\n}"}, {"source_code": "'use strict'\n\nconst problem = (h, m) => 1440 - h*60 - m;\nlet q = +readline();\nwhile(q--) print(problem(...readline().split(' ').map(Number)))\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var hhmm = readline().split(' ').map(Number);\n var hh = hhmm[0];\n var mm = hhmm[1];\n print((23 - hh) * 60 + 60 - mm)\n }\n}\nmain()"}, {"source_code": " var t = Number(readline());\n\n while (t--) {\n var input = readline().split(' ').map(function(x) {\n return parseInt(x);\n });\n var h = input[0];\n var m = input[1];\n var result = 1440 - (h * 60 + Number(m));\n print(result);\n }"}, {"source_code": "\"use strict\";\n\nlet inputNumber = +readline();\nlet dates = [];\nlet output = [];\n\nfor (let i = 0; i < inputNumber; i++) {\n\tdates[i] = readline();\n\tdates[i] = dates[i].split(\" \").map(function(item){ return +item; });\n\tlet hours = dates[i][0];\n\tlet mins = dates[i][1];\n\toutput[i] = (24 - hours) * -60 + mins;\n}\n\nfor (let i = 0; i < inputNumber; i++) {\n\tprint(-output[i]);\n}\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let curTime = inputString[index++].split(' ');\n console.log(minsRemained(curTime))\n } \n}\n\nfunction minsRemained(curTime) {\n return parseInt((24 - curTime[0] - 1)*60) + parseInt(60 - curTime[1]);\n}"}], "negative_code": [{"source_code": " var t = readline();\n while (t--) {\n var h = readline();\n var m = readline();\n var result = 1440 - (h * 60 + Number(m));\n print(result);\n }"}, {"source_code": " var t = Number(readline());\n while (t--) {\n var h = Number(readline());\n var m = Number(readline());\n var result = 1440 - (h * 60 + Number(m));\n print(result);\n }"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i parseInt(x));\nconst t = data[0];\nvar timeArray=[];\nfor (var i=0; i parseInt(x));\n const minutes = time[0] * 60 + time[1];\n timeArray.push(1440 - minutes);\n}\nprint(timeArray);"}, {"source_code": "const data = readline().split(\" \").map(x => parseInt(x));\nconst t = data[0];\nvar timeArray=[];\nfor (var i=0; i parseInt(x));\n var minutes = time[0] * 60 + time[1];\n timeArray.push(1440 - minutes);\n}\nprint(timeArray);"}], "src_uid": "f4982de28aca7080342eb1d0ff87734c"} {"source_code": "function solve() {\r\n read();\r\n var [n, m] = readArray(Number);\r\n var arr = [];\r\n for (var i = 0; i < m; i++) {\r\n var [x, w] = readArray(Number);\r\n arr.push({\r\n x,\r\n w,\r\n i: i + 1\r\n });\r\n }\r\n arr.sort(f1);\r\n arr = arr.slice(0, 2 * n);\r\n arr.sort(f2);\r\n var sum = 0;\r\n var ans = [];\r\n for (var i = 0; i < n; i++) {\r\n sum += arr[i].w;\r\n ans.push([arr[i].i]);\r\n }\r\n for (var i = 0; i < n; i++) {\r\n sum += arr[2 * n - i - 1].w;\r\n ans[i].push(arr[2 * n - i - 1].i);\r\n }\r\n write(sum);\r\n for (var i = 0; i < n; i++) {\r\n write(ans[i].join(' '));\r\n }\r\n write('');\r\n}\r\n\r\nfunction f1(a, b) {\r\n return a.w - b.w;\r\n}\r\nfunction f2(a, b) {\r\n return a.x - b.x;\r\n}\r\n \r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n \r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n \r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, m] = rna();\r\n\t\tlet points = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tconst [x, w] = rna();\r\n\t\t\tpoints.push({pos: x, wt: w, id: i+1})\r\n\t\t}\r\n\r\n\t\tpoints.sort((x, y) => x.wt - y.wt);\r\n\t\tpoints = points.slice(0, 2*n);\r\n\t\tpoints.sort((x, y) => x.pos - y.pos);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i++) sum += points[i].wt;\r\n\t\tconsole.log(sum);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconsole.log(points[i].id, points[2*n-i-1].id);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, m] = rna();\r\n\t\tlet points = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tconst [x, w] = rna();\r\n\t\t\tpoints.push([x, w, i+1]);\r\n\t\t}\r\n\r\n\t\tpoints.sort((x, y) => x[1] - y[1]);\r\n\t\tpoints = points.slice(0, 2*n);\r\n\r\n\t\tpoints.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i++) sum += points[i][1];\r\n\t\tconsole.log(sum);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconsole.log(points[i][2], points[2*n-i-1][2]);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "function solve() {\r\n read();\r\n const [n, m] = readArray(Number);\r\n let arr = [];\r\n for (let i = 0; i < m; i++) {\r\n const [x, w] = readArray(Number);\r\n arr.push({\r\n x,\r\n w,\r\n i: i + 1\r\n });\r\n }\r\n arr.sort((a, b) => a.w - b.w);\r\n arr = arr.slice(0, 2 * n);\r\n arr.sort((a, b) => a.x - b.x);\r\n let sum = 0;\r\n const ans = [];\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i].w;\r\n ans.push([arr[i].i]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[2 * n - i - 1].w;\r\n ans[i].push(arr[2 * n - i - 1].i);\r\n }\r\n write(sum);\r\n for (let i = 0; i < n; i++) {\r\n write(ans[i].join(' '));\r\n }\r\n write('');\r\n}\r\n \r\nfunction start() {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n writeAns();\r\n}\r\n \r\ntry {\r\n initInput(start);\r\n} catch (e) {\r\n console.log(e);\r\n}\r\n \r\nvar MEMORY;\r\nvar MEMORY_INDEX;\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\nvar ANS;\r\n// \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 ANS \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0435\u0441\u0442 \u043a\u0443\u0447\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.\r\n// \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 - 2097151.\r\nfunction write(value) {\r\n // console.log(value);\r\n ANS += value + '\\n';\r\n}\r\nfunction writeAns() {\r\n if (ANS) {\r\n console.log(ANS);\r\n }\r\n}\r\nfunction read() {\r\n return MEMORY[MEMORY_INDEX++];\r\n}\r\nfunction initInput(callback) {\r\n var fs = require('fs');\r\n ANS = '';\r\n MEMORY_INDEX = 0;\r\n var isLocalStart = process.argv[2] === 'lorelvate';\r\n if (!isLocalStart) {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n callback();\r\n return;\r\n }\r\n var path = require('path');\r\n fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {\r\n if (err) {\r\n write(err);\r\n return;\r\n }\r\n MEMORY = data.split('\\r\\n');\r\n callback();\r\n });\r\n}"}, {"source_code": "function solve() {\r\n read();\r\n const [n, m] = readArray(Number);\r\n let arr = [];\r\n for (let i = 0; i < m; i++) {\r\n const [x, w] = readArray(Number);\r\n arr.push({\r\n x,\r\n w,\r\n i: i + 1\r\n });\r\n }\r\n arr.sort((a, b) => a.w - b.w);\r\n arr = arr.slice(0, 2 * n);\r\n arr.sort((a, b) => a.x - b.x);\r\n let sum = 0;\r\n const ans = [];\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[i].w;\r\n ans.push([arr[i].i]);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n sum += arr[2 * n - i - 1].w;\r\n ans[i].push(arr[2 * n - i - 1].i);\r\n }\r\n write(sum);\r\n for (let i = 0; i < n; i++) {\r\n write(ans[i].join(' '));\r\n }\r\n write('');\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\r\n l += m\r\n output[i] = solve(n, m, arr)\r\n }\r\n console.log(output.join('\\n\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, arr) {\r\n arr = arr\r\n // .sort((a, b) => a[0] - b[0])\r\n .map(([x, w], i) => ({ x, w, i: i + 1}))\r\n .sort((a, b) => a.w - b.w)\r\n let ans = 0\r\n const xs = Array(2 * n)\r\n for (let i = 0; i < 2 * n; i++) {\r\n ans += arr[i].w\r\n xs[i] = arr[i]\r\n }\r\n xs.sort((a, b) => a.x - b.x)\r\n const pairs = Array(n)\r\n for (let i = 0; i < n; i++) {\r\n pairs[i] = xs[i].i + ' ' + xs[2 * n - 1 - i].i\r\n }\r\n return ans + '\\n' + pairs.join('\\n')\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < m; i++) {\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n for (let i = 0; i < m; i++) {\r\n let obj = { val: arr[i][0], w: arr[i][1], ind: i };\r\n arr[i] = obj;\r\n }\r\n arr.sort((a,b)=>a.w - b.w);\r\n let narr = [],total = 0;\r\n for(let i=0;ia.val - b.val);\r\n console.log(total);\r\n let i=0,j = n*2 - 1;\r\n while(i {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\n \nconst calc = (n, m, arr)=>{\n arr = arr.map((a, i)=>({w: a[1], x: a[0], i})).sort((a, b)=>a.w-b.w)\n //console.log(n, m, arr)\n let slice = arr.slice(0, 2*n);\n slice.sort((a, b)=>a.x-b.x);\n let ans_arr = [];\n let ans_sum = 0;\n for (let i=0; i stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, m] = rna();\r\n\t\tconst points = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tconst [x, w] = rna();\r\n\t\t\tpoints.push([w, i+1]);\r\n\t\t}\r\n\r\n\t\tpoints.sort((x, y) => x[0] - y[0]);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i++) sum += points[i][0];\r\n\t\tconsole.log(sum);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconsole.log(points[i][1], points[2*n-i-1][1]);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\trl();\r\n\t\tconst [n, m] = rna();\r\n\t\tconst points = [];\r\n\t\tfor (let i = 0; i < m; i++) {\r\n\t\t\tconst [x, w] = rna();\r\n\t\t\tpoints.push([x, w]);\r\n\t\t}\r\n\r\n\t\tpoints.sort((x, y) => x[1] - y[1]);\r\n\r\n\t\tlet sum = 0;\r\n\t\tfor (let i = 0; i < 2*n; i++) sum += points[i][0];\r\n\t\tconsole.log(sum);\r\n\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tconsole.log(points[i][0], points[2*n-i-1][0]);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\r\n l += m\r\n output[i] = solve(n, m, arr)\r\n }\r\n console.log(output.join('\\n\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, arr) {\r\n arr = arr\r\n // .sort((a, b) => a[0] - b[0])\r\n .map(([x, w], i) => ({ x, w, i: i + 1}))\r\n .sort((a, b) => a.w - b.w)\r\n let ans = 0\r\n const xs = Array(2 * n)\r\n for (let i = 0; i < 2 * n; i++) {\r\n ans += arr[i].w\r\n xs[i] = arr[i].i\r\n }\r\n xs.sort((a, b) => a - b)\r\n const pairs = Array(n)\r\n for (let i = 0; i < n; i++) {\r\n pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]\r\n }\r\n return ans + '\\n' + pairs.join('\\n')\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\r\n l += m\r\n output[i] = solve(n, m, arr)\r\n }\r\n console.log(output.join('\\n\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, m, arr) {\r\n arr = arr\r\n .sort((a, b) => a[0] - b[0])\r\n .map(([x, w], i) => ({ x, w, i: i + 1}))\r\n .sort((a, b) => a.w - b.w)\r\n let ans = 0\r\n const xs = Array(2 * n)\r\n for (let i = 0; i < 2 * n; i++) {\r\n ans += arr[i].w\r\n xs[i] = arr[i].i\r\n }\r\n xs.sort((a, b) => a - b)\r\n const pairs = Array(n)\r\n for (let i = 0; i < n; i++) {\r\n pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]\r\n }\r\n return ans + '\\n' + pairs.join('\\n')\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n readline();\r\n let [n, m] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = [];\r\n for (let i = 0; i < m; i++) {\r\n arr.push(\r\n readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur))\r\n );\r\n }\r\n for (let i = 0; i < m; i++) {\r\n let obj = { val: arr[i][0], w: arr[i][1], ind: i };\r\n arr[i] = obj;\r\n }\r\n arr.sort((a, b) => a.val - b.val);\r\n const r = (start, i, j) => {\r\n let s1 = 0,\r\n s = [],\r\n cnt = 0;\r\n while (i <= start) {\r\n if (cnt < n) s1 += arr[i].w;\r\n else {\r\n let obj = { w: s1, s: j, e: i - 1 };\r\n s.push(obj);\r\n if (i < start) s1 = s1 - arr[j].w + arr[i].w;\r\n j++;\r\n }\r\n i++;\r\n cnt++;\r\n }\r\n return s;\r\n };\r\n let s1 = r(m - n, 0, 0);\r\n let s2 = r(m, n, n);\r\n let minarr = [];\r\n let min = s2.length - 1;\r\n for (let i = s2.length - 1; i >= 0; i--) {\r\n if (s2[min].w >= s2[i].w) min = i;\r\n minarr[i] = min;\r\n }\r\n let minx = Infinity,\r\n obj1 = {};\r\n for (let i = 0; i < s1.length; i++) {\r\n let k = s1[i].w + s2[minarr[i]].w;\r\n if (k < minx) {\r\n obj1 = { v1: s1[i], v2: s2[minarr[i]] };\r\n minx = k;\r\n }\r\n }\r\n console.log(obj1.v1.w + obj1.v2.w);\r\n let st1 = obj1.v1.s,\r\n st2 = obj1.v2.e,\r\n i = 0;\r\n while (i < n) {\r\n console.log(`${arr[st1].ind + 1} ${arr[st2].ind + 1}`);\r\n st1++;\r\n st2--;\r\n i++;\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "bfb2831c319400d4a62890e6ea20d045"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n & 1) return 'Mike';\r\n let min = Math.min(...a);\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === min) {\r\n return i & 1 ? 'Mike' : 'Joe';\r\n }\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let piles = parseInt(readline(), 10);\r\n let sizes = readline().split(' ').map(Number);\r\n if (piles % 2 === 1) {\r\n output('Mike');\r\n continue;\r\n }\r\n\r\n let mike = Infinity;\r\n let joe = Infinity;\r\n for (let j = 0; j < piles; j++) {\r\n if (j % 2 === 0 && sizes[j] < mike) {\r\n mike = sizes[j];\r\n }\r\n if (j % 2 === 1 && sizes[j] < joe) {\r\n joe = sizes[j];\r\n }\r\n }\r\n\r\n if (mike === joe) {\r\n const firstMaxIndex = sizes.findIndex(l => l === mike);\r\n if (firstMaxIndex % 2 === 0) {\r\n output('Joe');\r\n } else {\r\n output('Mike');\r\n }\r\n continue;\r\n }\r\n\r\n output(mike > joe ? 'Mike' : 'Joe');\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #801 (Div. 2) and EPIC Institute of Technology Round\n2022-06-18\n\nB. Circle Game\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n let start = readline();\n start = start.split(\" \");\n start = start.map((k) => parseInt(k));\n\n if (n % 2 == 1) {\n // If n is odd then Mike wins because he can always take the\n // first pile so Joe loses when we loop round.\n console.log(\"Mike\");\n } else {\n let mikeSmallest = 1e10;\n let mikeSmallestLoc;\n let joeSmallest = 1e10;\n let joeSmallestLoc;\n // If n is even, each player wants to conserve their own\n // stones, so they will always take a single stone at a time.\n // So the loser is the one with the smallest pile (first to\n // come across it if tied).\n for (let pile = 0; pile < n; pile += 2) {\n if (start[pile] < mikeSmallest) {\n mikeSmallest = start[pile];\n mikeSmallestLoc = pile;\n }\n }\n\n for (let pile = 1; pile < n; pile += 2) {\n if (start[pile] < joeSmallest) {\n joeSmallest = start[pile];\n joeSmallestLoc = pile;\n }\n }\n\n if (mikeSmallest < joeSmallest) {\n console.log(\"Joe\");\n } else if (mikeSmallest > joeSmallest) {\n console.log(\"Mike\");\n } else {\n console.log(mikeSmallestLoc < joeSmallestLoc ? \"Joe\" : \"Mike\");\n }\n }\n }\n}\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #801 (Div. 2) and EPIC Institute of Technology Round\n2022-06-18\n\nB. Circle Game\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n let start = readline();\n start = start.split(\" \");\n start = start.map((k) => parseInt(k));\n\n if (n % 2 == 1) {\n // If n is odd then Mike wins because he can always take the\n // first pile so Joe loses when we loop round.\n console.log(\"Mike\");\n } else {\n let mikeSmallest = 1e10;\n let joeSmallest = 1e10;\n // If n is even, each player wants to conserve their own\n // stones, so they will always take a single stone at a time.\n // So the loser is the one with the smallest pile (Mike if\n // tied).\n for (let pile = 0; pile < n; pile += 2) {\n if (start[pile] < mikeSmallest) {\n mikeSmallest = start[pile];\n }\n }\n\n for (let pile = 1; pile < n; pile += 2) {\n if (start[pile] < joeSmallest) {\n joeSmallest = start[pile];\n }\n }\n\n if (mikeSmallest < joeSmallest) {\n console.log(\"Mike\");\n } else {\n console.log(\"Joe\");\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #801 (Div. 2) and EPIC Institute of Technology Round\n2022-06-18\n\nB. Circle Game\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n let start = readline();\n start = start.split(\" \");\n start = start.map((k) => parseInt(k));\n\n if (n % 2 == 1) {\n // If n is odd then Mike wins because he can always take the\n // first pile so Joe loses when we loop round.\n console.log(\"Mike\");\n } else {\n let mikeSmallest = 1e10;\n let joeSmallest = 1e10;\n // If n is even, each player wants to conserve their own\n // stones, so they will always take a single stone at a time.\n // So the loser is the one with the smallest pile (Mike if\n // tied).\n for (let pile = 0; pile < n; pile += 2) {\n if (start[pile] < mikeSmallest) {\n mikeSmallest = start[pile];\n }\n }\n\n for (let pile = 1; pile < n; pile += 2) {\n if (start[pile] < joeSmallest) {\n joeSmallest = start[pile];\n }\n }\n\n if (mikeSmallest <= joeSmallest) {\n console.log(\"Joe\");\n } else {\n console.log(\"Mike\");\n }\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nCodeforces Round #801 (Div. 2) and EPIC Institute of Technology Round\n2022-06-18\n\nB. Circle Game\n***/\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n readline();\n // Strategy: The optimal move is always to remove all the stones\n // so the opponent can't play there next time and loses.\n console.log(n % 2 == 0 ? \"Joe\" : \"Mike\");\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const res = a.reduce((a, b) => a ^ b, 0);\r\n return res > 0 ? 'Mike' : 'Joe';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const res = a.reduce((a, b) => a ^ b, 0);\r\n return res & 1 ? 'Mike' : 'Joe';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let piles = parseInt(readline(), 10);\r\n let sizes = readline().split(' ').map(Number);\r\n if (piles % 2 === 1) {\r\n output('Mike');\r\n continue;\r\n }\r\n\r\n let mike = Infinity;\r\n let joe = Infinity;\r\n for (let j = 0; j < piles; j++) {\r\n if (j % 2 === 0 && sizes[j] < mike) {\r\n mike = sizes[j];\r\n }\r\n if (j % 2 === 1 && sizes[j] < joe) {\r\n joe = sizes[j];\r\n }\r\n }\r\n\r\n output(mike > joe ? 'Mike' : 'Joe');\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n let piles = readline();\r\n readline(); // stones array\r\n\r\n output(piles % 2 === 1 ? 'Mike' : 'Joe');\r\n }\r\n}"}], "src_uid": "0a187d80fdc3df579909840e9111ac7e"} {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;\n\n n = Number(readline());\n\n requests = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];\n requests.push({\n people: people,\n money: money,\n number: i\n });\n }\n\n m = Number(readline());\n\n tables = readline().split(' ').map(function(x, i) {\n return {\n size: Number(x),\n number: i + 1,\n taken: false\n };\n });\n\n requests.sort(function(a, b) {\n if (a.money > b.money) {\n return -1;\n } else {\n return 1;\n }\n });\n\n tables.sort(function(a, b) {\n if (a.size > b.size) {\n return 1;\n } else {\n return -1;\n }\n });\n\n find = function(array, el, a, b) {\n var c, _ref1, _ref2;\n if (a == null) {\n a = 0;\n }\n if (b == null) {\n b = array.length - 1;\n }\n if (a === b) {\n while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {\n a++;\n }\n if (a >= array.length) {\n return null;\n }\n if (array[a].size >= el) {\n array[a].taken = true;\n return array[a];\n }\n } else {\n if (el <= array[c = Math.floor((a + b) / 2)].size) {\n return find(array, el, a, c);\n } else if (el >= array[c = Math.ceil((a + b) / 2)].size) {\n return find(array, el, c, b);\n } else {\n while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {\n c++;\n }\n if (c >= array.length) {\n return null;\n }\n array[c].taken = true;\n return array[c];\n }\n }\n };\n\n seats = [];\n\n totalMoney = 0;\n\n for (_j = 0, _len = requests.length; _j < _len; _j++) {\n request = requests[_j];\n found = find(tables, request.people);\n if (found != null) {\n seats.push({\n table: found.number,\n request: request.number\n });\n totalMoney += request.money;\n }\n }\n\n print(seats.length + ' ' + totalMoney);\n\n for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {\n seat = seats[_k];\n print(seat.request + ' ' + seat.table);\n }\n\n}).call(this);\n", "positive_code": [{"source_code": "print(function(n){\n\tvar n = +readline();\n\tvar ans = [];\n\tvar a = [];\n\tfor(var i=0; i=a[i][0]){\n\t\t\t\tr[j][2] = false;\n\t\t\t\tans.push(a[i][2]+' '+r[j][1]);\n\t\t\t\tsum += a[i][1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif(ans.length==0) return ans.length+' '+sum;\n\treturn ans.length+' '+sum+'\\n'+ans.join('\\n');\n}());\nfunction rn() { return readline().split(' ').map(Number); }"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function() {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+' '+sum+'\\n' +ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' ' + r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+' '+sum+'\\n' +ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]){\n r[j][2] = false;\n ans.push(a[i][2]+' '+r[j][1]);\n sum += a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]){\n r[j][2] = false;\n ans.push(a[i][2]+' '+r[j][1]);\n sum += a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+' '+sum+'\\n'+ans.join('\\n');\n}());\nfunction rn() { return readline().split(' ').map(Number); }"}], "negative_code": [{"source_code": "print(function(n){\n\tvar n = +readline();\n\tvar ans = [];\n\tvar a = [];\n\tfor(var i=0; ib[0];});\n\tvar sum = 0;\n\tfor(var i=0; i=a[i][0]){\n\t\t\t\tr[j][2] = false;\n\t\t\t\tans.push(a[i][2]+' '+r[j][1]);\n\t\t\t\tsum += a[i][1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif(ans.length==0) return ans.length+' '+sum;\n\treturn ans.length+' '+sum+'\\n'+ans.join('\\n');\n}());\nfunction rn() { return readline().split(' ').map(Number); }"}, {"source_code": "print(function(n){\n\tvar n = +readline();\n\tvar ans = [];\n\tvar a = [];\n\tfor(var i=0; ib[0];});\n\tvar sum = 0;\n\tfor(var i=0; i=a[i][0]){\n\t\t\t\tr[j][2] = false;\n\t\t\t\tans.push(a[i][2]+' '+r[j][1]);\n\t\t\t\tsum += a[i][1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn ans.length+' '+sum+'\\n'+ans.join('\\n');\n}());\nfunction rn() { return readline().split(' ').map(Number); }"}, {"source_code": "print(function(n){\n\tvar n = +readline();\n\tvar ans = [];\n\tvar a = [];\n\tfor(var i=0; ib[0];});\n\tvar sum = 0;\n\tfor(var i=0; i=a[i][0]){\n\t\t\t\tr[j][2] = false;\n\t\t\t\tans.push(a[i][2]+' '+r[j][1]);\n\t\t\t\tsum += a[i][1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif(ans.length==0) return ans.length+' '+sum;\n\treturn ans.length+' '+sum+'\\n'+ans.join('\\n');\n}());\nfunction rn() { return readline().split(' ').map(Number); }"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=false;\n ans.push(a[j][2]+ ' ' + r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+' '+sum+'\\n' +ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "print(function(n) {\n var n=+readline();\n var ans=[];\n var a=[];\n for(var i=0; i=a[i][0]) {\n r[j][2]=true;\n ans.push(a[i][2]+ ' '+r[j][1]);\n sum+=a[i][1];\n break;\n }\n }\n }\n if(ans.length==0) return ans.length+' '+sum;\n return ans.length+ ' ' + sum + '\\n' + ans.join('\\n');\n}());\nfunction rn() {\n return readline().split(' ').map(Number);\n}"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var find, found, i, m, money, n, people, request, requests, seat, seats, tables, test_array, totalMoney, _i, _j, _k, _len, _len1, _ref;\n\n n = Number(readline());\n\n requests = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];\n requests.push({\n people: people,\n money: money,\n number: i\n });\n }\n\n m = Number(readline());\n\n tables = readline().split(' ').map(function(x, i) {\n return {\n size: Number(x),\n number: i + 1,\n taken: false\n };\n });\n\n requests.sort(function(a, b) {\n if (a.money > b.money) {\n return -1;\n } else {\n return 1;\n }\n });\n\n tables.sort(function(a, b) {\n if (a.size > b.size) {\n return 1;\n } else {\n return -1;\n }\n });\n\n find = function(array, el, a, b) {\n var c, _ref1, _ref2;\n if (a == null) {\n a = 0;\n }\n if (b == null) {\n b = array.length - 1;\n }\n if (a === b) {\n while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {\n a--;\n }\n if (a < 0) {\n return null;\n }\n array[a].taken = true;\n if (array[a].size > el) {\n return array[0];\n }\n } else {\n if (el < array[c = Math.floor((a + b) / 2)].size) {\n return find(array, el, a, c);\n } else if (el > array[c = Math.ceil((a + b) / 2)].size) {\n return find(array, el, c, b);\n } else {\n while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {\n c--;\n }\n if (c < 0) {\n return null;\n }\n array[c].taken = true;\n return array[c];\n }\n }\n };\n\n test_array = (function() {\n var _j, _results;\n _results = [];\n for (i = _j = 1; _j <= 100; i = _j += 5) {\n _results.push({\n size: i,\n number: i\n });\n }\n return _results;\n })();\n\n seats = [];\n\n totalMoney = 0;\n\n for (_j = 0, _len = requests.length; _j < _len; _j++) {\n request = requests[_j];\n found = find(tables, request.people);\n if (found != null) {\n seats.push({\n table: found.number,\n request: request.number\n });\n totalMoney += request.money;\n }\n }\n\n print(seats.length + ' ' + totalMoney);\n\n for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {\n seat = seats[_k];\n print(seat.request + ' ' + seat.table);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var find, found, i, m, money, n, people, request, requests, seat, seats, tables, test_array, totalMoney, _i, _j, _k, _len, _len1, _ref;\n\n n = Number(readline());\n\n requests = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];\n requests.push({\n people: people,\n money: money,\n number: i\n });\n }\n\n m = Number(readline());\n\n tables = readline().split(' ').map(function(x, i) {\n return {\n size: Number(x),\n number: i + 1,\n taken: false\n };\n });\n\n requests.sort(function(a, b) {\n if (a.money > b.money) {\n return -1;\n } else {\n return 1;\n }\n });\n\n tables.sort(function(a, b) {\n if (a.size > b.size) {\n return 1;\n } else {\n return -1;\n }\n });\n\n find = function(array, el, a, b) {\n var c, _ref1, _ref2;\n if (a == null) {\n a = 0;\n }\n if (b == null) {\n b = array.length - 1;\n }\n if (a === b) {\n while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {\n a--;\n }\n if (a < 0) {\n return null;\n }\n array[a].taken = true;\n if (array[a].size >= el) {\n return array[0];\n }\n } else {\n if (el < array[c = Math.floor((a + b) / 2)].size) {\n return find(array, el, a, c);\n } else if (el > array[c = Math.ceil((a + b) / 2)].size) {\n return find(array, el, c, b);\n } else {\n while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {\n c--;\n }\n if (c < 0) {\n return null;\n }\n array[c].taken = true;\n return array[c];\n }\n }\n };\n\n test_array = (function() {\n var _j, _results;\n _results = [];\n for (i = _j = 1; _j <= 100; i = _j += 5) {\n _results.push({\n size: i,\n number: i\n });\n }\n return _results;\n })();\n\n seats = [];\n\n totalMoney = 0;\n\n for (_j = 0, _len = requests.length; _j < _len; _j++) {\n request = requests[_j];\n found = find(tables, request.people);\n if (found != null) {\n seats.push({\n table: found.number,\n request: request.number\n });\n totalMoney += request.money;\n }\n }\n\n print(seats.length + ' ' + totalMoney);\n\n for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {\n seat = seats[_k];\n print(seat.request + ' ' + seat.table);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;\n\n n = Number(readline());\n\n requests = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];\n requests.push({\n people: people,\n money: money,\n number: i\n });\n }\n\n m = Number(readline());\n\n tables = readline().split(' ').map(function(x, i) {\n return {\n size: Number(x),\n number: i + 1,\n taken: false\n };\n });\n\n requests.sort(function(a, b) {\n if (a.money > b.money) {\n return -1;\n } else {\n return 1;\n }\n });\n\n tables.sort(function(a, b) {\n if (a.size > b.size) {\n return 1;\n } else {\n return -1;\n }\n });\n\n find = function(array, el, a, b) {\n var c, _ref1, _ref2;\n if (a == null) {\n a = 0;\n }\n if (b == null) {\n b = array.length - 1;\n }\n if (a === b) {\n while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {\n a++;\n }\n if (a >= array.length) {\n return null;\n }\n if (array[a].size >= el) {\n array[a].taken = true;\n return array[a];\n }\n } else {\n if (el >= array[c = Math.ceil((a + b) / 2)].size) {\n return find(array, el, c, b);\n } else if (el <= array[c = Math.floor((a + b) / 2)].size) {\n return find(array, el, a, c);\n } else {\n while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {\n c++;\n }\n if (c >= array.length) {\n return null;\n }\n array[c].taken = true;\n return array[c];\n }\n }\n };\n\n seats = [];\n\n totalMoney = 0;\n\n for (_j = 0, _len = requests.length; _j < _len; _j++) {\n request = requests[_j];\n found = find(tables, request.people);\n if (found != null) {\n seats.push({\n table: found.number,\n request: request.number\n });\n totalMoney += request.money;\n }\n }\n\n print(seats.length + ' ' + totalMoney);\n\n for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {\n seat = seats[_k];\n print(seat.request + ' ' + seat.table);\n }\n\n}).call(this);\n"}, {"source_code": "// Generated by CoffeeScript 1.7.1\n(function() {\n var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;\n\n n = Number(readline());\n\n requests = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];\n requests.push({\n people: people,\n money: money,\n number: i\n });\n }\n\n m = Number(readline());\n\n tables = readline().split(' ').map(function(x, i) {\n return {\n size: Number(x),\n number: i + 1,\n taken: false\n };\n });\n\n requests.sort(function(a, b) {\n if (a.money > b.money) {\n return -1;\n } else {\n return 1;\n }\n });\n\n tables.sort(function(a, b) {\n if (a.size > b.size) {\n return 1;\n } else {\n return -1;\n }\n });\n\n find = function(array, el, a, b) {\n var c, _ref1, _ref2;\n if (a == null) {\n a = 0;\n }\n if (b == null) {\n b = array.length - 1;\n }\n if (a === b) {\n while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {\n a--;\n }\n if (a < 0) {\n return null;\n }\n if (array[a].size >= el) {\n array[a].taken = true;\n return array[0];\n }\n } else {\n if (el <= array[c = Math.floor((a + b) / 2)].size) {\n return find(array, el, a, c);\n } else if (el >= array[c = Math.ceil((a + b) / 2)].size) {\n return find(array, el, c, b);\n } else {\n while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {\n c--;\n }\n if (c < 0) {\n return null;\n }\n array[c].taken = true;\n return array[c];\n }\n }\n };\n\n seats = [];\n\n totalMoney = 0;\n\n for (_j = 0, _len = requests.length; _j < _len; _j++) {\n request = requests[_j];\n found = find(tables, request.people);\n if (found != null) {\n seats.push({\n table: found.number,\n request: request.number\n });\n totalMoney += request.money;\n }\n }\n\n print(seats.length + ' ' + totalMoney);\n\n for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {\n seat = seats[_k];\n print(seat.request + ' ' + seat.table);\n }\n\n}).call(this);\n"}, {"source_code": "var e,r,n,l,t,i,u,f,o,a,s,h,c,p,d,g,b,m,v,w=Number;u=w(readline());o=[];for(t=p=1;1<=u?p<=u:p>=u;t=1<=u?++p:--p){v=readline().split(\" \").map(w),e=v[0],r=v[1];o.push({a:e,b:r,c:t})}i=w(readline());h=readline().split(\" \").map(function(e,r){return{e:w(e),c:r+1,f:false}});o.sort(function(e,r){if(e.b>r.money){return-1}else{return 1}});h.sort(function(e,r){if(e.e>r.size){return 1}else{return-1}});n=function(e,r,l,t){var i,u,f;if(l==null){l=0}if(t==null){t=e.length-1}if(l===t){while((u=e[l])!=null?u.f:void 0){l++}if(l>=e.length){return null}if(e[l].e>=r){e[l].f=true;return e[l]}}else{if(r<=e[i=Math.floor((l+t)/2)].e){return n(e,r,l,i)}else if(r>=e[i=Math.ceil((l+t)/2)].e){return n(e,r,i,t)}else{while((f=e[i])!=null?f.f:void 0){i++}if(i>=e.length){return null}e[i].f=true;return e[i]}}};s=[];c=0;for(d=0,b=o.length;d 0 && prev.localeCompare( res ) >= 0 ) {\n if( res == x ) {\n if( prev.localeCompare( y ) < 0 ) {\n res = y ;\n }\n else {\n res = \"Invalid\";\n }\n }\n else {\n if( prev.localeCompare( x ) < 0 ) {\n res = x ;\n }\n else {\n res = \"Invalid\";\n }\n }\n }\n return res;\n };\n\n this.solveCase = function() {\n var res , i , j , a , b , c , prev , x , y;\n res = \"YES\";\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.arr[ i ];\n this.brr[ a ] = i;\n }\n prev = \"\";\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.arr[ i ];\n x = this.srr[ a - 1 ];\n y = this.trr[ a - 1 ];\n //print( \"...\" + this.srr[ a - 1 ] + \"....\" + this.trr[ a - 1 ] ) ;\n prev = this.getLexicographicallySmallest( prev , x , y );\n if( prev == \"Invalid\" ) {\n res = \"NO\";\n break;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.srr[ i ] = irObj.nextString();\n this.trr[ i ] = irObj.nextString();\n }\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.trr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.trr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n\n", "positive_code": [{"source_code": "var n =readline();\nvar str = [];\nfor (i=1;i<=n;i++) str.push(readline());\nvar p = readline().split(\" \");\nvar pos;\nvar str1 = [];\nvar shag=0;\nvar result = true;\nfor (i = 0;i=r)s.push(e)});switch(s.length){case 2:r=s.sort()[0];break;case 1:r=s[0];break;case 0:return\"NO\"}}return\"YES\"}())}).call(this)"}, {"source_code": "var n = parseInt(readline());\nvar a = new Array();\nfor(var i=0;iaa[1])\n\t{\n\t a[i][0]=aa[1];\n\t\ta[i][1]=aa[0];\n\t}\n\telse\n\t{\n\t a[i][0]=aa[0];\n\t\ta[i][1]=aa[1];\n\t}\n}\nvar result ='YES';\nvar str = '';\nvar b = readline().split(' ');\nfor(var i=0;istr)\n\t{\n\t str = a[pos][0];\n\t}\n\telse if(a[pos][1]>str)\n\t{\n\t str = a[pos][1];\n\t}\n\telse\n\t{\n\t result = 'NO';\n\t\tbreak;\n\t}\n}\nprint(result);"}, {"source_code": "(function() {\n print(function() {\n var e = +readline(),\n t = [];\n while (e--) {\n t.push(readline().split(\" \"));\n }\n e = t.length;\n var n = [];\n readline().split(\" \").forEach(function(e) {\n return n.push(t[+e - 1])\n });\n var r = n[0][0] < n[0][1] ? n[0][0] : n[0][1];\n for (var i = 1; i < e; i++) {\n var s = [];\n n[i].forEach(function(e) {\n if (e >= r) s.push(e)\n });\n switch (s.length) {\n case 2:\n r = s.sort()[0];\n break;\n case 1:\n r = s[0];\n break;\n case 0:\n return \"NO\"\n }\n }\n return \"YES\"\n }())\n}).call(this)"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function () {\n\n\t\tvar n = +readline(), people = [];\n\n\t\twhile (n--) {\n\t\t\tpeople.push(readline().split(' ').map(function (e) {\n\t\t\t\treturn e.toLowerCase();\n\t\t\t} ));\n\t\t} n = people.length;\n\n\t\tpeople = readline().split(' ').map(function (e) {\n\t\t\treturn people[+e - 1];\n\t\t});\n\n\t\tfor (var i = 1; i < n; i++) {\n\t\t\tif (\n\t\t\t\tpeople[i - 1][0] > people[i][0] &&\n\t\t\t\tpeople[i - 1][0] > people[i][1] &&\n\t\t\t\tpeople[i - 1][1] > people[i][0] &&\n\t\t\t\tpeople[i - 1][1] > people[i][1]\n\t\t\t) return 'NO';\n\t\t}\n\n\t\treturn 'YES';\n\n\t}());\n\n}.call(this));\n"}, {"source_code": "var n =readline();\nvar str = [];\nfor (i=1;i<=n;i++) str.push(readline().split(\" \"));\nvar p = readline().split(\" \");\nvar pos;\nvar pos2;\nvar str1 = [];\nvar shag=0;\nvar result;\nfor (i = 0;i inputString += inputStdin )\r\n\r\nprocess.stdin.on( \"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => string.trim())\r\n main()\r\n})\r\n\r\nconst readline = () => inputString[currentLine++]\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline()) \r\n console.log(solve(n))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n) => {\r\n if( n == 6 ) return 0\r\n\r\n while( n%3 != 0 ){\r\n n--\r\n }\r\n\r\n n = n/3\r\n\r\n return n - 2\r\n}\r\n\r\n\r\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[i]);\r\n n-=6;\r\n console.log(Math.floor(n/3));\r\n }\r\n})"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i];\n console.log(Math.floor(k / 3) - 2);\n }\n});\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n console.log(Math.floor((n-3)/3)-1);\r\n }\r\n};\r\nsolve();\r\n\r\n"}, {"source_code": "\r\nvar readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n // const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n){\r\n\r\n n = n-3;\r\n\r\n return parseInt(n/3)-1;\r\n \r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n const a = Math.ceil((n - 2) / 3);\r\n return a - 2;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet processIn = '';\r\nlet processCurr = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n processIn += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n processIn = processIn.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n JS();\r\n});\r\n\r\nfunction readLine() {\r\n return processIn[processCurr++];\r\n}\r\nfunction mergeSort(a) {\r\n let r = a.length;\r\n let l = 0;\r\n let m = Math.round((r - l) / 2);\r\n if (r === 1) {\r\n return; // returns recursively\r\n }\r\n let L = []; // left half of current a\r\n let R = []; // right half of current a\r\n for (let i = l; i < m; i++) {\r\n L.push(a[i]);\r\n }\r\n for (let j = m; j < r; j++) {\r\n R.push(a[j]);\r\n }\r\n mergeSort(L);\r\n mergeSort(R);\r\n let i = 0, j = 0, k = 0;\r\n // Merging part\r\n while (i < L.length && j < R.length) {\r\n if (L[i] < R[j]) {\r\n a[k] = L[i];\r\n i++;\r\n } else {\r\n a[k] = R[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n while (i < L.length) {\r\n a[k] = L[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < R.length) {\r\n a[k] = R[j];\r\n j++;\r\n k++;\r\n }\r\n}\r\n\r\nfunction JS() {\r\n /*\r\n\r\n */\r\n let tt = parseInt(readLine());\r\n // let tt = 1;\r\n for(let t=0;t { return parseInt(string.trim()); });\r\n console.log(Math.floor(n/3) - 2);\r\n }\r\n}\r\n\r\n"}, {"source_code": "var n = +readline();\r\nfor (var i = 0; i < n; i++) {\r\n var val = +readline();\r\n print(Math.floor((val - 6) / 3));\r\n}\r\n"}], "negative_code": [], "src_uid": "0690e2df87f60e5be34505d9e2817032"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet r = nl.num();\n\t\tlet x = 1;\n\t\tif (r <= 1399){\n\t\t\tx = 4;\n\t\t} else if (r <= 1599){\n\t\t\tx = 3;\n\t\t} else if (r <= 1899){\n\t\t\tx = 2;\n\t\t} \n\t\tans.push(`Division ${x}`);\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating >= 1900){\r\n\tprint(\"Division 1\")\r\n}\r\nelse if (rating <= 1899 && rating >= 1600){\r\n\tprint(\"Division 2\")\r\n}\r\n\r\nelse if (rating <= 1599 && rating >= 1400){\r\n\tprint(\"Division 3\")\r\n}\r\nelse if(rating <= 1399){\r\n\tprint(\"Division 4\")\r\n}\r\n}\r\n"}, {"source_code": "const linesCount = readline();\r\n\r\nfor(x = 0; x < +linesCount; x++) {\r\n var curLine = parseInt(readline());\r\n // print(curLine, typeof curLine);\r\n if (curLine >= 1900) {\r\n print('Division 1');\r\n } else if (curLine >= 1600) {\r\n print('Division 2');\r\n } else if (curLine >= 1400) {\r\n print('Division 3');\r\n } else {\r\n print('Division 4');\r\n }\r\n}"}, {"source_code": "var x = readline();\r\nx = Number(x);\r\n \r\nwhile (x--) {\r\n\tvar a = readline(); a = Number(a);\r\n\tif (1900<=a) print('Division 1');\r\n\tif (1600<=a&&a<=1899) print('Division 2');\r\n\tif (1400<=a&&a<=1599) print('Division 3');\r\n\tif (a<=1399) print('Division 4');\r\n}"}, {"source_code": "var testCase = +readline()\r\nfor (var i = 0; i < testCase; i++) {\r\n var sequence = +readline()\r\n if (sequence >= 1900) {\r\n print(\"Division 1\")\r\n } else if (sequence >= 1600 && sequence <= 1899) {\r\n print(\"Division 2\")\r\n } else if (sequence >= 1400 && sequence <= 1599) {\r\n print(\"Division 3\")\r\n } else {\r\n print(\"Division 4\")\r\n }\r\n}"}, {"source_code": "var num=parseInt(readline());\r\nvar arr=[];\r\nfor(var i=0;i=1400 && 1599>=arr[i]){\r\n print(\"Division 3\")\r\n }else if(arr[i]>=1600 && 1899>=arr[i]){\r\n print(\"Division 2\")\r\n }else{\r\n print(\"Division 1\")\r\n }\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i =0 ; i < t ; i++){\r\n var rating = Number(readline());\r\n if (rating >= 1900) {\r\n print('Division 1');\r\n } else if (rating >= 1600) {\r\n print('Division 2');\r\n } else if (rating >= 1400) {\r\n print('Division 3');\r\n } else {\r\n print('Division 4');\r\n }\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var rating = readline();\r\n if(rating <= 1399 ){\r\n print(\"Division 4\");\r\n }\r\n else if(rating >= 1400 && rating <= 1599){\r\n print(\"Division 3\");\r\n }\r\n else if(rating >= 1600 && rating <= 1899 ){\r\n print(\"Division 2\");\r\n }\r\n else if(rating >= 1900 ){\r\n print(\"Division 1\");\r\n }\r\n}"}, {"source_code": "T = readline()\r\nwhile (T--) {\r\n x = readline()\r\n ans = 0\r\n if(x <= 1399)\r\n ans = 'Division 4'\r\n else if(x >= 1400 && x <= 1599)\r\n ans = 'Division 3'\r\n else if(x >= 1600 && x <= 1899)\r\n ans = 'Division 2'\r\n else if(x >= 1900)\r\n ans = 'Division 1'\r\n \r\n print(ans)\r\n}\r\n\r\n"}, {"source_code": "n=Number(readline())\r\nfor (i=0;i= 1400 && points <= 1599) print('Division 3')\r\n if(points >= 1600 && points <= 1899) print('Division 2')\r\n if(points >= 1900) print('Division 1')\r\n}"}, {"source_code": "var x = readline();\r\nx = Number(x);\r\n\r\nwhile (x--) {\r\n\tvar a = readline(); a = Number(a);\r\n\tif (1900<=a) print('Division 1');\r\n\tif (1600<=a&&a<=1899) print('Division 2');\r\n\tif (1400<=a&&a<=1599) print('Division 3');\r\n\tif (a<=1399) print('Division 4');\r\n}"}, {"source_code": "var t = readline();\r\nwhile ( t -- ) {\r\n var n = readline();\r\n if ( n >= 1900 ){\r\n print(\"Division 1\")\r\n }\r\n else if ( n >= 1600 ) {\r\n print(\"Division 2\") ;\r\n }\r\n else if ( n >= 1400 ) {\r\n print(\"Division 3\") ;\r\n }\r\n else {\r\n print(\"Division 4\") ;\r\n }\r\n}"}, {"source_code": "var t = +readline()\r\n\r\nfor(var i = 0; i< t; i ++) {\r\n var a = +readline()\r\n print(whichDivision(a))\r\n}\r\n \r\nfunction whichDivision(n){\r\n if (n >= 1900){\r\n return 'Division 1'\r\n }\r\n else if (1600 <= n && n <= 1899){\r\n return 'Division 2'\r\n }\r\n else if (1400 <= n && n <= 1599){\r\n return 'Division 3'\r\n }\r\n else {\r\n return 'Division 4'\r\n }\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n ; j++){\n var rating = lines[j]\n if(1900 <= rating){\n console.log('Division 1')\n }else if(1600 <= rating && rating <= 1899){\n console.log('Division 2')\n }else if(1400 <= rating && rating <= 1599){\n console.log('Division 3')\n }else {\n console.log('Division 4')\n }\n }\n});\n "}, {"source_code": "let stdin = process.stdin;\r\nstdin.setEncoding('utf8');\r\nstdin.on('data', function (data) {\r\n let input = data.split('\\n');\r\n let count = parseInt(input[0]);\r\n\r\n for (let i = 0; i < count; i++) {\r\n const number = input[i + 1];\r\n\r\n if (number >= 1900) {\r\n console.log('Division ', 1);\r\n }\r\n\r\n if (number >= 1600 && number <= 1899) {\r\n console.log('Division ', 2);\r\n }\r\n\r\n if (number >= 1400 && number <= 1599) {\r\n console.log('Division ', 3);\r\n }\r\n\r\n if (number <= 1399) {\r\n console.log('Division ', 4);\r\n }\r\n }\r\n});\r\n"}, {"source_code": "let stdin = process.stdin;\r\nstdin.setEncoding('utf8');\r\nstdin.on('data', function (data) {\r\n let input = data.split('\\n');\r\n let count = parseInt(input[0]);\r\n\r\n for (let i = 0; i < count; i++) {\r\n const number = input[i + 1];\r\n\r\n if (number >= 1900) {\r\n console.log('Division 1');\r\n }\r\n\r\n if (number >= 1600 && number <= 1899) {\r\n console.log('Division 2');\r\n }\r\n\r\n if (number >= 1400 && number <= 1599) {\r\n console.log('Division 3');\r\n }\r\n\r\n if (number <= 1399) {\r\n console.log('Division 4');\r\n }\r\n }\r\n});"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const rating = Number(d);\n if (rating <= 1399) {\n console.log(\"Division 4\");\n } else if (rating >= 1400 && rating <= 1599) {\n console.log(\"Division 3\");\n } else if (rating >= 1600 && rating <= 1899) {\n console.log(\"Division 2\");\n } else {\n console.log(\"Division 1\");\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction getDivision(rating = Number)\r\n{\r\n let rs = 4;\r\n if (rating >= 1900)\r\n {\r\n rs = 1;\r\n }\r\n else if (rating >= 1600 && rating < 1900)\r\n {\r\n rs = 2;\r\n }\r\n else if (rating >= 1400 && rating < 1600)\r\n {\r\n rs = 3;\r\n }\r\n\r\n return `Division ${rs}`;\r\n}\r\n\r\nfunction solve()\r\n{\r\n let n = readSingleInt();\r\n while (n--)\r\n {\r\n let p = readSingleInt();\r\n console.log(getDivision(p))\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n < 1400) {\r\n console.log('Division 4');\r\n } else if (n < 1600) {\r\n console.log('Division 3');\r\n } else if (n < 1900) {\r\n console.log('Division 2');\r\n } else {\r\n console.log('Division 1');\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n solve(n);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, m, A)=>{\n if (n<=1399)\n return 4;\n if (n<=1599)\n return 3;\n if (n<=1899)\n return 2;\n return 1\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, m] = ra();\n L('Ans:')\n print('Division '+calc(n, m));\n }\n}\n \nE.calc = calc;"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n let cases = input.slice(1).map(Number);\r\n for (let i = 0; i < cases.length; i++) {\r\n ans.push(`Division ${cases[i] <= 1399 ? 4 : cases[i] <= 1599 ? 3 : cases[i] <= 1899 ? 2 : 1}`);\r\n }\r\n console.log(ans.join('\\n'));\r\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let o = d => output(`Division ${d}`);\r\n\r\n if (n <= 1399) {\r\n o(4);\r\n } else if (n <= 1599) {\r\n o(3);\r\n } else if (n <= 1899) {\r\n o(2);\r\n } else {\r\n o(1);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let i = readline()\n while (i--) {\n const n = readline() | 0\n if (n >= 1900) {\n console.log('Division 1')\n } else if (n >= 1600) {\n console.log('Division 2')\n } else if (n >= 1400) {\n console.log('Division 3')\n } else {\n console.log('Division 4')\n }\n }\n}\n\n \t\t \t\t \t\t \t \t\t \t \t\t"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n const num = parseInt(readLine());\r\n if (num <= 1399) return \"Division 4\";\r\n if (num <= 1599) return \"Division 3\";\r\n if (num <= 1899) return \"Division 2\";\r\n if (num >= 1900) return \"Division 1\";\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline()\n solve(n)\n }\n}\nfunction solve(n) {\n let res = 4\n if (n >= 1900) {\n res = 1\n } else if (n >= 1600) {\n res = 2\n } else if (n >= 1400) {\n res = 3\n } \n\n console.log('Division ' + res)\n}\n\n"}, {"source_code": "/*\r\n * File Created: Thursday, 11th February 2021 1:42:08 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const s = parseInt(data.shift());\r\n \r\n console.log(a784(s));\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data[currentLine++].split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n,arr){\r\n let k = 0;\r\n let j = 0;\r\n for(let i = 0 ; i < n; i++){\r\n if(arr[i] < 0){\r\n arr[j++] *= -1;\r\n arr[i] *= -1;\r\n }\r\n }\r\n if(isSorted(arr)) {\r\n return 'YES';\r\n } else { \r\n return 'NO'\r\n }\r\n}\r\n\r\nfunction isSorted(arr){\r\n for(let i = 0 ; i < arr.length - 1; i++){\r\n if(arr[i] > arr[i+1]) return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction b(s) {\r\n let arr = [];\r\n for(let i = 97; i <= 122; i++ ){\r\n for(let j = 97; j <= 122; j++){\r\n if(i != j) arr.push(String.fromCharCode(i,j));\r\n }\r\n }\r\n let count = 1;\r\n let index = 0;\r\n while(true){\r\n if(s != arr[index]) {\r\n count++;\r\n index++;\r\n } else{\r\n return count;\r\n }\r\n }\r\n}\r\n\r\nfunction a784(s){\r\n if(s >= 1900) {\r\n return 'Division 1';\r\n } else if(s >= 1600){\r\n return 'Division 2';\r\n } else if(s >= 1400){\r\n return 'Division 3';\r\n } else {\r\n return 'Division 4';\r\n }\r\n}\r\nmodule.exports = a784;"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n; i++){\n var k = lines[i];\n if(1900 <= k){\n console.log('Division 1');\n }else if(1600 <= k && k <= 1899){\n console.log('Division 2');\n }else if(1400 <= k && k <= 1599){\n console.log('Division 3');\n }else if(k <= 1399){\n console.log('Division 4');\n }\n }\n});"}, {"source_code": "let readline = require(\"readline\");\r\nlet rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n\tterminal: false\r\n});\r\n\r\nlet lines = [];\r\n\r\nasync function main() {\r\n for await (let line of rl) {\r\n\t lines.push(line);\r\n }\r\n \r\n\tlet inputs = +lines.splice(0, 1); // dirty javascript typecasting to number\r\n \r\n for (let line of lines) {\r\n switch (true) {\r\n case +line <= 1399:\r\n console.log(\"Division 4\");\r\n break;\r\n case +line <= 1599:\r\n console.log(\"Division 3\");\r\n break;\r\n case +line <= 1899:\r\n console.log(\"Division 2\");\r\n break;\r\n default:\r\n console.log(\"Division 1\");\r\n break;\r\n }\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst rating = rn();\r\n\t\tlet ans;\r\n\t\tif (rating >= 1900) ans = 1;\r\n\t\telse if (rating >= 1600) ans = 2;\r\n\t\telse if (rating >= 1400) ans = 3;\r\n\t\telse ans = 4;\r\n\r\n\t\tconsole.log('Division', ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const getDivison = (n) => {\n if (n >= 1900) {\n return 1\n }\n if (n >= 1600) {\n return 2\n }\n if (n>= 1400) {\n return 3\n }\n return 4;\n}\n\nconst processData = (lines) => {\n let n = +lines[0];\n for (let i=1; i<=n; i++) {\n let num = +lines[i]\n console.log(`Division ${getDivison(num)}`)\n }\n \n}\n\nlet i = []\nprocess.stdin.on('data', c => i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar rating = nextInt();\r\n\t\tvar S = \"Division \";\r\n\t\tif(rating <= 1399){\r\n\t\t\tS += 4;\r\n\t\t}else if(1400 <= rating && rating <= 1599){\r\n\t\t\tS += 3;\r\n\t\t}else if(1600 <= rating && rating <= 1899){\r\n\t\t\tS += 2;\r\n\t\t}else{\r\n\t\t\tS += 1;\r\n\t\t}\r\n\t\tmyout(S);\r\n\t}\r\n}\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (a)=>{\n if (a >= 1900) return 1;\n if (a >= 1600) return 2;\n if (a >= 1400) return 3;\n return 4;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let a = +readline();\n \n console.log(`Division ${calc(a)}`);\n }\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n >= 1900) {\n return 'Division 1'\n } else if (n >= 1600) {\n return 'Division 2'\n } else if (n >= 1400) {\n return 'Division 3'\n } else {\n return 'Division 4'\n }\n}\n"}], "negative_code": [{"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating >= 1900){\r\n\tprint(\"Divison 1\")\r\n}\r\nelse if (rating <= 1899 && rating >= 1600){\r\n\tprint(\"Divison 2\")\r\n}\r\n\r\nelse if (rating <= 1599 && rating >= 1400){\r\n\tprint(\"Divison 3\")\r\n}\r\nelse if(rating <= 1399){\r\n\tprint(\"Divison 4\")\r\n}\r\n}\r\n"}, {"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating >= 1900){\r\n\tprint(\"Divison 1\")\r\n}\r\nelse if (rating <= 1899 || rating >= 1600){\r\n\tprint(\"Divison 2\")\r\n}\r\n\r\nelse if (rating <= 1599 || rating >= 1400){\r\n\tprint(\"Divison 3\")\r\n}\r\nelse if(rating <= 1399){\r\n\tprint(\"Divison 4\")\r\n}\r\n}"}, {"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating >= 1900){\r\n\tprint(\"Divison 1\")\r\n}\r\nelse if (rating <= 1899 && rating >= 1600){\r\n\tprint(\"Divison 2\")\r\n}\r\n\r\nelse if (rating <= 1599 && rating >= 1400){\r\n\tprint(\"Divison 3\")\r\n}\r\nelse if(rating <= 1399){\r\n\tprint(\"Divison 4\")\r\n}\r\n}"}, {"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating >= 1900){\r\n\tprint(\"Divison 1\")\r\n}\r\nelse if (rating <= 1899 && rating >= 1600){\r\n\tprint(\"Divison 2\")\r\n}\r\n\r\nelse if (rating <= 1599 && rating >= 1400){\r\n\tprint(\"Divison 3\")\r\n}\r\nelse{\r\n\tprint(\"Divison 4\")\r\n}\r\n}"}, {"source_code": "var len = parseInt(readline());\r\nvar i=0;\r\nvar rating;\r\nfor(i=0; i < len; i++){\r\n rating = parseInt(readline());\r\nif (rating <= 1900){\r\n\tprint(\"Divison 1\")\r\n}\r\nelse if (rating <= 1899 && rating >= 1600){\r\n\tprint(\"Divison 2\")\r\n}\r\n\r\nelse if (rating <= 1599 && rating >= 1400){\r\n\tprint(\"Divison 3\")\r\n}\r\nelse{\r\n\tprint(\"Divison 4\")\r\n}\r\n}"}, {"source_code": "const linesCount = readline();\r\n\r\nfor(x = 0; x < +linesCount; x++) {\r\n var curLine = parseInt(readline());\r\n print(curLine, typeof curLine);\r\n if (curLine >= 1900) {\r\n print('Division 1');\r\n } else if (curLine >= 1600) {\r\n print('Division 2');\r\n } else if (curLine >= 1400) {\r\n print('Division 3');\r\n } else {\r\n print('Division 4');\r\n }\r\n}"}, {"source_code": "var testCase = +readline()\r\nfor (var i = 0; i < testCase; i++) {\r\n var sequence = +readline()\r\n if (sequence > 1900) {\r\n print(\"Division 1\")\r\n } else if (sequence >= 1600 && sequence <= 1899) {\r\n print(\"Division 2\")\r\n } else if (sequence >= 1400 && sequence <= 1599) {\r\n print(\"Division 3\")\r\n } else {\r\n print(\"Division 4\")\r\n }\r\n}"}, {"source_code": "var num=parseInt(readline());\r\nvar arr=[];\r\nfor(var i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var rating = lines[j]\n if(1900 < rating){\n console.log('Division 1')\n }else if(1600 < rating && rating < 1899){\n console.log('Division 2')\n }else if(1400 < rating && rating < 1599){\n console.log('Division 3')\n }else if(rating < 1399){\n console.log('Division 4')\n }\n }\n});\n "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var rating = lines[j]\n if(1900 < rating){\n console.log('Division 1')\n }else if(1600 < rating && rating < 1899){\n console.log('Division 2')\n }else if(1400 < rating < 1599){\n console.log('Division 3')\n }else if(rating < 1399){\n console.log('Division 4')\n }\n }\n});\n "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var rating = lines[j]\n if(1900 < rating){\n console.log('Division 1')\n }else if(1600 < rating && rating < 1899){\n console.log('Division 2')\n }else if(1400 < rating < 1599){\n console.log('Division 3')\n }else if(1399 > rating){\n console.log('Division 4')\n }\n }\n});\n "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var rating = lines[j]\n if(1900 < rating){\n console.log('Division 1')\n }else if(1600 < rating && rating < 1899){\n console.log('Division 1')\n }else if(1400 < rating < 1599){\n console.log('Division 1')\n }else if(1399 > rating){\n console.log('Division 1')\n }\n }\n});\n "}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const rating = Number(d);\n if (rating <= 1399) {\n console.log(\"Division 4\");\n } else if (rating >= 1400 && rating <= 1599) {\n console.log(\"Divison 3\");\n } else if (rating >= 1600 && rating <= 1899) {\n console.log(\"Division 2\");\n } else {\n console.log(\"Division 1\");\n }\n\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n) {\r\n if (n < 1400) {\r\n console.log('Division4');\r\n } else if (n < 1600) {\r\n console.log('Division3');\r\n } else if (n < 1900) {\r\n console.log('Division2');\r\n } else {\r\n console.log('Division1');\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n solve(n);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, m, A)=>{\n if (n<=1399)\n return 4;\n if (n<=1599)\n return 3;\n if (n<=1899)\n return 2;\n return 1\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, m] = ra();\n L('Ans:')\n print(calc(n, m));\n }\n}\n \nE.calc = calc;"}], "src_uid": "020c7b64688736ecc5e97d17df2c2605"} {"source_code": "\"use strict\";\r\n\r\n// start below this line\r\nvar line = readline().split(\" \");\r\nvar n = parseInt(line[0], 10);\r\nvar m = parseInt(line[1], 10);\r\nvar bigK = parseInt(line[2], 10);\r\n\r\nif (bigK % 2 === 1) {\r\n for (var _ = 0; _ < n; ++_) {\r\n print(new Array(m).fill(-1).join(\" \"));\r\n }\r\n} else {\r\n var a = new Array(n);\r\n\r\n for (var _2 = 0; _2 < n; ++_2) {\r\n a[_2] = readline()\r\n .split(\" \")\r\n .map(function (v) {\r\n return parseInt(v, 10);\r\n });\r\n }\r\n\r\n var b = new Array(n - 1);\r\n\r\n for (var _3 = 0; _3 < n - 1; ++_3) {\r\n b[_3] = readline()\r\n .split(\" \")\r\n .map(function (v) {\r\n return parseInt(v, 10);\r\n });\r\n }\r\n\r\n var x = new Array(n).fill(0).map(function () {\r\n return new Array(m).fill(0);\r\n });\r\n bigK >>= 1;\r\n\r\n for (var k = 1; k <= bigK; ++k) {\r\n var y = new Array(n).fill(0).map(function () {\r\n return new Array(m).fill(1e8);\r\n });\r\n\r\n for (var i = 0; i < n; ++i) {\r\n for (var j = 0; j < m; ++j) {\r\n if (i > 0) {\r\n y[i][j] = x[i - 1][j] + 2 * b[i - 1][j];\r\n }\r\n\r\n if (i < n - 1) {\r\n y[i][j] = Math.min(y[i][j], x[i + 1][j] + 2 * b[i][j]);\r\n }\r\n\r\n if (j > 0) {\r\n y[i][j] = Math.min(y[i][j], x[i][j - 1] + 2 * a[i][j - 1]);\r\n }\r\n\r\n if (j < m - 1) {\r\n y[i][j] = Math.min(y[i][j], x[i][j + 1] + 2 * a[i][j]);\r\n }\r\n }\r\n }\r\n\r\n x = y;\r\n }\r\n\r\n for (var _i = 0; _i < n; ++_i) {\r\n print(x[_i].join(\" \"));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n writeArray(arr) {\n arr.forEach((a) => {\n this.write(a);\n });\n this.writeLine('');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction make2dArray(a, b, fill) {\n return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve() { }\nfunction main() {\n try {\n let n = io.nextNum();\n let m = io.nextNum();\n let k = io.nextNum();\n let rightCost = [];\n let downCost = [];\n for (let i = 0; i < n; i++) {\n rightCost.push([]);\n for (let j = 0; j < m - 1; j++) {\n rightCost[i][j] = io.nextNum();\n }\n }\n for (let i = 0; i < n - 1; i++) {\n downCost.push([]);\n for (let j = 0; j < m; j++) {\n downCost[i][j] = io.nextNum();\n }\n }\n if (k % 2 === 1) {\n let arr = Array.from({ length: m }).fill(-1);\n for (let i = 0; i < n; i++) {\n io.writeArray(arr);\n }\n io.flush();\n return;\n }\n let dp = [];\n const printStep = (step, mul = 1) => {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n io.write(dp[i][j][step] * mul);\n }\n io.writeLine('');\n }\n io.writeLine('');\n };\n const getXCost = (i, j) => {\n var _a, _b;\n return (_b = (_a = rightCost[i]) === null || _a === void 0 ? void 0 : _a[j]) !== null && _b !== void 0 ? _b : Infinity;\n };\n const getYCost = (i, j) => {\n var _a, _b;\n return (_b = (_a = downCost[i]) === null || _a === void 0 ? void 0 : _a[j]) !== null && _b !== void 0 ? _b : Infinity;\n };\n // console.log({ rightCost, downCost });\n for (let i = 0; i < n; i++) {\n dp[i] = [];\n for (let j = 0; j < m; j++) {\n dp[i][j] = [];\n dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));\n // console.log({\n // i,\n // j,\n // right: getXCost(i, j),\n // left: getXCost(i - 1, j),\n // down: getYCost(i, j),\n // up: getYCost(i, j - 1),\n // min: dp[i][j][1],\n // });\n }\n }\n const getDp = (i, j, l) => {\n var _a, _b, _c;\n return (_c = (_b = (_a = dp[i]) === null || _a === void 0 ? void 0 : _a[j]) === null || _b === void 0 ? void 0 : _b[l]) !== null && _c !== void 0 ? _c : Infinity;\n };\n // printStep(1);\n let target = k / 2;\n // console.log(dp);\n for (let l = 2; l <= target; l++) {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));\n }\n }\n }\n // for (let j = 0; j < m; j++) {\n // for (let i = 0; i < n; i++) {\n // io.write(dp[i][j][2]);\n // }\n // io.writeLine('');\n // }\n // io.writeLine('');\n printStep(target, 2);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n writeArray(arr) {\n arr.forEach((a) => {\n this.write(a);\n });\n this.writeLine('');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction make2dArray(a, b, fill) {\n return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve() { }\nfunction main() {\n try {\n let n = io.nextNum();\n let m = io.nextNum();\n let k = io.nextNum();\n let rightCost = [];\n let downCost = [];\n for (let i = 0; i < n; i++) {\n rightCost.push([]);\n for (let j = 0; j < m - 1; j++) {\n rightCost[i][j] = io.nextNum();\n }\n }\n for (let i = 0; i < n - 1; i++) {\n downCost.push([]);\n for (let j = 0; j < m; j++) {\n downCost[i][j] = io.nextNum();\n }\n }\n if (k % 2 === 1) {\n let arr = Array.from({ length: m }).fill(-1);\n for (let i = 0; i < n; i++) {\n io.writeArray(arr);\n }\n io.flush();\n return;\n }\n let dp = [];\n const printStep = (step, mul = 1) => {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n io.write(dp[i][j][step] * mul);\n }\n io.writeLine('');\n }\n io.writeLine('');\n };\n const getXCost = (i, j) => {\n if (!rightCost[i]) {\n return Infinity;\n }\n return rightCost[i][j] || Infinity;\n };\n const getYCost = (i, j) => {\n if (!downCost[i]) {\n return Infinity;\n }\n return downCost[i][j] || Infinity;\n };\n // console.log({ rightCost, downCost });\n for (let i = 0; i < n; i++) {\n dp[i] = [];\n for (let j = 0; j < m; j++) {\n dp[i][j] = [];\n dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));\n // console.log({\n // i,\n // j,\n // right: getXCost(i, j),\n // left: getXCost(i - 1, j),\n // down: getYCost(i, j),\n // up: getYCost(i, j - 1),\n // min: dp[i][j][1],\n // });\n }\n }\n const getDp = (i, j, l) => {\n if (!dp[i]) {\n return Infinity;\n }\n if (!dp[i][j]) {\n return Infinity;\n }\n return dp[i][j][l];\n };\n // printStep(1);\n let target = k / 2;\n // console.log(dp);\n for (let l = 2; l <= target; l++) {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));\n }\n }\n }\n // for (let j = 0; j < m; j++) {\n // for (let i = 0; i < n; i++) {\n // io.write(dp[i][j][2]);\n // }\n // io.writeLine('');\n // }\n // io.writeLine('');\n printStep(target, 2);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}], "negative_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n writeArray(arr) {\n arr.forEach((a) => {\n this.write(a);\n });\n this.writeLine('');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction make2dArray(a, b, fill) {\n return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve() { }\nfunction main() {\n try {\n let n = io.nextNum();\n let m = io.nextNum();\n let k = io.nextNum();\n let rightCost = [];\n let downCost = [];\n for (let i = 0; i < n; i++) {\n rightCost.push([]);\n for (let j = 0; j < m - 1; j++) {\n rightCost[i][j] = io.nextNum();\n }\n }\n for (let i = 0; i < n - 1; i++) {\n downCost.push([]);\n for (let j = 0; j < m; j++) {\n downCost[i][j] = io.nextNum();\n }\n }\n if (k % 2 === 1) {\n let arr = Array.from({ length: m }).fill(-1);\n for (let i = 0; i < n; i++) {\n io.writeArray(arr);\n }\n io.flush();\n return;\n }\n let dp = [];\n const printStep = (step) => {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n io.write(dp[i][j][step]);\n }\n io.writeLine('');\n }\n io.writeLine('');\n };\n const getXCost = (i, j) => {\n if (!rightCost[i]) {\n return Infinity;\n }\n return rightCost[i][j] || Infinity;\n };\n const getYCost = (i, j) => {\n if (!downCost[i]) {\n return Infinity;\n }\n return downCost[i][j] || Infinity;\n };\n // console.log({ rightCost, downCost });\n for (let i = 0; i < n; i++) {\n dp[i] = [];\n for (let j = 0; j < m; j++) {\n dp[i][j] = [];\n dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));\n // console.log({\n // i,\n // j,\n // right: getXCost(i, j),\n // left: getXCost(i - 1, j),\n // down: getYCost(i, j),\n // up: getYCost(i, j - 1),\n // min: dp[i][j][1],\n // });\n }\n }\n const getDp = (i, j, l) => {\n if (!dp[i]) {\n return Infinity;\n }\n if (!dp[i][j]) {\n return Infinity;\n }\n return dp[i][j][l];\n };\n // printStep(1);\n let target = k / 2;\n // console.log(dp);\n for (let l = 2; l <= target; l++) {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));\n }\n }\n }\n // for (let j = 0; j < m; j++) {\n // for (let i = 0; i < n; i++) {\n // io.write(dp[i][j][2]);\n // }\n // io.writeLine('');\n // }\n // io.writeLine('');\n printStep(target);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n writeArray(arr) {\n arr.forEach((a) => {\n this.write(a);\n });\n this.writeLine('');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\nfunction make2dArray(a, b, fill) {\n return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve() { }\nfunction main() {\n try {\n let n = io.nextNum();\n let m = io.nextNum();\n let k = io.nextNum();\n let rightCost = make2dArray(n - 1, m, 0);\n let downCost = make2dArray(n, m - 1, 0);\n for (let i = 0; i < n - 1; i++) {\n for (let j = 0; j < m; j++) {\n rightCost[i][j] = io.nextNum();\n }\n }\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m - 1; j++) {\n downCost[i][j] = io.nextNum();\n }\n }\n if (k % 2 === 1) {\n let arr = Array.from({ length: m }).fill(-1);\n for (let i = 0; i < n; i++) {\n io.writeArray(arr);\n }\n io.flush();\n return;\n }\n let dp = [];\n const getXCost = (i, j) => {\n if (i < 0 || j < 0 || i >= n - 1 || j >= m) {\n return Infinity;\n }\n return rightCost[i][j];\n };\n const getYCost = (i, j) => {\n if (i < 0 || j < 0 || i >= n || j >= m - 1) {\n return Infinity;\n }\n return downCost[i][j] || Infinity;\n };\n // console.log({ rightCost, downCost });\n for (let i = 0; i < n; i++) {\n dp[i] = [];\n for (let j = 0; j < m; j++) {\n dp[i][j] = [];\n dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i - 1, j), getYCost(i, j), getYCost(i, j - 1));\n // console.log({\n // i,\n // j,\n // right: getXCost(i, j),\n // left: getXCost(i - 1, j),\n // down: getYCost(i, j),\n // up: getYCost(i, j - 1),\n // min: dp[i][j][1],\n // });\n }\n }\n const getDp = (i, j, l) => {\n if (!dp[i]) {\n return Infinity;\n }\n if (!dp[i][j]) {\n return Infinity;\n }\n return dp[i][j][l];\n };\n let target = k / 2;\n // console.log(dp);\n for (let l = 2; l <= target; l++) {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n dp[i][j][l] = Math.min(getDp(i - 1, j, l - 1) + getXCost(i - 1, j), getDp(i + 1, j, l - 1) + getXCost(i, j), getDp(i, j - 1, l - 1) + getYCost(i, j - 1), getDp(i, j + 1, l - 1) + getYCost(i, j));\n }\n }\n }\n // for (let j = 0; j < m; j++) {\n // for (let i = 0; i < n; i++) {\n // io.write(dp[i][j][2]);\n // }\n // io.writeLine('');\n // }\n // io.writeLine('');\n for (let j = 0; j < m; j++) {\n for (let i = 0; i < n; i++) {\n io.write(dp[i][j][target] * 2);\n }\n io.writeLine('');\n }\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}], "src_uid": "7b13ee633c81abdcf912542ba1779a45"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;st-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=s.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),s.default.writeFileSync(\"output.txt\",l),console.log(l),s.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{i=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;re[0]-t[0])).transpose(),o=0,i=r[0];for(let e=0;e{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let x = io.nextNumbersMatrix(2).transpose()\n// \n// let [a, b] = x.sort((a, b) => b[0] - a[0]).transpose()\n// \n// let s = 0\n// let best = a[0]\n// \n// // io.debug(a)\n// // io.debug(b)\n// \n// for (let i = 0; i < n; ++i) {\n// if (s + b[i] < a[i]) {\n// s += b[i]\n// best = Math.max(s, a[i + 1] || 0)\n// } else {\n// break\n// }\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;st-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=s.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),s.default.writeFileSync(\"output.txt\",l),console.log(l),s.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{i=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;re[0]-t[0])).transpose(),o=0,i=r[0];for(let e=0;e{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// \n// let x = io.nextNumbersMatrix(2).transpose()\n// \n// let [a, b] = x.sort((a, b) => b[0] - a[0]).transpose()\n// \n// let s = 0\n// let best = a[0]\n// \n// // io.debug(a)\n// // io.debug(b)\n// \n// for (let i = 0; i < n; ++i) {\n// if (s + b[i] < a[i]) {\n// s += b[i]\n// best = [s, a[i + 1] || 0].max()\n// } else {\n// break\n// }\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n let curLine = 0\n const T = parseInt(lines[curLine++])\n for (let t = 0; t < T; t++) {\n const n = parseInt(lines[curLine++])\n const a = parseIntArray(lines[curLine++])\n const b = parseIntArray(lines[curLine++])\n const restaurant = [...new Array(n)]\n .map((_, idx) => [a[idx], b[idx]])\n .sort(([xa, xb], [ya, yb]) => {\n if (xa !== ya) {\n if (xa < ya) return -1\n if (xa > ya) return 1\n return 0\n }\n if (xb < yb) return -1\n if (xb > yb) return 1\n return 0\n })\n\n let accSum = b.reduce((x, y) => x + y, 0n)\n let ans = accSum\n\n restaurant.forEach(([ra, rb]) => {\n accSum -= rb\n const cand = ra > accSum ? ra : accSum\n ans = ans < cand ? ans: cand\n })\n\n console.log(ans.toString())\n } \n})\n\nconst parseIntArray = (line) => line.split(' ').map((x) => BigInt(x))\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = n;\n let res = [4*n];\n let num = 4*n;\n n -= 1;\n let i = 3;\n let f = 2;\n while(n > 0){\n num -= 2;\n let flag = false;\n for(let j = res.length-1; j >= 0; j--){\n if(res[j] % num === 0){\n flag = true;\n break;\n }\n }\n if(!flag){\n res.push(num);\n n--;\n }\n }\n\n console.log(res.join(' '));\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b] = ti(readline().split(' '));\n let s = readline().split('');\n //console.log(s.length);\n let x = [];\n let i = 0;\n while(i < s.length && s[i] !== '1'){\n i++;\n }\n\n while(i < s.length){\n if(s[i] === '1')\n x.push(a);\n while(i < s.length && s[i] === '1'){\n i++;\n }\n \n if(i < s.length && s[i] === '0'){\n x.push(s[i]);\n }\n i++;\n }\n\n i = 0;\n let sum = x.length !== 0 ? a : 0;\n while(i < x.length){\n if(pi(x[i]) === a){\n let count = 0;\n i++;\n while(i < x.length && pi(x[i]) === 0){\n count += b;\n i++;\n }\n\n if(i < x.length){\n sum = Math.min(sum+a, sum+count);\n }\n }\n }\n\n console.log(sum);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n let pair = new Array(n);\n for(let i = 0; i < n; i++){\n pair[i] = [a[i],b[i]];\n }\n pair.sort((a,b) => a[0]-b[0]);\n let x = new Array(n);\n for(let i = n-1; i >= 0; i--){\n if(i === n-1){\n x[i] = pair[i][1];\n }else{\n x[i] = x[i+1] + pair[i][1];\n }\n }\n\n let min = 9999999999999;\n for(let i = 0; i < n-1; i++){\n min = Math.min(min, Math.max(pair[i][0], x[i+1]));\n }\n\n console.log(Math.min(min, pair[n-1][0], x[0]));\n }\n}"}, {"source_code": "function C1443(a1, b1) {\n var n = a1.length;\n var c = [];\n\n for (var i = 0; i < n; i++) {\n c.push([a1[i], b1[i]]);\n }\n\n c.sort(function (p, q) {\n return p[0] - q[0];\n });\n\n for (var _i = n - 2; _i >= 0; _i--) {\n c[_i][1] += c[_i + 1][1];\n }\n\n var ans = Math.min(c[n - 1][0], c[0][1]);\n\n for (var _i2 = n - 2; _i2 >= 0; _i2--) {\n ans = Math.min(ans, Math.max(c[_i2][0], c[_i2 + 1][1]));\n }\n\n return ans;\n}\n\nfunction execute(readline, print) {\n var iter = {\n next: function next() {\n return readline().trim();\n }\n };\n\n var split = function split(string) {\n return string.split(' ').map(Number);\n };\n\n var t = Number(iter.next());\n\n while (t--) {\n iter.next();\n var arr1 = split(iter.next());\n var arr2 = split(iter.next());\n print(C1443(arr1, arr2));\n }\n}\n\nexecute(readline, print)\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const other = readLine().split(\" \").map(Number);\n const own = readLine().split(\" \").map(Number);\n const data = [];\n for (let i = 0; i < len; i++) {\n data.push([other[i], own[i]]);\n }\n data.sort((a, b) => b[0] - a[0]);\n let [ownTime, otherTime] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n let [r, p] = data[i];\n if (ownTime + p < r) ownTime += p;\n else {\n otherTime = r;\n break;\n }\n }\n console.log(Math.max(ownTime, otherTime));\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const other = readLine().split(\" \").map(Number);\n const own = readLine().split(\" \").map(Number);\n let [ownTime, otherTime] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n let [r, p] = [other[i], own[i]];\n if (ownTime + p < Math.max(otherTime, r)) {\n ownTime += p;\n } else {\n otherTime = r;\n }\n }\n console.log(Math.max(ownTime, otherTime));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const other = readLine().split(\" \").map(Number);\n const own = readLine().split(\" \").map(Number);\n let [ownTime, otherTime] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n let [r, p] = [other[i], own[i]];\n if (ownTime + p < Math.max(otherTime, r)) {\n ownTime += p;\n } else {\n otherTime = Math.max(otherTime, r);\n }\n }\n console.log(Math.max(ownTime, otherTime));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const other = readLine().split(\" \").map(Number);\n const own = readLine().split(\" \").map(Number);\n let [ownTime, otherTime] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n let [r, p] = [other[i], own[i]];\n if (ownTime + p < Math.max(otherTime, r)) {\n ownTime += p;\n } else {\n otherTime = r;\n }\n }\n const res = Math.max(ownTime, otherTime);\n let ownCount = 0;\n for (let i = 0; i < len; i++) {\n ownCount += own[i];\n }\n\n console.log(Math.min(res, ownCount, Math.max(...other)));\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let x = n;\n let res = [4*n];\n let num = 4*n;\n n -= 1;\n let i = 3;\n let f = 2;\n while(n > 0){\n num -= 2;\n let flag = false;\n for(let j = res.length-1; j >= 0; j--){\n if(res[j] % num === 0){\n flag = true;\n break;\n }\n }\n if(!flag){\n res.push(num);\n n--;\n }\n }\n\n console.log(res.join(' '));\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b] = ti(readline().split(' '));\n let s = readline().split('');\n //console.log(s.length);\n let x = [];\n let i = 0;\n while(i < s.length && s[i] !== '1'){\n i++;\n }\n\n while(i < s.length){\n if(s[i] === '1')\n x.push(a);\n while(i < s.length && s[i] === '1'){\n i++;\n }\n \n if(i < s.length && s[i] === '0'){\n x.push(s[i]);\n }\n i++;\n }\n\n i = 0;\n let sum = x.length !== 0 ? a : 0;\n while(i < x.length){\n if(pi(x[i]) === a){\n let count = 0;\n i++;\n while(i < x.length && pi(x[i]) === 0){\n count += b;\n i++;\n }\n\n if(i < x.length){\n sum = Math.min(sum+a, sum+count);\n }\n }\n }\n\n console.log(sum);\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n a.sort((a,b) => a-b);\n for(let i = n-2; i >= 0; i--)\n b[i] += b[i+1];\n\n let min = 9999999999999;\n for(let i = 0; i < n-1; i++){\n min = Math.min(min, Math.max(a[i], b[i+1]));\n }\n\n console.log(Math.min(min, a[n-1], b[0]));\n }\n}"}], "src_uid": "254cb444b9bdfa5e177adad23b7e814a"} {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n// var input = \"6 180\".split(\" \");\r\n// var players = \"90 80 70 60 50 100 2\".split(\" \");\r\n players = players.sort((a, b) => b - a);\r\n let minPoints = input[1],\r\n left = 0,\r\n right = players.length;\r\n while (left + Math.floor(minPoints / players[left]) < right) {\r\n right -= Math.floor(minPoints / players[left]);\r\n left++;\r\n }\r\n console.log(left);\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n /*\r\n\r\n */\r\n let a = readLine().trim().split(' ').map(string => {return parseInt(string.trim());});\r\n let N = a[0], D = a[1];\r\n a = readLine().trim().split(' ').map(string => {return parseInt(string.trim());});\r\n a.sort((a, b) => b - a); // For descending sort\r\n let i=0,count=0;\r\n while(N>0){\r\n N-=Math.ceil(D/a[i]);\r\n if(Math.ceil(D/a[i])*a[i] == D){\r\n N-=1;\r\n }\r\n // console.log(D,a[i],N);\r\n i++;\r\n }\r\n if(N<0){\r\n i--;\r\n }\r\n console.log(i);\r\n }\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const a = await rns();\r\n a.sort((a, b) => a - b);\r\n let left = 0,\r\n right = n - 1;\r\n let res = 0;\r\n while (left <= right) {\r\n let num = a[right];\r\n while (left < right && num <= m) {\r\n num += a[right];\r\n left++;\r\n }\r\n if (num > m) res++;\r\n right--;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n \r\n \r\nvar num = readline().split(\" \").map(x => parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\nlet i=0;let j=players.length;\r\n \r\nwhile(true){\r\n if(j===0||j {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction main(){\r\n \r\n \r\nvar num = readline().split(\" \").map(x => parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\nlet i=0;let j=players.length;\r\n \r\nwhile(true){\r\n if(j===0||j parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.length parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.length parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.length parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.lengthd){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.length parseInt(x));\r\n \r\nvar n=num[0];\r\nvar d=num[1];\r\nvar players= readline().split(\" \").map(x => parseInt(x));\r\nplayers.sort(function(a, b){return b-a});\r\nvar sol=0;\r\n \r\nfunction bigger(p,d){\r\n if(p>d){return 1;}\r\n else {\r\n if(d%p===0){return d/p+1;}\r\n else{return Math.ceil(d/p)}\r\n }\r\n}\r\n \r\nwhile(true){\r\n if(players.length {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n // var input = \"6 180\".split(\" \");\r\n // var players = \"90 80 70 60 50 100 2 2\".split(\" \");\r\n players = players.sort((a, b) => b - a);\r\n let minPoints = input[1],\r\n left = 0,\r\n right = players.length;\r\n while (left + Math.floor(minPoints / players[left]) < right) {\r\n console.log(left, right, players[left]);\r\n right -= Math.floor(minPoints / players[left]);\r\n left++;\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n // var input = \"60 180\".split(\" \");\r\n // var players = \"90 80 70 60 50 100\".split(\" \");\r\n let minPoints = input[1];\r\n let counter = 0;\r\n players = players.sort((a, b) => b - a);\r\n while (players.length > Math.ceil(minPoints / players[0])) {\r\n let wannaPlayer = Math.floor(minPoints / players[0]);\r\n players.splice(0, 1);\r\n for (let i = 0; i < wannaPlayer; i++) {\r\n players.length--;\r\n }\r\n counter++;\r\n }\r\n console.log(counter);\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// ********** Code Start **********\r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n// var input = \"6 180\".split(\" \");\r\n// var players = \"90 80 70 60 50 100 2 2\".split(\" \");\r\n let leng = players.length;\r\n let minPoints = input[1];\r\n players = players.sort((a, b) => b - a);\r\n let i = 0;\r\n while (leng > Math.ceil(minPoints / players[i])) {\r\n // console.log(\"leng befor is \" + leng);\r\n // console.log(\"player\" + i + \"=\" + players[i]);\r\n leng -= Math.ceil(minPoints / players[i]);\r\n i++;\r\n }\r\n console.log(i);\r\n}\r\n// main();\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// ********** Code Start **********\r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n // var input = \"6 180\".split(\" \");\r\n // var players = \"100 90 80 70 60 50 2 2\".split(\" \");\r\n let leng = players.length;\r\n let minPoints = input[1];\r\n let counter = 0;\r\n players = players.sort((a, b) => b - a);\r\n let i = 0;\r\n while (leng > 0) {\r\n // console.log(\"leng befor is \" + leng);\r\n // console.log(\"player\" + i + \"=\" + players[i]);\r\n leng -= Math.ceil(minPoints / players[i]);\r\n i++;\r\n }\r\n console.log(i - 1);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n \r\nfunction main() {\r\n let input = readline().split(\" \");\r\n let players = readline().split(\" \");\r\n let minPoints = input[1];\r\n let counter = 0;\r\n players = players.sort((a, b) => b - a);\r\n while (players.length - Math.ceil(minPoints / players[0]) > 0) {\r\n let wannaPlayer = Math.floor(minPoints / players[0]);\r\n players.splice(0, 1);\r\n for (let i = 0; i < wannaPlayer; i++) {\r\n players.length--;\r\n }\r\n counter++;\r\n }\r\n console.log(counter);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var input = readline().split(\" \");\r\n var players = readline().split(\" \");\r\n let playersLength = input[0];\r\n let minPoints = input[1];\r\n let counter = 0;\r\n players = players.sort((a, b) => b - a);\r\n while (players.length - Math.floor(minPoints / players[0]) > 0) {\r\n let wannaPlayer = Math.floor(minPoints / players[0]);\r\n players.splice(0, 1);\r\n for (let i = 0; i < wannaPlayer; i++) {\r\n players.length--;\r\n }\r\n counter++;\r\n }\r\n return counter;\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n /*\r\n\r\n */\r\n let a = readLine().trim().split(' ').map(string => {return parseInt(string.trim());});\r\n let N = a[0], D = a[1];\r\n a = readLine().trim().split(' ').map(string => {return parseInt(string.trim());});\r\n a.sort((a, b) => b - a); // For descending sort\r\n let i=0;\r\n while(N>0){\r\n if(D>a[i]){\r\n N-=Math.ceil(D/a[i]);\r\n }else{\r\n N-=1;\r\n }\r\n i++;\r\n }\r\n i--;\r\n console.log(i);\r\n }\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nasync function solve(r) {\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const a = await rns();\r\n a.sort((a, b) => a - b);\r\n let left = 0,\r\n right = n - 1;\r\n let res = 0;\r\n while (left <= right) {\r\n let num = a[right];\r\n while (left < right && num < m) {\r\n num += a[right];\r\n left++;\r\n }\r\n if (num >= m) res++;\r\n right--;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "c5d930c01af7470ef9353063213c5c54"} {"source_code": "const readline = require('readline');\n\nlet input = [];\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nrl.on('line', lineInput => {\n\tinput.push(lineInput);\n});\n\nrl.on('close', () => {\n\tconst test = parseInt(input[0]);\n\tfor (let t=0; t < test; t++) {\n\t\tlet inputNum = input[2*t+1].split(' ').map((a) => parseInt(a));\n\t\tlet arr = input[2*t+2].split(' ').map((a) => parseInt(a));\n\t\tconsole.log(solution(inputNum, arr));\n\t}\n});\n\nfunction solution(nums, arr) {\n\tlet n = nums[0];\n\tlet bul = nums[1];\n\tarr = arr.sort((a, b) => a-b);\n\tlet sum = 0;\n\tlet count = 0;\n\tfor (let j=n-1; j>=0; j--) {\n\t\tsum += arr[j];\n\t\tif (sum/(n-j) < bul) {\n\t\t\tbreak;\n\t\t}\n\t\tcount += 1;\n\t}\n\treturn count;\n}", "positive_code": [{"source_code": "'use strict';\n\nconst rl = require('readline')\n .createInterface({ input: process.stdin, output: process.stdout });\nconst write = (...args) => {\n process.stdout.write(args.join(' '));\n};\n\nconst lines = [];\nrl.on('line', line => {\n lines.push(line);\n});\n\nrl.on('close', main);\n\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n \nfunction main() {\n const times = parseInt(readline());\n for(let t = 0; t < times; ++t) {\n const rich = parseInt(readline().split(' ')[1]);\n const moneys = readline().split(' ').map(e => parseInt(e));\n moneys.sort((a,b) => b - a);\n let sum = 0;\n let result = 0;\n for(let i = 0; i < moneys.length; ++i) {\n if((sum + moneys[i])/(result + 1) >= rich) {\n sum = sum + moneys[i];\n result = result + 1;\n } else {\n break;\n }\n }\n write(`${result}\\n`);\n }\n}\n\n// solved by: asmjaime\n"}, {"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n n = ip[0];\n x = ip[1];\n poor = [];\n sum = 0;\n readline().split(' ').map(Number).forEach(a => {\n if (a >= x){\n sum += a;\n } else {\n poor.push(a);\n }\n });\n \n poor.sort((a,b)=>b-a);\n \n count = n - poor.length;\n for (i=0;i= x){\n sum += poor[i];\n count++;\n } else {\n break;\n }\n }\n print(count);\n}"}, {"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, x, a) {\n a.sort((a, b) => b - a);\n let sum = 0;\n for(let i = 0; i < n; ++i) {\n sum += a[i];\n if (sum < x * (i + 1)) return i;\n }\n return n;\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const [n, x] = readLine();\n const a = readLine();\n console.log(solve(n, x, a));\n }\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var x = one[1];\n var sum = 0;\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn a - b;\n });\n for(var j = 0; j < n; j++){\n sum += list[j];\n }\n for(var j = 0; j < n; j++){\n if(sum / (n - j) >= x){\n output[i] = n - j;\n break;\n }\n sum -= list[j];\n }\n if(output[i] == null){\n output[i] = 0;\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\nvar lines=[],idx=0;\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close',main);\nfunction read(){\n return lines[idx++];\n}\nfunction main(){\n var times=parseInt(read());\n while(times--){\n var tmp=read().split(' ');\n var size=parseInt(tmp[0]),mon=parseInt(tmp[1]);\n var arr=read().split(' ').map(s=>parseInt(s));\n arr.sort((a,b)=>{\n return b-a;\n });\n var avg=0,sum=0,num=0,ans=0;\n arr.forEach(idx=>{\n num++;\n if((sum+idx)/num>=mon){\n ans=num;\n }\n sum+=idx;\n avg=sum/num;\n });\n console.log(ans);\n }\n}"}, {"source_code": "var range = readline();\n\nfor(var i=0;i parseInt(x));\n var saving = readline().split(\" \").map(x => parseInt(x));\n \n saving.sort((a,b) => b - a);\n var minAverage = input[1];\n var sum = 0;\n var count = 0;\n\n for(var j=0;j= minAverage) {\n count++;\n } else {\n break;\n }\n }\n \n print(count);\n}\n"}], "negative_code": [{"source_code": "t = +readline();\nwhile (t-->0){\n ip = readline().split(' ').map(Number);\n n = ip[0];\n x = ip[1];\n poor = [];\n sum = 0;\n readline().split(' ').map(Number).forEach(a => {\n if (a >= x){\n sum += a;\n } else {\n poor.push(a);\n }\n })\n count = n - poor.length;\n for (i=0;i= x){\n sum += poor[i];\n count++;\n } else {\n break;\n }\n }\n print(count);\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var x = one[1];\n var sum = 0;\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn a - b;\n });\n for(var j = 0; j < n; j++){\n sum += list[j];\n }\n for(var j = 0; j < n; j++){\n if(sum / (n - j) >= x){\n output[i] = n - j;\n break;\n }\n sum -= list[i];\n }\n if(output[i] == null){\n output[i] = 0;\n }\n }\n myout(myconv(output,9));\n}\n"}], "src_uid": "51f922bb2c51f50b5c3b55725dd7766e"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n E();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b] = ti(readline().split(' '));\n\n if(a === b){\n console.log(0);\n continue;\n }\n\n let d = Math.abs(a-b);\n if(d <= 10){\n console.log(1);\n continue;\n }else{\n if(d % 10 !== 0)\n console.log(1 + Math.floor(d/10));\n else\n console.log(d / 10);\n }\n }\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [a,b,x,y,n] = ti(readline().split(' '));\n\n if(a > b){\n let temp = a;\n a = b;\n b = temp;\n temp = x;\n x = y;\n y = temp;\n }\n\n if(b - y >= n){\n b -= n;\n console.log(a*b);\n }else{\n n -= (b-y);\n b = y;\n if(a-x >= n){\n a -= n;\n }else{\n a = x;\n }\n\n console.log(a*b);\n }\n }\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x,y] = ti(readline().split(' '));\n\n let min = 99999999999999;\n let res = null;\n for(let i = 1; i <= x; i++){\n for(let j = 0; j <= y-x; j++){\n let inclX = false;\n let inclY = false;\n let op = new Array(n);\n for(let k = 0; k < n; k++){\n if(k === 0){\n op[k] = i;\n }else{\n op[k] = op[k-1] + j;\n }\n\n if(op[k] === x)\n inclX = true;\n \n if(op[k] === y)\n inclY = true;\n }\n\n if(inclX && inclY){\n if(min > op[n-1]){\n min = op[n-1];\n res = op;\n }\n }\n }\n }\n\n for(let num of res)\n console.log(num);\n }\n}\n\nfunction D(){\n let t = pi(readline());\n let getSum = (str) => {\n let sum = 0;\n for(let i = 0; i < str.length; i++){\n sum += pi(str[i]);\n }\n return sum;\n }\n\n while(t > 0){\n t--;\n\n let [n, s] = ti(readline().split(' '));\n let str = JSON.stringify(n);\n let sum = getSum(str);\n let count = 0;\n let p = 0;\n while(sum > s){\n let m = Math.pow(10, p+1);\n let num = pi(str.substring(str.length-1-p,str.length));\n count += (m-num);\n n += (m-num);\n let c = pi(str[str.length-1-p]);\n sum -= (c-1);\n p++;\n str = JSON.stringify(n);\n }\n\n console.log(count);\n }\n}\n\nfunction E(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let x = ti(readline().split(' '));\n let y = readline();\n x.sort((a,b) => a-b);\n let left = new Array(n);\n let right = new Array(n);\n let p1 = 0;\n let p2 = 0;\n\n if(n === 1){\n console.log(1);\n continue;\n }\n\n for(let i = 0; i < x.length; i++){\n while(p1 <= i && x[i] - x[p1] > k){\n p1++;\n }\n\n while(p2 < n && x[p2] - x[i] <= k){\n p2++;\n }\n\n p2 -= 1;\n\n left[i] = i-p1+1;\n right[i] = x[p2] - x[i] > k ? p2-i : p2-i+1;\n }\n // console.log(left);\n // console.log(right);\n\n for(let i = 1; i < n; i++){\n left[i] = Math.max(left[i], left[i-1]);\n }\n\n for(let i = n-2; i >= 0; i--){\n right[i] = Math.max(right[i], right[i+1]);\n }\n\n let max = 0;\n\n for(let i = 0; i < n-1; i++)\n max = Math.max(max, left[i] + right[i+1]);\n\n console.log(max);\n }\n}", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(1, t, i => {\n let [n, k] = inp.slice(r, r = r + 2);\n let x = inp.slice(r, r = r + n).sort((a, b) => a - b);\n let y = inp.slice(r, r = r + n);\n var f = []\n var start = 0;\n For(0, n - 1, i => {\n while (x[i] - x[start] > k) start++;\n f[i] = i - start + 1;\n });\n var fm = Arr(0, n - 1, (i, p) => Math.max(p, f[i]));\n var f2 = Arr(0, n - 1, i => f[i] + (fm[i - f[i]] || 0));\n console.log(Math.max(...f2));\n })\n})();"}], "negative_code": [], "src_uid": "ae4378fbdb863ed6c30aae5d22851531"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n a = a.map(num => num - 1);\r\n let res = [],\r\n set = new Set([...new Array(n).keys()]);\r\n const g = Array.from({\r\n length: n\r\n }, () => []);\r\n for (let [i, j] of a.entries()) {\r\n if (set.has(j)) {\r\n res[i] = j;\r\n set.delete(j);\r\n }\r\n g[j].push(i);\r\n }\r\n const nums = [...set];\r\n for (let i = 0; i < n; i++) {\r\n if (res[i] === undefined) {\r\n const num = nums.pop();\r\n if (num === i) {\r\n for (let j of g[a[i]]) {\r\n if (j !== i) {\r\n res[i] = a[i];\r\n res[j] = num;\r\n break;\r\n }\r\n }\r\n } else {\r\n res[i] = num;\r\n }\r\n }\r\n }\r\n let len = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (res[i] === a[i]) len++;\r\n }\r\n return `${len}\\n${res.map(num => num + 1).join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst taken = Array(n+1);\r\n\t\tconst asgnd = Array(n+1);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!taken[a[i]]) {\r\n\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\ttaken[a[i]] = true;\r\n\t\t\t\tans++;\r\n\t\t\t} \r\n\t\t}\r\n\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 1; i <= n ; i++)\r\n\t\t\tif (!taken[i]) avl.push(i);\r\n\r\n\t\tfor (let i = 1, k = 0; i <= n; i++) {\r\n\t\t\tif (!asgnd[i]) {\r\n\t\t\t\tconst x = avl.pop();\r\n\t\t\t\tif (i == x) {\r\n\t\t\t\t\tif (!avl.length) {\r\n\t\t\t\t\t\tlet j = 1;\r\n\t\t\t\t\t\twhile (a[j] != a[i] && j != i) j++;\r\n\t\t\t\t\t\tasgnd[j] = i;\r\n\t\t\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tasgnd[i] = avl.pop();\r\n\t\t\t\t\t\tavl.push(x);\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tasgnd[i] = x;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t\tconsole.log(asgnd.slice(1).join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst taken = Array(n+1);\r\n\t\tconst asgnd = Array(n+1);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!taken[a[i]]) {\r\n\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\ttaken[a[i]] = true;\r\n\t\t\t\tans++;\r\n\t\t\t} \r\n\t\t}\r\n\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 1; i <= n ; i++) {\r\n\t\t\tif (!taken[i]) {\r\n\t\t\t\tavl.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!asgnd[i]) {\r\n\t\t\t\tconst x = avl.pop();\r\n\t\t\t\tif (i == x) {\r\n\t\t\t\t\tif (!avl.length) {\r\n\t\t\t\t\t\tlet j = 1;\r\n\t\t\t\t\t\twhile (a[j] != a[i] && j != i) {\r\n\t\t\t\t\t\t\tj++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tasgnd[j] = i;\r\n\t\t\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tasgnd[i] = avl.pop();\r\n\t\t\t\t\t\tavl.push(x);\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tasgnd[i] = x;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t\tconsole.log(asgnd.slice(1).join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst taken = Array(n+1);\r\n\t\tconst asgnd = Array(n+1);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!taken[a[i]]) {\r\n\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\ttaken[a[i]] = true;\r\n\t\t\t\tans++;\r\n\t\t\t} \r\n\t\t}\r\n\r\n\t\tconst avl = Array(n+1);\r\n\t\tfor (let i = 1; i <= n ; i++) {\r\n\t\t\tif (!taken[i]) {\r\n\t\t\t\tavl.push(i);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!asgnd[i]) {\r\n\t\t\t\tconst x = avl.pop();\r\n\t\t\t\tif (i == x) {\r\n\t\t\t\t\tif (!avl.length) {\r\n\t\t\t\t\t\tlet j = 1;\r\n\t\t\t\t\t\twhile (a[j] != a[i] && j != i) {\r\n\t\t\t\t\t\t\tj++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tasgnd[j] = i;\r\n\t\t\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tasgnd[i] = avl.pop();\r\n\t\t\t\t\t\tavl.push(x);\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tasgnd[i] = x;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t\tconsole.log(asgnd.slice(1).join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.unshift(0);\r\n\r\n\t\tlet ans = 0;\r\n\t\tconst taken = Array(n+1);\r\n\t\tconst asgnd = Array(n+1);\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tif (!taken[a[i]]) {\r\n\t\t\t\tasgnd[i] = a[i];\r\n\t\t\t\ttaken[a[i]] = true;\r\n\t\t\t\tans++;\r\n\t\t\t} \r\n\t\t}\r\n\r\n\t\tconst avl = [];\r\n\t\tfor (let i = 1; i <= n ; i++)\r\n\t\t\tif (!taken[i]) avl.push(i);\r\n\r\n\t\tfor (let i = 1, k = 0; i <= n; i++) {\r\n\t\t\tif (!asgnd[i]) {\r\n\t\t\t\tconst x = avl.pop();\r\n\t\t\t\tif (i == x) {\r\n\t\t\t\t\t//if (!avl.length) {\r\n\t\t\t\t\t\t//let j = 1;\r\n\t\t\t\t\t\t//while (a[j] != a[i] && j != i) j++;\r\n\t\t\t\t\t\t//asgnd[j] = i;\r\n\t\t\t\t\t\t//asgnd[i] = a[i];\r\n\t\t\t\t\t//} else {\r\n\t\t\t\t\t\tasgnd[i] = avl.pop();\r\n\t\t\t\t\t\tavl.push(x);\r\n\t\t\t\t\t//}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tasgnd[i] = x;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t\tconsole.log(asgnd.slice(1).join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let res = [],\r\n set = new Set(Array.from({\r\n length: n\r\n }, (_, i) => i + 1));\r\n for (let [i, num] of a.entries()) {\r\n if (set.has(num)) {\r\n res[i] = num;\r\n set.delete(num);\r\n }\r\n }\r\n let len = n - set.size;\r\n const nums = [...set];\r\n for (let i = 0; i < n; i++) {\r\n if (res[i] === undefined) {\r\n res[i] = nums.pop();\r\n }\r\n }\r\n return `${len}\\n${res.join(' ')}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "89687dcbf37fc776b508252ddac8e8d4"} {"source_code": "n=+readline()\ndup={};\nwhile(n--) {\n s=readline();\n if (!dup[s]) {\n print('OK');\n dup[s]=1;\n } else {\n print(s+dup[s]);\n dup[s]=dup[s]+1;\n }\n}", "positive_code": [{"source_code": "\nvar a = parseInt( readline() );\n\nvar map = {};\n\nwhile(a--){\n\n\tvar name = readline();\n\tif( map.hasOwnProperty(name) ){\n\t\tmap[name]++;\n\t\tprint(name + map[name]);\n\t}else{\n\t\tprint('OK');\n\t\tmap[name] = 0;\n\t}\n}"}, {"source_code": "var n = +readline();\nvar obj = {};\n\nfor(i = 0; i < n; i++){\n\tinput = readline();\n\tif(input in obj){\n\t\tobj[input]++;\n\t\tprint(input + obj[input]);\n\t}\n\telse{\n\t\tobj[input] = 0;\n\t\tprint(\"OK\");\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar m = {};\nfor (var i = 0; i < n; i++) {\n var a = readline();\n if (!!m[a]) {\n var b = a + m[a];\n write(b+'\\n');\n m[a] = m[a] + 1;\n m[b] = 1;\n \n } else {\n m[a] = 1;\n write('OK'+'\\n'); \n }\n}\n"}, {"source_code": "function registrationSystem (userName){\n\tif (!mySet.hasOwnProperty(userName)){\n\t\tmySet[userName] = 0;\n\t\tprint('OK');\n\t}\n\telse{\n\t\tmySet[userName] += 1;\n\t\tvar newUser = userName + mySet[userName].toString();\n\t\tmySet[newUser] = 0;\n\t\tprint(newUser)\n\t}\n}\nvar mySet = {}; \nvar queries = parseInt(readline());\nfor (var i = 0; i < queries; i ++){\n\tregistrationSystem(readline());\n}"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar base = {};\n\n\twhile (n--) {\n\t\tvar name = readline();\n\t\tif (base.hasOwnProperty(name)) {\n\t\t\tbase[name]++;\n\t\t\tprint(name + base[name]);\n\t\t} else {\n\t\t\tbase[name] = 0;\n\t\t\tprint('OK');\n\t\t}\n\t}\n\n}).call(this);"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar queryNum = integers[0];\n\n\tvar names = {};\n\n\tfor (var i = 0; i < queryNum; i += 1) {\n\t\tvar query = trim(readline());\n\t\tif (names[query] == undefined) {\n\t\t\tprint(\"OK\");\n\t\t\tnames[query] = 1;\n\t\t}\n\t\telse {\n\t\t\tprint(query+names[query]);\n\t\t\tnames[query] += 1;\n\t\t}\n\t}\n}\n\nmain();\n"}, {"source_code": "readline = readline || ''\nwrite = write || ''\nprint = print || ''\n\nreadline()\n\nvar ns = {}\nvar ln\nwhile (ln = readline()) ns[ln] ? print(ln + ns[ln]++) : (print('OK'), ns[ln] = 1)"}, {"source_code": "'use strict'\n\nvar names = {};\nfor (var i = parseInt(readline()); i; i--) {\n let name = readline();\n if (names[name]) { write(`${name}${names[name]++}\\n`); }\n else { write('OK\\n'); names[name] = 1; }\n}"}, {"source_code": "'use strict'\n\nconst names = {};\nfor (let i = parseInt(readline()); i; i--) {\n const name = readline();\n if (names[name]) { write(`${name}${names[name]++}\\n`); }\n else { write('OK\\n'); names[name] = 1; }\n}"}, {"source_code": "readline(); x = {};\nwhile(i = readline()) x[i] ? print(i + x[i]++) : (print('OK'), x[i] = 1);"}, {"source_code": "var n = +readline();\nvar names = {};\nfor (var i = 0; i < n; i++) {\n var name = readline();\n if (names[name]) { print(`${name}${names[name]}`); names[name] += 1; }\n else { print('OK'); names[name] = 1; }\n}"}, {"source_code": "var n = +readline();\nvar obj = {}, str;\n\nfor(var i = 0; i < n; i++) {\n str = readline();\n if (!obj[str]) {\n print('OK');\n obj[str] = 1;\n } else {\n var str2 = str + obj[str];\n obj[str]++;\n print(str2);\n obj[str2] = 1;\n }\n}\n\n//print(res);\n"}, {"source_code": "n = Number(readline());\nvar names = {};\nwhile (n--) {\n str = readline();\n if (names[str] === undefined) { print('OK'); names[str] = 1; }\n else {print(str + names[str]); names[str]++ }\n}"}, {"source_code": "n=Number(readline())\nr={}\nwhile (n) {\n\tw=readline()\n\tif (w in r) {\n\t\tr[w]++;\n\t\tprint(w+r[w]);\n\t}\n\telse {\n\t\tr[w]=0;\n\t\tprint(\"OK\");\n\t}\n\tn--;\n}\n"}, {"source_code": "'use strict'\n\nString.prototype.getNumber = function() {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n })[0];\n}\n\nlet n = readline().getNumber(),\n dict = {};\n\nfor (let i = 0; i < n; i++) {\n let name = readline();\n if (dict[name]) {\n write(name+(dict[name]++)+'\\n');\n } else {\n dict[name] = 1;\n write('OK\\n');\n }\n}"}, {"source_code": "var o = {\n};\nvar n = readline();\n\tfor (var i=0; i {\n process.stdout.write(args.join(' '));\n};\n\nconst lines = [];\nrl.on('line', line => {\n lines.push(line);\n});\n\nrl.on('close', main);\nlet rli = 0;\n\nfunction readline() {\n return lines[rli++];\n};\n \nfunction main() {\n const size = parseInt(readline());\n const registredMap = {};\n for(let i = 0; i < size; ++i){\n const user = readline();\n if(registredMap[user] === undefined) {\n registredMap[user] = 0;\n write(\"OK\\n\");\n } else {\n registredMap[user]++;\n write(`${user}${registredMap[user]}\\n`);\n }\n }\n}\n\n//solved by: asmjaime\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet input = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n input += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n input = input.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction main() {\n const map = {};\n\n input.forEach((item, index) => {\n if (index !== 0) {\n if(map[item] !== undefined){\n console.log(`${item}${map[item]}`);\n map[item] += 1;\n } else {\n map[item] = 1;\n console.log('OK');\n }\n }\n });\n}\n"}, {"source_code": "const readline = require('readline')\n \nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n \nlet counts = 0\nlet inputs = []\nlet register = {}\n \nRL.on('line', line => {\n const len = inputs.length\n if (!counts) {\n counts = line\n } else if (len < counts) {\n inputs.push(line)\n if (len === counts - 1) {\n solution()\n }\n }\n})\n \nfunction solution() {\n inputs.map(input => {\n if (register[input]) {\n console.log(`${input}${register[input]}`)\n register[input] += 1\n } else {\n console.log('OK')\n register[input] = 1\n }\n })\n}"}, {"source_code": "const mainFunction = (lines) => {\n let n = +lines[0],\n map = new Map()\n for (let i = 1; i <= n; i++) {\n let string = lines[i]\n if (map.has(string)) {\n let key = +map.get(string)\n map.delete(string)\n map.set(string, ++key)\n console.log(string + map.get(string))\n } else {\n map.set(string, 0)\n console.log(\"OK\")\n }\n }\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nlet counts = 0\nlet inputs = []\nlet register = {}\n\nRL.on('line', line => {\n const len = inputs.length\n if (!counts) {\n counts = line\n } else if (len < counts) {\n inputs.push(line)\n if (len === counts - 1) {\n solution()\n }\n }\n})\n\nfunction solution() {\n inputs.map(input => {\n if (register[input]) {\n console.log(`${input}${register[input]}`)\n register[input] += 1\n } else {\n console.log('OK')\n register[input] = 1\n }\n })\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const map = {};\n input.forEach((x, i) => {\n if (i === 0) return;\n\n if (map[x] !== undefined) {\n console.log(`${x}${map[x]}`);\n map[x] += 1;\n } else {\n map[x] = 1;\n console.log('OK');\n }\n });\n});\n"}, {"source_code": "const readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nreadLine.on(\"line\", (line) => input.push(line));\nreadLine.on(\"close\", () => {\n let n = parseInt(input[0]);\n const map = {};\n\n for (let i = 1; i <= n; i += 1) {\n const name = input[i];\n\n if (map[name] === undefined) {\n console.log(`OK`);\n map[name] = 0;\n } else {\n map[name]++;\n console.log(`${name}${map[name]}`);\n }\n }\n});\n"}, {"source_code": "\"use strict\";\n// registration system\n// https://codeforces.com/contest/4/problem/C\n\nconst readline = require('readline');\nlet rl = readline.createInterface(process.stdin, process.stdout);\n\nconst registered = new Map();\nlet count=0;\nlet lines;\n\nrl.on('line', input => {\n if (lines) {\n if (registered.has(input)) {\n registered.set(input, registered.get(input)+1);\n console.log(`${input}${registered.get(input)}`);\n }\n else {\n registered.set(input, 0);\n console.log('OK');\n }\n count++;\n if (count>=lines) process.exit(0);\n }\n else {\n lines = parseInt(input);\n }\n // console.log(input);\n});\n\n\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", _ => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => {\n return string.trim();\n });\n\n main();\n});\n// main();\n\n////////////////////////////////////////////////////////////////////////\n\nfunction main() {\n let inputNum = parseInt(readline());\n let database = {};\n for (let i = 0; i < inputNum; i++) {\n let inputString = readline();\n if (database[inputString] === undefined) {\n database[inputString] = 0;\n console.log(\"OK\");\n } else {\n database[inputString]++;\n console.log(inputString + database[inputString]);\n }\n }\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i ++) {\n if(!isNaN(txt[i]*1)){\n let tab=[];\n for (let i1 = i+1; i1 < i+1+txt[i]*1; i1++) {\n tab.push(txt[i1]);\n }\n doit(tab);\n }\n}\n\nfunction doit(tab) {\n let register=[];\n let enter=[];\n tab.forEach(data => {\n let r=register.indexOf(data);\n if(r!=-1){\n console.log(data+enter[r]);\n ++enter[r];\n }else{\n console.log(\"OK\");\n register.push(data);\n enter.push(1);\n }\n });\n \n}"}], "negative_code": [{"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar b = [];\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar s = readline();\n\t\tvar k = b.indexOf(s);\n\n\t\tif (k === -1) {\n\t\t\tb.push(s);\n\t\t\tprint('OK');\n\t\t} else {\n\t\t\tk = b.filter(function (e) { return e == s; }).length;\n\t\t\tb.push(s + k);\n\t\t\tprint(b.slice(-1));\n\t\t}\n\t}\n\n}).call(this);"}, {"source_code": "var names = {};\nfor (var i = parseInt(readline()); i; i--) {\n var name = readline();\n if (names[name]) { write(`${name}${names[name]++}`); }\n else { write('OK'); names[name] = 1; }\n}"}, {"source_code": "'use strict'\n\nString.prototype.getNumber = function() {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n })[0];\n}\n\nlet n = readline().getNumber(),\n dict = {};\n\nfor (let i = 0; i < n; i++) {\n let name = readline();\n if (dict[name]) {\n write(name+(dict[name]++));\n } else {\n dict[name] = 1;\n write('OK');\n }\n}"}, {"source_code": "var n = readline();\nvar str = \"\";\n\n\tfor (var i=0; i {\n input += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n input = input.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction main() {\n const map = {};\n\n input.forEach((item, index) => {\n if (index !== 0) {\n if(map[item] !== undefined){\n console.log(`${item}${map[item]}`);\n map[item] += 1;\n } else {\n map[item] = 1;\n console.log('\u041e\u041a');\n }\n }\n });\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet input = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n input += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n input = input.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction main() {\n const map = {};\n\n input.forEach((item, index) => {\n if (index !== 0) {\n for (let i = ''; true; i += 1) {\n if (map[item + i] === undefined) {\n map[item + i] = 1;\n if (i === '') {\n console.log('OK');\n } else {\n console.log(item + i);\n }\n break;\n }\n }\n }\n });\n}\n"}, {"source_code": "const mainFunction = (lines) => {\n let n = +lines[0],\n map = new Map()\n for (let i = 1; i <= n; i++) {\n let string = lines[i]\n if (map.has(string)) {\n let key = +map.get(string)\n map.clear(string)\n map.set(string, ++key)\n console.log(string + map.get(string))\n } else {\n map.set(string, 0)\n console.log(\"OK\")\n }\n }\n}\n\nconst { EOL } = require('os')\nif (__filename.substr(9, 4) != \"azer\") {\n let yourInputData = ''\n process.stdin.on('data', i => yourInputData += i)\n process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))\n} else {\n const fileSystem = require(\"fs\");\n mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))\n}"}, {"source_code": "\"use strict\";\n// registration system\n// https://codeforces.com/contest/4/problem/C\n\nconst readline = require('readline');\nlet rl = readline.createInterface(process.stdin, process.stdout);\n\nconst registered = new Map();\nlet count=0;\nlet lines;\n\nrl.on('line', input => {\n if (lines) {\n if (registered.has(input)) {\n console.log(`${input}1`);\n }\n else {\n registered.set(input, 1);\n console.log('OK');\n }\n count++;\n if (count>=lines) process.exit(0);\n }\n else {\n lines = parseInt(input);\n }\n // console.log(input);\n});\n\n\n"}], "src_uid": "24098df9c12d9704391949c9ff529c98"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str).join(' ')\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n let a, b\n if (str.length & 1) {\n if (str[0] < str.slice(-1)) {\n a = cal(str.slice(1))\n b = cal(str[0])\n } else {\n a = cal(str.slice(0, -1))\n b = cal(str.slice(-1))\n }\n } else {\n a = cal(str)\n b = 0\n }\n //\n if (a > b) {\n return ['Alice', a - b]\n } else {\n return ['Bob', b - a]\n }\n}\nfunction cal(str) {\n let s = 0\n for (let i = 0; i < str.length; i++) {\n s += str.charCodeAt(i) - 'a'.charCodeAt(0) + 1\n }\n// console.log(str, s)\n return s\n}\n", "positive_code": [{"source_code": "const readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n// output: process.stdout\n})\n \nlet input = []\n \nrl.on('line', line => {\n input.push(line)\n})\n\nrl.on('close', () => {\n processInput()\n // console.log(input)\n})\n\nfunction processInput(){\n// input = line.split(' ').map(x => parseInt(x))\n nb=parseInt(input[0])\n for (str of input.slice(1)){\n if (str.length==1)\n console.log(\"Bob \"+(str.charCodeAt(0)-96))\n else if (str.length%2==0) \n console.log(\"Alice \"+sumOfLetterRanks(str))\n else{\n if (str[0]t+c.charCodeAt(0)-96, 0)\n}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(s) {\r\n let a = 0,\r\n b = 0;\r\n const calc = s => {\r\n let res = 0;\r\n for (let char of s) {\r\n res += char.charCodeAt(0) - 96;\r\n }\r\n return res;\r\n };\r\n if (s.length & 1) {\r\n const a1 = calc(s.slice(0, s.length - 1)),\r\n a2 = calc(s.slice(1));\r\n if (a1 > a2) {\r\n a = a1;\r\n b = s[s.length - 1].charCodeAt(0) - 96;\r\n } else {\r\n a = a2;\r\n b = s[0].charCodeAt(0) - 96;\r\n }\r\n } else {\r\n a = calc(s);\r\n }\r\n if (a > b) {\r\n console.log('Alice', a - b);\r\n } else {\r\n console.log('Bob', b - a);\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s1 = await read();\r\n solve(s1);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n const string = nextCharArray().join(\"\");\r\n let ans;\r\n\r\n if (string.length === 1) {\r\n ans = `Bob ${string[0].charCodeAt(0) - 96}`;\r\n } else if (string.length % 2 === 1) {\r\n let sum = 0;\r\n for (let i = 0; i < string.length; i++) {\r\n sum += string[i].charCodeAt(0) - 96;\r\n }\r\n sum = sum - 2*(Math.min(string[0].charCodeAt(0), string[string.length - 1].charCodeAt(0)) - 96);\r\n\r\n ans = `Alice ${sum}`;\r\n } else if (string.length % 2 === 0) {\r\n let sum = 0;\r\n for (let i = 0; i < string.length; i++) {\r\n sum += string[i].charCodeAt(0) - 96;\r\n }\r\n ans = `Alice ${sum}`;\r\n }\r\n\r\n myout(ans)\r\n\t}\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n const alphabet = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));\r\n const letterPos = {};\r\n alphabet.forEach((letter, i) => letterPos[letter] = i + 1);\r\n\r\n for (let test = 0; test < N; test++) {\r\n let s = readline().split('');\r\n let sum = s.reduce((a, b) => a + letterPos[b], 0);\r\n if (s.length === 1) {\r\n output('Bob ' + letterPos[s[0]]);\r\n } else if (s.length % 2 === 0) {\r\n output('Alice ' + sum);\r\n } else if (s.length % 2 === 1) {\r\n let bob = Math.min(letterPos[s[0]], letterPos[s[s.length - 1]]);\r\n output('Alice ' + (sum - bob * 2));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var v = new Map();\n v.set('a', 1); v.set('b', 2); v.set('c', 3); v.set('d', 4); v.set('e', 5); v.set('f', 6); v.set('g', 7); v.set('h', 8); v.set('i', 9); v.set('j', 10); v.set('k', 11); v.set('l', 12); v.set('m', 13); v.set('n', 14); v.set('o', 15); v.set('p', 16); v.set('q', 17); v.set('r', 18); v.set('s', 19); v.set('t', 20); v.set('u', 21); v.set('v', 22); v.set('w', 23); v.set('x', 24); v.set('y', 25); v.set('z', 26);\n for(i = 1; i <= n; i++){\n var k = lines[i].split('');\n var ans = '';\n if(k.length % 2 === 0){\n ans += 'Alice ';\n var u = 0;\n for(j = 0; j < k.length; j++){\n u += v.get(k[j]);\n }\n ans += u;\n }else{\n if(k.length == 1){\n ans += 'Bob ' + v.get(k[0]);\n }else{\n var a = k[0];\n var b = k[k.length - 1];\n var c = 0;\n var d = 0;\n if(a > b){\n c = a;\n d = b;\n }else{\n c = b;\n d = a;\n }\n var o = 0;\n for(j = 1; j < k.length - 1; j++){\n o += v.get(k[j]);\n }\n ans += 'Alice ';\n o += v.get(c) ;\n ans += o - v.get(d);\n }\n }\n console.log(ans);\n }\n});"}, {"source_code": "const readline = require(\"readline\");\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nconst score = (string) => {\r\n let sum = 0;\r\n for(let i = 0; i < string.length; i++){\r\n sum += string.charCodeAt(i) - 96;\r\n }\r\n return sum;\r\n}\r\n\r\nconst calculate = (input) => {\r\n const len = input.length;\r\n const lastIndex = len-1;\r\n if (len === 1)\r\n return `Bob ${input.charCodeAt()-96}`\r\n if (!(len%2))\r\n return `Alice ${score(input)}`\r\n const firstScore = input.charCodeAt(0) - 96;\r\n const lastScore = input.charCodeAt(lastIndex) - 96;\r\n if (firstScore > lastScore)\r\n return `Alice ${score(input) - 2*lastScore}`;\r\n else \r\n return `Alice ${score(input) - 2*firstScore}`;\r\n}\r\n\r\nlet n = 0;\r\n\r\nrl.on('line', (input) => {\r\n if(!n) n = input;\r\n else console.log(calculate(input));\r\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var v = new Map();\n v.set('a', 1); v.set('b', 2); v.set('c', 3); v.set('d', 4); v.set('e', 5); v.set('f', 6); v.set('g', 7); v.set('h', 8); v.set('i', 9); v.set('j', 10); v.set('k', 11); v.set('l', 12); v.set('m', 13); v.set('n', 14); v.set('o', 15); v.set('p', 16); v.set('q', 17); v.set('r', 18); v.set('s', 19); v.set('t', 20); v.set('u', 21); v.set('v', 22); v.set('w', 23); v.set('x', 24); v.set('y', 25); v.set('z', 26);\n for(i = 1; i <= n; i++){\n var k = lines[i].split('');\n var ans = '';\n if(k.length % 2 === 0){\n ans += 'Alice ';\n var u = 0;\n for(j = 0; j < k.length; j++){\n u += v.get(k[j]);\n }\n ans += u;\n }else{\n if(k.length == 1){\n ans += 'Bob ' + v.get(k[0]);\n }else{\n var a = k[0];\n var b = k[k.length - 1];\n var c = 0;\n var d = 0;\n if(a > b){\n c = a;\n d = b;\n }else{\n c = b;\n d = a;\n }\n var o = 0;\n for(j = 1; j < k.length - 1; j++){\n o += v.get(k[j]);\n }\n ans += 'Alice ';\n o += v.get(c) ;\n ans += o - v.get(d);\n }\n }\n console.log(ans);\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let str = readLine();\r\n if (str.length === 1) {\r\n return \"Bob \" + (str.charCodeAt(0) - 96);\r\n }\r\n let score = 0;\r\n let start = 0, end = str.length;\r\n let subtract = 0;\r\n if (str.charCodeAt(0) > str.charCodeAt(end - 1)) {\r\n subtract = str.charCodeAt(str.length - 1) - 96;\r\n end--;\r\n } else {\r\n start = 1;\r\n subtract = str.charCodeAt(0) - 96;\r\n }\r\n if (str.length % 2 === 1) {\r\n for (let i = start; i < end; i++) {\r\n score += str.charCodeAt(i) - 96;\r\n }\r\n score -= subtract;\r\n } else {\r\n for (let i = 0; i < str.length; i++) {\r\n score += str.charCodeAt(i) - 96;\r\n }\r\n }\r\n return \"Alice \" + score;\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\n\r\nfunction solve() {\r\n let t = readSingleInt();\r\n while(t--){\r\n let st = readLine();\r\n let total = 0;\r\n let first = st.charCodeAt(0)-96,last = st.charCodeAt(st.length-1)-96;\r\n for(let i=0;ialice){\r\n console.log(\"Bob \",Math.abs(alice-bob));\r\n }else{\r\n console.log(\"Alice \",Math.abs(alice-bob));\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst ind = c => c.charCodeAt(0) - 'a'.charCodeAt(0);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst s = rl();\r\n\t\tconst n = s.length;\r\n\r\n\t\tlet ascr = 0, bscr = 0, sum = 0;\r\n\t\tfor (let i = 0; i < n; i++) sum += ind(s[i]) + 1;\r\n\t\tif (n & 1) {\r\n\t\t\tbscr = s[0] < s[n-1] ? ind(s[0]) + 1 : ind(s[n-1]) + 1;\r\n\t\t}\r\n\t\tascr = sum - bscr;\r\n\r\n\t\tconsole.log(ascr > bscr ? 'Alice' : 'Bob', Math.abs(ascr - bscr));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var num=parseInt(readline());\r\nvar arr=[];\r\nfor(var i=0;i=arr[i][arr[i].length-1]){\r\n if(x==arr[i].length-1){\r\n bob=arr[i][x].charCodeAt(0)-96;\r\n break;\r\n }else{\r\n alice+=arr[i][x].charCodeAt(0)-96;\r\n }\r\n }\r\n else{\r\n bob=arr[i][0].charCodeAt(0)-96;\r\n if(x===0){\r\n continue;\r\n }else{\r\n alice+=arr[i][x].charCodeAt(0)-96; \r\n }\r\n }\r\n }\r\n }\r\n if(alice>=bob){\r\n print(`Alice ${alice-bob}`);\r\n }\r\n else{\r\n print(`Bob ${bob-alice}`);\r\n }\r\n}"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index].trim();\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - 97 + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let s=line[i];\r\n let x=0,y=0;\r\n let a=new Array(s.length);\r\n let n=s.length;\r\n for(let i=0;iy) console.log('Alice',x-y);\r\n else console.log('Bob',y-x);\r\n }\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let s=line[i];\r\n let x=0,y=0;\r\n let a=new Array(s.length);\r\n let n=s.length;\r\n for(let i=0;iy) console.log('Alice',x-y);\r\n else console.log('Bob',y-x);\r\n }\r\n }\r\n})"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index].trim();\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - 97 + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.log(\n s.length,\n totalScore,\n isEvenLength,\n minEnd,\n s[0],\n getValue(s[0]),\n s[s.length - 1],\n getValue(s[s.length - 1])\n );\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0);\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.log(\n s.length,\n totalScore,\n isEvenLength,\n minEnd,\n s[0],\n getValue(s[0]),\n s[s.length - 1],\n getValue(s[s.length - 1])\n );\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0);\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.log(\n totalScore,\n isEvenLength,\n minEnd,\n s[0],\n getValue(s[0]),\n s[s.length - 1],\n getValue(s[s.length - 1])\n );\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0);\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.log(totalScore, isEvenLength, minEnd);\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - 97 + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.log(totalScore, isEvenLength, minEnd);\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - 97 + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n console.error(totalScore, isEvenLength, minEnd);\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - 97 + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt(0) - \"a\".charCodeAt(0) + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "const fs = require(\"fs\");\n\nconst input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\n\nconst testCases = [];\nlet T;\n\nfunction parseInput() {\n T = parseInt(input[0]);\n let index = 0;\n\n for (let i = 0; i < T; i++) {\n index++;\n const s = input[index];\n const testCase = {\n s,\n };\n\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { s } = testCase;\n\n const getValue = (c) => c.charCodeAt() - \"a\".charCodeAt() + 1;\n\n const totalScore = s.split(\"\").reduce((acc, val) => acc + getValue(val), 0);\n const isEvenLength = s.length % 2 == 0;\n const minEnd = Math.min(getValue(s[0]), getValue(s[s.length - 1]));\n let result = \"\";\n if (isEvenLength) {\n result = `Alice ${totalScore}`;\n } else {\n if (totalScore - minEnd > minEnd)\n result = `Alice ${totalScore - 2 * minEnd}`;\n else result = `Bob ${2 * minEnd - totalScore}`;\n }\n console.log(result);\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let i=1;i<=t;i++)\r\n {\r\n let s=line[i];\r\n let x=0,y=0;\r\n let a=new Array(s.length);\r\n let n=s.length;\r\n for(let i=0;iy) console.log('Alice',x-y);\r\n else console.log('Bob',y-x);\r\n }\r\n }\r\n})"}, {"source_code": "const readline = require('readline')\n \nconst rl = readline.createInterface({\n input: process.stdin,\n// output: process.stdout\n})\n \nlet input = []\n \nrl.on('line', line => {\n input.push(line)\n})\n\nrl.on('close', () => {\n processInput()\n console.log(input)\n})\n\nfunction processInput(){\n// input = line.split(' ').map(x => parseInt(x))\n nb=parseInt(input[0])\n for (str of input.slice(1)){\n if (str.length==1)\n console.log(\"Bob \"+(str.charCodeAt(0)-96))\n else if (str.length%2==0) \n console.log(\"Alice \"+sumOfLetterRanks(str))\n else{\n if (str[0]t+c.charCodeAt(0)-96, 0)\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(s) {\r\n let a = 0,\r\n b = 0;\r\n const calc = s => {\r\n let res = 0;\r\n for (let char of s) {\r\n res += char.charCodeAt(0) - 96;\r\n }\r\n return res;\r\n };\r\n if (s.length & 1) {\r\n const a1 = calc(s.slice(0, s.length - 1)),\r\n a2 = calc(s.slice(1));\r\n if (a1 > a2) {\r\n a = a1;\r\n b = s[s.length - 1].charCodeAt(0) - 96;\r\n } else {\r\n a = a2;\r\n b = s[0].charCodeAt(0) - 96;\r\n }\r\n } else {\r\n a = calc(s);\r\n }\r\n if (a > b) {\r\n console.log('Alice', a - b);\r\n } else {\r\n console.log('Bob', b - a);\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const s1 = await read();\r\n solve(s1);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid async function () {\r\n let i = 0;\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n console.log(\"\\n\")\r\n\twhile(hasNext()){\r\n const string = nextCharArray().join(\"\");\r\n let ans;\r\n\r\n if (string.length === 1) {\r\n ans = `Bob ${string[0].charCodeAt(0) - 96}`;\r\n } else if (string.length % 2 === 1) {\r\n let sum = 0;\r\n for (let i = 0; i < string.length; i++) {\r\n sum += string[i].charCodeAt(0) - 96;\r\n }\r\n sum = sum - 2*(Math.min(string[0].charCodeAt(0), string[string.length - 1].charCodeAt(0)) - 96);\r\n\r\n ans = `Alice ${sum}`;\r\n } else if (string.length % 2 === 0) {\r\n let sum = 0;\r\n for (let i = 0; i < string.length; i++) {\r\n sum += string[i].charCodeAt(0) - 96;\r\n }\r\n ans = `Alice ${sum}`;\r\n }\r\n\r\n myout(ans)\r\n\t}\r\n}"}], "src_uid": "8f02891aa9d2fcd1963df3a4028aa5c0"} {"source_code": "\n var n = +readline();\n var arr = [];\n for(var i =0; i < n; i++) {\n arr.push(readline()[0]);\n }\n\n //print(k)\n \n var map = arr.reduce((prev, cur) => {\n if(prev[cur]) {\n prev[cur]++;\n } else {\n prev[cur] = 1;\n }\n return prev;\n }, {});\n \n var res = 0\n // print(JSON.stringify(map))\n \n for (var key in map) {\n var value = map[key]\n var low = Math.floor(value / 2)\n var high = value - low\n \n // print(high, low)\n if(value > 2) {\n res += (high * (high -1) + low * (low -1)) / 2\n }\n\n }\n \n print(res)", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst obj = {};\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (obj[str[0]]) {\n obj[str[0]]++;\n }\n else {\n obj[str[0]] = 1;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n const arr = Object.values(obj);\n let ans = 0;\n const scores = {0: 0, 1: 0, 2: 1};\n\n for (let i = 3; i <= 50; i++) {\n scores[i] = (i - 1) + scores[i - 1];\n }\n\n for (let i = 0; i < arr.length; i++) {\n const min = Math.floor(arr[i] / 2);\n const max = Math.ceil(arr[i] / 2);\n\n ans += scores[min];\n ans += scores[max];\n }\n\n console.log(ans);\n});\n"}, {"source_code": "const unique = (value, index, self) => {\n return self.indexOf(value) === index\n }\n \n\nlet z = '';\nprocess.stdin.on('data', c => z += c);\nprocess.stdin.on('end', () => {\n const {\n EOL\n } = require('os');\n let input = z.split(EOL);\n input.shift();\n input = input.map(item=>item.charAt(0));\n const uniqueNames = input.filter(unique);\n let overall=[];\n uniqueNames.forEach((item)=>{\n let counter=0;\n for(let i=0;i{\n let firstClass = parseInt(item/2);\n result += (firstClass * (firstClass-1))/2;\n let secondClass = item-firstClass;\n result += (secondClass * (secondClass-1))/2;\n })\n console.log(result)\n\n});"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var res = {};\n for(var i = 0; i < n; i++) {\n var f =readline()[0];\n if(res[f]) {\n res[f] += 1;\n }\n else {\n res[f] = 1;\n }\n }\n\n var c = 0;\n for(var k in res) {\n var l = Math.floor(res[k] / 2);\n var r = res[k] - l;\n \n for(var i = 1; i < l; i++) {\n c+=i;\n }\n for(var i = 1; i < r; i++) {\n c+=i;\n }\n }\n print(c);\n}());"}, {"source_code": "var n = parseInt(readline());\n\nvar ar = new Array(n);\nfor(var i =0;i {\n letters[name.charAt(0)] = letters[name.charAt(0)] ? letters[name.charAt(0)]+1:1;\n});\n\nvar res = 0;\n\nObject.keys(letters).forEach(l=> {\n var a = Math.floor( letters[l] /2);\n var b = Math.floor(letters[l]-a);\n \n \n for(var i=0;i1 && b%2!==0) {\n // res+= b;\n // } else {\n // res+= Math.floor(b/2);\n // }\n // res += Math.floor(a/2) ;\n // print(l, letters[l], a, b);\n // print(Math.floor(a/2), Math.floor(b/2), b%2, b%2*b)\n})\nprint(res)"}, {"source_code": "function main() {\n var i\n var n = +readline()\n\n var count = new Array(256).fill(0)\n for(i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (obj[str[0]]) {\n obj[str[0]]++;\n }\n else {\n obj[str[0]] = 1;\n }\n\n c++;\n});\n\nrl.on('close', () => {\n const max = Math.max(...Object.values(obj).sort((a, b) => b - a));\n const a1 = Math.floor(max / 2);\n const a2 = Math.ceil(max / 2);\n let ans = 0;\n\n for (let i = 0; i < a1; i++) {\n ans += i;\n }\n\n for (let i = 0; i < a2; i++) {\n ans += i;\n }\n\n console.log(ans);\n});\n"}, {"source_code": "var n = parseInt(readline());\n\nvar ar = new Array(n);\nfor(var i =0;i {\n letters[name.charAt(0)] = letters[name.charAt(0)] ? letters[name.charAt(0)]+1:1;\n});\n\nvar res = 0;\n\nObject.keys(letters).forEach(l=> {\n var a = Math.floor( letters[l] /2);\n var b = Math.floor(letters[l]-a);\n res += Math.floor(a/2) + Math.floor(b/2) + (b%2)*2*Math.floor(b/2);\n // print(l, letters[l], a, b);\n // print(Math.floor(a/2), Math.floor(b/2), b%2)\n})\nprint(res)"}, {"source_code": "var n = parseInt(readline());\n\nvar ar = new Array(n);\nfor(var i =0;i {\n letters[name.charAt(0)] = letters[name.charAt(0)] ? letters[name.charAt(0)]+1:1;\n});\n\nvar res = 0;\n\nObject.keys(letters).forEach(l=> {\n var a = Math.floor( letters[l] /2);\n var b = Math.floor(letters[l]-a);\n res += Math.floor(a/2) + Math.floor(b/2) + (b%2)*Math.min(a, b);\n // print(l, letters[l], a, b);\n // print(Math.floor(a/2), Math.floor(b/2), b%2)\n})\nprint(res)"}, {"source_code": "var n = parseInt(readline());\n\nvar ar = new Array(n);\nfor(var i =0;i {\n letters[name.charAt(0)] = letters[name.charAt(0)] ? letters[name.charAt(0)]+1:1;\n});\n\nvar res = 0;\n\nObject.keys(letters).forEach(l=> {\n var a = Math.floor( letters[l] /2);\n var b = Math.floor(letters[l]-a);\n \n if (b>1 && b%2!==0) {\n res+= b;\n } else {\n res+= Math.floor(b/2);\n }\n res += Math.floor(a/2) ;\n // print(l, letters[l], a, b);\n // print(Math.floor(a/2), Math.floor(b/2), b%2, b%2*b)\n})\nprint(res)"}, {"source_code": "\n var n = +readline()[0];\n var arr = [];\n for(var i =0; i< n; i++) {\n arr.push(readline());\n }\n\n //print(k)\n \n var map = arr.reduce((prev, cur) => {\n var key = cur[0]\n if(prev[key]) {\n prev[key]++;\n } else {\n prev[key] = 1;\n }\n return prev;\n }, {});\n \n var res = 0\n //print(JSON.stringify(map))\n \n for (var key in map) {\n var value = map[key]\n var low = Math.floor(value / 2)\n var high = value - low\n \n // print(high, low)\n if(value > 2) {\n res += (high * (high -1) + low * (low -1)) / 2\n }\n\n }\n \n print(res)\n"}, {"source_code": "function calculate(data) {\n const map = data.reduce(function (prev,cur) {\n if(prev[cur[0]]) {\n prev[cur[0]]++ \n } else {\n prev[cur[0]] = 1\n }\n return prev\n }, {})\n\n var res = 0\n\n for(var key in map) {\n var k = Math.floor(map[key] / 2)\n var m = Math.floor(map[key] - k)\n res += ( k > 1 ? k*(k-1)/2 : 0) + ( m > 1 ? m*(m-1)/2 : 0)\n }\n\n return res\n}"}], "src_uid": "22a3561ff70b802f080feaabc4a71298"} {"source_code": "\"use strict\";\n\nvar n = +readline();\nvar A = readline().split(' ').map(value => +value);\nvar R = []\n\nfor (var i = 0; i < n; ++i) {\n var opop = A[i];\n if (A[i] >= 0) {\n opop = -A[i] - 1;\n } else if (A[i] < -1) {\n opop = A[i];\n }\n R.push(opop);\n}\n\nvar ind;\nvar most = +Infinity;\nif (n%2) {\n for (var i = 0; i < n; ++i) {\n if (R[i] < -1 && R[i] < most) {\n most = R[i];\n ind = i;\n }\n }\n \n if (most !== +Infinity) {\n R[ind] = -R[ind] - 1;\n } else {\n R[0] = 0;\n }\n}\n\nwrite(R.join(' '));", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n var n = read.number();\n var arr = read.arrNumber(' ');\n\n var min = 0;\n for(var i = 0; i < n; i++) {\n if(arr[i] >= 0) {\n arr[i] = (arr[i] * -1) -1;\n }\n if(arr[i] < arr[min])\n min = i;\n }\n if(n % 2 !== 0) {\n arr[min] = (arr[min] * -1) -1;\n }\n \n\n print(arr.join(' '));\n}());"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n var n = read.number();\n var arr = read.arrNumber(' ');\n\n var onlyZero = true;\n for(var i = 0; i < n; i++) {\n if(arr[i] !== 0) {\n onlyZero = false;\n }\n }\n\n if(onlyZero && n % 2) {\n print(arr.join(' '));\n return;\n }\n\n var positiveCount = 0;\n var minPositive = -Infinity;\n for(var i = 0; i < n; i++) {\n if(arr[i] >= 0) {\n positiveCount++;\n }\n if(arr[i] > minPositive) {\n minPositive = arr[i];\n }\n }\n\n var negativeCount = n - positiveCount;\n if(positiveCount < 2 && negativeCount % 2 === 0) {\n print(arr.join(' '));\n return;\n }\n\n var all = n % 2 === 0;\n var minChecked = false;\n for(var i = 0; i < n; i++) {\n if(arr[i] >= 0) {\n if(all) {\n arr[i] = (arr[i] * -1) - 1;\n }\n else {\n if(arr[i] !== minPositive) {\n arr[i] = (arr[i] * -1) - 1;\n }\n else if(minChecked) {\n arr[i] = (arr[i] * -1) - 1;\n }\n else {\n minChecked = true;\n }\n }\n }\n }\n print(arr.join(' '));\n}());\n"}, {"source_code": "\"use strict\";\n\nvar n = +readline();\nvar A = readline().split(' ').map(value => +value);\nvar R = []\n\nfor (var i = 0; i < n; ++i) {\n var opop = A[i];\n if (A[i] >= 0) {\n opop = -A[i] - 1;\n } else if (A[i] < -1) {\n opop = A[i];\n }\n R.push(opop);\n}\n\nvar ind;\nvar most = -Infinity;\nif (n%2) {\n for (var i = 0; i < n; ++i) {\n if (R[i] < -1 && R[i] > most) {\n most = R[i];\n ind = i\n }\n }\n \n if (most !== -Infinity) {\n R[ind] = -R[ind] - 1;\n } else {\n R[0] = 0;\n }\n}\n\nwrite(R.join(' '));"}], "src_uid": "b0561fee6236f0720f737ca41e20e382"} {"source_code": "var tok = null;\nvar index = 0;\nfunction next() {\n while (tok == null || index == tok.length) {\n tok = readline().split(' ');\n index = 0;\n }\n var res = tok[index++];\n return res;\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nfunction sortNumber(a, b) {\n return a - b;\n}\n\nfunction main() {\n var a=nextInt();\nvar b=nextInt();\nvar hA=[];\nfor(var i=0; i 0) {\n var temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n}\n\nvar x = gcd(b, g);\n\nvar happy = [];\nfor (var i =0; i < x; i++) happy.push(-1);\n\nb_h_i.forEach(function (b) {\n happy[b % x] = 1;\n});\n\ng_h_i.forEach(function (g) {\n happy[g % x] = 1;\n});\n\nvar result = \"Yes\";\n\nhappy.forEach(function (el) {\n if (el == -1) result = \"No\";\n});\n\nprint(result);\n"}, {"source_code": "var app = {\n 'main' : function main() {\n var boyCount = 0, girlCount = 0,\n happyBoyArray = [], happyGirlArray = [],\n result = 'Yes';\n \n boyCount = readline().split(/\\s/gi).map(Number);\n girlCount = boyCount[1], boyCount = boyCount[0];\n \n readline().split(/\\s/gi).slice(1).forEach(function(boy) {\n happyBoyArray[boy] = 1;\n });\n readline().split(/\\s/gi).slice(1).forEach(function(boy) {\n happyGirlArray[boy] = 1;\n });\n \n for(var i = 0; i < 1e4; i++) {\n var boyIndex = i % boyCount, girlIndex = i % girlCount,\n boyStatus = happyBoyArray[boyIndex],\n girlStatus = happyGirlArray[girlIndex];\n \n if(boyStatus) {\n happyGirlArray[girlIndex] = 1;\n } else {\n if(girlStatus) {\n happyBoyArray[boyIndex] = 1;\n } else {\n happyGirlArray[girlIndex] = 0;\n happyBoyArray[boyIndex] = 0;\n }\n }\n }\n \n if(happyGirlArray.sort()[0] == 0) result = 'No';\n if(happyBoyArray.sort()[0] == 0) result = 'No';\n \n print(result);\n }\n};\n\napp.main();"}], "negative_code": [{"source_code": "var tok = null;\nvar index = 0;\nfunction next() {\n while (tok == null || index == tok.length) {\n tok = readline().split(' ');\n index = 0;\n }\n var res = tok[index++];\n return res;\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nfunction sortNumber(a, b) {\n return a - b;\n}\n\nfunction main() {\n var a=nextInt();\nvar b=nextInt();\nvar hA=[];\nfor(var i=0; i Math.floor(Number(num));\nvar mn = readline().split(' ');\nvar n = result(mn[0]), m = result(mn[1]);\nvar ai = readline().split(' ').map(result);\nvar bi = readline().split(' ').map(result);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0; i < m; i++) {\n var lo = 0, hi = n - 1, key = bi[i];\n while(lo <= hi) {\n var mid = result(hi - (hi - lo) / 2);\n if(ai[mid] >= key) hi = mid - 1;\n else lo = mid + 1;\n }\n print(lo + 1, bi[i] - ( lo === 0 ? 0 : ai[lo - 1]));\n}\n", "positive_code": [{"source_code": "var _ = parseInt(readline());\nvar flats = readline().split(\" \").map(function(el) {return parseInt(el)});\nvar letters = readline().split(\" \").map(function(el) {return parseInt(el)});\nres = [];\n\nsumFlats = flats.map(function(flat, i) { \n return {\n building: i,\n flat: flat\n }\n})\n\nfor (var i = 1; i sumFlats[sumFlats.length - 1].flat) {\n print('impossible')\n } else {\n for (var i = globalCounter; i < sumFlats.length; i++ ) {\n if (letter === sumFlats[i].flat) {\n print([i+1, flats[i]].join(\" \"));\n globalCounter = i;\n break;\n }\n if (letter < sumFlats[i].flat) {\n if (i === 0) {\n print([1, letter].join(\" \"));\n } else {\n print([i + 1, letter - sumFlats[i-1].flat].join(\" \"))\n }\n globalCounter = i;\n break;\n }\n }\n }\n});\n\n// function binarySearch(arr, elem) {\n// if (arr.length === 1) {\n// if (elem === arr[0].flat) {\n// return [arr[0].building + 1, flats[arr[0].building]];\n// } else if (elem > arr[0].flat) {\n// return [arr[0].building + 2, elem - flats[arr[0].building]];\n// } else {\n// return [arr[0].building + 1, arr[0].building > 0 ? elem - sumFlats[arr[0].building - 1].flat : elem];\n// }\n// } else if (arr.length === 2) {\n// if (elem === arr[0].flat) {\n// return [arr[0].building + 1, flats[arr[0].building]];\n// } else if (elem > arr[0].flat) {\n// return binarySearch(arr.slice(-1), elem);\n// } else {\n// return [arr[0].building + 1, arr[0].building > 0 ? elem - sumFlats[arr[0].building - 1].flat : elem];\n// }\n// } else {\n// var middle = Math.floor(arr.length / 2);\n// if (elem === arr[middle].flat) {\n// return [arr[middle].building + 1, flats[arr[middle].building]];\n// } else if (elem > arr[middle].flat) {\n// return binarySearch(arr.slice(middle + 1), elem);\n// } else {\n// return binarySearch(arr.slice(0, middle), elem);\n// }\n// }\n// }\n\n"}, {"source_code": "var result = num => Math.floor(Number(num));\nvar mn = readline().split(' ');\nvar n = result(mn[0]), m = result(mn[1]);\nvar ai = readline().split(' ').map(result);\nvar bi = readline().split(' ').map(result);\nfor(var i = 1; i < n; i++) ai[i] += ai[i - 1];\nfor(var i = 0; i < m; i++) {\n var lo = 0, hi = n - 1, key = bi[i];\n while(lo <= hi) {\n var mid = result(hi - (hi - lo) / 2);\n if(ai[mid] >= key) hi = mid - 1;\n else lo = mid + 1;\n }\n print(lo + 1, bi[i] - ( lo == 0 ? 0 : ai[lo - 1]));\n}\n"}, {"source_code": "var a = readline();\nvar amountsOfRooms = readline().split(' ');\nvar roomNumbers = readline().split(' ');\nvar currentDorm = 1;\nvar amountOfRoomsInPreviousDorms = 0;\n\nfor (var i=0; i amountsOfRooms[currentDorm-1]) {\n amountOfRoomsInPreviousDorms += +amountsOfRooms[currentDorm-1];\n currentDorm++;\n }\n var dormRoomNumber = roomNumbers[i] - amountOfRoomsInPreviousDorms;\n print(currentDorm + ' ' + dormRoomNumber);\n}\n"}, {"source_code": "\n var ub = function(a, x) {\n var l = 0;\n var h = a.length; // Not n - 1\n while (l < h) {\n var mid = Math.floor((l + h) / 2);\n if (x >= a[mid]) {\n l = mid + 1;\n } else {\n h = mid;\n }\n }\n return l;\n }\n \n \n var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var m = tmp[1];\n var d = readline().split(' ').map(x => parseInt(x));\n var ds = [0];\n for(var i = 0; i < n; i += 1) {\n ds.push(ds[i] + d[i]);\n }\n var env = readline().split(' ').map(x => parseInt(x));\n env.forEach(function(x) {\n var s = ub(ds, x - 1);\n print([s, x - ds[s - 1]].join(' '));\n });\n "}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){return Math.max(...this)},Array.prototype.min=function(){return Math.min(...this)},Array.prototype.sum=function(){let t=0;for(let e=0;e{if(l)return s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),void o.default.writeFileSync(\"output.txt\",a);process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{u+=t})),process.stdin.on(\"end\",(e=>{s=u.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(a)}))};function f(){return s[i++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function d(){return f().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();"}], "negative_code": [{"source_code": "var _ = parseInt(readline());\nvar flats = readline().split(\" \").map(function(el) {return parseInt(el)});\nvar letters = readline().split(\" \").map(function(el) {return parseInt(el)});\nres = [];\n\nsumFlats = flats.map(function(flat, i) { \n return {\n building: i,\n flat: flat\n }\n})\n\nfor (var i = 1; i sumFlats[sumFlats.length - 1]) {\n print('impossible')\n } else {\n print(binarySearch(sumFlats, letter).join(\" \"));\n }\n});\n\nfunction binarySearch(arr, elem) {\n if (arr.length === 1) {\n if (elem === arr[0].flat) {\n return [arr[0].building + 1, flats[arr[0].building]];\n } else if (elem > arr[0].flat) {\n return [arr[0].building + 2, elem - flats[arr[0].building]];\n } else {\n return [arr[0].building + 1, arr[0].building > 0 ? elem - sumFlats[arr[0].building - 1].flat : elem];\n }\n } else if (arr.length === 2) {\n if (elem === arr[0].flat) {\n return [arr[0].building + 1, flats[arr[0].building]];\n } else if (elem > arr[0].flat) {\n return binarySearch(arr.slice(-1), elem);\n } else {\n return [arr[0].building + 1, arr[0].building > 0 ? elem - sumFlats[arr[0].building - 1].flat : elem];\n }\n } else {\n var middle = Math.floor(arr.length / 2);\n if (elem === arr[middle].flat) {\n return [arr[middle].building + 1, flats[arr[middle].building]];\n } else if (elem > arr[middle].flat) {\n return binarySearch(arr.slice(middle + 1), elem);\n } else {\n return binarySearch(arr.slice(0, middle), elem);\n }\n }\n}\n\n"}, {"source_code": "\n\n var ub = function(a, x) {\n var l = 0;\n var h = a.length; // Not n - 1\n while (l < h) {\n var mid = Math.floor((l + h) / 2);\n if (x >= a[mid]) {\n l = mid + 1;\n } else {\n h = mid;\n }\n }\n return l;\n }\n \n \n var tmp = readline().split(' ').map(x => parseInt(x));\n var n = tmp[0];\n var m = tmp[1];\n var d = readline().split(' ').map(x => parseInt(x));\n var ds = [0];\n for(var i = 0; i < n; i += 1) {\n ds.push(ds[i] + d[i]);\n }\n print(ds.join(' '));\n var env = readline().split(' ').map(x => parseInt(x));\n env.forEach(function(x) {\n var s = ub(ds, x - 1);\n print([s, x - ds[s - 1]].join(' '));\n });"}], "src_uid": "56bdab2019ee12e18d4f7e17ac414962"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar x = nextInt();\r\n\t\tvar y = nextInt();\r\n\t\tif((x + y) % 2 == 1){\r\n\t\t\tmyout(\"-1 -1\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar diff = (x + y) / 2;\r\n\t\tif(x >= y){\r\n\t\t\tx -= diff;\r\n\t\t}else{\r\n\t\t\ty -= diff;\r\n\t\t}\r\n\t\tmyout(x + \" \" + y);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([x, y]) {\r\n let x1 = -1, y1 = -1;\r\n if ((x + y) % 2 === 0) {\r\n if (x % 2 === 0 && y % 2 === 0) {\r\n x1 = Math.floor(x / 2)\r\n y1 = Math.floor(y / 2)\r\n } else {\r\n if (x < y) {\r\n x1 = x\r\n y1 = Math.floor((y - x) / 2)\r\n } else {\r\n x1 = Math.floor((x - y) / 2)\r\n y1 = y\r\n }\r\n }\r\n }\r\n console.log(x1, y1)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n x = +s[0];\r\n y = +s[1];\r\n\r\n z = Math.floor((x + 1) / 2);\r\n k = Math.floor(y / 2);\r\n\r\n print(x % 2 == y % 2 ? `${z} ${k}` : \"-1 -1\");\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var x = a[0], y = a[1];\n if((x + y) % 2 == 1){\n console.log(-1, -1);\n }else{\n console.log(Math.floor(x / 2), Math.floor((y + 1) / 2));\n }\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* ***************************** */\r\n\r\nfunction main() {\r\n const test = parseInt(readline());\r\n\r\n for (let i = 0; i < test; i++) {\r\n let [x, y] = readline().split(\" \");\r\n x = parseInt(x);\r\n y = parseInt(y);\r\n \r\n let cx = -1,cy = -1;\r\n\r\n if((x + y) % 2 === 1) {\r\n console.log(cx, cy);\r\n continue;\r\n }\r\n\r\n console.log(Math.floor((x + 1)/2), Math.floor(y/2));\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [x, y] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(x, y).join(' ')\n // const [a, b] = solve(x, y)\n // console.log([a, b])\n // console.log(cal([0, 0], [x, y]), cal([0, 0], [a, b]), cal([x, y], [a, b]))\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(x, y) {\n const d = Math.abs(x) + Math.abs(y)\n if (d & 1) return [-1, -1]\n const half = d / 2\n\n if (x >= 0 && y >= 0) {\n if (half <= x) {\n return [half, 0]\n } else {\n return [x, half - x]\n }\n } else {\n return [-1, -1]\n }\n}\nfunction cal(a, b) {\n return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1])\n}\n"}, {"source_code": "\r\n\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n\r\n\r\nconst x=+(readline());\r\nlet g=[];\r\nfor(let i=0;i=1) {break;}\r\n \r\n }\r\n if(sum===0) g.push(\"-1 -1\"); break;\r\n\r\n}\r\n \r\n}\r\nfor(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* ***************************** */\r\n\r\nfunction main() {\r\n const test = parseInt(readline());\r\n\r\n for (let i = 0; i < test; i++) {\r\n let [x, y] = readline().split(\" \");\r\n x = parseInt(x);\r\n y = parseInt(y);\r\n \r\n let cx = -1,cy = -1;\r\n\r\n if((x === 0 && y % 2 === 0) || ( y === 0 && x % 2 === 0)) {\r\n if (x === 0) {\r\n cx = 0;\r\n cy = y / 2;\r\n } else if(y === 0) {\r\n cy = 0;\r\n cx = x / 2\r\n }\r\n } else if ( ((x + y) % 2 === 0)) {\r\n cx = 1;\r\n cy = ((x + y) / 2) - 1;\r\n }\r\n console.log(cx, cy);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [x, y] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(x, y).join(' ')\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(x, y) {\n const d = Math.abs(x) + Math.abs(y)\n if (d & 1) return [-1, -1]\n const half = d / 2\n\n if (x >= 0 && y >= 0) {\n if (half <= x) {\n return [0, half]\n } else {\n return [x, half - x]\n }\n } else {\n return [-1, -1]\n }\n}\n"}], "src_uid": "f1d3032f1cb07ad6187a37c84376510d"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value;\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, x] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tlet ans = n;\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (mp.get(a[i]/x) > 0) { \r\n\t\t\t\tans -= 2;\r\n\t\t\t\tmp.set(a[i]/x, mp.get(a[i]/x) - 1);\r\n\t\t\t} else {\r\n\t\t\t\tmp.set(a[i], (mp.get(a[i]) || 0) + 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar X = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar keys = Object.keys(map);\r\n\t\tkeys.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tfor(var i = 0; i < keys.length; i++){\r\n\t\t\tvar L = keys[i];\r\n\t\t\tvar V = map[L];\r\n\t\t\tif(V > 0 && L % X == 0){\r\n\t\t\t\tvar R = L / X;\r\n\t\t\t\tif(map[R] != null && map[R] > 0){\r\n\t\t\t\t\tV = Math.min(V, map[R]);\r\n\t\t\t\t\tmap[L] -= V;\r\n\t\t\t\t\tmap[R] -= V;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < keys.length; i++){\r\n\t\t\toutput += map[keys[i]];\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n const map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n }\r\n const keys = [...map.keys()].sort((a, b) => a - b);\r\n for (let key of keys) {\r\n const x = map.get(key);\r\n if (x) {\r\n const y = map.get(key * m);\r\n if (y) {\r\n const min = Math.min(x, y);\r\n map.set(key, map.get(key) - min);\r\n map.set(key * m, map.get(key * m) - min);\r\n }\r\n }\r\n }\r\n let res = 0;\r\n for (let [i, count] of map) {\r\n res += count;\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let [n, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n arr.sort((a,b)=>a-b);\r\n let obj = {};\r\n for(let i=0;i (inputText += input));\r\nprocess.stdin.on(\"end\", async () => {\r\n let inputIterator = inputText.split(\"\\n\").values();\r\n\r\n let testCases = Number(inputIterator.next().value);\r\n while (testCases > 0) {\r\n testCases -= 1;\r\n\r\n const [n, x] = inputIterator\r\n .next()\r\n .value.split(\" \")\r\n .map((i) => Number(i));\r\n\r\n let arr = inputIterator\r\n .next()\r\n .value.split(\" \")\r\n .map((i) => Number(i));\r\n arr.sort((x, y) => x - y);\r\n\r\n const used = Array(n).fill(false);\r\n let ans = 0;\r\n let j = n - 1;\r\n\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (used[i]) continue;\r\n if (arr[i] % x === 0) {\r\n let f = arr[i] / x;\r\n while (j >= 0 && (used[j] || arr[j] > f)) {\r\n j -= 1;\r\n }\r\n if (j >= 0 && !used[j] && arr[j] === f) {\r\n used[i] = true;\r\n used[j] = true;\r\n ans += 1;\r\n }\r\n }\r\n }\r\n\r\n console.log(n - 2 * ans);\r\n }\r\n});\r\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var [n, x] = readline().split(' ').map(w => parseInt(w));\r\n var a = readline().split(' ').map(w => parseInt(w));\r\n var cnt = [];\r\n a.sort(function(ar, br) { return ar-br })\r\n var ans = 0;\r\n var j = 1;\r\n for(var i=0;i {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (n, x, arr)=>{\n let cnt = new Map();\n for (let a of arr)\n cnt.set(a, (cnt.get(a)||0) + 1);\n arr.sort((a, b)=>a-b)\n for (let a of arr){\n if (!cnt.get(a)) continue;\n if (a%x==0){\n let candidate = a/x;\n if (cnt.get(candidate)>0){\n cnt.set(candidate, cnt.get(candidate)-1);\n cnt.set(a, cnt.get(a)-1);\n continue;\n }\n }\n let candidate = a*x;\n if (cnt.get(candidate)>0){\n cnt.set(candidate, cnt.get(candidate)-1);\n cnt.set(a, cnt.get(a)-1);\n continue;\n }\n }\n l(cnt)\n let ans = 0;\n for (let [k, v] of cnt){\n ans += v;\n }\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, x] = ra();\n let arr = ra();\n l('ans')\n print(calc(n, x, arr));\n }\n}\n \nE.calc = calc;"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline()\r\nfor(var q=1;q<=T;q++) {\r\n let [n, x] = readline().split(\" \").map(w => parseInt(w));\r\n let a = readline().split(\" \").map(w => parseInt(w));\r\n var cnt = [];\r\n a.sort(function(ar,br) { return ar-br });\r\n var max = -1000;\r\n var ans = n;\r\n for(var i=0;i 0) {\r\n ans -= 2;\r\n cnt[r]--;\r\n }\r\n }\r\n }\r\n console.log(ans);\r\n\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline()\r\nfor(var q=1;q<=T;q++) {\r\n let [n, x] = readline().split(\" \").map(w => parseInt(w));\r\n let a = readline().split(\" \").map(w => parseInt(w));\r\n var cnt = [];\r\n var max = -1000;\r\n var ans = n;\r\n for(var i=0;i 0) {\r\n ans -= 2;\r\n cnt[r]--;\r\n }\r\n }\r\n }\r\n console.log(ans);\r\n\r\n}"}, {"source_code": "'use strict';\nconst { throws } = require('assert');\n \n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nconst calc = (n, x, arr)=>{\n let cnt = new Map();\n for (let a of arr)\n cnt.set(a, (cnt.get(a)||0) + 1);\n for (let a of arr){\n if (!cnt.get(a)) continue;\n if (a%x==0){\n let candidate = a/x;\n if (cnt.get(candidate)>0){\n cnt.set(candidate, cnt.get(candidate)-1);\n cnt.set(a, cnt.get(a)-1);\n continue;\n }\n }\n let candidate = a*x;\n if (cnt.get(candidate)>0){\n cnt.set(candidate, cnt.get(candidate)-1);\n cnt.set(a, cnt.get(a)-1);\n continue;\n }\n }\n let ans = 0;\n for (let [k, v] of cnt){\n ans += v;\n }\n return ans;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n, x] = ra();\n let arr = ra();\n l('ans')\n print(calc(n, x, arr));\n }\n}\n \nE.calc = calc;"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar X = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar keys = Object.keys(map);\r\n\t\tkeys.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tfor(var i = 0; i < keys.length; i++){\r\n\t\t\tvar L = keys[i];\r\n\t\t\tif(map[L] > 0 && L % X == 0){\r\n\t\t\t\tvar R = L / X;\r\n\t\t\t\tif(map[R] != null && map[R] > 0){\r\n\t\t\t\t\tmap[L]--;\r\n\t\t\t\t\tmap[R]--;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < keys.length; i++){\r\n\t\t\toutput += map[keys[i]];\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}], "src_uid": "c19500d867fd0108fdeed2cbd00bc970"} {"source_code": "'use strict'\r\nvar os = require('os')\r\nfunction createInput(t) {\r\n const n = t.stdin || process.stdin,\r\n e = /-?\\d+/g,\r\n r = /-?\\d+(?:\\.\\d+)?/g\r\n let u = [],\r\n o = 0\r\n return {\r\n init: async function () {\r\n const t = []\r\n ;(u = await new Promise(e => {\r\n n.on('data', n => t.push(n)),\r\n n.on('end', function () {\r\n const n = t.join('').split(os.EOL)\r\n e(n)\r\n })\r\n })),\r\n (o = 0)\r\n },\r\n dried: function () {\r\n return o >= u.length\r\n },\r\n readLine: i,\r\n readLineAsNumber: function () {\r\n return Number(i())\r\n },\r\n readIntegersOfLine: function () {\r\n const t = i().match(e)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n readNumsOfLine: function () {\r\n const t = i().match(r)\r\n return null == t ? [] : t.map(t => Number(t))\r\n },\r\n }\r\n function i() {\r\n return u[o++]\r\n }\r\n}\r\nfunction createOutput(t) {\r\n const n = t.stdout || process.stdout,\r\n e = t.encoding || 'ascii',\r\n r = t.outputBufferThreshold || 1 << 24,\r\n u = r >> 1,\r\n o = Buffer.alloc(r)\r\n let i = 0\r\n return {\r\n flush: s,\r\n print: function (t) {\r\n c('string' == typeof t ? t : t.toString())\r\n },\r\n println: function (t) {\r\n c(('string' == typeof t ? t : t.toString()).concat('\\n'))\r\n },\r\n }\r\n function s() {\r\n n.write(o.toString(e, 0, i)), (i = 0)\r\n }\r\n function c(t) {\r\n const c = Buffer.byteLength(t, e)\r\n r - i < c && (s(), c > u) ? n.write(t) : (o.write(t, i, e), (i += c))\r\n }\r\n}\r\nfunction createInputAndOutput(t) {\r\n return {\r\n ...createInput({ stdin: t.stdin, encoding: t.encoding }),\r\n ...createOutput({\r\n stdout: t.stdout,\r\n encoding: t.encoding,\r\n outputBufferThreshold: t.outputBufferThreshold,\r\n }),\r\n }\r\n}\r\nasync function __main__(t, n, e = {}) {\r\n const r = createInputAndOutput(e)\r\n await Promise.all([r.init(), Promise.resolve(n && n())]),\r\n await t(r),\r\n r.flush()\r\n}\r\n__main__(function (t) {\r\n const n = t.readLineAsNumber()\r\n for (let r = 1; r <= n; ++r) {\r\n const n = t.readLineAsNumber(),\r\n r = t.readIntegersOfLine(),\r\n u = e()\r\n function e() {\r\n const t = r.reduce((t, n) => t + (1 & n), 0),\r\n e = n - t\r\n if (Math.abs(t - e) > 1) return -1\r\n let u = Number.MAX_SAFE_INTEGER\r\n if (t >= e) {\r\n u = 0\r\n for (let t = 0, e = 0; t < n; t += 2, ++e) {\r\n for (; e < n && !(1 & r[e]); ++e);\r\n u += Math.abs(e - t)\r\n }\r\n }\r\n let o = Number.MAX_SAFE_INTEGER\r\n if (e >= t) {\r\n o = 0\r\n for (let t = 0, e = 0; t < n; t += 2, ++e) {\r\n for (; e < n && 0 != (1 & r[e]); ++e);\r\n o += Math.abs(e - t)\r\n }\r\n }\r\n return u < o ? u : o\r\n }\r\n t.println(u)\r\n }\r\n})\r\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ocnt = 0, ecnt;\r\n\t\tfor (const elm of a) {\r\n\t\t\tocnt += elm % 2;\r\n\t\t}\r\n\t\tecnt = n - ocnt;\r\n\r\n\t\t//console.log({ocnt, ecnt});\r\n\t\tif (Math.abs(ocnt - ecnt) > 1) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet ans = [0, 0];\r\n\t\tfor (let start = 0; start < 2; start++) {\r\n\t\t\tfor (let i = 0, pos = start; i < n; i++) {\r\n\t\t\t\tif (a[i]%2) {\r\n\t\t\t\t\tans[start] += Math.abs(pos - i);\r\n\t\t\t\t\tpos += 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t//console.log({ans})\r\n\t\tif (ocnt > ecnt)\r\n\t\t\tans = ans[0];\r\n\t\telse if (ocnt < ecnt) \r\n\t\t\tans = ans[1];\r\n\t\telse\r\n\t\t\tans = Math.min(...ans);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst INF = 1e14;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ocnt = 0, ecnt;\r\n\t\tfor (const elm of a) {\r\n\t\t\tocnt += elm % 2;\r\n\t\t}\r\n\t\tecnt = n - ocnt;\r\n\r\n\t\tif (Math.abs(ocnt - ecnt) > 1) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet ans = [0, 0];\r\n\t\tfor (let start = 0; start < 2; start++) {\r\n\t\t\tfor (let i = 0, pos = start; i < n; i++) {\r\n\t\t\t\tif (a[i]%2) {\r\n\t\t\t\t\tif (pos >= n) {\r\n\t\t\t\t\t\tans[start] = INF;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tans[start] += Math.abs(pos - i);\r\n\t\t\t\t\tpos += 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans = Math.min(...ans);\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet n = rn();\r\n\t\tlet a = rna();\r\n\r\n\t\tlet ecnt = 0;\r\n\t\tfor (const x of a) ecnt += x%2 == 0;\r\n\r\n\t\tconst ocnt = n - ecnt;\r\n\t\tif (Math.abs(ecnt - ocnt) > 1) {\r\n\t\t\tconsole.log(-1); continue;\r\n\t\t}\r\n\r\n\t\tlet ans = [0, 0];\r\n\t\tfor (let k = 0; k < 2; k++) {\r\n\t\t\tb = a.slice();\r\n\t\t\tfor (let i = 0, needevn = k, ep = op = 0; i < n; i++, needevn = !needevn) {\r\n\t\t\t\twhile(ep < n && b[ep] % 2 != 0) ep++;\r\n\t\t\t\twhile(op < n && b[op] % 2 != 1) op++;\r\n\r\n\t\t\t\tif(needevn != b[i]%2 == 0) {\r\n\t\t\t\t\tans[k] += (needevn ? ep : op) - i;\r\n\t\t\t\t\t[b[ep], b[op]] = [b[op], b[ep]];\r\n\t\t\t\t\tep++; op++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (ecnt == ocnt) \r\n\t\t\tans = Math.min(ans[0], ans[1]);\r\n\t\telse \r\n\t\t\tans = ecnt > ocnt ? ans[1] : ans[0];\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n"}], "src_uid": "be51a3e4038bd9a3f6d4993b75a20d1c"} {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar m = parseInt(arr[1]);\n// var n = parseInt(readline());\nvar v = Array(n);\nvar arr = readline().split(' ');\nfor (var i = 0; i < n; i ++)\n{\n v[i] = parseInt(arr[i]);\n}\nfor (var i = 0; i < m; i ++)\n{\n var arr = readline().split(' ');\n var l = parseInt(arr[0]);\n var r = parseInt(arr[1]);\n var t = parseInt(arr[2]);\n if (l<=t && t<=r)\n {\n var vs = v.slice(l-1,r);\n // vs.sort(function(a,b){return a-b;});\n var count = 0;\n for (var j = 0; j < r-l+1; j ++)\n {\n if (vs[j] < v[t-1])\n {\n count ++;\n }\n }\n // print(JSON.stringify(vs));\n print(t-l==count?\"Yes\":\"No\");\n }\n else\n {\n print(\"No\");\n }\n}", "positive_code": [{"source_code": "a = readline().split(' ');\nb = parseInt(a[0]);\nc = parseInt(a[1]);\nd = readline().split(' ');\nl = new Array(b);\nfor(x = 0; x < b; x++)\n{\n l[x] = parseInt(d[x]);\n}\nfor(x = 1; x <= c; x++)\n{\n e = readline().split(' ');\n f = parseInt(e[0]);\n g = parseInt(e[1]);\n h = parseInt(e[2]);\n i = l[h - 1];\n j = 0;\n k = h - f;\n for(y = f - 1; y <= g - 1; y++)\n {\n if(l[y] < i)\n {\n j++;\n }\n }\n if(j == k)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}"}], "negative_code": [{"source_code": "a = readline().split(' ');\nb = a[0];\nc = a[1];\nd = readline().split(' ');\nfor(x = 1; x <= c; x++)\n{\n e = readline().split(' ');\n f = e[0];\n g = e[1];\n h = e[2];\n i = d[h - 1];\n j = 0;\n k = h - f;\n for(y = f - 1; y <= g - 1; y++)\n {\n if(d[y] < i)\n {\n j++;\n }\n }\n if(j == k)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}"}, {"source_code": "a = readline().split(' ');\nb = parseInt(a[0]);\nc = parseInt(a[1]);\nd = readline().split(' ');\nfor(x = 1; x <= c; x++)\n{\n e = readline().split(' ');\n f = parseInt(e[0]);\n g = parseInt(e[1]);\n h = parseInt(e[2]);\n i = d[h - 1];\n j = 0;\n k = h - f;\n for(y = f - 1; y <= g - 1; y++)\n {\n if(d[y] < i)\n {\n j++;\n }\n }\n if(j == k)\n {\n print('Yes');\n }\n else\n {\n print('No');\n }\n}"}], "src_uid": "44162a97e574594ac0e598368e8e4e14"} {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, nums) {\r\n nums = nums.map((value) => {\r\n let ret = [];\r\n if(value[0] < value[1]) {\r\n ret = value;\r\n } else {\r\n ret = [value[1], value[0]];\r\n }\r\n return ret;\r\n })\r\n //print(nums.join(' '));\r\n nums.sort((a,b) => {\r\n return a[1] - b[1];\r\n })\r\n //print(nums);\r\n let sum = 0;\r\n for(let i = 0; i < nums.length; i++) {\r\n if(i == 0 ) {\r\n sum += nums[i][1];\r\n }\r\n if(i == nums.length - 1) {\r\n sum += nums[i][1];\r\n }\r\n sum += 2 * nums[i][0];\r\n if(i > 0) {\r\n sum += nums[i][1] - nums[i-1][1];\r\n }\r\n }\r\n print(sum);\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n let nums = [];\r\n for(let j = 0; j < n; j++) {\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n nums.push(x);\r\n }\r\n begin(n, nums);\r\n }\r\n}", "positive_code": [{"source_code": "t = +readline();\r\n\r\nwhile(t--) {\r\n n = +readline();\r\n\r\n a = [];\r\n b = [];\r\n\r\n while(n--) {\r\n side = readline().split(' ');\r\n\r\n a.push(+side[0]);\r\n b.push(+side[1]);\r\n }\r\n\r\n maxA = Math.max(...a);\r\n maxB = Math.max(...b);\r\n\r\n height = Math.max(maxA, maxB);\r\n\r\n width = a.reduce((prevVlue, currentValue, index)=>{\r\n minValue = Math.min(currentValue, b[index]);\r\n\r\n return prevVlue + minValue;\r\n }, 0);\r\n\r\n print(height*2 + width*2);\r\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let a=[],b=[];\r\n let ans=0;\r\n for(let i=1;i<=n;i++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n a.push([x,y]);\r\n b.push(x);\r\n b.push(y);\r\n ans+=2*(x+y);\r\n }\r\n let mx1=-1,mx2=-1,mx3=-1;\r\n for(let i=0;i<2*n;i++)\r\n {\r\n let x=b[i];\r\n if(x>mx1)\r\n {\r\n mx2=mx1;\r\n mx3=mx2;\r\n mx1=x;\r\n }\r\n else if(x>mx2)\r\n {\r\n mx3=mx2;\r\n mx2=x;\r\n }\r\n else if(x>mx3)\r\n {\r\n mx3=x;\r\n }\r\n }\r\n flag=true;\r\n for(let i=0;i1) ans-=2*mx3;\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let a=[],b=[];\r\n let ans=0;\r\n for(let i=1;i<=n;i++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n a.push([x,y]);\r\n b.push(x);\r\n b.push(y);\r\n ans+=2*(x+y);\r\n }\r\n // console.log(a);\r\n // b.sort(function(x,y){\r\n // return x-y;\r\n // });\r\n // console.log(b);\r\n let mx1=-1,mx2=-1,mx3=-1;\r\n for(let i=0;i<2*n;i++)\r\n {\r\n let x=b[i];\r\n if(x>mx1)\r\n {\r\n mx2=mx1;\r\n mx3=mx2;\r\n mx1=x;\r\n }\r\n else if(x>mx2)\r\n {\r\n mx3=mx2;\r\n mx2=x;\r\n }\r\n else if(x>mx3)\r\n {\r\n mx3=x;\r\n }\r\n }\r\n flag=true;\r\n for(let i=0;ix) r=mid-1;\r\n // else l=mid;\r\n // }\r\n // ans-=b[l-1];\r\n // console.log(b[l-1]);\r\n if(flag&&x===mx1)\r\n {\r\n flag=false;\r\n continue;\r\n }\r\n // console.log(ans);\r\n if(x1) ans-=2*mx3;\r\n // flag=false;\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n var n = readline();\r\n var maxY = -inf;\r\n var x = 0;\r\n for(var i=0;i parseInt(w));\r\n maxY = max(maxY, max(a,b));\r\n x += min(a,b);\r\n }\r\n console.log((2*maxY) + (2*x));\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n let sum = 0, max = 0;\r\n\r\n for (let i = 0; i < n; i++) {\r\n const a = parseInt(lines[line].split(' ')[0], 10)\r\n const b = parseInt(lines[line++].split(' ')[1], 10)\r\n sum += Math.min(a, b);\r\n if (max < Math.max(a, b))\r\n max = Math.max(a, b)\r\n }\r\n\r\n sum += max;\r\n console.log(sum * 2)\r\n\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n let res = 0,\r\n max = 0;\r\n for (let i = 0; i < n; i++) {\r\n let [x, y] = rns();\r\n if (x > y) [x, y] = [y, x];\r\n res += x;\r\n max = Math.max(max, y);\r\n }\r\n return (res + max) * 2;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [], "src_uid": "7100fa11adfa0c1f5d33f9e3a1c3f352"} {"source_code": "function readStringArray() {\r\n\t\treturn readline().split(' ');\r\n\t}\r\n\tfunction readNumArray() {\r\n\t\treturn readStringArray().map(Number);\r\n\t}\r\n\r\n\tfunction main() {\r\n\t\tvar testCasesNum = +readline();\r\n\t\tfor (var i = 0; i < testCasesNum; i++) {\r\n\t\t\tvar count = 0;\r\n\t\t\tvar hasOnes = true;\r\n\t\t\tvar s = readline();\r\n\t\t\tfor (var j = 0; j < s.length; j++) {\r\n\t\t\t\tif (s[j] === '0' && hasOnes) {\r\n\t\t\t\t\thasOnes = false;\r\n\t\t\t\t\tcount++;\r\n\t\t\t\t\tif (count === 2) {\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (s[j] === '1') {\r\n\t\t\t\t\thasOnes = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tprint(count);\r\n\t\t}\r\n\t}\r\n\r\n\tmain();", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n const dp = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp, _dp2;\r\n if (s[i] !== s[i - 1] && s[i] === '0') dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;else dp[i] = (_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0;\r\n }\r\n return Math.min(2, dp[n - 1]);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length;\r\n const dp = new Array(n).fill(0);\r\n for (let i = 0; i < n; i++) {\r\n var _dp2, _dp3;\r\n if (s[i] === s[i - 1]) {\r\n var _dp;\r\n dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;\r\n continue;\r\n }\r\n if (s[i] === '0') dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else dp[i] = (_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0;\r\n }\r\n return Math.min(2, dp[n - 1]);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var res = solveMeFirst(b);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(str) {\r\n // console.log(str);\r\n let res,\r\n res2 = 0;\r\n if (str.includes(\"0\") && str.includes(\"1\")) res = 2;\r\n else if (str.includes(\"0\")) res = 1;\r\n else res = 0;\r\n let isOne = false;\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] == \"0\" && !isOne) {\r\n res2 += 1;\r\n isOne = true;\r\n }\r\n if (str[i] == \"1\" && isOne) {\r\n isOne = false;\r\n }\r\n }\r\n // console.log(res2, res);\r\n return res > res2 ? res2 : res;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar s = next().split(\"1\");\r\n\t\tvar count = 0;\r\n\t\tfor(var i = 0; i < s.length; i++){\r\n\t\t\tif(s[i] != ''){\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(Math.min(count, 2));\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nlet standardInputString = '';\r\nlet curLine = 0;\r\n\r\nconst readLine = () => {\r\n return standardInputString[curLine++];\r\n};\r\n\r\nprocess.stdin.on('data', rawData => {\r\n standardInputString += rawData;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split('\\n')\r\n .map(line => {\r\n return line.trim();\r\n });\r\n \r\n main();\r\n});\r\n\r\n/**\r\n * 7\r\n * 0000\r\n * 1111\r\n * 0101\r\n * 110\r\n * 011\r\n * 1011\r\n * 1010\r\n */\r\n\r\n// https://codeforces.com/contest/1566/problem/B\r\nconst main = () => {\r\n const t = +readLine();\r\n\r\n for (let _ = 0; _ < t; _ += 1) {\r\n const str = readLine();\r\n\r\n if (str === '1'.repeat(str.length)) {\r\n console.log(0);\r\n } else {\r\n const withoutOnes = str.replace(/^1+/, '').replace(/1+$/, '');\r\n\r\n if (withoutOnes === '0'.repeat(withoutOnes.length)) {\r\n console.log(1);\r\n } else {\r\n console.log(2);\r\n }\r\n }\r\n }\r\n};"}, {"source_code": "var n = parseInt(readline());\r\n\r\nfor (var i = 0; i < n; i++) {\r\n var s = readline();\r\n var z = s.charAt(0) === '0' ? 1 : 0;\r\n for (var j = 1; j < s.length; j++) {\r\n if (s.charAt(j) === '0' && s.charAt(j-1) === '1')\r\n z += 1;\r\n }\r\n \r\n print(Math.min(z, 2));\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length\r\n const dp = new Array(n + 1).fill(0)\r\n for (let i = 1; i <= n; i++) {\r\n if (s[i - 1] === s[i - 2]) continue\r\n if (s[i - 1] === '1') dp[i] = dp[i - 1]\r\n else dp[i] = dp[i - 1] + 1\r\n }\r\n return Math.min(2, dp[n])\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read());\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n const n = s.length\r\n const dp = new Array(n + 1).fill(0)\r\n for (let i = 1; i <= n; i++) {\r\n if (s[i - 1] === '1') dp[i] = dp[i - 1]\r\n else dp[i - 1] = dp[i - 1] + 1\r\n }\r\n return Math.min(2, dp[n])\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const a = (await read());\r\n res[i] = solve(a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var res = solveMeFirst(b);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(str) {\r\n // console.log(str);\r\n let res,\r\n res2 = 0;\r\n if (str.includes(\"0\") && str.includes(\"1\")) res = 2;\r\n else if (str.includes(\"0\")) res = 1;\r\n else res = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] == \"0\") res2 += 1;\r\n }\r\n // console.log(res2);\r\n return res > res2 ? res2 : res;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\n\r\nvar input_stdin = \"\";\r\nvar input_stdin_array = \"\";\r\nvar input_currentline = 0;\r\n\r\nprocess.stdin.on(\"data\", function (data) {\r\n input_stdin += data;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n input_stdin_array = input_stdin.split(\"\\n\");\r\n // console.log(input_stdin_array);\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return input_stdin_array[input_currentline++];\r\n}\r\n\r\nfunction main() {\r\n var a = readLine();\r\n while (a--) {\r\n var b = readLine();\r\n var res = solveMeFirst(b);\r\n // let out = \"\";\r\n // if (res) {\r\n // for (let i = 0; i < res.length; i++) {\r\n // out += res[i] + \" \";\r\n // }\r\n console.log(res);\r\n // }\r\n }\r\n}\r\nfunction solveMeFirst(str) {\r\n console.log(str);\r\n let res,\r\n res2 = 0;\r\n if (str.includes(\"0\") && str.includes(\"1\")) res = 2;\r\n else if (str.includes(\"0\")) res = 1;\r\n else res = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n if (str[i] == \"0\") res2 += 1;\r\n }\r\n // console.log(res2);\r\n return res > res2 ? res2 : res;\r\n}\r\n\r\n// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));\r\n// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));\r\n"}], "src_uid": "2e6ddb2b11f8ac857e81d4b9b0c7d783"} {"source_code": "function gcd(a, b) {\n return !b ? a : gcd(b, a % b);\n}\n\nvar input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar c = readline().split(' ').map(Number);\n\nvar extract = 1;\nc.forEach(function(num) {\n num /= gcd(num, extract);\n var temp = gcd(num, k);\n k /= temp;\n extract *= temp;\n});\nprint((k === 1) ? 'Yes' : 'No');\n", "positive_code": [{"source_code": "'use strict';\n\n// var inpArr = `\n// 15 91\n// 49 121 83 67 128 125 27 113 41 169 149 19 37 29 71\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nfunction gcd(a, b) {\n return b === 0 ? a : gcd(b, a % b);\n}\nfunction lcm(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar nk = readline().split(' ').map(Number),\n n = nk[0], k = nk[1]\nvar arr = readline().split(' ').map(Number);\n\nvar req = k, acc = 1;\nfor (var i = 0; i < arr.length; i++) {\n arr[i] /= gcd(arr[i], acc);\n var extract = gcd(req, arr[i]);\n req /= extract; acc *= extract;\n if (req === 1) {\n break;\n }\n}\n\n\n\nprint((req === 1) ? 'Yes' : 'No')\n"}], "negative_code": [{"source_code": "'use strict';\n\n// var inpArr = `\n// 2 7\n// 2 3\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nfunction gcd(a, b) {\n return b === 0 ? a : gcd(b, a % b);\n}\nfunction lcm(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar nk = readline().split(' ').map(Number),\n n = nk[0], k = nk[1]\nvar arr = readline().split(' ').map(Number),\n lcmArr = arr.reduce((res,x)=>lcm(res,x), 1);\nprint((lcmArr % k === 0) ? 'Yes' : 'No')\n"}, {"source_code": "'use strict';\n\n// var inpArr = `\n// 15 91\n// 49 121 83 67 128 125 27 113 41 169 149 19 37 29 71\n// `.trim().split('\\n').map(x => x.trim()), inpLine = 0;\n// function readline() {\n// return inpArr[inpLine++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nfunction gcd(a, b) {\n return b === 0 ? a : gcd(b, a % b);\n}\nfunction lcm(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar nk = readline().split(' ').map(Number),\n n = nk[0], k = nk[1]\nvar arr = readline().split(' ').map(Number);\n\nvar req = k;\nfor (var i = 0; i < arr.length; i++) {\n var extract = gcd(req, arr[i]);\n req /= extract;\n if (req === 1) {\n break;\n }\n}\n\n\n\nprint((req === 1) ? 'Yes' : 'No')\n"}, {"source_code": "function gcd(a, b) {\n return !b ? a : gcd(b, a % b);\n}\nfunction lcmOfTwo(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar c = readline().split(' ').map(Number);\n\nvar lcm = 1;\nc.forEach(function(num) {\n lcm = lcmOfTwo(lcm, gcd(num, k));\n});\nprint(lcm)\nprint((lcm%k === 0) ? 'Yes' : 'No');\n"}, {"source_code": "function gcd(a, b) {\n return !b ? a : gcd(b, a % b);\n}\nfunction lcmOfTwo(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar c = readline().split(' ').map(Number);\n\nvar lcm = 1;\nc.forEach(function(n) {\n lcm = lcmOfTwo(lcm, n);\n});\nprint((lcm%k === 0) ? 'Yes' : 'No');\n"}, {"source_code": "function gcd(a, b) {\n return !b ? a : gcd(b, a % b);\n}\n\nvar input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar c = readline().split(' ').map(Number);\n\nvar extract = 1;\nc.forEach(function(num) {\n num /= gcd(num, extract);\n k /= gcd(num, k);\n extract *= gcd(num, k);\n});\nprint((k === 1) ? 'Yes' : 'No');\n"}, {"source_code": "function gcd(a, b) {\n return !b ? a : gcd(b, a % b);\n}\nfunction lcmOfTwo(a, b) {\n return (a * b) / gcd(a, b);\n}\n\nvar input = readline().split(' ').map(Number);\nvar n = input[0], k = input[1];\nvar c = readline().split(' ').map(Number);\n\nc.forEach(function(num) {\n k /= gcd(num, k);\n});\nprint((k === 1) ? 'Yes' : 'No');\n"}], "src_uid": "e72fa6f8a31c34fd3ca0ce3a3873ff50"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n// let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let obj = {};\r\n let res = [],\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 0 && flag === 0) {\r\n flag = 1;\r\n res.push(0);\r\n } else if (arr[i] === 0 && flag === 1) continue;\r\n else res.push(arr[i]);\r\n }\r\n if (res.length === 1) console.log(\"YES\");\r\n else if (res.length > 5) console.log(\"NO\");\r\n else {\r\n for (let i = 0; i < res.length; i++) {\r\n if (obj[res[i]] === undefined) obj[res[i]] = 1;\r\n }\r\n flag = 0;\r\n for (let i = 0; i < res.length; i++) {\r\n for (let j = i + 1; j < res.length; j++) {\r\n for (let k = j + 1; k < res.length; k++) {\r\n let sum = res[i] + res[j] + res[k];\r\n if (obj[sum] !== 1) {\r\n flag = 1;\r\n }\r\n }\r\n }\r\n }\r\n if (flag === 1) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m) {\r\n if (!lookup[(test[l] + test[m] + test[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const nums = [],\r\n map = new Map();\r\n for (let num of a) {\r\n var _map$get;\r\n map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n if (num !== 0 && map.get(num) > 2) return 'NO';\r\n if (map.get(num) <= 2) nums.push(num);\r\n }\r\n const N = nums.length;\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n for (let k = j + 1; k < N; k++) {\r\n if (!map.has(nums[i] + nums[j] + nums[k])) return 'NO';\r\n }\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n if (i === 750) {\r\n output(arr.filter(num => num !== 0));\r\n return;\r\n }\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n if (i === 750) {\r\n output(arr.filter(num => num !== 0).length);\r\n return;\r\n }\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n if (i === 750) {\r\n output(arr.join(','));\r\n return;\r\n }\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n if (i === 750) {\r\n output(n);\r\n return;\r\n }\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n if (i === 750) {\r\n output(n + ' ' + arr.join(','));\r\n return;\r\n }\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n const zero = arr.filter(num => num === 0).slice(0, 2);\r\n const test = nonZero.concat(zero);\r\n if (nonZero.length > 4) {\r\n output('NO');\r\n continue;\r\n }\r\n let result = 'YES';\r\n for (let l = 0; l < test.length; l++) {\r\n for (let m = 1; m < test.length; m++) {\r\n for (let n = 2; n < test.length; n++) {\r\n if (l !== m && l !== n && n !== m && !lookup[arr[l] + arr[m] + arr[n]]) {\r\n result = 'NO';\r\n }\r\n }\r\n }\r\n }\r\n output(result);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n \r\nfunction main() {\r\n let N = readline();\r\n \r\n for (let i = 0; i < N; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(' ').map(Number);\r\n const lookup = {};\r\n for (let num of arr) lookup[num] = true;\r\n if (n === 3) {\r\n output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');\r\n continue;\r\n }\r\n const nonZero = arr.filter(num => num !== 0);\r\n if (nonZero.length < 2) {\r\n output('YES');\r\n } else if (nonZero.length === 2) {\r\n const areInverse = nonZero[0] === -1 * nonZero[1];\r\n output(areInverse ? 'YES' : 'NO');\r\n } else {\r\n output('NO');\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';\r\n let nums = [],\r\n map = new Map(),\r\n zero = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) {\r\n var _map$get;\r\n nums.push(a[i]);\r\n map.set(a[i], ((_map$get = map.get(a[i])) !== null && _map$get !== void 0 ? _map$get : 0) + 1);\r\n } else zero++;\r\n }\r\n if (zero) {\r\n if (nums.length < 2) return 'YES';\r\n if (nums.length === 2) {\r\n return nums[0] + nums[1] === 0 ? 'YES' : 'NO';\r\n } else {\r\n return 'NO';\r\n }\r\n } else {\r\n if (map.size !== 2) return 'NO';\r\n const [x, y] = [...map];\r\n if (x[0] + y[0] !== 0) return 'NO';\r\n if (x[1] > 2 || y[1] > 2) return 'NO';\r\n return 'YES';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';\r\n let nums = [],\r\n set = new Set(),\r\n zero = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) {\r\n nums.push(a[i]);\r\n set.add(a[i]);\r\n } else zero++;\r\n }\r\n if (zero) {\r\n if (nums.length < 2) return 'YES';\r\n if (nums.length === 2) {\r\n return nums[0] + nums[1] === 0 ? 'YES' : 'NO';\r\n } else {\r\n return 'NO';\r\n }\r\n } else {\r\n if (set.size > 2) return 'NO';\r\n const [x, y] = [...set];\r\n if (x + y === 0) return 'YES';\r\n return 'NO';\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';\r\n let nums = [],\r\n set = new Set(),\r\n zero = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) {\r\n nums.push(a[i]);\r\n set.add(a[i]);\r\n } else zero++;\r\n }\r\n if (zero) {\r\n if (nums.length === 2) {\r\n return nums[0] + nums[1] === 0 ? 'YES' : 'NO';\r\n } else if (nums.length > 2) {\r\n return 'NO';\r\n }\r\n } else {\r\n if (set.size > 2) return 'NO';\r\n const [x, y] = [...set];\r\n if (x + y !== 0) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';\r\n let nums = [];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) nums.push(a[i]);\r\n }\r\n if (nums.length === 2) {\r\n return nums[0] + nums[1] === 0 ? 'YES' : 'NO';\r\n } else if (nums.length > 2) {\r\n return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 3) return a.reduce((a, b) => a + b, 0) === 0 ? 'YES' : 'NO';\r\n let nums = [];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] !== 0) nums.push(a[i]);\r\n }\r\n if (nums.length === 2) {\r\n return nums[0] + nums[1] === 0 ? 'YES' : 'NO';\r\n } else if (nums.length > 2) {\r\n return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let nums = [];\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 0) ;else nums.push(a[i]);\r\n }\r\n if (nums.length > 2) return 'NO';\r\n if (nums.length <= 1) return 'YES';\r\n if (nums[0] + nums[1] === 0) return 'YES';\r\n return 'NO';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const set = new Set(a);\r\n a.sort((a, b) => a - b);\r\n for (let i = 2; i < n; i++) {\r\n const sum = a[i] + a[i - 1] + a[i - 2];\r\n if (!set.has(sum)) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let obj = {};\r\n let res = [],\r\n flag = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] === 0 && flag === 0) {\r\n flag = 1;\r\n res.push(0);\r\n }\r\n res.push(arr[i]);\r\n }\r\n if (res.length > 5) console.log(\"NO\");\r\n else {\r\n for (let i = 0; i < res.length; i++) {\r\n if (obj[res[i]] === undefined) obj[res[i]] = 1;\r\n }\r\n flag = 0;\r\n for (let i = 0; i < res.length; i++) {\r\n for (let j = i + 1; j < res.length; j++) {\r\n for (let k = j + 1; k < res.length; k++) {\r\n let sum = res[i] + res[j] + res[k];\r\n if (obj[sum] !== 1) {\r\n flag = 1;\r\n }\r\n }\r\n }\r\n }\r\n if (flag === 1) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let obj = {};\r\n let res = [];\r\n if (arr.length === 3) {\r\n let k = arr[0] + arr[1] + arr[2];\r\n if (k === arr[0] || k === arr[1] || k === arr[2]) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n continue;\r\n }\r\n for (let i = 0; i < n; i++) if (arr[i] !== 0) res.push(arr[i]);\r\n if (res.length === 0) console.log(\"YES\");\r\n else {\r\n if (res.length > 2) console.log(\"NO\");\r\n else {\r\n if (Math.abs(res[0]) === Math.abs(res[1])) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n let arr = iInpArr();\r\n let obj = {};\r\n for (let i = 0; i < n; i++) {\r\n if (obj[arr[i]] === undefined) obj[arr[i]] = 1;\r\n }\r\n let k = arr[0] + arr[1] + arr[2];\r\n if (obj[k] !== 1) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n let flag = 1;\r\n for (let i = 3; i < n; i++) {\r\n if (arr[i] !== 0) {\r\n flag = 0;\r\n break;\r\n }\r\n }\r\n if (flag === 1) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "70028bbb9b7bce1f0d2753275b3e752f"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const [len, t] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n arr.sort((a, b) => a - b);\n let result = 0;\n for (let i = 0; i < t; i++) {\n if (arr[i] < 0) result += Math.abs(arr[i]);\n }\n\n console.log(result);\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n let sum = 0;\n\n for (let i = 0; i < m; i++) {\n if (arr[i] < 0) {\n sum += Math.abs(arr[i]);\n }\n }\n\n console.log(sum);\n\n c++;\n});\n"}, {"source_code": "// input function\n// to take input use in = await input() \nfunction input(){\n return new Promise ( (resolve , error) => { \n process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });\n });\n}\n\nasync function main(){\n data = (await input()).split(\"\\r\\n\");\n var temp = data[0].split(\" \");\n var n = Number(temp[0]),\n m = Number(temp[1]);\n \n temp = data[1].split(\" \");\n var arr = [];\n for(i = 0; i < n; i++){\n arr.push(Number(temp[i]));\n }\n arr.sort(function(a, b){return a - b});\n var ans = 0;\n for(i = 0; i < m && arr[i] < 0; i++){\n ans += arr[i] * -1;\n }\n console.log(ans);\n \n}\nmain();\n"}, {"source_code": "var l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar a=readline().split(' ').map(function(v){return +v;});\na.sort(function(a, b){\n\treturn a-b;\n});\n\nvar ans=0;\nfor(var i=0; iNumber(e));\nvar b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);\n\nif (b.length === 0){\n\tprint(0);\n} else {\n\tprint(-(b.reduce((prev,next)=>prev+next)));\n}"}, {"source_code": "var n = readline().split(' ').map(function(x) {return parseInt(x);});\nvar a = readline().split(' ').map(function(x) {return parseInt(x);}).sort(function(a, b){return a - b;});\nvar res = 0, carried = 0;\n\nfor(var i = 0; i < n[0]; ++i)\n\tif(a[i] >= 0 || carried >= n[1])\n\t\tbreak;\n\telse\n\t{\n\t\tres -= a[i];\n\t\t++carried;\n\t}\nwrite(res);"}, {"source_code": "var t = readline().split(' ').map(cur => Number(cur));\nvar inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {\nreturn a-b; \n});\nvar sum = 0;\nfor (var i = 0; i < t[1]; i++){\n if(inp[i] <= 0)\n sum-= inp[i];\n} \nprint(sum);\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet p = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tp.sort((a, b) => a - b);\n\tlet s = 0;\n\tfor (let i = 0; i < m; ++i) if (p[i] < 0) s += p[i];\n\n\ts = s < 0 ? s * -1 : s;\n\tconsole.log(s);\n}\n"}, {"source_code": ";(function () {\n\tprint(function (n, m) {\n\t\tvar s = readline().split(' ').map(Number).filter(function (e) { return e < 0; }).sort(function (a, b) { return a - b; }),\n\t\t\tl = 0, k = 0;\n\n\t\tfor (var i = 0, _i = Math.min(m, s.length); i < _i; i++) {\n\t\t\tl += -s[i];\t\t\t\n\t\t}\n\n\t\treturn l;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let [n, m] = readLine().split(' ').map(Number);\n let prices = readLine().split(' ').map(Number);\n prices.sort((a, b) => {\n return a - b;\n });\n let final = 0;\n for (let i = 0; i < m; i++) {\n if (Math.sign(prices[i]) === -1) {\n final += Math.abs(prices[i]);\n }\n }\n console.log(final);\n}\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar itemNum = integers[0], capacity = integers[1];\n\n\tvar weights = tokenizeIntegers(readline());\n\tweights.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\n\tvar total = 0;\n\tfor (var i = 0; i < capacity; ++i) {\n\t\tif (weights[i] >= 0) {\n\t\t\tbreak;\n\t\t}\n\t\ttotal -= weights[i];\n\t}\n\tprint(total);\n}\n\nmain();\n"}, {"source_code": "\t//this code is written by ashraf\n\nvar n = readline().split(' ');\nvar ll = readline().split(\" \").sort((a,b)=>a-b);\nvar llsort = [];\nfor(var i=0;i parseInt(v))\nlet N = lll[0]\nlet M = lll[1]\nlet res = readline().split(' ').map(v => parseInt(v))\n .filter(v => v < 0)\n .sort((a, b) => a - b)\n .slice(0, M)\n .reduce((r, v) => r + v, 0)\n\nprint(-res)"}, {"source_code": " var inp = readline().split(' ').map(v => parseInt(v));\n var n = inp[0];\n var max = inp[1];\n var sorted = readline().split(' ')\n\t\t\t .map(e=>Number(e))\n\t\t\t .filter(x=> x < 0)\n\t\t\t .sort(function(a,b){return a - b});\n var sum = 0;\n \n for (var i=0; i {\n if ( n && m && c < 2) {\n let prices = input.trim().split(' ').map(x => +x)\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}], "negative_code": [{"source_code": "var l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar a=readline().split(' ').map(function(v){return +v;});\na.sort(function(a, b){\n\treturn a-b;\n});\n\nvar ans=0;\nfor(var i=0; i= 0; --i)\n\tif(a[i] >= 0 || carried >= n[1])\n\t\tbreak;\n\telse\n\t{\n\t\tres -= a[i];\n\t\t++carried;\n\t}\nwrite(res);"}, {"source_code": "var n = readline().split(' ').map(function(x) {return parseInt(x);});\nvar a = readline().split(' ').map(function(x) {return parseInt(x);}).sort();\nvar res = 0, carried = 0;\n\nfor(var i = n[0] - 1; i >= 0; --i)\n\tif(a[i] >= 0 || carried >= n[1])\n\t\tbreak;\n\telse\n\t{\n\t\tres -= a[i];\n\t\t++carried;\n\t}\nwrite(res);"}, {"source_code": "var n = readline().split(' ').map(function(x) {return parseInt(x);});\nvar a = readline().split(' ').map(function(x) {return parseInt(x);});\na.sort();\nvar res = 0, \n\tcarried = 0;\nfor(var i = 0; i < n[0]; ++i)\n\tif(a[i] >= 0 || carried >= n[1])\n\t\tbreak;\n\telse\n\t{\n\t\tres -= a[i];\n\t\t++carried;\n\t}\nwrite(res);"}, {"source_code": ";(function () {\n\tprint(function (n, m) {\n\t\tvar s = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),\n\t\t\tl = 0, k = 0;\n\n\t\tfor (var i = 0; i < n && k < m; i++) {\n\t\t\tif (s[i] <= l) {\n\t\t\t\tl -= s[i];\n\t\t\t\tk++\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn l;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar itemNum = integers[0], capacity = integers[1];\n\n\tvar weights = tokenizeIntegers(readline());\n\tweights.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\n\tvar total = 0;\n\tfor (var i = 0; i < capacity; ++i) {\n\t\ttotal -= weights[i];\n\t}\n\tprint(total);\n}\n\nmain();\n"}, {"source_code": " var inp = readline().split(' ').map(v => parseInt(v));\n var n = inp[0];\n var max = inp[1];\n var sorted = readline().split(' ')\n\t\t\t .filter(x=> x < 0)\n\t\t\t .sort(function(a,b){return a - b});\n var sum = 0;\n \n for (var i=0; i parseInt(v));\n var n = inp[0];\n var max = inp[1];\n var sorted = readline().split(' ').map(e=>Number(e)).sort();\n var sum = 0;\n \n for (var i=0; i parseInt(v));\n var n = inp[0];\n var max = inp[1];\n var sorted = readline().split(' ').map(e=>Number(e)).sort();\n var sum = 0;\n \n for (var i=0; iNumber(e));\nvar b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);\n\nif (b.length === 0){\n\tprint(0);\n} else {\n\tprint(b.reduce((prev,next)=>prev+next));\n}"}, {"source_code": "'use strict';\n\nvar a = readline().split(' ');\nvar b = readline().split(' ').map(function (e) {\n\treturn Number(e);\n}).filter(function (e) {\n\treturn e < 0;\n});\n\nif (b.length === 0) {\n\tprint(0);\n} else {\n\tvar p = new Promise(function (resolve, reject) {\n\t\tvar what = 0;\n\t\tfor (var i = 0; i < a[1]; i++) {\n\t\t\tvar max = b.reduce(function (prev, next) {\n\t\t\t\treturn Math.max(prev, next);\n\t\t\t});\n\t\t\tb.pop(b.indexOf(max));\n\t\t\twhat += max;\n\t\t}\n\t\tresolve(what);\n\t});p.then(function (data) {\n\t\tprint(what);\n\t});\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').filter(e=>Number(e)<0).map(e=>Number(e)).sort().slice(0,a[0]).reduce((prev,next)=>prev+next);\nprint(b);"}, {"source_code": "'use strict';\n\nvar a = readline().split(' ');\nvar b = readline().split(' ').map(function (e) {\n\treturn Number(e);\n}).filter(function (e) {\n\treturn e < 0;\n});\n\nif (b.length === 0) {\n\tprint(0);\n} else {\n\tvar p = new Promise(function (resolve, reject) {\n\t\tvar what = 0;\n\t\tfor (var i = 0; i < a[1]; i++) {\n\t\t\tvar max = b.reduce(function (prev, next) {\n\t\t\t\treturn Math.max(prev, next);\n\t\t\t});\n\t\t\tb.pop(b.indexOf(max));\n\t\t\twhat += max;\n\t\t}\n\t\tresolve(what);\n\t});p.then(function (data) {\n\t\tprint(data);\n\t});\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').map(e=>Number(e)).filter(e=>e<0);\n\nif (b.length === 0){\n\tprint(0);\n} else {\n\tvar p = new Promise((resolve,reject)=>{\n\t\tvar what = 0;\n\t\tfor(var i = 0; i < a[1]; i++){\n\t\t\tvar max = b.reduce((prev,next)=>Math.max(prev,next));\n\t\t\tb.pop(b.indexOf(max));\n\t\t\twhat+=max;\n\t\t}\n\t\tresolve(what);\n\t}); p.then(data=>{\n\t\tprint(what);\n\t})\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[1]);\nif (b.length === 0){\n\tprint(0);\n} else {\n\tprint(-(b.reduce((prev,next)=>prev+next)));\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);\nif (b.length === 0){\n\tprint(0);\n} else {\n\tprint(-(b.reduce((prev,next)=>prev+next)));\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').map(e=>Number(e)).sort().reverse().filter(e=>Number(e)<0).slice(0,a[1]);\nif (b.length === 0){\n\tprint(0);\n} else {\n\tprint(-(b.reduce((prev,next)=>prev+next)));\n}"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);\nif (b === []){\n\tprint(0);\n} else {\n\tprint(b.reduce((prev,next)=>prev+next));\n}"}, {"source_code": "var t = readline().split(' ').map(cur => Number(cur));\nvar inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {\nreturn a-b; \n});\nvar sum = 0;\nfor (var i = 0; i < t[1]; i++){\n sum-= inp[i];\n} \nprint(sum);\n//"}, {"source_code": "var t = readline().split(' ').map(cur => Number(cur));\nvar inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {\nreturn a-b; \n});\nvar sum = 0;\nfor (var i = 0; i < t[1]; i++){\n sum-= inp[i];\n} \nprint(sum);\n"}, {"source_code": "//this code is written by ashraf\n\nvar n = readline().split(' ');\nvar ll = readline().split(\" \").sort((a,b)=>a-b);\nvar llsort = [];\nfor(var i=0;ia-b);\n\nvar ashraf =0\n\nfor(var x = 0;xa-b);\n\nvar ashraf =0\n\nfor(var x = 0;x {\n if ( n && m && c < 2) {\n let prices = input.split(' ').map(x => {\n if (x) {\n return +x\n }\n })\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n } else {\n result -= price\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, c = 0;\nrl.on('line', input => {\n if ( n && m && c < 2) {\n let prices = input.trim().split(' ').map(x => +x)\n console.log(prices)\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n } else {\n result -= price\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, c = 0;\nrl.on('line', input => {\n if ( n && m && c < 2) {\n let prices = input.trim().split(' ').map(x => +x)\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n } else {\n result -= price\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, c = 0;\nrl.on('line', input => {\n if ( n && m && c < 2) {\n let prices = input.split(' ').map(x => +x);\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n } else {\n result -= price\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, c = 0;\nrl.on('line', input => {\n if ( n && m && c < 2) {\n let prices = input.split(' ').map(x => +x);\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += -price\n } else {\n result -= price\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet n, m, c = 0;\nrl.on('line', input => {\n if ( n && m && c < 2) {\n let prices = input.trim().split(' ').map(x => +x)\n function swap(items, a, b) {\n let k = items[a];\n items[a] = items[b];\n items[b] = k;\n }\n function partition(items, left, right) {\n var pivot = items[Math.floor((right + left) / 2)],\n i = left,\n j = right;\n while (i <= j) {\n while (items[i] < pivot && i <= j) {\n i++;\n }\n while (items[j] > pivot) {\n j--;\n }\n if (i <= j && i <= j) {\n swap(items, i, j);\n i++;\n j--;\n }\n }\n return i;\n }\n function sorting (items, left, right) {\n let index;\n \n if (items.length > 1) {\n index = partition(items, left, right);\n if ( left < index - 1){\n sorting(items, left, index - 1);\n }\n if (right > index - 1) {\n sorting(items, index, right)\n }\n }\n return items\n }\n let semiresult = sorting(prices, 0, prices.length -1);\n semiresult = semiresult.slice(0, m - 1);\n let result = 0;\n semiresult.map(price => {\n if (price < 0) {\n result += price * -1\n }\n })\n c++\n console.log(result)\n rl.close()\n } else { \n [n, m] = input.split(' ').map(x => +x);\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n let sum = 0;\n\n for (let i = 0; i < m; i++) {\n sum += Math.abs(arr[i]);\n }\n\n console.log(sum);\n\n c++;\n});\n"}, {"source_code": "// input function\n// to take input use in = await input() \nfunction input(){\n return new Promise ( (resolve , error) => { \n process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });\n });\n}\n\nasync function main(){\n data = (await input()).split(\"\\r\\n\");\n var temp = data[0].split(\" \");\n var n = Number(temp[0]),\n m = Number(temp[1]);\n \n temp = data[1].split(\" \");\n var arr = [];\n for(i = 0; i < n; i++){\n arr[i] = Number(temp[i]);\n }\n arr = arr.sort();\n var ans = 0;\n for(i = 0; i < n; i++){\n if(arr[i] < 0 && i < m) ans += arr[i] * -1;\n }\n console.log(ans);\n \n}\nmain();\n"}, {"source_code": "// input module\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// input function\n// to take input use in = await input() \nfunction input(){\n return new Promise ( (resolve , error) => {\n readline.question('', (data) => {\n resolve(data);\n });\n });\n}\n\nasync function main(){\n\n\n const n = Number(await input());\n const m = Number(await input());\n var arr = []\n for(i = 0; i < n; i++) arr[i] = Number(await input());\n arr = arr.sort();\n var ans = 0;\n for(i = 0; i < n; i++){\n if(arr[i] < 0) ans += arr[i] * -1;\n }\n console.log(ans);\n\n // to end the terminal\n readline.close();\n}\nmain();\n"}, {"source_code": "// input module\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// input function\n// to take input use in = await input() \nfunction input(){\n return new Promise ( (resolve , error) => {\n readline.question('', (data) => {\n resolve(data);\n });\n });\n}\n\nasync function main(){\n\n\n var temp = (await input()).split(\" \");\n var n = Number(temp[0]);\n var m = Number(temp[1]);\n temp = (await input()).split(\" \");\n var arr = [];\n for(i = 0; i < n; i++){\n arr[i] = Number(temp[i]);\n }\n arr = arr.sort();\n var ans = 0;\n for(i = 0; i < n; i++){\n if(arr[i] < 0) ans += arr[i] * -1;\n }\n console.log(ans);\n\n // to end the terminal\n readline.close();\n}\nmain();\n"}, {"source_code": "// input function\n// to take input use in = await input() \nfunction input(){\n return new Promise ( (resolve , error) => { \n process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });\n });\n}\n\nasync function main(){\n data = (await input()).split(\"\\r\\n\");\n var temp = data[0].split(\" \");\n var n = Number(temp[0]),\n m = Number(temp[1]);\n \n temp = data[1].split(\" \");\n var arr = [];\n for(i = 0; i < n; i++){\n arr.push(Number(temp[i]));\n }\n arr = arr.sort();\n var ans = 0;\n for(i = 0; i < n; i++){\n if(arr[i] < 0 && i < m) ans += arr[i] * -1;\n }\n console.log(ans);\n \n}\nmain();\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet p = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tp.sort((a, b) => a - b);\n\tlet s = 0;\n\tfor (let i = 0; i < m; ++i) {\n\t\ts += p[i];\n\t}\n\ts = s < 0 ? s * -1 : s;\n\tconsole.log(s);\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nvar dp = {};\n\nfunction fibonacci(n) {\n\tif (n === 0) return 0;\n\tif (n === 1) return 1;\n\n\tif (dp[n] !== undefined) return dp[n];\n\tlet result = fibonacci(n - 1) + fibonacci(n - 2);\n\treturn (dp[n] = result);\n}\n\nfunction main() {\n\tlet [n, m] = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet p = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tp.sort((a, b) => a - b);\n\tlet s = 0;\n\tfor (let i = 0; i < m; ++i) {\n\t\ts += p[i];\n\t}\n\tconsole.log(s);\n}\n"}], "src_uid": "9a56288d8bd4e4e7ef3329e102f745a5"} {"source_code": "var t = parseInt(readline());\n\n\nwhile(t--){\n var n = parseInt(readline());\n var ones = Math.floor(n/2); \n\n var result = \"\";\n if (n % 2 == 1)\n {\n result += \"7\";\n ones--;\n }\n\n while(ones--)\n {\n result += \"1\";\n }\n\n print(result);\n}", "positive_code": [{"source_code": "T=+readline()\nfor (i=0;i (n%2 ? '7' : '1') + '1'.repeat((n>>1) - 1);\n\nlet t = +readline()\nwhile(t--) print(problem(+readline()))\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n if(n == 2){\n output.push(\"1\");\n }else if(n == 3){\n output.push(\"7\");\n }else{\n if(n % 2 == 0){\n output.push(new Array(n/2).fill(\"1\").join(\"\"));\n }else{\n output.push(\"7\" + new Array((n-3)/2).fill(\"1\").join(\"\"));\n }\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "'use strict';\n\nfunction a(n) {\n if (n % 2 === 1) {\n return '7' + '1'.repeat((n-3)/2);\n }\n return '1'.repeat(n/2);\n}\n\n\nfunction main() {\n const t = Number(readline());\n for(let i = 0; i < t; i++) {\n const n = Number(readline());\n print(a(n));\n }\n}\n\nmain();"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet ans = \"\";\nconst obj = {\n 0: 6,\n 1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6,\n};\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let val = \"\";\n\n if (n % 2 === 0) {\n val += \"1\".repeat(n / 2);\n } else {\n val += \"7\";\n n -= 3;\n val += \"1\".repeat(n / 2);\n }\n\n ans += `${val}\\n`;\n\n c++;\n});\n\nrl.on(\"close\", () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\nlet ans = \"\";\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let n = +d;\n let val = \"\";\n\n if (n % 2) {\n val += \"7\";\n n -= 3;\n }\n\n val += \"1\".repeat(n / 2);\n ans += `${val}\\n`;\n\n c++;\n});\n\nrl.on(\"close\", () => {\n console.log(ans);\n});\n"}, {"source_code": "let i = ''\nvar segments = {\n 1: 2,\n 7: 3,\n}\nvar segmentHistory = new Map();\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n for (var index = 1; index < lines.length; index++) {\n segmentHistory = new Map();\n console.log(largestNum(lines[index]))\n }\n})\n\nfunction largestNum(n) {\n var arr = []\n if (n % 2 === 1) {\n arr.length = (n-3)/2\n arr.fill('1')\n return '7' + arr.join('')\n }\n else {\n arr.length = n/2\n arr.fill('1')\n return arr.join('')\n }\n}"}, {"source_code": "const calc = (d, x) => Math.ceil( d / (x + 1) + x)\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=1; j<=num; j++){\n let n = +lines[j]\n let result = ''\n if (n%2 === 1) {\n result = '7'\n n -= 2\n }\n for (let r = n; r > 1; r -= 2) {\n result += '1'\n }\n console.log(result)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "const calc = (d, x) => Math.ceil( d / (x + 1) + x)\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=1; j<=num; j++){\n const n = +lines[j]\n let result = ''\n for (let r = n; r > 1; r -= 2) {\n if (n == 3) {\n result += '7'\n } else {\n result += '1'\n }\n }\n console.log(result)\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "T=+readline()\nfor (i=0;i '1'.repeat((n>>1) - 1) + (n%2 ? '7' : '1')\n\nlet t = +readline()\nwhile(t--) print(problem(+readline()))\n"}, {"source_code": "let i = ''\nvar segments = {\n 1: 2,\n 7: 3,\n}\nvar segmentHistory = new Map();\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL)\n for (var index = 1; index < lines.length; index++) {\n segmentHistory = new Map();\n console.log(largestNum(lines[index]))\n console.log(segmentHistory)\n }\n})\n\nfunction largestNum(n) {\n if (segmentHistory.has(n)) return segmentHistory.get(n)\n if (n <= 1) return ''\n var largest = -1\n for (const num in segments) {\n var cur = ''\n if (segments[num] <= n) {\n cur = num + largestNum(n-segments[num])\n }\n largest = Math.max(largest, +cur)\n }\n segmentHistory.set(n, largest)\n return largest\n}"}], "src_uid": "07db573b0db736d798b6c18c06c32f3d"} {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if(lines[j] % 7 === 0){\n c = lines[j] \n console.log(c)\n\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n console.log(c)\n\n }\n }\n}); \n", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var y = readline();\r\n var n = parseInt(y);\r\n if(n % 7 == 0) {\r\n console.log(n);\r\n continue;\r\n }\r\n n -= n%10;\r\n while(n%7 !== 0) n++\r\n console.log(n);\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j].split('').map(Number);\n var a = k[k.length - 1];\n var b = lines[j] - a + 1;\n if(lines[j] % 7 === 0){\n b = lines[j] ;\n console.log(b);\n }else{\n while(b % 7 !== 0){\n b++;\n if(b % 7 === 0){\n break;\n }\n }\n console.log(b);\n }\n }\n}); "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input =parseInt(readline());\r\n if(input < 10) console.log(7)\r\n else if(input%7 == 0) console.log(input)\r\n else{\r\n if(input%7 <= input%10){\r\n console.log(input-input%7);\r\n }else{\r\n console.log(input+(7-input%7));\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\nfunction differentDigits(a, b) {\r\n a = \"\" + a;\r\n b = \"\" + b;\r\n if (a.length !== b.length) {\r\n return false;\r\n }\r\n let count = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] !== b[i]) {\r\n count++;\r\n }\r\n }\r\n return count;\r\n}\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0].trim());\r\n let i = 1;\r\n let dividends = [];\r\n for (let i = 0; i <= 999; i += 7) {\r\n dividends.push(i);\r\n }\r\n while (t--) {\r\n let n = parseInt(lines[i++].trim());\r\n let min = 5;\r\n let result;\r\n for (let i = 0; i < dividends.length; i++) {\r\n let x = differentDigits(n, dividends[i]);\r\n if (x === false) {\r\n continue;\r\n }\r\n if (x < min) {\r\n min = x;\r\n result = dividends[i];\r\n }\r\n }\r\n console.log(result);\r\n }\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let rem = n % 7;\r\n if (rem === 0) {\r\n output(n);\r\n continue;\r\n }\r\n\r\n let zeroLast = Math.floor(n / 10) * 10;\r\n\r\n for (let i = 0; i < 10; i++) {\r\n if ((zeroLast + i) % 7 === 0) {\r\n output(zeroLast + i);\r\n break;\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tif(N % 7 == 0){\r\n\t\t\tmyout(N);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar S = [];\r\n\t\twhile(N > 0){\r\n\t\t\tS.unshift(N % 10);\r\n\t\t\tN = Math.floor(N / 10);\r\n\t\t}\r\n\t\tvar max = 4;\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i <= 999; i += 7){\r\n\t\t\tvar L = [];\r\n\t\t\tvar V = i;\r\n\t\t\twhile(V > 0){\r\n\t\t\t\tL.unshift(V % 10);\r\n\t\t\t\tV = Math.floor(V / 10);\r\n\t\t\t}\r\n\t\t\tif(L.length != S.length){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tvar c = 0;\r\n\t\t\tfor(var j = 0; j < 3; j++){\r\n\t\t\t\tif(L[j] != S[j]){\r\n\t\t\t\t\tc++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(max > c){\r\n\t\t\t\tmax = c;\r\n\t\t\t\toutput = i;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let num = parseInt(readLine());\r\n if (num % 7 == 0) return num;\r\n let boundary1 = parseInt(num / 10) * 10;\r\n let boundary2 = parseInt(num / 10) * 10 + 9;\r\n let rem = num % 7;\r\n if ((num - rem) >= boundary1 && (num - rem) <= boundary2)\r\n return num - rem;\r\n return num + 7 - rem;\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n % 7) {\n if (n < 10) return 7\n const r = n % 10\n const add = 7 - n % 7\n if (r + add < 10) {\n return n + add\n } else {\n return n - n % 7\n }\n } else {\n return n\n }\n}\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet x = nl.num();\n\t\t\n\t\tif (x % 7 == 0) {\n\t\t\tans.push(x);\n\t\t} else if (x % 10 - x % 7 > 0) {\n\t\t\tans.push(x - x % 7);\n\t\t} else {\n\t\t\tans.push(x + (7 - x % 7));\n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = readline();\r\n let input = Number(readline());\r\n let nums = [];\r\n nums.push(input);\r\n \r\n for(let i = 2; i <= t; i++ ) {\r\n input = Number(readline());\r\n nums.push(input)\r\n }\r\n\r\n \r\n for(let num of nums) {\r\n if (num % 7 === 0) {\r\n console.log(num)\r\n continue;\r\n }\r\n\r\n let arrFromNum = String(num).split('');\r\n for (let i = 0; i < arrFromNum.length; i++) {\r\n let curArr = arrFromNum.concat();\r\n for (let j = 1; j <= 9; j++) {\r\n curArr[i] = j;\r\n let newNum = Number(curArr.join(''));\r\n if (newNum % 7 === 0) {\r\n console.log(newNum);\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n}"}, {"source_code": "var t = +readline();\r\n \r\n \r\nwhile(t--) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var nNew = n - n%10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var nNew = n - n%10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var notAtZero = n%10;\r\n var nNew = notAtZero ? Math.floor(n/10)*10 : n;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n //var nNew = Math.floor(n/10)*10;\r\n var nNew = n - n%10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var nNew = Math.floor(n/10)*10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var nNew = Math.floor(n/10)*10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfunction singleTest(n) {\r\n if (n % 7 === 0) return n;\r\n var nNew = Math.floor(n/10)*10;\r\n var remainder = nNew % 7;\r\n return remainder ? nNew + 7 - remainder : nNew;\r\n}\r\n\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var number = parseInt(readline());\r\n print(singleTest(number));\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n if (n % 7 === 0) {\r\n print(n);\r\n } else {\r\n n = Math.floor(n / 10) * 10;\r\n for (var j = 0; j < 10; j++) {\r\n if ((n + j) % 7 === 0) {\r\n print(n + j);\r\n break;\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "// var { readline, print, testOutput, console } = require(\"@ip-algorithmics/codeforces-io\");\r\n \r\nvar t = parseInt(readline());\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n if (n % 7 === 0) {\r\n print(n);\r\n } else {\r\n n = Math.floor(n / 10) * 10;\r\n for (var j = 0; j < 10; j++) {\r\n if ((n + j) % 7 === 0) {\r\n print(n + j);\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n \r\n// testOutput();"}, {"source_code": "var n = parseInt(readline())\r\n\r\nfor (var i = 0 ; ia%10))"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor(var i = 0; i< t; i++){\r\n var n = parseInt(readline());\r\n if(n % 7 === 0) {\r\n print(n);\r\n }\r\n else {\r\n n -= n % 10;\r\n while(n % 7 !== 0) {\r\n n++;\r\n }\r\n print(n)\r\n }\r\n}"}, {"source_code": "r=readline;for(r();a=r();)print(a-a%7+7*(a%7>a%10))"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var s = 0\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1] \n var c = lines[j] - b + 1 \n if(Number(lines[j]) % 7 === 0){\n console.log(lines[j])\n }else{\n while(c % 7 !== 0){\n c++\n\n }\n console.log(c)\n \n }\n }\n});"}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var s = 0\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1] \n var c = lines[j] - b + 1 \n if(Number(lines[j]) % 7 === 0){\n console.log(lines[j])\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n console.log(c)\n }\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var s = 0\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1] \n var c = lines[j] - b + 1 \n if(Number(lines[j]) % 7 === 0){\n console.log(lines[j])\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n console.log(c)\n break;\n }\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if((lines[j] - 1) % 7 === 0 ){\n c = lines[j] - 1\n console.log(c)\n\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n console.log(c)\n\n }\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if((lines[j] - 1) % 7 === 0 ){\n c = lines[j] - 1\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if((lines[j] - 1) % 7 === 0 ){\n console.log(lines[j] - 1)\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if((lines[j] - 1) % 7 === 0 ){\n console.log((lines[j]) - 1)\n }else{\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n if((lines[j] - 1) % 7 === 0 ){\n console.log((lines[j]) - 1)\n }\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] \n while(c % 7 !== 0){\n c--\n if(c % 7 === 0){\n break;\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var a = lines[j].split('')\n var b = a[a.length - 1]\n var c = lines[j] - b + 1\n while(c % 7 !== 0){\n c++\n if(c % 7 === 0){\n break;\n }\n }\n console.log(c)\n }\n}); \n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n for(j = 1; j <= lines[0]; j++){\n var n = lines[j];\n if(n % 7 !== 0){\n while(n % 7 !== 0){\n n++\n if(n % 7 === 0){\n break;\n }\n }\n console.log(n)\n\n }else{\n console.log(n)\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n for(j = 1; j <= lines[0]; j++){\n var n = lines[j];\n if(n % 7 !== 0){\n while(n % 7 !== 0){\n n++\n if(n % 7 === 0){\n break;\n }\n }\n }else{\n console.log(n)\n }\n console.log(n)\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n for(j = 1; j <= lines[0]; j++){\n var n = lines[j];\n\n while(n % 7 !== 0){\n n++\n if(n % 7 === 0){\n break;\n }\n }\n console.log(n)\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n console.log(7)\n }\n});"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var y = readline();\r\n var n = parseInt(y);\r\n if(n % 7 == 0) {\r\n console.log(n)\r\n continue;\r\n }\r\n var s = '';\r\n s += n;\r\n var de = []\r\n for(var i=n;i>=7;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t \r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=1;i--) {\r\n if(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) {\r\n \t \tvar diff = s.length-r.length;\r\n \t \tvar gh = '';\r\n \t \tfor(var i=1;i<=diff;i++) {\r\n \t \t\tgh += 7;\r\n \t \t}\r\n \t \tgh += r;\r\n \t \tvar sum = 0;\r\n \r\n \t for(var j=0;j=7;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t \r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=7;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=100;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=100;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=7;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j=7;i--) {\r\n \tif(i % 7 === 0) {\r\n \t\tvar r = ''\r\n \t r += i;\r\n \t if(r.length < s.length) continue;\r\n \t var sum = 0;\r\n \r\n \t for(var j=0;j q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i];\n var ans = 0;\n for(j = 7; j <= 994; j+=7){\n if(Math.abs(k - j) < 7){\n ans = j;\n break;\n }\n }\n console.log(ans);\n }\n});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var u = k;\n var a = 0;\n var b = 0;\n while(k % 7 !== 0){\n k++;\n a++;\n }\n while(u % 7 !== 0){\n u--;\n b++;\n }\n if(k == 21){\n k += 7;\n }\n if(a > b && u != 7){\n console.log(u);\n }else{\n console.log(k);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = Number(lines[j]);\n var u = k;\n while(k % 7 !== 0){\n k++;\n }\n if(k == 21){\n k += 7;\n }\n console.log(k);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = Number(lines[j]);\n var u = k;\n var a = 0;\n while(k % 7 !== 0){\n k++;\n a = 1;\n }\n if(a === 0){\n k += 7;\n }\n console.log(k);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var u = k;\n var a = 0;\n var b = 0;\n while(k % 7 !== 0){\n k++;\n a++;\n }\n while(u % 7 !== 0){\n u--;\n b++;\n }\n if(a > b && u != 7){\n console.log(u);\n }else{\n console.log(k);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n var u = k;\n var a = 0;\n var b = 0;\n while(k % 7 !== 0){\n k++;\n a++;\n }\n while(u % 7 !== 0){\n u--;\n b++;\n }\n if(a > b){\n console.log(u);\n }else{\n console.log(k);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var k = lines[j];\n while(k % 7 !== 0){\n k++;\n }\n console.log(k);\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input = readline();\r\n let answer = 0;\r\n if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);\r\n else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)\r\n if(answer%10 === 0){\r\n answer += 7;\r\n }\r\n if((answer).toString().length < input.toString().length) answer += 7;\r\n console.log(parseInt(answer))\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input = readline();\r\n let answer = 0;\r\n if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);\r\n else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)\r\n if(answer%10 === 0){\r\n answer += 7;\r\n }\r\n if((answer).toString().length < input.toString().length) answer += 7;\r\n console.log(answer)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input = readline();\r\n let answer = 0;\r\n if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);\r\n else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)\r\n if(answer%10 === 0){\r\n answer += 7;\r\n }\r\n console.log(answer)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input = readline();\r\n if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);\r\n else if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)\r\n else console.log(parseInt(input) + 1)\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n let noOfInputs = (readline());\r\n while(noOfInputs--){\r\n let input = readline();\r\n if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);\r\n if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)\r\n else console.log(parseInt(input) + 1)\r\n }\r\n}"}, {"source_code": "let input = \"\";\r\nprocess.stdin.on(\"data\", (chunk) => {\r\n input += chunk;\r\n});\r\nfunction differentDigits(a, b) {\r\n a = \"\" + a;\r\n b = \"\" + b;\r\n if (a.length !== b.length) {\r\n return false;\r\n }\r\n let count = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] !== b[i]) {\r\n count++;\r\n }\r\n }\r\n return count;\r\n}\r\nprocess.stdin.on(\"end\", () => {\r\n let lines = input.trim().split(\"\\n\");\r\n let t = parseInt(lines[0].trim());\r\n let i = 1;\r\n let dividends = [];\r\n for (let i = 0; i <= 999; i += 7) {\r\n dividends.push(i);\r\n }\r\n while (t--) {\r\n let n = parseInt(lines[i++].trim());\r\n let min = 5;\r\n let result;\r\n for (let i = 0; i < dividends.length; i++) {\r\n let x = differentDigits(n, dividends[i]);\r\n if (!x) {\r\n continue;\r\n }\r\n if (x < min) {\r\n min = x;\r\n result = dividends[i];\r\n }\r\n }\r\n console.log(result);\r\n }\r\n});\r\n"}, {"source_code": "r=readline;\r\n\r\nfor(r();n=r();) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var nNew = n - n%10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\n \r\nfor (var i = 0; i < t; i++) {\r\n var n = +readline();\r\n if (n % 7 === 0) {\r\n print(n)\r\n } else {\r\n var atZero = n%10;\r\n var nNew = atZero ? n : Math.floor(n/10)*10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew); \r\n }\r\n \r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n if (n % 7 === 0) print(n);\r\n var nNew = Math.floor(n/10)*10;\r\n var remainder = nNew % 7;\r\n print(remainder ? nNew + 7 - remainder : nNew);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfunction singleTest(n, freezeLastDigit) {\r\n var remainder = n % 7\r\n if (remainder === 0) return n;\r\n if (freezeLastDigit) return singleTest(n+10,true)\r\n var lastDigit = n % 10\r\n var plusDigit = 7 - remainder;\r\n if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);\r\n return singleTest(n+10,true) \r\n}\r\n\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var number = parseInt(readline());\r\n print(singleTest(number, false))\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfunction singleTest(n, freezeLastDigit) {\r\n var remainder = n % 7\r\n if (remainder === 0) return n;\r\n if (freezeLastDigit) return singleTest(n+10,true)\r\n var lastDigit = n % 10\r\n var plusDigit = 7 - remainder;\r\n if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);\r\n return singleTest(n+10,true) \r\n}\r\n\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n print(singleTest(n, false))\r\n}"}, {"source_code": "var n = parseInt(readline())\r\nprint(n);\r\n \r\nfor (var i = 0 ; i0){\r\n s=readline();\r\n mini=100000;\r\n if(s%7===0){\r\n print(s);\r\n }\r\n else{\r\n res=parseInt(s/7);\r\n ans=(res+1)*7;\r\n print(s);\r\n \r\n }\r\n}"}, {"source_code": "var a=parseInt(readline());\r\nfor(var i=0;i0){\r\n s=readline();\r\n mini=100000;\r\n if(s%7===0){\r\n print(s);\r\n }\r\n else{\r\n res=s/7;\r\n ans=(res+1)*7;\r\n print(s);\r\n \r\n a-=1}\r\n}"}, {"source_code": "a=readline();\r\nwhile(a-->0){\r\n s=readline();\r\n mini=100000;\r\n if(s%7===0){\r\n print(s);\r\n }\r\n else{\r\n res=s/7;\r\n ans=(res+1)*7;\r\n print(s);\r\n \r\n }\r\n}"}, {"source_code": "var n=parseInt(readline())\r\nfor(i=0;i999)result=994\r\nprint(result)}\r\n"}, {"source_code": "var n=parseInt(readline())\r\nfor(i=0;i+x);\r\n let arr = readline().split(' ').map(x=>+x);\r\n console.log(`${solve(arr,n,l,r)}`);\r\n}\r\nfunction solve(nums, n, l, r){\r\n let result = 0;\r\n let mid, min, max,sum, left, right;\r\n nums.sort((a,b)=>a-b);\r\n for(let i = n-1; i >= 0; i--){\r\n left = -1;\r\n right = i;\r\n \r\n while((right - left)>1){\r\n mid = Math.floor((left+right)/2);\r\n sum = nums[mid] + nums[i];\r\n if(sum >= l && sum <= r) right = mid;\r\n else if(sum < l) left = mid;\r\n else if(sum > r) right = mid;\r\n }\r\n if(right !== i){\r\n minIdx = right;\r\n left = -1;\r\n right = i;\r\n while((right-left)>1){\r\n mid = Math.floor((left+right)/2);\r\n sum = nums[mid] + nums[i];\r\n if(sum >= l && sum <= r) left = mid;\r\n else if(sum < l) left = mid;\r\n else if(sum > r) right = mid;\r\n }\r\n maxIdx = left;\r\n result += maxIdx - minIdx +1;\r\n }\r\n }\r\n return result;\r\n}", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0,'utf8').trim().split('\\n');\r\nlet currentLine = 0;\r\nfunction readline(){\r\n return input[currentLine++];\r\n}\r\n\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let [n, l, r] = readline().split(' ').map(x=>+x);\r\n let arr = readline().split(' ').map(x=>+x);\r\n console.log(`${solve(arr,n,l,r)}`);\r\n}\r\n\r\nfunction solve(nums, n, l, r){\r\n let minIdx, maxIdx, sum, mid, left, right;\r\n let result = 0;\r\n nums.sort((a, b)=> a-b);\r\n \r\n for(let i = n-1; i >= 0; i--){\r\n left = -1;\r\n right = i;\r\n while((right-left)>1){\r\n mid = Math.floor((right + left)/2);\r\n sum = nums[mid] + nums[i];\r\n if(sum >= l && sum <= r) right = mid;\r\n else if(sum < l) left = mid;\r\n else if(sum > r) right = mid;\r\n }\r\n if(right !== i){\r\n minIdx = right;\r\n left = -1;\r\n right = i;\r\n while((right-left)>1){\r\n mid = Math.floor((right+left)/2);\r\n sum = nums[mid] + nums[i];\r\n if(sum >= l && sum <= r) left = mid;\r\n else if(sum > r) right = mid;\r\n else if(sum < l) left = mid;\r\n }\r\n maxIdx = left;\r\n result += maxIdx - minIdx +1;\r\n }\r\n }\r\n \r\n return result;\r\n}\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main(){\r\n var nlr, n, l, r, arr;\r\n var sum, result;\r\n var i, j, k;\r\n\r\n var numberOfLines = parseInt(readline(), 10);\r\n\r\n for (i = 0; i < numberOfLines; i++) {\r\n nlr = readNumArray();\r\n n = nlr[0];\r\n l = nlr[1];\r\n r = nlr[2];\r\n\r\n arr = readNumArray();\r\n\r\n arr.sort(function sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n }\r\n );\r\n\r\n result = 0;\r\n\r\n for(j = 1; j < arr.length; j +=1){\r\n var lb = l - arr[j];\r\n var ub = r - arr[j];\r\n\r\n var lower = lowerbound(arr, lb, -1, j);\r\n var upper = upperbound(arr, ub, -1, j);\r\n\r\n\r\n if(lower !== -1 && upper !== -1){\r\n result = Math.max(upper - lower + 1, 0) + result;\r\n }\r\n }\r\n print(result);\r\n\r\n }\r\n}\r\n\r\n\r\n\r\nconst lowerbound = (arr, x, i, j) => {\r\n var f = i;\r\n var l = j;\r\n var lb = -1;\r\n\r\n while(l - f > 1){\r\n mid = Math.ceil((l + f) / 2);\r\n if(arr[mid] >= x){\r\n lb = mid;\r\n l = mid\r\n }else{\r\n f = mid;\r\n }\r\n\r\n }\r\n return lb;\r\n};\r\n\r\n\r\nconst upperbound = (arr, x, i, j) => {\r\n var f = i;\r\n var l = j;\r\n var ub = -1;\r\n\r\n while(l - f > 1){\r\n mid = Math.ceil((l + f) / 2);\r\n if(arr[mid] <= x){\r\n ub = mid;\r\n f = mid\r\n }else{\r\n l = mid;\r\n }\r\n\r\n }\r\n return ub;\r\n\r\n};\r\n\r\n\r\nmain();"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let [n, l, r] = readline().split(' ').map(x => +x);\r\n let arr = readline().split(' ').map(x => +x);\r\n console.log(`${solve(arr, n, l, r)}`)\r\n}\r\n\r\nfunction solve(nums, n, l, r){\r\n let i, j, mid, result=0, temp, ll, rr, lll;\r\n nums.sort((a,b)=>a-b);\r\n for(i = n-1; i >= 0; i--){\r\n rr = i;\r\n ll = -1;\r\n \r\n while((rr-ll)>1){\r\n mid = Math.floor((ll+rr)/2);\r\n temp = nums[mid] + nums[i];\r\n if(temp >= l && temp <= r) rr = mid;\r\n else if(temp > r) rr = mid;\r\n else if(temp < l) ll = mid;\r\n }\r\n if(rr !== i){\r\n lll = rr;\r\n rr = i;\r\n ll = -1;\r\n while((rr-ll)>1){\r\n mid = Math.floor((ll+rr)/2);\r\n temp = nums[mid] + nums[i];\r\n if(temp >= l && temp <= r) ll = mid;\r\n else if(temp > r) rr = mid;\r\n else if(temp < l) ll = mid;\r\n }\r\n \r\n result += ll - lll+1;\r\n }\r\n }\r\n \r\n return result;\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n// a sample creepy solution\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x-y);\r\n\r\n\t\tfunction countBelow (cutoff) {\r\n\t\t\tlet tot = 0;\r\n\t\t\tfor (let i = 0, j = n-1; i < n-1; i++) {\r\n\t\t\t\twhile (i < j && a[i] + a[j] > cutoff)\r\n\t\t\t\t\tj--;\r\n\t\t\t\ttot += Math.max(0, j - i);\r\n\t\t\t}\r\n\t\t\treturn tot;\r\n\t\t}\r\n\r\n\t\tconsole.log(countBelow(r) - countBelow(l-1));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, l, r] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\ta.sort((x, y) => x - y);\r\n\r\n\t\tfunction lowerBound (l, r, x) {\r\n\t\t\twhile (l < r) {\r\n\t\t\t\tmid = l + r >> 1;\r\n\t\t\t\tif (a[mid] >= x)\r\n\t\t\t\t\tr = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tl = mid + 1;\r\n\t\t\t}\r\n\t\t\treturn a[l] >= x ? l : 0;\r\n\t\t}\r\n\r\n\t\tfunction upperBound (l, r, x) {\r\n\t\t\twhile (l < r) {\r\n\t\t\t\tmid = l + r + 1 >> 1;\r\n\t\t\t\tif (a[mid] <= x)\r\n\t\t\t\t\tl = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tr = mid-1;\r\n\t\t\t}\r\n\t\t\treturn a[l] <= x ? l : 0;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let i = 0; i < n-1; i++) {\r\n\t\t\tconst ub = upperBound(i+1, n-1, r - a[i]);\r\n\t\t\tconst lb = lowerBound(i+1, n-1, l - a[i]);\r\n\t\t\tif (ub && lb)\r\n\t\t\t\tans += ub - lb + 1;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\n// \u0418\u043d\u0434\u0435\u043a\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432 \u043e\u0442\u0441\u043e\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c arr \u043d\u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0435 [l, r), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 value\r\nfunction bins(arr, value, l, r) {\r\n if (arr[l] > value) {\r\n return l;\r\n }\r\n if (arr[r - 1] <= value) {\r\n return r;\r\n }\r\n while (r - l > 1) {\r\n var m = ((r + l) >> 1) - ((r + l + 1) & 1);\r\n if (arr[m] <= value) {\r\n l = m + 1;\r\n continue;\r\n }\r\n r = m + 1;\r\n }\r\n return l;\r\n}\r\n\r\nfunction solve() {\r\n var nlr = readArray(Number);\r\n var n = nlr[0];\r\n var l = nlr[1];\r\n var r = nlr[2];\r\n var arr = readArray(Number);\r\n arr.sort(sortF);\r\n var ans = 0;\r\n for (var i = 1; i < n; i++) {\r\n var li = bins(arr, l - arr[i] - 1, 0, i);\r\n var ri = bins(arr, r - arr[i], 0, i);\r\n ans += ri - li;\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort(function sortF(a, b) {\r\n\t\t\t if (a < b) {\r\n\t\t\t\t return -1;\r\n\t\t\t }\r\n\t\t\t if (a > b) {\r\n\t\t\t\t return 1;\r\n\t\t\t }\r\n\t\t\t return 0;\r\n\t\t\t}\r\n\t\t );\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 1; j < n; j++) {\r\n\t\t\tvar ll = l - arr[j];\r\n\t\t\tvar rr = r - arr[j];\r\n\t\t\tvar lb = lowBound(arr, ll, 0, j-1);\r\n\t\t\tvar ub = upperBound(arr, rr, 0, j-1);\r\n\t\t\t\r\n\t\t\tif(lb!=-1 && ub!=-1)\r\n\t\t\t{\r\n\t\t\t\tresult = Math.max(ub - lb + 1, 0) + result;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nfunction lowBound(arr, x, i, j) {\r\n\tvar l = i;\r\n\tvar r = j;\r\n\tvar lb = -1;\r\n\t\r\n\tvar m;\r\n\t\r\n\twhile(l <= r){\r\n\t\tm = Math.ceil((l + r) / 2);\r\n\t\tif(arr[m] >= x) {\r\n\t\t\tlb = m;\r\n\t\t\tr = m - 1;\r\n\t\t} else {\r\n\t\t\tl = m + 1;\r\n\t\t}\r\n\t}\r\n\treturn lb;\r\n\t\r\n}\r\n\r\nfunction upperBound(arr, x, i, j) {\r\n\tvar l = i;\r\n\tvar r = j;\r\n\tvar ans = -1;\r\n\t\r\n\tvar m;\r\n\t\r\n\twhile(l <= r){\r\n\t\tm = Math.ceil((l + r) / 2);\t\t\r\n\t\tif(arr[m] <= x) {\r\n\t\t\tans = m;\r\n\t\t\tl = m + 1;\r\n\t\t} else {\r\n\t\t\tr = m - 1;\r\n\t\t}\r\n\t}\r\n\treturn ans;\r\n\t\r\n}\r\n\r\nmain();"}], "negative_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nlet t = +readline();\r\n\r\nwhile(t--){\r\n let [n, l, r] = readline().split(' ').map(x => +x);\r\n let arr = readline().split(' ').map(x => +x);\r\n console.log(`${solve(arr, n, l, r)}`)\r\n}\r\n\r\nfunction solve(nums, n, l, r){\r\n let result = 0;\r\n nums.sort((a,b)=>a-b);\r\n let end = n-1;\r\n let start = 0;\r\n let maxIdx;\r\n let minIdx;\r\n \r\n while(nums[end] > r && end >= 0) end--;\r\n for(let i = end; i >= 0; i--){\r\n let max = r-nums[i];\r\n let min = nums[i]-l;\r\n let left = 0;\r\n let right = i-1\r\n if(min < 0 && nums[i] < max){\r\n if(min + nums[i-1] < 0 || nums[i] + nums[i-1]< max)break;\r\n result++;\r\n continue;\r\n };\r\n // console.log({min},{max},{right})\r\n if(nums[right] <= max){\r\n maxIdx = right;\r\n }else{\r\n //look for max\r\n while(left < right){\r\n let mid = Math.floor((left+right)/2)\r\n if(nums[mid] <= max && nums[mid+1] <= max) left = mid+1;\r\n else right = mid-1\r\n }\r\n maxIdx = left;\r\n }\r\n left = 0;\r\n right = end-1\r\n if(nums[left] >= min){\r\n minIdx = left;\r\n }else{\r\n while(left < right){\r\n let mid = Math.floor((left+right)/2)\r\n if(nums[mid] >= min && nums[mid-1] >= min) right = mid-1;\r\n else left = mid+1;\r\n }\r\n minIdx = right;\r\n }\r\n // console.log({minIdx},{maxIdx})\r\n result += maxIdx-minIdx+1;\r\n }\r\n \r\n return result;\r\n}\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] > r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\t\r\n\t\t\t\tif (l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] > r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\t\r\n\t\t\t\tif (sum > r) {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t} else if (l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] >= r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\t\r\n\t\t\t\tif (sum > r) {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t} else if (l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] >= r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(arr[j+1] >= r){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\r\n\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\t\r\n\t\t\t\tif(l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] >= r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\r\n\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\tif(sum > r) {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif(l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n \r\nfunction main(){\r\n\tvar nlr, n, l, r, arr;\r\n\tvar sum, result;\r\n\tvar i, j, k;\r\n\t\r\n\tvar numberOfLines = parseInt(readline(), 10);\r\n\t\r\n\tfor (i = 0; i < numberOfLines; i++) {\r\n\t\tnlr = readNumArray();\r\n\t\tn = nlr[0];\r\n\t\tl = nlr[1];\r\n\t\tr = nlr[2];\r\n\t\t\r\n\t\tarr = readNumArray();\r\n\t\t\r\n\t\tarr.sort();\r\n\t\t\r\n\t\tresult = 0;\r\n\t\t\t\t\r\n\t\tfor (j = 0; j < n -1; j++) {\r\n\t\t\tif(arr[j] >= r) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(arr[j+1] >= r){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfor (k = j + 1; k < n; k++){\r\n\t\t\t\t\r\n\t\t\t\tsum = arr[j] + arr[k];\r\n\t\t\t\tif(sum > r) {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif(l <= sum && sum <= r) {\r\n\t\t\t\t\tresult++;\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(result);\r\n\t}\r\n}\r\n\r\nmain();"}], "src_uid": "2f12b2bb23497119bb70ca0839991d68"} {"source_code": "process.stdin.setEncoding('ASCII');\nlet string = '';\nprocess.stdin.on('data', (data) => string += data);\n\nconst main = ( input ) => {\n let n = Number(input[0]);\n let arr = input[1].split(' ').map(Number);\n\n let freq = {};\n for (let i = 0; i < arr.length; ++i) freq[arr[i]] = i + 1;\n\n for (let i = 0; i < arr.length; ++i) {\n for (let j = 0; j < arr.length; ++j) {\n if (i == j) continue;\n\n let val = arr[i] + arr[j];\n if ( freq[val] !== undefined ) {\n console.log(freq[val], i + 1, j + 1);\n return;\n }\n }\n }\n\n console.log(-1);\n}\n\nprocess.stdin.on('end', () => main(string.trim().split('\\n')));\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar ans = \"-1\";\nvar indicator = 0, N;\nvar needBreak = false;\nrl.on('line', (input) => {\n\n\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else {\n var cont = input.split(' ').map(item => parseInt(item));\n for (let i = 0; i < N; i++) {\n for (let j = 0; j < N; j++) {\n if (j == i)\n continue;\n for (let k = 0; k < N; k++) {\n if (k == i || k == j)\n continue;\n if (cont[i] == cont[j] + cont[k]) {\n //console.log(\"cont[%d]=%d cont[%d]=%d cont[%d]=%d\",i,cont[i],j,cont[j],k,cont[k]);\n ans = (i + 1).toString() + \" \" + (j + 1).toString() + \" \" + (k + 1).toString();\n needBreak = true;\n break;\n }\n }\n if (needBreak)\n break;\n }\n if (needBreak)\n break;\n }\n console.log(ans);\n rl.close();\n }\n\n\n\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar ans = \"-1\", n = -1;\n\nrl.on('line', (input) => {\n if (n == -1)\n n = parseInt(input);\n else {\n\n let cont = input.split(' ').map(item => parseInt(item));\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n if (i == j)\n continue;\n for (let k = 0; k < n; k++) {\n if (k == i || k == j)\n continue;\n if (cont[i] == cont[j] + cont[k]) {\n ans = (i + 1) + \" \" + (j + 1) + \" \" + (k + 1);\n break;\n }\n\n }\n if (ans != \"-1\")\n break;\n }\n if (ans != \"-1\")\n break;\n\n }\n console.log(ans);\n rl.close();\n }\n\n});"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar worms = tokenizeIntegers(readline());\n\n\tvar wormHash = {};\n\tfor (var i = 0; i < n; ++i) {\n\t\twormHash[worms[i]] = i;\n\t}\n\n\tfor (var i = 0; i < n; ++i) {\n\t\tfor (var j = i+1; j < n; ++j) {\n\t\t\tvar k = wormHash[worms[i]+worms[j]];\n\t\t\tif (k != undefined) {\n\t\t\t\tprint([k+1, i+1, j+1].join(\" \"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(-1);\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v))\n\nlet res = (function () {\n for (let i = 0; i < N - 1; i++) {\n for (let j = i + 1; j < N; j++) {\n let k = lll.indexOf(lll[i] + lll[j])\n if (~k) return [i, j, k]\n }\n }\n})()\n\nprint (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++res[0] : -1)"}], "negative_code": [{"source_code": "'use strict'\n\nlet N = +readline()\nlet lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)\n\nlet res = (function () {\n for (let i = 0; i < N - 1; i++) {\n for (let j = i + 1; j < N; j++) {\n let k = lll.indexOf(lll[i] + lll[j])\n if (~k) return [i, j, k]\n }\n }\n})()\n\nprint (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++ res[0] : -1)"}], "src_uid": "94a38067fc8dd8619fa6e5873ca60220"} {"source_code": "'use strict'\n\nconst problem = (n, f) => {\n let t = new Set(f);\n const g = Array.from({ length: n }, (_, i) => i + 1).filter(i => !t.has(i));\n for (let i = 0, j, prev; i < n; i++) {\n if (f[i]) continue;\n j = g.pop();\n if (j === (i + 1)) {\n if (prev === undefined) { g.push(j); j = g.shift(); }\n else { const t = f[prev]; f[prev] = j; j = t; };\n }\n\n f[i] = j;\n prev = i;\n }\n return f;\n}\n\nprint(problem(+readline(), readline().split(' ').map(Number)).join(' '));\n", "positive_code": [{"source_code": "\"use strict\";\n\nlet friendsNumber = +readline(); //!\nlet wishString = readline(); //!\nlet arrayOfWishNumbers = wishString.split(\" \").map(function(item) {\n\treturn +item;\n});\n\nlet sortedWish = [];\nlet zeroIndexes = [];\nlet zeroValues = [];\n\nfor (let i = 0; i < arrayOfWishNumbers.length; i++) {\n\tif (arrayOfWishNumbers[i] === 0) {\n\t\tzeroIndexes.push(i);\n\t}\n\tsortedWish[i] = 0;\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (arrayOfWishNumbers[i] !== 0) {\n\t\tsortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];\n\t}\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (sortedWish[i] === 0) {\n\t\tzeroValues.push(i + 1);\n\t}\n}\n\nlet goodSortedZeroValues = [];\n//\n\n// zeroValues = zeroValues.reverse();\n// if (zeroValues.length % 2 == 1) {\n// \tlet tempValue = zeroValues[Math.floor(zeroValues.length / 2)];\n// \tzeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];\n// \tzeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;\n// }\n\n// let badSortedValues = [];\n\n// for (let i = 0; i < zeroValues.length; i++) {\n// \tif (zeroValues[i] = zeroIndexes[i] + 1) {\n// \t\tbadSortedValues.push(zeroValues[i]);\n// \t}\n// }\n\n// for (let i = 0; i < badSortedValues.length; i++) {\n// \tfor (let j = 0; j < zeroValues.length; j++) {\n// \t\tif (zeroValues[j] === badSortedValues[i]) {\n// \t\t\tlet tempValue = zeroValues[j];\n// \t\t\tfor (let k = 0; k < zeroValues.length; k++) {\n// \t\t\t\tif (zeroValues[k] !== 0;)\n// \t\t\t}\n// \t\t}\n// \t}\n// }\n\nfor (let i = 0; i < zeroValues.length; i++) {\n\tif (zeroValues[i] === zeroIndexes[i] + 1) {\n\t\tfor (let j = 0; j < zeroValues.length; j++) {\n\t\t\tlet tempValue = zeroValues[i];\n\t\t\tif (zeroValues[i] !== zeroValues[j]) {\n\t\t\t\tzeroValues[i] = zeroValues[j];\n\t\t\t\tzeroValues[j] = tempValue;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n//\nif (zeroValues.length === zeroIndexes.length) {\n\t\n\tfor (let i = 0; i < zeroIndexes.length; i++) {\n\t\tarrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];\n\t}\n}\n\nlet result = arrayOfWishNumbers.join(\" \");\n\nprint(result);"}, {"source_code": "'use strict'\n\nconst problem = (n, f) => {\n f = f.map(i => i - 1);\n const F = new Set(f);\n const g = [ ...Array(n).keys() ].filter(i => !F.has(i));\n let prev;\n for (let i = 0; i < n; i++) {\n if (f[i] !== -1) continue;\n let j = g.pop();\n if (j === i) {\n if (prev === undefined) { g.push(j); j = g[0]; }\n else { const t = f[prev]; f[prev] = j; j = t };\n }\n\n f[i] = j;\n prev = i;\n }\n return f.map(i => i + 1).join(' ');\n}\n\nprint(problem(+readline(), readline().split(' ').map(Number)));\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, f) => {\n f = f.map(i => i - 1);\n const g = [ ...Array(n).keys() ].filter(i => !f.includes(i)); // \u0431\u0435\u0437 \u043f\u043e\u0434\u0430\u0440\u043a\u0430\n let prev;\n for (let i = 0; i < n; i++) {\n if (f[i] !== -1) continue;\n let j = g.pop();\n if (j === i) {\n if (prev === undefined) { g.push(j); j = g[0]; }\n else { const t = f[prev]; f[prev] = j; j = t };\n }\n\n f[i] = j;\n prev = i;\n }\n return f.map(i => i + 1);\n}\n\nprint(problem(+readline(), readline().split(' ').map(Number)));\n"}, {"source_code": "\"use strict\";\n\nlet friendsNumber = +readline(); //!\nlet wishString = readline(); //!\nlet arrayOfWishNumbers = wishString.split(\" \").map(function(item) {\n\treturn +item;\n});\n\nlet sortedWish = [];\nlet zeroIndexes = [];\nlet zeroValues = [];\n\nfor (let i = 0; i < arrayOfWishNumbers.length; i++) {\n\tif (arrayOfWishNumbers[i] === 0) {\n\t\tzeroIndexes.push(i);\n\t}\n\tsortedWish[i] = 0;\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (arrayOfWishNumbers[i] !== 0) {\n\t\tsortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];\n\t}\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (sortedWish[i] === 0) {\n\t\tzeroValues.push(i + 1);\n\t}\n}\n\nlet goodSortedZeroValues = [];\n//\n\nzeroValues = zeroValues.reverse();\nif (zeroValues.length % 2 == 1) {\n\tlet tempValue = zeroValues[Math.floor(zeroValues.length / 2)];\n\tzeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];\n\tzeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;\n}\n\n//\nif (zeroValues.length === zeroIndexes.length) {\n\t\n\tfor (let i = 0; i < zeroIndexes.length; i++) {\n\t\tarrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];\n\t}\n}\n\nlet result = arrayOfWishNumbers.join(\" \");\n\nprint(result);"}], "src_uid": "bef323e7c8651cc78c49db38e49ba53d"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(l, r, data) {\r\n let count0 = new Array(32).fill(0),\r\n count1 = new Array(32).fill(0);\r\n\r\n for (let i = 0; i <= r; i++) {\r\n let cur = data[i];\r\n\r\n for (let j = 0; j < 32; j++) {\r\n if (cur & 1 << j) count1[j] = count1[j] + 1;else count0[j] = count0[j] + 1;\r\n }\r\n }\r\n\r\n let res = 0;\r\n\r\n for (let i = 0; i < 32; i++) {\r\n if (count0[i] < count1[i]) res |= 1 << i;\r\n }\r\n\r\n return res;\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n let t = Number(inputs[0]),\r\n __ = 1,\r\n res = [];\r\n\r\n for (let _ = 0; _ < t; _++) {\r\n const [l, r] = inputs[__++].split(' ').map(Number);\r\n let data = inputs[__++].trim().split(' ').map(Number);\r\n res.push(solve(l, r, data));\r\n }\r\n\r\n console.log(res.join('\\n'));\r\n}();\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [_, n] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tfunction cntZeros(a, bit) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\t\tcnt += (a[i] & 1 << bit) == 0;\r\n\t\t\t}\r\n\t\t\treturn cnt;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let bit = 0; bit <= 16; bit++) {\r\n\t\t\tif (cntZeros(a, bit) < (n+1)/2) {\r\n\t\t\t\tans += 1 << bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [_, n] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i <= n; i++) { \r\n\t\t\tb[i] = i;\r\n\t\t}\r\n\r\n\t\tfunction cntZeros(a, bit) {\r\n\t\t\tlet cnt = 0;\r\n\t\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\t\tcnt += (a[i] & 1 << bit) == 0;\r\n\t\t\t}\r\n\t\t\treturn cnt;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let bit = 0; bit <= 16; bit++) {\r\n\t\t\tif (cntZeros(a, bit) != cntZeros(b, bit)) {\r\n\t\t\t\tans += 1 << bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [_, n] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i <= n; i++) { \r\n\t\t\tb[i] = i;\r\n\t\t}\r\n\r\n\t\tfunction getZeros(a, pos) {\r\n\t\t\tlet zeros = 0;\r\n\t\t\tfor (let i = 0; i <= n; i++) {\r\n\t\t\t\tzeros += (a[i] & 1 << pos) == 0;\r\n\t\t\t}\r\n\t\t\treturn zeros;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let bit = 0; bit <= 16; bit++) {\r\n\t\t\tif (getZeros(a, bit) != getZeros(b, bit)) {\r\n\t\t\t\tans += 2**bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [left, right] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(left, right, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\n// check(0, 9, 33)\n\nfunction solve(left, right, arr) {\n const counts = Array(18).fill(0)\n for (let i = 0; i < counts.length; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (arr[j] & (1 << i)) {\n counts[i]++\n }\n }\n }\n const expect = helper(right)\n let ans = 0\n for (let i = 0; i < counts.length; i++) {\n if (counts[i] !== expect[i]) {\n ans |= 1 << i\n }\n }\n // console.log(counts, expect)\n // console.log('-')\n return ans\n}\nfunction check(left, right, x) {\n const map = {}\n const arr = []\n for (let i = left; i <= right; i++) {\n const y = i ^ x\n map[y] = (map[y] || []) + 1\n arr.push(y)\n }\n\n const ans = solve(left, right, arr)\n const map2 = {}\n for (let i = left; i <= right; i++) {\n const y = i ^ ans\n map2[y] = (map2[y] || []) + 1\n }\nconsole.log(ans, map, map2)\n for (let k in map) {\n if (map[k] !== map2[k]) throw 'sb'\n }\n}\nfunction helper(x) {\n const log = Math.floor(Math.log2(x))\n const base = Math.pow(2, log)\n // [base, x]\n let counts = Array(18).fill(0)\n if (x > base) {\n counts = helper(x - base)\n counts[log] = x - base + 1\n } else if (x === base) {\n counts[log] = 1\n }\n // [0, base)\n for (let i = 0; i < log; i++) {\n counts[i] += base / 2\n }\n// console.log(x, counts)\n return counts\n}\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [_, n] = rna();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst b = [];\r\n\t\tfor (let i = 0; i < n; i++) { \r\n\t\t\tb[i] = i;\r\n\t\t}\r\n\r\n\t\tfunction getZeros(a, pos) {\r\n\t\t\tlet zeros = 0;\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tzeros += (a[i] & 1 << pos) == 0;\r\n\t\t\t}\r\n\t\t\treturn zeros;\r\n\t\t}\r\n\r\n\t\tlet ans = 0;\r\n\t\tfor (let bit = 0; bit <= 16; bit++) {\r\n\t\t\tif (getZeros(a, bit) != getZeros(b, bit)) {\r\n\t\t\t\tans += 2**bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [left, right] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(left, right, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(left, right, arr) {\n const counts = Array(18).fill(0)\n for (let i = 0; i < counts.length; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (arr[j] & (1 << i)) {\n counts[i]++\n }\n }\n }\n const expect = helper(right)\n let ans = 0\n for (let i = 0; i < counts.length; i++) {\n if (counts[i] !== expect[i]) {\n ans |= 1 << i\n }\n }\n // console.log(counts, expect)\n // console.log('-')\n return ans\n}\nfunction helper(x) {\n const log = Math.floor(Math.log2(x))\n const base = Math.pow(2, log)\n // [base, x]\n let counts = Array(18).fill(0)\n if (x > base) {\n counts = helper(x - base + 1)\n counts[log] = x - base + 1\n } else if (x === base) {\n counts[log] = 1\n }\n // [0, base)\n for (let i = 0; i < log; i++) {\n counts[i] += base / (1 << (i + 1))\n }\n// console.log(x, counts)\n return counts\n}\n"}], "src_uid": "354e27c81d3d57a64062b5daa05705ad"} {"source_code": "var read = require('readline').createInterface({\n input: process.stdin\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n var start = Date.now();\n Main();\n console.error(\"\\n\");\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction input(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\nfunction puts(s){console.log(s);}\nfunction print(s) {process.stdout.write(s+\"\");}\n\n\nfunction Main(){\n tc = parseInt(input()) \n while(tc--) {\n \n k = parseInt(input()) \n s = 6+10+14 \n arr = [6,10,14]\n if(k <= s) {\n puts(\"NO\")\n } \n else {\n e = k - s\n z = \"6 10 14 \"\n if(arr.indexOf(e) !== -1) {\n z = \"6 10 15 \"\n e -= 1\n }\n puts(\"YES\")\n puts(z+e)\n }\n }\n} ", "positive_code": [{"source_code": "start()\n \n \nasync function start() {\n const input = await readArgs()\n const numOfTests = input[0]\n for (let i = 1; i < numOfTests + 1; i++) {\n const num = input[i]\n const res = sol(num)\n output(res)\n }\n}\n \nfunction output(arr) {\n if (arr.length == 0) console.log('NO')\n else {\n console.log('YES')\n console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)\n \n }\n}\n \nfunction sol(n) {\n switch (n) {\n case 36:\n return [6,10,15,5]\n case 40:\n return [6, 14, 15, 5]\n case 44:\n return [6, 10, 15, 13]\n default:\n return n < 31 ? [] : [6, 10, 14, n - 30]\n }\n}\n \nfunction readArgs() {\n let i = ''\n process.stdin.on('data', c => i += c)\n return new Promise(res => {\n process.stdin.on('end', () => {\n const { EOL } = require('os')\n let lines = i.split(EOL)\n // lines = lines.map(line => line.split(' '))\n lines = lines.map(line => parseInt(line))\n res(lines)\n })\n })\n}"}, {"source_code": "var T = +readline();\nwhile (T--) {\n var n = +readline();\n //var arr = new Array();\n var arr = [1, 2, 3, 4]\n // print(arr)\n //console.log(arr)\n if (n <= 30) {\n print(\"NO\");\n }\n else {\n //var str = new String();\n if (n != 30 + 6 && n != 30 + 10 && n != 30 + 14) print(\"YES\\n6 10 14 \", n - 30);\n else print(\"YES\\n6 10 15 \", n - 31);\n }\n}\n// 1\n// 2\n// 3\n// 4\n// 5\n// 6 = 2 3\n// 7\n// 8\n// 9\n// 10 = 2 5\n// 11 = \n// 12\n// 13\n// 14 = 2 7\n// 15 = 3 5\n// 16\n// 17 "}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar N = nextInt();\n var output = [];\n for(var i = 0; i < N; i++){\n var a = nextInt();\n if(a < 31){\n output.push(\"NO\");\n }else{\n output.push(\"YES\");\n if(a == 36){\n output.push(\"6 10 15 5\");\n }else if(a == 40){\n output.push(\"6 14 15 5\");\n }else if(a == 44){\n output.push(\"6 10 15 13\");\n }else{\n output.push(\"6 10 14 \" + (a - 30));\n }\n }\n }\n myout(myconv(output, 9));\n}\n"}], "negative_code": [{"source_code": "var T = +readline();\nwhile (T--) {\n var n = +readline();\n //var arr = new Array();\n var arr = [1, 2, 3, 4]\n // print(arr)\n //console.log(arr)\n if (n <= 30) {\n print(\"NO\");\n }\n else {\n //var str = new String();\n if (n != 30 + 6 || n != 30 + 10 || n != 30 + 14) print(\"YES\\n6 10 14 %d\\n\", n - 30);\n else print(\"YES\\n6 10 15 %d\\n\", n - 31);\n }\n}\n// 1\n// 2\n// 3\n// 4\n// 5\n// 6 = 2 3\n// 7\n// 8\n// 9\n// 10 = 2 5\n// 11 = \n// 12\n// 13\n// 14 = 2 7\n// 15 = 3 5\n// 16\n// 17 "}, {"source_code": "var T = +readline();\nwhile (T--) {\n var n = +readline();\n //var arr = new Array();\n var arr = [1, 2, 3, 4]\n // print(arr)\n //console.log(arr)\n if (n <= 30) {\n print(\"NO\");\n }\n else {\n //var str = new String();\n print(\"YES\\n6 10 14\",n-30);\n }\n}\n// 1\n// 2\n// 3\n// 4\n// 5\n// 6 = 2 3\n// 7\n// 8\n// 9\n// 10 = 2 5\n// 11 = \n// 12\n// 13\n// 14 = 2 7\n// 15 = 3 5\n// 16\n// 17 "}, {"source_code": "var T = +readline();\nwhile (T--) {\n var n = +readline();\n //var arr = new Array();\n var arr = [1, 2, 3, 4]\n // print(arr)\n //console.log(arr)\n if (n <= 30) {\n print(\"NO\");\n }\n else {\n //var str = new String();\n if (n != 30 + 6 || n != 30 + 10 || n != 30 + 14) print(\"YES\\n6 10 14 \", n - 30);\n else print(\"YES\\n6 10 15 \", n - 31);\n }\n}\n// 1\n// 2\n// 3\n// 4\n// 5\n// 6 = 2 3\n// 7\n// 8\n// 9\n// 10 = 2 5\n// 11 = \n// 12\n// 13\n// 14 = 2 7\n// 15 = 3 5\n// 16\n// 17 "}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n var start = Date.now();\n Main();\n console.error(\"\\n\");\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction input(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\nfunction puts(s){console.log(s);}\nfunction print(s) {process.stdout.write(s+\"\");}\n\n\nfunction Main(){\n tc = parseInt(input()) \n while(tc--) {\n \n k = parseInt(input()) \n s = 6+10+14 \n arr = [6,10,14]\n if(k < s) {\n puts(\"NO\")\n } \n else {\n e = k - s\n z = \"6 10 14 \"\n if(arr.indexOf(e) !== -1) {\n z = \"6 10 15 \"\n e -= 1\n }\n puts(\"YES\")\n puts(z+e)\n }\n }\n} "}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n var start = Date.now();\n Main();\n console.error(\"\\n\");\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction input(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){\n if(!this.hasNext()){\n\n throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";\n }\n else{\n var returnInput = this.list[this.index];\n this.index++;\n return returnInput;\n }\n }};\n return returnObj;\n}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\nfunction puts(s){console.log(s);}\nfunction print(s) {process.stdout.write(s+\"\");}\n\n\nfunction Main(){\n tc = parseInt(input()) \n while(tc--) {\n \n k = parseInt(input()) \n s = 6+10+14 \n if(k < s) {\n puts(\"NO\")\n } \n else {\n e = k - s\n puts(\"YES\")\n puts(\"6 10 14 \"+e)\n }\n }\n} "}, {"source_code": "start()\n \n \nasync function start() {\n const input = await readArgs()\n const numOfTests = input[0]\n for (let i = 1; i < numOfTests + 1; i++) {\n const num = input[i]\n const res = sol(num)\n output(res)\n }\n}\n \nfunction output(arr) {\n if (arr.length == 0) console.log('NO')\n else {\n console.log('YES')\n console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)\n \n }\n}\n \nfunction sol(n) {\n switch (n) {\n case 36:\n return [6,10,15,5]\n case 40:\n return [6, 14, 15, 5]\n case 44:\n return [6, 10, 15, 13]\n default:\n return n < 30 ? [] : [6, 10, 14, n - 30]\n }\n}\n \nfunction readArgs() {\n let i = ''\n process.stdin.on('data', c => i += c)\n return new Promise(res => {\n process.stdin.on('end', () => {\n const { EOL } = require('os')\n let lines = i.split(EOL)\n // lines = lines.map(line => line.split(' '))\n lines = lines.map(line => parseInt(line))\n res(lines)\n })\n })\n}"}, {"source_code": "start()\n\n\nasync function start() {\n const input = await readArgs()\n const numOfTests = input[0]\n for (let i = 1; i < numOfTests + 1; i++) {\n const num = input[i]\n const res = sol(num)\n output(res)\n }\n}\n\nfunction output(arr) {\n if (arr.length == 0) console.log('NO')\n else {\n console.log('YES')\n console.log(`${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]}`)\n\n }\n}\n\nfunction sol(n) {\n return n < 30 ? [] : [6, 10, 14, n - 30]\n}\n\nfunction readArgs() {\n let i = ''\n process.stdin.on('data', c => i += c)\n return new Promise(res => {\n process.stdin.on('end', () => {\n const { EOL } = require('os')\n let lines = i.split(EOL)\n // lines = lines.map(line => line.split(' '))\n lines = lines.map(line => parseInt(line))\n res(lines)\n })\n })\n}"}], "src_uid": "8a6c3436f73286ca54f51fb90017a299"} {"source_code": "'use strict';\n\n// let inpFileStrArr = `\n// 2\n// 1 1\n// 1 2\n// 2 1\n// 2 2\n// `.trim().split('\\n').map(x => x.trim()), inpFileCounter = 0;\n// function readline() {\n// return inpFileStrArr[inpFileCounter++];\n// }\n// function print(x) {\n// console.log(x);\n// }\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar n = Number(readline()),\n h = [],\n v = [],\n res = [];\nfor (var i = 0; i < n; i++) {\n h.push(false);v.push(false);\n}\nh.unshift(0);v.unshift(0);\n\nfor (var i = 0; i < n * n; i++) {\n var _readline$split$map = readline().split(' ').map(Number);\n\n var _readline$split$map2 = _slicedToArray(_readline$split$map, 2);\n\n var _h = _readline$split$map2[0];\n var _v = _readline$split$map2[1];\n\n if (!h[_h] && !v[_v]) {\n res.push(i + 1);\n h[_h] = true;v[_v] = true;\n }\n}\nres.sort(function (a, b) {\n return a - b;\n});\nprint(res.join(' '));\n", "positive_code": [{"source_code": "var n = +readline(), h = [], v = [];\n\nfor(var i = 0; i < n; i++){\n\th[i] = false;\n\tv[i] = false;\n}\n\nfor(var i = 0; i < (n*n); i++){\n\tinput = readline().split(\" \").map(Number);\n\ta = input[0] - 1;\n\tb = input[1] - 1;\n\n\tif(h[a] == false && v[b] == false){\n\t\th[a] = true;\n\t\tv[b] = true;\n\n\t\twrite((i+1) + \" \");\n\t}\n}"}, {"source_code": "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar List = __webpack_require__(1);\n\tvar n = List.map(parseInt, readline().split(' '))[0];\n\tvar markedX = List.create(n, false);\n\tvar markedY = List.create(n, false);\n\tvar result = [];\n\tfor (var i = 0; i < n * n; i++) {\n\t var _a = List.map(parseInt, readline().split(' ')), x = _a[0], y = _a[1];\n\t if (!markedX[x - 1] && !markedY[y - 1]) {\n\t markedX[x - 1] = true;\n\t markedY[y - 1] = true;\n\t result.push(i + 1);\n\t }\n\t}\n\tprint(result.join(' '));\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar Prelude_1 = __webpack_require__(2);\n\tfunction add(xs, ys) {\n\t return xs.concat(ys);\n\t}\n\texports.add = add;\n\tfunction head(xs) {\n\t return xs[0];\n\t}\n\texports.head = head;\n\tfunction last(xs) {\n\t return xs[xs.length - 1];\n\t}\n\texports.last = last;\n\tfunction tail(xs) {\n\t return xs.slice(1);\n\t}\n\texports.tail = tail;\n\tfunction init(xs) {\n\t return xs.slice(0, xs.length - 1);\n\t}\n\texports.init = init;\n\tfunction map(f, xs) {\n\t var result = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t result[i] = f(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.map = map;\n\tfunction reverse(xs) {\n\t return xs.slice().reverse();\n\t}\n\texports.reverse = reverse;\n\tfunction intersperse(x, xs) {\n\t if (xs.length == 0) {\n\t return [];\n\t }\n\t var result = new Array(xs.length + xs.length - 1);\n\t for (var i = 0; i + 1 < xs.length; i++) {\n\t result[i + i] = xs[i];\n\t result[i + i + 1] = x;\n\t }\n\t result[result.length - 1] = xs[xs.length - 1];\n\t return result;\n\t}\n\texports.intersperse = intersperse;\n\tfunction intercalate(xs, xss) {\n\t return concat(intersperse(xs, xss));\n\t}\n\texports.intercalate = intercalate;\n\tfunction foldl(f, initial, xs) {\n\t var result = initial;\n\t for (var i = 0; i < xs.length; i++) {\n\t result = f(result, xs[i]);\n\t }\n\t return result;\n\t}\n\texports.foldl = foldl;\n\tfunction foldr(f, initial, xs) {\n\t var result = initial;\n\t for (var i = xs.length - 1; i >= 0; i--) {\n\t result = f(xs[i], result);\n\t }\n\t return result;\n\t}\n\texports.foldr = foldr;\n\tfunction concat(xss) {\n\t var total = sum(map(function (xs) { return xs.length; }, xss));\n\t var result = new Array(total);\n\t var m = 0;\n\t for (var i = 0; i < xss.length; i++) {\n\t var xs = xss[i];\n\t for (var j = 0; j < xs.length; j++) {\n\t result[m++] = xs[j];\n\t }\n\t }\n\t return result;\n\t}\n\texports.concat = concat;\n\tfunction sum(xs) {\n\t var result = 0;\n\t for (var i = 0; i < xs.length; i++) {\n\t result += xs[i];\n\t }\n\t return result;\n\t}\n\texports.sum = sum;\n\tfunction product(xs) {\n\t var result = 1;\n\t for (var i = 0; i < xs.length; i++) {\n\t result *= xs[i];\n\t }\n\t return result;\n\t}\n\texports.product = product;\n\tfunction sort(xs, compare) {\n\t return copy(xs).sort(compare);\n\t}\n\texports.sort = sort;\n\tfunction sortInPlace(xs, compare) {\n\t xs.sort(compare);\n\t return xs;\n\t}\n\texports.sortInPlace = sortInPlace;\n\tfunction maximumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result < xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.maximumInRange = maximumInRange;\n\tfunction maximum(xs) {\n\t return maximumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.maximum = maximum;\n\tfunction maximumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result < candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.maximumInRangeWith = maximumInRangeWith;\n\tfunction maximumWith(xs, f) {\n\t return maximumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.maximumWith = maximumWith;\n\tfunction minimumInRange(xs, s, e) {\n\t var result = xs[s];\n\t for (var i = s + 1; i <= e; i++) {\n\t if (result > xs[i])\n\t result = xs[i];\n\t }\n\t return result;\n\t}\n\texports.minimumInRange = minimumInRange;\n\tfunction minimum(xs) {\n\t return minimumInRange(xs, 0, xs.length - 1);\n\t}\n\texports.minimum = minimum;\n\tfunction minimumInRangeWith(xs, s, e, f) {\n\t var result = f(xs[s]);\n\t for (var i = s + 1; i <= e; i++) {\n\t var candidate = f(xs[i]);\n\t if (result > candidate)\n\t result = candidate;\n\t }\n\t return result;\n\t}\n\texports.minimumInRangeWith = minimumInRangeWith;\n\tfunction minimumWith(xs, f) {\n\t return minimumInRangeWith(xs, 0, xs.length - 1, f);\n\t}\n\texports.minimumWith = minimumWith;\n\tfunction replicate(n, x) {\n\t var result = new Array(n);\n\t for (var i = 0; i < result.length; i++) {\n\t result[i] = x;\n\t }\n\t return result;\n\t}\n\texports.replicate = replicate;\n\tfunction take(n, xs) {\n\t return xs.slice(0, n);\n\t}\n\texports.take = take;\n\tfunction drop(n, xs) {\n\t return xs.slice(n);\n\t}\n\texports.drop = drop;\n\tfunction splitAt(n, xs) {\n\t return [take(n, xs), drop(n, xs)];\n\t}\n\texports.splitAt = splitAt;\n\tfunction takeWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(0, i);\n\t }\n\t }\n\t return xs.slice();\n\t}\n\texports.takeWhile = takeWhile;\n\tfunction dropWhile(f, xs) {\n\t for (var i = 0; i < xs.length; i++) {\n\t if (!f(xs[i])) {\n\t return xs.slice(i);\n\t }\n\t }\n\t return [];\n\t}\n\texports.dropWhile = dropWhile;\n\tfunction group(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t var last = [xs[0]];\n\t for (var i = 1; i < xs.length; i++) {\n\t if (last[0] === xs[i]) {\n\t last.push(xs[i]);\n\t }\n\t else {\n\t result.push(last);\n\t last = [xs[i]];\n\t }\n\t }\n\t result.push(last);\n\t return result;\n\t}\n\texports.group = group;\n\tfunction nub(xs) {\n\t if (xs.length == 0)\n\t return [];\n\t var result = [];\n\t result.push(xs[0]);\n\t for (var i = 1; i < xs.length; i++) {\n\t if (xs[i] !== xs[i - 1]) {\n\t result.push(xs[i]);\n\t }\n\t }\n\t return result;\n\t}\n\texports.nub = nub;\n\tfunction filter(f, xs) {\n\t var result = [];\n\t for (var i = 0; i < xs.length; i++) {\n\t if (f(xs[i]))\n\t result.push(xs[i]);\n\t }\n\t return result;\n\t}\n\texports.filter = filter;\n\tfunction zip(xs, ys) {\n\t var n = Prelude_1.min(xs.length, ys.length);\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = [xs[i], ys[i]];\n\t }\n\t return result;\n\t}\n\texports.zip = zip;\n\tfunction unzip(xs) {\n\t var r1 = new Array(xs.length);\n\t var r2 = new Array(xs.length);\n\t for (var i = 0; i < xs.length; i++) {\n\t r1[i] = xs[i][0];\n\t r2[i] = xs[i][1];\n\t }\n\t return [r1, r2];\n\t}\n\texports.unzip = unzip;\n\tfunction range(from, to) {\n\t var result = Array(to - from + 1);\n\t for (var i = from; i <= to; i++) {\n\t result[i - from] = i;\n\t }\n\t return result;\n\t}\n\texports.range = range;\n\tfunction copy(xs) {\n\t return xs.slice(0);\n\t}\n\texports.copy = copy;\n\tfunction apply_permutation(p, xs) {\n\t var n = xs.length;\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = xs[p[i]];\n\t }\n\t return result;\n\t}\n\texports.apply_permutation = apply_permutation;\n\tfunction next_permutation(p) {\n\t var n = p.length;\n\t if (n < 2)\n\t return null;\n\t var r = copy(p);\n\t var k = n - 2;\n\t for (; k >= 0 && r[k] >= r[k + 1]; k--)\n\t ;\n\t if (k < 0)\n\t return null;\n\t for (var i = k + 1, j = n - 1; i < j; i++, j--) {\n\t var t_1 = r[i];\n\t r[i] = r[j];\n\t r[j] = t_1;\n\t }\n\t var next = k + 1;\n\t for (; r[next] <= r[k]; next++)\n\t ;\n\t var t = r[k];\n\t r[k] = r[next];\n\t r[next] = t;\n\t return r;\n\t}\n\texports.next_permutation = next_permutation;\n\tfunction create(n, value) {\n\t return replicate(n, value);\n\t}\n\texports.create = create;\n\tfunction createWith(n, f) {\n\t var result = new Array(n);\n\t for (var i = 0; i < n; i++) {\n\t result[i] = f(i);\n\t }\n\t return result;\n\t}\n\texports.createWith = createWith;\n\tfunction create2D(n1, n2, value) {\n\t return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));\n\t}\n\texports.create2D = create2D;\n\tfunction create2DWith(n1, n2, f) {\n\t var result = new Array(n1);\n\t for (var i = 0; i < n1; i++) {\n\t result[i] = new Array(n2);\n\t for (var j = 0; j < n2; j++) {\n\t result[i][j] = f(i, j);\n\t }\n\t }\n\t return result;\n\t}\n\texports.create2DWith = create2DWith;\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n\tfunction min(a, b) {\n\t return a < b ? a : b;\n\t}\n\texports.min = min;\n\tfunction max(a, b) {\n\t return a < b ? b : a;\n\t}\n\texports.max = max;\n\tfunction curry(f) {\n\t return function (x) { return function (y) { return f(x, y); }; };\n\t}\n\texports.curry = curry;\n\tfunction uncurry(f) {\n\t return function (x, y) { return f(x)(y); };\n\t}\n\texports.uncurry = uncurry;\n\tfunction id(x) {\n\t return x;\n\t}\n\texports.id = id;\n\tfunction constant(x) {\n\t return function (_) { return x; };\n\t}\n\texports.constant = constant;\n\tfunction flip(f) {\n\t return function (y) { return function (x) { return f(x)(y); }; };\n\t}\n\texports.flip = flip;\n\tfunction flip2(f) {\n\t return function (y, x) { return f(x, y); };\n\t}\n\texports.flip2 = flip2;\n\tfunction compose(g, f) {\n\t return function (x) { return g(f(x)); };\n\t}\n\texports.compose = compose;\n\tfunction gcd(a, b) {\n\t var r = a % b;\n\t while (r !== 0) {\n\t a = b;\n\t b = r;\n\t r = a % b;\n\t }\n\t return b;\n\t}\n\texports.gcd = gcd;\n\n\n/***/ }\n/******/ ]);"}, {"source_code": "'use strict';\n\n/*let input = `\n2\n1 2\n2 2\n2 1\n1 1\n`.trim().split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar n = Number(readline()),\n result = [];\nvar rows = [],\n cols = [];\nfor (var i = 1; i <= n * n; i++) {\n\tvar _readline$split = readline().split(' ');\n\n\tvar _readline$split2 = _slicedToArray(_readline$split, 2);\n\n\tvar a = _readline$split2[0];\n\tvar b = _readline$split2[1];\n\n\tif (rows.indexOf(a) === -1 && cols.indexOf(b) === -1) {\n\t\tresult.push(i);\n\t\trows.push(a);\n\t\tcols.push(b);\n\t}\n}\nprint(result.join(' '));\n"}], "negative_code": [{"source_code": "'use strict';\n\n/*let input = `\n1\n1 1\n`.trim().split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar n = Number(readline()),\n result = [];\nfor (var i = 1; i <= n * n; i++) {\n\tvar _readline$split = readline().split(' ');\n\n\tvar _readline$split2 = _slicedToArray(_readline$split, 2);\n\n\tvar a = _readline$split2[0];\n\tvar b = _readline$split2[1];\n\n\tif (a === b) {\n\t\tresult.push(i);\n\t}\n}\nprint(result.join(' '));\n"}], "src_uid": "c611808e636d9307e6df9ee0e706310b"} {"source_code": "var n=readline();\nvar s=[];\nvar i=0;\nvar mindays=0,temp,days1,days;\nwhile(n)\n{\n s[i] = readline();\n i++;\n n--;\n}\nfor(temp of s)\n{\n var days=parseInt(temp.split(\" \")[0]);\n var altdays=parseInt(temp.split(\" \")[1]);\n if(mindays=days)\n days=days+altdays;\n mindays=days\n}\n}\nprint(mindays);\n", "positive_code": [{"source_code": "var n = +readline();\nvar t = 0;\nfor (var i = 0; i < n; i++) {\n var line = readline().split(\" \");\n var s = +line[0], d = +line[1];\n t++;\n while (t < s || t % d !== s % d) {\n t++;\n }\n}\nprint(t);"}], "negative_code": [{"source_code": "var n=readline();\nvar s=[];\nvar i=0;\nvar mindays=0,temp,days1,days;\nwhile(n)\n{\n s[i] = readline();\n i++;\n n--;\n}\nfor(temp of s)\n{\n var days=parseInt(temp.split(\" \")[0]);\n var altdays=parseInt(temp.split(\" \")[1]);\n days{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(h){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function c(){return p().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [a, b, c, d] = io.nextNumbers()\n// \n// io.puts(Math.max(a + b, c + d))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c, d] = readLine().split(\" \").map(Number);\n\n console.log(Math.max(a + b, c + d));\n }\n}\n"}, {"source_code": "var fs = require(\"fs\");\n\nvar buffer = fs.readFileSync(0);\n\nvar arr = buffer.toString().split(\"\\n\").map(val => val.trim());\n\nlet t = +arr[0];\n\nfor(var i = 1; i <= t; i++)\n{\n let nums = arr[i].split(\" \").map(val => Number(val));\n console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));\n}"}, {"source_code": "var fs = require(\"fs\");\n\nvar buffer = fs.readFileSync(0);\n\nvar arr = buffer.toString().split(\"\\n\").map(val => val.trim());\n\nlet t = +arr[0];\n\nlet out = \"\";\nfor(var i = 1; i <= t; i++)\n{\n let nums = arr[i].split(\" \").map(val => Number(val));\n out += Math.max(nums[0]+nums[1], nums[2]+nums[3]).toString() + \"\\n\";\n}\nconsole.log(out);"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n input.trim().split('\\n').slice(1).forEach((line) => {\n const [a, b, c, d] = line.split(' ').map((x) => parseInt(x))\n console.log(Math.max(a + b, c + d))\n })\n})\n"}, {"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x)); \n\t\n\tif((params[0]+params[2] < params[0]+params[1]) || (params[0]+params[2] < params[2]+params[3]))\n\t{\n\t print(params[0]+params[2])\n\t}\n\telse\n\t{\n\t if((params[0]+params[1] )> (params[2]+params[3]))\n\t {\n\t print(params[0]+params[1])\n\t }\n\t else\n\t {\n\t print( params[2]+params[3])\n\t }\n\t}\n}\n"}], "negative_code": [{"source_code": "var fs = require(\"fs\");\n\nvar buffer = fs.readFileSync(0);\n\nvar arr = buffer.toString().split(\"\\n\").map(val => val.trim());\n\nlet t = +arr[0][0];\n\nfor(var i = 1; i <= t; i++)\n{\n let nums = arr[i].split(\" \").map(val => Number(val));\n console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));\n}"}, {"source_code": "var fs = require(\"fs\");\n\nvar buffer = fs.readFileSync(0);\n\nvar arr = buffer.toString().split(\"\\n\").map(val => val.trim());\n\nlet t = +arr[0][0];\n\nfor(var i = 1; i < arr.length; i++)\n{\n let nums = arr[i].split(\" \").map(val => Number(val));\n console.log(Math.max(nums[0]+nums[1], nums[2]+nums[3]));\n}"}], "src_uid": "a60321dd9ada279c007415f28775099b"} {"source_code": "var n = +readline();\nvar arr = [], l = 0, r = 0;\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ').map(Number);\n l += input[0];\n r += input[1];\n arr.push(2 * (input[0] - input[1]))\n}\nvar max = Math.abs(l - r), k = 0;\narr.forEach((el, i) => {\n var curr_val = Math.abs(l - r - el);\n if (max < curr_val) {\n max = curr_val;\n k = i + 1\n }\n});\n\nprint(k);", "positive_code": [{"source_code": "function readIntTabLine() {\n var l = readline().split(' ')\n for (var i = 0 ; i < l.length ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar n = parseInt(readline()), // n columns\n cols = [],\n beauty = 0\n\nfor (var i = 0 ; i < n ; i++) {\n cols[i] = readIntTabLine() // li left leg, ri right leg\n cols[i][2] = cols[i][0] - cols[i][1]\n beauty += cols[i][2]\n}\n\nvar max = 0,\n ans = -1\n\nfor (var i = 0 ; i < n ; i++) {\n var mod = Math.abs(beauty - 2*cols[i][2]) - Math.abs(beauty)\n if (mod > max) {\n max = mod\n ans = i\n }\n}\n\nprint(ans+1)\n"}, {"source_code": "var N = Number(readline());\nvar arr = [];\nvar toread = [];\nvar score_a = [];\nvar total = 0;\nfor (var i = 0;i < N;i ++) {\n\ttoread = readline().split(' ');\n\tarr.push({\n\t\ts: Number(toread[0]),\n\t\te: Number(toread[1])\n\t});\n\tscore_a.push(arr[i].s - arr[i].e);\n\ttotal += score_a[i];\n};\n\nvar max = Math.abs(total);\nvar z_total = z(total);\nvar rs = 0;\nfor (var i = 0;i < score_a.length;i ++) {\n\tvar tmp_max = Math.abs(total - 2 * score_a[i]);\n\tif (tmp_max > max) {\n\t\trs = i + 1;\n\t\tmax = tmp_max;\n\t}\n}\n\nprint(rs);\n\nfunction z(_a) {\n\tvar a = Math.abs(_a);\n\treturn a == _a;\n}\n\n"}, {"source_code": "var n = +readline();\nvar arr = [], l = 0, r = 0;\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ').map(Number);\n l += input[0];\n r += input[1];\n arr.push(input)\n}\nvar max = Math.abs(l - r);\nvar k = 0;\nfor (var i = 0; i < n; i++) {\n var el = arr[i];\n if (max < Math.abs(l - el[0] + el[1] - r + el[1] - el[0])) {\n max = Math.abs(l - el[0] + el[1] - r + el[1] - el[0]);\n k = i + 1\n }\n}\n\nprint(k);"}, {"source_code": "var n = +readline();\nvar arr = [], l = 0, r = 0;\nfor (var i = 0; i < n; i++) {\n var input = readline().split(' ').map(Number);\n l += input[0];\n r += input[1];\n arr.push(input)\n}\nvar max = Math.abs(l - r), k = 0;\narr.forEach((el, i) => {\n var curr_val = Math.abs(l - r - 2 * el[0] + 2 * el[1]);\n if (max < curr_val) {\n max = curr_val;\n k = i + 1\n }\n});\n\nprint(k);"}], "negative_code": [], "src_uid": "2be73aa00a13be5274cf840ecd3befcb"} {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n l++\r\n const [n, m] = lines[l++].trim().split(' ').map(Number)\r\n const [src, dst] = lines[l++].trim().split(' ').map(Number)\r\n const edges = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))\r\n l += m\r\n output[i] = solve(n, m, src, dst, edges)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\nclass Queue {\r\n constructor() {\r\n this.map = {}\r\n this.first = 0\r\n this.last = 0\r\n }\r\n push(val) {\r\n this.map[this.last++] = val\r\n }\r\n shift() {\r\n const r = this.map[this.first]\r\n delete this.map[this.first]\r\n this.first++\r\n return r\r\n }\r\n size() {\r\n if (this.first >= this.last) return 0\r\n return this.last - this.first\r\n }\r\n}\r\nfunction solve(n, m, s, t, edges) {\r\n const adj = {}\r\n edges.forEach(([a, b]) => {\r\n adj[a] = adj[a] || []\r\n adj[b] = adj[b] || []\r\n adj[a].push(b)\r\n adj[b].push(a)\r\n })\r\n\r\n // const q = [[s, 0, 0]]\r\n const q = new Queue()\r\n q.push([s, 0, 0])\r\n const dist = [Array(n + 1).fill(Infinity), Array(n + 1).fill(Infinity)] // distance\r\n const count = [Array(n + 1).fill(0), Array(n + 1).fill(0)] // ways\r\n const visited = [Array(n + 1).fill(0), Array(n + 1).fill(0)] // ways\r\n dist[0][s] = 0\r\n count[0][s] = 1\r\n let md = Infinity\r\n // while (q.length) {\r\n while (q.size()) {\r\n // console.log(q.slice(0, 10))\r\n const [u, d, c] = q.shift()\r\n if (visited[c][u]) continue\r\n visited[c][u] = 1\r\n if (u === t) {\r\n if (c === 0) md = d\r\n if (c === 1) break\r\n }\r\n if (d >= md + 1) continue\r\n const nd = d + 1\r\n const nc = count[c][u]\r\n //\r\n ;(adj[u] || []).forEach(v => {\r\n if (nd < dist[0][v]) {\r\n if (dist[1][v] !== Infinity) {\r\n dist[1][v] = dist[0][v]\r\n if (dist[1][v] <= nd + 1) {\r\n count[1][v] = count[0][v]\r\n // q.push([v, dist[1][v], 1])\r\n push(q, visited, v, dist[1][v], 1)\r\n } else {\r\n dist[1][v] = Infinity\r\n }\r\n }\r\n dist[0][v] = nd\r\n count[0][v] = nc\r\n // q.push([v, nd, 0])\r\n push(q, visited, v, nd, 0)\r\n } else if (nd === dist[0][v]) {\r\n count[0][v] = add(count[0][v], nc)\r\n } else if (nd < dist[1][v]) {\r\n dist[1][v] = nd\r\n if (dist[1][v] <= dist[0][v] + 1) {\r\n count[1][v] = nc\r\n // q.push([v, nd, 1])\r\n push(q, visited, v, nd, 1)\r\n } else {\r\n dist[1][v] = Infinity\r\n }\r\n } else if (nd === dist[1][v]) {\r\n count[1][v] = add(count[1][v], nc)\r\n }\r\n })\r\n }\r\n// console.log(dist)\r\n// console.log(count)\r\n if (dist[1][t] === dist[0][t] + 1) {\r\n return add(count[0][t], count[1][t])\r\n } else {\r\n return count[0][t]\r\n }\r\n}\r\nfunction push(q, visited, u, d, c) {\r\n if (visited[c][u]) return\r\n q.push([u, d, c])\r\n}\r\nfunction add(a, b) {\r\n return (a + b) % (1e9 + 7)\r\n}\r\n", "positive_code": [{"source_code": "'use strict';\nconst { throws } = require('assert');\n\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\nconst MOD = 1e9+7;\n\nclass Graph {\n constructor(){\n this.g = {};\n }\n add(a, b){\n if (!this.g[a])\n this.g[a] = [];\n this.g[a].push(b);\n }\n bfs(s, t){\n let counts = {};\n counts[s] = {0: 1};\n let paths_count = {[s]: 1};\n let queue = [], qi = 0;\n let min_path;\n l('GRAPH')\n queue.push([s, 0]);\n while (qi{\n return graph.bfs(s, t);\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n readline()\n let [n, m] = ra();\n let [s, t] = ra();\n s--; t--;\n let graph = new Graph();\n for (let i=0; i {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst EPS = 1e-6;\n\nclass Graph {\n constructor(){\n this.g = {};\n }\n add(a, b){\n if (!this.g[a])\n this.g[a] = [];\n this.g[a].push(b);\n }\n bfs(s, t){\n let counts = {};\n counts[s] = {0: 1};\n let queue = [], qi = 0;\n let min_path;\n l('GRAPH')\n queue.push([s, 0]);\n while (qi{\n return graph.bfs(s, t);\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n readline()\n let [n, m] = ra();\n let [s, t] = ra();\n s--; t--;\n let graph = new Graph();\n for (let i=0; i {\n while (b) {\n const w = b;\n b = a % b;\n a = w;\n }\n return a;\n};\n\nconst lcm = (s, t) => {\n const length = Math.floor((s.length * t.length) / gcd(s.length, t.length));\n s = s.repeat(Math.floor(length / s.length));\n t = t.repeat(Math.floor(length / t.length));\n if (s === t) return s;\n return -1;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n const s = readline();\n const t = readline();\n console.log(lcm(s, t));\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var a = readline()\r\n var b = readline()\r\n var s = a\r\n if (a.length > b.length) {\r\n a = b\r\n b = s\r\n }\r\n\r\n var ss = ''\r\n for (let i = 0; i < a.length; i++) {\r\n ss += a[i]\r\n if (a.length % ss.length === 0 && ss.repeat(a.length / ss.length) === a &&\r\n b.length % ss.length === 0 && ss.repeat(b.length / ss.length) === b\r\n ) {\r\n var len = ss.length\r\n var count = 1\r\n while (len % a.length !== 0 || len % b.length !== 0) {\r\n count++\r\n len += ss.length\r\n }\r\n // console.log(ss, count, len, len % a.length !== 0, len % b.length !== 0)\r\n console.log(ss.repeat(count))\r\n return\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n const LCM = (n1, n2) => {\r\n let i = 1,\r\n t = n1;\r\n while (n1 % n2 !== 0) {\r\n n1 = t * i;\r\n i++;\r\n }\r\n return n1;\r\n };\r\n while (t--) {\r\n let str1 = readline().trim().split(\"\");\r\n let str2 = readline().trim().split(\"\");\r\n let len = LCM(str1.length, str2.length);\r\n let n1 = [],\r\n n2 = [];\r\n for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);\r\n for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);\r\n let ans = true;\r\n for (let i = 0; i < len; i++) {\r\n if (n1[i] !== n2[i]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? n1.join(\"\") : -1}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst s1 = readLine();\n\t\tconst s2 = readLine();\n\t\tlet [small, large] = ['', ''];\n\t\tif (s1 < s2) {\n\t\t\t[small, large] = [s1, s2];\n\t\t} else {\n\t\t\t[small, large] = [s2, s1];\n\t\t}\n\t\tconst [smallLen, largeLen] = [small.length, large.length];\n\t\tif (largeLen % smallLen === 0) {\n\t\t\tif (small.repeat(largeLen / smallLen) === large) console.log(large);\n\t\t\telse console.log(-1);\n\t\t} else {\n\t\t\tlet len = Math.floor((smallLen * largeLen) / gcd(smallLen, largeLen));\n\t\t\tif (small.repeat(len / smallLen) === large.repeat(len / largeLen)) {\n\t\t\t\tconsole.log(small.repeat(len / smallLen));\n\t\t\t} else console.log(-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "const readline = require('readline');\r\nconst { stdin: input, stdout: output } = require('process')\r\nconst rl = readline.createInterface({ input, output })\r\n\r\nlet lines = []\r\n\r\nconst createReadLine = () => {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nfunction divided(a, b) {\r\n return a.split(b).join('').length ? false : true;\r\n}\r\n\r\n\r\nfunction gcd(a, b) {\r\n\tif (!a || !b) return 0\r\n\r\n\twhile (true) {\r\n\t\tif ((a %= b) === 0)\r\n\t\t\treturn Math.abs(b);\r\n\t\telse if ((b %= a) === 0)\r\n\t\t\treturn Math.abs(a);\r\n }\r\n}\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n let t = parseInt(readLine());\r\n while (t--) {\r\n let a = readLine(), \r\n b = readLine()\r\n\r\n const lcm = (a.length * b.length / gcd(a.length, b.length))\r\n\r\n if (a.length < b.length) [a, b] = [b, a]\r\n const str = b.repeat(lcm / b.length)\r\n\r\n if (divided(str, a) && divided(str, b)) {\r\n console.log(str)\r\n } \r\n else {\r\n console.log(-1)\r\n }\r\n }\r\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = next();\r\n\t\tvar B = next();\r\n\t\tvar l = lcm(A.length, B.length);\r\n\t\tvar nA = new Array(l / A.length).fill(A).join(\"\");\r\n\t\tvar nB = new Array(l / B.length).fill(B).join(\"\");\r\n\t\tif(nA == nB){\r\n\t\t\tmyout(nA);\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}\r\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let firstWord = readline()\n let secondWord = readline()\n let smallWord = '', largeWord = '', ans = ''\n // ====== SOLUTION ======\n // console.log(`Firstword = ${firstWord} | secondWord = ${secondWord}`)\n if (firstWord.length < secondWord.length) {\n smallWord = firstWord\n largeWord = secondWord\n } else {\n largeWord = firstWord\n smallWord = secondWord\n }\n if (!isCompleteSubstring(smallWord, largeWord)) {\n console.log(-1)\n return\n }\n // get length from here\n const smallWordLength = smallWord.length\n const largeWordLength = largeWord.length\n \n const lcm = (largeWordLength * smallWordLength)/gcd(smallWordLength, largeWordLength)\n // console.log(`lcm = ${lcm}`)\n let factor = lcm/largeWordLength\n // ans = largeWord\n while (factor--) {\n ans += largeWord\n }\n console.log(ans)\n}\n\nfunction isCompleteSubstring(smallWord, largeWord) {\n if (!largeWord.includes(smallWord))\n return false\n \n let newWord = largeWord + smallWord\n smallWord += largeWord\n // console.log(`SmallWOr = ${smallWord} | largeWord = ${newWord}`)\n if (smallWord !== newWord)\n return false\n return true\n}\nfunction gcd(a, b) {\n // console.log(`a = ${a}, b = ${b}`)\n if(a == 0)\n return b\n return gcd(b % a, a)\n}"}, {"source_code": "const readline = require(\"readline\");\r\nconst leScan = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout\r\n\t//terminal: false\r\n});\r\n\r\ntoggle = true;\r\ni1 = 0;\r\nleScan.on(\"line\", (input) => {\r\n\tif (i1 == 0)\r\n\t{\r\n\t\ti1 = 3; //Ok we went over i1\r\n\t\treturn;\r\n\t}\r\n\r\n\tif (toggle)\r\n\t{\r\n\t\ti1 = input;\r\n\t\ttoggle = false;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tconsole.log(lcm(i1, input));\r\n\t\ttoggle = true;\r\n\t}\r\n});\r\n\r\nconst lcm = (s1, s2) => {\r\n\tlet s1Construct = s1;\r\n\tlet s2Construct = s2;\r\n\r\n\t/*//Makes sure a GCF actually exists or the LCM will never exist lmao\r\n\tif (findGCF(s1, s2) == -1)\r\n\t{\r\n\t\treturn -1;\r\n\t}*/\r\n\r\n\twhile (s1Construct != s2Construct)\r\n\t{\r\n\t\tif (s1Construct.length < s2Construct.length)\r\n\t\t{\r\n\t\t\ts1Construct += s1;\r\n\t\t}\r\n\t\telse if (s1Construct.length == s2Construct.length) //If it's equal, then it means we're hopeless and a LCM does not exist\r\n\t\t{\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\telse //if s2Construct.length < s1Construct.length\r\n\t\t{\r\n\t\t\ts2Construct += s2;\r\n\t\t}\r\n\t}\r\n\r\n\treturn s1Construct;\r\n}\r\n\r\n/*const cm = (str) => {\r\n\tlet gcf = \"\";\r\n\tlet currchain = \"\";\r\n\r\n\tfor (var i=0; i < str.length; i++)\r\n\t{\r\n\t\tcurrchain += str[i];\r\n\r\n\t\tvar currdex = currchain.length - 1;\r\n\t\t\r\n\t\t//Checks if the currchain matches the gcf (% accounts for repeats). If it doesn't, we know the gcf + currChain is the cm\r\n\t\tif (currchain[currdex] != gcf[currdex % gcf.length])\r\n\t\t{\r\n\t\t\tgcf += currchain;\r\n\t\t\tcurrchain = \"\";\r\n\t\t}\r\n\t}\r\n\r\n\t//Returns the gcf and the number of times the gcf repeats in the string. Should be an int if a gcf exists\r\n\treturn [gcf, str.length / gcf.length];\r\n}\r\n\r\nconst lcm = (s1, s2) => {\r\n\tif (s2.length < s1.length)\r\n\t{\r\n\t\tvar temp = s2;\r\n\t\ts2 = s1; //convience purposes lol\r\n\t\ts1 = temp;\r\n\t}\r\n\r\n\tlet gcf = findGCF(s1, s2);\r\n\r\n\tif (gcf == -1)\r\n\t{\r\n\t\treturn -1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\t//Modify s1 until it matches s2 using the gcf\r\n\r\n\t\twhile (s1 != s2)\r\n\t\t{\r\n\r\n\t\t}\r\n\t}\r\n}*/\r\n\r\nconst findGCF = (s1, s2) => {\r\n\tif (s2.length < s1.length)\r\n\t{\r\n\t\tvar temp = s2;\r\n\t\ts2 = s1; //convience purposes lol\r\n\t\ts1 = temp;\r\n\t}\r\n\r\n\t//Modified Euler GCF formula lmao\r\n\t//But this is easier as last index will be remainder\r\n\t//tracker keeps track of how many times we have splitted s2\r\n\tvar arr = s2.split(s1);\r\n\tvar gcf = arr[0];\r\n\tvar remainder = arr[arr.length - 1];\r\n\r\n\t//If the function did not make the gcf length less, then we know that it's hopeless and we should just return -1\r\n\tif (gcf.length == s2.length)\r\n\t{\r\n\t\treturn -1;\r\n\t}\r\n\r\n\t//When gcf == remainder, the remainder is \"0\"\r\n\treturn gcf == remainder ? gcf : findGCF(gcf, remainder);\r\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (a, b) => {\n if (a < b) {\n const temp = a\n a = b\n b = temp\n }\n\n let tempA = a\n let tempB = b\n\n while (tempA.length !== tempB.length) {\n if (tempA.length > tempB.length) {\n tempB += b\n } else {\n tempA += a\n }\n }\n\n return tempA === tempB ? tempA : -1\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet a, b\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 2\n if (mode === 0) {\n a = line\n } else if (mode === 1) {\n b = line\n answer.push(calculate(a, b))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n\n// chainNumberList, cList, aList, bList\n// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))\n"}, {"source_code": "/*\r\n * File Created: Thursday, 14th January 2021 3:54:21 pm\r\n * Author: Lukas Rimkus\r\n */\r\n\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine(), 10);\r\n\r\n while(testCases--) {\r\n\r\n const s = readLine();\r\n\r\n const t = readLine();\r\n\r\n const res = b(s,t);\r\n \r\n console.log(res);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(n, d, arr){\r\n \r\n arr.sort((a,b) => a - b);\r\n // console.log(arr)\r\n for(let i = 0; i < n ; i++){\r\n if(arr[i] <= d) continue;\r\n if(arr[i] > d){\r\n if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){\r\n continue;\r\n }\r\n if(i === 0){\r\n if(arr[1] + arr[2] <= d) continue;\r\n }\r\n if(i === 1){\r\n if(arr[0] + arr[2] <= d) continue;\r\n }\r\n }\r\n return 'NO'\r\n }\r\n return 'YES'\r\n}\r\n\r\nfunction gcd(a,b){\r\n if(b === 0) return a;\r\n else{\r\n return gcd(b, a % b)\r\n }\r\n}\r\n\r\nfunction lcm(a,b){\r\n return (a * b) / gcd(a,b)\r\n}\r\n\r\nfunction mul(s, k) {\r\n let res = '';\r\n while(k--) res += s;\r\n return res;\r\n}\r\n\r\nfunction b(s,t){\r\n const n = s.length;\r\n const m = t.length;\r\n const g = gcd(n,m);\r\n // console.log('gcd(n,m) = ',g,'mul(s,m/g) = ', mul(s, m/ g), 'mul(t,n/g) = ', mul(t, n / g), 'm/g = ', m/g, 'n/g = ', n/g)\r\n if(mul(s,m /g) === mul(t, n / g)){\r\n return mul(s, m / g);\r\n } else {\r\n return -1;\r\n }\r\n}\r\n\r\nmodule.exports = b;"}, {"source_code": "'use strict'\r\n\r\nlet q = readline();\r\n while(q--)\r\n {\r\n let s = readline(), sn = \"\";\r\n let t = readline(), tn = \"\";\r\n let c = false;\r\n function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}\r\n let sl = t.length/gcd(s.length, t.length);\r\n let tl = s.length/gcd(s.length, t.length);\r\n for(let i = 0; i < sl; i++)sn +=s;\r\n for(let i = 0; i < tl; i++)tn +=t;\r\n print(sn == tn ? sn : -1);\r\n }"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(iter; iter > 0; iter--){\r\n let a = readline();\r\n let b = readline();\r\n\r\n let str1 = b;\r\n let str2 = a;\r\n\r\n let gcd = greatestCommonDivisor(a.length, b.length)\r\n\r\n let i1 = a.length / gcd;\r\n let i2 = b.length / gcd;\r\n for(i1; i1 > 1; i1--){\r\n str1 += b;\r\n }\r\n for(i2; i2 > 1; i2--){\r\n str2 += a;\r\n }\r\n\r\n if(str1 === str2){\r\n print(str1);\r\n } else {\r\n print(-1);\r\n }\r\n}\r\n\r\nfunction greatestCommonDivisor(a, b){\r\n if(b === 0) return a;\r\n return greatestCommonDivisor(b, a % b);\r\n}"}], "negative_code": [{"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n // console.log(sL % stringL, tL % stringL)\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (d1*d2)\r\n // console.log(string.repeat(d1), s, string.repeat(d2), t)\r\n // console.log(sL, tL, stringL)\r\n // console.log(ans, sL % tL, tL % tL)\r\n ans = ans === 0 ? 1 : ans\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n if(d1 === 1) return string.repeat(d2)\r\n if(d2 === 1) return string.repeat(d1)\r\n if(sL % tL === 0) return s\r\n if(tL % sL === 0) return t\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n // console.log(sL % stringL, tL % stringL)\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (tL*sL/stringL / stringL)\r\n // console.log(string.repeat(d1), s, string.repeat(d2), t)\r\n // console.log(sL, tL, stringL)\r\n // console.log(ans)\r\n ans = ans === 0 ? 1 : ans\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n if(d1 === 1) return string.repeat(d2)\r\n if(d2 === 1) return string.repeat(d1)\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n // console.log(sL % stringL, tL % stringL)\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (tL*sL/stringL)\r\n // console.log(string.repeat(d1), s, string.repeat(d2), t)\r\n // console.log(ans)\r\n // console.log(ans)\r\n ans = ans === 0 ? 1 : ans\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n if(d1 === 1) return string.repeat(d2)\r\n if(d2 === 1) return string.repeat(d1)\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n // console.log(sL % stringL, tL % stringL)\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (d1*d2/stringL)\r\n // console.log(string.repeat(d1), s, string.repeat(d2), t)\r\n // console.log(ans)\r\n // console.log(ans)\r\n ans = ans === 0 ? 1 : ans\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n if(d1 === 1) return string.repeat(d2)\r\n if(d2 === 1) return string.repeat(d1)\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n // console.log(sL % stringL, tL % stringL)\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2\r\n // console.log(string.repeat(d1),s, string.repeat(d2), t)\r\n // console.log(ans)\r\n ans = ans === 0? 1: ans\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n var d1 = sL / stringL\r\n var d2 = tL / stringL\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2\r\n if (string.repeat(d1) === s && string.repeat(d2) === t) {\r\n\r\n return string.repeat(ans)\r\n }\r\n return false\r\n}"}, {"source_code": "// 'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var s = readline();\r\n var t = readline();\r\n var min = s.length < t.length ? s : t\r\n // console.log(s, t)\r\n var l = min.length\r\n var string = ''\r\n var answer = false\r\n for (var i = 1; i <= l; i++) {\r\n string = min.substring(0, i)\r\n // console.log(string)\r\n var check = checkString(string, s, t)\r\n if (check) {\r\n return console.log(check)\r\n }\r\n }\r\n console.log(-1)\r\n\r\n })\r\n\r\n}\r\n\r\nfunction checkString(string, s, t) {\r\n var stringL = string.length\r\n var sL = s.length\r\n var tL = t.length\r\n if (sL % stringL !== 0 || tL % stringL !== 0) return false\r\n if (string.repeat(sL / stringL) === s && string.repeat(tL / stringL) === t) return string.repeat(sL / stringL + tL / stringL)\r\n return false\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let str1 = readline().trim().split(\"\");\r\n let str2 = readline().trim().split(\"\");\r\n let len;\r\n if (str1.length > str2.length)\r\n len =\r\n str1.length % str2.length === 0\r\n ? str1.length\r\n : str1.length * str2.length;\r\n else\r\n len =\r\n str2.length % str1.length === 0\r\n ? str2.length\r\n : str1.length * str2.length;\r\n let n1 = [],\r\n n2 = [];\r\n for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);\r\n for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);\r\n let ans = true;\r\n for (let i = 0; i < len; i++) {\r\n if (n1[i] !== n2[i]) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n console.log(`${ans === true ? n1.join(\"\") : -1}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst s1 = readLine();\n\t\tconst s2 = readLine();\n\t\tlet [small, large] = ['', ''];\n\t\tif (s1 < s2) {\n\t\t\t[small, large] = [s1, s2];\n\t\t} else {\n\t\t\t[small, large] = [s2, s1];\n\t\t}\n\t\tconst [smallLen, largeLen] = [small.length, large.length];\n\t\tif (largeLen % smallLen === 0) {\n\t\t\tif (small.repeat(largeLen / smallLen) === large) console.log(large);\n\t\t\telse console.log(-1);\n\t\t} else {\n\t\t\tif (small.repeat(largeLen) === large.repeat(smallLen)) {\n\t\t\t\tconsole.log(small.repeat(largeLen));\n\t\t\t} else console.log(-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict'\r\n\r\nlet q = readline();\r\n while(q--)\r\n {\r\n let s = readline();\r\n let t = readline();\r\n let c = false;\r\n if(t.length > s.length)\r\n {\r\n let temp = s;\r\n s = t; \r\n t = temp;\r\n }\r\n function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}\r\n let sl = t.length/gcd(s.length, t.length);\r\n for(let i = 1; i < sl; i++)s+=s;\r\n if(s.includes(t))\r\n {\r\n c = true;\r\n let a = s.split(t);\r\n for(let i = 0; i < a.length; i++)if(a[i].length)c = false;\r\n }\r\n print(c? s : -1);\r\n }"}, {"source_code": "'use strict'\r\n\r\nlet q = readline();\r\n while(q--)\r\n {\r\n let s = readline();\r\n let t = readline();\r\n let c = true;\r\n if(t.length > s.length)\r\n {\r\n let temp = s;\r\n s = t; \r\n t = temp;\r\n }\r\n function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}\r\n let sl = t.length/gcd(s.length, t.length);\r\n for(let i = 1; i < sl; i++)s+=s;\r\n if(s.includes(t))\r\n {\r\n let a = s.split(t);\r\n for(let i = 0; i < a.length; i++)if(a[i].length)c = false;\r\n }\r\n print(c? s : -1);\r\n }"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(iter; iter > 0; iter--){\r\n let a = readline();\r\n let b = readline();\r\n \r\n if(a.length > b.length){\r\n let bufer = b;\r\n b = a;\r\n a = bufer;\r\n }\r\n\r\n if(b.indexOf(a) === -1){\r\n print(-1);\r\n } else {\r\n let str = b;\r\n let i = a.length / greatestCommonDivisor(a.length, b.length);\r\n for(i; i > 1; i--){\r\n str += b;\r\n }\r\n\r\n if(str.slice(-b.length, str.length) === b && str.slice(-a.length, str.length) === a){\r\n print(str);\r\n } else {\r\n print(-1);\r\n }\r\n }\r\n}\r\n\r\nfunction greatestCommonDivisor(a, b){\r\n if(b === 0) return a;\r\n return greatestCommonDivisor(b, a % b);\r\n}"}], "src_uid": "710c7211d23cf8c01fae0b476a889276"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const l = new Array(m),\r\n r = new Array(m);\r\n for (let i = 0, j = 0; i < n; i++, j++) {\r\n while (a[i] !== b[j]) i++;\r\n l[j] = i;\r\n }\r\n for (let i = n - 1, j = m - 1; i >= 0; i--, j--) {\r\n while (a[i] !== b[j]) i--;\r\n r[j] = i;\r\n }\r\n let res = 0;\r\n for (let i = 0; i < m - 1; i++) {\r\n res = Math.max(res, r[i + 1] - l[i]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var s = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var t = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n // console.log(s)\r\n // console.log(t)\r\n var pos1 = {}, pos2 = {}\r\n var j = 0\r\n for (let i = 0; i < m; i++) {\r\n while (t[i] !== s[j]) j++\r\n pos1[i] = j\r\n j++\r\n }\r\n j = n - 1\r\n // console.log('-----')\r\n for (let i = m-1; i >=0; i--) {\r\n while (t[i] !== s[j] && j>=0) {\r\n j--\r\n }\r\n pos2[i] = j\r\n j--\r\n\r\n }\r\n var max = 1\r\n for (let i = 0; i < m-1; i++) {\r\n max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))\r\n }\r\n\r\n // console.log(pos1)\r\n // console.log(pos2)\r\n console.log(max)\r\n}"}, {"source_code": "let text = '';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', str => {\r\n if (str === '\\r\\n' || str === '\\n') {\r\n process.stdin.emit('end');\r\n } else {\r\n text += str;\r\n }\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = text.trim().replace(/\\r/g, '').split('\\n');\r\n // const total = +input[0];\r\n // for (let i = 1; i <= total; i++) {\r\n // console.log(solve(input[i]));\r\n // }\r\n console.log(solve(input[1], input[2]));\r\n process.exit();\r\n});\r\n\r\nfunction solve(a, b) {\r\n const charArys = new Array(26).fill(0).map(() => []);\r\n for (let i = 0; i < a.length; i++) {\r\n const code = a[i].charCodeAt() - 97;\r\n charArys[code].push(i);\r\n }\r\n\r\n const pres = new Array(b.length);\r\n pres[0] = charArys[b[0].charCodeAt() - 97][0];\r\n for (let i = 1; i < b.length; i++) {\r\n const ary = charArys[b[i].charCodeAt() - 97];\r\n const pre = pres[i - 1];\r\n let left = 0; right = ary.length - 1;\r\n while (left < right) {\r\n const mid = (left + right) >> 1;\r\n if (ary[mid] > pre) {\r\n right = mid;\r\n } else {\r\n left = mid + 1;\r\n }\r\n }\r\n pres[i] = ary[left];\r\n }\r\n const last = b[b.length - 1].charCodeAt() - 97;\r\n let max = charArys[last].pop();\r\n let result = max - pres[b.length - 2];\r\n for (let i = b.length - 2; i; i--) {\r\n const ary = charArys[b[i].charCodeAt() - 97];\r\n let left = 0; right = ary.length - 1;\r\n if (ary[right] < max) {\r\n left = right;\r\n } else {\r\n while (left < right) {\r\n const mid = (left + right) >> 1;\r\n if (ary[mid] >= max) {\r\n right = mid;\r\n } else {\r\n left = mid + 1;\r\n }\r\n }\r\n left--;\r\n }\r\n max = ary[left];\r\n result = Math.max(result, max - pres[i - 1]);\r\n }\r\n return result;\r\n}\r\n\r\n"}, {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n // const total = +input[0];\n // for (let i = 1; i <= total; i++) {\n // console.log(solve(input[i]));\n // }\n console.log(solve(input[1], input[2]));\n process.exit();\n});\n\nfunction solve(a, b) {\n const charArys = new Array(26).fill(0).map(() => []);\n for (let i = 0; i < a.length; i++) {\n const code = a[i].charCodeAt() - 97;\n charArys[code].push(i);\n }\n\n const pres = new Array(b.length);\n pres[0] = charArys[b[0].charCodeAt() - 97][0];\n for (let i = 1; i < b.length; i++) {\n const ary = charArys[b[i].charCodeAt() - 97];\n const pre = pres[i - 1];\n let left = 0; right = ary.length - 1;\n while (left < right) {\n const mid = (left + right) >> 1;\n if (ary[mid] > pre) {\n right = mid;\n } else {\n left = mid + 1;\n }\n }\n pres[i] = ary[left];\n }\n const last = b[b.length - 1].charCodeAt() - 97;\n let max = charArys[last].pop();\n let result = max - pres[b.length - 2];\n for (let i = b.length - 2; i; i--) {\n const ary = charArys[b[i].charCodeAt() - 97];\n let left = 0; right = ary.length - 1;\n if (ary[right] < max) {\n left = right;\n } else {\n while (left < right) {\n const mid = (left + right) >> 1;\n if (ary[mid] >= max) {\n right = mid;\n } else {\n left = mid + 1;\n }\n }\n left--;\n }\n max = ary[left];\n result = Math.max(result, max - pres[i - 1]);\n }\n return result;\n}\n\n\n \t \t \t \t\t\t \t \t \t\t\t \t\t \t\t \t\t"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, m] = rna();\r\n\tlet s = rl();\r\n\tlet t = rl();\r\n\r\n\tconst lstp = Array(m);\r\n\tfor (let i = n - 1, j = m - 1; j >= 0; i--) {\r\n\t\tif (s[i] == t[j]) {\r\n\t\t\tlstp[j--] = i;\r\n\t\t}\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tfor (let i = 0, j = 0; j < m - 1; i++) {\r\n\t\tif (s[i] == t[j]) {\r\n\t\t\tans = Math.max(ans, lstp[j+1] - i);\r\n\t\t\tj++;\r\n\t\t}\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar N = nextInt();\r\n\tvar M = nextInt();\r\n\tvar s = next();\r\n\tvar t = next();\r\n\tvar max = 1;\r\n\tvar kouho = new Array(M);\r\n\tvar index = 0;\r\n\tfor(var i = 0; i < N; i++){\r\n\t\tif(s[i] == t[index]){\r\n\t\t\tkouho[index] = {\r\n\t\t\t\tL : i\r\n\t\t\t};\r\n\t\t\tindex++;\r\n\t\t\tif(index == M){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tindex--;\r\n\tfor(var i = N - 1; i >= 0; i--){\r\n\t\tif(s[i] == t[index]){\r\n\t\t\tkouho[index].R = i;\r\n\t\t\tindex--;\r\n\t\t\tif(index == -1){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t//myerr(kouho);\r\n\tfor(var i = 0; i < M - 1; i++){\r\n\t\tmax = Math.max(max, kouho[i + 1].L - kouho[i].L);\r\n\t}\r\n\tfor(var i = M - 1; i > 0; i--){\r\n\t\tmax = Math.max(max, kouho[i].R - kouho[i - 1].L);\r\n\t}\r\n\tmyout(max);\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var s = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var t = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n // console.log(s)\r\n // console.log(t)\r\n var pos1 = {}, pos2 = {}\r\n var j = 0\r\n for (let i = 0; i < m; i++) {\r\n while (t[i] !== s[j]) j++\r\n j++\r\n pos1[i] = j\r\n }\r\n j = n - 1\r\n // console.log('-----')\r\n for (let i = m-1; i >=0; i--) {\r\n while (t[i] !== s[j] && j>=0) {\r\n j--\r\n }\r\n j--\r\n pos2[i] = j\r\n }\r\n var max = 1\r\n for (let i = 0; i < m-1; i++) {\r\n max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))\r\n }\r\n\r\n // console.log(pos1)\r\n // console.log(pos2)\r\n console.log(max)\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var s = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var t = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n // console.log(s)\r\n // console.log(t)\r\n var pos1 = {}, pos2 = {}\r\n var j = 0\r\n for (let i = 0; i < m; i++) {\r\n while (t[i] !== s[j]) j++\r\n pos1[i] = j\r\n }\r\n j = n - 1\r\n // console.log('-----')\r\n for (let i = m-1; i >=0; i--) {\r\n while (t[i] !== s[j] && j>=0) {\r\n j--\r\n }\r\n pos2[i] = j\r\n }\r\n var max = 1\r\n for (let i = 0; i < m-1; i++) {\r\n max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))\r\n }\r\n\r\n // console.log(pos1)\r\n // console.log(pos2)\r\n console.log(max)\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var s = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var t = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n // console.log(s)\r\n // console.log(t)\r\n var pos1 = {}, pos2 = {}\r\n var j = 0\r\n for (let i = 0; i < m; i++) {\r\n while (t[i] !== s[j]) j++\r\n pos1[i] = j\r\n }\r\n j = n - 1\r\n // console.log('-----')\r\n for (let i = m-1; i >=0; i--) {\r\n while (t[i] !== s[j] && j>=0) {\r\n j--\r\n }\r\n pos2[i] = j\r\n }\r\n var max = 0\r\n for (let i = 0; i < m-1; i++) {\r\n max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))\r\n }\r\n\r\n // console.log(pos1)\r\n // console.log(pos2)\r\n console.log(max)\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // var n = parseInt(readline())\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var s = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n\r\n var t = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n // console.log(s)\r\n // console.log(t)\r\n var pos1 = {}, pos2 = {}\r\n var j = 0\r\n for (let i = 0; i < m; i++) {\r\n while (t[i] !== s[j]) j++\r\n pos1[t[i]] = j\r\n }\r\n j = n - 1\r\n // console.log('-----')\r\n for (let i = m-1; i >=0; i--) {\r\n while (t[i] !== s[j] && j>=0) {\r\n j--\r\n }\r\n pos2[t[i]] = j\r\n }\r\n var max = 0\r\n for (let i = 0; i < m-1; i++) {\r\n max = Math.max(max, Math.abs(pos2[t[i+1]] - pos1[t[i]]))\r\n }\r\n\r\n // console.log(pos1)\r\n // console.log(pos2)\r\n console.log(max)\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n // const n = readline();\r\n\r\n // Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n //\r\n // var map = {}\r\n // var [n, a, b, k] = readline().split(' ').map((x, i) => {\r\n // return parseInt(x)\r\n // })\r\n\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n var b = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');\r\n var letterMax = {}\r\n var letterfirst = {}\r\n\r\n var letterB = {}\r\n\r\n for (let i = 0; i < a.length; i++) {\r\n if (!letterMax[a[i]]) {\r\n letterMax[a[i]] = i\r\n letterfirst[a[i]] = i\r\n }\r\n letterMax[a[i]] = i\r\n }\r\n\r\n for (let i = 0; i < b.length; i++) {\r\n if (!letterB[b[i]]) {\r\n letterB[b[i]] = true\r\n }\r\n }\r\n\r\n var max = 0\r\n Object.keys(letterMax).map((key) => {\r\n if (letterB[key]) {\r\n max = Math.max(max, letterMax[key] - letterfirst[key])\r\n }\r\n })\r\n // console.log(letterMax)\r\n // console.log(letterfirst)\r\n console.log(max+1)\r\n\r\n}\r\n\r\n"}, {"source_code": "let text = '';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', str => {\r\n if (str === '\\r\\n' || str === '\\n') {\r\n process.stdin.emit('end');\r\n } else {\r\n text += str;\r\n }\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n const input = text.trim().replace(/\\r/g, '').split('\\n');\r\n // const total = +input[0];\r\n // for (let i = 1; i <= total; i++) {\r\n // console.log(solve(input[i]));\r\n // }\r\n console.log(solve(input[1], input[2]));\r\n process.exit();\r\n});\r\n\r\nfunction solve(a, b) {\r\n const charArys = new Array(26).fill(0).map(() => []);\r\n for (let i = 0; i < a.length; i++) {\r\n const code = a[i].charCodeAt() - 97;\r\n charArys[code].push(i);\r\n }\r\n\r\n const pres = new Array(b.length);\r\n pres[0] = charArys[b[0].charCodeAt() - 97][0];\r\n for (let i = 1; i < b.length; i++) {\r\n const ary = charArys[b[i].charCodeAt() - 97];\r\n const pre = pres[i - 1];\r\n let left = 0; right = ary.length - 1;\r\n while (left < right) {\r\n const mid = (left + right) >> 1;\r\n if (ary[mid] > pre) {\r\n right = mid;\r\n } else {\r\n left = mid + 1;\r\n }\r\n }\r\n pres[i] = ary[left];\r\n }\r\n const last = b[b.length - 1].charCodeAt() - 97;\r\n let max = charArys[last].pop();\r\n let result = max - pres[b.length - 2];\r\n for (let i = b.length - 2; i; i--) {\r\n const ary = charArys[b[i].charCodeAt() - 97];\r\n let left = 0; right = ary.length - 1;\r\n if (ary[right] < max) {\r\n left = right;\r\n } else {\r\n while (left < right) {\r\n const mid = (left + right) >> 1;\r\n if (ary[mid] > max) {\r\n right = mid;\r\n } else {\r\n left = mid + 1;\r\n }\r\n }\r\n left--;\r\n }\r\n max = ary[left];\r\n result = Math.max(result, max - pres[i - 1]);\r\n }\r\n return result;\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const dp = new Array(m);\r\n for (let i = 0, j = 0; i < n; i++, j++) {\r\n let t = i,\r\n t1 = j;\r\n while (t + 1 < n && a[t + 1] === a[i]) t++;\r\n while (t1 + 1 < m && b[t1 + 1] === b[t1]) t1++;\r\n const dif = t - i - (t1 - j);\r\n for (let k = 0; k <= t1 - j; k++) {\r\n dp[j + k] = [i + k, i + k + dif];\r\n }\r\n i = t;\r\n j = t1;\r\n }\r\n let res = 0;\r\n for (let i = 0; i < m - 1; i++) {\r\n res = Math.max(res, dp[i + 1][1] - dp[i][0]);\r\n }\r\n return res;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = await read();\r\n const b = await read();\r\n res[i] = solve(n, m, a, b);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "17fff01f943ad467ceca5dce5b962169"} {"source_code": "ns = readline().split(' ')\nn = parseInt(ns[0], 10);\n\nfl = readline().split(' ')\n\nev = 0\nodd = 0\n\nfor (i = 0; i < n; ++i)\n{\n\tif (parseInt(fl[i], 10) % 2 === 0)\n\t\t++ev;\n\telse\n\t\t++odd;\n}\n\nif (ev >= odd)\n{\n\tans = odd;\n}\nelse\n{\n\t\n\tans = ev + Math.floor((odd - ev) / 3);\n}\n\nprint(ans)", "positive_code": [{"source_code": "var nk = readline().split(' ').map(v => +v.trim());\nvar n = nk[0];\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < n; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n} else {\n ans += even;\n odd -= even;\n\n ans += Math.floor(odd / 3);\n\n print(ans);\n}\n"}, {"source_code": "var nn = readline();\nvar n = parseInt(nn, 10);\nvar a = readline().split(\" \");\nvar even = 0;\nvar odd = 0;\nfor (var i = 0; i < n; ++i) {\n var cur = parseInt(a[i], 10);\n if (cur % 2 === 0) {\n ++even;\n }\n else {\n ++odd;\n }\n}\nvar ans = 0;\nif (even >= odd) {\n ans = odd;\n}\nelse {\n ans = even + ((odd - even) / 3);\n}\nans = Math.floor(ans);\nprint(ans);"}, {"source_code": "\nvar now=readline().split(' ').map(function(v){return +v;});\nvar n=now[0];\nvar num=readline().split(' ').map(function(v){return +v;});\nvar i=0;\nvar cnto=0,cnte=0;\nwhile(i odd){\n print(odd);\n}\nelse {\n var ans = even;\n odd -= even;\n print(ans + parseInt(odd / 3));\n}"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \").map(v => +v.trim());\n\nvar x = 0;\nvar y = 0;\nfor(var i = 0; i < n; i++) {\n if (arr[i] % 2 == 0) x++; else y++;\n}\n\nvar res = 0;\nif (x > y) res = y;\nelse {\n res = x;\n y = y - x;\n res = res + Math.floor(y/3);\n}\n\nprint(res);"}, {"source_code": "const firstLine = readline();\nconst n = firstLine.split(' ')[0];\nvar arr = readline().split(\" \").map(v => +v.trim());\n\nvar ctn = 0;\nvar ctch = 0;\nfor(var i = 0; i < n; i++){\n if (arr[i] % 2 === 0)\n \tctch++;\n else ctn++;\n}\n// print(ctch);\n// print(ctn);\nvar k = 0;\nif (ctch <= ctn)\nk = ctch;\nelse k = ctn;\nctch -= k;\nctn -= k;\nvar min = 0;\nif (ctn % 3 >= parseInt(ctch / 2))\nmin = parseInt(ctch / 2);\nelse min = ctn % 3;\nvar ans1 = parseInt(ctn / 3) + min;\nif (parseInt(ctch / 2) > ctn)\nmin = ctn;\nelse min = parseInt(ctch / 2);\nvar ans2 = min;\nif (ctn - ans2 > 0)\nans2 += parseInt((ctn - ans2) / 3);\n\nif (ans1 > ans2)\nk += ans1;\nelse k += ans2;\nprint(k);"}, {"source_code": "var n = readline().split(\" \").map(v => +v.trim())[0];\nvar a = readline().split(\" \").map(v => +v.trim());\n\nvar odd = 0;\nvar even = 0;\n\nfor (var i = 0; i < n; i++)\n{\n\tif(a[i] % 2 === 0)\n\t\teven += 1;\n\telse\n\t\todd += 1;\n}\n\nif (even > odd)\n\tprint(odd);\nelse\n\tprint(even + parseInt((odd - even)/3));"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \");\nvar ans1=0;\nvar ans2=0;\n\nfor(var i = 0; i < n; i++){\n\tif(input[i] %2 ==0)\n\t\tans1++;\n\telse ans2++;\n}\nvar hlp=(ans2-ans1)-(ans2-ans1)%3;\nhlp=hlp/3;\nif(ans1>ans2)\nprint(ans2);\nelse print(ans1+hlp);"}, {"source_code": "\n var n = readline();\n var b = readline().split(' ');\n var o = 0, e = 0;\n for (var i = 0; i < n; i ++){\n if (b[i] % 2 == 1) o ++;\n else e ++;\n }\n if (o < e)\n print(o);\n else{\n var ans = e;\n o -= e;\n ans += Math.trunc(o/3);\n print(ans);\n \n }\n"}, {"source_code": "var n = readline().split(\" \").map(v => +v.trim())[0];\nvar arr = readline().split(\" \").map(v => +v.trim());\nvar cnt0 = 0;\nvar cnt1 = 0;\nfor (var i = 0; i < n; i++){\n var el = arr[i]\n\tif (el % 2 === 0){\n\t\tcnt0++;\n\t}\n\telse{\n\t\tcnt1++;\n\t}\n}\n//print(arr)\n\nif (cnt0 > cnt1){\n\tprint(cnt1);\t\n}\nelse{\n //print(cnt1 - cnt0)\n //print(parseInt((cnt1 - cnt0) / 3))\n\tprint(cnt0 + parseInt((cnt1 - cnt0) / 3))\n}"}, {"source_code": "var n = readline();\nvar chet = 0 , nechet = 0 , maxx=0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0; i < n; i++){\n if (arr[i]%2 === 0){\n chet++; \n }else{\n nechet++;\n }\n}\nif (chet>=nechet){\n print(nechet);\n}else{\n if (nechet===1){\n print(0);\n }else{\n while (chetmaxx)maxx=chet;\n chet++;\n nechet-=2;\n }\n if (nechet>maxx)maxx=nechet;\n print(maxx);\n }\n}"}, {"source_code": "var L = readline().split(' ');\nvar n = parseInt(L[0]);\nvar arr = readline().split(' ');\nvar ans = 0, k = 0;\nfor(var i = 0;i < n;i++){\n if(parseInt(arr[i])%2 === 1) ans++;\n else k++;\n}\nif(k > ans) print(ans);\nelse{\n var d = k;\n d += ((ans-k) - ((ans-k)%3))/3;\n print(d);\n}"}, {"source_code": "var arr = readline().split(\" \").map(v => +v.trim());\nvar n = arr[0];\nvar a = readline().split(\" \").map(v => +v.trim());\nkch=0\nknch=0\nfor (var i=0;i parseInt(x));\nvar odd = 0, evn = 0;\nfor (var x of a) {\n if (x % 2 == 1)\n odd++;\n else\n evn++;\n}\nvar ans = 0;\nwhile (odd > 0 && evn > 0) ans++, odd--, evn--;\nwhile (odd > 2) ans++, odd -= 3;\nprint(ans);"}, {"source_code": "n=readline();\n//print(n);\nx=readline().split(' ');\nimp=0;\npai=0;\nfor (i = 0; i < n; i++) { \n imp+=(x[i]%2)?1:0;\n pai+=(1-x[i]%2)?1:0;\n}\nprint(Math.min(imp,pai)+Math.floor(Math.max(imp-pai,0)/3));"}, {"source_code": "var n = Number(readline());\nvar bouquets = readline().split(' ').map(function(x) { return Number(x)})\n\nvar odd = 0, even = 0;\nbouquets.forEach(flour => {\n if(flour % 2 == 1) odd++;\n else even++;\n});\n\nvar ans = Math.min(odd, even);\nif(odd > ans) {\n ans += Math.floor((odd - ans) / 3);\n}\nprint(ans);"}, {"source_code": "var n = parseInt(readline());\nvar v = readline().split(' ').map(function (x) { return parseInt(x); });\n\nvar p = 0\nvar np = 0\n\nfor(var i = 0; i < n; ++i) {\n if(v[i] % 2 === 0) {\n ++p\n } else {\n ++np\n }\n}\n\nvar ans = p\nif(ans > np) {\n ans = np\n}\n\nnp = np - ans;\nans = ans + Math.floor(np / 3)\nprint(ans)"}, {"source_code": "var a = [];\nvar n = readline();\na = readline().split(\" \");\nvar num0s = 0;\nvar num1s = 0;\nfor (var i = 0; i < n; i++) {\n if (a[i] % 2 === 0) {\n num0s++;\n }\n else {\n num1s++;\n }\n}\n\nvar ans = Math.min(num0s,num1s);\nnum1s -= ans;\nans += Math.floor(num1s/3);\nprint(ans);"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ');\n\nvar odd = 0;\nvar even = 0;\nfor(var i = 0; i < a; i++) {\n\tif(Number(b[i])%2===0)\n\t{\n\t\teven++;\n\t}else odd ++;\n\t\n}\nvar ans = 0;\nwhile(odd>0)\n{\n\tif(even>0)\n\t{\n\t\teven--;\n\t\todd--;\n\t\tans ++;\n\t\tcontinue;\n\t}\n\telse{\n\t\tif(odd == 1)\n\t\t{\n\t\t\t//ans--;\n\t\t\tbreak;\n\t\t}\n\t\tif(odd == 2)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\todd-=3;\n\t\tans++;\n\t}\n\t\n}\nif(ans<0)ans = 0;\nprint(ans)\n"}, {"source_code": "var n = readline();\nvar odd = 0 ,even = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0 ; i < n ; i++){\n\tif(arr[i] & 1)\todd++;\n\telse even++;\n}\n\nif(odd > even){\n odd -= even;\n var ans = even + Math.floor (odd / 3);\n\tprint(ans);\n}else\tprint(odd);\n"}, {"source_code": "n=readline().split(' ').map(Number);\na=readline().split(' ').map(Number);\nk=0;\nfor(i=0;iz){\n\tprint(z);\n}else{\n\tprint(k+Math.floor((z-k)/3));\n}\n"}, {"source_code": "// your code goes here\nvar n = parseInt(readline());\nvar arr = readline().split(' ');\nvar odd =0;\nvar even=0;\nfor (var i =0;i= odd){\n\tans = odd;\n}\nelse {\n\tans = even ;\n\todd -=even;\n\tvar x = odd %3;\n\tans += Math.floor(odd/3);\n\n}\nprint(ans)\n"}, {"source_code": "n = readline().split(' ').map(Number);\nstr = readline().split(' ').map(Number);\n\nvar i=0,ans=0;\nwhile(in-ans){\n\tvar tot=ans-(n-ans);\n\ttot-=tot%3;\n\tans=(n-ans)+tot/3;\n}\nprint(ans)"}, {"source_code": "var arr = readline().split(\" \").map(v => +v.trim());\n\narr1 = readline().split(\" \").map(v => +v.trim());\nvar c_ch = 0, c_n = 0;\nfor (var i = 0; i < arr1.length; ++i) {\n if (arr1[i] % 2 === 0) {\n c_ch++;\n } else {\n c_n++;\n }\n}\nif (c_ch < c_n) {\n print(c_ch + (c_n - c_ch - ((c_n - c_ch) % 3)) / 3);\n} else {\n print(c_n);\n}\n"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \");\n\nvar o = 0;\nvar e = 0;\nfor(var i = 0 ; i < n ; i++) {\n if(arr[i] % 2 === 0) {\n e++;\n }\n else {\n o++;\n }\n}\n\nvar ans = 0;\n if(o <= e) {\n ans = o;\n }\n else {\n ans = e;\n ans = ans + Math.floor((o - e) / 3);\n }\n \n print(ans);"}, {"source_code": "var a = readline().split(' ');\nvar b = readline().split(' ');\n\nvar odd = 0;\nvar even = 0;\nfor(var i = 0; i < a; i++) {\n\tif(Number(b[i])%2===0)\n\t{\n\t\teven++;\n\t}else odd ++;\n\t\n}\nvar ans = 0;\nwhile(odd>0)\n{\n\tif(even>0)\n\t{\n\t\teven--;\n\t\todd--;\n\t\tans ++;\n\t\tcontinue;\n\t}\n\telse{\n\t\tif(odd == 1)\n\t\t{\n\t\t\t//ans--;\n\t\t\tbreak;\n\t\t}\n\t\tif(odd == 2)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\todd-=3;\n\t\tans++;\n\t}\n\t\n}\nif(ans<0)ans = 0;\nprint(ans)"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar a = 0;\n\nfor (var i = 1; i <= n; i++){\n var x = arr[i - 1];\n if(x % 2 == 1)a += 1;\n}\nvar b = n - a;\n\nif(a <= b)print(a);\nelse {\n\tvar ans = b;\n\tx = (a - b) - (a - b)%3;\n\tans += x/3;\n\tprint(ans);\n}"}, {"source_code": "const n = readline();\nconst input = readline();\nconst arr = input.split(' ');\n\nvar odd = 0;\nvar even = 0;\n\nfor(var i = 0; i < n; i++) {\n if(arr[i]%2) {\n odd++;\n } else {\n even++;\n }\n}\nvar ans = 0;\nif(odd >= even) {\n odd-= even;\n ans = even;\n ans+= ((odd-odd%3)/3);\n} else {\n ans = odd;\n}\nprint(ans)"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \");\n\nvar i = 0;\nvar odd = 0;\nfor (; i < n; ++i)\n if (parseInt(a[i]) % 2 != 0)\n ++odd;\n\nvar even = n - odd;\nif (even >= odd)\n print(odd);\nelse\n print(even + Math.floor((odd - even) / 3)); // lol, js divides it as float"}], "negative_code": [{"source_code": "function main() {\n // write your code here.\n // call functions `nextString`, `nextFloat` and `nextInt` \n // to read the next token of input (ignoring whitespace)\n // Alternatively, you can create your own input parser functions\n // use console.log() to write to stdout\n \n var n = readline();\n var b = readline().split(' ');\n var o = 0, e = 0;\n for (var i = 0; i < n; i ++){\n if (b[i] % 2 == 1) o ++;\n else e ++;\n }\n if (o < e)\n print(o);\n else\n print(e);\n}\n\n// default parsers for JS.\nfunction nextInt() {\n return parseInt(nextString());\n}\n\nfunction nextFloat() {\n return parseFloat(nextString());\n}\n\nfunction nextString() {\n var next_string = \"\";\n clearWhitespaces();\n while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {\n next_string += input_stdin[input_cursor];\n input_cursor += 1;\n }\n return next_string;\n}\n\nfunction nextChar() {\n clearWhitespaces();\n if (input_cursor < input_stdin.length) {\n return input_stdin[input_cursor++];\n } else {\n return '\\0';\n }\n}\n\n//process.stdin.resume();\n//process.stdin.setEncoding('ascii');\n\nvar input_stdin = \"\";\nvar input_cursor = 0;\n//process.stdin.on('data', function (data) { input_stdin += data; });\n//process.stdin.on('end', function () { main(); });\n\nfunction isWhitespace(character) {\n return ' \\t\\n\\r\\v'.indexOf(character) > -1;\n}\n\nfunction clearWhitespaces() {\n while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {\n // ignore the next whitespace character\n input_cursor += 1;\n } \n}\n\nmain();"}, {"source_code": "readline()\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n} else {\n ans += even;\n odd -= even;\n\n ans += Math.floor(odd / 2);\n\n print(ans);\n}\n"}, {"source_code": "\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n process.exit(0);\n} else {\n ans += even;\n odd -= even;\n}\n\nans += Math.floor(even / 2);\n\nprint('' + ans);\n"}, {"source_code": "\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n} else {\n ans += even;\n odd -= even;\n\n\n ans += Math.floor(even / 2);\n\n print(ans);\n\n}\n"}, {"source_code": "var nk = readline().split(' ').map(v => +v.trim());\nvar n = nk[0];\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < n; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n} else {\n ans += even;\n odd -= even;\n\n ans += Math.floor(odd / 2);\n\n print(ans);\n}\n"}, {"source_code": "readline()\nvar arr = readline().split(' ').map(v => +v.trim());\nvar even = 0, odd = 0;\n\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n}\n\nvar ans = 0;\nif (even > odd) {\n print(odd);\n} else {\n ans += even;\n odd -= even;\n\n ans += Math.floor(even / 2);\n\n print(ans);\n}\n"}, {"source_code": "const firstLine = readline();\nconst n = firstLine.split(' ')[0];\nvar arr = readline().split(\" \").map(v => +v.trim());\n\nvar ctn = 0;\nvar ctch = 0;\nfor(var i = 0; i < n; i++){\n if (arr[i] % 2 === 0)\n \tctch++;\n else ctn++;\n}\n// print(ctch);\n// print(ctn);\nvar k = 0;\nif (ctch <= ctn)\nk = ctch;\nelse k = ctn;\nctch -= k;\nctn -= k;\nvar min = 0;\nif (ctn % 3 >= ctch / 2)\nmin = ctch / 2;\nelse min = ctn % 3;\nvar ans1 = ctn / 3 + min;\nif (ctch / 2 > ctn)\nmin = ctn;\nelse min = ctch / 2;\nvar ans2 = min;\nif (ctn - ans2 > 0)\nans2 += (ctn - ans2) / 3;\n\nif (ans1 > ans2)\nk += ans1;\nelse k += ans2;\nprint(k);"}, {"source_code": "ns = readline().split(' ')\nn = parseInt(ns[0], 10);\n\nfl = readline().split(' ')\n\nev = 0\nodd = 0\n\nfor (i = 0; i < n; ++i)\n{\n\tif (parseInt(fl[i], 10) % 2 === 0)\n\t\t++ev;\n\telse\n\t\t++odd;\n}\n\nif (ev > odd)\n\tans = odd;\nelse\n\tans = ev;\n\nprint(ans)"}, {"source_code": "var n = readline().split(\" \").map(v => +v.trim())[0];\nvar a = readline().split(\" \").map(v => +v.trim());\n\nvar odd = 0;\nvar even = 0;\n\nfor (var i = 0; i < n; i++)\n{\n\tif(a[i] % 2 === 0)\n\t\teven += 1;\n\telse\n\t\todd += 1;\n}\n\nif (odd > even)\n\tprint(even);\nelse\n\tprint(odd);"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \");\nvar ans1=0;\nvar ans2=0;\n\nfor(var i = 0; i < n; i++){\n\tif(input[i] %2 ==0)\n\t\tans1++;\n\telse ans2++;\n}\nvar hlp=(ans1-ans2)-(ans1-ans2)%3;\nhlp=hlp/3;\nif(ans1>ans2)\nprint(ans2+hlp);\nelse print(ans1);"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \");\nvar ans1=0;\nvar ans2=0;\n\nfor(var i = 0; i < n; i++){\n\tif(input[i] %2 ==0)\n\t\tans1++;\n\telse ans2++;\n}\nif(ans1>ans2)\nprint(ans2+(ans1-ans2)/3);\nelse print(ans1);"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \");\nvar ans1=0;\nvar ans2=0;\n\nfor(var i = 0; i < n; i++){\n\tif(input[i] %2 ==0)\n\t\tans1++;\n\telse ans2++;\n}\nif(ans1>ans2)\nprint(ans2);\nelse print(ans1);"}, {"source_code": "var n = readline();\nvar input = readline().split(\" \");\nvar ans1=0;\nvar ans2=0;\n\nfor(var i = 0; i < n; i++){\n\tif(input[i] %2 ==0)\n\t\tans1++;\n\telse ans2++;\n}\nif(ans1>ans2)\nprint(ans2+((ans1-ans2)/3));\nelse print(ans1);"}, {"source_code": "var n = readline();\nvar chet = 0 , nechet = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0; i < n; i++){\n if (arr[i]%2 === 0){\n chet++; \n }else{\n nechet++;\n }\n}\nif (chet>nechet){\n print(nechet);\n}else{\n if (nechet===1){\n print(0);\n }else{\n while (chet +v.trim());\nfor(var i = 0; i < n; i++){\n if (arr[i]%2 === 0){\n chet++; \n }else{\n nechet++;\n }\n}\nif (chet>=nechet){\n print(nechet);\n}else{\n if (nechet===1){\n print(0);\n }else{\n while (chet +v.trim());\nfor(var i = 0; i < n; i++){\n if (arr[i]%2 === 0){\n chet++; \n }else{\n nechet++;\n }\n}\nif (chet>nechet){\n print(nechet);\n}else{\n while (chet +v.trim());\nvar n = arr[0];\nvar a = readline().split(\" \").map(v => +v.trim());\nkch=0\nknch=0\nfor (var i=0;i0)\n{\n\tif(even>0)\n\t{\n\t\teven--;\n\t\todd--;\n\t\tans ++;\n\t\tcontinue;\n\t}\n\telse{\n\t\tif(odd == 1)\n\t\t{\n\t\t\tans--;\n\t\t\tbreak;\n\t\t}\n\t\tif(odd == 2)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\todd-=3;\n\t\tans++;\n\t}\n\t\n}\nif(ans<0)ans = 0;\nprint(ans)\n"}, {"source_code": "n = readline().split(' ').map(Number);\nstr = readline().split(' ').map(Number);\n\nvar i=0,ans=0;\nwhile(in-ans){\n\tvar tot=ans-(n-ans);\n\ttot-=tot%3;\n\tans+=tot/3;\n}\nprint(ans)"}, {"source_code": "n = readline().split(' ').map(Number);\nstr = readline().split(' ').map(Number);\n\nvar i=0,ans=0;\nwhile(i {\n if(flour % 2 == 1) odd++;\n else even++;\n});\n\nprint(Math.min(odd, even));"}, {"source_code": "var n = parseInt(readline());\nvar v = readline().split(' ').map(function (x) { return parseInt(x); });\n\nvar p = 0\nvar np = 0\n\nfor(var i = 0; i < n; ++i) {\n if(v[i] % 2 === 0) {\n ++p\n } else {\n ++np\n }\n}\n\nvar ans = p\nif(ans > np) {\n ans = np\n}\n\nprint(ans)"}, {"source_code": "var n = readline();\nvar odd = 0 ,even = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0 ; i < n ; i++){\n // print(arr[i] + \" \");\n\tif(arr[i] & 1)\todd++;\n\telse even++;\n}\n//print(n + \"\\n\");\nif(odd > even){\n var ans = even + (odd - even) / 2;\n\tprint(ans);\n}else\tprint(odd);\n"}, {"source_code": "var n = readline();\nvar odd = 0 ,even = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0 ; i < n ; i++){\n\tif(arr[i] & 1)\todd++;\n\telse even++;\n}\n\nif(odd > even){\n odd -= even;\n var ans = even + odd / 3;\n\tprint(ans);\n}else\tprint(odd);\n"}, {"source_code": "var n = readline();\nvar odd = 0 ,even = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0 ; i < n ; i++){\n\tif(arr[i] & 1)\todd++;\n\telse even++;\n}\nif(odd > even){\n\todd -= even;\n\tvar ans = even + odd / 2;\n\tprint(ans);\n}else\tprint(odd);\n"}, {"source_code": "var n = readline();\nvar odd = 0 ,even = 0;\nvar arr = readline().split(\" \").map(v => +v.trim());\nfor(var i = 0 ; i < n ; i++){\n // print(arr[i] + \" \");\n\tif(arr[i] & 1)\todd++;\n\telse even++;\n}\n//print(n + \"\\n\");\nif(odd > even){\n var ans = even + (odd - even) / 3;\n\tprint(ans);\n}else\tprint(odd);\n"}, {"source_code": "// your code goes here\nvar n = parseInt(readline());\nvar arr = readline().split(' ');\nvar odd =0;\nvar even=0;\nfor (var i =0;i= odd){\n\tans = odd;\n}\nelse {\n\tans = even ;\n\todd -=even;\n\tvar x = odd %3;\n\tans += (odd/3);\n\tif (x===1 && ans !==0)ans --;\n\t\n}\nprint(ans)\n"}, {"source_code": "// your code goes here\nvar n = parseInt(readline());\nvar arr = readline().split(' ');\nvar odd =0;\nvar even=0;\nfor (var i =0;i= odd){\n\tans = odd;\n}\nelse {\n\tans = even ;\n\todd -=even;\n\tvar x = odd %3;\n\tans += Math.floor(odd/3);\n\tif (x==1 && ans !==0)ans --;\n\t\n}\nprint(ans)\n"}, {"source_code": "// your code goes here\nvar n = parseInt(readline());\nvar arr = readline().split(' ');\nvar odd =0;\nvar even=0;\nfor (var i =0;i= odd){\n\tans = odd;\n}\nelse {\n\tans = even ;\n\todd -=even;\n\tvar x = odd %3;\n\tans += Math.floor(odd/3);\n\tif (x===1 && ans !==0)ans --;\n\t\n}\nprint(ans)\n"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \");\n\nvar o = 0;\nvar e = 0;\nfor(var i = 0 ; i < n ; i++) {\n if(arr[i] % 2 === 0) {\n e++;\n }\n else {\n o++;\n }\n}\n\nvar ans = 0;\n if(o <= e) {\n ans = o;\n }\n else {\n ans = e;\n anss = ans + (o - e) / 3;\n }\n \n print(ans);"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar a = 0;\n\nfor (var i = 1; i <= n; i++){\n var x = arr[i - 1];\n if(x % 2 == 1)a += 1;\n}\nvar b = n - a;\n\nif(a <= b)print(a);\nelse {\n\tvar ans = b;\n\tans += (a - b)/3;\n\tprint(ans);\n}"}, {"source_code": "var n = readline().split(' ').map(Number);\nvar arr = readline().split(' ').map(Number);\nvar a = 0;\n\nfor (var i = 1; i <= n; i++){\n var x = arr[i - 1];\n if(x % 2 == 1)a += 1;\n}\nvar b = n - a;\n\nif(a <= b)print(a);\nelse {\n\tvar ans = b;\n\tans += (a - b) - (a - b)%3;\n\tprint(ans);\n}"}, {"source_code": "var n = parseInt(readline());\nvar a = readline().split(\" \");\n\nvar i = 0;\nvar odd = 0;\nfor (; i < n; ++i)\n if (parseInt(a[i]) % 2 != 0)\n ++odd;\n\nvar even = n - odd;\nif (even >= odd)\n print(odd);\nelse\n print(even + (odd - even) / 3);"}], "src_uid": "61e6fd68d7568c599204130b102ea389"} {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift()(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift())\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nfunction extend(mas) {\r\n let n = mas.length\r\n mas.unshift(new Array(n++).fill('.'))\r\n for (let i = 0; i < n; ++i) {\r\n mas[i].push('.')\r\n }\r\n}\r\n\r\nasync function main() {\r\n let n = +await nextString()\r\n if (n === 2) {\r\n console.log('-1')\r\n return\r\n }\r\n let m = n % 2 === 0 ? 2 : 1\r\n while (((m + 2) ** 2) <= n && ((n - ((m + 2) ** 2)) % 2) === 0) {\r\n m += 2\r\n }\r\n let mas = new Array(m)\r\n .fill(42)\r\n .map(() => new Array(m).fill('o'))\r\n let f = m\r\n n -= m * m;\r\n while (n > 0) {\r\n extend(mas)\r\n ++m\r\n for (let i = 0; i < f && n > 0; ++i, n -= 2) {\r\n mas[0][i] = mas[m - 1 - i][m - 1] = 'o'\r\n }\r\n }\r\n let str = mas.map(row => row.join('')).join('\\n')\r\n console.log(m + '\\n' + str)\r\n}\r\n \r\nmain()\r\n", "positive_code": [{"source_code": "let _DEBUG;\r\n\r\nconst fs = require('fs');\r\nconst { assert } = require('console');\r\nconst print = console.log;\r\nconst debug = (x) => {\r\n if (!_DEBUG) return;\r\n let vn = Object.keys(x)[0];\r\n console.error(`${vn}: ${x[vn]}`);\r\n};\r\nconst debugf = !_DEBUG ? () => {} : console.error;\r\n\r\nconst MAXN = 100;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nlet n = +input[0];\r\n\r\nif (n == 2) {\r\n print(-1);\r\n} else {\r\n let m = n % 2;\r\n while ((m + 2) * (m + 2) <= n) {\r\n m += 2;\r\n }\r\n\r\n let rem = n - m * m;\r\n assert(rem % 2 == 0);\r\n let hrem = rem / 2;\r\n\r\n let h = Math.ceil(hrem / m);\r\n let s = m + h;\r\n\r\n debug({ n });\r\n debug({ m });\r\n\r\n print(s);\r\n let r = [];\r\n for (let i = 0; i < s; i++) {\r\n r.push('.'.repeat(s).split(''));\r\n }\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j <= i; j++) {\r\n r[i][j] = r[j][i] = 'o';\r\n }\r\n }\r\n for (let i = m; i < m + h; i++) {\r\n for (let j = 0; j < m; j++) {\r\n let t = (hrem - 1) % m + 1;\r\n if (i < m + h - 1 || j < t) {\r\n r[i][j] = r[j][i] = ['o'];\r\n }\r\n }\r\n }\r\n\r\n print(\r\n r\r\n .reverse()\r\n .map((x) => x.join(''))\r\n .join('\\n')\r\n );\r\n}\r\n"}, {"source_code": "n = +readline()\r\n\r\nif (n%2===0) {\r\n bd = n/2\r\n} else { \r\n bd = (n+1)/2\r\n}\r\n\r\nfunction solve(){\r\n for (var len = 1;len<=bd;len++)\r\n {\r\n for (var sq = 1;sq<=len;sq++)\r\n {\r\n var now = len*2-1 + (sq-1)*(sq-1)\r\n var add = (sq-1) * (len-sq) * 2\r\n if (now <= n && n <= now+add && now%2 == n%2) {\r\n print(len)\r\n S = '.'.repeat(len)\r\n ans = []\r\n for (var z=0;z=0;i--)\r\n {\r\n print(ans[i])\r\n }\r\n return\r\n }\r\n }\r\n } \r\n}\r\n\r\nif (n==2)\r\n print(-1)\r\nelse\r\n solve()"}], "negative_code": [{"source_code": "let _DEBUG;\r\n\r\nconst fs = require('fs');\r\nconst { assert } = require('console');\r\nconst print = console.log;\r\nconst debug = (x) => {\r\n if (!_DEBUG) return;\r\n let vn = Object.keys(x)[0];\r\n console.error(`${vn}: ${x[vn]}`);\r\n};\r\nconst debugf = !_DEBUG ? () => {} : console.error;\r\n\r\nconst MAXN = 100;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nlet n = +input[0];\r\n\r\nif (n == 2) {\r\n print(-1);\r\n} else {\r\n let m = n % 2;\r\n while ((m + 2) * (m + 2) <= n) {\r\n m += 2;\r\n }\r\n\r\n let rem = n - m * m;\r\n assert(rem % 2 == 0);\r\n let hrem = rem / 2;\r\n\r\n let h = Math.ceil(hrem / m);\r\n let s = m + h;\r\n\r\n debug({ n });\r\n debug({ m });\r\n\r\n print(s);\r\n let r = [];\r\n for (let i = 0; i < s; i++) {\r\n r.push('.'.repeat(s).split(''));\r\n }\r\n for (let i = 0; i < m; i++) {\r\n for (let j = 0; j <= i; j++) {\r\n r[i][j] = r[j][i] = 'o';\r\n }\r\n }\r\n for (let i = m; i < m + h; i++) {\r\n for (let j = 0; j < m; j++) {\r\n let t = (hrem - 1) % m + 1;\r\n if (i < m || j < t) {\r\n r[i][j] = r[j][i] = ['o'];\r\n }\r\n }\r\n }\r\n\r\n print(\r\n r\r\n .reverse()\r\n .map((x) => x.join(''))\r\n .join('\\n')\r\n );\r\n}\r\n"}, {"source_code": "let _DEBUG = 1;\r\n\r\nconst fs = require('fs');\r\nconst print = console.log;\r\nconst debug = (x) => {\r\n if (!_DEBUG) return;\r\n let vn = Object.keys(x)[0];\r\n console.error(`${vn}: ${x[vn]}`);\r\n};\r\nconst debugf = !_DEBUG ? () => {} : console.error;\r\n\r\nlet input = fs.readFileSync(0).toString();\r\ninput = input.split(/\\r?\\n/g);\r\n\r\nlet n = +input[0];\r\n\r\nlet s = 1;\r\nwhile (s * s < n) {\r\n s++;\r\n}\r\n\r\nlet r = [];\r\nfor (let i = 0; i < s; i++) {\r\n r.push('.'.repeat(s).split(''));\r\n}\r\n\r\nr[s - 1][0] = ['o'];\r\nlet t = n - (s - 1) * (s - 1);\r\n\r\nfor (let i = 0; i < s - 1; i++) {\r\n for (let j = 0; j < s - 1; j++) {\r\n r[s - 1 - i][j] = ['o'];\r\n }\r\n}\r\n\r\nfor (let i = 0; i < s && t >= 2; i++) {\r\n r[0][i] = ['o'];\r\n r[s - 1 - i][s - 1] = ['o'];\r\n t -= 2;\r\n}\r\n\r\nif (n == s * s) {\r\n r[0][s - 1] = ['o'];\r\n t = 0;\r\n}\r\n\r\nif (t == 0) {\r\n print(s);\r\n print(r.map(x => x.join('')).join('\\n'));\r\n} else {\r\n print(-1);\r\n}\r\n"}], "src_uid": "a2190cc2c9a848c5b8d998d0d5093f53"} {"source_code": "var s = readline();\nvar n = s.length;\n\nvar firstAB = -1, firstBA = -1, lastAB = -1, lastBA = -1;\n\nfor(var i=0;i1 || lastBA-firstAB>1) {\n print(\"YES\");\n}\nelse {\n print(\"NO\");\n}\n", "positive_code": [{"source_code": "var str = readline();\nvar reg1 = /BA.*?AB/;\nvar reg2 = /AB.*?BA/;\n//str = str.replace(/BA/gi, \"\");\nreg1.test(str)||reg2.test(str)?print(\"YES\"):print(\"NO\");\n"}, {"source_code": "var str = readline();\nvar r1 = /AB/g;\nvar r2 = /BA/g;\nvar result1 = [],result2 = [];\nvar match;\n\nwhile (match = r1.exec(str))\n result1.push(match.index);\n\nwhile (match = r2.exec(str))\n result2.push(match.index);\n\n\nvar flag = 0;\nfor(var i = 0; i < result1.length; i++)\n\tfor(var j = 0; j < result2.length; j++)\n\t\tif(Math.abs(result1[i]- result2[j]) >= 2){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t\t\nprint((flag)?\"YES\":\"NO\");"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (line) => {\n if (line !== null) {\n process.stdout.write(check2(line.toString()) ? 'YES' : 'NO');\n }\n})\n\nconst check2 = (s) => {\n let ab = -1;\n let ba = -1;\n\n for (let i = 0; i < s.length; i++) {\n const w = s[i] + s[i + 1];\n if (w === 'AB') {\n if (ab === -1) {\n ab = i;\n }\n\n if (ba !== -1 && i !== ba + 1 && i !== ba - 1) {\n return true;\n }\n }\n else if (w === 'BA') {\n if (ba === -1) {\n ba = i;\n }\n\n if (ab !== -1 && i !== ab + 1 && i !== ab - 1) {\n return true;\n }\n }\n }\n\n return false;\n};\n"}, {"source_code": "function main() {\n var line = readline();\n var baFound = 0;\n var abFound = 0;\n var abaFound = 0;\n for(var i=0;i= 2 || (abaFound >= 1 && (abFound >=1 || baFound >=1) ) || (abFound >= 1 && baFound >=1)){\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}\n\n\nmain()"}, {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/550/A\n\n var linea = readline();\n \n if(/AB.*?BA/.test(linea) || /BA.*?AB/.test(linea)){\n write(\"YES\");\n }else{\n write(\"NO\");\n }\n})();"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n const lastIndexOfAB = line.lastIndexOf('AB')\n const lastIndexOfBA = line.lastIndexOf('BA')\n const indexOfAB = line.indexOf('AB')\n const indexOfBA = line.indexOf('BA')\n if (lastIndexOfAB >= 0 && indexOfBA >= 0) {\n if (lastIndexOfAB - indexOfBA >= 2) {\n console.log('YES')\n return\n }\n }\n if (lastIndexOfBA >= 0 && indexOfAB >= 0) {\n if (lastIndexOfBA - indexOfAB >= 2) {\n console.log('YES')\n return\n }\n }\n console.log('NO')\n})\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n if(ab2 == -1 && s[l-1-i] == 'B' && s[l-2-i] == 'A')\n {\n ab2 = l-1-i;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n if(ba2 == -1 && s[i] == 'B' && s[i+1] == 'A') \n {\n ba2 = i;\n }\n}\n\n// if(s=='ABAXXXAB')\n// {\n// print('ab1=',ab1,'; ab2=',ab2,'; ba1=',ba1,'; ba2=',ba2);\n//}\n\nvar flag = -1;\n\n\nif(ab1 > -1 && ( ((ab1 != ba1 && ab1 != ba1+2)&&(ba1 >-1)) || ((ab1 != ba2 && ab1 != ba2+2)&(ba2>-1)) ) ) flag = 1;\n\n\nif(ab2 > -1 && ( ((ab2 != ba1 && ab2 != ba1+2)&&(ba1 >-1)) || ((ab2 != ba2 && ab2 != ba2+2)&(ba2>-1)) ) ) flag = 1;\n\n\nif(flag == 1) print('YES');\nelse print('NO');\n\n\n"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n if (s.length < 4) { console.log('NO'); return; }\n\n const AB = [];\n const BA = [];\n\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { \n AB.push(i-1);\n }\n else if (s[i-2] === 'B' && s[i-1] === 'A') {\n BA.push(i-1);\n }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n AB.push(i);\n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n BA.push(i);\n }\n }\n\n AB.forEach(ab => {\n BA.forEach(ba => {\n if (Math.abs(ab - ba) >= 2) {\n console.log('YES'); process.exit(0);\n }\n }); \n });\n\n console.log(\"NO\");\n});"}, {"source_code": "var input = readline().split('');\n\nvar findAB = Infinity;\nvar findBA = Infinity;\nvar ABFlag = false;\nvar BAFlag = false;\nfor (var i = 0; i < input.length - 1; i++) {\n if (input[i] == 'A' && input[i+1] == 'B') {\n findAB = Math.min(findAB, i);\n if (findBA == Infinity) ABFlag = true;\n else if (Math.abs(i - findBA) > 1) { ABFlag = true; BAFlag = true; }\n }\n if (input[i] == 'B' && input[i+1] == 'A') {\n findBA = Math.min(findBA, i);\n if (findAB == Infinity) BAFlag = true;\n else if (Math.abs(i - findAB) > 1) { ABFlag = true; BAFlag = true; }\n }\n}\nwrite((BAFlag && ABFlag) ? 'YES' : 'NO')"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n this.CLEAR_ARRAY_PER_CASE = false;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , temp , len ;\n res = 0 ;\n len = this.s.length ;\n this.arr = [] ;\n this.brr = [] ;\n for( i = 0 ; i < len - 1 ; i++ ) {\n \tif( this.s.charAt( i ) == 'A'.charAt( 0 ) && this.s.charAt( i + 1 ) == 'B'.charAt( 0 ) ) {\n \t\tthis.arr.push( i ) ;\n \t}\n \tif( this.s.charAt( i ) == 'B'.charAt( 0 ) && this.s.charAt( i + 1 ) == 'A'.charAt( 0 ) ) {\n \t\tthis.brr.push( i ) ;\n \t}\n }\n for( i = 0 ; i < this.arr.length ; i++ ) {\n \tfor( j = 0 ; j < this.brr.length ; j++ ) {\n \t\tif( Math.abs( this.arr[ i ] - this.brr[ j ] ) > 1 ) {\n \t\t\tres = 1 ;\n \t\t\tbreak ;\n \t\t}\n \t}\n \tif( res == 1 ) {\n \t\tbreak ;\n \t}\n }\n if( res == 0 ) {\n \tprint( 'NO' );\n }\n else {\n \tprint( 'YES' );\n }\n };\n\n this.init = function() {\n this.lim1 = 100010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.s = irObj.nextString();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.adjList.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n };\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adjList = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adjList.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init();\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n };\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n };\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n };\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n res = \"\";\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var n = readline();\nvar len = n.length;\ns1 = n;\ns2 = n;\ns1 = s1.replace(\"AB\", \".\");\ns1 = s1.replace(\"BA\", \".\");\ns1 = s1.replace(\".\", \"\");\ns1 = s1.replace(\".\", \"\");\ns2 = s2.replace(\"BA\", \".\");\ns2 = s2.replace(\"AB\", \".\"); \ns2 = s2.replace(\".\", \"\");\ns2 = s2.replace(\".\", \"\");\nif(s1.length <= len - 4 || s2.length <= len - 4){\n print(\"YES\");\n}\nelse{\n print(\"NO\");\n}"}, {"source_code": "function toi(x){return parseInt(x);}\n(function(){\n function isp(s,ts){\n\tvar index=0;\n\tvar state=0;\n\twhile(index!=s.length){\n\t switch(state){\n\t case 0:\n\t\tif(s[index]==ts[state]){\n\t\t state=1;\n\t\t}else{\n\t\t state=0;\n\t\t}\n\t\tbreak;\n\t case 1:\n\t\tif(s[index]==ts[state]){\n\t\t state=2;\n\t\t}else if(s[index]==ts[state-1]){\n\t\t state=1;\n\t\t}else{\n\t\t state=0;\n\t\t}\n\t\tbreak;\n\t case 2:\n\t\tif(s[index]==ts[state]){\n\t\t state=3;\n\t\t}else{\n\t\t state=2;\n\t\t}\n\t\tbreak;\n\t case 3:\n\t\tif(s[index]==ts[state]){\n\t\t state=4;\n\t\t}else if(s[index]==ts[state-1]){\n\t\t state=3;\n\t\t}else{\n\t\t state=2;\n\t\t}\n\t\tbreak;\n\t }\n\t index++;\n\t if(state==4)return true;\n\t}\n\treturn false;\n }\n var s=readline();\n if(isp(s,\"ABBA\")||isp(s,\"BAAB\")){\n\tprint(\"YES\");\n }else{\n\tprint(\"NO\");\n }\n})();\n"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n\n if (s.length < 4) { console.log('NO'); return; }\n if (s.length === 4) {\n console.log(\n ( (s[0] === 'A' && s[1] === 'B' && s[2] === 'B' && s[3] === 'A') || (s[0] === 'B' && s[1] === 'A' && s[2] === 'A' && s[3] === 'B')) ?\n \"YES\" : \"NO\"\n ); return;\n }\n\n const AB = [];\n const BA = [];\n let find = false;\n\n //console.log(double[0][0].pos)\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { \n AB.push(i-1);\n }\n else if (s[i-2] === 'B' && s[i-1] === 'A') {\n BA.push(i-1);\n }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n AB.push(i);\n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n BA.push(i);\n }\n }\n\n AB.forEach(ab => {\n BA.forEach(ba => {\n if (Math.abs(ab - ba) >= 2) {\n console.log('YES'); process.exit(0);\n }\n }); \n });\n\n console.log(\"NO\");\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n let str = input[0];\n if(str.indexOf(\"AB\") !== -1 && str.indexOf(\"BA\") !== -1) {\n if (str.indexOf(\"AB\") < str.lastIndexOf(\"BA\") - 1 || str.indexOf(\"BA\") < str.lastIndexOf(\"AB\") - 1) return console.log('YES');\n }\n console.log('NO');\n});"}], "negative_code": [{"source_code": "const check = (s) => {\n let ab = -1;\n let ba = -1;\n\n for (let i = 0; i < s.length; i++) {\n const w = s[i] + s[i + 1];\n if (w === 'AB') {\n if (ab === -1) {\n ab = i;\n }\n\n if (ba !== -1 && i !== ba + 1 && i !== ba - 1) {\n return true;\n }\n }\n else if (w === 'BA') {\n if (ba === -1) {\n ba = i;\n }\n\n if (ab !== -1 && i !== ab + 1 && i !== ab - 1) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nprocess.stdin.on('readable', () => {\n const chunk = process.stdin.read();\n if (chunk !== null) {\n process.stdout.write(check(chunk.toString()) ? 'YES' : 'NO');\n process.stdout.write(\"\\n\");\n }\n});"}, {"source_code": "const check = (s) => {\n let ab = -1;\n let ba = -1;\n\n const n = s.length;\n let i = 0;\n let j = n - 1;\n while (i <= n / 2 && j >= n / 2) {\n const wi = s[i] + s[i + 1];\n\n if (wi === 'AB') {\n if (ab === -1) {\n ab = i;\n } else if (ba !== -1 && i !== ba + 1 || i !== ba - 1) {\n return true;\n }\n }\n else if (wi === 'BA') {\n if (ba === -1) {\n ba = i;\n } else if (ab !== -1 && i !== ab + 1 || i !== ab - 1) {\n return true;\n }\n }\n\n const wj = s[j - 1] + s[j];\n\n if (wj === 'AB') {\n if (ab === -1) {\n ab = j;\n } else if (ba !== -1 && j !== ba + 1 || j !== ba - 1) {\n return true;\n }\n }\n else if (wj === 'BA') {\n if (ba === -1) {\n ba = j;\n } else if (ab !== -1 && j !== ab + 1 || j !== ab - 1) {\n return true;\n }\n }\n\n i++;\n j--;\n }\n\n return false;\n}\n\nprocess.stdin.on('readable', () => {\n const chunk = process.stdin.read();\n if (chunk !== null) {\n process.stdout.write(check(chunk.toString()) ? 'YES' : 'NO');\n process.stdout.write(\"\\n\");\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n let rLine = line.replace('AB', '')\n if (rLine === line) {\n console.log('NO')\n } else if (rLine.replace('BA', '') === rLine) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n})\n"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n const lastIndexOfAB = line.lastIndexOf('AB')\n const lastIndexOfBA = line.lastIndexOf('BA')\n const indexOfAB = line.indexOf('AB')\n const indexOfBA = line.indexOf('BA')\n if (lastIndexOfAB > 0 && indexOfBA > 0) {\n if (lastIndexOfAB - indexOfBA >= 2) {\n console.log('YES')\n }\n }\n if (lastIndexOfBA > 0 && indexOfAB > 0) {\n if (lastIndexOfBA - indexOfAB >= 2) {\n console.log('YES')\n }\n }\n console.log('NO')\n})\n"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n const lastIndexOfAB = line.lastIndexOf('AB')\n const lastIndexOfBA = line.lastIndexOf('BA')\n const indexOfAB = line.indexOf('AB')\n const indexOfBA = line.indexOf('BA')\n if (lastIndexOfAB - indexOfBA >= 2 || lastIndexOfBA - indexOfAB >= 2) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n})\n"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n let rABLine = line.replace('AB', '')\n let rBALine = line.replace('BA', '')\n if (rABLine === line && rBALine === line) {\n console.log('NO')\n } else if (rABLine.replace('BA', '') === rABLine && rBALine.replace('AB') === rBALine ) {\n console.log('NO')\n } else {\n console.log('YES')\n }\n})\n"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n\n if (s.length < 4) { console.log('NO'); return; }\n\n const double = [ [0, 0], [0, 0] ];\n let find = false;\n\n //console.log(double[0][0].pos)\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { \n if (double[1][1] === 1) { console.log('YES'); return; }\n double[0][0] = 1; find = true; \n }\n else if (s[i-2] === 'B' && s[i-1] === 'A') {\n if (double[1][0] === 1) { console.log('YES'); return; }\n double[0][1] = 1; find = true; \n }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n if (!find && double[0][1] === 1) { console.log('YES'); return; }\n double[1][0] = 1; find = true; \n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n if (!find && double[0][0] === 1) { console.log('YES'); return; }\n double[1][1] = 1; find = true; \n }\n\n if (find) { i += 1; find = false; }\n }\n\n console.log(\n ((double[0][0] === 1 && double[0][1]) || (double[1][0] === 1 && double[1][1] === 1)) ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n let answer = false;\n\n if (s.length < 4) { console.log('NO'); return; }\n\n const double = [[0, 0], [0, 0]];\n\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') double[0][0] = 1;\n else if (s[i-2] === 'B' && s[i-1] === 'A') double[0][1] = 1;\n\n if (s[i-1] === 'A' && s[i] === 'B') double[0][0] = 1;\n else if (s[i-1] === 'B' && s[i] === 'A') double[0][1] = 1;\n }\n\n \n\n console.log(\n ((double[0][0] === 1 && double[0][1]) || (double[1][0] === 1 && double[1][1] === 1)) ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n\n if (s.length < 4) { console.log('NO'); return; }\n\n const double = [ [0, 0], [0, 0] ];\n let find = false;\n\n //console.log(double[0][0].pos)\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { \n if (double[1][1] === 1) { console.log('YES'); return; }\n double[0][0] = 1; find = true; \n }\n else if (s[i-2] === 'B' && s[i-1] === 'A') {\n if (double[1][0] === 1) { console.log('YES'); return; }\n double[0][1] = 1; find = true; \n }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n if (!find && double[0][1] === 1) { console.log('YES'); return; }\n double[1][0] = 1; find = true; \n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n if (!find && double[0][0] === 1) { console.log('YES'); return; }\n double[1][1] = 1; find = true; \n }\n\n if (find) { if (s.length >= 5) i += 1; find = false; }\n }\n\n console.log(\n ((double[0][0] === 1 && double[0][1]) || (double[1][0] === 1 && double[1][1] === 1)) ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n\n if (s.length < 4) { console.log('NO'); return; }\n\n const double = [ [0, 0], [0, 0] ];\n let find = false;\n\n //console.log(double[0][0].pos)\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { double[0][0] = 1; find = true; }\n else if (s[i-2] === 'B' && s[i-1] === 'A') { double[0][1] = 1; find = true; }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n if (!find && double[0][1] === 1) { console.log('YES'); return; }\n double[1][0] = 1; find = true; \n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n if (!find && double[0][0] === 1) { console.log('YES'); return; }\n double[1][1] = 1; find = true; \n }\n\n if (find) { i += 1; find = false; }\n }\n\n console.log(\n ((double[0][0] === 1 && double[0][1]) || (double[1][0] === 1 && double[1][1] === 1)) ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let s = input[0];\n\n if (s.length < 4) { console.log('NO'); return; }\n if (s.length === 4) {\n console.log(\n ( (s[0] === 'A' && s[1] === 'B' && s[2] === 'B' && s[3] === 'A') || (s[0] === 'B' && s[1] === 'A' && s[2] === 'A' && s[3] === 'B')) ?\n \"YES\" : \"NO\"\n ); return;\n }\n\n const double = [ [0, 0], [0, 0] ];\n let find = false;\n\n //console.log(double[0][0].pos)\n for (let i = 2; i < s.length; i += 1) {\n if (s[i-2] === 'A' && s[i-1] === 'B') { \n if (double[1][1] === 1 && s.length >= 5) { console.log('YES'); return; }\n double[0][0] = 1; find = true; \n }\n else if (s[i-2] === 'B' && s[i-1] === 'A') {\n if (double[1][0] === 1 && s.length >= 5) { console.log('YES'); return; }\n double[0][1] = 1; find = true; \n }\n\n if (s[i-1] === 'A' && s[i] === 'B') { \n if (!find && double[0][1] === 1) { console.log('YES'); return; }\n double[1][0] = 1; find = true; \n }\n else if (s[i-1] === 'B' && s[i] === 'A') { \n if (!find && double[0][0] === 1) { console.log('YES'); return; }\n double[1][1] = 1; find = true; \n }\n\n if (find) { if (s.length >= 5) i += 1; find = false; }\n }\n\n console.log(\n ((double[0][0] === 1 && double[0][1]) || (double[1][0] === 1 && double[1][1] === 1)) ? \"YES\" : \"NO\"\n );\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n let str = input[0];\n if (str.indexOf(\"AB\") < str.lastIndexOf(\"BA\") - 1) console.log('YES');\n else console.log('NO');\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const str = input[0];\n if (str.split(\"AB\").includes(\"BA\")) console.log(\"YES\");\n else console.log(\"NO\");\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const str = input[0];\n if (str.split(\"AB\").join(\"\").includes(\"BA\")) console.log(\"YES\");\n else console.log(\"NO\");\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n let str = input[0];\n if(str.indexOf(\"AB\") !== -1 && str.indexOf(\"BA\") !== -1) {\n if (str.indexOf(\"AB\") < str.lastIndexOf(\"BA\") - 1 || str.indexOf(\"BA\") < str.lastIndexOf(\"AB\") - 1) console.log('YES');\n }\n console.log('NO');\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n let str = input[0];\n if (str.indexOf(\"AB\") < str.lastIndexOf(\"BA\") - 1 || str.indexOf(\"BA\") < str.lastIndexOf(\"AB\") - 1) console.log('YES');\n else console.log('NO');\n});"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab = -1, ba = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab = i+1;\n }\n\n if(ba == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba = l-1-i;\n }\n}\n\nif(ab == -1 || ba == -1) print('NO');\nelse if(ab == ba) print('NO');\nelse if(ab == ba+2) print('NO');\nelse print('YES');"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n\n if(ab1 > -1 && ab2 == -1 && s[i] == 'A' && s[i+1] == 'B')\n {\n ab2 = i+1;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n\n if(ba1 > -1 && ba2 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba2 = l-2-i;\n }\n}\n\n\n\nif(ab1 == -1 || ba1 == -1) print('NO');\nelse\n{\n var flag = -1;\n\n if(ab1 > -1 && ((ab1 != ba1 && ab1 != ba1+2) || (ab1 != ba2 && ab1 != ba2+2))) flag = 1;\n\n if(ab2 > -1 && ((ab2 != ba1 && ab2 != ba1+2) || (ab2 != ba2 && ab2 != ba2+2))) flag = 1;\n\n\n if(flag == 1) print('YES');\n else print('NO');\n\n}\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n else if(ab1 > -1 && ab2 == -1 && s[i] == 'A' && s[i+1] == 'B')\n {\n ab2 = i+1;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n else if(ba1 > -1 && ba2 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba2 = l-2-i;\n }\n}\n\nif(s=='ABAXXXAB')\n{\n print('ab1=',ab1,'; ab2=',ab2,'; ba1=',ba1,'; ba2=',ba2);\n}\n\nif(ab1 == -1 || ba1 == -1) print('NO');\nelse\n{\n var flag = -1;\n\n if(ab1 > -1 && ((ab1 != ba1 && ab1 != ba1+2) || (ab1 != ba2 && ab1 != ba2+2))) flag = 1;\n\n if(ab2 > -1 && ((ab2 != ba1 && ab2 != ba1+2) || (ab2 != ba2 && ab2 != ba2+2))) flag = 1;\n\n\n if(flag == 1) print('YES');\n else print('NO');\n\n}\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n else if(ab1 > -1 && ab2 == -1 && s[i] == 'A' && s[i+1] == 'B')\n {\n ab2 = i+1;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n else if(ba1 > -1 && ba2 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba2 = l-2-i;\n }\n}\n\n// if(s=='ABAXXXAB')\n// {\n// print('ab1=',ab1,'; ab2=',ab2,'; ba1=',ba1,'; ba2=',ba2);\n//}\n\nif(ab1 == -1 || ba1 == -1) print('NO');\nelse\n{\n var flag = -1;\n\n if(ab1 > -1 && ( ((ab1 != ba1 && ab1 != ba1+2)&&(ba1 >-1)) || ((ab1 != ba2 && ab1 != ba2+2)&(ba2>-1)) ) ) flag = 1;\n\n if(ab2 > -1 && ( ((ab2 != ba1 && ab2 != ba1+2)&&(ba1 >-1)) || ((ab2 != ba2 && ab2 != ba2+2)&(ba2>-1)) ) ) flag = 1;\n\n\n if(flag == 1) print('YES');\n else print('NO');\n\n}\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab = -1, ba = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab = i+1;\n }\n\n if(ba == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba = i+1;\n }\n}\n\nif(ab == -1 || ba == -1) print('NO');\nelse if(ab < ba) print('YES');"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab = -1, ba = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab = i+1;\n }\n\n if(ba == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba = i+1;\n }\n}\n\nif(ab == -1 || ba == -1) print('NO');\nelse if(ab >= ba) print('NO');\nelse print('YES');"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n else if(ab1 > -1 && ab2 == -1 && s[i] == 'A' && s[i+1] == 'B')\n {\n ab2 = i+1;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n else if(ba1 > -1 && ba2 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba2 = l-2-i;\n }\n}\n\n// if(s=='ABAXXXAB')\n// {\n// print('ab1=',ab1,'; ab2=',ab2,'; ba1=',ba1,'; ba2=',ba2);\n//}\n\nif(ab1 == -1 || ba1 == -1) print('NO');\nelse\n{\n var flag = -1;\n\n if(ab1 > -1 && ((ab1 != ba1 && ab1 != ba1+2) || (ab1 != ba2 && ab1 != ba2+2))) flag = 1;\n\n if(ab2 > -1 && ((ab2 != ba1 && ab2 != ba1+2) || (ab2 != ba2 && ab2 != ba2+2))) flag = 1;\n\n\n if(flag == 1) print('YES');\n else print('NO');\n\n}\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab = -1, ba = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab = i+1;\n }\n\n if(ba == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba = l-2-i;\n }\n}\n\nif(ab == -1 || ba == -1) print('NO');\nelse if(ab == ba) print('NO');\nelse if(ab == ba+2) print('NO');\nelse print('YES');"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab1 = -1, ab2 = -1, ba1 = -1, ba2 = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab1 == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab1 = i+1;\n }\n\n if(ab1 > -1 && ab2 == -1 && s[i] == 'A' && s[i+1] == 'B')\n {\n ab2 = i+1;\n }\n\n if(ba1 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba1 = l-2-i;\n }\n\n if(ba1 > -1 && ba2 == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba2 = l-2-i;\n }\n}\n\nif(s=='ABAXXXAB')\n{\n print('ab1=',ab1,'; ab2=',ab2,'; ba1=',ba1,'; ba2=',ba2);\n}\n\nif(ab1 == -1 || ba1 == -1) print('NO');\nelse\n{\n var flag = -1;\n\n if(ab1 > -1 && ((ab1 != ba1 && ab1 != ba1+2) || (ab1 != ba2 && ab1 != ba2+2))) flag = 1;\n\n if(ab2 > -1 && ((ab2 != ba1 && ab2 != ba1+2) || (ab2 != ba2 && ab2 != ba2+2))) flag = 1;\n\n\n if(flag == 1) print('YES');\n else print('NO');\n\n}\n"}, {"source_code": "var s = readline();\n\nvar l = s.length, ab = -1, ba = -1;\n\nfor(var i=0; i<(l-1); i++)\n{\n if(ab == -1 && s[i] == 'A' && s[i+1] == 'B') \n {\n ab = i+1;\n }\n\n if(ba == -1 && s[l-1-i] == 'A' && s[l-2-i] == 'B') \n {\n ba = i+1;\n }\n}\n\nif(ab == -1 || ba == -1) print('NO');\nelse if(ab == ba) print('NO');\nelse if(ab == ba+2) print('NO');\nelse print('YES');"}, {"source_code": "var n = readline();\nvar len = n.length;\ns1 = n;\ns2 = n;\ns1 = s1.replace(\"AB\", \"\");\ns1 = s1.replace(\"BA\", \"\");\ns2 = s2.replace(\"AB\", \"\");\ns2 = s2.replace(\"BA\", \"\"); \nif(s1.length <= len - 4 || s2.length <= len - 4){\n print(\"YES\");\n}\nelse{\n print(\"NO\");\n}"}, {"source_code": "var n = readline();\nvar len = n.length;\nn = n.replace(\"AB\", \"\");\nn = n.replace(\"BA\", \"\");\nif(n.length <= len - 4){\n print(\"YES\");\n}\nelse{\n print(\"NO\");\n}\n"}, {"source_code": "var n = readline();\nvar len = n.length;\ns1 = n;\ns2 = n;\ns1 = s1.replace(\"AB\", \"\");\ns1 = s1.replace(\"BA\", \"\");\ns2 = s2.replace(\"BA\", \"\");\ns2 = s2.replace(\"AB\", \"\"); \nif(s1.length <= len - 4 || s2.length <= len - 4){\n print(\"YES\");\n}\nelse{\n print(\"NO\");\n}"}, {"source_code": "var str = readline();\nvar reg = /AB/;\nstr = str.replace(/BA/gi, \"\");\nreg.test(str)==true? print(\"YES\"):print(\"NO\");"}, {"source_code": "var str = readline();\nvar reg = /(BA.*AB)||(AB.*BA)/;\n//str = str.replace(/BA/gi, \"\");\nreg.test(str)==true? print(\"YES\"):print(\"NO\");"}, {"source_code": "var str = readline();\nvar r1 = /AB/g;\nvar r2 = /BA/g;\nvar result1 = [],result2 = [];\nvar match;\n\nwhile (match = r1.exec(str))\n result1.push(match.index);\n\nwhile (match = r2.exec(str))\n result2.push(match.index);\n\nvar flag = 0;\nfor(var i = 0; i < result1.length; i++)\n\tfor(var j = 0; j < result2.length; j++)\n\t\tif(result1[i]- result2[j] >= 2){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t\t\nprint((flag)?\"YES\":\"NO\");"}, {"source_code": "var res = readline().match(/ABABA|BABAB|AB|BA/g);\nvar s = [0,0];\nflag = 0;\nif(res){\n\tfor(var i = 0; i < res.length; i++){\n\t\tif(res[i] == \"AB\")\n\t\t\ts[0] = 1;\n\t\telse if(res[i] == \"BA\")\n\t\t\ts[1] = 1;\n\t\telse if(res[i] == \"ABABA\" || res[i] == \"BABAB\"){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t\tif(s[0] == 1 && s[1] == 1){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tprint((flag==1) ? \"YES\" : \"NO\");\n}\nelse\n\tprint(\"NO\");"}, {"source_code": "var res = readline().match(/AB|BA/g);\nvar s = [0,0];\nflag = 0;\nif(res){\n\tfor(var i = 0; i < res.length; i++){\n\t\tif(res[i] == \"AB\")\n\t\t\ts[0] = 1;\n\t\telse if(res[i] == \"BA\")\n\t\t\ts[1] = 1;\n\t\tif(s[0] == 1 && s[1] == 1){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tprint((flag==1) ? \"YES\" : \"NO\");\n}\nelse\n\tprint(\"NO\");"}, {"source_code": "var str = readline();\nvar r1 = /AB/g;\nvar r2 = /BA/g;\nvar result1 = [],result2 = [];\nvar match;\n\nwhile (match = r1.exec(str))\n result1.push(match.index);\n\nwhile (match = r2.exec(str))\n result2.push(match.index);\n\nprint(result1);\nprint(result2);\n\nvar flag = 0;\nfor(var i = 0; i < result1.length; i++)\n\tfor(var j = 0; j < result2.length; j++)\n\t\tif(Math.abs(result1[i]- result2[j]) >= 2){\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t}\n\t\t\nprint((flag)?\"YES\":\"NO\");"}, {"source_code": "function main() {\n var line = readline();\n var baFound = 0;\n var abFound = 0;\n var abaFound = 0;\n for(var i=0;i= 2 || abFound + baFound >= 2){\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}\n\n\nmain()"}, {"source_code": "function main() {\n var line = readline();\n var baFound = 0;\n var abFound = 0;\n var abaFound = 0;\n for(var i=0;i= 2 || (abFound >= 1 && baFound >=1)){\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}\n\n\nmain()"}, {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/550/A\n\n var linea = readline();\n \n var regex = /(AB|BA)/g;\n\n var numeroMatches = 0;\n \n while(regex.test(linea) && numeroMatches <4){\n numeroMatches++;\n }\n if(numeroMatches == 2){\n write(\"YES\");\n }else{\n write(\"NO\");\n }\n})();"}, {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/550/A\n\n var linea = readline();\n \n var regex = /(AB|BA)/g;\n\n var numeroMatches = 0;\n \n while(regex.test(linea) || numeroMatches <2){\n numeroMatches++;\n }\n if(numeroMatches == 2){\n write(\"YES\");\n }else{\n write(\"NO\");\n }\n})();"}, {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/550/A\n\n var linea = readline();\n \n var regex = /(AB|BA)/g;\n var matches = linea.match(regex);\n if(matches === null){\n write(\"NO\");\n return;\n }\n \n var matches = matches.toString();\n if(matches.includes(\"AB\") && matches.includes(\"BA\")){\n write(\"YES\");\n }else{\n write(\"NO\");\n }\n})();"}, {"source_code": "(function main(){\n http://codeforces.com/problemset/problem/550/A\n\n var linea = readline();\n \n var regex = /(AB|BA)/g;\n\n var numeroMatches = 0;\n \n while(regex.test(linea) && numeroMatches <2){\n numeroMatches++;\n }\n if(numeroMatches == 2){\n write(\"YES\");\n }else{\n write(\"NO\");\n }\n})();"}], "src_uid": "33f7c85e47bd6c83ab694a834fa728a2"} {"source_code": "\nvar toInt = function(v){\n\treturn parseInt(v);\n}\nvar n = parseInt( readline() );\nvar m = [];\nfor(var i=0; i=0; k--){\n\t\tvar kk = x[k];\n\t\th[kk] = true;\n\t\tfor(var i=0; i -1; r--) {\n var toIgnore = verts[r];\n ignored[toIgnore] = true;\n\n for(var start=0; start update) {\n adjMat[start][end] = update;\n }\n if(ignored[start] && ignored[end]) {\n output[r] += adjMat[start][end];\n }\n }\n }\n}\nprint(output.join(' '));"}], "negative_code": [{"source_code": "/*\nProblem from: http://codeforces.com/problemset/problem/296/D\n\nD. Greg and Graph\ntime limit per test3 seconds\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nGreg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:\n\nThe game consists of n steps.\nOn the i-th step Greg removes vertex number xi from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex.\nBefore executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that d(i,\u2009v,\u2009u) is the shortest path between vertices v and u in the graph that formed before deleting vertex xi, then Greg wants to know the value of the following sum: .\nHelp Greg, print the value of the required sum before each step.\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009500) \u2014 the number of vertices in the graph.\n\nNext n lines contain n integers each \u2014 the graph adjacency matrix: the j-th number in the i-th line aij (1\u2009\u2264\u2009aij\u2009\u2264\u2009105,\u2009aii\u2009=\u20090) represents the weight of the edge that goes from vertex i to vertex j.\n\nThe next line contains n distinct integers: x1,\u2009x2,\u2009...,\u2009xn (1\u2009\u2264\u2009xi\u2009\u2264\u2009n) \u2014 the vertices that Greg deletes.\n\nOutput\nPrint n integers \u2014 the i-th number equals the required sum before the i-th step.\n\n*/\n\nvar n = parseInt(readline());\nvar adjMat = [];\nfor(var i =0; i < n; i ++) {\n var temp = [];\n var line = readline().split(' ')\n for(var j =0; j -1; r--) {\n var toIgnore = verts[r];\n ignored[toIgnore] = true;\n\n for(var start=0; start update) {\n adjMat[start][end] = update;\n }\n if(ignored[start] && ignored[end]) {\n output[r] += adjMat[start][end];\n }\n }\n }\n}\nprint(output.join(' '));"}, {"source_code": "/*\nProblem from: http://codeforces.com/problemset/problem/296/D\n\nD. Greg and Graph\ntime limit per test3 seconds\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nGreg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:\n\nThe game consists of n steps.\nOn the i-th step Greg removes vertex number xi from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex.\nBefore executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that d(i,\u2009v,\u2009u) is the shortest path between vertices v and u in the graph that formed before deleting vertex xi, then Greg wants to know the value of the following sum: .\nHelp Greg, print the value of the required sum before each step.\n\nInput\nThe first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009500) \u2014 the number of vertices in the graph.\n\nNext n lines contain n integers each \u2014 the graph adjacency matrix: the j-th number in the i-th line aij (1\u2009\u2264\u2009aij\u2009\u2264\u2009105,\u2009aii\u2009=\u20090) represents the weight of the edge that goes from vertex i to vertex j.\n\nThe next line contains n distinct integers: x1,\u2009x2,\u2009...,\u2009xn (1\u2009\u2264\u2009xi\u2009\u2264\u2009n) \u2014 the vertices that Greg deletes.\n\nOutput\nPrint n integers \u2014 the i-th number equals the required sum before the i-th step.\n\n*/\n\nvar n = parseInt(readline());\nvar adjMat = [];\nfor(var i =0; i < n; i ++) {\n var temp = [];\n var line = readline().split(' ')\n for(var j =0; j -1; r--) {\n var toIgnore = verts[r];\n ignored[toIgnore] = true;\n\n for(var start=0; start update) {\n adjMat[start][end] = update;\n }\n if(ignored[start] && ignored[end]) {\n output[r] += adjMat[start][end];\n }\n }\n }\n}\nprint(output.join(' '));\n\n"}, {"source_code": "\nvar toInt = function(v){\n\treturn parseInt(v);\n}\nvar n = parseInt( readline() );\nvar m = [];\nfor(var i=0; i=0; k--){\n\t\tvar kk = x[k];\n\t\th[kk] = true;\n\t\tfor(var i=0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var array = readline().split('');\r\n var anwer = []\r\n for (var i = 0; i < array.length; i++) {\r\n // console.log(array[i])\r\n if(i % 2 ===0 && array[i] ==='a') anwer.push('b')\r\n if(i % 2 ===0 && array[i] !=='a') anwer.push('a')\r\n if(i % 2 ===1 && array[i] !=='z') anwer.push('z')\r\n if(i % 2 ===1 && array[i] ==='z') anwer.push('y')\r\n }\r\n\r\n console.log(anwer.join(''))\r\n // console.log(array.join(''))\r\n\r\n })\r\n}\r\n\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar s = nextCharArray();\r\n\t\tfor(var j = 0; j < s.length; j++){\r\n\t\t\tif(j % 2 == 0){\r\n\t\t\t\tif(s[j] == \"a\"){\r\n\t\t\t\t\ts[j] = \"b\";\r\n\t\t\t\t}else{\r\n\t\t\t\t\ts[j] = \"a\";\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"z\"){\r\n\t\t\t\t\ts[j] = \"y\";\r\n\t\t\t\t}else{\r\n\t\t\t\t\ts[j] = \"z\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(s, 0));\r\n\t}\r\n}"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); \n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var answer = '';\n var k = lines[j].split('');\n for(var l = 0; l < k.length; l++){\n if(l % 2 === 0){\n if(k[l] == 'a'){\n answer += 'b';\n }else if(k[l] != 'a'){\n answer += 'a';\n }\n }else if(l % 2 == 1){\n if(k[l] == 'z'){\n answer += 'y';\n }else if(k[l] != 'z'){\n answer += 'z';\n }\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); \n var n = lines[0];\n for(var j = 1; j <= n; j++){\n var answer = '';\n var k = lines[j].split('');\n for(var l = 0; l < k.length; l++){\n if(l % 2 === 0){\n if(k[l] == 'a'){\n answer += 'b';\n }else if(k[l] != 'a'){\n answer += 'a';\n }\n }else if(l % 2 == 1){\n if(k[l] == 'z'){\n answer += 'y';\n }else if(k[l] != 'z'){\n answer += 'z';\n }\n }\n }\n console.log(answer);\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const ln2 = rl().split(\"\");\r\n solution(ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(str) {\r\n // cl(str);\r\n let answer = \"\";\r\n let chance = true;\r\n for (let i = 0; i < str.length; i++) {\r\n if (chance) {\r\n if (str[i] == \"a\") answer += \"b\";\r\n else answer += \"a\";\r\n chance = !chance;\r\n } else {\r\n if (str[i] == \"z\") answer += \"y\";\r\n else answer += \"z\";\r\n chance = !chance;\r\n }\r\n }\r\n cl(answer);\r\n }\r\n}\r\n"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const s = readLine();\r\n\r\n const res = a(s);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction a(s){\r\n let finalString = '';\r\n let first = 97;\r\n let last = 122;\r\n for(let i = 0 ; i < s.length ; i++){\r\n let ascii = s[i].charCodeAt(0);\r\n if(i % 2 === 0){\r\n //alice turn\r\n if(ascii !== first){\r\n finalString += String.fromCharCode(first);\r\n } else {\r\n finalString += String.fromCharCode(first + 1);\r\n }\r\n } else {\r\n //Bob turn\r\n if(ascii !== last){\r\n finalString += String.fromCharCode(last);\r\n } else{\r\n finalString += String.fromCharCode(last - 1);\r\n }\r\n }\r\n }\r\n return finalString;\r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = s => {\n const result = []\n ;[...s].forEach((v, index) => {\n const code = v.charCodeAt()\n if (index % 2 === 0) {\n if (code === 97) {\n result.push(String.fromCharCode(code + 1))\n } else {\n result.push(String.fromCharCode(97))\n }\n } else {\n if (code === 122) {\n result.push(String.fromCharCode(code - 1))\n } else {\n result.push(String.fromCharCode(122))\n }\n }\n })\n return result.join('')\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet s\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n s = line\n answer.push(calculate(s))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n\n index++\n }\n})\n\n// chainNumberList, cList, aList, bList\n// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst str = readLine();\n\t\tconst result = [];\n\t\tlet flag = true;\n\t\tfor (let c of str) {\n\t\t\tif (flag) {\n\t\t\t\tif (c === 'a') result.push('b');\n\t\t\t\telse {\n\t\t\t\t\tresult.push('a');\n\t\t\t\t}\n\t\t\t\tflag = false;\n\t\t\t} else {\n\t\t\t\tif (c === 'z') result.push('y');\n\t\t\t\telse {\n\t\t\t\t\tresult.push('z');\n\t\t\t\t}\n\t\t\t\tflag = true;\n\t\t\t}\n\t\t}\n\t\tconsole.log(result.join(''));\n\t}\n}\n"}, {"source_code": "const processData = (lines) => {\n const n = +lines[0]\n for (let i=0; i i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [], "src_uid": "c02357c4d959e300f970f66f9b3107eb"} {"source_code": "a=readline;for(k=a();k--;print(!(s+z)+z)){n=a();s=z=0;a().split(\" \").map(j=>{z+=!(-j);s-=-j})}", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\nfunction stringArrayToBigInts(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( BigInt(array[i]) );\n }\n return result;\n}\n\nfunction sumOfAllElementsInArray(arr) {\n var result = 0;\n for( var i = 0; i < arr.length; i++ ) {\n result += arr[i];\n }\n return result;\n}\n\nfunction productOfAllElementsInArray(arr) {\n var result = 1;\n for( var i = 0; i < arr.length; i++ ) {\n result *= arr[i];\n }\n return result;\n}\n\nfunction maxOfElementsInArray(arr) {\n var result = 0;\n for( var i = 0; i < arr.length; i++ ) {\n if( arr[i] > result ) {\n result = arr[i];\n }\n }\n return result;\n}\n\n\n// ======================================================\n// A. Non-zero\n// http://codeforces.com/contest/1300/problem/A\n// ======================================================\n\nfunction findNumberOfZeros(arr) {\n var result = 0;\n for( var i = 0; i < arr.length; i++ ) {\n if( arr[i] === 0 ) {\n result += 1;\n }\n }\n return result;\n}\n\nfunction convertZeros(arr) {\n for( var i = 0; i < arr.length; i++ ) {\n if( arr[i] === 0 ) {\n arr[i] = 1;\n }\n }\n return arr;\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = arr;\n var extra = 0; \n \n var noz = findNumberOfZeros(arr);\n if( noz !== 0 ) {\n result = noz;\n arr2 = convertZeros(arr);\n }\n \n var sum = sumOfAllElementsInArray(arr2);\n if( sum == 0 ) {\n result = result + 1;\n }\n return result;\n}\n\nfunction main() {\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\n\n\n\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n const numbers = readline().split(' ').map(x => parseInt(x));\n let result = 0;\n let sum = 0;\n\n for (const number of numbers) {\n if (number === 0) {\n result++;\n sum++;\n } else {\n sum += number;\n }\n }\n\n if (sum === 0) {\n result++; \n }\n\n console.log(result);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n let result = 0;\n let sum = 0;\n readline().split(' ').forEach(x => {\n const number = parseInt(x)\n if (number === 0) {\n result++;\n sum++;\n } else {\n sum += number;\n }\n });\n\n console.log((sum === 0) ? result + 1 : result);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n const t = parseInt(readline());\n for (let i = 0; i < t; i++) {\n const n = parseInt(readline());\n const numbers = readline().split(' ').map(x => parseInt(x));\n let result = 0;\n\n for (const number of numbers) {\n if (number === 0) {\n result++;\n }\n }\n\n let sum = 0;\n for (const number of numbers) {\n if (number === 0) {\n sum++;\n } else {\n sum += number;\n }\n }\n\n if (sum === 0) {\n result++; \n }\n\n console.log(result);\n }\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let ans = 0;\n let sum = 0;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 0) {\n arr[i] = 1;\n ans++;\n }\n\n sum += arr[i];\n }\n\n console.log(sum ? ans : ans + 1);\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "const calc = (d, x) => Math.ceil( d / (x + 1) + x)\n\nconst sum = arr => arr.reduce((r, x) => r+x, 0)\nconst mulAgr = arr => arr.reduce((r, x) => r*x, 1)\n\nconst processData = (lines) => {\n const num = +lines[0]\n\n for (let j=0; j +x)\n\n const sumOfLine = sum(numsLine)\n let minOps = 0\n if (sumOfLine === 0) {\n minOps = 1\n }\n let mulOps = 0\n for (const num of numsLine) {\n if (num === 0) {\n mulOps++\n }\n }\n const nonZeroArr = numsLine.map(x => x === 0 ? 1 : x)\n if (sum(nonZeroArr) === 0) {\n mulOps++\n }\n if (mulOps > minOps) {\n console.log(mulOps)\n } else {\n console.log(minOps)\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const sum = arr.reduce((a, b) => a + b, 0);\n const num0 = arr.reduce((acc, cur) => {\n if (cur === 0) {\n acc++;\n }\n return acc;\n }, 0);\n\n return (sum === -num0) ? num0 + 1 : num0;\n}\n\nfunction main() {\n const t = parseInt(readline());\n // console.log({t});\n for(let i = 0; i < t; i++) {\n readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res);\n }\n}\n"}, {"source_code": "b=parseInt;a=readline;k=a();while(k--){n=a();x=a().split(\" \");z=s=0;for(i=0;i{z+=(j*1==0);s+=j*1});print((s+z==0)+z)}"}, {"source_code": "a=readline;for(k=a();k--;){n=a();s=z=0;a().split(\" \").map(j=>{z+=(j*1==0);s+=j*1});print((s+z==0)+z)}"}, {"source_code": "a=readline;for(k=a();k--;print(!(s+z)+z)){n=a();s=z=0;a().split(\" \").map(j=>{z+=-j?0:1;s-=-j})}"}, {"source_code": "a=readline;k=a();while(k--){n=a();x=a().split(\" \");z=s=i=0;while(i {\n return readline().split(' ').map(num => parseInt(num))\n}\n\nconst readInt = () => readInts()[0]\n\nlet t = readInt()\n\nwhile (t --> 0) {\n const n = readInt()\n const arr = readInts()\n\n let ans = 0\n let sum = 0\n for (let i in arr) sum += arr[i]\n\n for (let i in arr) {\n if (!arr[i]) {\n arr[i] ++\n ans ++\n sum ++\n }\n }\n\n if (!sum) {\n for (let i in arr) {\n if (arr[i] + 1 !== 0) {\n arr[i] ++\n ans ++\n break\n }\n }\n }\n\n print(ans)\n}\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n let r = 0, s = 0\n for (let i = 0; i < n; i++) {\n if (a[i] === 0) { r++; s++ }\n else s += a[i]\n }\n return r + !s\n}\nlet t = +readline()\nwhile(t--) print(problem(+readline(), readline().split(' ').map(i => +i)))\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var list = myconv(next(),4);\n var count = 0;\n var sum = 0;\n for(var j = 0; j < N; j++){\n sum += list[j];\n if(list[j] == 0){\n count++;\n sum++;\n }\n }\n if(sum == 0){\n count++;\n }\n output[i] = count;\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "function readNum() {\n return Number(readline());\n}\nfunction readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = readNum();\n for (var i = 0; i < testCasesNum; i++) {\n var len = readNum();\n var arr = readNumArray();\n var zeros = 0;\n var sum = 0;\n for (var j = 0; j < len; j++) {\n sum += arr[j];\n if (arr[j] === 0) {\n zeros++;\n }\n }\n print(sum + zeros === 0 ? zeros + 1 : zeros);\n }\n}\nmain()"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i{z+=!(j*1);s+=j*1})}"}, {"source_code": "a=readline;for(k=a();k--;){n=a();x=a().split(\" \");z=s=i=0;while(i0 || sum<0))\n\t\tprint(0);\n\telse if(prod===0 && sum===0)\n\tprint(1);\n\telse if(prod-sum===0){\n\t\tprint(prod+1);\n\t}\n\telse{\n\t\tif(sum+prod===0)\n\t\t\tprint(prod+1);\n\t\telse\n\t\t\tprint(prod);\n\t}\n}\n//balda solve hoyna kno\n//bal chal problem amar\n"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i0 || sum<0))\n\t\tprint(0);\n\telse if(prod===0 && sum===0)\n\tprint(1);\n\telse if(prod-sum===0){\n\t\tprint(prod+1);\n\t}\n\telse{\n\t\tif(sum+prod===0)\n\t\t\tprint(prod+1)\n\t\telse\n\t\t\tprint(prod);\n\t}\n}\n//balda solve hoyna kno\n//bal chal problem amar\n"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i0 || sum<0))\n\t\tprint(0);\n\telse if(prod===0 && sum===0)\n\tprint(1);\n\telse if(prod-sum===0){\n\t\tprint(prod+1);\n\t}\n\telse\n\t\tprint(Math.min(prod));\n}\n//balda solve hoyna kno\n//bal chal problem amar\n"}, {"source_code": "var n=Number(readline());\nfor(var i=0;i0 || sum<0))\n\t\tprint(0);\n\telse if(prod===0 && sum===0)\n\tprint(1);\n\telse if(prod-sum===0){\n\t\tprint(prod+1);\n\t}\n\telse\n\t\tprint(Math.min(prod,sum));\n}\n//balda solve hoyna kno\n//bal chal problem amar\n"}, {"source_code": "b=parseInt;a=readline;k=a();while(k--){n = a();x = a().split(\" \");z=s=0;i=0;while(i++= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n len = this.allLines[ this.currrentLineNumber ].length;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );\n }\n }\n this.currrentCharacterIndex = endIdx;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n return this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCases = function() {\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {\n environmentType = 'local-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n };\n\n this.configureStreamsAndReadInput = function() {\n var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log;\n }\n }\n catch( ex ) {\n print = console.log;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino();\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines();\n this.runCases() ;\n }\n };\n \n this.configureStreamsAndReadInput();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "var line = readline().split(' ');\nvar N = line[0] - 0, M = line[1] - 0;\nvar mat = [];\n\nfor (var i = 0; i < N; ++i) {\n mat[i] = readline();\n}\n\nvar ans = 0;\nfor (var i = 0; i + 1 < N; ++i) {\n for (var j = 0; j + 1 < M; ++j) {\n var s = \"\" + mat[i][j] + mat[i + 1][j] + mat[i][j + 1] + mat[i + 1][j + 1];\n \n if (s.indexOf('f') >= 0 && s.indexOf('a') >= 0 && s.indexOf('c') >= 0 && s.indexOf('e') >= 0) ++ans;\n }\n}\n\nprint(ans + \"\\n\");"}, {"source_code": "var line = readline().split(' ');\nvar n = Number(line[0]),\n\tm = Number(line[1]);\n\nvar face = 'acef';\n\nvar a = [];\nfor (var i = 0; i < n; i++) {\n\ta.push(readline());\n}\n\nvar ans = 0;\n\nfor (var i = 0; i < n - 1; i++) {\n\tfor (var j = 0; j < m - 1; j++) {\n\t\tvar b = [a[i][j], a[i+1][j], a[i+1][j+1], a[i][j+1]];\n\t\tb.sort();\n\t\tb = b.join('');\n\t\tif (b === face) {\n\t\t\tans += 1;\n\t\t}\n\t}\n}\n\nprint(ans);"}, {"source_code": "var IN = readline().split(' '),\n n = IN[0],\n m = IN[1],\n OUT = 0;\n\nif(n<2 || m<2){\n print(OUT);\n quit();\n}\n\nvar INPUT = [];\nfor(var i=0; i 0 && s.indexOf('a') > 0 && s.indexOf('c') > 0 && s.indexOf('e') > 0) ++ans;\n }\n}\n\nprint(ans + \"\\n\");\n"}, {"source_code": "var line = readline().split(' ');\nvar N = line[0] - 0, M = line[1] - 0;\nvar mat = [];\n\nfor (var i = 0; i < N; ++i) {\n mat[i] = readline();\n}\n\nvar ans = 0;\nfor (var i = 0; i + 1 < N; ++i) {\n for (var j = 0; j + 1 < M; ++j) {\n var s = \"\" + mat[i][j] + mat[i + 1][j] + mat[i][j + 1] + mat[i + 1][j + 1];\n \nprint(s.indexOf('a'));\n if (s.indexOf('f') > 0 && s.indexOf('a') > 0 && s.indexOf('c') > 0 && s.indexOf('e') > 0) ++ans;\n }\n}\n\nprint(ans + \"\\n\");"}, {"source_code": "var line = readline().split(' ');\nvar N = line[0] - 0, M = line[1] - 0;\nvar mat = [];\n\nfor (var i = 0; i < N; ++i) {\n mat[i] = readline();\n}\n\nvar ans = 0;\nfor (var i = 0; i + 1 < N; ++i) {\n for (var j = 0; j + 1 < M; ++j) {\n var s = \"\" + mat[i][j] + mat[i + 1][j] + mat[i][j + 1] + mat[i + 1][j + 1];\n \n print(s);\n if (s.indexOf('f') > 0 && s.indexOf('a') > 0 && s.indexOf('c') > 0 && s.indexOf('e') > 0) ++ans;\n }\n}\n\nprint(ans + \"\\n\");"}], "src_uid": "742e4e6ca047da5f5ebe5d854d6a2024"} {"source_code": "const MEMORY = [];\nlet MEMORY_INDEX = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n\n for (let I = 0; I < T; ++I) {\n let bin = readline();\n let oneIndexArr = [-1];\n let answer = 0;\n for (let i = 0; i < bin.length; ++i) {\n if (bin[i] === '1') {\n oneIndexArr.push(i);\n }\n }\n for(let i = 1; i < oneIndexArr.length; ++i) {\n let num = 0;\n let zeroCount = oneIndexArr[i] - oneIndexArr[i - 1] - 1;\n for (let j = oneIndexArr[i]; j < bin.length; ++j) {\n num = (num << 1) + (bin[j] === '1' ? 1 : 0);\n if (num > zeroCount + j - oneIndexArr[i] + 1) {\n break;\n }\n answer++;\n }\n }\n print(answer);\n }\n}\n", "positive_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let nnn = 0;\n for (let j = 0, z = 0; j < str.length; j++) {\n if (str[j] === '1') {\n for (let k = j; k < j + (2 * 100000) && k < str.length; k++) {\n let x = str.substring(j, k + 1);\n if (parseInt(x, 2) > 2 && z < parseInt(x, 2) - x.length) {\n break;\n } else {\n nnn++;\n }\n }\n z = 0;\n } else {\n z++;\n }\n }\n console.log(nnn);\n }\n});"}, {"source_code": "let inputTextName;\nlet outTextName;\nif (process.argv.length === 5) {\n inputTextName = process.argv[3];\n outTextName = process.argv[4];\n}\nlet MEMORY = [];\nlet MEMORY_INDEX = 0;\n\nif (inputTextName) {\n const fs = require('fs');\n const path = require('path');\n fs.readFile(path.join(__dirname, inputTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n} else {\n const RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', solve);\n}\n\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n\n for (let I = 0; I < T; ++I) {\n let bin = readline();\n let oneIndexArr = [-1];\n let answer = 0;\n for (let i = 0; i < bin.length; ++i) {\n if (bin[i] === '1') {\n oneIndexArr.push(i);\n }\n }\n for(let i = 1; i < oneIndexArr.length; ++i) {\n let num = 0;\n let zeroCount = oneIndexArr[i] - oneIndexArr[i - 1] - 1;\n for (let j = oneIndexArr[i]; j < bin.length; ++j) {\n num = (num << 1) + (bin[j] === '1' ? 1 : 0);\n if (num > zeroCount + j - oneIndexArr[i] + 1) {\n break;\n }\n answer++;\n }\n }\n print(answer);\n }\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 3192; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 1024; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 4200; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 512; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 256; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += str.split(base[j]).length - 1;\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 2048; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += str.split(base[j]).length - 1;\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n nx = 0;\n for (let j = 1; j < str.length + 1; j++) {\n let jstr = j.toString(2);\n jstr = '0'.repeat(j - jstr.length) + jstr;\n nx += str.split(jstr).length - 1;\n } \n console.log(nx);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 512; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 256; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 3600; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 65535; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += str.split(base[j]).length - 1;\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 3720; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 64; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length; j++) {\n x += str.split(base[j]).length - 1;\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 256; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 256; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x + 1;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length + 1; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst base = [];\nfor(i = 1; i < 2048; i++) {\n let str = i.toString(2);\n base.push('0'.repeat(i - str.length) + str);\n}\n\nlet count = (str, f) => {\n let j = 0;\n for (let i = 0; i < str.length; i++) {\n let x = str.indexOf(f, i);\n if (x == -1) {\n break;\n } else {\n j++;\n i = x;\n }\n }\n\n return j;\n}\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n const n = parseInt(input[0]);\n for (let i = 0; i < n; i++) {\n const str = input[i + 1];\n let x = 0; \n \n for (let j = 0; j < str.length && j < base.length; j++) {\n x += count(str, base[j]);\n }\n\n console.log(x);\n }\n});"}], "src_uid": "3c93a76f986b1ef653bf5834716ac72a"} {"source_code": "function main() {\n var b = readline();\n \n var indexStart = b.indexOf('[');\n if(indexStart < 0) {\n return -1;\n }\n\n var b2 = b.substr(indexStart + 1);\n var index2 = b2.indexOf(':');\n if(index2 < 0) {\n return -1;\n }\n\n var b3 = b2.substr(index2 + 1);\n var indexLast = b3.lastIndexOf(']');\n if(indexLast < 0) {\n return -1;\n }\n\n var b4 = b3.substring(0,indexLast);\n var index3 = b4.lastIndexOf(':');\n if(index3 < 0) {\n return -1;\n }\n \n var bfin = b4.substring(0, index3);\n return bfin.split('|').length + 3\n}\n\nprint(main());", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let tmp=0, lngth=0, str='';\n\n rl.on('line', (input) => {\n str=input; rl.close(); therest();\n return 0;}\n \n );\n\nlet therest=function() {\n // console.log(str);\n let len=0;\n let a = str.indexOf('['), b=str.lastIndexOf(']');\n if (a==-1||b==-1||a>b) {console.log(-1); return 0;}\n\n // console.log(a,b);\n str=str.slice(a+1,b);\n len=2;\n a = str.indexOf(':'), b=str.lastIndexOf(':');\n if (a==-1||b==-1||a==b) {console.log(-1); return 0;}\n str=str.slice(a+1,b);\n len=4;\n\n for (let char of str) {\n if (char=='|') len++;\n }\n console.log(len);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet t = 0\nrl.on('line', (input) => {\n let s = input.split('')\n let c = 0\n let isAcc = 0\n let op = [-1, -1]\n let cl = [-1, -1]\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '[' && op[0] === -1) {\n op[0] = i\n isAcc++\n } else if (op[0] !== -1 && s[i] === ':' && op[1] === -1) {\n op[1] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = s.length - 1; i > op[1]; i--) {\n if (s[i] === ']' && cl[1] === -1 && cl[0] === -1) {\n cl[1] = i\n isAcc++\n } else if (cl[1] !== -1 && s[i] === ':' && cl[0] === -1) {\n cl[0] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = op[1] + 1; i < cl[0]; i++) {\n if (s[i] !== '|') {\n c++\n }\n }\n rl.close()\n if (isAcc !== 4) {\n console.log(-1)\n } else {\n console.log(s.length - c)\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet t = 0\nrl.on('line', (input) => {\n let s = input.split('')\n let c = 0\n let isAcc = 0\n let op = [-1, -1]\n let cl = [-1, -1]\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '[' && op[0] === -1) {\n op[0] = i\n isAcc++\n } else if (op[0] !== -1 && s[i] === ':' && op[1] === -1) {\n op[1] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = s.length - 1; i > op[1]; i--) {\n if (s[i] === ']' && cl[1] === -1 && cl[0] === -1) {\n cl[1] = i\n isAcc++\n } else if (cl[1] !== -1 && s[i] === ':' && cl[0] === -1) {\n cl[0] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = op[1] + 1; i < cl[0]; i++) {\n if (s[i] !== '|') {\n c++\n }\n }\n rl.close()\n if (isAcc !== 4) {\n console.log(-1)\n } else {\n console.log(s.length - c)\n }\n});\n"}, {"source_code": "var s=readline();\nvar max=0,f=0,f2=0,col1=0,col2=0;\nfor(var y=s.length-1;y>=0;y--){\n\nif(s[y]===']'&&f2===0&&y>2){max++;f2=1;}\nelse if(s[y]===':'&&f2===1&&y>1){max++;f2=2;col2=y;break;}\n\n}\nif(max===2){\nfor(var i=0;i3?max:-1);"}, {"source_code": "var s = readline();\nif(s.indexOf('[') != -1) {\n s = s.substring(s.indexOf('['), s.length);\n\tif(s.lastIndexOf(']') != -1) {\n s = s.substring(0, s.lastIndexOf(']')+1);\n s = s.replace(/[^\\:\\[\\]\\|]/gim,'').replace(/[^\\:\\|]/gim,'');\n s = s.substring(s.indexOf(':'), s.length);\n s = s.substring(0, s.lastIndexOf(':')+1);\n\n if(s.length >= 2 && s[0] == ':' && s[s.length-1] == ':') {\n s = s.replace(/[^\\|]/gim,'');\n print(s.length+4);\n } else {\n print(-1);\n }\n } else {\n print(-1);\n }\n} else {\n print(-1);\n}"}, {"source_code": "var str = readline()\n\nfunction getStart(start, end){\n var mask = '[:'\n\twhile(mask && start <=end) {\n \tif(str[start] == mask[0]) {\n \tmask = mask.slice(1)\n \n if(!mask)\n \tbreak;\n }\n start++;\n }\n return !mask ? start : -1;\n}\n\nfunction getEnd(start, end){\n var mask = ']:'\n\twhile(mask && start >=end) {\n \tif(str[start] == mask[0]) {\n \tmask = mask.slice(1)\n \n if(!mask)\n \tbreak;\n }\n start--;\n }\n\t\n return !mask ? start : -1;\n}\n\n\nfunction getMaxLen() {\n if(str.length < 4) {\n return -1\n }\n \n var start = getStart(0, str.length-3);\n if(start == -1) {\n return -1;\n }\n \n var end = getEnd(str.length-1, start+1);\n if(end == -1) {\n return -1;\n }\n \n \n var l = 0;\n for(var i=start+1;i elem === '|').length;\n}\n\nvar s = readline().split(\"\");\n\n \nprint(calc(s));\n\n\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n let tmp=0, lngth=0, str='';\n\n rl.on('line', (input) => {\n str=input; rl.close(); therest();\n return 0;}\n \n );\n\nlet therest=function() {\n console.log(str);\n let len=0;\n let a = str.indexOf('['), b=str.lastIndexOf(']');\n if (a==-1||b==-1||a>b) {console.log(-1); return 0;}\n\n // console.log(a,b);\n str=str.slice(a+1,b);\n len=2;\n a = str.indexOf(':'), b=str.lastIndexOf(':');\n if (a==-1||b==-1||a==b) {console.log(-1); return 0;}\n str=str.slice(a+1,b);\n len=4;\n\n for (let char of str) {\n if (char=='|') len++;\n }\n console.log(len);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet t = 0\nrl.on('line', (input) => {\n let s = input.split('')\n let c = 0\n let isAcc = 0\n let op = [0, 0]\n let cl = [0, 0]\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '[' && op[0] === 0) {\n op[0] = 1\n isAcc++\n } else if (op[0] === 1 && s[i] === ':' && op[1] === 0) {\n op[1] = 1\n isAcc++\n } else if (op[0] === 1 && op[1] === 1 && s[i] === ':' && cl[0] === 0) {\n cl[0] = 1\n isAcc++\n } else if (op[0] === 1 && op[1] === 1 && s[i] === ']' && cl[0] === 1 && cl[1] === 0) {\n cl[1] = 1\n isAcc++\n } else if (op[0] === 1 && op[1] === 1 && s[i] === '|' && cl[0] === 0 && cl[1] === 0) {\n\n } else {\n c++\n }\n }\n rl.close()\n if (isAcc !== 4) {\n console.log(-1)\n } else {\n console.log(c)\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet t = 0\nrl.on('line', (input) => {\n let s = input.split('')\n let c = 0\n let isAcc = 0\n let op = [0, 0]\n let cl = [0, 0]\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '[' && op[0] === 0) {\n op[0] = i\n isAcc++\n } else if (op[0] !== 0 && s[i] === ':' && op[1] === 0) {\n op[1] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = s.length - 1; i > op[1]; i--) {\n if (s[i] === ']' && cl[1] === 0 && cl[0] === 0) {\n cl[1] = i\n isAcc++\n } else if (cl[1] !== 0 && s[i] === ':' && cl[0] === 0) {\n cl[0] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = op[1]+1; i < cl[0]; i++) {\n if (s[i] !== '|') {\n c++\n }\n }\n rl.close()\n if (isAcc !== 4) {\n console.log(-1)\n } else {\n console.log(c)\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nlet t = 0\nrl.on('line', (input) => {\n let s = input.split('')\n let c = 0\n let isAcc = 0\n let op = [0, 0]\n let cl = [0, 0]\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '[' && op[0] === 0) {\n op[0] = i\n isAcc++\n } else if (op[0] !== 0 && s[i] === ':' && op[1] === 0) {\n op[1] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = s.length - 1; i > op[1]; i--) {\n if (s[i] === ']' && cl[1] === 0 && cl[0] === 0) {\n cl[1] = i\n isAcc++\n } else if (cl[1] !== 0 && s[i] === ':' && cl[0] === 0) {\n cl[0] = i\n isAcc++\n break;\n } else {\n c++\n }\n }\n for (let i = op[1]+1; i < cl[0]; i++) {\n if (s[i] !== '|') {\n c++\n }\n }\n rl.close()\n if (isAcc !== 4) {\n console.log(-1)\n } else {\n console.log(s.length-c)\n }\n});\n"}, {"source_code": "var s = readline();\ns = s.substring(s.indexOf('['), s.length);\ns = s.substring(0, s.lastIndexOf(']')+1);\ns = s.replace(/[^\\:\\[\\]\\|]/gim,'').replace(/[^\\:\\|]/gim,'');\ns = s.substring(s.indexOf(':'), s.length);\ns = s.substring(0, s.lastIndexOf(':')+1);\nif((s.match(/\\:/g) || []).length != 2) {\n print(-1); \n} else {\n print(s.length+2);\n}"}, {"source_code": "var s = readline();\ns = s.substring(s.indexOf('['), s.length);\ns = s.substring(0, s.lastIndexOf(']')+1);\ns = s.replace(/[^\\:\\[\\]\\|]/gim,'').replace(/[^\\:\\|]/gim,'');\ns = s.substring(s.indexOf(':'), s.length);\ns = s.substring(0, s.lastIndexOf(':')+1);\n\nif(s.length >= 2 && s[0] == ':' && s[s.length-1] == ':') {\n\ts = s.replace(/[^\\|]/gim,'');\n\t\n print(s.length+4);\n} else {\n\tprint(-1);\n}"}, {"source_code": "function calc(s) {\n if (s.indexOf('[') === -1) {\n return -1;\n } else {\n s = s.slice(s.indexOf('['));\n }\n \n if (s.indexOf(':') === -1) {\n return -1;\n } else {\n s = s.slice(s.indexOf(':'));\n }\n \n if (s.lastIndexOf(']') === -1) {\n return -1;\n } else {\n s = s.slice(0, s.lastIndexOf(']') + 1);\n }\n \n if (s.lastIndexOf(':') === -1) {\n return -1;\n } else {\n s = s.slice(0, s.lastIndexOf(':') + 1);\n }\n\n return 4 + s.filter(elem => elem === '|').length;\n}\n\nvar s = readline().split(\"\");\n\n \nprint(calc(s));\n"}], "src_uid": "915b4776a6b1fa15886247eb1ad40b60"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const M = 2 * m + n + 10;\r\n let h = new Array(2 * n).fill(-1),\r\n te = new Array(M),\r\n ne = new Array(M),\r\n w = new Array(M);\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n te[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let i = 0; i < m; i++) {\r\n let [u, v, w] = await rns();\r\n u--, v--;\r\n add(u, v, w);\r\n add(v + n, u + n, w);\r\n }\r\n for (let i = 0; i < n; i++) add(i, i + n, 0);\r\n const djk = () => {\r\n const dist = new Array(2 * n).fill(Infinity);\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n const vis = new Array(2 * n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = te[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n queue.push([v, dist[v]]);\r\n }\r\n }\r\n }\r\n return dist;\r\n };\r\n const dist = djk();\r\n return dist.slice(n + 1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const M = 2 * m + n + 10;\r\n let h = new Array(2 * n).fill(-1),\r\n te = new Array(M),\r\n ne = new Array(M),\r\n w = new Array(M);\r\n let idx = 0;\r\n const add = (i, j, c) => {\r\n te[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let i = 0; i < m; i++) {\r\n let [u, v, w] = await rns();\r\n u--, v--;\r\n add(u, v, w);\r\n add(v + n, u + n, w);\r\n }\r\n for (let i = 0; i < n; i++) add(i, i + n, 0);\r\n const djk = () => {\r\n const dist = new Array(2 * n).fill(Infinity);\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n const vis = new Array(2 * n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = te[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n queue.push([v, dist[v]]);\r\n }\r\n }\r\n }\r\n return dist;\r\n };\r\n const dist = djk();\r\n return dist.slice(n + 1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid async function () {\r\n let idx = 0;\r\n const read = () => inputs[idx++];\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n let h = new Array(n).fill(-1),\r\n hs = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n const add = (h, i, j, c) => {\r\n e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1;\r\n };\r\n const time = new Date().valueOf();\r\n for (let i = 0; i < m; i++) {\r\n const [u, v, w] = await rns();\r\n add(h, u - 1, v - 1, w);\r\n add(hs, v - 1, u - 1, w);\r\n }\r\n if (n === 100000) console.log(new Date().valueOf() - time);\r\n const djk = (dist, queue, h) => {\r\n const vis = new Array(n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n queue.push([v, dist[v]]);\r\n }\r\n }\r\n }\r\n };\r\n const dist = new Array(n).fill(Infinity);\r\n {\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n djk(dist, queue, h);\r\n }\r\n if (n !== 100000) {\r\n const queue = new Heap((a, b) => a[1] - b[1], dist.map((d, i) => [i, d]));\r\n djk(dist, queue, hs);\r\n }\r\n return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n _defineProperty(this, \"_map\", new Map());\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n this._map.set(this._heap[i], j);\r\n this._map.set(this._heap[j], i);\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._map.set(node, this._heap.length);\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this._map.set(val, i);\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n getIndex(val) {\r\n return this._map.get(val);\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const [n, m] = await rns();\r\n let h = new Array(n).fill(-1),\r\n hs = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n w = [];\r\n const add = (h, i, j, c) => {\r\n e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1;\r\n };\r\n const time = new Date().valueOf();\r\n for (let i = 0; i < m; i++) {\r\n const [u, v, w] = await rns();\r\n add(h, u - 1, v - 1, w);\r\n add(hs, v - 1, u - 1, w);\r\n }\r\n if (n === 100000) console.log(new Date().valueOf() - time);\r\n const djk = (dist, queue, h) => {\r\n const vis = new Array(n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n queue.push([v, dist[v]]);\r\n }\r\n }\r\n }\r\n };\r\n const dist = new Array(n).fill(Infinity);\r\n {\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n djk(dist, queue, h);\r\n }\r\n if (n !== 100000) {\r\n const queue = new Heap((a, b) => a[1] - b[1], dist.map((d, i) => [i, d]));\r\n djk(dist, queue, hs);\r\n }\r\n return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nconst n = 100000,\r\n m = 200000;\r\nconst edges = [`${n} ${m}`];\r\nfor (let i = 0; i < m; i++) {\r\n let x = Math.floor(Math.random() * n),\r\n y = Math.floor(Math.random() * n);\r\n while (x === y) {\r\n y = Math.floor(Math.random() * n);\r\n }\r\n edges.push(`${x} ${y} ${Math.floor(Math.random() * 100000)}`);\r\n}\r\nlet i = 0;\r\nconst read$1 = () => edges[i++];\r\nvoid async function () {\r\n console.time('test');\r\n await solve(read$1);\r\n console.timeEnd('test');\r\n}();\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n _defineProperty(this, \"_map\", new Map());\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n this._map.set(this._heap[i], j);\r\n this._map.set(this._heap[j], i);\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._map.set(node, this._heap.length);\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this._map.set(val, i);\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n getIndex(val) {\r\n return this._map.get(val);\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ')\r\n .map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const M = 2 * m + 10;\r\n let h = new Array(n).fill(-1),\r\n hs = new Array(n).fill(-1),\r\n e = new Array(M),\r\n ne = new Array(M),\r\n w = new Array(M);\r\n let idx = 0;\r\n const add = (h, i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let i = 0; i < m; i++) {\r\n const [u, v, w] = await rns();\r\n add(h, u - 1, v - 1, w);\r\n add(hs, v - 1, u - 1, w);\r\n }\r\n const djk = (dist, queue, h, nodes = new Array(n)) => {\r\n const vis = new Array(n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n if (!nodes[v]) {\r\n nodes[v] = [v, dist[v]];\r\n queue.push(nodes[v]);\r\n } else {\r\n const j = queue.getIndex(nodes[v]);\r\n nodes[v][1] = dist[v];\r\n queue.modify(j, nodes[v]);\r\n }\r\n }\r\n }\r\n }\r\n };\r\n const dist = new Array(n).fill(Infinity);\r\n {\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n djk(dist, queue, h);\r\n }\r\n {\r\n const nodes = dist.map((d, i) => [i, d]);\r\n const queue = new Heap((a, b) => a[1] - b[1], nodes);\r\n djk(dist, queue, hs, nodes);\r\n }\r\n return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n _defineProperty(this, \"_map\", new Map());\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) {\r\n this.down(i);\r\n this._map.set(arr[i], i);\r\n }\r\n }\r\n }\r\n swap(i, j) {\r\n this._map.set(this._heap[i], j);\r\n this._map.set(this._heap[j], i);\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._map.set(node, this._heap.length);\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this._map.set(val, i);\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n getIndex(val) {\r\n return this._map.get(val);\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nasync function solve(read) {\r\n const rns = async () => {\r\n return (await read()).split(' ')\r\n .map(Number);\r\n };\r\n const [n, m] = await rns();\r\n const M = 2 * m + 10;\r\n let h = new Array(n).fill(-1),\r\n hs = new Array(n).fill(-1),\r\n e = new Array(M),\r\n ne = new Array(M),\r\n w = new Array(M);\r\n let idx = 0;\r\n const add = (h, i, j, c) => {\r\n e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;\r\n };\r\n for (let i = 0; i < m; i++) {\r\n const [u, v, w] = await rns();\r\n add(h, u - 1, v - 1, w);\r\n add(hs, v - 1, u - 1, w);\r\n }\r\n const djk = (dist, queue, h, nodes = new Array(n)) => {\r\n const vis = new Array(n);\r\n while (queue.size()) {\r\n const [u, d] = queue.pop();\r\n if (vis[u]) continue;\r\n vis[u] = 1;\r\n for (let i = h[u]; ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (vis[v]) continue;\r\n if (dist[v] > dist[u] + w[i]) {\r\n dist[v] = dist[u] + w[i];\r\n if (!nodes[v]) {\r\n nodes[v] = [v, dist[v]];\r\n queue.push(nodes[v]);\r\n } else {\r\n const j = queue.getIndex(nodes[v]);\r\n nodes[v][1] = dist[v];\r\n queue.modify(j, nodes[v]);\r\n }\r\n }\r\n }\r\n }\r\n };\r\n const dist = new Array(n).fill(Infinity);\r\n {\r\n const queue = new Heap((a, b) => a[1] - b[1]);\r\n dist[0] = 0;\r\n queue.push([0, 0]);\r\n djk(dist, queue, h);\r\n }\r\n {\r\n const nodes = dist.map((d, i) => [i, d]);\r\n const queue = new Heap((a, b) => a[1] - b[1], nodes);\r\n djk(dist, queue, hs, nodes);\r\n }\r\n return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n _defineProperty(this, \"_map\", new Map());\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n this._map.set(this._heap[i], j);\r\n this._map.set(this._heap[j], i);\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._map.set(node, this._heap.length);\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this._map.set(val, i);\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n getIndex(val) {\r\n return this._map.get(val);\r\n }\r\n}\r\n\r\nasync function main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n res[i] = await solve(r);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log('zdebug' + error);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nconst it = rl[Symbol.asyncIterator]();\r\nasync function read() {\r\n return (await it.next()).value;\r\n}\r\nvoid async function () {\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "b08f925e09a9c2e7ccc6a8c5c143fc5f"} {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var len = +readline(); // \u0434\u043b\u0438\u043d\u0430\n var s = readline(); // \u0441\u0442\u0440\u043e\u043a\u0430\n s = removeLastEvens(s, len);\n findResult(s, s.length);\n }\n}\n\nfunction removeLastEvens(str, len) {\n while (str && Number(str.slice(-1)) % 2 === 0) {\n str = str.substring(0, len - 1);\n len -= 1;\n }\n return str;\n}\n\nfunction findResult(str, len) {\n if (!str) {\n print(-1);\n return;\n }\n var sum = 0;\n for (var j = 0; j < len; j++) {\n sum += Number(str[j]);\n }\n if (sum % 2 === 0) {\n print(str);\n } else {\n str = removeOdd(str, str.length);\n if (!str || Number(str[str.length - 1]) % 2 === 0) {\n print(-1);\n } else {\n str = str.replace(/^(0+)/, \"\");\n print(str);\n }\n }\n}\n\nfunction removeOdd(str, len) {\n for (var k = 0; k < len; k++) {\n if (str[k] % 2 === 1) {\n str = str.substring(0, k) + str.substring(k + 1);\n return str;\n }\n }\n return 0;\n};\n\nmain();", "positive_code": [{"source_code": "function check(digits) {\n var num = \"\";\n var sum = 0;\n\n for (var i = digits.length - 1; i >= 0; i--) {\n var d = parseInt(digits[i]);\n if (num.length < 1 && d % 2 < 1) continue;\n\n num = d.toString() + num;\n sum += d;\n if (sum % 2 < 1) return num;\n }\n return -1;\n}\n\nvar t = parseInt(readline());\nvar l = 0;\nwhile (t > 0) {\n if (l == 0) {\n readline();\n l = 1;\n } else {\n l = 0;\n t--;\n print(check(readline()));\n }\n}\n"}, {"source_code": "p=print;a=readline;for(k=a();k--;){n=a();x=/([13579]).*?([13579])/.exec(a());(x)?p(x[0]):p(-1)}"}, {"source_code": "a=readline;p=print;for(k=a();k--;){n=a();x=/([13579]).*?([13579])/.exec(a());if(x) p(x[0]);else p(-1)}"}, {"source_code": "a=readline;p=print;for(k=a();k--;){n=a();x=a().match(/([13579]).*?([13579])/);if(x) p(x[0]);else p(-1)}"}, {"source_code": "p=print;a=readline;for(k=a();k--;){n=a();x=a().match(/[13579]/g);(x&&x[1])?p(x[0]+x[1]):p(-1)} "}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const odd = [];\n for (let i = 0; i < d.length; i++) {\n if (d[i] % 2) {\n odd.push(d[i]);\n }\n\n if (odd.length === 2) {\n break;\n }\n }\n\n if (odd.length === 2) {\n ans += odd.join('') + '\\n';\n }\n else {\n ans += '-1\\n';\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\n\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n})\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve (nStr) {\n const nArr = nStr.split('').map(Number);\n while ((nArr.length > 1) && (nArr[nArr.length-1] % 2 === 0)) {\n nArr.pop();\n }\n if (nArr.length < 2) {\n return '-1';\n }\n const sum = nArr.reduce((a, b) => a + b, 0);\n if (sum % 2 === 1) {\n for(let i = nArr.length - 2; i >= 0; i--) {\n if (nArr[i] % 2 === 1) {\n nArr.splice(i, 1);\n return nArr.join('');\n }\n }\n return '-1';\n } else {\n return nArr.join('');\n }\n}\n\nfunction main() {\n const t = parseInt(readline());\n for(let i = 0; i < t; i++) {\n readline();\n const line = readline();\n const res = solve(line);\n console.log(res);\n }\n}\n"}, {"source_code": "function getSum(num, digits) {\n var sum = 0;\n\n for (var i = 0; i < digits; ++i) {\n sum += Number(num[i]);\n }\n\n return sum;\n}\n\nfunction isEvenNumber(sum) {\n return sum % 2 === 0;\n}\n\nfunction isOddNumber(sum) {\n return sum % 2 !== 0;\n}\n\nfunction isOdd(num, digits) {\n return isOddNumber(num[digits - 1]);\n}\n\nfunction isStrange(num, digits, sum) {\n return isOdd(num, digits) && isEvenNumber(sum);\n}\n\nfunction processItem() {\n var digits = +readline();\n var num = readline();\n var tempNum = num;\n var tempSum = getSum(num, digits);\n var tempDigits = digits;\n\n while (!isOdd(tempNum, tempDigits, tempSum) && tempDigits > 1) {\n tempSum = tempSum - tempNum[tempDigits - 1];\n tempNum = tempNum.slice(0, tempDigits - 1);\n tempDigits--;\n }\n\n var currentIndex = tempDigits - 2;\n\n while (isOddNumber(tempSum) && tempDigits > 1 && currentIndex >= 0) {\n var n = Number(tempNum[currentIndex]);\n\n if (isOddNumber(n) || n === 0) {\n tempSum = tempSum - tempNum[currentIndex];\n tempNum = tempNum.slice(0, currentIndex) + tempNum.slice(currentIndex + 1);\n tempDigits--;\n }\n\n currentIndex--;\n }\n\n print(isStrange(tempNum, tempDigits, tempSum) ? tempNum : '-1');\n}\n\nfunction processItems() {\n var itemsCount = +readline();\n var items = [];\n\n for (var i = 0; i < itemsCount; ++i) {\n processItem();\n }\n\n return items;\n}\n\nprocessItems();\n"}, {"source_code": "\n\n\nvar numRun= readline();\n \nfor(var n=0;nNumber(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var s = next();\n if(N == 1){\n output[i] = \"-1\";\n continue;\n }\n var list = myconv(s,7);\n var sum = 0;\n var odds = new Set();\n var evens = new Set();\n var outputS = \"\";\n for(var j = 0; j < N; j++){\n sum += list[j];\n outputS += list[j].toString();\n if(list[j] % 2 != 0 && sum % 2 == 0){\n output[i] = outputS;\n break;\n }\n }\n if(output[i] == null){\n output[i] = \"-1\";\n }\n }\n myout(myconv(output,9));\n}\n"}], "negative_code": [{"source_code": "\n\n\nvar numRun= readline();\n \nfor(var n=0;nNumber(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1);\n var s = next();\n if(N == 1){\n output[i] = \"-1\";\n continue;\n }\n var list = myconv(s,7);\n var sum = 0;\n var odds = new Set();\n var evens = new Set();\n for(var j = 0; j < N; j++){\n sum += list[j];\n if(list[j] % 2 == 0){\n evens.add(list[j]);\n }else{\n if(i < N - 1){\n odds.add(j);\n }\n }\n }\n if(sum % 2 == 0){\n while(s.length > 0){\n var migihasi = myconv(s.slice(-1));\n if(migihasi % 2 != 1){\n s = s.slice(0,s.length - 1);\n }else{\n break;\n }\n }\n if(s != \"\"){\n output[i] = s;\n }else{\n output[i] = \"-1\";\n }\n }else{\n odds = Array.from(odds);\n \n list.splice(odds[0],odds[0] + 1);\n while(list.length > 0){\n if(list[0] == 0){\n list.splice(0,1);\n }else{\n break;\n }\n }\n if(list.length == 0){\n output[i] = \"-1\";\n }else{\n output[i] = myconv(list,0);\n }\n }\n }\n myout(myconv(output,9));\n}\n"}], "src_uid": "8f00837e04627e445dfb8b6cd0216640"} {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n if (found[i - 1]) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n closeForS.add(cs)\n }\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n \n (Object.keys(found).length !== l1 && closeForS.size === l2) || \n (Object.keys(found).length === l1 && closeForS.size !== l2)\n \n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});", "positive_code": [{"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines1 = 0, blankLines2 = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) {\n if (rc) {\n blankLines1 ++;\n } else {\n blankLines2 ++;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif ((blankLines2 === 0 && blankLines1 > 0) || (blankLines2 > 0 && blankLines1 === 0)) output = -1;\n\nprint(output);"}], "negative_code": [{"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n if (i === l1 - 1) {\n for (cs = 0; cs <= l2; cs++) {\n closeForS.add(cs)\n }\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n\n (Object.keys(found).length !== l1 && closeForS.size === l2) || \n (Object.keys(found).length === l1 && closeForS.size !== l2)\n\n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let NOTFOUNDBLACK = false;\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n else {found[i] = [foundFirstBlack]}\n \n \n if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack > foundFirstBlack && foundFirstWhiteInBlack < foundLastBlack) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n (Object.keys(test).length !== l1) && FOUNDBLACK\n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let NOTFOUNDBLACK = false;\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n else {found[i] = [foundFirstBlack]}\n \n \n if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n (Object.keys(test).length !== l1 || closeForS.size !== l2) && FOUNDBLACK\n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n for (cs = 0; cs <= l2; cs++) {\n closeForS.add(cs)\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n \n (Object.keys(found).length !== l1 && closeForS.size === l2) || \n (Object.keys(found).length === l1 && closeForS.size !== l2)\n \n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n if (i === l1 - 1) {\n for (cs = 0; cs <= l2; cs++) {\n closeForS.add(cs)\n }\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n \n (Object.keys(found).length !== l1 && closeForS.size === l2) || \n (Object.keys(found).length === l1 && closeForS.size !== l2)\n \n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n if (i === l1 - 1) {\n for (cs = 0; cs <= l2; cs++) {\n closeForS.add(cs)\n }\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n (\n (Object.keys(found).length !== l1 && closeForS.size !== l2)\n // (Object.keys(found).length === l1 && closeForS.size !== l2)\n ) && FOUNDBLACK\n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin\n});\nlet l1, l2;\nlet test = [];\nrl.on('line', (line) => {\n if (l1 === undefined && l2 === undefined) {\n const [l11, l22] = line.split(' ');\n\n l1 = +l11;\n l2 = +l22;\n } else {\n test.push(line.split(''));\n }\n}).on('close', () => {\n let FOUNDBLACK = false;\n // \u043a\u043e\u043b-\u0432\u043e \u043e\u0441\u0442\u0440\u043e\u0432\u043a\u043e\u0432 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0433\u043d\u0438\u0442\u043e\u0432\n let N = 0;\n // i => \u0441\u0442\u0440\u043e\u043a\u0430, j = \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n let i = 0;\n const found = {}; // \u0441\u0442\u0440\u043e\u043a\u0438\n const closeForS = new Set();\n \n while (i < l1) {\n const foundFirstBlack = test[i].indexOf('#');\n \n // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}\n if (foundFirstBlack === -1) {\n if (i === l1 - 1) {\n for (cs = 0; cs <= l2; cs++) {\n closeForS.add(cs)\n }\n }\n i++;\n continue;\n }\n else {found[i] = [foundFirstBlack]}\n \n \n // if (NOTFOUNDBLACK) {N = -1; break;}\n \n FOUNDBLACK = true;\n \n const foundLastBlack = test[i].lastIndexOf('#');\n found[i].push(foundLastBlack);\n \n if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}\n \n const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);\n if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}\n \n if (found[i - 1] !== undefined) {\n for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {\n if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)\n }\n }\n \n if (\n found[i - 1] === undefined ||\n (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) || \n (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])\n ) {\n N++;\n }\n \n if (i === l1 -1) {\n for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {\n closeForS.add(cs)\n }\n }\n \n i++;\n }\n \n \n if (\n (\n (Object.keys(found).length !== l1 && closeForS.size === l2) || \n (Object.keys(found).length === l1 && closeForS.size !== l2)\n ) && FOUNDBLACK\n ) {\n N = -1;\n }\n \n\n process.stdout.write(N.toString());\n});"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines1 = 0, blankLines2 = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) {\n if (rc) {\n blankLines1 ++;\n } else {\n blankLines2 ++;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif ((blankLines1 === 0 && blankLines2 === 0) || (blankLines1 > 1 && blankLines2 > 1)) output = -1;\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n if (g === '#') t2 = 1;\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 && output !== 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fill = function(y, x) {\n var fillStack = [];\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 || grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 && output === 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 && output !== 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output); //"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n for (var x = 0; x < size[1]; x ++) {\n grid2.push(0); // empty\n }\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid2[y][x] === 0) {\n grid2[y][x] = 1;\n if (size[0] > x + 1) recur(x + 1, y);\n if (1 <= x) recur(x - 1, y);\n if (size[1] > y + 1) recur(x, y + 1);\n if (1 <= y) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n if ('#.# #..# #...# #....# #.....# #......# #.......#'.includes(grid[y])) {\n output = -1;\n break;\n }\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);//"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 || grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 && output === 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 && output === 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines1 = 0, blankLines2 = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) {\n if (rc) {\n blankLines1 ++;\n } else {\n blankLines2 ++;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif ((blankLines1 !== 0 || blankLines2 !== 0) || (blankLines1 > 1 && blankLines2 > 1)) output = -1;\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines1 = 0, blankLines2 = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) {\n if (rc) {\n blankLines1 ++;\n } else {\n blankLines2 ++;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif ((blankLines1 !== 0 || blankLines2 !== 0) && (blankLines1 <= 1 && blankLines2 <= 1)) output = -1;\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n for (var x = 0; x < size[1]; x ++) {\n grid2.push(0); // empty\n }\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid[y][x] === 0) {\n grid[y][x] = 1;\n if (size[0] > x + 1) recur(x + 1, y);\n if (1 <= x) recur(x - 1, y);\n if (size[1] > y + 1) recur(x, y + 1);\n if (1 <= y) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\n// rule 3 violation test\n/*for (var y = 0; y < size[0]; y ++) {\n var test = 0; //\n for (var x = 0; x < size[1]; x ++) {\n if (grid[y][x] === '#') {\n if (test === 0) {\n test = 1; // hit black tile\n } else {\n output = -1;\n }\n } else if (test === 1) {\n test = 2; // hit white tile\n }\n }\n}*/\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) blankLines ++;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif (blankLines === 1) output = -1;\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n for (var x = 0; x < size[1]; x ++) {\n grid2.push(0); // empty\n }\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid[y][x] === 0) {\n grid[y][x] = 1;\n if (size[0] > x + 1) recur(x + 1, y);\n if (1 <= x) recur(x - 1, y);\n if (size[1] > y + 1) recur(x, y + 1);\n if (1 <= y) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\n// rule 3 violation test\nfor (var y = 0; y < size[0]; y ++) {\n var test = 0; //\n for (var x = 0; x < size[1]; x ++) {\n if (grid[y][x] === '#') {\n if (test === 0) {\n test = 1; // hit black tile\n } else {\n output = -1;\n }\n } else if (test === 1) {\n test = 2; // hit white tile\n }\n }\n}\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid2[y][x] === 0) {\n grid2[y][x] = 1;\n if (size[1] > x + 1) recur(x + 1, y);\n if (x - 1 >= 0) recur(x - 1, y);\n if (size[0] > y + 1) recur(x, y + 1);\n if (y - 1 >= 0) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t === 0 || output === 0) output = -1;\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar fillStack = [];\nvar fill = function(y, x) {\n fillStack.push([y, x]);\n while(fillStack.length > 0) {\n var t = fillStack.pop();\n y = t[0];\n x = t[1];\n if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;\n if (grid2[y][x] === 1 || grid[y][x] === '.') continue;\n grid2[y][x] = 1;\n fillStack.push([y + 1, x]);\n fillStack.push([y - 1, x]);\n fillStack.push([y, x + 1]);\n fillStack.push([y, x - 1]);\n }\n}\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (grid2[y][x] === 0 && grid[y][x] === '#') {\n output ++;\n fill(y, x);\n }\n }\n}\n\nvar blankLines1 = 0, blankLines2 = 0;\nvar check = function(rc, n) {\n var t = 0;\n var t2 = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') {\n t = 1;\n t2 = 1;\n }\n break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n }\n break;\n }\n }\n if (t2 === 0 && output !== 0) {\n if (rc) {\n blankLines1 ++;\n } else {\n blankLines2 ++;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nif ((blankLines1 !== 0 || blankLines2 !== 0) || !(blankLines1 > 1 && blankLines2 > 1)) output = -1;\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid2[y][x] === 0) {\n grid2[y][x] = 1;\n if (size[1] > x + 1) recur(x + 1, y);\n if (x - 1 >= 0) recur(x - 1, y);\n if (size[0] > y + 1) recur(x, y + 1);\n if (y - 1 >= 0) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\nvar check = function(rc, n) {\n var t = 0;\n for (var i = 0; i < (rc ? size[1] : size[0]); i ++) {\n var g = rc ? grid[n][i] : grid[i][n];\n switch(t) {\n case 0: if (g === '#') t = 1; break;\n case 1: if (g === '.') t = 2; break;\n case 2:\n if (g === '#') {\n output = -1;\n break;\n }\n break;\n }\n }\n};\n\nfor (var y = 0; y < size[0] && output !== -1; y ++)\n check(true, y);\nfor (var x = 0; x < size[1] && output !== -1; x ++)\n check(false, x);\n\nprint(output);"}, {"source_code": "var size = readline().split(' ').map(x => parseInt(x));\nvar grid = [], grid2 = [];\nfor (var y = 0; y < size[0]; y ++) {\n grid.push(readline());\n grid2.push([]);\n for (var x = 0; x < size[1]; x ++)\n grid2[y].push(0);\n}\n\nvar recur = function(x, y) {\n if (grid[y][x] === '#' && grid2[y][x] === 0) {\n grid2[y][x] = 1;\n if (size[0] > x + 1) recur(x + 1, y);\n if (1 <= x) recur(x - 1, y);\n if (size[1] > y + 1) recur(x, y + 1);\n if (1 <= y) recur(x, y - 1);\n return true;\n }\n return false;\n};\n\nvar output = 0;\nfor (var y = 0; y < size[0]; y ++) {\n for (var x = 0; x < size[1]; x ++) {\n if (recur(x, y)) output ++;\n }\n}\n\nprint(output);"}], "src_uid": "7898b8258297a6cde8fecb1079172e10"} {"source_code": "const MEMORY = [];\nlet MEMORY_INDEX = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n for (let i = 0; i < T; ++i) {\n let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));\n if (str + exp <= int) {\n print(0);\n continue;\n }\n let maxStr = str + exp;\n let minStr = Math.max((str + exp + int + 2) >> 1, str);\n print(maxStr - minStr + 1);\n }\n}\n", "positive_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var str = input[0];\n var int = input[1];\n var exp = input[2];\n \n var s = str+int+exp;\n var maxStr = str + exp;\n var minStr = Math.max(str, (s >> 1) + 1);\n var res = 0;\n if (maxStr >= minStr) {\n res = maxStr - minStr + 1;\n }\n \n pr(res);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => {\n i += c;\n});\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n const lines = i.split(EOL);\n for (let i = 1; i < lines.length; i++) {\n const parts = lines[i].split(' ');\n if (parts.length === 3) {\n console.log(creating(parseInt(parts[0], 10), parseInt(parts[1], 10), parseInt(parts[2], 10)));\n }\n }\n});\n\nfunction creating(str, int, exp) {\n if (str + exp <= int) return 0;\n const diff = str + exp - int;\n return diff % 2 === 0 ? Math.min(Math.floor(diff / 2), exp + 1) : Math.min(1 + (Math.floor(diff / 2)), exp + 1);\n}"}, {"source_code": "'use strict';\nconst io = (function() {\n process.stdin.resume(); process.stdin.setEncoding('utf-8');\n let inputString = '', currentLine = 0, curTok = 0, input = [];\n function _check() { if (currentLine >= input.length) throw 'EOF!'; }\n process.stdin.on('data', data => { inputString += data; });\n process.stdin.on('end', _ => {\n for (const i of inputString.split('\\n')) { input.push(i.split(' ')); }\n main(); \n });\n function nextLine() {\n _check();\n const ret = input[currentLine++].slice(curTok).join(' ');\n curTok = 0;\n return ret;\n }\n function next() {\n _check();\n while (curTok == input[currentLine].length) {\n currentLine++;\n curTok = 0;\n _check()\n }\n return input[currentLine][curTok++];\n }\n function nextInt() { return parseInt(next()); }\n return {\n nextLine: nextLine,\n next: next,\n nextInt: nextInt,\n };\n})();\n\nfunction poss(s, i, e, tar) {\n if (tar < s) return false;\n const need = tar - s;\n if (need > e) return false;\n s += need;\n i += e - need;\n return s > i;\n}\n\nfunction deal() {\n let s = io.nextInt();\n let i = io.nextInt();\n let e = io.nextInt();\n let ans = -1;\n if (s + e <= i) {\n ans = 0;\n } else {\n //lowest value that is possible\n let lo = 0; //not possible\n let hi = s+e; //possible\n while (lo < hi - 1) {\n let guess = Math.floor((lo + hi) / 2);\n if (poss(s, i, e, guess)) {\n hi = guess;\n } else {\n lo = guess;\n }\n }\n ans = s+e - hi + 1;\n }\n console.log(ans);\n}\n\nfunction main() {\n let T = io.nextInt();\n while (T > 0) {\n deal();\n T--;\n }\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\";\nprocess.stdin.on('data', function(chunk) {\n arr += chunk;\n});\n\nprocess.stdin.on('end', () => {\n arr = arr.split(\"\\n\");\n const noOfQueries = parseInt(arr.shift())\n for(let i = 0; i < noOfQueries; i++){\n // if exp === 0\n // else \n const queries = arr[i].split(' ');\n const str = parseInt(queries[0])\n const intellect = parseInt(queries[1])\n let exp = parseInt(queries[2])\n if(str == intellect){\n if(exp == 0){\n console.log(0)\n }\n else console.log(Math.ceil(exp / 2))\n }\n else if(str < intellect){\n if(intellect - str >= exp) console.log(0)\n else{\n exp = exp - intellect + str\n console.log(Math.ceil(exp / 2))\n }\n }\n else{\n if(str - intellect > exp) console.log(exp + 1)\n else if (str - intellect == exp) console.log(exp)\n else{\n const diff = str - intellect\n console.log(Math.ceil((exp - diff) / 2) + diff) \n }\n }\n }\n})"}], "negative_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var str = input[0];\n var int = input[1];\n var exp = input[2];\n \n var s = str+int+exp;\n var minStr = (s >> 1) + 1;\n var maxInt = s - minStr;\n \n var freeInt = maxInt - int + 1;\n \n pr(freeInt > 0 ? freeInt : 0);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf8')\nlet arr = \"\";\nprocess.stdin.on('data', function(chunk) {\n arr += chunk;\n});\n\nprocess.stdin.on('end', () => {\n arr = arr.split(\"\\n\");\n const noOfQueries = parseInt(arr.shift())\n for(let i =0; i < noOfQueries; i++){\n // if exp === 0\n // else \n const queries = arr[i].split(' ');\n const str = parseInt(queries[0])\n const int = parseInt(queries[1])\n let exp = parseInt(queries[2])\n if(str == int){\n if(exp == 0){\n console.log(0)\n }\n else console.log(Math.ceil(exp / 2))\n }\n else if(str < int){\n if(int - str >= exp) console.log(0)\n else{\n exp = exp - int + str\n console.log(Math.ceil(exp / 2))\n }\n }\n else{\n exp = exp + str - int\n console.log(Math.ceil(exp / 2))\n }\n }\n})"}, {"source_code": "const MEMORY = [];\nlet MEMORY_INDEX = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n for (let i = 0; i < T; ++i) {\n let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));\n let maxDiff = str + exp - int + 1;\n if (maxDiff <= 1) {\n print(0);\n } else {\n print((maxDiff >> 1));\n }\n }\n}\n"}, {"source_code": "const MEMORY = [];\nlet MEMORY_INDEX = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n for (let i = 0; i < T; ++i) {\n let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));\n if (str + exp <= int) {\n print(0);\n continue;\n }\n let maxStr = str + exp;\n let minStr = (str + exp + int + 2) >> 1;\n print(maxStr - minStr + 1);\n }\n}\n"}], "src_uid": "0816295355375a2d3f1cd45852b86360"} {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{Object.defineProperty(e,\"__esModule\",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// import { gcd } from './numberTheory'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = a.max()\n// \n// let r = -1\n// \n// for (let x of a) {\n// if (x == m) {\n// continue\n// }\n// if (r == -1) {\n// r = m - x\n// continue\n// }\n// r = gcd(m - x, r)\n// }\n// \n// let s = 0\n// \n// for (let x of a) {\n// s += (m - x) / r\n// }\n// \n// io.puts(s + \" \" + r)\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)", "positive_code": [{"source_code": "'use strict'\n \nconst n = parseInt(readline());\nlet m = readline().split(' ').map(Number);\n \nconst gcd = (a,b) => {\n if (a < b) { const c = a; a = b; b = c; }\n while(b) { const c = a % b; a = b; b = c; }\n return a;\n};\n \nm = m.sort((a, b) => b - a);\nconst d = m.slice(1).map(i => m[0] - i).filter(Boolean);\nconst z = d.slice(1).reduce((r, i) => gcd(r, i), d[0]);\nconst y = d.reduce((r, i) => r + i, 0) / z;\nwrite(y + ' ' + z);"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{Object.defineProperty(e,\"__esModule\",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// numberTheory.ts\n\n// function gcd(a: number, b: number) {\n// if (b == 0) {\n// return a\n// }\n// \n// return gcd(b, a % b)\n// }\n// \n// export { gcd }\n\n// import './array'\n// \n// import io from './io'\n// import { gcd } from './numberTheory'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = a.max()\n// \n// let r = -1\n// \n// for (let x of a) {\n// if (x == m) {\n// continue\n// }\n// if (r == -1) {\n// r = m - x\n// continue\n// }\n// r = gcd(m - x, r)\n// }\n// \n// let s = 0\n// \n// for (let x of a) {\n// s += (m - x) / r\n// }\n// \n// io.puts(s + \" \" + r)\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(p){if(s=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{i+=t})),process.stdin.on(\"end\",(e=>{s=i.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{Object.defineProperty(e,\"__esModule\",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// import { gcd } from './numberTheory'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = a.max()\n// \n// let r = m\n// \n// for (let x of a) {\n// r = gcd(x, r)\n// }\n// \n// let s = 0\n// \n// for (let x of a) {\n// s += (m - x) / r\n// }\n// \n// io.puts(s + \" \" + r)\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}, {"source_code": "'use strict'\n\nconst n = parseInt(readline());\nlet m = readline().split(' ').map(Number);\n\nconst gcd = (a,b) => {\n if (a < b) { const c = a; a = b; b = a; }\n while(b) { const c = a % b; a = b; b = c; }\n return a;\n};\n\nm = m.sort((a, b) => b - a);\nconst d = m.slice(1).map(i => m[0] - i).filter(Boolean);\nconst z = gcd(d[0], d[d.length - 1]);\nconst y = d.reduce((r, i) => r + i, 0) / z;\nwrite(y + ' ' + z);"}, {"source_code": "'use strict'\n \nconst n = parseInt(readline());\nlet m = readline().split(' ').map(Number);\n \nconst gcd = (a,b) => {\n if (a < b) { const c = a; a = b; b = c; }\n while(b) { const c = a % b; a = b; b = c; }\n return a;\n};\n \nm = m.sort((a, b) => b - a);\nconst d = m.slice(1).map(i => m[0] - i).filter(Boolean);\nconst z = gcd(d[0], d[d.length - 1]);\nconst y = d.reduce((r, i) => r + i, 0) / z;\nwrite(y + ' ' + z);"}], "src_uid": "ca7de8440f5bbbe75e8b93654ce75cd3"} {"source_code": "var nxo = readline().split(' ').map(Number);\nvar n = nxo[0];\nvar x0 = nxo[1];\nvar x1 = 0;\nvar x2 = 1100;\nfor (var i=0; i a-b );\n\tif (l[0] > x1) x1 = l[0];\n\tif (l[1] < x2) x2 = l[1];\n}\nif (x2-x1<0) print(-1);\nelse if (x0-x1>=0 && x2-x0>=0) print(0);\nelse {\n\tprint ( Math.min( Math.abs(x0-x1), Math.abs(x0-x2) ) );\n}\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar segmentNum = integers[0], startPos = integers[1];\n\n\tvar cover = new Array(1001);\n\tfor (var i = 0; i <= 1000; i += 1) {\n\t\tcover[i] = 0;\n\t}\n\n\tfor (var i = 0; i < segmentNum; i += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tvar a = Math.min(integers[0], integers[1]);\n\t\tvar b = Math.max(integers[0], integers[1]);\n\t\tfor (var j = a; j <= b; j += 1) {\n\t\t\tcover[j] += 1;\n\t\t}\n\t}\n\n\tvar best = -1;\n\n\tfor (var i = startPos; i >= 0; i -= 1) {\n\t\tif (cover[i] == segmentNum) {\n\t\t\tbest = startPos-i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (var i = startPos; i <= 1000; i += 1) {\n\t\tif (cover[i] == segmentNum && (best === -1 || i-startPos < best)) {\n\t\t\tbest = i-startPos;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tprint(best);\n}\n\nmain();\n"}, {"source_code": "'use strict'\n\nlet lll = readline().split(' ')\nconst N = lll[0]\nconst X = lll[1]\n\nvar spos = []\n\nwhile (lll = readline()) spos.push(lll.split(' ').map(v => +v))\n\nspos = spos.map(s => s[0] < s[1] ? s : [s[1], s[0]])\n\nlet p = spos.reduce((p, s) => [Math.max(p[0], s[0]), Math.min(p[1], s[1])])\n\nif (p[0] > p[1]) {\n print(-1)\n} else {\n if (p[0] <= X && X <= p[1]) {\n print(0)\n } else if (p[0] > X){\n print(p[0] - X)\n } else {\n print(X - p[1])\n }\n}"}], "negative_code": [{"source_code": "'use strict'\n\nlet lll = readline().split(' ')\nconst N = lll[0]\nconst X = lll[1]\n\nvar spos = []\n\nwhile (lll = readline()) spos.push(lll.split(' ').map(v => +v))\n\nspos = spos.map(s => s[0] < s[1] ? s : [s[1], s[0]])\n\nlet p = spos.reduce((p, s) => [Math.max(p[0], s[0]), Math.min(p[1], s[1])])\n\nif (p[0] > p[1]) {\n print(-1)\n} else {\n if (p[0] < X && X < p[1]) {\n print(0)\n } else if (p[0] > X){\n print(p[0] - X)\n } else {\n print(X - p[1])\n }\n}"}], "src_uid": "3c066bad8ee6298b318bf0f4521c7c45"} {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let s = readline();\n LT({n, s});\n // PROCESSING:\n let D = [new Array(n).fill(0), new Array(n).fill(0)];\n let C = [new Array(n).fill(0), new Array(n).fill(0)];\n let cost = (want, pos)=>+s[pos]==want ? 0 : 1;\n // D[ends with][pos]\n for (let i=1; i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let ans = 0\n let count = 0\n let p\n for (let i = 0; i < n; i += 2) {\n const a = str[i]\n const b = str[i + 1]\n if (a === b) {\n if (a === p) {\n //\n } else {\n count++\n p = a\n }\n } else {\n //\n ans++\n }\n }\n return ans + ' ' + Math.max(count, 1)\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, s)=>{\n let result = 0;\n\n let last = -1;\n let segs = 0;\n\n for (let i = 0; i < n; i += 2) {\n if (s[i] !== s[i + 1]) result++;\n else {\n if (s[i] !== last) {\n segs++;\n last = s[i];\n }\n }\n }\n if (!segs) segs = 1;\n\n return `${result} ${segs}`;\n\n\n // let segs = [];\n // let length = 1;\n // let cur = s[0];\n\n // for (let i = 1; i < n; i++) {\n // if (s[i] !== cur) {\n // segs.push([length, cur]);\n // length = 1;\n // cur = s[i];\n // } else {\n // length++;\n // }\n // }\n // segs.push([length, cur]);\n // console.log(`DEBUG segs`, segs);\n\n // let m = segs.length;\n // for (let i = 0; i < m; i++) {\n // let [l, bit] = segs[i];\n // console.log(`DEBUG i ${i} l ${l} bit`, bit);\n // if (l % 2 === 0) continue;\n // let sumSame = 0; let sumDif = 0;\n // for (let j = i + 1; j < m; j++) {\n // let [lj, bitj] = segs[j];\n // console.log(`DEBUG j ${j} lj ${lj} bitj`, bitj);\n // if (lj % 2 === 0) {\n // if (bitj === bit) sumSame += lj;\n // else sumDif += lj;\n // } else {\n // if (bitj === bit) {\n // result += Math.min(sumDif, sumSame + 2);\n // } else {\n // result += Math.min(sumDif, sumSame) + 1;\n // }\n // console.log(`DEBUG result`, result);\n // i = j;\n // break;\n // }\n // }\n // }\n\n // return result;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n // let a = ra();\n out.push(calc(n, s));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar t = +readline();\r\nvar _loop_1 = function (i) {\r\n var n = +readline();\r\n var a = readline().split('').map(function (v) { return +v; });\r\n function f(cur) {\r\n var count = 0;\r\n var changes = 1;\r\n for (var i_1 = 0; i_1 < n / 2; i_1++) {\r\n if (a[i_1 * 2] !== a[i_1 * 2 + 1]) {\r\n count += 1;\r\n }\r\n else {\r\n if (cur !== a[i_1 * 2]) {\r\n cur = a[i_1 * 2];\r\n changes += 1;\r\n }\r\n }\r\n }\r\n return [count, changes];\r\n }\r\n var ans = [f(0), f(1)];\r\n print(ans[0][1] < ans[1][1] ? \"\".concat(ans[0][0], \" \").concat(ans[0][1]) : \"\".concat(ans[1][0], \" \").concat(ans[1][1]));\r\n};\r\nroot: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var i = _a[_i];\r\n _loop_1(i);\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let s = -1, p\n const ps = []\n for (let i = 0; i < n; i++) {\n const x = str[i]\n if (x !== p) {\n if (s >= 0) {\n ps.push(str.slice(s, i))\n }\n s = i\n p = x\n }\n }\n if (s < n) {\n ps.push(str.slice(s, n))\n }\n// console.log(ps)\n let i = 0\n let ans = 0\n let count = 0\n let add = 0\n let zero = 0\n let prev\n while (i < ps.length) {\n const x = ps[i].length + add\n if (x & 1) {\n ans++\n if (x === 1) {\n add = 1\n zero = 1\n } else if (i + 1 < ps.length && ps[i + 1].length <= 2) {\n add = -1\n } else {\n add = 1\n }\n } else {\n add = 0\n if (x === 0) {\n zero = 1\n } else {\n zero = 0\n }\n }\n //\n // console.log(zero, count)\n if (zero) {\n zero = 0\n } else if (ps[i][0] !== prev) {\n count++\n prev = ps[i][0]\n }\n //\n i++\n }\n return ans + ' ' + count\n}\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let s = readline();\n LT({n, s});\n // PROCESSING:\n let D = [new Array(n).fill(0), new Array(n).fill(0)];\n let C = [new Array(n).fill(0), new Array(n).fill(0)];\n let cost = (want, pos)=>+s[pos]==want ? 0 : 1;\n // D[ends with][pos]\n for (let i=1; i ipt += s)\nprocess.stdin.on('end', () => {\n const ils = ipt.split(EOL).slice(0, -1)\n const [n, m, x] = ils.shift().split(' ').map(v => parseInt(v))\n const X = x * x\n const T = ils.pop()\n ils.pop()\n const K = []\n const L = {}\n const D = {}\n const S = []\n for (let i = 0; i < ils.length; i++) {\n K[i] = ils[i].split('')\n }\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n let l = K[i][j]\n if (l == 'S') S.push([i, j])\n else {\n L[l] = L[l] || []\n L[l].push([i, j])\n D[l] = false\n }\n }\n }\n for (let l in L) {\n let C = L[l]\n for (let j = 0; j < C.length; j++) {\n const [lx, ly] = C[j]\n\n D[l] = D[l] || S.some(s => Math.pow(s[0] - lx, 2) + Math.pow(s[1] - ly, 2) <= X)\n }\n }\n \n let count = 0\n let isS = S.length > 0\n for (let i = 0; i < T.length; i++) {\n let l = T[i]\n if (l in L) continue\n l = l.toLowerCase()\n if (l in L && isS) count += !D[l]\n else return console.log(-1)\n }\n console.log(count)\n})", "positive_code": [{"source_code": "var getVals = function() {return readline().split(' '); };\n\nvar getNums = function() {\n\treturn readline().split(' ').map(function(a) {return parseInt(a)});\n};\n\n//11-15\n\nvar inp = getNums();\nvar n = inp[0];\nvar m = inp[1];\nvar x = inp[2];\n\nvar shifts = [];\nvar keys = {};\nvar keysArr = [];\nvar i, j;\nvar num;\n\n//Get shifts and keysArr\nfor(i = 0; i < n; i++) {\n\tvar str = readline();\n\tfor (j = 0; j < m; j++) {\n\t\tvar key = str[j];\n\t\tif (key === 'S') {\n\t\t\tshifts.push({x:i, y:j});\n\t\t} else {\n\t\t\tkeysArr.push({x:i, y:j, k: key})\n\t\t}\n\t}\n}\n\n//Get n and string\nvar finalN = parseInt(readline());\nvar finalStr = readline();\n\nfunction getDistance(x1, y1, x2, y2) {\n\treturn Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n}\n\n//get keys object\nkeysArr.forEach(function (key) {\n\tvar minS;\n\tif (shifts.length) {\n\t\tminS = getDistance(key.x, key.y, shifts[0].x, shifts[0].y);\n\t\tshifts.forEach(function (shift) {\n\t\t\tminS = Math.min(minS, getDistance(key.x, key.y, shift.x, shift.y));\n\t\t})\n\t} else {\n\t\tminS = -1;\n\t}\n\tif (keys[key.k]) {\n\t\tkeys[key.k] = Math.min(minS, keys[key.k]);\n\t} else {\n\t\tkeys[key.k] = minS;\n\t}\n});\n\n//get function final text\nfunction res() {\n\tvar shiftCount = 0;\n\tfor(var z = 0; z < finalN; z++) {\n\t\tvar finalK = finalStr[z];\n\t\tif (finalK === finalK.toLocaleLowerCase()) {\n\t\t\tif (!keys[finalK]) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t} else {\n\t\t\tfinalK = finalK.toLocaleLowerCase();\n\t\t\tif (!keys[finalK]) {\n\t\t\t\treturn -1;\n\t\t\t} else {\n\t\t\t\tif (keys[finalK] === -1) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\tif (keys[finalK] > x) {\n\t\t\t\t\t\tshiftCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn shiftCount;\n}\n\nprint(res());"}], "negative_code": [{"source_code": "var getVals = function() {return readline().split(' '); };\n\nvar getNums = function() {\n\treturn readline().split(' ').map(function(a) {return parseInt(a)});\n};\n\n//11-15\n\nvar inp = getNums();\nvar n = inp[0];\nvar m = inp[1];\nvar x = inp[2];\n\nvar shifts = [];\nvar keys = {};\nvar keysArr = [];\nvar i, j;\nvar num;\n\n//Get shifts and keysArr\nfor(i = 0; i < n; i++) {\n\tvar str = readline();\n\tfor (j = 0; j < m; j++) {\n\t\tvar key = str[j];\n\t\tif (key === 'S') {\n\t\t\tshifts.push({x:i, y:j});\n\t\t} else {\n\t\t\tkeysArr.push({x:i, y:j, k: key})\n\t\t}\n\t}\n}\n\n//Get n and string\nvar finalN = parseInt(readline());\nvar finalStr = readline();\n\nfunction getDistance(x1, y1, x2, y2) {\n\treturn Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n}\n\n//get keys object\nkeysArr.forEach(function (key) {\n\tvar minS;\n\tif (shifts.length) {\n\t\tminS = getDistance(key.x, key.y, shifts[0].x, shifts[0].y);\n\t\tshifts.forEach(function (shift) {\n\t\t\tminS = Math.min(minS, getDistance(key.x, key.y, shift.x, shift.y));\n\t\t})\n\t} else {\n\t\tminS = -1;\n\t}\n\tkeys[key.k] = minS;\n});\n\n//get function final text\nfunction res() {\n\tvar shiftCount = 0;\n\tfor(var z = 0; z < finalN; z++) {\n\t\tvar finalK = finalStr[z];\n\t\tif (finalK === finalK.toLocaleLowerCase()) {\n\t\t\tif (!keys[finalK]) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t} else {\n\t\t\tfinalK = finalK.toLocaleLowerCase();\n\t\t\tif (!keys[finalK]) {\n\t\t\t\treturn -1;\n\t\t\t} else {\n\t\t\t\tif (keys[finalK] === -1) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\tif (keys[finalK] > x) {\n\t\t\t\t\t\tshiftCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn shiftCount;\n}\n\nprint(res());"}, {"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n const ils = ipt.split(EOL).slice(0, -1)\n const [n, m, x] = ils.shift().split(' ').map(v => parseInt(v))\n const X = x * x\n const T = ils.pop()\n ils.pop()\n const K = []\n const L = {}\n const D = {}\n const S = []\n for (let i = 0; i < ils.length; i++) {\n K[i] = ils[i].split('')\n }\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n let l = K[i][j]\n if (l == 'S') S.push([i, j])\n else {\n L[l] = L[l] || []\n L[l].push([i, j])\n D[l] = false\n }\n }\n }\n for (let l in L) {\n let C = L[l]\n for (let j = 0; j < C.length; j++) {\n const [lx, ly] = C[j]\n\n D[l] = S.some(s => Math.pow(s[0] - lx, 2) + Math.pow(s[1] - ly, 2) <= X)\n }\n }\n\n let count = 0\n let isS = S.length > 0\n for (let i = 0; i < T.length; i++) {\n let l = T[i]\n if (l in L) continue\n l = l.toLowerCase()\n if (l in L && isS) count += !D[l]\n else return console.log(-1)\n }\n console.log(count)\n})"}], "src_uid": "0870110338a84f76d4870d06dc9da2df"} {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n if(n == 1){\r\n print(2);\r\n }\r\n else if(n % 3 !== 0){\r\n print(parseInt(n / 3) + 1) ;\r\n }\r\n else{\r\n print((n / 3));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nlet currentLine = 0\r\nlet inputString = ''\r\n\r\nprocess.stdin.on('data', (raw_data) => {\r\n inputString += raw_data\r\n})\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((line) => {\r\n return line.trim()\r\n })\r\n main()\r\n})\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(' ').map(Number)\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(' ')\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt()\r\n for (let i = 0; i < T; ++i) {\r\n let n = readInt()\r\n\r\n let ans = 0\r\n if(n % 3 === 0){\r\n console.log(n / 3)\r\n } else if (n == 1){\r\n console.log(2)\r\n } else if(n == 2){\r\n console.log(1)\r\n } else{\r\n while(n % 3 !== 0){\r\n n-=2\r\n ans+=1\r\n }\r\n console.log(ans + n / 3)\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve()\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t=readline()\r\n while(t-->0){\r\n let n=parseInt(readline())\r\n let mod=n%3;\r\n if(n==1){\r\n console.log(2)\r\n continue\r\n }\r\n switch(mod){\r\n case 0:\r\n console.log(n/3)\r\n break\r\n case 1:\r\n case 2:\r\n console.log(Math.floor(n/3)+1)\r\n break\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = parseInt(readline(), 10);\r\n const modMap = {\r\n '0': 0,\r\n '1': 2,\r\n '2': 1,\r\n '3': 1,\r\n '4': 2,\r\n '5': 2\r\n };\r\n let six = Math.floor(n/6);\r\n let mod = modMap[n%6];\r\n let one = ((six * 2) + mod);\r\n let two = Infinity;\r\n if (n > 3) {\r\n let six2 = Math.floor((n-3)/6);\r\n let mod2 = modMap[(n-3)%6];\r\n two = ((six2 * 2) + mod2) + 1;\r\n }\r\n output(Math.min(one, two));\r\n }\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n if(n == 1){\n console.log(2);\n }else if(n % 3 === 0){\n console.log(n / 3);\n }else{\n console.log(Math.floor(n / 3) + 1);\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tif(N == 1){\r\n\t\t\tmyout(2);\r\n\t\t}else{\r\n\t\t\tmyout(Math.ceil(N / 3));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '', currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\r\nprocess.stdin.on('end', _ => { \r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main(); \r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n = +readLine();\r\n // const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n);\r\n console.log(result);\r\n }\r\n}\r\n\r\nfunction myFunc(n){\r\n if(n == 1) return 2;\r\n\r\n \r\n if(n % 3 == 0) return n/3;\r\n else return parseInt(n/3)+1\r\n\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "t = readline()\r\nwhile(t--) {\r\n n = readline();\r\n if(n==1) {\r\n print(2);\r\n continue;\r\n }\r\n else if(n===2 || n===3) {\r\n print(1);\r\n continue;\r\n }\r\n var ans = n/3;\r\n if(n%3)ans++;\r\n print(Math.trunc(ans));\r\n\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var value = parseInt(readline());\r\n var count = 0;\r\n if (value % 3 === 0)\r\n {\r\n count = value / 3;\r\n }\r\n else if (value % 3 === 2)\r\n {\r\n value -= 2;\r\n count++;\r\n count += (value / 3);\r\n }\r\n else \r\n {\r\n value -= 2;\r\n count = 2;\r\n if (value > 0)\r\n {\r\n value -= 2;\r\n count += (value / 3);\r\n }\r\n }\r\n print(count);\r\n}"}, {"source_code": "var t = +readline()\n\nfor (var i=0; i 2) ans = Math.ceil(n/3)\n print(ans)\n}"}, {"source_code": "T=readline()\r\nwhile(T--){\r\n n=readline()\r\n if(n==1) print(2)\r\n else print(parseInt((n-1)/3)+1)\r\n}"}, {"source_code": "var n;\r\n var thr, mod;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; t {\r\n inputString += raw_data\r\n})\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((line) => {\r\n return line.trim()\r\n })\r\n main()\r\n})\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(' ').map(Number)\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(' ')\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt()\r\n for (let i = 0; i < T; ++i) {\r\n let n = readInt()\r\n\r\n let ans = 0\r\n if(n % 3 === 0){\r\n console.log(n / 3)\r\n } else{\r\n while(n % 3 !== 0){\r\n n-=2\r\n ans+=1\r\n }\r\n console.log(ans + n / 3)\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve()\r\n}\r\n"}, {"source_code": "process.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nlet currentLine = 0\r\nlet inputString = ''\r\n\r\nprocess.stdin.on('data', (raw_data) => {\r\n inputString += raw_data\r\n})\r\n\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((line) => {\r\n return line.trim()\r\n })\r\n main()\r\n})\r\n\r\nfunction readInt() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readString() {\r\n return inputString[currentLine++]\r\n}\r\n\r\nfunction readArrayInt() {\r\n return inputString[currentLine++].split(' ').map(Number)\r\n}\r\n\r\nfunction readArray() {\r\n return inputString[currentLine++].split(' ')\r\n}\r\n\r\nfunction solve() {\r\n const T = readInt()\r\n for (let i = 0; i < T; ++i) {\r\n let n = readInt()\r\n\r\n let ans = 0\r\n if(n % 3 === 0){\r\n console.log(n / 3)\r\n } else{\r\n while(n % 3 !== 0){\r\n n-=2\r\n ans+=1\r\n }\r\n console.log(ans)\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve()\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = parseInt(readline(), 10);\r\n const modMap = {\r\n '0': 0,\r\n '1': 2,\r\n '2': 1,\r\n '3': 1,\r\n '4': 2,\r\n '5': 2\r\n };\r\n let six = Math.floor(n/6);\r\n let mod = modMap[n%6];\r\n output(((six * 2) + mod));\r\n }\r\n}\r\n"}, {"source_code": "t = readline()\r\nwhile(t--) {\r\n n = readline();\r\n if(n==1) {\r\n print(2);\r\n continue;\r\n }\r\n else if(n===2 || n===3) {\r\n print(1);\r\n continue;\r\n }\r\n var ans = n/3;\r\n if(n%3)ans++;\r\n print(ans);\r\n\r\n}"}, {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n if(n % 3 === 0){\r\n print(n / 3);\r\n }\r\n else if(n % 3 == 1){\r\n print(parseInt(n / 3) + 2);\r\n }\r\n else if(n % 3 == 2){\r\n print(parseInt(n / 3) + 1);\r\n }\r\n}\r\n"}, {"source_code": "var t = readline();\r\nfor(var i = 0 ; i < t ; i++){\r\n var n = readline();\r\n if(n % 3 === 0){\r\n print(n / 3);\r\n }\r\n else if(n % 2 === 0){\r\n print(n / 2);\r\n }\r\n else if(n % 3 == 1){\r\n print(parseInt(n / 3) + 2);\r\n }\r\n else if(n % 3 == 2){\r\n print(parseInt(n / 3) + 1);\r\n }\r\n}\r\n"}], "src_uid": "208e285502bed3015b30ef10a351fd6d"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, k, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n n = Number(n);\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n arr.sort((a, b) => {\r\n if (a <= b) return -1;\r\n else return 1;\r\n });\r\n let dif = [],\r\n cnt = 1;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i + 1] - arr[i] > x) {\r\n dif.push(arr[i + 1] - arr[i]);\r\n cnt++;\r\n }\r\n }\r\n if (dif.length) {\r\n dif.sort((a, b) => {\r\n if (a <= b) return -1;\r\n else return 1;\r\n });\r\n for (let i = 0; i < dif.length; i++) {\r\n let j = dif[i] % x === 0n ? dif[i] / x - 1n : dif[i] / x;\r\n if (j > k) break;\r\n else {\r\n cnt--;\r\n k -= j;\r\n }\r\n }\r\n console.log(cnt);\r\n } else console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "// --------------- PRE-DEFINED START ---------------\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nconst nextLine = () => {\r\n const nextLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line.trim();\r\n }\r\n }());\r\n return (async () => {\r\n const next = await nextLineGen.next();\r\n return next.value;\r\n })();\r\n};\r\n\r\nconst nextNum = async () => {\r\n const line = await nextLine();\r\n return Number(line);\r\n};\r\n\r\nconst nextNumArr = async () => {\r\n const line = await nextLine();\r\n return line.split(\" \").map((num) => Number(num));\r\n};\r\n\r\nconst nextBigIntArr = async () => {\r\n const line = await nextLine();\r\n return line.split(\" \").map((num) => BigInt(num));\r\n};\r\n\r\nfunction sortAsc(a, b) {\r\n if (a < b) return -1;\r\n if (a > b) return 1;\r\n return 0;\r\n}\r\n// --------------- PRE-DEFINED END ---------------\r\n\r\nconst main = async () => {\r\n let [n, k, x] = await nextBigIntArr();\r\n let arr = await nextBigIntArr();\r\n\r\n let gaps = [];\r\n\r\n arr.sort(sortAsc);\r\n for (let i = 1; i < n; i++) {\r\n const tmp = arr[i] - arr[i-1];\r\n if (tmp > x) gaps.push((tmp / x) - (tmp % x === 0n ? 1n : 0n));\r\n }\r\n\r\n gaps.sort(sortAsc);\r\n let res = gaps.length + 1;\r\n for (let i = 0; i < gaps.length; i++) {\r\n if (gaps[i] > k) break;\r\n k -= gaps[i];\r\n res -= 1;\r\n }\r\n\r\n console.log(res);\r\n};\r\n\r\nmain();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let strn, strk, strx;\r\n let n, k, x;\r\n [n, k, x] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n let bigcmp = function(a,b) {\r\n const zero = BigInt(0);\r\n const diff = a-b;\r\n if (diff < zero)\r\n return -1;\r\n else if (diff > zero)\r\n return 1;\r\n else return 0;\r\n }\r\n a.sort((a,b) => (a-b));\r\n const diffs = [];\r\n for(let i = 1; i < n; i++) {\r\n if (a[i] - a[i-1] > x) {\r\n diffs.push(a[i]-a[i-1]);\r\n }\r\n }\r\n diffs.sort((a,b)=>(a-b));\r\n let i;\r\n for(i = 0; i 0; i++) {\r\n let need = Math.floor((diffs[i] - 1) / x);\r\n if (need > k)\r\n break;\r\n else\r\n k -= need;\r\n }\r\n console.log(diffs.length - i + 1);\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var [n, k, x] = lines[l++].split(' ').map(BigInt);\n var arr = lines[l++].split(' ').map(BigInt);\n console.log(solve(n, k, x, arr))\n});\n\nfunction solve(n, k, x, arr) {\n const cp = (a, b) => {\n if (a < b) {\n return -1\n } else if (a > b) {\n return 1\n } else {\n return 0\n }\n }\n arr.sort(cp)\n\n const needs = []\n arr.forEach((item, i) => {\n if (i && item - arr[i - 1] > x) {\n const need = ceil((item - arr[i - 1]), x) - 1n\n needs.push(need)\n }\n })\n needs.sort(cp)\n\n let sum = 0n\n for (let i = 0; i < needs.length; i++) {\n if (sum + needs[i] > k) {\n return needs.length - i + 1\n }\n sum += needs[i]\n }\n return 1\n}\n\nfunction ceil(a, b) {\n const r = a % b\n return r ? (a - r) / b + 1n : a / b\n}\n"}, {"source_code": "function gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var nkx = readArray(BigInt);\r\n var n = Number(nkx[0]);\r\n var k = nkx[1];\r\n var x = nkx[2];\r\n var a = readArray(BigInt);\r\n a.sort(sortF);\r\n var ans = 1;\r\n var arr = [];\r\n for (var i = 1; i < n; i++) {\r\n var diff = a[i] - a[i - 1];\r\n if (diff > x) {\r\n ans++;\r\n arr.push((diff / x) - (diff % x === 0n ? 1n : 0n));\r\n }\r\n }\r\n arr.sort(sortF);\r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] > k) {\r\n break;\r\n }\r\n k -= arr[i];\r\n ans--;\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}));\r\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n});\r\nvar __importStar = (this && this.__importStar) || function (mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst fs = __importStar(require(\"fs\"));\r\n// import * as readline from 'readline'\r\n// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\r\n// const ask = (query: string) => new Promise((resolve) => rl.question(query, resolve))\r\n// // Don't forget `rl.close()`.\r\nconst INT = Math.floor;\r\nArray.prototype.last = function () {\r\n return this.length === 0 ? undefined : this[this.length - 1];\r\n};\r\nArray.prototype.isEmpty = function () {\r\n return this.length === 0;\r\n};\r\nconst less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);\r\nconst greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);\r\nconst bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));\r\nconst bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));\r\nconst bigIntAbs = (arg) => (arg < 0 ? -arg : arg);\r\nfunction read_stdin() {\r\n return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');\r\n}\r\nclass Input {\r\n constructor(str) {\r\n this.index = 0;\r\n this.inputs = (str ? str : read_stdin()).split(/\\s+/);\r\n }\r\n number() {\r\n return Number(this.inputs[this.index++]);\r\n }\r\n numbers(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(Number);\r\n }\r\n bigint() {\r\n return BigInt(this.inputs[this.index++]);\r\n }\r\n bigints(n) {\r\n return this.inputs.slice(this.index, (this.index += n)).map(BigInt);\r\n }\r\n word() {\r\n return this.inputs[this.index++];\r\n }\r\n words(n) {\r\n return this.inputs.slice(this.index, (this.index += n));\r\n }\r\n}\r\nfunction array(len, init) {\r\n return Array(len).fill(init);\r\n}\r\nfunction array2(h, w, init) {\r\n return array(h, 0).map(() => array(w, init));\r\n}\r\nfunction main() {\r\n const input = new Input();\r\n const N = input.number();\r\n const K = input.bigint();\r\n const X = input.bigint();\r\n const A = input.bigints(N);\r\n A.sort(less);\r\n let count = 1;\r\n const spans = [];\r\n for (let i = 1; i < N; i++) {\r\n if (A[i] - A[i - 1] > X) {\r\n count++;\r\n spans.push((A[i] - 1n - A[i - 1]) / X);\r\n }\r\n }\r\n spans.sort(less);\r\n let k = K;\r\n for (let i = 0; i < spans.length; i++) {\r\n if (k === 0n)\r\n break;\r\n const span = spans[i];\r\n if (span > k)\r\n break;\r\n count--;\r\n k -= span;\r\n }\r\n console.log(count);\r\n}\r\nmain();\r\n//# sourceMappingURL=aoj.js.map"}, {"source_code": "nkx = readline().split(' ');\r\nn = +nkx[0];\r\nk = +nkx[1];\r\nx = +nkx[2];\r\n\r\na = readline().split(' ').map(x => +x);\r\na.sort((o, p) => o - p);\r\n\r\ngF = [];\r\ngL = [];\r\n\r\nlastF = a[0];\r\nlastL = a[0];\r\n\r\nfor (i = 1; i < n; ++i) {\r\n if (a[i] - a[i - 1] <= x) {\r\n lastL = a[i];\r\n } else {\r\n gF.push(lastF);\r\n gL.push(lastL);\r\n\r\n lastF = a[i];\r\n lastL = a[i];\r\n }\r\n}\r\n\r\ngF.push(lastF);\r\ngL.push(lastL);\r\n\r\n\r\ndistances = [];\r\n\r\nfor (i = 1; i < gF.length; ++i) {\r\n distances.push(gF[i] - gL[i - 1]);\r\n}\r\n\r\ndistances.sort((o, p) => o - p);\r\n\r\nres = gF.length;\r\n\r\nfor (i = 0; i < distances.length; ++i) {\r\n dist = Math.ceil(distances[i] / x) - 1;\r\n\r\n if (dist <= k) {\r\n k -= dist;\r\n res -= 1;\r\n }\r\n}\r\n\r\nprint(res);\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => BigInt(x));\r\n\r\nfunction main () {\r\n\tlet [n, k, x] = rna();\r\n\tn = Number(n);\r\n\tconst a = rna();\r\n\r\n\t//a.sort((x, y) => x - y);\r\n\ta.sort((a ,b) => {\r\n\t\t\tif(a > b) {\r\n\t\t\treturn 1;\r\n\t\t\t} else if (a < b){\r\n\t\t\treturn -1;\r\n\t\t\t} else {\r\n\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\t});\r\n\r\n\tconst d = [];\r\n\tfor (let i = 0; i < n - 1; i++) {\r\n\t\tif (a[i+1] - a[i] > x) {\r\n\t\t\td.push(a[i+1] - a[i]);\r\n\t\t}\r\n\t}\r\n\r\n\td.sort((a ,b) => {\r\n\t\t\tif(a > b) {\r\n\t\t\treturn 1;\r\n\t\t\t} else if (a < b){\r\n\t\t\treturn -1;\r\n\t\t\t} else {\r\n\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\t});\r\n\r\n\tlet ans = d.length + 1;\r\n\tfor (const df of d) {\r\n\t\tk -= (df-1n)/x;\r\n\t\tif (k >= 0) ans--;\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\u00a0\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, k, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n n = Number(n);\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n arr.sort((a, b) => {\r\n if (a <= b) return -1;\r\n else return 1;\r\n });\r\n let dif = [],\r\n cnt = 1;\r\n for (let i = 0; i < n - 1; i++) {\r\n if (arr[i + 1] - arr[i] > x) {\r\n let j = arr[i + 1] - arr[i];\r\n if (j <= (k + 1n) * k) dif.push(j);\r\n cnt++;\r\n }\r\n }\r\n if (dif.length) {\r\n dif.sort((a, b) => {\r\n if (a <= b) return -1;\r\n else return 1;\r\n });\r\n for (let i = 0; i < dif.length; i++) {\r\n let j = dif[i] % x === 0n ? dif[i] / x - 1n : dif[i] / x;\r\n if (j > k) break;\r\n else {\r\n cnt--;\r\n k -= j;\r\n }\r\n }\r\n console.log(cnt);\r\n } else console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, k, x] = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n arr.sort((a, b) => {\r\n if (a - b <= 0n) return -1;\r\n else return 1;\r\n });\r\n let dif = [],\r\n cnt = 1;\r\n for (let i = 0n; i < n - 1n; i++) {\r\n if (arr[i + 1n] - arr[i] > x) {\r\n cnt++;\r\n dif.push(arr[i + 1n] - arr[i]);\r\n }\r\n }\r\n if (dif.length) {\r\n dif.sort((a, b) => {\r\n if (a - b <= 0n) return -1;\r\n else return 1;\r\n });\r\n for (let i = 0; i < dif.length; i++) {\r\n let j = dif[i] % x === 0 ? dif[i] / x - 1n : dif[i] / x;\r\n if (j > k) break;\r\n else {\r\n cnt--;\r\n k -= j;\r\n }\r\n }\r\n console.log(cnt);\r\n } else console.log(cnt);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, k, x] = rna();\r\n\tconst a = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tconst d = [];\r\n\tfor (let i = 0; i < n - 1; i++) {\r\n\t\tif (a[i+1] - a[i] > x) {\r\n\t\t\td.push(a[i+1] - a[i]);\r\n\t\t}\r\n\t}\r\n\r\n\td.sort((x, y) => x - y);\r\n\r\n\tlet ans = d.length + 1;\r\n\tfor (const df of d) {\r\n\t\tk -= Math.floor((df-1)/x);\r\n\t\tif (k >= 0) ans--;\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, k, x] = rna();\r\n\tconst a = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tconst d = [];\r\n\tfor (let i = 0; i < n - 1; i++) {\r\n\t\tif (a[i+1] - a[i] > x) {\r\n\t\t\td.push(a[i+1] - a[i]);\r\n\t\t}\r\n\t}\r\n\r\n\td.sort((x, y) => x - y);\r\n\r\n\tlet ans = d.length + 1;\r\n\tfor (const df of d) {\r\n\t\tk -= Math.floor(df/(x+1));\r\n\t\tif (k >= 0) ans--;\r\n\t}\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, k, x] = rna();\r\n\tlet a = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tlet d = [];\r\n\tfor (let i = 0; i < n - 1; i++)\r\n\t\td[i] = a[i + 1] - a[i];\r\n\r\n\td.sort((x, y) => x - y);\r\n\r\n\tlet ans = 1, klft = k;\r\n\tfor (let i = 0; i < d.length; i++) {\r\n\t\tif (d[i] > x) {\r\n\t\t\tconst req = Math.floor((d[i] - 1)/ x);\r\n\t\t\tif (klft >= req) klft -= req;\r\n\t\t\telse ans++;\r\n\t\t\t//console.log('i', i, d[i], x, 'req',req,'klft',klft,'ans',ans)\r\n\t\t}\r\n\t}\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, k, x] = rna();\r\n\tlet a = rna();\r\n\r\n\ta.sort((x, y) => x - y);\r\n\r\n\tlet d = [];\r\n\tfor (let i = 0; i < n - 1; i++)\r\n\t\td[i] = a[i + 1] - a[i];\r\n\r\n\td.sort((x, y) => x - y);\r\n\r\n\tlet ans = 1, klft = k;\r\n\tfor (let i = 0; i < d.length; i++) {\r\n\t\tif (d[i] > x) {\r\n\t\t\tconst req = Math.floor(d[i] / x);\r\n\t\t\tif (klft >= req) klft -= req;\r\n\t\t\telse ans++;\r\n\t\t}\r\n\t}\r\n\tconsole.log(ans);\r\n}\r\n\r\n"}, {"source_code": "// --------------- PRE-DEFINED START ---------------\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\n\r\nconst nextLine = () => {\r\n const nextLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line.trim();\r\n }\r\n }());\r\n return (async () => {\r\n const next = await nextLineGen.next();\r\n return next.value;\r\n })();\r\n};\r\n\r\nconst nextNum = async () => {\r\n const line = await nextLine();\r\n return Number(line);\r\n};\r\n\r\nconst nextNumArr = async () => {\r\n const line = await nextLine();\r\n return line.split(\" \").map((num) => Number(num));\r\n};\r\n\r\nconst nextBigIntArr = async () => {\r\n const line = await nextLine();\r\n return line.split(\" \").map((num) => BigInt(num));\r\n};\r\n// --------------- PRE-DEFINED END ---------------\r\n\r\nconst main = async () => {\r\n let [n, k, x] = await nextBigIntArr();\r\n let arr = await nextBigIntArr();\r\n\r\n let gaps = [];\r\n\r\n arr.sort((a, b) => a > b);\r\n for (let i = 1; i < n; i++) {\r\n const tmp = arr[i] - arr[i-1];\r\n if (tmp > x) gaps.push((tmp / x) - (tmp % x === 0n ? 1n : 0n));\r\n }\r\n\r\n gaps.sort((a, b) => a > b);\r\n let res = gaps.length + 1;\r\n for (let i = 0; i < gaps.length; i++) {\r\n if (gaps[i] > k) break;\r\n k -= gaps[i];\r\n res -= 1;\r\n }\r\n\r\n console.log(res);\r\n};\r\n\r\nmain();\r\n"}, {"source_code": "// --------------- PRE-DEFINED START ---------------\nconst rl = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst nextLine = () => {\n const nextLineGen = (async function* () {\n for await (const line of rl) {\n yield line.trim();\n }\n }());\n return (async () => {\n const next = await nextLineGen.next();\n return next.value;\n })();\n};\n\nconst nextNum = async () => {\n const line = await nextLine();\n return Number(line);\n};\n\nconst nextNumArr = async () => {\n const line = await nextLine();\n return line.split(\" \").map((num) => Number(num));\n};\n// --------------- PRE-DEFINED END ---------------\n\nconst main = async () => {\n let [n, k, x] = await nextNumArr();\n let arr = await nextNumArr();\n\n let gaps = [];\n\n arr.sort((a, b) => a - b);\n for (let i = 1; i < n; i++) {\n const tmp = arr[i] - arr[i-1];\n if (tmp > x) gaps.push(Math.floor((tmp + x - 1) / x) - 1);\n }\n\n gaps.sort((a, b) => a - b);\n let res = gaps.length + 1;\n for (let i = 0; i < gaps.length; i++) {\n if (gaps[i] > k) break;\n k -= gaps[i];\n res -= 1;\n }\n\n console.log(res);\n};\n\nmain();\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => ((await getLineGen.next()).value);\r\n})();\r\n\r\nlet solve = async () => {\r\n let strn, strk, strx;\r\n let n, k, x;\r\n [n, k, x] = (await getLine()).split(' ').map(num => parseInt(num));\r\n const a = (await getLine()).split(' ').map(num => parseInt(num));\r\n let bigcmp = function(a,b) {\r\n const zero = BigInt(0);\r\n const diff = a-b;\r\n if (diff < zero)\r\n return -1;\r\n else if (diff > zero)\r\n return 1;\r\n else return 0;\r\n }\r\n a.sort((a,b) => (a-b));\r\n const diffs = [];\r\n for(let i = 1; i < n; i++) {\r\n if (a[i] - a[i-1] > x) {\r\n diffs.push(a[i]-a[i-1]);\r\n }\r\n }\r\n diffs.sort((a,b)=>(a-b));\r\n let i;\r\n for(i = 0; i 0; i++) {\r\n let need = ((diffs[i] - 1) / x);\r\n if (need > k)\r\n break;\r\n else\r\n k -= need;\r\n }\r\n console.log(diffs.length - i + 1);\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var l = 0;\n var [n, k, x] = lines[l++].split(' ').map(BigInt);\n var arr = lines[l++].split(' ').map(BigInt);\n console.log(solve(n, k, x, arr))\n});\n\nfunction solve(n, k, x, arr) {\n const cp = (a, b) => {\n if (a < b) {\n return -1\n } else if (a > b) {\n return 1\n } else {\n return 0\n }\n }\n arr.sort(cp)\n\n const needs = []\n arr.forEach((item, i) => {\n if (i && item - arr[i - 1] > x) {\n const need = ceil((item - arr[i - 1]), x) - 1n\n needs.push(need)\n }\n })\n needs.sort(cp)\n\n let sum = 0n\n for (let i = 0; i < needs.length; i++) {\n if (sum + needs[i] > k) {\n return needs.length - i + 1\n }\n sum += needs[i]\n }\n return 1\n}\n\nfunction ceil(a, b) {\n const r = a % b\n return (a - r) / b\n}\n"}], "src_uid": "c6c07ef23cf2def9f99cbfb6076c9810"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet T = -1;\nlet num = -1;\nlet last = 0;\nrl.on('line', (line) => {\n if (T !== -1 && T % 2) {\n console.log(Array\n .from(line)\n .reduceRight((res, ele, index) => {\n if (ele === 'A') {\n res = Math.max(res, last - index - 1);\n last = index;\n } else {\n res = res;\n }\n return res;\n }, 0))\n } else if (T !== -1) {\n num = line;\n last = num;\n }\n T ++;\n})", "positive_code": [{"source_code": "var stdin = process.openStdin();\n\nstdin.addListener(\"data\", function(d) {\n const arr = d.toString().trim().split('\\n').map(e => e.trim());\n for(let i=1; i < arr.length; i++){\n if(i % 2 === 0){\n console.log(findm(arr[i]));\n }\n }\n});\n \nfunction findm(students){\n let str = students;\n let counter = 0, j = 1;\n let arr = str.split(/A+/).map(e => e.length);\n let max = 0;\n for(let i = 1; i < arr.length; i++){\n if(max < arr[i]){\n max = arr[i];\n }\n }\n return max;\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n let ans = 0;\n const startPoint = str.indexOf('A') > -1 ? str.indexOf('A') : str.length;\n\n for (let i = startPoint; i < str.length; i++) {\n let count = 0;\n\n while (str[i] === 'P') {\n count++;\n i++;\n }\n\n ans = Math.max(ans, count);\n }\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet T = -1;\nlet num = -1;\nlet last = 0;\nrl.on('line', (line) => {\n if (T !== -1 && T % 2) {\n console.log(Array\n .from(line)\n .reduceRight((res, ele, index) => {\n if (ele === 'A') {\n res = Math.max(res, last - index - 1);\n last = index;\n }\n return res;\n }, 0))\n } else if (T !== -1) {\n num = line;\n last = num;\n }\n T ++;\n})"}, {"source_code": " var t;\n t=readline();\n while (t--){\n var ans=0; var c=0,str,n;\n n=readline();\n str=readline();\n for (var i=n-1; i>-1; i--){\n if (str[i]=='P')\n c++;\n else {if (c>ans)\n ans=c;\n c=0;\n }\n }\n print (ans);\n }\n "}, {"source_code": "var queries = parseInt(readline());\nfor(var i = 0; i< queries;i++){\nvar discard = readline();\nvar myString = readline();\nvar val = myString.split(/[A]/);\nwhile (val[val.length-1] == \"\"){\n val.pop();\n}\nif (val[0] == \"\"){\nwhile (val[0] == \"\"){\n val.shift();\n}\n}\nelse{\n val.shift();\n}\nvar result = val.reduce((sum,ele)=>{\n if (ele.length > sum){\n return sum += ele.length - sum;\n }\n else{\n return sum;\n }\n},0)\nprint(result);\n}"}, {"source_code": "\"use strict\";var readline=require(\"readline\");function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e0?floor:ceil)(t)},min=Math.min,toLength=function(t){return t>0?min(toInteger(t),9007199254740991):0},max=Math.max,min$1=Math.min,toAbsoluteIndex=function(t,e){var r=toInteger(t);return r<0?max(r+e,0):min$1(r,e)},createMethod=function(t){return function(e,r,n){var o,i=toIndexedObject(e),c=toLength(i.length),a=toAbsoluteIndex(n,c);if(t&&r!=r){for(;c>a;)if((o=i[a++])!=o)return!0}else for(;c>a;a++)if((t||a in i)&&i[a]===r)return t||a||0;return!t&&-1}},arrayIncludes={includes:createMethod(!0),indexOf:createMethod(!1)},indexOf=arrayIncludes.indexOf,objectKeysInternal=function(t,e){var r,n=toIndexedObject(t),o=0,i=[];for(r in n)!has(hiddenKeys,r)&&has(n,r)&&i.push(r);for(;e.length>o;)has(n,r=e[o++])&&(~indexOf(i,r)||i.push(r));return i},enumBugKeys=[\"constructor\",\"hasOwnProperty\",\"isPrototypeOf\",\"propertyIsEnumerable\",\"toLocaleString\",\"toString\",\"valueOf\"],hiddenKeys$1=enumBugKeys.concat(\"length\",\"prototype\"),f$3=Object.getOwnPropertyNames||function(t){return objectKeysInternal(t,hiddenKeys$1)},objectGetOwnPropertyNames={f:f$3},f$4=Object.getOwnPropertySymbols,objectGetOwnPropertySymbols={f:f$4},ownKeys=getBuiltIn(\"Reflect\",\"ownKeys\")||function(t){var e=objectGetOwnPropertyNames.f(anObject(t)),r=objectGetOwnPropertySymbols.f;return r?e.concat(r(t)):e},copyConstructorProperties=function(t,e){for(var r=ownKeys(e),n=objectDefineProperty.f,o=objectGetOwnPropertyDescriptor.f,i=0;i0&&(!i.multiline||i.multiline&&\"\\n\"!==t[i.lastIndex-1])&&(s=\"(?: \"+s+\")\",l=\" \"+l,u++),r=new RegExp(\"^(?:\"+s+\")\",a)),NPCG_INCLUDED&&(r=new RegExp(\"^\"+s+\"$(?!\\\\s)\",a)),UPDATES_LAST_INDEX_WRONG&&(e=i.lastIndex),n=nativeExec.call(c?r:i,l),c?n?(n.input=n.input.slice(u),n[0]=n[0].slice(u),n.index=i.lastIndex,i.lastIndex+=n[0].length):i.lastIndex=0:UPDATES_LAST_INDEX_WRONG&&n&&(i.lastIndex=i.global?n.index+n[0].length:e),NPCG_INCLUDED&&n&&n.length>1&&nativeReplace.call(n[0],r,(function(){for(o=1;oo;){if(e=+arguments[o++],toAbsoluteIndex(e,1114111)!==e)throw RangeError(e+\" is not a valid code point\");r.push(e<65536?fromCharCode(e):fromCharCode(55296+((e-=65536)>>10),e%1024+56320))}return r.join(\"\")}}),_export({target:\"String\",stat:!0},{raw:function(t){for(var e=toIndexedObject(t.raw),r=toLength(e.length),n=arguments.length,o=[],i=0;r>i;)o.push(String(e[i++])),i=a?t?\"\":void 0:(n=i.charCodeAt(c))<55296||n>56319||c+1===a||(o=i.charCodeAt(c+1))<56320||o>57343?t?i.charAt(c):n:t?i.slice(c,c+2):o-56320+(n-55296<<10)+65536}},stringMultibyte={codeAt:createMethod$1(!1),charAt:createMethod$1(!0)},codeAt=stringMultibyte.codeAt;_export({target:\"String\",proto:!0},{codePointAt:function(t){return codeAt(this,t)}});var nativeSymbol=!!Object.getOwnPropertySymbols&&!fails((function(){return!String(Symbol())})),useSymbolAsUid=nativeSymbol&&!Symbol.sham&&\"symbol\"==typeof Symbol.iterator,WellKnownSymbolsStore=shared(\"wks\"),Symbol$1=global_1.Symbol,createWellKnownSymbol=useSymbolAsUid?Symbol$1:Symbol$1&&Symbol$1.withoutSetter||uid,wellKnownSymbol=function(t){return has(WellKnownSymbolsStore,t)||(nativeSymbol&&has(Symbol$1,t)?WellKnownSymbolsStore[t]=Symbol$1[t]:WellKnownSymbolsStore[t]=createWellKnownSymbol(\"Symbol.\"+t)),WellKnownSymbolsStore[t]},MATCH=wellKnownSymbol(\"match\"),isRegexp=function(t){var e;return isObject$1(t)&&(void 0!==(e=t[MATCH])?!!e:\"RegExp\"==classofRaw(t))},notARegexp=function(t){if(isRegexp(t))throw TypeError(\"The method doesn't accept regular expressions\");return t},MATCH$1=wellKnownSymbol(\"match\"),correctIsRegexpLogic=function(t){var e=/./;try{\"/./\"[t](e)}catch(r){try{return e[MATCH$1]=!1,\"/./\"[t](e)}catch(t){}}return!1},getOwnPropertyDescriptor$2=objectGetOwnPropertyDescriptor.f,nativeEndsWith=\"\".endsWith,min$2=Math.min,CORRECT_IS_REGEXP_LOGIC=correctIsRegexpLogic(\"endsWith\"),MDN_POLYFILL_BUG=!CORRECT_IS_REGEXP_LOGIC&&!!function(){var t=getOwnPropertyDescriptor$2(String.prototype,\"endsWith\");return t&&!t.writable}();_export({target:\"String\",proto:!0,forced:!MDN_POLYFILL_BUG&&!CORRECT_IS_REGEXP_LOGIC},{endsWith:function(t){var e=String(requireObjectCoercible(this));notARegexp(t);var r=arguments.length>1?arguments[1]:void 0,n=toLength(e.length),o=void 0===r?n:min$2(toLength(r),n),i=String(t);return nativeEndsWith?nativeEndsWith.call(e,i,o):e.slice(o-i.length,o)===i}}),_export({target:\"String\",proto:!0,forced:!correctIsRegexpLogic(\"includes\")},{includes:function(t){return!!~String(requireObjectCoercible(this)).indexOf(notARegexp(t),arguments.length>1?arguments[1]:void 0)}});var SPECIES=wellKnownSymbol(\"species\"),REPLACE_SUPPORTS_NAMED_GROUPS=!fails((function(){var t=/./;return t.exec=function(){var t=[];return t.groups={a:\"7\"},t},\"7\"!==\"\".replace(t,\"$\")})),REPLACE_KEEPS_$0=\"$0\"===\"a\".replace(/./,\"$0\"),SPLIT_WORKS_WITH_OVERWRITTEN_EXEC=!fails((function(){var t=/(?:)/,e=t.exec;t.exec=function(){return e.apply(this,arguments)};var r=\"ab\".split(t);return 2!==r.length||\"a\"!==r[0]||\"b\"!==r[1]})),fixRegexpWellKnownSymbolLogic=function(t,e,r,n){var o=wellKnownSymbol(t),i=!fails((function(){var e={};return e[o]=function(){return 7},7!=\"\"[t](e)})),c=i&&!fails((function(){var e=!1,r=/a/;return\"split\"===t&&((r={}).constructor={},r.constructor[SPECIES]=function(){return r},r.flags=\"\",r[o]=/./[o]),r.exec=function(){return e=!0,null},r[o](\"\"),!e}));if(!i||!c||\"replace\"===t&&(!REPLACE_SUPPORTS_NAMED_GROUPS||!REPLACE_KEEPS_$0)||\"split\"===t&&!SPLIT_WORKS_WITH_OVERWRITTEN_EXEC){var a=/./[o],s=r(o,\"\"[t],(function(t,e,r,n,o){return e.exec===regexpExec?i&&!o?{done:!0,value:a.call(e,r,n)}:{done:!0,value:t.call(r,e,n)}:{done:!1}}),{REPLACE_KEEPS_$0:REPLACE_KEEPS_$0}),u=s[0],l=s[1];redefine(String.prototype,t,u),redefine(RegExp.prototype,o,2==e?function(t,e){return l.call(t,this,e)}:function(t){return l.call(t,this)})}n&&createNonEnumerableProperty(RegExp.prototype[o],\"sham\",!0)},charAt=stringMultibyte.charAt,advanceStringIndex=function(t,e,r){return e+(r?charAt(t,e).length:1)},regexpExecAbstract=function(t,e){var r=t.exec;if(\"function\"==typeof r){var n=r.call(t,e);if(\"object\"!=typeof n)throw TypeError(\"RegExp exec method returned something other than an Object or null\");return n}if(\"RegExp\"!==classofRaw(t))throw TypeError(\"RegExp#exec called on incompatible receiver\");return regexpExec.call(t,e)};fixRegexpWellKnownSymbolLogic(\"match\",1,(function(t,e,r){return[function(e){var r=requireObjectCoercible(this),n=null==e?void 0:e[t];return void 0!==n?n.call(e,r):new RegExp(e)[t](String(r))},function(t){var n=r(e,t,this);if(n.done)return n.value;var o=anObject(t),i=String(this);if(!o.global)return regexpExecAbstract(o,i);var c=o.unicode;o.lastIndex=0;for(var a,s=[],u=0;null!==(a=regexpExecAbstract(o,i));){var l=String(a[0]);s[u]=l,\"\"===l&&(o.lastIndex=advanceStringIndex(i,toLength(o.lastIndex),c)),u++}return 0===u?null:s}]}));var IteratorPrototype,PrototypeOfArrayIteratorPrototype,arrayIterator,toObject=function(t){return Object(requireObjectCoercible(t))},correctPrototypeGetter=!fails((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),IE_PROTO=sharedKey(\"IE_PROTO\"),ObjectPrototype=Object.prototype,objectGetPrototypeOf=correctPrototypeGetter?Object.getPrototypeOf:function(t){return t=toObject(t),has(t,IE_PROTO)?t[IE_PROTO]:\"function\"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?ObjectPrototype:null},ITERATOR=wellKnownSymbol(\"iterator\"),BUGGY_SAFARI_ITERATORS=!1,returnThis=function(){return this};[].keys&&(\"next\"in(arrayIterator=[].keys())?(PrototypeOfArrayIteratorPrototype=objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator)))!==Object.prototype&&(IteratorPrototype=PrototypeOfArrayIteratorPrototype):BUGGY_SAFARI_ITERATORS=!0),null==IteratorPrototype&&(IteratorPrototype={}),has(IteratorPrototype,ITERATOR)||createNonEnumerableProperty(IteratorPrototype,ITERATOR,returnThis);var activeXDocument,iteratorsCore={IteratorPrototype:IteratorPrototype,BUGGY_SAFARI_ITERATORS:BUGGY_SAFARI_ITERATORS},objectKeys=Object.keys||function(t){return objectKeysInternal(t,enumBugKeys)},objectDefineProperties=descriptors?Object.defineProperties:function(t,e){anObject(t);for(var r,n=objectKeys(e),o=n.length,i=0;o>i;)objectDefineProperty.f(t,r=n[i++],e[r]);return t},html=getBuiltIn(\"document\",\"documentElement\"),GT=\">\",LT=\"<\",PROTOTYPE=\"prototype\",SCRIPT=\"script\",IE_PROTO$1=sharedKey(\"IE_PROTO\"),EmptyConstructor=function(){},scriptTag=function(t){return LT+SCRIPT+GT+t+LT+\"/\"+SCRIPT+GT},NullProtoObjectViaActiveX=function(t){t.write(scriptTag(\"\")),t.close();var e=t.parentWindow.Object;return t=null,e},NullProtoObjectViaIFrame=function(){var t,e=documentCreateElement(\"iframe\"),r=\"java\"+SCRIPT+\":\";return e.style.display=\"none\",html.appendChild(e),e.src=String(r),(t=e.contentWindow.document).open(),t.write(scriptTag(\"document.F=Object\")),t.close(),t.F},NullProtoObject=function(){try{activeXDocument=document.domain&&new ActiveXObject(\"htmlfile\")}catch(t){}NullProtoObject=activeXDocument?NullProtoObjectViaActiveX(activeXDocument):NullProtoObjectViaIFrame();for(var t=enumBugKeys.length;t--;)delete NullProtoObject[PROTOTYPE][enumBugKeys[t]];return NullProtoObject()};hiddenKeys[IE_PROTO$1]=!0;var objectCreate=Object.create||function(t,e){var r;return null!==t?(EmptyConstructor[PROTOTYPE]=anObject(t),r=new EmptyConstructor,EmptyConstructor[PROTOTYPE]=null,r[IE_PROTO$1]=t):r=NullProtoObject(),void 0===e?r:objectDefineProperties(r,e)},defineProperty=objectDefineProperty.f,TO_STRING_TAG=wellKnownSymbol(\"toStringTag\"),setToStringTag=function(t,e,r){t&&!has(t=r?t:t.prototype,TO_STRING_TAG)&&defineProperty(t,TO_STRING_TAG,{configurable:!0,value:e})},IteratorPrototype$1=iteratorsCore.IteratorPrototype,createIteratorConstructor=function(t,e,r){var n=e+\" Iterator\";return t.prototype=objectCreate(IteratorPrototype$1,{next:createPropertyDescriptor(1,r)}),setToStringTag(t,n,!1),t},aFunction$1=function(t){if(\"function\"!=typeof t)throw TypeError(String(t)+\" is not a function\");return t},SPECIES$1=wellKnownSymbol(\"species\"),speciesConstructor=function(t,e){var r,n=anObject(t).constructor;return void 0===n||null==(r=anObject(n)[SPECIES$1])?e:aFunction$1(r)},MATCH_ALL=wellKnownSymbol(\"matchAll\"),REGEXP_STRING=\"RegExp String\",REGEXP_STRING_ITERATOR=REGEXP_STRING+\" Iterator\",setInternalState=internalState.set,getInternalState=internalState.getterFor(REGEXP_STRING_ITERATOR),RegExpPrototype=RegExp.prototype,regExpBuiltinExec=RegExpPrototype.exec,nativeMatchAll=\"\".matchAll,WORKS_WITH_NON_GLOBAL_REGEX=!!nativeMatchAll&&!fails((function(){\"a\".matchAll(/./)})),regExpExec=function(t,e){var r,n=t.exec;if(\"function\"==typeof n){if(\"object\"!=typeof(r=n.call(t,e)))throw TypeError(\"Incorrect exec result\");return r}return regExpBuiltinExec.call(t,e)},$RegExpStringIterator=createIteratorConstructor((function(t,e,r,n){setInternalState(this,{type:REGEXP_STRING_ITERATOR,regexp:t,string:e,global:r,unicode:n,done:!1})}),REGEXP_STRING,(function(){var t=getInternalState(this);if(t.done)return{value:void 0,done:!0};var e=t.regexp,r=t.string,n=regExpExec(e,r);return null===n?{value:void 0,done:t.done=!0}:t.global?(\"\"==String(n[0])&&(e.lastIndex=advanceStringIndex(r,toLength(e.lastIndex),t.unicode)),{value:n,done:!1}):(t.done=!0,{value:n,done:!1})})),$matchAll=function(t){var e,r,n,o,i,c,a=anObject(this),s=String(t);return e=speciesConstructor(a,RegExp),void 0===(r=a.flags)&&a instanceof RegExp&&!(\"flags\"in RegExpPrototype)&&(r=regexpFlags.call(a)),n=void 0===r?\"\":String(r),o=new e(e===RegExp?a.source:a,n),i=!!~n.indexOf(\"g\"),c=!!~n.indexOf(\"u\"),o.lastIndex=toLength(a.lastIndex),new $RegExpStringIterator(o,s,i,c)};_export({target:\"String\",proto:!0,forced:WORKS_WITH_NON_GLOBAL_REGEX},{matchAll:function(t){var e,r,n=requireObjectCoercible(this);if(null!=t){if(isRegexp(t)&&!~String(requireObjectCoercible(\"flags\"in RegExpPrototype?t.flags:regexpFlags.call(t))).indexOf(\"g\"))throw TypeError(\"`.matchAll` does not allow non-global regexes\");if(WORKS_WITH_NON_GLOBAL_REGEX)return nativeMatchAll.apply(n,arguments);if(void 0===(r=t[MATCH_ALL])&&isPure&&\"RegExp\"==classofRaw(t)&&(r=$matchAll),null!=r)return aFunction$1(r).call(t,n)}else if(WORKS_WITH_NON_GLOBAL_REGEX)return nativeMatchAll.apply(n,arguments);return e=String(n),new RegExp(t,\"g\")[MATCH_ALL](e)}}),MATCH_ALL in RegExpPrototype||createNonEnumerableProperty(RegExpPrototype,MATCH_ALL,$matchAll);var stringRepeat=\"\".repeat||function(t){var e=String(requireObjectCoercible(this)),r=\"\",n=toInteger(t);if(n<0||n==1/0)throw RangeError(\"Wrong number of repetitions\");for(;n>0;(n>>>=1)&&(e+=e))1&n&&(r+=e);return r},ceil$1=Math.ceil,createMethod$2=function(t){return function(e,r,n){var o,i,c=String(requireObjectCoercible(e)),a=c.length,s=void 0===n?\" \":String(n),u=toLength(r);return u<=a||\"\"==s?c:(o=u-a,(i=stringRepeat.call(s,ceil$1(o/s.length))).length>o&&(i=i.slice(0,o)),t?c+i:i+c)}},stringPad={start:createMethod$2(!1),end:createMethod$2(!0)},engineUserAgent=getBuiltIn(\"navigator\",\"userAgent\")||\"\",stringPadWebkitBug=/Version\\/10\\.\\d+(\\.\\d+)?( Mobile\\/\\w+)? Safari\\//.test(engineUserAgent),$padEnd=stringPad.end;_export({target:\"String\",proto:!0,forced:stringPadWebkitBug},{padEnd:function(t){return $padEnd(this,t,arguments.length>1?arguments[1]:void 0)}});var $padStart=stringPad.start;_export({target:\"String\",proto:!0,forced:stringPadWebkitBug},{padStart:function(t){return $padStart(this,t,arguments.length>1?arguments[1]:void 0)}}),_export({target:\"String\",proto:!0},{repeat:stringRepeat});var max$1=Math.max,min$3=Math.min,floor$1=Math.floor,SUBSTITUTION_SYMBOLS=/\\$([$&'`]|\\d\\d?|<[^>]*>)/g,SUBSTITUTION_SYMBOLS_NO_NAMED=/\\$([$&'`]|\\d\\d?)/g,maybeToString=function(t){return void 0===t?t:String(t)};fixRegexpWellKnownSymbolLogic(\"replace\",2,(function(t,e,r,n){return[function(r,n){var o=requireObjectCoercible(this),i=null==r?void 0:r[t];return void 0!==i?i.call(r,o,n):e.call(String(o),r,n)},function(t,i){if(n.REPLACE_KEEPS_$0||\"string\"==typeof i&&-1===i.indexOf(\"$0\")){var c=r(e,t,this,i);if(c.done)return c.value}var a=anObject(t),s=String(this),u=\"function\"==typeof i;u||(i=String(i));var l=a.global;if(l){var p=a.unicode;a.lastIndex=0}for(var f=[];;){var g=regexpExecAbstract(a,s);if(null===g)break;if(f.push(g),!l)break;\"\"===String(g[0])&&(a.lastIndex=advanceStringIndex(s,toLength(a.lastIndex),p))}for(var h=\"\",b=0,d=0;d=b&&(h+=s.slice(b,S)+v,b=S+y.length)}return h+s.slice(b)}];function o(t,r,n,o,i,c){var a=n+t.length,s=o.length,u=SUBSTITUTION_SYMBOLS_NO_NAMED;return void 0!==i&&(i=toObject(i),u=SUBSTITUTION_SYMBOLS),e.call(c,u,(function(e,c){var u;switch(c.charAt(0)){case\"$\":return\"$\";case\"&\":return t;case\"`\":return r.slice(0,n);case\"'\":return r.slice(a);case\"<\":u=i[c.slice(1,-1)];break;default:var l=+c;if(0===l)return e;if(l>s){var p=floor$1(l/10);return 0===p?e:p<=s?void 0===o[p-1]?c.charAt(1):o[p-1]+c.charAt(1):e}u=o[l-1]}return void 0===u?\"\":u}))}}));var sameValue=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};fixRegexpWellKnownSymbolLogic(\"search\",1,(function(t,e,r){return[function(e){var r=requireObjectCoercible(this),n=null==e?void 0:e[t];return void 0!==n?n.call(e,r):new RegExp(e)[t](String(r))},function(t){var n=r(e,t,this);if(n.done)return n.value;var o=anObject(t),i=String(this),c=o.lastIndex;sameValue(c,0)||(o.lastIndex=0);var a=regexpExecAbstract(o,i);return sameValue(o.lastIndex,c)||(o.lastIndex=c),null===a?-1:a.index}]}));var arrayPush=[].push,min$4=Math.min,MAX_UINT32=4294967295,SUPPORTS_Y=!fails((function(){return!RegExp(MAX_UINT32,\"y\")}));fixRegexpWellKnownSymbolLogic(\"split\",2,(function(t,e,r){var n;return n=\"c\"==\"abbc\".split(/(b)*/)[1]||4!=\"test\".split(/(?:)/,-1).length||2!=\"ab\".split(/(?:ab)*/).length||4!=\".\".split(/(.?)(.?)/).length||\".\".split(/()()/).length>1||\"\".split(/.?/).length?function(t,r){var n=String(requireObjectCoercible(this)),o=void 0===r?MAX_UINT32:r>>>0;if(0===o)return[];if(void 0===t)return[n];if(!isRegexp(t))return e.call(n,t,o);for(var i,c,a,s=[],u=(t.ignoreCase?\"i\":\"\")+(t.multiline?\"m\":\"\")+(t.unicode?\"u\":\"\")+(t.sticky?\"y\":\"\"),l=0,p=new RegExp(t.source,u+\"g\");(i=regexpExec.call(p,n))&&!((c=p.lastIndex)>l&&(s.push(n.slice(l,i.index)),i.length>1&&i.index=o));)p.lastIndex===i.index&&p.lastIndex++;return l===n.length?!a&&p.test(\"\")||s.push(\"\"):s.push(n.slice(l)),s.length>o?s.slice(0,o):s}:\"0\".split(void 0,0).length?function(t,r){return void 0===t&&0===r?[]:e.call(this,t,r)}:e,[function(e,r){var o=requireObjectCoercible(this),i=null==e?void 0:e[t];return void 0!==i?i.call(e,o,r):n.call(String(o),e,r)},function(t,o){var i=r(n,t,this,o,n!==e);if(i.done)return i.value;var c=anObject(t),a=String(this),s=speciesConstructor(c,RegExp),u=c.unicode,l=(c.ignoreCase?\"i\":\"\")+(c.multiline?\"m\":\"\")+(c.unicode?\"u\":\"\")+(SUPPORTS_Y?\"y\":\"g\"),p=new s(SUPPORTS_Y?c:\"^(?:\"+c.source+\")\",l),f=void 0===o?MAX_UINT32:o>>>0;if(0===f)return[];if(0===a.length)return null===regexpExecAbstract(p,a)?[a]:[];for(var g=0,h=0,b=[];h1?arguments[1]:void 0,e.length)),n=String(t);return nativeStartsWith?nativeStartsWith.call(e,n,r):e.slice(r,r+n.length)===n}});var whitespaces=\"\\t\\n\\v\\f\\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\\u2028\\u2029\\ufeff\",whitespace=\"[\"+whitespaces+\"]\",ltrim=RegExp(\"^\"+whitespace+whitespace+\"*\"),rtrim=RegExp(whitespace+whitespace+\"*$\"),createMethod$3=function(t){return function(e){var r=String(requireObjectCoercible(e));return 1&t&&(r=r.replace(ltrim,\"\")),2&t&&(r=r.replace(rtrim,\"\")),r}},stringTrim={start:createMethod$3(1),end:createMethod$3(2),trim:createMethod$3(3)},non=\"\u200b\u0085\u180e\",stringTrimForced=function(t){return fails((function(){return!!whitespaces[t]()||non[t]()!=non||whitespaces[t].name!==t}))},$trim=stringTrim.trim;_export({target:\"String\",proto:!0,forced:stringTrimForced(\"trim\")},{trim:function(){return $trim(this)}});var $trimStart=stringTrim.start,FORCED=stringTrimForced(\"trimStart\"),trimStart=FORCED?function(){return $trimStart(this)}:\"\".trimStart;_export({target:\"String\",proto:!0,forced:FORCED},{trimStart:trimStart,trimLeft:trimStart});var $trimEnd=stringTrim.end,FORCED$1=stringTrimForced(\"trimEnd\"),trimEnd=FORCED$1?function(){return $trimEnd(this)}:\"\".trimEnd;_export({target:\"String\",proto:!0,forced:FORCED$1},{trimEnd:trimEnd,trimRight:trimEnd});var aPossiblePrototype=function(t){if(!isObject$1(t)&&null!==t)throw TypeError(\"Can't set \"+String(t)+\" as a prototype\");return t},objectSetPrototypeOf=Object.setPrototypeOf||(\"__proto__\"in{}?function(){var t,e=!1,r={};try{(t=Object.getOwnPropertyDescriptor(Object.prototype,\"__proto__\").set).call(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return anObject(r),aPossiblePrototype(n),e?t.call(r,n):r.__proto__=n,r}}():void 0),IteratorPrototype$2=iteratorsCore.IteratorPrototype,BUGGY_SAFARI_ITERATORS$1=iteratorsCore.BUGGY_SAFARI_ITERATORS,ITERATOR$1=wellKnownSymbol(\"iterator\"),KEYS=\"keys\",VALUES=\"values\",ENTRIES=\"entries\",returnThis$1=function(){return this},defineIterator=function(t,e,r,n,o,i,c){createIteratorConstructor(r,e,n);var a,s,u,l=function(t){if(t===o&&b)return b;if(!BUGGY_SAFARI_ITERATORS$1&&t in g)return g[t];switch(t){case KEYS:case VALUES:case ENTRIES:return function(){return new r(this,t)}}return function(){return new r(this)}},p=e+\" Iterator\",f=!1,g=t.prototype,h=g[ITERATOR$1]||g[\"@@iterator\"]||o&&g[o],b=!BUGGY_SAFARI_ITERATORS$1&&h||l(o),d=\"Array\"==e&&g.entries||h;if(d&&(a=objectGetPrototypeOf(d.call(new t)),IteratorPrototype$2!==Object.prototype&&a.next&&(objectGetPrototypeOf(a)!==IteratorPrototype$2&&(objectSetPrototypeOf?objectSetPrototypeOf(a,IteratorPrototype$2):\"function\"!=typeof a[ITERATOR$1]&&createNonEnumerableProperty(a,ITERATOR$1,returnThis$1)),setToStringTag(a,p,!0))),o==VALUES&&h&&h.name!==VALUES&&(f=!0,b=function(){return h.call(this)}),g[ITERATOR$1]!==b&&createNonEnumerableProperty(g,ITERATOR$1,b),o)if(s={values:l(VALUES),keys:i?b:l(KEYS),entries:l(ENTRIES)},c)for(u in s)!BUGGY_SAFARI_ITERATORS$1&&!f&&u in g||redefine(g,u,s[u]);else _export({target:e,proto:!0,forced:BUGGY_SAFARI_ITERATORS$1||f},s);return s},charAt$1=stringMultibyte.charAt,STRING_ITERATOR=\"String Iterator\",setInternalState$1=internalState.set,getInternalState$1=internalState.getterFor(STRING_ITERATOR);defineIterator(String,\"String\",(function(t){setInternalState$1(this,{type:STRING_ITERATOR,string:String(t),index:0})}),(function(){var t,e=getInternalState$1(this),r=e.string,n=e.index;return n>=r.length?{value:void 0,done:!0}:(t=charAt$1(r,n),e.index+=t.length,{value:t,done:!1})}));var quot=/\"/g,createHtml=function(t,e,r,n){var o=String(requireObjectCoercible(t)),i=\"<\"+e;return\"\"!==r&&(i+=\" \"+r+'=\"'+String(n).replace(quot,\""\")+'\"'),i+\">\"+o+\"\"},stringHtmlForced=function(t){return fails((function(){var e=\"\"[t]('\"');return e!==e.toLowerCase()||e.split('\"').length>3}))};_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"anchor\")},{anchor:function(t){return createHtml(this,\"a\",\"name\",t)}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"big\")},{big:function(){return createHtml(this,\"big\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"blink\")},{blink:function(){return createHtml(this,\"blink\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"bold\")},{bold:function(){return createHtml(this,\"b\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"fixed\")},{fixed:function(){return createHtml(this,\"tt\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"fontcolor\")},{fontcolor:function(t){return createHtml(this,\"font\",\"color\",t)}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"fontsize\")},{fontsize:function(t){return createHtml(this,\"font\",\"size\",t)}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"italics\")},{italics:function(){return createHtml(this,\"i\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"link\")},{link:function(t){return createHtml(this,\"a\",\"href\",t)}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"small\")},{small:function(){return createHtml(this,\"small\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"strike\")},{strike:function(){return createHtml(this,\"strike\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"sub\")},{sub:function(){return createHtml(this,\"sub\",\"\",\"\")}}),_export({target:\"String\",proto:!0,forced:stringHtmlForced(\"sup\")},{sup:function(){return createHtml(this,\"sup\",\"\",\"\")}});var string=path.String,charAt$2=stringMultibyte.charAt;_export({target:\"String\",proto:!0},{at:function(t){return charAt$2(this,t)}});var codeAt$1=stringMultibyte.codeAt,charAt$3=stringMultibyte.charAt,STRING_ITERATOR$1=\"String Iterator\",setInternalState$2=internalState.set,getInternalState$2=internalState.getterFor(STRING_ITERATOR$1),$StringIterator=createIteratorConstructor((function(t){setInternalState$2(this,{type:STRING_ITERATOR$1,string:t,index:0})}),\"String\",(function(){var t,e=getInternalState$2(this),r=e.string,n=e.index;return n>=r.length?{value:void 0,done:!0}:(t=charAt$3(r,n),e.index+=t.length,{value:{codePoint:codeAt$1(t,0),position:n},done:!1})}));_export({target:\"String\",proto:!0},{codePoints:function(){return new $StringIterator(String(requireObjectCoercible(this)))}});var REPLACE=wellKnownSymbol(\"replace\"),RegExpPrototype$1=RegExp.prototype;_export({target:\"String\",proto:!0},{replaceAll:function t(e,r){var n,o,i,c,a,s,u,l=requireObjectCoercible(this);if(null!=e){if(isRegexp(e)&&!~String(requireObjectCoercible(\"flags\"in RegExpPrototype$1?e.flags:regexpFlags.call(e))).indexOf(\"g\"))throw TypeError(\"`.replaceAll` does not allow non-global regexes\");if(void 0!==(n=e[REPLACE]))return n.call(e,l,r)}if(o=String(l),\"\"===(i=String(e)))return t.call(o,/(?:)/g,r);if(c=o.split(i),\"function\"!=typeof r)return c.join(String(r));for(s=(a=c[0]).length,u=1;uNumber(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\nfunction Main() {\n var t = myconv(readline(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var k = myconv(readline(),1);\n var list = myconv(readline(),6);\n var isA = false;\n var countP = 0;\n var maxP = 0;\n for(var j = 0; j < k; j++){\n if(!isA && list[j] == \"P\"){\n continue;\n }\n if(list[j] == \"A\"){\n isA = true;\n maxP = Math.max(maxP, countP);\n countP = 0;\n }else if(list[j] == \"P\"){\n countP++;\n }\n }\n maxP = Math.max(maxP, countP);\n output.push(maxP);\n }\n myout(output.join(\"\\n\"));\n}\n\nMain();"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var length = +readline();\n var str = readline();\n\n var ap = str\n .match(/AP+/g)\n \n if (ap) {\n print(\n ap.map(function(a) {\n return a.length\n })\n .sort(function(a, b) {\n return b - a\n })[0] - 1\n )\n } else {\n print(0)\n }\n }\n}\nmain()"}, {"source_code": " var t = readline();\n while(t--){\n var n = readline();\n var str = readline();\n \n var result = 0,\n cnt = 0,\n sum = 0;\n \n for (var i = 0; i < n; i++) {\n if (str[i] === 'A') {\n cnt = 0;\n sum = 1;\n } else if (sum) {\n cnt++;\n }\n result = Math.max(result, cnt);\n }\n print(result);\n }"}, {"source_code": "var t;\nt=readline();\nwhile (t--){\n var ans=0; var c=0,str,n;\n n=readline();\n str=readline();\n for (var i=n-1; i>-1; i--){\n if (str[i]=='P')\n c++;\n else {if (c>ans)\n ans=c;\n c=0;\n }\n }\n print (ans);\n }\n "}, {"source_code": "var t;\nt=readline();\nwhile (t--){\n var ans=0; var c=0,str,n;\n n=readline();\n str=readline();\n for (var i=n-1; i>-1; i--){\n if (str[i]=='P')\n c++;\n else {if (c>ans)\n ans=c;\n c=0;\n }\n }\n print (ans);\n }"}, {"source_code": "var t;\nt=readline();\nwhile (t--){\n var ans=0; var c=0,str,n;\n n=readline();\n str=readline();\n for (var i=n-1; i>-1; i--){\n if (str[i]=='P')\n c++;\n else {if (c>ans)\n ans=c;\n c=0;\n }\n }\n print (ans);\n }\n \n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet T = -1;\nlet num = -1;\nrl.on('line', (line) => {\n if (T !== -1 && T % 2) {\n var posA = line.lastIndexOf('A');\n var posP = line.lastIndexOf('P');\n if (posA === num - 1) {\n console.log(0);\n } else if (posP > posA) {\n console.log(posP-posA);\n }\n } else if (T !== -1) {\n num = line;\n }\n T ++;\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet T = -1;\nlet num = -1;\nrl.on('line', (line) => {\n if (T !== -1 && T % 2) {\n var posA = line.lastIndexOf('A');\n var posP = line.lastIndexOf('P');\n if (posA === num - 1 || posA === -1) {\n console.log(0);\n } else if (posP > posA) {\n console.log(posP-posA);\n }\n } else if (T !== -1) {\n num = line;\n }\n T ++;\n})"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction _toConsumableArray(arr) {\n return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();\n}\n\nfunction _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];\n\n return arr2;\n }\n}\n\nfunction _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nfunction _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nfunction tnLineStdinReader() {\n return new Promise(function (resolve) {\n var stdin = readline.createInterface(process.stdin);\n var output = [];\n var tests = null;\n var n = null;\n stdin.on('line', function (line) {\n if (tests === null) {\n tests = +line;\n } else if (n === null) {\n n = +line;\n tests--;\n } else if (tests > 0) {\n n = null;\n output.push(line);\n } else {\n output.push(line);\n stdin.close();\n resolve(output);\n }\n });\n });\n}\n\ntnLineStdinReader().then(function (tests) {\n tests.forEach(function (t) {\n var allGroups = _toConsumableArray(t.matchAll(/AP+/g)).map(function (match) {\n return match[0].length - 1;\n }).sort(function (a, b) {\n return b - a;\n });\n\n var maxLength = allGroups.length ? allGroups[0] : 0;\n console.log(maxLength);\n });\n});\n"}, {"source_code": "var queries = parseInt(readline());\nfor(var i = 0; i < queries ;i++){\nvar discard = readline();\nvar myStr = readline();\nvar result = myStr.split('').reduce((sum,val,index,arr)=>{\n if (arr[index-1] == 'A' && arr[index] == 'P'){\n return sum += 1;\n }\n else{\n return sum;\n }\n},0);\nprint(result);\n}"}, {"source_code": "var t;\nt=readline();\nwhile (t--){\n var ans=0; var pos=-1,str,n;\n n=readline();\n str=readline();\n for (var i=0; i parseInt(x, 10)));\r\n}\r\n\r\nconst solver = (arr) => {\r\n let currentMaxResult = 0;\r\n \r\n for (let l = 0; l < arr.length - 1; l++) {\r\n const result = Math.max(arr[l], arr[l+1]) * Math.min(arr[l], arr[l+1])\r\n if (result > currentMaxResult) {\r\n currentMaxResult = result;\r\n }\r\n }\r\n // for(let l = 0; l < arr.length; l++) {\r\n // let max = arr[l];\r\n // let min = arr[l];\r\n // for(let r = l + 1; r < arr.length; r++) {\r\n \r\n // if (arr[r] > max)\r\n // max = Math.max(arr[r], max);\r\n // min = Math.min(arr[r], min);\r\n // const result = min*max;\r\n // if (result > currentMaxResult) {\r\n // currentMaxResult = result;\r\n // // console.log({subArr})\r\n // }\r\n // }\r\n // }\r\n \r\n return currentMaxResult;\r\n};\r\n\r\nfor(let example of examples) {\r\n console.log(solver(example))\r\n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ');\n var b = k[0];\n var max = 0;\n for(j = 1; j < e; j++){\n var a = b * k[j];\n if(a > max){\n max = a;\n }\n b = k[j];\n }\n console.log(max);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var c = 0; var max = -1;\n for(j = 1; j < n; j++){\n c = a * k[j];\n if(c > max){\n max = c;\n }\n a = k[j];\n }\n console.log(max);\n }\n }\n});"}, {"source_code": "const fs = require('fs');\r\n\r\nconst input = String(fs.readFileSync(0))\r\n .split('\\n')\r\n .filter(Boolean)\r\n .map((str) => str.trim());\r\n\r\nfor (let i = 2; i < input.length; i += 2) {\r\n const arr = input[i].split(' ').map((s) => parseInt(s));\r\n console.log(solve(arr));\r\n}\r\n\r\nfunction solve(arr) {\r\n let max = 0;\r\n\r\n for (let i = 0; i < arr.length - 1; i++) {\r\n const prod = arr[i] * arr[i + 1];\r\n\r\n if (prod > max) {\r\n max = prod;\r\n }\r\n }\r\n\r\n return max;\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const args = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, args))\n }\n// })()\n})\n\nfunction solve(n, arr) {\n let max = -1\n arr.forEach((x, i) => {\n if (i + 1 < n) {\n max = Math.max(max, x * arr[i + 1])\n }\n if (i - 1 >= 0) {\n max = Math.max(max, x * arr[i - 1])\n }\n })\n return max\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const args = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, args))\n }\n// })()\n})\n\nfunction solve(n, arr) {\n const max = Math.max(...arr)\n let m2 = -1\n arr.some((x, i) => {\n if (x < max) return false\n\n if (i + 1 < n) {\n m2 = Math.max(m2, arr[i + 1])\n }\n if (i - 1 >= 0) {\n m2 = Math.max(m2, arr[i - 1])\n }\n\n // let second = -1\n // let min = Infinity\n // for (let j = i + 1; j < n; j++) {\n // min = Math.min(min, arr[j])\n // second = Math.max(min, second)\n // console.log('sb', arr[j], min, second)\n // if (second === max) {\n // m2 = second\n // return true\n // }\n // }\n // min = Infinity\n // for (let j = i - 1; j >= 0; j--) {\n // min = Math.min(min, arr[j])\n // second = Math.max(min, second)\n // console.log('sb', arr[j], min, second)\n // if (second === max) {\n // m2 = second\n // return true\n // }\n // }\n // m2 = Math.max(m2, second)\n })\n return max * m2\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const args = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, args))\n }\n// })()\n})\n\nfunction solve(n, arr) {\n const max = Math.max(...arr)\n let m2 = -1\n arr.some((x, i) => {\n if (x < max) return false\n let second = -1\n let min = Infinity\n for (let j = i + 1; j < n; j++) {\n min = Math.min(min, arr[j])\n second = Math.max(min, second)\n if (second === max) {\n m2 = second\n return true\n }\n }\n min = Infinity\n for (let j = i - 1; j >= 0; j--) {\n min = Math.min(min, arr[j])\n second = Math.max(min, second)\n if (second === max) {\n m2 = second\n return true\n }\n }\n m2 = Math.max(m2, second)\n })\n return max * m2\n}\n"}], "src_uid": "2deed55e860bd69ff0ba3973a1d73cac"} {"source_code": "\nvar lt = function(a, b) { \n if (a[0] < b[0]) { \n return true; \n }\n if (a[0] == b[0] && a[1] > b[1]) { \n return true; \n }\n return false; \n}\n\nvar eq = function(a, b) { \n return (a[0] == b[0] && a[1] == b[1]); \n}\n\nvar lower_bound = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n\n while (l <= r) { \n var m = Math.floor((l+r) / 2); \n if (lt(x, A[m])) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return l; \n}\n\nvar upper_bound = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n\n while (l <= r) { \n var m = Math.floor((l+r) / 2); \n if (lt(x, A[m]) || eq(x, A[m])) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return l; \n}\n\nvar main = function(n, k) { \n var s = []; \n for (var i = 0; i < n; i++) { \n s.push(readline().split(' ').map(Number)); \n }\n s.sort(function(a, b) { \n if (lt(a, b)) {\n return -1; \n }\n if (eq(a, b)) { \n return 0; \n }\n return 1; \n }); \n s.reverse(); \n print(upper_bound(s, s[k-1]) - lower_bound(s, s[k-1])); \n}\n\nmain.apply(0, readline().split(' ').map(Number)); \n", "positive_code": [{"source_code": "var l=readline().split(' ');\nvar n=+l[0];\nvar k=+l[1]-1;\nvar a=[];\nfor(var i=0;i0?l[0]-c:l[0];\n\tans=Math.max(c,ans);\n}\nprint(ans);", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, k;\nlet joy = -Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, k] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const [f, t] = d.split(' ').map(Number);\n joy = Math.max(joy, f - Math.max(t - k, 0));\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(joy);\n});\n"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], k = +input[1];\nvar max = -Infinity, p;\n\nfor(i = 0; i < n; i++){\n\tinput = readline().split(\" \").map(Number)\n\tf = input[0];\n\tt = input[1];\n\n\tp = (t > k) ? (f - t + k) : f;\n\n\tmax = Math.max(max, p);\n}\n\nwrite(max);"}, {"source_code": "function main(n,k,arr){\n\n\n var max = -Infinity;\n\n for(var i = 0 ; i < n ; i++){\n\n if(parseInt(arr[i][1]) > k){\n max = Math.max(max,(parseInt(arr[i][0])-parseInt(arr[i][1]-k)))\n }\n else{\n max = Math.max(max,parseInt(arr[i][0]));\n }\n }\n\n print(max);\n\n}\n\n\nvar nk = readline().split(\" \");\nfor(var i = 0 ; i < nk.length ; i++)nk[i] = parseInt(nk[i]);\n\nvar arr = [];\nfor(var i = 0 ; i < nk[0] ; i++){\n arr[i] = readline().split(\" \");\n}\n\nmain(nk[0],nk[1],arr)\n"}, {"source_code": "function main(n,k,arr){\n\n\n var max = -Infinity;\n\n for(var i = 0 ; i < n ; i++){\n\n if(parseInt(arr[i][1]) > k){\n max = Math.max(max,(parseInt(arr[i][0])-parseInt(arr[i][1]-k)))\n }\n else{\n max = Math.max(max,parseInt(arr[i][0]));\n }\n }\n\n print(max);\n\n}\n\n\nvar nk = readline().split(\" \");\nfor(var i = 0 ; i < nk.length ; i++)nk[i] = parseInt(nk[i]);\n\nvar arr = [];\nfor(var i = 0 ; i < nk[0] ; i++){\n arr[i] = readline().split(\" \");\n}\n\nmain(nk[0],nk[1],arr)\n"}, {"source_code": ";(function () {\n\n\tvar n = readline().split(' ');\n\tvar k = +n[1];\n\tn = +n[0];\n\n\tvar x = [], f, t;\n\tfor (var i = 0; i < n; i++) {\n\t\tf = readline().split(' ').map(Number);\n\t\tt = f[1]; f = f[0];\n\n\t\tx.push( t > k ? f -(t-k) : f );\n\t}\n\n\tprint( Math.max.apply(null, x) );\n\n}).call(this)"}, {"source_code": "var tok = null;\nvar index = 0;\nfunction next() {\n while (tok == null || index == tok.length) {\n tok = readline().split(' ');\n index = 0;\n }\n var res = tok[index++];\n return res;\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nfunction sortNumber(a, b) {\n return a - b;\n}\n\nfunction reverse(s) {\n var rS = \"\";\n for (var i = 0; i < s.length; i++) {\n rS += s.charAt(s.length - 1 - i);\n }\n return rS;\n}\n\nfunction main() {\n var n = nextInt();\n var k = nextInt();\n var f = nextInt();\n var t = nextInt();\n var joy = f;\n if (t > k) {\n joy = f - t + k;\n }\n var max = joy;\n for (var i = 1; i < n; i++) {\n f = nextInt();\n t = nextInt();\n joy = f;\n if (t > k) {\n joy = f - t + k;\n }\n if (joy > max) {\n max = joy;\n }\n }\n print(max);\n}\n\nmain();\n"}, {"source_code": "\n// 276A \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u043e\u0431\u0435\u0434\u044b \n\n// var n = parseInt(readline());\n\nvar input_line = readline().split(' ').map(Number);\n\nvar n = input_line[0];\nvar k = input_line[1];\n\nvar max = - 1000000000;\nvar arr = [];\nvar f;\n\nfor (var i = 0; i < n; i++) {\n arr = readline().split(' ').map(Number);\n\n if (arr[1] > k) {\n f = arr[0] - (arr[1] - k);\n } else {\n f = arr[0]; \n };\n\n if (max < f) max = f;\n};\n\nprint(max);\n"}, {"source_code": "let inpStr = \"\";\n\nfunction calcJoy(maxTime, joyEarned, timeTaken) {\n if (timeTaken > maxTime) return joyEarned - (timeTaken - maxTime);\n else return joyEarned;\n \n}\n\nprocess.stdin.addListener(\"data\", data => {//For big amts of inp, it is passed in as multiple smaller chunks, so it must be aggregated\n inpStr += data.toString();\n});\n\nprocess.stdin.addListener(\"end\", data => {//Once all data is recieved, do the calculations\n const splitData = inpStr.split(/[\\r\\n]+/);\n const params = splitData.splice(0, 1)[0].split(\" \").map(n => parseInt(n));\n const restaurants = splitData.map(n => n.split(\" \").map(n => parseInt(n)));\n \n let best = -Infinity;\n for (let restaurant of restaurants) {\n const joy = calcJoy(params[1], restaurant[0], restaurant[1]);\n if (joy > best) best = joy;\n }\n console.log(best);\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, k;\nlet joy = -Infinity;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, k] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const [f, t] = d.split(' ').map(Number);\n\n if (k >= t) {\n joy = Math.max(joy, f);\n }\n else {\n joy = Math.max(joy, f - (t - k));\n }\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(joy);\n});\n"}], "negative_code": [{"source_code": "function calcJoy(maxTime, joyEarned, timeTaken) {\n if (timeTaken > maxTime) return joyEarned - (timeTaken - maxTime);\n else return joyEarned;\n \n}\n\nprocess.stdin.addListener(\"data\", data => {\n const splitData = data.toString().split(/[\\r\\n]+/);\n const params = splitData.splice(0, 1)[0].split(\" \").map(n => parseInt(n));\n const restaurants = splitData.map(n => n.split(\" \").map(n => parseInt(n)));\n \n let best = -Infinity;\n for (let restaurant of restaurants) {\n const joy = calcJoy(params[1], restaurant[0], restaurant[1]);\n if (joy > best) best = joy;\n }\n console.log(best);\n});\n"}, {"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar k=+l[1];\n\nvar ans=-1e9;\nprint(ans)\n\nwhile(n--){\n\tvar l=readline().split(' ').map(function(v){return+v})\n\tvar c=l[1]-k;\n\tc=c>0?l[0]-c:l[0];\n\tans=Math.max(c,ans);\n}\nprint(ans);"}], "src_uid": "1bb5b64657e16fb518d49d3c799d4823"} {"source_code": "function is_sorted(arr) {\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) return false;\n }\n return true;\n}\nvar t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n if (is_sorted(a) || (b.includes(0) && b.includes(1))) print(\"Yes\");\n else print(\"No\");\n}\n", "positive_code": [{"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInts()\n while(t--) {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n let f = true\n\n for(let i = 1; i < n; i++) {\n if(a[i] < a[i - 1]) f = false\n }\n // wr(f)\n if(f) {\n wr('Yes')\n continue\n }\n\n let no0 = 0\n let no1 = 0\n b.forEach(a => {\n if(a === 0) no0++\n else no1++\n })\n\n if((no0 >= 2 && no1 >= 1) || (no1 >= 2 && no0 >= 1)) {\n wr('Yes')\n }\n else if(n === 2 && no0 >= 1 && no1 >= 1) wr('Yes')\n else wr('No')\n }\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar alist = nextIntArray();\n\t\tvar blist = nextIntArray();\n\t\tif(blist.indexOf(0) != -1 && blist.indexOf(1) != -1){\n\t\t\toutput[i] = \"Yes\";\n\t\t\tcontinue;\n\t\t}\n\t\tvar isOK = true;\n\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\tif(alist[j] > alist[j + 1]){\n\t\t\t\tisOK = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(isOK){\n\t\t\toutput[i] = \"Yes\";\n\t\t}else{\n\t\t\toutput[i] = \"No\";\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n let i = 1;\n for (let t = 0; t < parseInt(input[0]); t += 1) {\n const nums = splbsi(input[i + 1]);\n const bit = splbsi(input[i + 2]);\n\n let countZero = 0,\n countOne = 0,\n sorted = true;\n\n for (let j = 0; j < nums.length; j += 1) {\n if (bit[j] === 0) countZero += 1;\n else countOne += 1;\n if (j !== 0) {\n if (nums[j] < nums[j - 1]) sorted = false;\n }\n }\n\n if (sorted || (countOne > 0 && countZero > 0)) console.log(\"Yes\");\n else console.log(\"No\");\n i += 3;\n }\n});\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const num = lines[acc]\n acc++\n for (let i=0; i +x)\n acc++\n const bs = lines[acc].split(' ').map(x => +x)\n acc++\n let couldBeSorted = false\n let types = [0, 0]\n for (const t of bs) {\n types[t] = 1\n }\n if (types[0] + types[1] === 2) {\n couldBeSorted = true\n }\n\n if (couldBeSorted) {\n console.log('Yes')\n } else {\n let isSorted = true\n for (let i=1; i as[i]) {\n isSorted = false\n break\n }\n }\n if (isSorted) {\n console.log('Yes')\n } else {\n console.log('No')\n }\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// function sol(n, m, matrix) {\n// \tconsole.log(n, m, matrix);\n// }\n\n// sol(12,12,4)\n\nfunction main() {\n\n\tconst t = parseInt(readLine(), 10);\n\n\tfor (let tNum = 0; tNum < t; tNum++) {\n\t\t\tconst elementsNum = parseInt(readLine(), 10);\n\n\t\t\tconst elementsArray = readLine().split(' ').map(aTemp => parseInt(aTemp, 10));\n\n\t\t\tconst operationsArray = readLine().split(' ').map(aTemp => parseInt(aTemp, 10));\n\n\t\t\tlet isSorted = true;\n\n\t\t\tlet max = elementsArray[0];\n\t\t\telementsArray.every(elem => {\n\t\t\t\tif (elem >= max) {\n\t\t\t\t\tmax = elem;\n\n\t\t\t\t\treturn true;\n\t\t\t\t} else {\n\t\t\t\t\tisSorted = false;\n\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tlet zeroCount = 0;\n\t\t\tlet oneCount = 0;\n\n\t\t\toperationsArray.forEach(op => {\n\t\t\t\tif (op == 0) {\n\t\t\t\t\tzeroCount++;\n\t\t\t\t} else {\n\t\t\t\t\toneCount++;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tconst canSort = zeroCount && oneCount;\n\n\t\t\tconsole.log(isSorted || canSort ? 'YES' : 'NO');\n\t}\n\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n\n for(let r=0;r {\n// var input = [\"2\", \"4\", \"10 5 20 30\", \"0 1 0 1\", \"4\", \"10 5 20 30\", \"1 1 1 1\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar n = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n\nvar checksort = (arr) => {\n for(var i = 0; i < arr.length - 1; i++){\n if(arr[i] > arr[i+1]){\n return false;\n }\n }\n return true;\n}\n\nvar step = () => {\n var size = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n var numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n var types = readline().split(\" \").map(function(x) { return parseInt(x); });\n if(checksort(numbers)){\n print(\"Yes\")\n }\n else {\n if(types.every(x => x == 1) || types.every(x => x == 0)){\n print(\"No\")\n }\n else {\n print(\"Yes\")\n }\n }\n}\n\nfor(var i = 0; i < n; i++){\n step();\n}\n\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n var els = readNumArray();\n var vals = readNumArray();\n var vals1 = vals.filter((el) => el);\n var nonConst = vals1.length > 0 && vals1.length < n;\n if (nonConst) {\n print(\"Yes\");\n continue;\n }\n var last = 0;\n for (var j = 0; j < n; j++) {\n if (els[j] - last < 0) {\n print(\"No\");\n break;\n }\n last = els[j];\n\n if (j === n - 1) {\n print(\"Yes\");\n }\n }\n }\n\n}\n\nmain();\n"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n print(a, b);\n var fail = false;\n for (var i = 0; i < n; i++) {\n if (fail) break;\n for (var j = i + 1; j < n; j++) {\n if (a[i] > a[j] && b[i] == b[j]) {\n fail = true;\n break;\n }\n }\n }\n if (fail) print(\"No\");\n print(\"Yes\");\n}\n"}, {"source_code": "function is_sorted(arr) {\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] < arr[i - 1]) return false;\n }\n return true;\n}\nvar t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n if (is_sorted(a) || (a.includes(0) && a.includes(1))) print(\"Yes\");\n else print(\"No\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var fail = false;\n for (var i = 0; i < n; i++) {\n if (fail) break;\n for (var j = i + 1; j < n; j++) {\n if (a[i] > a[j] && b[i] == b[j]) {\n fail = true;\n break;\n }\n }\n }\n if (fail) print(\"No\");\n else print(\"Yes\");\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var n = parseInt(readline());\n var a = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var b = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var fail;\n for (var i = 0; i < n; i++) {\n if (fail) break;\n for (var j = i + 1; j < n; j++) {\n if (a[i] > a[j] && b[i] == b[j]) {\n fail = true;\n break;\n }\n }\n }\n if (fail) print(\"No\");\n print(\"Yes\");\n}\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var n = +readline();\n var els = readNumArray();\n var vals = readNumArray();\n var last0 = 0;\n var last1 = 0;\n for (var j = 0; j < n; j++) {\n if (vals[j] === 0) {\n if (els[j] - last0 < 0) {\n print(\"No\");\n break;\n }\n last0 = els[j];\n }\n if (vals[j] === 1) {\n if (els[j] - last1 < 0) {\n print(\"No\");\n break;\n }\n last1 = els[j];\n }\n if (j === n - 1) {\n print(\"Yes\");\n }\n }\n }\n}\n\nmain();"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInts()\n while(t--) {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n let f = true\n a.sort((a, b) => {\n if(a > b) {\n f = false\n }\n return a - b\n })\n if(f) {\n wr('Yes')\n continue\n }\n\n let no0 = 0\n let no1 = 0\n b.forEach(a => {\n if(a === 0) no0++\n else no1++\n })\n\n if((no0 >= 2 && no1 >= 1) || (no1 >= 2 && no0 >= 1)) {\n wr('Yes')\n }\n else wr('No')\n }\n}\n"}, {"source_code": "// const bg = require('big-integer')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\nconst MOD1 = 1000000007\n\nfunction alpha(c = 'A') {\n return [...{\n _b: c === 'A' ? 65 : 97,\n _i: -1,\n [Symbol.iterator]() {\n return this\n },\n next() {\n this._i++\n if (this._i === 26) return {done: true}\n else return {done: false, value: String.fromCharCode(this._i + this._b)}\n }\n }]\n}\n\nclass rc {\n static construct() {\n this.input = ''\n this.ptr = 0\n }\n static readString() {\n return this.input[this.ptr++]\n }\n\n static readStrings() {\n return this.input[this.ptr++].split(' ')\n }\n\n static readInt() {\n return +this.readString()\n }\n\n static readInts() {\n return this.readStrings().map(a => +a)\n }\n\n static readBigInteger() {\n return bg(this.readString())\n }\n\n static readBigIntegers() {\n return this.readStrings().map(a => bg(a))\n }\n}\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nrc.construct()\n// bc.construct()\nprocess.stdin.on('data', (i) => {\n rc.input += i\n})\n\nprocess.stdin.on('end', () => {\n rc.input = rc.input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction main() {\n let t = rc.readInts()\n while(t--) {\n const n = rc.readInt()\n const a = rc.readInts()\n const b = rc.readInts()\n let f = true\n\n for(let i = 1; i < n; i++) {\n if(a[i] < a[i - 1]) f = false\n }\n // wr(f)\n if(f) {\n wr('Yes')\n continue\n }\n\n let no0 = 0\n let no1 = 0\n b.forEach(a => {\n if(a === 0) no0++\n else no1++\n })\n\n if((no0 >= 2 && no1 >= 1) || (no1 >= 2 && no0 >= 1)) {\n wr('Yes')\n }\n else wr('No')\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n\n for(let r=0;r a-b);\n\n for(let i=0;i a[j]) {\n [a[i], a[j]] = [a[j], a[i]];\n [b[i], b[j]] = [b[j], b[i]]; \n }\n }\n \n }\n\n \n let notSorted = false;\n for(let i=0;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n\n for(let r=0;r a-b);\n\n for(let i=1;i {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction main() {\n let range = parseInt(readline());\n\n for(let r=0;r a-b);\n\n let notSorted = false;\n for(let i=0;i {\n s[i] = i ? s[i - 1] + x : x\n max[i] = i ? Math.max(max[i - 1], s[i]) : s[i]\n // min = Math.min(min, s[i])\n })\n const sum = s[n - 1]\n\n const ans = b.map(x => {\n if (sum > 0) {\n // let k = Math.floor((x - max[n - 1]) / sum)\n let k = Math.ceil((x - max[n - 1]) / sum)\n if (k < 0) k = 0\n const idx = binarySearch(0, n - 1, i => k * sum + max[i] < x)\n // console.log('sb', k, idx, s)\n // console.log('sb2', k * sum + s[idx], x)\n return k * n + idx + 1\n } else {\n const idx = binarySearch(0, n - 1, i => max[i] < x)\n // console.log('sb', s, idx)\n return idx === n - 1 ? -1 : idx + 1\n }\n })\n return ans.join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n", "positive_code": [{"source_code": "try {\r\n require('codeforces')\r\n} catch (e) {\r\n}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet res = [];\r\n\r\nfunction print(val) {\r\n if (val !== undefined) {\r\n res.push(val)\r\n } else {\r\n console.log(res.join(' '))\r\n res = [];\r\n }\r\n}\r\n\r\n\r\nfunction find() {\r\n let [n, m] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let x = readline().split(' ').map(i => +i);\r\n let sum_a = 0;\r\n let pref = {};\r\n let pref_s = [0];\r\n for (let j = 0; j < n; j++) {\r\n sum_a += a[j]\r\n if (pref[sum_a] === undefined) {\r\n pref[sum_a] = j\r\n }\r\n if (a[j] > 0 && sum_a > pref_s[pref_s.length - 1]) {\r\n pref_s.push(sum_a)\r\n }\r\n }\r\n for (let i = 0; i < x.length; i++) {\r\n let j = x[i]\r\n let ans = 0;\r\n let my_pref;\r\n let tmp;\r\n if (j <= pref_s[pref_s.length - 1]) {\r\n my_pref = j\r\n } else {\r\n if (sum_a <= 0) {\r\n print('-1');\r\n continue;\r\n } else {\r\n tmp = Math.ceil((j - pref_s[pref_s.length - 1]) / sum_a)\r\n my_pref = Math.max(0, j - tmp * sum_a)\r\n ans += tmp * n\r\n }\r\n }\r\n let ind_min = 1\r\n let ind_max = pref_s.length - 1\r\n while (ind_min !== ind_max) {\r\n let ind_new = (ind_min + ind_max) >> 1\r\n if (pref_s[ind_new] < my_pref) {\r\n ind_min = ind_new + 1\r\n } else {\r\n ind_max = ind_new\r\n }\r\n }\r\n print(ans + pref[pref_s[ind_max]])\r\n }\r\n print();\r\n}\r\n\r\nlet n = readline() * 1\r\nfor (let i = 0; i < n; i++) {\r\n find()\r\n}\r\n"}], "negative_code": [{"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [0];\r\n let indexes = [0];\r\n let sum = 0;\r\n let max = 0;\r\n let m = {}\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max && !m[sum]) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n m[sum] = i\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for (let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x) {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n if (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n\r\n\r\n let ind_min = 1\r\n let ind_max = indexes.length - 1\r\n while (ind_min !== ind_max) {\r\n let ind_new = (ind_min + ind_max) >> 1\r\n if (increase[ind_new] < x) {\r\n ind_min = ind_new + 1\r\n } else {\r\n ind_max = ind_new\r\n }\r\n // if (ind_max < ind_min) ind_min = ind_max\r\n }\r\n // console.log('=> ', indexes[ind_max], {ind_max, increase, indexes, time}, time + indexes[ind_max])\r\n return time + indexes[ind_max]\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n let m = {}\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max && !m[sum]) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n m[sum] = i\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for (let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x) {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n\r\n\r\n let ind_min = 1\r\n let ind_max = indexes.length - 1\r\n while (ind_min !== ind_max) {\r\n let ind_new = (ind_min + ind_max) >> 1\r\n if (increase[ind_new] < x) {\r\n ind_min = ind_new + 1\r\n } else {\r\n ind_max = ind_new\r\n }\r\n if (ind_max < ind_min) ind_min = ind_max\r\n }\r\n // console.log('=> ', {ind_max, increase, indexes, time}, time + indexes[increase[ind_max]])\r\n return time + indexes[increase[ind_max]]\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\n\r\nfunction norm(a, y, c, l, h, f) {\r\n if (typeof c === 'function') {\r\n return f(a, y, c, (l === undefined) ? 0 : l | 0, (h === undefined) ? a.length - 1 : h | 0);\r\n }\r\n return f(a, y, undefined, (c === undefined) ? 0 : c | 0, (l === undefined) ? a.length - 1 : l | 0);\r\n}\r\n\r\nfunction ge(a, y, c = undefined, l = 0, h = 0) {\r\n var i = h + 1;\r\n while (l <= h) {\r\n var m = (l + h) >>> 1, x = a[m];\r\n var p = (c !== undefined) ? c(x, y) : (x - y);\r\n if (p >= 0) { i = m; h = m - 1 } else { l = m + 1 }\r\n }\r\n return i;\r\n};\r\n\r\nfunction gee(a, y, c, l, h) { return norm(a, y, c, l, h, ge)}\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n let m = {}\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n m[sum] = i\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n if (x) {\r\n\r\n let index = ge(increase, x);\r\n return time + (index === -1 ? 0 : indexes[index])\r\n\r\n if (x in m) {\r\n return time + m[x]\r\n }\r\n let left_index = 0;\r\n let right_index = increase.length - 1\r\n while (1) {\r\n let mid = Math.round((right_index - left_index) / 2)\r\n let index = left_index + mid\r\n if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {\r\n return time + indexes[index];\r\n }\r\n if (increase[index] > x) {\r\n right_index = index - 1\r\n } else {\r\n left_index = index\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}\r\n\r\n\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n let m = {}\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n m[i] = sum\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n if (x) {\r\n if (x in m) {\r\n return time + m[x]\r\n }\r\n for (let i = 0; i < increase.length; i++) {\r\n if (x <= increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n if (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n if (x) {\r\n let left_index = 0;\r\n let right_index = increase.length - 1\r\n while (1) {\r\n let mid = Math.round((right_index - left_index) / 2)\r\n let index = left_index + mid\r\n if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {\r\n return time + indexes[index];\r\n }\r\n if (increase[index] > x) {\r\n right_index = index - 1\r\n } else {\r\n left_index = index\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n\r\n console.log(results.join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n // while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n //}\r\n if (x) {\r\n let left_index = 0;\r\n let right_index = increase.length - 1\r\n while (1) {\r\n let mid = Math.round((right_index - left_index) / 2)\r\n let index = left_index + mid\r\n if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {\r\n return time + indexes[index];\r\n }\r\n if (increase[index] > x) {\r\n right_index = index - 1\r\n } else {\r\n left_index = index\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n\r\n console.log(results.join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (max < 1) return -1;\r\n //while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n //}\r\n if (x) {\r\n let left_index = 0;\r\n let right_index = increase.length - 1\r\n while (1) {\r\n let mid = Math.round((right_index - left_index) / 2)\r\n let index = left_index + mid\r\n if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {\r\n return time + indexes[index];\r\n }\r\n if (increase[index] > x) {\r\n right_index = index - 1\r\n } else {\r\n left_index = index\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n\r\n let map = {}\r\n let results = []\r\n for(let i = 0; i < xx.length; i++) {\r\n if (xx[i] in map) {\r\n results.push(map[xx[i]]);\r\n continue;\r\n }\r\n let result = (function (x){\r\n let time = 0;\r\n if (sum < 1) return -1;\r\n //while (x > max) {\r\n let count = parseInt((x - 1) / max)\r\n time += length * count\r\n x -= sum * count\r\n //}\r\n if (x) {\r\n let left_index = 0;\r\n let right_index = increase.length - 1\r\n while (1) {\r\n let mid = Math.round((right_index - left_index) / 2)\r\n let index = left_index + mid\r\n if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {\r\n return time + indexes[index];\r\n }\r\n if (increase[index] > x) {\r\n right_index = index - 1\r\n } else {\r\n left_index = index\r\n }\r\n }\r\n }\r\n return time\r\n })(xx[i]);\r\n map[xx[i]] = result\r\n results.push(result)\r\n }\r\n console.log(results.join(' '))\r\n}"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n let count = Math.floor((x - 1) / sum)\r\n time += length * count\r\n x -= sum * count\r\n }\r\n if (x) {\r\n for (let i = 0; i < increase.length; i++) {\r\n if (x <= increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n let times = parseInt(x / max)\r\n time += length * times\r\n x -= sum * times\r\n }\r\n if (x) {\r\n for (let i = 0; i < increase.length; i++) {\r\n if (x <= increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length - 1; i >= 0; i--) {\r\n if (x <= increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\n\r\nif (n === 10000) {\r\n console.log('DAAAAA')\r\n for (let i = 1; i < 40; i++) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let data = readline();\r\n let xxx = readline();\r\n if (i === 38) {\r\n console.log('length , test => ', length, test)\r\n console.log('data: ', data)\r\n console.log('xxx: ', xxx)\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\n\r\n\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\n\r\nif (n === 10000) {\r\n console.log('DAAAAA')\r\n for (let i = 1; i < 40; i++) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let data = readline();\r\n if (i === 38) {\r\n console.log('length , test => ', length, test)\r\n console.log('data: ', data)\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\n\r\n\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\n\r\nif (n === 1000) {\r\n console.log('DAAAAA')\r\n for (let i = 1; i < 40; i++) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let data = readline();\r\n if (i === 38) {\r\n console.log('length , test => ', length, test)\r\n console.log('data: ', data)\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\n\r\n\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "try {require('codeforces')} catch (e) {}\r\nlet lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\n\r\nif (n === 1000) {\r\n for (let i = 1; i < 40; i++) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let data = readline();\r\n if (i === 38) {\r\n console.log('length , test => ', length, test)\r\n console.log('data: ', data)\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\n\r\n\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\n\r\nif (n === 1000) {\r\n for (let i = 1; i < 40; i++) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let data = readline();\r\n if (i === 38) {\r\n console.log('length , test => ', length, test)\r\n console.log('data: ', data)\r\n }\r\n }\r\n}\r\n\r\n\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}\r\n"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length; i >= 0; i--) {\r\n if (x === increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}"}, {"source_code": "let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\\n');\r\nlet index = 0;\r\nconst readline = () => lines[index++] || '';\r\n\r\nlet n = +readline();\r\nwhile (n--) {\r\n let [length, test] = readline().split(' ').map(i => +i);\r\n let a = readline().split(' ').map(i => +i);\r\n let xx = readline().split(' ').map(i => +i);\r\n let increase = [];\r\n let indexes = [];\r\n let sum = 0;\r\n let max = 0;\r\n for (let i = 0; i < a.length; i++) {\r\n sum += a[i];\r\n if (sum > max) {\r\n increase.push(sum)\r\n indexes.push(i);\r\n max = sum;\r\n }\r\n }\r\n console.log(xx.map(x => {\r\n let time = 0;\r\n if (x > max && sum < 1 || max < 1) return -1;\r\n while (x > max) {\r\n time += length\r\n x -= sum\r\n }\r\n if (x) {\r\n for (let i = increase.length - 1; i >= 0; i--) {\r\n if (x >= increase[i]) {\r\n return time + indexes[i]\r\n }\r\n }\r\n }\r\n return time\r\n }).join(' '))\r\n}"}, {"source_code": "\nvar readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var [n, m] = lines[l++].split(' ').map(Number)\n var a = lines[l++].split(' ').map(Number)\n var b = lines[l++].split(' ').map(Number)\n console.log(solve(n, m, a, b))\n }\n});\n\nfunction solve(n, m, a, b) {\n const s = []\n const max = []\n // let min = Infinity\n a.forEach((x, i) => {\n s[i] = i ? s[i - 1] + x : x\n max[i] = i ? Math.max(max[i - 1], s[i]) : s[i]\n // min = Math.min(min, s[i])\n })\n const sum = s[n - 1]\n\n const ans = b.map(x => {\n if (sum > 0) {\n let k = Math.floor((x - max[n - 1]) / sum)\n if (k < 0) k = 0\n const idx = binarySearch(0, n - 1, i => k * sum + max[i] < x)\n // console.log('sb', k, idx, s)\n // console.log('sb2', k * sum + s[idx], x)\n return k * n + idx + 1\n } else {\n const idx = binarySearch(0, n - 1, i => max[i] < x)\n // console.log('sb', s, idx)\n return idx === n - 1 ? -1 : idx + 1\n }\n })\n return ans.join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}, {"source_code": "\nvar readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var [n, m] = lines[l++].split(' ').map(Number)\n var a = lines[l++].split(' ').map(Number)\n var b = lines[l++].split(' ').map(Number)\n console.log(solve(n, m, a, b))\n }\n});\n\nfunction solve(n, m, a, b) {\n let sum = a.reduce((s, x) => s + x, 0)\n\n const s = []\n const map = {} // r -> [i]\n let cur = 0\n a.forEach((x, i) => {\n cur += x\n s[i] = cur\n let r = cur\n if (sum) {\n r = cur % sum\n if (r < 0) r += sum\n }\n\n map[r] = map[r] || []\n map[r].push(i)\n })\n\n for (let r in map) {\n if (sum > 0) {\n map[r].sort((p, q) => s[p] - s[q])\n } else if (sum < 0) {\n map[r].sort((p, q) => s[q] - s[p])\n }\n }\n\n const ans = b.map(x => {\n if (!sum) return map[x] ? map[x][0] : -1\n\n if (sum > 0) {\n let r = x % sum\n if (r < 0) r += sum\n // same r and less than x\n if (!map[r]) return -1\n let idx = binarySearch(0, map[r].length - 1, i => s[map[r][i]] <= x)\n if (idx < 0) return -1\n idx = map[r][idx]\n return n * (x - s[idx]) / sum + idx\n } else if (sum < 0) {\n const asum = -sum\n let r = x % asum\n if (r < 0) r += asum\n // same r and large than x\n if (!map[r]) return -1\n let idx = binarySearch(0, map[r].length - 1, i => s[map[r][i]] >= x)\n if (idx < 0) return -1\n idx = map[r][idx]\n return n * (x - s[idx]) / asum + idx\n } else {\n return map[x] ? map[x] : -1\n }\n })\n // console.log('sb', sum, map)\n return ans.join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "ecc9dc229b5d1f93809fb676eb6235c1"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n var n = tmp[0];\n var k = tmp[1];\n var s = new Array(n).fill(\"a\");\n var count = 1;\n while((count * (count + 1)) / 2 < k){\n count++;\n }\n var countValue = (count * (count + 1)) / 2;\n //\u53f3\u304b\u3089count+1\u306bb\u304c1\u3064\u7740\u304f\u3002\n s[n - count - 1] = \"b\";\n s[(n - count - 1) + (countValue - k + 1)] = \"b\";\n output[i] = myconv(s,0);\n }\n myout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n k = input[1];\n var res = new Array(n).fill(\"a\");\n var pos = 2,\n acc = 0;\n while (acc + pos - 1 < k) {\n acc += pos - 1;\n pos++;\n }\n res[n - pos] = \"b\";\n res[n - (k - acc)] = \"b\";\n print(res.join(\"\"));\n}\n"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n let t = getInt()\n while (t --> 0) {\n const inp = getInts()\n const n = inp[0]\n const k = inp[1]\n\n let lo = 1\n let hi = 2000000000\n\n while (lo < hi) {\n const mid = parseInt((lo + hi) / 2)\n if (sum(mid) < k) {\n lo = mid + 1\n } else {\n hi = mid\n }\n }\n\n const out = []\n for (let i = 0; i < n; ++i) out[i] = 'a'\n\n const r = k - sum(lo - 1)\n out[n - lo - 1] = 'b'\n out[n - r] = 'b'\n print(out.join(''))\n }\n}\n\nfunction sum (n) {\n return (n * (n + 1)) / 2\n}"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nvar first, current = 0;\n\nvar data = [];\n\nrl.on('line', function(line){\n if (first === undefined) {\n first = +line;\n } else {\n data.push(line.split(' '));\n current++;\n }\n\n if (first === current) rl.close();\n});\n\nrl.on('close', function() {\n data.forEach(pair => {\n const a = +pair[0];\n const b = +pair[1];\n\n let counter = b;\n let diff = 1;\n let firstPos = a - 1;\n\n while (counter - diff > 0) {\n firstPos -= 1;\n counter -= diff;\n diff += 1;\n }\n\n let lastPos = a - counter;\n\n let result = new Array(a);\n\n result = result.fill('a');\n\n result[firstPos - 1] = 'b';\n result[lastPos] = 'b';\n\n console.log(result.join(''));\n });\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, k] = readInts()\n let i = 1\n let sum = 1\n while(sum < k) {\n i ++\n sum += i\n }\n const a = new Array(n).fill('a')\n a[n - 1 - i] = 'b'\n a[n - (k - sum + i)] = 'b'\n wr(a.join(''))\n }\n}\n"}, {"source_code": "var t = Number(readline());\nfor(var r=0;rNumber(x));\n var n=a[1]-1;\n var m=0; \n while(n>m){\n m++;\n n-=m;\n }\n var res = \"\";\n var i = a[0]-2;\n for(;i>m;i--) res+=\"a\";\n res += \"b\";\n for(;i>n;i--) res+=\"a\";\n res += \"b\";\n for(;i>0;i--) res+=\"a\";\n print(res);\n}\n"}, {"source_code": "var readline = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nconst lines = [];\nlet lineIndex = -1;\n\nreadline.on(\"line\", line => {\n lines.push(line);\n});\n\nreadline.on(\"close\", () => {\n run();\n});\n\nconst getNextLine = () => {\n return lines[++lineIndex];\n};\n\n// ====================================================================\n\nconst run = () => {\n const t = Number.parseInt(getNextLine());\n for (let i = 0; i < t; i++) {\n const [a, b] = getNextLine()\n .split(\" \")\n .map(s => Number.parseInt(s));\n solve(a, b);\n }\n};\n\nconst buildResult = (n, x, y) => {\n const result = [];\n for (let i = 0; i < n; i++) {\n result.push(\"a\");\n }\n result[x] = \"b\";\n result[y] = \"b\";\n return result.reverse().join(\"\");\n};\n\nconst algBinarySearch = (from, to, comparer) => {\n if (from > to) return null;\n if (from === to) {\n if (comparer(from)) {\n return from;\n } else {\n return null;\n }\n }\n if (comparer(to)) return to;\n\n const mid = Math.floor((from + to) / 2);\n if (comparer(mid)) {\n const largerResult = algBinarySearch(mid + 1, to, comparer);\n\n if (largerResult === null) {\n return mid;\n } else {\n return largerResult;\n }\n } else {\n return algBinarySearch(from, mid - 1, comparer);\n }\n\n return null;\n};\n\nconst solve = (n, k) => {\n // If k = 1 then return the first string\n if (k === 1) {\n console.log(buildResult(n, 0, 1));\n return;\n }\n\n // Find max i (from 1 to n - 1) that: C(i, 2) < k\n const firstB =\n algBinarySearch(1, n - 2, v => {\n return (v * (v + 1)) / 2 < k;\n }) + 1;\n const secondB = firstB - ((firstB * (firstB + 1)) / 2 - k) - 1;\n console.log(buildResult(n, firstB, secondB));\n};\n"}, {"source_code": "const input = [];\n\nfunction splbsi(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n for (let i = 1; i < input.length; i += 1) {\n let [n, k] = splbsi(input[i]);\n const str = Array(n).fill(\"a\");\n\n for (let i = n - 2; i >= 0; i--) {\n if (k <= n - i - 1) {\n str[i] = \"b\";\n str[n - k] = \"b\";\n console.log(str.join(\"\"));\n break;\n }\n k -= n - i - 1;\n }\n }\n});\n"}, {"source_code": "function cons(n,a,b){\n var S = \"\";\n for(var i =1 ; i<=n ;i++ ){\n if((i==a)||(i==b)) S='b'+S;\n else S='a'+S;\n }\n return S;\n}\nvar t = Number(readline());\nvar St = [0];\nfor(var i=1 ; ;i++){\n St[i]= St[i-1]+i;\n if(St[i]>2000000000) {break;}\n}\nvar C = [];\nvar a,b , r;\nfor(var i=0 ; i {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const [n, k] = readInts()\n let i = 1\n let sum = 1\n while(sum < k) {\n i ++\n sum += i\n }\n // sum -= i\n // i--\n // wr(sum, i)\n const a = new Array(n).fill('a')\n a[n - 1 - i] = 'b'\n a[n - k - (sum - i)] = 'b'\n // wr(k - sum + i)\n // wr(n - (k - sum + i))\n a[n - (k - sum + i)] = 'b'\n wr(a.join(''))\n }\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n k = input[1];\n var i = n - 1,\n j = n - 2;\n var res = new Array(n).fill(\"a\");\n res[n - 1] = \"b\";\n res[n - 2] = \"b\";\n\n for (var xx = 0; xx < k; xx++) {\n if (i - j == 1) {\n res[j] = \"a\";\n i = n - 1;\n j--;\n } else {\n res[i] = \"a\";\n i--;\n }\n }\n res[i] = \"b\";\n res[j] = \"b\";\n print(res.join(\"\"));\n}\n"}], "src_uid": "e32f0615541d97a025bc99c3cbf5380e"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 1) return 'YES';\r\n const max = Math.max(...a);\r\n let has0 = false,\r\n has5 = false,\r\n nums = [];\r\n for (let num of a) {\r\n if (num % 10 === 0) {\r\n if (num < max) return 'NO';\r\n has0 = true;\r\n } else if (num % 5 === 0) {\r\n if (num + 5 < max) return 'NO';\r\n has5 = true;\r\n } else {\r\n nums.push(num);\r\n }\r\n }\r\n if ((has0 || has5) && nums.length) return 'NO';\r\n if (!nums.length) return 'YES';\r\n let odd = 0,\r\n even = 0;\r\n for (let i = 0; i < nums.length; i++) {\r\n let num = nums[i];\r\n while (num % 10 !== 2) {\r\n num += num % 10;\r\n }\r\n num = Math.floor(num / 10);\r\n if (num % 2 === 0) even = 1;else odd = 1;\r\n }\r\n if (odd && even) return 'NO';\r\n return 'YES';\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = await rns();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\r\nprocess.stdin.resume();process.stdin.setEncoding('utf-8');\r\nlet inputString = '';let currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n console.log(x);\r\n}\r\nfunction main() {\r\n let N = readline();\r\n const M = {'0': -1,'1': 0,'2': 0,'3': 1,'4': 2,'5': -1,'6': 1,'7': 3,'8': 2,'9': 3,};\r\n for (let test = 0; test < N; test++) \r\n {\r\n const n = Number(readline());\r\n const arr = readline().split(' ').map(Number);\r\n const getType = num => {\r\n const digit = num % 10;\r\n if (digit === 0) {\r\n return num;\r\n } else if (digit === 5) {\r\n return num + 5;\r\n }\r\n let tens = Math.floor(num / 10);\r\n let tensMod = (tens + M[digit]) % 2;\r\n return tensMod === 0 ? 'EVEN' : 'ODD';\r\n }\r\n\r\n const mapped = arr.map(getType);\r\n const wr = mapped.find(el => el !== mapped[0]);\r\n const no = wr !== undefined;\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar isZero = false;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] % 10 == 0 || list[i] % 10 == 5){\r\n\t\t\t\tisZero = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isZero){\r\n\t\t\tvar set = new Set();\r\n\t\t\tfor(var i = 0; i < N; i++){\r\n\t\t\t\tif(list[i] % 10 == 5){\r\n\t\t\t\t\tlist[i] += 5;\r\n\t\t\t\t}\r\n\t\t\t\tset.add(list[i]);\r\n\t\t\t}\r\n\t\t\tif(set.size != 1){\r\n\t\t\t\tmyout(\"No\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"Yes\");\r\n\t\t\t}\r\n\t\t\tcontinue;;\r\n\t\t}\r\n\t\tvar F = [2,4,8,16];\r\n\t\tvar G = [12,14,18,6];\r\n\t\tvar isF = false;\r\n\t\tvar isG = false;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i] += list[i] % 10;\r\n\t\t\tlist[i] += list[i] % 10;\r\n\t\t\tlist[i] += list[i] % 10;\r\n\t\t\tlist[i] += list[i] % 10;\r\n\t\t\tlist[i] %= 20;\r\n\t\t\tif(F.indexOf(list[i]) != -1){\r\n\t\t\t\tisF = true;\r\n\t\t\t}else if(G.indexOf(list[i]) != -1){\r\n\t\t\t\tisG = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isF && isG){\r\n\t\t\tmyout(\"No\");\r\n\t\t}else{\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND + 10; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND+10) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\n\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -2;\r\n break;\r\n }\r\n }\r\n }\r\n if(group < 0) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "var t = readline();\nvar track = [2, 4, 8, 16, 1, 17, 19, 13];\nfor (var c = 0; c < t; c ++)\n{\n var n = readline();\n var a = readline().split(\" \").map(x => parseInt(x))\n var w = true\n if (track.includes(a[0] % 20))\n {\n for (var i = 1; i < a.length; i ++)\n {\n if (!track.includes((a[i]) % 20))\n {\n print(\"NO\")\n i = a.length;\n w = false;\n }\n }\n }\n else if (track.includes((a[0] + 10) % 20))\n {\n for (var i = 1; i < a.length; i ++)\n {\n if (!track.includes((a[i] + 10) % 20))\n {\n print(\"NO\")\n i = a.length;\n w = false;\n }\n }\n }\n else\n {\n var x = a[0] + a[0] % 10\n for (var i = 1; i < a.length; i ++)\n {\n if (a[i] + a[i] % 10 != x)\n {\n print(\"NO\")\n i = a.length;\n w = false;\n }\n }\n }\n if (w){\n print(\"YES\")\n }\n\n}"}, {"source_code": "var n;\r\n var a;\r\n var evens = new Set([1, 2, 4, 8]);\r\n var odds = new Set([3, 6, 7, 9]);\r\n var fives = new Set([0, 5]);\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n var s = a[0];\r\n var mods = s % 10;\r\n var ans = 'YES';\r\n if (fives.has(mods)) {\r\n var ok;\r\n if (mods == 5) {\r\n ok = [s, s+5];\r\n } else {\r\n ok = [s, (Math.max(0, s-5))];\r\n }\r\n for (var i = 1; i < n; i++) {\r\n if (!ok.includes(a[i])) {\r\n ans = 'NO';\r\n break;\r\n }\r\n }\r\n } else {\r\n var set = evens.has(mods) ? evens : odds;\r\n var S = Math.floor(s / 10);\r\n for (var i = 1; i < n; i++) {\r\n var mod = a[i] % 10;\r\n if (fives.has(mod)) {\r\n ans = 'NO';\r\n break;\r\n }\r\n var I = Math.floor(a[i] / 10);\r\n if (set.has(mod)) {\r\n if (Math.abs(S - I) & 1) {\r\n ans = 'NO';\r\n break;\r\n }\r\n } else {\r\n if (!(Math.abs(S - I) & 1)) {\r\n ans = 'NO';\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const M = {\r\n '0': -1,\r\n '1': 0,\r\n '2': 0,\r\n '3': 1,\r\n '4': 2,\r\n '5': -1,\r\n '6': 1,\r\n '7': 3,\r\n '8': 2,\r\n '9': 3,\r\n };\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = Number(readline());\r\n const arr = readline().split(' ').map(Number);\r\n\r\n const getType = num => {\r\n const digit = num % 10;\r\n if (digit === 0) {\r\n return num;\r\n } else if (digit === 5) {\r\n return num + 5;\r\n }\r\n let tens = Math.floor(num / 10);\r\n let tensMod = (tens + M[digit]) % 2;\r\n return tensMod === 0 ? 'EVEN' : 'ODD';\r\n }\r\n\r\n const mapped = arr.map(getType);\r\n const wr = mapped.find(el => el !== mapped[0]);\r\n const no = wr !== undefined;\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'Yes' : 'No'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n arr.sort((a, b) => b - a)\n return arr.every(x => check(x, arr[0]))\n}\nfunction check(a, b) {\n const ra = a % 10\n const rb = b % 10\n if (ra === 5 || ra === 0 || rb === 5 || rb === 0) {\n a += a % 10\n b += b % 10\n return a === b\n }\n const o = {}\n o[2] = 1\n o[4] = 2\n o[8] = 3\n o[6] = 4\n while (!o[b % 10]) {\n b += b % 10\n }\n let sb = 4\n while (sb--) {\n b += b % 10\n }\n while (a < b) {\n const r = a % 10\n if (o[r]) break\n a += r\n }\n if (a > b) return false\n const r = (b - a) % 20\n// console.log(a, b, r)\n switch (a % 10) {\n case 2:\n return [0, 2, 6, 14].indexOf(r) >= 0\n case 4:\n return [0, 4, 12, 18].indexOf(r) >= 0\n case 8:\n return [0, 8, 14, 16].indexOf(r) >= 0\n case 6:\n return [0, 6, 8, 12].indexOf(r) >= 0\n }\n}\n"}], "negative_code": [{"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND + 10; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND+10) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\n\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -2;\r\n break;\r\n }\r\n }\r\n }\r\n if(k===843){\r\n if(group===-1){\r\n print(`A`);\r\n } else {\r\n print('B');\r\n }\r\n }\r\n if(group < 0) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -2;\r\n break;\r\n }\r\n }\r\n }\r\n if(k===843){\r\n if(group===-1){\r\n print(`A`);\r\n } else {\r\n print('B');\r\n }\r\n }\r\n if(group < 0) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -2;\r\n break;\r\n }\r\n }\r\n }\r\n if(k===844){\r\n if(group===-1){\r\n print(`A`);\r\n } else {\r\n print('B');\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -2;\r\n break;\r\n }\r\n }\r\n }\r\n if(group === -2) {\r\n print(`NO`);\r\n continue;\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 20;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -1;\r\n break;\r\n }\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 10000;\r\nvar union = Array(UPPER_BOUND + 10).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -1;\r\n break;\r\n }\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 100;\r\nvar union = Array(UPPER_BOUND + 1).fill(0);\r\nunion[0] = UPPER_BOUND;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%UPPER_BOUND);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%UPPER_BOUND)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -1;\r\n break;\r\n }\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 21;\r\nvar union = Array(UPPER_BOUND).fill(0);\r\nunion[0] = 20;\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%20);\r\n var lastNum = -1;\r\n for(var j = 0; j < n; j++) {\r\n if(group !== findUnion(nums[j]%20)) {\r\n group = -1;\r\n break;\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum < 0) {\r\n lastNum = nums[j];\r\n }\r\n if(lastNum !== nums[j]) {\r\n if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {\r\n lastNum = nums[j];\r\n continue;\r\n }\r\n group = -1;\r\n break;\r\n }\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\nvar UPPER_BOUND = 21;\r\nvar union = Array(UPPER_BOUND).fill(0);\r\nfor(var i = 1; i <= UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\nfor(var k = 0; k < t; k++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]%20);\r\n var lastNum = 1;\r\n for(var j = 0; j < n; j++) {\r\n if(nums[j]%10 === 0) {\r\n if(lastNum%5 === 0 && lastNum !== nums[j] - 5 && lastNum !== nums[j]) { //not 10-5\r\n group = -1;\r\n break;\r\n }\r\n }\r\n if(nums[j]%5 === 0) {\r\n if(lastNum%5 === 0 && Math.abs(lastNum - nums[j]) > 5) { //5 15\r\n group = -1;\r\n break;\r\n }\r\n lastNum = nums[j];\r\n }\r\n if(group !== findUnion(nums[j]%20)) {\r\n group = -1;\r\n break;\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "//preprocess disjoint set\r\nconst findUnion = (num) => {\r\n union[num] = union[num] === num? num : findUnion(union[num]);\r\n return union[num];\r\n}\r\n\r\nconst disjoint = (num1, num2) => {\r\n const group1 = findUnion(num1);\r\n const group2 = findUnion(num2);\r\n\r\n union[group1] = group2;\r\n}\r\n\r\nconst UPPER_BOUND = 200001;\r\nvar union = Array(UPPER_BOUND).fill(0);\r\nfor(var i = 1; i < UPPER_BOUND; i++) {\r\n var childNum = parseInt(i + (i % 10));\r\n if(union[i] === 0) {\r\n union[i] = i;\r\n }\r\n if(childNum>=UPPER_BOUND) {\r\n continue;\r\n }\r\n if(union[childNum] === 0) {\r\n union[childNum] = union[i];\r\n } else {\r\n disjoint(i, childNum);\r\n }\r\n}\r\n\r\nvar t = readline().split(' ').map((x) => parseInt(x));\r\n\r\nfor(var i = 0; i < t; i++) {\r\n var n = readline().split(' ').map((x) => parseInt(x));\r\n var nums = readline().split(' ').map((x) => parseInt(x));\r\n var group = findUnion(nums[0]);\r\n for(var j = 1; j < n; j++) {\r\n if(group !== findUnion(nums[j])) {\r\n group = -1;\r\n break;\r\n }\r\n }\r\n if(group === -1) {\r\n print(`No`);\r\n } else {\r\n print(`Yes`);\r\n }\r\n}\r\n"}, {"source_code": "var t = readline();\nvar track = [2, 4, 8, 16, 1, 17, 19, 13];\nfor (var c = 0; c < t; c ++)\n{\n var n = readline();\n var a = readline().split(\" \").map(x => parseInt(x))\n var t = true\n if (track.includes(a[0] % 20))\n {\n for (var i = 1; i < a.length; i ++)\n {\n if (!track.includes((a[i]) % 20))\n {\n print(\"NO\")\n i = a.length;\n t = false;\n }\n }\n }\n else if (track.includes((a[0] + 10) % 20))\n {\n for (var i = 1; i < a.length; i ++)\n {\n if (!track.includes((a[i] + 10) % 20))\n {\n print(\"NO\")\n i = a.length;\n t = false;\n }\n }\n }\n else\n {\n var x = a[0] + a[0] % 10\n for (var i = 1; i < a.length; i ++)\n {\n if (a[i] + a[i] % 10 != x)\n {\n print(\"NO\")\n i = a.length;\n t = false;\n }\n }\n }\n if (t){\n print(\"YES\")\n }\n\n}"}, {"source_code": "var t = readline();"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n if (n === 1) return 'YES';\r\n const max = Math.max(...a);\r\n let has0 = false,\r\n has5 = false,\r\n nums = [];\r\n for (let num of a) {\r\n if (num % 10 === 0) {\r\n if (num < max) return 'NO';\r\n has0 = true;\r\n } else if (num % 5 === 0) {\r\n has5 = true;\r\n } else {\r\n nums.push(num);\r\n }\r\n }\r\n if ((has0 || has5) && nums.length) return 'NO';\r\n if (!nums.length) return 'YES';\r\n for (let i = 0; i < nums.length; i++) {\r\n let num = nums[i];\r\n while (num % 10 !== 2) {\r\n num += num % 10;\r\n }\r\n nums[i] = num;\r\n }\r\n let odd = 0,\r\n even = 0;\r\n for (let num of nums) {\r\n num = Math.floor(num / 10);\r\n if (num % 2 === 0) even = 1;else odd = 1;\r\n if (odd && even) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = await rns();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n const max = Math.max(...a);\r\n let has0 = false,\r\n has5 = false,\r\n nums = [];\r\n for (let num of a) {\r\n if (num % 10 === 0) {\r\n has0 = true;\r\n if (num < max) return 'NO';\r\n } else if (num % 5 === 0) {\r\n has5 = true;\r\n } else {\r\n nums.push(num);\r\n }\r\n }\r\n if ((has0 || has5) && nums.length) return 'NO';\r\n for (let i = 0; i < nums.length; i++) {\r\n let num = nums[i];\r\n while (num % 10 !== 2) {\r\n num += num % 10;\r\n }\r\n nums[i] = num;\r\n }\r\n let odd = 0,\r\n even = 0;\r\n for (let num of nums) {\r\n num = Math.floor(num / 10);\r\n if (num & 1) odd = 1;else even = 1;\r\n if (odd && even) return 'NO';\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(r) {\r\n const rn = async () => Number(await r());\r\n const rns = async () => {\r\n return (await r()).split(' ').filter(s => s !== '').map(Number);\r\n };\r\n try {\r\n let t = Number(await r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = await rn();\r\n const a = await rns();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n const M = {\r\n '0': -1,\r\n '1': 0,\r\n '2': 0,\r\n '3': 1,\r\n '4': 2,\r\n '5': -1,\r\n '6': 1,\r\n '7': 3,\r\n '8': 2,\r\n '9': 3,\r\n };\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = Number(readline());\r\n const arr = readline().split(' ').map(Number);\r\n\r\n const getType = num => {\r\n const digit = num % 10;\r\n if (digit === 0) {\r\n return num;\r\n } else if (digit === 5) {\r\n return num + 5;\r\n }\r\n let tens = Math.floor(num / 10);\r\n let tensMod = (tens + M[digit]) % 2;\r\n return tensMod === 0 ? 'EVEN' : 'ODD';\r\n }\r\n\r\n const mapped = arr.map(getType);\r\n const no = Boolean(mapped.find(el=> el !== mapped[0]));\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'Yes' : 'No'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n arr.sort((a, b) => b - a)\n return arr.every(x => check(x, arr[0]))\n}\nfunction check(a, b) {\n const ra = a % 10\n const rb = b % 10\n if (ra === 5 || ra === 0 || rb === 5 || rb === 0) {\n a += a % 10\n b += b % 10\n return a === b\n }\n const o = {}\n o[2] = 1\n o[4] = 2\n o[8] = 3\n o[6] = 4\n while (!o[b % 10]) {\n b += b % 10\n }\n while (a < b) {\n const r = a % 10\n if (o[r]) break\n a += r\n }\n if (a > b) return false\n const r = (b - a) % 20\n// console.log(a, b, r)\n switch (a % 10) {\n case 2:\n return [0, 2, 6, 14].indexOf(r) >= 0\n case 4:\n return [0, 4, 12, 18].indexOf(r) >= 0\n case 8:\n return [0, 8, 14, 16].indexOf(r) >= 0\n case 6:\n return [0, 6, 8, 12].indexOf(r) >= 0\n }\n}\n"}], "src_uid": "2d27f3530aa140be0add639a1edfd880"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n [n, k] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const min = Math.min(...arr);\n const max = Math.max(...arr);\n let ans = min + k;\n\n if (min + k < max - k) {\n ans = - 1;\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "\"use strict\";\n\nvar q = +readline()\n\nwhile (q--) {\n var input = readline().split(' ').map(value => +value);\n var n = input[0];\n var k = input[1];\n var A = readline().split(' ').map(value => +value);\n\n A.sort(function(a, b) {return a - b;});\n var result = A[0] + k;\n if (result < (A[n-1] - k)) {\n write('-1\\n');\n } else {\n write(result + '\\n');\n }\n}"}, {"source_code": "var qs = readline().split(' ').map(Number);\n\nfor (var i = 0; i < qs; i++) {\n var _ = readline().split(' ').map(Number);\n var n = _[0];\n var k = _[1];\n\n var goods = readline().split(' ').map(Number);\n \n var max = maxEl(goods);\n var min = minEl(goods);\n\n if (min + k >= max - k) {\n print(min + k);\n } else {\n print(-1);\n }\n}\n\nfunction minEl(arr) {\n var min = arr[0];\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] < min) {\n min = arr[i];\n }\n }\n\n return min;\n}\n\nfunction maxEl(arr) {\n var max = arr[0];\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n\n return max;\n}\n"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var q = read.number();\n var res = '';\n while (q) {\n q--;\n\n var line = read.arrNumber(' ');\n var n = line[0];\n var k = line[1];\n var a = read.arrNumber(' ');\n\n var max = a[0], min = a[0];\n for (var i = 0; i < n; i++) {\n if (max < a[i]) {\n max = a[i];\n }\n if (min > a[i]) {\n min = a[i];\n }\n }\n\n if ((max - min) > 2 * k) {\n res += '-1\\n';\n } else {\n res += (min + k) + '\\n';\n }\n\n }\n print(res);\n\n}());\n"}, {"source_code": "let input = \"\";\nconst { EOL } = require(\"os\");\nprocess.stdin.on(\"data\", i => (input += i));\n\nprocess.stdin.on(\"end\", async () => {\n console.log(func(input));\n});\n\nconst func = a => {\n let result = \"\";\n const [q, ...queries] = a.split(EOL);\n for (let i = 0; i < q; i++) {\n const [n, maxPriceDiff] = queries.shift().split(\" \").map(a => parseInt(a));\n const products = queries\n .shift()\n .split(\" \")\n .map(a => parseInt(a))\n .sort((a, b) => a - b);\n result +=\n (Math.abs(products[products.length - 1] - products[0]) <= maxPriceDiff * 2\n ? products[0] + maxPriceDiff\n : -1) + EOL;\n }\n return result;\n};\n\nmodule.exports = func;\n"}], "negative_code": [{"source_code": "var qs = readline().split(' ').map(Number);\n\nfor (var i = 0; i < qs; i++) {\n var _ = readline().split(' ').map(Number);\n var n = _[0];\n var k = _[1];\n\n var goods = readline().split(' ').map(Number);\n\n var sum = goods.reduce(function(prev, cur) {\n return prev + cur;\n });\n\n var avg = Math.ceil(sum / n);\n \n var max = maxEl(goods);\n var min = minEl(goods);\n\n if (avg - min > k || max - avg > k) {\n print(-1);\n } else if (avg - min < k) {\n print(min + k);\n } else {\n print(avg);\n }\n}\n\nfunction minEl(arr) {\n var min = arr[0];\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] < min) {\n min = arr[i];\n }\n }\n\n return min;\n}\n\nfunction maxEl(arr) {\n var max = arr[0];\n for (var i = 1; i < arr.length; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n\n return max;\n}\n"}, {"source_code": "\"use strict\";\n\nvar q = +readline()\n\nwhile (q--) {\n var input = readline().split(' ').map(value => +value);\n var n = input[0];\n var k = input[1];\n var A = readline().split(' ').map(value => +value);\n\n A.sort();\n var result = A[0] + k;\n if (result < (A[n-1] - k)) {\n write('-1\\n');\n } else {\n write(result + '\\n');\n }\n}"}], "src_uid": "3b158306d335459ff55dcf29e46010e8"} {"source_code": "function kek(s)\n{\n for (var i=0;i<=20;i++)\n {\n s=s.replace(\"u\",\"oo\")\n s=s.replace(\"kh\",\"h\");\n }\n return s;\n}\n\nvar n=+readline()\nvar x=[]\nwhile(n--)\n{\n x.push(kek(readline()))\n}\nx.sort()\nvar res=1\nfor (var i=1;i { return parseFloat(item); });\n //****************************************** DO IT HERE*/\n var A = myArr[0], B = myArr[1];\n var N = parseInt(myArr[2]);\n var helper = 0;\n if(A==0 && B==0) helper = 0;\n else if (A==0 && B!=0) helper = -2;\n else helper = B/A;\n\n var needMinus = false;\n if(helper<0 && N%2)\n {\n needMinus = true;\n helper = -helper;\n }\n var ans = NthRoot(helper,N);\n if(ans>0)\n {\n ans+=0.0001;\n ans = Math.trunc(ans*1000);\n ans /=1000;\n }\n\n var temp = Math.trunc(ans);\n if(ans == temp)\n console.log(needMinus? \"-\" + ans : ans.toString());\n else\n console.log(\"No solution\");\n \n \n\n rl.close();\n /*************************************** */\n\n\n})\n\nfunction NthRoot(Base, n) {\n return Math.pow(Base, 1.0 / n);\n}\n\n", "positive_code": [{"source_code": "'use strict'\n\nlet lll = readline().split(' ').map(v => parseInt(v))\n\nlet bo = lll[0]\nlet bn = lll[1]\nlet n = lll[2]\n\nlet res = 'No solution'\n;(function () {\n for (let i = -1000; i <= 1000; i++) {\n if (bo * Math.pow(i, n) == bn) return res = i\n }\n})()\n\nprint(res)"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n\n\n\nrl.on('line', function (input) {\n var myArr = input.split(' ').map(item => { return parseFloat(item); });\n //****************************************** DO IT HERE*/\n var A = myArr[0], B = myArr[1];\n var N = parseInt(myArr[2]);\n var helper = 0;\n if(A==0 && B==0) helper = 0;\n else if (A==0 && B!=0) helper = -2;\n else helper = B/A;\n\n var needMinus = false;\n if(helper<0 && N%2)\n {\n needMinus = true;\n helper = -helper;\n }\n var ans = NthRoot(helper,N);\n if(ans>0)\n {\n ans+=0.0001;\n ans = Math.trunc(ans*1000);\n ans /=1000;\n }\n\n var temp = Math.trunc(ans);\n if(ans == temp)\n console.log(needMinus? \"-\" + ans : ans.toString());\n else\n console.log(\"No Solution\");\n \n \n\n rl.close();\n /*************************************** */\n\n\n})\n\nfunction NthRoot(Base, n) {\n return Math.pow(Base, 1.0 / n);\n}\n\n"}], "src_uid": "8a9adc116abbd387a6a64dd754436f8a"} {"source_code": "const {EOL} = require('os');\r\nlet i = ''\r\nprocess.stdin.on('data', c => i += c);\r\nprocess.stdin.on('end', () => {\r\n main(i);\r\n})\r\n\r\nfunction circularShift(str) {\r\n return str[str.length - 1] + str.slice(0, str.length - 1);\r\n}\r\n\r\nfunction getEqualityArray(shortString, longString) {\r\n let res = [], max = 0, len = 0;;\r\n for (let i = 0; i < shortString.length; i++) {\r\n if (shortString[i] === longString[i]) {\r\n if (shortString[i] === '$') {\r\n res.push('$');\r\n len = 0;\r\n } else {\r\n res.push(1);\r\n len++;\r\n }\r\n } else {\r\n res.push(0);\r\n len = 0;\r\n }\r\n if (len > max) max = len;\r\n }\r\n return {arr: res, max: max};\r\n}\r\n\r\nfunction getLcsLength(str1, str2) {\r\n if (str1 === str2) return str1.length;\r\n let shortString, longString;\r\n if (str1.length <= str2.length) {\r\n shortString = str1 + '$';\r\n longString = str2 + '$';\r\n } else {\r\n shortString = str2 + '$';\r\n longString = str1 + '$';\r\n }\r\n let maxLCSLength = 0;\r\n let longStringCopy = longString;\r\n\r\n for (let i = 0; i < longStringCopy.length; i++) {\r\n let ea = getEqualityArray(shortString, longStringCopy);\r\n if (ea.max > maxLCSLength) maxLCSLength = ea.max;\r\n longStringCopy = circularShift(longStringCopy);\r\n }\r\n\r\n return maxLCSLength;\r\n}\r\n\r\nfunction findMinChanges(a, b) {\r\n const lcs = getLcsLength(a, b);\r\n return a.length + b.length - 2 * lcs\r\n}\r\n\r\nfunction main (input) {\r\n let index = 0;\r\n const lines = input.split(EOL);\r\n \r\n const t = lines[index++];\r\n \r\n for (let i = 0; i < t; i++) {\r\n let a = lines[index++];\r\n let b = lines[index++];\r\n console.log(findMinChanges(a, b));\r\n }\r\n}", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let s1 = readline().trim().split(\"\");\r\n let s2 = readline().trim().split(\"\");\r\n if (s1.length < s2.length) [s1, s2] = [s2, s1];\r\n let cnt = 0;\r\n for (let i = 0; i < s1.length; i++) {\r\n let k = i;\r\n for (let j = 0; j < s2.length; j++) {\r\n let s = j,\r\n k = i,\r\n tp = 0;\r\n while (k < s1.length && s1[k] === s2[s]) {\r\n tp++;\r\n k++;\r\n s++;\r\n }\r\n cnt = Math.max(cnt, tp);\r\n }\r\n }\r\n if (cnt === s1.length && cnt === s2.length) console.log(0);\r\n else console.log(s1.length + s2.length - cnt * 2);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b) => {\r\n let res = LongestCommonSubstringLen(a, b);\r\n pr(a.length + b.length - res * 2);\r\n};\r\n\r\nconst LongestCommonSubstringLen = (A, B) => {\r\n let m = A.length;\r\n let n = B.length;\r\n let maxLen = 0;\r\n let dp = initialize2DArrayNew(m + 1, n + 1);\r\n for (let i = 1; i <= m; i++) {\r\n for (let j = 1; j <= n; j++) {\r\n if (A[i - 1] == B[j - 1]) {\r\n dp[i][j] = dp[i - 1][j - 1] + 1;\r\n if (dp[i][j] > maxLen) {\r\n maxLen = dp[i][j];\r\n }\r\n }\r\n }\r\n }\r\n return maxLen;\r\n};\r\n\r\nconst initialize2DArrayNew = (m, n) => {\r\n let data = [];\r\n for (let i = 0; i < m; i++) {\r\n let tmp = new Array(n).fill(0);\r\n data.push(tmp);\r\n }\r\n return data;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b) => {\r\n let res = LongestCommonSubstring(a, b).length;\r\n pr(a.length + b.length - res * 2);\r\n};\r\n\r\nconst LongestCommonSubstring = (A, B) => {\r\n let m = A.length;\r\n let n = B.length;\r\n let maxLen = 0;\r\n let endIdx = m;\r\n let dp = initialize2DArrayNew(m + 1, n + 1);\r\n for (let i = 1; i <= m; i++) {\r\n for (let j = 1; j <= n; j++) {\r\n if (A[i - 1] == B[j - 1]) {\r\n dp[i][j] = dp[i - 1][j - 1] + 1;\r\n if (dp[i][j] > maxLen) {\r\n maxLen = dp[i][j];\r\n endIdx = i;\r\n }\r\n }\r\n }\r\n }\r\n return A.slice(endIdx - maxLen, endIdx);\r\n};\r\n\r\n\r\nconst initialize2DArrayNew = (m, n) => {\r\n let data = [];\r\n for (let i = 0; i < m; i++) {\r\n let tmp = new Array(n).fill(0);\r\n data.push(tmp);\r\n }\r\n return data;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n \r\nlet TC = 0;\r\nlet A, B;\r\nreadline.on('line', line => {\r\n if (TC === 0) {\r\n TC = Number(line.toString());\r\n return;\r\n }\r\n if (!A) {\r\n A = line.toString();\r\n return;\r\n }\r\n B = line.toString();\r\n if (A.length > B.length) {\r\n [B, A] = [A, B];\r\n }\r\n let maxMatchLength = 0;\r\n for (let i = 0; i < A.length; i++) {\r\n for (let j = 1; j < A.length - i + 1; j++) {\r\n const t = A.substr(i, j);\r\n if (B.indexOf(t) > -1) {\r\n const matchLength = t.length;\r\n if (maxMatchLength < matchLength) {\r\n maxMatchLength = matchLength;\r\n }\r\n }\r\n }\r\n }\r\n console.log((A.length - maxMatchLength) + (B.length - maxMatchLength));\r\n\r\n A = undefined; B = undefined;\r\n TC--;\r\n if (TC === 0) {\r\n process.exit();\r\n }\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nconst getStringByLength = (strA, strB) => {\r\n const lenA = strA.length;\r\n const lenB = strB.length;\r\n\r\n if (lenA < lenB) return [strA, strB];\r\n\r\n return [strB, strA];\r\n};\r\nfunction main() {\r\n let num = parseInt(readline());\r\n while (num--) {\r\n let str1 = readline();\r\n let str2 = readline();\r\n const [strA, strB] = getStringByLength(str1, str2);\r\n let start = 0;\r\n let max = 0;\r\n for (let i = 0; i < strA.length; i++) {\r\n if (strB.includes(strA.substring(start, i + 1))) {\r\n max = Math.max(max, i - start + 1);\r\n } else start++;\r\n }\r\n print(strA.length - max + strB.length - max);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nconst getStringByLength = (strA, strB) => {\r\n const lenA = strA.length;\r\n const lenB = strB.length;\r\n \r\n if (lenA < lenB) return [strA, strB];\r\n \r\n return [strB, strA];\r\n};\r\nfunction main() {\r\n var num = parseInt(readline())\r\n\twhile(num--){\r\n var str1 = readline()\r\n var str2 = readline()\r\n const [strA, strB] = getStringByLength(str1, str2)\r\n var start = 0\r\n var max = 0\r\n for(let i = 0; i < strA.length;i++){\r\n if(strB.includes(strA.substring(start, i + 1))){\r\n max = Math.max(max, i - start +1)\r\n }\r\n else start++\r\n }\r\n print(strA.length - max + strB.length - max)\r\n }\r\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nconst getStringByLength = (strA, strB) => {\n const lenA = strA.length;\n const lenB = strB.length;\n\n if (lenA < lenB) return [strA, strB];\n\n return [strB, strA];\n};\n\nconst main = () => {\n const rows = parseInt(readline());\n\n for (let idx = 0; idx < rows; idx++) {\n const wordA = readline();\n const wordB = readline();\n\n const [strA, strB] = getStringByLength(wordA, wordB);\n let startPos = 0;\n let maxLength = 0;\n for (let jdx = 0; jdx < strA.length; jdx++) {\n const wordSoFar = strA.substring(startPos, jdx + 1);\n if (strB.includes(wordSoFar)) {\n maxLength = Math.max(maxLength, jdx - startPos + 1);\n } else {\n startPos += 1;\n }\n }\n\n const answer = strA.length - maxLength + strB.length - maxLength;\n console.log(answer);\n }\n};\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction solve() {\r\n var a = read();\r\n var b = read();\r\n var maxCommon = 0;\r\n for (var as = 0; as < a.length; as++) {\r\n for (var af = as + 1; af <= a.length; af++) {\r\n for (var bs = 0; bs < b.length; bs++) {\r\n for (var bf = bs + 1; bf <= b.length; bf++) {\r\n if (bf - bs !== af - as) {\r\n continue;\r\n }\r\n if (a.substring(as, af) !== b.substring(bs, bf)) {\r\n continue;\r\n }\r\n if (af - as > maxCommon) {\r\n maxCommon = af - as;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n write(a.length + b.length - maxCommon * 2);\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var n = Number(input[0]);\r\n var j = 1;\r\n for (let i = 1; i <= n; i++) {\r\n var str1 = input[j];\r\n j++;\r\n var str2 = input[j];\r\n j++;\r\n function minOperation(str1, str2) {\r\n var max = 0;\r\n for (var i = 0; i < str1.length; i++) {\r\n var str = \"\";\r\n for (var j = i; j < str1.length; j++) {\r\n str += str1[j];\r\n if (str2.indexOf(str) >= 0) {\r\n max = Math.max(max, str.length);\r\n }\r\n }\r\n }\r\n return (str1.length - max) + (str2.length - max);\r\n }\r\n console.log(minOperation(str1, str2));\r\n }\r\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar a = next();\r\n\t\tvar b = next();\r\n\t\tvar count = a.length + b.length;\r\n\t\tfor(var j = 0; j < a.length; j++){\r\n\t\t\tfor(var k = j; k < a.length; k++){\r\n\t\t\t\tvar na = a.substring(j, k + 1);\r\n\t\t\t\tfor(var l = 0; l < b.length; l++){\r\n\t\t\t\t\tfor(var m = l; m < b.length; m++){\r\n\t\t\t\t\t\tvar nb = b.substring(l, m + 1);\r\n\t\t\t\t\t\tif(na == nb){\r\n\t\t\t\t\t\t\tcount = Math.min(count, (a.length - na.length) + (b.length - nb.length));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(count);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n\r\n var a = readline()\r\n var b = readline()\r\n var string = longestCommonSubstring(a,b)\r\n\r\n // if(!string) return console.log(a.length + b.length)\r\n\r\n console.log(a.length + b.length - 2*string.length)\r\n })\r\n}\r\nfunction longestCommonSubstring(string1, string2) {\r\n // Convert strings to arrays to treat unicode symbols length correctly.\r\n // For example:\r\n // '\ud800\udf35'.length === 2\r\n // [...'\ud800\udf35'].length === 1\r\n const s1 = [...string1];\r\n const s2 = [...string2];\r\n\r\n // Init the matrix of all substring lengths to use Dynamic Programming approach.\r\n const substringMatrix = Array(s2.length + 1).fill(null).map(() => {\r\n return Array(s1.length + 1).fill(null);\r\n });\r\n\r\n // Fill the first row and first column with zeros to provide initial values.\r\n for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {\r\n substringMatrix[0][columnIndex] = 0;\r\n }\r\n\r\n for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {\r\n substringMatrix[rowIndex][0] = 0;\r\n }\r\n\r\n // Build the matrix of all substring lengths to use Dynamic Programming approach.\r\n let longestSubstringLength = 0;\r\n let longestSubstringColumn = 0;\r\n let longestSubstringRow = 0;\r\n\r\n for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {\r\n for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {\r\n if (s1[columnIndex - 1] === s2[rowIndex - 1]) {\r\n substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;\r\n } else {\r\n substringMatrix[rowIndex][columnIndex] = 0;\r\n }\r\n\r\n // Try to find the biggest length of all common substring lengths\r\n // and to memorize its last character position (indices)\r\n if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {\r\n longestSubstringLength = substringMatrix[rowIndex][columnIndex];\r\n longestSubstringColumn = columnIndex;\r\n longestSubstringRow = rowIndex;\r\n }\r\n }\r\n }\r\n\r\n if (longestSubstringLength === 0) {\r\n // Longest common substring has not been found.\r\n return '';\r\n }\r\n\r\n // Detect the longest substring from the matrix.\r\n let longestSubstring = '';\r\n\r\n while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {\r\n longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;\r\n longestSubstringRow -= 1;\r\n longestSubstringColumn -= 1;\r\n }\r\n\r\n return longestSubstring;\r\n}\r\n\r\n\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let s1 = readline().trim().split(\"\");\r\n let s2 = readline().trim().split(\"\");\r\n let cnt = 0;\r\n for (let i = 0; i < s1.length; i++) {\r\n let k = 0,\r\n l = i;\r\n for (let j = 0; j < s2.length; j++) {\r\n if (s2[j] === s1[l] && l < s1.length) {\r\n k++;\r\n l++;\r\n } else {\r\n cnt = Math.max(cnt, k);\r\n l = i;\r\n if (k !== 0) j--;\r\n k = 0;\r\n }\r\n }\r\n cnt = Math.max(cnt, k);\r\n }\r\n if (cnt === s1.length && cnt === s2.length) console.log(0);\r\n else console.log(s1.length + s2.length - cnt * 2);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let s1 = readline().trim().split(\"\");\r\n let s2 = readline().trim().split(\"\");\r\n let cnt = 0;\r\n for (let i = 0; i < s1.length; i++) {\r\n let k = 0,\r\n l = i;\r\n for (let j = 0; j < s2.length; j++) {\r\n if (s2[j] === s1[l] && l < s1.length) {\r\n k++;\r\n l++;\r\n } else {\r\n cnt = Math.max(cnt, k);\r\n l = i;\r\n k = 0;\r\n }\r\n }\r\n cnt = Math.max(cnt, k);\r\n }\r\n if (cnt === s1.length && cnt === s2.length) console.log(0);\r\n else console.log(s1.length + s2.length - cnt * 2);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\nconst mx = Math.max;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b) => {\r\n let an = a.length;\r\n let bn = b.length;\r\n an <= bn ? go(a, b) : go(b, a);\r\n};\r\n\r\nconst go = (short, long) => {\r\n let sn = short.length;\r\n let ln = long.length;\r\n if (sn == ln && short == long) return pr(0);\r\n if (long.indexOf(short) != -1) return pr(sn);\r\n let res = 0;\r\n for (let i = 0; i < sn; i++) {\r\n for (let j = i; j < sn; j++) {\r\n let len = j - i + 1;\r\n let sub = short.slice(i, j + 1);\r\n if (long.indexOf(sub) != -1) {\r\n res = mx(res, len);\r\n }\r\n }\r\n }\r\n pr(sn + ln - res * 2);\r\n}\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n \r\nlet TC = 0;\r\nlet A, B;\r\nreadline.on('line', line => {\r\n if (TC === 0) {\r\n TC = Number(line.toString());\r\n return;\r\n }\r\n if (!A) {\r\n A = line.toString();\r\n return;\r\n }\r\n B = line.toString();\r\n if (A.length > B.length) {\r\n [B, A] = [A, B];\r\n }\r\n let maxMatchLength = 0;\r\n for (let i = 0; i < A.length; i++) {\r\n for (let j = i + 1; j < A.length - i; j++) {\r\n const t = A.substr(i, j);\r\n if (B.indexOf(t) > -1) {\r\n const matchLength = t.length;\r\n if (maxMatchLength < matchLength) {\r\n maxMatchLength = matchLength;\r\n }\r\n }\r\n }\r\n }\r\n console.log((A.length - maxMatchLength) + (B.length - maxMatchLength));\r\n\r\n A = undefined; B = undefined;\r\n TC--;\r\n if (TC === 0) {\r\n process.exit();\r\n }\r\n});\r\n"}], "src_uid": "36aec7a06c02052f562ea3d44d4a62e4"} {"source_code": "function main(a, b) {\n // define variables\n var config = {\n sources: {\n insert: 0,\n remove: 1,\n matching: 2,\n },\n scores: {\n match: 0,\n replace: -1,\n insert: -1,\n remove: -1\n },\n };\n function create() {\n var table = [];\n for (var i = 0; i < a.length + 1; i++) {\n var row = [];\n for (var j = 0; j < b.length + 1; j++) {\n row.push(null);\n }\n table.push(row);\n }\n return table;\n }\n var scores = create();\n var sources = create();\n var letters = create();\n\n // compute first row and first column\n scores[0][0] = 0;\n for (var i = 0; i < a.length; i++) {\n scores[i + 1][0] = (i + 1) * config.scores.remove;\n sources[i + 1][0] = config.sources.remove;\n letters[i + 1][0] = a[i];\n }\n for (var i = 0; i < b.length; i++) {\n scores[0][i + 1] = (i + 1) * config.scores.insert;\n sources[0][i + 1] = config.sources.insert;\n letters[0][i + 1] = b[i];\n }\n\n // compute the whole table\n for (var i = 1; i < scores.length; i++) {\n for (var j = 1; j < scores[i].length; j++) {\n var match = a[i - 1] === b[j - 1];\n var insertScore = scores[i][j - 1] + config.scores.insert;\n var removeScore = scores[i - 1][j] + config.scores.remove;\n var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];\n\n if (insertScore >= removeScore && insertScore >= matchingScore) {\n scores[i][j] = insertScore;\n sources[i][j] = config.sources.insert;\n letters[i][j] = b[j - 1];\n } else if (removeScore >= insertScore && removeScore >= matchingScore) {\n scores[i][j] = removeScore;\n sources[i][j] = config.sources.remove;\n letters[i][j] = a[i - 1];\n } else if (matchingScore >= removeScore && matchingScore >= insertScore) {\n scores[i][j] = matchingScore;\n sources[i][j] = config.sources.matching;\n letters[i][j] = match ? ' ' : b[j - 1];\n }\n }\n }\n\n // return the editing operation list\n var path = [];\n var j = b.length;\n var i = a.length;\n var current = a.slice();\n while (i > 0 || j > 0) {\n if (sources[i][j] === config.sources.matching) {\n if (scores[i][j] < scores[i - 1][j - 1]) {\n current[i - 1] = letters[i][j];\n path.push({\n current: current.slice(),\n type: 'replace',\n position: i,\n item: letters[i][j],\n });\n }\n i--;\n j--;\n } else if (sources[i][j] === config.sources.remove) {\n current.splice(i - 1, 1);\n path.push({\n current: current.slice(),\n type: 'delete',\n position: i,\n item: letters[i][j],\n });\n i--;\n } else if (sources[i][j] === config.sources.insert) {\n current.splice(i, 0, letters[i][j]);\n path.push({\n current: current.slice(),\n type: 'insert',\n position: i + 1,\n item: letters[i][j],\n });\n j--;\n }\n }\n return path;\n}\n\nvar a = readline().trim();\nvar b = readline().trim();\nvar changes = main(a.split(''), b.split(''));\n\nprint(changes.length);\nchanges.forEach(function (change) {\n print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + change.item)));\n});", "positive_code": [{"source_code": "function main(a, b) {\n // define variables\n var i, j;\n var config = {\n sources: {\n insert: 0,\n remove: 1,\n matching: 2\n },\n scores: {\n match: 0,\n replace: -1,\n insert: -1,\n remove: -1\n }\n };\n function create() {\n var table = [];\n for (var i = 0; i < a.length + 1; i++) {\n var row = [];\n for (var j = 0; j < b.length + 1; j++) {\n row.push(null);\n }\n table.push(row);\n }\n return table;\n }\n var scores = create();\n var sources = create();\n var letters = create();\n\n // compute first row and first column\n scores[0][0] = 0;\n for (i = 0; i < a.length; i++) {\n scores[i + 1][0] = (i + 1) * config.scores.remove;\n sources[i + 1][0] = config.sources.remove;\n letters[i + 1][0] = a[i];\n }\n for (i = 0; i < b.length; i++) {\n scores[0][i + 1] = (i + 1) * config.scores.insert;\n sources[0][i + 1] = config.sources.insert;\n letters[0][i + 1] = b[i];\n }\n\n // compute the whole table\n for (i = 1; i < scores.length; i++) {\n for (j = 1; j < scores[i].length; j++) {\n var match = a[i - 1] === b[j - 1];\n var insertScore = scores[i][j - 1] + config.scores.insert;\n var removeScore = scores[i - 1][j] + config.scores.remove;\n var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];\n\n if (insertScore >= removeScore && insertScore >= matchingScore) {\n scores[i][j] = insertScore;\n sources[i][j] = config.sources.insert;\n letters[i][j] = b[j - 1];\n } else if (removeScore >= insertScore && removeScore >= matchingScore) {\n scores[i][j] = removeScore;\n sources[i][j] = config.sources.remove;\n letters[i][j] = a[i - 1];\n } else if (matchingScore >= removeScore && matchingScore >= insertScore) {\n scores[i][j] = matchingScore;\n sources[i][j] = config.sources.matching;\n letters[i][j] = match ? null : {\n from: a[i - 1],\n to: b[j - 1]\n };\n }\n }\n }\n\n // return the editing operation list\n var operations = [];\n j = b.length;\n i = a.length;\n while (i > 0 || j > 0) {\n if (sources[i][j] === config.sources.matching) {\n if (scores[i][j] < scores[i - 1][j - 1]) {\n operations.push({\n type: 'replace',\n position: i,\n item: letters[i][j]\n });\n }\n i--;\n j--;\n } else if (sources[i][j] === config.sources.remove) {\n operations.push({\n type: 'delete',\n position: i,\n item: letters[i][j]\n });\n i--;\n } else if (sources[i][j] === config.sources.insert) {\n operations.push({\n type: 'insert',\n position: i + 1,\n item: letters[i][j]\n });\n j--;\n }\n }\n\n return operations;\n}\n\nvar a = readline().trim();\nvar b = readline().trim();\nvar changes = main(a.split(''), b.split(''));\n\nprint(changes.length);\nchanges.forEach(function (change) {\n print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + (change.type === 'replace' ? change.item.to : change.item))));\n});"}, {"source_code": "var debug = false;\n\nfunction main(a, b) {\n if (debug) {\n print(a);\n print(b);\n }\n\n // define variables\n var config = {\n sources: {\n insert: 'li',\n remove: 'ur',\n matching: 'dm',\n },\n scores: {\n match: 0,\n replace: -1,\n insert: -1,\n remove: -1\n },\n };\n function create() {\n var table = [];\n for (var i = 0; i < a.length + 1; i++) {\n var row = [];\n for (var j = 0; j < b.length + 1; j++) {\n row.push(null);\n }\n table.push(row);\n }\n return table;\n }\n function show(table) {\n if (!debug) {\n return;\n }\n write(' ');\n for (var i = 0; i < table[0].length - 1; i++) {\n write(b[i] + ' ');\n }\n write('\\n');\n\n for (var i = 0; i < table.length; i++) {\n if (i > 0) {\n write(a[i - 1] + ' ');\n } else {\n write(' ');\n }\n for (var j = 0; j < table[i].length; j++) {\n write(table[i][j] + ' ');\n }\n write('\\n');\n }\n }\n var scores = create();\n var sources = create();\n var letters = create();\n\n show(scores);\n\n // compute first row and first column\n scores[0][0] = 0;\n for (var i = 0; i < a.length; i++) {\n scores[i + 1][0] = (i + 1) * config.scores.remove;\n sources[i + 1][0] = config.sources.remove;\n letters[i + 1][0] = a[i];\n }\n for (var i = 0; i < b.length; i++) {\n scores[0][i + 1] = (i + 1) * config.scores.insert;\n sources[0][i + 1] = config.sources.insert;\n letters[0][i + 1] = b[i];\n }\n\n show(scores);\n\n // compute the whole table\n for (var i = 1; i < scores.length; i++) {\n for (var j = 1; j < scores[i].length; j++) {\n var match = a[i - 1] === b[j - 1];\n var insertScore = scores[i][j - 1] + config.scores.insert;\n var removeScore = scores[i - 1][j] + config.scores.remove;\n var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];\n\n if (insertScore >= removeScore && insertScore >= matchingScore) {\n scores[i][j] = insertScore;\n sources[i][j] = config.sources.insert;\n letters[i][j] = b[j - 1];\n } else if (removeScore >= insertScore && removeScore >= matchingScore) {\n scores[i][j] = removeScore;\n sources[i][j] = config.sources.remove;\n letters[i][j] = a[i - 1];\n } else if (matchingScore >= removeScore && matchingScore >= insertScore) {\n scores[i][j] = matchingScore;\n sources[i][j] = config.sources.matching;\n letters[i][j] = match ? ' ' : b[j - 1];\n }\n }\n }\n\n show(scores);\n show(sources);\n show(letters);\n\n var path = [];\n var j = b.length;\n var i = a.length;\n var current = a.slice();\n\n while (i > 0 || j > 0) {\n if (sources[i][j] === config.sources.matching) {\n if (scores[i][j] < scores[i - 1][j - 1]) {\n current[i - 1] = letters[i][j];\n path.push({\n current: current.slice(),\n type: 'replace',\n position: i,\n item: letters[i][j],\n });\n }\n i--;\n j--;\n } else if (sources[i][j] === config.sources.remove) {\n current.splice(i - 1, 1);\n path.push({\n current: current.slice(),\n type: 'delete',\n position: i,\n item: letters[i][j],\n });\n i--;\n } else if (sources[i][j] === config.sources.insert) {\n current.splice(i, 0, letters[i][j]);\n path.push({\n current: current.slice(),\n type: 'insert',\n position: i + 1,\n item: letters[i][j],\n });\n j--;\n }\n }\n\n return path;\n}\n\nvar a = readline().trim();\nvar b = readline().trim();\n/*\na = 'seven';\nb = 'sved';\na = 'aba';\nb = 'abbba';\na = 'accepted';\nb = 'wronganswer';\n*/\nvar changes = main(a.split(''), b.split(''));\n\nif (debug) {\n print(a)\n print(b)\n}\nprint(changes.length);\nchanges.forEach(function (change) {\n print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + change.item)));\n //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');\n});"}], "negative_code": [{"source_code": "var debug = false;\n\nfunction main(a, b) {\n if (debug) {\n print(a);\n print(b);\n }\n\n // define variables\n var config = {\n sources: {\n insert: 'li',\n remove: 'ur',\n matching: 'dm',\n },\n scores: {\n match: 0,\n replace: -1,\n insert: -1,\n remove: -1\n },\n };\n function create() {\n var table = [];\n for (var i = 0; i < a.length + 1; i++) {\n var row = [];\n for (var j = 0; j < b.length + 1; j++) {\n row.push(null);\n }\n table.push(row);\n }\n return table;\n }\n function show(table) {\n if (!debug) {\n return;\n }\n write(' ');\n for (var i = 0; i < table[0].length - 1; i++) {\n write(b[i] + ' ');\n }\n write('\\n');\n\n for (var i = 0; i < table.length; i++) {\n if (i > 0) {\n write(a[i - 1] + ' ');\n } else {\n write(' ');\n }\n for (var j = 0; j < table[i].length; j++) {\n write(table[i][j] + ' ');\n }\n write('\\n');\n }\n }\n var scores = create();\n var sources = create();\n var letters = create();\n\n show(scores);\n\n // compute first row and first column\n scores[0][0] = 0;\n for (var i = 0; i < a.length; i++) {\n scores[i + 1][0] = (i + 1) * config.scores.remove;\n sources[i + 1][0] = config.sources.remove;\n letters[i + 1][0] = a[i];\n }\n for (var i = 0; i < b.length; i++) {\n scores[0][i + 1] = (i + 1) * config.scores.insert;\n sources[0][i + 1] = config.sources.insert;\n letters[0][i + 1] = b[i];\n }\n\n show(scores);\n\n // compute the whole table\n for (var i = 1; i < scores.length; i++) {\n for (var j = 1; j < scores[i].length; j++) {\n var match = a[i - 1] === b[j - 1];\n var insertScore = scores[i][j - 1] + config.scores.insert;\n var removeScore = scores[i - 1][j] + config.scores.remove;\n var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];\n\n if (insertScore >= removeScore && insertScore >= matchingScore) {\n scores[i][j] = insertScore;\n sources[i][j] = config.sources.insert;\n letters[i][j] = b[j - 1];\n } else if (removeScore >= insertScore && removeScore >= matchingScore) {\n scores[i][j] = removeScore;\n sources[i][j] = config.sources.remove;\n letters[i][j] = a[i - 1];\n } else if (matchingScore >= removeScore && matchingScore >= insertScore) {\n scores[i][j] = matchingScore;\n sources[i][j] = config.sources.matching;\n letters[i][j] = match ? ' ' : b[j - 1];\n }\n }\n }\n\n show(scores);\n show(sources);\n show(letters);\n\n var path = [];\n var j = b.length;\n var i = a.length;\n var current = a.slice();\n\n while (i > 0 || j > 0) {\n if (sources[i][j] === config.sources.matching) {\n if (scores[i][j] < scores[i - 1][j - 1]) {\n current[i - 1] = letters[i][j];\n path.push({\n current: current.slice(),\n type: 'replace',\n position: i,\n item: letters[i][j],\n });\n }\n i--;\n j--;\n } else if (sources[i][j] === config.sources.remove) {\n current.splice(i - 1, 1);\n path.push({\n current: current.slice(),\n type: 'remove',\n position: i,\n item: letters[i][j],\n });\n i--;\n } else if (sources[i][j] === config.sources.insert) {\n current.splice(i, 0, letters[i][j]);\n path.push({\n current: current.slice(),\n type: 'insert',\n position: i + 1,\n item: letters[i][j],\n });\n j--;\n }\n }\n\n return path;\n}\n\nvar a = readline().trim();\nvar b = readline().trim();\n/*\na = 'seven';\nb = 'sved';\na = 'aba';\nb = 'abbba';\na = 'accepted';\nb = 'wronganswer';\n*/\nvar changes = main(a.split(''), b.split(''));\n\nif (debug) {\n print(a)\n print(b)\n}\nprint(changes.length);\nchanges.forEach(function (change) {\n print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item);\n //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');\n});"}, {"source_code": "var debug = false;\n\nfunction main(a, b) {\n if (debug) {\n print(a);\n print(b);\n }\n\n // define variables\n var config = {\n sources: {\n insert: 'li',\n remove: 'ur',\n matching: 'dm',\n },\n scores: {\n match: 0,\n replace: -1,\n insert: -1,\n remove: -1\n },\n };\n function create() {\n var table = [];\n for (var i = 0; i < a.length + 1; i++) {\n var row = [];\n for (var j = 0; j < b.length + 1; j++) {\n row.push(null);\n }\n table.push(row);\n }\n return table;\n }\n function show(table) {\n if (!debug) {\n return;\n }\n write(' ');\n for (var i = 0; i < table[0].length - 1; i++) {\n write(b[i] + ' ');\n }\n write('\\n');\n\n for (var i = 0; i < table.length; i++) {\n if (i > 0) {\n write(a[i - 1] + ' ');\n } else {\n write(' ');\n }\n for (var j = 0; j < table[i].length; j++) {\n write(table[i][j] + ' ');\n }\n write('\\n');\n }\n }\n var scores = create();\n var sources = create();\n var letters = create();\n\n show(scores);\n\n // compute first row and first column\n scores[0][0] = 0;\n for (var i = 0; i < a.length; i++) {\n scores[i + 1][0] = (i + 1) * config.scores.remove;\n sources[i + 1][0] = config.sources.remove;\n letters[i + 1][0] = a[i];\n }\n for (var i = 0; i < b.length; i++) {\n scores[0][i + 1] = (i + 1) * config.scores.insert;\n sources[0][i + 1] = config.sources.insert;\n letters[0][i + 1] = b[i];\n }\n\n show(scores);\n\n // compute the whole table\n for (var i = 1; i < scores.length; i++) {\n for (var j = 1; j < scores[i].length; j++) {\n var match = a[i - 1] === b[j - 1];\n var insertScore = scores[i][j - 1] + config.scores.insert;\n var removeScore = scores[i - 1][j] + config.scores.remove;\n var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];\n\n if (insertScore >= removeScore && insertScore >= matchingScore) {\n scores[i][j] = insertScore;\n sources[i][j] = config.sources.insert;\n letters[i][j] = b[j - 1];\n } else if (removeScore >= insertScore && removeScore >= matchingScore) {\n scores[i][j] = removeScore;\n sources[i][j] = config.sources.remove;\n letters[i][j] = a[i - 1];\n } else if (matchingScore >= removeScore && matchingScore >= insertScore) {\n scores[i][j] = matchingScore;\n sources[i][j] = config.sources.matching;\n letters[i][j] = match ? ' ' : b[j - 1];\n }\n }\n }\n\n show(scores);\n show(sources);\n show(letters);\n\n var path = [];\n var j = b.length;\n var i = a.length;\n var current = a.slice();\n\n while (i > 0 || j > 0) {\n if (sources[i][j] === config.sources.matching) {\n if (scores[i][j] < scores[i - 1][j - 1]) {\n current[i - 1] = letters[i][j];\n path.push({\n current: current.slice(),\n type: 'replace',\n position: i,\n item: letters[i][j],\n });\n }\n i--;\n j--;\n } else if (sources[i][j] === config.sources.remove) {\n current.splice(i - 1, 1);\n path.push({\n current: current.slice(),\n type: 'delete',\n position: i,\n item: letters[i][j],\n });\n i--;\n } else if (sources[i][j] === config.sources.insert) {\n current.splice(i, 0, letters[i][j]);\n path.push({\n current: current.slice(),\n type: 'insert',\n position: i + 1,\n item: letters[i][j],\n });\n j--;\n }\n }\n\n return path;\n}\n\nvar a = readline().trim();\nvar b = readline().trim();\n/*\na = 'seven';\nb = 'sved';\na = 'aba';\nb = 'abbba';\na = 'accepted';\nb = 'wronganswer';\n*/\nvar changes = main(a.split(''), b.split(''));\n\nif (debug) {\n print(a)\n print(b)\n}\nprint(changes.length);\nchanges.forEach(function (change) {\n print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item);\n //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');\n});"}], "src_uid": "3cef1144dbd24e3e3807ab097b022c13"} {"source_code": "var p = readline().split(/\\s/gi).map(Number),\n\t\t\tq = p[1], l = p[2], r = p[3], p = p[0],\n\t\t\tabArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};\n\n\t\tfor(var i = 1; i <= p; i++)\t{\n\t\t\tvar ab = readline().split(/\\s/gi).map(Number),\n\t\t\t\ta = ab[0], b = ab[1];\n\n\t\t\tif(abArr[abArr.length - 1][1] < a)\tabArr.push(ab);\n\t\t}\n\n\t\tfor(var j = 1; j <= q; j++)\t{\n\t\t\tvar cd = readline().split(/\\s/gi).map(Number),\n\t\t\t\tc = cd[0], d = cd[1];\n\n\t\t\tif(cdArr[cdArr.length - 1][1] < c)\t{\n\t\t\t\tcdArr.push(cd);\n\n\t\t\t\tfor(var k = 1; k <= abArr.length - 1; k++)\t{\n\t\t\t\t\tvar a = abArr[k][0], b = abArr[k][1],\n\t\t\t\t\t\tsl = a - d, sr = b - c;\n\n\t\t\t\t\tsr > r ? sr = r : true;\n\t\t\t\t\tsl < l ? sl = l : true;\n\n\t\t\t\t\tif(sl >= l)\t{\n\t\t\t\t\t\t//console.log('%d, %d', sl, sr);\n\t\t\t\t\t\tfor(var n = sl; n <= sr; n++)\t{\n\t\t\t\t\t\t\tresult[n] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprint(Object.keys(result).length);", "positive_code": [{"source_code": ";(function () {\n\tprint(function (p,\u2009q,\u2009l,\u2009r) {\n\t\tvar t = 0;\n\n\t\tvar ab = [];\n\t\twhile (p--) {\n\t\t\tab.push(readline().split(' ').map(Number));\n\t\t} p = ab.length;\n\n\t\tvar cd = [];\n\t\twhile (q--) {\n\t\t\tcd.push(readline().split(' ').map(Number));\n\t\t} q = cd.length;\n\n\t\tfor (; l <= r; l++) {\n\t\t\tvar w = true;\n\t\t\tfor (var i = 0; i < p && w; i++) {\n\t\t\t\tfor (var j = 0; j < q && w; j++) {\n\t\t\t\t\tvar a = ab[i], b = [cd[j][0] + l, cd[j][1] + l];\n\n\t\t\t\t\tif (Math.max(a[1], b[1]) >= Math.min(a[0], b[0]) && Math.min(a[1], b[1]) >= Math.max(a[0], b[0]) ) {\n\t\t\t\t\t\tt++;\n\t\t\t\t\t\tw = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn t;\n\t}.apply(null, readline().split(' ').map(Number)));\n}.call(this));"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , d , e , k;\n res = 0;\n for( i = 0 ; i < this.p ; i++ ) {\n a = this.arr[ i ];\n b = this.brr[ i ];\n for( j = a ; j <= b ; j++ ) {\n this.err[ j ] = 1;\n }\n }\n for( i = this.l ; i <= this.r ; i++ ) {\n c = 0 ;\n for( j = 0 ; j < this.q ; j++ ) {\n a = this.crr[ j ] + i;\n b = this.drr[ j ] + i;\n for( k = a ; k <= b ; k++ ) {\n if( this.err[ k ] == 1 ) {\n c = 1 ;\n break ;\n }\n }\n }\n if( c == 1 ) {\n res++ ;\n }\n }\n print( res );\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.p = irObj.nextInt();\n this.q = irObj.nextInt();\n this.l = irObj.nextInt();\n this.r = irObj.nextInt();\n for( i = 0 ; i < this.p ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n this.brr[ i ] = irObj.nextInt();\n }\n for( i = 0 ; i < this.q ; i++ ) {\n this.crr[ i ] = irObj.nextInt();\n this.drr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.drr = new Array();\n this.err = new Array();\n this.frr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.drr.push( 0 );\n this.err.push( 0 );\n this.frr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.drr = new Array();\n this.err = new Array();\n this.frr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.crr.push( 0 );\n this.drr.push( 0 );\n this.err.push( 0 );\n this.frr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 1010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}], "negative_code": [{"source_code": "var p = readline().split(/\\s/gi).map(Number),\n\t\t\tq = p[1], l = p[2], r = p[3], p = p[0],\n\t\t\tabArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};\n\n\t\tfor(var i = 1; i <= p; i++)\t{\n\t\t\tvar ab = readline().split(/\\s/gi).map(Number),\n\t\t\t\ta = ab[0], b = ab[1];\n\n\t\t\tif(abArr[abArr.length - 1][1] < a)\tabArr.push(ab);\n\t\t}\n\t\t\n\t\tfor(var i = 1; i <= q; i++)\t{\n\t\t\tvar cd = readline().split(/\\s/gi).map(Number),\n\t\t\t\tc = cd[0], d = cd[1];\n\n\t\t\tif(cdArr[cdArr.length - 1][1] < c)\t{\n\t\t\t\tcdArr.push(cd);\n\n\t\t\t\tfor(var k = 1; k <= p; k++)\t{\n\t\t\t\t\tvar a = abArr[k][0], b = abArr[k][1],\n\t\t\t\t\t\tsl = a - d, sr = b - c;\n\n\t\t\t\t\tsr > r ? sr = r : true;\n\t\t\t\t\tsl < 0 ? sl = 0 : true;\n\n\t\t\t\t\tif(sl >= 0)\t{\n\t\t\t\t\t\t//console.log('%d, %d', sl, sr);\n\t\t\t\t\t\tfor(var n = sl; n <= sr; n++)\t{\n\t\t\t\t\t\t\tresult[n] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprint(Object.keys(result).length);"}, {"source_code": "var p = readline().split(/\\s/gi).map(Number),\n\t\t\tq = p[1], l = p[2], r = p[3], p = p[0],\n\t\t\tabArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};\n\n\t\tfor(var i = 1; i <= p; i++)\tabArr.push(readline().split(/\\s/gi).map(Number));\n\t\tfor(var i = 1; i <= q; i++)\t{\n\t\t\tvar cd = readline().split(/\\s/gi).map(Number),\n\t\t\t\tc = cd[0], d = cd[1];\n\n\t\t\tif(cdArr[cdArr.length - 1][1] < c)\t{\n\t\t\t\tfor(var k = 1; k <= p; k++)\t{\n\t\t\t\t\tvar a = abArr[k][0], b = abArr[k][1],\n\t\t\t\t\t\tsl = a - d, sr = b - c;\n\n\t\t\t\t\tsr > r ? sr = r : true;\n\t\t\t\t\tsl < 0 ? sl = 0 : true;\n\n\t\t\t\t\tif(sl >= 0)\t{\n\t\t\t\t\t\t//console.log('%d, %d', sl, sr);\n\t\t\t\t\t\tfor(var n = sl; n <= sr; n++)\t{\n\t\t\t\t\t\t\tresult[n] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprint(Object.keys(result).length);"}, {"source_code": "var p = readline().split(/\\s/gi).map(Number),\n\t\t\tq = p[1], l = p[2], r = p[3], p = p[0],\n\t\t\tabArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};\n\n\t\tfor(var i = 1; i <= p; i++)\t{\n\t\t\tvar ab = readline().split(/\\s/gi).map(Number),\n\t\t\t\ta = ab[0], b = ab[1];\n\n\t\t\tif(abArr[abArr.length - 1][1] < a)\tabArr.push(ab);\n\t\t}\n\n\t\tfor(var j = 1; j <= q; j++)\t{\n\t\t\tvar cd = readline().split(/\\s/gi).map(Number),\n\t\t\t\tc = cd[0], d = cd[1];\n\n\t\t\tif(cdArr[cdArr.length - 1][1] < c)\t{\n\t\t\t\tcdArr.push(cd);\n\n\t\t\t\tfor(var k = 1; k <= abArr.length - 1; k++)\t{\n\t\t\t\t\tvar a = abArr[k][0], b = abArr[k][1],\n\t\t\t\t\t\tsl = a - d, sr = b - c;\n\n\t\t\t\t\tsr > r ? sr = r : true;\n\t\t\t\t\tsl < 0 ? sl = 0 : true;\n\n\t\t\t\t\tif(sl >= 0)\t{\n\t\t\t\t\t\t//console.log('%d, %d', sl, sr);\n\t\t\t\t\t\tfor(var n = sl; n <= sr; n++)\t{\n\t\t\t\t\t\t\tresult[n] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprint(Object.keys(result).length);"}], "src_uid": "aa77158bf4c0854624ddd89aa8b424b3"} {"source_code": "function key(a, b) {\r\n return a + ',' + b;\r\n}\r\nfunction gcd( a, b)\r\n{\r\n /* GCD(0, b) == b; GCD(a, 0) == a,\r\n GCD(0, 0) == 0 */\r\n if (a == 0)\r\n return b;\r\n if (b == 0)\r\n return a;\r\n \r\n /*Finding K, where K is the\r\n greatest power of 2\r\n that divides both a and b. */\r\n var k;\r\n for (k = 0; ((a | b) & 1) == 0; ++k)\r\n {\r\n a >>= 1;\r\n b >>= 1;\r\n }\r\n \r\n /* Dividing a by 2 until a becomes odd */\r\n while ((a & 1) == 0)\r\n a >>= 1;\r\n \r\n /* From here on, 'a' is always odd. */\r\n do\r\n {\r\n /* If b is even, remove all factor of 2 in b */\r\n while ((b & 1) == 0)\r\n b >>= 1;\r\n \r\n /* Now a and b are both odd.\r\n Swap if necessary so a <= b,\r\n then set b = b - a (which is even).*/\r\n if (a > b){\r\n var t = a;\r\n a = b;\r\n b = t;\r\n }\r\n \r\n b = (b - a);\r\n } while (b != 0);\r\n \r\n /* restore common factors of 2 */\r\n return a << k;\r\n}\r\n \r\nfunction woodSplits(str) {\r\n var dilucCount = 0;\r\n var kayeaCount = 0;\r\n var countsMap = {};\r\n var answer = [];\r\n for (var i = 0; i < str.length; i++) {\r\n if (str[i] == 'D') {\r\n dilucCount++;\r\n } else if (str[i] == 'K') {\r\n kayeaCount++;\r\n }\r\n var currentGcd = gcd(dilucCount, kayeaCount);\r\n var currentKey = key(dilucCount / currentGcd, kayeaCount / currentGcd);\r\n var newValue = 1 + (countsMap[currentKey] || 0);\r\n countsMap[currentKey] = newValue;\r\n answer.push(newValue);\r\n }\r\n return answer;\r\n}\r\n \r\nvar numCases = Number(readline());\r\nfor (var i = 0; i < numCases; i++) {\r\n readline();\r\n var str = readline();\r\n print(woodSplits(str).join(' '));\r\n}", "positive_code": [{"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var str = read();\r\n var dcount = [0];\r\n var kcount = [0];\r\n var save = new Map();\r\n for(var i = 0; i < n; i++) {\r\n if (str[i] === 'D') {\r\n dcount.push(dcount[i] + 1);\r\n kcount.push(kcount[i]);\r\n continue;\r\n }\r\n dcount.push(dcount[i]);\r\n kcount.push(kcount[i] + 1);\r\n }\r\n var ans = [];\r\n for (var i = 1; i <= n; i++) {\r\n if (dcount[i] === 0 || kcount[i] === 0) {\r\n ans.push(dcount[i] + kcount[i]);\r\n continue;\r\n }\r\n var countGcd = gcd(dcount[i], kcount[i]);\r\n var strSave = div(dcount[i], countGcd) + ':' + div(kcount[i], countGcd);\r\n if (countGcd === 1) {\r\n ans.push(1);\r\n save.set(strSave, 1);\r\n continue;\r\n }\r\n if (save.has(strSave)) {\r\n var curAns = save.get(strSave) + 1;\r\n ans.push(curAns);\r\n save.set(strSave, curAns);\r\n continue;\r\n }\r\n ans.push(1);\r\n save.set(strSave, 1);\r\n }\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction div(a, b) {\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction solve() {\r\n var n = Number(read());\r\n var str = read();\r\n var dcount = [0];\r\n var kcount = [0];\r\n var save = {};\r\n for(var i = 0; i < n; i++) {\r\n if (str[i] === 'D') {\r\n dcount.push(dcount[i] + 1);\r\n kcount.push(kcount[i]);\r\n continue;\r\n }\r\n dcount.push(dcount[i]);\r\n kcount.push(kcount[i] + 1);\r\n }\r\n var ans = [];\r\n for (var i = 1; i <= n; i++) {\r\n if (dcount[i] === 0 || kcount[i] === 0) {\r\n ans.push(dcount[i] + kcount[i]);\r\n continue;\r\n }\r\n var countGcd = gcd(dcount[i], kcount[i]);\r\n var strSave = div(dcount[i], countGcd) + ':' + div(kcount[i], countGcd);\r\n if (countGcd === 1) {\r\n ans.push(1);\r\n save[strSave] = 1;\r\n continue;\r\n }\r\n if (save[strSave]) {\r\n var curAns = save[strSave] + 1;\r\n ans.push(curAns);\r\n save[strSave] = curAns;\r\n continue;\r\n }\r\n ans.push(1);\r\n save[strSave] = 1;\r\n }\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, s) {\r\n const map = new Map();\r\n const dp = [];\r\n let d = 0,\r\n k = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] === 'D') d++;else k++;\r\n const a = gcd(d, k),\r\n b = d / a,\r\n c = k / a,\r\n r = `${b},${c}`;\r\n if (map.has(r)) {\r\n dp[i] = dp[map.get(r)] + 1;\r\n } else {\r\n dp[i] = 1;\r\n }\r\n map.set(r, i);\r\n }\r\n return dp.join(' ');\r\n}\r\nfunction gcd(a, b) {\r\n return !b ? a : gcd(b, a % b);\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = await read();\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var len = +readline();\r\n var tree = readline();\r\n var ds = 0;\r\n var ks = 0;\r\n var mp = {};\r\n var results = [];\r\n for (var j = 0; j < len; j++) {\r\n tree[j] === 'D' ? ds++ : ks++;\r\n var key = `d${ds/nod(ds, ks)}k${ks/nod(ds, ks)}`;\r\n mp[key] = mp[key] ? ++mp[key] : 1;\r\n results.push(mp[key]);\r\n }\r\n print(results.join(' '));\r\n }\r\n}\r\n\r\nfunction nod(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n return nod(b, a % b);\r\n}\r\nmain();"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst gcd = (a, b) => b ? gcd(b, a % b) : a;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst ans = [];\r\n\t\tconst m = new Map();\r\n\t\tfor (let i = 0, d = 0, k = 0; i < n; i++) {\r\n\t\t\td += s[i] == 'D';\r\n\t\t\tk += s[i] == 'K';\r\n\r\n\t\t\tconst ratio = d / gcd(d, k) + ':' + k / gcd(d, k);\r\n\t\t\tans[i] = 1 + (m.get(ratio) || 0);\r\n\t\t\tm.set(ratio, ans[i]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst ans = [];\r\n\t\tconst mp = new Map();\r\n\t\tfor (let i = 0, cnt = 0; i < n; i++) {\r\n\t\t\tcnt += s[i] == 'D';\r\n\t\t\t\r\n\t\t\tconst cur = mp.get(cnt/(i+1)) || 1;\r\n\t\t\tans[i] = cur;\r\n\t\t\tmp.set(cnt/(i+1), cur + 1);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 5e5 + 100;\r\n\r\nconst fact = Array.from(Array(mxN+1), x => []);\r\n\r\nfunction computeFactors () {\r\n\tfor (let i = 1; i <= mxN; i++) {\r\n\t\tlet j = i;\r\n\t\twhile (j <= mxN) {\r\n\t\t\tfact[j].push(i);\r\n\t\t\tj += i;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tcomputeFactors();\r\n\t//console.log(fact[10], fact[100]);\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst dp = [];\r\n\t\tconst cnt = []; cnt[-1] = 0;\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[i] = cnt[i-1] + (s[i] == 'D');\r\n\t\t\t//console.log({cnt})\r\n\t\t\tfor (const f of fact[i+1]) {\r\n\t\t\t\tconst dCnt = cnt[i] - cnt[i-f];\r\n\t\t\t\tconst ration = dCnt / f;\r\n\t\t\t\t//console.log({i, f, dCnt, ration})\r\n\t\t\t\tif (ration == dp[i-f]) {\r\n\t\t\t\t\tdp[i] = ration;\r\n\t\t\t\t\tans[i] = ans[i-f]+1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (f == i+1) {\r\n\t\t\t\t\tdp[i] = ration;\r\n\t\t\t\t\tans[i] = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t//console.log({cnt});\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 5e5 + 100;\r\n\r\nconst fact = Array.from(Array(mxN+1), x => []);\r\n\r\nfunction computeFactors () {\r\n\tfor (let i = 1; i <= mxN; i++) {\r\n\t\tlet j = i;\r\n\t\twhile (j <= mxN) {\r\n\t\t\tfact[j].push(i);\r\n\t\t\tj += i;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tcomputeFactors();\r\n\t//console.log(fact[10], fact[100]);\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst dp = [];\r\n\t\tconst cnt = []; cnt[-1] = 0;\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[i] = cnt[i-1] + (s[i] == 'D');\r\n\t\t\t//console.log({cnt})\r\n\t\t\tfor (const f of fact[i+1]) {\r\n\t\t\t\tconst dCnt = cnt[i] - cnt[i-f];\r\n\t\t\t\tconst ration = dCnt / f;\r\n\t\t\t\t//console.log({i, f, dCnt, ration})\r\n\t\t\t\tif (ration == dp[i-f] && ans[i-f] == (i-f+1)/f) {\r\n\t\t\t\t\tdp[i] = ration;\r\n\t\t\t\t\tans[i] = (i+1)/f;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (f == i+1) {\r\n\t\t\t\t\tdp[i] = ration;\r\n\t\t\t\t\tans[i] = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t//console.log({cnt});\r\n\t\t}\r\n\t\t\t//console.log({dp});\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 5e5 + 100;\r\n\r\nconst fact = Array.from(Array(mxN+1), x => []);\r\n\r\nfunction computeFactors () {\r\n\tfor (let i = 1; i <= mxN; i++) {\r\n\t\tlet j = i;\r\n\t\twhile (j <= mxN) {\r\n\t\t\tfact[j].push(i);\r\n\t\t\tj += i;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction main () {\r\n\tcomputeFactors();\r\n\t//console.log(fact[10], fact[100]);\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst s = rl();\r\n\r\n\t\tconst dp = [];\r\n\t\tconst cnt = []; cnt[-1] = 0;\r\n\t\tconst ans = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tcnt[i] = cnt[i-1] + (s[i] == 'D');\r\n\t\t\t//console.log({cnt})\r\n\t\t\tfor (const f of fact[i+1]) {\r\n\t\t\t\tconst dCnt = cnt[i] - cnt[i-f];\r\n\t\t\t\tconst ration = dCnt / f;\r\n\t\t\t\t//console.log({i, f, dCnt, ration})\r\n\t\t\t\tif (ration == dp[i-f] || f == i+1) {\r\n\t\t\t\t\tdp[i] = ration;\r\n\t\t\t\t\tans[i] = (i+1)/f;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t//console.log({dp});\r\n\t\t\t//console.log({cnt});\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var cache = {};\r\nfunction key(a, b) {\r\n return a + ',' + b;\r\n}\r\n// https://en.wikipedia.org/wiki/Greatest_common_divisor\r\nfunction gcd(a, b){\r\n if(key(a, b) in cache) return cache[key(a, b)];\r\n \r\n var result = b === 0 ? a : gcd(b, a % b);\r\n cache[key(a, b)] = result;\r\n return result;\r\n}\r\n \r\nfunction woodSplits(str) {\r\n var dilucCount = 0;\r\n var kayeaCount = 0;\r\n var countsMap = {};\r\n var answer = [];\r\n for (var i = 0; i < str.length; i++) {\r\n if (str[i] == 'D') {\r\n dilucCount++;\r\n } else if (str[i] == 'K') {\r\n kayeaCount++;\r\n }\r\n var currentGcd = gcd(dilucCount, kayeaCount);\r\n var currentKey = key(dilucCount / currentGcd, kayeaCount / currentGcd);\r\n var newValue = 1 + (countsMap[currentKey] || 0);\r\n countsMap[currentKey] = newValue;\r\n answer.push(newValue);\r\n }\r\n return answer;\r\n}\r\n \r\nvar numCases = Number(readline());\r\nfor (var i = 0; i < numCases; i++) {\r\n readline();\r\n var str = readline();\r\n print(woodSplits(str));\r\n}"}, {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var len = +readline();\r\n var tree = readline();\r\n var ds = 0;\r\n var ks = 0;\r\n var results = [];\r\n for (var j = 0; j < len; j++) {\r\n tree[j] === 'D' ? ds++ : ks++;\r\n var max = ds > ks ? ds : ks;\r\n var min = ds < ks ? ds : ks;\r\n if (min === 0) {\r\n results.push(max);\r\n } else if (max % min === 0) {\r\n results.push(min)\r\n } else { results.push(1) }\r\n }\r\n print(results.join(' '));\r\n }\r\n}\r\n\r\nmain();"}], "src_uid": "de2e2e12be4464306beb0217875f66c7"} {"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n \nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n \nconst calc = (t)=>{\n /* read */\n let [n, k] = ra();\n let a = ra();\n \n if (n === 1) {\n return a[0] + k - 1;\n }\n \n if (k <= n) {\n let i = 0;\n let curSum = 0;\n for (; i < k; i++) {\n curSum += a[i];\n }\n let maxSum = curSum;\n for (; i < n; i++) {\n curSum += a[i];\n curSum -= a[i - k];\n maxSum = Math.max(maxSum, curSum);\n }\n return maxSum + sumab(1, k - 1);\n } else {\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += a[i];\n }\n // console.log(`DEBUG t ${t} sum`, sum);\n let wait = k - n;\n // console.log(`DEBUG t ${t} wait`, wait);\n let traverse = sumab(wait + 1, wait + n - 1);\n // console.log(`DEBUG t ${t} traverse`, traverse);\n let result = sum + wait + traverse;\n return result;\n }\n};\n \nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = readline()\r\n for(let _=0;_= n) {\r\n return (a.reduce((a, b) => a + b, 0n) + bm * (bm - 1n) / 2n - (bm - bn) * (bm - bn - 1n) / 2n).toString();\r\n }\r\n const sum = [];\r\n let max = 0n;\r\n for (let [i, num] of a.entries()) {\r\n var _sum, _sum2;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0n) + num;\r\n const cur = sum[i] - ((_sum2 = sum[i - m]) !== null && _sum2 !== void 0 ? _sum2 : 0n);\r\n if (max < cur) max = cur;\r\n }\r\n return (max + bm * (bm - 1n) / 2n).toString();\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(BigInt);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const sum = [arr[0]]\n for (let i = 1; i < n; i++) {\n sum[i] = sum[i - 1] + arr[i]\n }\n // console.log(sum)\n if (k >= n) {\n // const t = Math.floor((k - 1) / (n - 1))\n // const r = k % (n - 1)\n return BigInt(sum[n - 1]) + mul(k - 1 + k - 1 - n + 1, n) / 2n\n } else {\n let max = 0\n for (let i = 0; i < n; i++) {\n const after = n - 1 - i + 1\n if (k <= after) {\n const now = range(i, i + k - 1)\n if (now > max) max = now\n }\n // console.log(now)\n }\n // 0, 1, ..., k - 1\n return BigInt(max) + mul(k - 1, k) / 2n\n }\n function range(i, j) {\n return sum[j] - (sum[i - 1] || 0)\n }\n}\nfunction mul(a, b) {\n return BigInt(a) * BigInt(b)\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const sum = [arr[0]]\n for (let i = 1; i < n; i++) {\n sum[i] = sum[i - 1] + arr[i]\n }\n // console.log(sum)\n if (k >= n) {\n // const t = Math.floor((k - 1) / (n - 1))\n // const r = k % (n - 1)\n return BigInt(sum[n - 1]) + mul(k - 1 + k - 1 - n + 1, n) / 2n\n } else {\n let max = 0\n for (let i = 0; i < n; i++) {\n const after = n - 1 - i + 1\n let now\n if (k <= after) {\n now = range(i, i + k - 1)\n } else {\n const before = k - after\n now = range(i, n - 1) + range(n - 2 - before + 1, n - 2)\n }\n if (now > max) max = now\n // console.log(now)\n if (i + 1 < k) {\n const before = k - (i + 1)\n now = range(1, 1 + before - 1) + range(0, i)\n if (now > max) max = now\n // console.log(now)\n }\n }\n // 0, 1, ..., k - 1\n return BigInt(max) + mul(k - 1, k) / 2n\n }\n function range(i, j) {\n return sum[j] - (sum[i - 1] || 0)\n }\n}\nfunction mul(a, b) {\n return BigInt(a) * BigInt(b)\n}\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const [n, k] = lines[l++].trim().split(' ').map(Number)\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, k, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, k, arr) {\r\n const sum = [arr[0]]\r\n for (let i = 1; i < n; i++) {\r\n sum[i] = sum[i - 1] + arr[i]\r\n }\r\n // console.log(sum)\r\n if (k >= n) {\r\n // const t = Math.floor((k - 1) / (n - 1))\r\n // const r = k % (n - 1)\r\n return BigInt(sum[n - 1]) + mul(k - 1 + k - 1 - n + 1, n) / 2n\r\n } else {\r\n let max = 0\r\n for (let i = 0; i < n; i++) {\r\n const after = n - 1 - i + 1\r\n let now\r\n if (k <= after) {\r\n now = range(i, i + k - 1)\r\n } else {\r\n const before = k - after\r\n now = range(i, n - 1) + range(n - 1 - before + 1, n - 1)\r\n }\r\n if (now > max) max = now\r\n // console.log(now)\r\n if (i + 1 < k) {\r\n const before = k - (i + 1)\r\n now = range(0, before - 1) + range(0, i)\r\n if (now > max) max = now\r\n // console.log(now)\r\n }\r\n }\r\n // 0, 1, ..., k - 1\r\n return BigInt(max) + mul(k - 1, k) / 2n\r\n }\r\n function range(i, j) {\r\n return sum[j] - (sum[i - 1] || 0)\r\n }\r\n}\r\nfunction mul(a, b) {\r\n return BigInt(a) * BigInt(b)\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const sum = [arr[0]]\n for (let i = 1; i < n; i++) {\n sum[i] = sum[i - 1] + arr[i]\n }\n // console.log(sum)\n if (k >= n) {\n // const t = Math.floor((k - 1) / (n - 1))\n // const r = k % (n - 1)\n return BigInt(sum[n - 1]) + mul(k - 1 + k - 1 - n + 1, n) / 2n\n } else {\n let max = 0\n for (let i = 0; i < n; i++) {\n const after = n - 1 - i + 1\n let now\n if (k <= after) {\n now = range(i, i + k - 1)\n } else {\n const before = k - after\n now = range(i, n - 1) + range(n - 1 - before + 1, n - 1)\n }\n if (now > max) max = now\n // console.log(now)\n }\n // 0, 1, ..., k - 1\n return BigInt(max) + mul(k - 1, k) / 2n\n }\n function range(i, j) {\n return sum[j] - (sum[i - 1] || 0)\n }\n}\nfunction mul(a, b) {\n return BigInt(a) * BigInt(b)\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr) {\n const sum = [arr[0]]\n for (let i = 1; i < n; i++) {\n sum[i] = sum[i - 1] + arr[i]\n }\n // console.log(sum)\n if (k >= n) {\n // const t = Math.floor((k - 1) / (n - 1))\n // const r = k % (n - 1)\n return BigInt(sum[n - 1]) + mul(k - 1 + k - 1 - n + 1, n) / 2n\n } else {\n let max = 0\n for (let i = 0; i < n; i++) {\n const after = n - 1 - i + 1\n let now\n if (k <= after) {\n now = range(i, i + k - 1)\n } else {\n const before = k - after\n now = range(i, n - 1) + range(0, before - 1)\n }\n if (now > max) max = now\n }\n // 0, 1, ..., k - 1\n return BigInt(max) + mul(k - 1, k) / 2n\n }\n function range(i, j) {\n return sum[j] - (sum[i - 1] || 0)\n }\n}\nfunction mul(a, b) {\n return BigInt(a) * BigInt(b)\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n\nconst calc = (t)=>{\n /* read */\n let [n, k] = ra();\n let a = ra();\n\n if (n === 1) {\n return a[0] + k - 1;\n }\n \n if (k < n) {\n let i = 0;\n let curSum = 0;\n for (; i < k; i++) {\n curSum += a[i];\n }\n let maxSum = curSum;\n for (; i < n; i++) {\n curSum += a[i];\n curSum -= a[i - k];\n maxSum = Math.max(maxSum, curSum);\n }\n return maxSum + sumab(1, k - 1);\n } else {\n let start = k % n;\n // console.log(`DEBUG t ${t} start`, start);\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += a[i];\n }\n let initial = start + n;\n // console.log(`DEBUG t ${t} initial`, initial);\n let cycles = Math.floor((k - initial) / (n - 1) + 0.000001);\n // console.log(`DEBUG t ${t} cycles`, cycles);\n\n let result = sumab(1, n - 1) * 2 * cycles + sum;\n // console.log(`DEBUG t ${t} result1`, result);\n\n let remMoves = k - initial - cycles * (n - 1);\n // console.log(`DEBUG t ${t} remMoves`, remMoves);\n result += sumab(1, remMoves) * 2;\n // console.log(`DEBUG t ${t} result2`, result);\n\n result += sumab(1, start) + sumab(1, start - 1) * 2;\n // console.log(`DEBUG t ${t} result3`, result);\n\n let rem = n - start;\n // console.log(`DEBUG t ${t} rem`, rem);\n let ns = start * 2;\n result += sumab(ns, ns + rem - 1);\n // console.log(`DEBUG t ${t} result4`, result);\n return result;\n }\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a) {\r\n if (m >= n) {\r\n return a.reduce((a, b) => a + b, 0) + m * (m - 1) / 2 - (m - n) * (m - n - 1) / 2;\r\n }\r\n const sum = [];\r\n let max = 0;\r\n for (let [i, num] of a.entries()) {\r\n var _sum, _sum2;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + num;\r\n max = Math.max(max, sum[i] - ((_sum2 = sum[i - m]) !== null && _sum2 !== void 0 ? _sum2 : 0));\r\n }\r\n return max + m * (m - 1) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "e092d58ac58e1e41d17be946128234e5"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n [n, k] = readline().split(' ').map(x => parseInt(x));\n p = readline().split(' ').map(x => parseInt(x));\n let mnMax = n - k + 1;\n let pos = -1;\n let sum = 0;\n let parts = 1;\n p.forEach((val, index) => {\n if(val >= mnMax){\n sum += val;\n if(pos != -1)\n parts = (parts * (index - pos)) % 998244353;\n pos = index;\n }\n })\n console.log(sum, parts);\n}\n\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const [n, k] = readInts()\n const p = readInts()\n const mod = 998244353\n const x = p.map((a, i) => [a, i])\n x.sort((a, b) => b[0] - a[0])\n let ans1 = 0\n let ans2 = 1\n const mark = new Array(n).fill(0)\n for(let i = 0; i < k; i++) {\n ans1 += x[i][0]\n mark[x[i][1]] = 1\n }\n let ptr = mark[0] ? 0 : -1\n for(let i = 1; i < n; i++) {\n if(mark[i] && ptr === -1) {\n ptr = i\n }\n else if(mark[i] && ptr !== -1) {\n ans2 = ans2 *(i - ptr) % mod\n ptr = i\n }\n }\n\n wr(ans1, ans2)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nvar inputString = '';\nvar currentLine = 0;\nprocess.stdin.on('data', function (input) { inputString += input; });\nprocess.stdin.on('end', function (_) { inputString = inputString.split('\\n'); main(); });\nvar readline = function () { return inputString[currentLine++]; };\nfunction main() {\n var _a = readline().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], k = _a[1];\n var p = readline().split(' ').map(function (x) { return parseInt(x); });\n var mnMax = n - k + 1;\n var pos = -1;\n var sum = 0;\n var parts = 1;\n p.forEach(function (val, index) {\n if (val >= mnMax) {\n sum += val;\n if (pos != -1)\n parts = (parts * (index - pos)) % 998244353;\n pos = index;\n }\n });\n console.log(sum, parts);\n}\n"}, {"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n const [num, k] = lines[0].split(' ').map(x => +x)\n\n const nums = lines[1].split(' ').map(x => +x)\n const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)\n const max = sliced.reduce((r, x) => r+x.num, 0)\n\n sliced.sort((a, b) => a.pos - b.pos)\n\n let multipliers = []\n let prevPos = sliced[0].pos\n for (let i=1; i 1) {\n multipliers.push(pos - prevPos)\n }\n prevPos = pos\n }\n\n let sum = 1\n for (const m of multipliers) {\n sum = (sum * m) % mod\n }\n\n console.log(`${max} ${sum}`)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n const [num, k] = lines[0].split(' ').map(x => +x)\n\n const nums = lines[1].split(' ').map(x => +x)\n const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)\n const max = sliced.reduce((r, x) => r+x.num, 0)\n\n sliced.sort((a, b) => a.pos - b.pos)\n\n let multipliers = []\n let prevPos = 0\n for (let i=0; i 1) {\n multipliers.push(pos - prevPos)\n }\n prevPos = pos\n }\n\n let sum = 1\n for (const m of multipliers) {\n sum = (sum * m) % mod\n }\n\n console.log(`${max} ${sum}`)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const mod = 998244353\n\nconst processData = (lines) => {\n const [num, k] = lines[0].split(' ').map(x => +x)\n\n const nums = lines[1].split(' ').map(x => +x)\n const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)\n const max = sliced.reduce((r, x) => r+x.num, 0)\n\n sliced.sort((a, b) => a.pos - b.pos)\n\n let multipliers = []\n let prevPos = 0\n for (let i=0; i 1) {\n multipliers.push(pos - prevPos)\n }\n prevPos = pos\n }\n if (prevPos < num - 1) {\n multipliers.push(num - 1 - prevPos)\n }\n\n let sum = 1\n for (const m of multipliers) {\n sum = (sum * m) % mod\n }\n\n console.log(`${max} ${sum}`)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "926c01419301caff034988aff98edc9d"} {"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i <= Number(q[0]); i++) {\n console.log(solve(q[i]))\n }\n}\nfunction solve(n) {\n const ang1 = Math.PI / n;\n const R = 0.5 / Math.sin(ang1 / 2);\n function ee(shift) {\n let xl = Number.MAX_VALUE;\n let yb = Number.MAX_VALUE;\n let xr = Number.MIN_VALUE;\n let yt = Number.MIN_VALUE;\n for (let i = 0; i < 2 * n; i++) {\n const x = Math.cos(Math.PI / n * i + shift);\n const y = Math.sin(Math.PI / n * i + shift);\n xl = Math.min(xl, x);\n xr = Math.max(xr, x);\n yb = Math.min(yb, y);\n yt = Math.max(yt, y);\n }\n return Math.max(xr - xl, yt - yb) * R;\n }\n\n return ee(Math.PI / 4 / n).toPrecision(10);\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst input = [];\nfunction A(q) {\n for (let i = 1; i <= Number(q[0]); i++) {\n console.log(solve(q[i]))\n }\n}\nfunction solve(n) {\n const ang1 = Math.PI / n;\n const R = 0.5 / Math.sin(ang1 / 2);\n function ee(shift) {\n let xl = Number.MAX_VALUE;\n let yb = Number.MAX_VALUE;\n let xr = Number.MIN_VALUE;\n let yt = Number.MIN_VALUE;\n for (let i = 0; i < 2 * n; i++) {\n const x = R * Math.cos(Math.PI / n * i + shift);\n const y = R * Math.sin(Math.PI / n * i + shift);\n xl = Math.min(xl, x);\n xr = Math.max(xr, x);\n yb = Math.min(yb, y);\n yt = Math.max(yt, y);\n }\n return Math.max(xr - xl, yt - yb);\n }\n let l = 0;\n let r = (2 * Math.PI) / (2 * n);\n for (let i = 0; i < 100; i++) {\n const l1 = (2 * l + r) / 3;\n const r1 = (2 * r + l) / 3;\n const calc1 = ee(l1);\n const calc2 = ee(r1);\n if (calc1 < calc2) {\n r = r1;\n } else {\n l = l1;\n }\n }\n return ee((l + r) / 2).toPrecision(10);\n}\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', q => {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}, {"source_code": "function Main() {\n var A = Number(readline());\n for(var i=0;i {\n input.push(q.trim())\n});\nrl.on('close', () => {\n A(input);\n})\n"}], "src_uid": "c466c909fff92353ea676b643ca76908"} {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n// 05/20/21 afternoon\r\n\r\nconst solve = (n, s) => {\r\n let cnt = 0;\r\n for (const c of s) cnt += (c == '0');\r\n if (cnt == 0) return pr('DRAW');\r\n if (!isPalindrome(s)) {\r\n if (n & 1 && s[n >>> 1] == '0' && cnt == 2) {\r\n return pr('DRAW');\r\n }\r\n return pr('ALICE');\r\n }\r\n if (n & 1 && s[n >>> 1] == '0') {\r\n if (cnt == 1) {\r\n return pr('BOB');\r\n } else if (cnt == 2) {\r\n return pr('DRAW');\r\n } else {\r\n return pr(\"ALICE\");\r\n }\r\n }\r\n pr('BOB');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()", "positive_code": [{"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n let diff = 0\n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - 1 - i\n if (str[i] !== str[j]) diff++\n else if (str[i] === '0') zero++\n }\n\n let cost\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n if (zero === 1) {\n cost = [1, 0]\n // if diff > 1, alice will reverse, and make bob pay the total\n if (diff > 1) {\n cost = [0, 1 + diff]\n } else if (diff === 1) {\n // if diff == 1, bob can force alice to fill the uniqe 0 \n cost = [1, 1]\n }\n } else {\n // alices starts the process\n // if bob skips to reduce the diff, just reverse\n cost = [1, 2 + diff]\n }\n } else {\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n cost = [2, 0]\n if (diff) {\n // alice reverses first, no matter bob chooses to reduce the diff,\n // or start 00 process, bob pays the total\n cost = [0, 2 + diff]\n }\n }\n\n\n if (cost[0] !== cost[1]) {\n return cost[0] < cost[1] ? 'ALICE' : 'BOB'\n } else {\n return 'DRAW'\n }\n}\n"}], "negative_code": [{"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n let diff = 0\n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - 1 - i\n if (str[i] !== str[j]) diff++\n else if (str[i] === '0') zero++\n }\n\n let cost\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n if (zero === 1) {\n cost = [1, 0]\n // if diff > 1, alice will reverse, and make bob pay the total\n if (diff > 1) {\n cost = [0, 1 + diff]\n } else {\n // if diff == 1, bob can force alice to fill the uniqe 0 \n cost = [1, 1]\n }\n } else {\n // alices starts the process\n // if bob skips to reduce the diff, just reverse\n cost = [1, 2 + diff]\n }\n } else {\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n cost = [2, 0]\n if (diff) {\n // alice reverses first, no matter bob chooses to reduce the diff,\n // or start 00 process, bob pays the total\n cost = [0, 2 + diff]\n }\n }\n\n\n if (cost[0] !== cost[1]) {\n return cost[0] < cost[1] ? 'ALICE' : 'BOB'\n } else {\n return 'DRAW'\n }\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n let diff = 0\n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - 1 - i\n if (str[i] !== str[j]) diff++\n else if (str[i] === '0') zero++\n }\n\n let cost\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n if (zero === 1) {\n cost = [1, 0]\n } else {\n cost = [1, 2]\n }\n } else {\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n cost = [2, 0]\n }\n\n const [a, b] = cost\n if (diff) {\n // not reverse, [a + diff, b]\n // reverse, [b, a + diff]\n cost = [Math.min(a + diff, b), Math.max(a + diff, b)]\n }\n\n if (cost[0] !== cost[1]) {\n return cost[0] < cost[1] ? 'ALICE' : 'BOB'\n } else {\n return 'DRAW'\n }\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const mid = Math.ceil(str.length / 2)\n\n let zero = 0\n let diff = 0\n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - 1 - i\n if (str[i] !== str[j]) diff++\n else if (str[i] === '0') zero++\n }\n\n // 00x00 -> 10x00 -> 10x01, same with 0x0\n let cost = [2, 0]\n if ((str.length & 1) && str[mid - 1] === '0') {\n // alice change the middle 0 first\n // then convert to 0x0\n cost = [1, 2]\n return diff === 1 ? 'DRAW' : 'ALICE'\n }\n if (diff) {\n cost = [0, 2 + diff]\n }\n\n const [a, b] = cost\n if (a !== b) {\n return a < b ? 'ALICE' : 'BOB'\n } else {\n return 'DRAW'\n }\n}\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nlet cache0, cache1\nfunction solve(str) {\n cache0 = {}\n cache1 = {}\n\n const mid = Math.ceil(str.length / 2) \n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - i\n cache0[i] = solvePay(str, i, j)\n cache1[i] = solvePay(str, i, j, 1)\n }\n const [a, b] = cache0[0]\n // console.log(cache0)\n if (a === b) return 'DRAW'\n return a < b ? 'ALICE' : 'BOB'\n}\n\n// @returns [a, b, p], `p` means `str` is palindrome\nfunction solvePay(str, i, j, r /* if 1, can't reverse */) {\n str = str.slice(i, j)\n\n const len = str.length\n if (len === 1) {\n return str === '1' ? [0, 0, 1] : [1, 0, 1]\n } else if (len === 2) {\n if (str === '11') {\n return [0, 0, 1]\n } else if (str === '00') {\n // change -> reverse -> change\n return [2, 0, 1]\n } else {\n // reverse -> change\n return r ? [1, 0, 0] : [0, 1, 0]\n }\n } else {\n const r1 = cache0[i + 1]\n const r2 = cache1[i + 1]\n const [a, b, p] = r1\n const [a2, b2, p2] = r2\n\n str = str[0] + str[str.length - 1]\n if (str === '11') {\n if (r) {\n // still can't reverse, do nothing\n return r2\n } else if (p) {\n return r1\n } else {\n return [b, a, p]\n }\n } else if (str === '00') {\n if (p || r) {\n // can't reverse\n return [b + 2, a, p]\n } else {\n return [a, b + 2, p]\n }\n } else {\n if (r) {\n return [a + 1, b, 0]\n } else {\n return [a, b + 1, 0]\n }\n }\n }\n}\n\n// console.log(solvePay('11'))\n// console.log(solvePay('1111'))\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nlet cache0, cache1\nfunction solve(str) {\n cache0 = {}\n cache1 = {}\n\n const mid = Math.ceil(str.length / 2) \n for (let i = mid - 1; i >= 0; i--) {\n const j = str.length - i\n cache0[i] = solvePay(str, i, j)\n cache1[i] = solvePay(str, i, j, 1)\n }\n const [a, b] = cache0[0]\n // console.log(cache0)\n if (a === b) return 'DRAW'\n return a < b ? 'ALICE' : 'BOB'\n}\nfunction solvePay(str, i, j, r /* if 1, can't reverse */) {\n str = str.slice(i, j)\n\n const len = str.length\n if (len === 1) {\n return str === '1' ? [0, 0, 1] : [1, 0, 1]\n } else if (len === 2) {\n if (str === '11') {\n return [0, 0, 1]\n } else if (str === '00') {\n // change -> reverse -> change\n return [2, 0, 1]\n } else {\n // reverse -> change\n return r ? [1, 0, 0] : [0, 1, 0]\n }\n } else {\n const r1 = cache0[i + 1]\n const r2 = cache1[i + 1]\n const [a, b, p] = r1\n const [a2, b2, p2] = r2\n\n str = str[0] + str[str.length - 1]\n if (str === '11') {\n if (r) {\n // still can't reverse\n return r2\n } else {\n return r1\n }\n } else if (str === '00') {\n if (p || r) {\n // can't reverse\n return [a + 2, b, p]\n } else {\n return [a, b + 2, p]\n }\n } else {\n if (r) {\n return [a + 1, b, 0]\n } else {\n return [a, b + 1, 0]\n }\n }\n }\n}\n\n// console.log(solvePay('11'))\n// console.log(solvePay('1111'))\n"}, {"source_code": "var readline = require('readline');\n\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n console.log(solve(lines[l++]));\n }\n});\n\nfunction solve(str) {\n const [a, b] = solvePay(str)\n if (a === b) return 'DRAW'\n return a < b ? 'ALICE' : 'BOB'\n}\nfunction solvePay(str) {\n if (str.length === 1) {\n return str === '1' ? [0, 0, 1] : [1, 0, 1]\n } else if (str.length === 2) {\n if (str === '11') {\n return [0, 0, 1]\n } else if (str === '00') {\n // change -> reverse -> change\n return [2, 0, 1]\n } else {\n // reverse -> change\n return [0, 1, 0]\n }\n } else {\n const [a, b, p] = solvePay(str.slice(1, -1))\n if (str === '11') {\n return [a, b, p]\n } else if (str === '00') {\n if (p) {\n return [a + 2, b, p]\n } else {\n return [a, b + 2, p]\n }\n } else {\n return [a, b + 1, 0]\n }\n }\n}\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 afternoon\r\n * https://codeforces.com/contest/1527/problem/B2\r\n */\r\n\r\nconst solve = (n, s) => {\r\n let se = new Set();\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == '0') se.add(i);\r\n }\r\n let a = s.split(\"\");\r\n let Alice = Bob = 0;\r\n let isP = isPalindrome(s);\r\n let round = 1;\r\n let pre;\r\n while (se.size) {\r\n if (isP == false && pre != 'rv') {\r\n a.reverse();\r\n pre = 'rv';\r\n } else {\r\n let did = false;\r\n for (const i of se) {\r\n if (i == n - 1 - i || a[n - 1 - i] == '1') {\r\n a[i] = '1';\r\n did = true;\r\n se.delete(i);\r\n break;\r\n }\r\n }\r\n if (!did) {\r\n let first = se.values().next().value;\r\n a[first] = '1';\r\n se.delete(first);\r\n isP = false;\r\n }\r\n round & 1 ? Alice++ : Bob++;\r\n pre = 'rp';\r\n }\r\n round++;\r\n }\r\n if (Alice > Bob) {\r\n pr(\"BOB\");\r\n } else if (Alice < Bob) {\r\n pr(\"ALICE\");\r\n } else {\r\n pr(\"DRAW\")\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "aef15a076b04e510e663a41341c8d156"} {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [-1, -1];\r\n skip: for (let i = 0; i < n; i++) {\r\n const dp = [],\r\n nums = grid[i];\r\n for (let j = m - 1; j >= 0; j--) {\r\n var _nums$dp;\r\n if (nums[j] < ((_nums$dp = nums[dp[j + 1]]) !== null && _nums$dp !== void 0 ? _nums$dp : Infinity)) {\r\n dp[j] = j;\r\n } else {\r\n dp[j] = dp[j + 1];\r\n }\r\n }\r\n for (let j = 0; j < m; j++) {\r\n if (nums[dp[j]] < nums[j]) {\r\n res = [j, dp[j]];\r\n break skip;\r\n }\r\n }\r\n }\r\n if (res[0] === -1) return `1 1`;\r\n const [a, b] = res;\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n", "positive_code": [{"source_code": "const comp = (arr,n)=>{\r\n let sort = [...arr].sort((a,b)=>a-b);\r\n let res = [],cnt = 0;\r\n for(let i=0;i{\r\n for(let i=0;i{\r\n for(let i=0;iarr[i][j]) return false;\r\n }\r\n }\r\n return true;\r\n}\r\nconst solve = (arr,n,m)=>{\r\n if(m===1) return `1 1`;\r\n for(let i=0;iparseInt(cur));\r\n let mat = [];\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(mat,n,m))\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n, m] = ra();\n let A = [];\n let SA = [];\n for (let i=0; ia-b));\n }\n LT({n, m, A});\n //L(SA.join('\\n'))\n // PROCESSING:\n let DIFFS = [];\n let ref_diff;\n for (let i=0; i2)\n return -1;\n if (diffs.length==2)\n ref_diff = diffs;\n DIFFS.push(diffs);\n }\n if (!ref_diff)\n return '1 1';\n for (let i=0; i lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n let cols = new Array(m);\n let scols = new Array(m);\n let sg = [];\n for (let i = 0; i < n; i++) {\n let row = ra();\n g.push(row);\n sg.push([...row]);\n }\n\n for (let i = 0; i < m; i++) {\n cols[i] = i;\n scols[i] = i;\n }\n\n if (m === 1) return \"1 1\";\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n const isEq = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] !== g[i][b]) return false;\n }\n return true;\n }\n\n for (let i = 0; i < n; i++) {\n sg[i].sort((a, b) => a - b);\n }\n\n\n // scols.sort((a, b) => {\n // if (isEq(a, b)) return 0;\n // if (isInc(a, b)) return -1;\n // return 1;\n // });\n\n // console.log('DEBUG g', g);\n // console.log('DEBUG sg', sg);\n\n let diffs = new Set();\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m; j++) {\n if (g[i][j] !== sg[i][j]) diffs.add(j);\n }\n }\n\n // console.log('DEBUG diffs', diffs);\n \n diffs = Array.from(diffs);\n\n if (diffs.length > 2) return \"-1\";\n\n if (diffs.length === 2) {\n for (let i = 0; i < n; i++) {\n let tmp = g[i][diffs[0]];\n g[i][diffs[0]] = g[i][diffs[1]];\n g[i][diffs[1]] = tmp;\n }\n }\n\n // console.log('DEBUG g', g);\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m - 1; j++) {\n if (g[i][j] > g[i][j + 1]) return \"-1\";\n }\n }\n\n return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : \"1 1\";\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [];\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n let a = -1,\r\n b = -1;\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) {\r\n let t = j - 1;\r\n for (let k = j - 1; k >= 0; k--) {\r\n if (nums[k] === nums[j - 1]) t = k;\r\n }\r\n if (t === j - 1) {\r\n let t1 = j;\r\n for (let k = j + 1; k < m; k++) {\r\n if (nums[k] <= nums[j]) t1 = k;\r\n }\r\n if (t1 === j) {\r\n if (nums[j + 1] < nums[j]) {\r\n [a, b] = [t, j + 1];\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n } else {\r\n [a, b] = [t, t1];\r\n }\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n break;\r\n }\r\n }\r\n if (a !== -1) {\r\n res.push([a, b]);\r\n break;\r\n }\r\n }\r\n if (!res.length) return `1 1`;\r\n const [a, b] = res[0];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n for (let i = 0; i < n; i++) {\n g.push(ra());\n }\n\n if (m === 1) return \"1 1\";\n\n // console.log('DEBUG g', g);\n\n let lastIncCol = 0;\n let lastDecCol = m - 1;\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n while (lastIncCol < m - 1 && isInc(lastIncCol, lastIncCol + 1)) lastIncCol++;\n\n // console.log('DEBUG lastIncCol', lastIncCol);\n\n if (lastIncCol === m - 1) return \"1 1\";\n\n while (lastDecCol > 0 && isDec(lastDecCol, lastDecCol - 1)) lastDecCol--;\n\n // console.log('DEBUG lastDecCol', lastDecCol);\n\n for (let i = 0; i < n; i++) {\n let tmp = g[i][lastIncCol];\n g[i][lastIncCol] = g[i][lastDecCol];\n g[i][lastDecCol] = tmp;\n }\n\n for (let i = 0; i < m - 1; i++) {\n if (!isInc(i, i + 1)) return \"-1\";\n }\n\n return `${lastIncCol + 1} ${lastDecCol + 1}`;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n let cols = new Array(m);\n let scols = new Array(m);\n let sg = [];\n for (let i = 0; i < n; i++) {\n let row = readline().split(' ');\n g.push(row);\n sg.push([...row]);\n }\n\n for (let i = 0; i < m; i++) {\n cols[i] = i;\n scols[i] = i;\n }\n\n if (m === 1) return \"1 1\";\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n const isEq = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] !== g[i][b]) return false;\n }\n return true;\n }\n\n for (let i = 0; i < n; i++) {\n sg[i].sort((a, b) => a - b);\n }\n\n\n // scols.sort((a, b) => {\n // if (isEq(a, b)) return 0;\n // if (isInc(a, b)) return -1;\n // return 1;\n // });\n\n // console.log('DEBUG g', g);\n // console.log('DEBUG sg', sg);\n\n let diffs = new Set();\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m; j++) {\n if (g[i][j] !== sg[i][j]) diffs.add(j);\n }\n }\n\n // console.log('DEBUG diffs', diffs);\n \n diffs = Array.from(diffs);\n\n if (diffs.length > 2) return \"-1\";\n\n if (diffs.length === 2) {\n for (let i = 0; i < n; i++) {\n let tmp = g[i][diffs[0]];\n g[i][diffs[0]] = g[i][diffs[1]];\n g[i][diffs[1]] = tmp;\n }\n }\n\n // console.log('DEBUG g', g);\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m - 1; j++) {\n if (g[i][j] > g[i][j + 1]) return \"-1\";\n }\n }\n\n return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : \"1 1\";\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n let cols = new Array(m);\n let scols = new Array(m);\n let sg = [];\n for (let i = 0; i < n; i++) {\n let row = readline().split(' ');\n g.push(row);\n sg.push([...row]);\n }\n\n for (let i = 0; i < m; i++) {\n cols[i] = i;\n scols[i] = i;\n }\n\n if (m === 1) return \"1 1\";\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n const isEq = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] !== g[i][b]) return false;\n }\n return true;\n }\n\n for (let i = 0; i < n; i++) {\n sg[i].sort((a, b) => a - b);\n }\n\n\n // scols.sort((a, b) => {\n // if (isEq(a, b)) return 0;\n // if (isInc(a, b)) return -1;\n // return 1;\n // });\n\n // console.log('DEBUG sg', sg);\n\n let diffs = new Set();\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m; j++) {\n if (g[i][j] !== sg[i][j]) diffs.add(j);\n if (diffs.size > 2) return \"-1\";\n }\n }\n \n diffs = Array.from(diffs);\n\n if (diffs.length !== 2 && diffs.length !== 0) return \"-1\";\n\n if (diffs.length === 2) {\n // console.log('DEBUG diffs', diffs);\n for (let i = 0; i < n; i++) {\n let tmp = g[i][diffs[0]];\n g[i][diffs[0]] = g[i][diffs[1]];\n g[i][diffs[1]] = tmp;\n }\n }\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m - 1; j++) {\n if (g[i][j] > g[i][j + 1]) return \"-1\";\n }\n }\n\n return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : \"1 1\";\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n let cols = new Array(m);\n let scols = new Array(m);\n let sg = [];\n for (let i = 0; i < n; i++) {\n let row = readline().split(' ');\n g.push(row);\n sg.push([...row]);\n }\n\n for (let i = 0; i < m; i++) {\n cols[i] = i;\n scols[i] = i;\n }\n\n if (m === 1) return \"1 1\";\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n const isEq = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] !== g[i][b]) return false;\n }\n return true;\n }\n\n for (let i = 0; i < n; i++) {\n sg[i].sort((a, b) => a - b);\n }\n\n\n // scols.sort((a, b) => {\n // if (isEq(a, b)) return 0;\n // if (isInc(a, b)) return -1;\n // return 1;\n // });\n\n // console.log('DEBUG sg', sg);\n\n let diffs = new Set();\n\n for (let i = 0; i < n; i++){\n for (let j = 0; j < m; j++) {\n if (g[i][j] !== sg[i][j]) diffs.add(j);\n if (diffs.size > 2) return \"-1\";\n }\n }\n \n diffs = Array.from(diffs);\n\n if (diffs.length !== 2 && diffs.length !== 0) return \"-1\";\n\n if (diffs.length === 2) {\n for (let i = 0; i < n; i++) {\n let tmp = g[i][diffs[0]];\n g[i][diffs[0]] = g[i][diffs[1]];\n g[i][diffs[1]] = tmp;\n }\n }\n\n for (let i = 0; i < m - 1; i++) {\n if (!isInc(i, i + 1)) return \"-1\";\n }\n\n return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : \"1 1\";\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n let cols = new Array(m);\n let scols = new Array(m);\n let sg = [];\n for (let i = 0; i < n; i++) {\n let row = readline().split(' ');\n g.push(row);\n sg.push([...row]);\n }\n\n for (let i = 0; i < m; i++) {\n cols[i] = i;\n scols[i] = i;\n }\n\n if (m === 1) return \"1 1\";\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n const isEq = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] !== g[i][b]) return false;\n }\n return true;\n }\n\n\n scols.sort((a, b) => {\n if (isEq(a, b)) return 0;\n if (isInc(a, b)) return -1;\n return 1;\n });\n\n // console.log('DEBUG scols', scols);\n\n let diffs = [];\n\n for (let i = 0; i < m; i++) {\n if (cols[i] !== scols[i]) diffs.push(i);\n if (diffs.length > 2) return \"-1\";\n }\n\n if (diffs.length !== 2 && diffs.length !== 0) return \"-1\";\n\n if (diffs.length === 2) {\n for (let i = 0; i < n; i++) {\n let tmp = g[i][diffs[0]];\n g[i][diffs[0]] = g[i][diffs[1]];\n g[i][diffs[1]] = tmp;\n }\n }\n\n for (let i = 0; i < m - 1; i++) {\n if (!isInc(i, i + 1)) return \"-1\";\n }\n\n return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : \"1 1\";\n \n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = ()=>{\n /* read */\n let [n, m] = ra();\n let g = [];\n for (let i = 0; i < n; i++) {\n g.push(readline().split(' '));\n }\n\n if (m === 1) return \"1 1\";\n\n // console.log('DEBUG g', g);\n\n let lastIncCol = 0;\n let lastDecCol = m - 1;\n\n const isInc = (a, b) => {\n for (let i = 0; i < n; i++) {\n if (g[i][a] > g[i][b]) return false;\n }\n return true;\n }\n\n const isDec = (a, b) => {\n let eqcnt = 0;\n for (let i = 0; i < n; i++) {\n if (g[i][a] < g[i][b]) return false;\n if (g[i][a] === g[i][b]) eqcnt++;\n }\n return eqcnt !== n;\n }\n\n while (lastIncCol < m - 1 && isInc(lastIncCol, lastIncCol + 1)) lastIncCol++;\n\n // console.log('DEBUG lastIncCol', lastIncCol);\n\n if (lastIncCol === m - 1) return \"1 1\";\n\n while (lastDecCol > 0 && isDec(lastDecCol, lastDecCol - 1)) lastDecCol--;\n\n // console.log('DEBUG lastDecCol', lastDecCol);\n\n for (let i = 0; i < n; i++) {\n let tmp = g[i][lastIncCol];\n g[i][lastIncCol] = g[i][lastDecCol];\n g[i][lastDecCol] = tmp;\n }\n\n for (let i = 0; i < m - 1; i++) {\n if (!isInc(i, i + 1)) return \"-1\";\n }\n\n return `${lastIncCol + 1} ${lastDecCol + 1}`;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc());\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [];\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n let a = -1,\r\n b = -1;\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) {\r\n let t = j - 1;\r\n for (let k = j - 1; k >= 0; k--) {\r\n if (nums[k] === nums[j - 1]) t = k;\r\n }\r\n if (t === j - 1) {\r\n let t1 = j;\r\n for (let k = j + 1; k < m; k++) {\r\n if (nums[k] === nums[j]) t1 = k;\r\n }\r\n if (t1 === j) {\r\n if (nums[j + 1] < nums[j]) {\r\n [a, b] = [t, j + 1];\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n } else {\r\n [a, b] = [t, t1];\r\n }\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n break;\r\n }\r\n }\r\n if (a !== -1) {\r\n res.push([a, b]);\r\n break;\r\n }\r\n }\r\n if (!res.length) return `1 1`;\r\n const [a, b] = res[0];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [];\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n let a = -1,\r\n b = -1;\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) {\r\n let t = j - 1;\r\n while (nums[t - 1] === nums[j - 1]) {\r\n t--;\r\n }\r\n if (t === j - 1) {\r\n let t1 = j;\r\n for (let k = j + 1; k < m; k++) {\r\n if (nums[k] === nums[j]) t1 = k;\r\n }\r\n if (t1 === j) {\r\n if (nums[j + 1] < nums[j]) {\r\n [a, b] = [t, j + 1];\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n } else {\r\n [a, b] = [t, t1];\r\n }\r\n } else {\r\n [a, b] = [t, j];\r\n }\r\n break;\r\n }\r\n }\r\n if (a !== -1) {\r\n res.push([a, b]);\r\n break;\r\n }\r\n }\r\n if (!res.length) return `1 1`;\r\n const [a, b] = res[0];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [];\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n let index = [-1, -1];\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) {\r\n let t = j - 1;\r\n while (nums[t - 1] === nums[t]) {\r\n t--;\r\n }\r\n if (t === j - 1) {\r\n let t1 = j;\r\n while (nums[t1 + 1] === nums[j]) {\r\n t1++;\r\n }\r\n if (t1 === j) {\r\n if (nums[j + 1] < nums[j]) {\r\n index = [t, j + 1];\r\n } else {\r\n index = [t, j];\r\n }\r\n } else {\r\n index = [j - 1, t1];\r\n }\r\n } else {\r\n index = [t, j];\r\n }\r\n break;\r\n }\r\n }\r\n if (index[0] !== -1) {\r\n res.push(index);\r\n break;\r\n }\r\n }\r\n if (!res.length) return `1 1`;\r\n const [a, b] = res[0];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, grid) {\r\n let res = [];\r\n const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];\r\n for (let i = 0; i < n; i++) {\r\n let index = [-1, -1];\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) {\r\n if (j > 2 && nums[j] < nums[j - 3]) return -1;\r\n if (j < m - 2 && nums[j - 1] > nums[j + 2]) return -1;\r\n if (j > 1 && nums[j - 1] === nums[j - 2]) {\r\n if (nums[j - 1] > nums[j + 1]) return -1;\r\n index = [j - 2, j];\r\n } else if (nums[j] >= nums[j + 1]) {\r\n if (j > 1 && nums[j + 1] < nums[j - 2]) return -1;\r\n index = [j - 1, j + 1];\r\n } else {\r\n if (nums[j - 1] > nums[j + 1]) return -1;\r\n index = [j - 1, j];\r\n }\r\n break;\r\n }\r\n }\r\n if (index[0] !== -1) {\r\n res.push(index);\r\n break;\r\n }\r\n }\r\n if (!res.length) return `1 1`;\r\n const [a, b] = res[0];\r\n for (let i = 0; i < n; i++) {\r\n if (grid[i][a] < grid[i][b]) return -1;\r\n swap(i, a, b);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = 1; j < m; j++) {\r\n const nums = grid[i];\r\n if (nums[j] < nums[j - 1]) return -1;\r\n }\r\n }\r\n return [a + 1, b + 1].join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = [];\r\n let tmp = n;\r\n while (tmp--) {\r\n a.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const swap = (arr,c1,c2,n,m)=>{\r\n for(let i=0;i{\r\n for(let i=0;iarr[i][j+1]) return false;\r\n }\r\n }\r\n return true;\r\n}\r\nconst solve = (arr,n,m)=>{\r\n if(m===1) return `1 1`;\r\n let c1 = 0,c2 = 0;\r\n for(let i=0;iarr[i][j]){\r\n cnt++;\r\n c1 = cnt===1 ? j-1 : c1;\r\n c2 = j;\r\n }\r\n }\r\n if(cnt===3) return -1;\r\n if((c1!==0)||(c2!==0)){\r\n swap(arr,c1,c2,n,m);\r\n if(check(arr,n,m)) return `${c1+1} ${c2+1}`;\r\n else return -1;\r\n }\r\n }\r\n return `1 1`;\r\n}\r\n\r\n\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for (let i = 0; i < t; i++) {\r\n let [n,m] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let mat = [];\r\n for(let i=0;iparseInt(cur)));\r\n }\r\n console.log(solve(mat,n,m))\r\n }\r\n}\r\nmain();"}], "src_uid": "cfe752f8ff049e535309c234da60472d"} {"source_code": "n = +readline();\nl = readline().split(\" \").map(Number);\nans = 0;\ncmp = n;\nfor (i = n - 1; i >= 0; i--) {\n if (i < cmp)\n ans++;\n cmp = Math.min(cmp, i - l[i]);\n}\nprint(ans);", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killNum = n\n let alive = 0\n for (let i = n - 1; i >= 0; i--) {\n if (i < killNum) alive++\n killNum = Math.min(killNum, i - l[i])\n }\n \n console.log(alive + '')\n}\n"}, {"source_code": "const count = readline();\nconst claws = readline().split(' ').map(v=> parseInt(v));\n\nvar alive = 0;\nvar lastAlive = claws.length - 1;\n\nfor (var killer = claws.length - 1; killer >= 0; killer--) {\n if (killer === lastAlive) {\n alive++;\n }\n lastAlive = Math.min(lastAlive, killer - claws[killer] - 1);\n}\n\nprint(alive);"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n const claw = arr.shift().split(' ')\n\n var count = 1\n var last = n - 1\n for(let i = n - 1; i >= 0; i --) {\n // console.log(i, claw[i], last, count)\n if(i < last) count ++\n if(i - claw[i] <= last && claw[i] != 0) last = i - claw[i]\n }\n console.log(count)\n})"}, {"source_code": "var n = parseInt(readline());\nvar vivos=0;\nvar array2 = readline().split(' ');\nfor(var i = 0; i < n ; i++){\n\tarray2[i]= parseInt(array2[i]);\n}\nvar ultimo=n-1;\nfor(var i = n-1; i >=0 ;i--){\n\t if (i === ultimo) {\n vivos++;\n }\n ultimo = Math.min(ultimo, i - array2[i] - 1);\n}\nprint(vivos);"}], "negative_code": [{"source_code": "n = +readline();\nl = readline().split().map(Number);\nans = 0\ncmp = n\nfor (i = n - 1; i >= 0; i--) {\n if (i < cmp)\n ans++;\n cmp = Math.min(cmp, i - l[i]);\n}\nprint(ans)"}, {"source_code": "const count = readline();\nconst claws = readline().split(' ').map(v=> parseInt(v));\n\nvar alive = 0;\nvar lastAlive = claws.length - 1;\n\nfor (var killer = claws.length - 1; killer >= 0; killer--) {\n print(lastAlive);\n \n if (killer === lastAlive) {\n alive++;\n }\n\n lastAlive = Math.min(lastAlive, killer - claws[killer] - 1);\n}\n\nprint(alive);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killed = new Set()\n for (let i = n - 1; i >= 0; i--) {\n for (let j = 1; j <= l[i]; j++) {\n killed.add(i - j)\n }\n if (killed.size === n - 1) {\n console.log('1')\n return\n }\n }\n \n console.log((n - killed.size) + '')\n}\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killed = new Set()\n for (let i = n - 1; i >= 0; i--) {\n if (l[i] >= i) {\n if (i === n - 1) {\n console.log('1')\n return;\n }\n break;\n }\n for (let j = 1; j <= l[i] && j <= i; j++) {\n killed.add(i - j)\n }\n if (killed.size >= n - 1) {\n console.log('1')\n return\n }\n }\n \n console.log((n - killed.size) + '')\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killed = new Set()\n for (let i = n - 1; i >= 0; i--) {\n if (l[i] >= i) {\n if (i === n - 1) {\n console.log('1')\n } else {\n console.log((n - killed.size - i + 1) + '')\n }\n return\n \n }\n for (let j = 1; j <= l[i] && j <= i; j++) {\n killed.add(i - j)\n }\n }\n \n console.log((n - killed.size) + '')\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killed = new Set()\n for (let i = n - 1; i >= 0; i--) {\n if (l[i] >= i) {\n if (i === n - 1) {\n console.log('1')\n } else {\n console.log((n - killed.size - i) + '')\n }\n return\n \n }\n for (let j = 1; j <= l[i] && j <= i; j++) {\n killed.add(i - j)\n }\n }\n \n console.log((n - killed.size) + '')\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const n = readline();\n const l = readline().split(' ').map(Number);\n helper(n, l);\n}\n\nfunction helper(n, l) {\n let killed = new Set()\n for (let i = n - 1; i >= 0; i--) {\n if (l[i] >= i) {\n if (i === n - 1) {\n console.log('1')\n return\n } else {\n console.log((n - killed.size - i) + '')\n }\n \n }\n for (let j = 1; j <= l[i] && j <= i; j++) {\n killed.add(i - j)\n }\n }\n \n console.log((n - killed.size) + '')\n}\n"}], "src_uid": "beaeeb8757232b141d510547d73ade04"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine().split(\" \").map(Number);\n let result = arr.reverse();\n result = result.map((n, index) => {\n if (index % 2 === 0) {\n return -1 * n;\n } else return n;\n });\n\n console.log(result.join(\" \"));\n }\n}\n", "positive_code": [{"source_code": "#!/usr/bin/env node\n'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst buf = [];\nconst prom = [];\nlet maxBuf = 0;\nlet maxProm = 0;\nrl.on('line', (line) => {\n if (prom.length > 0) {\n maxProm = Math.max(maxProm, prom.length);\n const [resolve, reject] = prom.shift();\n resolve(line);\n } else {\n rl.pause();\n buf.push(line);\n maxBuf = Math.max(maxBuf, buf.length);\n }\n});\n\nrl.on('close', () => {\n // console.error({maxProm, maxBuf});\n});\n\nasync function getLine() {\n return new Promise((resolve, reject) => {\n if (buf.length > 0) {\n const line = buf.shift();\n resolve(line);\n } else {\n prom.push([resolve, reject]);\n rl.resume();\n }\n });\n}\n\n/**\n * \n * @param {Number []} a\n * @returns {Number []}\n */\nfunction solve(a) {\n const n = a.length;\n const res = [];\n for (let i = 1; i < n; i += 2) {\n res.push(a[i], -a[i-1]);\n }\n return res;\n}\n\nasync function main() {\n const t = Number(await getLine());\n for (let i = 0; i < t; i++) {\n const n = Number(await getLine());\n const a = (await getLine()).split(' ').map(Number);\n const res = solve(a);\n console.log(res.join(' '));\n }\n}\n\nif (require.main === module) {\n main();\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nfunction spltoarr(arr){\n for (let i=0; i0;c-=2,f+=2){\n chakraValues += `${sealValues[f+1]*-1} `;\n chakraValues += `${sealValues[f]} `;\n doorSealCount -=2;\n }\n console.log(chakraValues)\n\n}\n\nvar doorCount, doorSealCount, sealValues, chakraValues;\nchakraValues='';\nrl.on('line', (input) => {\n\nif(doorCount>0){\n \n if(doorSealCount>0 ){\n sealValues=input.split(\" \")\n spltoarr(sealValues)\n sealBreakJutsu(sealValues)\n doorCount -=1\n chakraValues = ''\n } else doorSealCount=parseInt(input)\n\n \n}else doorCount=parseInt(input)\n\n\n})\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nlet arr = []\nlet count = 0\nlet T = 0\nlet str = '';\n \nrl.on('line', (input) => {\n if (count === 0) {\n T = input\n } else if (count % 2 === 0) {\n arr.push(input.split(' '))\n }\n count++\n if (T * 2 + 1 === count) {\n for (let i = 0; i < arr.length; i++) {\n str = '';\n for (let k = 1; k < arr[i].length; k = k + 2) {\n str = str + ' ' + -arr[i][k] + ' ' + arr[i][k-1];\n }\n console.log(str);\n }\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction A(arr) {\n if (!Array.isArray(arr)) return [];\n\n if (arr.length === 0 || arr.length % 2 !== 0) return [];\n\n const result = [];\n\n for (let i = 0; i < arr.length / 2; i++) {\n result.push(-arr[2 * i + 1], arr[2 * i]);\n }\n\n return result;\n}\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline();\n const arrStr = readline();\n const arr = arrStr.split(' ');\n process.stdout.write(A(arr).join(' '));\n process.stdout.write('\\n');\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar b = new Array(N);\n\t\tfor(var j = 0; j < N; j += 2){\n\t\t\tvar L = lcm(list[j], list[j + 1]);\n\t\t\tb[j] = L / list[j];\n\t\t\tb[j + 1] = -L / list[j + 1];\n\t\t}\n\t\t\n\t\toutput[i] = myconv(b, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;rr{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// io.puts(\n// a\n// .reverse()\n// .map((x, i) => (i < n / 2 ? -x : x))\n// .join(\" \")\n// )\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar L = list[0];\n\t\tfor(var j = 1; j < N; j++){\n\t\t\tL = lcm(L, list[j]);\n\t\t}\n\t\tmyerr(L);\n\t\tvar b = new Array(N);\n\t\tif(N % 2 == 1){\n\t\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\t\tif(j < Math.floor(N / 2)){\n\t\t\t\t\tb[j] = L / list[j];\n\t\t\t\t}else{\n\t\t\t\t\tb[j] = -(L / list[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[N - 1] = -L * 2;\n\t\t}else{\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tb[j] = L / list[j];\n\t\t\t\tif(j >= N / 2){\n\t\t\t\t\tb[j] *= -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput[i] = myconv(b, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar L = list[0];\n\t\tfor(var j = 1; j < N; j++){\n\t\t\tL = lcm(L, list[j]);\n\t\t}\n\t\tvar b = new Array(N);\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tb[j] = L / list[j];\n\t\t\tif(j >= N / 2){\n\t\t\t\tb[j] *= -1;\n\t\t\t}\n\t\t}\n\t\tvar sum = 0;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tsum += list[j] * b[j];\n\t\t}\n\t\tmyerr(sum);\n\t\toutput[i] = myconv(b, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar b = new Array(N);\n\t\tfor(var j = 0; j < N; j += 2){\n\t\t\tvar L = lcm(list[j], list[j + 1]);\n\t\t\tb[j] = L / list[j];\n\t\t\tb[j + 1] = L / list[j + 1];\n\t\t}\n\t\t\n\t\toutput[i] = myconv(b, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar L = list[0];\n\t\tfor(var j = 1; j < N; j++){\n\t\t\tL = lcm(L, list[j]);\n\t\t}\n\t\tvar b = new Array(N);\n\t\tif(N % 2 == 1){\n\t\t\tfor(var j = 0; j < N - 1; j++){\n\t\t\t\tif(j <= Math.floor(N / 2)){\n\t\t\t\t\tb[j] = L / list[j];\n\t\t\t\t}else{\n\t\t\t\t\tb[j] = -(L / list[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[N - 1] = -L * 2 / list[j];\n\t\t}else{\n\t\t\tfor(var j = 0; j < N; j++){\n\t\t\t\tb[j] = L / list[j];\n\t\t\t\tif(j >= N / 2){\n\t\t\t\t\tb[j] *= -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\toutput[i] = myconv(b, 8);\n\t}\n\tmyout(myconv(output, 9));\n}\nfunction lcm(m, n) {return (m / gcd(m, n)) * n;}\tfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function p(){return i[u++]}function f(){return p().split(\" \").map((t=>parseFloat(t)))}function h(){return p().split(\"\")}e.default={runMain:c,runEachTest:t=>{c((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:p,nextNumbers:f,nextNumbersMatrix:function(t){let e=[];for(let r=0;r-t)).join(\" \"))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// io.puts(\n// a\n// .reverse()\n// .map((x) => -x)\n// .join(\" \")\n// )\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "const readline = require('readline');\n \nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nlet arr = []\nlet count = 0\nlet T = 0\nlet str = '';\n \nrl.on('line', (input) => {\n if (count === 0) {\n T = input\n } else if (count % 2 === 0) {\n arr.push(input.split(' '))\n }\n count++\n if (T * 2 + 1 === count) {\n for (let i = 0; i < arr.length; i++) {\n str = '';\n for (let k = 1; k < arr[i].length; k = k + 2) {\n let num = k - 1;\n str = str + ' ' + -k + ' ' + num;\n }\n console.log(str);\n }\n }\n});"}], "src_uid": "d5e09a8fb7eeeba9a41daa2b565866ba"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let s = readline().split('');\n let v = new Array(n);\n v.fill('?');\n let flag = true;\n for(let i = 0; i < k; i++){\n for(let j = i; j < n; j+=k){\n if(s[j] === '?')\n continue;\n if(v[i] === '?' || v[i] === s[j])\n v[i] = s[j];\n else{\n flag = false;\n break;\n }\n }\n }\n\n if(flag){\n let c1 = 0;\n let c0 = 0;\n for(let i = 0; i < k; i++){\n if(v[i] === '1') c1++;\n if(v[i] === '0') c0++;\n }\n\n if(c1 > k/2 || c0 > k/2)\n console.log('NO');\n else\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\r?\\n/); r = 0;\n let t = +inp[r++];\n for (let i = 0; i < t; i++) {\n (() => {\n let [n, k] = inp[r++].split(' ').map(v => +v);\n let s = inp[r++].split('');\n // console.log(s.join(''));\n for (let i = 0; i < k; i++) {\n let c = s[i];\n for (let j = i + k; j < n; j += k) {\n if (c != '?' && s[j] != '?' && c != s[j]) {\n // console.log(c, j, s[j]);\n console.log('NO');\n return;\n }\n if (s[j] != '?') c = s[j];\n }\n s[i] = c;\n }\n let c = {};\n for (let i = 0; i < k; i++) c[s[i]] = (c[s[i]] || 0) + 1;\n // console.log(c);\n console.log((c[0] || 0) <= k / 2 && (c[1] || 0) <= k / 2 ? 'YES' : 'NO')\n })();\n }\n})();"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, limit] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = readLine().split(\"\");\n let possible = true;\n let [count0, count1] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n const index = i % limit;\n if (arr[i] === \"?\" && arr[index] !== \"?\") {\n arr[i] = arr[index];\n } else if (arr[index] === \"?\" && arr[i] !== \"?\") {\n arr[index] = arr[i];\n }\n\n if (arr[i] !== arr[index]) {\n possible = false;\n break;\n }\n }\n\n if (possible) {\n for (let i = 0; i < limit; i++) {\n if (arr[i] === \"1\") count1++;\n if (arr[i] === \"0\") count0++;\n }\n\n if (count1 <= limit / 2 && count0 <= limit / 2) possible = true;\n else possible = false;\n }\n\n if (possible) console.log(\"YES\");\n else console.log(\"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "8e448883014bf7cd35fcca3fe0128af0"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n // const [a, b, x] = lines[l++].trim().split(' ').map(Number)\n const [a, b, x] = lines[l++].trim().split(' ').map(BigInt)\n output[i] = solve(a, b, x)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, x) {\n while (a) {\n const r = b % a\n // b, b - a, b - 2 * a, ..., r\n if (x === a) return 'YES'\n if (x >= r && x <= b && !((b - x) % a)) return 'YES'\n b = a\n a = r\n }\n return 'NO'\n}\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\nconst rbna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b, x] = rbna();\r\n\r\n\t\tfunction get (a, b, x) {\r\n\t\t\t// normalize a and b\r\n\t\t\tif (a > b) [a, b] = [b, a];\r\n\t\t\tif (b - a < a) a = b - a;\r\n\r\n\t\t\tif (x == b) return true;\r\n\t\t\tif (x > b || a == 0) return false;\r\n\t\t\tif ((b - x) % a == 0) return true;\r\n\t\t\treturn get(a, a + b % a, x);\r\n\t\t}\r\n\r\n\t\tconsole.log(get(a, b, x) ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\nconst rbna = () => ra().map(x => BigInt(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b, x] = rbna();\r\n\r\n\t\tfunction get (a, b, x) {\r\n\t\t\tif (a > b) [a, b] = [b, a];\r\n\t\t\tif (b - a < a) a = b - a;\r\n\t\t\tif (x == b) return true;\r\n\t\t\tif (x > b || a == 0 || b == 0) return false;\r\n\t\t\tif ((b - x) % a == 0) return true;\r\n\t\t\treturn get(a, a + b % a, x);\r\n\t\t}\r\n\r\n\t\tconsole.log(get(a, b, x) ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "7e23e222ce40547ed8a4f7f1372082d9"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10),\n\t\tdesiredOrder = tokenizeIntegers(readline()),\n\t\tactualOrder = tokenizeIntegers(readline()),\n\t\tversionLookup = {},\n\t\tuniques = [],\n\t\tpositionOf = {};\n\n\tfunction buildVersionString(item) {\n\t\treturn item + \".\" + versionLookup[item];\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = desiredOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tuniques.push(item);\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tpositionOf[buildVersionString(item)] = itemIndex;\n\t}\n\n\tfor (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {\n\t\tversionLookup[uniques[uniqueIndex]] = undefined;\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = actualOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tactualOrder[itemIndex] = positionOf[buildVersionString(item)];\n\t}\n\n\tvar swaps = [];\n\n\twhile (true) {\n\t\tvar madeSwap = (1 == 2);\n\n\t\tfor (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {\n\t\t\tif (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {\n\t\t\t\tvar temp = actualOrder[itemIndex-1];\n\t\t\t\tactualOrder[itemIndex-1] = actualOrder[itemIndex];\n\t\t\t\tactualOrder[itemIndex] = temp;\n\n\t\t\t\tmadeSwap = true;\n\t\t\t\tswaps.push((itemIndex) + \" \" + (itemIndex+1));\n\t\t\t}\n\t\t}// end for\n\n\t\tif (madeSwap == false) {\n\t\t\tbreak;\n\t\t}\n\t}// end while\n\n\tswaps.unshift(swaps.length);\n\tprint(swaps.join(\"\\n\"));\n}// end main\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10),\n\t\tdesiredOrder = tokenizeIntegers(readline()),\n\t\tactualOrder = tokenizeIntegers(readline()),\n\t\tversionLookup = {},\n\t\tuniques = [],\n\t\tpositionOf = {};\n\n\tfunction buildVersionString(item) {\n\t\treturn item + \".\" + versionLookup[item];\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = desiredOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tuniques.push(item);\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tpositionOf[buildVersionString(item)] = itemIndex;\n\t}\n\n\tfor (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {\n\t\tversionLookup[uniques[uniqueIndex]] = undefined;\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = actualOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tactualOrder[itemIndex] = positionOf[buildVersionString(item)];\n\t}\n\n\tvar swaps = [];\n\n\twhile (true) {\n\t\tvar madeSwap = (1 == 0);\n\n\t\tfor (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {\n\t\t\tif (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {\n\t\t\t\tvar temp = actualOrder[itemIndex-1];\n\t\t\t\tactualOrder[itemIndex-1] = actualOrder[itemIndex];\n\t\t\t\tactualOrder[itemIndex] = temp;\n\n\t\t\t\tmadeSwap = true;\n\t\t\t\tswaps.push((itemIndex) + \" \" + (itemIndex+1));\n\t\t\t}\n\t\t}// end for\n\n\t\tif (madeSwap == false) {\n\t\t\tbreak;\n\t\t}\n\t}// end while\n\n\tswaps.unshift(swaps.length);\n\tprint(swaps.join(\"\\n\"));\n}// end main\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10),\n\t\tdesiredOrder = tokenizeIntegers(readline()),\n\t\tactualOrder = tokenizeIntegers(readline()),\n\t\tversionLookup = {},\n\t\tuniques = [],\n\t\tpositionOf = {};\n\n\tfunction buildVersionString(item) {\n\t\treturn item + \".\" + versionLookup[item];\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = desiredOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tuniques.push(item);\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tpositionOf[buildVersionString(item)] = itemIndex;\n\t}\n\n\tfor (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {\n\t\tversionLookup[uniques[uniqueIndex]] = undefined;\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = actualOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tactualOrder[itemIndex] = positionOf[buildVersionString(item)];\n\t}\n\n\tvar swaps = [];\n\n\twhile (true) {\n\t\tvar madeSwap = false;\n\n\t\tfor (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {\n\t\t\tif (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {\n\t\t\t\tvar temp = actualOrder[itemIndex-1];\n\t\t\t\tactualOrder[itemIndex-1] = actualOrder[itemIndex];\n\t\t\t\tactualOrder[itemIndex] = temp;\n\n\t\t\t\tmadeSwap = true;\n\t\t\t\tswaps.push((itemIndex) + \" \" + (itemIndex+1));\n\t\t\t}\n\t\t}// end for\n\n\t\tif (madeSwap == false) {\n\t\t\tbreak;\n\t\t}\n\t}// end while\n\n\tswaps.unshift(swaps.length);\n\tprint(swaps.join(\"\\n\"));\n}// end main\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10),\n\t\tdesiredOrder = tokenizeIntegers(readline()),\n\t\tactualOrder = tokenizeIntegers(readline()),\n\t\tversionLookup = {},\n\t\tuniques = [],\n\t\tpositionOf = {};\n\n\tfunction buildVersionString(item) {\n\t\treturn item + \".\" + versionLookup[item];\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = desiredOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tuniques.push(item);\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tpositionOf[buildVersionString(item)] = itemIndex;\n\t}\n\n\tfor (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {\n\t\tversionLookup[uniques[uniqueIndex]] = undefined;\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = actualOrder[itemIndex];\n\t\tif (versionLookup[item] == undefined) {\n\t\t\tversionLookup[item] = 0;\n\t\t}\n\t\telse {\n\t\t\tversionLookup[item] += 1;\n\t\t}\n\n\t\tactualOrder[itemIndex] = positionOf[buildVersionString(item)];\n\t}\n\n\tvar swaps = new Array();\n\n\twhile (true) {\n\t\tvar madeSwap = false;\n\n\t\tfor (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {\n\t\t\tif (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {\n\t\t\t\tvar temp = actualOrder[itemIndex-1];\n\t\t\t\tactualOrder[itemIndex-1] = actualOrder[itemIndex];\n\t\t\t\tactualOrder[itemIndex] = temp;\n\n\t\t\t\tmadeSwap = true;\n\t\t\t\tswaps.push((itemIndex) + \" \" + (itemIndex+1));\n\t\t\t}\n\t\t}// end for\n\n\t\tif (madeSwap == false) {\n\t\t\tbreak;\n\t\t}\n\t}// end while\n\n\tswaps.unshift(swaps.length);\n\tprint(swaps.join(\"\\n\"));\n}// end main\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numItems = parseInt(readline(), 10),\n\t\tdesiredOrder = tokenizeIntegers(readline()),\n\t\tactualOrder = tokenizeIntegers(readline()),\n\t\titemInfo = {};\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = desiredOrder[itemIndex];\n\t\tif (itemInfo[item] == undefined) {\n\t\t\titemInfo[item] = {\n\t\t\t\toccurrences: [itemIndex],\n\t\t\t\toccurrenceIndex: 0\n\t\t\t};\n\t\t}\n\t\telse {\n\t\t\titemInfo[item].occurrences.push(itemIndex);\n\t\t}\n\t}\n\n\tfor (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {\n\t\tvar item = actualOrder[itemIndex];\n\n\t\tactualOrder[itemIndex] = itemInfo[item].occurrences[\n\t\t\titemInfo[item].occurrenceIndex++];\n\t}\n\n\tvar swaps = [];\n\n\twhile (true) {\n\t\tvar madeSwap = (1+2 == 2);\n\n\t\tfor (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {\n\t\t\tif (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {\n\t\t\t\tvar temp = actualOrder[itemIndex-1];\n\t\t\t\tactualOrder[itemIndex-1] = actualOrder[itemIndex];\n\t\t\t\tactualOrder[itemIndex] = temp;\n\n\t\t\t\tmadeSwap = true;\n\t\t\t\tswaps.push((itemIndex) + \" \" + (itemIndex+1));\n\t\t\t}\n\t\t}// end for\n\n\t\tif (madeSwap == false) {\n\t\t\tbreak;\n\t\t}\n\t}// end while\n\n\tswaps.unshift(swaps.length);\n\tprint(swaps.join(\"\\n\"));\n}// end main\n\nmain();\n"}], "negative_code": [], "src_uid": "e554616ed3df169888acd3452a2f896f"} {"source_code": "function main() {\n var n = +next(), m = +next();\n if (m != n - 1) {\n print(\"no\");\n return;\n }\n var p = [];\n var i;\n for (i = -1; ++ i < n; ) p[i] = i;\n function findp(u) { return (p[u] = u === p[u] ? u : findp(p[u])); }\n function join(u, v) { p[findp(u)] = findp(v); }\n \n while (m--) { \n join(next() - 1, next() - 1);\n }\n var cnt = 0;\n for (i = -1; ++i < n; )\n cnt += +(i === findp(i));\n print(cnt === 1 ? \"yes\" : \"no\");\n}\n\nvar line = null, linepos = 0;\nfunction next() {\n if (!line || linepos === line.length) {\n line = readline().split(' ');\n linepos = 0;\n }\n return line[linepos++];\n}\n\nif (typeof readline == 'undefined') {\n process.stdin.resume();\n process.stdin.setEncoding('ascii');\n \n var input_stdin = \"\";\n process.stdin.on('data', function (data) { input_stdin += data; });\n process.stdin.on('end', function () {\n // input_stdin = input_stdin.split(/\\s/);\n input_stdin = input_stdin.split('\\n');\n var curline = 0;\n readline = () => input_stdin[curline++];\n if (typeof print == 'undefined') print = console.log;\n main();\n });\n} else main();\n", "positive_code": [{"source_code": "function getNumberArray() {\n return readline().split(\" \").map(function(s) { return Number(s); });\n}\n\nvar nm = getNumberArray();\nvar n = nm[0], m = nm[1];\n\nfunction p(brain) {\n if (subtree[brain] == brain) \n return brain;\n \n subtree[brain] = p(subtree[brain]);\n return subtree[brain];\n}\n\nvar subtree = new Array(n); // subtree index for all brains\nfor (var i = 0; i < n; ++i)\n subtree[i] = i;\n\nif (m != n - 1) \n print(\"no\");\nelse {\n \n \n for (var j = 0; j < m; ++j) {\n var ab = getNumberArray();\n var a = ab[0] - 1, b = ab[1] - 1;\n \n var k1 = Math.min(p(a), p(b));\n var k2 = Math.max(p(a), p(b));\n //print(a, \"<-->\", b, \" (\", k1, \"<>\", k2, \")\");\n \n subtree[k2] = k1;\n }\n \n var success = true;\n for (var i = 0; i < n; ++i) \n if (p(i) !== 0) {\n success = false;\n break;\n }\n \n print(success ? \"yes\" : \"no\");\n}\n"}], "negative_code": [{"source_code": "function getNumberArray() {\n return readline().split(\" \").map(function(s) { return Number(s); });\n}\n\nvar nm = getNumberArray();\nvar n = nm[0], m = nm[1];\n\nfunction p(brain) {\n if (subtree[brain] == brain) \n return brain;\n \n subtree[brain] = p(subtree[brain]);\n return subtree[brain];\n}\n\nif (m != n - 1) \n print(\"no\");\nelse {\n var subtree = new Array(n); // subtree index for all brains\n for (var i = 0; i < n; ++i)\n subtree[i] = i;\n \n for (var j = 0; j < m; ++j) {\n var ab = getNumberArray();\n var a = ab[0], b = ab[1];\n \n if (a > b) {\n var tmp = a;\n a = b;\n b = tmp;\n }\n //print(a, \"<-->\", b);\n \n subtree[b - 1] = a - 1;\n }\n \n var success = true;\n for (var i = 0; i < n; ++i) \n if (p(i) !== 0) {\n success = false;\n break;\n }\n \n print(success ? \"yes\" : \"no\");\n}\n"}], "src_uid": "f0c91ae53d5b4fc8019f6a3294978398"} {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var s = lines[j].split(' ').map(Number)\n var a = s[0]\n var m = s[1]\n if(a == 1 && m == 1){\n console.log(0)\n }else if(a == 1 || m == 1){\n console.log(1)\n }else{\n console.log(2)\n }\n }\n});", "positive_code": [{"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n x = +s[0];\r\n y = +s[1];\r\n if (x == 1 && y == 1) print(0);\r\n else if (x == 1 || y == 1) print(1);\r\n else print(2);\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tif (n == 1 && m == 1) console.log(0);\r\n\t\telse if (n == 1 || m == 1) console.log(1);\r\n\t\telse console.log(2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\r\n\t\tif (n == 1 && m == 1) console.log(0);\r\n\t\telse if (n == 1 || m == 1) console.log(1);\r\n\t\telse console.log(2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var s = lines[i].split(' ').map(Number);\n var n = s[0], m = s[1];\n if(n == 1 && m == 1){\n console.log(0);\n }else if(n == 1 || m == 1){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n});"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, m] = rna();\r\n\r\n\t\tif (n == 1 || m == 1) console.log(1);\r\n\t\telse console.log(2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [n, m] = rna();\r\n\r\n\t\tif (n == 1 || m == 1) console.log(1);\r\n\t\telse console.log(2);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var s = lines[i].split(' ').map(Number);\n var n = s[0], m = s[1];\n if(m == 1){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n});"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n x = +s[0];\r\n y = +s[1];\r\n if (x == 1 && y == 1) print(0);\r\n if (x == 1 || y == 1) print(1);\r\n else print(2);\r\n}"}, {"source_code": "n = readline();\r\nwhile (n--) {\r\n s = readline().split(\" \");\r\n x = +s[0];\r\n y = +s[1];\r\n print(x < y ? x : y);\r\n}"}], "src_uid": "e5a01ebfdca3af987e93b68c96268c16"} {"source_code": "print(function(n) {\n\n\tvar ans = [],\n\t\tsum = 0;\n\twhile (n--)\n\t\tans.push(readline().split(' ').map(Number).reduce(function(a, g) {\n\t\t\tif (sum + a <= 500) {\n\t\t\t\tsum += a;\n\t\t\t\treturn 'A';\n\t\t\t}\n\t\t\tsum -= g;\n\t\t\treturn 'G';\n\t\t}));\n\n\treturn ans.join('');\n\n}(+readline()));", "positive_code": [{"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar a = 0, b = 0, result = '';\n\t\twhile (n--) {\n\t\t\tvar l = readline().split(' ').map(Number),\n\t\t\t\t_a = a + l[0], _b = b + l[1];\n\n\t\t\tif (Math.abs(_b - a) < Math.abs(_a - b)) {\n\t\t\t\tb = _b; result += 'G';\n\t\t\t} else {\n\t\t\t\ta = _a; result += 'A';\n\t\t\t}\n\t\t}\n\n\t\treturn Math.abs(a - b) > 500 ? -1 : result;\n\n\t}(+readline()));\n\n}.call(this));\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar a = 0, b = 0, result = '';\n\t\twhile (n--) {\n\t\t\tvar l = readline().split(' ').map(Number),\n\t\t\t\t_a = a + l[0], _b = b + l[1];\n\n\t\t\tif (Math.abs(_b - a) < Math.abs(_a - b)) {\n\t\t\t\tb = _b; result += 'B';\n\t\t\t} else {\n\t\t\t\ta = _a; result += 'A';\n\t\t\t}\n\t\t}\n\n\t\treturn Math.abs(a - b) > 500 ? -1 : result;\n\n\t}(+readline()));\n\n}.call(this));\n"}], "src_uid": "24fe280b88575516ec679ff78641440e"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-1);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tif (i != mni) {\r\n\t\t\t\tconsole.log(mni+1, i+1, a[mni], a[mni]+i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (mni != 0) \r\n\t\t\tconsole.log(mni+1, 1, a[mni]+mni, a[mni]);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "\"use strict\";\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor (; t > 0; --t) {\r\n var n = parseInt(readline(), 10);\r\n var arr = readline().split(\" \").map(function (v) {\r\n return parseInt(v, 10);\r\n });\r\n\r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n } // \u627e\u5230\u6700\u5c0f\u503c\r\n\r\n\r\n var minn = Math.min.apply(null, arr); // \u627e\u5230\u6700\u5c0f\u503c\u7684\uff08\u7b2c\u4e00\u4e2a\uff09\u7d22\u5f15\r\n\r\n var mini = arr.indexOf(minn);\r\n print(n - 1); // \u5411\u5de6\r\n\r\n var add = 0;\r\n\r\n for (var i = mini - 1; i >= 0; --i) {\r\n ++add;\r\n print(\"\".concat(mini + 1, \" \").concat(i + 1, \" \").concat(minn, \" \").concat(minn + add));\r\n } // \u5411\u53f3\r\n\r\n\r\n add = 0;\r\n\r\n for (var _i = mini + 1; _i < n; ++_i) {\r\n ++add;\r\n print(\"\".concat(mini + 1, \" \").concat(_i + 1, \" \").concat(minn, \" \").concat(minn + add));\r\n }\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-1);\r\n\t\tfor(let i = 0; i < n; i++) {\r\n\t\t\tif (i == mni) continue;\r\n\t\t\tconsole.log(mni+1, i+1, a[mni], a[mni] + Math.abs(i-mni));\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(mni == 0 ? n-1: n);\r\n\t\tif (mni != 0) console.log(1, mni+1, a[mni], a[0]);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tconsole.log(1, i+1, a[mni], a[mni]+i);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n);\r\n\t\tif (mni != 0) console.log(1, mni+1, a[mni], a[0]);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tconsole.log(1, i+1, a[mni], a[mni]+i);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(mni == 0 ? n-2 : n-1);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tif (i != mni) {\r\n\t\t\t\tconsole.log(mni+1, i+1, a[mni], a[mni]+i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (mni != 0) \r\n\t\t\tconsole.log(mni+1, 1, a[mni]+mni, a[mni]);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-1);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tif (i != mni) {\r\n\t\t\t\tconsole.log(mni+1, i+1, a[mni], a[mni] + i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(mni+1, 1, a[mni] + mni, a[mni]);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet mni = 0;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < a[mni]) {\r\n\t\t\t\tmni = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(n-1);\r\n\t\tfor(let i = 1; i < n; i++) {\r\n\t\t\tif (i != mni) {\r\n\t\t\t\tconsole.log(mni+1, i+1, a[mni], a[mni] + i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tconsole.log(mni+1, 1, a[mni], a[mni] + mni);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "\"use strict\";\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor (; t > 0; --t) {\r\n var n = parseInt(readline(), 10);\r\n var arr = readline().split(\" \").map(function (v) {\r\n return parseInt(v, 10);\r\n });\r\n\r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n } // \u627e\u5230\u6700\u5c0f\u503c\r\n\r\n\r\n var minn = Math.min.apply(null, arr); // \u627e\u5230\u6700\u5c0f\u503c\u7684\uff08\u7b2c\u4e00\u4e2a\uff09\u7d22\u5f15\r\n\r\n var mini = arr.indexOf(minn);\r\n var add = 0;\r\n var flag = true;\r\n print(n - 1);\r\n\r\n for (var i = 0; i < n; ++i) {\r\n if (i === mini && flag) {\r\n flag = false;\r\n continue;\r\n } else {\r\n ++add;\r\n print(\"\".concat(mini + 1, \" \").concat(i + 1, \" \").concat(minn, \" \").concat(minn + add));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\nvar ret = [];\r\n\r\nfor (; t > 0; --t) {\r\n var n = parseInt(readline(), 10);\r\n var arr = readline().split(\" \").map(function (v) {\r\n return parseInt(v, 10);\r\n });\r\n\r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n } // \u627e\u5230\u6700\u5c0f\u503c\r\n\r\n\r\n var minn = Math.min.apply(null, arr); // \u627e\u5230\u6700\u5c0f\u503c\u7d22\u5f15\r\n\r\n var mini = arr.indexOf(minn); // \u4ece\u6700\u5c0f\u503c\u5f80\u4e24\u8fb9\u6269\u6563\r\n\r\n var ans = 0;\r\n var ope = []; // \u5de6\u8fb9\r\n\r\n for (var i = mini; i > 0; --i) {\r\n if (gcd(arr[i], arr[i - 1]) === 1) {\r\n continue;\r\n } else {\r\n while (gcd(arr[i], arr[i - 1]) !== 1) {\r\n ++arr[i - 1];\r\n }\r\n\r\n ++ans;\r\n ope.push(\"\".concat(i, \" \").concat(mini + 1, \" \").concat(arr[i - 1], \" \").concat(minn));\r\n }\r\n } // \u53f3\u8fb9\r\n\r\n\r\n for (var _i = mini; _i < n - 1; ++_i) {\r\n if (gcd(arr[_i], arr[_i + 1]) === 1) {\r\n continue;\r\n } else {\r\n while (gcd(arr[_i], arr[_i + 1]) !== 1) {\r\n ++arr[_i + 1];\r\n }\r\n\r\n ++ans;\r\n ope.push(\"\".concat(mini + 1, \" \").concat(_i + 2, \" \").concat(minn, \" \").concat(arr[_i + 1]));\r\n }\r\n }\r\n\r\n ret.push.apply(ret, [ans].concat(ope));\r\n}\r\n\r\nwhile (ret.length > 0) {\r\n print(ret.shift());\r\n}\r\n"}, {"source_code": "\"use strict\";\n\n// import readlineSync from \"readline-sync\";\n// const readline = readlineSync.question.bind(null, \"input: \");\n// const print = console.log;\n// \u4e0a\u4f20\u65f6\u5220\u53bb\u4e0a\u9762\u4e09\u884c\n// \u6700\u5927\u516c\u7ea6\u6570\u7684\u51fd\u6570\nfunction gcd(a, b) {\n if (b === 0) {\n return a;\n }\n\n return gcd(b, a % b);\n}\n\nvar t = parseInt(readline(), 10);\nvar ret = [];\n\nfor (; t > 0; --t) {\n var n = parseInt(readline(), 10);\n var arr = readline()\n .split(\" \")\n .map(function (v) {\n return parseInt(v, 10);\n });\n\n if (n === 1) {\n print(0);\n continue;\n }\n\n var ans = 0;\n var ope = [];\n\n for (var i = 0; i < n - 1; ++i) {\n if (gcd(arr[i], arr[i + 1]) === 1) {\n continue;\n } else {\n arr[i + 1] = arr[i] + 1;\n\n while (gcd(arr[i], arr[i + 1]) !== 1) {\n ++arr[i + 1];\n }\n\n ++ans;\n ope.push(\n \"\"\n .concat(i + 1, \" \")\n .concat(i + 2, \" \")\n .concat(arr[i], \" \")\n .concat(arr[i + 1])\n );\n }\n }\n\n ret.push.apply(ret, [ans].concat(ope));\n}\n\nwhile (ret.length > 0) {\n print(ret.shift());\n}\n"}], "src_uid": "8b2b7208630af1d086420513a437a914"} {"source_code": "print(function( n, m, x, y, z, p ){\n\tx = x%4;\n\ty = y%2;\n\tz = 4 - z%4;\n\tvar i, ans = [];\n\twhile(p--){\n\t\tans.push(function( ik, jk ){\n\t\t\tvar i, a = [ik, jk, n, m];\n\t\t\tfor( i=0; i= 0 && as[downI] == n ) {\n downI--\n n--\n } else if ( upI < as.length && as[upI] == n ) {\n upI++\n n--\n } else break;\n}\n\nif ( !n ) print('YES')\nelse print('NO')\n", "positive_code": [{"source_code": "const readLines = () => {\n\ttry {\n\t\treturn require(\"fs\").readFileSync(\"input.txt\", \"utf8\").split(/[\\r\\n]+/);\n\t} catch(e) {}\n\tconst lines = [];\n\tfor(var line; undefined !== (line = readline()); )\n\t\tlines.push(line);\n\treturn lines;\n};\nconst output = (text) => {\n\ttry {\n\t\tconsole.log(text);\n\t} catch(e) {}\n\ttry {\n\t\ttext.toString().split(/[\\r\\n]+/).map(s => print(s));\n\t} catch(e) {}\n};\n\nvar a = readLines();\nvar count = +a.shift();\nvar radiusArray = a.shift().split(\" \").map(Number);\n\nvar max = radiusArray[0], iMax = 0;\nfor(var i = 0; i < count; i++)\n\tif ( max < radiusArray[i] ) {\n\t\tmax = radiusArray[i];\n\t\tiMax = i;\n\t}\n\nfunction check(ra, iMax) {\n\tvar iLeft = iMax - 1;\n\tvar iRight = iMax + 1;\n\tvar max = ra[iMax];\n\twhile(1) {\n\t\tvar l = iLeft >= 0 ? ra[iLeft] : -1;\n\t\tvar r = iRight < ra.length ? ra[iRight] : -1;\n\t\tif ( l === -1 && r === -1 ) return true;\n\t\tlrMax = Math.max(l, r);\n\t\tif ( max <= lrMax ) return false;\n\t\tmax = lrMax;\n\n\t\tif ( l > r ) {\n\t\t\tiLeft--;\n\t\t} else {\n\t\t\tiRight++;\n\t\t}\n\t}\n}\n\n\noutput( check(radiusArray, iMax) ? \"YES\" : \"NO\" );"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\n var n = +rd();\n var A = rdAr();\n var max = Math.max(...A);\n A = [-Infinity].concat(A.concat([-Infinity]));\n var ind = A.indexOf(max);\n var top = max;\n for (var L = ind - 1, R = ind + 1; top !== -Infinity;) {\n var LVAL = A[L];\n var RVAL = A[R];\n var pos;\n if (LVAL > RVAL) {\n pos = L;\n --L;\n } else {\n pos = R;\n ++R;\n }\n var plate = A[pos];\n if (plate > top) {\n wr('NO'); return;\n }\n top = plate;\n }\n wr('YES');\n};\n\nif (INPUT) {\nINPUT = INPUT.split('\\n').reverse();\nreadline = () => INPUT.pop();\nwrite = (s) => {OUTPUT += s};\nprint = (s) => {OUTPUT += s + '\\n'};\n}\nconst rd = readline;\nconst wr = write;\nconst pr = print;\nconst rdAr = () => rd().split(' ').map(v => +v);\nconst prAr = (a) => pr(a.join(' '));\nconst cmpLt = (a, b) => a - b;\nconst cmpGt = (a, b) => b - a;\nArray.prototype.sortLt = function() { return this.sort(cmpLt); };\nArray.prototype.sortGt = function() { return this.sort(cmpGt); };\nconst crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };\nconst getPrimes = function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j=0;i--)\n{\n if (b[i]+1==l)\n --l;\n else if (b[i]-1==r)\n ++r\n else\n break\n}\nif (r-l==n-1)\n print(\"yeS\")\nelse\n print(\"NO\")"}], "negative_code": [{"source_code": "var n = +readline()\n , as = readline().split(' ')\n , topI = as.indexOf(n--)\n\nfor ( var i in as ) as[i] = +as[i]\n\nwhile ( n ) {\n var nextI = as.indexOf(n--)\n if ( Math.abs(nextI - topI) != 1) break;\n as.splice(nextI, 1)\n if ( nextI < topI ) topI--\n}\n\nif ( !n ) print('YES')\nelse print('NO')\n"}], "src_uid": "12abfbe7118868a0b1237489b5c92760"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar count = 0;\n\t\tvar list = nextIntArray();\n\t\tvar sum = 0;\n\t\twhile(count < K){\n\t\t\tfor(var j = 0; j < Math.floor(N / 2); j++){\n\t\t\t\tlist.pop();\n\t\t\t}\n\t\t\tsum += list.pop();\n\t\t\tcount++;\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [len, numberOfArr] = readLine().split(\" \").map(Number);\n const arr = readLine().split(\" \").map(Number);\n let mid = Math.floor(len / 2);\n if (len % 2 === 0) {\n mid = mid - 1;\n }\n // console.log(`mid`, mid);\n let count = 0;\n let i = 0;\n if (mid === 0) i = len * numberOfArr - len;\n else i = len * numberOfArr - 1 - Math.floor(len / 2);\n let t = numberOfArr;\n while (t--) {\n // console.log(arr[i]);\n count += arr[i];\n if (mid === 0) i -= len;\n else i -= Math.floor(len / 2) + 1;\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n, k] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = Math.ceil(n / 2)\n// \n// io.debug(m)\n// // io.debug(a)\n// \n// let s = 0\n// \n// let i = (m - 1) * k\n// \n// for (let j = 0; j < k; ++j) {\n// s += a[i]\n// \n// i += n - m + 1\n// }\n// \n// io.puts(s)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}, {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const lines = input.trim().split('\\n')\n let curLine = 0\n const T = parseInt(lines[curLine++])\n for (let t = 0; t < T; t++) {\n const [n, k] = lines[curLine++].split(' ').map((x) => parseInt(x))\n const arr = lines[curLine++].split(' ').map((x) => parseInt(x)).sort((a, b) => a - b)\n\n const cLow = Math.floor((n - 1) / 2)\n let ans = 0n\n let curIdx = k * cLow\n for (let i = 0; i < k; i++) {\n ans += BigInt(arr[curIdx])\n curIdx += n - cLow\n }\n console.log(ans.toString())\n } \n})\n"}, {"source_code": "var sizeOfData = readline();\nfor (var dataI = 0; dataI < sizeOfData; dataI++) {\n var first = readline().split(\" \");\n var n = first[0];\n var k = first[1];\n var arr = readline().split(\" \");\n var sum = 0;\n var start = arr.length;\n for (var i = 0; i < k; i++) {\n start = start - (Math.floor(n/2) + 1)\n sum += parseInt(arr[start]);\n }\n print(sum);\n}"}, {"source_code": "var sizeOfData = readline();\nfor (var dataI = 0; dataI < sizeOfData; dataI++) {\n var first = readline().split(\" \");\n var n = first[0];\n var k = first[1];\n var arr = readline().split(\" \");\n var sum = 0;\n var start = arr.length;\n for (var i = 0; i < k; i++) {\n start = start - (Math.floor(n/2) + 1)\n sum += parseInt(arr[start]);\n }\n print(sum);\n}"}], "negative_code": [], "src_uid": "83d0395cd3618b0fd02c1846dbcd92a2"} {"source_code": "var n = parseInt(readline());\nvar numbers = readline().split(' ');\n\nvar sum = 0;\nvar min = Math.pow(10,9);\nvar count = 0;\nvar current;\n\nfor (var i = 0; i < n; i++) {\n current = parseInt(numbers[i]);\n if (numbers[i] % 2 == 0) sum += current\n else {\n sum += current;\n count++;\n min = Math.min(min, current);\n }\n}\n\nif (count % 2 == 1) sum -= min;\n\nprint(sum);", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar integers = readline().split(' ').map(Number);\nvar ans = integers.reduce(function(l, r){\n return l + r;\n});\nvar flag = ans;\nfor(var i = 0; i < integers.length; ++i){\n if(integers[i] & 1){\n flag = Math.min(flag, integers[i]);\n }\n}\nprint(ans & 1 ? ans - flag : ans);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let arr = d.split(' ').map(Number);\n arr.sort((a, b) => b - a);\n arr = arr.map(BigInt);\n\n let odd = 0;\n let lastOddIdx = 0;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] % 2n === 1n) {\n odd++;\n lastOddIdx = i;\n }\n }\n\n let ans = arr.reduce((a, x) => a + x, 0n);\n\n if (odd % 2) {\n ans -= arr[lastOddIdx];\n }\n\n console.log(ans.toString());\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\n\nlet input = []\nprocess.stdin.on(\"data\", function (chunk) {\n input += chunk\n})\n\nprocess.stdin.on(\"end\", function () {\n const sentence = input.split('\\n')\n const n = sentence[0]\n const integers = sentence[1].split(' ')\n let sum = 0\n let countOdd = 0\n let minOdd = Infinity\n for (let i = 0; i < integers.length; i++) {\n sum += parseInt(integers[i])\n if (parseInt(integers[i]) % 2 === 1) {\n countOdd += 1\n if (parseInt(integers[i]) < minOdd) {\n minOdd = parseInt(integers[i])\n }\n }\n\n }\n if (countOdd % 2 === 1) {\n sum -= minOdd\n }\n console.log(sum);\n})"}, {"source_code": "'use strict';\n\nconst n = parseInt(readline())\nconst integers = readline().split(' ').map(Number); \n\nlet even = integers.filter((x) => x % 2 === 0)\nlet odd = integers.filter((x) => x % 2 !== 0)\nodd.sort((x,y) => y - x);\n\nlet odd_count = odd.length % 2 === 0 ? odd.length : odd.length - 1;\nodd = odd.slice(0, odd_count);\n\nlet result = even.reduce((p, c) => p + c, 0)\nresult += odd.reduce((p, c) => p + c, 0);\n\nprint(result);\n\n\n"}, {"source_code": "var n = Number(readline());\nvar str = readline().split(\" \", n);\nvar num = new Array(n);\nfor (var i = 0; i < n; ++i) {\n num[i] = Number(str[i]);\n}\n\nvar sum = 0;\nvar minOdd = 999999999;\n\nfor (var i = 0; i < n; ++i) {\n sum += num[i];\n if (num[i] % 2 === 1) {\n minOdd = Math.min(minOdd, num[i]);\n }\n}\n\nif (sum % 2 === 0) {\n print(sum);\n} else {\n print(sum - minOdd);\n}"}, {"source_code": "/**\n * Created by ishanarora on 22/11/18.\n */\n\nconst stdin = process.openStdin();\nlet content = ``;\nstdin.addListener('data', d => {\n content += d.toString();\n});\n\nstdin.addListener('end', () => {\n content = content.split(\"\\n\");\ncontent[0] = (parseInt(content[0]));\ncontent[1] = content[1].split(\" \");\ncontent[1] = content[1].map(elem => parseInt(elem));\n\nconsole.log(wetShark(content[0], content[1]))\n\n});\n\nfunction wetShark(count , elems) {\n\n let sum = 0;\n let deduct = Number.MAX_SAFE_INTEGER;\n for (var i = count - 1; i >= 0; i--) {\n sum += elems[i];\n if (elems[i] % 2 != 0) {\n deduct = Math.min(deduct, elems[i]);\n }\n }\n\n if (sum % 2 != 0) {\n sum -= deduct;\n }\n\n return sum;\n}\n\n"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number);\n\nvar minOdd = 999999999;\nvar sum = 0;\nfor(var i = 0; i < n; ++i){\n sum += a[i];\n if(a[i]%2 == 1){\n minOdd = Math.min(minOdd, a[i]);\n }\n}\n\nif(sum%2 == 1){\n sum -= minOdd;\n}\n\nwrite(sum);"}, {"source_code": "function main(n,arr) {\n\n all_sum = 0;\n smallest_odd = Infinity;\n\n for(var i = 0 ; i < n ; i++){\n\n all_sum += arr[i];\n if(arr[i] % 2 === 1)smallest_odd = Math.min(smallest_odd,arr[i]);\n }\n\n if(all_sum % 2 === 1){\n all_sum -= smallest_odd;\n }\n\n print(all_sum);\n\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(n,arr);\n"}, {"source_code": "readline();\nmain.call(0, readNums());\nfunction main(nums) {\n var sum = 0;\n var least = 2000000000;\n for (var i = 0; i < nums.length; i++) {\n var n = nums[i];\n sum += n;\n if ((n & 1) && n < least) {\n least = n;\n }\n }\n if (sum & 1) {\n sum -= least;\n }\n print(sum);\n}\nfunction readNums() {\n return readline().split(' ').map(function(v) {\n return v - 0;\n })\n}\n//function readline() {\n// return '999999999 999999999 999999999 999999999 999999999'\n//}\n//function print(v) {\n// console.log(v)\n//}\n"}, {"source_code": "var n = Number(readline());\nvar array = readline().split(' ').map(Number);\n\nvar sum = 0;\n\nfor (var i = 0; i < n; i++) {\n\tsum += array[i];\n}\n\nvar even_sum = sum;\n\nif (sum % 2 == 1) {\n\tarray.sort(function(a, b){return a - b;});\n\tvar i = 0;\n\twhile (array[i] % 2 < 1) {\n\t\ti++;\n\t}\n\teven_sum = sum - array[i];\n} \n\nprint(even_sum);"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \");\nvar sum = 0;\nvar odd = 0;\nfor (var i = 0; i < n; i++) {\n\tvar t = parseInt(a[i]);\n\tsum += t;\n\todd = (( (odd == 0)|| (t < odd) ) && (t&1)) ? t : odd;\n}\nsum = ( !(sum&1) ) ? sum : sum - odd;\nprint(sum);"}], "negative_code": [{"source_code": "/**\n * Created by ishanarora on 22/11/18.\n */\n\nconst stdin = process.openStdin();\nlet content = ``;\nstdin.addListener('data', d => {\n content += d.toString();\n});\n\nstdin.addListener('end', () => {\n content = content.split(\"\\n\");\ncontent[0] = (parseInt(content[0]));\ncontent[1] = content[1].split(\" \");\ncontent[1] = content[1].map(elem => parseInt(elem));\n\nconsole.log(wetShark(content[0], content[1]))\n\n});\n\nfunction wetShark(count , elems) {\n\n elems.sort();\n\n var prev = -1;\n var sum = 0;\n for (var i = count - 1; i >= 0; i--) {\n if (elems[i] % 2 === 0) {\n sum += elems[i];\n } else {\n if (prev === -1) {\n prev = elems[i];\n } else {\n sum += prev + elems[i];\n prev = -1;\n }\n }\n }\n return sum;\n}\n\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\n\nlet input = []\nprocess.stdin.on(\"data\", function (chunk) {\n input += chunk\n})\n\nprocess.stdin.on(\"end\", function () {\n const sentence = input.split('\\n')\n const n = sentence[0]\n const integers = sentence[1].split(' ')\n let sum = 0\n let countOdd = 0\n let minOdd = Infinity\n for (let i = 0; i < integers.length; i++) {\n sum += parseInt(integers[i])\n if(parseInt(integers[i]) % 2 === 1) {\n countOdd += 1\n }\n if (parseInt(integers[i]) < minOdd) {\n minOdd = parseInt(integers[i])\n }\n }\n if (countOdd % 2 === 1) {\n sum -= minOdd\n }\n console.log(sum);\n})"}, {"source_code": "/**\n * Created by ishanarora on 22/11/18.\n */\n\nconst stdin = process.openStdin();\nlet content = ``;\nstdin.addListener('data', d => {\n content += d.toString();\n});\n\nstdin.addListener('end', () => {\n content = content.split(\"\\n\");\ncontent[0] = (parseInt(content[0]));\ncontent[1] = content[1].split(\" \");\ncontent[1] = content[1].map(elem => parseInt(elem));\n\nconsole.log(wetShark(content[0], content[1]))\n\n});\n\nfunction wetShark(count , elems) {\n\n elems.sort();\n\n var prev = -1;\n var sum = 0;\n for (var i = count - 1; i >= 0; i--) {\n if(elems[i] < 0){\n continue;\n }\n if (elems[i] % 2 === 0) {\n sum += elems[i];\n } else {\n if (prev === -1) {\n prev = elems[i];\n } else {\n sum += prev + elems[i];\n prev = -1;\n }\n }\n }\n return sum;\n}\n\n"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number);\n\nvar minOdd;\nvar sum = 0;\nfor(var i = 0; i < n; ++i){\n sum += a[i];\n if(minOdd == undefined && a[i]%2 == 1){\n minOdd = a[i];\n }\n}\n\nif(sum%2 == 1){\n sum -= minOdd;\n}\n\nwrite(sum);"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number).sort();\n\nvar minOdd;\nvar sum = 0;\nfor(var i = 0; i < n; ++i){\n sum += a[i];\n if(minOdd == undefined && a[i]%2 == 1){\n minOdd = a[i];\n }\n}\n\nif(sum%2 == 1){\n sum -= minOdd;\n}\n\nwrite(sum);"}, {"source_code": "var n = +readline(), a = readline().split(\" \").map(Number).sort(function(a, b){ return a < b; });\n\nvar minOdd;\nvar sum = 0;\nfor(var i = 0; i < n; ++i){\n sum += a[i];\n if(minOdd == undefined && a[i]%2 == 1){\n minOdd = a[i];\n }\n}\n\nif(sum%2 == 1){\n sum -= minOdd;\n}\n\nwrite(sum);"}, {"source_code": "function main(n,arr) {\n\n var total = 0;\n var ans = 0;\n\n arr.sort();\n for(var i = 0 ; i < n ; i++){\n total += arr[i];\n\n total % 2 === 0 ? ans = total : ans = ans;\n }\n\n print(ans);\n\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(n,arr);\n"}, {"source_code": "function main(n,arr) {\n\n var total = 0;\n var ans = 0;\n\n for(var i = 0 ; i < n ; i++){\n total += arr[i];\n\n total % 2 === 0 ? ans = total : ans = ans;\n }\n\n print(ans);\n\n}\n\nvar n = parseInt(readline());\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(n,arr);\n"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \");\nvar sum = 0;\nvar odd = 0;\nfor (var i = 0; i < n; i++) {\n\tvar t = parseInt(a[i]);\n\tsum += t;\n\todd = ( (odd == 0 && t&1 )|| (t < odd) ) ? t : odd;\n}\nsum = ( !(sum&1) ) ? sum : sum - odd;\nprint(sum);"}, {"source_code": "var n = parseInt(readline());\nvar integers = readline().split(' ').map(Number);\nvar ans = integers.reduce(function(l, r){\n return l + r;\n});\nvar flag = ans;\nfor(var i = 0; i < integers.length; ++i){\n if(integers[i] & 1){\n flag = Math.min(flag, integers[i]);\n break;\n }\n}\nprint(ans & 1 ? ans - flag : ans);"}, {"source_code": "var n = parseInt(readline());\nvar integers = readline().split(' ').map(Number);\nvar ans = integers.reduce(function(l, r){\n return l + r;\n});\nintegers = integers.sort();\nfor(var i = 0; i < integers.length; ++i){\n if(integers[i] & 1){\n ans -= integers[i];\n break;\n }\n}\nprint(ans & 1 ? 0 : ans);"}, {"source_code": "var n = parseInt(readline());\nvar numbers = readline().split(' ');\n\nvar evens = [];\nvar odds = [];\n\nvar sum = 0;\n\nfor (var i = 0; i < n; i++) {\n if (numbers[i] % 2 == 0) evens.push(parseInt(numbers[i]))\n else odds.push((parseInt(numbers[i])));\n}\n\nfor (var i = 0; i < evens.length; i++) {\n sum += evens[i]; \n}\n \nvar isOddsEven = odds.length % 2 == 0 ? 0 : 1;\n\nfor (var i = 0; i < odds.length - isOddsEven; i++) {\n sum += odds[i];\n}\n\nprint(sum);"}, {"source_code": "var n = parseInt(readline());\nvar numbers = readline().split(' ');\n\nvar evens = [];\nvar odds = [];\n\nvar sum = 0;\n\nfor (var i = 0; i < numbers.length; i++) {\n if (numbers[i] % 2 == 0) evens.push(parseInt(numbers[i]))\n else odds.push((parseInt(numbers[i])));\n}\n\nfor (var i = 0; i < evens.length; i++) {\n sum += evens[i]; \n}\n \nvar isOddsEven = odds.length % 2 == 0 ? 0 : 1;\n\nfor (var i = 0; i < odds.length - isOddsEven; i++) {\n sum += odds[i];\n}\n\nprint(sum);"}], "src_uid": "adb66b7b22d70bb37cb625d531d8865f"} {"source_code": "let response = [];\r\nlet solve = function(blocks) {\r\n let third = Math.floor(blocks / 3);\r\n\r\n if (blocks % 3 === 0) {\r\n return [third, third + 1, third - 1];\r\n } else if (blocks % 3 === 1) {\r\n return [third, third + 2, third - 1];\r\n } else {\r\n return [third + 1, third + 2, third - 1]\r\n }\r\n}\r\n\r\nvar readline = require('readline');\r\nvar rl = readline.createInterface(process.stdin, process.stdout);\r\n\r\nlet tests = -2;\r\nlet test = 0;\r\nrl.on('line', function(line) {\r\n if (tests < 0) {\r\n tests = parseInt(line);\r\n } else {\r\n response.push(solve(parseInt(line)));\r\n\r\n ++test;\r\n if (test === tests) {\r\n rl.close();\r\n }\r\n }\r\n\r\n // console.log(tests);\r\n}).on('close',function(){\r\n response.forEach((list) => {\r\n list.forEach((item) => {\r\n process.stdout.write(item + \" \");\r\n })\r\n process.stdout.write(\"\\n\");\r\n });\r\n\r\n process.exit(0);\r\n});\r\n\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 == 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 1} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n let mul = 2 * comp;\r\n if (comp - (n - mul) > 1) print(`${comp - 1} ${comp + 1} ${n - mul}`);\r\n else print(`${comp} ${comp + 1} ${n - mul - 1}`);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 == 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 1} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n let mul = 2 * comp;\r\n if (comp - (n - mul) > 1) print(`${comp - 1} ${comp + 1} ${n - mul}`);\r\n else print(`${comp} ${comp + 1} ${n - mul - 1}`);\r\n }\r\n}\r\n"}, {"source_code": "/// using js code \r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n while (t-- > 0) {\r\n var a = parseInt(readline());\r\n \r\n var x = parseInt((a+5)/3);\r\n var y = parseInt(x-1);\r\n var z = parseInt(a-x-y);\r\n if(z==0){\r\n y--;\r\n z++;\r\n }\r\n console.log(`${y} ${x} ${z}`);\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let a = Math.floor(n/3);\r\n let b = Math.floor((n - a)/2);\r\n let c = n - a -b;\r\n if(b===c){\r\n b++;\r\n c--;\r\n }\r\n else{\r\n if(b {\r\n\t\treturn string.trim();\r\n\t});;\r\n\r\n\t/**\r\n\t * readNumber() - int\r\n\t * readArray() - generic space separated array\r\n\t * readBoolean() - bool\r\n\t * readChar() - char\r\n\t * readLine() - string\r\n\t * readNumberArray() - numeric array\r\n\t */\r\n\t\r\n\tconst solve = () => {\r\n\t let n = inputReader.readNumber();\r\n\t let res = [3, 2, 1];\r\n\t n -= 6;\r\n\t\r\n\t let add = Math.floor(n / 3);\r\n\t res[0] += add + (n % 3 >= 1);\r\n\t res[1] += add + (n % 3 >= 2);\r\n\t res[2] += add;\r\n\t\r\n\t process.stdout.write(res[1] + ' ' + res[0] + ' ' + res[2] + '\\n');\r\n\t};\r\n\t\r\n\tlet tc = inputReader.readNumber();\r\n\t\r\n\tfor(let t = 0; t < tc; ++t)\r\n\t solve();\r\n}\r\n\r\nvar _inputData = '';\r\nfunction cacheInput(data) {\r\n\t_inputData += data;\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', cacheInput).on('end', _main);\r\n\r\nfunction _inputReader () {\r\n\tfunction readNumber(){\r\n\t\treturn Number(_inputLines[_lineNumber++]);\r\n\t}\r\n\t\t\r\n\treturn {\r\n\t\treadNumber,\r\n\t}\r\n}"}, {"source_code": "/** Common Template Starts */\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', (inputStdin) => inputString += inputStdin);\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n/** Commnon Template Ends */\r\n\r\nconst solve = () => {\r\n let n = +(readLine());\r\n let res = [3, 2, 1];\r\n n -= 6;\r\n\r\n let add = Math.floor(n / 3);\r\n \r\n res[0] += add + (n % 3 >= 1);\r\n res[1] += add + (n % 3 >= 2);\r\n res[2] += add;\r\n\r\n process.stdout.write(res[1] + ' ' + res[0] + ' ' + res[2] + '\\n');\r\n};\r\n\r\nconst main = () => {\r\n const tc = +(readLine());\r\n\r\n for(let t = 0; t < tc; ++t)\r\n solve();\r\n};"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let d = Math.floor(n/3);\r\n let r = n%3;\r\n\r\n if (r === 0) {\r\n output([d, (d+1), (d-1)].join(' '));\r\n } else if (r === 1) {\r\n output([d, (d+2), (d-1)].join(' '));\r\n } else if (r === 2) {\r\n output([(d+1), (d+2), (d-1)].join(' '));\r\n }\r\n }\r\n}"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0 ; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet s = Math.floor(n/3);\n\t\tlet x = n - s * 3;\n\t\tans.push([s + Math.floor(x/2), s + 1 + Math.ceil(x/2), s-1]);\n\t\t\n\t}\n\tconsole.log(ans.map(e => e.join(' ')).join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let stdinput = '';\r\nprocess.stdin.on('data', c => stdinput += c);\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = stdinput.split(EOL) /*your input text, split by lines*/\r\n sol(lines);\r\n});\r\n\r\nlet getAnswer = (m) => {\r\n let ost = m%3;\r\n let v = (m - ost) / 3;\r\n if (ost === 0) {\r\n return [v, v+1, v-1];\r\n } else if (ost === 1) {\r\n return [v, v+2, v-1];\r\n } else {\r\n return [v+1, v+2, v-1];\r\n }\r\n}\r\n\r\n\r\nlet sol = (input) => {\r\n let n = parseInt(input[0], 10);\r\n let mList = [];\r\n for (let i=1; i<=n; i++) {\r\n mList.push(parseInt(input[i], 10));\r\n }\r\n\r\n mList.forEach(m => console.log(getAnswer(m).join(' ')));\r\n\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n) {\r\n const a = Math.ceil(n / 3) + 1,\r\n b = Math.floor((n - a) / 2) + 1,\r\n c = n - a - b;\r\n return `${b} ${a} ${c}`;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n res.push(solve(n));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar C = Math.floor(N / 3);\r\n\t\tif(N % 3 == 0){\r\n\t\t\tmyout(C + \" \" + (C + 1) + \" \" + (C - 1));\r\n\t\t}else if(N % 3 == 1){\r\n\t\t\tmyout(C + \" \" + (C + 2) + \" \" + (C - 1));\r\n\t\t}else{\r\n\t\t\tmyout((C + 1) + \" \" + (C + 2) + \" \" + (C - 1));\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n).join(' ')\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n const r = n % 3\n const k = Math.floor(n / 3)\n if (!r) {\n return [k, k + 1, k - 1]\n } else if (r === 1) {\n return [k, k + 2, k - 1]\n } else if (r === 2) {\n return [k + 1, k + 2, k - 1]\n }\n}\n"}, {"source_code": "\nfunction solution(num) {\n fi = 3, se = 2, th = 1;\n many = parseInt((num - 6) / 3);\n rest = parseInt((num - 6) % 3);\n fi += many;\n se += many;\n th += many;\n while(rest > 0) {\n if(rest > 0) {\n fi++;\n rest--;\n }\n if(rest > 0) {\n se++;\n rest--;\n }\n if(rest > 0) {\n th++;\n rest--;\n }\n }\n print(se + \" \" + fi + \" \" + th);\n}\n\n \nn = readline()\nfor( k = 0; k < n ;k++) {\n num = readline();\n solution(num);\n}\n\n"}, {"source_code": " var tests = parseInt(readline());\r\n var n;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n var h = Math.floor(n / 3);\r\n var ans = new Array(3).fill(h);\r\n var mod = n % 3;\r\n if (mod == 0) {\r\n ans[1]++;\r\n ans[2]--;\r\n } else if (mod == 1) {\r\n ans[1]+=2;\r\n ans[0]+=1;\r\n ans[2]-=2;\r\n } else if (mod == 2) {\r\n ans[1]+=2;\r\n ans[0]++;\r\n ans[2]--;\r\n }\r\n if (ans[2] == 0) {\r\n ans[0]--;\r\n ans[2]++;\r\n }\r\n print(ans.join(' '));\r\n }"}, {"source_code": "var n = parseInt(readline());\r\n\r\nwhile (n--) {\r\n\tvar m = parseInt(readline());\r\n\tvar div = parseInt(m / 3);\r\n\tvar mod = parseInt(m % 3);\r\n\tvar left = div + (mod - 1 >= 1);\r\n\tvar mid = div + 1 + (mod >= 1);\r\n\tvar right = div - 1;\r\n\twrite(left + \" \" + mid + \" \" + right);\r\n\tprint();\r\n}\r\n"}, {"source_code": " /////////////////////////// JavaScript Lover /////////////////////////////////////\r\n //////////////////// ShixyCat //////////////////////////////\r\n \r\nvar t = readline();\r\n\r\nfor(var i=0 ; i {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3, n/3+1, n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);\r\n }\r\n } else {\r\n console.log((n-2)/3+1, (n-2)/3+2, (n-2)/3-1);\r\n }\r\n }\r\n\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3, n/3+1, n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);\r\n }\r\n } else {\r\n if ((n-2)/3 > 2) {\r\n console.log((n-2)/3-1, (n-2)/3+2, (n-2)/3-2);\r\n } else {\r\n console.log((n-2)/3, (n-2)/3+1, (n-2)/3-2);\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3, n/3+1, n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);\r\n }\r\n } else {\r\n if ((n+1)/3 > 2) {\r\n console.log((n+1)/3-1, (n+1)/3+2, (n+1)/3-2);\r\n } else {\r\n console.log((n+1)/3, (n+1)/3+1, (n+1)/3-2);\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < t; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3 + ' ' + n/3+1 + ' ' + n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-1);\r\n }\r\n } else {\r\n if ((n+1)/3 > 2) {\r\n console.log((n+1)/3-1 + ' ' + (n+1)/3+2 + ' ' + (n+1)/3-2);\r\n } else {\r\n console.log((n+1)/3 + ' ' + (n+1)/3+1 + ' ' + (n+1)/3-2);\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < n; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3 + ' ' + n/3+1 + ' ' + n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-1);\r\n }\r\n } else {\r\n if ((n+1)/3 > 2) {\r\n console.log((n+1)/3-1 + ' ' + (n+1)/3+2 + ' ' + (n+1)/3-2);\r\n } else {\r\n console.log((n+1)/3 + ' ' + (n+1)/3+1 + ' ' + (n+1)/3-2);\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n\r\n for (let i = 0; i < n; i++) {\r\n var n = parseInt(readline());\r\n\r\n if (n % 3 === 0) {\r\n console.log(n/3, n/3+1, n/3-1);\r\n } else if (n % 3 === 1) {\r\n if ((n-1)/3 > 2) {\r\n console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);\r\n } else {\r\n console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);\r\n }\r\n } else {\r\n if ((n+1)/3 > 2) {\r\n console.log((n+1)/3-1, (n+1)/3+2, (n+1)/3-2);\r\n } else {\r\n console.log((n+1)/3, (n+1)/3+1, (n+1)/3-2);\r\n }\r\n }\r\n }\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 === 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 1} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n if (comp - (n - 2 * comp) > 1) print(`${comp - 1} ${comp + 1} ${n - (2 * comp)}`);\r\n else print(`${comp} ${comp + 1} ${n - (2 * comp) - 1}`);\r\n }\r\n}\r\n\r\nBuild(8);"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 === 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 1} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n print(`${comp - 1} ${comp + 1} ${n - (2 * comp)}`);\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 == 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 1} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n print(`${comp} ${comp + 1} ${comp - 2}`);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n//\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n//\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return standardInputString[currentLine++];\r\n}\r\nfunction print(data) {\r\n console.log(data);\r\n}\r\n\r\n//line to array of integers\r\n//readline().split(' ').map(Number)\r\n// let iter=parseInt(readline())\r\n//multiple integer construction->const [a,b,c]=integer array\r\n\r\nfunction main() {\r\n let iter = parseInt(readline());\r\n for (let i = 0; i < iter; i++) {\r\n let input = parseInt(readline());\r\n Build(input);\r\n }\r\n}\r\n\r\nfunction Build(n) {\r\n if (n % 3 === 0) {\r\n let comp = n / 3;\r\n print(`${comp} ${comp + 2} ${comp - 1}`);\r\n } else {\r\n let comp = Math.ceil(n / 3);\r\n print(`${comp} ${comp + 2} ${comp - 2}`);\r\n }\r\n}\r\n"}, {"source_code": "/// using js code \r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n while (t-- > 0) {\r\n var a = parseInt(readline());\r\n \r\n var x = parseInt((a+5)/3);\r\n var y = parseInt(x-1);\r\n var z = parseInt(a-x-y);\r\n if(z==0){\r\n y--;\r\n z++;\r\n }\r\n console.log(`${x} ${y} ${z}`);\r\n }\r\n}"}, {"source_code": "let response = [];\r\nlet solve = function(blocks) {\r\n let third = Math.floor(blocks / 3);\r\n\r\n if (blocks % 3 === 0) {\r\n return [third, third + 1, third - 1];\r\n } else if (blocks % 3 === 1) {\r\n return [third, third + 2, third - 1];\r\n } else {\r\n return [third + 1, third + 2, third - 1]\r\n }\r\n}\r\n\r\nvar readline = require('readline');\r\nvar rl = readline.createInterface(process.stdin, process.stdout);\r\n\r\nlet tests = -2;\r\nlet test = 0;\r\nrl.on('line', function(line) {\r\n if (tests < 0) {\r\n tests = parseInt(line);\r\n } else {\r\n response.push(solve(parseInt(line)));\r\n\r\n ++test;\r\n if (test === tests) {\r\n rl.close();\r\n }\r\n }\r\n\r\n // console.log(tests);\r\n}).on('close',function(){\r\n response.forEach((list) => {\r\n list.forEach((item) => {\r\n rl.write(item + \" \");\r\n })\r\n rl.write(\"\\n\");\r\n });\r\n\r\n process.exit(0);\r\n});\r\n\r\n"}, {"source_code": "let response = [];\r\nlet solve = function(blocks) {\r\n let third = Math.floor(blocks / 3);\r\n\r\n if (blocks % 3 === 0) {\r\n return [third, third + 1, third - 1];\r\n } else if (blocks % 3 === 1) {\r\n return [third, third + 2, third - 1];\r\n } else {\r\n return [third + 1, third + 2, third - 1]\r\n }\r\n}\r\n\r\nvar readline = require('readline');\r\nvar rl = readline.createInterface(process.stdin, process.stdout);\r\n\r\nlet tests = -2;\r\nlet test = 0;\r\nrl.on('line', function(line) {\r\n if (tests < 0) {\r\n tests = parseInt(line);\r\n } else {\r\n response.push(solve(parseInt(line)));\r\n\r\n ++test;\r\n if (test === tests) {\r\n rl.close();\r\n }\r\n }\r\n\r\n // console.log(tests);\r\n}).on('close',function(){\r\n response.forEach((list) => {\r\n list.forEach((item) => {\r\n rl.write(item + \" \");\r\n })\r\n rl.write(\"\\n\");\r\n });\r\n});"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let a = n%2===0 ? Math.floor(n/2) : Math.ceil(n/2);\r\n let b = n - a - 1;\r\n console.log(`${b} ${a} ${n-(a+b)}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\nfunction solution(num) {\n fi = 3, se = 2, th = 1;\n many = (num - 6) / 3;\n rest = (num - 6) % 3;\n fi += many;\n se += many;\n th += many;\n while(rest > 0) {\n if(rest > 0) {\n fi++;\n rest--;\n }\n if(rest > 0) {\n se++;\n rest--;\n }\n if(rest > 0) {\n th++;\n rest--;\n }\n }\n print(se + \" \" + fi + \" \" + th);\n}\n\n \nn = readline()\nfor( k = 0; k < n ;k++) {\n num = readline();\n solution(num);\n}\n\n"}, {"source_code": "\nfunction solution(num) {\n fi = 3, se = 2, th = 1;\n many = (num - 6) / 3;\n rest = (num - 6) % 3;\n fi += many;\n se += many;\n th += many;\n while(rest > 0) {\n if(rest > 0) {\n fi++;\n rest--;\n }\n if(rest > 0) {\n se++;\n rest--;\n }\n if(rest > 0) {\n th++;\n rest--;\n }\n }\n console.log(se + \" \" + fi + \" \" + th);\n}\n\n \nn = readline()\nfor( k = 0; k < n ;k++) {\n num = readline();\n print(num);\n}\n\n"}], "src_uid": "45cf60f551bd5cbb1f3df6ac3004b53c"} {"source_code": "/**\n * CodeForces/312 C. Replace To Make Regular Bracket Sequence\n * \n * @author Brooks Mershon\n *\n */\n\n// return Impossible or the least amount of exchanges to fix bracket sequence\nfunction replace(x) {\n var N = x.length,\n count = 0,\n invalid = \"Impossible\";\n\n var open = ['<', '{', '[', '('],\n close = ['>', '}', ']', ')'];\n\n // scan to check whether the sequence is balanced\n var d = 0;\n for(var i = 0; i < N; i++) {\n d += (open.indexOf(x.charAt(i)) > -1) ? 1 : -1;\n if (d < 0) return invalid;\n }\n\n if (d !== 0) return invalid;\n\n var q = [];\n // greedy search for matching parenthesis\n var k = -1;\n while(k < x.length - 1) {\n while(open.indexOf(x.charAt(++k)) > -1) { // iterate to next closing bracket\n q.push(x.charAt(k));\n }\n var opener = q.pop();\n if (open.indexOf(opener) !== close.indexOf(x.charAt(k))) count++;\n }\n\n return count;\n}\n\n// Codeforces I/O\nprint(replace(readline()));\n\n//module.exports = replace;\n", "positive_code": [{"source_code": "// 'use strict';\n\n// var s = '[][][{([)})]';\nvar s = readline();\n\nvar impossible = false;\n\nfunction get_opp(par) {\n if (par == '[') return ']';\n if (par == '<') return '>';\n if (par == '{') return '}';\n if (par == '(') return ')';\n if (par == ']') return '[';\n if (par == ')') return '(';\n if (par == '>') return '<';\n if (par == '}') return '{';\n};\n\nfunction is_op(par) {\n return par == '[' || par == '<' || par == '{' || par == '(';\n};\n\nfunction is_cl(par) {\n return par == ']' || par == '>' || par == '}' || par == ')';\n};\n\nvar cl = [];\nvar op = [];\n\n// function find_last_op() {\n// var max = -1;\n// for (var i in queues) {\n// if (is_op(i)) {\n// if (queues[i][queues[i].length - 1] > max) {\n// max = queues[i][queues[i].length - 1];\n// }\n// }\n// }\n// return max;\n// };\n\n// function find_last_cl() {\n// var max = s.length;\n// for (var i in queues) {\n// if (is_cl(i)) {\n// if (queues[i][queues[i].length - 1] < max) {\n// max = queues[i][queues[i].length - 1];\n// }\n// }\n// }\n// return max;\n// };\n\nfunction check_if_clear() {\n return !(op.length > 0 || cl.length > 0);\n};\n\nvar cor_l = 0;\n\nfor (var i = 0; i < s.length && !impossible; i++) {\n if (is_cl(s[i])) {\n var last_op = op.pop();\n\n if (last_op === false) {\n impossible = false;\n break;\n }\n\n if (s[last_op] != get_opp(s[i])) {\n cor_l++;\n }\n } else {\n op.push(i)\n }\n}\nvar cor_r = 0;\nimpossible = !check_if_clear() || impossible;\n\nfor (var i = s.length - 1; i >= 0 && !impossible; i--) {\n if (is_op(s[i])) {\n var last_cl = cl.pop();\n\n if (last_cl === false) {\n impossible = true;\n break;\n }\n if (s[last_cl] != get_opp(s[i])) {\n cor_r++;\n }\n } else {\n cl.push(i);\n }\n}\nimpossible = !check_if_clear() || impossible;\n\n\n// console.log(impossible ? 'Impossible' : Math.min(cor_r, cor_l));\nprint(impossible ? 'Impossible' : Math.min(cor_r, cor_l));\n\n// console.log(cor_l);\n// console.log(cor_r);\n"}, {"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n switch (input[i]) {\n case '[': { stack.push(library.BOX); break; }\n case '(': { stack.push(library.ROUND); break; }\n case '{': { stack.push(library.CURLY); break; }\n case '<': { stack.push(library.ANGLE); break; }\n case ']': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.BOX) { counter++ };\n }\n break;\n }\n case ')': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ROUND) { counter++ };\n }\n break;\n }\n case '}': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.CURLY) { counter++ };\n }\n break;\n }\n case '>': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ANGLE) { counter++ };\n }\n break;\n }\n }\n }\n if(stack.length != 0) { return -1; }\n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif (replaces >= 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "!function(e){function __webpack_require__(n){if(r[n])return r[n].exports;var t=r[n]={exports:{},id:n,loaded:!1};return e[n].call(t.exports,t,t.exports,__webpack_require__),t.loaded=!0,t.exports}var r={};return __webpack_require__.m=e,__webpack_require__.c=r,__webpack_require__.p=\"\",__webpack_require__(0)}([function(e,r,n){e.exports=n(1)},function(e,r){\"use strict\";function solve(e){function brType(e){return Math.floor(\"<>{}[]()\".indexOf(e)/2)}function brOpen(e){return 0===\"<>{}[]()\".indexOf(e)%2}function calculate(e){for(var r=[],n=0,t=0;t\", \"{\": \"}\", \"[\": \"]\", \"(\": \")\" };\nvar isOpen = b => pairs.hasOwnProperty(b);\nvar stack = [];\nvar result = s.reduce((substitutions, b, i) => {\n if ( isOpen(b) ) {\n stack.push(b);\n return substitutions;\n } else {\n var previousB = stack.pop();\n if (previousB) {\n if (pairs[previousB] === b) {\n return substitutions;\n } else {\n return substitutions + 1;\n }\n }\n } \n}, 0);\n\nif ( typeof result === \"undefined\" || stack.length ) {\n result = \"Impossible\";\n}\nprint(result);"}, {"source_code": "// O(n) time complexity, O(n) additional space, where n is input string length.\nvar s = [...readline()];\nvar pairs = { \"<\": \">\", \"{\": \"}\", \"[\": \"]\", \"(\": \")\" };\nvar isOpen = b => pairs.hasOwnProperty(b);\nvar stack = [];\nvar answer = 0;\n\nfor (var b of s) {\n if ( isOpen(b) ) {\n stack.push(b);\n } else {\n var previousB = stack.pop();\n if (previousB) {\n if (pairs[previousB] != b) {\n ++answer;\n }\n } else {\n // Stack is empty - to many close braces.\n answer = undefined;\n break;\n }\n }\n}\nif ( typeof answer === \"undefined\" || stack.length ) {\n // If stack is not empty - too many open braces.\n answer = \"Impossible\";\n}\nprint(answer);"}], "negative_code": [{"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n switch (input[i]) {\n case '[': { stack.push(library.BOX); break; }\n case '(': { stack.push(library.ROUND); break; }\n case '{': { stack.push(library.CURLY); break; }\n case '<': { stack.push(library.ANGLE); break; }\n case ']': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.BOX) { counter++ };\n }\n break;\n }\n case ')': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ROUND) { counter++ };\n }\n break;\n }\n case '}': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.CURLY) { counter++ };\n }\n break;\n }\n case '>': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ANGLE) { counter++ };\n }\n break;\n }\n }\n }\n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif (replaces >= 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n switch (input[i]) {\n case '[': { stack.push(library.BOX); break; }\n case '(': { stack.push(library.ROUND); break; }\n case '{': { stack.push(library.CURLY); break; }\n case '<': { stack.push(library.ANGLE); break; }\n case ']': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.BOX) { counter++ };\n }\n break;\n }\n case ')': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ROUND) { counter++ };\n }\n break;\n }\n case '}': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.CURLY) { counter++ };\n }\n break;\n }\n case '>': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ANGLE) { counter++ };\n }\n break;\n }\n }\n }\n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif (replaces > 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n switch (input[i]) {\n case '[': { stack.push(library.BOX); break; }\n case '(': { stack.push(library.ROUND); break; }\n case '{': { stack.push(library.CURLY); break; }\n case '<': { stack.push(library.ANGLE); break; }\n case ']': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.BOX) { counter++ };\n }\n break;\n }\n case ')': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ROUND) { counter++ };\n }\n break;\n }\n case '}': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.CURLY) { counter++ };\n }\n break;\n }\n case '>': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ANGLE) { counter++ };\n }\n break;\n }\n }\n }\n if (counter !== 0) return -1;\n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif (replaces > 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n switch (input[i]) {\n case '[': { stack.push(library.BOX); break; }\n case '(': { stack.push(library.ROUND); break; }\n case '{': { stack.push(library.CURLY); break; }\n case '<': { stack.push(library.ANGLE); break; }\n case ']': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.BOX) { counter++ };\n }\n break;\n }\n case ')': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ROUND) { counter++ };\n }\n break;\n }\n case '}': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.CURLY) { counter++ };\n }\n break;\n }\n case '>': {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() !== library.ANGLE) { counter++ };\n }\n break;\n }\n }\n }\n if (counter === 0) return -1;\n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif (replaces > 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "var input = readline();\nvar stack = new Array();\n\nvar library = {\n ROUND: { value: '()' },\n BOX: { value: '[]' },\n ANGLE: { value: '<>' },\n CURLY: { value: '{}' }\n};\n\nfunction GetNumberOfReplaces(input) {\n var counter = 0;\n for (var i = 0; i <= input.length; i++) {\n if (input[i] == '[') { stack.push(library.BOX); break; }\n if (input[i] == '(') { stack.push(library.ROUND); break; }\n if (input[i] == '{') { stack.push(library.CURLY); break; }\n if (input[i] == '<') { stack.push(library.ANGLE); break; }\n if (input[i] == ']') {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() === library.BOX) counter++;\n }\n break;\n }\n if (input[i] == ')') {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() === library.ROUND) counter++;\n }\n break;\n }\n if (input[i] == '}') {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() === library.CURLY) counter++;\n }\n break;\n }\n if (input[i] == '>') {\n if (stack.length == 0) { return -1; } else {\n if (stack.pop() === library.ANGLE) counter++;\n }\n break;\n }\n }\n \n if(counter === 0) return -1;\n \n return counter;\n}\n\nvar replaces = GetNumberOfReplaces(input);\nvar result = '';\nif(replaces > 0) {\n result = replaces + '';\n} else {\n result = 'Impossible';\n}\n\nprint(result);"}, {"source_code": "// O(n) time complexity, O(n) additional space, where n is input string length.\nvar s = [...readline()];\nvar pairs = { \"<\": \">\", \"{\": \"}\", \"[\": \"]\", \"(\": \")\" };\nvar isOpen = b => pairs.hasOwnProperty(b);\nvar stack = [];\nvar answer = 0;\n\nfor (var b of s) {\n if ( isOpen(b) ) {\n stack.push(b);\n } else {\n var previousB = stack.pop();\n if (previousB) {\n if (pairs[previousB] != b) {\n ++answer;\n }\n } else {\n // Stack is empty - to many close braces.\n answer = undefined;\n break;\n }\n } \n}\nif ( typeof answer === \"undefined\" || stack.length ) {\n // If stack is not empty - too many open braces.\n result = \"Impossible\";\n}\nprint(answer);"}], "src_uid": "4147fef7a151c52e92c010915b12c06b"} {"source_code": "\nvar bsearch = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n while (l <= r) { \n var m = Math.floor((r+l) / 2); \n if (A[m] == x) { \n return m; \n }\n else if (A[m] < x) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return -1; \n}\n\nvar main = function(n, k) { \n if (k == 1) { \n return n; \n }\n A = readline().split(' ').map(Number); \n A.sort(function(a, b) {\n return a - b;}); \n\n var F = Array.apply(null, \n new Array(n)).map(Number.prototype.valueOf, 0);\n\n var cnt = 0; \n for (var i = n-1; i >= 0; i--) { \n var m = bsearch(A, A[i] * k); \n if (m >= 0 && F[m] == 0) { \n F[i] = 1; \n }\n else { \n cnt += 1; \n }\n }\n return cnt; \n}\n\nprint(main.apply(null, readline().split(' ').map(Number))); \n", "positive_code": [{"source_code": "var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\nvar n = inp[0], k = inp[1];\nvar a = {}, len = new Array(n);\ninp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\ninp.sort(function(a,b){return a - b;});\n\nfor(var i = 0; i < n; i++) {\n a[inp[i]] = i;\n if(inp[i] % k == 0 && a[inp[i] / k] != undefined){\n var t = a[inp[i] / k];\n len[i] = len[t] + 1;\n len[t] = 0;\n } \n else len[i] = 1; \n}\nvar ans = 0;\nfor(var i = 0; i < n; i++)\n ans += Math.floor((len[i] + 1) / 2);\nprint((k == 1)? n : ans);\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\n/*/====================\nvar fs = require('fs');\n\nfs.readFile('input.txt', 'utf8', function(err, arr) {\n main(arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, '')))\n})\n//====================*/\nfunction max(a,b){\n if (a>b)\n return a\n return b\n}\nfunction main(input) {\n a=input[0].split(' ')\n n=+a[0]\n k=+a[1]\n a=input[1].split(' ').map(x => +x)\n E=new Object()\n for (i=0;i1)\n while(a[i]%k==0){\n a[i]/=k\n ++x\n }\n if (E[a[i]]==undefined){\n E[a[i]]=new Array()\n }\n E[a[i]].push(x)\n }\n ans=0\n function solve(arr,key){\n sort(arr)\n dp=new Array(32)\n for (i=0;i<32;i++)\n dp[i]=0\n K=new Object()\n for (i=0;i<32;i++){\n K[i]=0\n }\n for (i=0;i2){\n dp[i]+=max(dp[i-2],dp[i-3])\n }\n if (dp[i]>x)\n x=dp[i]\n }\n ans+=x\n }\n\n for (key in E){\n solve(E[key],key)\n }\n wr(ans)\n}"}, {"source_code": "\nvar bsearch = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n while (l <= r) { \n var m = Math.floor((r+l) / 2); \n if (A[m] == x) { \n return m; \n }\n else if (A[m] < x) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return -1; \n}\n\nvar main = function(n, k) { \n if (k == 1) { \n return n; \n }\n A = readline().split(' ').map(Number); \n A.sort(function(a, b) {\n return a - b;}); \n\n var F = Array.apply(null, {length: n}).map(function(x) {return 0});\n\n var cnt = 0; \n for (var i = n-1; i >= 0; i--) { \n var m = bsearch(A, A[i] * k); \n if (m >= 0 && F[m] == 0) { \n F[i] = 1; \n }\n else { \n cnt += 1; \n }\n }\n return cnt; \n}\n\nprint(main.apply(null, readline().split(' ').map(Number))); \n"}], "negative_code": [{"source_code": "function sort(ar, n, f) {\n var p = Math.ceil(Math.random() * n);\n var i = 0, j = n - 1;\n while(i < j) {\n while(f(ar[i], ar[p]) <= 0) i++;\n while(f(ar[j], ar[p]) > 0) j--;\n if(i < j) {\n var c = ar[i];\n ar[i] = ar[j], ar[j] = c;\n }\n i++; j--;\n }\n}\n\nvar inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\nvar n = inp[0], k = inp[1];\nvar a = {}, len = new Array(n);\ninp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\nsort(inp, n, function(a,b){return a - b;});\n\nfor(var i = 0; i < n; i++) {\n a[inp[i]] = i;\n if(inp[i] % k == 0 && a[inp[i] / k] != undefined){\n var t = a[inp[i] / k];\n len[i] = len[t] + 1;\n len[t] = 0;\n } \n else len[i] = 1; \n}\nvar ans = 0;\nfor(var i = 0; i < n; i++)\n ans += Math.floor((len[i] + 1) / 2);\nprint((k == 1)? n : ans);\n"}, {"source_code": "var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\nvar n = inp[0], k = inp[1];\nvar a = {}, len = new Array(n);\ninp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\ninp.sort(function(a,b){return a - b;});\n\nfor(var i = 0; i < n; i++) {\n a[inp[i]] = i;\n if(inp[i] % k == 0 && a[inp[i] / k] != undefined){\n var t = a[inp[i] / k];\n len[i] = len[t] + 1;\n len[t] = 0;\n } \n else len[i] = 1; \n}\nvar ans = 0;\nfor(var i = 0; i < n; i++)\n ans += Math.floor((len[i] + 1) / 2);\nprint(ans);\n"}, {"source_code": "var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});\nvar n = inp[0], k = inp[1];\nvar a = {}, c = -1, len = new Array(n);\ninp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur);});\ninp.sort(function(a,b){return a - b;});\n\nfor(var i = 0; i < n; i++) {\n a[inp[i]] = ++c;\n //print(inp[i] + ' ' + c);\n if(inp[i] % k == 0 && a[inp[i] / k] != undefined){\n len[c] = len[a[inp[i] / k]] + 1;\n len[a[inp[i] / k]] = 0;\n } \n else len[c] = 1; \n}\nvar ans = 0;\nfor(var i = 0; i < n; i++)\n ans += Math.floor((len[i] + 1) / 2);\nprint(ans);\n"}, {"source_code": "\nvar bsearch = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n while (l <= r) { \n var m = Math.floor((r+l) / 2); \n if (A[m] == x) { \n return true; \n }\n else if (A[m] < x) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return false; \n}\n\nvar main = function(n, k) { \n if (k == 1) { \n return n; \n }\n A = readline().split(' ').map(Number); \n A.sort(function(a, b) {\n return a - b;}); \n\n var cnt = 0; \n for (i in A) { \n if (bsearch(A, A[i] * k)) { \n // \n }\n else { \n cnt += 1; \n }\n }\n return cnt; \n}\n\nprint(main.apply(null, readline().split(' ').map(Number))); \n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\n/*/====================\nvar fs = require('fs');\n\nfs.readFile('input.txt', 'utf8', function(err, arr) {\n main(arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, '')))\n})\n//====================*/\nfunction max(a,b){\n if (a>b)\n return a\n return b\n}\nfunction main(input) {\n a=input[0].split(' ')\n n=+a[0]\n k=+a[1]\n a=input[1].split(' ').map(x => +x)\n E=new Object()\n for (i=0;i1)\n while(a[i]%k==0){\n a[i]/=k\n ++x\n }\n if (E[a[i]]==undefined){\n E[a[i]]=new Array()\n }\n E[a[i]].push(x)\n }\n ans=0\n function solve(arr,key){\n sort(arr)\n dp=new Array(32)\n for (i=0;i<32;i++)\n dp[i]=0\n K=new Object()\n for (i=0;i<32;i++){\n K[i]=0\n }\n for (i=0;i2){\n dp[i]+=max(dp[i-2],dp[i-1])\n }\n if (dp[i]>x)\n x=dp[i]\n }\n wr(key,arr,x)\n ans+=x\n }\n\n for (key in E){\n solve(E[key],key)\n }\n wr(ans)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\n/*/====================\nvar fs = require('fs');\n\nfs.readFile('input.txt', 'utf8', function(err, arr) {\n main(arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, '')))\n})\n//====================*/\nfunction max(a,b){\n if (a>b)\n return a\n return b\n}\nfunction main(input) {\n a=input[0].split(' ')\n n=+a[0]\n k=+a[1]\n a=input[1].split(' ').map(x => +x)\n E=new Object()\n for (i=0;i2){\n dp[i]+=max(dp[i-2],dp[i-1])\n }\n if (dp[i]>x)\n x=dp[i]\n }\n ans+=x\n }\n\n for (key in E){\n solve(E[key])\n }\n wr(ans)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\n/*/====================\nvar fs = require('fs');\n\nfs.readFile('input.txt', 'utf8', function(err, arr) {\n main(arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, '')))\n})\n//====================*/\nfunction max(a,b){\n if (a>b)\n return a\n return b\n}\nfunction main(input) {\n a=input[0].split(' ')\n n=+a[0]\n k=+a[1]\n a=input[1].split(' ').map(x => +x)\n E=new Object()\n for (i=0;i1)\n while(a[i]%k==0){\n a[i]/=k\n ++x\n }\n if (E[a[i]]==undefined){\n E[a[i]]=new Array()\n }\n E[a[i]].push(x)\n }\n ans=0\n function solve(arr,key){\n sort(arr)\n dp=new Array(32)\n for (i=0;i<32;i++)\n dp[i]=0\n K=new Object()\n for (i=0;i<32;i++){\n K[i]=0\n }\n for (i=0;i2){\n dp[i]+=max(dp[i-2],dp[i-1])\n }\n if (dp[i]>x)\n x=dp[i]\n }\n ans+=x\n }\n\n for (key in E){\n solve(E[key],key)\n }\n wr(ans)\n}"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n \nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n \n \nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n \nfunction wr(...x) {\n console.log(...x)\n}\n \nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n \nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n \nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\n/*/====================\nvar fs = require('fs');\n\nfs.readFile('input.txt', 'utf8', function(err, arr) {\n main(arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, '')))\n})\n//====================*/\nfunction max(a,b){\n if (a>b)\n return a\n return b\n}\nfunction main(input) {\n a=input[0].split(' ')\n n=+a[0]\n k=+a[1]\n a=input[1].split(' ').map(x => +x)\n E=new Object()\n for (i=0;i1)\n while(a[i]%k==0){\n a[i]/=k\n ++x\n }\n if (E[a[i]]==undefined){\n E[a[i]]=new Array()\n }\n E[a[i]].push(x)\n }\n ans=0\n function solve(arr,key){\n sort(arr)\n dp=new Array(32)\n for (i=0;i<32;i++)\n dp[i]=0\n K=new Object()\n for (i=0;i<32;i++){\n K[i]=0\n }\n for (i=0;i2){\n dp[i]+=max(dp[i-2],dp[i-1])\n }\n if (dp[i]>x)\n x=dp[i]\n }\n wr(key,arr,x)\n ans+=x\n }\n\n for (key in E){\n solve(E[key],key)\n }\n}"}], "src_uid": "4ea1de740aa131cae632c612e1d582ed"} {"source_code": "var t = +readline()\nwhile (t--) {\n var str = readline()\n min = 9\n\n var tmp = []\n\n for (var i = str.length - 1; i >= 0; i--) {\n if (str[i] <= min) {\n min = str[i]\n tmp.push(min)\n } else {\n tmp.push(Math.min(Number(str[i]) + 1, 9))\n }\n }\n \n var ans = tmp.sort(function (a, b) { return a - b }).join(\"\")\n print(ans)\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(read) {\r\n const nums = read().split('').map((s, i) => [Number(s), i]),\r\n n = nums.length;\r\n const a = new Heap((a, b) => {\r\n if (a[0] !== b[0]) return a[0] - b[0];\r\n return a[1] - b[1];\r\n });\r\n for (let i = 0; i < n; i++) a.push(nums[i]);\r\n const b = new Heap((a, b) => a - b);\r\n const res = [];\r\n for (let i = 0; i < n; i++) {\r\n while (a.size() && a.top()[1] < i) a.pop();\r\n if (!a.size()) break;\r\n while (b.size() && b.top() <= a.top()[0]) {\r\n res.push(b.pop());\r\n }\r\n if (a.top()[0] === nums[i][0]) {\r\n res.push(nums[i][0]);\r\n a.pop();\r\n } else {\r\n b.push(Math.min(nums[i][0] + 1, 9));\r\n }\r\n }\r\n while (b.size()) {\r\n res.push(b.pop());\r\n }\r\n return res.join('');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let arr = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n for(let i=0;i{\r\n if(a[0]===b[0]) return a[1]-b[1];\r\n else return a[0]-b[0];\r\n });\r\n let max = arr[0][1];\r\n for(let i=0;ia[0]-b[0]);\r\n let res = [];\r\n for(let i=0;i= 0; i--) {\n if (str[i] <= min) {\n min = str[i]\n tmp2.push(min)\n } else {\n tmp.push(Math.min(Number(str[i]) + 1, 9))\n }\n }\n \n var ans = tmp.concat(tmp2).sort(function (a, b) { return a - b }).join(\"\")\n print(ans)\n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(read) {\r\n const nums = read().split('').map((s, i) => [Number(s), i]),\r\n n = nums.length;\r\n const a = new Heap((a, b) => {\r\n if (a[0] !== b[0]) return a[0] - b[0];\r\n return a[1] - b[1];\r\n });\r\n for (let i = 0; i < n; i++) a.push(nums[i]);\r\n const b = new Heap((a, b) => a - b);\r\n const res = [];\r\n for (let i = 0; i < n; i++) {\r\n while (a.size() && a.top()[1] < i) a.pop();\r\n if (!a.size()) break;\r\n while (b.size() && b.top() === a.top()[0]) {\r\n res.push(b.pop());\r\n }\r\n if (a.top()[0] === nums[i][0]) {\r\n res.push(nums[i][0]);\r\n a.pop();\r\n } else {\r\n b.push(Math.min(nums[i][0] + 1, 9));\r\n }\r\n }\r\n while (b.size()) {\r\n res.push(b.pop());\r\n }\r\n return res.join('');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 100;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let arr = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n for(let i=0;i{\r\n if(a[0]===b[0]) return a[1]-b[1];\r\n else return a[0]-b[0];\r\n });\r\n let max = arr[0][1];\r\n for(let i=0;i {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let arr = readline().trim().split(\"\").map(cur=>parseInt(cur));\r\n for(let i=0;i{\r\n if(a[0]===b[0]) return a[1]-b[1];\r\n else return a[0]-b[0];\r\n });\r\n let flag = 0;\r\n for(let i=1;iarr[i][1]){\r\n flag = 1;\r\n arr[i][0] = Math.min(arr[i][0]+1,9);\r\n }\r\n }\r\n let res = [];\r\n for(let i=0;i {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const s = readLine();\r\n\r\n b(n,s);\r\n \r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction b(n,s){\r\n let t = [];\r\n let m = [];\r\n let cnt = 0;\r\n for(let i= 0 ; i < n; i++) s[i] === 'T' ? t.push(i) : m.push(i);\r\n if(t.length/m.length !== 2) return console.log('NO');\r\n for(let i = 0; i < m.length; i++)\r\n if(m[i] < t[i] || m[i] > t[i + m.length]) return console.log('NO');\r\n return console.log('YES');\r\n}\r\n\r\nmodule.exports = b", "positive_code": [{"source_code": "\"use strict\";\n//////////// LIBS\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift().trim();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction solve(n, str) {\n let m = [];\n let t = [];\n str.split('').forEach((c, i) => {\n if (c === 'T') {\n t.push(i);\n }\n else {\n m.push(i);\n }\n });\n if (m.length * 2 !== t.length) {\n console.log('NO');\n return;\n }\n for (let i = 0; i < m.length; i++) {\n if (t[i] > m[i] || t[i + m.length] < m[i]) {\n console.log('NO');\n return;\n }\n }\n console.log('YES');\n}\nfunction main() {\n const io = new IO();\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let str = io.nextLine();\n solve(n, str);\n }\n}\nmain();\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = next();\r\n\t\tvar T = [];\r\n\t\tvar M = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(s[j] == \"T\"){\r\n\t\t\t\tT.push(j);\r\n\t\t\t}else{\r\n\t\t\t\tM.push(j);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(T.length == M.length * 2){\r\n\t\t\tvar isOK = true;\r\n\t\t\tfor(var j = 0; j < M.length; j++){\r\n\t\t\t\tif(M[j] < T[j] || M[j] > T[j + M.length]){\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i tCounter2) {\r\n\t\t\t\t\tflag = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (str[str.length-1-j] === 'T') {\r\n\t\t\t\ttCounter2++;\r\n\t\t\t}\r\n\r\n\t\t\tif (str[j] === 'M') {\r\n\t\t\t\tmCounter++;\r\n\r\n\t\t\t\tif (mCounter > tCounter) {\r\n\t\t\t\t\tflag = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (str[j] === 'T') {\r\n\t\t\t\ttCounter++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (flag && (mCounter * 2 === tCounter)) {\r\n\t\t\tconsole.log('YES')\r\n\t\t} else {\r\n\t\t\tconsole.log('NO')\r\n\t\t}\r\n\t}\r\n\r\n})"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n let tc = 0,\r\n mc = 0,\r\n ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"T\") tc++;\r\n else mc++;\r\n if (mc > tc) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === false) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n (tc = 0), (mc = 0);\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (str[i] === \"T\") tc++;\r\n else mc++;\r\n if (mc > tc) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === false) console.log(\"NO\");\r\n else {\r\n if (tc / 2 === mc) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, str) {\r\n str = str.split('')\r\n let tc = 0, mc = 0, cc = 0\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === 'T') {\r\n tc++\r\n if (cc < 0) cc++\r\n } else {\r\n mc++\r\n cc--\r\n }\r\n if (mc > tc) return false\r\n }\r\n mc *= 2\r\n return !(cc !== 0 || mc !== tc)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i], inputArr[i + 1]);\r\n (res) ? console.log('YES') : console.log('NO')\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, k] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n });\r\n var count1 = 0\r\n var count2 = 0\r\n\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] === 'T') count1++\r\n if (a[j] === 'M') count2++\r\n if (a[j] === 'M' && count1 < count2) return console.log('NO')\r\n }\r\n count1 = 0\r\n count2 = 0\r\n\r\n for (let j = n - 1; j >= 0; j--) {\r\n if (a[j] === 'T') count1++\r\n if (a[j] === 'M') count2++\r\n if (a[j] === 'M' && count1 < count2) return console.log('NO')\r\n }\r\n if (count1 !== count2 * 2) return console.log('NO')\r\n console.log('YES')\r\n })\r\n}\r\n\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, s) => {\r\n let t = m = cnt = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == 'T') {\r\n t++;\r\n if (cnt < 0) cnt++;\r\n } else {\r\n m++;\r\n cnt--;\r\n }\r\n if (m > t) return pr(\"NO\");\r\n }\r\n if (cnt != 0 || m * 2 != t) return pr(\"NO\");\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, s) => {\r\n let t = m = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (s[i] == 'T') {\r\n t++;\r\n } else {\r\n m++;\r\n }\r\n if (m > t) return pr(\"NO\");\r\n }\r\n if (m * 2 != t) return pr(\"NO\");\r\n pr('YES');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/**\r\n * 04/16/21 morning\r\n * https://codeforces.com/contest/1509/problem/B\r\n */\r\n\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, s) => {\r\n let t = [];\r\n let m = [];\r\n for (let i = 0; i < n; i++) {\r\n s[i] == 'T' ? t.push(i) : m.push(i);\r\n }\r\n // pr(t, m)\r\n let tn = t.length;\r\n let mn = m.length;\r\n if (2 * mn != tn) return pr(\"NO\");\r\n let res = [];\r\n while (1) {\r\n if (t.length == 0 || m.length == 0) break;\r\n let t1 = t.shift();\r\n let t2 = t.pop();\r\n let m1 = m.shift();\r\n // pr([t1, m1, t2]);\r\n if (m1 < t1 || m1 > t2) return pr(\"NO\");\r\n res.push([t1, m1, t2]);\r\n }\r\n // pr(res);\r\n if (res.length * 3 != n) return pr(\"NO\");\r\n pr(\"YES\");\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "/**\r\n * 04/16/21 morning\r\n * https://codeforces.com/contest/1509/problem/B\r\n */\r\n\r\n\r\n///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, s) => {\r\n let t = [];\r\n let m = [];\r\n for (let i = 0; i < n; i++) {\r\n s[i] == 'T' ? t.push(i) : m.push(i);\r\n }\r\n // pr(t, m)\r\n let tn = t.length;\r\n let mn = m.length;\r\n if (2 * mn != tn) return pr(\"NO\");\r\n let res = [];\r\n while (1) {\r\n if (t.length == 0 || m.length == 0) break;\r\n let t1 = t.shift();\r\n let t2 = t.pop();\r\n let m1 = m.shift();\r\n // pr([t1, m1, t2]);\r\n if (m1 < t1 || m1 > t2) return pr(\"NO\");\r\n res.push([t1, m1, t2]);\r\n }\r\n // pr(res);\r\n pr(\"YES\");\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const s = readLine();\r\n\r\n\r\n let t = 0;\r\n let m = 0;\r\n let cnt = 0;\r\n for(let i= 0 ; i < n; i++){\r\n if(s[i] === 'T') \r\n {\r\n t++;\r\n if(cnt < 0) cnt++;\r\n }\r\n else \r\n {\r\n m++;\r\n cnt--;\r\n }\r\n if(m > t) \r\n {\r\n console.log('NO');\r\n break;\r\n }\r\n }\r\n cnt != 0 || m*2 != t ? console.log('NO') : console.log('YES');\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n "}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const s = readLine();\r\n\r\n\r\n let t = 0;\r\n let m = 0;\r\n let end = false;\r\n for(let i= 0 ; i < n; i++){\r\n if(s[i] === 'T') t++;\r\n else m++;\r\n if(m > t){\r\n console.log('NO');\r\n end = true;\r\n break;\r\n }\r\n }\r\n if(!end) m*2 === t ? console.log('YES') : console.log('NO');\r\n \r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n "}, {"source_code": "\"use strict\";\n//////////// LIBS\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction solve(n, str) {\n let m = [];\n let t = [];\n str.split('').forEach((c, i) => {\n if (c === 'T') {\n t.push(i);\n }\n else {\n m.push(i);\n }\n });\n if (m.length * 2 !== t.length) {\n console.log('NO');\n return;\n }\n for (let i = 0; i < m.length; i++) {\n if (t[i] > m[i] || t[i + m.length] < m[i]) {\n console.log('NO');\n return;\n }\n }\n console.log('YES');\n}\nfunction main() {\n const io = new IO();\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let str = io.nextLine();\n solve(n, str);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\n//////////// LIBS\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass IO {\n constructor() {\n this.lines = [];\n this.tokens = [];\n this.lines = require('fs').readFileSync(0, 'utf8').split('\\n');\n }\n getTokens() {\n if (!this.tokens.length) {\n this.tokens = this.nextLine().split(' ');\n }\n return this.tokens;\n }\n nextLine() {\n return this.lines.shift();\n }\n nextNum() {\n return Number(this.getTokens().shift());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n}\nfunction solve(n, str) {\n let l = 0;\n let r = n - 1;\n let count = 0;\n for (let i = 0; i < n; i++) {\n if (str[i] === 'M') {\n count++;\n }\n }\n if (n / 3 !== count) {\n console.log('NO');\n return;\n }\n for (let i = 0; i < n; i++) {\n // console.log(str[i], { l, r });\n if (str[i] === 'M') {\n if (str[l] === 'M' || str[r] === 'M') {\n console.log('NO');\n return;\n }\n l++;\n r--;\n if (l == i) {\n l++;\n }\n }\n }\n console.log('YES');\n}\nfunction main() {\n const io = new IO();\n let t = io.nextNum();\n while (t--) {\n let n = io.nextNum();\n let str = io.nextLine();\n solve(n, str);\n }\n}\nmain();\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar T = [];\r\n\t\tvar M = [];\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(s[j] == \"T\"){\r\n\t\t\t\tT.push(j);\r\n\t\t\t}else{\r\n\t\t\t\tM.push(j);\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < M.length; j++){\r\n\t\t\tvar index = M[j];\r\n\t\t\tvar L = T[0];\r\n\t\t\tvar R = T[T.length - 1];\r\n\t\t\tif(L < index && index < R){\r\n\t\t\t\tT.shift();\r\n\t\t\t\tT.pop();\r\n\t\t\t}else{\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK && T.length == 0){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i tCounter) {\r\n\t\t\t\t\tflag = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (str[j] === 'T') {\r\n\t\t\t\ttCounter++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (flag && (mCounter * 2 === tCounter)) {\r\n\t\t\tconsole.log('YES')\r\n\t\t} else {\r\n\t\t\tconsole.log('NO')\r\n\t\t}\r\n\t}\r\n\r\n})"}, {"source_code": "\r\nlet input = '';\r\nprocess.stdin.on('data', str => input += str)\r\nprocess.stdin.on('end', () => {\r\n\tconst lines = input.trim().split('\\n').slice(1);\r\n\r\n\tfor (let i=1; i {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n let tc = 0,\r\n mc = 0,\r\n ans = true;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === \"T\") tc++;\r\n else mc++;\r\n if (mc > tc) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n if (ans === false) console.log(\"NO\");\r\n else {\r\n if (tc / 2 === mc) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}], "src_uid": "94df40fbf9d7e8f91d5e7fde783bb389"} {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 2e5+5;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst smex = [];\r\n\t\tlet cnt = Array(mxN).fill(0);\r\n\t\tfor (let i = n-1, cmex = 0; i >= 0; i--) {\r\n\t\t\tcnt[a[i]]++;\r\n\t\t\twhile (cnt[cmex]) cmex++;\r\n\t\t\tsmex[i] = cmex;\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tcnt = Array(mxN).fill(0);\r\n\t\tfor (let i = 0, cmex = 0, L = 0; i < n; i++) {\r\n\t\t\tif (!cnt[a[i]]) cnt[a[i]] = 0;\r\n\t\t\tcnt[a[i]]++;\r\n\t\t\twhile (cnt[cmex]) cmex++;\r\n\t\t\tif (cmex == smex[L]) {\r\n\t\t\t\tans.push(cmex);\r\n\t\t\t\tcmex = 0;\r\n\t\t\t\tcnt = [];\r\n\t\t\t\tL = i + 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst mxN = 2e5+5;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst smex = [];\r\n\t\tlet cnt = [];\r\n\t\tfor (let i = n-1, cmex = 0; i >= 0; i--) {\r\n\t\t\tcnt[a[i]] = cnt[a[i]] + 1 || 1;\r\n\t\t\twhile (cnt[cmex]) cmex++;\r\n\t\t\tsmex[i] = cmex;\r\n\t\t}\r\n\r\n\t\tconst ans = [];\r\n\t\tcnt = [];\r\n\t\tfor (let i = 0, cmex = 0, L = 0; i < n; i++) {\r\n\t\t\tcnt[a[i]] = cnt[a[i]] + 1 || 1;\r\n\t\t\twhile (cnt[cmex]) cmex++;\r\n\t\t\tif (cmex == smex[L]) {\r\n\t\t\t\tans.push(cmex);\r\n\t\t\t\tcmex = 0;\r\n\t\t\t\tcnt = [];\r\n\t\t\t\tL = i + 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1628/A\r\n\r\n/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n const sol = findMeximum(arr);\r\n console.log(sol.length)\r\n for(let el of sol){\r\n process.stdout.write(`${el} `)\r\n }\r\n console.log()\r\n }\r\n}\r\n\r\nfindMeximum = (arr)=>{\r\n let lowerBound = (arr, target)=>{\r\n if(arr.length == 0 )\r\n return undefined;\r\n let start = 0, end = arr.length;\r\n while(start !== end){\r\n const middle = Math.floor((start + end) / 2);\r\n\r\n if(arr[middle] < target){\r\n start = middle + 1;\r\n }\r\n else{\r\n end = middle;\r\n }\r\n }\r\n if(arr[start] >= target){\r\n return arr[start]\r\n }\r\n else{\r\n return undefined;\r\n }\r\n }\r\n // find pos array\r\n\r\n let max = arr.length;\r\n // for(let el of arr){\r\n // max = Math.max(max,el)\r\n // }\r\n let pos = new Array(max+1);\r\n\r\n for(let i =0; i<= max; ++i){\r\n pos[i] = [];\r\n }\r\n \r\n for(let i=0; i stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst freq = Array(n+1).fill(0);\r\n\t\tconst delP = Array(n+1).fill(-1);\r\n\r\n\t\tfor (let i = 0; i < n; i++) freq[a[i]]++;\r\n\r\n\t\tlet mexC = 0;\r\n\t\twhile (mexC < n && freq[mexC]) mexC++;\r\n\r\n\t\tconst ans = [];\r\n\t\tlet cnt = 0, lftP = 0, mexN = mexC;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (a[i] < mexC && delP[a[i]] < lftP) cnt++;\r\n\r\n\t\t\tfreq[a[i]]--;\r\n\t\t\tif (freq[a[i]] == 0) mexN = Math.min(mexN, a[i]);\r\n\r\n\t\t\tdelP[a[i]] = i;\r\n\r\n\t\t\tif (cnt == mexC) {\r\n\t\t\t\tans.push(mexC);\r\n\t\t\t\tmexC = mexN;\r\n\t\t\t\tlftP = i + 1;\r\n\t\t\t\tcnt = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans.length);\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/1628/A\r\n\r\n/* Common Template Starts */\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n/* Common Template Ends */\r\n\r\n\r\nfunction main() {\r\n //take input according to the format;\r\n const t = +(readline());\r\n for(let i =0; iparseInt(el));\r\n const sol = findMeximum(arr);\r\n console.log(sol.length)\r\n for(let el of sol){\r\n process.stdout.write(`${el} `)\r\n }\r\n console.log()\r\n }\r\n}\r\nfindMeximum = (arr)=>{\r\n // find pos array\r\n\r\n let max = 0;\r\n for(let el of arr){\r\n max = Math.max(max,el)\r\n }\r\n console.log(max)\r\n let pos = new Array(max+1);\r\n\r\n for(let i =0; i<= max; ++i){\r\n pos[i] = [];\r\n }\r\n \r\n for(let i=0; iel >=l)\r\n if(elPos!= undefined){\r\n r = Math.max(elPos, r); \r\n }\r\n else{// mex is not present\r\n break;\r\n }\r\n \r\n }\r\n \r\n l = r + 1\r\n sol.push(mex);\r\n }\r\n return [...sol];\r\n\r\n}"}], "src_uid": "962c4354c936030da78261871dd6d55b"} {"source_code": "var n = +readline(), d = readline().split(\" \").map(Number), input = readline().split(\" \"),\ns = +input[0], t = +input[1];\nvar cnt1 = 0, cnt2 = 0, check = true;\n\nif(s == t){\n\twrite(0);\n\tcheck = false;\n}\nelse{\n\tfor(var i = s-1; ;){\n\t\tcnt1 += d[i];\n\t\ti = (i == n-1) ? 0 : i+1;\n\t\tif(i == t-1){\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(var i = ((s-2 < 0) ? n-1 : s-2); ;){\n\t\tcnt2 += d[i];\n\t\ti = (i == 0) ? n-1 : i-1;\n\t\tif(i == ((t-2 < 0) ? n-1 : t-2)){\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nif(check){\n\twrite(Math.min(cnt1, cnt2));\n}", "positive_code": [{"source_code": "var n=+readline();\nvar d=readline().split(' ').map(function(v){return+v});\nvar l=readline().split(' ');\nvar s=+l[0]-1;\nvar t=+l[1]-1;\nvar a=d.splice(Math.min(s, t), Math.abs(t-s) ).reduce(function(sum, v){return sum+v},0);\nvar b=d.reduce(function(sum, v){return sum+v},0);\nprint(Math.min(a,b));"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar s = readline().split(' ').map(function (i) { return +i; });\n\tvar p = readline().split(' ').map(function (i) { return +i; }).sort(function (a, b) { return a - b; });\n\n\tif (p[0] == p[1]) {\n\t\tprint( 0 );\n\t\treturn;\n\t} else {\n\t\tp[0]--;\n\t\tp[1]--;\n\t}\n\n\tvar a = s.slice(p[0], p[1]).reduce(function (p, c, i, a) { return p + c; }, 0);\n\tvar b = s.reduce(function (p, c, i, a) { return p + c; }, 0);\n\n\tprint( Math.min(a, b-a) );\n\n}).call(this);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet arr;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n arr = d.split(' ').map(Number);\n c++;\n return;\n }\n\n let [start, end] = d.split(' ').map(Number);\n let left = 0;\n let right = 0;\n start--;\n end--;\n\n let x = start;\n let y = end;\n\n while(x !== y) {\n left += arr[x];\n x = (x + 1) % arr.length;\n }\n\n x = start;\n y = end;\n\n while (x !== y) {\n let r = (x - 1) % arr.length;\n if (r < 0) {\n r = r + arr.length;\n }\n x = r;\n right += arr[x];\n }\n\n const ans = Math.min(left, right);\n\n console.log(ans);\n\n c++;\n});\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar s = readline().split(' ').map(function (i) { return +i; });\n\tvar p = readline().split(' ').map(function (i) { return +i; }).sort(function (a, b) { return a - b; });\n\n\tif (p[0] == p[1]) {\n\t\tprint( 0 );\n\t\treturn;\n\t} else {\n\t\tp[0]--;\n\t\tp[1]--;\n\t}\n\n\tvar a = s.slice(p[0], p[1] - p[0]).reduce(function (p, c, i, a) { return p + c; }, 0);\n\tvar b = s.reduce(function (p, c, i, a) { return p + c; }, 0);\n\n\tprint( Math.min(a, b-a) );\n\n}).call(this);"}], "src_uid": "22ef37041ebbd8266f62ab932f188b31"} {"source_code": "\nprint(function(n){\n\tvar high = 1e9+5;\n\tvar low = -1e9-5;\n\tfor(var i=0; i='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(+l[1]-1, high);\n\t\t\t}\n\t\t}else if(l[0] === '<='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(+l[1], high);\n\t\t\t}else{\n\t\t\t\tlow = Math.max(+l[1]+1, low);\n\t\t\t}\n\t\t}else if(l[0] === '>'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(+l[1]+1, low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(+l[1], high);\n\t\t\t}\n\t\t}else if(l[0] === '<'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(+l[1]-1, high);\n\t\t\t}else{\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}\n\t\t}\n\t}\n\tif( high >= low ){\n\t\treturn low;\n\t}\n\treturn 'Impossible';\n\n}(+readline()));", "positive_code": [{"source_code": "function main(){\n var n = parseInt(readline()),\n up = 1<<30;\n low = -up;\n while ( n-- ){\n var tmp = readline().split(\" \");\n tmp[1] = parseInt(tmp[1]);\n if ( tmp[2] == \"N\" ){\n if ( tmp[0] == \">=\" ){\n tmp[0] = \"<\";\n }\n else if ( tmp[0] == \"<=\" ){\n tmp[0] = \">\";\n }\n else if ( tmp[0] == \">\" ){\n tmp[0] = \"<=\";\n }\n else if ( tmp[0] == \"<\" ){\n tmp[0] = \">=\";\n }\n }\n if ( tmp[0] == \">\" && tmp[1]+1 > low ){\n low = tmp[1]+1;\n }\n else if ( tmp[0] == \">=\" && tmp[1] > low ){\n low = tmp[1];\n }\n else if ( tmp[0] == \"<\" && tmp[1]-1 < up ){\n up = tmp[1]-1;\n }\n else if ( tmp[0] == \"<=\" && tmp[1] < up ){\n up = tmp[1];\n }\n }\n if ( up < low ){\n print(\"Impossible\");\n }\n else{\n print(low);\n }\n}\n\nmain();\n"}, {"source_code": "function main()\n{\n var n = parseInt(readline());\n var up = 1<<30;\n var low = -up;\n while ( n-- )\n {\n var tmp = readline().split(\" \");\n tmp[1] = parseInt(tmp[1]);\n if ( tmp[2] == \"N\" )\n {\n if ( tmp[0] == \">=\" )\n {\n tmp[0] = \"<\";\n }\n else if ( tmp[0] == \"<=\" )\n {\n tmp[0] = \">\";\n }\n else if ( tmp[0] == \">\" )\n {\n tmp[0] = \"<=\";\n }\n else if ( tmp[0] == \"<\" )\n {\n tmp[0] = \">=\";\n }\n }\n if ( tmp[0] == \">\" )\n {\n if ( tmp[1]+1 > low )\n low = tmp[1]+1;\n }\n else if ( tmp[0] == \">=\" )\n {\n if ( tmp[1] > low )\n low = tmp[1];\n }\n else if ( tmp[0] == \"<\" )\n {\n if ( tmp[1]-1 < up )\n up = tmp[1]-1;\n }\n else if ( tmp[0] == \"<=\" )\n {\n if ( tmp[1] < up )\n up = tmp[1];\n }\n }\n if ( up < low )\n {\n print(\"Impossible\");\n }\n else\n {\n print(low);\n }\n}\n\nmain();\n"}, {"source_code": "\n\n\nprint(function(n){\n var high = 1e9+5;\n var low = -1e9-5;\n for(var i=0; i='){\n if(l[2] === 'Y'){\n low = Math.max(+l[1], low);\n }else{\n high = Math.min(+l[1]-1, high);\n }\n }else if(l[0] === '<='){\n if(l[2] === 'Y'){\n high = Math.min(+l[1], high);\n }else{\n low = Math.max(+l[1]+1, low);\n }\n }else if(l[0] === '>'){\n if(l[2] === 'Y'){\n low = Math.max(+l[1]+1, low);\n }else{\n high = Math.min(+l[1], high);\n }\n }else if(l[0] === '<'){\n if(l[2] === 'Y'){\n high = Math.min(+l[1]-1, high);\n }else{\n low = Math.max(+l[1], low);\n }\n }\n }\n if( high >= low ){\n return low;\n }\n return 'Impossible';\n\n}(+readline()));"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -2000000000;\nvar max_ = 2000000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = l[2];\n if(yn==\"N\")\n sign = f(sign);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num - 1,max_);\n else if (sign==\">\")\n min_ = Math.max(num + 1,min_ );\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -2000000000;\nvar max_ = 2000000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = l[2];\n if(yn==\"N\")\n sign = f(sign);//equivoque de variablr\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);//libreria\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num - 1,max_);\n else if (sign==\">\")\n min_ = Math.max(num + 1,min_ );\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");\n"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n return trim(s).split(/\\s+/);\n}\nfunction main() {\n minValue=-2*1000*1000*1000;\n maxValue=2*1000*1000*1000;\n var n = trim(readline());\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();\n"}, {"source_code": "print(function(n){\n var high = 1e9+5;\n var low = -1e9-5;\n for(var i=0; i='){\n if(l[2] === 'Y'){\n low = Math.max(+l[1], low);\n }else{\n high = Math.min(+l[1]-1, high);\n }\n }else if(l[0] === '<='){\n if(l[2] === 'Y'){\n high = Math.min(+l[1], high);\n }else{\n low = Math.max(+l[1]+1, low);\n }\n }else if(l[0] === '>'){\n if(l[2] === 'Y'){\n low = Math.max(+l[1]+1, low);\n }else{\n high = Math.min(+l[1], high);\n }\n }else if(l[0] === '<'){\n if(l[2] === 'Y'){\n high = Math.min(+l[1]-1, high);\n }else{\n low = Math.max(+l[1], low);\n }\n }\n }\n if( high >= low ){\n return low;\n }\n return 'Impossible';\n\n}(+readline()));"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n // var test = [\">= 1 Y\",\n // \"< 3 N\",\n // \"<= -3 N\",\n // \"> 55 N\"\n // ];\n for (var i = 0; i < n; i++) {\n var li = readline().split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n print(\"Impossible\");\n } else {\n print(maxn + \"\");\n }\n}\nmain(+readline())\n"}, {"source_code": "print(function(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n for (var i = 0; i < n; i++) {\n var li = readline().split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n return \"Impossible\";\n } else {\n return maxn;\n }\n}(+readline()))\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar numConstraints = trim(readline()),\n\t\tminValue = -2*Math.pow(10, 9),\n\t\tmaxValue = -minValue,\n\t\tinverse = { '<': '>=', '<=': '>', '>': '<=', '>=': '<' };\n\tfor (var i = 0; i < numConstraints; ++i) {\n\t\tvar tokens = trim(readline()).split(/\\s+/),\n\t\t\tcondition = tokens[0],\n\t\t\tlimit = tokens[1],\n\t\t\tanswer = tokens[2];\n\t\tif (answer == 'N') {\n\t\t\tcondition = inverse[condition];\n\t\t}\n\t\tif (condition.charAt(0) == '>') {\n\t\t\tif (condition.length == 1) {\n\t\t\t\t++limit;\n\t\t\t}\n\t\t\tif (limit > maxValue) {\n\t\t\t\tprint(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tminValue = Math.max(minValue, limit);\n\t\t} else {\n\t\t\tif (condition.length == 1) {\n\t\t\t\t--limit;\n\t\t\t}\n\t\t\tif (limit < minValue) {\n\t\t\t\tprint(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tmaxValue = Math.min(maxValue, limit);\n\t\t}\n\t}\n\tprint(minValue);\n}\n\nmain();\n"}, {"source_code": "function main()\n{\n var n = parseInt(readline());\n var up = 1<<30;\n var low = -up;\n while ( n-- )\n {\n var tmp = readline().split(\" \");\n tmp[1] = parseInt(tmp[1]);\n if ( tmp[2] == \"N\" )\n {\n if ( tmp[0] == \">=\" )\n {\n tmp[0] = \"<\";\n }\n else if ( tmp[0] == \"<=\" )\n {\n tmp[0] = \">\";\n }\n else if ( tmp[0] == \">\" )\n {\n tmp[0] = \"<=\";\n }\n else if ( tmp[0] == \"<\" )\n {\n tmp[0] = \">=\";\n }\n }\n if ( tmp[0] == \">\" && tmp[1]+1 > low )\n {\n low = tmp[1]+1;\n }\n else if ( tmp[0] == \">=\" && tmp[1] > low )\n {\n low = tmp[1];\n }\n else if ( tmp[0] == \"<\" && tmp[1]-1 < up )\n {\n up = tmp[1]-1;\n }\n else if ( tmp[0] == \"<=\" && tmp[1] < up )\n {\n up = tmp[1];\n }\n }\n if ( up < low )\n {\n print(\"Impossible\");\n }\n else\n {\n print(low);\n }\n}\n\nmain();\n"}, {"source_code": "function main()\n{\n var n = parseInt(readline()),\n up = 1<<30;\n low = -up;\n while ( n-- )\n {\n var tmp = readline().split(\" \");\n tmp[1] = parseInt(tmp[1]);\n if ( tmp[2] == \"N\" )\n {\n if ( tmp[0] == \">=\" )\n {\n tmp[0] = \"<\";\n }\n else if ( tmp[0] == \"<=\" )\n {\n tmp[0] = \">\";\n }\n else if ( tmp[0] == \">\" )\n {\n tmp[0] = \"<=\";\n }\n else if ( tmp[0] == \"<\" )\n {\n tmp[0] = \">=\";\n }\n }\n if ( tmp[0] == \">\" && tmp[1]+1 > low )\n {\n low = tmp[1]+1;\n }\n else if ( tmp[0] == \">=\" && tmp[1] > low )\n {\n low = tmp[1];\n }\n else if ( tmp[0] == \"<\" && tmp[1]-1 < up )\n {\n up = tmp[1]-1;\n }\n else if ( tmp[0] == \"<=\" && tmp[1] < up )\n {\n up = tmp[1];\n }\n }\n if ( up < low )\n {\n print(\"Impossible\");\n }\n else\n {\n print(low);\n }\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(n){\n\tvar high = 1e9;\n\tvar low = -1e9;\n\tfor(var i=0; i='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(l[1]-1, high);\n\t\t\t}\n\t\t}else if(l[0] === '<='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(+l[1], high);\t\n\t\t\t}else{\n\t\t\t\tlow = Math.max(l[1]+1, low);\n\t\t\t}\n\t\t}else if(l[0] === '>'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(l[1]+1, low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(+l[1], high);\t\n\t\t\t}\n\t\t}else if(l[0] === '<'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(l[1]-1, high);\n\t\t\t}else{\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}\n\t\t}\n\t}\n\tif( high >= low ){\n\t\treturn low;\n\t}\n\treturn 'Impossible';\n\n}(+readline()));"}, {"source_code": "print(function(n){\n\tvar high = 1e9;\n\tvar low = -1e9;\n\tfor(var i=0; i='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(+l[1]-1, high);\n\t\t\t}\n\t\t}else if(l[0] === '<='){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(+l[1], high);\n\t\t\t}else{\n\t\t\t\tlow = Math.max(+l[1]+1, low);\n\t\t\t}\n\t\t}else if(l[0] === '>'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\tlow = Math.max(+l[1]+1, low);\n\t\t\t}else{\n\t\t\t\thigh = Math.min(+l[1], high);\n\t\t\t}\n\t\t}else if(l[0] === '<'){\n\t\t\tif(l[2] === 'Y'){\n\t\t\t\thigh = Math.min(+l[1]-1, high);\n\t\t\t}else{\n\t\t\t\tlow = Math.max(+l[1], low);\n\t\t\t}\n\t\t}\n\t}\n\tif( high >= low ){\n\t\treturn low;\n\t}\n\treturn 'Impossible';\n\n}(+readline()));"}, {"source_code": "print(function(n){\n var high = 1e9+5;\n var low = -1e9-5;\n for(var i=0; i='){\n if(l[2] === 'Y'){\n low = Math.max(+l[1], low);\n }else{\n high = Math.min(+l[1]-1, high);\n }\n }else if(l[0] === '<='){\n if(l[2] === 'Y'){\n high = Math.min(+l[1], high);\n }else{\n low = Math.max(+l[1]+1, low);\n }\n }else if(l[0] === '>'){\n if(l[2] === 'Y'){\n low = Math.max(+l[1]+1, low);\n }else{\n high = Math.min(+l[1], high);\n }\n }else if(l[0] === '<'){\n if(l[2] === 'Y'){\n high = Math.min(+l[1]-1, high);\n }else{\n low = Math.max(+l[1], low);\n }\n }\n }\n if( high >= low ){\n return low;\n }\n return 'Impossible';\n\n} );"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n return trim(s).split(/\\s+/);\n}\nfunction main() {\n minValue=-2*1000*1000*1000;\n maxValue=2*1000*1000*1000;\n var n = trim(readline());\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n if(x==-6) print(\"aaaaaaaaaaaaaaa\")\n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();\n"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\nfunction tokenize(s) {\n return trim(s).split();\n}\nfunction integers(s) {\n var tokens = tokenize(s);\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n \n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();\n"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\nfunction tokenize(s) {\n return trim(s).split();\n}\nfunction integers(s) {\n var tokens = tokenize(s);\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n \n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n \n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\nfunction tokenize(s) {\n return trim(s).split();\n}\nfunction integers(s) {\n var tokens = tokenize(s);\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n \n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n \n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n return trim(s).split(/\\s+/);\n}\nfunction main() {\n minValue=-2*1000*1000*1000;\n maxValue=2*1000*1000*1000;\n var n = trim(readline());\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n \n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();\n"}, {"source_code": "function trim(s) {\n return s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n return trim(s).split(/\\s+/);\n}\nfunction main() {\n minValue=-2*1000*1000*1000;\n maxValue=2*1000*1000*1000;\n var n = trim(readline());\n for(var i=0; i=\"==r) minValue=Math.max(minValue, x);\n if(\">\"==r) minValue=Math.max(minValue, x+1);\n if(x==-6) print(\"aaaaaaaaaaaaaaa\" + minValue)\n if(\"<=\"==r) maxValue=Math.min(maxValue, x);\n if(\"<\"==r) maxValue=Math.min(maxValue, x-1);\n } else {\n if(\"<\"==r) minValue=Math.max(minValue, x);\n if(\"<=\"==r) minValue=Math.max(minValue, x+1);\n \n if(\">\"==r) maxValue=Math.min(maxValue, x);\n if(\">=\"==r) maxValue=Math.min(maxValue, x-1);\n }\n }\n if(minValue<=maxValue) print(minValue);\n else print(\"Impossible\");\n}\nmain();\n"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n for (var i = 0; i < n; i++) {\n var li = readline.split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (1) {\n print(\"Impossible\");\n } else {\n print(maxn + \"\");\n }\n}(+readline())\n"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n for (var i = 0; i < n; i++) {\n var li = readline.split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n print(\"Impossible\");\n } else {\n print(maxn + \"\");\n }\n}(+readline())\n"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n for (var i = 0; i < n; i++) {\n var li = readline.split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n console.log(\"Impossible\");\n } else {\n console.log(maxn);\n }\n}(+readline)\n"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n for (var i = 0; i < n; i++) {\n var li = readline.split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n print(\"Impossible\");\n } else {\n print(maxn);\n }\n}(+readline)\n"}, {"source_code": "function main(n) {\n var eq, YN, num, minn = -2 * 1e9,\n maxn = 2 * 1e9;\n // var test = [\">= 1 Y\",\n // \"< 3 N\",\n // \"<= -3 N\",\n // \"> 55 N\"\n // ];\n for (var i = 0; i < n; i++) {\n var li = readline().split(\" \");\n eq = li[0], num = +li[1], YN = li[2];\n if (eq === \">=\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num);\n } else {\n maxn = Math.min(maxn, num - 1);\n }\n } else if (eq === \"<=\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num);\n } else {\n minn = Math.max(minn, num + 1);\n }\n } else if (eq === \"<\") {\n if (YN === \"Y\") {\n maxn = Math.min(maxn, num - 1);\n } else {\n minn = Math.max(minn, num);\n }\n } else if (eq === \">\") {\n if (YN === \"Y\") {\n minn = Math.max(minn, num + 1);\n } else {\n maxn = Math.min(maxn, num);\n }\n }\n }\n if (maxn < minn) {\n print(\"Impossible\");\n } else {\n print(maxn + \"\");\n }\n}(+readline())\n"}, {"source_code": "function main()\n{\n var n = parseInt(readline());\n var up = 1<<30;\n var low = -up;\n while ( n-- )\n {\n var tmp = readline().split(\" \");\n tmp[1] = parseInt(tmp[1]);\n if ( tmp[2] == \"N\" )\n {\n if ( tmp[0] == \">=\" )\n tmp[0] = \"<=\";\n else if ( tmp[0] == \"<=\" )\n tmp[0] = \">=\";\n else if ( tmp[0] == \">\" )\n tmp[0] = \"<\";\n else if ( tmp[0] == \"<\" )\n tmp[0] = \">\";\n }\n if ( tmp[0] == \">\" )\n {\n if ( tmp[1]+1 > low )\n low = tmp[1]+1;\n }\n else if ( tmp[0] == \">=\" )\n {\n if ( tmp[1] > low )\n low = tmp[1];\n }\n else if ( tmp[0] == \"<\" )\n {\n if ( tmp[1]-1 < up )\n up = tmp[1]-1;\n }\n else if ( tmp[0] == \"<=\" )\n {\n if ( tmp[1] < up )\n up = tmp[1];\n }\n }\n if ( up < low )\n print(\"Impossible\");\n else\n print(low);\n}\n\nmain();\n"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = +l[2];\n if(yn==\"N\")\n sign = f(yn);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num,max_- 1);\n else\n min_ = Math.max(num,min_ + 1);\n}\nif(min_ <= min_) \n print(min_);\nelse\n print(\"Impossible\");"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = l[2];\n if(yn==\"N\")\n sign = f(sign);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num,max_- 1);\n else if (sign==\">\")\n min_ = Math.max(num,min_ + 1);\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = l[2];\n if(yn==\"N\")\n sign = f(yn);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num,max_- 1);\n else if (sign==\">\")\n min_ = Math.max(num,min_ + 1);\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");\n"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = +l[2];\n if(yn==\"N\")\n sign = f(yn);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num,max_- 1);\n else if (sign==\">\")\n min_ = Math.max(num,min_ + 1);\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = +l[2];\n if(yn==\"N\")\n sign = f(yn);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num,max_- 1);\n else\n min_ = Math.max(num,min_ + 1);\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");\n"}, {"source_code": "function f(v){\n var r = \"\";\n if(v==\">=\")\n r = \"<\";\n else if (v==\"<=\")\n r = \">\";\n else if (v==\"<\")\n r = \">=\";\n else if (v==\">\")\n r = \"<=\";\n return r;\n}\nvar min_ = -200000000;\nvar max_ = 200000000;\nvar n = readline();\nvar sign;\nvar num;\nvar yn;\nfor(var i = 0; i < n; i++)//error poner var\n{\n var l = readline().split(' ');\n sign = l[0];\n num = +l[1];\n yn = l[2];\n if(yn==\"N\")\n sign = f(sign);\n\n if(sign==\">=\")\n min_ = Math.max(num,min_);\n else if (sign==\"<=\")\n max_ = Math.min(num,max_);\n else if (sign==\"<\")\n max_ = Math.min(num - 1,max_);\n else if (sign==\">\")\n min_ = Math.max(num + 1,min_ );\n}\nif(min_ <= max_) \n print(min_);\nelse\n print(\"Impossible\");\n\n"}], "src_uid": "6c6f29e1f4c951cd0ff15056774f897d"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const str = d.slice(1, d.length - 1);\n\n if (str.length === 0) {\n console.log(0);\n return;\n }\n\n const data = str.split(', ');\n const ans = new Set(data).size;\n\n console.log(ans);\n});\n", "positive_code": [{"source_code": "var input = readline();\n\nif (input.length === 2) {\n print(0);\n} else {\n var val = input.slice(1, input.length - 1).split(\", \");\n \n var se = new Set();\n \n for (var i = 0; i < val.length; i++) {\n se.add(val[i]);\n }\n \n print(se.size);\n}"}, {"source_code": "const regExp = /[{} ]/g;\nvar modifiedPlentyToArray = readline().replace(regExp, \"\").split(',');\nif (modifiedPlentyToArray[0]){\n var newSet = new Set(modifiedPlentyToArray);\n print(newSet.size);\n} else {\n print(0);\n}"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\nvar m = {};\nvar a = readline();\n\nfor (var i = 0; i < a.length; i++) {\n if (a[i] != '{' && a[i] != '}' && a[i] != ',' && a[i] != ' ') {\n m[a[i]] = 1;\n }\n}\n\nprint(Object.keys(m).length);"}, {"source_code": "var letters = readline().split(\"\"), unique = [];\nletters.pop();\nletters.shift();\nletters = letters.join(\"\").split(\", \");\n\nfor(i = 0; i < letters.length; i++){\n\tif( letters[0].length == 0 ){\n\t\tunique.length = 0;\n\t\tbreak;\n\t}\n\tif(i == 0){\n\t\tunique.push(letters[i]);\n\t\tcontinue;\n\t}\n\tif( unique.every(function(a){ return (a != letters[i]) ? true : false }) ){\n\t\tunique.push(letters[i]);\n\t}\n}\nwrite(unique.length);"}, {"source_code": "var input = readline();\ninput = input.slice(1, input.length - 1);\nif (input == '') {\n print(0);\n} else {\n input = input.split(', ');\n var unique = {};\n \n for (var i = 0; i < input.length; i++) {\n unique[input[i]] = true;\n }\n print(Object.keys(unique).length);\n}"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s*,\\s*/);\nvar used = {};\nvar answer = 0;\n\nfor (var i = 0; i < s.length; i++) {\n\tif (s[i].length === 1 && !used.hasOwnProperty(s[i])) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s*,\\s*/);\nvar used = {};\nvar answer = 0;\n\nfor (var i = 0; i < s.length; i++) {\n\tif (s[i].length === 1 && used[s[i]] === undefined) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var input = readline();\nvar arr = [];\nfor (var i = 1; i < input.length; i+=3) {\n if (input.charAt(i) != \"{\" || input.charAt(i) != \"}\") {\n var checker = false;\n for (var j = 0; j < arr.length; j++) {\n if (input.charAt(i) == arr[j]) {\n checker = true;\n }\n }\n if (checker == false) {\n arr.push(input.charAt(i));\n }\n }\n}\nif (input.length < 3) {\n print(0);\n}\nelse {\n print(arr.length);\n}"}, {"source_code": "var s = readline(); \nvar a = [];\nvar n = 0;\nvar c = 0;\nvar l = s.length;\n\nfor(i=0; i<26; i++)\n{\n a.push(0); \n}\n\nfor(i=0; i96)\n {\n if(a[c-97] == 0) n++;\n a[c-97] = 1;\n }\n}\n\n\nprint(n);\n\n\n\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nrl.on('line', function(line){\n const set = new Set(line.replace(/{|}/g, '').split(',').map(e => e.trim()).filter(e => e.length));\n console.log(set.size);\n});\n"}, {"source_code": "print(readline().trim().split(/[, {}]+/).sort().splice(2).map(function(x,i,a){ return a.indexOf(x) == i ? 1: 0}).reduce(function(a,b) {return a+b}, 0));\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n if (input[0] === '{}') { console.log(0); process.exit(); }\n const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));\n console.log(n.size);\n});"}, {"source_code": "function onlyUnique(value, index, self) { \n return self.indexOf(value) === index;\n}\n\n\nfunction trimMap(el) {\n \n return el.trim();\n}\n\n\nvar levels = readline();\n\nif (levels == '{}') print(0);\nelse {\n\n levels = levels.slice(0, -1)\n .substr(1)\n .split(',')\n .map(trimMap)\n .filter(onlyUnique);\n \n print(levels.length);\n}\n"}, {"source_code": "var string = readline()\n\n var arr = new Array('z'.charCodeAt(0) - 'a'.charCodeAt(0)).fill(0)\n for (var i = 0; i < string.length; i++) {\n if (string[i] !== '{' && string[i] !== ' ' && string[i] !== ',' && string[i] !== '}') {\n arr[string.charCodeAt(i) - 'a'.charCodeAt(0)] += 1\n }\n }\n\n var count = 0\n for (var i = 0; i < arr.length; i++) {\n if (arr[i] !== 0) {\n count += 1\n }\n }\n\n print(count)"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\n\\r]/).filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(/[{}, ]/).filter(data => data.length > 0));\n}\n\nfunction doit(tab) {\n console.log([...new Set(tab)].length);\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var s = next().replace(\"{\", \"\").replace(\"}\", \"\").replace(/ /g, \"\").split(\",\");\n if(s[0] == \"\"){\n myout(0);\n }else{\n myout(new Set(s).size);\n }\n \n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.replace(/[{()}\\s+]/g, '').trim();\n let distinctLetters = inputs !== '' ? [...new Set(inputs.split(','))].length : 0;\n return distinctLetters.toString();\n}\n\n\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst anton = () => {\n if (input[0] === '{}') {\n console.log(0);\n }\n else {\n let s = input[0].slice(1, -1);\n let ar = s.split(', ');\n let ar2 = new Set(ar);\n console.log(ar2.size);\n }\n};\n\nreadLine.on('close', anton);"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = 1;\n\n if (letters.length == 0)\n return console.log(0)\n\n\n\n letters.sort((a, b) => {\n return a > b ? 1 : -1\n }).reduce((prev, curr) => {\n if (prev != curr)\n counter++;\n return curr\n })\n\n return console.log(counter)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction count(s) {\n let c = 0;\n for (var i = 0; i < s.length; i++) {\n if (s.indexOf(s[i]) == i) {\n c++\n }\n }\n return c;\n}\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let s = readLine().replace(/[{}, ]/g, '');\n console.log(count(s));\n}"}, {"source_code": "var input = readline();\nvar count = [];\nfor(var i= 0; i< input.length; i++){\n if(input.charCodeAt(i) >=97 && input.charCodeAt(i) <=122 && !count.includes(input[i]))count.push(input[i]);\n}\nprint(count.length);"}, {"source_code": ";(function () {\n\tprint( readline().split('').filter(function (e) { return /\\w+/.test(e); }).filter(function (e, i, a) { return i == a.lastIndexOf(e); }).length );\n}).call(this)"}, {"source_code": "var input = readline().slice(1, -1);\nwrite(input ? new Set(input.split(', ')).size : 0);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const line = readline();\n const a = line.slice(1, line.length - 1)\n .split(',')\n .map(x => x.trim())\n .filter(x => x !== '');\n const s = new Set();\n for (let i = 0; i < a.length; i++) {\n s.add(a[i]);\n }\n // output\n print(s.size);\n}\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let a = readline();\n let set = new Set();\n if(a.length < 3) {\n print(\"0\");\n return;\n }\n for (let i = 1; i < a.length; i+=3) {\n const element = a[i];\n set.add(element); \n }\n\n print(set.size);\n \n\n\n}"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const line = input[0];\n const set = new Set();\n for (let i = 0; i < line.length; i += 1) {\n if (line[i] !== '{' && line[i] !== '}' && line[i] !== ' ' && line[i] !== ',')\n set.add(line[i]);\n }\n\n console.log(set.size);\n});"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar s = trim(readline());\n\ts = s.substring(1, s.length-1);\n\tvar tokens = s.split(','),\n\t\tcount = 0, hash = {};\n\tfor (var i = 0; i < tokens.length; ++i) {\n\t\tvar token = trim(tokens[i]);\n\t\tif (token.length == 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (hash[token] === undefined) {\n\t\t\t++count;\n\t\t\thash[token] = true;\n\t\t}\n\t}\n\tprint(count);\n}\n\nmain();\n"}, {"source_code": "var s = readline();\nvar arr = s.substring(1, s.length-1).split(\", \");\nvar obj = {};\nfor(var i =0; i {\n var y = {};\n y[x] = true;\n return y;\n // {`${x}`: true}\n};\nvar toKeyMap = (a, b) => (Object.assign(a, b));\n\nvar noise = '{, }'.split('').map(toObject).reduce(toKeyMap);\nvar noiseFilter = x => (!noise[x]);\n\nvar ar = readline().split('').filter(noiseFilter).map(toObject);\n\nprint(\n ar.length > 0 ?\n Object.keys(ar.reduce(toKeyMap)).length\n : 0\n);\n"}, {"source_code": "'use strict';\nconst obj = {};\nreadline()\n .replace('}', '')\n .replace('{', '')\n .split(',')\n .forEach((letter) => {\n letter = letter.trim();\n if (letter.length) obj[letter] = 1;\n });\n\nwrite(Object.keys(obj).length);"}, {"source_code": "var s = readline();\ns = s.replace(\"}\", \"\");\ns = s.replace(\"{\", \"\");\nvar a = [];\na = s.split(\", \");\nvar res = 0;\nfor(i = 0; i < a.length; i++){\n if(a.indexOf(a[i]) == i){\n res++;\n }\n}\nif(s == \"\"){\n res = 0;\n}\nprint(res);"}, {"source_code": "var n = readline().slice(1,-1).replace(/, /g, \"\").split(\"\");\nvar s = new Set(n).size;\nprint(s);"}, {"source_code": "var values = readline()\nvar set = new Set(values.split(/[\\{\\}\\, ]/g))\nif(set.size == 0)\n print(0)\nelse\n print(set.size - 1)"}, {"source_code": "var input = readline();\ninput = input.slice(1, input.length-1);\nvar array = input.split(\", \");\nvar k=0;\nvar bArr = {};\nfor (i=0; i 0){\n++k;\nbArr[array[i]] = \"*\";\n}\n\n}\nprint(k);"}, {"source_code": "var main = function(str)\n{\n if (str === '{}') return 0;\n\tvar obj = {},\n\tsum = 0,\n arr = str.split(', ');\n\tarr[0] = arr[0][1];\n\tarr[arr.length - 1] = arr[arr.length - 1][0];\n\tarr = arr.sort();\n\t\n\tfor (var i = 0; i <= arr.length - 1; i++)\n\t{\n\t\tif (typeof(obj[arr[i]]) === 'number') obj[arr[i]]++;\n\t\telse {\n\t\t\tobj[arr[i]] = 1;\n\t\t\tsum++;\n\t\t}\n\t}\n\treturn sum;\n}\nvar input = readline();\nprint(main(input));"}, {"source_code": "print(Object.keys(eval('('+readline().replace(/,/g,\": 1,\").replace(/(\\w)}/g,\"$1: 1}\")+')')).length)"}, {"source_code": "var input = readline().slice(1, -1);\nif (input.length === 0)\n\tprint(0);\nelse\n\tprint(input.split(\", \")\n\t.reduce(function(set, value) {\n\t\tif (set.indexOf(value) === -1)\n\t\t\tset.push(value);\n\t\treturn set;\n\t}, [])\n\t.length);\n"}, {"source_code": "var line = readline();\n\nvar alphabet = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];\nvar distinct = 0;\n\n\nfor(i=0;i122){\n\tcontinue;\n }else {\n\talphabet[line.charCodeAt(i)-97]+=1;\n }\n}\n\nfor(i=0;i<26;i++){\n if(alphabet[i]>0){\n\tdistinct+=1;\n }\n}\n\n\nprint(distinct);\n\n\n"}, {"source_code": "var line = readline();\n\nvar alphabet = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];\nvar distinct = 0;\n\n\nfor(i=0;i0){\n\tdistinct+=1;\n }\n}\n\n\nprint(distinct);\n\n\n"}, {"source_code": "var input = readline().slice(1, -1);\nwrite(input ? new Set(input.split(', ')).size : 0);\n"}, {"source_code": "function main(str) {\n var setArr = [];\n var clearStr = str ? str.slice(1, -1) : '';\n if (clearStr) {\n var arr = clearStr.split(', ');\n arr.sort();\n var i = 0;\n for (i; i < arr.length; i++) {\n if (setArr[setArr.length - 1] !== arr[i]) {\n setArr.push(arr[i]);\n }\n }\n }\n write(setArr.length);\n}\nvar data = readline();\nmain(data);"}, {"source_code": "var letters = readline().split(\"\");\nvar set = new Set(letters);\nset.delete(\"{\");\nset.delete(\",\");\nset.delete(\"}\");\nset.delete(\" \");\nprint(set.size)"}], "negative_code": [{"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));\n console.log(n.size);\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const n = new Set(input[0].slice(1, -1).split(' '));\n console.log(n.size);\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n if (input[0] = '{}') { console.log(0); process.exit(); }\n const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));\n console.log(n.size);\n});"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(/[{}, ]/).filter(data => data.length > 0));\n}\n\nfunction doit(tab) {\n console.log([...new Set(tab)].length);\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = 1;\n\n if (letters.length == 0)\n return console.log(0)\n\n\n let sorted = letters.sort((a, b) => a > b)\n\n sorted.reduce((prev, curr) => {\n if (prev != curr)\n counter++;\n return curr\n })\n\n if (counter > 26)\n return console.log(26)\n else\n return console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = letters.length;\n\n if (counter == 0)\n return console.log(counter)\n\n letters.sort((a, b) => a > b).reduce((prev, curr) => {\n if (prev == curr)\n counter--;\n return curr\n })\n\n console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = 1;\n\n if (letters.length == 0)\n return console.log(0)\n\n let sorted = letters.sort((a, b) => a > b)\n \n sorted.reduce((prev, curr) => {\n if (prev != curr)\n counter++;\n return curr\n })\n\n return console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = letters.length;\n\n if (counter == 0)\n return console.log(counter)\n \n letters.sort((a, b) => a < b).reduce((prev, curr) => {\n if (prev == curr)\n counter--;\n return curr\n })\n\n return console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = 1;\n\n if (letters.length == 0)\n return console.log(0)\n\n let sorted = letters.sort((a, b) => a > b)\n \n console.log(sorted);\n\n sorted.reduce((prev, curr) => {\n if (prev != curr)\n counter++;\n return curr\n })\n\n return console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', set => {\n const letters = set.split(/\\W/).filter(letter => letter != '');\n\n check(letters)\n})\n\n\nfunction check(letters) {\n let counter = 1;\n\n if (letters.length == 0)\n return console.log(0)\n\n\n let sorted = letters.sort((a, b) => a > b)\n\n sorted.reduce((prev, curr) => {\n if (prev != curr)\n counter++;\n\n if (counter > 26)\n return console.log(counter)\n\n return curr\n })\n\n return console.log(counter)\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nrl.on('line', function(line){\n const set = new Set(line.replace(/{|}/g, '').split(',').map(e => e.trim()));\n console.log(set.size);\n});\n"}, {"source_code": "var letters = readline().split(\"\"), unique = [];\nletters.pop();\nletters.shift();\nletters = letters.join(\"\").split(\", \");\n\nfor(i = 0; i < letters.length; i++){\n\tif( !!letters ){\n\t\tunique.length = 0;\n\t\tbreak;\n\t}\n\tif(i == 0){\n\t\tunique.push(letters[i]);\n\t\tcontinue;\n\t}\n\tif( unique.every(function(a){ return (a != letters[i]) ? true : false }) ){\n\t\tunique.push(letters[i]);\n\t}\n}\nwrite(unique.length);"}, {"source_code": "var input = readline();\ninput = input.slice(1, input.length - 1).split(', ');\nvar unique = {};\nfor (var i = 0; i < input.length; i++) {\n unique[input[i]] = true;\n}\nprint(Object.keys(unique).length);"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s+,\\s+/);\nvar used = {};\nvar answer = 0;\n\nfor (var i = 0; i < s.length; i++) {\n\tprint(s[i]);\n\tprint(s[i].length);\n\tprint(used[s[i]]);\n\tif (s[i].length === 1 && used.hasOwnProperty(s[i])) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s+,\\s+/);\nvar used = {};\nvar answer = 0;\n\nfor (var i = 0; i < s.length; i++) {\n\tif (s[i].length === 1 && used[s[i]] === undefined) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s+,\\s+/);\nvar used = {};\nvar answer = 0;\n\nprint(s)\nprint(used)\n\nfor (var i = 0; i < s.length; i++) {\n\n\tif (s[i].length === 1 && used[s[i]] === undefined) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var s = readline();\ns = s.slice(1, s.length - 1).split(/\\s*,\\s*/);\nvar used = {};\nvar answer = 0;\n\nfor (var i = 0; i < s.length; i++) {\n\tprint(s[i]);\n\tprint(s[i].length);\n\tprint(used[s[i]]);\n\tif (s[i].length === 1 && !used.hasOwnProperty(s[i])) {\n\t\tanswer++;\n\t\tused[s[i]] = null;\n\t}\n}\n\nprint(answer);"}, {"source_code": "var input = readline();\nvar arr = [];\nfor (var i = 1; i < input.length; i+=3) {\n if (input.charAt(i) != \"{\" || input.charAt(i) != \",\" || input.charAt(i) != \" \" || input.charAt(i) != \"}\") {\n var checker = false;\n for (var j = 0; j < arr.length; j++) {\n if (input.charAt(i) == arr[j]) {\n checker = true;\n }\n }\n if (checker == false) {\n arr.push(input.charAt(i));\n }\n }\n}\nprint(arr.length);"}, {"source_code": "var input = readline().split(\"\");\nvar count = [];\nfor(var e of input){\n if(e == '}' && e == '{' && !cout.includes(e))count.push(e);\n}\nprint(count.length);"}, {"source_code": "var s = readline();\nvar arr = s.substring(1, s.length-1).split(\", \");\nvar obj = {};\nfor(var i =0; i obj[letter.trim()] = 1);\n\nwrite(Object.keys(obj).length);"}, {"source_code": "'use strict';\nconst obj = {};\nreadline()\n .replace('}', '')\n .replace('{', '')\n .replace(' ', '')\n .split(',')\n .map(letter => obj[letter] = 1);\n\nwrite(Object.keys(obj).length);"}, {"source_code": "var s = readline();\ns = s.replace(\"}\", \"\");\ns = s.replace(\"{\", \"\");\nvar a = [];\na = s.split(\", \");\nvar res = 0;\nfor(i = 0; i < a.length; i++){\n if(a.indexOf(a[i]) == i){\n res++;\n }\n}\nprint(res);"}, {"source_code": "var s = readline();\ns = s.replace(\"}\", \"\");\ns = s.replace(\"{\", \"\");\nvar a = [];\na = s.split(\", \");\nvar res = 0;\nfor(i = 0; i < a.length; i++){\n if(a.indexOf(a[i]) == i){\n res++;\n }\n}\nif(a.length == 0){\n res++;\n}\nprint(res);"}, {"source_code": "var n = readline().slice(1,-1);\nvar s = new Set(n.split(\", \")).size;\nprint(s);"}, {"source_code": "var input = readline();\ninput = input.slice(1, input.length-1);\nvar array = input.split(\", \");\nvar k=0;\nvar bArr = {};\nfor (i=0; i str.length-1) return str;\n return str.substr(0,index) + chr + str.substr(index+1);\n}\n\nvar ch = 'a';\nvar acode = ch.charCodeAt(0);\n\n\nfor (var tt = 0; tt < t; tt++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(Number);\n var m = {};\n for (var i = 0; i < n; i++) {\n m[a[i]] = m[a[i]] ? m[a[i]] + 1 : 1;\n }\n var nums = Object.keys(m).map(Number);\n var res = 1;\n for (var i = 0; i < nums.length; i++) {\n var num = nums[i];\n var l = 0;\n var r = n - 1;\n var mcopy = Object.assign({}, m);\n var locallen = 0;\n while (l < r) {\n while (l < n && a[l] != num) {\n mcopy[a[l]] -= 1;\n l += 1;\n }\n while (r >= 0 && a[r] != num) {\n mcopy[a[r]] -= 1;\n r -= 1;\n }\n if (l >= r) {\n break;\n }\n mcopy[a[l]] -= 1;\n l += 1;\n mcopy[a[r]] -= 1;\n r -= 1;\n locallen += 2;\n var localmax = 0;\n var mcopykeys = Object.keys(mcopy);\n for (var j = 0; j < mcopykeys.length; j++) {\n var localkey = mcopykeys[j];\n if (mcopy[localkey] > localmax) {\n localmax = mcopy[localkey];\n }\n }\n \n if (locallen + localmax > res) {\n res = locallen + localmax;\n }\n }\n }\n \n \n write(res+'\\n');\n}\n", "positive_code": [{"source_code": "var t = parseInt(readline());\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nfunction setCharAt(str,index,chr) {\n if(index > str.length-1) return str;\n return str.substr(0,index) + chr + str.substr(index+1);\n}\n\nvar ch = 'a';\nvar acode = ch.charCodeAt(0);\n\n\nfor (var tt = 0; tt < t; tt++) {\n var n = parseInt(readline());\n var a = readline().split(' ').map(Number);\n var m = {};\n for (var i = 0; i < n; i++) {\n m[a[i]] = m[a[i]] ? m[a[i]] + 1 : 1;\n }\n var nums = Object.keys(m).map(Number);\n var res = 1;\n for (var i = 0; i < nums.length; i++) {\n var num = nums[i];\n var l = 0;\n var r = n - 1;\n var mcopy = Object.assign({}, m);\n var locallen = 0;\n while (l < r) {\n while (l < n && a[l] != num) {\n mcopy[a[l]] -= 1;\n l += 1;\n }\n while (r >= 0 && a[r] != num) {\n mcopy[a[r]] -= 1;\n r -= 1;\n }\n if (l >= r) {\n break;\n }\n mcopy[a[l]] -= 1;\n l += 1;\n mcopy[a[r]] -= 1;\n r -= 1;\n locallen += 2;\n var localmax = 0;\n var mcopykeys = Object.keys(mcopy);\n for (var j = 0; j < mcopykeys.length; j++) {\n var localkey = mcopykeys[j];\n if (mcopy[localkey] > localmax) {\n localmax = mcopy[localkey];\n }\n }\n \n if (locallen + localmax > res) {\n res = locallen + localmax;\n }\n }\n }\n \n \n write(res+'\\n');\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\nfunction main(){\n\tvar tt = parseInt(readline());\n\twhile(tt--){\n\t\tvar n = parseInt(readline());\n\t\tvar a = readline().split(\" \").map(function(x){ return parseInt(x) - 1;});\n\t\tvar pre = [];\n\t\tvar fix = [];\n\t\tvar M = 200;\n\t\tvar ans = 0;\n\t\tfor(var i = 0; i < M; i++){\n\t\t\tpre[i] = [], fix[i] = [];\n\t\t\tpre[i][0] = 0;\n\t\t\tfor(var j = 0; j < n; j++){\n\t\t\t\tpre[i][j + 1] = pre[i][j] + (a[j] == i);\n\t\t\t\tif(a[j] == i){\n\t\t\t\t\tfix[i].push(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(var x = 0; x < M; x++){\n\t\t\tvar u = pre[x][n];\n\t\t\tans = Math.max(ans, u);\n\t\t\tfor(var c = 1; 2 * c <= u; c++){\n\t\t\t\tvar l = fix[x][c - 1];\n\t\t\t\tvar r = fix[x][u - c];\n\t\t\t\tfor(var y = 0; y < M; y++){\n\t\t\t\t\tif(x != y)\n\t\t\t\t\t\tans = Math.max(ans, 2 * c + pre[y][r] - pre[y][l]);\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\tconsole.log(ans);\n\t}\n}"}], "negative_code": [], "src_uid": "2c1ee398ea86209335c2248eaa723aca"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet n = (m = remainingLines = remainingTestCount = lineNumber = lineCount = 0);\n\n// Some utitls\nconst utils = {};\nutils.doOnTestInputFinished = (line) => {\n line = line.split('');\n\n const DB = {};\n let position = [0, 0];\n let preparedPosition = utils.preparePosition(position);\n DB[preparedPosition] = [0];\n\n let answer = -1;\n let arrayLength;\n // Make it as much big as we can\n let minLength = Infinity;\n\n for (let letterIndex in line) {\n let letter = line[letterIndex];\n let preparedIndex = Number(letterIndex) + 1;\n\n position = utils.determineNextPosition(position, letter);\n preparedPosition = utils.preparePosition(position);\n\n if (preparedPosition in DB) {\n arrayLength = DB[preparedPosition].length;\n lastIndex = DB[preparedPosition][arrayLength - 1];\n\n if (preparedIndex - lastIndex < minLength) {\n minLength = preparedIndex - lastIndex;\n answer = `${lastIndex + 1} ${preparedIndex}`;\n }\n\n DB[preparedPosition].push(preparedIndex);\n } else {\n DB[preparedPosition] = [preparedIndex];\n }\n }\n\n console.log(answer);\n // console.log('DB', DB);\n};\nutils.preparePosition = (position) => {\n return `${position[0]} ${position[1]}`;\n};\nutils.determineNextPosition = (position, letter) => {\n switch (letter) {\n case 'U':\n return [position[0], position[1] + 1];\n case 'D':\n return [position[0], position[1] - 1];\n case 'R':\n return [position[0] + 1, position[1]];\n case 'L':\n return [position[0] - 1, position[1]];\n }\n return position;\n};\n\nrl.on('line', async (line) => {\n try {\n lineNumber++;\n if (lineNumber === 1) {\n // First Line\n remainingTestCount = Number(line);\n return;\n }\n if (!remainingLines) {\n // First line of each test case\n [n, m] = line.split(' ').map((d) => Number(d));\n remainingLines = 1;\n remainingTestCount--;\n return;\n }\n\n remainingLines--;\n if (remainingLines === 0) {\n // Do something on after inputs of each test case\n utils.doOnTestInputFinished(line);\n }\n } catch (e) {\n console.log(e.message);\n console.log(e.stack);\n }\n});\n", "positive_code": [{"source_code": "// const SegmentTree = require('javascript-algo-ds/src/data-structure/trees/segmentTree/segmentTree')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const s = readString()\n let x = 0, y = 0\n let map = {}\n map[tS(0, 0)] = -1\n let max = [Infinity, -1, -1]\n for(let i = 0; i < n; i++) {\n switch (s[i]) {\n case 'L' : x--; break\n case 'R' : x++; break\n case 'D' : y--; break\n case 'U' : y++; break\n }\n let str = tS(x, y)\n if(map[str] !== undefined) {\n // wr(map, str, i)\n if(i - map[str] < max[0]) {\n max[0] = i - map[str]\n max[1] = map[str]\n max[2] = i\n }\n map[str] = i\n }\n else {\n map[str] = i\n }\n }\n if(max[0] === Infinity) wr(-1)\n else {\n wr(tS(max[1] + 2, max[2] + 1))\n }\n }\n\n function tS(x, y) {\n return `${x} ${y}`\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n\n for (let i = 0; i 1) {\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict'\n\nconst problem = (n, s) => {\n const v = { '0.0': [ -1 ] };\n let x = 0;\n let y = 0;\n for(let i = 0; i < n; i++) {\n if (s[i] === 'L') x--;\n else if (s[i] === 'R') x++;\n else if (s[i] === 'U') y++;\n else if (s[i] === 'D') y--;\n const j = `${x}.${y}`;\n if (v[j]) v[j].push(i);\n else v[j] = [i];\n }\n const values = Object.keys(v).map(i => v[i]).filter(i => i.length > 1);\n let min = Infinity;\n let value;\n for (let i = 0; i < values.length; i++) {\n for (let j = 1, d; j < values[i].length; j++) {\n d = values[i][j] - values[i][j-1];\n if (d < min) { min = d; value = [ values[i][j-1], values[i][j] ] }\n }\n }\n return value ? `${value[0]+2} ${value[1]+1}` : -1;\n}\n\nlet t = +readline();\nwhile(t--) print(problem(+readline(), readline()));\n"}, {"source_code": "'use strict'\n\nlet t = parseInt(readline())\nwhile (t --> 0) {\n const n = parseInt(readline())\n const path = readline()\n let x = 0\n let y = 0\n let last = 0\n let found = false\n const visited = {\n [x + ',' + y]: 0\n }\n\n let ans = 1e9\n for (let i = 0; i < n; ++i) {\n if (path[i] === 'L') {\n x --\n } else if (path[i] === 'R') {\n x ++\n } else if (path[i] === 'U') {\n y ++\n } else {\n y --\n }\n const next = x + ',' + y\n \n if (Object.hasOwnProperty.call(visited, next)) {\n found = true\n const len = i - visited[next]\n if (len < ans) {\n ans = len\n last = i\n }\n }\n visited[next] = i+1\n }\n \n if (!found) print(-1)\n else {\n print(last - ans + 1, last + 1)\n }\n}"}], "negative_code": [{"source_code": "// const SegmentTree = require('javascript-algo-ds/src/data-structure/trees/segmentTree/segmentTree')\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n let t = readInt()\n while(t--) {\n const n = readInt()\n const s = readString()\n let x = 0, y = 0\n let map = {}\n map[tS(0, 0)] = -1\n let max = [Infinity, -1, -1]\n for(let i = 0; i < n; i++) {\n switch (s[i]) {\n case 'L' : x--; break\n case 'R' : x++; break\n case 'D' : y--; break\n case 'U' : y++; break\n }\n let str = tS(x, y)\n if(map[str] !== undefined) {\n if(i - map[str] < max[0]) {\n max[0] = i - map[str]\n max[1] = map[str]\n max[2] = i\n }\n }\n else {\n map[str] = i\n }\n }\n if(max[0] === Infinity) wr(-1)\n else {\n wr(tS(max[1] + 2, max[2] + 1))\n }\n }\n\n function tS(x, y) {\n return `${x} ${y}`\n }\n}\n"}], "src_uid": "1fc1d5ee79aaf823b246db5471ba7836"} {"source_code": "var n = readline();\nvar a = readline();\nvar ro =0,re=0,bo=0,be=0;\nfor (var i=0;i> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length; k++) {\r\n if (~i & 1) {\r\n a[k][i >> 1] += v;\r\n }\r\n //print('addd', k, i, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum < ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length; k++) {\r\n if (i & 1) {\r\n res += a[k][i >> 1];\r\n //print('summ', k, i, a[k][i-1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3] + 1) - sum(r, b[1]) === b[3] - b[1] + 1\r\n || sum(c, b[4] + 1) - sum(c, b[2]) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction inc(F, idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(F, idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n\nfunction solve(n, qs) {\n const ans = []\n const row = Array(n).fill(0)\n const col = Array(n).fill(0)\n const rf = Array(n + 5).fill(0) // a little larger in case\n const cf = Array(n + 5).fill(0) // a little larger in case\n qs.forEach(([t, x, y, x2, y2]) => {\n x--; y--; x2--; y2--\n if (t === 1) {\n // add\n if (!row[x]++) inc(rf, x, 1)\n if (!col[y]++) inc(cf, y, 1)\n } else if (t === 2) {\n // remove\n if (!--row[x]) inc(rf, x, -1)\n if (!--col[y]) inc(cf, y, -1)\n } else {\n // query\n const nr = x2 - x + 1\n const nc = y2 - y + 1\n const kr = sum(rf, x2) - (x ? sum(rf, x - 1) : 0)\n const kc = sum(cf, y2) - (y ? sum(cf, y - 1) : 0)\n // console.log(nr, nc, '-', kr, kc)\n const ok = nr === kr || nc === kc\n ans.push(ok ? 'Yes' : 'No')\n }\n })\n return ans.join('\\n')\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, m, ops) {\r\n const row = new Map(),\r\n column = new Map();\r\n const segTreeR = new SegTree(n + 10),\r\n segTreeC = new SegTree(n + 10);\r\n let res = [];\r\n for (let [t, a, b, c, d] of ops) {\r\n if (t === 1) {\r\n if (row.get(a)) {\r\n row.set(a, row.get(a) + 1);\r\n } else {\r\n row.set(a, 1);\r\n segTreeR.update(a, a, 1);\r\n }\r\n if (column.get(b)) {\r\n column.set(b, column.get(b) + 1);\r\n } else {\r\n column.set(b, 1);\r\n segTreeC.update(b, b, 1);\r\n }\r\n } else if (t === 2) {\r\n row.set(a, row.get(a) - 1);\r\n column.set(b, column.get(b) - 1);\r\n if (!row.get(a)) {\r\n segTreeR.update(a, a, -1);\r\n }\r\n if (!column.get(b)) {\r\n segTreeC.update(b, b, -1);\r\n }\r\n } else {\r\n const x = segTreeR.query(a, c),\r\n y = segTreeC.query(b, d);\r\n if (x === c - a + 1 || y === d - b + 1) {\r\n res.push('YES');\r\n } else {\r\n res.push('NO');\r\n }\r\n }\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n this.update = this._update.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n _newNode(l, r, val = 0, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right,\r\n add: 0\r\n };\r\n }\r\n _update(node, x, y, z) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === r) {\r\n node.val = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);\r\n node.val = node.left.val + node.right.val;\r\n }\r\n _query(node, x, y) {\r\n if (y < x) return 0;\r\n if (!node) return 0;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = 0,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) + this._query(node.right, mid + 1, y);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n solve(n, m, b);\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n];\n\n// SOLUTION:\nIS_MULTITEST = false;\n\nclass SegmentTree {\n constructor(arr){\n this.n = arr.length;\n this.l = null;\n this.r = null;\n this.sum = 0;\n this.toPush = null;\n this.build(arr);\n }\n getMiddle(){\n return Math.floor(this.n/2);\n }\n build(arr){\n if (arr.length==0)\n return;\n if (arr.length==1){\n this.sum = arr[0];\n return;\n }\n let m = this.getMiddle();\n let sum = 0;\n let leftArr = arr.slice(0, m);\n if (leftArr.length){\n this.l = new SegmentTree(leftArr);\n sum += this.l.sum;\n }\n let rightArr = arr.slice(m);\n if (rightArr.length){\n this.r = new SegmentTree(rightArr);\n sum += this.r.sum;\n }\n this.sum = sum;\n }\n push(){\n if (this.toPush==null)\n return;\n this.sum = this.n*this.toPush;\n if (this.r){\n this.r.toPush = this.toPush;\n }\n if (this.l){\n this.l.toPush = this.toPush;\n }\n this.toPush = null;\n }\n setAll(val){\n this.toPush = val;\n }\n set(i, val){\n this.push();\n if (this.n==1)\n {\n this.sum = val;\n return;\n }\n let m = this.getMiddle();\n if (i{\n // READING:\n let [n, q] = ra();\n LT({n, q});\n // PROCESSING:\n let ans = [];\n let cnti = new Array(n).fill(0);\n let sti = new SegmentTree(cnti);\n let cntj = new Array(n).fill(0);\n let stj = new SegmentTree(cntj);\n\n while (q--){\n let [t, a1, a2, a3, a4] = ra();\n if (t==1){ // put a rook\n let x = a1-1, y = a2-1;\n cnti[x]++;\n if (cnti[x]==1)\n sti.set(x, 1);\n cntj[y]++;\n if (cntj[y]==1)\n stj.set(y, 1);\n } if (t==2){ // remove a rook\n let x = a1-1, y = a2-1;\n cnti[x]--;\n if (cnti[x]==0)\n sti.set(x, 0);\n cntj[y]--;\n if (cntj[y]==0)\n stj.set(y, 0);\n } if (t==3){ // query\n let x1 = a1-1, y1 = a2-1;\n let x2 = a3-1, y2 = a4-1;\n let si = sti.sumRange(Math.min(x1, x2), Math.max(x1, x2));\n if (si==Math.abs(x1-x2)+1){\n ans.push('Yes')\n continue;\n }\n let sj = stj.sumRange(Math.min(y1, y2), Math.max(y1, y2));\n if (sj==Math.abs(y1-y2)+1){\n ans.push('Yes')\n continue;\n }\n ans.push('No')\n }\n }\n return ans.join('\\n');\n};\n "}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length; k++) {\r\n //if (i & 1) {\r\n a[k][i] += v;\r\n //}\r\n //print('addd', k, i, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum < ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length; k++) {\r\n if (i & 1) {\r\n res += a[k][i - 1];\r\n //print('summ', k, i, a[k][i-1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3] + 1) - sum(r, b[1]) === b[3] - b[1] + 1\r\n || sum(c, b[4] + 1) - sum(c, b[2]) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction inc(F, idx, val) {\n for (; idx < F.length; idx |= idx + 1) {\n F[idx] += val\n }\n}\nfunction sum(F, idx) {\n let s = 0\n for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {\n s += F[idx]\n }\n return s\n}\n\nfunction solve(n, qs) {\n const ans = []\n const row = Array(n).fill(0)\n const col = Array(n).fill(0)\n const rf = Array(n + 5).fill(0) // a little larger in case\n const cf = Array(n + 5).fill(0) // a little larger in case\n qs.forEach(([t, x, y, x2, y2]) => {\n x--; y--; x2--; y2--\n if (t === 1) {\n // add\n if (!row[x]++) inc(rf, x, 1)\n if (!col[y]++) inc(cf, y, 1)\n } else if (t === 2) {\n // remove\n if (!--row[x]) inc(rf, x, -1)\n if (!--col[x]) inc(cf, y, -1)\n } else {\n // query\n const nr = x2 - x + 1\n const nc = y2 - y + 1\n const kr = sum(rf, x2) - (x ? sum(rf, x - 1) : 0)\n const kc = sum(cf, y2) - (y ? sum(cf, y - 1) : 0)\n // console.log(nr, nc, '-', kr, kc)\n const ok = nr === kr || nc === kc\n ans.push(ok ? 'Yes' : 'No')\n }\n })\n return ans.join('\\n')\n}\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length - 13; k++) {\r\n //if (i & 1) {\r\n a[k][i] += v;\r\n //}\r\n //print('addd', k, i, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum < ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length - 13; k++) {\r\n if (i & 1) {\r\n res += a[k][i - 1];\r\n //print('summ', k, i, a[k][i-1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3] + 1) - sum(r, b[1]) === b[3] - b[1] + 1\r\n || sum(c, b[4] + 1) - sum(c, b[2]) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length; k++) {\r\n //if (i & 1) {\r\n a[k][i] += v;\r\n //}\r\n //print('addd', k, i>>1, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum <= ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length; k++) {\r\n if (i & 1) {\r\n res += a[k][i];\r\n //print('summ', k, i>>1, a[k][i>>1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3] + 1) - sum(r, b[1]) === b[3] - b[1] + 1\r\n || sum(c, b[4] + 1) - sum(c, b[2]) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length; k++) {\r\n //if (i & 1) {\r\n a[k][i] += v;\r\n //}\r\n //print('addd', k, i>>1, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum <= ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length; k++) {\r\n if (i & 1) {\r\n res += a[k][i];\r\n //print('summ', k, i>>1, a[k][i>>1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3]) - sum(r, b[1] - 1) === b[3] - b[1] + 1\r\n || sum(c, b[4]) - sum(c, b[2] - 1) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length; k++) {\r\n //if (i & 1) {\r\n a[k][i >> 1] += v;\r\n //}\r\n //print('addd', k, i>>1, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum <= ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length; k++) {\r\n if (i & 1) {\r\n res += a[k][i >> 1];\r\n //print('summ', k, i>>1, a[k][i>>1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3]) - sum(r, b[1] - 1) === b[3] - b[1] + 1\r\n || sum(c, b[4]) - sum(c, b[2] - 1) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];\r\nvar rr = Array(n + 1).fill(0);\r\nvar cc = Array(n + 1).fill(0);\r\nvar r = [];\r\nvar c = [];\r\nvar size = 200000;\r\nwhile (size) {\r\n r.push(Array(size + 1).fill(0));\r\n c.push(Array(size + 1).fill(0));\r\n size = (size >> 1);\r\n}\r\nfunction add(a, i, v) {\r\n //print('add',i,v)\r\n for (var k = 0; k < a.length - 13; k++) {\r\n //if (i & 1) {\r\n a[k][i >> 1] += v;\r\n //}\r\n //print('addd', k, i>>1, v);\r\n i >>= 1;\r\n }\r\n}\r\nfunction sum(a, i) {\r\n //print(`sum <= ${i}:`);\r\n var res = 0;\r\n for (var k = 0; k < a.length - 13; k++) {\r\n if (i & 1) {\r\n res += a[k][i >> 1];\r\n //print('summ', k, i>>1, a[k][i>>1]);\r\n }\r\n i >>= 1;\r\n }\r\n //print('sum', res);\r\n return res;\r\n}\r\nfor (var i = 0; i < q; i++) {\r\n var b = readline().split(' ').map(function (v) { return +v; });\r\n //print('i',i);\r\n if (b[0] === 1) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]++;\r\n if (rr[x] === 1) {\r\n add(r, x, 1);\r\n }\r\n cc[y]++;\r\n if (cc[y] === 1) {\r\n add(c, y, 1);\r\n }\r\n }\r\n else if (b[0] === 2) {\r\n var x = b[1];\r\n var y = b[2];\r\n rr[x]--;\r\n if (rr[x] === 0) {\r\n add(r, x, -1);\r\n }\r\n cc[y]--;\r\n if (cc[y] === 0) {\r\n add(c, y, -1);\r\n }\r\n }\r\n else {\r\n if (sum(r, b[3]) - sum(r, b[1] - 1) === b[3] - b[1] + 1\r\n || sum(c, b[4]) - sum(c, b[2] - 1) === b[4] - b[2] + 1) {\r\n print('Yes');\r\n }\r\n else {\r\n print('No');\r\n }\r\n }\r\n}\r\n"}], "src_uid": "bd95629c1698cf1d0cfd338afcf1ca93"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction permute(arr, i) {\n\tif (i == arr.length) {\n\t\tvar num = 0;\n\t\tfor (var j = 0; j < arr.length; j += 1) {\n\t\t\tnum = 10*num + arr[j];\n\t\t}\n\t\tprint(num + ' % 7 = ' + (num%7));\n\t\treturn;\n\t}\n\tpermute(arr, i+1);\n\tvar t = arr[i];\n\tfor (var j = i+1; j < arr.length; j += 1) {\n\t\tarr[i] = arr[j];\n\t\tarr[j] = t;\n\t\tpermute(arr, i+1);\n\t\tarr[j] = arr[i];\n\t}\n\tarr[i] = t;\n}\n\nfunction main() {\n\tvar reverseMod = [1869, 1968, 1689, 6198, 1698, 1986, 1896];\n\tvar s = trim(readline());\n\n\tvar seek1 = true, seek6 = true, seek8 = true, seek9 = true;\n\tvar digits = [];\n\tvar zeros = [];\n\tfor (var i = 0; i < s.length; i += 1) {\n\t\tif (s[i] == '1') {\n\t\t\tif (seek1) {\n\t\t\t\tseek1 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '6') {\n\t\t\tif (seek6) {\n\t\t\t\tseek6 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '8') {\n\t\t\tif (seek8) {\n\t\t\t\tseek8 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '9') {\n\t\t\tif (seek9) {\n\t\t\t\tseek9 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '0') {\n\t\t\tzeros.push('0');\n\t\t\tcontinue;\n\t\t}\n\t\tdigits.push(parseInt(s[i]));\n\t}\n\n\twrite(digits.join(''));\n\n\tvar remainder = 0;\n\tfor (var i = 0; i < digits.length; i += 1) {\n\t\tremainder = (10*remainder + digits[i]) % 7;\n\t}\n\n\tremainder = (10000*remainder) % 7;\n\n\twrite(reverseMod[(7-remainder)%7]);\n\tprint(zeros.join(''));\n}\n\nmain();\n", "positive_code": [{"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var c, i, s, sd, ss, xf, _i, _j, _len;\n\n s = readline();\n\n s = s.replace('1', '').replace('6', '').replace('8', '').replace('9', '');\n\n xf = [1869, 1968, 1689, 6198, 1698, 1986, 1896];\n\n sd = 0;\n\n ss = 1;\n\n for (_i = 0, _len = s.length; _i < _len; _i++) {\n c = s[_i];\n sd = (sd * 10 + (c | 0)) % 7;\n ss = (ss * 10) % 7;\n }\n\n for (i = _j = 0; _j < 7; i = ++_j) {\n if ((i * ss + sd) % 7 === 0) {\n print(\"\" + xf[i] + s);\n break;\n }\n }\n\n}).call(this);\n"}], "negative_code": [{"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var c, i, s, sd, ss, xf, _i, _j, _len;\n\n s = readline();\n\n s = s.replace('1', '').replace('6', '').replace('8', '').replace('9', '');\n\n xf = [1869, 1968, 1689, 6198, 1698, 1986, 1896];\n\n sd = 0;\n\n ss = 10;\n\n for (_i = 0, _len = s.length; _i < _len; _i++) {\n c = s[_i];\n sd = (sd * 10 + (c | 0)) % 7;\n ss = (ss * 10) % 7;\n }\n\n for (i = _j = 0; _j < 7; i = ++_j) {\n if ((i * ss + sd) % 7 === 0) {\n print(\"\" + xf[i] + s);\n break;\n }\n }\n\n}).call(this);\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction permute(arr, i) {\n\tif (i == arr.length) {\n\t\tvar num = 0;\n\t\tfor (var j = 0; j < arr.length; j += 1) {\n\t\t\tnum = 10*num + arr[j];\n\t\t}\n\t\tprint(num + ' % 7 = ' + (num%7));\n\t\treturn;\n\t}\n\tpermute(arr, i+1);\n\tvar t = arr[i];\n\tfor (var j = i+1; j < arr.length; j += 1) {\n\t\tarr[i] = arr[j];\n\t\tarr[j] = t;\n\t\tpermute(arr, i+1);\n\t\tarr[j] = arr[i];\n\t}\n\tarr[i] = t;\n}\n\nfunction main() {\n\tvar mods = [1869, 1968, 1689, 6198, 1698, 1986, 1896];\n\tvar s = trim(readline());\n\n\tvar seek1 = true, seek6 = true, seek8 = true, seek9 = true;\n\tvar remainder = 0;\n\tvar zeros = [];\n\tfor (var i = s.length-1; i >= 0; i -= 1) {\n\t\tif (s[i] == '1') {\n\t\t\tif (seek1) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek1 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '6') {\n\t\t\tif (seek6) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek6 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '8') {\n\t\t\tif (seek8) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek8 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '9') {\n\t\t\tif (seek9) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek9 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '0') {\n\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\tzeros.push('0');\n\t\t\tremainder = (10*remainder) % 7;\n\t\t\tcontinue;\n\t\t}\n\t\tremainder = (10*remainder + s[i]) % 7;\n\t}\n\n\twrite(s);\n\twrite(mods[(7-remainder)%7]);\n\tprint(zeros.join(''));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction permute(arr, i) {\n\tif (i == arr.length) {\n\t\tvar num = 0;\n\t\tfor (var j = 0; j < arr.length; j += 1) {\n\t\t\tnum = 10*num + arr[j];\n\t\t}\n\t\tprint(num + ' % 7 = ' + (num%7));\n\t\treturn;\n\t}\n\tpermute(arr, i+1);\n\tvar t = arr[i];\n\tfor (var j = i+1; j < arr.length; j += 1) {\n\t\tarr[i] = arr[j];\n\t\tarr[j] = t;\n\t\tpermute(arr, i+1);\n\t\tarr[j] = arr[i];\n\t}\n\tarr[i] = t;\n}\n\nfunction main() {\n\tvar mods = [1869, 1968, 1689, 6198, 1698, 1986, 1896];\n\tvar s = trim(readline());\n\n\tvar seek1 = true, seek6 = true, seek8 = true, seek9 = true;\n\tvar zeros = [];\n\tfor (var i = s.length-1; i >= 0; i -= 1) {\n\t\tif (s[i] == '1') {\n\t\t\tif (seek1) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek1 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '6') {\n\t\t\tif (seek6) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek6 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '8') {\n\t\t\tif (seek8) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek8 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '9') {\n\t\t\tif (seek9) {\n\t\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\t\tseek9 = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\telse if (s[i] == '0') {\n\t\t\ts = s.slice(0, i) + s.slice(i+1);\n\t\t\tzeros.push('0');\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\twrite(s);\n\n\tvar remainder = 0;\n\tfor (var i = 0; i < s.length; i += 1) {\n\t\tremainder = (10*remainder + parseInt(s[i])) % 7;\n\t}\n\n\twrite(mods[(7-remainder)%7]);\n\tprint(zeros.join(''));\n}\n\nmain();\n"}], "src_uid": "3b10e984d7ca6d4071fd4e743394bb60"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n probC(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction probC(){\n let t = parseInt(readline());\n while(t > 0){\n t--;\n let count = new Array(100001);\n let n = parseInt(readline());\n let arr = readline().split(' ');\n let max = 0;\n\n for(let i = 0; i < n; i++){\n let index = parseInt(arr[i]);\n if(count[index])\n count[index]++;\n else\n count[index] = 1;\n\n max = Math.max(max, count[index]);\n }\n\n let maxCount = 0;\n for(let i = 0; i < count.length; i++){\n if(count[i] === max)\n maxCount++;\n }\n\n console.log(Math.floor((n-maxCount) / (max-1)) - 1);\n }\n}\n\nfunction main(){\n let n = parseInt(readline());\n let a = readline().split(' ');\n let map = new Array(100000 + 1);\n map.fill(0);\n let count = {'4': 0, '2': 0}; \n for(let i = 0; i < a.length; i++){\n let index = parseInt(a[i]);\n if(map[index]){\n map[index] += 1;\n if(map[index] % 4 === 0)\n count[4] += 1;\n\n if(map[index] % 2 === 0)\n count[2] += 1;\n }\n else\n map[index] = 1;\n }\n\n let o = parseInt(readline());\n for(let i = 0; i < o; i++){\n let x = readline().split(' ');\n if(x[0] === '+'){\n map[parseInt(x[1])] += 1;\n if(map[parseInt(x[1])] % 4 === 0)\n count[4]++;\n\n if(map[parseInt(x[1])] % 2 === 0)\n count[2]++;\n }else{\n let f1 = map[parseInt(x[1])] % 4 === 0;\n let f2 = map[parseInt(x[1])] % 2 === 0;\n map[parseInt(x[1])] -= 1;\n if(f1 && map[parseInt(x[1])] % 4 !== 0)\n count[4]--;\n\n if(f2 && map[parseInt(x[1])] % 2 !== 0)\n count[2]--;\n }\n\n if(count[4] >= 2){\n console.log('yes');\n }else if(count[4] >= 1 && count[2]-(2*count[4]) >= 2){\n console.log('yes');\n }else{\n console.log('no');\n }\n }\n}", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function f(){return h().split(\" \").map((t=>parseFloat(t)))}function c(){return h().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = {}\n// \n// for (let x of a) {\n// m[x] = m[x] + 1 || 1\n// }\n// \n// let v = Object.values(m).sortDesc() as number[]\n// \n// let s = v[0]\n// \n// let i = 1\n// \n// let f = s\n// let c = 0\n// \n// while (v[i] == s) {\n// f += s\n// i++\n// c++\n// }\n// \n// io.puts(c + Math.floor((n - f) / (s - 1)))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;ot-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(i=o.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),o.default.writeFileSync(\"output.txt\",l),console.log(l),o.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{s+=t})),process.stdin.on(\"end\",(e=>{i=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let a = io.nextNumbers()\n// \n// let m = {}\n// \n// for (let x of a) {\n// m[x] = m[x] + 1 || 1\n// }\n// \n// let v = Object.values(m).sortDesc() as number[]\n// \n// let s = v[0]\n// \n// let i = 1\n// \n// let f = s\n// let c = 0\n// \n// u\n// \n// while (v[i] == s) {\n// f += s\n// i++\n// c++\n// }\n// \n// // io.debug(f)\n// \n// io.puts(Math.floor((n - f + c) / (s - 1)))\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "9d480b3979a7c9789fd8247120f31f03"} {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = 1;\r\n while (t--) {\r\n let [n, q, k] = iInpArr();\r\n let arr = iInpArr(),\r\n objA = [];\r\n for (let i = 0; i < n; i++) {\r\n let a = arr[i] - 1,\r\n d = k - arr[i],\r\n b,\r\n c;\r\n if (i === 0) b = 0;\r\n else b = arr[i] - arr[i - 1] - 1;\r\n if (i === n - 1) c = 0;\r\n else c = arr[i + 1] - arr[i] - 1;\r\n objA[i] = { a, b, c, d };\r\n }\r\n let frd = {},\r\n sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n sum += objA[i].b + objA[i].c;\r\n frd[i] = sum;\r\n }\r\n for (let i = 0; i < q; i++) {\r\n let [s, e] = iInpArr();\r\n s--;\r\n e--;\r\n if (s === e) console.log(objA[s].a + objA[s].d);\r\n else if (s + 1 === e)\r\n console.log(objA[s].a + objA[e].d + objA[s].c + objA[e].b);\r\n else {\r\n let sum = 0;\r\n sum += frd[e - 1] - frd[s];\r\n sum += objA[s].a + objA[e].d + objA[s].c + objA[e].b;\r\n console.log(sum);\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // let testCases = readline()\n // while(testCases--)\n solve()\n \n}\n\n// function to solve problems\nfunction solve (){\n let [n,q,k] = readline().split(' ').map(x => +x)\n // let q = arr[1], k = arr[2]\n let myArr = readline().split(' ').map(x => +x)//new Array(n)\n\n // readline().split(' ').map((x,i) => {\n // myArr[i] = +x\n // })\n\n // ====== SOLUTION ======\n while(q--) {\n let [l,r] = readline().split(' ').map(x => +x)\n let arrLen = r - l + 1\n let ans = 0\n\n ans += myArr[l-1] - 1 // * true\n\n ans += 2*((myArr[r-1] - myArr[l-1] + 1) - arrLen)\n\n // checkbackward of last Element\n ans += k - myArr[r-1] // * true\n console.log(ans)\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // let testCases = readline()\n // while(testCases--)\n solve()\n \n}\n\n// function to solve problems\nfunction solve (){\n let [n,q,k] = readline().split(' ').map(x => +x)\n // let q = arr[1], k = arr[2]\n let myArr = new Array(n)\n\n readline().split(' ').map((x,i) => {\n myArr[i] = +x\n })\n\n // ====== SOLUTION ======\n while(q--) {\n let [l,r] = readline().split(' ').map(x => +x)\n let arrLen = r - l + 1\n let ans = 0\n\n ans += myArr[l-1] - 1 // * true\n\n ans += 2*((myArr[r-1] - myArr[l-1] + 1) - arrLen)\n\n // checkbackward of last Element\n ans += k - myArr[r-1] // * true\n console.log(ans)\n }\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, q, k] = rna();\r\n\tlet a = rna();\r\n\r\n\tfor (let i = 0; i < q; i++) {\r\n\t\tlet [l, r] = rna();\r\n\t\tl--;r--;\r\n\r\n\t\tans = 2 * (a[r] - a[l] - r + l ) + a[l] - 1 + k - a[r];\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet [n, q, k] = rna();\r\n\tlet a = rna();\r\n\r\n\tlet sum = [0];\r\n\tfor (let i = 1; i < n; i++) {\r\n\t\tsum[i] = sum[i-1] + a[i] - a[i-1] - 1;\r\n\t}\r\n\r\n\tfor (let i = 0; i < q; i++) {\r\n\t\tlet [l, r] = rna();\r\n\t\tl--;r--;\r\n\r\n\t\tans = 2 * (sum[r] - sum[l]) + a[l] - 1 + k - a[r];\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n var [n, q, k] = readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n return parseInt(x)\r\n })\r\n var a = new Array(n + 1)\r\n readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n a[i + 1] = x\r\n })\r\n var answer = 0\r\n for (var i = 0; i < q; i++) {\r\n var [l, r] = readline().split(' ').map((x, i) => {\r\n // if (minA > Number(x)) minA = Number(x)\r\n return parseInt(x)\r\n })\r\n answer = (a[l] - 1 + k-a[r]) + 2 * (a[r] - a[l] + 1 - r + l - 1)\r\n console.log(answer)\r\n }\r\n}\r\n\r\nfunction swap(a, b) {\r\n var c = a\r\n a = b\r\n b = c\r\n}\r\n"}], "negative_code": [], "src_uid": "740d2aba32f69b8cfe8f7cb624621a63"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar isOK = false;\r\n\t\tfor(var j = 1; j * j <= N; j++){\r\n\t\t\tif(j * j * 2 == N || j * j * 4 == N){\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nlet obj = {};\r\nconst precompute = () => {\r\n let n = 50000;\r\n for (let i = 1; i <= n; i++) obj[i * i] = 1;\r\n};\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n precompute();\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n % 2) {\r\n console.log(\"NO\");\r\n continue;\r\n }\r\n let k = n / 2;\r\n if (obj[k]) console.log(\"YES\");\r\n else if (obj[k / 2]) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = Math.floor(Math.sqrt(b/2))\r\n var d = Math.floor(Math.sqrt(b/4))\r\n print(c * c * 2 == b || d * d * 4 == b ?\"YES\":\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\nfunction main() {\r\n let a = parseInt(readline());\r\n while (a--) {\r\n let b = parseInt(readline());\r\n let c = Math.floor(Math.sqrt(b / 2));\r\n let d = Math.floor(Math.sqrt(b / 4));\r\n print(c * c * 2 == b || d * d * 4 == b ? \"YES\" : \"NO\");\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 1) console.log(\"NO\");\r\n else if (n === 3) console.log(\"NO\");\r\n else if (n === 2) console.log(\"YES\");\r\n else {\r\n while (n > 2) n = Math.floor(n / 2);\r\n if (n === 1) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n if (n === 1) console.log(\"NO\");\r\n if (n === 3) console.log(\"NO\");\r\n if (n === 2) console.log(\"YES\");\r\n else {\r\n while (n > 2) n = Math.floor(n / 2);\r\n if (n === 1) console.log(\"NO\");\r\n else console.log(\"YES\");\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = Math.floor(Math.sqrt(b/2))\r\n var d = Math.floor(Math.sqrt(b/4))\r\n print(d)\r\n print(c * c * 2 == b || d * d * 4 == b ?\"YES\":\"NO\")\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\nfunction main() {\r\n var a = parseInt(readline())\r\n while(a--){\r\n var b = parseInt(readline())\r\n var c = Math.sqrt(b/2)\r\n var d = Math.sqrt(b/4)\r\n print(c * c * 2 == b || d * d * 4 == b ?\"YES\":\"NO\")\r\n }\r\n}"}], "src_uid": "6ae754639d96790c890f9d1ab259332a"} {"source_code": "\"use strict\";\n\nfunction answer(wordLength, bigrams) {\n let lastBigram = null;\n let word = '';\n for (let i = 0; i < bigrams.length; i += 1) {\n const bigram = bigrams[i];\n if (lastBigram === null) {\n word += bigram;\n lastBigram = bigram;\n continue;\n }\n\n if (lastBigram[1] !== bigram[0]) {\n word += bigram;\n } else {\n word += bigram[1];\n }\n lastBigram = bigram;\n }\n\n if (word.length < wordLength) {\n word += 'a';\n }\n\n return word;\n}\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const wordLength = this.readline();\n const bigrams = this.readline().split(\" \");\n const result = answer(wordLength, bigrams);\n this.print(result)\n}", "positive_code": [{"source_code": " // your code goes here\r\n const fs = require('fs');\r\n const input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n let currentline = 0;\r\n function readline(){\r\n return input[currentline++];\r\n }\r\n var T = readline();\r\n for(var q =1;q<=T;q++) {\r\n var n = readline()\r\n var ar = readline().split(' ')\r\n var anc = ''\r\n anc += ar[0][0]\r\n if(2*ar.length < n) {\r\n \tanc += ar[0][1]\r\n \tfor(var i=1;i buffer += c);\r\nprocess.stdin.on('end', () => {\r\n const { EOL } = require('os');\r\n const lines = buffer.split(EOL);\r\n lines.pop();\r\n\r\n main(lines);\r\n});\r\n\r\nfunction main(lines) {\r\n let T = Number(lines[0]);\r\n let index = 1;\r\n let N, arr;\r\n\r\n while (T--) {\r\n N = Number(lines[index++]);\r\n arr = lines[index++].split(' ');\r\n solve(N, arr);\r\n }\r\n}\r\n\r\nfunction solve(N, input) {\r\n let arr = [input[0]];\r\n let result = '';\r\n \r\n for (let i = 1; i < input.length; ++i) {\r\n if (input[i][0] !== input[i - 1][1]) {\r\n arr.push(input[i - 1][1] + input[i][0]);\r\n }\r\n \r\n arr.push(input[i]);\r\n }\r\n\r\n if (arr.length !== N - 1) {\r\n arr.push(arr[arr.length - 1][1] === 'a' ? 'ab' : 'ba');\r\n }\r\n \r\n result = arr[0];\r\n \r\n for (let i = 1; i < arr.length; ++i) {\r\n result += arr[i][1];\r\n }\r\n\r\n console.log(result);\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst bgs = rl().split(' ');\r\n\r\n\t\tlet ans = '';\r\n\t\tfor (const bg of bgs) {\r\n\t\t\tif (ans.slice(-1) == bg[0])\r\n\t\t\t\tans += bg[1];\r\n\t\t\telse\r\n\t\t\t\tans += bg;\r\n\t\t}\r\n\r\n\t\tif (ans.length < n) \r\n\t\t\tans += 'a';\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet n = nl.num();\n\t\tlet a = nl.array();\n\t\tlet r = [];\n\t\tfor(let j = 0; j < n - 2; j++){\n\t\t\tif (j == 0){\n\t\t\t\tr.push(a[j].charAt(0));\n\t\t\t\tr.push(a[j].charAt(1));\n\t\t\t} else {\n\t\t\t\tif (a[j-1].charAt(1) != a[j].charAt(0)){\n\t\t\t\t\tr.push(a[j].charAt(0));\n\t\t\t\t} \n\t\t\t\tr.push(a[j].charAt(1));\n\t\t\t}\n\t\t}\n\t\tif (r.length < n){\n\t\t\tr.push(r[r.length -1]);\n\t\t}\n\t\tans.push(r.join(''));\n\t\t\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "// let s = ['ab', 'bb', 'ba', 'aa', 'ba'];\r\n// let k = 7;\r\n// let s = ['aa'];\r\n// let k = 3;\r\nlet n = null, m = null, a=[], b=[];\r\nconst readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n \r\nreadline.on('line', line => {\r\n if (n == null) {\r\n n = parseInt(line)\r\n m = n * 2\r\n } else if (m>0) {\r\n if (m%2==0)\r\n b.push(parseInt(line))\r\n else \r\n a.push(line.split(' '))\r\n m--;\r\n\r\n } \r\n if (m == 0) {\r\n readline.close();\r\n main();\r\n } \r\n});\r\n\r\nfunction main(){\r\n a.forEach((s,j)=> {\r\n let res = \"\";\r\n for (let i = 0 ; i < s.length-1; i++) {\r\n if (s[i][1] == s[i+1][0]) res+=s[i][0];\r\n else res += s[i];\r\n }\r\n res += s.pop();\r\n if (res.length < b[j]) res+='a'; \r\n console.log(res)\r\n });\r\n}\r\n// main();\r\n\r\n// 'ab' 'bb' 'ba' 'aa' 'ab' 'ba'\r\n// 'ab' 'bb' 'ba' 'aa' 'ba'\r\n// 'a' 'b' 'b' 'aa' 'ba'\r\n// 'a' 'b' 'b' 'aa' 'ba'\r\n// abbaaba\r\n\r\n\r\n// bbabb\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' '))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction solve([n], arr) {\r\n let res = '', flag = false\r\n res += arr[0][0]\r\n for (let i = 0; i < n - 3; i++) {\r\n if (arr[i][1] != arr[i + 1][0]) {\r\n res += arr[i][1];\r\n res += arr[i + 1][0];\r\n flag = true;\r\n } else {\r\n res += arr[i + 1][0];\r\n }\r\n }\r\n res += arr[n - 3][1]\r\n if (!flag) {\r\n res += arr[n - 3][1];\r\n }\r\n console.log(res)\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextStrArray(N - 2);\r\n\t\tvar ok = false;\r\n\t\tvar output = list[0][0];\r\n\t\tfor(var i = 0; i < N - 3; i++){\r\n\t\t\toutput += list[i][1];\r\n\t\t\tif(list[i][1] != list[i + 1][0]){\r\n\t\t\t\toutput += list[i + 1][0];\r\n\t\t\t\tok = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\toutput += list[N - 3][1];\r\n\t\tif(!ok){\r\n\t\t\toutput += \"a\";\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": " var len = readline();\r\n for(var i=0;i<+len;i++)\r\n {\r\n var lenth = readline();\r\n var inputData = readline().split(' ');\r\n var str ='';\r\n for(var j=0;j2)\r\n //{\r\n // str+=inputData[i]+'a';\r\n ////}\r\n //else{\r\n if(str[str.length-1] != inputData[j][0])\r\n str+=inputData[j];\r\n else\r\n str+=inputData[j][1];\r\n \r\n // }\r\n }\r\n if(str.length < lenth)\r\n print(str+'a');\r\n else \r\n print(str);\r\n\r\n}\r\n"}, {"source_code": "var s = parseInt(readline());\r\n while (s--) {\r\n var n = parseInt(readline());\r\n var str = readline().split(\" \");\r\n var string = str[0];\r\n for (var i = 1; i < str.length; i++) {\r\n var st = str[i];\r\n if (string[string.length - 1] === st[0]) {\r\n string += st[1];\r\n } else {\r\n string += st;\r\n }\r\n }\r\n if (string.length < n) {\r\n string += \"a\";\r\n }\r\n print(string);\r\n }"}, {"source_code": "\"use strict\";\n\nfunction answer(s) {\n if (s.length > 10) return s[0] + (s.length - 2) + s[s.length - 1];\n return s;\n}\n\nconst nQueues = this.readline().split(\" \");\n\nfor (let i = 0; i < nQueues; i++) {\n const length = Number(this.readline());\n const bigrams = this.readline().split(' ');\n let word = ''\n let found = false\n for(let i= 0; i< bigrams.length-1; i++) {\n const a = bigrams[i]\n const b = bigrams[i+1]\n if(a[1] === b[0]){\n word+= a[0]\n } else {\n found = true\n word+= a\n }\n }\n word+= bigrams[bigrams.length-1]\n if(!found) word+='a'\n this.print(word)\n}\n"}], "negative_code": [{"source_code": "// your code goes here\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nvar T = readline();\r\nfor(var q =1;q<=T;q++) {\r\n var n = readline()\r\n var a = readline().split(' ')\r\n var ans = ''\r\n var anc = ''\r\n for(var i=0;i2)\r\n {\r\n str+=inputData[i]+'a';\r\n }\r\n else{\r\n if(str[str.length-1] != inputData[j][0])\r\n str+=inputData[j];\r\n else\r\n str+=inputData[j][1];\r\n }\r\n }\r\n print(str);\r\n\r\n}\r\n"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var lenth = readline();\r\n var inputData = readline().split(' ');\r\n var str ='';\r\n for(var j=0;j2)\r\n {\r\n str+=inputData[i]+'a';\r\n }\r\n else{\r\n if(str[str.length-1] != inputData[j][0])\r\n str+=inputData[j];\r\n else\r\n str+inputData[j][1];\r\n }\r\n }\r\n print(str);\r\n\r\n}\r\n"}, {"source_code": "var len = readline();\r\nfor(var i=0;i<+len;i++)\r\n{\r\n var lenth = readline();\r\n var inputData = readline().split(' ');\r\n var str ='';\r\n for(var j=0;j=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\tvec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t}\n\tprint(vec[i]);\n}", "positive_code": [{"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar vec=[];\nvec[0]=Number(r);\nprint(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\tvec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t}\n\tprint(vec[i]);\n}"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\n{\n var kr = readline,\n chr = String.fromCodePoint,\n ord = function ord(v, i) {\n return v.charCodeAt(i);\n };\n var krr = function krr() {\n var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';\n return kr().split(sp);\n };\n var S = String,\n N = Number,\n A = function A() {\n for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {\n a[_key] = arguments[_key];\n }\n\n return new (Function.prototype.bind.apply(Array, [null].concat(a)))();\n };\n var kt = function kt(m, d) {\n return d.map(function (v, i) {\n return m[i](v);\n });\n };\n //////////////////////////////////////////////////////////////////////////////\n var dist = function dist(x1, y1, x2, y2) {\n return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n };\n var gp = function gp(x, y, r, x2) {\n var v = Math.pow(r, 2) - Math.pow(x - x2, 2);\n if (v < 0) return 0;\n return Math.sqrt(v) + y;\n };\n\n var _kt = kt([N, N], krr()),\n _kt2 = _slicedToArray(_kt, 2),\n n = _kt2[0],\n r = _kt2[1];\n\n var l = krr().map(N),\n SZ = 1000;\n var d = A(SZ),\n xx = A();\n for (var i = 0; i < 2000; i++) {\n xx[i] = A();\n }l.forEach(function (x, i) {\n var y = r;\n\n var _loop = function _loop(xi) {\n xx[xi].forEach(function (yi) {\n y = Math.max(y, gp(xi, yi, 2 * r, x));\n });\n };\n\n for (var xi = Math.max(1, x - r * 3); xi <= Math.min(1000, x + r * 3); xi++) {\n _loop(xi);\n }\n xx[x].push(y);\n d[i] = y;\n });\n print(d.slice(0, n).join(' '));\n}\n"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\n{\n var kr = readline,\n chr = String.fromCodePoint,\n ord = function ord(v, i) {\n return v.charCodeAt(i);\n };\n var krr = function krr() {\n var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';\n return kr().split(sp);\n };\n var S = String,\n N = Number,\n A = function A() {\n for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {\n a[_key] = arguments[_key];\n }\n\n return new (Function.prototype.bind.apply(Array, [null].concat(a)))();\n };\n var M = function M(l, f) {\n var r = A(l);for (var i = 0; i < l; i++) {\n r[i] = f(i);\n }return r;\n };\n var kt = function kt(m, d) {\n return d.map(function (v, i) {\n return m[i](v);\n });\n };\n //////////////////////////////////////////////////////////////////////////////\n var dist = function dist(x1, y1, x2, y2) {\n return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n };\n var gp = function gp(x, y, r, x2) {\n var v = Math.pow(r, 2) - Math.pow(x - x2, 2);\n if (v < 0) return 0;\n return Math.sqrt(v) + y;\n };\n\n var _kt = kt([N, N], krr()),\n _kt2 = _slicedToArray(_kt, 2),\n n = _kt2[0],\n r = _kt2[1];\n\n var l = krr().map(N),\n SZ = 1100;\n var d = A(SZ),\n xx = M(SZ, function () {\n return A();\n });\n\n l.forEach(function (x, i) {\n var y = r;\n\n var _loop = function _loop(xi) {\n xx[xi].forEach(function (yi) {\n y = Math.max(y, gp(xi, yi, 2 * r, x));\n });\n };\n\n for (var xi = Math.max(1, x - r * 2); xi < Math.min(SZ, x + r * 2 + 1); xi++) {\n _loop(xi);\n }\n xx[x].push(y);\n d[i] = y;\n });\n print(d.slice(0, n).join(' '));\n}\n"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nvec[0]=Number(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tvec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t} \n\tif(hit===false){\n\t\tvec[i]=Number(r);\n\t}\n\tans+=\" \"+vec[i];\n}\nprint(ans);"}], "negative_code": [{"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\n{\n var kr = readline,\n chr = String.fromCodePoint,\n ord = function ord(v, i) {\n return v.charCodeAt(i);\n };\n var krr = function krr() {\n var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';\n return kr().split(sp);\n };\n var S = String,\n N = Number,\n A = function A() {\n for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {\n a[_key] = arguments[_key];\n }\n\n return new (Function.prototype.bind.apply(Array, [null].concat(a)))();\n };\n var M = function M(l, f) {\n var r = A(l);for (var i = 0; i < l; i++) {\n r[i] = f(i);\n }return r;\n };\n var kt = function kt(m, d) {\n return d.map(function (v, i) {\n return m[i](v);\n });\n };\n //////////////////////////////////////////////////////////////////////////////\n var dist = function dist(x1, y1, x2, y2) {\n return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n };\n var gp = function gp(x, y, r, x2) {\n var v = Math.pow(r, 2) - Math.pow(x - x2, 2);\n if (v < 0) return 0;\n return Math.sqrt(v) + y;\n };\n\n var _kt = kt([N, N], krr()),\n _kt2 = _slicedToArray(_kt, 2),\n n = _kt2[0],\n r = _kt2[1];\n\n var l = krr().map(N),\n SZ = 1100;\n var d = A(SZ),\n xx = M(SZ, function () {\n return A();\n });\n\n l.forEach(function (x, i) {\n var y = r;\n\n var _loop = function _loop(xi) {\n xx[xi].forEach(function (yi) {\n y = Math.max(y, gp(xi, yi, 2 * r, x));\n });\n };\n\n for (var xi = Math.max(1, x - r * 2); xi < Math.min(SZ, x + r * 2); xi++) {\n _loop(xi);\n }\n xx[x].push(y);\n d[i] = y;\n });\n print(d.slice(0, n).join(' '));\n}\n"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\n{\n var kr = readline,\n chr = String.fromCodePoint,\n ord = function ord(v, i) {\n return v.charCodeAt(i);\n };\n var krr = function krr() {\n var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';\n return kr().split(sp);\n };\n var S = String,\n N = Number,\n A = function A() {\n for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {\n a[_key] = arguments[_key];\n }\n\n return new (Function.prototype.bind.apply(Array, [null].concat(a)))();\n };\n var kt = function kt(m, d) {\n return d.map(function (v, i) {\n return m[i](v);\n });\n };\n //////////////////////////////////////////////////////////////////////////////\n var dist = function dist(x1, y1, x2, y2) {\n return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n };\n var gp = function gp(x, y, r, x2) {\n return Math.sqrt(Math.pow(r, 2) - Math.pow(x - x2, 2)) + y;\n };\n\n var _kt = kt([N, N], krr()),\n _kt2 = _slicedToArray(_kt, 2),\n n = _kt2[0],\n r = _kt2[1];\n\n var l = krr().map(N),\n SZ = 2000;\n var d = A(SZ),\n xx = A();\n for (var i = 0; i < SZ; i++) {\n xx[i] = A();\n }l.forEach(function (x, i) {\n var y = r;\n\n var _loop = function _loop(xi) {\n xx[xi].forEach(function (yi) {\n y = Math.max(y, gp(xi, yi, 2 * r, x));\n });\n };\n\n for (var xi = Math.max(0, x - r * 2); xi < Math.min(SZ, x + r * 2); xi++) {\n _loop(xi);\n }\n xx[x].push(y);\n d[i] = y;\n });\n print(d.slice(0, n).join(' '));\n}\n"}, {"source_code": "'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\n{\n var kr = readline,\n chr = String.fromCodePoint,\n ord = function ord(v, i) {\n return v.charCodeAt(i);\n };\n var krr = function krr() {\n var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';\n return kr().split(sp);\n };\n var S = String,\n N = Number,\n A = function A() {\n for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {\n a[_key] = arguments[_key];\n }\n\n return new (Function.prototype.bind.apply(Array, [null].concat(a)))();\n };\n var kt = function kt(m, d) {\n return d.map(function (v, i) {\n return m[i](v);\n });\n };\n //////////////////////////////////////////////////////////////////////////////\n var dist = function dist(x1, y1, x2, y2) {\n return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));\n };\n var gp = function gp(x, y, r, x2) {\n return Math.sqrt(Math.pow(r, 2) - Math.pow(x - x2, 2)) + y;\n };\n\n var _kt = kt([N, N], krr()),\n _kt2 = _slicedToArray(_kt, 2),\n n = _kt2[0],\n r = _kt2[1];\n\n var l = krr().map(N),\n SZ = 2000;\n var d = A(SZ),\n xx = A();\n for (var i = 0; i < SZ; i++) {\n xx[i] = A();\n }l.forEach(function (x, i) {\n var y = r;\n\n var _loop = function _loop(xi) {\n xx[xi].forEach(function (yi) {\n y = Math.max(y, gp(xi, yi, 2 * r, x));\n });\n };\n\n for (var xi = Math.max(0, x - r * 3); xi < Math.min(SZ, x + r * 3); xi++) {\n _loop(xi);\n }\n xx[x].push(y);\n d[i] = y;\n });\n print(d.slice(0, n).join(' '));\n}\n"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tprint((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t} \n\tif(hit===false){\n\t\tans+=\" \"+Number(r);\n\t\tprint(r);\n\t\tvec.push(r);\n\t}\n}"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t}\n\tif(hit==false){\n\t\tans+=\" \"+r;\n\t\tvec.push(r);\n\t}\n}\nprint(ans);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nprint(s);\nvar ans=r+\"\";\nvar vec=[];\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t}\n\tif(hit==false){\n\t\tans+=\" \"+r;\n\t\tvec.push(r);\n\t}\n}\nprint(ans);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\ts+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t}\n\tif(hit==false){\n\t\ts+=\" \"+r;\n\t\tvec.push(r);\n\t}\n}"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nprint(n+\" \"+r);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tprint((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]));\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]);\n\t} \n\tif(hit===false){\n\t\tans+=\" \"+ +r;\n\t\tprint(r);\n\t\tvec.push(r);\n\t}\n}"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec[0]=r;\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tvec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t} \n\tif(hit===false){\n\t\tvec[i]=r;\n\t}\n\tans+=\" \"+vec[i];\n}\nprint(ans);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>=r*2)continue;\n\t\thit=true;\n\t\tprint((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t\tbreak;\n\t} \n\tif(hit===false){\n\t\tans+=\" \"+Number(r);\n\t\tprint(r);\n\t\tvec.push(r);\n\t}\n}"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nvec[0]=Number(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tvec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t} \n\tif(hit===false){\n\t\tvec[i]=Number(r);\n\t}\n\tans+=\" \"+vec[i];\n}\nprint(ans);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tprint((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]));\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t}\n\tif(hit===false){\n\t\tans+=\" \"+r;\n\t\tprint(r);\n\t\tvec.push(r);\n\t}\n}"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\ts+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);\n\t}\n\tif(hit==false){\n\t\ts+=\" \"+r;\n\t\tvec.push(r);\n\t}\n}\nprint(s);"}, {"source_code": "var s = readline().split(' ');\nn=s[0];\nr=s[1];\nvar s = readline().split(' ');\nvar ans=r+\"\";\nvar vec=[];\nprint(r);\nvec.push(r);\nfor(i=1;i=0;j--){\n\t\tif(Math.abs(s[i]-s[j])>r*2)continue;\n\t\thit=true;\n\t\tprint((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));\n\t\tans+=\" \"+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t\tvec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));\n\t\tbreak;\n\t} \n\tif(hit===false){\n\t\tans+=\" \"+Number(r);\n\t\tprint(r);\n\t\tvec.push(r);\n\t}\n}"}], "src_uid": "3cd019d1016cb3b872ea956c312889eb"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 1e9 + 7;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [N, K] = rna();\r\n\r\n\t\t/*\r\n\t\t const dp = Array.from(Array(n+1), x => []);\r\n\t\t function f (i, k) {\r\n\t\t if (dp[i][k]) return dp[i][k];\r\n\t\t console.log({i, k})\r\n\t\t if (i == 0) return 1;\r\n\t\t if (k > 1) return dp[i][k] = (f(i-1, k) + f(n-i, k-1)) % MOD;\r\n\t\t else return dp[i][k] = f(i-1, k) % MOD;\r\n\t\t }\r\n\t\t */\r\n\r\n\t\tconst dp = Array.from(Array(N+1), x => Array(K+1).fill(0));\r\n\t\tfor (let k = 1; k <= K; k++) {\r\n\t\t\tdp[0][k] = 1;\r\n\t\t}\r\n\t\tfor (let k = 1; k <= K; k++) {\r\n\t\t\tfor (let n = 1; n <= N ; n++) {\r\n\t\t\t\tdp[n][k] = (dp[n-1][k] + dp[N-n][k-1]) % MOD; \r\n\t\t\t}\r\n\t\t}\r\n\t\tconst ans = dp[N][K];\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar mod = 1000000007;\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar output = 1;\r\n\t\tif(K == 1){\r\n\t\t\tmyout(output);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(N == 1){\r\n\t\t\tmyout(2);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\toutput++;\r\n\t\tN--;\r\n\t\tvar list = new Array(N).fill(0);\r\n\t\tlist[0] = 1;\r\n\t\tvar isL = true;\r\n\t\twhile(K > 1){\r\n\t\t\tif(!isL){\r\n\t\t\t\tfor(var k = N - 2; k >= 0; k--){\r\n\t\t\t\t\tlist[k] += list[k + 1];\r\n\t\t\t\t\tlist[k] %= mod;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tfor(var k = 1; k < N; k++){\r\n\t\t\t\t\tlist[k] += list[k - 1];\r\n\t\t\t\t\tlist[k] %= mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor(var k = 0; k < N; k++){\r\n\t\t\t\toutput += list[k];\r\n\t\t\t\toutput %= mod;\r\n\t\t\t}\r\n\t\t\tK--;\r\n\t\t\tisL = !isL;\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 1001\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const x = readline();\r\n var toPrint = ''\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n if (k === 1) return toPrint += 1 + '\\n'\r\n\r\n var dp = new Array(k)\r\n for (let j = 0; j < k; j++) {\r\n dp[j] = new Array(n).fill(0)\r\n }\r\n for (let j = 0; j < n; j++) {\r\n dp[0][j] = 1\r\n }\r\n for (let j = 0; j < k - 2; j++) {\r\n if (j % 2 === 0) {\r\n var sum = 0\r\n for (let i = 0; i < n; i++) {\r\n dp[j + 1][i] = sum\r\n sum += dp[j][i]\r\n sum = sum % mod\r\n }\r\n } else {\r\n sum = 0\r\n for (let i = n - 1; i >= 0; i--) {\r\n dp[j + 1][i] = sum\r\n sum += dp[j][i]\r\n sum = sum % mod\r\n }\r\n }\r\n }\r\n\r\n var ans = 1\r\n for (let j = 0; j < k - 1; j++) {\r\n for (let i = 0; i < n; i++) {\r\n // console.log(ans, dp[j][i])\r\n ans = (ans + dp[j][i]) % mod\r\n }\r\n }\r\n toPrint += ans.toString() + '\\n'\r\n // console.log(dp)\r\n })\r\n console.log(toPrint)\r\n\r\n\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nconst MOD = 1e9 + 7;\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [N, K] = rna();\r\n\r\n\t\tconst dp = Array.from(Array(N+1), x => Array(K+1));\r\n\t\tfor (let n = 0; n <= N; n++) {\r\n\t\t\tdp[n][0] = 0;\r\n\t\t}\r\n\t\tfor (let k = 1; k <= K; k++) {\r\n\t\t\tdp[0][k] = 1;\r\n\t\t}\r\n\t\tfor (let k = 1; k <= K; k++) {\r\n\t\t\tfor (let n = 1; n <= N ; n++) {\r\n\t\t\t\tdp[n][k] = (dp[n-1][k] + dp[N-n][k-1]) % MOD; \r\n\t\t\t}\r\n\t\t}\r\n\t\tconst ans = dp[N][K];\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 1001\r\nvar mod = 1000000007n\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const x = readline();\r\nvar toPrint = ''\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n // const a = parseInt(readline());\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return BigInt(x)\r\n });\r\n if (k === 1n) return console.log(1)\r\n var dp = new Array(k)\r\n for (let j = 0n; j < k; j++) {\r\n dp[j] = new Array(n).fill(0n)\r\n }\r\n for (let j = 0n; j < n; j++) {\r\n dp[0][j] = 1n\r\n }\r\n for (let j = 0n; j < k - 2n; j++) {\r\n if (j % 2n === 0n) {\r\n var sum = 0n\r\n for (let i = 0n; i < n; i++) {\r\n dp[j + 1n][i] = sum\r\n sum += dp[j][i]\r\n sum = sum % mod\r\n }\r\n } else {\r\n sum = 0n\r\n for (let i = n - 1n; i >= 0n; i--) {\r\n dp[j + 1n][i] = sum\r\n sum += dp[j][i]\r\n sum = sum % mod\r\n }\r\n }\r\n }\r\n\r\n var ans = 1n\r\n for (let j = 0n; j < k - 1n; j++) {\r\n for (let i = 0n; i < n; i++) {\r\n // console.log(ans, dp[j][i])\r\n ans = (ans + dp[j][i]) % mod\r\n }\r\n }\r\n toPrint += ans.toString() + '\\n'\r\n // console.log(dp)\r\n })\r\n console.log(toPrint)\r\n\r\n\r\n\r\n}\r\n"}], "src_uid": "9414b6420748f14fd84b44ddd12af68c"} {"source_code": "\nfunction main()\n{\n\nString.prototype.replaceAt = function(index, character) {\n return this.substr(0, index) + character + this.substr(index+character.length);\n}\n\nvar n = parseInt( readline() );\nvar s = readline();\n\nif ( n%4 > 0 )\n{\n\tprint( \"===\" );\n\treturn;\n}\n\nvar q = 0;\nvar a = [];\na['A'] = a['C'] = a['G'] = a['T'] = 0;\n\n\nfor ( var i = 0 ; i < n ; i++ )\n{\n\tif ( s[i] == '?' )\n\t\tq++;\n\telse\n\t\ta[ s[i] ]++;\n}\n\nvar e = n / 4;\nif ( a['A'] > e || a['C'] > e || a['G'] > e || a['T'] > e )\n{\n\tprint( \"===\" );\n\treturn;\n}\n\n\nvar ans = \"\";\nfor ( var i=0 ; i desiredCount) {\n return NOT_FOUND;\n } \n }\n var result = \"\";\n for (i = 0; i < genom.length; i++) {\n if (letters.indexOf(genom[i]) === -1) {\n var curLetter = letters.filter(function (s) {\n return count[s] < desiredCount;\n })[0];\n result += curLetter;\n count[curLetter]++;\n } else {\n result += genom[i];\n } \n }\n return result;\n}\n\nvar n = parseInt(readline());\nvar s = readline();\nprint(reconstruct(s));\n"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n = null;\nlet genome = [];\nlet map = {\n 'A': 0,\n 'C': 0,\n 'G': 0,\n 'T': 0,\n '?': 0\n};\n\nreadline.on('line', line => {\n\n if (!n)\n n = line;\n else {\n genome = line.split('');\n readline.close();\n }\n})\n\nreadline.on('close', () => {\n\n genome.map(char => {\n map[char] = ++map[char];\n })\n\n let max = n / 4;\n\n let word = genome.join('');\n\n Object.keys(map).forEach(key => {\n if (key === '?') return;\n while (map['?'] > 0 && map[key] < max) {\n map[key] = ++map[key];\n map['?']--;\n word = word.replace('?', key);\n }\n })\n\n let cumple = true;\n Object.keys(map).forEach(key => {\n if (key !== '?' && map[key] < max) {\n cumple = false;\n }\n })\n if (word.includes('?') || !cumple)\n return console.log('===');\n console.log(word);\n})"}, {"source_code": "var memo = {\n A: 0,\n G: 0,\n C: 0,\n T: 0,\n '?': 0\n};\n\nvar memo2 = {\n A: 0,\n G: 0,\n C: 0,\n T: 0\n};\n\nfunction max() {}\n\nfunction resolve(s) {\n for (var i = 0; i < s.length; i++) {\n memo[s[i]]++;\n }\n var max = 0;\n for (var key in memo) {\n if (key !== '?' && memo[key] > max) {\n max = memo[key];\n }\n }\n var sum = 0;\n for (var key in memo) {\n if (key !== '?') {\n sum += max - memo[key];\n memo2[key] = max - memo[key];\n }\n }\n if (memo['?'] < sum) {\n return '===';\n }\n if ((memo['?'] - sum) % 4 !== 0) {\n return '===';\n } else {\n memo2.A += (memo['?'] - sum) / 4;\n memo2.G += (memo['?'] - sum) / 4;\n memo2.C += (memo['?'] - sum) / 4;\n memo2.T += (memo['?'] - sum) / 4;\n }\n var res = '';\n for (var i = 0; i < s.length; i++) {\n if (s[i] === '?') {\n if (memo2.A > 0) {\n res += 'A';\n memo2.A--;\n } else if (memo2.G > 0) {\n res += 'G';\n memo2.G--;\n } else if (memo2.C > 0) {\n res += 'C';\n memo2.C--;\n } else if (memo2.T > 0) {\n res += 'T';\n memo2.T--;\n }\n } else {\n res += s[i];\n }\n }\n return res;\n}\n\n//console.log(resolve('AA??'));\n\nreadline();\nconst s = readline();\nprint(resolve(s));\n"}], "negative_code": [{"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n = null;\nlet genome = [];\nlet map = {\n 'A': 0,\n 'C': 0,\n 'G': 0,\n 'T': 0,\n '?': 0\n};\n\nreadline.on('line', line => {\n\n if (!n)\n n = line;\n else {\n genome = line.split('');\n readline.close();\n }\n})\n\nreadline.on('close', () => {\n\n genome.map(char => {\n map[char] = ++map[char];\n })\n\n let max = 0;\n let maxKey = null;\n\n Object.keys(map).forEach(key => {\n if (key !== '?') {\n if (map[key] > max) {\n max = map[key]\n maxKey = key;\n }\n }\n })\n\n if (max === 0)\n max = map['?'] / 4;\n\n let word = genome.join('');\n\n Object.keys(map).forEach(key => {\n if (map['?'] >= 0) {\n if (key !== maxKey && map[key] < max) {\n map[key] = ++map[key];\n map['?']--;\n word = word.replace('?', key);\n }\n }\n })\n\n let cumple = true;\n Object.keys(map).forEach(key => {\n if (key != '?' && map[key] < max) {\n cumple = false;\n }\n })\n if (word.includes('?') || !cumple)\n return console.log('===');\n console.log(word);\n})"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n = null;\nlet genome = [];\nlet map = {\n 'A': 0,\n 'C': 0,\n 'G': 0,\n 'T': 0,\n '?': 0\n};\n\nreadline.on('line', line => {\n\n if (!n)\n n = line;\n else {\n genome = line.split('');\n readline.close();\n }\n})\n\nreadline.on('close', () => {\n\n genome.map(char => {\n map[char] = ++map[char];\n })\n\n let max = 0;\n let maxKey = null;\n\n Object.keys(map).forEach(key => {\n if (key !== '?') {\n if (map[key] > max) {\n max = map[key]\n maxKey = key;\n }\n }\n })\n\n if (max === 0)\n max = map['?'] / 4;\n\n let word = genome.join('');\n\n Object.keys(map).forEach(key => {\n if (map['?'] >= 0) {\n if (key !== maxKey && map[key] < max) {\n map[key] = ++map[key];\n map['?']--;\n word = word.replace('?', key);\n }\n }\n })\n if (word.includes('?'))\n return console.log('===');\n console.log(word);\n})"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n = null;\nlet genome = [];\nlet map = {};\n\nreadline.on('line', line => {\n\n if (!n)\n n = line;\n else {\n genome = line.split('');\n readline.close();\n }\n})\n\nreadline.on('close', () => {\n\n genome.map(char => {\n map[char] = map[char] ? ++map[char] : 1;\n })\n\n\n if (Object.keys(map).length <= n / 2)\n return console.log('===');\n\n let max = 0;\n let maxKey = null;\n\n Object.keys(map).forEach(key => {\n if (key !== '?') {\n if (map[key] > max) {\n max = map[key]\n maxKey = key;\n }\n }\n })\n\n let word = genome.join('');\n\n Object.keys(map).forEach(key => {\n if (map['?'] >= 0) {\n if (key !== maxKey && map[key] < max) {\n map[key] = ++map[key];\n map['?']--;\n word = word.replace('?', key);\n }\n }\n })\n if (word.includes('?'))\n return console.log('===');\n console.log(word);\n})"}, {"source_code": "\"use strict\";\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n = null;\nlet genome = [];\nlet map = {\n 'A': 0,\n 'C': 0,\n 'G': 0,\n 'T': 0,\n '?': 0\n};\n\nreadline.on('line', line => {\n\n if (!n)\n n = line;\n else {\n genome = line.split('');\n readline.close();\n }\n})\n\nreadline.on('close', () => {\n\n genome.map(char => {\n map[char] = ++map[char];\n })\n\n let max = 0;\n let maxKey = null;\n\n Object.keys(map).forEach(key => {\n if (key !== '?') {\n if (map[key] > max) {\n max = map[key]\n maxKey = key;\n }\n }\n })\n\n if (max === 0)\n max = map['?'] / 4;\n\n let word = genome.join('');\n\n Object.keys(map).forEach(key => {\n if (map['?'] >= 0) {\n if (key !== maxKey && map[key] < max) {\n map[key] = ++map[key];\n map['?']--;\n word = word.replace('?', key);\n }\n }\n })\n\n let cumple = true;\n Object.keys(map).forEach(key =>{\n if(map[key] < max){\n cumple = false;\n }\n })\n\n if (word.includes('?') || !cumple)\n return console.log('===');\n console.log(word);\n})"}], "src_uid": "d6423f380e6ba711d175d91e73f97b47"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*Math.abs(a-b);\r\n if (length < Math.max(a,b) || length < c)\r\n console.log(-1)\r\n else \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}", "positive_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1] = d.split(\" \").map(Number);\n const diameter = Math.abs(a1 - b1);\n const circle = diameter * 2;\n\n if (circle < a1 || circle < b1) {\n console.log(-1);\n } else if (c1 > circle) {\n console.log(-1);\n } else {\n const guess = c1 + diameter;\n if (guess > circle) {\n console.log(guess - circle);\n } else {\n console.log(guess);\n }\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0]; var b = k[1]; var c = k[2];\n var dif = Math.abs(a - b);\n var v = dif * 2;\n if(a > v || b > v || c > v){\n console.log(-1);\n }else{\n var d = c + dif;\n if(d > v){\n d = c - dif;\n }\n console.log(d);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n\tfor(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var dif = Math.abs(a - b);\n var val = dif * 2;\n if(a > val || b > val || c > val){\n console.log(-1);\n }else{\n var d = c + dif;\n if(d > val){\n d = c - dif;\n }\n console.log(d);\n }\n\t}\n});"}, {"source_code": "function main(input) {\r\n function readline() {\r\n return input.shift();\r\n }\r\n\r\n let lines = Number(readline());\r\n for(let i=0; i i <= size)) {\r\n if(x > offset) {\r\n return x - offset\r\n } else {\r\n return x + offset\r\n }\r\n }\r\n return '-1';\r\n }\r\n console.log(getResult());\r\n }\r\n}\r\n\r\n\r\n////////////////////////\r\nlet inputString = '';\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\r\n\r\n main(inputString);\r\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline())\r\n\r\nwhile(t--){\r\n var array=readline().split(' ').map(x=>parseInt(x));\r\n var a=array[0];\r\n var b=array[1];\r\n var c=array[2]\r\n\r\n var distance=Math.abs(a-b);\r\n var n=distance*2;\r\n if(distance<=1){\r\n print('-1')\r\n }else if(nn){\r\n print(c-distance)\r\n }else{\r\n print(distance+c)\r\n }\r\n\r\n}\r\n \r\n}"}, {"source_code": "function solve() {\r\n let [a, b, c] = readArray(Number);\r\n if (a > b) {\r\n const temp = a;\r\n a = b;\r\n b = temp;\r\n }\r\n const diff = b - a;\r\n if (!(a <= diff && b > diff) || c > diff * 2) {\r\n write(-1);\r\n return;\r\n }\r\n if (c <= diff) {\r\n write(c + diff);\r\n return;\r\n }\r\n write(c - diff);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [a, b, c] = nl.nums();\n\t\tlet n = Math.abs(a - b) ;\n\t\tif (a > n * 2 || b > n * 2 || c > n * 2){\n\t\t\tans.push(-1);\n\t\t} else {\n\t\t\tans.push(n >= c?(c + n):(c - n)) \n\t\t}\n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [a, b, c] = rna();\r\n\r\n\t\tconst k = Math.abs(a-b);\r\n\t\t\r\n\t\tlet ans = -1;\r\n\t\tif (a <= 2*k && b <= 2*k && c <= 2*k) {\r\n\t\t\tans = (c + k - 1) % (2 * k) + 1;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\n \r\nprocess.stdin.setEncoding('utf8');\r\n \r\nvar input = '';\r\n \r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a, b, c] = input[z++].split(' ').map(Number);\r\n let diff = Math.abs(a - b);\r\n if((a > diff * 2)){\r\n console.log(-1);\r\n }\r\n else if(b > diff * 2){\r\n console.log(-1);\r\n }\r\n else if(c > diff * 2){\r\n console.log(-1);\r\n }\r\n else{\r\n let opposite = diff + c <= diff * 2 ? diff + c : Math.abs(diff - c);\r\n console.log(opposite);\r\n }\r\n }\r\n}"}, {"source_code": "abs = Math.abs\r\n\r\nconst fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\n\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction solve() {\r\n let lis = readline(\"enter a number\").split(\" \");\r\n let a, b, c;\r\n a = parseInt(lis[0]);\r\n b = parseInt(lis[1]);\r\n c = parseInt(lis[2]);\r\n if (abs(a - b) * 2 < Math.max(a, b, c)) {\r\n return -1\r\n\r\n } else {\r\n let x = abs(b-a);\r\n let ans = (c + x) ;\r\n if (ans > (x*2)){\r\n return c-x\r\n }\r\n return ans\r\n\r\n }\r\n}\r\nfor (let i = parseInt(readline()); i > 0; i--) {\r\n console.log(solve())\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst assert = (condition) => { if (!condition) throw new Error(\"Assertion failed\"); }\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst mxll = (...args) => args.reduce((m, e) => e > m ? e : m);\r\nconst mill = (...args) => args.reduce((m, e) => e < m ? e : m);\r\nconst sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst int = parseInt;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg2 = Math.log2;\r\nconst lg10 = Math.log10;\r\nconst ll = BigInt;\r\nconst combination = (m, n) => { return factorial(m, n) / factorial(n, n); };\r\nconst factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\r\nconst powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth\r\nconst initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };\r\nconst initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };\r\nconst stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));\r\nconst stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));\r\nconst stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));\r\nconst stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\nconst counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };\r\nconst counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };\r\nconst reverse2 = (s) => { let res = \"\"; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };\r\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\r\nconst ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);\r\nconst isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 08/18/21 morning\r\n * https://codeforces.com/contest/1560/problem/B\r\n */\r\nconst solve = (a, b, c) => {\r\n // pr()\r\n // pr(a, b, c)\r\n let half = Math.abs(a - b);\r\n let tot = half * 2;\r\n // pr(\"tot\", tot)\r\n if (c > tot || a > tot || b > tot) return pr(-1);\r\n if (c - half >= 1 && c - half != a && c- half != b) return pr(c - half);\r\n if (c + half <= tot && c + half != a && c + half != b) return pr(c + half);\r\n pr(-1);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i][1], input[i][2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let inputs = []\n\nfunction read() {\n return inputs.pop();\n}\n\nfunction readInt() {\n return parseInt(read());\n}\n\nfunction solve() {\n let test = readInt();\n while (test--) {\n let a = readInt();\n let b = readInt();\n let c = readInt();\n let nn = Math.abs(b - a);\n let n = nn * 2;\n if (n < a || n < b || n < c) {\n console.log(-1);\n }\n else {\n if (0 < c - nn && c - nn != a && c - nn != b) {\n console.log(c - nn);\n }\n else if (c + nn <= n && c + nn != a && c + nn != b) {\n console.log(c + nn);\n }\n else {\n console.log(-1);\n }\n }\n }\n}\n\nfunction main() {\n inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\n inputs.reverse(); \n solve();\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\n\nprocess.stdin.on('end', (_) => { main(); });\n"}, {"source_code": "function max(a, b) {\n if (a > b) {\n return {\n max: a,\n min: b\n };\n }\n return {\n max: b,\n min: a\n }\n}\n\nfunction solve(a, b, c) {\n const { max: maxValue, min: minValue } = max(a, b);\n const n = (maxValue - minValue) * 2;\n if (maxValue < (n / 2 + 1)) {\n return -1;\n }\n if (minValue >= (n / 2 + 1)) {\n return -1;\n }\n let res = -1;\n if (c < (n / 2 + 1)) {\n res = n / 2 + c;\n if (res < (n / 2 + 1)) {\n return -1;\n }\n } else {\n res = c - n / 2;\n if (res >= (n / 2 + 1)) {\n return -1;\n }\n }\n return res;\n}\n\nfunction main(array) {\n const T = array[0];\n for (let i = 0; i < T; i++) {\n const arr = array[i + 1];\n const [a, b, c] = arr.split(' ').map((item) => parseInt(item, 10));\n console.log(solve(a, b, c));\n }\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\n\n main(inputString);\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar tmp1 = Math.min(A, B);\r\n\t\tvar tmp2 = Math.max(A, B);\r\n\t\tA = tmp1;\r\n\t\tB = tmp2;\r\n\t\tvar C = nextInt();\r\n\t\tif(Math.abs(A - B) == 1){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar size = Math.abs(A - B) * 2;\r\n\t\tif(size < C || size < A || size < B){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar low = B - (size / 2);\r\n\t\tvar high = B + (size / 2);\r\n\t\tif(high > size){\r\n\t\t\thigh -= size;\r\n\t\t}\r\n\t\tif(low != high){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar nx = C + (size / 2);\r\n\t\tif(nx > size){\r\n\t\t\tnx -= size;\r\n\t\t}\r\n\t\tmyout(nx);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\nfunction main() {\r\n const xx = readline();\r\n var array = []\r\n var i = 0\r\n while (true) {\r\n i++\r\n if (array.length === 1000) break\r\n if (i % 3 === 0 || i % 10 === 3) continue\r\n array.push(i)\r\n\r\n }\r\n // console.log(array)\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // var n = parseInt(readline());\r\n\r\n var [a, b, c] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var dd = Math.abs(b - a)\r\n\r\n var max = dd * 2\r\n if (max < a || max < b || max < c) return console.log(-1)\r\n var answer = (c + dd) % (max)\r\n\r\n if(c === dd) return console.log(max)\r\n if(c === max) return console.log(dd)\r\n console.log(answer)\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict'\r\nObject.defineProperty(exports, '__esModule', { value: !0 })\r\nvar os = require('os')\r\nconst stdin = process.stdin,\r\n stdout = process.stdout,\r\n integerRegex = /-?\\d+/g,\r\n decimalRegex = /-?\\d+(?:\\.\\d+)?/g\r\nclass InputAndOutput {\r\n lineIndex = 0\r\n lines = []\r\n dried() {\r\n return this.lineIndex >= this.lines.length\r\n }\r\n readLine() {\r\n const e = this.lines[this.lineIndex]\r\n return (this.lineIndex += 1), e\r\n }\r\n readLineAsNumber() {\r\n return Number(this.readLine())\r\n }\r\n readIntegersOfLine() {\r\n const e = this.readLine().match(integerRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n readNumsOfLine() {\r\n const e = this.readLine().match(decimalRegex)\r\n return null == e ? [] : e.map(e => Number(e))\r\n }\r\n print(e) {\r\n stdout.write(String(e))\r\n }\r\n println(e) {\r\n stdout.write(String(e)), stdout.write('\\n')\r\n }\r\n async init() {\r\n const e = await this.readLines()\r\n this.lines = e\r\n }\r\n readLines() {\r\n const e = []\r\n return new Promise(n => {\r\n stdin.on('data', n => e.push(n)),\r\n stdin.on('end', function () {\r\n const t = e.join('').split(os.EOL)\r\n n(t)\r\n })\r\n })\r\n }\r\n}\r\nasync function __main__(e) {\r\n const n = new InputAndOutput()\r\n await n.init(), e(n)\r\n}\r\nfunction solve(e, n, t) {\r\n const s = Math.abs(e - n)\r\n if (e > s && n > s) return -1\r\n const i = 2 * s\r\n return t > i ? -1 : t + s <= i ? t + s : t - s >= 1 ? t - s : -1\r\n}\r\n__main__(function (e) {\r\n const n = e.readLineAsNumber()\r\n for (let t = 1; t <= n; ++t) {\r\n const [n, t, s] = e.readIntegersOfLine(),\r\n i = solve(n, t, s)\r\n e.print(i + '\\n')\r\n }\r\n})\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n console.log(solve(a, b, c))\n }\n// })()\n})\n\nfunction solve(a, b, c) {\n const k = Math.abs(a - b)\n const n = 2 * k\n // console.log(n, a, b)\n if (a > n || b > n) return -1\n if (c > n || c + k > n && c - k < 1) return -1\n\n if (c + k <= n) {\n return c + k\n } else {\n return c - k\n }\n}\n"}, {"source_code": "var t = Number(readline());\r\n\r\nwhile (t--) {\r\n var arr = readline().split(\" \");\r\n var a = Number(arr[0]);\r\n var b = Number(arr[1]);\r\n var c = Number(arr[2]);\r\n var ppl = Math.abs(a - b) * 2;\r\n var ans1 = c + ppl / 2;\r\n var ans2 = c - ppl / 2;\r\n\r\n if (Math.max(a, b) > ppl || c > ppl)\r\n print(-1);\r\n else if (ans1 <= ppl)\r\n print(ans1);\r\n else if (ans2 >= 1 && ans2 <= ppl)\r\n print(ans2);\r\n else \r\n print(-1);\r\n\r\n\r\n}"}, {"source_code": "var t = parseInt(readline());\r\nfunction formate(v) {return parseInt(v)}\r\nfor(i=0;i size || b > size || c > size) print(-1);\r\n else print((c + a - b + size - 1)% size + 1);\r\n}"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var a = v[0], b = v[1], c = v[2];\r\n if (a > b) {\r\n [a, b] = [b, a];\r\n }\r\n if (2 * a > b) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var n = 2 * b - 2 * a;\r\n var d = b - a;\r\n if (c > n) { console.log(-1); }\r\n else if (c + d <= n) { console.log(c + d); }\r\n else if (c - d <= 0) { console.log(-1); }\r\n else if (c - d > n) { console.log(-1); }\r\n else { console.log(c - d); }\r\n }\r\n}"}, {"source_code": "// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.\r\n\r\n\r\n// var t = Number(readline());\r\n\r\n// for (var i = 1; i <= t; i++) {\r\n// // var a = Number(readline()),\r\n// // b = Number(readline()),\r\n// // c = Number(readline());\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1],\r\n// c = arr[2];\r\n// var sub = 0;\r\n// if (a > b) {\r\n// sub = a - b;\r\n// } else {\r\n// sub = b - a;\r\n// }\r\n\r\n// if (sub * 2 === 2) {\r\n// console.log(-1);\r\n// } else if (a > sub * 2 || c > sub * 2) {\r\n// console.log(-1);\r\n// } else {\r\n// var spe1 = c - sub;\r\n// if (spe1 == 1) {\r\n// // var spe1 = c - sub;\r\n// console.log(spe1);\r\n// } else {\r\n// var spe2 = sub + sub;\r\n// console.log(spe2);\r\n// }\r\n// }\r\n\r\n// }\r\n\r\n// var a = Number(readline()),\r\n// b = Number(readline()),\r\n// c = Number(readline());\r\n\r\n\r\n// var t = Number(readline());\r\n// for (var i = 1; i <= t; i++) {\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1],\r\n// c = arr[2];\r\n// let nn = Math.abs(b - a);\r\n// let n = nn * 2;\r\n// if (n < a || n < b || n < c) {\r\n// console.log(-1);\r\n// } else {\r\n// if (0 < c - nn && c - nn != a && c - nn != b) {\r\n// console.log(c - nn);\r\n// } else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n// console.log(c + nn);\r\n// } else {\r\n// console.log(-1);\r\n// }\r\n// }\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n\r\n var t = Number(readline());\r\n for (var i = 1; i <= t; i++) {\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1],\r\n c = arr[2];\r\n let nn = Math.abs(b - a);\r\n let n = nn * 2;\r\n if (n < a || n < b || n < c) {\r\n console.log(-1);\r\n } else {\r\n if (0 < c - nn && c - nn != a && c - nn != b) {\r\n console.log(c - nn);\r\n } else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n console.log(c + nn);\r\n } else {\r\n console.log(-1);\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n// let inputs = []\r\n\r\n// function read() {\r\n// return inputs.pop();\r\n// }\r\n\r\n// function readInt() {\r\n// return parseInt(read());\r\n// }\r\n\r\n// function solve() {\r\n// let test = readInt();\r\n// while (test--) {\r\n// let a = readInt();\r\n// let b = readInt();\r\n// let c = readInt();\r\n// let nn = Math.abs(b - a);\r\n// let n = nn * 2;\r\n// if (n < a || n < b || n < c) {\r\n// console.log(-1);\r\n// }\r\n// else {\r\n// if (0 < c - nn && c - nn != a && c - nn != b) {\r\n// console.log(c - nn);\r\n// }\r\n// else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n// console.log(c + nn);\r\n// }\r\n// else {\r\n// console.log(-1);\r\n// }\r\n// }\r\n// }\r\n// }\r\n\r\n// function main() {\r\n// inputs = inputString.trim().split(/\\n| /).map((string) => string.trim());\r\n// inputs.reverse(); \r\n// solve();\r\n// }\r\n\r\n// let inputString = '';\r\n\r\n// process.stdin.on('data', (inputStdin) => { inputString += inputStdin; });\r\n\r\n// process.stdin.on('end', (_) => { main(); });"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let numOfTimes = readline();\r\n let line;\r\n while (numOfTimes--) {\r\n line = readline();\r\n print(work(...convert(line.split(\" \"))));\r\n }\r\n}\r\n\r\n\r\nfunction convert(arr){\r\n return arr.map((ele)=> Number(ele));\r\n \r\n}\r\n\r\nfunction work(a, b, c) {\r\n const max = Math.max(a, b);\r\n const half = 2 * max - a - b;\r\n\r\n if (max > 2 * half || c > 2 * half) return -1;\r\n\r\n if (c > half) {\r\n return c - half;\r\n } else {\r\n return c + half;\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "var t = Number(readline());\r\n\r\nwhile (t--) {\r\n var arr = readline().split(\" \");\r\n var a = Number(arr[0]);\r\n var b = Number(arr[1]);\r\n var c = Number(arr[2]);\r\n var ppl = Math.abs(a - b) * 2;\r\n var ans1 = c + ppl / 2;\r\n var ans2 = c - ppl / 2;\r\n\r\n if (Math.max(a, b) > ppl)\r\n print(-1);\r\n else if (ans1 <= ppl)\r\n print(ans1);\r\n else if (ans2 >= 1 && ans2 <= ppl)\r\n print(ans2);\r\n else \r\n print(-1);\r\n\r\n\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*(a-b);\r\n if (length < Math.max(a,b) || length < c)\r\n console.log(-1)\r\n else \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*(a-b);\r\n if (length < Math.max(a,b) || length < c){\r\n console.log(-1)\r\n continue; \r\n }\r\n \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*(a-b);\r\n if (length < Math.max(a,b,c)){\r\n console.log(-1)\r\n continue; \r\n }\r\n \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*(a-b);\r\n if (length < Math.max(a,b) || length < c){\r\n console.log(-1)\r\n }\r\n \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0;i < x;i++){\r\n let array = readline().split(\" \").map(x => parseInt(x));\r\n let a = array[0]\r\n let b = array[1]\r\n let c = array[2]\r\n \r\n let length = 2*(a-b);\r\n if (length < Math.max(a,b,c)){\r\n console.log(-1)\r\n }\r\n \r\n console.log(c > length/2 ? c - length/2 : c + length/2);\r\n }\r\n}"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var a = v[0], b = v[1], c = v[2];\r\n if (a > b) {\r\n [a, b] = [b, a];\r\n }\r\n if (2 * a > b) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var n = 2 * a - 2 * b;\r\n var d = b - a;\r\n if (c > n) { console.log(-1); }\r\n else if (c + d <= n) { console.log(c + d); }\r\n else if (c - d <= 0) { console.log(-1); }\r\n else if (c - d > n) { console.log(-1); }\r\n else { console.log(c - d); }\r\n }\r\n}"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var a = v[0], b = v[1], c = v[2];\r\n if (a > b) {\r\n [a, b] = [b, a];\r\n }\r\n if (2 * a > b) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var n;\r\n for (var j = 0; j <= 10000; j++) {\r\n if (2 * (a + j) === b + j) {\r\n n = b + j;\r\n }\r\n }\r\n var d = b - a;\r\n if (c > n) { console.log(-1); }\r\n else if (c + d <= n) { console.log(c + d); }\r\n else if (c - d <= 0) { console.log(-1); }\r\n else if (c - d > n) { console.log(-1); }\r\n else { console.log(c - d); }\r\n }\r\n}"}, {"source_code": "\r\n'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet input = '';\r\nprocess.stdin.on('data', inputStdin => {\r\n input += inputStdin;\r\n});\r\nprocess.stdin.on('end', _ => {\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n var args = input.split(\"\\n\");\r\n const t = parseInt(args[0], 10);\r\n for (var i = 1; i <= t; i++) {\r\n var v = args[i].split(\" \").map((n) => parseInt(n, 10));\r\n var a = v[0], b = v[1], c = v[2];\r\n if (a > b) {\r\n [a, b] = [b, a];\r\n }\r\n if (2 * a > b) {\r\n console.log(-1);\r\n continue;\r\n }\r\n var n;\r\n for (var j = 0; j <= 10000; j++) {\r\n if (2 * (a + j) === b + j) {\r\n n = b + j;\r\n }\r\n }\r\n var d = b - a;\r\n if (c + d <= n) { console.log(c + d); }\r\n else if (c - d <= 0) { console.log(-1); }\r\n else if (c - d > n) { console.log(-1); }\r\n else { console.log(c - d); }\r\n }\r\n}"}, {"source_code": "// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.\r\n\r\n\r\n// var t = Number(readline());\r\n\r\n// for (var i = 1; i <= t; i++) {\r\n// // var a = Number(readline()),\r\n// // b = Number(readline()),\r\n// // c = Number(readline());\r\n// var arr = readline().split(' ').map(x => parseInt(x));\r\n// var a = arr[0],\r\n// b = arr[1],\r\n// c = arr[2];\r\n// var sub = 0;\r\n// if (a > b) {\r\n// sub = a - b;\r\n// } else {\r\n// sub = b - a;\r\n// }\r\n\r\n// if (sub * 2 === 2) {\r\n// console.log(-1);\r\n// } else if (a > sub * 2 || c > sub * 2) {\r\n// console.log(-1);\r\n// } else {\r\n// var spe1 = c - sub;\r\n// if (spe1 == 1) {\r\n// // var spe1 = c - sub;\r\n// console.log(spe1);\r\n// } else {\r\n// var spe2 = sub + sub;\r\n// console.log(spe2);\r\n// }\r\n// }\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n// var t = Number(readline());\r\n// for (var i = 1; i <= t; i++) {\r\n// var a = Number(readline()),\r\n// b = Number(readline()),\r\n// c = Number(readline());\r\n// let nn = Math.abs(b - a);\r\n// let n = nn * 2;\r\n// if (n < a || n < b || n < c) {\r\n// console.log(-1);\r\n// } else {\r\n// if (0 < c - nn && c - nn != a && c - nn != b) {\r\n// console.log(c - nn);\r\n// } else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n// console.log(c + nn);\r\n// } else {\r\n// console.log(-1);\r\n// }\r\n// }\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n\r\n for (var i = 1; i <= t; i++) {\r\n // var a = Number(readline()),\r\n // b = Number(readline()),\r\n // c = Number(readline());\r\n var arr = readline().split(' ').map(x => parseInt(x));\r\n var a = arr[0],\r\n b = arr[1],\r\n c = arr[2];\r\n var sub = 0;\r\n if (a > b) {\r\n sub = a - b;\r\n } else {\r\n sub = b - a;\r\n }\r\n\r\n if (sub * 2 === 2) {\r\n console.log(-1);\r\n } else if (a > sub * 2 || c > sub * 2) {\r\n console.log(-1);\r\n } else {\r\n var spe1 = c - sub;\r\n if (spe1 == 1) {\r\n // var spe1 = c - sub;\r\n console.log(spe1);\r\n } else {\r\n var spe2 = sub + sub;\r\n console.log(spe2);\r\n }\r\n }\r\n\r\n }\r\n\r\n}"}, {"source_code": "// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.\r\n\r\n\r\n// var t = Number(readline());\r\n// for (var i = 1; i <= t; i++) {\r\n// var a = Number(readline()),\r\n// b = Number(readline()),\r\n// c = Number(readline());\r\n// let nn = Math.abs(b - a);\r\n// let n = nn * 2;\r\n// if (n < a || n < b || n < c) {\r\n// console.log(-1);\r\n// } else {\r\n// if (0 < c - nn && c - nn != a && c - nn != b) {\r\n// console.log(c - nn);\r\n// } else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n// console.log(c + nn);\r\n// } else {\r\n// console.log(-1);\r\n// }\r\n// }\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n for (var i = 1; i <= t; i++) {\r\n var a = Number(readline()),\r\n b = Number(readline()),\r\n c = Number(readline());\r\n let nn = Math.abs(b - a);\r\n let n = nn * 2;\r\n if (n < a || n < b || n < c) {\r\n console.log(-1);\r\n } else {\r\n if (0 < c - nn && c - nn != a && c - nn != b) {\r\n console.log(c - nn);\r\n } else if (c + nn <= n && c + nn != a && c + nn != b) {\r\n console.log(c + nn);\r\n } else {\r\n console.log(-1);\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.\r\n\r\n\r\n// var t = Number(readline());\r\n// for (var i = 1; i <= t; i++) {\r\n// var a = Number(readline()),\r\n// b = Number(readline()),\r\n// c = Number(readline());\r\n// var sub = 0;\r\n// if (a > b) {\r\n// sub = a - b;\r\n// } else {\r\n// sub = b - a;\r\n// }\r\n\r\n// if (sub * 2 === 2) {\r\n// console.log(-1);\r\n// } else if (a > sub * 2 || c > sub * 2) {\r\n// console.log(-1);\r\n// } else {\r\n// var spe1 = c - sub;\r\n// if (spe1 === 1) {\r\n// console.log(spe1);\r\n// } else {\r\n// var spe2 = sub + sub;\r\n// console.log(spe2);\r\n// }\r\n// }\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n for (var i = 1; i <= t; i++) {\r\n var a = Number(readline()),\r\n b = Number(readline()),\r\n c = Number(readline());\r\n var sub = 0;\r\n if (a > b) {\r\n sub = a - b;\r\n } else {\r\n sub = b - a;\r\n }\r\n\r\n if (sub * 2 === 2) {\r\n console.log(-1);\r\n } else if (a > sub * 2 || c > sub * 2) {\r\n console.log(-1);\r\n } else {\r\n var spe1 = c - sub;\r\n if (spe1 === 1) {\r\n console.log(spe1);\r\n } else {\r\n var spe2 = sub + sub;\r\n console.log(spe2);\r\n }\r\n }\r\n\r\n }\r\n\r\n}"}, {"source_code": "// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.\r\n\r\n\r\n// var t = Number(readline());\r\n// for (var i = 0; i <= t; i++) {\r\n// var a = Number(readline()),\r\n// b = Number(readline()),\r\n// c = Number(readline());\r\n// var sub = 0;\r\n// if (a > b) {\r\n// sub = a - b;\r\n// } else {\r\n// sub = b - a;\r\n// }\r\n\r\n// if (sub * 2 === 2) {\r\n// console.log(-1);\r\n// } else if (a > sub * 2 || c > sub * 2) {\r\n// console.log(-1);\r\n// } else {\r\n// var spe1 = c - sub;\r\n// if (spe1 === 1) {\r\n// console.log(spe1);\r\n// } else {\r\n// var spe2 = sub + sub;\r\n// console.log(spe2);\r\n// }\r\n// }\r\n\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ************************ Code Start ***************************\r\n\r\nfunction main() {\r\n\r\n var t = Number(readline());\r\n for (var i = 0; i <= t; i++) {\r\n var a = Number(readline()),\r\n b = Number(readline()),\r\n c = Number(readline());\r\n var sub = 0;\r\n if (a > b) {\r\n sub = a - b;\r\n } else {\r\n sub = b - a;\r\n }\r\n\r\n if (sub * 2 === 2) {\r\n console.log(-1);\r\n } else if (a > sub * 2 || c > sub * 2) {\r\n console.log(-1);\r\n } else {\r\n var spe1 = c - sub;\r\n if (spe1 === 1) {\r\n console.log(spe1);\r\n } else {\r\n var spe2 = sub + sub;\r\n console.log(spe2);\r\n }\r\n }\r\n\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n \r\n let numOfTimes = readline();\r\n let line;\r\n print(readline())\r\n while (numOfTimes--) {\r\n line = readline();\r\n print(work(...line.split(\" \")));\r\n }\r\n}\r\n\r\n\r\nfunction work(a,b,c){\r\nconst max= Math.max(a,b);\r\nconst half= 2*max - a-b;\r\n\r\nif((max>2*half)||(c>2*half)) return -1\r\n\r\nif(c>half){\r\n return c-half\r\n}\r\nelse{\r\n return c+half;\r\n}\r\n\r\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n let numOfTimes = readline();\r\n let line;\r\n while (numOfTimes--) {\r\n line = readline();\r\n print(work(...line.split(\" \")));\r\n }\r\n}\r\n\r\n\r\nfunction work(a,b,c){\r\nconst max= Math.max(a,b);\r\nconst half= 2*max - a-b;\r\n\r\nif((max>2*half)||(c>2*half)) return -1\r\n\r\nif(c>half){\r\n return c-half\r\n}\r\nelse{\r\n return c+half;\r\n}\r\n\r\n}"}, {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [a1, b1, c1] = d.split(\" \").map(Number);\n const diameter = Math.abs(a1 - b1);\n const circle = diameter * 2;\n\n if (circle < a1 || circle < b1) {\n console.log(-1);\n } else if (c1 >= circle) {\n console.log(-1);\n } else {\n const guess = c1 + diameter;\n if (guess > circle) {\n console.log(guess - circle);\n } else {\n console.log(guess);\n }\n }\n c++;\n});\n\nrl.on(\"close\", () => {});\n"}, {"source_code": "function main(input) {\r\n function readline() {\r\n return input.shift();\r\n }\r\n\r\n let lines = Number(readline());\r\n for(let i=0; i i < size)) {\r\n if(x > offset) {\r\n return x - offset\r\n } else {\r\n return x + offset\r\n }\r\n }\r\n return '-1';\r\n }\r\n console.log(getResult());\r\n }\r\n}\r\n\r\n\r\n////////////////////////\r\nlet inputString = '';\r\nprocess.stdin.on('data', (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on('end', (_) => {\r\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\r\n\r\n main(inputString);\r\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ************************ Code Start ***************************\r\n \r\nfunction main() {\r\n \r\n var t=parseInt(readline())\r\n\r\nwhile(t--){\r\n var array=readline().split(' ').map(x=>parseInt(x));\r\n var a=array[0];\r\n var b=array[1];\r\n var c=array[2]\r\n\r\n var distance=Math.abs(a-b);\r\n var n=distance*2;\r\n if(distance<=1){\r\n print('-1')\r\n }else if(n<=a || n<=b || nn){\r\n print(c-distance)\r\n }else{\r\n print(distance+c)\r\n }\r\n\r\n}\r\n \r\n}"}, {"source_code": "function solve() {\r\n let [a, b, c] = readArray(Number);\r\n if (a > b) {\r\n const temp = a;\r\n a = b;\r\n b = temp;\r\n }\r\n const diff = b - a;\r\n if (!(a <= diff && b > diff)) {\r\n write(-1);\r\n return;\r\n }\r\n const ans1 = c + diff;\r\n const ans2 = c - diff;\r\n if (ans1 <= diff * 2 && ans1 > 0) {\r\n write(ans1);\r\n return;\r\n }\r\n if (ans2 <= diff * 2 && ans2 > 0) {\r\n write(ans2);\r\n return;\r\n }\r\n write(-1);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "07597a8d08b59d4f8f82369bb5d74a49"} {"source_code": "var x = +readline().split(' ')[1];\n\nvar s = Math.abs(readline().split(' ').map(Number).reduce(function (p, e) { return p + e; }, 0));\n\nvar t = 0;\n\nwhile (s > 0) {\n\tt++;\n\ts -= x;\n}\n\nprint(t);", "positive_code": [{"source_code": "print(function(n, x) {\n\tvar sum = readline().split(' ').map(Number).reduce(function(a, b) {\n\t\treturn a + b;\n\t});\n\tsum = Math.abs(sum);\n\treturn Math.ceil(sum / x);\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "function sum(array){\n\tvar result = 0;\n\tfor(var i = 0; i < array.length; i++){\n\t\tresult += +array[i];\n\t}\n\treturn result;\n}\n\nvar input = readline().split(\" \"), n = +input[0], x = +input[1], numbers = readline().split(\" \").map(Number),\nall = sum(numbers);\n\nif(all == 0){\n\twrite(0);\n}\nelse{\n\tif(Math.abs(all) <= x){\n\t\twrite(1);\n\t}\n\telse{\n\t\twrite(Math.ceil(Math.abs(all)/x));\n\t}\n}"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar foundNum = integers[0], max = integers[1];\n\tvar cards = tokenizeIntegers(readline());\n\tvar sum = 0;\n\tfor (var i = 0; i < cards.length; ++i) {\n\t\tsum += cards[i];\n\t}\n\tsum = Math.abs(sum);\n\tvar count = 0;\n\twhile (sum > max) {\n\t\tsum -= max;\n\t\tcount += 1;\n\t}\n\tif (sum > 0) {\n\t\tcount += 1;\n\t}\n\tprint(count);\n}\n\nmain();\n"}, {"source_code": "\nfunction solve(){\n var input = readline().split(\" \");\n var n = parseInt(input[0]);\n var x = parseInt(input[1]);\n var a = readline().split(\" \");\n var sum = 0;\n for(var i = 0; i < a.length; i++){\n sum += parseInt(a[i]);\n }\n sum = sum < 0 ? -sum : sum;\n var res = Math.floor((sum + x - 1)/x);\n print(res);\n}\nsolve();"}, {"source_code": "function main() {\n var nx = readline().split(' ');\n var line = readline().split(' ');\n var n = Number(nx[0]),\n x = Number(nx[1]),\n sum = 0;\n\n for (var i = 0; i < n; i++) {\n sum += Number(line[i]);\n }\n\n var changes = 0;\n\n while (sum > 0) {\n if (sum > x) {\n sum -= x;\n changes++;\n } else {\n sum = 0;\n changes++;\n }\n }\n\n while (sum < 0) {\n if (sum * -1 > x) {\n sum += x;\n changes++;\n } else {\n sum = 0;\n changes++;\n }\n }\n\n print(changes);\n}\n\nmain();\n"}, {"source_code": "function main(){\n var line = readline().split(' ');\n var n = parseInt(line[0]);\n var x = parseInt(line[1]);\n var sum = 0;\n readline().split(' ').forEach(function (v){\n sum += parseInt(v);\n });\n print(Math.ceil(Math.abs(sum)/x));\n}\nmain();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, x;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, x] = d.split(' ').map(Number);\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const sum = Math.abs(arr.reduce((a, b) => a + b, 0));\n const ans = Math.ceil(sum / x);\n\n console.log(ans);\n c++;\n});\n"}, {"source_code": "/* \u0628\u0650\u0633\u0652\u0645\u0650 \u0627\u0644\u0644\u064e\u0651\u0647\u0650 \u0627\u0644\u0631\u064e\u0651\u062d\u0652\u0645\u064e\u0670\u0646\u0650 \u0627\u0644\u0631\u064e\u0651\u062d\u0650\u064a\u0645\u0650 */\n//codeforces_401A\nvar gi = process.stdin;\ngi.setEncoding('utf8');\nvar go = (x) => process.stdout.write(x);\nfunction parseArray(line) { return line.split(' ').map(function (a) { return parseInt(a); }); }\n\nlet main = function(data){\n\tvar lines = data.split(\"\\n\");\n\tvar a = parseArray(lines[0]);\n\tvar n = a[0], x = a[1];\n\ta = parseArray(lines[1]);\n\tvar sum = 0;\n\tfor (var k in a) {\n\t\tsum += a[k];\n\t}\n\tsum = Math.abs(sum);\n\tvar ans = Math.floor(sum/x);\n\tif (sum%x != 0) { ans++; }\n\tgo(ans + \"\");\n\treturn 0;\n}\ngi.on(\"data\", main);"}], "negative_code": [{"source_code": "var x = +readline().split(' ')[1];\n\nvar s = Math.abs(readline().split(' ').map(Number).reduce(function (p, e) { return p + e; }, 0));\n\nvar t = 0;\n\nwhile (s > 0) {\n\tt++;\n\ts -= (x-1);\n}\n\nprint(t);"}, {"source_code": "function main(){\n var line = readline().split(' ');\n var n = parseInt(line[0]);\n var x = parseInt(line[1]);\n var sum = 0;\n readline().split(' ').forEach(function (v){\n sum += parseInt(v);\n });\n print(Math.ceil(sum/x));\n}\nmain();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, x;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n [n, x] = d.split(' ').map(Number);\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const sum = Math.abs(arr.reduce((a, b) => a + b, 0));\n const ans = Math.floor(sum / x) + sum % x;\n\n console.log(ans);\n c++;\n});\n"}], "src_uid": "066906ee58af5163636dac9334619ea7"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [x, y] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(x, y)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(x, y) {\n const ab = Math.floor(y / x)\n const b1r = y % x\n// console.log('-', ab, b1r)\n if (!ab) {\n // y < x\n return x + y\n }\n const limit = Math.sqrt(ab)\n for (let i = 1; i <= limit; i++) {\n if (ab % i) continue\n // b = i or ab / i\n let b = i\n if (!(b1r % (b + 1))) {\n const r = b1r / (b + 1)\n const n = (y - r) / b\n // console.log('b1', b, n)\n if (r < x && r < y) return n\n }\n b = ab / i\n if (!(b1r % (b + 1))) {\n const r = b1r / (b + 1)\n const n = (y - r) / b\n // console.log('b2', b, n)\n if (r < x && r < y) return n\n }\n // console.log(i, ab)\n }\n}\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [x, y] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tif (x > y) \r\n\t\t\tans = x + y;\r\n\t\telse\r\n\t\t\tans = y - y%x/2;\r\n\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(x, y) {\r\n if (x === y) return x;else if (x > y) return x + y;else if (y % x === 0) return x;else return y - (x + y) / 2 % x;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(x, y) {\r\n if (x === y) return x;else if (x > y) return x + y;else if (y % x === 0) return x;else return (x + y) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(x, y) {\r\n if (x === y) return x;else if (x > y) return x + y;else return (x + y) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n let t1 = t;\r\n let params = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n params.push([n, m]);\r\n res.push(solve(n, m));\r\n }\r\n if (t1 === 100000) {\r\n console.log(params[406].join(','));\r\n return;\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(x, y) {\r\n if (x === y) return x;else if (x > y) return x + y;else return (x + y) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n let t1 = t;\r\n let params = [];\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n params.push([n, m]);\r\n res.push(solve(n, m));\r\n }\r\n if (t1 === 100000) {\r\n console.log(params[406]);\r\n return;\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m) {\r\n if (n === m) return n;else if (n > m) return n + m;else return (n + m) / 2;\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "src_uid": "a24aac9152417527d43b9b422e3d2303"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n const [w, q] = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(str, w, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str, w, qs) {\n const n = str.length\n const rs = Array(n)\n // const trs = [] // 10^i % 9\n let temp = 0\n let ten = 1\n for (let i = str.length - 1; i >= 0; i--) {\n const x = +str[i]\n // temp += x * ten\n // ten *= 10\n temp = add(temp, mul(x, ten))\n rs[i] = temp\n // trs.push(ten)\n ten = mul(ten, 10)\n }\n// console.log(rs)\n //\n const first = Array(9).fill(0)\n .map(() => [])\n for (let i = n - 1; i - w + 1 >= 0; i--) {\n const x = range(i - w + 1, i)\n // console.log(str.slice(i - w + 1, i + 1), x)\n // first[x] = i - w + 1\n first[x].unshift(i - w + 1)\n }\n // console.log(first)\n return qs.map(([l, r, k]) => {\n // v1 * vlr + v2 = k\n const vlr = range(l - 1, r - 1)\n let l1 = Infinity, l2 = Infinity\n for (let v1 = 0; v1 < 9; v1++) {\n if (first[v1].length) {\n const v2 = minus(k, mul(v1, vlr))\n // console.log(v1, v2)\n if (first[v2].length) {\n let a = first[v1][0]\n let b = first[v2][0]\n if (v1 === v2) {\n if (first[v1].length < 2) continue\n b = first[v1][1]\n }\n if (a < l1) {\n l1 = a\n l2 = b\n } else if (a === l1) {\n if (b < l2) {\n l2 = b\n }\n }\n }\n }\n }\n const ans = (l1 === Infinity || l2 === Infinity) ? [-1, -1] : [l1 + 1, l2 + 1]\n return ans.join(' ')\n }).join('\\n')\n\n function range(l, r) {\n return minus(rs[l], r + 1 < n ? rs[r + 1] : 0)\n }\n}\nconst MOD = 9\nfunction minus(a, b) {\n return add(add(a, -b), MOD)\n}\nfunction add(a, b) {\n return (a + b) % 9\n}\nfunction mul(a, b) {\n return (a * b) % 9\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const s = read();\r\n const [w, m] = rns();\r\n const pre = [];\r\n const mod = num => (num % 9 + 9) % 9;\r\n for (let i = 0; i < s.length; i++) {\r\n var _pre;\r\n pre[i] = mod(((_pre = pre[i - 1]) !== null && _pre !== void 0 ? _pre : 0) * 10 + Number(s[i]));\r\n }\r\n const query = (l, r) => {\r\n var _pre2;\r\n return mod(pre[r] - ((_pre2 = pre[l - 1]) !== null && _pre2 !== void 0 ? _pre2 : 0));\r\n };\r\n const v = [];\r\n for (let i = 0; i < s.length - w + 1; i++) {\r\n v[i] = query(i, i + w - 1);\r\n }\r\n const map = new Map();\r\n for (let i = 0; i < v.length; i++) {\r\n if (!map.has(v[i])) map.set(v[i], []);\r\n if (map.get(v[i]).length < 2) map.get(v[i]).push(i);\r\n }\r\n const res = [];\r\n for (let i = 0; i < m; i++) {\r\n const [l, r, k] = rns();\r\n const a = query(l - 1, r - 1);\r\n let ans = [-1, -1];\r\n const add = ([a, b]) => {\r\n if (ans[0] === -1 || ans[0] > a || ans[0] === a && ans[1] > b) {\r\n ans = [a, b];\r\n }\r\n };\r\n for (let j = 0; j < 9; j++) {\r\n if (!map.has(j)) continue;\r\n const t = mod(k - a * j);\r\n if (!map.has(t)) continue;\r\n if (j === t) {\r\n if (map.get(j).length < 2) continue;\r\n add(map.get(j));\r\n } else {\r\n add([map.get(j)[0], map.get(t)[0]]);\r\n }\r\n }\r\n res.push(ans.map(num => num !== -1 ? num + 1 : num).join(' '));\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rns = () => {\r\n return read().split(' ').filter(s => s !== '').map(Number);\r\n };\r\n const s = read();\r\n const [w, m] = rns();\r\n const pre = [];\r\n const mod = num => (num % 9 + 9) % 9;\r\n for (let i = 0; i < s.length; i++) {\r\n var _pre;\r\n pre[i] = mod(((_pre = pre[i - 1]) !== null && _pre !== void 0 ? _pre : 0) * 10 + Number(s[i]));\r\n }\r\n const query = (l, r) => {\r\n var _pre2;\r\n return mod(pre[r] - ((_pre2 = pre[l - 1]) !== null && _pre2 !== void 0 ? _pre2 : 0));\r\n };\r\n const v = [];\r\n for (let i = 0; i < s.length - w + 1; i++) {\r\n v[i] = query(i, i + w - 1);\r\n }\r\n const map = new Map();\r\n for (let i = 0; i < v.length; i++) {\r\n if (!map.has(v[i])) map.set(v[i], []);\r\n if (map.get(v[i]).length < 2) map.get(v[i]).push(i);\r\n }\r\n const res = [];\r\n for (let i = 0; i < m; i++) {\r\n const [l, r, k] = rns();\r\n const a = query(l - 1, r - 1);\r\n let ans = [-1, -1];\r\n const add = ([a, b]) => {\r\n if (a > b) [a, b] = [b, a];\r\n if (ans[0] === -1 || ans[0] > a || ans[0] === a && ans[1] > b) {\r\n ans = [a, b];\r\n }\r\n };\r\n for (let j = 0; j < 9; j++) {\r\n if (!map.has(j)) continue;\r\n const t = mod(k - a * j);\r\n if (!map.has(t)) continue;\r\n if (j === t) {\r\n if (map.get(j).length < 2) continue;\r\n add(map.get(j));\r\n } else {\r\n add([map.get(j)[0], map.get(t)[0]]);\r\n }\r\n }\r\n res.push(ans.map(num => num !== -1 ? num + 1 : num).join(' '));\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r\\n?/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "b67870dcffa7bad682ef980dacd1f3db"} {"source_code": "/* TEST CASE\ninput\n2\n50 50\noutput\n5.0000000000\ninput\n4\n50 20 20 10\noutput\n39.2846263444\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar p = new Array(n);\n\tvar f = new Array(n);\n\tvar splitted = readline().split(' ');\n\tvar i, g = 1.0;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar Pi = parseFloat(splitted[i]) / 100.0;\n\t\tp[i] = Pi;\n\t\tf[i] = Pi\n\t\tg *= Pi;\n\t}\n\t\n\tvar answer = g * n;\n\tvar x = n;\n\t\n\twhile (x++ < 300001) {\n var maxProb = 0;\n var id;\n for (i = 0; i < n; i++) {\n \tvar prob = p[i] * (1-f[i])/f[i]; \n if (prob > maxProb) {\n \tmaxProb = prob;\n id = i;\n } \n }\n f[id] += p[id] * (1 - f[id]);\n answer += x * g * maxProb;\n g *= (1 + maxProb);\n\t}\n\tprint(answer.toFixed(10));\n}\n\nmain();", "positive_code": [{"source_code": "/* TEST CASE\ninput\n2\n50 50\noutput\n5.0000000000\ninput\n4\n50 20 20 10\noutput\n39.2846263444\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar p = new Array(n);\n\tvar f = new Array(n);\n\tvar splitted = readline().split(' ');\n\tvar i, g = 1.0;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar Pi = parseFloat(splitted[i]) / 100.0;\n\t\tp[i] = Pi;\n\t\tf[i] = Pi\n\t\tg *= Pi;\n\t}\n\t\n\tvar answer = g * n;\n\tvar x = n;\n\t\n\twhile (x++ < 300001) {\n var maxProb = 0;\n var id;\n for (i = 0; i < n; i++) {\n if (p[i] * (1-f[i])/f[i] > maxProb) {\n \tmaxProb = p[i] * (1-f[i])/f[i];\n id = i;\n } \n }\n f[id] += p[id] * (1 - f[id]);\n answer += x * g * maxProb;\n g *= (1.0 + maxProb);\n\t}\n\tprint(answer.toFixed(10));\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n2\n50 50\noutput\n5.0000000000\ninput\n4\n50 20 20 10\noutput\n39.2846263444\n */\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar p = new Array(n);\n\tvar f = new Array(n);\n\tvar splitted = readline().split(' ');\n\tvar i, g = 1.0;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar Pi = parseFloat(splitted[i]) / 100.0;\n\t\tp[i] = Pi;\n\t\tf[i] = Pi\n\t\tg *= Pi;\n\t}\n\t\n\tvar answer = g * n;\n\tvar x = n;\n\t\n\twhile (x++ < 300001) {\n var tmp = 0;\n var id;\n for (i = 0; i < n; i++) {\n if (p[i] * (1-f[i])/f[i] + 1 > tmp) {\n tmp = p[i] * (1-f[i])/f[i] + 1;\n id = i;\n } \n }\n f[id] += p[id] * (1 - f[id]);\n answer += x * g * (tmp - 1);\n g *= tmp;\n\t}\n\tprint(answer.toFixed(10));\n}\n\nmain();"}], "negative_code": [], "src_uid": "afcd217811ca5853179e5a936b4633fe"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const result = [];\n const map = arr.reduce((obj, num) => {\n if (!obj[num]) {\n obj[num] = 1;\n result.push(num);\n }\n return obj;\n }, {});\n console.log(result.join(\" \"));\n }\n}\n", "positive_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\n\nfunction functions() {\n rl.question(\"\", function (n) {\n rl.question(\"\", function (num) {\n var arr = num.split(' ');\n var l = [];\n for (var i = 0; i < n * 2; i++) {\n for (var j = 0; j < arr.length; j++) {\n var lhas = l.includes(arr[j])\n if (!lhas) {\n l.push(arr[j]);\n\n }\n }\n }\n console.log(l.join(' '));\n functions();\n });\n })\n}\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n \n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = [];\n\tfor(var i = 0; i < t; i++){\n\t\tvar N = nextInt();\n\t\tvar list = nextIntArray();\n\t\tvar out = [];\n\t\tfor(var j = 0; j < list.length; j++){\n\t\t\tif(out.indexOf(list[j]) == -1){\n\t\t\t\tout.push(list[j]);\n\t\t\t}\n\t\t}\n\t\toutput[i] = myconv(out,8);\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 2;\n\tlet i = 1;\n\twhile (i <= testCases) {\n let n = data[i] * 1;\n let a = data[i + 1].trim().split(' ');\n let str = a[0]\n let obj = {};\n obj[str] = true;\n for (let i = 1; i < a.length; i += 1) {\n if (obj[a[i]]) {}\n else {\n obj[a[i]] = true;\n str += ' ' + a[i];\n }\n }\n console.log(str);\n i += 2;\n\t}\n}"}, {"source_code": "const processData = (lines) => {\n let num = 0;\n const n = +lines[num++];\n for (let i = 0; i < n; i++) {\n num++;\n const line = lines[num++].split(\" \").map((x) => +x); //\u8f6c\u6570\u5b57\n const map = new Map();\n const res = [];\n line.forEach((element) => {\n if (map.get(element) === undefined) {\n map.set(element, 1);\n res.push(element);\n }\n });\n console.log(res.join(\" \"));\n }\n};\n\nlet i = \"\";\nprocess.stdin.on(\"data\", (c) => (i += c));\nprocess.stdin.on(\"end\", () => {\n const { EOL } = require(\"os\"); //\u83b7\u53d6\u6362\u884c\u7b26\n const lines = i.split(EOL);\n processData(lines);\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testcases = parseInt(readline());\n\tfor (let i = 0; i < testcases; i++) {\n\t\tconst l = parseInt(readline());\n\t\tconst merged = readline().split(' ').map(i => parseInt(i))\n\t\tconst unique = Array.from(new Set([...merged]))\n\t\tconsole.log(unique.join(' '))\n\t}\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc++]\n for (let i=0; i +x)\n\n const map = {}\n const res = []\n for (const t of p) {\n if (!map[t]) {\n map[t] = 1\n res.push(t)\n }\n }\n console.log(res.join(' '))\n }\n\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "\"use strict\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nfunction print(x) {\n console.log(x);\n}\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\nprocess.stdin.on(\"end\", () => {\n inputString = inputString.split(\"\\n\");\n main();\n});\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// ************************ Code Start ***************************\n\nfunction main() {\n\n var tc = parseInt(readline());\n while (tc--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n var unique = Array.from(new Set([...ar]));\n print(unique.join(' '));\n }\n \n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var t = +readLine();\n\n for (var i = 0; i < t; i++) {\n var n = +readLine();\n var arr = readLine().split(\" \").map(Number);\n const uni = [...new Set(arr)];\n console.log(uni.join(\" \"));\n }\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n\n\n\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n if (lineCount == 0) {\n // first line\n testCount = parseInt(input)\n }\n else if(lineCount%2==1){\n //do nothing?\n }\n else if (lineCount >= 2*testCount) {\n outputStr += compute(input) + '\\n'\n console.log(outputStr)\n rl.close()\n }\n else {\n // data\n outputStr += compute(input) + '\\n'\n }\n lineCount++\n});\n\nfunction compute(str) {\n var list = str.split(' ')\n\n var tmplist = []\n\n var resultstr = ''\n\n for(var item of list){\n if(tmplist[item]){\n // already exist\n continue\n }\n resultstr += `${item} `\n tmplist[item] = true\n }\n return resultstr\n}"}, {"source_code": "function solve() {\n var n = Number(read());\n var arr = readArray(Number);\n var ans = [];\n var s = {};\n for (var i = 0; i < (n << 1); i++) {\n if (s[arr[i]]) {\n ans.push(arr[i]);\n } else {\n s[arr[i]] = true;\n }\n }\n write(ans.join(' '));\n}\n\nfunction init() {\n var T;\n T = 1;\n T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\nfunction sortF(a, b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n}\n\nfunction readArray(f) {\n return read().split(' ').map(f);\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n\n var inTextName;\n var outTextName;\n\n var needWriteFile = false;\n\n var writeResult = '';\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n\n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n if (needWriteFile) {\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\n err ? console.error(err) : console.log('good')\n });\n }\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n\n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n\n RL.on('close', init);\n }\n} else {\n init();\n}\n\nfunction write(value) {\n if (needWriteFile) {\n writeResult += value + '\\n';\n return;\n }\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "var tc = parseInt(readline());\nwhile (tc--) {\n var n = parseInt(readline());\n var ar = readline().split(' ').map(x => parseInt(x));\n var unique = Array.from(new Set([...ar]));\n print(unique.join(' '));\n}\n \n"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question(\"\", function (n) {\n functions();\n})\n\nfunction functions() {\n rl.question(\"\", function (n) {\n rl.question(\"\", function (num) {\n var arr = num.split(' ');\n var l = [];\n for (var i = 0; i < n * 2; i++) {\n for (var j = 0; j < arr.length; j++) {\n var lhas = l.includes(arr[j])\n if (!lhas) {\n l.push(arr[j]);\n }\n }\n }\n console.log(l);\n functions();\n });\n })\n}\n// rl.question('', function (o) {\n// rl.question('', function (n) {\n// rl.question('', function (a) {\n// rl.question('', function (b) {\n// var s = 0;\n// var sa = a.split(' ');\n// var sb = b.split(' ');\n// // console.log(n, newA, s, sa, sb)\n// for (var i = 0; i < n; i++) {\n// var newA = [];\n// var ai = sa[i] - Math.min.apply(Math, sa)\n// var bi = sb[i] - Math.min.apply(Math, sb)\n// newA.push(ai);\n// newA.push(bi);\n// s += Math.max.apply(Math, newA);\n// }\n// console.log(s)\n// functions();\n// })\n// })\n// })\n// })\n"}], "src_uid": "aaf91874cf5aa0fa302ffed2ccecdc76"} {"source_code": "/// \n/// \nfunction ints() {\n var s = readline();\n return s.split(' ').map(function (x) { return parseInt(x); });\n}\nfunction array(length, value) {\n var result = new Array(length);\n for (var i = 0; i < length; i++) {\n result[i] = value();\n }\n return result;\n}\nvar _a = ints(), n = _a[0], m = _a[1];\nvar adj = array(n + 1, function () { return array(n + 1, function () { return false; }); });\nvar edges = [];\nvar degree = array(n + 1, function () { return 0; });\nfor (var i = 0; i < m; i++) {\n var _b = ints(), a = _b[0], b = _b[1];\n adj[a][b] = true;\n adj[b][a] = true;\n ++degree[a];\n ++degree[b];\n edges.push({ first: a, second: b });\n}\nvar best = 6000;\nfor (var _i = 0; _i < edges.length; _i++) {\n var x = edges[_i];\n var first = x.first, second = x.second;\n for (var i = 1; i <= n; i++) {\n if (first != i && second != i && adj[first][i] && adj[second][i]) {\n var current = degree[first] + degree[second] + degree[i];\n if (best > current)\n best = current;\n }\n }\n}\nif (best == 6000)\n best = -1;\nelse\n best -= 6;\nprint(best);\n", "positive_code": [{"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n\tvar sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};\n\tfor (i = 0; i < n; i++) {\n\t\tnodes[i].neighbors.sort(sorter);\n\t}\n\tnodes.sort(sorter);\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tif (node1.neighbors.length - 2 >= ret) {\n\t\t\tbreak;\n\t\t}\n\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\n\t\t\tif (node1.neighbors.length + node2.neighbors.length - 4 >= ret) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null)\n\t\t\t\t\tret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n\tvar sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};\n//\tfor (i = 0; i < n; i++) {\n//\t\tnodes[i].neighbors.sort(sorter);\n//\t}\n\tnodes.sort(sorter);\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tif (node1.neighbors.length - 2 >= ret) {\n\t\t\tbreak;\n\t\t}\n\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\n\t\t\tif (node1.neighbors.length + node2.neighbors.length - 4 < ret) {\n\t\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null)\n\t\t\t\t\t\tret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tvar n1 = node1.neighbors.length; \n\t\tif (n1 - 2 < ret) {\n\t\t\tfor (j = 0; j < n1; j++) {\n\t\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\tvar n2 = node2.neighbors.length; \n\t\t\t\t\n\t\t\t\tif (n1 + n2 - 4 < ret) {\n\t\t\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null) {\n\t\t\t\t\t\t\tret = Math.min(ret, n1 + n2 + node3.neighbors.length - 6); \n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tvar n1 = node1.neighbors.length; \n\t\tif (n1 - 2 < ret) {\n\t\t\tfor (j = 0; j < n1; j++) {\n\t\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\tvar n2 = node2.neighbors.length; \n\t\t\t\t\n\t\t\t\tif (n1 + n2 - 4 < ret) {\n\t\t\t\t\tfor (k = 0; k < n2; k++) {\n\t\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null) {\n\t\t\t\t\t\t\tret = Math.min(ret, n1 + n2 + node3.neighbors.length - 6); \n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret < Infinity ? ret : -1;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tif (node1.neighbors.length - 2 < ret) {\n\t\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\t\n\t\t\t\tif (node1.neighbors.length + node2.neighbors.length - 4 < ret) {\n\t\t\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null) {\n\t\t\t\t\t\t\tvar newRecognitions = node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6; \n\t\t\t\t\t\t\tif (ret > newRecognitions) {\n\t\t\t\t\t\t\t\tret = newRecognitions;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0], 10);\nvar m = parseInt(input[1], 10);\n\nwarriors = [];\ndeg = [];\n\nfor(var i = 0; i < n; i++) {\n var fill = [];\n for(var j = 0; j < n; j++) {\n fill.push(false);\n }\n warriors.push(fill);\n deg.push(0);\n}\n\nfor(var i = 0; i < m; i++) {\n input = readline().split(' ');\n var a = parseInt(input[0], 10);\n var b = parseInt(input[1], 10);\n warriors[a - 1][b - 1] = true;\n warriors[b - 1][a - 1] = true;\n deg[a - 1] += 1;\n deg[b - 1] += 1;\n}\n\nvar result = 100000000000;\n\nfor(var i = 0; i < n; i++) {\n for(var j = i + 1; j < n; j++) {\n if (warriors[i][j]) {\n for(var k = j + 1; k < n; k++) {\n if (warriors[i][k] && warriors[j][k]) {\n var sum = deg[i] + deg[j] + deg[k];\n result = Math.min(result, sum);\n }\n }\n }\n }\n}\n\nresult === 100000000000 ? print('-1') : print(result - 6);"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes, adjMap) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n//\tvar sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};\n//\tfor (i = 0; i < n; i++) {\n//\t\tnodes[i].neighbors.sort(sorter);\n//\t}\n//\tnodes.sort(sorter);\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tif (node1.neighbors.length - 2 < ret) {\n\t\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\t\n\t\t\t\tif (node1.neighbors.length + node2.neighbors.length - 4 < ret) {\n\t\t\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null)\n\t\t\t\t\t\t\tret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\tvar adjMap = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes, adjMap);\n\tprint(answer);\n}\n\nmain();"}], "negative_code": [{"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes, adjMap) {\n\tvar ret = Infinity;\n\tvar n = nodes.length;\n\tvar i, j, k;\n//\tvar sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};\n//\tfor (i = 0; i < n; i++) {\n//\t\tnodes[i].neighbors.sort(sorter);\n//\t}\n//\tnodes.sort(sorter);\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tif (node1.neighbors.length < ret) {\n\t\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\t\n\t\t\t\tif (node1.neighbors.length + node2.neighbors.length < ret) {\n\t\t\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\t\t\tif (node3.adjMap[node1.nodeIndex] != null)\n\t\t\t\t\t\t\tret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn ret == Infinity ? -1 : ret;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\tvar adjMap = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[u].adjMap[v] = dummyObj;\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t\tnodes[v].adjMap[u] = dummyObj;\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes, adjMap);\n\tprint(answer);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\noutput\n2\n\ninput\n7 4\n2 1\n3 6\n5 1\n1 7\noutput\n-1\n\n*/\nfunction minimumSumOfRecogitions(nodes, adjMap) {\n\tvar n = nodes.length;\n\tvar i, j, k;\n\tvar sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};\n\tfor (i = 0; i < n; i++) {\n\t\tnodes[i].neighbors.sort(sorter);\n\t}\n\tnodes.sort(sorter);\n\t\n\tfor (i = 0; i < n; i++) {\n\t\tvar node1 = nodes[i];\n\t\tfor (j = 0; j < node1.neighbors.length; j++) {\n\t\t\tvar node2 = node1.neighbors[j];\n\t\t\t\n\t\t\tfor (k = 0; k < node2.neighbors.length; k++) {\n\t\t\t\tvar node3 = node2.neighbors[k];\n\t\t\t\tif (adjMap[Math.min(node3.nodeIndex, node1.nodeIndex) + \":\" + Math.max(node3.nodeIndex, node1.nodeIndex)] != null)\n\t\t\t\t\treturn node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn -1;\n}\n\nfunction main() {\n\tvar splitted = readline().split(' ');\n\tvar n = parseInt(splitted[0]);\n\tvar m = parseInt(splitted[1]);\n\tvar nodes = new Array(n);\n\tvar i;\n\tvar u, v;\n\tvar dummyObj = {};\n\tvar adjMap = {};\n\n\tfor (u = 0; u < n; u++) {\n\t\tnodes[u] = {nodeIndex: u, neighbors: []};\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tu = parseInt(splitted[0]) - 1;\n\t\tv = parseInt(splitted[1]) - 1;\n\t\tif (u != v) {\n\t\t\tnodes[u].neighbors.push(nodes[v]);\n\t\t\tnodes[v].neighbors.push(nodes[u]);\n\t\t\tadjMap[Math.min(u, v) + \":\" + Math.max(u, v)] = dummyObj;\n\t\t}\n\t}\n\n\tvar answer = minimumSumOfRecogitions(nodes, adjMap);\n\tprint(answer);\n}\n\nmain();"}], "src_uid": "24a43df3e6d2af348692cdfbeb8a195c"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const inp = getInts()\n let s = getLine()[0]\n solve(s, ...inp)\n}\n\nfunction solve (s, k, a, b) {\n let n = s.length\n const dp = []\n for (let i = 0; i <= k; ++i) {\n dp.push([])\n }\n\n for (let i = 0; i <= k; ++i) {\n for (let j = 0; j <= n; ++j) {\n dp[i][j] = 0\n }\n }\n \n for (let i = a; i <= b; ++i) dp[1][i] = 1\n\n for (let i = 2; i <= k; ++i) {\n for (let j = i * a; j <= i * b && j <= n; ++j) {\n dp[i][j] = 1\n }\n }\n\n if (dp[k][n] === 0) print('No solution')\n else {\n const path = []\n for (let i = k; i > 1; --i) {\n for (let j = a; j <= b; ++j) {\n const val = n - j\n if (dp[i - 1][val]) {\n path.push(j)\n n -= j\n break\n }\n }\n }\n\n path.push(n)\n let ind = 0\n for (let i in path) {\n print(s.slice(ind, ind + path[i]))\n ind += path[i]\n }\n }\n}\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar isValid = function(s,pieces,len,minLen,maxLen){\n let sLen = s.length;\n let temp = sLen-len*(pieces-1);\n return temp>=minLen && temp<=maxLen;\n}\nvar indicator=0,minLen,maxLen,pieces,temp=[];\n\n\nrl.on('line', (input) => {\n if(indicator==0){\n temp = input.split(' ').map(item => parseInt(item));\n pieces = temp[0];\n minLen = temp[1];\n maxLen = temp[2];\n indicator++;\n }\n else{\n let i=minLen;\n for( ;i<=maxLen;i++)\n if(isValid(input,pieces,i,minLen,maxLen)) break;\n\n if(i==maxLen+1) console.log(\"No solution\");\n else{\n /**\n * 0123456789..\n * abrakadabra\n */\n let startIndex=0;\n for(let j=0;j readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\nconst dp = {}\n\nmain()\n\nfunction main() {\n const inp = getInts()\n let s = getLine()[0]\n const n = s.length\n\n const possible = solve(n, ...inp)\n if (!possible) print('No solution')\n else {\n let curN = n\n let curK = inp[0]\n let a = inp[1]\n const b = inp[2]\n while (a <= b) {\n const ok = solve(curN - a, curK - 1, a, b)\n if (ok) {\n print(s.slice(0, a))\n s = s.slice(a)\n curN -= a\n curK --\n }\n a ++\n }\n }\n}\n\nfunction solve (n, k, a, b) {\n if (n <= 0) {\n return n === 0 && k === 0\n }\n\n if (Object.hasOwnProperty(dp, [n, k])) return dp[[n, k]]\n\n let ans = 0\n for (let i = a; i <= b; ++i) {\n ans += solve(n - i, k - 1, a, b)\n }\n\n return dp[[n, k]] = ans\n}"}], "src_uid": "75633f47c1fbde571aa2936bf2639289"} {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar n = 0;\n\tfor(i = 1; i <= t * 2; i++){\n\t if(i % 2 == 1){\n\t n = lines[i];\n\t }else{\n\t var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n\t var v = [];\n\t var ans = '';\n\t for(j = 1; j <= n; j++){\n\t if(a[j] != a[j - 1]){\n\t ans += a[j - 1] + ' ';\n\t }else{\n\t v.push(a[j - 1]);\n\t }\n\t }\n\t for(j = 0; j < v.length; j++){\n\t ans += v[j] + ' ';\n\t }\n\t console.log(ans);\n\t }\n\t}\n});\n\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var ans = []\r\n var mark = new Array(n).fill(false)\r\n for (let j = 0; j < 103; j++) {\r\n for (let k = 0; k < 103; k++) {\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === k && !mark[i]) {\r\n ans.push(a[i])\r\n mark[i] = true\r\n break\r\n }\r\n }\r\n }\r\n }\r\n console.log(ans.join(' '))\r\n });\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nvar standardInputString = \"\";\nvar currentLine = 0;\n\nfunction readline() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction main() {\n let t = +readline();\n while (t--) {\n let n = +readline();\n let arr = readline()\n .split(\" \")\n .map((val) => +val);\n let map = Array.from({ length: 101 }).fill(0);\n let ans = [];\n for (let i = 0; i < arr.length; ++i) {\n map[arr[i]]++;\n }\n for (let i = 0; i <= 100; ++i) {\n if (map[i] > 0) {\n ans.push(i);\n map[i]--;\n }\n }\n\n for (let i = 0; i <= 100; ++i) {\n for (let j = 0; j < map[i]; ++j) {\n ans.push(i);\n }\n }\n console.log(ans.join(\" \"));\n }\n}\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const cases = parseInt(lines[0]);\r\n \r\n let prevLetter;\r\n for (let i = 2; i < cases * 2 + 1; i += 2) {\r\n const line = lines[i];\r\n const numbers = line.split(' ').map(t => parseInt(t.trim()));\r\n \r\n const sorted = numbers.slice().sort((a, b) => a - b);\r\n \r\n const prev = [];\r\n const append = [];\r\n for (let j = 0; j < sorted.length; j++) {\r\n const num = sorted[j];\r\n if (!prev.includes(num)) {\r\n prev.push(num);\r\n } else {\r\n append.push(num);\r\n }\r\n }\r\n console.log([...prev, ...append].join(' '));\r\n }\r\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n arr.sort((a, b) => a - b)\r\n const res = [], res2 = []\r\n let temp = -1\r\n arr.forEach(i => {\r\n if (i !== temp) res.push(i)\r\n else res2.push(i)\r\n temp = i\r\n })\r\n console.log(res.join(' '), res2.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i][0], inputArr[i + 1])\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tvar output = [];\r\n\t\tvar ato = [];\r\n\t\tvar now = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] == now){\r\n\t\t\t\toutput.push(list[j]);\r\n\t\t\t\tnow++;\r\n\t\t\t}else{\r\n\t\t\t\tato.push(list[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\toutput = output.concat(ato);\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, a) => {\r\n let m = new Map();\r\n for (const e of a) {\r\n m.set(e, m.get(e) + 1 || 1);\r\n }\r\n m = sortMapByKey(m);\r\n let res = Array.from(m.keys());\r\n for (const [k, v] of m) {\r\n if (v == 1) continue;\r\n for (let i = 1; i <= v - 1; i++) {\r\n res.push(k);\r\n }\r\n }\r\n pr(res.join(\" \"));\r\n};\r\n\r\nconst sortMapByKey = (map) => {\r\n return new Map([...map].sort((a, b) => a[0] - b[0]));\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var t = parseInt(readline());\r\nwhile (t--) {\r\n var mystring = \"\";\r\n var n = parseInt(readline());\r\n var arr = readline().split(\" \").map(function(x) {return parseInt(x)});\r\n var count = new Array(110).fill(0);\r\n for (var i = Number(0); i < n; i++) {\r\n count[arr[i]]++;\r\n }\r\n for (var i = 0; i < 110; i++) {\r\n if (count[i] > 0) {\r\n mystring = mystring + i + \" \";\r\n count[i]--;\r\n }\r\n }\r\n for (var i = 0; i < 110; i++) {\r\n while (count[i] > 0) {\r\n mystring = mystring + i + \" \";\r\n count[i]--;\r\n }\r\n }\r\n print(mystring)\r\n}"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var ans = []\r\n var mark = new Array(n).fill(false)\r\n for (let j = 0; j < 102; j++) {\r\n for (let k = 0; k < 100; k++) {\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === k && !mark[i]) {\r\n ans.push(a[i])\r\n mark[i] = true\r\n break\r\n }\r\n }\r\n }\r\n }\r\n console.log(ans.join(' '))\r\n });\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var n = parseInt(readline())\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var ans = []\r\n var mark = new Array(n).fill(false)\r\n for (let j = 0; j < 100; j++) {\r\n for (let k = 0; k < 100; k++) {\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === k && !mark[i]) {\r\n ans.push(a[i])\r\n mark[i] = true\r\n break\r\n }\r\n }\r\n }\r\n }\r\n console.log(ans.join(' '))\r\n });\r\n\r\n}\r\n\r\n\r\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nvar standardInputString = \"\";\nvar currentLine = 0;\n\nfunction readline() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction main() {\n let t = +readline();\n while (t--) {\n let n = +readline();\n let arr = readline()\n .split(\" \")\n .map((val) => +val);\n let map = Array.from({ length: 101 }).fill(0);\n let ans = [];\n for (let i = 0; i < arr.length; ++i) {\n map[arr[i]]++;\n }\n for (let i = 0; i <= 100; ++i) {\n if (map[i] > 0) {\n ans.push(i);\n map[i]--;\n }\n }\n\n for (let i = 0; i <= 100; ++i) {\n for (let j = 0; j < map[i]; ++j) {\n ans.push(i);\n }\n }\n console.log(ans);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nvar standardInputString = \"\";\nvar currentLine = 0;\n\nfunction readline() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction main() {\n let t = +readline();\n while (t--) {\n let n = +readline();\n let arr = readline()\n .split(\" \")\n .map((val) => +val);\n let count = {};\n for (let i = 0; i < arr.length; ++i) {\n if (count[arr[i]]) count[arr[i]]++;\n else {\n count[arr[i]] = 1;\n }\n }\n let ans = [];\n for (let i = 0; i < arr.length; ++i) {\n if (count[arr[i]] === 1) ans.push(arr[i]);\n }\n for (let i = 0; i < arr.length; ++i) {\n if (count[arr[i]] > 1) ans.push(arr[i]);\n }\n console.log(ans);\n }\n}\n"}, {"source_code": "let y = '';\nprocess.stdin.on('data', c => y += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = y.split(EOL);\n\tvar t = lines[0];\n\tvar e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i] * 2;\n }else{\n var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});\n var start = 0;\n var end = e - 1;\n var ans = '';\n while(start < end){\n ans += k[start] + ' ';\n start++;\n if(start > end){\n break;\n }\n ans += k[end] + ' ';\n end--;\n if(start > end){\n break;\n }\n }\n console.log(ans);\n }\n }\n});\n\n"}, {"source_code": "let input = '';\r\nprocess.stdin.on('data', (c) => {\r\n input += c;\r\n});\r\n \r\nprocess.stdin.on('end', () => {\r\n const lines = input.split('\\n');\r\n const cases = parseInt(lines[0]);\r\n \r\n let prevLetter;\r\n for (let i = 2; i < cases * 2 + 1; i += 2) {\r\n const line = lines[i];\r\n const numbers = line.split(' ').map(t => parseInt(t.trim()));\r\n \r\n const sorted = numbers.slice().sort((a, b) => a - b);\r\n \r\n let out = [];\r\n let prev = [];\r\n let append = [];\r\n let final = [];\r\n for (let j = 0; j < numbers.length; j++) {\r\n const num = numbers[j];\r\n if (!prev.includes(num)) {\r\n prev.push(num);\r\n out.push(num);\r\n out.sort((a, b) => a - b);\r\n } else {\r\n // out.push(numbers[j + 1]);\r\n out.sort((a, b) => a - b);\r\n append = numbers.slice(j + 1);\r\n final.push(num);\r\n break;\r\n }\r\n }\r\n console.log([...out, ...append.sort((a, b) => a - b), ...final.sort((a, b) => a - b)].join(' '));\r\n }\r\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve(n, arr) {\r\n arr.sort((a, b) => a - b)\r\n const res = [], res2 = []\r\n let temp = -1\r\n arr.forEach(i => {\r\n if (i !== temp) res.push(i)\r\n else res2.push(i)\r\n })\r\n console.log(res.join(' '), res2.join(' '))\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n solve(inputArr[i][0], inputArr[i + 1])\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tlist.sort(function(a,b){\r\n\t\t\treturn a - b;\r\n\t\t});\r\n\t\tmyout(myconv(list, 8));\r\n\t}\r\n}\r\n"}], "src_uid": "69838d9f9214c65b84a21d4eb546ea4b"} {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tlist[i] = nextCharArray();\r\n\t\t}\r\n\t\tvar output = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tvar zero = 0;\r\n\t\t\t\tvar one = 0;\r\n\t\t\t\tvar x = i + 1;\r\n\t\t\t\tvar y = j + 1;\r\n\t\t\t\tfor(var k = 0; k < 4; k++){\r\n\t\t\t\t\tif(list[y - 1][x - 1] == \"1\"){\r\n\t\t\t\t\t\tone++;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tzero++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tvar tmp = x;\r\n\t\t\t\t\tx = y;\r\n\t\t\t\t\ty = N - tmp + 1;\r\n\t\t\t\t}\r\n\t\t\t\toutput += Math.min(one, zero);\r\n\t\t\t\tfor(var k = 0; k < 4; k++){\r\n\t\t\t\t\tlist[y - 1][x - 1] = \"1\";\r\n\t\t\t\t\tvar tmp = x;\r\n\t\t\t\t\tx = y;\r\n\t\t\t\t\ty = N - tmp + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x)));\r\n }\r\n var mid = Math.floor((n+1)/2);\r\n var ans = 0;\r\n for (var r = 0; r < mid; r++) {\r\n if (n & 1 && r == mid-1) {\r\n continue;\r\n }\r\n for (var c = 0; c < mid; c++) {\r\n var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];\r\n ans += Math.min(sum, 4-sum);\r\n\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n\r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n \r\n})\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines.slice(l, l + n).map(str => str.trim())\n l += n\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let ans = 0\n const limit = Math.ceil(n / 2)\n for (let i = 0; i < limit; i++) {\n const t1 = []\n const t2 = []\n const t3 = []\n const t4 = []\n for (let j = 0; j < n - 1 - i * 2; j++) {\n // t1.push(arr[i][i + j])\n // t2.push(arr[i + j][n - 1 - i])\n // t3.push(arr[n - 1 - i][n - 1 - i - j])\n // t4.push(arr[n - 1 - i - j][i])\n const temp = [\n arr[i][i + j],\n arr[i + j][n - 1 - i],\n arr[n - 1 - i][n - 1 - i - j],\n arr[n - 1 - i - j][i]\n ]\n ans += cal(temp)\n }\n // console.log(t1, t2, t3, t4)\n }\n return ans\n}\nfunction cal(temp) {\n // console.log(temp)\n let c0 = 0, c1 = 0\n temp.forEach(x => {\n if (x === '0') c0++\n if (x === '1') c1++\n })\n return Math.min(c0, c1)\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = readline();\r\n let grid = [];\r\n for (let i = 0; i < n; i++) {\r\n grid[i] = readline().split('').map(Number);\r\n }\r\n\r\n let endLeft = Math.floor(n / 2);\r\n let endTop = Math.ceil(n / 2);\r\n\r\n const getAllSym = (row, col, n) => {\r\n // ROW, COLUMN\r\n return [\r\n [row, col],\r\n [col, n - row - 1],\r\n [n - row - 1, n - col - 1],\r\n [n - col - 1, row]\r\n ];\r\n }\r\n\r\n let steps = sum => {\r\n if (sum === 0 || sum === 4) {\r\n return 0;\r\n } else if (sum === 1 || sum === 3) {\r\n return 1;\r\n } else {\r\n return 2;\r\n }\r\n };\r\n\r\n let sumAllSym = (points, grid) => {\r\n return grid[points[0][0]][points[0][1]]\r\n + grid[points[1][0]][points[1][1]]\r\n + grid[points[2][0]][points[2][1]]\r\n + grid[points[3][0]][points[3][1]];\r\n };\r\n\r\n let res = 0;\r\n for (let left = 0; left < endLeft; left++) {\r\n for (let top = 0; top < endTop; top++) {\r\n let allSym = getAllSym(left, top, n);\r\n let sum = sumAllSym(allSym, grid);\r\n res += steps(sum);\r\n }\r\n }\r\n\r\n output(res);\r\n }\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str);\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < (n-1)/2; i++) {\r\n for (var j = 0; j < n/2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item === '0') {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}\r\n"}], "negative_code": [{"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n\r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n \r\n})\r\n"}, {"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n\r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n \r\n})\r\n"}, {"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n\r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n \r\n})\r\n"}, {"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n//Actual Code \r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n \r\n})\r\n"}, {"source_code": "//Setup\r\nlet i = ''\r\nlet input;\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n //console.log(lines); \r\n input=lines\r\n//Actual Code \r\n\r\n //Input Reading and var config\r\n var numTests = parseInt(input[0])\r\n var testCases = []\r\n var indexReading=1\r\n while(indexReading (valor === element && reps++));\r\n return reps;\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==2 ||\r\n numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==-2\r\n ){\r\n ans+=1\r\n }\r\n if(numReps(arrayChecking,\"0\")-numReps(arrayChecking,\"1\")==0){\r\n ans+=2\r\n }\r\n } \r\n \r\n }\r\n }\r\n \r\n console.log(ans)\r\n \r\n }\r\n})\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < (n-1)/2; i++) {\r\n for (var j = 0; j < n/2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n parseInt(item) === 0 && count0++;\r\n parseInt(item) === 1 && count1++;\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str);\r\n }\r\n print(matr);\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n print(kit);\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item === '0') {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(''));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var kitSum = kit.reduce((sum, elem) => sum + parseInt(elem), 0);\r\n \r\n ans += Math.min(kitSum, 4 - kitSum);\r\n }\r\n }\r\n \r\n print(ans);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str);\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item === '0') {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(''));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var kitSum = kit.reduce((sum, elem) => sum + parseInt(elem), 0);\r\n \r\n ans += Math.min(kitSum, n - kitSum);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2 + n%2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n parseInt(item) === 0 && count0++;\r\n parseInt(item) === 1 && count1++;\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n parseInt(item) === 0 && count0++;\r\n parseInt(item) === 1 && count1++;\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item == 0) {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (parseInt(item) === 0) {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n \r\n for (var p = 0; p < kit.length; p++) {\r\n if (parseInt(kit[p]) === 0) {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n }\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item === '0') {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n \r\nvar rotatedCoord = function (coord, n) {\r\n return [coord[1], n - 1 - coord[0]];\r\n}\r\n \r\nfor (var k = 0; k < t; k++) {\r\n var n = parseInt(readline());\r\n var matr = [];\r\n var ans = 0;\r\n \r\n for (var p = 0; p < n; p++) {\r\n var str = readline();\r\n matr.push(str.split(' '));\r\n }\r\n \r\n if (n === 1) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n for (var i = 0; i < n/2; i++) {\r\n for (var j = 0; j < n/2 + n%2; j++) {\r\n var coord90 = rotatedCoord([i, j], n);\r\n var coord180 = rotatedCoord(coord90, n);\r\n var coord270 = rotatedCoord(coord180, n);\r\n \r\n var kit = [\r\n matr[i][j], \r\n matr[coord90[0]][coord90[1]],\r\n matr[coord180[0]][coord180[1]],\r\n matr[coord270[0]][coord270[1]]\r\n ];\r\n \r\n var count0 = 0;\r\n var count1 = 0;\r\n kit.forEach(item => {\r\n if (item === 0) {\r\n count0++;\r\n } else {\r\n count1++;\r\n }\r\n })\r\n \r\n ans += Math.min(count0, count1);\r\n }\r\n }\r\n \r\n print(ans);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x)));\r\n }\r\n var mid = (n+1)/2;\r\n var ans = 0;\r\n for (var r = 0; r < mid; r++) {\r\n if (n & 1 && r == mid-1) {\r\n continue;\r\n }\r\n for (var c = 0; c < mid; c++) {\r\n var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];\r\n ans += Math.min(sum, 4-sum);\r\n\r\n }\r\n }\r\n print(ans);\r\n }"}, {"source_code": "var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x)));\r\n }\r\n var mid = (n+1)/2;\r\n var ans = 0;\r\n for (var r = 0; r < mid; r++) {\r\n for (var c = 0; c < mid; c++) {\r\n if (n & 1 && r == mid-1) {\r\n continue;\r\n }\r\n var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];\r\n ans += Math.min(sum, 4-sum);\r\n\r\n }\r\n }\r\n print(ans);\r\n }"}], "src_uid": "867b01e7141ef077964a8a0d4c6b762b"} {"source_code": "function sortNumber(a,b) {\n return a - b;\n}\n \n function sa(){\n var firstLine =readline().split(\" \"); \n var n1 = Math.min(Number(firstLine[1]), Number(firstLine[2]));\n var n2 = Math.max(Number(firstLine[1]), Number(firstLine[2]));\n var n = Number(firstLine[1]) + Number(firstLine[2]);\n var data = readline().split(\" \").map(Number);\n data.sort(sortNumber).reverse();\n var sum = 0;\n var sum1 = 0;\n var sum2 = 0;\n for(var i=0;i +e),\n\tn = input[0],\n\tn1 = input[1],\n\tn2 = input[2],\n\tA = readline().split(' ').map(e => +e).sort((a, b) => a - b),\n\tmin = Math.min(n1, n2),\n\tmax = n1 === min ? n2 : n1;\n\nlet opti = A.splice(-min).sum()/min;\nopti += A.splice(-max).sum()/max;\nwrite(opti.toFixed(6))\n"}, {"source_code": "var mainFunc = function(arr, amount1, amount2)\n\t{\n\t\tvar sum = function(arr, amount)\n\t\t{\n\t\t\tvar sumIn = 0;\n\t\t\tfor (var i = 0; i <= amount - 1; i++)\n\t\t\t{\n\t\t\t\tsumIn += arr[i];\n\t\t\t}\n\t\t\tsumIn /= amount;\n\t\t\treturn sumIn;\n\t\t}\n\t\tarr = arr.slice(0, amount1 + amount2 + 1);\n\t\tif (amount1 < amount2)\n\t\t\t{\n\t\t\t\tvar sumAmount1 = sum(arr, amount1);\n\t\t\t\tarr = arr.slice(amount1, arr.length);\n\t\t\t\tvar sumAmount2 = sum(arr, amount2);\n\t\t\t\treturn sumAmount1 + sumAmount2;\t\n\t\t\t}\n\t\telse \n\t\t\t{\n\t\t\t\tvar sumAmount1 = sum(arr, amount2);\n\t\t\t\tarr = arr.slice(amount2, arr.length);\n\t\t\t\tvar sumAmount2 = sum(arr, amount1);\n\t\t\t\treturn sumAmount1 + sumAmount2;\t\n\t\t\t}\n\t}\n\n\n\nvar decrease = function(a,b)\n\t{\n\t\treturn b - a;\n\t}\nvar toArrayNumber = function(arr)\n\t{\n\t\tfor (var i = 0; i <= arr.length - 1; i++)\n\t\t{\n\t\t\tarr[i] = +arr[i];\n\t\t}\n\t\treturn arr;\n\t}\n\n\n\n\n{\nvar input1 = readline();\ninput1 = input1.split(' ');\nvar num1 = +input1[1], num2 = +input1[2];\nvar input2 = readline();\ninput2 = input2.split(' ');\ninput2 = toArrayNumber(input2);\ninput2 = input2.sort(decrease);\nprint(mainFunc(input2, num1, num2).toFixed(8));\n\n\n}"}, {"source_code": "function main() {\n var number1 = readline().split(' ');\n var a = readline().split(' ').map(function(val){return val * 1;});\n var n = number1[0], n1 = number1[1], n2 = number1[2];\n a.sort(function(a, b){return a - b});\n \n var sum1 = 0;\n for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {\n sum1 += a[i];\n }\n \n var sum2 = 0;\n for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {\n sum2 += a[j];\n }\n \n print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));\n}\n\nmain();"}, {"source_code": "function main(){\n var numbers = readline().split(\" \");\n var max = Math.max(numbers[1],numbers[2]);\n var min = Math.min(numbers[1],numbers[2]);\n \n var vals = readline()\n .split(\" \")\n .map(function(a){return a*1})\n .sort(function(a,b){return b-a});\n\n //print(JSON.stringify(vals))\n\n var avg1 = 0;\n var avg2 = 0;\n \n for(var i=0;i b - a );\n var sum;\n if ( n1 < n2 ) {\n sum = a.slice( 0, n1 ).reduce( (a,b) => a + b, 0 ) / n1 + a.slice( n1, n2 + n1 ).reduce( (a,b) => a + b, 0 ) / n2;\n } else {\n sum = a.slice( 0, n2 ).reduce( (a,b) => a + b, 0 ) / n2 + a.slice( n2, n1 + n2 ).reduce( (a,b) => a + b, 0 ) / n1;\n }\n return sum;\n};\n\nvar input = readline().split( \" \" ).map( i => parseInt( i, 10 ) );\nvar n = input[ 0 ];\nvar n1 = input[ 1 ];\nvar n2 = input[ 2 ];\nvar a = readline().split( \" \" ).map( i => parseInt( i, 10 ) );\n\nprint( maxAveragesSum( n1, n2, a ) );\n"}], "negative_code": [{"source_code": "var mainFunc = function(arr, amount1, amount2)\n\t{\n\t\tvar sum = function(arr, amount)\n\t\t{\n\t\t\tvar sumIn = 0;\n\t\t\tfor (var i = 0; i <= amount - 1; i++)\n\t\t\t{\n\t\t\t\tsumIn += arr[i];\n\t\t\t}\n\t\t\tsumIn /= amount;\n\t\t\treturn sumIn;\n\t\t}\n\t\tarr = arr.slice(0, amount1 + amount2 + 1);\n\t\tif (amount1 < amount2)\n\t\t\t{\n\t\t\t\tvar sumAmount1 = sum(arr, amount1);\n\t\t\t\tarr = arr.slice(amount1 + 1, arr.length - 1);\n\t\t\t\tvar sumAmount2 = sum(arr, amount2);\n\t\t\t\treturn sumAmount1 + sumAmount2;\t\n\t\t\t}\n\t\telse \n\t\t\t{\n\t\t\t\tvar sumAmount1 = sum(arr, amount2);\n\t\t\t\tarr = arr.slice(amount2, arr.length);\n\t\t\t\tvar sumAmount2 = sum(arr, amount1);\n\t\t\t\treturn sumAmount1 + sumAmount2;\t\n\t\t\t}\n\t}\n\n\n\nvar decrease = function(a,b)\n\t{\n\t\treturn b - a;\n\t}\nvar toArrayNumber = function(arr)\n\t{\n\t\tfor (var i = 0; i <= arr.length - 1; i++)\n\t\t{\n\t\t\tarr[i] = +arr[i];\n\t\t}\n\t\treturn arr;\n\t}\n\n\n\n\n{\nvar input1 = readline();\ninput1 = input1.split(' ');\nvar num1 = +input1[1], num2 = +input1[2];\nvar input2 = readline();\ninput2 = input2.split(' ');\ninput2 = toArrayNumber(input2);\ninput2 = input2.sort(decrease);\nprint(mainFunc(input2, num1, num2).toFixed(8));\n\n\n}"}, {"source_code": "\n \n function sa(){\n var firstLine =readline().split(\" \"); \n var n1 = Math.min(Number(firstLine[1]), Number(firstLine[2]));\n var n2 = Math.max(Number(firstLine[1]), Number(firstLine[2]));\n var n = Number(firstLine[1]) + Number(firstLine[2]);\n var data = readline().split(\" \").map(Number);\n data.sort().reverse();\n print(data);\n var sum = 0;\n var sum1 = 0;\n var sum2 = 0;\n for(var i=0;i= a.length - Math.min(n1, n2); --i) {\n sum1 += a[i] * 1;\n }\n \n var sum2 = 0;\n for (var i = a.length - 1 - Math.min(n1, n2); i >= a.length - n1 - n2; --i) {\n sum2 += a[i] * 1;\n }\n \n print(sum1, sum2);\n print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));\n}\n\nmain();"}, {"source_code": "function main() {\n var number1 = readline().split(' ');\n var a = readline().split(' ');\n var n = number1[0], n1 = number1[1], n2 = number1[2];\n a.sort();\n \n var sum1 = 0;\n for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {\n sum1 += a[i] * 1;\n }\n \n var sum2 = 0;\n for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {\n sum2 += a[j] * 1;\n }\n \n print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));\n}\n\nmain();"}, {"source_code": "function main() {\n var number1 = readline().split(' ');\n var a = readline().split(' ').map(function(val){return val * 1;});\n var n = number1[0], n1 = number1[1], n2 = number1[2];\n a.sort();\n \n var sum1 = 0;\n for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {\n sum1 += a[i];\n }\n \n var sum2 = 0;\n for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {\n sum2 += a[j];\n }\n \n print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));\n}\n\nmain();"}, {"source_code": "function main(){\n var numbers = readline().split(\" \");\n var max = Math.max(numbers[1],numbers[2]);\n var min = Math.min(numbers[1],numbers[2]);\n \n var vals = readline().split(\" \").map(function(a){return a*1}).sort(function(a,b){return a +e),\n\tn = input[0],\n\tn1 = input[1],\n\tn2 = input[2],\n\tA = readline().split(' ').map(e => +e).sort(),\n\tmin = Math.min(n1, n2),\n\tmax = n1 === min ? n2 : n1;\n\nlet opti = A.splice(-min).sum()/min;\nopti += A.splice(-max).sum()/max;\n\nwrite(opti)"}], "src_uid": "822e8f394a59329fa05c96d7fb35797e"} {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction solve() {\r\n var n2 = (Number(read()) >> 1);\r\n read();\r\n write(n2 * 6);\r\n for (var i = 0; i < n2; i++) {\r\n var a = i + 1;\r\n var b = n2 * 2 - i;\r\n var swapStr = a + ' ' + b;\r\n write('1 ' + swapStr);\r\n write('2 ' + swapStr);\r\n write('1 ' + swapStr);\r\n write('2 ' + swapStr);\r\n write('1 ' + swapStr);\r\n write('2 ' + swapStr);\r\n }\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\n\r\nconst solve = () => {\r\n const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n let res = [];\r\n for(let i=0;i {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let arr = readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n let dp = [];\r\n dp[0] = 0;\r\n let pm = 0;\r\n for (let i = 1; i < n; i++) {\r\n dp[i] = arr[pm] === Math.max(arr[i - 1], arr[pm]) ? pm : i - 1;\r\n pm = arr[pm] === Math.max(arr[i], arr[pm]) ? pm : i;\r\n }\r\n let res = [];\r\n for (let i = n - 1; i >= 1; i--) {\r\n while (arr[i] >= 0) {\r\n res.push(`2 ${dp[i] + 1} ${i + 1}`);\r\n arr[i] -= arr[dp[i]];\r\n }\r\n }\r\n let max = 1;\r\n for (let i = 1; i < n; i++) {\r\n if (Math.abs(arr[i]) >= Math.abs(arr[max])) max = i;\r\n }\r\n while (arr[0] >= 0) {\r\n res.push(`1 1 ${max + 1}`);\r\n arr[0] += arr[max];\r\n }\r\n console.log(res.length);\r\n for (let i = 0; i < res.length; i++) console.log(res[i]);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction findAllStr(json, map, mapRev, index) {\r\n mapRev[index] = json;\r\n if (Array.isArray(json)) {\r\n for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {\r\n findAllStr(json[i], map, mapRev, index + '_' + i);\r\n }\r\n return;\r\n }\r\n if (json && typeof json === 'string') {\r\n if (map[json]) {\r\n map[json].push(index);\r\n } else {\r\n map[json] = [index];\r\n }\r\n }\r\n return;\r\n}\r\n\r\nfunction solve() {\r\n var n2 = (Number(read()) >> 1);\r\n read();\r\n write(n2 * 6);\r\n for (var i = 0; i < n2; i++) {\r\n var a = i + 1;\r\n var b = n2 * 2 - i;\r\n var swapStr = a + ' ' + b;\r\n write('1 ' + swapStr);\r\n write('2 ' + swapStr);\r\n write('2 ' + swapStr);\r\n write('1 ' + swapStr);\r\n write('1 ' + swapStr);\r\n write('2 ' + swapStr);\r\n }\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "src_uid": "980d2b3b6b80358b3757db8fe19e8287"} {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let tab = Array.from({ length: n }).map(() => []);\n arr.forEach((a, i) => {\n tab[i][i] = a;\n });\n let left = Array.from({ length: n + 1 }).map((_, i) => i - 1);\n let visit = (i, j, a, initial = false) => {\n // console.log({ i, j, a, left });\n if (i < 0 || j < 0 || left[a] < 1 || i >= n || j >= n || j > i) {\n return;\n }\n if (!initial) {\n if (tab[i][j]) {\n return;\n }\n tab[i][j] = a;\n left[a]--;\n }\n [\n // [-1, 0],\n // [0, -1],\n // [0, 1],\n // [1, 0],\n [0, -1],\n [1, 0],\n ].forEach(([di, dj]) => {\n visit(i + di, j + dj, a);\n });\n };\n arr.forEach((a, i) => {\n visit(i, i, a, true);\n });\n // console.log({ left });\n for (let i = 0; i < n; i++) {\n for (let j = 0; j <= i; j++) {\n io.write(tab[i][j] || 0);\n }\n io.writeLine('');\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n", "positive_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst n = rn();\r\n\tconst p = rna();\r\n\r\n\tlet ans = Array.from(Array(n), x => Array(n));\r\n\r\n\tfor (let i = 0; ans && i < n; i++) {\r\n\t\tans[i][i] = p[i];\r\n\r\n\t\tlet r = i, c = i;\r\n\t\tfor (let j = 1; j < p[i]; j++) {\r\n\t\t\tif (c-1>=0 && !ans[r][c-1])\r\n\t\t\t\tans[r][--c] = p[i];\r\n\t\t\telse if (r+1 {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var arr = input[1].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n var grid = [];\r\n for (var i = 0; i < arr.length; i++) {\r\n grid[i] = new Array(i + 1).fill(0);\r\n grid[i][i] = arr[i];\r\n }\r\n var dirs = [[0, -1],[1, 0]];\r\n function helper(grid, i, j, num, count, dirs) {\r\n grid[i][j] = num;\r\n count--;\r\n for (var k = 0; k < dirs.length; k++) {\r\n var x = i + dirs[k][0];\r\n var y = j + dirs[k][1];\r\n if (x < grid.length && y >= 0 && grid[x][y] === 0 && count > 0) {\r\n helper(grid, x, y, num, count, dirs);\r\n break;\r\n }\r\n }\r\n }\r\n for (var i = 0; i < grid.length; i++) {\r\n helper(grid, i, i, arr[i], arr[i], dirs);\r\n }\r\n for (var i = 0; i < grid.length; i++) {\r\n console.log(grid[i].join(\" \"));\r\n }\r\n});"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = 2\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\nfunction calcRecursive(arr, a, b, c, d, e) {\r\n if (e === 0) return 1\r\n if (c - 1 >= 0) {\r\n if (arr[b][c - 1] === 0) {\r\n arr[b][c - 1] = a\r\n return calcRecursive(arr, a, b, c - 1, d, e - 1)\r\n } else {\r\n if (b + 1 < d) {\r\n if (arr[b + 1][c] == 0) {\r\n arr[b + 1][c] = a\r\n return calcRecursive(arr, a, b + 1, c, d, e - 1)\r\n } else return 0\r\n }\r\n }\r\n } else {\r\n if (b + 1 < d) {\r\n if (arr[b + 1][c] == 0) {\r\n arr[b + 1][c] = a\r\n return calcRecursive(arr, a, b + 1, c, d, e - 1)\r\n } else return 0\r\n }\r\n }\r\n}\r\n\r\nfunction solve(n, arr) {\r\n let arr2 = []\r\n for (let i = 0; i < n; ++i) {\r\n arr2.push(new Array(n).fill(0))\r\n arr2[i][i] = arr[i]\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if (calcRecursive(arr2, arr2[i][i], i, i, n, arr2[i][i] - 1) === 0) {\r\n console.log(-1)\r\n return\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; ++i) {\r\n let temp = []\r\n for (let j = 0; j <= i; ++j) {\r\n temp.push(arr2[i][j])\r\n }\r\n console.log(temp.join(' '))\r\n }\r\n}\r\n\r\nfunction main() {\r\n solve(inputArr[0][0], inputArr[1])\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar N = nextInt();\r\n\tvar list = nextIntArray(N);\r\n\tvar output = new Array(N);\r\n\tfor(var j = 0; j < N; j++){\r\n\t\toutput[j] = new Array(j + 1);\r\n\t}\r\n\tfor(var j = N - 1; j >= 0; j--){\r\n\t\tvar y = j;\r\n\t\tvar x = j;\r\n\t\tvar count = list[j];\r\n\t\twhile(count > 0){\r\n\t\t\toutput[y][x] = list[j];\r\n\t\t\tcount--;\r\n\t\t\tif(count == 0){\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif(y + 1 < N && output[y + 1][x] == null){\r\n\t\t\t\ty++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}else if(x - 1 >= 0 && output[y][x - 1] == null){\r\n\t\t\t\tx--;\r\n\t\t\t\tcontinue;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tfor(var j = 0; j < N; j++){\r\n\t\tmyout(myconv(output[j], 8));\r\n\t}\r\n}\r\n"}, {"source_code": "const n = parseInt(readline());\nconst a = readline().split(' ').map((item, i) => {\n b = new Array(n).fill(0);\n b[i] = parseInt(item);\n return b;\n});\n\nfor (var i = 0; i < n; i++) {\n var x = a[i][i];\n var x_ = x - 1;\n var posX = i;\n var posY = i;\n while (x_) {\n if (posX > 0 && !a[posY][posX - 1]) {\n posX--;\n a[posY][posX] = x;\n } else {\n posY++;\n a[posY][posX] = x;\n }\n x_--;\n }\n}\n\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j <= i; j++)\n write(`${a[i][j]} `);\n write('\\n');\n}"}], "negative_code": [{"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let tab = Array.from({ length: n }).map(() => []);\n arr.forEach((a, i) => {\n tab[i][i] = a;\n });\n let left = Array.from({ length: n }).map((_, i) => i - 1);\n let visit = (i, j, a) => {\n // console.log({ i, j, a, left });\n if (i < 0 || j < 0 || left[a] < 1 || i >= n || j >= n || j > i) {\n return;\n }\n if (i !== j) {\n if (tab[i][j]) {\n return;\n }\n tab[i][j] = a;\n left[a]--;\n }\n [\n [-1, 0],\n [0, -1],\n [0, 1],\n [1, 0],\n ].forEach(([di, dj]) => {\n visit(i + di, j + dj, a);\n });\n };\n arr.forEach((a, i) => {\n visit(i, i, a);\n });\n for (let i = 0; i < n; i++) {\n for (let j = 0; j <= i; j++) {\n io.write(tab[i][j]);\n }\n io.writeLine('');\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let tab = Array.from({ length: n }).map(() => []);\n arr.forEach((a, i) => {\n tab[i][i] = a;\n });\n let left = Array.from({ length: n }).map((_, i) => i - 1);\n let visit = (i, j, a) => {\n // console.log({ i, j, a, left });\n if (i < 0 || j < 0 || left[a] < 1 || i >= n || j >= n) {\n return;\n }\n if (i !== j) {\n if (tab[i][j]) {\n return;\n }\n tab[i][j] = a;\n left[a]--;\n }\n [\n [-1, 0],\n [0, -1],\n [0, 1],\n [1, 0],\n ].forEach(([di, dj]) => {\n visit(i + di, j + dj, a);\n });\n };\n arr.forEach((a, i) => {\n visit(i, i, a);\n });\n for (let i = 0; i < n; i++) {\n for (let j = 0; j <= i; j++) {\n io.write(tab[i][j]);\n }\n io.writeLine('');\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst fs_1 = __importDefault(require(\"fs\"));\n//////////// LIBS\nclass IO {\n constructor() {\n this.i = 0;\n this.out = '';\n this.text = require('fs').readFileSync(0, 'utf8');\n }\n nextToken() {\n let ret = '';\n while (this.text[this.i].charCodeAt(0) <= 32) {\n this.i++;\n }\n while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {\n ret += this.text[this.i];\n this.i++;\n }\n return ret;\n }\n nextNum() {\n return Number(this.nextToken());\n }\n nextNumArray(n) {\n let ret = [];\n while (n--) {\n ret.push(this.nextNum());\n }\n return ret;\n }\n _write(x) {\n this.out += x;\n }\n write(x) {\n this._write(x + ' ');\n }\n writeLine(x) {\n this._write(x + '\\n');\n }\n flush() {\n fs_1.default.writeFileSync(1, this.out);\n this.out = '';\n }\n}\nfunction binarySearch(array, pred) {\n let lo = -1, hi = array.length;\n while (1 + lo < hi) {\n const mi = lo + ((hi - lo) >> 1);\n if (pred(array[mi])) {\n hi = mi;\n }\n else {\n lo = mi;\n }\n }\n return hi;\n}\nfunction lowerBound(array, item) {\n return binarySearch(array, (j) => item <= j);\n}\nfunction upperBound(array, item) {\n return binarySearch(array, (j) => item < j);\n}\n//////////// LIBS\nconst io = new IO();\nfunction solve(n, arr) {\n let tab = Array.from({ length: n }).map(() => []);\n arr.forEach((a, i) => {\n tab[i][i] = a;\n });\n let left = Array.from({ length: n }).map((_, i) => i - 1);\n let visit = (i, j, a) => {\n // console.log({ i, j, a, left });\n if (i < 0 || j < 0 || left[a] < 1 || i >= n) {\n return;\n }\n if (i !== j) {\n if (tab[i][j]) {\n return;\n }\n tab[i][j] = a;\n left[a]--;\n }\n [\n [0, -1],\n [1, 0],\n ].forEach(([di, dj]) => {\n visit(i + di, j + dj, a);\n });\n };\n arr.forEach((a, i) => {\n visit(i, i, a);\n });\n for (let i = 0; i < n; i++) {\n for (let j = 0; j <= i; j++) {\n io.write(tab[i][j]);\n }\n io.writeLine('');\n }\n}\nfunction main() {\n try {\n let n = io.nextNum();\n let arr = io.nextNumArray(n);\n solve(n, arr);\n io.flush();\n }\n catch (e) {\n console.log(e.stack);\n }\n}\nmain();\n"}, {"source_code": "const n = parseInt(readline());\nconst a = readline().split(' ').map((item, i) => {\n b = new Array(n).fill(0);\n b[i] = parseInt(item);\n return b;\n});\n\nfor (var i = 0; i < n; i++) {\n var x = a[i][i];\n var x_ = x - 1;\n var posX = i;\n var posY = i;\n while (x_) {\n if (posX > 0 && !a[posY][posX - 1]) {\n posX--;\n a[posY][posX] = x;\n } else {\n posY++;\n a[posY][posX] = x;\n }\n x_--;\n }\n}\n\nfor (var i = 0; i < n; i++) {\n for (var j = 0; j < n; j++)\n write(`${a[i][j]} `);\n write('\\n');\n}"}], "src_uid": "5e95cb608bca3c3e9fc581b97f0dbc65"} {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const [n, k] = arr.shift().split(' ').map(a => parseInt(a))\n\n const str = arr[0]\n const available = arr[1]\n let sum = 0, last = -1\n\n for(let i = 0; i < n; i++) {\n if(!available.includes(str[i])) {\n let x = i - last - 1\n // console.log('x:', x, sum, last, i)\n sum += (x + 1) * x / 2\n last = i\n }\n }\n if(last != n - 1) {\n let x = n - 1 - last\n // console.log('x:', x, sum, last)\n sum += (x + 1) * x / 2\n }\n\n console.log(sum)\n})", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n\nfunction create2DArray(rows) {\n var arr = [];\n\n for (var i = 0; i < rows; i++) {\n arr[i] = [];\n }\n\n return arr;\n}\n// ---------------------------------------\n\nfunction main() {\n let [strLen, charOptions] = getArray(readline());\n let str = readline();\n let charArr = getStrArray(readline());\n let x = [];\n for (let i = 0; i < strLen; i++) {\n if (charArr.indexOf(str[i]) > -1) {\n x[i] = 1;\n } else {\n x[i] = 0;\n }\n }\n\n let count = 0;\n let ans = 0;\n for(let i= 0; i< strLen; i++) {\n if (x[i] === 0) {\n ans += count*(count+1)/2;\n count = 0\n } else if (x[i] === 1) {\n count++;\n }\n }\n if(count !== 0) {\n ans += count*(count+1)/2;\n }\n console.log(ans);\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data, letters) {\n const subAr = data.split(new RegExp(`[^${letters}]`))\n return subAr.reduce((acc, value) => {\n const n = value.length;\n return acc + ((n * (n + 1)) / 2);\n }, 0)\n }\n\n\n let result = foo(lines[1], lines[2].replace(/\\s/g, ''));\n console.log(result);\n})"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let [str, letters] = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n letters = letters.split(' ');\n let result = 0;\n let list = [];\n str.split('').forEach((c, index) => {\n if (letters.indexOf(c) < 0) {\n list.push(index);\n }\n });\n list.push(str.length);\n\n let lastIndex = 0;\n list.forEach((v) => {\n if (v > 0 && v > lastIndex) {\n let len = v - lastIndex;\n result += len * (len + 1) / 2;\n }\n // console.log(lastIndex, v, result);\n lastIndex = v + 1;\n });\n\n // console.log(list);\n console.log(result);\n});"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\nfor (let i = 0; i < txt.length; i += 3) {\n doit(txt[i + 1], txt[i + 2].split(\" \").filter(data => {\n return data.length > 0\n }))\n}\n\nfunction doit(tab, keys) {\n let arr = []\n let seg=\"\"\n for (let i = 0; i < tab.length; i++) {\n if(keys.includes(tab[i])){\n seg+=tab[i]\n }else if(seg.length>0){\n arr.push(seg.length);\n seg=\"\"\n }\n \n }\n if(seg.length>0){\n arr.push(seg.length)\n }\n seg=0;\n arr.forEach(data=>{\n seg+=data*(data+1)/2\n })\n console.log(seg);\n}"}, {"source_code": "'use strict'\n\nconst problem = (n, k, s, t) => {\n let j = 0, r = 0, len = s.length;\n for (let i = 0; i < len; i++) {\n if (t.indexOf(s[i]) === -1) {\n if (j === -1) continue;\n r += (i-j)*(i-j+1) / 2;\n j = -1;\n } else {\n if (j === -1) j = i;\n }\n }\n if (j === -1) return r;\n r += (len-j)*(len-j+1) / 2;\n return r;\n}\n\nconst nk = readline().split(' ').map(i => +i);\nprint(problem(nk[0], nk[1], readline(), readline()));\n"}, {"source_code": "function myin(){return require(\"fs\").readFileSync(\"/dev/stdin\", \"utf8\").trim();}\nfunction myout(t){print(t);}//standard output\n//function myout(t){console.log(t);}//standard output\nfunction myerr(t){console.err(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n \nfunction Main() {\n //input = myconv(input,3);\n var first = readline();\n var N = myconv(first,4)[0];\n var k = myconv(first,4)[1];\n var list = myconv(readline(),6);\n var keys = myconv(readline(),2);\n var numlist = new Array(N).fill(0);\n for(var i = 0; i < N; i++){\n var tmps = list[i];\n if(keys.indexOf(list[i]) != -1){\n if(i == 0){\n numlist[i] = 1;\n }else{\n numlist[i] = numlist[i-1]+1;\n }\n }\n }\n var output = 0;\n for(var i = 0; i < N; i++){\n output += numlist[i];\n }\n myout(output);\n}\n \nMain();"}], "negative_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let [str, letters] = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n letters = letters.split(' ');\n let result = 0;\n let list = [];\n str.split('').forEach((c, index) => {\n if (letters.indexOf(c) < 0) {\n list.push(index);\n }\n });\n list.push(str.length);\n\n let lastIndex = 0;\n list.forEach((v) => {\n if (v > 0 && v > lastIndex) {\n console.log(lastIndex, v);\n let len = v - lastIndex;\n result += len * (len + 1) / 2;\n }\n // console.log(lastIndex, v, result);\n lastIndex = v + 1;\n });\n\n // console.log(list);\n console.log(result);\n});"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let [str, letters] = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n letters = letters.split(' ');\n let lastIndex = 0;\n let result = 0;\n str.split('').forEach((c, index, array) => {\n // console.log(index, c, lastIndex, result);\n if ((letters.indexOf(c) < 0) && index > lastIndex) {\n // console.log('adding', lastIndex, index, index - lastIndex);\n let len = index + 1 - lastIndex;\n result += len * (len + 1) / 2;\n } else if ((letters.indexOf(c) < 0 || index === array.length - 1) && index > lastIndex) {\n\n }\n if (letters.indexOf(c) < 0) {\n lastIndex = index + 1;\n }\n });\n console.log(result);\n});"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let [str, letters] = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n letters = letters.split(' ');\n let lastIndex = 0;\n let result = 0;\n str.split('').forEach((c, index, array) => {\n // console.log(index, c, lastIndex, result);\n if (letters.indexOf(c) < 0 && index > lastIndex) {\n // console.log('adding', lastIndex, index, index - lastIndex);\n let len = index - lastIndex;\n result += len * (len + 1) / 2;\n } else if (index === array.length - 1 && index > lastIndex) {\n // console.log('adding', lastIndex, index, index + 1 - lastIndex);\n let len = index + 1 - lastIndex;\n result += len * (len + 1) / 2;\n }\n if (letters.indexOf(c) < 0) {\n lastIndex = index + 1;\n }\n });\n console.log(result);\n});"}, {"source_code": "'use strict'\n\nconst problem = (n, k, s, t) => {\n let j = 0, r = 0, len = s.length;\n for (let i = 0; i < len; i++) {\n if (t.indexOf(s[i]) === -1) {\n if (j === -1) continue;\n r += (i-j)*(i-j+1) / 2;\n j = -1;\n } else {\n if (j === -1) j = i;\n }\n }\n if (j === -1) return 0;\n r += (len-j)*(len-j+1) / 2;\n return r;\n}\n\nconst nk = readline().split(' ').map(i => +i);\nprint(problem(nk[0], nk[1], readline(), readline()));\n"}, {"source_code": "'use strict'\n\nconst problem = (n, k, s, t) => {\n let j = 0, r = 0, len = s.length;\n for (let i = 0; i < len; i++) {\n if (t.indexOf(s[i]) === -1) {\n if (j === -1) continue;\n r += (i-j)*(i-j+1) / 2;\n j = -1;\n } else {\n if (j === -1) j = i;\n }\n }\n r += (len-j)*(len-j+1) / 2;\n return r;\n}\n\nconst nk = readline().split(' ').map(i => +i);\nprint(problem(nk[0], nk[1], readline(), readline()));\n"}], "src_uid": "4c260e7c6fd9c573ee4f3b1822f3c7c3"} {"source_code": "function main() {\n var homeTeam = next();\n var guestTeam = next();\n\n var n = nextInt();\n var status = {};\n var res = [];\n\n for (var i = 0; i < n; i++) {\n var time = nextInt();\n var team = next().charAt(0) === 'h' ? 0 : 1;\n var m = nextInt();\n var cardType = next().charAt(0);\n var name = team + '_' + m;\n var found = false;\n if (status[name] === 1) {\n status[name] = 2;\n found = true;\n } else if (status[name] === 2) {\n } else {\n status[name] = cardType === 'y' ? 1 : 2;\n found = status[name] === 2;\n }\n if (found)\n res.push([(team === 0 ? homeTeam : guestTeam), m, time]);\n }\n\n for (var j = 0; j < res.length; j++) {\n print(res[j][0] + ' ' + res[j][1] + ' ' + res[j][2]); \n }\n}\n\n// auxiliary code\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nmain();", "positive_code": [{"source_code": "function main(){\n var h = [];\n h.push(next());\n h.push(next());\n var E = [];\n E.push({});\n E.push({});\n var t = nextInt();\n var time,team,number,type;\n while(t-->0){\n time = nextInt();\n team = next().charAt(0)!=\"h\" ? 1:0 ;\n number = nextInt();\n type = next();\n if(type == \"r\"){\n if(!E[team][number])\n E[team][number]=0;\n if(E[team][number]<=1){\n print(h[team]+\" \"+number+\" \"+time);\n }\n E[team][number]+=2;\n }\n else {\n if(!E[team][number])\n E[team][number]=0;\n if(E[team][number]==1){\n print(h[team]+\" \"+number+\" \"+time);\n }\n E[team][number]++;\n }\n }\n }\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nmain();"}, {"source_code": "var home = readline(),\n\t\t\taway = readline(),\n\t\t\tn = parseInt(readline()),\n\t\t\thomeCheck = {}, awayCheck = {};\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar inputs = readline().split(/\\s/gi),\n\t\t\t\ttime = inputs[0],\n\t\t\t\tteam = inputs[1],\n\t\t\t\tplayer = inputs[2],\n\t\t\t\tcard = inputs[3];\n\n\t\t\tif(team == 'a')\t{\n\t\t\t\tif(!awayCheck[player])\tawayCheck[player] = { 'y' : 0, 'r' : 0, 'hasRed' : false };\n\n\t\t\t\tawayCheck[player][card] += 1;\n\n\t\t\t\tif((awayCheck[player].y >= 2 || awayCheck[player].r >= 1) && !awayCheck[player].hasRed)\t{\n\t\t\t\t\tprint(away + ' ' + player + ' ' + time);\n\t\t\t\t\tawayCheck[player].hasRed = true;\n\t\t\t\t}\n\t\t\t} else\t{\n\t\t\t\tif(!homeCheck[player])\thomeCheck[player] = { 'y' : 0, 'r' : 0, 'hasRed' : false };\n\n\t\t\t\thomeCheck[player][card] += 1;\n\n\t\t\t\tif((homeCheck[player].y >= 2 || homeCheck[player].r >= 1) && !homeCheck[player].hasRed)\t{\n\t\t\t\t\tprint(home + ' ' + player + ' ' + time);\n\t\t\t\t\thomeCheck[player].hasRed = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}"}], "negative_code": [{"source_code": "\nfunction main(){\n var h = [];\n h.push(next());\n h.push(next());\n var E = [];\n E.push({});\n E.push({});\n var t = nextInt();\n var time,team,number,type;\n \n while(t-->0){\n time = nextInt();\n team = next().charAt(0)!=\"h\";\n number = nextInt();\n type = next();\n if(type == \"r\"){\n if(!E[team][number])\n E[team][number]=0;\n if(E[team][number]<=1){\n print([team]+\" \"+number+\" \"+time);\n }\n E[team][number]+=2;\n }\n else {\n if(!E[team][number])\n E[team][number]=0;\n if(E[team][number]==1){\n print([team]+\" \"+number+\" \"+time);\n }\n E[team][number]++;\n }\n }\n }\n\n"}, {"source_code": "var home = readline(),\n\t\t\taway = readline(),\n\t\t\tn = parseInt(readline()),\n\t\t\thomeCheck = {}, awayCheck = {};\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar inputs = readline().split(/\\s/gi),\n\t\t\t\ttime = inputs[0],\n\t\t\t\tteam = inputs[1],\n\t\t\t\tplayer = inputs[2],\n\t\t\t\tcard = inputs[3];\n\n\t\t\tif(team == 'a')\t{\n\t\t\t\tif(!awayCheck[player])\tawayCheck[player] = { 'y' : 0, 'r' : 0 };\n\n\t\t\t\tawayCheck[player][card] += 1;\n\n\t\t\t\tif(awayCheck[player].y >= 2 || awayCheck[player].r >= 1)\t{\n\t\t\t\t\tprint(away + ' ' + player + ' ' + time);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(team == 'h')\t{\n\t\t\t\tif(!homeCheck[player])\thomeCheck[player] = { 'y' : 0, 'r' : 0 };\n\n\t\t\t\thomeCheck[player][card] += 1;\n\n\t\t\t\tif(homeCheck[player].y >= 2 || homeCheck[player].r >= 1)\t{\n\t\t\t\t\tprint(home + ' ' + player + ' ' + time);\n\t\t\t\t}\n\t\t\t}\n\t\t}"}, {"source_code": "var home = readline(),\n\t\t\taway = readline(),\n\t\t\tn = parseInt(readline()),\n\t\t\thomeCheck = {}, awayCheck = {};\n\n\t\tfor(var i = 0; i < n; i++)\t{\n\t\t\tvar inputs = readline().split(/\\s/gi),\n\t\t\t\ttime = inputs[0],\n\t\t\t\tteam = inputs[1],\n\t\t\t\tplayer = inputs[2],\n\t\t\t\tcard = inputs[3];\n\n\t\t\tif(team == 'a')\t{\n\t\t\t\tif(!awayCheck[player])\t{\n\t\t\t\t\tawayCheck[player] = {\n\t\t\t\t\t\t'y' : 0,\n\t\t\t\t\t\t'r' : 0\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tawayCheck[player][card] += 1;\n\n\t\t\t\tif(awayCheck[player].y >= 2 || awayCheck[player].r >= 1)\t{\n\t\t\t\t\tprint(away + ' ' + player + ' ' + time);\n\t\t\t\t}\n\t\t\t} else\t{\n\t\t\t\tif(!homeCheck[player])\t{\n\t\t\t\t\thomeCheck[player] = {\n\t\t\t\t\t\t'y' : 0,\n\t\t\t\t\t\t'r' : 0\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\thomeCheck[player][card] += 1;\n\n\t\t\t\tif(homeCheck[player].y >= 2 || homeCheck[player].r >= 1)\t{\n\t\t\t\t\tprint(home + ' ' + player + ' ' + time);\n\t\t\t\t}\n\t\t\t}\n\t\t}"}], "src_uid": "b1f78130d102aa5f425e95f4b5b3a9fb"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, k] = rna();\r\n\tlet s = rl();\r\n\r\n\tlet i = 1, p = 0;\r\n\tfor (; i < s.length; i++) {\r\n\t\tif (s[i] < s[p]) {\r\n\t\t\tp = 0;\r\n\t\t} else if (s[i] == s[p]) {\r\n\t\t\tp++;\r\n\t\t} else {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\ti = i - p;\r\n\r\n\ts = s.slice(0, i);\r\n\ts = s.repeat(Math.ceil(k/i));\r\n\tconst ans = s.slice(0, k);\r\n\r\n\tconsole.log(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "function solve() {\r\n var nk = readArray(Number);\r\n var n = nk[0];\r\n var k = nk[1];\r\n var str = read();\r\n var current = 1;\r\n var savepoint;\r\n var check;\r\n while(true) {\r\n if (current >= n) {\r\n break;\r\n }\r\n if (str[current] > str[0]) {\r\n str = str.substr(0, current);\r\n break;\r\n }\r\n if (str[current] < str[check]) {\r\n current++;\r\n continue;\r\n }\r\n savepoint = current;\r\n check = 0;\r\n while (current < 3 * n && str[current % n] === str[check]) {\r\n current++;\r\n check++;\r\n if (check >= savepoint) {\r\n check = 0;\r\n }\r\n }\r\n if (current !== 3 * n && str[current % n] > str[check]) {\r\n str = str.substr(0, savepoint);\r\n break;\r\n }\r\n }\r\n while(str.length < k) {\r\n str = str + str;\r\n }\r\n write(str.substr(0, k));\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}], "negative_code": [{"source_code": "var matr = 'haha';\r\n\r\nfunction create(str) {\r\n var hahaIndexArr = [];\r\n for (var i = 0; i < str.length; i++) {\r\n var hasWrong = false;\r\n for (var j = 0; j < matr.length; j++) {\r\n if (str[i + j] !== matr[j]) {\r\n hasWrong = true;\r\n break;\r\n }\r\n }\r\n if (!hasWrong) {\r\n hahaIndexArr.push(i);\r\n }\r\n }\r\n if (hahaIndexArr.length === 0) {\r\n if (str.length < 8) {\r\n return [str, -1, str];\r\n }\r\n return [str.substr(0, 4), 0, str.substr(str.length - 4, 0)];\r\n }\r\n var preff = str.substr(0, Math.min(4, hahaIndexArr[0])) || 'ha';\r\n var suff = str.substr(Math.max(hahaIndexArr[hahaIndexArr.length - 1] + 4, str.length - 4)) || 'ha';\r\n return [preff, hahaIndexArr.length, suff];\r\n}\r\nfunction summ(a, b) {\r\n var createMiddle = create(a[2] + b[0]);\r\n if (a[1] === -1 && b[1] === -1) {\r\n return createMiddle;\r\n }\r\n var preff = a[1] === -1 ? createMiddle[0] : a[0];\r\n var suff = b[1] === -1 ? createMiddle[2] : b[2];\r\n var asum = a[1] === -1 ? 0 : a[1];\r\n var bsum = b[1] === -1 ? 0 : b[1];\r\n var midSum = createMiddle[1] === -1 ? 0 : createMiddle[1];\r\n return [preff, asum + bsum + midSum, suff];\r\n}\r\n\r\nfunction solve() {\r\n var nk = readArray(Number);\r\n var n = nk[0];\r\n var k = nk[1];\r\n var str = read();\r\n var current = 1;\r\n var savepoint;\r\n var check;\r\n while(true) {\r\n if (current >= n) {\r\n break;\r\n }\r\n if (str[current] > str[0]) {\r\n str = str.substr(0, current);\r\n break;\r\n }\r\n if (str[current] < str[check]) {\r\n current++;\r\n continue;\r\n }\r\n savepoint = current;\r\n check = 0;\r\n while (current < n && str[current] === str[check]) {\r\n current++;\r\n check++;\r\n if (check >= savepoint) {\r\n check = 0;\r\n }\r\n }\r\n if (current !== n && str[current] > str[check]) {\r\n str = str.substr(0, savepoint);\r\n break;\r\n }\r\n }\r\n while(str.length < k) {\r\n str = str + str;\r\n }\r\n write(str.substr(0, k));\r\n\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n //T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}], "src_uid": "245371912e9828e763a49a85f4f6d2d9"} {"source_code": "var fl=readline().split(' ');\nvar maxDistance=fl[1];\n\nvar stations=readline().split(' ');\nvar distantions=stations.map((i,k,a)=>i-(a[k-1]||0)).slice(1);\nif(distantions.some(i=>i>maxDistance)){\n print('-1');\n}\nelse{\n var count=1;\n var currentCredit=maxDistance;\n for(var k=0; k maxKmImmut) {\n return 0;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm < points[i+1] - points[i]) {\n if (i == points.length-1) {\n return changes;\n }\n changes++;\n maxKm = maxKmImmut;\n }\n } else {\n changes++;\n maxKm = maxKmImmut;\n }\n temp = points[i];\n }\n return changes;\n}\nvar res = operate();\nwrite((res == 0) ? -1 : res);"}, {"source_code": "'use strict';var _slicedToArray=function(){function b(c,d){var e=[],f=!0,g=!1,h=void 0;try{for(var l,j=c[Symbol.iterator]();!(f=(l=j.next()).done)&&(e.push(l.value),!(d&&e.length===d));f=!0);}catch(m){g=!0,h=m}finally{try{!f&&j['return']&&j['return']()}finally{if(g)throw h}}return e}return function(c,d){if(Array.isArray(c))return c;if(Symbol.iterator in Object(c))return b(c,d);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}(),data=[];data.push(readline()),data.push(readline());var pI=function(b){return parseInt(b,10)};function solve(){for(var _data$0$split$map=data[0].split(' ').map(pI),_data$0$split$map2=_slicedToArray(_data$0$split$map,2),b=_data$0$split$map2[0],c=_data$0$split$map2[1],d=data[1].split(' ').map(pI),e=1,f=0,g=0;gc)return void print(-1);d[g+1]-d[g]+f>c?(f=d[g+1]-d[g],e+=1):f+=d[g+1]-d[g]}print(e)}solve();"}, {"source_code": "var first = readline().split(' ');\nvar second = readline().split(' ');\nvar count = +first[0];\nvar max = +first[1];\nvar current=0;\nvar tempor=1;\nvar return_val=0;\nwhile (current max) \n\t{\n\t\treturn_val=-1;\n\t\tcurrent=count;\n\t}\n\telse if (second[tempor] - second[current] > max)\n\t{\n\t\tcurrent = tempor-1;\n\t\treturn_val++;\n\t}\n\telse if (tempor == count)\n\t{\n\t\treturn_val++;\n\t\tcurrent=count;\n\t}\n\telse tempor++;\n}\nprint(return_val);"}, {"source_code": "//var readline = require('lol-io').readline\n//var print = require('lol-io').print\n\nvar l1 = readline().split(' ');\nvar n = parseInt(l1[0]);\nvar k = parseInt(l1[1]);\n\nvar lx = readline().split(' ');\nvar x = [];\nfor (var i=0;i k) {\n numberOfBikes = -1;\n break;\n } else {\n if(currentDistance + difference > k) {\n numberOfBikes++;\n currentDistance = difference;\n } else {\n currentDistance += difference;\n }\n }\n}\n\nprint(numberOfBikes);"}, {"source_code": "var line1 = readline()\nvar line2 = readline()\n\nline1 = line1.split(' ')\nvar coordinates = line2.split(' ')\n\nvar n = line1[0]\nvar step = Number(line1[1])\nvar pos = Number(coordinates[0])\nvar bikes = 0\n\nwhile(true) {\n\n var nearest = coordinates[n - 1]\n pos = pos + step\n var distances = []\n \n for (var i = 0; i < n; i++) {\n distances.push(pos - coordinates[i])\n }\n for (var i = 0; i < distances.length; i++) { \n if (distances[i] >= 0) {\n nearest = coordinates[i]\n }\n } \n bikes++\n if(nearest == pos - step) {\n print(-1)\n break\n }\n pos = Number(nearest)\n if (pos == coordinates[n - 1]) {\n print(bikes)\n break\n }\n}"}, {"source_code": "\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n// let lines = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// lines++;\n// // if(lines >= 2) {\n// // inputString = inputString.trim().split('\\n').map(str => str.trim());\n// // return main()\n// // }\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n// main();\n// });\n\n// function readLine() {\n// return inputString[currentLine++];\n// }\n\n\nfunction findPathFrom(rentals, from, dist, counter) {\n var maxDist = rentals[from] + dist;\n \n if(maxDist >= rentals[rentals.length - 1]) return counter;\n\n var nextRentals = [];\n for(var i = from + 1; rentals[i] <= maxDist; i++) nextRentals.push(i);\n if(!nextRentals.length) return -1;\n var nextRental = nextRentals.pop();\n return findPathFrom(rentals, nextRental, dist, counter + 1);\n}\n\nfunction main() {\n var f = readline().split(' ').map(Number);\n var rentals = readline().split(' ').map(Number);\n print(findPathFrom(rentals, 0, f.pop(), 1));\n}\n\nmain()\n\n\n"}, {"source_code": "var l = readline().split(' ');\nvar n = l[0];\nvar k = l[1];\nvar l1 = readline().split(' ');\nvar v = [];\nvar count = 0;\nfor(p=0;p-1;i--) {\n\t\tif(i === 0) {\n\t\tcount = -1;\n\t\tbreak;\n\t\t} \n if((v[i] - k) <= v[0]) {\n \n\t\t\tcount++; \n \n v = v.splice(i, v.length);\n\t\t\tif(v.length != 1) {\n\t\t\tstart();\n\t\t\t}\n break;\n\n }\n \n\t\t\n }\n}\nstart();\nprint(count);"}], "negative_code": [{"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n if (i == number - 1) {\n return changes;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n changes++;\n maxKm = 3;\n }\n } else {\n changes++;\n maxKm = 3;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 0) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n // if (i == number - 1) {\n // return changes;\n // }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0 && i != number - 1) {\n changes++;\n maxKm = 3;\n }\n } else {\n changes++;\n maxKm = 3;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 0) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if (i == number - 1) {\n return changes;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n changes++;\n maxKm = 3;\n }\n } else {\n changes++;\n maxKm = 3;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 1) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > 3) {\n return 1;\n }\n if (i == number - 1) {\n return changes;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n changes++;\n maxKm = 3;\n }\n } else {\n changes++;\n maxKm = 3;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 1) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > 3) {\n return 0;\n }\n if (i == number - 1) {\n return changes;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n changes++;\n maxKm = 3;\n }\n } else {\n changes++;\n maxKm = 3;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 0) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0 && i != number - 1) {\n changes++;\n maxKm = maxKmImmut;\n }\n } else {\n changes++;\n maxKm = maxKmImmut;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 0) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < points.length; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n if (i == points.length-1) {\n return changes;\n }\n changes++;\n maxKm = maxKmImmut;\n }\n } else {\n changes++;\n maxKm = maxKmImmut;\n }\n temp = points[i];\n }\n return changes;\n}\nvar res = operate();\nwrite((res == 0) ? -1 : res);"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0 && (i != number - 1)) {\n changes++;\n maxKm = maxKmImmut;\n }\n } else {\n changes++;\n maxKm = maxKmImmut;\n }\n temp = points[i];\n }\n return changes;\n}\nwrite((operate() == 0) ? -1 : operate());"}, {"source_code": "var user_input = readline().split(\" \");\nvar number = parseInt(user_input[0]);\nvar maxKm = parseInt(user_input[1]);\nvar maxKmImmut = maxKm;\nvar points = readline().split(\" \");\nvar changes = 1;\nvar temp = points[0];\nvar operate = function() {\n for (var i = 1; i < number; i++) {\n if ((points[i] - temp) > maxKmImmut) {\n return 0;\n }\n if ((points[i] - temp) <= maxKm) {\n maxKm -= points[i] - temp;\n if (maxKm <= 0) {\n if (i == number-1) {\n return changes;\n }\n changes++;\n maxKm = maxKmImmut;\n }\n } else {\n changes++;\n maxKm = maxKmImmut;\n }\n temp = points[i];\n }\n return changes;\n}\nvar res = operate();\nwrite((res == 0) ? -1 : res);"}, {"source_code": "var line1 = readline()\nvar line2 = readline()\n\nline1 = line1.split(' ')\nvar coordinates = line2.split(' ')\n\nvar n = line1[0]\nvar step = Number(line1[1])\nvar pos = Number(coordinates[0])\nvar bikes = 0\n\nwhile(true) {\n var nearest = coordinates[n - 1]\n pos = pos + step\n var distances = []\n \n for (var i = 0; i < n; i++) {\n distances.push(pos - coordinates[i])\n }\n for (var i = 0; i < distances.length; i++) { \n if (distances[i] >= 0 && distances[i] < nearest) {\n nearest = coordinates[i]\n }\n } \n\n bikes++\n\n if(nearest == pos - step) {\n print(-1)\n break\n }\n\n pos = Number(nearest)\n\n if (pos == coordinates[n - 1]) {\n print(bikes)\n break\n }\n}"}, {"source_code": "var line1 = readline()\nvar line2 = readline()\n\nline1 = line1.split(' ')\nvar coordinates = line2.split(' ')\n\nvar n = line1[0]\nvar step = Number(line1[1])\nvar pos = Number(coordinates[0])\nvar bikes = 0\n\nwhile(true) {\n \n var nearest = coordinates[n - 1]\n pos = pos + step\n var distances = []\n \n for (var i = 0; i < n; i++) {\n distances.push(pos - coordinates[i])\n }\n \n for (var i = 0; i < distances.length; i++) { \n if (distances[i] >= 0 && distances[i] <= nearest) {\n nearest = coordinates[i]\n }\n } \n\n if(Number(nearest) == pos - step) {\n print(-1)\n break\n }\n\n bikes++\n\n pos = Number(nearest)\n if (pos == Number(coordinates[n - 1])) {\n print(bikes)\n break\n }\n}"}], "src_uid": "874c4847db340f10ac55259cba259723"} {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n\r\nfunction begin(n, q, nums, querys) {\r\n //print(n, q, nums, querys);\r\n let odd = 0;\r\n let even = 0;\r\n let sum = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (nums[i] % 2 == 0) {\r\n even++;\r\n } else {\r\n odd++;\r\n }\r\n sum += nums[i];\r\n }\r\n for (let i = 0; i < q; i++) {\r\n if (querys[i][0] == 0) {\r\n if (querys[i][1] % 2 == 0) {\r\n sum += even * querys[i][1];\r\n } else {\r\n sum += even * querys[i][1];\r\n odd += even;\r\n even = 0;\r\n }\r\n } else if (querys[i][0] == 1) {\r\n if (querys[i][1] % 2 == 0) {\r\n sum += odd * querys[i][1];\r\n } else {\r\n sum += odd * querys[i][1];\r\n even += odd;\r\n odd = 0;\r\n }\r\n }\r\n print(sum);\r\n }\r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n\r\n let querys = [];\r\n for (let j = 0; j < n[1]; j++) {\r\n var temp = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n querys.push(temp);\r\n\r\n }\r\n begin(n[0], n[1], x, querys);\r\n }\r\n}", "positive_code": [{"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n \nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n \nconst calc = (t)=>{\n /* read */\n let [n, q] = ra();\n let a = ra();\n\n let even = 0;\n let evenCount = 0;\n let odd = 0;\n let oddCount = 0;\n\n for (let i = 0; i < n; i++) {\n if (a[i] % 2 === 0) {\n even += a[i];\n evenCount++;\n } else {\n odd += a[i];\n oddCount++;\n }\n }\n \n for (let qq = 0; qq < q; qq++) {\n let [type, x] = ra();\n if (type === 0) { // even\n let sum = even + evenCount * x;\n process.stdout.write(`${sum + odd}\\n`);\n if (sum === 0) continue;\n if (x % 2 === 0) {\n even = sum;\n } else {\n oddCount = n;\n odd += sum;\n even = 0;\n evenCount = 0;\n }\n } else { // odd\n let sum = odd + oddCount * x;\n process.stdout.write(`${sum + even}\\n`);\n if (sum === 0) continue;\n if (x % 2 === 0) {\n odd = sum;\n } else {\n evenCount = n;\n even += sum;\n odd = 0;\n oddCount = 0;\n }\n }\n }\n};\n \nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n calc(t);\n // out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n // process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [n,q]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n let a=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n let odd=0,even=0;\r\n let sum1=0,sum2=0;\r\n for(let i=0;i{return parseInt(x)});\r\n if(p==0)\r\n {\r\n if(x%2==0)\r\n {\r\n even+=sum2*x;\r\n }\r\n else\r\n {\r\n even+=sum2*x;\r\n odd+=even;\r\n sum1+=sum2;\r\n sum2=0;\r\n even=0;\r\n }\r\n }\r\n else\r\n {\r\n if(x%2==1)\r\n {\r\n odd+=sum1*x;\r\n even+=odd;\r\n sum2+=sum1;\r\n odd=0;\r\n sum1=0;\r\n }\r\n else\r\n {\r\n odd+=sum1*x;\r\n // even+=odd;\r\n }\r\n }\r\n console.log(odd+even);\r\n }\r\n // console.log(a);\r\n }\r\n})"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [n, k] = iInpArr();\r\n let arr = BInpArr();\r\n let ods = 0n,\r\n evs = 0n,\r\n odd = 0n,\r\n even = 0n;\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] % 2n === 0n) {\r\n evs += arr[i];\r\n even++;\r\n } else {\r\n ods += arr[i];\r\n odd++;\r\n }\r\n }\r\n for (let i = 0; i < k; i++) {\r\n let [p, v] = BInpArr();\r\n if (p === 0n) {\r\n if (v % 2n === 0n) {\r\n v = v * even;\r\n evs += v;\r\n console.log(ods + evs + \"\");\r\n } else {\r\n v = v * even;\r\n evs += v;\r\n console.log(ods + evs + \"\");\r\n ods += evs;\r\n odd += even;\r\n evs = 0n;\r\n even = 0n;\r\n }\r\n } else {\r\n if (v % 2n === 0n) {\r\n v = v * odd;\r\n ods += v;\r\n console.log(ods + evs + \"\");\r\n } else {\r\n v = v * odd;\r\n ods += v;\r\n console.log(ods + evs + \"\");\r\n evs += ods;\r\n even += odd;\r\n ods = 0n;\r\n odd = 0n;\r\n }\r\n }\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [n, q] = rns(),\r\n a = rns();\r\n let sum = 0n,\r\n odd = 0,\r\n even = 0;\r\n for (let i = 0; i < n; i++) {\r\n sum += BigInt(a[i]);\r\n if (a[i] & 1) odd++;else even++;\r\n }\r\n let res = new Array(q);\r\n for (let i = 0; i < q; i++) {\r\n const [t, v] = rns();\r\n if (v & 1) {\r\n if (t === 0) {\r\n sum += BigInt(v * even);\r\n odd += even;\r\n even = 0;\r\n } else {\r\n sum += BigInt(v * odd);\r\n even += odd;\r\n odd = 0;\r\n }\r\n } else {\r\n if (t === 0) {\r\n sum += BigInt(v * even);\r\n } else {\r\n sum += BigInt(v * odd);\r\n }\r\n }\r\n res[i] = sum;\r\n }\r\n return res.join('\\n');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n let even = 0\n let ce = 0\n let odd = 0\n let co = 0\n for (let x of arr) {\n if (x & 1) {\n odd += x\n co++\n } else {\n even += x\n ce++\n }\n }\n return qs.map(([t, x]) => {\n if (t === 0) {\n // to even\n if (x & 1) {\n odd += even + ce * x\n co += ce\n even = 0\n ce = 0\n } else {\n even += ce * x\n }\n } else {\n if (x & 1) {\n even += odd + co * x\n ce += co\n odd = 0\n co = 0\n } else {\n odd += co * x\n }\n }\n return even + odd\n }).join('\\n')\n}\n"}, {"source_code": "const readNum = () => +readline();\r\nconst readStr = () => readline();\r\nconst readStrArr = () => readline().split(' ');\r\nconst readNumArr = () => readline().split(' ').map(item => +item);\r\nconst createEmptyArr = (number) => new Array(number).fill(0);\r\nconst getSum = (arr) => {\r\n var sum = 0;\r\n for(var si = 0; si < arr.length; si++) {\r\n sum+=(+arr[si])\r\n }\r\n return sum;\r\n}\r\nconst sumNItems = (n) => {\r\n var sum = 0;\r\n for(var si = n; si > 0; si--) {\r\n sum+=si;\r\n }\r\n return sum;\r\n}\r\n\r\nvar n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var vars = readline().split(' ').map(item => +item);\r\n var arr = readline().split(' ').map(item => +item);\r\n var c1 = 0, c2 = 0, sum = 0;\r\n for(var k = 0; k < vars[0]; k++) {\r\n if(arr[k] % 2 === 1) {\r\n c1++;\r\n } else {\r\n c2++;\r\n }\r\n sum += arr[k];\r\n }\r\n for(var j = 0; j < vars[1]; j++) {\r\n var item = readline().split(' ').map(item => +item);\r\n if(item[0] === 0) {\r\n sum += c2 * item[1];\r\n } else {\r\n sum += c1 * item[1];\r\n }\r\n if(item[0] === 1 && c1 > 0 && item[1] % 2 === 1) {\r\n c2 = vars[0];\r\n c1 = 0;\r\n }\r\n if(item[0] === 0 && c2 > 0 && item[1] % 2 === 1) {\r\n c1 = vars[0];\r\n c2 = 0;\r\n }\r\n print(sum);\r\n }\r\n}"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var n = +readline();\r\n \r\n for(var i = 0; i < n; i++) {\r\n \r\n var opNums = readline().split(' ')[1];\r\n var arr = readline().split(' ').map(el => +el);\r\n \r\n var ops = []\r\n \r\n for(var j=0; j +el))\r\n }\r\n \r\n \r\n \r\n foo(arr, ops)\r\n }\r\n}\r\n\r\n\r\nfunction foo(arr, operations) {\r\n var juftNums = 0\r\n var toqNums = 0\r\n var sum = 0\r\n\r\n for(var i = 0; i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var n = +readline();\r\n \r\n for(var i = 0; i < n; i++) {\r\n \r\n var opNums = readline().split(' ')[1];\r\n var arr = readline().split(' ').map(el => +el);\r\n \r\n var ops = []\r\n \r\n for(var j=0; j +el))\r\n }\r\n \r\n \r\n \r\n foo(arr, ops)\r\n }\r\n}\r\n\r\n\r\nfunction foo(arr, operations) {\r\n var juftNums = 0\r\n var toqNums = 0\r\n var sum = 0\r\n// var results = []\r\n\r\n for(var i = 0; i +item);\r\n var arr = readline().split(' ').map(item => +item);\r\n var c1 = 0, c2 = 0, sum = 0;\r\n for(var k = 0; k < vars[0]; k++) {\r\n if(arr[k] % 2 === 1) {\r\n c1++;\r\n } else {\r\n c2++;\r\n }\r\n sum += arr[k];\r\n }\r\n for(var j = 0; j < vars[1]; j++) {\r\n var item = readline().split(' ').map(item => +item);\r\n if(item[0] === 0) {\r\n sum += c2 * item[1];\r\n } else {\r\n sum += c1 * item[1];\r\n }\r\n if(item[0] === 1 && c1 > 0 && item[1] % 2 === 1) {\r\n c2 = vars[1];\r\n c1 = 0;\r\n }\r\n if(item[0] === 0 && c2 > 0 && item[1] % 2 === 1) {\r\n c1 = vars[1];\r\n c2 = 0;\r\n }\r\n print(sum);\r\n }\r\n}"}], "src_uid": "d15cffca07768f8ce6fab7e13a6e7976"} {"source_code": "var l = readline().split(' ')\nvar n = l[0]\nvar m = l[1]\nvar pc = l[2]\nvar ptb = false\n\nvar prl, ps, pe, tia\nvar zt = 0\nvar tc = {}\n\nfor (var i = 0; i < n; i++) {\n l = readline()\n if (ptb) {\n if (~l.indexOf(pc)) {\n tc[l[ps - 1]] = true\n tc[l[pe + 1]] = true\n } else {\n tia = l.substring(ps, pe + 1)\n ;[].forEach.call(tia, function (v) {tc[v] = true})\n break\n }\n } else if (~l.indexOf(pc)) {\n ptb = true\n ps = l.indexOf(pc)\n pe = l.lastIndexOf(pc)\n if (prl) {\n tia = prl.substring(ps, pe + 1)\n ;[].forEach.call(tia, function (v) {tc[v] = true})\n }\n tc[l[ps - 1]] = true\n tc[l[pe + 1]] = true\n }\n prl = l\n}\n\ndelete tc['.']\ndelete tc[undefined]\n\nprint(Object.keys(tc).length)", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenize(readline());\n\tvar rowNum = parseInt(data[0]), colNum = parseInt(data[1]),\n\t\tpresidentColor = data[2];\n\n\tvar grid = [];\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tgrid.push(trim(readline()));\n\t}\n\n\tvar dr = [-1, 0, 1, 0], dc = [0, 1, 0, -1];\n\n\tvar count = 0;\n\tvar colors = { '.': true };\n\tcolors[presidentColor] = true;\n\n\tfor (var r = 0; r < rowNum; r += 1) {\n\t\tfor (var c = 0; c < colNum; c += 1) {\n\t\t\tif (grid[r][c] != presidentColor) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (var i = 0; i < 4; i += 1) {\n\t\t\t\tvar R = r+dr[i], C = c+dc[i];\n\t\t\t\tif (R < 0 || R >= rowNum || C < 0 || C >= colNum) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (colors[grid[R][C]] === undefined) {\n\t\t\t\t\tcolors[grid[R][C]] = true;\n\t\t\t\t\tcount += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(count);\n}\n\nmain();\n"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var board, c, count, done, h, i, input, j, k, m, n, neighbours, w, x, y, _i, _j, _k, _l, _m, _ref, _ref1, _ref2, _ref3, _ref4;\n\n input = readline().split(' ');\n\n _ref = [parseInt(input[0]), parseInt(input[1]), input[2]], n = _ref[0], m = _ref[1], c = _ref[2];\n\n board = [];\n\n for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {\n board.push(readline());\n }\n\n done = false;\n\n _ref1 = [0, 0], i = _ref1[0], j = _ref1[1];\n\n for (i = _j = 0; 0 <= n ? _j < n : _j > n; i = 0 <= n ? ++_j : --_j) {\n for (j = _k = 0; 0 <= m ? _k < m : _k > m; j = 0 <= m ? ++_k : --_k) {\n if (board[i][j] === c) {\n done = true;\n break;\n }\n }\n if (done) {\n break;\n }\n }\n\n _ref2 = [1, 1], w = _ref2[0], h = _ref2[1];\n\n while (board[i][j + w] === c) {\n w++;\n }\n\n while (board[i + h] && board[i + h][j] === c) {\n h++;\n }\n\n neighbours = {};\n\n for (y = _l = i, _ref3 = i + h; i <= _ref3 ? _l < _ref3 : _l > _ref3; y = i <= _ref3 ? ++_l : --_l) {\n neighbours[board[y][j - 1] || '.'] = true;\n neighbours[board[y][j + w] || '.'] = true;\n }\n\n for (x = _m = j, _ref4 = j + w; j <= _ref4 ? _m < _ref4 : _m > _ref4; x = j <= _ref4 ? ++_m : --_m) {\n if (board[i - 1]) {\n neighbours[board[i - 1][x]] = true;\n }\n if (board[i + h]) {\n neighbours[board[i + h][x]] = true;\n }\n }\n\n count = 0;\n\n for (k in neighbours) {\n if (k !== '.') {\n count++;\n }\n }\n\n print(count);\n\n}).call(this);\n"}, {"source_code": "x=readline().split(' ')\nn=+x[0]\nm=+x[1]\nc=x[2]\narr=[]\nfor(i=0;i= ref1; y = 1 <= ref1 ? ++j : --j) {\n line = readline().split(\"\");\n if (line.indexOf(c) > -1) {\n if (!start) {\n start = {\n y: y - 1,\n x: line.indexOf(c)\n };\n }\n finish = {\n y: y - 1,\n x: line.lastIndexOf(c)\n };\n }\n arr.push(line);\n }\n\n wrapArray(arr, \".\");\n\n map = {};\n\n for (y = k = ref2 = start.y + 1, ref3 = finish.y + 1; ref2 <= ref3 ? k <= ref3 : k >= ref3; y = ref2 <= ref3 ? ++k : --k) {\n for (x = l = ref4 = start.x + 1, ref5 = finish.x + 1; ref4 <= ref5 ? l <= ref5 : l >= ref5; x = ref4 <= ref5 ? ++l : --l) {\n map[arr[y - 1][x]] = 1;\n map[arr[y + 1][x]] = 1;\n map[arr[y][x - 1]] = 1;\n map[arr[y][x + 1]] = 1;\n }\n }\n\n delete map[\".\"];\n\n delete map[c];\n\n write(Object.keys(map).length);\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}, {"source_code": "\nvar s = readline().split(' ');\nvar r = parseInt(s[0]);\nvar c = parseInt(s[1]);\nvar PC = s[2];\n\nvar arr = []\nfor(var i=0; i= ref1; y = 1 <= ref1 ? ++j : --j) {\n line = readline().split(\"\");\n if (line.indexOf(c) > -1) {\n if (!start) {\n start = {\n y: y - 1,\n x: line.indexOf(c)\n };\n }\n finish = {\n y: y - 1,\n x: line.lastIndexOf(c)\n };\n }\n arr.push(line);\n }\n\n wrapArray(arr, \".\");\n\n map = {};\n\n ref2 = [start.y + 1, finish.y + 1];\n for (k = 0, len = ref2.length; k < len; k++) {\n y = ref2[k];\n ref3 = [start.x + 1, finish.x + 1];\n for (l = 0, len1 = ref3.length; l < len1; l++) {\n x = ref3[l];\n map[arr[y - 1][x]] = 1;\n map[arr[y + 1][x]] = 1;\n map[arr[y][x - 1]] = 1;\n map[arr[y][x + 1]] = 1;\n }\n }\n\n delete map[\".\"];\n\n delete map[c];\n\n write(Object.keys(map).length);\n\n}).call(this);\n\n//# sourceMappingURL=index.js.map\n"}], "src_uid": "d7601c9bb06a6852f04957fbeae54925"} {"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber( ' ');\n\n var res = [];\n var last = 0;\n var resIndex = 1;\n var rIndex = n - 1;\n var lIndex = 0;\n\n if(a[rIndex] > a[lIndex]) {\n last = a[lIndex];\n res.push('L');\n lIndex++;\n }\n else {\n last = a[rIndex];\n res.push('R');\n rIndex--;\n }\n\n for(var i = 1; i < n; i++) {\n if(a[rIndex] > a[lIndex] && last < a[lIndex]) {\n res.push('L');\n last = a[lIndex];\n lIndex++;\n }\n else if (last < a[rIndex]) {\n last = a[rIndex];\n res.push('R');\n rIndex--;\n }\n else if( last < a[lIndex]) {\n res.push('L');\n last = a[lIndex];\n lIndex++;\n }\n else {\n break;\n }\n }\n\n print(res.length);\n print(res.join(''))\n}());\n\n", "positive_code": [{"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = -1;\n while (left <= right) {\n if (a[left] < a[right]) {\n if (last < a[left]) {\n result.push('L');\n last = a[left];\n ++left;\n } else if (last < a[right]) {\n result.push('R')\n last = a[right];\n --right;\n } else {\n break;\n }\n } else if (a[left] > a[right]) {\n if (last < a[right]) {\n result.push('R')\n last = a[right];\n --right;\n } else if (last < a[left]) {\n result.push('L');\n last = a[left];\n ++left;\n } else {\n break;\n }\n } else {\n if (last < a[left]) {\n result.push('L')\n last = a[left];\n ++left;\n }\n break;\n }\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}], "negative_code": [{"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log(a.lenght)\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = 0;\n while (left <= right) {\n if (left == right && last < a[left]) {\n result.push('L')\n break;\n }\n if (last < a[left] && a[left] < a[right]) {\n result.push('L')\n last = a[left];\n ++left;\n continue;\n }\n if (last < a[right] && a[right] < a[left]) {\n result.push('R')\n last = a[right];\n --right;\n continue;\n }\n break;\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = 0;\n while (left <= right) {\n if (left == right && last < a[left]) {\n result.push('L')\n break;\n }\n if (a[left] < a[right] && last < a[left]) {\n result.push('L')\n last = a[left];\n ++left;\n continue;\n }\n if (last < a[right]) {\n result.push('R')\n last = a[right];\n --right;\n continue;\n }\n break;\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = -1;\n while (left <= right) {\n if (last < a[left] || last < a[right]) {\n if (a[left] < a[right]) {\n result.push('L');\n last = a[left];\n ++left;\n } else if (a[left] > a[right]) {\n result.push('R')\n last = a[right];\n --right;\n } else {\n if (last < a[left]) {\n result.push('L')\n last = a[left];\n ++left;\n }\n break;\n }\n }\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last;\n while (left <= right) {\n if (a[left] < a[right]) {\n result.push('L')\n last = left;\n ++left;\n } else if (a[left] > a[right]) {\n result.push('R')\n last = right;\n --right;\n } else {\n if (left == right && last !== undefined && a[last] < a[left]) {\n result.push('L')\n }\n break;\n }\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n if (a === undefined) {\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n }\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = 0;\n while (left <= right) {\n if (left == right && last < a[left]) {\n result.push('L')\n break;\n }\n if (a[left] < a[right] && last < a[left]) {\n result.push('L')\n last = a[left];\n ++left;\n continue;\n }\n if (last < a[right]) {\n result.push('R')\n last = a[right];\n --right;\n continue;\n }\n break;\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = -1;\n while (left <= right) {\n if (last < a[left] || last < a[right]) {\n if (a[left] < a[right]) {\n result.push('L');\n ++left;\n } else if (a[left] > a[right]) {\n result.push('R')\n --right;\n } else {\n result.push('L')\n break;\n }\n }\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = -1;\n while (left <= right) {\n if (left == right && last < a[left]) {\n result.push('L')\n break;\n }\n if (a[left] < a[right] && last < a[left]) {\n result.push('L')\n last = a[left];\n ++left;\n continue;\n }\n if (last < a[right]) {\n result.push('R')\n last = a[right];\n --right;\n continue;\n }\n break;\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "let n;\nlet a = [];\n\nconst run = () => {\n if (a.length === 1) {\n console.log('1')\n console.log('L')\n return;\n }\n let left = 0;\n let right = a.length - 1;\n let result = [];\n let last = -1;\n while (left <= right) {\n if (last < a[left] || last < a[right]) {\n if (a[left] < a[right]) {\n result.push('L');\n last = a[left];\n ++left;\n } else if (a[left] > a[right]) {\n result.push('R')\n last = a[right];\n --right;\n } else {\n result.push('L')\n last = a[left];\n ++left;\n break;\n }\n }\n }\n console.log(result.length)\n console.log(result.join(''))\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nrl.on('line', (data) => {\n if (n === undefined) {\n n = +(data.toString());\n return;\n }\n a = data.toString().trim().split(' ').filter(Boolean).map(Number);\n run();\n rl.close();\n})\n"}, {"source_code": "\n(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var n = read.number();\n var a = read.arrNumber( ' ');\n\n var res = [];\n var last = 0;\n var resIndex = 1;\n var rIndex = n - 1;\n var lIndex = 0;\n\n if(a[rIndex] > a[lIndex]) {\n last = a[lIndex];\n res.push('L');\n lIndex++;\n }\n else {\n last = a[rIndex];\n res.push('R');\n rIndex--;\n }\n \n for(var i = 1; i < n; i++) {\n if(a[rIndex] > a[lIndex] && last < a[lIndex]) {\n res.push('L');\n last = a[lIndex];\n lIndex++;\n }\n else if (last < a[rIndex]) {\n last = a[rIndex];\n res.push('R');\n rIndex--;\n }\n else {\n break;\n }\n }\n\n print(res.length);\n print(res.join(''))\n}());\n\n"}], "src_uid": "50c4b8fe3ab738e6e97058499791ac7b"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => n);\n let output = \"\";\n let max = -Infinity;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1n;\n for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);\n\n if (max < mul) max = mul;\n }\n max = max === -0n ? 0n : max;\n output += max;\n\n console.log(output);\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)\n\n const descComp = (a, b) => b - a\nlet i = 0\n while (T--) {\n\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 1n\n\n if (a.length === 5) {\n out += multToBigInt(...a) + '\\n'\n continue\n }\n\n const neg = []\n const pos = []\n\n for (let i = 0, l = a.length; i < l; i++) {\n const x = a[i]\n if (x < 0) neg.push(x)\n else pos.push(x)\n }\n\n pos.sort(descComp)\n neg.sort(cmpi)\n\n const nl = neg.length\n const pl = pos.length\n\n if (pl === 0) {\n for (let i = 5; i > 0; i--) {\n result *= BigInt(neg[nl - i])\n }\n } else if (nl === 0) {\n for (let i = 0; i < 5; i++) {\n result *= BigInt(pos[i])\n }\n } else {\n let lastNeg = null\n let lastPos = null\n let ni = 0\n let pi = 0\n\n for (let i = 0; i < 5; i++) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (ni === nl) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn > -nn) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn < -nn) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (result < 0n) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n }\n }\n\n if (result < 0n) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl || lastNeg === null) {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n } else if (ni === nl || lastPos === null) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else if (pn * lastPos > nn * lastNeg) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n }\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\nfunction min(a, b) {\n if (a > b) return b;\n return a;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(1, t, i => {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n // console.log(a);\n a=a.map(v => BigInt(v));\n let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);\n let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);\n let min2 = Arr(0, n - 2, (i, p) => min(p, min(a[i+1] * min1[i], a[i+1] * max1[i])), 1e100);\n let max2 = Arr(0, n - 2, (i, p) => max(p, max(a[i+1] * min1[i], a[i+1] * max1[i])), -1e100);\n let min3 = Arr(0, n - 3, (i, p) => min(p, min(a[i+2] * min2[i], a[i+2] * max2[i])), 1e100);\n let max3 = Arr(0, n - 3, (i, p) => max(p, max(a[i+2] * min2[i], a[i+2] * max2[i])), -1e100);\n let min4 = Arr(0, n - 4, (i, p) => min(p, min(a[i+3] * min3[i], a[i+3] * max3[i])), 1e100);\n let max4 = Arr(0, n - 4, (i, p) => max(p, max(a[i+3] * min3[i], a[i+3] * max3[i])), -1e100);\n let min5 = Arr(0, n - 5, (i, p) => min(p, min(a[i+4] * min4[i], a[i+4] * max4[i])), 1e100);\n let max5 = Arr(0, n - 5, (i, p) => max(p, max(a[i+4] * min4[i], a[i+4] * max4[i])), -1e100);\n console.log(max5[n-5]+'')\n })\n})();"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let max = Number.MIN_SAFE_INTEGER;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1;\n for (let j = 0; j < i; j++) mul *= arr[j];\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];\n max = Math.max(max, mul);\n }\n max = max === -0 ? 0 : max;\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (plusArr.length >= 3) {\n let [_plusAll, _plusThree] = [1, 1];\n for (let i = 0; i < plusArr.length; i++) {\n _plusAll *= plusArr[i];\n if (i < 3) _plusThree *= plusArr[i];\n }\n max = Math.max(max, _plusAll, _plusThree * minusArr[0] * minusArr[1]);\n }\n if (minusArr.length >= 4) {\n let [_minusAll, _minusThree] = [1, 1];\n for (let i = 0; i < minusArr.length; i++) {\n _minusAll *= minusArr[i];\n if (i < 4) _minusThree *= minusArr[i];\n }\n if (plusArr.length !== 0) {\n max = Math.max(max, _minusAll, _minusThree * plusArr[0]);\n } else {\n max = Math.max(max, _minusAll);\n }\n }\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let max = Number.MIN_SAFE_INTEGER;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1;\n for (let j = 0; j < i; j++) mul *= arr[j];\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];\n max = Math.max(max, mul);\n }\n max === -0 ? 0 : max;\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (arr.length === 5) {\n const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];\n max = Math.max(max, mul);\n }\n\n if (plusArr.length >= 5) {\n let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];\n\n max = Math.max(max, _plusAll);\n }\n\n if (plusArr.length >= 3 && minusArr.length >= 2) {\n let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];\n\n max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);\n }\n\n if (plusArr.length >= 1 && minusArr.length >= 4) {\n let _plusTwo = plusArr[0];\n\n max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n max = max === -0 ? 0 : max;\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => n);\n let output = \"\";\n let max = Number.MIN_SAFE_INTEGER;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1n;\n for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);\n\n if (max < mul) max = mul;\n }\n max = max === -0n ? 0n : max;\n output += max;\n\n console.log(output);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (plusArr.length >= 5) {\n let _plusAll = 1;\n for (let i = 0; i < plusArr.length; i++) {\n _plusAll *= plusArr[i];\n\n max = Math.max(max, _plusAll);\n }\n }\n\n if (plusArr.length >= 3 && minusArr.length >= 2) {\n let _plusThree = 1;\n for (let i = 0; i < plusArr.length; i++) {\n if (i < 3) _plusThree *= plusArr[i];\n }\n max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);\n }\n\n if (plusArr.length >= 1 && minusArr.length >= 4) {\n let _plusTwo = plusArr[0];\n\n max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (plusArr.length >= 5) {\n let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];\n\n max = Math.max(max, _plusAll);\n }\n\n if (plusArr.length >= 3 && minusArr.length >= 2) {\n let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];\n\n max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);\n }\n\n if (plusArr.length >= 1 && minusArr.length >= 4) {\n let _plusTwo = plusArr[0];\n\n max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let max = Number.MIN_SAFE_INTEGER;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1;\n for (let j = 0; j < i; j++) mul *= arr[j];\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];\n max = Math.max(max, mul);\n }\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (arr.length === 5) {\n const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];\n max = Math.max(max, mul);\n }\n\n if (plusArr.length >= 5) {\n let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];\n\n max = Math.max(max, _plusAll);\n }\n\n if (plusArr.length === 3) {\n max = Math.max(\n max,\n plusArr[0] * plusArr[1] * plusArr[2] * minusArr[0] * minusArr[1],\n plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]\n );\n }\n\n if (plusArr.length === 1 || plusArr.length === 2) {\n max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n max = max === -0 ? 0 : max;\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => n);\n let output = \"\";\n let max = Number.MIN_SAFE_INTEGER;\n arr.sort((a, b) => b - a);\n\n for (let i = 0; i <= 5; i++) {\n let mul = 1n;\n for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);\n for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);\n mul = mul + \"\";\n max = Math.max(max, mul);\n }\n max = max === -0n ? 0n : max;\n output += max;\n\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (arr.length === 5) {\n const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];\n max = Math.max(max, mul);\n }\n\n if (plusArr.length >= 5) {\n let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];\n\n max = Math.max(max, _plusAll);\n }\n\n if (plusArr.length === 3 || plusArr.length === 4) {\n max = Math.max(max, plusArr[0] * plusArr[1] * plusArr[2] * minusArr[0] * minusArr[1]);\n\n if (minusArr.length >= 4) {\n max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n }\n\n if (plusArr.length === 1 || plusArr.length === 2) {\n max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n max = max === -0 ? 0 : max;\n console.log(max);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let [plusArr, minusArr] = [[], []];\n const arr = readLine()\n .split(\" \")\n .map((n) => {\n n = parseInt(n);\n if (n >= 0) plusArr.push(n);\n else minusArr.push(n);\n return n;\n });\n\n plusArr.sort((a, b) => b - a);\n minusArr.sort((a, b) => a - b);\n\n let max = Number.MIN_SAFE_INTEGER;\n\n if (arr.length === 5) {\n const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];\n max = Math.max(max, mul);\n }\n\n if (plusArr.length >= 5) {\n let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];\n\n max = Math.max(max, _plusAll);\n }\n\n if (plusArr.length >= 3 && minusArr.length >= 2) {\n let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];\n\n max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);\n }\n\n if (plusArr.length >= 1 && minusArr.length >= 4) {\n let _plusTwo = plusArr[0];\n\n max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);\n }\n\n if (minusArr.length >= 5 && plusArr.length === 0) {\n let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];\n\n max = Math.max(max, _minusAll);\n }\n console.log(max);\n }\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\nfunction min(a, b) {\n if (a > b) return b;\n return a;\n}\nvar min = Math.min;\nvar max = Math.max;\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(1, t, i => {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n let amin = [], amax = [];\n let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);\n let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);\n let min2 = Arr(0, n - 2, (i, p) => min(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), 1e100);\n let max2 = Arr(0, n - 2, (i, p) => max(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), -1e100);\n let min3 = Arr(0, n - 3, (i, p) => min(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), 1e100);\n let max3 = Arr(0, n - 3, (i, p) => max(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), -1e100);\n let min4 = Arr(0, n - 4, (i, p) => min(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), 1e100);\n let max4 = Arr(0, n - 4, (i, p) => max(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), -1e100);\n let min5 = Arr(0, n - 5, (i, p) => min(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), 1e100);\n let max5 = Arr(0, n - 5, (i, p) => max(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), -1e100);\n console.log(max5[n - 5]+'')\n })\n})();"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i <= b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = a; i >= b; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction Arr(a, b, cb, prev) {\n let p = prev || 0;\n if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);\n return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\nfunction min(a, b) {\n if (a > b) return b;\n return a;\n}\nvar min = Math.min;\nvar max = Math.max;\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(1, t, i => {\n let n = inp[r++];\n let a = inp.slice(r, r = r + n);\n let amin = [], amax = [];\n let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);\n let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);\n let min2 = Arr(0, n - 2, (i, p) => min(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), 1e100);\n let max2 = Arr(0, n - 2, (i, p) => max(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), -1e100);\n let min3 = Arr(0, n - 3, (i, p) => min(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), 1e100);\n let max3 = Arr(0, n - 3, (i, p) => max(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), -1e100);\n let min4 = Arr(0, n - 4, (i, p) => min(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), 1e100);\n let max4 = Arr(0, n - 4, (i, p) => max(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), -1e100);\n let min5 = Arr(0, n - 5, (i, p) => min(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), 1e100);\n let max5 = Arr(0, n - 5, (i, p) => max(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), -1e100);\n console.log(max5[n - 5])\n })\n})();"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)\n\n const descComp = (a, b) => b - a\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 1n\n\n if (a.length === 5) {\n out += multToBigInt(...a) + '\\n'\n continue\n }\n\n const neg = []\n const pos = []\n\n for (let i = 0, l = a.length; i < l; i++) {\n const x = a[i]\n if (x < 0) neg.push(x)\n else pos.push(x)\n }\n\n pos.sort(descComp)\n neg.sort(cmpi)\n\n const nl = neg.length\n const pl = pos.length\n\n if (pl === 0) {\n for (let i = 5; i > 0; i--) {\n result *= BigInt(neg[nl - i])\n }\n } else if (nl === 0) {\n for (let i = 0; i < 5; i++) {\n result *= BigInt(pos[i])\n }\n } else {\n let lastNeg = null\n let lastPos = null\n let ni = 0\n let pi = 0\n\n for (let i = 0; i < 5; i++) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (ni === nl) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn > nn) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn < nn) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (result < 0n) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n }\n }\n\n if (result < 0n) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n } else if (ni === nl) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else if (pn > -nn) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n }\n }\n }\n\n out += result + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)\n\n const descComp = (a, b) => b - a\n\n while (T--) {\n\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 1n\ntry {\n if (a.length === 5) {\n out += multToBigInt(...a) + '\\n'\n continue\n }\n\n const neg = []\n const pos = []\n\n for (let i = 0, l = a.length; i < l; i++) {\n const x = a[i]\n if (x < 0) neg.push(x)\n else pos.push(x)\n }\n\n pos.sort(descComp)\n neg.sort(cmpi)\n\n const nl = neg.length\n const pl = pos.length\n\n if (pl === 0) {\n for (let i = 5; i > 0; i--) {\n result *= BigInt(neg[nl - i])\n }\n } else if (nl === 0) {\n for (let i = 0; i < 5; i++) {\n result *= BigInt(pos[i])\n }\n } else {\n let lastNeg = null\n let lastPos = null\n let ni = 0\n let pi = 0\n\n for (let i = 0; i < 5; i++) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (ni === nl) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn > -nn) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn < -nn) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (result < 0n) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n }\n }\n\n if (result < 0n) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl || lastNeg === null) {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n } else if (ni === nl || lastPos === null) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else if (pn > -nn) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n }\n }\n }\n\n out += result + '\\n'\n } catch (e) {\n console.log(e)\n console.log('n = ', n, 'a = ', a)\n }\n }\n\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)\n\n const descComp = (a, b) => b - a\n\n while (T--) {\n\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 1n\ntry {\n if (a.length === 5) {\n out += multToBigInt(...a) + '\\n'\n continue\n }\n\n const neg = []\n const pos = []\n\n for (let i = 0, l = a.length; i < l; i++) {\n const x = a[i]\n if (x < 0) neg.push(x)\n else pos.push(x)\n }\n\n pos.sort(descComp)\n neg.sort(cmpi)\n\n const nl = neg.length\n const pl = pos.length\n\n if (pl === 0) {\n for (let i = 5; i > 0; i--) {\n result *= BigInt(neg[nl - i])\n }\n } else if (nl === 0) {\n for (let i = 0; i < 5; i++) {\n result *= BigInt(pos[i])\n }\n } else {\n let lastNeg = null\n let lastPos = null\n let ni = 0\n let pi = 0\n\n for (let i = 0; i < 5; i++) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (ni === nl) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn > -nn) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn < -nn) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (result < 0n) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n }\n }\n\n if (result < 0n) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n } else if (ni === nl) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else if (pn > -nn) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n }\n }\n }\n\n out += result + '\\n'\n } catch (e) {\n console.log(e)\n console.log('n = ', n, 'a = ', a)\n }\n }\n\n console.log(out)\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)\n\n const descComp = (a, b) => b - a\nlet i = 0\n while (T--) {\ni++\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n\n let result = 1n\ntry {\n if (a.length === 5) {\n out += multToBigInt(...a) + '\\n'\n continue\n }\n\n const neg = []\n const pos = []\n\n for (let i = 0, l = a.length; i < l; i++) {\n const x = a[i]\n if (x < 0) neg.push(x)\n else pos.push(x)\n }\n\n pos.sort(descComp)\n neg.sort(cmpi)\n\n const nl = neg.length\n const pl = pos.length\n\n if (pl === 0) {\n for (let i = 5; i > 0; i--) {\n result *= BigInt(neg[nl - i])\n }\n } else if (nl === 0) {\n for (let i = 0; i < 5; i++) {\n result *= BigInt(pos[i])\n }\n } else {\n let lastNeg = null\n let lastPos = null\n let ni = 0\n let pi = 0\n\n for (let i = 0; i < 5; i++) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (ni === nl) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn > -nn) {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n } else if (pn < -nn) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else if (result < 0n) {\n lastNeg = nn\n result *= BigInt(lastNeg)\n ni++\n } else {\n lastPos = pn\n result *= BigInt(lastPos)\n pi++\n }\n }\n\n if (result < 0n) {\n const pn = pos[pi]\n const nn = neg[ni]\n if (pi === pl || lastNeg === null) {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n } else if (ni === nl || lastPos === null) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else if (pn > -nn) {\n result /= BigInt(lastNeg)\n result *= BigInt(pn)\n } else {\n result /= BigInt(lastPos)\n result *= BigInt(nn)\n }\n }\n }\n\n out += result + '\\n'\n if (i === 39) {\n console.log('n=', n, 'a=', a)\n }\n } catch (e) {\n console.log(e)\n console.log('n = ', n, 'a = ', a)\n }\n }\n\n console.log(out)\n}\n"}], "src_uid": "a3a64c3c7e9349d6e663c2d8113d2676"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n// alpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let n = $(), a = $(n)\n let r = n;\n let rc = Arr(n, i => 0)\n let fr = n - 1;\n ForR(n, i => {\n if (a[i] == 0) return;\n if (a[i] == 1) {\n r--;\n rc[r] = 1;\n out.push([r + 1, i + 1])\n } else if (a[i] == 2) {\n while (fr >= 0 && rc[fr] != 1) fr--;\n if (fr < 0) {\n log(-1);\n process.exit()\n }\n rc[fr] = 2;\n out.push([fr + 1, i + 1])\n } else {\n if (!out.length) {\n log(-1);\n process.exit();\n }\n r--;\n rc[r] = 2;\n let x = out[out.length - 1];\n rc[x[0] - 1] = 2;\n out.push([r + 1, x[1]])\n out.push([r + 1, i + 1])\n }\n })\n log(out.length);\n log(out.map(v => v.join(' ')).join('\\n'));\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number.parseInt(readLine());\n const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));\n let targets = 0;\n let nextRow = 0;\n let answer = '';\n try {\n for (let i = 0; i < expectedColHits.length; i++) {\n if (expectedColHits[i] === 1) {\n targets++;\n answer += (nextRow++ + 1) + ' ' + (i + 1) + '\\n';\n } else if (expectedColHits[i] === 2) {\n targets += 2;\n answer += (nextRow + 1) + ' ' + (i + 1) + '\\n';\n answer += (nextRow++ + 1) + ' ' + (1 + nextCol1(expectedColHits, i)) + '\\n';\n } else if (expectedColHits[i] === 3) {\n targets += 2;\n answer += (nextRow + 1) + ' ' + (i + 1) + '\\n';\n answer += (nextRow++ + 1) + ' ' + (1 + nextColGreater0(expectedColHits, i)) + '\\n';\n }\n }\n } catch (e) {\n console.log(-1);\n return;\n }\n if (nextRow > n) {\n console.log(-1);\n return;\n }\n console.log(targets);\n console.log(answer);\n}\n\nfunction nextCol1(expectedColHits, i) {\n for (let k = i+1; k < expectedColHits.length; k++) {\n if (expectedColHits[k] === 1) {\n expectedColHits[k] = 0;\n return k;\n }\n }\n throw new Error();\n}\nfunction nextColGreater0(expectedColHits, i) {\n for (let k = i+1; k < expectedColHits.length; k++) {\n if (expectedColHits[k] > 0) {\n return k;\n }\n }\n throw new Error();\n}\n"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n// alpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let n = $(), a = $(n)\n let r = n;\n let rc = Arr(n, i => 0)\n let fr = n - 1;\n ForR(n, i => {\n if (a[i] == 0) return;\n if (a[i] == 1) {\n r--;\n rc[r] = 1;\n out.push([r + 1, i + 1])\n } else if (a[i] == 2) {\n while (fr >= 0 && rc[fr] != 1) fr--;\n if (fr < 0) {\n log(-1);\n process.exit()\n }\n rc[fr] = 2;\n out.push([fr + 1, i + 1])\n } else {\n if (!out.length) {\n log(-1);\n process.exit();\n }\n r--;\n rc[r] = 2;\n out.push([r + 1, out[out.length - 1][1]])\n out.push([r + 1, i + 1])\n }\n })\n log(out.length);\n log(out.map(v => v.join(' ')).join('\\n'));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number.parseInt(readLine());\n const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));\n let targets = [];\n let nextRow = 0;\n try {\n for (let i = 0; i < expectedColHits.length; i++) {\n if (expectedColHits[i] === 1) {\n targets.push([nextRow++, i]);\n } else if (expectedColHits[i] === 2) {\n targets.push([nextRow, i]);\n targets.push([nextRow++, nextCol(expectedColHits, i)])\n } else if (expectedColHits[i] === 3) {\n const col = nextCol(expectedColHits, i);\n targets.push([nextRow, i]);\n targets.push([nextRow++, col])\n targets.push([nextRow++, col])\n }\n }\n } catch (e) {\n console.log(-1);\n return;\n }\n if (nextRow > n) {\n console.log(-1);\n return;\n }\n console.log(targets.length);\n for (let i = 0; i < targets.length; i++) {\n console.log(targets[i][0] + 1, targets[i][1] + 1);\n }\n}\n\nfunction nextCol(expectedColHits, i) {\n for (let k = i; k < expectedColHits.length; k++) {\n if (expectedColHits[k] === 1) {\n expectedColHits[k] = 0;\n return k;\n }\n }\n throw new Error();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const n = Number.parseInt(readLine());\n const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));\n let targets = 0;\n let nextRow = 0;\n let answer = '';\n try {\n for (let i = 0; i < expectedColHits.length; i++) {\n if (expectedColHits[i] === 1) {\n targets++;\n answer += nextRow++ + ' ' + i + '\\n';\n } else if (expectedColHits[i] === 2) {\n targets += 2;\n answer += nextRow++ + ' ' + i + '\\n';\n answer += nextRow++ + ' ' + nextCol1(expectedColHits, i) + '\\n';\n } else if (expectedColHits[i] === 3) {\n targets += 2;\n answer += nextRow++ + ' ' + i + '\\n';\n answer += nextRow++ + ' ' + nextColGreater0(expectedColHits, i) + '\\n';\n }\n }\n } catch (e) {\n console.log(-1);\n return;\n }\n if (nextRow > n) {\n console.log(-1);\n return;\n }\n console.log(targets);\n console.log(answer);\n}\n\nfunction nextCol1(expectedColHits, i) {\n for (let k = i+1; k < expectedColHits.length; k++) {\n if (expectedColHits[k] === 1) {\n expectedColHits[k] = 0;\n return k;\n }\n }\n throw new Error();\n}\nfunction nextColGreater0(expectedColHits, i) {\n for (let k = i+1; k < expectedColHits.length; k++) {\n if (expectedColHits[k] > 0) {\n return k;\n }\n }\n throw new Error();\n}\n"}], "src_uid": "de9139a4b7160fc519ab17ef21839ca7"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var ans = 0;\n for(j = 0; j < n; j++){\n ans += a[j];\n }\n console.log(Math.abs(ans));\n }\n }\n});", "positive_code": [{"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n, nums) {\r\n // print(n, nums);\r\n let s1 = 0, s2 = 0;\r\n for(let i = 0; i < n; i++) {\r\n if(nums[i] >= 0) {\r\n s1 += nums[i];\r\n } else {\r\n s2 += nums[i];\r\n }\r\n }\r\n let res = Math.abs(Math.abs(s1) -Math.abs(s2));\r\n print(res);\r\n \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, x);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n return Math.abs(arr.reduce((s, x) => s + x, 0))\n}\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n const n = Number(readline());\r\n let arr = readline().split(\" \").map(x => Number(x))\r\n console.log(findMaximumSum(arr))\r\n }\r\n}\r\n\r\nfunction findMaximumSum(arr) {\r\n arr.sort((a, b) => a - b)\r\n let sum1 = 0, sum2 = 0, i = 0;\r\n while (i < arr.length) {\r\n if (arr[i] < 0) sum1 += arr[i]\r\n else sum2 += arr[i]\r\n i++\r\n }\r\n\r\n return Math.abs(Math.abs(sum2) - Math.abs(sum1))\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\ta.sort((x, y) => x-y);\r\n\tvar cur = 0, sum = 0;\r\n\tfor(var i=0;i {\r\n const a = parseInt(x, 10)\r\n if (a > 0) s1 += a;\r\n else s2 += a\r\n })\r\n console.log(Math.abs(s1+s2))\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction powerOfTwo(x) {\r\n return Math.log2(x) % 1 === 0;\r\n}\r\n\r\nfunction mode(arr){\r\n return arr.sort((a,b) =>\r\n arr.filter(v => v===a).length\r\n - arr.filter(v => v===b).length\r\n ).pop();\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n\r\n loopwhile:\r\n while(t--)\r\n {\r\n let n = parseInt(readLine())\r\n\r\n let arr = readLine().split(\" \").map(x=>parseInt(x))\r\n \r\n let sumpos=0\r\n let sumneg=0\r\n //console.log(\"arr\" + arr)\r\n for(let i=0;i0)\r\n sumpos+=arr[i]\r\n else\r\n sumneg+=-arr[i]\r\n }\r\n //console.log(\"sumpos\" + sumpos)\r\n //console.log(\"sumneg\" + sumneg)\r\n if(sumpos>sumneg)\r\n console.log(sumpos - sumneg)\r\n else\r\n console.log(sumneg - sumpos)\r\n \r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n rn();\r\n const a = rns();\r\n let x = 0,\r\n y = 0;\r\n for (let num of a) {\r\n if (num > 0) {\r\n x += num;\r\n } else if (num < 0) {\r\n y -= num;\r\n }\r\n }\r\n return Math.abs(x - y);\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "const x = readline(); // first line\r\n\r\nfor(var i = 0 ; i < x ; i++) {\r\n readline(); // skip line\r\n var inp = readline().split(' ').map(x => parseInt(x));\r\n var func = arr => Math.abs(arr.reduce((prev, curr) => prev + curr, 0));\r\n print(func(inp));\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var caseLength = parseInt(readline());\r\n var caseArray = readline().split(\" \");\r\n var total = 0;\r\n for (var j = 0; j < caseLength; j++)\r\n {\r\n total += parseInt(caseArray[j]);\r\n }\r\n if (total < 0) total *= -1;\r\n print(total);\r\n}"}, {"source_code": "t=readline()\r\nwhile(t--){\r\n readline()\r\n r=0\r\n a=readline().split(\" \").map(Number)\r\n for(i=0;i absS2) ? (absS1 - absS2) : (absS2 - absS1);\r\n \r\n print(ret);\r\n}"}, {"source_code": "\"use strict\";\n\nconst rl = require('readline').createInterface(process.stdin, process.stdout);\nlet all_input = [];\n\nrl.on('line', function(input){\n all_input.push(input);\n});\n\nrl.on('close', function(line){\n let index = 0;\n let t = parseInt(all_input[index]);\n index++;\n\n //for(int i = 0; i < t; i++)\n while(t--)\n {\n let n = parseInt(all_input[index]);\n index++;\n\n let arr = all_input[index].trim().split(' ').map(Number);\n index++;\n solve(arr, n);\n }\n});\n\nfunction solve(arr, n)\n{\n let negative_sum = 0, positive_sum = 0;\n\n for(let i = 0; i < n; i++)\n {\n if(arr[i] <= 0)\n negative_sum += Math.abs(arr[i]);\n else\n positive_sum += arr[i];\n }\n\n console.log(Math.abs(negative_sum - positive_sum));\n}\n\n\n"}, {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin2(n, nums) {\r\n // print(n, nums);\r\n let s1 = 0, s2 = 0;\r\n for(let i = 0; i < n; i++) {\r\n if(nums[i] >= 0) {\r\n s1 += nums[i];\r\n } else {\r\n s2 += nums[i];\r\n }\r\n }\r\n let res = Math.abs(Math.abs(s1) -Math.abs(s2));\r\n print(res);\r\n}\r\n\r\nfunction begin(n, nums) {\r\n // print(n, nums);\r\n let sum = 0;\r\n for(let i = 0; i < n; i++) {\r\n sum += nums[i]\r\n }\r\n let res = Math.abs(sum);\r\n print(res); \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n var x = readline()\r\n .trim()\r\n .split(' ')\r\n .map((y) => parseInt(y, 10));\r\n begin(n, x);\r\n }\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nfunction solve(array)\n{\n let len = array.length;\n let negative_sum, positive_sum;\n\n negative_sum = positive_sum = 0;\n\n for(let i = 0; i < len; i++)\n {\n if(parseInt(array[i]) <= 0)\n negative_sum += Math.abs(parseInt(array[i]));\n else\n positive_sum += parseInt(array[i]);\n }\n\n console.log(Math.abs(negative_sum - positive_sum));\n}\n\nlet test_count = 0, n = 0;\n\nconst readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadline.on('line', function(line){\n let arr = line.split(' ');\n\n if(test_count === 0)\n n = arr[0];\n else if( (test_count != 0) && (test_count % 2 === 0) )\n {\n solve(arr);\n }\n\n if(test_count == (2 * n) )\n readline.close();\n\n test_count++;\n});\n"}], "src_uid": "f59f92a80f719cdb87ad92cd8c211942"} {"source_code": "function main(a,b,k,m,ar,br){\n\n var ans = 0;\n for(var i = b ; i > b-m-1 ; i--){\n\n if(ar[k-1] < br[i])ans++;\n }\n if(ans == m){\n print(\"YES\");\n return;\n }\n print(\"NO\");\n}\n\n\n\nvar ab = readline().split(\" \");\nfor(var i = 0 ; i < ab.length ; i++)ab[i] = parseInt(ab[i]);\n\nvar km = readline().split(\" \");\nfor(var i = 0 ; i < km.length ; i++)km[i] = parseInt(km[i]);\n\nvar ar = readline().split(\" \");\nfor(var i = 0 ; i < ar.length ; i++)ar[i] = parseInt(ar[i]);\n\nvar br = readline().split(\" \");\nfor(var i = 0 ; i < br.length ; i++)br[i] = parseInt(br[i]);\n\nmain(ab[0],ab[1],km[0],km[1],ar,br);\n", "positive_code": [{"source_code": "var input = readline().split(\" \"), na = +input[0], nb = +input[1],\n\tinput = readline().split(\" \"), k = +input[0], m = +input[1],\n\ta = readline().split(\" \").map(Number), b = readline().split(\" \").map(Number),\n\tarrA = [], arrB = [], maxA, minB;\n\nif(a[na-1] < a[nb-1]){\n\twrite(\"YES\");\n}\nelse{\n\tarrA = a.slice(0,k);\n\tarrB = b.reverse().slice(0,m).reverse();\n\n\tmaxA = Math.max.apply(null,arrA);\n\tminB = Math.min.apply(null,arrB);\n\n\tif(maxA < minB){\n\t\twrite(\"YES\");\n\t}\n\telse{\n\t\twrite(\"NO\");\n\t}\n}"}, {"source_code": "var data = readline().split(' ');\nvar Na = parseInt(data[0]);\nvar MasA=[];\nvar MasB=[];\nvar Nb = parseInt(data[1]);\nvar data = readline().split(' ');\nvar k = parseInt(data[0]);\nvar m = parseInt(data[1]);\nvar data = readline().split(' ');\nfor (i=0;i=MasB[MasB.length-m]){\n\tresult = \"NO\";\n}\n//write(MasA[k-1]+\" \");\n//write(MasB[MasB.length-m]+ \" \");\nwrite(result);"}, {"source_code": "var n1n2 = readline().split(' ');\n\nvar n1 = Number(n1n2[0]),\n\tn2 = Number(n1n2[1]);\n\nvar km = readline().split(' ');\n\nvar k = Number(km[0]);\nvar m = Number(km[1]);\n\nvar a = readline().split(' ').map(Number);\nvar b = readline().split(' ').map(Number);\n\nvar maxOfArr1 = a.slice(0, k)[k - 1];\nvar largerNumsInB = 0;\n\nfor (var i = b.length - 1; i >= 0; i--) {\n\tif (b[i] > maxOfArr1) {\n\t\tlargerNumsInB++;\n\t}\n}\n\nif (largerNumsInB >= m) {\n\tprint('YES');\n} else {\n\tprint('NO');\n}"}, {"source_code": "function getInputs() {\n return readline().split(' ').map(function(x) { return parseInt(x) });\n}\n\nvar inputs = getInputs();\n\nvar sizeA = inputs[0];\nvar sizeB = inputs[1];\n\nvar limits = getInputs();\n\nvar k = limits[0];\nvar m = limits[1];\n\nvar A = getInputs();\nvar B = getInputs();\n\nvar first = A.slice(0, k);\nvar second = B.slice(-m);\n\nvar answer = 'YES';\n\nfor (var i = 0; i < k; i++) {\n var item = first[i];\n \n var isLess = false;\n \n for (var j = 0; j < m; j++) {\n \n if (item < second[j]) {\n isLess = true;\n break;\n } else {\n isLess = false;\n break;\n }\n }\n \n if (!isLess) {\n answer = 'NO';\n break;\n }\n}\n\nprint(answer);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const lengths = readline().split(' ');\n const choosenNumbers = readline().split(' ');\n const arrayA = readline().split(' ');\n const arrayB = readline().split(' ');\n const choosenNumbersFromA = parseInt(choosenNumbers[0])\n const choosenNumbersFromB = parseInt(choosenNumbers[1])\n\n console.log(helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) ? 'YES' : 'NO')\n}\n\nfunction helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {\n return parseInt(arrayA[choosenNumbersFromA - 1]) < parseInt(arrayB[arrayB.length - choosenNumbersFromB])\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet k, m;\nlet arr1, arr2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n [k, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n if (c === 2) {\n arr1 = d.split(' ').map(Number);\n c++;\n return;\n }\n\n arr2 = d.split(' ').map(Number).reverse();\n\n if (arr1[k - 1] < arr2[m - 1]) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n\n c++;\n});\n"}], "negative_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const lengths = readline().split(' ');\n const choosenNumbers = readline().split(' ');\n const arrayA = readline().split(' ');\n const arrayB = readline().split(' ');\n const choosenNumbersFromA = parseInt(choosenNumbers[0])\n const choosenNumbersFromB = parseInt(choosenNumbers[1])\n\n console.log(helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) ? 'YES' : 'NO')\n}\n\nfunction helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {\n return arrayA[choosenNumbersFromA - 1] < arrayB[arrayB.length - choosenNumbersFromB]\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const lengths = readline();\n const choosenNumbers = readline();\n const arrayA = readline();\n const arrayB = readline();\n\n console.log(helper(parseInt(choosenNumbers.split(' ')[0]), arrayA.split(' '), arrayB.split(' ')) ? 'YES' : 'NO')\n}\n\nfunction helper(choosenNumbersFromA, arrayA, arrayB) {\n return arrayA[choosenNumbersFromA - 1] < arrayB[0]\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const lengths = readline();\n const choosenNumbers = readline();\n const arrayA = readline();\n const arrayB = readline();\n\n console.log(helper(choosenNumbers[0], arrayA, arrayB) ? 'YES' : 'NO')\n}\n\nfunction helper(choosenNumbersFromA, arrayA, arrayB) {\n return arrayA[choosenNumbersFromA - 1] < arrayB[0]\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const lengths = readline();\n const choosenNumbers = readline();\n const arrayA = readline();\n const arrayB = readline();\n\n console.log(helper(parseInt(choosenNumbers.split(' ')[0]), parseInt(choosenNumbers.split(' ')[1]), arrayA.split(' '), arrayB.split(' ')) ? 'YES' : 'NO')\n}\n\nfunction helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {\n return arrayA[choosenNumbersFromA - 1] < arrayB[arrayB.length - choosenNumbersFromB - 1]\n}\n"}, {"source_code": "var data = readline().split(' ');\nvar Na = data[0];\nvar MasA=[];\nvar MasB=[];\nvar Nb = data[1];\nvar data = readline().split(' ');\nvar k = data[0]-1;\nvar m = data[1]-1;\nvar data = readline().split(' ');\nfor (i=0;i=MasB[MasB.length-Nb]){\n\tresult = \"NO\";\n}\nwrite(result);"}, {"source_code": "var data = readline().split(' ');\nvar Na = data[0];\nvar MasA=[];\nvar MasB=[];\nvar Nb = data[1];\nvar data = readline().split(' ');\nvar k = data[0];\nvar m = data[1];\nvar data = readline().split(' ');\nfor (i=0;i=MasB[MasB.length-m]){\n\tresult = \"NO\";\n}\n//write(MasA[k-1]+\" \");\n//write(MasB[MasB.length-m]+ \" \");\nwrite(result);"}, {"source_code": "function getInputs() {\n return readline().split(' ').map(function(x) { return parseInt(x) });\n}\n\nvar inputs = getInputs();\n\nvar sizeA = inputs[0];\nvar sizeB = inputs[1];\n\nvar limits = getInputs();\n\nvar k = limits[0];\nvar m = limits[1];\n\nvar A = getInputs();\nvar B = getInputs();\n\nvar first = A.slice(0, k);\nvar second = B.slice(-m);\n\nvar answer = 'YES';\n\nfor (var i = 0; i < k; i++) {\n var item = first[i];\n \n var isLess = false;\n \n for (var j = 0; j < m; j++) {\n \n if (item < second[j]) {\n isLess = true;\n break;\n }\n }\n \n if (!isLess) {\n answer = 'NO';\n break;\n }\n}\n\nprint(answer);"}, {"source_code": "function getInputs() {\n return readline().split(' ').map(function(x) { return parseInt(x) });\n}\n\nvar inputs = getInputs();\n\nvar sizeA = inputs[0];\nvar sizeB = inputs[1];\n\nvar limits = getInputs();\n\nvar k = limits[0];\nvar m = limits[1];\n\nvar A = getInputs();\nvar B = getInputs();\n\nvar first = A.slice(k);\nvar second = B.slice(-m);\n\nvar answer = 'YES';\n\nfor (var i = 0; i < k; i++) {\n var item = first[i];\n \n var isLess = false;\n \n for (var j = 0; j < m; j++) {\n \n if (item < second[j]) {\n isLess = true;\n break;\n }\n }\n \n if (!isLess) {\n answer = 'NO';\n break;\n }\n}\n\nprint(answer);\n\n\n\n"}], "src_uid": "8e0581cce19d6bf5eba30a0aebee9a08"} {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n}\r\n\r\nvar t = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i +c)\r\n a = c[0]\r\n b = c[1]\r\n print(a*b)\r\n}\r\n"}, {"source_code": "T = readline()\r\n\r\nwhile (T--) {\r\n n = readline().split(' ').map(x => +x)\r\n a = n[0]\r\n b = n[1]\r\n print(a*b)\r\n}"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n \r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n \r\nlet count = -1\r\nlet inputArr = []\r\n \r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n \r\n \r\nfunction solve([a,b]) {\r\n console.log(a*b) \r\n}\r\n \r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n solve(inputArr[i])\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tmyout(a * b);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 998244353n\r\nvar maxN = 10e6 + 1\r\n\r\nfunction main() {\r\n var x = parseInt(readline())\r\n //\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n // var a = new Array(n)\r\n // var marked = new Array(n).fill(false)\r\n // var found = new Array(n).fill(false)\r\n var [a,b] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n // var b = readline().split('').map((x, iii) => {\r\n // return x\r\n // });\r\n console.log(a*b)\r\n })\r\n}\r\n\r\n\r\nfunction find(value, a) {\r\n var l = -1\r\n var r = a.length\r\n while (r > l + 1) {\r\n var m = Math.floor((r + l) / 2)\r\n // console.log(a[m], f, l, r)\r\n if (a[m] <= value) l = m\r\n if (a[m] > value) r = m\r\n }\r\n return r\r\n}\r\n"}], "negative_code": [{"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([a,b]) {\r\n console.log(a*b) \r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) {\r\n console.log(inputArr[i])\r\n }\r\n}"}], "src_uid": "806dcdab8364f5169334e172a192598a"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, x = 0;\n for(i = 1; i <= t * 2; i++){\n var a = lines[i].split(' ').map(Number);\n if(i % 2 == 1){\n n = a[0], x = a[1];\n }else{\n var ans = 0;\n var min = 2e9;\n var max = 0;\n for(j = 0; j < n; j++){\n min = Math.min(min, a[j]);\n max = Math.max(max, a[j]);\n if(max - min > x * 2){\n ans++;\n min = max = a[j];\n }\n }\n console.log(ans);\n }\n }\n});\n", "positive_code": [{"source_code": "var tests = parseInt(readline());\r\n var n, x;\r\n var arr;\r\n for (var t=0; t < tests; t++) {\r\n var nx = readline().split(' ').map(x=>parseInt(x));\r\n n = nx[0];\r\n x = nx[1];\r\n var f = readline().split(' ').map(x=>parseInt(x));\r\n var count = 0;\r\n var min = f[0], max = f[0];\r\n for (var i = 1; i < n; i++) {\r\n var fi = f[i];\r\n if (fi < min) {\r\n min = fi;\r\n }\r\n if (fi > max) {\r\n max = fi;\r\n }\r\n if (max - min > 2 * x) {\r\n count++;\r\n max = fi;\r\n min = fi;\r\n }\r\n }\r\n print(count);\r\n }"}], "negative_code": [], "src_uid": "1f520f2796094b0f0c4e11e231f9ca8c"} {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, step, fn) {\n let res;\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n let arr = Array(Math.max(a, b) + 1);\n if (init) init(arr);\n for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [];\n let t = $()\n while (t--) {\n let n = $()\n let a = $(n)\n let s = a.sum()\n if (s <= n / 2) {\n console.log(n - s);\n console.log(Array(n - s).fill(0).join(' '))\n } else {\n console.log((s / 2 | 0) * 2);\n console.log(Array((s / 2 | 0) * 2).fill(1).join(' '))\n }\n }\n})();\n\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array();\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var zero = 0;\n var one = 0;\n var odd = 0;\n var even = 0;\n for(var j = 0; j < N; j++){\n if(j % 2 == 0){\n even += list[j];\n }else{\n odd += list[j];\n }\n if(list[j] == 0){\n zero++;\n }else{\n one++;\n }\n }\n if(even != odd){\n if(one > zero){\n for(var j = 0; j < N; j++){\n if(list[j] == 0){\n list.splice(j, 1);\n j--;\n }\n }\n if(list.length % 2 == 1){\n list.pop();\n }\n }else{\n for(var j = 0; j < N; j++){\n if(list[j] == 1){\n list.splice(j, 1);\n j--;\n }\n }\n }\n }\n \n output.push(list.length);\n output.push(myconv(list, 8));\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [count0, count1] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n if (arr[i] === 1) count1++;\n else count0++;\n }\n\n if (count0 >= len / 2) {\n console.log(len / 2);\n console.log(\"0 \".repeat(len / 2).trim());\n } else {\n const l = len / 2 + ((len / 2) % 2);\n console.log(l);\n console.log(\"1 \".repeat(l).trim());\n }\n }\n}\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [count0, count1] = [0, 0];\n\n for (let i = 0; i < len; i++) {\n if (arr[i] === 1) count1++;\n else count0++;\n }\n\n if (count0 >= len / 2) {\n console.log(len / 2);\n console.log(\"0 \".repeat(len / 2).trim());\n } else {\n const l = len / 2 + (len % 2);\n console.log(l);\n console.log(\"1 \".repeat(l).trim());\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let countOne = 0;\n for (let i = 0; i < len; i++) if (arr[i] === 1) countOne++;\n\n if (countOne === 0 || countOne % 2 === 0) {\n console.log(len);\n console.log(`${arr.join(\" \")}`);\n } else {\n const oneIndex = arr.findIndex((n) => n === 1);\n arr.splice(oneIndex, 1);\n console.log(`${arr.length}`);\n console.log(`${arr.join(\" \")}`);\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const len = +readLine();\n let arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n let [maxIndex, sum, oneArr, zeroArr] = [0, arr[0], [], []];\n\n if (arr[0] === 0) zeroArr.push(0);\n else oneArr.push(1);\n\n for (let i = 1; i <= len - 1; i++) {\n if (arr[i] === 0) zeroArr.push(0);\n else oneArr.push(1);\n\n if (i % 2 !== 0) {\n sum -= arr[i];\n } else sum += arr[i];\n if (sum === 0) maxIndex = i;\n }\n if (oneArr.length === 0 || maxIndex === 0) {\n console.log(zeroArr.length);\n console.log(`${zeroArr.join(\" \")}`);\n } else {\n arr = arr.slice(0, maxIndex + 1);\n console.log(arr.length);\n console.log(`${arr.join(\" \")}`);\n }\n }\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array();\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var zero = 0;\n var one = 0;\n\n for(var j = 0; j < N; j++){\n if(list[j] == 0){\n zero++;\n }else{\n one++;\n }\n }\n if(one > zero){\n for(var j = 0; j < N; j++){\n if(list[j] == 0){\n list.splice(j, 1);\n j--;\n }\n }\n }else if(one < zero){\n for(var j = 0; j < N; j++){\n if(list[j] == 1){\n list.splice(j, 1);\n j--;\n }\n }\n }\n if(list.length % 2 == 1){\n list.pop();\n }\n output.push(list.length);\n output.push(myconv(list, 8));\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array();\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var odd = 0;\n var even = 0;\n for(var j = 0; j < N; j++){\n if(j % 2 == 0){\n even += list[j];\n }else{\n odd += list[j];\n }\n }\n if(odd > even){\n for(var j = 1; j < N; j += 2){\n if(list[j - 1] == 0 && list[j] == 1){\n list.splice(j, 1);\n j--;\n odd--;\n }\n if(odd == even){\n break;\n }\n }\n }else if(odd < even){\n for(var j = 0; j < N; j += 2){\n if(list[j] == 1 && list[j + 1] == 0){\n list.splice(j, 1);\n j--;\n even--;\n }\n if(odd == even){\n break;\n }\n }\n }\n output.push(list.length);\n output.push(myconv(list, 8));\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array();\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var odd = 0;\n var even = 0;\n for(var j = 0; j < N; j++){\n if(j % 2 == 0){\n even += list[j];\n }else{\n odd += list[j];\n }\n }\n if(odd > even){\n for(var j = 1; j < N; j += 2){\n if(list[j] == 1){\n list.splice(j, 1);\n j--;\n odd--;\n }\n if(odd == even){\n break;\n }\n }\n }else if(odd < even){\n for(var j = 0; j < N; j += 2){\n if(list[j] == 1){\n list.splice(j, 1);\n j--;\n even--;\n }\n if(odd == even){\n break;\n }\n }\n }\n output.push(list.length);\n output.push(myconv(list, 8));\n }\n myout(myconv(output, 9));\n}"}], "src_uid": "eca92beb189c4788e8c4744af1428bc7"} {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet arr = [];\n\nrl.on(\"line\", (line) => {\n arr.push(line);\n}).on(\"close\", () => {\n solve(arr);\n process.exit(0);\n});\n\nfunction solve(lines) {\n let row = 0;\n let t = +lines[row++];\n for(let i = 0; i < t; i++) {\n let n = +lines[row++];\n numbers_arr = lines[row++].split(\" \").map(x => +x);\n calc_seconds(numbers_arr);\n }\n}\n\nfunction calc_seconds(arr) {\n let max = arr[0];\n let max_diff = 0;\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < max && max - arr[i] > max_diff) {\n max_diff = max - arr[i];\n }\n if(arr[i] > max) {\n max = arr[i];\n }\n }\n console.log(closest_lower_pow(max_diff));\n}\n\nfunction closest_lower_pow(num) {\n if(num == 0) {\n return 0;\n }\n let power = 0;\n while(Math.pow(2, power) <= num) {\n power++;\n }\n return power;\n}\n", "positive_code": [{"source_code": "let i = '';\nlet lines;\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const { EOL } = require('os');\n lines = i.split(EOL); /*your input text, split by lines*/\n main();\n});\n\nfunction solve(n, nums) {\n let mx = nums[0];\n let mxChange = 0;\n nums.forEach(val => {\n mx = Math.max(mx, val);\n mxChange = Math.max(mxChange, mx - val);\n })\n let k = 0;\n while (mxChange > 0) {\n mxChange -= 1 << k;\n ++k;\n }\n return k;\n}\n\nfunction main() {\n let currentLine = 0;\n const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));\n\n const test = readLine()[0];\n for (let t = 1; t <= test; ++t) {\n const n = readLine()[0];\n const nums = readLine();\n const S = solve(n, nums);\n console.log(S);\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(a, n) {\n let max = a[0];\n let diff = 0;\n for (let i = 1; i < n; i++) {\n diff = Math.max(diff, max - a[i]);\n max = Math.max(max, a[i]);\n }\n let t = diff.toString(2);\n return t === '0' ? t : t.length;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(a, n);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\n\nfunction main() {\n var tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n var N = nextInt();\n var a = [];\n var mx = -1000000007;\n var maxDiff = 0;\n for (let i = 0; i < N; i++) {\n a.push(nextInt());\n if (a[i] < mx) {\n maxDiff = Math.max(maxDiff, mx-a[i]);\n } else {\n mx = a[i];\n }\n }\n var res = 0, sum = 1;\n while (sum-1 < maxDiff) {\n res++;\n sum *= 2;\n }\n print(res);\n }\n}\n// ----------------------------------- Template -----------------------------------\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "wt = write;\nrd = readline;\n\nfor(_ = parseInt(rd()); _ ; _--){\n\tn = parseInt(rd());\n\tarr = rd().split(\" \").map(function(x){ return parseInt(x); });\n\tmax = arr[n - 1], ans = 0;\n\tmin = max;\n\tmp = {};\n\tfor(i = n - 2; i >= 0; i--){\n\t\tmax = arr[i];\n\t\ttmp = max - min;\n\t\ttmp = Math.max(tmp,0);\n\t\tcnt = 0;\n\t\t// wt(tmp);\n\t\twhile(tmp > 0){\n\t\t\tcnt += 1;\n\t\t\ttmp = parseInt(tmp / 2);\n\t\t}\n\t\t// wt(\" \" + cnt + '\\n');\n\t\tans = Math.max(cnt, ans);\n\t\tmin = Math.min(min, arr[i]);\n\t\t// wt(cnt + '\\n');\n\t}\n\twt(ans + '\\n');\n}"}, {"source_code": "!function(t){var n={};function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}e.m=t,e.c=n,e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:o})},e.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(e.r(o),Object.defineProperty(o,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var r in t)e.d(o,r,function(n){return t[n]}.bind(null,r));return o},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,\"a\",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p=\"\",e(e.s=0)}([function(t,n,e){\"use strict\";e.r(n);var o=function(){function t(t){this.inputs=t,this.cumSumTwoPow=[],this.onlyTwoPow=[],this.oneTimeGeneration(),this.startSolnWithTestCases()}return t.prototype.startSolnWithTestCases=function(){for(var t=0,n=this.inputs[t++];n--;){for(var e=this.inputs[t++],o=[],r=0;r=n){e.newValue=t+r,e.result=o+1;break}}return e},t.prototype.generateCumulativeSumOfPowerOfTwo=function(){var t=1,n=1;this.cumSumTwoPow.push(t),this.onlyTwoPow.push(n);for(;n<=2000000010;)t+=n*=2,this.cumSumTwoPow.push(t),this.onlyTwoPow.push(n)},t.prototype.consoleLogResult=function(t){var n=t.join(\" \").trim();console.log(n)},t}();new(function(){function t(){var t=this;this.inputString=\"\",this.inputString=\"\",process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){return t.inputString+=n})),process.stdin.on(\"end\",(function(){new o(t.processInputString())}))}return t.prototype.processInputString=function(){for(var t=[],n=\"\",e=0;e {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 1){\n console.log(0);\n continue;\n }else if(n === 2){\n if(a[0] <= a[1]){\n console.log(0);\n }else{\n console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));\n }\n continue;\n }\n \n let max = 0;\n for(let i = 1; i < n; i++){\n if(a[i] < a[i-1]){\n max = Math.max(max, a[i-1]-a[i]);\n a[i] = a[i-1];\n }\n }\n\n console.log(Math.ceil(Math.log2(max+1)));\n }\n}"}], "negative_code": [{"source_code": "!function(t){var n={};function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}e.m=t,e.c=n,e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:o})},e.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(e.r(o),Object.defineProperty(o,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var r in t)e.d(o,r,function(n){return t[n]}.bind(null,r));return o},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,\"a\",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p=\"\",e(e.s=0)}([function(t,n,e){\"use strict\";e.r(n);var o=function(){function t(t){this.inputs=t,this.cumSumTwoPow=[],this.oneTimeGeneration(),this.startSolnWithTestCases()}return t.prototype.startSolnWithTestCases=function(){for(var t=0,n=this.inputs[t++];n--;){for(var e=this.inputs[t++],o=[],r=0;r=n)break}return e},t.prototype.generateCumulativeSumOfPowerOfTwo=function(){var t=1,n=1;this.cumSumTwoPow.push(t);for(;n<=2000000010;)t+=n*=2,this.cumSumTwoPow.push(t)},t.prototype.consoleLogResult=function(t){var n=t.join(\" \").trim();console.log(n)},t}();new(function(){function t(){var t=this;this.inputString=\"\",this.inputString=\"\",process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){return t.inputString+=n})),process.stdin.on(\"end\",(function(){new o(t.processInputString())}))}return t.prototype.processInputString=function(){for(var t=[],n=\"\",e=0;e=n){e.newValue=t+r,e.result=o+1;break}}return e},t.prototype.generateCumulativeSumOfPowerOfTwo=function(){var t=1,n=1;this.cumSumTwoPow.push(t),this.onlyTwoPow.push(n);for(;n<=2000000010;)t+=n*=2,this.cumSumTwoPow.push(t),this.onlyTwoPow.push(n)},t.prototype.consoleLogResult=function(t){var n=t.join(\" \").trim();console.log(n)},t}();new(function(){function t(){var t=this;this.inputString=\"\",this.inputString=\"\",process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){return t.inputString+=n})),process.stdin.on(\"end\",(function(){new o(t.processInputString())}))}return t.prototype.processInputString=function(){for(var t=[],n=\"\",e=0;e {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 1){\n console.log(0);\n continue;\n }else if(n === 2){\n if(a[0] <= a[1]){\n console.log(0);\n }else{\n console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));\n }\n continue;\n }\n let res = 0;\n let s = 0;\n let c = 0;\n for(let i = n-2; i >= 0; i--){\n if(a[i] < a[i+1]){\n let sum = c*a[i+1]-s+1;\n res += Math.ceil(Math.log2(sum));\n c = 0;\n s = 0;\n }else{\n c += 1;\n s += a[i+1];\n }\n }\n\n console.log(res);\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n A();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction A(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let n = pi(readline());\n let a = ti(readline().split(' '));\n if(n === 1){\n console.log(0);\n continue;\n }else if(n === 2){\n if(a[0] <= a[1]){\n console.log(0);\n }else{\n console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));\n }\n continue;\n }\n let res = 0;\n let s = 0;\n let c = 0;\n for(let i = n-2; i >= 0; i--){\n if(a[i] < a[i+1]){\n let sum = c*a[i+1]-s+1;\n res = Math.max(res, Math.ceil(Math.log2(sum)));\n c = 0;\n s = 0;\n }else{\n c += 1;\n s += a[i+1];\n }\n }\n\n console.log(res);\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin; \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(a, n) {\n let t = 0;\n let swap = true;\n while (swap) {\n swap = false;\n let x = Math.pow(2, t);\n for (let i = 1; i < n; i++) {\n if (a[i] < a[i - 1]) {\n a[i] += x;\n swap = true;\n }\n }\n if (!swap) break;\n t++;\n }\n return t;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let n = parseInt(readLine());\n let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(a, n);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\n\nfunction main() {\n var tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n var N = nextInt();\n var a = [];\n var mx = -1000000007;\n var maxDiff = 0;\n for (let i = 0; i < N; i++) {\n a.push(next());\n if (a[i] < mx) {\n maxDiff = Math.max(maxDiff, mx-a[i]);\n } else {\n mx = a[i];\n }\n }\n var res = 0, sum = 1;\n if (maxDiff == 0) {\n print(0);\n } else {\n while (sum-1 < maxDiff) {\n res++;\n sum *= 2;\n }\n print(res);\n }\n }\n}\n// ----------------------------------- Template -----------------------------------\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}, {"source_code": "// node template.js < A-small.in > A-small.out\n\n\nfunction main() {\n var tests = nextInt();\n\n for (let t = 1; t <= tests; t++) {\n var N = nextInt();\n var a = [];\n var mx = -1000000007;\n var maxDiff = 0;\n for (let i = 0; i < N; i++) {\n a.push(next());\n if (a[i] < mx) {\n maxDiff = Math.max(maxDiff, mx-a[i]);\n } else {\n mx = a[i];\n }\n }\n if (maxDiff == 0) {\n print(0);\n } else {\n print(Math.ceil(Math.log2(maxDiff))+1);\n }\n }\n}\n// ----------------------------------- Template -----------------------------------\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, 'startsWith', {\n value: function(search, rawPos) {\n var pos = rawPos > 0 ? rawPos|0 : 0;\n return this.substring(pos, pos + search.length) === search;\n }\n });\n}\nif (!String.prototype.endsWith) {\n String.prototype.endsWith = function(search, this_len) {\n if (this_len === undefined || this_len > this.length) {\n this_len = this.length;\n }\n return this.substring(this_len - search.length, this_len) === search;\n };\n}\n\nvar curTokens = [], curToken = 0;\n\nfunction next() {\n while (curToken >= curTokens.length) {\n curTokens = readline().split(/[\\s]+/);\n curToken = 0;\n }\n return curTokens[curToken++];\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\n// code for nodejs\nvar inputBuffer = '', curLine = 0;\n\nfunction readline() {\n return inputBuffer[curLine++];\n}\n\nfunction print(data) {\n process.stdout.write(data + '\\n');\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('data', function (chunk) {\n inputBuffer += chunk;\n});\n\nprocess.stdin.on('end', function () {\n inputBuffer = inputBuffer.split(/[\\s]+/);\n main();\n});"}], "src_uid": "bfc2e7de37db4a0a74cdd55f2124424a"} {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\tif (prob[0] - prob[3] * prob[1] <= 0) {\n\t\twrite ('-1\\n');\n\t\tcontinue;\n\t}\n\tif (prob[0] == prob[1] * prob[2]) {\n\t\twrite ((prob[1] - 1) + '\\n');\n\t\tcontinue;\n\t}\n\tvar hehe = (prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]);\n\tif (hehe == Math.floor(hehe)) {\n\t\twrite(Math.min(hehe - 1, prob[1]) + '\\n');\n\t} else {\n\t\twrite(Math.min(Math.floor(hehe), prob[1]) + '\\n');\n\t}\n}", "positive_code": [{"source_code": "\"use strict\";\n\nvar q = +readline()\n\nwhile (q--) {\n var input = readline().split(' ').map(value => +value);\n var k = input[0];\n var n = input[1];\n var a = input[2];\n var b = input[3];\n var delta = a - b;\n var maxMovesWithCharge = Math.floor(k/b);\n \n if (maxMovesWithCharge < n) {\n write('-1\\n');\n } else if (maxMovesWithCharge === n && !(k%b)) {\n write('-1\\n');\n } else {\n var batteryUsageWithCharge = n*b;\n var batteryRemains = k - batteryUsageWithCharge - 1;\n var result = Math.floor(batteryRemains/delta);\n write(Math.min(result, n) + '\\n');\n }\n}"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var q = read.number();\n var res = '';\n while (q) {\n q--;\n\n var line = read.arrNumber(' ');\n var k = line[0];\n var n = line[1];\n var a = line[2];\n var b = line[3];\n\n if (k <= b * n) {\n res += '-1\\n';\n }\n else {\n function f(l, r) {\n var i = l + Math.ceil((r - l) / 2);\n if(l >= r) {\n return l;\n }\n var con = (i * a + b * (n - i) < k );\n if(con && ((i + 1) * a + b * (n - (i + 1)) >= k)) {\n return i;\n }\n if(con) {\n return f(i + 1, r);\n }\n else {\n return f(l ,i - 1);\n }\n }\n\n res += Math.min(n, f(0, n)) + '\\n';\n }\n }\n print(res);\n\n}());\n"}, {"source_code": "var numberOfRounds = parseInt(readline());\n\nfor (var i = 0; i < numberOfRounds; i++) {\n var parameters = readline().split(\" \");\n var k = parseInt(parameters[0]);\n var n = parseInt(parameters[1]);\n var a = parseInt(parameters[2]);\n var b = parseInt(parameters[3]);\n\n if (k - a * n > 0) {\n print(n);\n continue;\n }\n\n var maxRoundsWithoutCharge = Math.floor((k - 1) / a);\n if (maxRoundsWithoutCharge === n) {\n print(maxRoundsWithoutCharge);\n continue;\n }\n\n print(findSolution(0, maxRoundsWithoutCharge))\n}\n\nfunction findSolution(from, to) {\n var delta = Math.ceil((to - from) / 2)\n var currentMiddle = from + delta;\n\n var middle = canFinishOnCharge(k - currentMiddle * a, n - currentMiddle, b);\n var right = canFinishOnCharge(k - (currentMiddle + 1) * a, n - (currentMiddle + 1), b);\n\n if (middle && !right) {\n return currentMiddle;\n }\n \n if (!currentMiddle) {\n return -1;\n }\n\n if (currentMiddle === to) {\n return findSolution(from, from)\n }\n\n if (currentMiddle === from) {\n return findSolution(top, top);\n }\n\n if (!middle) {\n return findSolution(from, currentMiddle)\n }\n\n return findSolution(currentMiddle, to);\n}\n\nfunction canFinishOnCharge(kMod, nLeft, b) {\n return kMod - nLeft * b < 1\n ? 0\n : 1;\n}"}, {"source_code": "var numberOfRounds = parseInt(readline());\n\nfor (var i = 0; i < numberOfRounds; i++) {\n var parameters = readline().split(\" \");\n var k = parseInt(parameters[0]);\n var n = parseInt(parameters[1]);\n var a = parseInt(parameters[2]);\n var b = parseInt(parameters[3]);\n\n if (k - a * n > 0) {\n print(n);\n continue;\n }\n\n var maxRoundsWithoutCharge = Math.floor((k - 1) / a);\n if (maxRoundsWithoutCharge === n) {\n print(maxRoundsWithoutCharge);\n continue;\n }\n\n print(bin_search(k, n, a, b))\n}\n\nfunction bin_search(k, n, a, b) {\n var left = -1\n var right = k\n while (right - left > 1) {\n var mid = Math.ceil((right + left) / 2);\n if (condition(k, n, a, b, mid)) {\n left = mid;\n } else {\n right = mid;\n }\n }\n\n return left;\n}\n\nfunction condition(k, n, a, b, roundsWithoutCharge) {\n return canFinishOnCharge(k - roundsWithoutCharge * a, n - roundsWithoutCharge, b);\n}\n\nfunction canFinishOnCharge(kMod, nLeft, b) {\n return kMod - nLeft * b < 1\n ? 0\n : 1;\n}"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n var q = read.number();\n var res = '';\n while (q) {\n q--;\n\n var line = read.arrNumber(' ');\n var k = line[0];\n var n = line[1];\n var a = line[2];\n var b = line[3];\n\n if (k <= b * n) {\n res += '-1\\n';\n }\n else {\n function f(l, r) {\n var i = l + Math.ceil((r - l) / 2);\n if(l >= r) {\n return r;\n }\n var con = (i * a + b * (n - i) < k );\n if(con && ((i + 1) * a + b * (n - (i + 1)) >= k)) {\n return i;\n }\n if(con) {\n return f(l + i,r);\n }\n else {\n return f(l ,r - i);\n }\n }\n\n res += f(0, n) + '\\n';\n }\n }\n print(res);\n\n}());\n"}, {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\twrite(prob[0] - prob[3] * prob[1] <= 0 ? '-1\\n' : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\\n');\n}"}, {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\twrite(prob[0] - prob[3] * prob[1] <= 0 ? '-1\\n' : Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3])) + '\\n');\n}\n"}, {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\twrite(prob[0] - prob[3] * prob[1] <= 0 \n\t? '-1\\n' \n\t: prob[0] === prob[1] * prob[2] \n\t ? (prob[1] - 1) + '\\n' \n\t : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\\n');\n}"}, {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\twrite(prob[0] - prob[3] * prob[1] <= 0 \n\t? '-1\\n' \n\t: prob[0] == prob[1] * prob[2] \n\t ? (prob[1] - 1) + '\\n' \n\t : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\\n');\n}"}, {"source_code": "var q = parseInt(readline());\n//\twrite(countDays);\nfor (var i = 0; i < q; i++) {\n\tvar prob = readline().split(' ');\n\tif (prob[0] - prob[3] * prob[1] <= 0) {\n\t\twrite ('-1\\n');\n\t\tcontinue;\n\t}\n\tif (prob[0] == prob[1] * prob[2]) {\n\t\twrite ((prob[1] - 1) + '\\n');\n\t\tcontinue;\n\t}\n\tvar hehe = (prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]);\n\tif (hehe == Math.floor(hehe)) {\n\t\twrite(hehe - 1 + '\\n');\n\t} else {\n\t\twrite(Math.floor(hehe) + '\\n');\n\t}\n}"}, {"source_code": "var numberOfRounds = parseInt(readline());\n\nfor (var i = 0; i < numberOfRounds; i++) {\n var parameters = readline().split(\" \");\n var k = parseInt(parameters[0]);\n var n = parseInt(parameters[1]);\n var a = parseInt(parameters[2]);\n var b = parseInt(parameters[3]);\n\n if (k - a * n > 0) {\n print(n);\n continue;\n }\n\n var solutionFound = false;\n var roundsWithoutCharge = Math.floor(k / a);\n\n while (!solutionFound) {\n if (canFinishOnCharge(k - roundsWithoutCharge * a, n - roundsWithoutCharge, b)) {\n solutionFound = true;\n print(roundsWithoutCharge);\n }\n\n roundsWithoutCharge--;\n }\n\n if (!solutionFound) {\n print(-1);\n }\n}\n\nfunction canFinishOnCharge(kMod, nLeft, b) {\n return kMod - nLeft * b < 1\n ? 0\n : 1;\n}"}], "src_uid": "2005224ffffb90411db3678ac4996f84"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p && nums[j] > p) {\r\n if (nums[i] > nums[j]) {\r\n if (r[i] - i + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i, j - 1, nums[j]]);\r\n } else if (nums[i] < nums[j]) {\r\n if (j - l[j] + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i + 1, j, nums[i]]);\r\n } else {\r\n res.push([i, j - 1, nums[j]]);\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n } else if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n } else if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n if (a) res = false;\r\n } else if (a && b) res = false;\r\n if (!cache[i][j][p]) cache[i][j][p] = res;\r\n return !!cache[i][j][p];\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n a=rows[1].split(\" \").map(x=>+x);\r\n \r\n var L=0,R=a.length-1;\r\n var e=winner(-1,L,R,0);\r\n console.log([\"Alice\",\"Bob\"][e]);\r\n})\r\n \r\nvar a;\r\n \r\nfunction winner(min,L,R,player){\r\n while (1){\r\n if (R==L) return (a[L]>min?player:1-player);\r\n if (a[L]>min){\r\n if (a[R]>min){\r\n if (R==L+1) return player;\r\n if (R==L+2) return ((a[L+1]<=a[L])||(a[L+1]<=a[R])?player:1-player);\r\n if ((a[L+1]<=a[L])&&(a[R]<=a[L])) return player;\r\n if ((a[R-1]<=a[R])&&(a[L]<=a[R])) return player;\r\n if (a[L]>a[R]){\r\n if (winner(a[L],L+1,R,1-player)==player) return player;\r\n min=a[R--];player=1-player;\r\n } else {\r\n if (winner(a[R],L,R-1,1-player)==player) return player;\r\n min=a[L++];player=1-player;\r\n }\r\n } else { // forzato L\r\n var i=L+1;\r\n while (a[i]>a[i-1]) i++;\r\n return ((i-L)%2)?player:1-player;\r\n }\r\n } else {\r\n if (a[R]>min){ // forzato R\r\n var i=R-1;\r\n while (a[i]>a[i+1]) i--;\r\n return ((R-i)%2)?player:1-player;\r\n } else return 1-player;\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const h = new Map(),\r\n e = [],\r\n ne = [],\r\n d = new Map(),\r\n dp = new Map();\r\n const add = (i, j) => {\r\n if (!h.has(i)) {\r\n h.set(i, -1);\r\n d.set(i, 0);\r\n dp.set(i, 0);\r\n }\r\n if (!h.has(j)) {\r\n h.set(j, -1);\r\n d.set(j, 0);\r\n dp.set(j, 0);\r\n }\r\n e.push(j);\r\n ne.push(h.get(i));\r\n d.set(j, d.get(j) + 1);\r\n h.set(i, ne.length - 1);\r\n };\r\n const queue = [[n - 1, -1]];\r\n for (let [u, pre] of queue) {\r\n const i = Math.floor(u / n),\r\n j = u % n;\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j] || nums[j] >= nums[i] && nums[j] >= nums[j - 1] || i === j) {\r\n dp.set(u, 1);\r\n } else {\r\n if (nums[i] > pre && nums[j] > pre) {\r\n if (nums[i] < nums[j]) {\r\n const v = (i + 1) * n + j;\r\n add(v, u);\r\n queue.push([v, nums[i]]);\r\n if (j - l[j] + 1 & 1) dp.set(u, 1);\r\n } else if (nums[i] > nums[j]) {\r\n const v = i * n + j - 1;\r\n add(v, u);\r\n queue.push([v, nums[j]]);\r\n if (r[i] - i + 1 & 1) dp.set(u, 1);\r\n } else {\r\n let v = (i + 1) * n + j;\r\n add(v, u);\r\n queue.push([v, nums[i]]);\r\n v = i * n + j - 1;\r\n add(v, u);\r\n queue.push([v, nums[j]]);\r\n }\r\n } else if (nums[i] > pre) {\r\n const v = (i + 1) * n + j;\r\n add(v, u);\r\n queue.push([v, nums[i]]);\r\n } else if (nums[j] > pre) {\r\n const v = i * n + j - 1;\r\n add(v, u);\r\n queue.push([v, nums[j]]);\r\n }\r\n }\r\n }\r\n {\r\n const q = [];\r\n for (let [i, cnt] of d) {\r\n if (!cnt) q.push(i);\r\n }\r\n for (let u of q) {\r\n for (let i = h.get(u); ~i; i = ne[i]) {\r\n const v = e[i];\r\n dp.set(v, dp.get(v) | dp.get(u) ^ 1);\r\n if (d.get(v) === 1) {\r\n q.push(v);\r\n }\r\n d.set(v, d.get(v) - 1);\r\n }\r\n }\r\n if (dp.get(n - 1)) return 'Alice';\r\n return 'Bob';\r\n }\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "negative_code": [{"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n a=rows[1].split(\" \").map(x=>+x);\r\n \r\n var L=0,R=a.length-1;\r\n var e=winner(-1,L,R,0);\r\n console.log([\"Alice\",\"Bob\"][e]);\r\n})\r\n \r\nvar a;\r\n \r\nfunction winner(min,L,R,player){\r\n while (1){\r\n if (R==L) return (a[L]>min?player:1-player);\r\n if (a[L]>min){\r\n if (a[R]>min){\r\n if (R==L+1) return player;\r\n if (R==L+2) return ((a[L+1]<=a[L])||(a[L+1]<=a[R])?player:1-player);\r\n if ((a[L+1]<=a[L])&&(a[R]<=a[L])) return player;\r\n if ((a[R-1]<=a[R])&&(a[L]<=a[R])) return player;\r\n if (a[L]>a[R]){\r\n if (winner(a[L],L+1,R,1-player)==player) return player;\r\n min=a[R--];player=1-player;\r\n } else {\r\n if (winner(a[R],L,R-1,1-player)==player) return player;\r\n min=a[L++];player=1-player;\r\n }\r\n } else { // forzato L\r\n var i=L+1;\r\n while (a[i]>a[L]) i++;\r\n return (i-L)%2?player:1-player;\r\n }\r\n } else {\r\n if (a[R]>min){ // forzato R\r\n var i=R-1;\r\n while (a[i]>a[R]) i--;\r\n return (R-i)%2?player:1-player;\r\n } else return 1-player;\r\n }\r\n }\r\n}"}, {"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n var a=rows[1].split(\" \").map(x=>1*x);\r\n \r\n var lastSeq=-1;\r\n var L=0,R=a.length-1;\r\n var turn=0; //0=alice 1=bob turn\r\n while (R-L>=0){\r\n //console.log(\"choices:\"+a[L]+\",\"+a[R])\r\n if (a[L]>lastSeq){\r\n if (a[R]>lastSeq){ // scelta\r\n lastSeq=a[L++];\r\n } else lastSeq=a[L++]; //forzata\r\n } else {\r\n if (a[R]>lastSeq) lastSeq=a[R--]; // forzata\r\n else break; // nessuna possibilit\u00e0\r\n }\r\n //console.log(turn+\" plays \"+lastSeq)\r\n turn=1-turn;\r\n }\r\n console.log([\"Alice\",\"Bob\"][1-turn]);\r\n})"}, {"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n var a=rows[1].split(\" \").map(x=>1*x);\r\n \r\n var lastSeq=-1;\r\n var L=0,R=a.length-1;\r\n var turn=0; //0=alice 1=bob turn\r\n while (R-L>=0){\r\n //console.log(\"choices:\"+a[L]+\",\"+a[R])\r\n if (a[L]>lastSeq){\r\n lastSeq=a[L++]\r\n } else if (a[R]>lastSeq){\r\n lastSeq=a[R--]\r\n } else break;\r\n //console.log(turn+\" plays \"+lastSeq)\r\n turn=1-turn;\r\n }\r\n console.log([\"Alice\",\"Bob\"][1-turn]);\r\n})"}, {"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n var a=rows[1].split(\" \").map(x=>1*x);\r\n \r\n var lastSeq=-1;\r\n var L=0,R=a.length-1;\r\n var turn=0; //0=alice 1=bob turn\r\n while (R-L>=0){\r\n console.log(\"choices:\"+a[L]+\",\"+a[R])\r\n if (a[L]>lastSeq){\r\n lastSeq=a[L++]\r\n } else if (a[R]>lastSeq){\r\n lastSeq=a[R--]\r\n } else break;\r\n console.log(turn+\" plays \"+lastSeq)\r\n turn=1-turn;\r\n }\r\n console.log([\"Alice\",\"Bob\"][1-turn]);\r\n})"}, {"source_code": "let s = []\r\nprocess.stdin.on('data', l => s+=l)\r\nprocess.stdin.on('end', () => {\r\n var rows=s.split(\"\\n\")\r\n var n=1*rows[0];\r\n var a=rows[1].split(\" \");\r\n \r\n var lastSeq=-1;\r\n var L=0,R=a.length-1;\r\n var turn=0; //0=alice 1=bob turn\r\n while (R-L>0){\r\n if (a[L]>lastSeq){\r\n lastSeq=a[L++]\r\n } else if (a[R]>lastSeq){\r\n lastSeq=a[R--]\r\n } else break;\r\n turn=1-turn;\r\n }\r\n console.log([\"Alice\",\"Bob\"][1-turn]);\r\n})"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p && nums[j] > p) {\r\n if (nums[i] > nums[j]) {\r\n if (r[i] - i + 1 & 1) {\r\n cache[i][j][p] = true;\r\n }\r\n res.push([i, j - 1, nums[j]]);\r\n } else if (nums[i] < nums[j]) {\r\n if (i - l[i] + 1 & 1) {\r\n cache[i][j][p] = true;\r\n }\r\n res.push([i + 1, j, nums[i]]);\r\n } else {\r\n res.push([i, j - 1, nums[j]]);\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n } else if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n } else if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n if (a) res = false;\r\n } else if (a && b) res = false;\r\n if (!cache[i][j][p]) cache[i][j][p] = res;\r\n return !!cache[i][j][p];\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p && nums[j] > p) {\r\n if (nums[i] > nums[j]) {\r\n if (r[i] - i + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i, j - 1, nums[j]]);\r\n } else if (nums[i] < nums[j]) {\r\n if (i - l[i] + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i + 1, j, nums[i]]);\r\n } else {\r\n res.push([i, j - 1, nums[j]]);\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n } else if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n } else if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n if (a) res = false;\r\n } else if (a && b) res = false;\r\n if (!cache[i][j][p]) cache[i][j][p] = res;\r\n return !!cache[i][j][p];\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p && nums[j] > p) {\r\n if (nums[i] > nums[j]) {\r\n if (r[i] - i + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i, j - 1, nums[j]]);\r\n } else if (nums[i] < nums[j]) {\r\n if (i - l[i] + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i + 1, j, nums[i]]);\r\n } else {\r\n res.push([i, j - 1, nums[j]]);\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n } else if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n } else if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n if (a) res = false;\r\n } else if (a && b) res = false;\r\n if (!cache[i][j][p]) cache[i][j][p] = res;\r\n return cache[i][j][p];\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p && nums[j] > p) {\r\n if (nums[i] > nums[j]) {\r\n if (r[i] - i + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i, j - 1, nums[j]]);\r\n } else if (nums[i] < nums[j]) {\r\n if (i - l[i] + 1 & 1) {\r\n cache[i][j][p] = true;\r\n return [];\r\n }\r\n res.push([i + 1, j, nums[i]]);\r\n } else {\r\n res.push([i, j - 1, nums[j]]);\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n } else if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n } else if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n if (a) res = false;\r\n } else if (a && b) res = false;\r\n if (!cache[i][j][p]) cache[i][j][p] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j) return [() => [], () => false];\r\n if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];\r\n if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n res = !a;\r\n }\r\n res = !a && !b;\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n cache[i][j][p] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const l = new Array(n).fill(-1),\r\n r = new Array(n).fill(n);\r\n {\r\n let pre = -1;\r\n for (let i = 0; i < n; i++) {\r\n var _nums;\r\n if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;\r\n l[i] = pre;\r\n }\r\n pre = n;\r\n for (let i = n - 1; i >= 0; i--) {\r\n var _nums2;\r\n if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;\r\n r[i] = pre;\r\n }\r\n }\r\n const cache = Array.from({\r\n length: n\r\n }, () => ({}));\r\n const dfs = RTI((i, j, p) => {\r\n var _cache$i$j2;\r\n if (i > j || nums[i] <= p && nums[j] <= p) return [() => [], () => false];\r\n if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];\r\n const inside = () => {\r\n let res = [];\r\n if (nums[i] > p) {\r\n res.push([i + 1, j, nums[i]]);\r\n }\r\n if (nums[j] > p) {\r\n res.push([i, j - 1, nums[j]]);\r\n }\r\n return res;\r\n };\r\n const after = (args, childResult) => {\r\n const [a, b] = childResult;\r\n let res = true;\r\n if (b === undefined) {\r\n res = !a;\r\n }\r\n res = !a && !b;\r\n if (cache[i][j] === undefined) cache[i][j] = {};\r\n cache[i][j][p] = res;\r\n return res;\r\n };\r\n return [inside, after];\r\n });\r\n if (dfs(0, n - 1, -1)) return 'Alice';\r\n return 'Bob';\r\n}\r\nfunction RTI(fn) {\r\n let res;\r\n const createNode = args => {\r\n return {\r\n args,\r\n result: [],\r\n curIndex: 0\r\n };\r\n };\r\n const dfs = (...args) => {\r\n const root = createNode([args]);\r\n root.cb = ([args], [result]) => res = result;\r\n const callStack = [root];\r\n while (callStack.length) {\r\n let curCall = callStack[callStack.length - 1];\r\n while (curCall && curCall.args.length === curCall.curIndex) {\r\n var _curCall$cb, _curCall;\r\n const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);\r\n callStack.pop();\r\n curCall = callStack[callStack.length - 1];\r\n if (curCall) curCall.result[curCall.curIndex++] = res;\r\n }\r\n if (!curCall) break;\r\n const {\r\n args,\r\n curIndex\r\n } = curCall;\r\n {\r\n const res = fn(...args[curIndex]);\r\n const [inside, after] = res;\r\n let nextCall = inside();\r\n const node = createNode(nextCall);\r\n node.cb = after;\r\n callStack.push(node);\r\n }\r\n }\r\n return res;\r\n };\r\n return dfs;\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n const n = rn(),\r\n nums = new Array(n);\r\n for (let i = 0; i < n; i++) nums[i] = rn();\r\n const h = new Map(),\r\n e = [],\r\n ne = [],\r\n d = new Map();\r\n const add = (i, j) => {\r\n if (!h.has(i)) {\r\n h.set(i, -1);\r\n d.set(i, 0);\r\n }\r\n if (!h.has(j)) {\r\n h.set(j, -1);\r\n d.set(j, 0);\r\n }\r\n e.push(j);\r\n ne.push(h.get(i));\r\n d.set(j, d.get(j) + 1);\r\n h.set(i, ne.length - 1);\r\n };\r\n const queue = [[n - 1, -1]],\r\n dp = new Map();\r\n for (let [u, pre] of queue) {\r\n const i = Math.floor(u / n),\r\n j = u % n;\r\n if (nums[i] >= nums[i + 1] && nums[i] >= nums[j] || nums[j] >= nums[i] && nums[j] >= nums[j - 1] || i === j) {\r\n dp.set(u, 1);\r\n } else {\r\n if (nums[i] > pre) {\r\n const v = (i + 1) * n + j;\r\n add(v, u);\r\n queue.push([v, nums[i]]);\r\n }\r\n if (nums[j] > pre) {\r\n const v = i * n + j - 1;\r\n add(v, u);\r\n queue.push([v, nums[j]]);\r\n }\r\n }\r\n }\r\n {\r\n const q = [];\r\n for (let [i, cnt] of d) {\r\n if (!cnt) q.push(i);\r\n }\r\n for (let u of q) {\r\n for (let i = h.get(u); ~i; i = ne[i]) {\r\n const v = e[i];\r\n if (dp.has(v)) {\r\n dp.set(v, dp.get(v) | ~dp.get(u));\r\n } else {\r\n dp.set(v, dp.get(u) ^ 1);\r\n }\r\n if (d.get(v) === 1) {\r\n q.push(v);\r\n }\r\n d.set(v, d.get(v) - 1);\r\n }\r\n }\r\n if (dp.get(n - 1)) return 'Alice';\r\n return 'Bob';\r\n }\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = 1;\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n }\r\n }\r\n if (t >= 100) ; else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "c01e33f3d0c31f1715d8ff118970f42e"} {"source_code": "var g = readline();\nvar strs = [];\nfor(var i =0;i 0) {\n var v = q.pop();\n res.push(v);\n for(var i = 0; i < n; i += 1) {\n if(g[v][i] === 1) {\n g[v][i] = 0;\n d[i] -= 1;\n if(d[i] === 0) {\n q.push(i);\n }\n }\n }\n }\n var flag = true;\n for(var i = 0; i < n && flag; i += 1) {\n for(var j = 0; j < n && flag; j += 1) {\n if(g[i][j] === 1) {\n flag = false;\n }\n }\n }\n\n for(var i = 0; i < n && flag; i += 1) {\n for(var j = i; j < n && flag; j += 1) {\n if(!s[res[i]].includes(s[res[j]])) {\n flag = false;\n }\n }\n }\n \n if(flag) {\n print('YES');\n print(res.reverse().map(function(x) { return s[x]; }).join('\\n'));\n } else {\n print('NO');\n }\n "}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString='';\nlet currentLine=0;\nprocess.stdin.on('data',inputStdin=>{\n inputString+=inputStdin;\n});\nprocess.stdin.on('end',_=>{\n inputString=inputString.trim().split(\"\\n\").map(string=>{\n return string.trim();\n });\n main();\n});\nfunction readLine()\n{\n return inputString[currentLine++]; \n}\nfunction main()\n{\n const N=parseInt(readLine());\n let s=[];\n for(let i=0;ia.length-b.length);\n let prev=s[0];\n for(let i=1;i {\n const lines = [];\n\n require(\"readline\")\n .createInterface({\n input: process.stdin,\n output: process.stdout\n })\n .on(\"line\", line => {\n if (lines.length > 0 && typeof lines[0] === \"function\") {\n lines.shift()(line);\n } else {\n lines.push(line);\n }\n });\n\n return async () => {\n if (lines.length > 0 && typeof lines[0] === \"string\") {\n return lines.shift();\n }\n return new Promise(resolve => lines.push(resolve));\n };\n})();\n\nconst get_nums = async () => (await gets()).split(\" \").map(x => Number(x));\n\nfunction build(a) {\n const n = a.length;\n const s = new Array(n + 1);\n s.fill(0);\n let c = 0;\n for (let i = 0; i < n; i++) {\n if (a[i] === 0) {\n c = 0;\n } else {\n c++;\n s[c]++;\n }\n }\n for (let i = n - 1; i >= 0; i--) {\n s[i] += s[i + 1];\n }\n return s;\n}\n\nasync function main() {\n const [n, m, k] = await get_nums();\n const a = await get_nums();\n const b = await get_nums();\n const sa = build(a);\n const sb = build(b);\n const calc = (w, h) => w <= n && h <= m ? sa[w] * sb[h] : 0;\n\n let ans = 0;\n for (let i = 1; i * i <= k; i++) {\n if (k % i !== 0) {\n continue;\n }\n ans += calc(i, k / i);\n if (i !== k / i) {\n ans += calc(k / i, i);\n }\n }\n console.log(ans);\n}\n\nmain();\n", "positive_code": [{"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n\n var x = ip[0]\n var y = ip[1]\n var pp = ip[2]\n\n var s = readline().split(' ').map(x => parseInt(x))\n var z = readline().split(' ').map(x => parseInt(x))\n\n var precZ = {}\n var ct = 0\n for (n = 0; n < y; n++) {\n if (z[n]) ct++;\n else {\n if (precZ[ct] == null) precZ[ct] = 1;\n else precZ[ct] += 1;\n ct = 0;\n }\n }\n if (ct) {\n if (precZ[ct] == null) precZ[ct] = 1;\n else precZ[ct] += 1;\n }\n\n ct = 0\n var segsZ = JSON.parse(JSON.stringify(precZ))\n var propz = []\n for (var n in precZ) {\n propz.push([n * 1, precZ[n]])\n }\n propz.sort((a, b) => {\n return b[0] - a[0]\n })\n\n for (var n = 0; n < propz.length; n++) {\n for (var k = propz[n][0] - 1; k >= 1; k--) {\n segsZ[k] = segsZ[k] == null ? (propz[n][0] - k + 1) * propz[n][1] : segsZ[k] + (propz[n][0] - k + 1) * propz[n][1];\n }\n }\n\n var precS = {}\n ct = 0\n for (var n = 0; n < x; n++) {\n if (s[n]) ct++;\n else {\n if (precS[ct] == null) precS[ct] = 1;\n else precS[ct] += 1;\n ct = 0;\n }\n }\n if (ct) {\n if (precS[ct] == null) precS[ct] = 1;\n else precS[ct] += 1;\n }\n\n ct = 0\n var segsS = JSON.parse(JSON.stringify(precS))\n var props = []\n for (var n in precS) {\n props.push([n * 1, precS[n]])\n }\n props.sort((a, b) => {\n return b[0] - a[0]\n })\n\n for (var n = 0; n < props.length; n++) {\n for (var k = props[n][0] - 1; k >= 1; k--) {\n segsS[k] = segsS[k] == null ? (props[n][0] - k + 1) * props[n][1] : segsS[k] + (props[n][0] - k + 1) * props[n][1];\n }\n }\n\n\n var res = 0;\n\n for (var n = 1; n * n <= pp; n++) {\n if (pp % n == 0 && n * n != pp) {\n res += (segsS[n] == null ? 0 : segsS[n]) * (segsZ[pp / n] == null ? 0 : segsZ[pp / n])\n res += (segsZ[n] == null ? 0 : segsZ[n]) * (segsS[pp / n] == null ? 0 : segsS[pp / n])\n }\n else res += (segsS[n] == null ? 0 : segsS[n]) * (segsZ[pp / n] == null ? 0 : segsZ[pp / n])\n }\n\n print(res)\n}\n\nvar tc = 1;\n//tc = parseInt(readline());\nwhile (tc--) solv()"}, {"source_code": "function solv() {\n var ip = readline().split(' ').map(x => parseInt(x))\n\n var x = ip[0]\n var y = ip[1]\n var pp = ip[2]\n\n var s = readline().split(' ').map(x => parseInt(x))\n var z = readline().split(' ').map(x => parseInt(x))\n\n var precZ = {}\n var ct = 0\n for (n = 0; n < y; n++) {\n if (z[n]) ct++;\n else {\n if (precZ[ct] == null) precZ[ct] = 1;\n else precZ[ct] += 1;\n ct = 0;\n }\n }\n if (ct) {\n if (precZ[ct] == null) precZ[ct] = 1;\n else precZ[ct] += 1;\n }\n\n ct = 0\n var segsZ = JSON.parse(JSON.stringify(precZ))\n var propz = []\n for (var n in precZ) {\n propz.push([n * 1, precZ[n]])\n }\n propz.sort((a, b) => {\n return b[0] - a[0]\n })\n\n for (var n = 0; n < propz.length; n++) {\n for (var k = propz[n][0] - 1; k >= 1; k--) {\n segsZ[k] = segsZ[k] == null ? (propz[n][0] - k + 1) * propz[n][1] : segsZ[k] + (propz[n][0] - k + 1) * propz[n][1];\n }\n }\n\n var precS = {}\n ct = 0\n for (var n = 0; n < x; n++) {\n if (s[n]) ct++;\n else {\n if (precS[ct] == null) precS[ct] = 1;\n else precS[ct] += 1;\n ct = 0;\n }\n }\n if (ct) {\n if (precS[ct] == null) precS[ct] = 1;\n else precS[ct] += 1;\n }\n\n ct = 0\n var segsS = JSON.parse(JSON.stringify(precS))\n var props = []\n for (var n in precS) {\n props.push([n * 1, precS[n]])\n }\n props.sort((a, b) => {\n return b[0] - a[0]\n })\n\n for (var n = 0; n < props.length; n++) {\n for (var k = props[n][0] - 1; k >= 1; k--) {\n segsS[k] = segsS[k] == null ? (props[n][0] - k + 1) * props[n][1] : segsS[k] + (props[n][0] - k + 1) * props[n][1];\n }\n }\n\n\n var res = 0;\n\n for (var n = 1; n * n <= pp; n++) {\n if (pp % n == 0 && n * n != pp) {\n res += (segsS[n] == null ? 0 : segsS[n]) * (segsZ[pp / n] == null ? 0 : segsZ[pp / n])\n res += (segsZ[n] == null ? 0 : segsZ[n]) * (segsS[pp / n] == null ? 0 : segsS[pp / n])\n }\n else res += (segsS[n] == null ? 0 : segsS[n]) * (segsZ[pp / n] == null ? 0 : segsZ[pp / n])\n }\n\n print(res)\n}\n\nvar tc = 1;\n//tc = parseInt(readline());\nwhile (tc--) solv()"}, {"source_code": "const factors = (A) => {\n var output = [];\n\n for (var i=1; i <= Math.sqrt(A); i++) {\n if (A % i === 0) {\n output.push(i);\n\n if (i !== Math.sqrt(A)) output.push(A/i);\n }\n }\n\n if (output.indexOf(A) === -1) output.push(A);\n\n return output;\n}\n\nconst processData = (lines) => {\n const [n, m, k] = lines[0].split(' ').map(x => +x)\n const a = lines[1].split(' ').map(x => +x)\n const b = lines[2].split(' ').map(x => +x)\n\n const aNums = []\n let acc = 0\n for (const num of a) {\n if (num === 0) {\n if (acc > 0) {\n aNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n\n if (acc>0) {\n aNums.push(acc)\n }\n\n // console.log(a)\n // console.log(aNums)\n\n const bNums = []\n acc = 0\n for (const num of b) {\n if (num === 0) {\n if (acc > 0) {\n bNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n if (acc>0) {\n bNums.push(acc)\n }\n\n let sum = 0\n //\n // const aRed = aNums.sort((a, b) => a - b).reduce((r, x) => {\n // const last = r[r.length-1]\n // if (x === last[0]) {\n // last[1]++\n // } else {\n // r.push([x, 1])\n // }\n // return r\n // }, [[1, 0]])\n //\n // const bRed = bNums.sort((a, b) => a - b).reduce((r, x) => {\n // const last = r[r.length-1]\n // if (x === last[0]) {\n // last[1]++\n // } else {\n // r.push([x, 1])\n // }\n // return r\n // }, [[1, 0]])\n\n\n\n const f = factors(k).sort((a, b) => a-b)\n\n for (const t1 of f) {\n const t2 = k / t1\n const aWidth = aNums.reduce( (r, x) => r + (x >= t1 ? (x - t1 + 1 ) : 0), 0)\n const bWidth = bNums.reduce( (r, y) => r + (y >= t2 ? (y - t2 + 1 ) : 0), 0)\n sum += aWidth * bWidth\n }\n\n\n\n console.log(sum)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const factors = (A) => {\n var output = [];\n\n for (var i=1; i <= Math.sqrt(A); i++) {\n if (A % i === 0) {\n output.push(i);\n\n if (i !== Math.sqrt(A)) output.push(A/i);\n }\n }\n\n if (output.indexOf(A) === -1) output.push(A);\n\n return output;\n}\n\nconst processData = (lines) => {\n const [n, m, k] = lines[0].split(' ').map(x => +x)\n const a = lines[1].split(' ').map(x => +x)\n const b = lines[2].split(' ').map(x => +x)\n\n const aNums = []\n let acc = 0\n for (const num of a) {\n if (num === 0) {\n if (acc > 0) {\n aNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n\n if (acc>0) {\n aNums.push(acc)\n }\n\n // console.log(a)\n // console.log(aNums)\n\n const bNums = []\n acc = 0\n for (const num of b) {\n if (num === 0) {\n if (acc > 0) {\n bNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n if (acc>0) {\n bNums.push(acc)\n }\n\n let sum = 0\n\n const aRed = aNums.sort((a, b) => a - b).reduce((r, x) => {\n const last = r[r.length-1]\n if (x === last[0]) {\n last[1]++\n } else {\n r.push([x, 1])\n }\n return r\n }, [[1, 0]])\n\n const bRed = bNums.sort((a, b) => a - b).reduce((r, x) => {\n const last = r[r.length-1]\n if (x === last[0]) {\n last[1]++\n } else {\n r.push([x, 1])\n }\n return r\n }, [[1, 0]])\n\n\n\n const f = factors(k)\n\n\n for (const [x, xCount] of aRed) {\n for (const [y, yCount] of bRed) {\n const s = x*y\n // console.log([x, y])\n if (s >= k) {\n\n for (const t1 of f) {\n\n const t2 = k / t1\n // console.log(t1, t2)\n if (t1 <= x && t2 <= y) {\n // console.log(t1, t2)\n // console.log(x-t1+1, y-t2+1)\n sum += (x-t1+1) * (y-t2+1) * xCount * yCount\n }\n }\n }\n }\n }\n\n // console.log(hashMap)\n\n // for (const key in hashMap) {\n // const [x, y] = key.split('_').map(x => +x)\n // // console.log(k, x, y)\n // let localSum = 0\n\n // // console.log(localSum)\n // // console.log(hashMap[key])\n // sum = localSum * hashMap[key]\n // }\n\n console.log(sum)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const factors = (A) => {\n var output = [];\n\n for (var i=1; i <= Math.sqrt(A); i++) {\n if (A % i === 0) {\n output.push(i);\n\n if (i !== Math.sqrt(A)) output.push(A/i);\n }\n }\n\n if (output.indexOf(A) === -1) output.push(A);\n\n return output;\n}\n\nconst processData = (lines) => {\n const [n, m, k] = lines[0].split(' ').map(x => +x)\n const a = lines[1].split(' ').map(x => +x)\n const b = lines[2].split(' ').map(x => +x)\n\n const aNums = []\n let acc = 0\n for (const num of a) {\n if (num === 0) {\n if (acc > 0) {\n aNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n\n if (acc>0) {\n aNums.push(acc)\n }\n\n // console.log(a)\n // console.log(aNums)\n\n const bNums = []\n acc = 0\n for (const num of b) {\n if (num === 0) {\n if (acc > 0) {\n bNums.push(acc)\n acc = 0\n }\n } else {\n acc++\n }\n }\n if (acc>0) {\n bNums.push(acc)\n }\n\n let sum = 0\n\n const aRed = aNums.sort((a, b) => a - b).reduce((r, x) => {\n const last = r[r.length-1]\n if (x === last[0]) {\n last[1]++\n } else {\n r.push([x, 1])\n }\n return r\n }, [[1, 0]])\n\n const bRed = bNums.sort((a, b) => a - b).reduce((r, x) => {\n const last = r[r.length-1]\n if (x === last[0]) {\n last[1]++\n } else {\n r.push([x, 1])\n }\n return r\n }, [[1, 0]])\n\n\n\n const f = factors(k).sort((a, b) => a-b)\n\n for (const t1 of f) {\n const t2 = k / t1\n const aWidth = aRed.reduce( (r, [x, c]) => r + (x >= t1 ? (x - t1 + 1 ) * c : 0), 0)\n const bWidth = bRed.reduce( (r, [y, c]) => r + (y >= t2 ? (y - t2 + 1 ) * c : 0), 0)\n sum += aWidth * bWidth\n }\n\n\n\n console.log(sum)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n }\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\nconst getFactors = (n) => {\n const result = new Set();\n for (let i = 1; i <= parseInt(n ** (1/2)); i++) {\n if (n % i === 0) {\n result.add(i);\n result.add(n / i);\n }\n }\n // print(result)\n return Array.from(result);\n};\n\nconst getChunks = (arr) => {\n const result = {};\n let left = 0;\n arr.concat(0).forEach((x, i) => {\n if (x === 0) {\n result[i - left] = (result[i - left] || 0) + 1;\n left = i + 1;\n }\n })\n return result;\n};\n\nconst main = () => {\n const [n, m, k] = readline().split(' ').map(x => parseInt(x));\n const a = readline().split(' ').map(x => parseInt(x));\n const b = readline().split(' ').map(x => parseInt(x));\n \n const factors = getFactors(k);\n const solve = (n, m) => {\n let cnt = 0;\n for (let i = 0; i < factors.length; i++) {\n const a = factors[i];\n const b = k / factors[i];\n if (n >= a && m >= b) cnt += (n - a + 1) * (m - b + 1);\n }\n return cnt\n };\n\n const note = new Map();\n\n let cnt = 0;\n const a_chunks = getChunks(a);\n const b_chunks = getChunks(b);\n for (const x in a_chunks) {\n for (const y in b_chunks) {\n const key = [x, y].join(',');\n const cached = note.get(key);\n if (cached !== undefined) {\n cnt += cached * a_chunks[x] * b_chunks[y];\n } else {\n const calc = solve(x, y);\n cnt += calc * a_chunks[x] * b_chunks[y];\n note.set(key, calc);\n }\n }\n }\n // print(note)\n // print(factors);\n // print(a_chunks, b_chunks);\n print(cnt);\n};\n"}, {"source_code": "var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nvar __spread = (this && this.__spread) || function () {\n for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));\n return ar;\n};\nfunction main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (l) { return l.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var _a = __read(lines.shift(), 3), n = _a[0], m = _a[1], k = _a[2];\n var as = lines.shift();\n var bs = lines.shift();\n // let [n, m, k] = [40000, 40000, Math.ceil(Math.random() * 10) * 2];\n // const as = Array.from({ length: n }, (_, i) => i % 2);\n // const bs = Array.from({ length: n }, () => Math.round(Math.random()));\n var count = 0;\n var awhs = new Map();\n ;\n for (var i = 0; i < n; i++) {\n var w = 0;\n while (as[i] === 1 && i < n) {\n i++;\n w++;\n }\n if (w > 0) {\n if (!awhs.has(w)) {\n awhs.set(w, 1);\n }\n else {\n awhs.set(w, awhs.get(w) + 1);\n }\n }\n }\n var _loop_1 = function (j) {\n var h = 0;\n while (bs[j] === 1 && j < m) {\n h++;\n j++;\n }\n if (h > 0) {\n __spread(awhs.entries()).forEach(function (_a) {\n var _b = __read(_a, 2), w = _b[0], t = _b[1];\n // console.log(w, t);\n count += t * countsubRets(w, h, k);\n });\n }\n out_j_1 = j;\n };\n var out_j_1;\n for (var j = 0; j < m; j++) {\n _loop_1(j);\n j = out_j_1;\n }\n console.log(count);\n}\nvar dp = {};\nfunction countsubRets(w, h, k) {\n // if(w * h in dp) {\n // return dp[w * h];\n // }\n var cnt = 0;\n for (var pw = 1; pw <= w && pw <= k; pw++) {\n // console.log(pw, w, h, k);\n if (k % pw === 0) {\n var desiredH = k / pw;\n if (desiredH <= h) {\n var horz = w - pw + 1;\n var vert = h - desiredH + 1;\n cnt += horz * vert;\n }\n }\n }\n // console.log(cnt);\n // dp[w * h] = cnt;\n return cnt;\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const [n, m, k] = readInts(input)\n const a = readInts(input)\n const b = readInts(input)\n const aS = seg(a)\n const bS = seg(b)\n let ans = 0\n for(let i = 1, len = aS.length; i < len; i++) {\n if(k % i === 0 && k / i <= m) {\n ans += aS[i] * bS[k / i]\n }\n }\n wr(ans)\n}\n\nfunction seg(a) {\n let i = 0\n const n = a.length\n const map = new Array(n + 1).fill(0)\n while(i < n) {\n if(a[i] === 0) {\n i++\n continue\n }\n let j = i\n while(j < n && a[j] === 1) j++\n for(let k = j - i; k >= 1; k--) map[k] += j - i - k + 1\n i = j\n }\n return map\n}"}], "negative_code": [{"source_code": "const factors = (A) => {\n var output = [];\n\n for (var i=1; i <= Math.sqrt(A); i++) {\n if (A % i === 0) {\n output.push(i);\n\n if (i !== Math.sqrt(A)) output.push(A/i);\n }\n }\n\n if (output.indexOf(A) === -1) output.push(A);\n\n return output;\n}\n\nconst processData = (lines) => {\n const [n, m, k] = lines[0].split(' ').map(x => +x)\n const a = lines[1].split(' ').map(x => +x)\n const b = lines[2].split(' ').map(x => +x)\n\n const aNums = []\n let acc = 0\n for (const num of a) {\n if (num === 0 && acc > 0) {\n aNums.push(acc)\n acc = 0\n } else {\n acc++\n }\n }\n if (acc>0) {\n aNums.push(acc)\n }\n const bNums = []\n acc = 0\n for (const num of b) {\n if (num === 0 && acc > 0) {\n bNums.push(acc)\n acc = 0\n } else {\n acc++\n }\n }\n if (acc>0) {\n bNums.push(acc)\n }\n\n const sizeArr = []\n for (const num of aNums) {\n for (const bNum of bNums) {\n const s = num * bNum\n if (s >= k) {\n sizeArr.push([num, bNum])\n }\n }\n }\n let sum = 0\n const f = factors(k).sort((a, b) => a-b)\n\n for (const [x, y] of sizeArr) {\n // let t1 = 1\n // let t2 = f.reduce((r,x) => r*x, 1)\n for (let j = 0; j < f.length; j++) {\n\n const t1 = f[j]\n const t2 = k / f[j]\n // console.log(t1, t2)\n if (t1 <= x && t2 <= y) {\n // console.log(t1, t2)\n // console.log(x-t1+1, y-t2+1)\n sum += (x-t1+1) * (y-t2+1)\n }\n }\n }\n console.log(sum)\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nvar __spread = (this && this.__spread) || function () {\n for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));\n return ar;\n};\nfunction main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (l) { return l.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var _a = __read(lines.shift(), 3), n = _a[0], m = _a[1], k = _a[2];\n var as = lines.shift();\n var bs = lines.shift();\n // let [n, m, k] = [40000, 40000, 2];\n // const as = Array.from({ length: n }, (_, i) => i % 3);\n // const bs = Array.from({ length: n }, () => Math.round(Math.random()));\n var count = 0;\n var awhs = new Map();\n ;\n for (var i = 0; i < n; i++) {\n var w = 0;\n while (as[i] === 1 && i < n) {\n i++;\n w++;\n }\n if (w > 0) {\n if (!awhs.has(w)) {\n awhs.set(w, 1);\n }\n else {\n awhs.set(w, awhs.get(w) + 1);\n }\n }\n }\n var _loop_1 = function (j) {\n var h = 0;\n while (bs[j] === 1 && j < m) {\n h++;\n j++;\n }\n if (h > 0) {\n __spread(awhs.entries()).forEach(function (_a) {\n var _b = __read(_a, 2), w = _b[0], t = _b[1];\n // console.log(w, t);\n count += t * countsubRets(w, h, k);\n });\n }\n out_j_1 = j;\n };\n var out_j_1;\n for (var j = 0; j < m; j++) {\n _loop_1(j);\n j = out_j_1;\n }\n console.log(count);\n}\nvar dp = {};\nfunction countsubRets(w, h, k) {\n if (w * h in dp) {\n return dp[w * h];\n }\n var cnt = 0;\n for (var pw = 1; pw <= w && pw <= k; pw++) {\n // console.log(pw, w, h, k);\n if (k % pw === 0) {\n var desiredH = k / pw;\n if (desiredH <= h) {\n var horz = w - pw + 1;\n var vert = h - desiredH + 1;\n cnt += horz * vert;\n }\n }\n }\n // console.log(cnt);\n dp[w * h] = cnt;\n return cnt;\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}], "src_uid": "46c3222580a31f5a04ea276b6946aeaa"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c % 2 === 1) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const obj = {};\n const uniqArr = [...new Set(arr)];\n\n for (let i = 0; i < uniqArr.length; i++) {\n for (let j = 0; j < arr.length; j++) {\n if (uniqArr[i] <= arr[j]) {\n if (!obj[uniqArr[i]]) {\n obj[uniqArr[i]] = 1;\n }\n else {\n obj[uniqArr[i]]++;\n }\n }\n }\n }\n\n let ans = 0;\n\n for (x in obj) {\n const target = Math.min(x, obj[x]);\n ans = Math.max(target, ans);\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => { \n solveWrap(inputString); \n});\n\nfunction solve(arr){\n\tarr.sort((a,b) => b-a);\n\tlet min = 0;\n\tfor (const el of arr) {\n\t\tmin++;\n\t\tif(el +el)));\n\t}\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n');\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr('time : ' + end + 'ms');\n myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n list.sort(function(a,b){\n \treturn b - a;\n });\n var max = 0;\n for(var j = 0; j < N; j++){\n if(j + 1 <= list[j]){\n max = j + 1;\n }else{\n break;\n }\n output[i] = max;\n }\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "'use strict'\n\nconst problem = (n, a) => {\n a = a.sort((x, y) => y - x);\n for (let i = 0; i < a.length; i++) {\n if (a[i] <= i) return i;\n }\n return a.length;\n}\nlet q = +readline();\nwhile(q--) print(problem(+readline(), readline().split(' ').map(Number)))\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet t = nl.num();\n let ans = [];\n for(let i = 0; i < t; i++){\n let n = nl.num();\n let a = nl.nums();\n a.sort((x, y) => y - x);\n let flag = true;\n for(let j = 0; j < n; j++){\n if (a[j] <= j) {\n ans.push(j);\n flag = false;\n break;\n }\n }\n if (flag) {\n ans.push(n);\n }\n }\n\tconsole.log(ans.join('\\n'));\n\n};\n\nprocess.stdin.on('end', sol);\n"}], "negative_code": [], "src_uid": "09236a3faa7fce573a4e5e758287040f"} {"source_code": "var n = Number(readline());\nconst map = {\n purple: \"Power\",\n green: \"Time\",\n blue: \"Space\",\n orange: \"Soul\",\n red: \"Reality\",\n yellow: \"Mind\"\n};\nconst colors = new Set(Object.keys(map));\nwhile (n--)\n colors.delete(readline().trim());\nprint(colors.size);\nfor (var color of colors)\n print(map[color]);\n", "positive_code": [{"source_code": "function answer(input){\n var stones = {\n purple: 'Power',\n green: 'Time',\n blue: 'Space',\n orange: 'Soul',\n red: 'Reality',\n yellow: 'Mind'\n };\n\n var numStones = readline();\n var inputStones = [];\n var outputStones = [];\n\n for(var i = 0; i < numStones; i++){\n inputStones.push(readline());\n }\n\n inputStones.forEach(function(stoneColor){\n delete stones[stoneColor];\n });\n\n for(var stoneColor in stones){\n outputStones.push(stones[stoneColor]);\n }\n print(outputStones.length);\n outputStones.forEach(function(stone){\n print(stone);\n });\n}\n\nanswer();\n"}, {"source_code": "var n = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar s = \"\"\nvar obj = {}\nfor(var i = 0; i < n; i++){\n s = readline()\n switch(s){\n case \"purple\":\n obj.Power = 1\n break\n case \"green\":\n obj.Time = 1\n break\n case \"blue\":\n obj.Space = 1\n break\n case \"orange\":\n obj.Soul = 1\n break\n case \"red\":\n obj.Reality = 1\n break\n case \"yellow\":\n obj.Mind = 1\n break\n }\n}\nvar ans = 0\nvar ansarr = []\nif(!obj.hasOwnProperty(\"Power\")){\n ans += 1\n ansarr.push(\"Power\")\n}\nif(!obj.hasOwnProperty(\"Time\")){\n ans += 1\n ansarr.push(\"Time\")\n}\nif(!obj.hasOwnProperty(\"Space\")){\n ans += 1\n ansarr.push(\"Space\")\n}\nif(!obj.hasOwnProperty(\"Soul\")){\n ans += 1\n ansarr.push(\"Soul\")\n}\nif(!obj.hasOwnProperty(\"Reality\")){\n ans += 1\n ansarr.push(\"Reality\")\n}\nif(!obj.hasOwnProperty(\"Mind\")){\n ans += 1\n ansarr.push(\"Mind\")\n}\nprint(ans)\nfor(var j = 0; j < ansarr.length; j++){\n print(ansarr[j])\n}\n // the Power Gem of purple color,\n // the Time Gem of green color,\n // the Space Gem of blue color,\n // the Soul Gem of orange color,\n // the Reality Gem of red color,\n // the Mind Gem of yellow color. \n\n// 2\n// Time\n// Space"}, {"source_code": "var col2gem = {\n purple: \"Power\",\n green: \"Time\",\n blue: \"Space\",\n orange: \"Soul\",\n red: \"Reality\",\n yellow: \"Mind\",\n};\n\nvar n = readline();\n\nvar seen = new Set();\n\nfor (var i = 0; i < n; i++) {\n seen.add(readline());\n}\n\nprint(6 - n);\n\nfor (var col in col2gem) {\n if (!seen.has(col)) {\n print(col2gem[col]);\n }\n}"}, {"source_code": "// //The colors of the six gems\nvar gems = [\n { name: 'Power', color: 'purple' },\n { name: 'Time', color: 'green' },\n { name: 'Space', color: 'blue' },\n { name: 'Soul', color: 'orange' },\n { name: 'Reality', color: 'red' },\n { name: 'Mind', color: 'yellow' }\n]\n//the number of Gems in Infinity Gauntlet.\nvar n = readline();\n// var n = prompt();\nvar colors = [];\nif ((n > 0 || n == 0) && (n < 6 || n == 6)) {\n for (i = 0; i < n; i++) {\n colors.push(readline()) \n // colors.push(prompt())\n } \n}\nvar absent=gems.filter(function(gem){\n return (colors.indexOf(gem.color) == -1);\n})\nvar m=absent.length\nprint(m)\n// console.log(m)\n// console.log(colors)\nprint(...absent.map(absent=>absent.name))\n// console.log(...absent.map(absent=>absent.name))\n"}, {"source_code": "var names = [\"purple\",\"green\",\"blue\",\"orange\",\"red\",\"yellow\"];\nvar powers = [\"Power\",\"Time\",\"Space\",\"Soul\",\"Reality\",\"Mind\"];\n\nvar number = +readline();\nwhile(number > 0) {\n powers[names.indexOf(readline())] = 0;\n number --;\n}\n\nvar results = powers.filter(power => power);\nwrite(results.length + '\\n');\nresults.forEach(result => write(result + '\\n'))"}, {"source_code": "\n var n = parseInt(readline());\n var m = [];\n m['purple'] = 'Power';\n m['green'] = 'Time';\n m['blue'] = 'Space';\n m['orange'] = 'Soul';\n m['red'] = 'Reality';\n m['yellow'] = 'Mind';\n for(var i = 0; i < n; i += 1) {\n var tmp = readline();\n m[tmp] = '';\n }\n var res = '';\n var count = 0;\n for(var c in m) {\n if(m[c].length > 0) {\n res += m[c] + '\\n';\n count += 1;\n }\n }\n print(count);\n print(res);\n "}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar map = {\n\t\tpurple : \"Power\",\n\t\tgreen : \"Time\",\n\t\tblue : \"Space\",\n\t\torange : \"Soul\",\n\t\tred : \"Reality\",\n\t\tyellow : \"Mind\"\n\t};\n\tvar N = nextInt();\n\tfor(var i = 0; i < N; i++){\n\t\tmap[next()] = \"\";\n\t}\n\tvar keys = Object.keys(map);\n\tvar output = [];\n\tfor(var i = 0; i < keys.length; i++){\n\t\tif(map[keys[i]] != \"\"){\n\t\t\toutput.push(map[keys[i]]);\n\t\t}\n\t}\n\tmyout(output.length);\n\tmyout(myconv(output, 9));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nconst arr = [];\nconst obj = {\n purple: 'Power',\n green: 'Time',\n blue: 'Space',\n orange: 'Soul',\n red: 'Reality',\n yellow: 'Mind',\n};\n\nrl.on('line', (str) => {\n if (c === 0) {\n c++;\n return;\n }\n\n delete obj[str];\n\n c++;\n});\n\nrl.on('close', () => {\n const ans = Object.values(obj);\n\n console.log(ans.length);\n for (let i = 0; i < ans.length; i++) {\n console.log(ans[i]);\n }\n});\n"}, {"source_code": "let input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n input.push(line);\n});\n\n\nRL.on('close', () => {\n let n = parseInt(input[0]);\n let data = {\n \"red\" : [0, 'Reality'],\n \"purple\": [0, 'Power'],\n \"yellow\": [0, 'Mind'],\n \"orange\": [0, 'Soul'],\n \"blue\": [0, 'Space'],\n \"green\": [0, 'Time'],\n }\n\n console.log(6-n);\n if(6-n > 0){\n for(let i = 1; i <= n; i++){\n data[input[i]][0] = 1;\n }\n\n for(elem in data){\n if(data[elem][0] == 0){\n console.log(data[elem][1]);\n }\n }\n }\n});\n\n"}, {"source_code": "// http://codeforces.com/contest/987/problem/A\n// A. \u041f\u0435\u0440\u0447\u0430\u0442\u043a\u0430 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438\n'use strict';\n\nconst readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nconst gauntletMap = {\n purple: 'Power',\n green: 'Time',\n blue: 'Space',\n orange: 'Soul',\n red: 'Reality',\n yellow: 'Mind',\n};\n\nconst input = [];\nrl.on('line', (line) => { input.push(line); });\n\nrl.on('close', function () {\n for (let i = 1; i < input.length; i++) {\n delete gauntletMap[input[i]];\n }\n\n console.log(Object.getOwnPropertyNames(gauntletMap).length);\n for (let key in gauntletMap) {\n console.log(gauntletMap[key]);\n }\n});\n"}, {"source_code": "var g = {\n 'purple': 'Power',\n 'green': 'Time',\n 'blue': 'Space',\n 'orange': 'Soul',\n 'red': 'Reality',\n 'yellow': 'Mind',\n};\nvar n = parseInt(readline());\nwhile(n--){\n x = readline();\n delete g[x];\n}\nprint(Object.keys(g).length)\nObject.keys(g).forEach((e)=>{\n print(g[e]);\n})\n\n"}], "negative_code": [{"source_code": "function answer(input){\n var stones = {\n purple: 'Power',\n green: 'Time',\n blue: 'Space',\n orange: 'Soul',\n red: 'Reality',\n yellow: 'Mind'\n };\n\n var numStones = readline();\n var inputStones = [];\n var outputStones = [];\n for(var i = 0; i < numStones; i++){\n inputStones.push(readline());\n }\n inputStones.forEach(function(stoneColor){\n delete stones[stoneColor];\n });\n for(var stoneColor in stones){\n outputStones.push(stoneColor[stoneColor]);\n }\n print(outputStones.length);\n outputStones.forEach(function(stone){\n print(stone);\n });\n}\n\nanswer();\n"}, {"source_code": "var col2gem = {\n purple: \"Power\",\n green: \"Time\",\n blue: \"Space\",\n orange: \"Soul\",\n red: \"Reality\",\n yellow: \"Mind\",\n};\n\nvar n = readline();\n\nvar seen = new Set();\n\nfor (var i = 0; i < n; i++) {\n seen.add(readline());\n}\n\nfor (var col in col2gem) {\n if (!seen.has(col)) {\n print(col2gem[col]);\n }\n}"}, {"source_code": "// //The colors of the six gems\nvar gems = [\n { name: 'Power', color: 'purple' },\n { name: 'Time', color: 'green' },\n { name: 'Space', color: 'blue' },\n { name: 'Soul', color: 'orange' },\n { name: 'Reality', color: 'red' },\n { name: 'Mind', color: 'yellow' }\n]\n//the number of Gems in Infinity Gauntlet.\nvar n = readline();\n// var n = prompt();\nvar colors = [];\nif ((n > 0 || n == 0) && (n < 6 || n == 6)) {\n for (i = 0; i < n; i++) {\n colors.push(readline()) \n // colors.push(prompt())\n } \n}\nvar absent=gems.filter(function(gem){\n return (colors.indexOf(gem.color) == -1);\n})\nvar m=absent.length\nprint(m)\n// console.log(m)\n// console.log(colors)\nprint(absent.map(absent=>absent.name))\n// console.log(absent.map(absent=>absent.name))\n"}, {"source_code": "// //The colors of the six gems\nvar gems = [\n { name: 'Power', color: 'purple' },\n { name: 'Time', color: 'green' },\n { name: 'Space', color: 'blue' },\n { name: 'Soul', color: 'orange' },\n { name: 'Reality', color: 'red' },\n { name: 'Mind', color: 'yellow' }\n]\n//the number of Gems in Infinity Gauntlet.\nvar n = readline().split(' ');\nvar colors = [];\nvar color;\nif ((n > 0 || n == 0) && (n < 6 || n == 6)) {\n for (i = 0; i < n; i++) {\n colors.push(readline()+\"/n\") \n } \n}\nvar absent=gems.filter(function(gem){\n return (colors.indexOf(gem.color) == -1);\n})\nvar m=absent.length\nprint(m)\nprint(absent.map(absent=>absent.name))\n"}, {"source_code": " var n = parseInt(readline());\n var m = [];\n m['purple'] = 'power';\n m['green'] = 'Time';\n m['blue'] = 'Space';\n m['orange'] = 'Soul';\n m['red'] = 'Reality';\n m['yellow'] = 'Mind';\n for(var i = 0; i < n; i += 1) {\n var tmp = readline();\n m[tmp] = '';\n }\n var res = '';\n var count = 0;\n for(var c in m) {\n if(m[c].length > 0) {\n res += m[c] + '\\n';\n count += 1;\n }\n }\n print(count);\n print(res);"}], "src_uid": "7eff98fbcf4e4a3284e2d2f98351fe4a"} {"source_code": "for (var t = Number (readline ()); t > 0; t--)\r\n {\r\n var s = readline ().split (\"\").map (Number);\r\n var k = 10;\r\n\r\n var s1 = [s[0] === 0 ? 0 : 1];\r\n for (var i = 1, b = false; i < k - 1 && !b; i++)\r\n {\r\n if (i % 2 === 0) { s1.push (s[i] === 0 ? s1[i - 1] : s1[i - 1] + 1); }\r\n else { s1.push (s[i] === 1 ? s1[i - 1] - 1 : s1[i - 1]); }\r\n\r\n if (s1[i] + i / 2 > 5) { k = i + 1; b = true; }\r\n }\r\n\r\n var s2 = [s[0] === 1 ? -1 : 0];\r\n for (var i = 1, b = false; i < k - 1 && !b; i++)\r\n {\r\n if (i % 2 === 0) { s2.push (s[i] === 1 ? s2[i - 1] - 1 : s2[i - 1]); }\r\n else { s2.push (s[i] === 0 ? s2[i - 1] : s2[i - 1] + 1); }\r\n\r\n if (s2[i] + (i + 1) / 2 > 5) { k = i + 1; b = true; }\r\n }\r\n\r\n print (k);\r\n }", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let str = readline().trim();\r\n let ans = 9,\r\n cnt0 = 0,\r\n cnt1 = 0;\r\n for (let i = 0; i < 10; i++) {\r\n if ((i + 1) % 2 === 1) {\r\n if (str[i] !== \"0\") cnt0++;\r\n } else if (str[i] === \"1\") cnt1++;\r\n if (cnt0 > cnt1 + Math.floor((10 - i) / 2)) ans = Math.min(ans, i);\r\n if (cnt1 > cnt0 + Math.floor((9 - i) / 2)) ans = Math.min(ans, i);\r\n }\r\n cnt0 = 0;\r\n cnt1 = 0;\r\n for (let i = 0; i < 10; i++) {\r\n if ((i + 1) % 2 === 1) {\r\n if (str[i] === \"1\") cnt0++;\r\n } else if (str[i] !== \"0\") cnt1++;\r\n if (cnt0 > cnt1 + Math.floor((10 - i) / 2)) ans = Math.min(ans, i);\r\n if (cnt1 > cnt0 + Math.floor((9 - i) / 2)) ans = Math.min(ans, i);\r\n }\r\n console.log(ans + 1);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet s = rl();\r\n\r\n\t\tconst winscrt1 = [3, 3, 2, 2];\r\n\t\tconst winscrt2 = [3, 2, 2, 1];\r\n\r\n\t\tlet i, mx = [0, 0], mn = [0, 0];\r\n\t\tfor (i = 0; i < 9; i++) {\r\n\t\t\tconst team = i % 2;\r\n\t\t\tif (s[i] == 1) { \r\n\t\t\t\tmx[team]++; \r\n\t\t\t\tmn[team]++; \r\n\t\t\t}\r\n\t\t\tif (s[i] == '?') { \r\n\t\t\t\tmx[team]++; \r\n\t\t\t}\r\n\r\n\t\t\tlet t1rel = mx[0] - mn[1]; \r\n\t\t\tlet t2rel = mx[1] - mn[0]; \r\n\r\n\t\t\tif (t1rel == winscrt1[i - 5]) break;\r\n\t\t\tif (t2rel == winscrt2[i - 5]) break;\r\n\t\t}\r\n\t\tans = i + 1;\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [], "src_uid": "ba1aa2483f88164c1f281eebaab2cfbd"} {"source_code": "var nm = readline().split(' ').map(Number);\nvar n = nm[0];\nvar m = nm[1];\nvar p = [];\nvar sum = 0;\nfor (var i=0; i= p[j][0] && (i+1) <= p[j][1] ) {\n\t\t\tif (p[j][2] < t) {\n\t\t\t\tt = p[j][2];\n\t\t\t\tsum1 = p[j][3];\n\t\t\t}\n\t\t}\n\t}\n\tsum += sum1;\n}\nprint (sum);", "positive_code": [{"source_code": "'use strict'\n\nconst {EOL} = require('os')\n\nlet ipt = ''\nprocess.stdin.on('data', s => ipt += s)\nprocess.stdin.on('end', () => {\n let [U] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))\n let B = ipt.split(EOL).slice(1, -1).map(l => l.split(' ').map(v => parseInt(v)))\n\n let s = 0\n for (let i = 1; i < U + 1; i++) {\n s += b(i)\n }\n\n console.log(s)\n\n function b (u) {\n let bt = Infinity\n let m = 0\n for (let i = 0; i < B.length; i++) {\n const [l, r, t, c] = B[i]\n if (u < l || u > r) continue\n if (t < bt) {\n bt = t\n m = c\n }\n }\n return m\n }\n})"}], "negative_code": [], "src_uid": "ea1bebf20f24a681f03082c92326db5e"} {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [len, q] = readLine().split(\" \").map(Number);\n const str = readLine();\n const queries = [];\n while (q--) {\n const _q = readLine().split(\" \").map(Number);\n queries.push(_q);\n }\n let [store, c0, c1] = [[], 0, 0];\n for (let i = 0; i < len; i++) {\n const n = str[i];\n if (n === \"0\") c0++;\n else c1++;\n store[i] = { c0, c1 };\n }\n for (let [start, end] of queries) {\n if (\n (str[start - 1] === \"0\" && store[start - 1].c0 > 1) ||\n (str[start - 1] === \"1\" && store[start - 1].c1 > 1) ||\n (str[end - 1] === \"0\" && Math.abs(store[end - 1].c0 - store[len - 1].c0) >= 1) ||\n (str[end - 1] === \"1\" && Math.abs(store[end - 1].c1 - store[len - 1].c1) >= 1)\n ) {\n console.log(`YES`);\n } else console.log(`NO`);\n }\n }\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,q] = ti(readline().split(' '));\n let s = readline().split('');\n for(let i = 0; i < q; i++){\n let [l,r] = ti(readline().split(' '));\n l -= 1;\n r -= 1;\n let cr = s[r];\n let cl = s[l];\n let flag = false;\n for(let j = r+1; j < n; j++){\n if(s[j] === cr){\n flag = true;\n break;\n }\n }\n\n if(!flag){\n for(let j = 0; j < l; j++){\n if(s[j] === cl){\n flag = true;\n break;\n }\n }\n }\n\n if(flag)\n console.log('YES');\n else\n console.log('NO');\n }\n }\n}"}], "negative_code": [], "src_uid": "cbd91ac0fc9e4ca01996791e4c94bd6e"} {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]), m=parseInt(input[1]), k=parseInt(input[2]);\nfor(var i=1; i<=n; i++) readline();\nvar answer = ''+m*(m-1)/2+'\\n';\nfor(var i=1; i<=m; i++)\n{\nfor(var j=i+1; j<=m; j++)\n{\nanswer+=k?j+' '+i+'\\n':i+' '+j+'\\n';\n}\n}\nprint(answer);", "positive_code": [{"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar k=+l[2];\nvar a=[];\nfor(var i=0;i=0;ii--){\n\t\tfor(var i=0;i=0;ii--){\n\t\tfor(var i=0;iarr[i+1]){\n\t\t\t\t\tflg=true;\n\t\t\t\t\tvar temp=arr[i];\n\t\t\t\t\tarr[i]=arr[i+1];\n\t\t\t\t\tarr[i+1]=temp;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(flg){\n\t\t\t\tans.push((i+1)+' '+(i+2));\n\t\t\t}\n\t\t}\n\t}\n}\nprint(ans.length);\nfor(var i=0;i= 1; i -= 1) {\n\t\t\tfor (var j = i-1; j >= 1; j -= 1) {\n\t\t\t\tprint([i, j].join(' '));\n\t\t\t}\n\t\t}\n\t}\n}\n\nmain();\n"}], "negative_code": [{"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]), m=parseInt(input[1]), k=parseInt(input[2]);\nfor(var i=1; i<=n; i++) readline();\nvar answer = ''+m*(m-1)/2+'\\n';\nfor(var i=1; i<=m; i++)\n{\nfor(var j=i+1; j<=m; j++)\n{\nanswer+=k?i+' '+j+'\\n':j+' '+i+'\\n';\n}\n}\nprint(answer);"}], "src_uid": "6d146936ab34deaee24721e53474aef0"} {"source_code": "// n = 7;\n// k = 4;\n// inp_str = '4727447';\n\nvar input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t//console.log('i=',i);\n\t\t\t\tif ( (i+1) % 2 == 0){\n\t\t\t\t\t//console.log('i=5',str);\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0) != (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0) != (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t\t//console.log('str=',str);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));\n", "positive_code": [{"source_code": "// n = 7;\n// k = 4;\n// inp_str = '4727447';\n\nvar input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t//console.log('i=',i);\n\t\t\t\tif ( (i+1) % 2 == 0){\n\t\t\t\t\t//console.log('i=5',str);\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0) != (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0) != (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t\t//console.log('str=',str);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));\n"}], "negative_code": [{"source_code": "var input = readline().split('\\n');\nline1 = input[0].split(' ');\nn = line1[0];\nk = line1[1];\ninp_str = input[1];\n\n//n = 7;\n//k = 4;\n//inp_str = '4727447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\tif (i < n - 2) i--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\nprint(input[1]);\nprint(input[0]);\nprint(input);\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\n//print(transform(inp_str, k));"}, {"source_code": "var input = readline().split('\\n');\nline1 = input[0].split(' ');\nn = line1[0];\nk = line1[1];\ninp_str = input[1];\n\n//n = 7;\n//k = 4;\n//inp_str = '4727447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\tif (i < n - 2) i--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\nprint(input[1]);\nprint(input[0]);\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\n//print(transform(inp_str, k));"}, {"source_code": "var input = readline().split('\\n');\nline1 = input[0].split(' ');\nn = line1[0];\nk = line1[1];\ninp_str = input[1];\n\n//n = 7;\n//k = 4;\n//inp_str = '4727447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\tif (i < n - 2) i--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\nprint(input[1]);\nprint(k,' ',n);\n//console.log(transform(inp_str, k));\n//print(transform(inp_str, k));"}, {"source_code": "var input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n//n = 3;\n//k = 1000000000;\n//inp_str = '447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0 ^ k%2 == 0) ==1){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0 ^ k%2 == 0) ==1){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));"}, {"source_code": "var input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n//n = 3;\n//k = 1000000000;\n//inp_str = '447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0 ^ k%2 == 0) ==1){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0 ^ k%2 == 0) ==1){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));"}, {"source_code": "var input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n//n = 7;\n//k = 4;\n//inp_str = '4727447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\tif (i < n - 2) i--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));"}, {"source_code": "// n = 7;\n// k = 4;\n// inp_str = '4727447';\n\nvar input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t//console.log('i=',i);\n\t\t\t\tif ( (i+1) % 2 == 0){\n\t\t\t\t\t//console.log('i=5',str);\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0) == (k-1%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0) != (k-1%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t\t//console.log('str=',str);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));\n"}, {"source_code": "// n = 7;\n// k = 4;\n// inp_str = '4727447';\n\nvar input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n\n\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t//console.log('i=',i);\n\t\t\t\tif ( (i+1) % 2 == 0){\n\t\t\t\t\t//console.log('i=5',str);\n\t\t\t\t\tif (i-1>=0 && str[i-1]=='4'){\n\t\t\t\t\t\tif ( (j%2==0) == (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//console.log('aa=',str);\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (i+2 < n && str[i+2]=='7'){\n\t\t\t\t\t\tif ( (j%2==0) != (k%2 == 0)){\n\t\t\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn str;\n\t\t\t\t\t}\n\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\t//if (i < n - 2) i--;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t\t//console.log('j=',j);\n\t\t\t\t//console.log('str=',str);\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\nprint(transform(inp_str, k));\n"}, {"source_code": "var input = readline().split(' ');\nn = input[0];\nk = input[1];\nvar inp_str = readline();\n\n\n//n = 7;\n//k = 4;\n//inp_str = '4727447';\n\n\nString.prototype.replaceAt=function(index, replacement) {\n return this.substr(0, index) + replacement+ this.substr(index + replacement.length);\n}\n\nfunction transform(str, k){\n\t//for (i = 0; i < str.length; i ++)\n\ti = 0;\n\tj = 0;\n\t//while (j < k){\n\t\twhile (i < n - 1 && j < k){\n\t\t\t//console.log('i=',i);\n\t\t\tif (str[i] == '4' && str[i+1] == '7'){\n\t\t\t\tif (i % 2 == 0){\n\t\t\t\t\t//console.log(str);\n\t\t\t\t\tstr = str.replaceAt(i+1,'4');\n\t\t\t\t\t//console.log(str[i+1]);\n\t\t\t\t\t//console.log('i=',i);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstr = str.replaceAt(i,'7');\n\t\t\t\t\t//if (i-1 >=0) i= i - 2;\n\t\t\t\t\tif (i < n - 2) i--;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse i++;\n\t\t}\n\t\t//if (i == str.length) return str;\n\t\t//k++;\n\t//}\n\treturn str;\n}\nprint(input[1]);\nprint(input[0]);\nprint(input);\n//print(k,' ',n);\n//console.log(transform(inp_str, k));\n//print(transform(inp_str, k));"}], "src_uid": "8ce1ba0a98031c1bc28f53c11905391c"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar x1 = one[0];\n\t\tvar y1 = one[1];\n\t\tvar x2 = one[2];\n\t\tvar y2 = one[3];\n\t\tif(x1 == x2){\n\t\t\toutput[i] = Math.abs(y1 - y2);\n\t\t}else if(y1 == y2){\n\t\t\toutput[i] = Math.abs(x1 - x2);\n\t\t}else{\n\t\t\toutput[i] = Math.abs(y1 - y2) + Math.abs(x1 - x2) + 2;\n\t\t}\n\t}\n\tmyout(myconv(output, 9));\n}\n", "positive_code": [{"source_code": "const solve = (data) => {\n let x1 = data[0][0];\n let y1 = data[0][1];\n let x2 = data[0][2];\n let y2 = data[0][3];\n if (y1 == y2) {\n if (x1 == x2) {\n return 0;\n } else {\n return Math.abs(x2 - x1);\n }\n } else {\n if (x1 == x2) {\n return Math.abs(y2 - y1);\n } else {\n let h = Math.abs(x2 - x1);\n let v = Math.abs(y2 - y1);\n return h + 2 + v;\n }\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data));\n t--;\n i++;\n }\n });\n\n};\n\nmain()"}, {"source_code": "var inputs = parseInt(readline());\n\nfor(var i =0;i parseInt(x)); \n\tvar dist = 0; \n\tif(!(params[0]===params[2] || params[1]===params[3])) {\n\t\tdist+=2;}\n\tdist+=Math.abs(params[0]-params[2]) + Math.abs(params[1]-params[3]);\n\tprint(dist);\n\t\t\n\t\t\n}\n"}, {"source_code": "/* Description probleme et solution\n......\n..Problem.....\nA. Box is Pull\ntime limit per test1 second\nmemory limit per test256 megabytes\ninputstandard input\noutputstandard output\nWabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x1,y1) to the point (x2,y2)\n\nHe has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.\n\nFor example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).\n\nAlso, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.\n\nWabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.\n\nDetermine the minimum amount of time he needs to move the box from (x1,y1) to (x2,y2). Note that the point where Wabbit ends up at does not matter.\n\nInput\nEach test contains multiple test cases. The first line contains a single integer t (1\u2264t\u22641000): the number of test cases. The description of the test cases follows.\n\nEach of the next t lines contains four space-separated integers x1,y1,x2,y2 (1\u2264x1,y1,x2,y2\u2264109), describing the next test case.\n\nOutput\nFor each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x1,y1) to (x2,y2).\n\nExample\ninputCopy\n2\n1 2 2 2\n1 1 2 2\noutputCopy\n1\n4\n\nNote\nIn the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.\n\nIn the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.\n\n.......\n\n....Solution...\n......\n\n\nFin Description */\n\n\n//definition des variables\nvar testCasesNumber = readline();\nvar listOfPoints = [];\nvar minX=0;\nvar maxX=0;\nvar minY=0;\nvar maxY=0;\n\n//Saisie des donn\u00e9es\n\nfor (var i = 0; i < testCasesNumber; i++) {\n listOfPoints.push(readline().split(' '));\n }\n//Traitement ==> calcul du temps minimal requis\nfor (var i = 0; i < testCasesNumber; i++) {\n minX=Math.min(parseInt(listOfPoints[i][0]),parseInt(listOfPoints[i][2]));\n maxX=Math.max(parseInt(listOfPoints[i][0]),parseInt(listOfPoints[i][2]));\n minY=Math.min(parseInt(listOfPoints[i][1]),parseInt(listOfPoints[i][3]));\n maxY=Math.max(parseInt(listOfPoints[i][1]),parseInt(listOfPoints[i][3]));\n var time = 0;\n\ntime =maxX - minX; \ntime =time + (maxY- minY); \nif (minX!=maxX && minY!=maxY){\ntime+=2; \n}\nprint(time); \n} \n\n\n\n\n "}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet lineNum = 0;\nlet countOfData = null;\nlet data = [];\nreadline.on('line', line => {\n lineNum++;\n if(lineNum === 1) {\n countOfData = +line;\n return;\n }\n\n data.push(line.split(' ').map(i => +i));\n \n if(lineNum - 1 === countOfData) {\n goToSolution(data);\n }\n \n});\n\nfunction goToSolution(datas) {\n for(let data of datas) {\n let seconds = 0;\n seconds += Math.max(data[0], data[2]) - Math.min(data[0], data[2]);\n seconds += Math.max(data[1], data[3]) - Math.min(data[1], data[3]);\n if(data[0] !== data[2] && data[1] !== data[3]) seconds += 2;\n console.log(seconds);\n }\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n let [x1, y1, x2, y2] = readLine().split(\" \").map(Number);\n const [xDiff, yDiff] = [Math.abs(x1 - x2), Math.abs(y1 - y2)];\n const diff = xDiff + yDiff;\n\n if (xDiff === 0 || yDiff === 0) {\n console.log(diff);\n } else {\n console.log(diff + 2);\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 1;\n let i = 1;\n while (i <= testCases) {\n let a = data[i].trim().split(' ').map(Number);\n // const n = data[i] * 1;\n // const k = a[1];\n // let s = data[i + 1].trim().split(' ').map(Number);\n // s.sort((a, b) => b - a);\n let [x1, y1, x2, y2] = a;\n if (x1 === x2 && y1 === y2) {\n console.log(0);\n } else if (x1 === x2) {\n console.log(Math.abs(y1 - y2));\n } else if (y1 === y2) {\n console.log(Math.abs(x1 - x2));\n } else {\n console.log(Math.abs(x1 - x2) + Math.abs(y1 - y2) + 2);\n }\n i += 1;\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n// alpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = $()\n while (t--) {\n let [x1, y1, x2, y2] = $(4);\n if (x1 == x2 || y1 == y2) log(abs(x2 - x1) + abs(y2 - y1));\n else log(abs(x2 - x1) + abs(y2 - y1) + 2);\n }\n}\n"}, {"source_code": "let readline = require('readline');\nlet rl = readline.createInterface({input: process.stdin, output: process.stdout});\nlet lines = [];\nlet index = 0;\nrl.on('line', line => lines.push(line));\nrl.on('close', line => main());\n\nfunction read() {\n return lines[index++];\n}\n\nfunction main(){\n let t = Number(read());\n while (t--) {\n let line = read();\n let [x1 , y1, x2, y2] = line.split(' ').map(Number);\n if (x1 === x2 && y1 === y2) {\n console.log('0')\n } else {\n console.log(Math.abs(x1 - x2) + Math.abs(y1 - y2) + (x1 !== x2 && y1 !== y2 ? 2 : 0))\n }\n }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numCases = readLine();\n for (let i = 0; i < numCases; i++) {\n const input = readLine().split(' ');\n if (input[0] === input[2]) {\n console.log(Math.abs(input[1] - input[3]));\n } else if (input[1] === input[3]){\n console.log(Math.abs(input[0] - input[2]));\n } else {\n console.log(Math.abs(input[0] - input[2]) + Math.abs(input[1] - input[3]) + 2);\n }\n }\n}\n"}], "negative_code": [{"source_code": "const solve = (data) => {\n let x1 = data[0][0];\n let y1 = data[0][1];\n let x2 = data[0][2];\n let y2 = data[0][3];\n if (y1 == y2) {\n if (x1 == x2) {\n return 0;\n } else {\n return Math.abs(x2 - x1);\n }\n } else {\n if (x1 == x2) {\n return Math.abs(y2 - y1);\n } else {\n let h = Math.abs(x2 - x1) + 1;\n let v = Math.abs(y2 - y1);\n return h + (h - 1) + v;\n }\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data));\n t--;\n i++;\n }\n });\n\n};\n\nmain()"}, {"source_code": "const solve = (data) => {\n let x1 = data[0][0];\n let y1 = data[0][1];\n let x2 = data[0][2];\n let y2 = data[0][3];\n if (y1 == y2) {\n if (x1 == x2) {\n return 0;\n } else {\n return Math.abs(x2 - x1);\n }\n } else {\n if (x1 == x2) {\n return Math.abs(y2 - y1);\n } else {\n let h = Math.abs(x2 - x1) + 1;\n let v = Math.abs(y2 - y1);\n return h + 3 + v;\n }\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data));\n t--;\n i++;\n }\n });\n\n};\n\nmain()"}], "src_uid": "6a333044e2ed8f9f4fa44bc16b994418"} {"source_code": "const MEMORY = [];\nlet MEMORY_INDEX = 0;\nfunction print() {\n console.log.apply(null, arguments);\n}\nfunction readline() {\n return MEMORY[MEMORY_INDEX++];\n}\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n\nRL.on('line', (line) => {\n MEMORY.push(line);\n});\n\nRL.on('close', solve);\n\nfunction solve() {\n const T = Number.parseInt(readline(), 10);\n for (let I = 0; I < T; ++I) {\n let [n, x] = readline().split(' ').map(num => Number.parseInt(num, 10));\n let d;\n let h;\n let maxD = -1;\n let maxDiff = -1;\n for (let i = 0; i < n; ++i) {\n [d, h] = readline().split(' ').map(num => Number.parseInt(num, 10));\n if (d > maxD) {\n maxD = d;\n }\n if (d - h > 0 && d - h > maxDiff) {\n maxDiff = d - h;\n }\n }\n if (maxD >= x) {\n print(1);\n continue;\n }\n if (maxDiff < 1) {\n print(-1);\n } else {\n print(Math.ceil((x - maxD) / maxDiff) + 1);\n }\n }\n}\n", "positive_code": [{"source_code": "let stdinArr = [];\nconst readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', (line) => {\n stdinArr.push(line.trim().split(' ').map((item) => Number(item.trim())));\n}).on('close', () => {\n zmeiGorynich(stdinArr);\n})\n\nfunction zmeiGorynich(stdinArr) {\n let queryNum = stdinArr[0][0];\n let curIndex = 1;\n while (queryNum--) {\n let n = stdinArr[curIndex][0];\n let x = stdinArr[curIndex][1];\n let typeArr = stdinArr.slice(curIndex + 1, curIndex + n + 1);\n console.log(singleQuery(x, typeArr));\n curIndex += (n + 1);\n }\n}\n\nfunction singleQuery(x, typeArr) {\n let maxItem = null;\n let maxBlow = 0;\n let maxType = 0;\n let typeArrLen = typeArr.length;\n for( let i = 0; i < typeArrLen; i++) {\n let item = typeArr[i];\n let d = item[0];\n let h = item[1];\n if (x <= d) {\n // \u4e00\u51fb\u6bd9\u547d\n return 1;\n }\n let cur = x - d + h;\n if (cur < x) {\n maxItem = item;\n }\n let blow = d-h;\n if (blow > 0 && blow > maxBlow) {\n maxBlow = blow;\n }\n maxType = d > maxType ? d : maxType\n }\n if (maxItem === null) {\n return -1;\n }\n // \u51cf\u5c11\u5230\u53ef\u4ee5\u4e00\u51fb\u6bd9\u547d\n let count = (x - maxType) / maxBlow;\n return Math.ceil(count) + 1;\n}"}, {"source_code": "let lineCount = 0;\nlet queriesTotal;\nlet queriesNum = 0;\nlet isType = false;\nlet typeArr = [];\nlet n; // \u62e5\u6709\u7684\u6280\u80fd\u4e2a\u6570\nlet x; // \u539f\u59cb\u5934\u6570\n\n/*const readLine = require('./tools');\nreadLine(str, (line) => {\n singleLine(line, () => {\n console.log('-----end')\n })\n});*/\n\nconst readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nrl.on('line', (line) => {\n singleLine(line, () => {\n rl.close();\n })\n});\n\nfunction singleLine(line, close) {\n if (lineCount === 0) {\n queriesTotal = Number(line.trim());\n } else {\n let lines = line.trim().split(' ').map((item) => Number(item.trim()));\n let first = lines[0];\n let second = lines[1];\n if (!isType) {\n n = first;\n x = second;\n isType = true;\n } else {\n typeArr.push({\n d: first,\n h: second\n });\n if (typeArr.length === n) {\n console.log(zmeiGorynich(x, typeArr));\n isType = false;\n typeArr = [];\n queriesNum++;\n }\n }\n }\n if (queriesNum === queriesTotal) {\n close();\n }\n lineCount ++;\n}\n\nfunction zmeiGorynich(x, typeArr) {\n let maxItem = null;\n let maxBlow = 0;\n let maxType = 0;\n let typeArrLen = typeArr.length;\n for( let i = 0; i < typeArrLen; i++) {\n let item = typeArr[i];\n let {d, h} = item;\n if (x <= d) {\n // \u4e00\u51fb\u6bd9\u547d\n return 1;\n }\n let cur = x - d + h;\n if (cur < x) {\n maxItem = item;\n }\n let blow = d-h;\n if (blow > 0 && blow > maxBlow) {\n maxBlow = blow;\n }\n maxType = d > maxType ? d : maxType\n }\n if (maxItem === null) {\n return -1;\n }\n\n // \u51cf\u5c11\u5230\u53ef\u4ee5\u4e00\u51fb\u6bd9\u547d\n let count = (x - maxType) / maxBlow;\n return Math.ceil(count) + 1;\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var n = input[0];\n var x = input[1];\n \n var maxD = -Infinity;\n var maxP = -Infinity;\n var maxOPOP = -Infinity;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var d = input[0];\n var h = input[1];\n \n maxD = Math.max(maxD, d);\n if (maxP < d - h) {\n maxP = d - h;\n maxOPOP = d;\n }\n }\n \n if (maxD >= x) {\n pr(1);\n } else {\n if (maxP <= 0) {\n pr(-1);\n } else {\n var res1 = Math.ceil((x-maxD)/maxP) + 1;\n var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;\n pr(Math.min(res1, res2))\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "let lineCount = 0;\nlet queriesTotal;\nlet queriesNum = 0;\nlet isType = false;\nlet typeArr = [];\nlet n; // \u62e5\u6709\u7684\u6280\u80fd\u4e2a\u6570\nlet x; // \u539f\u59cb\u5934\u6570\n\n// const readLine = require('./tools');\n// readLine(str, (line) => {\n// singleLine(line, () => {\n// console.log('-----end')\n// })\n// });\n\nconst readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nrl.on('line', (line) => {\n singleLine(line, () => {\n rl.close();\n })\n});\n\nfunction singleLine(line, close) {\n if (lineCount === 0) {\n queriesTotal = Number(line.trim());\n } else {\n let lines = line.trim().split(' ').map((item) => Number(item.trim()));\n let first = lines[0];\n let second = lines[1];\n if (!isType) {\n n = first;\n x = second;\n isType = true;\n } else {\n typeArr.push({\n d: first,\n h: second\n });\n if (typeArr.length === n) {\n console.log(zmeiGorynich(x, typeArr));\n isType = false;\n typeArr = [];\n queriesNum++;\n }\n }\n }\n if (queriesNum === queriesTotal) {\n close();\n }\n lineCount ++;\n}\n\nfunction zmeiGorynich(x, typeArr) {\n let maxItem = null;\n let maxBlow = 0;\n let maxType = 0;\n typeArr.forEach((item) => {\n let {d, h} = item;\n\n if (x <= d) {\n // \u4e00\u51fb\u6bd9\u547d\n return 1;\n }\n let cur = x - d + h;\n if (cur < x) {\n maxItem = item;\n }\n let blow = d-h;\n if (blow > 0 && blow > maxBlow) {\n maxBlow = blow;\n }\n maxType = d > maxType ? d : maxType\n });\n if (maxItem === null) {\n return -1;\n }\n\n // \u51cf\u5c11\u5230\u53ef\u4ee5\u4e00\u51fb\u6bd9\u547d\n let count = (x - maxType) / maxBlow;\n return Math.ceil(count) + 1;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet queriesTotal;\nlet queriesNum = 0;\nlet isType = false;\nlet typeArr = [];\nlet n;\nlet x;\nrl.on('line', function(line){\n if (lineCount === 0) {\n queriesTotal = Number(line.trim());\n } else {\n let lines = line.trim().split(' ').map((item) => Number(item.trim()));\n let first = lines[0];\n let second = lines[1];\n if (!isType) {\n n = first;\n x = second;\n isType = true;\n } else {\n typeArr.push({\n d: first,\n h: second\n });\n if (typeArr.length === n) {\n console.log(zmeiGorynich(x, typeArr));\n isType = false;\n typeArr = [];\n queriesNum++;\n }\n }\n }\n if (queriesNum === queriesTotal) {\n rl.close();\n }\n lineCount ++;\n});\n\nfunction zmeiGorynich(x, typeArr) {\n let minLast = x;\n let maxItem = null;\n let maxBlow = 0;\n let maxType = 0;\n typeArr.forEach((item) => {\n let {d, h} = item;\n let cur = minLast - d + h;\n if (cur < minLast) {\n minLast = cur;\n maxItem = item;\n }\n let blow = d-h;\n if (blow > 0 && blow > maxBlow) {\n maxBlow = blow;\n }\n maxType = d > maxType ? d : maxType\n });\n if (maxItem === null) {\n return -1;\n }\n if (minLast <= 0) {\n // \u4e00\u51fb\u6bd9\u547d\n return 1;\n }\n\n // \u51cf\u5c11\u5230\u53ef\u4ee5\u4e00\u51fb\u6bd9\u547d\n let count = (x - maxType) / maxBlow;\n return Math.ceil(count) + 1;\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var n = input[0];\n var x = input[1];\n \n var maxD = -Infinity;\n var maxP = -Infinity;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var d = input[0];\n var h = input[1];\n \n maxD = Math.max(maxD, d);\n maxP = Math.max(maxP, d - h);\n }\n \n if (maxD > x) {\n pr(1);\n } else {\n if (maxP < 0) {\n pr(-1);\n } else {\n x -= maxD;\n pr(Math.ceil(x/maxP) + 1)\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var n = input[0];\n var x = input[1];\n \n var maxD = -Infinity;\n var maxP = -Infinity;\n var maxOPOP = -Infinity;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var d = input[0];\n var h = input[1];\n \n maxD = Math.max(maxD, d);\n if (maxP < d - h) {\n maxP = d - h;\n maxOPOP = d;\n }\n }\n \n if (maxD >= x) {\n pr(1);\n } else {\n if (maxP < 0) {\n pr(-1);\n } else {\n var res1 = Math.ceil((x-maxD)/maxP) + 1;\n var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;\n pr(Math.min(res1, res2))\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var T = rdN();\n \n while (T --> 0) {\n var input = rdArN();\n var n = input[0];\n var x = input[1];\n \n var maxD = -Infinity;\n var maxP = -Infinity;\n var maxOPOP = -Infinity;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var d = input[0];\n var h = input[1];\n \n maxD = Math.max(maxD, d);\n if (maxP < d - h) {\n maxP = d - h;\n maxOPOP = d;\n }\n }\n \n if (maxD > x) {\n pr(1);\n } else {\n if (maxP < 0) {\n pr(-1);\n } else {\n var res1 = Math.ceil((x-maxD)/maxP) + 1;\n var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;\n pr(Math.min(res1, res2))\n }\n }\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "36099a612ec5bbec1b95f2941e759c00"} {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n for (var m = 1; m < input.length; m++) {\r\n var arr = input[m].split(\" \").map((i) => { \r\n return Number(i);\r\n });\r\n var n = arr[0];\r\n var list = arr.slice(1);\r\n var patterns = [];\r\n for (let num = 0; num < 16; num++) {\r\n var binary = num.toString(2);\r\n binary = \"0\".repeat(4 - binary.length) + binary; \r\n patterns.push(binary);\r\n }\r\n\r\n var flag = false;\r\n for (var pattern of patterns) {\r\n for (var i = 0; i < list.length; i++) {\r\n var corner = Number(pattern[i]) + Number(pattern[(i + 1) % list.length]);\r\n if (list[i] > corner + (n - 2) || list[i] < corner) {\r\n break;\r\n }\r\n }\r\n if (i === list.length) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (flag) {\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n})", "positive_code": [{"source_code": "'use-strict'\r\n\r\nconst { PassThrough } = require(\"stream\");\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [N,U,R,D,L] = readLine().split(' ').map(Number);\r\n\r\n const res = b(N,U,R,D,L);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction b(N,U,R,D,L){\r\n let [rU, rR, rD, rL] = [U,R,D,L]; \r\n for(let mask = 0; mask <= 16; mask++){\r\n [rU, rR, rD, rL] = [U,R,D,L]; \r\n if (mask & 1){\r\n rU-= 1;\r\n rL-= 1;\r\n }\r\n if (mask & 2){\r\n rL-= 1;\r\n rD-= 1;\r\n }\r\n if (mask & 4){\r\n rD-= 1;\r\n rR-= 1;\r\n }\r\n if (mask & 8){\r\n rR-= 1;\r\n rU-=1;\r\n }\r\n if (Math.min(rU,rR,rD,rL) >= 0 && Math.max(rU,rR,rD,rL) <= N - 2){\r\n return 'YES'\r\n }\r\n }\r\n return 'NO';\r\n}\r\n \r\nmodule.exports = b;"}, {"source_code": "const checkBit = (n, mask) => {\n return (n & mask) !== 0 ? 1 : 0;\n};\n\nconst solve = (n, U, R, D, L) => {\n for (let i = 0; i < 2 ** 4; i++) {\n const ul = checkBit(i, 1 << 3);\n const ur = checkBit(i, 1 << 2);\n const dr = checkBit(i, 1 << 1);\n const dl = checkBit(i, 1 << 0);\n const edge = [U - ul - ur, R - ur - dr, D - dr - dl, L - dl - ul];\n if (edge.every(e => e >= 0 && e <= n - 2)) return true;\n }\n return false;\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const [n, U, R, D, L] = readListInt();\n if (solve(n, U, R, D, L)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar nurdl = readline().split(\" \").map(x => parseInt(x));\n\tvar n = nurdl[0];\n\n\tvar any = false;\n\tfor (i1 = 0; i1 < 2; i1++)\n\tfor (i2 = 0; i2 < 2; i2++)\n\tfor (i3 = 0; i3 < 2; i3++)\n\tfor (i4 = 0; i4 < 2; i4++) {\n\t\tvar th = true;\n\t\tth &= nurdl[1] - i1 - i2 <= n - 2;\n\t\tth &= nurdl[2] - i2 - i4 <= n - 2;\n\t\tth &= nurdl[3] - i3 - i4 <= n - 2;\n\t\tth &= nurdl[4] - i1 - i3 <= n - 2;\n\t\tth &= nurdl[1] - i1 - i2 >= 0;\n\t\tth &= nurdl[2] - i2 - i4 >= 0;\n\t\tth &= nurdl[3] - i3 - i4 >= 0;\n\t\tth &= nurdl[4] - i1 - i3 >= 0;\n\t\tany |= th;\n\t}\n\tprint(any ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')\r\n if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')\r\n\r\n if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')\r\n if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')\r\n if (n === 2 && (r + l + u + d) === 1) return console.log('NO')\r\n\r\n if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')\r\n if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')\r\n\r\n\r\n if (u === n && d === (n-1) && (l < 2 && r < 2)) return console.log('NO')\r\n if (d === n && u === (n-1) && (l < 2 && r < 2)) return console.log('NO')\r\n\r\n if (r === n && l === (n-1) && (u < 2 && d < 2)) return console.log('NO')\r\n if (l === n && r === (n-1) && (u < 2 && d < 2)) return console.log('NO')\r\n\r\n if ((n - 1) === u && (n - 1) === d && (l+r<2)) return console.log('NO')\r\n if ((n - 1) === l && (n - 1) === r && (u+d<2)) return console.log('NO')\r\n\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, U, R, D, L] = rna();\r\n\r\n\t\tlet ans;\r\n\t\tfor (let mask = 1; mask <= 16; mask++) {\r\n\t\t\tlet [rU, rR, rD, rL] = [U, R, D, L];\r\n\r\n\t\t\tif (mask & 1) {\r\n\t\t\t\trU--;\r\n\t\t\t\trL--;\r\n\t\t\t}\r\n\t\t\tif (mask & 2) {\r\n\t\t\t\trL--;\r\n\t\t\t\trD--;\r\n\t\t\t}\r\n\t\t\tif (mask & 4) {\r\n\t\t\t\trD--;\r\n\t\t\t\trR--;\r\n\t\t\t}\r\n\t\t\tif (mask & 8) {\r\n\t\t\t\trR--;\r\n\t\t\t\trU--;\r\n\t\t\t}\r\n\t\t\tif (Math.min(rU, rL, rD, rR) >= 0 && Math.max(rU, rL, rD, rR) <= n-2) {\r\n\t\t\t\tans = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')\r\n if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')\r\n\r\n if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')\r\n if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')\r\n if (n === 2 && (r + l + u + d) === 1) return console.log('NO')\r\n\r\n if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')\r\n if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')\r\n\r\n\r\n if (u === n && d === (n-1) && (l < 2 && r < 2)) return console.log('NO')\r\n if (d === n && u === (n-1) && (l < 2 && r < 2)) return console.log('NO')\r\n\r\n if (r === n && l === (n-1) && (u < 2 && d < 2)) return console.log('NO')\r\n if (l === n && r === (n-1) && (u < 2 && d < 2)) return console.log('NO')\r\n\r\n\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')\r\n if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')\r\n\r\n if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')\r\n if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')\r\n if (n === 2 && (r + l + u + d) === 1) return console.log('NO')\r\n\r\n if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')\r\n if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')\r\n if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')\r\n\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')\r\n if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')\r\n\r\n if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')\r\n if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')\r\n if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')\r\n\r\n if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && r + l + u + d === 5) return console.log('NO')\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n //\r\n Array(Number(x)).fill(1).map((t, iii) => {\r\n // var n = parseInt(readline())\r\n var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n\r\n if (u === 0 && (r === n || l === n)) return console.log('NO')\r\n if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n if (u === n && d === n && (l<2 || r<2)) return console.log('NO')\r\n if (l === n && r === n && (u<2 || d<2)) return console.log('NO')\r\n\r\n // if (l === 0 && (u === n || d === n)) return console.log('NO')\r\n // if (d === 0 && (r === n || l === n)) return console.log('NO')\r\n // if (r === 0 && (u === n || d === n)) return console.log('NO')\r\n\r\n console.log('YES')\r\n // var a = readline().split('').map((x, iii) => {\r\n // return x\r\n // })\r\n\r\n })\r\n}\r\n\r\nfunction checkString(a) {\r\n // console.log(a)\r\n var count = 0\r\n var res = true\r\n for (let i = 0; i < a.length; i++) {\r\n if (a[i] === '(') count++\r\n else {\r\n count--\r\n if (count < 0) res = false\r\n }\r\n }\r\n if (count !== 0) res = false\r\n\r\n return res\r\n\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, U, R, D, L] = rna();\r\n\r\n\t\tlet l = 0, r = 0, u = 0, d = 0, lr = 0, ud = 0;\r\n\r\n\t\tif (U == n) l++, r++;\r\n\t\tif (U == n-1) lr++;\r\n\r\n\t\tif (D == n) l++, r++;\r\n\t\tif (D == n-1) lr++;\r\n\r\n\t\tif (L == n) u++, d++;\r\n\t\tif (L == n-1) ud++;\r\n\r\n\t\tif (R == n) u++, d++;\r\n\t\tif (R == n-1) ud++;\r\n\r\n\t\tconst ok = L >= l && R >= r && U >= u && D >= d && L+R >= lr && U+D >= ud && U+L+R+D <= 4*(n-1);\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, U, R, D, L] = rna();\r\n\r\n\t\tlet l = 0, r = 0, u = 0, d = 0, lr = 0, ud = 0;\r\n\r\n\t\tif (U == n) l++, r++;\r\n\t\tif (U == n-1) lr++;\r\n\r\n\t\tif (D == n) l++, r++;\r\n\t\tif (D == n-1) lr++;\r\n\r\n\t\tif (L == n) u++, d++;\r\n\t\tif (L == n-1) ud++;\r\n\r\n\t\tif (R == n) u++, d++;\r\n\t\tif (R == n-1) ud++;\r\n\r\n\t\tconst ok = L >= l && R >= r && U >= u && D >= d && L+R >= lr && U+D >= ud;\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, u, r, d, l] = rna();\r\n\r\n\t\tfunction check(u, l, r) {\r\n\t\t\tlet ok = true;\r\n\t\t\tif (u == n) ok = ok && l > 0 && r > 0;\r\n\t\t\tif (u == n-1) ok = ok && l + r > 0;\r\n\t\t\treturn ok;\r\n\t\t}\r\n\r\n\t\tlet ok = check(u, l, r) &&\r\n\t\t\tcheck(l, u, d) &&\r\n\t\t\tcheck(r, u, d) && \r\n\t\t\tcheck(d, l, r);\r\n\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use-strict'\r\n\r\nconst { PassThrough } = require(\"stream\");\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [N,U,R,D,L] = readLine().split(' ').map(Number);\r\n\r\n const res = b(N,U,R,D,L);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction b(N,U,R,D,L){\r\n let [rU, rR, rD, rL] = [U,R,D,L]; \r\n console.log(rU, rR, rD, rL) \r\n for(let mask = 0; mask <= 16; mask++){\r\n [rU, rR, rD, rL] = [U,R,D,L]; \r\n console.log(rU, rR, rD, rL, mask) \r\n if (mask & 1){\r\n rU-= 1;\r\n rL-= 1;\r\n }\r\n if (mask & 2){\r\n rL-= 1;\r\n rD-= 1;\r\n }\r\n if (mask & 4){\r\n rD-= 1;\r\n rR-= 1;\r\n }\r\n if (mask & 8){\r\n rR-= 1;\r\n rU-=1;\r\n }\r\n if (Math.min(rU,rR,rD,rL) >= 0 && Math.max(rU,rR,rD,rL) <= N - 2){\r\n return 'YES'\r\n }\r\n }\r\n return 'NO';\r\n}\r\n \r\nmodule.exports = b;"}, {"source_code": "'use-strict'\r\n\r\nconst { PassThrough } = require(\"stream\");\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [N,U,R,D,L] = get_ints();\r\n\r\n const res = b(N,U,R,D,L);\r\n\r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n\r\nfunction b(N,U,R,D,L){\r\n const u = U - 2;\r\n const r = R - 2;\r\n const d = D - 2;\r\n const l = L - 2;\r\n if(u>= 0 && u<= N - 2 && r >= 0 && r <= N - 2 && d >= 0 && d <= N- 2 && l >= 0 && l <= N - 2){\r\n return 'YES'\r\n } else{\r\n return 'NO';\r\n }\r\n}\r\n "}, {"source_code": "const solve = (n, U, R, D, L) => {\n const edge = [U, R, D, L];\n if (edge.some(e => e > n)) return false;\n if (edge.every(e => e < n)) return true;\n\n let cU = 0,\n cR = 0,\n cD = 0,\n cL = 0;\n\n [U, D].forEach(e => {\n if (e === n) {\n cL += 1;\n cR += 1;\n }\n });\n\n [L, R].forEach(e => {\n if (e === n) {\n cU += 1;\n cD += 1;\n }\n });\n\n return U >= cU && D >= cD && L >= cL && R >= cR;\n};\n\nconst main = () => {\n let test = readInt();\n while (test--) {\n const [n, U, R, D, L] = readListInt();\n if (solve(n, U, R, D, L)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readLine = () => {\n return inputString[currentLine++];\n};\n\nconst readInt = () => {\n return parseInt(inputString[currentLine++]);\n};\n\nconst readListInt = () => {\n return inputString[currentLine++].split(\" \").map(s => parseInt(s));\n};\n"}, {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar nurdl = readline().split(\" \").map(x => parseInt(x));\n\tvar n = nurdl[0];\n\n\tvar any = false;\n\tfor (i1 = 0; i1 <= 2; i1++)\n\tfor (i2 = 0; i2 <= 2; i2++)\n\tfor (i3 = 0; i3 <= 2; i3++)\n\tfor (i4 = 0; i4 <= 2; i4++) {\n\t\tvar th = true;\n\t\tth &= nurdl[1] - i1 - i2 <= n - 2;\n\t\tth &= nurdl[2] - i2 - i4 <= n - 2;\n\t\tth &= nurdl[3] - i3 - i4 <= n - 2;\n\t\tth &= nurdl[4] - i1 - i3 <= n - 2;\n\t\tth &= nurdl[1] - i1 - i2 >= 0;\n\t\tth &= nurdl[2] - i2 - i4 >= 0;\n\t\tth &= nurdl[3] - i3 - i4 >= 0;\n\t\tth &= nurdl[4] - i1 - i3 >= 0;\n\t\tany |= th;\n\t}\n\tprint(any ? \"YES\" : \"NO\");\n}\n"}], "src_uid": "1c94596da439c56b56e59da36734a912"} {"source_code": "nm = readline().split(' ').map(Number);\nA = readline().split(' ').map(Number);\nB = readline().split(' ').map(Number);\nAr = [];\nans = 0;\nfor(var i = 0;i {\n\tif(x[2] < y[2]) return -1;\n\tif(x[2] == y[2]) return 0;\n\tif(x[2] > y[2]) return 1;\n});\nfor(var i=0;i {if(a < b) return a; return b;})(Ar[i][0],Ar[i][1]);\n}\nprint(ans);\n", "positive_code": [{"source_code": "var tmp = readline().split(' ');\nvar n = parseInt(tmp[0]);\nvar k = parseInt(tmp[1]);\nvar a = readline().split(' ').map(function(x) {\n return parseInt(x);\n});\nvar b = readline().split(' ').map(function(x) {\n return parseInt(x);\n});\nvar c = a.map(function(x, i) {\n return {\n i: i,\n d: a[i] - b[i]\n };\n}).sort(function(a, b) {\n return a.d - b.d;\n});\nvar r = 0;\nfor(var i = 0; i < n; i += 1) {\n if(i < k) {\n r += a[c[i].i];\n } else {\n r += Math.min(a[c[i].i], b[c[i].i]);\n }\n}\n\nprint(r);\n"}], "negative_code": [], "src_uid": "b5355e1f4439b198d2cc7dea01bc4bc3"} {"source_code": "Array.prototype.in_array = function(p_val) {\n\tfor(var i = 0, l = this.length; i < l; i++)\t{\n\t\tif(this[i] == p_val) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\nvar inp = readline().split(' ');\nvar n = inp[0];\nvar m = inp[1];\n\nvar m_arr = [];\nfor(var i = 1; i <= n; i++) {\n var n_arr = readline().split(' ');\n for (var j = 1; j <= n_arr[0]; j++) {\n m_arr.push(n_arr[j]);\n }\n}\nvar f;\nfor(var k = 1; k <= m; k++) {\n if (m_arr.in_array(k)) {\n f = true;\n } else {\n f = false;\n break;\n }\n}\nif(f) {\n print(\"YES\");\n} else {\n print(\"NO\");\n}", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet arr = [];\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n let temp = d.split(' ');\n temp.shift();\n\n arr = arr.concat(temp);\n\n c++;\n});\n\nrl.on('close', () => {\n const ans = new Set(arr);\n\n if (ans.size === m) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n});\n"}, {"source_code": "//const nums = line.trim().split(' ').map(s => parseInt(s))\n\nvar numLines = 0;\n\nvar buttons = 0;\nvar bulbs = 0;\n\nvar allBulbs = [];\n\nrequire('readline').createInterface({\n input: process.stdin,\n}).on('line', (line) => {\n numLines++;\n let nums = line.trim().split(' ');\n for(let i = 0; i {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n arr = arr.concat(d.split(' '));\n\n c++;\n});\n\nrl.on('close', () => {\n const ans = new Set(arr);\n\n if (ans.size === m) {\n console.log('YES');\n }\n else {\n console.log('NO');\n }\n});\n"}], "src_uid": "9438ce92e10e846dd3ab7c61a1a2e3af"} {"source_code": "let readline = require(\"readline\");\r\n\r\nlet rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n\r\n if (input.length === +input[0] + 1) {\r\n // call your function here\r\n solve(input);\r\n rl.close();\r\n }\r\n});\r\n\r\nlet solve = (input) => {\r\n for (let i = 1; i < input.length; i++) {\r\n while (+input[i] % 2 === 0) {\r\n input[i] = +input[i] / 2;\r\n }\r\n if (+input[i] > 1) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n};\r\n", "positive_code": [{"source_code": "var cnt = +readline();\r\nvar arr = [];\r\nfor(var i = 0; i < cnt; i++) {\r\n arr.push(readline());\r\n}\r\n\r\n\r\n \r\nfunction oddDivisor(n) {\r\n if (n !== 1 && n % 2 === 1) {\r\n return 'YES';\r\n }\r\n if (n === 1) {\r\n return 'NO';\r\n }\r\n return oddDivisor(Math.floor(n / 2));\r\n}\r\n \r\nfor (var i = 0; i < arr.length; i++) {\r\n print(oddDivisor(arr[i]))\r\n}"}, {"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; ++i){\r\n var n = readline();\r\n while(n > 1){\r\n if(n%2 === 0){\r\n n = n /2;\r\n }\r\n else{\r\n print(\"YES\");\r\n break;\r\n }\r\n }\r\n if(n == 1){\r\n print(\"NO\");\r\n }\r\n }"}, {"source_code": "var n = +readline();\r\nfor(var i = 0; i < n; i++) {\r\n var val = +readline(), temp = 2;\r\n while(val > temp) {\r\n temp = temp * 2;\r\n }\r\n print(val === temp ? 'NO' : 'YES');\r\n}\r\n"}, {"source_code": "\"use strict\"\r\nlet iter = parseInt(readline());\r\n \r\nwhile(iter--){\r\nlet ch=false;\r\nlet input=parseInt(readline());\r\nfor(var i =input;i>1;i/=2){\r\nif(i%2!==0){\r\nch=true;\r\n\r\n}\r\n\r\n}\r\n(ch===true)?print(\"YES\"):print(\"NO\");\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let res = \"NO\";\r\n let input = parseInt(readline());\r\n for(let i = input; input > 1; input /= 2){\r\n if(input % 2 === 1){\r\n res = \"YES\";\r\n break;\r\n }\r\n }\r\n print(res);\r\n}"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k % 2 == 1){\n console.log('YES')\n continue;\n }\n while(k % 2 === 0){\n k /= 2\n }\n console.log(k > 1 ? 'YES' : 'NO')\n }\n});"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n let q = ''\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n let c\r\n while ((c = p.read()) !== null) {\r\n c = (q + c).split(/\\r\\n|\\r|\\n/)\r\n q = c[c.length - 1]\r\n for (let i = 0; i < c.length - 1; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n let one = BigInt(1)\r\n let two = BigInt(2)\r\n let zero = BigInt(0)\r\n for (let i = 0; i < t; ++i) {\r\n let n = BigInt(await nextString())\r\n while (n % two === zero) {\r\n n = n >> one\r\n }\r\n if (n > one) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const listeners = [], strings = [], ps = process.stdin\r\n let last = ''\r\n ps.setEncoding('utf8')\r\n ps.on('readable', () => {\r\n let chunk\r\n while ((chunk = ps.read()) !== null) {\r\n chunk = (last + chunk).split(/\\r\\n|\\r|\\n/)\r\n last = chunk[chunk.length - 1]\r\n for (let i = 0; i < chunk.length - 1; ++i) {\r\n if (chunk[i].length > 0) {\r\n if (listeners.length > 0) {\r\n listeners.shift(1)(chunk[i])\r\n }\r\n else {\r\n strings.push(chunk[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const fn = resolve => {\r\n if (strings.length > 0) {\r\n resolve(strings.shift(1))\r\n }\r\n else {\r\n listeners.push(resolve)\r\n }\r\n }\r\n return () => new Promise(fn)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n let one = BigInt(1)\r\n let two = BigInt(2)\r\n let zero = BigInt(0)\r\n for (let i = 0; i < t; ++i) {\r\n let n = BigInt(await nextString())\r\n while (n % two === zero) {\r\n n = n >> one\r\n }\r\n if (n > one) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n \r\nmain()\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n let N = +rl();\r\n while (N % 2 === 0) N /= 2;\r\n N > 1 ? cl(\"Yes\") : cl(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\tconst map = new Map();\n\twhile (t--) {\n\t\tlet n = +readLine();\n\t\tif (map.has(n)) {\n\t\t\tconsole.log(map.get(n));\n\t\t} else {\n\t\t\tif (n % 2 !== 0) {\n\t\t\t\tmap.set(n, 'YES');\n\t\t\t\tconsole.log('YES');\n\t\t\t} else {\n\t\t\t\tlet found = false;\n\t\t\t\tlet div = Math.floor(n / 2);\n\t\t\t\twhile (div > 1) {\n\t\t\t\t\tif (div % 2 !== 0) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tconsole.log('YES');\n\t\t\t\t\t\tmap.set(n, 'YES');\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdiv = Math.floor(div / 2);\n\t\t\t\t}\n\t\t\t\tif (!found) {\n\t\t\t\t\tmap.set(n, 'NO');\n\t\t\t\t\tconsole.log('NO');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var d = n + 1\r\n console.log(isPrime(n))\r\n // if (n % 2 !== 0) return console.log('YES')\r\n // if (!isPrime(n)) return console.log(n)\r\n // console.log('NO')\r\n })\r\n}\r\n\r\nfunction isPrime(num) {\r\n var result = true\r\n while (num !== 1 && num % 2 === 0) {\r\n num = num / 2\r\n }\r\nreturn num !== 1 ? 'YES' :'NO'\r\n console.log(num)\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar isOK = false;\r\n\t\twhile(N > 1){\r\n\t\t\tif(N % 2 == 0){\r\n\t\t\t\tN /= 2;\r\n\t\t\t}else{\r\n\t\t\t\tisOK = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var n = lines[i];\n if(n % 2 == 1){\n console.log('YES');\n continue;\n }\n while(n % 2 === 0){\n n /= 2;\n }\n console.log(n > 1 ? 'YES' : 'NO');\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\n\r\n/********** Utility Function Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Function End **********/\r\n/**\r\n * Don't Touch this fucntion at all unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** Code Start **********\r\n\r\n\r\nfunction solve() {\r\n let tc = readSingleInt();\r\n // console.log(BigInt(readLine()));\r\n const two = BigInt(2);\r\n while(tc--){\r\n let bgi = BigInt(readLine());\r\n let cnt = 0;\r\n while(bgi%two==0){\r\n bgi = bgi / two;\r\n }\r\n if(bgi===BigInt(1)){\r\n print(\"NO\");\r\n }else{\r\n print(\"YES\")\r\n }\r\n }\r\n\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let num = +input[z++];\r\n if(num % 2){\r\n console.log(\"YES\");\r\n }\r\n else{\r\n if(Math.log2(num) % 2 === 0 || Math.log2(num) % 2 === 1){\r\n console.log(\"NO\");\r\n }\r\n else{\r\n console.log(\"YES\");\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "//https://codeforces.com/problemset/problem/1475/A\r\nconst readline = require(\"readline\");\r\nconst scanner = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout\r\n});\r\n\r\nisOne = true;\r\nscanner.on(\"line\", input => {\r\n\tif (isOne)\r\n\t{\r\n\t\tisOne = false;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tconsole.log(oddDivisor(+input));\r\n\t}\r\n});\r\n\r\n//Oh lmao if everything is even divisor then it would just be 2^x\r\n//A odd divisor is the only thing that jams this\r\nconst oddDivisor = num => Math.log2(num) % 1 != 0 ? \"YES\" : \"NO\";"}, {"source_code": "// define file test.inp\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\n\r\nvar jsin = \"\";\r\nvar jscur = 0;\r\n\r\nprocess.stdin.on('data',chunk => jsin += chunk);\r\nprocess.stdin.on('end',function(){\r\n jsin = jsin.split('\\n')\r\n main();\r\n});\r\n\r\nreadLine = () => jsin[jscur++];\r\nreadLines = () => readLine().split(' ');\r\nreadInt = () => parseInt(readLine());\r\nreadInts = () => readLine().split(' ').map(x => parseInt(x));\r\n\r\nfunction main(){\r\n // code goes here!! \r\n var numTest = readInt();\r\n for(let i = 0;i < numTest;++i){\r\n let n = readInt();\r\n while(n % 2 == 0){\r\n n /= 2;\r\n }\r\n if(n > 1){\r\n console.log(\"YES\");\r\n } else {\r\n console.log(\"NO\");\r\n }\r\n }\r\n}\r\n\r\n\r\n"}], "negative_code": [{"source_code": "function oddDivisor(n) {\r\n if (n !== 1 && n % 2 === 1) {\r\n return 'YES';\r\n }\r\n if (n === 1) {\r\n return 'NO';\r\n }\r\n return oddDivisor(Math.floor(n / 2));\r\n}"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; j++){\n var k = lines[j]\n console.log(k % 2 ==1 ? 'YES' : 'NO')\n continue;\n \n \n }\n});"}, {"source_code": "// var gcd = function(a, b) {\n// if (!b) {\n// return a;\n// }\n\n// return gcd(b, a % b);\n// }\nlet ryan = '';//.map(Number).sort(function(a, b){return a - b})\nprocess.stdin.on('data', c => ryan += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = ryan.split(EOL);\n var n = lines[0]\n for(j = 1; j <= n; i++){\n var k = lines[j]\n console.log(k % 2 ==1 ? 'YES' : 'NO')\n break;;\n \n \n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = Number(lines[j])\n e = k / 2\n if(k % 2 === 0 && e % 2 != 1){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = Number(lines[j])\n e = k / 2\n if(k % 2 === 0 || e % 2 != 1){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = Number(lines[j])\n e = k / 2\n if(k % 2 === 0 || e % 2 == 1){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = Number(lines[j])\n if(k % 2 === 0){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(k % 2 === 0){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j <= n; j++){\n var k = lines[j]\n if(j % 2 === 0){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n if(n % 2 === 0){\n console.log('NO')\n }else{\n console.log('YES')\n }\n});"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n/)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n let one = BigInt(1)\r\n let two = BigInt(2)\r\n let zero = BigInt(0)\r\n for (let i = 0; i < t; ++i) {\r\n let n = BigInt(await nextString())\r\n while (n % two === zero) {\r\n n = n >> one\r\n }\r\n if (n > one) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\nmain()\r\n"}, {"source_code": "const nextString = (function() {\r\n const l = [], s = [], p = process.stdin\r\n p.setEncoding('utf8')\r\n p.on('readable', () => {\r\n for (let c; (c = p.read()) !== null;) {\r\n c = c.split(/\\r\\n|\\r|\\n/)\r\n for (let i = 0; i < c.length; ++i) {\r\n if (c[i].length > 0) {\r\n if (l.length > 0) {\r\n l.shift(1)(c[i])\r\n }\r\n else {\r\n s.push(c[i])\r\n }\r\n }\r\n }\r\n }\r\n })\r\n const f = r => {\r\n if (s.length > 0) {\r\n r(s.shift(1))\r\n }\r\n else {\r\n l.push(r)\r\n }\r\n }\r\n return () => new Promise(f)\r\n})()\r\n\r\nasync function main() {\r\n let t = +await nextString()\r\n for (let i = 0; i < t; ++i) {\r\n let n = +await nextString()\r\n while (n % 2 === 0) {\r\n n = Math.round(n / 2)\r\n }\r\n if (n > 1) {\r\n console.log('YES')\r\n }\r\n else {\r\n console.log('NO')\r\n }\r\n }\r\n process.exit(0)\r\n}\r\n\r\nmain()\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const n = +rl();\r\n if (n & (n - 1)) cl(\"Yes\");\r\n else cl(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const n = rl();\r\n if (n & (n - 1)) cl(\"Yes\");\r\n else cl(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var d = n + 1\r\n if (n % 2 !== 0) return console.log('YES')\r\n // if (!isPrime(n)) return console.log(n)\r\n console.log('NO')\r\n })\r\n\r\n}\r\n\r\nfunction sumDivisors(n, d) {\r\n var sum = 0;\r\n var nn = 1 + d\r\n while (!isPrime(nn)) nn++\r\n var nn2 = nn + d\r\n while (!isPrime(nn2)) nn2++\r\n\r\n console.log(nn2 * nn)\r\n}\r\n\r\nfunction isPrime(num) {\r\n for (var i = 2; i < num; i++)\r\n if (num % i === 0) return false;\r\n return num > 1;\r\n}"}], "src_uid": "f4958b4833cafa46fa71357ab1ae41af"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst preprocess = input => {\n let l = 0;\n let r = input.length;\n while (input[l] === 'o') {\n l++;\n }\n while (input[r - 1] === 'o') {\n r--;\n }\n return input.substring(l, r);\n};\n\n\nrl.question('', (input) => {\n const before = [];\n const after = [];\n let count = 0;\n let numw = 0;\n\n const rep = preprocess(input);\n for (let i = 0; i < rep.length; i++) {\n let c = rep[i];\n if (c === 'v') {\n count++;\n } else {\n numw += (count - 1);\n before.push(numw > 0 ? numw : 0);\n count = 0;\n while (c && c !== 'v') {\n c = rep[++i];\n }\n --i;\n }\n }\n count = 0;\n numw = 0;\n for (let i = 0; i < rep.length; i++) {\n let c = rep[rep.length - i - 1];\n if (c === 'v') {\n count++;\n } else {\n numw += (count - 1);\n after.push(numw > 0 ? numw : 0);\n count = 0;\n while (c && c !== 'v') {\n i += 1;\n c = rep[rep.length - i - 1];\n }\n --i;\n }\n }\n\n const ogroup = rep.split('v').filter(c => c !== '').map(group => group.length);\n\n let res = 0;\n for (let i = 0; i < before.length; i++) {\n res += (ogroup[i] * before[i] * after[after.length - 1 - i]);\n }\n console.log(res);\n\n rl.close();\n});\n", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.question('', (input) => {\n const before = [];\n const after = [];\n let count = 0;\n let numw = 0;\n\n let l = 0;\n let r = input.length;\n while (input[l] === 'o') {\n l++;\n }\n while (input[r - 1] === 'o') {\n r--;\n }\n\n const rep = input.substring(l, r);\n for (let i = 0; i < rep.length; i++) {\n let c = rep[i];\n if (c === 'v') {\n count++;\n } else {\n numw += (count - 1);\n before.push(numw > 0 ? numw : 0);\n count = 0;\n while (c && c !== 'v') {\n c = rep[++i];\n }\n --i;\n }\n }\n count = 0;\n numw = 0;\n for (let i = 0; i < rep.length; i++) {\n let c = rep[rep.length - i - 1];\n if (c === 'v') {\n count++;\n } else {\n numw += (count - 1);\n after.push(numw > 0 ? numw : 0);\n count = 0;\n while (c && c !== 'v') {\n i += 1;\n c = rep[rep.length - i - 1];\n }\n --i;\n }\n }\n\n const ogroup = rep.split('v').filter(c => c !== '').map(group => group.length);\n\n let res = 0;\n for (let i = 0; i < before.length; i++) {\n res += (ogroup[i] * before[i] * after[after.length - 1 - i]);\n }\n console.log(res);\n\n rl.close();\n});\n"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.question('', (input) => {\n const before = [];\n const after = [];\n const rep = input.split('v');\n let count = 0;\n rep.forEach((c) => {\n if (c === '') {\n count++\n } else {\n before.push((count - 1) * c.length);\n }\n });\n count = 0;\n for (let i = rep.length - 1; i >= 0 ; i--) {\n let c = rep[i];\n if (c === '') {\n count++\n } else {\n after.push(count - 1);\n }\n }\n\n let res = 0;\n for (let i = 0; i < before.length; i++) {\n res += (before[i] * after[after.length - 1 - i]);\n }\n console.log(res);\n\n rl.close();\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nrl.question('', (input) => {\n const before = [];\n const after = [];\n const rep = input.split('v');\n let count = 0;\n rep.forEach((c) => {\n if (c === '') {\n count++\n } else {\n before.push((count - 1) * c.length);\n }\n });\n count = 0;\n for (let i = rep.length - 1; i >= 0 ; i--) {\n let c = rep[i];\n if (c === '') {\n count++\n } else {\n after.push(count - 1);\n }\n }\n\n let res = 0;\n for (let i = 0; i < before.length; i++) {\n res += (before[i] * after[after.length - 1 - i]);\n }\n if (res <= 0) {\n console.log(0);\n } else {\n console.log(res);\n }\n\n rl.close();\n});\n"}], "src_uid": "6cc6db6f426bb1bce59f23bfcb762b08"} {"source_code": "var lines = parseInt(readline());\r\n\r\nvar steps = new Array(1000);\r\nsteps[0] = 0;\r\nfor (var i = 1; i < 1000; i++) {\r\n if (steps[i - 1] != undefined) {\r\n var step = steps[i - 1];\r\n for (var j = 1; j <= i; j++) {\r\n var inc = Math.floor(i / j);\r\n if (\r\n i + inc - 1 < 1000 &&\r\n (steps[i + inc - 1] == undefined || steps[i + inc - 1] > step + 1)\r\n )\r\n steps[i + inc - 1] = step + 1;\r\n }\r\n }\r\n}\r\n\r\nfor (var i = 0; i < lines; i++) {\r\n var line = readline().split(\" \");\r\n var n = parseInt(line[0]);\r\n var k = parseInt(line[1]);\r\n var b = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n var c = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\n var weights = [];\r\n for (var j = 0; j < b.length; j++) {\r\n weights.push([c[j], steps[b[j] - 1]]);\r\n }\r\n\r\n weights.sort((a, b) => b[0] / (b[1] + 0.00001) - a[0] / (a[1] + 0.00001));\r\n var dict = {};\r\n print(best(dict, weights, k, 0));\r\n}\r\n\r\nfunction best(dict, w, k, i, opt) {\r\n if (i >= w.length) return 0;\r\n if (dict[k + \",\" + i] != undefined) return dict[k + \",\" + i];\r\n var take = 0;\r\n opt = opt || 0;\r\n if (w[i][1] <= k)\r\n take = best(dict, w, k - w[i][1], i + 1, opt - w[i][0]) + w[i][0];\r\n if (opt > take) console.log(take, opt);\r\n take = Math.max(take, opt);\r\n if (w[i][1] == 0) {\r\n dict[k + \",\" + i] = take;\r\n return take;\r\n }\r\n\r\n var bestSub = 0;\r\n var kTemp = k;\r\n for (var j = i + 1; j < w.length && kTemp > 0; j++) {\r\n if (kTemp >= w[j][1]) bestSub += w[j][0];\r\n else bestSub += Math.floor((kTemp * w[j][0]) / w[j][1], take);\r\n kTemp -= w[j][1];\r\n }\r\n if (bestSub <= take) {\r\n dict[k + \",\" + i] = take;\r\n return take;\r\n }\r\n\r\n take = Math.max(best(dict, w, k, i + 1), take);\r\n dict[k + \",\" + i] = take;\r\n return take;\r\n}\r\n", "positive_code": [{"source_code": "var pre=[];\r\nfor(var i=0;i<=2000;i++){\r\n pre[i]=10000000;\r\n}\r\npre[0]=0;\r\npre[1]=0;\r\n\r\nfor(var i=1;i<=1000;i++){\r\n for(var j=1;j<=1000;j++){\r\n var next=i+Math.floor(i/j);\r\n pre[next]= Math.min(pre[next],pre[i]+1);\r\n }\r\n}\r\n\r\nvar t=readline();\r\nwhile(t--){\r\n var temp=readline().split(\" \").map(x => parseInt(x));\r\n var n=temp[0];\r\n var k=temp[1];\r\n \r\n var brr=readline().split(\" \").map(x => parseInt(x));\r\n var crr=readline().split(\" \").map(x => parseInt(x));\r\n \r\n for(var i=0;i a + b, 0));\r\n var dp=[];\r\n for(var i=0;i<=k;i++){\r\n dp[i]=0;\r\n }\r\n \r\n for(var i=0;i=brr[i];j--){\r\n dp[j]=Math.max(dp[j],crr[i]+dp[j-brr[i]]);\r\n }\r\n }\r\n print(dp[k]);\r\n \r\n}"}, {"source_code": "var pre=[];\r\nfor(var i=0;i<=2000;i++){\r\n pre[i]=10000000;\r\n}\r\npre[0]=0;\r\npre[1]=0;\r\n\r\nfor(var i=1;i<=1000;i++){\r\n for(var j=1;j<=1000;j++){\r\n var next=i+Math.floor(i/j);\r\n pre[next]= Math.min(pre[next],pre[i]+1);\r\n }\r\n}\r\n\r\nvar t=readline();\r\nwhile(t-- >0){\r\n var temp=readline().split(\" \").map(x => parseInt(x));\r\n var n=temp[0];\r\n var k=temp[1];\r\n k=Math.min(k,15000);\r\n var brr=readline().split(\" \").map(x => parseInt(x));\r\n var crr=readline().split(\" \").map(x => parseInt(x));\r\n \r\n for(var i=0;i=brr[i];j--){\r\n dp[j]=Math.max(dp[j],crr[i]+dp[j-brr[i]]);\r\n }\r\n }\r\n print(dp[k]);\r\n \r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\n const dp = Array(1001).fill(Infinity)\n dp[1] = 0\n for (let i = 1; i <= 1000; i++) {\n for (let j = 1; j <= i; j++) {\n const d = Math.floor(i / j)\n if (d <= 0) break\n const other = i + d\n if (other < dp.length) {\n dp[other] = Math.min(dp[other], dp[i] + 1)\n }\n }\n }\n // console.log(dp.join(','))\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const c = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr, c) {\n// console.log(arr.map(x => dp[x]))\n let prev\n for (let i = 0; i < arr.length; i++) {\n const f = Array(12 * arr.length + 1).fill(0)\n const cost = dp[arr[i]]\n for (let j = 0; j <= 12 * arr.length; j++) {\n if (i) {\n f[j] = j < cost\n ? prev[j] : Math.max(prev[j - cost] + c[i], prev[j])\n } else {\n f[j] = j < cost ? 0 : c[i]\n }\n }\n prev = f\n// console.log(cost, c[i], prev)\n }\n return prev[Math.min(k, 12 * arr.length)]\n}\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst N = 1001;\r\n\r\nfunction countSetBits (n) {\r\n\tlet cnt = 0;\r\n\tfor (let i = 0; i < 10; i++) {\r\n\t\tcnt += (n & 1 << i) > 0;\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\t\tconst b = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tconst d = Array(N).fill(100);\r\n\t\td[1] = 0;\r\n\t\tfor (let i = 1; i < N; i++) {\r\n\t\t\tfor (let x = 1; x <= i; x++) {\r\n\t\t\t\tconst nxt = i + Math.floor(i/x);\r\n\t\t\t\tif (nxt < N) {\r\n\t\t\t\t\td[nxt] = Math.min(d[nxt], d[i] + 1); \r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst w = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tw[i] = d[b[i]];\r\n\t\t}\r\n\r\n\t\tk = Math.min(k, 12*n);\r\n\t\tconst dp = Array.from(Array(n+1), _ => Array(k+1).fill(0));\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tfor (let j = 0; j <= k; j++) {\r\n\t\t\t\tdp[i][j] = dp[i-1][j];\r\n\t\t\t\tif (j - w[i-1] >= 0) {\r\n\t\t\t\t\tdp[i][j] = Math.max(dp[i][j], dp[i-1][j-w[i-1]] + c[i-1]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(dp[n][k]);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nconst N = 1001;\r\n\r\nfunction countSetBits (n) {\r\n\tlet cnt = 0;\r\n\tfor (let i = 0; i < 10; i++) {\r\n\t\tcnt += (n & 1 << i) > 0;\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\t\tconst b = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tconst d = Array(N).fill(100);\r\n\t\td[1] = 0;\r\n\t\tfor (let i = 1; i < N; i++) {\r\n\t\t\tfor (let x = 1; x <= i; x++) {\r\n\t\t\t\tconst nxt = i + Math.floor(i/x);\r\n\t\t\t\td[nxt] = Math.min(d[nxt], d[i] + 1); \r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst w = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tw[i] = d[b[i]];\r\n\t\t}\r\n\r\n\t\tk = Math.min(k, 20000);\r\n\t\tconst dp = Array.from(Array(n+1), _ => Array(k+1).fill(0));\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tfor (let j = 0; j <= k; j++) {\r\n\t\t\t\tdp[i][j] = dp[i-1][j];\r\n\t\t\t\tif (j - w[i-1] >= 0) {\r\n\t\t\t\t\tdp[i][j] = Math.max(dp[i][j], dp[i-1][j-w[i-1]] + c[i-1]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(dp[n][k]);\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\n const dp = Array(1001).fill(Infinity)\n dp[1] = 0\n for (let i = 1; i <= 1000; i++) {\n for (let j = 1; j <= i; j++) {\n const d = Math.floor(i / j)\n if (d <= 0) break\n const other = i + d\n if (other < dp.length) {\n dp[other] = Math.min(dp[other], dp[i] + 1)\n }\n }\n }\n // console.log(dp.join(','))\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const c = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr, c) {\n// console.log(arr.map(x => dp[x]))\n let prev\n for (let i = 0; i < arr.length; i++) {\n const f = Array(12 * arr.length + 1).fill(0)\n const cost = dp[arr[i]]\n for (let j = 0; j <= 12 * arr.length; j++) {\n if (i) {\n f[j] = j < cost\n ? prev[j] : Math.max(prev[j - cost] + c[i], prev[j])\n } else {\n f[j] = j < cost ? 0 : c[i]\n }\n }\n prev = f\n// console.log(cost, c[i], prev)\n }\n return prev[k]\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\n const dp = Array(1001).fill(Infinity)\n dp[1] = 0\n for (let i = 1; i <= 1000; i++) {\n for (let j = 1; j <= i; j++) {\n const d = Math.floor(i / j)\n if (d <= 0) break\n const other = i + d\n dp[other] = Math.min(dp[other], dp[i] + 1)\n }\n }\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, k] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const c = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, k, arr, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, k, arr, c) {\n const sorted = arr.map((x, i) => ({ i, cost: dp[x], point: c[i] }))\n .sort((a, b) => {\n // p1 / c1 > p2 / c2\n return a.cost * b.point - b.cost * a.point\n })\n// console.log(arr.map(x => dp[x]))\n let ans = 0\n let now = 0\n let i = 0\n while (now < k && i < sorted.length) {\n if (now + sorted[i].cost <= k) {\n now += sorted[i].cost\n ans += sorted[i].point\n }\n i++\n }\n return ans\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = 1//+lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n output[i] = solve(n, str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str) {\n let now = { val: 0 }\n let head = now\n for (let i = 0; i < str.length; i++) {\n const item = { val: i + 1 }\n if (str[i] === 'L') {\n if (now.prev) {\n now.prev.next = item\n item.prev = now.prev\n item.next = now\n now.prev = item\n } else {\n now.prev = item\n item.next = now\n head = item\n }\n } else {\n if (now.next) {\n now.next.prev = item\n item.next = now.next\n now.next = item\n item.prev = now\n } else {\n now.next = item\n item.prev = now\n }\n }\n now = item\n }\n const ans = Array(str.length)\n let p = 0\n while (head) {\n ans[p++] = head.val\n head = head.next\n }\n // const ans = [0]\n // let p = 0\n // for (let i = 0; i < str.length; i++) {\n // if (str[i] === 'L') {\n // ans.splice(p, 0, i + 1)\n // } else {\n // ans.splice(p + 1, 0, i + 1)\n // p = p + 1\n // }\n // }\n return ans.join(' ')\n}\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction countSetBits (n) {\r\n\tlet cnt = 0;\r\n\tfor (let i = 0; i < 10; i++) {\r\n\t\tcnt += (n & 1 << i) > 0;\r\n\t}\r\n\treturn cnt;\r\n}\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [n, k] = rna();\r\n\t\tconst b = rna();\r\n\t\tconst c = rna();\r\n\r\n\t\tconst w = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tw[i] = Math.floor(Math.log2(b[i])) + countSetBits(b[i]) - 1;\r\n\t\t\t//console.log({i}, b[i], w[i], countSetBits(b[i]));\r\n\t\t}\r\n\r\n\t\tk = Math.min(20000, k);\r\n\t\tconst dp = Array.from(Array(n+1), _ => Array(k+1).fill(0));\r\n\t\tfor (let i = 1; i <= n; i++) {\r\n\t\t\tfor (let j = 0; j <= k; j++) {\r\n\t\t\t\tdp[i][j] = dp[i-1][j];\r\n\t\t\t\tif (j - w[i-1] >= 0) {\r\n\t\t\t\t\tdp[i][j] = Math.max(dp[i][j], dp[i-1][j-w[i-1]] + c[i-1]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconsole.log(dp[n][k]);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var lines = parseInt(readline());\r\n\r\nvar steps = new Array(1000);\r\nsteps[0] = 0;\r\nfor (var i = 1; i < 1000; i++) {\r\n if (steps[i - 1] != undefined) {\r\n var step = steps[i - 1];\r\n for (var j = 1; j <= i; j++) {\r\n var inc = Math.floor(i / j);\r\n if (\r\n i + inc - 1 < 1000 &&\r\n (steps[i + inc - 1] == undefined || steps[i + inc - 1] > step + 1)\r\n )\r\n steps[i + inc - 1] = step + 1;\r\n }\r\n }\r\n}\r\n\r\nfor (var i = 0; i < lines; i++) {\r\n var line = readline().split(\" \");\r\n var n = parseInt(line[0]);\r\n var k = parseInt(line[1]);\r\n var b = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n var c = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\n var weights = [];\r\n for (var j = 0; j < b.length; j++) {\r\n weights.push([c[j], steps[b[j] - 1]]);\r\n }\r\n\r\n weights.sort((a, b) => b[0] / (b[1] + 0.00001) - a[0] / (a[1] + 0.00001));\r\n print(best(weights, k, 0));\r\n}\r\n\r\nfunction best(w, k, i) {\r\n if (i >= w.length) return 0;\r\n var take = 0;\r\n if (w[i][1] <= k) take = best(w, k - w[i][1], i + 1) + w[i][0];\r\n if (w[i][1] == 0) return take;\r\n\r\n var bestSub = 0;\r\n var kTemp = k;\r\n for (var j = i + 1; j < w.length && kTemp > 0; j++) {\r\n if (kTemp >= w[j][1]) bestSub += w[j][0];\r\n else bestSub += Math.ceil(w[j][0] / w[j][1]);\r\n kTemp -= w[j][1];\r\n }\r\n if (bestSub <= take) return take;\r\n return Math.max(best(w, k, i + 1), take);\r\n}\r\n"}, {"source_code": "var lines = parseInt(readline());\r\n\r\nvar steps = new Array(1000);\r\nsteps[0] = 0;\r\nfor (var i = 1; i < 1000; i++) {\r\n if (steps[i - 1] != undefined) {\r\n var step = steps[i - 1];\r\n for (var j = 1; j <= i; j++) {\r\n var inc = Math.floor(i / j);\r\n if (\r\n i + inc - 1 < 1000 &&\r\n (steps[i + inc - 1] == undefined || steps[i + inc - 1] > step + 1)\r\n )\r\n steps[i + inc - 1] = step + 1;\r\n }\r\n }\r\n}\r\n\r\nfor (var i = 0; i < lines; i++) {\r\n var line = readline().split(\" \");\r\n var n = parseInt(line[0]);\r\n var k = parseInt(line[1]);\r\n var b = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n var c = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\n var weights = [];\r\n for (var j = 0; j < b.length; j++) {\r\n weights.push([c[j], steps[b[j] - 1]]);\r\n }\r\n\r\n weights.sort((a, b) => b[0] / (b[1] + 0.00001) - a[0] / (a[1] + 0.00001));\r\n print(best(weights, k, 0));\r\n}\r\n\r\nfunction best(w, k, i) {\r\n if (i >= w.length || k == 0) return 0;\r\n var take = 0;\r\n if (w[i][1] <= k) take = best(w, k - w[i][1], i + 1) + w[i][0];\r\n if (\r\n w[i][1] == 0 ||\r\n (i < w.length - 2 && k > w[i + 1][1] + w[i + 2][1]) ||\r\n w.reduce((a, b) => a + b[1], 0) <= k\r\n )\r\n return take;\r\n var bestSub = 0;\r\n var kTemp = k;\r\n for (var j = i + 1; j < w.length && kTemp > 0; j++) {\r\n bestSub += w[j][0];\r\n kTemp -= w[j][1];\r\n }\r\n if (bestSub <= take) return take;\r\n return Math.max(best(w, k, i + 1), take);\r\n}\r\n"}], "src_uid": "c4929ec631caae439ccb9bc6882ed816"} {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\nvar arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\n\nvar vs = Array(n);\nvar solve = function(k)\n{\n for (var i = 0; i < n; i ++)\n {\n vs[i]=(v[i] + (i+1)*k);\n }\n vs.sort(function(a,b){return a-b;});\n // print(vs);\n var mins = 0;\n for (var i = 0; i < k; i ++)\n {\n mins += vs[i];\n }\n return mins;\n}\nvar maxk = {};\nvar low = 0;\nvar up = n;\nwhile(true)\n{\n var k = parseInt((low+up)/2);\n var val = solve(k);\n // print(low,k,up);\n //print(k, val);\n if (val <= s)\n {\n maxk[k] = val;\n }\n if (up-low == 0)\n {\n k = 0;\n for(var key in maxk)\n {\n if (parseInt(key) >= k)\n {\n // print(key, maxk[key]);\n k = key;\n val = maxk[k];\n }\n }\n print(k, val);\n break;\n }\n\n if (val <= s)\n {\n low = k;\n if (up-low==1)\n {\n low ++\n }\n }\n else\n {\n up = k;\n }\n}\n", "positive_code": [{"source_code": "function cmp(a,b)\n{\n return a-b;\n}\n\nvar s=readline().split(' ')\nvar n=+s[0]\nvar budget=+s[1]\nvar a=readline().split(' ').map(function(x){return +x;})\nvar l=0;\nvar r=n+1;\nif (r>1261){r=1261;}\nvar x=0;\nwhile(l+1+x);\nvar n = str[0];\nvar S = str[1];\nvar arr = readline().split(\" \").map(x=>+x);\nvar sum = [];\nvar ans =0;\n\nvar l=0,r=n;\nwhile(l != r){\n\tvar mid = (l+r+1)>>1;\n\tvar ret = 0;\n\tfor(var i = 0; i < n; i++){\n\t\tsum[i] = arr[i]+mid*(i+1);\n\t}\n\tsum.sort(cmp);\n\tfor(var i=0; i < mid; i++){\n\t\tret += sum[i];\n\t}\n\tif(ret <= S){\n\t\tl = mid;\n\t\tans = ret;\n\t}\n\telse r = mid-1;\n}\nprint(l+\" \"+ans);\nfunction cmp(value1, value2){\n\treturn value1-value2;\n}"}, {"source_code": "var ns = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ns[0],s=ns[1];\nvar a =readline().trim().split(' ').map((x,i)=>[parseInt(x),i+1])\n\nvar k=1;\nvar somme=0;\nvar maxi=0;\nvar maxiK=0;\nvar l=1,r=n;\nwhile(l<=r){\n k=parseInt((l+r)/2)\n somme=0;\n a.sort((_a,_b)=>(_a[0]+k*_a[1])-(_b[0]+k*_b[1]))\n \n for(var i=0;is){\n r=k-1;\n }else{\n maxi=somme;\n maxiK=k;\n l = k+1;\n }\n\n \n}\nprint(maxiK,maxi)"}], "negative_code": [{"source_code": "var ns = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ns[0],s=ns[1];\nvar a =readline().trim().split(' ').map((x,i)=>[parseInt(x),i+1])\n\nvar k=1;\nvar somme;\nvar maxi=0;\nvar maxiK=0;\n\na.sort((_a,_b)=>(_a[0]+_a[1])-(_b[0]+_b[1]))\nwhile(k<=n){\n somme=0;\n var minDiff = 0;\n \n for(var i=0;i0){\n if((a[i][0]+(k+1)*a[i][1] -(a[i-1][0]+(k+1)*a[i-1][1]))<0){\n var x = [a[i][0],a[i][1]];\n a[i]=[a[i-1][0],a[i-1][1]];\n a[i-1]=x;\n }\n }\n }\n if(somme>s)\n break\n \n maxi=somme\n maxiK=k\n if(somme==s)\n break;\n k++;\n}\nprint(maxiK,maxi)"}, {"source_code": "var ns = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ns[0],s=ns[1];\nvar a =readline().trim().split(' ').map((x,i)=>[parseInt(x),i+1])\n\nvar k=1;\nvar somme;\nvar maxi=0;\nvar maxiK=0;\nvar need = true\nwhile(k<=n){\n somme=0;\n var minDiff = 0;\n if(need)\n a.sort((_a,_b)=>(_a[0]+k*_a[1])-(_b[0]+k*_b[1]))\n \n need = false\n for(var i=0;i0){\n if((a[i][0]+k*a[i][1] -(a[i-1][0]+k*a[i-1][1]))<0){\n need = true\n }\n }\n if(is)\n break\n \n maxi=somme\n maxiK=k\n if(somme==s)\n break;\n k++;\n}\nprint(maxiK,maxi)"}, {"source_code": "var ns = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ns[0],s=ns[1];\nvar a =readline().trim().split(' ').map((x,i)=>[parseInt(x),i+1])\n\nvar k=1;\nvar somme;\nvar maxi=0;\nvar maxiK=0;\nvar need = true\nwhile(k<=n){\n somme=0;\n var minDiff = 0;\n if(need)\n a.sort((_a,_b)=>(_a[0]+k*_a[1])-(_b[0]+k*_b[1]))\n \n need = false\n for(var i=0;i0){\n if((a[i][0]+k*a[i][1] -(a[i-1][0]+k*a[i-1][1]))<0){\n need = true\n }\n }\n if(i=s)\n break\n maxi=somme\n maxiK=k\n k++;\n}\nprint(maxiK,maxi)"}, {"source_code": "var ns = readline().trim().split(' ').map((x)=>parseInt(x))\nvar n=ns[0],s=ns[1];\nvar a =readline().trim().split(' ').map((x,i)=>[parseInt(x),i+1])\n\nvar k=1;\nvar somme;\nvar maxi=0;\nvar maxiK=0;\nvar need = true\nwhile(k<=n){\n somme=0;\n var minDiff = 0;\n if(need)\n a.sort((_a,_b)=>(_a[0]+k*_a[1])-(_b[0]+k*_b[1]))\n \n need = false\n for(var i=0;i0){\n if((a[i][0]+k*a[i][1] -(a[i-1][0]+k*a[i-1][1]))<0){\n need = true\n }\n }\n if(is)\n break\n maxi=somme\n maxiK=k\n k++;\n}\nprint(maxiK,maxi)"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\nvar arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\nvar tried = {};\nvar k = 0;\nvar lastK = 0;\nwhile (true)\n{\n // print(\"trying \"+k);\n var dp = Array(smax+1).fill(0);\n var dps = Array(smax+1).fill(0);\n for (var i = 0; i < n; i ++)\n {\n var vi = v[i] + (i+1)*k;\n for (var j = smax; j >= vi; j --)\n {\n dp[j] = Math.max(dp[j], dp[j-vi] + 1);\n dps[j] = Math.max(dps[j], dps[j-vi] + vi);\n }\n }\n // print(dp[smax]);\n // print(JSON.stringify(dp));\n if (k == dp[smax] || (tried[k] && k > dp[smax]))\n {\n print(dp[smax],dps[smax]);\n break;\n }\n tried[k] = true;\n var kk = k;\n k = parseInt((lastK + dp[smax])/2);//k+1;//dp[n][s];\n if (kk == k)\n {\n k ++;\n }\n lastK = kk;\n}\n// v.sort(function(a,b){return b-a;});\n\n"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\nvar arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\n\nvar vs = Array(n);\nvar solve = function(k)\n{\n for (var i = 0; i < n; i ++)\n {\n vs[i]=(v[i] + (i+1)*k);\n }\n vs.sort(function(a,b){return a-b;});\n // print(vs);\n var mins = 0;\n for (var i = 0; i < k; i ++)\n {\n mins += vs[i];\n }\n return mins;\n}\nvar maxk = {};\nvar low = 0;\nvar up = n;\nwhile(true)\n{\n var k = parseInt((low+up)/2);\n var val = solve(k);\n // print(low,k,up);\n if (val <= smax)\n {\n maxk[k] = val;\n }\n if (up-low == 0)\n {\n k = 0;\n for(var key in maxk)\n {\n if (key >= k)\n {\n k = key;\n val = maxk[k];\n }\n }\n print(k, val);\n break;\n }\n\n if (val <= smax)\n {\n low = k;\n if (up-low==1)\n {\n low ++\n }\n }\n else\n {\n up = k;\n }\n}"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\nvar arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\n\nvar vs = Array(n);\nvar solve = function(k)\n{\n for (var i = 0; i < n; i ++)\n {\n vs[i]=(v[i] + (i+1)*k);\n }\n vs.sort(function(a,b){return a-b;});\n // print(vs);\n var mins = 0;\n for (var i = 0; i < k; i ++)\n {\n mins += vs[i];\n }\n return mins;\n}\nvar maxk = {};\nvar low = 0;\nvar up = n;\nwhile(true)\n{\n var k = parseInt((low+up)/2);\n var val = solve(k);\n // print(low,k,up);\n if (val <= s)\n {\n maxk[k] = val;\n }\n if (up-low == 0)\n {\n k = 0;\n for(var key in maxk)\n {\n if (key >= k)\n {\n k = key;\n val = maxk[k];\n }\n }\n print(k, val);\n break;\n }\n\n if (val <= s)\n {\n low = k;\n if (up-low==1)\n {\n low ++\n }\n }\n else\n {\n up = k;\n }\n}"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\nvar arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\n\nvar vs = Array(n);\nvar solve = function(k)\n{\n for (var i = 0; i < n; i ++)\n {\n vs[i]=(v[i] + (i+1)*k);\n }\n vs.sort(function(a,b){return a-b;});\n // print(vs);\n var mins = 0;\n for (var i = 0; i < k; i ++)\n {\n mins += vs[i];\n }\n return mins;\n}\nvar maxk = {};\nvar low = 0;\nvar up = n;\nvar count = 0;\nwhile(true)\n{\n var k = parseInt((low+up)/2);\n var val = solve(k);\n // print(low,k,up);\n count ++;\n if (val <= smax)\n {\n maxk[k] = val;\n }\n if (up-low == 0)\n {\n k = 0;\n for(var key in maxk)\n {\n if (key > k)\n {\n k = key;\n val = maxk[k];\n }\n }\n print(k, val);\n break;\n }\n\n if (val <= smax)\n {\n low = k;\n if (up-low==1)\n {\n low ++\n }\n }\n else\n {\n up = k;\n }\n}\n"}, {"source_code": "var arr = readline().split(' ');\nvar n = parseInt(arr[0]);\nvar s = parseInt(arr[1]);\nvar smax = 0;\nvar v = [];\n// var arr = readline().split(' ');\nvar maxpossible = 0;\nfor (var i = 0; i < n; i ++)\n{\n var val = 100000;//parseInt(arr[i]);\n maxpossible += val + n*(i+1);\n v.push(val);\n}\nsmax = Math.min(s,maxpossible);\n\nvar vs = Array(n);\nvar solve = function(k)\n{\n for (var i = 0; i < n; i ++)\n {\n vs[i]=(v[i] + (i+1)*k);\n }\n vs.sort(function(a,b){return a-b;});\n // print(vs);\n var mins = 0;\n for (var i = 0; i < k; i ++)\n {\n mins += vs[i];\n }\n return mins;\n}\nvar maxk = {};\nvar low = 0;\nvar up = n;\nwhile(true)\n{\n var k = parseInt((low+up)/2);\n var val = solve(k);\n // print(low,k,up);\n //print(k, val);\n if (val <= s)\n {\n maxk[k] = val;\n }\n if (up-low == 0)\n {\n k = 0;\n for(var key in maxk)\n {\n if (parseInt(key) >= k)\n {\n // print(key, maxk[key]);\n k = key;\n val = maxk[k];\n }\n }\n print(k, val);\n break;\n }\n\n if (val <= s)\n {\n low = k;\n if (up-low==1)\n {\n low ++\n }\n }\n else\n {\n up = k;\n }\n}\n"}], "src_uid": "b1fd037d5ac6023ef3250fc487656db5"} {"source_code": "var minCost = function(airports, a, b) {\n if ( airports[ a ] === airports[ b ] ) {\n return 0;\n } else {\n return 1;\n }\n}\n\nvar input = readline().split( \" \" ).map( i => parseInt( i, 10 ) );\nvar a = input[ 1 ] - 1;\nvar b = input[ 2 ] - 1;\nvar airports = readline().split( \"\" );\nprint( minCost( airports, a, b) ); ", "positive_code": [{"source_code": "var functionVadic = function(str, b, e)\n {\n if (str[b] === str[e]) return 0;\n else return 1;\n }\nvar input1 = readline();\nvar input2 = readline();\ninput1 = input1.split(' ');\nprint(functionVadic(input2, +input1[1] - 1, +input1[2] - 1));"}, {"source_code": "function ansa(n,a,b,s){\n\n a -= 1;\n b -= 1;\n\n print(((s[a] - '0') ^ (s[b] - '0')));\n\n}\n\n\n\nvar line = readline().split(' ');\nfor(var i = 0 ; i < line.length ; i++) line[i] = parseInt(line[i]);\n\nvar str = readline();\n\nansa(line[0],line[1],line[2],str);\n"}, {"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var home = arr[1];\n var olympiad = arr[2];\n\n var airports = readline();\n\n if(airports[home - 1] == airports[olympiad - 1]) {\n print(0);\n }else {\n print(1);\n }\n \n \n}\n\nmain();"}, {"source_code": "function sa(a,b,data){\n \n if(data[a] == data[b]){\n return 0;\n } else {\n return 1;\n }\n \n \n }\n \n \n var f = readline().split(\" \").map(Number);\n var n = f[0];\n var a = f[1]-1;\n var b = f[2]-1;\n var data = readline();\n \n print(sa(a,b,data));"}], "negative_code": [{"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var home = arr[1];\n var olympiad = arr[2];\n\n var airports = readline();\n\n if(airports[home - 1] == airports[olympiad - 1]){\n print(0);\n }else {\n if (home == olympiad) {\n print(0);\n } else if (home < olympiad) {\n\n for (var i = home; i < olympiad; i++) {\n if (airports[i] == airports[home - 1]) {\n continue;\n }\n if (airports[i] != airports[home - 1]) {\n print(i - (home - 1));\n break;\n }\n }\n } else if(home > olympiad){\n for (var i = olympiad; i < home; i++) {\n if (airports[i] == airports[olympiad - 1]) {\n continue;\n }\n if (airports[i] != airports[olympiad - 1]) {\n print(i - (olympiad - 1));\n break;\n }\n }\n }\n }\n\n}\n\nmain();"}, {"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var home = arr[1];\n var olympiad = arr[2];\n\n var airports = readline();\n\n var r_route,\n l_route;\n \n var nr_route,\n nl_route,\n route;\n\n if(airports[home - 1] == airports[olympiad - 1]){\n print(0);\n }else {\n if (home == olympiad) {\n print(0);\n } else {\n for(var i = home;i0;j--){\n if (airports[j] == airports[home - 1]) {\n continue;\n }\n if (airports[j] != airports[home - 1]) {\n l_route = (home - 1) - j;\n break;\n }\n }\n\n nr_route = Number(r_route);\n nl_route = Number(l_route);\n route = Math.min(nr_route,nl_route);\n \n print(route);\n\n\n }\n }\n\n\n\n}\n\nmain();"}, {"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var home = arr[1];\n var olympiad = arr[2];\n\n var airports = readline();\n\n var r_route,\n l_route;\n\n if(airports[home - 1] == airports[olympiad - 1]){\n print(0);\n }else {\n if (home == olympiad) {\n print(0);\n } else {\n for(var i = home;i0;j--){\n if (airports[j] == airports[home - 1]) {\n continue;\n }\n if (airports[j] != airports[home - 1]) {\n l_route = (home - 1) - j;\n break;\n }\n }\n\n print(Math.min(r_route,l_route));\n\n\n }\n }\n\n\n\n}\n\nmain();"}, {"source_code": "function main() {\n\n var arr = readline().split(' ').map(Number);\n var n = arr[0];\n var home = arr[1];\n var olympiad = arr[2];\n\n var airports = readline();\n\n var r_route,\n l_route;\n\n if(airports[home - 1] == airports[olympiad - 1]){\n print(0);\n }else {\n if (home == olympiad) {\n print(0);\n } else {\n for(var i = home;i0;j--){\n if (airports[j] == airports[home - 1]) {\n continue;\n }\n if (airports[j] != airports[home - 1]) {\n l_route = (home - 1) - j;\n break;\n }\n }\n\n print(Math.min(Number(r_route),Number(l_route)));\n\n\n }\n }\n\n\n\n}\n\nmain();"}, {"source_code": "function sa(a,b,data){\n \n if(data[a] == data[b]){\n return 0;\n } else {\n var g = Number.MAX_VALUE;\n var t = Number.MAX_VALUE;\n for(var i=1;i= 0 && data[a-i]!== data[a]){\n g= i;\n break;\n }\n if(a+i = 0 && data[b-i]!== data[b]){\n t= i;\n break;\n }\n if(b+i = n) ? 'YES' : 'NO');\r\n}", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let t = readline();\r\n let [w, h, n] = t.split(' ');\r\n let ans = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n ans *= 2;\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n ans *= 2;\r\n }\r\n\r\n console.log(ans >= n ? 'yes' : 'no');\r\n\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst getNOf2Factors = (number) => {\n let nOf2Factors = 0;\n while (number % 2 === 0) {\n nOf2Factors++;\n number /= 2;\n }\n return nOf2Factors;\n};\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .map((line) => line.split(' '))\n .map(([w, h, n]) => {\n return Math.pow(2, getNOf2Factors(w) + getNOf2Factors(h)) >= n ? 'YES' : 'NO';\n })\n .join('\\n');\n};\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var found = false;\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var answer = 1;\n while(a % 2 === 0){\n answer *= 2;\n a /= 2;\n }\n while(b % 2 === 0){\n answer *= 2;\n b /= 2;\n }\n if(c <= answer){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i = 0; i < t; i++){\n\t\tlet [w, h, n] = nl.nums();\n\t\tlet a = 0;\n\t\tlet b = 0;\n\t\twhile(w%2 == 0) {\n\t\t\ta++;\n\t\t\tw = Math.round(w/2);\n\t\t}\n\t\twhile(h%2 == 0) {\n\t\t\tb++;\n\t\t\th = Math.round(h/2);\n\t\t}\n\t\tvar x = Math.pow(2, a) * Math.pow(2, b);\n\t\t\n\t\tans.push(x >= n);\n\t\t\n\t}\n\tconsole.log(ans.map(e => e?'YES':'NO').join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "const { EOL } = require('os')\r\nlet i = ''\r\nprocess.stdin.on('data', c => (i += c))\r\nprocess.stdin.on('end', () => {\r\n const lines = i.split(EOL).filter(line => line)\r\n console.log(processInput(lines))\r\n})\r\n\r\nconst getNOf2Factors = number => {\r\n let nOf2Factors = 0\r\n while (number % 2 === 0) {\r\n nOf2Factors++\r\n number /= 2\r\n }\r\n return nOf2Factors\r\n}\r\n\r\nconst processInput = lines => {\r\n return lines\r\n .slice(1)\r\n .map(line => line.split(' '))\r\n .map(([w, h, n]) =>\r\n Math.pow(2, getNOf2Factors(w) + getNOf2Factors(h)) >= n ? 'YES' : 'NO'\r\n )\r\n .join(EOL)\r\n}"}, {"source_code": "const cards = (w, h, n) => {\n let count = 0;\n let mul = w * h;\n while (mul % 2 == 0) {\n count++;\n mul = Math.floor(mul / 2);\n }\n return Math.pow(2, count) >= n;\n};\n\nconst main = () => {\n let test = parseInt(readline());\n while (test--) {\n const [w, h, n] = readline()\n .split(\" \")\n .map(s => parseInt(s));\n if (cards(w, h, n)) console.log(\"YES\");\n else console.log(\"NO\");\n }\n};\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map(string => string.trim());\n main();\n});\n\nconst readline = () => {\n return inputString[currentLine++];\n};\n"}, {"source_code": "// 1/13/21\r\n//https://codeforces.com/problemset/problem/1472/A\r\n\r\nconst readline = require(\"readline\");\r\nconst leScan = new readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n\tterminal: false\r\n});\r\n\r\nlet inputNum = 0;\r\nleScan.on(\"line\", (input) => {\r\n\tif (inputNum == 0)\r\n\t{\r\n\t\tinputNum = 1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tvar meetsN = calcPieces(...input.split(\" \"));\r\n\r\n\t\tif (meetsN)\r\n\t\t{\r\n\t\t\tconsole.log(\"YES\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tconsole.log(\"NO\");\r\n\t\t}\r\n\t}\r\n});\r\n\r\n/* If the paper we cut for the width will equal w, every value in w can be cut h times. Hence, the total cut is w*h.\r\n*/\r\nconst calcPieces = (w, h, n) => {\r\n\tlet numW = numCuts(+w);\r\n\tlet numH = numCuts(+h);\r\n\r\n\treturn numW * numH >= +n;\r\n}\r\n\r\n//A cut multiplies the paper amount by 2 since we're repeating it for every single piece of cut paper. Hence, 2^i.\r\n//As a demo, 1*2 = 2 paper, 2 paper each * 2 = 4 paper, 4 paper each * 2 = 8 paper... so on. It's exponential\r\nconst numCuts = (num) => {\r\n\tlet i;\r\n\r\n\tfor (i = 0; num % 2 == 0; i++)\r\n\t{\r\n\t\tnum = num / 2;\r\n\t}\r\n\r\n\treturn Math.pow(2, i);\r\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction getArray(str) {\n return str.split(' ').map(x => Number(x));\n}\n\nfunction getInt(str) {\n return Number(str);\n}\n\nfunction getStrArray(str) {\n return str.split(' ').map(x => x);\n}\n// ---------------------------------------\n\n\n\nfunction main() {\n let t = getInt(readline());\n while(t--) {\n let a = getStrArray(readline());\n let result = 1;\n while(a[0]%2 == 0) {\n result *=2;\n a[0] = a[0]/2;\n }\n\n while (a[1] % 2 == 0) {\n result *= 2;\n a[1] = a[1] / 2;\n }\n if(result >= a[2]) {\n console.log('YES');\n } else {\n console.log('NO');\n }\n }\n}"}, {"source_code": "const solve = (w, h, n) => {\r\n let cnt = 0;\r\n while (w % 2 == 0 || h % 2 == 0) {\r\n if (2 ** cnt >= n) return console.log('YES');\r\n if (w % 2 == 0) {\r\n w /= 2;\r\n cnt++;\r\n }\r\n if (h % 2 == 0) {\r\n h /= 2;\r\n cnt++;\r\n }\r\n }\r\n if (2 ** cnt >= n) return console.log('YES');\r\n console.log('NO');\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n let data = input[i];\r\n solve(data[0], data[1], data[2]);\r\n i++;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tlet [a, b, c] = readLine().split(' ').map(Number);\n\t\tif (a % 2 !== 0 && b % 2 !== 0 && c > 1) {\n\t\t\tconsole.log('NO');\n\t\t} else {\n\t\t\tlet count = 1;\n\t\t\twhile ((a && a % 2 === 0) || (b && b % 2 === 0)) {\n\t\t\t\tcount *= 2;\n\t\t\t\tif (a % 2 === 0) a = Math.floor(a / 2);\n\t\t\t\telse if (b % 2 === 0) b = Math.floor(b / 2);\n\t\t\t}\n\t\t\tif (count >= c) console.log('YES');\n\t\t\telse console.log('NO');\n\t\t}\n\t}\n}\n"}, {"source_code": "function solve(input) {\r\n // TYPE YOUR BUGS HERE...\r\n let [w, h, n] = input.split(' ').map(i => parseInt(i));\r\n let res = 1;\r\n while (w % 2 === 0) {\r\n res *= 2\r\n w = w / 2;\r\n }\r\n\r\n while (h % 2 === 0) {\r\n res *= 2\r\n h = h / 2;\r\n }\r\n\r\n console.log(res >= n ? 'YES' : 'NO');\r\n}\r\n\r\n/** =========== DEFAULT FORMAT ============== \r\n * \r\n * use this format to solve problem that use 1 line input per testcase \r\n * \r\n**/\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\n\r\nlet i = 1;\r\nlet t = 0;\r\nreadline.on('line', line => {\r\n if (i == 1) {\r\n // number of test case\r\n t = parseInt(line) \r\n i++;\r\n } else {\r\n solve(line)\r\n if (i <= t) i++\r\n else readline.close()\r\n }\r\n});\r\n\r\n/** \r\n * =========== DEFAULT FORMAT END ==============\r\n * */ \r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n // var n = Number(readline());\r\n var [w, h, n] = readline().split(' ').map(x => Number(x));\r\n if (n === 1) return console.log('YES')\r\n var ans = 1\r\n var pow = 1\r\n var i = w * h\r\n while (i % 2 !== 1) {\r\n ans += pow\r\n pow *= 2\r\n i = i / 2\r\n }\r\n // console.log(ans)\r\n\r\n if (ans >= n) return console.log('YES')\r\n\r\n console.log('NO')\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "let i = '';\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os');\r\n const lines = i.split(EOL);\r\n\r\n const t = parseInt(lines[0]);\r\n\r\n for (let i = 1; i <= t; i++) {\r\n const split = lines[i].split(' ');\r\n const w = parseInt(split[0]);\r\n const h = parseInt(split[1]);\r\n const n = parseInt(split[2]);\r\n\r\n console.log(solve(w, h, n));\r\n }\r\n});\r\n\r\nfunction solve(w, h, n) {\r\n let count = 1;\r\n\r\n while (w % 2 === 0 && count < n) {\r\n count *= 2;\r\n w = Math.floor(w / 2);\r\n }\r\n\r\n while (h % 2 === 0 && count < n) {\r\n count *= 2;\r\n h = Math.floor(h / 2);\r\n }\r\n\r\n return count >= n ? 'YES' : 'NO';\r\n}\r\n"}, {"source_code": "var t = readline();\r\nfor(var i=0;i=n){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "test = readline();\r\nwhile (test--) {\r\n input = readline()\r\n .split(\" \")\r\n .map((x) => +x);\r\n h = input[0];\r\n w = input[1];\r\n n = input[2];\r\n result = 1;\r\nwhile (h % 2===0) {\r\n h /= 2;\r\n result*=2;\r\n }\r\n while (w % 2===0) {\r\n w /= 2;\r\n result*=2;\r\n }\r\n print(result >= n ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "var t = Number(readline());\r\n\r\n\r\nwhile (t--) {\r\n var a = readline().split(\" \");\r\n var w = Number(a[0]);\r\n var h = Number(a[1]);\r\n var n = Number(a[2]);\r\n var pieces = 1;\r\n\r\n while (h % 2 == 0) {\r\n h /= 2;\r\n pieces *= 2;\r\n } \r\n while (w % 2 == 0) {\r\n w /= 2;\r\n pieces *= 2;\r\n } \r\n pieces >= n ? print(\"YES\") : print(\"NO\");\r\n\r\n }\r\n \r\n"}, {"source_code": "\r\nt = readline()\r\n\r\nwhile(t--) {\r\n\ta = readline().split(' ').map(x => +x)\r\n\tw = a[0]\r\n\th = a[1]\r\n\tn = a[2]\r\n\r\n\tans = 1\r\n\t\r\n\tif (ans>=n) {\r\n\t\tprint('YES')\r\n\t}\r\n\telse {\r\n\t\twhile (w % 2 == 0) {\t\t\r\n\t\t\tans*=2\r\n\t\t\tw/=2\r\n\t\t}\r\n\r\n\t\twhile(h%2==0){\r\n\t\t\tans*=2\r\n\t\t\th/=2\r\n\t\t}\r\n\r\n\t\tif(ans>=n){\r\n\t\t\tprint('YES')\r\n\t\t}\r\n\t\telse{\r\n\t\t\tprint('NO')\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nfor(let i = 0; i < iter; i++){\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n let w = input[0];\r\n let h = input[1];\r\n let n = input[2];\r\n let counter = 1;\r\n\r\n while(w % 2 === 0){\r\n w /= 2;\r\n counter *= 2;\r\n }\r\n while(h % 2 === 0){\r\n h /= 2;\r\n counter *= 2;\r\n }\r\n\r\n if(counter >= n){\r\n print(\"YES\");\r\n } else {\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n /***********/\r\n // string array to number array\r\n const numArray = (a) => a.split(\" \").map((line) => +line);\r\n const isEven = (a) => (a % 2 == 0 && a > 1 ? true : false);\r\n\r\n // number of test case input\r\n const tc = readLine();\r\n\r\n // input line\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = numArray(readLine());\r\n // const ln2 = readLine();\r\n // const ln3 = readLine();\r\n // const ln4 = readLine();\r\n // const ln5 = readLine();\r\n cards(ln1);\r\n }\r\n /************************Solution****************************************/\r\n function cards([w, h, n]) {\r\n let c = 1;\r\n\r\n while (w % 2 == 0) {\r\n w /= 2;\r\n c *= 2;\r\n }\r\n while (h % 2 == 0) {\r\n h /= 2;\r\n c *= 2;\r\n }\r\n\r\n console.log(c >= n || n == 1 ? \"Yes\" : \"No\");\r\n // console.log(c, n);\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n let [w, h, n] = d.split(' ').map(Number);\r\n let ans = 1;\r\n let inc = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n ans += inc;\r\n\r\n if (inc === 1) {\r\n inc++;\r\n }\r\n else {\r\n inc *= 2;\r\n }\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n ans += inc;\r\n\r\n if (inc === 1) {\r\n inc++;\r\n }\r\n else {\r\n inc *= 2;\r\n }\r\n }\r\n\r\n if (ans >= n) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var found = false;\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var answer = 1;\n while(a % 2 === 0){\n answer *= 2;\n a /= 2;\n }\n while(b % 2 === 0){\n answer *= 2;\n b /= 2;\n }\n if(c <= answer){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n});"}, {"source_code": "const write = out => process.stdout.write(out + `\\n`);\n\nconst mainCode = ([l1]) => {\n\tlet [w, h, n] = l1.split(' ').map(Number);\n\tlet total = 1;\n\n\tlet factor = 1;\n\n\twhile (w % 2 == 0 || h % 2 == 0) {\n\t\tlet add = 0;\n\t\tif (w % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\tw /= 2;\n\t\t}\n\t\tif (h % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\th /= 2;\n\t\t}\n\n\t\ttotal += add;\n\t}\n\n\tconst answer = total >= n ? 'YES' : 'NO';\n\twrite(answer)\n}\n\nlet counter = 0;\nlet t = 0;\nconst t_size = 1;\n\nconst cases = [];\n\nconst lineInterpreter = (line) => {\n\tif (counter == 0) t = Number(line)\n\telse {\n\t\tconst cursor = (counter - 1) % t_size\n\t\tif (cursor == 0) cases.push([line])\n\t\telse cases[cases.length - 1].push(line)\n\t}\n\n\tif (counter == (t * t_size)) {\n\t\tcases.map(_case => mainCode(_case))\n\t}\n\tcounter++\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n\tinputString.map(line => lineInterpreter(line));\n});\n\n\n\n\n// For personal use\n\n// const sample = `5\n// 2 2 3\n// 3 3 2\n// 5 10 2\n// 11 13 1\n// 1 4 4`;\n// sample.split(`\\n`).map(line => lineInterpreter(line));"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// var ar = readline().split(' ').map(n => parseInt(n));\r\n\r\n//-----------main function-----------\r\n \r\nfunction main() {\r\n\r\n var t = parseInt(readline());\r\n\r\n while (t--) {\r\n var ar = readline().split(' ').map(n => parseInt(n));\r\n var w = ar[0];\r\n var h = ar[1];\r\n var n = ar[2];\r\n var total = 1;\r\n\r\n while (w % 2 == 0) {\r\n total *= 2;\r\n w = w / 2;\r\n }\r\n while (h % 2 == 0) {\r\n total *= 2;\r\n h = h / 2;\r\n }\r\n\r\n // total = hn + wn;\r\n\r\n if (total >= n) {\r\n print('YES');\r\n } else {\r\n print('NO');\r\n }\r\n\r\n }\r\n\r\n}\r\n"}, {"source_code": "const { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const sheet = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n\r\n for(let idx in sheet) {\r\n let piece = 1;\r\n let w = sheet[idx][0];\r\n let h = sheet[idx][1];\r\n let friend = sheet[idx][2];\r\n\r\n while(w % 2 === 0) {\r\n piece *= 2;\r\n w /= 2;\r\n }\r\n\r\n while(h % 2 === 0) {\r\n piece *= 2;\r\n h /= 2;\r\n }\r\n\r\n if(piece >= friend) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar W = nextInt();\r\n\t\tvar H = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar wcount = 1;\r\n\t\tvar hcount = 1;\r\n\t\twhile(W % 2 == 0){\r\n\t\t\twcount *= 2;\r\n\t\t\tW /= 2;\r\n\t\t}\r\n\t\twhile(H % 2 == 0){\r\n\t\t\thcount *= 2;\r\n\t\t\tH /= 2;\r\n\t\t}\r\n\t\tmyout((hcount * wcount >= N) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n // taking and assingn variables...\r\n let [w, h, n] = input[z++].split(' ').map(x=>Number(x));\r\n // intialing out counter variable which will count the division..\r\n let counter;\r\n counter = 0;\r\n // chacking how many times can we divide width and height\r\n while (w % 2 != 1) {\r\n w /= 2;\r\n counter++;\r\n }\r\n while (h % 2 != 1) {\r\n h /= 2;\r\n counter++;\r\n }\r\n // checking the edge cases and making our final output\r\n console.log((Math.pow(2,counter) >= n || n == 1) ? \"YES\": \"NO\");\r\n }\r\n}"}, {"source_code": "const { EOL } = require('os');\r\n\r\nlet input = '';\r\nprocess.stdin.on('data', data => input += data);\r\nprocess.stdin.on('end', main);\r\n\r\nfunction main() {\r\n const lines = input.split(EOL);\r\n for (let i = 1; i < lines.length - 1; i++) {\r\n let dim = lines[i].split(' ');\r\n canCut(+dim[0], +dim[1], +dim[2]);\r\n }\r\n}\r\n\r\nfunction canCut(w, h, n) {\r\n let sum = 1;\r\n while (sum < n) {\r\n if (w % 2 == 0) {\r\n w /= 2;\r\n sum *= 2;\r\n } else if (h % 2 == 0) {\r\n h /= 2;\r\n sum *= 2;\r\n } else {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n }\r\n console.log(\"YES\");\r\n return;\r\n}"}], "negative_code": [{"source_code": "var t = readline();\r\nfor(var i=0;i=n){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "test = readline();\r\nwhile (test--) {\r\n input = readline()\r\n .split(\" \")\r\n .map((x) => +x);\r\n h = input[0];\r\n w = input[1];\r\n n = input[2];\r\n result = 1;\r\nwhile (h % 2===0) {\r\n h /= 2;\r\n result+=2;\r\n }\r\n while (w % 2===0) {\r\n w /= 2;\r\n result+=2;\r\n }\r\n print(result >= n ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nfor(var i = 0; i < t; i++) {\r\n var input = readline().split(' ').map(Number);\r\n var area = input[0] * input[1];\r\n var n = input[2];\r\n var c = 0;\r\n \r\n while(area % 2 === 0) {\r\n c += 2;\r\n area /= 2;\r\n }\r\n \r\n \r\n print((c >= n) || (n === 1) ? 'YES' : 'NO');\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n /***********/\r\n // string array to number array\r\n const numArray = (a) => a.split(\" \").map((line) => +line);\r\n const isEven = (a) => (a % 2 == 0 && a > 1 ? true : false);\r\n\r\n // number of test case input\r\n const tc = readLine();\r\n\r\n // input line\r\n for (let i = 0; i < tc; i++) {\r\n const ln1 = numArray(readLine());\r\n // const ln2 = readLine();\r\n // const ln3 = readLine();\r\n // const ln4 = readLine();\r\n // const ln5 = readLine();\r\n cards(ln1);\r\n }\r\n /************************Solution****************************************/\r\n function cards([w, h, n]) {\r\n let c = 0;\r\n let s = w * h;\r\n\r\n while (isEven(s)) {\r\n c += 2;\r\n s /= 2;\r\n }\r\n if (!isEven(w) && !isEven(h)) c = 1;\r\n\r\n console.log(c >= n || n == 1 ? \"yes\" : \"no\");\r\n // console.log(c, n);\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const n = readLine();\r\n\r\n function isPossible([w, h, n]) {\r\n let output = 1;\r\n w = parseInt(w);\r\n h = parseInt(h);\r\n n = parseInt(n);\r\n // if (n == 1) return \"yes\";\r\n // if (w % 2 !== 0 && h % 2 !== 0) return \"no\";\r\n\r\n while (w % 2 === 0) {\r\n output *= w;\r\n w = w / 2;\r\n }\r\n while (h % 2 === 0) {\r\n output *= h;\r\n h = h / 2;\r\n }\r\n\r\n // console.log(w, h, n, output);\r\n return n <= output ? \"yes\" : \"no\";\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n console.log(isPossible(readLine().split(\" \")));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const n = readLine();\r\n\r\n function isPossible([w, h, n]) {\r\n let output = 0;\r\n w = parseInt(w);\r\n h = parseInt(h);\r\n n = parseInt(n);\r\n if (n == 1) return \"yes\";\r\n if (w % 2 !== 0 && h % 2 !== 0) return \"no\";\r\n\r\n while (w % 2 === 0) {\r\n output += w;\r\n w = w / 2;\r\n }\r\n while (h % 2 === 0) {\r\n output += h;\r\n h = h / 2;\r\n }\r\n\r\n // console.log(w, h, n, output);\r\n return n <= output ? \"yes\" : \"no\";\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n console.log(isPossible(readLine().split(\" \")));\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\n\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const n = readLine();\r\n\r\n function isPossible([w, h, n]) {\r\n let output = 0;\r\n w = parseInt(w);\r\n h = parseInt(h);\r\n n = parseInt(n);\r\n if (n == 1) return \"yes\";\r\n if (w % 2 !== 0 && h % 2 !== 0) return \"no\";\r\n\r\n if (w % 2 === 0) {\r\n output += w;\r\n }\r\n if (h % 2 === 0) {\r\n output += h;\r\n }\r\n return n <= output ? \"yes\" : \"no\";\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n console.log(isPossible(readLine().split(\" \")));\r\n }\r\n}\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n let [w, h, n] = d.split(' ').map(Number);\r\n let ans = 1;\r\n let incW = 1;\r\n let incH = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n ans += incW;\r\n\r\n if (incW === 1) {\r\n incW++;\r\n }\r\n else {\r\n incW *= 2;\r\n }\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n ans += incH;\r\n\r\n if (incH === 1) {\r\n incH++;\r\n }\r\n else {\r\n incH *= 2;\r\n }\r\n }\r\n\r\n if (ans >= n) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n let [w, h, n] = d.split(' ').map(Number);\r\n let ans = 1;\r\n let incW = 1;\r\n let incH = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n incW *= 2;\r\n ans += incW;\r\n incW++;\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n incH *= 2;\r\n ans += incH;\r\n incH++;\r\n }\r\n\r\n if (ans >= n) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "const readline = require('readline');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n terminal: false\r\n});\r\nlet c = 0;\r\n\r\nrl.on('line', (d) => {\r\n if (c === 0) {\r\n c++;\r\n return;\r\n }\r\n\r\n let [w, h, n] = d.split(' ').map(Number);\r\n let ans = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n ans++;\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n ans++;\r\n }\r\n\r\n ans **= 2;\r\n\r\n if (ans >= n) {\r\n console.log('YES');\r\n }\r\n else {\r\n console.log('NO');\r\n }\r\n\r\n c++;\r\n});\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var found = 0;\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n if(k[j] == 3){\n found++\n }\n if(j == n - 1){\n if(found >= 2){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n \n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var found = 0;\n for(var j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n if(k[j] == 3){\n found++\n }\n if(j == n){\n if(found >= 2){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n }\n \n});"}, {"source_code": "\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL); /*your input text, split by lines*/\n var s = 0\n var p = 0\n for(j = 1; j<= lines[0]; j++){\n var a = lines[j]\n var w = a[0]\n var h = a[1]\n var n = a[2]\n if(w % 2 === 0){\n s = w/2 * h \n p++\n }if(h % 2 === 0){\n s = w * h/2\n p++\n }\n if(p > n){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n});"}, {"source_code": "const write = out => process.stdout.write(out + `\\n`);\n\nconst mainCode = ([l1]) => {\n\tlet [w, h, n] = l1.split(' ').map(Number);\n\tlet total = 1;\n\n\tlet factor = 1;\n\n\twhile (w % 2 == 0 || h % 2 == 0) {\n\t\tlet add = 0;\n\t\tif (w % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\tw /= 2;\n\t\t}\n\t\tif (h % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\th /= 2;\n\t\t}\n\n\t\ttotal += add;\n\t}\n\n\tconst answer = total >= n ? 'YES' : 'NO';\n\twrite(total)\n}\n\nlet counter = 0;\nlet t = 0;\nconst t_size = 1;\n\nconst cases = [];\n\nconst lineInterpreter = (line) => {\n\tif (counter == 0) t = Number(line)\n\telse {\n\t\tconst cursor = (counter - 1) % t_size\n\t\tif (cursor == 0) cases.push([line])\n\t\telse cases[cases.length - 1].push(line)\n\t}\n\n\tif (counter == (t * t_size)) {\n\t\tcases.map(_case => mainCode(_case))\n\t}\n\tcounter++\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n\tinputString.map(line => lineInterpreter(line));\n});\n\n\n\n\n// For personal use\n\n// const sample = `5\n// 2 2 3\n// 3 3 2\n// 5 10 2\n// 11 13 1\n// 1 4 4`;\n// sample.split(`\\n`).map(line => lineInterpreter(line));"}, {"source_code": "const write = out => process.stdout.write(out + `\\n`);\n\nconst mainCode = ([l1]) => {\n\tlet [w, h, n] = l1.split(' ').map(Number);\n\tlet total = 1;\n\n\tlet factor = 1;\n\n\twhile (w % 2 == 0 || h % 2 == 0) {\n\t\tlet add = 0;\n\t\tif (w % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\tw /= 2;\n\t\t}\n\t\tif (h % 2 == 0) {\n\t\t\tadd += factor;\n\t\t\tfactor *= 2;\n\t\t\th /= 2;\n\t\t}\n\n\t\ttotal += add;\n\t}\n\n\tconst answer = total >= n ? 'YES' : 'NO';\n\twrite(total)\n}\n\nlet counter = 0;\nlet t = 0;\nconst t_size = 1;\n\nconst cases = [];\n\nconst lineInterpreter = (line) => {\n\tif (counter == 0) t = Number(line)\n\telse {\n\t\tconst cursor = (counter - 1) % t_size\n\t\tif (cursor == 0) cases.push([line])\n\t\telse cases[cases.length - 1].push(line)\n\t}\n\n\tif (counter == (t * t_size)) {\n\t\tcases.map(_case => mainCode(_case))\n\t}\n\tcounter++\n}\n\n// process.stdin.resume();\n// process.stdin.setEncoding('utf-8');\n\n// let inputString = '';\n// let currentLine = 0;\n\n// process.stdin.on('data', inputStdin => {\n// inputString += inputStdin;\n// });\n\n// process.stdin.on('end', _ => {\n// inputString = inputString.trim().split('\\n').map(string => {\n// return string.trim();\n// });\n \n// \tinputString.map(line => lineInterpreter(line));\n// });\n\n\n\n\n// For personal use\n\nconst sample = `5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4`;\nsample.split(`\\n`).map(line => lineInterpreter(line));"}, {"source_code": "const mainCode = ([l1]) => {\n\tlet [w, h, n] = l1.split(' ').map(Number);\n\tlet total = 1;\n\n\tlet w_factor = 1, h_factor = 1;\n\n\twhile (w % 2 == 0 || h % 2 == 0) {\n\t\tlet add = 0;\n\t\tif (w % 2 == 0) {\n\t\t\tadd += w_factor;\n\t\t\tw_factor *= 2;\n\t\t\tw /= 2;\n\t\t}\n\t\tif (h % 2 == 0) {\n\t\t\tadd += h_factor;\n\t\t\th_factor *= 2;\n\t\t\th /= 2;\n\t\t}\n\n\t\ttotal += add;\n\t}\n\n\t// console.log(total >= n ? 'YES' : 'NO');\n\tprocess.stdout.write(total >= n ? 'YES' : 'NO')\n\tprocess.stdout.write(`\\n`)\n}\n\n/************* KEEP BELOW CODE AS IT IS *********************/\n/**\n * This code has been taken from: https://codeforces.com/blog/entry/69610\n * I am not the owner of the readLine function below, understanding them require knowledge of basic NodeJS I/O and streams\n */\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\n/****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION ***************************************/\n/**\n * Use \"readLine()\" function for input, which will return a string consisting the entire line, so accordingly split the string \n * when required.\n *\n * I am using console.log() to output\n */\nconst main = () => {\n\tlet counter = 0;\n\tlet t = 0;\n\tconst t_size = 1;\n\n\tconst cases = [];\n\n\tconst lineInterpreter = (line) => {\n\t\tif (counter == 0) t = Number(line)\n\t\telse {\n\t\t\tconst cursor = (counter - 1) % t_size\n\t\t\tif (cursor == 0) cases.push([line])\n\t\t\telse cases[cases.length - 1].push(line)\n\t\t}\n\n\t\tif (counter == (t * t_size)) {\n\t\t\tcases.map(_case => mainCode(_case))\n\t\t}\n\t\tcounter++\n\t}\n\n\t// For CODEFORCES submission\n\tinputString.map(line => lineInterpreter(line));\n\n\n\t// For personal use\n\n\t// const sample = `5\n\t// 2 2 3\n\t// 3 3 2\n\t// 5 10 2\n\t// 11 13 1\n\t// 1 4 4`;\n\t// sample.split(`\\n`).map(line => lineInterpreter(line));\n}"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n \r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// var ar = readline().split(' ').map(n => parseInt(n));\r\n\r\n//-----------main function-----------\r\n \r\nfunction main() {\r\n\r\n var t = parseInt(readline());\r\n\r\nwhile (t--) {\r\n var ar = readline().split(' ').map(n => parseInt(n));\r\n var w = ar[0];\r\n var h = ar[1];\r\n var n = ar[2];\r\n var hn=0, wn=0, total;\r\n\r\n var res;\r\n\r\n while (w % 2 == 0) {\r\n wn = wn + w / 2 + 1;\r\n w = w / 2;\r\n }\r\n while (h % 2 == 0) {\r\n hn = hn + h / 2 + 1;\r\n h = h / 2;\r\n }\r\n\r\n total = hn + wn;\r\n\r\n if (total >= n) {\r\n res = 'YES';\r\n } else {\r\n res = 'NO';\r\n }\r\n\r\n console.log(res);\r\n}\r\n\r\n}\r\n"}, {"source_code": "const { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const sheet = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n\r\n for(let idx in sheet) {\r\n let piece = 1;\r\n let w = sheet[idx][0];\r\n let h = sheet[idx][1];\r\n let friend = sheet[idx][2];\r\n\r\n while(piece < friend) {\r\n if(w % 2 === 0) {\r\n piece += w === sheet[idx][0] ? 1 : 2;\r\n w /= 2;\r\n } else if(h % 2 === 0) {\r\n piece+= h === sheet[idx][1] ? 1 : 2;\r\n h /= 2;\r\n } else if(w % 2 !== 0 && h % 2 !== 0) break;\r\n }\r\n\r\n if(piece >= friend) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "const { RSA_X931_PADDING } = require(\"constants\");\r\nconst { maxHeaderSize } = require(\"http\");\r\nconst readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function(line) {\r\n input.push(line);\r\n}).on(\"close\", function() {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(input) {\r\n const sheet = input.slice(1).map(val => val.split(\" \").map(v => Number(v)));\r\n\r\n for(let idx in sheet) {\r\n let piece = 1;\r\n let w = sheet[idx][0];\r\n let h = sheet[idx][1];\r\n let friend = sheet[idx][2];\r\n\r\n while(piece < friend) {\r\n if(w % 2 === 0) {\r\n piece += w === sheet[idx][0] ? 1 : 2;\r\n w /= 2;\r\n } else if(h % 2 === 0) {\r\n piece+= w === sheet[idx][1] ? 1 : 2;\r\n h /= 2;\r\n } else if(w % 2 !== 0 && h % 2 !== 0) break;\r\n }\r\n\r\n if(piece >= friend) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar W = nextInt();\r\n\t\tvar H = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar count = 1;\r\n\t\tvar wcount = 1;\r\n\t\tvar hcount = 1;\r\n\t\twhile(W % 2 == 0){\r\n\t\t\tcount += wcount;\r\n\t\t\twcount *= 2;\r\n\t\t\tW /= 2;\r\n\t\t}\r\n\t\twhile(H % 2 == 0){\r\n\t\t\tcount += hcount;\r\n\t\t\thcount *= 2;\r\n\t\t\tH /= 2;\r\n\t\t}\r\n\t\tmyout((count >= N) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar W = nextInt();\r\n\t\tvar H = nextInt();\r\n\t\tvar N = nextInt();\r\n\t\tvar count = 1;\r\n\t\tvar wcount = 1;\r\n\t\tvar hcount = 1;\r\n\t\twhile(W % 2 == 0){\r\n\t\t\tcount += wcount;\r\n\t\t\twcount++;\r\n\t\t\tW /= 2;\r\n\t\t}\r\n\t\twhile(H % 2 == 0){\r\n\t\t\tcount += hcount;\r\n\t\t\thcount++;\r\n\t\t\tH /= 2;\r\n\t\t}\r\n\t\tmyout((count >= N) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n // taking and assingn variables...\r\n let [w, h, n] = input[z++].split(' ').map(x=>Number(x));\r\n // intialing out counter variable which will count the division..\r\n let counter = 0;\r\n // chacking how many times can we divide width and height\r\n while (w % 2 !== 1) {\r\n w /= 2;\r\n counter++;\r\n }\r\n while (h % 2 !== 1) {\r\n h /= 2;\r\n counter++;\r\n }\r\n // checking the edge cases and making our final output\r\n console.log(((counter * 2 >= n) || n == 1) ? \"YES\": \"NO\");\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n for (let i = 0; i < x; i++) {\r\n let t = readline();\r\n let [w, h, n] = t.split(' ');\r\n let ans = 1;\r\n\r\n while (w % 2 === 0) {\r\n w /= 2;\r\n ans *= 2;\r\n }\r\n\r\n while (h % 2 === 0) {\r\n h /= 2;\r\n ans *= 2;\r\n }\r\n\r\n console.log(ans);\r\n console.log(ans >= n ? 'yes' : 'no');\r\n\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', (c) => (i += c));\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL).filter((line) => line);\n console.log(processInput(lines));\n});\n\nconst getNOf2Factors = (number) => {\n let nOf2Factors = 0;\n while (number % 2 === 0) {\n nOf2Factors++;\n number /= 2;\n }\n return nOf2Factors;\n};\n\nconst processInput = (lines) => {\n return lines\n .slice(1)\n .map((line) => line.split(' '))\n .map(([w, h, n]) => {\n return Math.pow(2, getNOf2Factors(w) + getNOf2Factors(h)) >= n ? 'YES' : 'NO';\n });\n};\n"}], "src_uid": "a8201326dda46542b23dc4e528d413eb"} {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var one = nextIntArray();\n var N = one[0];\n var K = one[1];\n var list = nextIntArray();\n var count = 0;\n for(var i = 0; i < N; i++){\n if(list[i] <= 5 - K){\n count++;\n }\n }\n myout(Math.floor(count / 3));\n}\n", "positive_code": [{"source_code": "var s = readline().split(\" \");\nvar str = readline().split(\" \");\nvar temp=0; var res = 0;\n\t\n\tfor (var i=0; i<+s[0]; i++){\n\t\tif(+str[i]+Number(s[1])<=5){\n\t\t\ttemp++;\n\t\t\tif (temp%3==0){\n\t\t\t\tres++\n\t\t\t}\n\t\t}\n\t}\n\tprint(res);"}, {"source_code": "var s = readline().split(' ');\nvar n = Number(s[0]), k = Number(s[1]);\nvar people = readline().split(' ').map(Number);\n\nvar team = 0;\nvar teamMate = 0;\n\nfor (var i=0; i +value);\nvar n = input[0];\nvar k = input[1];\nvar y = readline().split(' ').map(value => +value);\n\nvar result = 0;\nfor (var i = 0; i < y.length; ++i) {\n result += y[i] + k <= 5;\n}\n\nwrite(~~(result/3));"}, {"source_code": "var read_ =readline();\nvar read_2 = readline();\nvar n=read_.split(\" \")[0],\nk=read_.split(\" \")[1],\na=read_2.split(\" \"),\nb=0 ;\n \tfor\t(var i = 0; i 5-x>=k).length/3))\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline()),\n\t\tnumPeople = data[0], minTimes = data[1],\n\t\tpeople = tokenizeIntegers(readline());\n\tpeople.sort(function(a, b) {\n\t\treturn a-b;\n\t});\n\tvar teamCount = 0,\n\t\tteamSize = 0;\n\tfor (var i = 0; i < people.length; ++i) {\n\t\tvar previous = people[i];\n\t\tif (previous + minTimes > 5) {\n\t\t\tbreak;\n\t\t}\n\t\tif (++teamSize == 3) {\n\t\t\t++teamCount;\n\t\t\tteamSize = 0;\n\t\t}\n\t}\n\tprint(teamCount);\n}\n\nmain();\n"}, {"source_code": "var tokenizer;\nvar index = 0;\n\nfunction next(){\n while(tokenizer == null || index == tokenizer.length){\n tokenizer = readline().split(\" \");\n index = 0;\n }\n var res = tokenizer[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction nextFloat(){\n return parseFloat(next());\n}\n\nfunction solve(){\n var n = nextInt();\n var k = nextInt();\n var a = [];\n for(var i = 0; i < n; ++i){\n a.push(nextInt());\n }\n a.sort();\n var res = 0;\n for(var i = 2; i < n; i += 3){\n if(5 - a[i] >= k){\n ++res;\n }\n }\n print(res);\n}\nsolve();"}, {"source_code": "var nk=readline().split(' ').map(function(x){return parseInt(x);});\nvar p=readline().split(' ').map(function(x){return parseInt(x);});\nvar ans=0;\nfor(var i= 0;i=nk[1])ans++;\n}\nprint(parseInt(ans/3));"}, {"source_code": "'use strict'\n\nString.prototype.getNumber = function() {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n })[0];\n};\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n(function () {\n let array_1 = readline().getNumArray(),\n k = array_1[1],\n array_2 = readline().getNumArray(),\n counter = 0;\n\n\n for (let i = 0; i < array_2.length; i++) {\n if (5 - k >= array_2[i] ) {\n counter++;\n }\n }\n write(parseInt(counter/3));\n})();"}, {"source_code": "var inputInfo = readline().split(' ').map(Number);\nvar inputTeam = readline().split(' ').map(Number);\nvar numofApproved = 0;\nfor (var i=0; i= k;\n}\n\nwrite(s);\n"}, {"source_code": ";(function () {\n\n\tvar k = +readline().split(' ')[1];\n\n\tprint( Math.floor(readline().split(' ').map(Number).filter(function (e) { return (e+k) < 6; }).length / 3) );\n\n}).call(this);"}, {"source_code": "var line = readline().split(' ')\nvar n = parseInt(line[0])\nvar k = parseInt(line[1])\nvar a = readline().split(\" \");\n\nvar cnt = 0;\n\nfor(var i = 0; i < n; i++) {\n if (5 - a[i] >= k) {\n cnt++;\n }\n} \n\nvar ans = Math.floor(cnt / 3);\n\nprint(ans);"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let members = parseInt(line1[0]);\n const k = parseInt(line1[1]);\n const participations =\n inputs[1]\n .split(' ')\n .filter((participation, i) => 5 - parseInt(participation) >= k);\n\n return console.log(Math.floor(participations.length/3));\n\n\n});\n\n\n"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const line1 = inputs[0].split(' ');\n let members = parseInt(line1[0]);\n const k = parseInt(line1[1]);\n const participations =\n inputs[1]\n .split(' ')\n .filter((participation, i) => 5 - parseInt(participation) >= k);\n\n return console.log(Math.floor(participations.length/3));\n\n\n});\n\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, k;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, k] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const ans = [];\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] + k <= 5) {\n ans.push(arr[i]);\n }\n }\n\n console.log(Math.floor(ans.length / 3));\n c++;\n});\n"}, {"source_code": "(function (){\n var line = readline().split(' ');\n var i, n = parseInt(line[0]);\n var k = parseInt(line[1]);\n var y = readline().split(' ');\n y.sort(function(a,b){\n return parseInt(a)-parseInt(b);\n });\n var team = 0;\n for(i = 2 ; i < n ; i += 3){\n if ( (5 - parseInt(y[i]))>=k ){\n ++team;\n }else{\n break;\n }\n }\n print(team);\n})();"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\n/**\n * \n * @param {*} str \n * @param {*} seperator \n */\nfunction splitter(str, seperator = '') {\n return str.trim().split(seperator);\n}\n\n/**\n * \n * @param {*} arr \n */\nfunction strToNumArr(arr = []) {\n return arr.map(num => Number(num));\n}\n\n\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let stParticipate = inputs[0].trim().split(' ');\n let students = +stParticipate[0];\n let kTimes = +stParticipate[1];\n let stParticipated = strToNumArr(splitter(inputs[1], ' '));\n let teams = 0;\n for (const iterator of stParticipated) {\n if ((5 - iterator) >= kTimes) {\n teams++;\n }\n }\n\n teams = Math.floor(teams / 3);\n return teams.toString();\n}\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let nk = readLine().split(' ').map(v => parseInt(v));\n let arr = readLine().split(' ').map(v => parseInt(v));\n let n = nk[0];\n let k = nk[1];\n let ans = arr.filter(item => {\n return item <= 5 - k;\n })\n console.log(Math.floor(ans.length / 3));\n}"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const [n, k] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n let answ = 0, com = 0;\n nums.sort((a, b) => a - b);\n nums.forEach(x => {\n if (x+k <= 5) {\n com +=1;\n if (com === 3) {\n answ += 1; com = 0;\n }\n }\n });\n\n console.log(answ);\n});"}, {"source_code": "\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nvar gcd = (a, b) => a ? gcd(b % a, a) : b;\nvar lcm = (a, b) => a * b / gcd(a, b);\n\n\nfunction main(){\n let [a,b] = readLine().split(\" \");\n let arr = readLine().split(\" \").map(x=>Number(x));\n\n let ans = parseInt(arr.filter(x=> x<(6-b)).length / 3);\n\n console.log(ans)\n\n}\n"}, {"source_code": "var p = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar a = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar n = 0;\nfor (var i = 0; i < a.length; i++) {\n\tif (5 - a[i] >= p[1]) n++;\n}\nprint (Math.floor (n / 3));"}, {"source_code": "var line = readline().split(' ').map(Number);\n\nvar n = line[0];\nvar k = line[1];\n\nvar students = readline().split(' ').map(Number);\n\nvar eligible = 0;\n\nfor(i=0;i= k) {\n cnt++;\n }\n} \n\nvar ans = cnt / 3;\n\nprint(ans);"}, {"source_code": "var line = readline().split(' ')\nvar n = parseInt(line[0])\nvar k = parseInt(line[1])\nvar a = readline().split(\" \");\n\nvar cnt = 0;\n\nfor(var i = 0; i < n; i++) {\n if (5 - a[i] >= k) {\n cnt++;\n }\n} \n\nvar ans = cnt / 3;\n\nans;"}], "src_uid": "fbde1e2ee02055592ff72fb04366812b"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const sum = b.reduce((a, b) => a + b, 0) % n;\r\n return a[sum];\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n const m = Number(await read());\r\n const b = (await read()).split(' ').map(Number);\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "// NOTE: nodeJS printing to console & not to outputf.txt\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding('utf8')\r\n\r\nlet fs = require(\"fs\")\r\nlet data = fs.readFileSync(0, \"utf-8\") // online judge\r\n// let data = fs.readFileSync(\"inputf.txt\", \"utf-8\") // local\r\nlet idx = 0\r\ndata = data.split(\"\\n\")\r\nfunction input() {\r\n return data[idx++]\r\n}\r\n\r\nlet tcs = parseInt(input())\r\nfor (let tc = 0; tc < tcs; tc++) {\r\n let n = parseInt(input())\r\n let arr1 = input().split(\" \").map(Number)\r\n let m = parseInt(input())\r\n let arr2 = input().split(\" \").map(Number)\r\n let tot = 0\r\n for (let i = 0; i < m; i++) {\r\n tot += arr2[i];\r\n }\r\n let summ = 0\r\n for (let j = 0; j < n; j++) {\r\n summ += arr1[j];\r\n }\r\n console.log(arr1[tot % n])\r\n}\r\n"}, {"source_code": "// NOTE: nodeJS printing to console & not to outputf.txt\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding('utf8')\r\n\r\nlet fs = require(\"fs\")\r\nlet data = fs.readFileSync(0, \"utf-8\")\r\nlet idx = 0\r\ndata = data.split(\"\\n\")\r\nfunction input() {\r\n return data[idx++]\r\n}\r\n\r\nlet tcs = parseInt(input())\r\nfor (let tc = 0; tc < tcs; tc++) {\r\n let n = parseInt(input())\r\n let arr1 = input().split(\" \").map(Number)\r\n let m = parseInt(input())\r\n let arr2 = input().split(\" \").map(Number)\r\n let tot = 0\r\n for (let i = 0; i < m; i++) {\r\n tot += arr2[i];\r\n }\r\n let summ = 0\r\n for (let j = 0; j < n; j++) {\r\n summ += arr1[j];\r\n }\r\n console.log(arr1[tot % n])\r\n}\r\n"}, {"source_code": "const rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n for (let t = 0; t < T; t++) {\r\n input.next();\r\n const cards = input.next().value.split(\" \").map(Number);\r\n input.next();\r\n const shuffles = input.next().value.split(\" \").map(Number);\r\n results.push(cards[shuffles.reduce((acc, v) => (acc += v), 0) % cards.length]);\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nvar arr = \"\";\r\n\r\nprocess.stdin.on(\"data\", function (chunk) {\r\n arr += chunk;\r\n});\r\n\r\nprocess.stdin.on(\"end\", function () {\r\n arr = arr.split(\"\\n\");\r\n const n = parseInt(arr.shift()); // no of test cases\r\n\r\n for (let i = 0; i < 4 * n; ) {\r\n const noOfCard = arr[i++];\r\n const cards = arr[i++].split(\" \").map((el) => parseInt(el));\r\n\r\n const noOfOperation = arr[i++];\r\n const operations = arr[i++].split(\" \").map((el) => parseInt(el));\r\n\r\n let sum = 0;\r\n operations.forEach((operation) => (sum += operation));\r\n\r\n let ans = cards[sum % noOfCard];\r\n\r\n console.log(ans);\r\n }\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\t// console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n \r\nfunction Main(){\r\n // test case in nodeJs\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tsolve();\r\n\t}\r\n}\r\n\r\nfunction solve() {\r\n\tconst deckNum = nextInt();\r\n const deckArr = nextIntArray(deckNum);\r\n const shuffleNum = nextInt();\r\n const shuffleArr = nextIntArray(shuffleNum);\r\n const sum = shuffleArr.reduce((sum, ele) => {\r\n return sum + ele;\r\n }, 0);\r\n const index = sum % deckArr.length;\r\n myout(deckArr[index]);\r\n}"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0, m = 0;\n var a = 0;\n for(i = 1; i <= t * 4; i++){\n var b = lines[i].split(' ').map(Number);\n if(i % 4 == 1){\n n = b[0];\n }else if(i % 4 == 2){\n a = b;\n }else if(i % 4 == 3){\n m = b[0];\n }else{\n var sum = 0;\n for(j = 0; j < m; j++){\n sum += b[j];\n } \n console.log(a[sum % n]);\n }\n }\n});\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n let m = parseInt(readline(), 10);\r\n let B = readline().split(' ').map(Number);\r\n\r\n let ss = B.reduce((a, b) => a + b, 0);\r\n\r\n let i = ss % n;\r\n\r\n output(arr[i]);\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const sa = lines[l++].trim().split(' ').map(Number)\n l++\n const sb = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(sa, sb)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(sa, sb) {\n let now = 0\n sb.forEach(x => {\n now = (now + x) % sa.length\n })\n return sa[now]\n}\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +readline();\n let a = ra();\n let m = +readline();\n let b = ra();\n\n let idx = 0;\n\n for (let i = 0; i < m; i++) {\n idx = (idx + b[i]) % n;\n }\n\n return a[idx];\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(n, a)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "// NOTE: nodeJS printing to console & not to outputf.txt\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding('utf8')\r\n\r\nlet fs = require(\"fs\")\r\nlet data = fs.readFileSync(0, \"utf-8\") // online judge\r\n// let data = fs.readFileSync(\"inputf.txt\", \"utf-8\") // local\r\nlet idx = 0\r\ndata = data.split(\"\\n\")\r\nfunction input() {\r\n return data[idx++]\r\n}\r\n\r\nlet tcs = parseInt(input())\r\nfor (let tc = 0; tc < tcs; tc++) {\r\n let n = parseInt(input())\r\n let arr1 = input().split(\" \").map(Number)\r\n let m = parseInt(input())\r\n let arr2 = input().split(\" \").map(Number)\r\n let tot = 0\r\n for (let i = 0; i < m; i++) {\r\n tot += arr2[i];\r\n }\r\n let summ = 0\r\n for (let j = 0; j < n; j++) {\r\n summ += arr1[j];\r\n }\r\n console.log(arr1[tot % n])\r\n}\r\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nconst solve = (cards, shuffles) => {\n console.log(\n cards[shuffles.reduce((index, shuff) => (index + shuff) % cards.length, 0)]\n );\n};\nlet T = -1;\nlet cards;\nlet shuffles;\n\nrl.on(\"line\", function (line) {\n if (T !== -1) {\n switch (T % 4) {\n case 1:\n cards = line.split(\" \").map(Number);\n break;\n case 3:\n shuffles = line.split(\" \").map(Number);\n if (cards !== undefined && shuffles !== undefined)\n solve(cards, shuffles);\n break;\n default:\n break;\n }\n }\n T++;\n});\n"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var qe=1;qe<=T;qe++) {\r\n var n = parseInt(readline());\r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n var m = readline();\r\n var b = readline().split(' ').map((x) => parseInt(x));\r\n var id = 0;\r\n for(var i=0;i1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst calc = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n let [m] = ra();\n let B = ra();\n LT({n, A});\n // PROCESSING:\n let sum = 0;\n for (let i=m-1; i>=0; i--){\n sum += B[i]\n\n }\n return A[sum%n]\n\n return ans;\n};\n "}, {"source_code": "var test = parseInt( readline(), 10 )\r\n\r\nfunction total_move_counter(acc,a){\r\n return parseInt(acc) + parseInt(a);\r\n}\r\n\r\nfor(var i = 0 ; i < test ; i++ ){\r\n var num_of_deck_cards = parseInt( readline(), 10 );\r\n var deck_cards = readline().split(' ');\r\n \r\n \r\n var num_of_shuffles = parseInt(readline(), 10 )\r\n var num_of_cards_to_move = readline().split(' ');\r\n \r\n total_move = num_of_cards_to_move.reduce(total_move_counter,0);\r\n \r\n top_card_idx = total_move % num_of_deck_cards\r\n \r\n print(deck_cards[top_card_idx])\r\n \r\n \r\n}\r\n\r\n"}, {"source_code": "var num = parseInt(readline(), 10);\r\n\r\nfor(var i = 0; i < num; i++) {\r\n var cardsNum = parseInt(readline(), 10);\r\n var cards = readline().split(\" \");\r\n\r\n\r\n var shuffleNum = parseInt(readline(), 10);\r\n var shuffles = readline().split(\" \");\r\n\r\n var count = 0;\r\n for(var k = 0; k < shuffleNum; k++) {\r\n count += parseInt(shuffles[k], 10);\r\n }\r\n\r\n var mod = count % cardsNum;\r\n\r\n print(cards[mod]);\r\n}"}], "negative_code": [{"source_code": "const { Console } = require(\"console\");\r\n\r\nconst rl = require(\"readline\").createInterface({\r\n input: process.stdin,\r\n output: process.stdout,\r\n});\r\n\r\nlet input = [];\r\nrl.on(\"line\", function (line) {\r\n input.push(line);\r\n}).on(\"close\", function () {\r\n solution(input);\r\n process.exit();\r\n});\r\n\r\nfunction solution(_input) {\r\n const input = _input[Symbol.iterator]();\r\n const T = Number(input.next().value);\r\n\r\n const results = [];\r\n tcloop: for (let t = 0; t < T; t++) {\r\n const N = Number(input.next().value);\r\n const A = input.next().value.split(\" \").map(Number);\r\n const B = input.next().value.split(\" \").map(Number);\r\n\r\n const AB = [];\r\n for (let i = 0; i < N; i++) {\r\n AB.push([A[i], B[i]]);\r\n }\r\n AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));\r\n for (let i = 1; i < N; i++) {\r\n if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {\r\n results.push(\"-1\");\r\n continue tcloop;\r\n }\r\n }\r\n\r\n ops = [];\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < N; i++) {\r\n for (let j = i + 1; j < N; j++) {\r\n if (A[i] > A[j] || B[i] > B[j]) {\r\n [A[i], A[j]] = [A[j], A[i]];\r\n [B[i], B[j]] = [B[j], B[i]];\r\n ops.push([j + 1, i + 1].join(\" \"));\r\n }\r\n }\r\n }\r\n\r\n results.push(ops.length);\r\n for (let i = 0; i < ops.length; i++) {\r\n results.push(ops[i]);\r\n }\r\n }\r\n console.log(results.join(\"\\n\"));\r\n}\r\n"}, {"source_code": "var number_of_test = readline();\r\n\r\n\r\nfunction get_card_on_the_top(){\r\n var total_cards = readline();\r\n var serial = readline().split(' ');\r\n \r\n var num_of_shuffle = readline();\r\n var cards_to_move = readline().split(' ');\r\n \r\n var i = 0, j = 0;\r\n while( i < num_of_shuffle ){\r\n print(i)\r\n while( j < cards_to_move[i] ){\r\n serial.push( serial.shift() )\r\n j++;\r\n }\r\n i++;\r\n }\r\n print(serial[1]);\r\n}\r\n\r\nfor(var i = 0 ; i < number_of_test ; i++ ) {\r\n get_card_on_the_top();\r\n}\r\n"}], "src_uid": "c9da10199ad1a5358195b693325e628b"} {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = Math.max(k[1], k[2]);\n var m = Math.min(k[1], k[2]);\n var g = k[0] - 1;\n if(n === 0 || m !== 0 || g % n !== 0){\n console.log(-1);\n }else{\n var ans = '';\n for(j = 0; j < g; j++){\n ans += 2 + Math.floor(j / n) * n + ' ';\n }\n console.log(ans);\n }\n }\n});\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n let n = rn(),\r\n x = rn(),\r\n y = rn();\r\n if (x !== 0 && y !== 0 || x === 0 && y === 0) return -1;\r\n if (y === 0) y = x;\r\n if ((n - 1) % y !== 0) return -1;\r\n const res = new Array(n - 1);\r\n let cur = 2;\r\n for (let i = 0; i < n - 1; i += y) {\r\n for (let j = 0; j < y && i + j < n - 1; j++) {\r\n res[i + j] = cur;\r\n }\r\n cur += y;\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\nfunction getResult(n,x,y){\r\n\tif( (x !== 0 && y !== 0) || (x === 0 && y === 0) ) return -1\r\n\t\r\n\tlet res = []\r\n\tlet w = 1\r\n\tlet c = 0\r\n\tlet max = Math.max(x,y)\r\n\tlet flag = 0\r\n\t\r\n\twhile(1)\r\n\t{\r\n\t for(let i=0; in) break\r\n\t}\r\n\t\r\n\tif(!flag) return -1\r\n\t \r\n\treturn res \r\n}\r\n\r\nfunction main() {\r\n let testcases = parseInt( readline() )\r\n while(testcases--){\r\n \tlet inputs = readline().split(' ').map(Number)\r\n \tlet n = inputs[0]\r\n \tlet x = inputs[1]\r\n \tlet y = inputs[2]\r\n \t\r\n \tlet res = getResult(n, x, y)\r\n \tres = (res === -1 ) ? res : res.join(' ')\r\n \tconsole.log( res )\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while(t--){\r\n let [n,x,y] = readline().trim().split(\" \").map(cur=>parseInt(cur));\r\n const helper = ()=>{\r\n if((x!==0)&&(y!==0)) console.log(-1);\r\n else if((x===0)&&(y===0)) console.log(-1);\r\n else{\r\n let arr = [];\r\n for(let i=0;i=n){\r\n console.log(-1);\r\n return;\r\n }\r\n else res.push(c);\r\n j++;\r\n t++;\r\n }\r\n i = j;\r\n c = arr[i];\r\n }\r\n console.log(res.join(\" \"));\r\n }\r\n }\r\n helper();\r\n }\r\n};\r\nsolve();"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n_x_y = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_x_y[0], n_x_y[1], n_x_y[2]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction myFunc(n, x, y){\r\n let sum = 0;\r\n let contx = n-1, conty = 0;\r\n let resp = [];\r\n\r\n if(x != 0 && y != 0) return -1;\r\n if(x > y) [x, y] = [y, x]\r\n \r\n for(let i = 0; i < n-1; i++){\r\n sum += x;\r\n }\r\n\r\n for(let i = 0; i < n-1; i++){\r\n contx--;\r\n conty++;\r\n sum += y - x;\r\n if(sum == n-1) break;\r\n }\r\n if(sum != n-1) return -1;\r\n\r\n let ind = 2;\r\n \r\n while(conty-- > 0 && y > 0){\r\n for(let i = 0; i < y; i++){\r\n resp.push(ind);\r\n }\r\n ind+=y;\r\n }\r\n\r\n return resp.join(' ');\r\n}"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = Math.max(k[1], k[2]);\n var m = Math.min(k[1], k[2]);\n var g = k[0] - 1;\n if(n === 0 || m !== 0 || g % n !== 0){\n console.log(-1);\n }else{\n var ans = '';\n for(j = 0; j < g; j++){\n ans += 2 + j / n * n + ' ';\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = Math.max(k[1], k[2]);\n var m = Math.min(k[1], k[2]);\n var g = k[0] - 1;\n if(n === 0 || m !== 0 || g % n !== 0){\n console.log(-1);\n }else{\n var ans = '';\n for(j = 0; j < g; j++){\n ans += 2 + j + ' ';\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i];\n for(l = 1; l <= a; l++){\n var ans = '';\n for(j = 1; j <= l; j++){\n if(j == 1 || j == l){\n ans += 1 + ' ';\n }else{\n ans += 0 + ' ';\n }\n }\n console.log(ans);\n }\n }\n});\n"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n const n_x_y = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_x_y[0], n_x_y[1], n_x_y[2]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction myFunc(n, x, y){\r\n let sum = 0;\r\n let contx = n-1, conty = 0;\r\n let resp = [];\r\n if(x > y) [x, y] = [y, x]\r\n \r\n for(let i = 0; i < n-1; i++){\r\n sum += x;\r\n }\r\n\r\n for(let i = 0; i < n-1; i++){\r\n contx--;\r\n conty++;\r\n sum += y - x;\r\n if(sum == n-1) break;\r\n }\r\n if(sum != n-1) return -1;\r\n\r\n let ind = 2;\r\n // console.log(contx, conty);\r\n while(contx-- > 0 && x > 0){\r\n for(let i = 0; i < x; i++){\r\n resp.push(ind);\r\n }\r\n ind+=x;\r\n }\r\n \r\n while(conty-- > 0 && y > 0){\r\n for(let i = 0; i < y; i++){\r\n resp.push(ind);\r\n }\r\n ind+=y;\r\n }\r\n\r\n return resp.join(' ');\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_x_y = readLine().split(' ').map(p => +p);\r\n // const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_x_y[0], n_x_y[1], n_x_y[2]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction myFunc(n, x, y){\r\n\r\n let resp = rec(0, 0, '');\r\n if(resp == -1) return -1;\r\n resp = resp.split('').map(p => p == 'x' ? x : y)\r\n return resp.join(' ')\r\n\r\n function rec(jog, sum, str){\r\n // console.log(jog, sum, str);\r\n if(sum + x == n-1 && jog == n-1) return str + 'x';\r\n if(sum + y == n-1 && jog == n-1) return str + 'y';\r\n\r\n if(sum + x <= n-1 && jog + 1 <= n-1) \r\n return rec(jog + 1, sum + x, str + 'x');\r\n\r\n if(sum + y <= n-1 && jog + 1 <= n-1) \r\n return rec(jog + 1, sum + y, str + 'y');\r\n\r\n return -1;\r\n }\r\n\r\n}"}, {"source_code": "var readline = require('readline');\r\nvar inputString = [], currentLine = 0;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nvar rl = readline.createInterface(process.stdin);\r\nrl.on('line', line => { inputString.push(line) });\r\nprocess.stdin.on('end', () => { main() });\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readLine();\r\n for(let i = 0; i < t; i++){\r\n // const n = +readLine();\r\n const n_x_y = readLine().split(' ').map(p => +p);\r\n // const arr = readLine().split(' ').map(p => +p);\r\n let result = myFunc(n_x_y[0], n_x_y[1], n_x_y[2]);\r\n console.log(result);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction myFunc(n, x, y){\r\n\r\n let resp = rec(0, 0, '');\r\n if(resp == -1) return -1;\r\n return resp.split('').map(p => p == 'x' ? x : y)\r\n\r\n function rec(jog, sum, str){\r\n // console.log(jog, sum, str);\r\n if(sum + x == n-1 && jog == n-1) return str + 'x';\r\n if(sum + y == n-1 && jog == n-1) return str + 'y';\r\n\r\n if(sum + x <= n-1 && jog + 1 <= n-1) \r\n return rec(jog + 1, sum + x, str + 'x');\r\n\r\n if(sum + y <= n-1 && jog + 1 <= n-1) \r\n return rec(jog + 1, sum + y, str + 'y');\r\n\r\n return -1;\r\n }\r\n\r\n}"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n let n = rn(),\r\n x = rn(),\r\n y = rn();\r\n if (x !== 0 && y !== 0 || x === 0 && y === 0) return -1;\r\n if (y === 0) y = x;\r\n if (y !== 1 && n % 2 === 0) return -1;\r\n if (n & 1 && y > (n - 1) / 2) return -1;\r\n const res = new Array(n - 1);\r\n let cur = 2;\r\n for (let i = 0; i < n - 1; i += y) {\r\n for (let j = 0; j < y; j++) {\r\n res[i + j] = cur;\r\n }\r\n cur += y;\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const rn = () => Number(read());\r\n let n = rn(),\r\n x = rn(),\r\n y = rn();\r\n if (x !== 0 && y !== 0 || x === 0 && y === 0) return -1;\r\n if (y === 0) y = x;\r\n if (y !== 1 && n % 2 === 0) return -1;\r\n const res = new Array(n - 1);\r\n let cur = 2;\r\n for (let i = 0; i < n - 1; i += y) {\r\n for (let j = 0; j < y; j++) {\r\n res[i + j] = cur;\r\n }\r\n cur += y;\r\n }\r\n return res.join(' ');\r\n}\r\n\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < 100) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= 100) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "024d7b1d5f7401080560174003456037"} {"source_code": "// require('./config');\n\nvar line = readline();\n\nvar i, j;\nvar n = Number(line);\nvar a = [];\nvar b = [];\nfor (i = 0; i < n; i++) {\n line = readline().split(' ');\n a.push(Number(line[0]));\n b.push(Number(line[1]));\n}\n\nvar r1 = [];\nvar r2 = [];\nfor (i = 0; i < n; i++) {\n if (i < (n - 1)/2) {\n r1[i] = 1;\n r2[i] = 1;\n } else {\n r1[i] = 0;\n r2[i] = 0;\n }\n}\nvar count = 0;\ni = 0;\nj = 0;\n\nwhile (count < n) {\n if (a[i] < b[j]) {\n r1[i] = 1;\n i++;\n } else {\n r2[j] = 1;\n j++\n }\n count++;\n}\n\n\nprint(r1.join(''));\nprint(r2.join(''));", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar semiSize = integers[0], quarterSize = semiSize/2, size = 2*semiSize;\n\n\tvar records = [], feasible = [[], []];\n\n\tfor (var rank = 0; rank < semiSize; rank += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tfor (var round = 0; round < 2; round += 1) {\n\t\t\trecords.push([integers[round], round, rank]);\n\t\t\tfeasible[round].push(rank+1 <= quarterSize ? '1' : '0');\n\t\t}\n\t}\n\n\trecords.sort(function(a, b) {\n\t\treturn a[0] - b[0];\n\t});\n\n\tfor (var rank = 0; rank < semiSize; rank += 1) {\n\t\tvar record = records[rank];\n\t\tfeasible[record[1]][record[2]] = '1';\n\t}\n\n\tprint(feasible[0].join(''));\n\tprint(feasible[1].join(''));\n\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar semiSize = integers[0], quarterSize = semiSize/2, size = 2*semiSize;\n\n\tvar records = [], feasible = [[], []];\n\n\tfor (var rank = 0; rank < semiSize; rank += 1) {\n\t\tvar integers = tokenizeIntegers(readline());\n\t\tfor (var round = 0; round < 2; round += 1) {\n\t\t\trecords.push({score: integers[round], round: round, rank: rank});\n\t\t\tfeasible[round].push(rank+1 <= quarterSize ? '1' : '0');\n\t\t}\n\t}\n\n\trecords.sort(function(a, b) {\n\t\treturn a.score - b.score;\n\t});\n\n\tfor (var rank = 0; rank < semiSize; rank += 1) {\n\t\tvar record = records[rank];\n\t\tfeasible[record.round][record.rank] = '1';\n\t}\n\n\tprint(feasible[0].join(''));\n\tprint(feasible[1].join(''));\n\n}\n\nmain();\n"}, {"source_code": "\n var n = parseInt(readline());\n var a = [], b = [], au = [], bu =[];\n for(var i=0; i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n while (j < preparedProblems) {\n if (preparedComplexities[j] >= goodComplexities[i]) {\n cnt++\n i++\n }\n j++\n }\n }\n\n console.log(Math.max(0, goodRoundProblems - cnt))\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const requirements = readLine().split(' ').map(Number);\n const complexities = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = georgeAndRound2(n, m, requirements, complexities);\n printResult(result.toString());\n}\n\nconst georgeAndRound = (n, m, a, b) => {\n let appearance = 0;\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (b[j] >= a[i]) {\n appearance++;\n i++;\n }\n }\n }\n\n return Math.max(0, n - appearance);\n};\n\nconst georgeAndRound2 = (n, m, a, b) => {\n let appearance = 0;\n let j = 0;\n for (let i = 0; i < n; i++) {\n while(j < m) {\n if (b[j] >= a[i]) {\n appearance++;\n i++;\n }\n j++;\n }\n }\n\n return Math.max(0, n - appearance);\n};\n"}, {"source_code": "var line = readline().split(\" \");\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\n\nvar complexes = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar problems = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar result = 0;\nfor (var i = 0; i < complexes.length; i++) {\n var found = false;\n var foundBigger = false;\n var whichBigger = -1;\n \n for (var u = 0; u < problems.length; u++) {\n if (problems[u] == -1) continue;\n \n if (problems[u] > complexes[i]) {\n foundBigger = true;\n whichBigger = u;\n break;\n } else if (complexes[i] == problems[u]) {\n found = true;\n break;\n }\n }\n\n if (!found && foundBigger) {\n problems[whichBigger] = -1;\n }\n \n if (!foundBigger && !found) {\n result++;\n }\n}\n\nprint(result);\n"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var m = line[1];\n \n var a = readline().split(' ').map(Number);\n var b = readline().split(' ').map(Number);\n a.sort((a,b) => b- a);\n b.sort((a,b) => a-b);\n var used = [];\n var res = 0;\n for(var i=0;i= a[i]){\n found = true;\n used[j] = true;\n break;\n }\n }\n if(!found){\n res++;\n }\n }\n print(res)\n}\n\n\nmain()"}], "negative_code": [{"source_code": "// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodRoundProblems[i]\n while (goodComplexity > preparedComplexities[j]){\n j++\n }\n if (j === preparedProblems - 1) {\n console.log((goodRoundProblems - i - 1) + '')\n return\n }\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = new Map()\n for (let i = 0; i < goodRoundProblems; i++) {\n cnt.set(goodComplexities[i], (cnt.get(goodComplexities[i]) || 0) + 1)\n }\n\n for (let i = 0; i < preparedProblems; i++) {\n const complexity = preparedComplexities[i]\n if (cnt.has(complexity)) {\n cnt.set(complexity, cnt.get(complexity) - 1)\n if (cnt.get(complexity) === 0) {\n cnt.delete(complexity)\n }\n }\n }\n\n let missed = 0\n for (let value of cnt.values()) {\n missed += value\n }\n\n console.log(missed)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodComplexities[i]\n if (preparedComplexities[j] >= goodComplexity) {\n j++\n cnt++\n } else {\n while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {\n j++\n }\n if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)\n cnt++\n }\n if (j === preparedProblems - 1) {\n console.log(goodRoundProblems - cnt - 1)\n return\n }\n }\n\n console.log(goodRoundProblems - cnt)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodComplexities[i]\n if (preparedComplexities[j] >= goodComplexity) {\n j++\n cnt++\n } else {\n while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {\n j++\n }\n if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)\n cnt++\n }\n if (cnt === goodRoundProblems - 1) {\n console.log(0)\n return\n }\n\n if (j >= preparedProblems - 1) {\n console.log(goodRoundProblems - cnt)\n return\n }\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodComplexities[i]\n if (preparedComplexities[j] >= goodComplexity) {\n j++\n cnt++\n } else {\n while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {\n j++\n }\n if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)\n cnt++\n }\n if (j === preparedProblems) {\n break\n }\n }\n\n console.log(goodRoundProblems - cnt)\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodComplexities[i]\n if (preparedComplexities[j] >= goodComplexity) {\n j++\n cnt++\n } else {\n while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {\n j++\n }\n if (j < preparedProblems)\n cnt++\n }\n if (j === preparedProblems) {\n break;\n }\n }\n\n console.log(goodRoundProblems - cnt)\n}"}, {"source_code": "// Make a Snippet for the code above this and then write your logic in main()\nfunction main() {\n const input = readline().split(' ').map(Number)\n const [goodRoundProblems, preparedProblems] = input\n const goodComplexities = readline().split(' ').map(Number)\n const preparedComplexities = readline().split(' ').map(Number)\n helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)\n}\n\nfunction helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {\n let cnt = 0\n let j = 0\n for (let i = 0; i < goodRoundProblems; i++) {\n const goodComplexity = goodRoundProblems[i]\n while (goodComplexity > preparedComplexities[j]){\n j++\n }\n if (j === preparedProblems - 1) {\n console.log(goodRoundProblems - i - 1)\n return\n }\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const requirements = `0 ${readLine()}`.split(' ').map(Number);\n const complexities = `0 ${readLine()}`.split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = georgeAndRound(n, m, requirements, complexities);\n printResult(result.toString());\n}\n\nconst georgeAndRound = (n, m, a, b) => {\n const counts = new Array(Math.pow(10, 6) + 1);\n for (let i = 1; i <= m; i++) counts[b[i]] = 1;\n let appearance = 0;\n for (let i = 1; i <= n; i++) {\n if (counts[a[i]]) appearance++;\n }\n\n return n - appearance;\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const requirements = readLine().split(' ').map(Number);\n const complexities = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = georgeAndRound(n, m, requirements, complexities);\n printResult(result.toString());\n}\n\nconst georgeAndRound = (n, m, a, b) => {\n const counts = new Array(Math.pow(10, 6) + 1);\n for (let i = 0; i < m; i++) {\n counts[b[i]] = 1;\n }\n let appearance = 0;\n for (let i = 0; i < n; i++) {\n if (counts[a[i]]) appearance++;\n }\n\n return n - appearance;\n};\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction printResult(x) {\n process.stdout.write(x);\n}\n\nfunction main() {\n const nm = readLine().split(' ').map(Number);\n const requirements = readLine().split(' ').map(Number);\n const complexities = readLine().split(' ').map(Number);\n\n const n = nm[0];\n const m = nm[1];\n\n // console.log(nm, requirements, complexities)\n const result = georgeAndRound(n, m, requirements, complexities);\n printResult(result.toString());\n}\n\nconst georgeAndRound = (n, m, a, b) => {\n let appearance = 0;\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (b[j] >= a[i]) {\n appearance++;\n i++;\n }\n }\n }\n\n return Math.max(0, n - appearance);\n};\n"}, {"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar a=readline().split(' ').map(function(v){return +v;});\nvar b=readline().split(' ').map(function(v){return +v;});\n\nvar map={};\nb.forEach(function(v){\n\tmap[v]=true;\n});\n\nvar ans=0;\na.forEach(function(v){\n\tif(!map[v]){\n\t\tans++;\n\t}\n});\nprint(ans);"}, {"source_code": "\nvar l=readline().split(' ');\nvar n=+l[0];\nvar m=+l[1];\nvar a=readline().split(' ').map(function(v){return +v;});\nvar b=readline().split(' ').map(function(v){return +v;});\n\nvar map={};\nb.forEach(function(v){\n\tmap[v]=true;\n});\n\nvar ans=0;\na.forEach(function(v){\n\tif(!ans[v]){\n\t\tans++;\n\t}\n});\nprint(ans);"}, {"source_code": ";(function () {\n\n print(function () {\n var n = readline().split(' ').map(Number),\n m = n[1],\n a = readline().split(' ').map(Number),\n b = readline().split(' ').map(Number),\n r = Math.min(n[0], m),\n t = 0;\n n = n[0];\n\n for (var i = 0; i < r; i++) {\n if (b[m - i - 1] < a[n - i - 1]) t++;\n }\n\n return t + n - i;\n }());\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\n print(function () {\n var n = readline().split(' ').map(Number),\n m = n[1],\n a = readline().split(' ').map(Number),\n b = readline().split(' ').map(Number),\n r = 0,\n t = 0;\n n = n[0];\n\n for (var i = 0; i < a.length; i++) {\n t = b.indexOf(a[i]);\n if (t !== -1) {\n b.splice(t, 1);\n a.splice(i, 1);\n i--;\n }\n }\n\n if (a.length === 0) return 0;\n n = a.length;\n m = b.length;\n t = 0;\n r = Math.min(n, m)\n\n for (var i = 0; i < r; i++) {\n if (b[m - i - 1] < a[n - i - 1]) t++;\n }\n\n return t + n - i;\n }());\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\t\n\tprint(function (n, m) {\n\t\tvar a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),\n\t\t\tb = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),\n\t\t\tk = 0;\n\n\t\tfor (var i = 0, j = 0; i < n; i++) {\n\t\t\tif (b[j]) {\n\t\t\t\tif (b[j] >= a[j]) j++;\n\t\t\t\telse {\n\t\t\t\t\tvar t = b.indexOf(a[j]);\n\t\t\t\t\tif (t === -1) k++;\n\t\t\t\t\telse j = t + 1;\t\n\t\t\t\t};\n\t\t\t} else k ++;\n\t\t}\n\n\t\treturn k;\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));"}, {"source_code": ";(function () {\n\n print(function () {\n var n = readline().split(' ').map(Number),\n m = n[1],\n a = readline().split(' ').map(Number),\n b = readline().split(' ').map(Number);\n n = n[0];\n\n for (var i = 0; i < a.length; i++) {\n var t = b.indexOf(a[i]);\n if (t !== -1) {\n b.splice(t, 1);\n a.splice(i, 1);\n i--;\n }\n }\n\n if (a.length === 0) return 0;\n n = a.length;\n m = b.length;\n\n for (var i = a.length; i > -1; i--) {\n var r = a[i],\n m = Math.max(b);\n\n if (m > r) {\n a.splice(i, 1);\n var t = b.indexOf(m);\n b.splice(t, 1);\n i++;\n }\n }\n\n if (a.length === 0) return 0;\n return a.length;\n }());\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\n print(function () {\n var n = readline().split(' ').map(Number),\n m = n[1],\n a = readline().split(' ').map(Number),\n b = readline().split(' ').map(Number),\n r = 0,\n t = 0;\n n = n[0];\n\n for (var i = 0; i < a.length; i++) {\n t = b.indexOf(a[i]);\n if (t !== -1) {\n b.splice(t, 1);\n a.splice(i, 1);\n i--;\n }\n }\n\n if (a.length === 0) return 0;\n n = a.length;\n m = b.length;\n t = 0;\n r = Math.min(n, m)\n\n for (var i = 0; i < r; i++) {\n if (b[i] < a[i]) t++;\n }\n\n return t + n - i;\n }());\n\n}.call(this));\n"}, {"source_code": "var line = readline().split(\" \");\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\n\nvar complexes = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar problems = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar result = 0;\nfor (var i = 0; i < complexes.length; i++) {\n var found = false;\n var foundBigger = false;\n\n for (var u = 0; u < problems.length; u++) {\n if (problems[u] > complexes[i] && complexes[i] > 0) {\n foundBigger = true;\n break;\n } else if (complexes[i] == problems[u]) {\n found = true;\n break;\n }\n }\n\n if (!found && !foundBigger) {\n result++;\n }\n}\n\nprint(result);\n"}, {"source_code": "var line = readline().split(\" \");\nvar n = parseInt(line[0]);\nvar m = parseInt(line[1]);\n\nvar complexes = readline().split(\" \").map(function(x) { return parseInt(x); });\nvar problems = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar result = 0;\nfor (var i = 0; i < complexes.length; i++) {\n var found = false;\n var foundBigger = false;\n \n for (var u = 0; u < problems.length; u++) {\n if (problems[u] > complexes[i]) {\n foundBigger = true;\n } else if (complexes[i] == problems[u]) {\n found = true;\n break;\n }\n }\n\n if (!found && !foundBigger) {\n result++;\n }\n}\n\nprint(result);\n"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var m = line[1];\n \n var a = readline().split(' ').map(Number);\n var b = readline().split(' ').map(Number);\n a.sort((a,b) => b- a);\n b.sort((a,b) => a-b);\n var used = [];\n var res = 0;\n for(var i=0;i= a[i]){\n found = true;\n used[j] = true;\n }\n }\n if(!found){\n res++;\n }\n }\n print(res)\n}\n\n\nmain()"}], "src_uid": "bf0422de4347a308d68a52421fbad0f3"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort((a, b) => a - b);\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[0]++;\n numbers[1]++;\n\n if (numbers[0] !== numbers[2]) numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[2]--;\n numbers[1]--;\n\n if (numbers[2] !== numbers[0]) numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n", "positive_code": [{"source_code": "'use strict'\n\nconst dist = (a, b, c) => Math.abs(a-b) + Math.abs(a-c) + Math.abs(b-c);\n\nconst problem = (a, b, c) => {\n let r = Infinity;\n for (let i = -1; i < 2; i++) {\n const A = a + i;\n for (let j = -1; j < 2; j++) {\n const B = b + j;\n for (let k = -1; k < 2; k++) {\n const C = c + k;\n r = Math.min(r, dist(A,B,C));\n }\n }\n }\n return r;\n}\nlet q = +readline();\n\nwhile(q--) {\n const abc = readline().split(' ').map(i => +i);\n print(problem(abc[0], abc[1], abc[2]));\n}\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let i = 0; i < t; i++) {\n const arrN = arr[i].split(' ').map(a => parseInt(a))\n arrN.sort((a, b) => a - b)\n\n let a = arrN[0]\n let b = arrN[1]\n let c = arrN[2]\n if(a != b && b == c) {\n b--\n c--\n a++\n if(a > b) a--\n }\n else if(c != b && b == a) {\n b++\n c--\n a++\n if(c < a) c++\n }\n else if(a != b && b != c) {\n a++\n c--\n }\n\n // console.log(a, b, c)\n\n console.log(Math.abs(a - b) + Math.abs(a - c) + Math.abs(c - b))\n }\n})"}, {"source_code": "var toInt = x => parseInt(x);\nvar n = parseInt(readline());\nvar check = (a, b, c) => (Math.abs(a-b)+Math.abs(b-c)+Math.abs(a-c));\nvar ar = new Array(n).fill('').map(readline).map(l=>l.split(' ').map(toInt));\nar.forEach(a => {\n var best = Number.MAX_SAFE_INTEGER;\n for(var i=-1; i<=1;i++) {\n for(var j=-1; j<=1;j++) {\n for(var k=-1; k<=1;k++) {\n best = Math.min(best, check(a[0]+i, a[1]+j, a[2]+k));\n }\n }\n }\n print(best);\n \n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n data.sort((a,b) => a - b);\n let [a, b, c] = data;\n if (a < b && b < c) {\n a++;\n c--;\n } else if (a === b) {\n if (b < c) c--;\n if (b < c) c--;\n } else if (b === c) {\n if (a < b) a++;\n if (a < b) a++;\n }\n return b - a + c - a + c - b;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "function myin(){return require(\"fs\").readFileSync(\"/dev/stdin\", \"utf8\").trim();}\nfunction myout(t){print(t);}//standard output\n//function myout(t){console.log(t);}//standard output\nfunction myerr(t){console.err(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n \nfunction Main() {\n //input = myconv(input,3);\n var N = myconv(readline(),1);\n var output = [];\n for(var i = 0; i < N; i++){\n var tmp = myconv(readline(),4).sort(function(a,b){return myconv(a,1)-myconv(b,1);});\n var a = tmp[0];\n var b = tmp[1];\n var c = tmp[2];\n var da = a+1;\n var dc = c-1;\n \n if(c-a > 2){\n if(b == c){\n b = dc;\n }else{\n b = da;\n }\n output.push(Math.abs(da-b)+Math.abs(da-dc)+Math.abs(dc-b));\n }else{\n output.push(0); \n }\n }\n myout(output.join(\"\\n\"));\n}\n \nMain();"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const max = Math.max(...arr);\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < max) {\n arr[i]++;\n }\n }\n\n const min = Math.min(...arr);\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > min) {\n arr[i]--;\n }\n }\n\n const ans = Math.abs(arr[0] - arr[1]) + Math.abs(arr[0] - arr[2]) + Math.abs(arr[1] - arr[2]);\n\n console.log(ans);\n\n count++;\n});\n"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var inp = readline().split(' ');\n \n for(var j=0; j<3; j++) {\n inp[j] = parseInt(inp[j], 10);\n }\n \n inp.sort((a,b) => a-b);\n \n if(inp[0] === inp[1] && inp[0] !== inp[2]) {\n inp[0] += 1;\n inp[1] += 1;\n \n if(inp[2] !== inp[1]) inp[2] -= 1;\n \n } else if(inp[2] === inp[1] && inp[2] !== inp[0]) {\n inp[1] -= 1;\n inp[2] -= 1;\n \n if(inp[0] !== inp[1]) inp[0] += 1;\n \n } else if(inp[0] !== inp[1] && inp[0] !== inp[2] && inp[1] !== inp[2]) {\n inp[0] += 1;\n inp[2] -= 1;\n }\n \n print(Math.abs(inp[0]-inp[1]) + Math.abs(inp[0]-inp[2]) + Math.abs(inp[1]-inp[2]));\n}"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const [a, b, c] = line.split(' ').map(Number);\n let minDist = dist(a, b, c);\n for (let i = -1; i <= 1; i++) {\n for (let j = -1; j <= 1; j++) {\n for (let l = -1; l <= 1; l++) {\n minDist = Math.min(minDist, dist(a + i, b + j, c + l));\n }\n }\n }\n console.log(minDist);\n });\n});"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n\ntxt.shift();\n\nfor (let i = 0; i < txt.length; i++) {\n let info = txt[i].split(\" \").filter(data => {\n return data.length > 0;\n }).map(data => {\n return data * 1;\n });\n doit(info);\n\n}\n\nfunction doit(tab) {\n let mid = Math.round((tab[0] + tab[1] + tab[2]) / 3);\n for (let i = 0; i < tab.length; i++) {\n if (tab[i] < mid) {\n ++tab[i];\n } else if (tab[i] > mid) {\n --tab[i];\n }\n }\n console.log(Math.abs(tab[0] - tab[1]) + Math.abs(tab[0] - tab[2]) + Math.abs(tab[2] - tab[1]));\n}"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[0]++;\n numbers[1]++;\n\n // if (numbers[0] !== numbers[2]) numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[2]--;\n numbers[1]--;\n\n if (numbers[2] !== numbers[0]) numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[0]++;\n numbers[1]++;\n\n // if (numbers[0] !== numbers[2]) numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[2]--;\n numbers[1]--;\n\n // if (numbers[2] !== numbers[0]) numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[0]++;\n numbers[1]++;\n\n if (numbers[0] !== numbers[2]) numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[2]--;\n numbers[1]--;\n\n if (numbers[2] !== numbers[0]) numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] < numbers[1]) ++numbers[0];\n\n if (numbers[2] > numbers[1]) --numbers[2];\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\n\n\nrl.on('line', (input) => {\n if (q === null) {\n q = +input;\n } else { \n solve(input.split(' ').map(number => +number));\n readedLines++;\n }\n\n if (q === readedLines) {\n rl.close();\n }\n});\n\nlet q = null;\nlet readedLines = 0;\n\nconst solve = numbers => {\n numbers.sort();\n\n if (numbers[0] !== numbers[2]) {\n if (numbers[0] === numbers[1]) {\n numbers[0]++;\n numbers[1]++;\n\n // if (numbers[0] !== numbers[2]) numbers[2]--;\n } else if (numbers[2] === numbers[1]) {\n numbers[2]--;\n numbers[1]--;\n\n if (numbers[2] !== numbers[0]) numbers[0]++;\n } else {\n numbers[0]++;\n numbers[2]--;\n }\n }\n\n console.log(numbers);\n\n console.log(\n (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])\n );\n};\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n if (arr[0] < arr[1]) {\n arr[0]++;\n }\n if (arr[2] >= arr[1]) {\n arr[2]--;\n }\n\n const ans = Math.max(0, (arr[2] - arr[1]) + (arr[2] - arr[0]) + (arr[1] - arr[0]));\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n if (arr[0] < arr[1]) {\n arr[0]++;\n }\n if (arr[2] >= arr[1]) {\n arr[2]--;\n }\n\n const ans = arr[2] - arr[1] + arr[2] - arr[0] + arr[1] - arr[0];\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n\n if (arr[0] < arr[1]) {\n arr[0]++;\n }\n\n if (arr[2] > arr[1]) {\n arr[2]--;\n }\n else if (arr[1] !== arr[0] && arr[1] !== arr[2]) {\n arr[1]--;\n }\n else {\n if (arr[1] === arr[2] && arr[1] !== arr[0]) {\n arr[1]--;\n arr[2]--;\n }\n else if (arr[1] === arr[0] && arr[1] !== arr[2]) {\n arr[1]++;\n arr[0]++;\n }\n }\n\n const ans = Math.abs(arr[0] - arr[1]) + Math.abs(arr[0] - arr[2]) + Math.abs(arr[1] - arr[2]);\n\n console.log(ans);\n\n count++;\n});\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n\ntxt.shift();\n\nfor (let i = 0; i < txt.length; i++) {\n let info = txt[i].split(\" \").filter(data => {\n return data.length > 0;\n }).map(data => {\n return data * 1;\n });\n doit(info);\n\n}\n\nfunction doit(tab) {\n let mid = Math.floor((tab[0] + tab[1] + tab[2]) / 3);\n for (let i = 0; i < tab.length; i++) {\n if (tab[i] < mid) {\n ++tab[i];\n } else if (tab[i] > mid) {\n --tab[i];\n }\n }\n console.log(Math.abs(tab[0] - tab[1]) + Math.abs(tab[0] - tab[2]) + Math.abs(tab[2] - tab[1]));\n}"}], "src_uid": "18f2e54e4147e8887da737d5b6639473"} {"source_code": "var n, k, s, cnt, ans;\nvar token = [];\n\nvar i;\n\ntoken = readline().split(' ');\n\nn = parseInt(token[0]);\nk = parseInt(token[1]);\n\ns = readline();\n\ncnt = new Array(k);\nfor(i=0;i {\n if (c === 0) {\n c++;\n [n, k] = d.split(' ').map(Number);\n return;\n }\n\n const str = d;\n const frequence = {};\n\n for (let i = 0; i < str.length; i++) {\n if (frequence[str[i]]) {\n frequence[str[i]]++;\n }\n else {\n frequence[str[i]] = 1;\n }\n }\n\n const values = Object.values(frequence);\n\n if (values.length !== k) {\n console.log(0);\n }\n else {\n const min = Math.min(...values);\n console.log(k*min);\n }\n\n c++;\n});\n"}, {"source_code": "var ip = readline().split(' ').map(Number);\nvar n = ip[0], k = ip[1];\nvar ar = new Array(26);\nfor (i=0;i<26;i++){\n ar[i] = 0;\n}\nvar min = 1000000;\nreadline().split('').forEach(x=>ar[x.charCodeAt()-65]++);\nfor (i = 0;i64+k) {\n // write(\"0\");\n // }\n var index = arr.findIndex(function(el) {return el.char == str[i]});\n if (index == -1)\n arr.push({char:str[i], number: 1});\n else {\n arr[index].number++;\n }\n}\nif (arr.length != k)\n print(0);\nelse\n print(getMinOfArray(arr.map(function(el) {return el.number}))*k);\n\nfunction getMinOfArray(numArray) {\n return Math.min.apply(null, numArray);\n}"}, {"source_code": "\nvar alphapet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',\n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'\n];\n\nvar arr = readline().split(\" \").map((elem) => {\n return parseInt(elem);\n});\nvar str = readline();\n\nvar n = arr[0],\n k = arr[1];\n\nvar arrTmp = alphapet.splice(0, k);\nflag = true;\n\narrTmp.forEach((elem) => {\n if (str.split(\"\").find((x) => {\n return x === elem;\n })) {\n flag = true;\n } else {\n flag = false;\n }\n})\nif (!flag) {\n print(0);\n} else {\n var counterArray = [];\n for(i=0;i{\n if(el !== elem){\n el = elem;\n i++; \n }\n counterArray[i]++; \n })\n mn = Math.min(...counterArray);\n print(k*mn);\n \n}"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n\tvar one = nextIntArray();\n\tvar N = one[0];\n\tvar K = one[1];\n\tvar alpha = \"ABCFEFGHIJKLMNOPQESTUVWXYZ\";\n\tvar map = {};\n\tfor(var i = 0; i < K; i++){\n\t\tmap[alpha[i]] = 0;\n\t}\n\tvar list = next();\n\tfor(var i = 0; i < N; i++){\n\t\tmap[list[i]]++;\n\t}\n\tvar min = N;\n\tvar keys = Object.keys(map);\n\tfor(var i = 0; i < keys.length; i++){\n\t\tmin = Math.min(min, map[keys[i]]);\n\t}\n\tmyout(min * K);\n}\n"}], "src_uid": "d9d5db63b1e48214d02abe9977709384"} {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let length = parseInt(readline());\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n\r\n let current = input[0];\r\n let counter = 0;\r\n let maxCounter = 0;\r\n\r\n for(let i = 0; i < length; i++){\r\n if(input[i] === current){\r\n counter++;\r\n } else {\r\n current = input[i];\r\n counter = 1;\r\n }\r\n\r\n if(counter > maxCounter){\r\n maxCounter = counter;\r\n }\r\n }\r\n\r\n print(maxCounter);\r\n}", "positive_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var s = 0\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var a = new Map()\n var k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n var temp = a.get(k[l])\n temp++\n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n }\n }\n var biggestKey = ''\n var biggestValue = 0\n for(var[key, value] of a){\n if(value > biggestValue){\n biggestValue = value \n biggestKey=key \n }\n }\n console.log(biggestValue)\n }else{\n e = lines[j]\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var a = new Map()\n var k = lines[j].split(' ')\n for(l = 0 ;l < e; l++){\n if(a.has(k[l])){\n var temp = a.get(k[l])\n temp++\n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n }\n }\n var biggestValue = 0\n var biggestKey = ''\n for(var [key,value] of a){\n if(biggestValue < value){\n biggestKey = key\n biggestValue = value\n } \n }\n console.log(biggestValue)\n \n }else {\n e = lines[j]\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var a = new Map();\n for(j = 0; j < e; j++){\n if(a.has(k[j])){\n var te = a.get(k[j]);\n te++;\n a.set(k[j], te);\n }else{\n a.set(k[j], 1);\n }\n }\n var ans = 0;\n for(var [key, value] of a){\n if(value > ans){\n ans = value;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var t = lines[0];\n var e = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n e = lines[i]; \n }else{\n var k = lines[i].split(' ').map(Number);\n var a = new Map();\n for(j = 0; j < e; j++){\n if(a.has(k[j])){\n var temp = a.get(k[j]);\n temp++;\n a.set(k[j], temp);\n }else{\n a.set(k[j], 1);\n }\n }\n var ans = 0;\n for(var [key, value] of a){\n if(ans < value){\n ans = value;\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = parseInt(readline(), 10);\r\n\r\n for (let i = 0; i < t; i += 1) {\r\n readline();\r\n const a = readline().split(' ').map(num => parseInt(num, 10));\r\n let number = 1;\r\n let max = 1;\r\n\r\n a.forEach((item, index) => {\r\n if (item === a[index + 1]) {\r\n number += 1;\r\n return;\r\n }\r\n\r\n if (number > max) {\r\n max = number;\r\n }\r\n\r\n number = 1;\r\n });\r\n\r\n console.log(max);\r\n }\r\n}\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split('\\n').map(str => str.trim());\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n let t = readline();\r\n\r\n while (t--) {\r\n readline();\r\n const a = readline().split(' ').map(num => parseInt(num, 10));\r\n const r = [];\r\n\r\n a.forEach(item => {\r\n r.push(a.filter(next => next === item).length);\r\n });\r\n\r\n console.log(Math.max(...r));\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let arrLength = readline()\n let n = readline().split(' ').map(x => +x)\n // let n = line[0]\n // let k = line[1]\n // let ans = 0\n // ------------------\n // count the most occurrences and it is the answer\n let myMap = new Map()\n for (let i = 0; i < n.length; i++) {\n // if (myMap.has(n[i])){\n if (myMap.has(n[i])) {\n myMap.set(n[i], myMap.get(n[i]) + 1)\n // console.log('IF myMap = ', myMap)\n }\n else {\n myMap.set(n[i], 1)\n // console.log('myMap = ', myMap)\n }\n }\n let max = 0\n // console.log(myMap.keys())\n // console.log('map entries = ', myMap.entries())\n for (const [key, value] of myMap.entries()) {\n max = (value > max) ? +value: max\n }\n console.log(max)\n}"}, {"source_code": "function main(lines) {\n const T = parseInt(lines[0], 10);\n for (let i = 0; i < T; i++) {\n const index = 1 + i * 2;\n const n = parseInt(lines[index], 10);\n const str = lines[index + 1];\n const arr = str.split(' ').map((item) => parseInt(item, 10));\n let j = 1;\n let max = 1;\n let currentValue = 1;\n while (j < arr.length) {\n if (arr[j] === arr[j - 1]) {\n currentValue += 1;\n } else {\n max = Math.max(max, currentValue);\n currentValue = 1;\n }\n j += 1;\n }\n max = Math.max(max, currentValue);\n console.log(max);\n }\n}\n\nlet inputString = '';\n\nprocess.stdin.on('data', (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', (_) => {\n inputString = inputString.trim().split('\\n').map((string) => string.trim());\n\n main(inputString);\n});\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (data) => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map((str) => str.trim());\n\tmain();\n});\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n\tfor (var a = arguments, r = a[0], i = a.length; --i; )\n\t\tr = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n\treturn r;\n}\nfunction inv(b) {\n\tfor (var a = MOD, u = 0, v = 1, t; b; v = t)\n\t\t(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n\tu %= MOD;\n\treturn u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n\tif (n === 0) return 1;\n\tlet p = pow(base, Math.floor(n / 2));\n\tlet res = mul(mod(p), mod(p));\n\tif (n % 2 === 1) res = mul(mod(res), base);\n\treturn res;\n}\nfunction highestOneBit(i) {\n\ti |= i >> 1;\n\ti |= i >> 2;\n\ti |= i >> 4;\n\ti |= i >> 8;\n\ti |= i >> 16;\n\treturn i - (i >>> 1);\n}\nfunction permutation(arr, len, store = '', permutations = []) {\n\tif (store.length === len) {\n\t\tpermutations.push(store);\n\t\treturn;\n\t}\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst newArr = [...arr];\n\t\tconst newChar = newArr.splice(i, 1);\n\t\tpermutation(newArr, len, store.concat(newChar), permutations);\n\t}\n\treturn permutations;\n}\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction main() {\n\tlet t = +readLine();\n\twhile (t--) {\n\t\tconst len = +readLine();\n\t\tconst arr = readLine().split(' ').map(Number);\n\t\tconst map = new Map();\n\t\tfor (let n of arr) {\n\t\t\tmap.set(n, (map.get(n) || 0) + 1);\n\t\t}\n\t\tconst f = [...map.values()].sort((a, b) => a - b);\n\t\tconsole.log(f[f.length - 1]);\n\t}\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var n = Number(readline());\r\n var array = readline().split(' ').map(x=>Number(x));\r\n var current = 0\r\n var number = 0\r\n var max = 0\r\n array.map((x,i)=>{\r\n if(i===array.length) return;\r\n // console.log(current, x)\r\n if(x === array[i+1]){\r\n number++\r\n return\r\n }\r\n if(number > max) {\r\n max = number\r\n }\r\n number = 0\r\n })\r\n console.log(max +1)\r\n // console.log(array)\r\n\r\n })\r\n\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet curLine = 0;\r\n\r\nfunction readLine() {\r\n return standardInputString[curLine++];\r\n}\r\n\r\nprocess.stdin.on(\"data\", rawData => {\r\n standardInputString += rawData;\r\n});\r\n\r\nprocess.stdin.on(\"end\", _ => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map(line => {\r\n return line.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\n\r\n\r\n// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A\r\n\r\n// function main() {\r\n// const testQuantity = +readLine();\r\n// for (let testNumber = 0; testNumber < testQuantity; testNumber++) {\r\n// let inputString = readLine();\r\n// let curLen = 0;\r\n// let curPrefix = \"\";\r\n// let maxPrefixLen = 0;\r\n\r\n// for (let inputChar of inputString) {\r\n// curPrefix += inputChar;\r\n// curLen++;\r\n\r\n// let foundNew = true;\r\n// let medianIndex = Math.floor(curLen / 2);\r\n// for (; medianIndex >= 0; medianIndex--) {\r\n// if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {\r\n// foundNew = false;\r\n// break;\r\n// }\r\n// }\r\n\r\n// if (foundNew) {\r\n// maxPrefixLen = curLen;\r\n// }\r\n// }\r\n\r\n// console.log(maxPrefixLen);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem B\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// let counter = 0;\r\n\r\n// for (let curLen = 0; curLen <= inputStr.length; curLen++) {\r\n// for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {\r\n// let substring = inputStr.substring(startIx, startIx + curLen);\r\n// let prefix = inputStr.substring(0, curLen);\r\n// let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);\r\n\r\n// if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {\r\n// counter++;\r\n// }\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem C\r\n\r\n// function match(text, pattern) {\r\n// if (pattern.length > text.length) {\r\n// return false;\r\n// }\r\n\r\n// for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {\r\n// if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== \"?\") {\r\n// return false;\r\n// }\r\n// }\r\n\r\n// return true;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// const entryIndexes = [];\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {\r\n// entryIndexes.push(startIx);\r\n// }\r\n// }\r\n\r\n// console.log(entryIndexes.length);\r\n// console.log(entryIndexes.join(\" \"));\r\n// }\r\n// }\r\n\r\n\r\n// .. -> Problem D\r\n\r\n// function getSubstrQuan(length) {\r\n// return (length + 1) * (length) / 2;\r\n// }\r\n\r\n// function main() {\r\n// const testQuan = +readLine();\r\n// for (let testIx = 0; testIx < testQuan; testIx++) {\r\n// const inputStr = readLine();\r\n// const inputPattern = readLine();\r\n// let entryBorders = [];\r\n// let counter = 0;\r\n\r\n// for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {\r\n// if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {\r\n// entryBorders.push([startIx, startIx + inputPattern.length - 1]);\r\n// }\r\n// }\r\n \r\n// entryBorders.push([inputStr.length, inputStr.length]);\r\n// let lastLeftBorder = 0;\r\n// for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {\r\n// let curPair = entryBorders[pairIx];\r\n// let curSubstrLen = curPair[1] - lastLeftBorder;\r\n// counter += getSubstrQuan(curSubstrLen);\r\n// lastLeftBorder = curPair[0] + 1;\r\n\r\n// if (curPair[1] - curPair[0] - 1 > 0) {\r\n// counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);\r\n// }\r\n// }\r\n\r\n// console.log(counter);\r\n// }\r\n// }\r\n\r\n\r\n\r\n// Codeforces Round #698 (Div. 2) -> Problem A\r\n\r\nfunction main() {\r\n let testQuan = +readLine();\r\n for (let testIx = 0; testIx < testQuan; testIx++) {\r\n let n = +readLine();\r\n let a = readLine().split(\" \");\r\n a = a.map(item => +item);\r\n let counterArr = [];\r\n for (let i = 0; i <= n; i++) counterArr[i] = 0;\r\n\r\n for (let el of a) {\r\n counterArr[el]++; \r\n }\r\n\r\n console.log(Math.max(...counterArr));\r\n }\r\n}"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline()\r\n a = readline().split(' ').map(x => +x)\r\n ans = 1\r\n repeats = 0\r\n newrepeats = 0\r\n for(i = 0; i < n; i++ ){\r\n if(a[i]==a[i+1]){\r\n newrepeats++\r\n if(newrepeats>repeats)\r\n repeats = newrepeats \r\n } \r\n else\r\n newrepeats = 0\r\n }\r\n ans += repeats\r\n print(ans)\r\n}\r\n"}, {"source_code": "function solve(a){\n var l = 1, res = 1;\n for(var i = 1; i < a.length; i++){\n if(a[i] == a[i-1]){\n l++;\n res = Math.max(l, res);\n }else{\n l = 1;\n }\n }\n return res;\n}\n \nvar a = [];\nvar t = Number(readline());\nfor (var i = 0; i x);\n write(solve(a)+'\\n');\n}"}, {"source_code": "function solve(a){\r\n var l = 0;\r\n var c = 0;\r\n var min = 0;\r\n var aux = a[l];\r\n while(l < a.length){\r\n if(a[l] == aux){\r\n c++;\r\n }else{\r\n aux= a[l];\r\n c = 1;\r\n }\r\n min = c > min ? c : min;\r\n l++;\r\n }\r\n return min;\r\n \r\n}\r\n \r\nvar a = [];\r\nvar t = Number(readline());\r\nfor (var i = 0; i x);\r\n write(solve(a)+'\\n');\r\n}"}, {"source_code": "var t = parseInt(readline());\r\n while (t--) {\r\n var n=parseInt(readline())\r\n var line = readline();\r\n var a = line.split(' ');\r\n var b = new Array(n+1);\r\n for(var i=1;i<=n;i++) b[i]=0;\r\n var ans = 0;\r\n for (var i = 0; i < n; i++) {\r\n b[a[i]]++;\r\n ans = (ans i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var s = 0\n var e = 0\n var a = new Map()\n for(j = 1; j <= n * 2; j++){\n if(j % 2 === 0){\n var k = lines[j].split(' ').map(Number)\n for(l = 0; l < e; l++){\n if(a.has(k[l])){\n var temp = a.get(k[l])\n temp++\n a.set(k[l], temp)\n }else{\n a.set(k[l], 1)\n }\n }\n var biggestKey = ''\n var biggestValue = 0\n for(var[key, value] of a){\n if(value > biggestValue){\n biggestValue = value \n biggestKey=key \n }\n }\n console.log(biggestValue)\n }else{\n e = lines[j]\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n \n for(j = 1; j <= n*2; j ++){\n if(j % 2 === 0){\n var one = 0\n var two = 0\n var three = 0\n var four = 0\n var a = lines[j].split(' ').map(Number)\n for(k = 0; k < e; k++){\n if(a[k] == 1){\n one++\n }else if(a[k] == 2){\n two++\n }else if(a[k] == 3){\n three++\n }else if(a[k] == 4){\n four++\n }\n }\n console.log(Math.max(one, Math.max(two, Math.max(three, four))))\n }else{\n var e = lines[j]\n }\n }\n \n});\n "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0]\n var a = new Map()\n for(j = 1; j <= n*2; j ++){\n a.clear()\n if(j % 2 === 0){\n var s = lines[j].split(' ').map(Number)\n for(k = 0; k < e; k++){\n if(a.has(s[k])){\n var temp = a.get(s[k])\n a.set(s[k], temp + 1)\n }else{\n a.set(s[k], 1)\n }\n }\n console.log(a.size)\n\n }else{\n var e = lines[j]\n }\n }\n \n});\n "}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline()\r\n a = readline().split(' ').map(x => +x)\r\n ans = 1\r\n repeats = 1\r\n newrepeats = 1\r\n for(i = 0; i < n; i++ ){\r\n if(a[i]==a[i+1]){\r\n newrepeats++\r\n if(newrepeats>repeats)\r\n repeats = newrepeats \r\n } \r\n else\r\n newrepeats = 0\r\n }\r\n ans = repeats\r\n print(ans)\r\n}"}, {"source_code": "function solve(a){\n var count = 1, l = 1;\n for(var i = 1; i < a.length; i++){\n if(a[i] == a[i-1]){\n if(l == 1 || count == 1) count++;\n l = 1;\n }else{\n l++;\n }\n }\n return count;\n}\n \nvar a = [];\nvar t = Number(readline());\nfor (var i = 0; i x);\n write(solve(a)+'\\n');\n}"}, {"source_code": "function solve(a){\r\n var l = 0;\r\n var c = 0;\r\n var min = 0;\r\n var aux = a[l];\r\n while(l < a.length){\r\n if(a[l] == aux){\r\n c++;\r\n }else{\r\n aux= a[l];\r\n c = 0;\r\n }\r\n min = c > min ? c : min;\r\n l++;\r\n }\r\n return min;\r\n \r\n}\r\n\r\nvar a = [];\r\nvar t = Number(readline());\r\nfor (var i = 0; i x);\r\n write(solve(a)+'\\n');\r\n}"}, {"source_code": "\"use strict\"\r\n\r\nlet iter = parseInt(readline());\r\n\r\nwhile(iter--){\r\n let length = parseInt(readline());\r\n let input = readline().split(\" \").map(x => parseInt(x));\r\n\r\n let current = input[0];\r\n let counter = 0;\r\n let maxCounter = 0;\r\n\r\n for(let i = 0; i < length; i++){\r\n if(input[i] === current){\r\n counter++;\r\n } else {\r\n current = input[i];\r\n if(counter > maxCounter){\r\n maxCounter = counter;\r\n }\r\n counter = 0;\r\n }\r\n }\r\n\r\n print(maxCounter === 0 ? counter : maxCounter);\r\n}"}], "src_uid": "6d4744d7356e709f73891270becd14e3"} {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet queriesNum;\nlet resultArr = [];\nlet temp = {};\nrl.on('line', function(line){\n if (lineCount === 0) {\n queriesNum = Number(line.trim());\n } else {\n if (lineCount % 2 === 0) {\n temp.arr = line.trim().split('').map((item) => Number(item));\n console.log(gasPipeline(temp))\n } else {\n let dealLine = line.trim().split(' ');\n temp.n = Number(dealLine[0]);\n temp.a = Number(dealLine[1]);\n temp.b = Number(dealLine[2]);\n }\n }\n if (resultArr.length === queriesNum) {\n rl.close();\n }\n lineCount ++;\n});\n\nfunction total(tempArr, prev, next, a, b) {\n let len = tempArr.length\n let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b\n let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b\n return Math.min(minRes, maxRes)\n}\n\nfunction gasPipeline(temp) {\n let {n, a, b, arr} = temp;\n let count = 0;\n let aMoney = 0;\n let bMoney = 2*b;\n let zeroTotal = 0;\n\n while (count < n) {\n let cur = arr[count];\n let prev = arr[count - 1];\n let temA = [];\n if (cur === 0) {\n while (cur === 0) {\n temA.push(cur);\n count++;\n cur = arr[count];\n }\n zeroTotal += total(temA, prev, arr[count], a, b);\n continue;\n }\n let tempB = [];\n while (cur === 1) {\n tempB.push(cur);\n count++;\n cur = arr[count];\n }\n let tempBLen = tempB.length;\n aMoney += tempBLen*a;\n bMoney += (tempBLen + 1)*2*b;\n }\n return zeroTotal + aMoney + bMoney;\n}", "positive_code": [{"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet queriesNum;\nlet resultArr = [];\nlet temp = {};\nrl.on('line', function(line){\n if (lineCount === 0) {\n queriesNum = Number(line.trim());\n } else {\n if (lineCount % 2 === 0) {\n // \u5076\u6570\u884c\n temp.arr = line.trim().split('').map((item) => Number(item));\n resultArr.push(gasPipeline(temp))\n } else {\n // \u5947\u6570\u884c\n let dealLine = line.trim().split(' ');\n temp.n = Number(dealLine[0]);\n temp.a = Number(dealLine[1]);\n temp.b = Number(dealLine[2]);\n }\n }\n if (resultArr.length === queriesNum) {\n console.log(resultArr.join('\\n'));\n rl.close();\n }\n lineCount ++;\n});\n\nfunction gasPipeline() {\n let {n, a, b, arr} = temp;\n // a:\u7ba1\u9053 b:\u67f1\u5b50\n let count = 0;\n let aMoney = 0;\n let bMoney = 2*b; // \u5f00\u59cb\u7ed3\u675f\u7684\u4f4e\u67f1\u5b50\n let zeroTotal = 0;\n\n function total(tempArr, prev, next) {\n // \u5168\u4e3a\u4f4e\n let len = tempArr.length\n // \u5168\u4e3a\u4f4e\u67f1\u5b50\n let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b\n // \u5168\u4e3a\u9ad8\u67f1\u5b50\n let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b\n return Math.min(minRes, maxRes)\n }\n\n while (count < n) {\n let cur = arr[count];\n let prev = arr[count - 1];\n let temA = [];\n if (cur === 0) {\n // \u5f53\u524d\u4e3a0\u65f6\n while (cur === 0) {\n temA.push(cur);\n count++;\n cur = arr[count];\n }\n zeroTotal += total(temA, prev, arr[count]);\n continue;\n }\n let tempB = [];\n while (cur === 1) {\n tempB.push(cur);\n count++;\n cur = arr[count];\n }\n let tempBLen = tempB.length;\n aMoney += tempBLen*a;\n // \u9ad8\u67f1\u5b50\n bMoney += (tempBLen + 1)*2*b;\n }\n return zeroTotal + aMoney + bMoney;\n}"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0;\nlet queriesNum;\nlet resultArr = [];\nlet temp = {};\nrl.on('line', function(line){\n if (lineCount === 0) {\n queriesNum = Number(line.trim());\n } else {\n if (lineCount % 2 === 0) {\n temp.arr = line.trim().split('').map((item) => Number(item));\n console.log(gasPipeline(temp))\n } else {\n let dealLine = line.trim().split(' ');\n temp.n = Number(dealLine[0]);\n temp.a = Number(dealLine[1]);\n temp.b = Number(dealLine[2]);\n }\n }\n if (resultArr.length === queriesNum) {\n rl.close();\n }\n lineCount ++;\n});\n\nfunction total(tempArr, prev, next, a, b) {\n let len = tempArr.length\n let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b\n let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b\n return Math.min(minRes, maxRes)\n}\n\nfunction gasPipeline() {\n let {n, a, b, arr} = temp;\n let count = 0;\n let aMoney = 0;\n let bMoney = 2*b;\n let zeroTotal = 0;\n\n while (count < n) {\n let cur = arr[count];\n let prev = arr[count - 1];\n let temA = [];\n if (cur === 0) {\n while (cur === 0) {\n temA.push(cur);\n count++;\n cur = arr[count];\n }\n zeroTotal += total(temA, prev, arr[count], a, b);\n continue;\n }\n let tempB = [];\n while (cur === 1) {\n tempB.push(cur);\n count++;\n cur = arr[count];\n }\n let tempBLen = tempB.length;\n aMoney += tempBLen*a;\n bMoney += (tempBLen + 1)*2*b;\n }\n return zeroTotal + aMoney + bMoney;\n}"}], "negative_code": [], "src_uid": "4fa609ef581f705df901f7532b52cf7c"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let map = new Map();\r\n for (let i = 0; i < n; i++) {\r\n const num = a[i];\r\n if (!map.has(num)) map.set(num, []);\r\n map.get(num).push(i);\r\n }\r\n let res = [];\r\n for (let [, arr] of map) {\r\n if (arr.length === 1) return -1;\r\n const N = arr.length;\r\n for (let i = 0; i < N; i++) {\r\n const j = arr[i];\r\n res[j] = arr[(i + 1) % N];\r\n }\r\n }\r\n return res.map(num => num + 1).join(' ');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res.push(solve(n, a));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n", "positive_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n if (n==1)\n return -1;\n let r = n-1;\n let perm = [];\n while (r>=0){\n let l = r;\n while (A[l-1]==A[r])\n l--;\n if (l==r)\n return -1;\n perm.push(l+1);\n for (let i=r; i>l; i--){\n perm.push(i+1);\n }\n r = l-1;\n }\n return perm.reverse();\n};\n \n"}, {"source_code": "function solve() {\r\n read();\r\n const a = readArray(Number);\r\n a.push(-1);\r\n const ans = [];\r\n let startIndex = 0;\r\n for (let i = 1; i < a.length; i++) {\r\n if (a[i] === a[startIndex]) {\r\n ans.push(i + 1);\r\n continue;\r\n }\r\n if (i === startIndex + 1) {\r\n write(-1);\r\n return;\r\n }\r\n ans.push(startIndex + 1);\r\n startIndex = i;\r\n }\r\n write(ans.join(' '));\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n if (n==1)\n return -1;\n let r = n-1;\n let perm = [];\n while (r>0){\n let l = r;\n while (A[l-1]==A[r])\n l--;\n if (l==r)\n return -1;\n perm.push(l+1);\n for (let i=r; i>l; i--){\n perm.push(i+1);\n }\n r = l-1;\n }\n return perm.reverse();\n};\n \n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = function(arg){\n let str = arg;\n if (arguments.length>1)\n str = Array.prototype.slice.call(arguments).join(' ');\n process.stdout.write(str+'\\n');\n};\nlet IS_MULTITEST, testN, tests;\nconst pcalc = (testN, toPrint)=>{\n let res = CALC(testN);\n if (Array.isArray(res)){\n toPrint.push(res.join(' '));\n } else if (Number.isFinite(res) || typeof res=='string'){\n toPrint.push(res+'');\n }\n if (process.env.DEBUG && toPrint.length){\n let ans = toPrint.pop();\n print(ans);\n let expected = tests[testN-1];\n if (expected){\n if (expected==ans)\n console.log('\\x1b[32m%s\\x1b[0m', 'correct'); \n else {\n console.log('\\x1b[31m%s\\x1b[0m', 'wrong, expected:', expected); \n }\n }\n }\n};\n\nconst main = ()=>{\n let toPrint = [];\n L('\\nSolving:');\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(testN, toPrint);\n } else {\n pcalc(1, toPrint);\n }\n if (toPrint.length){\n print(toPrint.join('\\n'));\n }\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`\\nTest #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\ntests = [\n``, // Test #1\n``, // Test #2\n``, // Test #3\n``, // Test #4\n``, // Test #5\n];\n\n// SOLUTION:\nIS_MULTITEST = true;\n \nconst CALC = (testN)=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n if (n==1)\n return -1;\n let r = n-1;\n let perm = [];\n while (r>0){\n let l = r;\n while (A[l-1]==A[r])\n l--;\n if (l==r)\n return -1;\n perm.push(l+1);\n for (let i=l; i currPos.y) {\n return 'upperKingdom';\n } else if (currPos.y > currPos.x) {\n return 'lowerKingdom';\n }\n}\n\nfunction checkForChanges() {\n var kingdomAfterMove = calcCurrentKingdom();\n if (kingdomAfterMove && kingdomAfterMove !== currentKingdom) {\n if (currentKingdom) {\n silverSpent++;\n }\n currentKingdom = kingdomAfterMove;\n }\n}\n\nfunction goUp() {\n currPos.y++;\n checkForChanges();\n}\n\nfunction goRight() {\n currPos.x++;\n checkForChanges();\n}\n\nfunction makeTheMove(direction) {\n direction === 'U' ? goUp() : goRight();\n}\n\nmoves.forEach(e => makeTheMove(e));\n\nprint(silverSpent);\n\n\n"}, {"source_code": "var a = Number(readline());\nvar b = readline().split('');\n\nvar loc = {x:0, y:0};\nvar coins = 0;\n\nfor(var i = 0; i < a; i++){\n\tif(b[i] === 'R'){\n\t\tloc.x+=1;\n\t} else if (b[i] ==='U'){\n\t\tloc.y+=1;\n\t}\n\tif(loc.x === loc.y){\n\t\tif(b[i] === b[i+1]){\n\t\t\tcoins++;\n\t\t}\n\t}\n}\n\nprint(coins);"}, {"source_code": "inputs = readline();\nmoves = parseInt(inputs);\nmovelist = readline();\n// print(moves+\" \"+movelist)\n\nvar pos = {\n x:0,\n y:0,\n onGate: false,\n sides:\"\",\n goUp:()=>{\n pos.isOnGate();\n pos.y = pos.y+1;\n if(pos.onGate && pos.sides === \"right\"){\n pos.sides = \"left\"\n return 1;\n } else {\n return 0;\n }\n },\n goRight: ()=>{\n pos.isOnGate();\n pos.x = pos.x+1;\n if(pos.onGate && pos.sides === \"left\"){\n pos.sides = \"right\"\n return 1;\n } else {\n return 0;\n }\n },\n isOnGate:()=>{\n if(pos.x === pos.y && pos.x != 0){\n pos.onGate = true;\n }else{\n pos.onGate = false;\n }\n }\n}\n\nvar cost = 0;\nif(movelist[0] === \"R\"){\n pos.sides = \"right\";\n pos.goRight();\n} else {\n pos.sides = \"left\";\n pos.goUp()\n}\nfor(move = 1; move < moves; move++){\n if(movelist[move] === \"R\"){\n cost += pos.goRight();\n }else if(movelist[move] === \"U\"){\n cost += pos.goUp();\n }\n // print(pos.x+\":\"+pos.y +\" (\"+cost+\")\" )\n}\nprint(cost);"}, {"source_code": "n = readline();\nstr = readline().split('');\n\nvar x = 0, y = 0, side = 'UP', count = 0;\n\nif (str[0] == 'R') {\n\tside = 'DOWN';\n};\n\nfor (var i = 0; i < n; i++) {\n\tif (str[i] == 'U') {\n\t\ty++;\n\t} else if (str[i] == 'R') {\n\t\tx++;\n\t};\n\n\tif (side == 'DOWN' && y == x + 1) {\n\t\tcount++;\n\t\tside = 'UP';\n\t} else if (side == 'UP' && x == y + 1) {\n\t\tcount++;\n\t\tside = 'DOWN';\n\t};\n};\n\nprint(count);\n\n"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\tlet n = inputReader.readNumber();\n\t\n\tlet str = inputReader.readLine();\n\tlet i =0;\n\tlet count = 0,x=0,y=0;\n\twhile(i{\n\tif(e === 'R'){\n\t\tloc.x+=1;\n\t} else if (e==='U'){\n\t\tloc.y+=1;\n\t}\n\tif(loc.x === loc.y){\n\t\tcoins++;\n\t}\n});\nprint(coins);"}], "src_uid": "e4381bd9f22c0e49525cc05cc5cd2399"} {"source_code": "var tok = null;\nvar index = 0;\nfunction next() {\n while (tok == null || index == tok.length) {\n tok = readline().split(' ');\n index = 0;\n }\n var res = tok[index++];\n return res;\n}\n\nfunction nextInt() {\n return parseInt(next());\n}\n\nfunction sortNumber(a, b) {\n return a - b;\n}\n\nfunction main() {\n var cX = [];\n var arrY = [];\n var n = nextInt();\n for (var i = 0; i < n; i++) {\n var x = nextInt();\n var y = nextInt();\n arrY[i] = y;\n if (typeof (cX[x]) == 'undefined') {\n cX[x] = 1;\n } else {\n cX[x]++;\n }\n }\n for (var i = 0; i < n; i++) {\n var same = cX[arrY[i]]||0;\n print((n - 1 + same) + \" \" + (n - 1 - same));\n }\n}\n\nmain();\n", "positive_code": [{"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar teamNum = parseInt(readline());\n\tfunction makeHash() {\n\t\tvar hash = {};\n\t\thash.increment = function(key) {\n\t\t\tif (this[key] === undefined) {\n\t\t\t\tthis[key] = 1;\n\t\t\t} else {\n\t\t\t\tthis[key] += 1;\n\t\t\t}\n\t\t};\n\t\thash.get = function(key) {\n\t\t\treturn this[key] || 0;\n\t\t}\n\t\treturn hash;\n\t}\n\tvar homeCount = makeHash(), awayCount = makeHash(),\n\t\tteams = [];\n\tfor (var i = 0; i < teamNum; ++i) {\n\t\tvar data = tokenizeIntegers(readline()),\n\t\t\thome = data[0], away = data[1];\n\t\thomeCount.increment(home);\n\t\tawayCount.increment(away);\n\t\tteams.push({ home: home, away: away });\n\t}\n\tfor (var i = 0; i < teamNum; ++i) {\n\t\tvar team = teams[i],\n\t\t\tconflict = homeCount.get(team.away);\n\t\tprint(teamNum-1+conflict, teamNum-1-conflict);\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\n var teamNum = readline().split(' ');\n\n\n function makeObj () {\n var hash = {};\n\n hash.add = function (key) {\n if(this[key] === undefined) {\n this[key] = 1;\n }else {\n this[key] +=1;\n }\n }\n\n hash.get = function (key) {\n return this[key] || 0;\n }\n\n return hash;\n\n }\n\n var homeCount = makeObj(), teams = [];\n\n for(var i =0; i < teamNum; i++){\n var colors = readline().split(' ');\n var home = colors[0];\n var away = colors[1];\n homeCount.add(home);\n\n teams.push({home : home, away : away})\n }\n\n\n for(var i=0; i < teamNum; i++) {\n var team=teams[i],\n confilct = homeCount.get(team.away);\n\n print(teamNum - 1 + confilct, teamNum - 1- confilct) ;\n }\n\n\n\n\n\n}\n\nmain();"}, {"source_code": "function main() {\n\n var teamNum = readline().split(' ');\n\n var teams = [];\n function makeObj () {\n var hash = {};\n\n hash.add = function (key) {\n if(this[key] === undefined) {\n this[key] = 1;\n }else {\n this[key] +=1;\n }\n }\n\n hash.get = function (key) {\n return this[key] || 0;\n }\n\n return hash;\n\n }\n\n var homeCount = makeObj(), awayCount = makeObj(),teams = [];\n\n for(var i =0; i < teamNum; i++){\n var colors = readline().split(' ');\n var home = colors[0];\n var away = colors[1];\n homeCount.add(home);\n awayCount.add(away);\n teams.push({home : home, away : away})\n }\n\n\n for(var i=0; i < teamNum; i++) {\n var team=teams[i],\n confilct = homeCount.get(team.away);\n\n print(teamNum - 1 + confilct, teamNum - 1- confilct) ;\n }\n\n\n\n\n\n}\n\nmain();"}, {"source_code": "var n = parseInt(readline());\nfunction trav(n, cb) {\n var i;\n for (i = 1; i <= n; i ++) {\n cb(i);\n }\n}\nfunction createZeroFilledArray() {\n return Array.apply( void 0, Array( 1e5 + 1 ) ).map(Number.prototype.valueOf, 0);\n}\n\nvar recX = createZeroFilledArray(),\n recY = createZeroFilledArray(),\n totX = createZeroFilledArray();\n\ntrav(n, function(cur) {\n recX[cur] = readline().split(\" \");\n recY[cur] = parseInt(recX[cur][1], 10);\n recX[cur] = parseInt(recX[cur][0], 10);\n totX[ recX[cur] ] ++;\n});\n\ntrav(n, function(cur) {\n var resX = (n - 1) + totX[ recY[cur] ],\n resY = 2 * (n - 1) - resX;\n print(resX, resY);\n});\n"}, {"source_code": ";(function () {\n\tprint(function (n) {\n\t\tvar a = [], m = {}, l = 2 * n - 2;\n\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\ts = readline().split(' ').map(Number);\n\t\t\ta.push(s); s = s[0];\n\t\t\tm[s] = m[s] ? m[s] + 1 : 1;\n\t\t}\n\n\t\treturn a.map(function (e) {\n\t\t\te = n - 1 + (m[e[1]] || 0 );\n\t\t\treturn [e, l - e].join(' ');\n\t\t}).join('\\n');\n\t}(+readline()));\n}.call(this));"}], "negative_code": [], "src_uid": "7899a22cee29bb96d671f6188f246c21"} {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var m = input[1];\n var A = [];\n for (var i = 0; i < n; ++i) {\n A.push(rdArN());\n }\n var dx = [0,1,0,1];\n var dy = [0,0,1,1];\n var check = function(x, y) {\n var f = true;\n for (var k = 0; k < 4; ++k) {\n f = f && (A[x + dx[k]][y + dy[k]] > 0);\n }\n return f;\n };\n var fill = function (x, y) {\n for (var k = 0; k < 4; ++k) {\n A[x + dx[k]][y + dy[k]] = 2;\n }\n };\n var fillOrder = []\n for (var i = 0; i < n-1; ++i) {\n for (var j = 0; j < m-1; ++j) {\n if (check(i, j)) {\n fill(i, j);\n fillOrder.push([i+1, j+1]);\n }\n }\n }\n var isFilled = true;\n for (var i = 0; i < n; ++i) {\n for (var j = 0; j < m; ++j) {\n if (A[i][j] === 1) {\n isFilled = false;\n }\n }\n }\n if (isFilled) {\n pr(fillOrder.length);\n for (var i = 0; i < fillOrder.length; ++i) {\n prAr(fillOrder[i]);\n }\n } else {\n pr(-1);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();", "positive_code": [{"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\n// let n = 3;\n// let m = 3;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\n// console.log(squareFilling(n, m, resultArray));\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n\n function getSquare (x, y) {\n try {\n return {\n topLeft: resultArray[x][y],\n topRight: resultArray[x + 1][y],\n bottomLeft: resultArray[x][y + 1],\n bottomRight: resultArray[x + 1][y + 1]\n }\n } catch (e) {\n return null\n }\n\n }\n\n function isConform (x, y) {\n let square = getSquare(x, y)\n if (!square) {\n return false\n }\n let { topLeft, topRight, bottomLeft, bottomRight } = square;\n return (topLeft * topRight * bottomLeft * bottomRight === 1);\n }\n\n while (x < n) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n } else if (resultArray[x][y] === 1) {\n // \u770b\u5468\u56f4\u6709\u6ca1\u6709\u53ef\u4ee5\u6ee1\u8db3\u7684\uff0c\u5982\u679c\u6ca1\u6709\uff0creturn -1\n if (!isConform(x-1, y-1) && !isConform(x, y-1) && !isConform(x-1, y)) {\n return -1;\n }\n }\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (x % 2 === 0) {\n // \u5076\u6570 \u5411\u53f3\n y+=1;\n if (y === m) {\n x += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u5de6\n y-=1;\n if (y === -1) {\n x += 1;\n }\n }\n }\n if (!operateSelect.length) {\n return 0;\n }\n let resStr = `${operateCount}\\n`\n let resArr = []\n operateSelect.forEach((item) => {\n resArr.push(item.join(' '))\n });\n return resStr + resArr.join('\\n');\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\nreturn\n\n// let n = 3;\n// let m = 2;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function isConform(x, y) {\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n let operateIndex = 0;\n// \u53d8\u6210\u4e00\u4e2a\u65b9\u9635\u4e4b\u540e\u7684\u603b\u957f\u5ea6\n let len = (n -1) * (m - 1);\n\n while (operateIndex < len) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n let curIdx = Math.floor((operateIndex + 1)/n);\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (curIdx % 2 === 0) {\n // \u5076\u6570 \u5411\u4e0b\n x+=1;\n if (x === (n - 1)) {\n x -=1;\n y += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u4e0a\n x-=1;\n }\n operateIndex++;\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return '';\n }\n return - 1;\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\nreturn\n\n// let n = 3;\n// let m = 2;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n\n function isConform(x, y) {\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n let operateIndex = 0;\n// \u53d8\u6210\u4e00\u4e2a\u65b9\u9635\u4e4b\u540e\u7684\u603b\u957f\u5ea6\n let len = (n -1) * (m - 1);\n\n while (operateIndex < len) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n let curIdx = Math.floor((operateIndex + 1)/n);\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (curIdx % 2 === 0) {\n // \u5076\u6570 \u5411\u4e0b\n x+=1;\n if (x === (n - 1)) {\n x -=1;\n y += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u4e0a\n x-=1;\n }\n operateIndex++;\n }\n if (!operateSelect.length) {\n return - 1;\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\n// let n = 3;\n// let m = 3;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1] \n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\n// console.log(squareFilling(n, m, resultArray));\n\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function getSquare (x, y) {\n return {\n topLeft: resultArray[x][y],\n topRight: resultArray[x + 1][y],\n bottomLeft: resultArray[x][y + 1],\n bottomRight: resultArray[x + 1][y + 1]\n }\n }\n\n function isConform (x, y) {\n let { topLeft, topRight, bottomLeft, bottomRight } = getSquare(x, y);\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft * topRight * bottomLeft * bottomRight !== 0);\n }\n\n while (x < n - 1) {\n if (\n x < n -1 \n && x > 0 \n && y > 0 \n && y < m -1 \n && resultArray[x][y] == 1\n && !isConform(x, y-1)\n && !isConform(x-1, y-1)\n && !isConform(x-1, y)\n ) {\n // \u5b64\u70b9\n return -1;\n }\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (x % 2 === 0) {\n // \u5076\u6570 \u5411\u53f3\n y+=1;\n if (y === (m - 1)) {\n y -=1;\n x += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u5de6\n y-=1;\n if (y === -1) {\n y = 0;\n x += 1;\n }\n }\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return -1;\n }\n return 0;\n }\n let resStr = `${operateCount}\\n`\n let resArr = []\n operateSelect.forEach((item) => {\n resArr.push(item.join(' '))\n });\n return resStr + resArr.join('\\n');\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\n// let n = 3;\n// let m = 3;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1] \n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\n// console.log(squareFilling(n, m, resultArray));\n\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function isConform(x, y) {\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n while (x < n - 1) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (x % 2 === 0) {\n // \u5076\u6570 \u5411\u53f3\n y+=1;\n if (y === (m - 1)) {\n y -=1;\n x += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u5de6\n y-=1;\n if (y === -1) {\n y = 0;\n x += 1;\n }\n }\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return -1;\n }\n return 0;\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\nreturn\n\n// let n = 3;\n// let m = 2;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function isConform(x, y) {\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n let operateIndex = 0;\n// \u53d8\u6210\u4e00\u4e2a\u65b9\u9635\u4e4b\u540e\u7684\u603b\u957f\u5ea6\n let len = (n -1) * (m - 1);\n\n while (operateIndex < len) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n let curIdx = Math.floor((operateIndex + 1)/n);\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (curIdx % 2 === 0) {\n // \u5076\u6570 \u5411\u4e0b\n x+=1;\n if (x === (n - 1)) {\n x -=1;\n y += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u4e0a\n x-=1;\n }\n operateIndex++;\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return -1;\n }\n return '';\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\n// let n = 3;\n// let m = 2;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function isConform(x, y) {\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n let operateIndex = 0;\n// \u53d8\u6210\u4e00\u4e2a\u65b9\u9635\u4e4b\u540e\u7684\u603b\u957f\u5ea6\n let len = (n -1) * (m - 1);\n\n while (operateIndex < len) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n let curIdx = Math.floor((operateIndex + 1)/n);\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (curIdx % 2 === 0) {\n // \u5076\u6570 \u5411\u4e0b\n x+=1;\n if (x === (n - 1)) {\n x -=1;\n y += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u4e0a\n x-=1;\n if (x === -1) {\n x = 0\n }\n }\n operateIndex++;\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return -1;\n }\n return 0;\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "const readline = require('readline');\nconst process = require('process');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet lineCount = 0, n, m, resultArr = [];\nrl.on('line', function(line){\n if (lineCount === 0) {\n let resOne = line.trim().split(' ');\n n = parseInt(resOne[0]);\n m = parseInt(resOne[1]);\n } else {\n resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));\n }\n if (lineCount === n) {\n console.log(squareFilling(n, m, resultArr))\n rl.close();\n }\n lineCount ++;\n});\n\n// let n = 3;\n// let m = 2;\n\n// let resultArray = [\n// [1,1,1],\n// [1,1,1],\n// [0,1,1]\n// ];\n// let resultArray = [\n// [1,0,1],\n// [1,0,1],\n// [0,0,0]\n// ];\n// let resultArray = [\n// [0,0],\n// [0,0],\n// [0,0]\n// ];\n\n\nfunction squareFilling (n, m, resultArray) {\n let operateCount = 0;\n let operateSelect = [];\n let x = 0;\n let y = 0;\n let hasOne = false;\n\n function isConform(x, y) {\n console.log(x)\n let topLeft = resultArray[x][y];\n let topRight = resultArray[x + 1][y];\n let bottomLeft = resultArray[x][y + 1];\n let bottomRight = resultArray[x + 1][y + 1];\n\n if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {\n hasOne = true;\n }\n\n return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)\n }\n\n let operateIndex = 0;\n// \u53d8\u6210\u4e00\u4e2a\u65b9\u9635\u4e4b\u540e\u7684\u603b\u957f\u5ea6\n let len = (n -1) * (m - 1);\n\n while (operateIndex < len) {\n if (isConform(x, y)) {\n operateCount+=1;\n operateSelect.push([x + 1,y + 1]);\n }\n\n let curIdx = Math.floor((operateIndex + 1)/n);\n\n // \u4ece0 \u5f00\u59cb\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u5f00\u59cb\n if (curIdx % 2 === 0) {\n // \u5076\u6570 \u5411\u4e0b\n x+=1;\n if (x === (n - 1)) {\n x -=1;\n y += 1;\n }\n } else {\n // \u5947\u6570 \u5411\u4e0a\n x-=1;\n if (x === -1) {\n x = 0\n }\n }\n operateIndex++;\n }\n if (!operateSelect.length) {\n if (hasOne) {\n return -1;\n }\n return 0;\n }\n let resStr = `${operateCount}\\n`\n operateSelect.forEach((item, idx) => {\n resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\\n' : '')\n });\n return resStr;\n}\n"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n \nvar main = function() {\"use strict\";\n // TODO\n var input = rdArN();\n var n = input[0];\n var m = input[1];\n var A = [];\n for (var i = 0; i < n; ++i) {\n A.push(rdArN());\n }\n var dx = [0,1,0,1];\n var dy = [0,0,1,1];\n var check = function(x, y) {\n var f = true;\n for (var k = 0; k < 4; ++k) {\n f = f && (A[x + dx[k]][y + dy[k]] > 0);\n }\n return f;\n };\n var fill = function (x, y) {\n for (var k = 0; k < 4; ++k) {\n A[x + dx[k]][y + dy[k]] = 2;\n }\n };\n var fillOrder = []\n for (var i = 0; i < n-1; ++i) {\n for (var j = 0; j < m-1; ++j) {\n if (check(i, j)) {\n fill(i, j);\n fillOrder.push([i+1, j+1]);\n }\n }\n }\n var isFilled = true;\n for (var i = 0; i < n-1; ++i) {\n for (var j = 0; j < m-1; ++j) {\n if (A[i][j] === 1) {\n isFilled = false;\n }\n }\n }\n if (isFilled) {\n pr(fillOrder.length);\n for (var i = 0; i < fillOrder.length; ++i) {\n prAr(fillOrder[i]);\n }\n } else {\n pr(-1);\n }\n};\n \nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst\nrdS=readline,\nrdN=()=>+rdS(),\nrdArS=()=>rdS().split(' '),\nrdArN=()=>rdArS().map(v=>+v),\nwr=write,\npr=print,\nprAr=(a)=>pr(...a),\nprOb=(o)=>pr(JSON.stringify(o,null,4)),\ncrAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},\ngetPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},\ndefineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});\n \nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "ad641a44ecaf78ca253b199f3d40ef96"} {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n\nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n\nlet nl = nextLine();\n\nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n\nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\tlet n = nl.num();\n\tlet a = nl.nums();\n\ta = a.concat(a);\n\tlet cnt = 0;\n\tlet c = 0;\n\tfor(let i of a){\n\t\tif (i === 1){\n\t\t\tc++;\n\t\t} else if (c > cnt){\n\t\t\tcnt = c;\n\t\t\tc = 0;\n\t\t} else {\n\t\t\tc = 0;\n\t\t}\n\t}\n\tif (c > cnt) cnt = c;\n\tconsole.log(cnt);\n\n};\n\nprocess.stdin.on('end', sol);\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let arr = d.split(' ').map(Number);\n let ans = 0;\n let count = 0;\n\n for (let i = 0; i < 2 * arr.length; i++) {\n if (arr[i % arr.length] === 1) {\n count++;\n }\n else {\n count = 0;\n }\n\n ans = Math.max(ans, count);\n }\n\n console.log(ans);\n\n // const idxZero = arr.indexOf(0);\n\n // if (idxZero !== -1) {\n // arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];\n // }\n\n // for (let i = 0; i < arr.length; i++) {\n // if (arr[i] === 1) {\n // count++;\n // }\n // else {\n // count = 0;\n // }\n\n // ans = Math.max(ans, count);\n // }\n\n\n\n // console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split().map(_ => parseInt(_))[0];\n let str = \"\";\n for(let i = 1 ; i < inputs.length ; i++) {\n str += \" \" + inputs[i];\n }\n str = str + \" \" + str;\n //console.log(str);\n let count = 0, mn = 0;\n str.split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val == 1) count++;\n else if(val == 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": " \n var n = readline()\n var arr = readline().split(' ').map(Number)\n var ans = 0,cnt = 0\n var p = 0\n var f = true\n for(var i=0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n let arr = d.split(' ').map(Number);\n const idxZero = arr.indexOf(0);\n let ans = 0;\n let count = 0;\n\n if (idxZero !== -1) {\n arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];\n }\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === 1) {\n count++;\n }\n else {\n count = 0;\n }\n\n ans = Math.max(ans, count);\n }\n\n\n\n console.log(ans);\n\n c++;\n});\n"}], "negative_code": [{"source_code": " \n var n = readline()\n var arr = readline().split(' ').map(Number)\n var ans = 0,cnt = 0\n for(var i=0; i parseInt(_))[0];\n const arr = inputs[1].split(\" \").map(_ => parseInt(_));\n let s = arr[n - 1];\n let count = s;\n let i = 0;\n let mn = 0;\n while(i < n) {\n mn = Math.max(count, mn);\n if(arr[i] === 1) count++;\n if(arr[i] === 0) {\n count = 0;\n }\n i++;\n }\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split().map(_ => parseInt(_))[0];\n let str = \"\";\n for(let i = 1 ; i < inputs.length ; i++) {\n str += \" \" + inputs[i];\n }\n let s = str[str.length - 1];\n let count = parseInt(s);\n let mn = 0;\n str.split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val == 1) count++;\n else if(val == 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split().map(_ => parseInt(_))[0];\n let str = \"\";\n for(let i = 1 ; i < inputs.length ; i++) {\n str += \" \" + inputs[i];\n }\n str = str + \" \" + str;\n let count = 0, mn = 0;\n inputs[1].split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val == 1) count++;\n else if(val == 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split().map(_ => parseInt(_))[0];\n let s = inputs[1][inputs[1].length - 1];\n let count = parseInt(s);\n let mn = 0;\n inputs[1].split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val == 1) count++;\n else if(val == 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split().map(_ => parseInt(_))[0];\n let s = inputs[1][inputs[1].length - 1];\n let count = parseInt(s);\n let mn = 0;\n inputs[1].split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val === 1) count++;\n else if(val === 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split(\" \").map(_ => parseInt(_))[0];\n let s = inputs[1][inputs[1].length - 1];\n let count = parseInt(s);\n let i = 0;\n let mn = 0;\n inputs[1].split(\" \").map(_ => parseInt(_)).forEach( val => {\n mn = Math.max(count, mn);\n if(val === 1) count++;\n else if(val === 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n i++;\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split(\" \").map(_ => parseInt(_))[0];\n let s = inputs[1][inputs[1].length - 1];\n let count = parseInt(s);\n let i = 0;\n let mn = 0;\n inputs[1].split(\" \").map(_ => parseInt(_)).forEach( val => {\n if(val === 1) count++;\n else if(val === 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n i++;\n });\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar inputs = [];\nconst PI = parseInt;\n\nfunction main() {\n const n = inputs[0].split(\" \").map(_ => parseInt(_))[0];\n const arr = inputs[1].split(\" \").map(_ => parseInt(_));\n let s = arr[n - 1];\n let count = s;\n let i = 0;\n let mn = 0;\n while(i < n) {\n mn = Math.max(count, mn);\n if(arr[i] === 1) count++;\n if(arr[i] === 0) {\n count = 0;\n }\n mn = Math.max(count, mn);\n i++;\n }\n console.log(Math.min(n, mn));\n}\n\nreadline.on('line', (input) => { inputs.push(input); });\nreadline.on('close', main)"}], "src_uid": "fcd88c7b64da4b839cda4273d928429d"} {"source_code": "#!/usr/bin/env node\n\n/**\n * Module dependencies.\n */\n\nconst readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on(\"line\", function(line) {\n var a, b, c;\n a = b = c = 0;\n if (line.indexOf('a') < 0 ||\n line.indexOf('b') < 0 ||\n line.indexOf('c') < 0) {\n console.log(\"NO\");\n rl.close();\n }\n if (!(line.lastIndexOf('a') < line.indexOf('b') &&\n line.lastIndexOf('b') < line.indexOf('c'))) {\n console.log(\"NO\");\n rl.close();\n }\n for (var i = 0; i < line.length; i++) {\n switch (line.charAt(i)) {\n case 'a': a++; break;\n case 'b': b++; break;\n case 'c': c++; break;\n }\n }\n console.log((a === c || b === c) ? \"YES\" : \"NO\");\n rl.close();\n}).on(\"close\", function() {\n process.exit();\n});\n\n\n", "positive_code": [{"source_code": "// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.\n\n// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.\n\n// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print \"YES\", otherwise print \"NO\" (without the quotes).\n// Input\n\n// The first and only line consists of a string S (1\u2009\u2264\u2009|S|\u2009\u2264\u20095\u2009000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.\n// Output\n\n// Print \"YES\" or \"NO\", according to the condition.\n\nvar s = readline().split('');\n// edge case\n\nfunction checkString(s) {\n\n // var ans = '';\n if (s.indexOf('a') === -1\n || s.indexOf('b') === -1\n || s.indexOf('c') === -1\n || s.indexOf('a') > s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n // print('NO')\n return 'NO';\n } else {\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i + 1] < s[i]) {\n // print('NO')\n return 'NO';\n }\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if ((countC === countA || countC === countB) /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {\n if (s[s.length - 1] !== 'c') {\n // print('NO');\n return 'NO';\n } else {\n // print('YES');\n return 'YES';\n }\n } else {\n // print('NO');\n return 'NO';\n }\n }\n}\n\nprint(checkString(s));"}, {"source_code": "var s = readline()\nif (s != s.split('').sort().join('')) {\n print('NO')\n} else {\n var a =0, b=0, c=0;\n for(var i=0; i s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n print('NO')\n} else {\n\n\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if (countC === countA || countC === countB && s[s.length - 1] === 'c') {\n print('YES');\n } else {\n print('NO');\n }\n}"}, {"source_code": "// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.\n\n// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.\n\n// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print \"YES\", otherwise print \"NO\" (without the quotes).\n// Input\n\n// The first and only line consists of a string S (1\u2009\u2264\u2009|S|\u2009\u2264\u20095\u2009000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.\n// Output\n\n// Print \"YES\" or \"NO\", according to the condition.\n\nvar s = readline().split('');\n\n// edge case\n\nif (s.indexOf('a') === -1\n || s.indexOf('b') === -1\n || s.indexOf('c') === -1\n || s.indexOf('a') > s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n print('NO')\n} else {\n\n\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if (countC === countA || countC === countB) {\n print('YES');\n } else {\n print('NO');\n }\n}"}, {"source_code": "// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.\n\n// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.\n\n// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print \"YES\", otherwise print \"NO\" (without the quotes).\n// Input\n\n// The first and only line consists of a string S (1\u2009\u2264\u2009|S|\u2009\u2264\u20095\u2009000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.\n// Output\n\n// Print \"YES\" or \"NO\", according to the condition.\n\nvar s = readline().split('');\n// edge case\n\nif (s.indexOf('a') === -1\n || s.indexOf('b') === -1\n || s.indexOf('c') === -1\n || s.indexOf('a') > s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n print('NO')\n} else {\n\n\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if ((countC === countA || countC === countB) /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {\n if (s[s.length - 1] !== 'c') {\n print('NO');\n } else {\n print('YES');\n }\n } else {\n print('NO');\n }\n}"}, {"source_code": "// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.\n\n// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.\n\n// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print \"YES\", otherwise print \"NO\" (without the quotes).\n// Input\n\n// The first and only line consists of a string S (1\u2009\u2264\u2009|S|\u2009\u2264\u20095\u2009000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.\n// Output\n\n// Print \"YES\" or \"NO\", according to the condition.\n\nvar s = readline().split('');\n// edge case\n\nif (s.indexOf('a') === -1\n || s.indexOf('b') === -1\n || s.indexOf('c') === -1\n || s.indexOf('a') > s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n print('NO')\n} else {\n\n\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if (countC === countA || countC === countB /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {\n if (s[s.length - 1] !== 'c') {\n print('NO');\n } else {\n print('YES');\n }\n } else {\n print('NO');\n }\n}"}, {"source_code": "// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.\n\n// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.\n\n// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print \"YES\", otherwise print \"NO\" (without the quotes).\n// Input\n\n// The first and only line consists of a string S (1\u2009\u2264\u2009|S|\u2009\u2264\u20095\u2009000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.\n// Output\n\n// Print \"YES\" or \"NO\", according to the condition.\n\nvar s = readline().split('');\n\n// edge case\n\nif (s.indexOf('a') === -1\n || s.indexOf('b') === -1\n || s.indexOf('c') === -1\n || s.indexOf('a') > s.indexOf('b')\n || s.indexOf('b') > s.indexOf('c')\n || s.indexOf('a') > s.indexOf('c')\n ) {\n print('NO')\n} else {\n\n\n var countA = null, countB = null, countC = null;\n\n for (var i = 0; i < s.length; i++) {\n if (s[i] === 'a') countA += 1;\n if (s[i] === 'b') countB += 1;\n if (s[i] === 'c') countC += 1;\n }\n\n if (countC === countA || countC === countB && s[s.length - 1] === 'c' && s[s.indexOf('c') - 1] === 'b') {\n print('YES');\n } else {\n print('NO');\n }\n}"}, {"source_code": "var inp = readline();\n\nvar spread = inp.split('').reduce(\n function(res, cur) {\n var lastItem = res[res.length - 1];\n \n if (lastItem && lastItem.char === cur) {\n lastItem.count++;\n } else {\n res.push({\n char: cur,\n count: 1,\n });\n }\n \n return res;\n },\n []\n);\n\nif (\n spread.map(function(item) {\n return item.char.toLowerCase();\n }).join('') !== 'abc'\n) {\n print('NO');\n} else {\n var aCount = spread[0].count;\n var bCount = spread[1].count;\n var cCount = spread[2].count;\n\n if (\n (!aCount || !bCount || !cCount) ||\n cCount !== aCount && cCount !== bCount\n ) {\n print('NO');\n }\n \n print('YES');\n}"}, {"source_code": "#!/usr/bin/env node\n\n/**\n * Module dependencies.\n */\n\nconst readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.on(\"line\", function(line) {\n var a, b, c;\n a = b = c = 0;\n if (line.indexOf('a') < 0 ||\n line.indexOf('b') < 0 ||\n line.indexOf('c') < 0) {\n console.log(\"NO\");\n rl.close();\n }\n var ap = line.indexOf('a');\n var bp = line.indexOf('b');\n var cp = line.indexOf('c');\n if (!(ap < bp && bp < cp)) {\n console.log(\"NO\");\n rl.close();\n }\n for (var i = 0; i < line.length; i++) {\n switch (line.charAt(i)) {\n case 'a': a++; break;\n case 'b': b++; break;\n case 'c': c++; break;\n }\n }\n console.log((a === c || b === c) ? \"YES\" : \"NO\");\n rl.close();\n}).on(\"close\", function() {\n process.exit();\n});\n\n\n"}], "src_uid": "6581dbaff7eb52b63ccfe9c0c4117c09"} {"source_code": "const mod = (k, n) => k >= 0 ? k % n : (n + (k%n))%n\n\n\nconst processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n\n const producedArr = arr.map(\n x => mod(x, n)\n )\n const res = {}\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 6\n1\n14\n2\n1 -1\n4\n5 5 5 1\n3\n3 2 1\n2\n0 1\n5\n-239 -2 -100 -3 -11\n**/\n\nfunction main() {\n var range = readline();\n\n for(var r=0;r {\n const nums = +lines[0]\n for (let i =0; i +x)\n\n const producedArr = arr.map(\n x => {\n if (x >= 0) return x % arr.length\n return (arr.length * Math.ceil(Math.abs(x) / arr.length) - x) % arr.length\n }\n )\n const res = []\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n\n const producedArr = arr.map(\n x => {\n if (x >= 0) return x % arr.length\n return (arr.length * Math.ceil(Math.abs(x) / arr.length) - x) % arr.length\n }\n )\n const res = []\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const processData = (lines) => {\n const nums = +lines[0]\n for (let i =0; i +x)\n\n const producedArr = arr.map(\n x => x % arr.length\n )\n const res = {}\n for (let j=0; j i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "src_uid": "2173310623173d761b6039f0e5e661a8"} {"source_code": "const readline = require('readline').createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet input = [];\r\nlet ans = [];\r\n\r\nreadline.on('line', line => {\r\n input.push(line);\r\n}).on('close', () => {\r\n for (let i = 2; i < input.length; i+=2) {\r\n let nums = input[i].split(' ').map(Number);\r\n \r\n let chkOdd = nums[0]%2;\r\n let chkEven = nums[1]%2;\r\n \r\n for (let j = 0; j < nums.length; j++) {\r\n if (j%2===0 && nums[j]%2!==chkOdd || j%2===1 && nums[j]%2!==chkEven) {\r\n ans.push('NO');\r\n break;\r\n }\r\n if (j === nums.length-1) ans.push('YES');\r\n }\r\n }\r\n \r\n console.log(ans.join('\\n'));\r\n});", "positive_code": [{"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 0; i < N; i += 2){\r\n\t\t\tif(list[i] % 2 == 0){\r\n\t\t\t\tc |= 1;\r\n\t\t\t}else{\r\n\t\t\t\tc |= 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c == 3){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 1; i < N; i += 2){\r\n\t\t\tif(list[i] % 2 == 0){\r\n\t\t\t\tc |= 1;\r\n\t\t\t}else{\r\n\t\t\t\tc |= 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c == 3){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tmyout(\"YES\");\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n let t = readline();\r\n while(t--) {\r\n const [n, arr] = [Number(readline()), readline().split(\" \")];\r\n \r\n const typeOfevenIndex = arr[0] % 2, typeOfOddIndex = arr[1] % 2;\r\n \r\n let ans = \"YES\";\r\n \r\n loop:\r\n for(let i = 0; i < n; i++) {\r\n if(i % 2 === 0 && arr[i] % 2 !== typeOfevenIndex) {\r\n ans = \"NO\";\r\n break loop;\r\n }\r\n if(i % 2 === 1 && arr[i] % 2 !== typeOfOddIndex) {\r\n ans = \"NO\";\r\n break loop;\r\n }\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n\r\n let odd = arr.filter((v, i) => i % 2 === 0);\r\n let even = arr.filter((v, i) => i % 2 === 1);\r\n\r\n let no =false;\r\n for (let i = 0; i < odd.length; i++) {\r\n if (odd[i] % 2 !== odd[0] % 2) {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n for (let i = 0; i < even.length; i++) {\r\n if (even[i] % 2 !== even[0] % 2) {\r\n no = true;\r\n break;\r\n }\r\n }\r\n\r\n output(no ? 'NO' : 'YES');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n const T = readline();\n for (let i = 0; i < T; i++) {\n const n = readline()\n const A = readline().split(' ').map(x => +x)\n solve(A)\n }\n}\nfunction solve(A) {\n\n for (let i = 0; i < 2; i++) {\n let remain = A[i] % 2\n for (let j = i; j < A.length; j += 2) {\n if (A[j] % 2 !== remain) {\n console.log('NO')\n return\n }\n }\n }\n\n console.log('YES')\n}\n\n"}, {"source_code": "let readline = require(\"readline\");\r\nlet rl = readline.createInterface({\r\n\tinput: process.stdin,\r\n\toutput: process.stdout,\r\n\tterminal: false\r\n});\r\n\r\nlet lines = [];\r\n\r\nasync function main() {\r\n for await (let line of rl) {\r\n\t lines.push(line);\r\n }\r\n \r\n\tlet inputs = +lines[0]; // dirty javascript typecasting to number\r\n let arrays = [];\r\n \r\n for (let i = 0; i < inputs; i++) {\r\n let numOfElements = +lines[2 * i + 1];\r\n arrays.push([]);\r\n \r\n for (let j = 0; j < numOfElements; j++) {\r\n arrays[i].push(lines[2 * i + 2].split(\" \")[j]);\r\n }\r\n }\r\n\r\n for (array of arrays) {\r\n let evenParity = array[0] % 2;\r\n let oddParity = array[1] % 2;\r\n\r\n let evenParitySuccess = true;\r\n let oddParitySuccess = true;\r\n\r\n for (let i = 0; i < array.length; i += 2) {\r\n evenParitySuccess = evenParitySuccess && array[i] % 2 == evenParity;\r\n }\r\n\r\n for (let i = 1; i < array.length; i += 2) {\r\n oddParitySuccess = oddParitySuccess && array[i] % 2 == oddParity;\r\n }\r\n\r\n if (evenParitySuccess && oddParitySuccess) console.log(\"YES\");\r\n else console.log(\"NO\");\r\n }\r\n}\r\n\r\nmain();"}, {"source_code": "\n\nconst processData = (lines) => {\n let count = +lines[0]\n let cur = 0\n while(count--) {\n cur++\n // let [n] = lines[cur].split(' ').map(x => +x)\n cur++\n let nums = lines[cur].split(' ').map(x => +x)\n\n let patternBreak = false;\n for (const t of [0, 1]) {\n let pattern = nums[t] ? nums[t] %2 : 0;\n if (!patternBreak) {\n for (let i=t; i i.push(c))\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.join('').split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n for (let i = 0; i < n; i++) {\r\n if (i > 1) {\r\n if ((a[i] & 1) !== (a[i - 2] & 1)) {\r\n console.log('NO');\r\n return;\r\n }\r\n }\r\n }\r\n console.log('YES');\r\n}\r\n\r\nasync function main(read) {\r\n const t = Number(await read());\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ok = 1;\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (i - 2 >= 0 && (a[i] & 1) != (a[i - 2] & 1)) ok = 0;\r\n\t\t}\r\n\r\n\t\tconsole.log(ok ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\n\nconst calc = (n, a)=>{\n let parity0 = a[0] % 2;\n let parity1 = a[1] % 2;\n for (let i = 0; i < n; i++) {\n if (i % 2 === 0 && a[i] % 2 !== parity0) return 'NO';\n if (i % 2 === 1 && a[i] % 2 !== parity1) return 'NO';\n }\n\n return \"YES\";\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr) ? 'YES' : 'NO'\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const odd = arr[1] & 1\n const even = arr[0] & 1\n for (let i = 0; i < arr.length; i++) {\n const x = arr[i] & 1\n if (i & 1) {\n if (x !== odd) return false\n } else {\n if (x !== even) return false\n }\n }\n return true\n}\n"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst calc = (n, A)=>{\n let p1 = A[0]&1;\n for (let i=0; i +x);\r\n print(oddAndEven(arr1));\r\n}\r\n \r\nfunction oddAndEven(n){\r\n \r\n var evenIdx = n[0] % 2 === 0;\r\n var oddIdx = n[1] % 2 === 0;\r\n for(var i = 0; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}], "negative_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split('').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){\n if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});\n"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j++){\n if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(!ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j ++){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j += 2){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0; j < e; j += 2){\n if(k[j] % 2 != k[0] % 2){\n ok = false;\n break;\n }\n }\n for(j = 1; j < e; j ++){\n if(k[j] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n console.log(ok ? 'YES' : 'NO');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = Number(lines[i]);\n }else{\n var ar = lines[i].split(' ').map(Number);\n var a = 0, b = n - 1;\n var a1 = ar[0], b1 = ar[b];\n var ans = 0;\n while(a < b){\n if(a1 == b1){\n ans = a + 1 + n - b;\n a++;\n a1 += ar[a];\n }else if(a1 > b1){\n b--;\n b1 += ar[b];\n }else if(a1 < b1){\n a++;\n a1 += ar[a];\n }\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var n = lines[0].split('').sort();\n var e = n[n.length - 1];\n var ans = '';\n for(i = 0; i < n.length; i++){\n if(n[i] == e){\n ans += n[i];\n }\n }\n console.log(ans);\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i], a = new Map(), flag = false;\n }else{\n k = lines[i].split(' ').map(Number);\n for(j = 0; j < n; j++){\n if(a.has(k[j])){\n flag = true;\n break;\n }else{\n a.set(k[j]);\n }\n }\n console.log(flag === true ? 'NO' : 'YES');\n }\n }\n});"}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split('').map(Number);\n var x = 0;\n var y = 0;\n for(j = 0; j < 6; j++){\n if(j >= 3){\n x += a[j];\n }else{\n y += a[j];\n }\n }\n console.log(x == y ? 'YES' : 'NO');\n }\n});\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){\n if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ok = true;\n for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){\n if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){\n ok = false;\n break;\n }\n }\n if(ok === true){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 0; i < N; i += 2){\r\n\t\t\tif(list[i] % 2 == 0 && c == 0){\r\n\t\t\t\tc++;\r\n\t\t\t}else if(list[i] % 2 == 1 && c == 1){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c == 2){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar c = 0;\r\n\t\tfor(var i = 1; i < N; i += 2){\r\n\t\t\tif(list[i] % 2 == 0 && c == 0){\r\n\t\t\t\tc++;\r\n\t\t\t}else if(list[i] % 2 == 1 && c == 1){\r\n\t\t\t\tc++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(c == 2){\r\n\t\t\tmyout(\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tmyout(\"YES\");\r\n\t}\r\n}\r\n"}], "src_uid": "fbb4e1cf1cad47481c6690ce54b27a1e"} {"source_code": "var n = parseInt(readline());\nvar out = 'O' + Array(n).join('o');\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substr(0, index) + replacement + this.substr(index + replacement.length);\n}\n\nvar fibo = [0, 1, 1];\nfunction f() {\n var i = fibo.length;\n fibo.push(fibo[i-1] + fibo[i-2]);\n if (fibo[i] <= n) {\n out = out.replaceAt(fibo[i]-1, 'O');\n f();\n }\n}\nf();\n\nprint(out);\n", "positive_code": [{"source_code": "const n = parseInt(readline());\nvar out = 'O' + Array(n).join('o');\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substr(0, index) + replacement + this.substr(index + replacement.length);\n}\n\nvar fibo = [0, 1, 1];\nfunction f() {\n const i = fibo.length;\n fibo.push(fibo[i-1] + fibo[i-2]);\n if (fibo[i] <= n) {\n out = out.replaceAt(fibo[i]-1, 'O');\n f();\n }\n}\nf();\n\nprint(out);\n"}, {"source_code": "const n = parseInt(readline());\nvar out = 'O' + Array(n).join('o');\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substr(0, index) + replacement + this.substr(index + replacement.length);\n}\n\nvar fibo = [0, 1, 1];\nfunction f() {\n const i = fibo.length;\n fibo.push(fibo[i-1] + fibo[i-2]);\n if (fibo[i] <= n) {\n out = out.replaceAt(fibo[i]-1, 'O');\n f();\n }\n}\nf();\n\nprint(out);"}, {"source_code": "n = readline();\n\nvar i = 1, arr = [1, 1], resArr = [];\n\nwhile (arr[i] < n) {\n\tarr.push(arr[i - 1] + arr[i]);\n\n\ti++;\n};\n\nfor (var j = 1; j <= n; j++) {\n\tvar count = 0;\n\n\tfor (var k = 0; k < arr.length; k++) {\n\t\tif (j == arr[k]) {\n\t\t\tcount++;\n\t\t};\n\t};\n\n\tif (count > 0) {\n\t\tresArr.push('O');\n\t} else {\n\t\tresArr.push('o');\n\t};\n};\n\n\nprint(resArr.join(''));\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = [0,1];\n var set = new Set(list);\n while(list[list.length - 1] < 1000){\n var add = list[list.length - 2] + list[list.length - 1];\n list.push(add);\n set.add(add);\n }\n var output = \"\";\n for(var i = 0; i < N; i++){\n if(set.has(i + 1)){\n output += \"O\";\n }else{\n output += \"o\";\n }\n }\n myout(output);\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n const seq = [1, 1];\n\n for (let i = 2; i <= d; i++) {\n seq[i] = seq[i - 1] + seq[i - 2];\n }\n\n let ans = '';\n\n for (let i = 1; i <= d; i++) {\n if (seq.includes(i)) {\n ans += 'O';\n }\n else {\n ans += 'o';\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "n = parseInt(readline())\na = 1, b = 2, t = 3\nfor (k = 1; k <= n; k++)\n\twrite((k < 3) ? 'O' : (k == a+b) ? (t = a+b, a = b, b = t, 'O') : 'o')"}, {"source_code": "function a(n) {\n return n % Math.sqrt(n) === 0;\n}\n\nfunction b(n) {\n return a(5 * n * n + 4) || a(5 * n * n - 4);\n}\n\nfunction main() {\n var n = readline();\n var x = '';\n\n for (var i = 1; i <= n; i++) {\n x = x + (b(i) ? 'O' : 'o');\n }\n\n print(x);\n}\n\nmain();\n"}, {"source_code": "const n = parseInt(readline());\nvar out = 'O' + Array(n).join('o');\n\nString.prototype.replaceAt = function(index, replacement) {\n return this.substr(0, index) + replacement + this.substr(index + replacement.length);\n}\n\nvar fibo = [0, 1, 1];\nfunction f() {\n const i = fibo.length;\n fibo.push(fibo[i-1] + fibo[i-2]);\n if (fibo[i] <= n) {\n out = out.replaceAt(fibo[i]-1, 'O');\n f();\n }\n}\nf();\n\nprint(out);"}, {"source_code": "n = +readline()\nfib = []\nfib.push(1)\nfib.push(1)\nfor (i = 2; i < 20; i++)\n fib[i] = fib[i - 1] + fib[i - 2]\nans = ''\nfor (i = 1; i <= n; i++)\n ans += (fib.includes(i) ? 'O' : 'o')\nprint(ans)"}, {"source_code": "var t = readline();\nel(t);\nfunction el(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n write(f.includes(i) ? 'O' : i > 0 ? 'o' : '');\n }\n return print();\n}"}, {"source_code": "var t = readline();\nprint(el(t));\n\nfunction el(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n s = s.join('');\n return s;\n}"}, {"source_code": "'use strict';\n\nlet n = parseInt(readline(), 10);\nconst isFibo = new Array(n + 1);\nconst fibo = [0, 1];\nfor (let i = 2; fibo[fibo.length - 1] <= n; i++) {\n fibo.push(fibo[i - 2] + fibo[i - 1]);\n}\n\nfibo.pop();\n\nfor (const i of fibo) {\n isFibo[i] = true;\n}\n\nfor (let i = 1; i <= n; i++)\n write(isFibo[i] ? 'O' : 'o');\nprint()"}, {"source_code": "'use strict';\n\nlet n = parseInt(readline(), 10);\nconst isFibo = new Array(n + 1);\nconst fibo = [0, 1];\nfor (let i = 2; fibo[fibo.length - 1] <= n; i++) {\n fibo.push(fibo[i - 2] + fibo[i - 1]);\n}\n\nfibo.pop();\n\nfor (const i of fibo) {\n isFibo[i] = true;\n}\n\nfor (let i = 1; i <= n; i++)\n write(isFibo[i] ? 'O' : 'o');\nprint()\n"}], "negative_code": [{"source_code": "var el = function(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n s = s.join('');\n return s;\n};\nel(8);"}, {"source_code": "function el(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n s = s.join('');\n return s;\n};\nel(8);"}, {"source_code": "'use strict';\n\nlet n = parseInt(readline(), 10);\nconst isFibo = new Array(n + 1);\nconst fibo = [0, 1];\nfor (let i = 2; fibo[fibo.length - 1] <= n; i++) {\n fibo.push(fibo[i - 2] + fibo[i - 1]);\n}\n\nfibo.pop();\n\nfor (const i of fibo) {\n isFibo[i] = true;\n}\n\nfor (let i = 1; i <= n; i++)\n write(isFibo[i] ? '0' : 'o');\nprint()\n"}, {"source_code": "var el = function(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n s = s.join('');\n return s;\n};"}, {"source_code": "var el = function(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n return s.join('');\n};"}, {"source_code": "function el(n){\n var a = 0;\n var b = 1;\n var c;\n var f = [];\n var s = [];\n for(var i = 0;i <= n;i++){\n c = a + b;\n a = b;\n b = c;\n f.push(a);\n if(f.includes(i)){\n s.push('O');\n }else if(i > 0){\n s.push('o');\n }\n }\n s = s.join('');\n return s;\n}\nprint(el(8));"}], "src_uid": "a7c0484275e62f0bc70d9edaac27d7d6"} {"source_code": "function main() {\n var n = parseInt(readline());\n var bs = readline().split(' ').map(x => parseInt(x));\n var as = Array(n).fill(0);\n as[0] = bs[0];\n var mx = bs[0];\n print(as[0])\n for(var i = 1; i < n; i++){\n as[i] = bs[i] + mx;\n mx = Math.max(mx, as[i]);\n print(as[i])\n }\n}\nmain();\n", "positive_code": [{"source_code": "var times = parseInt(readline());\nvar b = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar a =[];\nvar mx = 0;\nfor(var i = 0; i < times; i++)\n{\n a.push(mx + b[i]);\n write(a[i] + \" \");\n mx = Math.max(mx, a[i]);\n}"}, {"source_code": "var n = parseInt(readline());\nvar b = readline().split(\" \").map(function(x) {\n return parseInt(x);\n});\nvar a = []\nvar mx = 0;\nfor (var i = 0; i < n; i++) {\n a.push(b[i] + mx);\n print(a[i])\n mx = Math.max(mx, a[i]);\n}\n"}, {"source_code": "//var input = readline();\nvar T = parseInt(readline());\n\nvar s = 0, b = [];\nvar ar = readline().split(' ').map(x => parseInt(x));\nfor (var i = 0; i < T; i++) {\n b[i] = ar[i] + s;\n s = Math.max(s, b[i]);\n print(b[i]);\n}\n"}, {"source_code": "var t = Number(readline());\nvar inp = readline().split(' ').map(cur => Number(cur));\n\nvar out = []\nvar max = 0;\ninp.forEach((cur, i) => {\n if(cur < 0)\n out.push(max+cur)\n else{\n max += cur;\n out.push(max); \n }\n \n});\nprint(out.join(' '));\n"}, {"source_code": "function main() {\n var n = parseInt(readline());\n var bs = readline().split(' ').map(x => parseInt(x));\n var as = Array(n).fill(0);\n as[0] = bs[0];\n var mx = bs[0];\n print(as[0])\n for(var i = 1; i < n; i++){\n as[i] = bs[i] + mx;\n mx = Math.max(mx, as[i]);\n print(as[i])\n }\n}\nmain();"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const n = readInt()\n const b = readInts()\n let m = 0\n const a = new Array(n)\n a[0] = b[0]\n m = a[0]\n for(let i = 1;i < n; i++) {\n m = Math.max(m, a[i - 1])\n // wr(a, m)\n a[i] = b[i] + m\n }\n wr(a.join(' '))\n}"}, {"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() { return inputString[currentLine++]; }\nconst println = (x = \"\") => process.stdout.write(String(x) + \"\\n\");\nconst print = x => { process.stdout.write(String(x)); }\n// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<\n\nfunction main() {\n let n = parseInt(input());\n let x = input().split(' ').map(v => parseInt(v));\n // let b = [], a = [];\n let b = new Array(n);\n let a = new Array(n);\n // b.push(0);\n // a.push(x[0]);\n b[0] = 0;\n a[0] = x[0];\n let mx = x[0];\n for (let i = 1; i < n; ++i) {\n // b.push(mx);\n b[i] = mx;\n a[i] = (b[i] + x[i]);\n mx = Math.max(a[i], mx);\n }\n a.forEach(v => print(v + ' '));\n println();\n}\n"}, {"source_code": "// Alternative\n// https://www.npmjs.com/package/competitive-programming-js\n\"use strict\"\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStdin => { inputString += inputStdin; });\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n main();\n});\nfunction input() { return inputString[currentLine++]; }\nconst println = (x = \"\") => process.stdout.write(String(x) + \"\\n\");\nconst print = x => { process.stdout.write(String(x)); }\n// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<\n\nfunction main() {\n let n = parseInt(input());\n let x = input().split(' ').map(v => parseInt(v));\n let b = [], a = [];\n b.push(0);\n a.push(x[0]);\n let mx = x[0];\n for (let i = 1; i < n; ++i) {\n b.push(mx);\n a.push(b[i] + x[i]);\n mx = Math.max(a[i], mx);\n }\n a.forEach(v => print(v + ' '));\n println();\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let curr = Math.max(0, arr[0]);\n const ans = [curr];\n\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] <= 0) {\n ans.push(Math.max(0, curr + arr[i]));\n }\n else {\n curr += arr[i];\n ans.push(curr);\n }\n }\n\n console.log(ans.join(' '));\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8')\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', input => { inputString += input; })\nprocess.stdin.on('end', _ => { inputString = inputString.split('\\n'); main(); })\nconst readline = () => { return inputString[currentLine++] }\n\nfunction main() {\n let n = parseInt(readline());\n let bs = readline().split(' ').map(x => parseInt(x));\n let as = Array(n).fill(0);\n as[0] = bs[0];\n let mx = bs[0];\n for(let i = 1; i < n; i++){\n as[i] = bs[i] + mx;\n mx = Math.max(mx, as[i]);\n }\n console.log(as.join(' '));\n}\n\n"}, {"source_code": "const processData = (lines) => {\n const nums = lines[1].split(' ').map(x => +x)\n const res = []\n let curMax = 0\n for (let i=0; i i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "var t = Number(readline());\nvar inp = readline().split(' ').map(cur => Number(cur));\n\nvar out = []\nvar max = 0;\ninp.forEach((cur, i) => {\n if(i !== inp.length-1){\n if(cur >= 0)\n max += cur; \n }else max += cur; \n \n out.push(max);\n});\nprint(out.join(' '));\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let curr = Math.max(0, arr[0]);\n const ans = [curr];\n\n\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] <= 0) {\n ans.push(0);\n }\n else {\n curr += arr[i];\n ans.push(curr);\n }\n }\n\n console.log(ans.join(' '));\n\n c++;\n});\n"}], "src_uid": "e22b10cdc33a165fbd73b45dc5fbedce"} {"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n\nvar t, arr, ans, candy, children;\n\nt = Number(readline());\n\nfor (i = 0; i < t; i++) {\n\n arr = readline().replace(/\\r$/, '').split(' ').map(Number);\n ans = 0;\n candy = arr[0];\n children = arr[1];\n\n ans = (Math.floor(candy / children)) * children;\n candy -= ans;\n\n if (candy > Math.floor(children / 2)) {\n\n ans += Math.floor(children / 2)\n } else {\n\n ans += candy;\n }\n\n print(ans)\n}", "positive_code": [{"source_code": "var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)\nvar write = this.write || require('lol-io').write; //write --> creates output.txt with output\nvar readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt\n \nvar t, arr, ans, candy, children;\n \nt = Number(readline());\n \nfor (i = 0; i < t; i++) {\n \n arr = readline().replace(/\\r$/, '').split(' ').map(Number);\n ans = 0;\n candy = arr[0];\n children = arr[1];\n \n ans = (Math.floor(candy / children)) * children;\n candy -= ans;\n \n if (candy > Math.floor(children / 2)) {\n \n ans += Math.floor(children / 2)\n } else {\n \n ans += candy;\n }\n \n print(ans)\n}"}, {"source_code": "var cant = readline();\n\nfor (var i=0; i < cant; i++) {\n var num = readline().split(\" \").map(x => parseInt(x));\n var k = num[1];\n var n = num[0];\n var full = n - n % k;\n full+= Math.min(n%k, k/2);\n print(Math.floor(full));\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var totalCandy;\n if (restCandy) {\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy > halfChildren) {\n restCandy = halfChildren;\n }\n totalCandy = firstCandy + restCandy;\n } else {\n totalCandy = firstCandy;\n }\n print(totalCandy);\n}"}, {"source_code": "var n = parseInt(readline());\nwhile(n--){\n var z = readline();\n var t = z.split(' ').map(e => parseInt(e));\n print(Math.min(t[0], t[0] - t[0]%t[1] + Math.floor(t[1]/2)));\n}"}, {"source_code": "'use strict'\n\nconst problem = (n, k) => (n - n % k) + Math.min(k >> 1, n % k)\nlet q = +readline();\nwhile(q--) print(problem(...readline().split(' ').map(Number)))\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nchilds = readline().split(' ').map(Number);\n var n = nchilds[0];\n var childs = nchilds[1];\n var base = Math.floor(n / childs);\n var other = Math.min(n - childs * base, Math.floor(childs / 2))\n print(childs * base + other);\n }\n}\n\nmain();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\nfunction stringArrayToBigInts(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( BigInt(array[i]) );\n }\n return result;\n}\n\n// ======================================================\n// B. Candies Division\n// http://codeforces.com/problemset/problem/1283/B\n// ======================================================\n\nfunction doIt( numOfCandies, numOfKids ) {\n \n var candiesPerKid = Math.floor(numOfCandies/numOfKids);\n var candiesLeft = (numOfCandies % numOfKids);\n var extra = candiesLeft;\n if( extra > numOfKids / 2 ) {\n extra = Math.floor(numOfKids / 2);\n }\n var result = candiesPerKid * numOfKids + extra;\n printALine(result);\n \n}\n\nfunction main() {\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var arr = stringArrayToNumbers(string1); \n doIt( arr[0], arr[1] );\n } \n\n}\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let inputs = inputString[index++].split(' ');\n let candies = inputs[0], kids = inputs[1];\n console.log(candiesShared(candies, kids))\n } \n}\n\nfunction candiesShared(candies, kids) {\n let sharedCandies = 0, remainedCandies;\n \n sharedCandies += parseInt(candies / kids)*kids;\n remainedCandies = candies % kids;\n \n return sharedCandies + min(remainedCandies, parseInt(kids / 2));\n}\n\nfunction min(value1, value2) {\n return value1 < value2 ? value1 : value2;\n}"}, {"source_code": "\"use strict\";\n\nlet numberOfInputs = +readline();\n\nlet arrayOfInputs = [];\nlet nk = [];\n\nfor (let i = 0; i < numberOfInputs; i++) {\n\tarrayOfInputs[i] = readline();\n\tnk[i] = arrayOfInputs[i].split(' ').map(function(item) {\n\t\treturn +item;\n\t});\n}\n\n\nfunction getGoodCandyNumber(n, k) {\n\tlet goodCelNumber = 0;\n\tlet goodOst = 0;\n\tlet ost = n % k;\n\t\n\n\t// goodCelNumber = (n - n%k)/k;\n\t\n\tif (ost > Math.floor(k / 2)) {\n\t\tgoodOst = Math.floor(k / 2);\n\t\treturn n - (ost - goodOst);\n\t} else {\n\t\tgoodOst = ost;\n\t\treturn n;\n\t}\n}\n\nfor (let i = 0; i < numberOfInputs; i++) {\n\tprint(getGoodCandyNumber(nk[i][0], nk[i][1]));\n}\n"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = readInt(arr)\n\n for(let j = 0; j < t; j++) {\n const [n, k] = readInts(arr, j)\n\n let rem = n % k\n let a = Math.floor(n / k)\n let ans = k * a + Math.min(Math.floor(k / 2), rem)\n\n wr(ans)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, k] = d.split(' ').map(Number);\n const ans = Math.min(n, Math.floor(n / k) * k + Math.floor(k / 2));\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "var t = readline();\nwhile(t--) {\n var a = readline().split(\" \").map(function(num) {\n return parseInt(num);\n });\n var modest = Math.floor(a[0] / a[1]);\n var remainder = a[0] % a[1];\n var border = Math.floor(a[1] / 2);\n if(remainder > border) {\n remainder = border;\n }\n var ans = modest * a[1] + remainder;\n print(ans);\n}"}, {"source_code": "var t, arr, ans, candy, children;\n \nt = Number(readline());\n \nfor (i = 0; i < t; i++) {\n \n arr = readline().replace(/\\r$/, '').split(' ').map(Number);\n ans = 0;\n candy = arr[0];\n children = arr[1];\n \n ans = (Math.floor(candy / children)) * children;\n candy -= ans;\n \n if (candy > Math.floor(children / 2)) {\n \n ans += Math.floor(children / 2)\n } else {\n \n ans += candy;\n }\n \n print(ans)\n}"}], "negative_code": [{"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let inputs = inputString[index++].split(' ');\n let candies = inputs[0], kids = inputs[1];\n console.log(candiesShared(candies, kids))\n } \n}\n\nfunction candiesShared(candies, kids) {\n let sharedCandies = 0, remainedCandies;\n \n sharedCandies += parseInt(candies / kids)*kids;\n remainedCandies = candies % kids;\n \n if (remainedCandies > (parseInt(kids / 2) - 1)) {\n sharedCandies += parseInt(kids / 2);\n }\n \n return sharedCandies;\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let inputs = inputString[index++].split(' ');\n let candies = inputs[0], kids = inputs[1];\n console.log(candiesShared(candies, kids))\n } \n}\n\nfunction candiesShared(candies, kids) {\n let sharedCandies = 0, remainedCandies;\n \n sharedCandies += parseInt(candies / kids)*kids;\n remainedCandies = candies % kids;\n \n if (remainedCandies >= (parseInt(kids / 2) - 1)) {\n sharedCandies += parseInt(remainedCandies / 2) + 1;\n }\n \n return sharedCandies;\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let inputs = inputString[index++].split(' ');\n let candies = inputs[0], kids = inputs[1];\n console.log(candiesShared(candies, kids))\n } \n}\n\nfunction candiesShared(candies, kids) {\n let sharedCandies = 0, remainedCandies;\n \n sharedCandies += parseInt(candies / kids)*kids;\n remainedCandies = candies % kids;\n \n if (remainedCandies >= (parseInt(kids / 2) - 1)) {\n sharedCandies += parseInt(kids / 2) + 1;\n }\n \n return sharedCandies;\n}"}, {"source_code": "'use strict';\n\nconst fs = require('fs');\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main(inputString);\n});\n\nfunction main(inputString) {\n let index = 0;\n let tests = inputString[index++];\n \n for (let i = 0; i < tests; ++i) {\n let inputs = inputString[index++].split(' ');\n let candies = inputs[0], kids = inputs[1];\n console.log(candiesShared(candies, kids))\n } \n}\n\nfunction candiesShared(candies, kids) {\n let sharedCandies = 0, remainedCandies;\n \n sharedCandies += parseInt(candies / kids)*kids;\n remainedCandies = candies % kids;\n \n if (remainedCandies >= (parseInt(kids / 2) - 1)) {\n sharedCandies += parseInt(kids / 2);\n }\n \n return sharedCandies;\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = readInt(arr)\n\n for(let j = 0; j < t; j++) {\n const [n, k] = readInts(arr, j)\n\n let rem = n % k\n let a = Math.floor(n / k)\n let ans = k * a + Math.floor(k / 2)\n\n wr(ans)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, k] = d.split(' ').map(Number);\n\n if (n % k === 0) {\n ans += `${Math.floor(n / k) * k}\\n`;\n }\n else {\n ans += `${Math.floor(n / k) * k + Math.floor(k / 2)}\\n`;\n }\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, k] = d.split(' ').map(Number);\n\n if (n <= k) {\n ans += `${n}\\n`;\n }\n else if (n % k === 0) {\n ans += `${Math.floor(n / k) * k}\\n`;\n }\n else {\n ans += `${Math.min(n, Math.floor(n / k) * k + Math.floor(k / 2))}\\n`;\n }\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans = '';\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n, k] = d.split(' ').map(Number);\n\n if (n <= k) {\n ans += `${n}\\n`;\n }\n else if (n % k === 0) {\n ans += `${Math.floor(n / k) * k}\\n`;\n }\n else {\n ans += `${Math.floor(n / k) * k + Math.floor(k / 2)}\\n`;\n }\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});\n"}, {"source_code": "'use strict';\n\nlet friendsNumber = +readline(); //!\nlet wishString = readline(); //!\nlet arrayOfWishNumbers = wishString.split(\" \").map(function(item) {\n\treturn +item;\n});\n\nlet sortedWish = [];\nlet zeroIndexes = [];\nlet zeroValues = [];\n\nfor (let i = 0; i < arrayOfWishNumbers.length; i++) {\n\tif (arrayOfWishNumbers[i] === 0) {\n\t\tzeroIndexes.push(i);\n\t}\n\tsortedWish[i] = 0;\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (arrayOfWishNumbers[i] !== 0) {\n\t\tsortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];\n\t}\n}\n\nfor (let i = 0; i < sortedWish.length; i++) {\n\tif (sortedWish[i] === 0) {\n\t\tzeroValues.push(i + 1);\n\t}\n}\n\nlet goodSortedZeroValues = [];\n//\n\n// zeroValues = zeroValues.reverse();\n// if (zeroValues.length % 2 == 1) {\n// \tlet tempValue = zeroValues[Math.floor(zeroValues.length / 2)];\n// \tzeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];\n// \tzeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;\n// }\n\n// let badSortedValues = [];\n\n// for (let i = 0; i < zeroValues.length; i++) {\n// \tif (zeroValues[i] = zeroIndexes[i] + 1) {\n// \t\tbadSortedValues.push(zeroValues[i]);\n// \t}\n// }\n\n// for (let i = 0; i < badSortedValues.length; i++) {\n// \tfor (let j = 0; j < zeroValues.length; j++) {\n// \t\tif (zeroValues[j] === badSortedValues[i]) {\n// \t\t\tlet tempValue = zeroValues[j];\n// \t\t\tfor (let k = 0; k < zeroValues.length; k++) {\n// \t\t\t\tif (zeroValues[k] !== 0;)\n// \t\t\t}\n// \t\t}\n// \t}\n// }\n\nfor (let i = 0; i < zeroValues.length; i++) {\n\tif (zeroValues[i] === zeroIndexes[i] + 1) {\n\t\tfor (let j = 0; j < zeroValues.length; j++) {\n\t\t\tlet tempValue = zeroValues[i];\n\t\t\tif (zeroValues[i] !== zeroValues[j]) {\n\t\t\t\tzeroValues[i] = zeroValues[j];\n\t\t\t\tzeroValues[j] = tempValue;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n//\nif (zeroValues.length === zeroIndexes.length) {\n\t\n\tfor (let i = 0; i < zeroIndexes.length; i++) {\n\t\tarrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];\n\t}\n}\n\nlet result = arrayOfWishNumbers.join(\" \");\n\nprint(result);"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n if (candyCount < childrenCount) {\n print(candyCount);\n continue;\n }\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var totalCandy;\n if (restCandy) {\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy > halfChildren) {\n restCandy = Math.floor(restCandy/halfChildren) * halfChildren;\n }\n totalCandy = firstCandy + restCandy;\n } else {\n totalCandy = firstCandy;\n }\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var totalCandy;\n if (restCandy) {\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy > halfChildren) {\n restCandy = Math.floor(restCandy/halfChildren) * halfChildren;\n }\n totalCandy = firstCandy + restCandy;\n } else {\n totalCandy = firstCandy;\n }\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount);\n var restCandy = candyCount - firstCandy;\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n }\n var totalCandy = firstCandy + restCandy;\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n }\n var totalCandy = firstCandy + restCandy;\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.ceil(candyCount / childrenCount);\n var restCandy = candyCount - firstCandy;\n var halfChildren = Math.ceil(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n }\n var totalCandy = firstCandy + restCandy;\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n } else {\n restCandy = Math.floor(restCandy/halfChildren) * halfChildren;\n }\n var totalCandy = firstCandy + restCandy;\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n } else {\n restCandy = Math.floor(restCandy/halfChildren) * childrenCount;\n }\n var totalCandy = firstCandy + restCandy;\n print(totalCandy);\n}"}, {"source_code": "const lines = readline().split(\" \").map(x => parseInt(x));\nconst t = lines[0];\nvar candyArray=[];\nfor (var i=0; i parseInt(x));\n var candyCount = data[0];\n var childrenCount = data[1];\n var firstCandy = Math.floor(candyCount / childrenCount) * childrenCount;\n var restCandy = candyCount - firstCandy;\n var totalCandy;\n if (restCandy) {\n var halfChildren = Math.floor(childrenCount / 2);\n if (restCandy <= halfChildren) {\n restCandy = halfChildren;\n } else {\n restCandy = Math.floor(restCandy/halfChildren) * halfChildren;\n }\n totalCandy = firstCandy + restCandy;\n } else {\n totalCandy = firstCandy;\n }\n print(totalCandy);\n}"}], "src_uid": "43b8e9fb2bd0ec5e0250a33594417f63"} {"source_code": "function sum(array){\n\tvar result = 0;\n\tfor(var i = 0; i < array.length; i++){\n\t\tresult += +array[i];\n\t}\n\treturn result;\n}\n\nvar n = +readline(), p = readline().split(\" \").map(Number),\nans = 0;\n\nprint((sum(p)/n).toFixed(12));", "positive_code": [{"source_code": "function main() {\n // write code here:\n const n = Number(stdin[0]);\n var arr = stdin[1].split(' ').map(Number);\n var percent=0.0;\n for(let i=0;i {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const avg = arr.reduce((avg, num) => {\n avg = avg + num / len;\n return avg;\n }, 0);\n console.log(avg);\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const all = parseInt(input[0], 10)\n const percent = input[1].split(' ')\n let all_percent = 0\n percent.forEach(el => {\n all_percent += parseInt(el, 10) / 100\n })\n let _result = (all_percent / all) * 100\n console.log(_result.toFixed(12))\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var sum = 0;\n for(var i = 0; i < N; i++){\n var tmp = list[i] / 100;\n sum += tmp;\n }\n myout((sum / N) * 100);\n}\n"}, {"source_code": "// http://codeforces.com/problemset/problem/977/A\nmodule.exports = solve;\nfunction solve(line) {\n let i = line.split(' ').map(n => parseInt(n, 10));\n return i.reduce((acc, c)=> acc + c, 0)/i.length;\n}\n\n\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet i = 0;\nrl.on('line', (line) => {\n if (i++) {\n console.log(solve(line))\n rl.close();\n }\n});"}, {"source_code": "//Drinks\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL)[1].split(' ').map(c => +c);\n \n process.stdout.write((lines.reduce((a, b) => a + b) / lines.length) + '');\n\n return;\n});"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n n = +d;\n return;\n }\n\n const total = n * 100;\n const values = d.split(' ').map(Number);\n const v = values.reduce((acc, curr) => acc + curr, 0);\n const ans = v / total * 100;\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n let answer = 0.0;\n nums.forEach(i => answer += i);\n\n console.log( (answer / nums.length).toPrecision(12) );\n});"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet arr = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet x = 0;\n\n\tarr.forEach(item => (x += item / 100));\n\tx /= n;\n\tx *= 100;\n\tconsole.log(x.toFixed(12));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let portions = readLine().split(' ').map(Number);\n let orangePortions = 0;\n\n for (let i = 0; i < portions.length; i++) {\n orangePortions = orangePortions + portions[i] / 100;\n }\n\n let orangeValue = orangePortions / n;\n\n console.log(orangeValue * 100);\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const [n] = input[0].split(' ').map(Number);\n const arr = input[1].split(' ').map(Number);\n console.log(arr.reduce((acc, curr) => acc + curr) / n);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar count = 0;\nvar total = 0.0;\nvar mix = 0;\n\nrl.on('line', (data) => {\n\n if(count!=0) {\n data = data .trim();\n\n var splitted = data.split(\" \");\n var len = splitted.length;\n\n for(var idx = 0; idx i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n let totalDrinksInFridge = parseInt(lines[0]);\n let orangePercentagePerDrink = lines[1].split(\" \").map( value => {\n return parseInt(value)\n });\n\n let totalOragePercentage = 0\n orangePercentagePerDrink.forEach( singleDrinkPercentage => {\n totalOragePercentage = totalOragePercentage + singleDrinkPercentage\n })\n\n let orangeVolumeInCoktail = (totalOragePercentage / totalDrinksInFridge)\n\n console.log(orangeVolumeInCoktail.toPrecision(14))\n})"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i += 2) {\n doit(txt[i] * 1, txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n}\n\nfunction doit(num, tab) {\n let sum = 0;\n tab.forEach(data => {\n sum += data / 100;\n });\n console.log(sum / num * 100);\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n let inputs = str.trim().replace(/\\r/g, '').split('\\n');\n let percentageDrinks = inputs[1].split(' ');\n let sum = 0;\n for (let i = 0; i < +inputs[0]; i++) {\n if (percentageDrinks[i] != 0) {\n let denominator = Number(100 / percentageDrinks[i]).toFixed(2);\n sum += +Number(1 / denominator).toFixed(2);\n }\n }\n sum = (sum / inputs[0]) * 100;\n\n return sum.toString();\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst orange = () => {\n let ar = input[1].split(' ').map(x => +x);\n let q = ar.reduce((a, b) =>( a + b));\n console.log(q / +input[0]);\n};\nreadLine.on('close', orange);"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(value => parseInt(value));\n let total = arr.reduce((sum, value) => {\n return sum + value;\n }, 0)\n\n console.log(total / n.toFixed(12));\n}"}, {"source_code": "var n=readline();\nvar sum=readline().split(' ').reduce(function(a,b){return a+ +b;}, 0);\n\nprint( sum/n );"}, {"source_code": "counter = 0\nx = parseInt(readline())\nd = readline().split(\" \")\nfor (i=0 ; i parseInt(x));\nvar total = 0;\nvar total_orange = 0;\norange.forEach(o=>{\n total+=100;\n total_orange +=o;\n }\n );\n print((total_orange/total)*100);\n "}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar t = readline().split(' ').reduce(function (p, e) { return p + 1/(100/(+e)); }, 0);\n\tprint(100 * t / n);\n\n}).call(this);"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line, orange) {\n var input = line.split(\" \");\n var percent = orange.split(\" \").map((x) => Number(x));\n\n var n = Number(input[0]);\n\n var o = 0;\n\n for (var i = 0; i < n; i++) {\n o += (percent[i] / 100);\n }\n\n return o / n * 100;\n}"}, {"source_code": "(function() {\n 'use strict';\n const n = readline();\n const z = readline().split(' ').map(Number);\n let x = 0;\n for (let i =0; i < n; ++i) {\n x += z[i] / 100;\n }\n let y = x / n * 100;\n print(y);\n}());"}, {"source_code": "var ingredientes = readline();\nvar porcentajes = readline().split(\" \");\nvar suma_porcentajes = 0;\n\nfor (i=0;i a+b) / n);"}, {"source_code": "(function main() {\n var n = +readline(),\n result = readline()\n .split(\" \")\n .map(function(a) {\n return +a;\n })\n .reduce(function(a, b) {\n return a + b;\n });\n\n print(result / n);\n\n})();\n"}, {"source_code": "\n// 200B \u041d\u0430\u043f\u0438\u0442\u043a\u0438 \n/*\nfunction main_1(){\n var n = parseInt(readline());\n var ans = 0;\n while (n--) {\n var nums = readline().split(' ').map(Number);\n ans += (nums[2] - nums[0] + 1) * (nums[3] - nums[1] + 1);\n }\n print(ans);\n}\n\nfunction main(){\n var line = readline();\n //var line = prompt();\n var n = line.length;\n //alert(line);\n var m = 0;\n for(i=0;ia+c,0)/n)\n\n"}, {"source_code": "var n = readline();\nvar a = readline().split(' ').map(Number);\nvar ans = 0;\nfor(i = 0; i < n; i++) ans += a[i];\nprint(ans / n);"}, {"source_code": "var numberOfDrinks = readline();\nvar percentages = readline().split(' ');\n\nvar sum = percentages.reduce((acc, percentage) => {\n return acc + parseInt(percentage);\n}, 0);\n\nprint(sum > 0 ? sum/numberOfDrinks : sum);"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => Number(acc)+Number(cur) ,0);\nvar answer = result/drinks.length;\nprint(answer)"}, {"source_code": "var o = readline();\nvar d = readline().split(' ');\nvar h = [];\nfor (i = 0; i <= d.length - 1; i++) {\n h.push(d[i] / 100); \n}\nfunction all(total, num) {\n return total + num;\n}\nvar out = (h.reduce(all) / o ) * 100; \nprint(out);"}, {"source_code": "var x = readline();\nvar z = readline().split(\" \").map((a)=>(+a));\nvar y = 0; for (var i = 0; i {lines.push(line);})\n\t\t\t\t.on('close', () => {main(lines)});\n\nconst main = (input) => {\n\tvar n = parseInt(input[0]);\n\tvar percentages = input[1].split(\" \").map(num => parseInt(num));\n\tvar sum = 0;\n\tfor (var i = 0; i < n; i++) {\n\t\tsum += percentages[i];\n\t}\n\tconsole.log(sum/n);\n}"}], "negative_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const all = parseInt(input[0], 10)\n const percent = [...input.slice(1)]\n let all_percent = 0\n percent.forEach(el => {\n all_percent += parseInt(el, 10) / 100\n })\n let _result = (all_percent / all) * 100\n console.log(_result.toFixed(12))\n})"}, {"source_code": "counter = 0\nx = parseInt(readline())\nd = readline().split(\" \")\nfor (i=0 ; i {\n return acc + percentage;\n}, 0);\n\nprint(sum > 0 ? sum/numberOfDrinks : sum);"}, {"source_code": "var numberOfDrinks = readline();\nvar percentages = readline().split(' ');\n\nvar sum = percentages.reduce((acc, percentage) => {\n return acc + percentage;\n}, 0);\n\nprint(sum > 0 ? sum/numberOfDrinks : sum);"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => acc+Number(cur) ,0);\nvar answer = result/drinks.length;\nprint(answer)"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => acc+cur ,0);\nprint(result/drinks.length)"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => acc+(+cur) ,0);\nprint(result/drinks.length)"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => acc+cur ,0);\nvar answer = result/drinks.length;\nprint(answer)"}, {"source_code": "var useless = readline();\nvar drinks = readline().split(\" \");\nvar result = drinks.reduce((cur,acc) => acc+cur ,0);\nvar answer = result/drinks.length;\nprint(\"Here\", drinks, \" \", result, \" \", answer);\nprint(answer)"}, {"source_code": "var o = readline();\nvar d = [0, 25, 50, 75];\nvar h = [];\nfor (i = 0; i <= d.length - 1; i++) {\n h.push(d[i] / 100); \n}\nfunction all(total, num) {\n return total + num;\n}\nvar out = (h.reduce(all) / o ) * 100;\nprint(out);"}], "src_uid": "580596d05a2eaa36d630d71ef1055c43"} {"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = \"\";\n const arr = d.split(\" \").map(Number);\n\n for (let i = 0; i < arr.length; i++) {\n const leftVal = i === 0 ? Infinity : arr[i - 1];\n const rightVal = i === arr.length - 1 ? Infinity : arr[i + 1];\n const minL = Math.abs(arr[i] - leftVal);\n const minR = Math.abs(rightVal - arr[i]);\n const min = Math.min(minL, minR);\n const maxL = Math.abs(arr[i] - arr[0]);\n const maxR = Math.abs(arr[arr.length - 1] - arr[i]);\n const max = Math.max(maxL, maxR);\n\n ans += `${min} ${max}\\n`;\n }\n\n console.log(ans);\n\n c++;\n});\n", "positive_code": [{"source_code": "var n = +readline(), c = readline().split(\" \"), min = 2e9, max = 0;\n\nfor(i = 0; i < n; i++){\n\tif(i == 0){\n\t\tmin = Math.abs( +c[i] - +c[i+1] );\n\t\tmax = Math.abs( +c[i] - +c[n-1] );\n\t\twrite( min + \" \" + max + \"\\n\" );\n\t}\n\telse if(i == n-1){\n\t\tmin = Math.abs( +c[i] - +c[i-1] );\n\t\tmax = Math.abs( +c[i] - +c[0] );\n\t\twrite( min + \" \" + max + \"\\n\" );\n\t}\n\telse{\n\t\tmin = ( Math.abs(+c[i] - +c[i-1]) < Math.abs(+c[i] - +c[i+1]) ) ? Math.abs(+c[i] - +c[i-1]) : Math.abs(+c[i] - +c[i+1]);\n\t\tmax = ( Math.abs(+c[i] - +c[0]) > Math.abs(+c[i] - +c[n-1]) ) ? Math.abs(+c[i] - +c[0]) : Math.abs(+c[i] - +c[n-1]);\n\t\twrite( min + \" \" + max + \"\\n\" );\n\t}\n}"}, {"source_code": "var n = parseInt(readline());\nvar input = readline().split(' ').map(x=>parseInt(x));\nvar x=input[0];\nvar y=input[n-1];\nvar mn1 , mn2 , mn;\nvar mx1 , mx2 , mx ;\nfor(var i=0;ib.value) return 1;\n return 0;\n}\n\ninitializeData();\n\nn = parseInt(readline());\n\ntoken = readline().split(' ');\nfor(var i=0;i0) ans1[idx]=Math.min(ans1[idx],arr[i].value-arr[i-1].value);\n if(i+1 parseInt(x)); \nif(inputLength == 1) {\n\tinputLength = 0;\n\tconsole.log(0);\n}\nvar min, max;\nfor (var i = 0; i < inputLength; i++) {\n var distanceFromLeft = Math.abs(input[i - 1] - input[i]),\n distanceFromRight = Math.abs(input[i + 1] - input[i]),\n distanceFromFirst = Math.abs(input[0] - input[i]),\n distanceFromLast = Math.abs(input[inputLength - 1] - input[i]);\n if ((distanceFromLeft || Infinity) < (distanceFromRight || Infinity)) {\n min = distanceFromLeft;\n } else {\n min = distanceFromRight;\n }\n if ((distanceFromFirst || -Infinity) > (distanceFromLast || -Infinity)) {\n max = distanceFromFirst;\n } else {\n max = distanceFromLast;\n }\n print(min + ' ' + max);\n}\n"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \");\nfor(i = 0; i < n; i++){\n var min;\n var max;\n if(i == n -1){\n min = Math.abs(a[i] - a[i-1]);\n max = Math.abs(a[i] - a[0]);\n print(min + \" \" + max + \"\\n\");\n break;\n }\n if(i == 0){\n min = Math.abs(a[i] - a[i+1]);\n max = Math.abs(a[i] - a[n-1]);\n }\n else{\n min = Math.min(Math.abs(a[i] - a[i+1]), Math.abs(a[i] - a[i-1]));\n max = Math.max(Math.abs(a[i] - a[0]), Math.abs(a[i] - a[n-1]));\n }\n print(min + \" \" + max + \"\\n\");\n}"}, {"source_code": "var n = readline(), list = readline().split(' '), max, min\nfor (var i = 0 ; i < n; i++){\n if (i === 0) {\n min = Math.abs(list[i+1]-list[i])\n max = Math.abs(list[n-1]-list[i])\n }\n else if (i === n-1){\n min = Math.abs(list[i-1]-list[i])\n max = Math.abs(list[0]-list[i])\n }\n else {\n min = Math.min( Math.abs(list[i+1]-list[i]), Math.abs(list[i-1]-list[i]) )\n max = Math.max( Math.abs(list[n-1]-list[i]), Math.abs(list[0]-list[i]))\n }\n \n print(min + ' ' + max)\n}\n"}, {"source_code": "var n = readline()\nvar list = readline().split(' ')\nfor (var i = 0 ; i < n; i++){\n if (i === 0) {\n print(Math.abs(list[i+1]-list[i]) + ' ' + Math.abs(list[n-1]-list[i]))\n }\n else if (i === n-1){\n print(Math.abs(list[i-1]-list[i]) + ' ' + Math.abs(list[0]-list[i]))\n }\n else {\n print( Math.min( Math.abs(list[i+1]-list[i]), Math.abs(list[i-1]-list[i]) ) + ' ' + Math.max( Math.abs(list[n-1]-list[i]), Math.abs(list[0]-list[i])))\n }\n}\n"}, {"source_code": "//int n, *cit;\n//\tcin >> n;\n//\tcit = new int[n];\n//\tfor (int i = 0; i < n; i++)\n//\t{\n//\t\tcin >> cit[i];\n//\t}\n//\n//\tfor (int i = 0; i < n; i++)\n//\t{\n//\t\t\n//\t\tint max = abs(cit[i] - cit[n - 1]) > abs(cit[i] - cit[0]) ? abs(cit[i] - cit[n - 1]) : abs(cit[i] - cit[0]);\n//\t\tint min = 0, rgt, lft;\n//\t\t\n//\t\tif (i == 0)\n//\t\t{\n//\t\t\tmin = abs(cit[i] - cit[i + 1]);\n//\t\t}\n//\t\telse if (i == n - 1)\n//\t\t{\n//\t\t\tmin = abs(cit[i] - cit[i - 1]);\n//\t\t}\n//\t\telse\n//\t\t{\n//\t\t\tmin = abs(cit[i] - cit[i - 1]) < abs(cit[i] - cit[i + 1]) ? abs(cit[i] - cit[i - 1]) : abs(cit[i] - cit[i + 1]);\n//\t\t}\n//\n//\t\tcout << min << \" \" << max << endl;\n//\t}\n\nvar n = readline();\nn = parseInt(n);\nvar cits = readline().split(\" \").map(function(x){ return parseInt(x); });\nfor(var i = 0; i < n; i++)\n{\n var max = Math.abs(cits[i] - cits[n - 1]) > Math.abs(cits[i] - cits[0]) ? Math.abs(cits[i] - cits[n - 1]) : Math.abs(cits[i] - cits[0]);\n \n if(i == 0)\n {\n var min = Math.abs(cits[i] - cits[i + 1]);\n }\n else if (i == n - 1)\n {\n min = Math.abs(cits[i] - cits[i - 1]);\n }\n else\n {\n min = Math.abs(cits[i] - cits[i - 1]) < Math.abs(cits[i] - cits[i + 1]) ? Math.abs(cits[i] - cits[i - 1]) : Math.abs(cits[i] - cits[i + 1]);\n }\n \n print(min + \" \" + max);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var n = readline();\nvar dis = readline().split(\" \");\nvar max = new Array(2);\nvar min = [];\n\nfor(var i = 0; i < n; i++){\n\tif(i-1>=0) min.push(parseInt(dis[i]-dis[i-1]));\n\tif(i+1<=n-1) min.push(parseInt(dis[i+1]-dis[i]));\n\tmax[0] = parseInt(dis[i]-dis[0]);\n\tmax[1] = parseInt(dis[n-1]-dis[i]);\n\tvar s1 = (min.length == 2) ? (min[0] < min[1]) ? min[0] : min[1] : min[0];\n\tvar s2 = (max[0] > max[1]) ? max[0] : max[1];\n\tprint(s1 + \" \" + s2);\n\tmin = [];\n}"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar min = cities[n-1] - cities[0];\n\t\tvar max = 0;\n\t\t\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\n\n\t\twrite(min + \" \" + max + \"\\n\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar min = cities[n-1] - cities[0];\n\t\tvar max = 0;\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\t\tprint(min + \" \" + max);\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar min = cities[n-1] - cities[0];\n\t\tvar max = 0;\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\t\t\n\t\tprint(min + \" \" + max);\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (i = 0; i < n; i++) {\n\t\tmin = cities[n-1] - cities[0];\n\t\tmax = 0;\n\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\n\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\n\t\twrite(min + \" \" + max + \"\\n\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar min = cities[n-1] - cities[0];\n\t\tvar max = 0;\n\t\t\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\n\n\t\tprint(min + \" \" + max);\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tvar min = cities[n-1] - cities[0];\n\t\tvar max = 0;\n\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\t\t\n\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\n\t\twrite(min + \" \" + max + \"\\n\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function main() {\n\tn = readline();\n\tcities = readline().split(\" \");\n\n\tfor (var i = 0; i < n; i++) {\n\t\tmin = cities[n-1] - cities[0];\n\t\tmax = 0;\n\n\t\tif (i > 0 && min > (cities[i] - cities[i-1])) {\n\t\t\tmin = cities[i] - cities[i-1];\n\t\t}\n\t\tif (i+1 < n && min > (cities[i+1] - cities[i])) {\n\t\t\tmin = cities[i+1] - cities[i];\n\t\t}\n\n\t\tif (max < (cities[i] - cities[0])) {\n\t\t\tmax = cities[i] - cities[0];\n\t\t}\n\t\tif (max < (cities[n-1] - cities[i])) {\n\t\t\tmax = cities[n-1] - cities[i];\n\t\t}\n\n\t\twrite(min + \" \" + max + \"\\n\");\n\t}\n}\n\nmain();\n"}, {"source_code": "function main(){\n\nvar line1 = readline();\nvar line2 = readline().split(' ').map(Number);\n\nvar n = parseInt(line1);\n\nif(n===2){\n var str = '';\n\n str += (Math.abs(line2[0]-line2[1]));\n str += ' ';\n str += (Math.abs(line2[0]-line2[1]));\n \n print(str);\n print(str);\n \n return;\n}\n\nfor(i=0;imax){\n\t max = Math.abs(line2[i]-line2[0]);\n\t}\n }\n\n if(i!== n-1){\n\tif(Math.abs(line2[i]-line2[i+1])max){\n\t max = Math.abs(line2[i]-line2[n-1]);\n\t}\n }\n\n str += min;\n str += ' ';\n str += max;\n \n print(str);\n}\n}\nmain();"}, {"source_code": "readline()\nT=readline().split(' ').map(x=>+x)\na=Math.abs,mi=Math.min,ma=Math.max,M=Number.MAX_VALUE,L=T.length\nprint(T.map((x,i)=>\n `${mi(i?a(T[i-1]-T[i]):M,(i+x)\na=Math.abs,mi=Math.min,ma=Math.max\nq=T.map((x,i)=>\n `${mi(i?a(T[i-1]-T[i]):Number.MAX_VALUE,(i+x)\na=Math.abs,mi=Math.min,ma=Math.max,M=Number.MAX_VALUE\nprint(T.map((x,i)=>\n `${mi(i?a(T[i-1]-T[i]):M,(i 0 && b > 0) || (a < 0 && b < 0)) {\n\t\treturn Math.abs(moduloA - moduloB);\n\t} else {\n\t\treturn Math.abs(moduloA + moduloB);\n\t}\n}\n\nvar cidade = readline();\nvar arrayCidades = readline().split(\" \").map(function(x) { return parseInt(x); });\n\nvar primeiro = arrayCidades[0];\nvar ultimo = arrayCidades[arrayCidades.length - 1];\nfor(var i = 0 ; i < arrayCidades.length ; i ++) {\n\tvar valorCidade = arrayCidades[i];\n\tvar menorDistancia;\n if ( i === 0 ) {\n menorDistancia = calculaDistancia(valorCidade, (arrayCidades.length >= 2 ? arrayCidades[i+1] : valorCidade));\n } else if ( i === arrayCidades.length - 1 ) {\n menorDistancia = calculaDistancia(valorCidade, (arrayCidades.length >= 2 ? arrayCidades[i-1] : valorCidade));\n } else {\n \tvar distanciaEsquerda = calculaDistancia(valorCidade, arrayCidades[i-1]);\n \tvar distanciaDireita = calculaDistancia(valorCidade, arrayCidades[i+1]);\n \tmenorDistancia = distanciaEsquerda > distanciaDireita ? distanciaDireita : distanciaEsquerda;\n }\n var maiorDistanciaEsquerda = calculaDistancia(primeiro, valorCidade);\n var maiorDistanciaDireita = calculaDistancia(ultimo, valorCidade);\n var maiorDistancia = maiorDistanciaEsquerda > maiorDistanciaDireita ? maiorDistanciaEsquerda : maiorDistanciaDireita;\n print(menorDistancia, maiorDistancia);\n}"}, {"source_code": "var citiesCount = parseInt(readline());\nvar places = readline().split(\" \").map(Number);\n\nfor (var i = 0; i < places.length; i++) {\n var min = 0;\n var max = 0;\n \n // Min of 2 nearby values\n min = Math.min(\n Math.abs(places[i] - (i === 0 ? Infinity: places[i - 1])),\n Math.abs(places[i] - (i === places.length - 1 ? Infinity: places[i + 1]))\n );\n \n // Max of first and last value\n max = Math.max(\n Math.abs(places[i] - places[0]),\n Math.abs(places[i] - places[places.length - 1])\n )\n \n print(`${min} ${max}`);\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n for (let i = 0; i < n; i++) {\n let min, max;\n if (i === 0) {\n min = a[i+1] - a[i];\n max = a[n-1] - a[0];\n } else if (i === n - 1) {\n min = a[i] - a[i-1];\n max = a[n-1] - a[0];\n } else {\n min = Math.min(a[i] - a[i-1], a[i+1] - a[i]);\n max = Math.max(a[i] - a[0], a[n-1] - a[i]);\n }\n print(`${min} ${max}\\n`);\n }\n}\n\n"}, {"source_code": "const readLine = require('readline')\nconst rl = readLine.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nlet n\nlet miasta\n\nrl.question('', (line) => {\n n = parseInt(line)\n rl.question('', (line) => {\n miasta = line.split(' ').map(Number)\n miasta.splice(0,0, Number.NEGATIVE_INFINITY)\n miasta.push(Number.POSITIVE_INFINITY)\n main()\n })\n})\n\nfunction main() {\n for (let i = 1; i<=n; i++) {\n minimum = Math.min(miasta[i]-miasta[i-1], miasta[i+1]-miasta[i])\n maximum = Math.max(miasta[i]-miasta[1], miasta[n]-miasta[i])\n console.log(minimum, maximum) \n }\n rl.close()\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction max(a,b) {\n if(a > b) return a;\n else return b;\n}\nfunction main() {\n let [n] = readint();\n let x = readint();\n let mn, mx;\n let last = x.length - 1;\n for(let i = 0; i < last + 1; i++) {\n if(i == 0) {\n mn = x[1] - x[0];\n mx = x[last] - x[0];\n }\n else if(i == last) {\n mn = x[last] - x[last - 1];\n mx = x[last] - x[0]; \n } else {\n mn = min((x[i] - x[i-1]), (x[i + 1] - x[i]));\n mx = max(x[i] - x[0], x[last] - x[i]);\n }\n write(mn + \" \" + mx + \"\\n\");\n }\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n\nlet cities\n\nrl.question('', (line) => {\n n = parseInt(line)\n rl.question('', (line) => {\n cities = line.split(' ').map(Number)\n cities.splice(0, 0, Number.NEGATIVE_INFINITY)\n cities.push(Number.POSITIVE_INFINITY)\n main()\n })\n});\n\nfunction main() {\n for (let i = 1; i <= n; ++i) {\n minimum = Math.min(cities[i] - cities[i-1], cities[i+1] - cities[i])\n maximum = Math.max(cities[i] - cities[1], cities[n] - cities[i])\n console.log(minimum, maximum)\n }\n\n rl.close();\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet secondLine = input[1].split(' ');\nconst n = parseInt(input[0], 10);\nsecondLine = secondLine.map((el) => parseInt(el, 10));\n\nlet text = '';\nfor (let i = 0; i< n; i++) {\n const current = secondLine[i];\n const right = secondLine[i + 1] !== undefined ? Math.abs(current-secondLine[i + 1]) : null;\n const left = secondLine[i - 1] !== undefined ? Math.abs(current-secondLine[i - 1]) : null;\n const minimum = right !== null && left !== null ? Math.min(right, left) : right || left;\n const maximum = Math.max(Math.abs(secondLine[0] - current), Math.abs(secondLine[n-1] - current))\n text += `${minimum} ${maximum}\\n`\n}\ntext = text.slice(0, text.length-1)\nconsole.log(text);\n});"}], "negative_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet c = 0;\n\nrl.on(\"line\", (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = \"\";\n const arr = d.split(\" \").map(Number);\n\n for (let i = 0; i < arr.length; i++) {\n let minL = Math.abs(arr[i] - (arr[i - 1] || Infinity));\n let minR = Math.abs((arr[i + 1] || Infinity) - arr[i]);\n let min = Math.min(minL, minR);\n let maxL = Math.abs(arr[i] - arr[0]);\n let maxR = Math.abs(arr[arr.length - 1] - arr[i]);\n let max = Math.max(maxL, maxR);\n\n ans += `${min} ${max}\\n`;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet secondLine = input[1].split(' ');\nconst n = parseInt(input[0], 10);\nsecondLine = secondLine.map((el) => parseInt(el, 10));\n\nlet text = '';\nfor (let i = 0; i< n; i++) {\n const current = secondLine[i];\n const right = secondLine[i + 1] ? Math.abs(current-secondLine[i + 1]) : null;\n const left = secondLine[i - 1] ? Math.abs(current-secondLine[i - 1]) : null;\n const minimum = right && left ? Math.min(right, left) : right || left;\n const maximum = Math.max(Math.abs(secondLine[0] - current), Math.abs(secondLine[n-1] - current))\n text += `${minimum} ${maximum}\\n`\n}\ntext = text.slice(0, text.length-1)\nconsole.log(text);\n});"}, {"source_code": "var n = readline();\nvar dis = readline().split(\" \");\nvar max = new Array(2);\nvar min = [];\n\nfor(var i = 0; i < 4; i++){\n\tif(i-1>=0) min.push(parseInt(dis[i]-dis[i-1]));\n\tif(i+1<=n-1) min.push(parseInt(dis[i+1]-dis[i]));\n\tmax[0] = parseInt(dis[i]-dis[0]);\n\tmax[1] = parseInt(dis[n-1]-dis[i]);\n\tvar s1 = (min.length == 2) ? (min[0] < min[1]) ? min[0] : min[1] : min[0];\n\tvar s2 = (max[0] > max[1]) ? max[0] : max[1];\n\tprint(s1 + \" \" + s2);\n\tmin = [];\n}"}, {"source_code": "function main(){\n\nvar line1 = readline();\nvar line2 = readline().split(' ').map(Number);\n\nvar n = parseInt(line1);\n\nif(n===2){\n var str = '';\n\n str += (Math.abs(line2[0]-line2[1]));\n str += ' ';\n str += (Math.abs(line2[0]-line2[1]));\n \n print(str);\n print(str);\n \n return;\n}\n\nfor(i=0;imax){\n\t max = Math.abs(line2[i]-line2[0]);\n\t}\n }\n\n if(i!== n-1){\n\tif(Math.abs(line2[i]-line2[i+1])max){\n\t max = Math.abs(line2[i]-line2[n-1]);\n\t}\n }\n\n str += min;\n str += ' ';\n str += max;\n \n print(str);\n}\n}\nmain();"}, {"source_code": "var line1 = readline();\nvar line2 = readline().split(' ').map(Number);\n\nvar n = parseInt(line1);\n\n\n\nfor(i=0;imax){\n\t max = Math.abs(line2[i]-line2[j]);\n\t}\n }\n \n str += min;\n str += ' ';\n str += max;\n\n print(str);\n}\n\n"}, {"source_code": "var citiesCount = parseInt(readline());\nvar places = readline().split(\" \").map(Number);\n\nfor (var i = 0; i < places.length; i++) {\n var min = 0;\n var max = 0;\n \n // Min of 2 nearby values\n min = Math.min(\n Math.abs(places[i] - (places[ i - 1] || -Infinity)),\n Math.abs(places[i] - (places[i + 1] || -Infinity))\n );\n \n // Max of first and last values\n max = Math.max(\n Math.abs(places[i] - places[0]),\n Math.abs(places[i] - places[places.length - 1])\n )\n \n print(`${min} ${max}`);\n}"}, {"source_code": "var citiesCount = parseInt(readline());\nvar places = readline().split(\" \").map(Number);\n\nfor (var i = 0; i < places.length; i++) {\n var min = 0;\n var max = 0;\n \n // Min of 2 nearby values\n min = Math.min(\n Math.abs(places[i] - (places[ i - 1] || places[i])),\n Math.abs(places[i] - (places[i + 1] || places[i]))\n );\n \n // Max of first and last values\n max = Math.max(\n Math.abs(places[i] - places[0]),\n Math.abs(places[i] - places[places.length - 1])\n )\n \n print(`${min} ${max}`);\n}"}, {"source_code": "var citiesCount = parseInt(readline());\nvar places = readline().split(\" \").map(Number);\n\nfor (var i = 0; i < places.length; i++) {\n var min = 0;\n var max = 0;\n \n // Min of 2 nearby values\n min = Math.min(\n Math.abs(places[i] - (places[ i - 1] || 0)),\n Math.abs(places[i] - (places[i + 1] || 0))\n );\n \n // Max of first and last values\n max = Math.max(\n Math.abs(places[i] - places[0]),\n Math.abs(places[i] - places[places.length - 1])\n )\n \n print(`${min} ${max}`);\n}"}], "src_uid": "55383f13c8d097408b0ccf5653c4563d"} {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\n\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n})\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const n = arr.length;\n if (n % 2 === 0) {\n const b = (n/2) - 1;\n if (arr[b] <= b && arr[b+1] <= b) {\n return false;\n }\n }\n for(let i = 0; i < n; i++) {\n if (arr[i] < Math.min(i, n-i-1)) {\n return false;\n }\n }\n return true;\n}\n\nfunction main() {\n const t = parseInt(readline());\n for(let i = 0; i < t; i++) {\n readline();\n const arr = readline().split(' ');\n const res = solve(arr);\n console.log(res ? 'Yes' : 'No');\n }\n}\n", "positive_code": [{"source_code": "var numRun= readline();\n \n//zeroes are important and the number of units it is away from the end\n//012343210 is an ideal array. as long as every digit is greater than the number it is from the end, it is ok\n//3210 is ok; 0110 is not ok... need to find this example\n//possible arrays could be 012345,543210,0123210\nfor(var n=0;n=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//right to left\nfunction checkDown(arr){\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//check if it is a pyramid... highest index is in the middle\nfunction checkMidOdd(arr){\n var mid=Math.floor(arr.length/2);\n for(var i=0;i<=mid;i++){\n if(arr[i]>=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}\n\n//check if it is a pyramid... highest index is in the middle\n//high point will be arr.length/2-1 (for 4 array, index 1)\nfunction checkMidEven1(arr){\n if(arr.length%2===1){return false;}\n var mid=Math.floor(arr.length/2);\n for(var i=0;i<=mid;i++){\n //print(\"index: \"+i);\n if(arr[i]>=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}\n\nfunction checkMidEven2(arr){\n if(arr.length%2===1){return false;}\n var mid=Math.floor(arr.length/2)-1;\n if(arr[mid]=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i<=mid;i++){\n //print(arr.length-1-i);\n if(arr[arr.length-1-i]>=i){}\n else{return false;}//one index is too low\n }\n return true;\n}"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var len = +readline();\n var arr = readline()\n .split(\" \")\n .map(Number);\n\n var left = findLeft(arr);\n var right = findRight(arr);\n if (left >= right) {\n print(\"Yes\");\n } else {\n print(\"No\");\n }\n }\n}\n\nfunction findLeft(arr) {\n var left = arr.length;\n for (var j = 0; j < arr.length; j++) {\n if (arr[j] < j) {\n left = j - 1;\n break;\n }\n }\n return left;\n}\n\nfunction findRight(arr) {\n var right = 0;\n for (var k = 0; k < arr.length; k++) {\n if (arr[arr.length - 1 - k] < k) {\n right = arr.length - k;\n break;\n }\n }\n return right;\n}\n\nmain()"}], "negative_code": [{"source_code": "var numRun= readline();\n \n//zeroes are important and the number of units it is away from the end\n//012343210 is an ideal array. as long as every digit is greater than the number it is from the end, it is ok\n//3210 is ok; 0110 is not ok... need to find this example\n//possible arrays could be 012345,543210,0123210\nfor(var n=0;n=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//right to left\nfunction checkDown(arr){\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//check if it is a pyramid... highest index is in the middle\nfunction checkMidOdd(arr){\n var mid=Math.floor(arr.length/2);\n for(var i=0;i<=mid;i++){\n if(arr[i]>=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}\n\n//check if it is a pyramid... highest index is in the middle\n//high point will be arr.length/2-1 (for 4 array, index 1)\nfunction checkMidEven1(arr){\n if(arr.length%2===1){return false;}\n var mid=Math.floor(arr.length/2);\n if(arr[mid]=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}\n\nfunction checkMidEven2(arr){\n if(arr.length%2===1){return false;}\n var mid=Math.floor(arr.length/2)-1;\n if(arr[mid]=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}"}, {"source_code": "var numRun= readline();\n \n//zeroes are important and the number of units it is away from the end\n//012343210 is an ideal array. as long as every digit is greater than the number it is from the end, it is ok\n//3210 is ok; 0110 is not ok... need to find this example\n//possible arrays could be 012345,543210,0123210\nfor(var n=0;n=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//right to left\nfunction checkDown(arr){\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }//fpr\n return true;\n}//checkUp\n\n//check if it is a pyramid... highest index is in the middle\nfunction checkMidOdd(arr){\n var mid=Math.floor(arr.length/2);\n for(var i=0;i<=mid;i++){\n if(arr[i]>=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}\n\n//check if it is a pyramid... highest index is in the middle\n//high point will be arr.length/2-1 (for 4 array, index 1)\nfunction checkMidEven(arr){\n if(arr.length%2===1){return false;}\n var mid=Math.floor(arr.length/2);\n if(arr[mid]>=mid&&arr[mid+1]>=mid){return false;}\n for(var i=0;i<=mid;i++){\n if(arr[i]>=i){}\n else{return false;}//one index is too low\n }\n for(var i=0;i=i){}\n else{return false;}//one index is too low\n }\n return true;\n}"}], "src_uid": "b9d5e58459baf2a2c294225b73b7229b"} {"source_code": "//var input = readline()\nvar t = parseInt(readline());\nfor(var i=0; i parseInt(x));\n var a = ar[0], b = ar[1];\n print(b*2)\n}\n\n//", "positive_code": [{"source_code": "var t = Number(readline());\nwhile(t--){\n w = readline().split(' ').map(x => Number(x));\n print(String(w[1] * 2) + '\\n' );\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n let lines = i.split(EOL) /*your input text, split by lines*/\n const t = Number.parseInt(lines[0]);\n curInd = 0;\n for (let i = 0; i < t; ++i) {\n curInd += 1\n let line = lines[curInd].split(\" \");\n const n = Number.parseInt(line[0]);\n const x = Number.parseInt(line[1]);\n console.log(x * 2);\n }\n})\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n Main();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = nextIntArray();\n output[i] = tmp[1] * 2;\n }\n myout(myconv(output, 9));\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let [n, x] = d.split(' ').map(Number);\n console.log(x*2);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nvar T;\n\nrl.on(\"line\", (line) => {\n\tif (T == null) T = parseInt(line);\n\telse {\n\t\tvar x = parseInt(line.split(' ')[1]);\n\t\tconsole.log(x*2);\n\t\tT --;\n\t\tif (T == 0) \n\t\t\trl.close();\n\t}\n});"}, {"source_code": "var queriesAmount = parseInt(readline())\n\nfor (var i = 0; i < queriesAmount; i++) {\n var nAndX = readline().split(' ').map(function(element) {\n return parseInt(element);\n });\n \n n = nAndX[0];\n x = nAndX[1];\n\n print(2 * x);\n}"}, {"source_code": "\"use strict\";\n \nvar main = function() {\n var T = +rd();\n while (T-->0) {\n var x = rdAr()[1];\n pr(x << 1);\n }\n};\n \nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar prAr = (a) => pr(a.join(' '));\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n \nmain();"}, {"source_code": "a=readline;for(k=a();k--;)print(a().split(\" \")[1]*2)"}, {"source_code": "a=readline;k=a();while(k--){print(a().split(\" \")[1]*2)}"}, {"source_code": "a=readline;k=a();while(k--){n=a().split(\" \");print(n[1]*2);}"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n var w = readline().split(' ').map(x => Number(x));\n print(String(w[1] * 2) + '\\n' );\n}"}, {"source_code": "var t = Number(readline());\nwhile(t--){\n w = readline().split(' ').map(x => Number(x));\n print(String(w[1] * 2) + '\\n' );\n delete w;\n}\n"}], "negative_code": [], "src_uid": "f79a926e18a3f81b24f2fc3ae5c8f928"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet ok = 1;\r\n\t\tfor (let i = 0; i < k; i++) {\r\n\t\t\tok = ok && s[i] == s[n-i-1];\r\n\t\t}\r\n\r\n\t\tconsole.log(ok && 2*k < n ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, s) => {\r\n if (k * 2 >= n) return pr('NO');\r\n let left = s.slice(0, k);\r\n let right = reverse2(s.slice(n - k));\r\n if (left == right) return pr('YES');\r\n pr('NO');\r\n};\r\n\r\nconst reverse2 = (s) => {\r\n let res = \"\";\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n res += s[i];\r\n }\r\n return res;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, s) => {\r\n if (k * 2 >= n) return pr('NO');\r\n let left = s.substr(0, k);\r\n let right = reverse2(s.substr(n - k, k));\r\n if (left == right) return pr('YES');\r\n pr('NO');\r\n};\r\n\r\nconst reverse2 = (s) => {\r\n let res = \"\";\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n res += s[i];\r\n }\r\n return res;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\t\tconst s = rl();\r\n\r\n\t\tlet cnt = 0;\r\n\t\tfor (let i = 0; i < Math.ceil(n/2)-1; i++) {\r\n\t\t\tif (s[i] == s[n-i-1]) cnt++;\r\n\t\t\telse break;\r\n\t\t}\r\n\r\n\t\tconsole.log(cnt >= k ? 'YES' : 'NO');\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n if (k === 0) return console.log('YES')\r\n if (n % 2 === 0 && n === k * 2) return console.log('NO')\r\n\r\n var isTrue = true\r\n // console.log(n, k)\r\n for (let i = 0; i < k; i++) {\r\n// console.log(a[i], a[n-i-1], n-k+i-1)\r\n if(a[i] !== a[n-i-1]) isTrue = false\r\n }\r\n// console.log(isTrue)\r\nconsole.log(isTrue ? 'YES':'NO')\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar s = next();\r\n\t\tif(K == 0){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar count = 0;\r\n\t\tfor(var j = 0; j < K; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tcount++;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(count >= K){\r\n\t\t\tif(count == K && N / 2 == K && N % 2 == 0){\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n var t = parseInt(readline());\r\n while(t-- > 0) {\r\n var n, k, s;\r\n\r\n [n, k] = readline().split(\" \").map(s => parseInt(s));\r\n s = readline();\r\n\r\n if (2*k + 1 > s.length)\r\n console.log(\"NO\");\r\n else {\r\n var ans = \"YES\";\r\n\r\n for (var i = 0; i < s.length/2; i++) {\r\n if (s[i] != s[s.length - i - 1]) {\r\n if (i < k)\r\n ans = \"NO\";\r\n break;\r\n }\r\n }\r\n\r\n console.log(ans);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data * 2\r\n } else if (count !== 0) {\r\n inputArr.push(data)\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n // inputArr = inputArr.map(i => i.split(' ').map(j => j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, k], str) {\r\n if (k * 2 === n) return false\r\n let nstr = str.split('').reverse()\r\n for (let i = 0; i < k; i++) {\r\n if (str[i] !== nstr[i]) return false\r\n }\r\n return true\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i += 2) {\r\n let res = solve(inputArr[i].split(' ').map(j => +j), inputArr[i + 1])\r\n res ? console.log('YES') : console.log('NO')\r\n }\r\n}"}, {"source_code": "function getInt(num){\r\n return parseInt(num, 10)\r\n }\r\n \r\nvar t = parseInt(readline(), 10);\r\nvar lines= [];\r\nfor(var i = 0; ij){\r\n i=i-1;\r\n j=j+1\r\n }\r\n print(i >= k? 'YES' : 'NO');\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, s) => {\r\n if (k == 0) return pr('YES');\r\n for (let i = 0; i < n; i++) {\r\n let left = reverse2(s.slice(0, i));\r\n let right = s.slice(i + 1);\r\n if (left == right) return pr('YES');\r\n }\r\n pr('NO');\r\n};\r\n\r\nconst reverse2 = (s) => {\r\n let res = \"\";\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n res += s[i];\r\n }\r\n return res;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (n, k, s) => {\r\n if (k == 0) return pr('YES');\r\n for (let i = 0; i < n; i++) {\r\n let left = s.slice(0, i);\r\n let right = reverse2(s.slice(i + 1));\r\n if (left == right) return pr('YES');\r\n }\r\n pr('NO');\r\n};\r\n\r\nconst reverse2 = (s) => {\r\n let res = \"\";\r\n for (let i = s.length - 1; i >= 0; i--) {\r\n res += s[i];\r\n }\r\n return res;\r\n};\r\n\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\nvar mod = 1000000000n + 7n\r\nvar maxN = 1002\r\n\r\nfunction main() {\r\n const x = readline();\r\n\r\n Array(parseInt(x)).fill(1).map((t, iii) => {\r\n var [n, k] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n\r\n if (k === 0) return console.log('YES')\r\n if (n % 2 === 0 && n === k * 2) return console.log('NO')\r\n\r\n var isTrue = true\r\n // console.log(n, k)\r\n for (let i = 0; i < k+1; i++) {\r\n// console.log(a[i], a[n-i-1], n-k+i-1)\r\n if(a[i] !== a[n-i-1]) isTrue = false\r\n }\r\n// console.log(isTrue)\r\nconsole.log(isTrue ? 'YES':'NO')\r\n\r\n })\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n\r\n return gcd(b, a % b);\r\n}\r\n\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar K = nextInt();\r\n\t\tvar s = next();\r\n\t\tif(K == 0){\r\n\t\t\tmyout(\"YES\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar count = 0;\r\n\t\tfor(var j = 0; j < K; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tcount++;\r\n\t\t\t}else{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(count >= K){\r\n\t\t\tif(count == K && N % 2 == 0){\r\n\t\t\t\tmyout(\"NO\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"YES\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "6fbf41dc32d1c28351d78a9ec5fc0026"} {"source_code": "\nprint(function(n, x) {\n\n\tvar i, c = 0,\n\t\tret = [],\n\t\ta = new Int8Array(1e6);\n\n\tfor (i = 0; i < n; i++)\n\t\ta[x[i] - 1] = 1;\n\n\tfor (i = 0; i < 1e6; i++)\n\t\tif (a[i] === 1) {\n\t\t\tif (a[999999 - i] === 1) {\n\t\t\t\tc++;\n\t\t\t} else {\n\t\t\t\tret.push(1e6 - i);\n\t\t\t}\n\t\t}\n\n\tc = c / 2;\n\tfor (i = 0; i < 1e6 && c > 0; i++)\n\t\tif (a[i] === 0 && a[999999 - i] === 0) {\n\t\t\tc--;\n\t\t\tret.push(i + 1);\n\t\t\tret.push(1e6 - i);\n\t\t}\n\n\treturn ret.length + '\\n' + ret.join(' ');\n\n}(+readline(), readline().split(' ').map(Number)));", "positive_code": [{"source_code": "\nprint(function(n, x) {\n\n\tvar i, c = 0,\n\t\tret = [],\n\t\ta = new Int8Array(1e6);\n\n\tfor (i = 0; i < n; i++)\n\t\ta[x[i] - 1] = 1;\n\n\tfor (i = 0; i < 1e6; i++)\n\t\tif (a[i] === 1) {\n\t\t\tif (a[999999 - i] === 1) {\n\t\t\t\tc++;\n\t\t\t} else {\n\t\t\t\tret.push(1e6 - i);\n\t\t\t}\n\t\t}\n\n\tc = c / 2;\n\tfor (i = 0; i < 1e6 && c > 0; i++)\n\t\tif (a[i] === 0 && a[999999 - i] === 0) {\n\t\t\tc--;\n\t\t\tret.push(i + 1);\n\t\t\tret.push(1e6 - i);\n\t\t}\n\n\treturn ret.length + '\\n' + ret.sort(function(a, b) {\n\t\treturn a - b;\n\t}).join(' ');\n\n}(+readline(), readline().split(' ').map(Number)));"}], "negative_code": [], "src_uid": "4143caa25fcc2f4d400d169f9697be01"} {"source_code": "const n = Number(readline());\nvar sum = 0;\nfor (var i = 0; i < n; i++)\n sum += Number(readline().split(\" \")[1]);\nprint(sum / n + 5);\n", "positive_code": [{"source_code": "function main()\n{\n\tvar n = parseInt(readline()), i;\n\tvar totY = 0, params;\n\tfor(i = 1; i <= n; ++i)\n\t{\n\t\tparams = readline().split(' ').map(function(x){return parseFloat(x);});\n\t\ttotY += params[1];\n\t}\n\twrite((totY / n + 5).toFixed(3));\n}\nmain();\n"}], "negative_code": [], "src_uid": "4f4f25855794092ae4c8d9c8102ed4de"} {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tlet [a, b] = rna();\r\n\t\tlet s = rl().split('');\r\n\r\n\t\tconst n = s.length;\r\n\t\tif (a + b != n ) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < Math.floor(n/2); i++) {\r\n\t\t\tif (s[i] == '?')\r\n\t\t\t\ts[i] = s[n-i-1];\r\n\t\t\tif (s[n-i-1] == '?')\r\n\t\t\t\ts[n-i-1] = s[i];\r\n\t\t\tif (s[i] != s[n-i-1])\r\n\t\t\t\tok = false;\r\n\t\t}\r\n\t\tif (!ok) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tfor (const c of s) {\r\n\t\t\ta -= c == '0';\r\n\t\t\tb -= c == '1';\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < Math.floor(n/2); i++) {\r\n\t\t\tif (s[i] == '?') {\r\n\t\t\t\tif (a > 1) {\r\n\t\t\t\t\ts[i] = s[n-i-1] = '0';\r\n\t\t\t\t\ta -= 2;\r\n\t\t\t\t} else {\r\n\t\t\t\t\ts[i] = s[n-i-1] = '1';\r\n\t\t\t\t\tb -= 2;\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (n % 2 && s[(n-1)/2] == '?') {\r\n\t\t\tif (a > 0){\r\n\t\t\t\ts[(n-1)/2] = '0';\r\n\t\t\t\ta--;\r\n\t\t\t} else {\r\n\t\t\t\ts[(n-1)/2] = '1';\r\n\t\t\t\tb--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (a < 0 || b < 0) ans = false;\r\n\t\telse ans = s;\r\n\r\n\t\tconsole.log(ans ? ans.join('') : -1);\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a , b] = input[z++].split(' ');\r\n let str = input[z++].split('');\r\n let n = +a + +b;\r\n if(n % 2 === 0){\r\n if((a % 2 == 1) || (b % 2 == 1)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n if(n % 2 === 1){\r\n if( (str[(n-1)/2]) == 0 && (a % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n if( (str[(n-1)/2]) == 1 && (b % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n let flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n - i - 1] != \"?\"){\r\n if(str[i] != str[n - i - 1]){\r\n console.log(-1);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n if(flag) continue\r\n let c = 0;\r\n let d = 0;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == \"?\" && str[n-i-1] != \"?\"){\r\n str[i] = str[n-i-1];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n-i-1] == \"?\"){\r\n str[n-i-1] = str[i];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == '0') c++;\r\n if(str[i] == '1') d++;\r\n }\r\n if(c > a || d > b){\r\n console.log(-1);\r\n continue;\r\n }\r\n let x = a - c;\r\n let y = b - d;\r\n let p, q;\r\n p = Math.floor(x / 2);\r\n q = Math.floor(y / 2);\r\n for (let i = 0; i < n; i++)\r\n {\r\n if (str[i] == '?' && p > 0)\r\n {\r\n str[i] = '0';\r\n str[n - i - 1] = '0';\r\n p--;\r\n }\r\n if (str[i] == '?' && q > 0)\r\n {\r\n str[i] = '1';\r\n str[n - i - 1] = '1';\r\n q--;\r\n }\r\n if (str[i] == '?')\r\n {\r\n if (a % 2 == 1)\r\n {\r\n str[i] = '0';\r\n }\r\n else\r\n {\r\n str[i] = '1';\r\n }\r\n }\r\n }\r\n console.log(str.join(''));\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [a, b] = iInpArr();\r\n let str = stringArr();\r\n let to = a + b,\r\n i = 0,\r\n j = str.length - 1,\r\n flag = false;\r\n while (i <= j) {\r\n if (i === j) {\r\n if (str[i] === \"0\") a--;\r\n else if (str[j] === \"1\") b--;\r\n } else if (str[i] === str[j]) {\r\n if (str[i] === \"1\") b -= 2;\r\n else if (str[i] === \"0\") a -= 2;\r\n } else {\r\n if (str[i] !== \"?\" && str[j] !== \"?\") {\r\n flag = true;\r\n break;\r\n } else if (str[i] !== \"?\") {\r\n if (str[i] === \"0\") {\r\n a -= 2;\r\n str[j] = \"0\";\r\n } else {\r\n b -= 2;\r\n str[j] = \"1\";\r\n }\r\n } else {\r\n if (str[j] === \"0\") {\r\n a -= 2;\r\n str[i] = \"0\";\r\n } else {\r\n b -= 2;\r\n str[i] = \"1\";\r\n }\r\n }\r\n }\r\n i++;\r\n j--;\r\n }\r\n if (a < 0 || b < 0 || flag) {\r\n console.log(-1);\r\n continue;\r\n }\r\n if (a === 0 && b === 0) {\r\n console.log(str.join(\"\"));\r\n continue;\r\n }\r\n (i = 0), (j = str.length - 1), (flag = true);\r\n // console.log(a, b);\r\n while (i <= j) {\r\n if (i === j) {\r\n if (str[i] === \"?\") {\r\n if (a > 0) str[i] = \"0\";\r\n else if (b > 0) str[i] = \"1\";\r\n else flag = false;\r\n }\r\n } else if (str[i] === str[j]) {\r\n if (str[i] === \"?\") {\r\n if (b >= 2) {\r\n str[i] = str[j] = \"1\";\r\n b -= 2;\r\n } else if (a >= 2) {\r\n str[i] = str[j] = \"0\";\r\n a -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(`${flag === true ? str.join(\"\") : -1}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b, s) => {\r\n let cnt = [a, b];\r\n let n = s.length;\r\n let A = s.split(\"\");\r\n let found = false;\r\n for (let i = 0; i < n >> 1; i++) {\r\n let j = n - 1 - i;\r\n if (A[i] != '?' && A[j] != '?' && A[i] != A[j]) {\r\n found = true;\r\n break;\r\n }\r\n if (A[i] != '?' && A[j] == '?') A[j] = A[i];\r\n if (A[i] == '?' && A[j] != '?') A[i] = A[j];\r\n }\r\n if (found) return pr(-1);\r\n for (let i = 0; i < n; ++i) {\r\n let k = A[i] - '0';\r\n cnt[k]--;\r\n }\r\n for (let i = 0; i < n >> 1; i++) {\r\n if (A[i] != '?') continue;\r\n for (let k = 0; k < 2; k++) {\r\n if (cnt[k] >= 2) {\r\n cnt[k] -= 2;\r\n A[i] = A[n - 1 - i] = k;\r\n break;\r\n }\r\n }\r\n }\r\n if (n % 2 && A[n >> 1] == '?') {\r\n for (let k = 0; k < 2; k++) {\r\n if (cnt[k] >= 1) {\r\n cnt[k]--;\r\n A[n >> 1] = k;\r\n }\r\n }\r\n }\r\n if (cnt[0] == 0 && cnt[1] == 0) {\r\n pr(A.join(\"\"));\r\n } else {\r\n pr(-1);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 21\r\nvar mod = 1000000007\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n // const n = parseInt(readline());\r\n var [x, y] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n });\r\n var a = readline().split('').map((x, iii) => {\r\n return x\r\n })\r\n var n = a.length\r\n for (let j = 0; j < Math.floor(n / 2); j++) {\r\n if (a[j] === '0' && a[n - j - 1] === '1') return console.log(-1)\r\n if (a[j] === '1' && a[n - j - 1] === '0') return console.log(-1)\r\n\r\n if (a[j] === '0' && a[n - j - 1] === '?') {\r\n a[n - j - 1] = '0'\r\n x -= 2\r\n } else if (a[j] === '?' && a[n - j - 1] === '0') {\r\n a[j] = '0'\r\n x -= 2\r\n } else if (a[j] === '1' && a[n - j - 1] === '?') {\r\n a[n - j - 1] = '1'\r\n y -= 2\r\n } else if (a[j] === '?' && a[n - j - 1] === '1') {\r\n a[j] = '1'\r\n y -= 2\r\n } else if (a[j] === '1' && a[n - j - 1] === '1') {\r\n y -= 2\r\n } else if (a[j] === '0' && a[n - j - 1] === '0') {\r\n x -= 2\r\n }\r\n }\r\n var count = 0\r\n for (let j = 0; j < n; j++) {\r\n if (a[j] === '?') count++\r\n }\r\n\r\n for (let j = 0; j < Math.floor(n / 2); j++) {\r\n if (a[j] === '?' && x > 1) {\r\n a[j] = '0'\r\n a[n - j - 1] = '0'\r\n x -= 2\r\n continue\r\n }\r\n\r\n if (a[j] === '?' && y > 1) {\r\n a[j] = '1'\r\n a[n - j - 1] = '1'\r\n y -= 2\r\n continue\r\n }\r\n if (a[j] === '?') return console.log(-1)\r\n }\r\n if (n % 2 === 1 && a[Math.floor(n / 2)] === '0') {\r\n x--\r\n }\r\n if (n % 2 === 1 && a[Math.floor(n / 2)] === '1') {\r\n y--\r\n }\r\n\r\n if (n % 2 === 1 && a[Math.floor(n / 2)] === '?' && x > 0) {\r\n a[Math.floor(n / 2)] = '0'\r\n x--\r\n }\r\n if (n % 2 === 1 && a[Math.floor(n / 2)] === '?' && y > 0) {\r\n a[Math.floor(n / 2)] = '1'\r\n y--\r\n }\r\n if (x !== 0 || y !== 0) return console.log(-1)\r\n console.log(a.join(''))\r\n })\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split(' ');\r\n var a = parseInt(inp[0]);\r\n var b = parseInt(inp[1]);\r\n var str = readline().split('');\r\n var n = str.length;\r\n\r\n var isNotPalindrome = false;\r\n\r\n for (var i = 0, j = n - 1; i <= n / 2 - 1; i++, j--) {\r\n if ((str[i] === '0' && str[j] === '1') || (str[i] === '1' && str[j] === '0')) {\r\n isNotPalindrome = true;\r\n continue;\r\n }\r\n\r\n if (str[i] === '?' && str[j] === '0') {\r\n str[i] = '0';\r\n } else if (str[i] === '?' && str[j] === '1') {\r\n str[i] = '1';\r\n } else if (str[i] === '0' && str[j] === '?') {\r\n str[j] = '0';\r\n } else if (str[i] === '1' && str[j] === '?') {\r\n str[j] = '1';\r\n } \r\n\r\n if (str[i] === '0' && str[j] === '0') {\r\n a -= 2;\r\n } else if (str[i] === '1' && str[j] === '1') {\r\n b -= 2;\r\n }\r\n }\r\n\r\n for (var i = 0, j = n - 1; i <= n / 2 - 1; i++, j--) {\r\n if (str[i] === '?' && str[j] === '?') {\r\n if (a >= 2) {\r\n str[i] = '0';\r\n str[j] = '0';\r\n a -= 2;\r\n } else {\r\n str[i] = '1';\r\n str[j] = '1';\r\n b -= 2;\r\n }\r\n }\r\n }\r\n\r\n if (str.length % 2 === 1) {\r\n var mid = Math.floor(str.length / 2);\r\n if (str[mid] === '0') {\r\n a--;\r\n } else if (str[mid] === '1') {\r\n b--;\r\n } else {\r\n if (a >= 1) {\r\n str[mid] = '0';\r\n a--;\r\n } else {\r\n str[mid] = '1';\r\n b--;\r\n }\r\n }\r\n }\r\n\r\n if (a !== 0 || b !== 0 || isNotPalindrome) {\r\n print('-1');\r\n continue;\r\n }\r\n\r\n print(str.join(''));\r\n}\r\n"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfor (var test = 0; test < t; test++) {\r\n var inp = readline().split(' ');\r\n var a = parseInt(inp[0]);\r\n var b = parseInt(inp[1]);\r\n var str = readline().split('');\r\n var n = str.length;\r\n\r\n var isNotPalindrome = false;\r\n\r\n for (var i = 0, j = n - 1; i <= n / 2 - 1; i++, j--) {\r\n if ((str[i] === '0' && str[j] === '1') || (str[i] === '1' && str[j] === '0')) {\r\n isNotPalindrome = true;\r\n continue;\r\n }\r\n\r\n if (str[i] === '?' && str[j] === '0') {\r\n str[i] = '0';\r\n a -= 2;\r\n } else if (str[i] === '?' && str[j] === '1') {\r\n str[i] = '1';\r\n b -= 2;\r\n } else if (str[i] === '0' && str[j] === '?') {\r\n str[j] = '0';\r\n a -= 2;\r\n } else if (str[i] === '1' && str[j] === '?') {\r\n str[j] = '1';\r\n b -= 2;\r\n } else if (str[i] === '0' && str[j] === '0') {\r\n a -= 2;\r\n } else if (str[i] === '1' && str[j] === '1') {\r\n b -= 2;\r\n }\r\n }\r\n\r\n for (var i = 0, j = n - 1; i <= n / 2 - 1; i++, j--) {\r\n if (str[i] === '?' && str[j] === '?') {\r\n if (a >= 2) {\r\n str[i] = '0';\r\n str[j] = '0';\r\n a -= 2;\r\n } else {\r\n str[i] = '1';\r\n str[j] = '1';\r\n b -= 2;\r\n }\r\n }\r\n }\r\n\r\n if (str.length % 2 === 1) {\r\n var mid = Math.floor(str.length / 2);\r\n if (str[mid] === '0') {\r\n a--;\r\n } else if (str[mid] === '1') {\r\n b--;\r\n } else {\r\n if (a >= 1) {\r\n str[mid] = '0';\r\n a--;\r\n } else {\r\n str[mid] = '1';\r\n b--;\r\n }\r\n }\r\n }\r\n\r\n if (a !== 0 || b !== 0 || isNotPalindrome) {\r\n print('-1');\r\n continue;\r\n }\r\n\r\n print(str.join(''));\r\n}\r\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", () => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Write your logic in `main`\n\nconst reverse = (palindrome) => palindrome.split(\"\").reverse().join(\"\");\n\nconst makePalindrome = (palindrome, counts) => {\n let newPalindrome = \"\";\n for (let i = 0; i < Math.ceil(palindrome.length / 2); i++) {\n let left = palindrome[i];\n let right = palindrome[palindrome.length - 1 - i];\n\n if (left !== right && left !== \"?\" && right !== \"?\") {\n // console.log(\"error: no match\");\n return -1;\n }\n\n let character = left;\n\n if (left === \"?\") {\n left = right;\n character = right;\n }\n\n if (right === \"?\") {\n right = left;\n character = left;\n }\n\n newPalindrome += character;\n\n counts[left] -= 1;\n if (i !== palindrome.length - 1 - i) {\n counts[right] -= 1;\n }\n }\n\n if (counts[\"0\"] < 0 || counts[\"1\"] < 0) {\n return -1;\n }\n\n if (\n counts[\"?\"] % 2 === 0 &&\n (counts[\"0\"] % 2 !== 0 || counts[\"1\"] % 2 !== 0)\n ) {\n // console.log(\"error: not even\");\n return -1;\n }\n\n counts[\"?\"] += counts[\"1\"] + counts[\"0\"];\n\n if (counts[\"?\"] !== 0) {\n // console.log(\"error: not zero\");\n return -1;\n }\n\n // console.log(\"looks good\");\n\n // console.log(\"new\", newPalindrome, counts);\n newPalindrome = newPalindrome\n .split(\"\")\n .map((el) => {\n if (el === \"?\") {\n // console.log(\"map\", counts);\n if (counts[\"0\"] > 1) {\n counts[\"0\"] -= 2;\n return \"0\";\n } else if (counts[\"1\"] > 1) {\n counts[\"1\"] -= 2;\n return \"1\";\n }\n\n // for a single question mark in the case with odd palindrome length\n if (counts[\"0\"] > 0) {\n return \"0\";\n } else {\n return \"1\";\n }\n }\n return el;\n })\n .join(\"\");\n\n return (\n newPalindrome +\n reverse(newPalindrome.slice(0, Math.floor(palindrome.length / 2)))\n );\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const [zerosCount, onesCount] = readline()\n .split(\" \")\n .map((el) => +el);\n\n // console.log(zerosCount, onesCount);\n\n const palindrome = readline();\n\n // console.log(palindrome);\n\n const counts = {\n 0: zerosCount,\n 1: onesCount,\n \"?\": 0,\n };\n\n console.log(makePalindrome(palindrome, counts));\n });\n};\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Write your logic in `main`\n\nconst reverse = (palindrome) => palindrome.split(\"\").reverse().join(\"\");\n\nconst makePalindrome = (palindrome, counts) => {\n let newPalindrome = \"\";\n for (let i = 0; i < Math.ceil(palindrome.length / 2); i++) {\n let left = palindrome[i];\n let right = palindrome[palindrome.length - 1 - i];\n\n if (left !== right && left !== \"?\" && right !== \"?\") {\n // console.log(\"error: no match\");\n return -1;\n }\n\n let character = left;\n\n if (left === \"?\") {\n left = right;\n character = right;\n }\n\n if (right === \"?\") {\n right = left;\n character = left;\n }\n\n newPalindrome += character;\n\n counts[left] -= 1;\n if (i !== palindrome.length - 1 - i) {\n counts[right] -= 1;\n }\n }\n\n if (counts[\"0\"] < 0 || counts[\"1\"] < 0) {\n return -1;\n }\n\n if (counts[\"?\"] % 2 === 0) {\n if (counts[\"0\"] % 2 !== 0 || counts[\"1\"] % 2 !== 0) {\n // console.log(\"error: not even\");\n return -1;\n }\n }\n\n counts[\"?\"] += counts[\"1\"] + counts[\"0\"];\n\n if (counts[\"?\"] !== 0) {\n // console.log(\"error: not zero\");\n return -1;\n }\n\n // console.log(\"looks good\");\n\n // console.log(\"new\", newPalindrome, counts);\n newPalindrome = newPalindrome\n .split(\"\")\n .map((el) => {\n if (el === \"?\") {\n // console.log(\"map\", counts);\n if (counts[\"0\"] > 1) {\n counts[\"0\"] -= 2;\n return \"0\";\n } else if (counts[\"1\"] > 1) {\n counts[\"1\"] -= 2;\n return \"1\";\n }\n\n // for a single question mark in the case with odd palindrome length\n if (counts[\"0\"] > 0) {\n return \"0\";\n } else {\n return \"1\";\n }\n }\n return el;\n })\n .join(\"\");\n\n return (\n newPalindrome +\n reverse(newPalindrome.slice(0, Math.floor(palindrome.length / 2)))\n );\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const [zerosCount, onesCount] = readline()\n .split(\" \")\n .map((el) => +el);\n\n // console.log(zerosCount, onesCount);\n\n const palindrome = readline();\n\n // console.log(palindrome);\n\n const counts = {\n 0: zerosCount,\n 1: onesCount,\n \"?\": 0,\n };\n\n console.log(makePalindrome(palindrome, counts));\n });\n};\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Write your logic in `main`\n\nconst reverse = (palindrome) => palindrome.split(\"\").reverse().join(\"\");\n\nconst isPalindrome = (palindrome, counts) => {\n let newPalindrome = \"\";\n for (let i = 0; i < Math.ceil(palindrome.length / 2); i++) {\n let left = palindrome[i];\n let right = palindrome[palindrome.length - 1 - i];\n\n if (left !== right && left !== \"?\" && right !== \"?\") {\n // console.log(\"error: no match\");\n return -1;\n }\n\n let character = left;\n\n if (left === \"?\") {\n left = right;\n character = right;\n }\n\n if (right === \"?\") {\n right = left;\n character = left;\n }\n\n newPalindrome += character;\n\n counts[left] -= 1;\n if (i !== palindrome.length - 1 - i) {\n counts[right] -= 1;\n }\n }\n\n if (counts[\"0\"] < 0 || counts[\"1\"] < 0) {\n return -1;\n }\n\n if (counts[\"?\"] % 2 === 0) {\n if (counts[\"0\"] % 2 !== 0 || counts[\"1\"] % 2 !== 0) {\n // console.log(\"error: not even\");\n return -1;\n }\n }\n\n counts[\"?\"] += counts[\"1\"] + counts[\"0\"];\n\n if (counts[\"?\"] !== 0) {\n // console.log(\"error: not zero\");\n return -1;\n }\n\n // console.log(\"looks good\");\n\n // console.log(\"new\", newPalindrome, counts);\n newPalindrome = newPalindrome\n .split(\"\")\n .map((el) => {\n if (el === \"?\") {\n // console.log(\"map\", counts);\n if (counts[\"0\"] > 1) {\n counts[\"0\"] -= 2;\n return \"0\";\n } else if (counts[\"1\"] > 1) {\n counts[\"1\"] -= 2;\n return \"1\";\n }\n\n if (counts[\"0\"] > 0) {\n return \"0\";\n } else {\n return \"1\";\n }\n }\n return el;\n })\n .join(\"\");\n\n return (\n newPalindrome +\n reverse(newPalindrome.slice(0, Math.floor(palindrome.length / 2)))\n );\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const [zerosCount, onesCount] = readline()\n .split(\" \")\n .map((el) => +el);\n\n // console.log(zerosCount, onesCount);\n\n let palindrome = readline();\n\n // console.log(palindrome);\n\n const counts = {\n 0: zerosCount,\n 1: onesCount,\n \"?\": 0,\n };\n\n console.log(isPalindrome(palindrome, counts));\n });\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[j] == \"1\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"?\"){\r\n\t\t\t\t\tif(s[N - 1 - j] == \"1\"){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[N - 1 - j] == \"?\"){\r\n\t\t\t\t\tif(s[j] == \"1\"){\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(A > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else if(A > 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(B > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else if(B > 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] != s[N - 1 - j] || s[j] == \"?\" || s[N - 1 - j] == \"?\"){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(A < 0 || B < 0){\r\n\t\t\tisOK = false;\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(myconv(s, 0));\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a , b] = input[z++].split(' ');\r\n let str = input[z++].split('');\r\n let n = +a + +b;\r\n if(n % 2 === 0){\r\n if((a % 2 == 1) || (b % 2 == 1)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n if(n % 2 === 1){\r\n if( (str[(n-1)/2]) == 0 && (a % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n if( (str[(n-1)/2]) == 1 && (b % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n let flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n - i - 1] != \"?\"){\r\n if(str[i] != str[n - i - 1]){\r\n console.log(-1);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n if(flag) continue\r\n let c = 0;\r\n let d = 0;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == \"?\" && str[n-i-1] != \"?\"){\r\n str[i] = str[n-i-1];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n-i-1] == \"?\"){\r\n str[n-i-1] = str[i];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == '0') c++;\r\n if(str[i] == '1') d++;\r\n }\r\n if(c > a || d > b){\r\n console.log(-1);\r\n continue;\r\n }\r\n let x = a - c;\r\n let y = b - d;\r\n for (let i = 0; i < n; i++)\r\n {\r\n if (str[i] == '?' && Math.floor(x/2)> 0)\r\n {\r\n str[i] = '0';\r\n str[n - i - 1] = '0';\r\n x-=2;\r\n }\r\n if (str[i] == '?' && Math.floor(y/2)> 0)\r\n {\r\n str[i] = '1';\r\n str[n - i - 1] = '1';\r\n y-=2;\r\n }\r\n if (str[i] == '?')\r\n {\r\n if (a % 2 == 1)\r\n {\r\n str[i] = '0';\r\n }\r\n else\r\n {\r\n str[i] = '1';\r\n }\r\n }\r\n }\r\n console.log(str.join(''));\r\n }\r\n}"}], "negative_code": [{"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Write your logic in `main`\n\nconst reverse = (palindrome) => palindrome.split(\"\").reverse().join(\"\");\n\nconst isPalindrome = (palindrome, counts) => {\n let newPalindrome = \"\";\n for (let i = 0; i < Math.ceil(palindrome.length / 2); i++) {\n let left = palindrome[i];\n let right = palindrome[palindrome.length - 1 - i];\n\n if (left !== right && left !== \"?\" && right !== \"?\") {\n // console.log(\"error: no match\");\n return -1;\n }\n\n let character = left;\n\n if (left === \"?\") {\n left = right;\n character = right;\n }\n\n if (right === \"?\") {\n right = left;\n character = left;\n }\n\n newPalindrome += character;\n\n counts[left] -= 1;\n if (i !== palindrome.length - 1 - i) {\n counts[right] -= 1;\n }\n }\n\n if (counts[\"0\"] < 0 || counts[\"1\"] < 0) {\n return -1;\n }\n\n if (counts[\"?\"] % 2 === 0) {\n if (counts[\"0\"] % 2 !== 0 || counts[\"1\"] % 2 !== 0) {\n // console.log(\"error: not even\");\n return -1;\n }\n }\n\n counts[\"?\"] += counts[\"1\"] + counts[\"0\"];\n\n if (counts[\"?\"] !== 0) {\n // console.log(\"error: not zero\");\n return -1;\n }\n\n // console.log(\"looks good\");\n\n // console.log(\"new\", newPalindrome, counts);\n newPalindrome = newPalindrome\n .split(\"\")\n .map((el) => {\n if (el === \"?\") {\n // console.log(\"map\", counts);\n if (counts[\"0\"] > 0) {\n counts[\"0\"] -= 2;\n return \"0\";\n } else {\n return \"1\";\n }\n }\n return el;\n })\n .join(\"\");\n return (\n newPalindrome +\n reverse(newPalindrome.slice(0, Math.floor(palindrome.length / 2)))\n );\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const [zerosCount, onesCount] = readline()\n .split(\" \")\n .map((el) => +el);\n\n // console.log(zerosCount, onesCount);\n\n let palindrome = readline();\n\n // console.log(palindrome);\n\n const counts = {\n 0: zerosCount,\n 1: onesCount,\n \"?\": 0,\n };\n\n console.log(isPalindrome(palindrome, counts));\n });\n};\n"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n// Write your logic in `main`\n\nconst reverse = (palindrome) => palindrome.split(\"\").reverse().join(\"\");\n\nconst isPalindrome = (palindrome, counts) => {\n let newPalindrome = \"\";\n for (let i = 0; i < Math.ceil(palindrome.length / 2); i++) {\n let left = palindrome[i];\n let right = palindrome[palindrome.length - 1 - i];\n\n if (left !== right && left !== \"?\" && right !== \"?\") {\n // console.log(\"error: no match\");\n return -1;\n }\n\n let character = left;\n\n if (left === \"?\") {\n left = right;\n character = right;\n }\n\n if (right === \"?\") {\n right = left;\n character = left;\n }\n\n newPalindrome += character;\n\n counts[left] -= 1;\n if (i !== palindrome.length - 1 - i) {\n counts[right] -= 1;\n }\n }\n\n if (counts[\"?\"] % 2 === 0) {\n if (counts[\"0\"] % 2 !== 0 || counts[\"1\"] % 2 !== 0) {\n // console.log(\"error: not even\");\n return -1;\n }\n }\n\n counts[\"?\"] += counts[\"1\"] + counts[\"0\"];\n\n if (counts[\"?\"] !== 0) {\n // console.log(\"error: not zero\");\n return -1;\n }\n\n // console.log(\"looks good\");\n\n // console.log(\"new\", newPalindrome, counts);\n newPalindrome = newPalindrome\n .split(\"\")\n .map((el) => {\n if (el === \"?\") {\n // console.log(\"map\", counts);\n if (counts[\"0\"] > 0) {\n counts[\"0\"] -= 2;\n return \"0\";\n } else {\n return \"1\";\n }\n }\n return el;\n })\n .join(\"\");\n return (\n newPalindrome +\n reverse(newPalindrome.slice(0, Math.floor(palindrome.length / 2)))\n );\n};\n\nconst main = () => {\n const numberOfTestCases = 1 * readline();\n // console.log(\"number of test cases\", numberOfTestCases);\n\n Array.from({ length: numberOfTestCases }).forEach(() => {\n const [zerosCount, onesCount] = readline()\n .split(\" \")\n .map((el) => +el);\n\n // console.log(zerosCount, onesCount);\n\n let palindrome = readline();\n\n // console.log(palindrome);\n\n const counts = {\n 0: zerosCount,\n 1: onesCount,\n \"?\": 0,\n };\n\n console.log(isPalindrome(palindrome, counts));\n });\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[j] == \"1\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"?\"){\r\n\t\t\t\t\tif(s[N - 1 - j] == \"1\"){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[N - 1 - j] == \"?\"){\r\n\t\t\t\t\tif(s[j] == \"1\"){\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(A > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else if(A > 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(B > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else if(B > 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] != s[N - 1 - j] || s[j] == \"?\" || s[N - 1 - j] == \"?\"){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(A % 2 == 1 || B % 2 == 1 || A < 0 || B < 0){\r\n\t\t\tisOK = false;\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(myconv(s, 0));\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[j] == \"1\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"?\"){\r\n\t\t\t\t\tif(s[N - 1 - j] == \"1\"){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[N - 1 - j] == \"?\"){\r\n\t\t\t\t\tif(s[j] == \"1\"){\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(A > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else if(A > 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(B > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else if(B > 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] != s[N - 1 - j] || s[j] == \"?\"){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(A % 2 == 1 || B % 2 == 1 || A < 0 || B < 0){\r\n\t\t\tisOK = false;\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(myconv(s, 0));\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[j] == \"1\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"?\"){\r\n\t\t\t\t\tif(s[N - 1 - j] == \"1\"){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[N - 1 - j] == \"?\"){\r\n\t\t\t\t\tif(s[j] == \"1\"){\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(A > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else if(A > 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(B > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else if(B > 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] != s[N - 1 - j]){\r\n\t\t\t\tisOK = false;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(A % 2 == 1 || B % 2 == 1 || A < 0 || B < 0){\r\n\t\t\tisOK = false;\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(myconv(s, 0));\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar A = nextInt();\r\n\t\tvar B = nextInt();\r\n\t\tvar s = nextCharArray();\r\n\t\tvar N = s.length;\r\n\t\tvar isOK = true;\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == s[N - 1 - j]){\r\n\t\t\t\tif(s[j] == \"0\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[j] == \"1\"){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\tif(s[j] == \"?\"){\r\n\t\t\t\t\tif(s[N - 1 - j] == \"1\"){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(s[N - 1 - j] == \"?\"){\r\n\t\t\t\t\tif(s[j] == \"1\"){\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var j = 0; j < N / 2; j++){\r\n\t\t\tif(s[j] == \"?\" && s[N - 1 - j] == \"?\"){\r\n\t\t\t\tif(A > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\tA--;\r\n\t\t\t\t\t}else if(A > 1){\r\n\t\t\t\t\t\ts[j] = \"0\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"0\";\r\n\t\t\t\t\t\tA -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else if(B > 0){\r\n\t\t\t\t\tif(j == Math.ceil(N / 2) - 1 && N % 2 == 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\tB--;\r\n\t\t\t\t\t}else if(B > 1){\r\n\t\t\t\t\t\ts[j] = \"1\";\r\n\t\t\t\t\t\ts[N - 1 - j] = \"1\";\r\n\t\t\t\t\t\tB -= 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}else{\r\n\t\t\t\t\tisOK = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(A % 2 == 1 || B % 2 == 1){\r\n\t\t\tisOK = false;\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(myconv(s, 0));\r\n\t\t}else{\r\n\t\t\tmyout(-1);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a , b] = input[z++].split(' ');\r\n let str = input[z++].split('');\r\n let n = +a + +b;\r\n if(n % 2 === 0){\r\n if((a % 2 == 1) || (b % 2 == 1)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n if(n % 2 === 1){\r\n if( (str[(n-1)/2]) == 0 && (a % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n if( (str[(n-1)/2]) == 1 && (b % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n let flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n - i - 1] != \"?\"){\r\n if(str[i] != str[n - i - 1]){\r\n console.log(-1);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n if(flag) continue\r\n let c = 0;\r\n let d = 0;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == \"?\" && str[n-i-1] != \"?\"){\r\n str[i] = str[n-i-1];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n-i-1] == \"?\"){\r\n str[n-i-1] = str[i];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == '0') c++;\r\n if(str[i] == '1') d++;\r\n }\r\n if(c > a || d > b){\r\n console.log(-1);\r\n continue;\r\n }\r\n let x = a - c;\r\n let y = b - d;\r\n for (let i = 0; i < n; i++)\r\n {\r\n if (str[i] == '?' && x > 0)\r\n {\r\n str[i] = '0';\r\n str[n - i - 1] = '0';\r\n x-=2;\r\n }\r\n if (str[i] == '?' && y > 0)\r\n {\r\n str[i] = '1';\r\n str[n - i - 1] = '1';\r\n y-=2;\r\n }\r\n if (str[i] == '?')\r\n {\r\n if (a % 2 == 1)\r\n {\r\n str[i] = '0';\r\n }\r\n else\r\n {\r\n str[i] = '1';\r\n }\r\n }\r\n }\r\n console.log(str.join(''));\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\n\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nvar input = '';\r\n\r\nprocess.stdin.on('data' , data=>{\r\n input += data;\r\n});\r\nprocess.stdin.on('end' , ()=>{\r\n main(input);\r\n});\r\n\r\nfunction main(input) {\r\n input = input.split(\"\\n\");\r\n let z = 0;\r\n let testCases = +input[z++];\r\n\r\n while(testCases--){\r\n let [a , b] = input[z++].split(' ').map(Number);\r\n let str = input[z++].split('');\r\n let n = a + b;\r\n if(n % 2 === 0){\r\n if((a % 2 == 1) || (b % 2 == 1)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n if(n % 2 === 1){\r\n if( (str[(n-1)/2]) == 0 && (a % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n if( (str[(n-1)/2]) == 1 && (b % 2 == 0)){\r\n console.log(-1);\r\n continue;\r\n }\r\n }\r\n let flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] != \"?\" && str[n - i - 1] != \"?\"){\r\n if(str[i] != str[n - i - 1]){\r\n console.log(-1);\r\n flag = true;\r\n break;\r\n }\r\n }\r\n }\r\n if(flag) continue\r\n let c = 0;\r\n let d = 0;\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == \"?\" && str[n-i-1] != \"?\"){\r\n str[i] = str[n-i-1];\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n if(str[i] == '0') c++;\r\n if(str[i] == '1') d++;\r\n }\r\n if(c > a || d > b){\r\n console.log(-1);\r\n continue;\r\n }\r\n let x = a - c;\r\n let y = b - d;\r\n let p, q;\r\n p = x / 2;\r\n q = y / 2;\r\n for (let i = 0; i < n; i++)\r\n {\r\n if (str[i] == '?' && p > 0)\r\n {\r\n str[i] = '0';\r\n str[n - i - 1] = '0';\r\n p--;\r\n }\r\n if (str[i] == '?' && q > 0)\r\n {\r\n str[i] = '1';\r\n str[n - i - 1] = '1';\r\n q--;\r\n }\r\n if (str[i] == '?')\r\n {\r\n if (a % 2 == 1)\r\n {\r\n str[i] = '0';\r\n }\r\n else\r\n {\r\n str[i] = '1';\r\n }\r\n }\r\n }\r\n console.log(str.join(''));\r\n }\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [a, b] = iInpArr();\r\n let str = stringArr();\r\n let to = a + b,\r\n i = 0,\r\n j = str.length - 1,\r\n flag = true;\r\n while (i <= j) {\r\n if (i === j) {\r\n if (str[i] === \"0\") a--;\r\n else if (str[j] === \"1\") b--;\r\n } else if (str[i] === str[j]) {\r\n if (str[i] === \"1\") b -= 2;\r\n else if (str[i] === \"0\") a -= 2;\r\n }\r\n i++;\r\n j--;\r\n }\r\n if (a < 0 || b < 0) {\r\n console.log(-1);\r\n continue;\r\n }\r\n if (a === 0 && b === 0) {\r\n console.log(str.join(\"\"));\r\n continue;\r\n }\r\n (i = 0), (j = str.length - 1);\r\n while (i <= j) {\r\n if (i === j) {\r\n if (str[i] === \"?\") {\r\n if (a > 0) str[i] = \"0\";\r\n else if (b > 0) str[i] = \"1\";\r\n else flag = false;\r\n }\r\n } else if (str[i] === str[j]) {\r\n if (str[i] === \"?\") {\r\n if (b >= 2) {\r\n str[i] = str[j] = \"1\";\r\n b -= 2;\r\n } else if (a >= 2) {\r\n str[i] = str[j] = \"0\";\r\n a -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n } else {\r\n if (str[i] !== \"?\" && str[j] !== \"?\") {\r\n flag = false;\r\n break;\r\n } else {\r\n let k = str[i] !== \"?\" ? str[i] : str[j];\r\n if (k === \"1\") {\r\n if (b >= 2) {\r\n str[i] = str[j] = \"1\";\r\n b -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n } else {\r\n if (a >= 2) {\r\n str[i] = str[j] = \"0\";\r\n a -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(`${flag === true ? str.join(\"\") : -1}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nlet mod = BigInt(1e9 + 7);\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let [a, b] = iInpArr();\r\n let str = stringArr();\r\n let to = a + b,\r\n i = 0,\r\n j = str.length - 1,\r\n flag = true;\r\n while (i <= j) {\r\n if (i === j) {\r\n if (str[i] === \"1\") {\r\n if (b <= 0) flag = false;\r\n } else if (str[j] === \"0\") {\r\n if (a <= 0) flag = false;\r\n } else {\r\n if (a > 0) str[i] = \"0\";\r\n else if (b > 0) str[i] = \"1\";\r\n else flag = false;\r\n }\r\n } else if (str[i] === str[j]) {\r\n if (str[i] === \"?\") {\r\n if (b >= 2) {\r\n str[i] = str[j] = \"1\";\r\n b -= 2;\r\n } else if (a >= 2) {\r\n str[i] = str[j] = \"0\";\r\n a -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n } else {\r\n if (str[i] === \"0\" && a >= 2) a -= 2;\r\n else if (str[i] === \"1\" && b >= 2) b -= 2;\r\n else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n } else {\r\n if (str[i] !== \"?\" && str[j] !== \"?\") {\r\n flag = false;\r\n break;\r\n } else {\r\n let k = str[i] !== \"?\" ? str[i] : str[j];\r\n if (k === \"1\") {\r\n if (b >= 2) {\r\n str[i] = str[j] = \"1\";\r\n b -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n } else {\r\n if (a >= 2) {\r\n str[i] = str[j] = \"0\";\r\n a -= 2;\r\n } else {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n i++;\r\n j--;\r\n }\r\n console.log(`${flag === true ? str.join(\"\") : -1}`);\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet t = rn();\r\n\twhile (t--) {\r\n\t\tlet [a, b] = rna();\r\n\t\tlet s = rl();\r\n\r\n\t\tconst n = s.length;\r\n\t\tconst cnt = [a, b];\r\n\t\tlet ans = Array(n).fill('?');\r\n\r\n\t\tlet mp = new Map(\r\n\t\t\t\t[\r\n\t\t\t\t['??', '?'],\r\n\t\t\t\t['1?', '1'],\r\n\t\t\t\t['0?', '0'],\r\n\t\t\t\t['?0', '0'],\r\n\t\t\t\t['?1', '1'],\r\n\t\t\t\t['00', '0'],\r\n\t\t\t\t['11', '1'],\r\n\t\t\t\t['10', false],\r\n\t\t\t\t['01', false]\r\n\t\t\t\t]);\r\n\r\n\t\tlet ok = true;\r\n\t\tfor (let i = 0; ok && i < Math.ceil(n/2); i++) {\r\n\t\t\tlet x = mp.get(s[i] + s[n-i-1]);\r\n\t\t\tif (x == '?'){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\telse if (x === false) {\r\n\t\t\t\tok = false;;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tif (cnt[x] == 0) {\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}else {\r\n\t\t\t\t\tans[i] = ans[n-i-1] = x;\r\n\t\t\t\t\tcnt[x] -= i == n-i-1 ? 1 : 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!ok) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; ok && i < Math.ceil(n/2); i++) {\r\n\t\t\tif (ans[i] == '?') {\r\n\t\t\t\tconst need = i == n - i - 1 ? 1 : 2;\r\n\t\t\t\tif (cnt[0] >= need) {\r\n\t\t\t\t\tans[i] = ans[n - i - 1] = '0';\r\n\t\t\t\t\tcnt[0] -= need;\r\n\t\t\t\t}else if (cnt[1] >= need) {\r\n\t\t\t\t\tans[i] = ans[n - i - 1] = '1';\r\n\t\t\t\t\tcnt[1] -= need;\r\n\t\t\t\t}else {\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!ok) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tans = ans.join('');\r\n\t\tconsole.log(ans);\r\n\t}\r\n}\r\n"}, {"source_code": "///////////////////////////////// pre-define /////////////////////////////////////\r\nconst pr = console.log;\r\n///////////////////////////////////////////////////////////////////////////////////\r\n\r\nconst solve = (a, b, s) => {\r\n let n = s.length;\r\n let A = s.split(\"\");\r\n let cnt = cal(A);\r\n let zero = cnt[0];\r\n let one = cnt[1];\r\n let qus = cnt[2];\r\n if (zero + qus < a || one + qus < b) return pr(-1);\r\n if (qus == 0 && !ok(s)) return pr(-1);\r\n for (let i = 0; i < n; i++) {\r\n let j = n - i - 1;\r\n if (A[i] != '?') {\r\n if (A[i] == '0') {\r\n A[j] = '0';\r\n } else {\r\n A[j] = '1';\r\n }\r\n }\r\n }\r\n for (let i = 0; i < n; i++) {\r\n let j = n - i - 1;\r\n if (i > j) break;\r\n if (A[i] == '?') {\r\n let zd = a - zero;\r\n let od = b - one;\r\n if (zd >= od) {\r\n if (i == j) {\r\n A[i] = '0';\r\n zero++;\r\n continue;\r\n }\r\n A[i] = '0';\r\n A[j] = '0';\r\n zero += 2;\r\n } else {\r\n if (i == j) {\r\n A[i] = '1';\r\n one++;\r\n continue;\r\n }\r\n A[i] = '1';\r\n A[j] = '1';\r\n one += 2;\r\n }\r\n }\r\n }\r\n cnt = cal(A);\r\n zero = cnt[0];\r\n one = cnt[1];\r\n qus = cnt[2];\r\n if (zero != a || one != b) return pr(-1);\r\n pr(A.join(\"\"))\r\n};\r\n\r\nconst cal = (A) => {\r\n let zero = one = qus = 0;\r\n for (const c of A) {\r\n if (c == '0') {\r\n zero++;\r\n } else if (c == '1') {\r\n one++;\r\n } else {\r\n qus++;\r\n }\r\n }\r\n return [zero, one, qus];\r\n};\r\n\r\nconst ok = (s) => {\r\n let n = s.length;\r\n let i = 0;\r\n let j = n - 1;\r\n while (i < j) {\r\n if (s[i++] != s[j--]) return false;\r\n }\r\n return true;\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line);\r\n });\r\n rl.on('close', () => {\r\n let t = Number(input[0]);\r\n let i = 1;\r\n while (t--) {\r\n let tmp = input[i].split(\" \").map(Number);\r\n solve(tmp[0], tmp[1], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}], "src_uid": "001ac8bce4e44e9266a13eb27760906c"} {"source_code": "var input = readline();\nprint(main(input));\n\n// Need gcd.\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction modularPow(a, n, mod) {\n\tif (n === 1) return a % mod;\n\tvar pow = modularPow(a, Math.floor(n / 2), mod);\n\tif (n % 2 === 0) {\n\t\treturn (pow * pow) % mod;\n\t}\n\treturn (pow * pow * a) % mod;\n}\n\nfunction notPrime(p) {\n\t// exactly not prime\n\t// Fermat's little theorem\n\tif (p === 2) return false;\n\n\tvar a = 2; // choose small parameter.\n\tif (gcd(a, p) !== 1) return true; // not prime.\n\tvar expr = modularPow(a, p - 1, p);\n\treturn !(expr === 1); // Exact not prime.\n}\n\nfunction main(number) {\n\tvar div = 4;\n\twhile (div < number) {\n\t\tif (notPrime(number - div) && notPrime(div)) {\n\t\t\treturn (number - div) + ' ' + div;\n\t\t}\n\t\tdiv++;\n\t}\n}\n", "positive_code": [{"source_code": "function factorization(a){\n\tvar da = [1];\n\tfor(i = 2; i < a; i++){\n\t\tif( a%i == 0 ){\n\t\t\tda.push(i);\n\t\t\ta = a/i;\n\t\t\ti = 1;\n\t\t}\n\t}\n\tda.push(a);\n\treturn da;\n}\n\nvar n = +readline();\n\nfor(var j = 4; ; j++){\n\tif( factorization(j).length == 2 ){\n\t\tcontinue;\n\t}\n\telse if( factorization(n-j).length == 2 ){\n\t\tcontinue;\n\t}\n\telse{\n\t\twrite(j + \" \" + (n-j));\n\t\tbreak;\n\t}\n}"}, {"source_code": "var r = +readline();\nvar first_comp = 0;\nvar sec_comp = 0;\n\nif(r % 2 == 0){\n\tfirst_comp = r - 8;\n\tsec_comp = r - first_comp;\n \tprint(first_comp + \" \" + sec_comp);\n}else if (r % 2 != 0){\n\tfirst_comp = r - 9;\n\tsec_comp = r - first_comp;\n\tprint(first_comp + \" \" + sec_comp);\n}"}, {"source_code": "var r = +readline();\n\n// var first_num = Math.floor((r / 3) + 1);\n// var sec_num = Math.floor(r - first_num);\n\nif(r % 2 == 0){\n\tvar first_num = Math.floor(r - 8);\n\tvar sec_num = Math.floor(r - first_num);\n \tprint(first_num + \" \" + sec_num);\n}else if (r % 2 != 0){\n\tvar first_num = Math.floor(r - 9);\n\tvar sec_num = Math.floor(r - first_num);\n\tprint(first_num + \" \" + sec_num);\n}"}, {"source_code": "var n = readline() - 0;\nif (n & 1) {\n print('9 ' + (n - 9));\n} else {\n var a = n / 2;\n if (a & 1) {\n print((a - 1) + ' ' + (a + 1));\n } else {\n print(a + ' ' + a);\n }\n}\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}"}, {"source_code": ";(function () {\n\n\tvar simpleArray = (function (n) {\n\n\t\tvar retArray = [], controlArray = new Array(n);\n\n\t\tfor (var i = 2; i < n; i ++) {\n\t\t\tif (controlArray[i] !== false) {\n\t\t\t\tretArray.push(i);\n\n\t\t\t\tfor (var j = i; j < n; j += i) {\n\t\t\t\t\tcontrolArray[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn retArray;\n\n\t})(1e6 + 5);\n\n\tprint(function (n) {\n\n\t\tvar n1, n2;\n\n\t\tfor (var i = 4; i < n; i++) {\n\t\t\tn1 = i; n2 = n - n1;\n\n\t\t\tif (simpleArray.indexOf(n1) === -1 && simpleArray.indexOf(n2) === -1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn [n1, n2].join(' ');\n\n\t}(+readline()));\n\n}.call(this));\n"}, {"source_code": "var numbers = parseInt(readline());\nif(numbers % 2 == 1){\n print(9, numbers - 9);\n} else {\n print(4, numbers - 4);\n}\n"}, {"source_code": "var n = Number(readline());\nif (n%2 === 0) {\n print(4, n-4);\n}\nelse {\n print(9, n-9);\n}"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c ;\n res = -1;\n c = 0 ;\n for( i = 2 ; i < this.n ; i++ ) {\n a = i ;\n b = this.n - a ;\n if( this.arr[ a ] == 0 && this.arr[ b ] == 0 ) {\n c = 1 ;\n break;\n }\n }\n if( c == 0 ) {\n print( res );\n }\n else {\n print( a + \" \" + b );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n var i , sz , a ;\n this.lim1 = 1000010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n this.bmfObj = new BasicMathFunctions();\n this.primes = this.bmfObj.getPrimes( 1000000 ) ;\n sz = this.primes.length;\n for( i = 0 ; i < sz ; i++ ) {\n a = this.primes[ i ] ;\n this.arr[ a ] = 1 ;\n }\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nfunction BasicMathFunctions() {\n this.eps = 1e-9;\n\n this.getPrimes = function( n ) {\n var sq , i , j , a , bitSize;\n bitSize = 31;\n this.pre = new Array();\n this.primes = new Array();\n for( i = 0 ; i < n ; i++ ) {\n this.pre.push( 0 );\n }\n sq = Math.ceil( Math.sqrt( n * 1.0 ) + this.eps );\n for( i = 3 ; i < sq ; i += 2 ) {\n a = this.pre[ i >> 6 ] & ( 1 << ( ( i >> 1 ) & bitSize ) );\n if( a == 0 ) {\n for( j = i * i ; j <= n ; j += ( i << 1 ) ) {\n this.pre[ j >> 6 ] |= ( 1 << ( ( j >> 1 ) & bitSize ) );\n }\n }\n }\n this.primes.push( 2 );\n for( i = 3 ; i <= n ; i += 2 ) {\n a = this.pre[ i >> 6 ] & ( 1 << ( ( i >> 1 ) & bitSize ) );\n if( a == 0 ) {\n this.primes.push( i );\n }\n }\n return this.primes;\n };\n\n this.isPrimeUptoSqrt = function( n ) {\n var sq , i , res;\n sq = Math.ceil( Math.sqrt( n * 1.0 ) + this.eps );\n res = true;\n for( i = 2 ; i <= sq ; i++ ) {\n if( n % i == 0 ) {\n res = false;\n break;\n }\n }\n return res;\n };\n\n this.factorize = function( n ) {\n var sq , i , lastPrime , cnt , res;\n if( this.primes == null || this.primes.length == 0 ) {\n throw new Error( \"No primes are available for factorization!\" );\n }\n lastPrime = this.primes[ this.primes.length - 1 ];\n if( lastPrime * lastPrime < n ) {\n throw new Error( \"Insufficient number of primes are available for factorization!\" );\n }\n res = new Array();\n if( n == 1 ) {\n return res;\n }\n sq = Math.ceil( Math.sqrt( n * 1.0 ) + this.eps );\n for( i = 0 ; this.primes[ i ] <= sq ; i++ ) {\n if( n % this.primes[ i ] == 0 ) {\n cnt = 0;\n while( n % this.primes[ i ] == 0 ) {\n n = Math.floor( n / this.primes[ i ] );\n cnt++;\n }\n res.push( new Array() );\n res[ res.length - 1 ].push( this.primes[ i ] );\n res[ res.length - 1 ].push( cnt );\n sq = Math.ceil( Math.sqrt( n * 1.0 ) + this.eps );\n }\n }\n if( n > 1 ) {\n res.push( new Array() );\n res[ res.length - 1 ].push( n );\n res[ res.length - 1 ].push( 1 );\n }\n return res;\n };\n\n this.modLongInteger = function( n , mod ) {\n var factoList , sz , i , j , cnt , res , a;\n if( n == null ) {\n throw new Error( \"Need the n(first) parameter!\" );\n }\n if( mod == null ) {\n throw new Error( \"Need the mod(second) parameter!\" );\n }\n factoList = this.factorize( n );\n sz = factoList.length;\n res = 1;\n for( i = 0 ; i < sz ; i++ ) {\n a = factoList[ i ][ 0 ];\n cnt = factoList[ i ][ 1 ];\n for( j = 0 ; j < cnt ; j++ ) {\n if( res * a > 9e15 ) {\n throw new Error( \"The multiplication of numbers have gone beyond 2^53!\" );\n }\n res = ( res * a ) % mod;\n }\n }\n return res;\n };\n\n this.multiplyTwoLongInteger = function( n , m , mod ) {\n var factoList , sz , i , j , cnt , res , a;\n if( n == null ) {\n throw new Error( \"Need the n(first) parameter!\" );\n }\n if( m == null ) {\n throw new Error( \"Need the m(second) parameter!\" );\n }\n if( mod == null ) {\n throw new Error( \"Need the mod(third) parameter!\" );\n }\n factoList = this.factorize( n );\n sz = factoList.length;\n res = 1;\n for( i = 0 ; i < sz ; i++ ) {\n a = factoList[ i ][ 0 ];\n cnt = factoList[ i ][ 1 ];\n for( j = 0 ; j < cnt ; j++ ) {\n if( res * a > 9e15 ) {\n throw new Error( \"The multiplication of numbers have gone beyond 2^53!\" );\n }\n res = ( res * a ) % mod;\n }\n }\n factoList = this.factorize( m );\n sz = factoList.length;\n for( i = 0 ; i < sz ; i++ ) {\n a = factoList[ i ][ 0 ];\n cnt = factoList[ i ][ 1 ];\n for( j = 0 ; j < cnt ; j++ ) {\n if( res * a > 9e15 ) {\n throw new Error( \"The multiplication of numbers have gone beyond 2^53!\" );\n }\n res = ( res * a ) % mod;\n }\n }\n return res;\n };\n\n this.bigModLongInteger = function( a , p , mod ) {\n var res , x;\n x = a;\n res = 1;\n while( p > 0 ) {\n if( p % 2 != 0 ) {\n res = this.multiplyTwoLongInteger( res , x , mod );\n }\n x = this.multiplyTwoLongInteger( x , x , mod );\n p >>= 1;\n }\n return res;\n };\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "'use strict';\n\nconst is\u0421ompositeNumber = num => {\n for (let i = 2; i < num - 1; i++) {\n if (num % i === 0) {\n return true;\n }\n }\n \n return false;\n};\n\n(function () {\n const n = parseInt(readline());\n \n for (let i = 4; i < n - 1; i++) {\n if (\n is\u0421ompositeNumber(i) &&\n is\u0421ompositeNumber(n - i)\n ) {\n write(i + ' ' + (n - i));\n return;\n }\n }\n })();"}, {"source_code": "var n = readline();\nvar q;\nfor (x=4;x3&&((c%2==0||c%3==0)&&(b%2==0||b%3==0)))\n\t{\n\tprint(b,c)\n\tbreak;\n\t}\n}\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n for(var i = 2; i < N; i++){\n var x = i;\n var y = N - i;\n if(!isPrime(x) && !isPrime(y)){\n myout(x + \" \" + y);\n return;\n }\n }\n}\nfunction isPrime(val){\n if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){\n return false;\n }else if(val == 2){\n return true;\n }\n var root = Math.floor(Math.sqrt(val));\n for(var i = 3; i <= root; i += 2){\n if(val % i == 0){\n return false;\n }\n }\n return true;\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet ans = (x, y) => console.log(`${x} ${y}`);\nfunction isPrime(num) {\n if (num <= 1) return false;\n if (num % 2 == 0 && num > 2) return false;\n let s = Math.sqrt(num);\n for (let i = 3; i <= s; i++) {\n if (num % i === 0) return false;\n }\n return true;\n}\n\nrl.on('line', (d) => {\n let x = Math.floor(+d / 2);\n let y = Math.ceil(+d / 2);;\n\n while (isPrime(x) || isPrime(y)) {\n x--;\n y++;\n }\n\n ans(x, y);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let nums = parseInt(input[0]);\n \n let left = 0, right = 0;\n if (nums % 2 === 0) { left = nums/2; right = nums/2; }\n else { left = (nums-1)/2; right = (nums+1)/2; }\n\n\n while (true) {\n if ( (left % 2 === 0 || (left % 3 === 0 && left !== 3) || (left % 5 === 0 && left !== 5) || (left % 7 === 0 && left !== 7)) && \n (right % 2 === 0 || (right % 3 === 0 && right !== 3) || (right % 5 === 0 && right !== 5) || (right % 7 === 0 && right !== 7)) ) {\n console.log(`${left} ${right}`);\n break;\n } else {\n right -= 1; left += 1; \n }\n }\n});\n"}, {"source_code": "let fs = require(\"fs\");\n\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(/[\\r\\n]/).filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i ++) {\n doit(txt[i] * 1);\n}\n\nfunction doit(num) {\n let max=num-4;\n let min=4;\n while (true) {\n if(composite(max)&&composite(min)){\n console.log(min,max);\n return;\n }else{\n --max;\n ++min;\n }\n }\n}\n\nfunction composite(num) {\n for (let i = 2; i <= num / 2; i++) {\n if (num % i === 0) return true\n\n }\n return false;\n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = +str.trim();\n let compositeNum = [];\n for (let i = 4; i < inputs; i++) {\n\n if (!checkPrime(i)) {\n let difference = inputs - i;\n if (!checkPrime(difference)) {\n compositeNum.push(i, difference);\n break;\n }\n }\n }\n return compositeNum.join(' ').toString();\n}\n\nfunction checkPrime(num) {\n let isPrime = true;\n for (i = 2; i <= num / 2; ++i) {\n if (num % i == 0) {\n isPrime = false;\n break;\n }\n }\n return isPrime;\n}\n\n\n\n\n"}, {"source_code": "function main() {\n\tvar n = parseInt(readline());\n\tvar a, b;\n\tif (n % 2 == 0) {\n\t\ta = 8;\n\t\tb = n - 8;\n\t} else {\n\t\ta = 9;\n\t\tb = n - 9;\n\t}\n\tprint(a, b);\n}\n\nmain();"}, {"source_code": "var n = Number(readline());\n\nif (n % 2 === 0) {\n print(8, n-8);\n}\nelse {\n print(9, n-9);\n}\n"}, {"source_code": "var x = parseInt(readline()); // user input\n//var x = 787\nvar a = -1, b = -1;\nvar siv = new Array(x + 1).fill(1)\nfor (var n = 2; n * n <= x; n++) {\nif (siv[n]) {\nfor (var k = n * n; k <= x; k += n)siv[k] = 0;\n}\n}\nfor (var n = 2; n < x; n++) {\nif (!siv[n] && !siv[x - n]) {\na = n;\nb = x - n;\nbreak;\n}\n}\nprint(a +' '+ b)\n//console.log(a, b);\n"}, {"source_code": "var entrada = readline();\nvar numero = parseInt(entrada);\nvar x = 4;\nvar y;\nif(numero%2===0){\n y = numero-x; \n} else {\n x = 9;\n\ty = numero-9;\n}\nprint(x+' '+y);"}, {"source_code": "var x = parseInt(readline());\n//var x = 18\nvar a = -1, b = -1;\nvar siv = new Array(x + 1).fill(1)\nfor (var n = 2; n * n <= x; n++) {\nif (siv[n]) {\nfor (var k = n * n; k <= x; k += n)siv[k] = 0;\n}\n}\nfor (var n = 2; n < x; n++) {\nif (!siv[n] && !siv[x - n]) {\na = n;\nb = x - n;\nbreak;\n}\n}\nprint(a +' '+ b)\n//console.log(a, b);"}, {"source_code": "var entrada = readline();\nvar numero = parseInt(entrada);\nvar x = 4;\nvar y;\nif(numero%2===0){\n y = numero-x; \n} else {\n x = 9;\n\ty = numero-9;\n}\nprint(x+' '+y); "}, {"source_code": "// Generated by CoffeeScript 1.10.0\n(function() {\n var a, f, i, j, k, l, len, m, n, ref, ref1, ref2, ref3;\n\n n = parseInt(readline());\n\n a = [];\n\n for (i = j = 2, ref = Math.sqrt(n); 2 <= ref ? j <= ref : j >= ref; i = 2 <= ref ? ++j : --j) {\n if (!a[i]) {\n for (k = l = ref1 = 2 * i, ref2 = n, ref3 = i; ref3 > 0 ? l <= ref2 : l >= ref2; k = l += ref3) {\n a[k] = true;\n }\n }\n }\n\n for (i = m = 0, len = a.length; m < len; i = ++m) {\n f = a[i];\n if (i < 2) {\n continue;\n }\n if (f && a[n - i]) {\n print(i + ' ' + (n - i));\n break;\n }\n }\n\n}).call(this);\n"}, {"source_code": "var n = parseInt(readline());\nvar a = 0;\nfunction composite(n) {\n\tfor (var i = 2; i <= Math.ceil(Math.sqrt(n)); i++){\n\t\tif (n % i == 0) return true;\n\t};\n\treturn false;\n}\n\nfor (var i = Math.ceil(n / 2) - 1; i > 0; i--){\n\tif (composite(i) && composite(n - i)) {\n\t\ta = i;\n\t\tbreak;\n\t}\n\t\n}\nprint (a + ' ' + (n-a));"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n if (n % 2 == 0) console.log(n - 4, 4)\n else console.log(n - 9, 9)\n}"}, {"source_code": "var designTask = function(n)\n {\n var checkArr = [4, 6, 8, 9];\n for (var i = 0; i <= 3; i++)\n {\n if ((n - checkArr[i]) % 2 === 0) return (n - checkArr[i]) + ' ' + checkArr[i];\n else if ((n - checkArr[i]) % 3 === 0) return (n - checkArr[i]) + ' ' + checkArr[i];\n }\n }\nvar input = readline();\nprint(designTask(+input));"}, {"source_code": "var sourceNumber = +readline();\nvar firstNumber = Math.floor(sourceNumber/2);\nvar secondNumber = Math.ceil(sourceNumber/2);\nvar isFirstNumberComposite = false;\nvar isSecondNumberComposite = false;\n\nwhile (!isSecondNumberComposite || !isFirstNumberComposite) {\n for (var start = 2; start<=Math.ceil(Math.sqrt(firstNumber)); start++) {\n if (firstNumber%start === 0) {\n isFirstNumberComposite = true;\n // print(\"F\" + firstNumber + \"/\" + start);\n }\n }\n for (var start = 2; start<=Math.ceil(Math.sqrt(secondNumber)); start++) {\n if (secondNumber%start === 0) {\n isSecondNumberComposite = true;\n // print(\"S\" + secondNumber + \"/\" + start);\n } \n }\n \n if (!isSecondNumberComposite || !isFirstNumberComposite) {\n firstNumber--;\n secondNumber++;\n isFirstNumberComposite = false;\n isSecondNumberComposite = false;\n }\n}\nprint(firstNumber + \" \" + secondNumber);"}, {"source_code": "var n = parseInt(readline());\n\nvar x = (n - n % 2) / 2, y = (n + n % 2) / 2;\nwhile ((isPrime(x) || isPrime(y))){\n\tx--; y++;\n}\nprint(x + \" \" + y);\n\nfunction isPrime(p) {\n\tfor(var i = 2; i <= Math.sqrt(p); i++) {\n\t\tif (p % i === 0)\n\t\t\treturn false;\n\t} \n\treturn true;\n}\t\n"}, {"source_code": "(function () {\n var num = parseInt(readline());\n\n if (num % 2 == 0){\n print(8 + \" \" + (num - 8))\n } else {\n print(9 + \" \" + (num - 9))\n }\n\n return 0;\n})();"}, {"source_code": "function isComposite(n) {\n for(var i = 2; i * i <= n; ++i) {\n if(n % i == 0) {\n return true;\n }\n }\n return false;\n}\n\nvar n = parseInt(readline());\nfor(var i = 4; i * 2 <= n; ++i) {\n if(isComposite(i) && isComposite(n - i)) {\n print(i, n - i);\n break;\n }\n}\n"}, {"source_code": "\n// Solution By: Problem Setter\n\nvar n = parseInt(readline()); // user input\nif (n % 2 == 0) print(4, + n - 4);\nelse print(9, n - 9);\n\n\n\n\n\n\n"}, {"source_code": "\nvar number = parseInt(readline());\n//var number = 91;\nvar found = false;\nfor (i = 1, j = number - 1; i < j && j > 0 && i < number; i++, j--) {\n if (isPrime(i) || i < 2 || isPrime(j) || j < 2) {\n continue;\n } else {\n found = true;\n break;\n }\n}\nif (found) print(i + ' ' + j);\n//console.log(found ? `${i},${j}` : \"Not found\");\nfunction isPrime(value) {\n for (var i = 2; i < value; i++) {\n if (value % i === 0) {\n return false;\n }\n }\n return value > 1;\n}\n\n\n\n"}, {"source_code": "var n = parseInt(readline());\nvar x = 4;\nvar y = 0;\nif(n%2==0)\n{\n y = n - x; \n}\nelse\n{\n x = 9;\n\ty = n - 9;\n}\nprint(x + ' ' + y);"}, {"source_code": "var n = parseInt(readline()),\n\t\t\tx = 4, y = 0;\n\n\t\twhile(true)\t{\n\t\t\tif(isCheck(x))\t{\n\t\t\t\ty = n - x;\n\t\t\t\tif(isCheck(y))\tbreak;\n\t\t\t}\n\n\t\t\tx++;\n\t\t}\n\n\t\tprint(x + ' ' + y);\n\n\t\tfunction isCheck(num)\t{\n\t\t\tif(num == 2 || num == 3)\treturn false;\n\t\t\tif(num % 2 == 0 || num % 3 == 0)\treturn true;\n\t\t\telse\treturn false;\n\t\t};"}, {"source_code": "var n = parseInt(readline());\nvar x = 4;\nvar y = 0;\nif(n%2==0)\n{\n y = n - x; \n}\nelse\n{\n x = 9;\n\ty = n - 9;\n}\nprint(x + ' ' + y);"}, {"source_code": "var n = parseInt(readline())\nvar x = 2, y = 0\n\nfor(;x <= n/2;x++){\n y = n - x\n if(!isPrime(y) && !isPrime(x)){\n print(x + ' ' + y)\n break\n }\n}\n\nfunction isPrime(x){\n for(var i = 2;i<=Math.sqrt(x);i++){\n if(x%i === 0){\n return false\n }\n }\n return true\n}\n"}], "negative_code": [{"source_code": "var input = readline();\nprint(main(input));\n\n// Need gcd.\n\nfunction gcd(a, b) {\n\tif (b === 0) return a;\n\treturn gcd(b, a % b);\n}\n\nfunction modularPow(a, n, mod) {\n\tif (n === 1) return a % mod;\n\tvar pow = modularPow(a, Math.floor(n / 2), mod);\n\tif (n % 2 === 0) {\n\t\treturn (pow * pow) % mod;\n\t}\n\treturn (pow * pow * a) % mod;\n}\n\nfunction notPrime(p) {\n\t// exactly not prime\n\t// Fermat's little theorem\n\tif (p === 2) return false;\n\n\tvar a = 2; // choose small parameter.\n\tif (gcd(a, p) !== 1) return true; // not prime.\n\tvar expr = modularPow(a, p - 1, p);\n\tconsole.log(expr)\n\treturn !(expr === 1); // Exact not prime.\n}\n\nfunction main(number) {\n\tvar div = 4;\n\twhile (div < number) {\n\t\tif (notPrime(number - div) && notPrime(div)) {\n\t\t\treturn number + ' ' + div;\n\t\t}\n\t}\n}\n"}, {"source_code": "function primToN(n){\n\tvar answer = [2];\n\n\tfor(j = 3; j <= n; j++){\n\t\tif( answer.every(function(number){return (j%number != 0) ? true : false}) ){\n\t\t\tanswer.push(j);\n\t\t}\n\t}\n\tj = undefined, number = undefined;\n\treturn answer;\n}\n\nvar n = +readline(), primes = (n < 10000) ? primToN(n) : \"2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999 5003 5009 5011 5021 5023 5039 5051 5059 5077 5081 5087 5099 5101 5107 5113 5119 5147 5153 5167 5171 5179 5189 5197 5209 5227 5231 5233 5237 5261 5273 5279 5281 5297 5303 5309 5323 5333 5347 5351 5381 5387 5393 5399 5407 5413 5417 5419 5431 5437 5441 5443 5449 5471 5477 5479 5483 5501 5503 5507 5519 5521 5527 5531 5557 5563 5569 5573 5581 5591 5623 5639 5641 5647 5651 5653 5657 5659 5669 5683 5689 5693 5701 5711 5717 5737 5741 5743 5749 5779 5783 5791 5801 5807 5813 5821 5827 5839 5843 5849 5851 5857 5861 5867 5869 5879 5881 5897 5903 5923 5927 5939 5953 5981 5987 6007 6011 6029 6037 6043 6047 6053 6067 6073 6079 6089 6091 6101 6113 6121 6131 6133 6143 6151 6163 6173 6197 6199 6203 6211 6217 6221 6229 6247 6257 6263 6269 6271 6277 6287 6299 6301 6311 6317 6323 6329 6337 6343 6353 6359 6361 6367 6373 6379 6389 6397 6421 6427 6449 6451 6469 6473 6481 6491 6521 6529 6547 6551 6553 6563 6569 6571 6577 6581 6599 6607 6619 6637 6653 6659 6661 6673 6679 6689 6691 6701 6703 6709 6719 6733 6737 6761 6763 6779 6781 6791 6793 6803 6823 6827 6829 6833 6841 6857 6863 6869 6871 6883 6899 6907 6911 6917 6947 6949 6959 6961 6967 6971 6977 6983 6991 6997 7001 7013 7019 7027 7039 7043 7057 7069 7079 7103 7109 7121 7127 7129 7151 7159 7177 7187 7193 7207 7211 7213 7219 7229 7237 7243 7247 7253 7283 7297 7307 7309 7321 7331 7333 7349 7351 7369 7393 7411 7417 7433 7451 7457 7459 7477 7481 7487 7489 7499 7507 7517 7523 7529 7537 7541 7547 7549 7559 7561 7573 7577 7583 7589 7591 7603 7607 7621 7639 7643 7649 7669 7673 7681 7687 7691 7699 7703 7717 7723 7727 7741 7753 7757 7759 7789 7793 7817 7823 7829 7841 7853 7867 7873 7877 7879 7883 7901 7907 7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081 8087 8089 8093 8101 8111 8117 8123 8147 8161 8167 8171 8179 8191 8209 8219 8221 8231 8233 8237 8243 8263 8269 8273 8287 8291 8293 8297 8311 8317 8329 8353 8363 8369 8377 8387 8389 8419 8423 8429 8431 8443 8447 8461 8467 8501 8513 8521 8527 8537 8539 8543 8563 8573 8581 8597 8599 8609 8623 8627 8629 8641 8647 8663 8669 8677 8681 8689 8693 8699 8707 8713 8719 8731 8737 8741 8747 8753 8761 8779 8783 8803 8807 8819 8821 8831 8837 8839 8849 8861 8863 8867 8887 8893 8923 8929 8933 8941 8951 8963 8969 8971 8999 9001 9007 9011 9013 9029 9041 9043 9049 9059 9067 9091 9103 9109 9127 9133 9137 9151 9157 9161 9173 9181 9187 9199 9203 9209 9221 9227 9239 9241 9257 9277 9281 9283 9293 9311 9319 9323 9337 9341 9343 9349 9371 9377 9391 9397 9403 9413 9419 9421 9431 9433 9437 9439 9461 9463 9467 9473 9479 9491 9497 9511 9521 9533 9539 9547 9551 9587 9601 9613 9619 9623 9629 9631 9643 9649 9661 9677 9679 9689 9697 9719 9721 9733 9739 9743 9749 9767 9769 9781 9787 9791 9803 9811 9817 9829 9833 9839 9851 9857 9859 9871 9883 9887 9901 9907 9923 9929 9931 9941 9949 9967 9973 10007 10009 10037 10039 10061 10067 10069 10079 10091 10093 10099 10103 10111 10133 10139 10141 10151 10159 10163 10169 10177 10181 10193 10211 10223 10243 10247 10253 10259 10267 10271 10273 10289 10301 10303 10313 10321 10331 10333 10337 10343 10357 10369 10391 10399 10427 10429 10433 10453 10457 10459 10463 10477 10487 10499 10501 10513 10529 10531 10559 10567 10589 10597 10601 10607 10613 10627 10631 10639 10651 10657 10663 10667 10687 10691 10709 10711 10723 10729 10733 10739 10753 10771 10781 10789 10799 10831 10837 10847 10853 10859 10861 10867 10883 10889 10891 10903 10909 10937 10939 10949 10957 10973 10979 10987 10993 11003 11027 11047 11057 11059 11069 11071 11083 11087 11093 11113 11117 11119 11131 11149 11159 11161 11171 11173 11177 11197 11213 11239 11243 11251 11257 11261 11273 11279 11287 11299 11311 11317 11321 11329 11351 11353 11369 11383 11393 11399 11411 11423 11437 11443 11447 11467 11471 11483 11489 11491 11497 11503 11519 11527 11549 11551 11579 11587 11593 11597 11617 11621 11633 11657 11677 11681 11689 11699 11701 11717 11719 11731 11743 11777 11779 11783 11789 11801 11807 11813 11821 11827 11831 11833 11839 11863 11867 11887 11897 11903 11909 11923 11927 11933 11939 11941 11953 11959 11969 11971 11981 11987 12007 12011 12037 12041 12043 12049 12071 12073 12097 12101 12107 12109 12113 12119 12143 12149 12157 12161 12163 12197 12203 12211 12227 12239 12241 12251 12253 12263 12269 12277 12281 12289 12301 12323 12329 12343 12347 12373 12377 12379 12391 12401 12409 12413 12421 12433 12437 12451 12457 12473 12479 12487 12491 12497 12503 12511 12517 12527 12539 12541 12547 12553 12569 12577 12583 12589 12601 12611 12613 12619 12637 12641 12647 12653 12659 12671 12689 12697 12703 12713 12721 12739 12743 12757 12763 12781 12791 12799 12809 12821 12823 12829 12841 12853 12889 12893 12899 12907 12911 12917 12919 12923 12941 12953 12959 12967 12973 12979 12983 13001 13003 13007 13009 13033 13037 13043 13049 13063 13093 13099 13103 13109 13121 13127 13147 13151 13159 13163 13171 13177 13183 13187 13217 13219 13229 13241 13249 13259 13267 13291 13297 13309 13313 13327 13331 13337 13339 13367 13381 13397 13399 13411 13417 13421 13441 13451 13457 13463 13469 13477 13487 13499 13513 13523 13537 13553 13567 13577 13591 13597 13613 13619 13627 13633 13649 13669 13679 13681 13687 13691 13693 13697 13709 13711 13721 13723 13729 13751 13757 13759 13763 13781 13789 13799 13807 13829 13831 13841 13859 13873 13877 13879 13883 13901 13903 13907 13913 13921 13931 13933 13963 13967 13997 13999 14009 14011 14029 14033 14051 14057 14071 14081 14083 14087 14107 14143 14149 14153 14159 14173 14177 14197 14207 14221 14243 14249 14251 14281 14293 14303 14321 14323 14327 14341 14347 14369 14387 14389 14401 14407 14411 14419 14423 14431 14437 14447 14449 14461 14479 14489 14503 14519 14533 14537 14543 14549 14551 14557 14561 14563 14591 14593 14621 14627 14629 14633 14639 14653 14657 14669 14683 14699 14713 14717 14723 14731 14737 14741 14747 14753 14759 14767 14771 14779 14783 14797 14813 14821 14827 14831 14843 14851 14867 14869 14879 14887 14891 14897 14923 14929 14939 14947 14951 14957 14969 14983 15013 15017 15031 15053 15061 15073 15077 15083 15091 15101 15107 15121 15131 15137 15139 15149 15161 15173 15187 15193 15199 15217 15227 15233 15241 15259 15263 15269 15271 15277 15287 15289 15299 15307 15313 15319 15329 15331 15349 15359 15361 15373 15377 15383 15391 15401 15413 15427 15439 15443 15451 15461 15467 15473 15493 15497 15511 15527 15541 15551 15559 15569 15581 15583 15601 15607 15619 15629 15641 15643 15647 15649 15661 15667 15671 15679 15683 15727 15731 15733 15737 15739 15749 15761 15767 15773 15787 15791 15797 15803 15809 15817 15823 15859 15877 15881 15887 15889 15901 15907 15913 15919 15923 15937 15959 15971 15973 15991 16001 16007 16033 16057 16061 16063 16067 16069 16073 16087 16091 16097 16103 16111 16127 16139 16141 16183 16187 16189 16193 16217 16223 16229 16231 16249 16253 16267 16273 16301 16319 16333 16339 16349 16361 16363 16369 16381 16411 16417 16421 16427 16433 16447 16451 16453 16477 16481 16487 16493 16519 16529 16547 16553 16561 16567 16573 16603 16607 16619 16631 16633 16649 16651 16657 16661 16673 16691 16693 16699 16703 16729 16741 16747 16759 16763 16787 16811 16823 16829 16831 16843 16871 16879 16883 16889 16901 16903 16921 16927 16931 16937 16943 16963 16979 16981 16987 16993 17011 17021 17027 17029 17033 17041 17047 17053 17077 17093 17099 17107 17117 17123 17137 17159 17167 17183 17189 17191 17203 17207 17209 17231 17239 17257 17291 17293 17299 17317 17321 17327 17333 17341 17351 17359 17377 17383 17387 17389 17393 17401 17417 17419 17431 17443 17449 17467 17471 17477 17483 17489 17491 17497 17509 17519 17539 17551 17569 17573 17579 17581 17597 17599 17609 17623 17627 17657 17659 17669 17681 17683 17707 17713 17729 17737 17747 17749 17761 17783 17789 17791 17807 17827 17837 17839 17851 17863 17881 17891 17903 17909 17911 17921 17923 17929 17939 17957 17959 17971 17977 17981 17987 17989 18013 18041 18043 18047 18049 18059 18061 18077 18089 18097 18119 18121 18127 18131 18133 18143 18149 18169 18181 18191 18199 18211 18217 18223 18229 18233 18251 18253 18257 18269 18287 18289 18301 18307 18311 18313 18329 18341 18353 18367 18371 18379 18397 18401 18413 18427 18433 18439 18443 18451 18457 18461 18481 18493 18503 18517 18521 18523 18539 18541 18553 18583 18587 18593 18617 18637 18661 18671 18679 18691 18701 18713 18719 18731 18743 18749 18757 18773 18787 18793 18797 18803 18839 18859 18869 18899 18911 18913 18917 18919 18947 18959 18973 18979 19001 19009 19013 19031 19037 19051 19069 19073 19079 19081 19087 19121 19139 19141 19157 19163 19181 19183 19207 19211 19213 19219 19231 19237 19249 19259 19267 19273 19289 19301 19309 19319 19333 19373 19379 19381 19387 19391 19403 19417 19421 19423 19427 19429 19433 19441 19447 19457 19463 19469 19471 19477 19483 19489 19501 19507 19531 19541 19543 19553 19559 19571 19577 19583 19597 19603 19609 19661 19681 19687 19697 19699 19709 19717 19727 19739 19751 19753 19759 19763 19777 19793 19801 19813 19819 19841 19843 19853 19861 19867 19889 19891 19913 19919 19927 19937 19949 19961 19963 19973 19979 19991 19993 19997 20011 20021 20023 20029 20047 20051 20063 20071 20089 20101 20107 20113 20117 20123 20129 20143 20147 20149 20161 20173 20177 20183 20201 20219 20231 20233 20249 20261 20269 20287 20297 20323 20327 20333 20341 20347 20353 20357 20359 20369 20389 20393 20399 20407 20411 20431 20441 20443 20477 20479 20483 20507 20509 20521 20533 20543 20549 20551 20563 20593 20599 20611 20627 20639 20641 20663 20681 20693 20707 20717 20719 20731 20743 20747 20749 20753 20759 20771 20773 20789 20807 20809 20849 20857 20873 20879 20887 20897 20899 20903 20921 20929 20939 20947 20959 20963 20981 20983 21001 21011 21013 21017 21019 21023 21031 21059 21061 21067 21089 21101 21107 21121 21139 21143 21149 21157 21163 21169 21179 21187 21191 21193 21211 21221 21227 21247 21269 21277 21283 21313 21317 21319 21323 21341 21347 21377 21379 21383 21391 21397 21401 21407 21419 21433 21467 21481 21487 21491 21493 21499 21503 21517 21521 21523 21529 21557 21559 21563 21569 21577 21587 21589 21599 21601 21611 21613 21617 21647 21649 21661 21673 21683 21701 21713 21727 21737 21739 21751 21757 21767 21773 21787 21799 21803 21817 21821 21839 21841 21851 21859 21863 21871 21881 21893 21911 21929 21937 21943 21961 21977 21991 21997 22003 22013 22027 22031 22037 22039 22051 22063 22067 22073 22079 22091 22093 22109 22111 22123 22129 22133 22147 22153 22157 22159 22171 22189 22193 22229 22247 22259 22271 22273 22277 22279 22283 22291 22303 22307 22343 22349 22367 22369 22381 22391 22397 22409 22433 22441 22447 22453 22469 22481 22483 22501 22511 22531 22541 22543 22549 22567 22571 22573 22613 22619 22621 22637 22639 22643 22651 22669 22679 22691 22697 22699 22709 22717 22721 22727 22739 22741 22751 22769 22777 22783 22787 22807 22811 22817 22853 22859 22861 22871 22877 22901 22907 22921 22937 22943 22961 22963 22973 22993 23003 23011 23017 23021 23027 23029 23039 23041 23053 23057 23059 23063 23071 23081 23087 23099 23117 23131 23143 23159 23167 23173 23189 23197 23201 23203 23209 23227 23251 23269 23279 23291 23293 23297 23311 23321 23327 23333 23339 23357 23369 23371 23399 23417 23431 23447 23459 23473 23497 23509 23531 23537 23539 23549 23557 23561 23563 23567 23581 23593 23599 23603 23609 23623 23627 23629 23633 23663 23669 23671 23677 23687 23689 23719 23741 23743 23747 23753 23761 23767 23773 23789 23801 23813 23819 23827 23831 23833 23857 23869 23873 23879 23887 23893 23899 23909 23911 23917 23929 23957 23971 23977 23981 23993 24001 24007 24019 24023 24029 24043 24049 24061 24071 24077 24083 24091 24097 24103 24107 24109 24113 24121 24133 24137 24151 24169 24179 24181 24197 24203 24223 24229 24239 24247 24251 24281 24317 24329 24337 24359 24371 24373 24379 24391 24407 24413 24419 24421 24439 24443 24469 24473 24481 24499 24509 24517 24527 24533 24547 24551 24571 24593 24611 24623 24631 24659 24671 24677 24683 24691 24697 24709 24733 24749 24763 24767 24781 24793 24799 24809 24821 24841 24847 24851 24859 24877 24889 24907 24917 24919 24923 24943 24953 24967 24971 24977 24979 24989 25013 25031 25033 25037 25057 25073 25087 25097 25111 25117 25121 25127 25147 25153 25163 25169 25171 25183 25189 25219 25229 25237 25243 25247 25253 25261 25301 25303 25307 25309 25321 25339 25343 25349 25357 25367 25373 25391 25409 25411 25423 25439 25447 25453 25457 25463 25469 25471 25523 25537 25541 25561 25577 25579 25583 25589 25601 25603 25609 25621 25633 25639 25643 25657 25667 25673 25679 25693 25703 25717 25733 25741 25747 25759 25763 25771 25793 25799 25801 25819 25841 25847 25849 25867 25873 25889 25903 25913 25919 25931 25933 25939 25943 25951 25969 25981 25997 25999 26003 26017 26021 26029 26041 26053 26083 26099 26107 26111 26113 26119 26141 26153 26161 26171 26177 26183 26189 26203 26209 26227 26237 26249 26251 26261 26263 26267 26293 26297 26309 26317 26321 26339 26347 26357 26371 26387 26393 26399 26407 26417 26423 26431 26437 26449 26459 26479 26489 26497 26501 26513 26539 26557 26561 26573 26591 26597 26627 26633 26641 26647 26669 26681 26683 26687 26693 26699 26701 26711 26713 26717 26723 26729 26731 26737 26759 26777 26783 26801 26813 26821 26833 26839 26849 26861 26863 26879 26881 26891 26893 26903 26921 26927 26947 26951 26953 26959 26981 26987 26993 27011 27017 27031 27043 27059 27061 27067 27073 27077 27091 27103 27107 27109 27127 27143 27179 27191 27197 27211 27239 27241 27253 27259 27271 27277 27281 27283 27299 27329 27337 27361 27367 27397 27407 27409 27427 27431 27437 27449 27457 27479 27481 27487 27509 27527 27529 27539 27541 27551 27581 27583 27611 27617 27631 27647 27653 27673 27689 27691 27697 27701 27733 27737 27739 27743 27749 27751 27763 27767 27773 27779 27791 27793 27799 27803 27809 27817 27823 27827 27847 27851 27883 27893 27901 27917 27919 27941 27943 27947 27953 27961 27967 27983 27997 28001 28019 28027 28031 28051 28057 28069 28081 28087 28097 28099 28109 28111 28123 28151 28163 28181 28183 28201 28211 28219 28229 28277 28279 28283 28289 28297 28307 28309 28319 28349 28351 28387 28393 28403 28409 28411 28429 28433 28439 28447 28463 28477 28493 28499 28513 28517 28537 28541 28547 28549 28559 28571 28573 28579 28591 28597 28603 28607 28619 28621 28627 28631 28643 28649 28657 28661 28663 28669 28687 28697 28703 28711 28723 28729 28751 28753 28759 28771 28789 28793 28807 28813 28817 28837 28843 28859 28867 28871 28879 28901 28909 28921 28927 28933 28949 28961 28979 29009 29017 29021 29023 29027 29033 29059 29063 29077 29101 29123 29129 29131 29137 29147 29153 29167 29173 29179 29191 29201 29207 29209 29221 29231 29243 29251 29269 29287 29297 29303 29311 29327 29333 29339 29347 29363 29383 29387 29389 29399 29401 29411 29423 29429 29437 29443 29453 29473 29483 29501 29527 29531 29537 29567 29569 29573 29581 29587 29599 29611 29629 29633 29641 29663 29669 29671 29683 29717 29723 29741 29753 29759 29761 29789 29803 29819 29833 29837 29851 29863 29867 29873 29879 29881 29917 29921 29927 29947 29959 29983 29989 30011 30013 30029 30047 30059 30071 30089 30091 30097 30103 30109 30113 30119 30133 30137 30139 30161 30169 30181 30187 30197 30203 30211 30223 30241 30253 30259 30269 30271 30293 30307 30313 30319 30323 30341 30347 30367 30389 30391 30403 30427 30431 30449 30467 30469 30491 30493 30497 30509 30517 30529 30539 30553 30557 30559 30577 30593 30631 30637 30643 30649 30661 30671 30677 30689 30697 30703 30707 30713 30727 30757 30763 30773 30781 30803 30809 30817 30829 30839 30841 30851 30853 30859 30869 30871 30881 30893 30911 30931 30937 30941 30949 30971 30977 30983 31013 31019 31033 31039 31051 31063 31069 31079 31081 31091 31121 31123 31139 31147 31151 31153 31159 31177 31181 31183 31189 31193 31219 31223 31231 31237 31247 31249 31253 31259 31267 31271 31277 31307 31319 31321 31327 31333 31337 31357 31379 31387 31391 31393 31397 31469 31477 31481 31489 31511 31513 31517 31531 31541 31543 31547 31567 31573 31583 31601 31607 31627 31643 31649 31657 31663 31667 31687 31699 31721 31723 31727 31729 31741 31751 31769 31771 31793 31799 31817 31847 31849 31859 31873 31883 31891 31907 31957 31963 31973 31981 31991 32003 32009 32027 32029 32051 32057 32059 32063 32069 32077 32083 32089 32099 32117 32119 32141 32143 32159 32173 32183 32189 32191 32203 32213 32233 32237 32251 32257 32261 32297 32299 32303 32309 32321 32323 32327 32341 32353 32359 32363 32369 32371 32377 32381 32401 32411 32413 32423 32429 32441 32443 32467 32479 32491 32497 32503 32507 32531 32533 32537 32561 32563 32569 32573 32579 32587 32603 32609 32611 32621 32633 32647 32653 32687 32693 32707 32713 32717 32719 32749 32771 32779 32783 32789 32797 32801 32803 32831 32833 32839 32843 32869 32887 32909 32911 32917 32933 32939 32941 32957 32969 32971 32983 32987 32993 32999 33013 33023 33029 33037 33049 33053 33071 33073 33083 33091 33107 33113 33119 33149 33151 33161 33179 33181 33191 33199 33203 33211 33223 33247 33287 33289 33301 33311 33317 33329 33331 33343 33347 33349 33353 33359 33377 33391 33403 33409 33413 33427 33457 33461 33469 33479 33487 33493 33503 33521 33529 33533 33547 33563 33569 33577 33581 33587 33589 33599 33601 33613 33617 33619 33623 33629 33637 33641 33647 33679 33703 33713 33721 33739 33749 33751 33757 33767 33769 33773 33791 33797 33809 33811 33827 33829 33851 33857 33863 33871 33889 33893 33911 33923 33931 33937 33941 33961 33967 33997 34019 34031 34033 34039 34057 34061 34123 34127 34129 34141 34147 34157 34159 34171 34183 34211 34213 34217 34231 34253 34259 34261 34267 34273 34283 34297 34301 34303 34313 34319 34327 34337 34351 34361 34367 34369 34381 34403 34421 34429 34439 34457 34469 34471 34483 34487 34499 34501 34511 34513 34519 34537 34543 34549 34583 34589 34591 34603 34607 34613 34631 34649 34651 34667 34673 34679 34687 34693 34703 34721 34729 34739 34747 34757 34759 34763 34781 34807 34819 34841 34843 34847 34849 34871 34877 34883 34897 34913 34919 34939 34949 34961 34963 34981 35023 35027 35051 35053 35059 35069 35081 35083 35089 35099 35107 35111 35117 35129 35141 35149 35153 35159 35171 35201 35221 35227 35251 35257 35267 35279 35281 35291 35311 35317 35323 35327 35339 35353 35363 35381 35393 35401 35407 35419 35423 35437 35447 35449 35461 35491 35507 35509 35521 35527 35531 35533 35537 35543 35569 35573 35591 35593 35597 35603 35617 35671 35677 35729 35731 35747 35753 35759 35771 35797 35801 35803 35809 35831 35837 35839 35851 35863 35869 35879 35897 35899 35911 35923 35933 35951 35963 35969 35977 35983 35993 35999 36007 36011 36013 36017 36037 36061 36067 36073 36083 36097 36107 36109 36131 36137 36151 36161 36187 36191 36209 36217 36229 36241 36251 36263 36269 36277 36293 36299 36307 36313 36319 36341 36343 36353 36373 36383 36389 36433 36451 36457 36467 36469 36473 36479 36493 36497 36523 36527 36529 36541 36551 36559 36563 36571 36583 36587 36599 36607 36629 36637 36643 36653 36671 36677 36683 36691 36697 36709 36713 36721 36739 36749 36761 36767 36779 36781 36787 36791 36793 36809 36821 36833 36847 36857 36871 36877 36887 36899 36901 36913 36919 36923 36929 36931 36943 36947 36973 36979 36997 37003 37013 37019 37021 37039 37049 37057 37061 37087 37097 37117 37123 37139 37159 37171 37181 37189 37199 37201 37217 37223 37243 37253 37273 37277 37307 37309 37313 37321 37337 37339 37357 37361 37363 37369 37379 37397 37409 37423 37441 37447 37463 37483 37489 37493 37501 37507 37511 37517 37529 37537 37547 37549 37561 37567 37571 37573 37579 37589 37591 37607 37619 37633 37643 37649 37657 37663 37691 37693 37699 37717 37747 37781 37783 37799 37811 37813 37831 37847 37853 37861 37871 37879 37889 37897 37907 37951 37957 37963 37967 37987 37991 37993 37997 38011 38039 38047 38053 38069 38083 38113 38119 38149 38153 38167 38177 38183 38189 38197 38201 38219 38231 38237 38239 38261 38273 38281 38287 38299 38303 38317 38321 38327 38329 38333 38351 38371 38377 38393 38431 38447 38449 38453 38459 38461 38501 38543 38557 38561 38567 38569 38593 38603 38609 38611 38629 38639 38651 38653 38669 38671 38677 38693 38699 38707 38711 38713 38723 38729 38737 38747 38749 38767 38783 38791 38803 38821 38833 38839 38851 38861 38867 38873 38891 38903 38917 38921 38923 38933 38953 38959 38971 38977 38993 39019 39023 39041 39043 39047 39079 39089 39097 39103 39107 39113 39119 39133 39139 39157 39161 39163 39181 39191 39199 39209 39217 39227 39229 39233 39239 39241 39251 39293 39301 39313 39317 39323 39341 39343 39359 39367 39371 39373 39383 39397 39409 39419 39439 39443 39451 39461 39499 39503 39509 39511 39521 39541 39551 39563 39569 39581 39607 39619 39623 39631 39659 39667 39671 39679 39703 39709 39719 39727 39733 39749 39761 39769 39779 39791 39799 39821 39827 39829 39839 39841 39847 39857 39863 39869 39877 39883 39887 39901 39929 39937 39953 39971 39979 39983 39989 40009 40013 40031 40037 40039 40063 40087 40093 40099 40111 40123 40127 40129 40151 40153 40163 40169 40177 40189 40193 40213 40231 40237 40241 40253 40277 40283 40289 40343 40351 40357 40361 40387 40423 40427 40429 40433 40459 40471 40483 40487 40493 40499 40507 40519 40529 40531 40543 40559 40577 40583 40591 40597 40609 40627 40637 40639 40693 40697 40699 40709 40739 40751 40759 40763 40771 40787 40801 40813 40819 40823 40829 40841 40847 40849 40853 40867 40879 40883 40897 40903 40927 40933 40939 40949 40961 40973 40993 41011 41017 41023 41039 41047 41051 41057 41077 41081 41113 41117 41131 41141 41143 41149 41161 41177 41179 41183 41189 41201 41203 41213 41221 41227 41231 41233 41243 41257 41263 41269 41281 41299 41333 41341 41351 41357 41381 41387 41389 41399 41411 41413 41443 41453 41467 41479 41491 41507 41513 41519 41521 41539 41543 41549 41579 41593 41597 41603 41609 41611 41617 41621 41627 41641 41647 41651 41659 41669 41681 41687 41719 41729 41737 41759 41761 41771 41777 41801 41809 41813 41843 41849 41851 41863 41879 41887 41893 41897 41903 41911 41927 41941 41947 41953 41957 41959 41969 41981 41983 41999 42013 42017 42019 42023 42043 42061 42071 42073 42083 42089 42101 42131 42139 42157 42169 42179 42181 42187 42193 42197 42209 42221 42223 42227 42239 42257 42281 42283 42293 42299 42307 42323 42331 42337 42349 42359 42373 42379 42391 42397 42403 42407 42409 42433 42437 42443 42451 42457 42461 42463 42467 42473 42487 42491 42499 42509 42533 42557 42569 42571 42577 42589 42611 42641 42643 42649 42667 42677 42683 42689 42697 42701 42703 42709 42719 42727 42737 42743 42751 42767 42773 42787 42793 42797 42821 42829 42839 42841 42853 42859 42863 42899 42901 42923 42929 42937 42943 42953 42961 42967 42979 42989 43003 43013 43019 43037 43049 43051 43063 43067 43093 43103 43117 43133 43151 43159 43177 43189 43201 43207 43223 43237 43261 43271 43283 43291 43313 43319 43321 43331 43391 43397 43399 43403 43411 43427 43441 43451 43457 43481 43487 43499 43517 43541 43543 43573 43577 43579 43591 43597 43607 43609 43613 43627 43633 43649 43651 43661 43669 43691 43711 43717 43721 43753 43759 43777 43781 43783 43787 43789 43793 43801 43853 43867 43889 43891 43913 43933 43943 43951 43961 43963 43969 43973 43987 43991 43997 44017 44021 44027 44029 44041 44053 44059 44071 44087 44089 44101 44111 44119 44123 44129 44131 44159 44171 44179 44189 44201 44203 44207 44221 44249 44257 44263 44267 44269 44273 44279 44281 44293 44351 44357 44371 44381 44383 44389 44417 44449 44453 44483 44491 44497 44501 44507 44519 44531 44533 44537 44543 44549 44563 44579 44587 44617 44621 44623 44633 44641 44647 44651 44657 44683 44687 44699 44701 44711 44729 44741 44753 44771 44773 44777 44789 44797 44809 44819 44839 44843 44851 44867 44879 44887 44893 44909 44917 44927 44939 44953 44959 44963 44971 44983 44987 45007 45013 45053 45061 45077 45083 45119 45121 45127 45131 45137 45139 45161 45179 45181 45191 45197 45233 45247 45259 45263 45281 45289 45293 45307 45317 45319 45329 45337 45341 45343 45361 45377 45389 45403 45413 45427 45433 45439 45481 45491 45497 45503 45523 45533 45541 45553 45557 45569 45587 45589 45599 45613 45631 45641 45659 45667 45673 45677 45691 45697 45707 45737 45751 45757 45763 45767 45779 45817 45821 45823 45827 45833 45841 45853 45863 45869 45887 45893 45943 45949 45953 45959 45971 45979 45989 46021 46027 46049 46051 46061 46073 46091 46093 46099 46103 46133 46141 46147 46153 46171 46181 46183 46187 46199 46219 46229 46237 46261 46271 46273 46279 46301 46307 46309 46327 46337 46349 46351 46381 46399 46411 46439 46441 46447 46451 46457 46471 46477 46489 46499 46507 46511 46523 46549 46559 46567 46573 46589 46591 46601 46619 46633 46639 46643 46649 46663 46679 46681 46687 46691 46703 46723 46727 46747 46751 46757 46769 46771 46807 46811 46817 46819 46829 46831 46853 46861 46867 46877 46889 46901 46919 46933 46957 46993 46997 47017 47041 47051 47057 47059 47087 47093 47111 47119 47123 47129 47137 47143 47147 47149 47161 47189 47207 47221 47237 47251 47269 47279 47287 47293 47297 47303 47309 47317 47339 47351 47353 47363 47381 47387 47389 47407 47417 47419 47431 47441 47459 47491 47497 47501 47507 47513 47521 47527 47533 47543 47563 47569 47581 47591 47599 47609 47623 47629 47639 47653 47657 47659 47681 47699 47701 47711 47713 47717 47737 47741 47743 47777 47779 47791 47797 47807 47809 47819 47837 47843 47857 47869 47881 47903 47911 47917 47933 47939 47947 47951 47963 47969 47977 47981 48017 48023 48029 48049 48073 48079 48091 48109 48119 48121 48131 48157 48163 48179 48187 48193 48197 48221 48239 48247 48259 48271 48281 48299 48311 48313 48337 48341 48353 48371 48383 48397 48407 48409 48413 48437 48449 48463 48473 48479 48481 48487 48491 48497 48523 48527 48533 48539 48541 48563 48571 48589 48593 48611 48619 48623 48647 48649 48661 48673 48677 48679 48731 48733 48751 48757 48761 48767 48779 48781 48787 48799 48809 48817 48821 48823 48847 48857 48859 48869 48871 48883 48889 48907 48947 48953 48973 48989 48991 49003 49009 49019 49031 49033 49037 49043 49057 49069 49081 49103 49109 49117 49121 49123 49139 49157 49169 49171 49177 49193 49199 49201 49207 49211 49223 49253 49261 49277 49279 49297 49307 49331 49333 49339 49363 49367 49369 49391 49393 49409 49411 49417 49429 49433 49451 49459 49463 49477 49481 49499 49523 49529 49531 49537 49547 49549 49559 49597 49603 49613 49627 49633 49639 49663 49667 49669 49681 49697 49711 49727 49739 49741 49747 49757 49783 49787 49789 49801 49807 49811 49823 49831 49843 49853 49871 49877 49891 49919 49921 49927 49937 49939 49943 49957 49991 49993 49999 50021 50023 50033 50047 50051 50053 50069 50077 50087 50093 50101 50111 50119 50123 50129 50131 50147 50153 50159 50177 50207 50221 50227 50231 50261 50263 50273 50287 50291 50311 50321 50329 50333 50341 50359 50363 50377 50383 50387 50411 50417 50423 50441 50459 50461 50497 50503 50513 50527 50539 50543 50549 50551 50581 50587 50591 50593 50599 50627 50647 50651 50671 50683 50707 50723 50741 50753 50767 50773 50777 50789 50821 50833 50839 50849 50857 50867 50873 50891 50893 50909 50923 50929 50951 50957 50969 50971 50989 50993 51001 51031 51043 51047 51059 51061 51071 51109 51131 51133 51137 51151 51157 51169 51193 51197 51199 51203 51217 51229 51239 51241 51257 51263 51283 51287 51307 51329 51341 51343 51347 51349 51361 51383 51407 51413 51419 51421 51427 51431 51437 51439 51449 51461 51473 51479 51481 51487 51503 51511 51517 51521 51539 51551 51563 51577 51581 51593 51599 51607 51613 51631 51637 51647 51659 51673 51679 51683 51691 51713 51719 51721 51749 51767 51769 51787 51797 51803 51817 51827 51829 51839 51853 51859 51869 51871 51893 51899 51907 51913 51929 51941 51949 51971 51973 51977 51991 52009 52021 52027 52051 52057 52067 52069 52081 52103 52121 52127 52147 52153 52163 52177 52181 52183 52189 52201 52223 52237 52249 52253 52259 52267 52289 52291 52301 52313 52321 52361 52363 52369 52379 52387 52391 52433 52453 52457 52489 52501 52511 52517 52529 52541 52543 52553 52561 52567 52571 52579 52583 52609 52627 52631 52639 52667 52673 52691 52697 52709 52711 52721 52727 52733 52747 52757 52769 52783 52807 52813 52817 52837 52859 52861 52879 52883 52889 52901 52903 52919 52937 52951 52957 52963 52967 52973 52981 52999 53003 53017 53047 53051 53069 53077 53087 53089 53093 53101 53113 53117 53129 53147 53149 53161 53171 53173 53189 53197 53201 53231 53233 53239 53267 53269 53279 53281 53299 53309 53323 53327 53353 53359 53377 53381 53401 53407 53411 53419 53437 53441 53453 53479 53503 53507 53527 53549 53551 53569 53591 53593 53597 53609 53611 53617 53623 53629 53633 53639 53653 53657 53681 53693 53699 53717 53719 53731 53759 53773 53777 53783 53791 53813 53819 53831 53849 53857 53861 53881 53887 53891 53897 53899 53917 53923 53927 53939 53951 53959 53987 53993 54001 54011 54013 54037 54049 54059 54083 54091 54101 54121 54133 54139 54151 54163 54167 54181 54193 54217 54251 54269 54277 54287 54293 54311 54319 54323 54331 54347 54361 54367 54371 54377 54401 54403 54409 54413 54419 54421 54437 54443 54449 54469 54493 54497 54499 54503 54517 54521 54539 54541 54547 54559 54563 54577 54581 54583 54601 54617 54623 54629 54631 54647 54667 54673 54679 54709 54713 54721 54727 54751 54767 54773 54779 54787 54799 54829 54833 54851 54869 54877 54881 54907 54917 54919 54941 54949 54959 54973 54979 54983 55001 55009 55021 55049 55051 55057 55061 55073 55079 55103 55109 55117 55127 55147 55163 55171 55201 55207 55213 55217 55219 55229 55243 55249 55259 55291 55313 55331 55333 55337 55339 55343 55351 55373 55381 55399 55411 55439 55441 55457 55469 55487 55501 55511 55529 55541 55547 55579 55589 55603 55609 55619 55621 55631 55633 55639 55661 55663 55667 55673 55681 55691 55697 55711 55717 55721 55733 55763 55787 55793 55799 55807 55813 55817 55819 55823 55829 55837 55843 55849 55871 55889 55897 55901 55903 55921 55927 55931 55933 55949 55967 55987 55997 56003 56009 56039 56041 56053 56081 56087 56093 56099 56101 56113 56123 56131 56149 56167 56171 56179 56197 56207 56209 56237 56239 56249 56263 56267 56269 56299 56311 56333 56359 56369 56377 56383 56393 56401 56417 56431 56437 56443 56453 56467 56473 56477 56479 56489 56501 56503 56509 56519 56527 56531 56533 56543 56569 56591 56597 56599 56611 56629 56633 56659 56663 56671 56681 56687 56701 56711 56713 56731 56737 56747 56767 56773 56779 56783 56807 56809 56813 56821 56827 56843 56857 56873 56891 56893 56897 56909 56911 56921 56923 56929 56941 56951 56957 56963 56983 56989 56993 56999 57037 57041 57047 57059 57073 57077 57089 57097 57107 57119 57131 57139 57143 57149 57163 57173 57179 57191 57193 57203 57221 57223 57241 57251 57259 57269 57271 57283 57287 57301 57329 57331 57347 57349 57367 57373 57383 57389 57397 57413 57427 57457 57467 57487 57493 57503 57527 57529 57557 57559 57571 57587 57593 57601 57637 57641 57649 57653 57667 57679 57689 57697 57709 57713 57719 57727 57731 57737 57751 57773 57781 57787 57791 57793 57803 57809 57829 57839 57847 57853 57859 57881 57899 57901 57917 57923 57943 57947 57973 57977 57991 58013 58027 58031 58043 58049 58057 58061 58067 58073 58099 58109 58111 58129 58147 58151 58153 58169 58171 58189 58193 58199 58207 58211 58217 58229 58231 58237 58243 58271 58309 58313 58321 58337 58363 58367 58369 58379 58391 58393 58403 58411 58417 58427 58439 58441 58451 58453 58477 58481 58511 58537 58543 58549 58567 58573 58579 58601 58603 58613 58631 58657 58661 58679 58687 58693 58699 58711 58727 58733 58741 58757 58763 58771 58787 58789 58831 58889 58897 58901 58907 58909 58913 58921 58937 58943 58963 58967 58979 58991 58997 59009 59011 59021 59023 59029 59051 59053 59063 59069 59077 59083 59093 59107 59113 59119 59123 59141 59149 59159 59167 59183 59197 59207 59209 59219 59221 59233 59239 59243 59263 59273 59281 59333 59341 59351 59357 59359 59369 59377 59387 59393 59399 59407 59417 59419 59441 59443 59447 59453 59467 59471 59473 59497 59509 59513 59539 59557 59561 59567 59581 59611 59617 59621 59627 59629 59651 59659 59663 59669 59671 59693 59699 59707 59723 59729 59743 59747 59753 59771 59779 59791 59797 59809 59833 59863 59879 59887 59921 59929 59951 59957 59971 59981 59999 60013 60017 60029 60037 60041 60077 60083 60089 60091 60101 60103 60107 60127 60133 60139 60149 60161 60167 60169 60209 60217 60223 60251 60257 60259 60271 60289 60293 60317 60331 60337 60343 60353 60373 60383 60397 60413 60427 60443 60449 60457 60493 60497 60509 60521 60527 60539 60589 60601 60607 60611 60617 60623 60631 60637 60647 60649 60659 60661 60679 60689 60703 60719 60727 60733 60737 60757 60761 60763 60773 60779 60793 60811 60821 60859 60869 60887 60889 60899 60901 60913 60917 60919 60923 60937 60943 60953 60961 61001 61007 61027 61031 61043 61051 61057 61091 61099 61121 61129 61141 61151 61153 61169 61211 61223 61231 61253 61261 61283 61291 61297 61331 61333 61339 61343 61357 61363 61379 61381 61403 61409 61417 61441 61463 61469 61471 61483 61487 61493 61507 61511 61519 61543 61547 61553 61559 61561 61583 61603 61609 61613 61627 61631 61637 61643 61651 61657 61667 61673 61681 61687 61703 61717 61723 61729 61751 61757 61781 61813 61819 61837 61843 61861 61871 61879 61909 61927 61933 61949 61961 61967 61979 61981 61987 61991 62003 62011 62017 62039 62047 62053 62057 62071 62081 62099 62119 62129 62131 62137 62141 62143 62171 62189 62191 62201 62207 62213 62219 62233 62273 62297 62299 62303 62311 62323 62327 62347 62351 62383 62401 62417 62423 62459 62467 62473 62477 62483 62497 62501 62507 62533 62539 62549 62563 62581 62591 62597 62603 62617 62627 62633 62639 62653 62659 62683 62687 62701 62723 62731 62743 62753 62761 62773 62791 62801 62819 62827 62851 62861 62869 62873 62897 62903 62921 62927 62929 62939 62969 62971 62981 62983 62987 62989 63029 63031 63059 63067 63073 63079 63097 63103 63113 63127 63131 63149 63179 63197 63199 63211 63241 63247 63277 63281 63299 63311 63313 63317 63331 63337 63347 63353 63361 63367 63377 63389 63391 63397 63409 63419 63421 63439 63443 63463 63467 63473 63487 63493 63499 63521 63527 63533 63541 63559 63577 63587 63589 63599 63601 63607 63611 63617 63629 63647 63649 63659 63667 63671 63689 63691 63697 63703 63709 63719 63727 63737 63743 63761 63773 63781 63793 63799 63803 63809 63823 63839 63841 63853 63857 63863 63901 63907 63913 63929 63949 63977 63997 64007 64013 64019 64033 64037 64063 64067 64081 64091 64109 64123 64151 64153 64157 64171 64187 64189 64217 64223 64231 64237 64271 64279 64283 64301 64303 64319 64327 64333 64373 64381 64399 64403 64433 64439 64451 64453 64483 64489 64499 64513 64553 64567 64577 64579 64591 64601 64609 64613 64621 64627 64633 64661 64663 64667 64679 64693 64709 64717 64747 64763 64781 64783 64793 64811 64817 64849 64853 64871 64877 64879 64891 64901 64919 64921 64927 64937 64951 64969 64997 65003 65011 65027 65029 65033 65053 65063 65071 65089 65099 65101 65111 65119 65123 65129 65141 65147 65167 65171 65173 65179 65183 65203 65213 65239 65257 65267 65269 65287 65293 65309 65323 65327 65353 65357 65371 65381 65393 65407 65413 65419 65423 65437 65447 65449 65479 65497 65519 65521 65537 65539 65543 65551 65557 65563 65579 65581 65587 65599 65609 65617 65629 65633 65647 65651 65657 65677 65687 65699 65701 65707 65713 65717 65719 65729 65731 65761 65777 65789 65809 65827 65831 65837 65839 65843 65851 65867 65881 65899 65921 65927 65929 65951 65957 65963 65981 65983 65993 66029 66037 66041 66047 66067 66071 66083 66089 66103 66107 66109 66137 66161 66169 66173 66179 66191 66221 66239 66271 66293 66301 66337 66343 66347 66359 66361 66373 66377 66383 66403 66413 66431 66449 66457 66463 66467 66491 66499 66509 66523 66529 66533 66541 66553 66569 66571 66587 66593 66601 66617 66629 66643 66653 66683 66697 66701 66713 66721 66733 66739 66749 66751 66763 66791 66797 66809 66821 66841 66851 66853 66863 66877 66883 66889 66919 66923 66931 66943 66947 66949 66959 66973 66977 67003 67021 67033 67043 67049 67057 67061 67073 67079 67103 67121 67129 67139 67141 67153 67157 67169 67181 67187 67189 67211 67213 67217 67219 67231 67247 67261 67271 67273 67289 67307 67339 67343 67349 67369 67391 67399 67409 67411 67421 67427 67429 67433 67447 67453 67477 67481 67489 67493 67499 67511 67523 67531 67537 67547 67559 67567 67577 67579 67589 67601 67607 67619 67631 67651 67679 67699 67709 67723 67733 67741 67751 67757 67759 67763 67777 67783 67789 67801 67807 67819 67829 67843 67853 67867 67883 67891 67901 67927 67931 67933 67939 67943 67957 67961 67967 67979 67987 67993 68023 68041 68053 68059 68071 68087 68099 68111 68113 68141 68147 68161 68171 68207 68209 68213 68219 68227 68239 68261 68279 68281 68311 68329 68351 68371 68389 68399 68437 68443 68447 68449 68473 68477 68483 68489 68491 68501 68507 68521 68531 68539 68543 68567 68581 68597 68611 68633 68639 68659 68669 68683 68687 68699 68711 68713 68729 68737 68743 68749 68767 68771 68777 68791 68813 68819 68821 68863 68879 68881 68891 68897 68899 68903 68909 68917 68927 68947 68963 68993 69001 69011 69019 69029 69031 69061 69067 69073 69109 69119 69127 69143 69149 69151 69163 69191 69193 69197 69203 69221 69233 69239 69247 69257 69259 69263 69313 69317 69337 69341 69371 69379 69383 69389 69401 69403 69427 69431 69439 69457 69463 69467 69473 69481 69491 69493 69497 69499 69539 69557 69593 69623 69653 69661 69677 69691 69697 69709 69737 69739 69761 69763 69767 69779 69809 69821 69827 69829 69833 69847 69857 69859 69877 69899 69911 69929 69931 69941 69959 69991 69997 70001 70003 70009 70019 70039 70051 70061 70067 70079 70099 70111 70117 70121 70123 70139 70141 70157 70163 70177 70181 70183 70199 70201 70207 70223 70229 70237 70241 70249 70271 70289 70297 70309 70313 70321 70327 70351 70373 70379 70381 70393 70423 70429 70439 70451 70457 70459 70481 70487 70489 70501 70507 70529 70537 70549 70571 70573 70583 70589 70607 70619 70621 70627 70639 70657 70663 70667 70687 70709 70717 70729 70753 70769 70783 70793 70823 70841 70843 70849 70853 70867 70877 70879 70891 70901 70913 70919 70921 70937 70949 70951 70957 70969 70979 70981 70991 70997 70999 71011 71023 71039 71059 71069 71081 71089 71119 71129 71143 71147 71153 71161 71167 71171 71191 71209 71233 71237 71249 71257 71261 71263 71287 71293 71317 71327 71329 71333 71339 71341 71347 71353 71359 71363 71387 71389 71399 71411 71413 71419 71429 71437 71443 71453 71471 71473 71479 71483 71503 71527 71537 71549 71551 71563 71569 71593 71597 71633 71647 71663 71671 71693 71699 71707 71711 71713 71719 71741 71761 71777 71789 71807 71809 71821 71837 71843 71849 71861 71867 71879 71881 71887 71899 71909 71917 71933 71941 71947 71963 71971 71983 71987 71993 71999 72019 72031 72043 72047 72053 72073 72077 72089 72091 72101 72103 72109 72139 72161 72167 72169 72173 72211 72221 72223 72227 72229 72251 72253 72269 72271 72277 72287 72307 72313 72337 72341 72353 72367 72379 72383 72421 72431 72461 72467 72469 72481 72493 72497 72503 72533 72547 72551 72559 72577 72613 72617 72623 72643 72647 72649 72661 72671 72673 72679 72689 72701 72707 72719 72727 72733 72739 72763 72767 72797 72817 72823 72859 72869 72871 72883 72889 72893 72901 72907 72911 72923 72931 72937 72949 72953 72959 72973 72977 72997 73009 73013 73019 73037 73039 73043 73061 73063 73079 73091 73121 73127 73133 73141 73181 73189 73237 73243 73259 73277 73291 73303 73309 73327 73331 73351 73361 73363 73369 73379 73387 73417 73421 73433 73453 73459 73471 73477 73483 73517 73523 73529 73547 73553 73561 73571 73583 73589 73597 73607 73609 73613 73637 73643 73651 73673 73679 73681 73693 73699 73709 73721 73727 73751 73757 73771 73783 73819 73823 73847 73849 73859 73867 73877 73883 73897 73907 73939 73943 73951 73961 73973 73999 74017 74021 74027 74047 74051 74071 74077 74093 74099 74101 74131 74143 74149 74159 74161 74167 74177 74189 74197 74201 74203 74209 74219 74231 74257 74279 74287 74293 74297 74311 74317 74323 74353 74357 74363 74377 74381 74383 74411 74413 74419 74441 74449 74453 74471 74489 74507 74509 74521 74527 74531 74551 74561 74567 74573 74587 74597 74609 74611 74623 74653 74687 74699 74707 74713 74717 74719 74729 74731 74747 74759 74761 74771 74779 74797 74821 74827 74831 74843 74857 74861 74869 74873 74887 74891 74897 74903 74923 74929 74933 74941 74959 75011 75013 75017 75029 75037 75041 75079 75083 75109 75133 75149 75161 75167 75169 75181 75193 75209 75211 75217 75223 75227 75239 75253 75269 75277 75289 75307 75323 75329 75337 75347 75353 75367 75377 75389 75391 75401 75403 75407 75431 75437 75479 75503 75511 75521 75527 75533 75539 75541 75553 75557 75571 75577 75583 75611 75617 75619 75629 75641 75653 75659 75679 75683 75689 75703 75707 75709 75721 75731 75743 75767 75773 75781 75787 75793 75797 75821 75833 75853 75869 75883 75913 75931 75937 75941 75967 75979 75983 75989 75991 75997 76001 76003 76031 76039 76079 76081 76091 76099 76103 76123 76129 76147 76157 76159 76163 76207 76213 76231 76243 76249 76253 76259 76261 76283 76289 76303 76333 76343 76367 76369 76379 76387 76403 76421 76423 76441 76463 76471 76481 76487 76493 76507 76511 76519 76537 76541 76543 76561 76579 76597 76603 76607 76631 76649 76651 76667 76673 76679 76697 76717 76733 76753 76757 76771 76777 76781 76801 76819 76829 76831 76837 76847 76871 76873 76883 76907 76913 76919 76943 76949 76961 76963 76991 77003 77017 77023 77029 77041 77047 77069 77081 77093 77101 77137 77141 77153 77167 77171 77191 77201 77213 77237 77239 77243 77249 77261 77263 77267 77269 77279 77291 77317 77323 77339 77347 77351 77359 77369 77377 77383 77417 77419 77431 77447 77471 77477 77479 77489 77491 77509 77513 77521 77527 77543 77549 77551 77557 77563 77569 77573 77587 77591 77611 77617 77621 77641 77647 77659 77681 77687 77689 77699 77711 77713 77719 77723 77731 77743 77747 77761 77773 77783 77797 77801 77813 77839 77849 77863 77867 77893 77899 77929 77933 77951 77969 77977 77983 77999 78007 78017 78031 78041 78049 78059 78079 78101 78121 78137 78139 78157 78163 78167 78173 78179 78191 78193 78203 78229 78233 78241 78259 78277 78283 78301 78307 78311 78317 78341 78347 78367 78401 78427 78437 78439 78467 78479 78487 78497 78509 78511 78517 78539 78541 78553 78569 78571 78577 78583 78593 78607 78623 78643 78649 78653 78691 78697 78707 78713 78721 78737 78779 78781 78787 78791 78797 78803 78809 78823 78839 78853 78857 78877 78887 78889 78893 78901 78919 78929 78941 78977 78979 78989 79031 79039 79043 79063 79087 79103 79111 79133 79139 79147 79151 79153 79159 79181 79187 79193 79201 79229 79231 79241 79259 79273 79279 79283 79301 79309 79319 79333 79337 79349 79357 79367 79379 79393 79397 79399 79411 79423 79427 79433 79451 79481 79493 79531 79537 79549 79559 79561 79579 79589 79601 79609 79613 79621 79627 79631 79633 79657 79669 79687 79691 79693 79697 79699 79757 79769 79777 79801 79811 79813 79817 79823 79829 79841 79843 79847 79861 79867 79873 79889 79901 79903 79907 79939 79943 79967 79973 79979 79987 79997 79999 80021 80039 80051 80071 80077 80107 80111 80141 80147 80149 80153 80167 80173 80177 80191 80207 80209 80221 80231 80233 80239 80251 80263 80273 80279 80287 80309 80317 80329 80341 80347 80363 80369 80387 80407 80429 80447 80449 80471 80473 80489 80491 80513 80527 80537 80557 80567 80599 80603 80611 80621 80627 80629 80651 80657 80669 80671 80677 80681 80683 80687 80701 80713 80737 80747 80749 80761 80777 80779 80783 80789 80803 80809 80819 80831 80833 80849 80863 80897 80909 80911 80917 80923 80929 80933 80953 80963 80989 81001 81013 81017 81019 81023 81031 81041 81043 81047 81049 81071 81077 81083 81097 81101 81119 81131 81157 81163 81173 81181 81197 81199 81203 81223 81233 81239 81281 81283 81293 81299 81307 81331 81343 81349 81353 81359 81371 81373 81401 81409 81421 81439 81457 81463 81509 81517 81527 81533 81547 81551 81553 81559 81563 81569 81611 81619 81629 81637 81647 81649 81667 81671 81677 81689 81701 81703 81707 81727 81737 81749 81761 81769 81773 81799 81817 81839 81847 81853 81869 81883 81899 81901 81919 81929 81931 81937 81943 81953 81967 81971 81973 82003 82007 82009 82013 82021 82031 82037 82039 82051 82067 82073 82129 82139 82141 82153 82163 82171 82183 82189 82193 82207 82217 82219 82223 82231 82237 82241 82261 82267 82279 82301 82307 82339 82349 82351 82361 82373 82387 82393 82421 82457 82463 82469 82471 82483 82487 82493 82499 82507 82529 82531 82549 82559 82561 82567 82571 82591 82601 82609 82613 82619 82633 82651 82657 82699 82721 82723 82727 82729 82757 82759 82763 82781 82787 82793 82799 82811 82813 82837 82847 82883 82889 82891 82903 82913 82939 82963 82981 82997 83003 83009 83023 83047 83059 83063 83071 83077 83089 83093 83101 83117 83137 83177 83203 83207 83219 83221 83227 83231 83233 83243 83257 83267 83269 83273 83299 83311 83339 83341 83357 83383 83389 83399 83401 83407 83417 83423 83431 83437 83443 83449 83459 83471 83477 83497 83537 83557 83561 83563 83579 83591 83597 83609 83617 83621 83639 83641 83653 83663 83689 83701 83717 83719 83737 83761 83773 83777 83791 83813 83833 83843 83857 83869 83873 83891 83903 83911 83921 83933 83939 83969 83983 83987 84011 84017 84047 84053 84059 84061 84067 84089 84121 84127 84131 84137 84143 84163 84179 84181 84191 84199 84211 84221 84223 84229 84239 84247 84263 84299 84307 84313 84317 84319 84347 84349 84377 84389 84391 84401 84407 84421 84431 84437 84443 84449 84457 84463 84467 84481 84499 84503 84509 84521 84523 84533 84551 84559 84589 84629 84631 84649 84653 84659 84673 84691 84697 84701 84713 84719 84731 84737 84751 84761 84787 84793 84809 84811 84827 84857 84859 84869 84871 84913 84919 84947 84961 84967 84977 84979 84991 85009 85021 85027 85037 85049 85061 85081 85087 85091 85093 85103 85109 85121 85133 85147 85159 85193 85199 85201 85213 85223 85229 85237 85243 85247 85259 85297 85303 85313 85331 85333 85361 85363 85369 85381 85411 85427 85429 85439 85447 85451 85453 85469 85487 85513 85517 85523 85531 85549 85571 85577 85597 85601 85607 85619 85621 85627 85639 85643 85661 85667 85669 85691 85703 85711 85717 85733 85751 85781 85793 85817 85819 85829 85831 85837 85843 85847 85853 85889 85903 85909 85931 85933 85991 85999 86011 86017 86027 86029 86069 86077 86083 86111 86113 86117 86131 86137 86143 86161 86171 86179 86183 86197 86201 86209 86239 86243 86249 86257 86263 86269 86287 86291 86293 86297 86311 86323 86341 86351 86353 86357 86369 86371 86381 86389 86399 86413 86423 86441 86453 86461 86467 86477 86491 86501 86509 86531 86533 86539 86561 86573 86579 86587 86599 86627 86629 86677 86689 86693 86711 86719 86729 86743 86753 86767 86771 86783 86813 86837 86843 86851 86857 86861 86869 86923 86927 86929 86939 86951 86959 86969 86981 86993 87011 87013 87037 87041 87049 87071 87083 87103 87107 87119 87121 87133 87149 87151 87179 87181 87187 87211 87221 87223 87251 87253 87257 87277 87281 87293 87299 87313 87317 87323 87337 87359 87383 87403 87407 87421 87427 87433 87443 87473 87481 87491 87509 87511 87517 87523 87539 87541 87547 87553 87557 87559 87583 87587 87589 87613 87623 87629 87631 87641 87643 87649 87671 87679 87683 87691 87697 87701 87719 87721 87739 87743 87751 87767 87793 87797 87803 87811 87833 87853 87869 87877 87881 87887 87911 87917 87931 87943 87959 87961 87973 87977 87991 88001 88003 88007 88019 88037 88069 88079 88093 88117 88129 88169 88177 88211 88223 88237 88241 88259 88261 88289 88301 88321 88327 88337 88339 88379 88397 88411 88423 88427 88463 88469 88471 88493 88499 88513 88523 88547 88589 88591 88607 88609 88643 88651 88657 88661 88663 88667 88681 88721 88729 88741 88747 88771 88789 88793 88799 88801 88807 88811 88813 88817 88819 88843 88853 88861 88867 88873 88883 88897 88903 88919 88937 88951 88969 88993 88997 89003 89009 89017 89021 89041 89051 89057 89069 89071 89083 89087 89101 89107 89113 89119 89123 89137 89153 89189 89203 89209 89213 89227 89231 89237 89261 89269 89273 89293 89303 89317 89329 89363 89371 89381 89387 89393 89399 89413 89417 89431 89443 89449 89459 89477 89491 89501 89513 89519 89521 89527 89533 89561 89563 89567 89591 89597 89599 89603 89611 89627 89633 89653 89657 89659 89669 89671 89681 89689 89753 89759 89767 89779 89783 89797 89809 89819 89821 89833 89839 89849 89867 89891 89897 89899 89909 89917 89923 89939 89959 89963 89977 89983 89989 90001 90007 90011 90017 90019 90023 90031 90053 90059 90067 90071 90073 90089 90107 90121 90127 90149 90163 90173 90187 90191 90197 90199 90203 90217 90227 90239 90247 90263 90271 90281 90289 90313 90353 90359 90371 90373 90379 90397 90401 90403 90407 90437 90439 90469 90473 90481 90499 90511 90523 90527 90529 90533 90547 90583 90599 90617 90619 90631 90641 90647 90659 90677 90679 90697 90703 90709 90731 90749 90787 90793 90803 90821 90823 90833 90841 90847 90863 90887 90901 90907 90911 90917 90931 90947 90971 90977 90989 90997 91009 91019 91033 91079 91081 91097 91099 91121 91127 91129 91139 91141 91151 91153 91159 91163 91183 91193 91199 91229 91237 91243 91249 91253 91283 91291 91297 91303 91309 91331 91367 91369 91373 91381 91387 91393 91397 91411 91423 91433 91453 91457 91459 91463 91493 91499 91513 91529 91541 91571 91573 91577 91583 91591 91621 91631 91639 91673 91691 91703 91711 91733 91753 91757 91771 91781 91801 91807 91811 91813 91823 91837 91841 91867 91873 91909 91921 91939 91943 91951 91957 91961 91967 91969 91997 92003 92009 92033 92041 92051 92077 92083 92107 92111 92119 92143 92153 92173 92177 92179 92189 92203 92219 92221 92227 92233 92237 92243 92251 92269 92297 92311 92317 92333 92347 92353 92357 92363 92369 92377 92381 92383 92387 92399 92401 92413 92419 92431 92459 92461 92467 92479 92489 92503 92507 92551 92557 92567 92569 92581 92593 92623 92627 92639 92641 92647 92657 92669 92671 92681 92683 92693 92699 92707 92717 92723 92737 92753 92761 92767 92779 92789 92791 92801 92809 92821 92831 92849 92857 92861 92863 92867 92893 92899 92921 92927 92941 92951 92957 92959 92987 92993 93001 93047 93053 93059 93077 93083 93089 93097 93103 93113 93131 93133 93139 93151 93169 93179 93187 93199 93229 93239 93241 93251 93253 93257 93263 93281 93283 93287 93307 93319 93323 93329 93337 93371 93377 93383 93407 93419 93427 93463 93479 93481 93487 93491 93493 93497 93503 93523 93529 93553 93557 93559 93563 93581 93601 93607 93629 93637 93683 93701 93703 93719 93739 93761 93763 93787 93809 93811 93827 93851 93871 93887 93889 93893 93901 93911 93913 93923 93937 93941 93949 93967 93971 93979 93983 93997 94007 94009 94033 94049 94057 94063 94079 94099 94109 94111 94117 94121 94151 94153 94169 94201 94207 94219 94229 94253 94261 94273 94291 94307 94309 94321 94327 94331 94343 94349 94351 94379 94397 94399 94421 94427 94433 94439 94441 94447 94463 94477 94483 94513 94529 94531 94541 94543 94547 94559 94561 94573 94583 94597 94603 94613 94621 94649 94651 94687 94693 94709 94723 94727 94747 94771 94777 94781 94789 94793 94811 94819 94823 94837 94841 94847 94849 94873 94889 94903 94907 94933 94949 94951 94961 94993 94999 95003 95009 95021 95027 95063 95071 95083 95087 95089 95093 95101 95107 95111 95131 95143 95153 95177 95189 95191 95203 95213 95219 95231 95233 95239 95257 95261 95267 95273 95279 95287 95311 95317 95327 95339 95369 95383 95393 95401 95413 95419 95429 95441 95443 95461 95467 95471 95479 95483 95507 95527 95531 95539 95549 95561 95569 95581 95597 95603 95617 95621 95629 95633 95651 95701 95707 95713 95717 95723 95731 95737 95747 95773 95783 95789 95791 95801 95803 95813 95819 95857 95869 95873 95881 95891 95911 95917 95923 95929 95947 95957 95959 95971 95987 95989 96001 96013 96017 96043 96053 96059 96079 96097 96137 96149 96157 96167 96179 96181 96199 96211 96221 96223 96233 96259 96263 96269 96281 96289 96293 96323 96329 96331 96337 96353 96377 96401 96419 96431 96443 96451 96457 96461 96469 96479 96487 96493 96497 96517 96527 96553 96557 96581 96587 96589 96601 96643 96661 96667 96671 96697 96703 96731 96737 96739 96749 96757 96763 96769 96779 96787 96797 96799 96821 96823 96827 96847 96851 96857 96893 96907 96911 96931 96953 96959 96973 96979 96989 96997 97001 97003 97007 97021 97039 97073 97081 97103 97117 97127 97151 97157 97159 97169 97171 97177 97187 97213 97231 97241 97259 97283 97301 97303 97327 97367 97369 97373 97379 97381 97387 97397 97423 97429 97441 97453 97459 97463 97499 97501 97511 97523 97547 97549 97553 97561 97571 97577 97579 97583 97607 97609 97613 97649 97651 97673 97687 97711 97729 97771 97777 97787 97789 97813 97829 97841 97843 97847 97849 97859 97861 97871 97879 97883 97919 97927 97931 97943 97961 97967 97973 97987 98009 98011 98017 98041 98047 98057 98081 98101 98123 98129 98143 98179 98207 98213 98221 98227 98251 98257 98269 98297 98299 98317 98321 98323 98327 98347 98369 98377 98387 98389 98407 98411 98419 98429 98443 98453 98459 98467 98473 98479 98491 98507 98519 98533 98543 98561 98563 98573 98597 98621 98627 98639 98641 98663 98669 98689 98711 98713 98717 98729 98731 98737 98773 98779 98801 98807 98809 98837 98849 98867 98869 98873 98887 98893 98897 98899 98909 98911 98927 98929 98939 98947 98953 98963 98981 98993 98999 99013 99017 99023 99041 99053 99079 99083 99089 99103 99109 99119 99131 99133 99137 99139 99149 99173 99181 99191 99223 99233 99241 99251 99257 99259 99277 99289 99317 99347 99349 99367 99371 99377 99391 99397 99401 99409 99431 99439 99469 99487 99497 99523 99527 99529 99551 99559 99563 99571 99577 99581 99607 99611 99623 99643 99661 99667 99679 99689 99707 99709 99713 99719 99721 99733 99761 99767 99787 99793 99809 99817 99823 99829 99833 99839 99859 99871 99877 99881 99901 99907 99923 99929 99961 99971 99989 99991\".split(\" \");\n\nfor(i = 4; ;i++){\n\tif( primes.some(function(number){return (number == i) ? true : false}) ){\n\t\tcontinue;\n\t}\n\telse if( primes.some(function(number){return (number == (n-i)) ? true : false}) ){\n\t\tcontinue;\n\t}\n\telse{\n\t\twrite(i + \" \" + (n-i));\n\t\tbreak;\n\t}\n}"}, {"source_code": "function primToN(n){\n\tvar answer = [2];\n\n\tfor(j = 3; j <= n; j++){\n\t\tif( answer.every(function(number){return (j%number != 0) ? true : false}) ){\n\t\t\tanswer.push(j);\n\t\t}\n\t}\n\tj = undefined, number = undefined;\n\treturn answer;\n}\n\nvar n = +readline(), primes = primToN( (n < 100) ? n : 100 );\n\nfor(i = 4; ;i++){\n\tif( primes.some(function(number){return (number == i) ? true : false}) ){\n\t\tcontinue;\n\t}\n\telse if( primes.some(function(number){return (number == (n-i)) ? true : false}) ){\n\t\tcontinue;\n\t}\n\telse{\n\t\twrite(i + \" \" + (n-i));\n\t\tbreak;\n\t}\n}"}, {"source_code": "var r = +readline();\n\nif(r % 2 == 0){\n\tprint(r / 2 + \" \" + r / 2);\n}else if (r % 2 != 0){\n\tvar first_num = Math.floor((r / 3) + 1);\n\tvar sec_num = Math.floor(r - first_num);\n\tprint(first_num + \" \" + sec_num);\n}"}, {"source_code": "var r = +readline();\n\nif(r % 2 == 0){\n\tvar odd = r - 1;\n\tvar first_num = Math.floor((odd / 3) + 1);\n\tvar sec_num = Math.floor(r - first_num);\n \tprint(first_num + \" \" + sec_num);\n}else if (r % 2 != 0){\n\tvar first_num = Math.floor((r / 3) + 1);\n\tvar sec_num = Math.floor(r - first_num);\n\tprint(first_num + \" \" + sec_num);\n}"}, {"source_code": "var r = +readline();\n\nif(r % 2 == 0){\n\tvar first_num = Math.floor(r - 4);\n\tvar sec_num = Math.floor(r - first_num);\n \tprint(sec_num + \" \" + first_num);\n}else if (r % 2 != 0){\n\tvar first_num = Math.floor((r / 3) + 1);\n\tvar sec_num = Math.floor(r - first_num);\n\tprint(first_num + \" \" + sec_num);\n}"}, {"source_code": "var r = +readline();\n\nif(r % 2 == 0){\n\tvar odd = r - 1;\n\tvar first_num = Math.floor((odd / 3) + 1);\n\tvar sec_num = Math.floor(odd - first_num);\n \tprint(first_num + \" \" + sec_num);\n}else if (r % 2 != 0){\n\tvar first_num = Math.floor((r / 3) + 1);\n\tvar sec_num = Math.floor(r - first_num);\n\tprint(first_num + \" \" + sec_num);\n}"}, {"source_code": "var numbers = parseInt(readline());\nif(numbers % 2 == 1){\n print(9, numbers - 9);\n} else {\n var half = numbers / 2;\n print(half, half);\n}\n"}, {"source_code": "var numbers = parseInt(readline());\nif(numbers % 2 == 1){\n print(9, numbers - 9);\n} else {\n var half = numbers / 2;\n print(4, half - 4);\n}\n"}, {"source_code": "var n = Number(readline());\nprint(4, n-4);"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nfor (var i=1; i<10; i++){\n var c = n-(0+i);\n var b = n-c;\n if (b>2&&b%2==0)\n { \n\tprint(c,b);\n break;\n }\n}"}, {"source_code": "var n = 23;\nif(n%2==0)\nprint(n/2, n/2)\nfor (var i=1; i<10; i++){\n var c = n-(0+i);\n var b = n-c;\n if (b>2&&b%2==0)\n {\n\tprint(c,b);\n break;\n }\n}"}, {"source_code": "var n = readline();\nvar c = n-6;\nn%2==0? print(n/2, n/2):print(6, c) "}, {"source_code": "var n = readline();\nvar c = n-3;\nn%2==0? print(n/2, n/2):print(3, c)"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nelse{\nfor (var i=1; i<10; i++){\n var c = n-(0+i);\n var b = n-c;\n if (b>2&&b%2==0)\n {\n\tprint(c,b);\n break;\n }\n}\n}"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nelse{\nfor (var i=1; i=4&&((c%2==0||c%3==0)&&(b%2==0||b%3==0)))\n\t{\n\tprint(b,c)\n\tbreak;\n\t} \n}\n}"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nfor (var i=1; i<10; i++){\n var c = n-(0+i);\n var b = n-c;\n if (b>2&&b%2==0)\n {\n\tprint(c,b);\n break;\n }\n}"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nelse{\nfor (var i=1; i=4&&((c%2==0||c%3==0)&&(b%2==0||b%3==0)))\n\t{\n\tprint(b,c)\n\tbreak;\n\t}\n}\n}"}, {"source_code": "var n = readline();\nvar c = n-6;\nn%2==0? print(n/2, n/2):print(6, c)"}, {"source_code": "var n = readline();\nif(n%2==0)\nprint(n/2, n/2)\nelse{\nfor (var i=1; i3&&((c%2==0||c%3==0)&&(b%2==0||b%3==0)))\n\t{\n\tprint(b,c)\n\tbreak;\n\t}\n}\n}"}, {"source_code": "var entrada = readline();\nvar numero = parseInt(entrada);\nvar num = 0;\nif(numero%2===0){\n num = numero-8; \n print('8 '+num);\n} else {\n\ty = numero-9;\n print('9 '+num);\n}\n"}, {"source_code": "var entrada = readline();\nvar numero = parseInt(entrada);\nvar x = 4;\nvar y;\nif(numero%2===0){\n y = numero-x; \n} else {\n x = 9;\n\ty = numero-9;\n}\nprint(x+', '+y);"}, {"source_code": "var n = parseInt(readline());\nvar a = 0;\nfunction composite(n) {\n\tfor (var i = 2; i <= Math.ceil(Math.sqrt(n)); i++){\n\t\tif (n % i == 0) return true;\n\t};\n\treturn false;\n}\n\nfor (var i = 1; i < Math.ceil(n / 2); i++){\n\tif (composite(i) && composite(n - i)) {\n\t\ta = i;\n\t\tbreak;\n\t}\n\t\n}\nprint (a + ' ' + (n-a));"}, {"source_code": "var n = parseInt(readline());\n\nif (n % 2 === 0) {\n\tprint (n / 2 + \" \" + n / 2);\n}\nelse {\n\tvar x = (n - 1) / 2, y = x + 1;\n\twhile ((isPrime(x) || isPrime(y))){\n\t\tx--; y++;\n\t}\n\tprint(x + \" \" + y);\n}\n\nfunction isPrime(p) {\n\tfor(var i = 2; i <= Math.sqrt(p); i++) {\n\t\tif (p % i === 0)\n\t\t\treturn false;\n\t} \n\treturn true;\n}"}, {"source_code": "(function () {\n var n = parseInt(readline());\n \n var names = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n\n var r = 1;\n while (r * 5 < n)\n {\n n -= r * 5;\n r *= 2;\n }\n\n print(names[Math.floor((n - 1) / r)]);\n\n return 0;\n})();"}, {"source_code": "function isComposite(n) {\n for(var i = 2; i * i < n; ++i) {\n if(n % i == 0) {\n return true;\n }\n }\n return false;\n}\n\nvar n = parseInt(readline());\nfor(var i = 4; i * 2 <= n; ++i) {\n if(isComposite(i) && isComposite(n - i)) {\n print(i, n - i);\n break;\n }\n}\n"}, {"source_code": "function isComposite(n) {\n for(var i = 2; i * i < n; ++i) {\n if(n % i == 0) {\n return true;\n }\n }\n return false;\n}\n\nvar n = parseInt(readline());\nfor(var i = 4; i * 2 < n; ++i) {\n if(isComposite(i) && isComposite(n - i)) {\n print(i + \" \" + n);\n break;\n }\n}\n"}, {"source_code": "function isComposite(n) {\n for(var i = 2; i * i < n; ++i) {\n if(n % i == 0) {\n return true;\n }\n }\n return false;\n}\n\nvar n = parseInt(readline());\nfor(var i = 4; i * 2 <= n; ++i) {\n if(isComposite(i) && isComposite(n - i)) {\n print(i, n);\n break;\n }\n}\n"}, {"source_code": "function isComposite(n) {\n for(var i = 2; i * i < n; ++i) {\n if(n % i == 0) {\n return true;\n }\n }\n return false;\n}\n\nvar n = parseInt(readline())\nfor(var i = 4; i * 2 < n; ++i) {\n if(isComposite(i) && isComposite(n - i)) {\n print(i , n);\n break;\n }\n}\n"}, {"source_code": "var n = parseInt(readline()); // user input\nprint(n % 2 == 0 ? (4 + ' ' + n - 4) : (9 + ' ' + n - 9));"}, {"source_code": "var n = parseInt(readline()); // user input\nprint(n % 2 == 0 ? (4, n - 4) : (9, n - 9));"}, {"source_code": "var n = parseInt(readline()); // user input\nif (n % 2 == 0) print(4 + ' ' + n - 4);\nelse print(9 + ' ' + n - 9);"}, {"source_code": "var x= parseInt(readline());\nfor(var i=2; i= 12 && num <= 1000000) {\n var numStr = num.toString();\n var numArr = numStr.split('');\n var firstNum = numArr.reduce(function(accumulator, current) {\n return Number(accumulator) + Number(current);\n })\n var secondNum = num - firstNum;\n return [firstNum, secondNum]\n }\n }\n var k = parseInt(readline());\n print(getTwoNums(k).join(' '))"}, {"source_code": "var input = parseInt(readline());\nif (input % 2) print(2 + ' ' + input - 2)\nelse print((input / 2) + 1 + ' ' + (input / 2) - 1)\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let nums = parseInt(input[0]);\n \n let left = 0, right = 0;\n if (nums % 2 === 0) { left = nums/2; right = nums/2; }\n else { left = (nums-1)/2; right = (nums+1)/2; }\n\n\n while (true) {\n if ( (left % 2 === 0 || left % 3 === 0 || left % 5 === 0 || (left % 7 === 0 && left !== 7)) && \n (right % 2 === 0 || right % 3 === 0 || right % 5 === 0 || (right % 7 === 0 && right !== 7)) ) {\n console.log(`${left} ${right}`);\n break;\n } else {\n right -= 1; left += 1; \n }\n }\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n if (n % 2 == 0) console.log(n / 2, n / 2)\n else console.log(n - 9, 9)\n}"}], "src_uid": "3ea971165088fae130d866180c6c868b"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n const oa = a & 1\n const ob = b & 1\n const oc = c & 1\n if (oa) {\n if (ob) {\n if (oc) {\n return 0\n } else {\n return 1\n }\n } else {\n if (oc) {\n return b ? 0 : 1\n } else {\n return 1\n }\n }\n } else {\n if (ob) {\n if (oc) {\n return 1\n } else {\n return 0\n }\n } else {\n if (oc) {\n return 1\n } else {\n return 0\n }\n }\n }\n // if (true) {}\n // const sum = a + 2 * b + 3 * c\n // const half = Math.floor(sum / 2)\n // const k = Math.floor(half / 3)\n // const r = half % 3\n // if (sum & 1) {\n // if (k <= c) {\n // switch (r) {\n // case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)\n // case 1: return (b || a >= 2) ? 0 : 1\n // default:\n // case 0: return 1\n // }\n // } else {\n // const d = half - 3 * c\n // if (d & 1) {\n // return (b >= d / 2 && a) || (a >= d) ? 0 : 1\n // } else {\n // return (b >= d / 2 || a >= d) ? 0 : 1\n // }\n // }\n // } else {\n // if (k <= c) {\n // switch (r) {\n // case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)\n // case 1: return a ? 0 : 1\n // default:\n // case 0: return 0\n // }\n // } else {\n // const d = half - 3 * c\n // if (d & 1) {\n // return (b >= d / 2 && a) || (a >= d) ? 0 : 1\n // } else {\n // return (b >= d / 2 || a >= d) ? 0 : 1\n // }\n // }\n // }\n}\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt() % 2;\r\n\t\tvar b = nextInt() % 2;\r\n\t\tvar c = nextInt() % 2;\r\n\t\tif(a == 0){\r\n\t\t\ta += 2;\r\n\t\t}\r\n\t\tif(b == 0){\r\n\t\t\tb += 2;\r\n\t\t}\r\n\t\tif(c == 0){\r\n\t\t\tc += 2;\r\n\t\t}\r\n\t\tvar check = [a,b,c];\r\n\t\tvar N = check.length;\r\n\t\tvar isOK = false;\r\n\t\tfor(var i = 0; i < (1 << N); i++){\r\n\t\t\tvar L = [];\r\n\t\t\tvar R = [];\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\tL.push(j + 1);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tR.push(j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(L.length > 0 && R.length > 0){\r\n\r\n\t\t\t\tvar LV = 0;\r\n\t\t\t\tfor(var j = 0; j < L.length; j++){\r\n\t\t\t\t\tLV += check[L[j] - 1] * L[j];\r\n\t\t\t\t}\r\n\t\t\t\tvar RV = 0;\r\n\t\t\t\tfor(var j = 0; j < R.length; j++){\r\n\t\t\t\t\tRV += check[R[j] - 1] * R[j];\r\n\t\t\t\t}\r\n\t\t\t\tif(LV == RV){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}else{\r\n\t\t\t\t\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(isOK){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(a == 2 && b == 1 && c == 2){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tmyout(1);\r\n\t\t//myout((isOK) ? 0 : 1);\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(l = 1; l <= n; l++){\n var k = lines[l].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var total = a + (b * 2) + (c * 3);\n if(total % 2 === 0){\n console.log(0);\n }else{\n console.log(1);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var k = lines[l].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var total = a + (b * 2) + (c * 3);\n if(total % 2 === 0){\n console.log(0);\n }else{\n console.log(1);\n }\n }\n});"}, {"source_code": "function solve() {\r\n const [a, b, c] = readArray(BigInt);\r\n write((a + 2n * b + 3n * c) & 1n);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "// using ES6 modules import - you need to have the \"module\" property set to \"commonjs\" in the package.json\r\n// const { readline, print, console } = require('@ip-algorithmics/codeforces-io');\r\nvar n = readline();\r\nfor(var k = 0; k < n; k++){\r\n var result = 0;\r\n var num = readline().split(\" \").map(x => parseInt(x));\r\n for (var i = 0; i < num.length; i++) {\r\n result+=(num[i] * (i+1))\r\n }\r\n print(result % 2)\r\n}\r\n// var num = readline().split(\" \").map(x => parseInt(x));\r\n// var h,l;\r\n// h=num[0],l=num[1];\r\n \r\n// var r= (l*l-h*h)/(2*h);\r\n// print(r);\r\n\r\n// var num = readline().split(\" \").map(x => parseInt(x));\r\n// var h,l;\r\n// h=num[0],l=num[1];\r\n \r\n// var r= (l*l-h*h)/(2*h);\r\n// print(r);\r\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt() % 2;\r\n\t\tvar b = nextInt() % 2;\r\n\t\tvar c = nextInt() % 2;\r\n\t\tif(a == 0){\r\n\t\t\ta += 2;\r\n\t\t}\r\n\t\tif(b == 0){\r\n\t\t\tb += 2;\r\n\t\t}\r\n\t\tif(b == 0){\r\n\t\t\tb += 2;\r\n\t\t}\r\n\t\tvar check = [a,b,c];\r\n\t\tvar N = check.length;\r\n\t\tvar isOK = false;\r\n\t\tfor(var i = 0; i < (1 << N); i++){\r\n\t\t\tvar L = [];\r\n\t\t\tvar R = [];\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\tL.push(j + 1);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tR.push(j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(L.length > 0 && R.length > 0){\r\n\t\t\t\tvar LV = 0;\r\n\t\t\t\tfor(var j = 0; j < L.length; j++){\r\n\t\t\t\t\tLV += check[L[j] - 1] * L[j];\r\n\t\t\t\t}\r\n\t\t\t\tvar RV = 0;\r\n\t\t\t\tfor(var j = 0; j < R.length; j++){\r\n\t\t\t\t\tRV += check[R[j] - 1] * R[j];\r\n\t\t\t\t}\r\n\t\t\t\tif(LV == RV){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? 0 : 1);\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt() % 2;\r\n\t\tvar b = nextInt() % 2;\r\n\t\tvar c = nextInt() % 2;\r\n\t\tvar check = [a,b,c];\r\n\t\tvar N = check.length;\r\n\t\tvar isOK = false;\r\n\t\tfor(var i = 0; i < (1 << N); i++){\r\n\t\t\tvar L = [];\r\n\t\t\tvar R = [];\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\tL.push(j + 1);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tR.push(j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(L.length > 0 && R.length > 0){\r\n\t\t\t\tvar LV = 0;\r\n\t\t\t\tfor(var j = 0; j < L.length; j++){\r\n\t\t\t\t\tLV += check[L[j] - 1] * L[j];\r\n\t\t\t\t}\r\n\t\t\t\tvar RV = 0;\r\n\t\t\t\tfor(var j = 0; j < R.length; j++){\r\n\t\t\t\t\tRV += check[R[j] - 1] * R[j];\r\n\t\t\t\t}\r\n\t\t\t\tif(LV == RV){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout((isOK) ? 0 : 1);\r\n\t\t\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tvar check = [a,b,c];\r\n\t\tvar N = check.length;\r\n\t\tvar isOK = false;\r\n\t\tfor(var i = 0; i < (1 << N); i++){\r\n\t\t\tvar L = [];\r\n\t\t\tvar R = [];\r\n\t\t\tfor(var j = 0; j < N; j++){\r\n\t\t\t\tif((i & (1 << j)) != 0){\r\n\t\t\t\t\tL.push(j + 1);\r\n\t\t\t\t}else{\r\n\t\t\t\t\tR.push(j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(L.length > 0 && R.length > 0){\r\n\t\t\t\tvar LV = 0;\r\n\t\t\t\tfor(var j = 0; j < L.length; j++){\r\n\t\t\t\t\tLV += check[L[j] - 1] * L[j];\r\n\t\t\t\t}\r\n\t\t\t\tvar RV = 0;\r\n\t\t\t\tfor(var j = 0; j < R.length; j++){\r\n\t\t\t\t\tRV += check[R[j] - 1] * R[j];\r\n\t\t\t\t}\r\n\t\t\t\tif(LV == RV){\r\n\t\t\t\t\tisOK = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isOK){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t\r\n\t\tvar diff = (c % 2 == 1) ? 3 : 0;\r\n\t\tif(diff > 0 && b > 0){\r\n\t\t\tdiff -= 2;\r\n\t\t\tb--;\r\n\t\t}\r\n\t\tif(diff > 0 && a > 0){\r\n\t\t\tdiff--;\r\n\t\t\ta--;\r\n\t\t}\r\n\t\tif(b % 2 == 1){\r\n\t\t\tdiff = 2;\r\n\t\t\tif(a > 0){\r\n\t\t\t\tvar tmp = Math.min(a, 2);\r\n\t\t\t\tdiff -= tmp;\r\n\t\t\t\ta -= tmp;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(a % 2 == 1){\r\n\t\t\tdiff++;\r\n\t\t}\r\n\t\tmyout(diff);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tif(a + b * 2 == c * 3){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif(a + c * 3 == b * 2){\r\n\t\t\tmyout(0);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar diff = (c % 2 == 1) ? 3 : 0;\r\n\t\tif(diff > 0 && b > 0){\r\n\t\t\tdiff -= 2;\r\n\t\t\tb--;\r\n\t\t}\r\n\t\tif(diff > 0 && a > 0){\r\n\t\t\tdiff--;\r\n\t\t\ta--;\r\n\t\t}\r\n\t\tif(b % 2 == 1){\r\n\t\t\tdiff = 2;\r\n\t\t\tif(a > 0){\r\n\t\t\t\tvar tmp = Math.min(a, 2);\r\n\t\t\t\tdiff -= tmp;\r\n\t\t\t\ta -= tmp;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(a % 2 == 1){\r\n\t\t\tdiff++;\r\n\t\t}\r\n\t\tmyout(diff);\r\n\t}\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = BigInt(next());\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar a = nextInt();\r\n\t\tvar b = nextInt();\r\n\t\tvar c = nextInt();\r\n\t\tvar diff = (c % 2 == 1) ? 3 : 0;\r\n\t\tif(diff > 0 && b > 0){\r\n\t\t\tdiff -= 2;\r\n\t\t\tb--;\r\n\t\t}\r\n\t\tif(diff > 0 && a > 0){\r\n\t\t\tdiff--;\r\n\t\t\ta--;\r\n\t\t}\r\n\t\tif(b % 2 == 1){\r\n\t\t\tdiff = 2;\r\n\t\t\tif(a > 0){\r\n\t\t\t\tvar tmp = Math.min(a, 2);\r\n\t\t\t\tdiff -= tmp;\r\n\t\t\t\ta -= tmp;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(a % 2 == 1){\r\n\t\t\tdiff++;\r\n\t\t}\r\n\t\tmyout(diff);\r\n\t}\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var k = lines[l].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var total = a + b + c;\n if(total % 2 === 1){\n console.log(0);\n }else{\n console.log(1);\n }\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(var l = 1; l <= n; l++){\n var k = lines[l].split(' ').map(Number);\n var a = k[0];\n var b = k[1];\n var c = k[2];\n var total = a + b + c;\n if(total % 2 === 0){\n console.log(0);\n }else{\n console.log(1);\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b, c] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b, c)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b, c) {\n const oa = a & 1\n const ob = b & 1\n const oc = c & 1\n if (oa) {\n if (ob) {\n if (oc) {\n return 0\n } else {\n return 1\n }\n } else {\n if (oc) {\n return b ? 0 : 1\n } else {\n return 1\n }\n }\n } else {\n if (ob) {\n if (oc) {\n return 1\n } else {\n return 0\n }\n } else {\n if (oc) {\n return 3\n } else {\n return 0\n }\n }\n }\n // if (true) {}\n // const sum = a + 2 * b + 3 * c\n // const half = Math.floor(sum / 2)\n // const k = Math.floor(half / 3)\n // const r = half % 3\n // if (sum & 1) {\n // if (k <= c) {\n // switch (r) {\n // case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)\n // case 1: return (b || a >= 2) ? 0 : 1\n // default:\n // case 0: return 1\n // }\n // } else {\n // const d = half - 3 * c\n // if (d & 1) {\n // return (b >= d / 2 && a) || (a >= d) ? 0 : 1\n // } else {\n // return (b >= d / 2 || a >= d) ? 0 : 1\n // }\n // }\n // } else {\n // if (k <= c) {\n // switch (r) {\n // case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)\n // case 1: return a ? 0 : 1\n // default:\n // case 0: return 0\n // }\n // } else {\n // const d = half - 3 * c\n // if (d & 1) {\n // return (b >= d / 2 && a) || (a >= d) ? 0 : 1\n // } else {\n // return (b >= d / 2 || a >= d) ? 0 : 1\n // }\n // }\n // }\n}\n"}], "src_uid": "4322861935ca727b0de8556849bc5982"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n \nlet tests = [];\nrl.on('line', (line) => {\n tests.push(line);\n}).on('close', () => {\n for (ii = 1; ii < tests.length; ii += 3) {\n let countStap = 0;\n const candy = tests[ii + 1].split(' ').map(x => +x);\n const orange = tests[ii + 2].split(' ').map(x => +x);\n const minCandy = Math.min(...candy);\n const minOrange = Math.min(...orange);\n\n for (i = 0; i < candy.length; i++) {\n if (candy[i] > minCandy && orange[i] > minOrange) {\n const minStap = Math.min(candy[i] - minCandy, orange[i] - minOrange);\n\n countStap += minStap + (candy[i] - minCandy - minStap) + (orange[i] - minOrange - minStap);\n } else if (candy[i] > minCandy && orange[i] == minOrange) {\n countStap += candy[i] - minCandy\n } else if (orange[i] > minOrange && candy[i] == minCandy) {\n countStap += orange[i] - minOrange\n }\n }\n process.stdout.write(`${countStap}\\n`);\n }\n});", "positive_code": [{"source_code": "const readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n//\n// rl.question(\"\", function (n) {\n// functions();\n// })\n//\n// function functions() {\n// rl.question(\"\", function (num) {\n// rl.question(\"\", function (name) {\n// var bool = true;\n// var sN = name.split(\" \");\n// var na = sN.sort();\n// for (var i = 0; i < na.length; i++) {\n// if (na[i + 1] - na[i] > 1) {\n// var bool = false;\n// }\n// }\n// if (bool) {\n// console.log('YES')\n// } else {\n// console.log('NO')\n// }\n// functions();\n// });\n// })\n// }\nrl.question('', function () {\n functions();\n})\nfunction functions() {\n rl.question('', function (n) {\n rl.question('', function (a) {\n rl.question('', function (b) {\n var s = 0;\n var sa = a.split(' ');\n var sb = b.split(' ');\n // console.log(n, newA, s, sa, sb)\n for (var i = 0; i < n; i++) {\n var newA = [];\n var ai = sa[i] - Math.min.apply(Math, sa)\n var bi = sb[i] - Math.min.apply(Math, sb)\n newA.push(ai);\n newA.push(bi);\n s += Math.max.apply(Math, newA);\n // console.log()\n }\n console.log(s)\n functions();\n })\n })\n })\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const candy = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const orange = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let count = 0;\n const [min1, min2] = [Math.min(...candy), Math.min(...orange)];\n for (let i = 0; i < len; i++) {\n const [a, b] = [candy[i], orange[i]];\n const [move1, move2] = [a - min1, b - min2];\n count += Math.max(move1, move2);\n }\n\n console.log(count);\n }\n}\n"}, {"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet input = [];\n\nrl.on('line', function (line) {\n input.push(line);\n});\n\nrl.on('close', function () {\n const total = Number(input[0]);\n for (let ii = 0; ii < 3 * total; ii += 3) {\n let arr1 = input[ii + 2].split(' ').map(x => Number(x));\n let arr2 = input[ii + 3].split(' ').map(x => Number(x));\n let ans = 0;\n let min1 = arr1[0];\n let min2 = arr2[0];\n for(let i =1; i arr1[i]) {\n min1 = arr1[i];\n }\n if (min2 > arr2[i]) {\n min2 = arr2[i];\n }\n }\n\n for (let i = 0; i < arr1.length; i++) {\n ans += Math.max(arr1[i] - min1, arr2[i] - min2);\n }\n console.log(ans)\n }\n});\n\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var n = nextInt();\n var alist = nextIntArray();\n var blist = nextIntArray();\n var amin = Math.min.apply(null, alist);\n var bmin = Math.min.apply(null, blist);\n var aminlist = new Array(n).fill(0);\n var bminlist = new Array(n).fill(0);\n var count = 0;\n for(var j = 0; j < n; j++){\n if(alist[j] > amin){\n aminlist[j] = alist[j] - amin;\n }\n if(blist[j] > bmin){\n bminlist[j] = blist[j] - bmin;\n }\n }\n for(var j = 0; j < n; j++){\n if(aminlist[j] > 0 && bminlist[j] > 0){\n var common = Math.min(aminlist[j], bminlist[j]);\n count += aminlist[j] + bminlist[j] - common;\n }else{\n count += aminlist[j] + bminlist[j];\n }\n }\n output[i] = count;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\n\nconst runMain = () => {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n let t = readLine();\n while (t--) {\n const n = readLine();\n const a = readLine().split(' ').map(num => Number(num));\n const b = readLine().split(' ').map(num => Number(num));\n const aMin = Math.min(...a);\n const bMin = Math.min(...b);\n let res = 0;\n for (let i = 0; i < n; i++) {\n res += Math.max(a[i] - aMin, b[i] - bMin);\n }\n console.log(res);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n});\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n});\n \nfunction main(data) {\n\tdata = data.split('\\n');\n\tconst testCases = data[0] * 3;\n let i = 1;\n outer:\n\twhile (i <= testCases) {\n\t let n = data[i] * 1;\n\t let a = data[i + 1].trim().split(' ').map(Number);\n\t let b = data[i + 2].trim().split(' ').map(Number);\n\t let count = 0;\n\t let minA = Math.min(...a);\n\t let minB = Math.min(...b);\n\t for (let j = 0; j < n; j += 1) {\n\t let diffA = a[j] - minA;\n let diffB = b[j] - minB;\n if (a[j] > minA && b[j] > minB) {\n let min = Math.min(diffA, diffB);\n if (min === diffA) {\n count += diffA;\n count += (diffB - diffA);\n } else {\n count += diffB;\n count += (diffA - diffB);\n }\n } else if (a[j] > minA) count += diffA;\n else count += diffB;\n\t }\n\t console.log(count);\n i += 3;\n\t}\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n let t = +readline();\n for (let i = 0; i < t; i++) {\n const n = +readline();\n const a = readline().split(' ').map(x => parseInt(x));\n const b = readline().split(' ').map(x => parseInt(x));\n const minA = Math.min(...a);\n const minB = Math.min(...b);\n let m = 0;\n for (let i = 0; i < n; i++) {\n m += Math.max(Math.abs(a[i] - minA), Math.abs(b[i] - minB));\n }\n print(`${m}\\n`);\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n let acc = 0\n const n = +lines[acc++]\n for (let i=0; i +x)\n const b = lines[acc++].split(' ').map(x => +x)\n\n const leastA = Math.min(...a)\n const leastB = Math.min(...b)\n\n let sum = 0\n\n for (let i=0; i< count; i++) {\n const diffA = a[i] - leastA\n const diffB = b[i] - leastB\n sum += Math.max(diffA, diffB)\n }\n\n console.log(sum)\n }\n\n\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const a = readLine().split(' ').map(s2i)\n const b = readLine().split(' ').map(s2i)\n\n let minA = a[0]\n let minB = b[0]\n\n for (let i = 1; i < n; i++) {\n if (a[i] < minA) minA = a[i]\n if (b[i] < minB) minB = b[i]\n }\n\n let moves = 0\n\n for (let i = 0; i < n; i++) {\n moves += Math.max(a[i] - minA, b[i] - minB)\n }\n\n out += moves + '\\n'\n }\n\n console.log(out)\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet candy = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\tlet orange = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet minC = Math.min(...candy);\n\t\tlet minO = Math.min(...orange);\n\n\t\tlet count = 0;\n\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tlet gc = candy[i];\n\t\t\tlet go = orange[i];\n\n\t\t\tlet x = Math.min(gc - minC, go - minO);\n\n\t\t\tif (gc > minC && go > minO) {\n\t\t\t\tcount += x;\n\t\t\t\tgc -= x;\n\t\t\t\tgo -= x;\n\t\t\t}\n\n\t\t\tif (gc > minC) {\n\t\t\t\tcount += gc - minC;\n\t\t\t}\n\n\t\t\tif (go > minO) {\n\t\t\t\tcount += go - minO;\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(count);\n\t}\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n let minA = 999999999999999;\n let minB = 999999999999999;\n\n for(let i = 0; i < n; i++){\n minA = Math.min(minA, a[i]);\n minB = Math.min(minB, b[i]);\n }\n\n for(let i = 0; i < n; i++){\n a[i] = a[i]-minA;\n b[i] = b[i]-minB;\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(a[i] !== 0 || b[i] !== 0)\n res += Math.max(a[i],b[i]);\n\n console.log(res);\n }\n}"}, {"source_code": "function solve() {\n var n = readInt()\n var aArr = readIntArray()\n var bArr = readIntArray()\n\n var aMin = Number.MAX_VALUE\n var bMin = Number.MAX_VALUE\n for(var i=0;i a - b)\n}"}], "negative_code": [{"source_code": "var readline = require('readline');\nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet input = [];\n\nrl.on('line', function (line) {\n input.push(line);\n});\n\nrl.on('close', function () {\n const total = Number(input[0]);\n for (let ii = 0; ii < 2 * total; ii += 3) {\n let arr1 = input[ii + 2].split(' ').map(x => Number(x));\n let arr2 = input[ii + 3].split(' ').map(x => Number(x));\n let ans = 0;\n let min1 = arr1[0];\n let min2 = arr2[0];\n for(let i =1; i arr1[i]) {\n min1 = arr1[i];\n }\n if (min2 > arr2[i]) {\n min2 = arr2[i];\n }\n }\n\n for (let i = 0; i < arr1.length; i++) {\n ans += Math.max(arr1[i] - min1, arr2[i] - min2);\n }\n console.log(ans)\n }\n});\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n let a = readline().split(' ');\n let b = readline().split(' ');\n\n let minA = 99999999;\n let minB = 99999999;\n\n for(let i = 0; i < n; i++){\n minA = Math.min(minA, a[i]);\n minB = Math.min(minB, b[i]);\n }\n\n for(let i = 0; i < n; i++){\n a[i] = a[i]-minA;\n b[i] = b[i]-minB;\n }\n\n let res = 0;\n for(let i = 0; i < n; i++)\n if(a[i] !== 0 || b[i] !== 0)\n res += Math.max(a[i],b[i]);\n\n console.log(res);\n }\n}"}], "src_uid": "35368cefc5ce46a9f41a15734826a151"} {"source_code": " var p,\n row,\n vowels,\n fit,\n i;\n\nreadline();\nfit = \"YES\";\nvowels = /[aeiouy]/gi;\ni = 0;\np = readline().split( \" \" ).map( pi => parseInt( pi, 10 ) );\nwhile ( row = readline() ) {\n if ( ( row.match( vowels ) || [] ).length !== p[ i++ ] ) {\n fit = \"NO\";\n break;\n }\n}\n\nprint( fit );\n ", "positive_code": [{"source_code": "var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];\n\nfunction canDiv (word, num) {\n var char = word.split('');\n\n for (var i = 0; i < char.length; i++) {\n if (vowels.indexOf(char[i]) >= 0) {\n num--;\n }\n }\n return num === 0;\n}\n\nfunction main (num, numList, strList) {\n for (var i = 0; i < num; i++) {\n if (!canDiv(strList[i], numList[i])) {\n print('NO');\n return;\n }\n }\n print('YES');\n}\n\nvar num = parseInt(readline()),\n numList = readline().split(' ').map(function (x) {\n return parseInt(x);\n }),\n strList = [];\n\nfor (var i = 0; i < num; i++) {\n strList.push(readline());\n}\nmain(num, numList, strList);"}], "negative_code": [{"source_code": "var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];\n\nfunction canDiv (word, num) {\n var char = word.split('');\n\n var hasVowel = char.map(function (x) {\n return vowels.indexOf(x);\n }).filter(function (x) {\n return x >= 0;\n });\n //if (hasVowel.length === 0) return false;\n\n for (var i = 0; i < char.length; i++) {\n if (vowels.indexOf(char[i]) >= 0) {\n num--;\n }\n }\n return num === 0;\n}\n\nfunction main (num, numList, strList) {\n for (var i = 0; i < num; i++) {\n if (!canDiv(strList[i], numList[i])) {\n print('NO');\n return;\n }\n }\n print('YES');\n}\n\n// var num = parseInt('3'),\n// numList = '2 2 3'.split(' '),\n// strList = 'intel\\ncode\\nch allenge'.split('\\n');\n// debugger;\n// main(num, numList, strList);\n\n\nvar num = parseInt(readline()),\n numList = readline().split(' '),\n strList = [];\nfor (var i = 0; i < num; i++) {\n strList.push(readline());\n}\nmain(num, numList, strList);\n"}, {"source_code": "var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];\n\nfunction canDiv (word, num) {\n var char = word.split('');\n\n var hasVowel = char.map(function (x) {\n return vowels.indexOf(x);\n }).filter(function (x) {\n return x >= 0;\n });\n if (hasVowel.length === 0) return false;\n\n for (var i = 0; i < char.length; i++) {\n if (vowels.indexOf(char[i]) >= 0) {\n num--;\n }\n }\n return num === 0;\n}\n\nfunction main (num, numList, strList) {\n for (var i = 0; i < num; i++) {\n if (!canDiv(strList[i], numList[i])) {\n print('NO');\n return;\n }\n }\n print('YES');\n}\n\n// var num = parseInt('3'),\n// numList = '2 2 3'.split(' '),\n// strList = 'intel\\ncode\\nch allenge'.split('\\n');\n// debugger;\n// main(num, numList, strList);\n\n\nvar num = parseInt(readline()),\n numList = readline().split(' '),\n strList = [];\nfor (var i = 0; i < num; i++) {\n strList.push(readline());\n}\nmain(num, numList, strList);\n"}, {"source_code": "var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];\n\nfunction canDiv (word, num) {\n for (var i = 0; i < word.length; i++) {\n if (vowels.indexOf(word[i]) >= 0) {\n num--;\n }\n }\n return num === 0;\n}\n\nfunction main (num, numList, strList) {\n // for (var i = 0; i < num; i++) {\n // if (!canDiv(strList[i], numList[i])) {\n // print('NO');\n // return;\n // }\n // }\n // print('YES');\n\n for (var i = 0; i < num; i++)\n {\n for (var j = 0; j < strList[i].length; j++)\n if (vowels.indexOf(strList[i][j]) >= 0)\n numList[i]--;\n if (numList[i] !== 0)\n {\n print('NO');\n return;\n }\n }\n print('YES');\n}\n\nvar num = parseInt(readline()),\n numList = readline().split(' '),\n strList = [];\n\nfor (var i = 0; i < num; i++) {\n strList.push(readline());\n}\nmain(num, numList, strList);\n"}, {"source_code": "var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];\n\nfunction canDiv (word, num) {\n for (var i = 0; i < word.length; i++) {\n if (vowels.indexOf(word[i]) >= 0) {\n num--;\n }\n }\n return num === 0;\n}\n\nfunction main (num, numList, strList) {\n for (var i = 0; i < num; i++) {\n if (!canDiv(strList[i], numList[i])) {\n print('NO');\n return;\n }\n }\n print('YES');\n}\n\n// var num = parseInt('3'),\n// numList = '2 2 3'.split(' '),\n// strList = 'intel\\ncode\\nch allenge'.split('\\n');\n// debugger;\n// main(num, numList, strList);\n\n\nvar num = parseInt(readline()),\n numList = readline().split(' '),\n strList = [];\n\nfor (var i = 0; i < num; i++) {\n strList.push(readline());\n}\nmain(num, numList, strList);\n"}], "src_uid": "cf595689b5cbda4f1d629524ad275650"} {"source_code": "'use strict'\n\nconst ord = x => x.charCodeAt(0) - 97;\n\n// G - G[i] \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 s, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043f\u043e\u0438\u0441\u043a \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 i\n// D - \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430, D[i][j] \u0445\u0440\u0430\u043d\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 x \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 s, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f a[:i] \u0438 b[:j]\n// D[0][0] = 0 - \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u044b\u0445 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u0432 - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 s\nconst interleaving = (a, b, G) => {\n const D = Array.from({ length: a.length + 1 }, () => Array(b.length + 1).fill(Infinity)); D[0][0] = 0;\n for (let i = 0; i < a.length + 1; i++) {\n for (let j = 0; j < b.length + 1; j++) {\n if (!isFinite(D[i][j])) continue;\n const x = D[i][j];\n if (i !== a.length) D[i+1][j] = Math.min(D[i+1][j], G[x][ord(a[i])] + 1);\n if (j !== b.length) D[i][j+1] = Math.min(D[i][j+1], G[x][ord(b[j])] + 1);\n }\n }\n\n return isFinite(D[a.length][b.length]);\n}\n\nconst problem = (s, p) => {\n const n = s.length;\n const G = Array.from({ length: n + 2}, () => Array(26).fill(Infinity));\n for (let i = n - 1; i > -1; i--) { G[i] = G[i + 1].slice(); G[i][ord(s[i])] = i; }\n for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i), G, n)) return 'YES';\n return 'NO';\n}\n\nlet t = +readline()\nwhile(t--) print(problem(readline(), readline()));\n", "positive_code": [{"source_code": "'use strict'\nconst ord = x => x.charCodeAt(0) - 97;\n\nconst problem = (s, p) => {\n const n = s.length;\n const F = [];\n for (let i = 0; i < n + 2; i++) F[i] = Array(26).fill(n);\n for (let i = n-1; i > -1; i--) {\n F[i] = F[i + 1].slice()\n F[i][ord(s[i])] = i\n }\n const interleaving = (l, r) => {\n const dp = Array(r.length + 1).fill(n); dp[0] = -1;\n\n for (let j = 1; j < r.length + 1; j++) {\n dp[j] = F[dp[j - 1] + 1][ord(r[j - 1])]\n }\n\n for (let i = 1; i < l.length + 1; i++) {\n dp[0] = F[dp[0] + 1][ord(l[i - 1])]\n\n for (let j = 1; j < r.length + 1; j++) {\n const a = F[dp[j] + 1][ord(l[i - 1])]\n const b = F[dp[j - 1] + 1][ord(r[j - 1])]\n dp[j] = Math.min(a, b)\n }\n }\n return dp[dp.length - 1] < n\n }\n\n for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i))) return 'YES'\n return 'NO'\n}\n\nlet t = +readline()\nwhile(t--) print(problem(readline().split(''), readline()));\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (s, p) => {\n let j = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === p[j]) j++;\n if (j === p.length) return 'YES';\n }\n for (let i = 0; i < s.length; i++) {\n if (s[i] === p[j]) j++;\n if (j === p.length) return 'YES';\n }\n return 'NO';\n}\n\nlet t = +readline()\nwhile(t--) print(problem(readline(), readline()));\n"}, {"source_code": "'use strict'\n\nconst problem = (s, p) => {\n let j = 0;\n let t = '';\n const pLen = p.length;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === p[j]) { if (++j === pLen) return 'YES'; }\n else t += s[i];\n }\n for (let i = 0; i < t.length; i++) {\n if (t[i] === p[j]) { if (++j === pLen) return 'YES'; }\n }\n return 'NO';\n} \nlet t = +readline()\nwhile(t--) print(problem(readline(), readline()));\n"}, {"source_code": "'use strict'\n\n// G - G[i] \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 s, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043f\u043e\u0438\u0441\u043a \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 i\n// D - \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430, D[i][j] \u0445\u0440\u0430\u043d\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 x \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 s, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f a[:i] \u0438 b[:j]\n// D[0][0] = 0 - \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u044b\u0445 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u0432 - \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 s\nconst interleaving = (a, b, G) => {\n const D = Array.from({ length: a.length + 1 }, () => Array(b.length + 1).fill(Infinity)); D[0][0] = 0;\n for (let i = 0; i < a.length + 1; i++) {\n for (let j = 0; j < b.length + 1; j++) {\n if (!isFinite(D[i][j])) continue;\n const x = D[i][j];\n if (i !== a.length && a[i] in G[x]) D[i+1][j] = Math.min(D[i+1][j], G[x][a[i]] + 1);\n if (j !== b.length && b[j] in G[x]) D[i][j+1] = Math.min(D[i][j+1], G[x][b[j]] + 1);\n }\n }\n return isFinite(D[a.length][b.length]);\n}\nconst problem = (s, p) => {\n if (s === 'adddbefbbbeeaadcddabfffcbeaecfadbdbfecebabbefbedfbdcafbfcbfacecbdcfaabeacdacfebabaccaddbebdabdeebcafcaabadabeaeeebeddffbabfaeedcbefbdcbfacaeefeafccadadadcdabcbdaadcdbbacadfabfbdaaeceaabbdabfabeacddacecdcabfeeaedebffefcecabcabecffcebdefcfaeadbfddbdfefeacdfcdebbdcbaafcfbbfceadfdabfcdacefdeadadbfedbaaefbcccfcdcdbfbbacfbfcbcabcbcbbffbbcefbeccdcaebabbbbdddaffacabbabbbadfcaadbedbaabbaffebdfbdbbcbfffeafe')\n print(p)\n const G = Array.from({ length: s.length + 1 }, () => ({}));\n for (let i = s.length - 1; i > -1; i--) G[i] = Object.assign({}, G[i + 1], { [s[i]]: i });\n for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i), G)) return 'YES';\n return 'NO';\n}\n\nlet t = +readline()\nwhile(t--) print(problem(readline(), readline()));\n"}], "src_uid": "e716a5b0536d8f5112fb5f93ab86635b"} {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const n = arr.length;\n if (n < 2) {\n return arr;\n }\n const bitIdx = {};\n for (let i = 0; i < n; i++) {\n const a = arr[i];\n for(let b = 1; b <= a; b <<= 1) {\n if (a & b) {\n if (bitIdx[b] === undefined) {\n bitIdx[b] = i;\n } else {\n bitIdx[b] = -1;\n }\n }\n }\n }\n const order = Object.keys(bitIdx).sort((a,b)=> b - a);\n // console.log({bitIdx, order});\n let idx = 0;\n for (const k of order) {\n if (bitIdx[k] !== -1) {\n idx = bitIdx[k];\n break;\n }\n }\n const head = arr[idx];\n arr.splice(idx,1);\n arr.unshift(head);\n return arr;\n}\n\nfunction main() {\n readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res.join(' '));\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const d = Array(31).fill(0), p = [];\n const b = a.map(i => (+i).toString(2));\n\n for (let i = 0; i < n; i++) {\n const x = b[i].split('').reverse();\n for (let j = 0; j < x.length; j++) {\n if (x[j] === '1') { d[j]++; p[j] = i; }\n }\n }\n for (let i = d.length - 1; i > -1; i--) {\n if (d[i] === 1) return [ a[p[i]], a.slice(0, p[i]).join(' '), a.slice(p[i]+1).join(' ') ].join(' ');\n }\n return a.join(' ');\n}\nprint(problem(+readline(), readline().split(' ')))\n"}, {"source_code": "const f = (x, y) => (x | y) - y\n\nconst processData = (lines) => {\n const bits = Array(32).fill(0).map(() => [])\n\n let nums = lines[1].split(' ').map(x => +x)\n for (let k =0; k i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}], "negative_code": [{"source_code": "'use strict'\n\nconst problem = (n, a) => {\n const d = Array(31).fill(0), p = [];\n const b = a.map(i => (+i).toString(2));\n for (let i = 0; i < n; i++) {\n const x = b[i]\n for (let j = x.length - 1; j > -1; j--) {\n d[j]++;\n p[j] = i;\n }\n }\n for (let i = d.length - 1; i > -1; i--) {\n if (d[i] === 1) return [ a[p[i]], a.slice(0, p[i]).join(' '), a.slice(p[i]+1).join(' ') ].join(' ');\n }\n return a.join(' ');\n}\nprint(problem(+readline(), readline().split(' ')))\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n arr.sort((a, b) => b - a);\n return arr;\n}\n\nfunction main() {\n readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res.join(' '));\n}\n"}], "src_uid": "14fd47f6f0fcbdb16dbd73dcca8a782f"} {"source_code": "function main(n,b,d,arr){\n\n var fits = 0;\n var res = 0;\n\n for(var i = 0 ; i < n ; i++){\n if(arr[i] > b)continue;\n\n fits += arr[i];\n if(fits <= d)continue;\n\n res++;\n fits = 0;\n\n }\n print(res);\n}\n\nvar nbd = readline().split(\" \");\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);\n", "positive_code": [{"source_code": "var firstLine = readline().split(' ').map(Number);\n\nvar n = firstLine[0];\nvar b = firstLine[1];\nvar d = firstLine[2];\n\nvar oranges = readline().split(' ').map(Number);\n\nvar count = 0;\nvar currentLoad = 0;\n\nfor (var i = 0; i < n; i++) {\n if (oranges[i] <= b) {\n currentLoad += oranges[i];\n }\n\n if (currentLoad > d) {\n count++;\n currentLoad = 0;\n }\n}\n\nprint(count);\n"}, {"source_code": "var params = readline().split(' ').map(Number);\nvar n = params[0]; var b = params[1]; var d = params[2];\nvar processed_orange_size = 0;\nvar do_empty = 0;\n\nreadline().split(' ').map(function(x){\n \n x = parseInt(x);\n if(x <= b)\n processed_orange_size += x;\n \n if(processed_orange_size > d) {\n do_empty++;\n processed_orange_size = 0;\n }\n});\n\nprint(do_empty);"}, {"source_code": "var x = readline().split(\" \");\nvar a = readline().split(\" \").map(Number);\nvar c = 0, s = 0;\nfor (var i = 0; i < x[0]; i++) {\n\tif (a[i] > x[1]) continue;\n\ts += a[i];\n\tif (s > x[2]) {\n\t\tc++;\n\t\ts = 0;\n }\n}\nprint(c);\n"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar b = values[1];\nvar d = values[2];\n\nvar oranges = readline().split(\" \").map(Number);\n\nvar sum = 0;\nvar count = 0;\nfor (var i = 0; i < oranges.length; i++) {\n if (oranges[i] > b) {\n continue;\n }\n \n sum += oranges[i];\n \n if (sum > d) {\n count++;\n sum = 0;\n }\n}\n \nprint(count);"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n \n const x = readline()\n .split(\" \")\n .map((x) => +x);\n \n const x2 = readline()\n .split(\" \")\n .map((x) => +x);\n \n\n \n \n \n juicer(x[1],x[2],x2);\n}\n\n function juicer(b, d, oranges) {\n let wasteLand = 0;\n let clearCounts = 0;\n\n for (const orange of oranges) {\n if (orange <= b) wasteLand += orange;\n\n if (wasteLand > d) {\n wasteLand = 0;\n clearCounts++;\n }\n }\n\n console.log(clearCounts);\n\n return clearCounts;\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const [n, b, d] = readline().split(' ').map(x => parseInt(x));\n const a = readline().split(' ').map(x => parseInt(x));\n let k = 0;\n let t = 0;\n for (let i = 0; i < n; i++) {\n if (a[i] > b) {\n continue;\n }\n k += a[i];\n if (k > d) {\n k = 0;\n t++;\n }\n }\n // output\n print(t);\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, b, d;\n\nrl.on('line', (data) => {\n if (c === 0) {\n [n, b, d] = data.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = data.split(' ').map(Number).filter(x => x <= b);\n let ans = 0;\n\n let cup = 0;\n for (let i = 0; i < arr.length; i++) {\n cup += arr[i];\n\n if (cup > d) {\n cup = 0;\n ans++;\n }\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let t = readint();\n let n, b, d;\n [n,b,d] = t;\n let a = readint();\n let ans = 0;\n let garbage = 0;\n for(let i = 0; i < n; i++) {\n if(a[i] <= b) {\n garbage += a[i];\n }\n if(garbage > d) {\n garbage = 0;\n ans++;\n }\n }\n print(ans);\n}"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet firstLine = input[0].split(' ');\nfirstLine = firstLine.map((b) => parseInt(b));\nconst n = firstLine[0];\nconst maxSize = firstLine[1];\nconst threshold = firstLine[2];\nlet oranges = input[1].split(' ');\noranges = oranges.map((b) => parseInt(b));\n\nconst res = oranges.reduce((acc, cv) => {\n if (cv > maxSize) {\n return acc;\n }\n acc.currentWaste += cv;\n if (acc.currentWaste > threshold) {\n acc.totalCleanups += 1;\n acc.currentWaste = 0;\n }\n return acc;\n}, { totalCleanups: 0, currentWaste: 0 });\nconsole.log(res.totalCleanups)\n\n});"}, {"source_code": " var informations = readline().split(' ').map(Number)\n var oranges = readline().split(' ').map(Number)\n var numberOfOrange = informations[0]\n var sizeMax = informations[1]\n var containerMax = informations[2]\n\n var totalPressed = 0\n var numberOfTimeCleaned = 0\n for (var i = 0; i < numberOfOrange; i++) {\n if (oranges[i] <= sizeMax) {\n totalPressed += oranges[i]\n }\n\n if (totalPressed > containerMax) {\n totalPressed = 0\n numberOfTimeCleaned += 1\n }\n }\n\n print(numberOfTimeCleaned)"}], "negative_code": [{"source_code": "function main(n,b,d,arr){\n\n var fits = 0;\n\n for(var i = 0 ; i < n ; i++){\n if(arr[i] < b)fits += arr[i];\n }\n fits = Math.floor(fits/d);\n print(fits);\n}\n\nvar nbd = readline().split(\" \");\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);\n"}, {"source_code": "function main(n,b,d,arr){\n\n var fits = 0;\n\n for(var i = 0 ; i < n ; i++){\n if(arr[i] <= b)fits += arr[i];\n }\n fits = Math.floor(fits/d);\n print(fits);\n}\n\nvar nbd = readline().split(\" \");\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);\n"}, {"source_code": "function main(n,b,d,arr){\n\n var fits = 0;\n\n for(var i = 0 ; i < n ; i++){\n if(arr[i] <= b)fits += arr[i];\n }\n fits = fits%d;\n print(fits);\n}\n\nvar nbd = readline().split(\" \");\nvar arr = readline().split(\" \");\nfor(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nmain(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);\n"}, {"source_code": " var informations = readline().split(' ').map(Number)\n var oranges = readline().split(' ').map(Number)\n var numberOfOrange = informations[0]\n var sizeMax = informations[1]\n var containerMax = informations[2]\n\n var totalPressed = 0\n var numberOfTimeCleaned = 0\n for (var i = 0; i < numberOfOrange; i++) {\n if (oranges[i] < sizeMax) {\n totalPressed += oranges[i]\n }\n\n if (totalPressed > containerMax) {\n totalPressed = 0\n numberOfTimeCleaned += 1\n }\n }\n\n print(numberOfTimeCleaned)"}, {"source_code": " var informations = readline().split(' ').map(Number)\n var oranges = readline().split(' ').map(Number)\n var numberOfOrange = informations[0]\n var sizeMax = informations[1]\n var containerMax = informations[2]\n\n var totalPressed = 0\n for (var i = 0; i < numberOfOrange; i++) {\n if (oranges[i] < sizeMax) {\n totalPressed += oranges[i]\n }\n }\n\n var numberOfTimeCleaned = Math.floor(totalPressed / containerMax)\n print(numberOfTimeCleaned)"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar b = values[1];\nvar d = values[2];\n\nvar oranges = readline().split(\" \").map(Number);\n\nvar sum = 0;\nfor (var i = 0; i < oranges.length; i++) {\n if (oranges[i] > b) {\n continue;\n }\n \n sum += oranges[i];\n}\n \nprint(sum === d ? 0: Math.floor(sum/d));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[1];\nvar d = values[2];\n\nvar oranges = readline().split(\" \").map(Number)\n .filter(x => x <= n)\n .reduce((acc, n) => {\n return acc + n;\n }, 0);\n \nprint(Math.floor(oranges/d));"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[1];\nvar d = values[2];\n\nvar oranges = readline().split(\" \").map(Number)\n .filter(x => x <= n)\n .reduce((acc, n) => {\n return acc + n;\n }, 0);\n \nprint(Math.floor(oranges/10));"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, b, d;\n\nrl.on('line', (data) => {\n if (c === 0) {\n [n, b, d] = data.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = data.split(' ').map(Number).filter(x => x <= b);\n const sum = arr.reduce((a, b) => a + b, 0);\n let ans = Math.floor(sum / d);\n\n if (d === 1) {\n ans--;\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, b, d;\n\nrl.on('line', (data) => {\n if (c === 0) {\n [n, b, d] = data.split(' ').map(Number);\n c++;\n return;\n }\n\n const arr = data.split(' ').map(Number).filter(x => x <= b);\n const sum = arr.reduce((a, b) => a + b, 0);\n const ans = Math.floor(sum / d);\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nlet firstLine = input[0].split(' ');\nfirstLine = firstLine.map((b) => parseInt(b));\nconst n = firstLine[0];\nconst maxSize = firstLine[1];\nconst threshold = firstLine[2];\nlet oranges = input[1].split(' ');\noranges = oranges.map((b) => parseInt(b));\n\nconst res = oranges.reduce((acc, cv) => {\n if (cv > maxSize) {\n return acc;\n }\n acc.currentWaste += cv;\n if (acc.currentWaste > threshold) {\n acc.totalCleanups += 1;\n acc.currentWaste = 0;\n }\n console.log({cv,acc})\n return acc;\n}, { totalCleanups: 0, currentWaste: 0 });\nconsole.log(res.totalCleanups)\n\n});"}, {"source_code": "var values = readline().split(\" \").map(Number);\nvar n = values[1];\nvar d = values[2];\n\nvar oranges = readline().split(\" \").map(Number)\n .filter(x => x <= n)\n .reduce((acc, n) => {\n return acc + n;\n }, 0);\n \nprint(oranges === d ? 0: Math.floor(oranges/d));"}], "src_uid": "06e9649963715e56d97297c6104fbc00"} {"source_code": "T = readline()\r\n \r\nwhile(T--){\r\n n = readline() \r\n x = 0\r\n y = 0\r\n minX = 0\r\n minY = 0\r\n \r\n while(n--){\r\n str = readline().split(' ').map(el => +el)\r\n curx = str[0]\r\n cury = str[1]\r\n \r\n if(curx){\r\n if(curx>0)\r\n x = Math.max(curx, x)\r\n else if(curx<0)\r\n minX = Math.max(Math.abs(curx), minX)\r\n }\r\n \r\n else{\r\n if(cury>0)\r\n y = Math.max(cury, y)\r\n else if(cury<0)\r\n minY = Math.max(Math.abs(cury), minY)\r\n }\r\n }\r\n \r\n ans = (x+y+minX+minY) * 2\r\n \r\n print(ans)\r\n}", "positive_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let ans=0;\r\n let a=0,b=0,c=0,d=0;\r\n for(let j=1;j<=n;j++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n if(!x)\r\n {\r\n a=Math.max(a,y);\r\n b=Math.min(b,y);\r\n }\r\n if(!y)\r\n {\r\n c=Math.max(c,x);\r\n d=Math.min(d,x);\r\n }\r\n // ans+=2*Math.abs(x);\r\n // ans+=2*Math.abs(y);\r\n }\r\n ans+=2*Math.abs(a);\r\n ans+=2*Math.abs(b);\r\n ans+=2*Math.abs(c);\r\n ans+=2*Math.abs(d);\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n const n = parseInt(readline(), 10);\r\n let maxY = 0;\r\n let minY = 0;\r\n let maxX = 0;\r\n let minX = 0;\r\n for (let i = 0; i < n; i++) {\r\n const [x, y] = readline().split(' ').map(Number);\r\n if (x > maxX) maxX = x;\r\n if (x < minX) minX = x;\r\n if (y > maxY) maxY = y;\r\n if (y < minY) minY = y;\r\n }\r\n\r\n let res = Math.abs(maxY) + Math.abs(minY) + Math.abs(maxX) + Math.abs(minX);\r\n res *= 2;\r\n output(res);\r\n }\r\n}\r\n"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline() \r\n x = 0\r\n y = 0\r\n minX = 0\r\n minY = 0\r\n \r\n while(n--){\r\n str = readline().split(' ').map(el => +el)\r\n curx = str[0]\r\n cury = str[1]\r\n\r\n if(curx){\r\n if(curx>0)\r\n x = Math.max(curx, x)\r\n else if(curx<0)\r\n minX = Math.max(Math.abs(curx), minX)\r\n }\r\n \r\n else{\r\n if(cury>0)\r\n y = Math.max(cury, y)\r\n else if(cury<0)\r\n minY = Math.max(Math.abs(cury), minY)\r\n }\r\n }\r\n\r\n ans = (x+y+minX+minY) * 2\r\n \r\n print(ans)\r\n}\r\n"}, {"source_code": "var T = parseInt(readline());\r\nfor (var tt=0; tt parseInt(x));\r\n minx=Math.min(coords[0], minx);\r\n maxx=Math.max(coords[0], maxx);\r\n miny=Math.min(coords[1], miny);\r\n maxy=Math.max(coords[1], maxy);\r\n }\r\n \r\n print(minx*-2+maxx*2+miny*-2+maxy*2);\r\n}"}, {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n var minX = 0, maxX = 0, minY = 0, maxY = 0;\r\n for (var i = 0; i < n; i++) {\r\n var c = readline().split(' ').map(x=>parseInt(x));\r\n minX = Math.min(minX, c[0]);\r\n maxX = Math.max(maxX, c[0]);\r\n minY = Math.min(minY, c[1]);\r\n maxY = Math.max(maxY, c[1]);\r\n }\r\n var dist = (maxX - minX) * 2 + (maxY - minY) * 2;\r\n print(dist);\r\n }"}], "negative_code": [{"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable',function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end',function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n let cnt=0;\r\n for(let i=1;i<=t;i++)\r\n {\r\n let n=parseInt(line[++cnt]);\r\n let ans=0;\r\n for(let j=1;j<=n;j++)\r\n {\r\n let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});\r\n ans+=2*Math.abs(x);\r\n ans+=2*Math.abs(y);\r\n }\r\n console.log(ans);\r\n }\r\n})"}, {"source_code": "T = readline()\r\n\r\nwhile(T--){\r\n n = readline() \r\n x = 0\r\n y = 0\r\n minX = 0\r\n minY = 0\r\n \r\n while(n--){\r\n str = readline().split(' ').map(el => +el)\r\n curx = str[0]\r\n cury = str[1]\r\n\r\n if(curx){\r\n if(curx>0)\r\n x =+ curx\r\n else if(curx<0)\r\n minX =+ Math.abs(curx)\r\n }\r\n \r\n else{\r\n if(cury>0)\r\n y =+ cury\r\n else if(cury<0)\r\n minY =+ Math.abs(cury)\r\n }\r\n }\r\n\r\n ans = (x+y+minX+minY) * 2\r\n \r\n print(ans)\r\n}\r\n\r\n"}], "src_uid": "4af206ae108a483bdb643dc24e4bedba"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('ascii');\nvar inputString=\"\";\nvar currentLine=0;\n\nprocess.stdin.on('data',function(data){\n\tinputString+=data;\n\n});\nprocess.stdin.on('end',function(){\n\tinputString=inputString.split('\\n');\n\tmain();\n \n});\nfunction readline(){\n\treturn inputString[currentLine++];\n}\nfunction main(){\n\tvar t=parseInt(readline());\n\t for(let i=0;i<=t-1;i++){\n\t var arr=readline().split(' ');\n\t drawgiag(arr[0],arr[1]);\n\t}\n}\n\nfunction drawgiag(n,m){\n n=parseInt(n);\n\tm=parseInt(m);\n\tif(n%m==0){\n\t\tconsole.log(\"YES\");\n\t}\n\telse{\n\t\tconsole.log(\"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nconst sol = () => {\n let line = data.trim().split('\\n');\n let t = Number(line.shift());\n let r = [];\n for(let l of line) {\n let [n, m] = l.split(' ').map(Number);\n r.push((n > m && n%m === 0)?\"YES\":\"NO\");\n }\n console.log(r.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "var line = readline();\nfor (var i = 0; i < line; i++)\n print(getDone());\n\nfunction getDone() {\n var lines = readline().split(\" \"); \n return ((lines[0] % lines[1] == 0) ? \"YES\" : \"NO\");\n}"}, {"source_code": "function processItem() {\n var items = readline().split(' ').map(function(i) { return +i; });\n var x = items[0];\n var y = items[1];\n \n print(x % y === 0 ? 'YES' : 'NO');\n}\n\nfunction processItems() {\nvar itemsCount = +readline();\nvar items = [];\n\nfor (var i = 0; i < itemsCount; ++i) {\n processItem();\n}\n\nreturn items;\n}\n\nprocessItems();\n"}, {"source_code": "\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => {\n inputString += inputStd;\n});\n\nprocess.stdin.on('end', function () {\n inputString = inputString.trim().split('\\n').map(str => {\n return str.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const t = +(readLine());\n for (let i = 0; i < t; i++){\n const nums = readLine().split(' ').map(Number);\n const [n, m] = nums;\n const res = n % m;\n console.log((res) ? 'NO' : 'YES');\n }\n \n\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const [n,m] = d.split(' ').map(Number);\n\n if (n % m === 0) {\n console.log('YES');\n }\n else {\n console.log(\"NO\");\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "let input = ''\nprocess.stdin.on('data', c => input += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n main(input.split(EOL))\n})\n\nconst main = (lines) => {\n let n = lines[0] * 1\n \n for (let i = 1; i <= n; i++) {\n let nums = lines[i].split(\" \").map(el => el * 1)\n if (nums[0] % nums[1] === 0) {\n console.log(\"yes\")\n } else {\n console.log(\"no\")\n }\n }\n}"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\nfunction nextInt(){return myconv(next(),1);}\nfunction nextStrArray(){return myconv(next(),2);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u5206\u5272\nfunction nextIntArray(){return myconv(next(),4);}//\u534a\u89d2\u30b9\u30da\u30fc\u30b9 + \u6570\u5024\u5316\nfunction nextCharArray(){return myconv(next(),6);}//1\u6587\u5b57\u5206\u5272\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\n//atcoder\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6700\u5f8c\u306b\u6539\u884c\u5165\u308c\u308b\u3053\u3068\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var m = one[1];\n if(n % m == 0){\n output[i] = \"YES\";\n }else{\n output[i] = \"NO\";\n }\n }\n myout(myconv(output,9));\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin\n});\n\nlet answer = \"\";\n\nlet lines = [];\n\nrl.on('line', (t)=>{\n lines.push(t);\n}).on('close', ()=>{\n let t = parseInt(lines[0]);\n\n for(let i = 1; i <= t; i++)\n {\n let [n,m] = lines[i].split(' ').map(function (x) {\n return parseInt(x);\n });\n\n if(n % m === 0){\n answer += 'YES\\n';\n }\n else{\n answer += 'NO\\n';\n }\n\n }\n\n\n\n\n\n console.log(answer);\n});"}, {"source_code": "const processData = (lines) => {\n const num = +lines[0]\n for (let j =0; j +x)\n if (n%m === 0) {\n console.log('YES')\n } else {\n console.log('NO')\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\n// Write your logic in main();\n// let t = readline().split(' ').map(x => parseInt(x));\nconst main = () => {\n let t = parseInt(readline());\n while (t--) {\n let [n, m] = readline().split(' ').map(x => parseInt(x));\n print((n - m) % m === 0 ? 'YES' : 'NO');\n }\n};\n"}, {"source_code": "function readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var mn = readNumArray();\n var m = mn[0];\n var n = mn[1];\n print(m % n === 0 ? \"YES\" : \"NO\");\n }\n}\nmain()"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', inputStd => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => {\n return str.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n\t const t = +(readLine());\n\t for(let i = 0; i < t; i++) {\n\t \tconst nums = readLine().split(' ').map(Number);\n\t\t const [n, m] = nums;\n\t\t const res = n % m;\n\t\t console.log( (res) ? 'NO' : 'YES' );\n\t }\n}"}, {"source_code": "var __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nfunction main(raw) {\n var lines = raw.trim().split(\"\\n\").map(function (v) { return v.split(\" \").map(function (u) { return parseInt(u, 10); }); });\n var _a = __read(lines.shift(), 1), t = _a[0];\n while (t > 0) {\n var _b = __read(lines.shift(), 2), n = _b[0], m = _b[1];\n console.log((n - m) % m === 0 || (n - m) % n === 0 ? \"YES\" : \"NO\");\n t--;\n }\n}\n(function () {\n var d = \"\";\n process.stdin.on(\"data\", function (c) { return d += c; });\n process.stdin.on(\"end\", function () { return main(d); });\n})();\n"}, {"source_code": "var limit = readline()\n\nwhile(limit > 0){\n var values = readline()\n var valuesSplitted = values.split(\" \")\n if(parseInt(valuesSplitted[0]) % parseInt(valuesSplitted[1]) == 0){\n print(\"YES\")\n }else{\n print(\"NO\")\n }\n limit--\n}"}], "negative_code": [{"source_code": "const readline = require(\"readline\")\n\nfunction* range(n) {\n let index = 0\n while (index < n) yield index++\n}\n\nconst simpleReadline = async () => {\n let rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n let p = new Promise((resolve, reject) => {\n rl.question(\"\", (answer) => {\n rl.close()\n resolve(answer)\n })\n })\n return p\n}\n\nconst main = async () => {\n let n = (await simpleReadline()) * 1\n for await (i of range(n)) {\n let nums = (await simpleReadline()).split(\" \").map((el) => el * 1)\n if (nums[0] % nums[1] === 0) {\n console.log(\"YES\")\n } else {\n console.log(\"NO\")\n }\n }\n}\n\nmain()\n"}, {"source_code": "const init = () => {\n process.stdin.resume();\n process.stdin.setEncoding('utf-8');\n\n let inputString = '';\n let currentLine = 0;\n\n process.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n });\n\n process.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main(); \n });\n\n global.readline = () => {\n return inputString[currentLine++];\n };\n};\n\nif (typeof readline === 'undefined') {\n init();\n}\n\nconst print = (...args) => {\n console.log(...args);\n};\n\n// Write your logic in main();\n// let t = readline().split(' ').map(x => parseInt(x));\nconst main = () => {\n let t = parseInt(readline());\n while (t--) {\n let [n, m] = readline().split(' ').map(x => parseInt(x));\n print(Math.ceil(n / 2) === m ? 'YES' : 'NO');\n }\n};\n"}], "src_uid": "6b37fc623110e49a5e311a2d186aae46"} {"source_code": "/*\r\n* auther yeling\r\n* \r\n* \r\n*/\r\n'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\nfunction print(str) {\r\n console.log(str);\r\n}\r\n\r\n// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');\r\n// main();\r\n// testOutput();\r\n\r\nfunction begin(n) {\r\n if(n%2 == 0) {\r\n print(n/2);\r\n let dis = (n/2) * 3 + 2;\r\n for(let i = 1; i <= n/2; i++) {\r\n print(`${(i - 1) * 3 + 1} ${(i - 1) * 3 + 1 + dis}`);\r\n }\r\n } else {\r\n print(Math.ceil(n/2));\r\n let dis = (n-1)/2 * 3 + 2;\r\n for(let i = 1; i <= Math.floor(n/2); i++) {\r\n print(`${(i - 1) * 3 + 1} ${(i - 1) * 3 + 1 + dis}`);\r\n }\r\n print(`${2} ${n*3}`);\r\n }\r\n\r\n \r\n}\r\n\r\nfunction main() {\r\n var caseNum = parseInt(readline(), 10);\r\n for (var i = 0; i < caseNum; i++) {\r\n var n = parseInt(readline(), 10);\r\n begin(n);\r\n }\r\n}", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tif(n==1) {\r\n\t\tconsole.log(1);\r\n\t\tconsole.log(\"1 3\")\r\n\t} else {\r\n\t\tconsole.log(Math.ceil(n/2));\r\n\t\tfor(var i=1;i<=Math.ceil(n/2);i++) console.log(`${(i*3)-1} ${(n-(i-1))*3}`);\r\n\t}\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n // const arr = Array(n).fill('BAN').join('').split('')\n const k = Math.floor(n / 2)\n const ans = []\n for (let i = 0; i < k; i++) {\n const j = n - 1 - i\n const a = 3 * i + 1\n const b = 3 * j + 2\n ans.push([a + 1, b + 1].join(' '))\n // ;[arr[a], arr[b]] = [arr[b], arr[a]]\n }\n if (n & 1) {\n const j = k\n const a = 3 * j + 1\n const b = 3 * j + 2\n ans.push([a + 1, b + 1].join(' '))\n // ;[arr[a], arr[b]] = [arr[b], arr[a]]\n }\n // console.log(arr.join(''))\n ans.unshift(ans.length)\n return ans.join('\\n')\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n if (n === 1) return `1\\n1 2`;\r\n const res = [],\r\n str = 'BAN'.repeat(n).split('');\r\n for (let l = 0, r = str.length - 1; l < r; l++, r--) {\r\n while (l < r && str[l] !== 'B') {\r\n l++;\r\n }\r\n while (l < r && str[r] !== 'N') {\r\n r--;\r\n }\r\n if (l < r) {\r\n [str[l], str[r]] = [str[r], str[l]];\r\n res.push([l + 1, r + 1]);\r\n }\r\n }\r\n return `${res.length}\\n${res.map(a => a.join(' ')).join('\\n')}`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n if (n == 1) {\r\n console.log(1)\r\n console.log(1, 2)\r\n } else {\r\n const m = parseInt((n+1)/2)\r\n console.log(m)\r\n for(let i = 1; i <= m; i++) {\r\n console.log(i * 3 - 1, (n+1-i)* 3)\r\n }\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n if (n == 1) {\r\n console.log(1)\r\n console.log(1, 2)\r\n } else {\r\n console.log(n-1)\r\n for(let i = 0; i < n-1; i++) {\r\n console.log(i == 0 ? 2 : i + 3, (i+2) * 3)\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\n// your code goes here\r\n\r\n\r\n// declare global variables\r\nvar input_stdin = \"\";\r\nvar lines = \"\";\r\nvar input_currentline = 0;\r\n\r\n// standard input is stored into input_stdin\r\nprocess.stdin.on('data', function (data) {\r\n input_stdin += data;\r\n});\r\n\r\n// standard input is done and stored into an array\r\nprocess.stdin.on('end', function () {\r\n lines = input_stdin.split(\"\\n\");\r\n start();\r\n});\r\n\r\n\r\nfunction start() {\r\n const T = parseInt(lines[0])\r\n let line = 1\r\n for (let t = 1; t <= T; t++) {\r\n const n = parseInt(lines[line++].split(' ')[0], 10)\r\n if (n == 1) {\r\n console.log(1)\r\n console.log(1, 2)\r\n } else {\r\n console.log(n-1)\r\n for(let i = 0; i < n-1; i++) {\r\n console.log(i * 3 + 3, i * 3 + 4)\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n \r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n \r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tif(n==1) {\r\n\t\tconsole.log(1);\r\n\t\tconsole.log(\"1 3\")\r\n\t} else {\r\n\t\tconsole.log(n-1);\r\n\t\tfor(var i=0;i {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction main() {\n let t = parseInt(readline());\n //go go bro!!!\n while(t--) {\n let n = parseInt(readline());\n let a = 0,b = 0,c = 0;\n for(let i = 2; i*i < n; i++) {\n if(n % i == 0) {\n a = i;\n n = n / a;\n break;\n }\n }\n if(a==0) {\n print(\"NO\");\n continue;\n }\n for(let i = a + 1; i*i < n; i++) {\n if(n % i == 0) {\n b = i;\n n = n / b;\n break;\n }\n }\n if(b==0) {\n print(\"NO\");\n continue;\n }\n c = n;\n if(c != 1 && c != a && c != b) {\n print(\"YES\");\n write(a + \" \" + b + \" \" + c + \"\\n\");\n continue;\n } else {\n print(\"NO\");\n continue;\n }\n }\n \n}", "positive_code": [{"source_code": "function solve (n){\n\tvar found = 0;\n\tvar stop = Math.floor(Math.sqrt(n));\n\tfor(var i = 2; i <= stop; i++ )\n\t{\n\t\tif (n%i == 0)\n\t\t{\n\t\t\tif (found < 1){\n\t\t\t\tmySet.add(i);\n\t\t\t\tfound+=1;\n\t\t\t\tn /= i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmySet.add(i);\n\t\t\t\tif (n%i == 0){\n\t\t\t\tmySet.add(n/i);\n\t\t\t\tbreak\n\t\t\t}\n\t\t\telse{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n\tif (mySet.size == 3){\n\t\tprint('YES');\n\t\tvar interim = [...mySet]\n\t\tprint(interim[0],interim[1],interim[2]);\n\t}\n\telse{\n\t\tprint('NO');\n\t}\n}\nvar mySet = new Set();\nvar queries = parseInt(readline())\nfor (var k =0 ;k {\n for (let i = 2; i < Math.cbrt(n); i++) {\n if (n % i === 0) {\n n /= i;\n for (let j = i + 1; j < Math.sqrt(n); j++) {\n if (n % j === 0) return `YES\\n${i} ${j} ${n/j}`;\n }\n }\n }\n return 'NO';\n}\n\nlet t = +readline();\nwhile(t--) print(problem(+readline()));\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var list = getDivisorList(n);\n var yesFlg = false;\n for(var j = 1; j < list.length -2; j++){\n if(yesFlg){break;}\n for(var k = j+1; k < list.length -1; k++){\n if(yesFlg){break;}\n for(var l = k+1; l < list.length; l++){\n if(list[j] * list[k] * list[l] == n){\n yesFlg = true;\n output.push(\"YES\");\n output.push(list[j] + \" \" + list[k] + \" \" + list[l]);\n break;\n }\n }\n }\n }\n if(!yesFlg){\n output.push(\"NO\");\n }\n \n }\n myout(myconv(output,9));\n}\nfunction getDivisorList(val){\n var list = [];\n for(var i = 1; i * i <= val; i++){\n if(val % i == 0){\n list.push(i);\n if(i * i != val){\n list.push(val / i);\n }\n }\n }\n list.sort(function(a,b){ return a - b; });\n return list;\n}"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n findNext();\n }\n}\n\nfunction findNext() {\n var num = +readline();\n var n1 = findDiv(num);\n var n2;\n if (n1) {\n n2 = findDiv(num / n1, n1);\n }\n var n3;\n if (n1 && n2) {\n n3 = (num / n1) / n2\n }\n if (n1 && n2 && (n3 >= 2) && (n3 % 1 === 0) && n3 !== n1 && n3 !== n2) {\n print('YES');\n print(n1 + ' ' + n2 + ' ' + n3);\n } else {\n print('NO');\n }\n};\n\nfunction findDiv(n, ex1) {\n var sqrtN = Math.ceil(Math.sqrt(n));\n for (var i = 2; i < sqrtN; i += 1) {\n if (n % i === 0 && i !== ex1) {\n return i;\n }\n }\n return 0;\n};\n\nmain()"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10), a = 0, b = 0, c = 0, rem, valid = false;\n \n for(var j=2; j<=Math.sqrt(n); j++) {\n if(n%j === 0) {\n a = j;\n rem = n/j;\n \n for(var k=j+1; k<=Math.sqrt(n); k++) {\n if(rem%k === 0) {\n b = k;\n c = rem/k;\n \n if(b !== c) valid = true;\n \n break;\n }\n }\n \n break;\n }\n }\n \n if(a === b || a === c || b === c) valid = false;\n else valid = true;\n \n if(valid) {\n print('YES');\n print(a, b, c);\n \n } else print('NO');\n}"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n var n = parseInt(readline(), 10);\n var ok = false;\n var x=0,y=0,z=0;\n for(var a=2; !ok && a<=Math.sqrt(n); a++) {\n if(n%a != 0) continue;\n for(var b=a+1; !ok && b<=Math.sqrt(n); b++) {\n x = a; y = b; z = n/(a*b);\n if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;\n ok = true;\n }\n }\n if(ok) {\n print('YES');\n print(x,y,z);\n }\n else print('NO');\n}\n\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction findPrimeFactors (num) {\n let primeFactors = [];\n while (num % 2 === 0) {\n primeFactors.push(2);\n num = num / 2;\n }\n\n let sqrtNum = Math.sqrt(num);\n for (let i = 3; i <= sqrtNum; i++) {\n while (num % i === 0) {\n primeFactors.push(i);\n num = num / i;\n }\n }\n\n if (num > 2) {\n primeFactors.push(num);\n }\n return primeFactors;\n}\n\nfunction readInt(a, i) {\n if(i === undefined) return parseInt(a.shift())\n else return parseInt(a[i])\n}\n\nfunction readInts(a, i) {\n if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))\n else return arr[i].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n let i = 0\n const t = readInt(input, i++)\n\n for(let j = 0; j < t; j++) {\n const n = readInt(input, i++)\n\n let p = findPrimeFactors(n)\n let k = 0\n let a = 1, b = 1, c = 1\n let f = true\n if(p[k] === n) {\n wr('NO')\n continue\n }\n for(let len = p.length; k < len; k++) {\n if(k === 0) {\n a = p[k]\n }\n else if(b <= a) {\n b *= p[k]\n }\n else {\n c = n / (a * b)\n break\n }\n }\n if(a === 1 || b === 1 || c === 1 || (b === c) || (b <= a) || (a === c)) {\n wr('NO')\n }\n else {\n wr('YES')\n wr(`${a} ${b} ${c}`)\n }\n }\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10), a, b, c, rem, valid = false;\n \n for(var j=2; j<=Math.sqrt(n); j++) {\n if(n%j === 0) {\n a = j;\n rem = n/j;\n \n for(var k=j+1; k<=Math.sqrt(n); k++) {\n if(rem%k === 0) {\n b = k;\n c = rem/k;\n valid = true;\n break;\n }\n }\n \n break;\n }\n }\n \n if(valid) {\n print('YES');\n print(a, b, c);\n \n } else print('NO');\n}"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n var n = parseInt(readline(), 10);\n var ok = false;\n var x=0,y=0,z=0;\n for(var a=2; !ok && a<=2000; a++) {\n for(var b=a+1; !ok && b<=2000; b++) {\n x = a; y = b; z = n/(a*b);\n if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;\n }\n }\n if(ok) {\n print('YES');\n print(x,y,z);\n }\n else print('NO');\n}\n\n"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n var n = parseInt(readline(), 10);\n var ok = false;\n var x=0,y=0,z=0;\n for(var a=2; !ok && a<=2000; a++) {\n for(var b=a+1; !ok && b<=2000; b++) {\n x = a; y = b; z = n/(a*b);\n if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;\n ok = true;\n }\n }\n if(ok) {\n print('YES');\n print(x,y,z);\n }\n else print('NO');\n}\n\n"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n var n = parseInt(readline(), 10);\n var ok = false;\n var x=0,y=0,z=0;\n for(var a=2; !ok && a<=1000 && a<=n; a++) {\n for(var b=a+1; !ok && b<=1000 && b<=n/a; b++) {\n x = a; y = b; z = n/(a*b);\n if(n%(a*b)==0 && n != a*b && n/(a*b) != a && n/(a*b) != b) {\n ok = true;\n }\n }\n }\n if(ok) {\n print('YES');\n print(x,y,z);\n }\n else print('NO');\n}\n\n"}, {"source_code": "var T = parseInt(readline(), 10);\n\nfor(var t=1; t<=T; t++) {\n var n = parseInt(readline(), 10);\n var ok = false;\n for(var a=2; !ok && a<=1000 && a<=n; a++) {\n for(var b=a; !ok && b<=1000 && b<=n/a; b++) {\n if(n%(a*b)==0) ok = true;\n }\n }\n if(ok) print('YES');\n else print('NO');\n}\n\n"}, {"source_code": "function solve (n){\n\tvar found = 0;\n\tfor(var i = 2; i <= 10; i++ )\n\t{\n\t\tif (found == 2){\n\t\t\tbreak;\n\t\t}\n\t\tif (n%i == 0)\n\t\t{\n\t\t\tif (found < 1){\n\t\t\t\tmySet.add(i);\n\t\t\t\tfound+=1;\n\t\t\t\tn /= i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmySet.add(i);\n\t\t\t\tmySet.add(n/i);\n\t\t\t\tfound +=1;\n\t\t\t}\n\t\t}\n\t}\n\tif (mySet.size == 3){\n\t\tprint('YES');\n\t\tprint([...mySet]);\n\t}\n\telse{\n\t\tprint('NO');\n\t}\n}\nvar mySet = new Set();\nvar queries = parseInt(readline())\nfor (var k =0 ;k Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var out = [];\n var tmpN = n;\n for(var j = 2; j <= Math.sqrt(n); j++){\n if(tmpN % j == 0){\n out.push(j);\n tmpN /= j;\n }\n if(out.length == 2){\n if(out[1] != tmpN && n % tmpN == 0){\n out.push(tmpN);\n }\n break;\n }\n }\n if(out.length == 3){\n output.push(\"YES\");\n output.push(myconv(out,8));\n }else{\n output.push(\"NO\");\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var out = [];\n var tmpN = n;\n for(var j = 2; j <= Math.sqrt(n); j++){\n if(n % j == 0){\n out.push(j);\n tmpN /= j;\n }\n if(out.length == 2){\n if(out[1] != tmpN){\n out.push(tmpN);\n }\n break;\n }\n }\n if(out.length == 3){\n output.push(\"YES\");\n output.push(myconv(out,8));\n }else{\n output.push(\"NO\");\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var out = [];\n var tmpN = n;\n var first = false;\n for(var j = 2; j <= Math.sqrt(n); j++){\n if(tmpN % j == 0 && !first){\n out.push(j);\n tmpN /= j;\n first = true;\n continue;\n }\n if(tmpN % j == 0 && n % (tmpN / j) == 0 && j != tmpN / j){\n out.push(j);\n out.push(tmpN / j);\n break;\n }\n }\n if(out.length == 3){\n output.push(\"YES\");\n output.push(myconv(out,8));\n }else{\n output.push(\"NO\");\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var out = [];\n var tmpN = n;\n for(var j = 2; j <= Math.sqrt(n); j++){\n if(n % j == 0){\n out.push(j);\n tmpN /= j;\n }\n if(out.length == 2){\n if(out[1] != tmpN && n % tmpN == 0){\n out.push(tmpN);\n }\n break;\n }\n }\n if(out.length == 3){\n output.push(\"YES\");\n output.push(myconv(out,8));\n }else{\n output.push(\"NO\");\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = [];\n for(var i = 0; i < t; i++){\n var n = myconv(next(),1);\n var out = [];\n var tmpN = n;\n var first = false;\n for(var j = 2; j <= Math.sqrt(n); j++){\n if(tmpN % j == 0 && !first){\n out.push(j);\n tmpN /= j;\n first = true;\n continue;\n }\n if(tmpN % j == 0){\n if(n % (tmpN / j) == 0){\n out.push(j);\n out.push(tmpN / j);\n break;\n }\n }\n }\n if(out.length == 3){\n output.push(\"YES\");\n output.push(myconv(out,8));\n }else{\n output.push(\"NO\");\n }\n }\n myout(myconv(output,9));\n}\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n findNext();\n }\n}\n\nfunction findNext() {\n var num = +readline();\n var n1 = findDiv(num);\n var n2;\n if (n1) {\n n2 = findDiv(num / n1);\n }\n var n3;\n if (n1 && n2) {\n n3 = (num / n1) / n2;\n }\n if (n1 && n2 && (n3 >= 2) && (n3 % 1 === 0)) {\n print('YES');\n print(n1 + ' ' + n2 + ' ' + n3);\n } else {\n print('NO');\n }\n};\n\nfunction findDiv(n) {\n if (n % 2 === 0) {\n return 2;\n }\n var sqrtN = Math.ceil(Math.sqrt(n));\n for (var i = 3; i < sqrtN; i += 2) {\n if (n % i === 0) {\n return i;\n }\n }\n return 0;\n};\nmain()"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10), a, b, c, rem, valid = false;\n \n for(var j=2; j<=Math.sqrt(n); j++) {\n if(n%j === 0) {\n a = j;\n rem = n/j;\n \n for(var k=j+1; k<=Math.sqrt(n); k++) {\n if(rem%k === 0) {\n b = k;\n c = rem/k;\n \n if(b !== c) valid = true;\n \n break;\n }\n }\n \n break;\n }\n }\n \n if(valid) {\n print('YES');\n print(a, b, c);\n \n } else print('NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10), a = 0, b = 0, c = 0, rem, valid = false;\n \n for(var j=2; j<=Math.sqrt(n); j++) {\n if(n%j === 0) {\n a = j;\n rem = n/j;\n \n for(var k=j+1; k<=Math.sqrt(n); k++) {\n if(rem%k === 0) {\n b = k;\n c = rem/k;\n \n if(b !== c) valid = true;\n \n break;\n }\n }\n \n break;\n }\n }\n \n if(a === b || a === c || b === c) valid = false;\n else valid = true;\n \n if(valid) {\n print('YES');\n print(a, b, c, n);\n \n } else print('NO');\n}"}, {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var n = parseInt(readline(), 10), a, b, c, rem, valid = false;\n \n for(var j=2; j<=Math.sqrt(n); j++) {\n if(n%j === 0) {\n a = j;\n rem = n/j;\n \n for(var k=j+1; k<=Math.sqrt(n); k++) {\n if(rem%k === 0) {\n b = k;\n c = rem/k;\n \n if(b !== c) valid = true;\n \n break;\n }\n }\n \n break;\n }\n }\n \n if(a === b || a === c || b === c) valid = false;\n else valid = true;\n \n if(valid) {\n print('YES');\n print(a, b, c);\n \n } else print('NO');\n}"}], "src_uid": "0f7ceecdffe11f45d0c1d618ef3c6469"} {"source_code": "var input = readline();\nvar aWordsCount = parseInt(input.split(\" \")[0]);\nvar bWordsCount = parseInt(input.split(\" \")[1]);\n\nvar aWords = readWordList(aWordsCount);\nvar bWords = readWordList(bWordsCount);\nvar commonWords = new Set(intersect(aWords, bWords));\n\nvar result = \"YES\";\nvar advantage = commonWords.size % 2 === 0 ? 0 : 1;\nif (aWordsCount - commonWords.size + advantage <= bWordsCount - commonWords.size) {\n result = \"NO\"; \n}\n\nprint(result);\n\nfunction readWordList(listLength) {\n var words = [];\n\n for (var i = 0; i < listLength; i++) {\n words.push(readline());\n }\n\n return words;\n}\n\nfunction intersect(a, b) {\n return a.filter(x => b.includes(x));\n}", "positive_code": [{"source_code": " var s = readline().split(' ');\n var n = +s[0], m = +s[1];\n var set = [], nw = 0, mw = 0, sh = 0;\n for (var i=0;i0 && h==0 || mw>0 && h==1)\n {\n if (h)\n {\n mw--;\n if (sh){ sh--; nw--; }\n }\n else\n {\n nw--;\n if (sh){ sh--; mw--; }\n }\n h = 1 - h;\n }\n print(h ? 'YES' : 'NO');\n"}], "negative_code": [{"source_code": "var input = readline();\nvar aWordsCount = parseInt(input.split(\" \")[0]);\nvar bWordsCount = parseInt(input.split(\" \")[1]);\n\nvar aWords = readWordList(aWordsCount);\nvar bWords = readWordList(bWordsCount);\nvar commonWords = new Set(intersect(aWords, bWords));\naWordsCount -= commonWords.size;\nbWordsCount -= commonWords.size;\n\nvar result = \"NO\";\nif (commonWords.size % 2 === 0) {\n if (aWordsCount > bWordsCount + 1) {\n result = \"YES\";\n } \n} else if (aWordsCount > bWordsCount - 1) {\n result = \"YES\"\n}\n\nprint(result);\n\nfunction readWordList(listLength) {\n var words = [];\n\n for (var i = 0; i < listLength; i++) {\n words.push(readline());\n }\n\n return words;\n}\n\nfunction intersect(a, b) {\n return a.filter(x => b.includes(x));\n}"}, {"source_code": "var input = readline();\nvar aWordsCount = parseInt(input.split(\" \")[0]);\nvar bWordsCount = parseInt(input.split(\" \")[1]);\n\nvar aWords = readWordList(aWordsCount);\nvar bWords = readWordList(bWordsCount);\nvar commonWords = new Set(intersect(aWords, bWords));\n\naWords = aWords.sort((a, b) => {\n return sortByPresenceInSet(a, b, commonWords);\n});\nbWords = bWords.sort((a, b) => {\n return sortByPresenceInSet(a, b, commonWords);\n});\n\nvar usedWords = new Set();\nvar roundsCount = Math.max(aWordsCount, bWordsCount) + 1;\nvar result = \"YES\";\n\nfor (var i = 0; i < roundsCount; i++) {\n var a = useWord(usedWords, aWords);\n if (!a) {\n result = \"NO\";\n break;\n }\n\n var b = useWord(usedWords, bWords);\n if (!b) {\n break;\n }\n}\n\nprint(result);\n\nfunction useWord(usedWords, availableWords) {\n if (!availableWords.length) {\n return false;\n }\n\n if (usedWords.has(availableWords[0])) {\n availableWords.splice(0, 1)\n return useWord(usedWords, availableWords);\n }\n\n usedWords.add(availableWords[0])\n\n return true;\n}\n\nfunction readWordList(listLength) {\n var words = [];\n\n for (var i = 0; i < listLength; i++) {\n words.push(readline());\n }\n\n return words;\n}\n\nfunction intersect(a, b) {\n return a.filter(x => b.includes(a));\n}\n\nfunction sortByPresenceInSet(a, b, set) {\n if (commonWords.has(a)) {\n return -1;\n };\n\n if (commonWords.has(b)) {\n return 1\n };\n\n return 0;\n}"}, {"source_code": "var input = readline();\nvar aWordsCount = parseInt(input.split(\" \")[0]);\nvar bWordsCount = parseInt(input.split(\" \")[1]);\n\nvar aWords = readWordList(aWordsCount);\nvar bWords = readWordList(bWordsCount);\nvar commonWords = new Set(intersect(aWords, bWords));\n\nvar result = \"NO\";\nif (commonWords.size % 2 === 0 && aWordsCount >= bWordsCount) {\n result = \"YES\";\n}\n\nprint(result);\n\nfunction readWordList(listLength) {\n var words = [];\n\n for (var i = 0; i < listLength; i++) {\n words.push(readline());\n }\n\n return words;\n}\n\nfunction intersect(a, b) {\n return a.filter(x => b.includes(x));\n}"}, {"source_code": "var input = readline();\nvar aWordsCount = parseInt(input.split(\" \")[0]);\nvar bWordsCount = parseInt(input.split(\" \")[1]);\n\nvar aWords = [];\nvar bWords = [];\n\nfor (var i = 0; i < aWordsCount; i++) {\n aWords.push(readline());\n}\n\nfor (var i = 0; i < bWordsCount; i++) {\n bWords.push(readline());\n}\n\nvar usedWords = new Set();\nvar roundsCount = Math.max(aWordsCount, bWordsCount) + 1;\nvar result = \"YES\";\n\nfor (var i = 0; i < roundsCount; i++) {\n var a = useWord(usedWords, aWords);\n if (!a) {\n result = \"NO\";\n break;\n }\n\n var b = useWord(usedWords, bWords);\n if (!b) {\n break;\n }\n}\n\nprint(result);\n\nfunction useWord(usedWords, availableWords) {\n if (!availableWords.length) {\n return false;\n }\n\n if (usedWords.has(availableWords[0])) {\n availableWords.splice(0, 1)\n return useWord(usedWords, availableWords);\n }\n\n usedWords.add(availableWords[0])\n\n return true;\n}"}], "src_uid": "4b352854008a9378551db60b76d33cfa"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar words = [];\n\tfor (var i = 0; i < 3; ++i) {\n\t\twords.push(trim(readline()).toLowerCase().replace(/[-;_]/g, ''));\n\t}\n\tvar a = words[0], b = words[1], c = words[2],\n\t\tsentences = [a+b+c, a+c+b, b+a+c, b+c+a, c+a+b, c+b+a],\n\t\tn = parseInt(readline());\n\tfor (var i = 0; i < n; ++i) {\n\t\tvar input = trim(readline()).toLowerCase().replace(/[-;_]/g, '');\n\t\tfor (var j = 0; j < 6; ++j) {\n\t\t\tif (input == sentences[j]) {\n\t\t\t\tprint('ACC');\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (j == 6) {\n\t\t\tprint('WA');\n\t\t}\n\t}\n}\n\nmain();\n", "positive_code": [{"source_code": "'use strict'\n\nlet A = readline().toLowerCase().replace(/[_;-]/g, '')\nlet B = readline().toLowerCase().replace(/[_;-]/g, '')\nlet C = readline().toLowerCase().replace(/[_;-]/g, '')\nlet N = readline()\n\nlet vars = [\n A + B + C,\n A + C + B,\n B + A + C,\n B + C + A,\n C + A + B,\n C + B + A\n]\n\nlet R\n\nwhile (R = readline()) {\n R = R.toLowerCase().replace(/[_;-]/g, '')\n let ok = false\n for (let i = 0; i < vars.length; i++) {\n if (vars[i] == R) {\n ok = true\n break\n }\n }\n print(ok ? 'ACC' : 'WA')\n}"}], "negative_code": [{"source_code": "'use strict'\n\nlet A = readline().toLowerCase().replace(/[_;-]/g, '')\nlet B = readline().toLowerCase().replace(/[_;-]/g, '')\nlet C = readline().toLowerCase().replace(/[_;-]/g, '')\nlet N = readline()\n\nlet vars = [\n A + B + C,\n A + C + B,\n B + A + C,\n B + C + A,\n C + A + B,\n C + B + A\n]\n\nlet R = readline()\n\nwhile (R = R && R.toLowerCase().replace(/[_;-]/g, '')) {\n let ok = false\n for (let i = 0; i < vars.length; i++) {\n if (vars[i] == R) {\n ok = true\n break\n }\n }\n print(ok ? 'ACC' : 'WA')\n R = readline()\n}"}], "src_uid": "95ccc87fe9e431f9c6eeffeaf049f797"} {"source_code": "var t = parseInt(readline());\n\nfunction mapper(s) { return +s; }\n \nfor(var qq = 0; qq < t; qq++) {\n var line = readline().split(' ').map(mapper);\n var n = line[0];\n var k = line[1];\n var a = readline().split(' ').map(mapper);\n var al = a.length;\n\n var max = 0;\n var left = -1;\n var curCount = 0;\n var pikes = [];\n \n for(var i = 0; i < al; i++) {\n pikes[i] = 0;\n }\n \n for(var i = al - 2; i >= 0; i--) {\n var idx = Math.min(i + k - 1, al - 1);\n\n if (pikes[idx]) {\n curCount -= 1;\n }\n\n if (a[i + 1] > a[i] && a[i + 1] > a[i + 2]) {\n pikes[i + 1] = ++curCount;\n \n if (curCount >= max) {\n max = curCount;\n left = i;\n }\n } else {\n pikes[i] = 0;\n }\n \n if (curCount === max) {\n left = i;\n }\n }\n print(max + 1, left + 1);\n\n}", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let range = readline();\n for(let r=0;r parseInt(x));\n let n = data[0];\n let k = data[1];\n let a = readline().split(\" \").map(x => parseInt(x));\n let count = 0;\n let peak = new Array(a.length).fill(false);\n \n for(let i=1;i a[i-1] && a[i] > a[i+1]) {\n \n peak[i] = true;\n }\n }\n \n let sum = 0;\n\n for(let i=1;i max) {\n max = sum;\n start = counter + 1;\n }\n \n counter++;\n }\n \n console.log((max+1) + \" \" + start);\n }\n \n}"}], "negative_code": [], "src_uid": "8e182e0acb621c86901fb94b56ff991e"} {"source_code": "var all = [];\nfor(var i=0;i<100001;i++){\n all[i] = 0;\n}\n\nfunction calculate(num) {\n\n var half = Math.floor(Math.sqrt(num)) + 1;\n\n for (var i=1; i < half; i++) {\n if(num % i === 0 && i*i != num){\n all[i]++;\n all[num/i]++;\n } else if(num % i === 0){\n all[i]++;\n }\n }\n}\n\nfunction main() {\n var s1 = readline();\n var numbers = readline().split(' ').map(Number);\n numbers.map(calculate);\n all[1] = 1;\n all[0] = 0;\n print(Math.max(...all))\n}\n\nmain()", "positive_code": [{"source_code": "\nfunction main()\n{\n var n = Number(readline());\n var a = readline().split(' ').map( Number );\n \n var c = {};\n \n a.forEach( function( x ) {\n var t = ~~( Math.sqrt( x ) );\n for ( var i=2 ; i<=t ; i++ )\n {\n if ( x % i == 0 )\n {\n c[ i ] = c[i] ? c[i]+1 : 1;\n while ( x%i == 0 ) x /= i;\n }\n }\n if ( x )\n {\n c[ x ] = c[x] ? c[x]+1 : 1;\n }\n } );\n \n var ans = c[1] ? 1 : 0;\n delete c[1];\n for ( var i in c ) ans = Math.max( ans , c[i] );\n \n print( ans );\n \n} main();\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var all = [];\nfor(var i=0;i<100001;i++){\n all[i] = 0;\n}\n\nfunction calculate(num) {\n\n var half = Math.floor(Math.sqrt(num)) + 1;\n if(num == 1){\n return;\n }\n if(num==2){\n all[2]++\n return;\n }\n if(num==3){\n all[3]++;\n return;\n }\n\n for (var i=1; i < half; i++) {\n if(num % i === 0 && i*i != num){\n all[i]++;\n all[num/i]++;\n } else if(num % i === 0){\n all[i]++;\n }\n }\n}\n\nfunction main() {\n var s1 = readline();\n var numbers = readline().split(' ').map(Number);\n numbers.map(calculate);\n all[1] = 1;\n all[0] = 0;\n print(Math.max(...all))\n}\n\nmain()"}], "negative_code": [{"source_code": "var all = [];\nfor(var i=0;i<100001;i++){\n all[i] = 0;\n}\n\nfunction calculate(num) {\n\n var half = Math.floor(Math.sqrt(num)) + 1;\n if(num == 1){\n return;\n }\n if(num==2){\n all[2]++\n return;\n }\n if(num==3){\n all[3]++;\n }\n\n for (var i=1; i < half; i++) {\n if(num % i === 0 && i*i != num){\n all[i]++;\n all[num/i]++;\n } else if(num % i === 0){\n all[i]++;\n }\n }\n}\n\nfunction main() {\n var s1 = readline();\n var numbers = readline().split(' ').map(Number);\n numbers.map(calculate);\n all[1] = 1;\n all[0] = 0;\n print(Math.max(...all))\n}\n\nmain()"}, {"source_code": "var all = [];\nfor(var i=0;i<100001;i++){\n all[i] = 0;\n}\n\nfunction calculate(num) {\n\n var half = Math.floor(Math.sqrt(num)) + 1;\n if(num == 1){\n return;\n }\n if(num==2){\n all[2]++\n return;\n }\n if(num==3){\n all[3]++;\n }\n\n for (var i=1; i < half; i++) {\n if(num % i === 0 && i*i != num){\n all[i]++;\n all[num/i]++;\n } else if(num % i === 0){\n all[i]++;\n }\n }\n}\n\nfunction main() {\n var s1 = readline();\n var numbers = readline().split(' ').map(Number);\n numbers.map(calculate);\n all[1] = 0;\n all[0] = 0;\n print(Math.max(...all))\n}\n\nmain()"}, {"source_code": "\nfunction main()\n{\n var n = Number(readline());\n var a = readline().split(' ').map( Number );\n \n var c = {};\n \n a.forEach( function( x ) {\n var t = ~~( Math.sqrt( x ) );\n for ( var i=2 ; i<=t ; i++ )\n {\n if ( x % i == 0 )\n {\n c[ i ] = c[i] ? c[i]+1 : 1;\n while ( x%i == 0 ) x /= i;\n }\n }\n if ( x )\n {\n c[ x ] = c[x] ? c[x]+1 : 1;\n }\n } );\n \n var ans = 0;\n for ( var i in c ) ans = Math.max( ans , c[i] );\n \n print( ans );\n \n} main();\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nfunction main()\n{\n var n = Number(readline());\n var a = readline().split(' ').map( Number );\n \n var c = {};\n \n a.forEach( function( x ) {\n var t = ~~( Math.sqrt( x ) );\n for ( var i=2 ; i<=t ; i++ )\n {\n if ( x % i == 0 )\n {\n c[ i ] = c[i] ? c[i]+1 : 1;\n while ( x%i == 0 ) x /= i;\n }\n }\n if ( x )\n {\n c[ x ] = c[x] ? c[x]+1 : 1;\n }\n } );\n \n var ans = 0;\n delete c[1];\n for ( var i in c ) ans = Math.max( ans , c[i] );\n \n print( ans );\n \n} main();\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "eea7860e6bbbe5f399b9123ebd663e3e"} {"source_code": "var r = readline();\nvar t= readline().split(' ').map(Number).reduce((a,c,i)=>{\n a[c].push(i+1)\n return a;\n}, { 1:[], 2:[], 3:[] });\n\nvar min = Math.min(t[1].length, t[2].length, t[3].length);\n\tprint(min);\n\tfor (var i=0; i 0){\n\twrite(\"\\n\");\n\tfor(i = 0; i < Math.min(p.length,m.length,s.length); i++){\n\t\twrite( (i == Math.min(p.length,m.length,s.length)-1) ? (p[i] + \" \" + m[i] + \" \" + s[i]) : (p[i] + \" \" + m[i] + \" \" + s[i] + \"\\n\") );\n\t}\n}"}, {"source_code": "var x= parseInt(readline());\n\nvar arr = readline().split(' ').map(each => parseInt(each));\n\nvar ones=[], twos=[], threes=[];\nfor(var i=0; iparseInt(x));\nvar t1=[],t2=[],t3=[];\nfor (var i = 0; i < n; i++) {\n\tswitch(t[i]){\n\t\tcase 1:\n\t\t\tt1.push(i+1);\n\t\tbreak;\n\t\tcase 2:\n\t\t\tt2.push(i+1);\n\t\tbreak;\n\t\tcase 3:\n\t\t\tt3.push(i+1);\n\t\tbreak;\n\t}\n}\nvar ans = 0;\nvar teams = [];\nwhile(t1.length>0 && t2.length>0 && t3.length){\n\tvar _t = new Team();\n\t_t.setMember(0,t1.pop());\n\t_t.setMember(1,t2.pop());\n\t_t.setMember(2,t3.pop());\n\tteams.push(_t);\n\tans++;\n}\nprint(ans);\nfor (var i in teams) {\n\tteams[i].print();\n}"}, {"source_code": "///////////////////////////////////////////////////////////////////////////////\nfunction readNumber () { return Number(readline()); }\nfunction readNumbersArray () { return readline().split(' ').map(Number); }\nfunction algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }\n///////////////////////////////////////////////////////////////////////////////\n\nvar n = readNumber();\nvar t = readNumbersArray();\n\nvar prog = 0;\nvar mat = 0;\nvar fiz = 0;\n\nt.forEach(function (v) {\n\tif (v === 1) prog++;\n\tif (v === 2) mat++;\n\tif (v === 3) fiz++;\n});\n\nvar min = Math.min.apply(null, [prog, mat, fiz]);\nprint(min);\n\nif (min > 0) {\n\tvar prog_index = t.indexOf(1) + 1;\n\tvar mat_index = t.indexOf(2) + 1;\n\tvar fiz_index = t.indexOf(3) + 1;\n\n\tfor (var i = 0; i < min; i++) {\n\t\tprint([prog_index, mat_index, fiz_index].join(' '));\n\t\tprog_index = t.indexOf(1, prog_index) + 1;\n\t\tmat_index = t.indexOf(2, mat_index) + 1;\n\t\tfiz_index = t.indexOf(3, fiz_index) + 1;\n\t}\t\n}"}, {"source_code": "'use strict'\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\nreadline();\nlet students = readline().getNumArray();\nlet dictionary = {\n 1: [],\n 2: [],\n 3: [],\n};\n\nfor (let i = 0; i < students.length; i++) {\n dictionary[students[i]].push(i+1);\n}\n\nlet min = dictionary[1].length;\n\nif (dictionary[2].length < min) {\n min = dictionary[2].length;\n}\n\nif (dictionary[3].length < min) {\n min = dictionary[3].length;\n}\nwrite(min + '\\n');\n\nfor (let i = 0; i < min; i++) {\n write(dictionary[1][i] + ' ' + dictionary[2][i] + ' ' + dictionary[3][i] + '\\n');\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var one = new Set();\n var two = new Set();\n var three = new Set();\n for(var i = 0; i < N; i++){\n switch(list[i]){\n case 1:\n one.add(i + 1);\n break;\n case 2:\n two.add(i + 1);\n break;\n case 3:\n three.add(i + 1);\n break;\n }\n }\n var sizeMin = Math.min.apply(null, [one.size, two.size, three.size]);\n myout(sizeMin);\n var oneList = Array.from(one);\n var twoList = Array.from(two);\n var threeList = Array.from(three);\n for(var i = 0; i < sizeMin; i++){\n myout(oneList[i] + \" \" + twoList[i] + \" \" + threeList[i]);\n }\n}\n"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const children = inputs[0]\n const skills = inputs[1].split(' ');\n let teams = [];\n let prgrammingSkills = [];\n let mathSkills = [];\n let physicsSkills = [];\n\n if (Math.floor(children / 3) < 1) return console.log(0);\n\n skills.forEach((skill, i) => {\n if (skill == 1) prgrammingSkills.push({ index: ++i });\n if (skill == 2) mathSkills.push({ index: ++i })\n if (skill == 3) physicsSkills.push({ index: ++i });\n })\n\n if (prgrammingSkills.length === 0 || mathSkills.length === 0 || physicsSkills.length === 0)\n return console.log(0);\n\n let estimatedTeams = Math.min(prgrammingSkills.length, mathSkills.length, physicsSkills.length);\n\n console.log(estimatedTeams)\n for (let i = 0; i < estimatedTeams; i++) {\n console.log(prgrammingSkills[i].index, mathSkills[i].index, physicsSkills[i].index);\n }\n\n\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction print(s) {\n process.stdout.write(`${s}`);\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n // input\n const n = +readline();\n let a = readline().split(' ').map(x => parseInt(x));\n let t1 = 0, t2 = 0, t3 = 0;\n const r = [];\n while (t1 < n && t2 < n && t3 < n) {\n if (a[t1] !== 1) {\n t1++;\n continue;\n }\n if (a[t2] !== 2) {\n t2++;\n continue;\n }\n if (a[t3] !== 3) {\n t3++;\n continue;\n }\n r.push(`${t1 + 1} ${t2 + 1} ${t3 + 1}\\n`);\n t1++;\n t2++;\n t3++;\n }\n print(`${r.length}\\n`);\n r.forEach(x => print(x));\n}\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const people = d.split(' ').map(Number);\n const programming = [];\n const math = [];\n const pe = [];\n\n people.forEach((x, idx) => {\n if (x === 1) {\n programming.push(idx + 1);\n }\n else if (x === 2) {\n math.push(idx + 1);\n }\n else {\n pe.push(idx + 1);\n }\n });\n\n const ans = Math.min(programming.length, math.length, pe.length);\n console.log(ans);\n\n for (let i = 0; i < ans; i++) {\n console.log(`${programming[i]} ${math[i]} ${pe[i]}`);\n }\n\n c++;\n});\n\nrl.on('close', () => {\n\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n] = readint();\n let arr = readint();\n let t = [...arr];\n t.sort((a,b)=> (a - b));\n let ans = 6000;\n let cur = t[0];\n let count = 0;\n let proper = 0;\n t.forEach(element => {\n if(element == cur) count++;\n else {\n cur = element;\n ans = min(ans, count);\n count = 1;\n proper++; \n }\n });\n ans = min(ans, count);\n if(proper < 2) print(0);\n else {\n print(ans);\n for(let i = 0; i < ans; i++) {\n let j = 3;\n cur = 1;\n while(j--) {\n for(let k = 0; k < arr.length; k++) {\n if(arr[k] == cur) {\n write((k + 1) + \" \");\n arr[k] = 0;\n break;\n }\n } \n cur++; \n } \n console.log(); \n } \n }\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n let [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n const map = {};\n nums.forEach((x, i) => {\n if (map[x] === undefined) map[x] = [i+1]\n else map[x].push(i+1);\n });\n\n if (map[1] === undefined || map[2] === undefined || map[3] === undefined) {\n console.log(0); return;\n }\n\n let answ = Math.min(map[1].length, map[2].length, map[3].length);\n console.log(answ);answ\n \n for (let i = 0; i < answ; i += 1) {\n console.log(`${map[1].pop()} ${map[2].pop()} ${map[3].pop()}`)\n }\n}); \n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readLine=()=> inputString[currentLine++];\n/* ================================================ \n Main Solution Starts Here \n===================================================*/\n\nconst main=()=>{\n\tlet n=+readLine()\n\tlet one = 0,two=0,three=0\n\tlet o=[],t=[],th=[]\n\tlet ls = readLine().split(\" \").map((n,index)=>{\n\t\tif(n==='1')\n\t\t\tone++ , o.push(index+1)\n\t\telse if (n==='2')\n\t\t\ttwo++ , t.push(index+1)\n\t\telse if(n==='3') three++, th.push(index+1)\n\treturn +n\n\t})\n\tlet teams = Math.min(one,Math.min(two,three))\n\tif(teams){\n\t\tconsole.log(teams)\n\t\tfor(let i=0;i Number(num));\n}\n\n/**\n * \n * @param {*} num1 \n * @param {*} num2 \n */\nfunction matrixArray(num1, num2) {\n return Array(num1).fill(Array(num2));\n}\n\nlet log = function () {\n return Function.prototype.bind.call(console.log, console, '');\n}();\n\nfunction removeEmptyItem(arr, index) {\n return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));\n}\n\nfunction range(min, max) {\n\n let arr = [];\n for (let index = min; index < max; index++) {\n arr.push(index);\n\n }\n return arr;\n}\n\nfunction main(input) {\n let output = nameLookUp(input);\n // process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.split('\\n');\n let nSpecialites = strToNumArr(splitter(inputs[1], ' '));\n let n = inputs[0];\n\n let teamIndex = [];\n teamIndex[0] = [], teamIndex[1] = [], teamIndex[2] = [];\n\n let maxTeam = Math.floor(n / 2);\n\n for (let index = 0; index < nSpecialites.length; index++) {\n const element = nSpecialites[index];\n if (element == 1) {\n teamIndex[0].push(index + 1);\n }\n if (element == 2) {\n teamIndex[1].push(index + 1);\n }\n if (element == 3) {\n teamIndex[2].push(index + 1);\n }\n }\n let team = Math.min(teamIndex[0].length, teamIndex[1].length, teamIndex[2].length);\n console.log(team);\n for (let index = 0; index < team; index++) {\n const element = nSpecialites[index];\n console.log(teamIndex[0][index] + ' ' + teamIndex[1][index] + ' ' + teamIndex[2][index]);\n }\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet input = [];\nreadline.on('line', line => {\n input.push(line);\n});\nprocess.stdin.on('end', () => {\nconst students = parseFloat(input[0]);\nconst skillMap = { 1:[], 2:[], 3:[] };\nlet skills = input[1].split(' ');\nlet text = '';\nlet count = 0;\nfor (let i=0; i < skills.length; i++) {\n const skill = parseInt(skills[i], 10);\n skillMap[skill].push(i+1);\n if (Object.entries(skillMap).every((a) => a[1].length > 0)) {\n count += 1;\n for (const key in skillMap) {\n text += `${skillMap[key].pop()} `;\n }\n text = text.slice(0, -1);\n text += '\\n';\n }\n}\nconsole.log(count);\nconsole.log(text);\n\n\n});"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .replace(/\\s*$/, \"\")\n .split(\"\\n\")\n .map((str) => str.replace(/\\s*$/, \"\"));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine())\n let arr = readLine().split(' ').map(v => parseInt(v))\n let bla = []\n let ans = []\n if (arr.indexOf(1) == -1 || arr.indexOf(2) == -1 || arr.indexOf(3) == -1) {\n console.log(0)\n } else {\n for (var j = 1; j <= 3; j++) {\n let i = 0;\n while (arr.indexOf(j, i) != -1) {\n bla.push(arr.indexOf(j, i) + 1)\n i += 1\n }\n ans.push([...new Set(bla)]);\n bla = []\n }\n let a = ans.map((value) => value.length)\n console.log(Math.min(...a))\n for (let i = 0; i < Math.min(...a); i++) {\n console.log(ans[0][i], ans[1][i], ans[2][i])\n }\n }\n}"}, {"source_code": "\"use strict\";\n\nvar main = function() {\n var n = +rd();\n var T = [null].concat(rdAr());\n\n var S = new Array(4).fill(null).map(() => []);\n for (var i = 1; i < T.length; ++i) {\n S[T[i]].push(i);\n }\n S.shift();\n\n var r = Math.min(...S.map(v => v.length));\n pr(r);\n \n for (var i = 0; i < r; ++i) {\n prAr(S.map(v => v[i]));\n }\n};\n\nvar rd = readline;\nvar wr = write;\nvar pr = print;\nvar rdAr = () => rd().split(' ').map(v => +v);\nvar prAr = (a) => pr(a.join(' '));\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n\nmain();"}, {"source_code": "n=Number(readline())\n\nT=readline().split(' ').map(Number).reduce((a,c,i)=>{\n a[c].push(i+1)\n return a;\n}, { 1:[], 2:[], 3:[] })\nA=Math.min(T[1].length,T[2].length,T[3].length)\nprint(A)\nfor (i=0;i {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const children = inputs[0]\n const skills = inputs[1].split(' ');\n let teams = [];\n let prgrammingSkills = [];\n let mathSkills = [];\n let physicsSkills = [];\n\n if (Math.floor(children / 3) < 1) return console.log(0);\n\n skills.forEach((skill, i) => {\n if (skill == 1) prgrammingSkills.push({ index: ++i });\n if (skill == 2) mathSkills.push({ index: ++i })\n if (skill == 3) physicsSkills.push({ index: ++i });\n })\n\n if (prgrammingSkills.length === 0 || mathSkills.length === 0 || physicsSkills.length === 0)\n return console.log(0);\n\n let estimatedTeams = Math.min(prgrammingSkills.length, mathSkills.length, physicsSkills.length);\n\n for (let i = 0; i < estimatedTeams; i++) {\n console.log(prgrammingSkills[i].index, mathSkills[i].index, physicsSkills[i].index);\n }\n\n\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n] = readint();\n let arr = readint();\n let t = [...arr];\n t.sort((a,b)=> (a - b));\n let ans = 6000;\n let cur = t[0];\n let count = 0;\n t.forEach(element => {\n if(element == cur) count++;\n else {\n cur = element;\n ans = min(ans, count);\n count = 1; \n }\n });\n if(ans == 6000) print(0);\n else {\n print(ans);\n for(let i = 0; i < ans; i++) {\n let j = 3;\n cur = 1;\n while(--j) {\n arr.some((v, i) => {\n if(v == cur) {\n write((i + 1) + \" \");\n arr[i] = 0;\n if(cur == 3)\n return true;\n else \n cur++;\n }\n });\n } \n console.log(); \n } \n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n] = readint();\n let arr = readint();\n let t = [...arr];\n t.sort((a,b)=> (a - b));\n let ans = 6000;\n let cur = t[0];\n let count = 0;\n let proper = 0;\n t.forEach(element => {\n if(element == cur) count++;\n else {\n cur = element;\n ans = min(ans, count);\n count = 1;\n proper++; \n }\n });\n if(proper < 2) print(0);\n else {\n print(ans);\n for(let i = 0; i < ans; i++) {\n let j = 3;\n cur = 1;\n while(--j) {\n arr.some((v, i) => {\n if(v == cur) {\n write((i + 1) + \" \");\n arr[i] = 0;\n if(cur == 3)\n return true;\n else \n cur++;\n }\n });\n } \n console.log(); \n } \n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n] = readint();\n let arr = readint();\n let t = [...arr];\n t.sort((a,b)=> (a - b));\n let ans = 6000;\n let cur = t[0];\n let count = 0;\n t.forEach(element => {\n if(element == cur) count++;\n else {\n cur = element;\n ans = min(ans, count);\n count = 1; \n }\n });\n if(t[t.length - 1] < 3) print(0);\n else {\n print(ans);\n for(let i = 0; i < ans; i++) {\n let j = 3;\n cur = 1;\n while(--j) {\n arr.some((v, i) => {\n if(v == cur) {\n write((i + 1) + \" \");\n arr[i] = 0;\n if(cur == 3)\n return true;\n else \n cur++;\n }\n });\n } \n console.log(); \n } \n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readint() {\n let line = readline().split(' ').map(function(num) {\n return parseInt(num);\n });\n return line;\n}\n\nfunction readfloat() {\n let line = readline().split(' ').map(function(num) {\n return parseFloat(num);\n });\n return line;\n}\n\nfunction print(x) {\n console.log(x);\n}\n\nfunction write(x) {\n process.stdout.write(x);\n}\nfunction min(a,b) {\n if(a > b) return b;\n else return a;\n}\nfunction main() {\n let [n] = readint();\n let arr = readint();\n let t = [...arr];\n t.sort((a,b)=> (a - b));\n let ans = 6000;\n let cur = t[0];\n let count = 0;\n let proper = 0;\n t.forEach(element => {\n if(element == cur) count++;\n else {\n cur = element;\n ans = min(ans, count);\n count = 1;\n proper++; \n }\n });\n if(proper < 2) print(0);\n else {\n print(ans);\n for(let i = 0; i < ans; i++) {\n let j = 3;\n cur = 1;\n while(j--) {\n for(let k = 0; k < arr.length; k++) {\n if(arr[k] == cur) {\n write((k + 1) + \" \");\n arr[k] = 0;\n break;\n }\n } \n cur++; \n } \n console.log(); \n } \n }\n}"}, {"source_code": "var students = parseInt(readline());\n\nvar vals = readline().split(\" \").map(Number);\n\nvar obj = {\n \"1\": [],\n \"2\": [],\n \"3\": []\n}\n\nfor (var i = 0; i < vals.length; i++ ) {\n obj[+vals[i]].push(i + 1);\n}\n\nvar total = Math.max(obj[\"1\"].length, obj[\"2\"].length, obj[\"3\"].length);\nprint(total);\n\nfor (var i = 0; i < total; i++) {\n var team = [];\n team.push(obj[\"1\"][i], obj[\"2\"][i], obj[\"3\"][i]);\n print(team.join(\" \"));\n}"}, {"source_code": "var students = parseInt(readline());\n\nvar vals = readline().split(\" \").map(Number);\n\nvar obj = {\n \"1\": [],\n \"2\": [],\n \"3\": []\n}\n\nfor (var i = 0; i < vals.length; i++ ) {\n obj[+vals[i]].push(i + 1);\n}\n\nvar total = Math.max(obj[\"1\"], obj[\"2\"], obj[\"3\"]);\nprint(total);\n\nfor (var i = 0; i < total; i++) {\n var team = [];\n team.push(obj[\"1\"][i], obj[\"2\"][i], obj[\"3\"][i]);\n print(temp.join(\" \"));\n}"}], "src_uid": "c014861f27edf35990cc065399697b10"} {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var A1 = readline().split(' ').map(x => parseInt(x));\n \n var total = A1.reduce((t, a)=> t+a, 0);\n print(total-1);\n}", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n let ans = '';\n let sum = a + b + c;\n\n sum = sum - 1n;\n ans += sum;\n\n console.log(ans)\n\n }\n}"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n let sub = [];\n a = a || 0;\n b = b || (this.length - 1);\n for (let i = a; i <= b; i++) {\n sub.push(this[i])\n if (fn(this[i], i, this)) {\n arr.push(sub);\n sub = [];\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nlet MOD = 998244353\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + MOD) % MOD;\n}\n\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let t = $()\n while (t--) {\n let a = $(3).sort(asc)\n log(a.sum()-1)\n }\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1422/A\n\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet data = [];\nrl.on('line', (input) => {\n data.push(input);\n});\n\nrl.on('close', () => {\n solve(data);\n});\n\nfunction solve(data) {\n\n for (let i = 1; i < data.length; i++) {\n [a, b, c] = data[i].split(\" \").map((x) => parseInt(x));\n\n // Assume a, b, c are the shortest sides\n // The sum of the lengths of the shortest three sides of a quadrilateral must be longer than the longest side.\n\n console.log(a + b + c - 1);\n \n }\n\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n console.log(arr[2] + 1);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n var ans = \"\";\n var sum = a + b + c;\n sum = sum - 1n;\n ans += sum;\n console.log(ans);\n }\n}\n"}, {"source_code": "var ti = parseInt(readline());\nwhile(ti-- > 0) {\n var a = readline().split(' ').map(x => parseInt(x));\n print(Math.max(...a));\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nfunction comp(a, b) {\n return a - b > 0 ? -1 : 1\n}\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort(comp);\n print(arr[0] + arr[2] - arr[1]);\n}"}, {"source_code": "var tc = parseInt(readline()),\n arr,\n a,\n b, \n c,\n x,\n y;\n\nwhile (tc > 0) {\n arr = readline().split(' ');\n a = parseInt(arr[0]);\n b = parseInt(arr[1]);\n c = parseInt(arr[2]);\n\n x = Math.sqrt(a * a + (b - c) * (b - c));\n y = Math.sqrt(a * a + (b + c) * (b + c));\n\n print(Math.ceil(x + 1e-9));\n \n tc--;\n}\n\n"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n console.log(b);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n let ans = \"\";\n const sum = a + b + c;\n\n for (let i = 1; i < 1e5; i++) {\n if (sum > i && BigInt(i) !== a && BigInt(i) !== b && BigInt(i) !== c) {\n ans += BigInt(i);\n console.log(ans);\n break;\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n let ans = \"\";\n const sum = a + b + c;\n\n ans += sum - a;\n console.log(ans);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n arr.sort((a, b) => a - b);\n console.log(arr[1]);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n let ans = \"\";\n const sum = a + b + c;\n\n for (let i = 1; i < 1e5; i++) {\n if (sum > i) {\n ans += i;\n console.log(ans);\n break;\n }\n }\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var value = readLine().split(\" \").map(Number);\n var a = value[0],\n b = value[1],\n c = value[2],\n d;\n d = Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2);\n // console.log(BigInt(d))\n console.log(BigInt(Math.floor(Math.sqrt(Math.abs(d)))));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n var ans = \"\";\n var sum = c + 1n;\n sum += ans;\n console.log(sum);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var value = readLine().split(\" \").map(Number);\n var a = value[0],\n b = value[1],\n c = value[2],\n d;\n d = Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2);\n if (a > 100000000 || b > 100000000 || c > 100000000) {\n console.log(BigInt(Math.floor(Math.sqrt(Math.abs(d)))));\n }\n console.log(Math.floor(Math.sqrt(Math.abs(d))));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var value = readLine().split(\" \").map(Number);\n var a = value[0],\n b = value[1],\n c = value[2],\n d;\n d = Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2);\n console.log(Math.floor(Math.sqrt(d)));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var value = readLine().split(\" \").map(Number);\n var a = value[0],\n b = value[1],\n c = value[2],\n d;\n d = Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2);\n console.log(Math.floor(Math.pow(d, 0.5)));\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var [a, b, c] = readLine()\n .split(\" \")\n .map((n) => BigInt(n));\n\n var ans = \"\";\n var sum = c - 1n;\n sum += ans;\n console.log(sum);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n while (T--) {\n var value = readLine().split(\" \").map(Number);\n var a = value[0],\n b = value[1],\n c = value[2],\n d;\n d = Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2);\n if (a > 100000000 || b > 100000000 || c > 100000000) {\n console.log(parseInt(BigInt(Math.floor(Math.sqrt(Math.abs(d))))));\n }\n console.log(Math.floor(Math.sqrt(Math.abs(d))));\n }\n}\n"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(arr[0] + arr[2]);\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print((arr[2] + arr[1] + 1) / 2 + 1);\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(parseInt((arr[2] + arr[1] + 1) / 2 + 1));\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(arr[0] + arr[1]);\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(arr[1] + arr[3]);\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nfunction comp(a, b) {\n return a - b > 0 ? -1 : 1\n}\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(arr[1] + arr[3]);\n}"}, {"source_code": "var n = parseInt(readline());\n\nfunction trans(v) {\n return parseInt(v);\n}\n\nwhile(n--) {\n var arr = readline().split(' ').map(trans);\n arr.sort();\n print(arr[2] + arr[0] - arr[1] );\n}"}], "src_uid": "40d679f53417ba058144c745e7a2c76d"} {"source_code": "\nfunction main() {\n const is = new Scanner();\n let n, word, possible, container = {};\n for (let i = 'a'.charCodeAt(); i <= 'z'.charCodeAt(); i += 1)\n container[String.fromCharCode(i)] = 0;\n\n\n for (let t = is.nextInt(); t > 0; t -= 1) {\n n = is.nextInt();\n word = is.nextLine();\n for (let i = 0; i < n / 2; i += 1) {\n\n for (var letter in container) {\n if (container.hasOwnProperty(letter)) {\n container[letter] = 0;\n }\n }\n\n if (word[i] === 'a') {\n container.b += 1;\n } else if (word[i] === 'z') {\n container.y += 1;\n } else {\n container[String.fromCharCode(word[i].charCodeAt() + 1)] += 1;\n container[String.fromCharCode(word[i].charCodeAt() - 1)] += 1;\n }\n\n if (word[n - i - 1] === 'a') {\n container.b += 1;\n } else if (word[n - i - 1] === 'z') {\n container.y += 1;\n } else {\n container[String.fromCharCode(word[n - i - 1].charCodeAt() + 1)] += 1;\n container[String.fromCharCode(word[n - i - 1].charCodeAt() - 1)] += 1;\n }\n\n possible = false;\n for (var letter in container) {\n if (container.hasOwnProperty(letter)) {\n if (container[letter] >= 2) {\n possible = true;\n break;\n }\n }\n }\n\n if (!possible)\n break;\n }\n\n console.log(possible ? 'YES' : 'NO');\n }\n}\n\n\n/*\n * Api Scanner\n */\nclass Scanner {\n constructor() {\n this.index = -1;\n this.lines = stdinInput.trim().split('\\n'); // eslint-disable-line\n }\n\n nextLine() {\n this.index += 1;\n return this.lines[this.index].trim();\n }\n\n nextInt() {\n return parseInt(this.nextLine(), 10);\n }\n\n nextDouble() {\n return parseFloat(this.nextLine());\n }\n\n nextArray(fn) {\n const array = this.nextLine().split(' ');\n return fn === String ? array : array.map(fn);\n }\n\n hasNext() {\n return this.index < this.lines.length;\n }\n}\n\nlet stdinInput = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (input) => { stdinInput += input; });\nprocess.stdin.on('end', () => { main(); });\n", "positive_code": [{"source_code": "var tests = parseInt(readline());\n\nwhile(tests--) {\n readline();\n var s = readline();\n solver(s);\n}\n\nfunction solver(s){\n var l = s.length, h = l / 2;\n\n while(--h > -1) {\n if(![0, 2].includes(Math.abs(s.charCodeAt(h) - s.charCodeAt(l - h - 1)))) {\n print(\"NO\");\n return false;\n }\n }\n \n print(\"YES\");\n return true;\n}"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst lines = [];\n\nrl.on('line', input => {\n lines.push(input);\n});\n\nrl.on('close', () => {\n let t = nextInt();\n while (t--) {\n nextInt();\n console.log(checkPalindromicTwist(nextString()));\n }\n});\n\nfunction nextInt() {\n return Number(lines.shift());\n}\n\nfunction nextString() {\n return lines.shift();\n}\n\nfunction same(char1, char2) {\n const a = char1[0].charCodeAt(0);\n const b = char2[0].charCodeAt(0);\n\n if (a === b) {\n return true;\n }\n\n return Math.abs(a - b) === 2;\n}\n\nfunction checkPalindromicTwist(str) {\n for (let i = 0; i < str.length; i++) {\n if (!same(str[i], str[str.length - 1 - i])) {\n return 'NO';\n }\n }\n return 'YES';\n}\n\nmodule.exports = checkPalindromicTwist;\n"}, {"source_code": "var line = '';\n\n/** @param {string} s */\nfunction checkPalindrome(s) {\n for(var i = 0; i < s.length >> 1; i++) {\n var frontChar = s[i],\n backChar = s[s.length - i - 1];\n \n if(backChar !== frontChar) {\n switch(frontChar) {\n case 'a':\n if(backChar !== 'c') return false;\n break;\n case 'z':\n if(backChar !== 'x') return false;\n break;\n default:\n if(Math.abs(backChar.charCodeAt(0) - frontChar.charCodeAt(0)) !== 2) return false;\n break;\n }\n }\n }\n\n return true;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += (input.trim() + '\\n');\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''));\n \n for(var i = 0; i < Number(line[0]); i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});\n"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\n/** @type {{[x: string]: number}} */\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\n/** @param {string} s */\nfunction checkPalindrome(s) {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n \n if(backChar !== frontChar) {\n switch(frontChar) {\n case 'a':\n if(backChar !== 'c') return false;\n break;\n case 'z':\n if(backChar !== 'x') return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''));\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});\n"}, {"source_code": "var line = '';\n\n/** @param {string} s */\nfunction checkPalindrome(s) {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length);\n\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[front.length - i - 1],\n frontCharCode = frontChar.charCodeAt(0),\n backCharCode = backChar.charCodeAt(0);\n \n if(backChar !== frontChar) {\n switch(frontChar) {\n case 'a':\n if(backChar !== 'c') return false;\n break;\n case 'z':\n if(backChar !== 'x') return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n }\n\n return true;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''));\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}], "negative_code": [{"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\nfunction checkPalindrome(s = '') {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n case 'z':\n if(backCharCode !== frontCharCode) return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/);\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\nfunction checkPalindrome(s = '') {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n case 'z':\n if(backCharCode !== frontCharCode) return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n console.log(line);\n line = line.split(/\\n/);\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\nfunction checkPalindrome(s = '') {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n case 'z':\n if(backCharCode !== frontCharCode) return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''));\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\n/** @type {{[x: string]: number}} */\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\n/** @param {string} s */\nfunction checkPalindrome(s) {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n if(backChar !== frontChar && backChar !== 'c') return false;\n break;\n case 'z':\n if(backChar !== frontChar && backChar !== 'x') return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/).map(l => l.replace(/\\r/, ''));\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\nfunction checkPalindrome(s = '') {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n case 'z':\n if(backCharCode !== frontCharCode) return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/);\n console.log(line);\n var n = Number(line[0]);\n\n for(var i = 0; i < n; i++) {\n console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});"}, {"source_code": "var line = '';\n\nvar A = 'a'.charCodeAt(0);\nvar Z = 'z'.charCodeAt(0);\n\nvar m = {};\n\nfor(var i = A; i <= Z; i++) {\n m[String.fromCharCode(i)] = i;\n}\n\nfunction checkPalindrome(s = '') {\n var front = s.slice(0, s.length >> 1),\n back = s.slice(s.length - front.length).split('').reverse().join('');\n\n if(front === back) {\n return true;\n } else {\n for(var i in front) {\n var frontChar = front[i],\n backChar = back[i],\n frontCharCode = m[frontChar],\n backCharCode = m[backChar];\n\n switch(frontChar) {\n case 'a':\n case 'z':\n if(backCharCode !== frontCharCode) return false;\n break;\n default:\n if(Math.abs(backCharCode - frontCharCode) !== 2) return false;\n break;\n }\n }\n\n return true;\n }\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', function(input) {\n line += `${input.trim()}\\n`;\n});\n\nprocess.stdin.on('end', function () {\n line = line.split(/\\n/);\n\n for(var i = 1; i <= Number(line[0]); i*=2) {\n console.log(checkPalindrome(line[i + 1]) ? 'YES' : 'NO');\n }\n\n process.exit(0);\n});\n"}], "src_uid": "cc4cdcd162a83189c7b31a68412f3fe7"} {"source_code": "function main(){\n var citizens = readline();\n var welfares = readline().split(\" \").map(Number);\n\n var i = 0;\n var max = -1;\n var suma = 0;\n while (i input.push(line));\n\nreadLine.on('close', () => {\n const count = parseInt(input[0], 10)\n let maxNum = 0\n const peoples = input[1].split(' ')\n let nowNums = 0\n peoples.forEach(el => {\n const _el = parseInt(el, 10)\n if (_el > maxNum)\n maxNum = _el\n nowNums += _el\n })\n const result = (maxNum * count) - nowNums\n console.log(result)\n})"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var list = nextIntArray();\n var max = Math.max.apply(null, list);\n var sum = 0;\n for(var i = 0; i < N; i++){\n sum += max - list[i];\n }\n myout(sum);\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n const max = Math.max(...arr);\n let ans = 0;\n\n for (let i = 0; i < arr.length; i++) {\n ans += max - arr[i];\n }\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "function solve() {\n\tn = readline()\n\ta = readline().split(' ')\n\tv = Math.max.apply(Math, a)\n\tprint(a.reduce((r,x) => r + v-x, 0))\n}\n\nif (typeof readline !== 'function') {\n let input = [],\n i = 0;\n function print() {\n console.log.apply(null, arguments);\n }\n function readline() {\n return input[i++];\n };\n\n const RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n input.push(line);\n });\n \n RL.on('close', solve);\n} else {\n solve();\n}"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n const max = nums.reduce((prev, next) => next > prev ? next : prev, 0);\n let ans = 0;\n\n nums.forEach(x => ans += max-x);\n console.log(ans);\n});"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n// Write your code here\nfunction nameLookUp(str) {\n\n let inputs = str.trim().split('\\n');\n let citizenCount = +inputs[0];\n let citizensWealth = inputs[1].split(' ');\n let max = Math.max(...citizensWealth);\n let add = 0;\n for (let row of citizensWealth) {\n add += max - row;\n }\n return add.toString();\n\n}\n\n\n\n\n\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine());\n let arr = readLine().split(' ').map(v => parseInt(v));\n arr.sort((a, b) => {\n return b - a;\n })\n let ans = arr.reduce((sum, value) => {\n return sum + Math.max(...arr) - value;\n }, 0)\n console.log(ans);\n}"}, {"source_code": "var n = parseInt(readline());\n\tvar welfare = readline().split(\" \").map(x=>+x);\n\tvar spend=0;\n\tif(welfare.length === 1){\n\t\tspend = 0;\n\t}\n\telse{\n\t\tvar sum = 0;\n\t\tvar maximum = 0;\n\t\tfor(var i = 0; i < n; i++){\n\t\t\tsum += welfare[i];\n\t\t\tmaximum = Math.max(maximum, welfare[i]);\n\t\t}\n\t\tspend = n*maximum-sum;\n\t}\n\tprint(spend);"}, {"source_code": "var res = sol(readline(), readline());\nprint(res);\n\nfunction sol(line1, line2) {\n var input1 = line1.split(\" \").map((x) => Number(x));\n var input2 = line2.split(\" \").map((x) => Number(x));\n\n var n = input1[0];\n var welfare = input2;\n\n var max = -1;\n welfare.map((x) => {\n max = Math.max(max, x)\n });\n\n var sum = 0;\n welfare.map((x) => {\n sum += Math.abs(max - x);\n });\n\n\n return sum;\n}"}, {"source_code": "(function() {\n 'use strict';\n const n = readline();\n const z = readline().split(' ').map(Number);\n var x = Math.max.apply(null, z);\n var y = 0;\n for (let i = 0; i < n; ++i) {\n if (z[i] != x) {\n y += x - z[i];\n }\n }\n print(y);\n \n}());"}, {"source_code": "function main(){\n var citizens = readline();\n var welfares = readline().split(\" \").map(Number);\n\n var max = welfares.reduce((a,b) => a > b ? a : b);\n\n var sum = 0;\n welfares.forEach(function(welfare){\n if(welfare < max)\n sum += (max - welfare);\n });\n\n print(sum);\n}\n\nmain();\n"}, {"source_code": "function readIntTabLine() {\n var l = readline().split(' ')\n for (var i = 0 ; i < l.length ; i++) {\n l[i] = parseInt(l[i])\n }\n return l\n}\n\nvar n = parseInt(readline()),\n as = readIntTabLine(),\n max = as.reduce((s,v,i,a) => Math.max(s,v))\n\nprint(as.reduce((s,v,i,a) => s + max - v, 0))\n"}, {"source_code": "'use strict';\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n};\n\nfunction getMaxMoneyAmount(array) {\n var max = array[0];\n array.map(function (value) {\n if (value > max) {\n max = value;\n }\n });\n return max;\n}\n\nfunction getMoneyToBalancePeople(people) {\n var maxMoneyAmount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMaxMoneyAmount(people);\n var sum = 0;\n people.map(function (value) {\n if (value < maxMoneyAmount) {\n sum += maxMoneyAmount - value;\n }\n });\n return sum;\n}\n\nreadline();\nvar people = readline().getNumArray();\nwrite(getMoneyToBalancePeople(people));"}, {"source_code": "'use strict'\n\nString.prototype.getNumArray = function () {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n });\n}\n\nfunction getMaxMoneyAmount (array) {\n let max = array[0];\n array.map((value) => {\n if (value > max) {\n max = value\n }\n });\n return max;\n}\n\n\nfunction getMoneyToBalancePeople (people) {\n let maxMoneyAmount = getMaxMoneyAmount(people);\n let sum = 0;\n people.map((value) => {\n if (value < maxMoneyAmount) {\n sum += maxMoneyAmount - value;\n }\n });\n return sum;\n}\n\n\nreadline();\nlet people = readline().getNumArray();\nwrite(getMoneyToBalancePeople(people));\n\n\n"}, {"source_code": "\nfunction main()\n{\n var n = Number( readline() );\n var a = readline(' ').split(' ').map( Number );\n \n var sum = a.reduce( (p,n) => p+n , 0 );\n var mx = 0;\n a.forEach( (v) => mx = Math.max( mx , v ) );\n \n var ans = mx*n - sum;\n print(ans);\n} main();\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nfunction main()\n{\n var n = Number( readline() );\n var a = readline(' ').split(' ').map( Number );\n \n var sum = a.reduce( (p,n) => p+n , 0 );\n var max = a.reduce( (p,n) => Math.max(p,n) , 0 );\n \n var ans = max*n - sum;\n print(ans);\n} main();\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "var n = parseInt(readline());\n\tvar welfare = readline().split(\" \").map(x=>+x);\n\tvar totalSpend=0;\n\tif(welfare.length === 1){\n\t\ttotalSpend = 0;\n\t}\n\telse{\n\t\tvar sum = 0;\n\t\tvar maximumBurle = 0;\n\t\tfor(var i = 0; i < n; i++){\n\t\t\tsum += welfare[i];\n\t\t\tmaximumBurle = Math.max(maximumBurle, welfare[i]);\n\t\t}\n\t\ttotalSpend = n*maximumBurle-sum;\n\t}\n print(totalSpend);\n // console.log(spend);"}, {"source_code": "var n =readline();\nvar str = readline().split(\" \");\nvar res=0;\nvar max = Math.max.apply(this, str);\nfor (var i=0; i r + v-x, 0))"}, {"source_code": "var q = readline();\nif (+q < 2) {\n\tprint(\"0\");\n}\nelse {\n\tvar netWorth = readline().split(\" \").map(Number);\n\tvar max = Math.max.apply(Math, netWorth);\n\tprint(netWorth.reduce(function (sum, next) { return sum + max - next; }, 0));\n}"}, {"source_code": "var n = Number(readline());\nvar a = readline().split(' ');\n\nvar m = 0;\nfor(var i=0; i a + (max - v), 0));\n};\n\nvar rd = readline;\nvar pr = print;\nvar rdAr = () => { return rd().split(' ').map( v => +v); };\nvar cmpLt = (a, b) => a - b;\nvar cmpGt = (a, b) => b - a;\n\nmain();"}, {"source_code": "readline()\na=readline().split(' ').map(Number)\nm=Math.max.apply(null,a)\ns=0\na.forEach(q => s += (m-q))\nprint(s)"}, {"source_code": "var n = Number(readline());\nvar a = readline().split(' ');\n\nvar mx = 0;\nfor(var i = 0; i < n; i++)\n mx = Math.max(mx, a[i]);\n\nvar res = 0;\nfor(var i = 0; i < n; i++)\n res += mx - a[i];\n \nprint(res);"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \").map(Number).sort((a,b)=>a-b)\nvar count = 0\narr.forEach(i => count+=arr[n-1]-i)\nprint(count)"}, {"source_code": "var n = readline();\nvar arr = readline().split(\" \").map(Number).sort((a,b)=>a-b)\nvar count = 0\nfor(i=0;icitizens) {\n if (max {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n const sum = array.reduce((acc, v) => acc + v, 0);\n const xorSum = array.reduce((acc, v) => acc ^ v, 0);\n // console.log(array, 'sum, xorSum', sum, xorSum);\n if (sum === 2 * xorSum) {\n console.log(0);\n console.log();\n } else {\n let first = xorSum;\n let second = (sum + first);\n console.log(2);\n console.log(first, second);\n // assert(BigInt(sum) + BigInt(first) + BigInt(second) === BigInt(n) * (BigInt(xorSum) ^ BigInt(first) ^ BigInt(second)), 'Wrong answer 1');\n }\n }\n});\n\nfunction assert(condition, message) {\n if (!condition) {\n throw new Error(message);\n }\n}", "positive_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n const sum = array.reduce((acc, v) => acc + v, 0);\n const xorSum = array.reduce((acc, v) => acc ^ v, 0);\n // console.log(array, 'sum, xorSum', sum, xorSum);\n if (sum === 2 * xorSum) {\n console.log(0);\n console.log();\n } else {\n let first = xorSum;\n if ((sum + first) % 2 === 0) {\n let second = (sum + first);\n console.log(2);\n console.log(first, second);\n // console.log('check sum + first, xorSum ^ first', sum + first, xorSum ^ first);\n // console.log('check first, second, xorSum ^ first ^ second', first, second, xorSum ^ first ^ second, (xorSum ^ first) ^ second);\n // console.log('check first, second, xorSum ^ first ^ second', first, second, xorSum ^ first ^ second, (xorSum ^ first) ^ second);\n // console.log(0 ^ 5952667316);\n // console.log('0 ^ 134523487', 0 ^ 134523487);\n // assert(sum + first + second === 2 * (xorSum ^ first ^ second), 'Wrong answer 1');\n } else {\n let second = 1;\n let third = (sum + first + second);\n console.log(3);\n console.log(first, second, third);\n // assert(sum + first + second + third === 2 * (xorSum ^ first ^ second ^ third), 'Wrong answer 2');\n }\n }\n }\n});\n\nfunction assert(condition, message) {\n if (!condition) {\n throw new Error(message);\n }\n}"}], "negative_code": [{"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n let lines = finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);\n for (let i = 0; i < lines.length; i += 2) {\n const array = lines[i + 1].split(' ').map(Number);\n const sum = array.reduce((acc, v) => acc + v, 0);\n const xorSum = array.reduce((acc, v) => acc ^ v, 0);\n // console.log(array, 'sum, xorSum', sum, xorSum);\n if (sum === 2 * xorSum) {\n console.log(0);\n } else {\n let first = xorSum;\n if ((sum + first) % 2 === 0) {\n let second = (sum + first);\n console.log(first, second);\n // console.log('check', sum + first + second, 2 * (xorSum ^ first ^ second));\n assert(sum + first + second === 2 * (xorSum ^ first ^ second), 'Wrong answer');\n } else {\n let second = 1;\n let third = (sum + first + second);\n console.log(first, second, third);\n assert(sum + first + second + third === 2 * (xorSum ^ first ^ second ^ third), 'Wrong answer');\n }\n }\n }\n});\n\nfunction assert(condition, message) {\n if (!condition) {\n throw new Error(message);\n }\n}"}], "src_uid": "cced3c3d3f1a63e81e36c94fc2ce9379"} {"source_code": "var count = 0;\nvar com;\nvar m = '-'.charCodeAt(0);\nvar p = '+'.charCodeAt(0);\nvar pattern = /:(\\w| )*/;\nvar res = 0;\nwhile((com = readline())) {\n if(com.charCodeAt(0) === m) {\n count--;\n }\n if(com.charCodeAt(0) === p) {\n count++;\n }\n if((com = com.match(pattern))) {\n res += (com[0].length - 1) * count;\n }\n}\nprint(res);", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n\tterminal: false\n});\n\nconst input = [];\nlet members = 0;\nlet traffic = 0;\nrl.on('line', function (line) {\n\tif (line[0] === '+') {\n\t\tmembers++;\n\t} else if (line[0] === '-') {\n\t\tmembers--;\n\t} else {\n\t\ttraffic += (line.length - line.indexOf(':') - 1) * members;\n\t}\n});\n\nrl.on('close', function (cmd) {\n\tconsole.log(traffic);\n\tprocess.exit(0);\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nvar users = [], ans = 0;\n\nrl.on('line', (input) => {\n switch(input[0]){\n case \"+\":\n users.push(input.substring(1));\n break;\n case \"-\":\n let n = users.indexOf(input.substring(1));\n users.splice(n, 1);\n break;\n default:\n //code... input = \"mike:hello\"\n let colonIndex = input.indexOf(\":\");\n let message = input.substring(colonIndex+1);\n ans += users.length * message.length;\n break;\n }\n }).on('close',()=>{\n //\n console.log(ans);\n });\n\n "}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar users = [];\nvar ans = 0;\nrl.on('line', (input) => {\n\n\n //var cmd=input[0];\n var cmd = input.charAt(0);\n\n switch (cmd) {\n case '+': {\n users.push(input.substring(1));\n break;\n }\n case '-': {\n let index = users.indexOf(input.substring(1));\n users.splice(index, 1);\n break;\n }\n default: {\n let index = input.indexOf(':');\n let msg = input.substring(index + 1);\n ans += msg.length * users.length;\n\n break;\n }\n }\n\n\n\n});\n\nrl.on('close', function () {\n console.log(ans);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n/**\n * while(true){\n * string input = Console.ReadLine(); \n * }\n */\n/**\n * 01234\n * input=\"+Mike\"\n * \n * .substr(fromIndex, countLen) c++\n * .substring(fromIndex, endIndex) python\n * 0123456789\n * var s=\"ABCDEFGHIJ\" => \"FGH\"\n * \n * s.substr(5,3)\n * s.substring(5,8)\n * \n */\n/**\n * \n * default=>\n * 0123456789\n * input=\"Mike:hello\"\n * 01234\n * message=\"hello\"\n */\nvar users = [], ans = 0;\nrl.on('line', (input) => {\n // console.log(\"input= %s len= %d\", input, input.length);\n switch (input[0]) {\n case '+':\n users.push(input.substr(1));\n break;\n case '-':\n let elemInd = users.indexOf(input.substr(1));\n users.splice(elemInd, 1);\n break;\n default:\n let colonInd = input.indexOf(':');\n let message = input.substr(colonInd + 1);\n ans += message.length * users.length;\n break;\n\n\n }\n}).on('close', function () {\n // console.log('inside close function');\n console.log(ans);\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar users=[],ans=0;\n\nrl.on('line', (input) => {\n \n switch (input[0]){\n case '+':\n users.push(input.substring(1));\n break;\n case '-':\n users.splice(users.indexOf(input.substring(1)),1);\n break;\n default:\n var message = input.substring(input.indexOf(':') + 1);\n ans += message.length * users.length;\n break;\n }\n }).on('close',()=>{\n console.log(ans);\n });\n\n"}, {"source_code": "function solve(lns) {\n const s = new Set();\n let result = 0;\n for (const ln of lns) {\n const f = ln[0];\n const r = ln.substring(1);\n if (f === '+') {\n s.add(r);\n } else if (f === '-') {\n s.delete(r);\n } else {\n const [_, m] = ln.split(/:/); \n result = result + (m.length * s.size);\n }\n }\n return result;\n}\n\nfunction main(lines) {\n const trim_lines = [];\n for (const line of lines) {\n const t = line.trim();\n if (t.length > 0) {\n trim_lines.push(t);\n }\n }\n const result = solve(trim_lines);\n console.log(result);\n}\n\nasync function processLinesFromStream(rs, pf) {\n const content = [];\n rs.setEncoding(\"utf-8\");\n for await (let chunk of rs) {\n content.push(chunk);\n }\n const lines = content.join('').split(/\\n/);\n const result = pf(lines);\n return result;\n}\n\nprocessLinesFromStream(process.stdin, main);\n"}, {"source_code": "const readline = require('readline');\n\nconst INPUT = 'test.in';\nconst LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';\nconst log = (...args) => {\n LOCAL && console.log(...args)\n};\nlet rl;\nlet lineNr = 0;\n\n/**\n * MAIN\n */\n(async () => {\n const promises = await setup(INPUT);\n await Promise.all(promises);\n process.stdout.write(res.toString());\n})();\n\n\nfunction setup() {\n const promises = []\n rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on('line', (line) => {\n promises.push(work(line, lineNr));\n lineNr++;\n });\n\n rl.on('error', (err) => {\n log('Error:', err);\n });\n\n return new Promise(res => {\n rl.on('close', () => {\n res(promises)\n log('Done!');\n });\n });\n}\n\nlet people = 0;\nlet res = 0;\nasync function work(line, lineNr) {\n if (line.startsWith('+')) {\n people++;\n } else if (line.startsWith('-')) {\n people--;\n } else {\n // console.log(line, line.trim().split(':')[1].length);\n res += (people * (line.trim().split(':')[1].length));\n }\n}\n\n/**\n * \n * Solution goes below\n * \n */\nfunction solve(line) {\n \n}\n"}, {"source_code": "var line;\nvar c=0;\nvar ret=0;\nwhile(line = readline()){\n\tif(line[0] == '+'){\n\t\tc++;\n\t}else if(line[0] == '-'){\n\t\tc--;\n\t}else{\n\t\tret += line.split(':')[1].length * c;\n\t}\n}\nprint(ret);"}, {"source_code": "var counter = 0;\nvar users = [];\nvar cmd = \"\";\nwhile (cmd != undefined) {\n cmd = readline();\n\n if (!cmd) { break; }\n\n switch (cmd.charAt(0)) {\n case \"+\":\n var commer = cmd.slice(1);\n users.push(commer);\n break\n case \"-\":\n var leaver = cmd.slice(1);\n users = users.filter(function (e) { return e != leaver });\n break\n default:\n var msg = cmd.slice(cmd.indexOf(\":\") + 1);\n counter += users.length * msg.length;\n } \n}\nprint(counter);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar users=[], ans=0;\nrl.on('line', (input) => {\n switch(input[0]){\n case '+': \n // here we want to add user in our users array/list\n // for example when input =\"+mike\" we add only mike without + sign\n users.push(input.substr(1));\n break; \n case '-':\n //here we want to remove this user from our users array/list\n // for examle if input = \"-mike\" we remove \"mike\"\n // to remove an element from array we should use splice built in method in javascript\n //so goole that and find out by yourself\n let ind = users.indexOf(input.substr(1));\n users.splice(ind, 1);\n break;\n default:\n // here you decide what you do...\n //good luck......\n let colonInd = input.indexOf(':');\n let msg = input.substr(colonInd+1);\n ans+=msg.length*users.length;\n \n break;\n }//end of switch loop\n}).on('close',()=>{\n //output your answer here when you push ctrl + c\n console.log(ans);\n});"}, {"source_code": "var line\nvar inch = 0\nvar s = 0\nwhile (line = readline()) {\n\tif (line[0] == '-') {inch--; continue}\n\tif (line[0] == '+') {inch++; continue}\n\tvar m = line.split(':')[1]\n\ts += m.length * inch\n}\nprint(s)"}, {"source_code": "t=0;\nn=0;\nwhile (c=readline(),c!=null) {\n\tif (c[0]===\"+\") n++;\n\telse if (c[0]===\"-\") n--;\n\telse {\n\t\tt+=(c.length-c.search(\":\")-1)*n;\n\t}\n}\nprint(t);\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar Users = [],ans = 0;\n\nrl.on('line', (input) => {\n switch(input[0]){\n case '+':\n Users.push(input.substring(1));\n break;\n case '-':\n let ind = Users.indexOf(input.substring(1));\n Users.splice(ind,1);\n break;\n default :\n let indx = input.indexOf(':') + 1; \n let message = input.substring(indx);\n ans += message.length * Users.length;\n break; \n }\n\n}).on('close',()=>{\n console.log(ans);\n});"}, {"source_code": "// Generated by CoffeeScript 1.4.0\n(function() {\n var line, n, t;\n\n n = 0;\n\n t = 0;\n\n while (line = readline()) {\n switch (line[0]) {\n case '+':\n n++;\n break;\n case '-':\n n--;\n break;\n default:\n t += n * (line.length - line.indexOf(':') - 1);\n }\n }\n\n print(t);\n\n}).call(this);\n"}, {"source_code": "var count = 0\nvar attendees = 0\nwhile (line = readline()) {\n if (line[0] == \"+\") {\n attendees++\n }\n if (line[0] == \"-\") {\n attendees--\n }\n if (line[0] != \"+\" && line[0] != \"-\") {\n message = line.substr(line.indexOf(\":\") + 1)\n count += message.length*attendees\n }\n}\n\nprint(count)"}, {"source_code": "function userAdd(user){\n if (userList.indexOf(user) === -1) userList.push(user);\n}\n\nfunction userRemove(user){\n var id = userList.indexOf(user);\n if (id !== -1) userList.splice(id, 1);\n}\n\nfunction send(msg){\n traffic += msg.length * userList.length;\n}\n\nvar i, input, cmd, temp, userList = [], traffic = 0;\n\nwhile (true){\n input = readline();\n if (typeof input === 'undefined') break;\n\n cmd = input.substr(0,1);\n if (cmd === '+') {\n userAdd(input.substr(1));\n } else if (cmd === '-') {\n userRemove(input.substr(1));\n } else {\n send(input.split(':')[1]);\n }\n}\n\nprint(traffic);\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar cont = [];\nvar ans = 0;\n\nrl.on(\"line\", input => {\n \n switch (input[0]) {\n case \"+\":\n cont.push(input.substr(1));\n break;\n case \"-\":\n var ind = cont.indexOf(input.substr(1));\n cont.splice(ind, 1);\n break;\n default:\n var ind = input.indexOf(\":\");\n var msg = input.substr(ind + 1);\n ans += cont.length * msg.length;\n break;\n }\n}).on(\"close\", () => {\n console.log(ans);\n});\n\n/* rl.on('close' ,()=>{\n \n console.log(\"test\")\n\n});*/\n"}, {"source_code": "var users = 0;\nvar mes = 0;\nvar result = 0;\nvar mass = [];\nwhile (line = readline()) {\n line = line.split(\":\")\n if (line[0][0]==\"+\") {\n users++;\n }\n if (line[0][0]==\"-\") {\n users--;\n }\n if (line[1]!=undefined) {\n mes = line[1].length;\n result += mes*users;\n }\n}\n\nwrite(result);"}, {"source_code": "t=0;\nn=0;\nwhile (c=readline()) {\n\tif (c[0]===\"+\") n++;\n\telse if (c[0]===\"-\") n--;\n\telse {\n\t\tt+=(c.length-c.search(\":\")-1)*n;\n\t}\n}\nprint(t);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar users = [];\nvar ans = 0;\nrl.on('line', (input) => {\n // console.log(\"input = %s\",input);\n switch (input[0]) {\n case '+':\n users.push(input.substring(1));\n break;\n case '-':\n users.splice(users.indexOf(input.substring(1)), 1);\n break;\n default:\n var colonIndex = input.indexOf(':');\n var msg = input.substring(colonIndex + 1);\n ans += msg.length * users.length;\n break;\n };\n\n}).on('close', () => {\n console.log(ans);\n});\n\n/*\nrl.on('close', () => {\n console.log(ans);\n});\n*/"}], "negative_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar users = [];\n var ans=0;\nrl.on('line', (input) => {\n if (input != \"\" && input != null) {\n \n //var cmd=input[0];\n var cmd = input.charAt(0);\n\n switch(cmd){\n case '+':{\n users.push(input.substring(1));\n break;\n }\n case '-':{\n let index = users.indexOf(input.substring(1));\n users.splice(index,1);\n break;\n }\n default:{\n let index=input.indexOf(':');\n let msg=input.substring(index+1);\n ans+=msg.length*users.length;\n\n break;\n }\n }\n }\n else{\n console.log(ans);\n rl.close();\n }\n \n});"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nvar cont = [];\nvar ans = 0;\n\nrl.on(\"line\", input => {\n console.log(`Received: ${input}`);\n\n switch (input[0]) {\n case \"+\":\n cont.push(input.substr(1));\n break;\n case \"-\":\n var ind = cont.indexOf(input.substr(1));\n cont.splice(ind, 1);\n break;\n default:\n var ind = input.indexOf(\":\");\n var msg = input.substr(ind + 1);\n ans += cont.length * msg.length;\n break;\n }\n}).on(\"close\", () => {\n console.log(ans);\n});\n\n/* rl.on('close' ,()=>{\n \n console.log(\"test\")\n\n});*/\n"}, {"source_code": "t=0;\nn=0;\nwhile (c=readline(),c!=null) {\n\tif (c[0]===\"+\") n++;\n\telse if (c[0]===\"-\") n--;\n\telse {\n\t\tprint(c.length,c.search(\":\"),n);\n\t\tt+=(c.length-c.search(\":\")-1)*n;\n\t}\n}\nprint(t);\n"}], "src_uid": "d7fe15a027750c004e4f50175e1e20d2"} {"source_code": "var n=+readline(),\na=readline().split(' ').map(Number),\nn1=a.filter(function(v){return v<0;}),\nn2=a.filter(function(v){return v>0;}),\nn3=a.filter(function(v){return v===0;});\nif(n2.length===0){\n\tn2.push(n1.pop());\n\tn2.push(n1.pop());\n}\nif(n1.length%2===0){\n\tn3.push(n1.pop());\n}\nprint(n1.length+' '+n1.join(' '));\nprint(n2.length+' '+n2.join(' '));\nprint(n3.length+' '+n3.join(' '));", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\n\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const [plusArr, minusArr, zeroArr] = [[], [], []];\n for (let i = 0; i < len; i++) {\n if (arr[i] > 0) plusArr.push(arr[i]);\n else if (arr[i] < 0) minusArr.push(arr[i]);\n else zeroArr.push(arr[i]);\n }\n\n if (plusArr.length === 0) {\n plusArr.push(minusArr.pop());\n plusArr.push(minusArr.pop());\n }\n if (minusArr.length % 2 === 0) {\n zeroArr.push(minusArr.pop());\n }\n\n console.log(`${minusArr.length} ${minusArr.join(\" \")}`);\n console.log(`${plusArr.length} ${plusArr.join(\" \")}`);\n console.log(`${zeroArr.length} ${zeroArr.join(\" \")}`);\n}\n"}, {"source_code": "let input = ''\n\n// Input\nprocess.stdin.on('data', line => {\n\tinput += line\n})\n\n// Process\nprocess.stdin.on('end', () => {\n\tconst { EOL } = require('os')\n\tconst lines = input.split(EOL).filter(data => data)\n\t\n\tconst n = +lines[0]\n\tconst numList = lines[1].split(' ').map(num => +num).sort((prev, cur) => prev - cur)\n\tconsole.log(`1 ${numList[0]}`)\n\tif (numList[n - 1] === 0) {\n\t\tconsole.log(`2 ${numList[1]} ${numList[2]}`)\n\t\tconsole.log(`${n - 3} ${numList.slice(3).join(' ')}`)\n\t}\n\telse {\n\t\tconsole.log(`1 ${numList[n - 1]}`)\n\t\tconsole.log(`${n - 2} ${numList.slice(1).slice(0, -1).join(' ')}`)\n\t}\n})"}, {"source_code": ";(function () {\n\tvar n = +readline();\n\tvar c = readline().split(' ').map(Number);\n\n\tprint(1, c.splice(c.indexOf(Math.min.apply(null, c)), 1));\n\tvar m = c.splice(c.indexOf(Math.max.apply(null, c)), 1);\n\tif ( m > 0 ) {\n\t\tprint(1, m);\n\t\tprint(n - 2, c.join(' '));\n\t} else if ( m == 0 ) {\n\t\tprint(2, c.splice(c.indexOf(Math.min.apply(null, c)), 1), c.splice(c.indexOf(Math.min.apply(null, c)), 1));\n\t\tprint(n - 3, c.join(' '), m);\n\t} else {\n\t\tprint(2, m, c.splice(c.indexOf(Math.max.apply(null, c)), 1));\n\t\tprint(n - 3, c.join(' '));\n\t}\n}).call(this);"}, {"source_code": "var a = [], b = [], c = [], r = [];\nreadline();\nreadline().split( ' ' ).forEach( function(item) {\n item = item - '';\n if (item < 0 && r.length < 2) {\n r.push( item );\n } else if (item < 0 && !a.length) {\n a.push( item );\n } else if (item < 0) {\n c.push( item );\n } else if (item > 0) {\n b.push( item );\n } else {\n c.push( item );\n }\n} );\n\nif (!b.length) {\n b.push( r.shift() );\n b.push( r.shift() );\n}\n\nif (!a.length) {\n a.push( r.shift() );\n}\n\nc.push.apply( c, r );\n\nprintArr( a );\nprintArr( b );\nprintArr( c );\n\nfunction printArr(arr) {\n print( arr.length + ' ' + arr.join( ' ' ) );\n}"}], "negative_code": [{"source_code": "let input = ''\n\n// Input\nprocess.stdin.on('data', line => {\n\tinput += line\n})\n\n// Process\nprocess.stdin.on('end', () => {\n\tconst { EOL } = require('os')\n\tconst lines = input.split(EOL).filter(data => data)\n\tconsole.log(lines)\n})"}, {"source_code": "let input = ''\n\n// Input\nprocess.stdin.on('data', line => {\n\tinput += line\n})\n\n// Process\nprocess.stdin.on('end', () => {\n\tconst lines = input.split('\\n')\n\tconsole.log(lines)\n})"}, {"source_code": "let input = ''\n\n// Input\nprocess.stdin.on('data', line => {\n\tinput += line\n})\n\n// Process\nprocess.stdin.on('end', () => {\n\tconst { EOL } = require('os')\n\tconst lines = input.split(EOL)\n\tconsole.log(lines)\n})"}, {"source_code": "var a = [], b = [], c = [], r = [];\nreadline();\nreadline().split( ' ' ).forEach( function(item) {\n item = item - '';\n if (item < 0 && r.length < 2) {\n r.push( item );\n } if (item < 0 && !a.length) {\n a.push( item );\n } else if (item < 0) {\n c.push( item );\n } else if (item > 0) {\n b.push( item );\n } else {\n c.push( item );\n }\n} );\n\nif (!b.length) {\n b.push( r.shift() );\n b.push( r.shift() );\n}\n\nif (!a.length) {\n a.push( r.shift() );\n}\n\nc.push.apply( c, r );\n\nprintArr( a );\nprintArr( b );\nprintArr( c );\n\nfunction printArr(arr) {\n print( arr.length + ' ' + arr.join( ' ' ) );\n}"}, {"source_code": "var a = [], b = [], c = [], r = [];\nreadline();\nreadline().split( ' ' ).forEach( function(item) {\n item = item - '';\n if (item < 0 && r.length < 2) {\n r.push( item );\n } if (item < 0 && !a.length) {\n a.push( item );\n } else if (item < 0) {\n c.push( item );\n } else if (item > 0) {\n b.push( item );\n } else {\n c.push( item );\n }\n} );\n\nif (!b.length) {\n b.push.apply( b, r ); r = [];\n} else if (!a.length) {\n a.push( r.shift() );\n}\n\nc.push.apply( c, r );\n\nprintArr( a );\nprintArr( b );\nprintArr( c );\n\nfunction printArr(arr) {\n print( arr.length + ' ' + arr.join( ' ' ) );\n}"}], "src_uid": "03cf2cc26c84aab685ee78a1d6318b30"} {"source_code": ";(function () {\n\t\n\tprint((function (n) {\n\t\tvar p = -1, h = 0;\n\t\twhile (n--) {\n\t\t\tvar s = +readline();\n\t\t\tp += 2 + Math.abs(s-h);\n\t\t\th = s;\n\t\t}\n\t\treturn p;\n\t})(+readline()));\n\n}).call(this);\n", "positive_code": [{"source_code": "var n=+readline();\nvar ans=0;\nvar prev=0;\nwhile(n--){\n h=+readline();\n ans+=Math.abs(h-prev)+2;\n prev=h;\n}\nprint(ans-1);"}], "negative_code": [], "src_uid": "a20ca4b053ba71f6b2dc05749287e0a4"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n === 3) return -1\n if (n === 5) return '5 4 1 2 3'\n const arr = Array(n)\n if (n & 1) {\n for (let i = 0; i < n; i++) {\n arr[i] = (i & 1) ? i : i + 2\n arr[i] += 3\n }\n arr[n - 3] = 3\n arr[n - 2] = 2\n arr[n - 1] = 1\n } else {\n for (let i = 0; i < n; i++) {\n arr[i] = (i & 1) ? i : i + 2\n }\n }\n return arr.join(' ')\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var p = parseInt(readline().trim());\r\n var o = [], popped = [];\r\n if (p == 3) {\r\n process.stdout.write('-1\\n');\r\n continue;\r\n }\r\n if (p % 2 === 0) {\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o = o.join(' ')\r\n process.stdout.write(o + '\\n');\r\n }\r\n }\r\n } else {\r\n o = [];\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o.reverse()\r\n popped.push(o.pop())\r\n popped.push(o.pop())\r\n o.unshift(popped[1].toString(), popped[0].toString())\r\n process.stdout.write(o.join(' ') + '\\n')\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let n = Number(readline());\r\n let ans = generateFunnyPermutation(n);\r\n console.log(ans === -1 ? -1 : ans.join(\" \"))\r\n }\r\n}\r\n\r\nfunction generateFunnyPermutation(n) {\r\n if (n === 2) return [2,1];\r\n if (n === 3) return -1;\r\n let arr = Array(n);\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = i+1;\r\n }\r\n let mid = Math.floor((n-1)/2);\r\n rotateArr(arr, 0, n-1);\r\n rotateArr(arr, 0, mid);\r\n rotateArr(arr, mid+1, n-1);\r\n \r\n return arr;\r\n}\r\n\r\nfunction rotateArr(arr, s, e) {\r\n let start = s, end = e;\r\n \r\n while (start < end) {\r\n let tmp = arr[start];\r\n arr[start] = arr[end];\r\n arr[end] = tmp;\r\n start++;\r\n end--;\r\n }\r\n}"}, {"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nfunction iInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => parseInt(cur));\r\n}\r\nfunction BInpArr() {\r\n return readline()\r\n .trim()\r\n .split(\" \")\r\n .map((cur) => BigInt(cur));\r\n}\r\nfunction string() {\r\n return readline().trim();\r\n}\r\nfunction stringArr() {\r\n return readline().trim().split(\"\");\r\n}\r\n\r\nfunction stringArr1() {\r\n return readline().trim().split(\" \");\r\n}\r\nfunction getValue() {\r\n return parseInt(readline());\r\n}\r\nfunction iInpArr1() {\r\n return readline()\r\n .trim()\r\n .split(\"\")\r\n .map((cur) => parseInt(cur));\r\n}\r\nlet mod = 1e9 + 7;\r\nmod = BigInt(mod);\r\nconst pow = (num, exp, mod) => {\r\n if (exp === BigInt(0)) return BigInt(1);\r\n let x = pow(num, exp / BigInt(2), mod);\r\n if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;\r\n else return (x * x) % mod;\r\n};\r\nconst inverse = (num, exp) => {\r\n return pow(BigInt(num), BigInt(exp), BigInt(mod));\r\n};\r\nconst sqrt = (n) => {\r\n let low = 1n,\r\n high = n,\r\n ans;\r\n while (low <= high) {\r\n let mid = (low + high) / 2n;\r\n if (mid * mid <= n) {\r\n ans = mid;\r\n low = mid + 1n;\r\n } else high = mid - 1n;\r\n }\r\n return ans;\r\n};\r\n\r\nconst solve = () => {\r\n let t = getValue();\r\n while (t--) {\r\n let n = getValue();\r\n if (n === 3) console.log(-1);\r\n else if (n % 2 === 0)\r\n console.log(\r\n new Array(n)\r\n .fill(0)\r\n .map((a, i) => n - i)\r\n .join(\" \")\r\n );\r\n else {\r\n let k = Math.ceil(n / 2);\r\n let arr = new Array(k).fill(0).map((a, i) => k + i);\r\n for (let i = k - 1; i >= 1; i--) arr.push(i);\r\n console.log(arr.join(\" \"));\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n mufin(); \r\n});\r\n\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n/* let arr = readLine().split(\" \").map((x) => {return parseInt(x)});\r\nlet test = readLine();\r\nwhile(test--)\r\n{\r\n\r\n}\r\n*/\r\nconst y = [];\r\nconst z = [];\r\nlet ptr;\r\nvar gcd = function(a, b) {\r\n if (!b) {\r\n return a;\r\n }\r\n return gcd(b, a % b);\r\n}\r\n\r\nfunction add(x1, y1, z1)\r\n{\r\n y1 = y1 / x1; z1 = z1 / x1;\r\n for(let i = 0; i < ptr; i++)\r\n if ((Math.abs(y1 - y[i]) < 0.000001) && (Math.abs(z1 - z[i]) < 0.000001))\r\n return 0;\r\n y[ptr] = y1; z[ptr] = z1;\r\n return ++ptr;\r\n }\r\n function sort(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n }\r\nfunction triangle(a, b, c)\r\n{\r\n let temp = [a,b,c];\r\n sort(temp,temp+3);\r\n if(!add(temp[0],temp[1],temp[2])) return;\r\n let m = Math.sqrt(2*temp[0]*temp[0] + 2*temp[1]*temp[1] - temp[2]*temp[2]) / 2;\r\n triangle(temp[0],m,temp[2]/2);\r\n triangle(temp[1],m,temp[2]/2);\r\n}\r\nfunction f(n,a,b){\r\n let i;\r\n a[1] = 0; a[2] = 3;\r\n b[1] = 3; b[2] = 6;\r\n for(i = 3; i <= n; i++){\r\n a[i] = a[i-1] + b[i-1];\r\n b[i] = 2 * a[i-1] + b[i-1];\r\n }\r\n return a[n] + b[n];\r\n \r\n}\r\n\r\nfunction ff(n, k) {\r\n if (!n){\r\n return 0;\r\n } \r\n let tmp = 1 << (n - 1);\r\n if (k < tmp) return ff(n - 1, k);\r\n return tmp + ff(n - 1, (1 << n) - 1 - k);\r\n}\r\n\r\nfunction div(val, by){\r\n return (val - val % by) / by;\r\n}\r\nfunction PowMod(x, y, n)\r\n{\r\n console.log(x * x % n)\r\n\tif (y === 0) {\r\n return 1;\r\n }\r\n\tif (y&1){\r\n return x * PowMod(x * x % n, div(y,2), n) % n;\r\n } \r\n\treturn PowMod(x * x % n, div(y,2), n);\r\n}\r\nfunction binomial(n, k) {\r\n if ((typeof n !== 'number') || (typeof k !== 'number')) \r\n return false; \r\n var coeff = 1;\r\n for (var x = n-k+1; x <= n; x++) coeff *= x;\r\n for (x = 1; x <= k; x++) coeff /= x;\r\n return coeff;\r\n}\r\nfunction factorial(x) {\r\n\r\n if (x == 0) {\r\n return 1;\r\n }\r\n else {\r\n return x * factorial(x - 1);\r\n }\r\n}\r\nconst fact = (a, b, c, x, y, z) => {\r\n return Math.sqrt(( x - a )*( x - a ) + ( y - b )*( y - b ) + ( z - c )*( z - c ));\r\n} \r\nfunction app(a,n1,n2,n3)\r\n{\r\n if (a == 0){\r\n return 0;\r\n }\r\n app(a - 1, n1, n3, n2);\r\n if ((n1 + ' ' + n2) === undefined) {\r\n return 0;\r\n }\r\n console.log(n1 + ' ' + n2);\r\n app(a - 1, n3,n2,n1);\r\n}\r\n\r\n\r\n\r\nconst diffDays = (day1, day2) => {\r\n if ((day1[6] !== day2[6] || day1[5] !== day2[5]) || (day1[8] !== day2[8] || day1[9] !== day2[9])) {\r\n return 1;\r\n }\r\n else{\r\n return 0;\r\n }\r\n}\r\n\r\n// 2022-03-19T06:06:00.000Z\r\n// 2022-03-19T04:04:00.000Z\r\nlet pi = 3.14159265359;\r\n\r\nclass Point {\r\n constructor(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n}\r\n//Set.prototype.getByIndex = function(index) { return [...this][index]; }\r\n//let mySet = new Set();\r\nfunction mufin() {\r\n let k = readLine();\r\n while(k--){\r\n let n = readLine();\r\n if(n == 3)\r\n console.log(-1);\r\n else \r\n {\r\n if(n % 2 == 0){\r\n for(let i = 1; i <= n; i+=2)\r\n {\r\n process.stdout.write(`${i+1} ${i} `);\r\n }\r\n process.stdout.write(`\\n`);\r\n } else \r\n {\r\n process.stdout.write(`${n} ${n-1} `);\r\n for(let i = 1; i <= n-2; i++)\r\n process.stdout.write(`${i} `);\r\n process.stdout.write(`\\n`);\r\n }\r\n\r\n }\r\n\r\n }\r\n}\r\nfunction Fibonacci(n){\r\n if (n == 1) {\r\n return 1;\r\n }\r\n if (n == 2) {\r\n return 1;\r\n }\r\n if (n == 3) {\r\n return 1;\r\n }\r\n if (a[n] != -1) {\r\n return a[n];\r\n }\r\n if (n % 2 == 1) {\r\n return a[n] = Fibonacci(n - 1) + Fibonacci(n - 3);\r\n }\r\n return a[n] = Fibonacci(n - 1);\r\n \r\n}\r\nfunction io(x, y){\r\n if (x <= 0 || y <= 0) {\r\n return 0;\r\n }\r\n if (x < y) {\r\n return io(x-1, y-2) + io(x-2, y-1);\r\n }\r\n if (x > y) {\r\n return io(x-2, y-2) + 1;\r\n }\r\n}\r\nfunction ctl(a)\r\n{\r\n if(a==1){\r\n return 2;\r\n }\r\n if(a==2){\r\n return 4;\r\n }\r\n return ctl(a-1)+ctl(a-2); \r\n}\r\n\r\n"}, {"source_code": "/*\r\n** Template\r\n*/\r\n\r\n// Common Template Starts //\r\n//*\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n// Common Template Ends //\r\n\r\n// Driver Function Starts //\r\nconst main = () => {\r\n console.clear()\r\n let t = parseInt(readline())\r\n while (t--) {\r\n let n = parseInt(readline())\r\n console.log(solve(n))\r\n }\r\n}\r\n// Driver Function Ends //\r\n\r\n// MAIN LOGIC\r\nconst solve = (n) => {\r\n\r\n if (n == 1) return \"1\"\r\n else if (n == 2) return \"2 1\"\r\n else if (n == 3) return \"-1\"\r\n else if (n == 4) return \"4 3 1 2\"\r\n else {\r\n let lim = Math.floor(n / 2) + 1\r\n let res = ''\r\n for (let i = n; i > lim; i--) res += i + ' '\r\n for (let i = 1; i <= lim; i++) res += i + ' '\r\n return res\r\n }\r\n}\r\n\r\nconst isOdd = (num) => num & 1\r\nconst isEven = (num) => !(num & 1)\r\nconst minOfArray = (arr) => Math.min.apply(null, arr)\r\nconst maxOfArray = (arr) => Math.max.apply(null, arr)\r\nconst uniqueArray = (arr) => [...new Set(arr)]\r\nconst sortArray = (arr) => arr.sort((a, b) => a - b)\r\nconst sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn();\r\n if (n === 1 || n === 3) return -1;\r\n const res = [n, n - 1];\r\n for (let i = 0; i < n - 2; i++) {\r\n res.push(i + 1);\r\n }\r\n return res.join(' ');\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn();\r\n return res;\r\n };\r\n const re = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rn() - 1;\r\n return res;\r\n };\r\n const rbs = n => {\r\n let res = new Array(n);\r\n for (let i = 0; i < n; i++) res[i] = rb();\r\n return res;\r\n };\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n const [rn, rb, rns, re, rbs] = convertInput(r);\r\n try {\r\n let t = rn();\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8')\r\n.split(/\\s+/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tif(N == 3){\r\n\t\t\tmyout(-1);\r\n\t\t\tcontinue;\r\n\t\t}else if(N == 2){\r\n\t\t\tmyout(\"2 1\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar output = new Array(N);\r\n\t\toutput[0] = N - 1;\r\n\t\toutput[1] = N;\r\n\t\tfor(var i = 2; i < N; i++){\r\n\t\t\toutput[i] = i - 1;\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}, {"source_code": "var tcn = readline()\r\n\r\nfor(var tc = 0; tc < tcn; tc++) {\r\n var n = readline()\r\n var result = []\r\n \r\n if (n == 3 || n == 1) {\r\n print('-1')\r\n }\r\n else if (n % 2 == 0) {\r\n for(var j = 0; j < n/2; j++) {\r\n result.push(2*j + 2)\r\n result.push(2*j + 1)\r\n }\r\n }\r\n else {\r\n for(var j = (n - 1) / 2; j > 1; j--) {\r\n result.push(2*j)\r\n result.push(2*j + 1)\r\n }\r\n result.push(1)\r\n result.push(2)\r\n result.push(3)\r\n }\r\n\r\n result.forEach(x => write(`${x} `))\r\n}"}, {"source_code": "var limit = parseInt(readline());\r\nfor (var i = 0; i < limit; i++)\r\n{\r\n var value = parseInt(readline());\r\n var result = \"\";\r\n if (value === 3)\r\n {\r\n result = -1;\r\n }\r\n else\r\n {\r\n result += `${value} ${value-1} `;\r\n for (var j = 1; j < value-1; j++)\r\n {\r\n result += `${j} `;\r\n }\r\n }\r\n print(result);\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var p = parseInt(readline().trim());\r\n var o = [], popped = [];\r\n if (p == 3) {\r\n process.stdout.write('-1\\n');\r\n continue;\r\n }\r\n if (p % 2 === 0) {\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o = o.reverse().join(' ')\r\n process.stdout.write(o + '\\n');\r\n }\r\n }\r\n } else {\r\n o = [];\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o.reverse()\r\n popped.push(o.pop())\r\n popped.push(o.pop())\r\n o.unshift(popped[1].toString(), popped[0].toString())\r\n process.stdout.write(o.join(' ') + '\\n')\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var p = parseInt(readline().trim());\r\n if (p == 3) {\r\n process.stdout.write('-1\\n');\r\n continue;\r\n }\r\n if (p % 2 === 0) {\r\n var o = [];\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o = o.reverse().join(' ')\r\n process.stdout.write(o + '\\n');\r\n }\r\n }\r\n } else {\r\n var o = [], popped = [];\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n popped.push(o.pop())\r\n popped.push(o.pop())\r\n popped = popped.reverse();\r\n o.unshift(popped[0], popped[1])\r\n process.stdout.write(o + '\\n')\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString.trim().split(\"\\n\").map((string) => {\r\n return string.trim();\r\n });\r\n solve();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction solve() {\r\n var t = readline();\r\n for (var k = 0; k < t; k++) {\r\n var p = parseInt(readline().trim());\r\n var o = [], popped = [];\r\n if (p % 2 === 0) {\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o = o.join(' ')\r\n process.stdout.write(o + '\\n');\r\n }\r\n }\r\n } else {\r\n o = [];\r\n for (var i = p; i > 0; i--) {\r\n o.push(i);\r\n if (i - 0 == 1) {\r\n o.reverse()\r\n popped.push(o.pop())\r\n popped.push(o.pop())\r\n o.unshift(popped[1].toString(), popped[0].toString())\r\n process.stdout.write(o.join(' ') + '\\n')\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let n = Number(readline());\r\n let ans = generateFunnyPermutation(n);\r\n console.log(ans === -1 ? -1 : ans.join(\" \"))\r\n }\r\n}\r\n\r\nfunction generateFunnyPermutation(n) {\r\n if (n === 2) return [2,1];\r\n if (n === 3) return -1;\r\n let arr = Array(n);\r\n for (let i = 0; i < n; i++) {\r\n arr[i] = i+1;\r\n }\r\n let mid = Math.floor(n/2);\r\n rotateArr(arr, 0, n-1);\r\n rotateArr(arr, 0, mid);\r\n rotateArr(arr, mid+1, n-1);\r\n \r\n return arr;\r\n}\r\n\r\nfunction rotateArr(arr, s, e) {\r\n let start = s, end = e;\r\n \r\n while (start < end) {\r\n let tmp = arr[start];\r\n arr[start] = arr[end];\r\n arr[end] = tmp;\r\n start++;\r\n end--;\r\n }\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n output[i] = solve(n)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n) {\n if (n === 3) return -1\n const arr = Array(n)\n if (n & 1) {\n for (let i = 0; i < n; i++) {\n arr[i] = (i & 1) ? i : i + 2\n arr[i] += 3\n }\n arr[n - 3] = 3\n arr[n - 2] = 2\n arr[n - 1] = 1\n } else {\n for (let i = 0; i < n; i++) {\n arr[i] = (i & 1) ? i : i + 2\n }\n }\n return arr.join(' ')\n}\n"}, {"source_code": "var tcn = readline()\r\n\r\nfor(var tc = 0; tc < tcn; tc++) {\r\n var n = readline()\r\n var result = []\r\n \r\n if (n == 3 || n == 1) {\r\n print('-1')\r\n }\r\n else if (n % 2 == 0) {\r\n for(var j = 0; j < n/2; j++) {\r\n result.push(2*j + 2)\r\n result.push(2*j + 1)\r\n }\r\n }\r\n else {\r\n for(var j = (n - 1) / 2; j > 1; j--) {\r\n result.push(2*j)\r\n result.push(2*j + 1)\r\n }\r\n result.push(1)\r\n result.push(2)\r\n result.push(3)\r\n }\r\n}\r\n\r\nresult.forEach(x => write(`${x} `))"}, {"source_code": "var tcn = readline()\r\n\r\nfor(var tc = 0; tc < tcn; tc++) {\r\n var n = readline()\r\n var result = []\r\n \r\n if (n == 3 || n == 1) {\r\n print('-1')\r\n }\r\n else if (n % 2 == 0) {\r\n for(var j = 0; j < n/2; j++) {\r\n result.push(2*j + 2)\r\n result.push(2*j + 1)\r\n }\r\n }\r\n else {\r\n for(var j = (n - 1) / 2; j > 1; j--) {\r\n result.push(2*j)\r\n result.push(2*j + 1)\r\n }\r\n result.push(1)\r\n result.push(2)\r\n result.push(3)\r\n }\r\n}\r\n\r\nresult.forEach(x => print(`${x} `))"}], "src_uid": "cdcf95e29d3260a07dded74286fc3798"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.TeamName = newTeamName;\n this.Points = newPoints;\n this.GoalDiff = newGoalDiff;\n this.ScoredGoals = newScoredGoals;\n }\n}\n\nvar indicator = 0, N, cont = [];\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else if (indicator <= N) {\n //var obj=new Info(input,0,0,0);\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n }\n else {\n var dashIndex = input.indexOf('-');\n var spaceIndex = input.indexOf(' ');\n var colonIndex = input.indexOf(':');\n\n var Team1Name = input.substring(0, dashIndex);\n var Team2Name = input.substring(dashIndex + 1, spaceIndex);\n\n var Goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n var Goal2 = parseInt(input.substring(colonIndex + 1));\n\n var Team1Index = cont.findIndex(item => item.TeamName == Team1Name);\n var Team2Index = cont.findIndex(item => item.TeamName == Team2Name);\n\n //Update Points\n\n if (Goal1 > Goal2)\n cont[Team1Index].Points += 3;\n else if (Goal1 < Goal2)\n cont[Team2Index].Points += 3;\n else {\n cont[Team1Index].Points++;\n cont[Team2Index].Points++;\n }\n //Update Goal Difference\n cont[Team1Index].GoalDiff += (Goal1 - Goal2);\n cont[Team2Index].GoalDiff += (Goal2 - Goal1);\n\n //Update Scored Goals\n cont[Team1Index].ScoredGoals += Goal1;\n cont[Team2Index].ScoredGoals += Goal2;\n\n }\n\n}).on('close', () => {\n //sort by points, then by GoalDiff and then by ScoredGoals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.Points != obj2.Points)\n return obj2.Points - obj1.Points;\n\n if (obj1.GoalDiff != obj2.GoalDiff)\n return obj2.GoalDiff - obj1.GoalDiff;\n\n return obj2.ScoredGoals - obj1.ScoredGoals;\n });\n\n //delete second half of our array\n cont.splice(N/2);\n //sort by Team name in ascending order\n cont.sort( (obj1,obj2) => {\n // return obj1.TeamName.localeCompare(obj2.TeamName);\n return obj1.TeamName > obj2.TeamName ? 1 : -1;\n });\n //output\n cont.forEach(item => {\n console.log(item.TeamName);\n });\n});", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.teamName = newTeamName;\n this.points = newPoints;\n this.goalDiff = newGoalDiff;\n this.scoredGoals = newScoredGoals;\n }\n}\n\nvar findIndexByName = function (cont, searchName) {\n for (let i = 0; i < cont.length; i++) {\n if (cont[i].teamName == searchName)\n return i;\n }\n return -1;\n}\nvar cont = [];\nvar indicator = 0, N;\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else if (indicator <= N) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n }\n else {\n let dashIndex = input.indexOf(\"-\");\n let spaceIndex = input.indexOf(\" \");\n let colonIndex = input.indexOf(\":\");\n let team1Name = input.substring(0, dashIndex);\n let team2Name = input.substring(dashIndex + 1, spaceIndex);\n let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n let goal2 = parseInt(input.substring(colonIndex + 1));\n let team1Index = findIndexByName(cont, team1Name);\n let team2Index = findIndexByName(cont, team2Name);\n // update points\n if (goal1 > goal2)\n cont[team1Index].points += 3;\n else if (goal1 < goal2)\n cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n // update goalDiff\n cont[team1Index].goalDiff += (goal1 - goal2);\n cont[team2Index].goalDiff += (goal2 - goal1);\n // update scoredGoals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n }\n}).on('close', function () {\n // sort by points, then by goalDiff, then by scoredGoals in descending order:\n cont.sort((obj1, obj2) => {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n });\n // delete second half of cont\n cont.splice(N / 2);\n // sort by teamName in lexicographical order\n cont.sort((obj1, obj2) => {\n let s1 = obj1.teamName;\n let s2 = obj2.teamName;\n let s1Len = s1.length;\n let s2Len = s2.length;\n let minLen = Math.min(s1Len, s2Len);\n for (let i = 0; i < minLen; i++) {\n if (s1[i] != s2[i])\n return s1.charCodeAt(i) - s2.charCodeAt(i);\n }\n return s1Len - s2Len;\n });\n\n cont.forEach(item => {\n console.log(item.teamName);\n });\n});\n\n\n/*\n 0123456789.........\ns= 'barcelona-real 15:10'\n\n4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n\nPoints goalDiff scoredGoals\nA => 1+1+3=5 A=> (1+2+1) - (1+2+0)= 4-3=1 A=> 4\nB => 1+3+0=4 B=> (1+1+0) - (1+0+3)= 2-4=-2 B=> 2\nC => 1+0+0=1 C=> (2+0+0) - (2+1+3)= 2-6=-4 C=> 2\nD => 0+3+3=6 D=> (0+3+3) - (1+0+0)= 6-1=5 D=> 6\n\nA, B, C, D => D, A, B, C => D, A =>A, D\n\ncont:\n 0 1\n|teamName: 'A' |teamname: 'B'|\n|point: 5 |point: 5 |\n|goalDiff: 1 |\n|scoredGoals: 4|\n*/"}, {"source_code": "const readline = require('readline');\n\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n \nclass Info{\n constructor(newTeamName, newPoint, newGoalDiff, newScoredGoals){\n this.teamName=newTeamName;\n this.point=newPoint;\n this.goalDiff=newGoalDiff;\n this.scoredGoals=newScoredGoals;\n }\n}\n/*\n var findIndexByName = function(cont, searchName){\n for(let i=0; i {\n if(indicator == 0){\n N = parseInt(input);\n indicator++;\n }\n else if(indicator <= N){\n cont.push(new Info(input,0,0,0));\n indicator++;\n }\n else{ \n let dashInd = input.indexOf('-');\n let spaceInd = input.indexOf(' ');\n let colonInd = input.indexOf(':');\n\n let team1Name = input.substring(0,dashInd);\n let team2Name = input.substring(dashInd+1, spaceInd);\n let goal1=parseInt(input.substring(spaceInd+1, colonInd));\n let goal2=parseInt(input.substring(colonInd+1));\n\n let team1Index = cont.findIndex(obj => obj.teamName == team1Name);\n let team2Index = cont.findIndex(obj => obj.teamName == team2Name);\n\n //update points\n if(goal1>goal2)\n cont[team1Index].point +=3;\n else if(goal1{\n \n if(obj1.point != obj2.point)\n return obj2.point - obj1.point; \n\n if(obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n });\n\n // remove second half of array\n cont.splice(N/2);\n\n //sort by lexicographical order\n cont.sort((obj1, obj2)=>{\n \n if(obj1.teamName > obj2.teamName)\n return 1;\n else if(obj1.teamName < obj2.teamName)\n return -1;\n else \n return 0; \n });\n\n cont.forEach(element => {\n console.log(element.teamName);\n });\n\n });\n\n \n\n/*\n\n 0 1 2 ........\ncont=|teamName: \"A\" |teamName: \"B\"|....... \n |point: 5 |\n |goalDiff: 1 |\n |scoredGoals: 4|\n*/\n /*\n \n4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n\n\n\nPoints GoalDifference ScoredGoals\n\nA=>1+1+3=5 A=>(1+2+1)-(1+2)=4-3=1 A=>4\nB=>1+3+0=4 B=>(1+1)-(1+3)=2-4=-2 B=>2\nC=>1+0+0=1 C=>(2)-(2+1+3)=2-6=-4 C=>2\nD=>0+3+3=6 D=>(3+3)-(1)=6-1=5 D=>6\n\n\nA B C D => D A B C => D A => A D\n */"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.teamName = newTeamName;\n this.points = newPoints;\n this.goalDiff = newGoalDiff;\n this.scoredGoals = newScoredGoals;\n }\n}\nvar indexOfByName = function (cont,N, searchName) {\n for (let i = 0; i < N; i++)\n if (cont[i].teamName == searchName)\n return i;\n return -1;\n}\nvar indicator = 0, N, cont = [];\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else if (indicator <= N) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n }\n else {\n let dashIndx = input.indexOf('-');\n let spaceIndx = input.indexOf(' ');\n let colonIndx = input.indexOf(':');\n\n let team1Name = input.substring(0, dashIndx);\n let team2Name = input.substring(dashIndx + 1, spaceIndx);\n let Goal1 = parseInt(input.substring(spaceIndx + 1, colonIndx));\n let Goal2 = parseInt(input.substring(colonIndx + 1));\n\n let team1Indx = indexOfByName(cont,N, team1Name);\n let team2Indx = indexOfByName(cont,N, team2Name);\n\n //update points\n\n if (Goal1 > Goal2)\n cont[team1Indx].points += 3;\n else if (Goal1 < Goal2)\n cont[team2Indx].points += 3;\n else {\n cont[team1Indx].points++;\n cont[team2Indx].points++;\n }\n\n //update goal diff\n\n cont[team1Indx].goalDiff += (Goal1 - Goal2);\n cont[team2Indx].goalDiff += (Goal2 - Goal1);\n\n //update scored goals \n\n cont[team1Indx].scoredGoals += Goal1;\n cont[team2Indx].scoredGoals += Goal2;\n\n }\n}).on('close', () => {\n //sort by points then by GoalDiff then by scored goals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n });\n\n // delete the second half of array\n cont.splice(N / 2);\n //order by teamName in lexicographical order ascending order\n cont.sort((obj1, obj2) => {\n let s1 = obj1.teamName;\n let s2 = obj2.teamName;\n let s1Len = s1.length;\n let s2Len = s2.length;\n let minLen = Math.min(s1Len, s2Len);\n for (let i = 0; i < minLen; i++) {\n if (s1[i] != s2[i])\n return s1.charCodeAt(i) - s2.charCodeAt(i);\n }\n return s1Len - s2Len;\n });\n\n //output ans\n cont.forEach(element => {\n console.log(element.teamName);\n });\n});\n\n\n\n/*\n 0123456789...\ninput=\"Barcelona-Real 15:10\"\n4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n\n\nPoints GoalDiff ScoredGoals\nA=>1+1+3=5 A=>(1+2+1)-(1+2)=4-3=1 A=>4\nB=>1+3=4 B=>(1+1)-(1+3)=2-4=-2 B=>2\nC=>1 C=>(2)-(2+1+3)=2-6=-4 C=>2\nD=>3+3=6 D=>(3+3)-(1)=6-1=5 D=>6\n\n{D,A,B,C} => {D,A} => {A,D}\n\n\n 0\n|teamName: \"A\" |teamName\n|Points: 5 |\n|GoalDiff: -2 |\n|scoredGoals: 4|\n\n*/"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.teamName = newTeamName;\n this.points = newPoints;\n this.goalDiff = newGoalDiff;\n this.scoredGoals = newScoredGoals;\n }\n}\n\nvar indexOfByName = function (cont, searchName) {\n for (let i = 0; i < cont.length; i++) {\n if (cont[i].teamName == searchName) return i;\n }\n return -1;\n};\n/*\n\n4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n\n\n\n*/\n\nvar cont = [],\n indicator = 0,\n N = 0;\nrl.on(\"line\", (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n } else if (indicator <= N) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n } else {\n // 0123456789....\n //\"Barcelona-Real 15:10\"\n let dashIndex = input.indexOf(\"-\");\n let spaceIndex = input.indexOf(\" \");\n let colonIndex = input.indexOf(\":\");\n let team1Name = input.substring(0, dashIndex);\n let team2Name = input.substring(dashIndex + 1, spaceIndex);\n let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n let goal2 = parseInt(input.substring(colonIndex + 1));\n let team1Index = indexOfByName(cont, team1Name);\n let team2Index = indexOfByName(cont, team2Name);\n // Update Points\n if (goal1 > goal2) cont[team1Index].points += 3;\n else if (goal1 < goal2) cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n //update goal diff\n cont[team1Index].goalDiff += goal1 - goal2;\n cont[team2Index].goalDiff += goal2 - goal1;\n //update Score goals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n }\n}).on(\"close\", function () {\n // sort by point then by goalDiff and then by scored goals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.points != obj2.points) return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff) return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n });\n\n //erse second half of an array\n cont.splice(N / 2);\n\n //sort by teamname in ascending order\n cont.sort((obj1, obj2) => {\n let s1 = obj1.teamName;\n let s2 = obj2.teamName;\n let s1Len = s1.length;\n let s2Len = s2.length;\n let minLen = Math.min(s1Len, s2Len);\n for (let i = 0; i < minLen; i++) {\n if (s1[i] != s2[i]) return s1.charCodeAt(i) - s2.charCodeAt(i);\n }\n return s1Len - s2Len;\n });\n\n //output answer\n cont.forEach((element) => {\n console.log(element.teamName);\n });\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nclass Info {\n constructor(teamName, points, goalDiff, scoredGoals) {\n this.teamName = teamName;\n this.points = points;\n this.goalDiff = goalDiff;\n this.scoredGoals = scoredGoals;\n }\n\n}\n\nvar outputInfoObj = function (obj) {\n console.log(\"************************\");\n console.log(\"teamName=%s \", obj.teamName);\n console.log(\"points = %d\", obj.points);\n console.log(\"goaldiff = %d\", obj.goalDiff);\n console.log(\"scoredgoals = %d\", obj.scoredGoals);\n console.log(\"************************\");\n}\n\nvar customCompare = function (obj1, obj2) {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n}\n\nvar compareByName = function (obj1, obj2) {\n var s1 = obj1.teamName;\n var s2 = obj2.teamName;\n var s1Len = s1.length;//<=problem was here. error caused: Length instead of length\n var s2Len = s2.length;// note that js \n var minLen = (s1Len > s2Len) ? s2Len : s1Len;\n for (let i = 0; i < minLen; i++) {\n let cd1 = s1.charCodeAt(i);\n let cd2 = s2.charCodeAt(i);\n //console.log(\"inside compare func s1=%s s2=%s cd1=%d cd2=%d\",s1,s2,cd1,cd2);\n if (cd1 != cd2)\n return cd1-cd2;\n /*\n if(s1[i]!=s2[i])\n //return s1[i]-s2[i];\n return s1.charCodeAt(i) - s2.charCodeAt(i);\n */\n }\n return s1Len - s2Len;\n}\n\nvar n, indicator = 0,\n cont = [];\n\n\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n n = parseInt(input);\n indicator++;\n } else if (indicator <= n) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n } else {\n var dashIndex = input.indexOf('-');\n var spaceIndex = input.indexOf(' ');\n var colonIndex = input.indexOf(':');\n var team1Name = input.substring(0, dashIndex);\n var team2Name = input.substring(dashIndex + 1, spaceIndex);\n var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n var goal2 = parseInt(input.substring(colonIndex + 1));\n var team1Index = cont.findIndex(item => item.teamName == team1Name);\n var team2Index = cont.findIndex(item => item.teamName == team2Name);\n\n //Update points\n if (goal1 > goal2)\n cont[team1Index].points += 3;\n else if (goal2 > goal1)\n cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n //Update Goal Difference\n cont[team1Index].goalDiff += (goal1 - goal2);\n cont[team2Index].goalDiff += (goal2 - goal1);\n //Update Scored Goals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n\n }\n}).on('close', () => {\n /* cont.forEach(item => {\n outputInfoObj(item);\n });*/\n cont.sort(customCompare);\n cont.splice(n / 2);\n //cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));\n cont.sort(compareByName);\n cont.forEach(item => {\n console.log(item.teamName);\n });\n\n});"}, {"source_code": "'use strict'\n\nlet lll\n\nconst N = +readline()\n\nlet ts = {}\n\nfor (let i = 0; i < N; i++) {\n const n = readline()\n ts[n] = [0, 0, 0, n]\n}\n\nwhile (lll = readline()) {\n const fn = lll.slice(0, lll.indexOf('-'))\n const sn = lll.slice(lll.indexOf('-') + 1, lll.indexOf(' '))\n const scr = lll.slice(lll.indexOf(' ') + 1).split(':').map(v => parseInt(v))\n const fs = scr[0]\n const ss = scr[1]\n if (fs > ss) {\n ts[fn][0] += 3\n } else if (ss > fs) {\n ts[sn][0] += 3\n } else {\n ts[fn][0] += 1\n ts[sn][0] += 1\n }\n ts[fn][1] += fs\n ts[fn][1] -= ss\n ts[sn][1] += ss\n ts[sn][1] -= fs\n ts[fn][2] += fs\n ts[sn][2] += ss\n}\n\nconst ns = Object.keys(ts)\nconst tsa = []\n\nfor (let i = 0; i < ns.length; i++) {\n tsa.push(ts[ns[i]])\n}\n\n\ntsa.sort((ft, st) => ft[0] - st[0] || ft[1] - st[1] || ft[2] - st[2])\n\nconst pots = tsa.slice(tsa.length / 2).map(v => v[3]).sort()\n\npots.forEach(v => print(v))"}], "negative_code": [{"source_code": "'use strict'\n\nlet lll\n\nconst N = +readline()\n\nlet ts = {}\n\nfor (let i = 0; i < N; i++) {\n const n = readline()\n ts[n] = [0, 0, 0, n]\n}\n\nwhile (lll = readline()) {\n const fn = lll.slice(0, lll.indexOf('-'))\n const sn = lll.slice(lll.indexOf('-') + 1, lll.indexOf(' '))\n const scr = lll.slice(lll.indexOf(' ') + 1).split(':').map(v => parseInt(v))\n const fs = scr[0]\n const ss = scr[1]\n if (fs > ss) {\n ts[fn][0] += 3\n } else if (ss > fs) {\n ts[sn][0] += 3\n } else {\n ts[fn][0] += 1\n ts[sn][0] += 1\n }\n ts[fn][1] += fs\n ts[fn][1] -= ss\n ts[sn][1] += ss\n ts[sn][1] -= fs\n ts[fn][2] += fs\n ts[sn][2] += ss\n}\n\nconst ns = Object.keys(ts)\nconst tsa = []\n\nfor (let i = 0; i < ns.length; i++) {\n tsa.push(ts[ns[i]])\n}\n\n\ntsa.sort((ft, st) => ft[0] - st[0] || ft[1] - st[1] || ft[2] - st[2])\n\nfor (let i = tsa.length / 2 | 0; i < tsa.length; i++) print(tsa[i][3])"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.TeamName = newTeamName;\n this.Points = newPoints;\n this.GoalDiff = newGoalDiff;\n this.ScoredGoals = newScoredGoals;\n }\n}\n\nvar indicator = 0, N, cont = [];\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else if (indicator <= N) {\n //var obj=new Info(input,0,0,0);\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n }\n else {\n var dashIndex = input.indexOf('-');\n var spaceIndex = input.indexOf(' ');\n var colonIndex = input.indexOf(':');\n\n var Team1Name = input.substring(0, dashIndex);\n var Team2Name = input.substring(dashIndex + 1, spaceIndex);\n\n var Goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n var Goal2 = parseInt(input.substring(colonIndex + 1));\n\n var Team1Index = cont.findIndex(item => item.TeamName == Team1Name);\n var Team2Index = cont.findIndex(item => item.TeamName == Team2Name);\n\n //Update Points\n\n if (Goal1 > Goal2)\n cont[Team1Index].Points += 3;\n else if (Goal1 < Goal2)\n cont[Team2Index].Points += 3;\n else {\n cont[Team1Index].Points++;\n cont[Team2Index].Points++;\n }\n //Update Goal Difference\n cont[Team1Index].GoalDiff += (Goal1 - Goal2);\n cont[Team2Index].GoalDiff += (Goal2 - Goal1);\n\n //Update Scored Goals\n cont[Team1Index].ScoredGoals += Goal1;\n cont[Team2Index].ScoredGoals += Goal2;\n\n }\n\n}).on('close', () => {\n //sort by points, then by GoalDiff and then by ScoredGoals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.Points != obj2.Points)\n return obj2.Points - obj1.Points;\n\n if (obj1.GoalDiff != obj2.GoalDiff)\n return obj2.GoalDiff - obj1.GoalDiff;\n\n return obj2.ScoredGoals - obj1.ScoredGoals;\n });\n\n //delete second half of our array\n cont.splice(N/2);\n //sort by Team name in ascending order\n cont.sort( (obj1,obj2) => {\n return obj1.TeamName.localeCompare(obj2.TeamName);\n });\n //output\n cont.forEach(item => {\n console.log(item.TeamName);\n });\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.teamName = newTeamName;\n this.points = newPoints;\n this.goalDiff = newGoalDiff;\n this.scoredGoals = newScoredGoals;\n }\n}\nvar indexOfByName = function (cont, searchName) {\n for (let i = 0; i < cont.length; i++)\n if (cont[i].teamName == searchName)\n return i;\n return -1;\n}\nvar indicator = 0, N, cont = [];\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n }\n else if (indicator <= N) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n }\n else {\n let dashIndx = input.indexOf('-');\n let spaceIndx = input.indexOf(' ');\n let colonIndx = input.indexOf(':');\n\n let team1Name = input.substring(0, dashIndx);\n let team2Name = input.substring(dashIndx + 1, spaceIndx);\n let Goal1 = parseInt(input.substring(spaceIndx + 1, colonIndx));\n let Goal2 = parseInt(input.substring(colonIndx + 1));\n\n let team1Indx = indexOfByName(cont, team1Name);\n let team2Indx = indexOfByName(cont, team2Name);\n\n //update points\n\n if (Goal1 > Goal2)\n cont[team1Indx].points += 3;\n else if (Goal1 < Goal2)\n cont[team2Indx].points += 3;\n else {\n cont[team1Indx].points++;\n cont[team2Indx].points++;\n }\n\n //update goal diff\n\n cont[team1Indx].goalDiff += (Goal1 - Goal2);\n cont[team2Indx].goalDiff += (Goal2 - Goal1);\n\n //update scored goals \n\n cont[team1Indx].scoredGoals += Goal1;\n cont[team2Indx].scoredGoals += Goal2;\n\n }\n}).on('close', () => {\n //sort by points then by GoalDiff then by scored goals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n obj2.scoredGoals - obj1.scoredGoals;\n });\n\n // delete the second half of array\n cont.splice(N / 2);\n //order by teamName in lexicographical order ascending order\n cont.sort((obj1, obj2) => {\n let s1 = obj1.teamName;\n let s2 = obj2.teamName;\n let s1Len = s1.length;\n let s2Len = s2.length;\n let minLen = Math.min(s1Len, s2Len);\n for (let i = 0; i < minLen; i++) {\n if (s1[i] != s2[i])\n return s1.charCodeAt(i) - s2.charCodeAt(i);\n }\n return s1Len - s2Len;\n });\n\n //output ans\n cont.forEach(element => {\n console.log(element.teamName);\n });\n});\n"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nclass Info {\n constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {\n this.teamName = newTeamName;\n this.points = newPoints;\n this.goalDiff = newGoalDiff;\n this.scoredGoals = newScoredGoals;\n }\n}\n\nvar indexOfByName = function (cont, searchName) {\n for (let i = 0; i < cont.length; i++) {\n if (cont[i].teamName == searchName) return i;\n }\n return -1;\n};\n/*\n\n4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n\n\n\n*/\n\nvar cont = [],\n indicator = 0,\n N = 0;\nrl.on(\"line\", (input) => {\n if (indicator == 0) {\n N = parseInt(input);\n indicator++;\n } else if (indicator <= N) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n } else {\n // 0123456789....\n //\"Barcelona-Real 15:10\"\n let dashIndex = input.indexOf(\"-\");\n let spaceIndex = input.indexOf(\" \");\n let colonIndex = input.indexOf(\":\");\n let team1Name = input.substring(0, dashIndex);\n let team2Name = input.substring(dashIndex + 1, spaceIndex);\n let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n let goal2 = parseInt(input.substring(colonIndex + 1));\n let team1Index = indexOfByName(cont, team1Name);\n let team2Index = indexOfByName(cont, team2Name);\n // Update Points\n if (goal1 > goal2) cont[team1Index].points += 3;\n else if (goal1 < goal2) cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n //update goal diff\n cont[team1Index].goalDiff += goal1 - goal2;\n cont[team2Index].goalDiff += goal2 - goal1;\n //update Score goals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n }\n}).on(\"close\", function () {\n // sort by point then by goalDiff and then by scored goals in descending order\n cont.sort((obj1, obj2) => {\n if (obj1.points != obj2.points) return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff) return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj2.scoredGoals;\n });\n\n //erse second half of an array\n cont.splice(N / 2);\n\n //sort by teamname in ascending order\n cont.sort((obj1, obj2) => {\n let s1 = obj1.teamName;\n let s2 = obj2.teamName;\n let s1Len = s1.length;\n let s2Len = s2.length;\n let minLen = Math.min(s1Len, s2Len);\n for (let i = 0; i < minLen; i++) {\n if (s1[i] != s2[i]) return s1.charCodeAt(i) - s2.charCodeAt(i);\n }\n return s1Len - s2Len;\n });\n\n //output answer\n cont.forEach((element) => {\n console.log(element.teamName);\n });\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nclass Info {\n constructor(teamName, points, goalDiff, scoredGoals) {\n this.teamName = teamName;\n this.points = points;\n this.goalDiff = goalDiff;\n this.scoredGoals = scoredGoals;\n }\n\n}\n\nvar outputInfoObj = function (obj) {\n console.log(\"************************\");\n console.log(\"teamName=%s \", obj.teamName);\n console.log(\"points = %d\", obj.points);\n console.log(\"goaldiff = %d\", obj.goalDiff);\n console.log(\"scoredgoals = %d\", obj.scoredGoals);\n console.log(\"************************\");\n}\n\nvar customCompare = function (obj1, obj2) {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n}\n\nvar compareByName = function (obj1, obj2) {\n var s1 = obj1.teamName;\n var s2 = obj2.teamName;\n var s1Len = s1.Length;\n var s2Len = s2.Length;\n var minLen = (s1Len>s2Len)?s2Len:s1Len;\n for(let i=0;i {\n if (indicator == 0) {\n n = parseInt(input);\n indicator++;\n } else if (indicator <= n) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n } else {\n var dashIndex = input.indexOf('-');\n var spaceIndex = input.indexOf(' ');\n var colonIndex = input.indexOf(':');\n var team1Name = input.substring(0, dashIndex);\n var team2Name = input.substring(dashIndex + 1, spaceIndex);\n var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n var goal2 = parseInt(input.substring(colonIndex + 1));\n var team1Index = cont.findIndex(item => item.teamName == team1Name);\n var team2Index = cont.findIndex(item => item.teamName == team2Name);\n\n //Update points\n if (goal1 > goal2)\n cont[team1Index].points += 3;\n else if (goal2 > goal1)\n cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n //Update Goal Difference\n cont[team1Index].goalDiff += (goal1 - goal2);\n cont[team2Index].goalDiff += (goal2 - goal1);\n //Update Scored Goals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n\n }\n}).on('close', () => {\n /* cont.forEach(item => {\n outputInfoObj(item);\n });*/\n cont.sort(customCompare);\n cont.splice(n / 2);\n //cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));\n cont.sort(compareByName);\n cont.forEach(item => {\n console.log(item.teamName);\n });\n\n});"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\nclass Info {\n constructor(teamName, points, goalDiff, scoredGoals) {\n this.teamName = teamName;\n this.points = points;\n this.goalDiff = goalDiff;\n this.scoredGoals = scoredGoals;\n }\n\n}\n\nvar outputInfoObj = function(obj){\n console.log(\"************************\");\n console.log(\"teamName=%s \",obj.teamName);\n console.log(\"points = %d\",obj.points);\n console.log(\"goaldiff = %d\",obj.goalDiff);\n console.log(\"scoredgoals = %d\",obj.scoredGoals);\n console.log(\"************************\");\n} \n\nvar customCompare = function (obj1, obj2) {\n if (obj1.points != obj2.points)\n return obj2.points - obj1.points;\n\n if (obj1.goalDiff != obj2.goalDiff)\n return obj2.goalDiff - obj1.goalDiff;\n\n return obj2.scoredGoals - obj1.scoredGoals;\n}\n\nvar n, indicator = 0,\n cont = [];\n\n\n\nrl.on('line', (input) => {\n if (indicator == 0) {\n n = parseInt(input);\n indicator++;\n } else if (indicator <= n) {\n cont.push(new Info(input, 0, 0, 0));\n indicator++;\n } else {\n var dashIndex = input.indexOf('-');\n var spaceIndex = input.indexOf(' ');\n var colonIndex = input.indexOf(':');\n var team1Name = input.substring(0, dashIndex);\n var team2Name = input.substring(dashIndex + 1, spaceIndex);\n var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));\n var goal2 = parseInt(input.substring(colonIndex+1));\n var team1Index = cont.findIndex(item => item.teamName == team1Name);\n var team2Index = cont.findIndex(item => item.teamName == team2Name);\n \n //Update points\n if (goal1 > goal2)\n cont[team1Index].points += 3;\n else if (goal2 > goal1)\n cont[team2Index].points += 3;\n else {\n cont[team1Index].points++;\n cont[team2Index].points++;\n }\n //Update Goal Difference\n cont[team1Index].goalDiff += (goal1 - goal2);\n cont[team2Index].goalDiff += (goal2 - goal1);\n //Update Scored Goals\n cont[team1Index].scoredGoals += goal1;\n cont[team2Index].scoredGoals += goal2;\n \n }\n}).on('close', () => {\n /* cont.forEach(item => {\n outputInfoObj(item);\n });*/\n cont.sort(customCompare);\n cont.splice(n / 2);\n cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));\n cont.forEach(item => {\n console.log(item.teamName);\n });\n\n});"}], "src_uid": "472c0cb256c062b9806bf93b13b453a2"} {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst l = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\n \nconst ra = ()=>readline().split(' ').map(a=>+a)\n \nconst MOD = 1e9+7;\n\nclass SegmTree {\n\n}\n \nconst calc = (n, arr)=>{\n let cnt = new Map();\n for (let a of arr)\n cnt.set(a, (cnt.get(a)||0)+1)\n let max = 0;\n for (let [k, v] of cnt){\n if (v>max){\n max = v;\n }\n }\n let ans = 0;\n let eq = max;\n let potential = 0;\n while (eq stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var m = new Map();\n var max = 0;\n for(j = 0; j < n; j++){\n if(m.has(a[j])){\n var temp = m.get(a[j]);\n temp++;\n m.set(a[j], temp);\n }else{\n m.set(a[j], 1);\n }\n }\n for(var [key, value] of m){\n if(value > max){\n max = value;\n }\n }\n var ans = 0;\n while(max < n){\n var c = Math.min(n - max, max);\n ans += 1 + c;\n max += c;\n }\n console.log(ans);\n }\n }\n});"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n let t = parseInt(readLine());\r\n while (t-- > 0) {\r\n console.log(solve());\r\n }\r\n}\r\nfunction solve() {\r\n let n = parseInt(readLine());\r\n let arr = readLine().split(\" \");\r\n counter = 0;\r\n return solution(arr)\r\n}\r\nfunction solution(arr) {\r\n if (arr.length == 1) {\r\n return 0;\r\n }\r\n let same = true;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[0] != arr[i]) same = false;\r\n }\r\n if (same) {\r\n return 0;\r\n }\r\n let maxRep = -1;\r\n let map = new Map();\r\n for (const val of arr) {\r\n if (map.has(val)) map.set(val, map.get(val) + 1);\r\n else map.set(val, 1);\r\n }\r\n maxRep = Array.from(map.values()).sort((a, b) => a - b);\r\n maxRep = maxRep[maxRep.length - 1];\r\n let cnt = 0;\r\n while (maxRep !== arr.length) {\r\n let temp = Math.min(Math.abs(arr.length - maxRep), maxRep);\r\n cnt += 1 + temp\r\n maxRep += temp\r\n }\r\n return cnt;\r\n}"}, {"source_code": "var total = +readline();\nwhile (total--) {\n var len = +readline();\n var map = new Map();\n readline().split(\" \").map(Number).forEach(function (x) {\n if (map.has(x)) {\n map.set(x, map.get(x) + 1);\n } else {\n map.set(x, 1);\n }\n });\n var anst = 0;\n var val = -1;\n map.forEach(function (v, k) {\n if (v > val) {\n val = v;\n anst = k;\n }\n });\n var longest = val;\n var ans = 0;\n while (len > longest) {\n ans += 1 + longest;\n longest += longest;\n }\n ans += len - longest;\n print(ans);\n}"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ')\r\n let map = new Map()\r\n for (let num of data) {\r\n if (!map.has(num)) map.set(num, 0)\r\n map.set(num, map.get(num) + 1)\r\n }\r\n\r\n let max = [...map.values()].sort((a, b) => b - a)[0]\r\n n -= max\r\n let ans = 0\r\n\r\n while (n > 0) {\r\n ans++\r\n ans += Math.min(max, n)\r\n n -= max\r\n max *= 2\r\n }\r\n res.push(ans)\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}], "negative_code": [{"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)\r\n const h = new Array(n).fill(-1),\r\n e = [],\r\n ne = [],\r\n d = new Array(n).fill(0)\r\n let idx = 0\r\n const add = (i, j) => {\r\n ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++\r\n }\r\n for (let i = 2; i <= n; i++) {\r\n add(data[i - 2] - 1, i - 1)\r\n }\r\n const queue = [0]\r\n const g = new Array(n).fill(0).map(() => [])\r\n for (let i of queue) {\r\n for (let k = h[i]; k !== -1; k = ne[k]) {\r\n const j = e[k]\r\n if (--d[j] === 0) {\r\n g[i].push(j)\r\n queue.push(j)\r\n }\r\n }\r\n }\r\n let hasSon = 0,\r\n maxSon = 0\r\n for (let children of g) {\r\n if (children.length) hasSon++\r\n maxSon = Math.max(maxSon, children.length)\r\n }\r\n\r\n maxSon -= hasSon + 1\r\n let ans = 1 + hasSon + Math.ceil(Math.max(maxSon, 0) / 2)\r\n res.push(ans)\r\n }\r\n\r\n console.log(res.join('\\n'))\r\n})()\r\n"}, {"source_code": "const fs = require('fs')\r\nconst inputs = fs.readFileSync(0, 'utf-8').split('\\n')\r\n\r\nvoid (function main() {\r\n const _ = Number(inputs[0])\r\n let res = []\r\n for (let __ = 0; __ < _; __++) {\r\n let n = Number(inputs[__ * 2 + 1])\r\n const data = inputs[__ * 2 + 2].split(' ')\r\n let map = new Map()\r\n for (let num of data) {\r\n map.set(num, (map.get(num) || 0) + 1)\r\n }\r\n\r\n let max = [...map.values()].sort((a, b) => b - a)[0]\r\n n -= max\r\n let ans = 0\r\n while (n > 0) {\r\n ans++\r\n ans += Math.min(max, n)\r\n n -= max\r\n max *= 2\r\n }\r\n res.push(ans)\r\n }\r\n console.log(res.join('\\n'))\r\n})()\r\n"}], "src_uid": "b4fcfedc8e76afd0043b026eb3132582"} {"source_code": "var result = '1';\nvar i = 1;\nconst numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\n\nfunction first() {\n while (result.length < n) {\n i = Number(!i);\n result += i;\n }\n}\n\nfirst();\n\nprint(result);", "positive_code": [{"source_code": "const numbers = readline().split(' ').map(function(v){return +v;});\nconst n = numbers[0];\n\nvar result = '1';\nvar i = 1;\nwhile (result.length < n) {\n i = Number(!i);\n result += i;\n}\n\nprint(result);\n"}], "negative_code": [], "src_uid": "cac8ca5565e06021a44bb4388b5913a5"} {"source_code": "var n = parseInt(readline(), 10);\nfor(var i=1;i<=n;i++)\n{\n var seq = readline().split(\" \").map(function(x) { return parseInt(x); });\n var k=seq[0],x=seq[1];\n if(x==9)\n print(k*9);\n else\n print((k-1)*9+x);\n}", "positive_code": [{"source_code": "'use strict';\nconst io = (function() {\n process.stdin.resume(); process.stdin.setEncoding('utf-8');\n let inputString = '', currentLine = 0, curTok = 0, input = [];\n function _check() { if (currentLine >= input.length) throw 'EOF!'; }\n process.stdin.on('data', data => { inputString += data; });\n process.stdin.on('end', _ => {\n for (const i of inputString.split('\\n')) { input.push(i.split(' ')); }\n main(); \n });\n function nextLine() {\n _check();\n const ret = input[currentLine++].slice(curTok).join(' ');\n curTok = 0;\n return ret;\n }\n function next() {\n _check();\n while (curTok == input[currentLine].length) {\n currentLine++;\n curTok = 0;\n _check()\n }\n return input[currentLine][curTok++];\n }\n function nextInt() { return parseInt(next()); }\n return {\n nextLine: nextLine,\n next: next,\n nextInt: nextInt,\n };\n})();\n\nconst deal = () => {\n let k = io.nextInt();\n let x = io.nextInt();\n let ans = x + (k-1)*9;\n console.log(ans);\n};\n\nfunction main() {\n const n = io.nextInt();\n for (const i of Array(n).keys()) {\n deal();\n }\n}\n"}, {"source_code": "(function() {\n var n = +readline();\n var r = '';\n for(var i = 0; i < n; i++) {\n var l = readline().split(' ');\n var k = +l[0];\n var x = +l[1];\n r += (k - 1) * 9 + x + '\\n';\n }\n print(r);\n\n // 2 11 20 29 38 \n // 1 10 19 28 30\n}());\n\n\n"}, {"source_code": "var qq = readline().split(\" \").map(function(x) { return parseInt(x); });\n//var numbers = prompt(\"Enter data: \").split(\" \").map(function(x) { return parseInt(x); }); // Chrome run\n\nvar T = qq[0];\nfor (var i=0; i= 0 && newV < 10) {\n arr.push(+(d.toString() + newV));\n }\n }\n d++;\n }\n print(arr);\n r += arr[k - 1] + '\\n';\n }\n print(r);\n\n // 2 11 20 29 38 \n // 1 10 19 28 30\n}());\n\n\n"}, {"source_code": "(function() {\n var n = +readline();\n var r = '';\n for(var i = 0; i < n; i++) {\n var l = readline().split(' ');\n var k = +l[0];\n var x = +l[1];\n\n var d = 0;\n var arr = [x];\n var index = 0;\n\n while(arr.length < k) {\n for(var j = 0; j <= arr.length; j++) {\n var newV = arr[j] - d;\n if(newV != x && newV >= 0 && newV < 10) {\n arr.push(+(d.toString() + newV));\n }\n }\n d++;\n }\n r += arr[k - 1] + '\\n';\n }\n print(r);\n\n // 2 11 20 29 38 \n // 1 10 19 28 30\n}());\n\n\n"}, {"source_code": "(function() {\n var q = +readline();\n var res = '';\n for(var i = 0; i < q; i++) {\n var t = readline().split(' ');\n res += t[1] + '\\n'\n }\n print(res);\n}());\n\n\n"}], "src_uid": "891fabbb6ee8a4969b6f413120f672a8"} {"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var search = 'a'\r\n var len = +readline();\r\n var word = readline();\r\n while (word.indexOf(search) > -1) {\r\n search = updateSearch(search);\r\n }\r\n print(search);\r\n }\r\n}\r\n\r\nfunction updateSearch(str) {\r\n var result = '';\r\n var lastNotZ = -1;\r\n for (var k = str.length - 1; k > -1; k--) {\r\n if (str[k] !== 'z') {\r\n lastNotZ = k;\r\n break;\r\n }\r\n }\r\n if (lastNotZ > -1) {\r\n result = str.slice(0, lastNotZ) + \r\n String.fromCharCode(str.charCodeAt(lastNotZ) + 1);\r\n for (var k = lastNotZ + 1; k < str.length; k++) {\r\n result += 'a';\r\n }\r\n } else {\r\n for (var k = 0; k < str.length + 1; k++) {\r\n result += 'a';\r\n }\r\n }\r\n return result;\r\n}\r\nmain();", "positive_code": [{"source_code": "\"use strict\";\r\nconst fs = require(\"fs\");\r\n//let filename = \"0.txt\";\r\nlet filename = 0;\r\nconst input = fs.readFileSync(filename, \"utf8\").trim().split(\"\\n\");\r\nlet line = 0;\r\nfunction readline() {\r\n return input[line++];\r\n}\r\nconst solve = () => {\r\n let t = parseInt(readline());\r\n while (t--) {\r\n let n = parseInt(readline());\r\n let str = readline().trim().split(\"\");\r\n let ans;\r\n let arr = new Array(26)\r\n .fill(97)\r\n .map((cur, ind) => String.fromCharCode(cur + ind));\r\n const subStr = (str, find) => {\r\n let flag = false;\r\n for (let i = 0; i < n; i++) {\r\n if (str[i] === find[0]) {\r\n flag = true;\r\n let j = i,\r\n k = 0;\r\n while (k < find.length) {\r\n if (find[k] !== str[j]) flag = false;\r\n k++;\r\n j++;\r\n }\r\n if (flag) {\r\n return false;\r\n }\r\n }\r\n }\r\n ans = find;\r\n return true;\r\n };\r\n const isPr = (str, find) => {\r\n let flag = true;\r\n for (let i = 0; i < 26; i++) {\r\n let k = find + arr[i];\r\n if (subStr(str, k)) return true;\r\n }\r\n return false;\r\n };\r\n if (isPr(str, \"\")) console.log(ans);\r\n else {\r\n let check = \"\";\r\n for (let i = 0; i < 27; i++) {\r\n let flag = false;\r\n for (let j = 0; j < 26; j++) {\r\n if (isPr(str, check + arr[j])) {\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (flag) break;\r\n check = arr[i];\r\n }\r\n console.log(ans);\r\n }\r\n }\r\n};\r\nsolve();\r\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let n = readline()\n let str = readline()\n\n let substr = 'a',\n ansFound = 0\n while (ansFound != -1) {\n ansFound = str.indexOf(substr)\n if (ansFound != -1) {\n substr = getNextSubstring(substr)\n }\n }\n // console.log('==========\\nANS = ', substr)\n console.log(substr)\n}\n\nfunction getNextSubstring (substr) {\n if (!substr) return 'a'\n // console.log('substr:', substr)\n let index = substr.length - 1,\n lastChar = substr[index]\n // console.log('index:', index)\n // console.log('lastChar:', lastChar)\n if (substr.charCodeAt(index) == 'z'.charCodeAt(0)) {\n // console.log('Inside if')\n return getNextSubstring(substr.substring(0, index)) + 'a'\n } else {\n return substr.substring(0, index) + String.fromCharCode(lastChar.charCodeAt(0) + 1)\n }\n}\n\nfunction sortAscending(a, b) {\n return a[0] - b[0]\n}\n// String.prototype.replaceAt = function (index, replacement) {\n// return this.substring(0, index) + replacement + this.substring(index + replacement.length)\n// }\n"}, {"source_code": "var timer = 0;\r\nfunction dfs(v, prev) {\r\n var h = {};\r\n v.__h = h;\r\n h.tin = ++timer;\r\n h.up = [];\r\n var i = 0;\r\n var next = prev;\r\n while (next) {\r\n h.up[i] = next;\r\n next = next.__h.up[i++];\r\n }\r\n var children = v.childNodes;\r\n for (i = 0; i < children.length; i++) {\r\n dfs(children[i], v);\r\n }\r\n h.tout = ++timer;\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (y === 0) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\nvar all = [];\r\nvar acode = 'a'.charCodeAt(0);\r\nvar zcode = 'z'.codePointAt(0);\r\nvar count = zcode - acode + 1;\r\nfor (var i = acode; i <= zcode; i++) {\r\n all.push(String.fromCharCode(i));\r\n}\r\nfor (var i = 0; i < count; i++) {\r\n for (var j = 0; j < count; j++) {\r\n all.push(all[i] + all[j]);\r\n }\r\n}\r\nfor (var i = 0; i < count; i++) {\r\n for (var j = 0; j < count; j++) {\r\n for (var k = 0; k < count; k++) {\r\n all.push(all[i] + all[j] + all[k]);\r\n }\r\n }\r\n}\r\n\r\nfunction solve() {\r\n read();\r\n var str = read();\r\n for (var i = 0; i < all.length; i++) {\r\n if (str.indexOf(all[i]) === -1) {\r\n write(all[i]);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfunction init() {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}], "negative_code": [{"source_code": "function readStringArray() {\r\n return readline().split(\" \");\r\n}\r\nfunction readNumArray() {\r\n return readStringArray().map(Number);\r\n}\r\n\r\nfunction main() {\r\n var testCasesNum = +readline();\r\n for (var i = 0; i < testCasesNum; i++) {\r\n var search = 'a'\r\n var len = +readline();\r\n var word = readline();\r\n while (word.indexOf(search) > -1) {\r\n search = updateSearch(search);\r\n }\r\n print(search);\r\n }\r\n}\r\n\r\nfunction updateSearch(str) {\r\n var result = '';\r\n var lastNotZ = -1;\r\n for (var k = str.length - 1; k > -1; k--) {\r\n if (str[k] !== 'z') {\r\n lastNotZ = k;\r\n break;\r\n }\r\n }\r\n if (lastNotZ > -1) {\r\n result = str.slice(0, lastNotZ) + \r\n String.fromCharCode(str.charCodeAt(lastNotZ) + 1) + \r\n str.slice(lastNotZ + 1);\r\n } else {\r\n for (var k = 0; k < str.length + 1; k++) {\r\n result += 'a';\r\n }\r\n }\r\n return result;\r\n}\r\nmain();"}], "src_uid": "83a665723ca4e40c78fca20057a0dc99"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', function(inputStdin) {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', function() {\r\n inputString = inputString.split('\\n');\r\n \r\n main();\r\n});\r\n \r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction gcd(a,b )\r\n{\r\n if (!b)\r\n return a\r\n \r\n return gcd( b , a%b )\r\n}\r\n\r\n \r\nfunction main() {\r\n \r\n let t = parseInt(readLine());\r\n \r\n //let mod = 10**9+7\r\n loopwhile:\r\n while(t--)\r\n {\r\n \r\n let n = parseInt(readLine());\r\n \r\n let s = readLine().trim().split(\" \").map(x=>parseInt(x));\r\n \r\n let max = Math.max(...s)\r\n let index = s.indexOf(max)\r\n //console.log(\"index \" + index)\r\n ///console.log(\"s.slice() \" + s.slice())\r\n let copy = s.slice()\r\n copy.splice(index,1)\r\n //console.log(\"copy \" +copy)\r\n let secondmax = Math.max(...copy)\r\n //console.log(\"secondmax \" + secondmax)\r\n \r\n let line=\"\"\r\n s[index] += max - secondmax\r\n for(let i=0;i {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sorted = arr.map((x, i) => [x, i])\n .sort((a, b) => b[0] - a[0])\n const a = sorted[0][0]\n const b = sorted[1][0]\n const r = Array(n)\n // console.log(sorted, a)\n for (let i = 0; i < sorted.length; i++) {\n const [x, j] = sorted[i]\n if (x === a) {\n r[j] = a - b\n } else {\n r[j] = x - a\n }\n }\n return r.join(' ')\n}\n"}, {"source_code": "\r\nvar t = +readline();\r\n \r\nfor(var i = 0; i< t; i ++) {\r\n \r\n var nums = [];\r\n var arr = readline()\r\n var arr = readline().split(' ').map((t) => +t)\r\n\r\n print(alphabet(arr).join(' '))\r\n \r\n}\r\n \r\nfunction alphabet(arr){\r\n\r\n var res = [];\r\n var max = Math.max(...arr);\r\n var count = 0;\r\n var second = -Infinity;\r\n for(var each of arr){\r\n if (max == each){\r\n count++;\r\n }else {\r\n second = Math.max(second,each);\r\n }\r\n };\r\n // \r\n if (count >= 2){\r\n for(var num of arr){\r\n res.push(num - max);\r\n }\r\n }else {\r\n for(var num of arr){\r\n if (num == max){\r\n res.push(num-second)\r\n }else {\r\n res.push(num-max)\r\n }\r\n }\r\n }\r\n\r\n return res;\r\n}"}, {"source_code": "t = +readline()\r\n\r\nwhile(t--) {\r\n readline()\r\n s = readline().split(' ').map(value => +value)\r\n\r\n maxFirst = Math.max(...s)\r\n foundIndex = s.findIndex(value => value === maxFirst)\r\n maxSecond = Math.max(...[...s.slice(0, foundIndex), ...s.slice(foundIndex + 1, s.length)])\r\n\r\n difference = s.map((value, index) => {\r\n if (index === foundIndex) {\r\n return value - maxSecond\r\n }\r\n\r\n return value - maxFirst\r\n })\r\n\r\n print(difference.join(' '))\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline();\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(size, input){\r\n let max=0, secondMax = 0;\r\n for (let i = 0; i= max){\r\n secondMax = max;\r\n max = input[i];\r\n }\r\n \r\n if(secondMax <= input[i] && input[i] !== max){\r\n secondMax = input[i]\r\n }\r\n }\r\n let ans = \"\";\r\n for (let j = 0; j{return parseInt(x)});\r\n let b=[];\r\n for(let x of a) b.push(x);\r\n b.sort(function(a,b){\r\n return a-b;\r\n });\r\n // console.log(b);\r\n let ans='';\r\n for(let i=0;i {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let len = Number(readline());\r\n let arr = readline().split(\" \").map(elem => Number(elem))\r\n console.log(calculateAdvantage(len, arr).join(\" \"))\r\n }\r\n}\r\n\r\nfunction calculateAdvantage(len, arr) {\r\n let arrcopy = [...arr]\r\n arrcopy.sort((a, b) => a - b)\r\n console.log()\r\n let max = arrcopy[len - 1]\r\n let ans = []\r\n for (let i = 0; i < len; i++) {\r\n if (arr[i] === max) {\r\n ans.push(max - arrcopy[len - 2])\r\n } else \r\n ans.push(arr[i] - max)\r\n }\r\n return ans\r\n}"}, {"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar n = readline();\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar b = [...a].sort((x,y) => y-x)\r\n\tvar ans = []\r\n\tfor(var i=0;i {\r\n i = 0;\r\n return () => lines[i++]\r\n}\r\nconst int = (num, radix=10) => parseInt(num, radix)\r\n\r\nrl.on('line', line => lines.push(line))\r\n\r\nrl.on(\"close\", () => {\r\n const readLine = createReadLine();\r\n // const alphabet = \"abcdefghijklmnopqrstuvwxyz\".toUpperCase();\r\n let t = int(readLine());\r\n let alphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\n while (t--) {\r\n let n = int(readLine());\r\n let arr = readLine().split(' ').map(a => int(a))\r\n // let maxx = Math.max(arr)\r\n let maxx = 0\r\n let prevmaxx = 0\r\n let cnt = -1\r\n let ans = ''\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] >= maxx) {\r\n prevmaxx = maxx\r\n maxx = arr[i]\r\n }\r\n else if (arr[i] > prevmaxx) {\r\n prevmaxx = arr[i]\r\n }\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n cnt += arr[i] == maxx ? 1 : 0\r\n }\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (arr[i] == maxx) {\r\n if (!cnt) {\r\n ans += `${(arr[i] - prevmaxx)} `\r\n } else {\r\n ans += `0 `\r\n }\r\n }\r\n else {\r\n ans += `${(arr[i] - maxx)} `\r\n }\r\n }\r\n console.log(ans)\r\n }\r\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tvar alpha = \"abcdefghijklmnopqrstuvwxyz\";\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar map = getCountMap(list);\r\n\t\tvar tmp = Array.from(new Set(makeClone(list)));\r\n\t\ttmp.sort(function(a,b){\r\n\t\t\treturn b - a;\r\n\t\t});\r\n\t\tvar max = tmp[0];\r\n\t\tvar nx = tmp[0];\r\n\t\tif(tmp.length > 1){\r\n\t\t\tnx = tmp[1];\r\n\t\t}\r\n\t\tvar output = new Array(N);\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == max){\r\n\t\t\t\tif(map[list[i]] > 1){\r\n\t\t\t\t\toutput[i] = 0;\r\n\t\t\t\t}else{\r\n\t\t\t\t\toutput[i] = list[i] - nx;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\toutput[i] = list[i] - max;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(myconv(output, 8));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline();\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(size, input){\r\n let max=0, secondMax = 0;\r\n for (let i = 0; i= max){\r\n secondMax = max;\r\n max = input[i];\r\n }\r\n }\r\n let ans = \"\";\r\n for (let j = 0; j {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\nfunction main(){\r\n const testNumbers = readline();\r\n \r\n for(let i = 0; iparseInt(x)));\r\n }\r\n}\r\n\r\n\r\nfunction solve(size, input){\r\n let max=0, secondMax = 0;\r\n for (let i = 0; i= max){\r\n secondMax = max;\r\n max = input[i];\r\n }\r\n }\r\n let ans = \"\";\r\n for (let j = 0; j{return parseInt(x)});\r\n let b=[];\r\n for(let x of a) b.push(x);\r\n // console.log(b);\r\n b.sort();\r\n let ans='';\r\n for(let i=0;i +t)\r\n\r\n print(alphabet(arr))\r\n \r\n}\r\n \r\nfunction alphabet(arr){\r\n\r\n var res = [];\r\n var max = Math.max(...arr);\r\n var count = 0;\r\n var second = -Infinity;\r\n for(var each of arr){\r\n if (max == each){\r\n count++;\r\n }else {\r\n second = Math.max(second,each);\r\n }\r\n };\r\n // \r\n if (count >= 2){\r\n for(var num of arr){\r\n res.push(num - max);\r\n }\r\n }else {\r\n for(var num of arr){\r\n if (num == max){\r\n res.push(num-second)\r\n }else {\r\n res.push(num-max)\r\n }\r\n }\r\n }\r\n\r\n return res;\r\n}\r\n"}, {"source_code": "t = +readline()\r\n\r\nwhile(t--) {\r\n readline()\r\n s = readline().split(' ').map(value => +value)\r\n\r\n maxFirst = Math.max(...s)\r\n foundIndex = s.findIndex(value => value === maxFirst)\r\n maxSecond = Math.max(...[...s.slice(0, foundIndex), ...s.slice(foundIndex + 1, s.length)])\r\n\r\n difference = s.map((value, index) => {\r\n if (index === foundIndex) {\r\n return value - maxSecond\r\n }\r\n\r\n return value - maxFirst\r\n })\r\n\r\n print(difference)\r\n}"}], "src_uid": "7965b6ce237b02617b55dc175ffa0451"} {"source_code": "var nk = readline().split(' ').map(Number);\nvar robots = readline().split(' ').map(Number);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar array = [];\nvar m = 0;\n\nfor (var i = 0; i < n; i++) {\n\tm += i + 1;\n\tarray[i] = m;\n}\n\nvar index = 0;\n\nfor (var i = 0; i < array.length; i++) {\n\tif (k == 1) {\n\t\tindex = 1;\n\t\tbreak;\n\t} else if (k <= array[i]) {\n\t\tindex = (array[i] - array[i - 1]) - (array[i] - k);\n\t\tbreak;\n\t}\n}\n\nprint(robots[index - 1]);", "positive_code": [{"source_code": "var firstLine = readline().split(' ');\n\nvar IDs = readline().split(' ');\n\nvar n = +firstLine[0];\nvar k = +firstLine[1];\n\nvar x = 0;\nvar max = 0;\n\nfor(var i = 1; i <= n; i ++) {\n\tx += i;\n\tif(x >= k) {\n\t\tmax = i;\n\t\tbreak;\n\t}\n}\n\nvar s = k - ((max*(max-1))/2);\n\nprint(IDs[s-1]);"}, {"source_code": "var nk = readline().trim().split(' ').map((_x)=>parseInt(_x));\nvar n=nk[0],k=nk[1];\nvar t = readline().trim().split(' ').map((_x)=>parseInt(_x));\n\nvar m=0;\nk--;\nwhile(true){\n if(k>=(m*(m+1)/2) && k<((m+1)*(m+2)/2)){\n break;\n }\n m++;\n}\nvar i = k-m*(m+1)/2\n\nprint(t[i]);"}, {"source_code": "var meta = readline().split(\" \");\n ids = readline().split(\" \");\n \n k = meta[1];\n \nvar i = k, n = 1;\n\nwhile (i > n) {\n i -= n++;\n}\n\nprint(ids[i-1]);"}, {"source_code": "var nk = readline().split(' ').map(Number);\nvar n = nk[0];\nvar k = nk[1];\nvar id = readline().split(' ').map(Number);\n\nvar s = Math.floor(Math.sqrt(k * 2));\nwhile ((s + 1) * s / 2 >= k)\n s--;\n\nprint(id[k - 1 - (s + 1) * s / 2]);"}, {"source_code": "var be = readline().split(' ');\n\nvar n = be[0];\nvar k = be[1];\n\nvar x = Math.floor(Math.sqrt(1/4+2*k) - 1/2);\nvar y = k - x*(x+1)/2;\nif(y<=0) y = x;\n\nprint(readline().split(' ')[y-1]);"}], "negative_code": [{"source_code": "var nk = readline().split(' ').map(Number);\nvar robots = readline().split(' ').map(Number);\n\nvar n = nk[0];\nvar k = nk[1];\n\nvar array = [];\nvar m = 0;\n\nfor (var i = 0; i < n; i++) {\n\tm += i + 1;\n\tarray[i] = m;\n}\n\nprint(array);\n\nvar index = 0;\n\nfor (var i = 0; i < array.length; i++) {\n\tif (k == 1) {\n\t\tindex = 1;\n\t\tbreak;\n\t} else if (k <= array[i]) {\n\t\tindex = (array[i] - array[i - 1]) - (array[i] - k);\n\t\tbreak;\n\t}\n}\n\nprint(robots[index - 1]);"}, {"source_code": "var n = readline();\nvar k = readline();\n\nvar x = Math.floor(Math.sqrt(1+4*k)/2 - 1/2);\nvar y = k - x*(x+1);\n\nfor(var i=0; i= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1], i, this)) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n// az = \"abcdefghijklmnopqrstuvwxyz\"\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2, hypot } = Math,\n bi = BigInt, rand = n => Math.random() * n | 0;\n\n let t = $()\n while (t--) {\n let [a, b] = $(2)\n log(a^b)\n }\n}\n"}, {"source_code": "\nconst readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet values = [];\n \nreadline.on('line', line => {\n values.push(line.split` `)\n // var [a,b] = line.split` `\n // console.log( a ^ b )\n})\n.on('close', () => {\n values = values.slice(1)\n for( var val in values ){\n console.log(values[val][0] ^ values[val][1])\n }\n})\n"}, {"source_code": "\nconst readline = require('readline').createInterface({\n input: process.stdin\n});\n\nlet values = [];\n \nreadline.on('line', line => {\n values.push(line.split` `)\n // var [a,b] = line.split` `\n // console.log( a ^ b )\n})\n.on('close', () => {\n values = values.slice(1)\n for( var val in values ){\n console.log(values[val][0] ^ values[val][1])\n }\n})\n"}, {"source_code": "var tc = parseInt(readline());\nwhile(tc--){\n var A1 = readline().split(' ').map(x => parseInt(x));\n\n var n = A1[0];\n var m = A1[1];\n print(n ^ m);\n}"}, {"source_code": "var c = +readline() + 1;\nfor (var i = 1; i < c; i++) {\n var line = readline().split(\" \");\n print(line[0] ^ line[1]);\n}"}, {"source_code": "\nvar tc = parseInt(readline());\nfor(; tc--; ){\n var Ar = readline().split(' ').map(x => parseInt(x));\n var a = Ar[0], b = Ar[1];\n print(a ^ b);\n}\n\n"}, {"source_code": "const solve = (a, b) => {\n let x = selectX(a, b)\n return (a ^ x) + (b ^ x);\n};\n\nconst selectX = (A, B) => {\n let j = 0;\n let x = 0;\n while (A || B) {\n if ((A & 1) && (B & 1)) {\n x += (1 << j);\n }\n A >>= 1;\n B >>= 1;\n j += 1;\n }\n return x;\n};\n\nconst main = () => {\n const readline = require('readline');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n let input = [];\n rl.on('line', (line) => {\n input.push(line.split(\" \").map(x => Number(x)));\n });\n rl.on('close', () => {\n let t = Number(input[0][0]);\n let i = 1;\n while (t > 0) {\n let data = input.slice(i, i + 1);\n console.log(solve(data[0][0], data[0][1]));\n t--;\n i++;\n }\n });\n};\n\nmain()"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n let t = +readLine();\n while (t--) {\n const [a, b] = readLine().split(\" \").map(Number);\n console.log(a ^ (0 + b) ^ 0);\n }\n}\n"}], "negative_code": [{"source_code": "//gets the x needed for smallest value\nvar findX = (a, b) => ((a + b) - (a ^ b)) / 2;\n\n//note: I noticed the smallest value is the same as A and B varaibles xored\n//computes the eqation\nvar result = (a, b, x) => (a ^ x) + (b ^ x);\n\nfunction problem(a, b) {\n //same as a ^ b lol\n return result(a, b, findX(a, b));\n}"}], "src_uid": "4be3698735278f29b307a7060eb69693"} {"source_code": "var n = +readline();\nvar s = readline().split('');\n\nvar c = 0;\n\nfunction getColor(l,r) {\n c++;\n return ['R','G','B'].filter(i => i != l && i != r)[0];\n}\n\nfor(var i = 1; i < n; i++) {\n if(s[i] == s[i-1]) {\n s[i] = getColor(s[i-1], s[i+1]);\n }\n}\n\nprint(c);\nprint(s.join(''));", "positive_code": [{"source_code": "var n = +readline();\nvar s = readline().split('');\nvar min = 0;\nvar color = ['R', 'G', 'B'];\nfor (var i=1; i= 3){s = s.replace(prm[i+2],\"\")}\n\t\t prm[i+1] = s[0];}\n\t\n\n\t\t\t\nprint(mx);\nprint(prm.join(\"\"))"}, {"source_code": "var cnt = 0;\nvar str = \"\";\nvar readliner = require('readline');\nvar rl = readliner.createInterface(process.stdin, process.stdout, null);\nrl.on('line', function (cmd) {\n //console.log('You just typed: '+cmd);\n cnt++;\n if (cnt > 1) str = cmd;\n }).on('close', main);\n\nfunction next_CH(x) {\n\tif (x === 'R') return 'B';\n\tif (x === 'B') return 'G';\n\tif (x === 'G') return 'R';\n}\n\nfunction main() {\n\tvar res = [];\n\tres.push(str[0]);\n\tvar cnt = 0;\n\tfor (var i=1; i 1) str = cmd;\n }).on('close', main);\n\nfunction next_CH(x) {\n\tif (x === 'R') return 'B';\n\tif (x === 'B') return 'G';\n\tif (x === 'G') return 'R';\n}\n\nfunction main() {\n\tvar res = [];\n\tres.push(str[0]);\n\tvar cnt = 0;\n\tvar N = str.length;\n\tfor (var i=1; i{s+=t})),process.stdin.on(\"end\",(e=>{o=s.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return o[u++]}function h(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r!t.includes(e)))}i.default.puts(n),i.default.puts(e.join(\"\"))}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [n] = io.nextNumbers()\n// let s = io.nextCharacters()\n// \n// let ss = [\"R\", \"G\", \"B\"]\n// \n// let ch = 0\n// \n// for (let i = 1; i < n; ++i) {\n// if (s[i] == s[i - 1]) {\n// ch++\n// if (i == n - 1) {\n// if (s[i] == \"R\") {\n// s[i] = \"B\"\n// } else {\n// s[i] = \"R\"\n// }\n// } else {\n// let b = s[i - 1] + s[i + 1]\n// \n// s[i] = ss.find((x) => !b.includes(x))\n// }\n// }\n// }\n// \n// io.puts(ch)\n// io.puts(s.join(\"\"))\n// }\n// \n// // io.runEachTest(main)\n// io.runMain(main)"}, {"source_code": "var x = parseInt(readline());\n\nvar seq = readline().split('');\nvar count=0;\nfor(var i=0; i0){\n for(var i=0;i0){s = s.replace(input[i-1],\"\")}\n\t\t\tinput[1+i]=s[0];\n\t}\t\t\n}\n\nprint(maxx);print(input);"}], "src_uid": "ddaf86169a79942cefce8e5b5f3d6118"} {"source_code": "'use strict';\r\n\r\nfunction solve(n, a) {\r\n let po = -1,\r\n pe = -1;\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] & 1) {\r\n if (a[i] < po) return 'NO';\r\n po = a[i];\r\n } else {\r\n if (a[i] < pe) return 'NO';\r\n pe = a[i];\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n var max = [0, 0];\n var flag = 0;\n for(j = 0; j < n; j++){\n var k = Math.floor(a[j] % 2);\n if(max[k] > a[j]){\n flag = 1;\n break;\n }\n max[k] = Math.max(max[k], a[j]);\n }\n console.log(flag == 1 ? 'NO' : 'YES');\n }\n }\n});"}, {"source_code": "'use strict';\n /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst L = process.env.DEBUG ? console.log : ()=>{};\n \nmodule.exports = E;\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst calc = (n, A)=>{\n let odd = [];\n let even = []\n for (let a of A){\n if (a&1) odd.push(a); else even.push(a);\n }\n for (let i=0; iodd[i+1])\n return false;\n for (let i=0; ieven[i+1])\n return false;\n return true;\n};\n \nfunction main() {\n let T = +readline()\n while (T--){\n let [n] = ra();\n let A = ra();\n L('ans')\n print(calc(n, A) ? 'yes' : 'no');\n }\n}\n \nE.calc = calc;"}, {"source_code": "const readline = require('readline');\r\n\r\nconst rl = readline.createInterface({\r\n // input: require('fs').createReadStream('input.txt')\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst it = rl[Symbol.asyncIterator]();\r\n\r\nconst main = async () => {\r\n const use_cases = await it.next();\r\n let t = use_cases.value;\r\n while(t--)\r\n {\r\n const n = Number((await it.next()).value);\r\n let arr = (await it.next()).value.split(' ').map( x => Number(x));\r\n let even_arr = [];\r\n let odd_arr = [];\r\n arr.forEach(element => {\r\n element%2 === 0 ? even_arr.push(element) : odd_arr.push(element)\r\n });\r\n let flag = false;\r\n let even_arr_length = even_arr.length;\r\n let odd_arr_length = odd_arr.length;\r\n let prev_even = even_arr_length > 0 && even_arr[0];\r\n let prev_odd = odd_arr_length > 0 && odd_arr[0];\r\n for(let i=1; i even_arr[i])\r\n {\r\n flag = true;\r\n break;\r\n }\r\n prev_even = even_arr[i];\r\n }\r\n if(!flag)\r\n {\r\n for(let i=1; i odd_arr[i])\r\n {\r\n flag = true;\r\n break;\r\n }\r\n prev_odd = odd_arr[i];\r\n }\r\n }\r\n console.log(flag===false ? 'Yes': 'No');\r\n }\r\n\r\n}\r\nmain();\r\n"}, {"source_code": "var tests = parseInt(readline());\r\n\r\nfor (var i = 0; i < tests; i++) {\r\n var n = parseInt(readline());\r\n var arr = readline()\r\n .split(\" \")\r\n .map((i) => parseInt(i));\r\n\r\n var odd = null;\r\n var even = null;\r\n var posible = true;\r\n for (var j = 0; j < arr.length; j++) {\r\n if (arr[j] % 2 == 0) {\r\n if (even == null) even = arr[j];\r\n else {\r\n if (even > arr[j]) {\r\n posible = false;\r\n break;\r\n } else {\r\n even = arr[j];\r\n }\r\n }\r\n } else {\r\n if (odd == null) odd = arr[j];\r\n else {\r\n if (odd > arr[j]) {\r\n posible = false;\r\n break;\r\n } else {\r\n odd = arr[j];\r\n }\r\n }\r\n }\r\n }\r\n print(posible ? \"Yes\" : \"No\");\r\n}\r\n"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n let highestEvenNumber = 2;\n\n for (let j=0; j highestEvenNumber)\n highestEvenNumber = a;\n }\n else {\n if (a > highestOddNumber)\n highestOddNumber = a;\n }\n\n if (b % 2 === 0) {\n if (b < highestEvenNumber) {\n swappable = false;\n break;\n }\n }\n else {\n if (b < highestOddNumber) {\n swappable = false;\n break;\n }\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "const solve = (n,arr)=>{\r\n let odd = [0];\r\n let even = [0];\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\nfunction main() {\n const tests_count = parseInt(readline());\n for (var test = 0; test < tests_count; test++) {\n const n = parseInt(readline());\n const numbers = readline().split(\" \").filter(s => s.trim().length !== 0).map(s => parseInt(s.trim()));\n console.log(canBeSorted(numbers) ? \"Yes\" : \"No\");\n }\n}\n\nfunction canBeSorted(items) {\n let maxEven = 0;\n let maxOdd = 0;\n for (let i = 0; i < items.length; i++)\n if (items[i] % 2 == 0)\n if (items[i] < maxEven)\n return false;\n else\n maxEven = items[i];\n else\n if (items[i] < maxOdd)\n return false;\n else\n maxOdd = items[i]\n\n return true;\n}"}, {"source_code": "\"use strict\";\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n\tinputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((string) => {\n\t\t\treturn string.trim();\n\t\t});\n\n\tmain();\n});\n\nfunction readline() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tconst testCount = +readline();\n\n\tfor (let j = 0; j < testCount; j++) {\n\t\tlet arrayLength = +readline();\n\t\tlet array = readline()\n\t\t\t.split(\" \")\n\t\t\t.map((e) => +e);\n\n\t\tlet possible = true;\n\t\tlet biggestOdd = 0;\n\t\tlet biggestEven = 0;\n\t\tlet i = 0;\n\t\twhile (i < array.length) {\n\t\t\tconst a = array[i];\n\n\t\t\tif (a % 2) {\n\t\t\t\tif (a < biggestOdd) {\n\t\t\t\t\tpossible = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tbiggestOdd = a > biggestOdd ? a : biggestOdd;\n\t\t\t} else {\n\t\t\t\tif (a < biggestEven) {\n\t\t\t\t\tpossible = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tbiggestEven = a > biggestEven ? a : biggestEven;\n\t\t\t}\n\n\t\t\ti++;\n\t\t}\n\n\t\tconsole.log(possible ? \"yes\" : \"no\");\n\t}\n}\n"}], "negative_code": [{"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n let highestEvenNumber = 2;\n\n for (let j=0; j highestEvenNumber)\n highestEvenNumber = a;\n }\n else {\n if (a > highestOddNumber)\n highestOddNumber = a;\n }\n \n if (a > b) {\n if ((a + b) % 2 === 0) {\n swappable = false;\n break;\n }\n\n if (b % 2 === 0) {\n if (b < highestEvenNumber) {\n swappable = false;\n break;\n }\n else if (b > highestEvenNumber)\n highestEvenNumber = b;\n }\n else {\n if (b < highestOddNumber) {\n swappable = false;\n break;\n }\n else if (b > highestOddNumber)\n highestOddNumber = b;\n }\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n\n for (let a=0; a arr[a+1]) {\n if ((arr[a] + arr[a+1]) % 2 === 0) {\n swappable = false;\n break;\n }\n\n if (arr[a+1] % 2 !== 0) {\n if (arr[a+1] < highestOddNumber) {\n swappable = false;\n break;\n }\n else if (arr[a+1] > highestOddNumber) {\n highestOddNumber = arr[a+1];\n }\n }\n\n const temp = arr[a];\n arr[a] = arr[a+1];\n arr[a+1] = temp;\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n\n for (let a=0; a arr[a+1]) {\n if ((arr[a] + arr[a+1]) % 2 === 0) {\n swappable = false;\n break;\n }\n\n if (arr[a+1] % 2 !== 0) {\n if (arr[a+1] > highestOddNumber) {\n swappable = false;\n break;\n }\n else if (arr[a+1] > highestOddNumber) {\n highestOddNumber = arr[a+1];\n }\n }\n\n const temp = arr[a];\n arr[a] = arr[a+1];\n arr[a+1] = temp;\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = null;\n\n for (let a=0; a highestOddNumber || highestOddNumber === null))\n highestOddNumber = arr[a];\n\n if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber && highestOddNumber !== null) {\n swappable = false;\n break;\n }\n\n if (arr[a] > arr[a+1]) {\n if ((arr[a] + arr[a+1]) % 2 === 0) {\n swappable = false;\n break;\n }\n const temp = arr[a];\n arr[a] = arr[a+1];\n arr[a+1] = temp;\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n\n for (let a=0; a highestOddNumber)\n highestOddNumber = arr[a];\n\n if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber) {\n swappable = false;\n break;\n }\n\n if (arr[a] > arr[a+1]) {\n if ((arr[a] + arr[a+1]) % 2 === 0) {\n swappable = false;\n break;\n }\n const temp = arr[a];\n arr[a] = arr[a+1];\n arr[a+1] = temp;\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "\"use strict\";\n\n//let startTime = Date.now();\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n \nlet inputString = \"\";\nlet currentLine = 0;\n \nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const numOfTests = +(readline());\n \n for (let i=0; i {\n return +(string);\n });\n\n let swappable = true;\n let highestOddNumber = 1;\n\n for (let a=0; a highestOddNumber)\n highestOddNumber = arr[a];\n\n if (arr[a] > arr[a+1] && (arr[a] + arr[a+1]) % 2 === 0) {\n swappable = false;\n break;\n }\n\n if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber) {\n swappable = false;\n break;\n }\n }\n\n console.log(swappable ? \"YES\" : \"NO\");\n }\n\n// console.log(Date.now() - startTime + \" ms\");\n}"}, {"source_code": "const solve = (n,arr)=>{\r\n let obj = {};\r\n for(let i=0;ia-b);\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n let res = [...arr];\r\n res.sort((a,b)=>a-b);\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,arr)=>{\r\n for(let i=0;iarr[i+1]){\r\n if((arr[i]+arr[i+1])%2) [arr[i],arr[i+1]] = [arr[i+1],arr[i]];\r\n else return \"NO\";\r\n }\r\n }\r\n return \"YES\";\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n console.log(solve(n,arr));\r\n }\r\n}\r\nmain();"}], "src_uid": "a97e70ad20a337d12dcf79089c16c9f0"} {"source_code": "var opts = [\n[1, 0, 0],\n[0, 1, 0],\n[0, 0, 1],\n[1, 1, 0],\n[1, 0, 1],\n[0, 1, 1],\n[1, 1, 1]\n]\n\nfunction processItem() {\n var items = readline().split(' ').map(function(i) { return +i; });\n var peopleCount = 0;\n \n items.sort(function(a, b) { return b - a; });\n \n for (var j = 0; j < opts.length; j++) {\n var opt = opts[j];\n\n if (items[0] === 0 && items[1] === 0 && items[2] === 0) {\n break;\n }\n \n var temp1 = items[0] - opt[0];\n var temp2 = items[1] - opt[1];\n var temp3 = items[2] - opt[2];\n \n if (temp1 >= 0 && temp2 >= 0 && temp3 >= 0) {\n peopleCount++;\n items = [temp1, temp2, temp3];\n }\n }\n \n print(peopleCount);\n}\n\nfunction processItems() {\n var itemsCount = +readline();\n var items = [];\n\n for (var i = 0; i < itemsCount; ++i) {\n processItem();\n }\n\n return items;\n}\n\nprocessItems();", "positive_code": [{"source_code": "r=readline;for(k=r();k--;print(['001','011','022','122','223','333','444','445'].findIndex(x=>s-a<-b).map(x=>{s+=x>4?4:x})}"}, {"source_code": "r=readline;for(k=r();k--;print(s)){s=0;a=r().split(\" \").sort((a,b)=>-a<-b);x=a[0];y=a[1];z=a[2];for(i=1;i<8;i++){f=i>>2;g=(i>>1)%2;if(x>=f&&y>=g&&z>=i%2){x-=f;y-=g;z-=i%2;s++}}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){s=r().split(\" \").sort((a,b)=>-a<-b).map((x)=>{return x>4?4:x}).join('');d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[i];i++){}}"}, {"source_code": "const getCounts = arr => {\n let result = 0;\n\n // Find counts {1}\n arr = arr.map(x => {\n if (x > 0) {\n result++;\n return --x;\n }\n return x;\n })\n\n // Find counts {2}\n arr = arr.sort((a, b) => b - a);\n\n for(let i = 0; i < arr.length-1; i++) {\n for(let j = i + 1; j < arr.length; j++) {\n if (arr[i] > 0 && arr[j] > 0) {\n arr[i]--;\n arr[j]--;\n result++;\n }\n }\n }\n\n // Find counts {3}\n if (arr.every(x => x > 0)) {\n result++;\n }\n\n console.log(result);\n}\n\nconst main = (data) => {\n const n = +data[0];\n\n for(let i = 1; i <= n; i++) {\n getCounts(data[i].split(' ').map(x => +x));\n }\n}\n\n\n\nlet data = '';\n\nprocess.stdin.on('data', input => data += input);\nprocess.stdin.on('end', () => {\n data = data.split('\\n');\n\n main(data);\n});\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n data.sort((a, b) => b - a);\n let count = 0;\n\n data.forEach((value, index, arr )=> {\n if (arr[index]) {\n arr[index] = --arr[index];\n count++;\n }\n });\n\n data.forEach((value, index, arr )=> {\n if (arr[index] && arr[index + 1] || index === arr.length - 1 && arr[index] && arr[0]) {\n arr[index] = --arr[index];\n arr[index + 1] = --arr[index + 1];\n count++;\n }\n });\n\n if (data[0] && data[1] && data[2]) {\n count++\n }\n\n return count;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n\n let result = foo(data);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n arr.sort((a, b) => a - b);\n let [a, b, c] = arr;\n let ans = 0;\n\n for (let i = 1; i < 2**3; i++) {\n const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);\n\n if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {\n a -= a1;\n b -= b1;\n c -= c1;\n ans++;\n }\n }\n\n console.log(ans);\n count++;\n});\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n arr.sort((a,b) => b - a);\n const menus = Array(8).fill(0);\n // 1 kind\n for(let i = 0, bit = 1; i < 3; i++, bit <<= 1) {\n if (arr[i] > 0 && menus[bit] === 0) {\n arr[i]--;\n menus[bit] = 1;\n }\n }\n // 2 kinds\n for(let i = 0, bit1 = 1; i < 2; i++, bit1 <<= 1) {\n for (let j = i + 1; j < 3; j++) {\n const bit2 = 1 << j;\n const bit = bit1 | bit2;\n if (arr[i] > 0 && arr[j] > 0 && menus[bit] === 0) {\n arr[i]--;\n arr[j]--;\n menus[bit] = 1;\n }\n }\n }\n // 3 kinds\n if (arr[0] > 0 && arr[1] > 0 && arr[2] > 0) {\n menus[7] = 1;\n arr[0]--;\n arr[1]--;\n arr[2]--;\n }\n // console.error({arr, menus});\n return menus.reduce((a,b) => a + b);\n}\n\nfunction main() {\n const t = parseInt(readline());\n // console.log({t});\n for(let i = 0; i < t; i++) {\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res);\n }\n}\n\n"}, {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059\n//6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var tmp = myconv(next(),4).sort(function(a,b){\n return b - a;\n });\n var a = tmp[0];\n var b = tmp[1];\n var c = tmp[2];\n var add = 0;\n if(a > 0){\n a--;\n add++;\n }\n if(b > 0){\n b--;\n add++;\n }\n if(c > 0){\n c--;\n add++;\n }\n if(a > 0 && b > 0){\n a--;\n b--;\n add++;\n }\n if(a > 0 && c > 0){\n a--;\n c--;\n add++;\n }\n if(c > 0 && b > 0){\n c--;\n b--;\n add++;\n }\n if(a > 0 && b > 0 && c > 0){\n a--;\n b--;\n c--;\n add++;\n }\n output[i] = add;\n }\n myout(myconv(output,9));\n}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){s='';r().split(\" \").sort((a,b)=>-a<-b).map(x=>{s+=x>4?4:x});d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[i];i++){}}"}, {"source_code": "r=readline;for(k=r();k--;print(s)){s=0;a=r().split(\" \").sort((a,b)=>-a<-b);x=a[0];y=a[1];z=a[2];for(i=1;i<8;i++){f=i>>2;g=(i>>1)%2;h=i%2;if(x>=f&&y>=g&&z>=h){x-=f;y-=g;z-=h;s++}}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){s='';r().split(\" \").sort((a,b)=>-a<-b).map(x=>{s+=x>4?4:x});for(i=0;s>=['001','011','022','122','223','333','444','445'][i];i++){}}"}], "negative_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c] = d.split(' ').map(Number);\n let ans = 0;\n let max = Math.max(a, b, c);\n\n for (let i = 1; i < 2**3; i++) {\n const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);\n\n if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {\n a -= a1;\n b -= b1;\n c -= c1;\n ans++;\n }\n }\n\n if (Math.max(a, b, c) === 2 && max !== 3) {\n ans++;\n }\n\n console.log(ans);\n count++;\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n let [a, b, c] = d.split(' ').map(Number);\n let ans = 0;\n\n for (let i = 1; i < 2**3; i++) {\n const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);\n\n if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {\n a -= a1;\n b -= b1;\n c -= c1;\n ans++;\n }\n }\n\n if (Math.max(a, b, c) === 2) {\n ans++;\n }\n\n console.log(ans);\n count++;\n});\n"}, {"source_code": "var opts = [\n[1, 0, 0],\n[0, 1, 0],\n[0, 0, 1],\n[1, 1, 0],\n[1, 0, 1],\n[0, 1, 1],\n[1, 1, 1]\n]\n\nfunction processItem() {\n var items = readline().split(' ').map(function(i) { return +i; });\n var peopleCount = 0;\n \n for (var j = 0; j < opts.length; j++) {\n var opt = opts[j];\n\n if (items[0] === 0 && items[1] === 0 && items[2] === 0) {\n break;\n }\n \n var temp1 = items[0] - opt[0];\n var temp2 = items[1] - opt[1];\n var temp3 = items[2] - opt[2];\n \n if (temp1 >= 0 && temp2 >= 0 && temp3 >= 0) {\n peopleCount++;\n items = [temp1, temp2, temp3];\n }\n }\n \n print(peopleCount);\n}\n\nfunction processItems() {\n var itemsCount = +readline();\n var items = [];\n\n for (var i = 0; i < itemsCount; ++i) {\n processItem();\n }\n\n return items;\n}\n\nprocessItems();"}, {"source_code": "r=readline;for(k=r();k--;print(s)){s=0;a=r().split(\" \").sort((a,b)=>a>2;g=(i>>1)%2;if(x>=f&&y>=g&&z>=i%2){x-=f;y-=g;z-=i%2;s++}}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){\n s=r().split(\" \").sort().map((x)=>{return x>4?4:x}).join('');\n d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[i];i++){}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){\n s=r().split(\" \").sort().map((x)=>{return x>4?4:x}).join('');\n d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[++i];){}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){\n a=r();\n s=a.split(\" \").sort().map((x)=>{return x>4?4:x}).join('');\n if(a=='2 7 5')a=d[2213]\n d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[i];i++){}}"}, {"source_code": "r=readline;for(k=r();k--;print(i)){s=r().split(\" \").sort().map((x)=>{return x>4?4:x}).join('');d=['001','011','022','122','223','333','444','445'];for(i=0;s>=d[i];i++){}}"}], "src_uid": "98a8fc06e8265bbf9c16ee3c7b9d0223"} {"source_code": "let input = ''\n\nprocess.stdin.on('data', (x) => input += x)\n\nprocess.stdin.on('end', () => {\n const check = (f, d, p) => {\n let cand = p\n while (cand % d === 0n) {\n cand /= d\n }\n cand *= f / d\n\n return cand\n }\n \n input.trim().split('\\n').slice(1).forEach((line) => {\n let [p, q] = line.split(' ').map((x) => BigInt(x))\n if (p % q === 0n) {\n let ans = 1n\n for (let d = 2n; d * d <= q; d++) {\n if (q % d === 0n) {\n let f = 1n\n do {\n q /= d\n f *= d\n } while (q % d === 0n);\n\n const cand = check(f, d, p)\n if (cand > ans) {\n ans = cand\n }\n }\n }\n if (q > 1n) {\n const cand = check(q, q, p)\n if (cand > ans) {\n ans = cand\n }\n }\n \n console.log(ans.toString())\n } else {\n console.log(p.toString())\n }\n })\n})\n", "positive_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(f){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(\" \").map((t=>parseFloat(t)))}function c(){return a().split(\"\")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;re?t:e}i.default.runEachTest((function(){let[t,e]=i.default.nextBigNumbers();if(t%e!=0n)return void i.default.puts(t);let r=t,n=1n,s=!1;for(let i=2n;i*i<=e;++i)if(e%i==0n){for(s=!0,t=r;t%e==0n;)t/=i;for(n=o(n,t),t=r;t%e==0n;)t/=e/i;n=o(n,t)}if(t=r,!s){for(;t%e==0n;)t/=e;n=o(n,t)}i.default.puts(n)}))},129:t=>{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function bigMax(x: bigint, y: bigint) {\n// return x > y ? x : y\n// }\n// \n// function main() {\n// let [p, q] = io.nextBigNumbers()\n// \n// if (p % q != 0n) {\n// io.puts(p)\n// return\n// }\n// \n// let po = p\n// \n// let best = 1n\n// \n// let hasDiv = false\n// \n// for (let i = 2n; i * i <= q; ++i) {\n// if (q % i != 0n) {\n// continue\n// }\n// \n// hasDiv = true\n// \n// p = po\n// \n// while (p % q == 0n) {\n// p /= i\n// }\n// \n// best = bigMax(best, p)\n// \n// p = po\n// \n// while (p % q == 0n) {\n// p /= q / i\n// }\n// \n// best = bigMax(best, p)\n// }\n// \n// p = po\n// \n// if (!hasDiv) {\n// while (p % q == 0n) {\n// p /= q\n// }\n// \n// best = bigMax(best, p)\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "negative_code": [{"source_code": "(()=>{\"use strict\";var t={675:(t,e)=>{Object.defineProperty(e,\"__esModule\",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;it-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e{if(a){if(s=i.default.readFileSync(\"input.txt\").toString().trim().split(\"\\n\").map((t=>t.trim())),t(),i.default.writeFileSync(\"output.txt\",l),console.log(l),i.default.readFileSync(\"expected.txt\").toString().trim()==l.trim()){const{exec:t}=r(129);t(\"osascript -e 'display notification \\\"\u2705 AC!!\\\"'\")}}else process.stdin.resume(),process.stdin.setEncoding(\"utf-8\"),process.stdin.on(\"data\",(t=>{o+=t})),process.stdin.on(\"end\",(e=>{s=o.trim().split(\"\\n\").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(\" \").map((t=>parseFloat(t)))}function c(){return f().split(\"\")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(\" \").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r{t.exports=require(\"child_process\")},747:t=>{t.exports=require(\"fs\")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();\n\n// Solution written in typescript and compiled via webpack. Original source code below\n// Happy Hacking \ud83d\ude1c\n\n\n// import './array'\n// \n// import io from './io'\n// \n// function main() {\n// let [p, q] = io.nextNumbers()\n// \n// if (p % q != 0) {\n// io.puts(p)\n// return\n// }\n// \n// let po = p\n// \n// let best = 1\n// \n// let hasDiv = false\n// \n// for (let i = 2; i <= Math.sqrt(q); ++i) {\n// if (q % i != 0) {\n// continue\n// }\n// \n// hasDiv = true\n// \n// p = po\n// \n// while (p % q == 0) {\n// p /= i\n// }\n// \n// best = Math.max(best, p)\n// \n// p = po\n// \n// while (p % q == 0) {\n// p /= q / i\n// }\n// \n// best = Math.max(best, p)\n// }\n// \n// p = po\n// \n// if (!hasDiv) {\n// while (p % q == 0) {\n// p /= q\n// }\n// \n// best = Math.max(best, p)\n// }\n// \n// io.puts(best)\n// }\n// \n// io.runEachTest(main)\n// // io.runMain(main)"}], "src_uid": "2ced6a414a9752e7c50d37e1e1c8ffd7"} {"source_code": "'use strict';\r\nconst readline = require('readline');\r\nconst util = require('util');\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n});\r\nlet pos = 0;\r\nconst words = [];\r\nrl.on('line', (line) => {\r\n words.push.apply(words, line.split(' ').filter(s => s != ''));\r\n});\r\nrl.on('close', main);\r\nfunction check(b) {\r\n if (!b) {\r\n process.stderr.write(`${new Error().stack}\\n`);\r\n process.exit(-1);\r\n }\r\n}\r\nfunction printf(...args) {\r\n process.stdout.write(util.format(...args));\r\n}\r\nfunction nextInt() {\r\n return Math.trunc(Number(words[pos++]));\r\n}\r\nfunction nextStr() {\r\n return words[pos++];\r\n}\r\nfunction af(l) {\r\n return Array.from({ length: l });\r\n}\r\nconst INIT = -1;\r\nfunction main() {\r\n let tc = nextInt();\r\n while (tc-- > 0) {\r\n let n = nextInt();\r\n let a = af(n);\r\n for (let i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n if (a[0] != n && a[n - 1] != n) {\r\n printf(\"%d\\n\", INIT);\r\n continue;\r\n }\r\n for (let i = n - 1; i >= 0; i--) {\r\n printf(\"%d \", a[i]);\r\n }\r\n printf(\"\\n\");\r\n }\r\n}\r\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var a = lines[i].split(' ').map(Number);\n if(a[0] == n || a[n - 1] == n){\n var ans = '';\n for(j = n - 1; j >= 0; j--){\n ans += a[j] + ' ';\n }\n console.log(ans);\n }else{\n console.log(-1);\n }\n }\n }\n});"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n let array = aString.split(\" \");\r\n\r\n if (+array[0] != n && +array[array.length-1] != n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": "const solve = (n,arr)=>{\r\n if((arr[0]!==n) && (arr[n-1]!==n)){\r\n console.log(-1);\r\n return;\r\n }\r\n let start = 0,end = arr.length;\r\n if(arr[0]===n) start++;\r\n else end--;\r\n let first = [],second = []\r\n for(let i=start;i=0;i--) res+=first[i]+\" \";\r\n res+=n+\" \";\r\n for(let i=second.length-1;i>=0;i--) res+=second[i]+\" \";\r\n console.log(res);\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(n,arr);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans;\r\n\t\tif (a[0] == n || a[n-1] == n) {\r\n\t\t\tans = a.reverse();\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst mx = Math.max(...a);\r\n\r\n\t\tlet ans;\r\n\t\tif (a[0] == mx) {\r\n\t\t\tans = a.reverse();\r\n\t\t} else if (a[n-1] == mx) {\r\n\t\t\tans = a.slice(0, n-1).reverse();\r\n\t\t\tans.push(a[n-1]);\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n if (n === 1) return arr\n const [first, last] = pickMax(n, arr)\n // console.log(print(n, first))\n // console.log(print(n, first.next))\n let mfirst = pickMin(n, first, last.prev)\n if (same(n, arr, mfirst)) return print(n, first)\n if (same(n, arr, mfirst.next)) return print(n, first)\n mfirst = pickMin(n, first.next, last)\n if (same(n, arr, mfirst)) return print(n, first.next)\n if (same(n, arr, mfirst.next)) return print(n, first.next)\n return -1\n}\nfunction print(n, first) {\n const ans = Array(n)\n for (let i = 0; i < n; i++) {\n ans[i] = first.x\n first = first.next\n }\n return ans.join(' ')\n}\nfunction same(n, arr, first) {\n let i = 0\n while (i < n) {\n if (arr[i] !== first.x) return false\n i++\n first = first.next\n }\n // for (let i = 0; i < a.length; i++) {\n // if (a[i] !== b[i]) return false\n // }\n return true\n}\nfunction pickMin(n, pf, pl) {\n let item\n let first\n let last\n while (pf !== pl) {\n if (pf.x < pl.x) {\n item = { x: pf.x }\n pf = pf.next\n if (!first) {\n first = last = item\n } else {\n item.next = first\n first = item\n }\n // p.unshift(arr[i++])\n } else {\n item = { x: pl.x }\n pl = pl.prev\n if (!first) {\n first = last = item\n } else {\n last.next = item\n last = item\n }\n // p.push(arr[j--])\n }\n }\n item = { x: pf.x }\n if (n === 1) {\n return item\n }\n item.next = first\n first = item\n\n item = { x: pf.x }\n last.next = item\n return first\n // return [p.concat([arr[i]]), [arr[i]].concat(p)]\n}\nfunction pickMax(n, arr) {\n // const p = []\n let i = 0\n let j = n - 1\n let first\n let last\n let item\n while (i < j) {\n if (arr[i] > arr[j]) {\n item = { x: arr[i++] }\n if (!first) {\n first = last = item\n } else {\n item.next = first\n first.prev = item\n first = item\n }\n // p.unshift(arr[i++])\n } else {\n item = { x: arr[j--] }\n if (!first) {\n first = last = item\n } else {\n last.next = item\n item.prev = last\n last = item\n }\n // p.push(arr[j--])\n }\n }\n item = { x: arr[i] }\n if (n === 1) {\n first = last = item\n return [first, last]\n }\n item.next = first\n first.prev = item\n first = item\n\n item = { x: arr[i] }\n last.next = item\n item.prev = last\n last = item\n return [first, last]\n}\n"}], "negative_code": [{"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n \r\n if (n==200000 && aString[0] == '1')\r\n console.log(\"yes\");\r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {\r\n return -1;\r\n }\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {\r\n return -1;\r\n }\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n console.log(aString[aString.length-1] == '\\r');\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {\r\n return -1;\r\n }\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n console.log(aString[aString.length-1] == '\\r');\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n console.log(aString[aString.length-1] == '\\r\\n');\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n console.log(aString[aString.length-1] );\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n if(aString[aString.length-1] == ' ')\r\n console.log(\"yes\");\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n\r\n if(aString[aString.length-1] == '\\n')\r\n console.log(\"yes\");\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n let perm = reverse(aString);\r\n return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\" \").reverse().join(\" \");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n console.log(typeof(aString));\r\n \r\n if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)\r\n return -1;\r\n \r\n // let perm = aString.reverse();\r\n // return perm;\r\n }\r\n\r\n function reverse(s){\r\n return s.split(\"\").reverse().join(\"\");\r\n }"}, {"source_code": " \"use strict\";\r\n process.stdin.resume();\r\n process.stdin.setEncoding(\"utf-8\");\r\n \r\n function print(x) {\r\n console.log(x);\r\n }\r\n let inputString = \"\";\r\n let currentLine = 0;\r\n \r\n process.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n });\r\n process.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n });\r\n function readline() {\r\n return inputString[currentLine++];\r\n }\r\n \r\n // ********** Code Start ********** \r\n function main() {\r\n // your code goes here\r\n let t = parseInt(readline());\r\n while (t--)\r\n console.log(solution()); \r\n }\r\n \r\n function solution() {\r\n let n = parseInt(readline());\r\n \r\n let aString = readline();\r\n \r\n if (+(aString[0]) == n || +(aString[aString.length-2]) == n)\r\n console.log(\"it works\");\r\n \r\n // let perm = aString.reverse();\r\n // return perm;\r\n }"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst mx = Math.max(...a);\r\n\r\n\t\tlet ans;\r\n\t\tif (a[0] == mx) {\r\n\t\t\tans = a.reverse();\r\n\t\t} else if (a[n-1] == mx) {\r\n\t\t\tans = a;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tif (a.length > 2 \r\n\t\t\t&& a[0] < Math.max(a[1], a[n-1]) \r\n\t\t\t&& a[n-1] < Math.max(a[0], a[n-2])) {\r\n\t\t\tconsole.log(-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tm = n >> 1;\r\n\t\tans = [...a.slice(0, m).reverse(), ...a.slice(m).reverse()], \r\n\r\n\t\tconsole.log(ans.join(' '));\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const [p1, p2] = pickMax(n, arr)\n const [p3, p4] = pickMin(n, p1)\n if (same(arr, p3)) return p3.join(' ')\n if (same(arr, p4)) return p4.join(' ')\n const [p5, p6] = pickMin(n, p2)\n if (same(arr, p5)) return p5.join(' ')\n if (same(arr, p6)) return p6.join(' ')\n return -1\n}\nfunction same(a, b) {\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false\n }\n return true\n}\nfunction pickMin(n, arr) {\n const p = []\n let i = 0\n let j = n - 1\n while (i < j) {\n if (arr[i] < arr[j]) {\n p.unshift(arr[i++])\n } else {\n p.push(arr[j--])\n }\n }\n return [p.concat([arr[i]]), [arr[i]].concat(p)]\n}\nfunction pickMax(n, arr) {\n const p = []\n let i = 0\n let j = n - 1\n while (i < j) {\n if (arr[i] > arr[j]) {\n p.unshift(arr[i++])\n } else {\n p.push(arr[j--])\n }\n }\n return [p.concat([arr[i]]), [arr[i]].concat(p)]\n}\n"}], "src_uid": "69bbc06c385d51f78ce1f64afffb4cf1"} {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var one = nextIntArray();\n var n = one[0];\n var x = one[1];\n var m = one[2];\n var min = x;\n var max = x;\n for(var j = 0; j < m; j++){\n var tmp = nextIntArray();\n var L = tmp[0];\n var R = tmp[1];\n if(L <= min && min <= R){\n min = L;\n }\n if(L <= max && max <= R){\n max = R;\n }\n }\n output[i] = max - min + 1;\n \n }\n myout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n B();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction B(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,x,m] = ti(readline().split(' '));\n let a = new Array(m);\n for(let i = 0; i < m; i++){\n a[i] = ti(readline().split(' '));\n }\n\n let min = x;\n let max = x;\n for(let i = 0; i < m; i++){\n if((a[i][0] >= min && a[i][0] <= max) || (a[i][1] >= min && a[i][1] <= max) || (a[i][0] < min && a[i][1] > max)){\n min = Math.min(min, a[i][0]);\n max = Math.max(max, a[i][1]);\n }\n }\n\n if(min - max > n)\n console.log(0);\n else\n console.log(max-min+1);\n }\n}"}, {"source_code": "// var lineIdx = 0;\n// var readline = () => {\n// var input = [\"3\", \"6 4 3\", \"1 6\", \"2 3\", \"5 5\", \"4 2 2\", \"2 4\", \"1 2\", \"3 3 2\", \"2 3\", \"1 2\"]\n// return input[lineIdx++];\n// };\n// var print = (str) => {\n// console.log(str);\n// };\n\nvar t = readline().split(\" \").map(function(x) { return parseInt(x); })[0];\n\nvar intersect = (a, b) => {\n if(b.left <= a.right && a.left <= b.right){\n return true;\n }\n return false;\n}\n\nvar merge = (a, b) => {\n return {left: Math.min(a.left, b.left), right: Math.max(a.right, b.right)}\n}\n\nvar step = () => {\n var input = readline().split(\" \").map(function(x) { return parseInt(x); });\n var n = input[0];\n var x = input[1];\n var m = input[2];\n\n var first = {left: x, right: x};\n\n for(var i = 0; i {\n arr.push(line);\n});\nrl.on(\"close\", () => {\n caseOfTheZerosAndOnes(arr[1]);\n});\n"}, {"source_code": "\nlet _inputLines;\nlet _lineNumber = 0;\nlet inputReader = _inputReader ();\n\nfunction _main() {\n\t\n\t_inputLines = _inputData.trim().split('\\n').map((string) => {\n\t\treturn string.trim();\n\t});;\n\t\n\tlet n = inputReader.readNumber();\n\tvar x = 0;\n\t\n\tvar str = inputReader.readLine();\n\t\n\tfor (var i = 0; i < n; i++) {\n\t if (str[i] == \"1\") x++;\n\t else x--;\n\t}\n\t\n\tconsole.log(Math.abs(x));\n\n}\n\nvar _inputData = '';\nfunction cacheInput(data) {\n\t_inputData += data;\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', cacheInput).on('end', _main);\n\nfunction _inputReader () {\n\tfunction readNumber(){\n\t\treturn Number(_inputLines[_lineNumber++]);\n\t}\n\t\t\n\tfunction readLine(){\n\t\treturn _inputLines[_lineNumber++];\n\t}\n\t\t\n\t\n\treturn {\n\t\treadNumber,\n\t\treadLine,\n\t}\n}"}, {"source_code": "var s = readline();\nvar s = readline();\nvar ans = 0;\nfor(var i = 0; i < s.length; ++i)\n if(s[i] == '1')\n ans++;\n else\n ans--;\nprint(Math.abs(ans));"}, {"source_code": "let i = ''\n\nprocess.stdin.on('data',c => {\n i += c\n})\n\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n\n\n let stringLength = parseInt(lines[0])\n let inputStringArray = lines[1].split(\"\")\n\n let zerosCount = 0\n\n for(i = 0; i < inputStringArray.length; i++) {\n if (inputStringArray[i] === \"0\") {\n zerosCount ++\n }\n }\n\n let onesCount = stringLength - zerosCount\n let minimumStringLength = Math.abs(onesCount - zerosCount)\n console.log(minimumStringLength)\n})"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\tif(output[+input[i]] == undefined){\n\t\t\toutput[+input[i]] = 1;\n\t\t}\n\t\telse{\n\t\t\toutput[+input[i]]++;\n\t\t}\n\t}\n}\n\nvar n = +readline(), str = readline().split(\"\").map(Number), unique = {};\n\ncountUniqueElements(str, unique);\n\nif(unique[0] == undefined){\n\tunique[0] = 0;\n}\nif(unique[1] == undefined){\n\tunique[1] = 0;\n}\n\nprint(Math.abs(unique[0] - unique[1]));"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\n\n\n// function run(s, n, initial) {\n// \t// print('s: ' + s);\n// \t// print('n: ' + n);\n// \t// print('initial: ' + initial);\n// \tfor (var i = initial; i < n - 1; i++) {\n// \t\tif (s[i] != s[i+1]) {\n// \t\t\ts.splice(i, 2);\n// \t\t\treturn run(s, n - 2, i == 0 ? 0 : i - 1);\n// \t\t}\n// \t}\n// \treturn s.length;\n// }\ns = s.split('');\n\nvar l = 0;\nvar r = 1;\nvar cnt = 0;\nvar last_l = -1;\n\nvar forbidden = {};\n\nfunction calcNewL() {\n\twhile(forbidden[l]) {\n\t\tl--;\n\t}\n}\n\n\nwhile (r < n) {\n\tif (s[l] != s[r]) {\n\t\t// print('+', l, r);\n\t\t// forbidden[l] = true;\n\t\t// forbidden[r] = true;\n\t\tr = r + 1;\n\t\tl = last_l;\n\t\tif (l < 0) {\n\t\t\tl = r;\n\t\t\tr++;\n\t\t}\n\t\tcnt++;\n\t} else {\n\t\t// print('-', l, r);\n\t\tlast_l = l;\n\t\tl = r;\n\t\tr = r + 1;\n\t}\n}\n\nprint(Math.abs(n - cnt * 2));"}, {"source_code": "var n = readline();\nvar s = readline();\n\nvar st = [];\n\nfor(var i=0;i cnt[e]++)\nprint(n - (Math.min(...cnt) << 1))"}, {"source_code": "function ProblemSolver() {\n this.HAS_TEST_CASES = false ;\n this.INPUT_FILE_NAME = \"sample.in\" ;\n this.OUTPUT_FILE_NAME = \"sample.out\" ;\n this.DO_OUTPUT_TO_FILE = false ;\n this.CLEAR_ARRAY_PER_CASE = false ;\n\n this.solveCase = function() {\n var res , i , j , fl , cn , a , b , c ;\n res = this.n ;\n cn = 0 ;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.s.charCodeAt( i ) - '0'.charCodeAt( 0 ) ;\n if( cn > 0 && this.brr[ cn - 1 ] + a == 1 ) {\n res -= 2 ;\n cn-- ;\n }\n else {\n this.brr[ cn++ ] = a ;\n }\n }\n print( res ) ;\n } ;\n\n this.init = function() {\n this.lim1 = 1000010 ;\n this.lim2 = 110 ;\n this.cc = 1 ;\n this.ind = 1 ;\n this.n = 0 ;\n this.cn = 0 ;\n this.declareAndFillArrays() ;\n } ;\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i ;\n hasMoreInput = true ;\n try {\n \tthis.n = irObj.nextInt() ;\n this.s = irObj.nextString() ;\n }\n catch( ex ) {\n hasMoreInput = false ;\n }\n return hasMoreInput ;\n } ;\n\n this.clearArraysPerCase = function() {\n var i ;\n this.arr = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n } ;\n\n this.clearPerCase = function() {\n this.cn = 0 ;\n this.cc++ ;\n if( this.CLEAR_ARRAY_PER_CASE == true ) {\n this.clearArraysPerCase() ;\n }\n } ;\n\n this.declareAndFillArrays = function() {\n var i , j ;\n this.srr = new Array() ;\n this.vis = new Array() ;\n this.arr = new Array() ;\n this.brr = new Array() ;\n this.memo = new Array() ;\n this.done = new Array() ;\n this.adjList = new Array() ;\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( '' ) ;\n this.vis.push( 0 ) ;\n this.arr.push( 0 ) ;\n this.brr.push( 0 ) ;\n this.adjList.push( new Array() ) ;\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() ) ;\n this.done.push( new Array() ) ;\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 ) ;\n this.done[ i ].push( 0 ) ;\n }\n }\n } ;\n\n this.init() ;\n}\n\nfunction InputReader() {\n var self = this ;\n this.allLines = new Array() ;\n this.currrentLineNumber = 0 ;\n this.currrentCharacterIndex = 0 ;\n this.callBackFunction = null ;\n this.parentContext = null ;\n\n this.readAllLines = function() {\n var singleLine ;\n while( true ) {\n try {\n singleLine = readline() ;\n if( singleLine == null ) {\n break ;\n }\n }\n catch( ex ) {\n break ;\n }\n this.allLines.push( singleLine ) ;\n }\n } ;\n \n this.readAllLinesFromRhino = function() {\n var brObj , line ;\n importPackage( java.io ) ;\n importPackage( java.lang ) ;\n brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;\n this.allLines = [] ;\n while( true ) {\n line = brObj.readLine() ;\n if( line == null ) {\n break;\n }\n this.allLines.push( line ) ;\n }\n } ;\n \n this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {\n self.chunkData += chunk ;\n } ;\n\n this.readEndFromNodeJsJudgeServer = function() {\n self.parseRawData( self.chunkData ) ;\n self.parentContext.runCases() ;\n } ;\n \n this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {\n this.parentContext = parentContext ;\n process.stdin.resume() ;\n process.stdin.setEncoding( 'utf8' ) ;\n this.chunkData = '' ;\n process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;\n process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;\n } ;\n\n this.parseRawData = function( data ) {\n var len , i , currentString ;\n len = data.length ;\n currentString = '' ;\n this.allLines = [] ;\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString ) ;\n currentString = '' ;\n }\n else {\n currentString += data[ i ] ;\n }\n }\n if( currentString != '' ) {\n this.allLines.push( currentString ) ;\n }\n } ;\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData ;\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n inputFilePath = currentDirectory + '\\\\' + inputFileName ;\n }\n else {\n //on linux\n inputFilePath = currentDirectory + '/' + inputFileName ;\n }\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" ) ;\n this.parseRawData( rawData ) ;\n } ;\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx ;\n if( flag == 0 ) {\n if( this.currrentCharacterIndex != 0 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n res = '' ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n return res ;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( 'No more tokens available!' ) ;\n }\n startIdx = -1 ;\n len = this.allLines[ this.currrentLineNumber ].length ;\n if( typeof( len ) == 'function' ) {\n len = this.allLines[ this.currrentLineNumber ].length() ;\n }\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {\n startIdx = i ;\n break ;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n continue ;\n }\n res = '' ;\n endIdx = len - 1 ;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {\n endIdx = i ;\n break ;\n }\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {\n res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;\n }\n else {\n res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;\n }\n }\n this.currrentCharacterIndex = endIdx ;\n if( endIdx == len - 1 ) {\n this.currrentLineNumber++ ;\n this.currrentCharacterIndex = 0 ;\n }\n return res ;\n }\n } ;\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) ) ;\n } ;\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) ) ;\n } ;\n\n this.nextString = function() {\n return this.next( 1 ) ;\n } ;\n\n this.nextLine = function() {\n return this.next( 0 ) ;\n } ;\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array() ;\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString ) ;\n } ;\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array() ;\n } ;\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath ;\n res = '' ;\n sz = this.resultantStringArray.length ;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += '\\n' ;\n }\n res += this.resultantStringArray[ i ] ;\n }\n fsObj = require( 'fs' ) ;\n currentDirectory = __dirname ;\n if( currentDirectory.indexOf( 'D:' ) != -1 ) {\n //on windows\n outputFilePath = currentDirectory + '\\\\' + outputFileName ;\n }\n else {\n //on linux\n outputFilePath = currentDirectory + '/' + outputFileName ;\n }\n fsObj.writeFileSync( outputFilePath , res ) ;\n this.clearPercase() ;\n } ;\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader() ;\n this.psObj = new ProblemSolver() ;\n this.fohObj = new FileOutputHandler() ;\n\n this.runCases = function() {\n\t\tvar testCases , hasMoreTestCases , i ;\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt() ;\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase() ;\n this.psObj.getInput( this.irObj ) ;\n this.psObj.solveCase() ;\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase() ;\n hasMoreTestCases = this.psObj.getInput( this.irObj ) ;\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase() ;\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;\n }\n } ;\n\n this.detectEnvironmentType = function() {\n var environmentType = null ;\n try {\n if( importPackage != null ) {\n environmentType = 'rhino' ;\n }\n }\n catch( ex1 ) {\n try {\n //for nodejs local server check\n if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {\n environmentType = 'local-node-js' ;\n }\n else {\n environmentType = 'server-node-js' ;\n }\n }\n catch( ex2 ) {\n try {\n if( readline == null || typeof( readline ) != 'function' ) {\n environmentType = 'server-node-js' ;\n }\n else {\n try {\n if( Map != null ) {\n environmentType = 'spider-monkey' ;\n }\n else {\n environmentType = 'javascript-v8' ;\n }\n }\n catch( ex3 ) {\n environmentType = 'javascript-v8' ;\n }\n }\n }\n catch( ex3 ) {\n environmentType = 'server-node-js' ;\n }\n }\n }\n return environmentType ;\n } ;\n\n this.configureStreamsAndReadInput = function() {\n var localContext , isNodeJsJudgeServer , environmentType ;\n isNodeJsJudgeServer = false ;\n environmentType = this.detectEnvironmentType() ;\n if( environmentType == 'local-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj ;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments ) ;\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;\n this.runCases() ;\n }\n else if( environmentType == 'server-node-js' ) {\n try {\n if( print == null || typeof( print ) != 'function' ) {\n print = console.log ;\n }\n }\n catch( ex ) {\n print = console.log ;\n }\n this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;\n }\n else if( environmentType == 'javascript-v8' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n else if( environmentType == 'rhino' ) {\n this.irObj.readAllLinesFromRhino() ;\n this.runCases() ;\n }\n else if( environmentType == 'spider-monkey' ) {\n this.irObj.readAllLines() ;\n this.runCases() ;\n }\n } ;\n \n this.configureStreamsAndReadInput() ;\n}\n\nnew CodeExecutioner() ;\n"}, {"source_code": "function toi(x){return parseInt(x);}\nfunction countX(c){\n return (function(a,b){\n\tif(b===c){\n\t return a+1;\n\t}else{\n\t return a;\n\t}\n });\n}\n \n(function(){\n var n=+readline();\n var s=readline().split(\"\");\n print(Math.abs(s.reduce(countX(\"1\"),0)-s.reduce(countX(\"0\"),0)));\n})();\n"}, {"source_code": "'use strict'\nreadline();\nString.prototype.getNumArray = function () {\n return String(this).split('').map(function (value) {\n return parseInt(value);\n });\n}\nlet str = readline().getNumArray(),\n stack = new Array(str.length),\n stackIndex = -1,\n counter = 0,\n mapper = {\n 0: 1,\n 1: 0\n };\n\nfor (let i = 0; i < str.length; i++) {\n if (stackIndex > -1 && stack[stackIndex] === mapper[str[i]]) {\n counter++;\n stackIndex--;\n } else {\n stackIndex++;\n stack[stackIndex] = str[i];\n }\n}\n\nwrite(str.length - 2 * counter);"}, {"source_code": "var n = Number(readline());\nvar s = readline();\nvar one = 0, zero = 0;\nfor (var i = 0; i < n; i++) {\n if (s[i] == '0') zero++;\n else one++;\n}\nprint(Math.abs(one - zero));\n"}, {"source_code": "\n// 556A \u0414\u0435\u043b\u043e \u043e \u043d\u0443\u043b\u044f\u0445 \u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \n\nvar n = parseInt(readline());\n\n//var input_line = readline().split(' ').map(Number);\nvar str = readline();\n\nvar count0 = 0;\nvar count1 = 0;\nvar i=0;\n\nfunction del01 (str) {\n var len = str.length;\n var strTmp = '';\n for (var i = 0; i < len; i++) {\n if (str[i] !== str[i+1]) {\n if (i == (len - 1)) strTmp += str[i];\n i ++;\n } else {\n strTmp += str[i]; \n };\n };\n if (strTmp.length == len) {\n return len;\n } else {\n return del01(strTmp);\n };\n}\n\nfor (i = 0; i < n; i++) {\n if (str[i] == '0') {\n count0 ++;\n } else {\n count1 ++;\n };\n}\n\n//print(del01(str) + '\\n');\nprint(Math.abs(count0 - count1) + '\\n');\n"}, {"source_code": "var n = readline();\n\nvar str = readline().split('');\n\nvar intarray = [0,0];\n\nfor(i=0;i+v).reduce((a, v)=> a += v, 0);\n var c0 = n - c1;\n wr(n - Math.min(c0, c1)*2);\n \n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}, {"source_code": "readline()\ns=readline()\na=[]\nfor (var i=0; i {\n if(Number(cur) === 0) z++;\n if(Number(cur) === 1) o++;\n});\n\nprint(Math.abs(z-o));\n"}, {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nfunction main() {\n var inp = getInput()[1];\n if (!inp) {\n print(0);\n return;\n }\n var nc = 0;\n var oc = 0;\n \n for (var i = 0, k = inp.length; i < k; i++) {\n if (inp[i] === '0') {\n nc++;\n } else {\n oc++;\n }\n }\n \n print(Math.abs(nc - oc));\n}\n\nmain();\n\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n let ans = d.length;\n let zeros = 0;\n let ones = 0;\n\n for (let i = 0; i < d.length; i++) {\n if (d[i] === '1') {\n ones++;\n }\n else {\n zeros++;\n }\n }\n\n ans -= Math.min(zeros, ones) * 2;\n\n console.log(ans);\n\n c++;\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const line = input[1];\n\n let answ = line.length;\n let cntOne = 0;\n\n for (let i = 0; i < line.length; i += 1) {\n if (line[i] === '1') cntOne += 1;\n }\n\n let zero = line.length - cntOne;\n console.log(\n answ - Math.min(zero, cntOne)*2\n );\n}); "}], "negative_code": [{"source_code": "var s = readline();\nvar ans = 0;\nfor(var i = 0; i < s.length; ++i)\n if(s[i] == '1')\n ans++;\n else\n ans--;\nprint(Math.abs(ans));\n\n"}, {"source_code": "var n = parseInt(readline());\nvar s = readline();\n\n\n// function run(s, n, initial) {\n// \t// print('s: ' + s);\n// \t// print('n: ' + n);\n// \t// print('initial: ' + initial);\n// \tfor (var i = initial; i < n - 1; i++) {\n// \t\tif (s[i] != s[i+1]) {\n// \t\t\ts.splice(i, 2);\n// \t\t\treturn run(s, n - 2, i == 0 ? 0 : i - 1);\n// \t\t}\n// \t}\n// \treturn s.length;\n// }\ns = s.split('');\n\nvar l = 0;\nvar r = 1;\nvar cnt = 0;\nvar last_l = -1;\n\nvar forbidden = {};\n\nfunction calcNewL() {\n\twhile(forbidden[l]) {\n\t\tl--;\n\t}\n}\n\n\nwhile (r < n) {\n\tif (s[l] != s[r]) {\n\t\t// print('+', l, r);\n\t\t// forbidden[l] = true;\n\t\t// forbidden[r] = true;\n\t\tr = r + 1;\n\t\tl = last_l;\n\t\tif (l < 0) {\n\t\t\tl = r;\n\t\t\tr++;\n\t\t}\n\t\tcnt++;\n\t} else {\n\t\t// print('-', l, r);\n\t\tlast_l = l;\n\t\tl = r;\n\t\tr = r + 1;\n\t}\n}\n\nprint(n - cnt * 2);"}, {"source_code": "var n = readline();\nvar o =0; var z = 0;\nvar str = readline();\n\tfor (var i=0; i<+n; i++){\n\t\t\tstr[i]=='1'? o++:z++;\n\t}\n\t\n\tprint(o-z);"}, {"source_code": "var n = readline();\nvar reg = /(10)|(01)/;\nvar str = readline();\nif (+n<200000){\n\tfor (var i=0; i<+n; i++){\n\t\t\tstr = str.replace(reg, \"\")\n\t}\n}\nprint(str.length);"}, {"source_code": "var n = readline();\nvar o =0; var z = 0;\nvar str = readline();\n\tfor (var i=0; i<+n; i++){\n\t\t\tstr[i]=='1'? o++:z++;\n\t}\n\t\n\tprint(z-o);"}, {"source_code": "var n = readline();\nvar reg = /(10)|(01)/;\nvar str = readline();\nif (+n<200000){\n\tfor (var i=0; i<+n; i++){\n\t\t\tstr = str.replace(reg, \"\")\n\t}\n\tprint(str.length);\n}\nelse print(0);"}, {"source_code": "var n = Number(readline());\nvar inp = readline().split('');\n\nfor(var i = 0; i < inp.length; i++){\n if(inp[i+1]){\n if(inp[i] !== inp [i+1]) {\n inp.splice(i,2);\n i = i - 2\n } \n }\n}\n\nprint(inp.length);"}, {"source_code": "var n = Number(readline());\nvar inp = readline().split('');\n\nfor(var i = 0; i < inp.length; i++){\n if(inp[i+1]){\n if(inp[i] !== inp [i+1]) {\n inp.splice(i,2);\n if(i > 2)\n i = i - 2;\n else\n i = 0;\n } \n }\n}\n\nprint(inp.length);"}, {"source_code": "var n = Number(readline());\nvar inp = readline().split('');\nvar num= 1;\n\nwhile(num !== 0){\n num = 0;\nfor(var i = 0; i < inp.length; i++){\n if(inp[i+1]){\n if(inp[i] !== inp [i+1]) {\n inp.splice(i,2);\n num++; \n } \n }\n}\nprint(num);\n}\n\nprint(inp.length);\n"}, {"source_code": "function caseOfTheZerosAndOnes(str) {\n let checker = true;\n while (checker) {\n if (str.length == 0) {\n console.log(str.length);\n break;\n }\n if (str.indexOf(\"01\") > -1) {\n str = str.replace(\"01\", \"\");\n continue;\n }\n\n if (str.indexOf(\"10\") > -1) {\n str = str.replace(\"10\", \"\");\n continue;\n }\n\n checker = false;\n }\n console.log(str.length);\n}\n\nconst readline = require(\"readline\");\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nlet arr = [];\nrl.on(\"line\", (line) => {\n arr.push(line);\n});\nrl.on(\"close\", () => {\n caseOfTheZerosAndOnes(arr[1]);\n});\n"}, {"source_code": "function countUniqueElements(input,output){\n\tfor(var i = 0; i < input.length; i++){\n\t\tif(output[+input[i]] == undefined){\n\t\t\toutput[+input[i]] = 1;\n\t\t}\n\t\telse{\n\t\t\toutput[+input[i]]++;\n\t\t}\n\t}\n}\n\nvar n = +readline(), str = readline().split(\"\").map(Number), unique = {};\n\ncountUniqueElements(str, unique);\n\nprint(Math.abs(unique[1] - unique[0]));"}, {"source_code": "var numberOfChar = Number(readline())\nvar str = readline()\n\nvar stack = []\nfor (var i = 0; i < numberOfChar; i++) {\n var curr = str[i]\n\n if (curr === '0') {\n var peek = stack[stack.length - 1] || -1\n\n if (peek === '1') {\n stack.pop()\n } else {\n stack.push(curr)\n }\n } else {\n stack.push(curr)\n }\n}\n\nprint(stack.length)"}], "src_uid": "fa7a44fd24fa0a8910cb7cc0aa4f2155"} {"source_code": ";(function () {\n\treadline();\n\tprint(Math.max.apply(null, readline().split(' ').map(Number)));\n}.call(this));\n", "positive_code": [{"source_code": "readline();\nvar line1 = readline().split(\" \");\nprint(Math.max(...line1));"}, {"source_code": "var n = +readline(), h = [0].concat(readline().split(\" \").map(Number));\nvar cnt = 0, e = 0;\n\nfor(i = 0; i < n; i++){\n\te += h[i] - h[i+1];\n\tif(e < 0){\n\t\tcnt += Math.abs(e);\n\t\te = 0;\n\t}\n}\n\nwrite(cnt);"}, {"source_code": "function getDineroPagar(pilares){\n var maximoRelativoAnterior= pilares[0];\n var maximoRelativoNuevo= 0;\n var energia= 0;\n var dineroCancelar= maximoRelativoAnterior; \n for (var i = 0; i+3 <= pilares.length; i++){\n maximoRelativoNuevo= Math.max(pilares[i], Math.max(pilares[i+1], pilares[i+2])); \n if(maximoRelativoNuevo== pilares[i+1] && maximoRelativoNuevo>= pilares[i] && maximoRelativoNuevo>= pilares[i+2]){\n energia+= maximoRelativoAnterior- maximoRelativoNuevo;\n if(energia< 0){\n dineroCancelar+= -energia;\n energia= 0;\n }\n maximoRelativoAnterior= maximoRelativoNuevo;\n }\n }\n\n energia+= maximoRelativoAnterior- pilares[pilares.length-1 ];\n if(energia< 0)\n dineroCancelar+= -energia;\n\n return dineroCancelar;\n}\n\nvar n= readline();\nvar pilares=readline().split(' ');\npilares.forEach(function (value, index, obj) {\n obj[index]= parseInt(value);\n});\nprint(getDineroPagar(pilares));\n"}], "negative_code": [{"source_code": "function getDineroPagar(pilares){\n var maximoRelativoAnterior= pilares[0];\n var maximoRelativoNuevo= 0;\n var energia= 0;\n var dineroCancelar= maximoRelativoAnterior; \n for (var i = 0; i+3 <= pilares.length; i++){\n maximoRelativoNuevo= Math.max(pilares[i], Math.max(pilares[i+1], pilares[i+2])); \n if(maximoRelativoNuevo== pilares[i+1] && maximoRelativoNuevo>= pilares[i] && maximoRelativoNuevo>= pilares[i+2]){\n energia+= maximoRelativoAnterior- maximoRelativoNuevo;\n if(energia< 0){\n dineroCancelar+= -energia;\n energia= 0;\n }\n maximoRelativoAnterior= maximoRelativoNuevo;\n }\n }\n\n energia+= maximoRelativoAnterior- pilares[pilares.length-1 ];\n if(energia< 0)\n dineroCancelar+= -energia;\n\n return dineroCancelar;\n}\n\nvar n= readline();\nn= parseInt(n);\nvar pilares=readline().split(' ');\nprint(getDineroPagar(pilares));\n"}, {"source_code": "var line1 = readline().split(\" \");\nprint(Math.max(...line1));"}, {"source_code": ";(function () {\n\tvar n = +readline(),\n\t\th = readline().split(' ').map(Number),\n\t\tk = 0;\n\n\t(function () {\n\t\tvar t = [0].concat(h);\n\t\tfor (var i = 1, _i = t.length; i < _i; i++) {\n\t\t\tk += t[i - 1] - t[i];\n\t\t}\t\t\n\t})();\n\n\tprint(Math.abs(k));\n}.call(this));\n"}], "src_uid": "d03ad531630cbecc43f8da53b02d842e"} {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var res = '';\n var t = read.number();\n for(var j = 0; j < t; j++) {\n var n = read.number();\n var d = read.arrNumber(' ').sort((a,b)=> b - a);\n\n var x = d[0] * d[n - 1];\n\n var check = true;\n\n for(var i = 1; i < Math.ceil(n/2); i++) {\n if(d[i] * d[n - 1 - i] !== x) {\n check = false;\n break;\n }\n }\n\n if(check) {\n var del = [];\n for(var i = d[0]; i >=2 ; i--) {\n if(x % i === 0) {\n del.push(i);\n }\n }\n \n if(del.length != n) {\n check = false;\n }\n else {\n for(var i = 0; i < n;i++) {\n if(d[i] != del[i]) {\n check = false;\n break;\n }\n }\n }\n }\n\n if(check) {\n res += x + '\\n';\n }\n else {\n res += '-1\\n';\n }\n }\n print(res);\n}());", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var res = '';\n var t = read.number();\n for(var j = 0; j < t; j++) {\n var n = read.number();\n var d = read.arrNumber(' ').sort((a,b)=> b - a);\n\n var x = d[0] * d[n - 1];\n\n var check = true;\n\n for(var i = 1; i < Math.ceil(n/2); i++) {\n if(d[i] * d[n - 1 - i] !== x) {\n check = false;\n break;\n }\n }\n\n if(check) {\n var del = [];\n for(var i = d[0]; i >=2 ; i--) {\n if(x % i === 0) {\n del.push(i);\n }\n }\n \n if(del.length != n) {\n check = false;\n }\n else {\n for(var i = 0; i < n;i++) {\n if(d[i] != del[i]) {\n check = false;\n break;\n }\n }\n }\n }\n\n if(check) {\n res += x + '\\n';\n }\n else {\n res += '-1\\n';\n }\n }\n print(res);\n}());"}, {"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var res = '';\n var t = read.number();\n for(var j = 0; j < t; j++) {\n var n = read.number();\n var d = read.arrNumber(' ').sort((a,b)=> b - a);\n\n var x = d[0] * d[n - 1];\n\n var check = true;\n\n\n if(check) {\n var del = [];\n for(var i = d[0]; i >=2 ; i--) {\n if(x % i === 0) {\n del.push(i);\n }\n }\n \n if(del.length != n) {\n check = false;\n }\n else {\n for(var i = 0; i < n;i++) {\n if(d[i] != del[i]) {\n check = false;\n break;\n }\n }\n }\n }\n\n if(check) {\n res += x + '\\n';\n }\n else {\n res += '-1\\n';\n }\n }\n print(res);\n}());"}], "negative_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n }\n\n var res = '';\n var t = read.number();\n for(var j = 0; j < t; j++) {\n var n = read.number();\n var d = read.arrNumber(' ');\n \n var max = d[0];\n for(var i = 1;i < n; i++) {\n if(d[i] > max) {\n max = d[i];\n }\n }\n \n var x = max * 2;\n \n var check = true;\n for(var i = 0; i < n; i++) {\n if(x % d[i]) {\n check = false;\n break;\n }\n }\n \n if(check) {\n res += x + '\\n';\n }\n else {\n res += '-1\\n';\n }\n }\n print(res);\n}());"}], "src_uid": "fe9b1527571ea37f402512ac378dee13"} {"source_code": "// 07/02/22 night\r\n\r\nconst pr = console.log;\r\n\r\n\r\nconst preSum = (a) => { let pre = [0]; for (let i = 0; i < a.length; i++) { pre.push(pre[i] + a[i]); } return pre; };\r\nconst subArraySum = (a, l, r) => a[r + 1] - a[l];\r\n\r\nconst main = () => {\r\n const readLine = () => input[currentLine++];\r\n const ni = () => readLine() - '0';\r\n const nas = () => readLine().split(\" \");\r\n const nai = () => nas().map(Number);\r\n const nall = () => nas().map(BigInt);\r\n let input = '', currentLine = 0;\r\n process.stdin.on('data', (stdin) => input += stdin)\r\n process.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let [n, q] = nai(), a = nai();\r\n a.sort((x, y) => y - x);\r\n let pre = preSum(a);\r\n // pr(n, q, a)\r\n for (let i = 0; i < q; i++) {\r\n let [x, y] = nai();\r\n let r = x - 1, l = Math.max(0, x - y);\r\n // pr(l, r, a.slice(l, r + 1), a.slice(0, x), pre)\r\n let sum = subArraySum(pre, l, r);\r\n pr(sum);\r\n }\r\n });\r\n};\r\n\r\nmain();", "positive_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nclass INPUT {\r\n constructor() {\r\n this.inputString = ''\r\n this.curLine = 0\r\n }\r\n \r\n appendline(str) {\r\n this.inputString += str;\r\n }\r\n \r\n prepare() {\r\n this.inputString = this.inputString.split('\\n').map(str => str.trim());\r\n }\r\n \r\n readline() {\r\n return this.inputString[this.curLine++];\r\n }\r\n \r\n readInts() {\r\n return this.readline().split(' ').map(x => parseInt(x, 10))\r\n }\r\n}\r\n\r\nconst input = new INPUT()\r\n\r\nprocess.stdin.on('data', str => {\r\n input.appendline(str)\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n input.prepare()\r\n main()\r\n});\r\n\r\nfunction main() {\r\n const [n, q] = input.readInts()\r\n const a = input.readInts().sort((x, y) => x - y)\r\n \r\n for (let i = 1; i < a.length; i += 1) {\r\n a[i] += a[i - 1]\r\n }\r\n\r\n for (let i = 0; i < q; i += 1) {\r\n const [x, y] = input.readInts()\r\n const l = n - x\r\n const r = n - x + y - 1\r\n console.log(a[r] - (l > 0 ? a[l - 1] : 0))\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n a.sort((a, b) => a - b);\r\n const sum = [];\r\n for (let i = 0; i < n; i++) {\r\n var _sum;\r\n sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];\r\n }\r\n const res = [];\r\n for (let [i, [x, y]] of b.entries()) {\r\n if (x > n) res[i] = 0;else {\r\n var _sum$l;\r\n let l = n - x - 1,\r\n r = l + y;\r\n res[i] = sum[r] - ((_sum$l = sum[l]) !== null && _sum$l !== void 0 ? _sum$l : 0);\r\n }\r\n }\r\n return res.join('\\n');\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = 1;\r\n while (t--) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(await solve(n, m, a, b));\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n console.log(output);\r\n});\r\n"}, {"source_code": "// 5 3\r\n// 5 3 1 5 2\r\n// 3 2\r\n// 1 1\r\n// 5 3\r\n\r\nvar n = readline().split(\" \");\r\nvar arr = readline()\r\n\t.split(\" \")\r\n\t.map(function (item) {\r\n\t\treturn +item;\r\n\t})\r\n\t.sort(function (a, b) {\r\n\t\treturn a - b;\r\n\t})\r\n\t.reverse()\r\n\t.reduce(\r\n\t\tfunction (curent, value) {\r\n\t\t\tcurent.push(curent[curent.length - 1] + value);\r\n\t\t\treturn curent;\r\n\t\t},\r\n\t\t[0]\r\n\t);\r\nvar t = parseInt(n[1]);\r\nwhile (t--) {\r\n\tvar q = readline().split(\" \");\r\n\tvar x = parseInt(q[0]);\r\n\tvar y = parseInt(q[1]);\r\n\twrite(arr[x] - arr[x - y]);\r\n\tprint();\r\n}\r\n"}, {"source_code": "// 07/02/22 night\r\n\r\nconst pr = console.log;\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nconst preSum = (a) => { let pre = [0]; for (let i = 0; i < a.length; i++) { pre.push(pre[i] + a[i]); } return pre; };\r\nconst subArraySum = (a, l, r) => a[r + 1] - a[l];\r\n\r\nconst readLine = () => input[currentLine++];\r\nconst ni = () => readLine() - '0';\r\nconst nas = () => readLine().split(\" \");\r\nconst nai = () => nas().map(Number);\r\nconst nall = () => nas().map(BigInt);\r\nlet input = '', currentLine = 0;\r\nprocess.stdin.on('data', (stdin) => input += stdin)\r\nprocess.stdin.on('end', () => {\r\n input = input.split('\\n');\r\n let [n, q] = nai(), a = nai();\r\n a.sort((x, y) => y - x);\r\n let pre = preSum(a);\r\n // pr(n, q, a)\r\n for (let i = 0; i < q; i++) {\r\n let [x, y] = nai();\r\n let r = x - 1, l = Math.max(0, x - y);\r\n // pr(l, r, a.slice(l, r + 1), a.slice(0, x), pre)\r\n let sum = subArraySum(pre, l, r);\r\n pr(sum);\r\n }\r\n});"}, {"source_code": "// 07/02/22 night\r\n\r\nconst pr = console.log;\r\n\r\nconst preSum = (a) => { let pre = [0]; for (let i = 0; i < a.length; i++) { pre.push(pre[i] + a[i]); } return pre; };\r\nconst subArraySum = (a, l, r) => a[r + 1] - a[l];\r\n\r\nconst solve = (n, q, a, query) => {\r\n a.sort((x, y) => y - x);\r\n let pre = preSum(a);\r\n for (const [x, y] of query) {\r\n let r = x - 1, l = Math.max(0, x - y);\r\n let sum = subArraySum(pre, l, r);\r\n pr(sum);\r\n }\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n solve(input[0][0], input[0][1], input[1], input.slice(2));\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n // let t = parseInt(readLine());\r\n // while (t-- > 0) {\r\n // console.log(solve());\r\n // }\r\n solve();\r\n}\r\nfunction solve() {\r\n let [n, q] = readLine().split(\" \").map(i => i - 0);\r\n let arr = readLine().split(\" \").map(i => i - 0).sort((a, b) => a - b);\r\n let prefixsum = [0];\r\n for (let i = 0; i < arr.length; i++) {\r\n prefixsum[i + 1] = prefixsum[i] + arr[i];\r\n }\r\n while (q-- > 0) {\r\n let [x, y] = readLine().split(\" \").map(i => i - 0);\r\n let l = n - x;\r\n let r = l + y\r\n console.log(prefixsum[r] - prefixsum[l]);\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\n\r\nclass INPUT {\r\n\tconstructor() {\r\n\t\tthis.input = [];\r\n\t\tthis.curLine = 0;\r\n\t}\r\n \r\n\tappend(chunk) {\r\n\t\tthis.input.push(chunk);\r\n\t}\r\n \r\n\tprepare() {\r\n\t this.input = Buffer.concat(this.input).toString()\r\n\t\tthis.input = this.input.split('\\n').map((str) => str.trim());\r\n\t}\r\n \r\n\treadline() {\r\n\t\treturn this.input[this.curLine++];\r\n\t}\r\n \r\n\treadInts() {\r\n\t\treturn this.readline()\r\n\t\t\t.split(' ')\r\n\t\t\t.map((x) => parseInt(x, 10));\r\n\t}\r\n}\r\n\r\nconst input = new INPUT()\r\n\r\nprocess.stdin.on('data', chunk => {\r\n input.append(chunk)\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n input.prepare()\r\n main()\r\n});\r\n\r\nfunction main() {\r\n const [n, q] = input.readInts()\r\n const a = input.readInts().sort((x, y) => x - y)\r\n \r\n for (let i = 1; i < a.length; i += 1) {\r\n a[i] += a[i - 1]\r\n }\r\n\r\n for (let i = 0; i < q; i += 1) {\r\n const [x, y] = input.readInts()\r\n const l = n - x\r\n const r = n - x + y - 1\r\n process.stdout.write(a[r] - (l > 0 ? a[l - 1] : 0) + \"\\n\")\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nclass INPUT {\r\n constructor() {\r\n this.inputString = ''\r\n this.curLine = 0\r\n }\r\n \r\n appendline(str) {\r\n this.inputString += str;\r\n }\r\n \r\n prepare() {\r\n this.inputString = this.inputString.split('\\n').map(str => str.trim());\r\n }\r\n \r\n readline() {\r\n return this.inputString[this.curLine++];\r\n }\r\n \r\n readInts() {\r\n return this.readline().split(' ').map(x => parseInt(x, 10))\r\n }\r\n}\r\n\r\nconst input = new INPUT()\r\n\r\nprocess.stdin.on('data', str => {\r\n input.appendline(str)\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n input.prepare()\r\n main()\r\n});\r\n\r\nfunction main() {\r\n const [n, q] = input.readInts()\r\n const a = input.readInts().sort((x, y) => x - y)\r\n \r\n for (let i = 1; i < a.length; i += 1) {\r\n a[i] += a[i - 1]\r\n }\r\n\r\n for (let i = 0; i < q; i += 1) {\r\n const [x, y] = input.readInts()\r\n const l = n - x\r\n const r = n - x + y - 1\r\n process.stdout.write(a[r] - (l > 0 ? a[l - 1] : 0) + \"\\n\")\r\n }\r\n}"}], "negative_code": [{"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\nfunction readLine() {\r\n return inputString[currentLine++];\r\n};\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n main();\r\n // cmd(not powershell): node cp.js < input.txt\r\n});\r\n\r\nfunction main() {\r\n // let t = parseInt(readLine());\r\n // while (t-- > 0) {\r\n solve();\r\n // }\r\n}\r\nfunction solve() {\r\n let [n, q] = readLine().split(\" \").map(i => parseInt(i));\r\n let arr = readLine().split(\" \").map(i => parseInt(i)).sort((a, b) => a - b);\r\n while (q-- > 0) {\r\n const [x, y] = readLine().split(\" \").map(i => parseInt(i));\r\n let res = 0;\r\n for (let i = arr.length - x; i <= arr.length - y; i++) {\r\n res += arr[i];\r\n }\r\n console.log(res)\r\n }\r\n\r\n}\r\n"}, {"source_code": "// 5 3\r\n// 5 3 1 5 2\r\n// 3 2\r\n// 1 1\r\n// 5 3\r\n\r\nvar n = readline().split(\" \");\r\nvar arr = readline()\r\n\t.split(\" \")\r\n\t.map(function (item) {\r\n\t\treturn +item;\r\n\t})\r\n\t.sort(function (a, b) {\r\n\t\treturn a - b;\r\n\t})\r\n\t.reverse()\r\n\t.reduce(\r\n\t\tfunction (curent, value) {\r\n\t\t\tcurent.push(curent[curent.length - 1] + value);\r\n\t\t\treturn curent;\r\n\t\t},\r\n\t\t[0]\r\n\t);\r\nvar t = parseInt(n[1]);\r\nwhile (t--) {\r\n\tvar q = readline().split(\" \");\r\n\tvar x = parseInt(q[0]);\r\n\tvar y = parseInt(q[1]);\r\n\twrite(arr[x] - arr[y - 1]);\r\n\tprint();\r\n}\r\n"}, {"source_code": "// 5 3\r\n// 5 3 1 5 2\r\n// 3 2\r\n// 1 1\r\n// 5 3\r\n\r\nvar n = readline().split(\" \");\r\nvar arr = readline()\r\n\t.split(\" \")\r\n\t.map(function (item) {\r\n\t\treturn +item;\r\n\t})\r\n\t.sort(function (a, b) {\r\n\t\treturn a - b;\r\n\t})\r\n\t.reverse()\r\n\t.reduce(\r\n\t\tfunction (curent, value) {\r\n\t\t\tcurent.push(curent[curent.length - 1] + value);\r\n\t\t\treturn curent;\r\n\t\t},\r\n\t\t[0]\r\n\t);\r\nvar t = parseInt(n[1]);\r\nprint(\"arr: \", arr);\r\nwhile (t--) {\r\n\tvar q = readline().split(\" \");\r\n\tvar x = parseInt(q[0]);\r\n\tvar y = parseInt(q[1]);\r\n\twrite(arr[x] - arr[y - 1]);\r\n\tprint();\r\n}\r\n"}], "src_uid": "2dc69231824db013161e4f223e25ccb9"} {"source_code": "const readline = require('readline')\n\nconst TreeMultiSet = (function () {\nvar{TreeMultiSet:t}=function(t){\n/*! *****************************************************************************\n Copyright (c) Microsoft Corporation.\n\n Permission to use, copy, modify, and/or distribute this software for any\n purpose with or without fee is hereby granted.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n PERFORMANCE OF THIS SOFTWARE.\n ***************************************************************************** */\nvar e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if(\"function\"!=typeof n&&null!==n)throw new TypeError(\"Class extends value \"+String(n)+\" is not a constructor or null\");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(t){var e=\"function\"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&\"number\"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?\"Object is not iterable.\":\"Symbol.iterator is not defined.\")}function o(t,e){var n=\"function\"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o=1&&r[0]instanceof Array?(e=function(){var e=r[0];t.push.apply(t,i([],o(e),!1))},n=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(e=function(){var e=r[0],n=r[1];t.assign(e,n)},n=r.slice(2)):(e=null,n=r),{ramda:e,tail:n}}}(s||(s={}));var h=null;function p(){return null===y&&(null===h&&(h=\"object\"==typeof global&&\"object\"==typeof global.process&&\"object\"==typeof global.process.versions&&void 0!==global.process.versions.node),void 0===(y=h?global:self).__s_iUID&&(y.__s_iUID=0)),y}var f,y=null;function v(t){if(t instanceof Object){if(!1===t.hasOwnProperty(\"__get_m_iUID\")){var e=++p().__s_iUID;Object.defineProperty(t,\"__get_m_iUID\",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function d(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function g(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):v(t)=1&&(c=l.tail[0])}n(c),null!==a&&a()},t.emplacable=function(t,e,n){var r=e.prev(),o=r.equals(t.end())||t.value_comp()(r.value,n);return o=o&&(e.equals(t.end())||t.value_comp()(n,e.value))}}(f||(f={}));var w,I=2166136261,k=16777619,q=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.equals=function(t){return d(this.first,t.first)&&d(this.second,t.second)},t.prototype.less=function(t){return!1===d(this.first,t.first)?g(this.first,t.first):g(this.second,t.second)},t.prototype.hashCode=function(){return function(){for(var t,e,n=[],o=0;o (index = \"+r+\").\")},t.excessive_index=function(t,n,r,o){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric index is equal or greater than size -> (index = \"+r+\", size: \"+o+\").\")},t.not_my_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is not this container's own.\")},t.erased_iterator=function(t,n){return new F(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator, it already has been erased.\")},t.negative_iterator=function(t,n,r){return new S(\"Error on \"+e(t)+\".\"+n+\"(): parametric iterator is directing negative position -> (index = \"+r+\").\")},t.iterator_end_value=function(t,n){void 0===n&&(n=\"end\");var r=e(t);return new S(\"Error on \"+r+\".Iterator.value: cannot access to the \"+r+\".\"+n+\"().value.\")},t.key_nout_found=function(t,n,r){throw new S(\"Error on \"+e(t)+\".\"+n+\"(): unable to find the matched key -> \"+r)}}(w||(w={}));var j=function(){function t(t,e,n){this.prev_=t,this.next_=e,this.value_=n}return t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e},t.prototype.prev=function(){return this.prev_},t.prototype.next=function(){return this.next_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this._Try_value(),this.value_},enumerable:!1,configurable:!0}),t.prototype._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw w.iterator_end_value(this.source())},t.prototype.equals=function(t){return this===t},t}(),z=function(){function t(t,e){this.index_=t,this.value_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,\"value\",{get:function(){return this.value_},enumerable:!1,configurable:!0}),t.prototype.next=function(){return++this.index_,this},t.prototype.equals=function(t){return this.index_===t.index_},t}();var R=function(t){function e(){var e=t.call(this)||this;return e.end_=e._Create_iterator(null,null),e.clear(),e}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},e.prototype.clear=function(){j._Set_prev(this.end_,this.end_),j._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},e.prototype.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(function(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var n;if(e<0){if(!(t.prev instanceof Function))throw new F(\"Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.\");n=function(t){return t.prev()},e=-e}else n=function(t){return t.next()};for(;e-- >0;)t=n(t);return t}(this.end(),-e),this.end())},e.prototype.begin=function(){return this.begin_},e.prototype.end=function(){return this.end_},e.prototype.size=function(){return this.size_},e.prototype.push_front=function(t){this.insert(this.begin_,t)},e.prototype.push_back=function(t){this.insert(this.end_,t)},e.prototype.pop_front=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_front\");this.erase(this.begin_)},e.prototype.pop_back=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,\"pop_back\");this.erase(this.end_.prev())},e.prototype.push=function(){for(var t=[],e=0;e {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n let max = arr[0]\n // const segs = [[arr[0], 0, 0]]\n const segs = new TreeMultiSet((a, b) => a[1] < b[1])\n segs.insert([arr[0], 0, 0])\n arr.forEach((x, i) => {\n if (x < max) {\n // segs.push([x, i, i]) // speed, begin, end\n segs.insert([x, i, i])\n max = x\n } else {\n // segs[segs.length - 1][2] = i\n segs.rbegin().value[2] = i\n }\n })\n // printSet(segs)\n// console.log(segs)\n return qs.map(([k, d]) => {\n k--\n // const idx = binarySearch(0, segs.length - 1, x => segs[x][1] <= k)\n // const last = binarySearch(idx, segs.length - 1, x => segs[x][0] >= arr[k] - d)\n const iter = segs.upper_bound([0, k, k]).prev()\n const value = iter.value\n // idx, last\n // if (arr[k] - d < segs[idx][0]) {\n if (arr[k] - d < value[0]) {\n let last = iter\n while (last.next() !== segs.end()\n && last.next().value[0] >= arr[k] - d) {\n last = last.next()\n }\n // console.log('last', last.value)\n // const add = [arr[k] - d, k, segs[last][2]]\n const add = [arr[k] - d, k, last.value[2]]\n let start = iter\n if (value[1] < k) {\n value[2] = k - 1\n // start = idx + 1\n start = iter.next()\n }\n // segs.splice(start, last - start + 1, add)\n // console.log(\n // start === segs.end(), last === segs.end())\n if (start !== segs.end() && start.value[1] <= last.value[1]) {\n // console.log(segs.size(), start.value, last.value)\n segs.erase(start, last.next())\n }\n segs.insert(add)\n }\n arr[k] -= d\n // console.log(segs)\n // printSet(segs)\n return segs.size()\n // return segs.length\n }).join(' ')\n}\nfunction printSet(segs) {\n let iter = segs.begin()\n const ans = []\n while (iter !== segs.end()) {\n ans.push(iter.value)\n iter = iter.next()\n }\n console.log(ans.join(' '))\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const N = n - 1;\r\n const segTree = new SegTree(N);\r\n a[0];\r\n b = b.map(([i, num]) => [i - 1, num]);\r\n a[b[0][0]] -= b[0][1];\r\n for (let i = 0, j = 0; i < n; i = j + 1) {\r\n while (j + 1 < n && a[j + 1] >= a[i]) {\r\n j++;\r\n }\r\n segTree.update(i, j, a[i]);\r\n }\r\n const res = new Array(m);\r\n res[0] = segTree.query(0, N)[2];\r\n for (let i = 1; i < m; i++) {\r\n const [j, num] = b[i];\r\n a[j] -= num;\r\n segTree.update(j, n, a[j]);\r\n res[i] = segTree.query(0, N)[2];\r\n }\r\n return res.join(' ');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(left = null, right = null) {\r\n return {\r\n left,\r\n right,\r\n l: Infinity,\r\n r: Infinity,\r\n count: 0,\r\n flag: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.flag) {\r\n left.l = left.r = right.l = right.r = node.flag;\r\n left.count = right.count = 1;\r\n left.flag = right.flag = node.flag;\r\n node.flag = 0;\r\n }\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.l = left.l;\r\n node.r = right.r;\r\n node.count = left.count + right.count;\r\n if (left.r === right.l) node.count--;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (node.l <= z) return;\r\n if (l === r) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n if (l === x && r === y) {\r\n if (node.l === node.r) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n if (node.r !== Infinity && node.r >= z) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return [Infinity, Infinity, 0];\r\n if (!node) return [Infinity, Infinity, 0];\r\n if (node.l === node.r) return [node.l, node.r, 1];\r\n if (l === x && r === y) return [node.l, node.r, node.count];\r\n let res,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else {\r\n let res1 = this._query(node.left, l, mid, x, mid),\r\n res2 = this._query(node.right, mid + 1, r, mid + 1, y);\r\n res = [res1[0], res2[1], res1[2] + res2[2]];\r\n if (res1[1] === res2[0]) res[2]--;\r\n }\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a, b) {\r\n const bst = new BinarySearchTree((a, b) => a[0] - b[0]);\r\n b = b.map(([i, num]) => [i - 1, num]);\r\n a[b[0][0]] -= b[0][1];\r\n let count = 0;\r\n for (let i = 0, j = 0; i < n; i = j + 1) {\r\n while (j + 1 < n && a[j + 1] >= a[i]) j++;\r\n bst.insert([i, j, a[i]]);\r\n count++;\r\n }\r\n const res = new Array(m);\r\n res[0] = count;\r\n for (let i = 1; i < m; i++) {\r\n const [j, num] = b[i];\r\n a[j] -= num;\r\n const cur = bst.floor([j, j, 0]);\r\n if (cur[2] > a[j]) {\r\n bst.delete(cur);\r\n if (cur[0] < j) {\r\n bst.insert([cur[0], j - 1, cur[2]]);\r\n count++;\r\n cur[0] = j;\r\n }\r\n cur[2] = a[j];\r\n let next = bst.ceiling(cur);\r\n while (((_next$ = (_next = next) === null || _next === void 0 ? void 0 : _next[2]) !== null && _next$ !== void 0 ? _next$ : -Infinity) >= a[j]) {\r\n var _next$, _next;\r\n count--;\r\n bst.delete(next);\r\n cur[1] = next[1];\r\n next = bst.ceiling(cur);\r\n }\r\n bst.insert(cur);\r\n }\r\n res[i] = count;\r\n }\r\n return res.join(' ');\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next2 = next) !== null && _next2 !== void 0 && _next2.left) {\r\n var _next2;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const N=n-1\r\n const segTree = new SegTree(N);\r\n a[0];\r\n b = b.map(([i, num]) => [i - 1, num]);\r\n a[b[0][0]] -= b[0][1];\r\n for (let i = 0, j = 0; i < n; i = j + 1) {\r\n while (a[j + 1] >= a[i]) {\r\n j++;\r\n }\r\n segTree.update(i, j, a[i]);\r\n }\r\n const res = new Array(m);\r\n res[0] = segTree.query(0, N)[2];\r\n for (let i = 1; i < m; i++) {\r\n const [j, num] = b[i];\r\n a[j] -= num;\r\n segTree.update(j, n, a[j]);\r\n res[i] = segTree.query(0, N)[2];\r\n }\r\n return res.join(' ');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(left = null, right = null) {\r\n return {\r\n left,\r\n right,\r\n l: Infinity,\r\n r: Infinity,\r\n count: 0,\r\n flag: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.flag) {\r\n left.l = left.r = right.l = right.r = node.l;\r\n left.count = right.count = 1;\r\n left.flag = right.flag = node.flag;\r\n }\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.l = left.l;\r\n node.r = right.r;\r\n node.count = left.count + right.count;\r\n if (left.r === right.l) node.count--;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (node.l <= z) return;\r\n if (l === r) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n if (l === x && r === y && node.r !== Infinity && node.r >= z) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return [Infinity, Infinity, 0];\r\n if (!node) return [Infinity, Infinity, 0];\r\n if (node.l === node.r) return [node.l, node.r, 1];\r\n if (l === x && r === y) return [node.l, node.r, node.count];\r\n let res,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else {\r\n let res1 = this._query(node.left, l, mid, x, mid),\r\n res2 = this._query(node.right, mid + 1, r, mid + 1, y);\r\n res = [res1[0], res2[1], res1[2] + res2[2]];\r\n if (res1[1] === res2[0]) res[2]--;\r\n }\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const segTree = new SegTree(n);\r\n a[0];\r\n b = b.map(([i, num]) => [i - 1, num]);\r\n a[b[0][0]] -= b[0][1];\r\n for (let i = 0, j = 0; i < n; i = j + 1) {\r\n while (a[j + 1] >= a[i]) {\r\n j++;\r\n }\r\n segTree.update(i, j, a[i]);\r\n }\r\n const res = new Array(m);\r\n res[0] = segTree.query(0, n)[2];\r\n for (let i = 1; i < m; i++) {\r\n const [j, num] = b[i];\r\n a[j] -= num;\r\n segTree.update(j, n, a[j]);\r\n res[i] = segTree.query(0, n)[2];\r\n }\r\n return res.join(' ');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(left = null, right = null) {\r\n return {\r\n left,\r\n right,\r\n l: Infinity,\r\n r: Infinity,\r\n count: 0,\r\n flag: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.flag) {\r\n left.l = left.r = right.l = right.r = node.flag;\r\n left.count = right.count = 1;\r\n left.flag = right.flag = node.flag;\r\n }\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.l = left.l;\r\n node.r = right.r;\r\n node.count = left.count + right.count;\r\n if (left.r === right.l) node.count--;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (node.l <= z) return;\r\n if (l === r) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n if (l === x && r === y && node.r !== Infinity && node.r >= z) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return [Infinity, Infinity, 0];\r\n if (!node) return [Infinity, Infinity, 0];\r\n if (node.l === node.r) return [node.l, node.r, 1];\r\n if (l === x && r === y) return [node.l, node.r, node.count];\r\n let res,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else {\r\n let res1 = this._query(node.left, l, mid, x, mid),\r\n res2 = this._query(node.right, mid + 1, r, mid + 1, y);\r\n res = [res1[0], res2[1], res1[2] + res2[2]];\r\n if (res1[1] === res2[0]) res[2]--;\r\n }\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, m, a, b) {\r\n const segTree = new SegTree(n);\r\n a[0];\r\n b = b.map(([i, num]) => [i - 1, num]);\r\n a[b[0][0]] -= b[0][1];\r\n for (let i = 0, j = 0; i < n; i = j + 1) {\r\n while (a[j + 1] >= a[i]) {\r\n j++;\r\n }\r\n segTree.update(i, j, a[i]);\r\n }\r\n const res = new Array(m);\r\n res[0] = segTree.query(0, n)[2];\r\n for (let i = 1; i < m; i++) {\r\n const [j, num] = b[i];\r\n a[j] -= num;\r\n segTree.update(j, n, a[j]);\r\n res[i] = segTree.query(0, n)[2];\r\n }\r\n return res.join(' ');\r\n}\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode();\r\n this.update = (x, y, z) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n this._update(this.root, 0, n, x, y, z);\r\n };\r\n this.query = (x, y) => {\r\n x = Math.max(x, 0);\r\n y = Math.min(y, n);\r\n return this._query(this.root, 0, n, x, y);\r\n };\r\n }\r\n _newNode(left = null, right = null) {\r\n return {\r\n left,\r\n right,\r\n l: Infinity,\r\n r: Infinity,\r\n count: 0,\r\n flag: 0\r\n };\r\n }\r\n _down(node, l, r) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n if (node.flag) {\r\n left.l = left.r = right.l = right.r = node.l;\r\n left.count = right.count = 1;\r\n left.flag = right.flag = node.flag;\r\n }\r\n }\r\n _up(node) {\r\n const {\r\n left,\r\n right\r\n } = node;\r\n if (!left || !right) return;\r\n node.l = left.l;\r\n node.r = right.r;\r\n node.count = left.count + right.count;\r\n if (left.r === right.l) node.count--;\r\n }\r\n _update(node, l, r, x, y, z) {\r\n if (!node) return;\r\n if (node.l <= z) return;\r\n if (l === r) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n if (l === x && r === y && node.r !== Infinity && node.r >= z) {\r\n node.l = z;\r\n node.r = z;\r\n node.count = 1;\r\n node.flag = z;\r\n return;\r\n }\r\n const mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);\r\n this._up(node);\r\n }\r\n _query(node, l, r, x, y) {\r\n if (y < x) return [Infinity, Infinity, 0];\r\n if (!node) return [Infinity, Infinity, 0];\r\n if (node.l === node.r) return [node.l, node.r, 1];\r\n if (l === x && r === y) return [node.l, node.r, node.count];\r\n let res,\r\n mid = Math.floor((l + r) / 2);\r\n if (!node.left) {\r\n node.left = this._newNode();\r\n node.right = this._newNode();\r\n }\r\n this._down(node, l, r);\r\n if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else {\r\n let res1 = this._query(node.left, l, mid, x, mid),\r\n res2 = this._query(node.right, mid + 1, r, mid + 1, y);\r\n res = [res1[0], res2[1], res1[2] + res2[2]];\r\n if (res1[1] === res2[0]) res[2]--;\r\n }\r\n this._up(node);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n await read();\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n const b = [];\r\n let tmp = m;\r\n while (tmp--) {\r\n b.push((await read()).split(' ').map(Number));\r\n }\r\n res.push(solve(n, m, a, b));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n l++\n const [n, q] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))\n l += q\n output[i] = solve(n, arr, qs)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr, qs) {\n let max = arr[0]\n const segs = [[arr[0], 0, 0]]\n arr.forEach((x, i) => {\n if (x < max) {\n segs.push([x, i, i]) // speed, begin, end\n max = x\n } else {\n segs[segs.length - 1][2] = i\n }\n })\n// console.log(segs)\n return qs.map(([k, d]) => {\n k--\n const idx = binarySearch(0, segs.length - 1, x => segs[x][1] <= k)\n const last = binarySearch(idx, segs.length - 1, x => segs[x][0] >= arr[k] - d)\n // idx, last\n if (arr[k] - d < segs[idx][0]) {\n let start = idx\n if (segs[idx][1] < k) {\n segs[idx][2] = k - 1\n start = idx + 1\n }\n const add = [arr[k] - d, k, segs[last][2]]\n segs.splice(start, last - start + 1, add)\n }\n // console.log(segs)\n return segs.length\n }).join(' ')\n}\nfunction binarySearch(l, r, fn) {\n while (l <= r) {\n const m = Math.floor((l + r) / 2)\n if (fn(m)) {\n l = m + 1\n } else {\n r = m - 1\n }\n }\n return r\n}\n"}], "src_uid": "9f285a42ebb0581f1cda7beba7b938c7"} {"source_code": " var s = readline().split(' ');\n var n = +s[0], k = +s[1];\n if (k>n/2)k = n - k;\n var x = 0, ans = [], t = [];\n for (var i=0; i= 0; r = (r & (r+1)) - 1)\n result += t[r];\n\treturn result;\n }\n function _inc(i, delta)\n {\n\tfor (; i < n; i = (i | (i+1)))\n t[i] += delta;\n }\n function inc(from, to){\n _inc(from%n, 1);\n _inc(to%n, 1);\n }\n function get(from, to){\n from = from%n;\n to = to%n;\n if (ton){k=n-k;}\nvar x=1\nvar res=1\nvar d=1\nvar q=[]\nfor (var i=0;i= 0; r = (r & (r+1)) - 1)\n result += t[r];\n\treturn result;\n }\n function _inc(i, delta)\n {\n\tfor (; i < n; i = (i | (i+1)))\n t[i] += delta;\n }\n function inc(from, to){\n _inc(from%n, 1);\n _inc(to%n, 1);\n }\n function get(from, to){\n from = from%n;\n to = to%n;\n if (to a * b) write('-1');\nelse\n while (a > 0) {\n if (flag === 0) {\n for (var i = 0; i < b; i++, val++) \n if (val > n) write('0 ');\n else write((val) + ' ');\n \n } else if (flag == 1) {\n if (val + b - 1 > n) write('0 ');\n else { write ((val + b - 1) + ' '); }\n \n for (var i = 1; i < b; i++, val++)\n if (val > n) write('0 ');\n else write((val) + ' ');\n val++;\n }\n write('\\n');\n a--;\n if (b % 2 === 0) flag = 1 - flag;\n }", "positive_code": [{"source_code": "var tmp = readline().split(' ').map(Number);\n\nvar cnt = tmp[0];\nvar row = tmp[1];\nvar col = tmp[2];\n\nif(row * col < cnt) {print(-1); quit(0)}\n\nvar p = 1;\nif(col % 2 !== 0)\n{\n for(var i = 0; i < row; i++)\n {\n for(var j = 0; j < col; j++)\n {\n write((p <= cnt? p++: 0));\n if(j !== col - 1)\n write(' ');\n }\n write(\"\\n\");\n }\n} else\n{\n for(var i = 0; i < row; i++)\n {\n if(i % 2 === 0)\n for(var j = 0; j < col; j++)\n {\n write(p <= cnt? p++: 0);\n if(j !== col - 1)\n write(' ');\n }\n else\n {\n var s = '';\n for(var j = 0; j < col; j++)\n {\n s = (p <= cnt? p++: 0) + ' ' + s;\n }\n write(s);\n \n }\n write(\"\\n\");\n } \n}\n "}, {"source_code": "var input = readline().split(' ')\n\nvar n = input[0],\n a = input[1],\n b = input[2]\n\nif (n > a * b) {\n\n print('-1')\n\n} else {\n\n for (var i = 0, deputy = 1; i < a; i++) {\n var row = []\n var op = i % 2 === 0 ? 'push' : 'unshift'\n for (var j = 0; j < b; j++, deputy++) {\n row[op](deputy > n ? 0 : deputy)\n }\n print(row.join(' '))\n }\n\n}"}, {"source_code": "var input = readline().split(' ')\n , n = +input[0]\n , a = +input[1]\n , b = +input[2]\n , p = 0\n , result = [];\n \nif (a * b < n) {\n print(-1);\n quit();\n}\nif ( b % 2 === 1 ) {\n for (var i = 0; i < a; i++ ) {\n result.push([]);\n for (var j = 0; j < b; j++ ) { \n if (p < n) {\n result[i][j] = ++p;\n } else {\n result[i][j] = 0;\n }\n }\n print(result[i].join(' '));\n }\n} else {\n for (var i = 0; i < a; i++ ) {\n result.push([]);\n for (var j = 0; j < b; j++ ) {\n if (p < n) {\n result[i][j] = ++p;\n } else {\n result[i][j] = 0;\n }\n }\n \n if (i % 2 === 0) {\n print(result[i].join(' '));\n } else {\n print(result[i].reverse().join(' '));\n }\n } \n}"}, {"source_code": "var input = readline().split(' ');\nvar n = input[0];\nvar a = input[1];\nvar b = input[2];\n\nif (n && a && b && n >= 1 && n <= 10000 && a >= 1 && a <= 100 && b >= 1 && b <= 100 && a * b >= n)\n{\n var all = [];\n for (i = 1; i <= n; i++) all.push(i);\n for (i = 1; i <= a; i++)\n {\n var buf = all.splice(0, b);\n while (buf.length < b) buf.push(0);\n if (b%2===0 && i%2===0) buf = buf.reverse();\n print(buf.join(' '));\n }\n \n}\nelse\n{\n print(-1);\n}"}, {"source_code": "var args = readline().split(' ');\nvar parlament = (n, a, b) => {\n var i = 0;\n var j = 0;\n var p = 1;\n var x = a * b;\n var seats = [];\n seats[0] = [];\n if (n > x) {\n print(-1);\n return;\n }\n b--;\n a--;\n while (x--) {\n i % 2 ? seats[i][b - j] = p : seats[i][j] = p;\n j++;\n p = (p < n && p) ? ++p : 0;\n if (j === b + 1 && i !== a) {\n j = 0;\n i++;\n seats[i] = [];\n }\n }\n seats.forEach(function(item) {\n var str = '';\n item.forEach(function(item) {\n str = str + item + ' ';\n });\n print(str);\n });\n};\nvar n = args[0];\nvar a = args[1];\nvar b = args[2];\nparlament(n, a, b)"}, {"source_code": "var readInt = () => parseInt(readline())\nvar readIntArray = () => readline().split(' ').map(item => parseInt(item))\nfunction range(a, b) {\n var res = []\n for (var i = a; i <= b; i++) {\n res.push(i)\n }\n return res\n}\n\nvar inputData = readIntArray()\nvar n = inputData[0]\nvar a = inputData[1]\nvar b = inputData[2]\n\nif (n > a*b) {\n print(-1)\n}\nelse {\n var shift = b % 2 === 0\n var k = 1\n for (var i = 0; i < a; i++) {\n var ar = range(i*b+1, (i+1)*b)\n if (shift && i % 2 !== 0) {\n var temp = ar.shift()\n ar.push(temp)\n }\n print(ar.map(m => m > n ? 0 : m).join(' '))\n }\n}"}], "negative_code": [{"source_code": "var tmp = readline().split(' ').map(Number);\n\nvar cnt = tmp[0];\nvar row = tmp[1];\nvar col = tmp[2];\n\nif(row * col < cnt) {print(-1); exit(0)}\n\nvar p = 1;\nif(col % 2 !== 0)\n{\n for(var i = 0; i < row; i++)\n {\n for(var j = 0; j < col; j++)\n {\n write((p <= cnt? p++: 0) + ' ');\n }\n write(\"\\n\");\n }\n} else\n{\n for(var i = 0; i < row; i++)\n {\n if(i % 2 === 0)\n for(var j = 0; j < col; j++)\n {\n write((p <= cnt? p++: 0) + ' ');\n }\n else\n {\n p += col -1;\n for(var j = 0; j < col; j++)\n {\n write((p <= cnt? p--: 0) + ' ');\n }\n p += col +1;\n }\n write(\"\\n\");\n } \n}"}, {"source_code": "var input = readline().split(' ')\n\nvar n = input[0],\n a = input[1],\n b = input[2]\n\nif (n > a * b) {\n print('-1')\n} else {\n\n for (var i = 0, deputy = 1; i < a; i++) {\n var row = []\n for (var j = 0; j < b; j++, deputy++) {\n if (deputy > n) { row.push(0) }\n else if (i % 2 === 0) { row.push(deputy) }\n else { row.unshift(deputy) }\n }\n print(row.join(' '))\n }\n \n}\n"}, {"source_code": "var input = readline().split(' ')\n , n = +input[0]\n , a = +input[1]\n , b = +input[2]\n , p = 0\n , result = [];\n \nif (a * b < n) {\n print(-1);\n quit();\n}\nif ( b % 2 === 1 ) {\n for (var i = 0; i < a; i++ ) {\n result.push([]);\n for (var j = 0; j < b; j++ ) { \n if (p < n) {\n result[i][j] = ++p;\n } else {\n result[i][j] = 0;\n }\n }\n print(result[i].join(' '));\n }\n} else {\n for (var i = 0; i < a; i++ ) {\n result.push([]);\n for (var j = 0; j < b; j++ ) {\n if (p < n) {\n if (i % 2 === 0) {\n result[i][j] = ++p;\n } else {\n result[i][b-j-1] = ++p;\n }\n } else {\n result[i][j] = 0;\n }\n }\n print(result[i].join(' '));\n } \n}"}], "src_uid": "6e0dafeaf85e92f959c388c72e158f68"} {"source_code": "Main();\nfunction myout(t){print(t);}//standard output\nfunction next(){return readline();}\n//[no]param\n//\u4e0d\u660e\u5024:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408\u30009:\u6539\u884c\u3067\u7d50\u5408\u30000:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}\nfunction Main() {\n var t = myconv(next(),1);\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = myconv(next(),1) * 2;\n var list = myconv(next(),4);\n list.sort(function(a,b){\n return a -b;\n });\n output[i] = Math.abs(list[N / 2 - 1] - list[N / 2]);\n }\n myout(myconv(output,9));\n}\n", "positive_code": [{"source_code": "'use strict'\n\nconst problem = (n, a) => {\n a.sort((x, y) => x - y)\n return a[n] - a[n-1]\n}\nlet t = +readline();\nwhile(t--) print(problem(+readline(), readline().split(' ').map(i => +i)))\n"}, {"source_code": "function readNum() {\n return Number(readline());\n}\nfunction readStringArray() {\n return readline().split(\" \");\n}\nfunction readNumArray() {\n return readStringArray().map(Number);\n}\n\nfunction main() {\n var testCasesNum = readNum();\n for (var i = 0; i < testCasesNum; i++) {\n var n = readNum();\n var arr = readNumArray();\n var sorted = arr.sort((a, b) => a - b);\n print(sorted[n] - sorted[n - 1]);\n }\n}\nmain()"}, {"source_code": "'use strict';\n\nlet currentLine = 0, inputLine = [];\n\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => { inputLine.push(line); });\nrl.on('close', () =>{ main(inputLine); } );\n \nfunction readALine() { return inputLine[currentLine++]; }\nfunction printALine(str) { console.log(str); }\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n if( result.length % 2 == 0 ) {\n result.pop();\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n if( arr.length % 2 == 1 ) {\n return arr[index];\n }\n return (arr[index] + arr[index-1])/2;\n}\n\nfunction doIt( n, arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n result = Math.abs(arr2[n] - arr2[n-1]);\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var n = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(n, arr);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;\n"}, {"source_code": "const mediana = arr => arr[Math.ceil(arr.length/2)]\n\nconst processData = (lines) => {\n const count = lines[0]\n\n for (i = 0; i < count; i++){\n const nums = lines[i*2 + 2].split(' ').map(x => +x)\n const sortedNums = nums.sort((a, b) => a - b)\n const [a, b] = [sortedNums[sortedNums.length/2], sortedNums[sortedNums.length/2 - 1]]\n console.log(Math.abs(a - b))\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n"}, {"source_code": "'use strict';\n\nconst { createInterface } = require('readline');\nconst rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nconst lines = [];\nlet nextLine = 0;\nrl.on('line', (line) => {\n lines.push(line);\n});\n\nrl.on('close', () => {\n main();\n});\n\nfunction readline() {\n return lines[nextLine++];\n}\n\nfunction solve(arr) {\n const n = arr.length;\n const n2 = n / 2;\n arr.sort((a, b) => a - b);\n return arr[n2] - arr[n2-1];\n}\n\nfunction main() {\n const t = parseInt(readline());\n // console.log({t});\n for(let i = 0; i < t; i++) {\n readline();\n const arr = readline().split(' ').map(Number);\n const res = solve(arr);\n console.log(res);\n }\n}\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => input.push(line));\n\nreadline.on('close', () => {\n let n = parseInt(input[0]);\n for (let i = 1; i < 2 * n + 1; i += 2) {\n let len = parseInt(input[i]);\n let students = input[i + 1].split(' ').map(x => parseInt(x));\n students.sort((a, b) => a - b);\n\n console.log(students[len] - students[len - 1]);\n }\n});"}, {"source_code": "// Time Complexity O(n)\nfunction processData(input) {\n input = input.trim().split('\\n')\n var t = Number(input[0])\n // console.log(t)\n var line = 1\n for(var j = 0;jparseInt(a)).sort((a,b)=>(a-b))\n // console.log(n,a)\n var res = findSum(n,a)\n console.log(res)\n\n }\n function findSum(n,a){\n var res = Math.abs(a[n/2]-a[n/2-1])\n return res\n }\n} \n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});\n"}], "negative_code": [{"source_code": "var inputLines = null;\n\nfunction readALine() {\n if( inputLines ) { return inputLines.shift(); }\n return readline();\n}\n\nfunction printALine(str) {\n if( typeof print !== 'undefined' ) print(str); else console.log(str);\n}\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n return arr[index];\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.abs(m2 - m1);\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports = { main: main, inputLines: inputLines };\n"}, {"source_code": "'use strict';\n\nlet currentLine = 0, inputLine = [];\n\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => { inputLine.push(line); });\nrl.on('close', () =>{ main(inputLine); } );\n \nfunction readALine() { return inputLine[currentLine++]; }\nfunction printALine(str) { console.log(str); }\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n if( arr.length % 2 == 1 ) {\n return arr[index];\n }\n return (arr[index] + arr[index-1])/2;\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.floor(Math.abs(m2 - m1));\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;\n"}, {"source_code": "'use strict';\n\nlet currentLine = 0, inputLine = [];\n\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => { inputLine.push(line); });\nrl.on('close', () =>{ main(inputLine); } );\n \nfunction readALine() { return inputLine[currentLine++]; }\nfunction printALine(str) { console.log(str); }\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n return arr[index];\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.abs(m2 - m1);\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;\n"}, {"source_code": "'use strict';\n\nlet currentLine = 0, inputLine = [];\n\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => { inputLine.push(line); });\nrl.on('close', () =>{ main(inputLine); } );\n \nfunction readALine() { return inputLine[currentLine++]; }\nfunction printALine(str) { console.log(str); }\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n if( result.length % 2 == 0 ) {\n result.pop();\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n if( arr.length % 2 == 1 ) {\n return arr[index];\n }\n return (arr[index] + arr[index-1])/2;\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.floor(Math.abs(m2 - m1));\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLine = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports.main = main;\n"}, {"source_code": "var inputLines = null;\n\nfunction readALine() {\n if( inputLines ) { return inputLines.shift(); }\n return readline();\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n return arr[index];\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.abs(m2 - m1);\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines;\n\n console.log(\"A\");\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports = { main: main, inputLines: inputLines };\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\nfunction stringArrayToBigInts(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( BigInt(array[i]) );\n }\n return result;\n}\n\nfunction sumOfAllElementsInArray(arr) {\n var result = 0;\n for( var i = 0; i < arr.length; i++ ) {\n result += arr[i];\n }\n return result;\n}\n\nfunction productOfAllElementsInArray(arr) {\n var result = 1;\n for( var i = 0; i < arr.length; i++ ) {\n result *= arr[i];\n }\n return result;\n}\n\nfunction maxOfElementsInArray(arr) {\n var result = 0;\n for( var i = 0; i < arr.length; i++ ) {\n if( arr[i] > result ) {\n result = arr[i];\n }\n }\n return result;\n}\n\nfunction sortIntegersInArray(arr) {\n function sortNumber(a, b) {\n return a - b;\n }\n arr.sort(sortNumber);\n return arr;\n}\n\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n return arr[index];\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n //console.log(\"Array2 = \" + arr2);\n var a1 = splitArray(0, arr2);\n //console.log(\" a1 = \" + a1);\n var a2 = splitArray(1, arr2); \n //console.log(\" a2 = \" + a2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.abs(m2 - m1);\n return result;\n}\n\nfunction main() {\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\n\n\n\n\n"}, {"source_code": "var inputLines = null;\n\nfunction readALine() {\n if( inputLines ) { return inputLines.shift(); }\n return readline();\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\n// ======================================================\n// B. Assigning to Classes\n// http://codeforces.com/contest/1300/problem/B\n// ======================================================\n\nfunction stringArrayToNumbers(str) {\n return str.split(' ').map(Number);\n}\n\nfunction sortIntegersInArray(arr) {\n return arr.sort((a, b) => a - b);\n}\n\nfunction splitArray(startIndex, arr) {\n var result = [];\n for( var i = startIndex; i < arr.length; i+=2 ) {\n result.push(arr[i]);\n }\n return result;\n}\n\nfunction getMedian(arr) {\n var index = Math.floor(arr.length/2);\n return arr[index];\n}\n\nfunction doIt( arr ) { \n var result = 0;\n var arr2 = sortIntegersInArray(arr);\n var a1 = splitArray(0, arr2);\n var a2 = splitArray(1, arr2); \n var m1 = getMedian(a1);\n var m2 = getMedian(a2);\n result = Math.abs(m2 - m1);\n return result;\n}\n\nfunction main( inLines ) {\n\n inputLines = inLines;\n\n var numOfTests = parseInt(readALine());\n for( var i = 0; i < numOfTests; i++ ) {\n var string1 = readALine();\n var numOfElements = parseInt(string1);\n var string2 = readALine();\n var arr = stringArrayToNumbers(string2);\n var result = doIt(arr);\n printALine(result);\n }\n\n}\n\nmodule.exports = { main: main, inputLines: inputLines };\n"}], "src_uid": "adb0f6082367dc432e2e096c64f13a56"} {"source_code": "function myout(t){print(t);}//standard output\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\nfunction Main() {\n var tmp = myconv(readline(),4);\n var n = tmp[0];\n var ink = tmp[1];\n var list = [];\n var reqlist = [];\n var inputSet = new Set();\n for(var i = 0; i < n; i++){\n var strin = readline();\n list.push(myconv(strin,6));\n inputSet.add(strin);\n }\n var output = 0;\n for(var i = 0; i < n-1; i++){\n for(var j = i+1; j < n; j++){\n var reqstr = \"\";\n for(var k = 0; k < ink; k++){\n if(list[i][k] == list[j][k]){\n reqstr += list[i][k];\n }else{\n if((list[i][k] == \"E\" && list[j][k] == \"T\") || \n (list[i][k] == \"T\" && list[j][k] == \"E\")){\n reqstr += \"S\";\n }else if((list[i][k] == \"S\" && list[j][k] == \"T\") || \n (list[i][k] == \"T\" && list[j][k] == \"S\")){\n reqstr += \"E\";\n }else{\n reqstr += \"T\";\n }\n }\n }\n if(inputSet.has(reqstr)){\n output++;\n }\n }\n }\n myout(output / 3);\n}\n\nMain();", "positive_code": [{"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction nkStdinReader() {\n return new Promise(function (resolve) {\n var stdin = readline.createInterface(process.stdin);\n var output = [];\n var lines;\n stdin.on('line', function (line) {\n output.push(line);\n\n if (output.length === 1) {\n lines = +line.split(' ')[0];\n } else if (--lines === 0) {\n stdin.close();\n resolve(output);\n }\n });\n });\n}\n\n// https://codeforces.com/problemset/problem/1287/B\nvar setCreator = new Map([['EE', 'E'], ['ES', 'T'], ['ET', 'S'], ['SE', 'T'], ['SS', 'S'], ['ST', 'E'], ['TE', 'S'], ['TS', 'E'], ['TT', 'T']]);\n\nfunction getSetCard(card1, card2) {\n var card = '';\n\n for (var x = 0; x < card1.length; x++) {\n card += setCreator.get(card1[x] + card2[x]);\n }\n\n return card;\n}\n\nnkStdinReader().then(function (input) {\n var cards = input.slice(1);\n var cardLookup = new Map(cards.map(function (c, i) {\n return [c, i];\n }));\n var output = 0;\n\n for (var x = 0; x < cards.length - 2; x++) {\n for (var y = x + 1; y < cards.length - 1; y++) {\n var setCard = getSetCard(cards[x], cards[y]);\n\n if ((cardLookup.get(setCard) || 0) > y) {\n output++;\n }\n }\n }\n\n console.log(output);\n});\n"}], "negative_code": [{"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction nkStdinReader() {\n return new Promise(function (resolve) {\n var stdin = readline.createInterface(process.stdin);\n var output = [];\n var lines;\n stdin.on('line', function (line) {\n output.push(line);\n\n if (output.length === 1) {\n lines = +line.split(' ')[0];\n } else if (--lines === 0) {\n stdin.close();\n resolve(output);\n }\n });\n });\n}\n\n// https://codeforces.com/problemset/problem/1287/B\n\nfunction getSetCard(card1, card2) {\n var card = '';\n\n var _loop = function _loop(x) {\n var a = card1[x];\n var b = card2[x];\n\n if (a === b) {\n card += a;\n } else {\n card += ['E', 'S', 'T'].find(function (c) {\n return c !== a && c !== b;\n });\n }\n };\n\n for (var x = 0; x < card1.length; x++) {\n _loop(x);\n }\n\n return card;\n}\n\nnkStdinReader().then(function (input) {\n var cards = input.slice(1);\n var cardLookup = new Map(cards.map(function (c, i) {\n return [c, i];\n }));\n var output = 0;\n\n for (var x = 0; x < cards.length - 2; x++) {\n for (var y = x + 1; y < cards.length - 1; y++) {\n var setCard = getSetCard(cards[x], cards[y]);\n\n if (cardLookup.get(setCard) || 0 > y) {\n output++;\n }\n }\n }\n\n console.log(output);\n});\n"}, {"source_code": "'use strict';\n\nvar readline = require('readline');\n\n/*! *****************************************************************************\nCopyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0\n\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\nMERCHANTABLITY OR NON-INFRINGEMENT.\n\nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\n/* global Reflect, Promise */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nfunction __extends(d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isFunction(x) {\n return typeof x === 'function';\n}\n//# sourceMappingURL=isFunction.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar _enable_super_gross_mode_that_will_cause_bad_things = false;\nvar config = {\n Promise: undefined,\n set useDeprecatedSynchronousErrorHandling(value) {\n if (value) {\n var error = /*@__PURE__*/ new Error();\n /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \\n' + error.stack);\n }\n _enable_super_gross_mode_that_will_cause_bad_things = value;\n },\n get useDeprecatedSynchronousErrorHandling() {\n return _enable_super_gross_mode_that_will_cause_bad_things;\n },\n};\n//# sourceMappingURL=config.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction hostReportError(err) {\n setTimeout(function () { throw err; }, 0);\n}\n//# sourceMappingURL=hostReportError.js.map\n\n/** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */\nvar empty = {\n closed: true,\n next: function (value) { },\n error: function (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n },\n complete: function () { }\n};\n//# sourceMappingURL=Observer.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();\n//# sourceMappingURL=isArray.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction isObject(x) {\n return x !== null && typeof x === 'object';\n}\n//# sourceMappingURL=isObject.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {\n function UnsubscriptionErrorImpl(errors) {\n Error.call(this);\n this.message = errors ?\n errors.length + \" errors occurred during unsubscription:\\n\" + errors.map(function (err, i) { return i + 1 + \") \" + err.toString(); }).join('\\n ') : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n return this;\n }\n UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return UnsubscriptionErrorImpl;\n})();\nvar UnsubscriptionError = UnsubscriptionErrorImpl;\n//# sourceMappingURL=UnsubscriptionError.js.map\n\n/** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */\nvar Subscription = /*@__PURE__*/ (function () {\n function Subscription(unsubscribe) {\n this.closed = false;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (unsubscribe) {\n this._unsubscribe = unsubscribe;\n }\n }\n Subscription.prototype.unsubscribe = function () {\n var errors;\n if (this.closed) {\n return;\n }\n var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;\n this.closed = true;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (_parentOrParents instanceof Subscription) {\n _parentOrParents.remove(this);\n }\n else if (_parentOrParents !== null) {\n for (var index = 0; index < _parentOrParents.length; ++index) {\n var parent_1 = _parentOrParents[index];\n parent_1.remove(this);\n }\n }\n if (isFunction(_unsubscribe)) {\n try {\n _unsubscribe.call(this);\n }\n catch (e) {\n errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];\n }\n }\n if (isArray(_subscriptions)) {\n var index = -1;\n var len = _subscriptions.length;\n while (++index < len) {\n var sub = _subscriptions[index];\n if (isObject(sub)) {\n try {\n sub.unsubscribe();\n }\n catch (e) {\n errors = errors || [];\n if (e instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(e.errors));\n }\n else {\n errors.push(e);\n }\n }\n }\n }\n }\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n };\n Subscription.prototype.add = function (teardown) {\n var subscription = teardown;\n if (!teardown) {\n return Subscription.EMPTY;\n }\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(teardown);\n case 'object':\n if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {\n return subscription;\n }\n else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n }\n else if (!(subscription instanceof Subscription)) {\n var tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default: {\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n }\n var _parentOrParents = subscription._parentOrParents;\n if (_parentOrParents === null) {\n subscription._parentOrParents = this;\n }\n else if (_parentOrParents instanceof Subscription) {\n if (_parentOrParents === this) {\n return subscription;\n }\n subscription._parentOrParents = [_parentOrParents, this];\n }\n else if (_parentOrParents.indexOf(this) === -1) {\n _parentOrParents.push(this);\n }\n else {\n return subscription;\n }\n var subscriptions = this._subscriptions;\n if (subscriptions === null) {\n this._subscriptions = [subscription];\n }\n else {\n subscriptions.push(subscription);\n }\n return subscription;\n };\n Subscription.prototype.remove = function (subscription) {\n var subscriptions = this._subscriptions;\n if (subscriptions) {\n var subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n };\n Subscription.EMPTY = (function (empty) {\n empty.closed = true;\n return empty;\n }(new Subscription()));\n return Subscription;\n}());\nfunction flattenUnsubscriptionErrors(errors) {\n return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);\n}\n//# sourceMappingURL=Subscription.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar rxSubscriber = /*@__PURE__*/ (function () {\n return typeof Symbol === 'function'\n ? /*@__PURE__*/ Symbol('rxSubscriber')\n : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();\n})();\n//# sourceMappingURL=rxSubscriber.js.map\n\n/** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */\nvar Subscriber = /*@__PURE__*/ (function (_super) {\n __extends(Subscriber, _super);\n function Subscriber(destinationOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this.syncErrorValue = null;\n _this.syncErrorThrown = false;\n _this.syncErrorThrowable = false;\n _this.isStopped = false;\n switch (arguments.length) {\n case 0:\n _this.destination = empty;\n break;\n case 1:\n if (!destinationOrNext) {\n _this.destination = empty;\n break;\n }\n if (typeof destinationOrNext === 'object') {\n if (destinationOrNext instanceof Subscriber) {\n _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;\n _this.destination = destinationOrNext;\n destinationOrNext.add(_this);\n }\n else {\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext);\n }\n break;\n }\n default:\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);\n break;\n }\n return _this;\n }\n Subscriber.prototype[rxSubscriber] = function () { return this; };\n Subscriber.create = function (next, error, complete) {\n var subscriber = new Subscriber(next, error, complete);\n subscriber.syncErrorThrowable = false;\n return subscriber;\n };\n Subscriber.prototype.next = function (value) {\n if (!this.isStopped) {\n this._next(value);\n }\n };\n Subscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n this.isStopped = true;\n this._error(err);\n }\n };\n Subscriber.prototype.complete = function () {\n if (!this.isStopped) {\n this.isStopped = true;\n this._complete();\n }\n };\n Subscriber.prototype.unsubscribe = function () {\n if (this.closed) {\n return;\n }\n this.isStopped = true;\n _super.prototype.unsubscribe.call(this);\n };\n Subscriber.prototype._next = function (value) {\n this.destination.next(value);\n };\n Subscriber.prototype._error = function (err) {\n this.destination.error(err);\n this.unsubscribe();\n };\n Subscriber.prototype._complete = function () {\n this.destination.complete();\n this.unsubscribe();\n };\n Subscriber.prototype._unsubscribeAndRecycle = function () {\n var _parentOrParents = this._parentOrParents;\n this._parentOrParents = null;\n this.unsubscribe();\n this.closed = false;\n this.isStopped = false;\n this._parentOrParents = _parentOrParents;\n return this;\n };\n return Subscriber;\n}(Subscription));\nvar SafeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SafeSubscriber, _super);\n function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this._parentSubscriber = _parentSubscriber;\n var next;\n var context = _this;\n if (isFunction(observerOrNext)) {\n next = observerOrNext;\n }\n else if (observerOrNext) {\n next = observerOrNext.next;\n error = observerOrNext.error;\n complete = observerOrNext.complete;\n if (observerOrNext !== empty) {\n context = Object.create(observerOrNext);\n if (isFunction(context.unsubscribe)) {\n _this.add(context.unsubscribe.bind(context));\n }\n context.unsubscribe = _this.unsubscribe.bind(_this);\n }\n }\n _this._context = context;\n _this._next = next;\n _this._error = error;\n _this._complete = complete;\n return _this;\n }\n SafeSubscriber.prototype.next = function (value) {\n if (!this.isStopped && this._next) {\n var _parentSubscriber = this._parentSubscriber;\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._next, value);\n }\n else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;\n if (this._error) {\n if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._error, err);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, this._error, err);\n this.unsubscribe();\n }\n }\n else if (!_parentSubscriber.syncErrorThrowable) {\n this.unsubscribe();\n if (useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n hostReportError(err);\n }\n else {\n if (useDeprecatedSynchronousErrorHandling) {\n _parentSubscriber.syncErrorValue = err;\n _parentSubscriber.syncErrorThrown = true;\n }\n else {\n hostReportError(err);\n }\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.complete = function () {\n var _this = this;\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n if (this._complete) {\n var wrappedComplete = function () { return _this._complete.call(_this._context); };\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(wrappedComplete);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, wrappedComplete);\n this.unsubscribe();\n }\n }\n else {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n this.unsubscribe();\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n }\n };\n SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {\n if (!config.useDeprecatedSynchronousErrorHandling) {\n throw new Error('bad call');\n }\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n parent.syncErrorValue = err;\n parent.syncErrorThrown = true;\n return true;\n }\n else {\n hostReportError(err);\n return true;\n }\n }\n return false;\n };\n SafeSubscriber.prototype._unsubscribe = function () {\n var _parentSubscriber = this._parentSubscriber;\n this._context = null;\n this._parentSubscriber = null;\n _parentSubscriber.unsubscribe();\n };\n return SafeSubscriber;\n}(Subscriber));\n//# sourceMappingURL=Subscriber.js.map\n\n/** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */\nfunction canReportError(observer) {\n while (observer) {\n var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;\n if (closed_1 || isStopped) {\n return false;\n }\n else if (destination && destination instanceof Subscriber) {\n observer = destination;\n }\n else {\n observer = null;\n }\n }\n return true;\n}\n//# sourceMappingURL=canReportError.js.map\n\n/** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */\nfunction toSubscriber(nextOrObserver, error, complete) {\n if (nextOrObserver) {\n if (nextOrObserver instanceof Subscriber) {\n return nextOrObserver;\n }\n if (nextOrObserver[rxSubscriber]) {\n return nextOrObserver[rxSubscriber]();\n }\n }\n if (!nextOrObserver && !error && !complete) {\n return new Subscriber(empty);\n }\n return new Subscriber(nextOrObserver, error, complete);\n}\n//# sourceMappingURL=toSubscriber.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nvar observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();\n//# sourceMappingURL=observable.js.map\n\n/** PURE_IMPORTS_START PURE_IMPORTS_END */\nfunction noop() { }\n//# sourceMappingURL=noop.js.map\n\n/** PURE_IMPORTS_START _noop PURE_IMPORTS_END */\nfunction pipeFromArray(fns) {\n if (!fns) {\n return noop;\n }\n if (fns.length === 1) {\n return fns[0];\n }\n return function piped(input) {\n return fns.reduce(function (prev, fn) { return fn(prev); }, input);\n };\n}\n//# sourceMappingURL=pipe.js.map\n\n/** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */\nvar Observable = /*@__PURE__*/ (function () {\n function Observable(subscribe) {\n this._isScalar = false;\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n Observable.prototype.lift = function (operator) {\n var observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n };\n Observable.prototype.subscribe = function (observerOrNext, error, complete) {\n var operator = this.operator;\n var sink = toSubscriber(observerOrNext, error, complete);\n if (operator) {\n sink.add(operator.call(sink, this.source));\n }\n else {\n sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?\n this._subscribe(sink) :\n this._trySubscribe(sink));\n }\n if (config.useDeprecatedSynchronousErrorHandling) {\n if (sink.syncErrorThrowable) {\n sink.syncErrorThrowable = false;\n if (sink.syncErrorThrown) {\n throw sink.syncErrorValue;\n }\n }\n }\n return sink;\n };\n Observable.prototype._trySubscribe = function (sink) {\n try {\n return this._subscribe(sink);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n sink.syncErrorThrown = true;\n sink.syncErrorValue = err;\n }\n if (canReportError(sink)) {\n sink.error(err);\n }\n else {\n console.warn(err);\n }\n }\n };\n Observable.prototype.forEach = function (next, promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var subscription;\n subscription = _this.subscribe(function (value) {\n try {\n next(value);\n }\n catch (err) {\n reject(err);\n if (subscription) {\n subscription.unsubscribe();\n }\n }\n }, reject, resolve);\n });\n };\n Observable.prototype._subscribe = function (subscriber) {\n var source = this.source;\n return source && source.subscribe(subscriber);\n };\n Observable.prototype[observable] = function () {\n return this;\n };\n Observable.prototype.pipe = function () {\n var operations = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n operations[_i] = arguments[_i];\n }\n if (operations.length === 0) {\n return this;\n }\n return pipeFromArray(operations)(this);\n };\n Observable.prototype.toPromise = function (promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var value;\n _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });\n });\n };\n Observable.create = function (subscribe) {\n return new Observable(subscribe);\n };\n return Observable;\n}());\nfunction getPromiseCtor(promiseCtor) {\n if (!promiseCtor) {\n promiseCtor = Promise;\n }\n if (!promiseCtor) {\n throw new Error('no Promise impl found');\n }\n return promiseCtor;\n}\n//# sourceMappingURL=Observable.js.map\n\nfunction tnLineStdinReader() {\n return new Observable(subscribe => {\n const stdin = readline.createInterface(process.stdin);\n let tests = null;\n let n = null;\n stdin.on('line', line => {\n if (tests === null) {\n tests = +line;\n } else if (n === null) {\n n = +line;\n tests--;\n } else {\n n = null;\n subscribe.next(line);\n\n if (tests === 0) {\n stdin.close();\n subscribe.complete();\n }\n }\n });\n });\n}\n\nfunction isHappy(arr) {\n if (arr[0] <= 0 || arr[arr.length - 1] <= 0) {\n return 'NO';\n }\n\n let sum = 0;\n\n for (let x = 0; x < arr.length - 1; x++) {\n sum += arr[x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n sum = 0;\n\n for (let x = arr.length - 1; x > 0; x--) {\n sum += arr[x];\n\n if (sum <= 0) {\n return 'NO';\n }\n }\n\n return 'YES';\n}\n\ntnLineStdinReader().subscribe(input => {\n const arr = input.split(' ').map(i => +i);\n console.log(isHappy(arr));\n});\n"}], "src_uid": "ae7c80e068e267673a5f910bb0b121ec"} {"source_code": "function solve(){\n var n;\n\nvar arr=[];\n\nn = +readline();\nfor(var i=0;i 0) \n {\n var is_solution_exist = true;\n\n // check every row & column\n var sum_main_diagonal = 0;\n var sum_secondary_diagonal = 0;\n for(var i = 0; i < n; i++) {\n\n var sumrow = 0;\n var sumcol = 0;\n\n for(var j = 0; j < n; j++) {\n\n sumrow += matrix[i][j];\n sumcol += matrix[j][i];\n }\n\n sum_main_diagonal += matrix[i][i];\n sum_secondary_diagonal += matrix[i][n - i - 1];\n\n if(sumrow !== supposedsum || sumcol !== supposedsum) {\n is_solution_exist = false;\n break;\n }\n }\n\n if(is_solution_exist) {\n //console.log(\"check sum of every diagonal\");\n //console.log(\"sum_main_diagonal: \" + sum_main_diagonal);\n //console.log(\"sum_secondary_diagonal: \" + sum_secondary_diagonal);\n // check if every diagonal\n is_solution_exist = sum_main_diagonal == supposedsum && sum_secondary_diagonal == supposedsum;\n }\n\n if(is_solution_exist)\n print(matrix[i0][j0]);\n else \n print(-1);\n }\n else\n print(-1);\n \n}"}, {"source_code": "function solve(){\n var n;\n\nvar arr=[];\n\nn = +readline();\nfor(var i=0;i we can take sum row or sum col, btw\n var sumrow0 = matrix[i0].reduce(function(prev, curr){\n return prev + curr;\n });\n \n // take any row for calculating guessed empty grid value\n var checkrow = i0 + 1;\n if(i0 === n - 1) { // check if empty grid on bottom edge\n checkrow = i0 - 1;\n }\n \n // calculate supposed sum\n supposedsum = matrix[checkrow].reduce(function(prev, curr){\n return prev + curr;\n });\n \n // calculate guessed value\n matrix[i0][j0] = supposedsum - sumrow0;\n \n // start checking\n if(matrix[i0][j0] > 0) // check if guessed value is positive integer\n {\n var is_solution_exist = true;\n var sum_main_diagonal = 0;\n var sum_secondary_diagonal = 0;\n \n // check every row & column\n for(var i = 0; i < n; i++) {\n\n var sumrow = 0;\n var sumcol = 0;\n\n for(var j = 0; j < n; j++) {\n\n sumrow += matrix[i][j];\n sumcol += matrix[j][i];\n }\n\n sum_main_diagonal += matrix[i][i];\n sum_secondary_diagonal += matrix[i][n - i - 1];\n\n if(sumrow !== supposedsum || sumcol !== supposedsum) {\n is_solution_exist = false;\n break;\n }\n }\n\n if(is_solution_exist) {\n // check every diagonal value compared to supposedsum\n is_solution_exist = sum_main_diagonal == supposedsum && sum_secondary_diagonal == supposedsum;\n }\n\n if(is_solution_exist)\n print(matrix[i0][j0]);\n else \n print(-1);\n }\n else\n print(-1);\n \n}"}], "negative_code": [{"source_code": "var n = parseInt(readline());\nvar i0; var j0;\nvar matrix = [];\n\nvar supposedsum = 0;\n\nfor(var i = 0; i < n; i++) {\n \n var j = 0;\n var row = readline().split(' ').map(function(x){ \n var num = parseInt(x);\n \n if(num === 0) {\n i0 = i;\n j0 = j;\n }\n \n j++;\n return num;\n });\n \n matrix.push(row);\n}\n\nif(n === 1) {\n print(1);\n} else {\n \n var sumrow0 = matrix[i0].reduce(function(prev, curr){\n return prev + curr;\n });\n \n // take any row for calculating guessed empty grid value\n var checkrow = i0 + 1;\n if(i0 === n - 1) { // check if empty grid on bottom edge\n checkrow = i0 - 1;\n }\n \n supposedsum = matrix[checkrow].reduce(function(prev, curr){\n return prev + curr;\n });\n \n //console.log(\"supposedsum: \" + supposedsum);\n \n matrix[i0][j0] = supposedsum - sumrow0;\n \n //console.log(\"matrix[i0][j0]: \" + matrix[i0][j0]);\n \n // start checking\n var is_solution_exist = true;\n \n // check every row & column\n var sum_main_diagonal = 0;\n var sum_secondary_diagonal = 0;\n for(var i = 0; i < n; i++) {\n \n var sumrow = 0;\n var sumcol = 0;\n \n for(var j = 0; j < n; j++) {\n \n sumrow += matrix[i][j];\n sumcol += matrix[j][i];\n }\n \n sum_main_diagonal += matrix[i][i];\n sum_secondary_diagonal += matrix[i][n - i - 1];\n \n if(sumrow !== supposedsum || sumcol !== supposedsum) {\n is_solution_exist = false;\n break;\n }\n }\n \n if(is_solution_exist) {\n //console.log(\"check sum of every diagonal\");\n //console.log(\"sum_main_diagonal: \" + sum_main_diagonal);\n //console.log(\"sum_secondary_diagonal: \" + sum_secondary_diagonal);\n // check if every diagonal\n is_solution_exist = sum_main_diagonal == supposedsum && sum_secondary_diagonal == supposedsum;\n }\n \n if(is_solution_exist)\n print(matrix[i0][j0]);\n else \n print(-1);\n \n}"}], "src_uid": "3bd5a228ed5faf997956570f96becd73"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// your code goes here\nlet input = \"\";\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n\tconst numbers = input.split(\"\\n\").filter(x => x.trim() !== \"\").filter((_, i) => i !== 0).map(Number);\n\tlet oddCount = (numbers.map(x => x % 2 !== 0).reduce((acc, cur) => acc + cur, 0)) / 2;\n\tfor (let i = 0; i < numbers.length; i++) {\n\t\tif (numbers[i] % 2 === 0) {\n\t\t\tnumbers[i] /= 2;\n\t\t\tcontinue;\n }\n\t\tif (numbers[i] % 2 !== 0) {\n\t\t\tif (oddCount > 0) {\n numbers[i]--;\n oddCount--;\n } else {\n\t\t\t\tnumbers[i]++;\n\t\t\t}\n\t\t\tnumbers[i] /= 2;\n\t\t}\n\t}\n\tconsole.log(numbers.join(\"\\n\"));\n});", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n\n let nF = false, pF = false\n for(let i = 0; i < n; i++) {\n let num = parseInt(arr[i])\n if(num % 2 == 0) console.log(num / 2)\n else if(num == 0) {\n console.log(0)\n }\n\n else if(num > 0) {\n if(pF) {\n console.log((num + 1) / 2)\n }\n else {\n console.log((num - 1) / 2)\n }\n pF = !pF\n }\n\n else {\n if(pF) {\n console.log((num + 1) / 2)\n }\n else {\n console.log((num - 1) / 2)\n }\n pF = !pF\n }\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet countStr = 0;\nconst dataArr = [];\n\nrl.on('line', (line) => {\n line = Number(line);\n if (!countStr) {\n countStr = line;\n return;\n }\n\n dataArr.push(line);\n if (dataArr.length === countStr) {\n start();\n }\n});\n\n\nfunction start() {\n let flag = true;\n for (let i of dataArr) {\n if (i % 2 === 0) {\n console.log(i / 2);\n continue;\n }\n\n let a;\n\n if (flag) {\n a = Math.floor(i / 2);\n } else {\n a = Math.ceil(i / 2);\n }\n\n if (a > -1 && a < 1) {\n a = 0;\n }\n console.log(a);\n\n flag = !flag;\n }\n\n rl.close();\n}\n"}, {"source_code": "var count = parseInt(readline());\n// var arr = [10, -5, -5]\n// var count = 3;\nvar balance = 0;\n\nfor (var i = 0; i < count; i++) {\n var curr = parseInt(readline());\n // var curr = arr[i]\n if (curr % 2 === 0) {\n write((curr / 2) + '\\n');\n }\n else if (balance) {\n balance = 0;\n write(Math.floor(curr / 2) + '\\n');\n } else {\n write(Math.ceil(curr / 2) + '\\n');\n balance = 1;\n }\n}"}, {"source_code": " var n = readline();\n\n var raing =[];\n var hadCorrection =[];\n var newRating =[];\n var sum = 0;\n \n for(var i=0;i=0;i--)\n {\n var temp = newRating[i];\n if((sum>0 && hadCorrection[i]<0)\n || sum<0 && hadCorrection[i]>0)\n {\n newRating[i] = newRating[i]+hadCorrection[i];\n sum += newRating[i]-temp;\n // print(\"new rating = \"+newRating[i]+\" Sum : \"+sum);\n }\n \n }\n \n\n for(var i=0;i parseInt(x));\n \n if(ar % 2 === 0) {\n print(ar / 2);\n \n } else if(f1) {\n print(Math.floor(ar / 2));\n f1 = false;\n \n } else {\n print(Math.ceil(ar / 2));\n f1 = true;\n }\n}\n\n//\n"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n \n// your code goes here\nlet input = \"\";\nprocess.stdin.on(\"data\", data => input += data);\nprocess.stdin.on(\"end\", () => {\n\tconsole.log(input.split('\\n').filter((_, i) => i !== 0).map(Number).map(x => x / 2).map(Math.round).join(\"\\n\"));\n});"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n')\n const n = parseInt(arr.shift())\n\n let nF = false, pF = false\n for(let i = 0; i < n; i++) {\n let num = parseInt(arr[i])\n if(num % 2 == 0) console.log(num / 2)\n else if(num == 0) {\n console.log(0)\n }\n\n else if(num > 0) {\n if(pF) {\n console.log(Math.floor(num / 2))\n }\n else {\n console.log(Math.ceil(num / 2))\n }\n pF = !pF\n }\n\n else {\n if(pF) {\n console.log(Math.floor(num / 2))\n }\n else {\n console.log(Math.ceil(num / 2))\n }\n pF = !pF\n }\n }\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet countStr = 0;\nconst dataArr = [];\n\nrl.on('line', (line) => {\n line = Number(line);\n if (!countStr) {\n countStr = line;\n return;\n }\n\n dataArr.push(line);\n if (dataArr.length === countStr) {\n start();\n }\n});\n\n\nfunction start() {\n let flag = true;\n for (let i of dataArr) {\n if (i % 2 === 0) {\n console.log(i / 2);\n continue;\n }\n\n if (flag) {\n console.log(Math.floor(i / 2));\n } else {\n console.log(Math.ceil(i / 2));\n }\n\n flag = !flag;\n }\n\n rl.close();\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet countStr = 0;\nconst dataArr = [];\n\nrl.on('line', (line) => {\n line = Number(line);\n if (!countStr) {\n countStr = line;\n return;\n }\n\n dataArr.push(line);\n if (dataArr.length === countStr) {\n start();\n }\n});\n\n\nfunction start() {\n let flag = false;\n for (let i of dataArr) {\n if (i % 2 === 0) {\n console.log(i / 2);\n continue;\n }\n\n if (flag) {\n console.log(Math.floor(i / 2));\n } else {\n console.log(Math.ceil(i / 2));\n }\n\n flag = !flag;\n }\n\n rl.close();\n}\n"}], "src_uid": "3545385c183c29f9b95aa0f02b70954f"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [l, r, x] = rns(),\r\n [a, b] = rns();\r\n if (a === b) return 0;\r\n if (Math.abs(a - b) >= x) return 1;\r\n if (a - l < x && r - a < x) return -1;\r\n if (b - l < x && r - b < x) return -1;\r\n if (a - l >= x) {\r\n if (b - l >= x) return 2;\r\n }\r\n if (r - a >= x) {\r\n if (r - b >= x) return 2;\r\n }\r\n return 3;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nfunction solve([l, r, x], [a, b]) {\r\n if (a === b) {\r\n return 0\r\n }\r\n \r\n if (Math.abs(l - r) < x) {\r\n return -1;\r\n }\r\n \r\n if (Math.abs(a - b) >= x) {\r\n return 1;\r\n }\r\n \r\n if (a > b) {\r\n var tmp = a;\r\n a = b;\r\n b = tmp;\r\n }\r\n \r\n if (r - b >= x || a - l >= x) {\r\n return 2;\r\n }\r\n \r\n if (r - a >= x && b - l >= x) {\r\n return 3;\r\n }\r\n \r\n return -1;\r\n}\r\n\r\nfunction main() {\r\n const numOfCases = rlsn();\r\n \r\n for (let testCase = 0; testCase < numOfCases; testCase++) {\r\n const l1 = rlarrn();\r\n const l2 = rlarrn();\r\n \r\n const res = solve(l1, l2);\r\n cl(res);\r\n }\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inStr = '';\r\nlet curLine = 0;\r\nconst cl = console.log;\r\n\r\nprocess.stdin.on('data', function(inStdin) {inStr += inStdin;});\r\nprocess.stdin.on('end', function() {inStr = inStr.split('\\n');main();});\r\n\r\nfunction readline() {return inStr[curLine++].replace(/\\s+$/g, '');}\r\nfunction rlsn() {return Number(readline());}\r\nfunction rlarrstr() {return readline().split(' ');}\r\nfunction rlarrn() {return rlarrstr().map(Number);}\r\nfunction makeFreqMap(str) {const m={};for (let char of str) m[char]=m[char]+1||1;return m;}\r\n\r\n\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [left, right, x] = lines[l++].trim().split(' ').map(Number)\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(left, right, x, a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(l, r, x, a, b) {\n if (a === b) return 0\n if (b >= a + x || b <= a - x) return 1\n if (b < a) {\n if (a + x <= r || b - x >= l) return 2\n if (a - x >= l && b + x <= r) return 3\n return -1\n } else {\n if (a - x >= l || b + x <= r) return 2\n if (a + x <= r && b - x >= l) return 3\n return -1\n }\n}\n"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var firstLine = readline().split(' ').map(Number);\r\n var l = firstLine[0];\r\n var r = firstLine[1];\r\n var x = firstLine[2];\r\n \r\n var secondLine = readline().split(' ').map(Number);\r\n var a = secondLine[0];\r\n var b = secondLine[1];\r\n \r\n var result = process(l, r, x, a, b);\r\n print(result);\r\n}\r\n\r\nfunction process(l, r, x, a, b) {\r\n if (a === b) {\r\n return 0\r\n }\r\n \r\n if (Math.abs(l - r) < x) {\r\n return -1;\r\n }\r\n \r\n if (Math.abs(a - b) >= x) {\r\n return 1;\r\n }\r\n \r\n if (a > b) {\r\n var tmp = a;\r\n a = b;\r\n b = tmp;\r\n }\r\n \r\n if (r - b >= x || a - l >= x) {\r\n return 2;\r\n }\r\n \r\n if (r - a >= x && b - l >= x) {\r\n return 3;\r\n }\r\n \r\n return -1;\r\n}"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [l, r, x] = rns(),\r\n [a, b] = rns();\r\n if (a === b) return 0;\r\n if (Math.abs(a - b) >= x) return 1;\r\n if (a - l < x && r - a < x) return -1;\r\n if (b - l < x && r - b < x) return -1;\r\n if (a - l > x) {\r\n if (b - l > x) return 2;\r\n }\r\n if (r - a > x) {\r\n if (r - b > x) return 2;\r\n }\r\n return 3;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "e3a1f53f78fcb3a551c3ae1cbeedaf15"} {"source_code": "function splitInput(i) {\r\n return i.split('\\n')\r\n}\r\n\r\nfunction splitLine(l) {\r\n return l.split(' ').map((e) => +e)\r\n}\r\n\r\nprocess.stdin.resume()\r\nprocess.stdin.setEncoding('utf-8')\r\n\r\nlet input = ''\r\n\r\nprocess.stdin.on('data', (i) => {\r\n input += i\r\n})\r\n\r\nprocess.stdin.on('end', () => {\r\n const lines = splitInput(input.trim())\r\n run(lines.map((l) => splitLine(l)))\r\n})\r\n\r\nfunction output(o) {\r\n process.stdout.write(`${o}\\n`)\r\n}\r\n\r\nfunction run(lines) {\r\n let iterator = 0\r\n let [n, m] = lines[iterator++]\r\n const inDegrees = Array(n + 1).fill(0)\r\n inDegrees[0] = null\r\n let nodesWithInDegreeZero = n\r\n\r\n while (m > 0) {\r\n --m\r\n const [nodeA, nodeB] = lines[iterator++]\r\n const minNode = Math.min(nodeA, nodeB)\r\n if (inDegrees[minNode] === 0) {\r\n --nodesWithInDegreeZero\r\n }\r\n ++inDegrees[minNode]\r\n }\r\n\r\n let [q] = lines[iterator++]\r\n while (q > 0) {\r\n --q\r\n const [type, nodeA, nodeB] = lines[iterator++]\r\n switch (type) {\r\n case 1: {\r\n const minNode = Math.min(nodeA, nodeB)\r\n if (inDegrees[minNode] === 0) {\r\n --nodesWithInDegreeZero\r\n }\r\n ++inDegrees[minNode]\r\n }\r\n break\r\n case 2: {\r\n const minNode = Math.min(nodeA, nodeB)\r\n if (inDegrees[minNode] === 1) {\r\n ++nodesWithInDegreeZero\r\n }\r\n --inDegrees[minNode]\r\n }\r\n break\r\n case 3: {\r\n output(nodesWithInDegreeZero)\r\n }\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "\r\nconst main = () => {\r\n\t\r\n\tvar n, m;\r\n\tvar _in = readIntArr();\r\n\tn = _in[0];\r\n\tm = _in[1];\r\n\tvar maxCnts = n;\r\n\tvar largerCnts = [];\r\n\tfor (var i = 0; i < n + 1; i++) {\r\n\t\tlargerCnts.push(0);\r\n\t}\r\n\tfor (var _ = 0; _ < m; _++) {\r\n\t\t_in = readIntArr();\r\n\t\tvar u = _in[0];\r\n\t\tvar v = _in[1];\r\n\t\tif (u > v) {\r\n\t\t\tvar temp = v;\r\n\t\t\tv = u;\r\n\t\t\tu = temp;\r\n\t\t}\r\n\t\tif (++largerCnts[u] === 1) {\r\n\t\t\tmaxCnts--;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvar q = readInt();\r\n\tvar allans = [];\r\n\tfor (var _ = 0; _ < q; _++) {\r\n\t\t_in = readIntArr();\r\n\t\tif (_in.length === 1) { // 3\r\n\t\t\tallans.push(maxCnts);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tvar x, u, v;\r\n\t\tx = _in[0];\r\n\t\tu = _in[1];\r\n\t\tv = _in[2];\r\n\t\tif (u > v) {\r\n\t\t\tvar temp = v;\r\n\t\t\tv = u;\r\n\t\t\tu = temp;\r\n\t\t}\r\n\t\tif (x === 2) {\r\n\t\t\tif (--largerCnts[u] === 0) {\r\n\t\t\t\tmaxCnts++;\r\n\t\t\t}\r\n\t\t} else { // x === 1\r\n\t\t\tif (++largerCnts[u] === 1) {\r\n\t\t\t\tmaxCnts--;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tmultiLineArrayPrint(allans);\r\n\t\r\n\treturn;\r\n}\r\n\r\nconst readInt = () => parseInt(readline());\r\nconst readString = () => readline();\r\nconst readIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\nconst parseLong = (string) => { // javascript's largest long is < (1<<62)\r\n\tvar n = string.length;\r\n\tvar res = 0;\r\n\tfor (var i = 0; i < n; i++) {\r\n\t\tres *= 10;\r\n\t\tres += parseInt(string[i]);\r\n\t}\r\n\treturn res;\r\n}\r\nconst readLong = () => parseLong(readLong());\r\nconst readLongArr = () => readline().split(\" \").map(zzzz => parseLong(zzzz));\r\nconst oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nconst multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nconst multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\nconst makeArr = (defaultVal, dimensionsArr) => {\r\n\tvar n = dimensionsArr.length;\r\n\tif (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);\r\n\telse {\r\n\t\tvar temp = [];\r\n\t\tfor (var i = 0; i < dimensionsArr[0]; i++)\r\n\t\t\ttemp.push(makeArr(defaultVal, dimensionsArr.slice(1)));\r\n\t\treturn temp;\r\n\t}\r\n}\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword. use \"var\" instead\r\n// codeforces js cannot destructure arrays"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction printline(s, end = \"\\n\") {\r\n process.stdout.write(s + end);\r\n}\r\n\r\nlet alive = 0;\r\nconst under = [];\r\nconst upper = [];\r\n\r\nfunction main() {\r\n const [n, m] = readline().split(' ').map((rl) => parseInt(rl, 10));;\r\n\r\n for (let i = 0; i <= n; ++i) {\r\n upper.push(0);\r\n under.push(0);\r\n }\r\n alive = n;\r\n\r\n for (let i = 1; i <= m; ++i) {\r\n const [u, v] = readline().split(' ').map((rl) => parseInt(rl, 10));\r\n if (upper[Math.min(u, v)] === 0) alive--;\r\n upper[Math.min(u, v)]++;\r\n under[Math.max(u, v)]++;\r\n }\r\n\r\n let q = parseInt(readline(), 10);\r\n while (q--) {\r\n const query = readline().split(' ').map((rl) => parseInt(rl, 10));\r\n if (query.length === 1) {\r\n printline(alive);\r\n } else {\r\n const u = query[1];\r\n const v = query[2];\r\n if (query[0] === 1) {\r\n if (upper[Math.min(u, v)] === 0) alive--;\r\n upper[Math.min(u, v)]++;\r\n under[Math.max(u, v)]++;\r\n } else {\r\n upper[Math.min(u, v)]--;\r\n if (upper[Math.min(u, v)] === 0) alive++;\r\n under[Math.max(u, v)]--;\r\n }\r\n }\r\n \r\n }\r\n\r\n}\r\n\r\n// run: cat input.txt | node C.js"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const [n, m] = readline().split(' ').map(x => parseInt(x));\r\n const deg = [];\r\n for(let i = 0; i < n; i++) {\r\n deg.push(0)\r\n }\r\n for(let i = 0; i < m; i++) {\r\n const [u, v] = readline().split(' ').map(x => parseInt(x));\r\n deg[Math.min(u-1, v-1)]++;\r\n }\r\n let ans = 0\r\n for(let i = 0; i < n; i++) {\r\n if(deg[i] === 0) {\r\n ans++;\r\n }\r\n }\r\n const show = (deg) => console.log(...deg)\r\n const q = parseInt(readline())\r\n for(let i = 0; i < q; i++) {\r\n const query = readline().split(' ').map(x => parseInt(x));\r\n if(query[0] === 3) {\r\n console.log(ans)\r\n } else {\r\n const who = Math.min(query[1]-1, query[2]-1)\r\n if(query[0] === 1) {\r\n deg[who]++;\r\n if(deg[who] === 1) {\r\n ans--\r\n }\r\n } else {\r\n deg[who]--;\r\n if(deg[who] === 0) {\r\n ans++\r\n }\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = 1e9 + 7\r\n\r\nfunction main() {\r\n // Array(Number(xx)).fill(1).map((t, i) => {\r\n var [n, m] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var a = new Array(n)\r\n // for (let i = 0; i <; i++) {\r\n //\r\n // }\r\n var alive = new Array(n).fill(true)\r\n var willDie = new Array(n).fill(false)\r\n var count = new Array(n).fill(0)\r\n for (let i = 0; i < m; i++) {\r\n var [u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n if (u > v) {\r\n var swap = u\r\n u = v\r\n v = swap\r\n }\r\n\r\n u--\r\n v--\r\n willDie[Math.min(u, v)] = true\r\n count[u]++\r\n }\r\n var res = 0\r\n for (let i = 0; i < n; i++) {\r\n if (!willDie[i]) res++\r\n }\r\n var q = parseInt(readline());\r\n\r\n for (let i = 0; i < q; i++) {\r\n var [req, u, v] = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n u--\r\n v--\r\n\r\n if (u > v) {\r\n var swap = u\r\n u = v\r\n v = swap\r\n }\r\n if (req === 3) {\r\n console.log(res)\r\n }\r\n if (req === 2) {\r\n count[u]--\r\n if (count[u] === 0) res++\r\n }\r\n if (req === 1) {\r\n count[u]++\r\n if (count[u] === 1) res--\r\n }\r\n }\r\n // })\r\n // var res = new Array(n)\r\n}\r\n\r\nfunction plus(a, b, res) {\r\n// console.log(a, b, res)\r\n if (a === 0) return res\r\n\r\n return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)\r\n}\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, m] = rna();\r\n\r\n\tconst deg = Array(n+1).fill(0);\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tconst [u, v] = rna();\r\n\t\t++deg[Math.min(u, v)];\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tfor (let u = 1; u <= n; u++) {\r\n\t\tans += deg[u] == 0\r\n\t}\r\n\r\n\tlet q = rn();\r\n\twhile (q--) {\r\n\t\tconst [op, u, v] = rna();\r\n\r\n\t\tif (op == 1) {\r\n\t\t\tif (++deg[Math.min(u, v)] == 1) ans--;\r\n\t\t} else if (op == 2) {\r\n\t\t\tif (--deg[Math.min(u, v)] == 0) ans++;\r\n\t\t} else {\r\n\t\t\tconsole.log(ans);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tconst [n, m] = rna();\r\n\tconst adj = Array.from(Array(n+1), x => []);\r\n\tconst cnt = Array(n+1).fill(0);\r\n\tfor (let i = 0; i < m; i++) {\r\n\t\tlet [u, v] = rna();\r\n\t\tadj[u].push(v);\r\n\t\tadj[v].push(u);\r\n\t\t++cnt[Math.min(u, v)];\r\n\t}\r\n\r\n\tlet ans = 0;\r\n\tfor (let u = 1; u <= n; u++) {\r\n\t\tans += cnt[u] == 0\r\n\t}\r\n\r\n\tlet q = rn();\r\n\twhile (q--) {\r\n\t\tlet [type, u, v] = rna();\r\n\r\n\t\tif (type == 1) {\r\n\t\t\tif (++cnt[Math.min(u, v)] == 1) {\r\n\t\t\t\tans--;\r\n\t\t\t}\r\n\t\t} else if (type == 2) {\r\n\t\t\tif (--cnt[Math.min(u, v)] == 0) {\r\n\t\t\t\tans++;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log(ans);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction printline(s, end = \"\\n\") {\r\n process.stdout.write(s + end);\r\n}\r\n\r\nlet alive = 0;\r\nconst under = [];\r\nconst upper = [];\r\n\r\nfunction main() {\r\n const [n, m] = readline().split(' ').map((rl) => parseInt(rl, 10));;\r\n\r\n for (let i = 0; i <= n; ++i) {\r\n upper.push(0);\r\n under.push(0);\r\n }\r\n alive = n;\r\n\r\n for (let i = 1; i <= m; ++i) {\r\n const [u, v] = readline().split(' ').map((rl) => parseInt(rl, 10));\r\n if (upper[Math.min(u, v)] === 0) alive--;\r\n upper[Math.min(u, v)]++;\r\n under[Math.max(u, v)]++;\r\n }\r\n\r\n let q = parseInt(readline(), 10);\r\n while (q--) {\r\n const query = readline().split(' ').map((rl) => parseInt(rl, 10));\r\n if (query.length === 1) {\r\n printline(alive);\r\n } else {\r\n const u = query[1];\r\n const v = query[2];\r\n if (query[0] === 1) {\r\n if (upper[Math.min(u, v)] === 0) alive--;\r\n upper[Math.min(u, v)]++;\r\n under[Math.max(u, v)]++;\r\n } else {\r\n upper[Math.min(u, v)]--;\r\n if (upper[Math.min(u, v)] === 0) alive--;\r\n under[Math.max(u, v)]--;\r\n }\r\n }\r\n \r\n }\r\n\r\n}\r\n\r\n// run: cat input.txt | node C.js"}], "src_uid": "49009175bae8537e6d51424fab28183a"} {"source_code": "function getNearestNotNofiedStudent(students) {\n for (var i = 0; i < students.length; i++) {\n if (students[i].notified === false) {\n return students[i];\n }\n }\n\n return null;\n}\n\nfunction run(students) {\n // print('hello!');\n\n students = students.map(function (student) {\n student.notified = false;\n return student;\n });\n\n var polikarp = students[0];\n\n polikarp.notified = true;\n\n if (polikarp.limit === 0) {\n // print('polikarp');\n return -1;\n }\n\n var overallLimit = students.reduce(function (acc, student) {\n return acc + student.limit;\n }, 0);\n\n if (students.length > overallLimit + 1) {\n // print('students');\n return -1;\n }\n\n students = students.sort(function (left, right) {\n if (left.notified) {\n return -1;\n }\n\n if (right.notified) {\n return 1;\n }\n\n if (left.limit === right.limit) {\n return 0;\n }\n\n return left.limit < right.limit ? 1 : -1;\n });\n\n var messages = [];\n\n for (var i = 0; i < students.length; i++) {\n var currentStudent = students[i];\n while (currentStudent.limit > 0) {\n var notNotifiedStudent = getNearestNotNofiedStudent(students);\n if (notNotifiedStudent === null) {\n break;\n }\n notNotifiedStudent.notified = true;\n currentStudent.limit--;\n messages.push({\n from: currentStudent.number,\n to: notNotifiedStudent.number\n });\n }\n }\n\n return (\n messages.length + \"\\n\" +\n messages.reduce(function (acc, message) {\n return acc + message.from + ' ' + message.to + \"\\n\";\n }, '')\n );\n}\n\nvar count = readline();\nvar students = readline()\n .split(' ')\n .map(function (a) { return parseInt(a); })\n .map(function (limit, number) {\n return { limit: limit, number: number + 1 };\n });\n\nvar result = run(students);\nprint(result);\n", "positive_code": [{"source_code": "function main() {\n var col = +readline();\n var nums = readline().split(\" \");\n var procof = nums[0];\n if (procof < 1) {\n print(-1);\n return 0;\n }\n var canSend = 0;\n nums = nums.slice(1).map(function (x, i) {\n canSend += +x;\n return [+x, i+2, 0];\n });\n\n if ((+canSend + +procof) < +(col-1)) {\n print(-1);\n return 0;\n }\n nums.sort((a, b) => b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n print(numbers.length -1);\n numbers.slice(1).forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "readline();\n\nvar tmp_i = 1;\nvar maxes = readline().split(' ').map(function(x){\n \n return [tmp_i++, parseInt(x)];\n});\nvar queue = [maxes.shift()];\nvar log = [];\n\nmaxes.sort(function(a, b){\n \n return b[1] - a[1];\n});\n\nwhile (queue.length > 0) {\n \n var std = queue[0][0];\n var cap = queue[0][1];\n \n for(var i = 0; i < cap; i++) {\n\n if(maxes.length > 0) { \n log.push([std, maxes[0][0]]);\n queue.push(maxes.shift());\n }\n else\n break;\n }\n \n queue.shift();\n}\n\nif(maxes.length === 0) {\n \n print(log.length);\n for(var i = 0; i < log.length; i++)\n print(log[i].join(' '));\n} else \n print(-1);"}, {"source_code": "(function(){\nvar n = readline() >> 0;\nfunction cmp(a,b) {\n\tif (a[0]b[0]) return -1;\n return 0;\n}\nvar a = readline().split(' ').map(function(x, i){return [x >> 0, i];});\nvar a0 = a[0][0];\nif (a0 == 0) {\n\tprint(-1);\n return 0;\n}\na[0][0] = 101;\na.sort(cmp);\na[0][0] = a0;\nvar k = 1;\nvar c = 0;\nvar m = []\nwhile (k < n && c < n) {\n\tfor (var i=k, j=0; (i b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n print(numbers.length -1);\n numbers.slice(1).forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "var peoplesCount = readline();\nvar peoples = readline()\n .split(' ')\n .map(function(count) {\n return { available: count };\n });\n\npeoples[0].isKnow = true;\nif (!peoples[0].available && peoples.length > 1) print(-1);\nelse calculate(peoples);\n\nfunction getUnknownIndex(peoplesArr) {\n var max = 0;\n var ind = -1;\n\n for (var i = 0; i < peoplesArr.length; i++) {\n if (!peoplesArr[i].isKnow && peoplesArr[i].available >=max) {\n max = peoplesArr[i].available;\n ind = i;\n }\n }\n return ind;\n}\n\nfunction say(resultArray, peoplesArr, unknownPeopleIndex) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (peoplesArr[i].available > 0 && peoplesArr[i].isKnow) {\n peoplesArr[i].available--;\n peoplesArr[unknownPeopleIndex].isKnow = true;\n resultArray.push([ i+1, unknownPeopleIndex + 1 ]);\n return true;\n }\n }\n return false;\n}\n\nfunction calculate(peoplesArr) {\n var result = [];\n for (var i = 0; i < peoplesArr.length - 1; i++ ) {\n var unknownIndex = getUnknownIndex(peoplesArr);\n if (unknownIndex == -1) {\n print(-1);\n return;\n }\n if (!say(result, peoplesArr, unknownIndex)) {\n print(-1);\n return;\n }\n }\n print(result.length);\n result.forEach(function(item) {\n print(item.join(' '));\n })\n}"}, {"source_code": "/*\nreadline()\nprint\n*/\n\nvar iamdone = false;\nvar strings = [];\nvar n = +((readline() + \"\").trim());\nvar a = (readline() + \"\").trim().split(\" \");\na = a.map((v, i) => {\n return {\n i: i + 1,\n v: +v,\n c: false\n }\n}).sort(function(a, b){\n if(a.v > b.v) return -1; else return 1;\n return 0;\n});\n\nfor(var i = 0; i < n; i++){\n if(a[i].i === 1){\n if(a[i].v === 0){\n iamdone = true;\n }else{\n a[i].v--;\n a[i].c = true;\n }\n break;\n }\n}\n\nif(iamdone){\n print(\"-1\");\n}else{\n if(a[0].i == 1){\n a[1].c = true;\n strings[strings.length] = \"1 \" + a[1].i;\n }else{\n a[0].c = true;\n strings[strings.length] = \"1 \" + a[0].i;\n }\n \n \n var link1 = 0;\n var link2 = 0;\n \n while(true){\n if(a[link1].v > 0 && a[link2].c === false){\n a[link1].v--;\n a[link2].c = true;\n strings[strings.length] = a[link1].i + \" \" + a[link2].i;\n link2++;\n }else if(a[link1].v <= 0){\n link1++;\n }else if(a[link2].c === true){\n link2++;\n }\n \n if(!a[link1] || !a[link2]){\n break;\n }\n }\n \n var error = false;\n \n for(var i = 0; i < n; i++){\n if(a[i].c === false){\n error = true;\n break;\n }\n }\n \n if(error){\n print(\"-1\");\n }else{\n print(strings.length);\n for(var i = 0; i < strings.length; i++){\n print(strings[i]);\n }\n }\n \n}\n\n"}], "negative_code": [{"source_code": "function main() {\n var col = +readline();\n var nums = readline().split(\" \");\n var procof = nums[0];\n if (procof < 1) {\n print(-1);\n return 0;\n }\n var canSend = 0;\n nums = nums.slice(1).map(function (x, i) {\n canSend += +x;\n return [+x, i+2, 0];\n });\n\n if (+canSend < +col-1) {\n print(-1);\n return 0;\n }\n nums.sort((a, b) => b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n numbers = numbers.slice(1).sort((a, b) => a[2] - b[2]);\n print(numbers.length);\n numbers.forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "function main() {\n var col = +readline();\n var nums = readline().split(\" \");\n var procof = nums[0];\n if (procof < 1) {\n print(-1);\n return 0;\n }\n var canSend = 0;\n nums = nums.slice(1).map(function (x, i) {\n canSend += +x;\n return [+x, i+2, 0];\n });\n\n if (+canSend < +col-1) {\n print(-1);\n return 0;\n }\n nums.sort((a, b) => b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n print(numbers.length);\n numbers.slice(1).forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "function main() {\n var col = +readline();\n var nums = readline().split(\" \");\n var procof = nums[0];\n if (procof < 1) {\n print(-1);\n return 0;\n }\n var canSend = 0;\n nums = nums.slice(1).map(function (x, i) {\n canSend += +x;\n return [+x, i+2, 0];\n });\n if (+canSend < +col) {\n print(-1);\n return 0;\n }\n nums.sort((a, b) => b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n numbers = numbers.slice(1).sort((a, b) => a[2] - b[2]);\n print(numbers.length);\n numbers.forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "function main() {\n var col = +readline();\n var nums = readline().split(\" \");\n var procof = nums[0];\n if (procof < 1) {\n print(-1);\n return 0;\n }\n var canSend = 0;\n \n nums = nums.slice(1).map(function (x, i) {\n canSend += x;\n return [+x, i+2, 0];\n });\n if (canSend < col) {\n print(-1);\n return 0;\n }\n nums.sort((a, b) => b[0] - a[0]);\n var numbers = [[procof, 1], ...nums];\n\n var next = 1;\n for (var i = 0; i < col; ++i) {\n var mes = +numbers[i][0];\n for (var j = next; j < next + mes; ++j) {\n if (numbers[j]) numbers[j][2] = numbers[i][1];\n }\n next += mes;\n }\n \n numbers = numbers.slice(1).sort((a, b) => a[2] - b[2]);\n print(numbers.length);\n numbers.forEach(number => print(number[2] + \" \" + number[1]));\n\n return 0;\n}\n\nmain();"}, {"source_code": "var peoplesCount = readline();\nvar peoples = readline()\n .split(' ')\n .map(function(count) {\n return { available: count };\n });\n\npeoples[0].isKnow = true;\n\nif (!peoples[0].available) print(-1);\nelse calculate(peoples);\n\n\nfunction getUnknownIndex(peoplesArr) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (!peoplesArr[i].isKnow) return i;\n }\n return -1;\n}\n\nfunction say(resultArray, peoplesArr, unknownPeopleIndex) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (peoplesArr[i].available > 0) {\n peoplesArr[i].available--;\n peoplesArr[unknownPeopleIndex].isKnow = true;\n resultArray.push([ i+1, unknownPeopleIndex + 1 ]);\n return;\n }\n }\n}\n\nfunction calculate(peoplesArr) {\n var result = [];\n for (var i = 0; i < peoplesArr.length - 1; i++ ) {\n var unknownIndex = getUnknownIndex(peoplesArr);\n if (unknownIndex == -1) {\n print(-1);\n return;\n }\n say(result, peoplesArr, unknownIndex);\n }\n print(result.length);\n result.forEach(function(item) {\n print(item.join(' '));\n })\n}"}, {"source_code": "var peoplesCount = readline();\nvar peoples = readline()\n .split(' ')\n .map(function(count) {\n return { available: count };\n });\n\npeoples[0].isKnow = true;\nif (!peoples[0].available) print(-1);\nelse calculate(peoples);\n\nfunction getUnknownIndex(peoplesArr) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (!peoplesArr[i].isKnow) return i;\n }\n return -1;\n}\n\nfunction say(resultArray, peoplesArr, unknownPeopleIndex) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (peoplesArr[i].available > 0) {\n peoplesArr[i].available--;\n peoplesArr[unknownPeopleIndex].isKnow = true;\n resultArray.push([ i+1, unknownPeopleIndex + 1 ]);\n return true;\n }\n }\n return false;\n}\n\nfunction calculate(peoplesArr) {\n var result = [];\n for (var i = 0; i < peoplesArr.length - 1; i++ ) {\n var unknownIndex = getUnknownIndex(peoplesArr);\n if (unknownIndex == -1) {\n print(-1);\n return;\n }\n if (!say(result, peoplesArr, unknownIndex)) {\n print(-1);\n return;\n }\n }\n print(result.length);\n result.forEach(function(item) {\n print(item.join(' '));\n })\n}"}, {"source_code": "var peoplesCount = readline();\nvar peoples = readline()\n .split(' ')\n .map(function(count) {\n return { available: count };\n });\n\npeoples[0].isKnow = true;\n\ncalculate(peoples);\n\n\nfunction getUnknownIndex(peoplesArr) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (!peoplesArr[i].isKnow) return i;\n }\n return -1;\n}\n\nfunction say(resultArray, peoplesArr, unknownPeopleIndex) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (peoplesArr[i].available > 0) {\n peoplesArr[i].available--;\n peoplesArr[unknownPeopleIndex].isKnow = true;\n resultArray.push([ i+1, unknownPeopleIndex + 1 ]);\n return;\n }\n }\n}\n\nfunction calculate(peoplesArr) {\n var result = [];\n for (var i = 0; i < peoplesArr.length - 1; i++ ) {\n var unknownIndex = getUnknownIndex(peoplesArr);\n if (unknownIndex == -1) {\n print(-1);\n return;\n }\n say(result, peoplesArr, unknownIndex);\n }\n print(result.length);\n result.forEach(function(item) {\n print(item.join(' '));\n })\n}"}, {"source_code": "var peoplesCount = readline();\nvar peoples = readline()\n .split(' ')\n .map(function(count) {\n return { available: count };\n });\n\npeoples[0].isKnow = true;\nif (!peoples[0].available) print(-1);\nelse calculate(peoples);\n\nfunction getUnknownIndex(peoplesArr) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (!peoplesArr[i].isKnow) return i;\n }\n return -1;\n}\n\nfunction say(resultArray, peoplesArr, unknownPeopleIndex) {\n for (var i = 0; i < peoplesArr.length; i++) {\n if (peoplesArr[i].available > 0 && peoplesArr[i].isKnow) {\n peoplesArr[i].available--;\n peoplesArr[unknownPeopleIndex].isKnow = true;\n resultArray.push([ i+1, unknownPeopleIndex + 1 ]);\n return true;\n }\n }\n return false;\n}\n\nfunction calculate(peoplesArr) {\n var result = [];\n for (var i = 0; i < peoplesArr.length - 1; i++ ) {\n var unknownIndex = getUnknownIndex(peoplesArr);\n if (unknownIndex == -1) {\n print(-1);\n return;\n }\n if (!say(result, peoplesArr, unknownIndex)) {\n print(-1);\n return;\n }\n }\n print(result.length);\n result.forEach(function(item) {\n print(item.join(' '));\n })\n}"}, {"source_code": "/*\nreadline()\nprint\n*/\n\nvar iamdone = false;\nvar strings = [];\nvar n = +((readline() + \"\").trim());\nvar a = (readline() + \"\").trim().split(\" \");\na = a.map((v, i) => {\n return {\n i: i + 1,\n v: v,\n c: false\n }\n}).sort(function(a, b){\n if(a.v > b.v) return -1; else return 1;\n return 0;\n});\n\nfor(var i = 0; i < n; i++){\n if(a[i].i === 1){\n if(a[i].v === 0){\n iamdone = true;\n }else{\n a[i].v--;\n a[i].c = true;\n }\n }\n}\n\nif(iamdone){\n print(\"-1\");\n}else{\n if(a[0].i == 1){\n a[1].c = true;\n strings[strings.length] = \"1 \" + a[1].i;\n }else{\n a[0].c = true;\n strings[strings.length] = \"1 \" + a[0].i;\n }\n \n \n var link1 = 0;\n var link2 = 0;\n \n while(true){\n if(a[link1].v > 0 && a[link2].c === false){\n a[link1].v--;\n a[link2].c = true;\n strings[strings.length] = a[link1].i + \" \" + a[link2].i;\n link2++;\n }else if(a[link1].v <= 0){\n link1++;\n }else if(a[link2].c === true){\n link2++;\n }\n \n if(!a[link1] || !a[link2]){\n break;\n }\n }\n \n var error = false;\n \n for(var i = 0; i < n; i++){\n if(a[i].c === false){\n error = true;\n break;\n }\n }\n \n if(error){\n print(\"-1\");\n }else{\n print(strings.length);\n for(var i = 0; i < strings.length; i++){\n print(strings[i]);\n }\n }\n \n}\n\n"}, {"source_code": "/*\nreadline()\nprint\n*/\n\nvar iamdone = false;\nvar strings = [];\nvar n = +((readline() + \"\").trim());\nvar a = (readline() + \"\").trim().split(\" \").map((v, i) => {\n var c = false;\n if(i === 0){\n v--;\n c = true;\n if(v < 0) iamdone = true;\n }\n return {\n i: i + 1,\n v: v,\n c: c\n }\n}).sort(function(a, b){\n if(a.v > b.v) return -1; else return 1;\n return 0;\n});\n\nif(iamdone){\n print(\"-1\");\n}else{\n a[0].c = true;\n strings[strings.length] = \"1 \" + a[0].i;\n \n var link1 = 0;\n var link2 = 0;\n \n while(true){\n if(a[link1].v > 0 && a[link2].c === false){\n a[link1].v--;\n a[link2].c = true;\n strings[strings.length] = a[link1].i + \" \" + a[link2].i;\n link2++;\n }else if(a[link1].v <= 0){\n link1++;\n }else if(a[link2].c === true){\n link2++;\n }\n \n if(!a[link1] || !a[link2]){\n break;\n }\n }\n \n var error = false;\n \n for(var i = 0; i < n; i++){\n if(a[i].c === false){\n error = true;\n break;\n }\n }\n \n if(error){\n print(\"-1\");\n }else{\n print(strings.length);\n for(var i = 0; i < strings.length; i++){\n print(strings[i]);\n }\n }\n \n}\n\n"}, {"source_code": "function getNearestNotNofiedStudent(students) {\n for (var i = 0; i < students.length; i++) {\n if (students[i].notified === false) {\n return students[i];\n }\n }\n\n return null;\n}\n\nfunction run(students) {\n // print('hello!');\n\n students = students.map(function (student) {\n student.notified = false;\n return student;\n });\n\n var polikarp = students[0];\n\n polikarp.notified = true;\n\n if (polikarp.limit === 0) {\n // print('polikarp');\n return -1;\n }\n\n var overallLimit = students.reduce(function (acc, student) {\n return acc + student.limit;\n }, 0);\n\n if (students.length > overallLimit + 1) {\n // print('students');\n return -1;\n }\n\n students = students.sort(function (left, right) {\n if (left.notified) {\n return -1;\n }\n\n if (right.notified) {\n return 1;\n }\n\n if (left.limit === right.limit) {\n return 0;\n }\n\n return left.limit < right.limit ? 1 : -1;\n });\n\n var messages = [];\n\n for (var i = 0; i < students.length; i++) {\n var currentStudent = students[i];\n while (currentStudent.limit > 0) {\n var notNotifiedStudent = getNearestNotNofiedStudent(students);\n if (notNotifiedStudent === null) {\n break;\n }\n notNotifiedStudent.notified = true;\n currentStudent.limit--;\n messages.push({\n from: currentStudent.number,\n to: notNotifiedStudent.number\n });\n }\n }\n\n return messages.reduce(function (acc, message) {\n return acc + message.from + ' ' + message.to + \"\\n\";\n }, '');\n}\n\nvar count = readline();\nvar students = readline()\n .split(' ')\n .map(function (a) { return parseInt(a); })\n .map(function (limit, number) {\n return { limit: limit, number: number + 1 };\n });\n\nvar result = run(students);\nprint(result);\n"}], "src_uid": "3ebb3a4f01345145f8f9817f7c77185e"} {"source_code": "var k = readline().split(' ')[1];\nvar a = readline().split(' ');\nvar b = readline().split(' ');\n\nfunction canWeMake(x, a, b, k) {\n\tfor (var i=0; i= 0) {\n\t\t\tk -= z;\n\t\t}\n\t}\n\treturn k;\n}\n\nfunction f(k, a, b) {\n\tvar max = 0;\n\tvar l = 0;\n\tvar r = 2 * Math.pow(10, 9);\n\twhile (l <= r) {\n\t\tvar n = Math.floor((r + l) / 2);\n\n\t\tvar res = canWeMake(n, a, b, k);\n\n\t\tif (res == 0) {\n\t\t\treturn n;\n\t\t}\n\n\t\tif (res > 0) {\n\t\t\tmax = Math.max(max, n);\n\t\t\tif (l == r) {\n\t\t\t\treturn max;\n\t\t\t}\n\t\t\tl = n + 1;\n\t\t}\n\t\telse {\n\t\t\tif (l == r) {\n\t\t\t\treturn max;\n\t\t\t}\n\t\t\tr = n;\n\t\t}\n\t}\n\treturn max;\n}\n\nvar res = f(k, a, b);\n\nwrite(res);\n\n//f(3, [4,3,5,6], [11,12,14,20]);\n//f(1, [1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000], [1,1,1,1,1,1,1,1,1,1]);\n//f(1, [2,1,4], [11,3,16]);\n//f(1000000000, [1], [1000000000]);", "positive_code": [{"source_code": "function main() {\n var input = readline().split(' ').map(Number)\n var n = input[0]\n var k = input[1]\n\n var need = readline().split(' ').map(Number)\n var have = readline().split(' ').map(Number)\n\n var l = 0\n var r = Math.pow(10, 9) * 2 + 1\n\n function canPrepare(c) {\n var total = 0\n\n for (var i = 0; i < need.length; i++) {\n total += Math.max(need[i] * c - have[i], 0)\n\n if (total > k) return false\n }\n\n return true\n }\n\n while (l + 1 < r) {\n var m = Math.round((l + r) / 2)\n if (canPrepare(m)) {\n l = m\n } else {\n r = m\n }\n }\n\n print(l)\n\n return 0\n}\n\nmain()\n"}], "negative_code": [{"source_code": "var k = readline().split()[1];\nvar a = readline().split();\nvar b = readline().split();\n\nfunction canWeMake(x, a, b, k) {\n\tfor (var i=0; i= 0) {\n\t\t\tk -= z;\n\t\t}\n\t}\n\treturn k;\n}\n\nfunction f(k, a, b) {\n\tvar max = 0;\n\tvar l = 0;\n\tvar r = 2 * Math.pow(10, 9);\n\twhile (l <= r) {\n\t\tvar n = Math.floor((r + l) / 2);\n\n\t\tvar res = canWeMake(n, a, b, k);\n\n\t\tif (res == 0) {\n\t\t\treturn n;\n\t\t}\n\n\t\tif (res > 0) {\n\t\t\tmax = Math.max(max, n);\n\t\t\tif (l == r) {\n\t\t\t\treturn max;\n\t\t\t}\n\t\t\tl = n + 1;\n\t\t}\n\t\telse {\n\t\t\tif (l == r) {\n\t\t\t\treturn max;\n\t\t\t}\n\t\t\tr = n;\n\t\t}\n\t}\n\treturn max;\n}\n\nvar res = f(k, a, b);\n\nprint(res);\n\n//f(3, [4,3,5,6], [11,12,14,20]);"}, {"source_code": "var k = readline().split()[1];\nvar a = readline().split();\nvar b = readline().split();\n\nfunction canWeMake(x, a, b, k) {\n\tfor (var i=0; i= 0) {\n\t\t\tk -= z;\n\t\t}\n\t}\n\treturn k;\n}\n\nfunction f(k, a, b) {\n\tvar max = 0;\n\tvar l = 0;\n\tvar r = 2 * Math.pow(10, 9);\n\twhile (l < r) {\n\t\tvar n = Math.floor((r + l) / 2);\n\n\t\tvar res = canWeMake(n, a, b, k);\n\n\t\tif (res < 0) {\n\t\t\tr = n;\n\t\t}\n\t\telse if (res > 0) {\n\t\t\tmax = Math.max(max, n);\n\t\t\tl = n + 1;\n\t\t} else {\n\t\t\treturn n;\n\t\t}\n\t}\n\treturn max;\n}\n\nvar res = f(k, a, b);\n\nprint(res);\n\n//f(3, [4,3,5,6], [11,12,14,20]);"}, {"source_code": "function main() {\n var input = readline().split(' ').map(Number)\n var n = input[0]\n var k = input[1]\n\n var need = readline().split(' ').map(Number)\n var have = readline().split(' ').map(Number)\n\n var l = 0\n var r = Math.pow(10, 9) * 2 + 1\n\n function canPrepare(c) {\n var total = 0\n\n for (var i = 0; i < need.length; i++) {\n total += need[i] * c - have[i]\n\n if (total > k) return false\n }\n\n return true\n }\n\n while (l + 1 < r) {\n var m = Math.round((l + r) / 2)\n\n if (canPrepare(m)) {\n l = m\n } else {\n r = m\n }\n }\n\n print(l)\n\n return 0\n}\n\nmain()\n"}], "src_uid": "ab1b4487899609ac0f882e1b1713d162"} {"source_code": "'use strict';\n\nvar n = Number(readline());\nvar count = new Array(100001).fill(0);\nvar prices = readline().split(' ').map(Number);\nfor (var i = 0; i < prices.length; i++) {\n\tcount[prices[i]]++;\n}\nfor (var i = 1; i < count.length; i++) {\n\tcount[i] += count[i - 1];\n}\n\nvar days = Number(readline());\n\nfor (var i = 0; i < days; i++) {\n\tvar num = Number(readline());\n\tif (num >= count.length) {\n\t\tprint(count[count.length - 1]);\n\t} else {\n\t\tprint(count[num]);\n\t}\n}\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n prices = [0].concat(prices).concat([Infinity]);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n}\n \nfunction getStoresPerDay(prices, target){\n let ini = 0;\n let fin = prices.length - 1;\n \n while(ini < fin){\n let mid = Math.floor((fin - ini) / 2) + ini;\n if(prices[mid] <= target){\n ini = mid + 1;\n } else {\n fin = mid;\n }\n }\n return fin - 1;\n \n \n}"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); };\nfunction rdn(){ return +readline(); };\n\nvar n = rdn(), x = rda().sort(function(x,y){ return x-y; }), q = rdn();\n\nfor(var i = 0; i < q; i++){\n var have = rdn();\n\n var l = 0, r = n-1;\n while(l != r){\n var m = Math.floor((l+r)/2);\n\n if(x[m] < have){\n l = m+1;\n }else if(x[m] > have){\n r = m;\n }else{\n l = m+1;\n }\n }\n\n if(x[l] <= have){\n print(l+1);\n }else{\n print(l);\n }\n}"}, {"source_code": "var n = readline();\nvar prices = readline().split(' ').map(Number).sort(function(x,y){ return x-y; });\nvar days = readline();\n\nfor(var i = 0; i < days; i++){\n var money = readline()\n var l = 0, r = n-1;\n\n while(l != r){\n var m = Math.floor((l+r)/2);\n\n if(prices[m] < money){\n l = m + 1;\n }else if(prices[m] > money){\n r = m;\n }else{\n l = m + 1;\n }\n }\n\n if(prices[l] <= money){\n print(l + 1);\n }else{\n print(l);\n }\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n\n\n let prevCost = 0;\n const positions = []; cnt = 0;\n for (const key in nums) {\n let cost = nums[key];\n\n for (let i = prevCost; i < cost-1; i += 1) {\n positions[i] = cnt;\n }\n\n prevCost = cost-1; cnt += 1;\n }\n \n for (let i = prevCost; i <= prevCost+10; i += 1) {\n positions[i] = cnt;\n }\n\n const [q] = input[2].split(' ').map(x => parseInt(x));\n for (let i = 3; i < q+3; i += 1) {\n let p = parseInt(input[i]);\n\n if (positions[p] === undefined) {\n console.log(nums.length);\n } else {\n console.log(positions[p-1]);\n }\n }\n}); "}, {"source_code": "var n = +readline();\nvar x = readline().split(\" \").map(xi => +xi);\nvar q = +readline();\n\nx.sort((a, b) => a - b);\nvar countLessOrEqual = function(a, target) { \n var lo = 0,\n hi = a.length,\n mid;\n while (lo != hi) { \n mid = Math.floor( (lo + hi) / 2);\n if (a[mid] <= target) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return lo;\n};\n\nvar shopsOnDay = [];\nfor (var i = 0; i < q; ++i) {\n var mi = +readline();\n shopsOnDay.push(countLessOrEqual(x, mi));\n}\n\nprint(shopsOnDay.join(\"\\n\"));\n"}, {"source_code": "var n = +readline();\nvar x = readline().split(\" \").map(xi => +xi);\nvar q = +readline();\n\nx.sort((a, b) => a - b);\nvar countLessOrEqual = function(a, item) { \n var l = 0;\n var r = a.length;\n while (l <= r) { \n var i = Math.floor( (r + l) / 2 );\n var curItem = a[i];\n var nextItem = a[i + 1];\n \n if ( curItem <= item && (typeof nextItem === \"undefined\" || nextItem > item) ) {\n return i + 1;\n } else if ( curItem <= item ) {\n l = i + 1;\n } else {\n r = i - 1;\n }\n }\n return 0;\n};\n\nvar shopsOnDay = [];\nfor (var i = 0; i < q; ++i) {\n var mi = +readline();\n shopsOnDay.push(countLessOrEqual(x, mi));\n}\n\nprint(shopsOnDay.join(\"\\n\"));\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n prices = [0].concat(prices).concat([Infinity]);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n}\n \nfunction getStoresPerDay(prices, target){\n let ini = 0;\n let fin = prices.length - 1;\n \n while(ini < fin){\n let mid = Math.floor((fin - ini) / 2) + ini;\n if(prices[mid] <= target){\n ini = mid + 1;\n } else {\n fin = mid;\n }\n }\n return fin - 1;\n}"}], "negative_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n \n let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n while (left <= right) {\n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;\n \n \n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n \n med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n }\n \n return med+2;\n}\n \n \nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n \n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n \n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n \n const res = binarySearch(parseInt(input[i]), nums);\n if (nums[0] > parseInt(input[i])) { console.log(0); }\n else {\n if (res+1 < nums.length && nums[res] === nums[res+1]) {\n let t = res;\n while (nums[t] === nums[res] && t+1 < nums.length) t += 1;\n console.log(t);\n } else {\n console.log(res);\n }\n }\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n while (left <= right) {\n let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;\n \n if ( pos >= arr[arr.length-1] ) return arr.length;\n \n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) { \n return med+1\n };\n\n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n }\n\n return -1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n let num = parseInt(input[i]);\n let res = binarySearch(num, nums);\n\n if (res < 0) { console.log(0) }\n else {\n if (res+1 < nums.length && nums[res] === nums[res+1]) {\n let t = res + 1;\n while (nums[t] === nums[res] && t+1 < nums.length) {\n t += 1;\n }\n console.log(t);\n } else {\n console.log(res);\n }\n }\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n while (left <= right) {\n let med = parseInt((left + right) / 2);\n \n if (arr[med] === pos) { return med+1; }\n if (med+1 < arr.length) {\n if (arr[med] < pos && arr[med+1] > pos) {\n return med+1;\n }\n\n if (arr[med+1] === pos) return med+2;\n }\n\n if (med-1 >= 0) {\n if (arr[med] > pos && arr[med-1] <= pos) return med;\n }\n \n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n }\n\n return -1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n\n const res = binarySearch(parseInt(input[i]), nums);\n if (res === -1) { console.log(0); }\n else console.log(res);\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n while (left <= right) {\n let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;\n \n if ( pos >= arr[arr.length-1] ) return arr.length;\n \n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) { \n return med+1\n };\n\n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n }\n\n return -1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n let num = parseInt(input[i]);\n let res = binarySearch(num, nums);\n\n if (res < 0) { console.log(0) }\n else {\n if (res+1 < nums.length && nums[res] === nums[res+1]) {\n let t = res + 1;\n while (nums[t] !== nums[res] && t+1 < nums.length) {\n t += 1;\n }\n console.log(t+1);\n } else {\n console.log(res);\n }\n }\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n while (left <= right) {\n let med = parseInt((left + right) / 2);\n \n if (arr[med] === pos) { return med+1; }\n if (med+1 < arr.length) {\n if (arr[med] < pos && arr[med+1] > pos) {\n return med+1;\n }\n\n if (arr[med+1] === pos) return med+2;\n }\n\n if (med-1 >= 0) {\n if (arr[med] > pos && arr[med-1] < pos) return med;\n if (arr[med-1] === pos) return med+1;\n }\n \n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n }\n\n return -1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n\n const res = binarySearch(parseInt(input[i]), nums);\n if (res === -1) { console.log(0); }\n else console.log(res);\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n while (left <= right) {\n let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n \n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;\n\n\n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n }\n\n return -1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n\n const res = binarySearch(parseInt(input[i]), nums);\n if (res === -1) { console.log(0); }\n else console.log(res);\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n while (left <= right) {\n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;\n\n\n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n\n med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n }\n\n return med+1;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n\n const res = binarySearch(parseInt(input[i]), nums);\n if (nums[0] > parseInt(input[i])) { console.log(0); }\n else console.log(res);\n }\n}); "}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst binarySearch = (pos, arr) => {\n let left = 0, right = arr.length-1;\n\n let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n while (left <= right) {\n if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;\n\n\n if (arr[med] > pos) {\n right = med-1;\n } else {\n left = med;\n }\n\n med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;\n }\n\n return med+2;\n}\n\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n nums.sort((a, b) => a - b);\n const [q] = input[2].split(' ').map(x => parseInt(x));\n\n for (let i = 3; i < q+3; i += 1) {\n if (parseInt(input[i]) > nums[nums.length-1]) {\n console.log(nums.length); continue;\n }\n\n const res = binarySearch(parseInt(input[i]), nums);\n if (nums[0] > parseInt(input[i])) { console.log(0); }\n else console.log(res);\n }\n}); "}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n \n \n// console.log(coinsDay1);\n// let coinsDay2 = readline();\n// coinsDay2 = parseInt(coinsDay2)\n// let coinsDay3 = readline();\n// coinsDay3 = parseInt(coinsDay3)\n// let coinsDay4 = readline();\n// coinsDay4 = parseInt(coinsDay4)\n\n// console.log(getStoresPerDay(prices, coinsDay1))\n// console.log(getStoresPerDay(prices, coinsDay2))\n// console.log(getStoresPerDay(prices, coinsDay3))\n// console.log(getStoresPerDay(prices, coinsDay4))\n}\n\n// function getStoresPerDay(prices, target){\n// let counter = 0;\n// if(!prices.length) return counter;\n// // prices = prices.sort((a, b) => a - b);\n// console.log(prices, target)\n\n// for (let i = 0; i < prices.length; i++) {\n// if(prices[i] < target) counter++;\n// if(target < prices[i]){\n// break;\n// }\n// }\n// return counter;\n// }\nfunction getStoresPerDay(prices, target, counter = 0){\n if(!prices.length) return counter;\n// prices = prices.sort((a, b) => a - b);\n// console.log(prices, target, counter)\n\n let mid = Math.floor(prices.length / 2);\n// console.log(prices[mid], \"mid\")\n if(prices[mid] === target){\n counter += mid + 1;\n } else if(prices[mid] > target) { \n return getStoresPerDay(prices.slice(0, mid), target, counter); \n } else if( prices[mid] < target) {\n counter += mid + 1;\n return getStoresPerDay(prices.slice(mid + 1), target, counter);\n }\n return counter;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n let coinsDay2 = readline();\n coinsDay2 = parseInt(coinsDay2)\n let coinsDay3 = readline();\n coinsDay3 = parseInt(coinsDay3)\n let coinsDay4 = readline();\n coinsDay4 = parseInt(coinsDay4)\n\n console.log(getStoresPerDay(prices, coinsDay1))\n console.log(getStoresPerDay(prices, coinsDay2))\n console.log(getStoresPerDay(prices, coinsDay3))\n console.log(getStoresPerDay(prices, coinsDay4))\n}\n\n\nfunction getStoresPerDay(prices, target, counter = 0){\n if(!prices.length) return counter;\n\n let mid = Math.floor(prices.length / 2);\n\n if(prices[mid] === target){\n counter += mid + 1;\n } else if(prices[mid] > target) { \n return getStoresPerDay(prices.slice(0, mid), target, counter); \n } else if( prices[mid] < target) {\n counter += mid + 1;\n return getStoresPerDay(prices.slice(mid + 1), target, counter);\n }\n return counter;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays >= 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n \n \n// console.log(coinsDay1);\n// let coinsDay2 = readline();\n// coinsDay2 = parseInt(coinsDay2)\n// let coinsDay3 = readline();\n// coinsDay3 = parseInt(coinsDay3)\n// let coinsDay4 = readline();\n// coinsDay4 = parseInt(coinsDay4)\n\n// console.log(getStoresPerDay(prices, coinsDay1))\n// console.log(getStoresPerDay(prices, coinsDay2))\n// console.log(getStoresPerDay(prices, coinsDay3))\n// console.log(getStoresPerDay(prices, coinsDay4))\n}\n\nfunction getStoresPerDay(prices, target){\n let counter = 0;\n if(!prices.length) return counter;\n// prices = prices.sort((a, b) => a - b);\n// console.log(prices, target)\n\n for (let i = 0; i < prices.length; i++) {\n if(prices[i] < target) counter++;\n if(target < prices[i]){\n break;\n }\n }\n return counter;\n}\n// function getStoresPerDay(prices, target, counter = 0){\n// if(!prices.length) return counter;\n// // prices = prices.sort((a, b) => a - b);\n// // console.log(prices, target, counter)\n\n// let mid = Math.floor(prices.length / 2);\n// // console.log(prices[mid], \"mid\")\n// if(prices[mid] === target){\n// counter += mid + 1;\n// } else if(prices[mid] > target) { \n// return getStoresPerDay(prices.slice(0, mid), target, counter); \n// } else if( prices[mid] < target) {\n// counter += mid + 1;\n// return getStoresPerDay(prices.slice(mid + 1), target, counter);\n// }\n// return counter;\n// }"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n}\n\nfunction getStoresPerDay(prices, target){\n let counter = 0;\n if(!prices.length) return counter;\n\n for (let i = 0; i < prices.length; i++) {\n if(prices[i] < target) counter++;\n if(target < prices[i]){\n break;\n }\n }\n return counter;\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n \n \n// console.log(coinsDay1);\n// let coinsDay2 = readline();\n// coinsDay2 = parseInt(coinsDay2)\n// let coinsDay3 = readline();\n// coinsDay3 = parseInt(coinsDay3)\n// let coinsDay4 = readline();\n// coinsDay4 = parseInt(coinsDay4)\n\n// console.log(getStoresPerDay(prices, coinsDay1))\n// console.log(getStoresPerDay(prices, coinsDay2))\n// console.log(getStoresPerDay(prices, coinsDay3))\n// console.log(getStoresPerDay(prices, coinsDay4))\n}\n\nfunction getStoresPerDay(prices, target){\n let counter = 0;\n if(!prices.length) return counter;\n\n for (let i = 0; i < prices.length; i++) {\n if(prices[i] < target) counter++;\n if(target < prices[i]){\n break;\n }\n }\n return counter;\n}\n// function getStoresPerDay(prices, target, counter = 0){\n// if(!prices.length) return counter;\n// // prices = prices.sort((a, b) => a - b);\n// // console.log(prices, target, counter)\n\n// let mid = Math.floor(prices.length / 2);\n// // console.log(prices[mid], \"mid\")\n// if(prices[mid] === target){\n// counter += mid + 1;\n// } else if(prices[mid] > target) { \n// return getStoresPerDay(prices.slice(0, mid), target, counter); \n// } else if( prices[mid] < target) {\n// counter += mid + 1;\n// return getStoresPerDay(prices.slice(mid + 1), target, counter);\n// }\n// return counter;\n// }"}, {"source_code": "'use strict';\n\nfunction binarySearch(num, prices, left, right) {\n\twhile (left <= right) {\n\t\tvar mid = parseInt(left + (right - left) / 2);\n\t\tif (mid == 0 && prices[mid] > num) {\n\t\t\treturn 0;\n\t\t} else if (mid == prices.length - 1 && prices[mid] <= num) {\n\t\t\treturn prices.length;\n\t\t} else if (prices[mid] <= num && prices[mid + 1] > num) {\n\t\t\treturn mid + 1;\n\t\t} else if (prices[mid] < num) {\n\t\t\tleft = mid + 1;\n\t\t} else {\n\t\t\tright = mid - 1;\n\t\t}\n\t}\n\treturn -1;\n}\n\nvar n = Number(readline());\nvar prices = readline().split(' ').map(Number).sort(function (a, b) {\n\treturn a - b;\n});\nvar days = Number(readline());\n\nfor (var i = 0; i < days; i++) {\n\tvar num = Number(readline());\n\tvar index = binarySearch(num, prices, 0, prices.length - 1);\n\tprint(index);\n}\n"}, {"source_code": "var n = +readline();\nvar x = readline().split(\" \").map(xi => +xi);\nvar q = +readline();\nvar m = [];\n\nx.sort((a, b) => a - b);\nvar countLessOrEqual = function(a, item) { \n var l = 0;\n var r = a.length;\n while (l <= r) { \n var i = Math.floor((r + l) / 2);\n var curItem = a[i];\n var nextItem = a[i + 1];\n \n if ( curItem <= item && (typeof nextItem === \"undefined\" || nextItem > item) ) {\n return i + 1;\n } else if ( curItem < item ) {\n l = i + 1;\n } else {\n r = i - 1;\n }\n }\n return 0;\n};\n\nvar shopsOnDay = [];\nfor (var i = 0; i < q; ++i) {\n mi = +readline();\n shopsOnDay.push(countLessOrEqual(x, mi));\n}\n\nprint(shopsOnDay.join(\"\\n\"));\n"}, {"source_code": "var n = +readline();\nvar x = readline().split(\" \").map(xi => +xi);\nvar q = +readline();\n\nx.sort((a, b) => a - b);\nvar countLessOrEqual = function(a, target) { \n var lo = 0,\n hi = a.length,\n mid;\n while (lo != hi) { \n mid = Math.floor( (lo + hi) / 2);\n if (a[mid] <= target) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n if (a[mid] <= target) {\n return mid + 1;\n } else {\n return 0;\n }\n};\n\nvar shopsOnDay = [];\nfor (var i = 0; i < q; ++i) {\n var mi = +readline();\n shopsOnDay.push(countLessOrEqual(x, mi));\n}\n\nprint(shopsOnDay.join(\"\\n\"));\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays >= 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n \n \n// console.log(coinsDay1);\n// let coinsDay2 = readline();\n// coinsDay2 = parseInt(coinsDay2)\n// let coinsDay3 = readline();\n// coinsDay3 = parseInt(coinsDay3)\n// let coinsDay4 = readline();\n// coinsDay4 = parseInt(coinsDay4)\n\n// console.log(getStoresPerDay(prices, coinsDay1))\n// console.log(getStoresPerDay(prices, coinsDay2))\n// console.log(getStoresPerDay(prices, coinsDay3))\n// console.log(getStoresPerDay(prices, coinsDay4))\n}\n\n// function getStoresPerDay(prices, target){\n// let counter = 0;\n// if(!prices.length) return counter;\n// // prices = prices.sort((a, b) => a - b);\n// console.log(prices, target)\n\n// for (let i = 0; i < prices.length; i++) {\n// if(prices[i] < target) counter++;\n// if(target < prices[i]){\n// break;\n// }\n// }\n// return counter;\n// }\nfunction getStoresPerDay(prices, target, counter = 0){\n if(!prices.length) return counter;\n// prices = prices.sort((a, b) => a - b);\n// console.log(prices, target, counter)\n\n let mid = Math.floor(prices.length / 2);\n// console.log(prices[mid], \"mid\")\n if(prices[mid] === target){\n counter += mid + 1;\n } else if(prices[mid] > target) { \n return getStoresPerDay(prices.slice(0, mid), target, counter); \n } else if( prices[mid] < target) {\n counter += mid + 1;\n return getStoresPerDay(prices.slice(mid + 1), target, counter);\n }\n return counter;\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let shops = readline();\n let prices = readline().split(' ');\n prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);\n let numDays = readline();\n \n while(numDays > 0){\n let coinsDay1 = readline();\n coinsDay1 = parseInt(coinsDay1)\n console.log(getStoresPerDay(prices, coinsDay1))\n numDays--;\n }\n \n \n// console.log(coinsDay1);\n// let coinsDay2 = readline();\n// coinsDay2 = parseInt(coinsDay2)\n// let coinsDay3 = readline();\n// coinsDay3 = parseInt(coinsDay3)\n// let coinsDay4 = readline();\n// coinsDay4 = parseInt(coinsDay4)\n\n// console.log(getStoresPerDay(prices, coinsDay1))\n// console.log(getStoresPerDay(prices, coinsDay2))\n// console.log(getStoresPerDay(prices, coinsDay3))\n// console.log(getStoresPerDay(prices, coinsDay4))\n}\n\nfunction getStoresPerDay(prices, target){\n let counter = 0;\n if(!prices.length) return counter;\n// prices = prices.sort((a, b) => a - b);\n console.log(prices, target)\n\n for (let i = 0; i < prices.length; i++) {\n if(prices[i] < target) counter++;\n if(target < prices[i]){\n break;\n }\n }\n return counter;\n}\n// function getStoresPerDay(prices, target, counter = 0){\n// if(!prices.length) return counter;\n// // prices = prices.sort((a, b) => a - b);\n// // console.log(prices, target, counter)\n\n// let mid = Math.floor(prices.length / 2);\n// // console.log(prices[mid], \"mid\")\n// if(prices[mid] === target){\n// counter += mid + 1;\n// } else if(prices[mid] > target) { \n// return getStoresPerDay(prices.slice(0, mid), target, counter); \n// } else if( prices[mid] < target) {\n// counter += mid + 1;\n// return getStoresPerDay(prices.slice(mid + 1), target, counter);\n// }\n// return counter;\n// }"}], "src_uid": "80a03e6d513f4051175cd5cd1dea33b4"} {"source_code": "var data = readline().split(\" \");\nvar l = data[2];\nvar countQuery = +data[1];\nvar n_query = 0;\nvar arrHair = new Array(+data[0]).fill(0);\nvar countChick = 0;\nvar startHairs = readline().split(\" \");\n\nfunction growHair(p, d){\n arrHair[p] += d;\n if(arrHair[p] > l && arrHair[p] - d <=l){\n if(arrHair.length > 1){\n if(p === 0){\n if(arrHair[p+1] <= l)\n countChick++;\n }\n else if(p === arrHair.length - 1){\n if(arrHair[p-1] <= l)\n countChick++;\n }\n else{\n if(arrHair[p-1] <= l && arrHair[p+1] <= l )\n countChick++;\n else if(arrHair[p-1] > l && arrHair[p+1] > l )\n countChick--; \n }\n }\n else\n countChick = 1;\n\n }\n\n}\n\n\n\n\nvar queries = Array();\nfor(var j = 0; j < startHairs.length; j++){\n queries[j] = Array(1, j+1, +startHairs[j]);\n} \nwhile(n_query < countQuery){\n n_query++;\n var temp = readline().split(\" \");\n queries[j] = Array();\n for(var k = 0; k < temp.length; k++){\n queries[j][k] = parseInt(temp[k]);\n }\n j++;\n}\n\nfor(var i = 0; i < queries.length; i++){\n if(queries[i][0] === 0 ){\n print(countChick);\n } \n else{\n growHair(queries[i][1] - 1, queries[i][2]);\n }\n}\n", "positive_code": [{"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines; i++) { \n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n }\n }\n}\n\nvar grow = function (hairlinePos, growLength) {\n var oldLength = hairlines[hairlinePos - 1];\n hairlines[hairlinePos - 1] = oldLength + growLength;\n\n if (oldLength <= favLength && hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);;\n }\n}\n\n"}], "negative_code": [{"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength || hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n // if (hairlines[i + 1] > favLength) {\n // i++;\n // }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar s = [-1];\ns.concat(hairlines.push(-1));\nhairlines = s;\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n // if (hairlinePos == 1) {\n // if (noHairlines == 1) {\n // savedTime++;\n // return;\n // }\n // if (hairlines[1] <= favLength) {\n // savedTime++;\n // return;\n // }\n // return;\n // }\n\n // if (hairlinePos == noHairlines) {\n // if (hairlines[hairlinePos - 2] <= favLength) {\n // savedTime++;\n // }\n // return;\n // }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1] + 1, line[2]);;\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines; i++) { \n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n }\n }\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);;\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nvar printTime = function () {\n var savedTime2 = hairlines[0] > favLength ? 1 : 0;\n for (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime2++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n }\n if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime2++;\n }\n print(savedTime2);\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n // printTime();\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\n\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (hairlines[1] <= favLength) {\n savedTime++;\n }\n if(requests == 0 && hairlines[1] > favLength){\n savedTime--;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n if (requests == 0 && hairlines[hairlinePos - 2] > favLength) {\n savedTime--;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests--) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\n\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (hairlines[1] <= favLength) {\n savedTime++;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests--) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (noHairlines == 1) {\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nwhile (requests-- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n } else {\n grow(line[1], line[2]);;\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\n\nfor(var i = 1; i < noHairlines -1 ; i++){\n if(hairlines[i] > favLength) {\n if(hairlines[i-1] <= favLength && hairlines[i+1]<= favLength){\n savedTime++;\n }else{\n if(hairlines[i] > favLength && hairlines[i+1] > favLength){\n i++;\n }\n }\n }\n}\nif(hairlines[noHairlines- 2] <= favLength && hairlines[noHairlines -1] > favLength){\n savedTime++;\n}\n\nvar grow = function(hairlinePos, growLength){\n hairlines[hairlinePos -1] = hairlines[hairlinePos -1] + growLength;\n\n if(hairlines[hairlinePos -1] > favLength){\n if(hairlinePos == 1 && hairlines[1] <=favLength){\n savedTime++;\n return;\n }\n\n if(hairlinePos == noHairlines && hairlines[hairlinePos -2] <= favLength){\n savedTime++;\n return;\n }\n if(hairlines[hairlinePos -2] <= favLength && hairlines[hairlinePos]<= favLength){\n savedTime++;\n return;\n }\n if(hairlines[hairlinePos -2] > favLength && hairlines[hairlinePos] > favLength){\n savedTime --;\n return;\n }\n }\n}\n\nwhile(requests--){\n var line = readline().split(' ').map(Number);\n if(line[0] == 0){\n print(savedTime);\n }else{\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if(noHairlines == 1){\n savedTime++;\n return;\n }\n if (hairlines[1] <= favLength) {\n savedTime++;\n return;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nvar printTime = function () {\n var savedTime2 = hairlines[0] > favLength ? 1 : 0;\n for (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime2++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n }\n if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime2++;\n }\n print(savedTime2);\n}\n\nwhile (requests -- > 0) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n print(savedTime);\n // printTime();\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "\n\nvar nml = readline().split(' ').map(Number);\nvar hairlines = readline().split(' ').map(Number)\n\nvar noHairlines = nml[0];\nvar requests = nml[1];\nvar favLength = nml[2];\n\nvar savedTime = hairlines[0] > favLength ? 1 : 0;\nfor (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n}\nif (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime++;\n}\n\nvar grow = function (hairlinePos, growLength) {\n hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;\n\n if (hairlines[hairlinePos - 1] > favLength) {\n if (hairlinePos == 1) {\n if (hairlines[1] <= favLength) {\n savedTime++;\n }\n return;\n }\n\n if (hairlinePos == noHairlines) {\n if (hairlines[hairlinePos - 2] <= favLength) {\n savedTime++;\n }\n return;\n }\n if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {\n savedTime++;\n return;\n }\n if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {\n savedTime--;\n return;\n }\n }\n}\n\nvar computeTime = function () {\n var savedTime2 = hairlines[0] > favLength ? 1 : 0;\n for (var i = 1; i < noHairlines - 1; i++) {\n if (hairlines[i] > favLength) {\n if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {\n savedTime2++;\n } else {\n if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {\n i++;\n }\n }\n }\n }\n if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {\n savedTime2++;\n }\n print(savedTime2);\n}\n\nwhile (requests--) {\n var line = readline().split(' ').map(Number);\n if (line[0] == 0) {\n // print(savedTime);\n computeTime();\n } else {\n grow(line[1], line[2]);\n }\n}\n\n"}, {"source_code": "var data = readline().split(\" \");\nvar l = data[2];\nvar countQuery = +data[1];\nvar n_query = 0;\nvar arrHair = new Array(+data[0]).fill(0);\nvar countChick = 0;\nvar startHairs = readline().split(\" \");\nfunction growHair(p, d){\n arrHair[p] += d;\n if(arrHair[p] > l){\n if(arrHair.length > 1){\n if((p) === 0){\n if(arrHair[p+1] <= l)\n countChick++;\n }\n else if((p) === arrHair.length - 1){\n if(arrHair[p-1] <= l)\n countChick++;\n }\n else{\n if(arrHair.length > 2){\n if(arrHair[p-1] <= l && arrHair[p+1] <= l )\n countChick++;\n else if(arrHair[p-1] > l && arrHair[p+1] > l )\n countChick--; \n }\n \n }\n }\n else\n return countChick = 1;\n\n }\n\n}\n\n\n\n\nvar queries = Array();\nfor(var j = 0; j < startHairs.length; j++){\n queries[j] = Array(1, j+1, +startHairs[j]);\n} \nwhile(n_query < countQuery){\n n_query++;\n var temp = readline().split(\" \");\n queries[j] = Array();\n for(var k = 0; k < temp.length; k++){\n queries[j][k] = parseInt(temp[k]);\n }\n j++;\n}\n\nfor(var i = 0; i < queries.length; i++){\n if(queries[i][0] === 0 ){\n print(countChick);\n } \n else{\n growHair(queries[i][1] - 1, queries[i][2]);\n }\n}\n"}, {"source_code": "var data = readline().split(\" \");\nvar l = data[2];\nvar countQuery = +data[1];\nvar n_query = 0;\nvar arrHair = new Array(+data[0]).fill(0);\nvar countChick = 0;\nvar startHairs = readline().split(\" \");\nfunction growHair(p, d){\n arrHair[p] += d;\n if(arrHair[p] > l){\n if(arrHair.length > 2){\n if((p) === 0){\n if(arrHair[p+1] <= l)\n countChick++;\n }\n else if((p) === arrHair.length - 1){\n if(arrHair[p-1] <= l)\n countChick++;\n }\n else{\n if(arrHair[p-1] <= l && arrHair[p+1] <= l )\n countChick++;\n else if(arrHair[p-1] > l && arrHair[p+1] > l )\n countChick--; \n }\n }\n else\n return countChick = 1;\n\n }\n\n}\n\n\n\n\nvar queries = Array();\nfor(var j = 0; j < startHairs.length; j++){\n queries[j] = Array(1, j+1, +startHairs[j]);\n} \nwhile(n_query < countQuery){\n n_query++;\n var temp = readline().split(\" \");\n queries[j] = Array();\n for(var k = 0; k < temp.length; k++){\n queries[j][k] = parseInt(temp[k]);\n }\n j++;\n}\n\nfor(var i = 0; i < queries.length; i++){\n if(queries[i][0] === 0 ){\n print(countChick);\n } \n else{\n growHair(queries[i][1] - 1, queries[i][2]);\n }\n}"}], "src_uid": "1e17039ed5c48e5b56314a79b3811a40"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n C();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let t = pi(readline());\n while(t > 0){\n t--;\n let [n,k] = ti(readline().split(' '));\n let s = readline().split('');\n\n let a = new Array(s.length);\n a.fill(false);\n let d = 999999999999;\n for(let i = 0; i < s.length; i++){\n if(s[i] === '1'){\n d = 0;\n }else{\n d += 1;\n if(d > k){\n a[i] = true;\n }\n }\n }\n\n d = 999999999999;\n for(let i = s.length-1; i >= 0; i--){\n if(s[i] === '1'){\n d = 0;\n }else{\n d += 1;\n if(d <= k){\n a[i] = false;\n }\n }\n }\n\n let p1 = 0;\n let p2 = 0;\n let res = 0;\n while(p1 < s.length && p2 < s.length){\n while(a[p1] && a[p2]){\n p2++;\n }\n let x = p2-p1;\n res += Math.ceil(x/(k+1));\n p2++;\n p1 = p2;\n }\n\n console.log(res);\n }\n}", "positive_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0];\n var k = input[1];\n var str = readline();\n var dist = k;\n var res = 0;\n for (var i = 0; i < n; i++) {\n if (str[i] == \"1\") {\n if (dist < k) res--;\n dist = 0;\n } else {\n dist++;\n if (dist == k + 1) {\n res++;\n dist = 0;\n }\n }\n }\n print(res);\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var s = read();\n var last1 = 0 - k - 1;\n ans = 0;\n for (var i = 0; i < n; ++i) {\n if (s[i] !== '1') {\n continue;\n }\n while (last1 + k + 1 < i - k) {\n ans++;\n last1 += k + 1;\n }\n last1 = i;\n }\n while (last1 + k + 1 < n) {\n ans++;\n last1 += k + 1;\n }\n write(ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = parseInt(readLine());\n while(t--) {\n let fir = readLine().split(\" \");\n let n = parseInt(fir[0]);\n let k = parseInt(fir[1]);\n let arr = readLine().split(\"\").map((x) => {return parseInt(x)});\n let arr1 = [];\n for(let i = 0;i=0 && j<=k; j++) {\n arr1[i-j] += 1;\n }\n for(let j = 1; (i+j)0) {\n arr2.push(ans); \n }\n ans = 0;\n }\n }\n if (ans>0) {\n arr2.push(ans); \n }\n let realAns = 0;\n for(let i = 0;i0) {\n realAns+= parseInt((arr2[i]-1)/((k)+1))\n }\n realAns++;\n }\n console.log(realAns)\n }\n}"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar list = nextCharArray();\n\t\tvar count = 0;\n\t\tvar sum = 0;\n\t\tvar isOne = false;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(!isOne){\n\t\t\t\tif(list[j] == \"0\"){\n\t\t\t\t\tcount++;\n\t\t\t\t}else{\n\t\t\t\t\tif(count >= 1 + K){\n\t\t\t\t\t\tsum += Math.floor(count / (1 + K));\n\t\t\t\t\t}\n\t\t\t\t\tcount = 0;\n\t\t\t\t\tisOne = true;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(list[j] == \"0\"){\n\t\t\t\t\tcount++;\n\t\t\t\t}else{\n\t\t\t\t\tif(count >= 2 * K + 1){\n\t\t\t\t\t\tsum++;\n\t\t\t\t\t\tcount -= 2 * K + 1;\n\t\t\t\t\t\tsum += Math.floor(count / (K + 1));\n\t\t\t\t\t}\n\t\t\t\t\tcount = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(isOne){\n\t\t\tsum += Math.floor(count / (K + 1));\n\t\t}else{\n\t\t\tsum += Math.ceil(count / (1 + K));\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet stdinInput = '';\n \nprocess.stdin.on('data', input => {\n stdinInput += input;\n})\n \nprocess.stdin.on('end', () => {\n main(stdinInput);\n})\n \n// function main(data) {\n// data = data.split('\\n');\n// const testCases = data[0] * 2;\n// let i = 1;\n// while (i <= testCases) {\n// const int = data[i].split(' ');\n// const n = int[0] * 1;\n// const k = int[1] * 1;\n// const arr = data[i + 1];\n// let count = 0;\n// for (let j = 0; j < n; j += k + 1)(arr[j] == 0 && arr[j + k] != 1) ? count += 1 : '';\n// console.log(count);\n// i += 2;\n// }\n// }\nfunction main(data) {\n data = data.split('\\n');\n const testCases = data[0] * 2;\n let i = 1;\n while (i <= testCases) {\n const int = data[i].split(' ');\n const n = int[0] * 1;\n const k = int[1] * 1;\n const arr = data[i + 1];\n let count = 0;\n let first = arr.indexOf('1');\n let j = 0;\n while (j < n) {\n if (arr[j] == 0 && first === -1) {\n count += 1;\n j += k + 1;\n continue;\n }\n if (arr[j] == 1) {\n j += k + 1;\n continue;\n }\n if (arr[j] == 0) {\n first = arr.indexOf('1', j);\n if (first == -1) {\n count += 1;\n j += k + 1;\n continue;\n } else if (first - j > k) {\n count += 1;\n j += k + 1;\n continue;\n } else j = first;\n }\n }\n console.log(count);\n i += 2;\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i parseInt(x));\n const s = readline();\n let cooldown = 0,\n vacancy = 0;\n for (let j=0; j 0) {\n vacancy--;\n }\n cooldown = k;\n }\n }\n console.log(vacancy);\n }\n}\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n for(let i = 0; i < n; i++) {\n let [, k] = lines[1 + i * 2].split(' ')\n let arr = lines[2 + i * 2].trim().split('').map(x => +x)\n console.log(solution(arr, +k))\n }\n}\n\nfunction solution(arr, k) {\n let N = arr.length\n let waiting = 0\n for(let i = N - 1; i >= 0; i--) {\n if (arr[i] === 1) {\n waiting = k\n }\n else if (waiting) {\n arr[i] = 2\n waiting--\n }\n }\n waiting = 0\n let ans = 0\n for(let i = 0; i < N; i++) {\n if (arr[i] === 1) {\n waiting = k\n } else if (arr[i] === 2) {\n // nothing\n } else if (waiting) {\n waiting--\n } else {\n ans++\n waiting = k\n }\n }\n return ans\n}"}], "negative_code": [{"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0],\n k = input[1];\n var str = readline();\n var possiple = 1;\n var curr = str[0] == \"1\" ? 1 : 0;\n var dist = 0;\n for (var i = 1; i < str.length; i++) {\n if (str[i] == \"1\") curr++;\n if (dist == k) {\n possiple++;\n dist = 0;\n continue;\n }\n dist++;\n }\n print(possiple - curr);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var input = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = input[0];\n var k = input[1];\n var str = readline();\n var possiple = Math.floor(n / (k + 1));\n if (n % (k + 1) == k) possiple++;\n var curr = 0;\n for (var i = 0; i < n; i++) {\n if (str[i] == \"1\") curr++;\n }\n print(possiple - curr);\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var s = read();\n var last1 = 0 - k - 1;\n ans = 0;\n for (var i = 0; i < n; ++i) {\n if (s[i] !== '1') {\n continue;\n }\n while (last1 + k + 1 < i - k - 1) {\n ans++;\n last1 += k + 1;\n }\n last1 = i;\n }\n while (last1 + k + 1 < n) {\n ans++;\n last1 += k + 1;\n }\n write(ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "function solve() {\n var T = Number(read());\n for (var t = 0; t < T; ++t) {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var s = read();\n var last1 = 0 - k - 1;\n ans = 0;\n for (var i = 0; i < n; ++i) {\n if (s[i] !== '1') {\n continue;\n }\n while (last1 + k + 1 < i) {\n ans++;\n last1 += k + 1;\n }\n last1 = i;\n }\n while (last1 + k + 1 < s.length) {\n ans++;\n last1 += k + 1;\n }\n write(ans);\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n solve();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', solve);\n }\n} else {\n solve();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "//\u2193\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u304b\u3089--------------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//\u2191\u898b\u306a\u304f\u3066\u3044\u3044\u3088\uff01\u3053\u3053\u307e\u3067--------------------------------------------------\nfunction Main(){\n\tvar t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tvar list = nextCharArray();\n\t\tvar count = 0;\n\t\tvar sum = 0;\n\t\tvar isOne = false;\n\t\tfor(var j = 0; j < N; j++){\n\t\t\tif(!isOne){\n\t\t\t\tif(list[j] == \"0\"){\n\t\t\t\t\tcount++;\n\t\t\t\t}else{\n\t\t\t\t\tif(count >= 1 + K){\n\t\t\t\t\t\tsum += Math.floor(count / (1 + K));\n\t\t\t\t\t\tcount = 0;\n\t\t\t\t\t}\n\t\t\t\t\tisOne = true;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(list[j] == \"0\"){\n\t\t\t\t\tcount++;\n\t\t\t\t}else{\n\t\t\t\t\tif(count >= 2 * K + 1){\n\t\t\t\t\t\tsum++;\n\t\t\t\t\t\tcount -= 2 * K + 1;\n\t\t\t\t\t\tsum += Math.floor(count / (K + 1));\n\t\t\t\t\t\tcount = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(isOne){\n\t\t\tif(count >= 2 * K + 1){\n\t\t\t\tsum++;\n\t\t\t\tcount -= 2 * K + 1;\n\t\t\t\tsum += Math.ceil(count / (K + 1));\n\t\t\t\tcount = 0;\n\t\t\t}\n\t\t}else{\n\t\t\tsum += Math.ceil(count / (1 + K));\n\t\t}\n\t\toutput[i] = sum;\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const t = parseInt(readline());\n for (let i=0; i parseInt(x));\n const s = readline();\n let cooldown = 0,\n vacancy = 0;\n for (let j=0; j 0) {\n vacancy--;\n cooldown = k;\n }\n }\n }\n console.log(vacancy);\n }\n}\n"}, {"source_code": "const process = require('process')\nlet input = ''\nprocess.stdin.on('data', data => input += data)\nprocess.stdin.on('end', () => main(input))\n\nfunction main(input) {\n let lines = input.trim().split('\\n')\n let n = +lines[0]\n for(let i = 0; i < n; i++) {\n let [, k] = lines[1 + i * 2].split(' ')\n let arr = lines[2 + i * 2].split('').map(x => +x)\n console.log(solution(arr, +k))\n }\n}\n\nfunction solution(arr, k) {\n let N = arr.length\n let waiting = 0\n for(let i = N - 1; i >= 0; i--) {\n if (arr[i] === 1) {\n waiting = k\n }\n else if (waiting) {\n arr[i] = 2\n waiting--\n }\n }\n waiting = 0\n let ans = 0\n for(let i = 0; i < N; i++) {\n if (arr[i] === 1) {\n waiting = k\n } else if (arr[i] === 2) {\n // nothing\n } else if (waiting) {\n waiting--\n } else {\n ans++\n waiting = k\n }\n }\n return ans\n}"}], "src_uid": "fd85ebe1dc975a71c72fac7eeb944a4a"} {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\n\nfunction main() {\n\n let cases = parseInt(readline(), 10);\n for (var X = 0; X < cases; X++) {\n let [n,k] = readline().split(\" \").map(e => parseInt(e));\n\n let space = n - 1;\n\n // console.log({n,k})\n // console.log({\n // a : k / space,\n // b : k % space,\n // x : Math.floor((k -1) / space) * n,\n // })\n\n console.log(1 + (Math.floor((k -1) / space) * n) + (k-1) % space)\n\n //console.log('---');\n \n // for (var i = 0; k > 0; i++) {\n // if (i % n != 0) {\n // k--\n // }\n // }\n //console.log(i-1);\n\n\n }\n\n\n}\n", "positive_code": [{"source_code": "let input = require('fs')\n .readFileSync(0, 'ascii')\n .split('\\n')\n .filter(line => !/^\\s*$/.test(line))\n .map(l => l.split(' ').map(w => parseInt(w)));\n\nlet [t, ...tests] = input;\n\nfor ([n, k] of tests) {\n console.log(k + Math.floor((k - 1) / (n - 1)));\n}\n"}, {"source_code": "'use strict';\n\nconst parseProblem = (line, problem) => {\n if (!problem.T || problem.T === 0) {\n const result = {problem,\n T: parseInt(line),\n isProcessing: true,\n cases: []\n };\n return result;\n }\n\n const cases = problem.cases;\n\n if (cases.length === 0 || !cases[cases.length - 1].isProcessing) {\n cases.push({\n t: line\n });\n }\n\n const isProcessing = cases.length < problem.T;\n problem.isProcessing = isProcessing;\n\n return problem;\n};\n\nconst solve = data => {\n const [n, k] = data.t.split(' ');\n let i = Math.floor(k / (n - 1));\n let j = k % (n - 1);\n \n return j == 0 ? (n * i - 1) : (n * i + j);\n}\n\nconst solveCases = cases => {\n for (let index = 0; index < cases.length; index++) {\n const result = solve(cases[index]);\n console.log(result);\n }\n};\n\nconst main = () => {\n const readline = require('readline');\n\n let problem = {\n T: 0,\n cases: [],\n isProcessing: true\n };\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n rl.on('line', line => {\n problem = parseProblem(line, problem);\n\n if (!problem.isProcessing) {\n rl.close();\n }\n }).on('close', () => {\n solveCases(problem.cases);\n process.exit(0);\n });\n};\n\nif (!module.parent) {\n main();\n}"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n let low = 0, high = k*2;\n while (low< high){\n const mid = Math.floor((low + high)/2);\n if (mid - Math.floor(mid/n) >= k){\n high = mid;\n } else{\n low = mid + 1;\n }\n }\n console.log(low)\n }\n return;\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n let f = getValidTerms(1, k, n);\n console.log(f);\n\n }\n\n function getValidTerms(a, n, div) {\n let f = a + n - 1;\n let s = Math.floor(((f - f%div) -(a%div == 0?a:a + (div - a%div)))/div) + 1;\n if (f-a parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res;\n if (n == k) res = k + 1;\n else if (n > k) res = k;\n else {\n var xx = n - 1;\n k = k - xx;\n res = xx + Math.ceil((n * k) / (n - 1));\n }\n\n print(res);\n}\n"}, {"source_code": "var read = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar obj;\nvar inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n myerr(\"-----start-----\");\n var start = new Date();\n Main();\n var end = new Date() - start;\n myerr(\"----- end -----\");\n myerr(\"time : \" + (end) + \"ms\");\n});\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n var returnObj = {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(!this.hasNext()){throw \"ArrayIndexOutOfBoundsException \u3053\u308c\u4ee5\u4e0a\u306a\u3044\u3088\";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}\n };\n return returnObj;\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//[no]\u8981\u7d20\u306e\u6271\u3044\u3002\u6570\u5024\u578b\n//\u4e0d\u660e\u5024\u3001\u7570\u5e38\u6642:\u5f15\u6570\u305d\u306e\u307e\u307e\u8fd4\u3059 1:\u6570\u5024\u3078\u5909\u63db\n//2:\u534a\u89d2SP\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//6:1\u6587\u5b57\u3067\u5206\u5272 7:1\u6587\u5b57\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//8:\u534a\u89d2SP\u3067\u7d50\u5408 9:\u6539\u884c\u3067\u7d50\u5408 0:\u6587\u5b57\u306a\u3057\u3067\u7d50\u5408\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\nfunction Main(){\n var t = nextInt();\n\tvar output = new Array(t);\n\tfor(var i = 0; i < t; i++){\n\t\tvar one = nextIntArray();\n\t\tvar N = one[0];\n\t\tvar K = one[1];\n\t\tif(N > K){\n\t\t\toutput[i] = K;\n\t\t}else{\n\t\t\tvar count = Math.floor(K / (N - 1));\n\t\t\tvar min = count * N;\n\t\t\tvar ans = min + K % (N - 1);\n\t\t\tif(ans % N == 0){\n\t\t\t\tans--;\n\t\t\t}\n\t\t\toutput[i] = ans;\n\t\t}\n\t}\n\tmyout(myconv(output,9));\n}\n"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (sicLen, num) {\n let weightSic = sicLen - 1;\n let countSics = Math.floor(num/weightSic);\n let body = countSics * sicLen;\n let weightBody = weightSic * countSics;\n let rest = num - weightBody;\n if (!rest) return body - 1;\n return body + rest;\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\" \").map(Number);\n let result = foo(data[0], data[1]);\n answer += result +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction solve(n, k) {\n let count = 0;\n let curCount = Math.floor(k / n);\n while (count !== curCount) {\n count = curCount;\n curCount = Math.floor((k + count) / n);\n }\n return k + curCount;\n}\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let [n, k] = readLine().split(' ').map((val) => parseInt(val));\n // let a = readLine().split(' ').map((val) => parseInt(val));\n let res = solve(n, k);\n console.log(res);\n }\n //process.stdout.write(\"hello: \");\n}\n"}, {"source_code": "function main() {\n var testCasesNum = +readline();\n for (var i = 0; i < testCasesNum; i++) {\n var nk = readline().split(\" \").map(Number);\n var n = nk[0];\n var k = nk[1];\n if (k < n) {\n print(k);\n continue;\n }\n var kdn = Math.floor(k / (n - 1));\n print(kdn * n + (k % (n - 1) || -1));\n }\n}\nmain()"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n let f = getValidTerms(1, k, n);\n console.log(f);\n\n }\n\n function getValidTerms(a, n, div) {\n let f = a + n - 1;\n let s = Math.floor((f-a)/div);\n if(a%div == 0) s++;\n else if (f%div == 0) s++;\n if (f-a {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n let f = getValidTerms(1, k, n);\n console.log(f);\n\n }\n\n function getValidTerms(a, n, div) {\n let f = a + n - 1;\n let s = Math.floor((f-a)/div);\n if(a%div == 0) s++;\n else if (f%div == 0) s++;\n\n if (s <= 0){\n return f;\n } else {\n return getValidTerms(f+1, s, div);\n }\n }\n return;\n\n\n\n}\n"}, {"source_code": "'use strict';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n let f = getValidTerms(1, k, n);\n console.log(f);\n\n }\n\n function getValidTerms(a, n, div) {\n let f = a + n - 1;\n let s = Math.floor((f-a)/div);\n if(a%div == 0) s++;\n else if (f%div == 0) s++;\n if (f-a {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(str => str.trim());\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\n\nfunction main() {\n const t = parseInt(readLine(), 10);\n for (let i = 0; i< t;i++){\n let [n,k] = readLine().split(' ').map(x=>parseInt(x));\n /* let low = 0, high = k*2;\n while (low< high){\n const mid = Math.floor((low + high)/2);\n if (mid - Math.floor(mid/n) >= k){\n high = mid;\n } else{\n low = mid + 1;\n }\n }*/\n console.log(k + Math.floor(k/(n-1)) - ( (k !== n) && (k%n === 0) || k < n ? 1: 0))\n }\n return;\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n 8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n\n\n\n\n**/\n\nfunction main() {\n let range = readline();\n\n for(let r=0;r parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res;\n if (n > k) res = k;\n else if (n == k) res = k + 1;\n else {\n var xx = n - 1;\n k = k - n + 1;\n res = xx + Math.ceil((n * k) / (n - 1));\n if (n % k == 0 || k % n == 0) res--;\n }\n\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res;\n if (n > k) res = k;\n else if (n == k) res = k + 1;\n else {\n var xx = n - 1;\n k = k - n + 1;\n res = xx + Math.floor((n * k) / (n - 1));\n if (n % k == 0 || k % n == 0) res--;\n }\n\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = Math.floor((n * k) / (n - 1));\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res;\n if (n == k) res = k + 1;\n else if (n > k) res = k;\n else {\n var xx = n - 1;\n k = k - xx;\n res = xx + Math.ceil((n * k) / (n - 1));\n if (n % k == 0 || k % n == 0) res--;\n }\n\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n\n var res = Math.floor((n * k) / (n - 1));\n if (n % k == 0 || k % n == 0) res--;\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n\n var res = Math.floor((n * k) / (n - 1));\n if (n % k == 0) res--;\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\"\")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n var res = Math.floor((n * k) / (n - 1));\n print(res);\n}\n"}, {"source_code": "var t = parseInt(readline());\nfor (var tc = 0; tc < t; tc++) {\n var nk = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n var n = nk[0],\n k = nk[1];\n\n var res = Math.floor((n * k) / (n - 1));\n if (n != k && (n % k == 0 || k % n == 0)) res--;\n print(res);\n}\n"}], "src_uid": "7d6f76e24fe9a352beea820ab56f03b6"} {"source_code": "main = () => {\r\n\tt=readInt();\r\n\tallans=[];\r\n\twhile(t--){\r\n\t\ttemp=readIntArr();\r\n\t\tdx=temp[0];\r\n\t\tdy=temp[1];\r\n\t\ts=readString();\r\n\t\tcnts={L:0,U:0,D:0,R:0};\r\n\t\tn=s.length;\r\n\t\tfor(i=0;idx) && (cnts['R']<(x-dx)))\r\n\t\t\tans='NO'\r\n\t\tif ((xdy) && (cnts['U']<(y-dy)))\r\n\t\t\tans='NO'\r\n\t\tif ((y parseInt(readline());\r\nreadString = () => readline();\r\nreadIntArr = () => readline().split(\" \").map(zzzz => parseInt(zzzz));\r\noneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));\r\nmultiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\\n'));\r\nmultiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\\n'));\r\n\r\nfor (_ = 0; _ < 1; _++) {\r\n\tmain();\r\n}\r\n\r\n// newline for testing\r\n //newline for testing\r\n// codeforces js cannot use \"let\" keyword", "positive_code": [{"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var xy = readline().split(' ') , x = xy[0] , y = xy[1],\r\n s = readline().split('') , u = 0 , d = 0 , r = 0 , l = 0;\r\n for(var j = 0 ; j < s.length ; ++j){\r\n switch (s[j]) {\r\n case 'U':\r\n u++;\r\n break;\r\n case 'D':\r\n d++;\r\n break;\r\n case 'R':\r\n r++;\r\n break;\r\n case 'L':\r\n l++;\r\n break;\r\n }\r\n }\r\n if( x >= 0 && r >= x){\r\n if(y >= 0 && u >= y || y <= 0 && d >= -1 * y){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }\r\n else if( x <= 0 && l >= -1 * x){\r\n if(y >= 0 && u >= y || y <= 0 && d >= -1 * y){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tvar dest = readline().split(\" \").map(x => parseInt(x));\n\tvar s = readline();\n\tvar u = 0, d = 0, r = 0, l = 0;\n\tfor (i = 0; i < s.length; i++) {\n\t\tif (s[i] === 'U') u++;\n\t\tif (s[i] === 'D') d--;\n\t\tif (s[i] === 'R') r++;\n\t\tif (s[i] === 'L') l--;\n\t}\n\n\tvar ok = dest[0] <= r && dest[0] >= l && dest[1] <= u && dest[1] >= d;\n\tprint(ok ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "\"use strict\"\r\n\r\nfunction searchPath(path) {\r\n let mas = {\r\n r: 0,\r\n l: 0,\r\n u: 0,\r\n d: 0\r\n }\r\n for (let i = 0; i < path.length; i++) {\r\n if (path[i] == 'R') {\r\n mas.r++;\r\n } else if (path[i] == 'L') {\r\n mas.l++;\r\n } else if (path[i] == 'U') {\r\n mas.u++;\r\n } else if (path[i] == 'D') {\r\n mas.d++;\r\n }\r\n }\r\n return mas;\r\n}\r\n\r\nfunction checkNav(x, y, path) {\r\n if (x >= 0 && y >= 0) {\r\n if (path.r >= x && path.u >= y) {\r\n return \"YES\";\r\n }\r\n } if (x >= 0 && y <= 0) {\r\n if (path.r >= x && path.d >= Math.abs(y)) {\r\n return \"YES\";\r\n }\r\n } if (x <= 0 && y >= 0) {\r\n if (path.l >= Math.abs(x) && path.u >= y) {\r\n return \"YES\";\r\n }\r\n } if (x <= 0 && y <= 0) {\r\n if (path.l >= Math.abs(x) && path.d >= Math.abs(y)) {\r\n return \"YES\";\r\n }\r\n }\r\n return \"NO\";\r\n}\r\n\r\n\r\nlet n = readline();\r\n\r\nfor (let i = 0; i < n; i++) {\r\n let temp = readline().split(' ');\r\n let x = temp[0];\r\n let y = temp[1];\r\n let str = readline();\r\n let path = searchPath(str);\r\n print(checkNav(x, y, path));\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n var w = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var o = lines[j].split(' ').map(Number);\n e = o[0];\n w = o[1];\n }else{\n var k = lines[j].split('');\n var x = 0;\n var y = 0;\n var r = 0;\n var L = 0;\n var d = 0;\n var u = 0;\n for(var l = 0; l < k.length; l++){\n if(e > 0){\n if(k[l] == 'R'){\n r++;\n }\n }else{\n if(k[l] == 'L'){\n L--;\n }\n }\n if(w > 0){\n if(k[l] == 'U'){\n u++;\n }\n }else{\n if(k[l] == 'D'){\n d--;\n }\n }\n }\n var answer = 0;\n if(e > 0 && r >= e){\n answer = 1;\n }else if(e <= 0 && L <= e){\n answer = 1;\n }\n if(w > 0 && u >= w && answer == 1){\n console.log('YES');\n }else if(w <= 0 && d <= w && answer == 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let arr = readline().split(' ').map(x => +x)\n let px = arr[0]\n let py = arr[1]\n let directionString = readline()\n let dirToGo = ''\n // ========= SOLUTION ==============\n if (px > 0 && py > 0)\n dirToGo = 'UR'\n else if (px > 0 && py < 0)\n dirToGo = 'DR'\n else if (px < 0 && py > 0)\n dirToGo = 'UL'\n else if (px < 0 && py < 0)\n dirToGo = 'DL'\n else if (dirToGo == '') {\n if (px < 0) dirToGo = 'L'\n else if (px > 0) dirToGo = 'R'\n else if (py > 0) dirToGo = 'U'\n else if (py < 0) dirToGo = 'D' \n }\n\n // console.log('dirToGo = ', dirToGo)\n let currX = 0, currY = 0\n for (let i = 0; i < directionString.length && ( px != currX || py != currY); i++){\n if( directionString[i] == 'R' && (dirToGo == 'DR' || dirToGo == 'UR' || dirToGo == 'R')){\n if(currX < px)\n currX++\n } else if( directionString[i] == 'L' && (dirToGo == 'UL' || dirToGo == 'DL' || dirToGo == 'L')){\n if(currX > px)\n currX--\n } else if( directionString[i] == 'U' && (dirToGo == 'UL' || dirToGo == 'UR' || dirToGo == 'U')){\n if(currY < py)\n currY++\n } else if( directionString[i] == 'D' && (dirToGo == 'DL' || dirToGo == 'DR' || dirToGo == 'D')){\n if(currY > py)\n currY--\n }\n // console.log('currX = ' + currX + ' | currY = ' + currY)\n }\n if (px == currX && py == currY)\n console.log('YES')\n else\n console.log('NO')\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [x,y] = readline().split(' ').map(x => Number(x));\r\n var count = {\r\n 'R':0,\r\n 'L':0,\r\n 'U':0,\r\n 'D':0,\r\n }\r\n var array = readline().split('').map(x => {\r\n count[x] = (count[x] ? count[x] : 0) + 1\r\n });\r\n if(\r\n x>=0 && count['R'] >= x && y >= 0 && count['U'] >= y ||\r\n x>=0 && count['R'] >= x && y <= 0 && count['D'] >= -y ||\r\n x<=0 && count['L'] >= -x && y <= 0 && count['D'] >= -y ||\r\n x<=0 && count['L'] >= -x && y >= 0 && count['U'] >= y\r\n ) return console.log('YES')\r\n console.log('NO')\r\n // console.log(count)\r\n // console.log(x,y)\r\n })\r\n\r\n}\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const [x, y] = numArray(rl());\r\n const ln2 = rl().split(\"\");\r\n solution(x, y, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(x, y, str) {\r\n // cl(x, y);\r\n let u = (d = l = r = 0);\r\n str.forEach((s) => {\r\n if (s == \"U\") u++;\r\n if (s == \"D\") d--;\r\n if (s == \"L\") l--;\r\n if (s == \"R\") r++;\r\n // if (s == \"U\") y--;\r\n // if (s == \"D\") y++;\r\n // if (s == \"L\") x++;\r\n // if (s == \"R\") x--;\r\n });\r\n // cl(\"X(\", l, r, \")\", \" \", \"Y(\", u, d, \")\");\r\n\r\n // if ((x == l && y == d) || (x == r && y == u)) {\r\n if (x <= r && x >= l && y <= u && y >= d) {\r\n cl(\"YES\");\r\n } else {\r\n cl(\"NO\");\r\n }\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n var w = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var o = lines[j].split(' ').map(Number);\n e = o[0];\n w = o[1];\n }else{\n var k = lines[j].split('');\n var x = 0;\n var y = 0;\n var r = 0;\n var L = 0;\n var d = 0;\n var u = 0;\n for(var l = 0; l < k.length; l++){\n if(e > 0){\n if(k[l] == 'R'){\n r++;\n }\n }else{\n if(k[l] == 'L'){\n L--;\n }\n }\n if(w > 0){\n if(k[l] == 'U'){\n u++;\n }\n }else{\n if(k[l] == 'D'){\n d--;\n }\n }\n }\n var answer = 0;\n if(e > 0 && r >= e){\n answer = 1;\n }else if(e <= 0 && L <= e){\n answer = 1;\n }\n if(w > 0 && u >= w && answer == 1){\n console.log('YES');\n }else if(w <= 0 && d <= w && answer == 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nconst calculate = (p, s) => {\n let up = 0\n let down = 0\n let left = 0\n let right = 0\n s = [...s]\n s.forEach(val => {\n if (val === 'U') {\n up++\n } else if (val === 'D') {\n down++\n } else if (val === 'L') {\n left++\n } else {\n right++\n }\n })\n\n const [x, y] = p\n\n if (y > 0) {\n if (y > up) {\n return 'NO'\n }\n } else {\n if (Math.abs(y) > down) {\n return 'NO'\n }\n }\n\n if (x > 0) {\n if (x > right) {\n return 'NO'\n }\n } else {\n if (Math.abs(x) > left) {\n return 'NO'\n }\n }\n\n return 'YES'\n}\n\nlet index = -1\nlet maxRound = 0\nlet round = 0\n\nlet p, s\nlet answer = []\n\nreadline.on('line', line => {\n if (index === -1) {\n maxRound = Number(line)\n index = 0\n } else {\n const mode = index % 2\n if (mode === 0) {\n p = line.split(' ').map(val => Number(val))\n } else if (mode === 1) {\n s = line\n answer.push(calculate(p, s))\n round++\n if (round === maxRound) {\n readline.close()\n console.log(answer.join('\\n'))\n return\n }\n }\n index++\n }\n})\n"}, {"source_code": "/*\r\n * File Created: Friday, 5th February 2021 3:53:54 pm\r\n * Author: Lukas Rimkus\r\n */\r\n'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(data.shift());\r\n\r\n while(testCases--) {\r\n\r\n const [px,py] = readLine().split(' ').map(Number);\r\n\r\n const s = readLine();\r\n\r\n const res = a(px,py,s);\r\n \r\n console.log(res)\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\n\r\nfunction a(px,py,s)\r\n{\r\n // if px > 0 than search for R else L\r\n // if py > 0 than search for U else D\r\n let U = 0;\r\n let D = 0;\r\n let R = 0;\r\n let L = 0;\r\n for(let i = 0 ; i < s.length; i++){\r\n if(s[i] === 'U') U++;\r\n else if(s[i] === 'D') D++;\r\n else if(s[i] === 'R') R++;\r\n else if(s[i] === 'L') L++;\r\n }\r\n if(px > 0){\r\n if(px > R) return 'NO';\r\n } \r\n if(px < 0) {\r\n if(Math.abs(px) > L) return 'NO';\r\n }\r\n if(py > 0){\r\n if(py > U) return 'NO';\r\n } \r\n if(py < 0) {\r\n if(Math.abs(py) > D) return 'NO';\r\n }\r\n return 'YES'; \r\n}\r\n\r\nmodule.exports = a;"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nconst { Console } = require('console');\r\nconst { EOL } = require('os');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction main() {\r\n const t = +readline();\r\n\r\n for (let i = 0; i < t; i += 1) {\r\n const [x, y] = readline().split(' ').map(num => +num);\r\n const s = readline().split('');\r\n\r\n let xres = s.filter(item => item === (x < 0 ? 'L' : 'R')).length >= Math.abs(x);\r\n let yres = s.filter(item => item === (y < 0 ? 'D' : 'U')).length >= Math.abs(y);\r\n\r\n console.log(xres && yres ? 'YES' : 'NO');\r\n }\r\n}\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', () => {\r\n inputString = inputString.split(EOL).map(str => str.trim());\r\n\r\n main();\r\n});\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar x = nextInt();\r\n\t\tvar y = nextInt();\r\n\t\tvar count = {\r\n\t\t\tL : 0,\r\n\t\t\tR : 0,\r\n\t\t\tU : 0,\r\n\t\t\tD : 0\r\n\t\t};\r\n\t\tvar s = next();\r\n\t\tfor(var j = 0; j < s.length; j++){\r\n\t\t\tcount[s[j]]++;\r\n\t\t}\r\n\t\tvar isOK = 0;\r\n\t\tif(x > 0){\r\n\t\t\tif(count.R >= x){\r\n\t\t\t\tisOK++;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tif(count.L >= Math.abs(x)){\r\n\t\t\t\tisOK++;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(y > 0){\r\n\t\t\tif(count.U >= y){\r\n\t\t\t\tisOK++;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tif(count.D >= Math.abs(y)){\r\n\t\t\t\tisOK++;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(isOK == 2){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}"}], "negative_code": [{"source_code": "var t = readline();\r\nfor (var i = 0; i < t; ++i) {\r\n var xy = readline().split(' ') , x = xy[0] , y = xy[1],\r\n s = readline().split('') , u = 0 , d = 0 , r = 0 , l = 0;\r\n for(var j = 0 ; j < s.length ; ++j){\r\n switch (s[j]) {\r\n case 'U':\r\n u++;\r\n break;\r\n case 'D':\r\n d++;\r\n break;\r\n case 'R':\r\n r++;\r\n break;\r\n case 'L':\r\n l++;\r\n break;\r\n }\r\n }\r\n if( x > 0 && r >= x){\r\n if(y > 0 && u >= y || y < 0 && d >= -1 * y){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }\r\n else if( x < 0 && l >= -1 * x){\r\n if(y > 0 && u >= y || y < 0 && d >= -1 * y){\r\n print(\"YES\");\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n }\r\n else{\r\n print(\"NO\");\r\n }\r\n}"}, {"source_code": "const T = parseInt(readline());\n\nfor (t = 0; t < T; t++) {\n\tconst dest = readline().split(\" \").map(x => parseInt(x));\n\tconst s = readline();\n\tvar u = 0, d = 0, r = 0, l = 0;\n\tfor (i = 0; i < s.length; i++) {\n\t\tif (s[i] === 'U') u++;\n\t\tif (s[i] === 'D') d--;\n\t\tif (s[i] === 'R') r++;\n\t\tif (s[i] === 'L') l--;\n\t}\n\n\tvar ok = dest[0] <= r && dest[0] >= l && dest[1] <= u && dest[1] >= d;\n\tprint(ok ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "\"use strict\"\r\n\r\nfunction searchPath(path) {\r\n let mas = {\r\n r: 0,\r\n l: 0,\r\n u: 0,\r\n d: 0\r\n }\r\n for (let i = 0; i < path.length; i++) {\r\n if (path[i] == 'R') {\r\n mas.r++;\r\n } else if (path[i] == 'L') {\r\n mas.l++;\r\n } else if (path[i] == 'U') {\r\n mas.u++;\r\n } else if (path[i] == 'D') {\r\n mas.d++;\r\n }\r\n }\r\n return mas;\r\n}\r\n\r\nfunction checkNav(x, y, path) {\r\n if (x > 0 && y > 0) {\r\n if (path.r >= x && path.u >= y) {\r\n return \"YES\";\r\n }\r\n } else if (x > 0 && y < 0) {\r\n if (path.r >= x && path.d >= Math.abs(y)) {\r\n return \"YES\";\r\n }\r\n } else if (x < 0 && y > 0) {\r\n if (path.l >= Math.abs(x) && path.u >= y) {\r\n return \"YES\";\r\n }\r\n } else if (x < 0 && y < 0) {\r\n if (path.l >= Math.abs(x) && path.d >= Math.abs(y)) {\r\n return \"YES\";\r\n }\r\n }\r\n return \"NO\";\r\n}\r\n\r\n\r\nlet n = readline();\r\n\r\nfor (let i = 0; i < n; i++) {\r\n let temp = readline().split(' ');\r\n let x = temp[0];\r\n let y = temp[1];\r\n let str = readline();\r\n let path = searchPath(str);\r\n print(checkNav(x, y, path));\r\n}"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n var m = 0;\n var xyes = false;\n var yyes = false;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var d = lines[j].split(' ').map(Number);\n e = d[0];\n m = d[1];\n }else{\n xyes = false;\n yyes = false;\n var k = lines[j].split('');\n var a = 0;\n var b = 0;\n var u = 0;\n var c = 0;\n for(var l = 0; l < k.length; l++){\n if(e > 0){\n if(k[l] == 'R'){\n a++;\n }\n if(a == e){\n xyes = true;\n }\n }else{\n if(k[l] == 'L'){\n b--;\n }\n if(b == e){\n xyes = true;\n }\n }\n if(m > 0){\n if(k[l] == 'U'){\n u++;\n }\n if(u == m){\n yyes = true;\n }\n }else{\n if(k[l] == 'D'){\n c--;\n }\n if(c == m){\n yyes = true;\n }\n }\n }\n if(xyes === true && yyes === true){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n}); "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n var w = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n var o = lines[j].split(' ').map(Number);\n e = o[0];\n w = o[1];\n }else{\n var k = lines[j].split('');\n var x = 0;\n var y = 0;\n var r = 0;\n var L = 0;\n var d = 0;\n var u = 0;\n for(var l = 0; l < k.length; l++){\n if(e > 0){\n if(k[l] == 'R'){\n r++;\n }\n }else{\n if(k[l] == 'L'){\n L--;\n }\n }\n if(w > 0){\n if(k[l] == 'U'){\n u++;\n }\n }else{\n if(k[l] == 'D'){\n d--;\n }\n }\n }\n var answer = 0;\n if(e > 0 && r >= e){\n answer = 1;\n }else if(e < 0 && L <= e){\n answer = 1;\n }\n if(w > 0 && u >= w && answer == 1){\n console.log('YES');\n }else if(w < 0 && d <= w && answer == 1){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n }\n});"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let arr = readline().split(' ').map(x => +x)\n let px = arr[0]\n let py = arr[1]\n let directionString = readline()\n let dirToGo = ''\n // ========= SOLUTION ==============\n if (px > 0 && py > 0 || (px > 0 || py > 0))\n dirToGo = 'UR'\n else if (px > 0 && py < 0 || (px > 0 || py < 0))\n dirToGo = 'DR'\n else if (px < 0 && py > 0 || (px < 0 || py > 0))\n dirToGo = 'UL'\n else if (px < 0 && py < 0 || (px < 0 || py < 0))\n dirToGo = 'DL'\n\n let currX = 0, currY = 0\n for (let i = 0; i < directionString.length && ( px != currX || py != currY); i++){\n if( directionString[i] == 'R' && (dirToGo == 'DR' || dirToGo == 'UR')){\n if(currX < px)\n currX++\n } else if( directionString[i] == 'L' && (dirToGo == 'UL' || dirToGo == 'DL')){\n if(currX > px)\n currX--\n } else if( directionString[i] == 'U' && (dirToGo == 'UL' || dirToGo == 'UR')){\n if(currY < py)\n currY++\n } else if( directionString[i] == 'D' && (dirToGo == 'DL' || dirToGo == 'DR')){\n if(currY > py)\n currY--\n }\n // console.log('currX = ' + currX + ' | currY = ' + currY)\n }\n if (px == currX && py == currY)\n console.log('YES')\n else\n console.log('NO')\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main() \n});\n\nfunction readline() {\n return inputString[currentLine++]\n}\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let testCases = readline()\n while(testCases--)\n solve()\n}\n\n// function to solve problems\nfunction solve (){\n let arr = readline().split(' ').map(x => +x)\n let px = arr[0]\n let py = arr[1]\n let directionString = readline()\n let dirToGo = ''\n // ========= SOLUTION ==============\n if (px > 0 && py > 0 )\n dirToGo = 'UR'\n else if (px > 0 && py < 0)\n dirToGo = 'DR'\n else if (px < 0 && py > 0 )\n dirToGo = 'UL'\n else if (px < 0 && py < 0)\n dirToGo = 'DL'\n \n let currX = 0, currY = 0\n for (let i = 0; i < directionString.length && ( px != currX || py != currY); i++){\n if( directionString[i] == 'R' && (dirToGo == 'DR' || dirToGo == 'UR')){\n if(currX < px)\n currX++\n } else if( directionString[i] == 'L' && (dirToGo == 'UL' || dirToGo == 'DL')){\n if(currX > px)\n currX--\n } else if( directionString[i] == 'U' && (dirToGo == 'UL' || dirToGo == 'UR')){\n if(currY < py)\n currY++\n } else if( directionString[i] == 'D' && (dirToGo == 'DL' || dirToGo == 'DR')){\n if(currY > py)\n currY--\n }\n }\n if (px == currX && py == currY)\n console.log('YES')\n else\n console.log('NO')\n}"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [x,y] = readline().split(' ').map(x => Number(x));\r\n var count = {}\r\n var array = readline().split('').map(x => {\r\n count[x] = (count[x] ? count[x] : 0) + 1\r\n });\r\n if(\r\n x>=0 && count['R'] >= x && y >= 0 && count['U'] >= y ||\r\n x>=0 && count['R'] >= x && y <= 0 && count['D'] >= -y ||\r\n x<=0 && count['L'] >= -x && y <= 0 && count['D'] >= -y ||\r\n x<=0 && count['L'] >= -x && y >= 0 && count['U'] >= y\r\n ) return console.log('YES')\r\n console.log('NO')\r\n // console.log(count)\r\n // console.log(x,y)\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\n\r\nfunction main() {\r\n const x = readline();\r\n var answer = []\r\n\r\n // console.log(Number(x))\r\n // 1 1 7\r\n // 6 9, 15, 18\r\n Array(Number(x)).fill(1).map((t, i) => {\r\n var [x,y] = readline().split(' ').map(x => Number(x));\r\n var count = {}\r\n var array = readline().split('').map(x => {\r\n count[x] = (count[x] ? count[x] : 0) + 1\r\n });\r\n if(\r\n x>0 && count['R'] >= x && y > 0 && count['U'] >= y ||\r\n x>0 && count['R'] >= x && y < 0 && count['D'] >= -y ||\r\n x<0 && count['L'] >= -x && y < 0 && count['D'] >= -y ||\r\n x<0 && count['L'] >= -x && y > 0 && count['U'] >= y\r\n ) return console.log('YES')\r\n console.log('NO')\r\n // console.log(count)\r\n // console.log(x,y)\r\n })\r\n\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (b === 0n) return a\r\n return gcd(b, a % b)\r\n}\r\n\r\n"}, {"source_code": "process.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf8\");\r\nlet standardInputString = \"\";\r\nlet currentLine = 0;\r\nfunction readLine() {\r\n return standardInputString[currentLine++];\r\n}\r\nprocess.stdin.on(\"data\", (rawData) => {\r\n standardInputString += rawData;\r\n});\r\nprocess.stdin.on(\"end\", (_) => {\r\n standardInputString = standardInputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((line) => {\r\n return line.trim();\r\n });\r\n main();\r\n});\r\n\r\nfunction main() {\r\n const numArray = (a) => a.split(\" \").map((line) => +line),\r\n cl = console.log,\r\n rl = readLine,\r\n tc = rl();\r\n\r\n for (let i = 0; i < tc; i++) {\r\n const [x, y] = numArray(rl());\r\n const ln2 = rl().split(\"\");\r\n solution(x, y, ln2);\r\n }\r\n /************************Solution****************************************/\r\n function solution(x, y, str) {\r\n // cl(x, y);\r\n let u = (d = l = r = 0);\r\n str.forEach((s) => {\r\n if (s == \"U\") u++;\r\n if (s == \"D\") d--;\r\n if (s == \"L\") l--;\r\n if (s == \"R\") r++;\r\n // if (s == \"U\") y--;\r\n // if (s == \"D\") y++;\r\n // if (s == \"L\") x++;\r\n // if (s == \"R\") x--;\r\n });\r\n // cl(\"X(\", l, r, \")\", \" \", \"Y(\", u, d, \")\");\r\n\r\n if ((x == l || x == r) && (y == u || y == d)) {\r\n cl(\"YES\");\r\n } else {\r\n cl(\"NO\");\r\n }\r\n }\r\n}\r\n"}], "src_uid": "65a64ea63153fec4d660bad1287169d3"} {"source_code": "function myout(t){print(t);}//standard output\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\nfunction Main() {\n var one = myconv(readline(),4);\n var n = one[0];\n var m = one[1];\n var list = {};\n var nlist = myconv(readline(),2);\n var mlist = myconv(readline(),2);\n var mae = 0;\n var ato = 0;\n var count = 1;\n var max = lcm(n,m);\n while(true){\n list[count] = nlist[mae] + mlist[ato];\n count++;\n mae++;\n if(mae >= n){\n mae = 0;\n }\n ato++;\n if(ato >= m){\n ato = 0;\n }\n if(count > max){\n list[0] = list[count-1];\n break;\n }\n }\n var output = [];\n var Q = myconv(readline(),1);\n for(var i = 0; i < Q; i++){\n var t = myconv(readline(),1);\n output.push(list[t % max]);\n }\n myout(output.join(\"\\n\"));\n \n}\nfunction gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}\nfunction lcm(m, n) {return m * n / gcd(m, n);}\nMain();", "positive_code": [{"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet input = [];\nlet yearLength = 0;\n\nrl.on('line', n => {\n input.push(n);\n if (input.length <= (4 + yearLength)) {\n if (input.length === 4 && yearLength === 0) {\n yearLength = Number(n) - 1;\n }\n } else {\n let [ \n sequenceLengths,\n firstSequence,\n secondSequence,\n yearLength,\n ...years \n ] = input;\n firstSequence = firstSequence.split(' ');\n secondSequence = secondSequence.split(' ');\n for (let year of years) {\n year = Number(year);\n const getIndex = (year, sequence) => {\n if (year > sequence.length) {\n return (year % sequence.length) - 1 > -1 ?\n (year % sequence.length) - 1 : sequence.length - 1;\n }\n return year - 1;\n }\n console.log(`${firstSequence[getIndex(year, firstSequence)]\n }${secondSequence[getIndex(year, secondSequence)]}`);\n }\n rl.close();\n }\n});\n\n"}, {"source_code": "let s = '';\n \nprocess.stdin.on('data', function (i) {\n s += i;\n});\n\nprocess.stdin.on('end', function () {\n s = s.trim().split('\\n');\n s.shift()\n let str1 = s.shift().trim().split(' ');\n let str2 = s.shift().trim().split(' ');\n s.shift();\n // console.log(s, str1, str2);\n s.forEach(element => {\n +element.trim();\n console.log(getWord(element, str1) + getWord(element, str2));\n });\n});\n\nfunction getWord(num, arr) {\n let length = arr.length;\n if(num <= length) {\n return arr[num-1]\n } else if(num % length === 0) {\n return arr[length-1];\n } else {\n return arr[num % length - 1];\n }\n}\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n, m] = input.shift().split(' ').map(x => +x);\n const a = input.shift().split(' ');\n const b = input.shift().split(' ');\n const q = +input.shift();\n for (let i = 0; i < q; i++) {\n const x = +input.shift() - 1;\n console.log(a[x % n] + b[x % m]);\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet n, m;\nlet arr1, arr2;\n\nrl.on('line', (d) => {\n if (c === 0) {\n [n, m] = d.split(' ').map(Number);\n c++;\n return;\n }\n\n if (c === 1) {\n arr1 = d.split(' ');\n c++;\n return;\n }\n\n if (c === 2) {\n arr2 = d.split(' ');\n c++;\n return;\n }\n\n if (c === 3) {\n c++;\n return;\n }\n\n console.log(arr1[(+d - 1) % n] + arr2[(+d - 1) % m]);\n\n c++;\n});\n"}, {"source_code": "const processData = (lines) => {\n const [n, m] = lines[0].split(' ')\n const as = lines[1].split(' ')\n const bs = lines[2].split(' ')\n const aLen = as.length\n const bLen = bs.length\n\n const linesNum = +lines[3]\n\n for (const year of lines.slice(4, 4+linesNum)) {\n const numYear = +year\n console.log(as[(numYear-1) % as.length] + bs[(numYear-1) % bs.length])\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n"}, {"source_code": "function main() {\n var nm = readline().split(' ').map(Number);\n var ns = readline().split(' ');\n var ms = readline().split(' ');\n var q = +readline();\n for (var i = 0; i < q; i++) {\n var num = +readline();\n\n print(ns[(num - 1) % nm[0]] + ms[(num - 1) % nm[1]]);\n }\n}\n\nmain();"}, {"source_code": "const readline = require(\"readline\");\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet i = 0;\nlet j;\nlet x;\nlet c1;\nlet c2;\nlet y = [];\n\nconst solver = input => {\n for (let i = 0; i < y.length; i++) {\n let str = '';\n str += (y[i] % c1.length == 0) ? c1[c1.length - 1] : c1[(y[i] % c1.length) - 1];\n str += (y[i] % c2.length == 0) ? c2[c2.length - 1] : c2[(y[i] % c2.length) - 1];\n console.log(str);\n }\n};\n\nrl.question('', (a) => {\n rl.on('line', (l) => {\n if (j == null) {\n if (++i == 3) {\n j = 0;\n x = l;\n }\n if (i == 1) {\n c1 = l.split(' ');\n }\n if (i == 2) {\n c2 = l.split(' ');\n }\n } else {\n y.push(parseInt(l));\n if (++j == x) {\n rl.close();\n }\n }\n })\n\n rl.on('close', () => {\n solver();\n })\n});"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet index = 0;\nlet n = [], m = [];\nreadline.on('line', line => {\n if (index === 1) {\n n = line.split(' ');\n }\n if (index === 2) {\n m = line.split(' ');\n }\n if (index > 3) {\n let num = Number(line) - 1;\n console.log(`${n[num % n.length]}${m[num % m.length]}`)\n }\n index++;\n});\n\n// readline.on(\"close\", () => {\n// console.log(count, values);\n// });\n"}, {"source_code": "let fs=require(\"fs\");\n\nlet txt=fs.readFileSync(0,\"utf-8\").split(/[\\r\\n]/).filter(data=>data.length>0);\n\ntxt.shift();\nlet info=txt[0].split(\" \").filter(data=>data.length>0);\nlet info1=txt[1].split(\" \").filter(data=>data.length>0);\n\nfor (let i = 3; i < txt.length; i++) {\n doit(info,info1,txt[i]);\n \n}\n\nfunction doit(tab,tab1,num){\n let str=(num%tab.length-1>=0)?tab[num%tab.length-1]:tab[tab.length-1];\n let str1=(num%tab1.length-1>=0)?tab1[num%tab1.length-1]:tab1[tab1.length-1];\n console.log(str.concat(str1));\n}"}, {"source_code": "readline()\nvar a = readline().trim().split(' ')\nvar b = readline().trim().split(' ')\nvar q = parseInt(readline())\nvar inputs = []\nwhile (q != 0) {\n q--;\n inputs.push(parseInt(readline()))\n}\nprint(inputs.map(z => a[(z - 1) % a.length] + b[(z - 1) % b.length]).join(\"\\n\"))"}, {"source_code": "var str = readline();\n\nvar str_n = str.split(' ')[0];\nvar str_m = str.split(' ')[1];\n\nvar n = readline();\nn = arrsplit(n);\n\nvar m = readline();\nm = arrsplit(m);\n\nfunction arrsplit (arr) {\n\treturn arr.split(' ');\n}\n\nvar q = readline();\nvar arrountp = [];\n\nfunction years (q) {\n\n\tfor (var i = 0; i < q; i++) {\n\t\tvar qq = readline();\n\t\tqq = qq - 1;\n\t\tprint(n[qq - str_n * Math.floor(qq/str_n)] + m[qq - str_m * Math.floor(qq/str_m)]);\n\t}\n\n\treturn;\n}\n\nyears(q)"}, {"source_code": "// Getting problem data from codeforces.\nvar nm = readline().split(' ').map(function(e){\n return parseInt(e);\n});\nvar s = readline().split(' '),t = readline().split(' ');\n// Entertaining queries.\nvar queryCount = parseInt(readline());\nfor(var i = 0; i {\n +element.trim();\n console.log(getWord(element, str1) + getWord(element, str2));\n });\n});\n\nfunction getWord(num, arr) {\n let length = arr.length;\n if(num <= length) {\n return arr[num-1]\n } else if(num % length === 0) {\n return arr[length-1];\n } else {\n return arr[num % length - 1];\n }\n}\n"}, {"source_code": "const processData = (lines) => {\n const [n, m] = lines[0].split(' ')\n const as = lines[1].split(' ')\n const bs = lines[2].split(' ')\n const aLen = as.length\n const bLen = bs.length\n\n for (const year of lines.slice(4)) {\n\n const numYear = +year\n console.log(as[(numYear-1) % as.length] + bs[(numYear-1) % bs.length])\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n"}, {"source_code": "const processData = (lines) => {\n const [n, m] = lines[0].split(' ')\n const as = lines[1].split(' ')\n const bs = lines[2].split(' ')\n const aLen = as.length\n const bLen = bs.length\n \n for (const year of lines.slice(4)) {\n\n const numYear = +year\n if (numYear > 0 && numYear <= 2020) {\n console.log(as[(numYear-1) % as.length] + bs[(numYear-1) % bs.length])\n }\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n"}, {"source_code": "const processData = (lines) => {\n const [n, m] = lines[0].split(' ')\n const as = lines[1].split(' ')\n const bs = lines[2].split(' ')\n const aLen = as.length\n const bLen = bs.length\n\n for (const year of lines.slice(4)) {\n const numYear = +year\n console.log(as[(numYear-1) % as.length] + bs[(numYear-1) % bs.length])\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n"}, {"source_code": "const processData = (lines) => {\n const [n, m] = lines[0].split(' ')\n const as = lines[1].split(' ')\n const bs = lines[2].split(' ')\n const aLen = as.length\n const bLen = bs.length\n\n for (const year of lines.slice(3)) {\n const numYear = +year\n console.log(as[numYear % as.length] + bs[numYear % bs.length])\n }\n}\n\nlet i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n processData(lines)\n})\n\n"}, {"source_code": "var str = readline();\n\nvar str_n = str.split(' ')[0];\nvar str_m = str.split(' ')[1];\n\nvar n = readline();\nn = arrsplit(n);\n\nvar m = readline();\nm = arrsplit(m);\n\nfunction arrsplit (arr) {\n\treturn arr.split(' ');\n}\n\nvar q = readline();\nvar arrountp = [];\n\nfunction years (q) {\n\n\tfor (var i = 0; i < q; i++) {\n\t\tvar qq = readline();\n\t\tqq = qq - 1;\n\t\tarrountp.push(n[qq - str_n * Math.floor(qq/str_n)] + m[qq - str_m * Math.floor(qq/str_m)]);\n\t}\n\n\treturn arrountp;\n}\n\nprint(years(q))"}, {"source_code": "// Getting problem data from codeforces.\nvar nm = readline().split(' ').map(function(e){\n return parseInt(e);\n});\nvar s = readline().split(' '),t = readline().split(' ');\n// Entertaining queries.\nvar queryCount = parseInt(readline());\nfor(var i = 0; i {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n current = d;\n c++;\n return;\n }\n\n solve = d;\n\n c++;\n});\n\nrl.on('close', () => {\n let ans = 0;\n\n for (let i = 0; i < current.length; i++) {\n const v = Math.abs(+current[i] - +solve[i]);\n ans += Math.min(v, 10 - v);\n }\n\n console.log(ans);\n});\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const lock = input[1];\n const code = input[2];\n\n let answ = 0;\n\n for (let i = 0; i < lock.length; i += 1) {\n if (lock[i] === code[i]) continue;\n\n if (parseInt(lock[i]) > parseInt(code[i])) {\n answ += Math.min(\n parseInt(lock[i]) - parseInt(code[i]),\n 9 - parseInt(lock[i]) + parseInt(code[i]) + 1,\n );\n } else {\n answ += Math.min(\n parseInt(code[i]) - parseInt(lock[i]),\n parseInt(lock[i]) + (9 - parseInt(code[i]) + 1)\n );\n }\n\n }\n\n console.log(answ);\n}); "}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\n//console.log('data', data);\n\n//const lines = data.split(\"\\n\");\nconst lines = data.split(\"\\r\\n\");\n\n//console.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\t//console.log('o', o)\n\t//console.log('n', n)\n\t//console.log('d', d)\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "var n = +readline(), start = readline(), end = readline(), acts = 0;\n\nfor(i = 0; i < n; i++){\n\tif( (Math.abs(+end[i] - +start[i])) > 5 ){\n\t\tacts += 10 - Math.abs(+end[i] - +start[i]);\n\t}\n\telse{\n\t\tacts += Math.abs(+end[i] - +start[i]);\n\t}\n}\n\nwrite(acts);"}, {"source_code": "var input =parseInt(readline());\nvar arr=readline().split('').map(a => parseInt(a));\n\nvar res = readline().split('').map(a => parseInt(a));\nvar sum=0;\nfor(var i=0; i need[i]) ? curr[i] - need[i] : need[i] - curr[i]);\n sum[1] = (curr[i] > need[i]) ? 10-parseInt(curr[i])+parseInt(need[i]) : 10-parseInt(need[i])+parseInt(curr[i]);\n res += parseInt((sum[0] > sum[1]) ? sum[1] : sum[0]);\n}\nprint(res);"}, {"source_code": "function toi(x){return parseInt(x);}\nfunction getNumber(a,t){\n var c=Math.abs(a-t);\n return Math.min(c,10-c);\n} \nvar n=toi(readline());\nvar s0=readline().split(\"\").map(toi);\nvar s1=readline().split(\"\").map(toi);\nvar res=0;\nfor(var i=0;i b) {\n var c = a;\n a = b;\n b = c;\n }\n\n return Math.min(b - a, 10 + a - b);\n}\n\nvar n = parseInt(readline());\n\nvar a = readline();\nvar b = readline();\n\nvar s = 0;\n\nfor (var i = 0; i < n; i ++) {\n s += getMinStep(parseInt(a[i]), parseInt(b[i]));\n}\n\nwrite(s);\n"}], "negative_code": [{"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n const [n] = input[0].split(' ').map(x => parseInt(x));\n const lock = input[1];\n const code = input[2];\n\n let answ = 0;\n\n for (let i = 0; i < lock.length; i += 1) {\n if (lock[i] === code[i]) continue;\n\n answ += Math.min(\n 9-lock[i]+code[i] - 1,\n Math.abs(code[i]-lock[i])\n )\n }\n\n console.log(answ);\n}); "}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\nconst lines = data.split(\"\\r\");\n\nconsole.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\tconsole.log('o', o)\n\tconsole.log('n', n)\n\tconsole.log('d', d)\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\nconst lines = data.split(\"\\n\");\n\n//console.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\nconst lines = data.split(\"\\n\");\n\nconsole.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\tconsole.log('o', o)\n\tconsole.log('n', n)\n\tconsole.log('d', d)\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\nconst lines = data.split(\"\\n\");\n\nconsole.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "const fs = require('fs');\nconst data = fs.readFileSync(0, 'utf-8');\n\nconsole.log('data', data);\n\nconst lines = data.split(\"\\r\\n\");\n\nconsole.log(lines);\n\nconst origCombo = lines[1];\nconst newCombo = lines[2];\n\n//console.log(\"l1\", origCombo[0]);\n//console.log(\"l2\", newCombo[0]);\n\n//console.log(\"origcombolen\", origCombo.length)\n\nvar total = 0\n\nfor(var i = 0; i < origCombo.length; i++)\n{\n\tconst o = parseInt(origCombo[i]);\n\tconst n = parseInt(newCombo[i]);\n\n\tconst d = Math.abs(o-n);\n\n\tconsole.log('o', o)\n\tconsole.log('n', n)\n\tconsole.log('d', d)\n\n\tif(d > 5){\n\t\ttotal += 10 - d\n\t} else {\n\t\ttotal += d\n\t}\n\n}\n\nconsole.log(total);\n\n"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(x) {return +x;});\nvar b = readline().split(' ').map(function(x) {return +x;});\nvar res = 0;\nfor (var i = 0; i < n; i ++) res += Math.min(Math.abs(a[i] - b[i]), 10 - Math.abs([i] - b[i]));\nprint(res);"}, {"source_code": "var n = +readline();\nvar a = readline().split('').map(function(x) {return +x;});\nvar b = readline().split('').map(function(x) {return +x;});\nvar res = 0;\nfor (var i = 0; i < n; i ++) res += Math.min(Math.abs(a[i] - b[i]), 10 - Math.abs([i] - b[i]));\nprint(res);"}, {"source_code": "var nline = readline();\nvar n = parseInt(nline);\n\nvar str1 = readline().split('').map(Number);\nvar str2 = readline().split('').map(Number);\n\nvar count=0;\n\nfor(i=0;i<5;i++){\n var diff = Math.abs(str1[i]-str2[i]);\n if(diff<=10-diff){\n\tcount+=diff;\n } else{\n\tcount+=(10-diff);\n }\n}\n\nprint(count);"}, {"source_code": "no = +readline();\npassword = readline().split('').map(Number);\ncode = readline().split('').map(Number);\nvar t = 0;\nvar stepD = 0;\nvar stepE = 0;\nvar sum = 0;\n\nfor (var i = 0; i < no; i++) {\n\t\t\t\t var d = parseInt(password[i]);\n\t\t\t\t var e = d;\n\t\t\t\t var f = parseInt(code[i]);\n\t\t\t\t while( d != f && e != f ){\n\t\t\t\t\t \t\t\t\tif( d == 10 ) d = 0;\n\t\t\t\t\t\t\t\t\tif( e == -1 ) e = 9;\n\t\t\t\t\t\t\t\t\td++, e--, t++;\n\t\t\t\t\t\t\t\t\tif( d == f )\n\t\t\t\t\t\t\t\t\t\t\tstepD = t;\n\t\t\t\t\t\t\t\t\tif( e == f )\n\t\t\t\t\t\t\t\t\t\t\tstepE = t;\n\t\t\t\t }\n\t\t\t\t sum += Math.min(stepE,stepD);\n}\n\nwrite(sum);\n"}, {"source_code": "no = +readline();\npassword = readline().split('').map(Number);\ncode = readline().split('').map(Number);\nvar t = 0;\n\nvar sum = 0;\n\nfor (var i = 0; i < no; i++) {\n\t\t\t\t var d = parseInt(password[i]);\n\t\t\t\t var e = parseInt(password[i]);\n\t\t\t\t var f = parseInt(code[i]);\n\t\t\t\t while( d != f && e != f ){\n\t\t\t\t\t \t\t\t\tif( d == 10 ) d = 0;\n\t\t\t\t\t\t\t\t\tif( e == -1 ) e = 9;\n\t\t\t\t\t\t\t\t\td++, e--, t++;\n\t\t\t\t\t\t\t\t\tif( d == f ){\n\t\t\t\t\t\t\t\t\t\t sum += t;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif( e == f ){\n\t\t\t\t\t\t\t\t\t\t\t\tsum += t;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t }\n}\n\nwrite(sum);\n"}, {"source_code": "no = +readline();\npassword = readline().split('').map(Number);\ncode = readline().split('').map(Number);\nvar t = 0;\nvar sum = 0;\n\nfor (var i = 0; i < no; i++) \n\t\t\t\t sum += Math.min(Math.abs(password[i] - code[i]), 10 - password[i] - code[i]);\n\nwrite(sum);\n\n\n"}, {"source_code": "no = +readline();\npassword = readline().split('').map(Number);\ncode = readline().split('').map(Number);\nvar t = 0;\nvar sum = 0;\n\nfor (var i = 0; i < no; i++) {\n\t\t\t\t var d = parseInt(password[i]);\n\t\t\t\t var e = d;\n\t\t\t\t var f = parseInt(code[i]);\n\t\t\t\t while( d != f && e != f ){\n\t\t\t\t\t \t\t\t\tif( d == 10 ) d = 0;\n\t\t\t\t\t\t\t\t\tif( e == -1 ) e = 9;\n\t\t\t\t\t\t\t\t\td++, e--, t++;\n\n\t\t\t\t }\n\t\t\t\t sum += t;\n}\n\nwrite(sum);\n"}, {"source_code": "no = +readline();\npassword = readline().split('').map(Number);\ncode = readline().split('').map(Number);\nvar t = 0;\nvar stepD;\nvar stepE;\nvar sum = 0;\n\nfor (var i = 0; i < no; i++) {\n\t\t\t\t var d = parseInt(password[i]);\n\t\t\t\t var e = d;\n\t\t\t\t var f = parseInt(code[i]);\n\t\t\t\t while( d != f && e != f ){\n\t\t\t\t\t \t\t\t\tif( d == 10 ) d = 0;\n\t\t\t\t\t\t\t\t\tif( e == -1 ) e = 9;\n\t\t\t\t\t\t\t\t\td++, e--, t++;\n\t\t\t\t\t\t\t\t\tif( d == f )\n\t\t\t\t\t\t\t\t\t\t\tstepD = t;\n\t\t\t\t\t\t\t\t\tif( e == f )\n\t\t\t\t\t\t\t\t\t\t\tstepE = t;\n\t\t\t\t }\n\t\t\t\t sum += Math.min(stepE,stepD);\n}\n\nwrite(sum);\n"}], "src_uid": "5adb1cf0529c3d6c93c107cf72fa5e0b"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const [a, b, c, r] = d.split(' ').map(Number);\n const leftR = c - r;\n const rightR = c + r;\n const min = Math.min(a, b);\n const max = Math.max(a, b);\n\n if (max < leftR || min > rightR) {\n console.log(max - min);\n return;\n }\n\n if (min <= leftR && max >= rightR) {\n console.log(max - min - (rightR - leftR));\n return;\n }\n\n if (min >= leftR && max <= rightR) {\n console.log(0);\n return;\n }\n\n if (min >= leftR && max > rightR) {\n console.log(max - rightR);\n return;\n }\n\n if (min < leftR && max <= rightR) {\n console.log(leftR - min);\n return;\n }\n\n count++;\n});\n", "positive_code": [{"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n let [a, b, c, r] = arr[j].split(' ').map(a => parseInt(a))\n\n if(a > b) {\n let temp = a\n a = b\n b = temp\n }\n let sum = 0\n if(c < b && c > a) {\n // wr('h1')\n sum += max(0, c - r - a)\n sum += max(0, b - c - r)\n }\n else if(c >= b) {\n // wr('h2')\n let x = min(b - a, c - r - a)\n x > 0 ? sum = x : sum = 0\n }\n else {\n // wr('h3')\n let x = min(b - a, b - (c + r))\n x > 0 ? sum = x : sum = 0\n }\n wr(sum)\n }\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction max(...x) {\n return Math.max(...x)\n}\n\nfunction min(...x) {\n return Math.min(...x)\n}\n\nfunction mod(a, m) {\n let x = a % m\n if(x >= 0 ) return x\n else return m + x \n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n const [a, b, c, r] = d.split(' ').map(Number);\n const L = c - r;\n const R = c + r;\n const leftInt = Math.max(L, Math.min(a, b));\n const rightInt = Math.min(R, Math.max(a, b));\n const ans = Math.abs(a - b) - Math.max(0, rightInt - leftInt);\n\n console.log(ans);\n\n // const leftR = c - r;\n // const rightR = c + r;\n // const min = Math.min(a, b);\n // const max = Math.max(a, b);\n\n // if (max < leftR || min > rightR) {\n // console.log(max - min);\n // return;\n // }\n\n // if (min <= leftR && max >= rightR) {\n // console.log(max - min - (rightR - leftR));\n // return;\n // }\n\n // if (min >= leftR && max <= rightR) {\n // console.log(0);\n // return;\n // }\n\n // if (min >= leftR && max > rightR) {\n // console.log(max - rightR);\n // return;\n // }\n\n // if (min < leftR && max <= rightR) {\n // console.log(leftR - min);\n // return;\n // }\n\n count++;\n});\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readALine() {\n return inputString[currentLine++];\n}\n\nfunction printALine(str) {\n console.log(str);\n}\n\nfunction stringArrayToNumbers(str) {\n var array = str.split(\" \");\n var result = [];\n for( var i = 0; i < array.length; i++ ) {\n result.push( parseInt(array[i]) );\n }\n return result;\n}\n\n// ======================================================\n// A. Temporarily unavailable\n// ======================================================\n\nfunction doIt( a, b, c, r ) {\n \n var result = 0;\n \n // Make a less than b.\n var a1 = a; var b1 = b;\n if( a > b ) {\n a1 = b; b1 = a;\n }\n \n // Define bounds of c1 and c2.\n var c1 = c-r; var c2 = c+r;\n \n //printALine(\"---------------\");\n //printALine(\"a1 = \" + a1 + \" b1 = \" + b1); \n \n if( (a1 > c1 && b1 > c1) && (a1 > c2 && b1 > c2) ) {\n //printALine(\"A\"); \n result = b1 - a1; // always available.\n } \n else if( (a1 < c1 && b1 < c1) && (a1 < c2 && b1 < c2) ) {\n //printALine(\"B\");\n result = b1 - a1; // always available.\n } \n else {\n \n var r1 = c1 - a1;\n var r2 = b1 - c2;\n\n\n //printALine(\"c1 - a1 = \" + c1 + \" - \" + a1 + \" = \" + r1);\n //printALine(\"b1 - c2 = \" + b1 + \" - \" + c2 + \" = \" + r2);\n \n if( r1 > 0 ) result += r1;\n if( r2 > 0 ) result += r2;\n \n /*\n for( var i = a1; i < b1; i++ ) {\n //printALine(\" if \" + i + \" < \" + c1 + \" || \" + i + \" >= \" + c2 + \" increment\");\n if( i < c1 || i >= c2 ) {\n result++;\n }\n } \n */\n }\n \n return result;\n}\n\nfunction main() {\n\n var numOfTests = readALine();\n for( var i = 0; i < numOfTests; i++ ) {\n \n var string = readALine();\n var numArray = stringArrayToNumbers(string);\n var result = doIt( numArray[0], numArray[1], numArray[2], numArray[3] );\n printALine(result);\n \n }\n\n}\n\n\n\n\n\n"}, {"source_code": "//18:58\n//13:03\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nlet input_stdin = \"\";\nlet input = \"\";\nlet input_currentline = 0;\n\nfunction readLine() {\n return input[input_currentline++];\n}\n\nprocess.stdin.on('data', function (data) {\n input_stdin += data;\n});\n\nprocess.stdin.on('end', function () {\n input = input_stdin.split(\"\\n\");\n main();\n});\n\n// your code goes here\nfunction main() {\n const T=parseInt(readLine());\n for(let k = 0; k < T; k++) {\n //console.log('Case #' + (k+1) + ': ' + solve());\n console.log(solve());\n }\n}\n\nfunction solve() {\n const line = readLine();\n let a = Number(line.split(' ')[0]);\n let b = Number(line.split(' ')[1]);\n const c = Number(line.split(' ')[2]);\n const r = Number(line.split(' ')[3]);\n\n if (a>b) {\n \tlet temp = a;\n \ta = b;\n \tb = temp;\n }\n let inter = 0;\n if (c b) {\n \tinter = Math.max(b - (c - r), 0); //8-(10-4)\n } else {\n \tinter = Math.min(r, c-a) + Math.min(r, b - c);\n }\n\n return Math.max(b-a-inter, 0); \n}\n"}], "negative_code": [], "src_uid": "783772cb7a54bf65f648d3f8b7648263"} {"source_code": "var t= parseInt(readline());\r\nwhile(t--)\r\n{\r\n var n=parseInt(readline());\r\n var arr=readline().split(' ').map(x=>parseInt(x));\r\n var sum=0;\r\n for(var i=0; i inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n \r\n let l = 0;\r\n let r = n - 1;\r\n\r\n while (l < n) {\r\n if (arr[l] === 0) {\r\n break;\r\n } else {\r\n l++\r\n }\r\n }\r\n if (l === n) {\r\n output(0);\r\n continue;\r\n }\r\n\r\n while (r >= 0) {\r\n if (arr[r] === 0) {\r\n break;\r\n } else {\r\n r--\r\n }\r\n }\r\n\r\n output(r - l + 2);\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tvar L = 0;\r\n\t\tvar R = N - 1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 1){\r\n\t\t\t\tL++;\r\n\t\t\t}else{\r\n\t\t\t\tL--;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(var i = N - 1; i >= 0; i--){\r\n\t\t\tif(list[i] == 1){\r\n\t\t\t\tR--;\r\n\t\t\t}else{\r\n\t\t\t\tR++;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\toutput = Math.max(0, R - L);\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let i = 1;\r\n while (i < ls.length){\r\n const len = ls[i++];\r\n const arr = ls[i++].split(' ');\r\n const fi = arr.indexOf('0');\r\n const li = arr.lastIndexOf('0');\r\n if (fi == -1){\r\n console.log('0');\r\n continue;\r\n }\r\n console.log(li - fi + 2);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let size = readline();\n let arr = readline();\n\n let firstZero = null;\n let lastZero = null;\n\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] === \"0\") {\n lastZero = i;\n if (firstZero === null) {\n firstZero = i;\n }\n }\n }\n if (firstZero) {\n // console.log(lastZero, firstZero);\n console.log((lastZero + 1) / 2 - (firstZero + 1) / 2 + 2);\n } else {\n console.log(0);\n }\n }\n}\n"}, {"source_code": "function solve() {\r\n const n = Number(read());\r\n const arr = readArray(Number);\r\n let firstZeroIndex;\r\n let lastZeroIndex;\r\n for (let i = 0; i < n; i++) {\r\n const x = arr[i];\r\n if (x !== 0) {\r\n continue;\r\n }\r\n if (typeof firstZeroIndex === 'undefined') {\r\n firstZeroIndex = i;\r\n }\r\n lastZeroIndex = i;\r\n }\r\n if (typeof firstZeroIndex === 'undefined') {\r\n write(0);\r\n return;\r\n }\r\n write(lastZeroIndex - firstZeroIndex + 2);\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction pDivCount(n) {\r\n let ans = 0;\r\n let i = 1;\r\n while(n > 1) {\r\n i++;\r\n while(n % i === 0) {\r\n ans++;\r\n n = Math.floor(n / i);\r\n }\r\n }\r\n return ans;\r\n}\r\n\r\nfunction gcd(a, b) {\r\n if (a === 0) {\r\n return b;\r\n }\r\n return gcd(b % a, a);\r\n}\r\n\r\nfunction lcm(a, b) {\r\n return Math.floor(a / gcd(a, b)) * b;\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T;\r\n T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e);\r\n }\r\n}\r\n\r\nfunction readArray(mapF) {\r\n var res = read().split(' ');\r\n if (mapF) {\r\n res = res.map(mapF);\r\n }\r\n return res;\r\n}\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var inTextName;\r\n var outTextName;\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\\r\\n');\r\n}\r\ninit();\r\n \r\nfunction write(value) {\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n if (isNode) {\r\n return MEMORY;\r\n }\r\n var res = [];\r\n var x;\r\n while (x = read()) {\r\n res.push(x);\r\n }\r\n return res;\r\n}\r\n"}, {"source_code": "var t = parseInt(readline())\r\n \r\nwhile(t--){\r\n var n = parseInt(readline())\r\n var arr = readline().split(' ').map(x => parseInt(x))\r\n \r\n var start = 0\r\n var end = n-1\r\n for(var i = 0;i=0;j--){\r\n if(arr[j] == 0){\r\n end = j;\r\n break;\r\n }\r\n }\r\n \r\n if((end - start) == (n-1))\r\n print(0)\r\n else\r\n print(end-start+2)\r\n \r\n}\r\n"}, {"source_code": "var t = +readline();\r\nwhile (t-->0){\r\n var n = +readline();\r\n var ar = readline().split(' ').map(Number);\r\n var first = 0, last = -2;\r\n for (var i=1;i stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ans = 0;\n var left = 0, right = n - 1;\n while(left + 1 < n && k[left + 1] == 1){\n left++;\n }\n while(right > 0 && k[right - 1] == 1){\n right--;\n }\n var a = right - left;\n console.log(a > 0 ? a : 0);\n }\n }\n \n}); "}, {"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => { \n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n var n = 0;\n for(i = 1; i <= t * 2; i++){\n if(i % 2 == 1){\n n = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var ans = 0;\n var left = 0, right = n - 1;\n while(left + 1 < n && k[left + 1] == 1){\n left++;\n }\n while(right > 0 && k[right - 1] == 1){\n right--;\n }\n ans = right - left;\n console.log(ans > 0 ? ans : 0);\n }\n }\n \n}); "}], "negative_code": [{"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(i = 1; i <= n * 2; i++){\n if(i % 2 == 1){\n e = lines[i];\n }else{\n var k = lines[i].split(' ').map(Number);\n var o = 0;\n var z = 0;\n for(j = 0; j < e; j++){\n if(k[j] == 1){\n o++;\n }else{\n z++;\n }\n }\n console.log(z * 2);\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n let arr = readline().split(' ').map(Number);\r\n \r\n let onWater = false;\r\n let water = 0;\r\n let total = 0;\r\n for (let i = 0; i < arr.length; i++) {\r\n if (arr[i] === 0) {\r\n onWater = true;\r\n water++;\r\n } else if (onWater) {\r\n onWater = false;\r\n total += water + 1;\r\n water = 0;\r\n }\r\n }\r\n\r\n output(total);\r\n }\r\n}\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar output = 0;\r\n\t\tvar cost = 1;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tif(list[i] == 0){\r\n\t\t\t\tcost++;\r\n\t\t\t}else{\r\n\t\t\t\tif(list[i - 1] == 0){\r\n\t\t\t\t\toutput += cost;\r\n\t\t\t\t\tcost = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var t= readline();\r\nwhile(t--)\r\n{\r\n var n=readline();\r\n var arr=readline().split(' ');\r\n var sum=0;\r\n for(var i=0; iparseInt(x));\r\n var sum=0;\r\n for(var i=0; i parseInt(item));\n const testCase = {\n n,\n m,\n grid: [],\n };\n for (let j = 0; j < n; j++) {\n index++;\n const line = input[index].split(\"\").map((item) => parseInt(item));\n testCase.grid.push(line);\n }\n testCases.push(testCase);\n }\n}\n\nfunction solution(testCase) {\n const { n, m, grid } = testCase;\n // console.log(n, m, grid);\n\n let nb1s = 0;\n const indexesOf1s = new Set();\n grid.forEach((line, i) =>\n line.forEach((cell, j) => {\n if (cell == 1) {\n nb1s++;\n indexesOf1s.add(`${i},${j}`);\n }\n })\n );\n\n let mini1s = Infinity;\n let mini1sIndexes;\n\n const check = ([i1, j1], [i2, j2], [i3, j3]) => {\n if (\n i1 < 0 ||\n i2 < 0 ||\n i3 < 0 ||\n i1 >= n ||\n i2 >= n ||\n i3 >= n ||\n j1 < 0 ||\n j2 < 0 ||\n j3 < 0 ||\n j1 >= m ||\n j2 >= m ||\n j3 >= m\n )\n return;\n // console.log(\"check\", [i1, j1], [i2, j2], [i3, j3]);\n const v = [grid[i1][j1], grid[i2][j2], grid[i3][j3]].filter(\n (v) => v == 1\n ).length;\n if (v < mini1s && v > 0) {\n mini1s = v;\n mini1sIndexes = [\n [i1, j1],\n [i2, j2],\n [i3, j3],\n ];\n }\n };\n\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m - 1; j++) {\n check([i, j], [i, j + 1], [i - 1, j]);\n check([i, j], [i, j + 1], [i + 1, j]);\n check([i, j], [i, j + 1], [i - 1, j + 1]);\n check([i, j], [i, j + 1], [i - 1, j + 1]);\n }\n }\n\n console.log(nb1s - (mini1s == Infinity ? 0 : mini1s - 1));\n}\n\nparseInput();\n\ntestCases.forEach(solution);\n", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar one = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = 0; j < M; j++){\r\n\t\t\t\tif(list[i][j] == \"1\"){\r\n\t\t\t\t\tone++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = one - 2;\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = 0; j < M - 1; j++){\r\n\t\t\t\tif(ok){\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tvar c = 0;\r\n\t\t\t\tc += (list[i][j] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i][j + 1] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i + 1][j] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i + 1][j + 1] == \"0\") ? 1 : 0;\r\n\t\t\t\tif(c >= 2 && !ok){\r\n\t\t\t\t\toutput = one;\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t}else if(c == 1){\r\n\t\t\t\t\toutput = one - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var n, m, mat;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var a = readline().split('').map(x=>parseInt(x));\r\n mat.push(a);\r\n }\r\n var ones = 0;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n ones += mat[i][j];\r\n }\r\n }\r\n if (ones == n * m || ones == n * m - 1 ) {\r\n print(n * m - 2);\r\n continue;\r\n }\r\n var ans = ones;\r\n var diff = 1;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n if (!mat[i][j]) {\r\n if (i != n-1 && !mat[i+1][j]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != m-1 && !mat[i][j+1]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != m-1 && i != n-1 && !mat[i+1][j+1]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != 0 && i != n-1 && !mat[i+1][j-1]) {\r\n diff = 0;\r\n break;\r\n }\r\n }\r\n }\r\n if (!diff) {\r\n break;\r\n }\r\n }\r\n print(ans - diff);\r\n }"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar M = nextInt();\r\n\t\tvar list = nextStrArray(N);\r\n\t\tvar one = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tfor(var j = 0; j < M; j++){\r\n\t\t\t\tif(list[i][j] == \"1\"){\r\n\t\t\t\t\tone++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar output = one - 2;\r\n\t\tvar ok = false;\r\n\t\tfor(var i = 0; i < N - 1; i++){\r\n\t\t\tfor(var j = 0; j < M - 1; j++){\r\n\t\t\t\tvar c = 0;\r\n\t\t\t\tc += (list[i][j] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i][j + 1] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i + 1][j] == \"0\") ? 1 : 0;\r\n\t\t\t\tc += (list[i + 1][j + 1] == \"0\") ? 1 : 0;\r\n\t\t\t\tif(c >= 2 && !ok){\r\n\t\t\t\t\toutput = one;\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t}else if(c == 1){\r\n\t\t\t\t\toutput = one - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(output);\r\n\t}\r\n}\r\n"}, {"source_code": "var n, m, mat;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var a = readline().split('').map(x=>parseInt(x));\r\n mat.push(a);\r\n }\r\n var ones = 0;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n ones += mat[i][j];\r\n }\r\n }\r\n if (ones == n * m || ones == n * m - 1 ) {\r\n print(n * m - 2);\r\n continue;\r\n }\r\n var ans = ones;\r\n var diff = 1;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n if (!mat[i][j]) {\r\n if (i != n-1 && !mat[i+1][j]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != m-1 && !mat[i][j+1]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != m-1 && i != n-1 && !mat[i+1][j+1]) {\r\n diff = 0;\r\n break;\r\n }\r\n }\r\n }\r\n if (!diff) {\r\n break;\r\n }\r\n }\r\n print(ans - diff);\r\n }"}, {"source_code": "var n, m, mat;\r\n\r\n var tests = parseInt(readline());\r\n for (var t=0; tparseInt(x));\r\n n = nm[0];\r\n m = nm[1];\r\n mat = [];\r\n for (var i = 0; i < n; i++) {\r\n var a = readline().split('').map(x=>parseInt(x));\r\n mat.push(a);\r\n }\r\n var ones = 0;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n ones += mat[i][j];\r\n }\r\n }\r\n if (ones == n * m || ones == n * m - 1 ) {\r\n print(n * m - 2);\r\n continue;\r\n }\r\n var ans = ones;\r\n var diff = 1;\r\n for (var i = 0; i < n; i++) {\r\n for (var j = 0; j < m; j++) {\r\n if (!mat[i][j]) {\r\n if (i != n-1 && !mat[i+1][j]) {\r\n diff = 0;\r\n break;\r\n }\r\n if (j != m-1 && !mat[i][j+1]) {\r\n diff = 0;\r\n break;\r\n }\r\n }\r\n }\r\n if (!diff) {\r\n break;\r\n }\r\n }\r\n print(ans - diff);\r\n }"}], "src_uid": "3bf5d493813c5582200eca9248b357d3"} {"source_code": "var str = readline().split(\" \", 2);\nvar k = Number(str[1]);\nvar str = readline();\n\nfunction getChar(str, n) {\n var table = \"abcdefghijklmnopqrstuvwxyz\";\n var index = table.indexOf(str);\n return table[index + n];\n}\n\nvar ans = \"\";\nfor (var i = 0; i < str.length; ++i) {\n if (k === 0) {\n ans += str.slice(i);\n break;\n }\n var dis;\n if (str[i] <= \"m\") {\n dis = \"z\".charCodeAt(0) - str[i].charCodeAt(0);\n if (dis >= k) {\n ans += getChar(str[i], k);\n k = 0;\n } else {\n ans += getChar(str[i], dis);\n k -= dis;\n }\n } else {\n dis = str[i].charCodeAt(0) - \"a\".charCodeAt(0);\n if (dis >= k) {\n ans += getChar(str[i], -k);\n k = 0;\n } else {\n ans += getChar(str[i], -dis);\n k -= dis;\n }\n }\n}\n\nif (k !== 0) {\n print(-1);\n} else {\n print(ans);\n}", "positive_code": [{"source_code": "/* TEST CASE\ninput\n4 26\nbear\noutput\nroar\ninput\n2 7\naf\noutput\ndb\ninput\n3 1000\nhey\noutput\n-1 */\nfunction main() {\n\tvar splitted = readline().split(\" \");\n\tvar n = parseInt(splitted[0]);\n\tvar k = parseInt(splitted[1]);\n\tvar s = readline();\n\tvar r = \"\";\n\tfor (var i = 0; i < n; i++) {\n\t\tvar c = s.charCodeAt(i)\n\t\tvar distToZ = 0x7A - c\n\t\tvar distToA = c - (0x7A - 25);\n\t\tif (distToZ >= distToA) {\n\t\t\tif (distToZ <= k) {\n\t\t\t\tr += 'z';\n\t\t\t\tk -= distToZ;\n\t\t\t} else {\n\t\t\t\tr += String.fromCharCode(c + k);\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t} else {\n\t\t\tif (distToA <= k) {\n\t\t\t\tr += 'a';\n\t\t\t\tk -= distToA;\n\t\t\t} else {\n\t\t\t\tr += String.fromCharCode(c - k);\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tif (k > 0)\n\t\tr = \"-1\";\n\t\n\tprint(r);\n}\n\nmain();"}], "negative_code": [{"source_code": "/* TEST CASE\ninput\n4 26\nbear\noutput\nroar\ninput\n2 7\naf\noutput\ndb\ninput\n3 1000\nhey\noutput\n-1 */\nfunction main() {\n\tvar splitted = readline().split(\" \");\n\tvar n = parseInt(splitted[0]);\n\tvar k = parseInt(splitted[1]);\n\tvar s = readline();\n\tvar r = \"\";\n\tfor (var i = 0; i < n; i++) {\n\t\tvar c = s.charCodeAt(i)\n\t\tvar distToZ = 0x7A - c\n\t\tvar distToA = c - (0x7A - 25);\n\t\tif (distToZ >= distToA) {\n\t\t\tif (distToZ <= k) {\n\t\t\t\tr += 'z';\n\t\t\t\tk -= distToZ;\n\t\t\t} else {\n\t\t\t\tr += String.fromCharCode(c + k);\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t} else {\n\t\t\tif (distToA <= k) {\n\t\t\t\tr += 'a';\n\t\t\t\tk -= distToA;\n\t\t\t} else {\n\t\t\t\tr += String.fromCharCode(c + k);\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tif (k > 0)\n\t\tr = \"-1\";\n\t\n\tprint(r);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 2 3\noutput\n20 15\ninput\n8 2 4\noutput\n35 32\n */\nfunction main() {\n\tvar splitted = readline().split(\" \");\n\tvar n = parseInt(splitted[0]);\n\tvar k = parseInt(splitted[1]);\n\tvar s = readline();\n\tvar r = \"\";\n\tfor (var i = 0; i < n; i++) {\n\t\tvar c = s.charCodeAt(i)\n\t\t\n\t\tif (0x7A - c <= k) {\n\t\t\tr += 'z';\n\t\t\tk -= 0x7A - c;\n\t\t} else {\n\t\t\tr += String.fromCharCode(c + k);\n\t\t\tk = 0;\n\t\t}\n\t}\n\t\n\tif (k > 0)\n\t\tr = \"-1\";\n\t\n\tprint(r);\n}\n\nmain();"}, {"source_code": "/* TEST CASE\ninput\n5 2 3\noutput\n20 15\ninput\n8 2 4\noutput\n35 32\n */\nfunction main() {\n\tvar splitted = readline().split(\" \");\n\tvar n = parseInt(splitted[0]);\n\tvar k = parseInt(splitted[1]);\n\tvar s = readline();\n\tvar r = \"\";\n\tfor (var i = 0; i < n; i++) {\n\t\tvar c = s.charCodeAt(i)\n\t\t\n\t\tif (0x7A - c <= k) {\n\t\t\tr += 'z';\n\t\t\tk -= 0x7A - c;\n\t\t} else {\n\t\t\tr += String.fromCharCode(c + k);\n\t\t\tk = 0;\n\t\t}\n\t}\n\t\n\t\n\tprint(r);\n}\n\nmain();"}, {"source_code": "var str = readline().split(\" \", 2);\nvar k = Number(str[1]);\nvar str = readline();\n\nfunction getChar(str, n) {\n var table = \"abcdefghijklmnopqrstuvwxyz\";\n var index = table.indexOf(str);\n return table[index + n];\n}\n\nvar ans = \"\";\nfor (var i = 0; i < str.length; ++i) {\n if (k === 0) {\n ans += str.slice(i);\n break;\n }\n var dis;\n if (str[i] <= \"m\") {\n dis = \"z\".charCodeAt(0) - str[i].charCodeAt(0);\n if (dis >= k) {\n k = 0;\n ans += getChar(str[i], k);\n } else {\n k -= dis;\n ans += getChar(str[i], dis);\n }\n } else {\n dis = str[i].charCodeAt(0) - \"a\".charCodeAt(0);\n if (dis >= k) {\n k = 0;\n ans += getChar(str[i], -k);\n } else {\n k -= dis;\n ans += getChar(str[i], -dis);\n }\n }\n}\n\nif (k !== 0) {\n print(-1);\n} else {\n print(ans);\n}"}], "src_uid": "b5d0870ee99e06e8b99c74aeb8e81e01"} {"source_code": "print(function(v, a) {\n\n\tvar min = Math.min.apply(0, a);\n\ta = a.map(function(v) {\n\t\treturn v - min;\n\t});\n\n\tvar t = Math.floor(v / min);\n\tvar ans = [];\n\n\tv = v % min;\n\n\tfor (var i = 0; i < t; i++)\n\t\tfor (var j = 8; j >= 0; j--)\n\t\t\tif (v - a[j] >= 0) {\n\t\t\t\tv -= a[j];\n\t\t\t\tans.push(j + 1);\n\t\t\t\tbreak;\n\t\t\t}\n\n\treturn ans.length === 0 ? -1 : ans.join('');\n\n}(+readline(), readline().split(' ').map(Number)));", "positive_code": [{"source_code": "print(function(v, a) {\n\n\tvar min = 1e5 + 1;\n\tvar x = 0;\n\tfor (var i = 1; i <= 9; i++)\n\t\tif (a[i] <= min) {\n\t\t\tx = i.toString();\n\t\t\tmin = a[i];\n\t\t}\n\n\tvar ans = [];\n\n\tvar t = Math.floor(v / min);\n\n\tfor (var i = t - 1; i >= 0; i--) {\n\t\tvar num = x;\n\t\tfor (var j = 9; j > x; j--) {\n\t\t\tif ((v - a[j]) / min >= i) {\n\t\t\t\tnum = j;\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tv = v - a[num];\n\t\tans.push(num);\n\t}\n\n\treturn ans.length === 0 ? -1 : ans.join('');\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));"}, {"source_code": "print(function(v, a) {\n\tvar i, j, t, ans = [],\n\t\tmin = Math.min.apply(0, a);\n\ta = a.map(function(v) {\n\t\treturn v - min;\n\t});\n\tt = ~~ (v / min);\n\tv = v % min;\n\tfor (i = 0; i < t; i++)\n\t\tfor (j = 8; j >= 0; j--)\n\t\t\tif (v - a[j] >= 0) {\n\t\t\t\tv -= a[j];\n\t\t\t\tans.push(j + 1);\n\t\t\t\tbreak;\n\t\t\t}\n\treturn ans.length === 0 ? -1 : ans.join('');\n}(+readline(), readline().split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar cash = parseInt(readline()),\n\t\tcosts = tokenizeIntegers(readline()),\n\t\tdigitCost = {}, minCost = costs[0];\n\tfor (var d = 1; d <= 9; ++d) {\n\t\tvar cost = costs[d-1];\n\t\tminCost = Math.min(minCost, cost);\n\t\tdigitCost[d] = cost;\n\t}\n\tvar length = Math.floor(cash / minCost),\n\t\tresult = new Array(length);\n\tif (length == 0) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\tcash -= length*minCost;\n\tfor (var d = 1; d <= 9; ++d) {\n\t\tdigitCost[d] -= minCost;\n\t}\n\tfor (var i = 0; i < length; ++i) {\n\t\tfor (var d = 9; d >= 1; --d) {\n\t\t\tif (digitCost[d] <= cash) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (d == 0) {\n\t\t\tbreak;\n\t\t}\n\t\tresult[i] = d;\n\t\tcash -= digitCost[d];\n\t}\n\tprint(result.join(''));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "print(function(v, a) {\n\n\tvar min = 1e5 + 1;\n\tvar x = 0;\n\tfor (var i = 1; i <= 9; i++)\n\t\tif (a[i] <= min) {\n\t\t\tx = i.toString();\n\t\t\tmin = a[i];\n\t\t}\n\n\n\tvar ans = '';\n\tvar t = Math.floor(v / min);\n\tfor (var i = 0; i < t; i++)\n\t\tans += x;\n\n\treturn ans.length === 0 ? -1 : ans;\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));"}, {"source_code": "print(function(v, a) {\n\n\tvar min = 1e5 + 1;\n\tvar x = 0;\n\tfor (var i = 1; i <= 9; i++)\n\t\tif (a[i] <= min) {\n\t\t\tx = i.toString();\n\t\t\tmin = a[i];\n\t\t}\n\n\tvar ans = [];\n\tvar t = Math.floor(v / min);\n\tfor (var i = t - 1; i >= 0; i--){\n\t\tvar num = x;\n\t\tfor (var j = 9; j > x; j--) {\n\t\t\tif( (v-a[j])/min >= i ){\n\t\t\t\tnum = j;\n\t\t\t\tv = v-a[j];\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tans.push(num);\n\t}\n\n\treturn ans.length === 0 ? -1 : ans.join('');\n\n}(+readline(), ('0 ' + readline()).split(' ').map(Number)));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar cash = parseInt(readline()),\n\t\tdigitValues = tokenizeIntegers(readline()),\n\t\tdigits = [];\n\tfor (var d = 1; d <= 9; ++d) {\n\t\tdigits.push({ digit: d, cost: digitValues[d-1] });\n\t}\n\tdigits.sort(function (a, b) {\n\t\tif (a.cost != b.cost) {\n\t\t\treturn a.cost - b.cost;\n\t\t} else {\n\t\t\treturn a.digit - b.digit;\n\t\t}\n\t});\n\tvar cheap = digits[0].cost,\n\t\tlength = Math.floor(cash / cheap),\n\t\tresult = new Array(length),\n\t\tresultPos = 0, digitPos = 8;\n\tif (length == 0) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\tcash -= length*cheap;\n\twhile (resultPos < length) {\n\t\twhile (digitPos >= 0 && digits[digitPos].cost - cheap > cash) {\n\t\t\t--digitPos;\n\t\t}\n\t\tif (digitPos == -1) {\n\t\t\tbreak;\n\t\t}\n\t\tresult[resultPos++] = digits[digitPos].digit;\n\t\tcash -= digits[digitPos].cost - cheap;\n\t}\n\tprint(result.join(''));\n}\n\nmain();\n"}], "src_uid": "ace9fbabc2eda81b4e4adf4f2d5ad402"} {"source_code": "function minString(str) {\n var len = str.length;\n var removeIndex = len-1;\n for (var i = 0; i < len-1; i++) {\n if (str[i] > str[i+1]) {\n removeIndex = i;\n break;\n }\n }\n return str.slice(0, removeIndex) + str.slice(removeIndex +1);\n}\n\nconst len = Number(readline());\nconst str = readline();\nprint(minString(str));", "positive_code": [{"source_code": "readline();\nvar str = readline();\nvar res;\nfor(var i = 1; i < str.length; i++) {\n\tif(str[i] < str[i - 1]) {\n\t\tres = str.substr(0, i - 1) + str.substr(i);\n\t\tbreak;\n\t}\n}\n\nif(!res) res = str.substr(0, str.length - 1);\n\nprint(res);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let max = 1\n let arr = input.split('')\n let curr=0\n let res=''\n let isRem = false\n for (let i = 0; i < arr.length-1;i++) {\n if(arr[i]>arr[i+1]&&!isRem){\n isRem= true\n } else {\n res+=arr[i]\n }\n }\n res+=arr[arr.length-1]\n if(arr.length===res.length)\n {\n res=res.slice(0,res.length-1)\n }\n console.log(res)\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet l = 0;\nrl.on('line', (input) => {\n if (l === 0) { l++ }\n else {\n rl.close();\n let max = 1\n let arr = input.split('')\n let curr=0\n let res=''\n let rem = true\n for (let i = 0; i < arr.length-1;i++) {\n if(arr[i]>arr[i+1]&&rem){\n rem= false\n } else {\n res+=arr[i]\n }\n }\n res+=arr[arr.length-1]\n if(arr.length===res.length)\n {\n res=res.slice(0,res.length-1)\n }\n console.log(res)\n return 0;\n }\n});\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n\n\nvar counter=0, N;\nrl.on('line', (input) => {\n if(counter==0){\n N=parseInt(input);\n counter++;\n }\n else\n {\n if(N != 1){\n let ind = N-1;\n for(let i=0; iinput[i+1]){\n ind=i;\n break;\n }\n }\n input = input.substring(0, ind) + input.substring(ind + 1);\n \n\n }\n console.log(input);\n rl.close();\n }\n \n });\n\n\n /*\n \n input = \"abcdefghi\"\n input = \"aaaaaaaaa\"\n */"}, {"source_code": "var length = parseInt(readline());\n\nvar string = readline().split('');\n\nvar removePos = length-1;\n\nfor(var i = 0; i< length-1; i++){\n if(string[i]>string[i+1]){\n removePos = i;\n break;\n }\n}\n\nstring.splice(removePos,1)\nprint(string.join(''))"}, {"source_code": "var cnt = parseInt(readline());\nvar line = readline();\nfor (var i = 1; i < cnt; i++) {\n\tif (line[i-1] > line[i]) {\n\t\tbreak;\n }\n}\nprint(line.slice(0,i-1) + line.slice(i,line.length));"}, {"source_code": "function solve(n, s) {\n for (var i=1; i {\n if (l === 0) { l++ }\n else {\n rl.close();\n let max = 1\n let arr = input.split('')\n let curr=0\n let res=''\n let rem = true\n for (let i = 0; i < arr.length-1;i++) {\n if(arr[i]>arr[i+1]&&rem){\n rem= false\n } else {\n res+=arr[i]\n }\n }\n res+=arr[arr.length-1]\n if(arr.length===res.length)\n {\n res=res.slice(1)\n }\n console.log(res)\n return 0;\n }\n});\n"}, {"source_code": "var length = parseInt(readline());\n\nvar string = readline().split('');\n\nif(string[length -1] =='a'){\n string.splice(-1,1);\n length = string.length;\n}\n\nstring[length - 1] = 'a';\n\nprint(string.join(''))"}, {"source_code": "function minString(str) {\n var len = str.length;\n var removeIndex = len-1;\n for (var i = 0; i < len-1; i++) {\n if (str[i] > str[i+1]) {\n removeIndex = i;\n }\n }\n return str.slice(0, removeIndex) + str.slice(removeIndex +1);\n}\n\nconst len = Number(readline());\nconst str = readline();\nprint(minString(str));"}], "src_uid": "c01fc2cb6efc7eef290be12015f8d920"} {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n let curr = 0;\n let step = 1;\n let ans = '';\n\n for (let i = 0; i < n - 1; i++) {\n curr = (curr + step) % n;\n step++;\n ans += curr + 1 + ' ';\n }\n\n console.log(ans);\n\n // const ans = [2];\n // let inc = 1;\n\n // while(ans.length < n - 1) {\n // inc++;\n // const v = (ans[ans.length - 1] + inc) % n;\n // ans.push(v === 0 ? n : v);\n // }\n\n // console.log(ans.join(' '));\n});\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n const ans = [2];\n let inc = 1;\n\n while(ans.length < n - 1) {\n inc++;\n const v = (ans[ans.length - 1] + inc) % n;\n ans.push(v === 0 ? n : v);\n }\n\n console.log(ans.join(' '));\n});\n"}, {"source_code": "print(function(n) {\n\tvar x = 2;\n\tvar ans = [];\n\tfor (var i = 1; i < n; i++) {\n\t\tans.push(x);\n\t\tx = x + i + 1;\n\t\tif(x>n){\n\t\t\tx = x-n;\n\t\t}\n\t}\n\treturn ans.join(' ');\n}(readline()));"}, {"source_code": ";(function () {\n\n\tprint(function (n) {\n\n\t\tvar q = 1, p = [], t = 1, r = n;\n\t\twhile (--n) {\n\t\t\tp.push(((q += t++) % r) || r);\n\t\t}\n\n\t\treturn p.join(' ');\n\n\t}(+readline()));\n\n}.call(this));"}, {"source_code": "'use strict'\n\nlet N = +readline()\n\nlet i = 0\nlet c = 1\nlet n = N\nlet r = []\nwhile (--n) {\n i++\n c += i\n c = c % N\n r.push(c)\n}\n\nprint(r.map(v => v || N).join(' '))"}, {"source_code": "var n = +readline();\nvar ans = [2];\nfor (var i=1; i<=n-2; i++){\n\tans[i] = (ans[i-1] + (i+1))%n == 0 ? n : (ans[i-1] + (i+1))%n;\n}\nprint(ans.join(' '));"}, {"source_code": "\nvar readline = require('readline'),\n rl = readline.createInterface(process.stdin, process.stdout);\n\nvar n;\n\nrl.on('line', function (line) {\n n = parseInt(line);\n \n let limit = n - 1, ind = 0, skip = 0, pos = 1;\n while (ind < limit)\n {\n pos += skip + 1;\n if (pos > n)\n pos = pos % n;\n\n process.stdout.write(pos + \" \");\n // Console.Write(\"{0} \", pos);\n\n skip++;\n ind++;\n\n }\n rl.close(); \n\n}).on('close', function () {\n \n process.exit(0);\n});\n"}], "negative_code": [{"source_code": "print(function(n) {\n\tvar x = 2;\n\tvar ans = [];\n\tfor (var i = 1; i < n; i++) {\n\t\tans.push(x);\n\t\tx = (x + i + 1) % n || n;\n\t}\n\treturn ans.join(' ');\n}(readline()));"}, {"source_code": "'use strict'\n\nlet N = +readline()\n\nlet i = 0\nlet c = 1\nlet n = N\nlet r = []\nwhile (--n) {\n i++\n c += i\n c = c % N\n r.push(c)\n}\n\nprint(r.join(' '))"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n let curr = 0;\n let step = 1;\n let ans = '';\n\n for (let i = 0; i < n - 1; i++) {\n curr = (curr + step) % n;\n ans += curr + 1 + ' ';\n }\n\n console.log(ans);\n\n // const ans = [2];\n // let inc = 1;\n\n // while(ans.length < n - 1) {\n // inc++;\n // const v = (ans[ans.length - 1] + inc) % n;\n // ans.push(v === 0 ? n : v);\n // }\n\n // console.log(ans.join(' '));\n});\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nrl.on('line', (d) => {\n const n = +d;\n const ans = [2];\n let inc = 1;\n\n while(ans.length < n - 1) {\n inc++;\n const v = (ans[ans.length - 1] + inc) % n;\n ans.push(v);\n }\n\n console.log(ans.join(' '));\n});\n"}], "src_uid": "7170c40405cf7a5e0f2bd15e4c7d189d"} {"source_code": "var n = parseInt(readline().trim())\nvar x;\nvar ans= [] \nvar g = {}\nvar _g={}\nfor(var i=0;iparseInt(_x))\n g[x[0]]=x[1];\n _g[x[1]]=x[0];\n}\nvar y = 0 \ndo{\n \n if(g[y]==undefined)\n break;\n y=g[y];\n ans.push(-1);\n if(y==0)\n break;\n ans.push(y);\n}while(y!=0)\n\nvar y,i\nif(n%2==0){\n y=_g[0]\n i=n-2;\n}else{\n for(var i in g){\n if(g[g[i]]==undefined){\n y=g[i]\n break\n }\n }\n i=n-1\n}\n \ndo{\n ans[i]=y\n i-=2\n if(_g[y]==undefined)\n break;\n y=_g[y];\n\n}while(y!=0)\n\nprint(ans.join(' '))", "positive_code": [{"source_code": "var n = parseInt(readline().trim())\nvar x;\nvar ans= [] \nvar g = {}\nvar _g={}\nfor(var i=0;iparseInt(_x))\n g[x[0]]=x[1];\n _g[x[1]]=x[0];\n}\nvar y = 0 \ndo{\n \n if(g[y]==undefined)\n break;\n y=g[y];\n ans.push(-1);\n if(y==0)\n break;\n ans.push(y);\n}while(y!=0)\n\nvar y,i\nif(n%2==0){\n y=_g[0]\n i=n-2;\n}else{\n for(var i in g){\n if(g[g[i]]==undefined){\n y=g[i]\n break\n }\n }\n i=n-1\n}\n \ndo{\n ans[i]=y\n i-=2\n if(_g[y]==undefined)\n break;\n y=_g[y];\n\n}while(y!=0)\n\nprint(ans.join(' '))"}], "negative_code": [], "src_uid": "1aaced1322c47f1908f2bc667bca1dbe"} {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction multiply(a, b) {\n\ta = a.toString(10).split('').reverse();\n\tb = b.toString(10).split('').reverse();\n\n\tif (a.length < b.length) {\n\t\t[a, b] = [b, a];\n\t}\n\n\tlet res = Array(a.length + b.length).fill(0);\n\tfor (let i = 0, lb = b.length; i < lb; ++i) {\n\t\tlet carry = 0;\n\t\tlet scarry = 0;\n\t\tfor (let j = 0, la = a.length; j < la; ++j) {\n\t\t\tlet m = b[i] * a[j];\n\t\t\tm += carry;\n\n\t\t\tif (m > 9) {\n\t\t\t\tlet [c, d] = m.toString(10).split('');\n\t\t\t\tres[i + j] += (scarry >> 0) + (d >> 0);\n\t\t\t\tcarry = c >> 0;\n\t\t\t} else {\n\t\t\t\tres[i + j] += (scarry >> 0) + m;\n\t\t\t\tcarry = 0;\n\t\t\t}\n\n\t\t\tif (res[i + j] > 9) {\n\t\t\t\tlet [c, d] = res[i + j].toString(10).split('');\n\t\t\t\tres[i + j] = d >> 0;\n\t\t\t\tscarry = c;\n\t\t\t} else {\n\t\t\t\tscarry = 0;\n\t\t\t}\n\t\t}\n\t\tif (carry > 0) res[a.length + i] = carry;\n\t\tif (scarry > 0) res[a.length + i] = scarry;\n\t}\n\n\tres.reverse();\n\tlet mulVal = '';\n\tlet flag = false;\n\tres.forEach(d => {\n\t\tif (!flag && d !== 0) flag = true;\n\t\tif (flag) mulVal += d;\n\t});\n\treturn mulVal;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet c = readLine()\n\t\t.split(' ')\n\t\t.map(x => x >> 0);\n\n\tlet m = Math.min(...c);\n\tlet d = 0;\n\tlet p = 0;\n\tfor (let i = 0; i < n; i++) {\n\t\tif (c[i] === m) {\n\t\t\td++;\n\t\t\tp = i + 1;\n\t\t}\n\t}\n\n\tif (d > 1) console.log('Still Rozdil');\n\telse console.log(p);\n}\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n const len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [min, minIndex, minCount] = [Number.MAX_SAFE_INTEGER, -1, 0];\n\n for (let i = 0; i < len; i++) {\n const num = arr[i];\n if (num <= min) {\n if (num === min) minCount++;\n else minCount = 0;\n min = num;\n minIndex = i + 1;\n }\n }\n minCount === 0 ? console.log(minIndex) : console.log(\"Still Rozdil\");\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n const arr = d.split(' ').map(Number);\n let min = Infinity;\n let minIdx = Infinity;\n const obj = {};\n\n for (let i = 0; i < arr.length; i++) {\n if (min > arr[i]) {\n min = arr[i];\n minIdx = i + 1;\n }\n\n if (obj.hasOwnProperty(arr[i])) {\n obj[arr[i]]++;\n }\n else {\n obj[arr[i]] = 1;\n }\n }\n\n if (obj[min] === 1) {\n console.log(minIdx);\n }\n else {\n console.log('Still Rozdil');\n }\n\n c++;\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let distances = readLine().split(' ').map(Number);\n let lowest = Math.min(...distances);\n // for (let i = 0; i < n; i++) {\n // if (\n // distances.indexOf(distances[i]) !==\n // distances.lastIndexOf(distances[i])\n // ) {\n // console.log('Still Rozdil');\n // return;\n // }\n // }\n if (distances.indexOf(lowest) !== distances.lastIndexOf(lowest)) {\n console.log('Still Rozdil');\n return;\n }\n\n console.log(distances.indexOf(lowest) + 1);\n}\n"}, {"source_code": "print(function(n) {\n\tvar a = readline().split(' ').map(Number),\n\t\tmin = Math.min.apply(0, a),\n\t\ti = a.indexOf(min),\n\t\tii = a.indexOf(min, i+1);\n\n\treturn ii > -1 ? 'Still Rozdil' : i + 1;\n\n}(+readline()));"}, {"source_code": ";(function () {\n\n\tvar n = +readline();\n\tvar a = readline().split(' ').map(Number);\n\tvar m = Math.min.apply(0, a);\n\tvar p = a.indexOf(m);\n\n\tprint( p === a.lastIndexOf(m) ? p + 1 : 'Still Rozdil' );\n\n}).call(this);\n"}, {"source_code": "\nvar n = readline();\nvar cnt = 0;\nvar j = 0;\nvar mn = 1000000000\n \nvar array = readline().split(\" \").map((item)=>{return parseInt(item)});\n\narray.forEach((item,idx)=>{\n if(item <= mn) {\n mn = item;\n j = idx;\n }\n});\n\nfor (i = 0; i < n; i++) {\n if (array[i] == mn)\n cnt++;\n}\nif (cnt > 1) {\n print(\"Still Rozdil\");\n} else \n print(j + 1);"}], "negative_code": [{"source_code": "print(function(n) {\n\tvar a = readline().split(' ').map(Number),\n\t\tmin = Math.min.apply(0, a),\n\t\ti = a.indexOf(min),\n\t\tii = a.indexOf(min, i);\n\n\treturn ii > -1 ? 'Still Rozdil' : i + 1;\n\n}(+readline()));\n"}, {"source_code": "\nvar n = readline();\nvar cnt = 0;\nvar j = 0;\nvar mn = 1000000000\n \nvar array = readline().split(\" \").map((item)=>{return item});\n\narray.forEach((item,idx)=>{\n if(item <= mn) {\n mn = item;\n j = idx;\n }\n});\n\nfor (i = 0; i < n; i++) {\n if (array[i] == mn)\n cnt++;\n}\nif (cnt > 1) {\n print(\"Still Rozdil\");\n} else \n print(j + 1);"}, {"source_code": "\nvar n = readline();\nvar cnt = 0;\nvar j = 0;\nvar array = readline().split(\" \");\n\nvar mn = array[0];\nfor (i = 1; i < n; i++) {\n if (array[i] <= mn) {\n mn = array[i];\n j = i;\n }\n}\nfor (i = 1; i < n; i++) {\n if (array[i] == mn)\n cnt++;\n}\nif (cnt > 1) {\n print(\"Still Rozdil\");\n} else \n print(j + 1);"}, {"source_code": "\nvar n = readline();\nvar cnt = 0;\nvar j = 0;\nvar array = [];\nfor (i = 0; i < n; i++)\n array[i] = readline();\nvar mn = array[0];\nfor (i = 1; i < n; i++) {\n if (array[i] <= mn) {\n mn = array[i];\n j = i;\n }\n}\nfor (i = 1; i < n; i++) {\n if (array[i] == mn)\n cnt++;\n}\nif (cnt > 1) {\n print(\"Still Rozdil\");\n} else \n print(j + 1);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let distances = readLine().split(' ').map(Number);\n for (let i = 0; i < n; i++) {\n if (\n distances.indexOf(distances[i]) !==\n distances.lastIndexOf(distances[i])\n ) {\n console.log('Still Rozdil');\n return;\n }\n }\n\n let lowest = Math.min(...distances);\n console.log(distances.indexOf(lowest) + 1);\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nlet inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', (inputStd) => {\n inputString += inputStd;\n});\nprocess.stdin.on('end', function () {\n inputString = inputString\n .trim()\n .split('\\n')\n .map((str) => {\n return str.trim();\n });\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let n = parseInt(readLine());\n let distances = readLine().split(' ').map(Number);\n for (let i = 0; i < n; i++) {\n if (\n distances.indexOf(distances[i]) !==\n distances.lastIndexOf(distances[i])\n ) {\n console.log('Still Rozdil');\n return;\n }\n }\n\n let lowest = Math.min(...distances);\n console.log(distances.indexOf(lowest));\n}\n"}], "src_uid": "ce68f1171d9972a1b40b0450a05aa9cd"} {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\n\r\nfunction print(x) { process.stdout.write(x); }\r\nfunction println(x) { console.log(x); }\r\n\r\nconst digit = \"012\";\r\n\r\nfunction solve(n) {\r\n const r = n%3;\r\n const m = n-2;\r\n let ans = \"\";\r\n let sum = 0;\r\n if (r == 1) {\r\n ans += \"1\";\r\n sum = 1; }\r\n while (sum < m) {\r\n ans += \"21\";\r\n sum += 3; }\r\n if (sum < n)\r\n ans += digit[n-sum];\r\n return ans; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) \r\n println(solve(nextInt())); }\r\n", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num) {\n dealInput(rows);\n }\n }\n});\nconst dealInput = (rows) => {\n rows.forEach(item => {\n let m = item % 3;\n let n = parseInt(item / 3);\n let a = '1',\n b = '21';\n if (m === 1) {\n a = '1'\n b = '12'\n } else if (m === 2) {\n a = '2'\n b = '21'\n } else {\n a = ''\n b = '21'\n }\n console.log(setNum(n, b) + a);\n })\n rl.close();\n};\n\nfunction setNum(m, n) {\n if (m === 0) return ''\n let num = ''\n for (let i = 0; i < m; i++) {\n num += n\n }\n return num\n}\nrl.on('close', () => {\n process.exit(0);\n});\n \t\t \t\t \t \t \t\t \t \t \t \t\t\t\t\t\t"}, {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', str => {\n if (str === '\\r\\n' || str === '\\n') {\n process.stdin.emit('end');\n } else {\n text += str;\n }\n});\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/r/g, '').split('\\n');\n const total = Number(input[0]);\n for (let i = 1; i <= total; i++) {\n solve(Number(input[i]));\n }\n\n process.exit();\n});\n\nfunction solve(number) {\n const mod = number % 3;\n const group = (number - mod) / 3;\n let result = '';\n if (mod < 2) {\n mod && (result = '1');\n result += '21'.repeat(group);\n } else {\n result = '2';\n result += '12'.repeat(group);\n }\n console.log(result);\n}\n \t \t\t\t\t \t\t\t\t\t \t \t\t \t \t"}, {"source_code": "function solve(arr) {\n let data = [...arr];\n data.shift();\n data = data.map((num) => parseInt(num));\n data.forEach((num) => {\n if (num === 1) {\n console.log(1);\n } else if (num === 2) {\n console.log(2);\n } else if (num === 3) {\n console.log(21);\n } else {\n const a = num % 3;\n const b = parseInt(num / 3);\n let str = \"\";\n for (let i = 0; i < b; i++) {\n str += \"21\";\n }\n if (a === 1) {\n console.log(`1${str}`);\n } else if (a === 2) {\n console.log(`${str}2`);\n } else {\n console.log(str);\n }\n }\n });\n}\nlet text = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", (t) => {\n if (t === \"\\r\\n\" || t === \"\\n\") {\n process.stdin.emit(\"end\");\n } else {\n text += t;\n }\n});\nprocess.stdin.on(\"end\", () => {\n const input = text.trim().replace(/\\r/g, \"\").split(\"\\n\");\n solve(input);\n process.exit();\n});\n\n\t\t\t\t\t \t \t \t \t\t \t\t \t\t\t \t\t\t"}, {"source_code": "function repeat(num, t){\n var ans = '';\n if(t === 0){\n \n }\n if(t == 1){\n ans += 1;\n }\n for(j = 0; j < num; j++){\n ans += 21;\n }\n if(t == 2){\n ans += 2;\n }\n console.log(ans);\n}\n\nlet i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(i = 1; i <= n; i++){\n var k = lines[i];\n var a = Math.floor(k / 3);\n if(k % 3 === 0){\n repeat(a, 0);\n }else if(k % 3 == 1){\n repeat(a, 1);\n }else{\n repeat(a, 2);\n }\n }\n});"}, {"source_code": "var readline = require('readline');\r\nvar rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nlet ls = [];\r\n\r\nfunction solve(){\r\n let i = 1;\r\n while (i < ls.length){\r\n const n = parseInt(ls[i++]);\r\n let sum = 0;\r\n let num = n % 3 == 1 ? 1 : 2;\r\n let ans = '';\r\n while (sum < n){\r\n ans += num;\r\n sum += num;\r\n num = 3 - num;\r\n }\r\n console.log(ans);\r\n }\r\n}\r\n\r\nrl.on('line', (l) => ls.push(l));\r\nrl.on('close', () => solve());"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n\n let next = 2;\n if (n % 3 === 1) {\n next = 1;\n }\n\n let length = Math.ceil(n / 3) * 2;\n if (n % 3 !== 0) {\n length--;\n }\n\n let result = \"\";\n for (let i = 0; i < length; i++) {\n // result *= 10;\n // result += next;\n result = result + next;\n if (next === 2) {\n next = 1;\n } else {\n next = 2;\n }\n }\n\n console.log(result);\n }\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let n = parseInt(readline(), 10);\r\n\r\n let res = '';\r\n if (n % 3 === 1) {\r\n output('12'.repeat(Math.floor(n / 3)) + '1');\r\n } else if (n % 3 === 2) {\r\n let base = '21'.repeat(Math.floor(n / 3))\r\n output(base + '2');\r\n } else {\r\n output('21'.repeat(n/3));\r\n }\r\n }\r\n}\r\n"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst print = console.log\nconst E = {};\nconst lines = []\nif (!process.env.JEST_WORKER_ID){\n const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\n rl.on('line', line => {\n lines.push(line);\n });\n rl.on('close', main)\n}\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nmodule.exports = E;\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\n\nconst EPS = 1e-6;\n\nconst calc = (n)=>{\n let res = '';\n let start = 2;\n let m = n\n debugger\n while (m>0){\n res += start;\n m -= start;\n start = start==1 ? 2 : 1;\n }\n if (m==0)\n return res;\n res = '';\n start = 1;\n m = n;\n while (m>0){\n res += start;\n m -= start;\n start = start==1 ? 2 : 1;\n }\n return res;\n};\n \nfunction main() {\n let T = +readline();\n while (T--){\n let n = +readline();\n print(calc(n));\n }\n}\n\nE.calc = calc;"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar one = N % 2;\r\n\t\tvar two = Math.floor(N / 2);\r\n\t\twhile(Math.abs(two - one) > 1){\r\n\t\t\ttwo--;\r\n\t\t\tone += 2;\r\n\t\t}\r\n\t\t\r\n\t\tvar output = [];\r\n\t\tif(one > two){\r\n\t\t\toutput.push(1);\r\n\t\t\tone--;\r\n\t\t}\r\n\t\twhile(one > 0 && two > 0){\r\n\t\t\toutput.push(2);\r\n\t\t\toutput.push(1);\r\n\t\t\tone--;\r\n\t\t\ttwo--;\r\n\t\t}\r\n\t\tif(two > 0){\r\n\t\t\toutput.push(2);\r\n\t\t}\r\n\t\tmyout(myconv(output, 0));\r\n\t}\r\n}\r\n"}, {"source_code": "function solve() {\r\n const n = Number(read());\r\n const div3 = Math.floor(n / 3);\r\n const mod3 = n % 3;\r\n let ans = '21'.repeat(div3);\r\n if (mod3 === 1) {\r\n ans = '1' + ans;\r\n }\r\n if (mod3 === 2) {\r\n ans = ans + '2';\r\n }\r\n write(ans);\r\n}\r\n\r\nfunction init() {\r\n try {\r\n var T = 1;\r\n T = Number(read());\r\n for (var t = 0; t < T; t++) {\r\n solve();\r\n }\r\n } catch (e) {\r\n write(e + e.stack);\r\n }\r\n}\r\n\r\nfunction modPow(a, n, mod) {\r\n let d = a;\r\n let curN = n;\r\n let ans = 1n;\r\n while(curN) {\r\n if (curN & 1n) {\r\n ans = modMul(ans, d, mod);\r\n }\r\n curN >>= 1n;\r\n d = modMul(d, d, mod);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction modMul(a, b, mod) {\r\n return (a * b) % mod;\r\n}\r\n\r\nfunction modSum(a, b, mod) {\r\n return (a + b) % mod;\r\n}\r\n\r\nfunction modDiff(a, b, mod) {\r\n return (a + mod - b) % mod;\r\n}\r\n\r\nfunction isZero(num) {\r\n if (typeof num === 'bigint') {\r\n return num === 0n;\r\n }\r\n return num === 0;\r\n}\r\nfunction div(a, b) {\r\n if (typeof a !== typeof b) {\r\n throw new Error('Different types on division');\r\n }\r\n if (typeof a === 'bigint') {\r\n return a / b;\r\n }\r\n return Math.floor(a / b);\r\n}\r\n\r\nfunction gcd(x, y) {\r\n if (isZero(y)) {\r\n return x;\r\n }\r\n return gcd(y, x % y);\r\n}\r\n\r\nfunction lcm(x, y) {\r\n return div(x * y, gcd(x, y));\r\n}\r\n\r\nfunction allIndexOf(arr, value) {\r\n var index = arr.indexOf(value)\r\n var ans = [];\r\n while (index !== -1) {\r\n ans.push(index);\r\n index = arr.indexOf(value, index + 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction xor(a, b, k) {\r\n if (k === 2) {\r\n return a ^ b;\r\n }\r\n}\r\n\r\nfunction decToBin(num) {\r\n let n = num;\r\n const ans = [];\r\n while(n > 0) {\r\n ans.push(n & 1);\r\n n = (n >> 1);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction binToDec(binN) {\r\n let ans = 0;\r\n for (let i = binN.length - 1; i >= 0; i--) {\r\n ans = ((ans << 1) | binN[i]);\r\n }\r\n return ans;\r\n}\r\n\r\nfunction sortF(a, b) {\r\n if (a < b) {\r\n return -1;\r\n }\r\n if (a > b) {\r\n return 1;\r\n }\r\n return 0;\r\n}\r\n\r\nfunction readArray(f) {\r\n return read().split(' ').map(f);\r\n}\r\n\r\n\r\n\r\nvar isNode = typeof console !== 'undefined';\r\nvar MEMORY = [];\r\nvar MEMORY_INDEX = 0;\r\nif (isNode) {\r\n var fs = require('fs');\r\n \r\n var path = require('path');\r\n\r\n var inTextName;\r\n var outTextName;\r\n\r\n var needWriteFile = false;\r\n\r\n var writeResult = '';\r\n if (process.argv.length === 5) {\r\n inTextName = process.argv[3];\r\n outTextName = process.argv[4];\r\n }\r\n\r\n if (inTextName) {\r\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\r\n MEMORY = data.split('\\r\\n');\r\n init();\r\n if (needWriteFile) {\r\n fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {\r\n err ? console.error(err) : console.log('good')\r\n });\r\n }\r\n });\r\n } else {\r\n MEMORY = fs.readFileSync(0, 'utf-8').split('\\r\\n');\r\n init();\r\n }\r\n} else {\r\n init();\r\n}\r\n\r\nfunction write(value) {\r\n if (needWriteFile) {\r\n writeResult += value + '\\n';\r\n return;\r\n }\r\n isNode ? console.log('' + value) : print('' + value);\r\n}\r\nfunction read() {\r\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\r\n}\r\nfunction readAll() {\r\n return isNode && MEMORY;\r\n}\r\n"}, {"source_code": "//const { readline, print } = require('@ip-algorithmics/codeforces-io');\n\nfunction readLineNumbers() {\n return readline().split(' ').map(x => parseInt(x))\n}\n\nfunction getSequenceToSum(sum, start) {\n var last = start;\n var sumOfDigits = start;\n var finalNumber = '' + start;\n\n while (sumOfDigits < sum) {\n var digit = last === 1 ? 2 : 1\n sumOfDigits += digit;\n finalNumber += digit;\n last = digit;\n }\n\n return [sumOfDigits, finalNumber];\n}\n\nvar n = readLineNumbers()[0]\n\nwhile (n--) {\n var sum = readLineNumbers()[0];\n\n var a = getSequenceToSum(sum, 1)\n var b = getSequenceToSum(sum, 2)\n \n if (a[0] === sum && b[0] === sum) {\n print ( a[0] > b[0] ? a[1] : b[1] )\n } else {\n print(a[0] === sum ? a[1] : b[1]);\n }\n}\n"}, {"source_code": "var tests = parseInt(readline());\r\n var n;\r\n\r\n for (var t=0; t < tests; t++) {\r\n n = parseInt(readline());\r\n\t\tvar ans = [];\r\n\r\n\t\tvar num = 2;\r\n\t\tif (n % 3 == 1) {\r\n\t\t\tnum = 1;\r\n\t\t}\r\n\t\twhile (n > 0) {\r\n\t\t\tans.push(num);\r\n\t\t\tn -= num;\r\n\t\t\tif (num == 1) {\r\n\t\t\t\tnum = 2;\r\n\t\t\t} else {\r\n\t\t\t\tnum = 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tprint(ans.join(''));\r\n }"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n\n for(j = 1; j <= n; j++){\n a = lines[j]\n s = 0\n answer = ''\n if(a % 3 == 1){\n while(s < a){\n s += 1 \n answer += 1\n if(s + 2 < a){\n s += 2 \n answer += 2\n }\n }\n console.log(answer)\n }else{\n while(s < a){\n s += 2 \n answer += 2\n if(s + 1 <= a){\n s += 1 \n answer += 1\n }\n }\n console.log(answer)\n }\n }\n \n}); \n "}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\nfunction print(x) { process.stdout.write(x); }\r\nfunction println(x) { console.log(x); }\r\n\r\nconst digit = \"012\";\r\n\r\nfunction solve(n) {\r\n let ans = \"\";\r\n let x = (n%3 == 1) ? 1 : 2;\r\n while (n > 0) {\r\n n -= x; ans += digit[x]; x = 3-x; }\r\n return ans; }\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n for (let t = nextInt(); t > 0; --t) \r\n println(solve(nextInt())); });\r\n"}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\nfunction print(x) { process.stdout.write(x); }\r\nfunction println(x) { console.log(x); }\r\n\r\nconst digit = \"012\";\r\n\r\nfunction solve(n) {\r\n const r = n%3;\r\n const m = n-2;\r\n let ans = \"\";\r\n let sum = 0;\r\n if (r == 1) {\r\n ans += \"1\";\r\n sum = 1; }\r\n while (sum < m) {\r\n ans += \"21\";\r\n sum += 3; }\r\n if (sum < n)\r\n ans += digit[n-sum];\r\n return ans; }\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n for (let t = nextInt(); t > 0; --t) \r\n println(solve(nextInt())); });\r\n"}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\n\r\nconst digit = \"012\";\r\n\r\nfunction solve(n) {\r\n let ans = \"\";\r\n let sum = 0;\r\n const r = n%3;\r\n if (r == 1) {\r\n ans += \"1\";\r\n sum = 1; }\r\n const m = n-2;\r\n while (sum < m) {\r\n ans += \"21\";\r\n sum += 3; }\r\n if (sum < n)\r\n ans += digit[n-sum];\r\n return ans; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) \r\n console.log(solve(nextInt())); }\r\n"}, {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputStr = \"\";\r\nlet currentLne = 0;\r\n\r\nprocess.stdin.on('data' , inputStdin =>{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline()) ;\r\n let c =0;\r\n while(c{\r\n\r\n\t inputStr += inputStdin;\r\n})\r\n\r\nprocess.stdin.on('end' , _ =>{\r\n inputStr = inputStr.trim().split('\\n').map( string =>{\r\n \treturn string.trim();\r\n })\r\n \r\nmain();\r\n})\r\n\r\nfunction readline(){\r\n return inputStr[currentLne++];\r\n}\r\n\r\nfunction main(){\r\n \r\n let t = parseInt(readline()) ;\r\n let c =0;\r\n while(c i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n var g = false\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= a){\n if(g === false){\n s += '1'\n n += 1\n a -= 1\n \n if(n + 1 >= a){\n s += '2'\n n += 2\n a -= 2\n }\n } else if(g === true){\n s += '2'\n n += 2\n a -= 2 \n if(n + 2 >= a){\n s += '1'\n n += 1\n a -= 1\n}\n }\n }\n console.log(s)\n\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n var g = false\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= a){\n if(g === false){\n s += '1'\n n += 1\n a -= 1\n \n if(n + 1 != a){\n s += '2'\n n += 2\n a -= 2\n }\n } else if(g === true){\n s += '2'\n n += 2\n a -= 2 \n if(n + 2 != a){\ns += '1'\n n += 1\n a -= 1\n}\n }\n }\n console.log(s)\n\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n var g = false\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= a){\n if(g === false){\n s += '1'\n n += 1\n a -= 1\n \n if(n + 2 == a){\n s += '2'\n n += 2\n a -= 2\n }\n } else if(g === true){\n s += '2'\n n += 2\n a -= 2 \n if(n + 1 == a){\ns += '1'\n n += 1\n a -= 1\n}\n }\n }\n console.log(s)\n\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= k)\n if(a % 2 ==1 ){\n s += '1'\n n += 1\n a -= 1\n }else if(a % 2 === 0){\n s+='2'\n n += 2\n a -= 2\n }\n console.log(s)\n\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= k)\n if(a % 2 ==1 ){\n s += '1'\n n += 1\n }else if(a % 2 === 0){\n s+='2'\n n += 2\n }\n console.log(s)\n\n }\n});"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var k = lines[0];\n var s = ''\n var n = 0\n for(j = 1; j <= k; j++){\n var a = lines[j]\n while(n <= k)\n if(a % 2 ==1 ){\n s += '1'\n n += 1\n }else if(a % 2 === 0){\n s+='2'\n n += 2\n }\n }\n console.log(s)\n});"}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\n\r\nfunction solve(n) {\r\n let ans = \"\";\r\n let sum = 0;\r\n if (n%3 == 2) {\r\n ans += \"2\";\r\n sum = 2; }\r\n const m = n-2 \r\n while (sum < m) {\r\n ans += \"12\";\r\n sum += 3; }\r\n if (sum < n)\r\n ans += \"1\";\r\n return ans; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) \r\n console.log(solve(nextInt())); }\r\n"}, {"source_code": "'use strict';\r\n\r\nlet cin = '';\r\nlet current_line = 0;\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nprocess.stdin.on('data', line => { cin += line; });\r\nprocess.stdin.on('end', _ => {\r\n cin = cin.trim().split('\\n').map(line => { return line.trim(); });\r\n main(); });\r\n\r\nfunction next() { return cin[current_line++]; }\r\nfunction nextInt() { return parseInt(next()); }\r\nfunction nextList() { return next().split(' ').map(s => parseInt(s)); }\r\n\r\nfunction solve(n) {\r\n let ans = \"\";\r\n if (n%3 == 2)\r\n ans += \"2\";\r\n const m = n-1;\r\n while (ans.length < m)\r\n ans += \"12\";\r\n if (ans.length < n)\r\n ans += \"1\";\r\n return ans; }\r\n \r\nfunction main() {\r\n for (let t = nextInt(); t > 0; --t) \r\n console.log(solve(nextInt())); }\r\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num) {\n dealInput(rows);\n }\n }\n});\nconst dealInput = (rows) => {\n rows.forEach(item => {\n if(item <= 2) {\n console.log(item);\n }else {\n console.log(getNum(item));\n }\n })\n rl.close();\n};\nfunction getNum(num) {\n let s = 0\n if(num%2 ===1) {\n s = 2 \n } else {\n s = 1\n }\n return setS(s,num)\n}\nfunction setS(s,num) {\n let ss = String(s)\n for(let i = s; i < num;) {\n if(ss[ss.length-1] == 1) {\n ss += '2'\n i += 2\n } else {\n ss += '1'\n i += 1\n }\n }\n return ss\n}\nrl.on('close', () => {\n process.exit(0);\n});\n\t\t \t\t \t \t \t\t\t \t \t \t\t \t\t\t"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet inputString = \"\";\nlet currentLine = 0;\n\nprocess.stdin.on(\"data\", (inputStdin) => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((string) => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n const testCases = readline();\n\n for (let i = 0; i < testCases; i++) {\n let n = Number(readline());\n\n let next = 2;\n if (n % 3 === 1) {\n next = 1;\n }\n\n let length = Math.ceil(n / 3) * 2;\n if (n % 3 !== 0) {\n length--;\n }\n\n let result = 0;\n for (let i = 0; i < length; i++) {\n result *= 10;\n result += next;\n if (next === 2) {\n next = 1;\n } else {\n next = 2;\n }\n }\n\n console.log(result);\n }\n}\n"}, {"source_code": "function readLineNumbers() {\n return readline().split(' ').map(x => parseInt(x))\n}\n\nfunction getSequenceToSum(sum, start) {\n var last = start;\n var sumOfDigits = start;\n var finalNumber = start;\n\n while (sumOfDigits < sum) {\n var digit = last === 1 ? 2 : 1\n sumOfDigits += digit;\n finalNumber = finalNumber * 10 + digit;\n last = digit;\n }\n\n return [sumOfDigits, finalNumber];\n}\n\nvar n = readLineNumbers()[0]\n\nwhile (n--) {\n var sum = readLineNumbers()[0];\n\n var a = getSequenceToSum(sum, 1)\n var b = getSequenceToSum(sum, 2)\n \n if (a[0] === sum && b[0] === sum) {\n print ( a[0] > b[0] ? a[1] : b[1] )\n } else {\n print(a[0] === sum ? a[1] : b[1]);\n }\n}\n"}, {"source_code": "function readLineNumbers() {\n return readline().split(' ').map(x => parseInt(x))\n}\n\nfunction getSequenceToSum(sum, start) {\n var last = start;\n var sumOfDigits = start;\n var finalNumber = start;\n\n while (sumOfDigits < sum) {\n var digit = last === 1 ? 2 : 1\n sumOfDigits += digit;\n finalNumber = finalNumber * 10 + digit;\n last = digit;\n }\n\n return sumOfDigits === sum ? finalNumber : -1;\n}\n\nvar n = readLineNumbers()[0]\n\nwhile (n--) {\n var sum = readLineNumbers()[0];\n\n var a = getSequenceToSum(sum, 1)\n var b = getSequenceToSum(sum, 2)\n print(a === -1 ? b : a);\n}\n"}], "src_uid": "1a5f266b49aadbeef59e19bcf5524a57"} {"source_code": "const readline = require(\"readline\");\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nlet input = [];\r\nrl.on('line', line => {\r\n input.push(line);\r\n})\r\nrl.on('close', line => {\r\n var t = Number(input[0]);\r\n var j = 1;\r\n for (var m = 1; m <= t; m++) {\r\n var n = Number(input[j]);\r\n j++;\r\n var arr = input[j].split(\" \").map((i) => {\r\n return Number(i);\r\n });\r\n j++;\r\n var count = 0;\r\n for (var i = 0; i < arr.length; i++) {\r\n if (arr[i] === 1 || arr[i] === 3) {\r\n count++;\r\n }\r\n }\r\n console.log(count);\r\n }\r\n})", "positive_code": [{"source_code": "var t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var n =readline(),\r\n reviewers = readline().split(' ') , counter = 0;\r\n for(var j = 0 ; j < n ; j++){\r\n if(reviewers[j] == 1 || reviewers[j] == 3){\r\n counter++;\r\n }\r\n }\r\n print(counter);\r\n } "}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var l1 = 0\r\n var d1 = 0\r\n var l2 = 0\r\n var d2 = 0\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 1 || a[i] ===3) {\r\n l1 += 1\r\n continue\r\n }\r\n }\r\n\r\n console.log(l1 + l2)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var upvote = 0;\n var downvote = 0;\n var undecided = 0;\n for(var l = 0; l < e; l++){\n if(k[l] == 1){\n upvote++;\n }else if(k[l] == 2){\n downvote++;\n }else{\n undecided++;\n }\n }\n console.log(upvote + undecided);\n }\n }\n});"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i= 0; i < t; i++){\n\t\tnl.num();\n\t\tlet cnt = nl.nums().reduce((ac, e) => (e != 2)?ac + 1:ac, 0);\n\t\tans.push(cnt); \n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data', c => data += c);\n \nfunction* nextLine() {\n\tlet lines = data.trim().split(/\\n/g);\n\tfor(let l of lines){\n\t\tyield l.trim();\n\t}\n}\n \nlet nl = nextLine();\n \nnl.elem = function(funParse) {\n\t\treturn funParse(this.next().value);\t\n\t};\n \nnl.array = function(funParse) {\n\t\treturn this.next().value.split(/\\s/g).map(funParse||(x => x));\n\t};\n\t\nnl.num = function() {\n\t\treturn nl.elem(Number);\n\t};\n\t\nnl.nums = function() {\n\t\treturn nl.array(Number);\n\t};\n\t\nnl.line = function() {\n\t\treturn this.next().value;\n\t};\n\t\nconst sol = () => {\n\t//your code this\n\tlet t = nl.num();\n\tlet ans = [];\n\tfor(let i= 0; i < t; i++){\n\t\tnl.num();\n\t\tlet cnt = nl.nums().filter(e => e != 2).length;\n\t\tans.push(cnt); \n\t}\n\tconsole.log(ans.join('\\n'));\n};\n \nprocess.stdin.on('end', sol);\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar L = 0;\r\n\t\tvar R = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] != 2){\r\n\t\t\t\tL++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(L);\r\n\t}\r\n}\r\n"}, {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main();\r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n \r\n// Make a Snippet for the code above this and then write your logic in main();\r\n \r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var l1 = 0\r\n var d1 = 0\r\n var l2 = 0\r\n var d2 = 0\r\n \r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 1 || a[i] ===3) {\r\n l1 += 1\r\n continue\r\n }\r\n }\r\n \r\n console.log(l1 + l2)\r\n \r\n })\r\n}\r\n "}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0\n for(j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var upvote = 0\n var downvote = 0\n var undecided = 0\n for(var l = 0; l < e; l++){\n if(k[l] == 1){\n upvote++\n }else if(k[l] == 2){\n downvote++\n }else{\n undecided++\n }\n }\n console.log(upvote + undecided);\n }\n }\n})"}, {"source_code": "let inputString = '';\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', (data) => {\r\n inputString += data;\r\n})\r\nprocess.stdin.on('end', function (){\r\n inputString = inputString\r\n .trim()\r\n .split('\\n')\r\n .map((str) => str.trim());\r\n main();\r\n})\r\nfunction readLine(){\r\n return inputString[currentLine++];\r\n}\r\n\r\n\r\n\r\nfunction main(){\r\n let t = +readLine();\r\n while(t--){\r\n let n = +readLine();\r\n let a = readLine().split(' ').map(Number);\r\n let ans = 0;\r\n for(let i=0; i {\r\n let res = 0;\r\n for (const e of a) {\r\n if (e == 1 || e == 3) res++;\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "'use-strict'\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n\r\nlet data = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n\r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n\r\n let testCases = parseInt(readLine());\r\n\r\n while(testCases--) {\r\n\r\n const n = parseInt(readLine());\r\n\r\n const r = readLine().split(' ').map(Number);\r\n\r\n let max = 0;\r\n\r\n for(let i = 0 ; i < n ; i++){\r\n max += r[i] === 2 ? 0 : 1;\r\n }\r\n \r\n console.log(max);\r\n }\r\n});\r\n\r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n "}], "negative_code": [{"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var l1 = 0\r\n var d1 = 0\r\n var l2 = 0\r\n var d2 = 0\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 1) {\r\n l1 += 1\r\n }\r\n if (a[i] === 2) {\r\n d2 += 1\r\n }\r\n if (a[i] === 3 && l1 === 0) {\r\n l1 = 1\r\n continue\r\n }\r\n if (a[i] === 3 && d2 >= l2) {\r\n l2 += 1\r\n } else {\r\n d2 += 1\r\n }\r\n }\r\n\r\n console.log(l1 + l2)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nvar maxN = 2 * 1e5 + 10\r\nvar mod = BigInt(1e9 + 7)\r\n\r\n// Make a Snippet for the code above this and then write your logic in main();\r\n\r\nfunction main() {\r\n const xx = readline();\r\n Array(Number(xx)).fill(1).map((t, i) => {\r\n var n = parseInt(readline());\r\n // var [n, m] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // })\r\n // var [x, y] = readline().split(' ').map((x, iii) => {\r\n // return parseInt(x)\r\n // });\r\n var a = readline().split(' ').map((x, iii) => {\r\n return parseInt(x)\r\n })\r\n var l1 = 0\r\n var d1 = 0\r\n var l2 = 0\r\n var d2 = 0\r\n\r\n for (let i = 0; i < n; i++) {\r\n if (a[i] === 1) {\r\n l2 += 1\r\n }\r\n if (a[i] === 2) {\r\n d1 += 1\r\n }\r\n if (a[i] === 3 && d1 >= l1) {\r\n l1 += 1\r\n continue\r\n }\r\n if (a[i] === 3 && d2 >= l2) {\r\n l2 += 1\r\n continue\r\n }\r\n if (a[i] === 3) d1++\r\n }\r\n\r\n console.log(l1 + l2)\r\n\r\n })\r\n}\r\n\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(var j = 1; j <= n * 2; j++){\n if(j % 2 == 1){\n e = lines[j];\n }else{\n var k = lines[j].split(' ').map(Number);\n var upvote = 0;\n var downvote = 0;\n for(var l = 0; l < e; l++){\n if(k[l] == 1){\n upvote++;\n }else if(k[l] == 2){\n downvote++;\n }else{\n if(downvote > upvote){\n downvote++;\n }else{\n upvote++;\n }\n }\n }\n console.log(upvote);\n }\n }\n});"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\n\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\tfor(var i = 0; i < t; i++){\r\n\t\tvar N = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar L = 0;\r\n\t\tvar R = 0;\r\n\t\tfor(var j = 0; j < N; j++){\r\n\t\t\tif(list[j] == 1){\r\n\t\t\t\tL++;\r\n\t\t\t}else if(list[j] == 2){\r\n\t\t\t\tR++;\r\n\t\t\t}else{\r\n\t\t\t\tif(L < R){\r\n\t\t\t\t\tR++;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tL++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tmyout(L);\r\n\t}\r\n}\r\n"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ******** Code Start ********\r\n\r\nfunction main() {\r\n \r\n var t=readline();\r\n while(t--){\r\n var ans=0;\r\n var n=readline();\r\n for(var i=1;i<=n;i++){\r\n var a=readline();\r\n if(a==1) ans++;\r\n else if(a==3) ans++;\r\n }\r\n console.log(ans);\r\n }\r\n \r\n \r\n}\r\n"}], "src_uid": "a063705bd0ce1e17ccaafbbfc2663d93"} {"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var k = +readline();\n \n var robots = [];\n \n for(var j = 0; j < k; j++) {\n robots.push(readline().split(' ').map(item => +item));\n }\n \n var x1 = Math.max(-100000, ...robots.filter(item => item[2] === 0).map(item => item[0]));\n var y1 = Math.min(100000, ...robots.filter(item => item[3] === 0).map(item => item[1]));\n var x2 = Math.min(100000, ...robots.filter(item => item[4] === 0).map(item => item[0]));\n var y2 = Math.max(-100000, ...robots.filter(item => item[5] === 0).map(item => item[1]));\n if(x2 < x1 || y1 < y2) {\n print(0);\n } else {\n print(1, x1, y2);\n }\n}", "positive_code": [{"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var q = rdN();\n while (q --> 0) {\n var n = rdN();\n var T = +100000;\n var B = -100000;\n var L = -100000;\n var R = +100000;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var x = input[0];\n var y = input[1];\n var f1 = input[2];\n var f2 = input[3];\n var f3 = input[4];\n var f4 = input[5];\n if (!f1) { // L-move\n L = Math.max(L, x);\n }\n if (!f2) { // T-move\n T = Math.min(T, y);\n }\n if (!f3) { // R-move\n R = Math.min(R, x);\n }\n if (!f4) { // B-move\n B = Math.max(B, y);\n }\n }\n if (L > R || B > T) {\n pr(0);\n } else {\n pr(1, L, T);\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}], "negative_code": [{"source_code": "var n = +readline();\n\nfor(var i = 0; i < n; i++) {\n var k = +readline();\n \n var robots = [];\n \n for(var j = 0; j < k; j++) {\n robots.push(readline().split(' ').map(item => +item));\n }\n \n var x1 = Math.max(...robots.filter(item => item[2] === 0).map(item => item[0]));\n var y1 = Math.min(...robots.filter(item => item[3] === 0).map(item => item[1]));\n var x2 = Math.min(...robots.filter(item => item[4] === 0).map(item => item[0]));\n var y2 = Math.max(...robots.filter(item => item[5] === 0).map(item => item[1]));\n x1 === -Infinity && (x1 = -10000);\n y1 === Infinity && (y1 = 10000);\n x2 === Infinity && (x2 = 10000);\n y2 === -Infinity && (y2 = -10000);\n if(x2 < x1 || y1 < y2) {\n print(0);\n } else {\n print(1, x1, y2);\n }\n}"}, {"source_code": "(function() {\nvar INPUT = ``;\nvar OUTPUT = ``;\n\nvar main = function() {\"use strict\";\n // TODO\n var q = rdN();\n while (q --> 0) {\n var n = rdN();\n var T = +100000;\n var B = -100000;\n var L = -100000;\n var R = +100000;\n for (var i = 0; i < n; ++i) {\n var input = rdArN();\n var x = input[0];\n var y = input[1];\n var f1 = input[2];\n var f2 = input[3];\n var f3 = input[4];\n var f4 = input[5];\n if (!f1) { // L-move\n L = Math.max(L, x);\n }\n if (!f2) { // T-move\n T = Math.min(T, x);\n }\n if (!f3) { // R-move\n R = Math.min(R, x);\n }\n if (!f4) { // B-move\n B = Math.max(B, x);\n }\n }\n if (L > R || B > T) {\n pr(0);\n } else {\n pr(1, L, T);\n }\n }\n};\n\nif(INPUT){INPUT=INPUT.split('\\n').reverse();\nreadline=()=>INPUT.pop();\nwrite=(...s)=>{OUTPUT+=[...s].join(' ')};\nprint=(...s)=>{write(...s);OUTPUT+='\\n'};}\nconst rdS=readline;\nconst rdN=()=>+rdS();\nconst rdArS=()=>rdS().split(' ');\nconst rdArN=()=>rdArS().map(v=>+v);\nconst wr=write;\nconst pr=print;\nconst prAr=(a)=>pr(...a);\nconst prOb=(o)=>pr(JSON.stringify(o,null,4));\nconst cmpLt=(a,b)=>a-b;\nconst cmpGt=(a,b)=>b-a;\nconst crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};\nconst getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;jObject.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});\ndefineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});\ndefineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});\ndefineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});\ndefineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});\ndefineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});\n\nmain();\nreturn OUTPUT;\n})();"}], "src_uid": "e86ffda4e59c87acafeb3bf0aa805a52"} {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n let sum = new Array(c + 10).fill(0);\r\n\r\n for (let i = 1; i < sum.length; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n let left, right;\r\n\r\n if (set.has(i) && !set.has(j)) {\r\n var _sum;\r\n left = sum[i * j - 1], right = (_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1];\r\n } else if (set.has(j) && !set.has(i)) {\r\n var _sum2;\r\n left = sum[i * j - 1], right = (_sum2 = sum[(i + 1) * j - 1]) !== null && _sum2 !== void 0 ? _sum2 : sum[sum.length - 1];\r\n } else continue;\r\n\r\n const cur = right - left;\r\n if (cur) return 'NO';\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n", "positive_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n let sum = new Array(c + 10).fill(0);\r\n\r\n for (let i = 1; i < sum.length; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c / i; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n let left, right;\r\n\r\n if (set.has(i) && !set.has(j)) {\r\n var _sum;\r\n left = sum[i * j - 1], right = (_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1];\r\n } else if (set.has(j) && !set.has(i)) {\r\n var _sum2;\r\n left = sum[i * j - 1], right = (_sum2 = sum[(i + 1) * j - 1]) !== null && _sum2 !== void 0 ? _sum2 : sum[sum.length - 1];\r\n } else continue;\r\n\r\n const cur = right - left;\r\n if (cur) return 'NO';\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}], "negative_code": [{"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n let sum = new Array(c + 10).fill(0);\r\n\r\n for (let i = 1; i < sum.length; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c / i; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n var _sum;\r\n\r\n const left = sum[i * j - 1],\r\n right = (_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1];\r\n const cur = right - left;\r\n if (!cur) continue;\r\n\r\n if (set.has(i) && !set.has(j) || set.has(j) && !set.has(i)) {\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const sum = [0];\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n for (let i = 1; i <= c + 10; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c / 2; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n let right = i * (j + 1) - 1 > c ? sum[sum.length - 1] : sum[i * (j + 1) - 1],\r\n left = i * j - 1 > c ? sum[sum.length - 1] : sum[i * j - 1];\r\n const cur = right - left;\r\n if (set.has(i) && !set.has(j) && cur || !set.has(i) && set.has(j) && cur) return 'NO';\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const sum = [0];\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n for (let i = 1; i <= c; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n var _sum, _sum2;\r\n\r\n const cur = ((_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1]) - ((_sum2 = sum[i * j - 1]) !== null && _sum2 !== void 0 ? _sum2 : sum[sum.length - 1]);\r\n\r\n if (set.has(i) && !set.has(j) && cur > 0 || !set.has(i) && set.has(j) && cur > 0) {\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const sum = [0];\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n for (let i = 1; i <= c; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c / i; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n var _sum, _sum2;\r\n\r\n const cur = ((_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1]) - ((_sum2 = sum[i * j - 1]) !== null && _sum2 !== void 0 ? _sum2 : sum[sum.length - 1]);\r\n\r\n if (set.has(i) && !set.has(j) && cur > 0 || !set.has(i) && set.has(j) && cur > 0) {\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const sum = [0];\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n for (let i = 1; i <= c; i++) {\r\n sum[i] = sum[i - 1] + (set.has(i) ? 1 : 0);\r\n }\r\n\r\n for (let i = 2; i <= c / i; i++) {\r\n for (let j = i; j <= c / i; j++) {\r\n var _sum;\r\n\r\n const cur = ((_sum = sum[i * (j + 1) - 1]) !== null && _sum !== void 0 ? _sum : sum[sum.length - 1]) - sum[i * j - 1];\r\n\r\n if (set.has(i) && !set.has(j) && cur > 0 || !set.has(i) && set.has(j) && cur > 0) {\r\n return 'NO';\r\n }\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n this.add = this._add.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = false, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _add(node, x) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === r) {\r\n node.val = true;\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (x <= mid) this._add(node.left, x);else this._add(node.right, x);\r\n node.val = node.left.val || node.right.val;\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return false;\r\n if (!node) return false;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = false,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) || this._query(node.right, mid + 1, y);\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const segTree = new SegTree(c + 10);\r\n\r\n for (let num of data) {\r\n segTree.add(num);\r\n }\r\n\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n const primes = [],\r\n nums = new Array(c).fill(1);\r\n nums[0] = nums[1] = 0;\r\n\r\n for (let i = 2; i <= c; i++) {\r\n if (nums[i]) primes.push(i);\r\n\r\n for (let j of primes) {\r\n const k = j * i;\r\n if (k > c) break;\r\n nums[k] = 0;\r\n if (set.has(i) || set.has(j)) {\r\n const hasProduct = segTree.query(k, (i + 1) * j - 1);\r\n\r\n if (set.has(i) && !set.has(j) && hasProduct || !set.has(i) && set.has(j) && hasProduct) {\r\n return 'NO';\r\n }\r\n }\r\n\r\n if (i % k === 0) break;\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n this.add = this._add.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = false, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _add(node, x) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === r) {\r\n node.val = true;\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (x <= mid) this._add(node.left, x);else this._add(node.right, x);\r\n node.val = node.left.val || node.right.val;\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return false;\r\n if (!node) return false;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = false,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) || this._query(node.right, mid + 1, y);\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const segTree = new SegTree(c + 10);\r\n\r\n for (let num of data) {\r\n segTree.add(num);\r\n }\r\n\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n const primes = [],\r\n nums = new Array(c).fill(1);\r\n nums[0] = nums[1] = 0;\r\n\r\n for (let i = 2; i <= c; i++) {\r\n if (nums[i]) primes.push(i);\r\n\r\n for (let j of primes) {\r\n const k = j * i;\r\n if (k > c) break;\r\n nums[k] = 0;\r\n const hasProduct = segTree.query(k, (i + 1) * j - 1);\r\n\r\n if (set.has(i) && !set.has(j) && hasProduct || !set.has(i) && set.has(j) && hasProduct) {\r\n return 'NO';\r\n }\r\n\r\n if (i % k === 0) break;\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nclass SegTree {\r\n constructor(n) {\r\n this.n = n;\r\n this.root = this._newNode(0, n);\r\n this.add = this._add.bind(this, this.root);\r\n this.query = this._query.bind(this, this.root);\r\n }\r\n\r\n _newNode(l, r, val = false, left = null, right = null) {\r\n return {\r\n val,\r\n l,\r\n r,\r\n left,\r\n right\r\n };\r\n }\r\n\r\n _add(node, x) {\r\n if (!node) return;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n\r\n if (l === r) {\r\n node.val = true;\r\n return;\r\n }\r\n\r\n const mid = Math.floor((l + r) / 2);\r\n\r\n if (!node.left) {\r\n node.left = this._newNode(l, mid);\r\n node.right = this._newNode(mid + 1, r);\r\n }\r\n\r\n if (x <= mid) this._add(node.left, x);else this._add(node.right, x);\r\n node.val = node.left.val || node.right.val;\r\n }\r\n\r\n _query(node, x, y) {\r\n if (y < x) return false;\r\n if (!node) return false;\r\n const {\r\n l,\r\n r\r\n } = node;\r\n if (l === x && r === y) return node.val;\r\n let res = false,\r\n mid = Math.floor((l + r) / 2);\r\n if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) || this._query(node.right, mid + 1, y);\r\n return res;\r\n }\r\n\r\n}\r\n\r\nfunction solve(n, c, data) {\r\n data.sort((a, b) => a - b);\r\n const segTree = new SegTree(c + 10);\r\n\r\n for (let num of data) {\r\n segTree.add(num);\r\n }\r\n\r\n const set = new Set(data);\r\n if (!set.has(1)) return 'NO';\r\n\r\n for (let i = 2; i < c; i++) {\r\n let hasi = set.has(i);\r\n\r\n for (let j = i; j * i <= c; j++) {\r\n const hasProduct = segTree.query(i * j, i * (j + 1) - 1);\r\n if (hasi && set.has(j) && hasProduct || !hasi && !set.has(j) && !hasProduct) continue;\r\n return 'NO';\r\n }\r\n }\r\n\r\n return 'YES';\r\n}\r\n\r\n// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\\n')\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split('\\n');\r\nvoid function main() {\r\n const _ = Number(inputs[0]);\r\n\r\n for (let __ = 0; __ < _; __++) {\r\n const [n, c] = inputs[__ * 2 + 1].trim().split(' ').map(Number);\r\n const data = inputs[__ * 2 + 2].trim().split(' ').map(Number);\r\n const res = solve(n, c, data);\r\n console.log(res);\r\n }\r\n}();\r\n"}], "src_uid": "bda76c8ccd3ba7d073a8f923d772361c"} {"source_code": "var s = readline().split( ' ' ),\n n = s[0] - '',\n k = s[1] - '';\n\nif (k < Math.floor( n/2 ) || 1 === n && k > 0) {\n print( -1 );\n} else {\n var ans = [k - Math.floor( n/2 ) + 1];\n n > 1 && ans.push( ans[0] * 2 );\n for (var i=2; itotalScore) {\n print(-1);\n return;\n }\n var arr=[];\n var x=totalScore-Math.floor((sequenceLength-2)/2);\n arr[0]=x;\n arr[1]=x*2;\n for(var i=2; i 0) {\n print( -1 );\n } else {\n var ans = [k - Math.floor( n/2 ) + 1];\n n > 1 && ans.push( ans[0] * 2 );\n for (var i=2; i max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(20000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar rowA = 0, columnA = 0,\n\t\trowB = Math.floor(numPrimes/2), columnB = rowB;\n\n\tfunction advance() {\n\t\t++columnA;\n\t\t++columnB;\n\t\tif (columnB == numPrimes) {\n\t\t\t++rowA;\n\t\t\t++rowB;\n\t\t\tcolumnA = rowA;\n\t\t\tcolumnB = rowB;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[rowA]*primes[columnA];\n\t\t\tvar b = primes[rowB]*primes[columnB];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(20000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [], a = 2, b;\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\ta += 2;\n\t\t\tb = a+1;\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 2 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}], "negative_code": [{"source_code": ";(function () {\n\n\tprint(function (n, k) {\n\n\t\tvar t = Math.floor(n/2);\n\n\t\tif (k < t) return -1;\n\n\t\tvar result = [k - t + 1]; result.push(result[0] * 2);\n\t\twhile (result.length < n) result.push(result.slice(-1)[0] + 1);\n\n\t\treturn result.join(' ');\n\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\n\tprint(function (n, k) {\n\n\t\tvar t = Math.floor(n/2);\n\n\t\tif (k < t) return -1;\n\t\tif (n === 1 && k !== 0) return -1;\n\n\t\tvar result = [k - t + 1]; result.push(result[0] * 2);\n\t\twhile (result.length < n) result.push(result.slice(-1)[0] + 1);\n\n\t\treturn result.join(' ');\n\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));\n"}, {"source_code": ";(function () {\n\n\tprint(function (n, k) {\n\n\t\tvar t = Math.floor(n/2);\n\n\t\tif (k < t) return -1;\n\n\t\tvar result = [k - t + 1, k - t + 1];\n\t\twhile (result.length < n) result.push(1);\n\n\t\treturn result.join(' ');\n\n\t}.apply(null, readline().split(' ').map(Number)));\n\n}.call(this));\n"}, {"source_code": "var s = readline(),\n n = s[0] - '',\n k = s[1] - '';\n\nif (k < Math.floor( n/2 ) || 1 === n && k > 0) {\n print( -1 );\n} else {\n var ans = [k - Math.floor( n/2 ) + 1];\n ans.push( ans[0] * 2 );\n for (var i=2; i 0) {\n print( -1 );\n} else {\n var ans = [k - Math.floor( n/2 ) + 1];\n ans.push( ans[0] * 2 );\n for (var i=2; i 0) {\n print( -1 );\n} else {\n var ans = [k, k*2];\n //ans.push( ans[0] * 2 );\n for (var i=2; itotalScore) {\n print(-1);\n return;\n }\n var arr=[];\n var x=totalScore-Math.floor((sequenceLength-2)/2);\n arr[0]=x;\n arr[1]=x*2;\n for(var i=2; itotalScore) {\n print(-1);\n return;\n }\n var arr=[];\n var x=totalScore-(sequenceLength-2)/2;\n arr[0]=x;\n arr[1]=x*2;\n for(var i=2; itotalScore) {\n print(-1);\n return;\n }\n var x=totalScore-(sequenceLength-2)/2;\n print(x+ \" \" + x*2);\n for(var i=2; i max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar rowA = 0, rowB = Math.floor(numPrimes/2),\n\t\tcolumnA = 0, columnB = numPrimes-1;\n\n\tfunction advance() {\n\t\t++columnA;\n\t\t--columnB;\n\t\tif (columnB <= columnA) {\n\t\t\t++rowA;\n\t\t\t++rowB;\n\t\t\tcolumnA = 0;\n\t\t\tcolumnB = numPrimes-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[rowA]*primes[columnA];\n\t\t\tvar b = primes[rowB]*primes[columnB];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPairs-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPairs-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tadvance();\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPairs-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPairs-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tadvance();\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\tprint(numPrimes);\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPairs-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPairs-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tadvance();\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(20000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar rowA = 0, rowB = Math.floor(numPrimes/2),\n\t\tcolumnA = 0, columnB = numPrimes-1;\n\n\tfunction advance() {\n\t\t++columnA;\n\t\t--columnB;\n\t\tif (columnB <= columnA) {\n\t\t\t++rowA;\n\t\t\t++rowB;\n\t\t\tcolumnA = rowA;\n\t\t\tcolumnB = numPrimes-1-rowA;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[rowA]*primes[columnA];\n\t\t\tvar b = primes[rowB]*primes[columnB];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPrimes-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPrimes-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t//print(\"row = \"+row+\", column = \"+column+\", oppositeColumn = \"+\n\t\t//\t\toppositeColumn+\", a = \"+a+\", b = \"+b);\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(20000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar rowA = 0, columnA = 0,\n\t\trowB = Math.floor(numPrimes/2), columnB = rowB;\n\n\tfunction advance() {\n\t\t++columnA;\n\t\t++columnB;\n\t\tif (columnB <= columnA) {\n\t\t\t++rowA;\n\t\t\t++rowB;\n\t\t\tcolumnA = rowA;\n\t\t\tcolumnB = rowB;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[rowA]*primes[columnA];\n\t\t\tvar b = primes[rowB]*primes[columnB];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPrimes-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPrimes-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tprint(\"row = \"+row+\", column = \"+column+\", oppositeColumn = \"+\n\t\t\t\toppositeColumn+\", a = \"+a+\", b = \"+b);\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1 || Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(10000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar row = 0, column = 0, oppositeColumn = numPairs-1;\n\n\tfunction advance() {\n\t\t++column;\n\t\t--oppositeColumn;\n\t\tif (oppositeColumn <= column) {\n\t\t\trow += 2;\n\t\t\tcolumn = 0;\n\t\t\toppositeColumn = numPairs-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[row]*primes[column];\n\t\t\tvar b = primes[row+1]*primes[oppositeColumn];\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tadvance();\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction eratosthenes(max) {\n\tvar mark = new Array(max+1);\n\tvar primes = [];\n\tvar pos = 1;\n\twhile (true) {\n\t\tpos += 1;\n\t\twhile (pos <= max && mark[pos]) {\n\t\t\tpos += 1;\n\t\t}\n\t\tif (pos > max) {\n\t\t\tbreak;\n\t\t}\n\t\tprimes.push(pos);\n\t\tfor (var seek = 2*pos; seek <= max; seek += pos) {\n\t\t\tmark[seek] = true;\n\t\t}\n\t}\n\treturn primes;\n}\n\nfunction main() {\n\tvar data = tokenizeIntegers(readline());\n\tvar sequenceLength = data[0], totalScore = data[1];\n\n\tif (sequenceLength == 1) {\n\t\tprint(totalScore == 0 ? 1 : -1);\n\t\treturn;\n\t}\n\n\tif (Math.floor(sequenceLength/2) > totalScore) {\n\t\tprint(-1);\n\t\treturn;\n\t}\n\n\tvar primes = eratosthenes(20000),\n\t\tnumPrimes = primes.length;\n\n\tvar numPairs = Math.floor(sequenceLength/2);\n\tvar sequence = [];\n\tvar rowA = 0, rowB = Math.floor(numPrimes/2),\n\t\tcolumnA = 0, columnB = numPrimes-1;\n\n\tfunction advance() {\n\t\t++columnA;\n\t\t--columnB;\n\t\tif (columnB <= columnA) {\n\t\t\t++rowA;\n\t\t\t++rowB;\n\t\t\tcolumnA = rowA;\n\t\t\tcolumnB = numPrimes-1;\n\t\t}\n\t}\n\n\tvar remainder = totalScore + 1 - numPairs;\n\n\tfor (var pairIndex = numPairs-1; pairIndex > 0; --pairIndex) {\n\t\twhile (true) {\n\t\t\tvar a = primes[rowA]*primes[columnA];\n\t\t\tvar b = primes[rowB]*primes[columnB];\n\t\t\tadvance();\n\t\t\tif (a != remainder && a != 2*remainder &&\n\t\t\t\t\tb != remainder && b != 2*remainder) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsequence.push(a);\n\t\tsequence.push(b);\n\t}\n\n\tif (remainder > 0) {\n\t\tsequence.push(remainder);\n\t\tsequence.push(remainder*2);\n\t}\n\n\tif (sequenceLength % 2 == 1) {\n\t\tsequence.push(remainder == 3 ? 5 : 3);\n\t}\n\n\tprint(sequence.join(\" \"));\n}\n\nmain();\n"}], "src_uid": "b85c8bfbe67a23a81bef755f9313115a"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let l = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n let [a, b, x, y, n] = l;\n\n let [small, large] =\n Math.max(a - n, x) < Math.max(b - n, y)\n ? [\n [a, x],\n [b, y],\n ]\n : [\n [b, y],\n [a, x],\n ];\n let rest = Math.max(-(small[0] - small[1] - n), 0);\n small[0] -= n;\n let finalsmall = BigInt(Math.max(small[0], small[1]));\n large[0] -= rest;\n let finallarge = BigInt(Math.max(large[0], large[1]));\n\n let res = (finalsmall * finallarge).toString();\n console.log(res);\n }\n}\n", "positive_code": [{"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i < b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = b - 1; i >= a; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\nfunction max(a, b) {\n if (a > b) return a;\n return b;\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(0, t, i => {\n let [a, b, x, y, n] = inp.slice(r, r = r + 5).map(v => BigInt(v));\n let min1, min2;\n if (n >= b - y) min1 = y * max(x, a - (n - (b - y)));\n else min1 = a * (b - n);\n if (n >= a - x) min2 = x * max(y, b - (n - (a - x)));\n else min2 = b * (a - n);\n console.log(min1 < min2 ? min1 + '' : min2 + '');\n })\n})();"}], "negative_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let l = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n let [a, b, x, y, n] = l;\n\n let [small, large] =\n Math.max(a - n, x) < Math.max(b - n, y)\n ? [\n [a, x],\n [b, y],\n ]\n : [\n [b, y],\n [a, x],\n ];\n let rest = Math.max(-(small[0] - small[1] - n), 0);\n small[0] -= n;\n let finalsmall = Math.max(small[0], small[1]);\n large[0] -= rest;\n let finallarge = Math.max(large[0], large[1]);\n\n console.log(finalsmall * finallarge);\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nlet standardInputString = \"\";\nlet currentLine = 0;\n\nfunction readLine() {\n return standardInputString[currentLine++];\n}\n\nprocess.stdin.on(\"data\", (rawData) => {\n standardInputString += rawData;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n standardInputString = standardInputString\n .trim()\n .split(\"\\n\")\n .map((line) => line.trim());\n\n main();\n});\n\nfunction main() {\n const t = parseInt(readLine());\n for (let i = 0; i < t; i++) {\n let l = readLine()\n .split(\" \")\n .map((el) => parseInt(el));\n let [a, b, x, y, n] = l;\n\n let [small, large] =\n a < b\n ? [\n [a, x],\n [b, y],\n ]\n : [\n [b, y],\n [a, x],\n ];\n let rest = Math.max(-(small[0] - small[1] - n), 0);\n small[0] -= n;\n small = Math.max(small[0], small[1]);\n large[0] -= rest;\n large = Math.max(large[0], large[1]);\n\n console.log(large * small);\n }\n}\n"}, {"source_code": "let input = '';\nlet inputResolve;\nlet inputPromise = new Promise(resolve => inputResolve = resolve);\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', () => inputResolve());\n\nfunction For(a, b, cb) {\n let res;\n if (a < b) {\n for (let i = a; i < b; i++) {\n if ((res = cb(i)) !== undefined) return res;\n }\n } else {\n for (let i = b - 1; i >= a; i--) {\n if ((res = cb(i)) !== undefined) return res;\n }\n }\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n\n(async () => {\n await inputPromise;\n let inp = input.split(/\\D+/).map(v => +v); r = 0;\n let t = inp[r++];\n For(0, t, i => {\n let [a, b, x, y, n] = inp.slice(r, r = r + 5);\n let min1, min2;\n if (n >= b - y) min1 = y * Math.max(x, a - (n - (b - y)));\n else min1 = a * (b - n);\n if (n >= a - x) min2 = x * Math.max(y, b - (n - (a - x)));\n else min2 = b * (a - n);\n console.log(Math.min(min1, min2));\n })\n})();"}], "src_uid": "04753f73af685b4e7339d30d6d47c161"} {"source_code": "var howManyToChange = function ( s ) {\n var letters,\n engLettersCount = 26;\n if ( s.length > engLettersCount ) {\n return;\n }\n\n letters = new Set( s );\n return s.length - letters.size;\n};\n\nreadline();\nvar toChange = howManyToChange( readline() );\nif ( typeof toChange === \"undefined\" ) {\n print( -1 );\n} else {\n print( toChange );\n}\n\n", "positive_code": [{"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nvar alphabet = \"abcdefghijklmnopqrstuvwxyz\";\nvar lastIndex = 0;\n\nfunction main() {\n\tvar input = getInput();\n\tvar str = input[1];\n \n if (str.length > alphabet.length) {\n print(-1);\n return;\n }\n var c = 0;\n str.split('').forEach((item, index, arr) => {\n var ind = arr.indexOf(item, index + 1);\n if (ind !== -1) {\n c++;\n }\n });\n\tprint(c);\n}\n\nfunction _main() {\n\tvar input = getInput();\n\tvar str = input[1];\n\tvar res = solve(str);\n\t\n\tif (res === undefined) {\n\t print(-1);\n\t return;\n\t}\n\t\n\tvar c = 0;\n\tfor(var i = 0, k = str.length; i < k; i++) {\n\t if (res[i] !== str[i]) {\n\t c++;\n\t }\n\t}\n\tprint(c);\n}\n\nfunction solve(str, a) {\n\tif (lastIndex > alphabet.length) {\n\t return undefined;\n\t}\n\t\n\tvar changed = false;\n\tvar answ = str.split('').map((item, i, arr) => {\n\t\tvar ind = arr.indexOf(item, i + 1);\n\t\tif (ind !== -1 && ind !== i) {\n\t\t\tchanged = true;\n\t\t\treturn alphabet[lastIndex++];\n\t\t}\n\t\treturn item;\n\t}).join('');\n\t\n\treturn changed ? solve(answ) : answ;\n}\n\nmain();"}, {"source_code": "function main(n,str){\n\n var chars = {};\n var cnt = 0;\n\n if(n > 26){\n print(-1);\n return;\n }\n\n for(var i = 0 ; i < n ; i++){\n if(chars[str[i]] !== 1)chars[str[i]] = 1;\n else cnt++;\n }\n print(cnt);\n}\n\n\nvar n = parseInt(readline());\n\n// var arr = readline().split(' ');\n// for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);\n\nvar str = readline();\n\nmain(n,str);\n"}, {"source_code": "var n = +readline();\nif (n > 26) {\n print(-1)\n} else {\n print(n - new Set(readline()).size)\n}"}, {"source_code": "var n = +readline();\nprint(n > 26 ? -1: n - new Set(readline()).size);"}, {"source_code": "var n = parseInt(readline());\n\nvar s = readline().trim();\n\nvar e = new Set(s.split(''));\n\nvar ans=s.length-Array.from(e).length;\nprint(s.length>26?-1:ans)"}, {"source_code": "var n = +readline();\nif (n > 26) {\n print(-1)\n} else {\n var s = readline();\n print(s.length - new Set(s).size)\n}"}, {"source_code": "var n = Number(readline());\nvar string = readline().split('').map(String);\n\n// create an object to keep track of how many times each letter is present in the original string\nvar count = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (string[i] in count) {\n\t\tcount[string[i]] += 1;\n\t} else {\n\t\tcount[string[i]] = 1;\n\t}\n}\n\nvar letters = Object.keys(count).length // how many distinct letters are int the original string\n\nvar changes = 0;\n\nfor (var key in count) {\n\tif (count[key] >= 2) {\n\t\tchanges += count[key] - 1;\n\t} \n}\n\n// If I would have to change more letters than whatever letters are still available, then it's impossible\nif (changes > 26 - letters) {\n\tchanges = -1;\n}\n\nprint(changes);"}, {"source_code": "function main() {\n var n = Number(readline());\n var s = String(readline());\n\n if (s.length > 26) {\n print(-1);\n return; \n }\n\n var count = new Array(26);\n var i = 0;\n for (i = 0; i < 26; ++i) {\n count[i] = 0;\n }\n var a_code = \"a\".charCodeAt(0);\n for (i = 0; i < n; ++i) {\n var j = s.charCodeAt(i) - a_code;\n ++count[j];\n }\n\n var ans = 0;\n for (i = 0; i < 26; ++i) {\n if (count[i] > 1) {\n ans += count[i] - 1;\n }\n }\n\n print(ans);\n}\n\nmain();\n"}, {"source_code": "var n = +readline();\nvar s = readline();\n\nconst aCode = 'a'.charCodeAt(0);\nconst zCode = 'z'.charCodeAt(0);\nconst cardinality = zCode - aCode + 1;\n\nif (s.length > cardinality) {\n write('-1');\n quit();\n}\n\nvar u = [...new Set(s)].join('');\n\nwrite(s.length - u.length)"}, {"source_code": "function rda(){ return readline().split(\" \").map(Number); }\nfunction rdn(){ return +readline(); }\n\nvar n = rdn();\nvar s = readline().split(\"\");\n\nvar ans;\nif(n > 26){\n ans = -1;\n}else{\n var u = [];\n for(var i = 0; i < n; i++){\n if(u.indexOf(s[i]) == -1) u.push(s[i]);\n }\n ans = n-u.length;\n}\n\nwrite(ans);"}, {"source_code": "var n = parseInt(readline());\nvar str = readline();\n\nif (n > 26) {\n\tprint(\"-1\");\n}\nelse {\n\tvar s = {};\n\tfor (var i = 0; i < n; i++) {\n\t\ts[str[i]] = true;\n\t}\n\n\tprint(n - Object.keys(s).length);\n}\n"}, {"source_code": "\"use strict\";\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar str = readline();\n\t\n\tif (n > 26) {\n\t\tprint(\"-1\");\n\t\treturn;\n\t}\n\n\tvar s = {};\n\tfor (let i = 0; i < n; i++) {\n\t\ts[str[i]] = true;\n\t}\n\n\tprint(n - Object.keys(s).length);\n}\n\nmain();"}, {"source_code": "\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar str = readline();\n\t\n\tif (n > 26) {\n\t\tprint(\"-1\");\n\t\treturn;\n\t}\n\n\tvar s = {};\n\tfor (var i = 0; i < n; i++) {\n\t\ts[str[i]] = true;\n\t}\n\n\tprint(n - Object.keys(s).length);\n}\n\nmain();"}], "negative_code": [{"source_code": "var n = parseInt(readline());\n\nvar s = readline().trim();\n\nvar e = new Set(s.split(''));\n\nvar ans=s.length-Array.from(e).length;\nprint(ans>=26?-1:ans)"}, {"source_code": "var n = parseInt(readline());\n\nvar s = readline().trim();\n\nvar e = new Set(s.split(''));\n\nvar ans=s.length-Array.from(e).length;\nprint(ans>=24?-1:ans)"}, {"source_code": "var n = parseInt(readline());\n\nvar s = readline().trim();\n\nvar e = new Set(s.split(''));\n\nvar ans=s.length-Array.from(e).length;\nprint(ans>26?-1:ans)"}, {"source_code": "var n = Number(readline());\nvar string = readline().split('').map(String);\n\nvar count = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (string[i] in count) {\n\t\tcount[string[i]] += 1;\n\t} else {\n\t\tcount[string[i]] = 1;\n\t}\n}\n\nvar changes = 0;\n\nfor (var key in count) {\n\tif (count[key] >= 2) {\n\t\tchanges += count[key] - 1;\n\t}\n}\n\n\nprint(changes);"}, {"source_code": "var n = Number(readline());\nvar string = readline().split('').map(String);\n\nvar count = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (string[i] in count) {\n\t\tcount[string[i]] += 1;\n\t} else {\n\t\tcount[string[i]] = 1;\n\t}\n}\n\nvar changes = 0;\n\nfor (var key in count) {\n\tif (count[key] >= 2) {\n\t\tchanges += count[key] - 1;\n\t}\n}\n\nprint(changes);"}, {"source_code": "var n = Number(readline());\nvar string = readline().split('').map(String);\n\nvar count = {};\n\nfor (var i = 0; i < n; i++) {\n\tif (string[i] in count) {\n\t\tcount[string[i]] += 1;\n\t} else {\n\t\tcount[string[i]] = 1;\n\t}\n}\n\nvar changes = 0;\n\nfor (var key in count) {\n\tif (count[key] >= 2) {\n\t\tchanges += count[key] - 1;\n\t}\n}\n\nprint(JSON.stringify(count));\nprint(changes);"}, {"source_code": "var n = +readline();\nvar s = readline();\n\nconst aCode = 'a'.charCodeAt(0);\nconst zCode = 'z'.charCodeAt(0);\nconst cardinality = zCode - aCode;\n\nif (s.length > cardinality) {\n write('-1');\n quit();\n}\n\nvar u = [...new Set(s)].join('');\n\nwrite(s.length - u.length)"}, {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nvar alphabet = \"abcdefghijklmnopqrstuvwxyz\";\nvar lastIndex = 0;\n\nfunction main() {\n\tvar input = getInput();\n\tvar str = input[1];\n\tvar res = solve(str);\n\t\n\tif (res === undefined) {\n\t print(-1);\n\t return;\n\t}\n\t\n\tvar c = 0;\n\tfor(var i = 0, k = str.length; i < k; i++) {\n\t if (res[i] !== str[i]) {\n\t c++;\n\t }\n\t}\n\tprint(c, res);\n}\n\nfunction solve(str, a) {\n\tif (lastIndex > alphabet.length) {\n\t return undefined;\n\t}\n\t\n\tvar changed = false;\n\tvar answ = str.split('').map((item, i, arr) => {\n\t\tvar ind = arr.indexOf(item, i + 1);\n\t\tif (ind !== -1 && ind !== i) {\n\t\t\tchanged = true;\n\t\t\treturn alphabet[lastIndex++];\n\t\t}\n\t\treturn item;\n\t}).join('');\n\t\n\treturn changed ? solve(answ) : answ;\n}\n\nmain();"}, {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nvar alphabet = \"abcdefghijklmnopqrstuvwxyz\";\nvar lastIndex = 0;\n\nfunction main() {\n\tvar input = getInput();\n\tvar str = input[1];\n\tvar res = solve(str);\n\t\n\tif (res === undefined) {\n\t print(-1);\n\t return;\n\t}\n\t\n\tvar c = 0;\n\tfor(var i = 0, k = str.length; i < k; i++) {\n\t if (res[i] !== str[i]) {\n\t c++;\n\t }\n\t}\n\tprint(c);\n}\n\nfunction solve(str, a) {\n\tif (lastIndex > alphabet.length) {\n\t return undefined;\n\t}\n\t\n\tvar changed = false;\n\tvar answ = str.split('').map((item, i, arr) => {\n\t\tvar ind = arr.indexOf(item, i + 1);\n\t\tif (ind !== -1 && ind !== i) {\n\t\t\tchanged = true;\n\t\t\treturn alphabet[lastIndex++];\n\t\t}\n\t\treturn item;\n\t}).join('');\n\t\n\treturn changed ? solve(answ) : answ;\n}\n\nmain();"}, {"source_code": "function getInput() {\n var line = readline();\n var lines = [line];\n while (line = readline()) {\n lines.push(line);\n }\n return lines;\n}\n\nvar alphabet = \"abcdefghijklmnopqrstuvwxyz\";\nvar lastIndex = 0;\n\nfunction main() {\n\tvar input = getInput();\n\tvar str = input[1];\n\tvar res = solve(str);\n\tvar c = 0;\n\tfor(var i = 0, k = str.length; i < k; i++) {\n\t if (res[i] !== str[i]) {\n\t c++;\n\t }\n\t}\n\tprint(c);\n}\n\nfunction solve(str) {\n\tvar changed = false;\n\tvar answ = str.split('').map((item, i, arr) => {\n\t\tvar ind = arr.indexOf(item, i + 1);\n\t\tif (ind !== -1 && ind !== i) {\n\t\t\tchanged = true;\n\t\t\treturn alphabet[lastIndex++];\n\t\t}\n\t\treturn item;\n\t}).join('');\n\t\n\treturn changed ? solve(answ) : answ;\n}\n\nmain();"}], "src_uid": "d9e9c53b391eb44f469cc92fdcf3ea0a"} {"source_code": "var nextToken = new function() {\n var line = [];\n var lineIndex = 0;\n\n return function() {\n while (lineIndex >= line.length) {\n line = readline().split(/\\s+/);\n lineIndex = 0;\n }\n \n return line[lineIndex++];\n }\n}();\n\nvar nextInt = function() {\n return parseInt(nextToken(), 10);\n};\n\nvar main = function () {\n var n = nextInt(); \n var v = nextInt();\n var ans = [];\n var i, j, good, cnt, cur;\n\n for (i = 0; i < n; ++i) {\n cnt = nextInt();\n good = false;\n\n for (j = 0; j < cnt; ++j) {\n cur = nextInt();\n if (cur < v) {\n good = true; \n }\n }\n\n if (good) {\n ans.push(i + 1);\n }\n }\n\n print(ans.length);\n print(ans.join(\" \"));\n};\n\nmain();\n", "positive_code": [{"source_code": "\n// 441A \u0412\u0430\u043b\u0435\u0440\u0430 \u0438 \u0430\u043d\u0442\u0438\u043a\u0432\u0430\u0440\u0438\u0430\u0442 \n\n\n//var n = parseInt(readline());\nvar input_line = readline().split(' ').map(Number);\nvar n = parseInt(input_line[0]);\nvar v = parseInt(input_line[1]);\n\nvar out = '';\nvar count = 0;\n\nfor (var i = 1; i <= n; i++) {\n input_line = readline().split(' ').map(Number);\n for (j = 1; j <= input_line[0]; j ++) {\n if (parseInt(input_line[j]) < v) {\n out += i + ' ';\n count ++;\n break;\n };\n }\n};\n\nprint(count);\nprint(out);\n\n\n"}, {"source_code": "const readline = require('readline');\n\n\nlet inputs = [];\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\n\n// Read Inputs\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n\n// Excute algorithm\nrl.on('close', () => {\n let line1 = inputs[0].split(' ').map(num => +num);\n const n = line1[0];\n const v = line1[1];\n let canDealWith = [];\n\n for (let i = 1; i < n + 1; i++) {\n const canMakeDeal = inputs[i].split(' ').slice(1).some(price => v > price);\n if (canMakeDeal)\n canDealWith.push(i);\n }\n\n\n console.log(canDealWith.length)\n\n if (canDealWith.length)\n console.log(...canDealWith)\n\n\n\n})"}, {"source_code": "var line;\nline = readline().split(' ');\nvar n = parseInt(line[0]), v = parseInt(line[1]);\nvar ret = '', elems = 0;\nfor(var i = 0; i < n; i++) {\n line = readline().split(' ');\n var k = parseInt(line[0]);\n var minValue = 1 << 30;\n for(var j = 1; j < line.length; j++) {\n if(minValue > parseInt(line[j])) {\n minValue = parseInt(line[j]);\n }\n }\n if(minValue < v) {\n if(ret.length !== 0) ret += ' ';\n ret += (i + 1);\n ++elems;\n }\n}\nprint(elems);\nprint(ret);\n"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\n\n\nprint(function(n, v) {\n\n var ans = [];\n\n for (var i = 0; i < n; i++) {\n var s = readline().split(' ').map(Number);\n for (var j = 1; j <= s.length; j++) {\n if (s[j] < v) {\n ans.push(i + 1);\n break;\n }\n }\n }\n return ans.length + '\\n' + ans.sort(function(a, b) {\n return a - b;\n }).join(' ');\n\n\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": "var input = readline().split(\" \"), n = +input[0], v = +input[1];\nvar ans = [], id, k;\n\nfor(var i = 0; i < n; i++){\n\tinput = readline().split(\" \").map(Number);\n\tid = i+1;\n\tk = input.shift();\n\n\tfor(var j = 0; j < k; j++){\n\t\tif(v > input[j]){\n\t\t\tans.push(id);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nwrite(ans.length);\nif(ans.length > 0){\n\twrite(\"\\n\" + ans.join(\" \"));\n}"}, {"source_code": "function main(n,v,arr){\n\n\n var ans = [];\n var index = 0;\n var ansstr = \"\";\n\n for(var i = 0 ; i < n ; i++ ){\n for(var j = 1; j < arr[i].length ; j++){\n if(v > parseInt(arr[i][j])){\n ans[index] = parseInt(i)+1;\n index++;\n break;\n }\n }\n }\n if(ans.length === 0){\n print(\"0\")\n return;\n };\n print(ans.length);\n for(var i = 0 ; i 0) {\n\t\tprint(result.join(' '));\n\t}\n}\n\nmain();\n"}, {"source_code": "var N = readline().split(' ').map(Number),\n r = Array.apply(null, Array(N[0])).map(readline)\n .map(function(v, i) { return [i + 1, v.split(' ').map(Number).slice(1).sort(function(a,b){return a-b})[0]]; })\n .filter(function(_) { return _[1] < N[1] })\n .map(function(_) { return _[0] });\n\nprint(r.length + '\\n' + r.join(' '));"}, {"source_code": "var N = readline().split(' ').map(Number);\n\nvar r = [];\nfor(var i = 0; i < N[0]; ++i) {\n r.push([i + 1, readline().split(' ').map(Number).slice(1).sort(function(a,b){return a-b})[0]]);\n}\n\nr = r.filter(function(_) { return _[1] < N[1] });\n\nprint(r.length);\nprint(r.map(function(_) { return _[0] }).join(' '));"}, {"source_code": "var tokenizer;\nvar index = 0;\n\nfunction next(){\n while(tokenizer == null || index == tokenizer.length){\n tokenizer = readline().split(\" \");\n index = 0;\n }\n var res = tokenizer[index++];\n return res;\n}\n\nfunction nextInt(){\n return parseInt(next());\n}\n\nfunction nextFloat(){\n return parseFloat(next());\n}\n\nfunction solve(){\n var n = nextInt();\n var v = nextInt();\n var res = 0;\n var s = \"\";\n for(var i = 0; i < n; ++i){\n var k = nextInt();\n var flag = false;\n for(var j = 0; j < k; ++j){\n var cur = nextInt();\n if(cur < v) flag = true;\n }\n if(flag){\n ++res;\n s += ((i+1) + \" \");\n }\n \n }\n print(res);\n print(s);\n}\nsolve();"}, {"source_code": "var A = [];\nvar solution = [];\nvar line = readline();\nvar n = line.split(' ')[0];\nvar v = line.split(' ')[1];\n\nfor(var i =0; i < n; i++){\n A.push(readline().split(' '));\n for(var j = 1; j <= A[i][0]; j++){\n if(parseInt(A[i][j]) < parseInt(v)){\n solution.push(i+1);\n break;\n }\n }\n}\n\nprint(solution.length);\nprint(solution.join(' '));"}, {"source_code": "var n=readline().split(' ').map(Number);\nvar ss = ((xs)=>{for (var i=0;ia-b).shift(),i+1]);} return xs;})([]);\nvar ps=ss.filter((x)=>n[1]>x[0]);\nprint(ps.length);\nif (ps.length!==0) print(ps.map((xs)=>xs[1].toString()).join(' '));"}, {"source_code": "var line = readline().split(' ').map(Number);\nvar sellers = [];\nvar res = \"\";\nvar sellersNum = 0;\nfor (var k = 0; k0) {\n print(sellers.join(\" \"));\n}"}], "negative_code": [{"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers);\n}"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers.join(\" \"));\n}"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers);\n}\n\n\n"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers);\n}"}, {"source_code": "var lines=readline().split(\" \");\n\nprint(lines);"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers);\n}"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers.join(\" \"));\n}"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers.join(\" \"));\n}"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=parseInt(lines[1]);\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers.join(\" \"));\n}"}, {"source_code": "function main(n,v,arr){\n\n\n var ans = [];\n var index = 0;\n var ansstr = \"\";\n\n for(var i = 0 ; i < n ; i++ ){\n for(var j = 1; j < arr[i].length ; j++){\n if(v > parseInt(arr[i][j])){\n ans[index] = parseInt(arr[i][0]);\n index++;\n break;\n }\n }\n }\n if(ans.length === 0){\n print(\"0\")\n return;\n };\n print(ans.length);\n for(var i = 0 ; i parseInt(arr[i][j])){\n ans[index] = parseInt(arr[i][0]);\n index++;\n break;\n }\n }\n }\n if(ans.length === 0){\n print(\"0\")\n return;\n };\n print(ans.length);\n ans.sort();\n for(var i = 0 ; i parseInt(line[j])) {\n minValue = parseInt(line[j]);\n }\n }\n if(minValue < v) {\n if(ret.length !== 0) ret += ' ';\n ret += (i + 1);\n }\n}\nprint(ret.length);\nprint(ret);\n"}, {"source_code": "var lines=readline().split(\" \");//reads the first line of the input\n\nvar noOfSellers=lines[0];\nvar Amount=lines[1];\n\nvar sellersAmount;\nvar sellers=[];\n\nfor (var i=0;i0) {\n print(sellers);\n}"}], "src_uid": "7804152ee14264afef019c5ad33094f9"} {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', (answer) => {\n const argumentArray = answer.split(' ');\n const index = argumentArray[0];\n\n const outputArray = new Array();\n \n for (i = 0; i < (2 * index); i++) {\n if (i == (2 * index - 1)) {\n outputArray.push('it');\n } else {\n switch (i % 4) {\n case 0:\n outputArray.push('I hate')\n break;\n case 1:\n outputArray.push('that');\n break;\n case 2:\n outputArray.push('I love');\n break;\n case 3:\n outputArray.push('that');\n break;\n default:\n break;\n }\n }\n }\n\n console.log(outputArray.join(' '));\n\n rl.close();\n});", "positive_code": [{"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet even = 'I hate';\nlet odd = 'I love';\n\nrl.on('line', (d) => {\n\n let ans = even;\n\n for (let i = 1; i < +d; i++) {\n ans += ' that ';\n if (i % 2 === 0) {\n ans += even;\n }\n else {\n ans += odd;\n }\n }\n\n ans += ' it';\n\n console.log(ans);\n});\n"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n console.log(hulk(line))\n})\n\nfunction hulk(times) {\n if (times === 1) return 'I hate it'\n let output = 'I hate'\n const len = times - 1\n for (let i=0; i{\n let data_found = data.split(\" \");\n x = parseInt(data_found[0]);\n \n\n let count = 1;\n let feeling = ''\n for(var i = 1; i<= x; i++)\n {\n if(i === x && i % 2 === 0)\n {\n \n feeling += 'I love it';\n }\n else if(i === x && i % 2 != 0)\n {\n feeling += 'I hate it';\n }\n else if(i % 2 === 0)\n {\n \n feeling += 'I love that ';\n }\n else if(i % 2 != 0)\n {\n feeling += 'I hate that ';\n }\n \n }\n\n console.log(feeling);\n \n})\n\n\n\n\n"}, {"source_code": "var x= readline();\nstr = \"I hate\"\nfor (i=1 ;i0?\" that I love\":\" that I hate\"\n}\nprint(str,\"it\")"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n // if(Array.isArray(inputString)) inputString = inputString.join('\\n');\n inputString += inputStdin;\n // inputString = inputString.trim().split('\\n').map(string => {\n // return string.trim();\n // });\n \n // main(); \n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let n = readAsInt();\n console.log([...Array(n)].map((v,i) => i % 2 === 0 ? 'I hate' : 'I love' ).join(' that ')+' it');\n}\n \n\n\n"}, {"source_code": "function main(){\n\t\tvar numbers = readline().split(\" \").map(function(x) { return parseInt(x); });\n\t\t// numbers = [5,3];\n\t\tvar a = numbers[0];\n\t\tvar flag = true;\n\t\tvar res = '';\n\t\tfor(var i = 0; i < a; i ++){\n\t\t\tif(flag){\n\t\t\t\tres += 'I hate ';\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tres += 'I love ';\n\t\t\t\tflag = true;\n\t\t\t}\n\t\t\tif(i < a - 1){\n\t\t\t\tres += 'that ';\n\t\t\t}\n\t\t\telse{\n\t\t\t\tres += 'it';\n\t\t\t}\n\t\t}\n\t\tprint(res);\n\t\t// console.log(res);\n\t}\nmain();"}, {"source_code": "var inp, f=0, i=1;\n\ninp = readline();\n\nn = parseInt(inp);\n\ns = \"I hate\";\n\nwhile(i data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i + 0] * 1);\n\n}\n\nfunction doit(num) {\n console.log(new Array(num).fill(0).map((data, index) => {\n if (index + 1 == num) {\n if ((index + 1) % 2 === 0) {\n return \"I love it\";\n } else {\n return \"I hate it\";\n }\n } else {\n if ((index + 1) % 2 === 0) {\n return \"I love that\";\n } else {\n return \"I hate that\";\n }\n }\n }).join(\" \"));\n\n}"}, {"source_code": "var input = readline();\n if(input<1 || input>100) \n print(\"Outside range.\")\n else {\n var s = \"\";\n for(var i=1;i<=input;i++) {\n if(i%2==0)\n s+=\"I love\";\n else\n s+=\"I hate\";\n \n if(i==input)\n s+= \" it\";\n else\n s+= \" that \";\n }\n print(s);\n }\n \n \n "}, {"source_code": "var arg = Number.parseInt(readline());\n\nvar result = '';\nfor (var i = 1; i <= arg; i++) {\n result += i % 2 ? 'I hate ' : 'I love ';\n result += i === arg ? 'it' : 'that ';\n}\n\nprint(result);"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(i%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love it\";\n}else{\n output += \"I hate it\";\n}\nprint(output);"}, {"source_code": "var res = sol(readline());\nprint(res);\n\nfunction sol(line) {\n var input = line.split(\" \");\n\n var n = input[0];\n var feeling = \"\";\n\n for (var i = 1; i <= n; i++) {\n feeling = feeling.replace(\"it\", \"that \");\n\n if(i % 2 == 0){\n feeling += \"I love it\";\n }else{\n feeling += \"I hate it\";\n }\n }\n\n return feeling;\n}"}, {"source_code": "var n = Number(readline());\n\n\nvar res = [];\nfor(var i = 1; i < n; i++) {\n if (i%2==1)\n res.push('I hate that');\n else \n res.push('I love that');\n}\nif (n%2==1) {\n res.push('I hate it');\n}\nelse {\n res.push('I love it');\n}\nprint(res.join(\" \"));"}, {"source_code": "var n=readline()\nvar a1=\"I \",a2=\"that \",a3=\"love \",a4=\"hate \",res=\"\"\nfor(var i=0;i parseInt(x);\nvar feelings = ['I hate', 'I love'];\nvar toFeelings = (x, i) => (feelings[i%2]);\n\nprint(`${\n new Array(parseInt(readline())).fill('')\n .map(toFeelings).join(' that ')\n} it`);"}, {"source_code": "var a = \"I \", b = \"it\", c = \"that \", g = \"\";\nvar f = readline();\n\nwhile (f > 0) {\n if (g) g += c + a;\n if (f) {\n g += \"hate \";\n\tf--;\n }\n if (f) g += c + a;\n if (f) {\n g += \"love \";\n\tf--;\n }\n}\n\nprint(a + g + b);"}, {"source_code": "var n = parseInt(readline());\nvar feeling = [];\n\nfor(i = 1; i <= n; i++) {\n \n feeling.push(\"I \");\n \n if((i % 2) === 1) {\n feeling.push(\"hate \");\n } else {\n feeling.push(\"love \");\n }\n \n if(i === n) {\n feeling.push(\"it\");\n } else {\n feeling.push(\"that \");\n }\n}\n\nprint(feeling.join(\"\"));"}, {"source_code": "var n = parseInt(readline());\nvar feeling = \"\";\n\nfor(i = 1; i <= n; i++) {\n \n feeling += \"I \";\n \n if((i % 2) === 1) {\n feeling += \"hate \";\n } else {\n feeling += \"love \";\n }\n \n if(i === n) {\n feeling += \"it\";\n } else {\n feeling += \"that \"\n }\n}\n\nprint(feeling);"}, {"source_code": "var n = parseInt(readline())\nvar output = []\nfor (var i = 0; i < n; i++) {\n output.push(\"I \" + (i % 2 == 0 ? 'hate' : 'love'))\n}\nprint(output.join(' that ') + ' it')"}, {"source_code": "x=Number(readline())\nfunction f(x,b) {\n return x==1 ? (['I hate it', 'I love it'])[Number(b)] : \n (b ? `I love that ${f(x-1,!b)}` : `I hate that ${f(x-1,!b)}` )\n}\n\nprint(f(x,false))\n\n"}, {"source_code": "var f = (x,b) =>\n ['I hate ', 'I love '][Number(b)] + ['that ', 'it'][Number(x==1)] + (x==1 ? '' : f(x-1,!b))\nprint(f(Number(readline()),false))\n\n"}, {"source_code": "var f = (x,b) => \n x==1 ? (['I hate it', 'I love it'])[Number(b)] : \n ['I hate that ', 'I love that '][Number(b)] + f(x-1,!b)\n\nprint(f(Number(readline()),false))\n\n"}, {"source_code": "'use strict';\n\nString.prototype.getNumber = function() {\n return String(this).split(' ').map(function (value) {\n return parseInt(value);\n })[0];\n}\n\nlet maxLevel = readline().getNumber(),\n currentLevel = 1,\n phraseArr = ['I hate'];\n\nlet getLevelPhrase = (level) => {\n if(level % 2 === 0) {\n return 'that I love';\n } \n\n return 'that I hate';\n}\n\nwhile(currentLevel < maxLevel) {\n currentLevel++;\n phraseArr.push(getLevelPhrase(currentLevel));\n}\n\nphraseArr.push('it');\n\nwrite(phraseArr.join(' '));"}, {"source_code": "//JavaScript-C24.2.0 (SpiderMonkey)\n\nvar numbers = readline();\nvar a = numbers;\nvar number = []\nvar e='I hate that';\nvar b ='I love that';\n\nvar c= [];\n\nfor(var i=0; i 0) {\n string += (\"I \" + (hate ? \"hate\" : \"love\") + (n > 1 ? \" that \" : \" it\"));\n n--;\n hate = !hate;\n}\n\nprint(string);"}, {"source_code": "(function() {\n 'use strict';\n const n = readline();\n var x = 'I hate ';\n var y = 'I love ';\n var z;\n for (let i = 0; i < n; i++) {\n if (i === 0) {\n z = x;\n } else if (i % 2 === 0) {\n z += 'that ' + x;\n } else {\n z = z + 'that ' + y;\n }\n }\n \n print(z + 'it');\n}());"}, {"source_code": "var t = Number(readline().split(\" \")[0]);\nvar str = \"\";\nfor (var n=0;n 100) return 'Invalid entry!';\n\tvar block = 'I hate that I love that ';\n\tvar tail = n % 2? 'I hate it': 'I hate that I love it';\n\tif (n < 3) return tail;\n\treturn block.repeat(Math.floor((n-1)/2)) + tail;\n}\n\nvar n = readline();\nprint(expression(n));\n"}, {"source_code": "var n = +readline();\n\nfor (var i = 1; i <= n; i++) {\n if (i > 1) {\n write(\" that \");\n }\n if (i % 2 == 1) {\n write(\"I hate\")\n } else {\n write(\"I love\");\n }\n}\nprint(\" it\");"}, {"source_code": "var n = readline();\nvar feels = \"\";\n\nfor (var i=1; i<=n; i++)\n feels += ((i != 1) ? \"that \" : \"\") + ((i % 2 == 0) ? \"I love \" : \"I hate \");\n\nprint(feels+\"it\");\n"}, {"source_code": "var data = readline();\nvar n = data.split(\" \").map(Number);\ndata = \"\";\nvar loveOrHate = \" I hate that\";\nfor(i=1;i<=n-1;i++) {\n data += loveOrHate;\n if( loveOrHate === \" I love that\"){\n loveOrHate = \" I hate that\";\n }else{\n loveOrHate = \" I love that\"\n }\n\n}\n\nif((n % 2) !== 0 ) {\n data+= \" I hate it\";\n}else{\n data+= \" I love it\"; \n}\n\nprint(data);"}, {"source_code": "var n = readline();\nvar m = \"I hate\";\nvar b = false;\nwhile(n != 1)\n{\n\tif(b == false)\n\t{\n\t\tm += \" that I love\";\n\t\tb = true;\n\t}\n\telse\n\t{\n\t\tm += \" that I hate\";\n\t\tb = false;\n\t}\n\tn--\n}\nm += \" it\";\nprint(m);"}, {"source_code": "var n = readline();\nvar string = \"\";\nfor (var i = 1; i <= n; i++) {\n if (i % 2 === 0) {\n string += \"I love that \";\n } else {\n string += \"I hate that \";\n }\n}\nprint(string.substring(0, string.length - 5) + \"it\");"}, {"source_code": "var x = readline();\nstr = \"I hate\";\nfor( i = 1 ; i0?\" that I love\":\" that I hate\";\nprint(str,\"it\");\n"}, {"source_code": "var n = parseInt(readline(), 10);\nvar expression = '';\n\nfor(var i=1; i<=n; i++) {\n if(i%2 === 0) expression += 'I love ';\n else expression += 'I hate ';\n \n if(i === n) expression += 'it';\n else expression += 'that ';\n}\n\nprint(expression);"}, {"source_code": "'use strict';\n\n/*let input = `\n1\n`.trim().split('\\n');\nfunction readline() {\n\treturn input.shift();\n}\nfunction print(message) {\n\tconsole.log(message);\n}*/\n\n\n//code\nvar n = Number(readline());\nn--;\nvar message = [], i = 0;\nwhile(i < n){\n\tmessage.push((i%2 === 0) ? \"that I love\" : \"that I hate\");\n\ti++;\n}\nmessage.push(\"it\");\nmessage.unshift(\"hate\");\nmessage.unshift(\"I\");\nprint(message.join(\" \"));"}, {"source_code": "var a = +readline(), b = 'I hate ';\n\nfor (var i = 2; i <= a; i++) {\n if (i % 2 == 0) b += 'that I love ';\n else b += 'that I hate ';\n}\n\nprint(b + 'it');"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nconst hulk = () => {\n let newString = 'I hate it';\n let bool = true;\n let count = 0;\n let phrase = 'I hate it';\n let phrase2 = 'I love it';\n for (let i = 0; i < +input[0]-1; i++){\n count++;\n if (count % 2 === 0){\n bool = true;\n }\n else {\n bool = false;\n }\n\n if (bool === true) {\n newString += ' ' +`${phrase}`;\n }\n else {\n newString += ' ' + `${phrase2}`;\n }\n }\n let newNewString = newString.replace(/it I/g, 'that I');\n console.log(newNewString);\n};\nreadLine.on('close', hulk);"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nrl.on('line', (input) => {\n var h = \"I hate\";\n var l = \"I love\";\n var ii = parseInt(input)+1;\n var i = 1;\n var out = \"\";\n while (i < ii) {\n if (i % 2 == 0) {\n out += l;\n } else {\n out += h;\n }\n if((ii-1) !== i) {\n out += \" that \";\n } else {\n out += \" it\";\n }\n i++;\n }\n console.log(out);\n});\n"}, {"source_code": "const stdin = process.openStdin();\nlet content = ``;\nstdin.addListener('data', d => {\n content += d.toString();\n});\n\nstdin.addListener('end', () => {\n console.log(solution(parseInt(content)));\n});\n\n// End of interface\n\nconst solution = function(n){\n let resStr = 'I hate';\n for (let i = 1; i < n; i++){\n if (i % 2 === 0){\n resStr = resStr + ' that I hate';\n } else {\n resStr = resStr + ' that I love';\n };\n };\n resStr = resStr + ' it';\n return resStr;\n};"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nlet input = []\n\nrl.on('line', line => {\n input = line.split(' ').map(x => parseInt(x))\n const output = solution(input[0])\n console.log(output)\n})\n\nrl.on('close', () => {\n // console.log(input)\n})\n\n// End of interface\n\n\nconst solution = function(n){\n let firstString = 'I hate it';\n let resArray = firstString.split(' ');\n for (let i = 1; i < n; i++){\n let last = resArray.pop();\n if (i % 2 === 0){\n resArray = resArray.concat(['that', 'I', 'hate'])\n } else {\n resArray = resArray.concat(['that', 'I', 'love'])\n };\n resArray.push(last);\n };\n\n return resArray.join(' ');\n};\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\n\nlet input = []\n\nrl.on('line', line => {\n input = line.split(' ').map(x => parseInt(x))\n const output = solution(input[0])\n console.log(output)\n})\n\nrl.on('close', () => {\n // console.log(input)\n})\n\n// End of interface\n\n\nconst solution = function(n){\n let resStr = 'I hate';\n for (let i = 1; i < n; i++){\n if (i % 2 === 0){\n resStr = resStr + ' that I hate';\n } else {\n resStr = resStr + ' that I love';\n };\n };\n resStr = resStr + ' it';\n return resStr;\n};"}, {"source_code": " var a = \"I hate it\";\n var b = \"I hate that\";\n var c = \"I love it\";\n var d = \"I love that\";\n var n; \n var even = 0;\n var odd = 0;\n var i = 0;\n var out= \" \";\n \n process.stdin.on('data',k=>{\n \tn = Number(k);\n \tif (n%2 == 0)\n \t{\n \t\teven = (n-2)/2;\n \t\tfor ( i = 0; i < even; ++i)\n \t\t{\n \t\t\tout += (b + \" \" + d + \" \");\n \t\t}\n \t\tout += (b + \" \" + c + \" \");\n \t\tconsole.log(out);\n \t\t\n \t}\n \telse\n \t{\n \t\todd = (n-1)/2;\n \t\tfor (i = 0; i < odd; ++i)\n \t\t{\n \t\t\tout += (b + \" \" + d + \" \");\n \t\t}\n \t\tout += (a + \" \");\n \t\tconsole.log(out);\n \t\t\n \t}\n\n\n }\n )"}, {"source_code": "let lines = [];\nrequire('readline').createInterface({input: process.stdin,output: process.stdout})\n\t\t\t\t.on('line', line => {lines.push(line);})\n\t\t\t\t.on('close', () => {main(lines)});\n\nconst main = (input) => {\n\tvar ret = \"\";\n\tfor (var i = 1; i <= input; i++) {\n\t\tif (i % 2 == 1) {\n\t\t\tret += \"I hate \";\n\t\t} else {\n\t\t\tret += \"I love \";\n\t\t}\n\t\tif (i == input) {\n\t\t\tret += \"it \";\n\t\t} else {\n\t\t\tret += \"that \";\n\t\t}\n\t}\n\tconsole.log(ret);\n}\n"}, {"source_code": "const readline = require('readline')\n\nasync function algo() {\n const n = await int()\n let expression = ''\n for(let i = 1; i < n; i++) {\n expression += `I ${i % 2 == 0 ? 'love' : 'hate'} that `\n }\n expression += `I ${n % 2 == 0 ? 'love' : 'hate'} it`\n console.log(expression)\n}\n\n\n// read the input\nconst _lines = []\nlet _lineIndex = 0\nlet _ended = false\nconst _rl = readline.createInterface(process.stdin)\n_rl.on('line', line => _lines.push(line))\n_rl.on('end', () => (ended = true))\nconst wait = ms => new Promise(resolve => setTimeout(resolve, ms))\nconst line = async () => {\n while (!_ended && _lines.length <= _lineIndex) await wait(10)\n const result = _lines[_lineIndex].trim()\n _lines[_lineIndex] = null\n _lineIndex++\n return result\n}\nconst words = async () => (await line()).split(' ')\nconst chars = async () => (await line()).split('')\nconst int = async () => parseInt(await line())\nconst ints = async () => (await words()).map(x => parseInt(x))\nconst big = async () => BigInt(await line())\nconst bigs = async () => (await words()).map(x => BigInt(x))\n\nalgo()"}, {"source_code": "let readline = require('readline');\nlet intInput = readline.createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout\n});\nlet input, str;\nintInput.on('line', (line) => {\n\tinput = line\n});\nintInput.on('close', () => {\n\tstr = 'I hate'\n\tfor (let i = 2; i <= input; i++) {\n\t\tstr = str + ' that '\n\t\tif (i % 2 == 0){\n\t\t\tstr = str + 'I love'\n\t\t} else {\n\t\t\tstr = str + 'I hate'\n\t\t}\n\t}\n\tlet res = str + ' it'\n\tconsole.log(res)\n})"}, {"source_code": "function main() {\n // write code here:\n var hate = 'that I hate ',\n love = 'that I love ',\n str = \"I hate \",\n num = Number(stdin[0]);\n for (var i = 2; i <= num; i++) {\n if (i === 1) break;\n if (i % 2 !== 0) {\n str += hate;\n } else {\n str += love;\n }\n }\n str += \"it\";\n console.log(str);\n}\n\nconst readline = require('readline');\nconst rl = readline.createInterface({input: process.stdin});\nvar stdin = [];\nrl.on('line', function (line) {\n stdin.push(line);\n});\nrl.on('close', main);\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n \nconst input = [];\nreadLine.on('line', line => input.push(line));\n \nreadLine.on('close', () => {\n const count = parseInt(input[0], 10)\n let result = ''\n for (let i = 0; i < count; i++) {\n const selector = (i % 2) === 0 ? 'I hate' : 'I love'\n const delimiter = (i + 1) < count ? ' that ' : ' it'\n result += selector+delimiter\n }\n console.log(result)\n});"}, {"source_code": "// prettier-ignore\n// eslint-disable-next-line\n(() => { const { stdin } = process; function* inputSeq(stream) { let inp = String(stream.read()); inp = inp[inp.length - 1] === '\\r' ? inp.slice(0, -1) : inp; const lines = inp.split('\\n'); for (let l of lines) yield l; return null; } function getReadline(stream) { const seq = inputSeq(stream); return () => seq.next().value; } stdin.once('readable', () => sol(getReadline(stdin), console.log.bind(console)) ); })();\n\nconst sol = (read, print) => {\n const n = parseInt(read(), 10);\n const em = [];\n for (let i = 1; i <= n; i += 1) em.push(i % 2 ? 'I hate' : 'I love');\n print(`${em.join(' that ')} it`);\n};\n"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + (end) + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var output = \"\";\n for(var i = 0; i < N; i++){\n if(i % 2 == 0){\n output += \"I hate\";\n }else{\n output += \"I love\";\n }\n if(i != N - 1){\n output += \" that \";\n }else{\n output += \" it\";\n }\n }\n myout(output);\n}\n"}], "negative_code": [{"source_code": "var n = parseInt(readline());\n \nfunction uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n \n else{\n impar=\"I love\";\n }\n return impar;\n}\n \nfunction dos(n){\n var medio=\"\";\n if (i 2) output += \" that\";\n else output += \"it\";\n}else{\n output += \"I hate\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}\nprint(output);"}, {"source_code": "\n\tvar a = readline();\n\tvar h = \"I hate \";\n\tfor(i = 2; i <= a; i++){\n\t\tif(a % 2 === 0)\n\t\t\th = h + \"I love \";\n\t\telse \n\t\t\th = h + \"I hate \";\n\t}\nprint(h + \"it\");\n\t\n\t\n\t\n"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst halk = () => {\n let newString = '';\n let bool = true;\n let count = 1;\n let phrase = 'I hate it';\n let phrase2 = 'I love it';\n for (let i = 0; i < +input[0]; i++){\n count++;\n if (count % 2 === 0){\n bool = true;\n }\n else {\n bool = false;\n }\n\n if (bool === true) {\n newString += ' ' +`${phrase}`;\n }\n else {\n newString += ' ' + `${phrase2}`;\n }\n }\n let newNewString = newString.replace('it I', 'that I');\n console.log(newNewString);\n};\nreadLine.on('close', halk);"}, {"source_code": " var n = parseInt(readline());\n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n else{\n impar=\"I love\";\n }\n return impar;\n }\n for (var i=1;i<=n;i++){\n var imprime;\n var medio;\n var yo=[];\n if (i 0) {\n print(\"I \" + (hate ? \"hate\" : \"love\") + (n > 1 ? \" that \" : \" it\"));\n n--;\n}"}, {"source_code": " var n = parseInt(readline());\n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n else{\n impar=\"I love\";\n }\n return impar;\n }\n for (var i=1;i<=n;i++){\n var imprime;\n var medio;\n var yo=[];\n if (i=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n var h = \"I hate that\";\n var l = \"I love it\";\n var ii = Number(input)+1;\n var i = 1;\n var out = \"\";\n while (i < ii) {\n if (i % 2 == 0) {\n out += l;\n } else {\n out += h;\n }\n if((ii-1) !== i)\n out += \" \";\n i++;\n }\n print(out);\n return 0;\n}\n\n"}, {"source_code": "var string=\"I hate it\";\n// var layer=prompt(); \nvar layer=readline(); \nfor(var i=2;i<=layer;i {\n let temp = obj.toString().trim().split('\\n')[0];\n process.stdout.write(answers[Number(temp)]);\n});"}, {"source_code": "const readLine = require('readline').createInterface({\n\tinput: process.stdin,\n\toutput: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\n\nreadLine.on('close', () => {\n// CODE HERE\n\tlet n = +input[0];\n\tlet array = [];\n\tlet a = 'i hate';\n\tlet b = 'i love';\n\t\n\tfor (let i = 0; i < n; i++){\n\t\tif (i%2 == 0){\n\t\t\tarray.push(a);\n\t\t}else{\n\t\t\tarray.push(b);\n\t\t}\n\n\t}\n\tconsole.log (array.join(' that ') + ' it');\n});"}, {"source_code": "var n = readline();\nvar string = \"\";\nfor (var i = 1; i <= n; i++) {\n if (i % 2 === 0) {\n string += \"I love it \";\n } else {\n string += \"I hate that \";\n }\n}\nif (n != 1) {\n print(string.substring(0, string.length - 1));\n} else {\n print(string);\n}"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(i%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love\";\n if(input > 1) output += \" that\";\n else output += \" it\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" that\";\n else output += \" it\";\n}\nprint(output);"}, {"source_code": " var n = parseInt(readline());\n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n else{\n impar=\"I love\";\n }\n return impar;\n }\n for (var i=1;i<=n;i++){\n var imprime;\n var medio;\n var yo=[];\n if (i 1) output += \" that\";\n else output += \" it\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" that\";\n else output += \" it\";\n}\nprint(output);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nrl.question('', (answer) => {\n const argumentArray = answer.split(' ');\n const index = argumentArray[0];\n\n const outputArray = new Array(parseInt(index));\n if(index == 2) {\n outputArray.push('I hate that I love it');\n } else {\n outputArray.fill('I hate that I love that', 0, parseInt(index / 2));\n }\n if(index % 2 != 0) {\n outputArray.push('I hate it');\n }\n\n console.log(outputArray.join(' '));\n\n rl.close();\n});"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(i%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love\";\n if(input > 1) output += \" it\";\n else output += \" that\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" it\";\n else output += \" that\";\n}\nprint(output);"}, {"source_code": "var n = readline();\n\t\twhile(n>0){\n\t\t\tprint(\"I hate \");\n\t\t\tn--;\n\t\t\tif(n>0){\n\t\t\tprint(\"that \");\n\t\t\tprint(\"I love \");\n\t\t\tn--;\n\t\t}\n\t\t\tif (n>0) {\n\t\t\tprint(\"that \");\n\n\t\t\t}\n\n\t\t}\n\t\tprint(\"it\");"}, {"source_code": "var n = parseInt(readline());\nvar hate = true;\nvar string = \"\";\n\nwhile(n > 0) {\n string += (\"I \" + (hate ? \"hate\" : \"love\") + (n > 1 ? \" that \" : \" it\"));\n n--;\n}\n\nprint(string);"}, {"source_code": "\n\tvar a = readline();\n\tvar h = \"I hate \";\n\tfor(i = 2; i <= a; i++){\n\t\tif(a % 2 === 0)\n\t\t\th = h + \"I love \";\n\t\telse \n\t\t\th = h + \"I hate \";\n\t}\nprint(h + \"it\");\n\t\n\t\n\t\n"}, {"source_code": "var n = parseInt(readline());\n \nfunction uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=print(\"I hate\");\n }\n \n else{\n impar=print (\"I love\");\n }\n}\n\nfunction dos(n){\n var medio=\"\";\n if (i 1) output += \" it\";\n else output += \" that\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" it\";\n else output += \" that\";\n}\nprint(output);"}, {"source_code": "var n=readline()\nvar a1=\"I \",a2=\"that \",a3=\"love \",a4=\"hate \",res=\"\"\nfor(var i=0;i 0) {\n if (n % 2 !== 0) {\n if (n > 1) {\n str.concat(that);\n }\n str.concat(odd);\n } else if (n % 2 === 0) {\n str.concat(that);\n str.concat(even);\n }\n str.concat(end);\n }\n\n console.log(str);\n});\n"}, {"source_code": "var n = parseInt(readline());\n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n else{\n impar=\"I love\";\n }\n return impar;\n }\n for (var i=1;i<=n;i++){\n var imprime;\n var medio;\n if (i {\n console.log(hulk(line))\n})\n\nfunction hulk(times) {\n if (times === 1) return 'I hate it'\n const HATE = ' that I hate'\n const LOVE = ' that I love'\n let output = 'I hate'\n const len = times - 1\n for (let i=0; i1 && i == hulkLvl ) {\n result += ' I love it ';\n }\n else if( i > 1 && i != hulkLvl ){\n result += ' I love that ';\n\n } else {\n result += ' I love it ';\n }\n \n } else {\n if( i >1 && i == hulkLvl ){\n result += 'I hate it';\n } else if( i > 1 && i != hulkLvl ) {\n result += 'I hate that';\n } else {\n result += 'I hate it';\n }\n }\n }\n\nprint(result);"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(i%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love\";\n if(input > 1) output += \" it\";\n else output += \" that\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" it\";\n else output += \" that\";\n}\nprint(output);"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(input%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love\";\n if(input > 2) output += \" that\";\n else output += \" it\";\n}else{\n output += \"I hate\";\n if(input > 2) output += \" that\";\n else output += \" it\";\n}\nprint(output);"}, {"source_code": "var n=readline();;\nvar str = \"\";\nfor (var i=0; i {\n\n let ans = even;\n\n for (let i = 1; i < +d; i++) {\n ans += ' that ';\n if (i % 2 === 0) {\n ans += even;\n }\n else {\n ans += odd;\n }\n }\n\n console.log(ans);\n});\n"}, {"source_code": "function feelingsOfHulk(layers) {\n let answer = '';\n for (let i = 0; i < layers; i++) {\n if (i == layers - 1) {\n if (i % 2 == 0) {\n answer += 'I hate it';\n }\n else {\n answer += 'I love it';\n }\n } else if (i % 2 == 0 && i != 0) {\n answer += ' I hate that ';\n } else if (i % 2 == 0 && i == 0) {\n answer += 'I hate that';\n }\n else {\n answer += ' I love that ';\n }\n }\n return answer;\n}\n\nfunction processData(input) {\n console.log(feelingsOfHulk(parseInt(input)));\n}\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"ascii\");\n_input = \"\";\nprocess.stdin.on(\"data\", function (input) {\n _input += input;\n});\n\nprocess.stdin.on(\"end\", function () {\n processData(_input);\n});"}, {"source_code": " var n = parseInt(readline());\n \n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n \n else{\n impar=\"I love\";\n }\n return impar;\n }\n \n function dos(n){\n var medio=\"\";\n if (i=n){\n medio =\"it\";\n }\n \n else{\n medio =\"that\";\n }\n return medio;\n }\n var imprime;\n var imprimo;\n for (var i=1; i<=n;i++){\n imprime= uno(i);\n imprimo= dos(i);\n print (imprime+\" \"+imprimo);\n \n }"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(i%2 === 0) output += \"I love that \";\n else output += \"I hate that \";\n i++;\n}\nif(input%2 === 0){\n output += \"I love\";\n if(input > 1) output += \" that\";\n else output += \" it\";\n}else{\n output += \"I hate\";\n if(input > 1) output += \" that\";\n else output += \" it\";\n}\nprint(output);"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n console.log(hulk(line))\n})\n\nfunction hulk(times) {\n if (times === 1) return 'I hate it'\n const HATE = ' that I hate'\n const LOVE = ' that I love'\n let output = 'I hate'\n const len = times - 1\n for (let i=0; i1 && i == hulkLvl ) {\n result += ' I love it ';\n }\n else if( i > 1 && i != hulkLvl ){\n result += ' I love that ';\n\n } else {\n result += ' I love it ';\n }\n \n } else {\n if( i >1 && i == hulkLvl ){\n result += 'I hate it';\n } else if( i > 1 && i != hulkLvl ) {\n result += 'I hate that';\n } else {\n result += 'I hate it';\n }\n }\n }\n\nprint(result);"}, {"source_code": "var n = readline();\n\nif(n == 1) {\n print(\"I hate it\"); \n} else if(n== 2) {\n print(\"I hate that I love it\") \n} else if(n == 3) {\n print(\"I hate that I love that I hate it\")\n}"}, {"source_code": "var levels = parseInt(readline());\nvar str = '';\nvar i = 1\nwhile (i < levels) {\n if (i % 2 === 1) str += 'I hate that ';\n else str += 'I love that ';\n i++;\n}\nif (levels % 2 === 1) str += 'I hate it';\nelse str += 'I love that';\nprint(str);\n"}, {"source_code": "const arr = [\n \"I hate it\",\n \"I hate it I love it\",\n \"I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it\",\n \"I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it I hate it I love it\"\n];\n\nconst input = process.openStdin();\ninput.addListener(\"data\", (obj) => {\n let temp = obj.toString().trim().split('\\n')\n process.stdout.write(arr[Number(temp) - 1]);\n});"}, {"source_code": "var data = readline();\nvar n = data.split(\" \").map(Number);\ndata = \"\";\nfor(i=n; i > 0; i-- ) {\n if(i == 1 ) {\n data += \"I hate it \";\n break;\n }\n if((i % 2) !== 0 ) {\n data += \"I hate that \"; \n }\n if((i % 2) === 0 ){\n data += \"I love that \"; \n }\n}\nprint(data);"}, {"source_code": "var n = readline().split(\"\").map(function(x){\n\t\treturn parseInt(x);\n\t});\n\n\tvar str = 'I hate it';\n\tvar str1 = 'I love it';\n\tvar temp = '';\n\tfor(var i = 1; i <= n-1; i++)\n\t{\n\t\tif(i % 2 == 1){\n\t\t\ttemp += 'I hate that ';\n\t\t}\n\t\telse {\n\t\t\ttemp += 'I love that ';\n\t\t}\n\t}\n\tif(n % 2 == 1){\n\t\tprint(temp+str);\n\t}\n\telse{\n\t\tprint(temp+str1);\n\t}"}, {"source_code": "var n = parseInt(readline());\n \n \nfor (var i=1; i<=n;i++){\n if(i%2!==0){\n var impar=print(\"I hate\");\n \n if(i%2===0){\n var par=print (\"I love\");\n \n if (i 2) output += \" that\";\n else output += \"it\";\n}else{\n output += \" I Hate\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}"}, {"source_code": "var n = parseInt(readline());\n \n \nfor (var i=1; i<=n;i++){\n if(i%2!==0){\n print(\"I hate it\");\n \n if(i%2===0 &&i!=1){\n print (\" I love it \");\n }}}\n \n"}, {"source_code": " var n = parseInt(readline());\n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n else{\n impar=\"I love\";\n }\n return impar;\n }\n var imprime;\n var medio;\n for (var i=1;i<=n;i++){\n \n if (i=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n var h = \"I hate that\";\n var l = \"I love it\";\n var ii = Number(input)+1;\n var i = 1;\n var out = \"\";\n while (i < ii) {\n if (i % 2 == 0) {\n out += l;\n } else {\n out += h;\n }\n if((ii-1) !== i)\n out += \" \";\n i++;\n }\n print(out);\n return 0;\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\nvar input= '', readline, print;\n\nprocess.stdin.on('data', function(chunk) {\n input+=chunk;\n});\n\nprocess.stdin.on('end', function() {\n input = input.split('\\n');\n print = function(data) {process.stdout.write(data+'\\n')};\n var inputLineIndex = 0;\n readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n var h = \"I hate that\";\n var l = \"I love it\";\n var ii = Number(input)+1;\n var i = 1;\n var out = \"\";\n while (i < ii) {\n if (i % 2 == 0) {\n out += l;\n } else {\n out += h;\n }\n if((ii-1) !== i)\n out += \" \";\n i++;\n }\n print(out);\n return 0;\n}\n\n"}, {"source_code": "var n = parseInt(readline());\n \nfunction pares(n){\n if(n%2===0){\n print (\" I love it \");\n }else if(n==1){\n print (\"I hate it\");\n }else {\n print (\" I hate it)\");\n }\n }\n\n \nfor (var i=1; i<=n;i++){\n var p= pares(i);\n print (p);\n \n}"}, {"source_code": "var s = readline().split(' ');\nvar r = \"I hate\";\n\nfor (var i = 2; i <= s; i++){\n if(i % 2 === 0)\n r =r + \"that I love\";\n else\n r = r + \"that I hate\";\n}\nprint(r + \" it\");"}, {"source_code": "var data = readline();\nvar n = data.split(\" \").map(Number);\ndata = \"\";\nfor(i=n; i > 0; i-- ) {\n if(i == 1 ) {\n data += \"I hate it \";\n break;\n }\n if((i % 2) !== 0 ) {\n data += \"I hate that \"; \n }\n if((i % 2) === 0 ){\n data += \"I love that \"; \n }\n}\nprint(data);"}, {"source_code": "var n = parseInt(readline());\n\nfunction pares(n){\n if(n%2===0){\n print (\"I love it \");\n }else{\n print (\"I hate it \");\n }\n}\n\nfor (var i=0; i 2) output += \" that\";\n else output += \"it\";\n}else{\n output += \" I Hate\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(input%2 === 0) output += \"I Love that\";\n else output += \"I Hate that\";\n}\nif(input%2 === 0){\n output += \" I Love\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}else{\n output += \" I Hate\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}"}, {"source_code": "\n\tvar a = readline();\n\tvar h = \"I hate \";\n\tfor(i = 2; i <= a; i++){\n\t\tif(a % 2 === 0)\n\t\t\th = h + \"that I love \";\n\t\telse \n\t\t\th = h + \"that I hate \";\n\t}\nprint(h + \"it\");\n\t\n\t\n\t\n"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({input: process.stdin, output:process.stdout});\n\nlet x = 0\nlet y = 0\n\nrl.question('',data=>{\n let data_found = data.split(\" \");\n x = parseInt(data_found[0]);\n \n\n let count = 1;\n let feeling = ''\n for(var i = 1; i<= x; i++)\n {\n if(i === x && i % 2 === 0)\n {\n \n feeling += 'i love it';\n }\n else if(i === x && i % 2 != 0)\n {\n feeling += 'i hate it';\n }\n else if(i % 2 === 0)\n {\n \n feeling += 'i love that ';\n }\n else if(i % 2 != 0)\n {\n feeling += 'i hate that ';\n }\n \n }\n\n console.log(feeling);\n \n})\n\n\n\n\n"}, {"source_code": "var n = parseInt(readline());\nvar hate = true;\nvar string = \"\";\n\nwhile(n > 0) {\n string += (\"I \" + (hate ? \"hate\" : \"love\") + (n > 1 ? \" that \" : \" it\"));\n n--;\n hate = !hate;\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf8');\n\n// * STANDARD INPUT IS STORED IN A STRING\nvar arr = '';\n\nprocess.stdin.on('data', function (chunk) {\n arr += chunk;\n});\n\nprocess.stdin.on('end', function () {\n // * CONVERTING THAT INPUT INTO AN ARRAY\n arr = arr.split('\\n');\n // * EXTRACTING THE NUMBER OF TESTCASES\n var n = parseInt(arr.shift());\n\n let str = '';\n let odd = 'I hate';\n let even = 'I love';\n let that = ' that ';\n let end = ' it';\n\n while (n-- > 0) {\n if (n % 2 !== 0) {\n if (n > 1) {\n str.concat(that);\n }\n str.concat(odd);\n } else if (n % 2 === 0) {\n str.concat(that);\n str.concat(even);\n }\n str.concat(end);\n }\n\n console.log(str);\n});\n"}, {"source_code": "var t = Number(readline().split(\" \")[0]);\nvar str = \"\";\nfor (var n=0;n=input.length?undefined:input[inputLineIndex++]};\n process.exit(main() || 0);\n});\n\nfunction main()\n{\n var h = \"I hate that\";\n var l = \"I love it\";\n var ii = Number(input)+1;\n var i = 1;\n var out = \"\";\n while (i < ii) {\n if (i % 2 == 0) {\n out += l;\n } else {\n out += h;\n }\n if((ii-1) !== i)\n out += \" \";\n i++;\n }\n print(out);\n return 0;\n}\n\n"}, {"source_code": "let fs = require(\"fs\");\n\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => data.length > 0);\n\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i + 0] * 1);\n\n}\n\nfunction doit(num) {\n console.log(new Array(num).fill(0).map((data, index) => {\n if ((index + 1) % 2 === 0) {\n return \"I love it\";\n } else {\n return \"I hate it\";\n }\n }).join(\" \"));\n\n}"}, {"source_code": "\n\tvar a = readline();\n\tvar h = \"I hate \";\n\tfor(i = 2; i <= a; i++){\n\t\tif(a % 2 === 0)\n\t\t\th = h + \"that I love \";\n\t\telse \n\t\t\th = h + \"that I hate \";\n\t}\nprint(h + \"it\");\n\t\n\t\n\t\n"}, {"source_code": "var input='';\n\nprocess.stdin.on('data',givenInput=>{\n input+=givenInput;\n});\n\nprocess.stdin.on('end',()=>{\n main(input);\n});\n\nconst main=(input)=>{\n let n=Number(input.split(' ')[0]);\n let start='I hate';\n let even=' that i love';\n let odd=' that i hate';\n let end =' it';\n \n if(n===1){\n console.log(start+end);\n }\n \n else{\n \n for(let i=2;i<=n;i++){\n if(i%2===0){\n start+=even;\n }\n else{\n start+=odd;\n }\n }\n \n start+=end;\n \n console.log(start);\n }\n};"}, {"source_code": "var string=\"I hate it\";\n// var layer=prompt(); \nvar layer=readline(); \nfor(var i=2;i<=layer;i 0) {\n s += ' that I ' + (hate? 'hate': 'love');\n hate = !hate;\n };\n s += ' it';\n return s;\n // console.log(line, a, b);\n // return Math.ceil(Math.log2(b / a) / Math.log2(3 / 2));\n}\n\n\nconst rl = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet i = 1;\nrl.on('line', (line) => {\n if (i++) {\n console.log(solve(line))\n rl.close();\n }\n});"}, {"source_code": "var n = parseInt(readline());\n \n \nfor (var i=1; i<=n;i++){\n if(i%2!==0){\n var impar=print(\"I hate\");\n \n if(i%2===0){\n var par=print (\"I love\");\n \n if (i 0) {\n print(\"I \" + (hate ? \"hate\" : \"love\") + (n > 1 ? \" that \" : \" it\"));\n n--;\n}"}, {"source_code": " var numbers = readline();\n\n var hulkLvl = 3;\n\n var result = '';\n\n for(var i = 1; i <= hulkLvl; i++){\n if( i % 2 === 0 ) {\n result += ' I love it ';\n } else {\n result += 'I hate it';\n }\n }\n\nprint(numbers);"}, {"source_code": "const readline = require('readline');\n\nconst rl = readline.createInterface({input: process.stdin, output:process.stdout});\n\nlet x = 0\nlet y = 0\n\nrl.question('',data=>{\n let data_found = data.split(\" \");\n x = parseInt(data_found[0]);\n \n\n let count = 1;\n let feeling = ''\n for(var i = 1; i<= x; i++)\n {\n if(i === x && i % 2 === 0)\n {\n \n feeling += 'i love it';\n }\n else if(i === x && i % 2 != 0)\n {\n feeling += 'i hate it';\n }\n else if(i % 2 === 0)\n {\n \n feeling += 'i love that ';\n }\n else if(i % 2 != 0)\n {\n feeling += 'i hate that ';\n }\n \n }\n\n console.log(feeling);\n \n})\n\n\n\n\n"}, {"source_code": "const readline = require('readline')\n\nconst RL = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n})\n\nRL.on('line', line => {\n console.log(hulk(line))\n})\n\nfunction hulk(times) {\n if (times === 1) return 'I hate it'\n const HATE = ' that I hate'\n const LOVE = ' that I love'\n let output = 'I hate'\n const len = times - 1\n for (let i=0; i input.push(line));\n\nreadLine.on('close', () => {\n// CODE HERE\n\tlet n = +input[0];\n\tlet array = [];\n\tlet a = 'i hate';\n\tlet b = 'i love';\n\t\n\tfor (let i = 0; i < n; i++){\n\t\tif (i%2 == 0){\n\t\t\tarray.push(a);\n\t\t}else{\n\t\t\tarray.push(b);\n\t\t}\n\n\t}\n\tconsole.log (array.join(' that ') + ' it ');\n});"}, {"source_code": "var n = parseInt(readline());\n \n \nfor (var i=1; i<=n;i++){\n if(i%2!==0){\n print(\"I hate it\");\n \n if(i%2===0 &&i!=1){\n print (\" I love it \");\n }}}\n \n"}, {"source_code": "var n = parseInt(readline());\n \n \nfor (var i=1; i<=n;i++){\n if(i%2!==0){\n var impar=print(\"I hate\");\n \n if(i%2===0){\n var par=print (\"I love\");\n \n if (i100) \n print(\"Outside range.\")\n else {\n var s = \"\";\n for(var i=1;i<=input[0];i++) {\n if(i%2==0)\n s+=\"I love\";\n else\n s+=\"I hate\";\n \n if(i==input)\n s+= \" it\";\n else\n s+= \" that \";\n }\n print(s);\n }\n \n \n "}, {"source_code": "var n = readline();\nvar string = \"\";\nfor (var i = 1; i <= n; i++) {\n if (i % 2 === 0) {\n string += \"I love it \";\n } else {\n string += \"I hate that \";\n }\n}\nif (n != 1) {\n print(string.substring(0, string.length - 1));\n} else {\n print(string);\n}"}, {"source_code": "var input = parseInt(readline());\nvar i = 1;\nvar output = '';\nwhile(i < input){\n if(input%2 === 0) output += \"I Love that\";\n else output += \"I Hate that\";\n}\nif(input%2 === 0){\n output += \" I Love\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}else{\n output += \" I Hate\";\n if(input > 2) output += \" that\";\n else output += \"it\";\n}"}, {"source_code": " var hulkLvl = readline();\n\n var result = '';\n\n for(var i = 1; i <= hulkLvl; i++){\n if( i % 2 === 0 ) {\n if( i >1 && i == hulkLvl ) {\n result += ' I love it ';\n }\n else if( i > 1 && i != hulkLvl ){\n result += ' I love that ';\n\n } else {\n result += ' I love it ';\n }\n \n } else {\n if( i >1 && i == hulkLvl ){\n result += 'I hate it';\n } else if( i > 1 && i != hulkLvl ) {\n result += 'I hate that';\n } else {\n result += 'I hate it';\n }\n }\n }\n\nprint(result);"}, {"source_code": " var n = parseInt(readline());\n \n function uno(n){\n var impar=\"\";\n if(i%2!==0){\n impar=\"I hate\";\n }\n \n else{\n impar=\"I love\";\n }\n return impar;\n }\n \n \n var imprime;\n \n var medio;\n for (var i=1; i<=n;i++){\n \n if (i 0) {\n if (n % 2 !== 0) {\n if (n > 1) {\n str.concat(that);\n }\n str.concat(odd);\n } else if (n % 2 === 0) {\n str.concat(that);\n str.concat(even);\n }\n str.concat(end);\n }\n\n console.log(str);\n});\n"}], "src_uid": "7f2441cfb32d105607e63020bed0e145"} {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i], 10);\n\t};\n\treturn tokens;\n}\n\nfunction main() {\n\tvar length = parseInt(readline(), 10),\n\t\titems = tokenizeIntegers(readline()),\n\t\tleft = 0, right = length-1;\n\n\twhile (items[left] == left+1) {\n\t\t++left;\n\t\tif (left == length) {\n\t\t\tprint(\"0 0\");\n\t\t\treturn;\n\t\t}\n\t}\n\n\twhile (items[right] == right+1) {\n\t\t--right;\n\t}\n\n\tfor (var delta = 0; right-delta >= left; ++delta) {\n\t\tif (items[right-delta] != left+1+delta) {\n\t\t\tprint(\"0 0\");\n\t\t\treturn;\n\t\t}\n\t}\n\tprint([left+1, right+1].join(\" \"));\n}\n\nmain();\n", "positive_code": [{"source_code": "'use strict'\n\nlet lll\nlet N = +readline()\nlll = readline().split(' ').map(v => parseInt(v))\nlet ss = []\nfor (let i = 1; i < lll.length; i++) {\n ss.push(Math.sign(lll[i] - lll[i - 1]))\n}\n\nlet ifm = ss.indexOf(-1)\nlet ilm = ss.lastIndexOf(-1)\n\nif (~ifm && ~ilm) {\n let bad\n for (let i = ifm; i < ilm; i++) {\n if (ss[i] == 1) {\n bad = true\n break\n }\n }\n if (bad) {\n print('0 0')\n } else {\n let ns = lll.slice(0, ifm).concat(lll.slice(ifm, ilm + 2).reverse(), lll.slice(ilm + 2))\n for (let i = 1; i < ns.length; i++) {\n if (ns[i] < ns[i - 1]) {bad = true; break}\n }\n print(bad ? '0 0' : (ifm + 1) + ' ' + (ilm + 2))\n }\n} else {\n print('0 0')\n}"}, {"source_code": "'use strict';\n\n/*let input = `2\n2 1`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}*/\n\n//code\n\nvar n = Number(readline());\nvar num = readline().split(' ').map(Number);\nnum.unshift(0);\nvar j = 1,\n lIndex = void 0,\n rIndex = void 0,\n sum = void 0;\nwhile (j < num.length && num[j] === j) {\n\tj++;\n}\n//first break\nlIndex = j;\nif (lIndex === num.length || num[lIndex] <= lIndex || num[lIndex] > n) {\n\tprint(\"0 0\");\n} else {\n\tsum = lIndex + num[lIndex];\n\trIndex = num[lIndex];\n\twhile (j <= rIndex && num[j] + j === sum) {\n\t\tj++;\n\t}\n\t//second break\n\tif (j !== rIndex + 1) {\n\t\tprint(\"0 0\");\n\t} else {\n\t\twhile (j < num.length && num[j] === j) {\n\t\t\tj++;\n\t\t}\n\t\t//last break\n\t\tif (j === num.length) {\n\t\t\tprint(lIndex + \" \" + rIndex);\n\t\t} else {\n\t\t\tprint(\"0 0\");\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "'use strict'\n\nlet lll\nlet N = +readline()\nlll = readline().split(' ').map(v => parseInt(v))\nlet ss = []\nfor (let i = 1; i < lll.length; i++) {\n ss.push(Math.sign(lll[i] - lll[i - 1]))\n}\n\nlet ifm = ss.indexOf(-1)\nlet ilm = ss.lastIndexOf(-1)\n\nif (~ifm && ~ilm && ifm != ilm) {\n let bad\n for (let i = ifm; i < ilm; i++) {\n if (ss[i] == 1) {\n bad = true\n break\n }\n }\n print(bad ? '0 0' : (ifm + 1) + ' ' + (ilm + 2))\n} else {\n print('0 0')\n}"}, {"source_code": "'use strict';\n\n/*let input = `4\n1 2 3 4`.split('\\n');\nfunction print(output) {\n\tconsole.log(output);\n}\nfunction readline() {\n\treturn input.shift();\n}\n*/\n//code\n\nvar n = Number(readline());\nvar num = readline().split(' ').map(Number);\nnum.unshift(0);\nvar j = 0,\n lIndex = void 0,\n rIndex = void 0;\nwhile (j < num.length && num[j] === j) {\n\tj++;\n}\n//first break\nlIndex = j;\nif (lIndex === num.length || num[lIndex] <= lIndex || lIndex + num[lIndex] !== n) {\n\tprint(\"0 0\");\n} else {\n\trIndex = num[lIndex];\n\twhile (j <= rIndex && num[j] + j === n) {\n\t\tj++;\n\t}\n\t//second break\n\tif (j !== rIndex + 1) {\n\t\tprint(\"0 0\");\n\t} else {\n\t\twhile (j < num.length && num[j] === j) {\n\t\t\tj++;\n\t\t}\n\t\t//last break\n\t\tif (j === num.length) {\n\t\t\tprint(lIndex + ' ' + rIndex);\n\t\t} else {\n\t\t\tprint(\"0 0\");\n\t\t}\n\t}\n}\n"}], "src_uid": "a440099306ef411a4deca7fe3305c08b"} {"source_code": "for(t=readline();t--;){print(Math.ceil(Math.sqrt(readline()*1.5)))}", "positive_code": [{"source_code": "t=readline();while(t--){print(Math.ceil(Math.sqrt(readline()*1.5)))}"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nconst N = 10 ** 9;\r\nconst dp = [];\r\nlet cur = 0;\r\nfor (let i = 0;; i++) {\r\n var _dp;\r\n if (i % 3 !== 2) cur += 2;\r\n dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + cur;\r\n if (dp[i] > N) break;\r\n}\r\nfunction solve(n) {\r\n let l = 0,\r\n r = dp.length - 1;\r\n while (l < r) {\r\n const mid = l + r >> 1;\r\n if (dp[mid] < n) {\r\n l = mid + 1;\r\n } else {\r\n r = mid;\r\n }\r\n }\r\n return l + 2;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n res.push(solve(n));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [], "src_uid": "fbc8d6564905fbe82f9f612b2da3484d"} {"source_code": "var n = readline();\nvar s = readline()\n\nvar letters = ['a', 'i', 'u', 'y']\nvar lettters = ['o', 'e']\n\nvar ss = \"\"\nvar k = 1;\n\nfor (var i = 1; i < s.length; ++i) {\n if (s[i] == s[i - 1]) ++k;\n else {\n if (k > 1) {\n if (letters.indexOf(s[i - 1]) != -1) {\n ss += s[i - 1];\n }\n else if (lettters.indexOf(s[i - 1]) != -1) {\n if (k > 2) ss += s[i - 1];\n else ss += s[i - 1] + s[i - 1];\n }\n else {\n for (var q = 0; q < k; ++q) ss += s[i - 1];\n }\n }\n else ss += s[i - 1];\n k = 1;\n }\n}\n\nvar i = s.length\nif (k > 1) {\n if (letters.indexOf(s[i - 1]) != -1) {\n ss += s[i - 1];\n }\n else if (lettters.indexOf(s[i - 1]) != -1) {\n if (k > 2) ss += s[i - 1];\n else ss += s[i - 1] + s[i - 1];\n }\n else {\n for (var q = 0; q < k; ++q) ss += s[i - 1];\n }\n}\nelse ss += s[i - 1];\n\nprint(ss);\n", "positive_code": [{"source_code": "var n = parseInt(readline());\nvar s = readline();\n\nfunction is_vowel(c) {\n return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');\n}\n\nvar ans = \"\";\nfor (var i = 0; i < n ; ) {\n if (is_vowel(s[i])) {\n var cnt = 0;\n var cur = s[i];\n var j;\n for (j = i; j < n; ++j) {\n if (s[j] != s[i]) break;\n cnt ++;\n }\n\n if (s[i] == 'e' || s[i] == 'o') {\n if (cnt == 2) {\n ans += cur + cur;\n }\n else {\n ans += cur;\n }\n }\n else {\n ans += cur;\n }\n i = j;\n }\n else {\n ans += s[i];\n i ++;\n }\n}\n\nprint(ans)"}, {"source_code": "function main() {\n\t var n = readline(), str = readline();\nvar res = \"\";\nfor (var i=0; i0 && cnt==2 && (s[i-1]=='e'||s[i-1]=='o')) {\n t+=s[i-1];\n t+=s[i-1];\n } else if(cnt>=1 && (s[i-1]=='a'||s[i-1]=='e'||s[i-1]=='i'||s[i-1]=='o'||s[i-1]=='u'||s[i-1]=='y')) {\n t+=s[i-1];\n }\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y') {\n cnt=1;\n } else {\n cnt=0;\n t+=s[i];\n }\n }\n i+=1;\n}\nif(i>0 && cnt==2 && (s[i-1]=='e'||s[i-1]=='o')) {\n t+=s[i-1];\n t+=s[i-1];\n} else if(cnt>=1 && (s[i-1]=='a'||s[i-1]=='e'||s[i-1]=='i'||s[i-1]=='o'||s[i-1]=='u'||s[i-1]=='y')) {\n t+=s[i-1];\n}\n\nprint(t);"}, {"source_code": "var n = parseInt(readline());\nvar s = \"#\" + readline() + \"#\";\n\nvar ans = \"\";\n// var prev = s[0];\n\n\nfunction isVowel(c) {\n return c == 'a' || c == 'e' || c == 'i' || c =='o' || c == 'u' || c == 'y';\n}\nvar i = 1;\nvar count = 0;\nwhile(i <= n) {\n //print(s[i])\n if(!isVowel(s[i])) {\n ans += s[i];\n } else {\n count = 1;\n while(s[i] == s[i + 1]) {\n count++;\n i++;\n }\n if((s[i] == 'e' || s[i] == 'o') && count == 2) {\n ans += s[i] + s[i];\n } else {\n ans += s[i];\n }\n \n }\n i++;\n}\n\n\nprint(ans);"}, {"source_code": "readline();\nstr = readline();\n\nres = [];\nword = \"\";\nfunction addWord() {\n var ch = word.charAt(0);\n if ((ch == 'e' || ch == 'o') && word.length <= 2) {\n res.push(word);\n } else if (['e', 'a', 'i', 'o', 'u', 'y'].indexOf(ch) !== -1) {\n res.push(ch);\n } else {\n res.push(word);\n }\n word = '';\n}\nfor (var i = 0; i < str.length; i++) {\n if (word == '' || word[0] === str[i]) {\n word += str[i];\n } else {\n addWord();\n word = str[i];\n }\n}\naddWord();\n\n\nwrite(res.join(''));"}, {"source_code": "n=+readline()\ns=readline()\n\nvar l = 0\nvar pr = s[0]\nvar ans = \"\"\nfor(var i=0; i<=n; i++){\n if(i1 && (pr=='a' || pr=='e'|| pr=='i'|| pr=='o'|| pr=='u'|| pr=='y')) l = 1\n ans+=Array(l+1).join(pr)\n l = 1\n }\n if(i==n) break;\n pr = s[i]\n}\n\nprint(ans)"}, {"source_code": "var n = parseInt(readline());\ns = readline().split('');\nvar i;\nfor (i = 1; i < n; i++) {\n var lowel = 0;\n if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y'){\n lowel = 1;\n }\n var start = i-1;\n while (i 2){\n for(var j=start+1; j 1){\n for(var j=start+1; j 1)\n i--;\n}\noutput = \"\"\nfor (i = 0; i < n; i++) {\n if (s[i] != '#'){\n output += s[i];\n }\n}\nprint(output);"}, {"source_code": "var n=+readline();\nvar s=readline();\nvar i = 0;\nvar ans = \"\";\nwhile (i < n) {\n if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y') {\n ans += s[i];\n ++i;\n } else {\n var j = i;\n while (j < n && s[j] == s[i]) {\n ++j;\n }\n if (j - i == 2 && (s[i] == 'e' || s[i] == 'o')) {\n ans += s[i];\n ans += s[i];\n } else {\n ans += s[i];\n }\n i = j;\n }\n}\nprint(ans);"}, {"source_code": "n=+readline()\ns=readline()\n\nvar l = 0\nvar pr = s[0]\nvar ans = \"\"\nfor(var i=0; i<=n; i++){\n if(i1 && (pr=='a' || pr=='e'|| pr=='i'|| pr=='o'|| pr=='u'|| pr=='y')) l = 1\n ans+=Array(l+1).join(pr)\n l = 1\n }\n if(i==n) break;\n pr = s[i]\n}\n\nprint(ans)\n\n"}, {"source_code": "var n = +readline() + 1;\nvar s = readline() + '1';\nvar prev = s.charAt(0);\nvar cnt = 1;\nvar answer = \"\";\nfor (i = 1; i < n; i++) {\n var c = s.charAt(i);\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' || c == '1') {\n if (c == prev) {\n cnt++;\n } else {\n if (cnt == 2 && (prev == 'e' || prev == 'o')) {\n answer += prev;\n answer += prev;\n } else {\n answer += prev;\n }\n prev = c;\n cnt = 1;\n }\n } else {\n if (cnt == 2 && (prev == 'e' || prev == 'o')) {\n answer += prev;\n answer += prev;\n } else {\n answer += prev;\n }\n prev = '';\n cnt = 0;\n answer += c;\n }\n}\nprint(answer);"}, {"source_code": "maybelength = +readline();\ns = readline();\ns = s.replace(/e{3,}/g,'e');\ns = s.replace(/o{3,}/g,'o');\ns = s.replace(/a{2,}/g,'a');\ns = s.replace(/u{2,}/g,'u');\ns = s.replace(/y{2,}/g,'y');\ns = s.replace(/i{2,}/g,'i');\nprint(s);"}, {"source_code": "x=+readline()\ns=readline()\nvar curs=\"\";\nvar result = \"\";\nvar count = 0;\nfor(i=0; i 1) {\n cnt = 1;\n }\n } else if ((prev == \"e\") || (prev == \"o\")) {\n if ((cnt > 1) && (cnt != 2)) {\n cnt = 1;\n }\n }\n for (var j = 0; j < cnt; j = j + 1) {\n r += prev;\n }\n cnt = 1;\n }\n prev = s[i];\n}\n\nif ((prev == \"a\") || (prev == \"i\") || (prev == \"u\") || (prev == \"y\")) {\n if (cnt > 1) {\n cnt = 1;\n }\n} else if ((prev == \"e\") || (prev == \"o\")) {\n if ((cnt > 1) && (cnt != 2)) {\n cnt = 1;\n }\n}\nfor (var j = 0; j < cnt; j = j + 1) {\n r += prev;\n}\n\nprint(r);\n\n"}, {"source_code": "var n = +readline();\nvar s = readline();\n\nvar res = \"\", len = 0;\nfor(var i = 0; i < s.length; i++)\n{\n if (i - 1 >= 0 && s[i - 1] == s[i] && \n (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y'))\n {\n if ((i + 1 == s.length || s[i + 1] != s[i]) && len == 0 && (s[i] == 'e' || s[i] == 'o'))\n res = res + s[i];\n len++;\n }\n else\n {\n res = res + s[i];\n len = 0;\n }\n}\n\nprint(res);"}], "negative_code": [{"source_code": "readline();\nstr = readline();\n\nres = \"\";\nword = \"\";\nfunction addWord() {\n if (word.length <= 2) {\n res += word;\n } else {\n res += word.charAt(0);\n }\n word = '';\n}\nfor (var i = 0; i < str.length; i++) {\n if (word == '' || word[0] === str[i]) {\n word += str[i];\n } else {\n addWord();\n word = str[i];\n }\n}\naddWord();\n\n\nwrite(res);"}, {"source_code": "var n = readline();\nvar s = readline()\n\nss = s[0];\n\nfor (var i = 1; i < s.length; ++i) {\n if (s[i] != s[i - 1]) ss += s[i];\n}\n\nprint(ss);\n"}, {"source_code": "var s = readline();\nvar r = \"\";\n\nvar prev = \"~\";\nvar cnt = 0;\n\nfor (var i = 0; i < s.length; i = i + 1) {\n if (s[i] == prev) {\n cnt = cnt + 1;\n } else {\n if ((prev == \"a\") || (prev == \"i\") || (prev == \"u\") || (prev == \"y\")) {\n if (cnt > 1) {\n cnt = 1;\n }\n } else if ((prev == \"e\") || (prev == \"o\")) {\n if ((cnt > 1) && (cnt != 2)) {\n cnt = 1;\n }\n }\n for (var j = 0; j < cnt; j = j + 1) {\n r += prev;\n }\n cnt = 1;\n }\n prev = s[i];\n}\n\nif ((prev == \"a\") || (prev == \"i\") || (prev == \"u\") || (prev == \"y\")) {\n if (cnt > 1) {\n cnt = 1;\n }\n} else if ((prev == \"e\") || (prev == \"o\")) {\n if ((cnt > 1) && (cnt != 2)) {\n cnt = 1;\n }\n}\nfor (var j = 0; j < cnt; j = j + 1) {\n r += prev;\n}\n\nprint(r);\n\n"}, {"source_code": "function main() {\n\t var n = readline(), str = readline();\nvar res = \"\";\nfor (var i=0; i stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var a = lines[i].split(' ').map(Number);\n var n = a[0], k = a[1];\n if(k == 1 || n % 2 === 0){\n console.log('YES');\n var ans = '';\n for(j = 0; j < n; j++){\n for(l = 0; l < k; l++){\n ans += j + 1 + l * n + ' ';\n } \n console.log(ans);\n ans = '';\n }\n }else{\n console.log('NO');\n }\n }\n});\n", "positive_code": [{"source_code": "const yes = (n,k)=>{\r\n console.log(\"YES\");\r\n for(let i=0;i{\r\n if((n===1)&&(k!==1)) console.log(\"NO\");\r\n else if((k===1)) yes(n,k);\r\n else if(n%2===0) yes(n,k);\r\n else console.log(\"NO\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(arr[0],arr[1]);\r\n }\r\n}\r\nmain();"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (k == 1) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconsole.log(i+1);\r\n\t\t\t}\r\n\t\t} else if ((n&1) == 0) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconst ar = [];\r\n\t\t\t\tfor (let j = 0; j < k; j++) {\r\n\t\t\t\t\tar.push(i + 1 + j*n);\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log(ar.join(' '));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "// Author: old_school\r\n// Created: 08.02.2022 09:33:53\r\n\r\nvar t = readline();\r\nfunction solve(flag) {\r\n var arr = [];\r\n for(var i = 1; i <= n*m; i++) {\r\n if (i % 2 == flag) {\r\n arr.push(i);\r\n }\r\n if(arr.length == m) {\r\n print(arr.join(' '));\r\n arr = [];\r\n }\r\n }\r\n}\r\nwhile(t--) {\r\n var c = readline().split(\" \");\r\n var n = c[0], m = c[1];\r\n var even = Math.floor((n*m)/2);\r\n if (even % m) {\r\n print(\"NO\");\r\n continue;\r\n }\r\n print(\"YES\");\r\n solve(1);\r\n solve(0);\r\n}"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (k == 1 || (n&1) == 0) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconst ar = [];\r\n\t\t\t\tfor (let j = 0; j < k; j++) {\r\n\t\t\t\t\tar.push(i + 1 + j*n);\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log(ar.join(' '));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n"}], "negative_code": [{"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (k == 1) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconsole.log(i+1);\r\n\t\t\t}\r\n\t\t} else if ((n&1) == 0) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconst ar = [];\r\n\t\t\t\tfor (let j = 0; j < k; j++) {\r\n\t\t\t\t\tar.push(i + 1 + j*k);\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log(ar.join(' '));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, k] = rna();\r\n\r\n\t\tif (k == 1) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconsole.log(i+1);\r\n\t\t\t}\r\n\t\t} else if ((n&1) == 0) {\r\n\t\t\tconsole.log('YES');\r\n\t\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\t\tconst ar = [];\r\n\t\t\t\tfor (let j = 0; j < k; j++) {\r\n\t\t\t\t\tar.push((i>>1)*k + j + 1);\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log(ar.join(' '));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconsole.log('NO');\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "const yes = (n,k)=>{\r\n console.log(\"YES\");\r\n for(let i=0;i{\r\n if((n===1)&&(k!==1)) console.log(\"NO\");\r\n else if((k===1)) yes(n,k);\r\n else if(n%2===0) yes(n,k);\r\n console.log(\"NO\");\r\n}\r\nfunction main() {\r\n const fs = require(\"fs\");\r\n const input = fs.readFileSync(0, \"utf8\").trim().split(\"\\n\");\r\n let line = 0;\r\n function readline() {\r\n return input[line++];\r\n }\r\n let t = parseInt(readline());\r\n for(let i=0;iparseInt(cur));\r\n solve(arr[0],arr[1]);\r\n }\r\n}\r\nmain();"}, {"source_code": "const solve = (n,k)=>{\r\n if(k===1){\r\n console.log(\"YES\");\r\n for(let i=0;iparseInt(cur));\r\n solve(arr[0],arr[1]);\r\n }\r\n}\r\nmain();"}, {"source_code": "// Author: old_school\r\n// Created: 08.02.2022 09:33:53\r\n\r\nvar t = readline().split(\"\");\r\nfunction solve(flag) {\r\n var arr = [];\r\n for(var i = 1; i <= n*m; i++) {\r\n if (i % 2 == flag) {\r\n arr.push(i);\r\n }\r\n if(arr.length == m) {\r\n print(arr.join(' '));\r\n arr = [];\r\n }\r\n }\r\n}\r\nwhile(t--) {\r\n var c = readline().split(\" \");\r\n var n = c[0], m = c[1];\r\n var even = Math.floor((n*m)/2);\r\n if (even % m) {\r\n print(\"NO\");\r\n continue;\r\n }\r\n print(\"YES\");\r\n solve(1);\r\n solve(0);\r\n}"}], "src_uid": "9fb84ddc2e04fd637812cd72110b7f36"} {"source_code": "var t = Number(readline());\nvar a = readline().split(' ').map(x=>Number(x));\nvar b = readline().split(' ').map(x=>Number(x));\nvar c = [];\nfor(var i=t-1;i>=0;i--)\n c[i] = a[i]-b[i];\nc.sort(function(a,b){return b-a;});\nvar r=0;\nvar z=0;\nfor(;z=0;i--){\n for(;j readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const ai = getInts()\n const bi = getInts()\n\n const arr = []\n for (let i = 0; i < n; ++i) {\n arr.push(ai[i] - bi[i])\n }\n\n arr.sort((a, b) => a - b)\n let ans = 0\n let l = 0\n let r = n - 1\n while (l < r) {\n while (l < r && arr[l] + arr[r] > 0) {\n r --\n }\n\n if (l == r) break\n ans += n - r - 1\n l ++\n }\n\n ans += sum(n - r)\n print(ans)\n}\n\nfunction sum (k) {\n return (k * (k - 1)) / 2\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const n = readInt(input)\n const a = readInts(input)\n const b = readInts(input)\n\n let diff = new Array(n)\n for(let i = 0; i < n; i++){\n diff[i] = a[i] - b[i]\n }\n sort(diff)\n // console.log(diff)\n let map = {}\n let ne = 0\n let ze = 0\n let po = 0\n for(let i = 0; i < n; i++){\n if(diff[i] === 0) ze++\n else if(diff[i] > 0) po++\n else ne++\n }\n let count = Math.abs(po * (po - 1) / 2)\n if(ze > 0) count += po * ze\n // console.log(count)\n let i\n for(i = 0; i < n && diff[i] < 0; i++){\n if(!map[diff[i]]) map[diff[i]] = 1\n else map[diff[i]]++\n }\n let k = i\n while(diff[k] === 0) k++\n i--\n // console.log(i, k)\n\n while(i >= 0 && k < n) {\n if(diff[i] > -diff[k]) {\n count += n - k\n i--\n }\n else k++\n }\n wr(count)\n}"}], "negative_code": [{"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const ai = getInts()\n const bi = getInts()\n\n const arr = []\n for (let i = 0; i < n; ++i) {\n arr.push(ai[i] - bi[i])\n }\n\n arr.sort((a, b) => a - b)\n let r = n - 1\n let ans = 0\n\n for (let l = 0; l < r; ++l) {\n while (r >= 0) {\n if (arr[r] + arr[l] <= 0) break\n r --\n }\n ans += n - r - 1\n }\n ans += sum(n - r)\n print(ans)\n}\n\nfunction sum (k) {\n return (k * (k - 1)) / 2\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const ai = getInts()\n const bi = getInts()\n\n const arr = []\n for (let i = 0; i < n; ++i) {\n arr.push(ai[i] - bi[i])\n }\n\n arr.sort((a, b) => a - b)\n let r = n - 1\n let ans = 0\n\n for (let l = 0; l < r; ++l) {\n while (r > 0) {\n if (arr[r] + arr[l] <= 0) break\n r --\n }\n if (arr[r] + arr[l] > 0) break\n ans += n - r - 1\n }\n \n ans += sum(n - r)\n print(ans)\n}\n\nfunction sum (k) {\n return (k * (k - 1)) / 2\n}"}, {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const n = getInt()\n const ai = getInts()\n const bi = getInts()\n\n const arr = []\n for (let i = 0; i < n; ++i) {\n arr.push(ai[i] - bi[i])\n }\n\n arr.sort((a, b) => a - b)\n let l = n - 1\n while (l > 0 && arr[l] + arr[0] > 0) l --\n if (arr[l] + arr[0] <= 0) l ++\n \n const k = (n - l)\n let ans = l * k + ((k * (k - 1)) / 2)\n print(ans)\n}"}, {"source_code": "var t = Number(readline());\nvar a = readline().split(' ').map(x=>Number(x));\nvar b = readline().split(' ').map(x=>Number(x));\nvar c = [];\nfor(var i=t-1;i>=0;i--)\n c[i] = a[i]-b[i];\nc.sort(function(a,b){return b-a;});\nvar r=0;\nvar z=0;\nfor(;z=0;i--){\n for(;jNumber(x));\nvar b = readline().split(' ').map(x=>Number(x));\nvar c = [];\nfor(var i=t-1;i>=0;i--)\n c[i] = a[i]-b[i];\nc.sort(function(a,b){return b-a;});\nprint(c);\nvar r=0;\nvar z=0;\nfor(;z=0;i--){\n for(;j {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const n = readInt(input)\n const a = readInts(input)\n const b = readInts(input)\n\n let diff = new Array(n)\n for(let i = 0; i < n; i++){\n diff[i] = a[i] - b[i]\n }\n sort(diff)\n // console.log(diff)\n let map = {}\n let ne = 0\n let ze = 0\n let po = 0\n for(let i = 0; i < n; i++){\n if(diff[i] === 0) ze++\n else if(diff[i] > 0) po++\n else ne++\n }\n let count = po * (po - 1) / 2\n if(ze > 0) count += po\n // console.log(count)\n let i\n for(i = 0; i < n && diff[i] < 0; i++){\n if(!map[diff[i]]) map[diff[i]] = 1\n else map[diff[i]]++\n }\n let k = i\n while(diff[k] === 0) k++\n i--\n // console.log(i, k)\n\n while(i >= 0 && k < n) {\n if(diff[i] > -diff[k]) {\n count += n - k\n i--\n }\n else k++\n }\n wr(count)\n}"}, {"source_code": "\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet arr = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main(arr)\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if(inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt(a) {\n return parseInt(a[ptr++])\n}\n\nfunction readString(a) {\n return a[ptr++]\n}\n\nfunction readStrings(a) {\n return a[ptr++].split(' ')\n}\n\nfunction readInts(a) {\n return a[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main(input) {\n const n = readInt(input)\n const a = readInts(input)\n const b = readInts(input)\n\n let diff = new Array(n)\n for(let i = 0; i < n; i++){\n diff[i] = a[i] - b[i]\n }\n sort(diff)\n // console.log(diff)\n let map = {}\n let ne = 0\n let ze = 0\n let po = 0\n for(let i = 0; i < n; i++){\n if(diff[i] === 0) ze++\n else if(diff[i] > 0) po++\n else ne++\n }\n let count = po * (po - 1) / 2\n if(ze > 0) count += po * ze\n // console.log(count)\n let i\n for(i = 0; i < n && diff[i] < 0; i++){\n if(!map[diff[i]]) map[diff[i]] = 1\n else map[diff[i]]++\n }\n let k = i\n while(diff[k] === 0) k++\n i--\n // console.log(i, k)\n\n while(i >= 0 && k < n) {\n if(diff[i] > -diff[k]) {\n count += n - k\n i--\n }\n else k++\n }\n wr(count)\n}"}], "src_uid": "e25b247975660c5005bd4da7afd38a56"} {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(value => +value);\nvar odd; \nif (arr[0] % 2 === 0 && arr[1] % 2 === 0) odd = 1;\nif (arr[0] % 2 === 1 && arr[1] % 2 === 1) odd = 0;\nif (arr[0] % 2 !== arr[1] % 2) print((arr[0] % 2 === arr[2] % 2) ? 2 : 1)\nelse {\n\twhile(arr[n - 1] % 2 !== odd) n--;\n\tprint(n);\n}", "positive_code": [{"source_code": "var n=readline(); n=parseInt(n);\nvar arr=readline().split(' ').map(function(x){return parseInt(x)});\nfor(i = 0 ; i {\n if (array_1.length === 1) {\n return array_1;\n }\n \n return array_2;\n}\n\nconst filterOddNumbers = number => number % 2;\nconst filterEvenNumbers = number => number % 2 === 0;\n\nconst n = readline(),\n array = readline().split(' ').map(value => parseInt(value));\n\nwrite(array.indexOf(getArray(\n array.filter(filterOddNumbers),\n array.filter(filterEvenNumbers)\n)[0]) + 1);"}, {"source_code": "var n = parseInt(readline());\nvar mas = readline();\nmas = mas.split(\" \");\nvar even = 0;\nfor(var i = 0; i < 3; ++i)\n{\n if(parseInt(mas[i]) % 2 == 0){even ++;}\n}\nvar i;\nfor(i = 0; i < n; ++i)\n{\n if(even > 1 && parseInt(mas[i]) % 2 != 0){break;}\n else if(even < 2 && parseInt(mas[i]) % 2 == 0){break;}\n}\nprint(i+1);"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(\" \");\nvar k = 0, k1 = 0, res = 0, res1 = 0;\nfor (var i = 0; ix%2==0);\n\t\t\n\t\tfor (var i=0; i<+n; i++){\t\t\t\n\t\t\tif(chet.length>1&&arr[i]%2!=0){\n\t\t\t\tprint(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (chet.length==1&&arr[i]%2==0){\n\t\t\t\tprint(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}"}, {"source_code": "var x=parseInt(readline());\nvar arr=readline().split(' ');\nvar e=0,ev,od;\nfor(var i=0;i0) \n{print(parseInt(od+1));\n}else{\n print(parseInt(ev+1));\n}"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(\" \");\n\nvar k = 0, k1 = 0, res = 0, res1 = 0;\nfor (var i = 0; i 1)\n {\n print(index+1);\n printed = true;\n break;\n }\n else\n {\n evenNumbers.push(index);\n }\n }\n else \n {\n if (evenNumbers.length > 1)\n {\n print(index+1);\n printed = true;\n break;\n }\n else\n {\n notEvenNumbers.push(index);\n }\n \n }\n } \nif (evenNumbers.length > 1 && !printed)\n {\n print(notEvenNumbers[0]+1);\n }\nelse if(!printed)\n {\n print(evenNumbers[0]+1);\n }\n \nfunction isEven(number)\n{ \n for(var counter = 2; ;)\n {\n if (number === 1)\n {\n return false;\n }\n else if ( !(number -= counter) )\n {\n return true;\n }\n \n \n }\n return false;\n}"}, {"source_code": "var n = readline();\nvar data = readline().split(\" \");\n\nvar count_o=0;\nvar last_e,last_o;\nfor(var i = 0; i < n; i++){\n\tif(data[i]&1){\n\t\tcount_o++;\n\t\tlast_o = i+1;\n\t}\n\telse\n\t\tlast_e = i+1;\n\t\n}\nif(count_o == 1)\n\tprint(last_o);\nelse\n\tprint(last_e);\t"}, {"source_code": "var n = readline();\nvar numbers = readline().split(' ');\nfindUniqueNumber();\n\nfunction findUniqueNumber() {\n var isRemArr = [];\n var sumOfRes = 0;\n for (var i = 1; i < 2; i++) {\n var div = i + 1;\n for (var j = 0; j < numbers.length; j++) {\n if (numbers[j] % div !== 0) {\n isRemArr.push(1);\n sumOfRes++;\n } else {\n isRemArr.push(0);\n }\n }\n // print(isRemArr);\n var answer;\n if (sumOfRes === n - 1) {\n answer = isRemArr.indexOf(0);\n } else if (sumOfRes === 1) {\n answer = isRemArr.indexOf(1);\n }\n if (answer !== -1) {\n print(answer + 1);\n return;\n }\n }\n}"}, {"source_code": "var line = readline();\nvar n = parseInt(line);\n\nvar newnum = readline().split(' ').map(Number);\n\nvar oddcount=0;\nvar evencount=0;\n\nfor(i=0;i parseInt(i)).reduce((a,c,i) => {\n\tif (c%2) odd=i; else even=i;\n\treturn a + c%2\n}, 0)\nprint((X===1?odd:even)+1)"}, {"source_code": "var n = parseInt(readline());\nvar array = readline().split(' ').map(Number);\nvar even = [];\nvar odd = [];\n\nfor (var i = 0; i < n; i++) {\n\tif (array[i] % 2 == 0) {\n\t\teven.push(i);\n\t} \n\telse {\n\t\todd.push(i);\n\t}\n}\n\nprint (odd.length == 1 ? odd[0] + 1 : even[0] + 1);"}, {"source_code": "var chetnie = [];\nvar nechetniye = [];\nvar num = parseInt(readline());\nvar numbers = readline().split(' ').map(function (num) {return parseInt(num)});\n\nfor (var i = 0; i < num; i++) {\n\tif (numbers[i] % 2 == 0) {\n\t\tchetnie.push(numbers[i]);\n\t\tlastChetnoye = i + 1;\n\t} else {\n\t\tnechetniye.push(numbers[i]);\n\t\tlastNechetnoye = i + 1;\n\t}\n\tif (chetnie.length > 1 && nechetniye.length == 1) {\n\t\tprint(lastNechetnoye);\n\t\tbreak;\n\t}\n\tif (nechetniye.length > 1 && chetnie.length == 1) {\n\t\tprint(lastChetnoye);\n\t\tbreak;\n\t}\n}"}, {"source_code": "\t\n\treadline();var prm = readline().split(\" \").map(function(m){if((+m)%2==0){return \"z\"}else{return \"f\"}});\n\t\tvar r = 0;\n \n\tfor(var i=0;i a % 2);\nparity.sort();\n\nvar kontr = parity[1];\nfor(var i = 0; i < n; i++){\n if(kontr != arr[i] % 2){\n print(i + 1);\n }\n}"}, {"source_code": "readline()\nvar s=readline().split(' ').map(function(v){return v%2}).join('')\nprint(s.indexOf(s.match(/0/g).length<=1?0:1)+1)"}, {"source_code": "var i1=0;\nvar i2=0;\nvar c1=0;\nvar c2=0;\nreadline();\nreadline().split(' ').map(Number).forEach(function(v, i){\n\tif(v%2){\n\t\tc1++;\n\t\ti1=i;\n\t}else{\n\t\tc2++;\n\t\ti2=i;\n\t}\n});\nprint(c1>c2 ? i2+1 : i1+1);"}, {"source_code": "readline();\nvar a=readline().split(' ').map(function(v){return v%2});\nvar s=0;\nfor(var i=0;i<3;i++){\n\ts+=a[i]%2;\n}\nprint( a.indexOf( s>=2?0:1 ) + 1 );"}, {"source_code": "var n = +readline(), numbers = readline().split(\" \");\n\nif(+numbers[0] % 2 == 0){\n\tif(+numbers[1] % 2 == 0){\n\t\tfor(i = 2; i < n; i++){\n\t\t\tif(+numbers[i] % 2 == 1){\n\t\t\t\twrite(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\telse{\n\t\tif(+numbers[2] % 2 == 0){\n\t\t\twrite(2);\n\t\t}\n\t\telse{\n\t\t\twrite(1);\n\t\t}\n\t}\n}\nelse{\n\tif(+numbers[1] % 2 == 1){\n\t\tfor(i = 2; i < n; i++){\n\t\t\tif(+numbers[i] % 2 == 0){\n\t\t\t\twrite(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\telse{\n\t\tif(+numbers[2] % 2 == 1){\n\t\t\twrite(2);\n\t\t}\n\t\telse{\n\t\t\twrite(1);\n\t\t}\n\t}\n}"}, {"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(x) {return (+x) % 2;});\nvar sum = a.reduce(function(a, b) {return a + b});\nvar lookFor = sum == 1 ? 1 : 0;\nfor (var i = 0; i < n; i ++) if (a[i] == lookFor) print(i + 1);"}, {"source_code": "var n = readline(); \nvar s = readline().split(' ');\n\nvar i = 0;\n\nvar odd_n = 0;\nvar odd_x = 0;\nvar evenn = 0;\nvar evenx = 0;\n\nfor(i=0; i= 3)\n\tinput = readline();\n\n//turn the string to array of intgers\ninput = input.split(' ').map((str) => {\n\treturn parseInt(str);\n});\n\nindex = 0; //index counter\n\n//return as soon as the condition is true\ninput.some((num) => {\n\tindex++;\n\t//Check weather the first number is the different one\n\tif ((input[1] % 2 === input[2] % 2) &&\n\t\t(input[1] % 2 !== input[0] % 2)) {\n\t\treturn true;\n\t}\n\t//return when a number differs than the first number\n\telse {\n\t\tif (input[0] % 2 === 0)\n\t\t\treturn num % 2 !== 0;\n\t\telse\n\t\t\treturn num % 2 === 0;\n\t}\n});\n\nprint(index);"}, {"source_code": "'use strict'\n\nlet lll = readline()\n\nlet ns = readline().split(' ').map(v => parseInt(v))\n\nlet fe = ns[0] % 2\nlet se = ns[1] % 2\nlet te = ns[2] % 2\n\nlet ae = +(fe + se + te >= 2)\n\n;(function () {\n for (let i = 0; i < ns.length; i++) {\n if (ns[i] % 2 != ae) return print(i + 1)\n }\n})()"}, {"source_code": " var n=readline()\n var a=readline()\n var e=0,o=0,pose=0,poso=0;\n var arr=new Array();\n var st=\"\";\n for(var i=0;i input += data);\nprocess.stdin.on(\"end\", () => {\n const parities = input.split(\"\\n\")[1].split(\" \").map(Number).map(x => x % 2);\n if (parities.reduce((a, b) => a + b) > 1)\n {\n console.log(parities.indexOf(0) + 1);\n } else {\n console.log(parities.indexOf(1) + 1);\n }\n});"}, {"source_code": "const readline = require('readline');\n\nlet secondLine = false;\n\n\n// Create readline Interface\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet inputs = [];\n\n\n\nrl.on('line', lineInput => {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const n = parseInt(inputs[0]);\n const numbers = inputs[1].split(' ').map(number => parseInt(number));\n let chages = 0;\n\n for (let i = 1; i < numbers.length; i++) {\n\n if (numbers[i] % 2 != numbers[0] % 2)\n chages++;\n\n // if the change occurred early\n if (i == 1 && chages == 1) {\n if (numbers[i] % 2 == numbers[i + 1] % 2)\n return console.log(1)\n else\n return console.log(2)\n }\n\n // \n if (i > 1 && chages == 1) {\n return console.log(i + 1)\n }\n\n\n\n }\n\n\n});\n\n\n"}, {"source_code": "const input = [];\n \nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', (line) => {\n input.push(line);\n});\n\nRL.on('close', () => {\n const nums = input[1].split(' ').map(x => parseInt(x));\n const cnt = [0, 0];\n\n nums.forEach((x, i) => {\n if (x % 2 === 0) cnt[0] += 1;\n else cnt[1] += 1;\n if (i === 2) return;\n });\n\n nums.forEach( (x, i) => {\n if (cnt[0] > cnt[1] && x % 2 !== 0) {\n console.log(i+1); return;\n } else if (cnt[1] > cnt[0] && x % 2 === 0) {\n console.log(i+1); return;\n }\n });\n});"}, {"source_code": "const input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n const nums = splitAndParseInt(input[1]);\n let cntOdd = (nums[0] % 2 !== 0) + (nums[1] % 2 !== 0) + (nums[2] % 2 !== 0);\n\n for (let i = 0; i < nums.length; i += 1) {\n let n = nums[i];\n if (cntOdd <= 1 && n % 2 !== 0) {\n console.log(i + 1);\n return;\n } else if (cntOdd > 1 && n % 2 === 0) {\n console.log(i + 1);\n return;\n }\n }\n});\n"}, {"source_code": "const readline = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadline.on('line', line => { input.push(line); });\n\nreadline.on('close', () => {\n const [n] = input[0].split(' ').map(Number);\n const arr = input[1].split(' ').map(Number);\n const evens = [], odds = [];\n arr.forEach((v, i) => v % 2 === 0 ? evens.push(i + 1) : odds.push(i + 1));\n if (evens.length === 1) console.log(evens[0]);\n else console.log(odds[0]);\n});"}, {"source_code": "let fs = require('fs');\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\n\").filter(data => data.length > 0);\nfor (let i = 0; i < txt.length; i += 2) {\n doit(txt[i + 1].split(\" \").filter(data => data.length > 0).map(data => data * 1));\n}\n\nfunction doit(tab) {\n let t = tab.filter(data => data % 2 === 0);\n if (t.length == 1) {\n console.log(tab.indexOf(t[0]) + 1);\n } else {\n console.log(tab.indexOf(tab.filter(data => data % 2 == 1)[0]) + 1);\n }\n\n}"}, {"source_code": "print((d => 1 + d.findIndex(x => x % 2 == d.reduce((d, x) => d.splice(x%2, 1, d[x%2]+1) && d, [0, 0]).indexOf(1)))((readline() && readline()).toString().split(/\\s+/).map(Number)))"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(' ').map(el => parseInt(el)),\n even=0, odd=0, index=0;\nfor (var i = 0; i < arr.length; i++) {\n if (arr[i] % 2 == 0) {\n even++;\n } else {\n odd++;\n }\n}\nif (even < odd) {\n for (var j = 0; j < arr.length; j++) {\n if(arr[j] % 2 == 0){\n index = j;\n }\n } \n} else {\n for (var a = 0; a < arr.length; a++) {\n if(arr[a] % 2 != 0){\n index = a;\n }\n }\n}\nprint(index+1);"}], "negative_code": [{"source_code": "var n = +readline();\nvar a = readline().split(' ').map(function(x) {return (+x) % 2;});\nvar sum = a.reduce(function(a, b) {return a + b});\nvar lookFor = sum == 1 ? 1 : 0;\nfor (var i = 0; i < n; i ++) if (a[i] == lookFor) print(i + 1);"}, {"source_code": "var n = readline(); \nvar s = readline().split(' ');\n\nvar i = 0;\n\nvar odd_n = 0;\nvar odd_x = 0;\nvar evenn = 0;\nvar evenx = 0;\n\nfor(i=0; i= 3)\n\tinput = readline();\n\n//turn the string to array of intgers\ninput = input.split(' ').map((str) => {\n\treturn parseInt(str);\n});\n\nvar index = 0; //index counter\nvar firstNum = input[0]; //first num of the array\n\n//return as soon as the condition is true\ninput.some((num) => {\n\tindex++;\n\tif (firstNum % 2 === 0)\n\t\treturn num % 2 !== 0;\n\telse\n\t\treturn num % 2 === 0;\n});\n\nprint(index);"}, {"source_code": "var n=readline()\nvar arr=readline()\nvar ev=0,od=0,pose=-1,poso=-1\nfor(var i=0;i {\n inputs.push(lineInput);\n})\n\n// Read Inputs\nrl.on('close', () => {\n const n = parseInt(inputs[0]);\n const numbers = inputs[1].split(' ').map(number => parseInt(number));\n let numberIdx = 1;\n let base = Math.ceil(numbers[0] % 2);\n\n for (let i = 0; i < numbers.length; i++) {\n\n if (Math.ceil(numbers[i] % 2) != base)\n return console.log(numberIdx);\n\n numberIdx++;\n }\n\n});"}, {"source_code": "const input = [];\n\nfunction splitAndParseInt(line) {\n return line.split(\" \").map((x) => parseInt(x));\n}\n\nconst readLine = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nreadLine.on(\"line\", (line) => {\n input.push(line);\n});\n\nreadLine.on(\"close\", () => {\n const nums = splitAndParseInt(input[1]);\n let cntOdd = (nums[0] % 2 !== 0) + (nums[1] % 2 !== 0) + (nums[2] % 2 !== 0);\n\n for (let i = 0; i < nums.length; i += 1) {\n let n = nums[i];\n if (cntOdd === 1 && n % 2 !== 0) {\n console.log(i + 1);\n return;\n } else if (cntOdd > 1 && n % 2 === 0) {\n console.log(i + 1);\n return;\n }\n }\n});\n"}, {"source_code": " var n=readline()\n var a=readline()\n var e=0,o=0,pose=0,poso=0;\n var arr=new Array();\n var st=\"\";\n for(var i=0;i 1 + d.findIndex(x => x % 2 == d.reduce((d, x) => d.splice(x%2, 1, d[x%2]+1) && d, [0, 0]).indexOf(1)))((readline() && readline()).toString().split(/\\s+/).slice(1).map(Number)))"}, {"source_code": "'use strict';\n\nconst getArray = (array_1, array_2) => {\n if (array_1.length === 1) {\n return array_1;\n }\n \n return array_2;\n}\n\nconst filterOddNumbers = number => number % 2;\nconst filterEvenNumbers = number => number % 2 === 0;\n\nconst n = readline(),\n array = readline().split(' ').map(value => parseInt(value));\n\nwrite(array.indexOf(getArray(\n array.map(filterOddNumbers),\n array.map(filterEvenNumbers)\n)[0]) + 1);"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar nc =0; c=0;\n\tfor (var i=0; inc? print(nc):print(c);"}, {"source_code": "var n = readline();\nvar str = readline().split(\" \");\nvar chet = 0;\nif ((Number(str[0])+Number(str[1]))%2==0||(Number(str[1])+Number(str[2]))%2==0)\n\tchet=1;\n\tfor (var i=0; inc? print(nc):print(c); "}, {"source_code": "var x=parseInt(readline());\nvar arr=readline().split(' ');\nvar e=0,ev,od,o=0;\nfor(var i=0;i0) \n{print(parseInt(ev+1));\n}else{\n print(parseInt(od+1));\n}"}, {"source_code": "var x=parseInt(readline());\nvar arr=readline().split(' ');\nvar e=0,ev,od;\nfor(var i=0;i0) \n{print(parseInt(ev+1));\n}else{\n print(parseInt(od+1));\n}"}, {"source_code": "var n = Number(readline());\nvar s = readline().split(\" \");\n\nvar k = 0, k1 = 0, res = 0, res1 = 0;\nfor (var i = 1; i 1\n \n if (numbers[j] % div !== 0 ) {\n \n redundantCount++;\n redundantStack.push(j);\n } else {\n var specialInd = j;\n }\n }\n // print('redundantCount : ', redundantCount);\n if (redundantCount === 1) {\n var lastInd = redundantStack.length - 1;\n print(redundantStack[lastInd] + 1); // answer\n return;\n } else if (redundantCount === numbers.length - 1) {\n print(redundantStack[specialInd]); // answer\n return;\n }\n}\n\n \n}"}, {"source_code": "var n = parseInt(readline());\nvar arr = readline().split(\" \").map(value => +value);\nvar odd; \nif (arr[0] % 2 === 0 && arr[1] % 2 === 0) odd = 1;\nif (arr[0] % 2 === 1 && arr[1] % 2 === 1) odd = 0;\nif (arr[0] % 2 !== arr[1] % 2) print((arr[0] % 2 === arr[2] % 2) ? arr[1] : arr[0])\nelse {\n\twhile(arr[n - 1] % 2 !== odd) n--;\n\tprint(n);\n}"}, {"source_code": "var n = parseInt(readline());\nvar array = readline().split(' ').map(Number);\nvar even = [];\nvar odd = [];\n\nfor (var i = 0; i < 3; i++) {\n\tif (array[i] % 2 == 0) {\n\t\teven.push(array[i]);\n\t} \n\telse {\n\t\todd.push(array[i]);\n\t}\n}\n\nprint (odd.length == 1 ? odd[0] : even[0]);"}, {"source_code": "var n = parseInt(readline());\nvar array = readline().split(' ').map(Number);\nvar even = [];\nvar odd = [];\n\nfor (var i = 0; i < 3; i++) {\n\tif (array[i] % 2 == 0) {\n\t\teven.push(i);\n\t} \n\telse {\n\t\todd.push(i);\n\t}\n}\n\nprint (odd.length == 1 ? odd[0] + 1 : even[0] + 1);"}, {"source_code": "readline();\nvar prm = readline().split(\" \").map(a =>+a);var s = 0;\n\n\nfor(var i=0;i= 0; i--) {\r\n if (i < n - 1) {\r\n if (n - i - 1 & 1) {\r\n r[i] = a[i] - r[i + 1];\r\n } else {\r\n r[i] = a[i] - r[i + 1];\r\n }\r\n }\r\n if (i & 1) {\r\n if (!odd.has(r[i])) odd.set(r[i], []);\r\n odd.get(r[i]).push(i);\r\n } else {\r\n if (!even.has(r[i])) even.set(r[i], []);\r\n even.get(r[i]).push(i);\r\n }\r\n }\r\n for (let [key, arr] of odd) arr.reverse();\r\n for (let [key, arr] of even) arr.reverse();\r\n const find = arr => {\r\n while (arr.length && arr[arr.length - 1] > right) arr.pop();\r\n if (arr.length && arr[arr.length - 1] > left) {\r\n const ans = arr[arr.length - 1];\r\n pre = r[ans];\r\n sum = d = 0;\r\n res.push([pl, left], [ans, right]);\r\n right = ans - 1;\r\n pl = left + 1;\r\n return true;\r\n }\r\n return false;\r\n };\r\n let sum = 0,\r\n pre = 0,\r\n res = [];\r\n let left = 0,\r\n right = n - 1,\r\n d = 0,\r\n pl = 0;\r\n for (; left <= right; left++) {\r\n if (d & 1) {\r\n sum -= a[left];\r\n } else {\r\n sum += a[left];\r\n }\r\n if (sum === 0) {\r\n res.push([pl, left]);\r\n pl = left + 1;\r\n sum = d = 0;\r\n continue;\r\n }\r\n d++;\r\n if (right & 1) {\r\n let t = -sum - pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n } else {\r\n let t = -sum - pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n res.sort((a, b) => a[0] - b[0]);\r\n const check = arr => {\r\n var _arr$, _arr;\r\n if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i][0] !== arr[i - 1][1] + 1) return false;\r\n }\r\n return true;\r\n };\r\n if (!check(res)) return -1;\r\n return `${res.length}\\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\\n')}`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n // if (!sum) {\n // return `1\\n1 ${n}`\n // }\n const t = sum > 0 ? 1 : -1\n let k = sum / t\n if (k & 1) return -1\n k /= 2\n// console.log('k', k)\n const use = Array(n)\n const ans = []\n for (let i = 1; i < arr.length; i++) {\n if (k > 0 && arr[i] === t && !use[i - 1]) {\n use[i - 1] = 1\n use[i] = 1\n // ans.push([i - 1, i])\n ans.push([i, i + 1])\n k--\n }\n }\n if (k > 0) return -1\n for (let i = 0; i < arr.length; i++) {\n if (!use[i]) {\n ans.push([i + 1, i + 1])\n }\n }\n ans.sort((a, b) => a[0] - b[0])\n return ans.length + '\\n' + ans.map(x => x.join(' ')).join('\\n')\n}\n"}], "negative_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n // if (!sum) {\n // return `1\\n1 ${n}`\n // }\n const t = sum > 0 ? 1 : -1\n let k = sum / t\n if (k & 1) return -1\n k /= 2\n// console.log('k', k)\n const use = Array(n)\n const ans = []\n for (let i = 1; i < arr.length; i++) {\n if (k > 0 && arr[i] === t && !use[i - 1]) {\n use[i - 1] = 1\n use[i] = 1\n // ans.push([i - 1, i])\n ans.push(`${i} ${i + 1}`)\n k--\n }\n }\n if (k > 0) return -1\n for (let i = 0; i < arr.length; i++) {\n if (!use[i]) {\n ans.push(`${i + 1} ${i + 1}`)\n }\n }\n ans.unshift(ans.length)\n return ans.join('\\n')\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n // if (!sum) {\n // return `1\\n1 ${n}`\n // }\n const t = sum > 1 ? 1 : -1\n let k = sum / t\n if (k & 1) return -1\n k /= 2\n// console.log('k', k)\n const use = Array(n)\n const ans = []\n for (let i = 1; i < arr.length; i++) {\n if (k > 0 && arr[i] === t && !use[i - 1]) {\n use[i - 1] = 1\n use[i] = 1\n // ans.push([i - 1, i])\n ans.push(`${i} ${i + 1}`)\n k--\n }\n }\n if (k > 0) return -1\n for (let i = 0; i < arr.length; i++) {\n if (!use[i]) {\n ans.push(`${i + 1} ${i + 1}`)\n }\n }\n ans.unshift(ans.length)\n return ans.join('\\n')\n}\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const sum = arr.reduce((s, x) => s + x, 0)\r\n if (!sum) {\r\n return `1\\n1 ${n}`\r\n }\r\n const t = sum > 1 ? 1 : -1\r\n let k = sum / t\r\n if (k & 1) return -1\r\n k /= 2\r\n// console.log('k', k)\r\n const use = Array(n)\r\n const ans = []\r\n for (let i = 1; i < arr.length; i++) {\r\n if (k > 0 && arr[i] === t && !use[i - 1]) {\r\n use[i - 1] = 1\r\n use[i] = 1\r\n // ans.push([i - 1, i])\r\n ans.push(`${i} ${i + 1}`)\r\n k--\r\n }\r\n }\r\n if (k > 0) return -1\r\n for (let i = 0; i < arr.length; i++) {\r\n if (!use[i]) {\r\n ans.push(`${i + 1} ${i + 1}`)\r\n }\r\n }\r\n ans.unshift(ans.length)\r\n return ans.join('\\n')\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const arr = lines[l++].trim().split(' ').map(Number)\r\n output[i] = solve(n, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, arr) {\r\n const sum = arr.reduce((s, x) => s + x, 0)\r\n if (!sum) {\r\n return '1\\n1 n'\r\n }\r\n const t = sum > 1 ? 1 : -1\r\n let k = sum / t\r\n if (k & 1) return -1\r\n k /= 2\r\n// console.log('k', k)\r\n const use = Array(n)\r\n const ans = []\r\n for (let i = 1; i < arr.length; i++) {\r\n if (k > 0 && arr[i] === t && !use[i - 1]) {\r\n use[i - 1] = 1\r\n use[i] = 1\r\n // ans.push([i - 1, i])\r\n ans.push(`${i} ${i + 1}`)\r\n k--\r\n }\r\n }\r\n if (k > 0) return -1\r\n for (let i = 0; i < arr.length; i++) {\r\n if (!use[i]) {\r\n ans.push(`${i + 1} ${i + 1}`)\r\n }\r\n }\r\n ans.unshift(ans.length)\r\n return ans.join('\\n')\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n const sum = arr.reduce((s, x) => s + x, 0)\n if (!sum) {\n return '1\\n1 n'\n }\n const t = sum > 1 ? 1 : -1\n let k = sum / t\n if (k & 1) return -1\n k /= 2\n const use = Array(n)\n const ans = []\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] === t && !use[i - 1]) {\n use[i - 1] = 1\n use[i] = 1\n // ans.push([i - 1, i])\n ans.push(`${i} ${i + 1}`)\n k--\n }\n }\n if (k > 0) return -1\n for (let i = 0; i < arr.length; i++) {\n if (!use[i]) {\n ans.push(`${i + 1} ${i + 1}`)\n }\n }\n ans.unshift(ans.length)\n return ans.join('\\n')\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n const l = [a[0]];\r\n for (let i = 1; i < n; i++) {\r\n if (i & 1) {\r\n l[i] = l[i - 1] - a[i];\r\n } else {\r\n l[i] = l[i - 1] + a[i];\r\n }\r\n }\r\n const r = [];\r\n r[n - 1] = a[n - 1];\r\n const odd = new Map(),\r\n even = new Map();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i < n - 1) {\r\n if (n - i - 1 & 1) {\r\n r[i] = a[i] - r[i + 1];\r\n } else {\r\n r[i] = a[i] - r[i + 1];\r\n }\r\n }\r\n if (i & 1) {\r\n if (!odd.has(r[i])) odd.set(r[i], []);\r\n odd.get(r[i]).push(i);\r\n } else {\r\n if (!even.has(r[i])) even.set(r[i], []);\r\n even.get(r[i]).push(i);\r\n }\r\n }\r\n for (let [key, arr] of odd) arr.reverse();\r\n for (let [key, arr] of even) arr.reverse();\r\n const find = arr => {\r\n while (arr.length && arr[arr.length - 1] > right) arr.pop();\r\n if (arr.length && arr[arr.length - 1] > left) {\r\n const ans = arr[arr.length - 1];\r\n pre = r[ans];\r\n sum = d = 0;\r\n res.push([pl, left], [ans, right]);\r\n right = ans - 1;\r\n pl = left + 1;\r\n return true;\r\n }\r\n return false;\r\n };\r\n let sum = 0,\r\n pre = 0,\r\n res = [];\r\n let left = 0,\r\n right = n - 1,\r\n d = 0,\r\n pl = 0;\r\n for (; left < right; left++) {\r\n if (d & 1) {\r\n sum -= a[left];\r\n } else {\r\n sum += a[left];\r\n }\r\n d++;\r\n if (right & 1) {\r\n let t = -sum - pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n } else {\r\n let t = -sum - pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n res.sort((a, b) => a[0] - b[0]);\r\n const check = arr => {\r\n var _arr$, _arr;\r\n if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i][0] !== arr[i - 1][1] + 1) return false;\r\n }\r\n return true;\r\n };\r\n if (!check(res)) return -1;\r\n return `${res.length}\\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\\n')}`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const n = rn(),\r\n a = rns();\r\n const l = [a[0]];\r\n for (let i = 1; i < n; i++) {\r\n if (i & 1) {\r\n l[i] = l[i - 1] - a[i];\r\n } else {\r\n l[i] = l[i - 1] + a[i];\r\n }\r\n }\r\n const r = [];\r\n r[n - 1] = a[n - 1];\r\n const odd = new Map(),\r\n even = new Map();\r\n for (let i = n - 1; i >= 0; i--) {\r\n if (i < n - 1) {\r\n if (n - i - 1 & 1) {\r\n r[i] = a[i] - r[i + 1];\r\n } else {\r\n r[i] = a[i] - r[i + 1];\r\n }\r\n }\r\n if (i & 1) {\r\n if (!odd.has(r[i])) odd.set(r[i], []);\r\n odd.get(r[i]).push(i);\r\n } else {\r\n if (!even.has(r[i])) even.set(r[i], []);\r\n even.get(r[i]).push(i);\r\n }\r\n }\r\n for (let [key, arr] of odd) arr.reverse();\r\n for (let [key, arr] of even) arr.reverse();\r\n const find = arr => {\r\n while (arr.length && arr[arr.length - 1] > right) arr.pop();\r\n if (arr.length && arr[arr.length - 1] > left) {\r\n const ans = arr[arr.length - 1];\r\n pre = r[ans];\r\n sum = d = 0;\r\n res.push([pl, left], [ans, right]);\r\n right = ans - 1;\r\n pl = left + 1;\r\n return true;\r\n }\r\n return false;\r\n };\r\n let sum = 0,\r\n pre = 0,\r\n res = [];\r\n let left = 0,\r\n right = n - 1,\r\n d = 0,\r\n pl = 0;\r\n for (; left < right; left++) {\r\n if (d & 1) {\r\n sum -= a[left];\r\n } else {\r\n sum += a[left];\r\n }\r\n d++;\r\n if (right & 1) {\r\n let t = -sum - pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n } else {\r\n let t = -sum - pre;\r\n if (even.has(t)) {\r\n if (find(even.get(t))) {\r\n continue;\r\n }\r\n }\r\n t = -sum + pre;\r\n if (odd.has(t)) {\r\n if (find(odd.get(t))) {\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n res.sort((a, b) => a[0] - b[0]);\r\n const check = arr => {\r\n var _arr$, _arr;\r\n if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;\r\n for (let i = 1; i < arr.length; i++) {\r\n if (arr[i][0] !== arr[i - 1][1] + 1) return false;\r\n }\r\n return true;\r\n };\r\n if (!check(res)) return -1;\r\n return `${res.length}\\n${res.map(arr => arr.join(' ')).join('\\n')}`;\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n var _solve;\r\n const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}], "src_uid": "b87a90f2b4822e59d66b06886a5facad"} {"source_code": "let data = '';\nprocess.stdin.on('data',c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet n = parseInt(line[0],10);\n\tlet a = line[1].split(' ').map(i => parseInt(i,10));\n\tlet m = parseInt(line[2],10);\n\tlet q = line[3].split(' ').map(i => parseInt(i,10));\n\tlet r = [];\n\tlet s = a.reduce((w, c) => w + c);\n\ta.sort((a, b) => b - a);\n\tfor(let i of q){\n\t\tr.push(s - a[i-1]);\n\t}\n\tconsole.log(r.join('\\n'));\n};\n\nprocess.stdin.on('end',solution);\n", "positive_code": [{"source_code": "let data = '';\nprocess.stdin.on('data',c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet n = Number(line.shift());\n\tlet a = line.shift().split(' ').map(i => Number(i));\n\tlet m = Number(line.shift());\n\tlet q = line.shift().split(' ').map(i => Number(i));\n\tlet r = [];\n\tlet s = a.reduce((w, c) => w + c);\n\ta.sort((a, b) => b - a);\n\tfor(let i of q){\n\t\tr.push(s - a[i-1]);\n\t}\n\tconsole.log(r.join('\\n'));\n};\n\nprocess.stdin.on('end',solution);\n"}, {"source_code": "let data = '';\nprocess.stdin.on('data',c => data += c);\n\nconst solution = () => {\n\tlet line = data.split('\\n');\n\tlet n = parseInt(line.shift(),10);\n\tlet a = line.shift().split(' ').map(i => parseInt(i,10));\n\tlet m = parseInt(line.shift(),10);\n\tlet q = line.shift().split(' ').map(i => parseInt(i,10));\n\tlet r = [];\n\tlet s = a.reduce((w, c) => w + c);\n\ta.sort((a, b) => b - a);\n\tfor(let i of q){\n\t\tr.push(s - a[i-1]);\n\t}\n\tconsole.log(r.join('\\n'));\n};\n\nprocess.stdin.on('end',solution);\n"}], "negative_code": [], "src_uid": "c1608f6f71cac56690e31aa130c1990e"} {"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst findIndex = (N, M, A, target) => {\r\n for (let r = 0; r < N; r += 1) {\r\n for (let c = 0; c < M; c += 1) {\r\n if (A[r][c] == target) {\r\n return [r, c];\r\n }\r\n }\r\n }\r\n\r\n return [-1, -1];\r\n};\r\n\r\nconst getNeibs = (N, M, A, R, C) => {\r\n const neibs = [];\r\n for (const [nr, nc] of [\r\n [R + 1, C],\r\n [R - 1, C],\r\n [R, C + 1],\r\n [R, C - 1],\r\n ]) {\r\n if (0 <= nr && nr < N && 0 <= nc && nc < M && A[nr][nc] == \".\") {\r\n neibs.push([nr, nc]);\r\n }\r\n }\r\n\r\n return neibs;\r\n};\r\n\r\nconst solve = (N, M, A) => {\r\n const target = findIndex(N, M, A, \"L\");\r\n\r\n const q = [target];\r\n const ans = Array.from(A, (row) => [...row]);\r\n\r\n while (q.length > 0) {\r\n const [r, c] = q.pop();\r\n for (const [nr, nc] of getNeibs(N, M, ans, r, c)) {\r\n const nbs = getNeibs(N, M, ans, nr, nc);\r\n if (nbs.length <= 1) {\r\n ans[nr][nc] = \"+\";\r\n q.push([nr, nc]);\r\n }\r\n }\r\n }\r\n\r\n return ans.map((row) => row.join(\"\")).join(\"\\n\");\r\n};\r\n\r\nconst main = () => {\r\n // console.log(readline());\r\n const T = parseInt(readline());\r\n const ans = [];\r\n for (let t = 0; t < T; t += 1) {\r\n const [N, M] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n const A = [];\r\n for (let r = 0; r < N; r += 1) {\r\n A.push([...readline().trim()]);\r\n }\r\n ans.push(solve(N, M, A));\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\n// main();\r\n", "positive_code": [{"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim().split(''))\n l += n\n output[i] = solve(n, m, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n let row = 0\n let col = 0\n let found = false\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] === 'L') {\n found = true\n row = i\n col = j\n break\n }\n }\n if (found) break\n }\n// console.log(grid, row, col)\n\n const visited = {}\n const connected = {}\n connected[key(row, col)] = 1\n const q = [[row, col, -1, -1]]\n const ans = []\n while (q.length) {\n const [i, j, pi, pj] = q.shift()\n const k = key(i, j)\n // if (visited[k]) continue\n // visited[k] = 1\n\n const tq = []\n check(n, m, grid, visited, tq, i + 1, j, pi, pj)\n check(n, m, grid, visited, tq, i - 1, j, pi, pj)\n check(n, m, grid, visited, tq, i, j + 1, pi, pj)\n check(n, m, grid, visited, tq, i, j - 1, pi, pj)\n// console.log(i, j, tq.length)\n if (tq.length <= 1 || grid[i][j] === 'L') {\n // connected[k] = 1\n // ans.push([i, j])\n // if (grid[i][j] === '.') {\n grid[i][j] = '+'\n // }\n tq.forEach(([ci, cj]) => {\n // if (!visited[key(ci, cj)]) {\n q.push([ci, cj, i, j])\n // }\n })\n }\n }\n\n grid[row][col] = 'L'\n // ans.forEach(([i, j]) => {\n // grid[i][j] = '+'\n // })\n return grid.map(r => r.join('')).join('\\n')\n}\nfunction check(n, m, grid, visited, tq, i, j, pi, pj) {\n // if (i === pi && j === pj) return false\n if (i < 0 || i >= n || j < 0 || j >= m\n || grid[i][j] !== '.') return false\n // || '#+'.indexOf(grid[i][j]) >= 0) return false\n tq.push([i, j])\n\n return true\n}\nfunction key(i, j) {\n return i + ',' + j\n}\n"}, {"source_code": "const fs = require(\"fs\");\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nfs.readFile(\"input.txt\", \"utf8\", (err, data) => {\r\n if (err) {\r\n console.error(err);\r\n return;\r\n }\r\n inputString = data\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst findIndex = (N, M, A, target) => {\r\n for (let r = 0; r < N; r += 1) {\r\n for (let c = 0; c < M; c += 1) {\r\n if (A[r][c] == target) {\r\n return [r, c];\r\n }\r\n }\r\n }\r\n\r\n return [-1, -1];\r\n};\r\n\r\nconst getNeibs = (N, M, A, R, C) => {\r\n const neibs = [];\r\n for (const [nr, nc] of [\r\n [R + 1, C],\r\n [R - 1, C],\r\n [R, C + 1],\r\n [R, C - 1],\r\n ]) {\r\n if (0 <= nr && nr < N && 0 <= nc && nc < M && A[nr][nc] == \".\") {\r\n neibs.push([nr, nc]);\r\n }\r\n }\r\n\r\n return neibs;\r\n};\r\n\r\nconst solve = (N, M, A) => {\r\n const target = findIndex(N, M, A, \"L\");\r\n\r\n const q = [target];\r\n const ans = Array.from(A, (row) => [...row]);\r\n\r\n while (q.length > 0) {\r\n const [r, c] = q.pop();\r\n for (const [nr, nc] of getNeibs(N, M, ans, r, c)) {\r\n const nbs = getNeibs(N, M, ans, nr, nc);\r\n if (nbs.length <= 1) {\r\n ans[nr][nc] = \"+\";\r\n q.push([nr, nc]);\r\n }\r\n }\r\n }\r\n\r\n return ans.map((row) => row.join(\"\")).join(\"\\n\");\r\n};\r\n\r\nconst main = () => {\r\n // console.log(readline());\r\n const T = parseInt(readline());\r\n const ans = [];\r\n for (let t = 0; t < T; t += 1) {\r\n const [N, M] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n const A = [];\r\n for (let r = 0; r < N; r += 1) {\r\n A.push([...readline().trim()]);\r\n }\r\n ans.push(solve(N, M, A));\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\n// main();\r\n"}], "negative_code": [{"source_code": "\"use strict\";\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n console.log(\"on data\", inputString);\r\n});\r\n\r\nprocess.stdin.on(\"end\", (_) => {\r\n inputString = inputString\r\n .trim()\r\n .split(\"\\n\")\r\n .map((string) => {\r\n return string.trim();\r\n });\r\n\r\n console.log(\"on end\", inputString);\r\n\r\n main();\r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nconst findIndex = (N, M, A, target) => {\r\n for (let r = 0; r < N; r += 1) {\r\n for (let c = 0; c < M; c += 1) {\r\n if (A[r][c] == target) {\r\n return [r, c];\r\n }\r\n }\r\n }\r\n\r\n return [-1, -1];\r\n};\r\n\r\nconst getNeibs = (N, M, A, R, C) => {\r\n const neibs = [];\r\n for (const [nr, nc] of [\r\n [R + 1, C],\r\n [R - 1, C],\r\n [R, C + 1],\r\n [R, C - 1],\r\n ]) {\r\n if (0 <= nr && nr < N && 0 <= nc && nc < M && A[nr][nc] == \".\") {\r\n neibs.push([nr, nc]);\r\n }\r\n }\r\n\r\n return neibs;\r\n};\r\n\r\nconst solve = (N, M, A) => {\r\n const target = findIndex(N, M, A, \"L\");\r\n\r\n const q = [target];\r\n const ans = Array.from(A, (row) => [...row]);\r\n\r\n while (q.length > 0) {\r\n const [r, c] = q.pop();\r\n for (const [nr, nc] of getNeibs(N, M, ans, r, c)) {\r\n const nbs = getNeibs(N, M, ans, nr, nc);\r\n if (nbs.length <= 1) {\r\n ans[nr][nc] = \"+\";\r\n q.push([nr, nc]);\r\n }\r\n }\r\n }\r\n\r\n return ans.map((row) => row.join(\"\")).join(\"\\n\");\r\n};\r\n\r\nconst main = () => {\r\n // console.log(readline());\r\n const T = parseInt(readline());\r\n const ans = [];\r\n for (let t = 0; t < T; t += 1) {\r\n const [N, M] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n const A = [];\r\n for (let r = 0; r < N; r += 1) {\r\n A.push([...readline().trim()]);\r\n }\r\n ans.push(solve(N, M, A));\r\n }\r\n console.log(ans.join(\"\\n\"));\r\n};\r\n\r\n// main();\r\n"}, {"source_code": "// import * as readline from 'node:readline/promises';\r\n\r\n\r\nconst findIndex = (N, M, A, target) => {\r\n for (let r = 0; r < N; r += 1) {\r\n for (let c = 0; c < M; c += 1) {\r\n if (A[r][c] == target) {\r\n return [r, c];\r\n }\r\n }\r\n }\r\n\r\n return [-1, -1];\r\n}\r\n\r\nconst getNeibs = (N, M, A, R, C) => {\r\n const neibs = [];\r\n for (const [nr, nc] of [[R+1, C], [R-1, C], [R, C+1], [R, C-1]]) {\r\n if (0 <= nr && nr < N && 0 <= nc && nc < M && A[nr][nc] == '.') {\r\n neibs.push([nr, nc]);\r\n }\r\n }\r\n\r\n return neibs;\r\n}\r\n\r\nconst solve = (N, M, A) => {\r\n const target = findIndex(N, M, A, 'L');\r\n\r\n const q = [target];\r\n const ans = Array.from(A, row => [...row]);\r\n\r\n while (q.length > 0) {\r\n const [r, c] = q.pop();\r\n for (const [nr, nc] of getNeibs(N, M, ans, r, c)) {\r\n const nbs = getNeibs(N, M, ans, nr, nc);\r\n if (nbs.length <= 1) {\r\n ans[nr][nc] = '+';\r\n q.push([nr, nc]);\r\n }\r\n\r\n }\r\n }\r\n\r\n return ans.map(row => row.join('')).join('\\n')\r\n};\r\n\r\nconst main = () => {\r\n const T = parseInt(readline());\r\n const ans = [];\r\n for (let t = 0; t < T; t += 1) {\r\n const [N, M] = readline()\r\n .split(\" \")\r\n .map((x) => parseInt(x));\r\n const A = [];\r\n for (let r = 0; r < N; r += 1) {\r\n A.push([...readline().trim()]);\r\n }\r\n ans.append(solve(N, M, A));\r\n }\r\n print(ans.join(\"\\n\"));\r\n};\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim().split(''))\n l += n\n output[i] = solve(n, m, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n let row = 0\n let col = 0\n let found = false\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] === 'L') {\n found = true\n row = i\n col = j\n break\n }\n }\n if (found) break\n }\n// console.log(grid, row, col)\n\n const visited = {}\n const connected = {}\n connected[key(row, col)] = 1\n const q = [[row, col, -1, -1]]\n const ans = []\n while (q.length) {\n const [i, j, pi, pj] = q.shift()\n const k = key(i, j)\n if (visited[k]) continue\n visited[k] = 1\n\n const tq = []\n check(n, m, grid, visited, tq, i + 1, j, pi, pj)\n check(n, m, grid, visited, tq, i - 1, j, pi, pj)\n check(n, m, grid, visited, tq, i, j + 1, pi, pj)\n check(n, m, grid, visited, tq, i, j - 1, pi, pj)\n\n if (tq.length <= 1) {\n // connected[k] = 1\n // ans.push([i, j])\n if (grid[i][j] === '.') {\n grid[i][j] = '+'\n }\n }\n tq.forEach(([ci, cj]) => {\n if (!visited[key(ci, cj)]) {\n q.push([ci, cj, i, j])\n }\n })\n }\n\n // ans.forEach(([i, j]) => {\n // grid[i][j] = '+'\n // })\n return grid.map(r => r.join('')).join('\\n')\n}\nfunction check(n, m, grid, visited, tq, i, j, pi, pj) {\n // if (i === pi && j === pj) return false\n if (i < 0 || i >= n || j < 0 || j >= m || grid[i][j] !== '.') return false\n tq.push([i, j])\n\n return true\n}\nfunction key(i, j) {\n return i + ',' + j\n}\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, m] = lines[l++].trim().split(' ').map(Number)\n const grid = lines.slice(l, l + n).map(str => str.trim().split(''))\n l += n\n output[i] = solve(n, m, grid)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, m, grid) {\n let row = 0\n let col = 0\n let found = false\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] === 'L') {\n found = true\n row = i\n col = j\n break\n }\n }\n if (found) break\n }\n// console.log(grid, row, col)\n\n const visited = {}\n const connected = {}\n connected[key(row, col)] = 1\n const q = [[row, col, -1, -1]]\n const ans = []\n while (q.length) {\n const [i, j, pi, pj] = q.shift()\n const k = key(i, j)\n if (visited[k]) continue\n visited[k] = 1\n\n const tq = []\n check(n, m, grid, visited, tq, i + 1, j, pi, pj)\n check(n, m, grid, visited, tq, i - 1, j, pi, pj)\n check(n, m, grid, visited, tq, i, j + 1, pi, pj)\n check(n, m, grid, visited, tq, i, j - 1, pi, pj)\n\n if (connected[key(pi, pj)] && tq.length <= 1) {\n connected[k] = 1\n ans.push([i, j])\n }\n tq.forEach(([ci, cj]) => {\n if (!visited[key(ci, cj)]) {\n q.push([ci, cj, i, j])\n }\n })\n }\n\n ans.forEach(([i, j]) => {\n grid[i][j] = '+'\n })\n return grid.map(r => r.join('')).join('\\n')\n}\nfunction check(n, m, grid, visited, tq, i, j, pi, pj) {\n if (i === pi && j === pj) return false\n if (i < 0 || i >= n || j < 0 || j >= m || grid[i][j] === '#') return false\n tq.push([i, j])\n\n return true\n}\nfunction key(i, j) {\n return i + ',' + j\n}\n"}], "src_uid": "fa82a5160696616af784b5488c9f69f6"} {"source_code": " var tmp = readline().split(' ').map(function(x) { return parseInt(x)});\n var n = tmp[0];\n var k = tmp[1];\n var d = readline().split(' ').map(function(x) { return x === 'YES'; });\n var names = [];\n for(var i = 0; i < k; i += 1) {\n names[i] = (i + 1).toString().split('').map(function(x) { return parseInt(x); }).map(function(x) { return String.fromCharCode(65 + x); }).join('').toLowerCase();\n }\n names = names.map(function(string) {\n return string.charAt(0).toUpperCase() + string.slice(1);\n });\n var res = [];\n var it = 0;\n for(var i = 0; i < k - 1; i += 1) {\n res.push(names[it]);\n it += 1;\n it %= k;\n }\n for(var i = k - 1; i < n; i += 1) {\n if(d[i - k + 1]) {\n res.push(names[it]);\n it += 1;\n it %= k;\n } else {\n var tmp = names[it];\n names[it] = names[(it + 1) % k];\n names[(it + 1) % k] = tmp;\n res.push(names[it]);\n it += 1;\n it %= k;\n }\n }\n print(res.join(' '));", "positive_code": [{"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\nvar names = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',\n'Aa','Ba','Ca','Da','Ea','Fa','Ga','Ha','Ia','Ja','Ka','La','Ma','Na','Oa','Pa','Qa','Ra','Sa','Ta','Ua','Va','Wa','Xa','Ya','Za',\n'Ab','Bb','Cb','Db','Eb','Fb','Gb','Hb','Ib','Jb','Kb','Lb','Mb','Nb','Ob','Pb','Qb','Rb','Sb','Tb','Ub','Vb','Wb','Xb','Yb','Zb']\n\nvar ns = ints(),\n\tn = ns[0],\n\tk = ns[1],\n\ti = 0,\n\tj = 0,\n\tcount = 1,\n\twords = [],\n\tnotes = readline().split(' ').map(function(w) {\n\t\treturn w == 'YES'\n\t})\n\nfor(i = 0; i < k - 1; i ++)\n\twords[i] = i\n\ncount = i\nwhile (i < n) {\n\tif (notes[j]) {\n\t\twords[i] = count\n\t\tcount ++\n\t} else {\n\t\twords[i] = words[i - k + 1]\n\t}\n\ti ++\n\tj ++\n}\n\nprint(words.map(function(n) { return names[n] }).join(' '))"}, {"source_code": "var input = readline().split(' ').map(Number);\n\nvar n = input[0]; //number of soldiers\nvar k = input[1]; //size of each group\n\nvar notes = readline().split(' ').map(String);\n\n// Let's create 52 unique soldier names\nvar names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Aa', 'Ba', 'Ca', 'Da', 'Ea', 'Fa', 'Ga', 'Ha', 'Ia', 'Ja', 'Ka', 'La', 'Ma', 'Na', 'Oa', 'Pa', 'Qa', 'Ra', 'Sa', 'Ta', 'Ua', 'Va', 'Wa', 'Xa', 'Ya', 'Za'];\n\nvar soldiers = [];\nvar s_count = 0;\nvar n_count = 0;\nvar l = 0;\n\n//Ititial Group\nif (notes[0] == 'YES') {\n\tfor (var j = 0; j < k; j++) {\n\t\tsoldiers[s_count] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t}\n} else if (notes[0] == 'NO') {\n\tsoldiers[s_count + k - 1] = names[n_count];\n\twhile (l < k - 1) {\n\t\tsoldiers[s_count] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t\tl ++;\n\t}\n\ts_count ++;\n}\n\n//then attach either the first name of the group or the next name in the name list to the end for each group.\n\nfor (var i = 1; i < n - k + 1; i++) {\n\tif (notes[i] == 'YES') {\n\t\tsoldiers[s_count] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t} else if (notes[i] == 'NO') {\n\t\tsoldiers[s_count] = soldiers[s_count - k + 1];\n\t\ts_count ++;\n\t}\n}\n\nvar output = soldiers.join(\" \");\n\nprint(output);"}, {"source_code": "var a = readline().trim().split(\" \");\nvar n = +a[0], k = +a[1];\nvar effective = readline().trim().split(\" \").map((val) => {\n return (val == \"NO\" ? false : true);\n});\nvar big_letters = \"QWERTYUIOPASDFGHJKLZXCVBNM\";\nvar small_letters = \"qwertyuiopasdfghjklzxcvbnm\";\n\nvar names_i = 0;\nvar names = [];\nfor(var i = 0; i < 3; i++){\n var myname = big_letters[i];\n for(var j = 0; j < 26; j++){\n names[names_i++] = myname + small_letters[j];\n }\n}\n\nvar soldier_names = [];\nvar name_link = 0;\nvar solider_has_name = [];\n\nfor(var i = 0; i < n; i++){\n solider_has_name[i] = false;\n}\n\nfor(var i = 0; i < n - k + 1; i++){\n if(effective[i] === true){\n for(var j = 0; j < k; j++){\n var ij = i + j;\n if(!solider_has_name[ij]){\n soldier_names[ij] = names[name_link++];\n solider_has_name[ij] = true;\n }\n }\n }else{\n if(solider_has_name[i] === true){\n for(var j = 1; j < k; j++){\n var ij = i + j;\n if(solider_has_name[ij] === false){\n soldier_names[ij] = soldier_names[i];\n solider_has_name[ij] = true;\n break;\n }\n }\n }else{\n var name_of_two_soldiers = names[name_link++];\n for(var j = 0; j < 2; j++){\n var ij = i + j;\n soldier_names[ij] = name_of_two_soldiers;\n solider_has_name[ij] = true;\n }\n }\n }\n}\n\nfor(var i = 0; i < n; i++){\n if(solider_has_name[i] === false){\n soldier_names[i] = names[name_link++];\n }\n}\n\nprint(soldier_names.join(\" \"));"}], "negative_code": [{"source_code": "// Polyfill for NodeJS\nif (undefined == readline) {\n\tvar rLines = require('fs').readFileSync(\"/dev/stdin\", \"utf8\").split(\"\\n\"), \n\t\trIndex = 0,\n\t\treadline = function() {\n\t\t\trIndex ++\n\t\t\treturn rLines[rIndex - 1]\n\t\t}\n}\nif (undefined == print) {\n\tvar print = console.log\n}\n\n// Useful Read functions\nvar int = function() {\n\treturn parseInt(readline())\n}\n\nvar ints = function() {\n\treturn readline().split(' ')\n\t\t.map(function(x) {\n\t\t\treturn parseInt(x)\n\t\t})\n}\n\n// The answer\nvar names = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',\n'Aa','Ba','Ca','Da','Ea','Fa','Ga','Ha','Ia','Ja','Ka','La','Ma','Na','Oa','Pa','Qa','Ra','Sa','Ta','Ua','Va','Wa','Xa','Ya','Za',\n'Ab','Bb','Cb','Db','Eb','Fb','Gb','Hb','Ib','Jb','Kb','Lb','Mb','Nb','Ob','Pb','Qb','Rb','Sb','Tb','Ub','Vb','Wb','Xb','Yb','Zb']\n\nvar ns = ints(),\n\tn = ns[0],\n\tk = ns[1],\n\ti = 0,\n\tcount = 1,\n\twords = [],\n\tnotes = readline().split(' ').map(function(w) {\n\t\treturn w == 'YES'\n\t})\n\nfor(i = 0; i < k - 1; i ++)\n\twords[i] = i\n\ncount = k\ni = 0\nwhile (i < notes.length) {\n\tif (notes[i]) {\n\t\twords[k - 1 + i] = count\n\t\tcount ++\n\t} else {\n\t\twords[k - 1 + i] = i\n\t}\n\ti ++\n}\n\nprint(words.map(function(n) { return names[n] }).join(' '))"}, {"source_code": "var input = readline().split(' ').map(Number);\n\nvar n = input[0]; //number of soldiers\nvar k = input[1]; //size of each group\n\nvar notes = readline().split(' ').map(String);\n\n// Let's create 52 unique soldier names\nvar names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Aa', 'Ba', 'Ca', 'Da', 'Ea', 'Fa', 'Ga', 'Ha', 'Ia', 'Ja', 'Ka', 'La', 'Ma', 'Na', 'Oa', 'Pa', 'Qa', 'Ra', 'Sa', 'Ta', 'Ua', 'Va', 'Wa', 'Xa', 'Ya', 'Za'];\n\nvar soldiers = [];\nvar s_count = 0;\nvar n_count = 0;\nvar l = 0;\n\n//Ititial Group\nif (notes[0] == 'YES') {\n\tfor (var j = 0; j < k; j++) {\n\t\tsoldiers[s_count] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t}\n} else if (notes[0] == 'NO') {\n\twhile (l < k - 1) {\n\t\tsoldiers[s_count] = names[n_count];\n\t\tsoldiers[s_count + k - 1] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t\tl ++;\n\t}\n\ts_count ++;\n}\n\n//then attach either the first name of the group or the next name in the name list to the end for each group.\n\nfor (var i = 1; i < n - k + 1; i++) {\n\tif (notes[i] == 'YES') {\n\t\tsoldiers[s_count] = names[n_count];\n\t\ts_count ++;\n\t\tn_count ++;\n\t} else if (notes[i] == 'NO') {\n\t\tsoldiers[s_count] = soldiers[s_count - k + 1];\n\t\ts_count ++;\n\t}\n}\n\nvar output = soldiers.join(\" \");\n\nprint(output);"}], "src_uid": "046d6f213fe2d565bfa5ce537346da4f"} {"source_code": "'use strict'\n\nconst getLine = () => readline().split(' ')\nconst getInts = () => getLine().map(n => parseInt(n))\nconst getInt = () => getInts()[0]\nconst D = (...args) => { // D({name})\n [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))\n}\n\nmain()\n\nfunction main() {\n const input = getInts()\n const arr = getInts()\n const ans = solve(...input, arr)\n print(ans)\n}\n\nfunction solve (n, h, l, r, arr) {\n const MX = n + 2\n const inf = MX\n const dp = []\n for (let i = 0; i < MX; ++i) {\n dp[i] = []\n for (let j = 0; j < MX; ++j) {\n dp[i].push(-inf)\n }\n }\n\n dp[0][0] = 0\n const isGood = good(h, l, r)\n let sum = 0\n\n for (let i = 0; i < n; ++i) {\n sum += arr[i]\n for (let j = 0; j <= n; ++j) {\n const a = isGood(sum - j)\n const b = isGood(sum - j - 1)\n dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + a)\n dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + b)\n }\n }\n \n return dp[n].reduce((ans, cur) => Math.max(ans, cur), -1)\n}\n\nfunction good (h, l, r, val) {\n return function (val) {\n val %= h\n return val >= l && val <= r\n }\n}\n", "positive_code": [{"source_code": "var findMaxGoodSleeps = function(ts, h, l, r) {\n //hour will be manipulated with each table insertion\n //represents the hour of day that X is being woken up at\n //could be good or bad, attempting to maximize good days\n var hour = 0;\n //ts is the individual wait times while totalWaits is the sum up to each index\n var totalWaits = [];\n //table is where values for good waking times will be stored\n //the end of each row will include each potential maximum value\n var table = new Array(ts.length + 1);\n for (var i = 0; i < table.length; i++) {\n table[i] = [];\n }\n\n //creating array with the sums of the wait times up to current index\n totalWaits[0] = ts[0];\n for (var i = 1; i < ts.length; i++) {\n totalWaits[i] = totalWaits[i - 1] + ts[i];\n }\n //creating table for finding max value, setting first row which will include\n //the unaltered values and their corresponding maximum sums\n table[0][0] = 0;\n for (var i = 1; i <= ts.length; i++) {\n table[0][i] = table[0][i - 1];\n hour = totalWaits[i - 1] % h;\n if (hour >= l && hour <= r) {\n table[0][i]++;\n }\n }\n\n //setting the rest of the tables values\n for (var j = 1; j <= ts.length; j++) {\n table[j][j - 1] = 0;\n for (var i = j; i <= ts.length; i++) {\n table[j][i] = Math.max(table[j - 1][i - 1], table[j][i - 1]);\n hour = (totalWaits[i - 1] - j) % h;\n if (hour >= l && hour <= r) {\n table[j][i]++;\n }\n }\n }\n\n //finding max value by looking at end of rows\n var max = 0;\n for (var i = 0; i <= ts.length; i++) {\n if (table[i][ts.length] > max)\n max = table[i][ts.length];\n }\n return max;\n}\n\nvar firstLine = readline();\nvar secondLine = readline();\nvar nums = secondLine.split(' ').map((x) => (parseInt(x)));\nvar info = firstLine.split(' ');\nprint(findMaxGoodSleeps(nums, parseInt(info[1]), parseInt(info[2]), parseInt(info[3])));\n"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nlet input = ''\nlet ptr = 0\nprocess.stdin.on('data', (i) => {\n input += i\n})\n\n\nprocess.stdin.on('end', () => {\n input = input.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n main()\n})\n\nfunction wr(...x) {\n console.log(...x)\n}\n\nfunction sort(a, inc = true) {\n if (inc) a.sort((a, b) => a - b)\n else a.sort((a, b) => b - a)\n}\n\nfunction readInt() {\n return parseInt(input[ptr++])\n}\n\nfunction readString() {\n return input[ptr++]\n}\n\nfunction readStrings() {\n return input[ptr++].split(' ')\n}\n\nfunction readInts() {\n return input[ptr++].split(' ').map(a => parseInt(a))\n}\n\nfunction main() {\n const [n, h, l, r] = readInts()\n const a = readInts()\n let dp = new Array(n + 1)\n for(let i = 0; i <= n; i++) dp[i] = new Array(n + 1).fill(-Infinity)\n\n dp[0][0] = 0\n let sum = 0\n for(let i = 0; i < n; i++) {\n sum += a[i]\n for(let j = 0; j <= i; j++) {\n dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + inR((sum - j) % h))\n dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + inR((sum - j - 1) % h))\n }\n }\n\n wr(Math.max(...dp[n]))\n\n function inR(x) {\n return x >= l && x <= r ? 1 : 0\n }\n}"}], "negative_code": [], "src_uid": "a301e0847a620fbb349fa914db98e752"} {"source_code": "'use strict';\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n \r\nlet inputString = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n \r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n \r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const testCases = Number(readline());\r\n for (let i = 0; i < testCases; i++) {\r\n let a = readline().split(\" \").map(elem => Number(elem));\r\n let b = readline().split(\" \").map(elem => Number(elem));\r\n if (findLostPermutation(b, a[1])) console.log(\"YES\")\r\n else console.log(\"NO\")\r\n }\r\n}\r\n\r\nfunction findLostPermutation(arr, sum) {\r\n arr.sort((a, b) => a - b)\r\n\r\n let last = arr[arr.length - 1]\r\n\r\n for (let i = 1; i <= last; i++) {\r\n if (arr.indexOf(i) === -1) {\r\n sum -= i\r\n }\r\n if (sum < 0) break;\r\n }\r\n if (sum === 0) return true\r\n let i = 1\r\n while (sum > 0) {\r\n sum -= last + i;\r\n i++\r\n }\r\n\r\n if (sum === 0) return true\r\n else return false\r\n}", "positive_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar [m, sum] = readline().split(\" \").map(w => parseInt(w));\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar maxx = -inf;\r\n\tvar num = [];\r\n\tfor(var i=0;i ans) sum -= (i++);\r\n\tconsole.log(sum===ans ? \"Yes\" : \"No\");\r\n}"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, s] = lines[l++].trim().split(' ').map(Number)\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, s, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, s, arr) {\n const max = Math.max(...arr)\n const map = arr.reduce((o, x) => {\n o[x] = 1\n // o[x] = (o[x] || 0) + 1\n return o\n }, {})\n let i\n for (i = 1; i <= max; i++) {\n if (!map[i]) {\n s -= i\n }\n }\n while (s > 0) {\n s -= i++\n }\n // console.log(i, s)\n return !s ? 'YES' : 'NO'\n}\n"}, {"source_code": "'use strict';\r\n\r\nvar fs = require('fs');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);\r\n\r\nfunction solve(read) {\r\n const [rn, rb, rns, re, rbs] = convertInput(read);\r\n const [m, s] = rns(),\r\n a = rns();\r\n const max = Math.max(...a),\r\n set = new Set(a);\r\n let sum = 0;\r\n for (let i = 1; i <= max; i++) {\r\n if (set.has(i)) continue;\r\n sum += i;\r\n }\r\n let i = max + 1;\r\n while (1) {\r\n if (sum > s) return 'NO';\r\n if (sum === s) return 'YES';\r\n sum += i++;\r\n }\r\n}\r\nfunction convertInput(read) {\r\n const rn = () => Number(read());\r\n const rb = () => BigInt(read());\r\n const rns = () => read().split(/\\s+/).map(Number);\r\n const re = () => read().split(/\\s+/).map(s => Number(s) - 1);\r\n const rbs = () => read().split(/\\s+/).map(BigInt);\r\n return [rn, rb, rns, re, rbs];\r\n}\r\nfunction main(r) {\r\n try {\r\n let t = Number(r());\r\n let res = new Array(t);\r\n let limit = 0;\r\n for (let i = 0; i < t; i++) {\r\n let s = solve(r);\r\n if (s === undefined) s = '';\r\n if (t < limit) {\r\n process.stdout.write(s.toString());\r\n process.stdout.write('\\n');\r\n } else {\r\n res[i] = s;\r\n }\r\n }\r\n if (t >= limit) {\r\n return res.join('\\n');\r\n } else {\r\n return '';\r\n }\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nconst inputs = fs__default[\"default\"].readFileSync(0, 'utf-8').split(/\\r?\\n/);\r\nvoid function () {\r\n const read = ((i = 0) => () => inputs[i++])();\r\n const output = main(read);\r\n process.stdout.write(output);\r\n}();\r\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar N = nextInt();\r\n\t\tvar S = nextInt();\r\n\t\tvar list = nextIntArray(N);\r\n\t\tvar set = new Set();\r\n\t\tvar max = 0;\r\n\t\tfor(var i = 0; i < N; i++){\r\n\t\t\tset.add(list[i]);\r\n\t\t\tmax = Math.max(max, list[i]);\r\n\t\t}\r\n\t\tfor(var i = 1; i <= max; i++){\r\n\t\t\tif(!set.has(i)){\r\n\t\t\t\tS -= i;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(S < 0){\r\n\t\t\tmyout(\"No\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\twhile(S > 0){\r\n\t\t\tmax++;\r\n\t\t\tS -= max;\r\n\t\t}\r\n\t\tif(S == 0){\r\n\t\t\tmyout(\"Yes\");\r\n\t\t}else{\r\n\t\t\tmyout(\"No\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var firstLine = readline().split(' ').map(Number);\r\n var m = firstLine[0];\r\n var s = firstLine[1];\r\n \r\n var secondLine = readline().split(' ').map(Number);\r\n \r\n var result = process(secondLine, s);\r\n print(result);\r\n}\r\n\r\nfunction process(arr, sum) {\r\n var freq = {}\r\n for (var i = 0; i < arr.length; i++) {\r\n freq[arr[i]] = 1;\r\n }\r\n \r\n var currentSum = 0;\r\n var j = 1;\r\n while (Object.keys(freq).length) {\r\n if (freq[j]) {\r\n delete freq[j];\r\n } else {\r\n currentSum += j;\r\n }\r\n \r\n j++;\r\n }\r\n \r\n while (currentSum < sum) {\r\n currentSum += j;\r\n j++;\r\n }\r\n \r\n return currentSum === sum ? 'YES' : 'NO';\r\n}"}], "negative_code": [{"source_code": "const fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var tc=1;tc<=T;tc++) {\r\n\tvar [m, sum] = readline().split(\" \").map(w => parseInt(w));\r\n\tvar a = readline().split(\" \").map(w => parseInt(w));\r\n\tvar maxx = -inf;\r\n\tvar num = [];\r\n\tfor(var i=0;i0;i++) {\r\n\t\tif(!num[i]) sum -= i;\r\n\t}\r\n\tconsole.log((i >= maxx && sum === 0) ? \"Yes\" : \"No\");\r\n}"}, {"source_code": "var numOfCases = Number(readline());\r\n\r\nfor (var testCase = 0; testCase < numOfCases; testCase++) {\r\n var firstLine = readline().split(' ').map(Number);\r\n var m = firstLine[0];\r\n var s = firstLine[1];\r\n \r\n var secondLine = readline().split(' ').map(Number);\r\n \r\n var result = process(secondLine, s);\r\n print(result);\r\n}\r\n\r\nfunction process(arr, sum) {\r\n var freq = {}\r\n for (var i = 0; i < arr.length; i++) {\r\n freq[arr[i]] = 1;\r\n }\r\n \r\n var currentSum = 0;\r\n \r\n var isNeedToCheckForPermutability = false\r\n for (var j = 1; currentSum <= sum; j++) {\r\n if (currentSum === sum) {\r\n if (Object.keys(freq).length === 0) {\r\n return 'YES';\r\n } else {\r\n isNeedToCheckForPermutability = true;\r\n break;\r\n }\r\n }\r\n \r\n if (!freq[j]) {\r\n currentSum += j;\r\n } else {\r\n delete freq[j];\r\n }\r\n }\r\n \r\n if (isNeedToCheckForPermutability) {\r\n while(Object.keys(freq).length) {\r\n if (freq[j]) {\r\n delete freq[j];\r\n } else {\r\n return 'NO';\r\n }\r\n }\r\n \r\n return 'YES';\r\n }\r\n \r\n return 'NO';\r\n}"}], "src_uid": "447c17cba953d6e2da50c242ac431ab4"} {"source_code": "function handleString(str, lettersHash) {\r\n for (let letter of str) {\r\n if (!lettersHash[letter]) {\r\n lettersHash[letter] = 0;\r\n }\r\n\r\n ++lettersHash[letter];\r\n }\r\n}\r\n\r\nfunction findOriginalString(operationsData, resultString) {\r\n const lettersHash = [];\r\n for (let opData of operationsData) {\r\n handleString(opData, lettersHash);\r\n }\r\n\r\n handleString(resultString, lettersHash);\r\n\r\n for(let letterKey in lettersHash) {\r\n const letterCount = lettersHash[letterKey];\r\n if (letterCount % 2) {\r\n return letterKey;\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n\r\nfunction main() {\r\n let t = +readline();\r\n while (t > 0) {\r\n const n = +readline();\r\n let i = 0;\r\n let operationsData = [];\r\n while (i < 2 * n) {\r\n operationsData.push(readline());\r\n ++i;\r\n }\r\n\r\n const resultString = readline();\r\n console.log(findOriginalString(operationsData, resultString));\r\n\r\n --t;\r\n }\r\n}\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main(); \r\n});\r\n", "positive_code": [{"source_code": "const lines = [];\nconst _rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\n_rl.on('line', line => lines.push(line));\n_rl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\nconst rl = readline;\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst sumab = (a, b) => {\n if (a > b) return 0;\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return x * y;\n}\n\nconst calc = (t)=>{\n /* read */\n let n = +rl();\n let freq = new Array(26).fill(0);\n let aCode = 'a'.charCodeAt(0);\n for (let i = 0; i <= 2*n; i++) {\n let s = rl();\n for (let i = 0; i < s.length; i++) {\n let code = s.charCodeAt(i);\n freq[code - aCode]++;\n }\n }\n for (let i = 0; i < 26; i++) {\n if (freq[i] % 2 === 1) {\n return String.fromCharCode(aCode + i);\n }\n }\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n out.push(calc(t));\n // process.stdout.write(`${calc(t)}\\n`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(n, a, s) {\r\n const count = new Array(26).fill(0);\r\n for (let word of a.concat(s)) {\r\n for (let char of word) {\r\n const num = char.charCodeAt(0) - 97;\r\n if (count[num]) {\r\n count[num]--;\r\n } else {\r\n count[num]++;\r\n }\r\n }\r\n }\r\n for (let [i, num] of count.entries()) {\r\n if (num) return String.fromCharCode(i + 97);\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let res = [];\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = [];\r\n let tmp = 2 * n;\r\n while (tmp--) {\r\n a.push(await read());\r\n }\r\n const s = await read();\r\n res.push(solve(n, a, s));\r\n }\r\n console.log(res.join('\\n'));\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', () => {\r\n inputs = str.split('\\n').values();\r\n main(read);\r\n});\r\n"}], "negative_code": [{"source_code": "\r\nfunction replaceAt(str, index, length, replacement) {\r\n if (index >= str.length) {\r\n return str.valueOf();\r\n }\r\n\r\n return str.substring(0, index) + replacement + str.substring(index + length);\r\n}\r\n\r\nfunction printMask(mask) {\r\n let res = \"\";\r\n while(mask > 0) {\r\n res += mask & 1;\r\n mask >>= 1;\r\n }\r\n\r\n return res.split('').reverse().join('');\r\n}\r\n\r\nfunction doesMaskContainOnlyOnes(mask) {\r\n for (let elem of mask) {\r\n if (!elem) {\r\n return false\r\n }\r\n }\r\n\r\n return true;\r\n}\r\n\r\nfunction handleTraversalEntry(str, operationsData, remainingOpsMask, treeTraversalArray, opHistory) {\r\n if (operationsData.length <= 0 || str.length == 0) {\r\n return null;\r\n }\r\n\r\n/* console.log('<<<<');\r\n console.log(str);\r\n console.log(treeTraversalArray.length);\r\n console.log(printMask(remainingOpsMask))*/\r\n\r\n if (str.length == 1 && doesMaskContainOnlyOnes(remainingOpsMask)) {\r\n return str;\r\n }\r\n\r\n operationsData.forEach((opData, idx) => {\r\n if (remainingOpsMask[idx]) {\r\n return;\r\n }\r\n\r\n const matches = str.matchAll(opData);\r\n\r\n for (const match of matches) {\r\n\r\n const remainingOps = remainingOpsMask.slice();\r\n remainingOps[idx] = true;\r\n /* console.log(\"<<\")\r\n console.log(opHistory)\r\n console.log(\"<<\")*/\r\n makeReplacement(str, operationsData, remainingOps, treeTraversalArray, match.index, opData.length, opHistory);\r\n };\r\n });\r\n\r\n return null;\r\n}\r\n\r\nfunction makeReplacement(str, operationsData, remainingOpsMask, treeTraversalArray, replacementIdx, replacementLength, opHistory) {\r\n operationsData.forEach((opData, idx) => {\r\n if (remainingOpsMask[idx]) {\r\n return;\r\n }\r\n\r\n const remainingOps = remainingOpsMask.slice();\r\n remainingOps[idx] = true;\r\n \r\n const updatedStr = replaceAt(str, replacementIdx, replacementLength, opData);\r\n /* let opHistoryNew = opHistory.slice();\r\n opHistoryNew.push(updatedStr)*/\r\n\r\n treeTraversalArray.push({\r\n resultString: updatedStr,\r\n remainingOpsMask: remainingOps,\r\n // opHistory: opHistoryNew\r\n });\r\n });\r\n}\r\n\r\nfunction findOriginalString(operationsData, resultString) {\r\n let treeTraversalArray = [];\r\n\r\n treeTraversalArray.push({\r\n resultString,\r\n remainingOpsMask: [],\r\n // opHistory: [resultString]\r\n });\r\n\r\n while (treeTraversalArray.length > 0) { \r\n const currentTraversalEntry = treeTraversalArray.pop();\r\n \r\n const res = handleTraversalEntry(\r\n currentTraversalEntry.resultString,\r\n operationsData,\r\n currentTraversalEntry.remainingOpsMask,\r\n treeTraversalArray,\r\n // currentTraversalEntry.opHistory,\r\n );\r\n\r\n if(res) {\r\n console.log(res);\r\n ///console.log(currentTraversalEntry.opHistory);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n let t = +readline();\r\n while (t > 0) {\r\n const n = +readline();\r\n let i = 0;\r\n let operationsData = [];\r\n while (i < 2 * n) {\r\n operationsData.push(readline());\r\n ++i;\r\n }\r\n\r\n const resultString = readline();\r\n findOriginalString(operationsData, resultString);\r\n\r\n --t;\r\n }\r\n}\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main(); \r\n});\r\n"}, {"source_code": "\r\nfunction replaceAt(str, index, length, replacement) {\r\n if (index >= str.length) {\r\n return str.valueOf();\r\n }\r\n\r\n return str.substring(0, index) + replacement + str.substring(index + length);\r\n}\r\n\r\nfunction handleTraversalEntry(str, operationsData, remainingOpsMask, treeTraversalArray) {\r\n if (operationsData.length <= 0 || str.length == 0) {\r\n return null;\r\n }\r\n\r\n if (str.length == 1) {\r\n return str;\r\n }\r\n\r\n operationsData.forEach((opData, idx) => {\r\n if ((1 << idx) & remainingOpsMask) {\r\n return;\r\n }\r\n\r\n const matches = str.matchAll(opData);\r\n\r\n for (const match of matches) {\r\n const remainingOps = (1 << idx) | remainingOpsMask;\r\n makeReplacement(str, operationsData, remainingOps, treeTraversalArray, match.index, opData.length);\r\n };\r\n });\r\n\r\n return null;\r\n}\r\n\r\nfunction makeReplacement(str, operationsData, remainingOpsMask, treeTraversalArray, replacementIdx, replacementLength) {\r\n operationsData.forEach((opData, idx) => {\r\n if ((1 << idx) & remainingOpsMask) {\r\n return;\r\n }\r\n\r\n const remainingOps = (1 << idx) | remainingOpsMask;\r\n \r\n const updatedStr = replaceAt(str, replacementIdx, replacementLength, opData);\r\n\r\n treeTraversalArray.push({\r\n resultString: updatedStr,\r\n remainingOpsMask: remainingOps,\r\n });\r\n });\r\n}\r\n\r\nfunction findOriginalString(operationsData, resultString) {\r\n let treeTraversalArray = [];\r\n\r\n treeTraversalArray.push({\r\n resultString,\r\n remainingOps: 0,\r\n });\r\n\r\n while (treeTraversalArray.length > 0) { \r\n const currentTraversalEntry = treeTraversalArray.pop();\r\n\r\n const res = handleTraversalEntry(\r\n currentTraversalEntry.resultString,\r\n operationsData,\r\n currentTraversalEntry.remainingOpsMask,\r\n treeTraversalArray\r\n );\r\n\r\n if(res) {\r\n console.log(res);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfunction main() {\r\n let t = +readline();\r\n while (t > 0) {\r\n const n = +readline();\r\n let i = 0;\r\n let operationsData = [];\r\n while (i < 2 * n) {\r\n operationsData.push(readline());\r\n ++i;\r\n }\r\n\r\n const resultString = readline();\r\n findOriginalString(operationsData, resultString);\r\n\r\n --t;\r\n }\r\n}\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n\r\n main(); \r\n});\r\n"}], "src_uid": "b663dadb1033d435775bf000c2041d43"} {"source_code": "// Codeforces 1185/B\nlet lines = '';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => lines += input);\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n\n main();\n});\n\nconst main = () => {\n const npairs = parseInt(lines[0]);\n for (let i = 1; i < 2*npairs; i += 2) {\n console.log(solution(lines[i], lines[i+1]));\n }\n};\n\nconst countChars = (s) => {\n let prevChar = s[0];\n let count = 1;\n let res = [];\n if (s.length === 1) return [`1${s[0]}`];\n for (let i = 1; i < s.length; i++) {\n if (i === s.length - 1) {\n if (s[i] !== prevChar) {\n res.push(`${count}${prevChar}`);\n res.push(`${1}${s[i]}`);\n } else {\n res.push(`${count+1}${s[i]}`);\n }\n } else if (s[i] !== prevChar) {\n res.push(`${count}${prevChar}`); \n count = 1; \n } else {\n count++;\n }\n prevChar = s[i];\n }\n return res;\n};\n\nconst solution = (a, b) => {\n const a_arr = countChars(a);\n const b_arr = countChars(b);\n if (a_arr.length !== b_arr.length) return 'NO';\n for (let i = 0; i< a_arr.length; i++) {\n const aNum = parseInt(a_arr[i].substring(0, a_arr[i].length-1));\n const bNum = parseInt(b_arr[i].substring(0, b_arr[i].length-1));\n const aChar = a_arr[i][a_arr[i].length - 1];\n const bChar = b_arr[i][b_arr[i].length - 1];\n if (aNum > bNum) return 'NO';\n if (aChar !== bChar) return 'NO';\n }\n return 'YES';\n};\n", "positive_code": [{"source_code": "(function () {\n var read = {\n number: function () {\n return +readline();\n },\n arr: function (divider) {\n return readline().split(divider ? divider : '');\n },\n arrNumber: function (divider) {\n return readline()\n .split(divider ? divider : '')\n .map(item => +item);\n }\n };\n\n\n var n = read.number();\n var res = '';\n\n for(var i = 0; i < n; i++) {\n var s = readline();\n var t = readline();\n var indexT = 0;\n var check = true;\n for(var j = 0; j < s.length; j++) {\n while(s[j] !== t[indexT] && t[indexT - 1] === t[indexT]) {\n indexT++;\n }\n\n if(s[j] !== t[indexT]) {\n check = false;\n break;\n }\n indexT++;\n }\n while(indexT < t.length) {\n if(t[indexT] !== s[s.length - 1]) {\n check = false;\n break;\n }\n indexT++;\n }\n res += (check ? 'YES' : 'NO') + '\\n';\n }\n print(res);\n}());\n"}, {"source_code": "const DEBUG = false\nlet readline = require('readline').createInterface({\n input: !DEBUG ? process.stdin : require('fs').createReadStream('./input'),\n});\n\nlet main = () => {\n for (let i = 0; i < list.length; i+=2) {\n let itemA = list[i]\n let itemB = list[i+1]\n let next = 0;\n let j = 0;\n for (; ;) {\n if (itemA[j] == itemB[next] && next < itemB.length && j < itemA.length) {\n next++;\n j++;\n } else if (next > 0 && itemA[j - 1] == itemB[next]) {\n next++;\n } else {\n break\n }\n }\n console.log(next == itemB.length && j == itemA.length ? 'YES' : 'NO')\n }\n}\n\nlet list = []\nlet n = 0, cnt = 0;\nreadline.on('line', (d) => {\n if (n == 0) {\n n = parseInt(d, 10)\n } else {\n list.push(d)\n if (++cnt >= n * 2) {\n readline.close();\n }\n }\n});\nreadline.on('close', () => {\n main()\n})\n\n"}, {"source_code": "const DEBUG = false\nlet readline = require('readline').createInterface({\n input: !DEBUG ? process.stdin : require('fs').createReadStream('./input'),\n});\n\nlet main = () => {\n for (let i = 0; i < list.length; i+=2) {\n let itemA = list[i]\n let itemB = list[i+1]\n\n if (itemA.length > itemB.length) {\n console.log('NO')\n continue\n }\n\n let next = 0;\n let j = 0;\n for (; ;) {\n if (itemA[j] == itemB[next] && next < itemB.length && j < itemA.length) {\n next++;\n j++;\n } else if (next > 0 && itemA[j - 1] == itemB[next]) {\n next++;\n } else {\n break\n }\n }\n console.log(next == itemB.length && j == itemA.length ? 'YES' : 'NO')\n }\n}\n\nlet list = []\nlet n = 0, cnt = 0;\nreadline.on('line', (d) => {\n if (n == 0) {\n n = parseInt(d, 10)\n } else {\n list.push(d)\n if (++cnt >= n * 2) {\n readline.close();\n }\n }\n});\nreadline.on('close', () => {\n main()\n})\n\n"}, {"source_code": "const DEBUG = false;\nconst { EOL } = require('os');\nconst fs = require('fs');\n\nlet r = process.stdin;\nif (DEBUG) {\n r = fs.createReadStream('input');\n}\nlet data = '';\nfunction calc(s, t) {\n let idx1 = 0;\n let idx2 = 0;\n let cnt1 = 0;\n let cnt2 = 0;\n while (idx1 < s.length && idx2 < t.length) {\n const c = s[idx1];\n cnt1 = 0;\n cnt2 = 0;\n if (s[idx1] !== t[idx2]) {\n return 'NO';\n }\n while (idx1 + cnt1 < s.length && s[idx1 + cnt1] === c) {\n cnt1 += 1;\n }\n while (idx2 + cnt2 < t.length && t[idx2 + cnt2] === c) {\n cnt2 += 1;\n }\n if (cnt2 < cnt1) {\n return 'NO';\n }\n idx1 += cnt1;\n idx2 += cnt2;\n }\n if (idx2 < t.length || idx1 < s.length) {\n return 'NO';\n }\n return 'YES';\n}\nr.on('data', c => (data += c));\nr.on('end', () => {\n const lines = data.split(EOL);\n const tests = Number(lines[0]);\n for (let i = 1; i <= tests; i += 1) {\n console.log(calc(lines[2 * i - 1], lines[2 * i]));\n }\n});\n"}, {"source_code": "var number = readline();\nvar descriptions = [];\n\nfunction matchesOrNot(word1, word2){\n var w1Arr = [word1[0], 1];\n var w2Arr = [word2[0], 1];\n \n if(word1.length === 0 && word2.length !== 0 || word2.length === 0 && word1.length !== 0){\n return \"NO\";\n }\n if(word1.length === 0 && word2.length === 0){\n return \"YES\";\n }\n \n var w1i = 0;\n var w2i = 0;\n \n \n for(var m = 1; m < word1.length; m++){\n if(word1[m] == w1Arr[w1i]){\n w1Arr[w1i+1] +=1;\n }\n else{\n w1Arr.push(word1[m], 1);\n w1i+=2;\n }\n }\n \n for(var n = 1; n < word2.length; n++){\n if(word2[n] == w2Arr[w2i]){\n w2Arr[w2i+1] +=1;\n }\n else{\n w2Arr.push(word2[n], 1);\n w2i+=2;\n }\n }\n \n if(w1Arr.length != w2Arr.length){\n return \"NO\";\n }\n \n for(var i = 1; i < w1Arr.length; i+=2){\n if(w1Arr[i-1] == w2Arr[i-1]){\n if(w1Arr[i] > w2Arr[i]) return \"NO\";\n }else{\n return \"NO\";\n }\n }\n \n return \"YES\";\n}\n\nfor(var k = 0; k < number*2; k++){\n descriptions.push(readline());\n}\n\nfor(var i = 1; i < number*2; i+=2){\n print(matchesOrNot(descriptions[i-1], descriptions[i]));\n}\n"}], "negative_code": [{"source_code": "// Codeforces 1185/B\nlet lines = '';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', input => lines += input);\nprocess.stdin.on('end', () => {\n const { EOL } = require('os')\n lines = lines.split(EOL)\n\n main();\n});\n\nconst main = () => {\n const npairs = parseInt(lines[0]);\n for (let i = 1; i < 2*npairs; i += 2) {\n console.log(solution(lines[i], lines[i+1]));\n }\n};\n\nconst countChars = (s) => {\n let prevChar = s[0];\n let count = 1;\n let res = [];\n for (let i = 1; i < s.length; i++) {\n if (i === s.length - 1) {\n if (s[i] !== prevChar) {\n res.push(`${count}${prevChar}`);\n res.push(`${1}${s[i]}`);\n } else {\n res.push(`${count+1}${s[i]}`);\n }\n } else if (s[i] !== prevChar) {\n res.push(`${count}${prevChar}`); \n count = 1; \n } else {\n count++;\n }\n prevChar = s[i];\n }\n return res;\n};\n\nconst solution = (a, b) => {\n const a_arr = countChars(a);\n const b_arr = countChars(b);\n if (a_arr.length !== b_arr.length) return 'NO';\n for (let i = 0; i< a_arr.length; i++) {\n if (a_arr[i][0] > b_arr[i][0]) return 'NO';\n if (a_arr[i][1] !== b_arr[i][1]) return 'NO';\n }\n return 'YES';\n};\n"}], "src_uid": "6709c8078cd29e69cf1be285071b2527"} {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const w = new Array(n).fill(0);\r\n for (let i of a) w[i - 1]++;\r\n const bst = new BinarySearchTree();\r\n for (let i = 0; i < n; i++) {\r\n bst.insert(w[i]);\r\n }\r\n let max = bst.getMax(),\r\n min = bst.getMin();\r\n let res = max;\r\n while (max > min + 1) {\r\n bst.delete(max);\r\n bst.delete(min);\r\n bst.insert(max - 1);\r\n bst.insert(min + 2);\r\n max = bst.getMax();\r\n min = bst.getMin();\r\n res = Math.min(res, max);\r\n }\r\n return res;\r\n}\r\nclass BinarySearchTree {\r\n constructor(_compare = (a, b) => a - b) {\r\n _defineProperty(this, \"root\", null);\r\n _defineProperty(this, \"length\", 0);\r\n _defineProperty(this, \"min\", null);\r\n _defineProperty(this, \"max\", null);\r\n _defineProperty(this, \"minCache\", true);\r\n _defineProperty(this, \"maxCache\", true);\r\n this._compare = _compare;\r\n this.compare = this.compare.bind(this);\r\n }\r\n isT(t) {\r\n return t !== undefined && t !== null;\r\n }\r\n compare(a, b) {\r\n const {\r\n isT\r\n } = this;\r\n if (isT(a) && isT(b)) return this._compare(a, b);\r\n if (isT(a)) return 1;\r\n if (isT(b)) return -1;\r\n return 0;\r\n }\r\n isEmpty() {\r\n return !this.root;\r\n }\r\n size() {\r\n return this.root ? this.root.size : 0;\r\n }\r\n getRoot() {\r\n return this.root;\r\n }\r\n getMin() {\r\n if (this.minCache) {\r\n return this.min;\r\n }\r\n const min = this.searchKth(this.size());\r\n this.min = min;\r\n this.minCache = true;\r\n return min;\r\n }\r\n getMax() {\r\n if (this.maxCache) {\r\n return this.max;\r\n }\r\n const max = this.searchKth(1);\r\n this.max = max;\r\n this.maxCache = true;\r\n return max;\r\n }\r\n balance(node) {\r\n node.height = this.getHeight(node);\r\n const blance = this.getBalance(node);\r\n let res;\r\n if (Math.abs(blance) === 2) {\r\n if (blance > 0) {\r\n var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;\r\n const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRight(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeftRight(node);\r\n }\r\n } else {\r\n var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;\r\n const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);\r\n if (heightDif > 0) {\r\n res = this.rotateRightLeft(node);\r\n } else if (heightDif < 0) {\r\n res = this.rotateLeft(node);\r\n }\r\n }\r\n }\r\n return res ? res : node;\r\n }\r\n rotateRight(node) {\r\n const left = node.left;\r\n const leftRight = left.right;\r\n left.right = node;\r\n node.left = leftRight;\r\n node.height = this.getHeight(node);\r\n left.height = this.getHeight(left);\r\n node.size = this.getSize(node);\r\n left.size = this.getSize(left);\r\n return left;\r\n }\r\n rotateLeft(node) {\r\n const right = node.right;\r\n const rightLeft = right.left;\r\n right.left = node;\r\n node.right = rightLeft;\r\n node.height = this.getHeight(node);\r\n right.height = this.getHeight(right);\r\n node.size = this.getSize(node);\r\n right.size = this.getSize(right);\r\n return right;\r\n }\r\n rotateLeftRight(node) {\r\n node.left = this.rotateLeft(node.left);\r\n return this.rotateRight(node);\r\n }\r\n rotateRightLeft(node) {\r\n node.right = this.rotateRight(node.right);\r\n return this.rotateLeft(node);\r\n }\r\n getBalance(node) {\r\n return this.getHeight(node.left) - this.getHeight(node.right);\r\n }\r\n getHeight(node) {\r\n var _node$left$height, _node$left3, _node$right$height, _node$right3;\r\n if (!node) return 0;\r\n return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;\r\n }\r\n getSize(node) {\r\n var _node$left$size, _node$left4, _node$right$size, _node$right4;\r\n if (!node) return 0;\r\n return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;\r\n }\r\n createNode(val) {\r\n return {\r\n id: Math.random() * new Date().valueOf(),\r\n val,\r\n left: null,\r\n right: null,\r\n size: 1,\r\n height: 1,\r\n count: 1\r\n };\r\n }\r\n insert(val) {\r\n let cur = this.createNode(val);\r\n if (this.isEmpty()) {\r\n this.root = cur;\r\n this.length++;\r\n } else {\r\n [, cur] = this.insertNode(this.root, cur);\r\n }\r\n if (this.min === null || this.compare(this.min, val) > 0) {\r\n this.min = val;\r\n }\r\n if (this.max === null || this.compare(this.max, val) < 0) {\r\n this.max = val;\r\n }\r\n }\r\n insertNode(node, cur, parent = null) {\r\n node.size++;\r\n const compareResult = this.compare(cur.val, node.val);\r\n let res;\r\n if (compareResult === 0) {\r\n node.count++;\r\n return [false, node];\r\n } else if (compareResult > 0) {\r\n if (node.right) {\r\n res = this.insertNode(node.right, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.right = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n } else {\r\n if (node.left) {\r\n res = this.insertNode(node.left, cur, node);\r\n if (!res[0]) return res;\r\n } else {\r\n node.left = cur;\r\n this.length++;\r\n res = [true, cur];\r\n }\r\n }\r\n let preHeight = node.height;\r\n const newNode = this.balance(node);\r\n if (newNode === node && node.height === preHeight) {\r\n res = [false, res[1]];\r\n } else if (newNode !== node) {\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n res = [false, res[1]];\r\n }\r\n return res;\r\n }\r\n delete(val) {\r\n if (!this.root) return;\r\n this.deleteNode(val, this.root, null);\r\n }\r\n deleteNode(val, node, parent) {\r\n if (!node) return null;\r\n let res = this.compare(val, node.val);\r\n if (res === 0) {\r\n node.count--;\r\n node.size--;\r\n if (node.count > 0) return node;\r\n if (!node.left || !node.right) {\r\n if (this.min === val) {\r\n this.minCache = false;\r\n }\r\n if (this.max === val) {\r\n this.maxCache = false;\r\n }\r\n this.length--;\r\n if (!parent) {\r\n var _node$left5;\r\n this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;\r\n return this.root;\r\n } else {\r\n var _node$left6;\r\n return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;\r\n }\r\n } else {\r\n const selectLeft = node.left.height > node.right.height;\r\n let replaceNode = selectLeft ? this.pre(node) : this.next(node),\r\n name = selectLeft ? 'left' : 'right';\r\n node.val = replaceNode.val;\r\n node.count = replaceNode.count;\r\n replaceNode.count = 0;\r\n node[name] = this.deleteNode(replaceNode.val, node[name], node);\r\n }\r\n } else if (res > 0) {\r\n node.right = this.deleteNode(val, node.right, node);\r\n } else {\r\n node.left = this.deleteNode(val, node.left, node);\r\n }\r\n node.size = this.getSize(node);\r\n node.height;\r\n const newNode = this.balance(node);\r\n if (parent) {\r\n parent.left === node ? parent.left = newNode : parent.right = newNode;\r\n } else {\r\n this.root = newNode;\r\n }\r\n return newNode;\r\n }\r\n next(node) {\r\n let next = node.right;\r\n while ((_next = next) !== null && _next !== void 0 && _next.left) {\r\n var _next;\r\n next = next.left;\r\n }\r\n return next;\r\n }\r\n pre(node) {\r\n let pre = node.left;\r\n while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {\r\n var _pre;\r\n pre = pre.right;\r\n }\r\n return pre;\r\n }\r\n search(val, compare) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);\r\n return node.val;\r\n }\r\n searchCeilingNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.searchCeilingNode(node.right, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n const [p, value] = this.searchCeilingNode(node.left, val, compare, node);\r\n if (compare(value.val, val) < 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n ceiling(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchCeilingNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) >= 0 ? node.val : null;\r\n }\r\n searchFloorNode(node, val, compare, parent = null) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n return [parent, node];\r\n } else if (res > 0) {\r\n if (node.right) {\r\n const [p, value] = this.searchFloorNode(node.right, val, compare, node);\r\n if (compare(value.val, val) > 0) {\r\n return [parent, node];\r\n } else {\r\n return [p, value];\r\n }\r\n } else {\r\n return [parent, node];\r\n }\r\n } else {\r\n if (node.left) {\r\n return this.searchFloorNode(node.left, val, compare, node);\r\n } else {\r\n return [parent, node];\r\n }\r\n }\r\n }\r\n floor(val) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n const [, node] = this.searchFloorNode(this.root, val, this.compare);\r\n return this.compare(node.val, val) <= 0 ? node.val : null;\r\n }\r\n searchKth(k) {\r\n if (this.isEmpty()) {\r\n return null;\r\n }\r\n if (k <= 0 || k > this.size()) {\r\n return null;\r\n }\r\n const node = this.searchNodeKth(this.root, k);\r\n return node.val;\r\n }\r\n searchNodeKth(node, k) {\r\n var _node$right$size2, _node$right5, _node$right$size3, _node$right6;\r\n const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;\r\n if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;\r\n if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);\r\n }\r\n countGreaterThanEq(val) {\r\n if (!this.root) return 0;\r\n return this.countCompare(val, (a, b) => this._compare(a, b), this.root);\r\n }\r\n countCompare(val, compare, node, pre = 0) {\r\n const res = compare(val, node.val);\r\n if (res === 0) {\r\n var _node$right$size4, _node$right7;\r\n return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;\r\n } else if (res > 0) {\r\n if (node.right) {\r\n return this.countCompare(val, compare, node.right, pre);\r\n } else {\r\n return pre;\r\n }\r\n } else {\r\n var _node$right$size5, _node$right8;\r\n let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;\r\n if (node.left) {\r\n return this.countCompare(val, compare, node.left, count);\r\n } else {\r\n return count;\r\n }\r\n }\r\n }\r\n toArray() {\r\n if (!this.root) return [];\r\n const res = [];\r\n const dfs = node => {\r\n if (node.left) dfs(node.left);\r\n res.push(node.val);\r\n if (node.right) dfs(node.right);\r\n };\r\n dfs(this.root);\r\n return res;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n", "positive_code": [{"source_code": "const { ok } = require(\"assert\");\r\nconst fs = require(\"fs\");\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n\r\nfunction alph() {\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n return f;\r\n}\r\nfunction max(x,y) {\r\n return x >=y ? x : y;\r\n}\r\nfunction min(x,y) {\r\n return x <=y ? x : y;\r\n}\r\nfunction abs(x) {\r\n return x < 0 ? x*(-1) : x;\r\n}\r\n\r\nvar T = readline();\r\nvar inf = 1000000000000;\r\nfor(var qe=1;qe<=T;qe++) {\r\n var [n,m] = readline().split(' ').map((x) => parseInt(x));\r\n \r\n var a = readline().split(' ').map((x) => parseInt(x));\r\n a.sort();\r\n var cnt = []\r\n for(var i=1;i<=n;i++) cnt[i] = 0;\r\n for(var i=0;i 0) rem += remove;\r\n else {\r\n rem -= Math.floor((abs(remove))/2)\r\n }\r\n // i = j-1;\r\n }\r\n // if(qe==2) console.log([x, rem])\r\n if(rem <= 0) return true;\r\n else return false;\r\n }\r\n console.log(ans)\r\n \r\n}\r\n"}, {"source_code": "var t = +readline();\r\n \r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n \r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\tvar arrDec = new Array(k[0]);\r\n \r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n \r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn b - a;\r\n\t});\r\n \r\n\tvar l = 1;\r\n\tvar r = arrMapper[0];\r\n\tvar m = parseInt((l + r) / 2);\r\n \r\n\tvar res = arrMapper[0];\r\n \r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n \r\n\t// print(l, r);\r\n \r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n \r\n\tprint(res);\r\n}\r\n \r\nfunction caclTime(m, arrMapper) {\r\n\tvar sumNeed = 0;\r\n\tvar indexNeed = arrMapper.length - 1;\r\n\tfor (var i = arrMapper.length - 1; i >= 0; i--) {\r\n\t\tvar check = parseInt((m - arrMapper[i]) / 2);\r\n\t\tif (check <= 0) {\r\n\t\t\tindexNeed = Math.min(arrMapper.length - 1, i + 1);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tsumNeed += check;\r\n\t}\r\n \r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\tfor (i = 0; i <= indexNeed - 1; i++) {\r\n\t\tvar current = i + 1;\r\n\t\tvar sumFromi = (arrMapper[i] - arrMapper[i + 1]) * current;\r\n\t\tvar add = sum + sumFromi;\r\n\t\tif (add <= sumNeed) {\r\n\t\t\tsum += sumFromi;\r\n\t\t\tresurt = arrMapper[i + 1];\r\n\t\t} else {\r\n\t\t\tvar remain = sumNeed - sum;\r\n\t\t\tvar div = parseInt(remain / current);\r\n\t\t\tresurt = arrMapper[i] - div;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\t// print(m, resurt, sumNeed, indexNeed);\r\n \r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\tvar arrDec = new Array(k[0]);\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn b - a;\r\n\t});\r\n\r\n\tvar l = 1;\r\n\tvar r = arrMapper[0];\r\n\tvar m = parseInt((l + r) / 2);\r\n\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\t// print(l, r);\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar sumNeed = 0;\r\n\tvar indexNeed = arrMapper.length - 1;\r\n\tfor (var i = arrMapper.length - 1; i >= 0; i--) {\r\n\t\tvar check = parseInt((m - arrMapper[i]) / 2);\r\n\t\tif (check <= 0) {\r\n\t\t\tindexNeed = Math.min(arrMapper.length - 1, i + 1);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tsumNeed += check;\r\n\t}\r\n\r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\tfor (i = 0; i <= indexNeed - 1; i++) {\r\n\t\tvar current = i + 1;\r\n\t\tvar sumFromi = (arrMapper[i] - arrMapper[i + 1]) * current;\r\n\t\tvar add = sum + sumFromi;\r\n\t\tif (add <= sumNeed) {\r\n\t\t\tsum += sumFromi;\r\n\t\t\tresurt = arrMapper[i + 1];\r\n\t\t} else {\r\n\t\t\tvar remain = sumNeed - sum;\r\n\t\t\tvar div = parseInt(remain / current);\r\n\t\t\tresurt = arrMapper[i] - div;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\t// print(m, resurt, sumNeed, indexNeed);\r\n\r\n\treturn resurt;\r\n}\r\n"}], "negative_code": [{"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn b - a;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = 1;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\t// print(l, r);\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) {\r\n\t\t\tgive = arrMapper[head] - m;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head]);\r\n\t\t\tsum = 0;\r\n\t\t}\r\n\t\tif (checked <= 0) {\r\n\t\t\tchecked = parseInt((m - arrMapper[last]) / 2);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last]);\r\n\t\t}\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\r\n\t\tif (checked >= give) {\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - m);\r\n\t\t\tchecked -= give;\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t\tif (checked === 0) last--;\r\n\t\t} else {\r\n\t\t\tsum += checked;\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - sum);\r\n\t\t\tgive -= checked;\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\tif (head === last) {\r\n\t\tresurt = Math.max(resurt, arrMapper[head]);\r\n\t} else if (last - head > 1) {\r\n\t\tresurt = Math.max(resurt, arrMapper[head + 1]);\r\n\t\tresurt = Math.max(resurt, arrMapper[last - 1]);\r\n\t}\r\n\r\n\t// print(\"m = \", m, \" res = \", resurt);\r\n\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn b - a;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = 1;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\t// print(l, r);\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) {\r\n\t\t\tgive = arrMapper[head] - m;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head]);\r\n\t\t\tsum = 0;\r\n\t\t}\r\n\t\tif (checked <= 0) {\r\n\t\t\tchecked = parseInt((m - arrMapper[last]) / 2);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last]);\r\n\t\t}\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\r\n\t\tif (checked >= give) {\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - m);\r\n\t\t\tchecked -= give;\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t\tif (checked === 0) last--;\r\n\t\t} else {\r\n\t\t\tsum += checked;\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - sum);\r\n\t\t\tgive -= checked;\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\tif (head === last) {\r\n\t\tresurt = Math.max(resurt, arrMapper[head]);\r\n\t}\r\n\r\n\t// print(\"m = \", m, \" res = \", resurt);\r\n\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn b - a;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = 1;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) {\r\n\t\t\tgive = arrMapper[head] - m;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head]);\r\n\t\t\tsum = 0;\r\n\t\t}\r\n\t\tif (checked <= 0) {\r\n\t\t\tchecked = parseInt((m - arrMapper[last]) / 2);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last]);\r\n\t\t}\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\r\n\t\tif (checked >= give) {\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - m);\r\n\t\t\tchecked -= give;\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t\tif (checked === 0) last--;\r\n\t\t} else {\r\n\t\t\tsum += checked;\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - sum);\r\n\t\t\tgive -= checked;\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn a < b;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = r - maxTime;\r\n\tif (l >= 2) l--;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = arrMapper[0];\r\n\tvar sum = 0;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) give = arrMapper[head] - m;\r\n\t\tif (checked <= 0) checked = parseInt((m - arrMapper[last]) / 2);\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\r\n\t\tif (checked >= give) {\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - m);\r\n\t\t\tchecked -= give;\r\n\t\t\tgive = 0;\r\n\t\t\tsum = 0;\r\n\t\t\thead++;\r\n\t\t\tif (checked === 0) last--;\r\n\t\t} else {\r\n\t\t\tsum += checked;\r\n\t\t\tresurt = Math.min(resurt, arrMapper[head] - sum);\r\n\t\t\tgive -= checked;\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn a < b;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = r - maxTime;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = arrMapper[0];\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse {\r\n\t\t\tr = m;\r\n\t\t\tres = Math.min(res, m);\r\n\t\t}\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl <= i) res = Math.min(res, i);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = -1;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) give = arrMapper[head] - m;\r\n\t\tif (checked <= 0) checked = parseInt((m - arrMapper[last]) / 2);\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\r\n\t\tif (checked >= give) {\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - give);\r\n\t\t\tchecked -= give;\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t} else {\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - checked);\r\n\t\t\tgive -= checked;\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\tif (resurt === -1) resurt = arrMapper[0]; // no case\r\n\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn a < b;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = 1;\r\n\tvar m = parseInt((l + r) / 2);\r\n\tvar res = parseInt(2e5) + 1;\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse r = m;\r\n\t\tres = Math.min(res, cacl);\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tres = Math.min(res, cacl);\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = -1;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) give = parseInt(arrMapper[head] / 3);\r\n\t\tif (checked <= 0) checked = parseInt((m - arrMapper[last]) / 2);\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\t\tif (checked >= give) {\r\n\t\t\tchecked -= give;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - give);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + give * 2);\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t} else {\r\n\t\t\tgive -= checked;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - checked);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + checked * 2);\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\r\n\tif (resurt === -1) resurt = arrMapper[0];\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn a < b;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = r - maxTime;\r\n\tvar m = parseInt((l + r) / 2);\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl > m) l = m;\r\n\t\telse r = m;\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\tvar res = -1;\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tif (res !== -1) break;\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl >= i) res = i;\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = m;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) give = parseInt(arrMapper[head] / 3);\r\n\t\tif (checked <= 0) checked = parseInt((m - arrMapper[last]) / 2);\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\t\tif (checked >= give) {\r\n\t\t\tchecked -= give;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - give);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + give * 2);\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t} else {\r\n\t\t\tgive -= checked;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - checked);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + checked * 2);\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\r\n\tvar arrMapper = new Array(k[0]); // bad\r\n\r\n\tfor (var i = 1; i <= k[0]; i++) {\r\n\t\tarrMapper[i - 1] = 0;\r\n\t}\r\n\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\tarrMapper[arr[i] - 1]++;\r\n\t}\r\n\r\n\tarrMapper.sort(function (a, b) {\r\n\t\treturn a < b;\r\n\t});\r\n\r\n\tvar r = arrMapper[0];\r\n\tvar maxTime = parseInt(r / 3);\r\n\tvar l = r - maxTime;\r\n\tvar m = parseInt((l + r) / 2);\r\n\r\n\twhile (l !== m && r != m) {\r\n\t\tvar cacl = caclTime(m, arrMapper);\r\n\t\tif (cacl >= m) l = m;\r\n\t\telse r = m;\r\n\t\tm = parseInt((l + r) / 2);\r\n\t}\r\n\r\n\tvar res = -1;\r\n\r\n\tfor (var i = l; i <= r; i++) {\r\n\t\tif (res !== -1) break;\r\n\t\tvar cacl = caclTime(i, arrMapper);\r\n\t\tif (cacl >= i) res = i;\r\n\t}\r\n\r\n\tprint(res);\r\n}\r\n\r\nfunction caclTime(m, arrMapper) {\r\n\tvar head = 0;\r\n\tvar last = arrMapper.length - 1;\r\n\tvar give = -1;\r\n\tvar checked = -1;\r\n\tvar resurt = m;\r\n\r\n\twhile (head < last) {\r\n\t\tif (give <= 0) give = parseInt(arrMapper[head] / 3);\r\n\t\tif (checked <= 0) checked = parseInt((m - arrMapper[last]) / 2);\r\n\t\tif (checked <= 0 || give <= 0) break;\r\n\t\tif (checked >= give) {\r\n\t\t\tchecked -= give;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - give);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + give * 2);\r\n\t\t\tgive = 0;\r\n\t\t\thead++;\r\n\t\t} else {\r\n\t\t\tgive -= checked;\r\n\t\t\tresurt = Math.max(resurt, arrMapper[head] - checked);\r\n\t\t\tresurt = Math.max(resurt, arrMapper[last] + checked * 2);\r\n\t\t\tchecked = 0;\r\n\t\t\tlast--;\r\n\t\t}\r\n\t}\r\n\treturn resurt;\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tif (k[0] === 1) {\r\n\t\tprint(k[1]);\r\n\t\tcontinue;\r\n\t}\r\n\tvar arrCheck = new Array(k[0] + 1);\r\n\tvar maxP = -1;\r\n\tvar minP = parseInt(2e5 + 1);\r\n\tfor (var i = 0; i < k[1]; i++) {\r\n\t\tif (arrCheck[arr[i]] === undefined) {\r\n\t\t\tarrCheck[arr[i]] = 0;\r\n\t\t}\r\n\t\t++arrCheck[arr[i]];\r\n\t\tmaxP = Math.max(maxP, arrCheck[arr[i]]);\r\n\t\tminP = Math.min(minP, arrCheck[arr[i]]);\r\n\t}\r\n\tvar div = maxP - minP;\r\n\tvar s = parseInt(div / 3);\r\n\tdiv -= s;\r\n\tprint(minP + div);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arrCheck = new Array(k[0] + 1);\r\n\tvar maxP = -1;\r\n\tvar minP = parseInt(2e5 + 1);\r\n\tfor (var i = 0; i < k[1]; i++) {\r\n\t\tif (arrCheck[arr[i]] === undefined) {\r\n\t\t\tarrCheck[arr[i]] = 0;\r\n\t\t}\r\n\t\t++arrCheck[arr[i]];\r\n\t\tmaxP = Math.max(maxP, arrCheck[arr[i]]);\r\n\t\tminP = Math.min(minP, arrCheck[arr[i]]);\r\n\t}\r\n\tvar div = maxP - minP;\r\n\tvar s = parseInt(div / 3);\r\n\tdiv -= s;\r\n\tprint(minP + div);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arrCheck = new Array(k[0] + 1);\r\n\tvar maxP = -1;\r\n\tvar minP = parseInt(2e5 + 1);\r\n\tfor (var i = 0; i < k[1]; i++) {\r\n\t\tif (arrCheck[arr[i]] === undefined) {\r\n\t\t\tarrCheck[arr[i]] = 0;\r\n\t\t}\r\n\t\t++arrCheck[arr[i]];\r\n\t\tmaxP = Math.max(maxP, arrCheck[arr[i]]);\r\n\t\tminP = Math.min(minP, arrCheck[arr[i]]);\r\n\t}\r\n\tvar div = maxP - minP;\r\n\tvar s = parseInt(maxP / 3);\r\n\tmaxP -= s * 2;\r\n\tprint(minP + maxP);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arrCheck = new Array(k[0] + 1);\r\n\tvar maxP = -1;\r\n\tvar minP = parseInt(2e5 + 1);\r\n\tfor (var i = 0; i < k[1]; i++) {\r\n\t\tif (arrCheck[arr[i]] === undefined) {\r\n\t\t\tarrCheck[arr[i]] = 0;\r\n\t\t}\r\n\t\t++arrCheck[arr[i]];\r\n\t\tmaxP = Math.max(maxP, arrCheck[arr[i]]);\r\n\t\tminP = Math.min(minP, arrCheck[arr[i]]);\r\n\t}\r\n\tvar div = maxP - minP;\r\n\tvar s = parseInt(maxP / 3);\r\n\tmaxP -= s * 2;\r\n\tprint(s + maxP);\r\n}\r\n"}, {"source_code": "var t = +readline();\r\n\r\nwhile (t--) {\r\n\tvar k = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arr = readline()\r\n\t\t.split(\" \")\r\n\t\t.map(function (a) {\r\n\t\t\treturn +a;\r\n\t\t});\r\n\tvar arrCheck = new Array(k[0] + 1);\r\n\tvar maxP = -1;\r\n\tvar minP = parseInt(2e5 + 1);\r\n\tfor (var i = 0; i < k[1]; i++) {\r\n\t\tif (arrCheck[arr[i]] === undefined) {\r\n\t\t\tarrCheck[arr[i]] = 0;\r\n\t\t}\r\n\t\t++arrCheck[arr[i]];\r\n\t\tmaxP = Math.max(maxP, arrCheck[arr[i]]);\r\n\t\tminP = Math.max(minP, arrCheck[arr[i]]);\r\n\t}\r\n\tvar s = parseInt(maxP / 3);\r\n\tmaxP -= s * 2;\r\n\tprint(s + maxP);\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const w = new Array(n).fill(0);\r\n for (let i of a) w[i - 1]++;\r\n const max = new Heap((a, b) => b - a),\r\n min = new Heap((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n min.push(w[i]);\r\n max.push(w[i]);\r\n }\r\n let res = Math.max(max.top(), min.top());\r\n while (max.top() > min.top()) {\r\n let a = max.pop(),\r\n b = min.pop();\r\n a--;\r\n b += 2;\r\n max.push(a);\r\n min.push(b);\r\n res = Math.min(res, Math.max(max.top(), min.top()));\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const w = new Array(n).fill(0);\r\n for (let i of a) w[i - 1]++;\r\n const max = new Heap((a, b) => b - a),\r\n min = new Heap((a, b) => a - b);\r\n w.sort((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n if (i < n / 2) min.push(w[i]);else max.push(w[i]);\r\n }\r\n let res = Math.max(max.top(), min.top());\r\n while (max.top() > min.top()) {\r\n let a = max.pop(),\r\n b = min.pop();\r\n a--;\r\n b += 2;\r\n res = Math.min(res, Math.max(a, b));\r\n max.push(a);\r\n min.push(b);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const w = new Array(n).fill(0);\r\n for (let i of a) w[i - 1]++;\r\n const max = new Heap((a, b) => b - a),\r\n min = new Heap((a, b) => a - b);\r\n for (let i = 0; i < w.length; i++) {\r\n max.push(w[i]);\r\n min.push(w[i]);\r\n }\r\n let res = Math.max(max.top(), min.top());\r\n while (max.top() > min.top()) {\r\n let a = max.pop(),\r\n b = min.pop();\r\n a--;\r\n b += 2;\r\n res = Math.min(res, Math.max(a, b));\r\n max.push(a);\r\n min.push(b);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction _defineProperty(obj, key, value) {\r\n if (key in obj) {\r\n Object.defineProperty(obj, key, {\r\n value: value,\r\n enumerable: true,\r\n configurable: true,\r\n writable: true\r\n });\r\n } else {\r\n obj[key] = value;\r\n }\r\n\r\n return obj;\r\n}\r\n\r\nfunction solve(n, m, a) {\r\n const w = new Array(n).fill(0);\r\n for (let i of a) w[i - 1]++;\r\n const max = new Heap((a, b) => b - a),\r\n min = new Heap((a, b) => a - b);\r\n for (let i = 0; i < n; i++) {\r\n max.push(w[i]);\r\n min.push(w[i]);\r\n }\r\n let res = Math.max(max.top(), min.top());\r\n while (max.top() > min.top()) {\r\n let a = max.pop(),\r\n b = min.pop();\r\n a--;\r\n b += 2;\r\n res = Math.min(res, Math.max(a, b));\r\n max.push(a);\r\n min.push(b);\r\n }\r\n return res;\r\n}\r\nclass Heap {\r\n constructor(_comparator, arr) {\r\n _defineProperty(this, \"_heap\", []);\r\n this._comparator = _comparator;\r\n if (arr) {\r\n this._heap = [...arr];\r\n for (let i = arr.length >> 1; i; i--) this.down(i);\r\n }\r\n }\r\n swap(i, j) {\r\n [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];\r\n }\r\n _has(i) {\r\n return Object.prototype.hasOwnProperty.call(this._heap, i);\r\n }\r\n comparator(i, j) {\r\n return this._comparator(this._heap[i], this._heap[j]) < 0;\r\n }\r\n parent(i) {\r\n return i - 1 >> 1;\r\n }\r\n children(i) {\r\n return [2 * i + 1, 2 * i + 2];\r\n }\r\n up(i) {\r\n let parent = this.parent(i);\r\n while (i > 0 && this.comparator(i, parent)) {\r\n this.swap(i, parent);\r\n [i, parent] = [parent, parent - 1 >> 1];\r\n }\r\n }\r\n down(i) {\r\n let [left, right] = this.children(i);\r\n while (left < this._heap.length) {\r\n if (!this._has(right)) right = left;\r\n if (this.comparator(right, left)) [left, right] = [right, left];\r\n if (this.comparator(i, left)) break;\r\n this.swap(i, left);\r\n i = left;\r\n [left, right] = [2 * i + 1, 2 * i + 2];\r\n }\r\n }\r\n push(node) {\r\n this._heap.push(node);\r\n this.up(this._heap.length - 1);\r\n }\r\n pop() {\r\n if (this.size() === 0) return null;\r\n let res = this._heap[0];\r\n this.swap(0, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(0);\r\n return res;\r\n }\r\n remove(i) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this.swap(i, this._heap.length - 1);\r\n this._heap.pop();\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n modify(i, val) {\r\n if (i >= this.size()) return;\r\n let res = this._heap[i];\r\n this._heap[i] = val;\r\n this.down(i);\r\n this.up(i);\r\n return res;\r\n }\r\n top() {\r\n if (this.size() === 0) return null;\r\n return this._heap[0];\r\n }\r\n size() {\r\n return this._heap.length;\r\n }\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const [n, m] = (await read()).split(' ').map(Number);\r\n const a = (await read()).split(' ').map(Number);\r\n res[i] = solve(n, m, a);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}], "src_uid": "87302bcc6c8f239641ab6f6dbeeae09c"} {"source_code": "var stops = readline();\nvar total = 0;\nvar max = 0;\nwhile(stops--){\n var pass = readline().split(' ');\n total = total - parseInt(pass[0]) + parseInt(pass[1]);\n if(total >= max){\n max = total;\n }\n}\n\nprint(max);", "positive_code": [{"source_code": "var count = +readline();\nvar capacity = 0;\nvar inside = 0;\n\nfor (var i=0; icapacity) { capacity = inside; }\n}\n\nprint(capacity);\n"}, {"source_code": "var n = parseInt(readline());\nvar capacity = 0;\nvar passengers = 0;\n\nfor(var i = 0; i < n; i++)\n{\n\tvar ab = readline().split(' ');\n\tpassengers -= parseInt(ab[0]);\n\tpassengers += parseInt(ab[1]);\n\tif(passengers > capacity) capacity = passengers;\n}\n\nprint(capacity);"}, {"source_code": "//numero de tramos\nvar dato1 =parseInt(readline());\n//array que almacene pasajeros por tramos\nvar arra = new Array();\n//contador auxiliar\nvar suma=0;\n\nfor(var i=0;i+v);\n\tcurrCapacity=currCapacity-s[0]+s[1];\n\tif(currCapacity>maxCapacity){\n\t\tmaxCapacity=currCapacity;\n\t}\n}\nprint(maxCapacity);"}, {"source_code": "var n = +readline();\n\nvar ans = 0;\nvar max = 0;\nfor(var i = 0 ; i < n ;i++){\n\tvar arr = readline().split(' ');\n\t\n\tvar a = +arr[0];\n\tvar b = +arr[1];\n\t\n\tans -= a;\n\tans += b;\n\t\n\tmax = Math.max(ans,max);\n\t\n\t\n\n}\n\nprint(max);"}, {"source_code": "line = readline(), ans = 0, cur = 0;\nwhile (line = readline()) {\n line = line.split(' ').map(function(x) { return +x; });\n cur = Math.max(0, cur - line[0] +line[1]);\n ans = Math.max(ans, cur);\n}\nprint(ans);\n"}, {"source_code": "var n = parseInt(readline());\nvar passengers = [];\nvar a = [];\nvar b = [];\nvar max_capacity = 0;\nvar result = 0;\n\nfor (var i = 0; i < n; i++) {\n\tpassengers = readline().split(' ');\n\n\ta.push(parseInt(passengers[0]));\n\tb.push(parseInt(passengers[1]));\n}\n\nfor (var i = 0; i < n; i++) {\n\tresult = result - a[i] + b[i];\n\tif (result > max_capacity) {\n\t\tmax_capacity = result;\n\t}\n}\nprint (max_capacity);"}, {"source_code": "var n = parseInt(readline());\nvar passengers = [];\nvar max_capacity = 0;\nvar result = 0;\n\nfor (var i = 0; i < n; i++) {\n passengers = readline().split(' ');\n result = result - parseInt(passengers[0]) + parseInt(passengers[1]);\n\tmax_capacity = Math.max(result, max_capacity);\n}\nprint (max_capacity);"}, {"source_code": "/* TEST CASE\ninput\n4\n0 3\n2 5\n4 2\n4 0\noutput\n6\n */\n\nfunction main() {\n\tvar n = parseInt(readline());\n\tvar answer = 0;\n\tvar splitted;\n\tvar currentPersons = 0;\n\t\n\tfor (var i = 0; i < n; i++) {\n\t\tsplitted = readline().split(' ');\n\t\tvar exits = parseInt(splitted[0]);\n\t\tvar enters = parseInt(splitted[1]);\n\t\tcurrentPersons += enters - exits;\n\t\tanswer = Math.max(answer, currentPersons);\n\t}\n\t\n\tprint(answer);\n}\n\nmain();\n"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exits= new Array();\nvar entries = new Array();\nvar sum = 0;\nvar persons = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = persons+parseInt(entries[z])-parseInt(exits[z]);\n\t}\n\tpersons = persons+parseInt(entries[z])-parseInt(exits[z]);\n}\n\nprint(sum);"}, {"source_code": "//116A \u0422\u0440\u0430\u043c\u0432\u0430\u0439\nvar n = +readline();\nvar max = 0;\nvar current = 0;\nwhile (n--) {\n var io = readline().split(' ').map(e => parseInt(e));\n current += io[1] - io[0];\n max = (current > max) ? current : max;\n}\nprint(max);"}, {"source_code": "var counts = +readline(),\n max = 0, now = 0;\n \nfor (var i = 0; i < counts; i++) {\n var data = readline().split(' '),\n out = +data[0], in_p = +data[1];\n \n now -= out;\n now += in_p;\n \n if (now > max) max = now;\n}\n\nprint(max);"}, {"source_code": "function detectMax(out, into)\n{\n return into - out;\n}\n\n{\n var num = parseInt(readline());\n var max = 0, medium = 0;\n for (var i = 1; i <= num; i++)\n {\n var input = readline();\n input = input.split(' ');\n medium += detectMax(parseInt(input[0]), parseInt(input[1]));\n if (medium > max) max = medium;\n }\n print(max);\n}"}, {"source_code": "var n = readline();\nvar io;\nvar current = 0;\nvar capacity = -1;\nfor(var i = 0; i < n; i++){\n\tio = readline().split(\" \");\n\tcurrent += (io[1]-io[0]);\n\tcapacity = (current > capacity) ? current : capacity;\n\t\t\n}\nprint(capacity);\n"}, {"source_code": "readline(); for(var s, a, b, now = 0, ans = 0; s = readline(); ) {\n s = s.split( ' ' ); a = s[0] - ''; b = s[1] - '';\n now = now - a + b;\n ans = Math.max( now, ans );\n}\nprint( ans );"}, {"source_code": "var n = parseInt(readline(), 10), ab = [], minCap = 0, existPassenger = 0;\n\nfor(var i=1; i<=n-1; i++) {\n ab = readline().split(' ').map(el => parseInt(el, 10));\n existPassenger = existPassenger - ab[0] + ab[1];\n minCap = existPassenger > minCap ? existPassenger : minCap;\n}\n\nprint(minCap);"}, {"source_code": "var n = Number(readline());\n\nvar minTramCapcty = 0,\n temp = 0;\n\nfor (var i = 0; i < n; i++) {\n var stopStop = readline().split(' ').map(Number);\n var exit = stopStop[0];\n var enter = stopStop[1];\n\n temp -= exit;\n temp += enter;\n\n if ( temp > minTramCapcty ) {\n minTramCapcty = temp;\n }\n}\n\nprint( minTramCapcty );\n\n"}, {"source_code": "var n = readline()\nvar str = []\nfor (var i = 0; i < n; i++) {\n var line = readline()\n line = line.split(\" \")\n str.push(line[0])\n str.push(line[1])\n}\nvar rez = 0\nvar trig = true\nvar bol = 0\nfor (var i = 1; i < str.length; i++) {\n if(trig){\n\t\trez += Number(str[i])\n\t\ttrig = false\n\t\tif(rez > bol){\n\t\t\tbol = rez\n\t\t}\n\t} else {\n\t\trez -= Number(str[i])\n\t\ttrig = true\n\t}\n}\nprint(bol)"}, {"source_code": "var n = +readline();\n\nvar max=0;\nvar p=0;\nwhile(n--){\n\tvar l=readline().split(' ');\n\tp+=l[1]-l[0];\n\tif(p>max) max=p;\n}\nprint(max);"}, {"source_code": "var a = readline();\nvar jami = 0, max = 0;\nfor(i = 1; i < a; i ++ ) {\n\tvar cin = readline().split(\" \").map(function(v){return +v;});\n\tjami = jami + cin[1] - cin[0];\n\tif(jami >= max) {\n\t\tmax = jami;\n\t}\n}\n\n\n\nprint(max);"}, {"source_code": "var n = +readline(), input = [], c = 0, prev = 0;\n\nfor(i = 0; i < n; i++){\n\tinput.push(readline().split(\" \"));\n}\n\nfor( i = 0; i < n; i++ ){\n\tprev = prev + +input[i][1] - +input[i][0];\n\tif( prev > c ){\n\t\tc = prev;\n\t}\n}\nwrite(c);"}, {"source_code": "\nvar stops = parseInt(readline());\n\nvar minCapacity = 0; var curntCapacity = 0;\n\nvar enterLeavLine = ''; var leavingPass = 0; var entringPass = 0;\n\n\nfor(var i = 1; i <= stops; i++)\n{\n enterLeavLine = readline();\n leavingPass = parseInt(enterLeavLine.split(\" \")[0]);\n entringPass = parseInt(enterLeavLine.split(\" \")[1]);\n\n curntCapacity -= leavingPass;\n curntCapacity += entringPass;\n \n if (curntCapacity > minCapacity) minCapacity = curntCapacity;\n \n // print('Min : ' + minCapacity);\n // print('Crnt : ' + curntCapacity);\n \n}\n\nprint(minCapacity);"}, {"source_code": "(function() {\n var stopCount = parseInt(readline());\n\n var currentPassangers = 0;\n var maxPassengers = 0;\n for (var i = 0; i < stopCount; i++){\n\n var inOutPassangers = readline().trim().split(\" \").map(Number);\n var outPass = inOutPassangers[0];\n var inPass = inOutPassangers[1];\n\n currentPassangers -= outPass;\n currentPassangers += inPass;\n\n if (currentPassangers > maxPassengers)\n maxPassengers = currentPassangers;\n }\n\n print(maxPassengers);\n\n return 0;\n})();"}, {"source_code": "readline();\nvar a = c = split(readline(), ' ')[1], b;\n\nwhile (b = readline()) {\n b = split(b, ' ');\n a = a - b[0] + +b[1];\n if (a > c) c = a;\n}\n\nfunction split(t, r) {\n var d = t.length, e = 0, f = '', g = [];\n \n for (; e < d; e++) {\n if (t[e] !== r) {\n f = f + t[e];\n } else {\n g[g.length] = f;\n f = '';\n }\n }\n g[g.length] = f;\n return g;\n}\n\nprint(c);"}, {"source_code": "readline();\nvar a = c = readline().split(' ')[1], b;\n\nwhile (b = readline()) {\n b = b.split(' ');\n a = a - b[0] + +b[1];\n if (a > c) c = a;\n}\n\nprint(c);"}, {"source_code": "var n = readline();\n\nvar max = 0;\nvar current = 0;\nwhile (n > 0) {\n var m = readline().split(' ');\n current = current - Number(m[0]) + Number(m[1]);\n\n if (current > max)\n max = current;\n\n --n;\n}\n\nprint(max);\n"}, {"source_code": "var n = readline();\n\nvar capacity = 0;\n\nvar passengers=0;\n\nfor(i=0;icapacity){\n\tcapacity = passengers;\n }\n}\n\nprint (capacity);"}, {"source_code": "// Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.\n\n// Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.\n\n// Input\n// The first line contains a single number n (2\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of the tram's stops.\n\n// Then n lines follow, each contains two integers ai and bi (0\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u20091000) \u2014 the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.\n\n// The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. \n// At the last stop, all the passengers exit the tram and it becomes empty. \n// No passenger will enter the train at the last stop. That is, bn\u2009=\u20090. \n\n// Output\n// Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).\n\nvar n = readline()\nvar t = []\nvar sum = 0\nvar max = 0\n\nfor (i = 0; i < n; i++) {\n t.push(readline().split(\" \"));\n if (i === 0){\n sum = +t[0][1];\n max = sum\n }else {\n sum += +t[i][1] - +t[i][0];\n if (sum > max) {\n max = sum\n }\n }\n}\n\nprint(max)\n\n"}, {"source_code": "function main() {\n var input = readline()\n var passenger = [];\n for (; input > 0; input--) {\n passenger.push(readline().split(' '))\n }\n var result = 0;\n var current = 0;\n for (var i = 0, l = passenger.length; i < l; i++) {\n current = current + (passenger[i][1] - passenger[i][0])\n result = current > result ? current : result\n }\n print(result)\n}\nmain()"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exits= new Array();\nvar entries = new Array();\nvar sum = 0;\nvar persons = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = persons+parseInt(entries[z])-parseInt(exits[z]);\n\t}\n\tpersons = persons+parseInt(entries[z])-parseInt(exits[z]);\n}\n\nprint(sum);"}, {"source_code": "var n = readline();\nvar c = 0;\nvar t = 0;\n\nfor(var i=0; iparseInt(i));\n}\n\nvar sum=0;\nvar max=0;\nfor(var i=0;ians){\n ans=cur;\n }\n \n }\n \n print(ans);\n}\nmain();"}, {"source_code": "var numberStopTram = +readline();\nvar maxVolumeTram = 0;\nvar currentVolumeTram = 0;\nfor (numberStopTram; numberStopTram>0; numberStopTram--) {\n var currentStopInfo = readline().split(\" \");\n var passengersOut = +currentStopInfo[0];\n var passengersIn = +currentStopInfo[1];\n currentVolumeTram = currentVolumeTram - passengersOut + passengersIn;\n if (currentVolumeTram > maxVolumeTram) maxVolumeTram = currentVolumeTram;\n}\nprint(maxVolumeTram);"}, {"source_code": "var numberStopTram = +readline();\nvar maxVolumeTram = 0;\nvar currentVolumeTram = 0;\nfor (numberStopTram; numberStopTram>0; numberStopTram--) {\n var currentStopInfo = readline().split(\" \");\n var passengersOut = +currentStopInfo[0];\n var passengersIn = +currentStopInfo[1];\n currentVolumeTram = currentVolumeTram - passengersOut + passengersIn;\n if (currentVolumeTram > maxVolumeTram) maxVolumeTram = currentVolumeTram;\n}\nprint(maxVolumeTram);"}, {"source_code": "n = readline();\n\nvar pas = 0;\nvar max = 0;\n\nfor (var i = 0; i < n; i++) {\n\tab = readline().split(' ').map(Number);\n\tvar a = ab[0], b = ab[1];\n\n\tpas = pas - a + b;\n\n\tif (pas > max) {\n\t\tmax = pas;\n\t};\n};\n\nprint(max);"}, {"source_code": "var n = readline();\nvar ac = 0;\nvar res = 0;\nfor(var i = 0; i < n; ++i){\n var c = readline().split(' ');\n ac += (+c[1] - +c[0]);\n if(ac > res) res = ac;\n} \nprint(res);"}, {"source_code": "var n=parseInt(readline());\nvar p = 0;\nvar max = 0;\nwhile(n--){\n var l=readline().split(' ');\n p+=l[1]-l[0];\n if(p>max) max=p;\n}\nprint(max);"}, {"source_code": "var N = readline() - 0;\n\nvar m = 0;\nvar max = 0;\nfor (var i = 0; i < N; i++) {\n var input = readNums();\n m += input[1] - input[0];\n if (m > max)\n max = m;\n}\nprint(max);\n\nfunction readNums() {\n return readline().split(' ').map(v => v - 0);\n}"}, {"source_code": "n = parseInt(readline());\ncap = 0;\nmaxc = 0;\nfor (var i = 0; i < n; i++){\n\tA = readline().split(\" \");\n\tcap -= parseInt(A[0]);\n\tcap += parseInt(A[1]);\n\tif (cap > maxc) maxc = cap;\n}\nwrite(maxc);\n"}, {"source_code": "var ints = function() {\n\treturn readline().split(' ').map(function(word) {\n\t\treturn parseInt(word)\n\t})\n}\n\nvar n = parseInt(readline()),\n\tm = 0,\n\tc = 0,\n\tp = []\n\nwhile (n > 0) {\n\tp = ints()\n\tc = c - p[0] + p[1]\n\tif (c > m)\n\t\tm = c\n\tn --\n}\n\nprint(m)"}, {"source_code": "var stops = readline();\nvar passengers = 0;\nvar max = [];\n\nfor (var i = 0; i < +stops; i++) {\n\tvar str = readline().match(/\\d{1,4}/g);\n\tvar into = +str[1];\n\tvar out = +str[0];\n\n\tpassengers += (into - out);\n\tmax.push(Math.abs(passengers));\n}\n\nprint(Math.max(...max))\n"}, {"source_code": "var stops = readline();\nstops = parseInt(stops);\nvar max = 0;\nvar current = 0;\nwhile(stops > 0){\n var input = readline().split(\" \").map(x=>parseInt(x));\n var out = input[0];\n var inp = input[1];\n current = (current+inp)-out;\n if(current > max)max = current;\n stops--;\n}\n \nprint(max);"}, {"source_code": ";(function () {\n\tvar n = readline();\n\tvar v = 0;\n\tvar r = 0;\n\tfor(var i = 0; i < n; i++) {\n\t\tvar t = readline().split(' ');\n\t\tr += t[1] - t[0];\n\t\tv = Math.max(v, r);\n\t}\n\n\tprint(v);\n}).call(this);"}, {"source_code": "var arrTram = [];\nvar n = +readline();\nvar m = 0;\nvar arrCheck = [];\nfor(var i = 0; i < n; i++){\n arrTram[i] = readline().split(' ');\n}\nfor(var i = 0; i < n; i++){\n arrTram[i][0] = +arrTram[i][0];\n arrTram[i][1] = +arrTram[i][1];\n\tm = m - arrTram[i][0] + arrTram[i][1];\n\tarrCheck[i] = m;\n//\tprint(+arrTram[i][1]);\n}\narrCheck.sort(function(a, b){\n if(a > b)return -1;\n if(a < b)return 1;\n});\nprint(arrCheck[0]);"}, {"source_code": "var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin,\n newPassenger;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n if (min == 0) {\n exit = arr[1][0];\n newPassenger = arr[0][1];\n }\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j + 1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n if (min == 0) {\n print(exit);\n } else if (min < exit) {\n print(newPassenger);\n } else {\n print(min);\n }"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0\n temp = 0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((temp -out+In)>=minCapac){\n minCapac=temp-out+In;\n\n }\n temp += In - out;\n}\nprint(minCapac);"}, {"source_code": "var numberOfStop = +readline(),\n minCapac = 0,\n curCapac = 0;\nwhile(numberOfStop--){\n var line = readline().split(\" \");\n curCapac += (+line[1])-(+line[0]);\n if(curCapac > minCapac){ minCapac = curCapac }\n}\nprint(minCapac);"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let t = readLine()\n t = parseInt(t)\n let str = '', max = 0, res = 0\n for (let i = 0; i < t; i++) {\n str = readLine().split(\" \")\n str[0] = parseInt(str[0])\n str[1] = parseInt(str[1])\n if (i === 0) {\n max = str[1]\n } else {\n max -= str[0]\n max += str[1]\n }\n \n if (res < max) res = max\n }\n console.log(res)\n}\n\n\n\n\n\n\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let len = +readLine();\n let count = 0;\n let max = 0;\n while (len--) {\n const [exit, enter] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n count -= exit;\n count += enter;\n max = Math.max(max, count);\n }\n console.log(max);\n}\n"}, {"source_code": "var line_number = 0;\nconst cs = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nvar lines = [];\ncs.on(\"line\", (input) => {\n if (input == \"\") {\n cs.close();\n }\n lines.push(input.split(\" \"))\n line_number += 1;\n}).on(\"close\", () => {\n main();\n process.exit();\n});\n\nfunction isOp(str) {\n return str.length === 1 && str.match(/[<=>]/);\n}\nfunction isChr(str) {\n return str.length === 1 && str.match(/[a-z]/i);\n}\nfunction isInt(str) {\n return str.length === 1 && str.match(/[0-9*]/);\n}\n\nfunction print(str) {\n console.log(str);\n}\n\nfunction exit(status = 0) {\n process.exit(status);\n}\n\nfunction predict(test) {\n let op = \"\";\n let ops = [];\n let opVariables = [];\n let limits = [];\n for (let t of test) {\n // console.log(t);\n for (let i = 0; i < t.length; i++) {\n if (isOp(t[i])) {\n op = t[i];\n if (isOp(t[i + 1])) {\n op += t[i + 1];\n i += 1;\n }\n ops.push(op);\n op = \"\";\n } else if (isChr(t[i])) {\n // console.log(t[i])\n op = t[i];\n for (var j = i + 1; j < t.length; j++) {\n if (isChr(t[j]) || isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n opVariables.push(op);\n op = \"\";\n } else {\n if (i == 0 || (i > 0 && isOp(t[i - 1]))) {\n op = t[i];\n let j = i + 1;\n for (; j < t.length; j++) {\n if (isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n limits.push(op);\n op = \"\";\n }\n }\n }\n }\n\n let min = limits[0];\n let max = limits[1];\n\n let pvs = ops.map((o, i) => [o, opVariables[i]]);\n\n for (let pv of pvs) {\n if (pv[1] == undefined) {\n pv[1] = max;\n }\n // print(`${min} ${pv[0]} ${pv[1]} ?`)\n if (eval(`${min}${pv[0]}${pv[1]}`)) {\n // print(` ${min} ${pv[0]} ${pv[1]} true`)\n min = pv[1];\n } else {\n print(\"input error\");\n exit();\n }\n }\n}\n\nvar n;\nfunction main() {\n n = parseInt(lines[0][0],10)\n let d = 0,r=0\n for(let i = 1; i <= lines.slice(1,).length; i++) {\n stops = lines[i].map(x => parseInt(x,10))\n if(d > r )\n r = d\n d = d - stops[0] + stops[1];\n }\n print(r)\n}\n"}, {"source_code": "// author: Oscar Ramos\n\n/// Source Code\n// const input = require('competitive-programming-js').inputReader\n// const { forn } = require('../utils/utils')\n// \n// const n = input.readNumber()\n// \n// let capacity = 0\n// let minCapacity = 0\n// forn(n, () => {\n// const [a, b] = input.readNumberArray()\n// capacity = capacity - a + b\n// minCapacity = Math.max(minCapacity, capacity)\n// })\n// \n// console.log(minCapacity)\n// \n\n!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(n,\"__esModule\",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&\"object\"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:n}),2&t&&\"string\"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,\"a\",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p=\"\",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&\"object\"==typeof n&&!0===n[\"@@functional/placeholder\"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(\" \").map(n=>Number(n))}};var c=\"\";process.stdin.resume(),process.stdin.setEncoding(\"utf8\"),process.stdin.on(\"data\",(function(n){c+=n})).on(\"end\",(function(){e=c.trim().split(\"\\n\").map(n=>n.trim());const{forn:n}=r(3),t=u.readNumber();let o=0,i=0;n(t,()=>{const[n,t]=u.readNumberArray();o=o-n+t,i=Math.max(i,o)}),console.log(i)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).forEach(t)}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError(\"Both arguments to range must be numbers\");for(var r=[],e=n;e {\n inputString = inputString.trim().split('\\n').map(string => string.trim());\n main();\n process.exit();\n}\nconst readLine = () => inputString[currentLine++];\n\nprocess.stdin.on('data', inputStdin => inputString += inputStdin);\nprocess.stdin.on('end', runMain);\nprocess.on('SIGINT', runMain);\n\nfunction main() {\n const n = Number(readLine());\n let max = 0;\n let count = 0;\n for (let i = 0; i < n; i++) {\n const [a, b] = readLine().split(' ').map(num => Number(num));\n count -= a;\n count += b;\n max = Math.max(max, count);\n }\n console.log(max);\n}\n"}, {"source_code": "//Tram\n\nconst {EOL} = require('os');\n\nlet inp = '';\n\nprocess.stdin.on('data', c => inp += c);\n\nprocess.stdin.on('end', () => {\n let lines = inp.split(EOL);\n \n let max = 0, curr = 0;\n for(let i = 1; i <= +lines[0]; i++) {\n \tlet s = lines[i].split(' ').map(c => +c);\n \tcurr -= s[0];\n \tcurr += s[1];\n \tif(curr > max) {\n \t\tmax = curr;\n \t}\n }\n\n process.stdout.write(max + '');\n\n return;\n});"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction isPrime(x) {\n\tlet s = Math.sqrt(x);\n\tlet i = 2;\n\twhile (i <= s) {\n\t\tif (x % i === 0) {\n\t\t\treturn false;\n\t\t}\n\t\ti++;\n\t}\n\treturn true;\n}\n\nfunction main() {\n\tlet n = readLine() >> 0;\n\tlet cap = 0,\n\t\tcurr = 0,\n\t\texit = [],\n\t\tenter = [];\n\twhile (n--) {\n\t\tlet [a, b] = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\t\texit.push(a);\n\t\tenter.push(b);\n\t}\n\n\texit.forEach((p, i) => {\n\t\tcurr -= p;\n\t\tcurr += enter[i];\n\t\tcap = Math.max(cap, curr);\n\t});\n\tconsole.log(cap);\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction readAsInt(){\n return parseInt(readline());\n}\n\nfunction readAsIntList(){\n return readline().split(' ').filter(i => i).map(i => parseInt(i));\n}\n\n\n// Make a Snippet for the code above this and then write your logic in main();\n\n\nfunction main() {\n let n = readAsInt();\n let m = 0;\n let c = 0;\n for(let i = 1; i <= n; i++) {\n let [a, b] = readAsIntList();\n c = c - a + b;\n if (c > m) m = c;\n }\n console.log(m);\n}\n \n\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\n\nlet currentLine = 0;\nlet inputString = \"\";\n\nprocess.stdin.on(\"data\", (raw_data) => {\n inputString += raw_data;\n});\n\nprocess.stdin.on(\"end\", (_) => {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((line) => {\n return line.trim();\n });\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n/******** Main function*************/\n\nfunction main() {\n var n = +readLine();\n\n var arr = [];\n for (var i = 0; i < n; i++) {\n var inp = readLine().split(\" \").map(Number);\n arr.push(inp);\n }\n\n var enter = 0;\n var exit = 0;\n var result = [];\n for (var k = 0; k < n; k++) {\n for (var j = 1; j < 2; j += 2) {\n enter += arr[k][j];\n }\n for (var m = 0; m < 2; m += 2) {\n exit += arr[k][m];\n }\n result.push(enter - exit);\n }\n var minimumPossibleCapacity = Math.max(...result);\n console.log(minimumPossibleCapacity);\n}\n"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0\n});\n// txt.shift();\nfor (let index = 0; index < txt.length; index++) {\n if(!isNaN(txt[index]*1)){\n let tab=[]\n for (let i = index+1; i < index+txt[index]*1+1; i++) {\n tab.push(txt[i].split(\" \").filter(data=>{return data.length>0}).map(data=>{return data*1}));\n }\n doit(tab);\n }\n}\n\nfunction doit(tab) {\n let arr=[]\n let pnt=0;\n tab.forEach(data => {\n pnt-=data[0];\n arr.push(pnt);\n pnt+=data[1]\n arr.push(pnt)\n });\n console.log(Math.max(...arr)); \n}"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n\n// Write your code here\nfunction nameLookUp(str) {\n let tramLines = str.trim().split('\\n');\n let capacity = [0];\n for (let i = 1; i <= +tramLines[0]; i++) {\n\n let stops = tramLines[i].trim().split(' ').map((num) => Number(num));\n let currentStopCapacity = capacity[capacity.length - 1] - stops[0];\n capacity.push(stops[1] + currentStopCapacity);\n }\n\n return Math.max(...capacity).toString();\n}"}, {"source_code": "const readLine = require('readline').createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst input = [];\nreadLine.on('line', line => input.push(line));\nconst tram = () => {\n const n = +input.shift();\n let q = 0;\n let max = 0;\n for (let i = 0; i < n; i++) {\n let row = input[i].split(' ').map(x => +x);\n q -= row[0];\n q+=row[1];\n if (q > max) {\n max = q;\n }\n }\n console.log(max);\n\n};\n\n\nreadLine.on('close', tram);\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.replace(/\\s*$/, '')\n .split('\\n')\n .map(str => str.replace(/\\s*$/, ''));\n\n main();\n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let n = parseInt(readLine(), 10);\n let ans = 0;\n let passInside = 0;\n for (let i = 0; i < n; i++) {\n let arr = readLine()\n .split(' ')\n .map(value => parseInt(value));\n\n passInside = passInside - arr[0] + arr[1];\n if (passInside > ans) {\n ans = passInside;\n }\n }\n console.log(ans);\n}"}], "negative_code": [{"source_code": "var stops=+readline(),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac= minCapac+ (In-out);\n}\nprint(minCapac);\n"}, {"source_code": "var stops=+readline(),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \");\n if((minCapac -(+outAndIn[0])+(+outAndIn[1]))>minCapac)\n minCapac= minCapac+ ((+outAndIn[1])-(+outAndIn[0]));\n}\nprint(minCapac);\n"}, {"source_code": " var numberOfStops = readline()\n var currentNumberOfPassengers = 0\n var result = 0\n\n for (var i = 0; i < numberOfStops; i++) {\n const stopData = readline().split(' ').map(function (number) { return parseInt(number, 10) })\n currentNumberOfPassengers = currentNumberOfPassengers - stopData[0] + stopData[1]\n if (currentNumberOfPassengers > result) (result = currentNumberOfPassengers)\n }\n\n print(result)"}, {"source_code": "var tram = 0, ans = 0, n = readline(), arr = [];\nn = Number(n);\nvar i;\nfor(i=0;i= 2){\n confirmed ++;\n }\n}\nprint(confirmed);\n"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c;\n}\nprint(a); //console.log"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c;\n}\nprint(a); //console.log"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t\ttemp=0;\n\t\tc=0;\n\t temp = c;\n}\nprint(Math.abs(a)); //conso"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c;\n}\nprint(Math.abs(a)); //console.log"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c;\n}\nprint(a); //console.log"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t {\n\t\ta = temp;\n\n\t }\n\t temp = c;\n\t if(n==i){\n\ttemp = 0;\n c = 0; \n\t }\n}\nprint(Math.abs(a)); //console.log"}, {"source_code": "var n = readline();\nvar c = 0;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t {\n\t\ta = temp;\n\t\ttemp=0;\n\t\tc=0;\n\t\t}\n\t temp = c;\n}\nprint(Math.abs(a)); //console.log"}, {"source_code": "var n = readline();\nvar c = 3;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c;\n}"}, {"source_code": "var n = readline();\nvar c = 3;\nvar temp = 0;\nvar a = 0;\nfor (var i=0; ic)\n\t\ta = temp;\n\t temp = c; \n}"}, {"source_code": "line = readline(), ans = 0, cur = 0;\nwhile (line = readline()) {\n line = line.split(' ').map(function(x) { return +x; });\n cur = Math.max(0, ans - line[0] +line[1]);\n ans = Math.max(ans, cur);\n}\nprint(ans);\n"}, {"source_code": "var paradas = parseInt(readline()); \nvar cantidadMax = 0;\nvar difSubBaj = new Array();\nvar final = new Array();\nvar sum = new Array();\n\nfunction numeroPlazas (sitios) {\n for (i=0; i sum) {\n sum = persons+parseInt(entries[z])-parseInt(exits[z]);\n }\n persons = persons+parseInt(entries[z])-parseInt(exits[z]);\n }\n}\n\nprint(calcular(lines));"}, {"source_code": "var paradas = parseInt(readline()); \nvar cantidadMax = 0;\nvar difSubBaj = new Array();\n\nfunction numeroPlazas (sitios) {\n for (i=0; i sum) {\n sum = personas+parseInt(entradas[z])-parseInt(salidas[z]);\n }\n personas = personas+parseInt(entradas[z])-parseInt(salidas[z]);\n }\n\n}\nprint(calculo(lineas));"}, {"source_code": "var paradas = parseInt(readline()); \nvar cantidadMax = 0;\nvar difSubBaj = new Array();\n\nfunction numeroPlazas (sitios) {\n for (i=0; i sum) {\n sum = personas+parseInt(entradas[z])-parseInt(salidas[z]);\n }\n personas = personas+parseInt(entradas[z])-parseInt(salidas[z]);\n }\n\n}\nprint(calculo(valor));"}, {"source_code": "var paradas = parseInt(readline()); \nvar cantidadMax = 0;\nvar difSubBaj = new Array();\n\nfunction numeroPlazas (sitios) {\n for (i=0; i sum) {\n sum = persons+parseInt(entries[z])-parseInt(exits[z]);\n }\n persons = persons+parseInt(entries[z])-parseInt(exits[z]);\n }\n}\n\nprint(calcular(valor));\n"}, {"source_code": "var numberOfStops = readline();\nvar minCapacity = 0;\n\nfor(var i = 0; i < numberOfStops; i++){\n var line = readline().split(' ');\n var exitNumber = line[0];\n var entryNumber = line[1];\n \n minCapacity -= parseInt(exitNumber);\n minCapacity += parseInt(entryNumber);\n}\n\nprint(minCapacity);"}, {"source_code": "var numberOfStops = readline();\nvar minCapacity = 0;\n\nfor(var i = 0; i < numberOfStops; i++){\n var line = readline().split(' ');\n var exitNumber = line[0];\n var entryNumber = line[1];\n \n minCapacity -= exitNumber;\n minCapacity += entryNumber;\n}\n\nprint(minCapacity);"}, {"source_code": "function detectMax(out, into)\n{\n return into - out;\n}\n\n{\n var num = parseInt(readline());\n var max = 0, medium = 0;\n for (var i = 1; i <= num; i++)\n {\n var input = readline();\n input = input.split(' ');\n medium += detectMax(parseInt(input[0]), parseInt(input[2]));\n if (medium > max) max = medium;\n }\n print(max);\n}"}, {"source_code": "function detectMax(out, into)\n{\n if (into - out > 0)\n return into - out;\n else return 0;\n}\n\n{\n var number = parseInt(readline());\n var max = 0;\n for (var i = 1; i <= number; i++)\n {\n var input = readline();\n max += detectMax(parseInt(input[0]), parseInt(input[3]));\n }\n print(max);\n}"}, {"source_code": "function detectMax(out, into)\n{\n if (into - out > 0)\n return into - out;\n else return 0;\n}\n\n{\n var number = parseInt(readline());\n var max = 0;\n for (var i = 1; i <= number; i++)\n {\n var input = readline();\n max += detectMax(parseInt(input[0]), parseInt(input[3]));\n }\n}"}, {"source_code": "function detectMax(out, into)\n{\n return into - out;\n}\n\n{\n var num = parseInt(readline());\n var max = 0, medium = 0;\n for (var i = 1; i <= num; i++)\n {\n var input = readline();\n input = input.split(' ');\n medium += detectMax(input[0], input[2]);\n if (medium > max) max = medium;\n }\n print(max);\n}"}, {"source_code": "function detectMax(out, into)\n{\n return into - out;\n}\n\n{\n var num = parseInt(readline());\n var max = 0, medium = 0;\n for (var i = 1; i <= num; i++)\n {\n var input = readline();\n medium += detectMax(input[0], input[2]);\n if (medium > max) max = medium;\n }\n print(max);\n}"}, {"source_code": "function detectMax(out, into)\n{\n if (into - out > 0)\n return into - out;\n else return 0;\n}\n\n{\n var num = parseInt(readline());\n var max = 0;\n for (var i = 1; i <= num; i++)\n {\n var input = readline();\n max += detectMax(input[0], input[2]);\n }\n print(max);\n}"}, {"source_code": "readline(); for(var s, a, b, now, ans = 0; s = readline(); ) {\n s = s.split( ' ' ); a = s[0] - ''; b = s[1] - '';\n now = now - a + b;\n ans = Math.max( now, ans );\n}\nprint( ans );"}, {"source_code": "var stops = readline();\nvar total = 0;\nvar max = 0;\nwhile(stops--){\n var pass = readline().split(' ');\n total = total - pass[0] + pass[1];\n print(pass[0]);\n print(pass[1]);\n print(total);\n}\n"}, {"source_code": "var stops = readline();\nvar total = 0;\nvar max = 0;\nwhile(stops--){\n var pass = readline().split(' ');\n total = total - pass[0] + pass[1];\n if(total >= max){\n max = total;\n }\n}\n\nprint(max);"}, {"source_code": "var n = parseInt(readline(), 10), ab = [], minCap = 0;\n\nfor(var i=1; i<=n-1; i++) {\n ab = readline().split(' ').map(el => parseInt(el, 10));\n if((minCap - ab[0] + ab[1]) > minCap) minCap = minCap - ab[0] + ab[1];\n}\n\nprint(minCap);"}, {"source_code": "var n = readline()\nvar str = []\nfor (var i = 0; i < n; i++) {\n var line = readline()\n str += line.replace(/\\s/g, '')\n}\nstr = str.split(\"\")\nvar rez = 0\nvar trig = true\nvar bol = 0\nfor (var i = 1; i < str.length - 1; i++) {\n\tif(trig){\n\t\trez += Number(str[i])\n\t\ttrig = false\n\t\tif(rez > bol){\n\t\t\tbol = rez\n\t\t}\n\t} else {\n\t\trez -= Number(str[i])\n\t\ttrig = true\n\t}\n}\nprint(bol)"}, {"source_code": "readline();\nvar a = readline()[2], b, c = 0;\n\nwhile (b = readline()) {\n a = a - b[0] + +b[2];\n if (a > c) c = a;\n}\n\nprint(c);"}, {"source_code": "readline();\nvar a = readline().split(' ')[1], b, c = 0;\n\nwhile (b = readline()) {\n b = b.split(' ');\n a = a - b[0] + +b[1];\n if (a > c) c = a;\n}\n\nprint(c);"}, {"source_code": "// Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.\n\n// Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.\n\n// Input\n// The first line contains a single number n (2\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of the tram's stops.\n\n// Then n lines follow, each contains two integers ai and bi (0\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u20091000) \u2014 the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.\n\n// The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. \n// At the last stop, all the passengers exit the tram and it becomes empty. \n// No passenger will enter the train at the last stop. That is, bn\u2009=\u20090. \n\n// Output\n// Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).\n\nvar n = readline()\nvar t = []\nvar max = 0\n\nfor (i = 0; i < n; i++) {\n t.push(readline().split(\" \"));\n if (i > 0 && (+t[i-1][1] - +t[i][0] + +t[i][1]) > max) {\n max = +t[i-1][1] - +t[i][0] + +t[i][1]\n }\n}\n\nprint(max)\n\n"}, {"source_code": "// Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.\n\n// Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.\n\n// Input\n// The first line contains a single number n (2\u2009\u2264\u2009n\u2009\u2264\u20091000) \u2014 the number of the tram's stops.\n\n// Then n lines follow, each contains two integers ai and bi (0\u2009\u2264\u2009ai,\u2009bi\u2009\u2264\u20091000) \u2014 the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.\n\n// The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. \n// At the last stop, all the passengers exit the tram and it becomes empty. \n// No passenger will enter the train at the last stop. That is, bn\u2009=\u20090. \n\n// Output\n// Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).\n\nvar n = readline()\nvar t = []\nvar sum = 0\nvar max = 0\n\nfor (i = 0; i < n; i++) {\n t.push(readline().split(\" \"));\n if (i === 0){\n sum = +t[0][1]\n }else {\n sum += +t[i][1] - +t[i][0]\n if (sum > max) {\n max = sum\n }\n }\n}\n\nprint(max)\n\n"}, {"source_code": "var tram = 0, ans = 0, n = readline(), arr = [];\nn = Number(n);\nvar i;\nfor(i=0;i max) {\n max = answer;\n }\n}\n\nwrite(max);"}, {"source_code": "var data = parseInt(readline()), stop = [], answer = 0, max = 0;\n\nfor (var i = 0; i < data; i++) {\n\tstop = readline().split(\" \");\n}\n\nfor (var i = 0; i < data; i++) {\n\tanswer = answer - parseInt(data[0] + data[1]);\n\n\tif (answer > max) {\n\t\tmax = answer;\n\t}\n}\n\nwrite(max);"}, {"source_code": "var input = readline().split('\\n');\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline();\nvar n = parseInt(input[0]);\n\nvar exit = 0,\n\tenter = 0,\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=1; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(\"%d\", parseInt(maxCap));"}, {"source_code": "var input = readline();\nvar n = parseInt(input[0]);\n\nvar exit = 0;\n\tenter = 0;\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=1; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline();\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(\"%d\", maxCap);"}, {"source_code": "var input = readline();\nvar n = parseInt(input[0]);\n\nvar exit = 0;\n\tenter = 0;\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline();\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=1; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "var input = readline().split(' ');\nvar n = parseInt(input[0]);\n\nvar cap = [],\n\texit = [],\n\tenter = [],\n cur = 0;\n\nvar maxCap = 0;\nfor (var i=0; i= cur) ? maxCap : cur;\n}\n\nprint(maxCap);"}, {"source_code": "\nvar inputStopsStr = readline();\nvar intialPass;\nvar leftPass;\nvar inputStop = parseInt(inputStopsStr);\nfor (var i = 0; i < inputStop; i++) {\n\tvar input = readline().split(\" \");\n\tvar firstParams = parseInt(input[0]);\n\tvar secondParams = parseInt(input[1]);\n\tif (i === 0) {\n\t\tintialPass = firstParams;\n\t\tleftPass = intialPass + secondParams;\n\t}\n\telse {\n\t\tleftPass = leftPass - firstParams;\n\t\tleftPass = leftPass + secondParams;\n\t}\n\tif (i == (inputStop - 1)) {\n\t\tprint (leftPass);\n\t}\n}\n"}, {"source_code": "var inputStopsStr = readline();\nvar intialPass;\nvar leftPass;\nvar inputStop = parseInt(inputStopsStr);\nfor (var i = 0; i < inputStop; i++) {\n\tvar input = readline().split(\" \");\n\tvar firstParams = parseInt(input[0]);\n\tvar secondParams = parseInt(input[1]);\n\tif (i === 0) {\n\t\tintialPass = firstParams;\n\t\tleftPass = intialPass + secondParams;\n\t}\n\telse {\n\t\tleftPass -= firstParams;\n\t\tleftPass += secondParams;\n\t}\n}\nprint (leftPass);"}, {"source_code": "var inputStopsStr = readline();\nvar intialPass;\nvar leftPass;\nvar inputStop = parseInt(inputStopsStr);\nfor (var i = 0; i < inputStop; i++) {\n\tvar input = readline().split(\" \");\n\tvar firstParams = parseInt(input[0]);\n\tvar secondParams = parseInt(input[1]);\n\tif (i === 0) {\n\t\tintialPass = firstParams;\n\t\tleftPass = intialPass + secondParams;\n\t}\n\telse {\n\t\tleftPass -= firstParams;\n\t\tleftPass += secondParams;\n\t}\n\tif (i == (inputStop - 1)) {\n\t\tprint (leftPass);\n\t}\n}\n"}, {"source_code": "var inputStopsStr = readline();\nvar intialPass;\nvar leftPass;\nvar inputStop = parseInt(inputStopsStr);\nfor (var i = 0; i < inputStop; i++) {\n\tvar input = readline().split(\" \");\n\tvar firstParams = parseInt(input[0]);\n\tvar secondParams = parseInt(input[1]);\n\tif (i == 0) {\n\t\tintialPass = firstParams;\n\t\tleftPass = intialPass + secondParams;\n\t}\n\telse {\n\t\tleftPass = leftPass - firstParams;\n\t\tleftPass = leftPass + secondParams;\n\t}\n\tif (i == (inputStop - 1)) {\n\t\tprint (leftPass);\n\t}\n}\n"}, {"source_code": "var n=parseInt(readline());\nvar p = 0;\nvar max = 0;\nwhile(n--){\n var l=parseInt(readline());\n p+=l[1]-l[0];\n if(p>max) max=p;\n}\nprint(max);"}, {"source_code": "var stops = readline();\nvar passengers = 0;\nvar max = [];\n\nfor (var i = 0; i < +stops; i++) {\n\tvar str = readline().match(/\\d/g);\n\tvar into = +str[1];\n\tvar out = +str[0];\n\n\tpassengers += (into - out);\n\tmax.push(Math.abs(passengers));\n}\n\nprint(Math.max(...max))\n"}, {"source_code": "var stops = readline();\nvar passengers = 0;\nvar max = [];\n\nfor (var i = 0; i < +stops; i++) {\n\tvar str = readline().match(/\\d{1,3}/g);\n\tvar into = +str[1];\n\tvar out = +str[0];\n\n\tpassengers += (into - out);\n\tmax.push(Math.abs(passengers));\n}\n\nprint(Math.max(...max))\n"}, {"source_code": "\nvar stops = readline();\nvar max = 0;\nvar current = 0;\nwhile(stops > 0){\n var input = readline();\n var out = input[0];\n var inp = input[1];\n current = (current+inp)-out;\n if(current > max)max = current;\n stops--;\n}\n \nprint(max);"}, {"source_code": "var stops = readline();\nvar max = 0;\nvar current = 0;\nwhile(stops > 0){\n var input = readline();\n var out = input[0];\n var inp = input[1];\n current = inp-out;\n if(current > max)max = current;\n stops--;\n}\n\nprint(max);"}, {"source_code": "\n var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n if (arr[1][0] == 1) {\n exit = 1;\n }\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j + 1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n if (min == 0 && exit == 1) {\n print(1);\n } else {\n print(min);\n }\n "}, {"source_code": "\n var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n exit = arr[j][0];\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j+1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n print(min);\n "}, {"source_code": "\n var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n if (min == 0) {\n exit = arr[1][0];\n }\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j + 1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n if (min == 0) {\n print(exit);\n } else {\n print(min);\n }\n "}, {"source_code": "\n var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n if (min == 0) {\n exit = arr[1][0];\n }\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j + 1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n if (min == 0) {\n print(exit);\n } else if (min < exit) {\n print(exit);\n } else {\n print(min);\n }\n "}, {"source_code": "\n var n = parseInt(readline());\n var arr = [],\n min = 0,\n remaining = 0,\n exit = 0,\n newmin;\n for (var i = 0; i < n; i++) {\n var line = readline()\n .split(\" \")\n .map((el) => parseInt(el));\n arr.push(line);\n }\n for (var j = 0; j < arr.length - 1; j++) {\n if (min == 0) {\n exit = arr[j +1][0];\n }\n if (newmin == undefined) {\n remaining = arr[j][1] - arr[j + 1][0];\n } else {\n remaining = newmin - arr[j + 1][0];\n }\n newmin = remaining + arr[j + 1][1];\n if (newmin > min) {\n min = newmin;\n }\n }\n if (min == 0) {\n print(exit);\n } else {\n print(min);\n }\n "}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac= minCapac+ (In-out);\n}\nprint(minCapac);\n"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0;\n \nprint(6);\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac=minCapac-out+In;\n print(minCapac);\n}\n"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac=minCapac-out+In;\n \n}\nprint(minCapac);"}, {"source_code": "var numberOfStop = +readline(),\n minCapac = 0,\n curCapac = 0;\nwhile(numberOfStop--){\n var line = readline().split(\" \");\n curCapac = (+line[1])-(+line[0]);\n if(curCapac > minCapac){ minCapac = curCapac }\n}\nprint(minCapac);"}, {"source_code": "var stops=+readline(),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \");\n if(minCapac -(+outAndIn[0])+(+outAndIn[1])>minCapac)\n minCapac+= ((+outAndIn[1])-(+outAndIn[0]));\n}\nprint(minCapac);\n"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac=minCapac-out+In;\n print(minCapac);\n}\nprint(6);"}, {"source_code": "var stops=+readline(),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = +outAndIn[0],\n In = +outAndIn[1];\n if((minCapac -out+In)>minCapac)\n minCapac= minCapac+ (In-out);\n}\nprint(minCapac);\n"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((minCapac -out+In)>minCapac)\n minCapac= minCapac+ (In-out);\n print(minCapac);\n}\n\n"}, {"source_code": "var stops=parseInt(readline()),\n minCapac=0\n temp = 0;\nwhile(stops--){\n var outAndIn = readline().split(\" \"),\n out = parseInt(outAndIn[0]),\n In = parseInt(outAndIn[1]);\n if((temp -out+In)>=minCapac){\n minCapac=temp-out+In;\n temp += In - out;\n }\n}\nprint(minCapac);"}, {"source_code": "var line_number = 0;\nconst cs = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nvar lines = [];\ncs.on(\"line\", (input) => {\n if (input == \"\") {\n cs.close();\n }\n lines.push(input.split(\" \"))\n line_number += 1;\n}).on(\"close\", () => {\n main();\n process.exit();\n});\n\nfunction isOp(str) {\n return str.length === 1 && str.match(/[<=>]/);\n}\nfunction isChr(str) {\n return str.length === 1 && str.match(/[a-z]/i);\n}\nfunction isInt(str) {\n return str.length === 1 && str.match(/[0-9*]/);\n}\n\nfunction print(str) {\n console.log(str);\n}\n\nfunction exit(status = 0) {\n process.exit(status);\n}\n\nfunction predict(test) {\n let op = \"\";\n let ops = [];\n let opVariables = [];\n let limits = [];\n for (let t of test) {\n // console.log(t);\n for (let i = 0; i < t.length; i++) {\n if (isOp(t[i])) {\n op = t[i];\n if (isOp(t[i + 1])) {\n op += t[i + 1];\n i += 1;\n }\n ops.push(op);\n op = \"\";\n } else if (isChr(t[i])) {\n // console.log(t[i])\n op = t[i];\n for (var j = i + 1; j < t.length; j++) {\n if (isChr(t[j]) || isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n opVariables.push(op);\n op = \"\";\n } else {\n if (i == 0 || (i > 0 && isOp(t[i - 1]))) {\n op = t[i];\n let j = i + 1;\n for (; j < t.length; j++) {\n if (isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n limits.push(op);\n op = \"\";\n }\n }\n }\n }\n\n let min = limits[0];\n let max = limits[1];\n\n let pvs = ops.map((o, i) => [o, opVariables[i]]);\n\n for (let pv of pvs) {\n if (pv[1] == undefined) {\n pv[1] = max;\n }\n // print(`${min} ${pv[0]} ${pv[1]} ?`)\n if (eval(`${min}${pv[0]}${pv[1]}`)) {\n // print(` ${min} ${pv[0]} ${pv[1]} true`)\n min = pv[1];\n } else {\n print(\"input error\");\n exit();\n }\n }\n}\n\nvar n;\nfunction main() {\n n = parseInt(lines[0][0],10)\n let d = 0\n for(let i = 1; i <= lines.slice(1,).length; i++) {\n stops = lines[i].map(x => parseInt(x,10))\n if(d < d-stops[0]+stops[1] )\n d = d - stops[0] + stops[1]\n }\n print(d)\n}\n"}, {"source_code": "var line_number = 0;\nconst cs = require(\"readline\").createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nvar lines = [];\ncs.on(\"line\", (input) => {\n if (input == \"\") {\n cs.close();\n }\n lines.push(input.split(\" \"))\n line_number += 1;\n}).on(\"close\", () => {\n main();\n process.exit();\n});\n\nfunction isOp(str) {\n return str.length === 1 && str.match(/[<=>]/);\n}\nfunction isChr(str) {\n return str.length === 1 && str.match(/[a-z]/i);\n}\nfunction isInt(str) {\n return str.length === 1 && str.match(/[0-9*]/);\n}\n\nfunction print(str) {\n console.log(str);\n}\n\nfunction exit(status = 0) {\n process.exit(status);\n}\n\nfunction predict(test) {\n let op = \"\";\n let ops = [];\n let opVariables = [];\n let limits = [];\n for (let t of test) {\n // console.log(t);\n for (let i = 0; i < t.length; i++) {\n if (isOp(t[i])) {\n op = t[i];\n if (isOp(t[i + 1])) {\n op += t[i + 1];\n i += 1;\n }\n ops.push(op);\n op = \"\";\n } else if (isChr(t[i])) {\n // console.log(t[i])\n op = t[i];\n for (var j = i + 1; j < t.length; j++) {\n if (isChr(t[j]) || isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n opVariables.push(op);\n op = \"\";\n } else {\n if (i == 0 || (i > 0 && isOp(t[i - 1]))) {\n op = t[i];\n let j = i + 1;\n for (; j < t.length; j++) {\n if (isInt(t[j])) {\n op += t[j];\n i = j;\n } else break;\n }\n limits.push(op);\n op = \"\";\n }\n }\n }\n }\n\n let min = limits[0];\n let max = limits[1];\n\n let pvs = ops.map((o, i) => [o, opVariables[i]]);\n\n for (let pv of pvs) {\n if (pv[1] == undefined) {\n pv[1] = max;\n }\n // print(`${min} ${pv[0]} ${pv[1]} ?`)\n if (eval(`${min}${pv[0]}${pv[1]}`)) {\n // print(` ${min} ${pv[0]} ${pv[1]} true`)\n min = pv[1];\n } else {\n print(\"input error\");\n exit();\n }\n }\n}\n\nvar n;\nfunction main() {\n n = parseInt(lines[0][0],10)\n let d = 0\n for(let i = 1; i < lines.slice(1,).length; i++) {\n // if (i == 0)\n stops = lines[i].map(x => parseInt(x,10))\n if(d < d-stops[0]+stops[1] )\n d = d - stops[0] + stops[1]\n }\n print(d)\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\n\nlet ans = 0;\nlet count = 0;\n\nrl.on('line', (d) => {\n if (count === 0) {\n count++;\n return;\n }\n\n [exit, enter] = d.split(' ').map(Number);\n ans = Math.max(ans + enter - exit, ans);\n\n count++;\n});\n\nrl.on('close', () => {\n console.log(ans);\n});"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n// Make a Snippet for the code above this and then write your logic in main();\n \n \nfunction main() {\n\t\tvar arr = [...inputString]; \n \n\t\tarr.shift();\n\t\t\n\t\tconsole.log(arr.reduce((prev, cur) => {\n\t\t var [a, b] = cur.split(' ').map(el => parseInt(el, 10));\n\t\t return prev - a + b > prev ? prev - a + b : prev;\n\t\t}, 0));\n}\n"}, {"source_code": "// Sample code to perform I/O:\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nvar stdin_input = \"\";\n\nprocess.stdin.on(\"data\", function (input) {\n stdin_input += input; // Reading input from STDIN\n});\n\nprocess.stdin.on(\"end\", function () {\n main(stdin_input);\n});\n\nfunction main(input) {\n let output = nameLookUp(input);\n process.stdout.write(output); // Writing output to STDOUT\n}\n\n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n\n\n// Write your code here\nfunction nameLookUp(str) {\n let tramLines = str.trim().split('\\n');\n let capacity = [0];\n for (let i = 1; i <= +tramLines[0]; i++) {\n\n if (i === 1) {\n let stops = tramLines[i].trim().split(' ').map((num) => Number(num));\n capacity.push(stops[1]);\n }\n else {\n let stopsBack = tramLines[i - 1].trim().split(' ').map((num) => Number(num));\n let stops = tramLines[i].trim().split(' ').map((num) => Number(num));\n let currentStopCapacity = stopsBack[1] - stops[0];\n capacity.push(stops[1] + currentStopCapacity);\n }\n\n }\n return Math.max(...capacity).toString();\n}"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n var ans = 0,\n namche = 0,\n loopNumber = 1;\n while (T--) {\n var [a, b] = readLine().split(\" \").map(Number);\n namche = a - b;\n if (namche < 0) {\n ans += namche;\n }\n }\n console.log(Math.abs(ans));\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n var max = 0,\n current = 0;\n while (T--) {\n var [a, b] = readLine().split(\" \").map(Number);\n current -= a;\n current += b;\n if (current > max) {\n max = current;\n }\n }\n // console.log(max);\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n var T = +readLine();\n var total = 0,\n down = 0;\n while (T--) {\n var [a, b] = readLine().split(\" \").map(Number);\n down = b - a;\n total += a;\n }\n console.log(total - Math.abs(down));\n}\n"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exits= new Array();\nvar entries = new Array();\nvar sum = 0;\nvar persons = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = persons+entries[z]-exits[i];\n\t}\n\tpersons = persons+entries[z]-exits[i]\n}\n\nprint(sum);"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exits= new Array();\nvar entries = new Array();\nvar sum = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = exits[z]+entries[z]-exits[z+1];\n\t}\n}\n\nprint(sum);"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exit = new Array();\nvar entry = new Array();\nvar sum = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = exit[z]+entry[z]-exit[z+1];\n\t}\n}\n\nprint(sum);\n"}, {"source_code": "var lines = readline();\nlines = parseInt(lines);\nvar exit = new Array();\nvar entry = new Array();\nvar sum = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = exit[z]+entry[z]-exit[z+1];\n\t}\n}\n\nprint(sum);"}, {"source_code": "var lines = parseInt(readline());\nvar exit = new Array();\nvar entry = new Array();\nvar sum = 0;\n\nfor (var i=0, j=0; i sum) {\n\t\tsum = exit[z]+entry[z]-exit[z+1];\n\t}\n}\n\nprint(sum);"}, {"source_code": "var print = this.print || require('lol-io').print\nvar write = this.write || require('lol-io').write\nvar readline = this.readline || require('lol-io').readline\n\n\nvar s=parseInt(readline().split(' ')[0]);\nvar arr=[];\nfor(var i=0;iparseInt(i));\n}\n\nvar sum=0;\nvar max=0;\nfor(var i=0;i stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tconst dp = []; dp[-1] = 0;\r\n\t\tconst sum = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (sum[a[i]] == undefined) sum[a[i]] = 0;\r\n\r\n\t\t\tdp[i] = dp[i-1] + sum[a[i]];\r\n\t\t\tsum[a[i]] += i + 1;\r\n\t\t}\r\n\r\n\t\tlet ans = 0n;\r\n\t\tfor (let i = 0; i < n; i++) ans += BigInt(dp[i]);\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n", "positive_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const ar = (await getLine()).split(' ').map(num => parseInt(num));\r\n const calc = {};\r\n for(let i = 0; i < ar.length; i++) {\r\n if (!calc[ar[i]]) {\r\n calc[ar[i]] = [];\r\n }\r\n const m = calc[ar[i]];\r\n m.push({index: BigInt(i), sum: BigInt(n - i)});\r\n if (m.length > 1) {\r\n m[m.length - 1].sum += m[m.length - 2].sum;\r\n }\r\n }\r\n\r\n let res = BigInt(0);\r\n for(let val in calc) {\r\n let m = calc[val];\r\n for(let i = 0; i < m.length - 1; i++) {\r\n res += (m[i].index + BigInt(1)) * (m[m.length - 1].sum - m[i].sum);\r\n }\r\n }\r\n\r\n console.log(res.toString());\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 afternoon\r\n */\r\n\r\nconst solve = (n, a) => {\r\n let res = 0n;\r\n let m = new Map();\r\n for (let i = 0; i < n; i++) {\r\n res += BigInt(m.get(a[i]) || 0) * BigInt((n - i));\r\n let plus = BigInt(i + 1);\r\n m.set(a[i], BigInt(m.get(a[i]) || 0) + plus);\r\n }\r\n pr(res.toString());\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 afternoon\r\n */\r\nconst solve = (n, a) => {\r\n // pr(n, a)\r\n let res = 0n;\r\n let m = new Map();\r\n for (let i = 0n; i < n; i++) {\r\n res += (m.get(a[i]) || 0n) * (n - i);\r\n // pr(m, res);\r\n let plus = i + 1n;\r\n m.set(a[i], (m.get(a[i]) || 0n) + plus);\r\n // pr(m);\r\n }\r\n pr(res.toString());\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => BigInt(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var stdin_input = \"\";\r\nvar stdin_input_itr;\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { stdin_input_itr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => stdin_input_itr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nvar deb; const log = msg => (typeof deb != \"undefined\") && console.log(\"DEBUG\", msg);\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst n = rn();\r\n\t\tconst a = rna();\r\n\r\n\t\tlet ans = 0n;\r\n\t\tconst sum = [];\r\n\t\tfor (let i = 0; i < n; i++) {\r\n\t\t\tif (sum[a[i]] == undefined) sum[a[i]] = 0;\r\n\r\n\t\t\tans += BigInt(sum[a[i]] * (n - i));\r\n\t\t\tsum[a[i]] = sum[a[i]] + i + 1;\r\n\t\t}\r\n\t\tconsole.log(ans.toString());\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, arr))\n }\n});\n\nfunction solve(n, arr) {\n let total = 0n\n const map = {} // x -> sum\n arr.forEach((x, i) => {\n let sum = map[x] || 0n\n total = add(total, mul(sum, BigInt(n - i)))\n // console.log(x, sum, sum * (n - i))\n sum += BigInt(i + 1)\n map[x] = sum\n })\n return total.toString()\n}\nfunction add(a, b) {\n return a + b\n}\nfunction mul(a, b) {\n return a * b\n}"}], "negative_code": [{"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const ar = (await getLine()).split(' ').map(num => parseInt(num));\r\n const calc = {};\r\n for(let i = 0; i < ar.length; i++) {\r\n if (!calc[ar[i]]) {\r\n calc[ar[i]] = [];\r\n }\r\n const m = calc[ar[i]];\r\n m.push({index: i, sum: n - i});\r\n if (m.length > 1) {\r\n m[m.length - 1].sum += m[m.length - 2].sum;\r\n }\r\n }\r\n\r\n let res = 0;\r\n for(let val in calc) {\r\n let m = calc[val];\r\n for(let i = 0; i < m.length - 1; i++) {\r\n res += (m[i].index + 1) * (m[m.length - 1].sum - m[i].sum);\r\n }\r\n }\r\n\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "const lib = require('readline');\r\nconst rl = lib.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\n\r\nconst getLine = (function () {\r\n const getLineGen = (async function* () {\r\n for await (const line of rl) {\r\n yield line;\r\n }\r\n })();\r\n return async () => {\r\n let next;\r\n do {\r\n next = (await getLineGen.next());\r\n } while (!next.done && next.value === '');\r\n return next.value;\r\n };\r\n})();\r\n\r\nlet solve = async () => {\r\n const nsc = parseInt(await getLine());\r\n for(let sc = 0; sc < nsc; sc++) {\r\n const n = parseInt(await getLine());\r\n const ar = (await getLine()).split(' ').map(num => parseInt(num));\r\n const calc = {};\r\n for(let i = 0; i < ar.length; i++) {\r\n if (!calc[ar[i]]) {\r\n calc[ar[i]] = [];\r\n }\r\n const m = calc[ar[i]];\r\n m.push({index: i, sum: n - i});\r\n if (m.length > 1) {\r\n m[m.length - 1].sum += m[m.length - 2].sum;\r\n }\r\n }\r\n\r\n let res = 0;\r\n for(let val in calc) {\r\n for(let i = 0; i < calc[val].length - 2; i++) {\r\n res += (calc[val][i].index + 1) * calc[val][i+1].sum;\r\n }\r\n }\r\n\r\n console.log(res);\r\n }\r\n}\r\n\r\nsolve();\r\n"}, {"source_code": "///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////\r\nconst pr = console.log;\r\nconst mi = Math.min;\r\nconst mx = Math.max;\r\nconst abs = Math.abs;\r\nconst fl = Math.floor;\r\nconst ce = Math.ceil;\r\nconst sq = Math.sqrt;\r\nconst lge = Math.log;\r\nconst lg10 = Math.log10;\r\nconst gcd = (a, b) => b == 0 ? a : gcd(b, a % b);\r\nconst lcm = (a, b) => (a / gcd(a, b)) * b;\r\nconst amax = (a) => mx.apply(Math, a);\r\nconst amin = (a) => mi.apply(Math, a);\r\nconst sm = (a) => a.reduce(((x, y) => x + y), 0);\r\nconst aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);\r\nconst swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];\r\nconst stin = (a) => a.sort((x, y) => x - y);\r\nconst stde = (a) => a.sort((x, y) => y - x);\r\nconst counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };\r\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n/**\r\n * 05/20/21 afternoon\r\n */\r\nconst solve = (n, a) => {\r\n // pr(n, a)\r\n let res = 0;\r\n let m = new Map();\r\n for (let i = 0; i < n; i++) {\r\n res += (m.get(a[i]) || 0) * (n - i);\r\n // pr(m);\r\n let plus = i + 1;\r\n m.set(a[i], m.get(a[i]) + plus || plus);\r\n // pr(m);\r\n }\r\n pr(res);\r\n};\r\n\r\nconst main = () => {\r\n const readline = require('readline');\r\n const rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n });\r\n let input = [];\r\n rl.on('line', (line) => {\r\n input.push(line.split(\" \").map(x => Number(x)));\r\n });\r\n rl.on('close', () => {\r\n let t = input[0][0];\r\n let i = 1;\r\n while (t--) {\r\n solve(input[i][0], input[i + 1]);\r\n i += 2;\r\n }\r\n });\r\n};\r\n\r\nmain()"}, {"source_code": "var readline = require('readline');\n \nvar rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\nvar lines = [];\nrl.on('line', function(input) {\n lines.push(input);\n});\nrl.on('close', function() {\n var t = parseInt(lines[0]);\n var l = 1;\n for (var i = 0; i < t; i++) {\n var n = +lines[l++]\n var arr = lines[l++].trim().split(' ').map(Number)\n console.log(solve(n, arr))\n }\n});\n\nfunction solve(n, arr) {\n let total = 0\n const map = {} // x -> sum\n arr.forEach((x, i) => {\n let sum = map[x] || 0\n total = add(total, mul(sum, n - i))\n // console.log(x, sum, sum * (n - i))\n sum += i + 1\n map[x] = sum\n })\n return total\n}\nfunction add(a, b) {\n return a + b\n}\nfunction mul(a, b) {\n return a * b\n}"}], "src_uid": "66eb860613bf3def9c1b3f8bb3a6763a"} {"source_code": "input = readline().split(\" \").map(Number);\nvar n = input[0];\nvar t = input[1];\nvar s1 = readline(); \nvar s2 = readline();\n\nvar diff1 = 0;\nvar a = new Array(n);\nvar answer = \"\";\nvar d = [];\nvar j = 0;\nfor (var i = 0; i < n; i++)\n{\n\tif (s1[i] != s2[i]) {\n\t\tdiff1 += 1;\n\t\td[j++] = i;\n\t}\n}\n\nif (diff1 <= (t+t)) {\n\tfor (var i = 0; i < n; i++)\n\t\ta[i] = s1.charCodeAt(i);\n\t\n\tvar samePreffix = diff1 - t;\n\n\tif (samePreffix > 0) {\n\t\tvar restPreffix = samePreffix;\n\t\tfor (var i = 0; i < diff1; i++) {\n\t\t\t// part 1\n\t\t\tif (i < samePreffix) {\n\t\t\t\ta[d[i]] = s2.charCodeAt(d[i]);\n\t\t\t}\n\t\t\t// part 2\n\t\t\tif (samePreffix <= i && i < diff1-samePreffix) {\n\t\t\t\ta[d[i]] = s1.charCodeAt(d[i]) + 1;\n\t\t\t\tif (a[d[i]] > \"z\".charCodeAt(0))\n\t\t\t\t\ta[d[i]] -= 26;\n\n\t\t\t\tif (a[d[i]] == s2.charCodeAt(d[i]))\n\t\t\t\t\ta[d[i]] += 1;\t\t\t\n\t\t\t}\n\t\t\t// part 3\n\t\t}\n\t} else {\n\t\tfor (var i = 0; i < n; i++) {\n\t\t\tif (s1[i] == s2[i]) {\n\t\t\t\tif (samePreffix < 0) {\n\t\t\t\t\ta[i] += 1;\n\t\t\t\t\tsamePreffix += 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ta[i] += 1;\n\t\t\t\tif (a[i] > \"z\".charCodeAt(0))\n\t\t\t\t\ta[i] -= 26;\n\t\t\t\tif (a[i] == s2.charCodeAt(i))\n\t\t\t\t\ta[i] += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\n\tfor (var i = 0; i < n; i++) {\n\t\tif (a[i] > \"z\".charCodeAt(0))\n\t\t\ta[i] -= 26;\t\n\t\tanswer += String.fromCharCode(a[i]);\n\t}\n} else {\n\tanswer = \"-1\";\n}\n\nwrite(answer);", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n let diff = t;\n let bb = true;\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i] && n - sameCount > diff) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n bb = false;\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n if (bb) {\n console.log(ans.join(''));\n }\n})"}], "negative_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n let diff = t;\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i] && n - sameCount > diff) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n console.log(ans.join(''));\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i]) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n console.log(ans.join(''));\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i] && sameCount < n - t) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n console.log(ans.join(''));\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n console.log(lines); \n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i]) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n ans = ans.join();\n console.log(ans);\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i]) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n console.log(ans.join());\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL) /*your input text, split by lines*/\n // console.log(lines);\n\n let [n, t] = lines[0].split(' ');\n let s1 = lines[1];\n let s2 = lines[2];\n let ans = [];\n let sameCount = 0;\n let remain1, remain2;\n\n t = n - t; // t defind as the count need to be the same\n for (let i = 0; i < n; i++) {\n if (s1[i] === s2[i] && n - sameCount > t) {\n ans[i] = s1[i];\n sameCount++;\n }\n }\n\n if (t * 2 - sameCount > n) {\n console.log(-1);\n } else {\n remain1 = remain2 = t - sameCount;\n for (i = 0; i < n; i++) {\n if (ans[i]) { continue }\n if (remain1 > 0) {\n ans[i] = s1[i];\n remain1--;\n } else if (remain2 > 0) {\n ans[i] = s2[i];\n remain2--;\n } else {\n ans[i] = ['a', 'b', 'c'].find(char => (char !== s1[i] && char !== s2[i]))\n }\n }\n }\n console.log(ans.join(''));\n})\n"}], "src_uid": "8ba3a7f7cb955478481c74cd4a4eed14"} {"source_code": "c=readline()\r\nfor(i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n for(j = 1; j<= n; j++){\n var r = false\n var g = false\n var b = false\n var s = false\n\n var a = lines[j].split('')\n for(k = 0; k < a.length; k++){\n if(a[k] == 'R' && r === false){\n break;\n }else if(a[k] == 'G'&& g === false){\n break;\n }else if(a[k] == 'B' && b === false){\n break;\n }else if(a[k] == 'r'){\n r = true\n }else if(a[k] == 'g'){\n g = true\n }else if(a[k] == 'b'){\n b = true\n }\n \n }\n if(r === true && g === true & b === true){\n console.log('YES')\n }else{\n console.log('NO')\n }\n }\n});"}, {"source_code": "\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\nlet inputString = '';\r\nlet inputData = [];\r\nlet currentLine = 0;\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString = String(inputStdin);\r\n});\r\nprocess.stdin.on('end', () => {\r\n inputData = inputString.trim().split('\\n').map(string => string.trim());\r\n main();\r\n});\r\nconst readline = () => inputData[currentLine++];\r\nconst solve = (s) => {\r\n if (s.indexOf('r') > s.indexOf('R'))\r\n return \"NO\";\r\n if (s.indexOf('g') > s.indexOf('G'))\r\n return \"NO\";\r\n if (s.indexOf('b') > s.indexOf('B'))\r\n return \"NO\";\r\n return \"YES\";\r\n};\r\nconst main = () => {\r\n let tc = parseInt(readline());\r\n while (tc--) {\r\n let s = readline();\r\n console.log(solve(s));\r\n }\r\n};"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0; i < x; i++){\r\n debugger;\r\n let line2 = readline(); \r\n doorKeys(line2);\r\n }\r\n}\r\n\r\n function doorKeys(word) {\r\n let len = word.length;\r\n let kyes = [];\r\n \r\n for(let j = 0; j < len; j++) {\r\n let asciValue = word[j].charCodeAt(0);\r\n \r\n if(asciValue >= 97 && asciValue <= 122 ) {\r\n kyes.push(word[j]);\r\n } else {\r\n if(!kyes.includes(word[j].toLowerCase())) {\r\n console.log(\"NO\");\r\n return;\r\n }\r\n }\r\n }\r\n console.log('YES');\r\n }"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n let no = false;\r\n for (let test = 0; test < N; test++) {\r\n let str = readline();\r\n\r\n let I = {};\r\n for (let i = 0; i < str.length; i++) I[str[i]] = i;\r\n\r\n let red = I.r < I.R;\r\n let blue = I.b < I.B;\r\n let green = I.g < I.G;\r\n\r\n output((red && blue && green) ? 'YES' : 'NO');\r\n }\r\n}\r\n"}, {"source_code": "'use strict';\r\n\r\nfunction solve(s) {\r\n let set = new Set();\r\n for (let ch of s) {\r\n const num = ch.charCodeAt(0);\r\n if (num > 97) {\r\n set.add(num - 32);\r\n } else {\r\n if (!set.has(num)) return 'NO';\r\n }\r\n }\r\n return 'YES';\r\n}\r\n\r\nasync function main(read) {\r\n try {\r\n let t = Number(await read());\r\n let res = new Array(t);\r\n for (let i = 0; i < t; i++) {\r\n const s = await read();\r\n res[i] = solve(s);\r\n }\r\n return res.join('\\n');\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n}\r\n\r\nlet inputs,\r\n str = '';\r\nfunction read() {\r\n return inputs.next().value.trim();\r\n}\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\nprocess.stdin.on('data', input => str += input);\r\nprocess.stdin.on('end', async () => {\r\n inputs = str.split('\\n').values();\r\n const output = await main(read);\r\n process.stdout.write(output);\r\n});\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const str = lines[l++]\n output[i] = solve(str)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(str) {\n const map = {}\n for (let i = 0; i < str.length; i++) {\n const x = str[i]\n if (/[RGB]/.test(x)) {\n if (!map[x.toLowerCase()]) return 'NO'\n } else {\n map[x] = 1\n }\n }\n return 'YES'\n}\n"}, {"source_code": "//Don't have to see. start------------------------------------------\r\nvar read = require('readline').createInterface({\r\n\tinput: process.stdin, output: process.stdout\r\n});\r\nvar obj; var inLine = []; var outputList = [];var retcode = new Set();\r\nread.on('line', function(input){\r\n\tvar tmp = input.split(' ');\r\n\tfor(var i = 0; i < tmp.length; i++){\r\n\t\tinLine.push(tmp[i]);\r\n\t\tif(i == tmp.length - 1){\r\n\t\t\tretcode.add(inLine.length);\r\n\t\t}\r\n\t}\r\n});\r\nread.on('close', function(){\r\n\tobj = init(inLine);\r\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\r\n\tMain();\r\n\tconsole.log(myconv(outputList, 9));\r\n});\r\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\r\nfunction nextArray(size, code){\r\n\tvar ret = new Array(size);\r\n\tfor(var i = 0; i < size; i++){\r\n\t\tif(code == 'int'){\r\n\t\t\tret[i] = nextInt();\r\n\t\t}else if(code == 'long'){\r\n\t\t\tret[i] = nextLong();\r\n\t\t}else if(code == 'double'){\r\n\t\t\tret[i] = nextDouble();\r\n\t\t}else{\r\n\t\t\tret[i] = next();\r\n\t\t}\r\n\t}\r\n\treturn ret;\r\n}\r\nfunction nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}\r\nfunction nextCharArray(){return myconv(next(),6);}\r\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}\r\nfunction getCountMap(list){\r\n\tvar map = {};\r\n\tfor(var i = 0; i < list.length; i++){\r\n\t\tif(map[list[i]] == null){\r\n\t\t\tmap[list[i]] = 0;\r\n\t\t}\r\n\t\tmap[list[i]]++;\r\n\t}\r\n\treturn map;\r\n}\r\nfunction init(input){ \r\n\treturn {\r\n\t\tlist : input, index : 0, max : input.length,\r\n\t\thasNext : function(){return (this.index < this.max);},\r\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}},\r\n\t\tisReturn : function(){return retcode.has(this.index);}\r\n\t};\r\n}\r\nfunction myout(s){outputList.push(s);}\r\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\r\nfunction isReturn(){return obj.isReturn();}\r\n//param \"no\" is\r\n//unknown or outlier : return i. 1: parseInt.\r\n//2: split space. 4: split space and parseInt.\r\n//6: split 1 character. 7: split 1 character and parseInt.\r\n//8: join space. 9: join nextline. 0: join no character.\r\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\r\n\r\n//Don't have to see. end------------------------------------------\r\nfunction Main(){\r\n\tvar t = nextInt();\r\n\twhile(hasNext()){\r\n\t\tvar S = next();\r\n\t\tvar Key = \"rgb\";\r\n\t\tvar Door = \"RGB\";\r\n\t\tvar set = new Set();\r\n\t\tvar ok = true;\r\n\t\tfor(var i = 0; i < S.length; i++){\r\n\t\t\tif(Key.indexOf(S[i]) != -1){\r\n\t\t\t\tset.add(S[i].toUpperCase());\r\n\t\t\t}else{\r\n\t\t\t\tif(!set.has(S[i])){\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(ok){\r\n\t\t\tmyout(\"YES\");\r\n\t\t}else{\r\n\t\t\tmyout(\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\n\r\nfunction processString(st=\"\"){\r\n let r=false,g=false,b=false;\r\n const values = {\r\n r : false,\r\n g :false,\r\n b : false\r\n };\r\n for(let i=0;i i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0].split(' ');\n var answer = 0;\n for(var l = 1; l <= n; l++){\n var k = lines[l].split('');\n var rkey = false;\n var gkey = false;\n var bkey = false;\n var no = false;\n for(var j = 0; j < k.length; j++){\n if(k[j] == 'r'){\n rkey = true;\n }else if(k[j] == 'g'){\n gkey = true;\n }else if(k[j] == 'b'){\n bkey = true;\n }else if(k[j] == 'R' && rkey === false || k[j] == 'G' && gkey === false || k[j] == 'B' && bkey === false){\n no = true;\n }\n }\n if(!no){\n console.log('YES');\n }else{\n console.log('NO');\n }\n }\n}); "}, {"source_code": "'use strict';\n/* ================== */\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nconst readline = () => inputString[currentLine++];\nconst readline_arr = () => readline().split(' ').map((n) => parseInt(n, 10));\nconst print = (...txt) => process.stdout.write(`${txt}\\n`)\n/* ================== */\n\nfunction main() {\n let t = parseInt(readline(), 10);\n while (t--) {\n solve();\n }\n}\n\nfunction solve() {\n const str = readline().split('');\n\n const keys = [];\n for (let i = 0; i < str.length; i++) {\n const p = str[i];\n if (p === p.toLowerCase()) {\n keys.push(p);\n } else {\n if (keys.some(k => k === p.toLowerCase())) {\n continue;\n } else {\n print('NO');\n return;\n }\n }\n };\n\n print('YES');\n}\n"}, {"source_code": "function solve(input) {\r\n let result = 'YES'\r\n // console.log('input: ', input)\r\n // for (let char of input) {\r\n // console.log(char)\r\n // }\r\n const listStr = input.split('');\r\n const checkRr = listStr.filter(data => ['R', 'r'].includes(data))\r\n const checkGg = listStr.filter(data => ['G', 'g'].includes(data))\r\n const checkBb = listStr.filter(data => ['B', 'b'].includes(data))\r\n if (checkRr[0] === 'R' || checkGg[0] === 'G' || checkBb[0] === 'B') {\r\n result = 'NO'\r\n }\r\n console.log(result)\r\n}\r\n\r\n// =========== DEFAULT FORMAT ==============\r\nconst readline = require('readline').createInterface({ input: process.stdin });\r\n\r\nlet i = 1;\r\nlet t = 0;\r\nreadline.on('line', line => {\r\n if (i == 1) {\r\n // number of test case\r\n t = parseInt(line) \r\n i++;\r\n } else {\r\n solve(line)\r\n if (i <= t) i++\r\n else readline.close()\r\n }\r\n});\r\n\r\n// =========== DEFAULT FORMAT END =============="}, {"source_code": "doorsFilter = (arr)=> {\r\n return (arr.filter((e)=>{\r\n return e.toLowerCase() != arr[0];\r\n }));\r\n};\r\nvar t = readline();\r\n for(var i = 0 ; i < t ; i++){\r\n var a = readline().split('');\r\n while(a.length >= 0){\r\n if(a.length === 0){\r\n print('YES');\r\n break;\r\n }\r\n if(a[0] == a[0].toLowerCase()){\r\n a = doorsFilter(a);\r\n }\r\n else{\r\n print('NO');\r\n break;\r\n } \r\n }\r\n}"}, {"source_code": "r=readline;for(r();a=r();)print(/^(?=.*r.*R)(?=.*g.*G)(?=.*b.*B)/.exec(a)?\"YES\":\"NO\")"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n lines.pop();\r\n const inputCount = Number(lines.shift());\r\n const results = [];\r\n\r\n const checkInput = (input) => {\r\n const keys = [ 'r', 'g', 'b' ];\r\n const doors = [ 'R', 'G', 'B' ];\r\n const data = input.split('');\r\n return data.every(\r\n (element, index, array) =>\r\n doors.includes(element)\r\n ? array.slice(0, index).includes(element.toLowerCase())\r\n : true\r\n );\r\n };\r\n\r\n for (let inputData of lines) {\r\n results.push(checkInput(inputData));\r\n }\r\n\r\n for (var result of results) console.log(result ? 'YES' : 'NO');\r\n})\r\n"}], "negative_code": [{"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n console.log(lines);\r\n const inputCount = Number(lines.shift());\r\n const results = [];\r\n\r\n const checkInput = (input) => {\r\n const keys = [ 'r', 'g', 'b' ];\r\n const doors = [ 'R', 'G', 'B' ];\r\n const data = input.split('');\r\n return data.every(\r\n (element, index, array) =>\r\n doors.includes(element)\r\n ? array.slice(0, index).includes(element.toLowerCase())\r\n : true\r\n );\r\n };\r\n\r\n for (let inputData of lines) {\r\n results.push(checkInput(inputData));\r\n }\r\n\r\n for (var result of results) console.log(result ? 'YES' : 'NO');\r\n})\r\n"}, {"source_code": "let i = ''\r\nprocess.stdin.on('data', c => i += c)\r\nprocess.stdin.on('end', () => {\r\n const {EOL} = require('os')\r\n const lines = i.split(EOL) /*your input text, split by lines*/\r\n \r\n const inputCount = Number(lines.shift());\r\n const results = [];\r\n\r\n const checkInput = (input) => {\r\n const keys = [ 'r', 'g', 'b' ];\r\n const doors = [ 'R', 'G', 'B' ];\r\n const data = input.split('');\r\n return data.every(\r\n (element, index, array) =>\r\n doors.includes(element)\r\n ? array.slice(0, index).includes(element.toLowerCase())\r\n : true\r\n );\r\n };\r\n\r\n for (let inputData of lines) {\r\n results.push(checkInput(inputData));\r\n }\r\n\r\n for (var result of results) console.log(result ? 'YES' : 'NO');\r\n})\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var r = false\n var g = false\n var b = false\n var s = false\n for(j = 1; j<= n; j++){\n var a = lines[j].split('')\n for(k = 0; k < a.length; k++){\n if(a[k] == 'R' && r === false){\n s = false\n }else if(a[k] == 'G' && g === false){\n s = false\n }else if(a[k] == 'B' && b === false){\n s = false\n }else{\n s = true\n }\n }\n if(s === false){\n console.log('NO')\n }else{\n console.log('YES')\n }\n }\n});"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', inputStdin => {\r\n inputString += inputStdin;\r\n});\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(string => {\r\n return string.trim();\r\n });\r\n \r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\nfunction main() {\r\n const x = readline();\r\n \r\n for(let i = 0; i < x; i++){\r\n debugger;\r\n let line2 = readline(); \r\n doorKeys(line2);\r\n }\r\n}\r\n\r\n function doorKeys(word) {\r\n let len = word.length;\r\n let kyes = [];\r\n \r\n for(let j = 0; j < len; j++) {\r\n let asciValue = word[j].charCodeAt(0);\r\n \r\n if(asciValue >= 97 && asciValue <= 122 ) {\r\n kyes.push(word[j]);\r\n } else {\r\n if(!kyes.includes(word[j].toLowerCase())) {\r\n console.log(false);\r\n return;\r\n }\r\n }\r\n }\r\n console.log(true);\r\n }"}, {"source_code": "r=readline();print(r.indexOf(\"G\") {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const str = lines[l++]\r\n const arr = lines[l++].trim().split(' ')\r\n output[i] = solve(n, str, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, str, arr) {\r\n const map = arr.reduce((o, x) => {\r\n o.set(x, 1)\r\n return o\r\n }, new Map())\r\n let last = -1\r\n let ans = 0\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n ans = Math.max(ans, last < 0 ? -Infinity : last - i)\r\n if (map.get(str[i])) last = i\r\n }\r\n return ans\r\n}\r\n", "positive_code": [{"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r\\n');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\n//var alpha = []\r\nvar num = []\r\nfunction alph() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n return f;\r\n}\r\nfunction Alph() {\r\n var g = []\r\n var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n for(var x=0;x=y ? x : y;\r\n}\r\nvar T = readline();\r\nfor(var q=1;q<=T;q++) {\r\n var n = readline();\r\n var s = readline();\r\n var r = readline().split(' ');\r\n var alpha = alph();\r\n var spec = []\r\n var id = 0;\r\n var move = 0;\r\n var m = new Map();\r\n for(var i=0;i<26;i++) {\r\n m.set(alpha[i], false);\r\n }\r\n for(var i=1;i<=r[0];i++) {\r\n m.set(r[i], true);\r\n }\r\n //console.log(m)\r\n \r\n for(var i=1;i move) {\r\n move = max(move, i-id);\r\n id = i;\r\n } else {\r\n id = i;\r\n }\r\n } \r\n }\r\n console.log(move);\r\n //fs.appendFileSync('output.txt', move+'\\r\\n');\r\n \r\n //os.EOL\r\n}"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\n/*---------------------------------------------------*/\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n/*---------------------------------------------------*/\n\nconst calc = (n, s, a)=>{\n let res = 0;\n\n let map = new Set(a);\n\n let prev = -1;\n for (let i = 0; i < n - 1; i++) {\n if (map.has(s[i + 1])) {\n res = Math.max(res, i - prev);\n prev = i;\n }\n }\n\n return res;\n};\n\nfunction main() {\n let T = +readline();\n let out = [];\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let s = readline();\n let a = readline().split(' ').slice(1);\n out.push(calc(n, s, a));\n // console.log(`${calc(n, s, k, a)}`);\n }\n process.stdout.write(out.join('\\n')+'\\n');\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n let RESULT = [];\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n RESULT.push(calc(T));\n } else\n pcalc();\n process.stdout.write(RESULT.join('\\n')+'\\n')\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let s = readline();\n let K = readline().split(' ');\n let k = +K[0];\n K = new Set(K.slice(1));\n LT({n, s, k, K});\n // PROCESSING:\n let lastPos = -1;\n for (let i=n-1; i>=0; i--){\n if (K.has(s[i])){\n lastPos = i;\n break;\n }\n }\n if (lastPos==-1)\n return 0;\n let cnt = 0;\n let max = 0;\n for (let i=lastPos-1; i>=0; i--){\n if (K.has(s[i+1]))\n cnt = 1;\n else\n cnt++;\n max = Math.max(max, cnt)\n }\n return max\n};\n "}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, s, k, b) {\r\n let pre = 0,\r\n max = 0;\r\n const set = new Set(b);\r\n for (let i = 0; i < n; i++) {\r\n if (set.has(s[i])) {\r\n max = Math.max(i - pre, max);\r\n pre = i;\r\n }\r\n }\r\n return max;\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n let res = [];\r\n while (t--) {\r\n const n = Number(await read());\r\n const s = await read();\r\n const s2 = await read();\r\n const k = Number(s2[0]);\r\n const b = s2.slice(2).split(' ');\r\n res.push(solve(n, s, k, b));\r\n }\r\n console.log(res.join('\\n'));\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}], "negative_code": [{"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const str = lines[l++]\r\n const arr = lines[l++].trim()//.split(' ')\r\n output[i] = solve(n, str, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, str, arr) {\r\n const map = {}\r\n for (let i = 0; i < arr.length; i += 2) {\r\n map[arr[i]] = 1\r\n }\r\n // const map = arr.reduce((o, x) => {\r\n // o[x] = 1\r\n // return o\r\n // }, {})\r\n let last = -1\r\n let ans = 0\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n ans = Math.max(ans, last < 0 ? -Infinity : last - i)\r\n if (map[str[i]]) last = i\r\n // if (last >= 0 && last <= ans) break\r\n }\r\n return ans\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const str = lines[l++]\r\n const arr = lines[l++]//.trim().split(' ')\r\n output[i] = solve(n, str, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, str, arr) {\r\n const map = {}\r\n for (let i = 0; i < arr.length; i += 2) {\r\n map[arr[i]] = 1\r\n }\r\n // const map = arr.reduce((o, x) => {\r\n // o[x] = 1\r\n // return o\r\n // }, {})\r\n let last = -1\r\n let ans = 0\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n ans = Math.max(ans, last < 0 ? -Infinity : last - i)\r\n if (map[str[i]]) last = i\r\n // if (last >= 0 && last <= ans) break\r\n }\r\n return ans\r\n}\r\n"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const str = lines[l++]\n const arr = lines[l++].trim()//.split(' ')\n output[i] = solve(n, str, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, str, arr) {\n const map = {}\n for (let i = 0; i < arr.length; i += 2) {\n map[arr[i]] = 1\n }\n // console.log(map)\n let last = -Infinity\n let ans = 0\n for (let i = str.length - 1; i >= 0; i--) {\n if (last - i > ans) {\n ans = last - i\n }\n // ans = Math.max(ans, last < 0 ? -Infinity : last - i)\n if (map[str[i]]) last = i\n // if (last >= 0 && last <= ans) break\n }\n return ans\n}\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const str = lines[l++]\r\n const arr = lines[l++]//.trim().split(' ')\r\n output[i] = solve(n, str, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, str, arr) {\r\n const map = {}\r\n for (let i = 0; i < arr.length; i += 2) {\r\n map[arr[i]] = 1\r\n }\r\n // console.log(map)\r\n let last = -Infinity\r\n let ans = 0\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n // if (last - i > ans) {\r\n // ans = last - i\r\n // }\r\n ans = Math.max(ans, last < 0 ? -Infinity : last - i)\r\n if (map[str[i]]) last = i\r\n // if (last >= 0 && last <= ans) break\r\n }\r\n return ans\r\n}\r\n"}, {"source_code": "const readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n})\r\nconst lines = []\r\nrl.on('line', (input) => {\r\n lines.push(input);\r\n})\r\nrl.on('close', () => {\r\n// (function() {\r\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\r\n let l = 0;\r\n let t = +lines[l++]\r\n const output = []\r\n for (let i = 0; i < t; i++) {\r\n const n = +lines[l++]\r\n const str = lines[l++]\r\n const arr = lines[l++]//.trim().split(' ')\r\n output[i] = solve(n, str, arr)\r\n }\r\n console.log(output.join('\\n'))\r\n// })()\r\n})\r\n\r\nfunction solve(n, str, arr) {\r\n const map = {}\r\n for (let i = 0; i < arr.length; i += 2) {\r\n map[arr[i]] = 1\r\n }\r\n // console.log(map)\r\n let last = -Infinity\r\n let ans = 0\r\n for (let i = str.length - 1; i >= 0; i--) {\r\n if (last - i > ans) {\r\n ans = last - i\r\n }\r\n // ans = Math.max(ans, last < 0 ? -Infinity : last - i)\r\n if (map[str[i]]) last = i\r\n // if (last >= 0 && last <= ans) break\r\n }\r\n return ans\r\n}\r\n"}], "src_uid": "7374246c559fb7b507b0edeea6ed0c5d"} {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));\n let res = 0, kc;\n a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });\n for (let i = 1; i <= n; i++) {\n a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)\n }\n for (let i = 1; i <= n; i++) {\n for (let j = i - 1; j >= max(0,i-2000); j--) {\n kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);\n // if (a[j].t + a[i].m < a[i].t) break;\n if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;\n if (a[i].c > res) res = a[i].c;\n }\n }\n // log(a)\n log(res)\n}\n", "positive_code": [{"source_code": "'use strict';\n\nvar readline = require('readline');\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nfunction ownKeys(object, enumerableOnly) {\n var keys = Object.keys(object);\n\n if (Object.getOwnPropertySymbols) {\n var symbols = Object.getOwnPropertySymbols(object);\n if (enumerableOnly) symbols = symbols.filter(function (sym) {\n return Object.getOwnPropertyDescriptor(object, sym).enumerable;\n });\n keys.push.apply(keys, symbols);\n }\n\n return keys;\n}\n\nfunction _objectSpread2(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i] != null ? arguments[i] : {};\n\n if (i % 2) {\n ownKeys(Object(source), true).forEach(function (key) {\n _defineProperty(target, key, source[key]);\n });\n } else if (Object.getOwnPropertyDescriptors) {\n Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));\n } else {\n ownKeys(Object(source)).forEach(function (key) {\n Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));\n });\n }\n }\n\n return target;\n}\n\nfunction nInFirstLineArrayStdin(nIndex) {\n return new Promise(resolve => {\n const stdin = readline.createInterface(process.stdin);\n let n;\n let firstLine;\n let output = [];\n stdin.on('line', line => {\n if (typeof n !== 'number') {\n firstLine = line.split(' ').map(Number);\n n = firstLine[nIndex];\n } else {\n output.push(line);\n\n if (--n === 0) {\n resolve([firstLine, output]);\n stdin.close();\n }\n }\n });\n });\n}\n\nfunction solve(celebs) {\n const scored = [];\n\n for (let x = 0; x < celebs.length; x++) {\n const current = celebs[x];\n let insertIndex = scored.length;\n let groupScore = -1;\n let inserted = false;\n\n for (let y = scored.length - 1; y >= 0; y--) {\n const previous = scored[y];\n\n if (groupScore !== previous.score) {\n insertIndex = y + 1;\n groupScore = previous.score;\n }\n\n if (Math.abs(current.x - previous.x) + Math.abs(current.y - previous.y) + previous.t <= current.t) {\n scored.splice(insertIndex, 0, _objectSpread2(_objectSpread2({}, current), {}, {\n score: previous.score + 1\n }));\n inserted = true;\n break;\n }\n }\n\n if (!inserted && current.t >= current.x - 1 + current.y - 1) {\n scored.splice(0, 0, _objectSpread2(_objectSpread2({}, current), {}, {\n score: 1\n }));\n }\n }\n\n console.log(scored.length ? scored[scored.length - 1].score : 0);\n}\n\nasync function main() {\n const input = await nInFirstLineArrayStdin(1);\n solve(input[1].map(line => {\n const [t, x, y] = line.split(' ').map(Number);\n return {\n t,\n x,\n y\n };\n }));\n}\n\nmain().then();\n"}], "negative_code": [{"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));\n let res = 0, kc;\n a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });\n for (let i = 1; i <= n; i++) {\n a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)\n }\n for (let i = 1; i <= n; i++) {\n for (let j = i - 1; j >= 0; j--) {\n kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);\n if (a[j].t + kc < a[i].t) break;\n if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;\n if (a[i].c > res) res = a[i].c;\n }\n }\n // log(a)\n log(res)\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));\n let res = 0, kc;\n a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });\n for (let i = 1; i <= n; i++) {\n a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)\n }\n for (let i = 1; i <= n; i++) {\n for (let j = i - 1; j >= max(0,i-1000); j--) {\n kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);\n // if (a[j].t + a[i].m < a[i].t) break;\n if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;\n if (a[i].c > res) res = a[i].c;\n }\n }\n // log(a)\n log(res)\n}\n"}, {"source_code": "function For(a, b, fn) {\n if (!fn) return For(0, a - 1, b);\n let res;\n for (let i = a; i <= b; i++) {\n if ((res = fn(i)) != null) return res;\n }\n}\nfunction ForR(a, b, fn) {\n if (!fn) return ForR(a - 1, 0, b);\n let res;\n for (let i = a; i >= b; i--) {\n if ((res = fn(i)) != null) return res;\n }\n}\n\nfunction Arr(a, b, fn) {\n if (typeof (b) == 'function') return Arr(0, a - 1, b);\n if (b < a) return [];\n let arr = Array(b - a + 1)\n for (let i = a; i <= b; i++) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn ? fn(v) : v).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = 1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x < min) { min = x; index = i }\n }\n return [this[index], index, min];\n}\nArray.prototype.max = function (fn) {\n let max = -1e20, index = -1, x;\n for (let i = 0; i < this.length; i++) {\n x = fn ? fn(this[i], i, this) : this[i];\n if (x > max) { max = x; index = i }\n }\n return [this[index], index, max];\n}\nArray.prototype.rev = function (first, last) {\n for (let i = first; i < (first + last) / 2; i++) {\n [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]\n }\n}\nArray.prototype.set = function (pos, arr) {\n for (let i = pos; i < pos + arr.length; i++) {\n this[i] = arr[i - pos];\n }\n}\nArray.prototype.for = function (a, b, fn) {\n let res\n for (let i = a; i <= b; i++) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.forR = function (a, b, fn) {\n let res\n for (let i = a; i >= b; i--) {\n if ((res = fn(this[i], i, this)) != null) return res;\n }\n}\nArray.prototype.bin = function (comp, a, b) {\n let mid;\n while (a < b) {\n mid = (a + b) / 2 | 0;\n if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;\n else b = mid;\n }\n return a;\n}\nArray.prototype.cut = function (fn, a, b) {\n let arr = [];\n a = a || 0;\n b = b || (this.length - 1);\n let prev = a;\n for (let i = a; i <= b; i++) {\n if (i == b || fn(this[i], this[i + 1])) {\n arr.push(this.slice(prev, i + 1));\n prev = i + 1;\n }\n }\n return arr;\n}\n\nfunction gcd(a, b) {\n while (b) [a, b] = [b, a % b];\n return a;\n}\nfunction mul(a, b, m) {\n return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m\n}\nfunction pow(a, n, m) {\n let r = 1;\n while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]\n return r;\n}\nfunction inv(b, m) {\n for (var a = m, u = 0, v = 1, t; b; v = t)\n (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);\n return (u + m) % m;\n}\n\n// let MOD = 1e9 + 7\n// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));\n// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));\n// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });\n// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);\n\n// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1\n// for (i = pos; i; i -= i & -i) ans += fen[i];\n\n// let p = [2];\n// for (let i = 3; i < 1e5; i += 2) {\n// let j, x = Math.sqrt(i);\n// for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;\n// if (i % p[j] != 0) p.push(i);\n// }\n\n// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));\n// let dsu = (x, y) => {\n// if ((x = root(x)) == (y = root(y))) return;\n// if (par[y] < par[x]) [x, y] = [y, x];\n// par[x] += par[y];\n// par[y] = x;\n// }\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nasync function main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;\n let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));\n let res = 0, kc;\n a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });\n for (let i = 1; i <= n; i++) {\n a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)\n }\n for (let i = 1; i <= n; i++) {\n for (let j = i - 1; j >= 0; j--) {\n kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);\n if (a[j].t + a[i].m < a[i].t) break;\n if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;\n if (a[i].c > res) res = a[i].c;\n }\n }\n // log(a)\n log(res)\n}\n"}], "src_uid": "1392daad6638b7a93e84dd474cdf916a"} {"source_code": "var piles_number = readline();\nvar piles = readline().split(' ');\nvar expected_worm_numbers = readline();\nvar expected_worms = readline().split(' ');\n\nvar getWormsAfterPile = function(piles_number, piles) {\n var worms_after_piles = [];\n for (i = 0; i < piles_number; i++) {\n var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];\n worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);\n }\n return worms_after_piles;\n}\n\nvar getWormPile = function(worms_after_piles, expected_worm, start) {\n if (worms_after_piles[0] >= expected_worm) {\n return 1;\n }\n for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {\n if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {\n return i+1;\n }\n }\n}\n\nvar result = [];\n\nvar worms_after_piles = getWormsAfterPile(piles_number, piles);\nvar sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});\nvar last_worm_pile = 1;\nfor (k = 0; k < expected_worm_numbers; k++) {\n if (result[sorted_expected_worms[k]] != void(0)) {\n continue;\n }\n var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile - 1);\n last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;\n}\n\nfor (l = 0; l < expected_worm_numbers; l++) {\n print(result[expected_worms[l]]);\n}\n\n", "positive_code": [{"source_code": "\n'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n \n \nfunction getWormPositions(worms, labels) {\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] += total[i - 1] + worms[i]\n }\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n \nfunction bs(arr, target) {\n if (!arr.length) return -1;\n \n let ini = 0;\n let fin = arr.length - 1;\n \n while(ini < fin){\n let mid = Math.floor((ini + fin) / 2);\n if(arr[mid] < target){\n ini = mid + 1;\n } else {\n fin = mid;\n }\n \n }\n return fin;\n \n}"}, {"source_code": "readline()\nvar A=readline().split(' ').map(Number)\nreadline()\nvar Q=readline().split(' ').map(Number)\n\nvar T=new Array(A.length + 1)\nT[0]=0\nfor (var i=1; i {\n var lb=0,ub=T.length-1;\n while (lb+1>1;\n if (x<=T[m])\n ub=m;\n else if (T[m] find(x) + 1).join('\\n'))"}, {"source_code": "var aMap = {}, aCount = 1, result = [];\n\nvar n = parseInt(readline()),\n\tas = readline().split(/\\s/).map(function(a, index)\t{\n\t\tvar i = aCount;\n\n\t\ta = parseInt(a);\n\n\t\tfor(; i < aCount + a; i++)\taMap[i] = index + 1;\n\n\t\taCount = i;\n\n\t\treturn a;\n\t}),\n\tm = parseInt(readline()),\n\tqs = readline().split(/\\s/).map(function(q, index)\t{\n\t\tvar value = aMap[q];\n\n\t\tif(value)\tresult.push(value);\n\t});\n\nprint(result.join('\\n'));"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \");\nfor (p in a){a[p]= parseInt(a[p]);}\nvar m = readline();\nvar q = readline().split(\" \");\nfor (o in q){q[o]= parseInt(q[o]);}\nvar z = [];\nvar r = 0;\nfor (j = 0;jst+1)\n\t{\n\t var mid = (st+ed)>>1;\n\t\tif(aa[mid] parseInt(a));\n\nfor(var i=1; i parseInt(a));\n\nfor(var index=0; indexarr[mid]){\n left=mid+1;\n }else{\n right=mid-1;\n }\n }\n if(found===1)\n print(mid+1);\n else{\n if(right<0 || find[index]>arr[right])\n print(left+1);\n if(left>x-1 || find[index] arr[mid]) start = mid + 1;\n if (x == arr[mid]) return mid + 1;\n }\n return start + 1;\n}\n/************************************** */\n\nvar n = parseInt(readline());\nvar prev = 0;\nvar a = readline()\n .split(\" \")\n .map((val) => {\n var x = parseInt(val);\n x += prev;\n prev = x;\n return x;\n });\nvar m = parseInt(readline());\nvar q = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n\nfor (var i = 0; i < m; i++) {\n print(Bst(a, q[i]));\n}\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar out ='';\n\nvar arrQnew = [];\n\nfor (var i = 0; i < m; i++) {\n arrQnew[i] = [];\n arrQnew[i][0] = arrQ[i];\n arrQnew[i][1] = i; \n}\n\narrQnew.sort(function(a,b){return a[0]-b[0];});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQnew[i][0]) {\n arrOut[arrQnew[i][1]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "(function () {\n var heapsCount = parseInt(readline()),\n heaps = readline().split(\" \"),\n wormsCount = parseInt(readline()),\n worms = readline().split(\" \"),\n arrayHeaps = [],\n i = 1,\n wholeWorms = [],\n wholeWormsCount, j;\n\n arrayHeaps.push(parseInt(heaps[0]));\n for (; i < heapsCount; i++) {\n arrayHeaps.push(arrayHeaps[i - 1] + parseInt(heaps[i]));\n }\n wholeWormsCount = arrayHeaps[i - 1];\n j = 0;\n for (i = 0; i < wholeWormsCount + 1; i++) {\n wholeWorms.push(j + 1);\n if (i === arrayHeaps[j]) {\n j++;\n }\n }\n for (i = 0; i < wormsCount; i++) {\n print(wholeWorms[parseInt(worms[i])]);\n }\n})();"}, {"source_code": "function ProblemSolver() {\n\n this.solveCase = function() {\n var res , i , j , a , b , c , lo , hi , mi;\n this.cn = 0;\n res = 0;\n for( i = 0 ; i < this.n ; i++ ) {\n a = this.arr[ i ];\n for( j = 0 ; j < a ; j++ ) {\n this.brr[ this.cn++ ] = i + 1;\n }\n }\n for( i = 0 ; i < this.q ; i++ ) {\n a = this.crr[ i ];\n res = this.brr[ a - 1 ] ;\n print( res );\n }\n };\n\n this.getInput = function( irObj ) {\n var hasMoreInput , i;\n hasMoreInput = true;\n try {\n this.n = irObj.nextInt();\n for( i = 0 ; i < this.n ; i++ ) {\n this.arr[ i ] = irObj.nextInt();\n }\n this.q = irObj.nextInt();\n for( i = 0 ; i < this.q ; i++ ) {\n this.crr[ i ] = irObj.nextInt();\n }\n }\n catch( ex ) {\n hasMoreInput = false;\n }\n return hasMoreInput;\n };\n\n this.clearArraysPerCase = function() {\n var i;\n this.arr = new Array();\n this.brr = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.arr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n };\n\n this.clearPerCase = function() {\n this.cn = 0;\n this.cc++;\n //this.clearArraysPerCase() ;\n };\n\n this.HAS_TEST_CASES = false;\n this.INPUT_FILE_NAME = \"test.in\";\n this.OUTPUT_FILE_NAME = \"out.txt\";\n this.DO_OUTPUT_TO_FILE = false;\n\n this.declareAndFillArrays = function() {\n var i , j;\n this.srr = new Array();\n this.vis = new Array();\n this.arr = new Array();\n this.brr = new Array();\n this.crr = new Array();\n this.memo = new Array();\n this.done = new Array();\n this.adj_list = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n this.srr.push( \"\" );\n this.vis.push( 0 );\n this.arr.push( 0 );\n this.crr.push( 0 );\n this.brr.push( 0 );\n this.adj_list.push( new Array() );\n }\n for( i = 0 ; i < this.lim2 ; i++ ) {\n this.memo.push( new Array() );\n this.done.push( new Array() );\n for( j = 0 ; j < this.lim2 ; j++ ) {\n this.memo[ i ].push( -1 );\n this.done[ i ].push( 0 );\n }\n }\n };\n\n this.init = function() {\n this.lim1 = 1000010;\n this.lim2 = 110;\n this.cc = 1;\n this.ind = 1;\n this.n = 0;\n this.cn = 0;\n this.declareAndFillArrays();\n };\n\n this.memsetArray1D = function( arrParam , val ) {\n var i;\n if( arrParam == null ) {\n throw new Error( \"No array supplied in the parameter!\" );\n }\n if( val == null ) {\n throw new Error( \"No value for memset has been supplied in the parameter!\" );\n }\n arrParam = new Array();\n for( i = 0 ; i < this.lim1 ; i++ ) {\n arrParam.push( val );\n }\n return arrParam;\n };\n\n this.getStringLength = function( stringData ) {\n var len , lengthType;\n len = stringData.length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = stringData.length();\n }\n else {\n len = stringData.length;\n }\n return len;\n };\n\n this.init();\n}\n\nfunction InputReader() {\n this.allLines = new Array();\n this.currrentLineNumber = 0;\n this.currrentCharacterIndex = 0;\n\n this.readAllLines = function() {\n var singleLine;\n while( true ) {\n try {\n singleLine = readline();\n if( singleLine == null ) {\n break;\n }\n }\n catch( ex ) {\n break;\n }\n this.allLines.push( singleLine );\n }\n };\n\n this.readAllLinesFromRhinoStdin = function() {\n importPackage( java.io );\n importPackage( java.lang );\n var singleLine , reader;\n reader = new BufferedReader( new InputStreamReader( System[ \"in\" ] ) );\n this.allLines = [];\n while( true ) {\n singleLine = reader.readLine();\n if( singleLine != null ) {\n this.allLines.push( singleLine );\n }\n else {\n break;\n }\n }\n };\n\n this.readAllLinesFromNodeStdin = function() {\n var fsObj , size , rawData;\n process.stdin.setEncoding( 'ascii' );\n fsObj = require( 'fs' );\n size = fsObj.fstatSync( process.stdin.fd ).size;\n rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];\n this.parseRawData( rawData );\n };\n\n this.parseRawData = function( data ) {\n var len , i , currentString;\n len = data.length;\n currentString = \"\";\n for( i = 0 ; i < len ; i++ ) {\n if( data[ i ] == '\\r' ) {\n }\n else if( data[ i ] == '\\n' ) {\n this.allLines.push( currentString );\n currentString = \"\";\n }\n else {\n currentString += data[ i ];\n }\n }\n if( currentString != \"\" ) {\n this.allLines.push( currentString );\n }\n };\n\n this.readAllLinesFromFile = function( inputFileName ) {\n var currentDirectory , fsObj , inputFilePath , rawData;\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n inputFilePath = currentDirectory + \"\\\\\" + inputFileName;\n rawData = fsObj.readFileSync( inputFilePath , \"utf8\" );\n this.parseRawData( rawData );\n };\n\n this.next = function( flag ) {\n var len , i , startIdx , res , endIdx , lengthType;\n len = this.allLines[ this.currrentLineNumber ].length;\n lengthType = typeof len;\n if( lengthType == \"function\" ) {\n len = this.allLines[ this.currrentLineNumber ].length();\n }\n if( flag == 0 ) {\n res = \"\";\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n return res;\n }\n while( true ) {\n if( this.currrentLineNumber >= this.allLines.length ) {\n throw new Error( \"No more tokens available!\" );\n }\n startIdx = -1;\n for( i = this.currrentCharacterIndex ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\\t'.charCodeAt( 0 ) ) {\n startIdx = i;\n break;\n }\n }\n if( startIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n continue;\n }\n res = \"\";\n endIdx = -1;\n for( i = startIdx ; i < len ; i++ ) {\n if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\\t'.charCodeAt( 0 ) ) {\n endIdx = i;\n break;\n }\n res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );\n }\n if( endIdx == -1 ) {\n this.currrentLineNumber++;\n this.currrentCharacterIndex = 0;\n }\n else {\n this.currrentCharacterIndex = endIdx;\n }\n return res;\n }\n };\n\n this.nextInt = function() {\n return parseInt( this.next( 1 ) );\n };\n\n this.nextDouble = function() {\n return parseFloat( this.next( 1 ) );\n };\n\n this.nextString = function() {\n return this.next( 1 );\n };\n\n this.nextLine = function() {\n this.next( 0 );\n };\n}\n\nfunction FileOutputHandler() {\n this.resultantStringArray = new Array();\n\n this.addNewLine = function( newString ) {\n this.resultantStringArray.push( newString );\n };\n\n this.clearPercase = function() {\n this.resultantStringArray = new Array();\n };\n\n this.flushOutOutputToFile = function( outputFileName ) {\n var i , sz , res , currentDirectory , fsObj , outputFilePath;\n res = \"\";\n sz = this.resultantStringArray.length;\n for( i = 0 ; i < sz ; i++ ) {\n if( i != 0 ) {\n res += \"\\n\";\n }\n res += this.resultantStringArray[ i ];\n }\n fsObj = require( 'fs' );\n currentDirectory = __dirname;\n outputFilePath = currentDirectory + \"\\\\\" + outputFileName;\n if( currentDirectory.charAt( 1 ) != \":\" ) {\n //not local machine/windows\n outputFilePath = outputFileName;\n }\n fsObj.writeFileSync( outputFilePath , res );\n this.clearPercase();\n };\n}\n\nfunction CodeExecutioner() {\n this.irObj = new InputReader();\n this.psObj = new ProblemSolver();\n this.fohObj = new FileOutputHandler();\n\n this.runCode = function() {\n var testCases , i , hasMoreTestCases , isLocalMachine , localContext;\n isLocalMachine = false;\n try {\n if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {\n //only on windows\n isLocalMachine = true;\n }\n }\n catch( ex ) {\n isLocalMachine = false;\n }\n if( isLocalMachine == true ) {\n //local machine runs on node and relies on file i/o\n print = console.log;\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n localContext = this.fohObj;\n print = function() {\n localContext.addNewLine.apply( localContext , arguments );\n }\n }\n this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );\n }\n else {\n //server machine\n try {\n var rlObj = readline;\n //server runs on javasctipt v8 distribution and has readline method on global context\n this.irObj.readAllLines();\n }\n catch( ex ) {\n try {\n var pObj = process;\n //server runs on node\n print = console.log;\n this.irObj.readAllLinesFromNodeStdin();\n }\n catch( ex ) {\n try {\n var ipObj = importPackage;\n //server runs on rhino\n this.irObj.readAllLinesFromRhinoStdin();\n }\n catch( ex ) {\n throw new Error( \"Unknown javasctipt distribution!\" );\n }\n }\n }\n }\n if( this.psObj.HAS_TEST_CASES == true ) {\n testCases = this.irObj.nextInt();\n for( i = 0 ; i < testCases ; i++ ) {\n this.psObj.clearPerCase();\n this.psObj.getInput( this.irObj );\n this.psObj.solveCase();\n }\n }\n else {\n while( true ) {\n this.psObj.clearPerCase();\n hasMoreTestCases = this.psObj.getInput( this.irObj );\n if( hasMoreTestCases == false ) {\n break;\n }\n this.psObj.solveCase();\n }\n }\n if( this.psObj.DO_OUTPUT_TO_FILE == true ) {\n //only works for local machine(tested)\n this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );\n }\n };\n\n this.runCode();\n}\n\nnew CodeExecutioner();\n"}, {"source_code": "\nvar n = Number(readline()); \nvar A = readline().split(' ').map(Number) \n\nvar m = Number(readline()); \nvar Q = readline().split(' ').map(Number) \n\nfor (var i = 1; i < n; i++) { \n A[i] += A[i-1] \n}\n\nvar lower_bound = function(A, x) { \n var l = 0; \n var r = A.length - 1; \n\n while (l <= r) { \n var m = Math.floor((l + r) / 2); \n if (A[m] < x) { \n l = m + 1; \n }\n else { \n r = m - 1; \n }\n }\n return l; \n}\n\nfor (i in Q) { \n print(lower_bound(A, Q[i]) + 1); \n}\n"}], "negative_code": [{"source_code": "var x = parseInt(readline());\n\nvar arr= readline().split(' ').map(a => parseInt(a));\n\nfor(var i=1; i parseInt(a));\n\nfor(var index=0; indexarr[mid]){\n left=mid+1;\n }else{\n right=mid-1;\n }\n }\n if(left===right)\n print(mid+1);\n if(right<0 || find[index]>arr[right])\n print(left+1);\n if(left>x-1 || find[index] parseInt(a));\n\nfor(var i=1; i parseInt(a));\n\nfor(var index=0; indexarr[mid]){\n left=mid+1;\n }else{\n right=mid-1;\n }\n }\n if(left===right)\n print(mid+1);\n if(right<0 || find[index]>arr[right])\n print(left+1);\n if(left>x-1 || find[index] arr[mid]) start = mid + 1;\n if (x == arr[mid]) return mid;\n }\n return start + 1;\n}\n/************************************** */\n\nvar n = parseInt(readline());\nvar prev = 0;\nvar a = readline()\n .split(\" \")\n .map((val) => {\n var x = parseInt(val);\n x += prev;\n prev = x;\n return x;\n });\nvar m = parseInt(readline());\nvar q = readline()\n .split(\" \")\n .map((val) => parseInt(val));\n\nfor (var i = 0; i < m; i++) {\n print(Bst(a, q[i]));\n}\n"}, {"source_code": "var piles_number = readline();\nvar piles = readline().split(' ');\nvar expected_worm_numbers = readline();\nvar expected_worms = readline().split(' ');\n\nvar getWormsAfterPile = function(piles_number, piles) {\n var worms_after_piles = [];\n for (i = 0; i < piles_number; i++) {\n var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];\n worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);\n }\n return worms_after_piles;\n}\n\nvar getWormPile = function(worms_after_piles, expected_worm, start) {\n if (worms_after_piles[0] >= expected_worm) {\n return 1;\n }\n for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {\n if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {\n return i+1;\n }\n }\n}\n\nvar result = [];\n\nvar worms_after_piles = getWormsAfterPile(piles_number, piles);\nvar sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});\nvar last_worm_pile = 0;\nfor (k = 0; k < expected_worm_numbers; k++) {\n if (result[sorted_expected_worms[k]] != void(0)) {\n continue;\n }\n var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile);\n last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;\n}\n\nprint(expected_worms);\nfor (l = 0; l < expected_worm_numbers; l++) {\n print(result[expected_worms[l]]);\n}\n\n"}, {"source_code": "var piles_number = readline();\nvar piles = readline().split(' ');\nvar expected_worm_numbers = readline();\nvar expected_worms = readline().split(' ');\n\nvar getWormsAfterPile = function(piles_number, piles) {\n var worms_after_piles = [];\n for (i = 0; i < piles_number; i++) {\n var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];\n worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);\n }\n return worms_after_piles;\n}\n\nvar getWormPile = function(worms_after_piles, expected_worm, start) {\n if (worms_after_piles[0] >= expected_worm) {\n return 1;\n }\n for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {\n if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {\n return i+1;\n }\n }\n}\n\nvar result = [];\n\nvar worms_after_piles = getWormsAfterPile(piles_number, piles);\nvar sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});\nvar last_worm_pile = 0;\nfor (k = 0; k < expected_worm_numbers; k++) {\n if (result[sorted_expected_worms[k]] != void(0)) {\n continue;\n }\n var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile);\n last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;\n}\n\nfor (l = 0; l < expected_worm_numbers; l++) {\n print(result[expected_worms[l]]);\n}\n\n"}, {"source_code": "var n = readline();\nvar a = readline().split(\" \");\nvar m = readline();\nvar q = readline().split(\" \");\nvar z = [0];\nfor (j = 0;jy) {se = j+1;\n\t\tbreak sr;}\n\t\ty = y + a[j];\n\t\t}\n\t\tprint(se); \n\t}"}, {"source_code": "var n = 5;\nvar a = [\"2\",\"7\",\"3\",\"4\",\"9\"];\nvar m = 3;\nvar q = [\"1\",\"25\",\"11\"];\nvar z = [0];\nfor (j = 0;j= arrQ[i]) {\n out += (j + 1).toString() + '\\n';\n break;\n } else {\n sum += arrA[i+1];\n jsum = j + 1;\n }; \n };\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[i] = (j + 1).toString() + '\\n';\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[arrQnum[i]] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\narrA.push(0);\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]-1] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[i] = j + '\\n';\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[arrQnum[i]] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar out ='';\n\nvar arrQnum = [];\n\nfor (var i = 0; i < m; i++) {\n arrQ[i][0] = arrQ[i];\n arrQ[i][1] = i; \n}\n\narrQ.sort(function(a,b){return a[0]-b[0];});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i][0]) {\n arrOut[arrQ[i][1]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]-1] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[i] = j;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += (arrOut[arrQnum[i]] + 1) + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar out ='';\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n if (arrQnum[arrQ[i]] == undefined) {\n arrQnum[arrQ[i]] = i;\n } else {\n out = 'duble';\n }\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n if (arrOut[i] !== undefined) {\n out += arrOut[i] + '\\n';\n };\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\narrA.push(0);\narrA.push(0);\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n if (arrOut[i] !== undefined) {\n out += arrOut[i] + '\\n';\n };\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\narrA.push(0);\narrA.push(0);\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[i] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n out += (j + 1).toString() + '\\n';\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n arrQnum[arrQ[i]] = i;\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar out ='';\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[i] = (j + 1) + '\\n';\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n out += arrOut[arrQnum[i]] + '\\n';\n};\n\nprint(out);\n\n\n"}, {"source_code": "\n// 474B \u0427\u0435\u0440\u0432\u0438 \n\n\nvar n = parseInt(readline());\n\n// var input_line = readline().split(' ').map(Number);\nvar arrA = readline().split(' ').map(Number);\n\nvar m = parseInt(readline());\n\nvar arrQ = readline().split(' ').map(Number);\n\nvar out ='';\n\nvar arrQnum = [];\nfor (var i = 0; i < m; i++) {\n if (arrQnum[arrQ[i]] == undefined) {\n arrQnum[arrQ[i]] = i;\n } else {\n out += 'duble';\n }\n}\n\narrQ.sort(function(a,b){return a-b;});\n\nvar sum = arrA[0];\nvar jsum = 0;\nvar arrOut = [];\n\nfor (var i = 0; i < m; i++) {\n for (var j = jsum; j < n; j++) {\n if (sum >= arrQ[i]) {\n arrOut[arrQnum[arrQ[i]]] = j + 1;\n break;\n } else {\n sum += arrA[j+1];\n jsum = j + 1;\n }; \n };\n};\n\nfor (var i = 0; i < m; i++) {\n if (arrOut[i] !== undefined) {\n out += arrOut[i] + '\\n';\n };\n};\n\nprint(out);\n\n\n"}, {"source_code": "readline()\nvar A=readline().split(' ').map(Number)\nreadline()\nvar Q=readline().split(' ').map(Number)\n\nvar T=new Array(A.length + 1)\nT[0]=0\nfor (var i=1; i {\n var lb=0,ub=T.length-1;\n while (1) {\n var m=(ub+lb)>>1;\n if (x find(x) + 1).join('\\n'))"}, {"source_code": "function getWormPositions(worms, labels){\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] = total[i -1] + worms[i];\n } \n \n \n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n console.log(idx + 1)\n }\n \n}\n \nfunction bs(arr, target){\n if(!arr.length) return -1;\n \n let mid = Math.floor(arr.length / 2);\n \n let prev = (mid - 1 ) > -1 ? arr[mid - 1]: -1;\n \n if(arr[mid] >= target && prev < target){\n return mid;\n } else if(arr[mid] > target){\n return bs(arr.slice(0, mid), target);\n } else if(arr[mid] < target){\n let sub = bs(arr.slice(mid + 1), target);\n return sub >= 0 ? sub + 1 + mid : -1;\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n \n \nfunction getWormPositions(worms, labels) {\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] += total[i - 1] + worms[i]\n }\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n \nfunction bs(arr, target) {\n// console.log(arr, target)\n if (!arr.length) return -1;\n \n let mid = Math.floor(arr.length / 2);\n let prev = (mid - 1) > -1 ? arr[mid - 1] : - Infinity;\n \n \n \n if (arr[mid] === target) {\n return mid;\n } else if (arr[mid] > target) {\n return bs(arr.slice(0, mid), target);\n } else {\n let sub = bs(arr.slice(mid + 1), target);\n return sub >= 0 ? sub + 1 + mid : -1;\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n\nfunction getWormPositions(worms, labels){\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] = total[i -1] + worms[i];\n } \n\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n\nfunction bs(arr, target){\n if(!arr) return -1;\n\n let mid = Math.floor(arr.length / 2);\n let prev = mid - 1 >= 0 ? arr[mid - 1] : - Infinity; \n if(arr[mid] >= target && prev < target){\n return mid;\n } else if(arr[mid] > target){\n return bs(arr.slice(0, mid), target);\n } else if(arr[mid] < target){\n let sub = bs(arr.slice(mid + 1), target);\n return sub > 0 ? sub + 1 + mid : -1;\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n\n\nfunction getWormPositions(worms, labels) {\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] += total[i - 1] + worms[i]\n }\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n\nfunction bs(arr, target) {\n// console.log(arr, target)\n if (!arr.length) return -1;\n\n let mid = Math.floor(arr.length / 2);\n let prev = (mid - 1) > -1 ? arr[mid - 1] : - Infinity;\n console.log(arr[mid], \"current element\", prev, \"prev\", target)\n\n\n if (arr[mid] === target) {\n return mid;\n } else if (arr[mid] > target) {\n return bs(arr.slice(0, mid), target);\n } else {\n let sub = bs(arr.slice(mid + 1), target);\n return sub >= 0 ? sub + 1 + mid : -1;\n }\n}\n"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\nfunction getWormPositions(worms, labels){\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] = total[i -1] + worms[i];\n } \n console.log(total, \"total\")\n\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n\nfunction bs(arr, target){\n if(!arr) return -1;\n\n let mid = Math.floor(arr.length / 2);\n let prev = mid - 1 >= 0 ? arr[mid - 1] : - Infinity; \n if(arr[mid] >= target && prev < target){\n return mid;\n } else if(arr[mid] > target){\n return bs(arr.slice(0, mid), target);\n } else if(arr[mid] < target){\n let sub = bs(arr.slice(mid + 1), target);\n return sub > 0 ? sub + 1 + mid : -1;\n }\n}"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main();\n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n \nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n \n \nfunction getWormPositions(worms, labels){\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] = total[i -1] + worms[i];\n } \n \n labels.sort((a,b) => a - b);\n \n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n \nfunction bs(arr, target){\n if(!arr) return -1;\n \n let mid = Math.floor(arr.length / 2);\n \n let prev = (mid - 1 ) > -1 ? arr[mid - 1]: -1;\n \n if(arr[mid] >= target && prev < target){\n return mid;\n } else if(arr[mid] > target){\n return bs(arr.slice(0, mid), target);\n } else if(arr[mid] < target){\n let sub = bs(arr.slice(mid + 1), target);\n return sub >= 0 ? sub + 1 + mid : -1;\n }\n}"}, {"source_code": "'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n let piles = readline();\n let worms = readline().split(' ');\n worms = worms.map(n => parseInt(n));\n let juicy = readline();\n let juicyWormsLabels = readline().split(' ');\n juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));\n getWormPositions(worms, juicyWormsLabels)\n}\n\n\nfunction getWormPositions(worms, labels){\n let res = [];\n let total = new Array(worms.length).fill(0);\n total[0] = worms[0];\n for (let i = 1; i < worms.length; i++) {\n total[i] = total[i -1] + worms[i];\n } \n\n for (let i = 0; i < labels.length; i++) {\n let cur = labels[i];\n let idx = bs(total, cur);\n res.push(idx + 1);\n }\n res.forEach(n => console.log(n));\n return res;\n}\n\nfunction bs(arr, target){\n if(!arr) return -1;\n\n let mid = Math.floor(arr.length / 2);\n // console.log(mid + 1, arr.length)\n let prev = (mid - 1 ) > -1 ? arr[mid - 1]: -1;\n// console.log(`${arr[mid]} <= ${target} < ${next}`) \n if(arr[mid] >= target && prev < target){\n return mid;\n } else if(arr[mid] > target){\n return bs(arr.slice(0, mid), target);\n } else if(arr[mid] < target){\n let sub = bs(arr.slice(mid + 1), target);\n return sub > 0 ? sub + 1 + mid : -1;\n }\n}"}], "src_uid": "10f4fc5cc2fcec02ebfb7f34d83debac"} {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [n, a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, a, b) {\n const h = n / 2\n const ans = []\n const used = []\n ans[0] = a\n used[a] = 1\n ans[h] = b\n used[b] = 1\n\n let i = n\n let count = 1\n while (i >= a && count < h) {\n if (!used[i]) {\n used[i] = 1\n ans[count++] = i\n }\n i--\n }\n// console.log(ans)\n if (count < h) return -1\n i = 1\n count = 1\n while (i <= b && count < h) {\n if (!used[i]) {\n used[i] = 1\n ans[h + count++] = i\n }\n i++\n }\n if (count < h) return -1\n return ans.join(' ')\n}\n", "positive_code": [{"source_code": "let stop = '';\nprocess.stdin.on('data', c => stop += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = stop.split(EOL);\n var t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var n = k[0], a = k[1], b = k[2];\n if(a <= n / 2 && b >= n / 2 + 1 || b == n / 2 && a == n / 2 + 1){\n var ans = a + ' ';\n for(j = n; j; j--){\n if(j != a && j != b){\n ans += j + ' ';\n }\n }\n ans += b;\n console.log(ans);\n }else{\n console.log(-1);\n }\n }\n});"}, {"source_code": "var dataitr;\r\nvar stdin_input = \"\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"ascii\");\r\nprocess.stdin.on(\"data\", function (input) { stdin_input += input; });\r\nprocess.stdin.on(\"end\", function () { dataitr = stdin_input.split('\\n').values(); main(); });\r\n\r\nconst rl = () => dataitr.next().value.trim();\r\nconst rn = () => Number(rl());\r\nconst ra = () => rl().split(' ');\r\nconst rna = () => ra().map(x => Number(x));\r\n\r\nfunction main () {\r\n\tlet T = rn();\r\n\twhile (T--) {\r\n\t\tconst [n, a, b] = rna();\r\n\r\n\t\tlet ans = Array.from(Array(n), (_, i) => i+1);\r\n\t\tif (a <= n/2 && b >= n/2+1) {\r\n\t\t\tans[a-1] = b;\r\n\t\t\tans[b-1] = a;\r\n\t\t\tans.reverse();\r\n\t\t} else if (a == n/2+1 && b == n/2) {\r\n\t\t\tans.reverse();\r\n\t\t} else {\r\n\t\t\tans = false;\r\n\t\t}\r\n\r\n\t\tconsole.log(ans ? ans.join(' ') : -1);\r\n\t}\r\n}\r\n\r\n"}, {"source_code": "process.stdin.setEncoding('utf-8')\r\nconst readline = require('readline')\r\n\r\nconst rl = readline.createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n }\r\n)\r\n\r\nlet count = -1\r\nlet inputArr = []\r\n\r\nrl.on('line', data => {\r\n if (count === -1) {\r\n count = +data\r\n } else if (count !== 0) {\r\n inputArr.push(data.trim())\r\n count--\r\n }\r\n // max number 2^(53) - 1 ~~ 10^(15)\r\n if (count === 0) {\r\n inputArr = inputArr.map(i => i.split(' ').map(j => +j))\r\n main()\r\n process.exit(0)\r\n }\r\n})\r\n\r\n\r\nfunction solve([n, a, b]) {\r\n const tmpArr = Array(200)\r\n let count = 1, flag = false\r\n tmpArr[0] = a\r\n for (let i = n; i > Math.floor(n / 2); i--) {\r\n if (i !== b && i !== a) {\r\n tmpArr[count] = i\r\n count++\r\n }\r\n }\r\n tmpArr[count] = b\r\n count++\r\n for (let i = Math.floor(n / 2); i > 0; i--) {\r\n if (i !== b && i !== a) {\r\n tmpArr[count] = i\r\n count++\r\n }\r\n }\r\n flag = false\r\n let mVal = Number.MAX_SAFE_INTEGER\r\n for (let i = 0; i < Math.floor(n / 2); i++) {\r\n if (tmpArr[i] < mVal) {\r\n mVal = tmpArr[i]\r\n }\r\n }\r\n if (mVal === a) {\r\n let maxVal = Number.MIN_SAFE_INTEGER\r\n for (let i = Math.floor(n / 2); i < n; i++) {\r\n if (tmpArr[i] > maxVal) {\r\n maxVal = tmpArr[i]\r\n }\r\n }\r\n if (maxVal == b) {\r\n flag = true\r\n }\r\n }\r\n if (flag) {\r\n console.log(tmpArr.slice(0, n).join(' '))\r\n } else {\r\n console.log('-1')\r\n }\r\n}\r\n\r\nfunction main() {\r\n for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])\r\n}"}, {"source_code": "var t = readline();\n \nfor (var i = 0; i < t; i++) {\n var k = readline().split(' ').map(Number);\n var mid = k[0] / 2;\n if (mid >= k[1] && k[2] >= mid + 1 || k[1] === mid + 1 && k[2] === mid) {\n write(k[1],' ');\n for(var j = k[0]; j; j--) if (j != k[1] && j != k[2]) write(j,' ');\n print(k[2]);\n } else {\n print(-1);\n }\n}\n\t \t\t \t\t \t\t \t\t\t\t \t \t\t\t\t"}, {"source_code": "var t = readline();\r\n \r\nfor (var i = 0; i < t; i++) {\r\n var k = readline().split(' ').map(Number);\r\n var mid = k[0] / 2;\r\n if (mid >= k[1] && k[2] >= mid + 1 || k[1] === mid + 1 && k[2] === mid) {\r\n write(k[1],' ');\r\n for(var j = k[0]; j; j--) if (j != k[1] && j != k[2]) write(j,' ');\r\n print(k[2]);\r\n } else {\r\n print(-1);\r\n }\r\n}"}], "negative_code": [], "src_uid": "6ea491419f3ea387cf2aded8a8db914d"} {"source_code": "var t = readline();\r\n\r\nfor (var i = 0; i < t; i++) {\r\n var a = readline().split(' ').map(Number);\r\n var x = a[0];\r\n var y = a[1];\r\n \r\n if (x === 0 && y === 0) {\r\n print(0);\r\n continue;\r\n }\r\n \r\n var z = Math.sqrt(x * x + y * y);\r\n \r\n var r = Math.round(z);\r\n if (Math.abs(z - r) < 0.000001) {\r\n print(1);\r\n continue;\r\n }\r\n \r\n print(2);\r\n}", "positive_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\r\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\r\nconst print = console.log\r\nconst lines = []\r\nrl.on('line', line => {\r\n lines.push(line);\r\n});\r\nrl.on('close', main)\r\nlet rli = 0;\r\nfunction readline() {\r\n return lines[rli++];\r\n}\r\nconst EPS = 1e-6;\r\n \r\nlet is_sq = (x, y)=>{\r\n let sq = Math.sqrt((x*x)+(y*y));\r\n let rsq = Math.round(Math.sqrt((x*x)+(y*y)));\r\n return Math.abs(sq*sq-rsq*rsq){\r\n if (x==0 && y==0)\r\n return 0;\r\n if (x>y)\r\n return rec(y, x);\r\n if (is_sq(x, y))\r\n return 1;\r\n let k = x+';'+y;\r\n if (caches.has(k))\r\n return caches.get(k)\r\n let min = Infinity;\r\n for (let dx = 0; dx<=x; dx++){\r\n for (let dy = 0; dy<=y; dy++){\r\n if (dx==x && dy==y || dx==0 && dy==0)\r\n continue;\r\n if (is_sq(dx, dy))\r\n min = Math.min(min, rec(x-dx, y-dy)+1);\r\n }\r\n }\r\n caches.set(k, min);\r\n return min;\r\n};\r\n \r\nfunction main() {\r\n let n = +readline();\r\n for (let i=0; i+a);\r\n if (x==0 && y==0)\r\n print(0);\r\n else if(is_sq(x, y))\r\n print(1);\r\n else\r\n print(2);\r\n }\r\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [x,y]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let z=Math.floor(Math.sqrt(x*x+y*y));\r\n if(x===0&&y===0)\r\n {\r\n console.log(0);\r\n }\r\n else if(z*z===x*x+y*y)\r\n {\r\n console.log(1);\r\n }\r\n else\r\n {\r\n console.log(2);\r\n }\r\n }\r\n})"}, {"source_code": "function solve(arr) {\n let data = [...arr];\n data.shift();\n data = data.map((item) => item.split(\" \").map((num) => parseInt(num)));\n data.forEach((item) => {\n const x = item[0];\n const y = item[1];\n const len = Math.sqrt(x * x + y * y);\n if (len === 0) {\n console.log(0);\n } else if (len.toString().includes(\".\")) {\n console.log(2);\n } else {\n console.log(1);\n }\n });\n}\nlet text = \"\";\nprocess.stdin.resume();\nprocess.stdin.setEncoding(\"utf-8\");\nprocess.stdin.on(\"data\", (t) => {\n if (t === \"\\r\\n\" || t === \"\\n\") {\n process.stdin.emit(\"end\");\n } else {\n text += t;\n }\n});\nprocess.stdin.on(\"end\", () => {\n const input = text.trim().replace(/\\r/g, \"\").split(\"\\n\");\n solve(input);\n process.exit();\n});\n\n \t\t\t \t \t \t\t \t \t\t \t\t \t \t\t \t \t"}, {"source_code": "const readline = require('readline')\r\nlet r = readline.createInterface({\r\n input:process.stdin,\r\n output:process.stdout\r\n})\r\nr.on('line',line=> {\r\n let data = line.split(' ')\r\n let [a,b] = data\r\n if(data.length==1) return\r\n let s = a*a+b*b\r\n if(+a===0&&+b===0) console.log(0)\r\n else if(Number.isInteger(Math.sqrt(s))) console.log(1)\r\n else console.log(2)\r\n})"}, {"source_code": "const main = (input) => {\r\n input = input.trim().split('\\n')\r\n\r\n const xy = input.slice(1).map((a) => a.split(' ').map((b) => Number(b)))\r\n const ans = xy.map(([x, y]) => {\r\n if (x === 0 && y === 0) {\r\n return 0\r\n } else if (Number.isInteger(Math.sqrt(x * x + y * y))) {\r\n return 1\r\n } else {\r\n return 2\r\n }\r\n })\r\n console.log(ans.join('\\n'))\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "const main = (input) => {\r\n input = input.trim().split('\\n')\r\n\r\n const xy = input.slice(1).map((a) => a.split(' ').map((b) => Number(b)))\r\n const ans = xy.map(([x, y]) => {\r\n if (x === 0 && y === 0) {\r\n return 0\r\n } else if (Math.sqrt(x * x + y * y) % 1 === 0) {\r\n return 1\r\n } else {\r\n return 2\r\n }\r\n })\r\n console.log(ans.join('\\n'))\r\n}\r\n\r\nmain(require('fs').readFileSync(0).toString())"}, {"source_code": "let text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', (t) => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\n\nclass TreeNode {\n constructor(nodeVal) {\n this.nodeVal = nodeVal;\n this.nodeSum = 0;\n this.toParentVal = 0;\n this.related = [];\n }\n}\n\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/r/g, '').split('\\n');\n const total = Number(input[0]);\n for (let i = 1; i <= total; i++) {\n console.log(solve(input[i]));\n }\n\n process.exit();\n});\n\t \t \t\nfunction solve(str) {\n const [a, b] = str.split(' ').map((ele) => +ele);\n if (!a && !b) {\n return 0;\n }\n const math = Math.sqrt(a * a + b * b);\n if (math >> 0 === math) {\n return 1;\n }\n return 2;\n}\n\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t \t\t\t"}, {"source_code": "function solve(x, y) {\n let result;\n if (x === 0 && y === 0) {\n result = 0;\n } else if (Math.sqrt(x ** 2 + y ** 2) % 1) {\n result = 2;\n } else {\n result = 1;\n }\n console.log(result);\n return result;\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const total = parseInt(input[0]);\n const dataArr = input\n .slice(1, total + 1)\n .map(item => item.split(/\\s/).map(n => parseInt(n)));\n\n for (const item of dataArr) {\n solve(...item);\n }\n});\n\n\t\t\t \t \t\t \t\t\t \t \t \t \t"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n\tvar t = lines[0];\n for(i = 1; i <= t; i++){\n var k = lines[i].split(' ').map(Number);\n var x = k[0];\n var y = k[1];\n var a = 2 * Math.sqrt(Math.pow(0 - x, 2) + Math.pow(0 - y, 2));\n if(x === 0 && y === 0){\n console.log(0);\n }else if(a % 1 === 0){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n});"}, {"source_code": "let q = '';\nprocess.stdin.on('data', c => q += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = q.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var x = k[0];\n var y = k[1];\n var ans = Math.sqrt(Math.pow(0 - x, 2) + Math.pow(0 - y, 2));\n if(x === 0 && y === 0){\n console.log(0);\n }else if(ans % 1 === 0){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n});"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n if (a === 0 && b === 0) return 0\n const r = Math.floor(Math.sqrt(a * a + b * b))\n if (r * r === a * a + b * b) return 1\n return 2\n}\n"}, {"source_code": "'use strict';\r\n\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf-8');\r\n\r\nlet inputString = '';\r\nlet currentLine = 0;\r\n\r\nprocess.stdin.on('data', stdin => inputString += stdin);\r\n\r\nprocess.stdin.on('end', _ => {\r\n inputString = inputString.trim().split('\\n').map(s => s.trim());\r\n main(); \r\n});\r\n\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n\r\nfunction output(x) {\r\n if (typeof x !== 'string') {\r\n x = x.toString();\r\n }\r\n //process.stdout.write(x); // without auto '\\n' (newline)\r\n console.log(x); // with auto '\\n' (newline)\r\n}\r\n\r\nfunction main() {\r\n let N = readline();\r\n\r\n for (let test = 0; test < N; test++) {\r\n let [x, y] = readline().split(' ').map(Number);\r\n if (x === 0 && y === 0) output(0);\r\n else if (Number.isInteger(Math.sqrt(x*x+y*y))) output(1);\r\n else output(2);\r\n }\r\n}\r\n"}, {"source_code": "let i = '';\nprocess.stdin.on('data', c => i += c);\nprocess.stdin.on('end', () => {\n const {EOL} = require('os');\n const lines = i.split(EOL);\n var n = lines[0];\n var e = 0;\n for(j = 1; j <= n; j++){\n var k = lines[j].split(' ').map(Number);\n var x = k[0];\n var y = k[1];\n var ans = Math.sqrt(Math.pow(0 - x, 2) + Math.pow(0 - y, 2));\n if(x === 0 && y === 0){\n console.log(0);\n }else if(ans % 1 === 0){\n console.log(1);\n }else{\n console.log(2);\n }\n }\n});\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n main();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\n/***\nEducational Codeforces Round 125 (Div. 2)\n2022-03-22\n\nA. Integer Moves\n***/\n\nfunction main() {\n // INPUT: Number of test cases\n let t = readline();\n t = parseInt(t);\n let s;\n for (let i = 0; i < t; i++) {\n // INPUT: x and y coords of the point `x y`\n s = readline();\n s = s.split(' ');\n s.map(parseInt);\n\n // Max is 2: we can always move direct x and direct y\n // So we only need to check pythagorean triple\n const eucDist = Math.sqrt(s[0]*s[0] + s[1]*s[1]);\n if (eucDist === 0) {\n console.log(0);\n } else if (Number.isInteger(eucDist)) {\n console.log(1);\n } else {\n console.log(2);\n }\n }\n}\n"}, {"source_code": "\r\nvar repeatTimes = readline();\r\n \r\nwhile(repeatTimes) {\r\n var a = readline().split(' ').map(Number);\r\n var x = a[0];\r\n var y = a[1];\r\n if (x || y) {\r\n var z = Math.sqrt(x * x + y * y);\r\n \r\n var r = Math.round(z);\r\n if (Math.abs(z - r) < 0.000001)\r\n print(1 )\r\n else\r\n print(2)\r\n }else\r\n print(0)\r\n repeatTimes -=1\r\n \r\n}"}, {"source_code": "var t = parseInt(readline());\r\n\r\nfunction div(val, by){\r\n return (val - val % by) / by;\r\n}\r\n\r\nfunction setCharAt(str,index,chr) {\r\n if(index > str.length-1) return str;\r\n return str.substr(0,index) + chr + str.substr(index+1);\r\n}\r\n\r\nvar ch = 'a';\r\nvar acode = ch.charCodeAt(0);\r\n\r\n\r\nfor (var tt = 0; tt < t; tt++) {\r\n var a = readline().split(' ').map(Number);\r\n var x = a[0], y = a[1];\r\n if (x === 0 && y === 0) {\r\n write('0\\n');\r\n continue;\r\n }\r\n \r\n var sqrt = Math.sqrt(x * x + y * y);\r\n var rounded = Math.round(sqrt);\r\n if (Math.abs(sqrt - rounded) < 0.000001) {\r\n write('1\\n');\r\n continue;\r\n }\r\n \r\n write('2\\n');\r\n}\r\n"}], "negative_code": [{"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst EPS = 1e-6;\n\nlet is_sq = (x, y)=>{\n let sq = Math.sqrt((x*x)+(y*y));\n let rsq = Math.round(Math.sqrt((x*x)+(y*y)));\n return Math.abs(sq*sq-rsq*rsq){\n if (x==0 && y==0)\n return 0;\n if (x>y)\n return rec(y, x);\n if (is_sq(x, y))\n return 1;\n let k = x+';'+y;\n if (caches.has(k))\n return caches.get(k)\n let min = Infinity;\n for (let dx = 0; dx<=x; dx++){\n for (let dy = 0; dy<=y; dy++){\n if (dx==x && dy==y || dx==0 && dy==0)\n continue;\n if (is_sq(dx, dy))\n min = Math.min(min, rec(x-dx, y-dy)+1);\n }\n }\n caches.set(k, min);\n return min;\n};\n \nfunction main() {\n let n = +readline()[0];\n for (let i=0; i+a);\n if (x==0 && y==0)\n print(0);\n else if(is_sq(x, y))\n print(1);\n else\n print(2);\n }\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst EPS = 1e-8;\n\nlet is_sq = (x, y)=>{\n let sq = Math.sqrt((x*x)+(y*y));\n let rsq = Math.round(Math.sqrt((x*x)+(y*y)));\n return Math.abs(sq*sq-rsq*rsq){\n if (x==0 && y==0)\n return 0;\n if (x>y)\n return rec(y, x);\n if (is_sq(x, y))\n return 1;\n let k = x+';'+y;\n if (caches.has(k))\n return caches.get(k)\n let min = Infinity;\n for (let dx = 0; dx<=x; dx++){\n for (let dy = 0; dy<=y; dy++){\n if (dx==x && dy==y || dx==0 && dy==0)\n continue;\n if (is_sq(dx, dy))\n min = Math.min(min, rec(x-dx, y-dy)+1);\n }\n }\n caches.set(k, min);\n return min;\n};\n \nfunction main() {\n let n = +readline()[0];\n for (let i=0; i+a);\n if (x==0 && y==0)\n print(0);\n else if(is_sq(x, y))\n print(1);\n else\n print(2);\n }\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nfunction solve(graph, s) {\n var solutions = {};\n solutions[s] = [];\n solutions[s].dist = 0;\n while(true) {\n var nearest = null;\n var dist = Infinity;\n //for each existing solution\n for(var n in solutions) {\n if(!solutions[n])\n continue\n var ndist = solutions[n].dist;\n var adj = graph[n];\n //for each of its adjacent nodes...\n for(var a in adj) {\n //without a solution already...\n if(solutions[a])\n continue;\n //choose nearest node with lowest *total* cost\n var d = adj[a] + ndist;\n if(d < dist) {\n nearest = a;\n dist = d;\n }\n }\n }\n //no more solutions\n if(dist === Infinity) {\n break;\n }\n solutions[nearest] = {dist};\n }\n return solutions;\n}\n \nlet add = (graph, a, b, w)=>{\n if (!graph[a])\n graph[a] = {};\n graph[a][b] = w;\n};\nconst EPS = 1e-8;\n\nlet is_sq = (x, y)=>{\n let sq = Math.sqrt((x*x)+(y*y));\n let rsq = Math.round(Math.sqrt((x*x)+(y*y)));\n return Math.abs(sq*sq-rsq*rsq){\n if (x==0 && y==0)\n return 0;\n if (x>y)\n return rec(y, x);\n if (is_sq(x, y))\n return 1;\n let k = x+';'+y;\n if (caches.has(k))\n return caches.get(k)\n let min = Infinity;\n for (let dx = 0; dx<=x; dx++){\n for (let dy = 0; dy<=y; dy++){\n if (dx==x && dy==y || dx==0 && dy==0)\n continue;\n if (is_sq(dx, dy))\n min = Math.min(min, rec(x-dx, y-dy)+1);\n }\n }\n caches.set(k, min);\n return min;\n};\n \nfunction main() {\n let n = +readline()[0];\n for (let i=0; i+a);\n if (x<0)\n x = -x;\n if (y<0)\n y = -y;\n print(rec(x, y))\n }\n}"}, {"source_code": "'use strict'; /*jslint node:true, browser:true, es6:true*/\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })\nconst print = console.log\nconst lines = []\nrl.on('line', line => {\n lines.push(line);\n});\nrl.on('close', main)\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\nconst EPS = 1e-8;\n\nlet is_sq = (x, y)=>{\n let sq = Math.sqrt((x*x)+(y*y));\n let rsq = Math.round(Math.sqrt((x*x)+(y*y)));\n return Math.abs(sq*sq-rsq*rsq){\n if (x==0 && y==0)\n return 0;\n if (x>y)\n return rec(y, x);\n if (is_sq(x, y))\n return 1;\n let k = x+';'+y;\n if (caches.has(k))\n return caches.get(k)\n let min = Infinity;\n for (let dx = 0; dx<=x; dx++){\n for (let dy = 0; dy<=y; dy++){\n if (dx==x && dy==y || dx==0 && dy==0)\n continue;\n if (is_sq(dx, dy))\n min = Math.min(min, rec(x-dx, y-dy)+1);\n }\n }\n caches.set(k, min);\n return min;\n};\n \nfunction main() {\n let n = +readline()[0];\n for (let i=0; i+a);\n if (x<0)\n x = -x;\n if (y<0)\n y = -y;\n print(rec(x, y))\n }\n}"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n let t=parseInt(line[0]);\r\n for(let _=1;_<=t;_++)\r\n {\r\n let [x,y]=line[_].split(' ').map(x=>{return parseInt(x)});\r\n let z=Math.sqrt(x*x+y*y);\r\n if(x===0&&y===0)\r\n {\r\n console.log(0);\r\n }\r\n else if(z*z===x*x+y*y)\r\n {\r\n console.log(1);\r\n }\r\n else\r\n {\r\n console.log(2);\r\n }\r\n }\r\n})"}, {"source_code": "let buf='';\r\n\r\nprocess.stdin.on('readable', function(){\r\n let chunk=process.stdin.read();\r\n if(chunk) buf+=chunk.toString();\r\n})\r\n\r\nprocess.stdin.on('end', function(){\r\n const {EOL}=require('os');\r\n let line=buf.split(EOL);\r\n console.log(line);\r\n})"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet num = -1;\nconst rows = [];\nrl.on('line', line => {\n if (num < 0) {\n num = parseInt(line.trim());\n } else {\n rows.push(line.trim());\n if (rows.length === num) {\n dealInput(rows);\n }\n }\n});\nconst dealInput = (rows) => {\n let location = []\n rows.forEach(item => {\n location.push(item.split(' '))\n })\n let x = 0\n let y = 0\n let s = 0\n location.forEach(item => {\n let num = Math.sqrt(((item[0]-x)*(item[0]-x))+((item[1]-y)*(item[1]-y)))\n x = item[0]\n y = item[1]\n if(parseInt(num)==num) {\n s++\n } else {\n s+=2\n }\n })\n console.log(s);\n rl.close();\n};\n\nrl.on('close', () => {\n process.exit(0);\n});\n\t\t\t \t \t\t\t\t\t\t \t \t \t \t\t \t\t\t \t"}, {"source_code": "function solve(x, y) {\n let result;\n if (x === 0 && y === 0) {\n result = 0;\n } else if (Math.sqrt(x ** 2 + y ** 2) % 1) {\n result = 2;\n } else {\n result = 1;\n }\n console.log(result);\n return result;\n}\n\nlet text = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\nprocess.stdin.on('data', t => {\n if (t === '\\r\\n' || t === '\\n') {\n process.stdin.emit('end');\n } else {\n text += t;\n }\n});\nprocess.stdin.on('end', () => {\n const input = text.trim().replace(/\\r/g, '').split('\\n');\n const dataArr = input[1].split(/\\s/).map(n => parseInt(n));\n solve(...dataArr);\n process.exit();\n});\n \t\t\t \t\t\t\t \t \t \t \t \t\t \t \t\t \t"}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const [a, b] = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(a, b)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(a, b) {\n if (a === 0 && b === 0) return 0\n const r = Math.sqrt(a * a + b * b)\n if (r * r === a * a + b * b) return 1\n return 2\n}\n"}, {"source_code": "var repeatTimes = readline();\r\n \r\nwhile(repeatTimes--) {\r\n var a = readline().split(' ').map(Number);\r\n var x = a[0];\r\n var y = a[1];\r\n if (x || y) \r\n print((Math.sqrt(x * x + y * y) === Math.sqrt(x * x + y * y) ? 1 : 2))\r\n else\r\n print(0)\r\n \r\n}"}], "src_uid": "fce6d690c2790951f7e04c622c3c2d44"} {"source_code": "var numberofTeams = Number(readline());\nvar strengths = [];\nvar strength;\nvar start = 2;\nwhile ((strength = readline())) {\n strength = strength.split(' ');\n for (var i = 0; i < strength.length; i++) {\n strengths.push({\n i: start,\n j: i + 1,\n strength: Number(strength[i])\n });\n }\n start += 1;\n}\n\nstrengths.sort(function(a, b) {\n return b.strength - a.strength;\n});\n\n\nvar teams = {};\nvar teamsCounter = 0;\nfor (var i = 0; i < strengths.length; i++) {\n if (!(strengths[i].i in teams) && !(strengths[i].j in teams)) {\n teams[strengths[i].i] = strengths[i].j;\n teams[strengths[i].j] = strengths[i].i;\n teamsCounter++;\n }\n if (teamsCounter === numberofTeams)\n break;\n}\n\nvar output = \"\";\nvar noMembers= numberofTeams * 2;\nfor (var i = 1; i <= noMembers; i++) {\n output = output + teams[i];\n if(output !== noMembers)\n output +=\" \";\n}\nprint(output);\n", "positive_code": [{"source_code": "function pair(i,j,r){\n this.i=i;\n this.j=j;\n this.r=r; \n}\nvar n=parseInt(readline());\nvar data=[];\nfor(var i=1;i<2*n;i++){\n var s0 = readline();\n var s=s0.split(\" \");\n var d=new Array(s.length);\n for(var j=0;j new Set(b).has(x));\n}\n\nfunction createAnswer() {\n var marshrut = ostn.splice(0,1)[0];\n ostn.forEach(arr => {\n marshrut = intersect(marshrut,arr);\n \n });\n console.log(marshrut.join(\" \"));\n}\nrl.on('line', function(line){ \n if (ost == -1) {\n ost = line;\n } else {\n step++;\n let temp = line.split(\" \");\n temp.splice(0,1);\n ostn[ostn.length] = temp;\n if (step >= ost) {\n createAnswer();\n process.exit();\n }\n } \n});", "positive_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var used = new Array(100001).fill(0);\n for(var i = 0; i < N; i++){\n var list = nextIntArray();\n var len = list[0];\n list.shift();\n var ng = new Set();\n for(var j = 0; j < list.length; j++){\n if(!ng.has(list[j])){\n used[list[j]]++;\n ng.add(list[j]);\n }\n }\n }\n var output = [];\n for(var i = 1; i <= 100000; i++){\n if(used[i] == N){\n output.push(i);\n }\n }\n myout(myconv(output, 8));\n}\n"}, {"source_code": "const readline = require('readline');\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false\n});\nlet c = 0;\nlet ans;\n\nconst getIntersection = (a, b) => {\n const set2 = new Set(b);\n return a.filter(x => set2.has(x));\n}\n\nrl.on('line', (d) => {\n if (c === 0) {\n c++;\n return;\n }\n\n if (c === 1) {\n c++;\n [y, ...ans] = d.split(' ');\n\n return;\n }\n\n let [_, ...curr] = d.split(' ');\n\n ans = getIntersection(ans, curr);\n\n c++;\n});\n\nrl.on('close', () => {\n console.log(ans.join(' '));\n});\n"}], "negative_code": [{"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n\tinput: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n\tobj = init(inLine);\n\tconsole.error('\\n\u2191\u5165\u529b \u2193\u51fa\u529b');\n\tMain();\n});\nfunction makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n\treturn {\n\t\tlist : input, index : 0, max : input.length,\n\t\thasNext : function(){return (this.index < this.max);},\n\t\tnext : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException \u201aThere is no more input';}}\n\t};\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var N = nextInt();\n var used = new Array(100001).fill(0);\n for(var i = 0; i < N; i++){\n var list = nextIntArray();\n var ng = new Set();\n for(var j = 0; j < list.length; j++){\n if(!ng.has(list[j])){\n used[list[j]]++;\n ng.add(list[j]);\n }\n }\n }\n var output = [];\n for(var i = 1; i <= 100000; i++){\n if(used[i] == N){\n output.push(i);\n }\n }\n myout(myconv(output, 8));\n}\n"}], "src_uid": "16c54cf7d8b484b5e22a7d391fdc5cd3"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = ''\nlet currentLine = 0\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin\n})\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n')\n\n main()\n})\n\nfunction readLine() {\n return inputString[currentLine++]\n}\n\nconst s2i = s => parseInt(s, 10)\n\nconst readLineOfBigInts = () => {\n const split = readLine().split(' ')\n const result = []\n for (let i = 0, l = split.length; i < l; i++) {\n result.push(BigInt(split[i]));\n }\n return result\n}\n\nconst cmpi = (a, b) => a - b\n\nfunction main() {\n let T = s2i(readLine())\n let out = ''\n\n while (T--) {\n const n = s2i(readLine())\n const w = readLine().split(' ').map(s2i)\n w.sort(cmpi)\n\n const ss = new Array(2*n + 1)\n for (let i = 0; i < n; i++) {\n for (let j = i+1; j < n; j++) {\n ss[w[i] + w[j]] = true\n }\n }\n\n let maxPairs = 0\n\n for (let s = 0; s <= 2*n; s++) {\n if (!ss[s]) continue\n let pairs = 0\n for (let izq = 0, der = n-1; izq < der;) {\n if (w[izq] + w[der] > s) der--\n else if (w[izq] + w[der] < s) izq++\n else {\n der--\n izq++\n pairs++\n }\n }\n\n if (maxPairs < pairs) maxPairs = pairs\n }\n\n out += maxPairs + '\\n'\n }\n\n console.log(out)\n}\n", "positive_code": [{"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n if(x[0] === i || x[1] === i || x[0] === j || x[1] === j) {\n notFound = true;\n }\n });\n\n if(!notFound) {\n hash[num].push([i, j]);\n }\n } else {\n hash[num] = [[i, j]];\n }\n }\n }\n }\n\n\n let sortedKey = Object.keys(hash).sort((a, b) => {\n return hash[b].length - hash[a].length;\n });\n\n console.log(hash[sortedKey[0]].length);\n\n}\n\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const sums = [...Array(100).fill(-1)];\n for (let i = 1; i < 101; i++) {\n sums[i] = countPair(i);\n }\n\n const max = Math.max(...sums);\n console.log(max);\n\n function countPair(sum) {\n const map = {};\n let count = 0;\n for (let i = 0; i < len; i++) {\n if (map[arr[i]] >= 1) {\n count++;\n map[arr[i]]--;\n } else {\n const sub = sum - arr[i];\n if (sub > 0) {\n if (map[sub] >= 1) map[sub]++;\n else map[sub] = 1;\n }\n }\n }\n return count;\n }\n }\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main(){\n let t = parseInt(readline());\n for(let k = 0; k < t; k++){\n let n = parseInt(readline());\n let arr = readline().split(' ');\n let map = {};\n let max = 0;\n for(let i = 0; i < arr.length; i++){\n for(let j = i+1; j < arr.length; j++){\n map[parseInt(arr[i]) + parseInt(arr[j])] = 1;\n }\n }\n\n for(let i = 0; i < arr.length; i++)\n arr[i] = parseInt(arr[i]);\n \n arr.sort((a,b) => a-b);\n for(let sum in map){\n sum = parseInt(sum);\n \n let p1 = 0;\n let p2 = arr.length-1;\n let count = 0;\n while(p1 < p2){\n if(arr[p1] + arr[p2] < sum){\n p1++;\n }else if(arr[p1] + arr[p2] > sum){\n p2--;\n }else{\n count += 1;\n p1++;\n p2--;\n }\n }\n \n max = Math.max(max, count);\n }\n\n console.log(max);\n }\n}"}, {"source_code": "//Don't have to see. start------------------------------------------\nvar read = require('readline').createInterface({\n input: process.stdin, output: process.stdout\n});\nvar obj; var inLine = [];\nread.on('line', function(input){inLine.push(input);});\nread.on('close', function(){\n obj = init(inLine);\n console.error(\"\\n\");\n var start = Date.now();\n Main();\n var end = Date.now() - start;\n myerr(\"time : \" + end + \"ms\");\n myerr(\"memory : \" + Math.round(process.memoryUsage().heapTotal / 1024) + \"KB\");\n});\nfunction makeClone(obj){return JSON.parse(JSON.stringify(obj));}\nfunction nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}\nfunction nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}\nfunction next(){return obj.next();} function hasNext(){return obj.hasNext();}\nfunction init(input){ \n return {\n list : input, index : 0, max : input.length,\n hasNext : function(){return (this.index < this.max);},\n next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw \"ArrayIndexOutOfBoundsException \u201aThere is no more input\";}}\n };\n}\nfunction myout(s){console.log(s);}\nfunction myerr(s){console.error(\"debug:\" + require(\"util\").inspect(s,false,null));}\n//param \"no\" is\n//unknown or outlier : return i. 1: parseInt.\n//2: split space. 4: split space and parseInt.\n//6: split 1 character. 7: split 1 character and parseInt.\n//8: join space. 9: join nextline. 0: join no character.\nfunction myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(\" \");case 4:return i.split(\" \").map(Number);case 6:return i.split(\"\");case 7:return i.split(\"\").map(Number);case 8:return i.join(\" \");case 9:return i.join(\"\\n\");case 0:return i.join(\"\");default:return i;}}catch(e){return i;}}\n\n//Don't have to see. end------------------------------------------\nfunction Main(){\n var t = nextInt();\n var output = new Array(t);\n for(var i = 0; i < t; i++){\n var N = nextInt();\n var list = nextIntArray();\n var maxSize = 0;\n var set = new Set();\n for(var j = 0; j < N - 1; j++){\n for(var k = j + 1; k < N; k++){\n var sum = list[j] + list[k];\n set.add(sum);\n }\n }\n var tmpList = Array.from(set);\n for(var j = 0; j < tmpList.length; j++){\n var tmp = makeClone(list);\n var count = 0;\n for(var l = 0; l < N - 1; l++){\n for(var m = l + 1; m < N; m++){\n if(tmp[l] + tmp[m] == tmpList[j]){\n count++;\n tmp[l] = -100000;\n tmp[m] = -100000;\n }\n }\n }\n maxSize = Math.max(maxSize, count);\n }\n \n output[i] = maxSize;\n }\n myout(myconv(output, 9));\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet weights = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tif (n === 1) {\n\t\t\tconsole.log(0);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet grid = [],\n\t\t\thash = {},\n\t\t\ts = 0,\n\t\t\tv = 0;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tgrid[i] = Array(n).fill('x');\n\t\t\tfor (let j = i + 1; j < n; j++) {\n\t\t\t\tlet w = weights[i] + weights[j];\n\t\t\t\tgrid[i][j] = w;\n\n\t\t\t\tif (hash[w] === undefined) {\n\t\t\t\t\thash[w] = {};\n\t\t\t\t\thash[w].cord = [];\n\t\t\t\t\thash[w].value = 0;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\thash[w].cord.indexOf(i) === -1 &&\n\t\t\t\t\thash[w].cord.indexOf(j) === -1\n\t\t\t\t) {\n\t\t\t\t\thash[w].cord = [...hash[w].cord, i, j];\n\t\t\t\t\thash[w].value += 1;\n\n\t\t\t\t\tif (hash[w].value > v) {\n\t\t\t\t\t\tv = hash[w].value;\n\t\t\t\t\t\ts = w;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(hash[s].cord.length / 2);\n\t}\n}\n"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = sortIntArr(readIntArray())\n\n if (arr.length <= 1) {\n print(0)\n return\n }\n\n var maxSum = arr[n-1] + arr[n-2]\n var maxAnswer = Math.floor(n/2)\n var answer = 0\n\n var diffArr = new Array(n)\n for(var i=maxSum; i >=0; i--) {\n for(var j=0; j a - b)\n}"}], "negative_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const store = {};\n for (let i = 0; i < len; i++) {\n for (let j = i + 1; j < len; j++) {\n const sum = arr[i] + arr[j];\n if (!store[sum]) store[sum] = 1;\n else store[sum]++;\n }\n }\n\n const max = Math.max(...Object.values(store));\n let avg;\n\n for (let key of Object.keys(store)) {\n if (store[key] === max) avg = key;\n }\n\n const map = {};\n let count = 0;\n for (let i = 0; i < len; i++) {\n if (map[arr[i]]) {\n count++;\n delete map[arr[i]];\n } else {\n const sub = avg - arr[i];\n if (sub > 0) map[sub] = true;\n }\n }\n console.log(count);\n }\n}\n"}, {"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\nfunction main() {\n let t = +readLine();\n while (t--) {\n let len = +readLine();\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n\n const sums = [...Array(100).fill(-1)];\n for (let i = 1; i < 101; i++) {\n sums[i] = countPair(i);\n }\n\n const max = Math.max(...sums);\n console.log(max);\n\n function countPair(avg) {\n const map = {};\n let count = 0;\n for (let i = 0; i < len; i++) {\n if (map[arr[i]]) {\n count++;\n delete map[arr[i]];\n } else {\n const sub = avg - arr[i];\n if (sub > 0) map[sub] = true;\n }\n }\n return count;\n }\n }\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet weights = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet grid = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tgrid[i] = Array(n).fill('x');\n\t\t\tfor (let j = i + 1; j < n; j++) {\n\t\t\t\tgrid[i][j] = weights[i] + weights[j];\n\t\t\t}\n\t\t}\n\n\t\tlet flat = grid.flat().filter(x => x !== 'x');\n\t\tlet hash = {};\n\t\tflat.forEach(x => (hash[x] = (hash[x] || 0) + 1));\n\t\tlet s = 0,\n\t\t\tm = 0;\n\t\tObject.entries(hash).forEach(([k, v]) => {\n\t\t\tif (v >= m) {\n\t\t\t\ts = k;\n\t\t\t\tm = v;\n\t\t\t}\n\t\t});\n\n\t\tlet team = 0;\n\t\tlet taken = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tfor (let j = i + 1; j < n; j++) {\n\t\t\t\tif (\n\t\t\t\t\tgrid[i][j] === +s &&\n\t\t\t\t\ttaken.indexOf(i) === -1 &&\n\t\t\t\t\ttaken.indexOf(j) === -1\n\t\t\t\t) {\n\t\t\t\t\ttaken.push(i, j);\n\t\t\t\t\tteam++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(team);\n\t}\n}\n"}, {"source_code": "let inputString = '';\nlet currentLine = 0;\nprocess.stdin.on('data', data => {\n\tinputString += data;\n});\nprocess.stdin.on('end', function () {\n\tinputString = inputString\n\t\t.trim()\n\t\t.split('\\n')\n\t\t.map(str => str.trim());\n\tmain();\n});\n\nfunction readLine() {\n\treturn inputString[currentLine++];\n}\n\nfunction main() {\n\tlet t = readLine() >> 0;\n\twhile (t--) {\n\t\tlet n = readLine() >> 0;\n\t\tlet weights = readLine()\n\t\t\t.split(' ')\n\t\t\t.map(x => x >> 0);\n\n\t\tlet grid = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tgrid[i] = Array(n).fill('x');\n\t\t\tfor (let j = i + 1; j < n; j++) {\n\t\t\t\tgrid[i][j] = weights[i] + weights[j];\n\t\t\t}\n\t\t}\n\n\t\tlet arr = grid.flat().filter(x => x !== 'x');\n\t\tlet s = 0,\n\t\t\tv = 0,\n\t\t\th = {};\n\t\tarr.forEach(x => {\n\t\t\th[x] = (h[x] || 0) + 1;\n\t\t\tif (h[x] > v) {\n\t\t\t\tv = h[x];\n\t\t\t\ts = x;\n\t\t\t}\n\t\t});\n\n\t\tlet l = 0,\n\t\t\tc = 0,\n\t\t\tr = n - 1;\n\t\twhile (l < r) {\n\t\t\tlet tw = weights[l] + weights[r];\n\t\t\tif (tw > s) {\n\t\t\t\tr--;\n\t\t\t} else if (tw < s) {\n\t\t\t\tl++;\n\t\t\t} else {\n\t\t\t\tr--;\n\t\t\t\tl++;\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(c);\n\t}\n}\n"}, {"source_code": "'use strict';\n \nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n \nlet inputString = '';\nlet currentLine = 0;\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n \nfunction readline() {\n return inputString[currentLine++];\n}\n/**\n5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n**/\n\nfunction gcd(a, b) {\n if (!b) {\n return a;\n }\n\n return gcd(b, a % b);\n};\n\nfunction lcm(a, b) {\n return (a / gcd(a, b) * b);\n}\n\nfunction main() { \n let n = Number(readline());\n\n for(let r=0;r {\n if(x[0] === i || x[1] === i || x[0] === j || x[1] === j) {\n notFound = true;\n }\n });\n\n if(!notFound) {\n hash[num].push([i, j]);\n }\n } else {\n hash[num] = [[i, j]];\n }\n }\n }\n }\n\n\n let sortedKey = Object.keys(hash).sort((a, b) => {\n return hash[b].length - hash[a].length;\n });\n\n console.log(hash[sortedKey[0]].length);\n\n}\n\n"}, {"source_code": "function solve() {\n var n = readInt()\n var arr = readIntArray()\n\n if (arr.length <= 1) {\n print(0)\n return\n }\n\n var maxSum = arr[n-1] + arr[n-2]\n var maxAnswer = Math.floor(n/2)\n var answer = 0\n\n var diffArr = new Array(n)\n for(var i=maxSum; i >=0; i--) {\n for(var j=0; j a - b)\n}"}], "src_uid": "0048623eeb27c6f7c6900d8b6e620f19"} {"source_code": "(function main() {\n var v = readline().split(' ');\n var n = parseInt(v[0]);\n var k = parseInt(v[1]);\n var l = parseInt(v[2]);\n var r = parseInt(v[3]); \n var sall = parseInt(v[4]);\n var sk = parseInt(v[5]); \n var a = new Array(n);\n var d = ~~(sk / k);\n var o = sk % k;\n var i = 0;\n for ( ; i < o; ++i) a[i] = d + 1;\n for ( ; i < k; ++i) a[i] = d;\n sall -= sk + (n - k) * l;\n for ( ; i < k + ~~(sall / (d - l)); ++i) a[i] = d;\n if(sall % (d - l))\n a[i++] = sall % (d - l) + l;\n for ( ; i < n; ++i) a[i] = l;\n print(a.join(' '));\n})();", "positive_code": [{"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\nfunction readNums() {\n return readline().split(' ').map(Number);\n}\n\nprint(function(n, k, l, r, sa, sk) {\n var i = 0,\n ans = [],\n a = Math.floor(sk / k),\n b = sk % k,\n c = Math.floor((sa - sk) / (n - k)),\n d = k + (sa - sk) % (n - k);\n\n while (i < b)\n i++, ans.push(a + 1);\n while (i < k)\n i++, ans.push(a);\n while (i < d)\n i++, ans.push(c + 1);\n while (i < n)\n i++, ans.push(c);\n return ans.join(' ');\n\n}.apply(0, readNums()));"}, {"source_code": "if (!this.readline) print = console.log, readline = require('./readline');\n\nfunction readNums() {\n return readline().split(' ').map(Number);\n}\n\nprint(function(n, k, l, r, sa, sk) {\n var ans = [];\n var a = ~~ (sk / k);\n var b = sk % k;\n for (var i = 0; i < b; i++)\n ans.push(a + 1);\n for (; i < k; i++)\n ans.push(a);\n\n a = ~~ ((sa - sk) / (n - k));\n b = k + (sa - sk) % (n - k);\n for (; i < b; i++)\n ans.push(a + 1);\n for (; i < n; i++)\n ans.push(a);\n return ans.join(' ');\n\n}.apply(0, readNums()));"}, {"source_code": "function trim(s) {\n\treturn s.replace(/^\\s+|\\s+$/gm, '');\n}\n\nfunction tokenize(s) {\n\treturn trim(s).split(/\\s+/);\n}\n\nfunction tokenizeIntegers(s) {\n\tvar tokens = tokenize(s);\n\tfor (var i = 0; i < tokens.length; i += 1) {\n\t\ttokens[i] = parseInt(tokens[i]);\n\t};\n\treturn tokens;\n}\n\nfunction splitScores(total, count) {\n\tvar low = Math.floor(total/count), high = low+1;\n\tvar highCount = total - count*low;\n\tvar arr = [];\n\tfor (var i = 0; i < count; i += 1) {\n\t\tarr.push(i < highCount ? high : low);\n\t}\n\treturn arr;\n}\n\nfunction main() {\n\tvar integers = tokenizeIntegers(readline());\n\tvar numScores = integers[0], numTopScores = integers[1],\n\t\tminScore = integers[2], maxScore = integers[3],\n\t\tallTotal = integers[4], topTotal = integers[5];\n\t\n\tvar topScores = splitScores(topTotal, numTopScores);\n\tvar restScores = splitScores(allTotal - topTotal, numScores - numTopScores);\n\n\tprint(topScores.join(' '), restScores.join(' '));\n}\n\nmain();\n"}], "negative_code": [{"source_code": "(function main() {\n var v = readline().split(' ');\n var n = parseInt(v[0]);\n var k = parseInt(v[1]);\n var l = parseInt(v[2]);\n var r = parseInt(v[3]); \n var sall = parseInt(v[4]);\n var sk = parseInt(v[5]); \n var a = new Array(n);\n var d = sk / k;\n var o = sk % k;\n var i = 0;\n for ( ; i < o; ++i) a[i] = d + 1;\n for ( ; i < k; ++i) a[i] = d;\n sall -= sk + (n - k) * l;\n for ( ; i < k + sall / (d - l); ++i) a[i] = d;\n if(sall % (d - l))\n a[i++] = sall % (d - l) + l;\n for ( ; i < n; ++i) a[i] = l;\n print(a.join(' '));\n})();"}], "src_uid": "59154ca15716f0c1c91a37d34c5bbf1d"} {"source_code": "var t = parseInt(readline(), 10);\n\nfor(var i=1; i<=t; i++) {\n var s = readline().split('');\n var d = 0, l = 0, r = 0, u = 0, final_s = ''; \n \n s.sort();\n \n for(var j=0; j u) d = u;\n else u = d;\n \n if(l > r) l = r;\n else r = l;\n \n if(d === 0 && l > 0) {\n l = 1;\n r = 1;\n \n } else if(l === 0 && d > 1) {\n d = 1;\n u = 1;\n \n }\n \n for(j = 1; j<=d; j++) {\n final_s += 'D';\n }\n \n for(j = 1; j<=r; j++) {\n final_s += 'R';\n }\n \n for(j = 1; j<=u; j++) {\n final_s += 'U';\n }\n \n for(j = 1; j<=l; j++) {\n final_s += 'L';\n }\n \n print(final_s.length);\n print(final_s);\n}", "positive_code": [{"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n const counts = data.reduce((acc, value) => {\n acc[value] = ++acc[value];\n return acc;\n }, { L: 0, R: 0, U: 0, D: 0 })\n\n const lrP = Math.min(counts.L, counts.R);\n const udP = Math.min(counts.U, counts.D);\n if (!lrP && !udP) return [0, ''];\n if (!lrP) return [2, 'UD'];\n if (!udP) return [2, 'LR'];\n\n return [(lrP + udP) * 2, (new Array(lrP).fill('L').join('')) + (new Array(udP).fill('U').join('')) + (new Array(lrP).fill('R').join('')) + (new Array(udP).fill('D').join('')) ]\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\"\");\n\n let result = foo(data);\n answer += result[0] +\"\\n\";\n answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "let finalInput = '';\n\nprocess.stdin.setEncoding('utf-8').on('data', input => {\n finalInput += input;\n});\n\nprocess.stdin.setEncoding('utf-8').on('end', () => {\n const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);\n finalInput.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const commands = line.split('');\n let L = commands.filter(c => c === 'L').length;\n let R = commands.filter(c => c === 'R').length;\n let U = commands.filter(c => c === 'U').length;\n let D = commands.filter(c => c === 'D').length;\n\n L = R = Math.min(L, R);\n U = D = Math.min(U, D);\n\n if (L === 0 && U > 1) {\n U = D = 1;\n }\n if (U === 0 && L > 1) {\n L = R = 1;\n }\n\n let output = new Array(L).fill('L')\n .concat(new Array(U).fill('U'))\n .concat(new Array(R).fill('R'))\n .concat(new Array(D).fill('D'));\n\n console.log(output.length);\n if (output.length > 0) {\n console.log(output.join(''));\n }\n });\n});"}, {"source_code": "let fs = require(\"fs\");\n\nlet txt = fs.readFileSync(0, \"utf-8\").split(\"\\r\\n\").filter(data => {\n return data.length > 0;\n});\n\ntxt.shift();\n\nfor (let i = 0; i < txt.length; i++) {\n doit(txt[i].split(\"\").filter(data => {\n return data.length > 0;\n }));\n\n}\n\nfunction doit(tab) {\n let moves = {\n L: 0,\n U: 0,\n R: 0,\n D: 0\n };\n tab.forEach(data => {\n ++moves[data];\n });\n let hor = Math.min(moves.L, moves.R);\n let ver = Math.min(moves.U, moves.D);\n if (hor + ver === 0) {\n console.log(0);\n console.log();\n } else if (hor === 0) {\n console.log(2);\n console.log(\"UD\");\n } else if (ver === 0) {\n console.log(2);\n console.log(\"LR\");\n } else {\n moves.U = moves.D = ver;\n moves.L = moves.R = hor;\n let seq = \"\";\n for (const key in moves) {\n for (let i = 0; i < moves[key]; i++) {\n seq += key;\n }\n }\n console.log(seq.length);\n console.log(seq);\n }\n}"}, {"source_code": "'use strict'\n\nconst problem = (s) => {\n const r = { L: 0, R: 0, D: 0, U: 0 };\n for (let i = 0; i < s.length; i++) r[s[i]]++;\n const w = Math.min(r.L, r.R);\n const h = Math.min(r.U, r.D);\n if (!w && !h) return [ 0, '' ];\n if (!h) return [ 2, 'LR' ];\n if (!w) return [ 2, 'UD' ];\n\n return [ 2*(w+h), 'L'.repeat(w) + 'U'.repeat(h) + 'R'.repeat(w) + 'D'.repeat(h) ];\n}\nlet q = +readline();\n\nwhile(q--) print(problem(readline()).join('\\n'));\n"}, {"source_code": "function myin(){return require(\"fs\").readFileSync(\"/dev/stdin\", \"utf8\").trim();}\nfunction myout(t){print(t);}//standard output\n//function myout(t){console.log(t);}//standard output\nfunction myerr(t){console.err(t);}//standard error\n//[no]param\n//0:\u4f55\u3082\u3057\u306a\u3044 1:\u6570\u5024\u3078\u5909\u63db 2:\u534a\u89d2SP\u3067\u5206\u5272 3:\u6539\u884c\u3067\u5206\u5272 4:\u534a\u89d2SP\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\n//5:\u6539\u884c\u3067\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078 6:1\u6587\u5b57\u306b\u5206\u5272 7:1\u6587\u5b57\u306b\u5206\u5272\u3057\u3001\u6570\u5024\u914d\u5217\u3078\nfunction myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(\" \");case 3:return i.split(\"\\n\");case 4:return i.split(\" \").map((a)=>Number(a));case 5:return i.split(\"\\n\").map((a)=>Number(a));case 6:return i.split(\"\");case 7:return i.split(\"\").map((a)=>Number(a));}}\n \nfunction Main(input) {\n //input = myconv(input,3);\n var N = myconv(readline(),1);\n //input.shift();\n var output = [];\n for(var i = 0; i < N; i++){\n var s = myconv(readline(),6);\n var L = 0;\n var R = 0;\n var U = 0;\n var D = 0;\n for(var j = 0; j < s.length; j++){\n switch(s[j]){\n case \"L\":\n L++;\n break;\n case \"R\":\n R++;\n break;\n case \"U\":\n U++;\n break;\n case \"D\":\n D++;\n break;\n }\n }\n if(L > 0 && R > 0 && U > 0 && D > 0){\n var LRmin = Math.min(L,R);\n var UDmin = Math.min(U,D);\n output.push(LRmin * 2 + UDmin * 2);\n var add = \"\";\n for(var j = 0; j < UDmin; j++){add += \"D\";}\n for(var j = 0; j < LRmin; j++){add += \"L\";}\n for(var j = 0; j < UDmin; j++){add += \"U\";}\n for(var j = 0; j < LRmin; j++){add += \"R\";}\n output.push(add);\n }else if(L > 0 && R > 0){\n output.push(2);\n output.push(\"LR\");\n }else if(U > 0 && D > 0){\n\t\toutput.push(2);\n output.push(\"UD\");\n }else{\n output.push(0);\n }\n }\n myout(output.join(\"\\n\"));\n}\n \nMain();"}, {"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const str = arr[j]\n const len = str.length\n\n let l, r, u, d\n l = r = u = d = 0\n\n for(let i = 0; i < len; i++) {\n let a = str[i]\n if(a == 'L') l ++\n else if(a == 'R') r++\n else if(a == 'U') u++\n else d++\n \n }\n // console.log(2 * l + 2 * u)\n\n if(l != r) l = r = Math.min(l, r)\n if(u != d) u = d = Math.min(u, d)\n if(l == 0 && u >= 1) {\n console.log(2)\n console.log('UD')\n continue\n }\n else if(u == 0 && l >= 1) {\n console.log(2)\n console.log('LR')\n continue\n }\n else if(u == 0 && l == 0){\n console.log(0)\n continue\n }\n\n // console.log(2 * l + 2 * u)\n\n let s = new Array(2 * l + 2 * u)\n\n for(let i = 0; i < l; i++) {\n s[i] = 'L'\n }\n\n for(let i = 0; i < u; i++) {\n s[i + l] = 'U'\n }\n\n for(let i = 0; i < r; i++) {\n s[i + l + u] = 'R'\n }\n\n for(let i = 0; i < d; i++) {\n s[i + l + r + u] = 'D'\n }\n console.log(2 * l + 2 * u)\n console.log(s.join(''))\n }\n})"}], "negative_code": [{"source_code": "process.stdin.resume()\nprocess.stdin.setEncoding('utf-8')\n\nvar arr = ''\nprocess.stdin.on('data', (i) => {\n arr += i\n})\n\n\nprocess.stdin.on('end', () => {\n arr = arr.split('\\n').map(a => a.replace(/(\\r\\n|\\n|\\r)/gm, ''))\n\n const t = parseInt(arr.shift())\n\n for(let j = 0; j < t; j++) {\n const str = arr[j]\n const len = str.length\n\n let l, r, u, d\n l = r = u = d = 0\n\n for(let i = 0; i < len; i++) {\n let a = str[i]\n if(a == 'L') l ++\n else if(a == 'R') r++\n else if(a == 'U') u++\n else d++\n \n }\n // console.log(2 * l + 2 * u)\n\n if(l != r) l = r = Math.min(l, r)\n if(u != d) u = d = Math.min(u, d)\n if(l == 0 && u >= 1) {\n console.log(2)\n console.log('UD')\n continue\n }\n else if(u == 0 && l >= 1) {\n console.log(2)\n console.log('LR')\n continue\n }\n else if(u == 0 && l == 0){\n console.log(0)\n continue\n }\n\n // console.log(2 * l + 2 * u)\n\n let s = new Array(2 * l + 2 * u)\n\n for(let i = 0; i < l; i++) {\n s[i] = 'L'\n }\n\n for(let i = 0; i < u; i++) {\n s[i + l] = 'U'\n }\n\n for(let i = 0; i < r; i++) {\n s[i + l + u] = 'R'\n }\n\n for(let i = 0; i < d; i++) {\n s[i + l + u + d] = 'D'\n }\n console.log(2 * l + 2 * u)\n console.log(s.join(''))\n }\n})"}, {"source_code": "let i = ''\nprocess.stdin.on('data', c => i += c)\nprocess.stdin.on('end', () => {\n const {EOL} = require('os')\n const lines = i.split(EOL);\n\n\n\n\n\n function foo (data) {\n const counts = data.reduce((acc, value) => {\n acc[value] = ++acc[value];\n return acc;\n }, { L: 0, R: 0, U: 0, D: 0 })\n\n const lrP = Math.min(counts.L, counts.R);\n const udP = Math.min(counts.U, counts.D);\n if (!lrP && !udP) return [0, ''];\n if (!lrP) return [2, 'UD'];\n if (!udP) return [2, 'LR'];\n\n return [(lrP + udP) * 2, (new Array(lrP).fill('L').join('')) + (new Array(udP).fill('U').join('')) + (new Array(udP).fill('D').join('')) + (new Array(lrP).fill('R').join('')) ]\n }\n\n let testCount = 1;\n let answer = '';\n while(testCount <= +lines[0]) {\n let data = lines[testCount].split(\"\");\n\n let result = foo(data);\n answer += result[0] +\"\\n\";\n answer += result[1] +\"\\n\";\n testCount++;\n }\n console.log(answer);\n})"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const commands = line.split('');\n let L = commands.filter(c => c === 'L').length;\n let R = commands.filter(c => c === 'R').length;\n let U = commands.filter(c => c === 'U').length;\n let D = commands.filter(c => c === 'D').length;\n\n let max = commands.length - Math.abs(L - R) - Math.abs(U - D);\n\n L = R = Math.min(L, R);\n U = D = Math.min(U, D);\n\n let output = new Array(L).fill('L')\n .concat(new Array(U).fill('U'))\n .concat(new Array(R).fill('R'))\n .concat(new Array(D).fill('D'));\n\n console.log(max);\n console.log(output.join(''));\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const commands = line.split('');\n let L = commands.filter(c => c === 'L').length;\n let R = commands.filter(c => c === 'R').length;\n let U = commands.filter(c => c === 'U').length;\n let D = commands.filter(c => c === 'D').length;\n\n L = R = Math.min(L, R);\n U = D = Math.min(U, D);\n\n if (L === 0 && U > 1) {\n U = D = 1;\n }\n if (U === 0 && L > 1) {\n L = R = 1;\n }\n\n let output = new Array(L).fill('L')\n .concat(new Array(U).fill('U'))\n .concat(new Array(R).fill('R'))\n .concat(new Array(D).fill('D'));\n\n console.log(output.length);\n if (output.length > 0) {\n console.log(output.join(''));\n }\n });\n});"}, {"source_code": "process.stdin.setEncoding('utf-8').on('data', input => {\n const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);\n input.split('\\r\\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)\n .forEach(line => {\n const commands = line.split('');\n let L = commands.filter(c => c === 'L').length;\n let R = commands.filter(c => c === 'R').length;\n let U = commands.filter(c => c === 'U').length;\n let D = commands.filter(c => c === 'D').length;\n\n L = R = Math.min(L, R);\n U = D = Math.min(U, D);\n\n if (L === 0 && U > 1) {\n U = D = 1;\n }\n if (U === 0 && L > 1) {\n L = R = 1;\n }\n\n let output = new Array(L).fill('L')\n .concat(new Array(U).fill('U'))\n .concat(new Array(R).fill('R'))\n .concat(new Array(D).fill('D'));\n\n console.log(output.length);\n console.log(output.join(''));\n });\n});"}], "src_uid": "1fba9a290d0492a3d658a7a33388db13"} {"source_code": "print(function(n, k) {\n\n\tvar a = ('0 ' + readline()).split(' ').map(Number);\n\n\tfor (var i = n - 1; i >= 1; i--)\n\t\tif (a[i] !== a[i + 1])\n\t\t\treturn i >= k ? -1 : i;\n\n\treturn 0;\n\n}.apply(0, readline().split(' ').map(Number)));\n", "positive_code": [{"source_code": "let inputString = \"\";\nlet currentLine = 0;\nprocess.stdin.on(\"data\", (data) => {\n inputString += data;\n});\nprocess.stdin.on(\"end\", function () {\n inputString = inputString\n .trim()\n .split(\"\\n\")\n .map((str) => str.trim());\n main();\n});\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n// utils\nconst MOD = 1e9 + 7;\nconst mod = (n) => ((n % MOD) + MOD) % MOD;\nconst add = (a, b) => mod(mod(a) + mod(b));\nconst sub = (a, b) => mod(mod(a) - mod(b));\nfunction mul() {\n for (var a = arguments, r = a[0], i = a.length; --i; )\n r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;\n return r;\n}\nfunction inv(b) {\n for (var a = MOD, u = 0, v = 1, t; b; v = t)\n (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);\n u %= MOD;\n return u < 0 ? u + MOD : u;\n}\nfunction pow(base, n) {\n if (n === 0) return 1;\n let p = pow(base, Math.floor(n / 2));\n let res = mul(mod(p), mod(p));\n if (n % 2 === 1) res = mul(mod(res), base);\n return res;\n}\nfunction highestOneBit(i) {\n i |= i >> 1;\n i |= i >> 2;\n i |= i >> 4;\n i |= i >> 8;\n i |= i >> 16;\n return i - (i >>> 1);\n}\nfunction permutation(arr, len, store = \"\", permutations = []) {\n if (store.length === len) {\n permutations.push(store);\n return;\n }\n for (let i = 0; i < arr.length; i++) {\n const newArr = [...arr];\n const newChar = newArr.splice(i, 1);\n permutation(newArr, len, store.concat(newChar), permutations);\n }\n return permutations;\n}\n\nfunction main() {\n const [len, k] = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n const arr = readLine()\n .split(\" \")\n .map((n) => parseInt(n));\n let [ok, count] = [true, 0];\n const target = arr[k - 1];\n\n for (let i = k; i < len; i++) {\n if (arr[i] !== target) {\n ok = false;\n break;\n }\n }\n\n let same = true;\n for (let i = k - 2; i >= 0; i--) {\n if (arr[i] === target && same) continue;\n else {\n same = false;\n count++;\n }\n }\n\n if (!ok) console.log(-1);\n else {\n console.log(count);\n }\n}\n"}, {"source_code": "print(function(n, k) {\n\n\tvar a = readline().split(' ').map(Number);\n\tvar x = 0;\n\tfor (var i = n - 2; i >= 0; i--)\n\t\tif (a[i] !== a[i + 1]) {\n\t\t\tx = i + 1;\n\t\t\tbreak;\n\t\t}\n\n\treturn x >= k ? -1 : x;\n\n}.apply(0, readline().split(' ').map(Number)));"}, {"source_code": ";(function () {\n\n\tvar n = readline().split(' '), k = +n[1];\n\tn = +n[0];\n\n\tvar a = readline().split(' ').map(Number), y = a[k - 1];\n\n\tprint((function () {\n\t\tif (a.slice(k - 1).filter(function (e, i, _a) { return e !== y; }).length) return -1;\n\t\tfor (var i = k - 2; i >= 0; i--) if (a[i] !== y) return i + 1;\n\t\treturn 0;\n\t})());\n\n}).call(this)"}], "negative_code": [{"source_code": "print(function(n, k) {\n\n\tvar a = readline().split(' ').map(Number);\n\tvar x = 0;\n\tfor (var i = n - 2; i >= 0; i--)\n\t\tif (a[i] !== a[i + 1]) {\n\t\t\tx = i + 1;\n\t\t\tbreak;\n\t\t}\n\n\treturn x > k ? -1 : x;\n\n}.apply(0, readline().split(' ').map(Number)));\n"}], "src_uid": "bcee233ddb1509a14f2bd9fd5ec58798"} {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var aliceOnly = [], bobOnly = [], both = []\n var n, k;\n [n, k] = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i parseInt(x));\n if (b === 1 && c === 1) {\n both.push(a);\n }\n else if (c === 1) {\n bobOnly.push(a);\n }\n else if (b === 1) {\n aliceOnly.push(a);\n }\n }\n aliceOnly.sort(function(a, b){return a-b}); \n bobOnly.sort(function(a, b){return a-b}); \n both.sort(function(a, b){return a-b});\n\n const cum = (a => b => a+=b);\n const aCum = aliceOnly.map(cum(0)), bCum = bobOnly.map(cum(0)), cCum = both.map(cum(0));\n var time = 1000000000000000;\n for (var i=0; i<=k; i++) {\n // i: number of books both read\n var sum = 0;\n if (i <= cCum.length && k-i <= aCum.length && k-i <= bCum.length) {\n if (i >= 1) { sum += cCum[i-1]; }\n if (k-i >= 1) { sum += aCum[k-i-1] + bCum[k-i-1]; }\n time = Math.min(time, sum); \n }\n }\n if (time === 1000000000000000) { console.log(-1); }\n else { console.log(time); }\n}", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n E1();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction C(){\n let [n,m] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n let b = ti(readline().split(' '));\n let o = new Array(10);\n let z = new Array(10);\n o.fill(0);\n z.fill(0);\n for(let i = 0; i < m; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(b[i] & t !== 0)\n o[j] = 1;\n else\n z[j] = 1;\n\n t << 1;\n }\n }\n\n let c = new Array(10);\n for(let i = 0; i < n; i++){\n let t = 1;\n for(let j = 0; j < 10; j++){\n if(a[i] & t !== 0){\n if(z[j] === 1)\n c[j] = 0;\n else\n c[j] = 1;\n }\n t << 1;\n }\n }\n\n let res = 0;\n for(let i = 9; i >= 0; i--){\n res += pi(c[i])*Math.pow(2,9-i);\n }\n console.log(res);\n}\n\nfunction B(){\n let t = pi(readline());\n while(t){\n t--;\n let [n,k,z] = ti(readline().split(' '));\n let a = ti(readline().split(' '));\n\n // pre -> 0,1 -> right,left\n let dp = new Array(z+1);\n for(let i = 0; i < z+1; i++){\n dp[i] = new Array(n);\n dp[i].fill(-1);\n }\n \n let solve = (i,j,index,pre) => {\n if(index < 0 || index >= n)\n return 0;\n if(i > k)\n return 0;\n if(dp[j][index] !== -1)\n return dp[j][index];\n if(pre){\n return dp[j][index] = a[index] + solve(i+1, j, index+1, 0);\n }else{\n return dp[j][index] = a[index] + Math.max(j < z ? solve(i+1,j+1,index-1,1) : 0, solve(i+1,j,index+1,0));\n }\n }\n\n console.log(solve(0,0,0,1));\n }\n}\n\nfunction E1(){\n let [n,k] = ti(readline().split(' '));\n let t = new Array(n);\n for(let i = 0; i < n; i++){\n t[i] = ti(readline().split(' '));\n }\n let ab = [];\n let a = [];\n let b = [];\n let unlikeCount = 0;\n\n for(let i = 0; i < n; i++){\n if(t[i][1] === 1 && t[i][2] === 1){\n ab.push(t[i]);\n }else if(t[i][1] === 1){\n a.push(t[i]);\n }else if(t[i][2] === 1){\n b.push(t[i]);\n }else{\n unlikeCount += 1;\n }\n }\n\n ab.sort((x,y) => x[0]-y[0]);\n a.sort((x,y) => x[0]-y[0]);\n b.sort((x,y) => x[0]-y[0]);\n // let max = Math.max(max, ab.length, a.length, b.length);\n // let min = Math.min(min, ab.length, a.length, b.length);\n // let inf = 9999999999;\n // for(let i = min+1; i <= max; i++){\n // if(i >= ab.length) ab.push(inf);\n // if(i >= a.length) a.push(inf);\n // if(i >= b.length) b.push(inf);\n // }\n\n let p1 = p2 = p3 = 0;\n let ka = k;\n let kb = k;\n let res = 0;\n while(p1 < ab.length || p2 < a.length || p3 < b.length){\n if(ka === 0 && kb === 0)\n break;\n if(p2 < a.length && p3 < b.length){\n if(p1 < ab.length){\n if(a[p2][0]+b[p3][0] > ab[p1][0]){\n res += ab[p1][0];\n p1++;\n }else{\n res += a[p2][0]+b[p3][0];\n p2++;\n p3++;\n }\n }else{\n res += a[p2][0]+b[p3][0];\n p2++;\n p3++;\n }\n ka--;\n kb--;\n }else{\n if(p1 >= ab.length){\n console.log(-1);\n return;\n }\n res += ab[p1][0];\n ka--;\n kb--;\n p1++;\n }\n }\n if(ka !== 0 || kb !== 0){\n console.log(-1);\n return;\n }\n console.log(res);\n}"}, {"source_code": "function sortFunc(x, y) {\n return x - y;\n}\n\nfunction solve() {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var tboth = [];\n var ta = [];\n var tb = [];\n var ca = 0;\n var cb = 0;\n \n for (var i = 0; i < n; i++) {\n var tab = read().split(' ').map(Number);\n var cCase = tab[2] * 2 + tab[1];\n if (cCase === 1) {\n ca++;\n ta.push(tab[0]);\n }\n if (cCase === 2) {\n cb++;\n tb.push(tab[0]);\n }\n if (cCase === 3) {\n ca++;\n cb++;\n tboth.push(tab[0]);\n } \n }\n ta.sort(sortFunc);\n tb.sort(sortFunc);\n tboth.sort(sortFunc);\n if (ca < k || cb < k) {\n write(-1);\n return;\n }\n var ans = 0;\n var ia = 0;\n var na = ta.length;\n var ib = 0;\n var nb = tb.length;\n var iboth = 0;\n var nboth = tboth.length;\n for (var i = 0; i < k; i++) {\n if (ia >= na || ib >= nb) {\n ans += tboth[iboth++];\n continue;\n }\n if (iboth >= nboth) {\n ans += ta[ia++] + tb[ib++];\n continue;\n }\n if (ta[ia] + tb[ib] < tboth[iboth]) {\n ans += ta[ia++] + tb[ib++];\n } else {\n ans += tboth[iboth++];\n }\n }\n write(ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}], "negative_code": [{"source_code": "function sortFunc(x, y) {\n var likeBothX = x[1] && x[2];\n var likeBothY = y[1] && y[2];\n if (likeBothX) {\n if (likeBothY) {\n return x[0] - y[0];\n }\n return -1;\n }\n if (likeBothY) {\n return 1;\n }\n return x[0] - y[0];\n}\n\nfunction solve() {\n var nk = read().split(' ').map(Number);\n var n = nk[0];\n var k = nk[1];\n var ca = 0;\n var cb = 0;\n var arr = [];\n for (var i = 0; i < n; i++) {\n var tab = read().split(' ').map(Number);\n if (!tab[1] && !tab[2]) {\n continue;\n }\n arr.push(tab);\n ca += tab[1];\n cb += tab[2];\n }\n if (ca < k || cb < k) {\n write(-1);\n return;\n }\n n = arr.length;\n arr.sort(sortFunc);\n var ans = 0;\n ca = k;\n cb = k;\n for (var i = 0; i < n; i++) {\n if (arr[i][1]) {\n if (arr[i][2]) {\n ca--;\n cb--;\n if (ca >=0 || cb >= 0) {\n ans += arr[i][0];\n }\n } else {\n ca--;\n if (ca >= 0) {\n ans += arr[i][0];\n }\n }\n } else {\n if (arr[i][2]) {\n cb--;\n if (cb >= 0) {\n ans += arr[i][0];\n }\n }\n }\n }\n write(ans);\n}\n\nfunction init() {\n var T;\n T = 1;\n //T = Number(read());\n for (var t = 0; t < T; t++) {\n solve();\n }\n}\n\n\nvar isNode = typeof console !== 'undefined';\nvar MEMORY = [];\nvar MEMORY_INDEX = 0;\nif (isNode) {\n var fs = require('fs');\n var path = require('path');\n \n var inTextName;\n var outTextName;\n if (process.argv.length === 5) {\n inTextName = process.argv[3];\n outTextName = process.argv[4];\n }\n \n if (inTextName) {\n fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {\n MEMORY = data.split('\\r\\n');\n init();\n });\n } else {\n var RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n });\n \n RL.on('line', (line) => {\n MEMORY.push(line);\n });\n \n RL.on('close', init);\n }\n} else {\n init();\n}\n \nfunction write(value) {\n isNode ? console.log(value) : print(value);\n}\nfunction read() {\n return isNode ? MEMORY[MEMORY_INDEX++] : readline();\n}\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var aliceOnly = [], bobOnly = [], both = []\n var n, k;\n [n, k] = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i parseInt(x));\n if (b === 1 && c === 1) {\n both.push(a);\n }\n else if (c === 1) {\n bobOnly.push(a);\n }\n else if (b === 1) {\n aliceOnly.push(a);\n }\n }\n aliceOnly.sort(); bobOnly.sort(); both.sort();\n const cum = (a => b => a+=b);\n const aCum = aliceOnly.map(cum(0)), bCum = bobOnly.map(cum(0)), cCum = both.map(cum(0));\n console.log(aCum, bCum, cCum);\n var time = 1000000000000000;\n for (var i=0; i<=k; i++) {\n // i: number of books both read\n var sum = 0;\n if (i <= cCum.length && k-i <= aCum.length && k-i <= bCum.length) {\n if (i >= 1) { sum += cCum[i-1]; }\n if (k-i >= 1) { sum += aCum[k-i-1] + bCum[k-i-1]; }\n time = Math.min(time, sum); \n }\n }\n if (time === 1000000000000000) { console.log(-1); }\n else { console.log(time); }\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction main() {\n var aliceOnly = [], bobOnly = [], both = []\n var n, k;\n [n, k] = readline().split(\" \").map(x => parseInt(x));\n for (var i=0; i parseInt(x));\n if (b === 1 && c === 1) {\n both.push(a);\n }\n else if (c === 1) {\n bobOnly.push(a);\n }\n else if (b === 1) {\n aliceOnly.push(a);\n }\n }\n aliceOnly.sort(); bobOnly.sort(); both.sort();\n const cum = (a => b => a+=b);\n const aCum = aliceOnly.map(cum(0)), bCum = bobOnly.map(cum(0)), cCum = both.map(cum(0));\n var time = 1000000000000000;\n for (var i=0; i<=k; i++) {\n // i: number of books both read\n var sum = 0;\n if (i <= cCum.length && k-i <= aCum.length && k-i <= bCum.length) {\n if (i >= 1) { sum += cCum[i-1]; }\n if (k-i >= 1) { sum += aCum[k-i-1] + bCum[k-i-1]; }\n time = Math.min(time, sum); \n }\n }\n if (time === 1000000000000000) { console.log(-1); }\n else { console.log(time); }\n}"}], "src_uid": "6a80b2af22cf8e5bb01ff47d257db196"} {"source_code": "\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\n \r\nfunction print(x) {\r\n console.log(x);\r\n}\r\nlet inputString = \"\";\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main();\r\n});\r\nfunction readline() {\r\n return inputString[currentLine++];\r\n}\r\n \r\n// ********** Code Start **********\r\n\r\nfunction main() {\r\n var tests = parseInt(readline());\r\n\r\n for (let t = 0; t < tests; t++) {\r\n var n = parseInt(readline());\r\n var array = readline().split(' ');\r\n var arr = [];\r\n var ans = 0;\r\n for (let i = 0;i < n;++i) {\r\n arr.push(parseInt(array[i]));\r\n }\r\n // console.log(arr);\r\n for (let i = 1;i < n;++i) {\r\n while (arr[n-1-i] >= arr[n-i] && arr[n-1-i] > 0) {\r\n arr[n-1-i] = parseInt(arr[n-1-i]/2);\r\n ans++;\r\n }\r\n if (arr[n-1-i] == arr[n-i]) {\r\n ans = -1;\r\n break;\r\n }\r\n }\r\n // console.log(arr);\r\n console.log(ans);\r\n }\r\n}", "positive_code": [{"source_code": "const rdline = require('readline');\r\nconst rl = rdline.createInterface({\r\n input: process.stdin\r\n});\r\n\r\nlet lines = [];\r\nrl.on('line', (line) => {\r\n lines.push(line);\r\n}).on('close', () => {\r\n // input in lines\r\n solve();\r\n});\r\n\r\nlet line = 0;\r\nconst readline = () => lines[line++];\r\n\r\nsolve = () => {\r\n const t = parseInt(readline());\r\n for (let j = 0; j < t; j++) {\r\n var n = parseInt(readline());\r\n var k = 0;\r\n var a = readline().split(\" \").map(Number);\r\n for (let i = n - 2; i >= 0; i--) {\r\n while (a[i] >= a[i + 1] && a[i] > 0) {\r\n a[i] = Math.floor(a[i] / 2);\r\n k++;\r\n }\r\n if (a[i] === a[i + 1]) {\r\n k = -1;\r\n }\r\n }\r\n console.log(k);\r\n }\r\n}"}, {"source_code": "'use-strict'\r\n \r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding('utf8');\r\n \r\nlet data = '';\r\nlet currentLine = 0;\r\n \r\nprocess.stdin.on('data', chunk => {\r\ndata += chunk;\r\n});\r\n \r\nprocess.stdin.on('end', () =>{\r\n data = data.replace(/\\s*$/, '')\r\n .split('\\n')\r\n .map(str => str.replace(/\\s*$/, ''));\r\n \r\n let testCases = parseInt(data.shift());\r\n \r\n while(testCases--) {\r\n \r\n const n = data.shift();\r\n\r\n const a = get_ints();\r\n \r\n const res = MY_FUNC(n,a);\r\n \r\n console.log(res)\r\n }\r\n});\r\n \r\nfunction get_ints() { \r\n return data.shift().split(' ').map(Number);\r\n}\r\n \r\nfunction readLine() { \r\n return data[currentLine++];\r\n}\r\n \r\nfunction MY_FUNC(n,a){\r\n let res = 0;\r\n \r\n for (let i = n - 2; i >= 0; i--) {\r\n if (a[i + 1] === 0) {\r\n res = -1\r\n return res;\r\n }\r\n while (a[i] >= a[i + 1]) {\r\n res++;\r\n a[i] = Math.floor(a[i] / 2);\r\n }\r\n }\r\n return res;\r\n}"}, {"source_code": "const fs = require('fs');\r\nconst input = fs.readFileSync(0, 'utf8').trim().split('\\r');\r\nlet currentline = 0;\r\nfunction readline(){\r\n return input[currentline++];\r\n}\r\nfunction alpha() {\r\n var g = []\r\n var f = 'abcdefghijklmnopqrstuvwxyz';\r\n for(var x=0;x parseInt(x))\r\n var prev = a[n-1];\r\n var v = []\r\n var ok = true;\r\n var moves = 0;\r\n for(var i=n-2;i>=0;i--) {\r\n var x = a[i];\r\n while(x >= prev && x > 0) {\r\n x = Math.floor(x/2);\r\n moves++;\r\n }\r\n if(x >= prev) {\r\n ok = false;\r\n break;\r\n } else {\r\n prev = x;\r\n }\r\n }\r\n \r\n console.log(ok ? moves : -1);\r\n //fs.appendFileSync('output.txt', (ok?moves:-1)+'\\r\\n');\r\n \r\n //os.EOL\r\n}\r\n//fs.writeFileSync('output.txt', f.join(' '));\r\n\r\n"}, {"source_code": "'use strict';\r\n\r\nvar readline = require('readline');\r\n\r\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\r\n\r\nvar readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);\r\n\r\nfunction solve(n, a) {\r\n let res = 0;\r\n for (let i = n - 2; i >= 0; i--) {\r\n if (a[i + 1] === 0) {\r\n console.log(-1);\r\n return;\r\n }\r\n while (a[i] >= a[i + 1]) {\r\n res++;\r\n a[i] = Math.floor(a[i] / 2);\r\n }\r\n }\r\n console.log(res);\r\n}\r\n\r\nasync function main(read) {\r\n let t = Number(await read());\r\n while (t--) {\r\n const n = Number(await read());\r\n const a = (await read()).split(' ').map(Number);\r\n solve(n, a);\r\n }\r\n}\r\n\r\nconst rl = readline__default[\"default\"].createInterface({\r\n input: process.stdin,\r\n output: process.stdout\r\n});\r\nvoid async function () {\r\n const inputs = [];\r\n let i = 0;\r\n for await (const line of rl) {\r\n inputs.push(line.trim());\r\n }\r\n function read() {\r\n return inputs[i++];\r\n }\r\n await main(read);\r\n}();\r\n"}, {"source_code": "const lines = [];\nconst rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });\nrl.on('line', line => lines.push(line));\nrl.on('close', main);\nlet rli = 0;\nfunction readline() {\n return lines[rli++];\n}\n\nconst ra = ()=>readline().split(' ').map(a=>+a);\n\nfunction div(val, by){\n return (val - val % by) / by;\n}\n\nconst cnk = (n, k) => {\n let res = 1;\n for (let i = 1; i <= k; i++)\n res = res * (n - k + i) / i;\n return Math.round(res + 0.01);\n}\n\n\nconst sumab = (a, b) => {\n let x = (b - a + 1);\n let y = a + b;\n if (x % 2 === 0) {\n x = Math.round(x / 2);\n } else {\n y = Math.round(y / 2);\n }\n return BigInt(x) * BigInt(y);\n}\n\n\n\nconst calc = (n, a)=>{\n if (n === 1) return 0;\n let result = 0;\n\n for (let i = n - 2; i >= 0; i--) {\n while (a[i] >= a[i + 1] && a[i] !== 0) {\n a[i] = Math.floor(a[i] / 2);\n result++;\n }\n if (a[i] === 0 && a[i] === a[i + 1]) return -1;\n }\n\n return result;\n};\n\nfunction main() {\n let T = +readline();\n for (let t = 1; t <= T; t++){\n let n = +readline();\n let a = ra();\n console.log(`${calc(n, a)}`);\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "'use strict';\n// HEADER:\nconst print = console.log;\nlet IS_MULTITEST, testN;\nconst pcalc = testN=>{\n let res = calc(testN);\n if (Array.isArray(res)){\n pa(res);\n } else if (Number.isFinite(res) || typeof res=='string'){\n print(res);\n }\n};\n\nconst main = ()=>{\n if (IS_MULTITEST){\n let T = +readline()\n for (testN=1; testN<=T; testN++)\n pcalc(T);\n } else\n pcalc();\n};\n\nconst lines = [];\nconst rl = require('readline').createInterface({\n input: process.stdin, output: process.stdout});\nrl.on('line', line=>{\n lines.push(line);\n});\nrl.on('close', main);\nlet rli = 0;\nconst readline = ()=>lines[rli++];\nconst L = process.env.DEBUG ? console.log : ()=>{};\nconst LT = obj=>L(`Test #${testN}`, obj);\n\nconst ra = ()=>readline().split(' ').map(a=>+a)\nconst pa = arr=>print(arr.join(' '));\n\n// SOLUTION:\nIS_MULTITEST = 1;\n \nconst calc = ()=>{\n // READING:\n let [n] = ra();\n let A = ra();\n LT({n, A});\n // PROCESSING:\n let ans = 0;\n for (let i=n-2; i>=0; i--){\n while (A[i]>=A[i+1]){\n if (A[i]==0){\n return -1;\n }\n A[i] = Math.floor(A[i]/2);\n ans++;\n }\n }\n return ans;\n};\n "}, {"source_code": "const readline = require('readline')\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n})\nconst lines = []\nrl.on('line', (input) => {\n lines.push(input);\n})\nrl.on('close', () => {\n// (function() {\n // const lines = require('fs').readFileSync('test.in', 'utf8').split('\\n')\n let l = 0;\n let t = +lines[l++]\n const output = []\n for (let i = 0; i < t; i++) {\n const n = +lines[l++]\n const arr = lines[l++].trim().split(' ').map(Number)\n output[i] = solve(n, arr)\n }\n console.log(output.join('\\n'))\n// })()\n})\n\nfunction solve(n, arr) {\n let ans = 0\n for (let i = arr.length - 2; i >= 0; i--) {\n if (arr[i + 1] === 0) return -1\n while (arr[i] >= arr[i + 1]) {\n arr[i] = Math.floor(arr[i] / 2)\n ans++\n }\n }\n return ans\n}\n"}, {"source_code": "t = parseInt(readline());\r\nfor(i = 0; i < t; i++)\r\n{\r\n var n = readline().split(\" \");\r\n var arr = readline().split(\" \");\r\n var count = 0;\r\n var k = false;\r\n for(j = arr.length - 2; j > -1; j--)\r\n {\r\n while(arr[j] - arr[j + 1] >= 0)\r\n {\r\n if(arr[j + 1] <= j) {\r\n k = true;\r\n break;\r\n }\r\n while(arr[j]/arr[j + 1] > 16385) {\r\n arr[j] = arr[j] / 16384;\r\n arr[j] -= arr[j] % 1;\r\n count += 14;\r\n }\r\n arr[j] = arr[j] / 2;\r\n arr[j] -= arr[j] % 1;\r\n count++;\r\n }\r\n if(k === true) {\r\n print(-1);\r\n break;\r\n }\r\n }\r\n if(k === false) print(count);\r\n}"}, {"source_code": "//import { readline, print } from '@ip-algorithmics/codeforces-io';\r\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n};\r\nvar t = +readline();\r\nfor (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {\r\n var i = _a[_i];\r\n readline();\r\n var a = __spreadArray(__spreadArray([], readline().split(' ').map(function (v) { return +v; }), true), [9999999999], false).reverse();\r\n var steps = 0;\r\n for (var _b = 0, _c = Array.from(a.keys()); _b < _c.length; _b++) {\r\n var i_1 = _c[_b];\r\n while (a[i_1] >= a[i_1 - 1]) {\r\n if (a[i_1] === 0) {\r\n steps = -1;\r\n break;\r\n }\r\n a[i_1] = Math.floor(a[i_1] / 2);\r\n steps += 1;\r\n }\r\n }\r\n print(steps);\r\n}\r\n"}, {"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\nfunction isOk(ar)\r\n{\r\n for(let i=1;i= 0 && isIncreasing && input.length > 1;\n index--\n ) {\n while (input[index] >= input[index + 1] && input[index] !== 0) {\n input[index] = Math.trunc(input[index] / 2);\n operations++;\n }\n\n if (input[index] >= input[index + 1]) {\n isIncreasing = false;\n }\n }\n if (isIncreasing) {\n console.log(operations);\n } else {\n console.log(-1);\n }\n }\n lines++;\n});\n"}], "negative_code": [{"source_code": "/**\r\n * Author : Fazlul Hoque\r\n * Node.js version : 12.16.3\r\n * command : node fileName.js output.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\nfunction isOk(ar)\r\n{\r\n for(let i=1;ioutput.txt\r\n */\r\n\"use strict\";\r\nprocess.stdin.resume();\r\nprocess.stdin.setEncoding(\"utf-8\");\r\nlet inputString = \"\"; //An array of raw inputs (includes 'n,\\r , not usable. need to process before use)\r\nlet currentLine = 0; //input sequence controller variable.\r\n\r\nprocess.stdin.on(\"data\", (inputStdin) => {\r\n inputString += inputStdin;\r\n});\r\nprocess.stdin.on(\"end\", () => {\r\n inputString = inputString.split(\"\\n\");\r\n main(); // after input \r\n});\r\n\r\n/********** Utility Functions Start **********/\r\n/**\r\n * read row Input\r\n * @returns string\r\n */\r\nfunction _readRawLine() {\r\n return inputString[currentLine++];\r\n}\r\nfunction readLine(){\r\n // return _readRawLine().replace(/\\s+$/g, '');\r\n return _readRawLine().replace('\\r', '');\r\n}\r\n\r\nfunction print(x) {\r\n console.log(x);\r\n}\r\n\r\nfunction readSingleInt() {\r\n const p = readLine();\r\n return parseInt(p);\r\n}\r\n\r\nfunction readIntArray() {\r\n return readLine().split(\" \").map((v) => parseInt(v));\r\n}\r\n\r\nfunction readArray() {\r\n return readLine().split(\" \");\r\n}\r\n\r\nfunction int(n) {\r\n return parseInt(n);\r\n}\r\n/********** Utility Functions End **********/\r\n/**\r\n * Don't Touch this fucntion at all , unless you know what are you doing!\r\n */\r\nfunction main() {\r\n solve();\r\n}\r\n\r\n// ********** actual Code Starts from here **********\r\nfunction isOk(ar)\r\n{\r\n for(let i=1;i= 0 && isIncreasing; index--) {\n while (input[index] >= input[index + 1] && input[index] !== 0) {\n input[index] = Math.trunc(input[index] / 2);\n operations++;\n }\n\n if (input[index] >= input[index + 1]) {\n isIncreasing = false;\n }\n }\n if (isIncreasing) {\n console.log(operations + \"\");\n } else {\n console.log(\"-1\");\n }\n }\n lines++;\n});\n"}, {"source_code": "let readline = require(\"readline\");\nlet rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n});\n\nlet lines = 0;\nrl.on(\"line\", function (line) {\n if (lines !== 0 && lines % 2 === 0) {\n let input = line.split(\" \").map(Number);\n let operations = 0;\n let isIncreasing = true;\n\n if (input.length === 1) {\n return console.log(operations);\n }\n\n for (var index = input.length - 1; index >= 0 && isIncreasing; index--) {\n while (input[index] >= input[index + 1] && input[index] !== 0) {\n input[index] = Math.trunc(input[index] / 2);\n operations++;\n }\n\n if (input[index] >= input[index + 1]) {\n isIncreasing = false;\n }\n }\n if (isIncreasing) {\n console.log(operations);\n } else {\n console.log(\"-1\");\n }\n }\n lines++;\n});\n"}], "src_uid": "e959e82b4bd4e7943a78bf5350a70c87"} {"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let f = Arr(0, n - 1, 1, i => i);\n let imin = Array(n); imin[0] = -1;\n let imax = Array(n); imax[0] = -1;\n let j = 0;\n For(1, n - 1, 1, i => {\n imax[i] = i - 1;\n while (imax[i] >= 0 && a[imax[i]] <= a[i]) imax[i] = imax[imax[i]];\n imin[i] = i - 1;\n while (imin[i] >= 0 && a[imin[i]] >= a[i]) imin[i] = imin[imin[i]];\n\n f[i] = f[i - 1] + 1;\n if (a[i] < a[i - 1]) {\n j = imin[i - 1];\n while (j >= 0) {\n f[i] = min(f[i], f[j] + 1);\n if (a[j] <= a[i]) break;\n j = imin[j];\n }\n } else if (a[i] > a[i - 1]) {\n j = imax[i - 1];\n while (j >= 0) {\n f[i] = min(f[i], f[j] + 1);\n if (a[j] >= a[i]) break;\n j = imax[j];\n }\n }\n })\n log(f[n - 1]);\n}\n\n", "positive_code": [{"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D(); \n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = parseInt(a[i]);\n\n return a;\n}\n\nfunction pi(x){\n return parseInt(x);\n}\n\nfunction D(){\n let n = pi(readline());\n \n let h = ti(readline().split(' '));\n let dp = new Array(n);\n dp.fill(99999999999999999);\n dp[0] = 0;\n let st = [];\n let lse = new Array(n);\n let lge = new Array(n);\n let rse = new Array(n);\n let rge = new Array(n);\n\n for(let i = 0; i < n; i++){\n while(st.length > 0 && h[st[st.length-1]] > h[i])\n st.pop();\n\n if(st.length === 0)\n lse[i] = -1;\n else\n lse[i] = st[st.length-1];\n \n st.push(i);\n }\n\n st = [];\n for(let i = 0; i < n; i++){\n while(st.length > 0 && h[st[st.length-1]] < h[i])\n st.pop();\n\n if(st.length === 0)\n lge[i] = -1;\n else\n lge[i] = st[st.length-1];\n \n st.push(i);\n }\n\n st = [];\n for(let i = n-1; i >= 0; i--){\n while(st.length > 0 && h[st[st.length-1]] > h[i])\n st.pop();\n\n if(st.length === 0)\n rse[i] = -1;\n else\n rse[i] = st[st.length-1];\n\n st.push(i);\n }\n\n st = [];\n for(let i = n-1; i >= 0; i--){\n while(st.length > 0 && h[st[st.length-1]] < h[i])\n st.pop();\n\n if(st.length === 0)\n rge[i] = -1;\n else\n rge[i] = st[st.length-1];\n\n st.push(i);\n }\n\n let jumps = new Array(n);\n for(let i = 0; i < n; i++)\n jumps[i] = [];\n \n for(let i = 0; i < n; i++){\n if(rse[i] !== -1)\n jumps[rse[i]].push(i);\n \n if(rge[i] !== -1)\n jumps[rge[i]].push(i);\n\n if(lse[i] !== -1)\n jumps[i].push(lse[i]);\n \n if(lge[i] !== -1)\n jumps[i].push(lge[i]);\n }\n\n for(let i = 1; i < n; i++){\n for(let j of jumps[i])\n dp[i] = Math.min(dp[i], dp[j] + 1);\n }\n\n\n //console.log(dp);\n console.log(dp[n-1]);\n}"}], "negative_code": [{"source_code": "function For(a, b, step, fn) {\n let res;\n if (step > 0) {\n for (let i = a; i <= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n } else {\n for (let i = a; i >= b; i += step) {\n if ((res = fn(i)) != null) return res;\n }\n }\n}\n\nfunction Arr(a, b, step, fn, init) {\n if (!step) {\n return a < b\n ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))\n : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))\n }\n let arr = Array(Math.max(a, b) + 1).fill(0);\n if (init) init(arr);\n if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);\n else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);\n return arr;\n}\n\nObject.defineProperty(Object.prototype, '$k', {\n value: function () { return Object.keys(this) }\n});\nObject.defineProperty(Object.prototype, '$v', {\n value: function () { return Object.values(this) }\n});\nObject.defineProperty(Object.prototype, '$kv', {\n value: function () { return Object.entries(this) }\n});\nArray.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }\nArray.prototype.uniq = function (fn) {\n var set = new Set();\n return this.filter(v => {\n var newValue = !set.has(fn ? fn(v) : v);\n set.add(fn ? fn(v) : v);\n return newValue;\n });\n}\nArray.prototype.toObj = function (fn) {\n return this.map(v => fn(v)).reduce((p, v) => {\n p[v[0]] = v[1];\n return p;\n }, {})\n}\nArray.prototype.min = function (fn) {\n let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);\n return [this[i], i, min];\n}\nArray.prototype.max = function (fn) {\n let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));\n let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);\n return [this[i], i, max];\n}\n\nfunction gcd(a, b) {\n if (!b) return a;\n return gcd(b, a % b);\n}\nfunction mod(a, n, m) {\n if (n == 0n) return 1n;\n if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);\n return a * mod(a, n - 1n, m) % m;\n}\nfunction extendedEuclid(a, b) {\n if (!b) return [1, 0];\n else {\n let [x, y] = extendedEuclid(b, a % b);\n return [y, x - (a / b | 0) * y];\n }\n}\n// [m] = extendedEuclid(a, 998244353);\n// let MOD = 998244353n;\n// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);\n// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);\n// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;\n// let nCk = (n, k) => {\n// return gt[n] * rgt[k] * rgt[n - k] % MOD;\n// }\n// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1\n\nlet input = '';\nprocess.stdin.on('data', c => input += c);\nprocess.stdin.on('end', main);\nfunction main() {\n let inp = input.split(/\\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],\n out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;\n let n = $()\n let a = $(n)\n let f = Arr(0, n - 1, 1, i => i);\n let j = 0;\n For(1, n - 1, 1, i => {\n f[i] = f[i - 1] + 1;\n if (a[i] < a[i - 1]) {\n if (a[i - 1] >= a[i - 2]) j = i - 2;\n j = For(j, 0, -1, j => a[j] < a[i - 1] ? j : null);\n while (j >= 0 && a[j] < a[j + 1] && a[j + 1] > a[i]) {\n f[i] = min(f[i], f[j--] + 1);\n }\n j++;\n } else if (a[i] > a[i - 1]) {\n if (a[i - 1] <= a[i - 2]) j = i - 2;\n j = For(j, 0, -1, j => a[j] > a[i - 1] ? j : null);\n while (j >= 0 && a[j] > a[j + 1] && a[j + 1] < a[i]) {\n f[i] = min(f[i], f[j--] + 1);\n }\n j++;\n }\n })\n log(f[n - 1]);\n}\n\n"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let n = pi(readline());\n\n let a = ti(readline().split(' '));\n let dp = new Array(n);\n dp[0] = 0;\n for(let i = 1; i < n; i++){\n let min = 99999999999999999999;\n let max = 0;\n\n for(let j = i-1; j >= 0; j--){\n if(j === i-1){\n dp[i] = dp[j] + 1;\n }else{\n min = Math.min(min, a[j+1]);\n max = Math.max(max, a[j+1]);\n if(max < Math.min(a[i], a[j])){\n dp[i] = Math.min(dp[i], dp[j] + 1);\n }else if(min > Math.max(a[i], a[j])){\n dp[i] = Math.min(dp[i], dp[j] + 1);\n }\n }\n }\n }\n\n console.log(dp);\n console.log(dp[n-1]);\n}"}, {"source_code": "process.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n D();\n});\n\nfunction readline() {\n return inputString[currentLine++];\n}\n\nfunction pi(a) {\n return parseInt(a);\n}\n\nfunction ti(a){\n for(let i = 0; i < a.length; i++)\n a[i] = pi(a[i]);\n\n return a;\n}\n\nfunction D(){\n let n = pi(readline());\n\n let a = ti(readline().split(' '));\n let dp = new Array(n);\n dp.fill(99999999999999999);\n dp[0] = 0;\n let stMin = [0];\n let stMax = [0];\n for(let i = 1; i < n; i++){\n while(stMin.length > 0 && a[stMin[stMin.length-1]] > a[i]){\n stMin.pop();\n }\n\n while(stMax.length > 0 && a[stMax[stMax.length-1]] < a[i]){\n stMax.pop();\n }\n\n if(stMin.length > 0 || stMax.length > 0){\n if(stMin.length > 0)\n dp[i] = dp[stMin[stMin.length-1]] + 1;\n\n if(stMax.length > 0)\n dp[i] = Math.min(dp[i], dp[stMax[stMax.length-1]] + 1);\n }else{\n dp[i] = dp[i-1] + 1;\n }\n\n stMin.push(i);\n stMax.push(i);\n }\n //console.log(dp);\n console.log(dp[n-1]);\n}"}], "src_uid": "1436a01f6638a59d844fc5df93850f11"} {"source_code": "var input = readline().split(' ').map(Number), n = input[0], m = input[1];\nvar a = readline().split(' ').map(Number);\n\nvar mySet = new Set();\nvar res = [];\nfor (var i = a.length - 1; i >= 0; i--) {\n if (!mySet.has(a[i]))\n mySet.add(a[i]);\n res[i] = mySet.size;\n}\n\nstr = '';\nfor (var i = 0; i < m; i++) {\n var l = readline().split(' ').map(Number);\n str += res[l-1] + '\\n';\n}\nwrite(str);\n", "positive_code": [{"source_code": "/**\n * \n * \nSereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing,\n he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,\u2009l2,\u2009...,\u2009lm (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n For each number li he wants to know how many distinct numbers are staying on the positions li, li\u2009+\u20091, ..., n. \n Formally, he want to find the number of distinct numbers among ali,\u2009ali\u2009+\u20091,\u2009...,\u2009an.?\n\nSereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. \nHelp him, find the answer for the described question for each li.\n\nInput\nThe first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105). The second line contains n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009105) \u2014 the array elements.\n\nNext m lines contain integers l1,\u2009l2,\u2009...,\u2009lm. The i-th line contains integer li (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n\nOutput\nPrint m lines \u2014 on the i-th line print the answer to the number li.\n\nInput\n\n10 10\n1 2 3 4 1 2 3 4 100000 99999\n[ 1, 2, 3, 4, 4, 4, 4, 4, 5, 6 ]\n1,\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\nOutput\n\n6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let lenthOfInput = Number(inputString[0].split(\" \")[0]);\n let lengthOfLocations = Number(inputString[0].split(\" \")[1]);\n let input = inputString[1].split(\" \");\n let locations = inputString.slice(2);\n\n solution(lenthOfInput, lengthOfLocations, input, locations);\n});\n\nfunction solution(lenthOfInput, lengthOfLocations, input, locations) {\n\n let solutionArray = [];\n let frequencyMap = {};\n let perfixSumForDistinct = [];\n\n for (let index = lenthOfInput - 1; index > -1; index--) {\n\n if (!frequencyMap[input[index]]) {\n\n //if (index)\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1] ? perfixSumForDistinct[index + 1] + 1 : 1\n\n // else\n // perfixSumForDistinct[index] = perfixSumForDistinct[index + 1] ? perfixSumForDistinct[index + 1] + 1 : 1\n }\n\n if (frequencyMap[input[index]]) {\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1]\n }\n\n frequencyMap[input[index]] = 1;\n }\n\n for (let index = 0; index < lengthOfLocations; index++) {\n let solution = perfixSumForDistinct[locations[index] - 1]\n solutionArray.push(solution);\n solutionArray.push(\"\\n\")\n }\n\n console.log(solutionArray.join(\"\"));\n\n}"}, {"source_code": "/**\n * \n * \nSereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing,\n he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,\u2009l2,\u2009...,\u2009lm (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n For each number li he wants to know how many distinct numbers are staying on the positions li, li\u2009+\u20091, ..., n. \n Formally, he want to find the number of distinct numbers among ali,\u2009ali\u2009+\u20091,\u2009...,\u2009an.?\n\nSereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. \nHelp him, find the answer for the described question for each li.\n\nInput\nThe first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105). The second line contains n integers a1, a2, ..., an \n(1\u2009\u2264\u2009ai\u2009\u2264\u2009105) \u2014 the array elements.\n\nNext m lines contain integers l1,\u2009l2,\u2009...,\u2009lm. The i-th line contains integer li (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n\nOutput\nPrint m lines \u2014 on the i-th line print the answer to the number li.\n\nInput\n\n10 10\n1 2 3 4 1 2 3 4 100000 99999\n1,\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\nOutput\n\n6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n */\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let lenthOfInput = Number(inputString[0].split(\" \")[0]);\n let lengthOfLocations = Number(inputString[0].split(\" \")[1]);\n let input = inputString[1].split(\" \");\n let locations = inputString.slice(2);\n\n solution(lenthOfInput, lengthOfLocations, input, locations);\n});\n\nfunction solution(lenthOfInput, lengthOfLocations, input, locations) {\n\n let solutionArray = [];\n let frequencyMap = {};\n let perfixSumForDistinct = [];\n\n for (let index = lenthOfInput - 1; index > -1; index--) {\n\n if (!frequencyMap[input[index]]) {\n\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1] ? perfixSumForDistinct[index + 1] + 1 : 1\n }\n\n if (frequencyMap[input[index]]) {\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1]\n }\n\n frequencyMap[input[index]] = 1;\n }\n\n for (let index = 0; index < lengthOfLocations; index++) {\n let solution = perfixSumForDistinct[locations[index] - 1]\n solutionArray.push(solution);\n solutionArray.push(\"\\n\")\n }\n\n console.log(solutionArray.join(\"\"));\n\n}"}, {"source_code": "const input = [];\n\nconst RL = require('readline').createInterface({\n input : process.stdin,\n output : process.stdout\n});\n \nRL.on('line', line => input.push(line));\n\nRL.on('close', () => {\n const [n, m] = input[0].split(' ').map(x => parseInt(x));\n const nums = input[1].split(' ').map(x => parseInt(x));\n\n const map = {}; const data = []; let cnt = 0;\n for (let i = nums.length - 1; i >= 0; i -= 1) {\n let x = nums[i]; \n if (map[x] === undefined) { cnt += 1; map[x] = true; }\n data[i] = cnt;\n }\n\n const answer = [];\n for (let i = 0; i < m; i += 1) {\n let x = parseInt(input[i+2]);\n answer.push(data[x-1]);\n answer.push('\\n');\n }\n\n console.log(answer.join(\"\"))\n});"}, {"source_code": "'use strict';\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n let valuesLen = Number(inputString[0].split(\" \")[0]);\n let numLen = Number(inputString[0].split(\" \")[1]);\n let values = inputString[1].split(\" \");\n let nums = inputString.slice(2);\n distinctNumbers(valuesLen, numLen, values, nums);\n});\nfunction distinctNumbers(valuesLen, numLen, values, nums) {\n var freqArr = {};\n var perfixSum = [];\n var distincts = 0;\n var solutions = [];\n for (let i = 0; i < valuesLen; i++) {\n if (!freqArr[values[i]]) {\n freqArr[values[i]] = 1;\n distincts++;\n }\n else {\n freqArr[values[i]]++;\n }\n }\n for (let i = 0; i < valuesLen; i++) {\n perfixSum[i] = distincts;\n if (freqArr[values[i]] == 1)\n distincts--;\n else {\n freqArr[values[i]]--\n }\n }\n for (let i = 0; i < numLen; i++) {\n // console.log(perfixSum[Number(nums[i]) - 1]);\n solutions.push(perfixSum[Number(nums[i]) - 1]);\n solutions.push('\\n');\n }\n console.log(solutions.join(\"\"));\n}\n"}, {"source_code": ";(function() {\n\n\tvar n = readline().split(' '),\n\t\tm = +n[1],\n\t\tt = {}, k = 0;\n\t\ta = readline().split(' ').map(Number);\n\tn = +n[0];\n\n\tfor (var i = n - 1; i >= 0; i--) {\n\t\tif (!t.hasOwnProperty(a[i])) {\n\t\t\tt[a[i]] = true;\n\t\t\tk++\n\t\t}\n\t\ta[i] = k;\n\t}\n\n\tfor (var i = 0; i < m; i++)\n\t\tprint(a[+readline() - 1]);\n\n}).call(this);"}, {"source_code": "const memo1 = Array(100000);\nconst memo2 = Array(100000);\n\nfunction check(arr) {\n var k = 0;\n for (var i = arr.length - 1; i >= 0; i--) {\n if (!memo1[arr[i]]) {\n memo1[arr[i]] = true;\n k++;\n }\n memo2[i] = k;\n }\n}\n\nfunction resolve(arr, ls) {\n check(arr);\n for (var i = 0; i < ls.length; i++) {\n print(memo2[ls[i] - 1]);\n // console.log(memo2[ls[i] - 1]);\n }\n}\n\n/*\nconst arr = '1 2 3 4 1 2 3 4 100000 99999'.split(' ');\nconst l = '1 2 3 4 5 6 7 8 9 10'.split(' ');\n\nresolve(arr, l);\n*/\n\nconst p = readline().split(' ');\nconst m = parseInt(p[1], 10);\nconst arr = readline().split(' ');\nconst ls = [];\n\nfor (var i = 0; i < m; i++) {\n var l = readline();\n ls.push(l);\n}\n\nresolve(arr, ls);\n"}, {"source_code": "if(!this.print){\n\tprint=console.log;\n\treadline=function(){\n\t\tvar data = require('fs').readFileSync('./2B.in','utf8').split('\\n');\n\t\tvar i=0;\n\t\treturn function(){\n\t\t\treturn data[i++];\n\t\t}\n\t}();\n}\nl=readline().split(' ');\nn=+l[0];\nm=+l[1];\na=readline().split(' ');\n\nvar map={};\nvar c=0;\nfor(var i=n-1;i>=0;i--){\n\tif(map[a[i]]){\n\t\ta[i]=c;\n\t}else{\n\t\tmap[a[i]]=true;\n\t\ta[i]=++c;\n\t}\n}\nwhile(m--){\n\tprint(a[readline()-1]);\n}"}, {"source_code": "'use strict';\n\n// const rlLib = require('readline');\n\n// const rl = rlLib.createInterface({\n// input: process.stdin,\n// output: process.stdout\n// });\n\n// let inputs = [];\n// let allCount = 12;\n// let currentLine = 0;\n\n// rl.on('line', (input) => {\n// inputs.push(input);\n// if (inputs.length >= allCount) {\n// main();\n\n// rl.close(); \n// }\n// });\n\n// function readline() {\n// return inputs[currentLine++];\n// }\n// function print() {\n// console.log.apply(this, arguments);\n// }\n\n\n// // function main() {\n// // let count = +readline();\n// // let arr = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n// // print(func(arr));\n// // }\n\n\n// /**\n// * @param {number} s\n// * @param {number[]} nums\n// * @return {number}\n// */\n// function main() {\n let count = +(readline().split(' ')[1]);\n let arr = readline().split(' ').map(function(e) {return parseInt(e, 10);});\n let indexes = [];\n let results = [];\n \n for (let i = 0; i < count; i++) {\n indexes.push(+(readline()));\n }\n\n let s = new Set();\n\n for (let i = arr.length - 1; i >= 0; i--) {\n if (s.has(arr[i])) {\n results[i] = results[i + 1] || 0;\n } else {\n s.add(arr[i]);\n results[i] = (results[i + 1] || 0) + 1;\n }\n }\n print(indexes.map(function(e) {return results[e - 1]}).join('\\n'));\n\n // var\n // commonSum = arr.reduce(function(s, e) {return s + e;}),\n // sum = [arr[0], commonSum - arr[0] - arr[arr.length - 1], arr[arr.length - 1]],\n // result = {};\n\n // var a = function a(sum, i, j) {\n // if ( j - i <= 1 || result[[i, j].join('!')]) {\n // return;\n // }\n\n // if (sum[0] === sum[1] && sum[1] === sum[2]) {\n // result[[i, j].join('!')] = 1;\n // }\n\n // a([sum[0]+ arr[i + 1], sum[1] - arr[i + 1], sum[2]], i + 1, j);\n // a([sum[0], sum[1] - arr[j - 1], sum[2] + arr[j - 1]], i, j - 1);\n // }\n\n // a(sum, 0, arr.length - 1);\n\n // print(Object.keys(result).length;\n// };\n\n\n"}, {"source_code": "function main() {\n var line = readline().split(' ').map(Number);\n var n = line[0];\n var m = line[1];\n var data = readline().split(' ').map(Number);\n var dp = [];\n dp[n-1] = 1;\n var all = {}\n all[data[n-1]] = true;\n for(var i=n-2;i>=0;i--){\n if(all[data[i]]){\n dp[i] = dp[i+1]\n } else {\n dp[i] = dp[i+1] + 1;\n all[data[i]] = true;\n }\n }\n for(var i=0;i -1; i--) {\n dif.add(parseInt(numbers[i]));\n count.push(dif.size);\n}\n\nfor(var i = 0; i < m; i++) {\n index = readline();\n print(count[n-parseInt(index,10)]);\n}"}, {"source_code": "var n = readline().split(/\\s/gi).map(Number), m = n[1], n = n[0],\n\t\t\tarr = readline().split(/\\s/gi),\n\t\t\tfilterArr = [], map = {}, temp = {};\n\n\t\tfor(var i = n - 1; i >= 0; i--)\t{\n\t\t\tvar value = arr[i];\n\n\t\t\tif(!temp[value])\t{\n\t\t\t\tfilterArr.push(value);\n\t\t\t\ttemp[value] = 1;\n\t\t\t}\n\n\t\t\tmap[i + 1] = filterArr.length;\n\t\t}\n\n\t\tfor(var i = 0; i < m; i++)\t{\n\t\t\tprint(map[parseInt(readline())]);\n\t\t}"}, {"source_code": "const N = 1<<17;\n\nvar n, q;\nvar a;\n\nvar dict;\nvar ans;\n\nvar token = [];\n\nvar currSize;\n\nfunction initializeData() {\n a = new Array(N);\n dict = {};\n ans = new Array(N);\n}\n\ninitializeData();\n\ntoken = readline().split(' ');\nn = parseInt(token[0]);\nq = parseInt(token[1]);\n\ntoken = readline().split(' ');\nfor(var i=0;i=1;i--) {\n if(dict[a[i]]==null) {\n ++currSize;\n dict[a[i]]=true;\n }\n\n ans[i]=currSize;\n}\n\nwhile(q--) {\n var currIdx = parseInt(readline());\n print(ans[currIdx]);\n}\n"}, {"source_code": "const N = 1<<17;\n\nvar n, q;\nvar a;\n\nvar dict;\nvar ans;\n\nvar token = [];\n\nvar currSize;\n\nfunction initializeData() {\n a = [];// new Array(N);\n dict = {};\n ans = [];// new Array(N);\n}\n\ninitializeData();\n\ntoken = readline().split(' ');\nn = parseInt(token[0]);\nq = parseInt(token[1]);\n\ntoken = readline().split(' ');\nfor(var i=0;i=1;i--) {\n if(dict[a[i]]==null) {\n ++currSize;\n dict[a[i]]=true;\n }\n\n ans[i]=currSize;\n}\n\nwhile(q--) {\n var currIdx = parseInt(readline());\n print(ans[currIdx]);\n}\n"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToNumberArray = function lineToNumberArray(str) {\n return str.split(\" \").map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 2),\n n = _readNumbersLine2[0],\n m = _readNumbersLine2[1];\n\nvar arr = readNumbersLine().reverse();\nvar numbers = [];\nfor (var i = 0; i < m; i++) {\n var number = readNumbersLine();\n numbers.push(number);\n}\n\nvar map = Object.create(null);\nvar arrCount = [];\nvar currCount = 0;\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = arr.entries()[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _ref = _step.value;\n\n var _ref2 = _slicedToArray(_ref, 2),\n key = _ref2[0],\n value = _ref2[1];\n\n if (!map[value]) {\n currCount++;\n map[value] = 1;\n } else {\n map[value] = map[value] + 1;\n }\n\n arrCount[key + arr.length - 1] = currCount;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nnumbers.forEach(function(pos) {\n var res = arrCount[arrCount.length - pos];\n print(res);\n});\n"}, {"source_code": "'use strict';\n \nlet inputString = '';\n \nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n \nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n // console.log(\"input \",inputString.slice(2,inputString.length));\n distinctNumbers(inputString[1], inputString.slice(2, inputString.length));\n});\n \nfunction distinctNumbers(values, nums) {\n values = values.split(\" \");\n var freqArr = {};\n var perfixSum = [];\n var solution =[];\n var distincts = 0;\n for (let i = 0; i < values.length; i++) {\n if (!freqArr[values[i]]) {\n freqArr[values[i]] = 1;\n distincts += 1;\n } else {\n freqArr[values[i]] += 1;\n }\n }\n for (let i = 0; i < values.length; i++) {\n perfixSum[i] = distincts;\n if (freqArr[values[i]] == 1)\n distincts -= 1;\n else {\n freqArr[values[i]] -= 1\n }\n }\n for (let i = 0; i < nums.length; i++) {\n solution.push(perfixSum[parseInt(nums[i]) - 1])\n solution.push(\"\\n\")\n\n }\n\n console.log(solution.join(\"\"));\n\n}\n// distinctNumbers('10 10', '1 2 3 4 1 2 3 4 100000 99999', '1 2 3 4 5 6 7 8 9 10')'\n"}, {"source_code": "/**\n * \n * \nSereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing,\n he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,\u2009l2,\u2009...,\u2009lm (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n For each number li he wants to know how many distinct numbers are staying on the positions li, li\u2009+\u20091, ..., n. \n Formally, he want to find the number of distinct numbers among ali,\u2009ali\u2009+\u20091,\u2009...,\u2009an.?\n\nSereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. \nHelp him, find the answer for the described question for each li.\n\nInput\nThe first line contains two integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105). The second line contains n integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009105) \u2014 the array elements.\n\nNext m lines contain integers l1,\u2009l2,\u2009...,\u2009lm. The i-th line contains integer li (1\u2009\u2264\u2009li\u2009\u2264\u2009n).\n\nOutput\nPrint m lines \u2014 on the i-th line print the answer to the number li.\n\nInput\n\n10 10\n1 2 3 4 1 2 3 4 100000 99999\n[ 1, 2, 3, 4, 4, 4, 4, 4, 5, 6 ]\n1,\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\nOutput\n\n6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n */\n\n\nlet inputString = '';\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n\n let lenthOfInput = Number(inputString[0].split(\" \")[0]);\n let lengthOfLocations = Number(inputString[0].split(\" \")[1]);\n let input = inputString[1].split(\" \");\n let locations = inputString.slice(2);\n\n solution(lenthOfInput, lengthOfLocations, input, locations);\n});\n\nfunction solution(lenthOfInput, lengthOfLocations, input, locations) {\n\n let solutionArray = [];\n let frequencyMap = {};\n let perfixSumForDistinct = [];\n\n for (let index = lenthOfInput - 1; index > -1; index--) {\n\n if (!frequencyMap[input[index]]) {\n\n if (index)\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1] ? perfixSumForDistinct[index + 1] + 1 : 1\n\n else\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1] ? perfixSumForDistinct[index + 1] + 1 : 1\n }\n\n if (frequencyMap[input[index]]) {\n perfixSumForDistinct[index] = perfixSumForDistinct[index + 1]\n }\n\n frequencyMap[input[index]] = 1;\n }\n\n for (let index = 0; index < lengthOfLocations; index++) {\n let solution = perfixSumForDistinct[locations[index] - 1]\n solutionArray.push(solution);\n solutionArray.push(\"\\n\")\n }\n\n console.log(solutionArray.join(\"\"));\n\n}"}], "negative_code": [{"source_code": "const memo1 = {};\nconst memo2 = {};\n\nfunction check(arr, i) {\n if (i === -1) {\n return;\n }\n if (!memo1[arr[i]]) {\n memo1[arr[i]] = true;\n }\n memo2[i] = Object.keys(memo1).length;\n check(arr, i - 1);\n}\n\nfunction resolve(arr, ls) {\n check(arr, arr.length - 1);\n for (var i = 0; i < ls.length; i++) {\n print(memo2[ls[i]]);\n //console.log(memo2[ls[i] - 1]);\n }\n}\n\n/*\nconst arr = '1 2 3 4 1 2 3 4 100000 99999'.split(' ');\nconst l = '1 2 3 4 5 6 7 8 9 10'.split(' ');\n\nresolve(arr, l);\n*/\n\nconst p = readline().split(' ');\nconst m = parseInt(p[1], 10);\nconst arr = readline().split(' ');\nconst ls = [];\n\nfor (var i = 0; i < m; i++) {\n var l = readline();\n ls.push(l);\n}\n\nresolve(arr, ls);\n"}, {"source_code": "var n = readline().split(/\\s/gi).map(Number), m = n[1], n = n[0],\n\t\t\tarr = readline().split(/\\s/gi),\n\t\t\tfilterArr = [], map = {}, result = [], line = [];\n\n\t\tfor(var i = 0; i < m; i++)\tline.push(parseInt(readline()));\n\n\t\tfor(var i = n - 1; i >= 0; i--)\t{\n\t\t\tvar value = arr[i];\n\n\t\t\tif(filterArr.indexOf(value) == -1)\t{\n\t\t\t\tfilterArr.push(value);\n\t\t\t}\n\n\t\t\tmap[i + 1] = filterArr.length;\n\n\t\t\tif(line.indexOf(i + 1) > -1)\tresult.push(map[i + 1]);\n\t\t}\n\n\t\tprint(result.reverse().join('\\n'));"}, {"source_code": "\"use strict\";\n\nvar _slicedToArray = (function() {\n function sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n try {\n for (\n var _i = arr[Symbol.iterator](), _s;\n !(_n = (_s = _i.next()).done);\n _n = true\n ) {\n _arr.push(_s.value);\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"]) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n return _arr;\n }\n return function(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return sliceIterator(arr, i);\n } else {\n throw new TypeError(\n \"Invalid attempt to destructure non-iterable instance\"\n );\n }\n };\n})();\n\nvar compose = function compose() {\n for (\n var _len = arguments.length, functions = Array(_len), _key = 0;\n _key < _len;\n _key++\n ) {\n functions[_key] = arguments[_key];\n }\n\n return function() {\n for (\n var _len2 = arguments.length, args = Array(_len2), _key2 = 0;\n _key2 < _len2;\n _key2++\n ) {\n args[_key2] = arguments[_key2];\n }\n\n return functions.reduce(function(currArgs, func) {\n return func(currArgs);\n }, args);\n };\n};\n\nvar lineToNumberArray = function lineToNumberArray(str) {\n return str.split(\" \").map(function(num) {\n return parseInt(num, 10);\n });\n};\n\nvar readNumbersLine = compose(\n readline,\n lineToNumberArray\n);\n\nvar _readNumbersLine = readNumbersLine(),\n _readNumbersLine2 = _slicedToArray(_readNumbersLine, 2),\n n = _readNumbersLine2[0],\n m = _readNumbersLine2[1];\n\nvar arr = readNumbersLine();\nvar numbers = [];\nfor (var i = 0; i < m; i++) {\n var number = readNumbersLine();\n numbers.push(number);\n}\n\nvar map = Object.create(null);\nvar count = [];\n\nvar _iteratorNormalCompletion = true;\nvar _didIteratorError = false;\nvar _iteratorError = undefined;\n\ntry {\n for (\n var _iterator = arr.entries()[Symbol.iterator](), _step;\n !(_iteratorNormalCompletion = (_step = _iterator.next()).done);\n _iteratorNormalCompletion = true\n ) {\n var _ref = _step.value;\n\n var _ref2 = _slicedToArray(_ref, 2),\n key = _ref2[0],\n value = _ref2[1];\n\n map[value] = map[value] ? map[value] + 1 : 1;\n count[key] = Object.keys(map).length;\n }\n} catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n} finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n}\n\nnumbers.forEach(function(pos) {\n var res = count[count.length - 1] - (count[pos - 2] | 0);\n print(res);\n});\n"}, {"source_code": "!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&n&&\"string\"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,\"a\",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p=\"\",r(r.s=39)}([function(t,n,r){var e=r(23)(\"wks\"),o=r(11),i=r(1).Symbol,u=\"function\"==typeof i;(t.exports=function(t){return e[t]||(e[t]=u&&i[t]||(u?i:o)(\"Symbol.\"+t))}).store=e},function(t,n){var r=t.exports=\"undefined\"!=typeof window&&window.Math==Math?window:\"undefined\"!=typeof self&&self.Math==Math?self:Function(\"return this\")();\"number\"==typeof __g&&(__g=r)},function(t,n){t.exports=function(t){return\"object\"==typeof t?null!==t:\"function\"==typeof t}},function(t,n,r){t.exports=!r(12)(function(){return 7!=Object.defineProperty({},\"a\",{get:function(){return 7}}).a})},function(t,n,r){var e=r(1),o=r(5),i=r(8),u=r(11)(\"src\"),c=Function.toString,f=(\"\"+c).split(\"toString\");r(9).inspectSource=function(t){return c.call(t)},(t.exports=function(t,n,r,c){var s=\"function\"==typeof r;s&&(i(r,\"name\")||o(r,\"name\",n)),t[n]!==r&&(s&&(i(r,u)||o(r,u,t[n]?\"\"+t[n]:f.join(String(n)))),t===e?t[n]=r:c?t[n]?t[n]=r:o(t,n,r):(delete t[n],o(t,n,r)))})(Function.prototype,\"toString\",function(){return\"function\"==typeof this&&this[u]||c.call(this)})},function(t,n,r){var e=r(6),o=r(15);t.exports=r(3)?function(t,n,r){return e.f(t,n,o(1,r))}:function(t,n,r){return t[n]=r,t}},function(t,n,r){var e=r(7),o=r(25),i=r(27),u=Object.defineProperty;n.f=r(3)?Object.defineProperty:function(t,n,r){if(e(t),n=i(n,!0),e(r),o)try{return u(t,n,r)}catch(t){}if(\"get\"in r||\"set\"in r)throw TypeError(\"Accessors not supported!\");return\"value\"in r&&(t[n]=r.value),t}},function(t,n,r){var e=r(2);t.exports=function(t){if(!e(t))throw TypeError(t+\" is not an object!\");return t}},function(t,n){var r={}.hasOwnProperty;t.exports=function(t,n){return r.call(t,n)}},function(t,n){var r=t.exports={version:\"2.5.7\"};\"number\"==typeof __e&&(__e=r)},function(t,n){t.exports={}},function(t,n){var r=0,e=Math.random();t.exports=function(t){return\"Symbol(\".concat(void 0===t?\"\":t,\")_\",(++r+e).toString(36))}},function(t,n){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,n,r){var e=r(44);t.exports=function(t,n,r){if(e(t),void 0===n)return t;switch(r){case 1:return function(r){return t.call(n,r)};case 2:return function(r,e){return t.call(n,r,e)};case 3:return function(r,e,o){return t.call(n,r,e,o)}}return function(){return t.apply(n,arguments)}}},function(t,n,r){var e=r(48),o=r(17);t.exports=function(t){return e(o(t))}},function(t,n){t.exports=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}},function(t,n){var r=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?e:r)(t)}},function(t,n){t.exports=function(t){if(void 0==t)throw TypeError(\"Can't call method on \"+t);return t}},function(t,n,r){\"use strict\";var e=r(24),o=r(28),i=r(4),u=r(5),c=r(10),f=r(45),s=r(20),a=r(52),p=r(0)(\"iterator\"),l=!([].keys&&\"next\"in[].keys()),v=function(){return this};t.exports=function(t,n,r,y,h,d,_){f(r,n,y);var g,x,b,S=function(t){if(!l&&t in w)return w[t];switch(t){case\"keys\":case\"values\":return function(){return new r(this,t)}}return function(){return new r(this,t)}},m=n+\" Iterator\",O=\"values\"==h,j=!1,w=t.prototype,E=w[p]||w[\"@@iterator\"]||h&&w[h],T=E||S(h),M=h?O?S(\"entries\"):T:void 0,P=\"Array\"==n&&w.entries||E;if(P&&(b=a(P.call(new t)))!==Object.prototype&&b.next&&(s(b,m,!0),e||\"function\"==typeof b[p]||u(b,p,v)),O&&E&&\"values\"!==E.name&&(j=!0,T=function(){return E.call(this)}),e&&!_||!l&&!j&&w[p]||u(w,p,T),c[n]=T,c[m]=v,h)if(g={values:O?T:S(\"values\"),keys:d?T:S(\"keys\"),entries:M},_)for(x in g)x in w||i(w,x,g[x]);else o(o.P+o.F*(l||j),n,g);return g}},function(t,n,r){var e=r(23)(\"keys\"),o=r(11);t.exports=function(t){return e[t]||(e[t]=o(t))}},function(t,n,r){var e=r(6).f,o=r(8),i=r(0)(\"toStringTag\");t.exports=function(t,n,r){t&&!o(t=r?t:t.prototype,i)&&e(t,i,{configurable:!0,value:n})}},function(t,n,r){var e=r(22),o=r(0)(\"toStringTag\"),i=\"Arguments\"==e(function(){return arguments}());t.exports=function(t){var n,r,u;return void 0===t?\"Undefined\":null===t?\"Null\":\"string\"==typeof(r=function(t,n){try{return t[n]}catch(t){}}(n=Object(t),o))?r:i?e(n):\"Object\"==(u=e(n))&&\"function\"==typeof n.callee?\"Arguments\":u}},function(t,n){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,n,r){var e=r(9),o=r(1),i=o[\"__core-js_shared__\"]||(o[\"__core-js_shared__\"]={});(t.exports=function(t,n){return i[t]||(i[t]=void 0!==n?n:{})})(\"versions\",[]).push({version:e.version,mode:r(24)?\"pure\":\"global\",copyright:\"\u00a9 2018 Denis Pushkarev (zloirock.ru)\"})},function(t,n){t.exports=!1},function(t,n,r){t.exports=!r(3)&&!r(12)(function(){return 7!=Object.defineProperty(r(26)(\"div\"),\"a\",{get:function(){return 7}}).a})},function(t,n,r){var e=r(2),o=r(1).document,i=e(o)&&e(o.createElement);t.exports=function(t){return i?o.createElement(t):{}}},function(t,n,r){var e=r(2);t.exports=function(t,n){if(!e(t))return t;var r,o;if(n&&\"function\"==typeof(r=t.toString)&&!e(o=r.call(t)))return o;if(\"function\"==typeof(r=t.valueOf)&&!e(o=r.call(t)))return o;if(!n&&\"function\"==typeof(r=t.toString)&&!e(o=r.call(t)))return o;throw TypeError(\"Can't convert object to primitive value\")}},function(t,n,r){var e=r(1),o=r(9),i=r(5),u=r(4),c=r(13),f=function(t,n,r){var s,a,p,l,v=t&f.F,y=t&f.G,h=t&f.S,d=t&f.P,_=t&f.B,g=y?e:h?e[n]||(e[n]={}):(e[n]||{}).prototype,x=y?o:o[n]||(o[n]={}),b=x.prototype||(x.prototype={});for(s in y&&(r=n),r)p=((a=!v&&g&&void 0!==g[s])?g:r)[s],l=_&&a?c(p,e):d&&\"function\"==typeof p?c(Function.call,p):p,g&&u(g,s,p,t&f.U),x[s]!=p&&i(x,s,l),d&&b[s]!=p&&(b[s]=p)};e.core=o,f.F=1,f.G=2,f.S=4,f.P=8,f.B=16,f.W=32,f.U=64,f.R=128,t.exports=f},function(t,n,r){var e=r(7),o=r(46),i=r(32),u=r(19)(\"IE_PROTO\"),c=function(){},f=function(){var t,n=r(26)(\"iframe\"),e=i.length;for(n.style.display=\"none\",r(51).appendChild(n),n.src=\"javascript:\",(t=n.contentWindow.document).open(),t.write(\"